@kubohiroya/turbowarp-plus-editor-code-views 0.9.0 → 0.11.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.
@@ -9,6 +9,11 @@ export interface PaletteExtension {
9
9
  id: string;
10
10
  /** What the host knows about the extension; at least its name. */
11
11
  metadata: ExtensionMetadata;
12
+ /**
13
+ * The groups the extension declares, each chosen on its own, in place of the extension. A group whose ID is the
14
+ * extension's holds the blocks no declared group takes.
15
+ */
16
+ groups?: readonly {id: string; name: string; color?: string}[];
12
17
  }
13
18
 
14
19
  export interface PaletteVisibilityChoice {
@@ -32,7 +37,7 @@ export interface PaletteVisibilityDialogProps {
32
37
  newSprite?: boolean;
33
38
  /**
34
39
  * 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.
40
+ * one of them into its choices, which the person then adjusts and applies.
36
41
  */
37
42
  copySources?: readonly {name: string; groups: readonly string[]}[];
38
43
  onApply(choice: PaletteVisibilityChoice): void;
@@ -53,18 +58,18 @@ const messages = {
53
58
  en: {
54
59
  title: 'Block groups shown in the palette', sprite: (name: string) => `Sprite “${name}”`, stage: 'Stage',
55
60
  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',
61
+ quick: 'Choose several at once', copyFrom: 'Copy settings from', copy: 'Copy', chooseSprite: 'Choose a sprite',
62
+ sets: 'Setting shortcuts', addSet: 'Add setting shortcut', setName: 'Shortcut name', add: 'Add',
58
63
  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'
64
+ hiddenInUse: (count: number) => `Hidden and in use: ${count}`, otherBlocks: 'Other blocks', cancel: 'Cancel', confirm: 'Confirm', close: 'Close'
60
65
  },
61
66
  ja: {
62
67
  title: 'パレット内のブロックグループの表示・非表示の設定', sprite: (name: string) => `スプライト「${name}」`, stage: '背景',
63
68
  newSprite: (name: string) => `新しいスプライト「${name}」`,
64
- copyFrom: '作成済みのスプライトからコピー', copyApply: 'コピーして適用',
65
- sets: '適用可能なセット', addSet: '適用可能なセットを追加', setName: 'セットの名前', add: '追加',
69
+ quick: 'まとめて選ぶ', copyFrom: '設定のコピー元', copy: 'コピー', chooseSprite: 'スプライトを選ぶ',
70
+ sets: '設定のショートカット', addSet: '設定のショートカットを追加', setName: 'ショートカットの名前', add: '追加',
66
71
  standard: '標準のブロックグループ', extensions: '機能拡張のブロックグループ', used: (count: number) => `使用中 ${count}`,
67
- hiddenInUse: (count: number) => `非表示中・使用中 ${count} 件`, cancel: 'キャンセル', apply: '適用', close: '閉じる'
72
+ hiddenInUse: (count: number) => `非表示中・使用中 ${count} 件`, otherBlocks: 'そのほかのブロック', cancel: 'キャンセル', confirm: '確定', close: '閉じる'
68
73
  }
69
74
  };
70
75
  const isJapanese = (locale?: string) => /^ja(?:-|$)/i.test(locale ?? '');
@@ -74,7 +79,10 @@ interface DialogState {
74
79
  addedSets: PaletteGroupSet[];
75
80
  naming: boolean;
76
81
  setName: string;
77
- copySource: number;
82
+ /** The sprite chosen to copy from, or null before one is chosen. */
83
+ copySource: number | null;
84
+ /** The groups a shortcut or a copy source under the pointer or focus would choose, shown in the lists. */
85
+ highlight: Set<string> | null;
78
86
  }
79
87
 
80
88
  /**
@@ -85,7 +93,7 @@ interface DialogState {
85
93
  export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibilityDialogProps, DialogState> {
86
94
  constructor(props: PaletteVisibilityDialogProps) {
87
95
  super(props);
88
- this.state = {shown: new Set(props.initial), addedSets: [], naming: false, setName: '', copySource: 0};
96
+ this.state = {shown: new Set(props.initial), addedSets: [], naming: false, setName: '', copySource: null, highlight: null};
89
97
  }
90
98
  get text() {
91
99
  return isJapanese(this.props.locale) ? messages.ja : messages.en;
@@ -94,8 +102,13 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
94
102
  // The stage has no motion blocks.
95
103
  return standardGroups.filter(group => !(this.props.isStage && group === 'motion'));
96
104
  }
105
+ /** Every group on offer, in the order the screen lists them. */
106
+ offered() {
107
+ return [...this.standard(), ...this.props.extensions.flatMap(extension =>
108
+ extension.groups ? extension.groups.map(group => group.id) : [extension.id])];
109
+ }
97
110
  available(groups: readonly string[]) {
98
- const offered = new Set<string>([...this.standard(), ...this.props.extensions.map(extension => extension.id)]);
111
+ const offered = new Set<string>(this.offered());
99
112
  return groups.filter(group => offered.has(group));
100
113
  }
101
114
  toggle(group: string) {
@@ -124,21 +137,24 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
124
137
  const taken = new Set([...this.props.sets, ...this.state.addedSets].map(set => set.id));
125
138
  let id = name.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '') || 'set';
126
139
  for (let index = 2; taken.has(id); index++) id = `${id.replace(/-\d+$/, '')}-${index}`;
127
- const groups = [...this.standard(), ...this.props.extensions.map(extension => extension.id)]
128
- .filter(group => this.state.shown.has(group));
140
+ const groups = this.offered().filter(group => this.state.shown.has(group));
129
141
  this.setState(({addedSets}) => ({addedSets: [...addedSets, {id, name, groups}], naming: false, setName: ''}));
130
142
  }
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});
143
+ /**
144
+ * Choose the groups another sprite shows, as far as this one is offered them. The screen stays open, so the
145
+ * person sees the copy, adds or removes checks, and applies.
146
+ */
147
+ copy() {
148
+ if (this.state.copySource === null || !this.props.copySources?.[this.state.copySource]) return;
149
+ this.setState({shown: new Set(this.copyGroups())});
150
+ }
151
+ /** The groups of the chosen copy source this sprite can show, or none before one is chosen. */
152
+ copyGroups() {
153
+ const source = this.state.copySource === null ? undefined : this.props.copySources?.[this.state.copySource];
154
+ return source ? this.available(source.groups) : [];
138
155
  }
