@kubohiroya/turbowarp-plus-editor-workbench 0.12.0 → 0.14.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/README.ja.md +5 -5
- package/README.md +9 -6
- package/dist/sprite-layout-menu.d.ts +6 -0
- package/dist/sprite-layout-menu.js +36 -9
- package/dist/sprite-tabs.d.ts +28 -3
- package/dist/sprite-tabs.js +69 -12
- package/dist/workspace-layout-store.d.ts +6 -0
- package/dist/workspace-layout-store.js +23 -8
- package/package.json +3 -3
- package/src/editor.css +5 -0
- package/src/sprite-layout-menu.css +17 -0
- package/src/sprite-layout-menu.ts +45 -9
- package/src/sprite-tabs.ts +90 -15
- package/src/workspace-layout-store.ts +31 -8
package/README.ja.md
CHANGED
|
@@ -131,13 +131,13 @@ Editor がファイルメニューの接続口を提供している場合は、
|
|
|
131
131
|
|
|
132
132
|
Web 版の Plus 標準配置で `twPlusDockview=1` を付けて起動すると、スプライト編集ペインを左右・上下に分割できます。同じスプライトを複数のペインで開いた場合、表示セクション、コスチュームと音の選択、素材一覧のスクロール位置をペインごとに保持します。変数の値はプロジェクト内で共有され、編集中のペインで変更できます。URL から `twPlusDockview=1` を外して再読み込みすると、通常のスプライトタブに戻ります。
|
|
133
133
|
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
スプライトと背景の編集タブには「自由配置」(コード領域)、「コスチューム / 背景」「音」、「変数」「メッセージ」がある。
|
|
135
|
+
「メッセージ」の表示は `@kubohiroya/turbowarp-plus-editor-sprite-panes` の `SpriteMessagePane` が担う。
|
|
136
136
|
`broadcast_msg` はステージ所有なので、メッセージ名の変更は作品全体に及ぶ。
|
|
137
137
|
送受信の判定は `@kubohiroya/turbowarp-plus-editor-project-model` の `messageReference` だけが持ち、Editor の作品内検索も同じ関数を使う。
|
|
138
138
|
このパッケージの `./project-messages` は、既存の import のためにそれを再 export している。
|
|
139
139
|
|
|
140
|
-
ホストが `getFunctions`
|
|
141
|
-
`@kubohiroya/turbowarp-plus-editor-sprite-panes`
|
|
142
|
-
|
|
140
|
+
ホストが `getFunctions` を渡すと、「自由配置」の次に「ハット・関数一覧」と「呼び出し関係」がある(ボタンの並びは
|
|
141
|
+
`@kubohiroya/turbowarp-plus-editor-sprite-panes` のツールバーが決め、保存済みのレイアウトが持つセクションの番号は変わらない。「呼び出し関係」は次の番号を使う)。`SpriteFunctionPane` が、前者ではホストが `hats` で渡すハットのスクリプトとブロック定義を
|
|
142
|
+
一覧し(並べ方は名前順・Z順・N順)、後者では LR・TD の呼び出し図を表示する。並べ方・流れはビューごとに保つ。どちらで選んだ関数もホストの `openFunction` で、ハットのスクリプトは `openScript` で開く(スプライトの横のタブなど)。`openFunction` が無ければ関数はダイアログで開く。`createFunction(targetId, kind, name)` を渡すと、一覧の下と図の左下の「+ 新しい関数を追加」で、名前を入れて標準のブロック定義か TurboWarp-Plus の名前付き関数を作れる。ダイアログはホストの
|
|
143
143
|
`mountFunctionEditor` を呼び、その定義のコード編集画面はホストが持つ。このパッケージは Scratch Blocks のコードを持たないためである。
|
package/README.md
CHANGED
|
@@ -129,15 +129,18 @@ Sprite editing tabs are enabled by default in the Plus standard layout. Set `twP
|
|
|
129
129
|
|
|
130
130
|
In the Plus web editor, add `twPlusDockview=1` to enable split sprite panes. Each pane remembers its section, costume and sound selections, and asset-list scroll position. Variable values are shared across panes and can be changed in the active pane. Remove the startup parameter and reload to return to the regular sprite tabs.
|
|
131
131
|
|
|
132
|
-
The sprite and stage editor tabs carry
|
|
133
|
-
Variables
|
|
132
|
+
The sprite and stage editor tabs carry Free layout (the code area), then Costumes or Backdrops and Sounds, then
|
|
133
|
+
Variables and Messages. Messages is drawn by `SpriteMessagePane` from `@kubohiroya/turbowarp-plus-editor-sprite-panes`. The stage owns
|
|
134
134
|
`broadcast_msg` variables, so a rename applies project-wide. `messageReference` in `@kubohiroya/turbowarp-plus-editor-project-model` is the only place that decides what
|
|
135
135
|
sends or receives a message, and the editor's project search calls the same function. This package's
|
|
136
136
|
`./project-messages` re-exports it for existing imports.
|
|
137
137
|
|
|
138
|
-
When the host passes `getFunctions`,
|
|
138
|
+
When the host passes `getFunctions`, two sections follow Free layout: Hats and functions, and Calls (the
|
|
139
139
|
toolbar of `@kubohiroya/turbowarp-plus-editor-sprite-panes` sets the button order; the section numbers stored in
|
|
140
|
-
saved layouts do not change). `SpriteFunctionPane`
|
|
141
|
-
|
|
142
|
-
|
|
140
|
+
saved layouts do not change, and Calls takes the next one). `SpriteFunctionPane` shows the list in the first, with
|
|
141
|
+
the other hat scripts the host passes in `hats` above the definitions, ordered by name, in Z order or in N order, and the call
|
|
142
|
+
graph flowing LR or TD in the second; each view keeps the order and flow it chose. A function picked in either opens through
|
|
143
|
+
`openFunction`, and a hat script through `openScript`, such as in a tab beside the sprite; without `openFunction` a function opens
|
|
144
|
+
in a dialog. With `createFunction(targetId, kind, name)`, an “Add a new function” button below the list and in the bottom left
|
|
145
|
+
corner of the graph asks for a name and makes a standard custom block or a TurboWarp-Plus named function. The dialog calls the host's `mountFunctionEditor`, which owns the code workspace of that
|
|
143
146
|
definition, because this package carries no Scratch Blocks code.
|
|
@@ -11,6 +11,12 @@ interface SpriteLayoutCommands {
|
|
|
11
11
|
/** Whether the tabs stand in a column at the left of each split panel instead of a row above it. */
|
|
12
12
|
verticalTabs?(): boolean;
|
|
13
13
|
setVerticalTabs?(vertical: boolean): void;
|
|
14
|
+
/** Whether the column of section buttons at the left of each sprite tab is hidden. */
|
|
15
|
+
sectionsHidden?(): boolean;
|
|
16
|
+
setSectionsHidden?(hidden: boolean): void;
|
|
17
|
+
/** Whether the costume thumbnail at the bottom right of each code area is hidden. */
|
|
18
|
+
thumbnailHidden?(): boolean;
|
|
19
|
+
setThumbnailHidden?(hidden: boolean): void;
|
|
14
20
|
}
|
|
15
21
|
export declare const panelLayoutIconPath = "M2.5 3.5h11v9h-11zM2.5 6.5h11m-7 0v6";
|
|
16
22
|
export declare function createSpriteLayoutMenu(document: Document, locale: string, commands: SpriteLayoutCommands): {
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export const panelLayoutIconPath = 'M2.5 3.5h11v9h-11zM2.5 6.5h11m-7 0v6';
|
|
2
|
+
const checkIconPath = 'm3.5 8.5 3 3 6-7';
|
|
2
3
|
const labels = {
|
|
3
4
|
ja: ['編集パネルのレイアウト', 'パネルを横に分割', 'パネルを縦に分割', 'この分割パネルを閉じる',
|
|
4
|
-
'パネルを別画面で開く', 'ブロックパレットを別画面で開く', 'タブを垂直に並べて表示', 'タブを水平に並べて表示'
|
|
5
|
+
'パネルを別画面で開く', 'ブロックパレットを別画面で開く', 'タブを垂直に並べて表示', 'タブを水平に並べて表示',
|
|
6
|
+
'パネル切り替えボタンを表示', 'サムネイルを表示'],
|
|
5
7
|
en: ['Editor panel layout', 'Split right', 'Split below', 'Close this split',
|
|
6
|
-
'Open panel in another window', 'Open block palette in another window', 'Show tabs vertically', 'Show tabs horizontally'
|
|
8
|
+
'Open panel in another window', 'Open block palette in another window', 'Show tabs vertically', 'Show tabs horizontally',
|
|
9
|
+
'Show panel switch buttons', 'Show thumbnail']
|
|
7
10
|
};
|
|
8
11
|
function createIcon(document, path) {
|
|
9
12
|
const ns = 'http://www.w3.org/2000/svg';
|
|
@@ -21,7 +24,7 @@ function createIcon(document, path) {
|
|
|
21
24
|
return icon;
|
|
22
25
|
}
|
|
23
26
|
export function createSpriteLayoutMenu(document, locale, commands) {
|
|
24
|
-
const [title, right, below, closeLabel, panelLabel, paletteLabel, verticalLabel, horizontalLabel] = /^ja(?:-|$)/i.test(locale) ? labels.ja : labels.en;
|
|
27
|
+
const [title, right, below, closeLabel, panelLabel, paletteLabel, verticalLabel, horizontalLabel, sectionsLabel, thumbnailLabel] = /^ja(?:-|$)/i.test(locale) ? labels.ja : labels.en;
|
|
25
28
|
const element = document.createElement('div');
|
|
26
29
|
element.className = 'tw-plus-sprite-layout-menu';
|
|
27
30
|
const trigger = document.createElement('button');
|
|
@@ -42,36 +45,60 @@ export function createSpriteLayoutMenu(document, locale, commands) {
|
|
|
42
45
|
{ label: below, run: commands.splitBelow, enabled: commands.canSplit, path: 'M2.5 3.5h11v9h-11zM2.5 8h11' },
|
|
43
46
|
{ label: closeLabel, run: commands.close, enabled: commands.canClose, path: 'm4.5 4.5 7 7m0-7-7 7' },
|
|
44
47
|
{ label: panelLabel, run: commands.openPanel, enabled: commands.canOpenPanel, path: 'M7 3H3v10h10V9m-5-1 5-5m-4 0h4v4' },
|
|
45
|
-
{ label: paletteLabel, run: commands.openPalette, enabled: commands.canOpenPalette,
|
|
48
|
+
{ label: paletteLabel, group: 'palette', run: commands.openPalette, enabled: commands.canOpenPalette,
|
|
46
49
|
path: 'M7 4H3v3h2v2H3v3h7v-2h2V9m-3-2 4-4m-3 0h3v3' },
|
|
47
50
|
...(commands.verticalTabs && commands.setVerticalTabs ? [{
|
|
48
|
-
label: verticalLabel, run: () => commands.setVerticalTabs(!commands.verticalTabs()),
|
|
51
|
+
label: verticalLabel, group: 'tabs', run: () => commands.setVerticalTabs(!commands.verticalTabs()),
|
|
49
52
|
path: 'M2.5 3.5h11v9h-11zM6 3.5v9M2.5 6h3.5m-3.5 2.5h3.5',
|
|
50
53
|
// The item names the arrangement it switches to.
|
|
51
54
|
current: () => commands.verticalTabs() ?
|
|
52
55
|
{ label: horizontalLabel, path: 'M2.5 3.5h11v9h-11zM2.5 6.5h11M6 3.5v3m3.5-3v3' } : undefined
|
|
56
|
+
}] : []),
|
|
57
|
+
// These two say what is shown, with a check mark while it is.
|
|
58
|
+
...(commands.sectionsHidden && commands.setSectionsHidden ? [{
|
|
59
|
+
label: sectionsLabel, group: 'shown', run: () => commands.setSectionsHidden(!commands.sectionsHidden()),
|
|
60
|
+
path: '', checked: () => !commands.sectionsHidden()
|
|
61
|
+
}] : []),
|
|
62
|
+
...(commands.thumbnailHidden && commands.setThumbnailHidden ? [{
|
|
63
|
+
label: thumbnailLabel, group: 'shown', run: () => commands.setThumbnailHidden(!commands.thumbnailHidden()),
|
|
64
|
+
path: '', checked: () => !commands.thumbnailHidden()
|
|
53
65
|
}] : [])
|
|
54
66
|
];
|
|
55
|
-
const entries = items.flatMap(({ label, run, enabled, path, current }) => {
|
|
67
|
+
const entries = items.flatMap(({ label, group, run, enabled, path, current, checked }) => {
|
|
56
68
|
if (!run)
|
|
57
69
|
return [];
|
|
58
70
|
const item = document.createElement('button');
|
|
59
71
|
item.type = 'button';
|
|
60
72
|
const render = () => {
|
|
73
|
+
if (checked) {
|
|
74
|
+
const on = checked();
|
|
75
|
+
item.setAttribute('aria-checked', String(on));
|
|
76
|
+
item.replaceChildren(createIcon(document, on ? checkIconPath : ''), label);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
61
79
|
const shown = current?.() ?? { label, path };
|
|
62
80
|
item.replaceChildren(createIcon(document, shown.path), shown.label);
|
|
63
81
|
};
|
|
64
82
|
render();
|
|
65
83
|
item.tabIndex = -1;
|
|
66
|
-
item.setAttribute('role', 'menuitem');
|
|
84
|
+
item.setAttribute('role', checked ? 'menuitemcheckbox' : 'menuitem');
|
|
67
85
|
item.addEventListener('click', () => {
|
|
68
86
|
close(true);
|
|
69
87
|
run();
|
|
70
88
|
});
|
|
71
|
-
return [{ item, enabled, render: current && render }];
|
|
89
|
+
return [{ item, group, enabled, render: (current || checked) && render }];
|
|
72
90
|
});
|
|
73
91
|
const buttons = entries.map(({ item }) => item);
|
|
74
|
-
|
|
92
|
+
// A divider stands between groups of items, so it never leads the menu or doubles up when a group is missing.
|
|
93
|
+
entries.forEach(({ item, group }, index) => {
|
|
94
|
+
if (index > 0 && group !== entries[index - 1].group) {
|
|
95
|
+
const divider = document.createElement('div');
|
|
96
|
+
divider.className = 'tw-plus-sprite-layout-menu-divider';
|
|
97
|
+
divider.setAttribute('role', 'separator');
|
|
98
|
+
popup.append(divider);
|
|
99
|
+
}
|
|
100
|
+
popup.append(item);
|
|
101
|
+
});
|
|
75
102
|
let openedIn;
|
|
76
103
|
let topLayer = false;
|
|
77
104
|
function close(restoreFocus = false) {
|
package/dist/sprite-tabs.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { DockviewStagePane } from './dockview-stage.ts';
|
|
|
7
7
|
import type { WorkspaceLayoutStore, WorkspaceProjectIdentity } from './workspace-layout-store.ts';
|
|
8
8
|
import type { SpriteVariableEdit, SpriteVariableEditError } from '@kubohiroya/turbowarp-plus-editor-project-model/sprite-variable-edit';
|
|
9
9
|
import type { MessageRenameError } from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-message-pane';
|
|
10
|
-
import type { FunctionPaneData, MountFunctionEditor } from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-function-pane';
|
|
10
|
+
import type { FunctionKind, FunctionPaneData, MountFunctionEditor, OpenScriptOptions, SpriteFunction, SpriteHatScript } from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-function-pane';
|
|
11
11
|
import type { MessageUse, ProjectMessage, TargetMessages } from '@kubohiroya/turbowarp-plus-editor-project-model/project-messages';
|
|
12
12
|
export { getDocumentWorkspace } from './document-workspace.ts';
|
|
13
13
|
export { createWorkspaceLayoutStore, workspaceLayoutDatabase, workspaceLayoutLimit } from './workspace-layout-store.ts';
|
|
@@ -117,7 +117,7 @@ interface ToolbarSlot {
|
|
|
117
117
|
interface AssetPreviewSlot {
|
|
118
118
|
id: string;
|
|
119
119
|
targetId: string;
|
|
120
|
-
kind: AssetKind | 'variables' | 'messages' | 'functions';
|
|
120
|
+
kind: AssetKind | 'variables' | 'messages' | 'functions' | 'calls';
|
|
121
121
|
editable: boolean;
|
|
122
122
|
selected?: object;
|
|
123
123
|
renderLayout?: SpriteAssetLayout;
|
|
@@ -189,10 +189,35 @@ type SpriteTabsProps<Snapshot> = Omit<TabOptions<Snapshot>, 'activateSection' |
|
|
|
189
189
|
openMessageTarget?(targetId: string): void;
|
|
190
190
|
/** Rename a message everywhere in the project. The stage owns broadcast_msg variables. */
|
|
191
191
|
renameMessage?(message: ProjectMessage, name: string): MessageRenameError | void;
|
|
192
|
-
/**
|
|
192
|
+
/**
|
|
193
|
+
* The custom block definitions of this target, with its other hat scripts in `hats` for the list.
|
|
194
|
+
* `readTargetFunctions` reads the definitions from the runtime.
|
|
195
|
+
*/
|
|
193
196
|
getFunctions?(targetId: string): FunctionPaneData;
|
|
194
197
|
/** Mount an editor of one definition script in an open item of the functions pane. */
|
|
195
198
|
mountFunctionEditor?: MountFunctionEditor;
|
|
199
|
+
/**
|
|
200
|
+
* Open one function picked in the list or the call graph of the functions section, such as in a tab
|
|
201
|
+
* split beside the sprite. Without it the function opens in a dialog.
|
|
202
|
+
*/
|
|
203
|
+
openFunction?(targetId: string, fn: SpriteFunction, options?: OpenScriptOptions): void;
|
|
204
|
+
/**
|
|
205
|
+
* Open a hat script picked in the list of hats and functions, as `openFunction` opens a function.
|
|
206
|
+
* `options.block` asks to show one block, such as a call picked in the list of a function's uses.
|
|
207
|
+
*/
|
|
208
|
+
openScript?(targetId: string, hat: SpriteHatScript, options?: OpenScriptOptions): void;
|
|
209
|
+
/** The function or hat script shown beside the sprite, which the list of hats and functions highlights. */
|
|
210
|
+
selectedScript?: {
|
|
211
|
+
targetId: string;
|
|
212
|
+
id: string;
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Make a new function of this name in the target: a standard custom block, whose block text is the name,
|
|
216
|
+
* or a TurboWarp-Plus named function. Resolves with the id of the new hat, or with nothing when nothing
|
|
217
|
+
* was made; a rejection may carry a `code` the pane explains. Without it, the functions sections have
|
|
218
|
+
* no add button.
|
|
219
|
+
*/
|
|
220
|
+
createFunction?(targetId: string, kind: FunctionKind, name: string): Promise<string | void>;
|
|
196
221
|
getCodeSearchItems?(targetId: string): readonly SpriteSearchResult[];
|
|
197
222
|
openCodeSearchResult?(targetId: string, id: string): void;
|
|
198
223
|
};
|
package/dist/sprite-tabs.js
CHANGED
|
@@ -19,6 +19,7 @@ export { SpriteTargetTabsContext, useTargetTabMenu } from "./target-tab-menu.js"
|
|
|
19
19
|
const variableSection = spriteEditorSections.indexOf('variables');
|
|
20
20
|
const messageSection = spriteEditorSections.indexOf('messages');
|
|
21
21
|
const functionSection = spriteEditorSections.indexOf('functions');
|
|
22
|
+
const callSection = spriteEditorSections.indexOf('calls');
|
|
22
23
|
// The first three sections are the GUI's own panels; the rest are rendered by this package.
|
|
23
24
|
const lastNativeSection = 2;
|
|
24
25
|
function createAssetSelections(target, locale, source) {
|
|
@@ -118,7 +119,7 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
118
119
|
const stagePane = multiView ? options.stagePane : undefined;
|
|
119
120
|
const ownSection = (section) => (section === variableSection && Boolean(options.variables)) ||
|
|
120
121
|
(section === messageSection && Boolean(options.messages)) ||
|
|
121
|
-
(section === functionSection && Boolean(options.functions));
|
|
122
|
+
((section === functionSection || section === callSection) && Boolean(options.functions));
|
|
122
123
|
const usesNativeSection = (section) => !ownSection(section);
|
|
123
124
|
const sectionAvailable = (section) => section <= lastNativeSection || ownSection(section);
|
|
124
125
|
const document = root.ownerDocument;
|
|
@@ -175,6 +176,12 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
175
176
|
// Whether tabs stand in a column at the left of each split. It is the user's preference for every project.
|
|
176
177
|
let verticalTabs = false;
|
|
177
178
|
let tabsChosen = false;
|
|
179
|
+
// Whether the section buttons at the left of each sprite tab are hidden. It is also one preference for every project.
|
|
180
|
+
let sectionsHidden = false;
|
|
181
|
+
let sectionsChosen = false;
|
|
182
|
+
// Whether the costume thumbnail at the bottom right of each code area is hidden, for every project.
|
|
183
|
+
let thumbnailHidden = false;
|
|
184
|
+
let thumbnailChosen = false;
|
|
178
185
|
const dockview = createDockview(root, {
|
|
179
186
|
theme: themeLight,
|
|
180
187
|
disableFloatingGroups: true,
|
|
@@ -246,9 +253,11 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
246
253
|
if (multiView) {
|
|
247
254
|
element.classList.add('tw-plus-sprite-tab-slot--split');
|
|
248
255
|
body.className = 'tw-plus-sprite-tab-body';
|
|
256
|
+
body.toggleAttribute('data-thumbnail-hidden', thumbnailHidden);
|
|
249
257
|
if (toolbar) {
|
|
250
258
|
body.setAttribute('role', 'tabpanel');
|
|
251
259
|
toolbar.className = 'tw-plus-sprite-tab-toolbar';
|
|
260
|
+
toolbar.toggleAttribute('data-sections-hidden', sectionsHidden);
|
|
252
261
|
element.append(toolbar);
|
|
253
262
|
}
|
|
254
263
|
if (assetPreview) {
|
|
@@ -349,6 +358,9 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
349
358
|
canSplit: () => views.has(group.activePanel?.id),
|
|
350
359
|
verticalTabs: () => verticalTabs,
|
|
351
360
|
setVerticalTabs,
|
|
361
|
+
...(options.onToolbarSlots && { sectionsHidden: () => sectionsHidden, setSectionsHidden }),
|
|
362
|
+
thumbnailHidden: () => thumbnailHidden,
|
|
363
|
+
setThumbnailHidden,
|
|
352
364
|
...(popouts && {
|
|
353
365
|
canOpenPanel,
|
|
354
366
|
openPanel() {
|
|
@@ -397,6 +409,27 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
397
409
|
}
|
|
398
410
|
refreshSurfaces();
|
|
399
411
|
}
|
|
412
|
+
function setSectionsHidden(hidden, chosen = true) {
|
|
413
|
+
sectionsHidden = hidden;
|
|
414
|
+
for (const { toolbar } of slots.values())
|
|
415
|
+
toolbar?.toggleAttribute('data-sections-hidden', hidden);
|
|
416
|
+
if (chosen) {
|
|
417
|
+
sectionsChosen = true;
|
|
418
|
+
layoutStore?.writeSectionsHidden?.(hidden).catch(() => undefined);
|
|
419
|
+
}
|
|
420
|
+
// The code area is wider or narrower now, though the panel itself kept its size.
|
|
421
|
+
if (active)
|
|
422
|
+
options.resize();
|
|
423
|
+
}
|
|
424
|
+
function setThumbnailHidden(hidden, chosen = true) {
|
|
425
|
+
thumbnailHidden = hidden;
|
|
426
|
+
for (const { body } of slots.values())
|
|
427
|
+
body.toggleAttribute('data-thumbnail-hidden', hidden);
|
|
428
|
+
if (chosen) {
|
|
429
|
+
thumbnailChosen = true;
|
|
430
|
+
layoutStore?.writeThumbnailHidden?.(hidden).catch(() => undefined);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
400
433
|
const canRename = (target) => target.isOriginal && !target.isStage && Boolean(vm.renameSprite) && vm.runtime.targets.includes(target);
|
|
401
434
|
function openRenameDialog(target) {
|
|
402
435
|
if (renameDialog || !canRename(target))
|
|
@@ -482,7 +515,8 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
482
515
|
if (ownSection(view.section) && slot.assetPreview) {
|
|
483
516
|
slot.assetPreview.hidden = false;
|
|
484
517
|
assetPreviews.push({ id, targetId: descriptor.targetId,
|
|
485
|
-
kind: view.section === messageSection ? 'messages' : view.section === functionSection ? 'functions' :
|
|
518
|
+
kind: view.section === messageSection ? 'messages' : view.section === functionSection ? 'functions' :
|
|
519
|
+
view.section === callSection ? 'calls' : 'variables',
|
|
486
520
|
editable: active === view,
|
|
487
521
|
element: slot.assetPreview });
|
|
488
522
|
continue;
|
|
@@ -1254,6 +1288,14 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
1254
1288
|
readingTabs = false;
|
|
1255
1289
|
updateLayoutState();
|
|
1256
1290
|
});
|
|
1291
|
+
layoutStore?.readSectionsHidden?.().then(hidden => {
|
|
1292
|
+
if (!disposed && !sectionsChosen && hidden)
|
|
1293
|
+
setSectionsHidden(true, false);
|
|
1294
|
+
}, () => undefined);
|
|
1295
|
+
layoutStore?.readThumbnailHidden?.().then(hidden => {
|
|
1296
|
+
if (!disposed && !thumbnailChosen && hidden)
|
|
1297
|
+
setThumbnailHidden(true, false);
|
|
1298
|
+
}, () => undefined);
|
|
1257
1299
|
if (persistence)
|
|
1258
1300
|
window.addEventListener('pagehide', flushLayout);
|
|
1259
1301
|
updateLayoutState();
|
|
@@ -1462,7 +1504,7 @@ function SpriteTabs(props) {
|
|
|
1462
1504
|
activeGroup: view.groupActive, propertiesInVariables: Boolean(props.getProperties),
|
|
1463
1505
|
// A section with no port behind it would open an empty panel.
|
|
1464
1506
|
availableSections: spriteEditorSections.filter(section => (section !== 'messages' || Boolean(props.getMessages)) &&
|
|
1465
|
-
(section !== 'functions' || Boolean(props.getFunctions))),
|
|
1507
|
+
(section !== 'functions' && section !== 'calls' || Boolean(props.getFunctions))),
|
|
1466
1508
|
actions: view.active && currentSection !== 'variables' ? props.activeTools : undefined,
|
|
1467
1509
|
onSectionChange: section => actions.setSection(spriteEditorSections.indexOf(section)),
|
|
1468
1510
|
search: {
|
|
@@ -1478,9 +1520,10 @@ function SpriteTabs(props) {
|
|
|
1478
1520
|
items = (props.getMessages?.(view.targetId).messages ?? [])
|
|
1479
1521
|
.map(message => ({ id: message.key, label: message.name }));
|
|
1480
1522
|
}
|
|
1481
|
-
else if (section === 'functions') {
|
|
1482
|
-
|
|
1483
|
-
|
|
1523
|
+
else if (section === 'functions' || section === 'calls') {
|
|
1524
|
+
const data = props.getFunctions?.(view.targetId);
|
|
1525
|
+
items = [...(section === 'functions' ? data?.hats ?? [] : []).map(hat => ({ id: hat.id, label: hat.label })),
|
|
1526
|
+
...(data?.functions ?? []).map(fn => ({ id: fn.id, label: functionLabel(fn) }))];
|
|
1484
1527
|
}
|
|
1485
1528
|
else {
|
|
1486
1529
|
items = props.getAssetPreview?.(view.targetId, section).items.map((item, index) => ({ id: String(index), label: item.name })) ?? [];
|
|
@@ -1502,10 +1545,10 @@ function SpriteTabs(props) {
|
|
|
1502
1545
|
[...(pane?.querySelectorAll('[data-message-key]') ?? [])]
|
|
1503
1546
|
.find(node => node.dataset.messageKey === result.id)?.focus();
|
|
1504
1547
|
}
|
|
1505
|
-
else if (section === 'functions') {
|
|
1548
|
+
else if (section === 'functions' || section === 'calls') {
|
|
1506
1549
|
const pane = assetPreviewSlots.find(slot => slot.id === view.id)?.element;
|
|
1507
|
-
[...(pane?.querySelectorAll('[data-function-key]') ?? [])]
|
|
1508
|
-
.find(node => node.dataset.functionKey === result.id)?.focus();
|
|
1550
|
+
[...(pane?.querySelectorAll('[data-function-key], [data-hat-key]') ?? [])]
|
|
1551
|
+
.find(node => (node.dataset.functionKey ?? node.dataset.hatKey) === result.id)?.focus();
|
|
1509
1552
|
}
|
|
1510
1553
|
else
|
|
1511
1554
|
workspace?.selectAsset(view.id, section, Number(result.id));
|
|
@@ -1523,11 +1566,25 @@ function SpriteTabs(props) {
|
|
|
1523
1566
|
workspace?.refreshSurfaces();
|
|
1524
1567
|
return result;
|
|
1525
1568
|
})
|
|
1526
|
-
}) : kind === 'functions' ? React.createElement(SpriteFunctionPane, {
|
|
1527
|
-
|
|
1569
|
+
}) : kind === 'functions' || kind === 'calls' ? React.createElement(SpriteFunctionPane, {
|
|
1570
|
+
// The list and the call graph are sections of their own.
|
|
1571
|
+
kind: 'functions', view: kind === 'calls' ? 'graph' : 'list',
|
|
1572
|
+
locale: props.locale, editable, data: props.getFunctions(targetId),
|
|
1528
1573
|
defaultSettings: functionSettings.get(id),
|
|
1529
1574
|
onSettingsChange: (settings) => functionSettings.set(id, settings),
|
|
1530
|
-
mountEditor: props.mountFunctionEditor
|
|
1575
|
+
mountEditor: props.mountFunctionEditor,
|
|
1576
|
+
onOpenFunction: props.openFunction &&
|
|
1577
|
+
((fn, options) => props.openFunction(targetId, fn, options)),
|
|
1578
|
+
onOpenScript: props.openScript &&
|
|
1579
|
+
((hat, options) => props.openScript(targetId, hat, options)),
|
|
1580
|
+
selectedId: props.selectedScript?.targetId === targetId ? props.selectedScript.id : undefined,
|
|
1581
|
+
onCreate: props.createFunction && (async (functionKind, name) => {
|
|
1582
|
+
const created = await props.createFunction(targetId, functionKind, name);
|
|
1583
|
+
// Show the new function now rather than at the next project change.
|
|
1584
|
+
if (created)
|
|
1585
|
+
workspace?.refreshSurfaces();
|
|
1586
|
+
return created;
|
|
1587
|
+
})
|
|
1531
1588
|
}) : kind === 'variables' ? renderVariablePane(id, targetId, editable) :
|
|
1532
1589
|
props.getAssetPreview && React.createElement(AssetPreview, {
|
|
1533
1590
|
locale: props.locale, kind, selected, renderLayout, scrollTop, data: props.getAssetPreview(targetId, kind)
|
|
@@ -33,6 +33,12 @@ export interface WorkspaceLayoutStore {
|
|
|
33
33
|
open(identity: WorkspaceProjectIdentity, signature: string): Promise<WorkspaceLayoutSession>;
|
|
34
34
|
readTabsPosition(): Promise<TabsPosition | undefined>;
|
|
35
35
|
writeTabsPosition(position: TabsPosition): Promise<void>;
|
|
36
|
+
/** Whether the section buttons of the sprite tabs are hidden, one preference for every project. */
|
|
37
|
+
readSectionsHidden?(): Promise<boolean | undefined>;
|
|
38
|
+
writeSectionsHidden?(hidden: boolean): Promise<void>;
|
|
39
|
+
/** Whether the costume thumbnail of the code areas is hidden, one preference for every project. */
|
|
40
|
+
readThumbnailHidden?(): Promise<boolean | undefined>;
|
|
41
|
+
writeThumbnailHidden?(hidden: boolean): Promise<void>;
|
|
36
42
|
}
|
|
37
43
|
export interface WorkspaceLayoutStoreOptions {
|
|
38
44
|
indexedDB?: IDBFactory;
|
|
@@ -12,6 +12,8 @@ export const workspaceLayoutMaxBytes = 256 * 1024;
|
|
|
12
12
|
const layoutsStore = 'layouts';
|
|
13
13
|
const preferencesStore = 'preferences';
|
|
14
14
|
const tabsPositionKey = 'tabsPosition';
|
|
15
|
+
const sectionsHiddenKey = 'sectionsHidden';
|
|
16
|
+
const thumbnailHiddenKey = 'thumbnailHidden';
|
|
15
17
|
const legacyKeys = ['twPlusDockviewLayout', 'twPlusDockviewLayout.tabs'];
|
|
16
18
|
const result = (request) => new Promise((resolve, reject) => {
|
|
17
19
|
request.onsuccess = () => resolve(request.result);
|
|
@@ -165,13 +167,26 @@ export function createWorkspaceLayoutStore({ indexedDB: factory = globalThis.ind
|
|
|
165
167
|
return value === 'left' || value === 'top' ? value : undefined;
|
|
166
168
|
},
|
|
167
169
|
writeTabsPosition(position) {
|
|
168
|
-
return
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
});
|
|
175
|
-
}
|
|
170
|
+
return writePreference(tabsPositionKey, position);
|
|
171
|
+
},
|
|
172
|
+
readSectionsHidden: () => readFlag(sectionsHiddenKey),
|
|
173
|
+
writeSectionsHidden: hidden => writePreference(sectionsHiddenKey, hidden),
|
|
174
|
+
readThumbnailHidden: () => readFlag(thumbnailHiddenKey),
|
|
175
|
+
writeThumbnailHidden: hidden => writePreference(thumbnailHiddenKey, hidden)
|
|
176
176
|
};
|
|
177
|
+
async function readFlag(key) {
|
|
178
|
+
const opened = await connect();
|
|
179
|
+
const transaction = opened.transaction(preferencesStore, 'readonly');
|
|
180
|
+
const value = await result(transaction.objectStore(preferencesStore).get(key));
|
|
181
|
+
return typeof value === 'boolean' ? value : undefined;
|
|
182
|
+
}
|
|
183
|
+
function writePreference(key, value) {
|
|
184
|
+
return enqueue(async () => {
|
|
185
|
+
const opened = await connect();
|
|
186
|
+
const transaction = opened.transaction(preferencesStore, 'readwrite');
|
|
187
|
+
const finished = completion(transaction);
|
|
188
|
+
transaction.objectStore(preferencesStore).put(value, key);
|
|
189
|
+
await finished;
|
|
190
|
+
});
|
|
191
|
+
}
|
|
177
192
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-plus-editor-workbench",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "The TurboWarp Plus Editor workbench: layout, dockable sprite tabs, stage, debugger tab and file menu",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
"url": "git+https://github.com/kubohiroya/turbowarp-plus-editor-workbench.git"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@kubohiroya/turbowarp-plus-editor-project-model": "0.1.
|
|
76
|
-
"@kubohiroya/turbowarp-plus-editor-sprite-panes": "0.
|
|
75
|
+
"@kubohiroya/turbowarp-plus-editor-project-model": "0.1.2",
|
|
76
|
+
"@kubohiroya/turbowarp-plus-editor-sprite-panes": "0.5.0",
|
|
77
77
|
"dockview": "8.8.3"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
package/src/editor.css
CHANGED
|
@@ -424,6 +424,11 @@
|
|
|
424
424
|
padding-left: 16pt;
|
|
425
425
|
}
|
|
426
426
|
|
|
427
|
+
/* In a section heading of the sprite editor the row holds only its tools, with no stage to keep clear of. */
|
|
428
|
+
.standard-body :global(.tw-plus-sprite-toolbar-tools) .tab-row {
|
|
429
|
+
padding-right: 0;
|
|
430
|
+
}
|
|
431
|
+
|
|
427
432
|
.standard-body .stage-hidden {
|
|
428
433
|
visibility: hidden;
|
|
429
434
|
pointer-events: none;
|
|
@@ -52,6 +52,12 @@
|
|
|
52
52
|
|
|
53
53
|
.tw-plus-sprite-layout-menu-popup svg { width: 16px; height: 16px; flex: none; }
|
|
54
54
|
|
|
55
|
+
.tw-plus-sprite-layout-menu-divider {
|
|
56
|
+
height: 1px;
|
|
57
|
+
margin: 4px 0;
|
|
58
|
+
background: var(--ui-black-transparent, #c6cfda);
|
|
59
|
+
}
|
|
60
|
+
|
|
55
61
|
.tw-plus-sprite-layout-menu-popup button:disabled { opacity: 0.55; cursor: default; }
|
|
56
62
|
.tw-plus-sprite-layout-menu-popup button:enabled:is(:hover, :focus-visible) {
|
|
57
63
|
background: var(--looks-light-transparent, #e6dff3);
|
|
@@ -127,3 +133,14 @@
|
|
|
127
133
|
opacity: 1;
|
|
128
134
|
pointer-events: auto;
|
|
129
135
|
}
|
|
136
|
+
|
|
137
|
+
/* The layout menu can hide the section buttons at the left of every sprite tab. */
|
|
138
|
+
.tw-plus-sprite-tab-toolbar[data-sections-hidden] .tw-plus-sprite-toolbar-sections {
|
|
139
|
+
display: none;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/* It can also hide the costume thumbnail at the bottom right of each code area: the GUI's own
|
|
143
|
+
watermark in the active tab and the copy the editor shows in the other tabs. */
|
|
144
|
+
.tw-plus-sprite-tab-body[data-thumbnail-hidden] :is([data-dockview-costume-thumbnail], [class*="gui_watermark_"]) {
|
|
145
|
+
display: none;
|
|
146
|
+
}
|
|
@@ -11,15 +11,24 @@ interface SpriteLayoutCommands {
|
|
|
11
11
|
/** Whether the tabs stand in a column at the left of each split panel instead of a row above it. */
|
|
12
12
|
verticalTabs?(): boolean;
|
|
13
13
|
setVerticalTabs?(vertical: boolean): void;
|
|
14
|
+
/** Whether the column of section buttons at the left of each sprite tab is hidden. */
|
|
15
|
+
sectionsHidden?(): boolean;
|
|
16
|
+
setSectionsHidden?(hidden: boolean): void;
|
|
17
|
+
/** Whether the costume thumbnail at the bottom right of each code area is hidden. */
|
|
18
|
+
thumbnailHidden?(): boolean;
|
|
19
|
+
setThumbnailHidden?(hidden: boolean): void;
|
|
14
20
|
}
|
|
15
21
|
|
|
16
22
|
export const panelLayoutIconPath = 'M2.5 3.5h11v9h-11zM2.5 6.5h11m-7 0v6';
|
|
23
|
+
const checkIconPath = 'm3.5 8.5 3 3 6-7';
|
|
17
24
|
|
|
18
25
|
const labels = {
|
|
19
26
|
ja: ['編集パネルのレイアウト', 'パネルを横に分割', 'パネルを縦に分割', 'この分割パネルを閉じる',
|
|
20
|
-
'パネルを別画面で開く', 'ブロックパレットを別画面で開く', 'タブを垂直に並べて表示', 'タブを水平に並べて表示'
|
|
27
|
+
'パネルを別画面で開く', 'ブロックパレットを別画面で開く', 'タブを垂直に並べて表示', 'タブを水平に並べて表示',
|
|
28
|
+
'パネル切り替えボタンを表示', 'サムネイルを表示'],
|
|
21
29
|
en: ['Editor panel layout', 'Split right', 'Split below', 'Close this split',
|
|
22
|
-
'Open panel in another window', 'Open block palette in another window', 'Show tabs vertically', 'Show tabs horizontally'
|
|
30
|
+
'Open panel in another window', 'Open block palette in another window', 'Show tabs vertically', 'Show tabs horizontally',
|
|
31
|
+
'Show panel switch buttons', 'Show thumbnail']
|
|
23
32
|
};
|
|
24
33
|
|
|
25
34
|
function createIcon(document: Document, path: string) {
|
|
@@ -39,7 +48,8 @@ function createIcon(document: Document, path: string) {
|
|
|
39
48
|
}
|
|
40
49
|
|
|
41
50
|
export function createSpriteLayoutMenu(document: Document, locale: string, commands: SpriteLayoutCommands) {
|
|
42
|
-
const [title, right, below, closeLabel, panelLabel, paletteLabel, verticalLabel, horizontalLabel
|
|
51
|
+
const [title, right, below, closeLabel, panelLabel, paletteLabel, verticalLabel, horizontalLabel,
|
|
52
|
+
sectionsLabel, thumbnailLabel] = /^ja(?:-|$)/i.test(locale) ? labels.ja : labels.en;
|
|
43
53
|
const element = document.createElement('div');
|
|
44
54
|
element.className = 'tw-plus-sprite-layout-menu';
|
|
45
55
|
const trigger = document.createElement('button');
|
|
@@ -61,37 +71,63 @@ export function createSpriteLayoutMenu(document: Document, locale: string, comma
|
|
|
61
71
|
{label: below, run: commands.splitBelow, enabled: commands.canSplit, path: 'M2.5 3.5h11v9h-11zM2.5 8h11'},
|
|
62
72
|
{label: closeLabel, run: commands.close, enabled: commands.canClose, path: 'm4.5 4.5 7 7m0-7-7 7'},
|
|
63
73
|
{label: panelLabel, run: commands.openPanel, enabled: commands.canOpenPanel, path: 'M7 3H3v10h10V9m-5-1 5-5m-4 0h4v4'},
|
|
64
|
-
{label: paletteLabel, run: commands.openPalette, enabled: commands.canOpenPalette,
|
|
74
|
+
{label: paletteLabel, group: 'palette', run: commands.openPalette, enabled: commands.canOpenPalette,
|
|
65
75
|
path: 'M7 4H3v3h2v2H3v3h7v-2h2V9m-3-2 4-4m-3 0h3v3'},
|
|
66
76
|
...(commands.verticalTabs && commands.setVerticalTabs ? [{
|
|
67
|
-
label: verticalLabel, run: () => commands.setVerticalTabs!(!commands.verticalTabs!()),
|
|
77
|
+
label: verticalLabel, group: 'tabs', run: () => commands.setVerticalTabs!(!commands.verticalTabs!()),
|
|
68
78
|
path: 'M2.5 3.5h11v9h-11zM6 3.5v9M2.5 6h3.5m-3.5 2.5h3.5',
|
|
69
79
|
// The item names the arrangement it switches to.
|
|
70
80
|
current: () => commands.verticalTabs!() ?
|
|
71
81
|
{label: horizontalLabel, path: 'M2.5 3.5h11v9h-11zM2.5 6.5h11M6 3.5v3m3.5-3v3'} : undefined
|
|
82
|
+
}] : []),
|
|
83
|
+
// These two say what is shown, with a check mark while it is.
|
|
84
|
+
...(commands.sectionsHidden && commands.setSectionsHidden ? [{
|
|
85
|
+
label: sectionsLabel, group: 'shown', run: () => commands.setSectionsHidden!(!commands.sectionsHidden!()),
|
|
86
|
+
path: '', checked: () => !commands.sectionsHidden!()
|
|
87
|
+
}] : []),
|
|
88
|
+
...(commands.thumbnailHidden && commands.setThumbnailHidden ? [{
|
|
89
|
+
label: thumbnailLabel, group: 'shown', run: () => commands.setThumbnailHidden!(!commands.thumbnailHidden!()),
|
|
90
|
+
path: '', checked: () => !commands.thumbnailHidden!()
|
|
72
91
|
}] : [])
|
|
73
92
|
];
|
|
74
|
-
const entries = items.flatMap(({label, run, enabled, path, current}: typeof items[number] & {
|
|
93
|
+
const entries = items.flatMap(({label, group, run, enabled, path, current, checked}: typeof items[number] & {
|
|
94
|
+
group?: string;
|
|
75
95
|
current?(): {label: string; path: string} | undefined;
|
|
96
|
+
checked?(): boolean;
|
|
76
97
|
}) => {
|
|
77
98
|
if (!run) return [];
|
|
78
99
|
const item = document.createElement('button');
|
|
79
100
|
item.type = 'button';
|
|
80
101
|
const render = () => {
|
|
102
|
+
if (checked) {
|
|
103
|
+
const on = checked();
|
|
104
|
+
item.setAttribute('aria-checked', String(on));
|
|
105
|
+
item.replaceChildren(createIcon(document, on ? checkIconPath : ''), label);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
81
108
|
const shown = current?.() ?? {label, path};
|
|
82
109
|
item.replaceChildren(createIcon(document, shown.path), shown.label);
|
|
83
110
|
};
|
|
84
111
|
render();
|
|
85
112
|
item.tabIndex = -1;
|
|
86
|
-
item.setAttribute('role', 'menuitem');
|
|
113
|
+
item.setAttribute('role', checked ? 'menuitemcheckbox' : 'menuitem');
|
|
87
114
|
item.addEventListener('click', () => {
|
|
88
115
|
close(true);
|
|
89
116
|
run();
|
|
90
117
|
});
|
|
91
|
-
return [{item, enabled, render: current && render}];
|
|
118
|
+
return [{item, group, enabled, render: (current || checked) && render}];
|
|
92
119
|
});
|
|
93
120
|
const buttons = entries.map(({item}) => item);
|
|
94
|
-
|
|
121
|
+
// A divider stands between groups of items, so it never leads the menu or doubles up when a group is missing.
|
|
122
|
+
entries.forEach(({item, group}, index) => {
|
|
123
|
+
if (index > 0 && group !== entries[index - 1].group) {
|
|
124
|
+
const divider = document.createElement('div');
|
|
125
|
+
divider.className = 'tw-plus-sprite-layout-menu-divider';
|
|
126
|
+
divider.setAttribute('role', 'separator');
|
|
127
|
+
popup.append(divider);
|
|
128
|
+
}
|
|
129
|
+
popup.append(item);
|
|
130
|
+
});
|
|
95
131
|
let openedIn: Document | undefined;
|
|
96
132
|
let topLayer = false;
|
|
97
133
|
|
package/src/sprite-tabs.ts
CHANGED
|
@@ -22,7 +22,7 @@ import type {SpriteVariableEdit, SpriteVariableEditError} from '@kubohiroya/turb
|
|
|
22
22
|
import {SpriteMessagePane} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-message-pane';
|
|
23
23
|
import type {MessageRenameError} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-message-pane';
|
|
24
24
|
import {functionLabel, SpriteFunctionPane} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-function-pane';
|
|
25
|
-
import type {FunctionPaneData, FunctionPaneSettings, MountFunctionEditor} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-function-pane';
|
|
25
|
+
import type {FunctionKind, FunctionPaneData, FunctionPaneSettings, MountFunctionEditor, OpenScriptOptions, SpriteFunction, SpriteHatScript} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-function-pane';
|
|
26
26
|
import type {MessageUse, ProjectMessage, TargetMessages} from '@kubohiroya/turbowarp-plus-editor-project-model/project-messages';
|
|
27
27
|
import {createTargetTabMenuItem, spriteRenameLabel} from './target-tab-menu.ts';
|
|
28
28
|
|
|
@@ -91,6 +91,7 @@ type AssetKind = SpriteAssetKind;
|
|
|
91
91
|
const variableSection = spriteEditorSections.indexOf('variables');
|
|
92
92
|
const messageSection = spriteEditorSections.indexOf('messages');
|
|
93
93
|
const functionSection = spriteEditorSections.indexOf('functions');
|
|
94
|
+
const callSection = spriteEditorSections.indexOf('calls');
|
|
94
95
|
// The first three sections are the GUI's own panels; the rest are rendered by this package.
|
|
95
96
|
const lastNativeSection = 2;
|
|
96
97
|
|
|
@@ -188,7 +189,7 @@ interface ToolbarSlot {
|
|
|
188
189
|
interface AssetPreviewSlot {
|
|
189
190
|
id: string;
|
|
190
191
|
targetId: string;
|
|
191
|
-
kind: AssetKind | 'variables' | 'messages' | 'functions';
|
|
192
|
+
kind: AssetKind | 'variables' | 'messages' | 'functions' | 'calls';
|
|
192
193
|
editable: boolean;
|
|
193
194
|
selected?: object;
|
|
194
195
|
renderLayout?: SpriteAssetLayout;
|
|
@@ -271,7 +272,7 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
271
272
|
const stagePane = multiView ? options.stagePane : undefined;
|
|
272
273
|
const ownSection = (section: number) => (section === variableSection && Boolean(options.variables)) ||
|
|
273
274
|
(section === messageSection && Boolean(options.messages)) ||
|
|
274
|
-
(section === functionSection && Boolean(options.functions));
|
|
275
|
+
((section === functionSection || section === callSection) && Boolean(options.functions));
|
|
275
276
|
const usesNativeSection = (section: number) => !ownSection(section);
|
|
276
277
|
const sectionAvailable = (section: number) => section <= lastNativeSection || ownSection(section);
|
|
277
278
|
const document = root.ownerDocument;
|
|
@@ -328,6 +329,12 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
328
329
|
// Whether tabs stand in a column at the left of each split. It is the user's preference for every project.
|
|
329
330
|
let verticalTabs = false;
|
|
330
331
|
let tabsChosen = false;
|
|
332
|
+
// Whether the section buttons at the left of each sprite tab are hidden. It is also one preference for every project.
|
|
333
|
+
let sectionsHidden = false;
|
|
334
|
+
let sectionsChosen = false;
|
|
335
|
+
// Whether the costume thumbnail at the bottom right of each code area is hidden, for every project.
|
|
336
|
+
let thumbnailHidden = false;
|
|
337
|
+
let thumbnailChosen = false;
|
|
331
338
|
|
|
332
339
|
const dockview = createDockview(root, {
|
|
333
340
|
theme: themeLight,
|
|
@@ -393,9 +400,11 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
393
400
|
if (multiView) {
|
|
394
401
|
element.classList.add('tw-plus-sprite-tab-slot--split');
|
|
395
402
|
body.className = 'tw-plus-sprite-tab-body';
|
|
403
|
+
body.toggleAttribute('data-thumbnail-hidden', thumbnailHidden);
|
|
396
404
|
if (toolbar) {
|
|
397
405
|
body.setAttribute('role', 'tabpanel');
|
|
398
406
|
toolbar.className = 'tw-plus-sprite-tab-toolbar';
|
|
407
|
+
toolbar.toggleAttribute('data-sections-hidden', sectionsHidden);
|
|
399
408
|
element.append(toolbar);
|
|
400
409
|
}
|
|
401
410
|
if (assetPreview) {
|
|
@@ -485,6 +494,9 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
485
494
|
canSplit: () => views.has(group.activePanel?.id),
|
|
486
495
|
verticalTabs: () => verticalTabs,
|
|
487
496
|
setVerticalTabs,
|
|
497
|
+
...(options.onToolbarSlots && {sectionsHidden: () => sectionsHidden, setSectionsHidden}),
|
|
498
|
+
thumbnailHidden: () => thumbnailHidden,
|
|
499
|
+
setThumbnailHidden,
|
|
488
500
|
...(popouts && {
|
|
489
501
|
canOpenPanel,
|
|
490
502
|
openPanel() {
|
|
@@ -531,6 +543,26 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
531
543
|
refreshSurfaces();
|
|
532
544
|
}
|
|
533
545
|
|
|
546
|
+
function setSectionsHidden(hidden: boolean, chosen = true) {
|
|
547
|
+
sectionsHidden = hidden;
|
|
548
|
+
for (const {toolbar} of slots.values()) toolbar?.toggleAttribute('data-sections-hidden', hidden);
|
|
549
|
+
if (chosen) {
|
|
550
|
+
sectionsChosen = true;
|
|
551
|
+
layoutStore?.writeSectionsHidden?.(hidden).catch(() => undefined);
|
|
552
|
+
}
|
|
553
|
+
// The code area is wider or narrower now, though the panel itself kept its size.
|
|
554
|
+
if (active) options.resize();
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
function setThumbnailHidden(hidden: boolean, chosen = true) {
|
|
558
|
+
thumbnailHidden = hidden;
|
|
559
|
+
for (const {body} of slots.values()) body.toggleAttribute('data-thumbnail-hidden', hidden);
|
|
560
|
+
if (chosen) {
|
|
561
|
+
thumbnailChosen = true;
|
|
562
|
+
layoutStore?.writeThumbnailHidden?.(hidden).catch(() => undefined);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
|
|
534
566
|
const canRename = (target: Target) =>
|
|
535
567
|
target.isOriginal && !target.isStage && Boolean(vm.renameSprite) && vm.runtime.targets.includes(target);
|
|
536
568
|
|
|
@@ -614,7 +646,8 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
614
646
|
if (ownSection(view.section) && slot.assetPreview) {
|
|
615
647
|
slot.assetPreview.hidden = false;
|
|
616
648
|
assetPreviews.push({id, targetId: descriptor.targetId,
|
|
617
|
-
kind: view.section === messageSection ? 'messages' : view.section === functionSection ? 'functions' :
|
|
649
|
+
kind: view.section === messageSection ? 'messages' : view.section === functionSection ? 'functions' :
|
|
650
|
+
view.section === callSection ? 'calls' : 'variables',
|
|
618
651
|
editable: active === view,
|
|
619
652
|
element: slot.assetPreview});
|
|
620
653
|
continue;
|
|
@@ -1324,6 +1357,12 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
1324
1357
|
readingTabs = false;
|
|
1325
1358
|
updateLayoutState();
|
|
1326
1359
|
});
|
|
1360
|
+
layoutStore?.readSectionsHidden?.().then(hidden => {
|
|
1361
|
+
if (!disposed && !sectionsChosen && hidden) setSectionsHidden(true, false);
|
|
1362
|
+
}, () => undefined);
|
|
1363
|
+
layoutStore?.readThumbnailHidden?.().then(hidden => {
|
|
1364
|
+
if (!disposed && !thumbnailChosen && hidden) setThumbnailHidden(true, false);
|
|
1365
|
+
}, () => undefined);
|
|
1327
1366
|
if (persistence) window.addEventListener('pagehide', flushLayout);
|
|
1328
1367
|
updateLayoutState();
|
|
1329
1368
|
root.addEventListener('click', guardDocumentClose, true);
|
|
@@ -1407,10 +1446,32 @@ type SpriteTabsProps<Snapshot> = Omit<TabOptions<Snapshot>, 'activateSection' |
|
|
|
1407
1446
|
openMessageTarget?(targetId: string): void;
|
|
1408
1447
|
/** Rename a message everywhere in the project. The stage owns broadcast_msg variables. */
|
|
1409
1448
|
renameMessage?(message: ProjectMessage, name: string): MessageRenameError | void;
|
|
1410
|
-
/**
|
|
1449
|
+
/**
|
|
1450
|
+
* The custom block definitions of this target, with its other hat scripts in `hats` for the list.
|
|
1451
|
+
* `readTargetFunctions` reads the definitions from the runtime.
|
|
1452
|
+
*/
|
|
1411
1453
|
getFunctions?(targetId: string): FunctionPaneData;
|
|
1412
1454
|
/** Mount an editor of one definition script in an open item of the functions pane. */
|
|
1413
1455
|
mountFunctionEditor?: MountFunctionEditor;
|
|
1456
|
+
/**
|
|
1457
|
+
* Open one function picked in the list or the call graph of the functions section, such as in a tab
|
|
1458
|
+
* split beside the sprite. Without it the function opens in a dialog.
|
|
1459
|
+
*/
|
|
1460
|
+
openFunction?(targetId: string, fn: SpriteFunction, options?: OpenScriptOptions): void;
|
|
1461
|
+
/**
|
|
1462
|
+
* Open a hat script picked in the list of hats and functions, as `openFunction` opens a function.
|
|
1463
|
+
* `options.block` asks to show one block, such as a call picked in the list of a function's uses.
|
|
1464
|
+
*/
|
|
1465
|
+
openScript?(targetId: string, hat: SpriteHatScript, options?: OpenScriptOptions): void;
|
|
1466
|
+
/** The function or hat script shown beside the sprite, which the list of hats and functions highlights. */
|
|
1467
|
+
selectedScript?: {targetId: string; id: string};
|
|
1468
|
+
/**
|
|
1469
|
+
* Make a new function of this name in the target: a standard custom block, whose block text is the name,
|
|
1470
|
+
* or a TurboWarp-Plus named function. Resolves with the id of the new hat, or with nothing when nothing
|
|
1471
|
+
* was made; a rejection may carry a `code` the pane explains. Without it, the functions sections have
|
|
1472
|
+
* no add button.
|
|
1473
|
+
*/
|
|
1474
|
+
createFunction?(targetId: string, kind: FunctionKind, name: string): Promise<string | void>;
|
|
1414
1475
|
getCodeSearchItems?(targetId: string): readonly SpriteSearchResult[];
|
|
1415
1476
|
openCodeSearchResult?(targetId: string, id: string): void;
|
|
1416
1477
|
};
|
|
@@ -1570,7 +1631,7 @@ function SpriteTabs<Snapshot>(props: SpriteTabsProps<Snapshot>) {
|
|
|
1570
1631
|
// A section with no port behind it would open an empty panel.
|
|
1571
1632
|
availableSections: spriteEditorSections.filter(section =>
|
|
1572
1633
|
(section !== 'messages' || Boolean(props.getMessages)) &&
|
|
1573
|
-
(section !== 'functions' || Boolean(props.getFunctions))),
|
|
1634
|
+
(section !== 'functions' && section !== 'calls' || Boolean(props.getFunctions))),
|
|
1574
1635
|
actions: view.active && currentSection !== 'variables' ? props.activeTools : undefined,
|
|
1575
1636
|
onSectionChange: section => actions.setSection(spriteEditorSections.indexOf(section)),
|
|
1576
1637
|
search: {
|
|
@@ -1583,9 +1644,10 @@ function SpriteTabs<Snapshot>(props: SpriteTabsProps<Snapshot>) {
|
|
|
1583
1644
|
} else if (section === 'messages') {
|
|
1584
1645
|
items = (props.getMessages?.(view.targetId).messages ?? [])
|
|
1585
1646
|
.map(message => ({id: message.key, label: message.name}));
|
|
1586
|
-
} else if (section === 'functions') {
|
|
1587
|
-
|
|
1588
|
-
|
|
1647
|
+
} else if (section === 'functions' || section === 'calls') {
|
|
1648
|
+
const data = props.getFunctions?.(view.targetId);
|
|
1649
|
+
items = [...(section === 'functions' ? data?.hats ?? [] : []).map(hat => ({id: hat.id, label: hat.label})),
|
|
1650
|
+
...(data?.functions ?? []).map(fn => ({id: fn.id, label: functionLabel(fn)}))];
|
|
1589
1651
|
} else {
|
|
1590
1652
|
items = props.getAssetPreview?.(view.targetId, section).items.map((item, index) =>
|
|
1591
1653
|
({id: String(index), label: item.name})) ?? [];
|
|
@@ -1604,10 +1666,10 @@ function SpriteTabs<Snapshot>(props: SpriteTabsProps<Snapshot>) {
|
|
|
1604
1666
|
const pane = assetPreviewSlots.find(slot => slot.id === view.id)?.element;
|
|
1605
1667
|
[...(pane?.querySelectorAll<HTMLElement>('[data-message-key]') ?? [])]
|
|
1606
1668
|
.find(node => node.dataset.messageKey === result.id)?.focus();
|
|
1607
|
-
} else if (section === 'functions') {
|
|
1669
|
+
} else if (section === 'functions' || section === 'calls') {
|
|
1608
1670
|
const pane = assetPreviewSlots.find(slot => slot.id === view.id)?.element;
|
|
1609
|
-
[...(pane?.querySelectorAll<HTMLElement>('[data-function-key]') ?? [])]
|
|
1610
|
-
.find(node => node.dataset.functionKey === result.id)?.focus();
|
|
1671
|
+
[...(pane?.querySelectorAll<HTMLElement>('[data-function-key], [data-hat-key]') ?? [])]
|
|
1672
|
+
.find(node => (node.dataset.functionKey ?? node.dataset.hatKey) === result.id)?.focus();
|
|
1611
1673
|
} else workspace?.selectAsset(view.id, section, Number(result.id));
|
|
1612
1674
|
}
|
|
1613
1675
|
}
|
|
@@ -1623,11 +1685,24 @@ function SpriteTabs<Snapshot>(props: SpriteTabsProps<Snapshot>) {
|
|
|
1623
1685
|
if (!result) workspace?.refreshSurfaces();
|
|
1624
1686
|
return result;
|
|
1625
1687
|
})
|
|
1626
|
-
}) : kind === 'functions' ? React.createElement(SpriteFunctionPane, {
|
|
1627
|
-
|
|
1688
|
+
}) : kind === 'functions' || kind === 'calls' ? React.createElement(SpriteFunctionPane, {
|
|
1689
|
+
// The list and the call graph are sections of their own.
|
|
1690
|
+
kind: 'functions', view: kind === 'calls' ? 'graph' : 'list',
|
|
1691
|
+
locale: props.locale, editable, data: props.getFunctions!(targetId),
|
|
1628
1692
|
defaultSettings: functionSettings.get(id),
|
|
1629
1693
|
onSettingsChange: (settings: FunctionPaneSettings) => functionSettings.set(id, settings),
|
|
1630
|
-
mountEditor: props.mountFunctionEditor
|
|
1694
|
+
mountEditor: props.mountFunctionEditor,
|
|
1695
|
+
onOpenFunction: props.openFunction &&
|
|
1696
|
+
((fn: SpriteFunction, options?: OpenScriptOptions) => props.openFunction!(targetId, fn, options)),
|
|
1697
|
+
onOpenScript: props.openScript &&
|
|
1698
|
+
((hat: SpriteHatScript, options?: OpenScriptOptions) => props.openScript!(targetId, hat, options)),
|
|
1699
|
+
selectedId: props.selectedScript?.targetId === targetId ? props.selectedScript.id : undefined,
|
|
1700
|
+
onCreate: props.createFunction && (async (functionKind: FunctionKind, name: string) => {
|
|
1701
|
+
const created = await props.createFunction!(targetId, functionKind, name);
|
|
1702
|
+
// Show the new function now rather than at the next project change.
|
|
1703
|
+
if (created) workspace?.refreshSurfaces();
|
|
1704
|
+
return created;
|
|
1705
|
+
})
|
|
1631
1706
|
}) : kind === 'variables' ? renderVariablePane(id, targetId, editable) :
|
|
1632
1707
|
props.getAssetPreview && React.createElement(AssetPreview, {
|
|
1633
1708
|
locale: props.locale, kind, selected, renderLayout, scrollTop, data: props.getAssetPreview(targetId, kind)
|
|
@@ -29,6 +29,12 @@ export interface WorkspaceLayoutStore {
|
|
|
29
29
|
open(identity: WorkspaceProjectIdentity, signature: string): Promise<WorkspaceLayoutSession>;
|
|
30
30
|
readTabsPosition(): Promise<TabsPosition | undefined>;
|
|
31
31
|
writeTabsPosition(position: TabsPosition): Promise<void>;
|
|
32
|
+
/** Whether the section buttons of the sprite tabs are hidden, one preference for every project. */
|
|
33
|
+
readSectionsHidden?(): Promise<boolean | undefined>;
|
|
34
|
+
writeSectionsHidden?(hidden: boolean): Promise<void>;
|
|
35
|
+
/** Whether the costume thumbnail of the code areas is hidden, one preference for every project. */
|
|
36
|
+
readThumbnailHidden?(): Promise<boolean | undefined>;
|
|
37
|
+
writeThumbnailHidden?(hidden: boolean): Promise<void>;
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
export interface WorkspaceLayoutStoreOptions {
|
|
@@ -50,6 +56,8 @@ export const workspaceLayoutMaxBytes = 256 * 1024;
|
|
|
50
56
|
const layoutsStore = 'layouts';
|
|
51
57
|
const preferencesStore = 'preferences';
|
|
52
58
|
const tabsPositionKey = 'tabsPosition';
|
|
59
|
+
const sectionsHiddenKey = 'sectionsHidden';
|
|
60
|
+
const thumbnailHiddenKey = 'thumbnailHidden';
|
|
53
61
|
const legacyKeys = ['twPlusDockviewLayout', 'twPlusDockviewLayout.tabs'];
|
|
54
62
|
|
|
55
63
|
interface LayoutRecord {
|
|
@@ -209,13 +217,28 @@ export function createWorkspaceLayoutStore({indexedDB: factory = globalThis.inde
|
|
|
209
217
|
return value === 'left' || value === 'top' ? value : undefined;
|
|
210
218
|
},
|
|
211
219
|
writeTabsPosition(position) {
|
|
212
|
-
return
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
+
return writePreference(tabsPositionKey, position);
|
|
221
|
+
},
|
|
222
|
+
readSectionsHidden: () => readFlag(sectionsHiddenKey),
|
|
223
|
+
writeSectionsHidden: hidden => writePreference(sectionsHiddenKey, hidden),
|
|
224
|
+
readThumbnailHidden: () => readFlag(thumbnailHiddenKey),
|
|
225
|
+
writeThumbnailHidden: hidden => writePreference(thumbnailHiddenKey, hidden)
|
|
220
226
|
};
|
|
227
|
+
|
|
228
|
+
async function readFlag(key: string) {
|
|
229
|
+
const opened = await connect();
|
|
230
|
+
const transaction = opened.transaction(preferencesStore, 'readonly');
|
|
231
|
+
const value = await result(transaction.objectStore(preferencesStore).get(key));
|
|
232
|
+
return typeof value === 'boolean' ? value : undefined;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function writePreference(key: string, value: unknown) {
|
|
236
|
+
return enqueue(async () => {
|
|
237
|
+
const opened = await connect();
|
|
238
|
+
const transaction = opened.transaction(preferencesStore, 'readwrite');
|
|
239
|
+
const finished = completion(transaction);
|
|
240
|
+
transaction.objectStore(preferencesStore).put(value, key);
|
|
241
|
+
await finished;
|
|
242
|
+
});
|
|
243
|
+
}
|
|
221
244
|
}
|