@kubohiroya/turbowarp-plus-editor-code-views 0.20.0 → 0.21.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 +18 -2
- package/README.md +1 -1
- package/dist/code-pane.d.ts +8 -0
- package/dist/code-pane.js +49 -5
- package/dist/code-zoom.d.ts +3 -0
- package/dist/code-zoom.js +30 -0
- package/dist/script-arrows.d.ts +11 -1
- package/dist/script-arrows.js +268 -100
- package/dist/script-fit.d.ts +1 -1
- package/dist/script-fit.js +7 -9
- package/dist/script-layout-view.d.ts +18 -1
- package/dist/script-layout-view.js +13 -1
- package/dist/sprite-code-windows.d.ts +1 -0
- package/dist/sprite-code-windows.js +1 -0
- package/dist/workspace-overview.d.ts +16 -0
- package/dist/workspace-overview.js +221 -0
- package/dist/workspace.d.ts +3 -0
- package/dist/workspace.js +4 -2
- package/package.json +1 -1
- package/src/code-pane.ts +45 -5
- package/src/code-zoom.ts +28 -0
- package/src/script-arrows.ts +244 -98
- package/src/script-fit.ts +8 -10
- package/src/script-layout-view.ts +16 -2
- package/src/sprite-code-windows.tsx +1 -0
- package/src/styles.css +41 -1
- package/src/workspace-overview.ts +197 -0
- package/src/workspace.ts +6 -3
package/README.ja.md
CHANGED
|
@@ -6,7 +6,7 @@ TurboWarp Plus Editor のコードの画面。1つの作品と1つの取り消
|
|
|
6
6
|
|
|
7
7
|
## 選択したスクリプトの表示
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
関数・ハットなどを選んで開くと、そのスクリプトの描画範囲に合わせて倍率を調整し、先頭ブロックの左上をコードパネルの左上から右・下へ24px空けた位置に合わせる。自動ズームは50〜125%に制限し、ワークスペース固有の制限が厳しければそちらに従う。短いスクリプトや下限倍率でも同じ位置から表示し、後続の幅広いブロックの形には左右されない。通常の編集・手動ズームでは再フィットしない。
|
|
10
10
|
|
|
11
11
|
ホストが独立したワークスペースを表示する場合は、ルートまたは `./sprite-code-windows` の `fitScriptInWorkspace(workspace, scriptId, ScratchBlocks)` を使える。表示領域やブロックがまだない場合は `false` を返すので、レイアウト後に再試行する。
|
|
12
12
|
|
|
@@ -51,15 +51,31 @@ Editor は GUI の React 16 にこれらを描画するので、React 16.14 以
|
|
|
51
51
|
|
|
52
52
|
コードの背面に、関数呼び出しを紫系の実線、メッセージ送信を橙系の破線で表示する。「送って待つ」には待機の印を添える。通常配置、Z/N 配置、折り畳み、プレビュー、別窓で同じ表現を使う。関数の再帰はスクリプトの外へ回る線で示す。選択・ホバーによる強調は太さと不透明度で行い、関係種別の色・線種は変えない。
|
|
53
53
|
|
|
54
|
+
関数呼び出しとメッセージ送受信は、常に呼び出し元・送信元の右から出て、呼び出し先・受信先の左へ入る。左右の配置が逆でも接続する側を入れ替えない。自己呼び出しもスクリプトの外を回って左側へ戻る。
|
|
55
|
+
|
|
56
|
+
通常の線と矢印の先端は20%の濃さにし、選択・ホバー・ドラッグに関連する線を強調する。ドラッグ開始時に無関係な線だけが急に薄くなることはない。
|
|
57
|
+
|
|
54
58
|
関係は作品データから読み、折り畳みによって表示から消えた呼び出しも保持する。展開中は呼び出しブロックから、折り畳み中は見えているハットから結ぶ。同じハットと宛先へ重なる呼び出しは件数を表示する。別スプライトや一スクリプト表示の外にある接続先は、画面端の案内から辿れる。変数などで呼び出し先が変わるものは「実行時に決定」と示し、見えていない既定値を宛先とみなさない。
|
|
55
59
|
|
|
60
|
+
接続元または接続先を同じパネル内に描けない矢印は、線・矢印の先端・待機の印・件数を5%の濃さで表示する。ホバー・選択・ドラッグによる強調中も同じ濃さを維持する。
|
|
61
|
+
|
|
56
62
|
スクリプトをドラッグしている間は、そこへ入る・そこから出る矢印を太く濃くし、画面にある相手のスクリプト全体を枠で強調する。関係しない矢印は薄くし、画面外の相手は接続先の案内を強調する。関数とメッセージの色・線種は維持する。折り畳み中も同じように働き、ドラッグの終了・矢印の非表示・画面の破棄で一時的な枠を解除する。移動中に Blockly がブロックを別の SVG へ移しても追従する。
|
|
57
63
|
|
|
58
64
|
`attachDockedScriptLayout` と `attachCodeWorkspace` のプレビュー・関数エディタには自動で付く。VM を持たない表示では、`attachScriptView` に `relations: {getTarget, getRelations, getTargetName, navigate}` を渡す。`getRelations` は親の `createCodeSession` が渡す `scriptRelations`、`getTarget` はその対象の `blocks` を使う。`getTargetName` は既存の対象一覧から名前を返し、同じメッセージを受信する別スプライトを案内で識別できるようにする。投影の受信後は `view.relations.update()` を呼ぶ。関係だけの更新は `relations`、接続先への移動は `relation-navigate`/`relation-focus` で既存の編集回収・対象切り替えを経由する。編集中の窓には履歴の更新のために XML を再読み込みさせない。
|
|
59
65
|
|
|
60
66
|
色は共通の CSS 変数 `--tw-script-function-stroke` と `--tw-script-message-stroke` に定義する。明暗テーマでは同じ種別のまま明度を変え、線種でも区別できる。既存の関数呼び出し図とミニマップも関数用の変数を使う。
|
|
61
67
|
|
|
62
|
-
|
|
68
|
+
自由配置パネルの左端カラム下端に、呼び出し関係パネルと同じ「関数」「メッセージ」の表示ボタンを置く。両方とも既定で有効で、独立して切り替えられる。選択はコードペインごとに保持し、作業領域の保存・復元、非アクティブなプレビュー、Z/N表示にも反映する。非表示の種類は接続先の案内とドラッグ中の強調からも外し、両方を非表示にすると矢印の座標計算を止める。ホストはコードペインアダプターの `relations.getVisibility(paneId)`・`setVisibility(paneId, value)`・`subscribe(listener)` を既存のツールバーへ接続する。
|
|
69
|
+
|
|
70
|
+
矢印の描画層はブロックのキャンバスと分け、線の変更でミニマップの全ブロックを再生成しない。表示領域の寸法は1描画につき1回だけ読み、線の座標を測ってから必要なDOM更新をまとめる。スクロールでは内部の線とブロックの接続点を再利用し、画面端へ伸びる線だけを更新する。無関係なスクリプトの編集でも変化しない線は作り直さない。
|
|
71
|
+
|
|
72
|
+
ミニマップの描画と入力は `attachWorkspaceOverview` が所有し、ホストは workspace・配置・サムネイル取得の口を渡す。画面外のブロックを隠すネイティブの表示変更では形状を再走査せず、スクロール中は表示範囲の枠だけを更新する。ブロック編集時も既存のパスを保ち、必要な形・位置・色だけを書き換える。矢印の輪郭は同じパス形状で共有し、粗い走査と交点の精密化を組み合わせ、スクロール中は測定済みの接続点を使う。
|
|
73
|
+
|
|
74
|
+
自由配置とコードのプレビューは2%まで縮小できる。通常の拡大・縮小ボタンやホイールを使い、リセットでは従来の初期倍率へ戻る。最小倍率はコード画面の接続中だけ変更し、Blockly の他の用途の既定値は変えない。
|
|
75
|
+
|
|
76
|
+
選択・ホバー・ドラッグ中の関係に必要な接続先だけを短く表示する。呼び出し関係の図へ渡す `readScriptRelationGraph(targets, ScratchBlocks)` は、同じ関係データと、接続先スクリプトのハットの文言・対象名・位置を返す。図の向きは呼び出し関係パネルの左端カラム下端で操作する。
|
|
77
|
+
|
|
78
|
+
切り戻す場合は、code-views と workbench の固定依存を導入前の版へ戻して再ビルドする。追加した `relationVisibility` は作業領域の任意設定であり、作品のコード・座標・編集履歴は変更しない。
|
|
63
79
|
|
|
64
80
|
既定は表示する。作品の保存形式は変えない。完全に切り戻す場合は導入前のパッケージ固定と結線へ戻す。関連: [Editor #683](https://github.com/kubohiroya/turbowarp-plus-editor/issues/683)。
|
|
65
81
|
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ The code views of TurboWarp Plus Editor: code in tabs and windows that share one
|
|
|
6
6
|
|
|
7
7
|
## Opening a selected script
|
|
8
8
|
|
|
9
|
-
Opening a function or hat
|
|
9
|
+
Opening a function or hat adjusts the zoom to its rendered script and places the first block's top left 24px right and down from the code pane's top left. Automatic zoom stays between 50% and 125%, respecting stricter workspace limits. Short scripts and scripts at the zoom floor start at the same position, regardless of wider blocks farther down the script. Ordinary edits and manual zoom do not refit it.
|
|
10
10
|
|
|
11
11
|
Hosts with a separate workspace can call `fitScriptInWorkspace(workspace, scriptId, ScratchBlocks)` from the root or `./sprite-code-windows` export. It returns `false` if the viewport or block is not ready, so the host can retry after layout.
|
|
12
12
|
|
package/dist/code-pane.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { getCodeSession } from './workspace.ts';
|
|
|
2
2
|
import type { AttachPreviewMinimap, AttachWorkspaceNavigation } from './workspace.ts';
|
|
3
3
|
import { type ScriptView } from './script-layout-view.ts';
|
|
4
4
|
import { type RelationTarget } from './script-relations.ts';
|
|
5
|
+
import type { ScriptRelationVisibility } from './script-arrows.ts';
|
|
5
6
|
type Pane = {
|
|
6
7
|
id: string;
|
|
7
8
|
targetId: string;
|
|
@@ -15,10 +16,17 @@ export type SavedCodePane = {
|
|
|
15
16
|
x: number;
|
|
16
17
|
y: number;
|
|
17
18
|
scriptView?: ScriptView;
|
|
19
|
+
relationVisibility?: ScriptRelationVisibility;
|
|
18
20
|
};
|
|
19
21
|
/** Read a saved code area back, or nothing if it does not have the shape `serialize` writes. */
|
|
20
22
|
export declare function readSavedCodePane(value: Record<string, unknown>): SavedCodePane | undefined;
|
|
21
23
|
export declare function createCodePaneAdapter(vm: any, locale: string, attachMinimap?: AttachPreviewMinimap): {
|
|
24
|
+
/** Independent arrow filters belong to a code pane, including when its workspace is parked. */
|
|
25
|
+
relations: {
|
|
26
|
+
getVisibility: (paneId: string) => ScriptRelationVisibility;
|
|
27
|
+
setVisibility(paneId: string, value: ScriptRelationVisibility): void;
|
|
28
|
+
subscribe(listener: () => void): () => boolean;
|
|
29
|
+
};
|
|
22
30
|
/**
|
|
23
31
|
* Make a code view show one script, a hat or a function, or every script again without `scriptId`.
|
|
24
32
|
* The code area shows it while it is in that view, and the view's preview shows it otherwise.
|
package/dist/code-pane.js
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
import { getCodeSession } from "./workspace.js";
|
|
2
|
-
import { getDockedScriptLayout } from "./script-layout-view.js";
|
|
2
|
+
import { getDockedScriptLayout, setDockedRelationVisibility } from "./script-layout-view.js";
|
|
3
3
|
import { readScriptRelations } from "./script-relations.js";
|
|
4
4
|
const scriptViews = ['free', 'z', 'n'];
|
|
5
5
|
const finite = (value, limit) => typeof value === 'number' && Number.isFinite(value) && Math.abs(value) <= limit;
|
|
6
6
|
/** Read a saved code area back, or nothing if it does not have the shape `serialize` writes. */
|
|
7
7
|
export function readSavedCodePane(value) {
|
|
8
|
-
const { scale, x, y, scriptView } = value;
|
|
8
|
+
const { scale, x, y, scriptView, relationVisibility } = value;
|
|
9
9
|
if (!finite(scale, 100) || scale <= 0 || !finite(x, 1e7) || !finite(y, 1e7))
|
|
10
10
|
return;
|
|
11
|
-
|
|
11
|
+
const visibility = relationVisibility;
|
|
12
|
+
return { scale, x, y, ...(scriptViews.includes(scriptView) && { scriptView: scriptView }),
|
|
13
|
+
...(visibility && typeof visibility.function === 'boolean' && typeof visibility.message === 'boolean' &&
|
|
14
|
+
{ relationVisibility: { function: visibility.function, message: visibility.message } }) };
|
|
12
15
|
}
|
|
13
16
|
export function createCodePaneAdapter(vm, locale, attachMinimap) {
|
|
14
17
|
const session = getCodeSession(vm);
|
|
15
18
|
const label = /^ja(?:-|$)/i.test(locale) ? 'このペインでコードを編集' : 'Edit code in this pane';
|
|
16
19
|
const views = new Map();
|
|
20
|
+
const visibilities = new Map();
|
|
21
|
+
const visibilityListeners = new Set();
|
|
22
|
+
const getVisibility = (paneId) => ({ ...visibilities.get(paneId) ?? { function: true, message: true } });
|
|
17
23
|
// Views that show one script, a hat or a function, by pane id; `onLost` runs when that script is deleted.
|
|
18
24
|
const focused = new Map();
|
|
19
25
|
// The code pane the code area is in, which shows its script there.
|
|
@@ -62,6 +68,25 @@ export function createCodePaneAdapter(vm, locale, attachMinimap) {
|
|
|
62
68
|
};
|
|
63
69
|
}
|
|
64
70
|
return {
|
|
71
|
+
/** Independent arrow filters belong to a code pane, including when its workspace is parked. */
|
|
72
|
+
relations: {
|
|
73
|
+
getVisibility,
|
|
74
|
+
setVisibility(paneId, value) {
|
|
75
|
+
const before = getVisibility(paneId);
|
|
76
|
+
if (before.function === value.function && before.message === value.message)
|
|
77
|
+
return;
|
|
78
|
+
visibilities.set(paneId, { ...value });
|
|
79
|
+
if (current === paneId)
|
|
80
|
+
setDockedRelationVisibility(vm, value);
|
|
81
|
+
for (const listener of visibilityListeners)
|
|
82
|
+
listener();
|
|
83
|
+
session.changed();
|
|
84
|
+
},
|
|
85
|
+
subscribe(listener) {
|
|
86
|
+
visibilityListeners.add(listener);
|
|
87
|
+
return () => visibilityListeners.delete(listener);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
65
90
|
/**
|
|
66
91
|
* Make a code view show one script, a hat or a function, or every script again without `scriptId`.
|
|
67
92
|
* The code area shows it while it is in that view, and the view's preview shows it otherwise.
|
|
@@ -81,8 +106,10 @@ export function createCodePaneAdapter(vm, locale, attachMinimap) {
|
|
|
81
106
|
forgetPane(paneId) {
|
|
82
107
|
focused.delete(paneId);
|
|
83
108
|
views.delete(paneId);
|
|
109
|
+
visibilities.delete(paneId);
|
|
84
110
|
if (current === paneId) {
|
|
85
111
|
current = undefined;
|
|
112
|
+
setDockedRelationVisibility(vm, { function: true, message: true });
|
|
86
113
|
applyFocus(undefined);
|
|
87
114
|
}
|
|
88
115
|
},
|
|
@@ -113,7 +140,9 @@ export function createCodePaneAdapter(vm, locale, attachMinimap) {
|
|
|
113
140
|
return;
|
|
114
141
|
const scriptView = presentation ? presentation.scriptView : views.get(pane.id) ??
|
|
115
142
|
getDockedScriptLayout(vm)?.view.view;
|
|
116
|
-
|
|
143
|
+
const relationVisibility = visibilities.get(pane.id) ?? shown.relationVisibility;
|
|
144
|
+
return { scale: shown.scale, x: shown.x, y: shown.y, ...(scriptView && { scriptView }),
|
|
145
|
+
...(relationVisibility && { relationVisibility: { ...relationVisibility } }) };
|
|
117
146
|
},
|
|
118
147
|
/** A presentation from a saved code area. The preview draws it without the chrome of the code area. */
|
|
119
148
|
deserialize(pane, value) {
|
|
@@ -124,7 +153,14 @@ export function createCodePaneAdapter(vm, locale, attachMinimap) {
|
|
|
124
153
|
return;
|
|
125
154
|
if (saved.scriptView)
|
|
126
155
|
views.set(pane.id, saved.scriptView);
|
|
127
|
-
|
|
156
|
+
if (saved.relationVisibility)
|
|
157
|
+
visibilities.set(pane.id, { ...saved.relationVisibility });
|
|
158
|
+
else
|
|
159
|
+
visibilities.delete(pane.id);
|
|
160
|
+
for (const listener of visibilityListeners)
|
|
161
|
+
listener();
|
|
162
|
+
return { scale: saved.scale, x: saved.x, y: saved.y, visible: true, ...(saved.scriptView && { scriptView: saved.scriptView }),
|
|
163
|
+
...(saved.relationVisibility && { relationVisibility: { ...saved.relationVisibility } }) };
|
|
128
164
|
},
|
|
129
165
|
restore(pane, presentation) {
|
|
130
166
|
if (pending)
|
|
@@ -133,6 +169,12 @@ export function createCodePaneAdapter(vm, locale, attachMinimap) {
|
|
|
133
169
|
if (pane.section !== 0)
|
|
134
170
|
return;
|
|
135
171
|
current = pane.id;
|
|
172
|
+
if (!visibilities.has(pane.id) && presentation?.relationVisibility) {
|
|
173
|
+
visibilities.set(pane.id, { ...presentation.relationVisibility });
|
|
174
|
+
for (const listener of visibilityListeners)
|
|
175
|
+
listener();
|
|
176
|
+
}
|
|
177
|
+
setDockedRelationVisibility(vm, getVisibility(pane.id));
|
|
136
178
|
applyFocus(pane.id);
|
|
137
179
|
getDockedScriptLayout(vm)?.view.setView(views.get(pane.id) ?? 'free');
|
|
138
180
|
if (!presentation)
|
|
@@ -190,8 +232,10 @@ export function createCodePaneAdapter(vm, locale, attachMinimap) {
|
|
|
190
232
|
shownScript = focused.get(pane.id)?.scriptId;
|
|
191
233
|
preview = bridge?.preview(blocks, chrome, { target, presentation, attachMinimap, watermark, locale, dropElement: surface,
|
|
192
234
|
scriptView: views.get(pane.id), onScriptViewChange: view => views.set(pane.id, view),
|
|
235
|
+
relationVisibility: getVisibility(pane.id),
|
|
193
236
|
scriptId: focused.get(pane.id)?.scriptId });
|
|
194
237
|
}
|
|
238
|
+
preview?.setRelationVisibility(getVisibility(pane.id));
|
|
195
239
|
preview?.update();
|
|
196
240
|
}
|
|
197
241
|
const unsubscribe = session.subscribe(update);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const minimumCodeScale = 0.02;
|
|
2
|
+
const ranges = new WeakMap();
|
|
3
|
+
/** The code area and its previews share a lower zoom limit without changing Blockly's other workspaces. */
|
|
4
|
+
export function attachCodeZoomRange(workspace) {
|
|
5
|
+
const options = workspace.options?.zoomOptions;
|
|
6
|
+
if (!options)
|
|
7
|
+
return () => { };
|
|
8
|
+
let range = ranges.get(workspace);
|
|
9
|
+
if (!range) {
|
|
10
|
+
range = { users: 0, previous: options.minScale, minimum: Math.min(options.minScale || 1, minimumCodeScale) };
|
|
11
|
+
ranges.set(workspace, range);
|
|
12
|
+
options.minScale = range.minimum;
|
|
13
|
+
}
|
|
14
|
+
range.users++;
|
|
15
|
+
let disposed = false;
|
|
16
|
+
return () => {
|
|
17
|
+
if (disposed)
|
|
18
|
+
return;
|
|
19
|
+
disposed = true;
|
|
20
|
+
if (--range.users)
|
|
21
|
+
return;
|
|
22
|
+
if (options.minScale === range.minimum) {
|
|
23
|
+
if (range.previous === undefined)
|
|
24
|
+
delete options.minScale;
|
|
25
|
+
else
|
|
26
|
+
options.minScale = range.previous;
|
|
27
|
+
}
|
|
28
|
+
ranges.delete(workspace);
|
|
29
|
+
};
|
|
30
|
+
}
|
package/dist/script-arrows.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { type RelationTarget, type ScriptEndpoint, type ScriptRelation } from './script-relations.ts';
|
|
2
|
+
export type ScriptRelationVisibility = {
|
|
3
|
+
function: boolean;
|
|
4
|
+
message: boolean;
|
|
5
|
+
};
|
|
2
6
|
export interface ScriptRelationContext {
|
|
3
7
|
vm?: {
|
|
4
8
|
runtime?: {
|
|
@@ -16,10 +20,11 @@ export interface ScriptRelationContext {
|
|
|
16
20
|
getLocale?(): string;
|
|
17
21
|
getTargetName?(id: string): string | undefined;
|
|
18
22
|
navigate?(endpoint: ScriptEndpoint): void;
|
|
23
|
+
initialVisibility?: ScriptRelationVisibility;
|
|
19
24
|
}
|
|
20
25
|
export declare function registerScriptRelationNavigation(vm: object, navigate: (endpoint: ScriptEndpoint) => void): () => void;
|
|
21
26
|
/** One renderer and semantic stylesheet serve live code, folded scripts, previews and serial layouts. */
|
|
22
|
-
export declare function attachScriptArrows({ workspace, vm, getTarget, getRelations, getLocale, getTargetName, navigate }: ScriptRelationContext & {
|
|
27
|
+
export declare function attachScriptArrows({ workspace, vm, getTarget, getRelations, getLocale, getTargetName, navigate, initialVisibility }: ScriptRelationContext & {
|
|
23
28
|
workspace: {
|
|
24
29
|
getInjectionDiv(): HTMLElement;
|
|
25
30
|
getCanvas(): SVGElement;
|
|
@@ -41,6 +46,11 @@ export declare function attachScriptArrows({ workspace, vm, getTarget, getRelati
|
|
|
41
46
|
}): {
|
|
42
47
|
update: () => void;
|
|
43
48
|
readonly enabled: boolean;
|
|
49
|
+
readonly visibility: {
|
|
50
|
+
function: boolean;
|
|
51
|
+
message: boolean;
|
|
52
|
+
};
|
|
53
|
+
setVisibility(value: ScriptRelationVisibility): void;
|
|
44
54
|
setEnabled(value: boolean): void;
|
|
45
55
|
setProjection(svg: SVGSVGElement | null): void;
|
|
46
56
|
dispose(): void;
|