@kubohiroya/turbowarp-plus-editor-code-views 0.8.1 → 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` を渡すと、追加したばかりのスプライトについて尋ねる画面になり、見出しの下に「新しいスプライト「名前」」と出す。
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.
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
 
@@ -25,6 +25,14 @@ export interface PaletteVisibilityDialogProps {
25
25
  sets: readonly PaletteGroupSet[];
26
26
  /** Asked for a sprite just added: the screen names it as a new sprite. */
27
27
  newSprite?: boolean;
28
+ /**
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 into its choices, which the person then adjusts and applies.
31
+ */
32
+ copySources?: readonly {
33
+ name: string;
34
+ groups: readonly string[];
35
+ }[];
28
36
  onApply(choice: PaletteVisibilityChoice): void;
29
37
  onCancel(): void;
30
38
  }
@@ -33,6 +41,10 @@ interface DialogState {
33
41
  addedSets: PaletteGroupSet[];
34
42
  naming: boolean;
35
43
  setName: string;
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;
36
48
  }
37
49
  /**
38
50
  * The screen that chooses which block groups the palette shows for one sprite or the stage: sets that
@@ -46,6 +58,10 @@ export declare class PaletteVisibilityDialog extends React.PureComponent<Palette
46
58
  sprite: (name: string) => string;
47
59
  stage: string;
48
60
  newSprite: (name: string) => string;
61
+ quick: string;
62
+ copyFrom: string;
63
+ copy: string;
64
+ chooseSprite: string;
49
65
  sets: string;
50
66
  addSet: string;
51
67
  setName: string;
@@ -55,7 +71,7 @@ export declare class PaletteVisibilityDialog extends React.PureComponent<Palette
55
71
  used: (count: number) => string;
56
72
  hiddenInUse: (count: number) => string;
57
73
  cancel: string;
58
- apply: string;
74
+ confirm: string;
59
75
  close: string;
60
76
  };
61
77
  standard(): ("sound" | "variables" | "events" | "motion" | "looks" | "control" | "sensing" | "operators" | "lists" | "myBlocks")[];
@@ -63,6 +79,13 @@ export declare class PaletteVisibilityDialog extends React.PureComponent<Palette
63
79
  toggle(group: string): void;
64
80
  toggleSet(set: PaletteGroupSet): void;
65
81
  addSet(): 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[];
66
89
  apply(): void;
67
90
  render(): React.JSX.Element;
68
91
  }
@@ -16,16 +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
- 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',
20
21
  standard: 'Standard block groups', extensions: 'Extension block groups', used: (count) => `In use ${count}`,
21
- 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'
22
23
  },
23
24
  ja: {
24
25
  title: 'パレット内のブロックグループの表示・非表示の設定', sprite: (name) => `スプライト「${name}」`, stage: '背景',
25
26
  newSprite: (name) => `新しいスプライト「${name}」`,
26
- sets: '適用可能なセット', addSet: '適用可能なセットを追加', setName: 'セットの名前', add: '追加',
27
+ quick: 'まとめて選ぶ', copyFrom: '設定のコピー元', copy: 'コピー', chooseSprite: 'スプライトを選ぶ',
28
+ sets: '設定のショートカット', addSet: '設定のショートカットを追加', setName: 'ショートカットの名前', add: '追加',
27
29
  standard: '標準のブロックグループ', extensions: '機能拡張のブロックグループ', used: (count) => `使用中 ${count}`,
28
- hiddenInUse: (count) => `非表示中・使用中 ${count} 件`, cancel: 'キャンセル', apply: '適用', close: '閉じる'
30
+ hiddenInUse: (count) => `非表示中・使用中 ${count} 件`, cancel: 'キャンセル', confirm: '確定', close: '閉じる'
29
31
  }
30
32
  };
31
33
  const isJapanese = (locale) => /^ja(?:-|$)/i.test(locale ?? '');
@@ -37,7 +39,7 @@ const isJapanese = (locale) => /^ja(?:-|$)/i.test(locale ?? '');
37
39
  export class PaletteVisibilityDialog extends React.PureComponent {
38
40
  constructor(props) {
39
41
  super(props);
40
- this.state = { shown: new Set(props.initial), addedSets: [], naming: false, setName: '' };
42
+ this.state = { shown: new Set(props.initial), addedSets: [], naming: false, setName: '', copySource: null, highlight: null };
41
43
  }
42
44
  get text() {
43
45
  return isJapanese(this.props.locale) ? messages.ja : messages.en;
@@ -86,6 +88,20 @@ export class PaletteVisibilityDialog extends React.PureComponent {
86
88
  .filter(group => this.state.shown.has(group));
87
89
  this.setState(({ addedSets }) => ({ addedSets: [...addedSets, { id, name, groups }], naming: false, setName: '' }));
88
90
  }
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])
97
+ return;
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) : [];
104
+ }
89
105
  apply() {
90
106
  const order = [...this.standard(), ...this.props.extensions.map(extension => extension.id)];
91
107
  this.props.onApply({ groups: order.filter(group => this.state.shown.has(group)), addedSets: this.state.addedSets });
@@ -97,6 +113,17 @@ export class PaletteVisibilityDialog extends React.PureComponent {
97
113
  const names = isJapanese(locale) ? standardNames.ja : standardNames.en;
98
114
  const sets = [...this.props.sets, ...this.state.addedSets];
99
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() : [];
100
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))));
101
128
  return (React.createElement("div", { className: "tw-palette-visibility" },
102
129
  React.createElement("header", { className: "tw-palette-visibility-header" },
@@ -104,25 +131,38 @@ export class PaletteVisibilityDialog extends React.PureComponent {
104
131
  React.createElement("h2", null, text.title),
105
132
  React.createElement("p", null, isStage ? text.stage : this.props.newSprite ? text.newSprite(targetName) : text.sprite(targetName))),
106
133
  React.createElement("button", { type: "button", className: "tw-palette-visibility-close", "aria-label": text.close, title: text.close, onClick: onCancel }, "\u00D7")),
107
- React.createElement("section", { "aria-label": text.sets },
108
- React.createElement("h3", null, text.sets),
109
- React.createElement("div", { className: "tw-palette-visibility-sets" },
110
- sets.map(set => {
111
- const groups = this.available(set.groups);
112
- const all = groups.length > 0 && groups.every(group => shown.has(group));
113
- return (React.createElement("button", { key: set.id, type: "button", "aria-pressed": all, "data-set": set.id, onClick: () => this.toggleSet(set) },
114
- set.name,
115
- all ? ' ✓' : ''));
116
- }),
117
- naming ? (React.createElement("span", { className: "tw-palette-visibility-naming" },
118
- 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')
119
- this.addSet(); } }),
120
- 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 }) },
121
- "\uFF0B",
122
- 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)))))),
123
163
  React.createElement("section", { "aria-label": text.standard },
124
164
  React.createElement("h3", null, text.standard),
125
- 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) },
126
166
  React.createElement("input", { type: "checkbox", checked: shown.has(group), onChange: () => this.toggle(group) }),
127
167
  React.createElement("span", { className: "tw-palette-visibility-swatch", style: { color: standardColors[group] }, "aria-hidden": "true" }, "\u25CF"),
128
168
  names[group],
@@ -130,12 +170,12 @@ export class PaletteVisibilityDialog extends React.PureComponent {
130
170
  extensions.length > 0 && (React.createElement("section", { "aria-label": text.extensions },
131
171
  React.createElement("h3", null, text.extensions),
132
172
  React.createElement("div", { className: "twextsec-review" },
133
- 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)))))))),
134
174
  React.createElement("footer", { className: "tw-palette-visibility-footer" },
135
175
  React.createElement("span", { role: "status" }, hiddenInUse > 0 ? text.hiddenInUse(hiddenInUse) : ''),
136
176
  React.createElement("span", null,
137
177
  React.createElement("button", { type: "button", onClick: onCancel }, text.cancel),
138
- 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)))));
139
179
  }
140
180
  }
141
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.8.1",
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",
@@ -30,6 +30,11 @@ export interface PaletteVisibilityDialogProps {
30
30
  sets: readonly PaletteGroupSet[];
31
31
  /** Asked for a sprite just added: the screen names it as a new sprite. */
32
32
  newSprite?: boolean;
33
+ /**
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 into its choices, which the person then adjusts and applies.
36
+ */
37
+ copySources?: readonly {name: string; groups: readonly string[]}[];
33
38
  onApply(choice: PaletteVisibilityChoice): void;
34
39
  onCancel(): void;
35
40
  }
@@ -48,16 +53,18 @@ const messages = {
48
53
  en: {
49
54
  title: 'Block groups shown in the palette', sprite: (name: string) => `Sprite “${name}”`, stage: 'Stage',
50
55
  newSprite: (name: string) => `New sprite “${name}”`,
51
- 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',
52
58
  standard: 'Standard block groups', extensions: 'Extension block groups', used: (count: number) => `In use ${count}`,
53
- 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'
54
60
  },
55
61
  ja: {
56
62
  title: 'パレット内のブロックグループの表示・非表示の設定', sprite: (name: string) => `スプライト「${name}」`, stage: '背景',
57
63
  newSprite: (name: string) => `新しいスプライト「${name}」`,
58
- sets: '適用可能なセット', addSet: '適用可能なセットを追加', setName: 'セットの名前', add: '追加',
64
+ quick: 'まとめて選ぶ', copyFrom: '設定のコピー元', copy: 'コピー', chooseSprite: 'スプライトを選ぶ',
65
+ sets: '設定のショートカット', addSet: '設定のショートカットを追加', setName: 'ショートカットの名前', add: '追加',
59
66
  standard: '標準のブロックグループ', extensions: '機能拡張のブロックグループ', used: (count: number) => `使用中 ${count}`,
60
- hiddenInUse: (count: number) => `非表示中・使用中 ${count} 件`, cancel: 'キャンセル', apply: '適用', close: '閉じる'
67
+ hiddenInUse: (count: number) => `非表示中・使用中 ${count} 件`, cancel: 'キャンセル', confirm: '確定', close: '閉じる'
61
68
  }
62
69
  };
63
70
  const isJapanese = (locale?: string) => /^ja(?:-|$)/i.test(locale ?? '');
@@ -67,6 +74,10 @@ interface DialogState {
67
74
  addedSets: PaletteGroupSet[];
68
75
  naming: boolean;
69
76
  setName: string;
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;
70
81
  }
71
82
 
72
83
  /**
@@ -77,7 +88,7 @@ interface DialogState {
77
88
  export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibilityDialogProps, DialogState> {
78
89
  constructor(props: PaletteVisibilityDialogProps) {
79
90
  super(props);
80
- this.state = {shown: new Set(props.initial), addedSets: [], naming: false, setName: ''};
91
+ this.state = {shown: new Set(props.initial), addedSets: [], naming: false, setName: '', copySource: null, highlight: null};
81
92
  }
82
93
  get text() {
83
94
  return isJapanese(this.props.locale) ? messages.ja : messages.en;
@@ -120,6 +131,19 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
120
131
  .filter(group => this.state.shown.has(group));
121
132
  this.setState(({addedSets}) => ({addedSets: [...addedSets, {id, name, groups}], naming: false, setName: ''}));
122
133
  }
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) : [];
146
+ }
123
147
  apply() {
124
148
  const order = [...this.standard(), ...this.props.extensions.map(extension => extension.id)];
125
149
  this.props.onApply({groups: order.filter(group => this.state.shown.has(group)), addedSets: this.state.addedSets});
@@ -131,6 +155,17 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
131
155
  const names = isJapanese(locale) ? standardNames.ja : standardNames.en;
132
156
  const sets = [...this.props.sets, ...this.state.addedSets];
133
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() : [];
134
169
  const usedBadge = (group: string) => !shown.has(group) && (used.get(group) ?? 0) > 0 && (
135
170
  <span className="tw-palette-visibility-used">{text.used(used.get(group)!)}</span>
136
171
  );
@@ -144,28 +179,55 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
144
179
  <button type="button" className="tw-palette-visibility-close" aria-label={text.close} title={text.close}
145
180
  onClick={onCancel}>×</button>
146
181
  </header>
147
- <section aria-label={text.sets}>
148
- <h3>{text.sets}</h3>
149
- <div className="tw-palette-visibility-sets">
150
- {sets.map(set => {
151
- const groups = this.available(set.groups);
152
- const all = groups.length > 0 && groups.every(group => shown.has(group));
153
- return (
154
- <button key={set.id} type="button" aria-pressed={all} data-set={set.id}
155
- onClick={() => this.toggleSet(set)}>{set.name}{all ? ' ✓' : ''}</button>
156
- );
157
- })}
158
- {naming ? (
159
- <span className="tw-palette-visibility-naming">
160
- <input type="text" aria-label={text.setName} placeholder={text.setName} value={setName}
161
- autoFocus
162
- onChange={event => this.setState({setName: event.currentTarget.value})}
163
- onKeyDown={event => {if (event.key === 'Enter') this.addSet();}} />
164
- <button type="button" onClick={() => this.addSet()}>{text.add}</button>
165
- </span>
166
- ) : (
167
- <button type="button" className="tw-palette-visibility-add-set"
168
- onClick={() => this.setState({naming: true})}>+{text.addSet}</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>
210
+ </div>
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>
169
231
  )}
170
232
  </div>
171
233
  </section>
@@ -173,7 +235,7 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
173
235
  <h3>{text.standard}</h3>
174
236
  <div className="tw-palette-visibility-standard">
175
237
  {this.standard().map(group => (
176
- <label key={group} data-group={group}>
238
+ <label key={group} data-group={group} data-highlighted={highlighted(group)}>
177
239
  <input type="checkbox" checked={shown.has(group)} onChange={() => this.toggle(group)} />
178
240
  <span className="tw-palette-visibility-swatch" style={{color: standardColors[group]}}
179
241
  aria-hidden="true">●</span>
@@ -194,7 +256,7 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
194
256
  metadata={extension.metadata}
195
257
  ids={[extension.id]}
196
258
  locale={locale}
197
- itemProps={{'data-group': extension.id}}
259
+ itemProps={{'data-group': extension.id, 'data-highlighted': highlighted(extension.id)}}
198
260
  pick={{checked: shown.has(extension.id), onToggle: () => this.toggle(extension.id)}}
199
261
  >
200
262
  {usedBadge(extension.id)}
@@ -209,7 +271,7 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
209
271
  <span>
210
272
  <button type="button" onClick={onCancel}>{text.cancel}</button>
211
273
  <button type="button" className="tw-palette-visibility-apply" onClick={() => this.apply()}>
212
- {text.apply}
274
+ {text.confirm}
213
275
  </button>
214
276
  </span>
215
277
  </footer>
package/src/styles.css CHANGED
@@ -917,3 +917,54 @@
917
917
  outline-offset: 1px;
918
918
  }
919
919
 
920
+
921
+ .tw-palette-visibility-copy {
922
+ display: flex;
923
+ flex-wrap: wrap;
924
+ gap: 0.4rem;
925
+ }
926
+
927
+ .tw-palette-visibility select {
928
+ padding: 0.3rem 0.6rem;
929
+ border: 1px solid var(--ui-black-transparent, #80808070);
930
+ border-radius: 0.35rem;
931
+ background: var(--ui-primary, Canvas);
932
+ color: inherit;
933
+ font: inherit;
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
+ }