@done-coding/forge-plugin-guide 0.0.1-alpha.0 → 0.1.1-alpha.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.
Files changed (2) hide show
  1. package/es/index.mjs +149 -137
  2. package/package.json +3 -3
package/es/index.mjs CHANGED
@@ -1,59 +1,59 @@
1
- import { shallowRef as S, readonly as B, computed as A } from "vue";
2
- import { BADGE_KEY_ATTR as C, BADGE_HOST_ATTR as P, BADGE_MASK_KINDS as O } from "@done-coding/admin-core";
1
+ import { shallowRef as x, readonly as C, computed as _ } from "vue";
2
+ import { BADGE_KEY_ATTR as P, BADGE_HOST_ATTR as B, BADGE_MASK_KINDS as O } from "@done-coding/admin-core";
3
3
  import { driver as M } from "driver.js";
4
4
  import "driver.js/dist/driver.css";
5
5
  const N = (e) => {
6
6
  if (!e) return [];
7
7
  try {
8
8
  const r = JSON.parse(e);
9
- return Array.isArray(r) ? r.filter((o) => typeof o == "string") : [];
9
+ return Array.isArray(r) ? r.filter((t) => typeof t == "string") : [];
10
10
  } catch {
11
11
  return [];
12
12
  }
13
13
  }, L = (e, r) => {
14
- const o = S(
14
+ const t = x(
15
15
  N(e.getItem(r))
16
- ), s = (n) => {
17
- o.value = n, e.setItem(r, JSON.stringify(n));
18
- }, c = (n) => o.value.includes(n), t = (n) => {
19
- c(n) || s([...o.value, n]);
20
- }, i = () => {
21
- s([]);
16
+ ), l = (s) => {
17
+ t.value = s, e.setItem(r, JSON.stringify(s));
18
+ }, c = (s) => t.value.includes(s), n = (s) => {
19
+ c(s) || l([...t.value, s]);
20
+ }, d = () => {
21
+ l([]);
22
22
  };
23
23
  return {
24
- seen: B(o),
24
+ seen: C(t),
25
25
  isSeen: c,
26
- markSeen: t,
27
- reset: i
26
+ markSeen: n,
27
+ reset: d
28
28
  };
29
- }, U = (e) => e.replace(/(["\\])/g, "\\$1"), F = (e) => `[${C}="${U(e)}"]`, j = (e) => {
29
+ }, U = (e) => e.replace(/(["\\])/g, "\\$1"), F = (e) => `[${P}="${U(e)}"]`, j = (e) => {
30
30
  if (typeof document > "u") return;
31
31
  const r = document.querySelector(
32
32
  F(e)
33
33
  );
34
34
  if (!r) return;
35
- const o = r.closest(`[${P}]`) ?? r;
36
- return Y(o) ? o : void 0;
35
+ const t = r.closest(`[${B}]`) ?? r;
36
+ return Y(t) ? t : void 0;
37
37
  }, Y = (e) => e.getClientRects().length > 0, z = "[dc-plugin-guide]", H = O, V = (e, r) => r.startsWith("/") ? r : e ? `${e.replace(/\/$/, "")}/${r}` : `/${r}`, W = (e) => {
38
38
  const r = /* @__PURE__ */ new Map();
39
- let o = 0;
40
- const s = (c, t) => {
41
- c.forEach((i) => {
39
+ let t = 0;
40
+ const l = (c, n) => {
41
+ c.forEach((d) => {
42
42
  var v;
43
- const n = V(t, i.path), l = o++;
44
- r.has(n) || r.set(n, l), typeof i.name == "string" && !r.has(i.name) && r.set(i.name, l), (v = i.children) != null && v.length && s(i.children, n);
43
+ const s = V(n, d.path), a = t++;
44
+ r.has(s) || r.set(s, a), typeof d.name == "string" && !r.has(d.name) && r.set(d.name, a), (v = d.children) != null && v.length && l(d.children, s);
45
45
  });
46
46
  };
47
- return s(e ?? [], ""), r;
48
- }, J = (e, r) => !!e.expireAt && e.expireAt <= r, y = (e, r, o) => {
47
+ return l(e ?? [], ""), r;
48
+ }, q = (e, r) => !!e.expireAt && e.expireAt <= r, y = (e, r, t) => {
49
49
  if (e) {
50
50
  if (e.has(r)) return;
51
51
  e.add(r);
52
52
  }
53
- console.warn(`${z} ${o}`);
54
- }, R = (e, r, o) => {
55
- const s = e.key ?? e.badgeKey;
56
- if (!s) {
53
+ console.warn(`${z} ${t}`);
54
+ }, R = (e, r, t) => {
55
+ const l = e.key ?? e.badgeKey;
56
+ if (!l) {
57
57
  y(
58
58
  r.warned,
59
59
  "__nokey__",
@@ -62,40 +62,40 @@ const N = (e) => {
62
62
  return;
63
63
  }
64
64
  const c = e.badgeKey ? r.marks[e.badgeKey] : void 0;
65
- if (e.badgeKey && (!c || J(c, o))) return;
65
+ if (e.badgeKey && (!c || q(c, t))) return;
66
66
  if (c && H.includes(c.kind)) {
67
67
  y(
68
68
  r.warned,
69
- `mask:${s}`,
70
- `「${s}」的标是 ${c.kind},它会遮挡宿主交互(用户点不动),与引导正面冲突,已跳过。[MUST NOT] 把会遮挡的档(${O.join(
69
+ `mask:${l}`,
70
+ `「${l}」的标是 ${c.kind},它会遮挡宿主交互(用户点不动),与引导正面冲突,已跳过。[MUST NOT] 把会遮挡的档(${O.join(
71
71
  " / "
72
72
  )})配进 badgeKinds。`
73
73
  );
74
74
  return;
75
75
  }
76
- const t = e.description ?? (c == null ? void 0 : c.description);
77
- if (!t) {
76
+ const n = e.description ?? (c == null ? void 0 : c.description);
77
+ if (!n) {
78
78
  y(
79
79
  r.warned,
80
- `nodesc:${s}`,
81
- `「${s}」没有讲解正文(step.description 与 BadgeEntry.description 都为空),已跳过。[MUST NOT] 拿菜单 title 硬凑——没内容的引导步骤是噪音。`
80
+ `nodesc:${l}`,
81
+ `「${l}」没有讲解正文(step.description 与 BadgeEntry.description 都为空),已跳过。[MUST NOT] 拿菜单 title 硬凑——没内容的引导步骤是噪音。`
82
82
  );
83
83
  return;
84
84
  }
85
85
  if (e.route && !r.hasRouter) {
86
86
  y(
87
87
  r.warned,
88
- `norouter:${s}`,
89
- `「${s}」配了 route 但 createGuidePlugin 没拿到 router,无法导航,已跳过。`
88
+ `norouter:${l}`,
89
+ `「${l}」配了 route 但 createGuidePlugin 没拿到 router,无法导航,已跳过。`
90
90
  );
91
91
  return;
92
92
  }
93
- const i = e.badgeKey, n = c == null ? void 0 : c.version, l = n === void 0 || n === "" ? s : `${s}@${n}`;
93
+ const d = e.badgeKey, s = c == null ? void 0 : c.version, a = s === void 0 || s === "" ? l : `${l}@${s}`;
94
94
  return {
95
95
  ...e,
96
- key: l,
97
- sourceKey: s,
98
- description: t,
96
+ key: a,
97
+ sourceKey: l,
98
+ description: n,
99
99
  /**
100
100
  * 锚点:显式 `element` 优先,否则由 `badgeKey` 解析。
101
101
  *
@@ -104,19 +104,19 @@ const N = (e) => {
104
104
  * 高亮一个小圆点说「看这里」不是想要的。driver.js 的 `element` 支持
105
105
  * `() => Element`,且 `waitForElement` 会反复重算它 ⇒ 跨路由 / 懒挂载也吃得下。
106
106
  */
107
- element: e.element ?? (i ? () => j(i) : void 0)
107
+ element: e.element ?? (d ? () => j(d) : void 0)
108
108
  };
109
- }, T = (e) => {
109
+ }, $ = (e) => {
110
110
  var c;
111
111
  const r = e.now ?? Date.now();
112
112
  if ((c = e.steps) != null && c.length)
113
- return e.steps.map((t) => R(t, e, r)).filter((t) => !!t);
114
- const o = W(e.routes);
115
- return Object.keys(e.marks).filter((t) => e.badgeKinds.includes(e.marks[t].kind)).sort((t, i) => {
116
- const n = o.get(t), l = o.get(i);
117
- return n !== void 0 && l !== void 0 ? n - l : n !== void 0 ? -1 : l !== void 0 ? 1 : t < i ? -1 : t > i ? 1 : 0;
118
- }).map((t) => R({ badgeKey: t }, e, r)).filter((t) => !!t);
119
- }, q = `dc-guide-theme-${Math.random().toString(36).slice(2, 8)}`, X = "data-dc-guide-theme", h = "var(--dc-core-surface, var(--el-bg-color-overlay))", m = "var(--dc-core-primary-color, var(--el-color-primary))", Z = `
113
+ return e.steps.map((n) => R(n, e, r)).filter((n) => !!n);
114
+ const t = W(e.routes);
115
+ return Object.keys(e.marks).filter((n) => e.badgeKinds.includes(e.marks[n].kind)).sort((n, d) => {
116
+ const s = t.get(n), a = t.get(d);
117
+ return s !== void 0 && a !== void 0 ? s - a : s !== void 0 ? -1 : a !== void 0 ? 1 : n < d ? -1 : n > d ? 1 : 0;
118
+ }).map((n) => R({ badgeKey: n }, e, r)).filter((n) => !!n);
119
+ }, J = `dc-guide-theme-${Math.random().toString(36).slice(2, 8)}`, X = "data-dc-guide-theme", h = "var(--dc-core-surface, var(--el-bg-color-overlay))", S = "var(--dc-core-primary-color, var(--el-color-primary))", Z = `
120
120
  .driver-popover {
121
121
  color: var(--dc-core-base-color, var(--el-text-color-primary));
122
122
  background-color: ${h};
@@ -160,7 +160,7 @@ const N = (e) => {
160
160
 
161
161
  /* hover 对齐 EP default 档:用户主动悬停才染主色 */
162
162
  .driver-popover-footer-btn:hover {
163
- color: ${m};
163
+ color: ${S};
164
164
  background-color: var(--el-color-primary-light-9);
165
165
  border-color: var(--el-color-primary-light-7);
166
166
  }
@@ -181,8 +181,8 @@ const N = (e) => {
181
181
  .driver-popover-next-btn,
182
182
  .driver-popover-next-btn:focus:not(:hover) {
183
183
  color: var(--el-color-white, #fff);
184
- background-color: ${m};
185
- border-color: ${m};
184
+ background-color: ${S};
185
+ border-color: ${S};
186
186
  }
187
187
  .driver-popover-next-btn:hover {
188
188
  color: var(--el-color-white, #fff);
@@ -211,7 +211,7 @@ const N = (e) => {
211
211
  * 有一半在视口外、另一半被窗口裁掉,实测不可见,故无需为它做任何规避。
212
212
  */
213
213
  svg.driver-overlay path {
214
- stroke: ${m};
214
+ stroke: ${S};
215
215
  stroke-width: 2;
216
216
  }
217
217
 
@@ -226,7 +226,7 @@ const Q = () => {
226
226
  if (K || typeof document > "u") return;
227
227
  K = !0;
228
228
  const e = document.createElement("style");
229
- e.id = q, e.setAttribute(X, ""), e.textContent = Z, document.head.appendChild(e);
229
+ e.id = J, e.setAttribute(X, ""), e.textContent = Z, document.head.appendChild(e);
230
230
  }, ee = {
231
231
  showProgress: !0,
232
232
  progressText: "{{current}} / {{total}}",
@@ -255,7 +255,7 @@ const Q = () => {
255
255
  /** 等超时仍没有 → 跳过该步继续,[MUST NOT] 让它退化成「屏幕中央的空高亮」 */
256
256
  skipMissingElement: !0
257
257
  }, re = (e) => {
258
- var r, o;
258
+ var r, t;
259
259
  return {
260
260
  element: e.element,
261
261
  advanceOnClick: e.advanceOnClick,
@@ -265,7 +265,7 @@ const Q = () => {
265
265
  title: e.title,
266
266
  description: e.description,
267
267
  side: (r = e.popover) == null ? void 0 : r.side,
268
- align: (o = e.popover) == null ? void 0 : o.align,
268
+ align: (t = e.popover) == null ? void 0 : t.align,
269
269
  /**
270
270
  * 🔴 **[MUST] 显式清空**:driver.js 在**首步硬编码禁用 `previous`**
271
271
  * (源码 `disableButtons:[...isFirst?[]:["previous"]]`),而本包把那一位复用成了
@@ -295,141 +295,153 @@ const Q = () => {
295
295
  }, ne = (e, r) => {
296
296
  if (!e || typeof MutationObserver > "u") return () => {
297
297
  };
298
- const o = () => e.getClientRects().length === 0;
299
- if (o()) return () => {
300
- };
301
- const s = new MutationObserver(() => {
302
- o() && (s.disconnect(), r());
298
+ const t = () => e.getClientRects().length === 0;
299
+ if (t()) {
300
+ const c = setTimeout(r, 0);
301
+ return () => clearTimeout(c);
302
+ }
303
+ const l = new MutationObserver(() => {
304
+ t() && (l.disconnect(), r());
303
305
  });
304
- return s.observe(document.body, {
306
+ return l.observe(document.body, {
305
307
  childList: !0,
306
308
  subtree: !0,
307
309
  attributes: !0,
308
310
  attributeFilter: ["style", "class", "hidden"]
309
- }), () => s.disconnect();
311
+ }), () => l.disconnect();
310
312
  }, ie = (e) => {
311
- const { steps: r, router: o, driverConfig: s, onStepSeen: c } = e;
313
+ const { steps: r, router: t, driverConfig: l, onStepSeen: c } = e;
312
314
  Q();
313
- const t = r.map(re), i = (v, g) => {
314
- const u = oe(v);
315
- if (!u || !o || o.currentRoute.value.path === u) {
316
- g();
315
+ const n = r.map(re), d = (u, i) => {
316
+ const o = oe(u);
317
+ if (!o || !t || t.currentRoute.value.path === o) {
318
+ i();
317
319
  return;
318
320
  }
319
- o.push(u).catch(() => {
320
- }).then(g, g);
321
+ t.push(o).catch(() => {
322
+ }).then(i, i);
321
323
  };
322
- let n = () => {
324
+ let s = () => {
323
325
  };
324
- const l = M({
326
+ const a = M({
325
327
  ...ee,
326
- ...s,
327
- steps: t,
328
- onNextClick: (v, g, u) => {
329
- const x = u.index ?? 0;
330
- i(t[x + 1], () => u.driver.moveNext());
328
+ ...l,
329
+ steps: n,
330
+ onNextClick: (u, i, o) => {
331
+ const g = o.index ?? 0;
332
+ d(n[g + 1], () => o.driver.moveNext());
331
333
  },
332
334
  // 「上一步」位已复用为「跳过」⇒ 点它即销毁整条导览,[MUST NOT] 再 movePrevious
333
- onPrevClick: (v, g, u) => {
334
- u.driver.destroy();
335
+ onPrevClick: (u, i, o) => {
336
+ o.driver.destroy();
335
337
  },
336
- onHighlighted: (v, g) => {
337
- const u = te(g);
338
- u && c(u), n(), n = ne(v, () => {
339
- l.isActive() && (l.hasPreviousStep() ? l.movePrevious() : l.destroy());
338
+ onHighlighted: (u, i) => {
339
+ const o = te(i);
340
+ o && c(o), s(), s = ne(u, () => {
341
+ a.isActive() && (a.hasPreviousStep() ? a.movePrevious() : a.destroy());
340
342
  });
341
343
  }
342
- });
343
- return i(t[0], () => l.drive()), {
344
+ }), v = 300;
345
+ let p;
346
+ const m = () => {
347
+ p = setTimeout(() => {
348
+ if (!a.isActive()) return;
349
+ const u = document.querySelector(".driver-popover");
350
+ u && u.getClientRects().length > 0 || a.destroy();
351
+ }, v);
352
+ };
353
+ return d(n[0], () => {
354
+ a.drive(), m();
355
+ }), {
344
356
  destroy: () => {
345
- n(), l.isActive() && l.destroy();
357
+ s(), p !== void 0 && clearTimeout(p), a.isActive() && a.destroy();
346
358
  }
347
359
  };
348
- }, I = "dc-plugin-guide", se = ["new", "updated"], ce = "guide/seen", de = (e) => {
360
+ }, D = "dc-plugin-guide", se = ["new", "updated"], ce = "guide/seen", de = (e) => {
349
361
  const r = e == null ? void 0 : e.bridge;
350
362
  if (!(r != null && r.badge) || typeof r.getStorage != "function")
351
363
  throw new Error(
352
- `${I}: 安装面是 core bridge 的插件面,请用 coreBridge.use(guide),[MUST NOT] 用 app.use(guide)(两者 install 签名不同)`
364
+ `${D}: 安装面是 core bridge 的插件面,请用 coreBridge.use(guide),[MUST NOT] 用 app.use(guide)(两者 install 签名不同)`
353
365
  );
354
366
  return r;
355
367
  }, ge = (e = {}) => {
356
- const r = e.badgeKinds ?? se, o = e.storageKey ?? ce, s = e.name ?? I, c = /* @__PURE__ */ new Set(), t = S(), i = S();
357
- let n;
358
- const l = A(
368
+ const r = e.badgeKinds ?? se, t = e.storageKey ?? ce, l = e.name ?? D, c = /* @__PURE__ */ new Set(), n = x(), d = x();
369
+ let s;
370
+ const a = _(
359
371
  () => {
360
- var d, a;
361
- return T({
362
- marks: ((d = t.value) == null ? void 0 : d.badge.marks.value) ?? {},
372
+ var i, o;
373
+ return $({
374
+ marks: ((i = n.value) == null ? void 0 : i.badge.marks.value) ?? {},
363
375
  badgeKinds: r,
364
376
  steps: e.steps,
365
- routes: (a = t.value) == null ? void 0 : a.getRoutes(),
377
+ routes: (o = n.value) == null ? void 0 : o.getRoutes(),
366
378
  hasRouter: !!e.router,
367
379
  warned: c
368
380
  });
369
381
  }
370
- ), v = A(() => {
371
- const d = i.value;
372
- if (!d) return l.value;
373
- const a = d.seen.value;
374
- return l.value.filter((f) => !a.includes(f.key));
375
- }), g = (d) => {
376
- var w, E, _, $;
377
- const a = d.keys && Array.from(new Set(d.keys));
378
- if (!a)
379
- return d.force ? l.value : v.value;
380
- const f = (b) => a.map((k) => b.find((G) => G.sourceKey === k)).filter((k) => !!k);
382
+ ), v = _(() => {
383
+ const i = d.value;
384
+ if (!i) return a.value;
385
+ const o = i.seen.value;
386
+ return a.value.filter((g) => !o.includes(g.key));
387
+ }), p = (i) => {
388
+ var w, E, T, A;
389
+ const o = i.keys && Array.from(new Set(i.keys));
390
+ if (!o)
391
+ return i.force ? a.value : v.value;
392
+ const g = (b) => o.map((k) => b.find((I) => I.sourceKey === k)).filter((k) => !!k);
381
393
  if ((w = e.steps) != null && w.length)
382
- return f(d.force ? l.value : v.value);
383
- const p = T({
384
- marks: ((E = t.value) == null ? void 0 : E.badge.marks.value) ?? {},
394
+ return g(i.force ? a.value : v.value);
395
+ const f = $({
396
+ marks: ((E = n.value) == null ? void 0 : E.badge.marks.value) ?? {},
385
397
  badgeKinds: r,
386
- steps: a.map((b) => ({ badgeKey: b })),
387
- routes: (_ = t.value) == null ? void 0 : _.getRoutes(),
398
+ steps: o.map((b) => ({ badgeKey: b })),
399
+ routes: (T = n.value) == null ? void 0 : T.getRoutes(),
388
400
  hasRouter: !!e.router,
389
401
  warned: c
390
402
  });
391
- if (d.force) return p;
392
- const D = (($ = i.value) == null ? void 0 : $.seen.value) ?? [];
393
- return p.filter((b) => !D.includes(b.key));
394
- }, u = () => {
395
- n == null || n.destroy(), n = void 0;
403
+ if (i.force) return f;
404
+ const G = ((A = d.value) == null ? void 0 : A.seen.value) ?? [];
405
+ return f.filter((b) => !G.includes(b.key));
406
+ }, m = () => {
407
+ s == null || s.destroy(), s = void 0;
396
408
  };
397
409
  return {
398
- name: s,
399
- install: (d) => {
400
- const a = de(d);
401
- t.value = a, i.value = L(a.getStorage(), o);
410
+ name: l,
411
+ install: (i) => {
412
+ const o = de(i);
413
+ n.value = o, d.value = L(o.getStorage(), t);
402
414
  },
403
415
  pendingSteps: v,
404
- start: (d = {}) => {
405
- const a = g(d);
406
- return a.length ? (u(), n = ie({
407
- steps: a,
416
+ start: (i = {}) => {
417
+ const o = p(i);
418
+ return o.length ? (m(), s = ie({
419
+ steps: o,
408
420
  router: e.router,
409
421
  driverConfig: e.driverConfig,
410
- onStepSeen: (f) => {
411
- var p;
412
- return (p = i.value) == null ? void 0 : p.markSeen(f);
422
+ onStepSeen: (g) => {
423
+ var f;
424
+ return (f = d.value) == null ? void 0 : f.markSeen(g);
413
425
  }
414
426
  }), !0) : !1;
415
427
  },
416
- stop: u,
417
- isSeen: (d) => {
418
- var a;
419
- return ((a = i.value) == null ? void 0 : a.isSeen(d)) ?? !1;
428
+ stop: m,
429
+ isSeen: (i) => {
430
+ var o;
431
+ return ((o = d.value) == null ? void 0 : o.isSeen(i)) ?? !1;
420
432
  },
421
- markSeen: (d) => {
422
- var a;
423
- return (a = i.value) == null ? void 0 : a.markSeen(d);
433
+ markSeen: (i) => {
434
+ var o;
435
+ return (o = d.value) == null ? void 0 : o.markSeen(i);
424
436
  },
425
437
  reset: () => {
426
- var d;
427
- return (d = i.value) == null ? void 0 : d.reset();
438
+ var i;
439
+ return (i = d.value) == null ? void 0 : i.reset();
428
440
  }
429
441
  };
430
442
  };
431
443
  export {
432
- I as GUIDE_PLUGIN_NAME,
444
+ D as GUIDE_PLUGIN_NAME,
433
445
  ge as createGuidePlugin,
434
446
  F as guideBadgeAnchorSelector,
435
447
  j as guideResolveBadgeAnchor
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/forge-plugin-guide",
3
- "version": "0.0.1-alpha.0",
3
+ "version": "0.1.1-alpha.0",
4
4
  "description": "内部前端库",
5
5
  "private": false,
6
6
  "main": "es/index.mjs",
@@ -46,7 +46,7 @@
46
46
  "**/*.less"
47
47
  ],
48
48
  "devDependencies": {
49
- "@done-coding/admin-core": "^0.28.1-alpha.0",
49
+ "@done-coding/admin-core": "^0.29.1-alpha.0",
50
50
  "@done-coding/cli-inject": "0.6.3",
51
51
  "@types/node": "^18.0.0",
52
52
  "@vitejs/plugin-vue": "^5.0.4",
@@ -72,5 +72,5 @@
72
72
  "dependencies": {
73
73
  "driver.js": "^1.8.0"
74
74
  },
75
- "gitHead": "89cee2eb458d349b9a6f2f1acb6088f811cd5e8d"
75
+ "gitHead": "428001dd152178576b5f87445148896efdde98c5"
76
76
  }