@kubohiroya/turbowarp-plus-editor-code-views 0.9.0 → 0.10.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
@@ -67,7 +67,7 @@ MPL-2.0。turbowarp-plus-editor の `packages/editor-views` と `packages/editor
67
67
  | `paletteGroupSets(locale, projectSets)` | 「標準」「表現」「変数・リスト」「基本の制御」と、作品のセット |
68
68
  | `attachPaletteMenuButton(menu, getLocale, getItems)` | カテゴリの一覧の末尾(横配置では右端、縦配置では下端)に ▼ のボタンを置く。押すと、ホストが渡す項目のメニューを出す。項目は「ブロックグループの表示・非表示の設定」(`paletteVisibilityMenuLabel`)と、ホストの機能拡張に関する項目 |
69
69
 
70
- `./palette-visibility-dialog` の `openPaletteVisibilityDialog(document, props)` は「パレット内のブロックグループの表示・非表示の設定」の画面を開く。機能拡張の各行は `@kubohiroya/turbowarp-extension-security-dialog/react` の `ExtensionRow` で描くので、拡張の追加の画面と同じ見た目になる。適用すると、出すグループと、この画面で足したセットを `onApply` に渡す。`newSprite` を渡すと、追加したばかりのスプライトについて尋ねる画面になり、見出しの下に「新しいスプライト「名前」」と出す。あわせて `copySources`(作成済みのスプライトの名前と、それぞれが表示中のグループ)を渡すと、「作成済みのスプライトからコピー」の欄に選ぶ一覧と「コピーして適用」を出す。押すと、選んだスプライトのグループのうちこのスプライトに出せるものを、そのまま `onApply` に渡して閉じる。
70
+ `./palette-visibility-dialog` の `openPaletteVisibilityDialog(document, props)` は「パレット内のブロックグループの表示・非表示の設定」の画面を開く。機能拡張の各行は `@kubohiroya/turbowarp-extension-security-dialog/react` の `ExtensionRow` で描くので、拡張の追加の画面と同じ見た目になる。画面は、「まとめて選ぶ」の欄に「設定のショートカット」(「標準」「表現」などのセット)と「設定のコピー元」を左右に並べ、その下に標準と機能拡張のブロックグループのチェックを並べる。ショートカットやコピー元にポインターを重ねるかフォーカスすると、それが選ぶグループのチェックが、そのチェックにポインターを重ねたときと同じ背景になる。「確定」を押すと、出すグループと、この画面で足したショートカットを `onApply` に渡して閉じる。`newSprite` を渡すと、追加したばかりのスプライトについて尋ねる画面になり、見出しの下に「新しいスプライト「名前」」と出す。あわせて `copySources`(作成済みのスプライトの名前と、それぞれが表示中のグループ)を渡すと、「設定のコピー元」に選ぶ一覧と「コピー」を出す。一覧は「スプライトを選ぶ」から始まり、スプライトを選んでいる間は、それが選ぶグループのチェックを強調したままにする。「コピー」を押すと、選んだスプライトのグループのうちこのスプライトに出せるものを、画面のチェックに写す。画面は閉じないので、利用者はチェックを足したり外したりしてから「確定」を押す。
71
71
 
72
72
  ホストは `@kubohiroya/turbowarp-extension-security-dialog`(0.9.0 以上)を入れ、その `styles.css` も読み込む。設定を画面状態のスライスとして登録するのはホストの役目である。1つの機能拡張の中を複数のグループに分けて選ぶ機能は、VM がグループごとのカテゴリを作れるようになってから足す。
73
73
 
package/README.md CHANGED
@@ -67,7 +67,7 @@ Each sprite and the stage can choose which block groups the palette shows: the s
67
67
  | `paletteGroupSets(locale, projectSets)` | Standard, Expression, Variables and lists, Basic control, and the project's own sets |
68
68
  | `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 |
69
69
 
70
- `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 and names it as a new sprite. Given `copySources` too (the sprites already in the project, each with the groups it shows), it offers “Copy from an existing sprite”: a list to choose one and “Copy and apply”, which passes that sprite's groups, as far as this sprite is offered them, to `onApply` and closes.
70
+ `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. The screen puts “Setting shortcuts” (sets such as Standard and Expression) and “Copy settings from” side by side under “Choose several at once”, above the checkboxes of the standard and extension block groups. Pointing at or focusing a shortcut or the copy source gives the checkboxes it would choose the same background as pointing at them. Confirm passes the groups to show, and the shortcuts added in the screen, to `onApply` and closes. With `newSprite`, the screen asks about a sprite just added and names it as a new sprite. Given `copySources` too (the sprites already in the project, each with the groups it shows), “Copy settings from” offers a list to choose one, starting at “Choose a sprite”, and “Copy”. While a sprite is chosen, the checkboxes it would choose stay marked. “Copy” checks that sprite's groups, as far as this sprite is offered them. The screen stays open; the person adds or removes checks and presses Confirm.
71
71
 
