@kubohiroya/turbowarp-plus-editor-code-views 0.13.0 → 0.14.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,7 +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
+ | `./palette-category-groups` | ツールボックスで別の category を含む category をグループとして表示する。アイコンをクリックすると、要素を並べた子ブロックパレットを影つきで重ねて開く(横配置のパレットではアイコンの右に横並び、縦配置では下に縦並び)。外側をクリックすると閉じる。Scratch Blocks は入れ子の category を捨てるので、`flattenCategoryGroups(tree)` と `filterGroupedToolboxTree(tree, groups, filter)` で木を整え、`prepareGroupedToolboxTree(tree, {catalog, visible})` は、機能拡張が宣言したグループの入れ子化と表示するグループの絞り込みを含めて、これを一度に行う。`hasCategoryGroups(tree)` は木が category を入れ子にしているかを返す。`attachPaletteCategoryGroups(menu, options)` で子ブロックパレットを開く。その `selectionTarget(id)` は、自分のブロックを持たないグループの代わりに選ぶ category を返し、`syncButtons(openId)` はグループのアイコンの状態を付け直す。`splitExtensionCategories(tree, catalog, {nested: true})` は、グループを宣言した機能拡張をこのグループにする |
22
22
  | `./palette-category-visibility`・`./palette-visibility-dialog` | スプライト・背景ごとに、パレットに出すブロックグループを選ぶ。設定はエディターの画面状態として保存し、選ぶ画面を持つ |
23
23
  | `./block-argument-text` | 長いテキストの引数を短く表示し、ダイアログで編集する。テキストの引数で Shift+Enter を押すと、改行を入れてダイアログで編集を続ける |
24
24
  | `./block-number-input` | 数値の引数に入力した全角の数字・記号を半角にする |
package/README.md CHANGED
@@ -19,7 +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
+ | `./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; `prepareGroupedToolboxTree(tree, {catalog, visible})` does both in one step, also nesting the groups extensions declare and keeping only the groups to show, and `hasCategoryGroups(tree)` tells whether a tree nests categories. `attachPaletteCategoryGroups(menu, options)` opens the child palettes; its `selectionTarget(id)` gives the category to select for a group without blocks of its own, and `syncButtons(openId)` marks the groups' icons. `splitExtensionCategories(tree, catalog, {nested: true})` makes an extension that declares groups such a group |
23
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 |
24
24
  | `./block-number-input` | Converts full-width digits and signs typed into number arguments to half-width |
25
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)`) |
@@ -1,3 +1,4 @@
1
+ import type { PaletteGroupCatalog } from './palette-category-visibility.ts';
1
2
  /**
2
3
  * Block palette groups: a category of the toolbox XML that holds other categories is a group. Scratch Blocks
3
4
  * reads only the top-level categories and drops nested ones, so the tree is flattened before it is drawn:
@@ -26,6 +27,17 @@ export declare const flattenCategoryGroups: (tree: Element | null | undefined) =
26
27
  * with neither members nor blocks of its own is removed with its members. Returns the groups that remain.
27
28
  */
28
29
  export declare const filterGroupedToolboxTree: (tree: Element, groups: PaletteGroups, filter: (tree: Element) => void) => PaletteGroups;
30
+ /** Whether the toolbox tree nests categories, which Scratch Blocks drops unless the tree is prepared first. */
31
+ export declare const hasCategoryGroups: (tree: Element | null | undefined) => boolean;
32
+ /**
33
+ * Prepares a toolbox tree for the palette before Scratch Blocks draws it: with a catalog, each extension that declares
34
+ * groups becomes a group of them; nested categories are flattened; with the groups to show, the others are removed.
35
+ * Pass the groups returned to the controller's `update` once the palette is drawn.
36
+ */
37
+ export declare const prepareGroupedToolboxTree: (tree: Element, { catalog, visible }?: {
38
+ catalog?: PaletteGroupCatalog;
39
+ visible?: ReadonlySet<string> | null;
40
+ }) => PaletteGroups;
29
41
  /** The part of a Scratch Blocks toolbox category the child palettes use. */
