@kubohiroya/turbowarp-plus-editor-workbench 0.11.0 → 0.12.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 -0
- package/README.md +7 -0
- package/dist/sprite-tabs.d.ts +10 -2
- package/dist/sprite-tabs.js +50 -22
- package/package.json +2 -2
- package/src/sprite-tabs.ts +60 -24
package/README.ja.md
CHANGED
|
@@ -136,3 +136,8 @@ Web 版の Plus 標準配置で `twPlusDockview=1` を付けて起動すると
|
|
|
136
136
|
`broadcast_msg` はステージ所有なので、メッセージ名の変更は作品全体に及ぶ。
|
|
137
137
|
送受信の判定は `@kubohiroya/turbowarp-plus-editor-project-model` の `messageReference` だけが持ち、Editor の作品内検索も同じ関数を使う。
|
|
138
138
|
このパッケージの `./project-messages` は、既存の import のためにそれを再 export している。
|
|
139
|
+
|
|
140
|
+
ホストが `getFunctions` を渡すと、「音」と「変数など」の間に「関数」がある(ボタンの並びは
|
|
141
|
+
`@kubohiroya/turbowarp-plus-editor-sprite-panes` のツールバーが決め、保存済みのレイアウトが持つセクションの番号は変わらない)。`SpriteFunctionPane` が対象のブロック定義を
|
|
142
|
+
アコーディオンで一覧し、並べ方は名前順・Z順・N順から選び、LR・TD の呼び出し図にも切り替えられる(図の関数はダイアログで開く)。表示・並べ方・流れはビューごとに保つ。開いた項目はホストの
|
|
143
|
+
`mountFunctionEditor` を呼び、その定義のコード編集画面はホストが持つ。このパッケージは Scratch Blocks のコードを持たないためである。
|
package/README.md
CHANGED
|
@@ -134,3 +134,10 @@ Variables, drawn by `SpriteMessagePane` from `@kubohiroya/turbowarp-plus-editor-
|
|
|
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
|
+
|
|
138
|
+
When the host passes `getFunctions`, a Functions section appears between Sounds and Variables (the
|
|
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` lists the
|
|
141
|
+
target's custom block definitions as an accordion, ordered by name, in Z order or in N order, or as a call graph flowing LR or TD whose
|
|
142
|
+
functions open in a dialog; each view keeps the mode, order and flow it chose. Each open item calls the host's `mountFunctionEditor`, which owns the code workspace of that
|
|
143
|
+
definition, because this package carries no Scratch Blocks code.
|
package/dist/sprite-tabs.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { NativeAssetPanel } from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-asset-pane';
|
|
3
|
-
import type { NativeAssetPanelRenderer, NativeAssetSelector, SpriteAssetKind, SpriteAssetLayout, SpriteAssetPreviewItem, SpriteVariable } from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-asset-pane';
|
|
3
|
+
import type { NativeAssetPanelRenderer, NativeAssetSelector, SpriteAssetKind, SpriteAssetLayout, SpriteAssetPreviewItem, SpriteVariable, SpriteVariablePaneProps } from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-asset-pane';
|
|
4
4
|
import type { SpritePropertiesPanelProps } from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-properties';
|
|
5
5
|
import type { SpriteSearchResult } from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-editor-toolbar';
|
|
6
6
|
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
11
|
import type { MessageUse, ProjectMessage, TargetMessages } from '@kubohiroya/turbowarp-plus-editor-project-model/project-messages';
|
|
11
12
|
export { getDocumentWorkspace } from './document-workspace.ts';
|
|
12
13
|
export { createWorkspaceLayoutStore, workspaceLayoutDatabase, workspaceLayoutLimit } from './workspace-layout-store.ts';
|
|
@@ -92,6 +93,7 @@ interface TabOptions<Snapshot = unknown> {
|
|
|
92
93
|
stagePane?: DockviewStagePane;
|
|
93
94
|
variables?: boolean;
|
|
94
95
|
messages?: boolean;
|
|
96
|
+
functions?: boolean;
|
|
95
97
|
locale?: string;
|
|
96
98
|
viewAdapter?: SpriteTabAdapter<Snapshot>;
|
|
97
99
|
popouts?: {
|
|
@@ -115,7 +117,7 @@ interface ToolbarSlot {
|
|
|
115
117
|
interface AssetPreviewSlot {
|
|
116
118
|
id: string;
|
|
117
119
|
targetId: string;
|
|
118
|
-
kind: AssetKind | 'variables' | 'messages';
|
|
120
|
+
kind: AssetKind | 'variables' | 'messages' | 'functions';
|
|
119
121
|
editable: boolean;
|
|
120
122
|
selected?: object;
|
|
121
123
|
renderLayout?: SpriteAssetLayout;
|
|
@@ -177,6 +179,8 @@ type SpriteTabsProps<Snapshot> = Omit<TabOptions<Snapshot>, 'activateSection' |
|
|
|
177
179
|
writeProperties?: SpritePropertiesPanelProps['onChange'];
|
|
178
180
|
writeVariable?(targetId: string, id: string, value: SpriteVariable['value']): void;
|
|
179
181
|
editVariable?(targetId: string, edit: SpriteVariableEdit): SpriteVariableEditError | void;
|
|
182
|
+
/** Wrap a variables pane while receiving its docked view and original target identities. */
|
|
183
|
+
wrapVariablePane?(viewId: string, targetId: string, editable: boolean, pane: React.ReactElement<SpriteVariablePaneProps>): React.ReactNode;
|
|
180
184
|
/** What this target sends and receives. `scanTargetMessages` builds it from the runtime. */
|
|
181
185
|
getMessages?(targetId: string): TargetMessages;
|
|
182
186
|
/** Open the block that sends or receives a message. */
|
|
@@ -185,6 +189,10 @@ type SpriteTabsProps<Snapshot> = Omit<TabOptions<Snapshot>, 'activateSection' |
|
|
|
185
189
|
openMessageTarget?(targetId: string): void;
|
|
186
190
|
/** Rename a message everywhere in the project. The stage owns broadcast_msg variables. */
|
|
187
191
|
renameMessage?(message: ProjectMessage, name: string): MessageRenameError | void;
|
|
192
|
+
/** The custom block definitions of this target. `readTargetFunctions` builds it from the runtime. */
|
|
193
|
+
getFunctions?(targetId: string): FunctionPaneData;
|
|
194
|
+
/** Mount an editor of one definition script in an open item of the functions pane. */
|
|
195
|
+
mountFunctionEditor?: MountFunctionEditor;
|
|
188
196
|
getCodeSearchItems?(targetId: string): readonly SpriteSearchResult[];
|
|
189
197
|
openCodeSearchResult?(targetId: string, id: string): void;
|
|
190
198
|
};
|
package/dist/sprite-tabs.js
CHANGED
|
@@ -9,6 +9,7 @@ import { projectFolderIconPath } from "./drawer-views.js";
|
|
|
9
9
|
import { dockPopoutGroups, positionOnScreen, readWorkspaceLayout, workspaceWithoutTransientPanels } from "./workspace-layout.js";
|
|
10
10
|
import { createWorkspaceLayoutStore } from "./workspace-layout-store.js";
|
|
11
11
|
import { SpriteMessagePane } from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-message-pane';
|
|
12
|
+
import { functionLabel, SpriteFunctionPane } from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-function-pane';
|
|
12
13
|
import { createTargetTabMenuItem, spriteRenameLabel } from "./target-tab-menu.js";
|
|
13
14
|
export { getDocumentWorkspace } from "./document-workspace.js";
|
|
14
15
|
export { createWorkspaceLayoutStore, workspaceLayoutDatabase, workspaceLayoutLimit } from "./workspace-layout-store.js";
|
|
@@ -17,6 +18,7 @@ export { useDockviewStage } from "./dockview-stage.js";
|
|
|
17
18
|
export { SpriteTargetTabsContext, useTargetTabMenu } from "./target-tab-menu.js";
|
|
18
19
|
const variableSection = spriteEditorSections.indexOf('variables');
|
|
19
20
|
const messageSection = spriteEditorSections.indexOf('messages');
|
|
21
|
+
const functionSection = spriteEditorSections.indexOf('functions');
|
|
20
22
|
// The first three sections are the GUI's own panels; the rest are rendered by this package.
|
|
21
23
|
const lastNativeSection = 2;
|
|
22
24
|
function createAssetSelections(target, locale, source) {
|
|
@@ -115,7 +117,8 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
115
117
|
const viewAdapter = multiView ? options.viewAdapter : undefined;
|
|
116
118
|
const stagePane = multiView ? options.stagePane : undefined;
|
|
117
119
|
const ownSection = (section) => (section === variableSection && Boolean(options.variables)) ||
|
|
118
|
-
(section === messageSection && Boolean(options.messages))
|
|
120
|
+
(section === messageSection && Boolean(options.messages)) ||
|
|
121
|
+
(section === functionSection && Boolean(options.functions));
|
|
119
122
|
const usesNativeSection = (section) => !ownSection(section);
|
|
120
123
|
const sectionAvailable = (section) => section <= lastNativeSection || ownSection(section);
|
|
121
124
|
const document = root.ownerDocument;
|
|
@@ -479,7 +482,8 @@ export function mountSpriteTabs(root, content, options) {
|
|
|
479
482
|
if (ownSection(view.section) && slot.assetPreview) {
|
|
480
483
|
slot.assetPreview.hidden = false;
|
|
481
484
|
assetPreviews.push({ id, targetId: descriptor.targetId,
|
|
482
|
-
kind: view.section === messageSection ? 'messages' : '
|
|
485
|
+
kind: view.section === messageSection ? 'messages' : view.section === functionSection ? 'functions' : 'variables',
|
|
486
|
+
editable: active === view,
|
|
483
487
|
element: slot.assetPreview });
|
|
484
488
|
continue;
|
|
485
489
|
}
|
|
@@ -1357,11 +1361,14 @@ function SpriteTabs(props) {
|
|
|
1357
1361
|
});
|
|
1358
1362
|
const [toolbarSlots, setToolbarSlots] = React.useState([]);
|
|
1359
1363
|
const [assetPreviewSlots, setAssetPreviewSlots] = React.useState([]);
|
|
1364
|
+
// The functions pane remounts when its view switches sections; keep the view, order and flow each view chose.
|
|
1365
|
+
const [functionSettings] = React.useState(() => new Map());
|
|
1360
1366
|
const controller = React.useRef(null);
|
|
1361
1367
|
const hasVariables = Boolean(props.getVariables);
|
|
1362
1368
|
const hasMessages = Boolean(props.getMessages);
|
|
1369
|
+
const hasFunctions = Boolean(props.getFunctions);
|
|
1363
1370
|
const hasToolbar = Boolean(props.renderToolbar) || hasVariables;
|
|
1364
|
-
const hasAssetPreview = Boolean(props.getAssetPreview) || hasVariables || hasMessages;
|
|
1371
|
+
const hasAssetPreview = Boolean(props.getAssetPreview) || hasVariables || hasMessages || hasFunctions;
|
|
1365
1372
|
React.useLayoutEffect(() => {
|
|
1366
1373
|
sections.current.append(...props.slots);
|
|
1367
1374
|
parking.current.appendChild(content);
|
|
@@ -1409,6 +1416,7 @@ function SpriteTabs(props) {
|
|
|
1409
1416
|
stagePane: props.stagePane,
|
|
1410
1417
|
variables: hasVariables,
|
|
1411
1418
|
messages: hasMessages,
|
|
1419
|
+
functions: hasFunctions,
|
|
1412
1420
|
locale: props.locale,
|
|
1413
1421
|
viewAdapter: props.viewAdapter,
|
|
1414
1422
|
popouts: props.popouts && { ...props.popouts, className: props.className },
|
|
@@ -1428,7 +1436,7 @@ function SpriteTabs(props) {
|
|
|
1428
1436
|
};
|
|
1429
1437
|
}, [content, props.enabled, props.vm, props.reopenLabel, props.multiView, props.locale,
|
|
1430
1438
|
props.viewAdapter, props.stagePane, props.workspaceLayout, props.renameLabels, props.popouts, props.className,
|
|
1431
|
-
hasVariables, hasMessages, hasToolbar, hasAssetPreview]);
|
|
1439
|
+
hasVariables, hasMessages, hasFunctions, hasToolbar, hasAssetPreview]);
|
|
1432
1440
|
React.useLayoutEffect(() => {
|
|
1433
1441
|
controller.current?.syncActiveSection(props.activeSection);
|
|
1434
1442
|
}, [props.activeSection]);
|
|
@@ -1453,7 +1461,8 @@ function SpriteTabs(props) {
|
|
|
1453
1461
|
viewId: view.id, locale: props.locale, section: currentSection, isStage: view.isStage,
|
|
1454
1462
|
activeGroup: view.groupActive, propertiesInVariables: Boolean(props.getProperties),
|
|
1455
1463
|
// A section with no port behind it would open an empty panel.
|
|
1456
|
-
availableSections: spriteEditorSections.filter(section => section !== 'messages' || Boolean(props.getMessages))
|
|
1464
|
+
availableSections: spriteEditorSections.filter(section => (section !== 'messages' || Boolean(props.getMessages)) &&
|
|
1465
|
+
(section !== 'functions' || Boolean(props.getFunctions))),
|
|
1457
1466
|
actions: view.active && currentSection !== 'variables' ? props.activeTools : undefined,
|
|
1458
1467
|
onSectionChange: section => actions.setSection(spriteEditorSections.indexOf(section)),
|
|
1459
1468
|
search: {
|
|
@@ -1469,6 +1478,10 @@ function SpriteTabs(props) {
|
|
|
1469
1478
|
items = (props.getMessages?.(view.targetId).messages ?? [])
|
|
1470
1479
|
.map(message => ({ id: message.key, label: message.name }));
|
|
1471
1480
|
}
|
|
1481
|
+
else if (section === 'functions') {
|
|
1482
|
+
items = (props.getFunctions?.(view.targetId).functions ?? [])
|
|
1483
|
+
.map(fn => ({ id: fn.id, label: functionLabel(fn) }));
|
|
1484
|
+
}
|
|
1472
1485
|
else {
|
|
1473
1486
|
items = props.getAssetPreview?.(view.targetId, section).items.map((item, index) => ({ id: String(index), label: item.name })) ?? [];
|
|
1474
1487
|
}
|
|
@@ -1481,7 +1494,7 @@ function SpriteTabs(props) {
|
|
|
1481
1494
|
props.openCodeSearchResult?.(view.targetId, result.id);
|
|
1482
1495
|
else if (section === 'variables') {
|
|
1483
1496
|
const field = assetPreviewSlots.find(slot => slot.id === view.id)?.element;
|
|
1484
|
-
[...(field?.querySelectorAll('
|
|
1497
|
+
[...(field?.querySelectorAll('[data-variable-id]') ?? [])]
|
|
1485
1498
|
.find(input => input.dataset.variableId === result.id)?.focus();
|
|
1486
1499
|
}
|
|
1487
1500
|
else if (section === 'messages') {
|
|
@@ -1489,6 +1502,11 @@ function SpriteTabs(props) {
|
|
|
1489
1502
|
[...(pane?.querySelectorAll('[data-message-key]') ?? [])]
|
|
1490
1503
|
.find(node => node.dataset.messageKey === result.id)?.focus();
|
|
1491
1504
|
}
|
|
1505
|
+
else if (section === 'functions') {
|
|
1506
|
+
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();
|
|
1509
|
+
}
|
|
1492
1510
|
else
|
|
1493
1511
|
workspace?.selectAsset(view.id, section, Number(result.id));
|
|
1494
1512
|
}
|
|
@@ -1505,22 +1523,32 @@ function SpriteTabs(props) {
|
|
|
1505
1523
|
workspace?.refreshSurfaces();
|
|
1506
1524
|
return result;
|
|
1507
1525
|
})
|
|
1508
|
-
}) : kind === '
|
|
1509
|
-
kind, locale: props.locale, editable,
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1526
|
+
}) : kind === 'functions' ? React.createElement(SpriteFunctionPane, {
|
|
1527
|
+
kind, locale: props.locale, editable, data: props.getFunctions(targetId),
|
|
1528
|
+
defaultSettings: functionSettings.get(id),
|
|
1529
|
+
onSettingsChange: (settings) => functionSettings.set(id, settings),
|
|
1530
|
+
mountEditor: props.mountFunctionEditor
|
|
1531
|
+
}) : kind === 'variables' ? renderVariablePane(id, targetId, editable) :
|
|
1532
|
+
props.getAssetPreview && React.createElement(AssetPreview, {
|
|
1533
|
+
locale: props.locale, kind, selected, renderLayout, scrollTop, data: props.getAssetPreview(targetId, kind)
|
|
1534
|
+
}), element, id)));
|
|
1535
|
+
function renderVariablePane(id, targetId, editable) {
|
|
1536
|
+
const pane = React.createElement(SpriteAssetPane, {
|
|
1537
|
+
kind: 'variables', locale: props.locale, editable, variables: props.getVariables?.(targetId) ?? [],
|
|
1538
|
+
properties: props.getProperties?.(targetId),
|
|
1539
|
+
targetId,
|
|
1540
|
+
onWriteProperties(id, patch) {
|
|
1541
|
+
props.writeProperties?.(id, patch);
|
|
1542
|
+
workspace?.refreshSurfaces();
|
|
1543
|
+
},
|
|
1544
|
+
onWrite(variableId, value) {
|
|
1545
|
+
props.writeVariable?.(targetId, variableId, value);
|
|
1546
|
+
workspace?.refreshSurfaces();
|
|
1547
|
+
},
|
|
1548
|
+
onEdit: props.editVariable && (edit => props.editVariable(targetId, edit))
|
|
1549
|
+
});
|
|
1550
|
+
return props.wrapVariablePane?.(id, targetId, editable, pane) ?? pane;
|
|
1551
|
+
}
|
|
1524
1552
|
}
|
|
1525
1553
|
export function useSpriteTabs({ available, enabled, locale, ...props }) {
|
|
1526
1554
|
const controller = React.useRef(null);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-plus-editor-workbench",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.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",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
75
|
"@kubohiroya/turbowarp-plus-editor-project-model": "0.1.0",
|
|
76
|
-
"@kubohiroya/turbowarp-plus-editor-sprite-panes": "0.
|
|
76
|
+
"@kubohiroya/turbowarp-plus-editor-sprite-panes": "0.2.1",
|
|
77
77
|
"dockview": "8.8.3"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
package/src/sprite-tabs.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {DockviewGroupPanel, GroupPanelPartInitParameters, IDockviewPanel, S
|
|
|
5
5
|
import {createSpriteLayoutMenu} from './sprite-layout-menu.ts';
|
|
6
6
|
import {NativeAssetPanel, SpriteAssetPane} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-asset-pane';
|
|
7
7
|
import type {NativeAssetPanelRenderer, NativeAssetSelector, SpriteAssetKind, SpriteAssetLayout, SpriteAssetPreviewItem,
|
|
8
|
-
SpriteVariable} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-asset-pane';
|
|
8
|
+
SpriteVariable, SpriteVariablePaneProps} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-asset-pane';
|
|
9
9
|
import type {SpritePropertiesPanelProps} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-properties';
|
|
10
10
|
import {SpriteEditorToolbar, spriteEditorSections} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-editor-toolbar';
|
|
11
11
|
import type {SpriteSearchResult} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-editor-toolbar';
|
|
@@ -21,6 +21,8 @@ import type {WorkspaceLayoutSession, WorkspaceLayoutStore, WorkspaceProjectIdent
|
|
|
21
21
|
import type {SpriteVariableEdit, SpriteVariableEditError} from '@kubohiroya/turbowarp-plus-editor-project-model/sprite-variable-edit';
|
|
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
|
+
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';
|
|
24
26
|
import type {MessageUse, ProjectMessage, TargetMessages} from '@kubohiroya/turbowarp-plus-editor-project-model/project-messages';
|
|
25
27
|
import {createTargetTabMenuItem, spriteRenameLabel} from './target-tab-menu.ts';
|
|
26
28
|
|
|
@@ -88,6 +90,7 @@ type AssetKind = SpriteAssetKind;
|
|
|
88
90
|
|
|
89
91
|
const variableSection = spriteEditorSections.indexOf('variables');
|
|
90
92
|
const messageSection = spriteEditorSections.indexOf('messages');
|
|
93
|
+
const functionSection = spriteEditorSections.indexOf('functions');
|
|
91
94
|
// The first three sections are the GUI's own panels; the rest are rendered by this package.
|
|
92
95
|
const lastNativeSection = 2;
|
|
93
96
|
|
|
@@ -162,6 +165,7 @@ interface TabOptions<Snapshot = unknown> {
|
|
|
162
165
|
stagePane?: DockviewStagePane;
|
|
163
166
|
variables?: boolean;
|
|
164
167
|
messages?: boolean;
|
|
168
|
+
functions?: boolean;
|
|
165
169
|
locale?: string;
|
|
166
170
|
viewAdapter?: SpriteTabAdapter<Snapshot>;
|
|
167
171
|
popouts?: {url: string; className?: string; openPalette?(view: SpriteTabView): void};
|
|
@@ -184,7 +188,7 @@ interface ToolbarSlot {
|
|
|
184
188
|
interface AssetPreviewSlot {
|
|
185
189
|
id: string;
|
|
186
190
|
targetId: string;
|
|
187
|
-
kind: AssetKind | 'variables' | 'messages';
|
|
191
|
+
kind: AssetKind | 'variables' | 'messages' | 'functions';
|
|
188
192
|
editable: boolean;
|
|
189
193
|
selected?: object;
|
|
190
194
|
renderLayout?: SpriteAssetLayout;
|
|
@@ -266,7 +270,8 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
266
270
|
const viewAdapter = multiView ? options.viewAdapter : undefined;
|
|
267
271
|
const stagePane = multiView ? options.stagePane : undefined;
|
|
268
272
|
const ownSection = (section: number) => (section === variableSection && Boolean(options.variables)) ||
|
|
269
|
-
(section === messageSection && Boolean(options.messages))
|
|
273
|
+
(section === messageSection && Boolean(options.messages)) ||
|
|
274
|
+
(section === functionSection && Boolean(options.functions));
|
|
270
275
|
const usesNativeSection = (section: number) => !ownSection(section);
|
|
271
276
|
const sectionAvailable = (section: number) => section <= lastNativeSection || ownSection(section);
|
|
272
277
|
const document = root.ownerDocument;
|
|
@@ -609,7 +614,8 @@ export function mountSpriteTabs<Snapshot>(root: HTMLElement, content: HTMLElemen
|
|
|
609
614
|
if (ownSection(view.section) && slot.assetPreview) {
|
|
610
615
|
slot.assetPreview.hidden = false;
|
|
611
616
|
assetPreviews.push({id, targetId: descriptor.targetId,
|
|
612
|
-
kind: view.section === messageSection ? 'messages' : '
|
|
617
|
+
kind: view.section === messageSection ? 'messages' : view.section === functionSection ? 'functions' : 'variables',
|
|
618
|
+
editable: active === view,
|
|
613
619
|
element: slot.assetPreview});
|
|
614
620
|
continue;
|
|
615
621
|
}
|
|
@@ -1390,6 +1396,9 @@ type SpriteTabsProps<Snapshot> = Omit<TabOptions<Snapshot>, 'activateSection' |
|
|
|
1390
1396
|
writeProperties?: SpritePropertiesPanelProps['onChange'];
|
|
1391
1397
|
writeVariable?(targetId: string, id: string, value: SpriteVariable['value']): void;
|
|
1392
1398
|
editVariable?(targetId: string, edit: SpriteVariableEdit): SpriteVariableEditError | void;
|
|
1399
|
+
/** Wrap a variables pane while receiving its docked view and original target identities. */
|
|
1400
|
+
wrapVariablePane?(viewId: string, targetId: string, editable: boolean,
|
|
1401
|
+
pane: React.ReactElement<SpriteVariablePaneProps>): React.ReactNode;
|
|
1393
1402
|
/** What this target sends and receives. `scanTargetMessages` builds it from the runtime. */
|
|
1394
1403
|
getMessages?(targetId: string): TargetMessages;
|
|
1395
1404
|
/** Open the block that sends or receives a message. */
|
|
@@ -1398,6 +1407,10 @@ type SpriteTabsProps<Snapshot> = Omit<TabOptions<Snapshot>, 'activateSection' |
|
|
|
1398
1407
|
openMessageTarget?(targetId: string): void;
|
|
1399
1408
|
/** Rename a message everywhere in the project. The stage owns broadcast_msg variables. */
|
|
1400
1409
|
renameMessage?(message: ProjectMessage, name: string): MessageRenameError | void;
|
|
1410
|
+
/** The custom block definitions of this target. `readTargetFunctions` builds it from the runtime. */
|
|
1411
|
+
getFunctions?(targetId: string): FunctionPaneData;
|
|
1412
|
+
/** Mount an editor of one definition script in an open item of the functions pane. */
|
|
1413
|
+
mountFunctionEditor?: MountFunctionEditor;
|
|
1401
1414
|
getCodeSearchItems?(targetId: string): readonly SpriteSearchResult[];
|
|
1402
1415
|
openCodeSearchResult?(targetId: string, id: string): void;
|
|
1403
1416
|
};
|
|
@@ -1452,11 +1465,14 @@ function SpriteTabs<Snapshot>(props: SpriteTabsProps<Snapshot>) {
|
|
|
1452
1465
|
});
|
|
1453
1466
|
const [toolbarSlots, setToolbarSlots] = React.useState<readonly ToolbarSlot[]>([]);
|
|
1454
1467
|
const [assetPreviewSlots, setAssetPreviewSlots] = React.useState<readonly AssetPreviewSlot[]>([]);
|
|
1468
|
+
// The functions pane remounts when its view switches sections; keep the view, order and flow each view chose.
|
|
1469
|
+
const [functionSettings] = React.useState(() => new Map<string, FunctionPaneSettings>());
|
|
1455
1470
|
const controller = React.useRef<SpriteTabsController<Snapshot>>(null);
|
|
1456
1471
|
const hasVariables = Boolean(props.getVariables);
|
|
1457
1472
|
const hasMessages = Boolean(props.getMessages);
|
|
1473
|
+
const hasFunctions = Boolean(props.getFunctions);
|
|
1458
1474
|
const hasToolbar = Boolean(props.renderToolbar) || hasVariables;
|
|
1459
|
-
const hasAssetPreview = Boolean(props.getAssetPreview) || hasVariables || hasMessages;
|
|
1475
|
+
const hasAssetPreview = Boolean(props.getAssetPreview) || hasVariables || hasMessages || hasFunctions;
|
|
1460
1476
|
React.useLayoutEffect(() => {
|
|
1461
1477
|
sections.current.append(...props.slots);
|
|
1462
1478
|
parking.current.appendChild(content);
|
|
@@ -1504,6 +1520,7 @@ function SpriteTabs<Snapshot>(props: SpriteTabsProps<Snapshot>) {
|
|
|
1504
1520
|
stagePane: props.stagePane,
|
|
1505
1521
|
variables: hasVariables,
|
|
1506
1522
|
messages: hasMessages,
|
|
1523
|
+
functions: hasFunctions,
|
|
1507
1524
|
locale: props.locale,
|
|
1508
1525
|
viewAdapter: props.viewAdapter,
|
|
1509
1526
|
popouts: props.popouts && {...props.popouts, className: props.className},
|
|
@@ -1522,7 +1539,7 @@ function SpriteTabs<Snapshot>(props: SpriteTabsProps<Snapshot>) {
|
|
|
1522
1539
|
};
|
|
1523
1540
|
}, [content, props.enabled, props.vm, props.reopenLabel, props.multiView, props.locale,
|
|
1524
1541
|
props.viewAdapter, props.stagePane, props.workspaceLayout, props.renameLabels, props.popouts, props.className,
|
|
1525
|
-
hasVariables, hasMessages, hasToolbar, hasAssetPreview]);
|
|
1542
|
+
hasVariables, hasMessages, hasFunctions, hasToolbar, hasAssetPreview]);
|
|
1526
1543
|
React.useLayoutEffect(() => {
|
|
1527
1544
|
controller.current?.syncActiveSection(props.activeSection);
|
|
1528
1545
|
}, [props.activeSection]);
|
|
@@ -1552,7 +1569,8 @@ function SpriteTabs<Snapshot>(props: SpriteTabsProps<Snapshot>) {
|
|
|
1552
1569
|
activeGroup: view.groupActive, propertiesInVariables: Boolean(props.getProperties),
|
|
1553
1570
|
// A section with no port behind it would open an empty panel.
|
|
1554
1571
|
availableSections: spriteEditorSections.filter(section =>
|
|
1555
|
-
section !== 'messages' || Boolean(props.getMessages))
|
|
1572
|
+
(section !== 'messages' || Boolean(props.getMessages)) &&
|
|
1573
|
+
(section !== 'functions' || Boolean(props.getFunctions))),
|
|
1556
1574
|
actions: view.active && currentSection !== 'variables' ? props.activeTools : undefined,
|
|
1557
1575
|
onSectionChange: section => actions.setSection(spriteEditorSections.indexOf(section)),
|
|
1558
1576
|
search: {
|
|
@@ -1565,6 +1583,9 @@ function SpriteTabs<Snapshot>(props: SpriteTabsProps<Snapshot>) {
|
|
|
1565
1583
|
} else if (section === 'messages') {
|
|
1566
1584
|
items = (props.getMessages?.(view.targetId).messages ?? [])
|
|
1567
1585
|
.map(message => ({id: message.key, label: message.name}));
|
|
1586
|
+
} else if (section === 'functions') {
|
|
1587
|
+
items = (props.getFunctions?.(view.targetId).functions ?? [])
|
|
1588
|
+
.map(fn => ({id: fn.id, label: functionLabel(fn)}));
|
|
1568
1589
|
} else {
|
|
1569
1590
|
items = props.getAssetPreview?.(view.targetId, section).items.map((item, index) =>
|
|
1570
1591
|
({id: String(index), label: item.name})) ?? [];
|
|
@@ -1577,12 +1598,16 @@ function SpriteTabs<Snapshot>(props: SpriteTabsProps<Snapshot>) {
|
|
|
1577
1598
|
if (section === 'code') props.openCodeSearchResult?.(view.targetId, result.id);
|
|
1578
1599
|
else if (section === 'variables') {
|
|
1579
1600
|
const field = assetPreviewSlots.find(slot => slot.id === view.id)?.element;
|
|
1580
|
-
[...(field?.querySelectorAll<
|
|
1601
|
+
[...(field?.querySelectorAll<HTMLElement>('[data-variable-id]') ?? [])]
|
|
1581
1602
|
.find(input => input.dataset.variableId === result.id)?.focus();
|
|
1582
1603
|
} else if (section === 'messages') {
|
|
1583
1604
|
const pane = assetPreviewSlots.find(slot => slot.id === view.id)?.element;
|
|
1584
1605
|
[...(pane?.querySelectorAll<HTMLElement>('[data-message-key]') ?? [])]
|
|
1585
1606
|
.find(node => node.dataset.messageKey === result.id)?.focus();
|
|
1607
|
+
} else if (section === 'functions') {
|
|
1608
|
+
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();
|
|
1586
1611
|
} else workspace?.selectAsset(view.id, section, Number(result.id));
|
|
1587
1612
|
}
|
|
1588
1613
|
}
|
|
@@ -1598,22 +1623,33 @@ function SpriteTabs<Snapshot>(props: SpriteTabsProps<Snapshot>) {
|
|
|
1598
1623
|
if (!result) workspace?.refreshSurfaces();
|
|
1599
1624
|
return result;
|
|
1600
1625
|
})
|
|
1601
|
-
}) : kind === '
|
|
1602
|
-
kind, locale: props.locale, editable,
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1626
|
+
}) : kind === 'functions' ? React.createElement(SpriteFunctionPane, {
|
|
1627
|
+
kind, locale: props.locale, editable, data: props.getFunctions!(targetId),
|
|
1628
|
+
defaultSettings: functionSettings.get(id),
|
|
1629
|
+
onSettingsChange: (settings: FunctionPaneSettings) => functionSettings.set(id, settings),
|
|
1630
|
+
mountEditor: props.mountFunctionEditor
|
|
1631
|
+
}) : kind === 'variables' ? renderVariablePane(id, targetId, editable) :
|
|
1632
|
+
props.getAssetPreview && React.createElement(AssetPreview, {
|
|
1633
|
+
locale: props.locale, kind, selected, renderLayout, scrollTop, data: props.getAssetPreview(targetId, kind)
|
|
1634
|
+
}), element, id)));
|
|
1635
|
+
|
|
1636
|
+
function renderVariablePane(id: string, targetId: string, editable: boolean) {
|
|
1637
|
+
const pane = React.createElement<SpriteVariablePaneProps>(SpriteAssetPane, {
|
|
1638
|
+
kind: 'variables', locale: props.locale, editable, variables: props.getVariables?.(targetId) ?? [],
|
|
1639
|
+
properties: props.getProperties?.(targetId),
|
|
1640
|
+
targetId,
|
|
1641
|
+
onWriteProperties(id: string, patch: Parameters<SpritePropertiesPanelProps['onChange']>[1]) {
|
|
1642
|
+
props.writeProperties?.(id, patch);
|
|
1643
|
+
workspace?.refreshSurfaces();
|
|
1644
|
+
},
|
|
1645
|
+
onWrite(variableId, value) {
|
|
1646
|
+
props.writeVariable?.(targetId, variableId, value);
|
|
1647
|
+
workspace?.refreshSurfaces();
|
|
1648
|
+
},
|
|
1649
|
+
onEdit: props.editVariable && (edit => props.editVariable!(targetId, edit))
|
|
1650
|
+
});
|
|
1651
|
+
return props.wrapVariablePane?.(id, targetId, editable, pane) ?? pane;
|
|
1652
|
+
}
|
|
1617
1653
|
}
|
|
1618
1654
|
|
|
1619
1655
|
export function useSpriteTabs<Snapshot>({available, enabled, locale, ...props}:
|