@kubohiroya/turbowarp-plus-editor-workbench 0.19.1 → 0.21.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
@@ -144,6 +144,8 @@ Editor のルートから、`site/source.json` の GUI を `npm run build:pages`
144
144
 
145
145
  `attachStageInput` は、ホストから渡された別ウィンドウの document とキャンバスを使って、入力の購読と解放を管理する。ポインター処理とドラッグ状態の解除はホストのコールバックを使用する。
146
146
 
147
+ 日本語・中国語・韓国語の IME がオンのとき、ブラウザーは IME が受け取ったキーを `Process`(または IME が打つかな)と報告し、VM はこれを無視する。`attachStageInput` は `event.code` から元のキーを復元する。本体の document では、`@kubohiroya/turbowarp-plus-editor-workbench/ime-key` の `installImeKeyInput(document)` が capture 段階で `key` と `keyCode` を直し、ステージが読む前に同じ復元を行う。テキスト欄に向かうイベントは IME の報告のまま残す。
148
+
147
149
  スプライト編集タブの中のペイン(素材と変数、メッセージ、設定フォーム、セクション切り替えのツールバー)は `@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 に組み込めなくなる。
148
150
 
149
151
  ## デバッガーのタブ
package/README.md CHANGED
@@ -147,6 +147,8 @@ From the Editor root, build the GUI pinned in `site/source.json` with `npm run b
147
147
 
148
148
  `attachStageInput` manages input subscriptions and cleanup using the separate window's document and canvas provided by the host. Pointer handling and drag cleanup use the host's callbacks.
149
149
 
150
+ With a Japanese, Chinese or Korean IME on, the browser reports the key the IME took as `Process` (or as the kana the IME would type), which the VM ignores. `attachStageInput` recovers the key from `event.code`, and `installImeKeyInput(document)` from `/turbowarp-plus-editor-workbench/ime-key` does the same for the main document by correcting `key` and `keyCode` in the capture phase, before the stage reads them. Events aimed at text fields keep what the IME reported.
151
+
150
152
  The panes inside a sprite editing tab (assets and variables, messages, the properties form and the section toolbar) now live in `@kubohiroya/turbowarp-plus-editor-sprite-panes`; this package arranges them into tabs and splits. The window components, which came from the source of the previous release archive at `b0390c3`, now live in `@kubohiroya/turbowarp-plus-editor-windows`. The extraction kept the upstream Scratch GUI implementation in its original repository, so this package carries no GPL code and imports no GPL module. It is licensed MPL-2.0, which the GPL-3.0 Editor can still bundle because MPL-2.0 treats the GPL as a Secondary License. The source files carry no “Incompatible With Secondary Licenses” notice, and must not: that notice would make the package unusable in the Editor.
151
153
 