30
42
  export interface PaletteCategory {
31
43
  id_: string;
@@ -55,6 +67,16 @@ export interface PaletteCategoryGroupsController {
55
67
  isOpen(): boolean;
56
68
  /** The icon the palette shows for the category: its own, or that of the group it is in. */
57
69
  anchorOf(category: PaletteCategory): HTMLElement;
70
+ /**
71
+ * The category to select for an id: a group without blocks of its own stands for its first member, so selecting
72
+ * an extension that declares groups selects its first shown group.
73
+ */
74
+ selectionTarget(id: string): string;
75
+ /**
76
+ * Marks the groups' icons as buttons, focusable in a horizontal palette, and marks the group whose member's blocks
77
+ * are open (`data-palette-group-shown`). Call it whenever the open category changes.
78
+ */
79
+ syncButtons(openId: string | null): void;
58
80
  /** Whether the node is in a child palette. */
59
81
  contains(node: Node | null): boolean;
60
82
  close(): void;
@@ -1,3 +1,4 @@
1
+ import { filterToolboxTree, splitExtensionCategories } from "./palette-category-visibility.js";
1
2
  /**
2
3
  * Block palette groups: a category of the toolbox XML that holds other categories is a group. Scratch Blocks
3
4
  * reads only the top-level categories and drops nested ones, so the tree is flattened before it is drawn:
@@ -107,6 +108,19 @@ export const filterGroupedToolboxTree = (tree, groups, filter) => {
107
108
  }
108
109
  return remaining;
109
110
  };
111
+ /** Whether the toolbox tree nests categories, which Scratch Blocks drops unless the tree is prepared first. */
112
+ export const hasCategoryGroups = (tree) => !!tree?.querySelector?.('category category');
113
+ /**
114
+ * Prepares a toolbox tree for the palette before Scratch Blocks draws it: with a catalog, each extension that declares
115
+ * groups becomes a group of them; nested categories are flattened; with the groups to show, the others are removed.
116
+ * Pass the groups returned to the controller's `update` once the palette is drawn.
117
+ */
118
+ export const prepareGroupedToolboxTree = (tree, { catalog, visible } = {}) => {
119
+ if (catalog)
120
+ splitExtensionCategories(tree, catalog, { nested: true });
121
+ const groups = flattenCategoryGroups(tree);
122
+ return visible ? filterGroupedToolboxTree(tree, groups, filtered => filterToolboxTree(filtered, visible)) : groups;
123
+ };
110
124
  const selectedClass = 'categorySelected';
111
125
  /** Makes clicking a group's icon in the palette menu open its child palette. */
112
126
  export const attachPaletteCategoryGroups = (menu, options) => {
@@ -345,6 +359,28 @@ export const attachPaletteCategoryGroups = (menu, options) => {
345
359
  toggle,
346
360
  isOpen: () => stack.length > 0,
347
361
  anchorOf: category => categoryById(topLevelOf(category.id_))?.item_ ?? category.item_,
362
+ selectionTarget(id) {
363
+ let target = id;
364
+ while (groups.members.get(target)?.length && !groups.withOwnContents.has(target)) {
365
+ target = groups.members.get(target)[0];
366
+ }
367
+ return target;
368
+ },
369
+ syncButtons(openId) {
370
+ const horizontal = options.horizontal();
371
+ for (const category of options.categories()) {
372
+ if (!groups.members.has(category.id_) || parentOf.has(category.id_))
373
+ continue;
374
+ const item = category.item_;
375
+ if (horizontal)
376
+ item.tabIndex = 0;
377
+ else
378
+ item.removeAttribute('tabindex');
379
+ item.setAttribute('role', 'button');
380
+ item.toggleAttribute('data-palette-group-shown', horizontal && openId !== null && openId !== category.id_ &&
381
+ topLevelOf(openId) === category.id_);
382
+ }
383
+ },
348
384
  contains,
349
385
  close,
350
386
  dispose() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-plus-editor-code-views",
3
- "version": "0.13.0",
3
+ "version": "0.14.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",
@@ -1,3 +1,6 @@
1
+ import {filterToolboxTree, splitExtensionCategories} from './palette-category-visibility.ts';
2
+ import type {PaletteGroupCatalog} from './palette-category-visibility.ts';
3
+
1
4
  /**
2
5
  * Block palette groups: a category of the toolbox XML that holds other categories is a group. Scratch Blocks
3
6
  * reads only the top-level categories and drops nested ones, so the tree is flattened before it is drawn:
@@ -108,6 +111,21 @@ export const filterGroupedToolboxTree = (tree: Element, groups: PaletteGroups, f
108
111
  return remaining;
109
112
  };
110
113
 
114
+ /** Whether the toolbox tree nests categories, which Scratch Blocks drops unless the tree is prepared first. */
115
+ export const hasCategoryGroups = (tree: Element | null | undefined): boolean => !!tree?.querySelector?.('category category');
116
+
117
+ /**
118
+ * Prepares a toolbox tree for the palette before Scratch Blocks draws it: with a catalog, each extension that declares
119
+ * groups becomes a group of them; nested categories are flattened; with the groups to show, the others are removed.
120
+ * Pass the groups returned to the controller's `update` once the palette is drawn.
121
+ */
122
+ export const prepareGroupedToolboxTree = (tree: Element,
123
+ {catalog, visible}: {catalog?: PaletteGroupCatalog; visible?: ReadonlySet<string> | null} = {}): PaletteGroups => {
124
+ if (catalog) splitExtensionCategories(tree, catalog, {nested: true});
125
+ const groups = flattenCategoryGroups(tree);
126
+ return visible ? filterGroupedToolboxTree(tree, groups, filtered => filterToolboxTree(filtered, visible)) : groups;
127
+ };
128
+
111
129
  /** The part of a Scratch Blocks toolbox category the child palettes use. */
112
130
  export interface PaletteCategory {
113
131
  id_: string;
@@ -139,6 +157,16 @@ export interface PaletteCategoryGroupsController {
139
157
  isOpen(): boolean;
140
158
  /** The icon the palette shows for the category: its own, or that of the group it is in. */
141
159
  anchorOf(category: PaletteCategory): HTMLElement;
160
+ /**
161
+ * The category to select for an id: a group without blocks of its own stands for its first member, so selecting
162
+ * an extension that declares groups selects its first shown group.
163
+ */
164
+ selectionTarget(id: string): string;
165
+ /**
166
+ * Marks the groups' icons as buttons, focusable in a horizontal palette, and marks the group whose member's blocks
167
+ * are open (`data-palette-group-shown`). Call it whenever the open category changes.
168
+ */
169
+ syncButtons(openId: string | null): void;
142
170
  /** Whether the node is in a child palette. */
143
171
  contains(node: Node | null): boolean;
144
172
  close(): void;
@@ -368,6 +396,25 @@ export const attachPaletteCategoryGroups = (menu: HTMLElement, options: PaletteC
368
396
  toggle,
369
397
  isOpen: () => stack.length > 0,
370
398
  anchorOf: category => categoryById(topLevelOf(category.id_))?.item_ ?? category.item_,
399
+ selectionTarget(id) {
400
+ let target = id;
401
+ while (groups.members.get(target)?.length && !groups.withOwnContents.has(target)) {
402
+ target = groups.members.get(target)![0];
403
+ }
404
+ return target;
405
+ },
406
+ syncButtons(openId) {
407
+ const horizontal = options.horizontal();
408
+ for (const category of options.categories()) {
409
+ if (!groups.members.has(category.id_) || parentOf.has(category.id_)) continue;
410
+ const item = category.item_;
411
+ if (horizontal) item.tabIndex = 0;
412
+ else item.removeAttribute('tabindex');
413
+ item.setAttribute('role', 'button');
414
+ item.toggleAttribute('data-palette-group-shown', horizontal && openId !== null && openId !== category.id_ &&
415
+ topLevelOf(openId) === category.id_);
416
+ }
417
+ },
371
418
  contains,
372
419
  close,
373
420
  dispose() {