139
156
  apply() {
140
- const order = [...this.standard(), ...this.props.extensions.map(extension => extension.id)];
141
- this.props.onApply({groups: order.filter(group => this.state.shown.has(group)), addedSets: this.state.addedSets});
157
+ this.props.onApply({groups: this.offered().filter(group => this.state.shown.has(group)), addedSets: this.state.addedSets});
142
158
  }
143
159
  render() {
144
160
  const {locale, targetName, isStage, used, extensions, onCancel} = this.props;
@@ -147,6 +163,17 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
147
163
  const names = isJapanese(locale) ? standardNames.ja : standardNames.en;
148
164
  const sets = [...this.props.sets, ...this.state.addedSets];
149
165
  const hiddenInUse = [...used].filter(([group, count]) => count > 0 && !shown.has(group)).length;
166
+ // Under the pointer or focus first; otherwise, while a copy source is chosen, the groups it would choose.
167
+ const highlight = this.state.highlight ?? (this.state.copySource !== null ? new Set(this.copyGroups()) : null);
168
+ const highlighted = (group: string) => highlight?.has(group) ? 'true' : undefined;
169
+ // Pointing at or focusing a shortcut or the copy source marks the groups it would choose, as hovering them does.
170
+ const highlighting = (groups: readonly string[]) => {
171
+ const on = () => this.setState({highlight: new Set(groups)});
172
+ const off = () => this.setState({highlight: null});
173
+ return {onMouseEnter: on, onMouseLeave: off, onFocus: on, onBlur: off};
174
+ };
175
+ const copying = Boolean(this.props.newSprite && this.props.copySources?.length);
176
+ const copyGroups = copying ? this.copyGroups() : [];
150
177
  const usedBadge = (group: string) => !shown.has(group) && (used.get(group) ?? 0) > 0 && (
151
178
  <span className="tw-palette-visibility-used">{text.used(used.get(group)!)}</span>
152
179
  );
@@ -160,43 +187,55 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
160
187
  <button type="button" className="tw-palette-visibility-close" aria-label={text.close} title={text.close}
161
188
  onClick={onCancel}>×</button>
162
189
  </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>
190
+ <section aria-label={text.quick}>
191
+ <h3>{text.quick}</h3>
192
+ <div className="tw-palette-visibility-quick" data-columns={copying ? '2' : '1'}>
193
+ <div className="tw-palette-visibility-panel" aria-label={text.sets} role="group">
194
+ <h4>{text.sets}</h4>
195
+ <div className="tw-palette-visibility-sets">
196
+ {sets.map(set => {
197
+ const groups = this.available(set.groups);
198
+ const all = groups.length > 0 && groups.every(group => shown.has(group));
199
+ return (
200
+ <button key={set.id} type="button" aria-pressed={all} data-set={set.id}
201
+ {...highlighting(groups)}
202
+ onClick={() => this.toggleSet(set)}>{set.name}{all ? ' ✓' : ''}</button>
203
+ );
204
+ })}
205
+ {naming ? (
206
+ <span className="tw-palette-visibility-naming">
207
+ <input type="text" aria-label={text.setName} placeholder={text.setName} value={setName}
208
+ autoFocus
209
+ onChange={event => this.setState({setName: event.currentTarget.value})}
210
+ onKeyDown={event => {if (event.key === 'Enter') this.addSet();}} />
211
+ <button type="button" onClick={() => this.addSet()}>{text.add}</button>
212
+ </span>
213
+ ) : (
214
+ <button type="button" className="tw-palette-visibility-add-set"
215
+ onClick={() => this.setState({naming: true})}>+{text.addSet}</button>
216
+ )}
217
+ </div>
175
218
  </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>
219
+ {copying && (
220
+ <div className="tw-palette-visibility-panel" aria-label={text.copyFrom} role="group"
221
+ {...highlighting(copyGroups)}>
222
+ <h4>{text.copyFrom}</h4>
223
+ <div className="tw-palette-visibility-copy">
224
+ <select aria-label={text.copyFrom} value={this.state.copySource ?? ''}
225
+ onChange={event => {
226
+ const value = event.currentTarget.value;
227
+ this.setState({copySource: value === '' ? null : Number(value), highlight: null});
228
+ }}>
229
+ <option value="">{text.chooseSprite}</option>
230
+ {this.props.copySources.map((source, index) => (
231
+ <option key={index} value={index}>{source.name}</option>
232
+ ))}
233
+ </select>
234
+ <button type="button" className="tw-palette-visibility-copy-button"
235
+ disabled={this.state.copySource === null}
236
+ onClick={() => this.copy()}>{text.copy}</button>
237
+ </div>
238
+ </div>
200
239
  )}
201
240
  </div>
202
241
  </section>
@@ -204,7 +243,7 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
204
243
  <h3>{text.standard}</h3>
205
244
  <div className="tw-palette-visibility-standard">
206
245
  {this.standard().map(group => (
207
- <label key={group} data-group={group}>
246
+ <label key={group} data-group={group} data-highlighted={highlighted(group)}>
208
247
  <input type="checkbox" checked={shown.has(group)} onChange={() => this.toggle(group)} />
209
248
  <span className="tw-palette-visibility-swatch" style={{color: standardColors[group]}}
210
249
  aria-hidden="true">●</span>
@@ -219,13 +258,35 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
219
258
  <h3>{text.extensions}</h3>
220
259
  <div className="twextsec-review">
221
260
  <ul className="twextsec-rows">
222
- {extensions.map(extension => (
261
+ {extensions.map(extension => extension.groups ? (
262
+ <ExtensionRow
263
+ key={extension.id}
264
+ metadata={extension.metadata}
265
+ ids={[extension.id]}
266
+ locale={locale}
267
+ itemProps={{'data-extension': extension.id}}
268
+ >
269
+ <div className="tw-palette-visibility-extension-groups">
270
+ {extension.groups.map(group => (
271
+ <label key={group.id} data-group={group.id}
272
+ data-highlighted={highlighted(group.id)}>
273
+ <input type="checkbox" checked={shown.has(group.id)}
274
+ onChange={() => this.toggle(group.id)} />
275
+ <span className="tw-palette-visibility-swatch" aria-hidden="true"
276
+ style={{color: group.color}}>●</span>
277
+ {group.id === extension.id ? text.otherBlocks : group.name}
278
+ {usedBadge(group.id)}
279
+ </label>
280
+ ))}
281
+ </div>
282
+ </ExtensionRow>
283
+ ) : (
223
284
  <ExtensionRow
224
285
  key={extension.id}
225
286
  metadata={extension.metadata}
226
287
  ids={[extension.id]}
227
288
  locale={locale}
228
- itemProps={{'data-group': extension.id}}
289
+ itemProps={{'data-group': extension.id, 'data-highlighted': highlighted(extension.id)}}
229
290
  pick={{checked: shown.has(extension.id), onToggle: () => this.toggle(extension.id)}}
230
291
  >
231
292
  {usedBadge(extension.id)}
@@ -240,7 +301,7 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
240
301
  <span>
241
302
  <button type="button" onClick={onCancel}>{text.cancel}</button>
242
303
  <button type="button" className="tw-palette-visibility-apply" onClick={() => this.apply()}>
243
- {text.apply}
304
+ {text.confirm}
244
305
  </button>
245
306
  </span>
246
307
  </footer>
package/src/styles.css CHANGED
@@ -759,12 +759,21 @@
759
759
  gap: 0.35rem 0.75rem;
760
760
  }
761
761
 
762
- .tw-palette-visibility-standard label {
762
+ .tw-palette-visibility-standard label,
763
+ .tw-palette-visibility-extension-groups label {
763
764
  display: flex;
764
765
  align-items: center;
765
766
  gap: 0.35rem;
766
767
  }
767
768
 
769
+ /* The groups one extension declares, chosen one by one inside its row. */
770
+ .tw-palette-visibility-extension-groups {
771
+ display: grid;
772
+ grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
773
+ gap: 0.25rem 0.75rem;
774
+ margin-top: 0.4rem;
775
+ }
776
+
768
777
  .tw-palette-visibility-used {
769
778
  font-size: 0.75rem;
770
779
  color: var(--ui-warning, #b45309);
@@ -932,3 +941,42 @@
932
941
  color: inherit;
933
942
  font: inherit;
934
943
  }
944
+
945
+ /* 「まとめて選ぶ」: the shortcuts and the copy source side by side, as two ways to make the same choice. */
946
+ .tw-palette-visibility-quick {
947
+ display: grid;
948
+ grid-template-columns: minmax(0, 1fr);
949
+ gap: 0.6rem;
950
+ }
951
+
952
+ .tw-palette-visibility-quick[data-columns="2"] {
953
+ grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
954
+ }
955
+
956
+ .tw-palette-visibility-panel {
957
+ padding: 0.55rem 0.65rem;
958
+ border: 1px solid var(--ui-black-transparent, #80808040);
959
+ border-radius: 0.45rem;
960
+ }
961
+
962
+ .tw-palette-visibility-panel h4 {
963
+ margin: 0 0 0.45rem;
964
+ font-size: 0.85rem;
965
+ font-weight: 500;
966
+ }
967
+
968
+ /* A group under the pointer, and the groups a shortcut or copy source under the pointer would choose. */
969
+ .tw-palette-visibility-standard label,
970
+ .tw-palette-visibility-extension-groups label {
971
+ padding: 0.15rem 0.3rem;
972
+ border-radius: 0.3rem;
973
+ }
974
+
975
+ .tw-palette-visibility-standard label:hover,
976
+ .tw-palette-visibility-standard label[data-highlighted],
977
+ .tw-palette-visibility-extension-groups label:hover,
978
+ .tw-palette-visibility-extension-groups label[data-highlighted],
979
+ .tw-palette-visibility .twextsec-row:not([data-extension]):hover,
980
+ .tw-palette-visibility .twextsec-row[data-highlighted] {
981
+ background: color-mix(in srgb, var(--looks-secondary, #7951d1) 16%, transparent);
982
+ }