72
72
  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.
73
73
 
@@ -27,7 +27,7 @@ export interface PaletteVisibilityDialogProps {
27
27
  newSprite?: boolean;
28
28
  /**
29
29
  * For a new sprite: the sprites already in the project with the groups each shows. The screen offers to copy
30
- * one of them and apply it at once.
30
+ * one of them into its choices, which the person then adjusts and applies.
31
31
  */
32
32
  copySources?: readonly {
33
33
  name: string;
@@ -41,7 +41,10 @@ interface DialogState {
41
41
  addedSets: PaletteGroupSet[];
42
42
  naming: boolean;
43
43
  setName: string;
44
- copySource: number;
44
+ /** The sprite chosen to copy from, or null before one is chosen. */
45
+ copySource: number | null;
46
+ /** The groups a shortcut or a copy source under the pointer or focus would choose, shown in the lists. */
47
+ highlight: Set<string> | null;
45
48
  }
46
49
  /**
47
50
  * The screen that chooses which block groups the palette shows for one sprite or the stage: sets that
@@ -55,8 +58,10 @@ export declare class PaletteVisibilityDialog extends React.PureComponent<Palette
55
58
  sprite: (name: string) => string;
56
59
  stage: string;
57
60
  newSprite: (name: string) => string;
61
+ quick: string;
58
62
  copyFrom: string;
59
- copyApply: string;
63
+ copy: string;
64
+ chooseSprite: string;
60
65
  sets: string;
61
66
  addSet: string;
62
67
  setName: string;
@@ -66,7 +71,7 @@ export declare class PaletteVisibilityDialog extends React.PureComponent<Palette
66
71
  used: (count: number) => string;
67
72
  hiddenInUse: (count: number) => string;
68
73
  cancel: string;
69
- apply: string;
74
+ confirm: string;
70
75
  close: string;
71
76
  };
72
77
  standard(): ("sound" | "variables" | "events" | "motion" | "looks" | "control" | "sensing" | "operators" | "lists" | "myBlocks")[];
@@ -74,8 +79,13 @@ export declare class PaletteVisibilityDialog extends React.PureComponent<Palette
74
79
  toggle(group: string): void;
75
80
  toggleSet(set: PaletteGroupSet): void;
76
81
  addSet(): void;
77
- /** Apply the groups another sprite shows, as far as this one is offered them. */
78
- copyAndApply(): void;
82
+ /**
83
+ * Choose the groups another sprite shows, as far as this one is offered them. The screen stays open, so the
84
+ * person sees the copy, adds or removes checks, and applies.
85
+ */
86
+ copy(): void;
87
+ /** The groups of the chosen copy source this sprite can show, or none before one is chosen. */
88
+ copyGroups(): string[];
79
89
  apply(): void;
80
90
  render(): React.JSX.Element;
81
91
  }
@@ -16,18 +16,18 @@ const messages = {
16
16
  en: {
17
17
  title: 'Block groups shown in the palette', sprite: (name) => `Sprite “${name}”`, stage: 'Stage',
18
18
  newSprite: (name) => `New sprite “${name}”`,
19
- copyFrom: 'Copy from an existing sprite', copyApply: 'Copy and apply',
20
- sets: 'Applicable sets', addSet: 'Add applicable set', setName: 'Set name', add: 'Add',
19
+ quick: 'Choose several at once', copyFrom: 'Copy settings from', copy: 'Copy', chooseSprite: 'Choose a sprite',
20
+ sets: 'Setting shortcuts', addSet: 'Add setting shortcut', setName: 'Shortcut name', add: 'Add',
21
21
  standard: 'Standard block groups', extensions: 'Extension block groups', used: (count) => `In use ${count}`,
22
- hiddenInUse: (count) => `Hidden and in use: ${count}`, cancel: 'Cancel', apply: 'Apply', close: 'Close'
22
+ hiddenInUse: (count) => `Hidden and in use: ${count}`, cancel: 'Cancel', confirm: 'Confirm', close: 'Close'
23
23
  },
24
24
  ja: {
25
25
  title: 'パレット内のブロックグループの表示・非表示の設定', sprite: (name) => `スプライト「${name}」`, stage: '背景',
26
26
  newSprite: (name) => `新しいスプライト「${name}」`,
27
- copyFrom: '作成済みのスプライトからコピー', copyApply: 'コピーして適用',
28
- sets: '適用可能なセット', addSet: '適用可能なセットを追加', setName: 'セットの名前', add: '追加',
27
+ quick: 'まとめて選ぶ', copyFrom: '設定のコピー元', copy: 'コピー', chooseSprite: 'スプライトを選ぶ',
28
+ sets: '設定のショートカット', addSet: '設定のショートカットを追加', setName: 'ショートカットの名前', add: '追加',
29
29
  standard: '標準のブロックグループ', extensions: '機能拡張のブロックグループ', used: (count) => `使用中 ${count}`,
30
- hiddenInUse: (count) => `非表示中・使用中 ${count} 件`, cancel: 'キャンセル', apply: '適用', close: '閉じる'
30
+ hiddenInUse: (count) => `非表示中・使用中 ${count} 件`, cancel: 'キャンセル', confirm: '確定', close: '閉じる'
31
31
  }
32
32
  };
33
33
  const isJapanese = (locale) => /^ja(?:-|$)/i.test(locale ?? '');
@@ -39,7 +39,7 @@ const isJapanese = (locale) => /^ja(?:-|$)/i.test(locale ?? '');
39
39
  export class PaletteVisibilityDialog extends React.PureComponent {
40
40
  constructor(props) {
41
41
  super(props);
42
- this.state = { shown: new Set(props.initial), addedSets: [], naming: false, setName: '', copySource: 0 };
42
+ this.state = { shown: new Set(props.initial), addedSets: [], naming: false, setName: '', copySource: null, highlight: null };
43
43
  }
44
44
  get text() {
45
45
  return isJapanese(this.props.locale) ? messages.ja : messages.en;
@@ -88,14 +88,19 @@ export class PaletteVisibilityDialog extends React.PureComponent {
88
88
  .filter(group => this.state.shown.has(group));
89
89
  this.setState(({ addedSets }) => ({ addedSets: [...addedSets, { id, name, groups }], naming: false, setName: '' }));
90
90
  }
91
- /** Apply the groups another sprite shows, as far as this one is offered them. */
92
- copyAndApply() {
93
- const source = this.props.copySources?.[this.state.copySource];
94
- if (!source)
91
+ /**
92
+ * Choose the groups another sprite shows, as far as this one is offered them. The screen stays open, so the
93
+ * person sees the copy, adds or removes checks, and applies.
94
+ */
95
+ copy() {
96
+ if (this.state.copySource === null || !this.props.copySources?.[this.state.copySource])
95
97
  return;
96
- const order = [...this.standard(), ...this.props.extensions.map(extension => extension.id)];
97
- const groups = new Set(source.groups);
98
- this.props.onApply({ groups: order.filter(group => groups.has(group)), addedSets: this.state.addedSets });
98
+ this.setState({ shown: new Set(this.copyGroups()) });
99
+ }
100
+ /** The groups of the chosen copy source this sprite can show, or none before one is chosen. */
101
+ copyGroups() {
102
+ const source = this.state.copySource === null ? undefined : this.props.copySources?.[this.state.copySource];
103
+ return source ? this.available(source.groups) : [];
99
104
  }
100
105
  apply() {
101
106
  const order = [...this.standard(), ...this.props.extensions.map(extension => extension.id)];
@@ -108,6 +113,17 @@ export class PaletteVisibilityDialog extends React.PureComponent {
108
113
  const names = isJapanese(locale) ? standardNames.ja : standardNames.en;
109
114
  const sets = [...this.props.sets, ...this.state.addedSets];
110
115
  const hiddenInUse = [...used].filter(([group, count]) => count > 0 && !shown.has(group)).length;
116
+ // Under the pointer or focus first; otherwise, while a copy source is chosen, the groups it would choose.
117
+ const highlight = this.state.highlight ?? (this.state.copySource !== null ? new Set(this.copyGroups()) : null);
118
+ const highlighted = (group) => highlight?.has(group) ? 'true' : undefined;
119
+ // Pointing at or focusing a shortcut or the copy source marks the groups it would choose, as hovering them does.
120
+ const highlighting = (groups) => {
121
+ const on = () => this.setState({ highlight: new Set(groups) });
122
+ const off = () => this.setState({ highlight: null });
123
+ return { onMouseEnter: on, onMouseLeave: off, onFocus: on, onBlur: off };
124
+ };
125
+ const copying = Boolean(this.props.newSprite && this.props.copySources?.length);
126
+ const copyGroups = copying ? this.copyGroups() : [];
111
127
  const usedBadge = (group) => !shown.has(group) && (used.get(group) ?? 0) > 0 && (React.createElement("span", { className: "tw-palette-visibility-used" }, text.used(used.get(group))));
112
128
  return (React.createElement("div", { className: "tw-palette-visibility" },
113
129
  React.createElement("header", { className: "tw-palette-visibility-header" },
@@ -115,30 +131,38 @@ export class PaletteVisibilityDialog extends React.PureComponent {
115
131
  React.createElement("h2", null, text.title),
116
132
  React.createElement("p", null, isStage ? text.stage : this.props.newSprite ? text.newSprite(targetName) : text.sprite(targetName))),
117
133
  React.createElement("button", { type: "button", className: "tw-palette-visibility-close", "aria-label": text.close, title: text.close, onClick: onCancel }, "\u00D7")),
118
- this.props.newSprite && (this.props.copySources?.length ?? 0) > 0 && (React.createElement("section", { "aria-label": text.copyFrom },
119
- React.createElement("h3", null, text.copyFrom),
120
- React.createElement("div", { className: "tw-palette-visibility-copy" },
121
- React.createElement("select", { "aria-label": text.copyFrom, value: this.state.copySource, onChange: event => this.setState({ copySource: Number(event.currentTarget.value) }) }, this.props.copySources.map((source, index) => (React.createElement("option", { key: index, value: index }, source.name)))),
122
- React.createElement("button", { type: "button", className: "tw-palette-visibility-copy-apply", onClick: () => this.copyAndApply() }, text.copyApply)))),
123
- React.createElement("section", { "aria-label": text.sets },
124
- React.createElement("h3", null, text.sets),
125
- React.createElement("div", { className: "tw-palette-visibility-sets" },
126
- sets.map(set => {
127
- const groups = this.available(set.groups);
128
- const all = groups.length > 0 && groups.every(group => shown.has(group));
129
- return (React.createElement("button", { key: set.id, type: "button", "aria-pressed": all, "data-set": set.id, onClick: () => this.toggleSet(set) },
130
- set.name,
131
- all ? ' ✓' : ''));
132
- }),
133
- naming ? (React.createElement("span", { className: "tw-palette-visibility-naming" },
134
- React.createElement("input", { type: "text", "aria-label": text.setName, placeholder: text.setName, value: setName, autoFocus: true, onChange: event => this.setState({ setName: event.currentTarget.value }), onKeyDown: event => { if (event.key === 'Enter')
135
- this.addSet(); } }),
136
- React.createElement("button", { type: "button", onClick: () => this.addSet() }, text.add))) : (React.createElement("button", { type: "button", className: "tw-palette-visibility-add-set", onClick: () => this.setState({ naming: true }) },
137
- "\uFF0B",
138
- text.addSet)))),
134
+ React.createElement("section", { "aria-label": text.quick },
135
+ React.createElement("h3", null, text.quick),
136
+ React.createElement("div", { className: "tw-palette-visibility-quick", "data-columns": copying ? '2' : '1' },
137
+ React.createElement("div", { className: "tw-palette-visibility-panel", "aria-label": text.sets, role: "group" },
138
+ React.createElement("h4", null, text.sets),
139
+ React.createElement("div", { className: "tw-palette-visibility-sets" },
140
+ sets.map(set => {
141
+ const groups = this.available(set.groups);
142
+ const all = groups.length > 0 && groups.every(group => shown.has(group));
143
+ return (React.createElement("button", { key: set.id, type: "button", "aria-pressed": all, "data-set": set.id, ...highlighting(groups), onClick: () => this.toggleSet(set) },
144
+ set.name,
145
+ all ? ' ✓' : ''));
146
+ }),
147
+ naming ? (React.createElement("span", { className: "tw-palette-visibility-naming" },
148
+ React.createElement("input", { type: "text", "aria-label": text.setName, placeholder: text.setName, value: setName, autoFocus: true, onChange: event => this.setState({ setName: event.currentTarget.value }), onKeyDown: event => { if (event.key === 'Enter')
149
+ this.addSet(); } }),
150
+ React.createElement("button", { type: "button", onClick: () => this.addSet() }, text.add))) : (React.createElement("button", { type: "button", className: "tw-palette-visibility-add-set", onClick: () => this.setState({ naming: true }) },
151
+ "\uFF0B",
152
+ text.addSet)))),
153
+ copying && (React.createElement("div", { className: "tw-palette-visibility-panel", "aria-label": text.copyFrom, role: "group", ...highlighting(copyGroups) },
154
+ React.createElement("h4", null, text.copyFrom),
155
+ React.createElement("div", { className: "tw-palette-visibility-copy" },
156
+ React.createElement("select", { "aria-label": text.copyFrom, value: this.state.copySource ?? '', onChange: event => {
157
+ const value = event.currentTarget.value;
158
+ this.setState({ copySource: value === '' ? null : Number(value), highlight: null });
159
+ } },
160
+ React.createElement("option", { value: "" }, text.chooseSprite),
161
+ this.props.copySources.map((source, index) => (React.createElement("option", { key: index, value: index }, source.name)))),
162
+ React.createElement("button", { type: "button", className: "tw-palette-visibility-copy-button", disabled: this.state.copySource === null, onClick: () => this.copy() }, text.copy)))))),
139
163
  React.createElement("section", { "aria-label": text.standard },
140
164
  React.createElement("h3", null, text.standard),
141
- React.createElement("div", { className: "tw-palette-visibility-standard" }, this.standard().map(group => (React.createElement("label", { key: group, "data-group": group },
165
+ React.createElement("div", { className: "tw-palette-visibility-standard" }, this.standard().map(group => (React.createElement("label", { key: group, "data-group": group, "data-highlighted": highlighted(group) },
142
166
  React.createElement("input", { type: "checkbox", checked: shown.has(group), onChange: () => this.toggle(group) }),
143
167
  React.createElement("span", { className: "tw-palette-visibility-swatch", style: { color: standardColors[group] }, "aria-hidden": "true" }, "\u25CF"),
144
168
  names[group],
@@ -146,12 +170,12 @@ export class PaletteVisibilityDialog extends React.PureComponent {
146
170
  extensions.length > 0 && (React.createElement("section", { "aria-label": text.extensions },
147
171
  React.createElement("h3", null, text.extensions),
148
172
  React.createElement("div", { className: "twextsec-review" },
149
- 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)))))))),
173
+ 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, 'data-highlighted': highlighted(extension.id) }, pick: { checked: shown.has(extension.id), onToggle: () => this.toggle(extension.id) } }, usedBadge(extension.id)))))))),
150
174
  React.createElement("footer", { className: "tw-palette-visibility-footer" },
151
175
  React.createElement("span", { role: "status" }, hiddenInUse > 0 ? text.hiddenInUse(hiddenInUse) : ''),
152
176
  React.createElement("span", null,
153
177
  React.createElement("button", { type: "button", onClick: onCancel }, text.cancel),
154
- React.createElement("button", { type: "button", className: "tw-palette-visibility-apply", onClick: () => this.apply() }, text.apply)))));
178
+ React.createElement("button", { type: "button", className: "tw-palette-visibility-apply", onClick: () => this.apply() }, text.confirm)))));
155
179
  }
