@celestia-island/hikari 0.55.442 → 0.55.445
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/package.json +1 -1
- package/src/components/HkAdminShell.tsx +9 -3
- package/src/components/HkDebugFloat.scss +21 -0
- package/src/components/HkDebugFloat.test.tsx +95 -0
- package/src/components/HkDebugFloat.tsx +54 -12
- package/src/components/HkDeleteGateWindow.test.ts +22 -9
- package/src/components/HkThemeToggle.test.ts +5 -2
- package/src/composables/useActionBar.test.ts +303 -0
- package/src/composables/useActionBar.ts +164 -21
- package/src/index.ts +2 -2
package/package.json
CHANGED
|
@@ -28,7 +28,11 @@ export type { PaddingSidesScan } from "./HkFaceShell";
|
|
|
28
28
|
* The one thing the wrapper ADDS is its own action-bar provide: hosts
|
|
29
29
|
* of the pre-extraction contract read the registered actions through
|
|
30
30
|
* the header slot's `actions` param (the bar this shell provides
|
|
31
|
-
* itself).
|
|
31
|
+
* itself). The param keeps its shape — a flat VNode[] of the current
|
|
32
|
+
* registrations — while the bar itself went ranked-additive
|
|
33
|
+
* (PageActionSlot / SLOT_RANK): the array now carries every registered
|
|
34
|
+
* affordance in slot order instead of the last single renderer's
|
|
35
|
+
* output. Faces that own their action bar — or their whole content
|
|
32
36
|
* lifecycle, like a canvas stage — consume HkFaceShell directly and
|
|
33
37
|
* provide whatever they want, closest to their pages.
|
|
34
38
|
*/
|
|
@@ -155,8 +159,10 @@ export const HkAdminShell = defineComponent({
|
|
|
155
159
|
...shellParams,
|
|
156
160
|
// The legacy channel this wrapper exists to keep: the
|
|
157
161
|
// actions of the bar provided above, handed to the header
|
|
158
|
-
// slot exactly as before the extraction
|
|
159
|
-
|
|
162
|
+
// slot exactly as before the extraction — still a flat
|
|
163
|
+
// VNode[] (now one entry per registered affordance, in
|
|
164
|
+
// slot order).
|
|
165
|
+
actions: actionBar.actions.value.flatMap((render) => render()),
|
|
160
166
|
})
|
|
161
167
|
: undefined,
|
|
162
168
|
sidebar: slots.sidebar,
|
|
@@ -46,6 +46,27 @@
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
/* ---------- click-through lock (host-driven `interactive={false}`) ---------- */
|
|
50
|
+
/* The window suspends every pointer affordance of its own — hover yield,
|
|
51
|
+
* drag, close, overlay reveal — and lets pointers fall through to the page
|
|
52
|
+
* it measures. Clicks outside the window already passed through; this makes
|
|
53
|
+
* the window itself pass through too. A subtree the host marks
|
|
54
|
+
* `data-hk-debug-float-pointer` re-enables pointer-events explicitly
|
|
55
|
+
* (descendants may re-enable under a none ancestor), so exactly the host's
|
|
56
|
+
* own unlock control stays live (the wowsp pin button). The locked visual is
|
|
57
|
+
* the host's: its content fades itself (a static lock, not a hover fade). */
|
|
58
|
+
.hk-debug-float[data-interactive="false"] {
|
|
59
|
+
pointer-events: none;
|
|
60
|
+
|
|
61
|
+
& [data-el="fade"] {
|
|
62
|
+
transition: none;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
& [data-hk-debug-float-pointer] {
|
|
66
|
+
pointer-events: auto;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
49
70
|
/* ---------- the card (visual chrome + the hover fade) ---------- */
|
|
50
71
|
.hk-debug-float [data-el="fade"] {
|
|
51
72
|
overflow: hidden;
|
|
@@ -440,6 +440,85 @@ describe("HkDebugFloat headerless chrome", () => {
|
|
|
440
440
|
});
|
|
441
441
|
});
|
|
442
442
|
|
|
443
|
+
describe("HkDebugFloat chrome ownership (closable / interactive)", () => {
|
|
444
|
+
it("drops the header close when closable is false", () => {
|
|
445
|
+
mount(() => h(HkDebugFloat, { closable: false }, () => "fps 60"));
|
|
446
|
+
const win = floatWindow()!;
|
|
447
|
+
expect(win.querySelector(".hk-debug-float-close")).toBeNull();
|
|
448
|
+
// The header itself stays: the title and the drag handle are chrome
|
|
449
|
+
// the host did not ask to surrender.
|
|
450
|
+
expect(win.querySelector("[data-el='header']")).toBeTruthy();
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
it("keeps the header close by default", () => {
|
|
454
|
+
mount(() => h(HkDebugFloat, null, () => "fps 60"));
|
|
455
|
+
expect(
|
|
456
|
+
floatWindow()!.querySelector("[data-el='header'] .hk-debug-float-close"),
|
|
457
|
+
).toBeTruthy();
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
it("drops the headerless close and its empty overlay when closable is false", () => {
|
|
461
|
+
mount(() => h(HkDebugFloat, { chrome: "none", closable: false }, () => "fps 60"));
|
|
462
|
+
const win = floatWindow()!;
|
|
463
|
+
// No close left to hold open → no empty hover chrome box either.
|
|
464
|
+
expect(win.querySelector("[data-el='overlay']")).toBeNull();
|
|
465
|
+
expect(win.querySelector(".hk-debug-float-close")).toBeNull();
|
|
466
|
+
expect(win.getAttribute("data-chrome")).toBe("none");
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
it("keeps the overlay when sections are set, even without a close", () => {
|
|
470
|
+
mount(() =>
|
|
471
|
+
h(HkDebugFloat, {
|
|
472
|
+
chrome: "none",
|
|
473
|
+
closable: false,
|
|
474
|
+
sections: [{ key: "timing", label: "timing" }],
|
|
475
|
+
}),
|
|
476
|
+
);
|
|
477
|
+
const overlay = floatWindow()!.querySelector("[data-el='overlay']");
|
|
478
|
+
expect(overlay).toBeTruthy();
|
|
479
|
+
expect(overlay!.querySelector("button.hk-debug-float-section")).toBeTruthy();
|
|
480
|
+
expect(overlay!.querySelector(".hk-debug-float-close")).toBeNull();
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
it("suspends hover yield and drag while interactive is false", async () => {
|
|
484
|
+
mount(() => h(HkDebugFloat, { chrome: "none", interactive: false }, () => "fps 60"));
|
|
485
|
+
const win = floatWindow()!;
|
|
486
|
+
expect(win.getAttribute("data-interactive")).toBe("");
|
|
487
|
+
dispatchMouse("pointerenter", win);
|
|
488
|
+
await nextTick();
|
|
489
|
+
expect(win.hasAttribute("data-hovered")).toBe(false);
|
|
490
|
+
dispatchMouse("pointerdown", win, { clientX: 100, clientY: 100, button: 0, buttons: 1 });
|
|
491
|
+
await nextTick();
|
|
492
|
+
expect(win.hasAttribute("data-dragging")).toBe(false);
|
|
493
|
+
expect(win.style.left).toBe("");
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
it("drops the yielded state when the lock engages mid-hover", async () => {
|
|
497
|
+
const interactive = ref(true);
|
|
498
|
+
mount(() =>
|
|
499
|
+
h(HkDebugFloat, { chrome: "none", interactive: interactive.value }, () => "fps 60"),
|
|
500
|
+
);
|
|
501
|
+
const win = floatWindow()!;
|
|
502
|
+
dispatchMouse("pointerenter", win);
|
|
503
|
+
await nextTick();
|
|
504
|
+
expect(win.hasAttribute("data-hovered")).toBe(true);
|
|
505
|
+
interactive.value = false;
|
|
506
|
+
await nextTick();
|
|
507
|
+
expect(win.hasAttribute("data-hovered")).toBe(false);
|
|
508
|
+
expect(win.getAttribute("data-interactive")).toBe("");
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
it("keeps a host-marked unlock control addressable while locked", () => {
|
|
512
|
+
mount(() =>
|
|
513
|
+
h(HkDebugFloat, { chrome: "none", interactive: false }, () =>
|
|
514
|
+
h("button", { "data-hk-debug-float-pointer": "", class: "pin" }, "pin"),
|
|
515
|
+
),
|
|
516
|
+
);
|
|
517
|
+
const pin = floatWindow()!.querySelector("button.pin")!;
|
|
518
|
+
expect(pin.hasAttribute("data-hk-debug-float-pointer")).toBe(true);
|
|
519
|
+
});
|
|
520
|
+
});
|
|
521
|
+
|
|
443
522
|
describe("HkDebugFloat width", () => {
|
|
444
523
|
it("marks the auto seat and drops the inline px width", () => {
|
|
445
524
|
mount(() => h(HkDebugFloat, { width: "auto" }));
|
|
@@ -787,6 +866,22 @@ describe("HkDebugFloat stylesheet contract", () => {
|
|
|
787
866
|
);
|
|
788
867
|
});
|
|
789
868
|
|
|
869
|
+
it("locks the window out of the pointer layer when non-interactive", () => {
|
|
870
|
+
// interactive={false}: the whole window stops taking pointers, and a
|
|
871
|
+
// host-marked subtree re-enables hit testing explicitly so exactly
|
|
872
|
+
// one control (the unlock affordance) stays live.
|
|
873
|
+
expect(css).toMatch(
|
|
874
|
+
/\.hk-debug-float\[data-interactive=false\]\s*\{\s*pointer-events:\s*none;/,
|
|
875
|
+
);
|
|
876
|
+
expect(css).toMatch(
|
|
877
|
+
/\.hk-debug-float\[data-interactive=false\] \[data-hk-debug-float-pointer\]\s*\{\s*pointer-events:\s*auto;/,
|
|
878
|
+
);
|
|
879
|
+
// The lock is static — a click-through window has no hover to fade on.
|
|
880
|
+
expect(css).toMatch(
|
|
881
|
+
/\.hk-debug-float\[data-interactive=false\] \[data-el=fade\]\s*\{\s*transition:\s*none;/,
|
|
882
|
+
);
|
|
883
|
+
});
|
|
884
|
+
|
|
790
885
|
it("keeps the hover chrome out of the fading card and click-transparent until revealed", () => {
|
|
791
886
|
// Structure: the overlay is a sibling of the card, never inside it —
|
|
792
887
|
// a nested overlay would fade (and unclickable) with the content.
|
|
@@ -57,7 +57,18 @@
|
|
|
57
57
|
* - **Close (×)** emits `update:open` (v-model:open) and persists the
|
|
58
58
|
* closed state. With `persistKey` set, open-state, dragged position
|
|
59
59
|
* and hidden sections round-trip via localStorage under
|
|
60
|
-
* `hk-debug-float:<key>`; reopening restores them.
|
|
60
|
+
* `hk-debug-float:<key>`; reopening restores them. `closable={false}`
|
|
61
|
+
* drops the in-window close entirely (header × and the headerless
|
|
62
|
+
* hover close) for hosts that own their chrome — the wowsp perf HUD
|
|
63
|
+
* replaces it with a pin control and closes from its own content.
|
|
64
|
+
* - **Click-through lock (`interactive={false}`).** The window suspends
|
|
65
|
+
* every pointer affordance of its own — hover yield, drag, close,
|
|
66
|
+
* overlay reveal — and paints `pointer-events: none`, so pointers
|
|
67
|
+
* fall through to the page it measures. A subtree the host marks
|
|
68
|
+
* `data-hk-debug-float-pointer` keeps `pointer-events: auto`
|
|
69
|
+
* (descendants may re-enable under a none ancestor), so exactly the
|
|
70
|
+
* host's own unlock control stays live — the wowsp pin button. The
|
|
71
|
+
* host owns the locked visual (its content fades itself).
|
|
61
72
|
* - The window intercepts pointers ONLY on its own box (no backdrop,
|
|
62
73
|
* no inset-0 overlay) — clicks outside it always reach the page.
|
|
63
74
|
*/
|
|
@@ -118,6 +129,18 @@ export default defineComponent({
|
|
|
118
129
|
width: { type: [Number, String] as PropType<number | "auto">, default: 280 },
|
|
119
130
|
/** Opacity the window fades to while hovered, 0..1. */
|
|
120
131
|
hoverOpacity: { type: Number, default: 0.45 },
|
|
132
|
+
/** Whether the window renders its own close affordance — the header
|
|
133
|
+
* × or the headerless hover close. Hosts that own their chrome (the
|
|
134
|
+
* wowsp perf HUD replaces it with a pin control) pass false and
|
|
135
|
+
* close through v-model:open themselves. */
|
|
136
|
+
closable: { type: Boolean, default: true },
|
|
137
|
+
/** Interactive pointer mode. When false the window suspends ALL of
|
|
138
|
+
* its own pointer handling — hover yield, drag, close, overlay
|
|
139
|
+
* reveal — and paints pointer-events: none, letting pointers fall
|
|
140
|
+
* through to the page (a click-through HUD lock). Subtrees marked
|
|
141
|
+
* `data-hk-debug-float-pointer` keep pointer-events: auto so the
|
|
142
|
+
* host's own unlock control stays clickable. */
|
|
143
|
+
interactive: { type: Boolean, default: true },
|
|
121
144
|
/** Uncontrolled initial open state (superseded by any persisted one). */
|
|
122
145
|
defaultOpen: { type: Boolean, default: true },
|
|
123
146
|
/** When set: open-state + position (+ hidden sections) persist under
|
|
@@ -243,6 +266,7 @@ export default defineComponent({
|
|
|
243
266
|
function onDragPointerDown(e: PointerEvent): void {
|
|
244
267
|
// Primary button only; interactive chrome (close, section chips,
|
|
245
268
|
// producer content controls) keeps its own pointer semantics.
|
|
269
|
+
if (!props.interactive) return;
|
|
246
270
|
if (e.button !== 0) return;
|
|
247
271
|
if ((e.target as HTMLElement).closest("button, a, input, select, textarea")) return;
|
|
248
272
|
const el = windowEl.value;
|
|
@@ -297,6 +321,8 @@ export default defineComponent({
|
|
|
297
321
|
|
|
298
322
|
// -- hover → yield --
|
|
299
323
|
function onPointerEnter(): void {
|
|
324
|
+
// A locked (click-through) window has no hover affordance.
|
|
325
|
+
if (!props.interactive) return;
|
|
300
326
|
hovered.value = true;
|
|
301
327
|
}
|
|
302
328
|
|
|
@@ -304,6 +330,15 @@ export default defineComponent({
|
|
|
304
330
|
hovered.value = false;
|
|
305
331
|
}
|
|
306
332
|
|
|
333
|
+
// Locking mid-hover must drop the yielded state: the pointer leaves a
|
|
334
|
+
// click-through window without a leave event (it never received one).
|
|
335
|
+
watch(
|
|
336
|
+
() => props.interactive,
|
|
337
|
+
(interactive) => {
|
|
338
|
+
if (!interactive) hovered.value = false;
|
|
339
|
+
},
|
|
340
|
+
);
|
|
341
|
+
|
|
307
342
|
// A restored position clamps once the real box is measurable.
|
|
308
343
|
onMounted(() => {
|
|
309
344
|
void nextTick(reclampToViewport);
|
|
@@ -358,7 +393,11 @@ export default defineComponent({
|
|
|
358
393
|
onPointerup: endDrag,
|
|
359
394
|
onPointercancel: endDrag,
|
|
360
395
|
};
|
|
361
|
-
|
|
396
|
+
// The hover chrome renders only when it has something to hold: the
|
|
397
|
+
// section chips, or (headerless) the close — drop the empty box for
|
|
398
|
+
// a closable={false} HUD that carries no sections.
|
|
399
|
+
const hasSectionChips = (props.sections ?? []).length > 0;
|
|
400
|
+
const showOverlay = hasSectionChips || (!headered && props.closable);
|
|
362
401
|
return (
|
|
363
402
|
// Directly to <body> — NOT into #hk-overlay-root: this window
|
|
364
403
|
// is not a functional popup (no popup-manager band, no scroll
|
|
@@ -370,6 +409,7 @@ export default defineComponent({
|
|
|
370
409
|
class="hk-debug-float"
|
|
371
410
|
data-corner={props.position}
|
|
372
411
|
data-chrome={props.chrome}
|
|
412
|
+
data-interactive={props.interactive ? undefined : ""}
|
|
373
413
|
data-auto-width={props.width === "auto" ? "" : undefined}
|
|
374
414
|
data-hovered={hovered.value ? "" : undefined}
|
|
375
415
|
data-dragging={dragging.value ? "" : undefined}
|
|
@@ -386,15 +426,17 @@ export default defineComponent({
|
|
|
386
426
|
{headered && (
|
|
387
427
|
<div ref={headerEl} data-el="header" {...handleProps}>
|
|
388
428
|
<span data-el="title">{slots.title ? slots.title() : titleText.value}</span>
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
429
|
+
{props.closable && (
|
|
430
|
+
<HIconButton
|
|
431
|
+
class="hk-debug-float-close"
|
|
432
|
+
size={24}
|
|
433
|
+
variant="ghost"
|
|
434
|
+
aria-label={t("hikari::alert.close", "Close")}
|
|
435
|
+
onClick={() => setOpen(false)}
|
|
436
|
+
>
|
|
437
|
+
{{ icon: () => <X aria-hidden="true" /> }}
|
|
438
|
+
</HIconButton>
|
|
439
|
+
)}
|
|
398
440
|
</div>
|
|
399
441
|
)}
|
|
400
442
|
<div data-el="body">
|
|
@@ -432,7 +474,7 @@ export default defineComponent({
|
|
|
432
474
|
</button>
|
|
433
475
|
);
|
|
434
476
|
})}
|
|
435
|
-
{!headered && (
|
|
477
|
+
{!headered && props.closable && (
|
|
436
478
|
<HIconButton
|
|
437
479
|
class="hk-debug-float-close"
|
|
438
480
|
size={24}
|
|
@@ -95,6 +95,8 @@ describe("HkDeleteGateWindow", () => {
|
|
|
95
95
|
// and release: the window must emit confirm (the parent performs the
|
|
96
96
|
// delete) AND close itself (update:open=false). A short release must
|
|
97
97
|
// NOT close — it only emits cancel with the progress.
|
|
98
|
+
confirmSpy.mockClear();
|
|
99
|
+
cancelSpy.mockClear();
|
|
98
100
|
const onUpdate = vi.fn();
|
|
99
101
|
const c = mountWindow("<p>msg</p>", {
|
|
100
102
|
"onUpdate:open": onUpdate,
|
|
@@ -103,22 +105,33 @@ describe("HkDeleteGateWindow", () => {
|
|
|
103
105
|
onCancel: (p: number) => cancelSpy(p),
|
|
104
106
|
});
|
|
105
107
|
const el = c.querySelector(".hk-serpentine")!;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
+
// Fresh event objects per gesture: an Event instance is effectively
|
|
109
|
+
// single-use — re-dispatching the same object is engine-dependent (the
|
|
110
|
+
// CI runner ignores the second dispatch, so the walk below never
|
|
111
|
+
// started there and the confirm assertion saw zero calls).
|
|
112
|
+
const press = (clientX: number, clientY: number) =>
|
|
113
|
+
el.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true, clientX, clientY, pointerId: 1 }));
|
|
114
|
+
const move = (clientX: number, clientY: number) =>
|
|
115
|
+
el.dispatchEvent(new PointerEvent("pointermove", { bubbles: true, clientX, clientY, pointerId: 1 }));
|
|
116
|
+
const release = (clientX: number, clientY: number) =>
|
|
117
|
+
el.dispatchEvent(new PointerEvent("pointerup", { bubbles: true, clientX, clientY, pointerId: 1 }));
|
|
118
|
+
|
|
119
|
+
press(24, 48);
|
|
108
120
|
// Mid-lane release: cancel only.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
el.dispatchEvent(up);
|
|
121
|
+
move(300, 48);
|
|
122
|
+
release(300, 48);
|
|
123
|
+
await nextTick();
|
|
113
124
|
expect(confirmSpy).not.toHaveBeenCalled();
|
|
114
125
|
expect(cancelSpy).toHaveBeenCalled();
|
|
115
126
|
expect(onUpdate).not.toHaveBeenCalled(); // stays open
|
|
116
127
|
// Re-open state is already open; a full walk then confirms and closes.
|
|
117
|
-
|
|
128
|
+
await nextTick();
|
|
129
|
+
press(24, 48);
|
|
118
130
|
for (let x = 30; x <= 600; x += 10) {
|
|
119
|
-
|
|
131
|
+
move(x, 48);
|
|
120
132
|
}
|
|
121
|
-
|
|
133
|
+
release(600, 48);
|
|
134
|
+
await nextTick();
|
|
122
135
|
expect(confirmSpy).toHaveBeenCalledTimes(1);
|
|
123
136
|
expect(onUpdate).toHaveBeenCalledWith(false);
|
|
124
137
|
});
|
|
@@ -230,9 +230,12 @@ describe("HkThemeToggle color-mode group", () => {
|
|
|
230
230
|
expect(cell!.parentElement!.getAttribute("data-slots")).toBe("");
|
|
231
231
|
expect(document.body.querySelector(".hk-tabs-overlay")).toBeNull();
|
|
232
232
|
// The merged Light/Dark triggers leave the radio order entirely —
|
|
233
|
-
// the strip is the single pointer surface while auto is active.
|
|
233
|
+
// the strip is the single pointer surface while auto is active. The
|
|
234
|
+
// swap commits after the transition settles; poll instead of trusting
|
|
235
|
+
// one fixed sleep window (a loaded CI runner still saw the old
|
|
236
|
+
// three-way order when the merge had not landed yet).
|
|
237
|
+
await vi.waitFor(() => expect(modeSegments()).toHaveLength(1));
|
|
234
238
|
const segments = modeSegments();
|
|
235
|
-
expect(segments).toHaveLength(1);
|
|
236
239
|
expect(segments[0].textContent).toContain("Auto");
|
|
237
240
|
expect(segments[0].getAttribute("aria-checked")).toBe("true");
|
|
238
241
|
});
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { createApp, defineComponent, h, nextTick, ref } from "vue";
|
|
2
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
orderActionRegistrations,
|
|
6
|
+
PageActionSlot,
|
|
7
|
+
provideActionBar,
|
|
8
|
+
useActionBar,
|
|
9
|
+
type ActionBarRegistration,
|
|
10
|
+
} from "./useActionBar";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The unified action bar's registration contract, exercised through real
|
|
14
|
+
* mounts (no mock of the module under test; repo convention: raw
|
|
15
|
+
* createApp + container queries, no @vue/test-utils dependency):
|
|
16
|
+
* - a descendant's setActions/setCenter render into the layout's slots;
|
|
17
|
+
* - the registration is per-component-scope — unmounting the registering
|
|
18
|
+
* view clears its registrations so a stale page's refresh button or
|
|
19
|
+
* filter group can never linger under the next page (the property the
|
|
20
|
+
* whole header-chrome design leans on);
|
|
21
|
+
* - canonical slots render by rank regardless of registration order;
|
|
22
|
+
* customs stuff right-to-left (first-registered = rightmost);
|
|
23
|
+
* - the identity guard keeps a leaving view's dispose from wiping the
|
|
24
|
+
* entering view's chrome (the crossfade instant).
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
|
|
28
|
+
|
|
29
|
+
function mountApp(content: () => unknown) {
|
|
30
|
+
const container = document.createElement("div");
|
|
31
|
+
document.body.appendChild(container);
|
|
32
|
+
const app = createApp({ setup: () => content });
|
|
33
|
+
app.mount(container);
|
|
34
|
+
mounts.push({ app, container });
|
|
35
|
+
return container;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
afterEach(() => {
|
|
39
|
+
for (const { app, container } of mounts.splice(0)) {
|
|
40
|
+
app.unmount();
|
|
41
|
+
container.remove();
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
function makeView(tag: string, slot: string) {
|
|
46
|
+
return defineComponent({
|
|
47
|
+
name: `View-${tag}`,
|
|
48
|
+
setup() {
|
|
49
|
+
const bar = useActionBar();
|
|
50
|
+
bar.setActions(() => [h("button", { class: `reg-action reg-${tag}` }, tag)], slot);
|
|
51
|
+
return () => h("div", { class: `view-body view-${tag}` }, "view");
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function makeCenterView(tag: string) {
|
|
57
|
+
return defineComponent({
|
|
58
|
+
name: `CenterView-${tag}`,
|
|
59
|
+
setup() {
|
|
60
|
+
const bar = useActionBar();
|
|
61
|
+
bar.setCenter(() => [h("nav", { class: `reg-center reg-center-${tag}` }, tag)]);
|
|
62
|
+
return () => h("div", { class: `view-body view-${tag}` }, "view");
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function makeLayout(views: () => unknown[]) {
|
|
68
|
+
return defineComponent({
|
|
69
|
+
name: "Layout",
|
|
70
|
+
setup() {
|
|
71
|
+
const bar = provideActionBar();
|
|
72
|
+
return () => [
|
|
73
|
+
h("div", { class: "layout-actions" }, bar.actions.value.flatMap((r) => r())),
|
|
74
|
+
views(),
|
|
75
|
+
h("div", { class: "layout-center" }, bar.center.value?.() ?? []),
|
|
76
|
+
];
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function mountWithViews(views: () => unknown[]) {
|
|
82
|
+
const container = mountApp(() => h(makeLayout(views)));
|
|
83
|
+
await nextTick();
|
|
84
|
+
return container;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function registeredButtons(container: HTMLElement): string[] {
|
|
88
|
+
return Array.from(container.querySelectorAll<HTMLElement>(".layout-actions .reg-action")).map(
|
|
89
|
+
(b) => b.textContent ?? "",
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
describe("useActionBar", () => {
|
|
94
|
+
it("renders a descendant's registered actions and centre group", async () => {
|
|
95
|
+
// Built ONCE outside the render fn — a component created per render
|
|
96
|
+
// remounts (and re-registers) on every layout update, the infinite
|
|
97
|
+
// register/update loop, not the contract under test.
|
|
98
|
+
const view = makeView("refresh", PageActionSlot.Refresh);
|
|
99
|
+
const centerView = makeCenterView("filter");
|
|
100
|
+
const container = await mountWithViews(() => [h(view), h(centerView)]);
|
|
101
|
+
expect(container.querySelector(".layout-actions .reg-action")?.textContent).toBe("refresh");
|
|
102
|
+
expect(container.querySelector(".layout-center .reg-center")?.textContent).toBe("filter");
|
|
103
|
+
// The view body renders too — the probes mirror, never replace.
|
|
104
|
+
expect(container.querySelector(".view-body")).not.toBeNull();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("leaves both slots empty when the view registers nothing", async () => {
|
|
108
|
+
const bare = defineComponent({
|
|
109
|
+
name: "BareView",
|
|
110
|
+
setup: () => () => h("div", { class: "view-body" }, "view"),
|
|
111
|
+
});
|
|
112
|
+
const container = await mountWithViews(() => [h(bare)]);
|
|
113
|
+
expect(container.querySelector(".layout-actions .reg-action")).toBeNull();
|
|
114
|
+
expect(container.querySelector(".layout-center .reg-center")).toBeNull();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("clears the registrations when the registering view unmounts", async () => {
|
|
118
|
+
const show = ref(true);
|
|
119
|
+
// Built ONCE outside the render fn: a component created per render
|
|
120
|
+
// would remount (and re-register) on every layout update — an
|
|
121
|
+
// infinite register/update loop, not the contract under test.
|
|
122
|
+
const view = makeView("refresh", PageActionSlot.Refresh);
|
|
123
|
+
const centerView = makeCenterView("filter");
|
|
124
|
+
const container = await mountWithViews(() =>
|
|
125
|
+
show.value ? [h(view), h(centerView)] : [],
|
|
126
|
+
);
|
|
127
|
+
expect(container.querySelector(".layout-actions .reg-action")).not.toBeNull();
|
|
128
|
+
expect(container.querySelector(".layout-center .reg-center")).not.toBeNull();
|
|
129
|
+
|
|
130
|
+
// The page switches: the view unmounts and its chrome must go with
|
|
131
|
+
// it — both slots, not just the actions.
|
|
132
|
+
show.value = false;
|
|
133
|
+
await nextTick();
|
|
134
|
+
expect(container.querySelector(".layout-actions .reg-action")).toBeNull();
|
|
135
|
+
expect(container.querySelector(".layout-center .reg-center")).toBeNull();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("renders one page's several affordances in SLOT order, not call order", async () => {
|
|
139
|
+
// The composition contract: a page registering its filter trigger
|
|
140
|
+
// and then its refresh gets [filter][refresh] left-to-right — and
|
|
141
|
+
// one that registers refresh first and create last still gets the
|
|
142
|
+
// canonical rank order [create][filter][refresh].
|
|
143
|
+
const view = defineComponent({
|
|
144
|
+
name: "DualView",
|
|
145
|
+
setup() {
|
|
146
|
+
const bar = useActionBar();
|
|
147
|
+
bar.setActions(
|
|
148
|
+
() => [h("button", { class: "reg-action reg-filter" }, "filter")],
|
|
149
|
+
PageActionSlot.Filter,
|
|
150
|
+
);
|
|
151
|
+
bar.setActions(
|
|
152
|
+
() => [h("button", { class: "reg-action reg-refresh" }, "refresh")],
|
|
153
|
+
PageActionSlot.Refresh,
|
|
154
|
+
);
|
|
155
|
+
return () => h("div", { class: "view-body" }, "view");
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
const container = await mountWithViews(() => [h(view)]);
|
|
159
|
+
expect(registeredButtons(container)).toEqual(["filter", "refresh"]);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("places a late-registered create LEFTMOST (rank beats call order)", async () => {
|
|
163
|
+
const view = defineComponent({
|
|
164
|
+
name: "LateCreateView",
|
|
165
|
+
setup() {
|
|
166
|
+
const bar = useActionBar();
|
|
167
|
+
bar.setActions(
|
|
168
|
+
() => [h("button", { class: "reg-action reg-refresh" }, "refresh")],
|
|
169
|
+
PageActionSlot.Refresh,
|
|
170
|
+
);
|
|
171
|
+
bar.setActions(
|
|
172
|
+
() => [h("button", { class: "reg-action reg-create" }, "create")],
|
|
173
|
+
PageActionSlot.Create,
|
|
174
|
+
);
|
|
175
|
+
return () => h("div", { class: "view-body" }, "view");
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
const container = await mountWithViews(() => [h(view)]);
|
|
179
|
+
expect(registeredButtons(container)).toEqual(["create", "refresh"]);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("is a silent no-op outside any layout provider", async () => {
|
|
183
|
+
// Views render in tests (and anywhere without a layout) without a
|
|
184
|
+
// provider: registering must neither throw nor render anything.
|
|
185
|
+
const container = mountApp(() => h(makeView("refresh", PageActionSlot.Refresh)));
|
|
186
|
+
await nextTick();
|
|
187
|
+
expect(container.querySelector(".reg-action")).toBeNull();
|
|
188
|
+
expect(container.querySelector(".view-body")).not.toBeNull();
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("keeps the SURVIVING registration when an overlapped view unmounts (identity guard)", async () => {
|
|
192
|
+
// The crossfade property the whole header design leans on: during a
|
|
193
|
+
// page transition the entering and leaving views are alive at the
|
|
194
|
+
// same instant, so the entering view registers OVER the leaving one
|
|
195
|
+
// and then the leaving one disposes. The per-scope clear must fire
|
|
196
|
+
// only for ITS OWN renderer — an unconditional clear would wipe the
|
|
197
|
+
// entering page's chrome the moment the leaving view unmounts.
|
|
198
|
+
const showA = ref(true);
|
|
199
|
+
const showB = ref(true);
|
|
200
|
+
const viewA = makeView("a", "custom");
|
|
201
|
+
const viewB = makeView("b", "custom");
|
|
202
|
+
const container = await mountWithViews(() => [
|
|
203
|
+
showA.value ? h(viewA) : null,
|
|
204
|
+
showB.value ? h(viewB) : null,
|
|
205
|
+
]);
|
|
206
|
+
// Both alive (the crossfade instant): registrations are ADDITIVE —
|
|
207
|
+
// both pages' buttons render. Both declare the CUSTOM slot, so the
|
|
208
|
+
// stuffing rule orders them right-to-left: first-registered (a) is
|
|
209
|
+
// RIGHTMOST → visual order [b, a].
|
|
210
|
+
expect(registeredButtons(container)).toEqual(["b", "a"]);
|
|
211
|
+
|
|
212
|
+
// The LEAVING view (a — registered first) unmounts after b took
|
|
213
|
+
// over: b's chrome must survive a's disposal (the identity guard —
|
|
214
|
+
// an unconditional clear here wipes the entering page's header).
|
|
215
|
+
showA.value = false;
|
|
216
|
+
await nextTick();
|
|
217
|
+
expect(registeredButtons(container)).toEqual(["b"]);
|
|
218
|
+
|
|
219
|
+
// Then b leaves too: only now does the slot go empty.
|
|
220
|
+
showB.value = false;
|
|
221
|
+
await nextTick();
|
|
222
|
+
expect(registeredButtons(container)).toEqual([]);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it("keeps the SURVIVING centre when an overlapped view unmounts (centre identity guard)", async () => {
|
|
226
|
+
// setCenter's dispose must clear only when ITS OWN renderer is
|
|
227
|
+
// still the current one — a later view's centre must survive the
|
|
228
|
+
// earlier view's unmount.
|
|
229
|
+
const showA = ref(true);
|
|
230
|
+
const showB = ref(true);
|
|
231
|
+
const centerA = makeCenterView("a");
|
|
232
|
+
const centerB = makeCenterView("b");
|
|
233
|
+
const container = await mountWithViews(() => [
|
|
234
|
+
showA.value ? h(centerA) : null,
|
|
235
|
+
showB.value ? h(centerB) : null,
|
|
236
|
+
]);
|
|
237
|
+
// B registered last — B owns the centre slot now.
|
|
238
|
+
expect(container.querySelector(".layout-center .reg-center")?.textContent).toBe("b");
|
|
239
|
+
|
|
240
|
+
showA.value = false;
|
|
241
|
+
await nextTick();
|
|
242
|
+
expect(container.querySelector(".layout-center .reg-center")?.textContent).toBe("b");
|
|
243
|
+
|
|
244
|
+
showB.value = false;
|
|
245
|
+
await nextTick();
|
|
246
|
+
expect(container.querySelector(".layout-center .reg-center")).toBeNull();
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
describe("orderActionRegistrations (slot ranks + right-to-left customs)", () => {
|
|
251
|
+
function reg(slot: string, seq: number): ActionBarRegistration {
|
|
252
|
+
return { renderer: () => [], slot, seq };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
it("orders the canonical slots by rank regardless of registration order", () => {
|
|
256
|
+
const out = orderActionRegistrations([
|
|
257
|
+
reg("refresh", 0),
|
|
258
|
+
reg("custom-x", 1),
|
|
259
|
+
reg("filter", 2),
|
|
260
|
+
reg("create", 3),
|
|
261
|
+
]);
|
|
262
|
+
expect(out.map((r) => r.slot)).toEqual(["create", "filter", "refresh", "custom-x"]);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it("ranks the window slot right of the refresh, left of customs", () => {
|
|
266
|
+
// The secondary-window opener is canonical:
|
|
267
|
+
// [create][filter][search][refresh][window] — regardless of the
|
|
268
|
+
// order the page registered them in.
|
|
269
|
+
const out = orderActionRegistrations([
|
|
270
|
+
reg("window", 0),
|
|
271
|
+
reg("refresh", 1),
|
|
272
|
+
reg("search", 2),
|
|
273
|
+
reg("custom-x", 3),
|
|
274
|
+
reg("filter", 4),
|
|
275
|
+
reg("create", 5),
|
|
276
|
+
]);
|
|
277
|
+
expect(out.map((r) => r.slot)).toEqual([
|
|
278
|
+
"create",
|
|
279
|
+
"filter",
|
|
280
|
+
"search",
|
|
281
|
+
"refresh",
|
|
282
|
+
"window",
|
|
283
|
+
"custom-x",
|
|
284
|
+
]);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it("stuffs customs right-to-left: the FIRST-registered custom is rightmost", () => {
|
|
288
|
+
// The customs zone grows LEFTWARD (user rule 2026-10-11): the right
|
|
289
|
+
// edge takes the first arrival, later customs land to its left.
|
|
290
|
+
const out = orderActionRegistrations([
|
|
291
|
+
reg("create", 0),
|
|
292
|
+
reg("first", 1),
|
|
293
|
+
reg("second", 2),
|
|
294
|
+
reg("third", 3),
|
|
295
|
+
]);
|
|
296
|
+
expect(out.map((r) => r.slot)).toEqual(["create", "third", "second", "first"]);
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it("keeps same-slot registrations stable by sequence", () => {
|
|
300
|
+
const out = orderActionRegistrations([reg("create", 5), reg("create", 2)]);
|
|
301
|
+
expect(out.map((r) => r.seq)).toEqual([2, 5]);
|
|
302
|
+
});
|
|
303
|
+
});
|
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
import { inject, onScopeDispose, provide, ref, type VNode } from "vue";
|
|
1
|
+
import { computed, inject, onScopeDispose, provide, ref, type Ref, type VNode } from "vue";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Unified page action bar.
|
|
5
5
|
*
|
|
6
|
-
* A layout (`
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* A layout (`HkAdminShell`) calls `provideActionBar()` once and renders
|
|
7
|
+
* `actions.value` (top-right buttons) and `center.value` (the header
|
|
8
|
+
* centre group) in its header. Any descendant view then registers its own
|
|
9
|
+
* top-bar buttons (filter trigger, refresh, add, search, …) via
|
|
10
|
+
* `useActionBar().setActions(() => [...], slot)` in its setup — the header
|
|
11
|
+
* updates reactively. Registrations are ADDITIVE and render in SLOT order:
|
|
12
|
+
* a page that registers its filter trigger and then its refresh still gets
|
|
13
|
+
* [filter][refresh] left-to-right in the header (the user direction:
|
|
14
|
+
* 筛选在刷新左边;没有刷新就在主题按钮左边).
|
|
11
15
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
16
|
+
* **Slot ordering (2026-10-11 standardization)**: registrations declare
|
|
17
|
+
* their PURPOSE slot; the cluster renders canonical slots by rank
|
|
18
|
+
* ([create][filter][search][refresh][window]) and customs after them,
|
|
19
|
+
* stuffed right-to-left in join order — see PageActionSlot below. The
|
|
20
|
+
* registration CALL ORDER no longer influences the cluster. The grammar's
|
|
21
|
+
* normative home (slot order, ranks, exempt edges) is the design doc
|
|
22
|
+
* `design/page-chrome.md` (nine locales); the rank table below is its
|
|
23
|
+
* runtime mirror.
|
|
17
24
|
*
|
|
18
25
|
* **Why a render function, not VNodes?** VNodes are single-use: once Vue
|
|
19
26
|
* patches them into the DOM, re-using the same VNode object on the next
|
|
@@ -21,19 +28,125 @@ import { inject, onScopeDispose, provide, ref, type VNode } from "vue";
|
|
|
21
28
|
* the first time but not after a re-render). Storing a function that returns
|
|
22
29
|
* fresh VNodes ensures each render cycle gets a clean set with intact
|
|
23
30
|
* event handlers.
|
|
31
|
+
*
|
|
32
|
+
* **The centre slot** (2026-09-28): the second header zone pages can own —
|
|
33
|
+
* a filter / mode button group rendered in the header's true centre, the
|
|
34
|
+
* console face of the chat frontend's top-centre tab strip (报告审阅 /
|
|
35
|
+
* 节点概览 / 历史记录). Same registration contract, same per-scope
|
|
36
|
+
* lifetime: a view whose filter is a small closed enum renders it there
|
|
37
|
+
* (HkTabs segmented) instead of a filter card inside the page body.
|
|
38
|
+
*
|
|
39
|
+
* Readout-style header zones (a left-wing HUD cluster) are host-side
|
|
40
|
+
* extensions, not part of this contract: this module exposes only the
|
|
41
|
+
* right cluster and the centre slot.
|
|
24
42
|
*/
|
|
25
43
|
|
|
26
44
|
/** A function that produces fresh VNodes for the action bar on each render. */
|
|
27
45
|
export type ActionBarRenderer = () => VNode[];
|
|
28
46
|
|
|
47
|
+
/**
|
|
48
|
+
* The canonical top-right cluster slots (2026-10-11 standardization, user
|
|
49
|
+
* direction): every button declares its PURPOSE, and the cluster renders
|
|
50
|
+
* by the slot's canonical rank — [create][filter][search][refresh][window]
|
|
51
|
+
* — regardless of registration order. A button whose purpose is not in
|
|
52
|
+
* the enum is a CUSTOM slot: customs ride AFTER the canonical ranks,
|
|
53
|
+
* stuffed 由右往左 — the zone's right edge (adjacent to the global
|
|
54
|
+
* search) takes the FIRST-registered custom, the next one lands to its
|
|
55
|
+
* LEFT — so the enum zone never gets displaced and customs never
|
|
56
|
+
* interleave with it.
|
|
57
|
+
*
|
|
58
|
+
* Adding a canonical purpose = add the key here AND its rank in
|
|
59
|
+
* SLOT_RANK below (one place, test-pinned); everything else registers as
|
|
60
|
+
* its own custom slot string and inherits the stuffing rule.
|
|
61
|
+
*/
|
|
62
|
+
export const PageActionSlot = {
|
|
63
|
+
/** The page's primary create action (the plus). */
|
|
64
|
+
Create: "create",
|
|
65
|
+
/** The page's filter trigger. */
|
|
66
|
+
Filter: "filter",
|
|
67
|
+
/** The page's search trigger (the list scaffold's keyword panel;
|
|
68
|
+
* canonical since the scaffold landed — the old per-page
|
|
69
|
+
* "Search = refetch" buttons rode custom slots). */
|
|
70
|
+
Search: "search",
|
|
71
|
+
/** The page's refresh. */
|
|
72
|
+
Refresh: "refresh",
|
|
73
|
+
/** A page's secondary-window opener (2026-11-04 user direction): an
|
|
74
|
+
* icon button that opens a window/panel holding dynamic content the
|
|
75
|
+
* page must NOT expand inline (凭据、部署助手等一切动态内容都收下一级
|
|
76
|
+
* 的窗口内). The window itself stays the page's own (HkAdaptiveDialog);
|
|
77
|
+
* only the OPENING affordance is header chrome. */
|
|
78
|
+
Window: "window",
|
|
79
|
+
} as const;
|
|
80
|
+
export type PageActionSlotValue = (typeof PageActionSlot)[keyof typeof PageActionSlot];
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Canonical ranks — lower renders further LEFT. This is the ONE ranking
|
|
84
|
+
* table (runtime mirror of the page-chrome grammar). Deliberately NOT
|
|
85
|
+
* exported: consumers order through `orderActionRegistrations` and pin
|
|
86
|
+
* the order in tests, so adding a canonical purpose stays a two-line
|
|
87
|
+
* change (key above + rank here) with the test suite as the tripwire.
|
|
88
|
+
*/
|
|
89
|
+
const SLOT_RANK: Record<string, number> = {
|
|
90
|
+
[PageActionSlot.Create]: 0,
|
|
91
|
+
[PageActionSlot.Filter]: 1,
|
|
92
|
+
[PageActionSlot.Search]: 2,
|
|
93
|
+
[PageActionSlot.Refresh]: 3,
|
|
94
|
+
[PageActionSlot.Window]: 4,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/** A setActions registration: the renderer plus its declared slot. */
|
|
98
|
+
export interface ActionBarRegistration {
|
|
99
|
+
renderer: ActionBarRenderer;
|
|
100
|
+
/** The button's purpose — a canonical PageActionSlot or a custom
|
|
101
|
+
* string; REQUIRED for every registration (the ordering key). */
|
|
102
|
+
slot: string;
|
|
103
|
+
/** Registration sequence (disambiguates same-slot entries). */
|
|
104
|
+
seq: number;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Sort registrations into render order: canonical slots by rank; customs
|
|
109
|
+
* after them, stuffed right-to-left (first-registered = rightmost, so
|
|
110
|
+
* the customs zone grows LEFTWARD — reverse registration order).
|
|
111
|
+
* Exported pure for the unit pin.
|
|
112
|
+
*/
|
|
113
|
+
export function orderActionRegistrations(regs: ActionBarRegistration[]): ActionBarRegistration[] {
|
|
114
|
+
const canonical = regs
|
|
115
|
+
.filter((r) => r.slot in SLOT_RANK)
|
|
116
|
+
.sort((a, b) => SLOT_RANK[a.slot] - SLOT_RANK[b.slot] || a.seq - b.seq);
|
|
117
|
+
const customs = regs.filter((r) => !(r.slot in SLOT_RANK)).sort((a, b) => b.seq - a.seq);
|
|
118
|
+
return [...canonical, ...customs];
|
|
119
|
+
}
|
|
120
|
+
|
|
29
121
|
interface ActionBarContext {
|
|
30
|
-
|
|
122
|
+
/** Every registered top-right entry (renderer + declared slot); the
|
|
123
|
+
* public `actions` computed serves them in SLOT order — a page may
|
|
124
|
+
* own SEVERAL (create, filter trigger, refresh, customs), and the
|
|
125
|
+
* order no longer depends on the composable call sequence. */
|
|
126
|
+
actionRegistrations: Ref<ActionBarRegistration[]>;
|
|
127
|
+
/** Per-PROVIDER registration sequence — one counter for every scope
|
|
128
|
+
* sharing this bar, so cross-component customs tie on nothing (the
|
|
129
|
+
* stuffing rule's seq comparison must be globally monotonic). */
|
|
130
|
+
nextSeq: () => number;
|
|
131
|
+
/** Ordered renderers (what the header renders) — derived. */
|
|
132
|
+
actions: Ref<ActionBarRenderer[]>;
|
|
133
|
+
center: Ref<ActionBarRenderer | null>;
|
|
31
134
|
}
|
|
32
135
|
|
|
33
136
|
const KEY = Symbol("action-bar");
|
|
34
137
|
|
|
35
138
|
export function provideActionBar() {
|
|
36
|
-
const
|
|
139
|
+
const actionRegistrations = ref<ActionBarRegistration[]>([]);
|
|
140
|
+
let seqCounter = 0;
|
|
141
|
+
const nextSeq = () => seqCounter++;
|
|
142
|
+
const ctx: ActionBarContext = {
|
|
143
|
+
actionRegistrations,
|
|
144
|
+
nextSeq,
|
|
145
|
+
actions: computed(() =>
|
|
146
|
+
orderActionRegistrations(actionRegistrations.value).map((r) => r.renderer),
|
|
147
|
+
),
|
|
148
|
+
center: ref<ActionBarRenderer | null>(null),
|
|
149
|
+
};
|
|
37
150
|
provide(KEY, ctx);
|
|
38
151
|
return ctx;
|
|
39
152
|
}
|
|
@@ -41,26 +154,56 @@ export function provideActionBar() {
|
|
|
41
154
|
export function useActionBar() {
|
|
42
155
|
const ctx = inject<ActionBarContext | null>(KEY, null);
|
|
43
156
|
if (!ctx) {
|
|
44
|
-
// No provider (e.g. outside any layout) —
|
|
157
|
+
// No provider (e.g. outside any layout) — inert refs keep the
|
|
158
|
+
// return type uniform (consumers read `actions.value` without
|
|
159
|
+
// null-narrowing), while the setters stay silent no-ops.
|
|
45
160
|
return {
|
|
46
|
-
setActions: (_renderer: ActionBarRenderer) => {},
|
|
161
|
+
setActions: (_renderer: ActionBarRenderer, _slot: string) => {},
|
|
47
162
|
clearActions: () => {},
|
|
163
|
+
actions: ref<ActionBarRenderer[]>([]),
|
|
164
|
+
setCenter: (_renderer: ActionBarRenderer) => {},
|
|
165
|
+
clearCenter: () => {},
|
|
166
|
+
center: ref<ActionBarRenderer | null>(null),
|
|
48
167
|
};
|
|
49
168
|
}
|
|
50
169
|
return {
|
|
51
|
-
setActions: (renderer: ActionBarRenderer) => {
|
|
52
|
-
|
|
170
|
+
setActions: (renderer: ActionBarRenderer, slot: string) => {
|
|
171
|
+
// ADDITIVE registration: a page composes several buttons (create,
|
|
172
|
+
// filter trigger, refresh, customs) by calling this once per
|
|
173
|
+
// affordance, each declaring its PURPOSE slot — the cluster's
|
|
174
|
+
// render order comes from the slot ranks, never the call
|
|
175
|
+
// sequence. The identity guard keeps the dispose of one
|
|
176
|
+
// registration (a crossfade overlap, an unmount) from clearing
|
|
177
|
+
// its siblings.
|
|
178
|
+
if (!ctx.actionRegistrations.value.some((r) => r.renderer === renderer)) {
|
|
179
|
+
ctx.actionRegistrations.value = [
|
|
180
|
+
...ctx.actionRegistrations.value,
|
|
181
|
+
{ renderer, slot, seq: ctx.nextSeq() },
|
|
182
|
+
];
|
|
183
|
+
}
|
|
53
184
|
// Auto-clear when this view's effect scope dies so buttons never
|
|
54
185
|
// outlive the page that registered them.
|
|
55
186
|
onScopeDispose(() => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
187
|
+
ctx.actionRegistrations.value = ctx.actionRegistrations.value.filter(
|
|
188
|
+
(r) => r.renderer !== renderer,
|
|
189
|
+
);
|
|
59
190
|
});
|
|
60
191
|
},
|
|
61
192
|
clearActions: () => {
|
|
62
|
-
ctx.
|
|
193
|
+
ctx.actionRegistrations.value = [];
|
|
63
194
|
},
|
|
64
195
|
actions: ctx.actions,
|
|
196
|
+
setCenter: (renderer: ActionBarRenderer) => {
|
|
197
|
+
ctx.center.value = renderer;
|
|
198
|
+
onScopeDispose(() => {
|
|
199
|
+
if (ctx.center.value === renderer) {
|
|
200
|
+
ctx.center.value = null;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
},
|
|
204
|
+
clearCenter: () => {
|
|
205
|
+
ctx.center.value = null;
|
|
206
|
+
},
|
|
207
|
+
center: ctx.center,
|
|
65
208
|
};
|
|
66
209
|
}
|
package/src/index.ts
CHANGED
|
@@ -679,8 +679,8 @@ export {
|
|
|
679
679
|
type HkMfaFactor as MfaFactor,
|
|
680
680
|
} from "./components/HkMfaVerifyCard";
|
|
681
681
|
export { usePageTitle, useRouteTitle } from "./composables/usePageTitle";
|
|
682
|
-
export { provideActionBar, useActionBar } from "./composables/useActionBar";
|
|
683
|
-
export type { ActionBarRenderer } from "./composables/useActionBar";
|
|
682
|
+
export { provideActionBar, useActionBar, PageActionSlot, orderActionRegistrations } from "./composables/useActionBar";
|
|
683
|
+
export type { ActionBarRenderer, PageActionSlotValue, ActionBarRegistration } from "./composables/useActionBar";
|
|
684
684
|
export { useChromeActionSize } from "./composables/useChromeActionSize";
|
|
685
685
|
export { leadingZeroBits, sha256, solvePow, solvePowSync, verifyPow } from "./utils/pow";
|
|
686
686
|
export type { PowChallenge, PowSolution } from "./utils/pow";
|