@kubohiroya/turbowarp-plus-editor-workbench 0.25.0 → 0.27.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 CHANGED
@@ -240,6 +240,10 @@ Editor のルートから、`site/source.json` の GUI を `npm run build:pages`
240
240
 
241
241
  スプライト編集タブの中のペイン(素材と変数、メッセージ、設定フォーム、セクション切り替えのツールバー)は `@kubohiroya/turbowarp-plus-editor-sprite-panes` に移った。このパッケージはそれらをタブや分割に並べる。以前の配布アーカイブのソース `b0390c3` から移設したウィンドウ部品は、`@kubohiroya/turbowarp-plus-editor-windows` に移った。Scratch GUI の本家実装はこのパッケージに取り込んでいないため、GPL のコードを含まず、GPL のモジュールも import しない。ライセンスは MPL-2.0 とする。MPL-2.0 は GPL を二次ライセンスとして認めるので、GPL-3.0 の Editor に組み込んで配信できる。ソースに「Incompatible With Secondary Licenses」の表示は付けない。付けると Editor に組み込めなくなる。
242
242
 
243
+ スプライトの「呼び出し関係」では、図の方向を切り替える LR/TD と、関数・メッセージの表示を切り替えるボタンを縦ツールバーの下端に置く。方向と表示の選択はビューごとに管理し、分割した別ビューの選択を変えない。ホストが `renderToolbar` でツールバーを描く場合は、受け取る `actions.sectionControls` を `SpriteEditorToolbar` の `sectionControls` に渡す。図で選んだスクリプトは `openRelationScript` で開き、ホストが対象のスプライトとブロックへ移動する。
244
+
245
+ コードペインのアダプターに `relations` がある場合、「自由配置」にも同じ関数・メッセージの2ボタンを縦ツールバー下端に置く。表示状態の所有者はコードペインで、`getVisibility(paneId)`・`setVisibility(paneId, value)`・`subscribe(listener)` を使って描画へ反映する。関数だけ、メッセージだけ、両方、両方非表示を選べ、分割した別のペインや呼び出し関係パネルの設定は変えない。両方とも既定で表示する。アダプターにこの接続がなければボタンを追加しない。切り戻しは workbench と code-views の固定依存を導入前の版へ戻して再ビルドする。
246
+
243
247
  ## デバッガーのタブ
244
248
 
245
249
  `attachDebuggerPanel(debugger, {document, vm})` は、デバッガーアドオンのウィンドウを Dockview のタブとして開く。ホストはアドオンのウィンドウ要素、アドオン自身の表示切り替え関数、GUI の言語を返す関数を渡す。ワークスペースがパネルを受け付けるときは「デバッガー」タブで開き、タブとデバッガーの開閉を連動させる。受け付けないときは従来どおり浮動ウィンドウのままにする。タブは一時パネルとして扱い、保存するレイアウトには含めない。
@@ -8,7 +8,7 @@ import type { WorkspaceLayoutStore, WorkspaceProjectIdentity } from './workspace
8
8
  import type { ProjectScreenState } from './project-screen-state.ts';
9
9
  import type { SpriteVariableEdit, SpriteVariableEditError } from '@kubohiroya/turbowarp-plus-editor-project-model/sprite-variable-edit';
10
10
  import type { MessageRenameError } from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-message-pane';
11
- import type { FunctionKind, FunctionPaneData, MountFunctionEditor, OpenScriptOptions, SpriteFunction, SpriteHatScript } from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-function-pane';
11
+ import type { FunctionKind, FunctionPaneData, FunctionRelationVisibility, MountFunctionEditor, OpenScriptOptions, ScriptEndpoint, SpriteFunction, SpriteHatScript } from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-function-pane';
12
12
  import type { MessageUse, ProjectMessage, TargetMessages } from '@kubohiroya/turbowarp-plus-editor-project-model/project-messages';
13
13
  export { getDocumentWorkspace } from './document-workspace.ts';
14
14
  export { createWorkspaceLayoutStore, workspaceLayoutDatabase, workspaceLayoutLimit } from './workspace-layout-store.ts';
