@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/src/editor.css
CHANGED
|
@@ -257,6 +257,38 @@
|
|
|
257
257
|
cursor: nesw-resize;
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
+
.stage-drawer .stage-frame:has(> [data-stage-drawer-resize]) {
|
|
261
|
+
position: relative;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
.stage-drawer .stage-resize-handle[data-stage-drawer-resize]:is([data-stage-resize="left"], [data-stage-resize="right"]) {
|
|
265
|
+
inset: 6px auto 6px 0;
|
|
266
|
+
width: 6px;
|
|
267
|
+
cursor: ew-resize;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
.stage-drawer .stage-resize-handle[data-stage-drawer-resize][data-stage-resize="right"] {
|
|
271
|
+
inset: 6px 0 6px auto;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
.stage-drawer .stage-resize-handle[data-stage-drawer-resize]:is([data-stage-resize="top"], [data-stage-resize="bottom"]) {
|
|
275
|
+
inset: 0 0 auto;
|
|
276
|
+
height: 6px;
|
|
277
|
+
cursor: ns-resize;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
.stage-drawer .stage-resize-handle[data-stage-drawer-resize][data-stage-resize="bottom"] {
|
|
281
|
+
inset: auto 0 0;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
.stage-drawer:not([data-stage-drawer-contacts]) [data-stage-drawer-resize][data-stage-resize="right"],
|
|
285
|
+
.stage-drawer[data-stage-drawer-contacts~="left"] [data-stage-drawer-resize][data-stage-resize="left"],
|
|
286
|
+
.stage-drawer[data-stage-drawer-contacts~="right"] [data-stage-drawer-resize][data-stage-resize="right"],
|
|
287
|
+
.stage-drawer[data-stage-drawer-contacts~="top"] [data-stage-drawer-resize][data-stage-resize="top"],
|
|
288
|
+
.stage-drawer[data-stage-drawer-contacts~="bottom"] [data-stage-drawer-resize][data-stage-resize="bottom"] {
|
|
289
|
+
display: none;
|
|
290
|
+
}
|
|
291
|
+
|
|
260
292
|
.target-list-panel,
|
|
261
293
|
.target-list-content {
|
|
262
294
|
display: flex;
|
|
@@ -346,7 +378,22 @@
|
|
|
346
378
|
}
|
|
347
379
|
|
|
348
380
|
.standard-body .stage-drawer {
|
|
349
|
-
right:
|
|
381
|
+
right: max(0px, calc(100% - 100vw));
|
|
382
|
+
pointer-events: none;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
.standard-body:has(.stage-drawer) {
|
|
386
|
+
overflow: clip;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
.stage-drawer .edge-drawer [data-stage-drawer-handle] {
|
|
390
|
+
cursor: grab;
|
|
391
|
+
touch-action: none;
|
|
392
|
+
user-select: none;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
.stage-drawer[data-stage-drawer-dragging] .edge-drawer [data-stage-drawer-handle] {
|
|
396
|
+
cursor: grabbing;
|
|
350
397
|
}
|
|
351
398
|
|
|
352
399
|
.standard-body {
|
|
@@ -580,6 +627,86 @@ details.layout-menu button {
|
|
|
580
627
|
border-top: 1px solid var(--ui-black-transparent);
|
|
581
628
|
}
|
|
582
629
|
|
|
630
|
+
.stage-drawer {
|
|
631
|
+
--stage-drawer-slide: 100% 0;
|
|
632
|
+
--stage-drawer-chevron: 135deg;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
.stage-drawer[data-stage-drawer-edge="left"] {
|
|
636
|
+
--stage-drawer-slide: -100% 0;
|
|
637
|
+
--stage-drawer-chevron: -45deg;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
.stage-drawer[data-stage-drawer-edge="top"] {
|
|
641
|
+
--stage-drawer-slide: 0 -100%;
|
|
642
|
+
--stage-drawer-chevron: 45deg;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
.stage-drawer[data-stage-drawer-edge="bottom"] {
|
|
646
|
+
--stage-drawer-slide: 0 100%;
|
|
647
|
+
--stage-drawer-chevron: -135deg;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
.edge-drawer[data-movable-stage] > .edge-panel {
|
|
651
|
+
transition: translate var(--stage-drawer-transition, 160ms) ease-out;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
.edge-drawer[data-movable-stage]:not([data-stage-drawer-open]) > .edge-panel {
|
|
655
|
+
visibility: hidden;
|
|
656
|
+
translate: var(--stage-drawer-slide);
|
|
657
|
+
pointer-events: none;
|
|
658
|
+
transition: translate var(--stage-drawer-transition, 160ms) ease-out, visibility var(--stage-drawer-transition, 160ms);
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
.edge-drawer[data-movable-stage][data-stage-drawer-unavailable] > .edge-panel {
|
|
662
|
+
transition: none;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
.edge-drawer[data-movable-stage] > .edge-trigger[data-stage-drawer-trigger] {
|
|
666
|
+
position: absolute;
|
|
667
|
+
inset: 0 0 0 auto;
|
|
668
|
+
display: grid;
|
|
669
|
+
place-items: center;
|
|
670
|
+
width: 8px;
|
|
671
|
+
min-height: 0;
|
|
672
|
+
background: var(--ui-secondary);
|
|
673
|
+
border: 1px solid var(--ui-black-transparent);
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
.edge-drawer[data-stage-drawer-open] > .edge-trigger[data-stage-drawer-trigger-collapsed]:not(:focus) {
|
|
677
|
+
display: none;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
.edge-trigger[data-stage-drawer-trigger]::before {
|
|
681
|
+
content: '';
|
|
682
|
+
width: 4px;
|
|
683
|
+
height: 4px;
|
|
684
|
+
border: solid currentColor;
|
|
685
|
+
border-width: 0 1px 1px 0;
|
|
686
|
+
rotate: var(--stage-drawer-chevron);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
.stage-drawer[data-stage-drawer-edge="left"] .edge-trigger[data-stage-drawer-trigger] {
|
|
690
|
+
inset: 0 auto 0 0;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
.stage-drawer[data-stage-drawer-edge="top"] .edge-trigger[data-stage-drawer-trigger],
|
|
694
|
+
.stage-drawer[data-stage-drawer-edge="bottom"] .edge-trigger[data-stage-drawer-trigger] {
|
|
695
|
+
inset: 0 0 auto;
|
|
696
|
+
width: auto;
|
|
697
|
+
height: 8px;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
.stage-drawer[data-stage-drawer-edge="bottom"] .edge-trigger[data-stage-drawer-trigger] {
|
|
701
|
+
inset: auto 0 0;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
@media (prefers-reduced-motion: reduce) {
|
|
705
|
+
.edge-drawer[data-movable-stage] {
|
|
706
|
+
--stage-drawer-transition: 0ms;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
|
|
583
710
|
.target-list-panel .open-window-action,
|
|
584
711
|
.target-list-tools .open-window-action,
|
|
585
712
|
.edge-panel .backpack-panel .open-window-action {
|
|
@@ -967,6 +1094,11 @@ details.layout-menu button {
|
|
|
967
1094
|
z-index: var(--plus-docked-utility-layer);
|
|
968
1095
|
}
|
|
969
1096
|
|
|
1097
|
+
.standard-body .floating-stage.stage-drawer[data-stage-drawer-positioned] {
|
|
1098
|
+
inset: var(--plus-stage-drawer-y) auto auto var(--plus-stage-drawer-x);
|
|
1099
|
+
z-index: calc(var(--plus-docked-utility-layer) + 1);
|
|
1100
|
+
}
|
|
1101
|
+
|
|
970
1102
|
.standard-body:has(.sprite-tabs[data-multi-view]):has(.retracted-targets) {
|
|
971
1103
|
padding-left: 0.625rem;
|
|
972
1104
|
}
|
|
@@ -1142,8 +1274,7 @@ details.layout-menu button {
|
|
|
1142
1274
|
}
|
|
1143
1275
|
|
|
1144
1276
|
.stageLauncherAction,
|
|
1145
|
-
.stageLauncherMenu > button
|
|
1146
|
-
.stageFullscreenPrompt {
|
|
1277
|
+
.stageLauncherMenu > button {
|
|
1147
1278
|
min-block-size: 2rem;
|
|
1148
1279
|
font: inherit;
|
|
1149
1280
|
cursor: pointer;
|
|
@@ -1168,7 +1299,8 @@ details.layout-menu button {
|
|
|
1168
1299
|
border-end-start-radius: 1rem;
|
|
1169
1300
|
}
|
|
1170
1301
|
|
|
1171
|
-
.stageLauncherAction:disabled
|
|
1302
|
+
.stageLauncherAction:disabled,
|
|
1303
|
+
.stageLauncherMenu > button:disabled {
|
|
1172
1304
|
opacity: 0.5;
|
|
1173
1305
|
cursor: default;
|
|
1174
1306
|
}
|
|
@@ -1191,16 +1323,15 @@ details.layout-menu button {
|
|
|
1191
1323
|
block-size: auto;
|
|
1192
1324
|
}
|
|
1193
1325
|
|
|
1194
|
-
.
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
color: inherit;
|
|
1326
|
+
.stagePresentationMenu [role="menu"] {
|
|
1327
|
+
font-size: 0.875rem;
|
|
1328
|
+
font-weight: 500;
|
|
1329
|
+
white-space: nowrap;
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
.stagePresentationMenu [aria-current="true"]::after {
|
|
1333
|
+
content: '✓' / '';
|
|
1334
|
+
margin-inline-start: auto;
|
|
1204
1335
|
}
|
|
1205
1336
|
|
|
1206
1337
|
.stageLauncherAction:focus-visible,
|
|
@@ -1208,8 +1339,3 @@ details.layout-menu button {
|
|
|
1208
1339
|
outline: 2px solid currentColor;
|
|
1209
1340
|
outline-offset: -3px;
|
|
1210
1341
|
}
|
|
1211
|
-
|
|
1212
|
-
.stageFullscreenPrompt:focus-visible {
|
|
1213
|
-
outline: 2px solid var(--looks-secondary, #4c97ff);
|
|
1214
|
-
outline-offset: -2px;
|
|
1215
|
-
}
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,8 @@ interface SpriteLayoutCommands {
|
|
|
13
13
|
setVerticalTabs?(vertical: boolean): void;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
export const panelLayoutIconPath = 'M2.5 3.5h11v9h-11zM2.5 6.5h11m-7 0v6';
|
|
17
|
+
|
|
16
18
|
const labels = {
|
|
17
19
|
ja: ['編集パネルのレイアウト', 'パネルを横に分割', 'パネルを縦に分割', 'この分割パネルを閉じる',
|
|
18
20
|
'パネルを別画面で開く', 'ブロックパレットを別画面で開く', 'タブを垂直に並べて表示', 'タブを水平に並べて表示'],
|
|
@@ -47,7 +49,7 @@ export function createSpriteLayoutMenu(document: Document, locale: string, comma
|
|
|
47
49
|
trigger.setAttribute('aria-label', title);
|
|
48
50
|
trigger.setAttribute('aria-haspopup', 'menu');
|
|
49
51
|
trigger.setAttribute('aria-expanded', 'false');
|
|
50
|
-
trigger.append(createIcon(document,
|
|
52
|
+
trigger.append(createIcon(document, panelLayoutIconPath));
|
|
51
53
|
element.append(trigger);
|
|
52
54
|
|
|
53
55
|
const popup = document.createElement('div');
|
package/src/sprite-tabs.ts
CHANGED
|
@@ -21,7 +21,7 @@ import type {SpriteVariableEdit, SpriteVariableEditError} from '@kubohiroya/turb
|
|
|
21
21
|
import {SpriteMessagePane} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-message-pane';
|
|
22
22
|
import type {MessageRenameError} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-message-pane';
|
|
23
23
|
import type {MessageUse, ProjectMessage, TargetMessages} from '@kubohiroya/turbowarp-plus-editor-project-model/project-messages';
|
|
24
|
-
import {
|
|
24
|
+
import {createTargetTabMenuItem, spriteRenameLabel} from './target-tab-menu.ts';
|
|
25
25
|
|
|
26
26
|
export {getDocumentWorkspace} from './document-workspace.ts';
|
|
27
27
|
export {createWorkspaceLayoutStore, workspaceLayoutDatabase, workspaceLayoutLimit} from './workspace-layout-store.ts';
|
|
@@ -287,6 +287,7 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
287
287
|
const window = document.defaultView;
|
|
288
288
|
const documentWorkspace = multiView && getDocumentWorkspace(vm);
|
|
289
289
|
let pendingRestore = Boolean(persistence);
|
|
290
|
+
let drawerEditedDuringRestore = false;
|
|
290
291
|
let restoreFrame: number | undefined;
|
|
291
292
|
let restoreTimeout: number | undefined;
|
|
292
293
|
let saveFrame: number | undefined;
|
|
@@ -325,20 +326,24 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
325
326
|
const view = views.get(panel.id);
|
|
326
327
|
if (!view) return [];
|
|
327
328
|
const items = [];
|
|
328
|
-
if (multiView) items.push({
|
|
329
|
-
label: japanese ? '新しいタブで開く' : 'Open in new tab',
|
|
330
|
-
action: () => openInNewTab(view.id)
|
|
331
|
-
});
|
|
329
|
+
if (multiView) items.push({component: 'open-in-new-tab'});
|
|
332
330
|
if (!view.target.isStage && vm.renameSprite) items.push({
|
|
333
331
|
component: 'rename-sprite'
|
|
334
332
|
});
|
|
335
333
|
return items;
|
|
336
334
|
},
|
|
337
|
-
createContextMenuItemComponent: ({component}) =>
|
|
338
|
-
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
}
|
|
335
|
+
createContextMenuItemComponent: ({component}) => {
|
|
336
|
+
if (component === 'open-in-new-tab') {
|
|
337
|
+
const label = japanese ? '新しいタブで開く' : 'Open in new tab';
|
|
338
|
+
return createTargetTabMenuItem(document, label, 'new-tab', openInNewTab);
|
|
339
|
+
}
|
|
340
|
+
if (component === 'rename-sprite') {
|
|
341
|
+
return createTargetTabMenuItem(document, text.title, 'rename', id => {
|
|
342
|
+
const target = views.get(id)?.target;
|
|
343
|
+
if (target) openRenameDialog(target);
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
},
|
|
342
347
|
createComponent: ({name, id: componentId}) => {
|
|
343
348
|
const element = document.createElement('div');
|
|
344
349
|
if (name === documentComponent) {
|
|
@@ -914,8 +919,9 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
914
919
|
.map(popout => ({...popout, panels: popout.panels.filter(id =>
|
|
915
920
|
reopenable.get(id) === popout && views.has(id) && panels[id]?.kind === 'sprite')}))
|
|
916
921
|
.filter(popout => popout.panels.length);
|
|
922
|
+
const stageDrawer = stagePane?.drawer?.read();
|
|
917
923
|
return {version: 1, project: projectSignature(targets), ...saved,
|
|
918
|
-
editingView: active?.id, panels, ...(popouts.length && {popouts})};
|
|
924
|
+
editingView: active?.id, panels, ...(stageDrawer && {stageDrawer}), ...(popouts.length && {popouts})};
|
|
919
925
|
}
|
|
920
926
|
|
|
921
927
|
function writeLayout() {
|
|
@@ -987,17 +993,21 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
987
993
|
pendingRestore = false;
|
|
988
994
|
window.clearTimeout(restoreTimeout);
|
|
989
995
|
restoreTimeout = undefined;
|
|
996
|
+
if (drawerEditedDuringRestore) {
|
|
997
|
+
drawerEditedDuringRestore = false;
|
|
998
|
+
scheduleSave();
|
|
999
|
+
}
|
|
990
1000
|
updateLayoutState();
|
|
991
1001
|
}
|
|
992
1002
|
|
|
993
|
-
/** The
|
|
1003
|
+
/** The tab arrangement and drawer state used to detect a change from the initial layout. */
|
|
994
1004
|
function layoutShape(layout: WorkspaceLayout) {
|
|
995
1005
|
type Node = WorkspaceLayout['grid']['root'];
|
|
996
1006
|
const reference = (id: string) => layout.panels[id] ?? null;
|
|
997
1007
|
const shape = (node: Node): unknown => Array.isArray(node.data) ? node.data.map(shape) :
|
|
998
1008
|
node.data.views.map(reference);
|
|
999
1009
|
return JSON.stringify([layout.grid.orientation, shape(layout.grid.root),
|
|
1000
|
-
(layout.popouts ?? []).map(popout => popout.panels.map(reference))]);
|
|
1010
|
+
(layout.popouts ?? []).map(popout => popout.panels.map(reference)), layout.stageDrawer]);
|
|
1001
1011
|
}
|
|
1002
1012
|
|
|
1003
1013
|
function identifyProject(): WorkspaceProjectIdentity {
|
|
@@ -1025,7 +1035,7 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
1025
1035
|
/** Keep the layout the project opened with, so leaving it unchanged adds no record. */
|
|
1026
1036
|
function keepInitialLayout() {
|
|
1027
1037
|
const layout = captureLayout();
|
|
1028
|
-
initialShape = layout && layoutShape(layout);
|
|
1038
|
+
initialShape = layout && layoutShape({...layout, stageDrawer: undefined});
|
|
1029
1039
|
finishRestore();
|
|
1030
1040
|
}
|
|
1031
1041
|
|
|
@@ -1036,7 +1046,13 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
1036
1046
|
if (!targets.length || !vm.editingTarget) return;
|
|
1037
1047
|
const signature = projectSignature(targets);
|
|
1038
1048
|
if (!layoutSession) return openLayoutSession(signature);
|
|
1039
|
-
if (!pendingRestore)
|
|
1049
|
+
if (!pendingRestore) {
|
|
1050
|
+
if (drawerEditedDuringRestore) {
|
|
1051
|
+
drawerEditedDuringRestore = false;
|
|
1052
|
+
scheduleSave();
|
|
1053
|
+
}
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
1040
1056
|
reopenable.clear();
|
|
1041
1057
|
// A project found by its file, folder or desktop key keeps its tabs even after its sprites were renamed.
|
|
1042
1058
|
const exact = layoutSession.exact;
|
|
@@ -1085,6 +1101,7 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
1085
1101
|
assignTabNumbers(resolvedSprites.values(), new Set([...targets.map(baseTitle),
|
|
1086
1102
|
...Object.values(panels).map(panel => panel.title)]));
|
|
1087
1103
|
for (const [id, view] of resolvedSprites) panels[id].title = tabTitle(view);
|
|
1104
|
+
const restoreDrawer = !drawerEditedDuringRestore;
|
|
1088
1105
|
finishRestore();
|
|
1089
1106
|
syncing = true;
|
|
1090
1107
|
try {
|
|
@@ -1095,6 +1112,11 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
1095
1112
|
for (const [id, view] of resolvedSprites) views.set(id, view);
|
|
1096
1113
|
for (const [id, request] of resolvedDocuments) documents.set(id, {request});
|
|
1097
1114
|
dockview.fromJSON({grid: kept.grid, activeGroup: kept.activeGroup, panels});
|
|
1115
|
+
if (restoreDrawer) {
|
|
1116
|
+
const drawer = stored.stageDrawer;
|
|
1117
|
+
stagePane?.drawer?.restore(drawer && dockview.getPanel(stagePanelId) ?
|
|
1118
|
+
{...drawer, open: false, selected: false} : drawer);
|
|
1119
|
+
}
|
|
1098
1120
|
for (const popout of stored.popouts ?? []) {
|
|
1099
1121
|
for (const id of popout.panels) if (views.has(id)) reopenable.set(id, popout);
|
|
1100
1122
|
}
|
|
@@ -1127,6 +1149,8 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
1127
1149
|
layoutSession = undefined;
|
|
1128
1150
|
initialShape = undefined;
|
|
1129
1151
|
pendingRestore = true;
|
|
1152
|
+
drawerEditedDuringRestore = false;
|
|
1153
|
+
stagePane?.drawer?.restore();
|
|
1130
1154
|
if (saveFrame !== undefined) window.cancelAnimationFrame(saveFrame);
|
|
1131
1155
|
saveFrame = undefined;
|
|
1132
1156
|
window.clearTimeout(restoreTimeout);
|
|
@@ -1215,6 +1239,10 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
1215
1239
|
const unsubscribeDocuments = persistence && documentWorkspace && documentWorkspace.subscribe(scheduleRestore);
|
|
1216
1240
|
projectLoading = Boolean(persistence && persistence.isProjectLoading?.());
|
|
1217
1241
|
const unsubscribeProject = persistence && persistence.subscribeProject?.(projectChanged);
|
|
1242
|
+
const unsubscribeDrawer = persistence && stagePane?.drawer?.subscribe(() => {
|
|
1243
|
+
if (pendingRestore || !layoutSession) drawerEditedDuringRestore = true;
|
|
1244
|
+
scheduleSave();
|
|
1245
|
+
});
|
|
1218
1246
|
layoutStore?.readTabsPosition().then(position => {
|
|
1219
1247
|
if (!disposed && !tabsChosen && position === 'left') setVerticalTabs(true, false);
|
|
1220
1248
|
}, () => undefined).finally(() => {
|
|
@@ -1250,6 +1278,7 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
1250
1278
|
if (persistence) window.removeEventListener('pagehide', flushLayout);
|
|
1251
1279
|
if (unsubscribeDocuments) unsubscribeDocuments();
|
|
1252
1280
|
if (unsubscribeProject) unsubscribeProject();
|
|
1281
|
+
if (unsubscribeDrawer) unsubscribeDrawer();
|
|
1253
1282
|
if (disconnectDocuments) disconnectDocuments();
|
|
1254
1283
|
root.removeEventListener('click', guardDocumentClose, true);
|
|
1255
1284
|
root.removeEventListener('keydown', guardDocumentClose, true);
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type {StageDrawerPosition} from './workspace-layout.ts';
|
|
2
|
+
|
|
3
|
+
const controls = 'button, input, select, textarea, label, a[href], img, ' +
|
|
4
|
+
'[role="button"], [role="slider"], [role="menu"], [tabindex], [contenteditable]';
|
|
5
|
+
|
|
6
|
+
const clamp = (value: number) => Math.max(0, Math.min(1, value));
|
|
7
|
+
|
|
8
|
+
export function attachStageDrawerDrag(drawer: HTMLElement, stage: HTMLElement, editor: HTMLElement, focus: () => void,
|
|
9
|
+
onPositionChange: (position: StageDrawerPosition) => void) {
|
|
10
|
+
const document = drawer.ownerDocument;
|
|
11
|
+
const view = document.defaultView;
|
|
12
|
+
let position: StageDrawerPosition | undefined;
|
|
13
|
+
let drag: {id: number; x: number; y: number; offsetX: number; offsetY: number; moved: boolean} | undefined;
|
|
14
|
+
let resizeDrag: {id: number; edge: string; start: DOMRect; position?: StageDrawerPosition} | undefined;
|
|
15
|
+
|
|
16
|
+
function bounds() {
|
|
17
|
+
const area = editor.getBoundingClientRect();
|
|
18
|
+
const panel = stage.getBoundingClientRect();
|
|
19
|
+
const left = Math.max(area.left, 0);
|
|
20
|
+
const top = Math.max(area.top, 0);
|
|
21
|
+
return {
|
|
22
|
+
left, top, editorLeft: area.left, editorTop: area.top, panel,
|
|
23
|
+
width: Math.max(0, Math.min(area.right, document.documentElement.clientWidth) - left - panel.width),
|
|
24
|
+
height: Math.max(0, Math.min(area.bottom, document.documentElement.clientHeight) - top - panel.height)
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function place(area = bounds()) {
|
|
29
|
+
const {left, top, editorLeft, editorTop, width, height, panel} = area;
|
|
30
|
+
if (position) {
|
|
31
|
+
if (resizeDrag?.position) {
|
|
32
|
+
const {edge, start, position: original} = resizeDrag;
|
|
33
|
+
// Keep the opposite side of the frame fixed where it can move along the perimeter.
|
|
34
|
+
if (width && original.x > 0 && original.x < 1) {
|
|
35
|
+
const anchor = edge === 'left' ? start.right - panel.width : start.left;
|
|
36
|
+
position.x = clamp((anchor - left) / width);
|
|
37
|
+
}
|
|
38
|
+
if (height && original.y > 0 && original.y < 1) {
|
|
39
|
+
const anchor = edge === 'top' ? start.bottom - panel.height : start.top;
|
|
40
|
+
position.y = clamp((anchor - top) / height);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
stage.style.setProperty('--plus-stage-drawer-x', `${left - editorLeft + position.x * width}px`);
|
|
44
|
+
stage.style.setProperty('--plus-stage-drawer-y', `${top - editorTop + position.y * height}px`);
|
|
45
|
+
stage.setAttribute('data-stage-drawer-positioned', '');
|
|
46
|
+
}
|
|
47
|
+
const contacts = [
|
|
48
|
+
(position?.x === 0 || !width) && 'left',
|
|
49
|
+
(!position || position.x === 1 || !width) && 'right',
|
|
50
|
+
(position ? position.y === 0 || !height : Math.abs(panel.top - top) < 1) && 'top',
|
|
51
|
+
(position ? position.y === 1 || !height : Math.abs(panel.top - top - height) < 1) && 'bottom'
|
|
52
|
+
].filter(Boolean);
|
|
53
|
+
stage.setAttribute('data-stage-drawer-contacts', contacts.join(' '));
|
|
54
|
+
stage.setAttribute('data-stage-drawer-edge', String(contacts[0] ?? 'right'));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function start(event: PointerEvent) {
|
|
58
|
+
if (drag || resizeDrag || event.button !== 0 || !event.isPrimary || event.defaultPrevented) return;
|
|
59
|
+
const target = event.target as Element;
|
|
60
|
+
const resizeEdge = target.closest('[data-stage-drawer-resize]')?.getAttribute('data-stage-resize');
|
|
61
|
+
if (resizeEdge) {
|
|
62
|
+
resizeDrag = {id: event.pointerId, edge: resizeEdge, start: stage.getBoundingClientRect(),
|
|
63
|
+
position: position && {...position}};
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const header = target.closest('[data-stage-drawer-handle]');
|
|
67
|
+
const control = target.closest(controls);
|
|
68
|
+
if (!header || !drawer.contains(header) || (control && header.contains(control))) return;
|
|
69
|
+
const {left, top} = stage.getBoundingClientRect();
|
|
70
|
+
drag = {id: event.pointerId, x: event.clientX, y: event.clientY,
|
|
71
|
+
offsetX: event.clientX - left, offsetY: event.clientY - top, moved: false};
|
|
72
|
+
drawer.setPointerCapture(event.pointerId);
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function move(event: PointerEvent) {
|
|
77
|
+
if (drag?.id !== event.pointerId) return;
|
|
78
|
+
if (!drag.moved) {
|
|
79
|
+
if (Math.hypot(event.clientX - drag.x, event.clientY - drag.y) < 4) return;
|
|
80
|
+
drag.moved = true;
|
|
81
|
+
stage.setAttribute('data-stage-drawer-dragging', '');
|
|
82
|
+
focus();
|
|
83
|
+
}
|
|
84
|
+
const area = bounds();
|
|
85
|
+
const x = area.width ? 2 * clamp((event.clientX - drag.offsetX - area.left) / area.width) - 1 : 0;
|
|
86
|
+
const y = area.height ? 2 * clamp((event.clientY - drag.offsetY - area.top) / area.height) - 1 : 0;
|
|
87
|
+
// Project from the center of the travel area so changing edges passes through a corner.
|
|
88
|
+
const distance = Math.max(Math.abs(x), Math.abs(y));
|
|
89
|
+
if (distance) position = {x: (1 + x / distance) / 2, y: (1 + y / distance) / 2};
|
|
90
|
+
place(area);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function finish(event: PointerEvent) {
|
|
94
|
+
if (resizeDrag?.id === event.pointerId) {
|
|
95
|
+
place();
|
|
96
|
+
resizeDrag = undefined;
|
|
97
|
+
if (position) onPositionChange({...position});
|
|
98
|
+
}
|
|
99
|
+
if (drag?.id !== event.pointerId) return;
|
|
100
|
+
const moved = drag.moved;
|
|
101
|
+
drag = undefined;
|
|
102
|
+
stage.removeAttribute('data-stage-drawer-dragging');
|
|
103
|
+
if (moved && position) onPositionChange({...position});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function setPosition(next?: StageDrawerPosition) {
|
|
107
|
+
position = next && {...next};
|
|
108
|
+
if (!position) {
|
|
109
|
+
stage.removeAttribute('data-stage-drawer-positioned');
|
|
110
|
+
stage.style.removeProperty('--plus-stage-drawer-x');
|
|
111
|
+
stage.style.removeProperty('--plus-stage-drawer-y');
|
|
112
|
+
}
|
|
113
|
+
place();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const handlers = {pointerdown: start, pointermove: move, pointerup: finish,
|
|
117
|
+
pointercancel: finish, lostpointercapture: finish};
|
|
118
|
+
for (const [name, handler] of Object.entries(handlers)) drawer.addEventListener(name, handler);
|
|
119
|
+
const resize = () => place();
|
|
120
|
+
const observer = new view.ResizeObserver(resize);
|
|
121
|
+
observer.observe(editor);
|
|
122
|
+
observer.observe(stage);
|
|
123
|
+
view.addEventListener('resize', resize);
|
|
124
|
+
place();
|
|
125
|
+
function dispose() {
|
|
126
|
+
for (const [name, handler] of Object.entries(handlers)) drawer.removeEventListener(name, handler);
|
|
127
|
+
if (drag && drawer.hasPointerCapture(drag.id)) drawer.releasePointerCapture(drag.id);
|
|
128
|
+
observer.disconnect();
|
|
129
|
+
view.removeEventListener('resize', resize);
|
|
130
|
+
stage.removeAttribute('data-stage-drawer-dragging');
|
|
131
|
+
stage.removeAttribute('data-stage-drawer-positioned');
|
|
132
|
+
stage.removeAttribute('data-stage-drawer-contacts');
|
|
133
|
+
stage.removeAttribute('data-stage-drawer-edge');
|
|
134
|
+
stage.style.removeProperty('--plus-stage-drawer-x');
|
|
135
|
+
stage.style.removeProperty('--plus-stage-drawer-y');
|
|
136
|
+
}
|
|
137
|
+
return {setPosition, dispose};
|
|
138
|
+
}
|