dsh-lean-router 1.0.7 → 1.0.9
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 +13 -1
- package/docs/changelog.md +13 -1
- package/docs/quickstart.en.md +1 -1
- package/docs/quickstart.md +1 -1
- package/lib/client.js +117 -53
- package/package.json +1 -1
- package/test/client-plugin.test.mjs +85 -32
package/docs/changelog.en.md
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
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.0.9).
|
|
4
|
+
|
|
5
|
+
## 1.0.9 (2026-11-24)
|
|
6
|
+
|
|
7
|
+
- Fixed (real install, rendering): the header button appeared, but clicking it drew only a thin black bar across that row. The panel used to render as a React component inside the header slot, so `position: fixed` was confined to that row by an ancestor's `transform` / `overflow`. It is now a plain DOM overlay appended to `document.body` (`#lean-router-panel`), with only the button left in the slot; the overlay sits at `z-index: 2147483000`, closes on backdrop or ✕ click, and the button toggles it.
|
|
8
|
+
- Tests: new assertion that clicking the button mounts the panel on `body` and clicking again removes it; 222 tests green.
|
|
9
|
+
|
|
10
|
+
## 1.0.8 (2026-11-24)
|
|
11
|
+
|
|
12
|
+
- Fixed (real install, client timing): `apply` in `lib/client.js` ran before the `slots` service was registered. `ctx.get("slots")` was therefore `undefined`, so 1.0.7 went straight to the DOM fallback - and at that moment `document.body` did not exist yet, so `domFallback()` returned silently. On a real host that looks like "bundle loaded, zero console errors, nothing on screen". It now mirrors how `dsh-cost-meter` uses `e.inject(["locale"], …)`: `ctx.inject(["slots"], cb)` waits for the service and re-runs when it changes.
|
|
13
|
+
- Improved: the `register` spec now carries an `inject: () => ({})` props factory (cost-meter passes that field on every registration).
|
|
14
|
+
- Improved: the fallback is now "insert the pure-DOM button only if nothing registered after 2 seconds", so a failure to mount is visible instead of silent.
|
|
15
|
+
- Tests: `test/client-plugin.test.mjs` now covers three paths - registration once `ctx.inject(["slots"])` resolves, direct registration when `ctx.inject` is absent, and the 2-second DOM fallback when slots never appears. 221 tests green.
|
|
4
16
|
|
|
5
17
|
## 1.0.7 (2026-11-24)
|
|
6
18
|
|
package/docs/changelog.md
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
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.0.9)。
|
|
4
|
+
|
|
5
|
+
## 1.0.9 (2026-11-24)
|
|
6
|
+
|
|
7
|
+
- 修复(真机,渲染):顶栏按钮能出现,但点击后面板只在那一行显示成「一条黑条」。原因是面板原先作为 React 组件渲染在顶栏 slot 内部,`position: fixed` 被祖先元素的 `transform` / `overflow` 限制在那一行里。改为挂到 `document.body` 的纯 DOM 浮层(`#lean-router-panel`),slot 里只留按钮;浮层层级提到 `2147483000`,点遮罩或 ✕ 关闭,再点按钮收起。
|
|
8
|
+
- 测试:新增「点按钮把面板挂到 body、再点一次移除」断言;222 测试全绿。
|
|
9
|
+
|
|
10
|
+
## 1.0.8 (2026-11-24)
|
|
11
|
+
|
|
12
|
+
- 修复(真机,客户端时机):`lib/client.js` 的 `apply` 执行得比 `slots` 服务注册还早。此时 `ctx.get("slots")` 是 `undefined`,1.0.7 直接走 DOM 兜底,而那时 `document.body` 尚未建立 → `domFallback()` 静默 return。真机表现就是「bundle 已加载、控制台零报错、界面上什么都没有」。改为与 `dsh-cost-meter` 用 `e.inject(["locale"], …)` 同款写法:`ctx.inject(["slots"], cb)` 等服务就绪后再注册,服务变化时自动重跑。
|
|
13
|
+
- 改进:`register` 的 spec 补上 `inject: () => ({})` props 工厂(cost-meter 每次注册都带该字段)。
|
|
14
|
+
- 改进:兜底改为「2 秒后仍未注册成功才插入纯 DOM 按钮」,让「没挂上」可见,不再静默消失。
|
|
15
|
+
- 测试:`test/client-plugin.test.mjs` 改为覆盖三条路径——`ctx.inject(["slots"])` 就绪注册、无 `ctx.inject` 时直接注册、slots 永不出现时 2 秒后插兜底。221 测试全绿。
|
|
4
16
|
|
|
5
17
|
## 1.0.7 (2026-11-24)
|
|
6
18
|
|
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.0.9
|
|
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.0.9
|
|
24
24
|
~~~
|
|
25
25
|
|
|
26
26
|
(两条路径与 scripts/install.mjs 输出的说明一致;真安装器、认领边界与 `--uninstall` 回滚归票 09。)
|
package/lib/client.js
CHANGED
|
@@ -36,7 +36,7 @@ window.__ModuleLoader__.load({
|
|
|
36
36
|
const overlayStyle = {
|
|
37
37
|
position: "fixed",
|
|
38
38
|
inset: 0,
|
|
39
|
-
zIndex:
|
|
39
|
+
zIndex: 2147483000,
|
|
40
40
|
display: "flex",
|
|
41
41
|
alignItems: "center",
|
|
42
42
|
justifyContent: "center",
|
|
@@ -70,45 +70,73 @@ window.__ModuleLoader__.load({
|
|
|
70
70
|
opacity: 0.7,
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
-
/**
|
|
74
|
-
function
|
|
75
|
-
return
|
|
76
|
-
"
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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;
|
|
92
122
|
}
|
|
93
123
|
|
|
94
|
-
|
|
124
|
+
function togglePanel() {
|
|
125
|
+
if (panelEl) {
|
|
126
|
+
closePanel();
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (typeof document === "undefined" || !document.body) return;
|
|
130
|
+
panelEl = buildPanel();
|
|
131
|
+
document.body.appendChild(panelEl);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** 顶栏「技能」按钮:点开/关闭 body 级浮层面板。 */
|
|
95
135
|
function SkillsButton() {
|
|
96
|
-
const [open, setOpen] = React.useState(false);
|
|
97
|
-
const close = React.useCallback(() => setOpen(false), []);
|
|
98
136
|
return h(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
"button",
|
|
103
|
-
{
|
|
104
|
-
type: "button",
|
|
105
|
-
style: btnStyle,
|
|
106
|
-
title: "lean-router 技能面板",
|
|
107
|
-
onClick: () => setOpen((value) => !value),
|
|
108
|
-
},
|
|
109
|
-
"技能"
|
|
110
|
-
),
|
|
111
|
-
open ? h(SkillsPanel, { onClose: close }) : null
|
|
137
|
+
"button",
|
|
138
|
+
{ type: "button", style: btnStyle, title: "lean-router 技能面板", onClick: togglePanel },
|
|
139
|
+
"技能"
|
|
112
140
|
);
|
|
113
141
|
}
|
|
114
142
|
|
|
@@ -158,46 +186,82 @@ window.__ModuleLoader__.load({
|
|
|
158
186
|
// 1.0.7 修(真机):旧代码把 `typeof ctx.register === "function"` 写在 try 之外,属性访问
|
|
159
187
|
// 直接抛错 → 整个 apply 失败 → 连 DOM 兜底都跑不到(顶栏没按钮的真因,控制台原文:
|
|
160
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
|
+
// 等服务就绪后再注册,服务变化时还会重跑。
|
|
161
194
|
const SLOTS = ["conversation.session.header.actions", "conversation.session.header.utilities"];
|
|
162
195
|
|
|
163
196
|
function apply(ctx) {
|
|
164
197
|
const disposers = [];
|
|
165
|
-
let
|
|
166
|
-
try {
|
|
167
|
-
slots = typeof ctx.get === "function" ? ctx.get("slots") : undefined;
|
|
168
|
-
} catch (err) {
|
|
169
|
-
try {
|
|
170
|
-
console.warn("[lean-router] ctx.get('slots') failed", err);
|
|
171
|
-
} catch {}
|
|
172
|
-
}
|
|
198
|
+
let registered = false;
|
|
173
199
|
|
|
174
|
-
|
|
200
|
+
const registerInto = (slots) => {
|
|
175
201
|
for (const slot of SLOTS) {
|
|
176
|
-
|
|
202
|
+
// inject 是 slot 的 props 工厂:cost-meter 每次 register 都带,这里给空对象即可。
|
|
203
|
+
const spec = { name: slot, id: "lean-router.skills", order: 60, inject: () => ({}) };
|
|
177
204
|
try {
|
|
178
205
|
const dispose = slots.inject(slot, () => slots.register(spec, SkillsButton));
|
|
179
206
|
if (typeof dispose === "function") disposers.push(dispose);
|
|
180
|
-
|
|
207
|
+
registered = true;
|
|
208
|
+
return true;
|
|
181
209
|
} catch (err) {
|
|
182
210
|
try {
|
|
183
211
|
console.warn("[lean-router] register failed on", slot, err);
|
|
184
212
|
} catch {}
|
|
185
213
|
}
|
|
186
214
|
}
|
|
187
|
-
|
|
215
|
+
return false;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
const attempt = (scope) => {
|
|
219
|
+
let slots;
|
|
220
|
+
try {
|
|
221
|
+
slots = scope && typeof scope.get === "function" ? scope.get("slots") : undefined;
|
|
222
|
+
} catch (err) {
|
|
223
|
+
try {
|
|
224
|
+
console.warn("[lean-router] ctx.get('slots') failed", err);
|
|
225
|
+
} catch {}
|
|
226
|
+
}
|
|
227
|
+
if (slots === undefined || typeof slots.inject !== "function" || typeof slots.register !== "function") {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
return registerInto(slots);
|
|
231
|
+
};
|
|
188
232
|
|
|
189
|
-
|
|
190
|
-
// 目的不是最终形态,而是区分「bundle 没加载」与「slot API 不对」这两类失败。
|
|
191
|
-
if (disposers.length === 0) {
|
|
233
|
+
if (typeof ctx.inject === "function") {
|
|
192
234
|
try {
|
|
193
|
-
|
|
235
|
+
const dispose = ctx.inject(["slots"], (scoped) => {
|
|
236
|
+
attempt(scoped);
|
|
237
|
+
});
|
|
238
|
+
if (typeof dispose === "function") disposers.push(dispose);
|
|
194
239
|
} catch (err) {
|
|
195
240
|
try {
|
|
196
|
-
console.warn("[lean-router]
|
|
241
|
+
console.warn("[lean-router] ctx.inject(['slots']) failed", err);
|
|
197
242
|
} catch {}
|
|
198
243
|
}
|
|
244
|
+
} else {
|
|
245
|
+
attempt(ctx);
|
|
199
246
|
}
|
|
200
247
|
|
|
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
|
+
|
|
201
265
|
return () => {
|
|
202
266
|
for (const d of disposers) {
|
|
203
267
|
try {
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
// dsh-lean-router
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
1
|
+
// dsh-lean-router —— 客户端插件(lib/client.js)的服务获取、时机与渲染回归。
|
|
2
|
+
// 真机事故链:
|
|
3
|
+
// 1.0.6: 直接读 ctx.register 抛 cannot get property "register" without inject,apply 整体失败。
|
|
4
|
+
// 1.0.7: 改成 ctx.get("slots"),但 apply 早于 slots 服务注册,拿到 undefined 后兜底又因
|
|
5
|
+
// document.body 未建立而静默返回 → 无按钮、无报错。
|
|
6
|
+
// 1.0.8: 用 ctx.inject(["slots"], cb) 等服务就绪,按钮出现。
|
|
7
|
+
// 1.0.9: 面板原先渲染在顶栏 slot 内,position:fixed 被祖先 transform/overflow 裁成一条黑条,
|
|
8
|
+
// 改为挂到 document.body 的纯 DOM 浮层。
|
|
7
9
|
import test from "node:test";
|
|
8
10
|
import assert from "node:assert/strict";
|
|
9
11
|
|
|
@@ -14,8 +16,6 @@ await import("../lib/client.js");
|
|
|
14
16
|
const React = {
|
|
15
17
|
createElement: (type, props, ...children) => ({ type, props, children }),
|
|
16
18
|
Fragment: "Fragment",
|
|
17
|
-
useState: (value) => [value, () => {}],
|
|
18
|
-
useCallback: (fn) => fn,
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
function makePlugin() {
|
|
@@ -25,45 +25,98 @@ function makePlugin() {
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
function makeCtx(slots) {
|
|
28
|
+
function makeSlots(registered) {
|
|
30
29
|
return {
|
|
31
|
-
|
|
30
|
+
inject(name, cb) { cb(); return () => {}; },
|
|
31
|
+
register(spec, component) { registered.push({ spec, component }); return () => {}; },
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** 访问 slots / register 属性就会抛错的 ctx,复刻客户端 cordis 的服务保护。 */
|
|
36
|
+
function throwingGetters(extra) {
|
|
37
|
+
return Object.assign({
|
|
32
38
|
get register() { throw new Error('cannot get property "register" without inject'); },
|
|
33
39
|
get slots() { throw new Error('cannot get property "slots" without inject'); },
|
|
40
|
+
}, extra);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** 够用的假 DOM:支持 createElement / appendChild / remove / addEventListener。 */
|
|
44
|
+
function makeFakeDocument() {
|
|
45
|
+
const body = { tag: "body", children: [], appendChild(node) { this.children.push(node); node.parent = this; } };
|
|
46
|
+
const doc = {
|
|
47
|
+
body,
|
|
48
|
+
getElementById() { return undefined; },
|
|
49
|
+
createElement(tag) {
|
|
50
|
+
return {
|
|
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
|
+
},
|
|
34
57
|
};
|
|
58
|
+
return doc;
|
|
35
59
|
}
|
|
36
60
|
|
|
37
|
-
test("
|
|
61
|
+
test("用 ctx.inject(['slots'], cb) 等服务就绪后注册到头栏 slot", () => {
|
|
38
62
|
const registered = [];
|
|
39
|
-
const slots =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
63
|
+
const slots = makeSlots(registered);
|
|
64
|
+
let asked = null;
|
|
65
|
+
const ctx = throwingGetters({
|
|
66
|
+
inject(deps, cb) { asked = deps; cb(throwingGetters({ get: (name) => (name === "slots" ? slots : undefined) })); return () => {}; },
|
|
67
|
+
get() { return undefined; },
|
|
68
|
+
});
|
|
69
|
+
const dispose = makePlugin().apply(ctx);
|
|
44
70
|
assert.equal(typeof dispose, "function");
|
|
71
|
+
assert.deepEqual(asked, ["slots"]);
|
|
45
72
|
assert.equal(registered.length, 1);
|
|
46
73
|
assert.equal(registered[0].spec.name, "conversation.session.header.actions");
|
|
47
74
|
assert.equal(registered[0].spec.id, "lean-router.skills");
|
|
48
|
-
assert.equal(typeof registered[0].
|
|
75
|
+
assert.equal(typeof registered[0].spec.inject, "function", "spec 需要 inject props 工厂");
|
|
49
76
|
});
|
|
50
77
|
|
|
51
|
-
test("
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
78
|
+
test("没有 ctx.inject 时退化为直接取 slots 注册", () => {
|
|
79
|
+
const registered = [];
|
|
80
|
+
const slots = makeSlots(registered);
|
|
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);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("点按钮把面板挂到 body(不在 slot 内渲染),再点一次移除", () => {
|
|
88
|
+
const registered = [];
|
|
89
|
+
const slots = makeSlots(registered);
|
|
90
|
+
const ctx = throwingGetters({
|
|
91
|
+
inject(deps, cb) { cb(throwingGetters({ get: (name) => (name === "slots" ? slots : undefined) })); return () => {}; },
|
|
92
|
+
get() { return undefined; },
|
|
93
|
+
});
|
|
94
|
+
makePlugin().apply(ctx);
|
|
95
|
+
globalThis.document = makeFakeDocument();
|
|
96
|
+
try {
|
|
97
|
+
const Button = registered[0].component;
|
|
98
|
+
const element = Button({});
|
|
99
|
+
assert.equal(element.type, "button");
|
|
100
|
+
element.props.onClick();
|
|
101
|
+
assert.equal(document.body.children.length, 1, "面板必须挂到 body");
|
|
102
|
+
assert.equal(document.body.children[0].id, "lean-router-panel");
|
|
103
|
+
element.props.onClick();
|
|
104
|
+
assert.equal(document.body.children.length, 0, "再点一次必须移除");
|
|
105
|
+
} finally {
|
|
106
|
+
delete globalThis.document;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("slots 一直不出现时,2 秒后插入纯 DOM 兜底按钮(不再静默)", async () => {
|
|
111
|
+
globalThis.document = makeFakeDocument();
|
|
61
112
|
try {
|
|
62
|
-
const
|
|
113
|
+
const ctx = throwingGetters({ inject() { return () => {}; }, get() { return undefined; } });
|
|
114
|
+
const dispose = makePlugin().apply(ctx);
|
|
63
115
|
assert.equal(typeof dispose, "function");
|
|
64
|
-
assert.equal(
|
|
65
|
-
|
|
66
|
-
assert.equal(
|
|
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");
|
|
67
120
|
} finally {
|
|
68
121
|
delete globalThis.document;
|
|
69
122
|
}
|