@celestia-island/hikari 0.55.472 → 0.55.474
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 +8 -1
- package/dist/types/components/HkAuthHandoff.d.ts +132 -0
- package/dist/types/components/HkLoginFlow.d.ts +5 -0
- package/dist/types/components/HkStatusBar.d.ts +1 -1
- package/dist/types/components/loginDiscovery.d.ts +90 -0
- package/dist/types/composables/useAnchoredTop.d.ts +26 -2
- package/dist/types/index.d.ts +4 -0
- package/package.json +7 -4
- package/src/components/HkAuthChannelList.scss +4 -2
- package/src/components/HkAuthChannelList.test.tsx +64 -0
- package/src/components/HkAuthChannelList.tsx +51 -19
- package/src/components/HkAuthHandoff.scss +79 -0
- package/src/components/HkAuthHandoff.test.tsx +208 -0
- package/src/components/HkAuthHandoff.tsx +222 -0
- package/src/components/HkLoginFlow.test.tsx +21 -0
- package/src/components/HkLoginFlow.tsx +6 -0
- package/src/components/HkModal.open-close-scale.test.ts +7 -1
- package/src/components/HkModal.scss +5 -1
- package/src/components/HkModal.test.tsx +354 -0
- package/src/components/HkModal.tsx +129 -0
- package/src/components/loginDiscovery.test.ts +181 -0
- package/src/components/loginDiscovery.ts +157 -0
- package/src/composables/useAnchoredTop.test.ts +52 -0
- package/src/composables/useAnchoredTop.ts +49 -3
- package/src/composables/useHighlight.hostSurface.test.ts +11 -1
- package/src/i18n/locales/ar/components.json +7 -0
- package/src/i18n/locales/de/components.json +7 -0
- package/src/i18n/locales/en/components.json +7 -0
- package/src/i18n/locales/es/components.json +7 -0
- package/src/i18n/locales/fr/components.json +7 -0
- package/src/i18n/locales/ja/components.json +7 -0
- package/src/i18n/locales/ko/components.json +7 -0
- package/src/i18n/locales/pt/components.json +7 -0
- package/src/i18n/locales/ru/components.json +7 -0
- package/src/i18n/locales/zh-Hans/components.json +7 -0
- package/src/i18n/locales/zh-Hant/components.json +7 -0
- package/src/index.ts +18 -0
- package/src/scene3d/scene3dHostSurface.test.ts +16 -4
- package/src/utils/qr/qrHostSurface.test.ts +20 -6
- package/src/wasm/highlight/hikari_wasm_highlight.js +1 -1
- package/src/wasm/mermaid/hikari_wasm_mermaid.js +1 -1
- package/src/wasm/qr/hikari_wasm_qr.js +1 -1
- package/src/wasm/scene3d/hikari_wasm_scene3d.js +1 -1
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// AI-generated: developed with the DeepSeek Harness agent (model GLM-5.4),
|
|
2
|
+
// directed and reviewed by the lead agent — SySL-1.0 §2.3 disclosure.
|
|
3
|
+
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { createApp, h, nextTick } from "vue";
|
|
6
|
+
|
|
7
|
+
import HkAuthHandoff from "./HkAuthHandoff";
|
|
8
|
+
|
|
9
|
+
const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
|
|
10
|
+
|
|
11
|
+
function mount(node: ReturnType<typeof h>) {
|
|
12
|
+
const container = document.createElement("div");
|
|
13
|
+
document.body.appendChild(container);
|
|
14
|
+
const app = createApp({ render: () => node });
|
|
15
|
+
app.mount(container);
|
|
16
|
+
mounts.push({ app, container });
|
|
17
|
+
return container;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let assign: ReturnType<typeof vi.fn>;
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
assign = vi.fn();
|
|
24
|
+
Object.defineProperty(window, "location", {
|
|
25
|
+
configurable: true,
|
|
26
|
+
value: { ...window.location, assign },
|
|
27
|
+
});
|
|
28
|
+
vi.useFakeTimers();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
for (const { app, container } of mounts.splice(0)) {
|
|
33
|
+
app.unmount();
|
|
34
|
+
container.remove();
|
|
35
|
+
}
|
|
36
|
+
vi.useRealTimers();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
function statusText(c: HTMLElement) {
|
|
40
|
+
return c.querySelector(".hk-auth-handoff")?.textContent ?? "";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
describe("HkAuthHandoff", () => {
|
|
44
|
+
it("shell + card grammar: HkAuthScreen stage, s-auth-card frame, title from the status copy", () => {
|
|
45
|
+
const c = mount(h(HkAuthHandoff, { status: "completing" }));
|
|
46
|
+
expect(c.querySelector(".hk-auth-screen-stage .s-auth-card.hk-auth-handoff-card")).not.toBeNull();
|
|
47
|
+
// MUT:handoff-title-key (wiring the wrong status key shows the wrong
|
|
48
|
+
// line on the completing screen).
|
|
49
|
+
expect(c.querySelector(".hk-auth-handoff-title")?.textContent).toBe("Completing sign-in…");
|
|
50
|
+
expect(c.querySelector(".hk-auth-handoff-description")).toBeNull();
|
|
51
|
+
expect(c.querySelector(".hk-auth-handoff-logo")).toBeNull();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("title, description and logoSrc override the defaults", () => {
|
|
55
|
+
const c = mount(
|
|
56
|
+
h(HkAuthHandoff, {
|
|
57
|
+
status: "failed",
|
|
58
|
+
title: "Bind failed",
|
|
59
|
+
description: "Use another account",
|
|
60
|
+
logoSrc: "/logo.svg",
|
|
61
|
+
}),
|
|
62
|
+
);
|
|
63
|
+
expect(c.querySelector(".hk-auth-handoff-title")?.textContent).toBe("Bind failed");
|
|
64
|
+
expect(c.querySelector(".hk-auth-handoff-description")?.textContent).toBe("Use another account");
|
|
65
|
+
const logo = c.querySelector<HTMLImageElement>(".hk-auth-handoff-logo");
|
|
66
|
+
expect(logo?.getAttribute("src")).toBe("/logo.svg");
|
|
67
|
+
// MUT:handoff-logo-announced (a decorative logo with a non-empty alt
|
|
68
|
+
// makes screen readers read the mark before the status).
|
|
69
|
+
expect(logo?.getAttribute("alt")).toBe("");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("transient states: spinner + polite status region; failures: alert, no spinner", () => {
|
|
73
|
+
const redirecting = mount(h(HkAuthHandoff, { status: "redirecting", href: "" }));
|
|
74
|
+
const region = redirecting.querySelector<HTMLElement>(".hk-auth-handoff")!;
|
|
75
|
+
expect(region.getAttribute("role")).toBe("status");
|
|
76
|
+
expect(region.getAttribute("aria-live")).toBe("polite");
|
|
77
|
+
expect(region.querySelector(".hk-spinner")).not.toBeNull();
|
|
78
|
+
|
|
79
|
+
const failed = mount(h(HkAuthHandoff, { status: "expired" }));
|
|
80
|
+
const alert = failed.querySelector<HTMLElement>(".hk-auth-handoff")!;
|
|
81
|
+
// MUT:handoff-failed-polite (an expired session announced politely is
|
|
82
|
+
// missed by screen readers — failures must interrupt).
|
|
83
|
+
expect(alert.getAttribute("role")).toBe("alert");
|
|
84
|
+
expect(alert.getAttribute("aria-live")).toBeNull();
|
|
85
|
+
expect(alert.querySelector(".hk-spinner")).toBeNull();
|
|
86
|
+
expect(alert.querySelector(".hk-auth-handoff-title")?.textContent).toBe(
|
|
87
|
+
"Your session expired. Sign in to continue.",
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("success shows a status line, no spinner, no buttons", () => {
|
|
92
|
+
const c = mount(h(HkAuthHandoff, { status: "success" }));
|
|
93
|
+
expect(c.querySelector(".hk-spinner")).toBeNull();
|
|
94
|
+
// The default title already names the state: it is not repeated in a badge.
|
|
95
|
+
// MUT:handoff-success-duplicated (a badge under the default title reads the
|
|
96
|
+
// same sentence twice).
|
|
97
|
+
expect(c.querySelector(".hk-auth-handoff-title")?.textContent).toContain("Signed in");
|
|
98
|
+
expect(c.querySelector(".hk-auth-handoff-state")).toBeNull();
|
|
99
|
+
expect(c.querySelector(".hk-auth-handoff-actions")).toBeNull();
|
|
100
|
+
// Under a host title the badge is the only place the state is named.
|
|
101
|
+
// MUT:handoff-success-badge-dropped (without it the success screen is a
|
|
102
|
+
// heading that never says the sign-in succeeded).
|
|
103
|
+
const titled = mount(h(HkAuthHandoff, { status: "success", title: "Welcome back" }));
|
|
104
|
+
expect(titled.querySelector(".hk-auth-handoff-title")?.textContent).toBe("Welcome back");
|
|
105
|
+
expect(titled.querySelector(".hk-auth-handoff-state .hk-badge")?.textContent).toContain("Signed in");
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("default actions: back for failed/expired, none otherwise; each emits", async () => {
|
|
109
|
+
const onRetry = vi.fn();
|
|
110
|
+
const onBack = vi.fn();
|
|
111
|
+
const c = mount(h(HkAuthHandoff, { status: "failed", onRetry, onBack }));
|
|
112
|
+
const buttons = c.querySelectorAll<HTMLButtonElement>(".hk-auth-handoff-actions button");
|
|
113
|
+
// MUT:handoff-default-actions (the default action set for `failed` is exactly
|
|
114
|
+
// `['back']`: a retry button the host did not ask for must not render).
|
|
115
|
+
expect(buttons.length).toBe(1);
|
|
116
|
+
expect(buttons[0]!.textContent).toContain("Back to sign in");
|
|
117
|
+
buttons[0]!.click();
|
|
118
|
+
await nextTick();
|
|
119
|
+
expect(onBack).toHaveBeenCalledTimes(1);
|
|
120
|
+
expect(onRetry).not.toHaveBeenCalled();
|
|
121
|
+
|
|
122
|
+
const quiet = mount(h(HkAuthHandoff, { status: "redirecting", href: "", delayMs: 1e9 }));
|
|
123
|
+
expect(quiet.querySelector(".hk-auth-handoff-actions")).toBeNull();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("explicit actions render in order and the actions slot replaces the buttons", async () => {
|
|
127
|
+
const onRetry = vi.fn();
|
|
128
|
+
const c = mount(
|
|
129
|
+
h(HkAuthHandoff, {
|
|
130
|
+
status: "expired",
|
|
131
|
+
actions: ["retry", "back"],
|
|
132
|
+
onRetry,
|
|
133
|
+
}),
|
|
134
|
+
);
|
|
135
|
+
const buttons = c.querySelectorAll<HTMLButtonElement>(".hk-auth-handoff-actions button");
|
|
136
|
+
expect(Array.from(buttons).map((b) => b.textContent?.trim())).toEqual([
|
|
137
|
+
"Try again",
|
|
138
|
+
"Back to sign in",
|
|
139
|
+
]);
|
|
140
|
+
buttons[0]!.click();
|
|
141
|
+
await nextTick();
|
|
142
|
+
expect(onRetry).toHaveBeenCalledTimes(1);
|
|
143
|
+
|
|
144
|
+
const slotted = mount(
|
|
145
|
+
h(HkAuthHandoff, { status: "failed" }, { actions: () => h("button", { class: "mine" }, "Mine") }),
|
|
146
|
+
);
|
|
147
|
+
expect(slotted.querySelectorAll(".hk-auth-handoff-actions button").length).toBe(1);
|
|
148
|
+
expect(slotted.querySelector(".hk-auth-handoff-actions .mine")).not.toBeNull();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("forwards header and footer slots to HkAuthScreen", () => {
|
|
152
|
+
const c = mount(
|
|
153
|
+
h(HkAuthHandoff, { status: "success" }, { header: () => h("b", "H"), footer: () => h("i", "F") }),
|
|
154
|
+
);
|
|
155
|
+
expect(c.querySelector(".hk-auth-screen-header b")?.textContent).toBe("H");
|
|
156
|
+
expect(c.querySelector(".hk-auth-screen-footer i")?.textContent).toBe("F");
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("redirecting with href navigates after delayMs and emits redirect first", () => {
|
|
160
|
+
const onRedirect = vi.fn();
|
|
161
|
+
mount(h(HkAuthHandoff, { status: "redirecting", href: "/relay/begin", delayMs: 500, onRedirect }));
|
|
162
|
+
expect(assign).not.toHaveBeenCalled();
|
|
163
|
+
vi.advanceTimersByTime(499);
|
|
164
|
+
expect(assign).not.toHaveBeenCalled();
|
|
165
|
+
vi.advanceTimersByTime(1);
|
|
166
|
+
// MUT:handoff-delay-ignored (navigating on mount skips the splash the
|
|
167
|
+
// host paid `delayMs` for).
|
|
168
|
+
expect(assign).toHaveBeenCalledTimes(1);
|
|
169
|
+
expect(assign).toHaveBeenCalledWith("/relay/begin");
|
|
170
|
+
// The host's hook runs before the browser leaves.
|
|
171
|
+
expect(onRedirect).toHaveBeenCalledTimes(1);
|
|
172
|
+
expect(onRedirect).toHaveBeenCalledWith("/relay/begin");
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("a redirect handler returning false cancels the navigation", () => {
|
|
176
|
+
const onRedirect = vi.fn(() => false);
|
|
177
|
+
mount(h(HkAuthHandoff, { status: "redirecting", href: "/relay/begin", onRedirect }));
|
|
178
|
+
vi.runAllTimers();
|
|
179
|
+
expect(onRedirect).toHaveBeenCalledWith("/relay/begin");
|
|
180
|
+
// MUT:handoff-redirect-veto-ignored (assigning anyway turns the host's
|
|
181
|
+
// veto into a double navigation).
|
|
182
|
+
expect(assign).not.toHaveBeenCalled();
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("without href the component navigates nothing — the host handles redirect", () => {
|
|
186
|
+
const onRedirect = vi.fn();
|
|
187
|
+
mount(h(HkAuthHandoff, { status: "redirecting", onRedirect }));
|
|
188
|
+
vi.runAllTimers();
|
|
189
|
+
expect(onRedirect).toHaveBeenCalledTimes(1);
|
|
190
|
+
expect(assign).not.toHaveBeenCalled();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("never navigates in a non-redirecting status, and never after unmount", () => {
|
|
194
|
+
const onRedirect = vi.fn();
|
|
195
|
+
const c = mount(h(HkAuthHandoff, { status: "redirecting", href: "/relay/begin", delayMs: 100 }));
|
|
196
|
+
mounts.splice(0)[0]!.app.unmount();
|
|
197
|
+
c.remove();
|
|
198
|
+
vi.runAllTimers();
|
|
199
|
+
// MUT:handoff-timer-leak (a timer that survives unmount sends the user
|
|
200
|
+
// to the relay after the host already swapped the screen).
|
|
201
|
+
expect(assign).not.toHaveBeenCalled();
|
|
202
|
+
expect(onRedirect).not.toHaveBeenCalled();
|
|
203
|
+
|
|
204
|
+
mount(h(HkAuthHandoff, { status: "completing", href: "/relay/begin", delayMs: 0 }));
|
|
205
|
+
vi.runAllTimers();
|
|
206
|
+
expect(assign).not.toHaveBeenCalled();
|
|
207
|
+
});
|
|
208
|
+
});
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// AI-generated: developed with the DeepSeek Harness agent (model GLM-5.4),
|
|
2
|
+
// directed and reviewed by the lead agent — SySL-1.0 §2.3 disclosure.
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
defineComponent,
|
|
6
|
+
getCurrentInstance,
|
|
7
|
+
onMounted,
|
|
8
|
+
onUnmounted,
|
|
9
|
+
watch,
|
|
10
|
+
type PropType,
|
|
11
|
+
} from "vue";
|
|
12
|
+
|
|
13
|
+
import { useI18n } from "../i18n/context";
|
|
14
|
+
import HkBadge from "./HkBadge";
|
|
15
|
+
import HkButton from "./HkButton";
|
|
16
|
+
import { HkAuthScreen } from "./HkAuthScreen";
|
|
17
|
+
import HkSpinner from "./HkSpinner";
|
|
18
|
+
import "./HkAuthHandoff.scss";
|
|
19
|
+
|
|
20
|
+
/** The five states a hand-off screen can be in:
|
|
21
|
+
* `redirecting` (about to leave for the sign-in entry), `completing`
|
|
22
|
+
* (the callback is being exchanged), `success`, `failed` and `expired`. */
|
|
23
|
+
export type HkAuthHandoffStatus = "redirecting" | "completing" | "success" | "failed" | "expired";
|
|
24
|
+
|
|
25
|
+
/** The built-in actions: `retry` restarts the hand-off, `back` returns to
|
|
26
|
+
* the sign-in page. */
|
|
27
|
+
export type HkAuthHandoffAction = "retry" | "back";
|
|
28
|
+
|
|
29
|
+
const COPY_KEY: Record<HkAuthHandoffStatus, string> = {
|
|
30
|
+
redirecting: "hikari::authHandoff.redirecting",
|
|
31
|
+
completing: "hikari::authHandoff.completing",
|
|
32
|
+
success: "hikari::authHandoff.success",
|
|
33
|
+
failed: "hikari::authHandoff.failed",
|
|
34
|
+
expired: "hikari::authHandoff.expired",
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const COPY_FALLBACK: Record<HkAuthHandoffStatus, string> = {
|
|
38
|
+
redirecting: "Redirecting to sign-in…",
|
|
39
|
+
completing: "Completing sign-in…",
|
|
40
|
+
success: "Signed in",
|
|
41
|
+
failed: "Sign-in could not be completed",
|
|
42
|
+
expired: "Your session expired. Sign in to continue.",
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** States that are in progress: a spinner, a polite live region. */
|
|
46
|
+
const TRANSIENT = new Set<HkAuthHandoffStatus>(["redirecting", "completing"]);
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* HkAuthHandoff — the sign-in screens that are NOT a form: the relay-mode
|
|
50
|
+
* splash before the browser leaves for the central login, the "completing"
|
|
51
|
+
* state while a callback is exchanged, and the terminal success / failed /
|
|
52
|
+
* expired states.
|
|
53
|
+
*
|
|
54
|
+
* Built on `HkAuthScreen` (header strip, centred stage, footer) with the
|
|
55
|
+
* auth card's grammar (logo, title, description). A CONTROLLED component:
|
|
56
|
+
* it builds no URLs and reads no token — the host passes `href` (or
|
|
57
|
+
* navigates itself on `redirect`) and decides what `retry` / `back` mean.
|
|
58
|
+
*
|
|
59
|
+
* ```tsx
|
|
60
|
+
* <HkAuthHandoff
|
|
61
|
+
* status="redirecting"
|
|
62
|
+
* href={hkRelayEntryHref(policy, route.query.return) ?? undefined}
|
|
63
|
+
* delayMs={800}
|
|
64
|
+
* onBack={() => router.push("/login")}
|
|
65
|
+
* />
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export const HkAuthHandoff = defineComponent({
|
|
69
|
+
name: "HkAuthHandoff",
|
|
70
|
+
props: {
|
|
71
|
+
status: { type: String as PropType<HkAuthHandoffStatus>, required: true },
|
|
72
|
+
/** Overrides the status title. Default undefined — the title is the
|
|
73
|
+
* status copy from `hikari::authHandoff.*`. */
|
|
74
|
+
title: { type: String, default: undefined },
|
|
75
|
+
/** A line under the title. Default undefined — no description is
|
|
76
|
+
* rendered (the status copy alone is the title). */
|
|
77
|
+
description: { type: String, default: undefined },
|
|
78
|
+
/** Logo above the title. Default undefined — no logo. */
|
|
79
|
+
logoSrc: { type: String, default: undefined },
|
|
80
|
+
/** `redirecting` only: the navigation target. When undefined the
|
|
81
|
+
* component navigates nothing and the host handles `redirect`. */
|
|
82
|
+
href: { type: String, default: undefined },
|
|
83
|
+
/** `redirecting` only: how long the splash shows before navigating.
|
|
84
|
+
* Default 0 — navigate as soon as the screen mounts. */
|
|
85
|
+
delayMs: { type: Number, default: 0 },
|
|
86
|
+
/** Built-in buttons in render order. Default undefined — `["back"]` for
|
|
87
|
+
* `failed` / `expired`, none for the other states. */
|
|
88
|
+
actions: {
|
|
89
|
+
type: Array as PropType<readonly HkAuthHandoffAction[]>,
|
|
90
|
+
default: undefined,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
emits: {
|
|
94
|
+
/** The redirect fired: `href` is the target (an empty string when the
|
|
95
|
+
* `href` prop was not given). Return `false` from the handler to
|
|
96
|
+
* cancel the navigation (the handler is invoked directly so its
|
|
97
|
+
* return value can be read). */
|
|
98
|
+
redirect: (_href: string) => true,
|
|
99
|
+
/** The `retry` action was activated. */
|
|
100
|
+
retry: () => true,
|
|
101
|
+
/** The `back` action was activated. */
|
|
102
|
+
back: () => true,
|
|
103
|
+
},
|
|
104
|
+
setup(props, { emit, slots }) {
|
|
105
|
+
const { t } = useI18n();
|
|
106
|
+
const instance = getCurrentInstance();
|
|
107
|
+
type RedirectHandler = (href: string) => boolean | void | undefined;
|
|
108
|
+
|
|
109
|
+
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
110
|
+
function clearTimer(): void {
|
|
111
|
+
if (timer !== null) {
|
|
112
|
+
clearTimeout(timer);
|
|
113
|
+
timer = null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function go(): void {
|
|
118
|
+
const href = props.href ?? "";
|
|
119
|
+
// `emit()` cannot hand back a handler's return value, so the raw
|
|
120
|
+
// listener(s) are read off the component's current vnode and invoked
|
|
121
|
+
// directly; `false` from any of them is a veto. Read per call, on
|
|
122
|
+
// purpose: the handler consulted must be the one the host passes NOW,
|
|
123
|
+
// not one captured when this component was set up.
|
|
124
|
+
const raw = instance?.vnode.props?.onRedirect as RedirectHandler | RedirectHandler[] | undefined;
|
|
125
|
+
const handlers = Array.isArray(raw) ? raw : raw ? [raw] : [];
|
|
126
|
+
const vetoed = handlers.some((handler) => handler(href) === false);
|
|
127
|
+
if (vetoed) return;
|
|
128
|
+
if (props.href) window.location.assign(props.href);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function schedule(): void {
|
|
132
|
+
clearTimer();
|
|
133
|
+
if (props.status !== "redirecting") return;
|
|
134
|
+
timer = setTimeout(go, Math.max(0, props.delayMs));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// The timer follows the state: mounting, or a status / href / delay
|
|
138
|
+
// change, re-arms (or cancels) it; unmounting cancels it for good.
|
|
139
|
+
onMounted(schedule);
|
|
140
|
+
watch(() => [props.status, props.href, props.delayMs], schedule);
|
|
141
|
+
onUnmounted(clearTimer);
|
|
142
|
+
|
|
143
|
+
return () => {
|
|
144
|
+
const transient = TRANSIENT.has(props.status);
|
|
145
|
+
const failed = props.status === "failed" || props.status === "expired";
|
|
146
|
+
const title = props.title ?? t(COPY_KEY[props.status], COPY_FALLBACK[props.status]);
|
|
147
|
+
const description = props.description;
|
|
148
|
+
const actions = props.actions ?? (failed ? ["back"] : []);
|
|
149
|
+
|
|
150
|
+
function run(action: HkAuthHandoffAction): void {
|
|
151
|
+
if (action === "retry") emit("retry");
|
|
152
|
+
else emit("back");
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const buttonLabel: Record<HkAuthHandoffAction, string> = {
|
|
156
|
+
retry: t("hikari::authHandoff.retry", "Try again"),
|
|
157
|
+
back: t("hikari::authHandoff.back", "Back to sign in"),
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<HkAuthScreen>
|
|
162
|
+
{{
|
|
163
|
+
header: slots.header,
|
|
164
|
+
footer: slots.footer,
|
|
165
|
+
default: () => (
|
|
166
|
+
<div
|
|
167
|
+
class={[
|
|
168
|
+
"hk-auth-handoff",
|
|
169
|
+
`hk-auth-handoff--${props.status}`,
|
|
170
|
+
transient && "is-transient",
|
|
171
|
+
]}
|
|
172
|
+
role={failed ? "alert" : "status"}
|
|
173
|
+
aria-live={transient ? "polite" : undefined}
|
|
174
|
+
>
|
|
175
|
+
<div class="s-auth-card hk-auth-handoff-card">
|
|
176
|
+
<div class="s-auth-header hk-auth-handoff-header">
|
|
177
|
+
{props.logoSrc ? (
|
|
178
|
+
<img class="hk-auth-handoff-logo" src={props.logoSrc} alt="" aria-hidden="true" />
|
|
179
|
+
) : null}
|
|
180
|
+
<h1 class="s-auth-title hk-auth-handoff-title">{title}</h1>
|
|
181
|
+
{description ? (
|
|
182
|
+
<p class="s-auth-subtitle hk-auth-handoff-description">{description}</p>
|
|
183
|
+
) : null}
|
|
184
|
+
</div>
|
|
185
|
+
<div class="hk-auth-handoff-body">
|
|
186
|
+
{transient ? <HkSpinner center /> : null}
|
|
187
|
+
// With the default title the heading already names the
|
|
188
|
+
// state; the badge repeats it only under a host title.
|
|
189
|
+
{props.status === "success" && props.title ? (
|
|
190
|
+
<div class="hk-auth-handoff-state">
|
|
191
|
+
<HkBadge variant="success" size="md">
|
|
192
|
+
{t(COPY_KEY[props.status], COPY_FALLBACK[props.status])}
|
|
193
|
+
</HkBadge>
|
|
194
|
+
</div>
|
|
195
|
+
) : null}
|
|
196
|
+
{slots.actions ? (
|
|
197
|
+
<div class="hk-auth-handoff-actions">{slots.actions()}</div>
|
|
198
|
+
) : actions.length > 0 ? (
|
|
199
|
+
<div class="hk-auth-handoff-actions">
|
|
200
|
+
{actions.map((action, index) => (
|
|
201
|
+
<HkButton
|
|
202
|
+
key={action}
|
|
203
|
+
variant={index === 0 && action === "back" && failed ? "primary" : "secondary"}
|
|
204
|
+
onClick={() => run(action)}
|
|
205
|
+
>
|
|
206
|
+
{buttonLabel[action]}
|
|
207
|
+
</HkButton>
|
|
208
|
+
))}
|
|
209
|
+
</div>
|
|
210
|
+
) : null}
|
|
211
|
+
</div>
|
|
212
|
+
</div>
|
|
213
|
+
</div>
|
|
214
|
+
),
|
|
215
|
+
}}
|
|
216
|
+
</HkAuthScreen>
|
|
217
|
+
);
|
|
218
|
+
};
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
export default HkAuthHandoff;
|
|
@@ -252,6 +252,27 @@ describe("HkLoginFlow — sso channel", () => {
|
|
|
252
252
|
expect(onClick).toHaveBeenCalledWith("org");
|
|
253
253
|
});
|
|
254
254
|
|
|
255
|
+
it("forwards href: the destination row is a real link; without it, a button", () => {
|
|
256
|
+
const link = mount(
|
|
257
|
+
h(HkLoginFlow, {
|
|
258
|
+
channels: [{ ...orgChannel, href: "/auth/relay/begin" }],
|
|
259
|
+
modelValue: "org",
|
|
260
|
+
}),
|
|
261
|
+
);
|
|
262
|
+
const a = link.querySelector<HTMLAnchorElement>(".hk-login-flow-sso .hk-auth-channel-row")!;
|
|
263
|
+
expect(a.tagName).toBe("A");
|
|
264
|
+
// MUT:flow-sso-href-dropped (not forwarding the channel's href leaves
|
|
265
|
+
// the row a button — hosts must go back to window.location).
|
|
266
|
+
expect(a.getAttribute("href")).toBe("/auth/relay/begin");
|
|
267
|
+
expect(a.textContent).toContain("Organization login");
|
|
268
|
+
|
|
269
|
+
// Default (no href) is unchanged: today's button.
|
|
270
|
+
const button = mount(h(HkLoginFlow, { channels: [orgChannel], modelValue: "org" }));
|
|
271
|
+
const b = button.querySelector<HTMLButtonElement>(".hk-login-flow-sso .hk-auth-channel-row")!;
|
|
272
|
+
expect(b.tagName).toBe("BUTTON");
|
|
273
|
+
expect(b.hasAttribute("href")).toBe(false);
|
|
274
|
+
});
|
|
275
|
+
|
|
255
276
|
it("does not enter the verify step on an sso channel (fail-safe)", () => {
|
|
256
277
|
const c = mount(
|
|
257
278
|
h(HkLoginFlow, {
|
|
@@ -81,6 +81,11 @@ export interface HkLoginSsoChannel {
|
|
|
81
81
|
* label. */
|
|
82
82
|
buttonLabel?: string;
|
|
83
83
|
disabled?: boolean;
|
|
84
|
+
/** Navigation target forwarded to the channel row: the row becomes a
|
|
85
|
+
* real link (`sso-click` still fires first, navigation is not
|
|
86
|
+
* prevented). Default undefined — the row is a button and the host
|
|
87
|
+
* navigates on `sso-click`, as before. */
|
|
88
|
+
href?: string;
|
|
84
89
|
}
|
|
85
90
|
|
|
86
91
|
export type HkLoginChannel = HkLoginCredentialsChannel | HkLoginSsoChannel;
|
|
@@ -429,6 +434,7 @@ export const HkLoginFlow = defineComponent({
|
|
|
429
434
|
label: channel.buttonLabel ?? channelLabel(channel),
|
|
430
435
|
icon: channel.icon,
|
|
431
436
|
disabled: channel.disabled,
|
|
437
|
+
href: channel.href,
|
|
432
438
|
},
|
|
433
439
|
]}
|
|
434
440
|
onSelect={() => emit("sso-click", channel.key)}
|
|
@@ -309,8 +309,14 @@ const RIDE = [
|
|
|
309
309
|
|
|
310
310
|
const child = (parent: MockElement, cls: string): MockElement => el([cls], parent);
|
|
311
311
|
|
|
312
|
+
// The centering translate carries TWO offsets: the drag shift and the
|
|
313
|
+
// top-edge anchor (useAnchoredTop — a centred frame lifts by half of every
|
|
314
|
+
// height growth, so the anchor folds the measured drift back). Both compose
|
|
315
|
+
// on the individual `translate` property, never on `transform`: the ride
|
|
316
|
+
// below animates `transform` outright.
|
|
312
317
|
const CENTERING_TRANSLATE =
|
|
313
|
-
"calc(-50% + var(--hk-modal-shift-x, 0px))
|
|
318
|
+
"calc(-50% + var(--hk-modal-shift-x, 0px))"
|
|
319
|
+
+ " calc(-50% + var(--hk-modal-shift-y, 0px) + var(--hk-modal-anchor-y, 0px))";
|
|
314
320
|
|
|
315
321
|
/** Frame ride states: the centering translate lives on the INDIVIDUAL
|
|
316
322
|
* `translate` property (never animated, re-resolves against the live box
|
|
@@ -141,8 +141,12 @@
|
|
|
141
141
|
// order — center, then ride legs, drag shift included — is
|
|
142
142
|
// unchanged. The ≤767px sheet block neutralizes it alongside its own
|
|
143
143
|
// `transform: none`.)
|
|
144
|
+
// --hk-modal-anchor-y is the TOP-EDGE anchor (useAnchoredTop): the frame
|
|
145
|
+
// is centred, so a height morph would otherwise lift the whole window by
|
|
146
|
+
// half the growth. It composes here rather than on `transform` because the
|
|
147
|
+
// open/close ride owns that property outright (see the note above).
|
|
144
148
|
translate: calc(-50% + var(--hk-modal-shift-x, 0px))
|
|
145
|
-
calc(-50% + var(--hk-modal-shift-y, 0px));
|
|
149
|
+
calc(-50% + var(--hk-modal-shift-y, 0px) + var(--hk-modal-anchor-y, 0px));
|
|
146
150
|
width: 100%;
|
|
147
151
|
// Reasonable upper bound: a 2734px-wide viewport with width:100% gives
|
|
148
152
|
// a modal frame wider than the content can usefully fill — the body
|