@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
package/dist/dockview-stage.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { StageDrawerLayout } from './workspace-layout.ts';
|
|
1
2
|
type StageCommands = {
|
|
2
3
|
open(): void;
|
|
3
4
|
close(): void;
|
|
@@ -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
|
export declare function useDockviewStage(enabled: boolean, locale: string): {
|
|
11
17
|
surface: HTMLDivElement;
|
|
@@ -14,6 +20,9 @@ export declare function useDockviewStage(enabled: boolean, locale: string): {
|
|
|
14
20
|
commands: StageCommands;
|
|
15
21
|
inlineRef: (element: HTMLElement | null) => void;
|
|
16
22
|
suspend: (value: boolean) => void;
|
|
23
|
+
drawerLayout: StageDrawerLayout;
|
|
24
|
+
updateDrawer: (patch: Partial<StageDrawerLayout>) => void;
|
|
25
|
+
resetDrawerPresentation: () => void;
|
|
17
26
|
openLabel: string;
|
|
18
27
|
closeLabel: string;
|
|
19
28
|
};
|
package/dist/dockview-stage.js
CHANGED
|
@@ -12,6 +12,24 @@ export function useDockviewStage(enabled, locale) {
|
|
|
12
12
|
const suspended = React.useRef(false);
|
|
13
13
|
const [docked, setDocked] = React.useState(false);
|
|
14
14
|
const [commands, setCommands] = React.useState(null);
|
|
15
|
+
const [drawerLayout, setDrawerLayout] = React.useState();
|
|
16
|
+
const savedDrawer = React.useRef();
|
|
17
|
+
const drawerListeners = React.useMemo(() => new Set(), []);
|
|
18
|
+
const restoreDrawer = React.useCallback((layout) => {
|
|
19
|
+
savedDrawer.current = layout;
|
|
20
|
+
setDrawerLayout(layout);
|
|
21
|
+
}, []);
|
|
22
|
+
const updateDrawer = React.useCallback((patch) => {
|
|
23
|
+
const previous = savedDrawer.current;
|
|
24
|
+
const next = { open: false, selected: false, ...previous, ...patch };
|
|
25
|
+
if (next.open === Boolean(previous?.open) && next.selected === Boolean(previous?.selected) &&
|
|
26
|
+
next.position === previous?.position && next.width === previous?.width)
|
|
27
|
+
return;
|
|
28
|
+
restoreDrawer(next.open || next.selected || next.position || next.width ? next : undefined);
|
|
29
|
+
for (const listener of drawerListeners)
|
|
30
|
+
listener();
|
|
31
|
+
}, [drawerListeners, restoreDrawer]);
|
|
32
|
+
const resetDrawerPresentation = React.useCallback(() => updateDrawer({ open: false, selected: false }), [updateDrawer]);
|
|
15
33
|
const move = React.useCallback(() => {
|
|
16
34
|
const destination = suspended.current ? inline.current : dock.current ?? inline.current;
|
|
17
35
|
if (surface && destination && surface.parentElement !== destination)
|
|
@@ -35,10 +53,18 @@ export function useDockviewStage(enabled, locale) {
|
|
|
35
53
|
move();
|
|
36
54
|
setDocked(Boolean(destination));
|
|
37
55
|
},
|
|
38
|
-
connect: setCommands
|
|
39
|
-
|
|
56
|
+
connect: setCommands,
|
|
57
|
+
drawer: {
|
|
58
|
+
read: () => savedDrawer.current,
|
|
59
|
+
restore: restoreDrawer,
|
|
60
|
+
subscribe(listener) {
|
|
61
|
+
drawerListeners.add(listener);
|
|
62
|
+
return () => { drawerListeners.delete(listener); };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}), [japanese, move, restoreDrawer, drawerListeners]);
|
|
40
66
|
return surface && {
|
|
41
|
-
surface, pane, docked, commands, inlineRef, suspend,
|
|
67
|
+
surface, pane, docked, commands, inlineRef, suspend, drawerLayout, updateDrawer, resetDrawerPresentation,
|
|
42
68
|
openLabel: japanese ? 'ステージをタブで開く' : 'Open stage in workspace',
|
|
43
69
|
closeLabel: japanese ? 'ステージを元の位置に戻す' : 'Return stage from workspace'
|
|
44
70
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { attachExternalMonitorDrag } from './monitor-drag.ts';
|
|
2
2
|
export { attachStageInput } from './stage-input.ts';
|
|
3
|
+
export { panelLayoutIconPath } from './sprite-layout-menu.ts';
|
|
3
4
|
type Axis = 'columns' | 'rows';
|
|
4
5
|
type Ratios = Record<Axis, number | null>;
|
|
5
6
|
type LayoutStorage = Pick<Storage, 'getItem' | 'setItem'>;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { attachExternalMonitorDrag } from "./monitor-drag.js";
|
|
2
2
|
export { attachStageInput } from "./stage-input.js";
|
|
3
|
+
export { panelLayoutIconPath } from "./sprite-layout-menu.js";
|
|
3
4
|
const separatorSize = 8;
|
|
4
5
|
const keyboardStep = 16;
|
|
5
6
|
export function splitAxis(length, ratio, fallback, minimumFirst, minimumSecond) {
|
|
@@ -12,6 +12,7 @@ interface SpriteLayoutCommands {
|
|
|
12
12
|
verticalTabs?(): boolean;
|
|
13
13
|
setVerticalTabs?(vertical: boolean): void;
|
|
14
14
|
}
|
|
15
|
+
export declare const panelLayoutIconPath = "M2.5 3.5h11v9h-11zM2.5 6.5h11m-7 0v6";
|
|
15
16
|
export declare function createSpriteLayoutMenu(document: Document, locale: string, commands: SpriteLayoutCommands): {
|
|
16
17
|
element: HTMLDivElement;
|
|
17
18
|
dispose: () => void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export const panelLayoutIconPath = 'M2.5 3.5h11v9h-11zM2.5 6.5h11m-7 0v6';
|
|
1
2
|
const labels = {
|
|
2
3
|
ja: ['編集パネルのレイアウト', 'パネルを横に分割', 'パネルを縦に分割', 'この分割パネルを閉じる',
|
|
3
4
|
'パネルを別画面で開く', 'ブロックパレットを別画面で開く', 'タブを垂直に並べて表示', 'タブを水平に並べて表示'],
|
|
@@ -30,7 +31,7 @@ export function createSpriteLayoutMenu(document, locale, commands) {
|
|
|
30
31
|
trigger.setAttribute('aria-label', title);
|
|
31
32
|
trigger.setAttribute('aria-haspopup', 'menu');
|
|
32
33
|
trigger.setAttribute('aria-expanded', 'false');
|
|
33
|
-
trigger.append(createIcon(document,
|
|
34
|
+
trigger.append(createIcon(document, panelLayoutIconPath));
|
|
34
35
|
element.append(trigger);
|
|
35
36
|
const popup = document.createElement('div');
|
|
36
37
|
popup.className = 'tw-plus-sprite-layout-menu-popup';
|
package/dist/sprite-tabs.js
CHANGED
|
@@ -8,7 +8,7 @@ import { documentPanelTitle, getDocumentWorkspace } from "./document-workspace.j
|
|
|
8
8
|
import { dockPopoutGroups, positionOnScreen, readWorkspaceLayout, workspaceWithoutTransientPanels } from "./workspace-layout.js";
|
|
9
9
|
import { createWorkspaceLayoutStore } from "./workspace-layout-store.js";
|
|
10
10
|
import { SpriteMessagePane } from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-message-pane';
|
|
11
|
-
import {
|
|
11
|
+
import { createTargetTabMenuItem, spriteRenameLabel } from "./target-tab-menu.js";
|
|
12
12
|
export { getDocumentWorkspace } from "./document-workspace.js";
|
|
13
13
|
export { createWorkspaceLayoutStore, workspaceLayoutDatabase, workspaceLayoutLimit } from "./workspace-layout-store.js";
|
|
14
14
|
export { editSpriteVariable } from '@kubohiroya/turbowarp-plus-editor-project-model/sprite-variable-edit';
|
|
@@ -135,6 +135,7 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
135
135
|
const window = document.defaultView;
|
|
136
136
|
const documentWorkspace = multiView && getDocumentWorkspace(vm);
|
|
137
137
|
let pendingRestore = Boolean(persistence);
|
|
138
|
+
let drawerEditedDuringRestore = false;
|
|
138
139
|
let restoreFrame;
|
|
139
140
|
let restoreTimeout;
|
|
140
141
|
let saveFrame;
|
|
@@ -177,22 +178,26 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
177
178
|
return [];
|
|
178
179
|
const items = [];
|
|
179
180
|
if (multiView)
|
|
180
|
-
items.push({
|
|
181
|
-
label: japanese ? '新しいタブで開く' : 'Open in new tab',
|
|
182
|
-
action: () => openInNewTab(view.id)
|
|
183
|
-
});
|
|
181
|
+
items.push({ component: 'open-in-new-tab' });
|
|
184
182
|
if (!view.target.isStage && vm.renameSprite)
|
|
185
183
|
items.push({
|
|
186
184
|
component: 'rename-sprite'
|
|
187
185
|
});
|
|
188
186
|
return items;
|
|
189
187
|
},
|
|
190
|
-
createContextMenuItemComponent: ({ component }) =>
|
|
191
|
-
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
188
|
+
createContextMenuItemComponent: ({ component }) => {
|
|
189
|
+
if (component === 'open-in-new-tab') {
|
|
190
|
+
const label = japanese ? '新しいタブで開く' : 'Open in new tab';
|
|
191
|
+
return createTargetTabMenuItem(document, label, 'new-tab', openInNewTab);
|
|
192
|
+
}
|
|
193
|
+
if (component === 'rename-sprite') {
|
|
194
|
+
return createTargetTabMenuItem(document, text.title, 'rename', id => {
|
|
195
|
+
const target = views.get(id)?.target;
|
|
196
|
+
if (target)
|
|
197
|
+
openRenameDialog(target);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
},
|
|
196
201
|
createComponent: ({ name, id: componentId }) => {
|
|
197
202
|
const element = document.createElement('div');
|
|
198
203
|
if (name === documentComponent) {
|
|
@@ -807,8 +812,9 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
807
812
|
const popouts = [...new Set(reopenable.values())]
|
|
808
813
|
.map(popout => ({ ...popout, panels: popout.panels.filter(id => reopenable.get(id) === popout && views.has(id) && panels[id]?.kind === 'sprite') }))
|
|
809
814
|
.filter(popout => popout.panels.length);
|
|
815
|
+
const stageDrawer = stagePane?.drawer?.read();
|
|
810
816
|
return { version: 1, project: projectSignature(targets), ...saved,
|
|
811
|
-
editingView: active?.id, panels, ...(popouts.length && { popouts }) };
|
|
817
|
+
editingView: active?.id, panels, ...(stageDrawer && { stageDrawer }), ...(popouts.length && { popouts }) };
|
|
812
818
|
}
|
|
813
819
|
function writeLayout() {
|
|
814
820
|
saveFrame = undefined;
|
|
@@ -883,15 +889,19 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
883
889
|
pendingRestore = false;
|
|
884
890
|
window.clearTimeout(restoreTimeout);
|
|
885
891
|
restoreTimeout = undefined;
|
|
892
|
+
if (drawerEditedDuringRestore) {
|
|
893
|
+
drawerEditedDuringRestore = false;
|
|
894
|
+
scheduleSave();
|
|
895
|
+
}
|
|
886
896
|
updateLayoutState();
|
|
887
897
|
}
|
|
888
|
-
/** The
|
|
898
|
+
/** The tab arrangement and drawer state used to detect a change from the initial layout. */
|
|
889
899
|
function layoutShape(layout) {
|
|
890
900
|
const reference = (id) => layout.panels[id] ?? null;
|
|
891
901
|
const shape = (node) => Array.isArray(node.data) ? node.data.map(shape) :
|
|
892
902
|
node.data.views.map(reference);
|
|
893
903
|
return JSON.stringify([layout.grid.orientation, shape(layout.grid.root),
|
|
894
|
-
(layout.popouts ?? []).map(popout => popout.panels.map(reference))]);
|
|
904
|
+
(layout.popouts ?? []).map(popout => popout.panels.map(reference)), layout.stageDrawer]);
|
|
895
905
|
}
|
|
896
906
|
function identifyProject() {
|
|
897
907
|
try {
|
|
@@ -921,7 +931,7 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
921
931
|
/** Keep the layout the project opened with, so leaving it unchanged adds no record. */
|
|
922
932
|
function keepInitialLayout() {
|
|
923
933
|
const layout = captureLayout();
|
|
924
|
-
initialShape = layout && layoutShape(layout);
|
|
934
|
+
initialShape = layout && layoutShape({ ...layout, stageDrawer: undefined });
|
|
925
935
|
finishRestore();
|
|
926
936
|
}
|
|
927
937
|
function restoreLayout() {
|
|
@@ -934,8 +944,13 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
934
944
|
const signature = projectSignature(targets);
|
|
935
945
|
if (!layoutSession)
|
|
936
946
|
return openLayoutSession(signature);
|
|
937
|
-
if (!pendingRestore)
|
|
947
|
+
if (!pendingRestore) {
|
|
948
|
+
if (drawerEditedDuringRestore) {
|
|
949
|
+
drawerEditedDuringRestore = false;
|
|
950
|
+
scheduleSave();
|
|
951
|
+
}
|
|
938
952
|
return;
|
|
953
|
+
}
|
|
939
954
|
reopenable.clear();
|
|
940
955
|
// A project found by its file, folder or desktop key keeps its tabs even after its sprites were renamed.
|
|
941
956
|
const exact = layoutSession.exact;
|
|
@@ -994,6 +1009,7 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
994
1009
|
...Object.values(panels).map(panel => panel.title)]));
|
|
995
1010
|
for (const [id, view] of resolvedSprites)
|
|
996
1011
|
panels[id].title = tabTitle(view);
|
|
1012
|
+
const restoreDrawer = !drawerEditedDuringRestore;
|
|
997
1013
|
finishRestore();
|
|
998
1014
|
syncing = true;
|
|
999
1015
|
try {
|
|
@@ -1006,6 +1022,11 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
1006
1022
|
for (const [id, request] of resolvedDocuments)
|
|
1007
1023
|
documents.set(id, { request });
|
|
1008
1024
|
dockview.fromJSON({ grid: kept.grid, activeGroup: kept.activeGroup, panels });
|
|
1025
|
+
if (restoreDrawer) {
|
|
1026
|
+
const drawer = stored.stageDrawer;
|
|
1027
|
+
stagePane?.drawer?.restore(drawer && dockview.getPanel(stagePanelId) ?
|
|
1028
|
+
{ ...drawer, open: false, selected: false } : drawer);
|
|
1029
|
+
}
|
|
1009
1030
|
for (const popout of stored.popouts ?? []) {
|
|
1010
1031
|
for (const id of popout.panels)
|
|
1011
1032
|
if (views.has(id))
|
|
@@ -1042,6 +1063,8 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
1042
1063
|
layoutSession = undefined;
|
|
1043
1064
|
initialShape = undefined;
|
|
1044
1065
|
pendingRestore = true;
|
|
1066
|
+
drawerEditedDuringRestore = false;
|
|
1067
|
+
stagePane?.drawer?.restore();
|
|
1045
1068
|
if (saveFrame !== undefined)
|
|
1046
1069
|
window.cancelAnimationFrame(saveFrame);
|
|
1047
1070
|
saveFrame = undefined;
|
|
@@ -1140,6 +1163,11 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
1140
1163
|
const unsubscribeDocuments = persistence && documentWorkspace && documentWorkspace.subscribe(scheduleRestore);
|
|
1141
1164
|
projectLoading = Boolean(persistence && persistence.isProjectLoading?.());
|
|
1142
1165
|
const unsubscribeProject = persistence && persistence.subscribeProject?.(projectChanged);
|
|
1166
|
+
const unsubscribeDrawer = persistence && stagePane?.drawer?.subscribe(() => {
|
|
1167
|
+
if (pendingRestore || !layoutSession)
|
|
1168
|
+
drawerEditedDuringRestore = true;
|
|
1169
|
+
scheduleSave();
|
|
1170
|
+
});
|
|
1143
1171
|
layoutStore?.readTabsPosition().then(position => {
|
|
1144
1172
|
if (!disposed && !tabsChosen && position === 'left')
|
|
1145
1173
|
setVerticalTabs(true, false);
|
|
@@ -1182,6 +1210,8 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
1182
1210
|
unsubscribeDocuments();
|
|
1183
1211
|
if (unsubscribeProject)
|
|
1184
1212
|
unsubscribeProject();
|
|
1213
|
+
if (unsubscribeDrawer)
|
|
1214
|
+
unsubscribeDrawer();
|
|
1185
1215
|
if (disconnectDocuments)
|
|
1186
1216
|
disconnectDocuments();
|
|
1187
1217
|
root.removeEventListener('click', guardDocumentClose, true);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { StageDrawerPosition } from './workspace-layout.ts';
|
|
2
|
+
export declare function attachStageDrawerDrag(drawer: HTMLElement, stage: HTMLElement, editor: HTMLElement, focus: () => void, onPositionChange: (position: StageDrawerPosition) => void): {
|
|
3
|
+
setPosition: (next?: StageDrawerPosition) => void;
|
|
4
|
+
dispose: () => void;
|
|
5
|
+
};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
const controls = 'button, input, select, textarea, label, a[href], img, ' +
|
|
2
|
+
'[role="button"], [role="slider"], [role="menu"], [tabindex], [contenteditable]';
|
|
3
|
+
const clamp = (value) => Math.max(0, Math.min(1, value));
|
|
4
|
+
export function attachStageDrawerDrag(drawer, stage, editor, focus, onPositionChange) {
|
|
5
|
+
const document = drawer.ownerDocument;
|
|
6
|
+
const view = document.defaultView;
|
|
7
|
+
let position;
|
|
8
|
+
let drag;
|
|
9
|
+
let resizeDrag;
|
|
10
|
+
function bounds() {
|
|
11
|
+
const area = editor.getBoundingClientRect();
|
|
12
|
+
const panel = stage.getBoundingClientRect();
|
|
13
|
+
const left = Math.max(area.left, 0);
|
|
14
|
+
const top = Math.max(area.top, 0);
|
|
15
|
+
return {
|
|
16
|
+
left, top, editorLeft: area.left, editorTop: area.top, panel,
|
|
17
|
+
width: Math.max(0, Math.min(area.right, document.documentElement.clientWidth) - left - panel.width),
|
|
18
|
+
height: Math.max(0, Math.min(area.bottom, document.documentElement.clientHeight) - top - panel.height)
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function place(area = bounds()) {
|
|
22
|
+
const { left, top, editorLeft, editorTop, width, height, panel } = area;
|
|
23
|
+
if (position) {
|
|
24
|
+
if (resizeDrag?.position) {
|
|
25
|
+
const { edge, start, position: original } = resizeDrag;
|
|
26
|
+
// Keep the opposite side of the frame fixed where it can move along the perimeter.
|
|
27
|
+
if (width && original.x > 0 && original.x < 1) {
|
|
28
|
+
const anchor = edge === 'left' ? start.right - panel.width : start.left;
|
|
29
|
+
position.x = clamp((anchor - left) / width);
|
|
30
|
+
}
|
|
31
|
+
if (height && original.y > 0 && original.y < 1) {
|
|
32
|
+
const anchor = edge === 'top' ? start.bottom - panel.height : start.top;
|
|
33
|
+
position.y = clamp((anchor - top) / height);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
stage.style.setProperty('--plus-stage-drawer-x', `${left - editorLeft + position.x * width}px`);
|
|
37
|
+
stage.style.setProperty('--plus-stage-drawer-y', `${top - editorTop + position.y * height}px`);
|
|
38
|
+
stage.setAttribute('data-stage-drawer-positioned', '');
|
|
39
|
+
}
|
|
40
|
+
const contacts = [
|
|
41
|
+
(position?.x === 0 || !width) && 'left',
|
|
42
|
+
(!position || position.x === 1 || !width) && 'right',
|
|
43
|
+
(position ? position.y === 0 || !height : Math.abs(panel.top - top) < 1) && 'top',
|
|
44
|
+
(position ? position.y === 1 || !height : Math.abs(panel.top - top - height) < 1) && 'bottom'
|
|
45
|
+
].filter(Boolean);
|
|
46
|
+
stage.setAttribute('data-stage-drawer-contacts', contacts.join(' '));
|
|
47
|
+
stage.setAttribute('data-stage-drawer-edge', String(contacts[0] ?? 'right'));
|
|
48
|
+
}
|
|
49
|
+
function start(event) {
|
|
50
|
+
if (drag || resizeDrag || event.button !== 0 || !event.isPrimary || event.defaultPrevented)
|
|
51
|
+
return;
|
|
52
|
+
const target = event.target;
|
|
53
|
+
const resizeEdge = target.closest('[data-stage-drawer-resize]')?.getAttribute('data-stage-resize');
|
|
54
|
+
if (resizeEdge) {
|
|
55
|
+
resizeDrag = { id: event.pointerId, edge: resizeEdge, start: stage.getBoundingClientRect(),
|
|
56
|
+
position: position && { ...position } };
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const header = target.closest('[data-stage-drawer-handle]');
|
|
60
|
+
const control = target.closest(controls);
|
|
61
|
+
if (!header || !drawer.contains(header) || (control && header.contains(control)))
|
|
62
|
+
return;
|
|
63
|
+
const { left, top } = stage.getBoundingClientRect();
|
|
64
|
+
drag = { id: event.pointerId, x: event.clientX, y: event.clientY,
|
|
65
|
+
offsetX: event.clientX - left, offsetY: event.clientY - top, moved: false };
|
|
66
|
+
drawer.setPointerCapture(event.pointerId);
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
}
|
|
69
|
+
function move(event) {
|
|
70
|
+
if (drag?.id !== event.pointerId)
|
|
71
|
+
return;
|
|
72
|
+
if (!drag.moved) {
|
|
73
|
+
if (Math.hypot(event.clientX - drag.x, event.clientY - drag.y) < 4)
|
|
74
|
+
return;
|
|
75
|
+
drag.moved = true;
|
|
76
|
+
stage.setAttribute('data-stage-drawer-dragging', '');
|
|
77
|
+
focus();
|
|
78
|
+
}
|
|
79
|
+
const area = bounds();
|
|
80
|
+
const x = area.width ? 2 * clamp((event.clientX - drag.offsetX - area.left) / area.width) - 1 : 0;
|
|
81
|
+
const y = area.height ? 2 * clamp((event.clientY - drag.offsetY - area.top) / area.height) - 1 : 0;
|
|
82
|
+
// Project from the center of the travel area so changing edges passes through a corner.
|
|
83
|
+
const distance = Math.max(Math.abs(x), Math.abs(y));
|
|
84
|
+
if (distance)
|
|
85
|
+
position = { x: (1 + x / distance) / 2, y: (1 + y / distance) / 2 };
|
|
86
|
+
place(area);
|
|
87
|
+
}
|
|
88
|
+
function finish(event) {
|
|
89
|
+
if (resizeDrag?.id === event.pointerId) {
|
|
90
|
+
place();
|
|
91
|
+
resizeDrag = undefined;
|
|
92
|
+
if (position)
|
|
93
|
+
onPositionChange({ ...position });
|
|
94
|
+
}
|
|
95
|
+
if (drag?.id !== event.pointerId)
|
|
96
|
+
return;
|
|
97
|
+
const moved = drag.moved;
|
|
98
|
+
drag = undefined;
|
|
99
|
+
stage.removeAttribute('data-stage-drawer-dragging');
|
|
100
|
+
if (moved && position)
|
|
101
|
+
onPositionChange({ ...position });
|
|
102
|
+
}
|
|
103
|
+
function setPosition(next) {
|
|
104
|
+
position = next && { ...next };
|
|
105
|
+
if (!position) {
|
|
106
|
+
stage.removeAttribute('data-stage-drawer-positioned');
|
|
107
|
+
stage.style.removeProperty('--plus-stage-drawer-x');
|
|
108
|
+
stage.style.removeProperty('--plus-stage-drawer-y');
|
|
109
|
+
}
|
|
110
|
+
place();
|
|
111
|
+
}
|
|
112
|
+
const handlers = { pointerdown: start, pointermove: move, pointerup: finish,
|
|
113
|
+
pointercancel: finish, lostpointercapture: finish };
|
|
114
|
+
for (const [name, handler] of Object.entries(handlers))
|
|
115
|
+
drawer.addEventListener(name, handler);
|
|
116
|
+
const resize = () => place();
|
|
117
|
+
const observer = new view.ResizeObserver(resize);
|
|
118
|
+
observer.observe(editor);
|
|
119
|
+
observer.observe(stage);
|
|
120
|
+
view.addEventListener('resize', resize);
|
|
121
|
+
place();
|
|
122
|
+
function dispose() {
|
|
123
|
+
for (const [name, handler] of Object.entries(handlers))
|
|
124
|
+
drawer.removeEventListener(name, handler);
|
|
125
|
+
if (drag && drawer.hasPointerCapture(drag.id))
|
|
126
|
+
drawer.releasePointerCapture(drag.id);
|
|
127
|
+
observer.disconnect();
|
|
128
|
+
view.removeEventListener('resize', resize);
|
|
129
|
+
stage.removeAttribute('data-stage-drawer-dragging');
|
|
130
|
+
stage.removeAttribute('data-stage-drawer-positioned');
|
|
131
|
+
stage.removeAttribute('data-stage-drawer-contacts');
|
|
132
|
+
stage.removeAttribute('data-stage-drawer-edge');
|
|
133
|
+
stage.style.removeProperty('--plus-stage-drawer-x');
|
|
134
|
+
stage.style.removeProperty('--plus-stage-drawer-y');
|
|
135
|
+
}
|
|
136
|
+
return { setPosition, dispose };
|
|
137
|
+
}
|
package/dist/stage-launcher.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import React, { type ComponentType } from 'react';
|
|
2
|
-
declare const modes: readonly ["window", "
|
|
2
|
+
declare const modes: readonly ["window", "tab", "drawer"];
|
|
3
3
|
type StageMode = typeof modes[number];
|
|
4
|
+
export declare function stagePresentationItems(locale: string, current: StageMode | null, actions: Partial<Record<StageMode, () => void>>): MenuItem[];
|
|
5
|
+
export declare function useStageDocumentFullscreen(doc?: Document): boolean;
|
|
4
6
|
export interface StageDockAction {
|
|
5
7
|
kind: 'docked' | 'opening' | 'external';
|
|
6
8
|
external: boolean;
|
|
@@ -12,7 +14,8 @@ interface MenuItem {
|
|
|
12
14
|
label: string;
|
|
13
15
|
current: boolean;
|
|
14
16
|
disabled: boolean;
|
|
15
|
-
|
|
17
|
+
icon: React.ReactNode;
|
|
18
|
+
onSelect?(): void;
|
|
16
19
|
}
|
|
17
20
|
export interface StageLauncherOptions {
|
|
18
21
|
mount: HTMLElement;
|
|
@@ -22,6 +25,7 @@ export interface StageLauncherOptions {
|
|
|
22
25
|
icon: React.ReactNode;
|
|
23
26
|
items: MenuItem[];
|
|
24
27
|
className: string;
|
|
28
|
+
disabled?: boolean;
|
|
25
29
|
}>;
|
|
26
30
|
}
|
|
27
31
|
interface StageLauncherProps {
|
|
@@ -35,10 +39,12 @@ interface StageLauncherProps {
|
|
|
35
39
|
} | null;
|
|
36
40
|
};
|
|
37
41
|
drawerOpen: boolean;
|
|
42
|
+
savedDrawerSelected?: boolean;
|
|
43
|
+
editorFullscreen?: boolean;
|
|
38
44
|
focusDrawer(): void;
|
|
39
45
|
revealStage(): void;
|
|
40
46
|
}
|
|
41
|
-
export declare function StageLauncher({ locale, options, dockAction, tab, drawerOpen, focusDrawer, revealStage }: StageLauncherProps): React.
|
|
42
|
-
|
|
43
|
-
}>;
|
|
47
|
+
export declare function StageLauncher({ locale, options, dockAction, tab, drawerOpen, savedDrawerSelected, editorFullscreen, focusDrawer, revealStage }: StageLauncherProps): React.DetailedReactHTMLElement<{
|
|
48
|
+
className: string;
|
|
49
|
+
}, HTMLElement>;
|
|
44
50
|
export {};
|
package/dist/stage-launcher.js
CHANGED
|
@@ -1,103 +1,85 @@
|
|
|
1
1
|
import React, { createElement as element } from 'react';
|
|
2
|
-
import { createPortal } from 'react-dom';
|
|
3
2
|
const labels = {
|
|
4
3
|
ja: {
|
|
5
4
|
open: 'ステージを開く',
|
|
6
5
|
menu: 'ステージの開き方',
|
|
7
|
-
window: '
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
drawer: 'ステージを引き出しで開く',
|
|
11
|
-
enterFullscreen: '全画面にする'
|
|
6
|
+
window: '別ウィンドウで表示',
|
|
7
|
+
tab: 'タブで表示',
|
|
8
|
+
drawer: '引出しで表示'
|
|
12
9
|
},
|
|
13
10
|
en: {
|
|
14
11
|
open: 'Open stage',
|
|
15
12
|
menu: 'Stage opening options',
|
|
16
|
-
window: '
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
drawer: 'Open stage in the drawer',
|
|
20
|
-
enterFullscreen: 'Enter fullscreen'
|
|
13
|
+
window: 'Show in a separate window',
|
|
14
|
+
tab: 'Show in a tab',
|
|
15
|
+
drawer: 'Show in the drawer'
|
|
21
16
|
}
|
|
22
17
|
};
|
|
23
|
-
const modes = ['window', '
|
|
18
|
+
const modes = ['window', 'tab', 'drawer'];
|
|
24
19
|
const textFor = (locale) => /^ja(?:-|$)/i.test(locale) ? labels.ja : labels.en;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
const icons = {
|
|
21
|
+
window: 'M7 3H3v10h10V9m-5-1 5-5m-4 0h4v4',
|
|
22
|
+
tab: 'M2.5 6V3.5H7L8.5 6h5v6.5h-11zM2.5 6H9',
|
|
23
|
+
drawer: 'M2.5 3.5h11v9h-11zM10.5 3.5v9M8.5 8h-4m1.5-1.5L4.5 8 6 9.5'
|
|
24
|
+
};
|
|
25
|
+
export function stagePresentationItems(locale, current, actions) {
|
|
26
|
+
const text = textFor(locale);
|
|
27
|
+
return modes.map(id => ({
|
|
28
|
+
id, label: text[id], current: current === id, disabled: !actions[id], onSelect: actions[id],
|
|
29
|
+
icon: element('svg', { viewBox: '0 0 16 16', fill: 'none', stroke: 'currentColor', strokeWidth: 1.4,
|
|
30
|
+
strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true }, element('path', { d: icons[id] }))
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
export function useStageDocumentFullscreen(doc) {
|
|
34
|
+
const [fullscreenDocument, setFullscreenDocument] = React.useState();
|
|
35
|
+
React.useLayoutEffect(() => {
|
|
36
|
+
const update = () => setFullscreenDocument(doc?.fullscreenElement ? doc : undefined);
|
|
37
|
+
update();
|
|
38
|
+
doc?.addEventListener('fullscreenchange', update);
|
|
39
|
+
return () => doc?.removeEventListener('fullscreenchange', update);
|
|
40
|
+
}, [doc]);
|
|
41
|
+
return Boolean(doc && fullscreenDocument === doc);
|
|
42
|
+
}
|
|
43
|
+
export function StageLauncher({ locale, options, dockAction, tab, drawerOpen, savedDrawerSelected, editorFullscreen, focusDrawer, revealStage }) {
|
|
44
|
+
const [localDrawerSelected, setLocalDrawerSelected] = React.useState(false);
|
|
45
|
+
const drawerSelected = savedDrawerSelected ?? localDrawerSelected;
|
|
28
46
|
const { styles, MenuButton } = options;
|
|
29
47
|
const text = textFor(locale);
|
|
30
48
|
const separate = dockAction?.kind === 'opening' || dockAction?.kind === 'external';
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
(tab?.docked ? 'tab' : (drawerOpen ? 'drawer' : null));
|
|
49
|
+
const mode = separate ? 'window' : (tab?.docked ? 'tab' : (drawerOpen ? 'drawer' : null));
|
|
50
|
+
const disabled = Boolean(editorFullscreen || mode);
|
|
34
51
|
const available = {
|
|
35
52
|
window: Boolean(dockAction?.external),
|
|
36
|
-
fullscreen: Boolean(dockAction?.external),
|
|
37
53
|
tab: Boolean(tab?.commands),
|
|
38
54
|
drawer: true
|
|
39
55
|
};
|
|
56
|
+
const defaultTarget = drawerSelected || !available.window ? 'drawer' : 'window';
|
|
40
57
|
React.useLayoutEffect(() => {
|
|
41
|
-
if (!
|
|
42
|
-
|
|
43
|
-
}, [
|
|
58
|
+
if (savedDrawerSelected === undefined && mode && !editorFullscreen)
|
|
59
|
+
setLocalDrawerSelected(mode === 'drawer');
|
|
60
|
+
}, [mode, editorFullscreen, savedDrawerSelected]);
|
|
44
61
|
function activate(target) {
|
|
45
|
-
if (
|
|
46
|
-
return;
|
|
47
|
-
if (separate) {
|
|
48
|
-
child?.defaultView?.focus();
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
if (!available[target])
|
|
62
|
+
if (disabled || !available[target])
|
|
52
63
|
return;
|
|
53
64
|
revealStage();
|
|
54
65
|
if (target === 'drawer')
|
|
55
66
|
focusDrawer();
|
|
56
67
|
else if (target === 'tab')
|
|
57
68
|
tab?.commands?.open();
|
|
58
|
-
else
|
|
59
|
-
setFullscreen(target === 'fullscreen');
|
|
60
|
-
// Keep opening the popup on the original user gesture.
|
|
69
|
+
else
|
|
61
70
|
dockAction?.undock();
|
|
62
|
-
}
|
|
63
71
|
}
|
|
64
|
-
|
|
72
|
+
const actions = {};
|
|
73
|
+
for (const target of modes) {
|
|
74
|
+
if (!disabled && available[target])
|
|
75
|
+
actions[target] = () => activate(target);
|
|
76
|
+
}
|
|
77
|
+
return element('div', { className: styles.stageLauncher }, element('button', {
|
|
65
78
|
type: 'button',
|
|
66
79
|
className: styles.stageLauncherAction,
|
|
67
|
-
disabled
|
|
68
|
-
onClick: () => activate(
|
|
69
|
-
}, text
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
})) })), mode === 'fullscreen' && dockAction?.mount &&
|
|
73
|
-
element(PopupFullscreen, { mount: dockAction.mount, label: text.enterFullscreen,
|
|
74
|
-
className: styles.stageFullscreenPrompt, onExit: exitFullscreen }));
|
|
75
|
-
}
|
|
76
|
-
function PopupFullscreen({ mount, label, className, onExit }) {
|
|
77
|
-
const child = mount.ownerDocument;
|
|
78
|
-
const [needsGesture, setNeedsGesture] = React.useState(false);
|
|
79
|
-
const enter = React.useCallback(async () => {
|
|
80
|
-
try {
|
|
81
|
-
if (!child.fullscreenElement)
|
|
82
|
-
await child.documentElement.requestFullscreen();
|
|
83
|
-
setNeedsGesture(false);
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
setNeedsGesture(true);
|
|
87
|
-
}
|
|
88
|
-
}, [child]);
|
|
89
|
-
React.useEffect(() => { void enter(); }, [enter]);
|
|
90
|
-
React.useEffect(() => {
|
|
91
|
-
let wasFullscreen = Boolean(child.fullscreenElement);
|
|
92
|
-
const changed = () => {
|
|
93
|
-
if (child.fullscreenElement)
|
|
94
|
-
wasFullscreen = true;
|
|
95
|
-
else if (wasFullscreen)
|
|
96
|
-
onExit();
|
|
97
|
-
};
|
|
98
|
-
child.addEventListener('fullscreenchange', changed);
|
|
99
|
-
return () => child.removeEventListener('fullscreenchange', changed);
|
|
100
|
-
}, [child, onExit]);
|
|
101
|
-
// Mount a separate React portal so the child document receives the trusted click.
|
|
102
|
-
return needsGesture ? createPortal(element('button', { type: 'button', className, onClick: enter }, label), mount) : null;
|
|
80
|
+
disabled,
|
|
81
|
+
onClick: () => activate(defaultTarget)
|
|
82
|
+
}, text.open), element(MenuButton, { label: text.menu, icon: '▾', disabled,
|
|
83
|
+
className: `${styles.stageLauncherMenu} ${styles.stagePresentationMenu}`,
|
|
84
|
+
items: stagePresentationItems(locale, mode ?? (drawerSelected ? 'drawer' : null), actions) }));
|
|
103
85
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare function StageResizeHandle({ edge, aspect, width, limits, label, className, drawer }: {
|
|
3
|
+
edge: any;
|
|
4
|
+
aspect: any;
|
|
5
|
+
width: any;
|
|
6
|
+
limits: any;
|
|
7
|
+
label: any;
|
|
8
|
+
className: any;
|
|
9
|
+
drawer?: boolean;
|
|
10
|
+
}): React.DOMElement<{
|
|
11
|
+
className: any;
|
|
12
|
+
'data-stage-resize': any;
|
|
13
|
+
'data-stage-drawer-resize': true;
|
|
14
|
+
role: string;
|
|
15
|
+
'aria-orientation': string;
|
|
16
|
+
'aria-label': any;
|
|
17
|
+
'aria-valuemin': any;
|
|
18
|
+
'aria-valuemax': any;
|
|
19
|
+
'aria-valuenow': any;
|
|
20
|
+
tabIndex: number;
|
|
21
|
+
title: any;
|
|
22
|
+
onPointerDown: (event: React.PointerEvent<Element>) => void;
|
|
23
|
+
onPointerMove: (event: React.PointerEvent<Element>) => void;
|
|
24
|
+
onLostPointerCapture: () => void;
|
|
25
|
+
onKeyDown: (event: React.KeyboardEvent<Element>) => void;
|
|
26
|
+
}, Element>;
|