@kubohiroya/turbowarp-plus-editor-workbench 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dockview-stage.d.ts +9 -0
- package/dist/dockview-stage.js +30 -3
- package/dist/drawer-views.d.ts +1 -0
- package/dist/drawer-views.js +4 -0
- package/dist/sprite-tabs.js +31 -5
- package/dist/stage-drawer-drag.d.ts +5 -1
- package/dist/stage-drawer-drag.js +18 -3
- package/dist/stage-launcher.d.ts +8 -1
- package/dist/stage-launcher.js +22 -7
- package/dist/stage-surface.d.ts +3 -2
- package/dist/stage-surface.js +14 -2
- package/dist/standard-layout.d.ts +8 -2
- package/dist/standard-layout.js +65 -19
- package/dist/workspace-layout.d.ts +15 -0
- package/dist/workspace-layout.js +17 -0
- package/package.json +1 -1
- package/src/dockview-stage.ts +35 -3
- package/src/drawer-views.ts +7 -0
- package/src/sprite-tabs.ts +30 -5
- package/src/stage-drawer-drag.ts +22 -7
- package/src/stage-launcher.ts +24 -6
- package/src/stage-surface.ts +17 -3
- package/src/standard-layout.ts +65 -21
- package/src/workspace-layout.ts +31 -0
package/src/standard-layout.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {createLayout, createSplitter, splitAxis} from './index.ts';
|
|
2
2
|
import {createTargetList} from './targets.ts';
|
|
3
3
|
import type {DrawerViews} from './drawer-views.ts';
|
|
4
|
-
import {availableDrawerViews, createDrawerViewBar, hasDrawerBar, readDrawerView, writeDrawerView} from './drawer-views.ts';
|
|
4
|
+
import {availableDrawerViews, createDrawerViewBar, drawerPinIcon, hasDrawerBar, readDrawerView, writeDrawerView} from './drawer-views.ts';
|
|
5
5
|
import {attachStageDrawerDrag} from './stage-drawer-drag.ts';
|
|
6
|
+
import type {StageDrawerLayout, StageDrawerPosition} from './workspace-layout.ts';
|
|
6
7
|
|
|
7
8
|
export type {DrawerMenu, DrawerMenuRenderProps, DrawerRenderProps, DrawerView, DrawerViewId, DrawerViews,
|
|
8
9
|
HostDrawerViewId} from './drawer-views.ts';
|
|
@@ -25,12 +26,15 @@ export function createStandardLayout(React, {styles, targetStyles, context, Layo
|
|
|
25
26
|
|
|
26
27
|
function StandardLayout({
|
|
27
28
|
enabled, splitter, windowLayout, stageActionEnabled, stageDrawer = false,
|
|
28
|
-
onPaletteModeChange, windowTools, Container, render, drawerViews = undefined as DrawerViews | undefined,
|
|
29
|
+
onPaletteModeChange, windowTools, Container, render, drawerViews = undefined as DrawerViews | undefined,
|
|
30
|
+
stageDrawerLayout = undefined as StageDrawerLayout | undefined,
|
|
31
|
+
updateStageDrawer = undefined as ((patch: Partial<StageDrawerLayout>) => void) | undefined, ...props
|
|
29
32
|
}) {
|
|
30
33
|
const [showUndock, setShowUndock] = useState(false);
|
|
31
34
|
const [targetsPinned, setTargetsPinned] = useState(true);
|
|
32
35
|
const [showStage, setShowStage] = useState(true);
|
|
33
36
|
const [stageDrawerOpen, setStageDrawerOpen] = useState(false);
|
|
37
|
+
const [localStageDrawerPinned, setLocalStageDrawerPinned] = useState(true);
|
|
34
38
|
const [size, setSize] = useState(null);
|
|
35
39
|
const [targetRatio, setTargetRatio] = useState(null);
|
|
36
40
|
const [viewRatio, setViewRatio] = useState(null);
|
|
@@ -47,6 +51,11 @@ export function createStandardLayout(React, {styles, targetStyles, context, Layo
|
|
|
47
51
|
const body = useRef(null);
|
|
48
52
|
const plusLayout = enabled && !props.fullscreen;
|
|
49
53
|
const stageHidden = plusLayout && !showStage;
|
|
54
|
+
const stageDrawerPinned = updateStageDrawer ? stageDrawerLayout?.pinned !== false : localStageDrawerPinned;
|
|
55
|
+
const setStageDrawerPinned = (pinned: boolean) => {
|
|
56
|
+
if (updateStageDrawer) updateStageDrawer({pinned});
|
|
57
|
+
else setLocalStageDrawerPinned(pinned);
|
|
58
|
+
};
|
|
50
59
|
const japanese = isJapanese(props.locale);
|
|
51
60
|
const undockLabel = japanese ? 'アンドックボタンを表示' : 'Show undock buttons';
|
|
52
61
|
const layoutMenuLabel = japanese ? '配置メニュー' : 'Layout options';
|
|
@@ -82,9 +91,12 @@ export function createStandardLayout(React, {styles, targetStyles, context, Layo
|
|
|
82
91
|
((size?.height ?? 640) - 112) * props.stageAspect)));
|
|
83
92
|
const defaultStageWidth = Math.min(maximumStageWidth, Math.floor(Math.min(props.defaultStageWidth, 360, bodyWidth / 2)));
|
|
84
93
|
const minimumStageWidth = Math.min(defaultStageWidth, 280);
|
|
85
|
-
const
|
|
94
|
+
const preferredWidth = stageDrawer && updateStageDrawer ? stageDrawerLayout?.width : preferredStageWidth;
|
|
95
|
+
const resizeStage = stageDrawer && updateStageDrawer ?
|
|
96
|
+
(width: number | undefined) => updateStageDrawer({width}) : setPreferredStageWidth;
|
|
97
|
+
const stageWidth = Math.max(minimumStageWidth, Math.min(maximumStageWidth, preferredWidth ?? defaultStageWidth));
|
|
86
98
|
const stageResize = plusLayout && maximumStageWidth > minimumStageWidth ?
|
|
87
|
-
{minimum: minimumStageWidth, maximum: maximumStageWidth, resize:
|
|
99
|
+
{minimum: minimumStageWidth, maximum: maximumStageWidth, resize: resizeStage} : null;
|
|
88
100
|
|
|
89
101
|
useLayoutEffect(() => {
|
|
90
102
|
if (enabled) onPaletteModeChange?.(true);
|
|
@@ -160,7 +172,7 @@ export function createStandardLayout(React, {styles, targetStyles, context, Layo
|
|
|
160
172
|
targetClassName: targetsPinned ? styles.standardTargets :
|
|
161
173
|
`${styles.standardTargets} ${styles.retractedTargets}`,
|
|
162
174
|
stageDisplayWidth: stageWidth,
|
|
163
|
-
handleStagePreset: () =>
|
|
175
|
+
handleStagePreset: () => resizeStage(undefined),
|
|
164
176
|
editorWidth: targetsPinned && resizable ? targetSplit.second : size?.width
|
|
165
177
|
};
|
|
166
178
|
};
|
|
@@ -182,7 +194,8 @@ export function createStandardLayout(React, {styles, targetStyles, context, Layo
|
|
|
182
194
|
});
|
|
183
195
|
return element(context.Provider, {value: {
|
|
184
196
|
showUndock, plusLayout, targetsPinned, setTargetsPinned, stageHidden, setStageVisible: setShowStage, stageResize, stageActionMount,
|
|
185
|
-
stageDrawer: plusLayout && stageDrawer,
|
|
197
|
+
stageDrawer: plusLayout && stageDrawer, stageDrawerPinned, setStageDrawerPinned, setStageDrawerOpen,
|
|
198
|
+
locale: props.locale,
|
|
186
199
|
drawerViews, drawerView, selectDrawerView
|
|
187
200
|
}},
|
|
188
201
|
Container ? element(Container, {locale: props.locale}, layout) : layout);
|
|
@@ -190,22 +203,32 @@ export function createStandardLayout(React, {styles, targetStyles, context, Layo
|
|
|
190
203
|
|
|
191
204
|
function EdgeDrawer({edge, label, pinned = false, onOpenChange, portalContent = false, holdOpenSelector = '',
|
|
192
205
|
focusPanelRef = undefined, closePanelRef = undefined, focusBoundary = undefined, showTrigger = true,
|
|
193
|
-
movableStage = false, available = true,
|
|
206
|
+
movableStage = false, available = true, keepOpenOnBlur = false,
|
|
207
|
+
stageDrawerLayout = undefined as StageDrawerLayout | undefined,
|
|
208
|
+
updateStageDrawer = undefined as ((patch: Partial<StageDrawerLayout>) => void) | undefined, children}) {
|
|
194
209
|
const [hovered, setHovered] = useState(false);
|
|
195
|
-
const [
|
|
210
|
+
const [localEngaged, setLocalEngaged] = useState(false);
|
|
196
211
|
const [heldOpen, setHeldOpen] = useState(false);
|
|
197
212
|
const drawer = useRef(null);
|
|
198
213
|
const trigger = useRef(null);
|
|
199
214
|
const panel = useRef(null);
|
|
200
215
|
const opened = useRef(false);
|
|
201
|
-
const
|
|
202
|
-
const
|
|
216
|
+
const stageDrag = useRef(null);
|
|
217
|
+
const engaged = updateStageDrawer ? Boolean(stageDrawerLayout?.open) : localEngaged;
|
|
218
|
+
const setEngaged = React.useCallback((engaged: boolean) => {
|
|
219
|
+
if (updateStageDrawer) updateStageDrawer({open: engaged, ...(engaged && {selected: true})});
|
|
220
|
+
else setLocalEngaged(engaged);
|
|
221
|
+
}, [updateStageDrawer]);
|
|
222
|
+
const selected = updateStageDrawer ? Boolean(stageDrawerLayout?.selected) : opened.current;
|
|
223
|
+
const open = available && (pinned || engaged || heldOpen ||
|
|
224
|
+
(hovered && (!updateStageDrawer || showTrigger || selected)));
|
|
225
|
+
const stageTrigger = movableStage && available && (showTrigger || selected);
|
|
203
226
|
|
|
204
227
|
useLayoutEffect(() => {
|
|
205
228
|
if (open) opened.current = true;
|
|
206
229
|
if (!available) {
|
|
207
230
|
setHovered(false);
|
|
208
|
-
|
|
231
|
+
setLocalEngaged(false);
|
|
209
232
|
}
|
|
210
233
|
}, [open, available]);
|
|
211
234
|
|
|
@@ -215,8 +238,17 @@ export function createStandardLayout(React, {styles, targetStyles, context, Layo
|
|
|
215
238
|
const stage = node.closest<HTMLElement>(`.${styles.stageDrawer}`);
|
|
216
239
|
const editor = stage?.closest<HTMLElement>(`.${styles.standardBody}`);
|
|
217
240
|
if (!editor || !node.ownerDocument.defaultView?.ResizeObserver) return;
|
|
218
|
-
|
|
219
|
-
|
|
241
|
+
const controller = attachStageDrawerDrag(node, stage, editor, () => panel.current.focus({preventScroll: true}),
|
|
242
|
+
(position: StageDrawerPosition) => updateStageDrawer?.({position}));
|
|
243
|
+
stageDrag.current = controller;
|
|
244
|
+
return () => {
|
|
245
|
+
stageDrag.current = null;
|
|
246
|
+
controller.dispose();
|
|
247
|
+
};
|
|
248
|
+
}, [movableStage, updateStageDrawer]);
|
|
249
|
+
useLayoutEffect(() => {
|
|
250
|
+
stageDrag.current?.setPosition(stageDrawerLayout?.position);
|
|
251
|
+
}, [movableStage, stageDrawerLayout?.position, updateStageDrawer]);
|
|
220
252
|
|
|
221
253
|
useLayoutEffect(() => {
|
|
222
254
|
if (!holdOpenSelector) return;
|
|
@@ -248,6 +280,7 @@ export function createStandardLayout(React, {styles, targetStyles, context, Layo
|
|
|
248
280
|
if (panel.current.contains(event.target as Node)) setEngaged(true);
|
|
249
281
|
};
|
|
250
282
|
const blur = (event: FocusEvent) => {
|
|
283
|
+
if (keepOpenOnBlur) return;
|
|
251
284
|
const target = event.relatedTarget as Node;
|
|
252
285
|
const source = event.target as HTMLButtonElement;
|
|
253
286
|
// Opening the stage disables the launcher before focus moves into the drawer.
|
|
@@ -267,7 +300,7 @@ export function createStandardLayout(React, {styles, targetStyles, context, Layo
|
|
|
267
300
|
if (!focusPanelRef) return;
|
|
268
301
|
focusPanelRef.current = focusPanel;
|
|
269
302
|
return () => {focusPanelRef.current = null;};
|
|
270
|
-
}, [focusPanelRef, available]);
|
|
303
|
+
}, [focusPanelRef, available, setEngaged]);
|
|
271
304
|
|
|
272
305
|
const closePanel = React.useCallback(() => {
|
|
273
306
|
setHovered(false);
|
|
@@ -276,7 +309,7 @@ export function createStandardLayout(React, {styles, targetStyles, context, Layo
|
|
|
276
309
|
if (button?.disabled) {
|
|
277
310
|
button.ownerDocument.defaultView?.requestAnimationFrame(() => button.focus({preventScroll: true}));
|
|
278
311
|
} else button?.focus({preventScroll: true});
|
|
279
|
-
}, [focusBoundary, showTrigger]);
|
|
312
|
+
}, [focusBoundary, showTrigger, setEngaged]);
|
|
280
313
|
useLayoutEffect(() => {
|
|
281
314
|
if (!closePanelRef || !open) return;
|
|
282
315
|
closePanelRef.current = closePanel;
|
|
@@ -293,7 +326,7 @@ export function createStandardLayout(React, {styles, targetStyles, context, Layo
|
|
|
293
326
|
if (!focusBoundary) return;
|
|
294
327
|
focusBoundary.addEventListener('focusout', blur);
|
|
295
328
|
return () => focusBoundary.removeEventListener('focusout', blur);
|
|
296
|
-
}, [focusBoundary]);
|
|
329
|
+
}, [focusBoundary, keepOpenOnBlur, setEngaged]);
|
|
297
330
|
|
|
298
331
|
useLayoutEffect(() => {
|
|
299
332
|
if (!portalContent) return;
|
|
@@ -309,7 +342,21 @@ export function createStandardLayout(React, {styles, targetStyles, context, Layo
|
|
|
309
342
|
node.removeEventListener('focusin', focus);
|
|
310
343
|
node.removeEventListener('focusout', blur);
|
|
311
344
|
};
|
|
312
|
-
}, [portalContent, focusBoundary, open, showTrigger, movableStage]);
|
|
345
|
+
}, [portalContent, focusBoundary, open, showTrigger, movableStage, keepOpenOnBlur, setEngaged]);
|
|
346
|
+
|
|
347
|
+
useLayoutEffect(() => {
|
|
348
|
+
if (!movableStage || keepOpenOnBlur || !open) return;
|
|
349
|
+
const node = drawer.current as HTMLElement;
|
|
350
|
+
const dismiss = (event: PointerEvent) => {
|
|
351
|
+
const target = event.target as Node;
|
|
352
|
+
if (node.contains(target) || focusBoundary?.contains(target)) return;
|
|
353
|
+
setHovered(false);
|
|
354
|
+
setEngaged(false);
|
|
355
|
+
};
|
|
356
|
+
// The restored drawer may be open without having received focus.
|
|
357
|
+
node.ownerDocument.addEventListener('pointerdown', dismiss, true);
|
|
358
|
+
return () => node.ownerDocument.removeEventListener('pointerdown', dismiss, true);
|
|
359
|
+
}, [movableStage, keepOpenOnBlur, open, focusBoundary, setEngaged]);
|
|
313
360
|
|
|
314
361
|
useLayoutEffect(() => {
|
|
315
362
|
if (!portalContent || !movableStage || !open) return;
|
|
@@ -419,10 +466,7 @@ export function createStandardLayout(React, {styles, targetStyles, context, Layo
|
|
|
419
466
|
const {targetsPinned, setTargetsPinned} = useContext(context);
|
|
420
467
|
return element('button', {type: 'button', className: styles.drawerPin, 'aria-label': label, 'aria-pressed': targetsPinned,
|
|
421
468
|
title: label, onClick: () => setTargetsPinned(value => !value)},
|
|
422
|
-
element
|
|
423
|
-
fill: targetsPinned ? 'currentColor' : 'none', stroke: 'currentColor', strokeWidth: 1.2, strokeLinejoin: 'round'},
|
|
424
|
-
element('path', {d: 'M9 2 14 7 12 8l-2 3-5-5 3-2 1-2Z'}), element('path', {d: 'm7.5 8.5-4 4'}),
|
|
425
|
-
!targetsPinned && element('path', {d: 'M2 2l12 12', strokeLinecap: 'round'})));
|
|
469
|
+
drawerPinIcon(element, targetsPinned));
|
|
426
470
|
}
|
|
427
471
|
|
|
428
472
|
function useSpriteListTools() {
|
package/src/workspace-layout.ts
CHANGED
|
@@ -14,6 +14,19 @@ export interface WindowPosition {left: number; top: number; width: number; heigh
|
|
|
14
14
|
/** Panels that were open in one separate window when the layout was saved. */
|
|
15
15
|
export interface SavedPopout {panels: string[]; position?: WindowPosition}
|
|
16
16
|
|
|
17
|
+
/** Coordinates along the drawer's available travel, with at least one axis at an edge. */
|
|
18
|
+
export interface StageDrawerPosition {x: number; y: number}
|
|
19
|
+
|
|
20
|
+
export interface StageDrawerLayout {
|
|
21
|
+
open: boolean;
|
|
22
|
+
/** Keep the drawer selected after it folds into the edge. */
|
|
23
|
+
selected: boolean;
|
|
24
|
+
/** Missing in older records, which use the default pinned behavior. */
|
|
25
|
+
pinned?: boolean;
|
|
26
|
+
position?: StageDrawerPosition;
|
|
27
|
+
width?: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
17
30
|
export interface WorkspaceLayout {
|
|
18
31
|
version: 1;
|
|
19
32
|
project: string;
|
|
@@ -21,6 +34,7 @@ export interface WorkspaceLayout {
|
|
|
21
34
|
activeGroup: string;
|
|
22
35
|
editingView?: string;
|
|
23
36
|
panels: Record<string, PanelReference>;
|
|
37
|
+
stageDrawer?: StageDrawerLayout;
|
|
24
38
|
/** Separate windows are restored docked; the user reopens each one. */
|
|
25
39
|
popouts?: SavedPopout[];
|
|
26
40
|
}
|
|
@@ -191,11 +205,28 @@ export function readWorkspaceLayout(raw: string, project?: string): WorkspaceLay
|
|
|
191
205
|
if (editingView !== undefined && (!validId(editingView) || panels[editingView]?.kind !== 'sprite')) return;
|
|
192
206
|
const popouts = readPopouts(input.popouts, panels);
|
|
193
207
|
if (!popouts) return;
|
|
208
|
+
const stageDrawer = readStageDrawer(input.stageDrawer);
|
|
194
209
|
return {version: 1, project: input.project, grid: {root, width, height, orientation}, activeGroup: input.activeGroup,
|
|
195
210
|
editingView: typeof editingView === 'string' ? editingView : undefined, panels,
|
|
211
|
+
...(stageDrawer && {stageDrawer}),
|
|
196
212
|
...(popouts.length && {popouts})};
|
|
197
213
|
}
|
|
198
214
|
|
|
215
|
+
function readStageDrawer(input: unknown): StageDrawerLayout | undefined {
|
|
216
|
+
if (!record(input) || typeof input.open !== 'boolean' || typeof input.selected !== 'boolean') return;
|
|
217
|
+
const {position, width, pinned} = input;
|
|
218
|
+
const fraction = (value: unknown): value is number => size(value) && value <= 1;
|
|
219
|
+
const edge = (value: number) => value === 0 || value === 1;
|
|
220
|
+
return {
|
|
221
|
+
open: input.open,
|
|
222
|
+
selected: input.open || input.selected,
|
|
223
|
+
...(typeof pinned === 'boolean' && {pinned}),
|
|
224
|
+
...(size(width) && width > 0 && {width}),
|
|
225
|
+
...(record(position) && fraction(position.x) && fraction(position.y) &&
|
|
226
|
+
(edge(position.x) || edge(position.y)) && {position: {x: position.x, y: position.y}})
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
199
230
|
function readPopouts(input: unknown, panels: WorkspaceLayout['panels']): SavedPopout[] | undefined {
|
|
200
231
|
if (input === undefined) return [];
|
|
201
232
|
if (!Array.isArray(input) || input.length > limit) return;
|