@kubohiroya/turbowarp-plus-editor-workbench 0.27.1 → 0.28.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.ja.md CHANGED
@@ -242,6 +242,10 @@ Editor のルートから、`site/source.json` の GUI を `npm run build:pages`
242
242
 
243
243
  スプライトの「呼び出し関係」では、図の方向を切り替える LR/TD と、関数・メッセージの表示を切り替えるボタンを縦ツールバーの下端に置く。方向と表示の選択はビューごとに管理し、分割した別ビューの選択を変えない。ホストが `renderToolbar` でツールバーを描く場合は、受け取る `actions.sectionControls` を `SpriteEditorToolbar` の `sectionControls` に渡す。図で選んだスクリプトは `openRelationScript` で開き、ホストが対象のスプライトとブロックへ移動する。
244
244
 
245
+ `createEditorTabLayout` は自由配置のブロックメニューから、対象を含むスクリプトを右の個別編集ビューで開く。一覧を開く項目は左をハット・関数一覧へ、呼び出し関係を開く項目は左を図へ切り替えて対象を中央に置く。
246
+
247
+ 外部のメニューから対象スクリプトへ中央フォーカスする場合は、`selectedScript` の `{targetId, id}` に更新するたびに異なる `focusRequest` の数値を添える。対象のペインの `SpriteFunctionPane` へ同じ要求を渡し、関係図の移動や強調は図を所有するパッケージが行う。切り戻す場合は `focusRequest` を渡さない。
248
+
245
249
  コードペインのアダプターに `relations` がある場合、「自由配置」にも同じ関数・メッセージの2ボタンを縦ツールバー下端に置く。表示状態の所有者はコードペインで、`getVisibility(paneId)`・`setVisibility(paneId, value)`・`subscribe(listener)` を使って描画へ反映する。関数だけ、メッセージだけ、両方、両方非表示を選べ、分割した別のペインや呼び出し関係パネルの設定は変えない。両方とも既定で表示する。アダプターにこの接続がなければボタンを追加しない。切り戻しは workbench と code-views の固定依存を導入前の版へ戻して再ビルドする。
246
250
 
247
251
  ## デバッガーのタブ
@@ -1,5 +1,7 @@
1
1
  /** Give the browser a frame before starting work that may block its main thread. */
2
- export declare function withWaitCursor<T>(documents: Iterable<Document>, run: () => T): Promise<Awaited<T>>;
2
+ export declare function withWaitCursor<T>(documents: Iterable<Document>, run: () => T, { releaseAfterPaint }?: {
3
+ releaseAfterPaint?: boolean;
4
+ }): Promise<Awaited<T>>;
3
5
  /** Temporarily restore the normal cursor while an operation needs an answer. */
4
6
  export declare function withoutWaitCursor<T>(document: Document | undefined, ask: () => T): Promise<Awaited<T>>;
5
7
  interface Target {
@@ -38,7 +38,7 @@ function afterPaint(document) {
38
38
  });
39
39
  }
40
40
  /** Give the browser a frame before starting work that may block its main thread. */
