dsh-nav-fold 0.3.1 → 0.3.2
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 +10 -0
- package/README.md +8 -3
- package/lib/client.js +53 -49
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.2 — 2026-11-16
|
|
4
|
+
|
|
5
|
+
修复 0.3.1 固定方式带来的三个问题(K1–K3)。
|
|
6
|
+
|
|
7
|
+
- **改回原生滚动 + 双层 sticky**:不再重排外层布局,滚动仍由外壳负责 → 滚动条位置不变、侧栏宽度与自适应列数不再跳变
|
|
8
|
+
- 图标排与工作区标题行一起固定在顶部,只有文件夹与会话列表滚动
|
|
9
|
+
- 分隔线改为绝对定位满宽(图标档是 grid、收起档是 flex,之前 grid 下只占第一列)
|
|
10
|
+
- 找不到工作区标题行时降级为「仅固定导航」,侧栏不可见时挂起,均不影响布局
|
|
11
|
+
- 诊断区显示固定状态(已应用 / 仅固定导航 / 待定 / 未启用)与底色
|
|
12
|
+
|
|
3
13
|
## 0.3.1 — 2026-11-16
|
|
4
14
|
|
|
5
15
|
修正 0.3.0 的固定方式(0.3.0 未公开发布,仅内部迭代)。
|
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
## 为什么要它
|
|
10
10
|
|
|
11
|
-
侧栏顶部那串入口(Plugins / 自动化任务 / 上下文洞察 / …)是官方 `sidebar.panellist` 列表,每装一个带主面板的插件就多一行(36px)。实测 264px 宽的一列里 8 行占 **340px**,其下工作区/会话区只剩 **170px
|
|
11
|
+
侧栏顶部那串入口(Plugins / 自动化任务 / 上下文洞察 / …)是官方 `sidebar.panellist` 列表,每装一个带主面板的插件就多一行(36px)。实测 264px 宽的一列里 8 行占 **340px**,其下工作区/会话区只剩 **170px**;手机抽屉里更惨,旧版 DSH(0.2.2-rc.1 及更早)这块还不能滚动;新版官方已改为随侧栏一起滚动,本插件在此基础上提供「固定 / 跟随」开关,并额外支持三态折叠。
|
|
12
12
|
|
|
13
13
|
## 三种形态
|
|
14
14
|
|
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
| 图标网格 `compact` | 图标网格、隐文字(保留无障碍名)、行高 32px | **92px** |
|
|
19
19
|
| 收起 `hidden` | 只留「收起时保留」勾选的行(默认第一行)+「更多」锚点 | **100px** |
|
|
20
20
|
|
|
21
|
+
> 实测高度随列数与窗口宽度变化(下表是 264px 侧栏、7 列时的值)。
|
|
22
|
+
|
|
21
23
|
## 控制条在哪
|
|
22
24
|
|
|
23
25
|
挂在**被折叠那一组的末尾**(「更多」下面一行)——它的作用对象就是上面那几行,不是会话列表,也不是设置区:
|
|
@@ -45,8 +47,9 @@
|
|
|
45
47
|
| `cycle` | 一个按钮,**一次只显示当前档那一个图标**,点了换成下一档 |
|
|
46
48
|
| `header` | **标题行**:整组收成一行 `⌃ 功能入口 8`(位于入口列表最上方),点标题展开/收起;只有"文字行 / 收起"两态,图标网格档不可用。被外壳挪位会自动拉回,连续 3 次失败退回 `segmented` |
|
|
47
49
|
|
|
48
|
-
## 固定顶部区域与列数(0.3.
|
|
50
|
+
## 固定顶部区域与列数(0.3.2)
|
|
49
51
|
|
|
52
|
+
- **官方行为**:整栏一起滚动。开启「固定顶部区域」后,图标排与工作区标题固定、只有文件夹与会话列表滚动;关闭则完全跟随官方。
|
|
50
53
|
- **固定顶部区域**:图标档默认开启——图标排 + 工作区标题(含搜索/视图/新建)一起固定在顶部,**只有文件夹与会话列表滚动**;收起档可选(默认关);文字档不提供(行数多,固定会把会话区挤没)
|
|
51
54
|
- **底色**:固定区背景在运行时取自外壳侧栏颜色,不写死白底,浅色/深色都不会出现色块
|
|
52
55
|
- **每行几个**:自适应(默认,手机上最多 6 列)/ 8 / 7 / 6 / 5 / 4;写死 7、8 列时按侧栏实际宽度提示是否过挤,可一键切回自适应
|
|
@@ -98,6 +101,8 @@ dsh plugin --profile web add dsh-nav-fold
|
|
|
98
101
|
sudo systemctl restart dsh-web # 首次安装需要重启 Host 才会加载浏览器半
|
|
99
102
|
```
|
|
100
103
|
|
|
104
|
+
> 若你的 npm 源指向镜像(如 npmmirror),可能拉不到最新版本,可加 `--registry=https://registry.npmjs.org`。
|
|
105
|
+
|
|
101
106
|
### 从源码(开发/二次修改)
|
|
102
107
|
|
|
103
108
|
```bash
|
|
@@ -124,7 +129,7 @@ node --test test/*.test.mjs # 14 项,直接测上线产物 lib/client.js(v
|
|
|
124
129
|
|
|
125
130
|
## 版本契约(升级 DSH 后看这里)
|
|
126
131
|
|
|
127
|
-
- 支持 **DSH >= 0.2.2-rc.1 < 0.3.0**(实测 rc.1 / rc.3
|
|
132
|
+
- 支持 **DSH >= 0.2.2-rc.1 < 0.3.0**(实测 rc.1 / rc.2 / rc.3;rc.2 起入口行多一层 `div.panelEntry`)
|
|
128
133
|
- 侧栏入口行两种结构都适配:
|
|
129
134
|
- rc.1 及更早:`nav > button.panelRow`
|
|
130
135
|
- rc.2 起:`nav > div.panelEntry > button.panelRow`(行内可能还有「取消固定」按钮)
|
package/lib/client.js
CHANGED
|
@@ -29,7 +29,7 @@ const react = require("react");
|
|
|
29
29
|
/** 插件名(cordis 插件标识) */
|
|
30
30
|
const name = "nav-fold";
|
|
31
31
|
/** 版本号:必须与 package.json.version 一致(有单测守着) */
|
|
32
|
-
const PLUGIN_VERSION = "0.3.
|
|
32
|
+
const PLUGIN_VERSION = "0.3.2";
|
|
33
33
|
/** 设置分区 / 控制条占用者 id */
|
|
34
34
|
const ENTRY_ID = "nav-fold";
|
|
35
35
|
/** 注入样式表的幂等标记 */
|
|
@@ -58,12 +58,8 @@ const STORAGE_SHELL_MORE = "dsh-nav-fold/v1/shell-more";
|
|
|
58
58
|
const COLS_OPTIONS = ["auto", "8", "7", "6", "5", "4"];
|
|
59
59
|
/** 每列可用的最小像素(图标 18px + 内边距),低于它判定为“挤” */
|
|
60
60
|
const COL_MIN_PX = 32;
|
|
61
|
-
/**
|
|
62
|
-
const
|
|
63
|
-
const PIN_ATTR_REGION = "data-navfold-region";
|
|
64
|
-
const PIN_ATTR_STACK = "data-navfold-stack";
|
|
65
|
-
const PIN_ATTR_HEAD = "data-navfold-head";
|
|
66
|
-
const PIN_ATTR_LIST = "data-navfold-list";
|
|
61
|
+
/** 工作区标题行的标记属性(只用来挂 sticky,不重排布局) */
|
|
62
|
+
const PIN_ATTR_HEAD = "data-navfold-pin-head";
|
|
67
63
|
/** 命中导航元素的标记属性,三态值写在这个属性上 */
|
|
68
64
|
const NAV_ATTR = "data-navfold";
|
|
69
65
|
/** 自有控制条的标记属性 */
|
|
@@ -327,17 +323,11 @@ const CSS_TEXT = [
|
|
|
327
323
|
'@media (max-width:767px){nav[data-navfold="compact"][data-navfold-cols="auto"]{grid-template-columns:repeat(6,minmax(0,1fr))!important}}',
|
|
328
324
|
'nav[data-navfold="compact"][data-navfold-cols="8"]>button,nav[data-navfold="compact"][data-navfold-cols="8"]>div>button{height:30px!important;min-height:30px!important}',
|
|
329
325
|
'nav[data-navfold="compact"][data-navfold-cols="5"]>button,nav[data-navfold="compact"][data-navfold-cols="5"]>div>button,nav[data-navfold="compact"][data-navfold-cols="4"]>button,nav[data-navfold="compact"][data-navfold-cols="4"]>div>button{height:36px!important;min-height:36px!important}',
|
|
330
|
-
//
|
|
331
|
-
'[data-navfold-
|
|
332
|
-
'[data-navfold-
|
|
333
|
-
|
|
334
|
-
'[data-navfold-
|
|
335
|
-
'[data-navfold-list]{flex:1 1 auto!important;min-height:0!important;overflow-y:auto!important;overscroll-behavior:contain!important;padding-bottom:8px}',
|
|
336
|
-
'nav[data-navfold-pinned="on"]{position:static!important;background:var(--navfold-pin-bg,transparent)!important}',
|
|
337
|
-
'nav[data-navfold-pinned="on"]::after{content:"";display:block;height:1px;margin-top:6px;background:linear-gradient(to right,transparent 0%,var(--dsw-alias-border-l1,rgba(0,0,0,.14)) 22%,var(--dsw-alias-border-l1,rgba(0,0,0,.14)) 78%,transparent 100%)}',
|
|
338
|
-
// 回退路径:结构不符时才退回粘性导航(底色同样对齐外壳,不制造色块)
|
|
339
|
-
'nav[data-navfold-pinned="fallback"]{position:sticky!important;top:0!important;z-index:4!important;background:var(--navfold-pin-bg,transparent)!important}',
|
|
340
|
-
'nav[data-navfold-pinned="fallback"]::after{content:"";position:absolute;left:0;right:0;bottom:-1px;height:1px;pointer-events:none;background:linear-gradient(to right,transparent 0%,var(--dsw-alias-border-l1,rgba(0,0,0,.14)) 22%,var(--dsw-alias-border-l1,rgba(0,0,0,.14)) 78%,transparent 100%)}',
|
|
326
|
+
// 顶部固定区:原生滚动不变,nav 与工作区标题行用 sticky 贴在滚动口(不重排布局 → 宽度/列数不变)
|
|
327
|
+
'nav[data-navfold-pinned="on"],nav[data-navfold-pinned="nav-only"]{position:sticky!important;top:0!important;z-index:4!important;background:var(--navfold-pin-bg,transparent)!important}',
|
|
328
|
+
'[data-navfold-pin-head]{position:sticky!important;top:var(--navfold-nav-h,92px)!important;z-index:3!important;background:var(--navfold-pin-bg,transparent)!important}',
|
|
329
|
+
// 分隔线用绝对定位:grid(图标档)与 flex(收起档)下都满宽
|
|
330
|
+
'nav[data-navfold-pinned="on"]::after,nav[data-navfold-pinned="nav-only"]::after{content:"";position:absolute;left:0;right:0;bottom:-1px;height:1px;pointer-events:none;background:linear-gradient(to right,transparent 0%,var(--dsw-alias-border-l1,rgba(0,0,0,.14)) 22%,var(--dsw-alias-border-l1,rgba(0,0,0,.14)) 78%,transparent 100%)}',
|
|
341
331
|
// 设置面板:列数/吸附选中态沿用控件样式那套,提示用状态色
|
|
342
332
|
'[data-navfold-cols-btn][aria-checked="true"]{background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-label-primary,#111);border-color:var(--dsw-alias-label-tertiary,rgba(0,0,0,.28));font-weight:600;box-shadow:0 1px 2px rgba(0,0,0,.06)}',
|
|
343
333
|
'[data-navfold-warn]{margin:0;font-size:12px;line-height:1.5;color:var(--dsw-alias-state-warning-primary,#b26a00)}',
|
|
@@ -544,9 +534,10 @@ function findStack(node, depth) {
|
|
|
544
534
|
}
|
|
545
535
|
|
|
546
536
|
/**
|
|
547
|
-
* 探测顶部固定区需要的节点:滚动区
|
|
537
|
+
* 探测顶部固定区需要的节点:滚动区 + 工作区标题行。
|
|
538
|
+
* 只用来给标题行打标,不改布局(0.3.1 的布局重排已废弃)。
|
|
548
539
|
* @param nav - 命中的 nav。
|
|
549
|
-
* @returns { area,
|
|
540
|
+
* @returns { area, head } 或 null。
|
|
550
541
|
*/
|
|
551
542
|
function findPinTargets(nav) {
|
|
552
543
|
const area = nav && (nav.parentElement || nav.parentNode);
|
|
@@ -561,7 +552,7 @@ function findPinTargets(nav) {
|
|
|
561
552
|
if (!region) return null;
|
|
562
553
|
const stack = findStack(region, 0);
|
|
563
554
|
if (!stack || !stack.children || stack.children.length < 2) return null;
|
|
564
|
-
return { area: area,
|
|
555
|
+
return { area: area, head: stack.children[0] };
|
|
565
556
|
}
|
|
566
557
|
|
|
567
558
|
/**
|
|
@@ -590,21 +581,32 @@ function noteAnomaly(kind) {
|
|
|
590
581
|
runtime.lastWarnAt = runtime.anomalies[0].at;
|
|
591
582
|
}
|
|
592
583
|
|
|
593
|
-
/**
|
|
584
|
+
/** 清掉固定区标记(只摘标题行标记,不动外壳布局)。 */
|
|
594
585
|
function clearPin() {
|
|
595
586
|
const nodes = runtime.pinNodes;
|
|
596
|
-
if (nodes) {
|
|
597
|
-
|
|
598
|
-
const keys = Object.keys(map);
|
|
599
|
-
for (let i = 0; i < keys.length; i += 1) {
|
|
600
|
-
const el = nodes[keys[i]];
|
|
601
|
-
if (el && typeof el.removeAttribute === "function") el.removeAttribute(map[keys[i]]);
|
|
602
|
-
}
|
|
587
|
+
if (nodes && nodes.head && typeof nodes.head.removeAttribute === "function") {
|
|
588
|
+
nodes.head.removeAttribute(PIN_ATTR_HEAD);
|
|
603
589
|
}
|
|
604
590
|
runtime.pinNodes = null;
|
|
605
591
|
runtime.pinBg = "";
|
|
606
592
|
}
|
|
607
593
|
|
|
594
|
+
/**
|
|
595
|
+
* 把 nav 高度写进滚动区变量,供标题行 sticky 的 top 使用。
|
|
596
|
+
* @param area - 滚动区。
|
|
597
|
+
* @param nav - 命中的 nav。
|
|
598
|
+
*/
|
|
599
|
+
function syncNavHeight(area, nav) {
|
|
600
|
+
if (!area || !area.style || typeof area.style.setProperty !== "function") return;
|
|
601
|
+
const height = Math.round(rectHeight(nav));
|
|
602
|
+
if (!height) return;
|
|
603
|
+
try {
|
|
604
|
+
area.style.setProperty("--navfold-nav-h", height + "px");
|
|
605
|
+
} catch (err) {
|
|
606
|
+
/* 设不上就退回 CSS 默认值 */
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
|
|
608
610
|
/**
|
|
609
611
|
* 应用 / 撤销顶部固定区。
|
|
610
612
|
* @param nav - 命中的 nav。
|
|
@@ -623,28 +625,30 @@ function applyPin(nav) {
|
|
|
623
625
|
runtime.pinState = "pending";
|
|
624
626
|
return "pending";
|
|
625
627
|
}
|
|
628
|
+
// 底色与导航高度都挂在滚动区上:nav 与标题行共用
|
|
629
|
+
runtime.pinBg = readPanelBg(areaNode);
|
|
630
|
+
try {
|
|
631
|
+
if (areaNode.style && typeof areaNode.style.setProperty === "function") {
|
|
632
|
+
areaNode.style.setProperty("--navfold-pin-bg", runtime.pinBg);
|
|
633
|
+
}
|
|
634
|
+
} catch (err) {
|
|
635
|
+
/* 设不上就退回 transparent */
|
|
636
|
+
}
|
|
637
|
+
syncNavHeight(areaNode, nav);
|
|
626
638
|
const targets = findPinTargets(nav);
|
|
627
639
|
if (!targets) {
|
|
640
|
+
// 找不到工作区标题行:只固定导航(等价 0.3.0 行为),不记异常以外的副作用
|
|
628
641
|
clearPin();
|
|
629
|
-
runtime.
|
|
630
|
-
|
|
642
|
+
runtime.pinNodes = { area: areaNode, head: null };
|
|
643
|
+
runtime.pinState = "nav-only";
|
|
644
|
+
return "nav-only";
|
|
631
645
|
}
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
for (let i = 0; i < keys.length; i += 1) {
|
|
635
|
-
const el = targets[keys[i]];
|
|
636
|
-
if (el && typeof el.setAttribute === "function") el.setAttribute(map[keys[i]], "");
|
|
646
|
+
if (runtime.pinNodes && runtime.pinNodes.head && runtime.pinNodes.head !== targets.head) {
|
|
647
|
+
if (typeof runtime.pinNodes.head.removeAttribute === "function") runtime.pinNodes.head.removeAttribute(PIN_ATTR_HEAD);
|
|
637
648
|
}
|
|
649
|
+
if (typeof targets.head.setAttribute === "function") targets.head.setAttribute(PIN_ATTR_HEAD, "");
|
|
638
650
|
runtime.pinNodes = targets;
|
|
639
651
|
runtime.pinState = "applied";
|
|
640
|
-
runtime.pinBg = readPanelBg(targets.area);
|
|
641
|
-
try {
|
|
642
|
-
if (targets.area.style && typeof targets.area.style.setProperty === "function") {
|
|
643
|
-
targets.area.style.setProperty("--navfold-pin-bg", runtime.pinBg);
|
|
644
|
-
}
|
|
645
|
-
} catch (err) {
|
|
646
|
-
/* 设不上就退回 transparent */
|
|
647
|
-
}
|
|
648
652
|
return "applied";
|
|
649
653
|
}
|
|
650
654
|
|
|
@@ -1181,7 +1185,7 @@ function paintNav() {
|
|
|
1181
1185
|
nav.setAttribute("data-navfold-cols", runtime.cols);
|
|
1182
1186
|
const before = runtime.pinState;
|
|
1183
1187
|
const state = applyPin(nav);
|
|
1184
|
-
nav.setAttribute("data-navfold-pinned", state === "applied" ? "on" : state === "
|
|
1188
|
+
nav.setAttribute("data-navfold-pinned", state === "applied" ? "on" : state === "nav-only" ? "nav-only" : "off");
|
|
1185
1189
|
// 挂起态在下一帧再试一次(抽屉展开动画结束时高度才会非 0)
|
|
1186
1190
|
if (state === "pending" && typeof window.setTimeout === "function" && !runtime.pinRetry) {
|
|
1187
1191
|
runtime.pinRetry = window.setTimeout(() => {
|
|
@@ -1189,8 +1193,8 @@ function paintNav() {
|
|
|
1189
1193
|
paintNav();
|
|
1190
1194
|
}, 350);
|
|
1191
1195
|
}
|
|
1192
|
-
//
|
|
1193
|
-
if (state === "
|
|
1196
|
+
// 找不到工作区标题行时只固定导航:记一次,避免每次重扫刷屏
|
|
1197
|
+
if (state === "nav-only" && before !== "nav-only") noteAnomaly("未找到工作区标题行,仅固定导航区");
|
|
1194
1198
|
} catch (err) {
|
|
1195
1199
|
warn("写入档位失败", err);
|
|
1196
1200
|
}
|
|
@@ -1413,8 +1417,8 @@ function diagnosticsText() {
|
|
|
1413
1417
|
const pinText =
|
|
1414
1418
|
runtime.pinState === "applied"
|
|
1415
1419
|
? "已应用(" + runtime.mode + "档)· 底色 " + (runtime.pinBg || "transparent")
|
|
1416
|
-
: runtime.pinState === "
|
|
1417
|
-
? "
|
|
1420
|
+
: runtime.pinState === "nav-only"
|
|
1421
|
+
? "仅固定导航(未找到工作区标题行)· 底色 " + (runtime.pinBg || "transparent")
|
|
1418
1422
|
: runtime.pinState === "pending"
|
|
1419
1423
|
? "待定(侧栏当前不可见,展开后自动固定)"
|
|
1420
1424
|
: "未启用";
|