@kubohiroya/turbowarp-plus-editor-workbench 0.3.1 → 0.4.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/document-workspace.d.ts +17 -0
- package/dist/sprite-layout-menu.d.ts +3 -0
- package/dist/sprite-layout-menu.js +21 -8
- package/dist/sprite-tabs.js +70 -2
- package/package.json +1 -1
- package/src/document-workspace.ts +12 -0
- package/src/sprite-layout-menu.css +34 -0
- package/src/sprite-layout-menu.ts +27 -8
- package/src/sprite-tabs.ts +56 -2
|
@@ -7,6 +7,23 @@ export interface DocumentPanelRequest {
|
|
|
7
7
|
/** What the tab shows. Without it the tab names the file and where it comes from. */
|
|
8
8
|
title?: string;
|
|
9
9
|
transient?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Opens the tab beside the other open tabs of the same area, in one split panel. The first tab of an area
|
|
12
|
+
* opens in a new split to the right of the active panel, so the area does not mix with the sprite tabs.
|
|
13
|
+
*/
|
|
14
|
+
area?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Gathers the tab under a labelled chip with the other tabs of the same `id` in its split panel.
|
|
17
|
+
* `color` is a palette id of the workspace, such as `'green'`, `'red'` or `'blue'`.
|
|
18
|
+
*/
|
|
19
|
+
tabGroup?: {
|
|
20
|
+
id: string;
|
|
21
|
+
label: string;
|
|
22
|
+
color?: string;
|
|
23
|
+
collapsed?: boolean;
|
|
24
|
+
};
|
|
25
|
+
/** Opens the tab behind the active one, as when many tabs are opened at once. */
|
|
26
|
+
inactive?: boolean;
|
|
10
27
|
mount(element: HTMLElement, close: () => void): {
|
|
11
28
|
requestClose(): void;
|
|
12
29
|
dispose(): void;
|
|
@@ -8,6 +8,9 @@ interface SpriteLayoutCommands {
|
|
|
8
8
|
canOpenPanel?(): boolean;
|
|
9
9
|
openPalette?(): void;
|
|
10
10
|
canOpenPalette?(): boolean;
|
|
11
|
+
/** Whether the tabs stand in a column at the left of each split panel instead of a row above it. */
|
|
12
|
+
verticalTabs?(): boolean;
|
|
13
|
+
setVerticalTabs?(vertical: boolean): void;
|
|
11
14
|
}
|
|
12
15
|
export declare function createSpriteLayoutMenu(document: Document, locale: string, commands: SpriteLayoutCommands): {
|
|
13
16
|
element: HTMLDivElement;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const labels = {
|
|
2
2
|
ja: ['編集パネルのレイアウト', 'パネルを横に分割', 'パネルを縦に分割', 'この分割パネルを閉じる',
|
|
3
|
-
'パネルを別画面で開く', 'ブロックパレットを別画面で開く'],
|
|
3
|
+
'パネルを別画面で開く', 'ブロックパレットを別画面で開く', 'タブを垂直に並べて表示', 'タブを水平に並べて表示'],
|
|
4
4
|
en: ['Editor panel layout', 'Split right', 'Split below', 'Close this split',
|
|
5
|
-
'Open panel in another window', 'Open block palette in another window']
|
|
5
|
+
'Open panel in another window', 'Open block palette in another window', 'Show tabs vertically', 'Show tabs horizontally']
|
|
6
6
|
};
|
|
7
7
|
function createIcon(document, path) {
|
|
8
8
|
const ns = 'http://www.w3.org/2000/svg';
|
|
@@ -20,7 +20,7 @@ function createIcon(document, path) {
|
|
|
20
20
|
return icon;
|
|
21
21
|
}
|
|
22
22
|
export function createSpriteLayoutMenu(document, locale, commands) {
|
|
23
|
-
const [title, right, below, closeLabel, panelLabel, paletteLabel] = /^ja(?:-|$)/i.test(locale) ? labels.ja : labels.en;
|
|
23
|
+
const [title, right, below, closeLabel, panelLabel, paletteLabel, verticalLabel, horizontalLabel] = /^ja(?:-|$)/i.test(locale) ? labels.ja : labels.en;
|
|
24
24
|
const element = document.createElement('div');
|
|
25
25
|
element.className = 'tw-plus-sprite-layout-menu';
|
|
26
26
|
const trigger = document.createElement('button');
|
|
@@ -42,21 +42,32 @@ export function createSpriteLayoutMenu(document, locale, commands) {
|
|
|
42
42
|
{ label: closeLabel, run: commands.close, enabled: commands.canClose, path: 'm4.5 4.5 7 7m0-7-7 7' },
|
|
43
43
|
{ label: panelLabel, run: commands.openPanel, enabled: commands.canOpenPanel, path: 'M7 3H3v10h10V9m-5-1 5-5m-4 0h4v4' },
|
|
44
44
|
{ label: paletteLabel, run: commands.openPalette, enabled: commands.canOpenPalette,
|
|
45
|
-
path: 'M7 4H3v3h2v2H3v3h7v-2h2V9m-3-2 4-4m-3 0h3v3' }
|
|
45
|
+
path: 'M7 4H3v3h2v2H3v3h7v-2h2V9m-3-2 4-4m-3 0h3v3' },
|
|
46
|
+
...(commands.verticalTabs && commands.setVerticalTabs ? [{
|
|
47
|
+
label: verticalLabel, run: () => commands.setVerticalTabs(!commands.verticalTabs()),
|
|
48
|
+
path: 'M2.5 3.5h11v9h-11zM6 3.5v9M2.5 6h3.5m-3.5 2.5h3.5',
|
|
49
|
+
// The item names the arrangement it switches to.
|
|
50
|
+
current: () => commands.verticalTabs() ?
|
|
51
|
+
{ label: horizontalLabel, path: 'M2.5 3.5h11v9h-11zM2.5 6.5h11M6 3.5v3m3.5-3v3' } : undefined
|
|
52
|
+
}] : [])
|
|
46
53
|
];
|
|
47
|
-
const entries = items.flatMap(({ label, run, enabled, path }) => {
|
|
54
|
+
const entries = items.flatMap(({ label, run, enabled, path, current }) => {
|
|
48
55
|
if (!run)
|
|
49
56
|
return [];
|
|
50
57
|
const item = document.createElement('button');
|
|
51
58
|
item.type = 'button';
|
|
52
|
-
|
|
59
|
+
const render = () => {
|
|
60
|
+
const shown = current?.() ?? { label, path };
|
|
61
|
+
item.replaceChildren(createIcon(document, shown.path), shown.label);
|
|
62
|
+
};
|
|
63
|
+
render();
|
|
53
64
|
item.tabIndex = -1;
|
|
54
65
|
item.setAttribute('role', 'menuitem');
|
|
55
66
|
item.addEventListener('click', () => {
|
|
56
67
|
close(true);
|
|
57
68
|
run();
|
|
58
69
|
});
|
|
59
|
-
return [{ item, enabled }];
|
|
70
|
+
return [{ item, enabled, render: current && render }];
|
|
60
71
|
});
|
|
61
72
|
const buttons = entries.map(({ item }) => item);
|
|
62
73
|
popup.append(...buttons);
|
|
@@ -83,8 +94,10 @@ export function createSpriteLayoutMenu(document, locale, commands) {
|
|
|
83
94
|
if (openedIn)
|
|
84
95
|
return;
|
|
85
96
|
openedIn = trigger.ownerDocument;
|
|
86
|
-
for (const { item, enabled } of entries)
|
|
97
|
+
for (const { item, enabled, render } of entries) {
|
|
87
98
|
item.disabled = enabled?.() === false;
|
|
99
|
+
render?.();
|
|
100
|
+
}
|
|
88
101
|
topLayer = typeof popup.showPopover === 'function';
|
|
89
102
|
if (topLayer) {
|
|
90
103
|
popup.setAttribute('popover', 'manual');
|
package/dist/sprite-tabs.js
CHANGED
|
@@ -99,6 +99,9 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
99
99
|
const editLabel = japanese ? 'クリックしてこのビューで編集' : 'Activate this view to edit';
|
|
100
100
|
const backdropTitle = japanese ? '背景' : 'Backdrops';
|
|
101
101
|
const tabTitle = (target) => target.isStage ? backdropTitle : target.getName();
|
|
102
|
+
const chipText = japanese ?
|
|
103
|
+
{ collapse: 'グループを折りたたむ', expand: 'グループを展開する', close: 'このグループのタブを閉じる', closeAll: 'この分割パネルの文書タブをすべて閉じる' } :
|
|
104
|
+
{ collapse: 'Collapse group', expand: 'Expand group', close: 'Close the tabs of this group', closeAll: 'Close all document tabs of this split' };
|
|
102
105
|
const slots = new Map();
|
|
103
106
|
const views = new Map();
|
|
104
107
|
const documents = new Map();
|
|
@@ -123,12 +126,33 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
123
126
|
/** Panels that were in a separate window when the layout was saved, until the user reopens them. */
|
|
124
127
|
const reopenable = new Map();
|
|
125
128
|
const originalTargets = () => vm.runtime.targets.filter(target => target.isOriginal);
|
|
129
|
+
// Whether tabs stand in a column at the left of each split. It is the user's preference, kept apart from the layout.
|
|
130
|
+
const tabsKey = persistence ? persistence.key + '.tabs' : undefined;
|
|
131
|
+
let verticalTabs = false;
|
|
132
|
+
try {
|
|
133
|
+
verticalTabs = Boolean(tabsKey) && persistence.storage.getItem(tabsKey) === 'left';
|
|
134
|
+
}
|
|
135
|
+
catch { /* Storage can be unavailable. */ }
|
|
126
136
|
const dockview = createDockview(root, {
|
|
127
137
|
theme: themeLight,
|
|
128
138
|
disableFloatingGroups: true,
|
|
139
|
+
defaultHeaderPosition: verticalTabs ? 'left' : 'top',
|
|
129
140
|
...(multiView && { createRightHeaderActionComponent: createLayoutMenu }),
|
|
130
141
|
defaultTabComponent: 'sprite',
|
|
131
142
|
createTabComponent: () => new SpriteTab(document),
|
|
143
|
+
// A chip stands for several tabs, such as the changed scripts of one sprite, so it closes them together.
|
|
144
|
+
getTabGroupChipContextMenuItems: ({ tabGroup, group }) => [
|
|
145
|
+
{ label: tabGroup.collapsed ? chipText.expand : chipText.collapse, action: () => tabGroup.toggle() },
|
|
146
|
+
{ label: chipText.close, action: () => {
|
|
147
|
+
for (const id of [...tabGroup.panelIds])
|
|
148
|
+
dockview.getPanel(id)?.api.close();
|
|
149
|
+
} },
|
|
150
|
+
{ label: chipText.closeAll, action: () => {
|
|
151
|
+
for (const panel of [...group.panels])
|
|
152
|
+
if (documents.has(panel.id))
|
|
153
|
+
panel.api.close();
|
|
154
|
+
} }
|
|
155
|
+
],
|
|
132
156
|
getTabContextMenuItems: ({ panel }) => {
|
|
133
157
|
const target = views.get(panel.id)?.target;
|
|
134
158
|
if (!target || target.isStage || !vm.renameSprite)
|
|
@@ -257,6 +281,8 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
257
281
|
closeSplit(group.activePanel.id); },
|
|
258
282
|
canClose: () => canCloseGroup(group),
|
|
259
283
|
canSplit: () => views.has(group.activePanel?.id),
|
|
284
|
+
verticalTabs: () => verticalTabs,
|
|
285
|
+
setVerticalTabs,
|
|
260
286
|
...(popouts && {
|
|
261
287
|
canOpenPanel,
|
|
262
288
|
openPanel() {
|
|
@@ -293,6 +319,19 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
293
319
|
});
|
|
294
320
|
return { ...menu, init() { } };
|
|
295
321
|
}
|
|
322
|
+
function setVerticalTabs(vertical) {
|
|
323
|
+
verticalTabs = vertical;
|
|
324
|
+
const position = vertical ? 'left' : 'top';
|
|
325
|
+
dockview.updateOptions({ defaultHeaderPosition: position });
|
|
326
|
+
for (const group of dockview.groups)
|
|
327
|
+
group.api.setHeaderPosition(position);
|
|
328
|
+
try {
|
|
329
|
+
if (tabsKey)
|
|
330
|
+
persistence.storage.setItem(tabsKey, position);
|
|
331
|
+
}
|
|
332
|
+
catch { /* Storage can be unavailable. */ }
|
|
333
|
+
refreshSurfaces();
|
|
334
|
+
}
|
|
296
335
|
const canRename = (target) => target.isOriginal && !target.isStage && Boolean(vm.renameSprite) && vm.runtime.targets.includes(target);
|
|
297
336
|
function openRenameDialog(target) {
|
|
298
337
|
if (renameDialog || !canRename(target))
|
|
@@ -521,7 +560,8 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
521
560
|
const { providerId, documentId } = request.reference;
|
|
522
561
|
for (const [id, { request: opened }] of documents) {
|
|
523
562
|
if (opened.reference.providerId === providerId && opened.reference.documentId === documentId) {
|
|
524
|
-
|
|
563
|
+
if (!request.inactive)
|
|
564
|
+
dockview.getPanel(id)?.api.setActive();
|
|
525
565
|
return;
|
|
526
566
|
}
|
|
527
567
|
}
|
|
@@ -530,15 +570,43 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
530
570
|
id = 'document-view-' + ++nextView;
|
|
531
571
|
} while (views.has(id) || documents.has(id) || vm.runtime.targets.some(target => target.id === id));
|
|
532
572
|
const title = documentPanelTitle(request);
|
|
573
|
+
const position = documentPosition(request);
|
|
533
574
|
documents.set(id, { request });
|
|
534
575
|
try {
|
|
535
|
-
dockview.addPanel({ id, title, component: documentComponent, renderer: 'always'
|
|
576
|
+
dockview.addPanel({ id, title, component: documentComponent, renderer: 'always',
|
|
577
|
+
inactive: request.inactive, ...(position && { position }) });
|
|
536
578
|
}
|
|
537
579
|
catch (error) {
|
|
538
580
|
documents.get(id)?.session?.dispose();
|
|
539
581
|
documents.delete(id);
|
|
540
582
|
throw error;
|
|
541
583
|
}
|
|
584
|
+
if (request.tabGroup)
|
|
585
|
+
joinTabGroup(id, request.tabGroup);
|
|
586
|
+
}
|
|
587
|
+
/** Where a document of an area opens: in the split that already shows its area, or in a new split beside the editor. */
|
|
588
|
+
function documentPosition({ area }) {
|
|
589
|
+
if (!area)
|
|
590
|
+
return;
|
|
591
|
+
for (const [id, { request }] of documents) {
|
|
592
|
+
const panel = request.area === area && dockview.getPanel(id);
|
|
593
|
+
if (panel && panel.group.api.location.type === 'grid')
|
|
594
|
+
return { referenceGroup: panel.group };
|
|
595
|
+
}
|
|
596
|
+
const reference = dockview.activePanel;
|
|
597
|
+
return reference && reference.group.api.location.type === 'grid' ?
|
|
598
|
+
{ referencePanel: reference.id, direction: 'right' } : undefined;
|
|
599
|
+
}
|
|
600
|
+
function joinTabGroup(id, { id: key, label, color, collapsed }) {
|
|
601
|
+
const panel = dockview.getPanel(id);
|
|
602
|
+
if (!panel)
|
|
603
|
+
return;
|
|
604
|
+
const groupId = panel.group.id;
|
|
605
|
+
const existing = dockview.getTabGroups({ groupId }).find(item => item.componentParams?.key === key);
|
|
606
|
+
const tabGroup = existing ?? dockview.createTabGroup({ groupId, label, color, componentParams: { key } });
|
|
607
|
+
dockview.addPanelToTabGroup({ groupId, tabGroupId: tabGroup.id, panelId: id });
|
|
608
|
+
if (!existing && collapsed)
|
|
609
|
+
tabGroup.collapse();
|
|
542
610
|
}
|
|
543
611
|
function guardDocumentClose(event) {
|
|
544
612
|
const element = event.target;
|
package/package.json
CHANGED
|
@@ -4,6 +4,18 @@ export interface DocumentPanelRequest {
|
|
|
4
4
|
/** What the tab shows. Without it the tab names the file and where it comes from. */
|
|
5
5
|
title?: string;
|
|
6
6
|
transient?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Opens the tab beside the other open tabs of the same area, in one split panel. The first tab of an area
|
|
9
|
+
* opens in a new split to the right of the active panel, so the area does not mix with the sprite tabs.
|
|
10
|
+
*/
|
|
11
|
+
area?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Gathers the tab under a labelled chip with the other tabs of the same `id` in its split panel.
|
|
14
|
+
* `color` is a palette id of the workspace, such as `'green'`, `'red'` or `'blue'`.
|
|
15
|
+
*/
|
|
16
|
+
tabGroup?: {id: string; label: string; color?: string; collapsed?: boolean};
|
|
17
|
+
/** Opens the tab behind the active one, as when many tabs are opened at once. */
|
|
18
|
+
inactive?: boolean;
|
|
7
19
|
mount(element: HTMLElement, close: () => void): {requestClose(): void; dispose(): void};
|
|
8
20
|
}
|
|
9
21
|
|
|
@@ -56,3 +56,37 @@
|
|
|
56
56
|
.tw-plus-sprite-layout-menu-popup button:enabled:is(:hover, :focus-visible) {
|
|
57
57
|
background: var(--looks-light-transparent, #e6dff3);
|
|
58
58
|
}
|
|
59
|
+
|
|
60
|
+
/*
|
|
61
|
+
* "Show tabs vertically" stands the tabs of a split in a column at its left. dockview turns each tab on its side;
|
|
62
|
+
* here the column is a list of rows instead, so titles and tab group chips read as they do in a row.
|
|
63
|
+
*/
|
|
64
|
+
.dv-groupview-header-left > .dv-tabs-and-actions-container.dv-groupview-header-vertical {
|
|
65
|
+
width: var(--tw-plus-vertical-tabs-width, 180px);
|
|
66
|
+
border-inline-end: 1px solid var(--ui-black-transparent, #c6cfda);
|
|
67
|
+
}
|
|
68
|
+
.dv-groupview-header-left .dv-tabs-container.dv-tabs-container-vertical {
|
|
69
|
+
flex-direction: column;
|
|
70
|
+
height: auto;
|
|
71
|
+
overflow-x: hidden;
|
|
72
|
+
overflow-y: auto;
|
|
73
|
+
writing-mode: horizontal-tb;
|
|
74
|
+
}
|
|
75
|
+
.dv-groupview-header-left .dv-tabs-container-vertical > .dv-tab {
|
|
76
|
+
box-sizing: border-box;
|
|
77
|
+
width: 100%;
|
|
78
|
+
padding-inline: 8px 4px;
|
|
79
|
+
}
|
|
80
|
+
.dv-groupview-header-left .dv-tabs-container-vertical > .dv-tab .dv-default-tab-content {
|
|
81
|
+
overflow: hidden;
|
|
82
|
+
text-overflow: ellipsis;
|
|
83
|
+
white-space: nowrap;
|
|
84
|
+
}
|
|
85
|
+
.dv-groupview-header-left .dv-tabs-container-vertical > .dv-tab-group-chip {
|
|
86
|
+
align-self: flex-start;
|
|
87
|
+
margin: 6px 4px 2px;
|
|
88
|
+
}
|
|
89
|
+
.dv-groupview-header-left .dv-right-actions-container-vertical {
|
|
90
|
+
flex-direction: row;
|
|
91
|
+
justify-content: flex-end;
|
|
92
|
+
}
|
|
@@ -8,13 +8,16 @@ interface SpriteLayoutCommands {
|
|
|
8
8
|
canOpenPanel?(): boolean;
|
|
9
9
|
openPalette?(): void;
|
|
10
10
|
canOpenPalette?(): boolean;
|
|
11
|
+
/** Whether the tabs stand in a column at the left of each split panel instead of a row above it. */
|
|
12
|
+
verticalTabs?(): boolean;
|
|
13
|
+
setVerticalTabs?(vertical: boolean): void;
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
const labels = {
|
|
14
17
|
ja: ['編集パネルのレイアウト', 'パネルを横に分割', 'パネルを縦に分割', 'この分割パネルを閉じる',
|
|
15
|
-
'パネルを別画面で開く', 'ブロックパレットを別画面で開く'],
|
|
18
|
+
'パネルを別画面で開く', 'ブロックパレットを別画面で開く', 'タブを垂直に並べて表示', 'タブを水平に並べて表示'],
|
|
16
19
|
en: ['Editor panel layout', 'Split right', 'Split below', 'Close this split',
|
|
17
|
-
'Open panel in another window', 'Open block palette in another window']
|
|
20
|
+
'Open panel in another window', 'Open block palette in another window', 'Show tabs vertically', 'Show tabs horizontally']
|
|
18
21
|
};
|
|
19
22
|
|
|
20
23
|
function createIcon(document: Document, path: string) {
|
|
@@ -34,7 +37,7 @@ function createIcon(document: Document, path: string) {
|
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
export function createSpriteLayoutMenu(document: Document, locale: string, commands: SpriteLayoutCommands) {
|
|
37
|
-
const [title, right, below, closeLabel, panelLabel, paletteLabel] = /^ja(?:-|$)/i.test(locale) ? labels.ja : labels.en;
|
|
40
|
+
const [title, right, below, closeLabel, panelLabel, paletteLabel, verticalLabel, horizontalLabel] = /^ja(?:-|$)/i.test(locale) ? labels.ja : labels.en;
|
|
38
41
|
const element = document.createElement('div');
|
|
39
42
|
element.className = 'tw-plus-sprite-layout-menu';
|
|
40
43
|
const trigger = document.createElement('button');
|
|
@@ -57,20 +60,33 @@ export function createSpriteLayoutMenu(document: Document, locale: string, comma
|
|
|
57
60
|
{label: closeLabel, run: commands.close, enabled: commands.canClose, path: 'm4.5 4.5 7 7m0-7-7 7'},
|
|
58
61
|
{label: panelLabel, run: commands.openPanel, enabled: commands.canOpenPanel, path: 'M7 3H3v10h10V9m-5-1 5-5m-4 0h4v4'},
|
|
59
62
|
{label: paletteLabel, run: commands.openPalette, enabled: commands.canOpenPalette,
|
|
60
|
-
path: 'M7 4H3v3h2v2H3v3h7v-2h2V9m-3-2 4-4m-3 0h3v3'}
|
|
63
|
+
path: 'M7 4H3v3h2v2H3v3h7v-2h2V9m-3-2 4-4m-3 0h3v3'},
|
|
64
|
+
...(commands.verticalTabs && commands.setVerticalTabs ? [{
|
|
65
|
+
label: verticalLabel, run: () => commands.setVerticalTabs!(!commands.verticalTabs!()),
|
|
66
|
+
path: 'M2.5 3.5h11v9h-11zM6 3.5v9M2.5 6h3.5m-3.5 2.5h3.5',
|
|
67
|
+
// The item names the arrangement it switches to.
|
|
68
|
+
current: () => commands.verticalTabs!() ?
|
|
69
|
+
{label: horizontalLabel, path: 'M2.5 3.5h11v9h-11zM2.5 6.5h11M6 3.5v3m3.5-3v3'} : undefined
|
|
70
|
+
}] : [])
|
|
61
71
|
];
|
|
62
|
-
const entries = items.flatMap(({label, run, enabled, path}
|
|
72
|
+
const entries = items.flatMap(({label, run, enabled, path, current}: typeof items[number] & {
|
|
73
|
+
current?(): {label: string; path: string} | undefined;
|
|
74
|
+
}) => {
|
|
63
75
|
if (!run) return [];
|
|
64
76
|
const item = document.createElement('button');
|
|
65
77
|
item.type = 'button';
|
|
66
|
-
|
|
78
|
+
const render = () => {
|
|
79
|
+
const shown = current?.() ?? {label, path};
|
|
80
|
+
item.replaceChildren(createIcon(document, shown.path), shown.label);
|
|
81
|
+
};
|
|
82
|
+
render();
|
|
67
83
|
item.tabIndex = -1;
|
|
68
84
|
item.setAttribute('role', 'menuitem');
|
|
69
85
|
item.addEventListener('click', () => {
|
|
70
86
|
close(true);
|
|
71
87
|
run();
|
|
72
88
|
});
|
|
73
|
-
return [{item, enabled}];
|
|
89
|
+
return [{item, enabled, render: current && render}];
|
|
74
90
|
});
|
|
75
91
|
const buttons = entries.map(({item}) => item);
|
|
76
92
|
popup.append(...buttons);
|
|
@@ -95,7 +111,10 @@ export function createSpriteLayoutMenu(document: Document, locale: string, comma
|
|
|
95
111
|
function open(last = false) {
|
|
96
112
|
if (openedIn) return;
|
|
97
113
|
openedIn = trigger.ownerDocument;
|
|
98
|
-
for (const {item, enabled} of entries)
|
|
114
|
+
for (const {item, enabled, render} of entries) {
|
|
115
|
+
item.disabled = enabled?.() === false;
|
|
116
|
+
render?.();
|
|
117
|
+
}
|
|
99
118
|
topLayer = typeof popup.showPopover === 'function';
|
|
100
119
|
if (topLayer) {
|
|
101
120
|
popup.setAttribute('popover', 'manual');
|
package/src/sprite-tabs.ts
CHANGED
|
@@ -245,6 +245,9 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
245
245
|
const editLabel = japanese ? 'クリックしてこのビューで編集' : 'Activate this view to edit';
|
|
246
246
|
const backdropTitle = japanese ? '背景' : 'Backdrops';
|
|
247
247
|
const tabTitle = (target: Target) => target.isStage ? backdropTitle : target.getName();
|
|
248
|
+
const chipText = japanese ?
|
|
249
|
+
{collapse: 'グループを折りたたむ', expand: 'グループを展開する', close: 'このグループのタブを閉じる', closeAll: 'この分割パネルの文書タブをすべて閉じる'} :
|
|
250
|
+
{collapse: 'Collapse group', expand: 'Expand group', close: 'Close the tabs of this group', closeAll: 'Close all document tabs of this split'};
|
|
248
251
|
const slots = new Map<string, TabSlot>();
|
|
249
252
|
const views = new Map<string, View<Snapshot>>();
|
|
250
253
|
const documents = new Map<string, {request: DocumentPanelRequest; session?: ReturnType<DocumentPanelRequest['mount']>}>();
|
|
@@ -269,13 +272,28 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
269
272
|
/** Panels that were in a separate window when the layout was saved, until the user reopens them. */
|
|
270
273
|
const reopenable = new Map<string, SavedPopout>();
|
|
271
274
|
const originalTargets = () => vm.runtime.targets.filter(target => target.isOriginal);
|
|
275
|
+
// Whether tabs stand in a column at the left of each split. It is the user's preference, kept apart from the layout.
|
|
276
|
+
const tabsKey = persistence ? persistence.key + '.tabs' : undefined;
|
|
277
|
+
let verticalTabs = false;
|
|
278
|
+
try { verticalTabs = Boolean(tabsKey) && persistence.storage.getItem(tabsKey) === 'left'; } catch { /* Storage can be unavailable. */ }
|
|
272
279
|
|
|
273
280
|
const dockview = createDockview(root, {
|
|
274
281
|
theme: themeLight,
|
|
275
282
|
disableFloatingGroups: true,
|
|
283
|
+
defaultHeaderPosition: verticalTabs ? 'left' : 'top',
|
|
276
284
|
...(multiView && {createRightHeaderActionComponent: createLayoutMenu}),
|
|
277
285
|
defaultTabComponent: 'sprite',
|
|
278
286
|
createTabComponent: () => new SpriteTab(document),
|
|
287
|
+
// A chip stands for several tabs, such as the changed scripts of one sprite, so it closes them together.
|
|
288
|
+
getTabGroupChipContextMenuItems: ({tabGroup, group}) => [
|
|
289
|
+
{label: tabGroup.collapsed ? chipText.expand : chipText.collapse, action: () => tabGroup.toggle()},
|
|
290
|
+
{label: chipText.close, action: () => {
|
|
291
|
+
for (const id of [...tabGroup.panelIds]) dockview.getPanel(id)?.api.close();
|
|
292
|
+
}},
|
|
293
|
+
{label: chipText.closeAll, action: () => {
|
|
294
|
+
for (const panel of [...group.panels]) if (documents.has(panel.id)) panel.api.close();
|
|
295
|
+
}}
|
|
296
|
+
],
|
|
279
297
|
getTabContextMenuItems: ({panel}) => {
|
|
280
298
|
const target = views.get(panel.id)?.target;
|
|
281
299
|
if (!target || target.isStage || !vm.renameSprite) return [];
|
|
@@ -392,6 +410,8 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
392
410
|
close: () => { if (group.activePanel) closeSplit(group.activePanel.id); },
|
|
393
411
|
canClose: () => canCloseGroup(group),
|
|
394
412
|
canSplit: () => views.has(group.activePanel?.id),
|
|
413
|
+
verticalTabs: () => verticalTabs,
|
|
414
|
+
setVerticalTabs,
|
|
395
415
|
...(popouts && {
|
|
396
416
|
canOpenPanel,
|
|
397
417
|
openPanel() {
|
|
@@ -426,6 +446,15 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
426
446
|
return {...menu, init() {}};
|
|
427
447
|
}
|
|
428
448
|
|
|
449
|
+
function setVerticalTabs(vertical: boolean) {
|
|
450
|
+
verticalTabs = vertical;
|
|
451
|
+
const position = vertical ? 'left' : 'top';
|
|
452
|
+
dockview.updateOptions({defaultHeaderPosition: position});
|
|
453
|
+
for (const group of dockview.groups) group.api.setHeaderPosition(position);
|
|
454
|
+
try { if (tabsKey) persistence.storage.setItem(tabsKey, position); } catch { /* Storage can be unavailable. */ }
|
|
455
|
+
refreshSurfaces();
|
|
456
|
+
}
|
|
457
|
+
|
|
429
458
|
const canRename = (target: Target) =>
|
|
430
459
|
target.isOriginal && !target.isStage && Boolean(vm.renameSprite) && vm.runtime.targets.includes(target);
|
|
431
460
|
|
|
@@ -640,7 +669,7 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
640
669
|
const {providerId, documentId} = request.reference;
|
|
641
670
|
for (const [id, {request: opened}] of documents) {
|
|
642
671
|
if (opened.reference.providerId === providerId && opened.reference.documentId === documentId) {
|
|
643
|
-
dockview.getPanel(id)?.api.setActive();
|
|
672
|
+
if (!request.inactive) dockview.getPanel(id)?.api.setActive();
|
|
644
673
|
return;
|
|
645
674
|
}
|
|
646
675
|
}
|
|
@@ -649,14 +678,39 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
649
678
|
id = 'document-view-' + ++nextView;
|
|
650
679
|
} while (views.has(id) || documents.has(id) || vm.runtime.targets.some(target => target.id === id));
|
|
651
680
|
const title = documentPanelTitle(request);
|
|
681
|
+
const position = documentPosition(request);
|
|
652
682
|
documents.set(id, {request});
|
|
653
683
|
try {
|
|
654
|
-
dockview.addPanel({id, title, component: documentComponent, renderer: 'always'
|
|
684
|
+
dockview.addPanel({id, title, component: documentComponent, renderer: 'always',
|
|
685
|
+
inactive: request.inactive, ...(position && {position})});
|
|
655
686
|
} catch (error) {
|
|
656
687
|
documents.get(id)?.session?.dispose();
|
|
657
688
|
documents.delete(id);
|
|
658
689
|
throw error;
|
|
659
690
|
}
|
|
691
|
+
if (request.tabGroup) joinTabGroup(id, request.tabGroup);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/** Where a document of an area opens: in the split that already shows its area, or in a new split beside the editor. */
|
|
695
|
+
function documentPosition({area}: DocumentPanelRequest) {
|
|
696
|
+
if (!area) return;
|
|
697
|
+
for (const [id, {request}] of documents) {
|
|
698
|
+
const panel = request.area === area && dockview.getPanel(id);
|
|
699
|
+
if (panel && panel.group.api.location.type === 'grid') return {referenceGroup: panel.group};
|
|
700
|
+
}
|
|
701
|
+
const reference = dockview.activePanel;
|
|
702
|
+
return reference && reference.group.api.location.type === 'grid' ?
|
|
703
|
+
{referencePanel: reference.id, direction: 'right' as const} : undefined;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
function joinTabGroup(id: string, {id: key, label, color, collapsed}: NonNullable<DocumentPanelRequest['tabGroup']>) {
|
|
707
|
+
const panel = dockview.getPanel(id);
|
|
708
|
+
if (!panel) return;
|
|
709
|
+
const groupId = panel.group.id;
|
|
710
|
+
const existing = dockview.getTabGroups({groupId}).find(item => item.componentParams?.key === key);
|
|
711
|
+
const tabGroup = existing ?? dockview.createTabGroup({groupId, label, color, componentParams: {key}});
|
|
712
|
+
dockview.addPanelToTabGroup({groupId, tabGroupId: tabGroup.id, panelId: id});
|
|
713
|
+
if (!existing && collapsed) tabGroup.collapse();
|
|
660
714
|
}
|
|
661
715
|
|
|
662
716
|
function guardDocumentClose(event: MouseEvent | KeyboardEvent) {
|