dsh-sidebar-fold 0.1.16 → 0.1.18
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/CHANGELOG.md +22 -0
- package/LICENSE +21 -21
- package/README.md +6 -0
- package/README.zh.md +5 -0
- package/cordis.patch.yml +17 -17
- package/dsh.plugin.json +1 -1
- package/lib/client.js +188 -58
- package/package.json +2 -2
- package/screenshots.json +6 -6
- package/src/client/constants.ts +8 -0
- package/src/client/fold.ts +155 -41
- package/src/client/settings-card.ts +17 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.18 (2026-11-27)
|
|
4
|
+
|
|
5
|
+
**修复:0.1.17 真机回归——「更多」飘到列首、拖动方向反 / 拖不动。**
|
|
6
|
+
|
|
7
|
+
- 缺陷 1(更多飘顶):「更多」按钮的父节点是 `span.moreAnchor`,不是 `div._panelEntry`,`foldTarget()` 原样返回 button;rank 写在 button 上无效,而真正的 flex item(span)留在 `order:0`,比其它行的 `1..N` 都小 → 顶到列首。改法:新增 `flexItemOf()` 从 `foldTarget` 结果向上走到 `.panelList` 的直接子节点,rank 落在真 flex item;并把列内非本行的 chrome(moreAnchor 等)补 `rank = 行数 + 1`,不再留默认 `order:0`。
|
|
8
|
+
- 缺陷 2/3(方向反 / 拖不动):`drop` 用 `rowsOf(nav)` 的 DOM 序算新序,但用户按视觉序(`style.order`)拖;两序相反时移动量互相抵消。改法:`drop` 改从 `orderedRows(all, config.orderLabels)`(当前屏幕所见)算 `reorderLabels`。
|
|
9
|
+
- 回归测试:`tests/order-apply.test.ts` 新增 `nested()` 桩(DOM 序与视觉序互逆 + header 在 span 里)与 3 条断言(moreAnchor 拿最大 rank 且 button 不写、互逆序下拖动能换序、清空时含 chrome 全部撤 rank)。共 58/58 通过。
|
|
10
|
+
- 真机复验(farm 0.2.2-rc.3 / 3121):moreAnchor `order=3`、`top=184`(列内最大,稳在列尾);拖「插件→自动化任务」视觉序 `[自动化任务,插件]→[插件,自动化任务]`,拖回可还原;F5 刷新后顺序保持;控制台 0 错误。
|
|
11
|
+
|
|
12
|
+
## 0.1.17 (2026-11-27)
|
|
13
|
+
|
|
14
|
+
**修复:拖动排序只有反馈、顺序不变。**
|
|
15
|
+
|
|
16
|
+
- 根因:0.1.16 的 `applyOrder` 用 `parent.insertBefore(row, next)` 搬 DOM 节点。宿主 0.2.2 起每行按钮各自包在 `div._panelEntry` 里(`SidebarRoot.tsx:78`),`next` 属于另一个父节点 → DOM 抛 `NotFoundError` → 被 `try` 静默吞掉 → 拖动高亮有、松手列顺序没变;顺序落盘了也永远不生效。
|
|
17
|
+
- 改法:改用 CSS `order`,写在每行 **wrapper** 上(`.panelList` 是 `display:flex;flex-direction:column`)。不搬宿主节点、React 重渲染后依然成立、只在值变化时写,`orderLabels` 清空即撤掉,卸载/HMR 一并清理;「更多」header 的 rank 恒为最大值,仍是折叠开关。
|
|
18
|
+
- 拖动绑定从按钮挪到行 wrapper(该行就是 flex item,落在右侧 pin 留白上也能命中),并在`drop` 时清掉 source 再算新序。
|
|
19
|
+
- 设置卡同一处修复:原来 drop 后把新行 append 到卡片末尾(旧行还在 → 列表看着「没变」且重复),现在统一走 `applyConfig({orderLabels})` → `paint()` → `commit({orderLabels})`;卡片行的类从「拖动反馈」换成拖柄类(此前每行常驻 `opacity:.45`,读起来像禁用)。
|
|
20
|
+
- 新增 `tests/order-apply.test.ts`(5 条,锁「只写 rank、不搬节点、幂等、清空可撤」)+ `tests/order.test.ts` 反回归断言(`fold.ts` 运行代码里不得出现 `insertBefore`)。
|
|
21
|
+
|
|
3
22
|
## 0.1.16 (2026-11-27)
|
|
4
23
|
|
|
5
24
|
**侧边栏入口行排序:除「更多」外全部可拖,顺序持久化到 Config。**
|
|
@@ -8,6 +27,9 @@
|
|
|
8
27
|
- 新增纯函数 `reorderLabels` / `orderedRows`;`applyFold` 用幂等 `insertBefore` 重排,抗 MutationObserver 自激;「更多」header 恒固定末尾,折叠开关不变。
|
|
9
28
|
- 设置卡入口行加拖柄,drop 后 `commit({orderLabels})`;`index.ts` 把侧栏拖动经 `subscribeOrder` 桥接回同一 scope 落盘。
|
|
10
29
|
- 10 语字典 + locale 元数据同步新增 `settings.rowDrag` / `rowDragHint`;新增 `scripts/check-surface-classes.mjs` 并接进 prepack。
|
|
30
|
+
- **发版事故记录**:本版本的 CI release 运行以 `npm error 409 Cannot publish over previously staged version "0.1.16"` 失败
|
|
31
|
+
(同一版本一旦进入 npm staged 状态,重推同 tag 必失败),最终由本地 `npm publish` 补发、GitHub Release 事后回填。
|
|
32
|
+
0.1.15 同型。→ 结论:修发版失败必须换版本号,不要重推已有 tag(v0.1.17 即由此而来)。
|
|
11
33
|
|
|
12
34
|
## 0.1.15
|
|
13
35
|
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 drscrewdriver
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 drscrewdriver
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -29,6 +29,11 @@ folds those add-on rows away so only the “More” line remains; the arrow flip
|
|
|
29
29
|
in the “More” menu, from where the host's own pin control brings it back; the plugin
|
|
30
30
|
reconciles both sides on boot, on a config write and on every sidebar repaint — including
|
|
31
31
|
after a reload, where the host's in-memory pin table comes back empty.
|
|
32
|
+
- **Reorderable entries** — drag any add-on row onto another row in the sidebar, or drag the
|
|
33
|
+
handle inside the settings card, to change the column order. The order is stored in `Config`
|
|
34
|
+
(`orderLabels`) and applied as CSS `order` on the host's row wrappers — no host node is moved,
|
|
35
|
+
so a host repaint cannot undo it; the “More” row stays last and the fold toggle keeps working.
|
|
36
|
+
Both surfaces share one order, and clearing the config restores the host's own DOM order.
|
|
32
37
|
- **Configurable** — default state, the three-state row controls and the row alignment live
|
|
33
38
|
in the plugin's settings card (host `Config`, `.volatile()`, applied without a restart).
|
|
34
39
|
- **Rail-safe** — when the sidebar is collapsed to the 36 px icon rail the toggle is
|
|
@@ -77,6 +82,7 @@ path; a host without that service falls back to selecting the Plugins panel.
|
|
|
77
82
|
|---|---|---|
|
|
78
83
|
| Folded by default | State a window starts in when it has no local record | off |
|
|
79
84
|
| Row alignment | Three-way segmented control (left / centre / right) for the managed rows; the “More” row follows the same setting | left |
|
|
85
|
+
| Entry order | Drag a row onto another row (in the sidebar or in this card) to reorder; stored in the config, kept across reloads and repaints, the “More” row stays last | host DOM order |
|
|
80
86
|
| Entries (one per row) | **Show** = always visible; **Fold** = may be folded (default); **Hide in More** = move it into the host's “More” menu | Fold |
|
|
81
87
|
|
|
82
88
|
The row list is read from the DOM at open time, so a panel installed later shows up
|
package/README.zh.md
CHANGED
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
「隐藏到更多」= 把该行交给宿主自己的「更多」菜单(等价于点宿主的“取消固定”),
|
|
22
22
|
行从侧边栏消失、出现在「更多」列表里,可在里面一键固定回来;插件负责在启动、改配置与
|
|
23
23
|
侧边栏重绘时**反向校准**两边状态,宿主内存态的固定表丢了也能恢复。
|
|
24
|
+
- **入口行可排序** —— 在侧边栏把任意加项行拖到另一行上(「更多」不参与),或在设置卡里拖动
|
|
25
|
+
行上的拖柄,即可改变列顺序。顺序存进 `Config`(`orderLabels`),以 CSS `order` 写在宿主的
|
|
26
|
+
行 wrapper 上 —— 不搬宿主节点,宿主重绘也抹不掉;「更多」恒在末尾、折叠钮照常可用。
|
|
27
|
+
两侧共享同一份顺序,清空配置即恢复宿主自身的 DOM 原序。
|
|
24
28
|
- **可配置** —— 默认态、每行三档、行对齐都在插件设置卡里改(宿主 `Config` + `.volatile()`,
|
|
25
29
|
保存即生效,不用重启)。
|
|
26
30
|
- **窄栏友好** —— 侧边栏收成 36px 图标栏时自动摘掉按钮并显示全部行:不挤压、不留半隐藏态。
|
|
@@ -65,6 +69,7 @@ key 为包名);或点侧栏 **「更多」菜单最下面的「侧栏折叠
|
|
|
65
69
|
| 默认折叠 | 窗口在没有本地记录时采用的初始状态 | 关 |
|
|
66
70
|
| 文字与图标对齐 | 三档分段控件(左 / 居中 / 右);作用于被折叠管理的入口行,「更多」行跟随同一档 | 左 |
|
|
67
71
|
| 入口行(逐行) | 每行三选一:**显示**=一直显示(不折叠);**折叠**=允许折叠(默认);**隐藏到更多**=移进宿主「更多」菜单 | 折叠 |
|
|
72
|
+
| 入口行排序 | 按住入口行拖到目标位置(侧边栏与设置卡通用);顺序保存到设置,刷新与重绘后保持,「更多」固定末尾 | 宿主 DOM 原序 |
|
|
68
73
|
|
|
69
74
|
行清单在打开卡片时从 DOM 读取,所以之后新装的入口会自动出现在列表里;如果全部都开了「显示」,
|
|
70
75
|
折叠钮会自动置灰并报 `aria-disabled="true"`,不会出现“箭头动了但什么都没变”。
|
package/cordis.patch.yml
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
# dsh-sidebar-fold bundle patch
|
|
2
|
-
#
|
|
3
|
-
# Assembly layer for the DSH profiles whose bundle list includes this package.
|
|
4
|
-
# A pure ADDITION: one insert row carrying an id no shipped entry uses. No
|
|
5
|
-
# shipped row is disabled, renamed, or reconfigured here, so the patch stays
|
|
6
|
-
# safe to compose with any other plugin's patch.
|
|
7
|
-
#
|
|
8
|
-
# The row exists so the loader has a host-side entry point (src/index.js, which
|
|
9
|
-
# installs nothing) and so the bundle's settings namespace is served under this
|
|
10
|
-
# package's name; every behaviour lives in the browser half (lib/client.js).
|
|
11
|
-
#
|
|
12
|
-
# Install (recommended, official CLI):
|
|
13
|
-
# dsh plugin --profile <profile> add dsh-sidebar-fold
|
|
14
|
-
|
|
15
|
-
- insert:
|
|
16
|
-
- id: dsh-sidebar-fold
|
|
17
|
-
name: dsh-sidebar-fold
|
|
1
|
+
# dsh-sidebar-fold bundle patch
|
|
2
|
+
#
|
|
3
|
+
# Assembly layer for the DSH profiles whose bundle list includes this package.
|
|
4
|
+
# A pure ADDITION: one insert row carrying an id no shipped entry uses. No
|
|
5
|
+
# shipped row is disabled, renamed, or reconfigured here, so the patch stays
|
|
6
|
+
# safe to compose with any other plugin's patch.
|
|
7
|
+
#
|
|
8
|
+
# The row exists so the loader has a host-side entry point (src/index.js, which
|
|
9
|
+
# installs nothing) and so the bundle's settings namespace is served under this
|
|
10
|
+
# package's name; every behaviour lives in the browser half (lib/client.js).
|
|
11
|
+
#
|
|
12
|
+
# Install (recommended, official CLI):
|
|
13
|
+
# dsh plugin --profile <profile> add dsh-sidebar-fold
|
|
14
|
+
|
|
15
|
+
- insert:
|
|
16
|
+
- id: dsh-sidebar-fold
|
|
17
|
+
name: dsh-sidebar-fold
|
package/dsh.plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "dsh-external/dsh-sidebar-fold",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"main": "./src/index.js",
|
|
5
5
|
"description": "折叠左侧栏加项入口:在宿主「更多」行挂一个 28×28 方形箭头按钮,把自动化任务、agent 团队、插件市场、上下文页等加项面板行收纳成一行;设置卡每行三档:显示(一直显示)/ 折叠(允许折叠)/ 隐藏到更多(移进宿主「更多」菜单,宿主 0.2.2 起)。还可调默认态与行内文字图标对齐(左/居中/右)。",
|
|
6
6
|
"engines": {
|
package/lib/client.js
CHANGED
|
@@ -42,6 +42,8 @@ window.__ModuleLoader__.load({
|
|
|
42
42
|
/** Transient highlight on the row being dragged / targeted. */
|
|
43
43
|
rowDrag: 'dshsf-row-drag',
|
|
44
44
|
rowDragOver: 'dshsf-row-drag-over',
|
|
45
|
+
/** The settings-card handle a reorder drag is started from. */
|
|
46
|
+
rowHandle: 'dshsf-row-handle',
|
|
45
47
|
});
|
|
46
48
|
/**
|
|
47
49
|
* Alignment of a panel row's content (icon + label) inside the row.
|
|
@@ -69,6 +71,8 @@ window.__ModuleLoader__.load({
|
|
|
69
71
|
activeInside: 'data-dshsf-active-inside',
|
|
70
72
|
/** On a panel row we have wired for HTML5 drag-and-drop reordering. */
|
|
71
73
|
dnd: 'data-dshsf-dnd',
|
|
74
|
+
/** On a row wrapper carrying the flex `order` we wrote for a persisted rank. */
|
|
75
|
+
order: 'data-dshsf-order',
|
|
72
76
|
});
|
|
73
77
|
/** Selector fragments (hash-tolerant). */
|
|
74
78
|
const SEL = Object.freeze({
|
|
@@ -312,6 +316,10 @@ window.__ModuleLoader__.load({
|
|
|
312
316
|
// Row drag feedback — opacity on the source, a token-tinted outline on the target.
|
|
313
317
|
rule(`.${CLS.rowDrag}`, ['opacity:.45']),
|
|
314
318
|
rule(`.${CLS.rowDragOver}`, ['outline:2px solid var(--dsw-alias-state-business-primary,#4d6bfe)', 'outline-offset:-2px']),
|
|
319
|
+
// The settings card's drag handle: a grab cursor is the only honest affordance
|
|
320
|
+
// (dimming the whole row, as the first cut did, reads as “disabled”).
|
|
321
|
+
rule(`.${CLS.rowHandle}`, ['cursor:grab', '-webkit-user-select:none', 'user-select:none']),
|
|
322
|
+
rule(`.${CLS.rowHandle}:active`, ['cursor:grabbing']),
|
|
315
323
|
rule(`.${CLS.menuIcon}`, ['flex:none', 'display:block']),
|
|
316
324
|
].join('');
|
|
317
325
|
/**
|
|
@@ -924,7 +932,9 @@ window.__ModuleLoader__.load({
|
|
|
924
932
|
*/
|
|
925
933
|
function roster() {
|
|
926
934
|
const nav = findPanelNav(document);
|
|
927
|
-
const rows = nav === null
|
|
935
|
+
const rows = nav === null
|
|
936
|
+
? []
|
|
937
|
+
: rosterFrom(orderedRows(rowsOf(nav), config.orderLabels), config.keepLabels, config.hideLabels);
|
|
928
938
|
const seen = new Set(rows.map((row) => row.label.toLowerCase()));
|
|
929
939
|
for (const entry of moreMenuRows()) {
|
|
930
940
|
if (seen.has(entry.label.toLowerCase()))
|
|
@@ -1281,23 +1291,28 @@ window.__ModuleLoader__.load({
|
|
|
1281
1291
|
listener([...order]);
|
|
1282
1292
|
}
|
|
1283
1293
|
/**
|
|
1284
|
-
* Wire one panel row for HTML5 drag-and-drop.
|
|
1285
|
-
*
|
|
1286
|
-
*
|
|
1287
|
-
*
|
|
1294
|
+
* Wire one panel row's **wrapper** for HTML5 drag-and-drop.
|
|
1295
|
+
*
|
|
1296
|
+
* Idempotent: an `ATTR.dnd` mark prevents duplicate listeners across the many
|
|
1297
|
+
* rescan passes. The wrapper (not the button) is the drag surface because it is
|
|
1298
|
+
* the visible row *and* the flex item `applyOrder` ranks — otherwise dropping on
|
|
1299
|
+
* the row's pin gutter would miss the target. The "More" header is never wired:
|
|
1300
|
+
* it stays the fold toggle and stays last.
|
|
1288
1301
|
*/
|
|
1289
1302
|
function bindRowDrag(row, isHeader) {
|
|
1290
|
-
if (isHeader
|
|
1303
|
+
if (isHeader)
|
|
1291
1304
|
return;
|
|
1292
|
-
const el = row;
|
|
1293
|
-
el.setAttribute(ATTR.dnd, '');
|
|
1294
|
-
el.setAttribute('draggable', 'true');
|
|
1295
1305
|
const label = labelOf(row);
|
|
1296
1306
|
if (label === '')
|
|
1297
1307
|
return;
|
|
1308
|
+
const el = foldTarget(row);
|
|
1309
|
+
if (el.getAttribute(ATTR.dnd) !== null)
|
|
1310
|
+
return;
|
|
1311
|
+
el.setAttribute(ATTR.dnd, '');
|
|
1312
|
+
el.setAttribute('draggable', 'true');
|
|
1298
1313
|
el.addEventListener('dragstart', (e) => {
|
|
1299
1314
|
dragSourceLabel = label;
|
|
1300
|
-
el.classList
|
|
1315
|
+
el.classList.add(CLS.rowDrag);
|
|
1301
1316
|
if (e?.dataTransfer)
|
|
1302
1317
|
e.dataTransfer.effectAllowed = 'move';
|
|
1303
1318
|
});
|
|
@@ -1307,31 +1322,38 @@ window.__ModuleLoader__.load({
|
|
|
1307
1322
|
e?.preventDefault?.();
|
|
1308
1323
|
if (e?.dataTransfer)
|
|
1309
1324
|
e.dataTransfer.dropEffect = 'move';
|
|
1310
|
-
el.classList
|
|
1325
|
+
el.classList.add(CLS.rowDragOver);
|
|
1311
1326
|
});
|
|
1312
1327
|
el.addEventListener('dragleave', () => {
|
|
1313
|
-
el.classList
|
|
1328
|
+
el.classList.remove(CLS.rowDragOver);
|
|
1314
1329
|
});
|
|
1315
1330
|
el.addEventListener('drop', (e) => {
|
|
1316
1331
|
e?.preventDefault?.();
|
|
1317
|
-
el.classList
|
|
1318
|
-
|
|
1332
|
+
el.classList.remove(CLS.rowDragOver);
|
|
1333
|
+
const source = dragSourceLabel;
|
|
1334
|
+
dragSourceLabel = null;
|
|
1335
|
+
if (source === null || source === label)
|
|
1319
1336
|
return;
|
|
1320
1337
|
const all = rowsOf(mount?.nav ?? el.closest?.(SEL.panelList));
|
|
1321
1338
|
if (all.length === 0)
|
|
1322
1339
|
return;
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1340
|
+
// Order the reorderable rows only: the "More" header is not a rank, it is
|
|
1341
|
+
// pinned last by orderedRows, and persisting its label would just be noise.
|
|
1342
|
+
const header = all.find((row) => row.getAttribute('aria-haspopup') === 'menu') ?? all[all.length - 1];
|
|
1343
|
+
// The list the user is dragging in is the one they can SEE, and since 0.1.17
|
|
1344
|
+
// that order lives in `style.order`, not in the DOM. Computing the move from
|
|
1345
|
+
// DOM order made a downward drag a no-op once any rank existed (DOM order and
|
|
1346
|
+
// visual order differ), which read as "the drag does nothing" or "it goes the
|
|
1347
|
+
// wrong way". Always start from the order currently on screen.
|
|
1348
|
+
const visible = orderedRows(all, config.orderLabels);
|
|
1349
|
+
const next = reorderLabels(visible.filter((row) => row !== header).map(labelOf), source, label);
|
|
1328
1350
|
applyOrder(all, next);
|
|
1329
1351
|
notifyOrderChange(next);
|
|
1330
1352
|
});
|
|
1331
1353
|
el.addEventListener('dragend', () => {
|
|
1332
1354
|
dragSourceLabel = null;
|
|
1333
|
-
el.classList
|
|
1334
|
-
el.classList
|
|
1355
|
+
el.classList.remove(CLS.rowDrag);
|
|
1356
|
+
el.classList.remove(CLS.rowDragOver);
|
|
1335
1357
|
});
|
|
1336
1358
|
}
|
|
1337
1359
|
/** Wire every live row for reordering (called on each apply pass, idempotent). */
|
|
@@ -1343,33 +1365,134 @@ window.__ModuleLoader__.load({
|
|
|
1343
1365
|
bindRowDrag(row, row === header);
|
|
1344
1366
|
}
|
|
1345
1367
|
/**
|
|
1346
|
-
* Reorder the nav's rows
|
|
1368
|
+
* Reorder the nav's rows to match the persisted label order.
|
|
1369
|
+
*
|
|
1370
|
+
* Written as the flex `order` property on each row's **wrapper**, never by moving
|
|
1371
|
+
* nodes. Two measured facts force that choice:
|
|
1347
1372
|
*
|
|
1348
|
-
*
|
|
1349
|
-
*
|
|
1350
|
-
*
|
|
1373
|
+
* - from the 0.2.2 line on every row button sits in its own `div._panelEntry`
|
|
1374
|
+
* (`SidebarRoot.tsx:78`), so the buttons are *not* siblings. The first cut
|
|
1375
|
+
* moved them with `parent.insertBefore(row, next)`, where `next` belonged to
|
|
1376
|
+
* another parent — the DOM throws `NotFoundError`, our `try` swallowed it, and
|
|
1377
|
+
* a drop therefore highlighted the target and changed nothing (the bug this
|
|
1378
|
+
* replaces);
|
|
1379
|
+
* - the nodes are React's, so re-parenting them is a fight we lose on the next
|
|
1380
|
+
* render. `order` is ours alone to write, it survives re-renders (the host sets
|
|
1381
|
+
* no `style` on these wrappers), and removing the declarations undoes it.
|
|
1382
|
+
*
|
|
1383
|
+
* `.panelList` is `display:flex; flex-direction:column` (`SidebarRoot.module.css`),
|
|
1384
|
+
* so `order` reorders the column without touching document order — which is also
|
|
1385
|
+
* why the observer (attributes filtered to `class`) cannot see these writes.
|
|
1386
|
+
*
|
|
1387
|
+
* The "More" header is ordered last by {@link orderedRows}, so it stays the fold
|
|
1388
|
+
* toggle no matter what the user drags.
|
|
1389
|
+
* @param rows - the nav's panel rows, in document order.
|
|
1390
|
+
* @param orderLabels - persisted label order; an empty list clears every rank.
|
|
1391
|
+
*/
|
|
1392
|
+
/** The parent whose flex children the ranks reorder, or null for a detached stub. */
|
|
1393
|
+
function childContainer(node) {
|
|
1394
|
+
return (node.parentElement ?? null);
|
|
1395
|
+
}
|
|
1396
|
+
/** The flex children of a container (empty for a stub that has none). */
|
|
1397
|
+
function childrenOf(container) {
|
|
1398
|
+
const kids = container.children;
|
|
1399
|
+
return kids === undefined ? [] : Array.from(kids);
|
|
1400
|
+
}
|
|
1401
|
+
/**
|
|
1402
|
+
* The flex item a rank must be written on.
|
|
1403
|
+
*
|
|
1404
|
+
* `foldTarget` answers "which node does the host treat as the row", and on the
|
|
1405
|
+
* 0.2.2 line that is the `div._panelEntry` — a flex child of `.panelList`. The
|
|
1406
|
+
* "More" row is the exception: its button sits directly inside a
|
|
1407
|
+
* `span.moreAnchor`, so the closest entry above it is none and the button is
|
|
1408
|
+
* returned. A rank written there is inert (the button is not a flex item) while
|
|
1409
|
+
* the anchor keeps `order: 0` and floats to the top. Walk up to the child of the
|
|
1410
|
+
* container so every rank lands on something the column actually lays out.
|
|
1411
|
+
* @param target - the node {@link foldTarget} returned.
|
|
1412
|
+
* @param container - the flex container the ranks apply to, or null.
|
|
1413
|
+
* @returns the direct child of `container` that owns `target`, else `target`.
|
|
1351
1414
|
*/
|
|
1415
|
+
function flexItemOf(target, container) {
|
|
1416
|
+
if (container === null)
|
|
1417
|
+
return target;
|
|
1418
|
+
let node = target;
|
|
1419
|
+
let guard = 0;
|
|
1420
|
+
while (node.parentElement != null && node.parentElement !== container && guard < 8) {
|
|
1421
|
+
node = node.parentElement;
|
|
1422
|
+
guard += 1;
|
|
1423
|
+
}
|
|
1424
|
+
return node.parentElement === container ? node : target;
|
|
1425
|
+
}
|
|
1352
1426
|
function applyOrder(rows, orderLabels) {
|
|
1353
|
-
if (
|
|
1354
|
-
return;
|
|
1355
|
-
const target = orderedRows(rows, orderLabels);
|
|
1356
|
-
if (target.length !== rows.length)
|
|
1427
|
+
if (rows.length < 2)
|
|
1357
1428
|
return;
|
|
1358
|
-
const
|
|
1359
|
-
|
|
1429
|
+
const entries = [];
|
|
1430
|
+
for (const row of rows) {
|
|
1431
|
+
const entry = foldTarget(row);
|
|
1432
|
+
if (!entries.includes(entry))
|
|
1433
|
+
entries.push(entry);
|
|
1434
|
+
}
|
|
1435
|
+
if (entries.length === 0)
|
|
1360
1436
|
return;
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
const
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1437
|
+
const container = childContainer(entries[0]);
|
|
1438
|
+
const wanted = new Map();
|
|
1439
|
+
if (orderLabels.length > 0) {
|
|
1440
|
+
const ordered = orderedRows(rows, orderLabels);
|
|
1441
|
+
ordered.forEach((row, index) => {
|
|
1442
|
+
const entry = flexItemOf(foldTarget(row), container);
|
|
1443
|
+
if (!wanted.has(entry))
|
|
1444
|
+
wanted.set(entry, index + 1);
|
|
1445
|
+
});
|
|
1446
|
+
// Host chrome that is not one of our rows — above all the "More" anchor, a
|
|
1447
|
+
// `span.moreAnchor` that wraps the header button instead of being a
|
|
1448
|
+
// `div._panelEntry` — must not be left at the flex default `order: 0`, or it
|
|
1449
|
+
// jumps above every ranked row (measured: "More" flew to the top of the
|
|
1450
|
+
// column). Rank it past the last row so it stays where the host put it.
|
|
1451
|
+
if (container !== null) {
|
|
1452
|
+
const tail = ordered.length + 1;
|
|
1453
|
+
for (const child of childrenOf(container)) {
|
|
1454
|
+
if (!wanted.has(child))
|
|
1455
|
+
wanted.set(child, tail);
|
|
1369
1456
|
}
|
|
1370
|
-
catch { /* host may re-render */ }
|
|
1371
1457
|
}
|
|
1372
1458
|
}
|
|
1459
|
+
const touched = [...entries];
|
|
1460
|
+
if (container !== null)
|
|
1461
|
+
for (const child of childrenOf(container))
|
|
1462
|
+
touched.push(child);
|
|
1463
|
+
const seen = new Set();
|
|
1464
|
+
for (const entry of touched) {
|
|
1465
|
+
if (seen.has(entry))
|
|
1466
|
+
continue;
|
|
1467
|
+
seen.add(entry);
|
|
1468
|
+
const value = wanted.get(entry);
|
|
1469
|
+
if (value === undefined) {
|
|
1470
|
+
if (entry.getAttribute(ATTR.order) === null)
|
|
1471
|
+
continue;
|
|
1472
|
+
entry.removeAttribute(ATTR.order);
|
|
1473
|
+
const el = entry;
|
|
1474
|
+
if (el.style != null)
|
|
1475
|
+
el.style.order = '';
|
|
1476
|
+
continue;
|
|
1477
|
+
}
|
|
1478
|
+
const text = String(value);
|
|
1479
|
+
// Write only on change: a no-op write is a mutation nobody asked for.
|
|
1480
|
+
if (entry.getAttribute(ATTR.order) === text)
|
|
1481
|
+
continue;
|
|
1482
|
+
entry.setAttribute(ATTR.order, text);
|
|
1483
|
+
const el = entry;
|
|
1484
|
+
if (el.style != null)
|
|
1485
|
+
el.style.order = text;
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
/** Undo every inline rank this plugin wrote (dispose / HMR sweep). */
|
|
1489
|
+
function clearOrder() {
|
|
1490
|
+
for (const node of Array.from(document.querySelectorAll(`[${ATTR.order}]`))) {
|
|
1491
|
+
node.removeAttribute(ATTR.order);
|
|
1492
|
+
const el = node;
|
|
1493
|
+
if (el.style != null)
|
|
1494
|
+
el.style.order = '';
|
|
1495
|
+
}
|
|
1373
1496
|
}
|
|
1374
1497
|
/**
|
|
1375
1498
|
* Write the fold marks. Only attributes we own are touched: no host class,
|
|
@@ -1385,8 +1508,8 @@ window.__ModuleLoader__.load({
|
|
|
1385
1508
|
return;
|
|
1386
1509
|
const { header } = plan;
|
|
1387
1510
|
// Reorder the live rows to the persisted order before any fold marks are
|
|
1388
|
-
// written.
|
|
1389
|
-
// the
|
|
1511
|
+
// written. Ranks are inline `order` values written only when they change, and
|
|
1512
|
+
// the observer watches `class` alone, so a scan cannot trigger itself.
|
|
1390
1513
|
applyOrder(rows, config.orderLabels);
|
|
1391
1514
|
bindRowDrags(rows);
|
|
1392
1515
|
if (header.getAttribute(ATTR.header) === null)
|
|
@@ -1397,8 +1520,9 @@ window.__ModuleLoader__.load({
|
|
|
1397
1520
|
const align = normalizeAlign(config.align);
|
|
1398
1521
|
if (mount.nav.getAttribute(ATTR.align) !== align)
|
|
1399
1522
|
mount.nav.setAttribute(ATTR.align, align);
|
|
1400
|
-
// The settings card renders whatever is on screen right now; keep it in sync
|
|
1401
|
-
|
|
1523
|
+
// The settings card renders whatever is on screen right now; keep it in sync —
|
|
1524
|
+
// and in the order the column shows, so a drag reads the same on both surfaces.
|
|
1525
|
+
notifyRoster(rosterFrom(orderedRows(rows, config.orderLabels), config.keepLabels, config.hideLabels));
|
|
1402
1526
|
mount.toggle.classList.toggle(CLS.toggleIdle, plan.idle);
|
|
1403
1527
|
mount.toggle.setAttribute('aria-disabled', plan.idle ? 'true' : 'false');
|
|
1404
1528
|
for (const row of rows) {
|
|
@@ -1517,6 +1641,7 @@ window.__ModuleLoader__.load({
|
|
|
1517
1641
|
row.removeAttribute('draggable');
|
|
1518
1642
|
row.classList?.remove(CLS.rowDrag, CLS.rowDragOver);
|
|
1519
1643
|
}
|
|
1644
|
+
clearOrder();
|
|
1520
1645
|
mount = null;
|
|
1521
1646
|
}
|
|
1522
1647
|
/**
|
|
@@ -1581,6 +1706,7 @@ window.__ModuleLoader__.load({
|
|
|
1581
1706
|
row.removeAttribute('draggable');
|
|
1582
1707
|
row.classList?.remove(CLS.rowDrag, CLS.rowDragOver);
|
|
1583
1708
|
}
|
|
1709
|
+
clearOrder();
|
|
1584
1710
|
mount = null;
|
|
1585
1711
|
// The pin bookkeeping belongs to one window's DOM; a remount starts from what
|
|
1586
1712
|
// the host shows now, never from a count that may no longer refer to it.
|
|
@@ -1941,14 +2067,23 @@ window.__ModuleLoader__.load({
|
|
|
1941
2067
|
* Attach a drag handle to a settings row so the visible list can be reordered.
|
|
1942
2068
|
*
|
|
1943
2069
|
* The row itself is the drag source and drop target; both surfaces (sidebar and
|
|
1944
|
-
* card) compute the next order via reorderLabels and commit through
|
|
2070
|
+
* card) compute the next order via reorderLabels and commit through commit().
|
|
2071
|
+
*
|
|
2072
|
+
* The drop commits in one direction only — the sidebar is the ordering
|
|
2073
|
+
* authority: `applyConfig` ranks the live rows, `paint()` re-reads the roster
|
|
2074
|
+
* (which now reports the new order), and only then does the write go out. The
|
|
2075
|
+
* first cut rebuilt the list by appending fresh rows to the card root, which
|
|
2076
|
+
* left the originals in place (a duplicated list that read as "nothing changed").
|
|
1945
2077
|
*/
|
|
1946
2078
|
function makeDraggableRow(row, label, rows) {
|
|
1947
2079
|
row.setAttribute('draggable', 'true');
|
|
1948
|
-
row
|
|
2080
|
+
// A grab cursor, not the drag *feedback* class: dimming the row permanently
|
|
2081
|
+
// made every settings row look disabled.
|
|
2082
|
+
row.classList.add(CLS.rowHandle);
|
|
1949
2083
|
let source = '';
|
|
1950
2084
|
row.addEventListener('dragstart', (e) => {
|
|
1951
2085
|
source = label;
|
|
2086
|
+
row.classList.add(CLS.rowDrag);
|
|
1952
2087
|
if (e?.dataTransfer)
|
|
1953
2088
|
e.dataTransfer.effectAllowed = 'move';
|
|
1954
2089
|
});
|
|
@@ -1964,23 +2099,18 @@ window.__ModuleLoader__.load({
|
|
|
1964
2099
|
row.addEventListener('drop', (e) => {
|
|
1965
2100
|
e?.preventDefault?.();
|
|
1966
2101
|
row.classList.remove(CLS.rowDragOver);
|
|
1967
|
-
|
|
1968
|
-
return;
|
|
1969
|
-
const labels = rows.map((entry) => entry.label);
|
|
1970
|
-
const next = reorderLabels(labels, source, label);
|
|
2102
|
+
const from = source;
|
|
1971
2103
|
source = '';
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
const
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
// Build a fresh row for each entry in the new order.
|
|
1978
|
-
cardRoot?.appendChild(buildEntry(entry, reordered));
|
|
1979
|
-
}
|
|
2104
|
+
if (from === '' || from === label)
|
|
2105
|
+
return;
|
|
2106
|
+
const next = reorderLabels(rows.map((entry) => entry.label), from, label);
|
|
2107
|
+
applyConfig({ ...effectiveConfig(), orderLabels: next });
|
|
2108
|
+
paint();
|
|
1980
2109
|
commit({ orderLabels: next });
|
|
1981
2110
|
});
|
|
1982
2111
|
row.addEventListener('dragend', () => {
|
|
1983
2112
|
source = '';
|
|
2113
|
+
row.classList.remove(CLS.rowDrag);
|
|
1984
2114
|
row.classList.remove(CLS.rowDragOver);
|
|
1985
2115
|
});
|
|
1986
2116
|
return row;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-sidebar-fold",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"description": "Folds the sidebar's add-on panel rows under the shipped \"More\" row, and from host 0.2.2 on gives every row three states — show, fold, or hide in the host's own \"More\" list. The fold state persists per window, rows are read from the live sidebar, and the managed rows' icon + label can be aligned left, centre or right.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"scripts": {
|
|
38
38
|
"lint": "node scripts/lint.mjs",
|
|
39
39
|
"typecheck": "tsc -p tsconfig.json",
|
|
40
|
-
"test": "node --experimental-strip-types --no-warnings --test tests/fold.test.ts tests/fold-plan.test.ts tests/order.test.ts",
|
|
40
|
+
"test": "node --experimental-strip-types --no-warnings --test tests/fold.test.ts tests/fold-plan.test.ts tests/order.test.ts tests/order-apply.test.ts",
|
|
41
41
|
"test:coverage": "node --experimental-strip-types --no-warnings --experimental-test-coverage --test tests/fold.test.ts tests/fold-plan.test.ts",
|
|
42
42
|
"build": "node scripts/build-client.mjs",
|
|
43
43
|
"verify": "node scripts/verify.mjs",
|
package/screenshots.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
{
|
|
2
|
-
"screenshots": [
|
|
3
|
-
"assets/middle.png",
|
|
4
|
-
"assets/fold.png"
|
|
5
|
-
]
|
|
6
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"screenshots": [
|
|
3
|
+
"assets/middle.png",
|
|
4
|
+
"assets/fold.png"
|
|
5
|
+
]
|
|
6
|
+
}
|
package/src/client/constants.ts
CHANGED
|
@@ -38,6 +38,8 @@ export const CLS = Object.freeze({
|
|
|
38
38
|
/** Transient highlight on the row being dragged / targeted. */
|
|
39
39
|
rowDrag: 'dshsf-row-drag',
|
|
40
40
|
rowDragOver: 'dshsf-row-drag-over',
|
|
41
|
+
/** The settings-card handle a reorder drag is started from. */
|
|
42
|
+
rowHandle: 'dshsf-row-handle',
|
|
41
43
|
})
|
|
42
44
|
|
|
43
45
|
/**
|
|
@@ -70,6 +72,8 @@ export const ATTR = Object.freeze({
|
|
|
70
72
|
activeInside: 'data-dshsf-active-inside',
|
|
71
73
|
/** On a panel row we have wired for HTML5 drag-and-drop reordering. */
|
|
72
74
|
dnd: 'data-dshsf-dnd',
|
|
75
|
+
/** On a row wrapper carrying the flex `order` we wrote for a persisted rank. */
|
|
76
|
+
order: 'data-dshsf-order',
|
|
73
77
|
})
|
|
74
78
|
|
|
75
79
|
/** Selector fragments (hash-tolerant). */
|
|
@@ -323,5 +327,9 @@ export const SHEET = [
|
|
|
323
327
|
// Row drag feedback — opacity on the source, a token-tinted outline on the target.
|
|
324
328
|
rule(`.${CLS.rowDrag}`, ['opacity:.45']),
|
|
325
329
|
rule(`.${CLS.rowDragOver}`, ['outline:2px solid var(--dsw-alias-state-business-primary,#4d6bfe)', 'outline-offset:-2px']),
|
|
330
|
+
// The settings card's drag handle: a grab cursor is the only honest affordance
|
|
331
|
+
// (dimming the whole row, as the first cut did, reads as “disabled”).
|
|
332
|
+
rule(`.${CLS.rowHandle}`, ['cursor:grab', '-webkit-user-select:none', 'user-select:none']),
|
|
333
|
+
rule(`.${CLS.rowHandle}:active`, ['cursor:grabbing']),
|
|
326
334
|
rule(`.${CLS.menuIcon}`, ['flex:none', 'display:block']),
|
|
327
335
|
].join('')
|
package/src/client/fold.ts
CHANGED
|
@@ -389,7 +389,9 @@ let rosterKey = ''
|
|
|
389
389
|
*/
|
|
390
390
|
export function roster(): RowInfo[] {
|
|
391
391
|
const nav = findPanelNav(document as unknown as QueryRoot)
|
|
392
|
-
const rows = nav === null
|
|
392
|
+
const rows = nav === null
|
|
393
|
+
? []
|
|
394
|
+
: rosterFrom(orderedRows(rowsOf(nav), config.orderLabels), config.keepLabels, config.hideLabels)
|
|
393
395
|
const seen = new Set(rows.map((row) => row.label.toLowerCase()))
|
|
394
396
|
for (const entry of moreMenuRows()) {
|
|
395
397
|
if (seen.has(entry.label.toLowerCase())) continue
|
|
@@ -759,49 +761,61 @@ function notifyOrderChange(order: string[]): void {
|
|
|
759
761
|
}
|
|
760
762
|
|
|
761
763
|
/**
|
|
762
|
-
* Wire one panel row for HTML5 drag-and-drop.
|
|
763
|
-
*
|
|
764
|
-
*
|
|
765
|
-
*
|
|
764
|
+
* Wire one panel row's **wrapper** for HTML5 drag-and-drop.
|
|
765
|
+
*
|
|
766
|
+
* Idempotent: an `ATTR.dnd` mark prevents duplicate listeners across the many
|
|
767
|
+
* rescan passes. The wrapper (not the button) is the drag surface because it is
|
|
768
|
+
* the visible row *and* the flex item `applyOrder` ranks — otherwise dropping on
|
|
769
|
+
* the row's pin gutter would miss the target. The "More" header is never wired:
|
|
770
|
+
* it stays the fold toggle and stays last.
|
|
766
771
|
*/
|
|
767
772
|
function bindRowDrag(row: ElementLike, isHeader: boolean): void {
|
|
768
|
-
if (isHeader
|
|
769
|
-
const el = row as unknown as HTMLElement
|
|
770
|
-
el.setAttribute(ATTR.dnd, '')
|
|
771
|
-
el.setAttribute('draggable', 'true')
|
|
773
|
+
if (isHeader) return
|
|
772
774
|
const label = labelOf(row)
|
|
773
775
|
if (label === '') return
|
|
776
|
+
const el = foldTarget(row) as unknown as HTMLElement
|
|
777
|
+
if (el.getAttribute(ATTR.dnd) !== null) return
|
|
778
|
+
el.setAttribute(ATTR.dnd, '')
|
|
779
|
+
el.setAttribute('draggable', 'true')
|
|
774
780
|
el.addEventListener('dragstart', (e: any) => {
|
|
775
781
|
dragSourceLabel = label
|
|
776
|
-
el.classList
|
|
782
|
+
el.classList.add(CLS.rowDrag)
|
|
777
783
|
if (e?.dataTransfer) e.dataTransfer.effectAllowed = 'move'
|
|
778
784
|
})
|
|
779
785
|
el.addEventListener('dragover', (e: any) => {
|
|
780
786
|
if (dragSourceLabel === null || dragSourceLabel === label) return
|
|
781
787
|
e?.preventDefault?.()
|
|
782
788
|
if (e?.dataTransfer) e.dataTransfer.dropEffect = 'move'
|
|
783
|
-
el.classList
|
|
789
|
+
el.classList.add(CLS.rowDragOver)
|
|
784
790
|
})
|
|
785
791
|
el.addEventListener('dragleave', () => {
|
|
786
|
-
el.classList
|
|
792
|
+
el.classList.remove(CLS.rowDragOver)
|
|
787
793
|
})
|
|
788
794
|
el.addEventListener('drop', (e: any) => {
|
|
789
795
|
e?.preventDefault?.()
|
|
790
|
-
el.classList
|
|
791
|
-
|
|
796
|
+
el.classList.remove(CLS.rowDragOver)
|
|
797
|
+
const source = dragSourceLabel
|
|
798
|
+
dragSourceLabel = null
|
|
799
|
+
if (source === null || source === label) return
|
|
792
800
|
const all = rowsOf(mount?.nav ?? (el.closest?.(SEL.panelList) as ElementLike))
|
|
793
801
|
if (all.length === 0) return
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
802
|
+
// Order the reorderable rows only: the "More" header is not a rank, it is
|
|
803
|
+
// pinned last by orderedRows, and persisting its label would just be noise.
|
|
804
|
+
const header = all.find((row) => row.getAttribute('aria-haspopup') === 'menu') ?? all[all.length - 1]
|
|
805
|
+
// The list the user is dragging in is the one they can SEE, and since 0.1.17
|
|
806
|
+
// that order lives in `style.order`, not in the DOM. Computing the move from
|
|
807
|
+
// DOM order made a downward drag a no-op once any rank existed (DOM order and
|
|
808
|
+
// visual order differ), which read as "the drag does nothing" or "it goes the
|
|
809
|
+
// wrong way". Always start from the order currently on screen.
|
|
810
|
+
const visible = orderedRows(all, config.orderLabels)
|
|
811
|
+
const next = reorderLabels(visible.filter((row) => row !== header).map(labelOf), source, label)
|
|
798
812
|
applyOrder(all, next)
|
|
799
813
|
notifyOrderChange(next)
|
|
800
814
|
})
|
|
801
815
|
el.addEventListener('dragend', () => {
|
|
802
816
|
dragSourceLabel = null
|
|
803
|
-
el.classList
|
|
804
|
-
el.classList
|
|
817
|
+
el.classList.remove(CLS.rowDrag)
|
|
818
|
+
el.classList.remove(CLS.rowDragOver)
|
|
805
819
|
})
|
|
806
820
|
}
|
|
807
821
|
|
|
@@ -813,26 +827,123 @@ function bindRowDrags(rows: readonly ElementLike[]): void {
|
|
|
813
827
|
}
|
|
814
828
|
|
|
815
829
|
/**
|
|
816
|
-
* Reorder the nav's rows
|
|
830
|
+
* Reorder the nav's rows to match the persisted label order.
|
|
831
|
+
*
|
|
832
|
+
* Written as the flex `order` property on each row's **wrapper**, never by moving
|
|
833
|
+
* nodes. Two measured facts force that choice:
|
|
817
834
|
*
|
|
818
|
-
*
|
|
819
|
-
*
|
|
820
|
-
*
|
|
835
|
+
* - from the 0.2.2 line on every row button sits in its own `div._panelEntry`
|
|
836
|
+
* (`SidebarRoot.tsx:78`), so the buttons are *not* siblings. The first cut
|
|
837
|
+
* moved them with `parent.insertBefore(row, next)`, where `next` belonged to
|
|
838
|
+
* another parent — the DOM throws `NotFoundError`, our `try` swallowed it, and
|
|
839
|
+
* a drop therefore highlighted the target and changed nothing (the bug this
|
|
840
|
+
* replaces);
|
|
841
|
+
* - the nodes are React's, so re-parenting them is a fight we lose on the next
|
|
842
|
+
* render. `order` is ours alone to write, it survives re-renders (the host sets
|
|
843
|
+
* no `style` on these wrappers), and removing the declarations undoes it.
|
|
844
|
+
*
|
|
845
|
+
* `.panelList` is `display:flex; flex-direction:column` (`SidebarRoot.module.css`),
|
|
846
|
+
* so `order` reorders the column without touching document order — which is also
|
|
847
|
+
* why the observer (attributes filtered to `class`) cannot see these writes.
|
|
848
|
+
*
|
|
849
|
+
* The "More" header is ordered last by {@link orderedRows}, so it stays the fold
|
|
850
|
+
* toggle no matter what the user drags.
|
|
851
|
+
* @param rows - the nav's panel rows, in document order.
|
|
852
|
+
* @param orderLabels - persisted label order; an empty list clears every rank.
|
|
821
853
|
*/
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
854
|
+
/** The parent whose flex children the ranks reorder, or null for a detached stub. */
|
|
855
|
+
function childContainer(node: ElementLike): ElementLike | null {
|
|
856
|
+
return ((node as { parentElement?: ElementLike | null }).parentElement ?? null) as ElementLike | null
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/** The flex children of a container (empty for a stub that has none). */
|
|
860
|
+
function childrenOf(container: ElementLike): ElementLike[] {
|
|
861
|
+
const kids = (container as { children?: ArrayLike<ElementLike> }).children
|
|
862
|
+
return kids === undefined ? [] : (Array.from(kids) as ElementLike[])
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
/**
|
|
866
|
+
* The flex item a rank must be written on.
|
|
867
|
+
*
|
|
868
|
+
* `foldTarget` answers "which node does the host treat as the row", and on the
|
|
869
|
+
* 0.2.2 line that is the `div._panelEntry` — a flex child of `.panelList`. The
|
|
870
|
+
* "More" row is the exception: its button sits directly inside a
|
|
871
|
+
* `span.moreAnchor`, so the closest entry above it is none and the button is
|
|
872
|
+
* returned. A rank written there is inert (the button is not a flex item) while
|
|
873
|
+
* the anchor keeps `order: 0` and floats to the top. Walk up to the child of the
|
|
874
|
+
* container so every rank lands on something the column actually lays out.
|
|
875
|
+
* @param target - the node {@link foldTarget} returned.
|
|
876
|
+
* @param container - the flex container the ranks apply to, or null.
|
|
877
|
+
* @returns the direct child of `container` that owns `target`, else `target`.
|
|
878
|
+
*/
|
|
879
|
+
function flexItemOf(target: ElementLike, container: ElementLike | null): ElementLike {
|
|
880
|
+
if (container === null) return target
|
|
881
|
+
let node = target as unknown as { parentElement?: ElementLike | null }
|
|
882
|
+
let guard = 0
|
|
883
|
+
while (node.parentElement != null && node.parentElement !== container && guard < 8) {
|
|
884
|
+
node = node.parentElement
|
|
885
|
+
guard += 1
|
|
886
|
+
}
|
|
887
|
+
return node.parentElement === container ? (node as unknown as ElementLike) : target
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
export function applyOrder(rows: readonly ElementLike[], orderLabels: readonly string[]): void {
|
|
891
|
+
if (rows.length < 2) return
|
|
892
|
+
const entries: ElementLike[] = []
|
|
893
|
+
for (const row of rows) {
|
|
894
|
+
const entry = foldTarget(row)
|
|
895
|
+
if (!entries.includes(entry)) entries.push(entry)
|
|
896
|
+
}
|
|
897
|
+
if (entries.length === 0) return
|
|
898
|
+
const container = childContainer(entries[0])
|
|
899
|
+
const wanted = new Map<ElementLike, number>()
|
|
900
|
+
if (orderLabels.length > 0) {
|
|
901
|
+
const ordered = orderedRows(rows, orderLabels)
|
|
902
|
+
ordered.forEach((row, index) => {
|
|
903
|
+
const entry = flexItemOf(foldTarget(row), container)
|
|
904
|
+
if (!wanted.has(entry)) wanted.set(entry, index + 1)
|
|
905
|
+
})
|
|
906
|
+
// Host chrome that is not one of our rows — above all the "More" anchor, a
|
|
907
|
+
// `span.moreAnchor` that wraps the header button instead of being a
|
|
908
|
+
// `div._panelEntry` — must not be left at the flex default `order: 0`, or it
|
|
909
|
+
// jumps above every ranked row (measured: "More" flew to the top of the
|
|
910
|
+
// column). Rank it past the last row so it stays where the host put it.
|
|
911
|
+
if (container !== null) {
|
|
912
|
+
const tail = ordered.length + 1
|
|
913
|
+
for (const child of childrenOf(container)) {
|
|
914
|
+
if (!wanted.has(child)) wanted.set(child, tail)
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
const touched: ElementLike[] = [...entries]
|
|
919
|
+
if (container !== null) for (const child of childrenOf(container)) touched.push(child)
|
|
920
|
+
const seen = new Set<ElementLike>()
|
|
921
|
+
for (const entry of touched) {
|
|
922
|
+
if (seen.has(entry)) continue
|
|
923
|
+
seen.add(entry)
|
|
924
|
+
const value = wanted.get(entry)
|
|
925
|
+
if (value === undefined) {
|
|
926
|
+
if (entry.getAttribute(ATTR.order) === null) continue
|
|
927
|
+
entry.removeAttribute(ATTR.order)
|
|
928
|
+
const el = entry as unknown as HTMLElement
|
|
929
|
+
if (el.style != null) el.style.order = ''
|
|
930
|
+
continue
|
|
835
931
|
}
|
|
932
|
+
const text = String(value)
|
|
933
|
+
// Write only on change: a no-op write is a mutation nobody asked for.
|
|
934
|
+
if (entry.getAttribute(ATTR.order) === text) continue
|
|
935
|
+
entry.setAttribute(ATTR.order, text)
|
|
936
|
+
const el = entry as unknown as HTMLElement
|
|
937
|
+
if (el.style != null) el.style.order = text
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
/** Undo every inline rank this plugin wrote (dispose / HMR sweep). */
|
|
942
|
+
function clearOrder(): void {
|
|
943
|
+
for (const node of Array.from(document.querySelectorAll(`[${ATTR.order}]`)) as ElementLike[]) {
|
|
944
|
+
node.removeAttribute(ATTR.order)
|
|
945
|
+
const el = node as unknown as HTMLElement
|
|
946
|
+
if (el.style != null) el.style.order = ''
|
|
836
947
|
}
|
|
837
948
|
}
|
|
838
949
|
|
|
@@ -848,8 +959,8 @@ function applyFold(): void {
|
|
|
848
959
|
if (plan === null) return
|
|
849
960
|
const { header } = plan
|
|
850
961
|
// Reorder the live rows to the persisted order before any fold marks are
|
|
851
|
-
// written.
|
|
852
|
-
// the
|
|
962
|
+
// written. Ranks are inline `order` values written only when they change, and
|
|
963
|
+
// the observer watches `class` alone, so a scan cannot trigger itself.
|
|
853
964
|
applyOrder(rows, config.orderLabels)
|
|
854
965
|
bindRowDrags(rows)
|
|
855
966
|
if (header.getAttribute(ATTR.header) === null) header.setAttribute(ATTR.header, '')
|
|
@@ -859,8 +970,9 @@ function applyFold(): void {
|
|
|
859
970
|
const align = normalizeAlign(config.align)
|
|
860
971
|
if (mount.nav.getAttribute(ATTR.align) !== align) mount.nav.setAttribute(ATTR.align, align)
|
|
861
972
|
|
|
862
|
-
// The settings card renders whatever is on screen right now; keep it in sync
|
|
863
|
-
|
|
973
|
+
// The settings card renders whatever is on screen right now; keep it in sync —
|
|
974
|
+
// and in the order the column shows, so a drag reads the same on both surfaces.
|
|
975
|
+
notifyRoster(rosterFrom(orderedRows(rows, config.orderLabels), config.keepLabels, config.hideLabels))
|
|
864
976
|
|
|
865
977
|
// Nothing to fold (every sibling is kept): say so on the control instead of
|
|
866
978
|
// flipping the arrow over an unchanged list — the first report of "arrow moves
|
|
@@ -976,6 +1088,7 @@ function unmount(): void {
|
|
|
976
1088
|
row.removeAttribute('draggable')
|
|
977
1089
|
;(row as unknown as HTMLElement).classList?.remove(CLS.rowDrag, CLS.rowDragOver)
|
|
978
1090
|
}
|
|
1091
|
+
clearOrder()
|
|
979
1092
|
mount = null
|
|
980
1093
|
}
|
|
981
1094
|
|
|
@@ -1046,6 +1159,7 @@ function sweep(): void {
|
|
|
1046
1159
|
row.removeAttribute('draggable')
|
|
1047
1160
|
;(row as unknown as HTMLElement).classList?.remove(CLS.rowDrag, CLS.rowDragOver)
|
|
1048
1161
|
}
|
|
1162
|
+
clearOrder()
|
|
1049
1163
|
mount = null
|
|
1050
1164
|
// The pin bookkeeping belongs to one window's DOM; a remount starts from what
|
|
1051
1165
|
// the host shows now, never from a count that may no longer refer to it.
|
|
@@ -281,14 +281,23 @@ function writeRowState(rows: ReturnType<typeof roster>, label: string, next: Row
|
|
|
281
281
|
* Attach a drag handle to a settings row so the visible list can be reordered.
|
|
282
282
|
*
|
|
283
283
|
* The row itself is the drag source and drop target; both surfaces (sidebar and
|
|
284
|
-
* card) compute the next order via reorderLabels and commit through
|
|
284
|
+
* card) compute the next order via reorderLabels and commit through commit().
|
|
285
|
+
*
|
|
286
|
+
* The drop commits in one direction only — the sidebar is the ordering
|
|
287
|
+
* authority: `applyConfig` ranks the live rows, `paint()` re-reads the roster
|
|
288
|
+
* (which now reports the new order), and only then does the write go out. The
|
|
289
|
+
* first cut rebuilt the list by appending fresh rows to the card root, which
|
|
290
|
+
* left the originals in place (a duplicated list that read as "nothing changed").
|
|
285
291
|
*/
|
|
286
292
|
function makeDraggableRow(row: HTMLElement, label: string, rows: ReturnType<typeof roster>): HTMLElement {
|
|
287
293
|
row.setAttribute('draggable', 'true')
|
|
288
|
-
row
|
|
294
|
+
// A grab cursor, not the drag *feedback* class: dimming the row permanently
|
|
295
|
+
// made every settings row look disabled.
|
|
296
|
+
row.classList.add(CLS.rowHandle)
|
|
289
297
|
let source = ''
|
|
290
298
|
row.addEventListener('dragstart', (e: any) => {
|
|
291
299
|
source = label
|
|
300
|
+
row.classList.add(CLS.rowDrag)
|
|
292
301
|
if (e?.dataTransfer) e.dataTransfer.effectAllowed = 'move'
|
|
293
302
|
})
|
|
294
303
|
row.addEventListener('dragover', (e: any) => {
|
|
@@ -301,22 +310,17 @@ function makeDraggableRow(row: HTMLElement, label: string, rows: ReturnType<type
|
|
|
301
310
|
row.addEventListener('drop', (e: any) => {
|
|
302
311
|
e?.preventDefault?.()
|
|
303
312
|
row.classList.remove(CLS.rowDragOver)
|
|
304
|
-
|
|
305
|
-
const labels = rows.map((entry) => entry.label)
|
|
306
|
-
const next = reorderLabels(labels, source, label)
|
|
313
|
+
const from = source
|
|
307
314
|
source = ''
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
for (const entry of reordered) {
|
|
313
|
-
// Build a fresh row for each entry in the new order.
|
|
314
|
-
cardRoot?.appendChild(buildEntry(entry, reordered))
|
|
315
|
-
}
|
|
315
|
+
if (from === '' || from === label) return
|
|
316
|
+
const next = reorderLabels(rows.map((entry) => entry.label), from, label)
|
|
317
|
+
applyConfig({ ...effectiveConfig(), orderLabels: next })
|
|
318
|
+
paint()
|
|
316
319
|
commit({ orderLabels: next })
|
|
317
320
|
})
|
|
318
321
|
row.addEventListener('dragend', () => {
|
|
319
322
|
source = ''
|
|
323
|
+
row.classList.remove(CLS.rowDrag)
|
|
320
324
|
row.classList.remove(CLS.rowDragOver)
|
|
321
325
|
})
|
|
322
326
|
return row
|