@kubohiroya/turbowarp-plus-editor-code-views 0.21.3 → 0.22.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 +12 -2
- package/dist/code-pane.d.ts +7 -1
- package/dist/code-pane.js +45 -3
- package/dist/context-menu-icons.d.ts +5 -3
- package/dist/context-menu-icons.js +6 -2
- package/dist/script-arrows.js +109 -47
- package/dist/script-layout-view.js +123 -6
- package/dist/script-layout-workspace.js +7 -2
- package/dist/script-layout.d.ts +1 -1
- package/dist/script-layout.js +3 -3
- package/dist/script-projection.d.ts +8 -0
- package/dist/script-projection.js +10 -0
- package/dist/script-view-menu.d.ts +1 -0
- package/dist/script-view-menu.js +4 -2
- package/dist/serial-script-editor.d.ts +4 -0
- package/dist/serial-script-editor.js +43 -0
- package/dist/workspace-overview.js +67 -25
- package/dist/workspace.d.ts +1 -0
- package/dist/workspace.js +3 -2
- package/package.json +1 -1
- package/src/code-pane.ts +41 -3
- package/src/context-menu-icons.ts +8 -2
- package/src/script-arrows.ts +100 -47
- package/src/script-layout-view.ts +115 -6
- package/src/script-layout-workspace.ts +7 -2
- package/src/script-layout.ts +4 -3
- package/src/script-projection.ts +12 -0
- package/src/script-view-menu.ts +5 -2
- package/src/serial-script-editor.ts +41 -0
- package/src/styles.css +85 -24
- package/src/workspace-overview.ts +63 -22
- package/src/workspace.ts +3 -2
package/README.ja.md
CHANGED
|
@@ -10,6 +10,12 @@ TurboWarp Plus Editor のコードの画面。1つの作品と1つの取り消
|
|
|
10
10
|
|
|
11
11
|
ホストが独立したワークスペースを表示する場合は、ルートまたは `./sprite-code-windows` の `fitScriptInWorkspace(workspace, scriptId, ScratchBlocks)` を使える。表示領域やブロックがまだない場合は `false` を返すので、レイアウト後に再試行する。
|
|
12
12
|
|
|
13
|
+
Z/N配置のミニマップは、表示中のスクリプトの並びとスクロール範囲を示す。スクリプトをクリックすると内容の編集画面を開き、閉じた後もZ/N配置を保つ。編集画面では先頭ブロックを固定し、作品に保存する自由配置の座標を動かさない。スクリプト間の余白は64単位以上、画面上で48px以上を確保する。背景の右クリックメニューで「すべて折りたたむ」「折りたたみをすべて解除」を利用できる。
|
|
14
|
+
|
|
15
|
+
Z/N配置内の矢印は、スクリプト群の右外側へ96px以上張り出し、経路を分けて上下に曲がる。左縁の▼/▶ボタンは各スクリプトの上端に並び、クリックやEnter/Spaceで個別に折りたたみを切り替えられる。横スクロール中も左縁に残り、縦スクロールとズームにはスクリプトと一緒に追従する。
|
|
16
|
+
|
|
17
|
+
これらの変更の切り戻しは、本変更を revert して再ビルドする。ホストのパッケージ固定を以前の版へ戻す場合は、機能移管で追加された API との互換性も確認する。自由配置へ切り替えるだけでも元の配置を表示できる。折りたたみは既存の作品内フラグを使用するため、「折りたたみをすべて解除」で解除できる。
|
|
18
|
+
|
|
13
19
|
## 入口
|
|
14
20
|
|
|
15
21
|
| import | 内容 |
|
|
@@ -47,19 +53,23 @@ TurboWarp Plus Editor のコードの画面。1つの作品と1つの取り消
|
|
|
47
53
|
|
|
48
54
|
Editor は GUI の React 16 にこれらを描画するので、React 16.14 以降に対応する。
|
|
49
55
|
|
|
56
|
+
自由配置のブロックの右クリックメニューの先頭に「このスクリプトを個別の画面で編集する」、2番目に「このスクリプトの呼び出し関係を開く」を表示する。途中のブロックや関数呼び出しを選んだ場合も、そのブロックを含むスクリプト全体を開く。ホストは `attachFunctionCallMenu` の `scriptEditor: {vm, locale, open(scriptId, blockId, section)}` を既存の個別編集ペインへ接続する。`section` は先頭の項目では `functions`、2番目では `calls`。左側をハット・関数一覧または中央フォーカスした呼び出し関係にし、右側で編集する。Z/N表示、パレット、読み取り専用、個別編集中の画面には追加しない。既存の「この関数を表示」は呼び出し先を開く項目としてその下に残す。切り戻す場合は `scriptEditor` の接続を外す。
|
|
57
|
+
|
|
50
58
|
## スクリプト間の矢印
|
|
51
59
|
|
|
52
|
-
|
|
60
|
+
コードの背面に、関数呼び出しを紫系の実線、メッセージ送信を橙系の破線で表示する。「送って待つ」は線7・間隔5の破線、「送る」はその半分の線3.5・間隔2.5の細かい破線で区別し、砂時計アイコンは表示しない。通常配置、Z/N 配置、折り畳み、プレビュー、別窓で同じ表現を使う。関数の再帰はスクリプトの外へ回る線で示す。選択・ホバーによる強調は太さと不透明度で行い、関係種別の色・線種は変えない。
|
|
53
61
|
|
|
54
62
|
関数呼び出しとメッセージ送受信は、常に呼び出し元・送信元の右から出て、呼び出し先・受信先の左へ入る。左右の配置が逆でも接続する側を入れ替えない。自己呼び出しもスクリプトの外を回って左側へ戻る。
|
|
55
63
|
|
|
56
64
|
通常の線と矢印の先端は20%の濃さにし、選択・ホバー・ドラッグに関連する線を強調する。ドラッグ開始時に無関係な線だけが急に薄くなることはない。
|
|
57
65
|
|
|
66
|
+
矢印は、始点または終点のブロックの少なくとも一方が画面内にある場合に表示し、両方が画面外なら表示しない。画面外のブロックがネイティブの軽量化で非表示になっても接続位置を保持し、実際の接続位置へ向かう矢印を描く。スクロール・ズームでもこの表示判定を更新する。
|
|
67
|
+
|
|
58
68
|
関係は作品データから読み、折り畳みによって表示から消えた呼び出しも保持する。展開中は呼び出しブロックから、折り畳み中は見えているハットから結ぶ。同じハットと宛先へ重なる呼び出しは件数を表示する。別スプライトや一スクリプト表示の外にある接続先は、画面端の案内から辿れる。変数などで呼び出し先が変わるものは「実行時に決定」と示し、見えていない既定値を宛先とみなさない。
|
|
59
69
|
|
|
60
70
|
接続元または接続先を同じパネル内に描けない矢印は、線・矢印の先端・待機の印・件数を5%の濃さで表示する。ホバー・選択・ドラッグによる強調中も同じ濃さを維持する。
|
|
61
71
|
|
|
62
|
-
|
|
72
|
+
スクリプトをドラッグしている間は、そこへ入る・そこから出る矢印を太く濃くし、画面にある相手のスクリプト全体を薄い背景色で強調する。バウンディングボックスのボーダーは表示しない。関係しない矢印は薄くし、画面外の相手は接続先の案内を強調する。関数とメッセージの色・線種は維持する。折り畳み中も同じように働き、ドラッグの終了・矢印の非表示・画面の破棄で一時的な強調を解除する。移動中に Blockly がブロックを別の SVG へ移しても追従する。
|
|
63
73
|
|
|
64
74
|
`attachDockedScriptLayout` と `attachCodeWorkspace` のプレビュー・関数エディタには自動で付く。VM を持たない表示では、`attachScriptView` に `relations: {getTarget, getRelations, getTargetName, navigate}` を渡す。`getRelations` は親の `createCodeSession` が渡す `scriptRelations`、`getTarget` はその対象の `blocks` を使う。`getTargetName` は既存の対象一覧から名前を返し、同じメッセージを受信する別スプライトを案内で識別できるようにする。投影の受信後は `view.relations.update()` を呼ぶ。関係だけの更新は `relations`、接続先への移動は `relation-navigate`/`relation-focus` で既存の編集回収・対象切り替えを経由する。編集中の窓には履歴の更新のために XML を再読み込みさせない。
|
|
65
75
|
|
package/dist/code-pane.d.ts
CHANGED
|
@@ -89,11 +89,17 @@ export declare function readScriptRelationGraph(targets: readonly RelationTarget
|
|
|
89
89
|
/**
|
|
90
90
|
* Add “Show this function” at the top of the menu of every block that calls a function, in the code area and
|
|
91
91
|
* in the script editors. `find` names the function a block calls, if any; `open` shows it.
|
|
92
|
+
* With `scriptEditor`, free-layout blocks first offer to edit their own containing script.
|
|
92
93
|
*/
|
|
93
|
-
export declare function attachFunctionCallMenu(ScratchBlocks: any, { label, find, open }: {
|
|
94
|
+
export declare function attachFunctionCallMenu(ScratchBlocks: any, { label, find, open, scriptEditor }: {
|
|
94
95
|
label(): string;
|
|
95
96
|
find(blockId: string): string | undefined;
|
|
96
97
|
open(functionId: string): void;
|
|
98
|
+
scriptEditor?: {
|
|
99
|
+
vm: any;
|
|
100
|
+
locale: string;
|
|
101
|
+
open(scriptId: string, blockId: string, section: 'functions' | 'calls'): void;
|
|
102
|
+
};
|
|
97
103
|
}): () => void;
|
|
98
104
|
/** Add a function definition of this name to a target through the code area's bridge. Resolves with the new hat's id. */
|
|
99
105
|
export declare function createFunction(vm: any, targetId: string, kind: 'procedure' | 'named', name: string, options?: {
|
package/dist/code-pane.js
CHANGED
|
@@ -440,24 +440,66 @@ export function readScriptRelationGraph(targets, ScratchBlocks) {
|
|
|
440
440
|
/**
|
|
441
441
|
* Add “Show this function” at the top of the menu of every block that calls a function, in the code area and
|
|
442
442
|
* in the script editors. `find` names the function a block calls, if any; `open` shows it.
|
|
443
|
+
* With `scriptEditor`, free-layout blocks first offer to edit their own containing script.
|
|
443
444
|
*/
|
|
444
|
-
export function attachFunctionCallMenu(ScratchBlocks, { label, find, open }) {
|
|
445
|
+
export function attachFunctionCallMenu(ScratchBlocks, { label, find, open, scriptEditor }) {
|
|
445
446
|
const prototype = ScratchBlocks.BlockSvg.prototype;
|
|
446
447
|
const showContextMenu = prototype.showContextMenu_;
|
|
447
448
|
const patched = function (event) {
|
|
448
449
|
const functionId = this.isInFlyout ? undefined : find(this.id);
|
|
449
|
-
|
|
450
|
+
const target = scriptEditor?.vm.editingTarget;
|
|
451
|
+
const layout = scriptEditor && getDockedScriptLayout(scriptEditor.vm);
|
|
452
|
+
const script = scriptEditor && !this.isInFlyout && !this.workspace.options.readOnly &&
|
|
453
|
+
this.workspace === ScratchBlocks.getMainWorkspace?.() && layout?.view.view === 'free' &&
|
|
454
|
+
layout.canArrange() && !getCodeSession(scriptEditor.vm).bridge?.focusedScript ? this.getRootBlock() : undefined;
|
|
455
|
+
const scriptId = script && target?.blocks._blocks[script.id] ? script.id : undefined;
|
|
456
|
+
if (!functionId && !scriptId)
|
|
450
457
|
return showContextMenu.call(this, event);
|
|
458
|
+
const blockId = this.id;
|
|
459
|
+
const japanese = scriptEditor && /^ja(?:-|$)/i.test(scriptEditor.locale);
|
|
460
|
+
const scriptOptions = scriptId ? [
|
|
461
|
+
{ section: 'functions', text: japanese ?
|
|
462
|
+
'このスクリプトを個別の画面で編集する' : 'Edit this script in a separate view' },
|
|
463
|
+
{ section: 'calls', text: japanese ?
|
|
464
|
+
'このスクリプトの呼び出し関係を開く' : 'Open relationships for this script' }
|
|
465
|
+
].map(({ section, text }) => ({ text, twPlusMenuIcon: section, separator: false, enabled: true, callback() {
|
|
466
|
+
if (scriptEditor.vm.editingTarget === target && target.blocks._blocks[scriptId]) {
|
|
467
|
+
scriptEditor.open(scriptId, blockId, section);
|
|
468
|
+
}
|
|
469
|
+
} })) : [];
|
|
451
470
|
const owned = Object.prototype.hasOwnProperty.call(this, 'customContextMenu');
|
|
452
471
|
const custom = this.customContextMenu;
|
|
453
472
|
this.customContextMenu = function (options) {
|
|
454
473
|
custom?.call(this, options);
|
|
455
|
-
|
|
474
|
+
if (functionId)
|
|
475
|
+
options.unshift({ text: label(), enabled: true, callback: () => open(functionId) });
|
|
476
|
+
options.unshift(...scriptOptions);
|
|
456
477
|
};
|
|
478
|
+
const { ContextMenu } = ScratchBlocks;
|
|
479
|
+
const populate = scriptOptions.length ? ContextMenu.populate_ : undefined;
|
|
480
|
+
if (scriptOptions.length)
|
|
481
|
+
ContextMenu.populate_ = function (options, rtl) {
|
|
482
|
+
// Addons reorder ContextMenu.show's options after customContextMenu. Prioritize the final list,
|
|
483
|
+
// in place so their separator indices and the host's icon decoration still use the same order.
|
|
484
|
+
for (const priority of [...scriptOptions].reverse()) {
|
|
485
|
+
const index = options.findIndex(option => option.callback === priority.callback);
|
|
486
|
+
if (index > 0)
|
|
487
|
+
options.unshift(...options.splice(index, 1));
|
|
488
|
+
}
|
|
489
|
+
for (const option of scriptOptions)
|
|
490
|
+
option.separator = false;
|
|
491
|
+
if (options.length > 2)
|
|
492
|
+
options[2].separator = true;
|
|
493
|
+
const menu = populate.call(this, options, rtl);
|
|
494
|
+
menu.getChildAt(2)?.getElement().classList.add('tw-script-editor-menu-divider');
|
|
495
|
+
return menu;
|
|
496
|
+
};
|
|
457
497
|
try {
|
|
458
498
|
return showContextMenu.call(this, event);
|
|
459
499
|
}
|
|
460
500
|
finally {
|
|
501
|
+
if (scriptOptions.length)
|
|
502
|
+
ContextMenu.populate_ = populate;
|
|
461
503
|
if (owned)
|
|
462
504
|
this.customContextMenu = custom;
|
|
463
505
|
else
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
export declare function createContextMenuIcons({ enabled, addonMessages, styles }: {
|
|
2
|
+
export declare function createContextMenuIcons({ enabled, addonMessages, styles, renderSectionIcon, createSectionIcon }: {
|
|
3
3
|
enabled: boolean;
|
|
4
4
|
addonMessages: Record<string, string>;
|
|
5
5
|
styles: Record<string, string>;
|
|
6
|
+
renderSectionIcon?(section: 'functions' | 'calls', className: string): React.ReactNode;
|
|
7
|
+
createSectionIcon?(document: Document, section: 'functions' | 'calls', className: string): SVGSVGElement;
|
|
6
8
|
}): {
|
|
7
|
-
renderMenuIcon: (action: any) => React.
|
|
8
|
-
renderContextMenuIcon: (action: any) => React.
|
|
9
|
+
renderMenuIcon: (action: any) => React.ReactNode;
|
|
10
|
+
renderContextMenuIcon: (action: any) => React.ReactNode;
|
|
9
11
|
attachAssetContextMenuIcons: (document: any, getMessages: any) => {
|
|
10
12
|
dispose: () => any;
|
|
11
13
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MPL-2.0
|
|
2
2
|
import React from 'react';
|
|
3
|
-
export function createContextMenuIcons({ enabled, addonMessages, styles }) {
|
|
3
|
+
export function createContextMenuIcons({ enabled, addonMessages, styles, renderSectionIcon, createSectionIcon }) {
|
|
4
4
|
const paths = {
|
|
5
5
|
open: 'M13 4h7v7m0-7-9 9m-1-8H4v15h15v-6',
|
|
6
6
|
duplicate: 'M8 8V4h12v12h-4M4 8h12v12H4z',
|
|
@@ -107,13 +107,17 @@ export function createContextMenuIcons({ enabled, addonMessages, styles }) {
|
|
|
107
107
|
const id = Object.keys(actions).find(key => matchesMessage(text, messages[key], placeholder));
|
|
108
108
|
return actions[id];
|
|
109
109
|
};
|
|
110
|
-
const renderMenuIcon = action =>
|
|
110
|
+
const renderMenuIcon = action => (action === 'functions' || action === 'calls') && renderSectionIcon ?
|
|
111
|
+
renderSectionIcon(action, styles.icon) : paths[action] ? React.createElement('svg', {
|
|
111
112
|
className: styles.icon, 'aria-hidden': 'true', focusable: 'false', viewBox: '0 0 24 24'
|
|
112
113
|
}, React.createElement('path', { d: paths[action] })) : null;
|
|
113
114
|
const renderContextMenuIcon = action => enabled ? renderMenuIcon(action) : null;
|
|
114
115
|
const svgNamespace = 'http://www.w3.org/2000/svg';
|
|
115
116
|
const installed = new WeakSet();
|
|
116
117
|
function createContextMenuIcon(document, action) {
|
|
118
|
+
if ((action === 'functions' || action === 'calls') && createSectionIcon) {
|
|
119
|
+
return createSectionIcon(document, action, styles.icon);
|
|
120
|
+
}
|
|
117
121
|
if (!Object.hasOwn(paths, action))
|
|
118
122
|
return null;
|
|
119
123
|
const icon = document.createElementNS(svgNamespace, 'svg');
|
package/dist/script-arrows.js
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
import { isFoldedDefinition } from "./procedure-edits.js";
|
|
2
2
|
import { readScriptRelations } from "./script-relations.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
3
|
+
function roundedRoute(points, radii) {
|
|
4
|
+
let path = `M ${points[0].x} ${points[0].y}`;
|
|
5
|
+
for (let index = 1; index < points.length - 1; index++) {
|
|
6
|
+
const before = points[index - 1], corner = points[index], after = points[index + 1];
|
|
7
|
+
const entering = Math.hypot(corner.x - before.x, corner.y - before.y);
|
|
8
|
+
const leaving = Math.hypot(after.x - corner.x, after.y - corner.y);
|
|
9
|
+
const size = Math.min(radii[index - 1], entering / 2, leaving / 2);
|
|
10
|
+
if (!size) {
|
|
11
|
+
path += ` L ${corner.x} ${corner.y}`;
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
const first = { x: corner.x + (before.x - corner.x) * size / entering,
|
|
15
|
+
y: corner.y + (before.y - corner.y) * size / entering };
|
|
16
|
+
const last = { x: corner.x + (after.x - corner.x) * size / leaving,
|
|
17
|
+
y: corner.y + (after.y - corner.y) * size / leaving };
|
|
18
|
+
path += ` L ${first.x} ${first.y} Q ${corner.x} ${corner.y} ${last.x} ${last.y}`;
|
|
19
|
+
}
|
|
20
|
+
const end = points.at(-1);
|
|
21
|
+
return `${path} L ${end.x} ${end.y}`;
|
|
19
22
|
}
|
|
23
|
+
const ns = 'http://www.w3.org/2000/svg';
|
|
20
24
|
const outlines = new Map();
|
|
21
25
|
/** Intersect the actual outline, including a hat's overhang, rather than Blockly's layout padding. */
|
|
22
26
|
function outlinePoint(shape, bounds, side, fraction) {
|
|
@@ -116,6 +120,8 @@ export function attachScriptArrows({ workspace, vm, getTarget, getRelations, get
|
|
|
116
120
|
let geometryChanged = true;
|
|
117
121
|
let lastMatrix;
|
|
118
122
|
let edgeDrawings = [];
|
|
123
|
+
let viewportDrawings = [];
|
|
124
|
+
let measuredAnchors = new Map();
|
|
119
125
|
const renderedGroups = new WeakMap();
|
|
120
126
|
const syncTransform = (matrix) => {
|
|
121
127
|
// Workspace dragging lends the two native canvases to a separate SVG which must keep exactly two children.
|
|
@@ -186,16 +192,30 @@ export function attachScriptArrows({ workspace, vm, getTarget, getRelations, get
|
|
|
186
192
|
return;
|
|
187
193
|
const top = blockRoot(endpoint.scriptId, roots);
|
|
188
194
|
// A script hidden by the one-script view is not the same as its folded body.
|
|
189
|
-
if (!top ||
|
|
190
|
-
|
|
195
|
+
if (!top || top.closest('[data-tw-plus-hidden]'))
|
|
196
|
+
return;
|
|
197
|
+
// Native viewport culling hides the whole stack, but its real endpoints still exist.
|
|
198
|
+
const culled = !projection && top.style.display === 'none';
|
|
199
|
+
if (!culled && !top.getClientRects().length)
|
|
191
200
|
return;
|
|
192
201
|
const folded = isFoldedDefinition(target.blocks._blocks[endpoint.scriptId]);
|
|
193
202
|
let id = folded ? endpoint.scriptId : endpoint.blockId;
|
|
194
203
|
let root = blockRoot(id, roots);
|
|
195
204
|
// Native Blockly collapsing can also hide a caller inside a control block.
|
|
196
205
|
const visited = new Set();
|
|
197
|
-
|
|
198
|
-
|
|
206
|
+
const hidden = (node) => {
|
|
207
|
+
if (node.closest('[data-tw-plus-hidden]'))
|
|
208
|
+
return true;
|
|
209
|
+
if (!culled)
|
|
210
|
+
return !node.getClientRects().length || view.getComputedStyle(node).display === 'none';
|
|
211
|
+
// A collapsed parent below the culled stack still needs its visible proxy anchor.
|
|
212
|
+
for (let ancestor = node; ancestor && ancestor !== top; ancestor = ancestor.parentElement) {
|
|
213
|
+
if (view.getComputedStyle(ancestor).display === 'none')
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
return false;
|
|
217
|
+
};
|
|
218
|
+
while (root && hidden(root) && !visited.has(id)) {
|
|
199
219
|
visited.add(id);
|
|
200
220
|
id = target.blocks._blocks[id]?.parent ?? '';
|
|
201
221
|
root = blockRoot(id, roots);
|
|
@@ -225,7 +245,7 @@ export function attachScriptArrows({ workspace, vm, getTarget, getRelations, get
|
|
|
225
245
|
return points.get(key);
|
|
226
246
|
} };
|
|
227
247
|
}
|
|
228
|
-
function arrowGeometry({ relation, source, destination, count }, matrix, inverse, area, highlighted) {
|
|
248
|
+
function arrowGeometry({ relation, source, destination, count, serialRoute }, matrix, inverse, area, highlighted) {
|
|
229
249
|
// Anchor an external link to the viewport edge; the list itself remains keyboard accessible.
|
|
230
250
|
const local = source ?? destination;
|
|
231
251
|
const edgeX = source ? area.right - 12 : area.left + 12;
|
|
@@ -249,18 +269,20 @@ export function attachScriptArrows({ workspace, vm, getTarget, getRelations, get
|
|
|
249
269
|
` C ${left} ${top}, ${left} ${end.y}, ${end.x} ${end.y}`;
|
|
250
270
|
badgePoint = { x: middle, y: top - 6 };
|
|
251
271
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
272
|
+
if (serialRoute && source && destination) {
|
|
273
|
+
const { right, top, clearance, radius } = serialRoute;
|
|
274
|
+
// Leave room beside every script before turning vertically, then return through the gap above the hat.
|
|
275
|
+
const approach = end.x - clearance;
|
|
276
|
+
path = roundedRoute([start, { x: right, y: start.y }, { x: right, y: top },
|
|
277
|
+
{ x: approach, y: top }, { x: approach, y: end.y }, end], [radius, radius, clearance, clearance]);
|
|
278
|
+
badgePoint = { x: right, y: (start.y + top) / 2 };
|
|
258
279
|
}
|
|
259
|
-
|
|
280
|
+
const head = `M ${end.x - 9} ${end.y - 5} L ${end.x} ${end.y} L ${end.x - 9} ${end.y + 5}`;
|
|
281
|
+
return { path, head, recursive, badgePoint };
|
|
260
282
|
}
|
|
261
283
|
function drawArrow(drawing, matrix, inverse, area, highlighted) {
|
|
262
284
|
const { relation, source, destination, count } = drawing;
|
|
263
|
-
const { path, head, recursive, badgePoint
|
|
285
|
+
const { path, head, recursive, badgePoint } = arrowGeometry(drawing, matrix, inverse, area, highlighted);
|
|
264
286
|
const strings = text();
|
|
265
287
|
const group = element('g', {
|
|
266
288
|
'data-script-relation': relation.kind,
|
|
@@ -283,22 +305,24 @@ export function attachScriptArrows({ workspace, vm, getTarget, getRelations, get
|
|
|
283
305
|
class: 'tw-script-relation-head',
|
|
284
306
|
d: head
|
|
285
307
|
}));
|
|
286
|
-
if (waiting) {
|
|
287
|
-
const badge = element('g', { class: 'tw-script-relation-wait', 'aria-label': strings.wait,
|
|
288
|
-
transform: waitTransform });
|
|
289
|
-
const title = element('title');
|
|
290
|
-
title.textContent = strings.wait;
|
|
291
|
-
badge.append(title, element('rect', { x: '-10', y: '-10', width: '20', height: '20', rx: '4' }), element('path', { class: 'tw-script-relation-wait-glyph', d: relationWaitGlyph, transform: 'translate(-8 -8)' }));
|
|
292
|
-
group.append(badge);
|
|
293
|
-
}
|
|
294
308
|
if (count > 1) {
|
|
295
309
|
const badge = element('text', { x: String(badgePoint.x), y: String(badgePoint.y),
|
|
296
|
-
class: 'tw-script-relation-badge', 'text-anchor':
|
|
310
|
+
class: 'tw-script-relation-badge', 'text-anchor': 'middle' });
|
|
297
311
|
badge.textContent = `×${count}`;
|
|
298
312
|
group.append(badge);
|
|
299
313
|
}
|
|
300
314
|
return group;
|
|
301
315
|
}
|
|
316
|
+
function inViewport({ source, destination }, matrix, area) {
|
|
317
|
+
return [source, destination].some(anchor => {
|
|
318
|
+
if (!anchor)
|
|
319
|
+
return false;
|
|
320
|
+
const first = transform(matrix, anchor.box);
|
|
321
|
+
const last = transform(matrix, { x: anchor.box.x + anchor.box.width, y: anchor.box.y + anchor.box.height });
|
|
322
|
+
return Math.max(first.x, last.x) > area.left && Math.min(first.x, last.x) < area.right &&
|
|
323
|
+
Math.max(first.y, last.y) > area.top && Math.min(first.y, last.y) < area.bottom;
|
|
324
|
+
});
|
|
325
|
+
}
|
|
302
326
|
function render() {
|
|
303
327
|
frame = undefined;
|
|
304
328
|
if (disposed)
|
|
@@ -336,7 +360,9 @@ export function attachScriptArrows({ workspace, vm, getTarget, getRelations, get
|
|
|
336
360
|
const area = (projection ?? workspace.getParentSvg()).getBoundingClientRect();
|
|
337
361
|
const sameScale = lastMatrix && matrix.a === lastMatrix.a && matrix.b === lastMatrix.b &&
|
|
338
362
|
matrix.c === lastMatrix.c && matrix.d === lastMatrix.d;
|
|
339
|
-
|
|
363
|
+
const reuseAnchors = !geometryChanged && !projection && sameScale;
|
|
364
|
+
if (reuseAnchors &&
|
|
365
|
+
viewportDrawings.every(item => item.visible === inViewport(item.drawing, matrix, area))) {
|
|
340
366
|
const geometry = edgeDrawings.map(item => ({ ...item,
|
|
341
367
|
shape: arrowGeometry(item.drawing, matrix, inverse, area, item.highlighted) }));
|
|
342
368
|
syncTransform(matrix);
|
|
@@ -347,8 +373,6 @@ export function attachScriptArrows({ workspace, vm, getTarget, getRelations, get
|
|
|
347
373
|
};
|
|
348
374
|
set(group.querySelector('.tw-script-relation-line'), 'd', shape.path);
|
|
349
375
|
set(group.querySelector('.tw-script-relation-head'), 'd', shape.head);
|
|
350
|
-
if (shape.waitTransform)
|
|
351
|
-
set(group.querySelector('.tw-script-relation-wait'), 'transform', shape.waitTransform);
|
|
352
376
|
const count = group.querySelector('.tw-script-relation-badge');
|
|
353
377
|
set(count, 'x', shape.badgePoint.x);
|
|
354
378
|
set(count, 'y', shape.badgePoint.y);
|
|
@@ -359,6 +383,9 @@ export function attachScriptArrows({ workspace, vm, getTarget, getRelations, get
|
|
|
359
383
|
geometryChanged = false;
|
|
360
384
|
lastMatrix = matrix;
|
|
361
385
|
edgeDrawings = [];
|
|
386
|
+
viewportDrawings = [];
|
|
387
|
+
if (!reuseAnchors)
|
|
388
|
+
measuredAnchors = new Map();
|
|
362
389
|
const paint = [];
|
|
363
390
|
const guides = document.createDocumentFragment();
|
|
364
391
|
const previousGroups = renderedGroups.get(drawingLayer);
|
|
@@ -384,12 +411,11 @@ export function attachScriptArrows({ workspace, vm, getTarget, getRelations, get
|
|
|
384
411
|
const inDrag = (endpoint) => Boolean(endpoint && endpoint.targetId === target.id && draggedIds.has(endpoint.blockId));
|
|
385
412
|
const incident = (relation) => inDrag(relation.source) || inDrag(relation.destination);
|
|
386
413
|
const drawings = new Map();
|
|
387
|
-
const anchors = new Map();
|
|
388
414
|
const measuredAnchor = (endpoint) => {
|
|
389
415
|
const key = `${endpoint.targetId}\0${endpoint.scriptId}\0${endpoint.blockId}`;
|
|
390
|
-
if (!
|
|
391
|
-
|
|
392
|
-
return
|
|
416
|
+
if (!measuredAnchors.has(key))
|
|
417
|
+
measuredAnchors.set(key, anchor(endpoint, target, roots, inverse));
|
|
418
|
+
return measuredAnchors.get(key);
|
|
393
419
|
};
|
|
394
420
|
for (const relation of graph) {
|
|
395
421
|
if (!visibility[relation.kind])
|
|
@@ -408,6 +434,36 @@ export function attachScriptArrows({ workspace, vm, getTarget, getRelations, get
|
|
|
408
434
|
else
|
|
409
435
|
drawings.set(key, { relation, source, destination, count: 1 });
|
|
410
436
|
}
|
|
437
|
+
if (projection) {
|
|
438
|
+
const unit = 1 / (Math.hypot(matrix.a, matrix.b) || 1);
|
|
439
|
+
const scripts = new Map();
|
|
440
|
+
for (const root of projection.querySelectorAll('[data-script-view-block]')) {
|
|
441
|
+
const rect = root.getBoundingClientRect();
|
|
442
|
+
const first = transform(inverse, { x: rect.left, y: rect.top });
|
|
443
|
+
const last = transform(inverse, { x: rect.right, y: rect.bottom });
|
|
444
|
+
scripts.set(root.getAttribute('data-script-view-block'), { x: first.x, y: first.y, width: last.x - first.x, height: last.y - first.y });
|
|
445
|
+
}
|
|
446
|
+
const rightEdge = [...scripts.values()].reduce((edge, box) => Math.max(edge, box.x + box.width), 0);
|
|
447
|
+
let lane = 0;
|
|
448
|
+
for (const drawing of drawings.values()) {
|
|
449
|
+
if (!drawing.source || !drawing.destination)
|
|
450
|
+
continue;
|
|
451
|
+
const destination = scripts.get(drawing.relation.destination.scriptId);
|
|
452
|
+
if (!destination)
|
|
453
|
+
continue;
|
|
454
|
+
drawing.serialRoute = { right: rightEdge + (96 + lane * 16) * unit,
|
|
455
|
+
top: destination.y - (14 + lane % 4 * 6) * unit, clearance: 8 * unit, radius: 48 * unit };
|
|
456
|
+
lane++;
|
|
457
|
+
}
|
|
458
|
+
// Reserve actual scrollable SVG width for the right-hand routes while preserving the block scale.
|
|
459
|
+
const box = projection.viewBox.baseVal;
|
|
460
|
+
const width = Math.ceil(rightEdge + (112 + Math.max(0, lane - 1) * 16) * unit);
|
|
461
|
+
if (lane && width > box.width) {
|
|
462
|
+
const scale = Math.hypot(matrix.a, matrix.b);
|
|
463
|
+
projection.setAttribute('viewBox', `${box.x} ${box.y} ${width} ${box.height}`);
|
|
464
|
+
projection.setAttribute('width', String(width * scale));
|
|
465
|
+
}
|
|
466
|
+
}
|
|
411
467
|
const related = new Set();
|
|
412
468
|
for (const relation of graph)
|
|
413
469
|
if (visibility[relation.kind] && dragging && incident(relation)) {
|
|
@@ -426,7 +482,7 @@ export function attachScriptArrows({ workspace, vm, getTarget, getRelations, get
|
|
|
426
482
|
if (root && root.getClientRects().length && !root.closest('[data-tw-plus-hidden]'))
|
|
427
483
|
marked.set(root, 'related');
|
|
428
484
|
}
|
|
429
|
-
//
|
|
485
|
+
// Shade the whole stack, including its body; the original block paint and runtime glow stay intact.
|
|
430
486
|
for (const [root, role] of marked) {
|
|
431
487
|
const bounds = root.getBoundingClientRect();
|
|
432
488
|
const first = transform(inverse, { x: bounds.left, y: bounds.top });
|
|
@@ -436,6 +492,10 @@ export function attachScriptArrows({ workspace, vm, getTarget, getRelations, get
|
|
|
436
492
|
rx: '10', class: 'tw-script-relation-script-highlight', 'data-emphasis': role }));
|
|
437
493
|
}
|
|
438
494
|
for (const [key, drawing] of drawings) {
|
|
495
|
+
const visible = inViewport(drawing, matrix, area);
|
|
496
|
+
viewportDrawings.push({ drawing, visible });
|
|
497
|
+
if (!visible)
|
|
498
|
+
continue;
|
|
439
499
|
const { relation, source, destination, count } = drawing;
|
|
440
500
|
const highlighted = dragging ? incident(relation) :
|
|
441
501
|
emphasized && (emphasized === relation.source.scriptId || emphasized === relation.destination?.scriptId);
|
|
@@ -449,7 +509,7 @@ export function attachScriptArrows({ workspace, vm, getTarget, getRelations, get
|
|
|
449
509
|
vm?.runtime?.targets?.find(item => item.id === endpoint.targetId)?.getName?.());
|
|
450
510
|
const reason = relation.unresolved && strings[relation.unresolved];
|
|
451
511
|
external.textContent = `${name ? `${name} · ` : ''}` +
|
|
452
|
-
`${relation.label}${reason ? ` · ${reason}` : ''}${
|
|
512
|
+
`${relation.label}${reason ? ` · ${reason}` : ''}${count > 1 ? ` ×${count}` : ''}`;
|
|
453
513
|
external.disabled = !endpoint;
|
|
454
514
|
external.setAttribute('aria-label', `${strings[relation.kind]}: ${external.textContent}`);
|
|
455
515
|
external.toggleAttribute('data-highlighted', Boolean(highlighted));
|
|
@@ -496,6 +556,8 @@ export function attachScriptArrows({ workspace, vm, getTarget, getRelations, get
|
|
|
496
556
|
destinations.replaceChildren();
|
|
497
557
|
destinations.hidden = true;
|
|
498
558
|
edgeDrawings = [];
|
|
559
|
+
viewportDrawings = [];
|
|
560
|
+
measuredAnchors.clear();
|
|
499
561
|
lastMatrix = undefined;
|
|
500
562
|
renderedGroups.delete(layer);
|
|
501
563
|
if (projectedLayer)
|