@kubohiroya/turbowarp-plus-editor-code-views 0.11.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.
package/README.ja.md CHANGED
@@ -18,6 +18,7 @@ TurboWarp Plus Editor のコードの画面。1つの作品と1つの取り消
18
18
  | `./target-combobox` | コードの窓の対象の選択 |
19
19
  | `./detached-block-palette` | 別窓のブロックパレット |
20
20
  | `./palette-category-reorder`・`./palette-category-search`・`./palette-dropdown-resize` | パレットのカテゴリの並べ替えと検索、パレットのドロップダウンの大きさの変更 |
21
+ | `./palette-category-groups` | ツールボックスで別の category を含む category をグループとして表示する。アイコンをクリックすると、要素を並べた子ブロックパレットを影つきで重ねて開く(横配置のパレットではアイコンの右に横並び、縦配置では下に縦並び)。外側をクリックすると閉じる。Scratch Blocks は入れ子の category を捨てるので、`flattenCategoryGroups(tree)` と `filterGroupedToolboxTree(tree, groups, filter)` で木を整え、`attachPaletteCategoryGroups(menu, options)` で子ブロックパレットを開く。`splitExtensionCategories(tree, catalog, {nested: true})` は、グループを宣言した機能拡張をこのグループにする |
21
22
  | `./palette-category-visibility`・`./palette-visibility-dialog` | スプライト・背景ごとに、パレットに出すブロックグループを選ぶ。設定はエディターの画面状態として保存し、選ぶ画面を持つ |
22
23
  | `./block-argument-text` | 長いテキストの引数を短く表示し、ダイアログで編集する。テキストの引数で Shift+Enter を押すと、改行を入れてダイアログで編集を続ける |
23
24
  | `./block-number-input` | 数値の引数に入力した全角の数字・記号を半角にする |
package/README.md CHANGED
@@ -19,6 +19,7 @@ The code views of TurboWarp Plus Editor: code in tabs and windows that share one
19
19
  | `./detached-block-palette` | The block palette in its own window |
20
20
  | `./palette-category-visibility`, `./palette-visibility-dialog` | Choose which block groups the palette shows for each sprite and the stage. The setting is saved with the editor's screen state, with a screen to choose |
21
21
  | `./palette-category-reorder`, `./palette-category-search`, `./palette-dropdown-resize` | Reordering and searching palette categories, and resizing palette dropdowns |
22
+ | `./palette-category-groups` | Shows a category of the toolbox that holds other categories as a group: clicking its icon opens a child palette of its members, floating with a shadow — a row to the right of the icon in a horizontal palette, a column below it in a vertical one — and a click outside closes it. `flattenCategoryGroups(tree)` and `filterGroupedToolboxTree(tree, groups, filter)` prepare the tree, which Scratch Blocks would otherwise drop nested categories from; `attachPaletteCategoryGroups(menu, options)` opens the child palettes. `splitExtensionCategories(tree, catalog, {nested: true})` makes an extension that declares groups such a group |
22
23
  | `./block-argument-text` | Shortens long text arguments and edits them in a dialog. Shift+Enter in a text argument continues in the dialog with a line break |
23
24
  | `./block-number-input` | Converts full-width digits and signs typed into number arguments to half-width |
