dsh-sidebar-fold 0.1.16 → 0.1.17

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 CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.17 (2026-11-27)
4
+
5
+ **修复:拖动排序只有反馈、顺序不变。**
6
+
7
+ - 根因:0.1.16 的 `applyOrder` 用 `parent.insertBefore(row, next)` 搬 DOM 节点。宿主 0.2.2 起每行按钮各自包在 `div._panelEntry` 里(`SidebarRoot.tsx:78`),`next` 属于另一个父节点 → DOM 抛 `NotFoundError` → 被 `try` 静默吞掉 → 拖动高亮有、松手列顺序没变;顺序落盘了也永远不生效。
8
+ - 改法:改用 CSS `order`,写在每行 **wrapper** 上(`.panelList` 是 `display:flex;flex-direction:column`)。不搬宿主节点、React 重渲染后依然成立、只在值变化时写,`orderLabels` 清空即撤掉,卸载/HMR 一并清理;「更多」header 的 rank 恒为最大值,仍是折叠开关。
9
+ - 拖动绑定从按钮挪到行 wrapper(该行就是 flex item,落在右侧 pin 留白上也能命中),并在`drop` 时清掉 source 再算新序。
10
+ - 设置卡同一处修复:原来 drop 后把新行 append 到卡片末尾(旧行还在 → 列表看着「没变」且重复),现在统一走 `applyConfig({orderLabels})` → `paint()` → `commit({orderLabels})`;卡片行的类从「拖动反馈」换成拖柄类(此前每行常驻 `opacity:.45`,读起来像禁用)。
11
+ - 新增 `tests/order-apply.test.ts`(5 条,锁「只写 rank、不搬节点、幂等、清空可撤」)+ `tests/order.test.ts` 反回归断言(`fold.ts` 运行代码里不得出现 `insertBefore`)。
12
+
3
13
  ## 0.1.16 (2026-11-27)
4
14
 
5
15
  **侧边栏入口行排序:除「更多」外全部可拖,顺序持久化到 Config。**
@@ -8,6 +18,9 @@
8
18
  - 新增纯函数 `reorderLabels` / `orderedRows`;`applyFold` 用幂等 `insertBefore` 重排,抗 MutationObserver 自激;「更多」header 恒固定末尾,折叠开关不变。
9
19
  - 设置卡入口行加拖柄,drop 后 `commit({orderLabels})`;`index.ts` 把侧栏拖动经 `subscribeOrder` 桥接回同一 scope 落盘。
10
20
  - 10 语字典 + locale 元数据同步新增 `settings.rowDrag` / `rowDragHint`;新增 `scripts/check-surface-classes.mjs` 并接进 prepack。
21
+ - **发版事故记录**:本版本的 CI release 运行以 `npm error 409 Cannot publish over previously staged version "0.1.16"` 失败
22
+ (同一版本一旦进入 npm staged 状态,重推同 tag 必失败),最终由本地 `npm publish` 补发、GitHub Release 事后回填。
23
+ 0.1.15 同型。→ 结论:修发版失败必须换版本号,不要重推已有 tag(v0.1.17 即由此而来)。
11
24
 
12
25
  ## 0.1.15
13
26
 
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.16",
3
+ "version": "0.1.17",
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 ? [] : rosterFrom(rowsOf(nav), config.keepLabels, config.hideLabels);
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. Idempotent: an `ATTR.dnd` mark
1285
- * prevents duplicate listeners across the many rescan passes. The "More" header
1286
- * is never wired (it stays the fold toggle). Drop commits the reordered label
1287
- * list; the settings card and index.ts both observe it via subscribeOrder.
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 || row.getAttribute(ATTR.dnd) !== null)
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?.add(CLS.rowDrag);
1315
+ el.classList.add(CLS.rowDrag);
1301
1316
  if (e?.dataTransfer)
1302
1317
  e.dataTransfer.effectAllowed = 'move';
1303
1318
  });
@@ -1307,31 +1322,32 @@ window.__ModuleLoader__.load({
1307
1322
  e?.preventDefault?.();
1308
1323
  if (e?.dataTransfer)
1309
1324
  e.dataTransfer.dropEffect = 'move';
1310
- el.classList?.add(CLS.rowDragOver);
1325
+ el.classList.add(CLS.rowDragOver);
1311
1326
  });
