dsh-nav-fold 0.3.2 → 0.3.3

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,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.3 — 2026-11-16
4
+
5
+ - 固定顶部区域不再"先滑一段再钉住":sticky 的 top 改为按实测内容偏移(nav 8px / 标题行 110px),滚动全程位置不变、行间间隙不再被吃掉
6
+ - 设置页按档位分组:「图标档」「收起档」两个分组标题,行标签统一为「固定顶部区域」(小号),不再出现两个同名大标题
7
+
3
8
  ## 0.3.2 — 2026-11-16
4
9
 
5
10
  修复 0.3.1 固定方式带来的三个问题(K1–K3)。
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.2";
32
+ const PLUGIN_VERSION = "0.3.3";
33
33
  /** 设置分区 / 控制条占用者 id */
34
34
  const ENTRY_ID = "nav-fold";
35
35
  /** 注入样式表的幂等标记 */
@@ -129,6 +129,8 @@ const DICT = {
129
129
  "settings.restore": "恢复默认",
130
130
  "settings.restore.confirm": "再点一次确认",
131
131
  "settings.resetModel": "只重置控件样式",
132
+ "settings.group.icon": "图标档",
133
+ "settings.group.hidden": "收起档",
132
134
  "settings.cells.title": "每行几个",
133
135
  "settings.cells.auto": "自适应",
134
136
  "settings.cells.desc": "只影响图标档。自适应按侧栏宽度排版(手机上最多 6 列);写死列数在窄侧栏或手机上可能挤压。",
@@ -199,6 +201,8 @@ const DICT = {
199
201
  "settings.restore": "Restore defaults",
200
202
  "settings.restore.confirm": "Click again to confirm",
201
203
  "settings.resetModel": "Reset control style only",
204
+ "settings.group.icon": "Icon grid",
205
+ "settings.group.hidden": "Collapsed",
202
206
  "settings.cells.title": "Icons per row",
203
207
  "settings.cells.auto": "Auto",
204
208
  "settings.cells.desc": "Only affects the icon grid. Auto follows the sidebar width (6 columns max on phones); a fixed count may feel cramped on narrow sidebars.",
@@ -324,8 +328,8 @@ const CSS_TEXT = [
324
328
  '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}',
325
329
  '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}',
326
330
  // 顶部固定区:原生滚动不变,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}',
331
+ 'nav[data-navfold-pinned="on"],nav[data-navfold-pinned="nav-only"]{position:sticky!important;top:var(--navfold-pin-top,0px)!important;z-index:4!important;background:var(--navfold-pin-bg,transparent)!important}',
332
+ '[data-navfold-pin-head]{position:sticky!important;top:var(--navfold-pin-head-top,92px)!important;z-index:3!important;background:var(--navfold-pin-bg,transparent)!important}',
329
333
  // 分隔线用绝对定位:grid(图标档)与 flex(收起档)下都满宽
330
334
  '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%)}',
331
335
  // 设置面板:列数/吸附选中态沿用控件样式那套,提示用状态色
@@ -410,6 +414,8 @@ const runtime = {
410
414
  pinRetry: 0,
411
415
  pinNodes: null,
412
416
  pinBg: "",
417
+ pinTop: 0,
418
+ pinHeadTop: 0,
413
419
  anomalies: []
414
420
  };
415
421
 
@@ -592,16 +598,41 @@ function clearPin() {
592
598
  }
593
599
 
594
600
  /**
595
- * 把 nav 高度写进滚动区变量,供标题行 sticky 的 top 使用。
601
+ * 元素在滚动内容里的偏移(与当前滚动位置无关)。
602
+ * @param area - 滚动区。
603
+ * @param el - 目标元素。
604
+ * @returns 像素偏移,取不到返回 0。
605
+ */
606
+ function contentOffset(area, el) {
607
+ if (!area || !el || typeof area.getBoundingClientRect !== "function" || typeof el.getBoundingClientRect !== "function") return 0;
608
+ try {
609
+ const ar = area.getBoundingClientRect();
610
+ const er = el.getBoundingClientRect();
611
+ const scroll = typeof area.scrollTop === "number" ? area.scrollTop : 0;
612
+ return Math.max(0, Math.round(er.top - ar.top + scroll));
613
+ } catch (err) {
614
+ return 0;
615
+ }
616
+ }
617
+
618
+ /**
619
+ * 把 nav 高度与两个 sticky 偏移写进滚动区的 CSS 变量。
620
+ * 用内容偏移而不是写死 0:这样滚动时顶部不动、也不吃掉行间空隙。
596
621
  * @param area - 滚动区。
597
622
  * @param nav - 命中的 nav。
623
+ * @param head - 工作区标题行(可能为 null)。
598
624
  */
599
- function syncNavHeight(area, nav) {
625
+ function syncPinOffsets(area, nav, head) {
600
626
  if (!area || !area.style || typeof area.style.setProperty !== "function") return;
601
627
  const height = Math.round(rectHeight(nav));
602
- if (!height) return;
628
+ const navTop = contentOffset(area, nav);
629
+ const headTop = head ? contentOffset(area, head) : navTop + (height || 0);
630
+ runtime.pinTop = navTop;
631
+ runtime.pinHeadTop = headTop;
603
632
  try {
604
- area.style.setProperty("--navfold-nav-h", height + "px");
633
+ if (height) area.style.setProperty("--navfold-nav-h", height + "px");
634
+ area.style.setProperty("--navfold-pin-top", navTop + "px");
635
+ area.style.setProperty("--navfold-pin-head-top", headTop + "px");
605
636
  } catch (err) {
606
637
  /* 设不上就退回 CSS 默认值 */
607
638
  }
@@ -634,8 +665,8 @@ function applyPin(nav) {
634
665
  } catch (err) {
635
666
  /* 设不上就退回 transparent */
636
667
  }
637
- syncNavHeight(areaNode, nav);
638
668
  const targets = findPinTargets(nav);
669
+ syncPinOffsets(areaNode, nav, targets ? targets.head : null);
639
670
  if (!targets) {
640
671
  // 找不到工作区标题行:只固定导航(等价 0.3.0 行为),不记异常以外的副作用
641
672
  clearPin();
@@ -2050,7 +2081,9 @@ const PANEL_CSS = {
2050
2081
  fontSize: 12,
2051
2082
  cursor: "pointer"
2052
2083
  },
2053
- diag: { margin: 0 }
2084
+ diag: { margin: 0 },
2085
+ groupHead: { display: "flex", alignItems: "center", gap: 6 },
2086
+ rowLabel: { fontSize: 12, color: "var(--dsw-alias-label-secondary,#666)" }
2054
2087
  };
2055
2088
 
2056
2089
  /**
@@ -2096,6 +2129,8 @@ function NavFoldSettings() {
2096
2129
  const shellMore = react.useSyncExternalStore(subscribe, getHideAllWhenShellMore, getHideAllWhenShellMore);
2097
2130
  const diagOpen = react.useSyncExternalStore(subscribe, getDiagOpen, getDiagOpen);
2098
2131
  const cellsTitleId = uid + "-cells";
2132
+ const iconGroupId = uid + "-grp-icon";
2133
+ const hiddenGroupId = uid + "-grp-hidden";
2099
2134
  const iconStickId = uid + "-stick-icon";
2100
2135
  const hiddenStickId = uid + "-stick-hidden";
2101
2136
  const shellId = uid + "-shell";
@@ -2265,11 +2300,12 @@ function NavFoldSettings() {
2265
2300
  // 图标档:每行几个 + 吸附
2266
2301
  el(
2267
2302
  "section",
2268
- { style: PANEL_CSS.group, role: "group", "aria-labelledby": cellsTitleId },
2303
+ { style: PANEL_CSS.group, role: "group", "aria-labelledby": iconGroupId },
2304
+ el("div", { style: PANEL_CSS.groupHead }, el("span", { id: iconGroupId, style: PANEL_CSS.title }, t("settings.group.icon"))),
2269
2305
  el(
2270
2306
  "div",
2271
2307
  { style: PANEL_CSS.row },
2272
- el("span", { id: cellsTitleId, style: PANEL_CSS.title, key: "t" }, t("settings.cells.title")),
2308
+ el("span", { id: cellsTitleId, style: PANEL_CSS.rowLabel, key: "t" }, t("settings.cells.title")),
2273
2309
  el(
2274
2310
  "div",
2275
2311
  { style: PANEL_CSS.seg, role: "radiogroup", "aria-labelledby": cellsTitleId, key: "g" },
@@ -2295,7 +2331,7 @@ function NavFoldSettings() {
2295
2331
  el(
2296
2332
  "div",
2297
2333
  { style: PANEL_CSS.row },
2298
- el("span", { id: iconStickId, style: PANEL_CSS.title, key: "t2" }, t("settings.stick.title")),
2334
+ el("span", { id: iconStickId, style: PANEL_CSS.rowLabel, key: "t2" }, t("settings.stick.title")),
2299
2335
  switchOf(stickCompact, iconStickId, () => setStickCompact(!stickCompact), { "data-navfold-stick": "compact" })
2300
2336
  ),
2301
2337
  el("p", { style: PANEL_CSS.desc }, t("settings.stick.compact.desc"))
@@ -2303,11 +2339,12 @@ function NavFoldSettings() {
2303
2339
  // 收起档:吸附(默认关)
2304
2340
  el(
2305
2341
  "section",
2306
- { style: PANEL_CSS.group, role: "group", "aria-labelledby": hiddenStickId },
2342
+ { style: PANEL_CSS.group, role: "group", "aria-labelledby": hiddenGroupId },
2343
+ el("div", { style: PANEL_CSS.groupHead }, el("span", { id: hiddenGroupId, style: PANEL_CSS.title }, t("settings.group.hidden"))),
2307
2344
  el(
2308
2345
  "div",
2309
2346
  { style: PANEL_CSS.row },
2310
- el("span", { id: hiddenStickId, style: PANEL_CSS.title, key: "t" }, t("settings.stick.title")),
2347
+ el("span", { id: hiddenStickId, style: PANEL_CSS.rowLabel, key: "t" }, t("settings.stick.title")),
2311
2348
  switchOf(stickHidden, hiddenStickId, () => setStickHidden(!stickHidden), { "data-navfold-stick": "hidden" })
2312
2349
  ),
2313
2350
  el("p", { style: PANEL_CSS.desc }, t("settings.stick.hidden.desc"))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-nav-fold",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "nav-fold 导航折叠 · 把 DSH 左侧栏顶部的功能入口折叠成图标网格或收起(三态 + 三种控件模型,兼容 rc.1 扁平行与 rc.2+ 包裹行)",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",