24
25
  | `./clean-up-comments` | Keeps comments with their scripts in "Clean up blocks": block comments keep their offset from the block, scripts with their comments do not cover one another, and workspace comments that cover a script move beside the scripts (`installCleanUpComments(ScratchBlocks)`) |
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Block palette groups: a category of the toolbox XML that holds other categories is a group. Scratch Blocks
3
+ * reads only the top-level categories and drops nested ones, so the tree is flattened before it is drawn:
4
+ * each nested category becomes a top-level one right after its group, and the menu hides it. Clicking the
5
+ * group's icon then shows its members in a child palette laid out like the palette it opens from — a row to the
6
+ * right of the icon for a horizontal palette, a column below it for a vertical one — and a member that is itself
7
+ * a group opens the next level the same way. A click outside the child palettes closes them.
8
+ */
9
+ /** The attribute a flattened category keeps with the id of the group it was nested in. */
10
+ export declare const groupParentAttribute = "palette-group-parent";
11
+ export interface PaletteGroups {
12
+ /** Each group's members, in order, by category id. A member may itself be a group. */
13
+ members: Map<string, string[]>;
14
+ /** The groups that also hold blocks of their own, which their child palette offers first. */
15
+ withOwnContents: Set<string>;
16
+ }
17
+ /**
18
+ * Moves every nested category of the toolbox tree to the top level, right after the group that held it, depth
19
+ * first, so Scratch Blocks makes a category of each. Returns the groups found. A nested category without an id
20
+ * gets one from its group's id and its position.
21
+ */
22
+ export declare const flattenCategoryGroups: (tree: Element | null | undefined) => PaletteGroups;
23
+ /**
24
+ * Runs a filter that removes top-level categories by id, such as the palette's group settings, on a flattened tree.
25
+ * A group the filter removes still stays, without blocks of its own, while one of its members stays; a group left
26
+ * with neither members nor blocks of its own is removed with its members. Returns the groups that remain.
27
+ */
28
+ export declare const filterGroupedToolboxTree: (tree: Element, groups: PaletteGroups, filter: (tree: Element) => void) => PaletteGroups;
29
+ /** The part of a Scratch Blocks toolbox category the child palettes use. */
30
+ export interface PaletteCategory {
31
+ id_: string;
32
+ name_: string;
33
+ item_: HTMLElement;
34
+ setSelected(selected: boolean): void;
35
+ }
36
+ export interface PaletteCategoryGroupsOptions {
37
+ /** The toolbox's categories, top level and flattened members alike. */
38
+ categories(): PaletteCategory[];
39
+ /** Whether the palette is laid out in a row. */
40
+ horizontal(): boolean;
41
+ rtl?: boolean;
42
+ /** Opens a category that is not a group, as clicking its icon in the palette would. */
43
+ choose(category: PaletteCategory): void;
44
+ /** Called when a child palette opens or the last one closes. */
45
+ onChange?(): void;
46
+ }
47
+ export interface PaletteCategoryGroupsController {
48
+ /** Takes the groups of the toolbox just drawn: hides their members' icons and marks the groups' icons. */
49
+ update(groups: PaletteGroups): void;
50
+ isGroup(id: string): boolean;
51
+ /** The id of the outermost group the category is in, or its own id when it is in none. */
52
+ topLevelId(id: string): string;
53
+ /** Opens the group's child palette from its icon, or closes it if it is open. */
54
+ toggle(category: PaletteCategory, focus?: boolean): void;
55
+ isOpen(): boolean;
56
+ /** The icon the palette shows for the category: its own, or that of the group it is in. */
57
+ anchorOf(category: PaletteCategory): HTMLElement;
58
+ /** Whether the node is in a child palette. */
59
+ contains(node: Node | null): boolean;
60
+ close(): void;
61
+ dispose(): void;
62
+ }
63
+ /** Makes clicking a group's icon in the palette menu open its child palette. */
64
+ export declare const attachPaletteCategoryGroups: (menu: HTMLElement, options: PaletteCategoryGroupsOptions) => PaletteCategoryGroupsController;
@@ -0,0 +1,355 @@
1
+ /**
2
+ * Block palette groups: a category of the toolbox XML that holds other categories is a group. Scratch Blocks
3
+ * reads only the top-level categories and drops nested ones, so the tree is flattened before it is drawn:
4
+ * each nested category becomes a top-level one right after its group, and the menu hides it. Clicking the
5
+ * group's icon then shows its members in a child palette laid out like the palette it opens from — a row to the
6
+ * right of the icon for a horizontal palette, a column below it for a vertical one — and a member that is itself
7
+ * a group opens the next level the same way. A click outside the child palettes closes them.
8
+ */
9
+ /** The attribute a flattened category keeps with the id of the group it was nested in. */
10
+ export const groupParentAttribute = 'palette-group-parent';
11
+ const isCategory = (node) => node.nodeType === 1 && node.tagName.toLowerCase() === 'category';
12
+ const ownsContents = (category) => Array.from(category.children).some(child => !isCategory(child));
13
+ /**
14
+ * Moves every nested category of the toolbox tree to the top level, right after the group that held it, depth
15
+ * first, so Scratch Blocks makes a category of each. Returns the groups found. A nested category without an id
16
+ * gets one from its group's id and its position.
17
+ */
18
+ export const flattenCategoryGroups = (tree) => {
19
+ const groups = { members: new Map(), withOwnContents: new Set() };
20
+ if (!tree)
21
+ return groups;
22
+ const used = new Set(Array.from(tree.querySelectorAll('category[id]'), category => category.getAttribute('id')));
23
+ const flatten = (category, after) => {
24
+ const nested = Array.from(category.children).filter(isCategory);
25
+ if (!nested.length)
26
+ return after;
27
+ const id = category.getAttribute('id');
28
+ groups.members.set(id, []);
29
+ if (ownsContents(category))
30
+ groups.withOwnContents.add(id);
31
+ let last = after;
32
+ nested.forEach((child, index) => {
33
+ if (!child.getAttribute('id')) {
34
+ let generated = `${id}/${index}`;
35
+ while (used.has(generated))
36
+ generated += '_';
37
+ used.add(generated);
38
+ child.setAttribute('id', generated);
39
+ }
40
+ child.setAttribute(groupParentAttribute, id);
41
+ groups.members.get(id).push(child.getAttribute('id'));
42
+ last.after(child);
43
+ last = flatten(child, child);
44
+ });
45
+ return last;
46
+ };
47
+ for (const category of Array.from(tree.children).filter(isCategory)) {
48
+ if (!category.getAttribute('id'))
49
+ continue;
50
+ flatten(category, category);
51
+ }
52
+ return groups;
53
+ };
54
+ /**
55
+ * Runs a filter that removes top-level categories by id, such as the palette's group settings, on a flattened tree.
56
+ * A group the filter removes still stays, without blocks of its own, while one of its members stays; a group left
57
+ * with neither members nor blocks of its own is removed with its members. Returns the groups that remain.
58
+ */
59
+ export const filterGroupedToolboxTree = (tree, groups, filter) => {
60
+ const elements = new Map();
61
+ const markers = new Map();
62
+ for (const category of Array.from(tree.children).filter(isCategory)) {
63
+ const id = category.getAttribute('id');
64
+ if (!groups.members.has(id))
65
+ continue;
66
+ const marker = tree.ownerDocument.createComment('palette-group');
67
+ category.before(marker);
68
+ elements.set(id, category);
69
+ markers.set(id, marker);
70
+ }
71
+ filter(tree);
72
+ const present = (element) => !!element && element.parentNode === tree;
73
+ const remaining = { members: new Map(), withOwnContents: new Set() };
74
+ const keep = (id) => {
75
+ const members = groups.members.get(id);
76
+ if (!members)
77
+ return present(Array.from(tree.children).find(child => isCategory(child) && child.getAttribute('id') === id));
78
+ const kept = members.filter(keep);
79
+ const ownShown = groups.withOwnContents.has(id) && present(elements.get(id));
80
+ if (!kept.length && !ownShown)
81
+ return false;
82
+ remaining.members.set(id, kept);
83
+ if (ownShown)
84
+ remaining.withOwnContents.add(id);
85
+ return true;
86
+ };
87
+ for (const [id, element] of elements) {
88
+ if (!element.hasAttribute(groupParentAttribute))
89
+ keep(id);
90
+ }
91
+ for (const [id, element] of elements) {
92
+ if (!remaining.members.has(id))
93
+ element.remove();
94
+ else if (!present(element)) {
95
+ // Shown only as the way to its members.
96
+ element.replaceChildren();
97
+ markers.get(id).after(element);
98
+ }
99
+ }
100
+ for (const marker of markers.values())
101
+ marker.remove();
102
+ // A member whose group is gone goes with it.
103
+ for (const category of Array.from(tree.children).filter(isCategory)) {
104
+ const parent = category.getAttribute(groupParentAttribute);
105
+ if (parent && !remaining.members.has(parent))
106
+ category.remove();
107
+ }
108
+ return remaining;
109
+ };
110
+ const selectedClass = 'categorySelected';
111
+ /** Makes clicking a group's icon in the palette menu open its child palette. */
112
+ export const attachPaletteCategoryGroups = (menu, options) => {
113
+ const doc = menu.ownerDocument;
114
+ const events = new doc.defaultView.AbortController();
115
+ const capture = { capture: true, signal: events.signal };
116
+ let groups = { members: new Map(), withOwnContents: new Set() };
117
+ const parentOf = new Map();
118
+ // The open child palettes, outermost first, with the icon each opened from.
119
+ const stack = [];
120
+ let selected = null;
121
+ const categoryById = (id) => options.categories().find(category => category.id_ === id);
122
+ const topLevelOf = (id) => {
123
+ let current = id;
124
+ while (parentOf.has(current))
125
+ current = parentOf.get(current);
126
+ return current;
127
+ };
128
+ const markSelection = () => {
129
+ for (const [id] of groups.members) {
130
+ if (parentOf.has(id))
131
+ continue;
132
+ const item = categoryById(id)?.item_;
133
+ if (!item)
134
+ continue;
135
+ const current = selected !== null && selected !== id && topLevelOf(selected) === id;
136
+ item.toggleAttribute('data-palette-group-current', current);
137
+ if (current)
138
+ item.classList.add(selectedClass);
139
+ else if (selected !== id)
140
+ item.classList.remove(selectedClass);
141
+ }
142
+ };
143
+ const closeFrom = (depth) => {
144
+ let changed = false;
145
+ while (stack.length > depth) {
146
+ const { anchor, popup } = stack.pop();
147
+ anchor.setAttribute('aria-expanded', 'false');
148
+ popup.remove();
149
+ changed = true;
150
+ }
151
+ if (changed)
152
+ options.onChange?.();
153
+ };
154
+ const close = () => closeFrom(0);
155
+ const place = (popup, anchor) => {
156
+ const container = popup.offsetParent ?? popup.parentElement;
157
+ const bounds = container.getBoundingClientRect();
158
+ const rect = anchor.getBoundingClientRect();
159
+ const width = popup.offsetWidth;
160
+ const height = popup.offsetHeight;
161
+ const maxLeft = Math.max(0, container.clientWidth - width);
162
+ const maxTop = Math.max(0, container.clientHeight - height);
163
+ let left;
164
+ let top;
165
+ if (options.horizontal()) {
166
+ left = (options.rtl ? rect.left - width : rect.right) - bounds.left;
167
+ top = rect.top - bounds.top;
168
+ }
169
+ else {
170
+ left = (options.rtl ? rect.right - width : rect.left) - bounds.left;
171
+ top = rect.bottom - bounds.top;
172
+ }
173
+ popup.style.left = `${Math.min(Math.max(0, left), maxLeft)}px`;
174
+ popup.style.top = `${Math.min(Math.max(0, top), maxTop)}px`;
175
+ };
176
+ const activate = (category, entry, depth, focus, self) => {
177
+ if (!self && groups.members.has(category.id_)) {
178
+ if (stack[depth]?.id === category.id_)
179
+ closeFrom(depth);
180
+ else
181
+ open(category, entry, depth, focus);
182
+ return;
183
+ }
184
+ close();
185
+ options.choose(category);
186
+ };
187
+ const createEntry = (category, depth, self = false) => {
188
+ const entry = doc.createElement('div');
189
+ entry.className = `scratchCategoryMenuItem scratchCategoryId-${category.id_}`;
190
+ entry.classList.add('tw-palette-group-item');
191
+ entry.setAttribute('data-palette-group-item', category.id_);
192
+ entry.setAttribute('role', 'menuitem');
193
+ entry.tabIndex = -1;
194
+ for (const child of Array.from(category.item_.children))
195
+ entry.append(child.cloneNode(true));
196
+ const isGroup = !self && groups.members.has(category.id_);
197
+ if (isGroup) {
198
+ entry.setAttribute('aria-haspopup', 'true');
199
+ entry.setAttribute('aria-expanded', 'false');
200
+ }
201
+ if (selected === category.id_ || (isGroup && selected !== null && isInside(selected, category.id_))) {
202
+ entry.classList.add(selectedClass);
203
+ }
204
+ entry.addEventListener('click', event => {
205
+ event.stopPropagation();
206
+ activate(category, entry, depth, false, self);
207
+ }, { signal: events.signal });
208
+ entry.addEventListener('keydown', event => {
209
+ if (event.key === 'Enter' || event.key === ' ') {
210
+ event.preventDefault();
211
+ event.stopPropagation();
212
+ activate(category, entry, depth, true, self);
213
+ return;
214
+ }
215
+ const forward = options.horizontal() ? (options.rtl ? 'ArrowLeft' : 'ArrowRight') : 'ArrowDown';
216
+ const backward = options.horizontal() ? (options.rtl ? 'ArrowRight' : 'ArrowLeft') : 'ArrowUp';
217
+ if (event.key !== forward && event.key !== backward)
218
+ return;
219
+ event.preventDefault();
220
+ const entries = Array.from(entry.parentElement.children);
221
+ const index = entries.indexOf(entry) + (event.key === forward ? 1 : -1);
222
+ entries[(index + entries.length) % entries.length].focus();
223
+ }, { signal: events.signal });
224
+ return entry;
225
+ };
226
+ const isInside = (id, groupId) => {
227
+ for (let current = id; current !== undefined; current = parentOf.get(current)) {
228
+ if (current === groupId)
229
+ return true;
230
+ }
231
+ return false;
232
+ };
233
+ const open = (group, anchor, depth, focus) => {
234
+ closeFrom(depth);
235
+ const members = (groups.members.get(group.id_) ?? []).map(categoryById).filter(Boolean);
236
+ const popup = doc.createElement('div');
237
+ popup.className = 'tw-palette-group-popup';
238
+ popup.setAttribute('data-palette-group-popup', group.id_);
239
+ popup.setAttribute('role', 'menu');
240
+ popup.setAttribute('aria-label', anchor.textContent?.trim() || group.id_);
241
+ popup.toggleAttribute('data-horizontal', options.horizontal());
242
+ // The child palette is drawn in the palette's own colours and type.
243
+ const look = doc.defaultView.getComputedStyle(menu.querySelector('.scratchCategoryMenu, .scratchCategoryMenuHorizontal') ?? menu);
244
+ popup.style.setProperty('--palette-group-background', look.backgroundColor);
245
+ popup.style.color = look.color;
246
+ popup.style.fontSize = look.fontSize;
247
+ popup.style.fontFamily = look.fontFamily;
248
+ if (groups.withOwnContents.has(group.id_))
249
+ popup.append(createEntry(group, depth, true));
250
+ for (const member of members)
251
+ popup.append(createEntry(member, depth + 1));
252
+ (menu.parentElement ?? doc.body).append(popup);
253
+ place(popup, anchor);
254
+ anchor.setAttribute('aria-expanded', 'true');
255
+ stack.push({ id: group.id_, anchor, popup });
256
+ options.onChange?.();
257
+ if (focus)
258
+ popup.firstElementChild?.focus();
259
+ };
260
+ const toggle = (category, focus = false) => {
261
+ if (stack[0]?.id === category.id_)
262
+ close();
263
+ else
264
+ open(category, category.item_, 0, focus);
265
+ };
266
+ const groupItem = (target) => {
267
+ if (!(target instanceof doc.defaultView.Node))
268
+ return null;
269
+ return options.categories().find(category => groups.members.has(category.id_) &&
270
+ !parentOf.has(category.id_) && category.item_.contains(target)) ?? null;
271
+ };
272
+ // Scratch Blocks opens a category on mouseup (touchend on touch screens); a group opens its child palette on click.
273
+ for (const type of ['mouseup', 'touchend']) {
274
+ menu.addEventListener(type, event => {
275
+ if (groupItem(event.target))
276
+ event.stopPropagation();
277
+ }, capture);
278
+ }
279
+ menu.addEventListener('click', event => {
280
+ const category = groupItem(event.target);
281
+ if (!category)
282
+ return;
283
+ event.stopPropagation();
284
+ toggle(category);
285
+ }, capture);
286
+ const contains = (node) => !!node && stack.some(({ popup }) => popup.contains(node));
287
+ const onPointerDown = (event) => {
288
+ if (!stack.length)
289
+ return;
290
+ const target = event.target;
291
+ if (contains(target) || stack[0].anchor.contains(target))
292
+ return;
293
+ close();
294
+ };
295
+ const onKeyDown = (event) => {
296
+ if (event.key !== 'Escape' || event.isComposing || !stack.length)
297
+ return;
298
+ event.preventDefault();
299
+ // The palette's own Escape would close the block list as well.
300
+ event.stopImmediatePropagation();
301
+ const { anchor } = stack[stack.length - 1];
302
+ closeFrom(stack.length - 1);
303
+ anchor.focus();
304
+ };
305
+ doc.addEventListener('pointerdown', onPointerDown, capture);
306
+ doc.addEventListener('keydown', onKeyDown, capture);
307
+ menu.addEventListener('scroll', close, { signal: events.signal });
308
+ doc.defaultView.addEventListener('resize', close, { signal: events.signal });
309
+ return {
310
+ update(next) {
311
+ close();
312
+ groups = next;
313
+ parentOf.clear();
314
+ for (const [id, members] of groups.members)
315
+ for (const member of members)
316
+ parentOf.set(member, id);
317
+ for (const category of options.categories()) {
318
+ const member = parentOf.has(category.id_);
319
+ const row = category.item_.parentElement;
320
+ if (row && row !== menu)
321
+ row.hidden = member;
322
+ const group = groups.members.has(category.id_) && !member;
323
+ if (group) {
324
+ category.item_.setAttribute('aria-haspopup', 'true');
325
+ category.item_.setAttribute('aria-expanded', 'false');
326
+ category.item_.setAttribute('data-palette-group', '');
327
+ category.item_.classList.add('tw-palette-group');
328
+ }
329
+ const { setSelected } = category;
330
+ category.setSelected = function (value) {
331
+ setSelected.call(this, value);
332
+ if (value)
333
+ selected = category.id_;
334
+ else if (selected === category.id_)
335
+ selected = null;
336
+ markSelection();
337
+ };
338
+ if (category.item_.classList.contains(selectedClass))
339
+ selected = category.id_;
340
+ }
341
+ markSelection();
342
+ },
343
+ isGroup: id => groups.members.has(id) && !parentOf.has(id),
344
+ topLevelId: topLevelOf,
345
+ toggle,
346
+ isOpen: () => stack.length > 0,
347
+ anchorOf: category => categoryById(topLevelOf(category.id_))?.item_ ?? category.item_,
348
+ contains,
349
+ close,
350
+ dispose() {
351
+ close();
352
+ events.abort();
353
+ }
354
+ };
355
+ };
@@ -99,8 +99,12 @@ export declare function defaultVisibleGroups(target: Pick<PaletteTarget, 'blocks
99
99
  /**
100
100
  * Splits each extension category whose extension declares groups into one category per group, in the catalog's
101
101
  * order. A label, separator or button goes with the block after it, or with the last block when none follows.
102
+ * With `nested`, the extension's category stays, with its unmarked blocks, and holds the categories of its declared
103
+ * groups, so the palette can show it as a group that opens them (see `./palette-category-groups`).
102
104
  */
103
- export declare function splitExtensionCategories(tree: Element, catalog: PaletteGroupCatalog): void;
105
+ export declare function splitExtensionCategories(tree: Element, catalog: PaletteGroupCatalog, { nested }?: {
106
+ nested?: boolean;
107
+ }): void;
104
108
  /**
105
109
  * Removes the categories the target does not show from a parsed toolbox, before the palette is drawn from it.
106
110
  * With a catalog, an extension that declares groups is first split into a category per group.
@@ -156,11 +156,27 @@ export function defaultVisibleGroups(target, extensionGroups, catalog) {
156
156
  const used = usedGroups(target, catalog);
157
157
  return [...standardGroups, ...extensionGroups.filter(id => used.has(id))];
158
158
  }
159
+ /** A category for one group of an extension, drawn like the extension's own unless the group has its own look. */
160
+ function groupCategory(category, group, children) {
161
+ const part = category.cloneNode(false);
162
+ part.setAttribute('id', group.id);
163
+ part.setAttribute('name', group.name);
164
+ if (group.color1)
165
+ part.setAttribute('colour', group.color1);
166
+ if (group.color2)
167
+ part.setAttribute('secondaryColour', group.color2);
168
+ if (group.menuIconURI)
169
+ part.setAttribute('iconURI', group.menuIconURI);
170
+ part.append(...children);
171
+ return part;
172
+ }
159
173
  /**
160
174
  * Splits each extension category whose extension declares groups into one category per group, in the catalog's
161
175
  * order. A label, separator or button goes with the block after it, or with the last block when none follows.
176
+ * With `nested`, the extension's category stays, with its unmarked blocks, and holds the categories of its declared
177
+ * groups, so the palette can show it as a group that opens them (see `./palette-category-groups`).
162
178
  */
163
- export function splitExtensionCategories(tree, catalog) {
179
+ export function splitExtensionCategories(tree, catalog, { nested = false } = {}) {
164
180
  for (const category of Array.from(tree.querySelectorAll(':scope > category'))) {
165
181
  const extensionId = category.getAttribute('id');
166
182
  const groups = catalog.groups.filter(group => group.extensionId === extensionId);
@@ -180,24 +196,27 @@ export function splitExtensionCategories(tree, catalog) {
180
196
  }
181
197
  if (pending.length)
182
198
  items.set(last, [...items.get(last) ?? [], ...pending]);
199
+ if (nested) {
200
+ category.replaceChildren(...items.get(extensionId) ?? []);
201
+ for (const group of groups) {
202
+ const children = items.get(group.id);
203
+ if (!group.declared || !children)
204
+ continue;
205
+ const part = groupCategory(category, group, children);
206
+ part.removeAttribute('showStatusButton');
207
+ category.append(part);
208
+ }
209
+ continue;
210
+ }
183
211
  let first = true;
184
212
  for (const group of groups) {
185
213
  const children = items.get(group.id);
186
214
  if (!children)
187
215
  continue;
188
- const part = category.cloneNode(false);
189
- part.setAttribute('id', group.id);
190
- part.setAttribute('name', group.name);
191
- if (group.color1)
192
- part.setAttribute('colour', group.color1);
193
- if (group.color2)
194
- part.setAttribute('secondaryColour', group.color2);
195
- if (group.menuIconURI)
196
- part.setAttribute('iconURI', group.menuIconURI);
216
+ const part = groupCategory(category, group, children);
197
217
  if (!first)
198
218
  part.removeAttribute('showStatusButton');
199
219
  first = false;
200
- part.append(...children);
201
220
  category.before(part);
202
221
  }
203
222
  category.remove();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-plus-editor-code-views",
3
- "version": "0.11.0",
3
+ "version": "0.12.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",
@@ -54,6 +54,10 @@
54
54
  "types": "./dist/palette-dropdown-resize.d.ts",
55
55
  "default": "./dist/palette-dropdown-resize.js"
56
56
  },
57
+ "./palette-category-groups": {
58
+ "types": "./dist/palette-category-groups.d.ts",
59
+ "default": "./dist/palette-category-groups.js"
60
+ },
57
61
  "./palette-category-visibility": {
58
62
  "types": "./dist/palette-category-visibility.d.ts",
59
63
  "default": "./dist/palette-category-visibility.js"
@@ -0,0 +1,378 @@
1
+ /**
2
+ * Block palette groups: a category of the toolbox XML that holds other categories is a group. Scratch Blocks
3
+ * reads only the top-level categories and drops nested ones, so the tree is flattened before it is drawn:
4
+ * each nested category becomes a top-level one right after its group, and the menu hides it. Clicking the
5
+ * group's icon then shows its members in a child palette laid out like the palette it opens from — a row to the
6
+ * right of the icon for a horizontal palette, a column below it for a vertical one — and a member that is itself
7
+ * a group opens the next level the same way. A click outside the child palettes closes them.
8
+ */
9
+
10
+ /** The attribute a flattened category keeps with the id of the group it was nested in. */
11
+ export const groupParentAttribute = 'palette-group-parent';
12
+
13
+ export interface PaletteGroups {
14
+ /** Each group's members, in order, by category id. A member may itself be a group. */
15
+ members: Map<string, string[]>;
16
+ /** The groups that also hold blocks of their own, which their child palette offers first. */
17
+ withOwnContents: Set<string>;
18
+ }
19
+
20
+ const isCategory = (node: Node): node is Element =>
21
+ node.nodeType === 1 && (node as Element).tagName.toLowerCase() === 'category';
22
+ const ownsContents = (category: Element) => Array.from(category.children).some(child => !isCategory(child));
23
+
24
+ /**
25
+ * Moves every nested category of the toolbox tree to the top level, right after the group that held it, depth
26
+ * first, so Scratch Blocks makes a category of each. Returns the groups found. A nested category without an id
27
+ * gets one from its group's id and its position.
28
+ */
29
+ export const flattenCategoryGroups = (tree: Element | null | undefined): PaletteGroups => {
30
+ const groups: PaletteGroups = {members: new Map(), withOwnContents: new Set()};
31
+ if (!tree) return groups;
32
+ const used = new Set(Array.from(tree.querySelectorAll('category[id]'), category => category.getAttribute('id')));
33
+ const flatten = (category: Element, after: Element): Element => {
34
+ const nested = Array.from(category.children).filter(isCategory);
35
+ if (!nested.length) return after;
36
+ const id = category.getAttribute('id')!;
37
+ groups.members.set(id, []);
38
+ if (ownsContents(category)) groups.withOwnContents.add(id);
39
+ let last = after;
40
+ nested.forEach((child, index) => {
41
+ if (!child.getAttribute('id')) {
42
+ let generated = `${id}/${index}`;
43
+ while (used.has(generated)) generated += '_';
44
+ used.add(generated);
45
+ child.setAttribute('id', generated);
46
+ }
47
+ child.setAttribute(groupParentAttribute, id);
48
+ groups.members.get(id)!.push(child.getAttribute('id')!);
49
+ last.after(child);
50
+ last = flatten(child, child);
51
+ });
52
+ return last;
53
+ };
54
+ for (const category of Array.from(tree.children).filter(isCategory)) {
55
+ if (!category.getAttribute('id')) continue;
56
+ flatten(category, category);
57
+ }
58
+ return groups;
59
+ };
60
+
61
+ /**
62
+ * Runs a filter that removes top-level categories by id, such as the palette's group settings, on a flattened tree.
63
+ * A group the filter removes still stays, without blocks of its own, while one of its members stays; a group left
64
+ * with neither members nor blocks of its own is removed with its members. Returns the groups that remain.
65
+ */
66
+ export const filterGroupedToolboxTree = (tree: Element, groups: PaletteGroups, filter: (tree: Element) => void):
67
+ PaletteGroups => {
68
+ const elements = new Map<string, Element>();
69
+ const markers = new Map<string, Comment>();
70
+ for (const category of Array.from(tree.children).filter(isCategory)) {
71
+ const id = category.getAttribute('id')!;
72
+ if (!groups.members.has(id)) continue;
73
+ const marker = tree.ownerDocument.createComment('palette-group');
74
+ category.before(marker);
75
+ elements.set(id, category);
76
+ markers.set(id, marker);
77
+ }
78
+ filter(tree);
79
+ const present = (element: Element | undefined) => !!element && element.parentNode === tree;
80
+ const remaining: PaletteGroups = {members: new Map(), withOwnContents: new Set()};
81
+ const keep = (id: string): boolean => {
82
+ const members = groups.members.get(id);
83
+ if (!members) return present(Array.from(tree.children).find(child => isCategory(child) && child.getAttribute('id') === id));
84
+ const kept = members.filter(keep);
85
+ const ownShown = groups.withOwnContents.has(id) && present(elements.get(id));
86
+ if (!kept.length && !ownShown) return false;
87
+ remaining.members.set(id, kept);
88
+ if (ownShown) remaining.withOwnContents.add(id);
89
+ return true;
90
+ };
91
+ for (const [id, element] of elements) {
92
+ if (!element.hasAttribute(groupParentAttribute)) keep(id);
93
+ }
94
+ for (const [id, element] of elements) {
95
+ if (!remaining.members.has(id)) element.remove();
96
+ else if (!present(element)) {
97
+ // Shown only as the way to its members.
98
+ element.replaceChildren();
99
+ markers.get(id)!.after(element);
100
+ }
101
+ }
102
+ for (const marker of markers.values()) marker.remove();
103
+ // A member whose group is gone goes with it.
104
+ for (const category of Array.from(tree.children).filter(isCategory)) {
105
+ const parent = category.getAttribute(groupParentAttribute);
106
+ if (parent && !remaining.members.has(parent)) category.remove();
107
+ }
108
+ return remaining;
109
+ };
110
+
111
+ /** The part of a Scratch Blocks toolbox category the child palettes use. */
112
+ export interface PaletteCategory {
113
+ id_: string;
114
+ name_: string;
115
+ item_: HTMLElement;
116
+ setSelected(selected: boolean): void;
117
+ }
118
+
119
+ export interface PaletteCategoryGroupsOptions {
120
+ /** The toolbox's categories, top level and flattened members alike. */
121
+ categories(): PaletteCategory[];
122
+ /** Whether the palette is laid out in a row. */
123
+ horizontal(): boolean;
124
+ rtl?: boolean;
125
+ /** Opens a category that is not a group, as clicking its icon in the palette would. */
126
+ choose(category: PaletteCategory): void;
127
+ /** Called when a child palette opens or the last one closes. */
128
+ onChange?(): void;
129
+ }
130
+
131
+ export interface PaletteCategoryGroupsController {
132
+ /** Takes the groups of the toolbox just drawn: hides their members' icons and marks the groups' icons. */
133
+ update(groups: PaletteGroups): void;
134
+ isGroup(id: string): boolean;
135
+ /** The id of the outermost group the category is in, or its own id when it is in none. */
136
+ topLevelId(id: string): string;
137
+ /** Opens the group's child palette from its icon, or closes it if it is open. */
138
+ toggle(category: PaletteCategory, focus?: boolean): void;
139
+ isOpen(): boolean;
140
+ /** The icon the palette shows for the category: its own, or that of the group it is in. */
141
+ anchorOf(category: PaletteCategory): HTMLElement;
142
+ /** Whether the node is in a child palette. */
143
+ contains(node: Node | null): boolean;
144
+ close(): void;
145
+ dispose(): void;
146
+ }
147
+
148
+ const selectedClass = 'categorySelected';
149
+
150
+ /** Makes clicking a group's icon in the palette menu open its child palette. */
151
+ export const attachPaletteCategoryGroups = (menu: HTMLElement, options: PaletteCategoryGroupsOptions):
152
+ PaletteCategoryGroupsController => {
153
+ const doc = menu.ownerDocument;
154
+ const events = new doc.defaultView!.AbortController();
155
+ const capture = {capture: true, signal: events.signal};
156
+ let groups: PaletteGroups = {members: new Map(), withOwnContents: new Set()};
157
+ const parentOf = new Map<string, string>();
158
+ // The open child palettes, outermost first, with the icon each opened from.
159
+ const stack: {id: string; anchor: HTMLElement; popup: HTMLElement}[] = [];
160
+ let selected: string | null = null;
161
+
162
+ const categoryById = (id: string) => options.categories().find(category => category.id_ === id);
163
+ const topLevelOf = (id: string) => {
164
+ let current = id;
165
+ while (parentOf.has(current)) current = parentOf.get(current)!;
166
+ return current;
167
+ };
168
+
169
+ const markSelection = () => {
170
+ for (const [id] of groups.members) {
171
+ if (parentOf.has(id)) continue;
172
+ const item = categoryById(id)?.item_;
173
+ if (!item) continue;
174
+ const current = selected !== null && selected !== id && topLevelOf(selected) === id;
175
+ item.toggleAttribute('data-palette-group-current', current);
176
+ if (current) item.classList.add(selectedClass);
177
+ else if (selected !== id) item.classList.remove(selectedClass);
178
+ }
179
+ };
180
+
181
+ const closeFrom = (depth: number) => {
182
+ let changed = false;
183
+ while (stack.length > depth) {
184
+ const {anchor, popup} = stack.pop()!;
185
+ anchor.setAttribute('aria-expanded', 'false');
186
+ popup.remove();
187
+ changed = true;
188
+ }
189
+ if (changed) options.onChange?.();
190
+ };
191
+ const close = () => closeFrom(0);
192
+
193
+ const place = (popup: HTMLElement, anchor: HTMLElement) => {
194
+ const container = popup.offsetParent as HTMLElement | null ?? popup.parentElement!;
195
+ const bounds = container.getBoundingClientRect();
196
+ const rect = anchor.getBoundingClientRect();
197
+ const width = popup.offsetWidth;
198
+ const height = popup.offsetHeight;
199
+ const maxLeft = Math.max(0, container.clientWidth - width);
200
+ const maxTop = Math.max(0, container.clientHeight - height);
201
+ let left: number;
202
+ let top: number;
203
+ if (options.horizontal()) {
204
+ left = (options.rtl ? rect.left - width : rect.right) - bounds.left;
205
+ top = rect.top - bounds.top;
206
+ } else {
207
+ left = (options.rtl ? rect.right - width : rect.left) - bounds.left;
208
+ top = rect.bottom - bounds.top;
209
+ }
210
+ popup.style.left = `${Math.min(Math.max(0, left), maxLeft)}px`;
211
+ popup.style.top = `${Math.min(Math.max(0, top), maxTop)}px`;
212
+ };
213
+
214
+ const activate = (category: PaletteCategory, entry: HTMLElement, depth: number, focus: boolean, self: boolean) => {
215
+ if (!self && groups.members.has(category.id_)) {
216
+ if (stack[depth]?.id === category.id_) closeFrom(depth);
217
+ else open(category, entry, depth, focus);
218
+ return;
219
+ }
220
+ close();
221
+ options.choose(category);
222
+ };
223
+
224
+ const createEntry = (category: PaletteCategory, depth: number, self = false) => {
225
+ const entry = doc.createElement('div');
226
+ entry.className = `scratchCategoryMenuItem scratchCategoryId-${category.id_}`;
227
+ entry.classList.add('tw-palette-group-item');
228
+ entry.setAttribute('data-palette-group-item', category.id_);
229
+ entry.setAttribute('role', 'menuitem');
230
+ entry.tabIndex = -1;
231
+ for (const child of Array.from(category.item_.children)) entry.append(child.cloneNode(true));
232
+ const isGroup = !self && groups.members.has(category.id_);
233
+ if (isGroup) {
234
+ entry.setAttribute('aria-haspopup', 'true');
235
+ entry.setAttribute('aria-expanded', 'false');
236
+ }
237
+ if (selected === category.id_ || (isGroup && selected !== null && isInside(selected, category.id_))) {
238
+ entry.classList.add(selectedClass);
239
+ }
240
+ entry.addEventListener('click', event => {
241
+ event.stopPropagation();
242
+ activate(category, entry, depth, false, self);
243
+ }, {signal: events.signal});
244
+ entry.addEventListener('keydown', event => {
245
+ if (event.key === 'Enter' || event.key === ' ') {
246
+ event.preventDefault();
247
+ event.stopPropagation();
248
+ activate(category, entry, depth, true, self);
249
+ return;
250
+ }
251
+ const forward = options.horizontal() ? (options.rtl ? 'ArrowLeft' : 'ArrowRight') : 'ArrowDown';
252
+ const backward = options.horizontal() ? (options.rtl ? 'ArrowRight' : 'ArrowLeft') : 'ArrowUp';
253
+ if (event.key !== forward && event.key !== backward) return;
254
+ event.preventDefault();
255
+ const entries = Array.from(entry.parentElement!.children) as HTMLElement[];
256
+ const index = entries.indexOf(entry) + (event.key === forward ? 1 : -1);
257
+ entries[(index + entries.length) % entries.length].focus();
258
+ }, {signal: events.signal});
259
+ return entry;
260
+ };
261
+
262
+ const isInside = (id: string, groupId: string) => {
263
+ for (let current: string | undefined = id; current !== undefined; current = parentOf.get(current)) {
264
+ if (current === groupId) return true;
265
+ }
266
+ return false;
267
+ };
268
+
269
+ const open = (group: PaletteCategory, anchor: HTMLElement, depth: number, focus: boolean) => {
270
+ closeFrom(depth);
271
+ const members = (groups.members.get(group.id_) ?? []).map(categoryById).filter(Boolean) as PaletteCategory[];
272
+ const popup = doc.createElement('div');
273
+ popup.className = 'tw-palette-group-popup';
274
+ popup.setAttribute('data-palette-group-popup', group.id_);
275
+ popup.setAttribute('role', 'menu');
276
+ popup.setAttribute('aria-label', anchor.textContent?.trim() || group.id_);
277
+ popup.toggleAttribute('data-horizontal', options.horizontal());
278
+ // The child palette is drawn in the palette's own colours and type.
279
+ const look = doc.defaultView!.getComputedStyle(menu.querySelector('.scratchCategoryMenu, .scratchCategoryMenuHorizontal') ?? menu);
280
+ popup.style.setProperty('--palette-group-background', look.backgroundColor);
281
+ popup.style.color = look.color;
282
+ popup.style.fontSize = look.fontSize;
283
+ popup.style.fontFamily = look.fontFamily;
284
+ if (groups.withOwnContents.has(group.id_)) popup.append(createEntry(group, depth, true));
285
+ for (const member of members) popup.append(createEntry(member, depth + 1));
286
+ (menu.parentElement ?? doc.body).append(popup);
287
+ place(popup, anchor);
288
+ anchor.setAttribute('aria-expanded', 'true');
289
+ stack.push({id: group.id_, anchor, popup});
290
+ options.onChange?.();
291
+ if (focus) (popup.firstElementChild as HTMLElement | null)?.focus();
292
+ };
293
+
294
+ const toggle = (category: PaletteCategory, focus = false) => {
295
+ if (stack[0]?.id === category.id_) close();
296
+ else open(category, category.item_, 0, focus);
297
+ };
298
+
299
+ const groupItem = (target: EventTarget | null) => {
300
+ if (!(target instanceof doc.defaultView!.Node)) return null;
301
+ return options.categories().find(category => groups.members.has(category.id_) &&
302
+ !parentOf.has(category.id_) && category.item_.contains(target as Node)) ?? null;
303
+ };
304
+ // Scratch Blocks opens a category on mouseup (touchend on touch screens); a group opens its child palette on click.
305
+ for (const type of ['mouseup', 'touchend']) {
306
+ menu.addEventListener(type, event => {
307
+ if (groupItem(event.target)) event.stopPropagation();
308
+ }, capture);
309
+ }
310
+ menu.addEventListener('click', event => {
311
+ const category = groupItem(event.target);
312
+ if (!category) return;
313
+ event.stopPropagation();
314
+ toggle(category);
315
+ }, capture);
316
+
317
+ const contains = (node: Node | null) => !!node && stack.some(({popup}) => popup.contains(node));
318
+ const onPointerDown = (event: PointerEvent) => {
319
+ if (!stack.length) return;
320
+ const target = event.target as Node | null;
321
+ if (contains(target) || stack[0].anchor.contains(target)) return;
322
+ close();
323
+ };
324
+ const onKeyDown = (event: KeyboardEvent) => {
325
+ if (event.key !== 'Escape' || event.isComposing || !stack.length) return;
326
+ event.preventDefault();
327
+ // The palette's own Escape would close the block list as well.
328
+ event.stopImmediatePropagation();
329
+ const {anchor} = stack[stack.length - 1];
330
+ closeFrom(stack.length - 1);
331
+ anchor.focus();
332
+ };
333
+ doc.addEventListener('pointerdown', onPointerDown, capture);
334
+ doc.addEventListener('keydown', onKeyDown, capture);
335
+ menu.addEventListener('scroll', close, {signal: events.signal});
336
+ doc.defaultView!.addEventListener('resize', close, {signal: events.signal});
337
+
338
+ return {
339
+ update(next) {
340
+ close();
341
+ groups = next;
342
+ parentOf.clear();
343
+ for (const [id, members] of groups.members) for (const member of members) parentOf.set(member, id);
344
+ for (const category of options.categories()) {
345
+ const member = parentOf.has(category.id_);
346
+ const row = category.item_.parentElement;
347
+ if (row && row !== menu) row.hidden = member;
348
+ const group = groups.members.has(category.id_) && !member;
349
+ if (group) {
350
+ category.item_.setAttribute('aria-haspopup', 'true');
351
+ category.item_.setAttribute('aria-expanded', 'false');
352
+ category.item_.setAttribute('data-palette-group', '');
353
+ category.item_.classList.add('tw-palette-group');
354
+ }
355
+ const {setSelected} = category;
356
+ category.setSelected = function (value: boolean) {
357
+ setSelected.call(this, value);
358
+ if (value) selected = category.id_;
359
+ else if (selected === category.id_) selected = null;
360
+ markSelection();
361
+ };
362
+ if (category.item_.classList.contains(selectedClass)) selected = category.id_;
363
+ }
364
+ markSelection();
365
+ },
366
+ isGroup: id => groups.members.has(id) && !parentOf.has(id),
367
+ topLevelId: topLevelOf,
368
+ toggle,
369
+ isOpen: () => stack.length > 0,
370
+ anchorOf: category => categoryById(topLevelOf(category.id_))?.item_ ?? category.item_,
371
+ contains,
372
+ close,
373
+ dispose() {
374
+ close();
375
+ events.abort();
376
+ }
377
+ };
378
+ };
@@ -222,11 +222,26 @@ export function defaultVisibleGroups(target: Pick<PaletteTarget, 'blocks'>, exte
222
222
  return [...standardGroups, ...extensionGroups.filter(id => used.has(id))];
223
223
  }
224
224
 
225
+ /** A category for one group of an extension, drawn like the extension's own unless the group has its own look. */
226
+ function groupCategory(category: Element, group: ExtensionPaletteGroup, children: Element[]): Element {
227
+ const part = category.cloneNode(false) as Element;
228
+ part.setAttribute('id', group.id);
229
+ part.setAttribute('name', group.name);
230
+ if (group.color1) part.setAttribute('colour', group.color1);
231
+ if (group.color2) part.setAttribute('secondaryColour', group.color2);
232
+ if (group.menuIconURI) part.setAttribute('iconURI', group.menuIconURI);
233
+ part.append(...children);
234
+ return part;
235
+ }
236
+
225
237
  /**
226
238
  * Splits each extension category whose extension declares groups into one category per group, in the catalog's
227
239
  * order. A label, separator or button goes with the block after it, or with the last block when none follows.
240
+ * With `nested`, the extension's category stays, with its unmarked blocks, and holds the categories of its declared
241
+ * groups, so the palette can show it as a group that opens them (see `./palette-category-groups`).
228
242
  */
229
- export function splitExtensionCategories(tree: Element, catalog: PaletteGroupCatalog): void {
243
+ export function splitExtensionCategories(tree: Element, catalog: PaletteGroupCatalog,
244
+ {nested = false}: {nested?: boolean} = {}): void {
230
245
  for (const category of Array.from(tree.querySelectorAll(':scope > category'))) {
231
246
  const extensionId = category.getAttribute('id');
232
247
  const groups = catalog.groups.filter(group => group.extensionId === extensionId);
@@ -244,19 +259,24 @@ export function splitExtensionCategories(tree: Element, catalog: PaletteGroupCat
244
259
  pending = [];
245
260
  }
246
261
  if (pending.length) items.set(last, [...items.get(last) ?? [], ...pending]);
262
+ if (nested) {
263
+ category.replaceChildren(...items.get(extensionId) ?? []);
264
+ for (const group of groups) {
265
+ const children = items.get(group.id);
266
+ if (!group.declared || !children) continue;
267
+ const part = groupCategory(category, group, children);
268
+ part.removeAttribute('showStatusButton');
269
+ category.append(part);
270
+ }
271
+ continue;
272
+ }
247
273
  let first = true;
248
274
  for (const group of groups) {
249
275
  const children = items.get(group.id);
250
276
  if (!children) continue;
251
- const part = category.cloneNode(false) as Element;
252
- part.setAttribute('id', group.id);
253
- part.setAttribute('name', group.name);
254
- if (group.color1) part.setAttribute('colour', group.color1);
255
- if (group.color2) part.setAttribute('secondaryColour', group.color2);
256
- if (group.menuIconURI) part.setAttribute('iconURI', group.menuIconURI);
277
+ const part = groupCategory(category, group, children);
257
278
  if (!first) part.removeAttribute('showStatusButton');
258
279
  first = false;
259
- part.append(...children);
260
280
  category.before(part);
261
281
  }
262
282
  category.remove();
package/src/styles.css CHANGED
@@ -980,3 +980,60 @@
980
980
  .tw-palette-visibility .twextsec-row[data-highlighted] {
981
981
  background: color-mix(in srgb, var(--looks-secondary, #7951d1) 16%, transparent);
982
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
+ }