dsh-nav-fold 0.3.2 → 0.3.4
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 +13 -0
- package/lib/client.js +95 -14
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.4 — 2026-11-16
|
|
4
|
+
|
|
5
|
+
修复 0.3.3 的偏移自增缺陷(严重):滚动后每次外壳重渲染都会让「固定顶部区域」继续下移,最终把图标排推到会话列表下方。
|
|
6
|
+
|
|
7
|
+
- 测量偏移前临时解除 sticky(同一帧内还原),正常流下偏移与滚动位置无关
|
|
8
|
+
- 偏移准入加护栏:0–240px 之外拒绝;已滚动时只接受不变或变小
|
|
9
|
+
- 布局变化(模式/列数/尺寸)时重置基准重新测量
|
|
10
|
+
|
|
11
|
+
## 0.3.3 — 2026-11-16
|
|
12
|
+
|
|
13
|
+
- 固定顶部区域不再"先滑一段再钉住":sticky 的 top 改为按实测内容偏移(nav 8px / 标题行 110px),滚动全程位置不变、行间间隙不再被吃掉
|
|
14
|
+
- 设置页按档位分组:「图标档」「收起档」两个分组标题,行标签统一为「固定顶部区域」(小号),不再出现两个同名大标题
|
|
15
|
+
|
|
3
16
|
## 0.3.2 — 2026-11-16
|
|
4
17
|
|
|
5
18
|
修复 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.
|
|
32
|
+
const PLUGIN_VERSION = "0.3.4";
|
|
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:
|
|
328
|
-
'[data-navfold-pin-head]{position:sticky!important;top:var(--navfold-
|
|
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,10 @@ const runtime = {
|
|
|
410
414
|
pinRetry: 0,
|
|
411
415
|
pinNodes: null,
|
|
412
416
|
pinBg: "",
|
|
417
|
+
pinTop: 0,
|
|
418
|
+
pinHeadTop: 0,
|
|
419
|
+
pinMeasured: false,
|
|
420
|
+
pinHeadMeasured: false,
|
|
413
421
|
anomalies: []
|
|
414
422
|
};
|
|
415
423
|
|
|
@@ -583,6 +591,8 @@ function noteAnomaly(kind) {
|
|
|
583
591
|
|
|
584
592
|
/** 清掉固定区标记(只摘标题行标记,不动外壳布局)。 */
|
|
585
593
|
function clearPin() {
|
|
594
|
+
runtime.pinMeasured = false;
|
|
595
|
+
runtime.pinHeadMeasured = false;
|
|
586
596
|
const nodes = runtime.pinNodes;
|
|
587
597
|
if (nodes && nodes.head && typeof nodes.head.removeAttribute === "function") {
|
|
588
598
|
nodes.head.removeAttribute(PIN_ATTR_HEAD);
|
|
@@ -591,17 +601,79 @@ function clearPin() {
|
|
|
591
601
|
runtime.pinBg = "";
|
|
592
602
|
}
|
|
593
603
|
|
|
604
|
+
/** 偏移量的合理上限(导航/标题行不会超过这个高度) */
|
|
605
|
+
const PIN_MAX_OFFSET = 240;
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* 量元素在滚动内容里的偏移。
|
|
609
|
+
* 关键:测量前临时把 sticky 摘掉——否则算出来的是「已钉住的 top + 滚动量」,
|
|
610
|
+
* 写回变量后每次重绘都会再叠加一次滚动量(正反馈,导航会被推到列表下方)。
|
|
611
|
+
* @param area - 滚动区。
|
|
612
|
+
* @param el - 目标元素。
|
|
613
|
+
* @returns 像素偏移;失败返回 NaN。
|
|
614
|
+
*/
|
|
615
|
+
function measureLayoutOffset(area, el) {
|
|
616
|
+
if (!area || !el || typeof area.getBoundingClientRect !== "function" || typeof el.getBoundingClientRect !== "function") return NaN;
|
|
617
|
+
const style = el.style;
|
|
618
|
+
const prevPos = style ? style.position : "";
|
|
619
|
+
const prevTop = style ? style.top : "";
|
|
620
|
+
try {
|
|
621
|
+
if (style) {
|
|
622
|
+
style.position = "static";
|
|
623
|
+
style.top = "auto";
|
|
624
|
+
}
|
|
625
|
+
const ar = area.getBoundingClientRect();
|
|
626
|
+
const er = el.getBoundingClientRect();
|
|
627
|
+
const scroll = typeof area.scrollTop === "number" ? area.scrollTop : 0;
|
|
628
|
+
return Math.round(er.top - ar.top + scroll);
|
|
629
|
+
} catch (err) {
|
|
630
|
+
return NaN;
|
|
631
|
+
} finally {
|
|
632
|
+
if (style) {
|
|
633
|
+
style.position = prevPos;
|
|
634
|
+
style.top = prevTop;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* 偏移量的准入判定:越界保留旧值;已滚动时只接受"不变或变小",防止再次测到 sticky 态。
|
|
641
|
+
* @param next - 新测到的值。
|
|
642
|
+
* @param prev - 上一次的值。
|
|
643
|
+
* @param scroll - 当前滚动量。
|
|
644
|
+
* @param measured - 是否已有基准。
|
|
645
|
+
* @returns 采用的值。
|
|
646
|
+
*/
|
|
647
|
+
function acceptOffset(next, prev, scroll, measured) {
|
|
648
|
+
if (!isFinite(next) || next < 0 || next > PIN_MAX_OFFSET) return prev;
|
|
649
|
+
if (!measured) return next;
|
|
650
|
+
if (scroll > 0 && next > prev + 2) return prev;
|
|
651
|
+
return next;
|
|
652
|
+
}
|
|
653
|
+
|
|
594
654
|
/**
|
|
595
|
-
* 把 nav
|
|
655
|
+
* 把 nav 高度与两个 sticky 偏移写进滚动区的 CSS 变量。
|
|
656
|
+
* 用内容偏移而不是写死 0:这样滚动时顶部不动、也不吃掉行间空隙。
|
|
596
657
|
* @param area - 滚动区。
|
|
597
658
|
* @param nav - 命中的 nav。
|
|
659
|
+
* @param head - 工作区标题行(可能为 null)。
|
|
598
660
|
*/
|
|
599
|
-
function
|
|
661
|
+
function syncPinOffsets(area, nav, head) {
|
|
600
662
|
if (!area || !area.style || typeof area.style.setProperty !== "function") return;
|
|
601
663
|
const height = Math.round(rectHeight(nav));
|
|
602
|
-
|
|
664
|
+
const scroll = typeof area.scrollTop === "number" ? area.scrollTop : 0;
|
|
665
|
+
const navTop = acceptOffset(measureLayoutOffset(area, nav), runtime.pinTop, scroll, runtime.pinMeasured);
|
|
666
|
+
const headTop = head
|
|
667
|
+
? acceptOffset(measureLayoutOffset(area, head), runtime.pinHeadTop, scroll, runtime.pinHeadMeasured)
|
|
668
|
+
: navTop + (height || 0);
|
|
669
|
+
runtime.pinTop = navTop;
|
|
670
|
+
runtime.pinHeadTop = headTop;
|
|
671
|
+
runtime.pinMeasured = true;
|
|
672
|
+
runtime.pinHeadMeasured = true;
|
|
603
673
|
try {
|
|
604
|
-
area.style.setProperty("--navfold-nav-h", height + "px");
|
|
674
|
+
if (height) area.style.setProperty("--navfold-nav-h", height + "px");
|
|
675
|
+
area.style.setProperty("--navfold-pin-top", navTop + "px");
|
|
676
|
+
area.style.setProperty("--navfold-pin-head-top", headTop + "px");
|
|
605
677
|
} catch (err) {
|
|
606
678
|
/* 设不上就退回 CSS 默认值 */
|
|
607
679
|
}
|
|
@@ -634,8 +706,8 @@ function applyPin(nav) {
|
|
|
634
706
|
} catch (err) {
|
|
635
707
|
/* 设不上就退回 transparent */
|
|
636
708
|
}
|
|
637
|
-
syncNavHeight(areaNode, nav);
|
|
638
709
|
const targets = findPinTargets(nav);
|
|
710
|
+
syncPinOffsets(areaNode, nav, targets ? targets.head : null);
|
|
639
711
|
if (!targets) {
|
|
640
712
|
// 找不到工作区标题行:只固定导航(等价 0.3.0 行为),不记异常以外的副作用
|
|
641
713
|
clearPin();
|
|
@@ -2050,7 +2122,9 @@ const PANEL_CSS = {
|
|
|
2050
2122
|
fontSize: 12,
|
|
2051
2123
|
cursor: "pointer"
|
|
2052
2124
|
},
|
|
2053
|
-
diag: { margin: 0 }
|
|
2125
|
+
diag: { margin: 0 },
|
|
2126
|
+
groupHead: { display: "flex", alignItems: "center", gap: 6 },
|
|
2127
|
+
rowLabel: { fontSize: 12, color: "var(--dsw-alias-label-secondary,#666)" }
|
|
2054
2128
|
};
|
|
2055
2129
|
|
|
2056
2130
|
/**
|
|
@@ -2096,6 +2170,8 @@ function NavFoldSettings() {
|
|
|
2096
2170
|
const shellMore = react.useSyncExternalStore(subscribe, getHideAllWhenShellMore, getHideAllWhenShellMore);
|
|
2097
2171
|
const diagOpen = react.useSyncExternalStore(subscribe, getDiagOpen, getDiagOpen);
|
|
2098
2172
|
const cellsTitleId = uid + "-cells";
|
|
2173
|
+
const iconGroupId = uid + "-grp-icon";
|
|
2174
|
+
const hiddenGroupId = uid + "-grp-hidden";
|
|
2099
2175
|
const iconStickId = uid + "-stick-icon";
|
|
2100
2176
|
const hiddenStickId = uid + "-stick-hidden";
|
|
2101
2177
|
const shellId = uid + "-shell";
|
|
@@ -2265,11 +2341,12 @@ function NavFoldSettings() {
|
|
|
2265
2341
|
// 图标档:每行几个 + 吸附
|
|
2266
2342
|
el(
|
|
2267
2343
|
"section",
|
|
2268
|
-
{ style: PANEL_CSS.group, role: "group", "aria-labelledby":
|
|
2344
|
+
{ style: PANEL_CSS.group, role: "group", "aria-labelledby": iconGroupId },
|
|
2345
|
+
el("div", { style: PANEL_CSS.groupHead }, el("span", { id: iconGroupId, style: PANEL_CSS.title }, t("settings.group.icon"))),
|
|
2269
2346
|
el(
|
|
2270
2347
|
"div",
|
|
2271
2348
|
{ style: PANEL_CSS.row },
|
|
2272
|
-
el("span", { id: cellsTitleId, style: PANEL_CSS.
|
|
2349
|
+
el("span", { id: cellsTitleId, style: PANEL_CSS.rowLabel, key: "t" }, t("settings.cells.title")),
|
|
2273
2350
|
el(
|
|
2274
2351
|
"div",
|
|
2275
2352
|
{ style: PANEL_CSS.seg, role: "radiogroup", "aria-labelledby": cellsTitleId, key: "g" },
|
|
@@ -2295,7 +2372,7 @@ function NavFoldSettings() {
|
|
|
2295
2372
|
el(
|
|
2296
2373
|
"div",
|
|
2297
2374
|
{ style: PANEL_CSS.row },
|
|
2298
|
-
el("span", { id: iconStickId, style: PANEL_CSS.
|
|
2375
|
+
el("span", { id: iconStickId, style: PANEL_CSS.rowLabel, key: "t2" }, t("settings.stick.title")),
|
|
2299
2376
|
switchOf(stickCompact, iconStickId, () => setStickCompact(!stickCompact), { "data-navfold-stick": "compact" })
|
|
2300
2377
|
),
|
|
2301
2378
|
el("p", { style: PANEL_CSS.desc }, t("settings.stick.compact.desc"))
|
|
@@ -2303,11 +2380,12 @@ function NavFoldSettings() {
|
|
|
2303
2380
|
// 收起档:吸附(默认关)
|
|
2304
2381
|
el(
|
|
2305
2382
|
"section",
|
|
2306
|
-
{ style: PANEL_CSS.group, role: "group", "aria-labelledby":
|
|
2383
|
+
{ style: PANEL_CSS.group, role: "group", "aria-labelledby": hiddenGroupId },
|
|
2384
|
+
el("div", { style: PANEL_CSS.groupHead }, el("span", { id: hiddenGroupId, style: PANEL_CSS.title }, t("settings.group.hidden"))),
|
|
2307
2385
|
el(
|
|
2308
2386
|
"div",
|
|
2309
2387
|
{ style: PANEL_CSS.row },
|
|
2310
|
-
el("span", { id: hiddenStickId, style: PANEL_CSS.
|
|
2388
|
+
el("span", { id: hiddenStickId, style: PANEL_CSS.rowLabel, key: "t" }, t("settings.stick.title")),
|
|
2311
2389
|
switchOf(stickHidden, hiddenStickId, () => setStickHidden(!stickHidden), { "data-navfold-stick": "hidden" })
|
|
2312
2390
|
),
|
|
2313
2391
|
el("p", { style: PANEL_CSS.desc }, t("settings.stick.hidden.desc"))
|
|
@@ -2563,6 +2641,9 @@ exports.__internals = {
|
|
|
2563
2641
|
looksLikePanelNav: looksLikePanelNav,
|
|
2564
2642
|
findNav: findNav,
|
|
2565
2643
|
renderBar: renderBar,
|
|
2644
|
+
paintNav: paintNav,
|
|
2645
|
+
measureLayoutOffset: measureLayoutOffset,
|
|
2646
|
+
acceptOffset: acceptOffset,
|
|
2566
2647
|
setMode: setMode,
|
|
2567
2648
|
setModel: setModel,
|
|
2568
2649
|
getMode: getMode,
|