@celestia-island/hikari 0.55.458 → 0.55.459
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/dist/types/components/HkAuthChannelList.d.ts +66 -0
- package/dist/types/components/HkLoginFlow.d.ts +13 -12
- package/dist/types/index.d.ts +2 -0
- package/package.json +1 -1
- package/src/components/HkAuthChannelList.scss +83 -0
- package/src/components/HkAuthChannelList.test.tsx +74 -0
- package/src/components/HkAuthChannelList.tsx +88 -0
- package/src/components/HkDiffViewer.epoch.test.tsx +28 -10
- package/src/components/HkLoginFlow.scss +3 -5
- package/src/components/HkLoginFlow.test.tsx +20 -13
- package/src/components/HkLoginFlow.tsx +24 -19
- package/src/composables/useHighlight.coldPath.test.ts +162 -0
- package/src/composables/useHighlight.hostSurface.test.ts +220 -0
- package/src/composables/useHighlight.ts +102 -27
- package/src/index.ts +2 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import "./HkAuthChannelList.scss";
|
|
2
|
+
/** One sign-in destination row: the provider's mark on the left, the
|
|
3
|
+
* channel's name on the right. */
|
|
4
|
+
export interface HkAuthChannelListEntry {
|
|
5
|
+
key: string;
|
|
6
|
+
/** The channel name rendered as the row's label (e.g. 「飞书登录」). */
|
|
7
|
+
label: string;
|
|
8
|
+
/** Prebuilt icon vnode (brand SVG, <img>, …) rendered at the row's
|
|
9
|
+
* left. Loose-typed like every auth icon: hosts materialize hikari
|
|
10
|
+
* against their own vue store. A missing icon leaves the slot empty
|
|
11
|
+
* (the label carries the row). */
|
|
12
|
+
icon?: unknown;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* HkAuthChannelList — the standard sign-in destination list (2026-11-22
|
|
17
|
+
* user direction): one FULL-WIDTH ROW per channel, the mark on the left
|
|
18
|
+
* and the channel's NAME in plain sight on the right.
|
|
19
|
+
*
|
|
20
|
+
* This replaces the small square icon tiles (`HkAuthMethodList`) as the
|
|
21
|
+
* form for login-flow destination buttons — on every Celestia auth
|
|
22
|
+
* surface. A tile hides the channel's name behind a hover tooltip; a
|
|
23
|
+
* list row states it. The row is a plain bordered button (token-driven,
|
|
24
|
+
* dark-mode automatic) — no square framing, no hover reveal.
|
|
25
|
+
*
|
|
26
|
+
* Control contract: the list never talks to a backend; the host injects
|
|
27
|
+
* `methods` and handles `select(key)`.
|
|
28
|
+
*
|
|
29
|
+
* ```tsx
|
|
30
|
+
* <HkAuthChannelList
|
|
31
|
+
* methods={[{ key: "feishu", label: "飞书登录", icon: <FeishuMark /> }]}
|
|
32
|
+
* onSelect={(key) => startLogin(key)}
|
|
33
|
+
* />
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare const HkAuthChannelList: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
37
|
+
/** Optional divider text rendered above the list (consumer copy). */
|
|
38
|
+
divider: {
|
|
39
|
+
type: StringConstructor;
|
|
40
|
+
default: string;
|
|
41
|
+
};
|
|
42
|
+
/** Channel rows, in render order. */
|
|
43
|
+
methods: {
|
|
44
|
+
type: () => HkAuthChannelListEntry[];
|
|
45
|
+
required: true;
|
|
46
|
+
};
|
|
47
|
+
}>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
48
|
+
/** A channel row was activated. */
|
|
49
|
+
select: (_key: string) => true;
|
|
50
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
51
|
+
/** Optional divider text rendered above the list (consumer copy). */
|
|
52
|
+
divider: {
|
|
53
|
+
type: StringConstructor;
|
|
54
|
+
default: string;
|
|
55
|
+
};
|
|
56
|
+
/** Channel rows, in render order. */
|
|
57
|
+
methods: {
|
|
58
|
+
type: () => HkAuthChannelListEntry[];
|
|
59
|
+
required: true;
|
|
60
|
+
};
|
|
61
|
+
}>> & Readonly<{
|
|
62
|
+
onSelect?: ((_key: string) => any) | undefined;
|
|
63
|
+
}>, {
|
|
64
|
+
divider: string;
|
|
65
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
66
|
+
export default HkAuthChannelList;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type PropType } from "vue";
|
|
2
|
-
import { type
|
|
2
|
+
import { type HkAuthChannelListEntry } from "./HkAuthChannelList";
|
|
3
3
|
import { type HkMfaFactor } from "./HkMfaVerifyCard";
|
|
4
4
|
import "./HkLoginFlow.scss";
|
|
5
5
|
/** A channel whose sign-in is a credentials handshake the host drives:
|
|
@@ -34,27 +34,28 @@ export interface HkLoginCredentialsChannel {
|
|
|
34
34
|
* opening card must not ask for it (2026-11 user direction). */
|
|
35
35
|
passwordField?: boolean;
|
|
36
36
|
submitLabel?: string;
|
|
37
|
-
/** Alternative sign-in
|
|
37
|
+
/** Alternative sign-in rows under the form (rendered only when
|
|
38
38
|
* non-empty; an empty list omits the whole methods block instead of
|
|
39
39
|
* padding a dead strip). */
|
|
40
|
-
methods?:
|
|
41
|
-
/** Divider text above the
|
|
40
|
+
methods?: HkAuthChannelListEntry[];
|
|
41
|
+
/** Divider text above the rows; consumer-localized on purpose. */
|
|
42
42
|
methodsDivider?: string;
|
|
43
43
|
}
|
|
44
44
|
/** A channel whose whole sign-in is one redirect (a.celestia.world's
|
|
45
|
-
* "Celestia"
|
|
46
|
-
* only offers Feishu): the card renders
|
|
47
|
-
*
|
|
45
|
+
* "Celestia" row jumping to the central login, an org channel that
|
|
46
|
+
* only offers Feishu): the card renders the standard channel list —
|
|
47
|
+
* one full-width row naming the destination — and `sso-click` sends
|
|
48
|
+
* the host off to build its OAuth URL. */
|
|
48
49
|
export interface HkLoginSsoChannel {
|
|
49
50
|
key: string;
|
|
50
51
|
mode: "sso";
|
|
51
52
|
label?: string;
|
|
52
53
|
title?: string;
|
|
53
54
|
subtitle?: string;
|
|
54
|
-
/** Provider mark for the
|
|
55
|
+
/** Provider mark for the row (brand SVG, <img>, …). Loose-typed like
|
|
55
56
|
* every auth icon: hosts materialize hikari against their own vue. */
|
|
56
57
|
icon: unknown;
|
|
57
|
-
/**
|
|
58
|
+
/** The row's label (accessible name + visible text); defaults to the
|
|
58
59
|
* label. */
|
|
59
60
|
buttonLabel?: string;
|
|
60
61
|
disabled?: boolean;
|
|
@@ -71,7 +72,7 @@ export type HkLoginChannel = HkLoginCredentialsChannel | HkLoginSsoChannel;
|
|
|
71
72
|
* visual — the pill segment group (hidden when a deployment offers a
|
|
72
73
|
* single channel; a lone dead segment reads as a broken switch), the
|
|
73
74
|
* height-morphing channel swap, the direction-aware account→verify
|
|
74
|
-
* slide, the methods
|
|
75
|
+
* slide, the methods rows, the MFA card — while staying a CONTROLLED
|
|
75
76
|
* component: no endpoint, no URL building, no factor ladder policy.
|
|
76
77
|
* Each host (the chest migration plus the erp and arona login surfaces,
|
|
77
78
|
* landing as their own PRs) keeps its own auth client and drives the
|
|
@@ -85,8 +86,8 @@ export type HkLoginChannel = HkLoginCredentialsChannel | HkLoginSsoChannel;
|
|
|
85
86
|
* channel renders the account card as a fail-safe).
|
|
86
87
|
* - `account-submit(channel, username, password)` — credentials
|
|
87
88
|
* channel submitted (password is empty while `passwordField` is off).
|
|
88
|
-
* - `method-select(channel, key)` — an alternative
|
|
89
|
-
* - `sso-click(channel)` — the primary sso
|
|
89
|
+
* - `method-select(channel, key)` — an alternative method row was picked.
|
|
90
|
+
* - `sso-click(channel)` — the primary sso row was picked.
|
|
90
91
|
* - `verify(kind, proof)` / `verify-resend` / `verify-back` — the MFA
|
|
91
92
|
* card's events, re-emitted one level up.
|
|
92
93
|
*
|
package/dist/types/index.d.ts
CHANGED
|
@@ -491,6 +491,8 @@ export { type HkLoginChannel as HkLoginChannel } from "./components/HkLoginFlow"
|
|
|
491
491
|
export { type HkLoginCredentialsChannel as HkLoginCredentialsChannel } from "./components/HkLoginFlow";
|
|
492
492
|
export { type HkLoginSsoChannel as HkLoginSsoChannel } from "./components/HkLoginFlow";
|
|
493
493
|
export { HkAuthSsoButton as HkAuthSsoButton } from "./components/HkAuthSsoButton";
|
|
494
|
+
export { HkAuthChannelList as HkAuthChannelList } from "./components/HkAuthChannelList";
|
|
495
|
+
export { type HkAuthChannelListEntry as HkAuthChannelListEntry } from "./components/HkAuthChannelList";
|
|
494
496
|
export { HkLocalePicker as HkLocalePicker } from "./components/HkLocalePicker";
|
|
495
497
|
export { HkAdminTablePage as HkAdminTablePage } from "./components/HkAdminTablePage";
|
|
496
498
|
export { HkPageHeader as HkPageHeader } from "./components/HkPageHeader";
|
package/package.json
CHANGED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// HkAuthChannelList — the standard sign-in destination list (rows, not
|
|
2
|
+
// tiles). One full-width bordered row per channel: mark left, name
|
|
3
|
+
// right; token-driven so dark mode rides the triplets.
|
|
4
|
+
|
|
5
|
+
.hk-auth-channel-list {
|
|
6
|
+
display: flex;
|
|
7
|
+
flex-direction: column;
|
|
8
|
+
gap: var(--space-8, 0.5rem);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.hk-auth-channel-divider {
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
gap: var(--space-12, 0.75rem);
|
|
15
|
+
color: color-mix(in srgb, rgb(var(--color-text, 25 30 40)) 55%, transparent);
|
|
16
|
+
font-size: 0.75rem;
|
|
17
|
+
|
|
18
|
+
&::before,
|
|
19
|
+
&::after {
|
|
20
|
+
content: "";
|
|
21
|
+
flex: 1;
|
|
22
|
+
height: 1px;
|
|
23
|
+
background: color-mix(in srgb, rgb(var(--color-text, 25 30 40)) 12%, transparent);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.hk-auth-channel-rows {
|
|
28
|
+
display: flex;
|
|
29
|
+
flex-direction: column;
|
|
30
|
+
gap: var(--space-8, 0.5rem);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.hk-auth-channel-row {
|
|
34
|
+
display: flex;
|
|
35
|
+
align-items: center;
|
|
36
|
+
gap: var(--space-12, 0.75rem);
|
|
37
|
+
width: 100%;
|
|
38
|
+
padding: 0.625rem var(--space-16, 1rem);
|
|
39
|
+
border: 1px solid color-mix(in srgb, rgb(var(--color-text, 25 30 40)) 14%, transparent);
|
|
40
|
+
border-radius: var(--hi-radius-lg, 12px);
|
|
41
|
+
background: color-mix(in srgb, rgb(var(--color-surface, 255 255 255)) 88%, transparent);
|
|
42
|
+
color: rgb(var(--color-text, 25 30 40));
|
|
43
|
+
font-size: 0.875rem;
|
|
44
|
+
cursor: pointer;
|
|
45
|
+
transition:
|
|
46
|
+
border-color 0.15s ease,
|
|
47
|
+
background-color 0.15s ease;
|
|
48
|
+
|
|
49
|
+
&:hover:not(:disabled) {
|
|
50
|
+
border-color: color-mix(in srgb, rgb(var(--color-primary, 122 162 247)) 55%, transparent);
|
|
51
|
+
background: color-mix(in srgb, rgb(var(--color-surface, 255 255 255)) 100%, transparent);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
&:focus-visible {
|
|
55
|
+
outline: 2px solid rgb(var(--color-primary, 122 162 247));
|
|
56
|
+
outline-offset: 2px;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
&:disabled {
|
|
60
|
+
opacity: 0.55;
|
|
61
|
+
cursor: not-allowed;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.hk-auth-channel-icon {
|
|
66
|
+
display: flex;
|
|
67
|
+
align-items: center;
|
|
68
|
+
justify-content: center;
|
|
69
|
+
flex: none;
|
|
70
|
+
width: 1.25rem;
|
|
71
|
+
height: 1.25rem;
|
|
72
|
+
|
|
73
|
+
svg,
|
|
74
|
+
img {
|
|
75
|
+
width: 1.25rem;
|
|
76
|
+
height: 1.25rem;
|
|
77
|
+
object-fit: contain;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.hk-auth-channel-name {
|
|
82
|
+
text-align: left;
|
|
83
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { createApp, h, nextTick } from "vue";
|
|
3
|
+
|
|
4
|
+
import HkAuthChannelList from "./HkAuthChannelList";
|
|
5
|
+
|
|
6
|
+
const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
|
|
7
|
+
|
|
8
|
+
function mount(node: ReturnType<typeof h>) {
|
|
9
|
+
const container = document.createElement("div");
|
|
10
|
+
document.body.appendChild(container);
|
|
11
|
+
const app = createApp({ render: () => node });
|
|
12
|
+
app.mount(container);
|
|
13
|
+
mounts.push({ app, container });
|
|
14
|
+
return container;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
for (const { app, container } of mounts.splice(0)) {
|
|
19
|
+
app.unmount();
|
|
20
|
+
container.remove();
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const methods = [
|
|
25
|
+
{ key: "feishu", label: "飞书登录", icon: h("svg") },
|
|
26
|
+
{ key: "celestial", label: "Celestia 账号" },
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
describe("HkAuthChannelList", () => {
|
|
30
|
+
it("renders full-width rows: the mark on the left, the channel NAME on the right", () => {
|
|
31
|
+
// 2026-11-22 user direction: sign-in destinations are a standard
|
|
32
|
+
// list — the name is plain sight, not a hover tooltip on a tile.
|
|
33
|
+
const c = mount(h(HkAuthChannelList, { methods }));
|
|
34
|
+
const rows = c.querySelectorAll<HTMLButtonElement>(".hk-auth-channel-row");
|
|
35
|
+
expect(rows.length).toBe(2);
|
|
36
|
+
expect(rows[0]!.textContent).toContain("飞书登录");
|
|
37
|
+
expect(rows[1]!.textContent).toContain("Celestia 账号");
|
|
38
|
+
// The accessible name rides the row itself (no role override).
|
|
39
|
+
expect(rows[0]!.getAttribute("aria-label")).toBe("飞书登录");
|
|
40
|
+
expect(rows[0]!.getAttribute("role")).toBeNull();
|
|
41
|
+
// The icon renders BEFORE the name (left-mark, right-name).
|
|
42
|
+
const icon = rows[0]!.querySelector(".hk-auth-channel-icon");
|
|
43
|
+
const name = rows[0]!.querySelector(".hk-auth-channel-name");
|
|
44
|
+
expect(icon).not.toBeNull();
|
|
45
|
+
expect(name).not.toBeNull();
|
|
46
|
+
expect((icon as HTMLElement).compareDocumentPosition(name as HTMLElement)
|
|
47
|
+
& Node.DOCUMENT_POSITION_FOLLOWING).not.toBe(0);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("emits select with the row's key and honors disabled rows", async () => {
|
|
51
|
+
const onSelect = vi.fn();
|
|
52
|
+
const c = mount(
|
|
53
|
+
h(HkAuthChannelList, {
|
|
54
|
+
methods: [
|
|
55
|
+
...methods,
|
|
56
|
+
{ key: "off", label: "Disabled", disabled: true },
|
|
57
|
+
],
|
|
58
|
+
onSelect,
|
|
59
|
+
}),
|
|
60
|
+
);
|
|
61
|
+
const rows = c.querySelectorAll<HTMLButtonElement>(".hk-auth-channel-row");
|
|
62
|
+
rows[0]!.click();
|
|
63
|
+
await nextTick();
|
|
64
|
+
expect(onSelect).toHaveBeenCalledWith("feishu");
|
|
65
|
+
rows[2]!.click();
|
|
66
|
+
await nextTick();
|
|
67
|
+
expect(onSelect).toHaveBeenCalledTimes(1);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("renders an optional divider above the rows", () => {
|
|
71
|
+
const c = mount(h(HkAuthChannelList, { divider: "或", methods }));
|
|
72
|
+
expect(c.querySelector(".hk-auth-channel-divider")?.textContent).toContain("或");
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { defineComponent } from "vue";
|
|
2
|
+
|
|
3
|
+
import "./HkAuthChannelList.scss";
|
|
4
|
+
|
|
5
|
+
/** One sign-in destination row: the provider's mark on the left, the
|
|
6
|
+
* channel's name on the right. */
|
|
7
|
+
export interface HkAuthChannelListEntry {
|
|
8
|
+
key: string;
|
|
9
|
+
/** The channel name rendered as the row's label (e.g. 「飞书登录」). */
|
|
10
|
+
label: string;
|
|
11
|
+
/** Prebuilt icon vnode (brand SVG, <img>, …) rendered at the row's
|
|
12
|
+
* left. Loose-typed like every auth icon: hosts materialize hikari
|
|
13
|
+
* against their own vue store. A missing icon leaves the slot empty
|
|
14
|
+
* (the label carries the row). */
|
|
15
|
+
icon?: unknown;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* HkAuthChannelList — the standard sign-in destination list (2026-11-22
|
|
21
|
+
* user direction): one FULL-WIDTH ROW per channel, the mark on the left
|
|
22
|
+
* and the channel's NAME in plain sight on the right.
|
|
23
|
+
*
|
|
24
|
+
* This replaces the small square icon tiles (`HkAuthMethodList`) as the
|
|
25
|
+
* form for login-flow destination buttons — on every Celestia auth
|
|
26
|
+
* surface. A tile hides the channel's name behind a hover tooltip; a
|
|
27
|
+
* list row states it. The row is a plain bordered button (token-driven,
|
|
28
|
+
* dark-mode automatic) — no square framing, no hover reveal.
|
|
29
|
+
*
|
|
30
|
+
* Control contract: the list never talks to a backend; the host injects
|
|
31
|
+
* `methods` and handles `select(key)`.
|
|
32
|
+
*
|
|
33
|
+
* ```tsx
|
|
34
|
+
* <HkAuthChannelList
|
|
35
|
+
* methods={[{ key: "feishu", label: "飞书登录", icon: <FeishuMark /> }]}
|
|
36
|
+
* onSelect={(key) => startLogin(key)}
|
|
37
|
+
* />
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export const HkAuthChannelList = defineComponent({
|
|
41
|
+
name: "HkAuthChannelList",
|
|
42
|
+
props: {
|
|
43
|
+
/** Optional divider text rendered above the list (consumer copy). */
|
|
44
|
+
divider: { type: String, default: "" },
|
|
45
|
+
/** Channel rows, in render order. */
|
|
46
|
+
methods: {
|
|
47
|
+
type: Array as () => HkAuthChannelListEntry[],
|
|
48
|
+
required: true,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
emits: {
|
|
52
|
+
/** A channel row was activated. */
|
|
53
|
+
select: (_key: string) => true,
|
|
54
|
+
},
|
|
55
|
+
setup(props, { emit }) {
|
|
56
|
+
return () => (
|
|
57
|
+
<div class="hk-auth-channel-list">
|
|
58
|
+
{props.divider && (
|
|
59
|
+
<div class="hk-auth-channel-divider">
|
|
60
|
+
<span>{props.divider}</span>
|
|
61
|
+
</div>
|
|
62
|
+
)}
|
|
63
|
+
<div class="hk-auth-channel-rows">
|
|
64
|
+
{props.methods.map((method) => (
|
|
65
|
+
<button
|
|
66
|
+
key={method.key}
|
|
67
|
+
type="button"
|
|
68
|
+
class="hk-auth-channel-row"
|
|
69
|
+
data-key={method.key}
|
|
70
|
+
disabled={method.disabled}
|
|
71
|
+
aria-label={method.label}
|
|
72
|
+
onClick={() => {
|
|
73
|
+
if (!method.disabled) emit("select", method.key);
|
|
74
|
+
}}
|
|
75
|
+
>
|
|
76
|
+
<span class="hk-auth-channel-icon" aria-hidden="true">
|
|
77
|
+
{method.icon ?? null}
|
|
78
|
+
</span>
|
|
79
|
+
<span class="hk-auth-channel-name">{method.label}</span>
|
|
80
|
+
</button>
|
|
81
|
+
))}
|
|
82
|
+
</div>
|
|
83
|
+
</div>
|
|
84
|
+
);
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
export default HkAuthChannelList;
|
|
@@ -1,16 +1,34 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from "vitest";
|
|
2
2
|
import { createApp, defineComponent, h } from "vue";
|
|
3
3
|
|
|
4
|
-
// Mock the
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
// (packages/vue/src/wasm/highlight/hikari_wasm_highlight.d.ts). A
|
|
9
|
-
// mock
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
// Mock the host client's async door at the top level: the composable now loads
|
|
5
|
+
// the component through `loadComponent`, so that is where "the wasm module
|
|
6
|
+
// lands" happens. The returned surface mimics the real call shape, and its
|
|
7
|
+
// `html` is the real ABI record — `HighlightResult = { html?: string }`, NOT a
|
|
8
|
+
// bare string (packages/vue/src/wasm/highlight/hikari_wasm_highlight.d.ts). A
|
|
9
|
+
// string-returning mock hid the seam that fed the record to `v-html`; the
|
|
10
|
+
// adapter test pins that separately.
|
|
11
|
+
//
|
|
12
|
+
// Mocking the module this test used to mock (`../wasm/highlight/...`) no longer
|
|
13
|
+
// works: the composable imports it from `src/composables/`, which resolves to a
|
|
14
|
+
// different module id, so the real component loaded and the assertion never
|
|
15
|
+
// saw `<wasm>` (measured).
|
|
16
|
+
vi.mock("@celestia-island/tairitsu-host-client", async (importOriginal) => {
|
|
17
|
+
const actual = await importOriginal<typeof import("@celestia-island/tairitsu-host-client")>();
|
|
18
|
+
return {
|
|
19
|
+
...actual,
|
|
20
|
+
loadComponent: async () =>
|
|
21
|
+
({
|
|
22
|
+
exports: {},
|
|
23
|
+
call: (_name: string, text: string, lang: string) => ({
|
|
24
|
+
html: `<wasm>${lang}:${text}</wasm>`,
|
|
25
|
+
}),
|
|
26
|
+
stop: async () => {},
|
|
27
|
+
whenIdle: async () => {},
|
|
28
|
+
stopped: false,
|
|
29
|
+
}) as unknown as Awaited<ReturnType<typeof actual.loadComponent>>,
|
|
30
|
+
};
|
|
31
|
+
});
|
|
14
32
|
|
|
15
33
|
import HkDiffViewer from "./HkDiffViewer";
|
|
16
34
|
import { useHighlight } from "../composables/useHighlight";
|
|
@@ -13,11 +13,9 @@
|
|
|
13
13
|
margin-inline: auto;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
// The sso card's
|
|
17
|
-
//
|
|
18
|
-
// channel tabs.
|
|
16
|
+
// The sso card's destination list block: full-width rows (the 2026-11
|
|
17
|
+
// standard-list direction), so this wrapper just adds breathing room
|
|
18
|
+
// under the channel tabs.
|
|
19
19
|
.hk-login-flow-sso {
|
|
20
|
-
display: flex;
|
|
21
|
-
justify-content: center;
|
|
22
20
|
padding-block: var(--space-24, 1.5rem) var(--space-8, 0.5rem);
|
|
23
21
|
}
|
|
@@ -139,7 +139,7 @@ describe("HkLoginFlow — credentials channel", () => {
|
|
|
139
139
|
expect(onSubmit).toHaveBeenCalledWith("cloud", "demiurge", "");
|
|
140
140
|
});
|
|
141
141
|
|
|
142
|
-
it("renders alternative method
|
|
142
|
+
it("renders alternative method rows and forwards their selection", async () => {
|
|
143
143
|
const onSelect = vi.fn();
|
|
144
144
|
const channel: HkLoginChannel = {
|
|
145
145
|
key: "cloud",
|
|
@@ -154,24 +154,27 @@ describe("HkLoginFlow — credentials channel", () => {
|
|
|
154
154
|
onMethodSelect: onSelect,
|
|
155
155
|
}),
|
|
156
156
|
);
|
|
157
|
-
const
|
|
158
|
-
expect(
|
|
159
|
-
expect(
|
|
160
|
-
|
|
157
|
+
const row = c.querySelector<HTMLButtonElement>('[data-key="feishu"]');
|
|
158
|
+
expect(row).not.toBeNull();
|
|
159
|
+
expect(row!.getAttribute("aria-label")).toBe("Feishu");
|
|
160
|
+
expect(c.querySelector(".hk-auth-channel-divider")?.textContent).toContain("或");
|
|
161
|
+
row!.click();
|
|
161
162
|
await nextTick();
|
|
162
163
|
expect(onSelect).toHaveBeenCalledWith("cloud", "feishu");
|
|
163
164
|
});
|
|
164
165
|
|
|
165
166
|
it("omits the whole methods block when the list is empty", () => {
|
|
166
167
|
const c = mount(h(HkLoginFlow, { channels: [cloudChannel], modelValue: "cloud" }));
|
|
167
|
-
// An empty methods list must not pad a dead strip under the form
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
// An empty methods list must not pad a dead strip under the form
|
|
169
|
+
// (the operative pin is the channel list's absence — the retired
|
|
170
|
+
// tile wrapper's absence is not observable here, R2).
|
|
171
|
+
expect(c.querySelector(".hk-auth-channel-list")).toBeNull();
|
|
172
|
+
expect(c.querySelector(".hk-auth-channel-divider")).toBeNull();
|
|
170
173
|
});
|
|
171
174
|
});
|
|
172
175
|
|
|
173
176
|
describe("HkLoginFlow — sso channel", () => {
|
|
174
|
-
it("renders
|
|
177
|
+
it("renders the channel's destination row and emits sso-click", async () => {
|
|
175
178
|
const onClick = vi.fn();
|
|
176
179
|
const c = mount(
|
|
177
180
|
h(HkLoginFlow, {
|
|
@@ -180,9 +183,13 @@ describe("HkLoginFlow — sso channel", () => {
|
|
|
180
183
|
onSsoClick: onClick,
|
|
181
184
|
}),
|
|
182
185
|
);
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
+
// The 2026-11 list form: the destination renders as a standard
|
|
187
|
+
// channel row (icon left, name right) — not a square tile.
|
|
188
|
+
const row = c.querySelector<HTMLButtonElement>(".hk-auth-channel-row");
|
|
189
|
+
expect(row).not.toBeNull();
|
|
190
|
+
// No buttonLabel on the fixture → the conventional channel label.
|
|
191
|
+
expect(row!.getAttribute("aria-label")).toBe("Organization login");
|
|
192
|
+
row!.click();
|
|
186
193
|
await nextTick();
|
|
187
194
|
expect(onClick).toHaveBeenCalledWith("org");
|
|
188
195
|
});
|
|
@@ -198,7 +205,7 @@ describe("HkLoginFlow — sso channel", () => {
|
|
|
198
205
|
);
|
|
199
206
|
// A redirect flow has no second step by construction; the panel
|
|
200
207
|
// keeps showing the account card instead of a dead MFA card.
|
|
201
|
-
expect(c.querySelector(".hk-auth-
|
|
208
|
+
expect(c.querySelector(".hk-auth-channel-row")).not.toBeNull();
|
|
202
209
|
});
|
|
203
210
|
});
|
|
204
211
|
|
|
@@ -3,8 +3,7 @@ import { computed, defineComponent, ref, type PropType } from "vue";
|
|
|
3
3
|
import { useI18n } from "../i18n/context";
|
|
4
4
|
import { asPropType } from "../utils/typing";
|
|
5
5
|
import { HkAuthCard } from "./HkAuthCard";
|
|
6
|
-
import
|
|
7
|
-
import { HkAuthSsoButton } from "./HkAuthSsoButton";
|
|
6
|
+
import { HkAuthChannelList, type HkAuthChannelListEntry } from "./HkAuthChannelList";
|
|
8
7
|
import { HkMfaVerifyCard, type HkMfaFactor } from "./HkMfaVerifyCard";
|
|
9
8
|
import { HkSignInCard } from "./HkSignInCard";
|
|
10
9
|
import HkStepFlow from "./HkStepFlow";
|
|
@@ -45,28 +44,29 @@ export interface HkLoginCredentialsChannel {
|
|
|
45
44
|
* opening card must not ask for it (2026-11 user direction). */
|
|
46
45
|
passwordField?: boolean;
|
|
47
46
|
submitLabel?: string;
|
|
48
|
-
/** Alternative sign-in
|
|
47
|
+
/** Alternative sign-in rows under the form (rendered only when
|
|
49
48
|
* non-empty; an empty list omits the whole methods block instead of
|
|
50
49
|
* padding a dead strip). */
|
|
51
|
-
methods?:
|
|
52
|
-
/** Divider text above the
|
|
50
|
+
methods?: HkAuthChannelListEntry[];
|
|
51
|
+
/** Divider text above the rows; consumer-localized on purpose. */
|
|
53
52
|
methodsDivider?: string;
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
/** A channel whose whole sign-in is one redirect (a.celestia.world's
|
|
57
|
-
* "Celestia"
|
|
58
|
-
* only offers Feishu): the card renders
|
|
59
|
-
*
|
|
56
|
+
* "Celestia" row jumping to the central login, an org channel that
|
|
57
|
+
* only offers Feishu): the card renders the standard channel list —
|
|
58
|
+
* one full-width row naming the destination — and `sso-click` sends
|
|
59
|
+
* the host off to build its OAuth URL. */
|
|
60
60
|
export interface HkLoginSsoChannel {
|
|
61
61
|
key: string;
|
|
62
62
|
mode: "sso";
|
|
63
63
|
label?: string;
|
|
64
64
|
title?: string;
|
|
65
65
|
subtitle?: string;
|
|
66
|
-
/** Provider mark for the
|
|
66
|
+
/** Provider mark for the row (brand SVG, <img>, …). Loose-typed like
|
|
67
67
|
* every auth icon: hosts materialize hikari against their own vue. */
|
|
68
68
|
icon: unknown;
|
|
69
|
-
/**
|
|
69
|
+
/** The row's label (accessible name + visible text); defaults to the
|
|
70
70
|
* label. */
|
|
71
71
|
buttonLabel?: string;
|
|
72
72
|
disabled?: boolean;
|
|
@@ -85,7 +85,7 @@ export type HkLoginChannel = HkLoginCredentialsChannel | HkLoginSsoChannel;
|
|
|
85
85
|
* visual — the pill segment group (hidden when a deployment offers a
|
|
86
86
|
* single channel; a lone dead segment reads as a broken switch), the
|
|
87
87
|
* height-morphing channel swap, the direction-aware account→verify
|
|
88
|
-
* slide, the methods
|
|
88
|
+
* slide, the methods rows, the MFA card — while staying a CONTROLLED
|
|
89
89
|
* component: no endpoint, no URL building, no factor ladder policy.
|
|
90
90
|
* Each host (the chest migration plus the erp and arona login surfaces,
|
|
91
91
|
* landing as their own PRs) keeps its own auth client and drives the
|
|
@@ -99,8 +99,8 @@ export type HkLoginChannel = HkLoginCredentialsChannel | HkLoginSsoChannel;
|
|
|
99
99
|
* channel renders the account card as a fail-safe).
|
|
100
100
|
* - `account-submit(channel, username, password)` — credentials
|
|
101
101
|
* channel submitted (password is empty while `passwordField` is off).
|
|
102
|
-
* - `method-select(channel, key)` — an alternative
|
|
103
|
-
* - `sso-click(channel)` — the primary sso
|
|
102
|
+
* - `method-select(channel, key)` — an alternative method row was picked.
|
|
103
|
+
* - `sso-click(channel)` — the primary sso row was picked.
|
|
104
104
|
* - `verify(kind, proof)` / `verify-resend` / `verify-back` — the MFA
|
|
105
105
|
* card's events, re-emitted one level up.
|
|
106
106
|
*
|
|
@@ -256,7 +256,7 @@ export const HkLoginFlow = defineComponent({
|
|
|
256
256
|
...(methods.length > 0
|
|
257
257
|
? {
|
|
258
258
|
methods: () => (
|
|
259
|
-
<
|
|
259
|
+
<HkAuthChannelList
|
|
260
260
|
divider={channel.methodsDivider}
|
|
261
261
|
methods={methods}
|
|
262
262
|
onSelect={(key: string) => emit("method-select", channel.key, key)}
|
|
@@ -291,11 +291,16 @@ export const HkLoginFlow = defineComponent({
|
|
|
291
291
|
<>
|
|
292
292
|
{tabsEl()}
|
|
293
293
|
<div class="hk-login-flow-sso">
|
|
294
|
-
<
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
294
|
+
<HkAuthChannelList
|
|
295
|
+
methods={[
|
|
296
|
+
{
|
|
297
|
+
key: channel.key,
|
|
298
|
+
label: channel.buttonLabel ?? channelLabel(channel),
|
|
299
|
+
icon: channel.icon,
|
|
300
|
+
disabled: channel.disabled,
|
|
301
|
+
},
|
|
302
|
+
]}
|
|
303
|
+
onSelect={() => emit("sso-click", channel.key)}
|
|
299
304
|
/>
|
|
300
305
|
</div>
|
|
301
306
|
</>
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// Cold-path pins for the highlight composable.
|
|
2
|
+
//
|
|
3
|
+
// Why this file exists, separately from `useHighlight.hostSurface.test.ts`:
|
|
4
|
+
// that file warms the composable in `beforeAll` and then asserts against the
|
|
5
|
+
// loaded state, so it can only see the *hot* path. The contract this composable
|
|
6
|
+
// actually documents lives on the **cold** path — first call renders plaintext
|
|
7
|
+
// and starts exactly one load, `version` bumps when that load resolves, a failed
|
|
8
|
+
// load retries on the next call. Measured: deleting the version bump, leaving a
|
|
9
|
+
// failed load permanently stuck, or serving a placeholder surface all kept the
|
|
10
|
+
// warmed pins green, because none of them observes a cold instance.
|
|
11
|
+
//
|
|
12
|
+
// Each case here gets a **fresh module instance** via `vi.resetModules()` and a
|
|
13
|
+
// fresh client mock, so nothing carries over between them. That is the whole
|
|
14
|
+
// point of the file; do not add a shared `beforeAll` warm-up.
|
|
15
|
+
//
|
|
16
|
+
// (Run from `packages/vue` — that is where vite.config.ts registers the plugins.)
|
|
17
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
18
|
+
|
|
19
|
+
interface ClientState {
|
|
20
|
+
/** How many times the async door was asked to build. */
|
|
21
|
+
builds: number;
|
|
22
|
+
/** Fail this many leading builds, then behave normally. */
|
|
23
|
+
failFirst: number;
|
|
24
|
+
/** Resolve with a placeholder surface on the first build. */
|
|
25
|
+
placeholderFirst: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const client: ClientState = { builds: 0, failFirst: 0, placeholderFirst: false };
|
|
29
|
+
|
|
30
|
+
// The mock is installed once, but its behaviour is driven by `client`, which
|
|
31
|
+
// each case resets — so no case inherits another's failure mode.
|
|
32
|
+
vi.mock("@celestia-island/tairitsu-host-client", async (importOriginal) => {
|
|
33
|
+
const actual = await importOriginal<
|
|
34
|
+
typeof import("@celestia-island/tairitsu-host-client")
|
|
35
|
+
>();
|
|
36
|
+
return {
|
|
37
|
+
...actual,
|
|
38
|
+
loadComponent: async (
|
|
39
|
+
options: Parameters<typeof actual.loadComponent>[0],
|
|
40
|
+
): ReturnType<typeof actual.loadComponent> => {
|
|
41
|
+
client.builds += 1;
|
|
42
|
+
if (client.builds <= client.failFirst) {
|
|
43
|
+
throw new Error("simulated transient load failure");
|
|
44
|
+
}
|
|
45
|
+
if (client.placeholderFirst && client.builds === 1) {
|
|
46
|
+
// A surface that resolves but cannot serve the export.
|
|
47
|
+
return {
|
|
48
|
+
exports: {},
|
|
49
|
+
call: () => {
|
|
50
|
+
throw new actual.HostClientError("no-export", "the component exports no \"highlight\"");
|
|
51
|
+
},
|
|
52
|
+
stop: async () => {},
|
|
53
|
+
whenIdle: async () => {},
|
|
54
|
+
stopped: false,
|
|
55
|
+
} as unknown as Awaited<ReturnType<typeof actual.loadComponent>>;
|
|
56
|
+
}
|
|
57
|
+
return actual.loadComponent(options);
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
/** A cold instance of the composable: no module cache, nothing warmed. */
|
|
63
|
+
async function freshComposable() {
|
|
64
|
+
vi.resetModules();
|
|
65
|
+
return await import("./useHighlight");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Give the lazy load room to resolve / fail. Real timers: a fake clock stalls
|
|
69
|
+
* the dynamic import (measured). Polls rather than sleeping a fixed budget —
|
|
70
|
+
* a cold module instance pays the full 3.2 MB parse on first use, and a fixed
|
|
71
|
+
* wait that was long enough in one case was short in another. */
|
|
72
|
+
async function tick(until: () => boolean = () => false, ms = 6000): Promise<void> {
|
|
73
|
+
const deadline = Date.now() + ms;
|
|
74
|
+
while (Date.now() < deadline) {
|
|
75
|
+
if (until()) return;
|
|
76
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
describe("highlight cold path", () => {
|
|
81
|
+
beforeEach(() => {
|
|
82
|
+
client.builds = 0;
|
|
83
|
+
client.failFirst = 0;
|
|
84
|
+
client.placeholderFirst = false;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("first call returns escaped plaintext and starts exactly one load", async () => {
|
|
88
|
+
const { highlight } = await freshComposable();
|
|
89
|
+
const html = highlight("<a> & b", "rust");
|
|
90
|
+
|
|
91
|
+
// The pre-load answer is the *escaped source*, not the raw source.
|
|
92
|
+
expect(html).toBe("<a> & b");
|
|
93
|
+
// Exactly one door build was kicked off by that call.
|
|
94
|
+
expect(client.builds).toBe(1);
|
|
95
|
+
// …and it lands, so a second call is highlighted rather than plaintext.
|
|
96
|
+
await tick(() => highlight("<a> & b", "rust").includes("hljs"));
|
|
97
|
+
expect(highlight("<a> & b", "rust")).toContain("hljs");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("bumps version exactly once when the load resolves", async () => {
|
|
101
|
+
const { highlight, useHighlight } = await freshComposable();
|
|
102
|
+
const { version } = useHighlight();
|
|
103
|
+
expect(version.value).toBe(0);
|
|
104
|
+
highlight("fn main() {}", "rust");
|
|
105
|
+
await tick(() => version.value === 1);
|
|
106
|
+
expect(version.value).toBe(1);
|
|
107
|
+
// A further call must not bump it again — the surface is cached.
|
|
108
|
+
highlight("fn main() {}", "rust");
|
|
109
|
+
expect(version.value).toBe(1);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("makes a single build for two concurrent first calls", async () => {
|
|
113
|
+
const { highlight } = await freshComposable();
|
|
114
|
+
// Two cold calls before the first load resolves must collapse into one door
|
|
115
|
+
// build.
|
|
116
|
+
//
|
|
117
|
+
// Scope, precisely (both clauses measured): removing `highlight()`'s own
|
|
118
|
+
// `if (!surface && !loadPromise)` guard does NOT produce a second build
|
|
119
|
+
// (still 1), and neither does deleting the `loadPromise` cache inside
|
|
120
|
+
// `ensureLoaded` — the two calls both reach the guard before the first
|
|
121
|
+
// `await`, so the collapse holds without either. This case therefore pins
|
|
122
|
+
// the observable property (one build for two concurrent cold calls), not a
|
|
123
|
+
// particular guard: both guard removals stay green here.
|
|
124
|
+
highlight("fn a() {}", "rust");
|
|
125
|
+
highlight("fn b() {}", "rust");
|
|
126
|
+
await tick(() => highlight("fn a() {}", "rust").includes("hljs"));
|
|
127
|
+
expect(client.builds).toBe(1);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("retries a failed load on the next call instead of staying plaintext", async () => {
|
|
131
|
+
client.failFirst = 1;
|
|
132
|
+
const { highlight, useHighlight } = await freshComposable();
|
|
133
|
+
const { version } = useHighlight();
|
|
134
|
+
|
|
135
|
+
// First call: plaintext, load fails.
|
|
136
|
+
expect(highlight("fn main() {}", "rust")).toBe("fn main() {}");
|
|
137
|
+
expect(client.builds).toBe(1);
|
|
138
|
+
await tick(() => version.value !== 0, 400);
|
|
139
|
+
expect(version.value).toBe(0); // nothing resolved, so nothing bumped
|
|
140
|
+
|
|
141
|
+
// Second call retries: a second build must happen and succeed.
|
|
142
|
+
highlight("fn main() {}", "rust");
|
|
143
|
+
expect(client.builds).toBe(2);
|
|
144
|
+
await tick(() => version.value === 1);
|
|
145
|
+
expect(version.value).toBe(1);
|
|
146
|
+
expect(highlight("fn main() {}", "rust")).toContain("hljs");
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("degrades to plaintext when the surface cannot serve the export", async () => {
|
|
150
|
+
// A surface that resolves but throws on the call — a guest trap, or a
|
|
151
|
+
// wrapper that does not carry the export. The documented contract is
|
|
152
|
+
// "plain text until the module loads", and callers (`HkDiffViewer`) call
|
|
153
|
+
// this straight from a render, so a throw here breaks the view.
|
|
154
|
+
// Measured before the guard: `HostClientError: no-export` propagated out of
|
|
155
|
+
// `highlight()`.
|
|
156
|
+
client.placeholderFirst = true;
|
|
157
|
+
const { highlight } = await freshComposable();
|
|
158
|
+
highlight("fn main() {}", "rust");
|
|
159
|
+
await tick(() => false, 900);
|
|
160
|
+
expect(highlight("<a> & b", "rust")).toBe("<a> & b");
|
|
161
|
+
});
|
|
162
|
+
});
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// Wiring pins for the highlight composable: the component must be loaded
|
|
2
|
+
// **through the tairitsu host client's async door** (`loadComponent`), and the
|
|
3
|
+
// highlighting must come **through the surface that door returns**, not from a
|
|
4
|
+
// bare `import()` of the wrapper.
|
|
5
|
+
//
|
|
6
|
+
// Why a separate file: the frozen tests (`useHighlight.adaptResult.test.ts`,
|
|
7
|
+
// `useHighlight.languageForPath.test.ts`) pin the record adapter and the
|
|
8
|
+
// path→language table. Neither can see the loader: a bare `import()` of the
|
|
9
|
+
// generated wrapper produces identical highlighting, and no fixture-level
|
|
10
|
+
// assertion notices which module graph produced it. These pins observe the load
|
|
11
|
+
// seam itself.
|
|
12
|
+
//
|
|
13
|
+
// The four pins below are the shape QR (#1476) and scene3d (#1478) converged on.
|
|
14
|
+
// The build count here counts `loadComponent` calls, because this component is
|
|
15
|
+
// lazily loaded — there is no module-load-time surface to count.
|
|
16
|
+
// ① build count, asserted AFTER a call has run (the door is retryable, so a
|
|
17
|
+
// lazy second `loadComponent` would otherwise be invisible);
|
|
18
|
+
// ② the capabilities pin reads the FIRST build (a later load must not make it
|
|
19
|
+
// fail with `undefined`, i.e. for the wrong reason);
|
|
20
|
+
// ③ the data path: substitute the door's return and require the caller's
|
|
21
|
+
// value to be that substitution;
|
|
22
|
+
// ④ every assertion named in a comment here exists in this file.
|
|
23
|
+
//
|
|
24
|
+
// (Run from `packages/vue` — that is where vite.config.ts registers the plugins.)
|
|
25
|
+
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
26
|
+
|
|
27
|
+
interface Seam {
|
|
28
|
+
/** The options of every `loadComponent` call, in order. */
|
|
29
|
+
builds: Array<Record<string, unknown>>;
|
|
30
|
+
/** Argument list of every `surface.call(name, …)`. */
|
|
31
|
+
calls: Array<{ name: string; args: unknown[] }>;
|
|
32
|
+
/**
|
|
33
|
+
* Test seam: when set, the wrapped door delegates to this instead of the real
|
|
34
|
+
* export. Lets a probe substitute the door's return value and see whether the
|
|
35
|
+
* caller consumes it.
|
|
36
|
+
*/
|
|
37
|
+
doorOverride?: (name: string, ...args: unknown[]) => unknown;
|
|
38
|
+
/** Set when `loadComponent` resolved — the surface exists from then on. */
|
|
39
|
+
loaded: boolean;
|
|
40
|
+
/** The most recently returned surface object, for identity assertions. */
|
|
41
|
+
surfaceIdentity: unknown;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const seam: Seam = {
|
|
45
|
+
builds: [],
|
|
46
|
+
calls: [],
|
|
47
|
+
doorOverride: undefined,
|
|
48
|
+
loaded: false,
|
|
49
|
+
surfaceIdentity: undefined,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
vi.mock("@celestia-island/tairitsu-host-client", async (importOriginal) => {
|
|
53
|
+
const actual = await importOriginal<
|
|
54
|
+
typeof import("@celestia-island/tairitsu-host-client")
|
|
55
|
+
>();
|
|
56
|
+
return {
|
|
57
|
+
...actual,
|
|
58
|
+
loadComponent: async (
|
|
59
|
+
options: Parameters<typeof actual.loadComponent>[0],
|
|
60
|
+
): ReturnType<typeof actual.loadComponent> => {
|
|
61
|
+
// Every load is recorded, not just the first: the door is retryable, so a
|
|
62
|
+
// second `loadComponent` would otherwise be invisible to a
|
|
63
|
+
// first-call-only pin.
|
|
64
|
+
seam.builds.push(options as Record<string, unknown>);
|
|
65
|
+
const live = await actual.loadComponent(options);
|
|
66
|
+
seam.loaded = true;
|
|
67
|
+
seam.surfaceIdentity = live;
|
|
68
|
+
const realCall = live.call.bind(live);
|
|
69
|
+
// Wrap the surface's call door: this is where the highlighting must
|
|
70
|
+
// arrive.
|
|
71
|
+
live.call = ((name: string, ...args: unknown[]) => {
|
|
72
|
+
seam.calls.push({ name, args });
|
|
73
|
+
if (seam.doorOverride !== undefined) {
|
|
74
|
+
return seam.doorOverride(name, ...args);
|
|
75
|
+
}
|
|
76
|
+
return realCall(name, ...args);
|
|
77
|
+
}) as typeof live.call;
|
|
78
|
+
return live;
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const { highlight } = await import("./useHighlight");
|
|
84
|
+
const realWrapper = await import("../wasm/highlight/hikari_wasm_highlight.js");
|
|
85
|
+
|
|
86
|
+
const CODE = "fn main() { println!(\"hi\"); }";
|
|
87
|
+
const LANG = "rust";
|
|
88
|
+
|
|
89
|
+
/** Let the lazy load settle.
|
|
90
|
+
*
|
|
91
|
+
* Real timers, not fake ones: the load is a genuine dynamic `import()` of the
|
|
92
|
+
* ~3.2 MB artifact, and a fake clock would stall it (measured — under
|
|
93
|
+
* `vi.useFakeTimers()` the module never finishes loading and every pin that
|
|
94
|
+
* waits for a call fails). The loop caps at 70 × 25 ms ≈ 1.75 s; actual
|
|
95
|
+
* completion is well under 100 ms on a warm cache. */
|
|
96
|
+
async function settle(): Promise<void> {
|
|
97
|
+
for (let i = 0; i < 70; i++) {
|
|
98
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
99
|
+
if (surfaceReady()) return;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* True once the composable holds a surface.
|
|
105
|
+
*
|
|
106
|
+
* The load is deliberately NOT observable as a call: the first `highlight()`
|
|
107
|
+
* renders plaintext and kicks the load off, and only the *next* call reaches
|
|
108
|
+
* the door (measured — see the probe in the module comment). So "a call has
|
|
109
|
+
* happened" only becomes true after the test itself calls again, and waiting on
|
|
110
|
+
* it before that point would always time out.
|
|
111
|
+
*/
|
|
112
|
+
function surfaceReady(): boolean {
|
|
113
|
+
return seam.loaded;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
describe("highlight loads through the host client", () => {
|
|
117
|
+
// The surface is module-level state, cached after the first successful load —
|
|
118
|
+
// so it is loaded once here and every case below runs against that one door.
|
|
119
|
+
// `builds` is therefore 1 for the whole file; the per-case assertions about
|
|
120
|
+
// "still one build" are about a second load NOT happening.
|
|
121
|
+
let firstSurface: unknown;
|
|
122
|
+
beforeAll(async () => {
|
|
123
|
+
highlight(CODE, LANG);
|
|
124
|
+
await settle();
|
|
125
|
+
firstSurface = seam.surfaceIdentity;
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
beforeEach(() => {
|
|
129
|
+
seam.calls.length = 0;
|
|
130
|
+
seam.doorOverride = undefined;
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("loads the wrapper through loadComponent, not a bare import", async () => {
|
|
134
|
+
// Exactly one build so far. ① The factory is retryable, so this is
|
|
135
|
+
// asserted after a call has run rather than at import time.
|
|
136
|
+
expect(seam.builds).toHaveLength(1);
|
|
137
|
+
|
|
138
|
+
const options = seam.builds[0]!;
|
|
139
|
+
// The declaration reaches the door as the component's own object shape.
|
|
140
|
+
expect(options.capabilities).toEqual({ interfaces: [], wasiModules: [] });
|
|
141
|
+
// The load itself is a RELATIVE SPECIFIER through the client's
|
|
142
|
+
// `loaders.importModule` hook — not a bare `import()` of this module and
|
|
143
|
+
// not a URL built from `import.meta.url` (which resolves to a non-`file:`
|
|
144
|
+
// origin the ESM loader rejects; measured).
|
|
145
|
+
const loaders = options.loaders as
|
|
146
|
+
| { importModule?: (url: string) => Promise<unknown> }
|
|
147
|
+
| undefined;
|
|
148
|
+
expect(typeof loaders?.importModule).toBe("function");
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("declares an empty capability set on the first load", () => {
|
|
152
|
+
// ② Read from the FIRST build.
|
|
153
|
+
//
|
|
154
|
+
// Measured, so the scope is exact rather than assumed: dropping
|
|
155
|
+
// `capabilities` from the `loadComponent` call reds this case AND the one
|
|
156
|
+
// above (which asserts `options.capabilities` too) — two reds, not one.
|
|
157
|
+
// What it does NOT do is touch the three call-path cases below, so a
|
|
158
|
+
// failure here still points at the declaration rather than at the loader.
|
|
159
|
+
expect(seam.builds[0]!.capabilities).toEqual({
|
|
160
|
+
interfaces: [],
|
|
161
|
+
wasiModules: [],
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("calls the component export through the surface, not the wrapper", () => {
|
|
166
|
+
// A second call must reuse the loaded surface rather than loading again.
|
|
167
|
+
highlight(CODE, LANG);
|
|
168
|
+
|
|
169
|
+
// A bare `import()` returns the same highlighting but never reaches this
|
|
170
|
+
// door, so the array stays empty. Measured: replacing the surface call with
|
|
171
|
+
// a direct wrapper read reds this case plus the two below.
|
|
172
|
+
const highlightCalls = seam.calls.filter((c) => c.name === "highlight");
|
|
173
|
+
expect(highlightCalls).toHaveLength(1);
|
|
174
|
+
expect(highlightCalls[0]!.args[0]).toBe(CODE);
|
|
175
|
+
expect(highlightCalls[0]!.args[1]).toBe(LANG);
|
|
176
|
+
|
|
177
|
+
// ① Still exactly one load after a second call.
|
|
178
|
+
//
|
|
179
|
+
// Scope, precisely (measured, not assumed): this catches a load issued
|
|
180
|
+
// synchronously during the call. It does NOT catch a later asynchronous
|
|
181
|
+
// reload — one that clears the cached promise still short-circuits on the
|
|
182
|
+
// existing `if (surface) return`, so no second load happens at all; and a
|
|
183
|
+
// reload driven from outside the composable keeps all five cases green.
|
|
184
|
+
// The surface is cached by early return rather than by a guard the pins can
|
|
185
|
+
// observe, so "only ever one door" here rests on that `if (surface)` line,
|
|
186
|
+
// not on this assertion.
|
|
187
|
+
expect(seam.builds).toHaveLength(1);
|
|
188
|
+
expect(seam.surfaceIdentity).toBe(firstSurface);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("uses the value the observed door returned, not a parallel import", () => {
|
|
192
|
+
// ③ Substitute the door's return for one call. A loader that consults the
|
|
193
|
+
// door but takes its HTML from the raw namespace yields the real markup and
|
|
194
|
+
// fails here.
|
|
195
|
+
seam.doorOverride = () => ({ html: "<b>MARKED</b>" });
|
|
196
|
+
const substituted = highlight(CODE, LANG);
|
|
197
|
+
seam.doorOverride = undefined;
|
|
198
|
+
|
|
199
|
+
expect(substituted).toBe("<b>MARKED</b>");
|
|
200
|
+
// And the real path still works once the override is gone.
|
|
201
|
+
const real = highlight(CODE, LANG);
|
|
202
|
+
expect(real).not.toBe("<b>MARKED</b>");
|
|
203
|
+
expect(real).toContain("hljs");
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("adapts the record the door returns, and honours a declined result", () => {
|
|
207
|
+
// An omitted `html` is the component's "no answer" — the caller must get
|
|
208
|
+
// escaped plaintext, not the record.
|
|
209
|
+
seam.doorOverride = () => ({});
|
|
210
|
+
const declined = highlight("<a>", LANG);
|
|
211
|
+
seam.doorOverride = undefined;
|
|
212
|
+
|
|
213
|
+
expect(declined).toBe("<a>");
|
|
214
|
+
expect(typeof declined).toBe("string");
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
/** The artifact's own export, kept for reference by the substitution case above
|
|
219
|
+
* (it is what the real door calls). */
|
|
220
|
+
void realWrapper;
|
|
@@ -1,42 +1,106 @@
|
|
|
1
1
|
// wasm syntax highlighting — single source of truth, lazily loaded.
|
|
2
2
|
//
|
|
3
3
|
// The pest-driven Rust wasm component (hikari-wasm-highlight) handles
|
|
4
|
-
// all supported languages. The 2
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
// module instead of 85 JS
|
|
4
|
+
// all supported languages. The artifact is ~3.2 MB (3,306,474 bytes; an
|
|
5
|
+
// earlier "2.9MB" here was stale) and is code-split by Vite via dynamic
|
|
6
|
+
// import() — it loads on the first highlight() call, not at bundle
|
|
7
|
+
// initialization. Until loaded, code renders as plain text (same UX as the old
|
|
8
|
+
// hljs lazy loading, but with a single Rust wasm module instead of 85 JS
|
|
9
|
+
// grammar chunks).
|
|
10
|
+
//
|
|
11
|
+
// Loading goes through the tairitsu host client's ASYNC door
|
|
12
|
+
// (`loadComponent`), not a bare `import()`: the client publishes the
|
|
13
|
+
// capability declaration before it evaluates the wrapper, which is an
|
|
14
|
+
// ordering a bare import cannot give you (ES imports hoist, so a statement
|
|
15
|
+
// in this file can never run earlier than the import it is meant to guard).
|
|
16
|
+
// `highlight()` stays synchronous — the load resolves in the background and
|
|
17
|
+
// `version` re-runs the render effects, so the visible contract is unchanged.
|
|
18
|
+
//
|
|
19
|
+
// Measured behaviour this file's comments rely on (each verified by probe, not
|
|
20
|
+
// assumed): the first call renders escaped plaintext and starts the load; the
|
|
21
|
+
// next call reaches the surface; a failed load leaves plaintext and the
|
|
22
|
+
// following call retries; and `version` goes 0 → 1 when the load resolves.
|
|
9
23
|
|
|
10
24
|
import { ref } from "vue";
|
|
25
|
+
import {
|
|
26
|
+
HostClientError,
|
|
27
|
+
loadComponent,
|
|
28
|
+
type HostComponent,
|
|
29
|
+
} from "@celestia-island/tairitsu-host-client";
|
|
11
30
|
import type { HighlightResult } from "../wasm/highlight/hikari_wasm_highlight.js";
|
|
12
31
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
32
|
+
/**
|
|
33
|
+
* The capability declaration this component runs under.
|
|
34
|
+
*
|
|
35
|
+
* Empty is not cosmetic: the highlight artifact has no glue interface (its
|
|
36
|
+
* `interfaces/` are type declarations only) and gets WASI from its own direct
|
|
37
|
+
* `@bytecodealliance/preview2-shim/*` imports. Declaring anything here makes
|
|
38
|
+
* `buildImports` refuse the load before the wrapper is evaluated.
|
|
39
|
+
*/
|
|
40
|
+
const HIGHLIGHT_CAPABILITIES = { interfaces: [] as string[], wasiModules: [] as string[] } as const;
|
|
19
41
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
42
|
+
/** The wrapper's export name. jco names JS exports in the component's own
|
|
43
|
+
* identifier style; this one is a bare `highlight`, which is also the WIT func
|
|
44
|
+
* name — unlike scene3d, whose WIT `build-fleet-scene` becomes `buildFleetScene`.
|
|
45
|
+
* The host client's `pickExport` looks up an exact own property, so this must
|
|
46
|
+
* match the export exactly. */
|
|
47
|
+
const HIGHLIGHT_EXPORT = "highlight";
|
|
23
48
|
|
|
24
|
-
//
|
|
49
|
+
// Module-level state: the call surface (null until loaded). The surface is the
|
|
50
|
+
// host client's synchronous door onto the component — `surface.call("highlight",
|
|
51
|
+
// code, lang)` — so the hot path never touches the promise again.
|
|
52
|
+
let surface: HostComponent | null = null;
|
|
53
|
+
let loadPromise: Promise<HostComponent | null> | null = null;
|
|
54
|
+
|
|
55
|
+
// Reactive version — bumped when the component finishes loading so
|
|
25
56
|
// computed/render effects re-run and replace plain text with color.
|
|
26
57
|
const version = ref(0);
|
|
27
58
|
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Load the component on first use through the host client; cached thereafter.
|
|
61
|
+
*
|
|
62
|
+
* A failed load resolves `null` and clears `loadPromise`, which is the existing
|
|
63
|
+
* behaviour: the next `highlight()` call retries, and until one succeeds every
|
|
64
|
+
* call renders plaintext.
|
|
65
|
+
*/
|
|
66
|
+
function ensureLoaded(): Promise<HostComponent | null> {
|
|
67
|
+
if (surface) return Promise.resolve(surface);
|
|
31
68
|
if (!loadPromise) {
|
|
32
|
-
loadPromise =
|
|
33
|
-
.
|
|
34
|
-
|
|
69
|
+
loadPromise = loadComponent({
|
|
70
|
+
wrapper: "hikari_wasm_highlight.js",
|
|
71
|
+
capabilities: HIGHLIGHT_CAPABILITIES,
|
|
72
|
+
// A RELATIVE SPECIFIER, not a URL built from `import.meta.url`.
|
|
73
|
+
// The client's own fallback is `import(target)`, and a URL derived from
|
|
74
|
+
// `import.meta.url` resolves to the bundler's origin (an `http://` dev
|
|
75
|
+
// server) or to the wrong directory under Node — both of which the ESM
|
|
76
|
+
// loader rejects ("Only URLs with a scheme in: file and data are
|
|
77
|
+
// supported"; measured). A relative specifier is what the previous
|
|
78
|
+
// `import()` used, keeps the artifact in its own chunk, and is resolved
|
|
79
|
+
// by whichever loader is running.
|
|
80
|
+
loaders: {
|
|
81
|
+
// A STATIC-ANALYSABLE import: the specifier is a literal, so Vite emits
|
|
82
|
+
// the artifact as its own chunk and the module stays
|
|
83
|
+
// `vi.mock`-replaceable. (The exact chunk sizes depend on the build
|
|
84
|
+
// config — two reviewers and I measured three different entry sizes —
|
|
85
|
+
// so what is reproducible is the *split*: the artifact is its own file
|
|
86
|
+
// and the entry does not reference it statically; measured.) A
|
|
87
|
+
// `/* @vite-ignore */` here would silence the bundler's static analysis
|
|
88
|
+
// for no benefit — measured, it did NOT actually break `vi.mock` under
|
|
89
|
+
// this Vite/vitest, so the reason to omit it is generality, not a bug
|
|
90
|
+
// it caused.
|
|
91
|
+
importModule: () =>
|
|
92
|
+
import(
|
|
93
|
+
"../wasm/highlight/hikari_wasm_highlight.js"
|
|
94
|
+
) as Promise<Record<string, unknown>>,
|
|
95
|
+
},
|
|
96
|
+
})
|
|
97
|
+
.then((loaded) => {
|
|
98
|
+
surface = loaded;
|
|
35
99
|
version.value += 1;
|
|
36
|
-
return
|
|
100
|
+
return loaded;
|
|
37
101
|
})
|
|
38
102
|
.catch(() => {
|
|
39
|
-
//
|
|
103
|
+
// Load failed — stay plaintext and let the next call retry.
|
|
40
104
|
loadPromise = null;
|
|
41
105
|
return null;
|
|
42
106
|
});
|
|
@@ -91,12 +155,23 @@ export function highlight(code: string, lang?: string): string {
|
|
|
91
155
|
void version.value;
|
|
92
156
|
|
|
93
157
|
const name = lang ? normalize(lang) : "";
|
|
94
|
-
if (name &&
|
|
95
|
-
|
|
96
|
-
|
|
158
|
+
if (name && surface) {
|
|
159
|
+
// A surface that resolves but cannot serve the export (or whose guest traps)
|
|
160
|
+
// must degrade to plaintext, not throw into a render: this composable's
|
|
161
|
+
// documented contract is "plain text until the module loads", and callers
|
|
162
|
+
// (`HkDiffViewer`) call it directly inside a render. Measured before the
|
|
163
|
+
// guard: a surface missing the export threw `no-export` straight through.
|
|
164
|
+
try {
|
|
165
|
+
const html = adaptHighlightResult(
|
|
166
|
+
surface.call<HighlightResult>(HIGHLIGHT_EXPORT, code, name),
|
|
167
|
+
);
|
|
168
|
+
if (html !== null) return html;
|
|
169
|
+
} catch {
|
|
170
|
+
// Fall through to escaped plaintext.
|
|
171
|
+
}
|
|
97
172
|
}
|
|
98
173
|
// Trigger the lazy load (first call only); render plain text for now.
|
|
99
|
-
if (!
|
|
174
|
+
if (!surface && !loadPromise) {
|
|
100
175
|
void ensureLoaded();
|
|
101
176
|
}
|
|
102
177
|
return escapeHtml(code);
|
package/src/index.ts
CHANGED
|
@@ -1092,6 +1092,8 @@ export { type HkLoginChannel as HkLoginChannel } from "./components/HkLoginFlow"
|
|
|
1092
1092
|
export { type HkLoginCredentialsChannel as HkLoginCredentialsChannel } from "./components/HkLoginFlow";
|
|
1093
1093
|
export { type HkLoginSsoChannel as HkLoginSsoChannel } from "./components/HkLoginFlow";
|
|
1094
1094
|
export { HkAuthSsoButton as HkAuthSsoButton } from "./components/HkAuthSsoButton";
|
|
1095
|
+
export { HkAuthChannelList as HkAuthChannelList } from "./components/HkAuthChannelList";
|
|
1096
|
+
export { type HkAuthChannelListEntry as HkAuthChannelListEntry } from "./components/HkAuthChannelList";
|
|
1095
1097
|
export { HkLocalePicker as HkLocalePicker } from "./components/HkLocalePicker";
|
|
1096
1098
|
export { HkAdminTablePage as HkAdminTablePage } from "./components/HkAdminTablePage";
|
|
1097
1099
|
export { HkPageHeader as HkPageHeader } from "./components/HkPageHeader";
|