@@ -53,6 +53,12 @@ export interface SpriteTabView {
53
53
  readonly groupActive: boolean;
54
54
  }
55
55
  export interface SpriteTabAdapter<Snapshot = unknown> {
56
+ /** Optional per-pane filters supplied by the code view owner. */
57
+ relations?: {
58
+ getVisibility(paneId: string): FunctionRelationVisibility;
59
+ setVisibility(paneId: string, value: FunctionRelationVisibility): void;
60
+ subscribe(listener: () => void): () => void;
61
+ };
56
62
  /** Read the state of the mounted surface; the host's selected target may have changed already. */
57
63
  capture(view: SpriteTabView): Snapshot;
58
64
  renderInactive(container: HTMLElement, view: SpriteTabView, snapshot: Snapshot | undefined): void | (() => void);
@@ -123,6 +129,8 @@ interface TabOptions<Snapshot = unknown> {
123
129
  interface ToolbarActions {
124
130
  activate(): void;
125
131
  setSection(section: number): void;
132
+ /** Controls for the displayed section, separate from the rail's section tabs. */
133
+ sectionControls?: React.ReactNode;
126
134
  }
127
135
  interface ToolbarSlot {
128
136
  view: SpriteTabView;
@@ -220,6 +228,8 @@ type SpriteTabsProps<Snapshot> = Omit<TabOptions<Snapshot>, 'activateSection' |
220
228
  * `options.block` asks to show one block, such as a call picked in the list of a function's uses.
221
229
  */
222
230
  openScript?(targetId: string, hat: SpriteHatScript, options?: OpenScriptOptions): void;
231
+ /** Open a script chosen in the relationship graph, including one on another target. */
232
+ openRelationScript?(endpoint: ScriptEndpoint): void;
223
233
  /** The function or hat script shown beside the sprite, which the list of hats and functions highlights. */
224
234
  selectedScript?: {
225
235
  targetId: string;
@@ -10,7 +10,7 @@ import { projectFolderIconPath } from "./drawer-views.js";
10
10
  import { dockPopoutGroups, positionOnScreen, readWorkspaceLayout, workspaceWithoutTransientPanels } from "./workspace-layout.js";
11
11
  import { createWorkspaceLayoutStore } from "./workspace-layout-store.js";
12
12
  import { SpriteMessagePane } from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-message-pane';
13
- import { functionLabel, SpriteFunctionPane } from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-function-pane';
13
+ import { FunctionFlowToggle, FunctionRelationToggles, functionLabel, SpriteFunctionPane } from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-function-pane';
14
14
  import { createTargetTabMenuItem, spriteRenameLabel } from "./target-tab-menu.js";
15
15
  export { getDocumentWorkspace } from "./document-workspace.js";
16
16
  export { createWorkspaceLayoutStore, workspaceLayoutDatabase, workspaceLayoutLimit } from "./workspace-layout-store.js";
@@ -1497,8 +1497,18 @@ function SpriteTabs(props) {
1497
1497
  });
1498
1498
  const [toolbarSlots, setToolbarSlots] = React.useState([]);
1499
1499
  const [assetPreviewSlots, setAssetPreviewSlots] = React.useState([]);
1500
+ const [, refreshCodeRelations] = React.useReducer(value => value + 1, 0);
1501
+ const codeRelations = props.viewAdapter?.relations;
1502
+ React.useLayoutEffect(() => codeRelations?.subscribe(refreshCodeRelations), [codeRelations]);
1500
1503
  // The functions pane remounts when its view switches sections; keep the view, order and flow each view chose.
1501
- const [functionSettings] = React.useState(() => new Map());
1504
+ const [functionSettings, setFunctionSettings] = React.useState(() => new Map());
1505
+ const changeFunctionSettings = (id, patch) => setFunctionSettings(previous => {
1506
+ const current = previous.get(id) ?? {};
1507
+ const next = { ...current, ...patch };
1508
+ if (Object.keys(next).every(key => current[key] === next[key]))
1509
+ return previous;
1510
+ return new Map(previous).set(id, next);
1511
+ });
1502
1512
  const controller = React.useRef(null);
1503
1513
  const hasVariables = Boolean(props.getVariables);
1504
1514
  const hasMessages = Boolean(props.getMessages);
@@ -1584,14 +1594,37 @@ function SpriteTabs(props) {
1584
1594
  };
1585
1595
  return React.createElement('div', { className: props.className,
1586
1596
  'data-multi-view': props.enabled && props.multiView || undefined }, React.createElement('div', { ref: root, onClick: isolateDockviewTabs, onKeyDown: isolateDockviewTabs }), React.createElement('div', { ref: parking, hidden: true }), createPortal(React.createElement(React.Fragment, null, props.multiView && props.getVariables ? React.createElement('div', { hidden: true }, props.children) : props.children, React.createElement('div', { ref: sections, className: 'tw-plus-sprite-tab-sections' })), content), toolbarSlots.map(({ view, element }) => {
1597
+ const currentSection = spriteEditorSections[view.section] ?? 'code';
1598
+ const sectionControls = currentSection === 'calls' && props.getFunctions ? React.createElement(React.Fragment, null, React.createElement(FunctionFlowToggle, {
1599
+ locale: props.locale,
1600
+ value: functionSettings.get(view.id)?.direction ?? 'LR',
1601
+ onChange: (direction) => {
1602
+ workspace?.activateView(view.id);
1603
+ changeFunctionSettings(view.id, { direction });
1604
+ }
1605
+ }), React.createElement(FunctionRelationToggles, {
1606
+ locale: props.locale,
1607
+ value: functionSettings.get(view.id)?.relationVisibility ?? { function: true, message: true },
1608
+ onChange: (relationVisibility) => {
1609
+ workspace?.activateView(view.id);
1610
+ changeFunctionSettings(view.id, { relationVisibility });
1611
+ }
1612
+ })) : currentSection === 'code' && codeRelations ? React.createElement(FunctionRelationToggles, {
1613
+ locale: props.locale,
1614
+ value: codeRelations.getVisibility(view.id),
1615
+ onChange: (visibility) => {
1616
+ workspace?.activateView(view.id);
1617
+ codeRelations.setVisibility(view.id, visibility);
1618
+ }
1619
+ }) : undefined;
1587
1620
  const actions = {
1588
1621
  activate: () => { workspace?.activateView(view.id); },
1589
1622
  setSection: (section) => {
1590
1623
  workspace?.setViewSection(view.id, section);
1591
1624
  workspace?.activateView(view.id);
1592
- }
1625
+ },
1626
+ sectionControls
1593
1627
  };
1594
- const currentSection = spriteEditorSections[view.section] ?? 'code';
1595
1628
  const toolbar = props.renderToolbar?.(view, actions) ?? (props.getVariables &&
1596
1629
  React.createElement(SpriteEditorToolbar, {
1597
1630
  viewId: view.id, locale: props.locale, section: currentSection, isStage: view.isStage,
@@ -1600,6 +1633,7 @@ function SpriteTabs(props) {
1600
1633
  availableSections: spriteEditorSections.filter(section => (section !== 'messages' || Boolean(props.getMessages)) &&
1601
1634
  (section !== 'functions' && section !== 'calls' || Boolean(props.getFunctions))),
1602
1635
  actions: view.active && currentSection !== 'variables' ? props.activeTools : undefined,
1636
+ sectionControls,
1603
1637
  onSectionChange: section => actions.setSection(spriteEditorSections.indexOf(section)),
1604
1638
  search: {
1605
1639
  onFocus: actions.activate,
@@ -1665,12 +1699,15 @@ function SpriteTabs(props) {
1665
1699
  kind: 'functions', view: kind === 'calls' ? 'graph' : 'list',
1666
1700
  locale: props.locale, editable, data: props.getFunctions(targetId),
1667
1701
  defaultSettings: functionSettings.get(id),
1668
- onSettingsChange: (settings) => functionSettings.set(id, settings),
1702
+ direction: functionSettings.get(id)?.direction ?? 'LR',
1703
+ relationVisibility: functionSettings.get(id)?.relationVisibility,
1704
+ onSettingsChange: (settings) => changeFunctionSettings(id, settings),
1669
1705
  mountEditor: props.mountFunctionEditor,
1670
1706
  onOpenFunction: props.openFunction &&
1671
1707
  ((fn, options) => props.openFunction(targetId, fn, options)),
1672
1708
  onOpenScript: props.openScript &&
1673
1709
  ((hat, options) => props.openScript(targetId, hat, options)),
1710
+ onOpenRelationScript: props.openRelationScript,
1674
1711
  selectedId: props.selectedScript?.targetId === targetId ? props.selectedScript.id : undefined,
1675
1712
  onCreate: props.createFunction && (async (functionKind, name) => {
1676
1713
  const created = await props.createFunction(targetId, functionKind, name);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-plus-editor-workbench",
3
- "version": "0.25.0",
3
+ "version": "0.27.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",
@@ -158,7 +158,7 @@
158
158
  },
159
159
  "dependencies": {
160
160
  "@kubohiroya/turbowarp-plus-editor-project-model": "0.2.0",
161
- "@kubohiroya/turbowarp-plus-editor-sprite-panes": "0.5.0",
161
+ "@kubohiroya/turbowarp-plus-editor-sprite-panes": "0.10.0",
162
162
  "@kubohiroya/turbowarp-script-transfer": "0.1.5",
163
163
  "dockview": "8.8.3"
164
164
  },
@@ -136,7 +136,7 @@
136
136
  }
137
137
 
138
138
  /* The layout menu can hide the section buttons at the left of every sprite tab. */
139
- .tw-plus-sprite-tab-toolbar[data-sections-hidden] .tw-plus-sprite-toolbar-sections {
139
+ .tw-plus-sprite-tab-toolbar[data-sections-hidden] :is(.tw-plus-sprite-toolbar-rail, .tw-plus-sprite-toolbar-sections) {
140
140
  display: none;
141
141
  }
142
142
 
@@ -23,8 +23,9 @@ import type {ProjectScreenState, SavedScreenState} from './project-screen-state.
23
23
  import type {SpriteVariableEdit, SpriteVariableEditError} from '@kubohiroya/turbowarp-plus-editor-project-model/sprite-variable-edit';
24
24
  import {SpriteMessagePane} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-message-pane';
25
25
  import type {MessageRenameError} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-message-pane';
26
- import {functionLabel, SpriteFunctionPane} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-function-pane';
27
- import type {FunctionKind, FunctionPaneData, FunctionPaneSettings, MountFunctionEditor, OpenScriptOptions, SpriteFunction, SpriteHatScript} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-function-pane';
26
+ import {FunctionFlowToggle, FunctionRelationToggles, functionLabel, SpriteFunctionPane} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-function-pane';
27
+ import type {CallGraphDirection, FunctionKind, FunctionPaneData, FunctionPaneSettings, FunctionRelationVisibility,
28
+ MountFunctionEditor, OpenScriptOptions, ScriptEndpoint, SpriteFunction, SpriteHatScript} from '@kubohiroya/turbowarp-plus-editor-sprite-panes/sprite-function-pane';
28
29
  import type {MessageUse, ProjectMessage, TargetMessages} from '@kubohiroya/turbowarp-plus-editor-project-model/project-messages';
29
30
  import {createTargetTabMenuItem, spriteRenameLabel} from './target-tab-menu.ts';
30
31
 
@@ -71,6 +72,12 @@ export interface SpriteTabView {
71
72
  }
72
73
 
73
74
  export interface SpriteTabAdapter<Snapshot = unknown> {
75
+ /** Optional per-pane filters supplied by the code view owner. */
76
+ relations?: {
77
+ getVisibility(paneId: string): FunctionRelationVisibility;
78
+ setVisibility(paneId: string, value: FunctionRelationVisibility): void;
79
+ subscribe(listener: () => void): () => void;
80
+ };
74
81
  /** Read the state of the mounted surface; the host's selected target may have changed already. */
75
82
  capture(view: SpriteTabView): Snapshot;
76
83
  renderInactive(container: HTMLElement, view: SpriteTabView, snapshot: Snapshot | undefined): void | (() => void);
@@ -194,6 +201,8 @@ interface TabOptions<Snapshot = unknown> {
194
201
  interface ToolbarActions {
195
202
  activate(): void;
196
203
  setSection(section: number): void;
204
+ /** Controls for the displayed section, separate from the rail's section tabs. */
205
+ sectionControls?: React.ReactNode;
197
206
  }
198
207
 
199
208
  interface ToolbarSlot {
@@ -1566,6 +1575,8 @@ type SpriteTabsProps<Snapshot> = Omit<TabOptions<Snapshot>, 'activateSection' |
1566
1575
  * `options.block` asks to show one block, such as a call picked in the list of a function's uses.
1567
1576
  */
1568
1577
  openScript?(targetId: string, hat: SpriteHatScript, options?: OpenScriptOptions): void;
1578
+ /** Open a script chosen in the relationship graph, including one on another target. */
1579
+ openRelationScript?(endpoint: ScriptEndpoint): void;
1569
1580
  /** The function or hat script shown beside the sprite, which the list of hats and functions highlights. */
1570
1581
  selectedScript?: {targetId: string; id: string};
1571
1582
  /**
@@ -1629,8 +1640,17 @@ function SpriteTabs<Snapshot>(props: SpriteTabsProps<Snapshot>) {
1629
1640
  });
1630
1641
  const [toolbarSlots, setToolbarSlots] = React.useState<readonly ToolbarSlot[]>([]);
1631
1642
  const [assetPreviewSlots, setAssetPreviewSlots] = React.useState<readonly AssetPreviewSlot[]>([]);
1643
+ const [, refreshCodeRelations] = React.useReducer(value => value + 1, 0);
1644
+ const codeRelations = props.viewAdapter?.relations;
1645
+ React.useLayoutEffect(() => codeRelations?.subscribe(refreshCodeRelations), [codeRelations]);
1632
1646
  // The functions pane remounts when its view switches sections; keep the view, order and flow each view chose.
1633
- const [functionSettings] = React.useState(() => new Map<string, FunctionPaneSettings>());
1647
+ const [functionSettings, setFunctionSettings] = React.useState(() => new Map<string, Partial<FunctionPaneSettings>>());
1648
+ const changeFunctionSettings = (id: string, patch: Partial<FunctionPaneSettings>) => setFunctionSettings(previous => {
1649
+ const current = previous.get(id) ?? {};
1650
+ const next = {...current, ...patch};
1651
+ if (Object.keys(next).every(key => current[key] === next[key])) return previous;
1652
+ return new Map(previous).set(id, next);
1653
+ });
1634
1654
  const controller = React.useRef<SpriteTabsController<Snapshot>>(null);
1635
1655
  const hasVariables = Boolean(props.getVariables);
1636
1656
  const hasMessages = Boolean(props.getMessages);
@@ -1719,14 +1739,39 @@ function SpriteTabs<Snapshot>(props: SpriteTabsProps<Snapshot>) {
1719
1739
  createPortal(React.createElement(React.Fragment, null,
1720
1740
  props.multiView && props.getVariables ? React.createElement('div', {hidden: true}, props.children) : props.children,
1721
1741
  React.createElement('div', {ref: sections, className: 'tw-plus-sprite-tab-sections'})), content), toolbarSlots.map(({view, element}) => {
1742
+ const currentSection = spriteEditorSections[view.section] ?? 'code';
1743
+ const sectionControls = currentSection === 'calls' && props.getFunctions ? React.createElement(React.Fragment, null,
1744
+ React.createElement(FunctionFlowToggle, {
1745
+ locale: props.locale,
1746
+ value: functionSettings.get(view.id)?.direction ?? 'LR',
1747
+ onChange: (direction: CallGraphDirection) => {
1748
+ workspace?.activateView(view.id);
1749
+ changeFunctionSettings(view.id, {direction});
1750
+ }
1751
+ }),
1752
+ React.createElement(FunctionRelationToggles, {
1753
+ locale: props.locale,
1754
+ value: functionSettings.get(view.id)?.relationVisibility ?? {function: true, message: true},
1755
+ onChange: (relationVisibility: FunctionRelationVisibility) => {
1756
+ workspace?.activateView(view.id);
1757
+ changeFunctionSettings(view.id, {relationVisibility});
1758
+ }
1759
+ })) : currentSection === 'code' && codeRelations ? React.createElement(FunctionRelationToggles, {
1760
+ locale: props.locale,
1761
+ value: codeRelations.getVisibility(view.id),
1762
+ onChange: (visibility: FunctionRelationVisibility) => {
1763
+ workspace?.activateView(view.id);
1764
+ codeRelations.setVisibility(view.id, visibility);
1765
+ }
1766
+ }) : undefined;
1722
1767
  const actions = {
1723
1768
  activate: () => { workspace?.activateView(view.id); },
1724
1769
  setSection: (section: number) => {
1725
1770
  workspace?.setViewSection(view.id, section);
1726
1771
  workspace?.activateView(view.id);
1727
- }
1772
+ },
1773
+ sectionControls
1728
1774
  };
1729
- const currentSection = spriteEditorSections[view.section] ?? 'code';
1730
1775
  const toolbar = props.renderToolbar?.(view, actions) ?? (props.getVariables &&
1731
1776
  React.createElement(SpriteEditorToolbar, {
1732
1777
  viewId: view.id, locale: props.locale, section: currentSection, isStage: view.isStage,
@@ -1736,6 +1781,7 @@ function SpriteTabs<Snapshot>(props: SpriteTabsProps<Snapshot>) {
1736
1781
  (section !== 'messages' || Boolean(props.getMessages)) &&
1737
1782
  (section !== 'functions' && section !== 'calls' || Boolean(props.getFunctions))),
1738
1783
  actions: view.active && currentSection !== 'variables' ? props.activeTools : undefined,
1784
+ sectionControls,
1739
1785
  onSectionChange: section => actions.setSection(spriteEditorSections.indexOf(section)),
1740
1786
  search: {
1741
1787
  onFocus: actions.activate,
@@ -1793,12 +1839,15 @@ function SpriteTabs<Snapshot>(props: SpriteTabsProps<Snapshot>) {
1793
1839
  kind: 'functions', view: kind === 'calls' ? 'graph' : 'list',
1794
1840
  locale: props.locale, editable, data: props.getFunctions!(targetId),
1795
1841
  defaultSettings: functionSettings.get(id),
1796
- onSettingsChange: (settings: FunctionPaneSettings) => functionSettings.set(id, settings),
1842
+ direction: functionSettings.get(id)?.direction ?? 'LR',
1843
+ relationVisibility: functionSettings.get(id)?.relationVisibility,
1844
+ onSettingsChange: (settings: FunctionPaneSettings) => changeFunctionSettings(id, settings),
1797
1845
  mountEditor: props.mountFunctionEditor,
1798
1846
  onOpenFunction: props.openFunction &&
1799
1847
  ((fn: SpriteFunction, options?: OpenScriptOptions) => props.openFunction!(targetId, fn, options)),
1800
1848
  onOpenScript: props.openScript &&
1801
1849
  ((hat: SpriteHatScript, options?: OpenScriptOptions) => props.openScript!(targetId, hat, options)),
1850
+ onOpenRelationScript: props.openRelationScript,
1802
1851
  selectedId: props.selectedScript?.targetId === targetId ? props.selectedScript.id : undefined,
1803
1852
  onCreate: props.createFunction && (async (functionKind: FunctionKind, name: string) => {
1804
1853
  const created = await props.createFunction!(targetId, functionKind, name);