152
154
  ## Debugger tab
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Keys pressed while a Japanese, Chinese or Korean IME is on.
3
+ *
4
+ * The stage hands `event.key` to the VM. With an IME on, the browser reports a key that the IME
5
+ * takes as `Process` (keyCode 229), and in kana input mode some browsers report the kana it would
6
+ * type (`ち` for A). The VM drops `Process` and matches `ち` against no key, so "when [a] key
7
+ * pressed" and "key [space] pressed?" stay silent until the user turns the IME off. `event.code`
8
+ * still names the physical key, so the key the VM expects can be recovered from it.
9
+ */
10
+ export type ScratchKey = {
11
+ key: string;
12
+ keyCode: number;
13
+ };
14
+ /**
15
+ * The key and keyCode of a physical key, for the keys Scratch has a name for.
16
+ * @param {string} code The event's `code`.
17
+ * @param {boolean} shiftKey Whether Shift was held, which makes a letter upper case.
18
+ * @returns {ScratchKey | null} The key, or null for a key Scratch has no name for.
19
+ */
20
+ export declare const keyFromCode: (code: string, shiftKey?: boolean) => ScratchKey | null;
21
+ /**
22
+ * The key an event would have reported with the IME off, when the IME changed it.
23
+ * @param {KeyboardEvent} event The key event.
24
+ * @returns {ScratchKey | null} The recovered key, or null when the event needs no change.
25
+ */
26
+ export declare const imeScratchKey: (event: Pick<KeyboardEvent, "key" | "code" | "keyCode" | "shiftKey">) => ScratchKey | null;
27
+ /**
28
+ * Correct key events that reach the document itself, before the stage's own listeners read them.
29
+ * Events aimed at a text field or a block's field editor are left alone, so typing with the IME
30
+ * still works there.
31
+ * @param {Document} document The document whose stage takes key input.
32
+ * @returns {() => void} A function that removes the correction.
33
+ */
34
+ export declare function installImeKeyInput(document: Document): () => void;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Keys pressed while a Japanese, Chinese or Korean IME is on.
3
+ *
4
+ * The stage hands `event.key` to the VM. With an IME on, the browser reports a key that the IME
5
+ * takes as `Process` (keyCode 229), and in kana input mode some browsers report the kana it would
6
+ * type (`ち` for A). The VM drops `Process` and matches `ち` against no key, so "when [a] key
7
+ * pressed" and "key [space] pressed?" stay silent until the user turns the IME off. `event.code`
8
+ * still names the physical key, so the key the VM expects can be recovered from it.
9
+ */
10
+ /** A key the IME took, or a kana, ideographic or full-width character the IME would type. */
11
+ const imeKey = /^[ -ヿ!-゚]$/;
12
+ const namedKeys = {
13
+ Space: { key: ' ', keyCode: 32 },
14
+ Enter: { key: 'Enter', keyCode: 13 },
15
+ NumpadEnter: { key: 'Enter', keyCode: 13 },
16
+ Backspace: { key: 'Backspace', keyCode: 8 },
17
+ Escape: { key: 'Escape', keyCode: 27 },
18
+ ArrowLeft: { key: 'ArrowLeft', keyCode: 37 },
19
+ ArrowUp: { key: 'ArrowUp', keyCode: 38 },
20
+ ArrowRight: { key: 'ArrowRight', keyCode: 39 },
21
+ ArrowDown: { key: 'ArrowDown', keyCode: 40 }
22
+ };
23
+ /**
24
+ * The key and keyCode of a physical key, for the keys Scratch has a name for.
25
+ * @param {string} code The event's `code`.
26
+ * @param {boolean} shiftKey Whether Shift was held, which makes a letter upper case.
27
+ * @returns {ScratchKey | null} The key, or null for a key Scratch has no name for.
28
+ */
29
+ export const keyFromCode = (code, shiftKey = false) => {
30
+ const letter = /^Key([A-Z])$/.exec(code);
31
+ if (letter)
32
+ return { key: shiftKey ? letter[1] : letter[1].toLowerCase(), keyCode: letter[1].charCodeAt(0) };
33
+ const digit = /^(Digit|Numpad)([0-9])$/.exec(code);
34
+ if (digit)
35
+ return { key: digit[2], keyCode: (digit[1] === 'Digit' ? 48 : 96) + Number(digit[2]) };
36
+ return namedKeys[code] ?? null;
37
+ };
38
+ /**
39
+ * The key an event would have reported with the IME off, when the IME changed it.
40
+ * @param {KeyboardEvent} event The key event.
41
+ * @returns {ScratchKey | null} The recovered key, or null when the event needs no change.
42
+ */
43
+ export const imeScratchKey = (event) => {
44
+ const { key, code, keyCode, shiftKey } = event;
45
+ if (key !== 'Process' && keyCode !== 229 && !imeKey.test(key ?? ''))
46
+ return null;
47
+ return code ? keyFromCode(code, shiftKey) : null;
48
+ };
49
+ /**
50
+ * Correct key events that reach the document itself, before the stage's own listeners read them.
51
+ * Events aimed at a text field or a block's field editor are left alone, so typing with the IME
52
+ * still works there.
53
+ * @param {Document} document The document whose stage takes key input.
54
+ * @returns {() => void} A function that removes the correction.
55
+ */
56
+ export function installImeKeyInput(document) {
57
+ const window = document.defaultView;
58
+ if (!window)
59
+ return () => { };
60
+ const correct = (event) => {
61
+ if (event.target !== document && event.target !== document.body)
62
+ return;
63
+ const recovered = imeScratchKey(event);
64
+ if (!recovered)
65
+ return;
66
+ Object.defineProperty(event, 'key', { value: recovered.key, configurable: true });
67
+ Object.defineProperty(event, 'keyCode', { value: recovered.keyCode, configurable: true });
68
+ Object.defineProperty(event, 'which', { value: recovered.keyCode, configurable: true });
69
+ };
70
+ window.addEventListener('keydown', correct, true);
71
+ window.addEventListener('keyup', correct, true);
72
+ return () => {
73
+ window.removeEventListener('keydown', correct, true);
74
+ window.removeEventListener('keyup', correct, true);
75
+ };
76
+ }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { attachExternalMonitorDrag } from './monitor-drag.ts';
2
2
  export { attachStageInput } from './stage-input.ts';