156
180
  }
157
181
  /** Opens the screen as a modal `<dialog>` in `document`. Returns the function that closes it. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-plus-editor-code-views",
3
- "version": "0.9.0",
3
+ "version": "0.10.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",
@@ -32,7 +32,7 @@ export interface PaletteVisibilityDialogProps {
32
32
  newSprite?: boolean;
33
33
  /**
34
34
  * For a new sprite: the sprites already in the project with the groups each shows. The screen offers to copy
35
- * one of them and apply it at once.
35
+ * one of them into its choices, which the person then adjusts and applies.
36
36
  */
37
37
  copySources?: readonly {name: string; groups: readonly string[]}[];
38
38
  onApply(choice: PaletteVisibilityChoice): void;
@@ -53,18 +53,18 @@ const messages = {
53
53
  en: {
54
54
  title: 'Block groups shown in the palette', sprite: (name: string) => `Sprite “${name}”`, stage: 'Stage',
55
55
  newSprite: (name: string) => `New sprite “${name}”`,
56
- copyFrom: 'Copy from an existing sprite', copyApply: 'Copy and apply',
57
- sets: 'Applicable sets', addSet: 'Add applicable set', setName: 'Set name', add: 'Add',
56
+ quick: 'Choose several at once', copyFrom: 'Copy settings from', copy: 'Copy', chooseSprite: 'Choose a sprite',
57
+ sets: 'Setting shortcuts', addSet: 'Add setting shortcut', setName: 'Shortcut name', add: 'Add',
58
58
  standard: 'Standard block groups', extensions: 'Extension block groups', used: (count: number) => `In use ${count}`,
59
- hiddenInUse: (count: number) => `Hidden and in use: ${count}`, cancel: 'Cancel', apply: 'Apply', close: 'Close'
59
+ hiddenInUse: (count: number) => `Hidden and in use: ${count}`, cancel: 'Cancel', confirm: 'Confirm', close: 'Close'
60
60
  },
61
61
  ja: {
62
62
  title: 'パレット内のブロックグループの表示・非表示の設定', sprite: (name: string) => `スプライト「${name}」`, stage: '背景',
63
63
  newSprite: (name: string) => `新しいスプライト「${name}」`,
64
- copyFrom: '作成済みのスプライトからコピー', copyApply: 'コピーして適用',
65
- sets: '適用可能なセット', addSet: '適用可能なセットを追加', setName: 'セットの名前', add: '追加',
64
+ quick: 'まとめて選ぶ', copyFrom: '設定のコピー元', copy: 'コピー', chooseSprite: 'スプライトを選ぶ',
65
+ sets: '設定のショートカット', addSet: '設定のショートカットを追加', setName: 'ショートカットの名前', add: '追加',
66
66
  standard: '標準のブロックグループ', extensions: '機能拡張のブロックグループ', used: (count: number) => `使用中 ${count}`,
67
- hiddenInUse: (count: number) => `非表示中・使用中 ${count} 件`, cancel: 'キャンセル', apply: '適用', close: '閉じる'
67
+ hiddenInUse: (count: number) => `非表示中・使用中 ${count} 件`, cancel: 'キャンセル', confirm: '確定', close: '閉じる'
68
68
  }
69
69
  };
