@kubohiroya/turbowarp-plus-editor-workbench 0.6.0 → 0.8.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 +29 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/sprite-layout-menu.d.ts +1 -0
- package/dist/sprite-layout-menu.js +2 -1
- package/dist/sprite-tabs.js +46 -16
- package/dist/stage-drawer-drag.d.ts +5 -0
- package/dist/stage-drawer-drag.js +137 -0
- package/dist/stage-launcher.d.ts +11 -5
- package/dist/stage-launcher.js +52 -70
- package/dist/stage-resize-handle.d.ts +26 -0
- package/dist/stage-resize-handle.js +53 -0
- package/dist/stage-surface.d.ts +12 -3
- package/dist/stage-surface.js +25 -6
- package/dist/standard-layout.d.ts +10 -2
- package/dist/standard-layout.js +117 -26
- package/dist/target-tab-menu.d.ts +5 -1
- package/dist/target-tab-menu.js +7 -3
- package/dist/workspace-layout.d.ts +13 -0
- package/dist/workspace-layout.js +16 -0
- package/package.json +1 -1
- package/src/dockview-stage.ts +34 -3
- package/src/editor.css +145 -19
- package/src/index.ts +1 -0
- package/src/sprite-layout-menu.ts +3 -1
- package/src/sprite-tabs.ts +44 -15
- package/src/stage-drawer-drag.ts +138 -0
- package/src/stage-launcher.ts +60 -80
- package/src/stage-resize-handle.ts +47 -0
- package/src/stage-surface.ts +30 -7
- package/src/standard-layout.ts +114 -25
- package/src/target-tab-menu.ts +8 -3
- package/src/workspace-layout.ts +28 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export function StageResizeHandle({ edge, aspect, width, limits, label, className, drawer = false }) {
|
|
3
|
+
const drag = React.useRef(null);
|
|
4
|
+
const corner = edge === 'corner';
|
|
5
|
+
const horizontal = edge === 'left' || edge === 'right';
|
|
6
|
+
const resize = next => limits.resize(Math.round(Math.max(limits.minimum, Math.min(limits.maximum, next))));
|
|
7
|
+
return React.createElement('div', {
|
|
8
|
+
className,
|
|
9
|
+
'data-stage-resize': edge,
|
|
10
|
+
'data-stage-drawer-resize': drawer || undefined,
|
|
11
|
+
role: corner ? undefined : 'separator',
|
|
12
|
+
'aria-orientation': corner ? undefined : (horizontal ? 'vertical' : 'horizontal'),
|
|
13
|
+
'aria-label': corner ? undefined : label,
|
|
14
|
+
'aria-valuemin': corner ? undefined : limits.minimum,
|
|
15
|
+
'aria-valuemax': corner ? undefined : limits.maximum,
|
|
16
|
+
'aria-valuenow': corner ? undefined : width,
|
|
17
|
+
tabIndex: corner ? undefined : 0,
|
|
18
|
+
title: label,
|
|
19
|
+
onPointerDown: event => {
|
|
20
|
+
if (event.button !== 0 || drag.current)
|
|
21
|
+
return;
|
|
22
|
+
drag.current = { id: event.pointerId, x: event.clientX, y: event.clientY, width };
|
|
23
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
24
|
+
event.preventDefault();
|
|
25
|
+
},
|
|
26
|
+
onPointerMove: event => {
|
|
27
|
+
const start = drag.current;
|
|
28
|
+
if (start?.id !== event.pointerId)
|
|
29
|
+
return;
|
|
30
|
+
const dx = (event.clientX - start.x) * (edge === 'right' ? 1 : -1);
|
|
31
|
+
const dy = (event.clientY - start.y) * aspect * (edge === 'top' ? -1 : 1);
|
|
32
|
+
const delta = corner ? (Math.abs(dx) >= Math.abs(dy) ? dx : dy) : (horizontal ? dx : dy);
|
|
33
|
+
resize(start.width + delta);
|
|
34
|
+
},
|
|
35
|
+
onLostPointerCapture: () => { drag.current = null; },
|
|
36
|
+
onKeyDown: event => {
|
|
37
|
+
const grow = { left: 'ArrowLeft', right: 'ArrowRight', top: 'ArrowUp', bottom: 'ArrowDown' }[edge];
|
|
38
|
+
const shrink = { left: 'ArrowRight', right: 'ArrowLeft', top: 'ArrowDown', bottom: 'ArrowUp' }[edge];
|
|
39
|
+
if (event.key === grow)
|
|
40
|
+
resize(width + 16);
|
|
41
|
+
else if (event.key === shrink)
|
|
42
|
+
resize(width - 16);
|
|
43
|
+
else if (event.key === 'Home')
|
|
44
|
+
resize(limits.minimum);
|
|
45
|
+
else if (event.key === 'End')
|
|
46
|
+
resize(limits.maximum);
|
|
47
|
+
else
|
|
48
|
+
return;
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
event.stopPropagation();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
package/dist/stage-surface.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import type { Context, ElementType } from 'react';
|
|
|
2
2
|
import type { useDockviewStage } from './dockview-stage.ts';
|
|
3
3
|
import { type StageDockAction, type StageLauncherOptions } from './stage-launcher.ts';
|
|
4
4
|
export type { StageDockAction, StageLauncherOptions } from './stage-launcher.ts';
|
|
5
|
+
export { stagePresentationItems, useStageDocumentFullscreen } from './stage-launcher.ts';
|
|
6
|
+
export { StageResizeHandle } from './stage-resize-handle.ts';
|
|
5
7
|
interface StageWindowConnection<Target> {
|
|
6
8
|
ready: Promise<Target>;
|
|
7
9
|
disconnected: AbortSignal;
|
|
@@ -18,8 +20,8 @@ export declare function stageDockActionLabel(locale: string, { drawer, detached,
|
|
|
18
20
|
drawer?: boolean;
|
|
19
21
|
detached: boolean;
|
|
20
22
|
external?: boolean;
|
|
21
|
-
}): "
|
|
22
|
-
type StagePlacement = Pick<NonNullable<ReturnType<typeof useDockviewStage>>, 'surface' | 'inlineRef' | 'docked'> & Partial<Pick<NonNullable<ReturnType<typeof useDockviewStage>>, 'commands'>>;
|
|
23
|
+
}): "ステージをエディターに戻す" | "Dock stage" | "ステージを別ウィンドウで開く" | "別ウィンドウで開く" | "Open in a separate window" | "アンドック" | "Undock stage";
|
|
24
|
+
type StagePlacement = Pick<NonNullable<ReturnType<typeof useDockviewStage>>, 'surface' | 'inlineRef' | 'docked'> & Partial<Pick<NonNullable<ReturnType<typeof useDockviewStage>>, 'commands' | 'drawerLayout' | 'updateDrawer' | 'resetDrawerPresentation'>>;
|
|
23
25
|
export declare function createStageSurface(React: typeof import('react'), { context, EdgeDrawer, Panel }: {
|
|
24
26
|
context: Context<{
|
|
25
27
|
locale: string;
|
|
@@ -30,10 +32,17 @@ export declare function createStageSurface(React: typeof import('react'), { cont
|
|
|
30
32
|
}>;
|
|
31
33
|
EdgeDrawer: ElementType;
|
|
32
34
|
Panel: ElementType;
|
|
33
|
-
}): ({ externalHost, onDockActionChange, placement, dockAction, launcher, ...props }: {
|
|
35
|
+
}): ({ externalHost, onDockActionChange, placement, dockAction, launcher, openDrawerRef, closeDrawerRef, editorFullscreen, ...props }: {
|
|
34
36
|
placement?: StagePlacement;
|
|
35
37
|
dockAction?: StageDockAction;
|
|
36
38
|
launcher?: StageLauncherOptions;
|
|
39
|
+
openDrawerRef?: {
|
|
40
|
+
current: (() => void) | null;
|
|
41
|
+
};
|
|
42
|
+
closeDrawerRef?: {
|
|
43
|
+
current: (() => void) | null;
|
|
44
|
+
};
|
|
45
|
+
editorFullscreen?: boolean;
|
|
37
46
|
[key: string]: any;
|
|
38
47
|
}) => import("react").FunctionComponentElement<{
|
|
39
48
|
children?: import("react").ReactNode | undefined;
|
package/dist/stage-surface.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { createPortal } from 'react-dom';
|
|
2
2
|
import { createDockview, themeLight } from 'dockview';
|
|
3
3
|
import { StageLauncher } from "./stage-launcher.js";
|
|
4
|
+
export { stagePresentationItems, useStageDocumentFullscreen } from "./stage-launcher.js";
|
|
5
|
+
export { StageResizeHandle } from "./stage-resize-handle.js";
|
|
4
6
|
export function createStagePopoutHost(host, title) {
|
|
5
7
|
return {
|
|
6
8
|
open(request) {
|
|
@@ -31,7 +33,8 @@ export function createStagePopoutHost(host, title) {
|
|
|
31
33
|
disableAutoResizing: true
|
|
32
34
|
});
|
|
33
35
|
dockview = view;
|
|
34
|
-
view.
|
|
36
|
+
const group = view.addGroup({ direction: 'right', hideHeader: true });
|
|
37
|
+
view.addPanel({ id: 'stage', component: 'stage', title, position: { referenceGroup: group } });
|
|
35
38
|
removed = view.onDidRemovePanel(disconnect);
|
|
36
39
|
const layout = () => {
|
|
37
40
|
if (mount.clientWidth > 0 && mount.clientHeight > 0)
|
|
@@ -80,10 +83,19 @@ export function stageDockActionLabel(locale, { drawer, detached, external }) {
|
|
|
80
83
|
return japanese ? 'アンドック' : 'Undock stage';
|
|
81
84
|
}
|
|
82
85
|
export function createStageSurface(React, { context, EdgeDrawer, Panel }) {
|
|
83
|
-
return function StageSurface({ externalHost, onDockActionChange, placement, dockAction, launcher, ...props }) {
|
|
86
|
+
return function StageSurface({ externalHost, onDockActionChange, placement, dockAction, launcher, openDrawerRef, closeDrawerRef, editorFullscreen, ...props }) {
|
|
84
87
|
const { locale, stageDrawer, stageHidden, setStageDrawerOpen, setStageVisible } = React.useContext(context);
|
|
85
88
|
const [drawerOpen, setDrawerOpen] = React.useState(false);
|
|
86
|
-
const
|
|
89
|
+
const localDrawerRef = React.useRef(null);
|
|
90
|
+
const focusDrawer = openDrawerRef ?? localDrawerRef;
|
|
91
|
+
const updateDrawer = placement?.updateDrawer;
|
|
92
|
+
const resetDrawerPresentation = placement?.resetDrawerPresentation;
|
|
93
|
+
const drawerLayout = placement?.drawerLayout;
|
|
94
|
+
const stageOutsideDrawer = Boolean(editorFullscreen || dockAction?.kind === 'external' || placement?.docked);
|
|
95
|
+
React.useLayoutEffect(() => {
|
|
96
|
+
if (stageOutsideDrawer)
|
|
97
|
+
resetDrawerPresentation?.();
|
|
98
|
+
}, [stageOutsideDrawer, resetDrawerPresentation, drawerLayout?.open, drawerLayout?.selected]);
|
|
87
99
|
const onOpenChange = React.useCallback((open) => {
|
|
88
100
|
setStageDrawerOpen?.(open);
|
|
89
101
|
setDrawerOpen(open);
|
|
@@ -106,19 +118,26 @@ export function createStageSurface(React, { context, EdgeDrawer, Panel }) {
|
|
|
106
118
|
}) : panel;
|
|
107
119
|
const dock = stageDrawer ? React.createElement(EdgeDrawer, {
|
|
108
120
|
edge: 'right',
|
|
121
|
+
movableStage: true,
|
|
122
|
+
available: !placement?.docked && (!dockAction || dockAction.kind === 'docked'),
|
|
123
|
+
stageDrawerLayout: drawerLayout,
|
|
124
|
+
updateStageDrawer: updateDrawer,
|
|
109
125
|
label: japanese ? 'ステージを展開' : 'Reveal stage',
|
|
110
126
|
onOpenChange,
|
|
111
127
|
focusPanelRef: launcher ? focusDrawer : undefined,
|
|
128
|
+
closePanelRef: launcher ? closeDrawerRef : undefined,
|
|
112
129
|
focusBoundary: launcher?.mount,
|
|
113
|
-
//
|
|
130
|
+
// With the launcher, the handle appears after the drawer has been opened once.
|
|
114
131
|
showTrigger: !launcher,
|
|
115
132
|
portalContent: Boolean(placement),
|
|
116
133
|
holdOpenSelector: '[data-turbowarp-app-shell-source-chooser][role="dialog"][aria-modal="true"]'
|
|
117
134
|
}, inline) : inline;
|
|
118
|
-
const launcherView =
|
|
135
|
+
const launcherView = launcher && (stageDrawer || editorFullscreen) ? createPortal(React.createElement(StageLauncher, {
|
|
119
136
|
locale, options: launcher, dockAction,
|
|
120
137
|
tab: placement?.commands ? { docked: placement.docked, commands: placement.commands } : undefined,
|
|
121
|
-
drawerOpen: drawerOpen && !stageHidden,
|
|
138
|
+
drawerOpen: stageDrawer && drawerOpen && !stageHidden,
|
|
139
|
+
savedDrawerSelected: updateDrawer ? Boolean(drawerLayout?.selected) : undefined,
|
|
140
|
+
editorFullscreen,
|
|
122
141
|
focusDrawer: () => focusDrawer.current?.(),
|
|
123
142
|
revealStage: () => { if (stageHidden)
|
|
124
143
|
setStageVisible?.(true); }
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { DrawerViews } from './drawer-views.ts';
|
|
2
|
+
import type { StageDrawerLayout } from './workspace-layout.ts';
|
|
2
3
|
export type { DrawerMenu, DrawerMenuRenderProps, DrawerRenderProps, DrawerView, DrawerViewId, DrawerViews, HostDrawerViewId } from './drawer-views.ts';
|
|
3
4
|
export declare function createStandardLayout(React: any, { styles, targetStyles, context, LayoutMenu }: {
|
|
4
5
|
styles: any;
|
|
@@ -6,7 +7,7 @@ export declare function createStandardLayout(React: any, { styles, targetStyles,
|
|
|
6
7
|
context: any;
|
|
7
8
|
LayoutMenu: any;
|
|
8
9
|
}): {
|
|
9
|
-
StandardLayout: ({ enabled, splitter, windowLayout, stageActionEnabled, stageDrawer, onPaletteModeChange, windowTools, Container, render, drawerViews, ...props }: {
|
|
10
|
+
StandardLayout: ({ enabled, splitter, windowLayout, stageActionEnabled, stageDrawer, onPaletteModeChange, windowTools, Container, render, drawerViews, stageDrawerLayout, updateStageDrawer, ...props }: {
|
|
10
11
|
[x: string]: any;
|
|
11
12
|
enabled: any;
|
|
12
13
|
splitter: any;
|
|
@@ -18,8 +19,10 @@ export declare function createStandardLayout(React: any, { styles, targetStyles,
|
|
|
18
19
|
Container: any;
|
|
19
20
|
render: any;
|
|
20
21
|
drawerViews?: DrawerViews;
|
|
22
|
+
stageDrawerLayout?: StageDrawerLayout;
|
|
23
|
+
updateStageDrawer?: (patch: Partial<StageDrawerLayout>) => void;
|
|
21
24
|
}) => any;
|
|
22
|
-
EdgeDrawer: ({ edge, label, pinned, onOpenChange, portalContent, holdOpenSelector, focusPanelRef, focusBoundary, showTrigger, children }: {
|
|
25
|
+
EdgeDrawer: ({ edge, label, pinned, onOpenChange, portalContent, holdOpenSelector, focusPanelRef, closePanelRef, focusBoundary, showTrigger, movableStage, available, stageDrawerLayout, updateStageDrawer, children }: {
|
|
23
26
|
edge: any;
|
|
24
27
|
label: any;
|
|
25
28
|
pinned?: boolean;
|
|
@@ -27,8 +30,13 @@ export declare function createStandardLayout(React: any, { styles, targetStyles,
|
|
|
27
30
|
portalContent?: boolean;
|
|
28
31
|
holdOpenSelector?: string;
|
|
29
32
|
focusPanelRef?: any;
|
|
33
|
+
closePanelRef?: any;
|
|
30
34
|
focusBoundary?: any;
|
|
31
35
|
showTrigger?: boolean;
|
|
36
|
+
movableStage?: boolean;
|
|
37
|
+
available?: boolean;
|
|
38
|
+
stageDrawerLayout?: StageDrawerLayout;
|
|
39
|
+
updateStageDrawer?: (patch: Partial<StageDrawerLayout>) => void;
|
|
32
40
|
children: any;
|
|
33
41
|
}) => any;
|
|
34
42
|
TargetLayout: ({ compact, render }: {
|
package/dist/standard-layout.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createLayout, createSplitter, splitAxis } from "./index.js";
|
|
2
2
|
import { createTargetList } from "./targets.js";
|
|
3
3
|
import { availableDrawerViews, createDrawerViewBar, hasDrawerBar, readDrawerView, writeDrawerView } from "./drawer-views.js";
|
|
4
|
+
import { attachStageDrawerDrag } from "./stage-drawer-drag.js";
|
|
4
5
|
const isJapanese = locale => /^ja(?:-|$)/i.test(locale);
|
|
5
6
|
const singleColumnTargetWidth = 108;
|
|
6
7
|
// Views other than the sprite list show file names and commit subjects, so the drawer opens wider for them.
|
|
@@ -15,7 +16,7 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
|
|
|
15
16
|
const DrawerViewBar = createDrawerViewBar(React, styles);
|
|
16
17
|
const targetSearch = React.createContext('');
|
|
17
18
|
const targetTools = React.createContext(null);
|
|
18
|
-
function StandardLayout({ enabled, splitter, windowLayout, stageActionEnabled, stageDrawer = false, onPaletteModeChange, windowTools, Container, render, drawerViews = undefined, ...props }) {
|
|
19
|
+
function StandardLayout({ enabled, splitter, windowLayout, stageActionEnabled, stageDrawer = false, onPaletteModeChange, windowTools, Container, render, drawerViews = undefined, stageDrawerLayout = undefined, updateStageDrawer = undefined, ...props }) {
|
|
19
20
|
const [showUndock, setShowUndock] = useState(false);
|
|
20
21
|
const [targetsPinned, setTargetsPinned] = useState(true);
|
|
21
22
|
const [showStage, setShowStage] = useState(true);
|
|
@@ -63,12 +64,15 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
|
|
|
63
64
|
const resizable = targetSplit && targetSplit.maximum > targetSplit.minimum;
|
|
64
65
|
const editorSpace = targetsPinned ?
|
|
65
66
|
(targetSplit?.second ?? bodyWidth - (wideDrawer ? fixedDrawerWidth : singleColumnTargetWidth)) : bodyWidth;
|
|
66
|
-
const maximumStageWidth = Math.max(1, Math.floor(Math.min(editorSpace - 24, ((size?.height ?? 640) - 112) * props.stageAspect)));
|
|
67
|
+
const maximumStageWidth = Math.max(1, Math.floor(Math.min(editorSpace - 24, stageDrawer ? (size?.viewportWidth ?? bodyWidth) - 12 : Infinity, ((size?.height ?? 640) - 112) * props.stageAspect)));
|
|
67
68
|
const defaultStageWidth = Math.min(maximumStageWidth, Math.floor(Math.min(props.defaultStageWidth, 360, bodyWidth / 2)));
|
|
68
69
|
const minimumStageWidth = Math.min(defaultStageWidth, 280);
|
|
69
|
-
const
|
|
70
|
+
const preferredWidth = stageDrawer && updateStageDrawer ? stageDrawerLayout?.width : preferredStageWidth;
|
|
71
|
+
const resizeStage = stageDrawer && updateStageDrawer ?
|
|
72
|
+
(width) => updateStageDrawer({ width }) : setPreferredStageWidth;
|
|
73
|
+
const stageWidth = Math.max(minimumStageWidth, Math.min(maximumStageWidth, preferredWidth ?? defaultStageWidth));
|
|
70
74
|
const stageResize = plusLayout && maximumStageWidth > minimumStageWidth ?
|
|
71
|
-
{ minimum: minimumStageWidth, maximum: maximumStageWidth, resize:
|
|
75
|
+
{ minimum: minimumStageWidth, maximum: maximumStageWidth, resize: resizeStage } : null;
|
|
72
76
|
useLayoutEffect(() => {
|
|
73
77
|
if (enabled)
|
|
74
78
|
onPaletteModeChange?.(true);
|
|
@@ -80,13 +84,22 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
|
|
|
80
84
|
return;
|
|
81
85
|
const measure = () => {
|
|
82
86
|
const { clientWidth: width, clientHeight: height } = node;
|
|
83
|
-
|
|
87
|
+
const viewportWidth = node.ownerDocument.documentElement.clientWidth;
|
|
88
|
+
setSize(previous => previous?.width === width && previous.height === height &&
|
|
89
|
+
previous.viewportWidth === viewportWidth ? previous : { width, height, viewportWidth });
|
|
84
90
|
};
|
|
85
91
|
const observer = new Observer(measure);
|
|
86
92
|
measure();
|
|
87
93
|
observer.observe(node);
|
|
88
|
-
|
|
89
|
-
|
|
94
|
+
const view = node.ownerDocument.defaultView;
|
|
95
|
+
if (stageDrawer)
|
|
96
|
+
view.addEventListener('resize', measure);
|
|
97
|
+
return () => {
|
|
98
|
+
observer.disconnect();
|
|
99
|
+
if (stageDrawer)
|
|
100
|
+
view.removeEventListener('resize', measure);
|
|
101
|
+
};
|
|
102
|
+
}, [stageDrawer]);
|
|
90
103
|
const renderEditorTabRow = (tabs, action) => element('div', { className: styles.tabRow }, tabs, (layoutMenu || windowTools) && element('div', { className: styles.layoutTools }, layoutMenu, windowTools), action);
|
|
91
104
|
const applyStandardLayout = layout => {
|
|
92
105
|
if (!enabled)
|
|
@@ -107,7 +120,7 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
|
|
|
107
120
|
const stageOverlaps = showStage && (!stageDrawer || stageDrawerOpen);
|
|
108
121
|
const bodyStyle = {
|
|
109
122
|
display: 'grid',
|
|
110
|
-
'--plus-stage-overlap':
|
|
123
|
+
'--plus-stage-overlap': showStage && !stageDrawer ? stageOverlap : '0px',
|
|
111
124
|
'--plus-stage-tab-inset': stageOverlaps ? stageOverlap : '3rem'
|
|
112
125
|
};
|
|
113
126
|
if (resizable) {
|
|
@@ -137,7 +150,7 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
|
|
|
137
150
|
targetClassName: targetsPinned ? styles.standardTargets :
|
|
138
151
|
`${styles.standardTargets} ${styles.retractedTargets}`,
|
|
139
152
|
stageDisplayWidth: stageWidth,
|
|
140
|
-
handleStagePreset: () =>
|
|
153
|
+
handleStagePreset: () => resizeStage(undefined),
|
|
141
154
|
editorWidth: targetsPinned && resizable ? targetSplit.second : size?.width
|
|
142
155
|
};
|
|
143
156
|
};
|
|
@@ -162,14 +175,52 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
|
|
|
162
175
|
drawerViews, drawerView, selectDrawerView
|
|
163
176
|
} }, Container ? element(Container, { locale: props.locale }, layout) : layout);
|
|
164
177
|
}
|
|
165
|
-
function EdgeDrawer({ edge, label, pinned = false, onOpenChange, portalContent = false, holdOpenSelector = '', focusPanelRef = undefined, focusBoundary = undefined, showTrigger = true, children }) {
|
|
178
|
+
function EdgeDrawer({ edge, label, pinned = false, onOpenChange, portalContent = false, holdOpenSelector = '', focusPanelRef = undefined, closePanelRef = undefined, focusBoundary = undefined, showTrigger = true, movableStage = false, available = true, stageDrawerLayout = undefined, updateStageDrawer = undefined, children }) {
|
|
166
179
|
const [hovered, setHovered] = useState(false);
|
|
167
|
-
const [
|
|
180
|
+
const [localEngaged, setLocalEngaged] = useState(false);
|
|
168
181
|
const [heldOpen, setHeldOpen] = useState(false);
|
|
169
182
|
const drawer = useRef(null);
|
|
170
183
|
const trigger = useRef(null);
|
|
171
184
|
const panel = useRef(null);
|
|
172
|
-
const
|
|
185
|
+
const opened = useRef(false);
|
|
186
|
+
const stageDrag = useRef(null);
|
|
187
|
+
const engaged = updateStageDrawer ? Boolean(stageDrawerLayout?.open) : localEngaged;
|
|
188
|
+
const setEngaged = React.useCallback((engaged) => {
|
|
189
|
+
if (updateStageDrawer)
|
|
190
|
+
updateStageDrawer({ open: engaged, ...(engaged && { selected: true }) });
|
|
191
|
+
else
|
|
192
|
+
setLocalEngaged(engaged);
|
|
193
|
+
}, [updateStageDrawer]);
|
|
194
|
+
const selected = updateStageDrawer ? Boolean(stageDrawerLayout?.selected) : opened.current;
|
|
195
|
+
const open = available && (pinned || engaged || heldOpen ||
|
|
196
|
+
(hovered && (!updateStageDrawer || showTrigger || selected)));
|
|
197
|
+
const stageTrigger = movableStage && available && (showTrigger || selected);
|
|
198
|
+
useLayoutEffect(() => {
|
|
199
|
+
if (open)
|
|
200
|
+
opened.current = true;
|
|
201
|
+
if (!available) {
|
|
202
|
+
setHovered(false);
|
|
203
|
+
setLocalEngaged(false);
|
|
204
|
+
}
|
|
205
|
+
}, [open, available]);
|
|
206
|
+
useLayoutEffect(() => {
|
|
207
|
+
if (!movableStage)
|
|
208
|
+
return;
|
|
209
|
+
const node = drawer.current;
|
|
210
|
+
const stage = node.closest(`.${styles.stageDrawer}`);
|
|
211
|
+
const editor = stage?.closest(`.${styles.standardBody}`);
|
|
212
|
+
if (!editor || !node.ownerDocument.defaultView?.ResizeObserver)
|
|
213
|
+
return;
|
|
214
|
+
const controller = attachStageDrawerDrag(node, stage, editor, () => panel.current.focus({ preventScroll: true }), (position) => updateStageDrawer?.({ position }));
|
|
215
|
+
stageDrag.current = controller;
|
|
216
|
+
return () => {
|
|
217
|
+
stageDrag.current = null;
|
|
218
|
+
controller.dispose();
|
|
219
|
+
};
|
|
220
|
+
}, [movableStage, updateStageDrawer]);
|
|
221
|
+
useLayoutEffect(() => {
|
|
222
|
+
stageDrag.current?.setPosition(stageDrawerLayout?.position);
|
|
223
|
+
}, [movableStage, stageDrawerLayout?.position, updateStageDrawer]);
|
|
173
224
|
useLayoutEffect(() => {
|
|
174
225
|
if (!holdOpenSelector)
|
|
175
226
|
return;
|
|
@@ -191,6 +242,8 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
|
|
|
191
242
|
}, [holdOpenSelector]);
|
|
192
243
|
useLayoutEffect(() => { onOpenChange?.(open); }, [open, onOpenChange]);
|
|
193
244
|
const enter = (event) => {
|
|
245
|
+
if (movableStage && !showTrigger && !open)
|
|
246
|
+
return;
|
|
194
247
|
if (event.pointerType === 'mouse')
|
|
195
248
|
setHovered(true);
|
|
196
249
|
};
|
|
@@ -201,10 +254,16 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
|
|
|
201
254
|
};
|
|
202
255
|
const blur = (event) => {
|
|
203
256
|
const target = event.relatedTarget;
|
|
257
|
+
const source = event.target;
|
|
258
|
+
// Opening the stage disables the launcher before focus moves into the drawer.
|
|
259
|
+
if (!target && source.disabled && focusBoundary?.contains(source))
|
|
260
|
+
return;
|
|
204
261
|
if (!drawer.current.contains(target) && !focusBoundary?.contains(target))
|
|
205
262
|
setEngaged(false);
|
|
206
263
|
};
|
|
207
264
|
const focusPanel = () => {
|
|
265
|
+
if (!available)
|
|
266
|
+
return;
|
|
208
267
|
setEngaged(true);
|
|
209
268
|
const frame = drawer.current.ownerDocument.defaultView;
|
|
210
269
|
frame.requestAnimationFrame(() => {
|
|
@@ -217,13 +276,36 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
|
|
|
217
276
|
return;
|
|
218
277
|
focusPanelRef.current = focusPanel;
|
|
219
278
|
return () => { focusPanelRef.current = null; };
|
|
220
|
-
}, [focusPanelRef]);
|
|
279
|
+
}, [focusPanelRef, available, setEngaged]);
|
|
280
|
+
const closePanel = React.useCallback(() => {
|
|
281
|
+
setHovered(false);
|
|
282
|
+
setEngaged(false);
|
|
283
|
+
const button = (showTrigger ? trigger.current : focusBoundary?.querySelector('button'));
|
|
284
|
+
if (button?.disabled) {
|
|
285
|
+
button.ownerDocument.defaultView?.requestAnimationFrame(() => button.focus({ preventScroll: true }));
|
|
286
|
+
}
|
|
287
|
+
else
|
|
288
|
+
button?.focus({ preventScroll: true });
|
|
289
|
+
}, [focusBoundary, showTrigger, setEngaged]);
|
|
290
|
+
useLayoutEffect(() => {
|
|
291
|
+
if (!closePanelRef || !open)
|
|
292
|
+
return;
|
|
293
|
+
closePanelRef.current = closePanel;
|
|
294
|
+
return () => { closePanelRef.current = null; };
|
|
295
|
+
}, [closePanelRef, closePanel, open]);
|
|
296
|
+
const closeOnEscape = event => {
|
|
297
|
+
if (event.key !== 'Escape' || pinned || heldOpen || !open || event.defaultPrevented ||
|
|
298
|
+
(movableStage && event.target.closest('[role="menu"]')))
|
|
299
|
+
return;
|
|
300
|
+
closePanel();
|
|
301
|
+
event.stopPropagation();
|
|
302
|
+
};
|
|
221
303
|
useLayoutEffect(() => {
|
|
222
304
|
if (!focusBoundary)
|
|
223
305
|
return;
|
|
224
306
|
focusBoundary.addEventListener('focusout', blur);
|
|
225
307
|
return () => focusBoundary.removeEventListener('focusout', blur);
|
|
226
|
-
}, [focusBoundary]);
|
|
308
|
+
}, [focusBoundary, setEngaged]);
|
|
227
309
|
useLayoutEffect(() => {
|
|
228
310
|
if (!portalContent)
|
|
229
311
|
return;
|
|
@@ -239,31 +321,40 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
|
|
|
239
321
|
node.removeEventListener('focusin', focus);
|
|
240
322
|
node.removeEventListener('focusout', blur);
|
|
241
323
|
};
|
|
242
|
-
}, [portalContent, focusBoundary]);
|
|
324
|
+
}, [portalContent, focusBoundary, open, showTrigger, movableStage, setEngaged]);
|
|
325
|
+
useLayoutEffect(() => {
|
|
326
|
+
if (!portalContent || !movableStage || !open)
|
|
327
|
+
return;
|
|
328
|
+
const node = drawer.current;
|
|
329
|
+
node.addEventListener('keydown', closeOnEscape);
|
|
330
|
+
return () => node.removeEventListener('keydown', closeOnEscape);
|
|
331
|
+
}, [portalContent, movableStage, open, heldOpen, pinned, closePanel]);
|
|
243
332
|
return element('div', {
|
|
244
333
|
className: styles.edgeDrawer,
|
|
245
334
|
ref: drawer,
|
|
246
335
|
'data-edge': edge,
|
|
247
336
|
'data-pinned': pinned || undefined,
|
|
337
|
+
'data-movable-stage': movableStage || undefined,
|
|
338
|
+
'data-stage-drawer-open': movableStage && open || undefined,
|
|
339
|
+
'data-stage-drawer-unavailable': movableStage && !available || undefined,
|
|
248
340
|
...(!portalContent && { onPointerEnter: enter, onPointerLeave: leave, onFocus: focus, onBlur: blur }),
|
|
249
|
-
onKeyDown:
|
|
250
|
-
|
|
251
|
-
return;
|
|
252
|
-
setHovered(false);
|
|
253
|
-
setEngaged(false);
|
|
254
|
-
// Without its own trigger, the drawer returns focus to the control that opened it.
|
|
255
|
-
(trigger.current ?? focusBoundary?.querySelector('button'))?.focus();
|
|
256
|
-
event.stopPropagation();
|
|
257
|
-
}
|
|
258
|
-
}, showTrigger && element('button', {
|
|
341
|
+
onKeyDown: portalContent && movableStage ? undefined : closeOnEscape
|
|
342
|
+
}, (movableStage ? stageTrigger : showTrigger) && element('button', {
|
|
259
343
|
type: 'button',
|
|
260
344
|
className: styles.edgeTrigger,
|
|
261
345
|
hidden: pinned,
|
|
262
346
|
'aria-label': label,
|
|
263
347
|
'aria-expanded': open,
|
|
348
|
+
'data-stage-drawer-trigger': movableStage || undefined,
|
|
349
|
+
'data-stage-drawer-trigger-collapsed': movableStage && !showTrigger || undefined,
|
|
264
350
|
ref: trigger,
|
|
265
351
|
onClick: focusPanel
|
|
266
|
-
}, { left: '›', right: '‹', bottom: '⌃' }[edge]), element('div', {
|
|
352
|
+
}, movableStage ? null : { left: '›', right: '‹', bottom: '⌃' }[edge]), element('div', {
|
|
353
|
+
className: styles.edgePanel, ref: panel, tabIndex: -1,
|
|
354
|
+
hidden: !movableStage && !open,
|
|
355
|
+
'aria-hidden': movableStage && !open || undefined,
|
|
356
|
+
inert: movableStage && !open ? '' : undefined
|
|
357
|
+
}, children));
|
|
267
358
|
}
|
|
268
359
|
function TargetLayout({ compact, render }) {
|
|
269
360
|
const { plusLayout, targetsPinned, locale, drawerViews, drawerView = 'sprites', selectDrawerView } = useContext(context);
|
|
@@ -15,9 +15,13 @@ interface MenuPrimitives {
|
|
|
15
15
|
menuClassName: string;
|
|
16
16
|
itemClassName: string;
|
|
17
17
|
}
|
|
18
|
+
declare const tabMenuIcons: {
|
|
19
|
+
rename: string;
|
|
20
|
+
'new-tab': string;
|
|
21
|
+
};
|
|
18
22
|
export declare const spriteRenameLabel: (locale: string) => "スプライト名の変更" | "Rename sprite";
|
|
19
23
|
export declare const SpriteTargetTabsContext: React.Context<TargetTabs>;
|
|
20
|
-
export declare function
|
|
24
|
+
export declare function createTargetTabMenuItem(document: Document, title: string, iconName: keyof typeof tabMenuIcons, action: (id: string) => void): IContextMenuItemRenderer;
|
|
21
25
|
export declare function useTargetTabMenu(): {
|
|
22
26
|
onShow(id?: string): void;
|
|
23
27
|
select: (id?: string) => void;
|
package/dist/target-tab-menu.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
const pencil = 'm4 16-1 5 5-1L21 7l-4-4L4 16Zm10-10 4 4';
|
|
3
3
|
const open = 'M13 4h7v7m0-7-9 9m-1-8H4v15h15v-6';
|
|
4
|
+
const tabMenuIcons = {
|
|
5
|
+
rename: pencil,
|
|
6
|
+
'new-tab': 'M3 4h18v16H3zM3 10h18M11 4l3 6m-4 5h4m-2-2v4'
|
|
7
|
+
};
|
|
4
8
|
const iconClass = 'tw-plus-target-menu-icon';
|
|
5
9
|
const svgNamespace = 'http://www.w3.org/2000/svg';
|
|
6
10
|
const isJapanese = (locale) => /^ja(?:-|$)/i.test(locale);
|
|
7
11
|
export const spriteRenameLabel = (locale) => isJapanese(locale) ? 'スプライト名の変更' : 'Rename sprite';
|
|
8
12
|
export const SpriteTargetTabsContext = React.createContext(null);
|
|
9
|
-
export function
|
|
13
|
+
export function createTargetTabMenuItem(document, title, iconName, action) {
|
|
10
14
|
const element = document.createElement('button');
|
|
11
15
|
element.type = 'button';
|
|
12
16
|
element.className = 'dv-context-menu-item tw-plus-target-menu-button';
|
|
@@ -16,7 +20,7 @@ export function createRenameMenuItem(document, title, rename) {
|
|
|
16
20
|
icon.setAttribute('viewBox', '0 0 24 24');
|
|
17
21
|
icon.setAttribute('aria-hidden', 'true');
|
|
18
22
|
const path = document.createElementNS(svgNamespace, 'path');
|
|
19
|
-
path.setAttribute('d',
|
|
23
|
+
path.setAttribute('d', tabMenuIcons[iconName]);
|
|
20
24
|
icon.append(path);
|
|
21
25
|
element.append(icon, title);
|
|
22
26
|
return {
|
|
@@ -26,7 +30,7 @@ export function createRenameMenuItem(document, title, rename) {
|
|
|
26
30
|
return;
|
|
27
31
|
element.onclick = () => {
|
|
28
32
|
props.close();
|
|
29
|
-
|
|
33
|
+
action(props.panel.id);
|
|
30
34
|
};
|
|
31
35
|
},
|
|
32
36
|
dispose() {
|
|
@@ -23,6 +23,18 @@ export interface SavedPopout {
|
|
|
23
23
|
panels: string[];
|
|
24
24
|
position?: WindowPosition;
|
|
25
25
|
}
|
|
26
|
+
/** Coordinates along the drawer's available travel, with at least one axis at an edge. */
|
|
27
|
+
export interface StageDrawerPosition {
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
}
|
|
31
|
+
export interface StageDrawerLayout {
|
|
32
|
+
open: boolean;
|
|
33
|
+
/** Keep the drawer selected after it folds into the edge. */
|
|
34
|
+
selected: boolean;
|
|
35
|
+
position?: StageDrawerPosition;
|
|
36
|
+
width?: number;
|
|
37
|
+
}
|
|
26
38
|
export interface WorkspaceLayout {
|
|
27
39
|
version: 1;
|
|
28
40
|
project: string;
|
|
@@ -30,6 +42,7 @@ export interface WorkspaceLayout {
|
|
|
30
42
|
activeGroup: string;
|
|
31
43
|
editingView?: string;
|
|
32
44
|
panels: Record<string, PanelReference>;
|
|
45
|
+
stageDrawer?: StageDrawerLayout;
|
|
33
46
|
/** Separate windows are restored docked; the user reopens each one. */
|
|
34
47
|
popouts?: SavedPopout[];
|
|
35
48
|
}
|
package/dist/workspace-layout.js
CHANGED
|
@@ -189,10 +189,26 @@ export function readWorkspaceLayout(raw, project) {
|
|
|
189
189
|
const popouts = readPopouts(input.popouts, panels);
|
|
190
190
|
if (!popouts)
|
|
191
191
|
return;
|
|
192
|
+
const stageDrawer = readStageDrawer(input.stageDrawer);
|
|
192
193
|
return { version: 1, project: input.project, grid: { root, width, height, orientation }, activeGroup: input.activeGroup,
|
|
193
194
|
editingView: typeof editingView === 'string' ? editingView : undefined, panels,
|
|
195
|
+
...(stageDrawer && { stageDrawer }),
|
|
194
196
|
...(popouts.length && { popouts }) };
|
|
195
197
|
}
|
|
198
|
+
function readStageDrawer(input) {
|
|
199
|
+
if (!record(input) || typeof input.open !== 'boolean' || typeof input.selected !== 'boolean')
|
|
200
|
+
return;
|
|
201
|
+
const { position, width } = input;
|
|
202
|
+
const fraction = (value) => size(value) && value <= 1;
|
|
203
|
+
const edge = (value) => value === 0 || value === 1;
|
|
204
|
+
return {
|
|
205
|
+
open: input.open,
|
|
206
|
+
selected: input.open || input.selected,
|
|
207
|
+
...(size(width) && width > 0 && { width }),
|
|
208
|
+
...(record(position) && fraction(position.x) && fraction(position.y) &&
|
|
209
|
+
(edge(position.x) || edge(position.y)) && { position: { x: position.x, y: position.y } })
|
|
210
|
+
};
|
|
211
|
+
}
|
|
196
212
|
function readPopouts(input, panels) {
|
|
197
213
|
if (input === undefined)
|
|
198
214
|
return [];
|
package/package.json
CHANGED
package/src/dockview-stage.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import type {StageDrawerLayout} from './workspace-layout.ts';
|
|
2
3
|
|
|
3
4
|
type StageCommands = {open(): void; close(): void};
|
|
4
5
|
|
|
@@ -6,6 +7,11 @@ export interface DockviewStagePane {
|
|
|
6
7
|
title: string;
|
|
7
8
|
attach(destination: HTMLElement | null): void;
|
|
8
9
|
connect(commands: StageCommands | null): void;
|
|
10
|
+
drawer?: {
|
|
11
|
+
read(): StageDrawerLayout | undefined;
|
|
12
|
+
restore(layout?: StageDrawerLayout): void;
|
|
13
|
+
subscribe(listener: () => void): () => void;
|
|
14
|
+
};
|
|
9
15
|
}
|
|
10
16
|
|
|
11
17
|
export function useDockviewStage(enabled: boolean, locale: string) {
|
|
@@ -20,6 +26,23 @@ export function useDockviewStage(enabled: boolean, locale: string) {
|
|
|
20
26
|
const suspended = React.useRef(false);
|
|
21
27
|
const [docked, setDocked] = React.useState(false);
|
|
22
28
|
const [commands, setCommands] = React.useState<StageCommands>(null);
|
|
29
|
+
const [drawerLayout, setDrawerLayout] = React.useState<StageDrawerLayout>();
|
|
30
|
+
const savedDrawer = React.useRef<StageDrawerLayout>();
|
|
31
|
+
const drawerListeners = React.useMemo(() => new Set<() => void>(), []);
|
|
32
|
+
const restoreDrawer = React.useCallback((layout?: StageDrawerLayout) => {
|
|
33
|
+
savedDrawer.current = layout;
|
|
34
|
+
setDrawerLayout(layout);
|
|
35
|
+
}, []);
|
|
36
|
+
const updateDrawer = React.useCallback((patch: Partial<StageDrawerLayout>) => {
|
|
37
|
+
const previous = savedDrawer.current;
|
|
38
|
+
const next = {open: false, selected: false, ...previous, ...patch};
|
|
39
|
+
if (next.open === Boolean(previous?.open) && next.selected === Boolean(previous?.selected) &&
|
|
40
|
+
next.position === previous?.position && next.width === previous?.width) return;
|
|
41
|
+
restoreDrawer(next.open || next.selected || next.position || next.width ? next : undefined);
|
|
42
|
+
for (const listener of drawerListeners) listener();
|
|
43
|
+
}, [drawerListeners, restoreDrawer]);
|
|
44
|
+
const resetDrawerPresentation = React.useCallback(() => updateDrawer({open: false, selected: false}),
|
|
45
|
+
[updateDrawer]);
|
|
23
46
|
|
|
24
47
|
const move = React.useCallback(() => {
|
|
25
48
|
const destination = suspended.current ? inline.current : dock.current ?? inline.current;
|
|
@@ -43,10 +66,18 @@ export function useDockviewStage(enabled: boolean, locale: string) {
|
|
|
43
66
|
move();
|
|
44
67
|
setDocked(Boolean(destination));
|
|
45
68
|
},
|
|
46
|
-
connect: setCommands
|
|
47
|
-
|
|
69
|
+
connect: setCommands,
|
|
70
|
+
drawer: {
|
|
71
|
+
read: () => savedDrawer.current,
|
|
72
|
+
restore: restoreDrawer,
|
|
73
|
+
subscribe(listener) {
|
|
74
|
+
drawerListeners.add(listener);
|
|
75
|
+
return () => {drawerListeners.delete(listener);};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}), [japanese, move, restoreDrawer, drawerListeners]);
|
|
48
79
|
return surface && {
|
|
49
|
-
surface, pane, docked, commands, inlineRef, suspend,
|
|
80
|
+
surface, pane, docked, commands, inlineRef, suspend, drawerLayout, updateDrawer, resetDrawerPresentation,
|
|
50
81
|
openLabel: japanese ? 'ステージをタブで開く' : 'Open stage in workspace',
|
|
51
82
|
closeLabel: japanese ? 'ステージを元の位置に戻す' : 'Return stage from workspace'
|
|
52
83
|
};
|