1312
1327
  el.addEventListener('dragleave', () => {
1313
- el.classList?.remove(CLS.rowDragOver);
1328
+ el.classList.remove(CLS.rowDragOver);
1314
1329
  });
1315
1330
  el.addEventListener('drop', (e) => {
1316
1331
  e?.preventDefault?.();
1317
- el.classList?.remove(CLS.rowDragOver);
1318
- if (dragSourceLabel === null || dragSourceLabel === label)
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
- const labels = all.map(labelOf);
1324
- const next = reorderLabels(labels, dragSourceLabel, label);
1325
- dragSourceLabel = null;
1326
- if (next.some((value) => value === ''))
1327
- return;
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
+ const next = reorderLabels(all.filter((row) => row !== header).map(labelOf), source, label);
1328
1344
  applyOrder(all, next);
1329
1345
  notifyOrderChange(next);
1330
1346
  });
1331
1347
  el.addEventListener('dragend', () => {
1332
1348
  dragSourceLabel = null;
1333
- el.classList?.remove(CLS.rowDrag);
1334
- el.classList?.remove(CLS.rowDragOver);
1349
+ el.classList.remove(CLS.rowDrag);
1350
+ el.classList.remove(CLS.rowDragOver);
1335
1351
  });
1336
1352
  }
1337
1353
  /** Wire every live row for reordering (called on each apply pass, idempotent). */