3
+ export { imeScratchKey, installImeKeyInput, keyFromCode } from './ime-key.ts';
3
4
  export { panelLayoutIconPath } from './sprite-layout-menu.ts';
4
5
  type Axis = 'columns' | 'rows';
5
6
  type Ratios = Record<Axis, number | null>;
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export { attachExternalMonitorDrag } from "./monitor-drag.js";
2
2
  export { attachStageInput } from "./stage-input.js";
3
+ export { imeScratchKey, installImeKeyInput, keyFromCode } from "./ime-key.js";
3
4
  export { panelLayoutIconPath } from "./sprite-layout-menu.js";
4
5
  const separatorSize = 8;
5
6
  const keyboardStep = 16;
@@ -18,6 +18,12 @@ export type SaveAsRequest = {
18
18
  export interface SaveAsFormOptions {
19
19
  openCommit?: Action;
20
20
  folder?: {
21
+ /**
22
+ * `browser` keeps the new folder in the browser, as the project folder package does where there is no folder
23
+ * picker. The form then offers the folder format without the picker, keeps the name for the new folder, and
24
+ * leaves out the overwrite warning, since such a folder is always new. Defaults to `device`.
25
+ */
26
+ location?: 'device' | 'browser';
21
27
  overwriteWarning?: string;
22
28
  github?: {
23
29
  connectForCreation(interaction: CreationInteraction): Promise<GitHubCreationAccount | null>;
@@ -222,7 +222,8 @@ export function renderSaveAsForm(document, locale, storage, save, close, { folde
222
222
  appendOption(format, label('SB3(現在の格納方式)', 'SB3 (current storage settings)'), 'current');
223
223
  appendOption(format, label('SB3(設定対象の台本・素材を同梱)', 'SB3 (embed configured scripts and assets)'), 'embedded');
224
224
  const picker = document.defaultView?.showDirectoryPicker;
225
- const folderAvailable = folder && typeof picker === 'function';
225
+ const inBrowser = folder?.location === 'browser';
226
+ const folderAvailable = folder && (inBrowser || typeof picker === 'function');
226
227
  if (folderAvailable)
227
228
  appendOption(format, label('プロジェクトフォルダ', 'Project folder'), 'folder');
228
229
  appendField(fields, label('保存形式', 'Save format'), format);
@@ -333,7 +334,8 @@ export function renderSaveAsForm(document, locale, storage, save, close, { folde
333
334
  const refresh = () => {
334
335
  const reviewing = confirmedDraft !== null || task !== null;
335
336
  const creation = selectedGitHub();
336
- const localFolder = savingFolder() && !creation;
337
+ // A folder on the device takes its name from the picked folder; a folder in the browser keeps this name.
338
+ const localFolder = savingFolder() && !creation && !inBrowser;
337
339
  overwriteWarning.hidden = !localFolder;
338
340
  fields.hidden = reviewing;
339
341
  review.hidden = !reviewing;
@@ -355,7 +357,8 @@ export function renderSaveAsForm(document, locale, storage, save, close, { folde
355
357
  pending.hidden = reviewing || !pending.childElementCount;
356
358
  submit.textContent = task ? actionText(task.phase) : reviewing ? label('リポジトリを作成', 'Create Repository') : creation ?
357
359
  (creation.connected ? label('作成内容を確認', 'Review Repository') : label('GitHub へ接続…', 'Connect to GitHub…')) :
358
- (savingFolder() || storage.pick ? label('保存先を選ぶ…', 'Choose Where to Save…') : label('保存', 'Save'));
360
+ savingFolder() && inBrowser ? label('ブラウザー内に保存…', 'Save in This Browser…') :
361
+ (savingFolder() || storage.pick ? label('保存先を選ぶ…', 'Choose Where to Save…') : label('保存', 'Save'));
359
362
  };
360
363
  const loadPending = async () => {
361
364
  if (!publication)
@@ -1,3 +1,4 @@
1
+ import { imeScratchKey } from "./ime-key.js";
1
2
  /**
2
3
  * Connect a stage to the document hosting its canvas. The stage supplies its
3
4
  * pointer handlers and clears its own drag state when the document loses focus.
@@ -10,7 +11,8 @@ export function attachStageInput({ document, canvas, onMove, onUp, releasePointe
10
11
  return;
11
12
  if (event.ctrlKey || event.metaKey || event.altKey)
12
13
  return;
13
- const { code, key, keyCode } = event;
14
+ const { code } = event;
15
+ const { key, keyCode } = imeScratchKey(event) ?? event;
14
16
  const id = code || keyCode;
15
17
  if (!keys.has(id)) {
16
18
  const data = { key: key && key !== 'Dead' ? key : keyCode, keyCode };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-plus-editor-workbench",
3
- "version": "0.19.1",
3
+ "version": "0.21.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",
@@ -46,6 +46,10 @@
46
46
  "default": "./dist/extension-file-menu.js"
47
47
  },
48
48
  "./info-menu.css": "./src/info-menu.css",
49
+ "./ime-key": {
50
+ "types": "./dist/ime-key.d.ts",
51
+ "default": "./dist/ime-key.js"
52
+ },
49
53
  "./project-file-dialogs": {
50
54
  "types": "./dist/project-file-dialogs.d.ts",
51
55
  "default": "./dist/project-file-dialogs.js"
package/src/ime-key.ts ADDED
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Keys pressed while a Japanese, Chinese or Korean IME is on.
3
+ *
4
+ * The stage hands `event.key` to the VM. With an IME on, the browser reports a key that the IME
5
+ * takes as `Process` (keyCode 229), and in kana input mode some browsers report the kana it would
6
+ * type (`ち` for A). The VM drops `Process` and matches `ち` against no key, so "when [a] key
7
+ * pressed" and "key [space] pressed?" stay silent until the user turns the IME off. `event.code`
8
+ * still names the physical key, so the key the VM expects can be recovered from it.
9
+ */
10
+
11
+ export type ScratchKey = {key: string; keyCode: number};
12
+
13
+ /** A key the IME took, or a kana, ideographic or full-width character the IME would type. */
14
+ const imeKey = /^[ -ヿ!-゚]$/;
15
+
16
+ const namedKeys: Readonly<Record<string, ScratchKey>> = {
17
+ Space: {key: ' ', keyCode: 32},
18
+ Enter: {key: 'Enter', keyCode: 13},
19
+ NumpadEnter: {key: 'Enter', keyCode: 13},
20
+ Backspace: {key: 'Backspace', keyCode: 8},
21
+ Escape: {key: 'Escape', keyCode: 27},
22
+ ArrowLeft: {key: 'ArrowLeft', keyCode: 37},
23
+ ArrowUp: {key: 'ArrowUp', keyCode: 38},
24
+ ArrowRight: {key: 'ArrowRight', keyCode: 39},
25
+ ArrowDown: {key: 'ArrowDown', keyCode: 40}
26
+ };
27
+
28
+ /**
29
+ * The key and keyCode of a physical key, for the keys Scratch has a name for.
30
+ * @param {string} code The event's `code`.
31
+ * @param {boolean} shiftKey Whether Shift was held, which makes a letter upper case.
32
+ * @returns {ScratchKey | null} The key, or null for a key Scratch has no name for.
33
+ */
34
+ export const keyFromCode = (code: string, shiftKey = false): ScratchKey | null => {
35
+ const letter = /^Key([A-Z])$/.exec(code);
36
+ if (letter) return {key: shiftKey ? letter[1] : letter[1].toLowerCase(), keyCode: letter[1].charCodeAt(0)};
37
+ const digit = /^(Digit|Numpad)([0-9])$/.exec(code);
38
+ if (digit) return {key: digit[2], keyCode: (digit[1] === 'Digit' ? 48 : 96) + Number(digit[2])};
39
+ return namedKeys[code] ?? null;
40
+ };
41
+
42
+ /**
43
+ * The key an event would have reported with the IME off, when the IME changed it.
44
+ * @param {KeyboardEvent} event The key event.
45
+ * @returns {ScratchKey | null} The recovered key, or null when the event needs no change.
46
+ */
47
+ export const imeScratchKey = (event: Pick<KeyboardEvent, 'key' | 'code' | 'keyCode' | 'shiftKey'>): ScratchKey | null => {
48
+ const {key, code, keyCode, shiftKey} = event;
49
+ if (key !== 'Process' && keyCode !== 229 && !imeKey.test(key ?? '')) return null;
50
+ return code ? keyFromCode(code, shiftKey) : null;
51
+ };
52
+
53
+ /**
54
+ * Correct key events that reach the document itself, before the stage's own listeners read them.
55
+ * Events aimed at a text field or a block's field editor are left alone, so typing with the IME
56
+ * still works there.
57
+ * @param {Document} document The document whose stage takes key input.
58
+ * @returns {() => void} A function that removes the correction.
59
+ */
60
+ export function installImeKeyInput (document: Document) {
61
+ const window = document.defaultView;
62
+ if (!window) return () => {};
63
+ const correct = (event: Event) => {
64
+ if (event.target !== document && event.target !== document.body) return;
65
+ const recovered = imeScratchKey(event as KeyboardEvent);
66
+ if (!recovered) return;
67
+ Object.defineProperty(event, 'key', {value: recovered.key, configurable: true});
68
+ Object.defineProperty(event, 'keyCode', {value: recovered.keyCode, configurable: true});
69
+ Object.defineProperty(event, 'which', {value: recovered.keyCode, configurable: true});
70
+ };
71
+ window.addEventListener('keydown', correct, true);
72
+ window.addEventListener('keyup', correct, true);
73
+ return () => {
74
+ window.removeEventListener('keydown', correct, true);
75
+ window.removeEventListener('keyup', correct, true);
76
+ };
77
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export {attachExternalMonitorDrag} from './monitor-drag.ts';
2
2
  export {attachStageInput} from './stage-input.ts';
3
+ export {imeScratchKey, installImeKeyInput, keyFromCode} from './ime-key.ts';
3
4
  export {panelLayoutIconPath} from './sprite-layout-menu.ts';
4
5
 
5
6
  type Axis = 'columns' | 'rows';
@@ -14,6 +14,12 @@ export type SaveAsRequest =
14
14
  export interface SaveAsFormOptions {
15
15
  openCommit?: Action;
16
16
  folder?: {
17
+ /**
18
+ * `browser` keeps the new folder in the browser, as the project folder package does where there is no folder
19
+ * picker. The form then offers the folder format without the picker, keeps the name for the new folder, and
20
+ * leaves out the overwrite warning, since such a folder is always new. Defaults to `device`.
21
+ */
22
+ location?: 'device' | 'browser';
17
23
  overwriteWarning?: string;
18
24
  github?: {
19
25
  // The host can reuse a current session or open sign-in. The form retains its draft either way.
@@ -270,7 +276,8 @@ export function renderSaveAsForm(document: Document, locale: string, storage: Pr
270
276
  appendOption(format, label('SB3(現在の格納方式)', 'SB3 (current storage settings)'), 'current');
271
277
  appendOption(format, label('SB3(設定対象の台本・素材を同梱)', 'SB3 (embed configured scripts and assets)'), 'embedded');
272
278
  const picker = (document.defaultView as (Window & {showDirectoryPicker?: unknown}) | null)?.showDirectoryPicker;
273
- const folderAvailable = folder && typeof picker === 'function';
279
+ const inBrowser = folder?.location === 'browser';
280
+ const folderAvailable = folder && (inBrowser || typeof picker === 'function');
274
281
  if (folderAvailable) appendOption(format, label('プロジェクトフォルダ', 'Project folder'), 'folder');
275
282
  appendField(fields, label('保存形式', 'Save format'), format);
276
283
 
@@ -386,7 +393,8 @@ export function renderSaveAsForm(document: Document, locale: string, storage: Pr
386
393
  const refresh = () => {
387
394
  const reviewing = confirmedDraft !== null || task !== null;
388
395
  const creation = selectedGitHub();
389
- const localFolder = savingFolder() && !creation;
396
+ // A folder on the device takes its name from the picked folder; a folder in the browser keeps this name.
397
+ const localFolder = savingFolder() && !creation && !inBrowser;
390
398
  overwriteWarning.hidden = !localFolder;
391
399
  fields.hidden = reviewing;
392
400
  review.hidden = !reviewing;
@@ -408,6 +416,7 @@ export function renderSaveAsForm(document: Document, locale: string, storage: Pr
408
416
  pending.hidden = reviewing || !pending.childElementCount;
409
417
  submit.textContent = task ? actionText(task.phase) : reviewing ? label('リポジトリを作成', 'Create Repository') : creation ?
410
418
  (creation.connected ? label('作成内容を確認', 'Review Repository') : label('GitHub へ接続…', 'Connect to GitHub…')) :
419
+ savingFolder() && inBrowser ? label('ブラウザー内に保存…', 'Save in This Browser…') :
411
420
  (savingFolder() || storage.pick ? label('保存先を選ぶ…', 'Choose Where to Save…') : label('保存', 'Save'));
412
421
  };
413
422
  const loadPending = async () => {
@@ -1,3 +1,5 @@
1
+ import {imeScratchKey} from './ime-key.ts';
2
+
1
3
  type Key = {key: string | number; keyCode: number};
2
4
 
3
5
  interface StageInput {
@@ -21,7 +23,8 @@ export function attachStageInput({document, canvas, onMove, onUp, releasePointer
21
23
  function keyDown(event: KeyboardEvent) {
22
24
  if (event.target !== document && event.target !== document.body && event.target !== canvas) return;
23
25
  if (event.ctrlKey || event.metaKey || event.altKey) return;
24
- const {code, key, keyCode} = event;
26
+ const {code} = event;
27
+ const {key, keyCode} = imeScratchKey(event) ?? event;
25
28
  const id = code || keyCode;
26
29
  if (!keys.has(id)) {
27
30
  const data = {key: key && key !== 'Dead' ? key : keyCode, keyCode};