@celestia-island/hikari 0.55.438 → 0.55.440
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/HkAdminHeader.test.tsx +76 -1
- package/src/components/HkAdminHeader.tsx +73 -13
- package/src/components/HkAffixPicker.scss +13 -0
- package/src/components/HkAffixPicker.test.tsx +79 -1
- package/src/components/HkAffixPicker.tsx +37 -0
- package/src/components/HkDeleteFact.scss +25 -0
- package/src/components/HkDeleteFact.tsx +28 -0
- package/src/components/HkDeleteGateWindow.scss +9 -0
- package/src/components/HkDeleteGateWindow.test.ts +133 -0
- package/src/components/HkDeleteGateWindow.tsx +89 -0
- package/src/components/HkFaceShell.slots.test.ts +28 -1
- package/src/components/HkSerpentineUnlock.tsx +26 -1
- package/src/components/serpentineGeometry.test.ts +21 -0
- package/src/components/serpentineGeometry.ts +41 -7
- package/src/index.ts +3 -1
package/package.json
CHANGED
|
@@ -53,7 +53,11 @@ vi.mock("./HkMenu", async () => {
|
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
55
|
flatten(props.items);
|
|
56
|
-
return h("div", { class: "menu-stub" }, [
|
|
56
|
+
return h("div", { class: "menu-stub" }, [
|
|
57
|
+
...(slots.header?.() ?? []),
|
|
58
|
+
...rows,
|
|
59
|
+
...(slots.footer?.() ?? []),
|
|
60
|
+
]);
|
|
57
61
|
};
|
|
58
62
|
},
|
|
59
63
|
});
|
|
@@ -356,3 +360,74 @@ describe("HkAdminHeader chrome face drag region (2026-11-12)", () => {
|
|
|
356
360
|
expect(c.querySelector("header")!.hasAttribute("data-tauri-drag-region")).toBe(false);
|
|
357
361
|
});
|
|
358
362
|
});
|
|
363
|
+
|
|
364
|
+
describe("HkAdminHeader host slots (L39 ruling-a revival)", () => {
|
|
365
|
+
const LOCALES = [
|
|
366
|
+
{ code: "en", label: "English" },
|
|
367
|
+
{ code: "zh-Hans", label: "简体中文" },
|
|
368
|
+
];
|
|
369
|
+
|
|
370
|
+
async function openMenu(c: HTMLElement) {
|
|
371
|
+
await click(avatarButton(c));
|
|
372
|
+
return c.querySelector(".menu-stub") as HTMLElement | null;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
it("renders user-menu-extra rows in the dropdown tail and close() dismisses the menu", async () => {
|
|
376
|
+
const c = mount(
|
|
377
|
+
headerNode({ logoutLabel: "Log out" }, {
|
|
378
|
+
"user-menu-extra": ({ close }: { close?: () => void }) =>
|
|
379
|
+
h("button", { class: "menu-stub-row extra-row", onClick: () => close?.() }, "Account center"),
|
|
380
|
+
}),
|
|
381
|
+
);
|
|
382
|
+
const menu = await openMenu(c);
|
|
383
|
+
// The host row rides AFTER the built-in rows (tail), inside the menu.
|
|
384
|
+
const rows = menuRows(c);
|
|
385
|
+
expect(rows[rows.length - 1].textContent).toBe("Account center");
|
|
386
|
+
// close() dismisses the dropdown — a navigating entry leaves no
|
|
387
|
+
// orphaned menu behind.
|
|
388
|
+
await click(rows[rows.length - 1]);
|
|
389
|
+
expect(c.querySelector(".menu-stub")).toBeNull();
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it("renders the locale-picker popup when the Language row is selected", async () => {
|
|
393
|
+
const c = mount(
|
|
394
|
+
headerNode(
|
|
395
|
+
{ localeOptions: LOCALES, localeMenuLabel: "Language" },
|
|
396
|
+
{
|
|
397
|
+
"locale-picker": ({ open }: { open: boolean }) =>
|
|
398
|
+
h("div", { class: "locale-popup", "data-open": String(open) }, "picker"),
|
|
399
|
+
},
|
|
400
|
+
),
|
|
401
|
+
);
|
|
402
|
+
// Popup starts closed.
|
|
403
|
+
expect(c.querySelector(".locale-popup")?.getAttribute("data-open")).toBe("false");
|
|
404
|
+
const menu = await openMenu(c);
|
|
405
|
+
// Slot mode: the Language row is a leaf (no built-in cascade rows).
|
|
406
|
+
expect(menu!.querySelector('[data-key="locale:en"]')).toBeNull();
|
|
407
|
+
expect(menu!.querySelector('[data-key="locale:zh-Hans"]')).toBeNull();
|
|
408
|
+
await click(menu!.querySelector('[data-key="locale"]'));
|
|
409
|
+
// Selecting the Language row opens the host popup (the payload's
|
|
410
|
+
// open flips true; the real assertion is the rendered data-open).
|
|
411
|
+
expect(c.querySelector(".locale-popup")?.getAttribute("data-open")).toBe("true");
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
it("keeps the built-in cascade when no locale-picker slot is supplied", async () => {
|
|
415
|
+
// NEGATIVE CONTROL (hosts like chest pass localeOptions and nothing
|
|
416
|
+
// else): the Language row keeps its built-in children exactly as
|
|
417
|
+
// before the revival.
|
|
418
|
+
const c = mount(headerNode({ localeOptions: LOCALES, localeMenuLabel: "Language" }));
|
|
419
|
+
const menu = await openMenu(c);
|
|
420
|
+
expect(menu!.querySelector('[data-key="locale:en"]')).not.toBeNull();
|
|
421
|
+
expect(menu!.querySelector('[data-key="locale:zh-Hans"]')).not.toBeNull();
|
|
422
|
+
expect(menu!.querySelector('[data-key="locale"]')).not.toBeNull();
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
it("renders neither host surface when neither slot is supplied", () => {
|
|
426
|
+
// NEGATIVE CONTROL: existing hosts (chest-shaped) see zero change —
|
|
427
|
+
// no tail rows, no popup mount, the exact DOM they always had.
|
|
428
|
+
const c = mount(headerNode({ localeOptions: LOCALES }));
|
|
429
|
+
expect(c.querySelector(".menu-stub")).toBeNull();
|
|
430
|
+
expect(c.querySelector(".locale-popup")).toBeNull();
|
|
431
|
+
expect(c.textContent).not.toContain("Account center");
|
|
432
|
+
});
|
|
433
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, defineComponent, ref, watch, type PropType, type SlotsType, type VNode } from "vue";
|
|
1
|
+
import { computed, defineComponent, ref, watch, type PropType, type Ref, type SlotsType, type VNode } from "vue";
|
|
2
2
|
import { Camera, ExternalLink, Languages, LogOut, Menu } from "lucide-vue-next";
|
|
3
3
|
import { HBadge, HButton, HSpinner } from "@celestia-island/hikari";
|
|
4
4
|
import { useI18n } from "../i18n/context";
|
|
@@ -21,17 +21,40 @@ export interface HkAdminHeaderAvatarModalSlot {
|
|
|
21
21
|
onUpdateOpen: (value: boolean) => void;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Scoped payload of the `user-menu-extra` slot — host-owned rows the
|
|
26
|
+
* header appends to the user dropdown's TAIL (above nothing, below every
|
|
27
|
+
* built-in row). `close` dismisses the dropdown so a navigating entry
|
|
28
|
+
* (account center, …) leaves no orphaned menu behind. Mirrors the erp-side
|
|
29
|
+
* `AdminHeaderUserMenuExtraSlot` contract verbatim (L39 ruling a: the slot
|
|
30
|
+
* is consumed since this header grew the wiring).
|
|
31
|
+
*/
|
|
32
|
+
export interface HkAdminHeaderUserMenuExtraSlot {
|
|
33
|
+
close?: () => void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Scoped payload of the `locale-picker` slot — the host-owned locale
|
|
38
|
+
* popup. When the slot is supplied, the menu's Language row becomes a
|
|
39
|
+
* plain trigger for this popup (the built-in children cascade stands
|
|
40
|
+
* down); `triggerRef` anchors the popup to the avatar trigger so it
|
|
41
|
+
* opens where the menu was. Mirrors the erp-side
|
|
42
|
+
* `AdminHeaderLocalePickerSlot` contract verbatim.
|
|
43
|
+
*/
|
|
44
|
+
export interface HkAdminHeaderLocalePickerSlot {
|
|
45
|
+
open: boolean;
|
|
46
|
+
onUpdateOpen: (value: boolean) => void;
|
|
47
|
+
triggerRef: Ref<HTMLElement | null> | HTMLElement | null;
|
|
48
|
+
}
|
|
49
|
+
|
|
24
50
|
/**
|
|
25
51
|
* The header's whole slot surface, in `SlotsType` form. `identity`,
|
|
26
52
|
* `center`, `emergency-stop-extra` and `theme-toggle` take no params.
|
|
27
53
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* (reviving erp's invisible account-center menu entries) or erp should delete
|
|
33
|
-
* the dead bodies is ⏳ pending a user decision; until then neither name may
|
|
34
|
-
* appear in this aggregate.
|
|
54
|
+
* `user-menu-extra` (rows appended to the dropdown tail) and
|
|
55
|
+
* `locale-picker` (host locale popup replacing the built-in cascade) were
|
|
56
|
+
* consumed as of the L39 ruling-a revival (2026-11-20): the erp bodies
|
|
57
|
+
* that had sat invisible since 0.55.241 now render.
|
|
35
58
|
*/
|
|
36
59
|
export type HkAdminHeaderSlots = SlotsType<{
|
|
37
60
|
identity?: () => VNode[];
|
|
@@ -39,6 +62,8 @@ export type HkAdminHeaderSlots = SlotsType<{
|
|
|
39
62
|
"emergency-stop-extra"?: () => VNode[];
|
|
40
63
|
"theme-toggle"?: () => VNode[];
|
|
41
64
|
"avatar-modal"?: (params: HkAdminHeaderAvatarModalSlot) => VNode[];
|
|
65
|
+
"user-menu-extra"?: (params: HkAdminHeaderUserMenuExtraSlot) => VNode[];
|
|
66
|
+
"locale-picker"?: (params: HkAdminHeaderLocalePickerSlot) => VNode[];
|
|
42
67
|
}>;
|
|
43
68
|
|
|
44
69
|
export const HkAdminHeader = defineComponent({
|
|
@@ -132,6 +157,11 @@ export const HkAdminHeader = defineComponent({
|
|
|
132
157
|
const userMenuOpen = ref(false);
|
|
133
158
|
const userTriggerRef = ref<HTMLElement>();
|
|
134
159
|
const avatarModalOpen = ref(false);
|
|
160
|
+
// The host-owned locale popup's open state (L39 ruling a): when the
|
|
161
|
+
// `locale-picker` slot is supplied, the menu's Language row triggers
|
|
162
|
+
// THIS popup instead of the built-in children cascade — anchored to
|
|
163
|
+
// the avatar trigger, so the popup opens exactly where the menu was.
|
|
164
|
+
const localePickerOpen = ref(false);
|
|
135
165
|
// The DROPDOWN identity image's own failed-load latch, with the same
|
|
136
166
|
// URL-change reset the trigger's latch has inside HkAvatarButton —
|
|
137
167
|
// an avatar re-upload or account switch must heal BOTH faces (R2's
|
|
@@ -197,11 +227,19 @@ export const HkAdminHeader = defineComponent({
|
|
|
197
227
|
key: "locale",
|
|
198
228
|
label: props.localeMenuLabel ?? t("hikari::adminHeader.language", "Language"),
|
|
199
229
|
icon: Languages,
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
230
|
+
// A host-supplied `locale-picker` slot turns this row into a
|
|
231
|
+
// plain trigger for the host popup — the built-in cascade
|
|
232
|
+
// stands down (two locale surfaces in one menu would read as
|
|
233
|
+
// duplicated controls). Select routing is in onUserMenuSelect.
|
|
234
|
+
...(slots["locale-picker"]
|
|
235
|
+
? {}
|
|
236
|
+
: {
|
|
237
|
+
children: props.localeOptions.map((o) => ({
|
|
238
|
+
key: `locale:${o.code}`,
|
|
239
|
+
label: o.label,
|
|
240
|
+
checked: o.code === props.currentLocale,
|
|
241
|
+
})),
|
|
242
|
+
}),
|
|
205
243
|
});
|
|
206
244
|
}
|
|
207
245
|
// Frontend link — mirrors the drawer user panel's "go to frontend"
|
|
@@ -224,6 +262,10 @@ export const HkAdminHeader = defineComponent({
|
|
|
224
262
|
function onUserMenuSelect(key: string) {
|
|
225
263
|
if (key === "avatar") {
|
|
226
264
|
avatarModalOpen.value = true;
|
|
265
|
+
} else if (key === "locale" && slots["locale-picker"]) {
|
|
266
|
+
// Host-popup mode: the menu closes around the select (HkMenu's
|
|
267
|
+
// own behaviour) and the popup takes over the anchor's spot.
|
|
268
|
+
localePickerOpen.value = true;
|
|
227
269
|
} else if (key.startsWith("locale:")) {
|
|
228
270
|
emit("localeSelect", key.slice("locale:".length));
|
|
229
271
|
} else if (key === "go-to-frontend") {
|
|
@@ -377,6 +419,14 @@ export const HkAdminHeader = defineComponent({
|
|
|
377
419
|
</div>
|
|
378
420
|
)
|
|
379
421
|
),
|
|
422
|
+
/* Host-owned tail rows (L39 ruling a): appended AFTER every
|
|
423
|
+
* built-in row — the account-center / change-password entries
|
|
424
|
+
* erp has been passing since 0.55.241. `close` dismisses the
|
|
425
|
+
* dropdown so a navigating entry leaves no orphaned menu. */
|
|
426
|
+
footer: () =>
|
|
427
|
+
slots["user-menu-extra"]?.({
|
|
428
|
+
close: () => { userMenuOpen.value = false; },
|
|
429
|
+
}) ?? [],
|
|
380
430
|
}}
|
|
381
431
|
</HkMenu>
|
|
382
432
|
|
|
@@ -427,6 +477,16 @@ export const HkAdminHeader = defineComponent({
|
|
|
427
477
|
open: avatarModalOpen.value,
|
|
428
478
|
onUpdateOpen: (v: boolean) => { avatarModalOpen.value = v; },
|
|
429
479
|
})}
|
|
480
|
+
|
|
481
|
+
{/* Host-owned locale popup (L39 ruling a): the Language row's
|
|
482
|
+
* trigger target. Anchored to the avatar trigger — the popup
|
|
483
|
+
* opens where the dropdown was, so the handoff reads as the
|
|
484
|
+
* menu sliding into a picker rather than a second surface. */}
|
|
485
|
+
{slots["locale-picker"]?.({
|
|
486
|
+
open: localePickerOpen.value,
|
|
487
|
+
onUpdateOpen: (v: boolean) => { localePickerOpen.value = v; },
|
|
488
|
+
triggerRef: userTriggerRef.value ?? null,
|
|
489
|
+
})}
|
|
430
490
|
</header>
|
|
431
491
|
);
|
|
432
492
|
},
|
|
@@ -288,6 +288,19 @@
|
|
|
288
288
|
sans-serif;
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
+
/* The standard leading capsule (HkAffixOption.badge): the HBadge base
|
|
292
|
+
* owns every visual channel (primary wash, mono face, squared pill,
|
|
293
|
+
* tabular-friendly padding) — here it only opts out of the flex
|
|
294
|
+
* shrink/grow axes: `none` keeps the capsule from growing into the
|
|
295
|
+
* label's room (and from shrinking under it), so the emoji `flag` and
|
|
296
|
+
* the label keep their natural widths around it.
|
|
297
|
+
* The gap to the label is the row grammar's own --hk-menu-item-gap
|
|
298
|
+
* (8px desktop / sheet inherits), so hosts never hand-tune spacing. */
|
|
299
|
+
.hk-affix-row-badge,
|
|
300
|
+
.hk-affix-tag-badge {
|
|
301
|
+
flex: none;
|
|
302
|
+
}
|
|
303
|
+
|
|
291
304
|
.hk-affix-row-label {
|
|
292
305
|
flex: 1;
|
|
293
306
|
min-width: 0;
|
|
@@ -33,6 +33,7 @@ interface MountOptions {
|
|
|
33
33
|
confirmRemove?: boolean;
|
|
34
34
|
disabled?: boolean;
|
|
35
35
|
tagValues?: Record<string, string>;
|
|
36
|
+
options?: HkAffixOption[];
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
function mountPicker(opts: MountOptions = {}) {
|
|
@@ -47,7 +48,7 @@ function mountPicker(opts: MountOptions = {}) {
|
|
|
47
48
|
const app = createApp({
|
|
48
49
|
render: () =>
|
|
49
50
|
h(HkAffixPicker, {
|
|
50
|
-
options: OPTIONS,
|
|
51
|
+
options: opts.options ?? OPTIONS,
|
|
51
52
|
mode: opts.mode ?? "single",
|
|
52
53
|
selected: opts.selected ?? "",
|
|
53
54
|
activeKey: opts.activeKey,
|
|
@@ -494,3 +495,80 @@ describe("affix side → popup placement contract", () => {
|
|
|
494
495
|
);
|
|
495
496
|
});
|
|
496
497
|
});
|
|
498
|
+
|
|
499
|
+
describe("HkAffixPicker badge capsule", () => {
|
|
500
|
+
/** Provider-roster fixture (the shape GroupEditModal ships): a
|
|
501
|
+
* textual ordinal rides `badge` — the standard capsule slot — and
|
|
502
|
+
* never the emoji-font `flag` glyph slot (2026-11-20 user report:
|
|
503
|
+
* `flag: "#1"` rendered bare unstyled text). */
|
|
504
|
+
const BADGED: HkAffixOption[] = [
|
|
505
|
+
{ key: "llama-local", label: "llama-local", badge: "#1", keywords: "llama-local" },
|
|
506
|
+
{ key: "deepseek", label: "deepseek", badge: "#2", keywords: "deepseek" },
|
|
507
|
+
{ key: "bare", label: "bare provider" },
|
|
508
|
+
];
|
|
509
|
+
|
|
510
|
+
it("renders the badge as a standard capsule before the label; flag slot stays empty", async () => {
|
|
511
|
+
const { container } = mountPicker({ options: BADGED, selected: "llama-local" });
|
|
512
|
+
await openPopup(container);
|
|
513
|
+
const badges = [...document.querySelectorAll<HTMLElement>(".hk-affix-row-badge")];
|
|
514
|
+
expect(badges.map((b) => b.textContent)).toEqual(["#1", "#2"]);
|
|
515
|
+
// The capsule IS the standard badge chrome — primary wash, mono face,
|
|
516
|
+
// small size, squared pill — not just any span wearing the class
|
|
517
|
+
// (R2: a props-degraded mutant must turn red here).
|
|
518
|
+
for (const b of badges) {
|
|
519
|
+
expect(b.classList.contains("hk-badge-primary")).toBe(true);
|
|
520
|
+
expect(b.dataset.size).toBe("sm");
|
|
521
|
+
expect(b.dataset.mono).toBe("");
|
|
522
|
+
expect(b.dataset.pill).toBe("false");
|
|
523
|
+
}
|
|
524
|
+
// Textual ordinals must not leak into the emoji-flag glyph span.
|
|
525
|
+
expect(document.querySelector(".hk-affix-row-flag")).toBeNull();
|
|
526
|
+
// Capsule precedes the label inside its row (the row grammar's own
|
|
527
|
+
// 8px menu-item gap provides the spacing — no hand-tuned margins).
|
|
528
|
+
const row = rows()[0];
|
|
529
|
+
const badgeEl = row.querySelector(".hk-affix-row-badge");
|
|
530
|
+
const labelEl = row.querySelector(".hk-affix-row-label");
|
|
531
|
+
expect(
|
|
532
|
+
badgeEl &&
|
|
533
|
+
labelEl &&
|
|
534
|
+
!!(badgeEl.compareDocumentPosition(labelEl) & Node.DOCUMENT_POSITION_FOLLOWING),
|
|
535
|
+
).toBe(true);
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
it("multi mode keeps the badge on selected tags and remaining rows alike", async () => {
|
|
539
|
+
const { container } = mountPicker({
|
|
540
|
+
options: BADGED,
|
|
541
|
+
mode: "multi",
|
|
542
|
+
selected: ["deepseek"],
|
|
543
|
+
});
|
|
544
|
+
await openPopup(container);
|
|
545
|
+
const t = tag("deepseek");
|
|
546
|
+
expect(t, "selected tag renders").toBeTruthy();
|
|
547
|
+
expect(t!.querySelector(".hk-affix-tag-badge")?.textContent).toBe("#2");
|
|
548
|
+
// The not-yet-selected rows keep their capsules; a badge-less row
|
|
549
|
+
// (bare) renders no badge node at all.
|
|
550
|
+
expect(
|
|
551
|
+
rows().map((r) => r.querySelector(".hk-affix-row-badge")?.textContent),
|
|
552
|
+
).toEqual(["#1", undefined]);
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
it("options without a badge render no badge nodes", async () => {
|
|
556
|
+
// MULTI mode on purpose (R2: single mode never renders tags, so a
|
|
557
|
+
// `.hk-affix-tag-badge` assertion there is vacuous): both surfaces
|
|
558
|
+
// — remaining rows AND selected tags — must stay badge-free for a
|
|
559
|
+
// badge-less option.
|
|
560
|
+
const { container } = mountPicker({
|
|
561
|
+
options: BADGED,
|
|
562
|
+
mode: "multi",
|
|
563
|
+
selected: ["bare"],
|
|
564
|
+
});
|
|
565
|
+
await openPopup(container);
|
|
566
|
+
const t = tag("bare provider");
|
|
567
|
+
expect(t, "selected tag renders").toBeTruthy();
|
|
568
|
+
expect(t!.querySelector(".hk-affix-tag-badge")).toBeNull();
|
|
569
|
+
// The remaining rows are the two BADGED options — theirs render.
|
|
570
|
+
expect(
|
|
571
|
+
rows().map((r) => r.querySelector(".hk-affix-row-badge")?.textContent),
|
|
572
|
+
).toEqual(["#1", "#2"]);
|
|
573
|
+
});
|
|
574
|
+
});
|
|
@@ -11,6 +11,7 @@ import { ChevronDown, Plus, Search, X } from "lucide-vue-next";
|
|
|
11
11
|
|
|
12
12
|
import { useI18n } from "../i18n/context";
|
|
13
13
|
|
|
14
|
+
import HBadge from "./HkBadge";
|
|
14
15
|
import HkInput from "./HkInput";
|
|
15
16
|
import HkListTransition from "./HkListTransition";
|
|
16
17
|
import HkMenu from "./HkMenu";
|
|
@@ -27,6 +28,16 @@ export interface HkAffixOption {
|
|
|
27
28
|
meta?: string;
|
|
28
29
|
/** Optional leading glyph (flag emoji or any short symbol). */
|
|
29
30
|
flag?: string;
|
|
31
|
+
/** Standard leading CAPSULE: a small primary mono badge (`HBadge`,
|
|
32
|
+
* primary / sm / mono / square) — the visual language of the model
|
|
33
|
+
* tag's `#N` number segment downstream (shittim-chest kit
|
|
34
|
+
* `HkModelTag`, which renders its ordinal as exactly this badge
|
|
35
|
+
* shape) — rendered after the flag, before the label, separated by
|
|
36
|
+
* the row's own gap. Roster ordinals, short codes. A TEXTUAL
|
|
37
|
+
* ordinal never belongs in `flag`: that span is an emoji-font glyph
|
|
38
|
+
* slot, and an `#N` inside it renders as bare unstyled text
|
|
39
|
+
* (2026-11-20 user report). */
|
|
40
|
+
badge?: string;
|
|
30
41
|
/** Extra haystack for the search filter (aliases, codes, digits). */
|
|
31
42
|
keywords?: string;
|
|
32
43
|
disabled?: boolean;
|
|
@@ -60,6 +71,10 @@ function isSubsequence(query: string, text: string): boolean {
|
|
|
60
71
|
* - the option rows themselves: single mode shows every option and
|
|
61
72
|
* closes on pick; multi mode lists the NOT-yet-selected options and
|
|
62
73
|
* stays open for batch adds;
|
|
74
|
+
* - a row (or tag) can carry a `badge` — the standard leading capsule
|
|
75
|
+
* (primary mono, the model-tag num-segment language) for roster
|
|
76
|
+
* ordinals and short codes; `flag` stays the emoji glyph slot and
|
|
77
|
+
* the two never swap jobs;
|
|
63
78
|
* - with `allowCustom`, a trailing "Use <query>" row appears whenever
|
|
64
79
|
* the typed query is not an exact label match — free-text entries
|
|
65
80
|
* without leaving the keyboard flow (Enter picks the first row, or
|
|
@@ -420,6 +435,17 @@ export const HkAffixPicker = defineComponent({
|
|
|
420
435
|
{tag.flag}
|
|
421
436
|
</span>
|
|
422
437
|
)}
|
|
438
|
+
{tag.badge && (
|
|
439
|
+
<HBadge
|
|
440
|
+
variant="primary"
|
|
441
|
+
size="sm"
|
|
442
|
+
mono
|
|
443
|
+
pill={false}
|
|
444
|
+
class="hk-affix-tag-badge"
|
|
445
|
+
>
|
|
446
|
+
{tag.badge}
|
|
447
|
+
</HBadge>
|
|
448
|
+
)}
|
|
423
449
|
<span
|
|
424
450
|
class="hk-affix-tag-text"
|
|
425
451
|
data-unset={valueDriven && !value ? "" : undefined}
|
|
@@ -511,6 +537,17 @@ export const HkAffixPicker = defineComponent({
|
|
|
511
537
|
{option.flag}
|
|
512
538
|
</span>
|
|
513
539
|
)}
|
|
540
|
+
{option.badge && (
|
|
541
|
+
<HBadge
|
|
542
|
+
variant="primary"
|
|
543
|
+
size="sm"
|
|
544
|
+
mono
|
|
545
|
+
pill={false}
|
|
546
|
+
class="hk-affix-row-badge"
|
|
547
|
+
>
|
|
548
|
+
{option.badge}
|
|
549
|
+
</HBadge>
|
|
550
|
+
)}
|
|
514
551
|
<span class="hk-affix-row-label">{option.label}</span>
|
|
515
552
|
{option.meta && (
|
|
516
553
|
<span class="hk-affix-row-meta">{option.meta}</span>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// One emphasised key fact: a bordered chip pairing a muted label with a
|
|
2
|
+
// strong value. Channels are emitted-theme triplets wrapped in rgb().
|
|
3
|
+
|
|
4
|
+
.hk-delete-fact {
|
|
5
|
+
display: inline-flex;
|
|
6
|
+
align-items: baseline;
|
|
7
|
+
gap: var(--space-4, 4px);
|
|
8
|
+
padding: var(--space-2, 2px) var(--space-6, 6px);
|
|
9
|
+
border-radius: var(--radius-sm, 4px);
|
|
10
|
+
border: 1px solid rgb(var(--color-error, 166 41 55) / 35%);
|
|
11
|
+
background: rgb(var(--color-error, 166 41 55) / 6%);
|
|
12
|
+
font-size: var(--text-xs, 0.75rem);
|
|
13
|
+
max-width: 100%;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.hk-delete-fact-label {
|
|
17
|
+
color: rgb(var(--color-muted, 120 120 130));
|
|
18
|
+
flex-shrink: 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.hk-delete-fact-value {
|
|
22
|
+
color: rgb(var(--color-text, 20 20 24));
|
|
23
|
+
font-weight: 600;
|
|
24
|
+
overflow-wrap: anywhere;
|
|
25
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineComponent } from "vue";
|
|
2
|
+
|
|
3
|
+
import "./HkDeleteFact.scss";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* One emphasised key fact inside a {@link HkDeleteGateWindow} message
|
|
7
|
+
* slot. The house rule: EVERY key fact of the thing being deleted — name,
|
|
8
|
+
* per-locale alias, owner, counters, the names of attached resources — is
|
|
9
|
+
* rendered through this tag, so the irreversible act visibly names its
|
|
10
|
+
* target instead of waving at an anonymous blob.
|
|
11
|
+
*/
|
|
12
|
+
export default defineComponent({
|
|
13
|
+
name: "HkDeleteFact",
|
|
14
|
+
props: {
|
|
15
|
+
/** The fact's label ("名称" / "所有者" / "来源"). */
|
|
16
|
+
label: { type: String, required: true },
|
|
17
|
+
/** The fact's value ("ml-lab" / "demiurge" / "7 个仓库"). */
|
|
18
|
+
value: { type: String, required: true },
|
|
19
|
+
},
|
|
20
|
+
setup(props) {
|
|
21
|
+
return () => (
|
|
22
|
+
<span class="hk-delete-fact">
|
|
23
|
+
<span class="hk-delete-fact-label">{props.label}</span>
|
|
24
|
+
<span class="hk-delete-fact-value">{props.value}</span>
|
|
25
|
+
</span>
|
|
26
|
+
);
|
|
27
|
+
},
|
|
28
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// The delete confirmation window's message area: facts block on top, gate
|
|
2
|
+
// below, hint inside the gate (in flow per the stage split).
|
|
3
|
+
|
|
4
|
+
.hk-delete-gate-message {
|
|
5
|
+
display: flex;
|
|
6
|
+
flex-direction: column;
|
|
7
|
+
gap: var(--space-8, 8px);
|
|
8
|
+
margin-block-end: var(--space-12, 12px);
|
|
9
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { createApp, defineComponent, h, nextTick, ref } from "vue";
|
|
3
|
+
|
|
4
|
+
const confirmSpy = vi.fn();
|
|
5
|
+
const cancelSpy = vi.fn();
|
|
6
|
+
|
|
7
|
+
vi.mock("../runtime/animationBus", () => ({
|
|
8
|
+
onFrame: vi.fn(() => ({ disconnect: vi.fn() })),
|
|
9
|
+
reportTransition: vi.fn(() => ({ disconnect: vi.fn() })),
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
// HkModal is stubbed: this suite pins the WINDOW's wiring (open state,
|
|
13
|
+
// slot message, gate presence), not the modal chrome (covered upstream).
|
|
14
|
+
vi.mock("./HkModal", () => ({
|
|
15
|
+
default: defineComponent({
|
|
16
|
+
name: "HkModal",
|
|
17
|
+
props: { modelValue: { type: Boolean, default: false }, title: { type: String, default: "" } },
|
|
18
|
+
setup(props, { slots }) {
|
|
19
|
+
return () =>
|
|
20
|
+
props.modelValue
|
|
21
|
+
? h("div", { class: "delwin-stub" }, [
|
|
22
|
+
h("div", { class: "delwin-stub-title" }, props.title),
|
|
23
|
+
slots.default?.(),
|
|
24
|
+
])
|
|
25
|
+
: null;
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
import HkDeleteGateWindow from "./HkDeleteGateWindow";
|
|
31
|
+
|
|
32
|
+
const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
|
|
33
|
+
|
|
34
|
+
function mountWindow(slotHtml: string, props: Record<string, unknown> = {}) {
|
|
35
|
+
const container = document.createElement("div");
|
|
36
|
+
document.body.appendChild(container);
|
|
37
|
+
const Harness = defineComponent({
|
|
38
|
+
setup() {
|
|
39
|
+
return () =>
|
|
40
|
+
h(HkDeleteGateWindow, {
|
|
41
|
+
open: true,
|
|
42
|
+
title: "删除工作区",
|
|
43
|
+
label: "此工作区",
|
|
44
|
+
grabHint: "grab",
|
|
45
|
+
trackingHint: "keep going",
|
|
46
|
+
onConfirm: () => confirmSpy(),
|
|
47
|
+
onCancel: (p: number) => cancelSpy(p),
|
|
48
|
+
...props,
|
|
49
|
+
}, {
|
|
50
|
+
default: () => h("div", {
|
|
51
|
+
class: "hk-delete-gate-message",
|
|
52
|
+
innerHTML: slotHtml,
|
|
53
|
+
}),
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
const app = createApp(Harness);
|
|
58
|
+
app.mount(container);
|
|
59
|
+
mounts.push({ app, container });
|
|
60
|
+
return container;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
afterEach(() => {
|
|
64
|
+
for (const { app, container } of mounts.splice(0)) {
|
|
65
|
+
app.unmount();
|
|
66
|
+
container.remove();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe("HkDeleteGateWindow", () => {
|
|
71
|
+
it("renders the slot message, the title and the gate inside the window", () => {
|
|
72
|
+
const c = mountWindow(
|
|
73
|
+
'<span class="hk-delete-fact"><span class="hk-delete-fact-label">名称</span><span class="hk-delete-fact-value">ml-lab</span></span>',
|
|
74
|
+
);
|
|
75
|
+
expect(c.querySelector(".delwin-stub-title")!.textContent).toBe("删除工作区");
|
|
76
|
+
expect(c.querySelector(".hk-delete-gate-message .hk-delete-fact")!.textContent).toContain("ml-lab");
|
|
77
|
+
expect(c.querySelector(".hk-serpentine")).toBeTruthy();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("renders closed when open=false", () => {
|
|
81
|
+
const c = mountWindow("<p>msg</p>", { open: false });
|
|
82
|
+
expect(c.querySelector(".hk-serpentine")).toBeNull();
|
|
83
|
+
expect(c.querySelector(".delwin-stub")).toBeNull();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("passes a higher turn range through to the lane (sensitive deletes walk more)", () => {
|
|
87
|
+
const c = mountWindow("<p>msg</p>", { turns: [7, 9], seed: 42 });
|
|
88
|
+
const lane = c.querySelector(".hk-serpentine-lane") as SVGElement;
|
|
89
|
+
const corners = lane.getAttribute("points")!.split(" ").length - 2;
|
|
90
|
+
expect(corners).toBeGreaterThanOrEqual(7);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("closes itself after the gate confirms and forwards the walk events", async () => {
|
|
94
|
+
// The gate inside the window is the REAL component; walk it to the goal
|
|
95
|
+
// and release: the window must emit confirm (the parent performs the
|
|
96
|
+
// delete) AND close itself (update:open=false). A short release must
|
|
97
|
+
// NOT close — it only emits cancel with the progress.
|
|
98
|
+
const onUpdate = vi.fn();
|
|
99
|
+
const c = mountWindow("<p>msg</p>", {
|
|
100
|
+
"onUpdate:open": onUpdate,
|
|
101
|
+
seed: 42,
|
|
102
|
+
onConfirm: () => confirmSpy(),
|
|
103
|
+
onCancel: (p: number) => cancelSpy(p),
|
|
104
|
+
});
|
|
105
|
+
const el = c.querySelector(".hk-serpentine")!;
|
|
106
|
+
const down = new PointerEvent("pointerdown", { bubbles: true, clientX: 24, clientY: 48, pointerId: 1 });
|
|
107
|
+
el.dispatchEvent(down);
|
|
108
|
+
// Mid-lane release: cancel only.
|
|
109
|
+
const mid = new PointerEvent("pointermove", { bubbles: true, clientX: 300, clientY: 48, pointerId: 1 });
|
|
110
|
+
el.dispatchEvent(mid);
|
|
111
|
+
const up = new PointerEvent("pointerup", { bubbles: true, clientX: 300, clientY: 48, pointerId: 1 });
|
|
112
|
+
el.dispatchEvent(up);
|
|
113
|
+
expect(confirmSpy).not.toHaveBeenCalled();
|
|
114
|
+
expect(cancelSpy).toHaveBeenCalled();
|
|
115
|
+
expect(onUpdate).not.toHaveBeenCalled(); // stays open
|
|
116
|
+
// Re-open state is already open; a full walk then confirms and closes.
|
|
117
|
+
el.dispatchEvent(down);
|
|
118
|
+
for (let x = 30; x <= 600; x += 10) {
|
|
119
|
+
el.dispatchEvent(new PointerEvent("pointermove", { bubbles: true, clientX: x, clientY: 48, pointerId: 1 }));
|
|
120
|
+
}
|
|
121
|
+
el.dispatchEvent(new PointerEvent("pointerup", { bubbles: true, clientX: 600, clientY: 48, pointerId: 1 }));
|
|
122
|
+
expect(confirmSpy).toHaveBeenCalledTimes(1);
|
|
123
|
+
expect(onUpdate).toHaveBeenCalledWith(false);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("key facts carry the emphasis classes", () => {
|
|
127
|
+
const c = mountWindow(
|
|
128
|
+
'<span class="hk-delete-fact"><span class="hk-delete-fact-label">所有者</span><span class="hk-delete-fact-value">demiurge</span></span>',
|
|
129
|
+
);
|
|
130
|
+
expect(c.querySelector(".hk-delete-fact-label")!.textContent).toBe("所有者");
|
|
131
|
+
expect(c.querySelector(".hk-delete-fact-value")!.textContent).toBe("demiurge");
|
|
132
|
+
});
|
|
133
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { defineComponent, h, type PropType, type VNode } from "vue";
|
|
2
|
+
|
|
3
|
+
import HkSerpentineUnlock from "./HkSerpentineUnlock";
|
|
4
|
+
import HkModal from "./HkModal";
|
|
5
|
+
import "./HkDeleteGateWindow.scss";
|
|
6
|
+
|
|
7
|
+
export { default as HkDeleteFact } from "./HkDeleteFact";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The open-and-go delete confirmation window.
|
|
11
|
+
*
|
|
12
|
+
* ANY delete-related surface mounts this with `open` + `title`; the
|
|
13
|
+
* default slot renders the message area, and the HOUSE RULE for that slot
|
|
14
|
+
* is documented and enforced by review: the copy must carry EVERY key
|
|
15
|
+
* fact of the thing being deleted — its name (and per-locale alias where
|
|
16
|
+
* one exists), its owner, its size/counters, and the names of everything
|
|
17
|
+
* attached to it — each wrapped in an {@link HkDeleteFact} emphasis tag so
|
|
18
|
+
* the irreversible act is never aimed at an anonymous blob.
|
|
19
|
+
*
|
|
20
|
+
* The only confirm control is the serpentine walk (a full traced lane);
|
|
21
|
+
* closing abandons. The parent performs the actual deletion in
|
|
22
|
+
* `onConfirm`.
|
|
23
|
+
*/
|
|
24
|
+
export default defineComponent({
|
|
25
|
+
name: "HkDeleteGateWindow",
|
|
26
|
+
props: {
|
|
27
|
+
/** Window visibility (v-model:open). */
|
|
28
|
+
open: { type: Boolean, default: false },
|
|
29
|
+
/** Window title ("删除工作区"). */
|
|
30
|
+
title: { type: String, required: true },
|
|
31
|
+
/** What the confirming user is about to delete ("此工作区"). */
|
|
32
|
+
label: { type: String, required: true },
|
|
33
|
+
/** Hint before grabbing. */
|
|
34
|
+
grabHint: { type: String, required: true },
|
|
35
|
+
/** Hint while tracking. */
|
|
36
|
+
trackingHint: { type: String, required: true },
|
|
37
|
+
/** Corner-count range `[min, max]` — higher stakes, more turns. */
|
|
38
|
+
turns: {
|
|
39
|
+
type: Array as unknown as PropType<[number, number]>,
|
|
40
|
+
default: null,
|
|
41
|
+
},
|
|
42
|
+
/** Deterministic lane seed (tests / design review). */
|
|
43
|
+
seed: { type: Number, default: null },
|
|
44
|
+
/** Disables the gate (e.g. the delete RPC is in flight). */
|
|
45
|
+
disabled: { type: Boolean, default: false },
|
|
46
|
+
},
|
|
47
|
+
emits: {
|
|
48
|
+
"update:open": (v: boolean) => typeof v === "boolean",
|
|
49
|
+
/** Fired once, after a full lane walk released at the goal. */
|
|
50
|
+
confirm: () => true,
|
|
51
|
+
/** Progress at an early release; the parent may log or ignore. */
|
|
52
|
+
cancel: (progress: number) => typeof progress === "number",
|
|
53
|
+
},
|
|
54
|
+
setup(props, { emit, slots }) {
|
|
55
|
+
function close() {
|
|
56
|
+
emit("update:open", false);
|
|
57
|
+
}
|
|
58
|
+
function onConfirm() {
|
|
59
|
+
emit("confirm");
|
|
60
|
+
close();
|
|
61
|
+
}
|
|
62
|
+
return () =>
|
|
63
|
+
h(HkModal, {
|
|
64
|
+
modelValue: props.open,
|
|
65
|
+
"onUpdate:modelValue": (v: boolean) => emit("update:open", v),
|
|
66
|
+
title: props.title,
|
|
67
|
+
}, {
|
|
68
|
+
default: () => [
|
|
69
|
+
// The window renders the message wrapper itself: consumers put
|
|
70
|
+
// their key-fact chips inside the slot without knowing the class.
|
|
71
|
+
<div class="hk-delete-gate-message">
|
|
72
|
+
{slots.default?.() as VNode[]}
|
|
73
|
+
</div>,
|
|
74
|
+
<HkSerpentineUnlock
|
|
75
|
+
tone="danger"
|
|
76
|
+
label={props.label}
|
|
77
|
+
grabHint={props.grabHint}
|
|
78
|
+
trackingHint={props.trackingHint}
|
|
79
|
+
turns={props.turns ?? undefined}
|
|
80
|
+
seed={props.seed ?? undefined}
|
|
81
|
+
disabled={props.disabled}
|
|
82
|
+
onConfirm={() => onConfirm()}
|
|
83
|
+
onCancel={(progress: number) => emit("cancel", progress)}
|
|
84
|
+
/>,
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import * as barrel from "../index";
|
|
3
3
|
import { asIndexable } from "../utils/typing";
|
|
4
|
-
import type { HkAdminHeaderAvatarModalSlot, HkAdminHeaderSlots, HkFaceShellHeaderSlot, HkFaceShellSidebarSlot, HkFaceShellSlots, HkFaceShellUserPanelSlot } from "../index";
|
|
4
|
+
import type { HkAdminHeaderAvatarModalSlot, HkAdminHeaderLocalePickerSlot, HkAdminHeaderSlots, HkAdminHeaderUserMenuExtraSlot, HkFaceShellHeaderSlot, HkFaceShellSidebarSlot, HkFaceShellSlots, HkFaceShellUserPanelSlot } from "../index";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* The L39 slot-type contract pins. The exported slot types are what chest and
|
|
@@ -46,6 +46,22 @@ function avatarModalBody(params: HkAdminHeaderAvatarModalSlot) {
|
|
|
46
46
|
return { open, onUpdateOpen };
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
/** erp AdminLayout shape: the locale-picker destructure (L39 ruling-a
|
|
50
|
+
* revival — erp passes LocalePickerPopup exactly these members). */
|
|
51
|
+
function localePickerBody(params: HkAdminHeaderLocalePickerSlot) {
|
|
52
|
+
const { open, onUpdateOpen, triggerRef } = params;
|
|
53
|
+
onUpdateOpen(!open);
|
|
54
|
+
return { open, onUpdateOpen, triggerRef };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** erp AdminLayout shape: the user-menu-extra destructure (close is the
|
|
58
|
+
* only member; erp's account-center row calls it before navigating). */
|
|
59
|
+
function userMenuExtraBody(params: HkAdminHeaderUserMenuExtraSlot) {
|
|
60
|
+
const { close } = params;
|
|
61
|
+
close?.();
|
|
62
|
+
return { close };
|
|
63
|
+
}
|
|
64
|
+
|
|
49
65
|
describe("the public slot-type contract (L39)", () => {
|
|
50
66
|
it("exports every slot type name from the barrel", () => {
|
|
51
67
|
// Types are erased at runtime; the pin is the module-record presence of
|
|
@@ -80,6 +96,17 @@ describe("the public slot-type contract (L39)", () => {
|
|
|
80
96
|
const avatar = avatarModalBody({ open: false, onUpdateOpen: (v) => { opened = v; } });
|
|
81
97
|
expect(avatar.open).toBe(false);
|
|
82
98
|
expect(opened).toBe(true);
|
|
99
|
+
// L39 ruling-a revival shapes: erp's two revived slots destructured
|
|
100
|
+
// the way AdminLayout does (compile-level pin — a payload member
|
|
101
|
+
// rename breaks THIS file's vue-tsc, not a downstream repo's build).
|
|
102
|
+
let flipped = false;
|
|
103
|
+
const picker = localePickerBody({ open: false, onUpdateOpen: (v) => { flipped = v; }, triggerRef: null });
|
|
104
|
+
expect(picker.open).toBe(false);
|
|
105
|
+
expect(flipped).toBe(true);
|
|
106
|
+
let closed = false;
|
|
107
|
+
const extra = userMenuExtraBody({ close: () => { closed = true; } });
|
|
108
|
+
extra.close?.();
|
|
109
|
+
expect(closed).toBe(true);
|
|
83
110
|
});
|
|
84
111
|
|
|
85
112
|
it("the aggregate slot types fit a defineComponent slots declaration", () => {
|
|
@@ -8,11 +8,13 @@ import {
|
|
|
8
8
|
} from "vue";
|
|
9
9
|
|
|
10
10
|
import {
|
|
11
|
+
DEFAULT_TURNS,
|
|
11
12
|
generateSerpentinePath,
|
|
12
13
|
nearestOnPath,
|
|
13
14
|
projectOntoPath,
|
|
14
15
|
type PathPoint,
|
|
15
16
|
type SerpentinePath,
|
|
17
|
+
type TurnRange,
|
|
16
18
|
} from "./serpentineGeometry";
|
|
17
19
|
import "./HkSerpentineUnlock.scss";
|
|
18
20
|
import { onFrame, reportTransition, type AnimationHandle } from "../runtime/animationBus";
|
|
@@ -52,6 +54,17 @@ export default defineComponent({
|
|
|
52
54
|
* for tests and design review.
|
|
53
55
|
*/
|
|
54
56
|
seed: { type: Number, default: null },
|
|
57
|
+
/**
|
|
58
|
+
* Corner-count range `[min, max]` (inclusive). The actual count is a
|
|
59
|
+
* seeded draw inside the range, snapped to a constructible odd value —
|
|
60
|
+
* the lane's final leg is structural, so only odd counts exist and an
|
|
61
|
+
* even request clamps DOWN (at-most semantics). Default [3, 5];
|
|
62
|
+
* higher-stakes deletions can ask for more turns.
|
|
63
|
+
*/
|
|
64
|
+
turns: {
|
|
65
|
+
type: Array as unknown as PropType<[number, number]>,
|
|
66
|
+
default: null,
|
|
67
|
+
},
|
|
55
68
|
/** Danger tone (delete-class actions) vs neutral. */
|
|
56
69
|
tone: {
|
|
57
70
|
type: String as PropType<"default" | "danger">,
|
|
@@ -70,7 +83,9 @@ export default defineComponent({
|
|
|
70
83
|
const viewport = ref<HTMLElement | null>(null);
|
|
71
84
|
const stage = ref<HTMLElement | null>(null);
|
|
72
85
|
const seed = ref<number>(props.seed ?? Math.floor(Math.random() * 1e9));
|
|
73
|
-
const path = ref<SerpentinePath>(
|
|
86
|
+
const path = ref<SerpentinePath>(
|
|
87
|
+
generateSerpentinePath(600, 96, seed.value, toRange(props.turns)),
|
|
88
|
+
);
|
|
74
89
|
|
|
75
90
|
const tracking = ref(false);
|
|
76
91
|
/** Progress along the lane, 0..1 (arc-length fraction). */
|
|
@@ -91,6 +106,7 @@ export default defineComponent({
|
|
|
91
106
|
laneWidth.value,
|
|
92
107
|
laneHeight.value,
|
|
93
108
|
seed.value,
|
|
109
|
+
toRange(props.turns),
|
|
94
110
|
);
|
|
95
111
|
progress.value = 0;
|
|
96
112
|
}
|
|
@@ -108,6 +124,15 @@ export default defineComponent({
|
|
|
108
124
|
const keyboardGrabbed = ref(false);
|
|
109
125
|
const keyboardStep = 1 / 20;
|
|
110
126
|
|
|
127
|
+
function toRange(turns: [number, number] | null): TurnRange {
|
|
128
|
+
// A malformed tuple (too short) falls back to the default rather than
|
|
129
|
+
// poisoning the corner math with undefined → NaN lanes.
|
|
130
|
+
if (!turns || turns.length < 2 || !Number.isFinite(turns[0]) || !Number.isFinite(turns[1])) {
|
|
131
|
+
return DEFAULT_TURNS;
|
|
132
|
+
}
|
|
133
|
+
return { min: turns[0], max: turns[1] };
|
|
134
|
+
}
|
|
135
|
+
|
|
111
136
|
/** Pointer-to-lane distance the tracking forgives (px): inside it the knob
|
|
112
137
|
* follows the projection; outside it the knob holds (no reset). Generous
|
|
113
138
|
* by design — a touch wobble must not cost the walk. */
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
+
DEFAULT_TURNS,
|
|
4
5
|
generateSerpentinePath,
|
|
5
6
|
pathLength,
|
|
6
7
|
projectOntoPath,
|
|
7
8
|
TRACK_PAD,
|
|
9
|
+
type TurnRange,
|
|
8
10
|
type PathPoint,
|
|
9
11
|
} from "./serpentineGeometry";
|
|
10
12
|
|
|
@@ -113,6 +115,25 @@ describe("generateSerpentinePath", () => {
|
|
|
113
115
|
expect(down).toBeGreaterThan(0);
|
|
114
116
|
});
|
|
115
117
|
|
|
118
|
+
it("honours the requested turn RANGE (sensitive deletes can walk more)", () => {
|
|
119
|
+
// [5,7] must never produce a 3-corner lane; [3,5] must never produce 7.
|
|
120
|
+
const countCorners = (seed: number, range: TurnRange) =>
|
|
121
|
+
generateSerpentinePath(W, H, seed, range).points.length - 2;
|
|
122
|
+
for (let seed = 0; seed < 60; seed++) {
|
|
123
|
+
expect(countCorners(seed, { min: 5, max: 7 })).toBeGreaterThanOrEqual(5);
|
|
124
|
+
expect(countCorners(seed, { min: 5, max: 7 })).toBeLessThanOrEqual(7);
|
|
125
|
+
expect(countCorners(seed, DEFAULT_TURNS)).toBeLessThanOrEqual(5);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("clamps even requests DOWN to the odd value below (at-most semantics)", () => {
|
|
130
|
+
// corners = interior vertices = points.length - 2; an even max (4) can
|
|
131
|
+
// only ever be satisfied as 3 (the lane's final leg is structural).
|
|
132
|
+
const corners = generateSerpentinePath(W, H, 11, { min: 4, max: 4 })
|
|
133
|
+
.points.length - 2;
|
|
134
|
+
expect(corners).toBe(3);
|
|
135
|
+
});
|
|
136
|
+
|
|
116
137
|
it("stays inside the canvas on narrow widths (the budget guard)", () => {
|
|
117
138
|
for (const narrow of [120, 160, 240]) {
|
|
118
139
|
for (let seed = 0; seed < 50; seed++) {
|
|
@@ -79,6 +79,26 @@ const MIN_H_RUN = 40;
|
|
|
79
79
|
* border line and half of its hit area falls outside the gate. */
|
|
80
80
|
export const TRACK_PAD = 24;
|
|
81
81
|
|
|
82
|
+
export interface TurnRange {
|
|
83
|
+
/** Inclusive minimum corner count. */
|
|
84
|
+
min: number;
|
|
85
|
+
/** Inclusive maximum corner count. */
|
|
86
|
+
max: number;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The default corner range (the brief: 3–5 turns). */
|
|
90
|
+
export const DEFAULT_TURNS: TurnRange = { min: 3, max: 5 };
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Parity snap: even requests become the odd value below them (the lane's
|
|
94
|
+
* final leg is structural, so only odd corner counts are constructible).
|
|
95
|
+
* Callers enforce the ≥3 floor and integer-ness on top of this — this
|
|
96
|
+
* function alone does NOT guarantee a valid count.
|
|
97
|
+
*/
|
|
98
|
+
export function snapTurnCount(requested: number): number {
|
|
99
|
+
return requested % 2 === 1 ? requested : requested - 1;
|
|
100
|
+
}
|
|
101
|
+
|
|
82
102
|
/**
|
|
83
103
|
* Build the serpentine lane for a `width × height` canvas.
|
|
84
104
|
*
|
|
@@ -93,29 +113,43 @@ export function generateSerpentinePath(
|
|
|
93
113
|
width: number,
|
|
94
114
|
height: number,
|
|
95
115
|
seed: number,
|
|
116
|
+
turns: TurnRange = DEFAULT_TURNS,
|
|
96
117
|
): SerpentinePath {
|
|
97
118
|
const rand = mulberry32(seed);
|
|
98
119
|
const centre = height / 2;
|
|
99
120
|
const firstRowUp = rand() < 0.5;
|
|
100
121
|
const pad = Math.min(TRACK_PAD, width / 8);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
//
|
|
104
|
-
//
|
|
105
|
-
|
|
122
|
+
const span = width - pad * 2;
|
|
123
|
+
const minHRunHoisted = Math.min(MIN_H_RUN, Math.floor(width / 8));
|
|
124
|
+
// Corner count: a seeded draw inside the requested range, snapped to a
|
|
125
|
+
// constructible (odd) value — higher ranges (sensitive deletions) walk
|
|
126
|
+
// more corners. Leg count is corners + 1 and always ends with the
|
|
127
|
+
// horizontal run to the right edge: V,H,V,H,...,V,H. The seeded first V
|
|
128
|
+
// satisfies "the walk may start upward or downward".
|
|
129
|
+
const requestedMin = Math.max(3, Math.floor(turns.min));
|
|
130
|
+
const maxFitting = Math.max(3, 2 * (Math.floor(span / minHRunHoisted) + 1) - 1);
|
|
131
|
+
const requestedMax = Math.min(
|
|
132
|
+
Math.max(requestedMin, Math.ceil(turns.max)),
|
|
133
|
+
maxFitting,
|
|
134
|
+
);
|
|
135
|
+
const low = Math.max(3, snapTurnCount(requestedMin));
|
|
136
|
+
const high = Math.max(low, snapTurnCount(requestedMax));
|
|
137
|
+
const corners = Math.max(low, Math.min(high, snapTurnCount(
|
|
138
|
+
low + Math.floor(rand() * (high - low + 1)),
|
|
139
|
+
)));
|
|
140
|
+
const legCount = corners + 1;
|
|
106
141
|
const vLegs = legCount / 2;
|
|
107
142
|
|
|
108
143
|
const rowA = centre - height * ROW_FRACTION;
|
|
109
144
|
const rowB = centre + height * ROW_FRACTION;
|
|
110
145
|
// On narrow canvases the run floor shrinks so the lane still fits.
|
|
111
|
-
const minHRun =
|
|
146
|
+
const minHRun = minHRunHoisted;
|
|
112
147
|
|
|
113
148
|
const points: PathPoint[] = [{ x: pad, y: centre }];
|
|
114
149
|
let x = pad;
|
|
115
150
|
// Distribute the horizontal budget across the H legs: every H leg except
|
|
116
151
|
// the last gets a random slice (>= minHRun); the LAST H leg takes the
|
|
117
152
|
// remainder so the walk lands exactly on the right edge.
|
|
118
|
-
const span = width - pad * 2;
|
|
119
153
|
const hBudget = span - minHRun * (vLegs - 1);
|
|
120
154
|
const hRuns: number[] = [];
|
|
121
155
|
let used = 0;
|
package/src/index.ts
CHANGED
|
@@ -1031,6 +1031,8 @@ export { default as HkTreemap } from "./components/HkTreemap";
|
|
|
1031
1031
|
export { default as HkTreemapStage } from "./components/HkTreemapStage";
|
|
1032
1032
|
export { default as HkErrorBoundary } from "./components/HkErrorBoundary";
|
|
1033
1033
|
export { default as HkDraggableList } from "./components/HkDraggableList";
|
|
1034
|
+
export { default as HkDeleteFact } from "./components/HkDeleteFact";
|
|
1035
|
+
export { default as HkDeleteGateWindow } from "./components/HkDeleteGateWindow";
|
|
1034
1036
|
export { default as HkDraggableGrid } from "./components/HkDraggableGrid";
|
|
1035
1037
|
export { default as HkSelectionGrid } from "./components/HkSelectionGrid";
|
|
1036
1038
|
export { default as HkSelectionWaterfall } from "./components/HkSelectionWaterfall";
|
|
@@ -1070,7 +1072,7 @@ export { HkAdminShell as HkAdminShell } from "./components/HkAdminShell";
|
|
|
1070
1072
|
export { HkFaceShell as HkFaceShell } from "./components/HkFaceShell";
|
|
1071
1073
|
export type { HkFaceShellHeaderSlot, HkFaceShellSidebarSlot, HkFaceShellUserPanelSlot, HkFaceShellSlots } from "./components/HkFaceShell";
|
|
1072
1074
|
export { HkAdminHeader as HkAdminHeader } from "./components/HkAdminHeader";
|
|
1073
|
-
export type { HkAdminHeaderAvatarModalSlot, HkAdminHeaderSlots } from "./components/HkAdminHeader";
|
|
1075
|
+
export type { HkAdminHeaderAvatarModalSlot, HkAdminHeaderLocalePickerSlot, HkAdminHeaderSlots, HkAdminHeaderUserMenuExtraSlot } from "./components/HkAdminHeader";
|
|
1074
1076
|
export { HkAvatarButton as HkAvatarButton } from "./components/HkAvatarButton";
|
|
1075
1077
|
export { HkNavSidebar as HkNavSidebar } from "./components/HkNavSidebar";
|
|
1076
1078
|
export { HkThemeToggle as HkThemeToggle } from "./components/HkThemeToggle";
|