70
70
  const isJapanese = (locale?: string) => /^ja(?:-|$)/i.test(locale ?? '');
@@ -74,7 +74,10 @@ interface DialogState {
74
74
  addedSets: PaletteGroupSet[];
75
75
  naming: boolean;
76
76
  setName: string;
77
- copySource: number;
77
+ /** The sprite chosen to copy from, or null before one is chosen. */
78
+ copySource: number | null;
79
+ /** The groups a shortcut or a copy source under the pointer or focus would choose, shown in the lists. */
80
+ highlight: Set<string> | null;
78
81
  }
79
82
 
80
83
  /**
@@ -85,7 +88,7 @@ interface DialogState {
85
88
  export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibilityDialogProps, DialogState> {
86
89
  constructor(props: PaletteVisibilityDialogProps) {
87
90
  super(props);
88
- this.state = {shown: new Set(props.initial), addedSets: [], naming: false, setName: '', copySource: 0};
91
+ this.state = {shown: new Set(props.initial), addedSets: [], naming: false, setName: '', copySource: null, highlight: null};
89
92
  }
90
93
  get text() {
91
94
  return isJapanese(this.props.locale) ? messages.ja : messages.en;
@@ -128,13 +131,18 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
128
131
  .filter(group => this.state.shown.has(group));
129
132
  this.setState(({addedSets}) => ({addedSets: [...addedSets, {id, name, groups}], naming: false, setName: ''}));
130
133
  }
131
- /** Apply the groups another sprite shows, as far as this one is offered them. */
132
- copyAndApply() {
133
- const source = this.props.copySources?.[this.state.copySource];
134
- if (!source) return;
135
- const order = [...this.standard(), ...this.props.extensions.map(extension => extension.id)];
136
- const groups = new Set(source.groups);
137
- this.props.onApply({groups: order.filter(group => groups.has(group)), addedSets: this.state.addedSets});
134
+ /**
135
+ * Choose the groups another sprite shows, as far as this one is offered them. The screen stays open, so the
136
+ * person sees the copy, adds or removes checks, and applies.
137
+ */
138
+ copy() {
139
+ if (this.state.copySource === null || !this.props.copySources?.[this.state.copySource]) return;
140
+ this.setState({shown: new Set(this.copyGroups())});
141
+ }
142
+ /** The groups of the chosen copy source this sprite can show, or none before one is chosen. */
143
+ copyGroups() {
144
+ const source = this.state.copySource === null ? undefined : this.props.copySources?.[this.state.copySource];
145
+ return source ? this.available(source.groups) : [];
138
146
  }
139
147
  apply() {
140
148
  const order = [...this.standard(), ...this.props.extensions.map(extension => extension.id)];
@@ -147,6 +155,17 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
147
155
  const names = isJapanese(locale) ? standardNames.ja : standardNames.en;
148
156
  const sets = [...this.props.sets, ...this.state.addedSets];
149
157
  const hiddenInUse = [...used].filter(([group, count]) => count > 0 && !shown.has(group)).length;
158
+ // Under the pointer or focus first; otherwise, while a copy source is chosen, the groups it would choose.
159
+ const highlight = this.state.highlight ?? (this.state.copySource !== null ? new Set(this.copyGroups()) : null);
160
+ const highlighted = (group: string) => highlight?.has(group) ? 'true' : undefined;
161
+ // Pointing at or focusing a shortcut or the copy source marks the groups it would choose, as hovering them does.
162
+ const highlighting = (groups: readonly string[]) => {
163
+ const on = () => this.setState({highlight: new Set(groups)});
164
+ const off = () => this.setState({highlight: null});
165
+ return {onMouseEnter: on, onMouseLeave: off, onFocus: on, onBlur: off};
166
+ };
167
+ const copying = Boolean(this.props.newSprite && this.props.copySources?.length);
168
+ const copyGroups = copying ? this.copyGroups() : [];
150
169
  const usedBadge = (group: string) => !shown.has(group) && (used.get(group) ?? 0) > 0 && (
151
170
  <span className="tw-palette-visibility-used">{text.used(used.get(group)!)}</span>
152
171
  );
@@ -160,43 +179,55 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
160
179
  <button type="button" className="tw-palette-visibility-close" aria-label={text.close} title={text.close}
161
180
  onClick={onCancel}>×</button>
162
181
  </header>
163
- {this.props.newSprite && (this.props.copySources?.length ?? 0) > 0 && (
164
- <section aria-label={text.copyFrom}>
165
- <h3>{text.copyFrom}</h3>
166
- <div className="tw-palette-visibility-copy">
167
- <select aria-label={text.copyFrom} value={this.state.copySource}
168
- onChange={event => this.setState({copySource: Number(event.currentTarget.value)})}>
169
- {this.props.copySources.map((source, index) => (
170
- <option key={index} value={index}>{source.name}</option>
171
- ))}
172
- </select>
173
- <button type="button" className="tw-palette-visibility-copy-apply"
174
- onClick={() => this.copyAndApply()}>{text.copyApply}</button>
182
+ <section aria-label={text.quick}>
183
+ <h3>{text.quick}</h3>
184
+ <div className="tw-palette-visibility-quick" data-columns={copying ? '2' : '1'}>
185
+ <div className="tw-palette-visibility-panel" aria-label={text.sets} role="group">
186
+ <h4>{text.sets}</h4>
187
+ <div className="tw-palette-visibility-sets">
188
+ {sets.map(set => {
189
+ const groups = this.available(set.groups);
190
+ const all = groups.length > 0 && groups.every(group => shown.has(group));
191
+ return (
192
+ <button key={set.id} type="button" aria-pressed={all} data-set={set.id}
193
+ {...highlighting(groups)}
194
+ onClick={() => this.toggleSet(set)}>{set.name}{all ? ' ✓' : ''}</button>
195
+ );
196
+ })}
197
+ {naming ? (
198
+ <span className="tw-palette-visibility-naming">
199
+ <input type="text" aria-label={text.setName} placeholder={text.setName} value={setName}
200
+ autoFocus
201
+ onChange={event => this.setState({setName: event.currentTarget.value})}
202
+ onKeyDown={event => {if (event.key === 'Enter') this.addSet();}} />
203
+ <button type="button" onClick={() => this.addSet()}>{text.add}</button>
204
+ </span>
205
+ ) : (
206
+ <button type="button" className="tw-palette-visibility-add-set"
207
+ onClick={() => this.setState({naming: true})}>+{text.addSet}</button>
208
+ )}
209
+ </div>
175
210
  </div>
176
- </section>
177
- )}
178
- <section aria-label={text.sets}>
179
- <h3>{text.sets}</h3>
180
- <div className="tw-palette-visibility-sets">
181
- {sets.map(set => {
182
- const groups = this.available(set.groups);
183
- const all = groups.length > 0 && groups.every(group => shown.has(group));
184
- return (
185
- <button key={set.id} type="button" aria-pressed={all} data-set={set.id}
186
- onClick={() => this.toggleSet(set)}>{set.name}{all ? ' ✓' : ''}</button>
187
- );
188
- })}
189
- {naming ? (
190
- <span className="tw-palette-visibility-naming">
191
- <input type="text" aria-label={text.setName} placeholder={text.setName} value={setName}
192
- autoFocus
193
- onChange={event => this.setState({setName: event.currentTarget.value})}
194
- onKeyDown={event => {if (event.key === 'Enter') this.addSet();}} />
195
- <button type="button" onClick={() => this.addSet()}>{text.add}</button>
196
- </span>
197
- ) : (
198
- <button type="button" className="tw-palette-visibility-add-set"
199
- onClick={() => this.setState({naming: true})}>+{text.addSet}</button>
211
+ {copying && (
212
+ <div className="tw-palette-visibility-panel" aria-label={text.copyFrom} role="group"
213
+ {...highlighting(copyGroups)}>
214
+ <h4>{text.copyFrom}</h4>
215
+ <div className="tw-palette-visibility-copy">
216
+ <select aria-label={text.copyFrom} value={this.state.copySource ?? ''}
217
+ onChange={event => {
218
+ const value = event.currentTarget.value;
219
+ this.setState({copySource: value === '' ? null : Number(value), highlight: null});
220
+ }}>
221
+ <option value="">{text.chooseSprite}</option>
222
+ {this.props.copySources.map((source, index) => (
223
+ <option key={index} value={index}>{source.name}</option>
224
+ ))}
225
+ </select>
226
+ <button type="button" className="tw-palette-visibility-copy-button"
227
+ disabled={this.state.copySource === null}
228
+ onClick={() => this.copy()}>{text.copy}</button>
229
+ </div>
230
+ </div>
200
231
  )}
201
232
  </div>
202
233
  </section>
@@ -204,7 +235,7 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
204
235
  <h3>{text.standard}</h3>
205
236
  <div className="tw-palette-visibility-standard">
206
237
  {this.standard().map(group => (
207
- <label key={group} data-group={group}>
238
+ <label key={group} data-group={group} data-highlighted={highlighted(group)}>
208
239
  <input type="checkbox" checked={shown.has(group)} onChange={() => this.toggle(group)} />
209
240
  <span className="tw-palette-visibility-swatch" style={{color: standardColors[group]}}
210
241
  aria-hidden="true">●</span>
@@ -225,7 +256,7 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
225
256
  metadata={extension.metadata}
226
257
  ids={[extension.id]}
227
258
  locale={locale}
228
- itemProps={{'data-group': extension.id}}
259
+ itemProps={{'data-group': extension.id, 'data-highlighted': highlighted(extension.id)}}
229
260
  pick={{checked: shown.has(extension.id), onToggle: () => this.toggle(extension.id)}}
230
261
  >
231
262
  {usedBadge(extension.id)}
@@ -240,7 +271,7 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
240
271
  <span>
241
272
  <button type="button" onClick={onCancel}>{text.cancel}</button>
242
273
  <button type="button" className="tw-palette-visibility-apply" onClick={() => this.apply()}>
243
- {text.apply}
274
+ {text.confirm}
244
275
  </button>
245
276
  </span>
246
277
  </footer>
package/src/styles.css CHANGED
@@ -932,3 +932,39 @@
932
932
  color: inherit;
933
933
  font: inherit;
934
934
  }
935
+
936
+ /* 「まとめて選ぶ」: the shortcuts and the copy source side by side, as two ways to make the same choice. */
937
+ .tw-palette-visibility-quick {
938
+ display: grid;
939
+ grid-template-columns: minmax(0, 1fr);
940
+ gap: 0.6rem;
941
+ }
942
+
943
+ .tw-palette-visibility-quick[data-columns="2"] {
944
+ grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
945
+ }
946
+
947
+ .tw-palette-visibility-panel {
948
+ padding: 0.55rem 0.65rem;
949
+ border: 1px solid var(--ui-black-transparent, #80808040);
950
+ border-radius: 0.45rem;
951
+ }
952
+
953
+ .tw-palette-visibility-panel h4 {
954
+ margin: 0 0 0.45rem;
955
+ font-size: 0.85rem;
956
+ font-weight: 500;
957
+ }
958
+
959
+ /* A group under the pointer, and the groups a shortcut or copy source under the pointer would choose. */
960
+ .tw-palette-visibility-standard label {
961
+ padding: 0.15rem 0.3rem;
962
+ border-radius: 0.3rem;
963
+ }
964
+
965
+ .tw-palette-visibility-standard label:hover,
966
+ .tw-palette-visibility-standard label[data-highlighted],
967
+ .tw-palette-visibility .twextsec-row:hover,
968
+ .tw-palette-visibility .twextsec-row[data-highlighted] {
969
+ background: color-mix(in srgb, var(--looks-secondary, #7951d1) 16%, transparent);
970
+ }