@kubohiroya/turbowarp-plus-editor-code-views 0.17.0 → 0.18.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 +3 -1
- package/README.md +3 -1
- package/dist/palette-category-groups.d.ts +3 -2
- package/dist/palette-category-groups.js +46 -16
- package/dist/palette-category-reorder.d.ts +5 -0
- package/dist/palette-category-reorder.js +1 -1
- package/package.json +5 -2
- package/src/palette-category-groups.ts +46 -19
- package/src/palette-category-reorder.ts +6 -1
package/README.ja.md
CHANGED
|
@@ -18,7 +18,7 @@ TurboWarp Plus Editor のコードの画面。1つの作品と1つの取り消
|
|
|
18
18
|
| `./target-combobox` | コードの窓の対象の選択 |
|
|
19
19
|
| `./detached-block-palette` | 別窓のブロックパレット。パレットの `grouping` を渡すと、パレットと同じくグループを子ブロックパレットで開き、固定できる |
|
|
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)` で木を整え、`prepareGroupedToolboxTree(tree, {catalog, visible})` は、機能拡張が宣言したグループの入れ子化と表示するグループの絞り込みを含めて、これを一度に行う。`hasCategoryGroups(tree)` は木が category を入れ子にしているかを返す。`attachPaletteCategoryGroups(menu, options)` で子ブロックパレットを開く。その `selectionTarget(id)` は、自分のブロックを持たないグループの代わりに選ぶ category を返し、`syncButtons(openId)` はグループのアイコンの状態を付け直す。`reorder: 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)` はグループのアイコンの状態を付け直す。`reorder: true` では、グループの要素を長押しして、同じグループの要素の中で並べ替えられる(子ブロックパレットの中でも、固定したグループの要素を広げた場所でも)(別のグループや階層へは動かさない)。順番はパレットを描き直しても保ち(`order` を渡せば、プロジェクトと一緒に保存するパレットの設定に保つ)、`prepare(tree, options)` はツールボックスをその順番で描かせ、`arrange(categories, rank)` がツールボックスの category をそれに合わせて、グループの後にその要素が続くように並べる。子ブロックパレットの右上にはピンがあり、押すとグループの要素を、そのグループを表示していたパレットのそのグループの直後に広げて固定する。固定したグループのアイコンにはピンが付き、押すと元のようにたたむ。固定は同じ `order` に保つので、それを渡したパレット同士は揃う。`splitExtensionCategories(tree, catalog, {nested: true})` は、グループを宣言した機能拡張をこのグループにする |
|
|
22
22
|
| `./palette-category-visibility`・`./palette-visibility-dialog` | スプライト・背景ごとに、パレットに出すブロックグループを選ぶ。設定はエディターの画面状態として保存し、選ぶ画面を持つ。ストアの `order`(`createPaletteOrder`)は、パレットのカテゴリーと各グループの要素を並べ替えた順番を保ち、同じ設定と一緒に保存する |
|
|
23
23
|
| `./block-argument-text` | 長いテキストの引数を短く表示し、ダイアログで編集する。テキストの引数で Shift+Enter を押すと、改行を入れてダイアログで編集を続ける |
|
|
24
24
|
| `./block-number-input` | 数値の引数に入力した全角の数字・記号を半角にする |
|
|
@@ -45,6 +45,8 @@ Editor は GUI の React 16 にこれらを描画するので、React 16.14 以
|
|
|
45
45
|
|
|
46
46
|
`npm test` でビルドし、単体テストを実行し、React 16.14 より新しい API を使っていないことを確かめる。
|
|
47
47
|
|
|
48
|
+
`npm run test:browser` は、最小のエディター実行環境(`@kubohiroya/turbowarp-plus-editor-test-runtime`)で、Editor と同じ VM と Scratch Blocks を使い、パレットのグループを Chromium で操作して確かめる(子ブロックパレット、ピン、並べ替え、別窓のパレット)。`TWPE_CHROME_EXECUTABLE` を指定すると、Playwright のものの代わりにその Chromium を使う。
|
|
49
|
+
|
|
48
50
|
## ライセンス
|
|
49
51
|
|
|
50
52
|
MPL-2.0。turbowarp-plus-editor の `packages/editor-views` と `packages/editor-ui` から移したコードで、同じ作者が書いたもの。移すときに GPL-3.0 から MPL-2.0 にした。由来の監査は [turbowarp-plus-packages の移行計画](https://github.com/kubohiroya/turbowarp-plus-packages/blob/main/docs/editor-migration-plan.ja.md)の「由来の監査(7b)」にある。
|
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. Given the palette's `grouping`, it opens groups in child palettes and pins them as the palette does |
|
|
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. The store's `order` (`createPaletteOrder`) keeps the order the palette's categories and each group's members were dragged into, saved with the same settings |
|
|
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; `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. With `reorder: true`, a long press on a member of a
|
|
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. With `reorder: true`, a long press on a member of a group drags it among the members of the same group, in the group's child palette or where a pinned group shows its members (not to another group or level); the order is kept while the palette is drawn again (in the `order` given, such as the palette settings saved with the project), `prepare(tree, options)` draws the toolbox in it, and `arrange(categories, rank)` orders the toolbox's categories to match, each group followed by its members. A child palette has a pin at its top right: pinning the group shows its members in the palette that showed the group, right after it, and the pinned group's icon shows a pin that folds them back. The pins are kept in the same `order`, so palettes given it follow each other. `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)`) |
|
|
@@ -45,6 +45,8 @@ React 16.14 or later is supported, because the Editor mounts these views in the
|
|
|
45
45
|
|
|
46
46
|
Run `npm test` to build the package, run the unit tests, and check that the sources use no React API newer than 16.14.
|
|
47
47
|
|
|
48
|
+
Run `npm run test:browser` to drive the palette's groups in Chromium with the Editor's own VM and Scratch Blocks, through the minimal editor runtime (`@kubohiroya/turbowarp-plus-editor-test-runtime`): child palettes, pins, reordering and the detached palette. `TWPE_CHROME_EXECUTABLE` names a Chromium to use instead of Playwright's own.
|
|
49
|
+
|
|
48
50
|
## License
|
|
49
51
|
|
|
50
52
|
MPL-2.0. This code moved here from `packages/editor-views` and `packages/editor-ui` in turbowarp-plus-editor. The same author wrote it, and it changed from GPL-3.0 to MPL-2.0 in the move. The provenance audit is in the "由来の監査(7b)" section of the [migration plan in turbowarp-plus-packages](https://github.com/kubohiroya/turbowarp-plus-packages/blob/main/docs/editor-migration-plan.ja.md).
|
|
@@ -56,8 +56,9 @@ export interface PaletteCategoryGroupsOptions {
|
|
|
56
56
|
/** Called when a child palette opens or the last one closes. */
|
|
57
57
|
onChange?(): void;
|
|
58
58
|
/**
|
|
59
|
-
* Lets a long press on a member of a
|
|
60
|
-
*
|
|
59
|
+
* Lets a long press on a member of a group drag it to another place among the members of the same group, as the
|
|
60
|
+
* palette's own categories can be reordered: in the group's child palette, or where a pinned group shows its
|
|
61
|
+
* members. Members do not move to another group or level.
|
|
61
62
|
*/
|
|
62
63
|
reorder?: boolean;
|
|
63
64
|
/** Called after the members of a group were reordered, so the host can lay out its categories with `arrange`. */
|
|
@@ -236,8 +236,9 @@ export const attachPaletteCategoryGroups = (menu, options) => {
|
|
|
236
236
|
const closeFrom = (depth) => {
|
|
237
237
|
let changed = false;
|
|
238
238
|
while (stack.length > depth) {
|
|
239
|
-
const { anchor, popup,
|
|
240
|
-
reorder
|
|
239
|
+
const { anchor, popup, reorders } = stack.pop();
|
|
240
|
+
for (const reorder of reorders)
|
|
241
|
+
reorder.dispose();
|
|
241
242
|
anchor.setAttribute('aria-expanded', 'false');
|
|
242
243
|
popup.remove();
|
|
243
244
|
changed = true;
|
|
@@ -359,36 +360,34 @@ export const attachPaletteCategoryGroups = (menu, options) => {
|
|
|
359
360
|
popup.append(pinButton(false, () => pinFrom(depth)));
|
|
360
361
|
if (groups.withOwnContents.has(group.id_))
|
|
361
362
|
popup.append(createEntry(group, depth, true));
|
|
362
|
-
|
|
363
|
+
// The entries of each group's members shown here: the group's own, and those of pinned member groups.
|
|
364
|
+
const shown = new Map([[group.id_, []]]);
|
|
363
365
|
// A pinned member group is followed by its own members, here rather than in a child palette of its own.
|
|
364
|
-
const add = (member,
|
|
366
|
+
const add = (member, groupId) => {
|
|
365
367
|
const entry = createEntry(member, depth + 1);
|
|
366
|
-
|
|
367
|
-
entries.push(entry);
|
|
368
|
+
shown.get(groupId).push(entry);
|
|
368
369
|
popup.append(entry);
|
|
369
370
|
if (!isPinned(member.id_))
|
|
370
371
|
return;
|
|
372
|
+
shown.set(member.id_, []);
|
|
371
373
|
for (const id of groups.members.get(member.id_) ?? []) {
|
|
372
374
|
const inner = categoryById(id);
|
|
373
375
|
if (inner)
|
|
374
|
-
add(inner,
|
|
376
|
+
add(inner, member.id_);
|
|
375
377
|
}
|
|
376
378
|
};
|
|
377
379
|
for (const member of members)
|
|
378
|
-
add(member,
|
|
380
|
+
add(member, group.id_);
|
|
379
381
|
(menu.parentElement ?? doc.body).append(popup);
|
|
380
382
|
place(popup, anchor);
|
|
381
383
|
anchor.setAttribute('aria-expanded', 'true');
|
|
382
|
-
// The group's own blocks stay first;
|
|
383
|
-
const
|
|
384
|
-
|
|
385
|
-
order.splice(to, 0, order.splice(from, 1)[0]);
|
|
386
|
-
quietly(() => memberOrder().setMembers(group.id_, order));
|
|
387
|
-
groups.members.set(group.id_, order);
|
|
384
|
+
// The group's own blocks stay first; the members of each group shown here can be dragged among themselves.
|
|
385
|
+
const reorders = options.reorder ? [...shown].filter(([, entries]) => entries.length > 1).map(([groupId, entries]) => attachPaletteCategoryReorder(popup, () => entries, (from, to) => {
|
|
386
|
+
moveMember(groupId, from, to);
|
|
388
387
|
open(group, anchor, depth, false);
|
|
389
388
|
options.onReorder?.();
|
|
390
|
-
}, { horizontal: options.horizontal, area: entry => entry }) :
|
|
391
|
-
stack.push({ id: group.id_, anchor, popup,
|
|
389
|
+
}, { horizontal: options.horizontal, area: entry => entry })) : [];
|
|
390
|
+
stack.push({ id: group.id_, anchor, popup, reorders });
|
|
392
391
|
options.onChange?.();
|
|
393
392
|
if (focus)
|
|
394
393
|
popup.firstElementChild?.focus();
|
|
@@ -428,6 +427,34 @@ export const attachPaletteCategoryGroups = (menu, options) => {
|
|
|
428
427
|
else
|
|
429
428
|
applyVisibility();
|
|
430
429
|
}
|
|
430
|
+
/** Moves a member of the group, as dragged, and keeps the order. */
|
|
431
|
+
function moveMember(groupId, from, to) {
|
|
432
|
+
const order = [...(groups.members.get(groupId) ?? [])];
|
|
433
|
+
order.splice(to, 0, order.splice(from, 1)[0]);
|
|
434
|
+
quietly(() => memberOrder().setMembers(groupId, order));
|
|
435
|
+
groups.members.set(groupId, order);
|
|
436
|
+
}
|
|
437
|
+
// Where the palette shows a pinned group's members, they can be dragged among themselves.
|
|
438
|
+
let inlineReorders = [];
|
|
439
|
+
function attachInlineReorders() {
|
|
440
|
+
for (const reorder of inlineReorders)
|
|
441
|
+
reorder.dispose();
|
|
442
|
+
inlineReorders = [];
|
|
443
|
+
if (!options.reorder)
|
|
444
|
+
return;
|
|
445
|
+
for (const [id, members] of groups.members) {
|
|
446
|
+
if (members.length < 2 || !isPinned(id) || !inPalette(id))
|
|
447
|
+
continue;
|
|
448
|
+
const items = () => (groups.members.get(id) ?? []).map(member => categoryById(member)?.item_)
|
|
449
|
+
.filter((item) => Boolean(item));
|
|
450
|
+
inlineReorders.push(attachPaletteCategoryReorder(menu, items, (from, to) => {
|
|
451
|
+
moveMember(id, from, to);
|
|
452
|
+
close();
|
|
453
|
+
applyVisibility();
|
|
454
|
+
options.onReorder?.();
|
|
455
|
+
}, { horizontal: options.horizontal, ends: false }));
|
|
456
|
+
}
|
|
457
|
+
}
|
|
431
458
|
// Shows the categories every group of which is pinned open, hides the others, and marks the groups shown.
|
|
432
459
|
function applyVisibility() {
|
|
433
460
|
for (const category of options.categories()) {
|
|
@@ -457,6 +484,7 @@ export const attachPaletteCategoryGroups = (menu, options) => {
|
|
|
457
484
|
else if (!pinned)
|
|
458
485
|
button?.remove();
|
|
459
486
|
}
|
|
487
|
+
attachInlineReorders();
|
|
460
488
|
markSelection();
|
|
461
489
|
options.onChange?.();
|
|
462
490
|
}
|
|
@@ -634,6 +662,8 @@ export const attachPaletteCategoryGroups = (menu, options) => {
|
|
|
634
662
|
close,
|
|
635
663
|
dispose() {
|
|
636
664
|
close();
|
|
665
|
+
for (const reorder of inlineReorders)
|
|
666
|
+
reorder.dispose();
|
|
637
667
|
unwatch?.();
|
|
638
668
|
events.abort();
|
|
639
669
|
}
|
|
@@ -3,6 +3,11 @@ export interface PaletteCategoryReorderOptions {
|
|
|
3
3
|
horizontal?(): boolean;
|
|
4
4
|
/** The element an item takes up, which a drop over it lands on. By default, the row that holds the item. */
|
|
5
5
|
area?(item: HTMLElement): Element;
|
|
6
|
+
/**
|
|
7
|
+
* Whether a drop before the first item or after the last one lands at that end. On by default; off, a drop
|
|
8
|
+
* anywhere but over an item moves nothing, as when the items share the menu with others.
|
|
9
|
+
*/
|
|
10
|
+
ends?: boolean;
|
|
6
11
|
}
|
|
7
12
|
/**
|
|
8
13
|
* Lets a long press on an item of the menu drag it to another place among the items. Used for the palette's
|
|
@@ -40,7 +40,7 @@ export function attachPaletteCategoryReorder(menu, getItems, onDrop, options = {
|
|
|
40
40
|
if (!items.length || !menu.contains(hit))
|
|
41
41
|
return;
|
|
42
42
|
const item = items.find(candidate => area(candidate).contains(hit));
|
|
43
|
-
if (item)
|
|
43
|
+
if (item || options.ends === false)
|
|
44
44
|
return item;
|
|
45
45
|
const first = items[0];
|
|
46
46
|
const last = items[items.length - 1];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-plus-editor-code-views",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.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",
|
|
@@ -116,7 +116,8 @@
|
|
|
116
116
|
"scripts": {
|
|
117
117
|
"build": "tsc -p tsconfig.json",
|
|
118
118
|
"prepare": "npm run build",
|
|
119
|
-
"test": "npm run build && node --test test/*.test.ts"
|
|
119
|
+
"test": "npm run build && node --test test/*.test.ts",
|
|
120
|
+
"test:browser": "npm run build && node --test test/*.browser.ts"
|
|
120
121
|
},
|
|
121
122
|
"dependencies": {
|
|
122
123
|
"@kubohiroya/turbowarp-script-transfer": "0.1.5"
|
|
@@ -129,7 +130,9 @@
|
|
|
129
130
|
},
|
|
130
131
|
"devDependencies": {
|
|
131
132
|
"@kubohiroya/turbowarp-extension-security-dialog": "0.9.0",
|
|
133
|
+
"@kubohiroya/turbowarp-plus-editor-test-runtime": "0.2.0",
|
|
132
134
|
"@kubohiroya/turbowarp-plus-editor-windows": "0.2.0",
|
|
135
|
+
"@playwright/test": "1.64.1",
|
|
133
136
|
"@types/react": "18.3.31",
|
|
134
137
|
"@types/react-dom": "18.3.7",
|
|
135
138
|
"jsdom": "26.1.0",
|
|
@@ -147,8 +147,9 @@ export interface PaletteCategoryGroupsOptions {
|
|
|
147
147
|
/** Called when a child palette opens or the last one closes. */
|
|
148
148
|
onChange?(): void;
|
|
149
149
|
/**
|
|
150
|
-
* Lets a long press on a member of a
|
|
151
|
-
*
|
|
150
|
+
* Lets a long press on a member of a group drag it to another place among the members of the same group, as the
|
|
151
|
+
* palette's own categories can be reordered: in the group's child palette, or where a pinned group shows its
|
|
152
|
+
* members. Members do not move to another group or level.
|
|
152
153
|
*/
|
|
153
154
|
reorder?: boolean;
|
|
154
155
|
/** Called after the members of a group were reordered, so the host can lay out its categories with `arrange`. */
|
|
@@ -225,7 +226,7 @@ export const attachPaletteCategoryGroups = (menu: HTMLElement, options: PaletteC
|
|
|
225
226
|
let groups: PaletteGroups = {members: new Map(), withOwnContents: new Set()};
|
|
226
227
|
const parentOf = new Map<string, string>();
|
|
227
228
|
// The open child palettes, outermost first, with the icon each opened from.
|
|
228
|
-
const stack: {id: string; anchor: HTMLElement; popup: HTMLElement;
|
|
229
|
+
const stack: {id: string; anchor: HTMLElement; popup: HTMLElement; reorders: {dispose(): void}[]}[] = [];
|
|
229
230
|
// The order members were dragged into, by group, kept while the toolbox is drawn again.
|
|
230
231
|
const ownOrder = createPaletteOrder();
|
|
231
232
|
const memberOrder = () => options.order?.() ?? ownOrder;
|
|
@@ -320,8 +321,8 @@ export const attachPaletteCategoryGroups = (menu: HTMLElement, options: PaletteC
|
|
|
320
321
|
const closeFrom = (depth: number) => {
|
|
321
322
|
let changed = false;
|
|
322
323
|
while (stack.length > depth) {
|
|
323
|
-
const {anchor, popup,
|
|
324
|
-
reorder
|
|
324
|
+
const {anchor, popup, reorders} = stack.pop()!;
|
|
325
|
+
for (const reorder of reorders) reorder.dispose();
|
|
325
326
|
anchor.setAttribute('aria-expanded', 'false');
|
|
326
327
|
popup.remove();
|
|
327
328
|
changed = true;
|
|
@@ -437,33 +438,32 @@ export const attachPaletteCategoryGroups = (menu: HTMLElement, options: PaletteC
|
|
|
437
438
|
// Pinning the group shows its members in the palette that shows the group.
|
|
438
439
|
popup.append(pinButton(false, () => pinFrom(depth)));
|
|
439
440
|
if (groups.withOwnContents.has(group.id_)) popup.append(createEntry(group, depth, true));
|
|
440
|
-
|
|
441
|
+
// The entries of each group's members shown here: the group's own, and those of pinned member groups.
|
|
442
|
+
const shown = new Map<string, HTMLElement[]>([[group.id_, []]]);
|
|
441
443
|
// A pinned member group is followed by its own members, here rather than in a child palette of its own.
|
|
442
|
-
const add = (member: PaletteCategory,
|
|
444
|
+
const add = (member: PaletteCategory, groupId: string) => {
|
|
443
445
|
const entry = createEntry(member, depth + 1);
|
|
444
|
-
|
|
446
|
+
shown.get(groupId)!.push(entry);
|
|
445
447
|
popup.append(entry);
|
|
446
448
|
if (!isPinned(member.id_)) return;
|
|
449
|
+
shown.set(member.id_, []);
|
|
447
450
|
for (const id of groups.members.get(member.id_) ?? []) {
|
|
448
451
|
const inner = categoryById(id);
|
|
449
|
-
if (inner) add(inner,
|
|
452
|
+
if (inner) add(inner, member.id_);
|
|
450
453
|
}
|
|
451
454
|
};
|
|
452
|
-
for (const member of members) add(member,
|
|
455
|
+
for (const member of members) add(member, group.id_);
|
|
453
456
|
(menu.parentElement ?? doc.body).append(popup);
|
|
454
457
|
place(popup, anchor);
|
|
455
458
|
anchor.setAttribute('aria-expanded', 'true');
|
|
456
|
-
// The group's own blocks stay first;
|
|
457
|
-
const
|
|
458
|
-
(from, to) => {
|
|
459
|
-
|
|
460
|
-
order.splice(to, 0, order.splice(from, 1)[0]);
|
|
461
|
-
quietly(() => memberOrder().setMembers(group.id_, order));
|
|
462
|
-
groups.members.set(group.id_, order);
|
|
459
|
+
// The group's own blocks stay first; the members of each group shown here can be dragged among themselves.
|
|
460
|
+
const reorders = options.reorder ? [...shown].filter(([, entries]) => entries.length > 1).map(([groupId, entries]) =>
|
|
461
|
+
attachPaletteCategoryReorder(popup, () => entries, (from, to) => {
|
|
462
|
+
moveMember(groupId, from, to);
|
|
463
463
|
open(group, anchor, depth, false);
|
|
464
464
|
options.onReorder?.();
|
|
465
|
-
}, {horizontal: options.horizontal, area: entry => entry}) :
|
|
466
|
-
stack.push({id: group.id_, anchor, popup,
|
|
465
|
+
}, {horizontal: options.horizontal, area: entry => entry})) : [];
|
|
466
|
+
stack.push({id: group.id_, anchor, popup, reorders});
|
|
467
467
|
options.onChange?.();
|
|
468
468
|
if (focus) (popup.firstElementChild as HTMLElement | null)?.focus();
|
|
469
469
|
};
|
|
@@ -495,6 +495,31 @@ export const attachPaletteCategoryGroups = (menu: HTMLElement, options: PaletteC
|
|
|
495
495
|
if (depth > 0) reopen(depth - 1);
|
|
496
496
|
else applyVisibility();
|
|
497
497
|
}
|
|
498
|
+
/** Moves a member of the group, as dragged, and keeps the order. */
|
|
499
|
+
function moveMember(groupId: string, from: number, to: number) {
|
|
500
|
+
const order = [...(groups.members.get(groupId) ?? [])];
|
|
501
|
+
order.splice(to, 0, order.splice(from, 1)[0]);
|
|
502
|
+
quietly(() => memberOrder().setMembers(groupId, order));
|
|
503
|
+
groups.members.set(groupId, order);
|
|
504
|
+
}
|
|
505
|
+
// Where the palette shows a pinned group's members, they can be dragged among themselves.
|
|
506
|
+
let inlineReorders: {dispose(): void}[] = [];
|
|
507
|
+
function attachInlineReorders() {
|
|
508
|
+
for (const reorder of inlineReorders) reorder.dispose();
|
|
509
|
+
inlineReorders = [];
|
|
510
|
+
if (!options.reorder) return;
|
|
511
|
+
for (const [id, members] of groups.members) {
|
|
512
|
+
if (members.length < 2 || !isPinned(id) || !inPalette(id)) continue;
|
|
513
|
+
const items = () => (groups.members.get(id) ?? []).map(member => categoryById(member)?.item_)
|
|
514
|
+
.filter((item): item is HTMLElement => Boolean(item));
|
|
515
|
+
inlineReorders.push(attachPaletteCategoryReorder(menu, items, (from, to) => {
|
|
516
|
+
moveMember(id, from, to);
|
|
517
|
+
close();
|
|
518
|
+
applyVisibility();
|
|
519
|
+
options.onReorder?.();
|
|
520
|
+
}, {horizontal: options.horizontal, ends: false}));
|
|
521
|
+
}
|
|
522
|
+
}
|
|
498
523
|
// Shows the categories every group of which is pinned open, hides the others, and marks the groups shown.
|
|
499
524
|
function applyVisibility() {
|
|
500
525
|
for (const category of options.categories()) {
|
|
@@ -520,6 +545,7 @@ export const attachPaletteCategoryGroups = (menu: HTMLElement, options: PaletteC
|
|
|
520
545
|
}));
|
|
521
546
|
} else if (!pinned) button?.remove();
|
|
522
547
|
}
|
|
548
|
+
attachInlineReorders();
|
|
523
549
|
markSelection();
|
|
524
550
|
options.onChange?.();
|
|
525
551
|
}
|
|
@@ -676,6 +702,7 @@ export const attachPaletteCategoryGroups = (menu: HTMLElement, options: PaletteC
|
|
|
676
702
|
close,
|
|
677
703
|
dispose() {
|
|
678
704
|
close();
|
|
705
|
+
for (const reorder of inlineReorders) reorder.dispose();
|
|
679
706
|
unwatch?.();
|
|
680
707
|
events.abort();
|
|
681
708
|
}
|
|
@@ -9,6 +9,11 @@ export interface PaletteCategoryReorderOptions {
|
|
|
9
9
|
horizontal?(): boolean;
|
|
10
10
|
/** The element an item takes up, which a drop over it lands on. By default, the row that holds the item. */
|
|
11
11
|
area?(item: HTMLElement): Element;
|
|
12
|
+
/**
|
|
13
|
+
* Whether a drop before the first item or after the last one lands at that end. On by default; off, a drop
|
|
14
|
+
* anywhere but over an item moves nothing, as when the items share the menu with others.
|
|
15
|
+
*/
|
|
16
|
+
ends?: boolean;
|
|
12
17
|
}
|
|
13
18
|
|
|
14
19
|
/**
|
|
@@ -54,7 +59,7 @@ export function attachPaletteCategoryReorder(
|
|
|
54
59
|
const hit = doc.elementFromPoint(event.clientX, event.clientY);
|
|
55
60
|
if (!items.length || !menu.contains(hit)) return;
|
|
56
61
|
const item = items.find(candidate => area(candidate).contains(hit));
|
|
57
|
-
if (item) return item;
|
|
62
|
+
if (item || options.ends === false) return item;
|
|
58
63
|
|
|
59
64
|
const first = items[0];
|
|
60
65
|
const last = items[items.length - 1];
|