dsh-lean-router 1.0.9 → 1.1.0
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/docs/changelog.en.md +9 -1
- package/docs/changelog.md +9 -1
- package/docs/quickstart.en.md +1 -1
- package/docs/quickstart.md +1 -1
- package/lib/client.js +132 -205
- package/package.json +1 -1
- package/test/client-plugin.test.mjs +73 -79
package/docs/changelog.en.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
> English version of [changelog.md](./changelog.md). Versions follow package.json (currently 1.0
|
|
3
|
+
> English version of [changelog.md](./changelog.md). Versions follow package.json (currently 1.1.0).
|
|
4
|
+
|
|
5
|
+
## 1.1.0 (2026-11-25)
|
|
6
|
+
|
|
7
|
+
- Changed (surface, decided by the user): the skills panel moves from "header button + body overlay" to a **right sidebar tab**. The overlay had to be opened, covered the conversation and could not sit side by side, so it was never a usable form; the 1.0.9 `#lean-router-panel` overlay is dropped entirely.
|
|
8
|
+
- New: the right-sidebar contract follows the real examples `@modusensus/dsh-mneme` and `dsh-cost-meter` - the tab type and its guide entry go to `sidebarRightTabs.register({ id, kind, title, guide })` (checked with `get(id)` first, because the host throws `tab type id … is already registered`), and the body and title go to `sidebar.right.pane.tab` / `sidebar.right.pane.tab.title` with a `{ name, key }` spec.
|
|
9
|
+
- New: the header "Skills" button stays as a shortcut and opens the tab through `ctx.get("sidebarRight").openTab(kind)`.
|
|
10
|
+
- Fixed: the opener now resolves `sidebarRight` from the scoped ctx delivered by `ctx.inject(["slots"])`, so it cannot hit the "service not registered yet" timing trap again.
|
|
11
|
+
- Constraint: nothing is appended to `document.body` any more; this version is the shell only (a title and two lines), and every style inherits host theme tokens instead of hard-coded colours. 224 tests green.
|
|
4
12
|
|
|
5
13
|
## 1.0.9 (2026-11-24)
|
|
6
14
|
|
package/docs/changelog.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
# 变更记录(changelog)
|
|
2
2
|
|
|
3
|
-
> 中文为主,英文版:[changelog.en.md](./changelog.en.md)。版本号遵循 package.json(当前 1.0
|
|
3
|
+
> 中文为主,英文版:[changelog.en.md](./changelog.en.md)。版本号遵循 package.json(当前 1.1.0)。
|
|
4
|
+
|
|
5
|
+
## 1.1.0 (2026-11-25)
|
|
6
|
+
|
|
7
|
+
- 变更(形态,用户拍板):技能面板从「顶栏按钮 + body 浮层」改为**右侧栏标签页**。浮层要点开、会遮挡主对话、不能并排,本身就不是可用形态,1.0.9 的 `#lean-router-panel` 浮层实现整体废弃。
|
|
8
|
+
- 新增:按真机范例 `@modusensus/dsh-mneme` 与 `dsh-cost-meter` 的契约接入右栏 —— 类型与引导挂 `sidebarRightTabs.register({ id, kind, title, guide })`(注册前先 `get(id)` 查重,宿主对重复 id 会抛 `tab type id … is already registered`);正文与标题挂 `sidebar.right.pane.tab` / `sidebar.right.pane.tab.title`,spec 用 `{ name, key }` 关联类型。
|
|
9
|
+
- 新增:顶栏「技能」按钮保留为快捷入口,点击走 `ctx.get("sidebarRight").openTab(kind)` 直接打开右栏标签。
|
|
10
|
+
- 修复:opener 改用 `ctx.inject(["slots"])` 就绪后的 scoped ctx 取 `sidebarRight`,避免又踩「服务还没注册」的时机坑。
|
|
11
|
+
- 约束:不再往 `document.body` 追加任何元素;当前版本只做壳(标题 + 两行说明),样式全部继承宿主主题 token,不写死颜色。224 测试全绿。
|
|
4
12
|
|
|
5
13
|
## 1.0.9 (2026-11-24)
|
|
6
14
|
|
package/docs/quickstart.en.md
CHANGED
|
@@ -20,7 +20,7 @@ After restarting DSH, pick the **Lean router** preset (lean tier) or **Lean rout
|
|
|
20
20
|
### Path B: npm install (recommended)
|
|
21
21
|
|
|
22
22
|
~~~powershell
|
|
23
|
-
dsh plugin --profile desktop add npm:dsh-lean-router@1.0
|
|
23
|
+
dsh plugin --profile desktop add npm:dsh-lean-router@1.1.0
|
|
24
24
|
~~~
|
|
25
25
|
|
|
26
26
|
(Both paths match the output of scripts/install.mjs; the real installer, claim boundaries and `--uninstall` rollback belong to ticket 09.)
|
package/docs/quickstart.md
CHANGED
|
@@ -20,7 +20,7 @@ dsh plugin --profile desktop add "link:D:\path\to\dsh-lean-router"
|
|
|
20
20
|
### 路径 B:npm 安装(推荐)
|
|
21
21
|
|
|
22
22
|
~~~powershell
|
|
23
|
-
dsh plugin --profile desktop add npm:dsh-lean-router@1.0
|
|
23
|
+
dsh plugin --profile desktop add npm:dsh-lean-router@1.1.0
|
|
24
24
|
~~~
|
|
25
25
|
|
|
26
26
|
(两条路径与 scripts/install.mjs 输出的说明一致;真安装器、认领边界与 `--uninstall` 回滚归票 09。)
|
package/lib/client.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
// dsh-lean-router - 客户端 UI
|
|
1
|
+
// dsh-lean-router - 客户端 UI 层(技能面板 · 右侧栏标签页)
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
3
|
+
// 形态(用户拍板):右侧栏 tab,不做浮层、不往 document.body 追加第二份应用。
|
|
4
|
+
// 契约来源:已安装真机范例 @modusensus/dsh-mneme 的 lib/client.js 与 dsh-cost-meter。
|
|
5
|
+
// 1) 类型与引导挂服务 sidebarRightTabs: tabs.register({ id, kind, title, guide })
|
|
6
|
+
// 2) 正文与标题挂 slot: sidebar.right.pane.tab / sidebar.right.pane.tab.title,
|
|
7
|
+
// spec 用 { name, key: TAB_ID, inject }(注意是 key 不是 id)
|
|
8
|
+
// 3) 打开: ctx.get("sidebarRight").openTab(TAB_KIND)
|
|
9
|
+
//
|
|
10
|
+
// 踩过的坑(别再犯):
|
|
11
|
+
// - 直接读 ctx.register 会抛 cannot get property "register" without inject(1.0.6)
|
|
12
|
+
// - apply 早于 slots 服务就绪,ctx.get("slots") 是 undefined(1.0.7)
|
|
13
|
+
// 所以一律用 ctx.inject(["slots"], cb) 等服务就绪后再注册。
|
|
14
|
+
// - 面板不要渲染在顶栏 slot 内(会被祖先 transform/overflow 裁成黑条,1.0.9)
|
|
11
15
|
//
|
|
12
16
|
// 加载契约:package.json 的 dsh.client.platform="web" + exports["./client"],
|
|
13
17
|
// 入口形如 window.__ModuleLoader__.load({ id, factory }),factory(require) 取宿主模块。
|
|
@@ -17,6 +21,10 @@ window.__ModuleLoader__.load({
|
|
|
17
21
|
const React = require("react");
|
|
18
22
|
const h = React.createElement;
|
|
19
23
|
|
|
24
|
+
const TAB_ID = "lean-router.skills";
|
|
25
|
+
const TAB_KIND = "lean-router-skills";
|
|
26
|
+
const TAB_TITLE = "技能";
|
|
27
|
+
|
|
20
28
|
const btnStyle = {
|
|
21
29
|
display: "inline-flex",
|
|
22
30
|
alignItems: "center",
|
|
@@ -26,242 +34,161 @@ window.__ModuleLoader__.load({
|
|
|
26
34
|
marginLeft: 6,
|
|
27
35
|
borderRadius: 6,
|
|
28
36
|
border: "1px solid var(--dsh-border, rgba(128,128,128,.35))",
|
|
29
|
-
background: "
|
|
37
|
+
background: "transparent",
|
|
30
38
|
color: "inherit",
|
|
31
39
|
fontSize: 12,
|
|
32
40
|
lineHeight: "24px",
|
|
33
41
|
cursor: "pointer",
|
|
34
42
|
};
|
|
35
43
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
maxHeight: "82vh",
|
|
50
|
-
overflow: "auto",
|
|
51
|
-
padding: "20px 22px",
|
|
52
|
-
borderRadius: 12,
|
|
53
|
-
background: "var(--dsh-surface, #1b1b1f)",
|
|
54
|
-
color: "var(--dsh-text, inherit)",
|
|
55
|
-
boxShadow: "0 18px 60px rgba(0,0,0,.45)",
|
|
56
|
-
fontSize: 13,
|
|
57
|
-
lineHeight: 1.6,
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const closeStyle = {
|
|
61
|
-
position: "absolute",
|
|
62
|
-
top: 10,
|
|
63
|
-
right: 12,
|
|
64
|
-
border: "none",
|
|
65
|
-
background: "transparent",
|
|
66
|
-
color: "inherit",
|
|
67
|
-
fontSize: 18,
|
|
68
|
-
lineHeight: "20px",
|
|
69
|
-
cursor: "pointer",
|
|
70
|
-
opacity: 0.7,
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
/** 把 React 风格对象转成 cssText,DOM 浮层复用同一套样式。 */
|
|
74
|
-
function cssOf(style) {
|
|
75
|
-
return Object.entries(style)
|
|
76
|
-
.map(([key, value]) => key.replace(/[A-Z]/g, (ch) => "-" + ch.toLowerCase()) + ":" + value)
|
|
77
|
-
.join(";");
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// 1.0.9 修(真机):面板原来用 React 渲染在顶栏 slot 内,position:fixed 会被祖先的
|
|
81
|
-
// transform / overflow 限制在那一行里,只剩一条黑条。改为挂到 document.body 的纯 DOM
|
|
82
|
-
// 浮层,slot 里只留按钮。
|
|
83
|
-
let panelEl = null;
|
|
84
|
-
|
|
85
|
-
function closePanel() {
|
|
86
|
-
if (panelEl) {
|
|
87
|
-
panelEl.remove();
|
|
88
|
-
panelEl = null;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function buildPanel() {
|
|
93
|
-
const overlay = document.createElement("div");
|
|
94
|
-
overlay.id = "lean-router-panel";
|
|
95
|
-
overlay.style.cssText = cssOf(overlayStyle);
|
|
96
|
-
const card = document.createElement("div");
|
|
97
|
-
card.style.cssText = cssOf(cardStyle);
|
|
98
|
-
const close = document.createElement("button");
|
|
99
|
-
close.type = "button";
|
|
100
|
-
close.textContent = "✕";
|
|
101
|
-
close.title = "关闭";
|
|
102
|
-
close.style.cssText = cssOf(closeStyle);
|
|
103
|
-
const title = document.createElement("div");
|
|
104
|
-
title.textContent = "技能面板 · 骨架";
|
|
105
|
-
title.style.cssText = "font-size:15px;font-weight:600;margin-bottom:8px";
|
|
106
|
-
const body = document.createElement("div");
|
|
107
|
-
body.style.cssText = "opacity:.75";
|
|
108
|
-
body.innerHTML =
|
|
109
|
-
"链路已通:这个面板由 dsh-lean-router 的客户端插件渲染。<br>" +
|
|
110
|
-
"阶段 2 接入 31 个技能与审计统计,阶段 3 加分组表格、开关与一键工作流。";
|
|
111
|
-
close.addEventListener("click", (event) => {
|
|
112
|
-
event.stopPropagation();
|
|
113
|
-
closePanel();
|
|
114
|
-
});
|
|
115
|
-
card.addEventListener("click", (event) => event.stopPropagation());
|
|
116
|
-
overlay.addEventListener("click", closePanel);
|
|
117
|
-
card.appendChild(close);
|
|
118
|
-
card.appendChild(title);
|
|
119
|
-
card.appendChild(body);
|
|
120
|
-
overlay.appendChild(card);
|
|
121
|
-
return overlay;
|
|
44
|
+
/** 右栏标签图标:三条横线,取 currentColor 跟随宿主主题。 */
|
|
45
|
+
function SkillsIcon(props) {
|
|
46
|
+
const size = props && props.size ? props.size : 16;
|
|
47
|
+
return h(
|
|
48
|
+
"svg",
|
|
49
|
+
{ width: size, height: size, viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true" },
|
|
50
|
+
h("path", {
|
|
51
|
+
d: "M3 4h10M3 8h10M3 12h6",
|
|
52
|
+
stroke: "currentColor",
|
|
53
|
+
strokeWidth: 1.5,
|
|
54
|
+
strokeLinecap: "round",
|
|
55
|
+
})
|
|
56
|
+
);
|
|
122
57
|
}
|
|
123
58
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
59
|
+
/** 右栏正文(1.0.10 只做壳,验证形态)。样式全部继承宿主主题,不写死颜色。 */
|
|
60
|
+
function SkillsPane() {
|
|
61
|
+
return h(
|
|
62
|
+
"div",
|
|
63
|
+
{ style: { padding: "12px 14px", fontSize: 13, lineHeight: 1.7 } },
|
|
64
|
+
h("div", { style: { fontWeight: 600, marginBottom: 6 } }, "技能面板 · 骨架"),
|
|
65
|
+
h(
|
|
66
|
+
"div",
|
|
67
|
+
{ style: { opacity: 0.75 } },
|
|
68
|
+
"右栏形态已接好:这是 lean-router 的右侧栏标签页,可以和其他右栏面板并存。"
|
|
69
|
+
),
|
|
70
|
+
h(
|
|
71
|
+
"div",
|
|
72
|
+
{ style: { opacity: 0.75, marginTop: 6 } },
|
|
73
|
+
"下一步接入 31 个技能、开关与命中统计。"
|
|
74
|
+
)
|
|
75
|
+
);
|
|
132
76
|
}
|
|
133
77
|
|
|
134
|
-
/**
|
|
135
|
-
function SkillsButton() {
|
|
78
|
+
/** 顶栏「技能」按钮:打开右栏标签(宿主无右栏服务时什么也不做,只告警)。 */
|
|
79
|
+
function SkillsButton(props) {
|
|
80
|
+
const open = props && typeof props.open === "function" ? props.open : () => {};
|
|
136
81
|
return h(
|
|
137
82
|
"button",
|
|
138
|
-
{ type: "button", style: btnStyle, title: "
|
|
83
|
+
{ type: "button", style: btnStyle, title: "打开技能面板(右侧栏)", onClick: open },
|
|
139
84
|
"技能"
|
|
140
85
|
);
|
|
141
86
|
}
|
|
142
87
|
|
|
143
|
-
/**
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
btn.style.cssText =
|
|
156
|
-
"position:fixed;top:8px;right:12px;z-index:2147483647;height:26px;padding:0 10px;" +
|
|
157
|
-
"border-radius:6px;border:1px solid rgba(128,128,128,.45);background:rgba(30,30,36,.92);" +
|
|
158
|
-
"color:#fff;font-size:12px;line-height:24px;cursor:pointer;box-shadow:0 4px 16px rgba(0,0,0,.35)";
|
|
159
|
-
let panel = null;
|
|
160
|
-
btn.addEventListener("click", () => {
|
|
161
|
-
if (panel) {
|
|
162
|
-
panel.remove();
|
|
163
|
-
panel = null;
|
|
164
|
-
return;
|
|
88
|
+
/** 打开右栏标签;返回是否打开成功。 */
|
|
89
|
+
function makeOpener(ctx) {
|
|
90
|
+
return () => {
|
|
91
|
+
try {
|
|
92
|
+
const sidebar = typeof ctx.get === "function" ? ctx.get("sidebarRight") : undefined;
|
|
93
|
+
if (sidebar && typeof sidebar.openTab === "function") {
|
|
94
|
+
sidebar.openTab(TAB_KIND);
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
console.warn("[lean-router] sidebarRight.openTab 不可用,右栏无法打开");
|
|
98
|
+
} catch (err) {
|
|
99
|
+
console.warn("[lean-router] sidebarRight.openTab failed", err);
|
|
165
100
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
"position:fixed;top:44px;right:12px;z-index:2147483647;width:min(420px,92vw);" +
|
|
169
|
-
"padding:16px 18px;border-radius:10px;background:rgba(30,30,36,.97);color:#fff;" +
|
|
170
|
-
"font:13px/1.6 system-ui,sans-serif;box-shadow:0 18px 60px rgba(0,0,0,.5)";
|
|
171
|
-
panel.innerHTML =
|
|
172
|
-
"<div style='font-weight:600;margin-bottom:6px'>技能面板 · 兜底渲染</div>" +
|
|
173
|
-
"<div style='opacity:.75'>客户端 bundle 已加载,但 slot 注册没成功。" +
|
|
174
|
-
"这说明问题在 slot API,不在加载链路。</div>";
|
|
175
|
-
document.body.appendChild(panel);
|
|
176
|
-
});
|
|
177
|
-
document.body.appendChild(btn);
|
|
101
|
+
return false;
|
|
102
|
+
};
|
|
178
103
|
}
|
|
179
104
|
|
|
180
|
-
// 0.2.3 真机事实(对照 dsh-cost-meter 的 lib/client.js):
|
|
181
|
-
// const slots = ctx.get("slots")
|
|
182
|
-
// slots.inject(slotName, () => slots.register({ name, id, order }, Component))
|
|
183
|
-
// `slots` / `register` 都是客户端 cordis 的服务;直接读 ctx.register / ctx.slots 会抛
|
|
184
|
-
// Error: cannot get property "register" without inject。取服务的唯一安全姿势是 ctx.get(name)。
|
|
185
|
-
//
|
|
186
|
-
// 1.0.7 修(真机):旧代码把 `typeof ctx.register === "function"` 写在 try 之外,属性访问
|
|
187
|
-
// 直接抛错 → 整个 apply 失败 → 连 DOM 兜底都跑不到(顶栏没按钮的真因,控制台原文:
|
|
188
|
-
// dsh-lean-router: failed: Error: cannot get property "register" without inject)。
|
|
189
|
-
// 1.0.8 修(真机):apply 执行得比 slots 服务注册还早。此时 ctx.get("slots") 是 undefined,
|
|
190
|
-
// 旧代码直接走 DOM 兜底,而那时 document.body 还不存在 → domFallback 静默 return,
|
|
191
|
-
// 于是「bundle 已加载、控制台无报错、界面上什么都没有」。
|
|
192
|
-
// 正确姿势与 dsh-cost-meter 用 e.inject(["locale"], …) 一致:ctx.inject(["slots"], cb)
|
|
193
|
-
// 等服务就绪后再注册,服务变化时还会重跑。
|
|
194
|
-
const SLOTS = ["conversation.session.header.actions", "conversation.session.header.utilities"];
|
|
195
|
-
|
|
196
105
|
function apply(ctx) {
|
|
197
106
|
const disposers = [];
|
|
198
|
-
let registered = false;
|
|
199
107
|
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
try {
|
|
205
|
-
const dispose = slots.inject(slot, () => slots.register(spec, SkillsButton));
|
|
206
|
-
if (typeof dispose === "function") disposers.push(dispose);
|
|
207
|
-
registered = true;
|
|
208
|
-
return true;
|
|
209
|
-
} catch (err) {
|
|
210
|
-
try {
|
|
211
|
-
console.warn("[lean-router] register failed on", slot, err);
|
|
212
|
-
} catch {}
|
|
213
|
-
}
|
|
108
|
+
const registerSlots = (scope) => {
|
|
109
|
+
const slots = scope && typeof scope.get === "function" ? scope.get("slots") : undefined;
|
|
110
|
+
if (!slots || typeof slots.inject !== "function" || typeof slots.register !== "function") {
|
|
111
|
+
return false;
|
|
214
112
|
}
|
|
215
|
-
return false;
|
|
216
|
-
};
|
|
217
113
|
|
|
218
|
-
|
|
219
|
-
|
|
114
|
+
// 1) 右栏 tab 的类型与引导入口。类型挂在宿主服务上、插件重挂时仍留着,
|
|
115
|
+
// 所以必须先查重,否则宿主会抛 tab type id already registered。
|
|
220
116
|
try {
|
|
221
|
-
|
|
117
|
+
const tabs = typeof scope.get === "function" ? scope.get("sidebarRightTabs") : undefined;
|
|
118
|
+
if (tabs && typeof tabs.register === "function") {
|
|
119
|
+
const already = typeof tabs.get === "function" ? tabs.get(TAB_ID) : null;
|
|
120
|
+
if (!already) {
|
|
121
|
+
tabs.register({
|
|
122
|
+
id: TAB_ID,
|
|
123
|
+
kind: TAB_KIND,
|
|
124
|
+
title: () => TAB_TITLE,
|
|
125
|
+
guide: [
|
|
126
|
+
{
|
|
127
|
+
id: "lean-router:skills:guide",
|
|
128
|
+
order: 60,
|
|
129
|
+
title: () => TAB_TITLE,
|
|
130
|
+
description: () => "技能清单、开关与命中统计",
|
|
131
|
+
icon: (size) => h(SkillsIcon, { size }),
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
222
137
|
} catch (err) {
|
|
223
|
-
|
|
224
|
-
console.warn("[lean-router] ctx.get('slots') failed", err);
|
|
225
|
-
} catch {}
|
|
138
|
+
console.warn("[lean-router] sidebarRightTabs.register failed", err);
|
|
226
139
|
}
|
|
227
|
-
|
|
228
|
-
|
|
140
|
+
|
|
141
|
+
// 2) 顶栏入口 + 右栏正文与标题。opener 必须基于已就绪的 scope,
|
|
142
|
+
// 用外层 ctx 取 sidebarRight 可能还拿不到(1.0.8 同款时机问题)。
|
|
143
|
+
const open = makeOpener(scope);
|
|
144
|
+
const registrations = [
|
|
145
|
+
[
|
|
146
|
+
"conversation.session.header.actions",
|
|
147
|
+
() => ({ name: "conversation.session.header.actions", id: "lean-router.skills", order: 60, inject: () => ({ open }) }),
|
|
148
|
+
SkillsButton,
|
|
149
|
+
],
|
|
150
|
+
[
|
|
151
|
+
"sidebar.right.pane.tab",
|
|
152
|
+
() => ({
|
|
153
|
+
name: "sidebar.right.pane.tab",
|
|
154
|
+
key: TAB_ID,
|
|
155
|
+
inject: (sessionId) => ({ sessionId }),
|
|
156
|
+
}),
|
|
157
|
+
SkillsPane,
|
|
158
|
+
],
|
|
159
|
+
[
|
|
160
|
+
"sidebar.right.pane.tab.title",
|
|
161
|
+
() => ({ name: "sidebar.right.pane.tab.title", key: TAB_ID }),
|
|
162
|
+
() => TAB_TITLE,
|
|
163
|
+
],
|
|
164
|
+
];
|
|
165
|
+
|
|
166
|
+
let registered = 0;
|
|
167
|
+
for (const [slot, spec, component] of registrations) {
|
|
168
|
+
try {
|
|
169
|
+
const dispose = slots.inject(slot, () => slots.register(spec(), component));
|
|
170
|
+
if (typeof dispose === "function") disposers.push(dispose);
|
|
171
|
+
registered += 1;
|
|
172
|
+
} catch (err) {
|
|
173
|
+
console.warn("[lean-router] register failed on", slot, err);
|
|
174
|
+
}
|
|
229
175
|
}
|
|
230
|
-
return
|
|
176
|
+
return registered > 0;
|
|
231
177
|
};
|
|
232
178
|
|
|
233
179
|
if (typeof ctx.inject === "function") {
|
|
234
180
|
try {
|
|
235
181
|
const dispose = ctx.inject(["slots"], (scoped) => {
|
|
236
|
-
|
|
182
|
+
registerSlots(scoped);
|
|
237
183
|
});
|
|
238
184
|
if (typeof dispose === "function") disposers.push(dispose);
|
|
239
185
|
} catch (err) {
|
|
240
|
-
|
|
241
|
-
console.warn("[lean-router] ctx.inject(['slots']) failed", err);
|
|
242
|
-
} catch {}
|
|
186
|
+
console.warn("[lean-router] ctx.inject(['slots']) failed", err);
|
|
243
187
|
}
|
|
244
188
|
} else {
|
|
245
|
-
|
|
189
|
+
registerSlots(ctx);
|
|
246
190
|
}
|
|
247
191
|
|
|
248
|
-
// 兜底:2 秒后仍没注册上,就在右上角插一个纯 DOM 按钮。
|
|
249
|
-
// 目的不是最终形态,而是让「没挂上」这件事可见,不要再静默消失。
|
|
250
|
-
try {
|
|
251
|
-
const timer = setTimeout(() => {
|
|
252
|
-
if (registered) return;
|
|
253
|
-
try {
|
|
254
|
-
domFallback();
|
|
255
|
-
} catch (err) {
|
|
256
|
-
try {
|
|
257
|
-
console.warn("[lean-router] dom fallback failed", err);
|
|
258
|
-
} catch {}
|
|
259
|
-
}
|
|
260
|
-
}, 2000);
|
|
261
|
-
if (timer && typeof timer.unref === "function") timer.unref();
|
|
262
|
-
disposers.push(() => clearTimeout(timer));
|
|
263
|
-
} catch {}
|
|
264
|
-
|
|
265
192
|
return () => {
|
|
266
193
|
for (const d of disposers) {
|
|
267
194
|
try {
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
// dsh-lean-router —— 客户端插件(lib/client.js
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
// 改为挂到 document.body 的纯 DOM 浮层。
|
|
1
|
+
// dsh-lean-router —— 客户端插件(lib/client.js)契约回归。
|
|
2
|
+
// 形态演进:浮层 → 右栏标签页(用户 2026-11-25 拍板)。
|
|
3
|
+
// 契约来源:真机范例 @modusensus/dsh-mneme + dsh-cost-meter。
|
|
4
|
+
// 类型/引导: ctx.get("sidebarRightTabs").register({ id, kind, title, guide })
|
|
5
|
+
// 正文/标题: sidebar.right.pane.tab / .title,spec 用 { name, key, inject }
|
|
6
|
+
// 打开: ctx.get("sidebarRight").openTab(kind)
|
|
7
|
+
// 踩过的坑:直接读 ctx.register 会抛;apply 早于 slots 就绪时 ctx.get("slots") 为 undefined。
|
|
9
8
|
import test from "node:test";
|
|
10
9
|
import assert from "node:assert/strict";
|
|
11
10
|
|
|
@@ -25,14 +24,7 @@ function makePlugin() {
|
|
|
25
24
|
});
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
inject(name, cb) { cb(); return () => {}; },
|
|
31
|
-
register(spec, component) { registered.push({ spec, component }); return () => {}; },
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** 访问 slots / register 属性就会抛错的 ctx,复刻客户端 cordis 的服务保护。 */
|
|
27
|
+
/** 访问 register / slots 属性就会抛错的 ctx,复刻客户端 cordis 的服务保护。 */
|
|
36
28
|
function throwingGetters(extra) {
|
|
37
29
|
return Object.assign({
|
|
38
30
|
get register() { throw new Error('cannot get property "register" without inject'); },
|
|
@@ -40,83 +32,85 @@ function throwingGetters(extra) {
|
|
|
40
32
|
}, extra);
|
|
41
33
|
}
|
|
42
34
|
|
|
43
|
-
/**
|
|
44
|
-
function
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
tag, style: {}, children: [], parent: null,
|
|
52
|
-
addEventListener(type, fn) { this[type] = fn; },
|
|
53
|
-
appendChild(node) { this.children.push(node); node.parent = this; },
|
|
54
|
-
remove() { if (this.parent) { this.parent.children = this.parent.children.filter((x) => x !== this); this.parent = null; } },
|
|
55
|
-
};
|
|
56
|
-
},
|
|
35
|
+
/** 组一套假服务:slots / sidebarRightTabs / sidebarRight。 */
|
|
36
|
+
function makeServices(options = {}) {
|
|
37
|
+
const registered = [];
|
|
38
|
+
const tabTypes = [];
|
|
39
|
+
const opened = [];
|
|
40
|
+
const slots = {
|
|
41
|
+
inject(name, cb) { cb(); return () => {}; },
|
|
42
|
+
register(spec, component) { registered.push({ spec, component }); return () => {}; },
|
|
57
43
|
};
|
|
58
|
-
|
|
44
|
+
const tabs = {
|
|
45
|
+
register(def) { tabTypes.push(def); },
|
|
46
|
+
get() { return options.existingTabType === true ? { id: "lean-router.skills" } : null; },
|
|
47
|
+
};
|
|
48
|
+
const sidebar = { openTab(kind) { opened.push(kind); } };
|
|
49
|
+
const map = { slots, sidebarRightTabs: tabs, sidebarRight: sidebar };
|
|
50
|
+
return { registered, tabTypes, opened, map };
|
|
59
51
|
}
|
|
60
52
|
|
|
61
|
-
|
|
62
|
-
const registered = [];
|
|
63
|
-
const slots = makeSlots(registered);
|
|
64
|
-
let asked = null;
|
|
53
|
+
function applyWith(services) {
|
|
65
54
|
const ctx = throwingGetters({
|
|
66
|
-
inject(deps, cb) {
|
|
55
|
+
inject(deps, cb) { cb(throwingGetters({ get: (name) => services.map[name] })); return () => {}; },
|
|
67
56
|
get() { return undefined; },
|
|
68
57
|
});
|
|
69
58
|
const dispose = makePlugin().apply(ctx);
|
|
70
|
-
assert.equal(typeof dispose, "function");
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
59
|
+
assert.equal(typeof dispose, "function", "apply 必须返回 disposer");
|
|
60
|
+
return services;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
test("注册右栏 tab 类型,含 id / kind / title / guide", () => {
|
|
64
|
+
const s = applyWith(makeServices());
|
|
65
|
+
assert.equal(s.tabTypes.length, 1);
|
|
66
|
+
assert.equal(s.tabTypes[0].id, "lean-router.skills");
|
|
67
|
+
assert.equal(s.tabTypes[0].kind, "lean-router-skills");
|
|
68
|
+
assert.equal(s.tabTypes[0].title(), "技能");
|
|
69
|
+
assert.ok(Array.isArray(s.tabTypes[0].guide) && s.tabTypes[0].guide.length === 1);
|
|
76
70
|
});
|
|
77
71
|
|
|
78
|
-
test("
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
const ctx = throwingGetters({ get: (name) => (name === "slots" ? slots : undefined) });
|
|
82
|
-
const dispose = makePlugin().apply(ctx);
|
|
83
|
-
assert.equal(typeof dispose, "function");
|
|
84
|
-
assert.equal(registered.length, 1);
|
|
72
|
+
test("tab 类型已存在时不重复注册(宿主对重复 id 会抛)", () => {
|
|
73
|
+
const s = applyWith(makeServices({ existingTabType: true }));
|
|
74
|
+
assert.equal(s.tabTypes.length, 0);
|
|
85
75
|
});
|
|
86
76
|
|
|
87
|
-
test("
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
77
|
+
test("注册三个座位:顶栏入口 / 右栏正文 / 右栏标题,正文用 key 关联类型", () => {
|
|
78
|
+
const s = applyWith(makeServices());
|
|
79
|
+
const names = s.registered.map((r) => r.spec.name);
|
|
80
|
+
assert.deepEqual(names, [
|
|
81
|
+
"conversation.session.header.actions",
|
|
82
|
+
"sidebar.right.pane.tab",
|
|
83
|
+
"sidebar.right.pane.tab.title",
|
|
84
|
+
]);
|
|
85
|
+
const pane = s.registered.find((r) => r.spec.name === "sidebar.right.pane.tab");
|
|
86
|
+
assert.equal(pane.spec.key, "lean-router.skills");
|
|
87
|
+
const title = s.registered.find((r) => r.spec.name === "sidebar.right.pane.tab.title");
|
|
88
|
+
assert.equal(title.spec.key, "lean-router.skills");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("点顶栏按钮走 sidebarRight.openTab(kind)", () => {
|
|
92
|
+
const s = applyWith(makeServices());
|
|
93
|
+
const header = s.registered.find((r) => r.spec.name === "conversation.session.header.actions");
|
|
94
|
+
const element = header.component(header.spec.inject());
|
|
95
|
+
assert.equal(element.type, "button");
|
|
96
|
+
element.props.onClick();
|
|
97
|
+
assert.deepEqual(s.opened, ["lean-router-skills"]);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("没有 ctx.inject 时退化为直接注册(老宿主兼容)", () => {
|
|
101
|
+
const services = makeServices();
|
|
102
|
+
const ctx = throwingGetters({ get: (name) => services.map[name] });
|
|
103
|
+
const dispose = makePlugin().apply(ctx);
|
|
104
|
+
assert.equal(typeof dispose, "function");
|
|
105
|
+
assert.equal(services.registered.length, 3);
|
|
108
106
|
});
|
|
109
107
|
|
|
110
|
-
test("
|
|
111
|
-
|
|
108
|
+
test("不再往 document.body 追加任何东西(浮层形态已废弃)", () => {
|
|
109
|
+
const children = [];
|
|
110
|
+
globalThis.document = { body: { appendChild(node) { children.push(node); } }, getElementById() { return undefined; }, createElement() { return { style: {}, addEventListener() {} }; } };
|
|
112
111
|
try {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
assert.equal(typeof dispose, "function");
|
|
116
|
-
assert.equal(document.body.children.length, 0, "兜底要等 2 秒,不能立刻插");
|
|
117
|
-
await new Promise((resolve) => setTimeout(resolve, 2200));
|
|
118
|
-
assert.equal(document.body.children.length, 1, "2 秒后必须插兜底按钮");
|
|
119
|
-
assert.equal(document.body.children[0].id, "lean-router-dom-fallback");
|
|
112
|
+
applyWith(makeServices());
|
|
113
|
+
assert.equal(children.length, 0);
|
|
120
114
|
} finally {
|
|
121
115
|
delete globalThis.document;
|
|
122
116
|
}
|