@kubohiroya/turbowarp-plus-editor-workbench 0.3.1 → 0.4.1
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/README.ja.md +42 -0
- package/README.md +42 -0
- package/dist/ai-agent-settings.d.ts +97 -0
- package/dist/ai-agent-settings.js +316 -0
- package/dist/ai-agents.d.ts +24 -0
- package/dist/ai-agents.js +75 -0
- package/dist/document-workspace.d.ts +17 -0
- package/dist/drawer-views.d.ts +66 -0
- package/dist/drawer-views.js +152 -0
- package/dist/sprite-layout-menu.d.ts +3 -0
- package/dist/sprite-layout-menu.js +21 -8
- package/dist/sprite-tabs.d.ts +20 -0
- package/dist/sprite-tabs.js +171 -22
- package/dist/standard-layout.d.ts +4 -1
- package/dist/standard-layout.js +57 -13
- package/dist/target-tab-menu.d.ts +29 -0
- package/dist/target-tab-menu.js +76 -0
- package/dist/workspace-layout.d.ts +1 -0
- package/dist/workspace-layout.js +6 -2
- package/package.json +5 -1
- package/src/ai-agent-settings.ts +380 -0
- package/src/ai-agents.ts +95 -0
- package/src/document-workspace.ts +12 -0
- package/src/drawer-views.ts +203 -0
- package/src/editor.css +270 -0
- package/src/sprite-layout-menu.css +71 -0
- package/src/sprite-layout-menu.ts +27 -8
- package/src/sprite-tabs.ts +156 -22
- package/src/standard-layout.ts +67 -17
- package/src/target-tab-menu.ts +99 -0
- package/src/workspace-layout.ts +6 -3
package/dist/sprite-tabs.js
CHANGED
|
@@ -7,9 +7,11 @@ import { SpriteEditorToolbar, spriteEditorSections } from '@kubohiroya/turbowarp
|
|
|
7
7
|
import { documentPanelTitle, getDocumentWorkspace } from "./document-workspace.js";
|
|
8
8
|
import { dockPopoutGroups, positionOnScreen, readWorkspaceLayout, workspaceWithoutTransientPanels } from "./workspace-layout.js";
|
|
9
9
|
import { SpriteMessagePane } from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-message-pane';
|
|
10
|
+
import { createRenameMenuItem, spriteRenameLabel } from "./target-tab-menu.js";
|
|
10
11
|
export { getDocumentWorkspace } from "./document-workspace.js";
|
|
11
12
|
export { editSpriteVariable } from '@kubohiroya/turbowarp-plus-editor-project-model/sprite-variable-edit';
|
|
12
13
|
export { useDockviewStage } from "./dockview-stage.js";
|
|
14
|
+
export { SpriteTargetTabsContext, useTargetTabMenu } from "./target-tab-menu.js";
|
|
13
15
|
const variableSection = spriteEditorSections.indexOf('variables');
|
|
14
16
|
const messageSection = spriteEditorSections.indexOf('messages');
|
|
15
17
|
// The first three sections are the GUI's own panels; the rest are rendered by this package.
|
|
@@ -57,8 +59,8 @@ function createAssetSelections(target, locale, source) {
|
|
|
57
59
|
const stagePanelId = 'tw-plus-stage-display';
|
|
58
60
|
const documentComponent = 'tw-plus-document';
|
|
59
61
|
const renameLabels = {
|
|
60
|
-
en: { title: '
|
|
61
|
-
ja: { title: '
|
|
62
|
+
en: { title: spriteRenameLabel('en'), name: 'Sprite name', cancel: 'Cancel', save: 'Rename' },
|
|
63
|
+
ja: { title: spriteRenameLabel('ja'), name: 'スプライト名', cancel: 'キャンセル', save: '変更' }
|
|
62
64
|
};
|
|
63
65
|
const targetName = (target) => target.isStage ? 'Stage' : target.getName();
|
|
64
66
|
const projectSignature = (targets) => JSON.stringify(targets
|
|
@@ -98,7 +100,12 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
98
100
|
const japanese = /^ja(?:-|$)/i.test(locale);
|
|
99
101
|
const editLabel = japanese ? 'クリックしてこのビューで編集' : 'Activate this view to edit';
|
|
100
102
|
const backdropTitle = japanese ? '背景' : 'Backdrops';
|
|
101
|
-
const
|
|
103
|
+
const baseTitle = (target) => target.isStage ? backdropTitle : target.getName();
|
|
104
|
+
const numberedTitle = (target, number) => `${baseTitle(target)}(${number})`;
|
|
105
|
+
const tabTitle = ({ target, number }) => number ? numberedTitle(target, number) : baseTitle(target);
|
|
106
|
+
const chipText = japanese ?
|
|
107
|
+
{ collapse: 'グループを折りたたむ', expand: 'グループを展開する', close: 'このグループのタブを閉じる', closeAll: 'この分割パネルの文書タブをすべて閉じる' } :
|
|
108
|
+
{ collapse: 'Collapse group', expand: 'Expand group', close: 'Close the tabs of this group', closeAll: 'Close all document tabs of this split' };
|
|
102
109
|
const slots = new Map();
|
|
103
110
|
const views = new Map();
|
|
104
111
|
const documents = new Map();
|
|
@@ -123,18 +130,55 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
123
130
|
/** Panels that were in a separate window when the layout was saved, until the user reopens them. */
|
|
124
131
|
const reopenable = new Map();
|
|
125
132
|
const originalTargets = () => vm.runtime.targets.filter(target => target.isOriginal);
|
|
133
|
+
// Whether tabs stand in a column at the left of each split. It is the user's preference, kept apart from the layout.
|
|
134
|
+
const tabsKey = persistence ? persistence.key + '.tabs' : undefined;
|
|
135
|
+
let verticalTabs = false;
|
|
136
|
+
try {
|
|
137
|
+
verticalTabs = Boolean(tabsKey) && persistence.storage.getItem(tabsKey) === 'left';
|
|
138
|
+
}
|
|
139
|
+
catch { /* Storage can be unavailable. */ }
|
|
126
140
|
const dockview = createDockview(root, {
|
|
127
141
|
theme: themeLight,
|
|
128
142
|
disableFloatingGroups: true,
|
|
143
|
+
defaultHeaderPosition: verticalTabs ? 'left' : 'top',
|
|
129
144
|
...(multiView && { createRightHeaderActionComponent: createLayoutMenu }),
|
|
130
145
|
defaultTabComponent: 'sprite',
|
|
131
146
|
createTabComponent: () => new SpriteTab(document),
|
|
147
|
+
// A chip stands for several tabs, such as the changed scripts of one sprite, so it closes them together.
|
|
148
|
+
getTabGroupChipContextMenuItems: ({ tabGroup, group }) => [
|
|
149
|
+
{ label: tabGroup.collapsed ? chipText.expand : chipText.collapse, action: () => tabGroup.toggle() },
|
|
150
|
+
{ label: chipText.close, action: () => {
|
|
151
|
+
for (const id of [...tabGroup.panelIds])
|
|
152
|
+
dockview.getPanel(id)?.api.close();
|
|
153
|
+
} },
|
|
154
|
+
{ label: chipText.closeAll, action: () => {
|
|
155
|
+
for (const panel of [...group.panels])
|
|
156
|
+
if (documents.has(panel.id))
|
|
157
|
+
panel.api.close();
|
|
158
|
+
} }
|
|
159
|
+
],
|
|
132
160
|
getTabContextMenuItems: ({ panel }) => {
|
|
133
|
-
const
|
|
134
|
-
if (!
|
|
161
|
+
const view = views.get(panel.id);
|
|
162
|
+
if (!view)
|
|
135
163
|
return [];
|
|
136
|
-
|
|
164
|
+
const items = [];
|
|
165
|
+
if (multiView)
|
|
166
|
+
items.push({
|
|
167
|
+
label: japanese ? '新しいタブで開く' : 'Open in new tab',
|
|
168
|
+
action: () => openInNewTab(view.id)
|
|
169
|
+
});
|
|
170
|
+
if (!view.target.isStage && vm.renameSprite)
|
|
171
|
+
items.push({
|
|
172
|
+
component: 'rename-sprite'
|
|
173
|
+
});
|
|
174
|
+
return items;
|
|
137
175
|
},
|
|
176
|
+
createContextMenuItemComponent: ({ component }) => component === 'rename-sprite' ?
|
|
177
|
+
createRenameMenuItem(document, text.title, id => {
|
|
178
|
+
const target = views.get(id)?.target;
|
|
179
|
+
if (target)
|
|
180
|
+
openRenameDialog(target);
|
|
181
|
+
}) : undefined,
|
|
138
182
|
createComponent: ({ name, id: componentId }) => {
|
|
139
183
|
const element = document.createElement('div');
|
|
140
184
|
if (name === documentComponent) {
|
|
@@ -257,6 +301,8 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
257
301
|
closeSplit(group.activePanel.id); },
|
|
258
302
|
canClose: () => canCloseGroup(group),
|
|
259
303
|
canSplit: () => views.has(group.activePanel?.id),
|
|
304
|
+
verticalTabs: () => verticalTabs,
|
|
305
|
+
setVerticalTabs,
|
|
260
306
|
...(popouts && {
|
|
261
307
|
canOpenPanel,
|
|
262
308
|
openPanel() {
|
|
@@ -293,6 +339,19 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
293
339
|
});
|
|
294
340
|
return { ...menu, init() { } };
|
|
295
341
|
}
|
|
342
|
+
function setVerticalTabs(vertical) {
|
|
343
|
+
verticalTabs = vertical;
|
|
344
|
+
const position = vertical ? 'left' : 'top';
|
|
345
|
+
dockview.updateOptions({ defaultHeaderPosition: position });
|
|
346
|
+
for (const group of dockview.groups)
|
|
347
|
+
group.api.setHeaderPosition(position);
|
|
348
|
+
try {
|
|
349
|
+
if (tabsKey)
|
|
350
|
+
persistence.storage.setItem(tabsKey, position);
|
|
351
|
+
}
|
|
352
|
+
catch { /* Storage can be unavailable. */ }
|
|
353
|
+
refreshSurfaces();
|
|
354
|
+
}
|
|
296
355
|
const canRename = (target) => target.isOriginal && !target.isStage && Boolean(vm.renameSprite) && vm.runtime.targets.includes(target);
|
|
297
356
|
function openRenameDialog(target) {
|
|
298
357
|
if (renameDialog || !canRename(target))
|
|
@@ -469,23 +528,47 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
469
528
|
}
|
|
470
529
|
refreshSurfaces();
|
|
471
530
|
}
|
|
472
|
-
function
|
|
531
|
+
function nextTabNumber(target, titles) {
|
|
532
|
+
let number = 2;
|
|
533
|
+
while (titles.has(numberedTitle(target, number)))
|
|
534
|
+
number++;
|
|
535
|
+
return number;
|
|
536
|
+
}
|
|
537
|
+
function reservedTitles() {
|
|
538
|
+
return new Set([...originalTargets().map(baseTitle),
|
|
539
|
+
...dockview.panels.filter(panel => !views.has(panel.id)).map(panel => panel.title)]);
|
|
540
|
+
}
|
|
541
|
+
function assignTabNumbers(items, titles = reservedTitles()) {
|
|
542
|
+
const originals = new Set();
|
|
543
|
+
for (const view of items) {
|
|
544
|
+
if (!view.number && !originals.has(view.target)) {
|
|
545
|
+
originals.add(view.target);
|
|
546
|
+
continue;
|
|
547
|
+
}
|
|
548
|
+
if (!view.number || titles.has(tabTitle(view)))
|
|
549
|
+
view.number = nextTabNumber(view.target, titles);
|
|
550
|
+
titles.add(tabTitle(view));
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
function add(target, position, section) {
|
|
473
554
|
let id = target.id;
|
|
474
|
-
if (
|
|
555
|
+
if (position || views.has(id) || id === stagePanelId || documents.has(id)) {
|
|
475
556
|
do {
|
|
476
557
|
id = 'sprite-view-' + ++nextView;
|
|
477
558
|
} while (views.has(id) || documents.has(id) || vm.runtime.targets.some(item => item.id === id));
|
|
478
559
|
}
|
|
479
|
-
const source =
|
|
560
|
+
const source = position && views.get(position.referencePanel);
|
|
480
561
|
// An inactive panel leaves dockview without an active group, and dockview then opens each later
|
|
481
562
|
// panel in a new group; keep sprites added without a split as tabs of an existing sprite group.
|
|
482
|
-
const spriteGroup = !
|
|
563
|
+
const spriteGroup = !position && !dockview.activeGroup &&
|
|
483
564
|
dockview.groups.find(group => group.panels.some(panel => views.has(panel.id)));
|
|
484
|
-
|
|
485
|
-
|
|
565
|
+
const view = { id, target, section: section ?? remembered.get(target) ?? options.getSection(),
|
|
566
|
+
number: source && nextTabNumber(target, new Set([...reservedTitles(), ...[...views.values()].map(tabTitle)])),
|
|
567
|
+
assets: createAssetSelections(target, locale, source?.assets) };
|
|
568
|
+
views.set(id, view);
|
|
486
569
|
try {
|
|
487
|
-
return dockview.addPanel({ id, title: tabTitle(
|
|
488
|
-
position:
|
|
570
|
+
return dockview.addPanel({ id, title: tabTitle(view), component: 'sprite', inactive: !position,
|
|
571
|
+
position: position ?? (spriteGroup ? { referenceGroup: spriteGroup } : undefined),
|
|
489
572
|
params: { icon: getIcon(target) } });
|
|
490
573
|
}
|
|
491
574
|
catch (error) {
|
|
@@ -515,13 +598,34 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
515
598
|
[...views.values()].find(item => item.target === target);
|
|
516
599
|
activateView(view?.id ?? add(target).id);
|
|
517
600
|
}
|
|
601
|
+
function targetTabs(id) {
|
|
602
|
+
return dockview.groups.map(group => ({ group, rect: group.element.getBoundingClientRect() }))
|
|
603
|
+
.sort((a, b) => Number(a.group.api.location.type !== 'grid') - Number(b.group.api.location.type !== 'grid') ||
|
|
604
|
+
a.rect.left - b.rect.left || a.rect.top - b.rect.top)
|
|
605
|
+
.flatMap(({ group }) => group.panels.flatMap(panel => {
|
|
606
|
+
const target = views.get(panel.id)?.target;
|
|
607
|
+
return target && (id === undefined ? target.isStage : target.id === id) ?
|
|
608
|
+
[{ id: panel.id, title: panel.title }] : [];
|
|
609
|
+
}));
|
|
610
|
+
}
|
|
611
|
+
function selectFromList(id) {
|
|
612
|
+
const first = targetTabs(id)[0];
|
|
613
|
+
if (first)
|
|
614
|
+
activateView(first.id);
|
|
615
|
+
else {
|
|
616
|
+
const target = originalTargets().find(item => id === undefined ? item.isStage : item.id === id);
|
|
617
|
+
if (target)
|
|
618
|
+
select(target.id);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
518
621
|
function openDocument(request) {
|
|
519
622
|
if (pendingRestore)
|
|
520
623
|
finishRestore();
|
|
521
624
|
const { providerId, documentId } = request.reference;
|
|
522
625
|
for (const [id, { request: opened }] of documents) {
|
|
523
626
|
if (opened.reference.providerId === providerId && opened.reference.documentId === documentId) {
|
|
524
|
-
|
|
627
|
+
if (!request.inactive)
|
|
628
|
+
dockview.getPanel(id)?.api.setActive();
|
|
525
629
|
return;
|
|
526
630
|
}
|
|
527
631
|
}
|
|
@@ -530,15 +634,43 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
530
634
|
id = 'document-view-' + ++nextView;
|
|
531
635
|
} while (views.has(id) || documents.has(id) || vm.runtime.targets.some(target => target.id === id));
|
|
532
636
|
const title = documentPanelTitle(request);
|
|
637
|
+
const position = documentPosition(request);
|
|
533
638
|
documents.set(id, { request });
|
|
534
639
|
try {
|
|
535
|
-
dockview.addPanel({ id, title, component: documentComponent, renderer: 'always'
|
|
640
|
+
dockview.addPanel({ id, title, component: documentComponent, renderer: 'always',
|
|
641
|
+
inactive: request.inactive, ...(position && { position }) });
|
|
536
642
|
}
|
|
537
643
|
catch (error) {
|
|
538
644
|
documents.get(id)?.session?.dispose();
|
|
539
645
|
documents.delete(id);
|
|
540
646
|
throw error;
|
|
541
647
|
}
|
|
648
|
+
if (request.tabGroup)
|
|
649
|
+
joinTabGroup(id, request.tabGroup);
|
|
650
|
+
}
|
|
651
|
+
/** Where a document of an area opens: in the split that already shows its area, or in a new split beside the editor. */
|
|
652
|
+
function documentPosition({ area }) {
|
|
653
|
+
if (!area)
|
|
654
|
+
return;
|
|
655
|
+
for (const [id, { request }] of documents) {
|
|
656
|
+
const panel = request.area === area && dockview.getPanel(id);
|
|
657
|
+
if (panel && panel.group.api.location.type === 'grid')
|
|
658
|
+
return { referenceGroup: panel.group };
|
|
659
|
+
}
|
|
660
|
+
const reference = dockview.activePanel;
|
|
661
|
+
return reference && reference.group.api.location.type === 'grid' ?
|
|
662
|
+
{ referencePanel: reference.id, direction: 'right' } : undefined;
|
|
663
|
+
}
|
|
664
|
+
function joinTabGroup(id, { id: key, label, color, collapsed }) {
|
|
665
|
+
const panel = dockview.getPanel(id);
|
|
666
|
+
if (!panel)
|
|
667
|
+
return;
|
|
668
|
+
const groupId = panel.group.id;
|
|
669
|
+
const existing = dockview.getTabGroups({ groupId }).find(item => item.componentParams?.key === key);
|
|
670
|
+
const tabGroup = existing ?? dockview.createTabGroup({ groupId, label, color, componentParams: { key } });
|
|
671
|
+
dockview.addPanelToTabGroup({ groupId, tabGroupId: tabGroup.id, panelId: id });
|
|
672
|
+
if (!existing && collapsed)
|
|
673
|
+
tabGroup.collapse();
|
|
542
674
|
}
|
|
543
675
|
function guardDocumentClose(event) {
|
|
544
676
|
const element = event.target;
|
|
@@ -574,7 +706,7 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
574
706
|
function closeStage() {
|
|
575
707
|
dockview.getPanel(stagePanelId)?.api.close();
|
|
576
708
|
}
|
|
577
|
-
function
|
|
709
|
+
function addView(direction, id = active?.id) {
|
|
578
710
|
const reference = views.get(id);
|
|
579
711
|
if (!multiView || !reference)
|
|
580
712
|
return;
|
|
@@ -583,6 +715,8 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
583
715
|
activateView(panel.id);
|
|
584
716
|
return panel.id;
|
|
585
717
|
}
|
|
718
|
+
const split = (direction, id) => addView(direction, id);
|
|
719
|
+
const openInNewTab = (id) => addView('within', id);
|
|
586
720
|
function closeSplit(id = active?.id) {
|
|
587
721
|
const panel = dockview.getPanel(id);
|
|
588
722
|
if (!multiView || !panel || !canCloseGroup(panel.api.group))
|
|
@@ -637,7 +771,8 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
637
771
|
return;
|
|
638
772
|
const panels = Object.create(null);
|
|
639
773
|
for (const [id, view] of views) {
|
|
640
|
-
panels[id] = { kind: 'sprite', name: targetName(view.target), stage: view.target.isStage, section: view.section
|
|
774
|
+
panels[id] = { kind: 'sprite', name: targetName(view.target), stage: view.target.isStage, section: view.section,
|
|
775
|
+
number: view.number };
|
|
641
776
|
}
|
|
642
777
|
if (dockview.getPanel(stagePanelId))
|
|
643
778
|
panels[stagePanelId] = { kind: 'stage' };
|
|
@@ -708,8 +843,9 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
708
843
|
const target = targets.find(item => item.isStage === reference.stage && targetName(item) === reference.name);
|
|
709
844
|
if (!target || id === stagePanelId || !sectionAvailable(reference.section))
|
|
710
845
|
return finishRestore();
|
|
711
|
-
resolvedSprites.set(id, { id, target, section: reference.section,
|
|
712
|
-
|
|
846
|
+
resolvedSprites.set(id, { id, target, section: reference.section, number: reference.number,
|
|
847
|
+
assets: createAssetSelections(target, locale) });
|
|
848
|
+
panels[id] = { id, contentComponent: 'sprite', params: { icon: getIcon(target) } };
|
|
713
849
|
}
|
|
714
850
|
else if (reference.kind === 'stage') {
|
|
715
851
|
if (!stagePane || id !== stagePanelId)
|
|
@@ -729,6 +865,10 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
729
865
|
panels[id] = { id, title: documentPanelTitle(request), contentComponent: documentComponent, renderer: 'always' };
|
|
730
866
|
}
|
|
731
867
|
}
|
|
868
|
+
assignTabNumbers(resolvedSprites.values(), new Set([...targets.map(baseTitle),
|
|
869
|
+
...Object.values(panels).map(panel => panel.title)]));
|
|
870
|
+
for (const [id, view] of resolvedSprites)
|
|
871
|
+
panels[id].title = tabTitle(view);
|
|
732
872
|
finishRestore();
|
|
733
873
|
syncing = true;
|
|
734
874
|
try {
|
|
@@ -780,10 +920,11 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
780
920
|
dockview.getPanel(id)?.api.close();
|
|
781
921
|
}
|
|
782
922
|
const represented = new Set();
|
|
923
|
+
assignTabNumbers(views.values());
|
|
783
924
|
for (const [id, view] of views) {
|
|
784
925
|
represented.add(view.target);
|
|
785
926
|
const panel = dockview.getPanel(id);
|
|
786
|
-
const title = tabTitle(view
|
|
927
|
+
const title = tabTitle(view);
|
|
787
928
|
if (panel && panel.title !== title)
|
|
788
929
|
panel.api.setTitle(title);
|
|
789
930
|
const icon = getIcon(view.target);
|
|
@@ -861,7 +1002,8 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
861
1002
|
vm.on('targetsUpdate', refresh);
|
|
862
1003
|
refresh();
|
|
863
1004
|
return {
|
|
864
|
-
select, openStage, closeStage, split, closeSplit, activateView,
|
|
1005
|
+
select, selectFromList, targetTabs, openStage, closeStage, split, closeSplit, activateView,
|
|
1006
|
+
setViewSection, syncActiveSection, refreshSurfaces,
|
|
865
1007
|
rename(id) {
|
|
866
1008
|
const target = vm.runtime.targets.find(item => item.id === id);
|
|
867
1009
|
if (target)
|
|
@@ -1143,8 +1285,15 @@ export function useSpriteTabs({ available, enabled, locale, ...props }) {
|
|
|
1143
1285
|
}, [slots, props.activeSection]);
|
|
1144
1286
|
const japanese = /^ja(?:-|$)/i.test(locale);
|
|
1145
1287
|
const select = (id) => controller.current?.select(id);
|
|
1288
|
+
const listTabs = enabled && props.multiView ? {
|
|
1289
|
+
locale,
|
|
1290
|
+
list: (id) => controller.current?.targetTabs(id) ?? [],
|
|
1291
|
+
select: (id) => controller.current?.selectFromList(id),
|
|
1292
|
+
activate: (id) => controller.current?.activateView(id)
|
|
1293
|
+
} : null;
|
|
1146
1294
|
return {
|
|
1147
1295
|
controller,
|
|
1296
|
+
listTabs,
|
|
1148
1297
|
assetSelections: (enabled ? selection.assets : undefined) ?? defaultAssets,
|
|
1149
1298
|
context: enabled ? {
|
|
1150
1299
|
selectedId: selection.id, openLabel: japanese ? '開く' : 'Open', select, open: select,
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import type { DrawerViews } from './drawer-views.ts';
|
|
2
|
+
export type { DrawerMenu, DrawerMenuRenderProps, DrawerRenderProps, DrawerView, DrawerViewId, DrawerViews, HostDrawerViewId } from './drawer-views.ts';
|
|
1
3
|
export declare function createStandardLayout(React: any, { styles, targetStyles, context, LayoutMenu }: {
|
|
2
4
|
styles: any;
|
|
3
5
|
targetStyles: any;
|
|
4
6
|
context: any;
|
|
5
7
|
LayoutMenu: any;
|
|
6
8
|
}): {
|
|
7
|
-
StandardLayout: ({ enabled, splitter, windowLayout, stageActionEnabled, stageDrawer, onPaletteModeChange, windowTools, Container, render, ...props }: {
|
|
9
|
+
StandardLayout: ({ enabled, splitter, windowLayout, stageActionEnabled, stageDrawer, onPaletteModeChange, windowTools, Container, render, drawerViews, ...props }: {
|
|
8
10
|
[x: string]: any;
|
|
9
11
|
enabled: any;
|
|
10
12
|
splitter: any;
|
|
@@ -15,6 +17,7 @@ export declare function createStandardLayout(React: any, { styles, targetStyles,
|
|
|
15
17
|
windowTools: any;
|
|
16
18
|
Container: any;
|
|
17
19
|
render: any;
|
|
20
|
+
drawerViews?: DrawerViews;
|
|
18
21
|
}) => any;
|
|
19
22
|
EdgeDrawer: ({ edge, label, pinned, onOpenChange, portalContent, holdOpenSelector, focusPanelRef, focusBoundary, showTrigger, children }: {
|
|
20
23
|
edge: any;
|
package/dist/standard-layout.js
CHANGED
|
@@ -1,24 +1,38 @@
|
|
|
1
1
|
import { createLayout, createSplitter, splitAxis } from "./index.js";
|
|
2
2
|
import { createTargetList } from "./targets.js";
|
|
3
|
+
import { availableDrawerViews, createDrawerViewBar, hasDrawerBar, readDrawerView, writeDrawerView } from "./drawer-views.js";
|
|
3
4
|
const isJapanese = locale => /^ja(?:-|$)/i.test(locale);
|
|
4
5
|
const singleColumnTargetWidth = 108;
|
|
6
|
+
// Views other than the sprite list show file names and commit subjects, so the drawer opens wider for them.
|
|
7
|
+
const drawerViewWidth = 300;
|
|
8
|
+
const minimumDrawerViewWidth = 160;
|
|
5
9
|
const minimumStandardEditor = 380;
|
|
6
10
|
export function createStandardLayout(React, { styles, targetStyles, context, LayoutMenu }) {
|
|
7
11
|
const { createElement: element, useContext, useLayoutEffect, useRef, useState } = React;
|
|
8
12
|
const SplitLayout = createLayout(React);
|
|
9
13
|
const Splitter = createSplitter(React);
|
|
10
14
|
const targets = createTargetList(React, targetStyles);
|
|
15
|
+
const DrawerViewBar = createDrawerViewBar(React, styles);
|
|
11
16
|
const targetSearch = React.createContext('');
|
|
12
17
|
const targetTools = React.createContext(null);
|
|
13
|
-
function StandardLayout({ enabled, splitter, windowLayout, stageActionEnabled, stageDrawer = false, onPaletteModeChange, windowTools, Container, render, ...props }) {
|
|
18
|
+
function StandardLayout({ enabled, splitter, windowLayout, stageActionEnabled, stageDrawer = false, onPaletteModeChange, windowTools, Container, render, drawerViews = undefined, ...props }) {
|
|
14
19
|
const [showUndock, setShowUndock] = useState(false);
|
|
15
20
|
const [targetsPinned, setTargetsPinned] = useState(true);
|
|
16
21
|
const [showStage, setShowStage] = useState(true);
|
|
17
22
|
const [stageDrawerOpen, setStageDrawerOpen] = useState(false);
|
|
18
23
|
const [size, setSize] = useState(null);
|
|
19
24
|
const [targetRatio, setTargetRatio] = useState(null);
|
|
25
|
+
const [viewRatio, setViewRatio] = useState(null);
|
|
20
26
|
const [preferredStageWidth, setPreferredStageWidth] = useState(null);
|
|
21
27
|
const [stageActionMount, setStageActionMount] = useState(null);
|
|
28
|
+
const [preferredDrawerView, setPreferredDrawerView] = useState(() => readDrawerView(props.storage, props.storageKey));
|
|
29
|
+
const hostDrawerViews = availableDrawerViews(drawerViews);
|
|
30
|
+
// A view saved earlier comes back once the host supplies it again.
|
|
31
|
+
const drawerView = hostDrawerViews.some(view => view.id === preferredDrawerView) ? preferredDrawerView : 'sprites';
|
|
32
|
+
const selectDrawerView = view => {
|
|
33
|
+
setPreferredDrawerView(view);
|
|
34
|
+
writeDrawerView(props.storage, props.storageKey, view);
|
|
35
|
+
};
|
|
22
36
|
const body = useRef(null);
|
|
23
37
|
const plusLayout = enabled && !props.fullscreen;
|
|
24
38
|
const stageHidden = plusLayout && !showStage;
|
|
@@ -40,9 +54,15 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
|
|
|
40
54
|
const stageTools = stageActionEnabled &&
|
|
41
55
|
element('span', { className: styles.stageActionSlot, ref: setStageActionMount });
|
|
42
56
|
const bodyWidth = size?.width ?? 1024;
|
|
43
|
-
|
|
57
|
+
// The sprite list and the other views keep their own widths, so widening one leaves the other as it was.
|
|
58
|
+
const wideDrawer = plusLayout && drawerView !== 'sprites';
|
|
59
|
+
const targetSplit = plusLayout && splitter && size ? (wideDrawer ?
|
|
60
|
+
splitAxis(bodyWidth, viewRatio, drawerViewWidth, minimumDrawerViewWidth, minimumStandardEditor) :
|
|
61
|
+
splitAxis(bodyWidth, targetRatio, singleColumnTargetWidth, singleColumnTargetWidth, minimumStandardEditor)) : null;
|
|
62
|
+
const fixedDrawerWidth = Math.max(singleColumnTargetWidth, Math.min(drawerViewWidth, Math.floor(bodyWidth / 2)));
|
|
44
63
|
const resizable = targetSplit && targetSplit.maximum > targetSplit.minimum;
|
|
45
|
-
const editorSpace = targetsPinned ?
|
|
64
|
+
const editorSpace = targetsPinned ?
|
|
65
|
+
(targetSplit?.second ?? bodyWidth - (wideDrawer ? fixedDrawerWidth : singleColumnTargetWidth)) : bodyWidth;
|
|
46
66
|
const maximumStageWidth = Math.max(1, Math.floor(Math.min(editorSpace - 24, ((size?.height ?? 640) - 112) * props.stageAspect)));
|
|
47
67
|
const defaultStageWidth = Math.min(maximumStageWidth, Math.floor(Math.min(props.defaultStageWidth, 360, bodyWidth / 2)));
|
|
48
68
|
const minimumStageWidth = Math.min(defaultStageWidth, 280);
|
|
@@ -94,12 +114,17 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
|
|
|
94
114
|
bodyStyle['--plus-target-width'] = `${targetSplit.first}px`;
|
|
95
115
|
bodyStyle['--plus-target-divider-width'] = `${size.width - targetSplit.available}px`;
|
|
96
116
|
}
|
|
117
|
+
else if (wideDrawer) {
|
|
118
|
+
bodyStyle['--plus-target-width'] = `${fixedDrawerWidth}px`;
|
|
119
|
+
}
|
|
97
120
|
// The target list is on the physical left in both text directions.
|
|
98
121
|
const columnSplitter = targetsPinned && resizable ? element(Splitter, {
|
|
99
122
|
axis: 'columns', split: targetSplit,
|
|
100
|
-
label: japanese ? '
|
|
123
|
+
label: wideDrawer ? (japanese ? 'ドロワーと編集領域の幅' : 'Drawer and editor width') :
|
|
124
|
+
japanese ? 'スプライト一覧と編集領域の幅' : 'Sprite list and editor width',
|
|
101
125
|
className: `${styles.separator} ${styles.standardSeparator}`,
|
|
102
|
-
onChange:
|
|
126
|
+
onChange: wideDrawer ? setViewRatio : setTargetRatio,
|
|
127
|
+
onReset: () => (wideDrawer ? setViewRatio : setTargetRatio)(null)
|
|
103
128
|
}) : null;
|
|
104
129
|
return {
|
|
105
130
|
...shared,
|
|
@@ -133,7 +158,8 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
|
|
|
133
158
|
});
|
|
134
159
|
return element(context.Provider, { value: {
|
|
135
160
|
showUndock, plusLayout, targetsPinned, setTargetsPinned, stageHidden, setStageVisible: setShowStage, stageResize, stageActionMount,
|
|
136
|
-
stageDrawer: plusLayout && stageDrawer, setStageDrawerOpen, locale: props.locale
|
|
161
|
+
stageDrawer: plusLayout && stageDrawer, setStageDrawerOpen, locale: props.locale,
|
|
162
|
+
drawerViews, drawerView, selectDrawerView
|
|
137
163
|
} }, Container ? element(Container, { locale: props.locale }, layout) : layout);
|
|
138
164
|
}
|
|
139
165
|
function EdgeDrawer({ edge, label, pinned = false, onOpenChange, portalContent = false, holdOpenSelector = '', focusPanelRef = undefined, focusBoundary = undefined, showTrigger = true, children }) {
|
|
@@ -240,13 +266,27 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
|
|
|
240
266
|
}, { left: '›', right: '‹', bottom: '⌃' }[edge]), element('div', { className: styles.edgePanel, ref: panel, tabIndex: -1, hidden: !open }, children));
|
|
241
267
|
}
|
|
242
268
|
function TargetLayout({ compact, render }) {
|
|
243
|
-
const { plusLayout, targetsPinned, locale } = useContext(context);
|
|
269
|
+
const { plusLayout, targetsPinned, locale, drawerViews, drawerView = 'sprites', selectDrawerView } = useContext(context);
|
|
244
270
|
const tools = useState(null);
|
|
245
271
|
const panel = render(plusLayout || compact);
|
|
246
|
-
|
|
272
|
+
if (!plusLayout)
|
|
273
|
+
return panel;
|
|
274
|
+
const content = element(targetTools.Provider, { value: tools }, panel);
|
|
275
|
+
const drawer = children => element(EdgeDrawer, {
|
|
247
276
|
edge: 'left', pinned: targetsPinned,
|
|
248
277
|
label: isJapanese(locale) ? 'スプライト一覧を展開' : 'Reveal sprite list'
|
|
249
|
-
},
|
|
278
|
+
}, children);
|
|
279
|
+
// Without host views the drawer keeps the sprite list as its only, unwrapped content.
|
|
280
|
+
if (!hasDrawerBar(drawerViews))
|
|
281
|
+
return drawer(content);
|
|
282
|
+
const views = availableDrawerViews(drawerViews);
|
|
283
|
+
const active = views.find(view => view.id === drawerView);
|
|
284
|
+
return drawer(element(React.Fragment, null, element(DrawerViewBar, { locale, views, agents: drawerViews.agents, selected: active ? active.id : 'sprites',
|
|
285
|
+
onSelect: selectDrawerView }),
|
|
286
|
+
// Pinning belongs to the drawer, so every view keeps the pin button the sprite list shows.
|
|
287
|
+
active && element('div', { className: styles.drawerViewTools }, active.tools?.({ locale }), element(DrawerPinButton, { label: isJapanese(locale) ? 'このパネルを固定表示' : 'Pin this panel' })),
|
|
288
|
+
// The GUI's target pane stays mounted, so its file inputs and library keep working while hidden.
|
|
289
|
+
element('div', { className: styles.drawerSprites, hidden: Boolean(active) }, content), active && element('div', { className: styles.drawerViewContent, 'data-drawer-content': active.id }, active.render({ locale }))));
|
|
250
290
|
}
|
|
251
291
|
function SpriteGrid(props) {
|
|
252
292
|
const { plusLayout } = useContext(context);
|
|
@@ -281,8 +321,14 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
|
|
|
281
321
|
onClick: () => setExpanded(open => !open)
|
|
282
322
|
}, isJapanese(locale) ? 'スプライト' : 'Sprite'), element('div', { ref: tools?.[1] }), !inEditor && element('div', { className: styles.spritePropertiesContent, hidden: !expanded }, children)) : fallback;
|
|
283
323
|
}
|
|
324
|
+
function DrawerPinButton({ label }) {
|
|
325
|
+
const { targetsPinned, setTargetsPinned } = useContext(context);
|
|
326
|
+
return element('button', { type: 'button', className: styles.drawerPin, 'aria-label': label, 'aria-pressed': targetsPinned,
|
|
327
|
+
title: label, onClick: () => setTargetsPinned(value => !value) }, element('svg', { 'aria-hidden': true, width: 14, height: 14, viewBox: '0 0 16 16',
|
|
328
|
+
fill: targetsPinned ? 'currentColor' : 'none', stroke: 'currentColor', strokeWidth: 1.2, strokeLinejoin: 'round' }, element('path', { d: 'M9 2 14 7 12 8l-2 3-5-5 3-2 1-2Z' }), element('path', { d: 'm7.5 8.5-4 4' }), !targetsPinned && element('path', { d: 'M2 2l12 12', strokeLinecap: 'round' })));
|
|
329
|
+
}
|
|
284
330
|
function useSpriteListTools() {
|
|
285
|
-
const { locale
|
|
331
|
+
const { locale } = useContext(context);
|
|
286
332
|
const [mount] = useContext(targetTools) ?? [];
|
|
287
333
|
const [searching, setSearching] = useState(false);
|
|
288
334
|
const [query, setQuery] = useState('');
|
|
@@ -303,9 +349,7 @@ export function createStandardLayout(React, { styles, targetStyles, context, Lay
|
|
|
303
349
|
const renderTools = openAction => element(React.Fragment, null, element('div', { className: styles.targetListTools, role: 'group',
|
|
304
350
|
'aria-label': japanese ? 'スプライト一覧の操作' : 'Sprite list tools' }, element('button', { type: 'button', ref: searchButton, 'aria-label': searchLabel, 'aria-expanded': searching,
|
|
305
351
|
title: searchLabel, onClick: () => searching ? closeSearch() : setSearching(true) }, element('svg', { 'aria-hidden': true, width: 14, height: 14, viewBox: '0 0 16 16',
|
|
306
|
-
fill: 'none', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round' }, element('circle', { cx: 6.5, cy: 6.5, r: 4 }), element('path', { d: 'm9.5 9.5 4 4' }))), element('
|
|
307
|
-
title: pinLabel, onClick: () => setTargetsPinned(value => !value) }, element('svg', { 'aria-hidden': true, width: 14, height: 14, viewBox: '0 0 16 16',
|
|
308
|
-
fill: targetsPinned ? 'currentColor' : 'none', stroke: 'currentColor', strokeWidth: 1.2, strokeLinejoin: 'round' }, element('path', { d: 'M9 2 14 7 12 8l-2 3-5-5 3-2 1-2Z' }), element('path', { d: 'm7.5 8.5-4 4' }), !targetsPinned && element('path', { d: 'M2 2l12 12', strokeLinecap: 'round' }))), openAction), searching && element('input', { type: 'search', className: styles.targetListSearch, 'aria-label': searchLabel,
|
|
352
|
+
fill: 'none', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round' }, element('circle', { cx: 6.5, cy: 6.5, r: 4 }), element('path', { d: 'm9.5 9.5 4 4' }))), element(DrawerPinButton, { label: pinLabel }), openAction), searching && element('input', { type: 'search', className: styles.targetListSearch, 'aria-label': searchLabel,
|
|
309
353
|
ref: searchInput, placeholder: japanese ? '名前' : 'Name', value: query,
|
|
310
354
|
onChange: event => setQuery(event.currentTarget.value),
|
|
311
355
|
onKeyDown: event => {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { IContextMenuItemRenderer } from 'dockview';
|
|
3
|
+
interface TargetTabs {
|
|
4
|
+
locale: string;
|
|
5
|
+
list(id?: string): readonly {
|
|
6
|
+
id: string;
|
|
7
|
+
title: string;
|
|
8
|
+
}[];
|
|
9
|
+
select(id?: string): void;
|
|
10
|
+
activate(id: string): void;
|
|
11
|
+
}
|
|
12
|
+
interface MenuPrimitives {
|
|
13
|
+
MenuItem: React.ElementType;
|
|
14
|
+
SubMenu: React.ElementType;
|
|
15
|
+
menuClassName: string;
|
|
16
|
+
itemClassName: string;
|
|
17
|
+
}
|
|
18
|
+
export declare const spriteRenameLabel: (locale: string) => "スプライト名の変更" | "Rename sprite";
|
|
19
|
+
export declare const SpriteTargetTabsContext: React.Context<TargetTabs>;
|
|
20
|
+
export declare function createRenameMenuItem(document: Document, title: string, rename: (id: string) => void): IContextMenuItemRenderer;
|
|
21
|
+
export declare function useTargetTabMenu(): {
|
|
22
|
+
onShow(id?: string): void;
|
|
23
|
+
select: (id?: string) => void;
|
|
24
|
+
render({ MenuItem, SubMenu, menuClassName, itemClassName }: MenuPrimitives, id?: string, rename?: (event: React.MouseEvent) => void): {
|
|
25
|
+
open: React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
26
|
+
rename: React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
const pencil = 'm4 16-1 5 5-1L21 7l-4-4L4 16Zm10-10 4 4';
|
|
3
|
+
const open = 'M13 4h7v7m0-7-9 9m-1-8H4v15h15v-6';
|
|
4
|
+
const iconClass = 'tw-plus-target-menu-icon';
|
|
5
|
+
const svgNamespace = 'http://www.w3.org/2000/svg';
|
|
6
|
+
const isJapanese = (locale) => /^ja(?:-|$)/i.test(locale);
|
|
7
|
+
export const spriteRenameLabel = (locale) => isJapanese(locale) ? 'スプライト名の変更' : 'Rename sprite';
|
|
8
|
+
export const SpriteTargetTabsContext = React.createContext(null);
|
|
9
|
+
export function createRenameMenuItem(document, title, rename) {
|
|
10
|
+
const element = document.createElement('button');
|
|
11
|
+
element.type = 'button';
|
|
12
|
+
element.className = 'dv-context-menu-item tw-plus-target-menu-button';
|
|
13
|
+
element.setAttribute('role', 'menuitem');
|
|
14
|
+
const icon = document.createElementNS(svgNamespace, 'svg');
|
|
15
|
+
icon.setAttribute('class', iconClass);
|
|
16
|
+
icon.setAttribute('viewBox', '0 0 24 24');
|
|
17
|
+
icon.setAttribute('aria-hidden', 'true');
|
|
18
|
+
const path = document.createElementNS(svgNamespace, 'path');
|
|
19
|
+
path.setAttribute('d', pencil);
|
|
20
|
+
icon.append(path);
|
|
21
|
+
element.append(icon, title);
|
|
22
|
+
return {
|
|
23
|
+
element,
|
|
24
|
+
init(props) {
|
|
25
|
+
if (!('panel' in props))
|
|
26
|
+
return;
|
|
27
|
+
element.onclick = () => {
|
|
28
|
+
props.close();
|
|
29
|
+
rename(props.panel.id);
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
dispose() {
|
|
33
|
+
element.onclick = null;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const itemLabel = (path, label) => React.createElement(React.Fragment, null, React.createElement('svg', { className: iconClass, 'aria-hidden': true, viewBox: '0 0 24 24' }, React.createElement('path', { d: path })), label);
|
|
38
|
+
export function useTargetTabMenu() {
|
|
39
|
+
const tabs = React.useContext(SpriteTargetTabsContext);
|
|
40
|
+
const [shown, setShown] = React.useState();
|
|
41
|
+
if (!tabs)
|
|
42
|
+
return null;
|
|
43
|
+
return {
|
|
44
|
+
onShow(id) {
|
|
45
|
+
// Read the live order even if the last move did not change the selection.
|
|
46
|
+
setShown({ id, views: tabs.list(id) });
|
|
47
|
+
},
|
|
48
|
+
select: tabs.select,
|
|
49
|
+
render({ MenuItem, SubMenu, menuClassName, itemClassName }, id, rename) {
|
|
50
|
+
const views = shown?.id === id ? shown?.views ?? [] : [];
|
|
51
|
+
const label = itemLabel(open, isJapanese(tabs.locale) ? '開く' : 'Open');
|
|
52
|
+
const attributes = { className: itemClassName, 'data-tw-plus-menu-icon': '' };
|
|
53
|
+
const openItem = views.length > 1 ? React.createElement(SubMenu, {
|
|
54
|
+
title: React.createElement(React.Fragment, null, label, React.createElement('span', { className: 'tw-plus-target-submenu-arrow', 'aria-hidden': true }, '›')),
|
|
55
|
+
className: `${menuClassName} tw-plus-target-submenu`,
|
|
56
|
+
attributes
|
|
57
|
+
}, views.map(view => React.createElement(MenuItem, {
|
|
58
|
+
key: view.id, attributes: { className: itemClassName },
|
|
59
|
+
onClick: (event) => {
|
|
60
|
+
event.stopPropagation();
|
|
61
|
+
tabs.activate(view.id);
|
|
62
|
+
}
|
|
63
|
+
}, view.title))) : React.createElement(MenuItem, {
|
|
64
|
+
attributes,
|
|
65
|
+
onClick: (event) => {
|
|
66
|
+
event.stopPropagation();
|
|
67
|
+
tabs.select(id);
|
|
68
|
+
}
|
|
69
|
+
}, label);
|
|
70
|
+
return {
|
|
71
|
+
open: openItem,
|
|
72
|
+
rename: rename && React.createElement(MenuItem, { attributes, onClick: rename }, itemLabel(pencil, spriteRenameLabel(tabs.locale)))
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
package/dist/workspace-layout.js
CHANGED
|
@@ -158,8 +158,12 @@ export function readWorkspaceLayout(raw, project) {
|
|
|
158
158
|
if (!Object.hasOwn(input.panels, id) || !record(panel))
|
|
159
159
|
return;
|
|
160
160
|
if (panel.kind === 'sprite' && validId(panel.name) && typeof panel.stage === 'boolean' &&
|
|
161
|
-
typeof panel.section === 'number' && Number.isInteger(panel.section) && panel.section >= 0 && panel.section <=
|
|
162
|
-
|
|
161
|
+
typeof panel.section === 'number' && Number.isInteger(panel.section) && panel.section >= 0 && panel.section <= 4) {
|
|
162
|
+
const number = panel.number;
|
|
163
|
+
if (number !== undefined && (typeof number !== 'number' || !Number.isSafeInteger(number) || number < 2))
|
|
164
|
+
return;
|
|
165
|
+
panels[id] = { kind: 'sprite', name: panel.name, stage: panel.stage, section: panel.section,
|
|
166
|
+
...(typeof number === 'number' && { number }) };
|
|
163
167
|
}
|
|
164
168
|
else if (panel.kind === 'stage' && !hasStage) {
|
|
165
169
|
hasStage = true;
|