@@ -1343,32 +1359,73 @@ window.__ModuleLoader__.load({
1343
1359
  bindRowDrag(row, row === header);
1344
1360
  }
1345
1361
  /**
1346
- * Reorder the nav's rows in place to match the persisted label order.
1362
+ * Reorder the nav's rows to match the persisted label order.
1363
+ *
1364
+ * Written as the flex `order` property on each row's **wrapper**, never by moving
1365
+ * nodes. Two measured facts force that choice:
1366
+ *
1367
+ * - from the 0.2.2 line on every row button sits in its own `div._panelEntry`
1368
+ * (`SidebarRoot.tsx:78`), so the buttons are *not* siblings. The first cut
1369
+ * moved them with `parent.insertBefore(row, next)`, where `next` belonged to
1370
+ * another parent — the DOM throws `NotFoundError`, our `try` swallowed it, and
1371
+ * a drop therefore highlighted the target and changed nothing (the bug this
1372
+ * replaces);
1373
+ * - the nodes are React's, so re-parenting them is a fight we lose on the next
1374
+ * render. `order` is ours alone to write, it survives re-renders (the host sets
1375
+ * no `style` on these wrappers), and removing the declarations undoes it.
1376
+ *
1377
+ * `.panelList` is `display:flex; flex-direction:column` (`SidebarRoot.module.css`),
1378
+ * so `order` reorders the column without touching document order — which is also
1379
+ * why the observer (attributes filtered to `class`) cannot see these writes.
1347
1380
  *
1348
- * Mutation-safe: a row is moved only when its position actually differs from
1349
- * the target. The host owns these nodes (React), so we only re-parent them —
1350
- * never clone, never replace — and the "More" header stays at the end.
1381
+ * The "More" header is ordered last by {@link orderedRows}, so it stays the fold
1382
+ * toggle no matter what the user drags.
1383
+ * @param rows - the nav's panel rows, in document order.
1384
+ * @param orderLabels - persisted label order; an empty list clears every rank.
1351
1385
  */
1352
1386
  function applyOrder(rows, orderLabels) {
1353
- if (orderLabels.length === 0)
1354
- return;
1355
- const target = orderedRows(rows, orderLabels);
1356
- if (target.length !== rows.length)
1357
- return;
1358
- const parent = rows[0]?.parentElement;
1359
- if (parent == null)
1387
+ if (rows.length < 2)
1360
1388
  return;
1361
- // Walk the target order and insert each row before its successor; insertBefore
1362
- // of a node already in place is a no-op in the DOM, so no mutation is emitted.
1363
- for (let i = target.length - 2; i >= 0; i--) {
1364
- const row = target[i];
1365
- const next = target[i + 1];
1366
- if (row.nextElementSibling !== next) {
1367
- try {
1368
- parent.insertBefore(row, next);
1369
- }
1370
- catch { /* host may re-render */ }
1389
+ const entries = [];
1390
+ for (const row of rows) {
1391
+ const entry = foldTarget(row);
1392
+ if (!entries.includes(entry))
1393
+ entries.push(entry);
1394
+ }
1395
+ const wanted = new Map();
1396
+ if (orderLabels.length > 0) {
1397
+ orderedRows(rows, orderLabels).forEach((row, index) => {
1398
+ wanted.set(foldTarget(row), index + 1);
1399
+ });
1400
+ }
1401
+ for (const entry of entries) {
1402
+ const value = wanted.get(entry);
1403
+ if (value === undefined) {
1404
+ if (entry.getAttribute(ATTR.order) === null)
1405
+ continue;
1406
+ entry.removeAttribute(ATTR.order);
1407
+ const el = entry;
1408
+ if (el.style != null)
1409
+ el.style.order = '';
1410
+ continue;
1371
1411
  }
1412
+ const text = String(value);
1413
+ // Write only on change: a no-op write is a mutation nobody asked for.
1414
+ if (entry.getAttribute(ATTR.order) === text)
1415
+ continue;
1416
+ entry.setAttribute(ATTR.order, text);
1417
+ const el = entry;
1418
+ if (el.style != null)
1419
+ el.style.order = text;
1420
+ }
1421
+ }
1422
+ /** Undo every inline rank this plugin wrote (dispose / HMR sweep). */
1423
+ function clearOrder() {
1424
+ for (const node of Array.from(document.querySelectorAll(`[${ATTR.order}]`))) {
1425
+ node.removeAttribute(ATTR.order);
1426
+ const el = node;
1427
+ if (el.style != null)
1428
+ el.style.order = '';
1372
1429
  }
1373
1430
  }
1374
1431
  /**
@@ -1385,8 +1442,8 @@ window.__ModuleLoader__.load({
1385
1442
  return;
1386
1443
  const { header } = plan;
1387
1444
  // Reorder the live rows to the persisted order before any fold marks are
1388
- // written. insertBefore is idempotent (only moves when the order differs) so
1389
- // the MutationObserver cannot self-trigger an endless rescan loop.
1445
+ // written. Ranks are inline `order` values written only when they change, and
1446
+ // the observer watches `class` alone, so a scan cannot trigger itself.
1390
1447
  applyOrder(rows, config.orderLabels);
1391
1448
  bindRowDrags(rows);
1392
1449
  if (header.getAttribute(ATTR.header) === null)
@@ -1397,8 +1454,9 @@ window.__ModuleLoader__.load({
1397
1454
  const align = normalizeAlign(config.align);
1398
1455
  if (mount.nav.getAttribute(ATTR.align) !== align)
1399
1456
  mount.nav.setAttribute(ATTR.align, align);
1400
- // The settings card renders whatever is on screen right now; keep it in sync.
1401
- notifyRoster(rosterFrom(rows, config.keepLabels, config.hideLabels));
1457
+ // The settings card renders whatever is on screen right now; keep it in sync —
1458
+ // and in the order the column shows, so a drag reads the same on both surfaces.
1459
+ notifyRoster(rosterFrom(orderedRows(rows, config.orderLabels), config.keepLabels, config.hideLabels));
1402
1460
  mount.toggle.classList.toggle(CLS.toggleIdle, plan.idle);
1403
1461
  mount.toggle.setAttribute('aria-disabled', plan.idle ? 'true' : 'false');
1404
1462
  for (const row of rows) {
@@ -1517,6 +1575,7 @@ window.__ModuleLoader__.load({
1517
1575
  row.removeAttribute('draggable');
1518
1576
  row.classList?.remove(CLS.rowDrag, CLS.rowDragOver);
1519
1577
  }
1578
+ clearOrder();
1520
1579
  mount = null;
1521
1580
  }
1522
1581
  /**
@@ -1581,6 +1640,7 @@ window.__ModuleLoader__.load({
1581
1640
  row.removeAttribute('draggable');
1582
1641
  row.classList?.remove(CLS.rowDrag, CLS.rowDragOver);
1583
1642
  }
1643
+ clearOrder();
1584
1644
  mount = null;
1585
1645
  // The pin bookkeeping belongs to one window's DOM; a remount starts from what
1586
1646
  // the host shows now, never from a count that may no longer refer to it.
@@ -1941,14 +2001,23 @@ window.__ModuleLoader__.load({
1941
2001
  * Attach a drag handle to a settings row so the visible list can be reordered.
1942
2002
  *
1943
2003
  * 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 write().
2004
+ * card) compute the next order via reorderLabels and commit through commit().
2005
+ *
2006
+ * The drop commits in one direction only — the sidebar is the ordering
2007
+ * authority: `applyConfig` ranks the live rows, `paint()` re-reads the roster
2008
+ * (which now reports the new order), and only then does the write go out. The
2009
+ * first cut rebuilt the list by appending fresh rows to the card root, which
2010
+ * left the originals in place (a duplicated list that read as "nothing changed").
1945
2011
  */
1946
2012
  function makeDraggableRow(row, label, rows) {
1947
2013
  row.setAttribute('draggable', 'true');
1948
- row.classList.add(CLS.rowDrag);
2014
+ // A grab cursor, not the drag *feedback* class: dimming the row permanently
2015
+ // made every settings row look disabled.
2016
+ row.classList.add(CLS.rowHandle);
1949
2017
  let source = '';
1950
2018
  row.addEventListener('dragstart', (e) => {
1951
2019
  source = label;
2020
+ row.classList.add(CLS.rowDrag);
1952
2021
  if (e?.dataTransfer)
1953
2022
  e.dataTransfer.effectAllowed = 'move';
1954
2023
  });
@@ -1964,23 +2033,18 @@ window.__ModuleLoader__.load({
1964
2033
  row.addEventListener('drop', (e) => {
1965
2034
  e?.preventDefault?.();
1966
2035
  row.classList.remove(CLS.rowDragOver);
1967
- if (source === '' || source === label)
1968
- return;
1969
- const labels = rows.map((entry) => entry.label);
1970
- const next = reorderLabels(labels, source, label);
2036
+ const from = source;
1971
2037
  source = '';
1972
- // Local optimistic reorder: repaint the roster in the new order first, then
1973
- // persist it through the same commit() path as the three-state writes.
1974
- const rank = new Map(next.map((value, index) => [value, index]));
1975
- const reordered = [...rows].sort((a, b) => (rank.get(a.label) ?? 0) - (rank.get(b.label) ?? 0));
1976
- for (const entry of reordered) {
1977
- // Build a fresh row for each entry in the new order.
1978
- cardRoot?.appendChild(buildEntry(entry, reordered));
1979
- }
2038
+ if (from === '' || from === label)
2039
+ return;
2040
+ const next = reorderLabels(rows.map((entry) => entry.label), from, label);
2041
+ applyConfig({ ...effectiveConfig(), orderLabels: next });
2042
+ paint();
1980
2043
  commit({ orderLabels: next });
1981
2044
  });
1982
2045
  row.addEventListener('dragend', () => {
1983
2046
  source = '';
2047
+ row.classList.remove(CLS.rowDrag);
1984
2048
  row.classList.remove(CLS.rowDragOver);
1985
2049
  });
1986
2050
  return row;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-sidebar-fold",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
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
+ }
@@ -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('')
@@ -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 ? [] : rosterFrom(rowsOf(nav), config.keepLabels, config.hideLabels)
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,55 @@ function notifyOrderChange(order: string[]): void {
759
761
  }
760
762
 
761
763
  /**
762
- * Wire one panel row for HTML5 drag-and-drop. Idempotent: an `ATTR.dnd` mark
763
- * prevents duplicate listeners across the many rescan passes. The "More" header
764
- * is never wired (it stays the fold toggle). Drop commits the reordered label
765
- * list; the settings card and index.ts both observe it via subscribeOrder.
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 || row.getAttribute(ATTR.dnd) !== null) return
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?.add(CLS.rowDrag)
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?.add(CLS.rowDragOver)
789
+ el.classList.add(CLS.rowDragOver)
784
790
  })
785
791
  el.addEventListener('dragleave', () => {
786
- el.classList?.remove(CLS.rowDragOver)
792
+ el.classList.remove(CLS.rowDragOver)
787
793
  })
788
794
  el.addEventListener('drop', (e: any) => {
789
795
  e?.preventDefault?.()
790
- el.classList?.remove(CLS.rowDragOver)
791
- if (dragSourceLabel === null || dragSourceLabel === label) return
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
- const labels = all.map(labelOf)
795
- const next = reorderLabels(labels, dragSourceLabel, label)
796
- dragSourceLabel = null
797
- if (next.some((value) => value === '')) return
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
+ const next = reorderLabels(all.filter((row) => row !== header).map(labelOf), source, label)
798
806
  applyOrder(all, next)
799
807
  notifyOrderChange(next)
800
808
  })
801
809
  el.addEventListener('dragend', () => {
802
810
  dragSourceLabel = null
803
- el.classList?.remove(CLS.rowDrag)
804
- el.classList?.remove(CLS.rowDragOver)
811
+ el.classList.remove(CLS.rowDrag)
812
+ el.classList.remove(CLS.rowDragOver)
805
813
  })
806
814
  }
807
815
 
@@ -813,26 +821,67 @@ function bindRowDrags(rows: readonly ElementLike[]): void {
813
821
  }
814
822
 
815
823
  /**
816
- * Reorder the nav's rows in place to match the persisted label order.
824
+ * Reorder the nav's rows to match the persisted label order.
825
+ *
826
+ * Written as the flex `order` property on each row's **wrapper**, never by moving
827
+ * nodes. Two measured facts force that choice:
828
+ *
829
+ * - from the 0.2.2 line on every row button sits in its own `div._panelEntry`
830
+ * (`SidebarRoot.tsx:78`), so the buttons are *not* siblings. The first cut
831
+ * moved them with `parent.insertBefore(row, next)`, where `next` belonged to
832
+ * another parent — the DOM throws `NotFoundError`, our `try` swallowed it, and
833
+ * a drop therefore highlighted the target and changed nothing (the bug this
834
+ * replaces);
835
+ * - the nodes are React's, so re-parenting them is a fight we lose on the next
836
+ * render. `order` is ours alone to write, it survives re-renders (the host sets
837
+ * no `style` on these wrappers), and removing the declarations undoes it.
838
+ *
839
+ * `.panelList` is `display:flex; flex-direction:column` (`SidebarRoot.module.css`),
840
+ * so `order` reorders the column without touching document order — which is also
841
+ * why the observer (attributes filtered to `class`) cannot see these writes.
817
842
  *
818
- * Mutation-safe: a row is moved only when its position actually differs from
819
- * the target. The host owns these nodes (React), so we only re-parent them —
820
- * never clone, never replace — and the "More" header stays at the end.
843
+ * The "More" header is ordered last by {@link orderedRows}, so it stays the fold
844
+ * toggle no matter what the user drags.
845
+ * @param rows - the nav's panel rows, in document order.
846
+ * @param orderLabels - persisted label order; an empty list clears every rank.
821
847
  */
822
- function applyOrder(rows: readonly ElementLike[], orderLabels: readonly string[]): void {
823
- if (orderLabels.length === 0) return
824
- const target = orderedRows(rows, orderLabels)
825
- if (target.length !== rows.length) return
826
- const parent = rows[0]?.parentElement
827
- if (parent == null) return
828
- // Walk the target order and insert each row before its successor; insertBefore
829
- // of a node already in place is a no-op in the DOM, so no mutation is emitted.
830
- for (let i = target.length - 2; i >= 0; i--) {
831
- const row = target[i]
832
- const next = target[i + 1]
833
- if ((row as any).nextElementSibling !== next) {
834
- try { (parent as any).insertBefore(row, next) } catch { /* host may re-render */ }
848
+ export function applyOrder(rows: readonly ElementLike[], orderLabels: readonly string[]): void {
849
+ if (rows.length < 2) return
850
+ const entries: ElementLike[] = []
851
+ for (const row of rows) {
852
+ const entry = foldTarget(row)
853
+ if (!entries.includes(entry)) entries.push(entry)
854
+ }
855
+ const wanted = new Map<ElementLike, number>()
856
+ if (orderLabels.length > 0) {
857
+ orderedRows(rows, orderLabels).forEach((row, index) => {
858
+ wanted.set(foldTarget(row), index + 1)
859
+ })
860
+ }
861
+ for (const entry of entries) {
862
+ const value = wanted.get(entry)
863
+ if (value === undefined) {
864
+ if (entry.getAttribute(ATTR.order) === null) continue
865
+ entry.removeAttribute(ATTR.order)
866
+ const el = entry as unknown as HTMLElement
867
+ if (el.style != null) el.style.order = ''
868
+ continue
835
869
  }
870
+ const text = String(value)
871
+ // Write only on change: a no-op write is a mutation nobody asked for.
872
+ if (entry.getAttribute(ATTR.order) === text) continue
873
+ entry.setAttribute(ATTR.order, text)
874
+ const el = entry as unknown as HTMLElement
875
+ if (el.style != null) el.style.order = text
876
+ }
877
+ }
878
+
879
+ /** Undo every inline rank this plugin wrote (dispose / HMR sweep). */
880
+ function clearOrder(): void {
881
+ for (const node of Array.from(document.querySelectorAll(`[${ATTR.order}]`)) as ElementLike[]) {
882
+ node.removeAttribute(ATTR.order)
883
+ const el = node as unknown as HTMLElement
884
+ if (el.style != null) el.style.order = ''
836
885
  }
837
886
  }
838
887
 
@@ -848,8 +897,8 @@ function applyFold(): void {
848
897
  if (plan === null) return
849
898
  const { header } = plan
850
899
  // Reorder the live rows to the persisted order before any fold marks are
851
- // written. insertBefore is idempotent (only moves when the order differs) so
852
- // the MutationObserver cannot self-trigger an endless rescan loop.
900
+ // written. Ranks are inline `order` values written only when they change, and
901
+ // the observer watches `class` alone, so a scan cannot trigger itself.
853
902
  applyOrder(rows, config.orderLabels)
854
903
  bindRowDrags(rows)
855
904
  if (header.getAttribute(ATTR.header) === null) header.setAttribute(ATTR.header, '')
@@ -859,8 +908,9 @@ function applyFold(): void {
859
908
  const align = normalizeAlign(config.align)
860
909
  if (mount.nav.getAttribute(ATTR.align) !== align) mount.nav.setAttribute(ATTR.align, align)
861
910
 
862
- // The settings card renders whatever is on screen right now; keep it in sync.
863
- notifyRoster(rosterFrom(rows, config.keepLabels, config.hideLabels))
911
+ // The settings card renders whatever is on screen right now; keep it in sync —
912
+ // and in the order the column shows, so a drag reads the same on both surfaces.
913
+ notifyRoster(rosterFrom(orderedRows(rows, config.orderLabels), config.keepLabels, config.hideLabels))
864
914
 
865
915
  // Nothing to fold (every sibling is kept): say so on the control instead of
866
916
  // flipping the arrow over an unchanged list — the first report of "arrow moves
@@ -976,6 +1026,7 @@ function unmount(): void {
976
1026
  row.removeAttribute('draggable')
977
1027
  ;(row as unknown as HTMLElement).classList?.remove(CLS.rowDrag, CLS.rowDragOver)
978
1028
  }
1029
+ clearOrder()
979
1030
  mount = null
980
1031
  }
981
1032
 
@@ -1046,6 +1097,7 @@ function sweep(): void {
1046
1097
  row.removeAttribute('draggable')
1047
1098
  ;(row as unknown as HTMLElement).classList?.remove(CLS.rowDrag, CLS.rowDragOver)
1048
1099
  }
1100
+ clearOrder()
1049
1101
  mount = null
1050
1102
  // The pin bookkeeping belongs to one window's DOM; a remount starts from what
1051
1103
  // 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 write().
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.classList.add(CLS.rowDrag)
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
- if (source === '' || source === label) return
305
- const labels = rows.map((entry) => entry.label)
306
- const next = reorderLabels(labels, source, label)
313
+ const from = source
307
314
  source = ''
308
- // Local optimistic reorder: repaint the roster in the new order first, then
309
- // persist it through the same commit() path as the three-state writes.
310
- const rank = new Map(next.map((value, index) => [value, index]))
311
- const reordered = [...rows].sort((a, b) => (rank.get(a.label) ?? 0) - (rank.get(b.label) ?? 0))
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