dsh-sidebar-fold 0.1.17 → 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 CHANGED
@@ -1,5 +1,14 @@
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
+
3
12
  ## 0.1.17 (2026-11-27)
4
13
 
5
14
  **修复:拖动排序只有反馈、顺序不变。**
package/dsh.plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "dsh-external/dsh-sidebar-fold",
3
- "version": "0.1.17",
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
@@ -1340,7 +1340,13 @@ window.__ModuleLoader__.load({
1340
1340
  // Order the reorderable rows only: the "More" header is not a rank, it is
1341
1341
  // pinned last by orderedRows, and persisting its label would just be noise.
1342
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);
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);
1344
1350
  applyOrder(all, next);
1345
1351
  notifyOrderChange(next);
1346
1352
  });
@@ -1383,6 +1389,40 @@ window.__ModuleLoader__.load({
1383
1389
  * @param rows - the nav's panel rows, in document order.
1384
1390
  * @param orderLabels - persisted label order; an empty list clears every rank.
1385
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`.
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
+ }
1386
1426
  function applyOrder(rows, orderLabels) {
1387
1427
  if (rows.length < 2)
1388
1428
  return;
@@ -1392,13 +1432,39 @@ window.__ModuleLoader__.load({
1392
1432
  if (!entries.includes(entry))
1393
1433
  entries.push(entry);
1394
1434
  }
1435
+ if (entries.length === 0)
1436
+ return;
1437
+ const container = childContainer(entries[0]);
1395
1438
  const wanted = new Map();
1396
1439
  if (orderLabels.length > 0) {
1397
- orderedRows(rows, orderLabels).forEach((row, index) => {
1398
- wanted.set(foldTarget(row), index + 1);
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);
1399
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);
1456
+ }
1457
+ }
1400
1458
  }
1401
- for (const entry of entries) {
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);
1402
1468
  const value = wanted.get(entry);
1403
1469
  if (value === undefined) {
1404
1470
  if (entry.getAttribute(ATTR.order) === null)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-sidebar-fold",
3
- "version": "0.1.17",
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",
@@ -802,7 +802,13 @@ function bindRowDrag(row: ElementLike, isHeader: boolean): void {
802
802
  // Order the reorderable rows only: the "More" header is not a rank, it is
803
803
  // pinned last by orderedRows, and persisting its label would just be noise.
804
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)
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)
806
812
  applyOrder(all, next)
807
813
  notifyOrderChange(next)
808
814
  })
@@ -845,6 +851,42 @@ function bindRowDrags(rows: readonly ElementLike[]): void {
845
851
  * @param rows - the nav's panel rows, in document order.
846
852
  * @param orderLabels - persisted label order; an empty list clears every rank.
847
853
  */
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
+
848
890
  export function applyOrder(rows: readonly ElementLike[], orderLabels: readonly string[]): void {
849
891
  if (rows.length < 2) return
850
892
  const entries: ElementLike[] = []
@@ -852,13 +894,33 @@ export function applyOrder(rows: readonly ElementLike[], orderLabels: readonly s
852
894
  const entry = foldTarget(row)
853
895
  if (!entries.includes(entry)) entries.push(entry)
854
896
  }
897
+ if (entries.length === 0) return
898
+ const container = childContainer(entries[0])
855
899
  const wanted = new Map<ElementLike, number>()
856
900
  if (orderLabels.length > 0) {
857
- orderedRows(rows, orderLabels).forEach((row, index) => {
858
- wanted.set(foldTarget(row), index + 1)
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)
859
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
+ }
860
917
  }
861
- for (const entry of entries) {
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)
862
924
  const value = wanted.get(entry)
863
925
  if (value === undefined) {
864
926
  if (entry.getAttribute(ATTR.order) === null) continue