@kubohiroya/turbowarp-plus-editor-code-views 0.1.0 → 0.2.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 +4 -0
- package/README.md +4 -0
- package/dist/code-pane.d.ts +17 -0
- package/dist/code-pane.js +35 -0
- package/dist/sprite-code-windows.d.ts +2 -1
- package/dist/sprite-code-windows.js +1 -1
- package/dist/workspace.d.ts +2 -1
- package/package.json +1 -1
- package/src/code-pane.ts +40 -0
- package/src/sprite-code-windows.tsx +2 -1
- package/src/workspace.ts +2 -1
package/README.ja.md
CHANGED
|
@@ -27,6 +27,10 @@ TurboWarp Plus Editor のコードの画面。1つの作品と1つの取り消
|
|
|
27
27
|
|
|
28
28
|
`attachCodeWorkspace` と `attachDockedScriptLayout` は `presentationElements(injection)` を受け取る。これはワークスペースのまわりのホストの要素(`wrapper`・`extensionButton`・`watermark`)を返す。ドックしたスクリプトの整列は、透かしに `data-code-watermark`、拡張ボタンに `data-code-extension-button` の印を付け、スタイルシートはこの印で、ホバーで出す面と非アクティブな分割表示の中でそれらを隠す。
|
|
29
29
|
|
|
30
|
+
### 保存するコードエリア
|
|
31
|
+
|
|
32
|
+
コードのペインのアダプター(`createCodePaneAdapter`)は、workbench が保存する作業領域のために `serialize(pane, presentation?)` と `deserialize(pane, value)` を持つ。Editor はこの作業領域を SB3 に保存する。タブは、コードエリアのズーム・スクロール位置・スクリプト表示を `{scale, x, y, scriptView?}` として保存する。presentation がないとき、`serialize` は画面のコードエリアを変えずに読む。`deserialize` は `readSavedCodePane` で形を確かめ、コードエリアの操作部品の写しを含まない presentation を返す。プレビューは写しなしで描く。
|
|
33
|
+
|
|
30
34
|
Editor は GUI の React 16 にこれらを描画するので、React 16.14 以降に対応する。
|
|
31
35
|
|
|
32
36
|
## 検証
|
package/README.md
CHANGED
|
@@ -27,6 +27,10 @@ Load `@kubohiroya/turbowarp-plus-editor-code-views/styles.css` as a global style
|
|
|
27
27
|
|
|
28
28
|
`attachCodeWorkspace` and `attachDockedScriptLayout` take `presentationElements(injection)`, which returns the host's elements around the workspace: `wrapper`, `extensionButton` and `watermark`. The docked script layout marks the watermark with `data-code-watermark` and the extension button with `data-code-extension-button`, and the stylesheet hides them by those marks on a hover surface and in an inactive split view.
|
|
29
29
|
|
|
30
|
+
### Saved code areas
|
|
31
|
+
|
|
32
|
+
The code pane adapter (`createCodePaneAdapter`) has `serialize(pane, presentation?)` and `deserialize(pane, value)` for the workbench's saved workspace, which the Editor keeps in the SB3. A tab keeps the zoom, scroll position and script view of its code area as `{scale, x, y, scriptView?}`. Without a presentation, `serialize` reads the code area on screen without changing it. `deserialize` checks the shape with `readSavedCodePane` and returns a presentation without the copied controls of the code area, which the preview then draws without them.
|
|
33
|
+
|
|
30
34
|
React 16.14 or later is supported, because the Editor mounts these views in the GUI's React 16.
|
|
31
35
|
|
|
32
36
|
## Verification
|
package/dist/code-pane.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getCodeSession } from './workspace.ts';
|
|
2
2
|
import type { AttachPreviewMinimap, AttachWorkspaceNavigation } from './workspace.ts';
|
|
3
|
+
import { type ScriptView } from './script-layout-view.ts';
|
|
3
4
|
type Pane = {
|
|
4
5
|
id: string;
|
|
5
6
|
targetId: string;
|
|
@@ -7,6 +8,15 @@ type Pane = {
|
|
|
7
8
|
};
|
|
8
9
|
type Bridge = NonNullable<ReturnType<typeof getCodeSession>['bridge']>;
|
|
9
10
|
type Presentation = NonNullable<ReturnType<Bridge['capturePane']>>;
|
|
11
|
+
/** The code area of a tab as a saved workspace keeps it: zoom, scroll position and script view. */
|
|
12
|
+
export interface SavedCodePane {
|
|
13
|
+
scale: number;
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
scriptView?: ScriptView;
|
|
17
|
+
}
|
|
18
|
+
/** Read a saved code area back, or nothing if it does not have the shape `serialize` writes. */
|
|
19
|
+
export declare function readSavedCodePane(value: Record<string, unknown>): SavedCodePane | undefined;
|
|
10
20
|
export declare function createCodePaneAdapter(vm: any, locale: string, attachMinimap?: AttachPreviewMinimap): {
|
|
11
21
|
/**
|
|
12
22
|
* Make a code view show one script, a hat or a function, or every script again without `scriptId`.
|
|
@@ -19,6 +29,13 @@ export declare function createCodePaneAdapter(vm: any, locale: string, attachMin
|
|
|
19
29
|
ownsClick: (element: EventTarget) => boolean;
|
|
20
30
|
watchEditingCostume: (image: HTMLImageElement) => () => void;
|
|
21
31
|
capture(pane: Pane): import("./workspace.ts").Presentation;
|
|
32
|
+
/**
|
|
33
|
+
* The code area of a tab for a saved workspace. Without a presentation, the code area on screen is read; a
|
|
34
|
+
* presentation still waiting to be applied is what that tab shows.
|
|
35
|
+
*/
|
|
36
|
+
serialize(pane: Pane, presentation?: Presentation): SavedCodePane | undefined;
|
|
37
|
+
/** A presentation from a saved code area. The preview draws it without the chrome of the code area. */
|
|
38
|
+
deserialize(pane: Pane, value: Record<string, unknown>): Presentation | undefined;
|
|
22
39
|
restore(pane: Pane, presentation?: Presentation): void;
|
|
23
40
|
renderInactive(container: HTMLElement, pane: Pane, presentation?: Presentation): () => void;
|
|
24
41
|
};
|
package/dist/code-pane.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { getCodeSession } from "./workspace.js";
|
|
2
2
|
import { getDockedScriptLayout } from "./script-layout-view.js";
|
|
3
|
+
const scriptViews = ['free', 'z', 'n'];
|
|
4
|
+
const finite = (value, limit) => typeof value === 'number' && Number.isFinite(value) && Math.abs(value) <= limit;
|
|
5
|
+
/** Read a saved code area back, or nothing if it does not have the shape `serialize` writes. */
|
|
6
|
+
export function readSavedCodePane(value) {
|
|
7
|
+
const { scale, x, y, scriptView } = value;
|
|
8
|
+
if (!finite(scale, 100) || scale <= 0 || !finite(x, 1e7) || !finite(y, 1e7))
|
|
9
|
+
return;
|
|
10
|
+
return { scale, x, y, ...(scriptViews.includes(scriptView) && { scriptView: scriptView }) };
|
|
11
|
+
}
|
|
3
12
|
export function createCodePaneAdapter(vm, locale, attachMinimap) {
|
|
4
13
|
const session = getCodeSession(vm);
|
|
5
14
|
const label = /^ja(?:-|$)/i.test(locale) ? 'このペインでコードを編集' : 'Edit code in this pane';
|
|
@@ -87,6 +96,32 @@ export function createCodePaneAdapter(vm, locale, attachMinimap) {
|
|
|
87
96
|
views.set(pane.id, getDockedScriptLayout(vm)?.view.view ?? 'free');
|
|
88
97
|
return session.bridge?.capturePane(pane.targetId);
|
|
89
98
|
},
|
|
99
|
+
/**
|
|
100
|
+
* The code area of a tab for a saved workspace. Without a presentation, the code area on screen is read; a
|
|
101
|
+
* presentation still waiting to be applied is what that tab shows.
|
|
102
|
+
*/
|
|
103
|
+
serialize(pane, presentation) {
|
|
104
|
+
if (pane.section !== 0)
|
|
105
|
+
return;
|
|
106
|
+
const shown = presentation ?? (pending?.pane.id === pane.id ? pending.presentation :
|
|
107
|
+
session.bridge?.capturePane(pane.targetId));
|
|
108
|
+
if (!shown)
|
|
109
|
+
return;
|
|
110
|
+
const scriptView = presentation ? presentation.scriptView : views.get(pane.id) ??
|
|
111
|
+
getDockedScriptLayout(vm)?.view.view;
|
|
112
|
+
return { scale: shown.scale, x: shown.x, y: shown.y, ...(scriptView && { scriptView }) };
|
|
113
|
+
},
|
|
114
|
+
/** A presentation from a saved code area. The preview draws it without the chrome of the code area. */
|
|
115
|
+
deserialize(pane, value) {
|
|
116
|
+
if (pane.section !== 0)
|
|
117
|
+
return;
|
|
118
|
+
const saved = readSavedCodePane(value);
|
|
119
|
+
if (!saved)
|
|
120
|
+
return;
|
|
121
|
+
if (saved.scriptView)
|
|
122
|
+
views.set(pane.id, saved.scriptView);
|
|
123
|
+
return { scale: saved.scale, x: saved.x, y: saved.y, visible: true, ...(saved.scriptView && { scriptView: saved.scriptView }) };
|
|
124
|
+
},
|
|
90
125
|
restore(pane, presentation) {
|
|
91
126
|
if (pending)
|
|
92
127
|
cancelAnimationFrame(pending.frame);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { createCodePaneAdapter } from './code-pane.ts';
|
|
3
3
|
export { attachCodeWorkspace } from './workspace.ts';
|
|
4
|
-
export { attachFunctionCallMenu, createCodePaneAdapter, createFunction, mountProcedureEditor, readHatScripts } from './code-pane.ts';
|
|
4
|
+
export { attachFunctionCallMenu, createCodePaneAdapter, createFunction, mountProcedureEditor, readHatScripts, readSavedCodePane } from './code-pane.ts';
|
|
5
|
+
export type { SavedCodePane } from './code-pane.ts';
|
|
5
6
|
export declare function CodePaneCostumeThumbnail({ adapter }: {
|
|
6
7
|
adapter: ReturnType<typeof createCodePaneAdapter>;
|
|
7
8
|
}): React.JSX.Element;
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { createPortal } from 'react-dom';
|
|
3
3
|
import { getCodeSession } from "./workspace.js";
|
|
4
4
|
export { attachCodeWorkspace } from "./workspace.js";
|
|
5
|
-
export { attachFunctionCallMenu, createCodePaneAdapter, createFunction, mountProcedureEditor, readHatScripts } from "./code-pane.js";
|
|
5
|
+
export { attachFunctionCallMenu, createCodePaneAdapter, createFunction, mountProcedureEditor, readHatScripts, readSavedCodePane } from "./code-pane.js";
|
|
6
6
|
export function CodePaneCostumeThumbnail({ adapter }) {
|
|
7
7
|
const image = React.useRef(null);
|
|
8
8
|
React.useLayoutEffect(() => adapter.watchEditingCostume(image.current), [adapter]);
|
package/dist/workspace.d.ts
CHANGED
|
@@ -15,7 +15,8 @@ export interface Presentation {
|
|
|
15
15
|
y: number;
|
|
16
16
|
visible: boolean;
|
|
17
17
|
scriptView?: ScriptView;
|
|
18
|
-
|
|
18
|
+
/** Missing for a presentation read back from a saved workspace; the preview then draws without it. */
|
|
19
|
+
chrome?: ReturnType<typeof captureCodePreviewChrome>;
|
|
19
20
|
}
|
|
20
21
|
interface CodeSession {
|
|
21
22
|
frontView: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-plus-editor-code-views",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Code views for TurboWarp Plus Editor: code in tabs and windows, the detached block palette, script layout and block field editing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MPL-2.0",
|
package/src/code-pane.ts
CHANGED
|
@@ -6,6 +6,25 @@ type Pane = {id: string; targetId: string; section: number};
|
|
|
6
6
|
type Bridge = NonNullable<ReturnType<typeof getCodeSession>['bridge']>;
|
|
7
7
|
type Presentation = NonNullable<ReturnType<Bridge['capturePane']>>;
|
|
8
8
|
|
|
9
|
+
/** The code area of a tab as a saved workspace keeps it: zoom, scroll position and script view. */
|
|
10
|
+
export interface SavedCodePane {
|
|
11
|
+
scale: number;
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
scriptView?: ScriptView;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const scriptViews: readonly ScriptView[] = ['free', 'z', 'n'];
|
|
18
|
+
const finite = (value: unknown, limit: number): value is number =>
|
|
19
|
+
typeof value === 'number' && Number.isFinite(value) && Math.abs(value) <= limit;
|
|
20
|
+
|
|
21
|
+
/** Read a saved code area back, or nothing if it does not have the shape `serialize` writes. */
|
|
22
|
+
export function readSavedCodePane(value: Record<string, unknown>): SavedCodePane | undefined {
|
|
23
|
+
const {scale, x, y, scriptView} = value;
|
|
24
|
+
if (!finite(scale, 100) || scale <= 0 || !finite(x, 1e7) || !finite(y, 1e7)) return;
|
|
25
|
+
return {scale, x, y, ...(scriptViews.includes(scriptView as ScriptView) && {scriptView: scriptView as ScriptView})};
|
|
26
|
+
}
|
|
27
|
+
|
|
9
28
|
export function createCodePaneAdapter(vm, locale: string, attachMinimap?: AttachPreviewMinimap) {
|
|
10
29
|
const session = getCodeSession(vm);
|
|
11
30
|
const label = /^ja(?:-|$)/i.test(locale) ? 'このペインでコードを編集' : 'Edit code in this pane';
|
|
@@ -84,6 +103,27 @@ export function createCodePaneAdapter(vm, locale: string, attachMinimap?: Attach
|
|
|
84
103
|
views.set(pane.id, getDockedScriptLayout(vm)?.view.view ?? 'free');
|
|
85
104
|
return session.bridge?.capturePane(pane.targetId);
|
|
86
105
|
},
|
|
106
|
+
/**
|
|
107
|
+
* The code area of a tab for a saved workspace. Without a presentation, the code area on screen is read; a
|
|
108
|
+
* presentation still waiting to be applied is what that tab shows.
|
|
109
|
+
*/
|
|
110
|
+
serialize(pane: Pane, presentation?: Presentation): SavedCodePane | undefined {
|
|
111
|
+
if (pane.section !== 0) return;
|
|
112
|
+
const shown = presentation ?? (pending?.pane.id === pane.id ? pending.presentation :
|
|
113
|
+
session.bridge?.capturePane(pane.targetId));
|
|
114
|
+
if (!shown) return;
|
|
115
|
+
const scriptView = presentation ? presentation.scriptView : views.get(pane.id) ??
|
|
116
|
+
getDockedScriptLayout(vm)?.view.view;
|
|
117
|
+
return {scale: shown.scale, x: shown.x, y: shown.y, ...(scriptView && {scriptView})};
|
|
118
|
+
},
|
|
119
|
+
/** A presentation from a saved code area. The preview draws it without the chrome of the code area. */
|
|
120
|
+
deserialize(pane: Pane, value: Record<string, unknown>): Presentation | undefined {
|
|
121
|
+
if (pane.section !== 0) return;
|
|
122
|
+
const saved = readSavedCodePane(value);
|
|
123
|
+
if (!saved) return;
|
|
124
|
+
if (saved.scriptView) views.set(pane.id, saved.scriptView);
|
|
125
|
+
return {scale: saved.scale, x: saved.x, y: saved.y, visible: true, ...(saved.scriptView && {scriptView: saved.scriptView})};
|
|
126
|
+
},
|
|
87
127
|
restore(pane: Pane, presentation?: Presentation) {
|
|
88
128
|
if (pending) cancelAnimationFrame(pending.frame);
|
|
89
129
|
pending = undefined;
|
|
@@ -4,7 +4,8 @@ import type {createCodePaneAdapter} from './code-pane.ts';
|
|
|
4
4
|
import {getCodeSession} from './workspace.ts';
|
|
5
5
|
|
|
6
6
|
export {attachCodeWorkspace} from './workspace.ts';
|
|
7
|
-
export {attachFunctionCallMenu, createCodePaneAdapter, createFunction, mountProcedureEditor, readHatScripts} from './code-pane.ts';
|
|
7
|
+
export {attachFunctionCallMenu, createCodePaneAdapter, createFunction, mountProcedureEditor, readHatScripts, readSavedCodePane} from './code-pane.ts';
|
|
8
|
+
export type {SavedCodePane} from './code-pane.ts';
|
|
8
9
|
|
|
9
10
|
export function CodePaneCostumeThumbnail({adapter}: {adapter: ReturnType<typeof createCodePaneAdapter>}) {
|
|
10
11
|
const image = React.useRef<HTMLImageElement>(null);
|
package/src/workspace.ts
CHANGED
|
@@ -17,7 +17,8 @@ export interface Presentation {
|
|
|
17
17
|
y: number;
|
|
18
18
|
visible: boolean;
|
|
19
19
|
scriptView?: ScriptView;
|
|
20
|
-
|
|
20
|
+
/** Missing for a presentation read back from a saved workspace; the preview then draws without it. */
|
|
21
|
+
chrome?: ReturnType<typeof captureCodePreviewChrome>;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
interface CodeSession {
|