@kubohiroya/turbowarp-plus-editor-code-views 0.4.0 → 0.6.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
@@ -19,6 +19,7 @@ TurboWarp Plus Editor のコードの画面。1つの作品と1つの取り消
19
19
  | `./palette-category-reorder`・`./palette-category-search`・`./palette-dropdown-resize` | パレットのカテゴリの並べ替えと検索、パレットのドロップダウンの大きさの変更 |
20
20
  | `./palette-category-visibility`・`./palette-visibility-dialog` | スプライト・背景ごとに、パレットに出すブロックグループを選ぶ。設定はエディターの画面状態として保存し、選ぶ画面を持つ |
21
21
  | `./block-argument-text` | 長いテキストの引数を短く表示し、ダイアログで編集する |
22
+ | `./block-number-input` | 数値の引数に入力した全角の数字・記号を半角にする |
22
23
  | `./asset-edit-session`・`./dockview-unsaved` | 素材の編集のセッションと、Dockview のタブの未保存の印。ホストが GUI のエディターとレイアウトにつなぐ |
23
24
  | `./styles.css` | 上のすべてのスタイルシート |
24
25
 
@@ -61,7 +62,7 @@ MPL-2.0。turbowarp-plus-editor の `packages/editor-views` と `packages/editor
61
62
  | `paletteGroupSets(locale, projectSets)` | 「標準」「表現」「変数・リスト」「基本の制御」と、作品のセット |
62
63
  | `attachPaletteMenuButton(menu, getLocale, getItems)` | カテゴリの一覧の末尾(横配置では右端、縦配置では下端)に ▼ のボタンを置く。押すと、ホストが渡す項目のメニューを出す。項目は「ブロックグループの表示・非表示の設定」(`paletteVisibilityMenuLabel`)と、ホストの機能拡張に関する項目 |
63
64
 
64
- `./palette-visibility-dialog` の `openPaletteVisibilityDialog(document, props)` は「パレット内のブロックグループの表示・非表示の設定」の画面を開く。機能拡張の各行は `@kubohiroya/turbowarp-extension-security-dialog/react` の `ExtensionRow` で描くので、拡張の追加の画面と同じ見た目になる。適用すると、出すグループと、この画面で足したセットを `onApply` に渡す。
65
+ `./palette-visibility-dialog` の `openPaletteVisibilityDialog(document, props)` は「パレット内のブロックグループの表示・非表示の設定」の画面を開く。機能拡張の各行は `@kubohiroya/turbowarp-extension-security-dialog/react` の `ExtensionRow` で描くので、拡張の追加の画面と同じ見た目になる。適用すると、出すグループと、この画面で足したセットを `onApply` に渡す。`newSprite` を渡すと、追加したばかりのスプライトについて尋ねる画面になり、「新しいスプライト「名前」」と「次回から尋ねない」のチェックを出す。チェックの値は `onApply` の `dontAskAgain` になる。
65
66
 
66
67
  ホストは `@kubohiroya/turbowarp-extension-security-dialog`(0.9.0 以上)を入れ、その `styles.css` も読み込む。設定を画面状態のスライスとして登録するのはホストの役目である。1つの機能拡張の中を複数のグループに分けて選ぶ機能は、VM がグループごとのカテゴリを作れるようになってから足す。
67
68
 
package/README.md CHANGED
@@ -19,6 +19,7 @@ The code views of TurboWarp Plus Editor: code in tabs and windows that share one
19
19
  | `./palette-category-visibility`, `./palette-visibility-dialog` | Choose which block groups the palette shows for each sprite and the stage. The setting is saved with the editor's screen state, with a screen to choose |
20
20
  | `./palette-category-reorder`, `./palette-category-search`, `./palette-dropdown-resize` | Reordering and searching palette categories, and resizing palette dropdowns |
21
21
  | `./block-argument-text` | Shortens long text arguments and edits them in a dialog |
22
+ | `./block-number-input` | Converts full-width digits and signs typed into number arguments to half-width |
22
23
  | `./asset-edit-session`, `./dockview-unsaved` | The asset edit session and the unsaved marks on Dockview tabs, which the host connects to the GUI's editors and layout |
23
24
  | `./styles.css` | The stylesheet for all of the above |
24
25
 
@@ -61,7 +62,7 @@ Each sprite and the stage can choose which block groups the palette shows: the s
61
62
  | `paletteGroupSets(locale, projectSets)` | Standard, Expression, Variables and lists, Basic control, and the project's own sets |
62
63
  | `attachPaletteMenuButton(menu, getLocale, getItems)` | Puts a ▼ button at the end of the category menu (the right end of a horizontal palette, the bottom of a vertical one). Pressing it lists the items the host gives: the group settings (`paletteVisibilityMenuLabel`) and the host's extension items |
63
64
 
64
- `openPaletteVisibilityDialog(document, props)` from `./palette-visibility-dialog` opens the screen that chooses the groups. Each extension is drawn with `ExtensionRow` from `@kubohiroya/turbowarp-extension-security-dialog/react`, so it looks the same as in the screen that adds extensions. Applying passes the groups to show, and the sets added in the screen, to `onApply`.
65
+ `openPaletteVisibilityDialog(document, props)` from `./palette-visibility-dialog` opens the screen that chooses the groups. Each extension is drawn with `ExtensionRow` from `@kubohiroya/turbowarp-extension-security-dialog/react`, so it looks the same as in the screen that adds extensions. Applying passes the groups to show, and the sets added in the screen, to `onApply`. With `newSprite`, the screen asks about a sprite just added: it names it as a new sprite and offers “Don’t ask next time”, whose value `onApply` receives as `dontAskAgain`.
65
66
 
66
67
  The host installs `@kubohiroya/turbowarp-extension-security-dialog` (0.9.0 or later) and loads its `styles.css`, and registers the store as a screen-state slice. Choosing groups inside one extension comes once the VM can make a category per group.
67
68
 
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Full-width characters in number arguments.
3
+ *
4
+ * Every argument that takes a number (`math_number`, `math_integer`, `math_angle`, the list index
5
+ * of `data_listindexall` and so on) edits through a `FieldTextInput` subclass that was given a
6
+ * restrictor, a pattern of the characters it accepts. scratch-blocks tests that pattern only on
7
+ * `keypress`, and text an IME commits arrives through `input` alone, so `10` passes and the VM
8
+ * reads it as 0. This converts full-width digits and signs to their half-width forms and drops
9
+ * what the restrictor would have refused, for every field with a restrictor and no other.
10
+ */
11
+ /**
12
+ * Half-width forms of full-width ASCII (U+FF01–U+FF5E) and of the signs above.
13
+ * @param {string} text The value.
14
+ * @returns {string} The value with those characters replaced.
15
+ */
16
+ export declare const toHalfWidth: (text: string) => string;
17
+ /**
18
+ * A number field's value with full-width characters converted and refused characters dropped.
19
+ * @param {string} text The value.
20
+ * @param {RegExp} restrictor The field's restrictor, which tests one character.
21
+ * @returns {string} The value the field accepts.
22
+ */
23
+ export declare const normalizeNumberText: (text: string, restrictor: RegExp) => string;
24
+ /**
25
+ * Normalize number fields as they are typed.
26
+ * Only fields with a restrictor change: text arguments, which have none, keep full-width text.
27
+ * While an IME is composing the text is left alone, and it is normalized once the composition ends.
28
+ * @param {object} ScratchBlocks The loaded ScratchBlocks.
29
+ */
30
+ export declare const installBlockNumberInput: (ScratchBlocks: any) => void;
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Full-width characters in number arguments.
3
+ *
4
+ * Every argument that takes a number (`math_number`, `math_integer`, `math_angle`, the list index
5
+ * of `data_listindexall` and so on) edits through a `FieldTextInput` subclass that was given a
6
+ * restrictor, a pattern of the characters it accepts. scratch-blocks tests that pattern only on
7
+ * `keypress`, and text an IME commits arrives through `input` alone, so `10` passes and the VM
8
+ * reads it as 0. This converts full-width digits and signs to their half-width forms and drops
9
+ * what the restrictor would have refused, for every field with a restrictor and no other.
10
+ */
11
+ /** Characters an IME commits for a sign or a decimal point, beyond the full-width ASCII block. */
12
+ const signs = {
13
+ 'ー': '-', // KATAKANA-HIRAGANA PROLONGED SOUND MARK, what the minus key gives in kana mode
14
+ '−': '-', // MINUS SIGN
15
+ '‐': '-', // HYPHEN
16
+ '‑': '-', // NON-BREAKING HYPHEN
17
+ '–': '-', // EN DASH
18
+ '。': '.' // IDEOGRAPHIC FULL STOP, what the period key gives in kana mode
19
+ };
20
+ const fullWidth = /[!-~]/g;
21
+ /**
22
+ * Half-width forms of full-width ASCII (U+FF01–U+FF5E) and of the signs above.
23
+ * @param {string} text The value.
24
+ * @returns {string} The value with those characters replaced.
25
+ */
26
+ export const toHalfWidth = (text) => {
27
+ let result = '';
28
+ for (const character of text.replace(fullWidth, c => String.fromCharCode(c.charCodeAt(0) - 0xFEE0))) {
29
+ result += signs[character] ?? character;
30
+ }
31
+ return result;
32
+ };
33
+ /**
34
+ * A number field's value with full-width characters converted and refused characters dropped.
35
+ * @param {string} text The value.
36
+ * @param {RegExp} restrictor The field's restrictor, which tests one character.
37
+ * @returns {string} The value the field accepts.
38
+ */
39
+ export const normalizeNumberText = (text, restrictor) => {
40
+ let result = '';
41
+ for (const character of toHalfWidth(text)) {
42
+ restrictor.lastIndex = 0;
43
+ if (restrictor.test(character))
44
+ result += character;
45
+ }
46
+ return result;
47
+ };
48
+ const installed = new WeakSet();
49
+ const compositionHandlers = new WeakMap();
50
+ /**
51
+ * Rewrite the editor's value in place, keeping the caret after the same characters.
52
+ * @param {HTMLInputElement} input The inline editor.
53
+ * @param {RegExp} restrictor The field's restrictor.
54
+ */
55
+ const normalizeInput = (input, restrictor) => {
56
+ const { value } = input;
57
+ const normalized = normalizeNumberText(value, restrictor);
58
+ if (normalized === value)
59
+ return;
60
+ let caret = null;
61
+ try {
62
+ if (input.selectionEnd !== null)
63
+ caret = normalizeNumberText(value.slice(0, input.selectionEnd), restrictor).length;
64
+ }
65
+ catch {
66
+ // Some input types have no selection.
67
+ }
68
+ input.value = normalized;
69
+ if (caret !== null) {
70
+ try {
71
+ input.setSelectionRange(caret, caret);
72
+ }
73
+ catch {
74
+ // Same as above.
75
+ }
76
+ }
77
+ };
78
+ /**
79
+ * Normalize number fields as they are typed.
80
+ * Only fields with a restrictor change: text arguments, which have none, keep full-width text.
81
+ * While an IME is composing the text is left alone, and it is normalized once the composition ends.
82
+ * @param {object} ScratchBlocks The loaded ScratchBlocks.
83
+ */
84
+ export const installBlockNumberInput = ScratchBlocks => {
85
+ const FieldTextInput = ScratchBlocks?.FieldTextInput;
86
+ const field = FieldTextInput?.prototype;
87
+ if (!field?.onHtmlInputChange_ || !field.bindEvents_ || !field.unbindEvents_ || installed.has(field))
88
+ return;
89
+ installed.add(field);
90
+ const { onHtmlInputChange_: onChange, bindEvents_: bindEvents, unbindEvents_: unbindEvents } = field;
91
+ field.onHtmlInputChange_ = function (event, ...rest) {
92
+ const input = FieldTextInput.htmlInput_;
93
+ // A keypress is still filtered by the inherited code, before the character is inserted.
94
+ if (this.restrictor_ instanceof RegExp && input && event?.type !== 'keypress' && !event?.isComposing) {
95
+ normalizeInput(input, this.restrictor_);
96
+ }
97
+ return onChange.call(this, event, ...rest);
98
+ };
99
+ field.bindEvents_ = function (htmlInput, ...rest) {
100
+ const result = bindEvents.call(this, htmlInput, ...rest);
101
+ if (this.restrictor_ instanceof RegExp && htmlInput?.addEventListener) {
102
+ // Chrome sends the last `input` of a composition while it is still composing.
103
+ const handler = (event) => this.onHtmlInputChange_(event);
104
+ compositionHandlers.set(htmlInput, handler);
105
+ htmlInput.addEventListener('compositionend', handler);
106
+ }
107
+ return result;
108
+ };
109
+ field.unbindEvents_ = function (htmlInput, ...rest) {
110
+ const handler = htmlInput && compositionHandlers.get(htmlInput);
111
+ if (handler) {
112
+ htmlInput.removeEventListener('compositionend', handler);
113
+ compositionHandlers.delete(htmlInput);
114
+ }
115
+ return unbindEvents.call(this, htmlInput, ...rest);
116
+ };
117
+ };
@@ -12,6 +12,8 @@ export interface PaletteVisibilityChoice {
12
12
  groups: string[];
13
13
  /** Sets added in this dialog, to keep with the project. */
14
14
  addedSets: PaletteGroupSet[];
15
+ /** For a new sprite: start the next new sprites with these groups instead of asking. */
16
+ dontAskAgain?: boolean;
15
17
  }
16
18
  export interface PaletteVisibilityDialogProps {
17
19
  locale?: string;
@@ -23,6 +25,8 @@ export interface PaletteVisibilityDialogProps {
23
25
  used: ReadonlyMap<string, number>;
24
26
  extensions: readonly PaletteExtension[];
25
27
  sets: readonly PaletteGroupSet[];
28
+ /** Asked for a sprite just added: says so, and offers not to ask for the next ones. */
29
+ newSprite?: boolean;
26
30
  onApply(choice: PaletteVisibilityChoice): void;
27
31
  onCancel(): void;
28
32
  }
@@ -31,6 +35,7 @@ interface DialogState {
31
35
  addedSets: PaletteGroupSet[];
32
36
  naming: boolean;
33
37
  setName: string;
38
+ dontAskAgain: boolean;
34
39
  }
35
40
  /**
36
41
  * The screen that chooses which block groups the palette shows for one sprite or the stage: sets that
@@ -43,6 +48,8 @@ export declare class PaletteVisibilityDialog extends React.PureComponent<Palette
43
48
  title: string;
44
49
  sprite: (name: string) => string;
45
50
  stage: string;
51
+ newSprite: (name: string) => string;
52
+ dontAskAgain: string;
46
53
  sets: string;
47
54
  addSet: string;
48
55
  setName: string;
@@ -15,12 +15,14 @@ const standardColors = {
15
15
  const messages = {
16
16
  en: {
17
17
  title: 'Block groups shown in the palette', sprite: (name) => `Sprite “${name}”`, stage: 'Stage',
18
+ newSprite: (name) => `New sprite “${name}”`, dontAskAgain: 'Don’t ask next time',
18
19
  sets: 'Applicable sets', addSet: 'Add applicable set', setName: 'Set name', add: 'Add',
19
20
  standard: 'Standard block groups', extensions: 'Extension block groups', used: (count) => `In use ${count}`,
20
21
  hiddenInUse: (count) => `Hidden and in use: ${count}`, cancel: 'Cancel', apply: 'Apply', close: 'Close'
21
22
  },
22
23
  ja: {
23
24
  title: 'パレット内のブロックグループの表示・非表示の設定', sprite: (name) => `スプライト「${name}」`, stage: '背景',
25
+ newSprite: (name) => `新しいスプライト「${name}」`, dontAskAgain: '次回から尋ねない',
24
26
  sets: '適用可能なセット', addSet: '適用可能なセットを追加', setName: 'セットの名前', add: '追加',
25
27
  standard: '標準のブロックグループ', extensions: '機能拡張のブロックグループ', used: (count) => `使用中 ${count}`,
26
28
  hiddenInUse: (count) => `非表示中・使用中 ${count} 件`, cancel: 'キャンセル', apply: '適用', close: '閉じる'
@@ -35,7 +37,7 @@ const isJapanese = (locale) => /^ja(?:-|$)/i.test(locale ?? '');
35
37
  export class PaletteVisibilityDialog extends React.PureComponent {
36
38
  constructor(props) {
37
39
  super(props);
38
- this.state = { shown: new Set(props.initial), addedSets: [], naming: false, setName: '' };
40
+ this.state = { shown: new Set(props.initial), addedSets: [], naming: false, setName: '', dontAskAgain: false };
39
41
  }
40
42
  get text() {
41
43
  return isJapanese(this.props.locale) ? messages.ja : messages.en;
@@ -86,7 +88,8 @@ export class PaletteVisibilityDialog extends React.PureComponent {
86
88
  }
87
89
  apply() {
88
90
  const order = [...this.standard(), ...this.props.extensions.map(extension => extension.id)];
89
- this.props.onApply({ groups: order.filter(group => this.state.shown.has(group)), addedSets: this.state.addedSets });
91
+ this.props.onApply({ groups: order.filter(group => this.state.shown.has(group)), addedSets: this.state.addedSets,
92
+ ...this.props.newSprite ? { dontAskAgain: this.state.dontAskAgain } : {} });
90
93
  }
91
94
  render() {
92
95
  const { locale, targetName, isStage, used, extensions, onCancel } = this.props;
@@ -100,7 +103,7 @@ export class PaletteVisibilityDialog extends React.PureComponent {
100
103
  React.createElement("header", { className: "tw-palette-visibility-header" },
101
104
  React.createElement("div", null,
102
105
  React.createElement("h2", null, text.title),
103
- React.createElement("p", null, isStage ? text.stage : text.sprite(targetName))),
106
+ React.createElement("p", null, isStage ? text.stage : this.props.newSprite ? text.newSprite(targetName) : text.sprite(targetName))),
104
107
  React.createElement("button", { type: "button", className: "tw-palette-visibility-close", "aria-label": text.close, title: text.close, onClick: onCancel }, "\u00D7")),
105
108
  React.createElement("section", { "aria-label": text.sets },
106
109
  React.createElement("h3", null, text.sets),
@@ -131,6 +134,9 @@ export class PaletteVisibilityDialog extends React.PureComponent {
131
134
  React.createElement("ul", { className: "twextsec-rows" }, extensions.map(extension => (React.createElement(ExtensionRow, { key: extension.id, metadata: extension.metadata, ids: [extension.id], locale: locale, itemProps: { 'data-group': extension.id }, pick: { checked: shown.has(extension.id), onToggle: () => this.toggle(extension.id) } }, usedBadge(extension.id)))))))),
132
135
  React.createElement("footer", { className: "tw-palette-visibility-footer" },
133
136
  React.createElement("span", { role: "status" }, hiddenInUse > 0 ? text.hiddenInUse(hiddenInUse) : ''),
137
+ this.props.newSprite && (React.createElement("label", { className: "tw-palette-visibility-dont-ask" },
138
+ React.createElement("input", { type: "checkbox", checked: this.state.dontAskAgain, onChange: () => this.setState(({ dontAskAgain }) => ({ dontAskAgain: !dontAskAgain })) }),
139
+ text.dontAskAgain)),
134
140
  React.createElement("span", null,
135
141
  React.createElement("button", { type: "button", onClick: onCancel }, text.cancel),
136
142
  React.createElement("button", { type: "button", className: "tw-palette-visibility-apply", onClick: () => this.apply() }, text.apply)))));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-plus-editor-code-views",
3
- "version": "0.4.0",
3
+ "version": "0.6.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",
@@ -62,6 +62,10 @@
62
62
  "types": "./dist/block-argument-text.d.ts",
63
63
  "default": "./dist/block-argument-text.js"
64
64
  },
65
+ "./block-number-input": {
66
+ "types": "./dist/block-number-input.d.ts",
67
+ "default": "./dist/block-number-input.js"
68
+ },
65
69
  "./script-layout": {
66
70
  "types": "./dist/script-layout-view.d.ts",
67
71
  "default": "./dist/script-layout-view.js"
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Full-width characters in number arguments.
3
+ *
4
+ * Every argument that takes a number (`math_number`, `math_integer`, `math_angle`, the list index
5
+ * of `data_listindexall` and so on) edits through a `FieldTextInput` subclass that was given a
6
+ * restrictor, a pattern of the characters it accepts. scratch-blocks tests that pattern only on
7
+ * `keypress`, and text an IME commits arrives through `input` alone, so `10` passes and the VM
8
+ * reads it as 0. This converts full-width digits and signs to their half-width forms and drops
9
+ * what the restrictor would have refused, for every field with a restrictor and no other.
10
+ */
11
+
12
+ /** Characters an IME commits for a sign or a decimal point, beyond the full-width ASCII block. */
13
+ const signs: Readonly<Record<string, string>> = {
14
+ 'ー': '-', // KATAKANA-HIRAGANA PROLONGED SOUND MARK, what the minus key gives in kana mode
15
+ '−': '-', // MINUS SIGN
16
+ '‐': '-', // HYPHEN
17
+ '‑': '-', // NON-BREAKING HYPHEN
18
+ '–': '-', // EN DASH
19
+ '。': '.' // IDEOGRAPHIC FULL STOP, what the period key gives in kana mode
20
+ };
21
+
22
+ const fullWidth = /[!-~]/g;
23
+
24
+ /**
25
+ * Half-width forms of full-width ASCII (U+FF01–U+FF5E) and of the signs above.
26
+ * @param {string} text The value.
27
+ * @returns {string} The value with those characters replaced.
28
+ */
29
+ export const toHalfWidth = (text: string): string => {
30
+ let result = '';
31
+ for (const character of text.replace(fullWidth, c => String.fromCharCode(c.charCodeAt(0) - 0xFEE0))) {
32
+ result += signs[character] ?? character;
33
+ }
34
+ return result;
35
+ };
36
+
37
+ /**
38
+ * A number field's value with full-width characters converted and refused characters dropped.
39
+ * @param {string} text The value.
40
+ * @param {RegExp} restrictor The field's restrictor, which tests one character.
41
+ * @returns {string} The value the field accepts.
42
+ */
43
+ export const normalizeNumberText = (text: string, restrictor: RegExp): string => {
44
+ let result = '';
45
+ for (const character of toHalfWidth(text)) {
46
+ restrictor.lastIndex = 0;
47
+ if (restrictor.test(character)) result += character;
48
+ }
49
+ return result;
50
+ };
51
+
52
+ type HtmlInput = HTMLInputElement & {oldValue_?: string};
53
+
54
+ const installed = new WeakSet<object>();
55
+ const compositionHandlers = new WeakMap<HtmlInput, EventListener>();
56
+
57
+ /**
58
+ * Rewrite the editor's value in place, keeping the caret after the same characters.
59
+ * @param {HTMLInputElement} input The inline editor.
60
+ * @param {RegExp} restrictor The field's restrictor.
61
+ */
62
+ const normalizeInput = (input: HtmlInput, restrictor: RegExp) => {
63
+ const {value} = input;
64
+ const normalized = normalizeNumberText(value, restrictor);
65
+ if (normalized === value) return;
66
+ let caret: number | null = null;
67
+ try {
68
+ if (input.selectionEnd !== null) caret = normalizeNumberText(value.slice(0, input.selectionEnd), restrictor).length;
69
+ } catch {
70
+ // Some input types have no selection.
71
+ }
72
+ input.value = normalized;
73
+ if (caret !== null) {
74
+ try {
75
+ input.setSelectionRange(caret, caret);
76
+ } catch {
77
+ // Same as above.
78
+ }
79
+ }
80
+ };
81
+
82
+ /**
83
+ * Normalize number fields as they are typed.
84
+ * Only fields with a restrictor change: text arguments, which have none, keep full-width text.
85
+ * While an IME is composing the text is left alone, and it is normalized once the composition ends.
86
+ * @param {object} ScratchBlocks The loaded ScratchBlocks.
87
+ */
88
+ export const installBlockNumberInput = ScratchBlocks => {
89
+ const FieldTextInput = ScratchBlocks?.FieldTextInput;
90
+ const field = FieldTextInput?.prototype;
91
+ if (!field?.onHtmlInputChange_ || !field.bindEvents_ || !field.unbindEvents_ || installed.has(field)) return;
92
+ installed.add(field);
93
+
94
+ const {onHtmlInputChange_: onChange, bindEvents_: bindEvents, unbindEvents_: unbindEvents} = field;
95
+
96
+ field.onHtmlInputChange_ = function (event, ...rest) {
97
+ const input: HtmlInput | undefined = FieldTextInput.htmlInput_;
98
+ // A keypress is still filtered by the inherited code, before the character is inserted.
99
+ if (this.restrictor_ instanceof RegExp && input && event?.type !== 'keypress' && !event?.isComposing) {
100
+ normalizeInput(input, this.restrictor_);
101
+ }
102
+ return onChange.call(this, event, ...rest);
103
+ };
104
+
105
+ field.bindEvents_ = function (htmlInput: HtmlInput, ...rest) {
106
+ const result = bindEvents.call(this, htmlInput, ...rest);
107
+ if (this.restrictor_ instanceof RegExp && htmlInput?.addEventListener) {
108
+ // Chrome sends the last `input` of a composition while it is still composing.
109
+ const handler = (event: Event) => this.onHtmlInputChange_(event);
110
+ compositionHandlers.set(htmlInput, handler);
111
+ htmlInput.addEventListener('compositionend', handler);
112
+ }
113
+ return result;
114
+ };
115
+
116
+ field.unbindEvents_ = function (htmlInput: HtmlInput, ...rest) {
117
+ const handler = htmlInput && compositionHandlers.get(htmlInput);
118
+ if (handler) {
119
+ htmlInput.removeEventListener('compositionend', handler);
120
+ compositionHandlers.delete(htmlInput);
121
+ }
122
+ return unbindEvents.call(this, htmlInput, ...rest);
123
+ };
124
+ };
@@ -16,6 +16,8 @@ export interface PaletteVisibilityChoice {
16
16
  groups: string[];
17
17
  /** Sets added in this dialog, to keep with the project. */
18
18
  addedSets: PaletteGroupSet[];
19
+ /** For a new sprite: start the next new sprites with these groups instead of asking. */
20
+ dontAskAgain?: boolean;
19
21
  }
20
22
 
21
23
  export interface PaletteVisibilityDialogProps {
@@ -28,6 +30,8 @@ export interface PaletteVisibilityDialogProps {
28
30
  used: ReadonlyMap<string, number>;
29
31
  extensions: readonly PaletteExtension[];
30
32
  sets: readonly PaletteGroupSet[];
33
+ /** Asked for a sprite just added: says so, and offers not to ask for the next ones. */
34
+ newSprite?: boolean;
31
35
  onApply(choice: PaletteVisibilityChoice): void;
32
36
  onCancel(): void;
33
37
  }
@@ -45,12 +49,14 @@ const standardColors: Record<string, string> = {
45
49
  const messages = {
46
50
  en: {
47
51
  title: 'Block groups shown in the palette', sprite: (name: string) => `Sprite “${name}”`, stage: 'Stage',
52
+ newSprite: (name: string) => `New sprite “${name}”`, dontAskAgain: 'Don’t ask next time',
48
53
  sets: 'Applicable sets', addSet: 'Add applicable set', setName: 'Set name', add: 'Add',
49
54
  standard: 'Standard block groups', extensions: 'Extension block groups', used: (count: number) => `In use ${count}`,
50
55
  hiddenInUse: (count: number) => `Hidden and in use: ${count}`, cancel: 'Cancel', apply: 'Apply', close: 'Close'
51
56
  },
52
57
  ja: {
53
58
  title: 'パレット内のブロックグループの表示・非表示の設定', sprite: (name: string) => `スプライト「${name}」`, stage: '背景',
59
+ newSprite: (name: string) => `新しいスプライト「${name}」`, dontAskAgain: '次回から尋ねない',
54
60
  sets: '適用可能なセット', addSet: '適用可能なセットを追加', setName: 'セットの名前', add: '追加',
55
61
  standard: '標準のブロックグループ', extensions: '機能拡張のブロックグループ', used: (count: number) => `使用中 ${count}`,
56
62
  hiddenInUse: (count: number) => `非表示中・使用中 ${count} 件`, cancel: 'キャンセル', apply: '適用', close: '閉じる'
@@ -63,6 +69,7 @@ interface DialogState {
63
69
  addedSets: PaletteGroupSet[];
64
70
  naming: boolean;
65
71
  setName: string;
72
+ dontAskAgain: boolean;
66
73
  }
67
74
 
68
75
  /**
@@ -73,7 +80,7 @@ interface DialogState {
73
80
  export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibilityDialogProps, DialogState> {
74
81
  constructor(props: PaletteVisibilityDialogProps) {
75
82
  super(props);
76
- this.state = {shown: new Set(props.initial), addedSets: [], naming: false, setName: ''};
83
+ this.state = {shown: new Set(props.initial), addedSets: [], naming: false, setName: '', dontAskAgain: false};
77
84
  }
78
85
  get text() {
79
86
  return isJapanese(this.props.locale) ? messages.ja : messages.en;
@@ -118,7 +125,8 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
118
125
  }
119
126
  apply() {
120
127
  const order = [...this.standard(), ...this.props.extensions.map(extension => extension.id)];
121
- this.props.onApply({groups: order.filter(group => this.state.shown.has(group)), addedSets: this.state.addedSets});
128
+ this.props.onApply({groups: order.filter(group => this.state.shown.has(group)), addedSets: this.state.addedSets,
129
+ ...this.props.newSprite ? {dontAskAgain: this.state.dontAskAgain} : {}});
122
130
  }
123
131
  render() {
124
132
  const {locale, targetName, isStage, used, extensions, onCancel} = this.props;
@@ -135,7 +143,7 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
135
143
  <header className="tw-palette-visibility-header">
136
144
  <div>
137
145
  <h2>{text.title}</h2>
138
- <p>{isStage ? text.stage : text.sprite(targetName)}</p>
146
+ <p>{isStage ? text.stage : this.props.newSprite ? text.newSprite(targetName) : text.sprite(targetName)}</p>
139
147
  </div>
140
148
  <button type="button" className="tw-palette-visibility-close" aria-label={text.close} title={text.close}
141
149
  onClick={onCancel}>×</button>
@@ -202,6 +210,13 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
202
210
  )}
203
211
  <footer className="tw-palette-visibility-footer">
204
212
  <span role="status">{hiddenInUse > 0 ? text.hiddenInUse(hiddenInUse) : ''}</span>
213
+ {this.props.newSprite && (
214
+ <label className="tw-palette-visibility-dont-ask">
215
+ <input type="checkbox" checked={this.state.dontAskAgain}
216
+ onChange={() => this.setState(({dontAskAgain}) => ({dontAskAgain: !dontAskAgain}))} />
217
+ {text.dontAskAgain}
218
+ </label>
219
+ )}
205
220
  <span>
206
221
  <button type="button" onClick={onCancel}>{text.cancel}</button>
207
222
  <button type="button" className="tw-palette-visibility-apply" onClick={() => this.apply()}>
package/src/styles.css CHANGED
@@ -790,3 +790,11 @@
790
790
  margin: 0.25rem 0;
791
791
  background: var(--ui-black-transparent, #80808040);
792
792
  }
793
+
794
+ .tw-palette-visibility-dont-ask {
795
+ display: flex;
796
+ align-items: center;
797
+ gap: 0.35rem;
798
+ margin-left: auto;
799
+ font-size: 0.85rem;
800
+ }