@kubohiroya/turbowarp-plus-editor-code-views 0.10.0 → 0.12.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 {
@@ -56,7 +61,7 @@ const messages = {
56
61
  quick: 'Choose several at once', copyFrom: 'Copy settings from', copy: 'Copy', chooseSprite: 'Choose a sprite',
57
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', confirm: 'Confirm', 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: '背景',
@@ -64,7 +69,7 @@ const messages = {
64
69
  quick: 'まとめて選ぶ', copyFrom: '設定のコピー元', copy: 'コピー', chooseSprite: 'スプライトを選ぶ',
65
70
  sets: '設定のショートカット', addSet: '設定のショートカットを追加', setName: 'ショートカットの名前', add: '追加',
66
71
  standard: '標準のブロックグループ', extensions: '機能拡張のブロックグループ', used: (count: number) => `使用中 ${count}`,
67
- hiddenInUse: (count: number) => `非表示中・使用中 ${count} 件`, cancel: 'キャンセル', confirm: '確定', close: '閉じる'
72
+ hiddenInUse: (count: number) => `非表示中・使用中 ${count} 件`, otherBlocks: 'そのほかのブロック', cancel: 'キャンセル', confirm: '確定', close: '閉じる'
68
73
  }
69
74
  };
70
75
  const isJapanese = (locale?: string) => /^ja(?:-|$)/i.test(locale ?? '');
@@ -97,8 +102,13 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
97
102
  // The stage has no motion blocks.
98
103
  return standardGroups.filter(group => !(this.props.isStage && group === 'motion'));
99
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
+ }
100
110
  available(groups: readonly string[]) {
101
- const offered = new Set<string>([...this.standard(), ...this.props.extensions.map(extension => extension.id)]);
111
+ const offered = new Set<string>(this.offered());
102
112
  return groups.filter(group => offered.has(group));
103
113
  }
104
114
  toggle(group: string) {
@@ -127,8 +137,7 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
127
137
  const taken = new Set([...this.props.sets, ...this.state.addedSets].map(set => set.id));
128
138
  let id = name.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '') || 'set';
129
139
  for (let index = 2; taken.has(id); index++) id = `${id.replace(/-\d+$/, '')}-${index}`;
130
- const groups = [...this.standard(), ...this.props.extensions.map(extension => extension.id)]
131
- .filter(group => this.state.shown.has(group));
140
+ const groups = this.offered().filter(group => this.state.shown.has(group));
132
141
  this.setState(({addedSets}) => ({addedSets: [...addedSets, {id, name, groups}], naming: false, setName: ''}));
133
142
  }
134
143
  /**
@@ -145,8 +154,7 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
145
154
  return source ? this.available(source.groups) : [];
146
155
  }
147
156
  apply() {
148
- const order = [...this.standard(), ...this.props.extensions.map(extension => extension.id)];
149
- 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});
150
158
  }
151
159
  render() {
152
160
  const {locale, targetName, isStage, used, extensions, onCancel} = this.props;
@@ -250,7 +258,29 @@ export class PaletteVisibilityDialog extends React.PureComponent<PaletteVisibili
250
258
  <h3>{text.extensions}</h3>
251
259
  <div className="twextsec-review">
252
260
  <ul className="twextsec-rows">
253
- {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
+ ) : (
254
284
  <ExtensionRow
255
285
  key={extension.id}
256
286
  metadata={extension.metadata}
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);
@@ -957,14 +966,74 @@
957
966
  }
958
967
 
959
968
  /* A group under the pointer, and the groups a shortcut or copy source under the pointer would choose. */
960
- .tw-palette-visibility-standard label {
969
+ .tw-palette-visibility-standard label,
970
+ .tw-palette-visibility-extension-groups label {
961
971
  padding: 0.15rem 0.3rem;
962
972
  border-radius: 0.3rem;
963
973
  }
964
974
 
965
975
  .tw-palette-visibility-standard label:hover,
966
976
  .tw-palette-visibility-standard label[data-highlighted],
967
- .tw-palette-visibility .twextsec-row:hover,
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,
968
980
  .tw-palette-visibility .twextsec-row[data-highlighted] {
969
981
  background: color-mix(in srgb, var(--looks-secondary, #7951d1) 16%, transparent);
970
982
  }
983
+
984
+ /* The child palettes of the block palette's groups: each floats just above the palette it opens from. */
985
+ .tw-palette-group-popup {
986
+ position: absolute;
987
+ z-index: 40;
988
+ display: flex;
989
+ flex-direction: column;
990
+ padding: 0.25rem;
991
+ border: 1px solid rgb(0 0 0 / 12%);
992
+ border-radius: 0.5rem;
993
+ background: var(--palette-group-background, var(--ui-primary, white));
994
+ box-shadow: 0 2px 4px rgb(0 0 0 / 16%), 0 6px 16px rgb(0 0 0 / 18%);
995
+ user-select: none;
996
+ -webkit-user-select: none;
997
+ }
998
+
999
+ .tw-palette-group-popup[data-horizontal] {
1000
+ flex-direction: row;
1001
+ }
1002
+
1003
+ .tw-palette-group-item {
1004
+ border-radius: 0.375rem;
1005
+ padding: 0.375rem 0.5rem;
1006
+ white-space: nowrap;
1007
+ }
1008
+
1009
+ .tw-palette-group-popup[data-horizontal] > .tw-palette-group-item {
1010
+ padding: 6px 0.65rem;
1011
+ }
1012
+
1013
+ .tw-palette-group-item:focus-visible {
1014
+ outline: 2px solid var(--looks-secondary, #855cd6);
1015
+ outline-offset: -2px;
1016
+ }
1017
+
1018
+ .tw-palette-group[aria-expanded="true"],
1019
+ .tw-palette-group-item[aria-expanded="true"] {
1020
+ background: rgb(0 0 0 / 8%);
1021
+ }
1022
+
1023
+ /* A group's icon has a small mark at its corner, as a menu that opens further does. */
1024
+ .tw-palette-group,
1025
+ .tw-palette-group-item[aria-haspopup] {
1026
+ position: relative;
1027
+ }
1028
+
1029
+ .tw-palette-group::after,
1030
+ .tw-palette-group-item[aria-haspopup]::after {
1031
+ content: '';
1032
+ position: absolute;
1033
+ right: 0.2rem;
1034
+ bottom: 0.2rem;
1035
+ border-style: solid;
1036
+ border-width: 0 0 0.35rem 0.35rem;
1037
+ border-color: transparent transparent currentColor transparent;
1038
+ opacity: 0.55;
1039
+ }