From 874d6a27ca32ac0de6bcc14cac41162287cbb46c Mon Sep 17 00:00:00 2001 From: mathuo <6710312+mathuo@users.noreply.github.com> Date: Mon, 11 Aug 2025 20:35:19 +0100 Subject: [PATCH] chore: use constant --- packages/dockview-core/src/constants.ts | 2 ++ .../src/dockview/dockviewComponent.ts | 31 ++++++++++--------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/packages/dockview-core/src/constants.ts b/packages/dockview-core/src/constants.ts index c813942d3..b9c24451c 100644 --- a/packages/dockview-core/src/constants.ts +++ b/packages/dockview-core/src/constants.ts @@ -1,3 +1,5 @@ export const DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE = 100; export const DEFAULT_FLOATING_GROUP_POSITION = { left: 100, top: 100, width: 300, height: 300 }; + +export const DESERIALIZATION_POPOUT_DELAY_MS = 100 diff --git a/packages/dockview-core/src/dockview/dockviewComponent.ts b/packages/dockview-core/src/dockview/dockviewComponent.ts index dc4969f25..ee76d815b 100644 --- a/packages/dockview-core/src/dockview/dockviewComponent.ts +++ b/packages/dockview-core/src/dockview/dockviewComponent.ts @@ -70,6 +70,7 @@ import { AnchoredBox, AnchorPosition, Box } from '../types'; import { DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE, DEFAULT_FLOATING_GROUP_POSITION, + DESERIALIZATION_POPOUT_DELAY_MS, } from '../constants'; import { DockviewPanelRenderer, @@ -1533,7 +1534,7 @@ export class DockviewComponent // Create a promise that resolves when all popout groups are created const popoutPromises: Promise[] = []; - + // Queue popup group creation with delays to avoid browser blocking serializedPopoutGroups.forEach((serializedPopoutGroup, index) => { const { data, position, gridReferenceGroup, url } = @@ -1553,12 +1554,12 @@ export class DockviewComponent popoutUrl: url, }); resolve(); - }, index * 100); // 100ms delay between each popup + }, index * DESERIALIZATION_POPOUT_DELAY_MS); // 100ms delay between each popup }); - + popoutPromises.push(popoutPromise); }); - + // Store the promise for tests to wait on this._popoutRestorationPromise = Promise.all(popoutPromises).then(() => void 0); @@ -2382,8 +2383,8 @@ export class DockviewComponent } } else if (targetActivePanel) { // Ensure the target group's original active panel remains active - to.model.openPanel(targetActivePanel, { - skipSetGroupActive: true + to.model.openPanel(targetActivePanel, { + skipSetGroupActive: true }); } } else { @@ -2408,13 +2409,13 @@ export class DockviewComponent if (!selectedPopoutGroup) { throw new Error('failed to find popout group'); } - + // Remove from popout groups list to prevent automatic restoration const index = this._popoutGroups.indexOf(selectedPopoutGroup); if (index >= 0) { this._popoutGroups.splice(index, 1); } - + // Clean up the reference group (ghost) if it exists and is hidden if (selectedPopoutGroup.referenceGroup) { const referenceGroup = this.getPanel(selectedPopoutGroup.referenceGroup); @@ -2422,10 +2423,10 @@ export class DockviewComponent this.doRemoveGroup(referenceGroup, { skipActive: true }); } } - + // Manually dispose the window without triggering restoration selectedPopoutGroup.window.dispose(); - + // Update group's location and containers for target if (to.api.location.type === 'grid') { from.model.renderContainer = this.overlayRenderContainer; @@ -2436,7 +2437,7 @@ export class DockviewComponent from.model.dropTargetContainer = this.rootDropTargetContainer; from.model.location = { type: 'floating' }; } - + break; } } @@ -2449,7 +2450,7 @@ export class DockviewComponent referenceLocation, target ); - + // Add to grid for all moves targeting grid location let size: number; @@ -2478,7 +2479,7 @@ export class DockviewComponent ); if (targetFloatingGroup) { const box = targetFloatingGroup.overlay.toJSON(); - + // Calculate position based on available properties let left: number, top: number; if ('left' in box) { @@ -2488,7 +2489,7 @@ export class DockviewComponent } else { left = 50; // Default fallback } - + if ('top' in box) { top = box.top + 50; } else if ('bottom' in box) { @@ -2496,7 +2497,7 @@ export class DockviewComponent } else { top = 50; // Default fallback } - + this.addFloatingGroup(from, { height: box.height, width: box.width,