41
- export async function withWaitCursor(documents, run) {
41
+ export async function withWaitCursor(documents, run, { releaseAfterPaint = false } = {}) {
42
42
  const visible = [...new Set(documents)].filter(document => document?.head && document.defaultView && !document.defaultView.closed);
43
43
  const release = visible.map(holdCursor);
44
44
  try {
@@ -46,7 +46,13 @@ export async function withWaitCursor(documents, run) {
46
46
  return await run();
47
47
  }
48
48
  finally {
49
- release.forEach(done => done());
49
+ const finish = () => release.forEach(done => done());
50
+ // Resolving the project load lets the host mount its initial code view. Keep the already-painted
51
+ // wait cursor through that synchronous work without delaying the host's load continuation.
52
+ if (releaseAfterPaint)
53
+ void Promise.all(visible.map(afterPaint)).then(finish, finish);
54
+ else
55
+ finish();
50
56
  }
51
57
  }
52
58
  /** Temporarily restore the normal cursor while an operation needs an answer. */
@@ -168,7 +168,7 @@ export function createEditorTabLayout({ desktopCodeEnabled, openDesktopCode, sty
168
168
  const scriptViewRef = React.useRef(scriptView);
169
169
  scriptViewRef.current = scriptView;
170
170
  // A function or hat script picked in the functions sections shows there. `block` asks to show one of its blocks.
171
- const openScriptView = (targetId, id, block) => {
171
+ const openScriptView = (targetId, id, block, centerInCalls = false) => {
172
172
  const views = spriteTabs.controller.current;
173
173
  if (!views)
174
174
  return;
@@ -202,7 +202,8 @@ export function createEditorTabLayout({ desktopCodeEnabled, openDesktopCode, sty
202
202
  }));
203
203
  views.setViewSection(shown, codeTab);
204
204
  views.activateView(shown);
205
- setSelectedScript(current => current?.targetId === targetId && current.id === id ? current : { targetId, id });
205
+ setSelectedScript(current => !centerInCalls && current?.targetId === targetId && current.id === id ? current :
206
+ { targetId, id, ...(centerInCalls && { focusRequest: (current?.focusRequest ?? 0) + 1 }) });
206
207
  if (block) {
207
208
  requestAnimationFrame(() => {
208
209
  const workspace = getScratchBlocks()?.getMainWorkspace();
@@ -429,6 +430,17 @@ export function createEditorTabLayout({ desktopCodeEnabled, openDesktopCode, sty
429
430
  if (!fn)
430
431
  return;
431
432
  openScriptViewRef.current(target.id, fn.id);
433
+ },
434
+ scriptEditor: {
435
+ vm, locale,
436
+ open(scriptId, blockId, section) {
437
+ const views = spriteTabs.controller.current;
438
+ const current = views?.currentView();
439
+ if (!current || !vm.editingTarget)
440
+ return;
441
+ views.setViewSection(current.id, spriteEditorSections.indexOf(section));
442
+ openScriptViewRef.current(vm.editingTarget.id, scriptId, blockId, section === 'calls');
443
+ }
432
444
  }
433
445
  });
434
446
  };
@@ -30,7 +30,7 @@ export function createProjectTools({ installEditorExtensionHost, installProjectP
30
30
  const installProjectToolsHost = (vm, settings = {}, enabled = PROJECT_TOOLS_ENABLED) => {
31
31
  const diagnostics = createProjectDiagnostics();
32
32
  const document = settings.document || globalThis.document;
33
- const runProjectLoad = document ? (run) => withWaitCursor([document], run) : undefined;
33
+ const runProjectLoad = document ? (run) => withWaitCursor([document], run, { releaseAfterPaint: true }) : undefined;
34
34
  const host = installEditorExtensionHost(vm, { ...settings, showDiagnostics: false, runProjectLoad,
35
35
  projectArchives: editorProjectArchives,
36
36
  captureProjectProgress: () => captureProjectLoad(vm),
@@ -234,6 +234,7 @@ type SpriteTabsProps<Snapshot> = Omit<TabOptions<Snapshot>, 'activateSection' |
234
234
  selectedScript?: {
235
235
  targetId: string;
236
236
  id: string;
237
+ focusRequest?: number;
237
238
  };
238
239
  /**
239
240
  * Make a new function of this name in the target: a standard custom block, whose block text is the name,
@@ -1709,6 +1709,7 @@ function SpriteTabs(props) {
1709
1709
  ((hat, options) => props.openScript(targetId, hat, options)),
1710
1710
  onOpenRelationScript: props.openRelationScript,
1711
1711
  selectedId: props.selectedScript?.targetId === targetId ? props.selectedScript.id : undefined,
1712
+ focusRequest: props.selectedScript?.targetId === targetId ? props.selectedScript.focusRequest : undefined,
1712
1713
  onCreate: props.createFunction && (async (functionKind, name) => {
1713
1714
  const created = await props.createFunction(targetId, functionKind, name);
1714
1715
  // Show the new function now rather than at the next project change.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-plus-editor-workbench",
3
- "version": "0.27.1",
3
+ "version": "0.28.1",
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",
@@ -212,7 +212,7 @@
212
212
  "@turbowarp/jszip": "3.12.0",
213
213
  "@kubohiroya/turbowarp-extension-loader": "0.11.1",
214
214
  "@kubohiroya/turbowarp-plus-editor-project-folder": "0.20.1",
215
- "@kubohiroya/turbowarp-plus-editor-code-views": "0.21.2",
215
+ "@kubohiroya/turbowarp-plus-editor-code-views": "0.22.1",
216
216
  "@kubohiroya/turbowarp-extension-security-dialog": "0.9.0"
217
217
  },
218
218
  "repository": {
@@ -221,7 +221,7 @@
221
221
  },
222
222
  "dependencies": {
223
223
  "@kubohiroya/turbowarp-plus-editor-project-model": "0.2.0",
224
- "@kubohiroya/turbowarp-plus-editor-sprite-panes": "0.10.1",
224
+ "@kubohiroya/turbowarp-plus-editor-sprite-panes": "0.11.1",
225
225
  "@kubohiroya/turbowarp-script-transfer": "0.1.5",
226
226
  "dockview": "8.8.3"
227
227
  },
@@ -234,7 +234,7 @@
234
234
  "@turbowarp/jszip": ">=3.12.0 <4",
235
235
  "@kubohiroya/turbowarp-extension-loader": ">=0.11.1 <0.12.0",
236
236
  "@kubohiroya/turbowarp-plus-editor-project-folder": ">=0.20.1 <0.21.0",
237
- "@kubohiroya/turbowarp-plus-editor-code-views": ">=0.21.2 <0.22.0",
237
+ "@kubohiroya/turbowarp-plus-editor-code-views": ">=0.22.0 <0.23.0",
238
238
  "@kubohiroya/turbowarp-extension-security-dialog": ">=0.9.0 <0.10.0"
239
239
  },
240
240
  "peerDependenciesMeta": {
@@ -38,14 +38,19 @@ function afterPaint(document: Document) {
38
38
  }
39
39
 
40
40
  /** Give the browser a frame before starting work that may block its main thread. */
41
- export async function withWaitCursor<T>(documents: Iterable<Document>, run: () => T): Promise<Awaited<T>> {
41
+ export async function withWaitCursor<T>(documents: Iterable<Document>, run: () => T,
42
+ {releaseAfterPaint = false}: {releaseAfterPaint?: boolean} = {}): Promise<Awaited<T>> {
42
43
  const visible = [...new Set(documents)].filter(document => document?.head && document.defaultView && !document.defaultView.closed);
43
44
  const release = visible.map(holdCursor);
44
45
  try {
45
46
  await Promise.all(visible.map(afterPaint));
46
47
  return await run();
47
48
  } finally {
48
- release.forEach(done => done());
49
+ const finish = () => release.forEach(done => done());
50
+ // Resolving the project load lets the host mount its initial code view. Keep the already-painted
51
+ // wait cursor through that synchronous work without delaying the host's load continuation.
52
+ if (releaseAfterPaint) void Promise.all(visible.map(afterPaint)).then(finish, finish);
53
+ else finish();
49
54
  }
50
55
  }
51
56
 
@@ -211,14 +211,14 @@ export function createEditorTabLayout({desktopCodeEnabled, openDesktopCode, styl
211
211
  get screenState() { return projectScreenState(vm); }
212
212
  } : undefined, [multiView, vm]);
213
213
  // The script shown beside the sprite, which the list of hats and functions highlights.
214
- const [selectedScript, setSelectedScript] = React.useState<{targetId: string; id: string}>();
214
+ const [selectedScript, setSelectedScript] = React.useState<{targetId: string; id: string; focusRequest?: number}>();
215
215
  // The code view beside the sprite that shows one script at a time: the code area itself, without the other
216
216
  // scripts and without the section buttons.
217
217
  const [scriptView, setScriptView] = React.useState<{viewId: string; targetId: string}>();
218
218
  const scriptViewRef = React.useRef(scriptView);
219
219
  scriptViewRef.current = scriptView;
220
220
  // A function or hat script picked in the functions sections shows there. `block` asks to show one of its blocks.
221
- const openScriptView = (targetId: string, id: string, block?: string) => {
221
+ const openScriptView = (targetId: string, id: string, block?: string, centerInCalls = false) => {
222
222
  const views = spriteTabs.controller.current;
223
223
  if (!views) return;
224
224
  let viewId = scriptViewRef.current?.targetId === targetId &&
@@ -249,7 +249,8 @@ export function createEditorTabLayout({desktopCodeEnabled, openDesktopCode, styl
249
249
  }));
250
250
  views.setViewSection(shown, codeTab);
251
251
  views.activateView(shown);
252
- setSelectedScript(current => current?.targetId === targetId && current.id === id ? current : {targetId, id});
252
+ setSelectedScript(current => !centerInCalls && current?.targetId === targetId && current.id === id ? current :
253
+ {targetId, id, ...(centerInCalls && {focusRequest: (current?.focusRequest ?? 0) + 1})});
253
254
  if (block) {
254
255
  requestAnimationFrame(() => {
255
256
  const workspace = getScratchBlocks()?.getMainWorkspace();
@@ -469,6 +470,16 @@ export function createEditorTabLayout({desktopCodeEnabled, openDesktopCode, styl
469
470
  const fn = target && readTargetFunctions(target).functions.find(item => item.id === functionId);
470
471
  if (!fn) return;
471
472
  openScriptViewRef.current(target.id, fn.id);
473
+ },
474
+ scriptEditor: {
475
+ vm, locale,
476
+ open(scriptId, blockId, section) {
477
+ const views = spriteTabs.controller.current;
478
+ const current = views?.currentView();
479
+ if (!current || !vm.editingTarget) return;
480
+ views.setViewSection(current.id, spriteEditorSections.indexOf(section));
481
+ openScriptViewRef.current(vm.editingTarget.id, scriptId, blockId, section === 'calls');
482
+ }
472
483
  }
473
484
  });
474
485
  };
@@ -51,7 +51,8 @@ export function createProjectTools({installEditorExtensionHost, installProjectPr
51
51
  const installProjectToolsHost = (vm, settings: Parameters<typeof installEditorExtensionHost>[1] & Parameters<typeof installProjectProperties>[1] = {}, enabled = PROJECT_TOOLS_ENABLED) => {
52
52
  const diagnostics = createProjectDiagnostics();
53
53
  const document = settings.document || globalThis.document;
54
- const runProjectLoad = document ? <T>(run: () => Promise<T>) => withWaitCursor([document], run) : undefined;
54
+ const runProjectLoad = document ? <T>(run: () => Promise<T>) =>
55
+ withWaitCursor([document], run, {releaseAfterPaint: true}) : undefined;
55
56
  const host = installEditorExtensionHost(vm, {...settings, showDiagnostics: false, runProjectLoad,
56
57
  projectArchives: editorProjectArchives,
57
58
  captureProjectProgress: () => captureProjectLoad(vm),
@@ -1578,7 +1578,7 @@ type SpriteTabsProps<Snapshot> = Omit<TabOptions<Snapshot>, 'activateSection' |
1578
1578
  /** Open a script chosen in the relationship graph, including one on another target. */
1579
1579
  openRelationScript?(endpoint: ScriptEndpoint): void;
1580
1580
  /** The function or hat script shown beside the sprite, which the list of hats and functions highlights. */
1581
- selectedScript?: {targetId: string; id: string};
1581
+ selectedScript?: {targetId: string; id: string; focusRequest?: number};
1582
1582
  /**
1583
1583
  * Make a new function of this name in the target: a standard custom block, whose block text is the name,
1584
1584
  * or a TurboWarp-Plus named function. Resolves with the id of the new hat, or with nothing when nothing
@@ -1849,6 +1849,7 @@ function SpriteTabs<Snapshot>(props: SpriteTabsProps<Snapshot>) {
1849
1849
  ((hat: SpriteHatScript, options?: OpenScriptOptions) => props.openScript!(targetId, hat, options)),
1850
1850
  onOpenRelationScript: props.openRelationScript,
1851
1851
  selectedId: props.selectedScript?.targetId === targetId ? props.selectedScript.id : undefined,
1852
+ focusRequest: props.selectedScript?.targetId === targetId ? props.selectedScript.focusRequest : undefined,
1852
1853
  onCreate: props.createFunction && (async (functionKind: FunctionKind, name: string) => {
1853
1854
  const created = await props.createFunction!(targetId, functionKind, name);
1854
1855
  // Show the new function now rather than at the next project change.