@rightkit/onboarding 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -1
- package/dist/Onboarding.d.ts +4 -2
- package/dist/Onboarding.js +93 -13
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/steps.d.ts +10 -2
- package/dist/steps.js +40 -11
- package/dist/types.d.ts +43 -2
- package/onboarding.css +24 -20
- package/package.json +9 -5
package/README.md
CHANGED
|
@@ -11,5 +11,32 @@ import "@rightkit/onboarding/onboarding.css";
|
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
- `settings` is a `SettingsBackend`; progress is stored under the `onboarding.state` key.
|
|
14
|
-
- The agreement is enforced
|
|
14
|
+
- The agreement is enforced until accepted, regardless of the saved step index. Acceptance is stored as `legalAcceptance: { version, documentsHash, acceptedAt (UTC ISO), eligibilityBasis }`; legacy `legalAccepted: true` is still read.
|
|
15
15
|
- `onComplete` and `onSkip` run only after the state was saved. A rejected save is shown in an alert and neither callback runs.
|
|
16
|
+
|
|
17
|
+
## Props
|
|
18
|
+
|
|
19
|
+
| Prop | Purpose |
|
|
20
|
+
| --- | --- |
|
|
21
|
+
| `requiredVersion` | Version the user must have accepted. A different or missing stored version re-prompts with the legal gate's `re-acceptance` variant. Legacy boolean acceptance is only re-prompted when this is set. |
|
|
22
|
+
| `isAccepted(state)` | Custom acceptance check; overrides `requiredVersion`. |
|
|
23
|
+
| `documentsHash` | Hash recorded with the acceptance (default: SHA-256 of document titles and URLs). |
|
|
24
|
+
| `beforeLegalGate()` | Awaited before the gate shows (e.g. size or reveal the window). The package does no window sizing itself. |
|
|
25
|
+
| `requireModel` | Continue/Finish on the models step wait for an installed model. |
|
|
26
|
+
| `autoStartDownload` | Start the first missing model download when the models step opens. |
|
|
27
|
+
| `modelsIntro` | App copy shown at the top of the models step. |
|
|
28
|
+
| `allowSkip` | Show "Set up later" (default `true`). |
|
|
29
|
+
| `titlebar` | Node rendered in a strip along the top. |
|
|
30
|
+
| `dragRegion` | Add `data-tauri-drag-region` to that strip (default `false`; height `--rk-onboarding-titlebar-h`, default 32px). |
|
|
31
|
+
|
|
32
|
+
## Custom steps and readiness
|
|
33
|
+
|
|
34
|
+
A step may set `canContinue(context)`; Continue/Finish stay disabled while it returns `false` (optional `blockedHint` is shown). Steps with async readiness call `context.setReady(boolean)` from `render` and read `context.ready[stepId]`. Back is disabled on the first step after the agreement.
|
|
35
|
+
|
|
36
|
+
## Models backend
|
|
37
|
+
|
|
38
|
+
`ModelsBackend.cancel` is optional; the Pause control appears only when it is supplied.
|
|
39
|
+
|
|
40
|
+
## Tests
|
|
41
|
+
|
|
42
|
+
`pnpm exec vitest run` runs the jsdom unit tests (`src/*.test.tsx`) and the headless-Chrome e2e.
|
package/dist/Onboarding.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import type { OnboardingProps } from "./types.js";
|
|
1
|
+
import type { OnboardingProps, PersistedOnboardingState } from "./types.js";
|
|
2
|
+
/** True when the stored acceptance satisfies the host's requirement. */
|
|
3
|
+
export declare function isLegalAccepted(state: PersistedOnboardingState, requiredVersion?: string, custom?: (state: PersistedOnboardingState) => boolean): boolean;
|
|
2
4
|
export declare function onboardingStateKey(): string;
|
|
3
|
-
export declare function Onboarding({ settings, legal, steps, permissions, models, license, onComplete, onSkip, className }: OnboardingProps): import("react").JSX.Element;
|
|
5
|
+
export declare function Onboarding({ settings, legal, steps, permissions, models, license, onComplete, onSkip, className, requiredVersion, isAccepted, documentsHash, beforeLegalGate, requireModel, autoStartDownload, modelsIntro, allowSkip, titlebar, dragRegion }: OnboardingProps): import("react").JSX.Element;
|
package/dist/Onboarding.js
CHANGED
|
@@ -6,24 +6,72 @@ import { cx } from "./ui.js";
|
|
|
6
6
|
import { licenseStep, modelsStep, permissionsStep } from "./steps.js";
|
|
7
7
|
const KEY = "onboarding.state";
|
|
8
8
|
const INITIAL = { version: 1, currentStep: 0, completed: [], skipped: false, legalAccepted: false };
|
|
9
|
+
function readAcceptance(value) {
|
|
10
|
+
if (!value || typeof value !== "object")
|
|
11
|
+
return undefined;
|
|
12
|
+
const r = value;
|
|
13
|
+
if (typeof r.version !== "string" || typeof r.documentsHash !== "string" || typeof r.acceptedAt !== "string")
|
|
14
|
+
return undefined;
|
|
15
|
+
if (r.eligibilityBasis !== "individual" && r.eligibilityBasis !== "enterprise")
|
|
16
|
+
return undefined;
|
|
17
|
+
return { version: r.version, documentsHash: r.documentsHash, acceptedAt: r.acceptedAt, eligibilityBasis: r.eligibilityBasis };
|
|
18
|
+
}
|
|
9
19
|
function readState(value) {
|
|
10
20
|
if (!value || typeof value !== "object")
|
|
11
21
|
return INITIAL;
|
|
12
22
|
const candidate = value;
|
|
23
|
+
const legalAcceptance = readAcceptance(candidate.legalAcceptance);
|
|
13
24
|
return {
|
|
14
25
|
version: 1,
|
|
15
26
|
currentStep: typeof candidate.currentStep === "number" && candidate.currentStep >= 0 ? Math.floor(candidate.currentStep) : 0,
|
|
16
27
|
completed: Array.isArray(candidate.completed) ? candidate.completed.filter((x) => typeof x === "string") : [],
|
|
17
28
|
skipped: candidate.skipped === true,
|
|
18
|
-
legalAccepted: candidate.legalAccepted === true,
|
|
19
|
-
eligibilityBasis: candidate.eligibilityBasis === "individual" || candidate.eligibilityBasis === "enterprise" ? candidate.eligibilityBasis : undefined,
|
|
29
|
+
legalAccepted: candidate.legalAccepted === true || legalAcceptance !== undefined,
|
|
30
|
+
eligibilityBasis: legalAcceptance?.eligibilityBasis ?? (candidate.eligibilityBasis === "individual" || candidate.eligibilityBasis === "enterprise" ? candidate.eligibilityBasis : undefined),
|
|
31
|
+
...(legalAcceptance ? { legalAcceptance } : {}),
|
|
20
32
|
};
|
|
21
33
|
}
|
|
34
|
+
/** True when the stored acceptance satisfies the host's requirement. */
|
|
35
|
+
export function isLegalAccepted(state, requiredVersion, custom) {
|
|
36
|
+
if (custom)
|
|
37
|
+
return custom(state);
|
|
38
|
+
if (requiredVersion !== undefined)
|
|
39
|
+
return state.legalAcceptance?.version === requiredVersion;
|
|
40
|
+
return state.legalAccepted;
|
|
41
|
+
}
|
|
42
|
+
/** FNV-1a fallback when SubtleCrypto is unavailable. */
|
|
43
|
+
function fnv(text) {
|
|
44
|
+
let h = 0x811c9dc5;
|
|
45
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
46
|
+
h ^= text.charCodeAt(i);
|
|
47
|
+
h = Math.imul(h, 0x01000193) >>> 0;
|
|
48
|
+
}
|
|
49
|
+
return `fnv1a:${h.toString(16).padStart(8, "0")}`;
|
|
50
|
+
}
|
|
51
|
+
async function hashDocuments(documents) {
|
|
52
|
+
const text = JSON.stringify(documents.map((d) => [d.title, d.url ?? ""]));
|
|
53
|
+
try {
|
|
54
|
+
const subtle = globalThis.crypto?.subtle;
|
|
55
|
+
if (subtle) {
|
|
56
|
+
const digest = await subtle.digest("SHA-256", new TextEncoder().encode(text));
|
|
57
|
+
return `sha256:${[...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("")}`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch { /* fall through */ }
|
|
61
|
+
return fnv(text);
|
|
62
|
+
}
|
|
22
63
|
export function onboardingStateKey() { return KEY; }
|
|
23
|
-
|
|
64
|
+
function TitleStrip({ titlebar, dragRegion }) {
|
|
65
|
+
if (!titlebar && !dragRegion)
|
|
66
|
+
return null;
|
|
67
|
+
return _jsx("div", { className: "rk-onboarding__titlebar", "data-testid": "onboarding-titlebar", ...(dragRegion ? { "data-tauri-drag-region": "" } : {}), children: titlebar });
|
|
68
|
+
}
|
|
69
|
+
export function Onboarding({ settings, legal, steps = [], permissions, models, license, onComplete, onSkip, className, requiredVersion, isAccepted, documentsHash, beforeLegalGate, requireModel, autoStartDownload, modelsIntro, allowSkip = true, titlebar, dragRegion }) {
|
|
24
70
|
const [state, setState] = useState(null);
|
|
25
71
|
const [saving, setSaving] = useState(false);
|
|
26
72
|
const [error, setError] = useState(null);
|
|
73
|
+
const [readyMap, setReadyMap] = useState({});
|
|
74
|
+
const [gateCleared, setGateCleared] = useState(false);
|
|
27
75
|
/** Persists a patch; throws when the settings backend rejects it. */
|
|
28
76
|
const persist = useCallback(async (patch) => {
|
|
29
77
|
setSaving(true);
|
|
@@ -56,17 +104,41 @@ export function Onboarding({ settings, legal, steps = [], permissions, models, l
|
|
|
56
104
|
setState(readState(snapshot.values[KEY])); }, (e) => { if (live)
|
|
57
105
|
setError(e instanceof Error ? e.message : String(e)); }); return () => { live = false; }; }, [settings]);
|
|
58
106
|
const builtins = useMemo(() => [
|
|
59
|
-
{ id: "legal", label: "Agreement", title: "Review agreement", skippable: false, render: () =>
|
|
107
|
+
{ id: "legal", label: "Agreement", title: "Review agreement", skippable: false, render: () => _jsx("p", { className: "rk-onboarding__muted", children: "Agreement accepted." }) },
|
|
60
108
|
...(permissions ? [permissionsStep(permissions)] : []),
|
|
61
|
-
...(models ? [modelsStep(models)] : []),
|
|
109
|
+
...(models ? [modelsStep(models, { required: requireModel, autoStartDownload, intro: modelsIntro })] : []),
|
|
62
110
|
...(license ? [licenseStep(license)] : []),
|
|
63
111
|
...steps,
|
|
64
|
-
], [license, models, permissions, steps]);
|
|
112
|
+
], [license, models, permissions, steps, requireModel, autoStartDownload, modelsIntro]);
|
|
65
113
|
const activeState = state ?? INITIAL;
|
|
114
|
+
const accepted = isLegalAccepted(activeState, requiredVersion, isAccepted);
|
|
115
|
+
const needsGate = state !== null && !accepted;
|
|
66
116
|
// The agreement gate does not depend on the saved step: until it is accepted, the active step is the first.
|
|
67
|
-
|
|
117
|
+
// Once accepted, the Agreement step (index 0) is never shown again when other steps exist.
|
|
118
|
+
const index = !accepted ? 0 : builtins.length > 1 ? Math.max(1, Math.min(activeState.currentStep, builtins.length - 1)) : 0;
|
|
68
119
|
const active = builtins[index];
|
|
69
|
-
const
|
|
120
|
+
const activeId = active?.id ?? "";
|
|
121
|
+
const setReady = useCallback((ready) => setReadyMap((m) => m[activeId] === ready ? m : { ...m, [activeId]: ready }), [activeId]);
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
if (!needsGate) {
|
|
124
|
+
setGateCleared(false);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (gateCleared)
|
|
128
|
+
return;
|
|
129
|
+
let live = true;
|
|
130
|
+
void (async () => { try {
|
|
131
|
+
await beforeLegalGate?.();
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
if (live)
|
|
135
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
136
|
+
} if (live)
|
|
137
|
+
setGateCleared(true); })();
|
|
138
|
+
return () => { live = false; };
|
|
139
|
+
}, [needsGate, gateCleared, beforeLegalGate]);
|
|
140
|
+
const context = { state: activeState, settings, setState: saveStep, permissions, models, license, ready: readyMap, setReady };
|
|
141
|
+
const canContinue = active?.canContinue ? active.canContinue(context) : true;
|
|
70
142
|
const runCallback = async (callback) => {
|
|
71
143
|
try {
|
|
72
144
|
await callback?.();
|
|
@@ -88,11 +160,19 @@ export function Onboarding({ settings, legal, steps = [], permissions, models, l
|
|
|
88
160
|
return _jsxs("div", { className: cx("rk-onboarding", className), children: [_jsx("p", { className: "rk-onboarding__error", role: "alert", children: error }), _jsx(Button, { onClick: () => window.location.reload(), children: "Retry" })] });
|
|
89
161
|
if (!state || !active)
|
|
90
162
|
return _jsx("div", { className: cx("rk-onboarding", className), "aria-busy": "true", children: _jsx("p", { className: "rk-onboarding__muted", children: "Loading setup\u2026" }) });
|
|
91
|
-
if (
|
|
92
|
-
|
|
93
|
-
|
|
163
|
+
if (needsGate) {
|
|
164
|
+
if (!gateCleared)
|
|
165
|
+
return _jsxs("div", { className: cx("rk-onboarding", className), "aria-busy": "true", children: [_jsx(TitleStrip, { titlebar: titlebar, dragRegion: dragRegion }), _jsx("p", { className: "rk-onboarding__muted", children: "Loading setup\u2026" })] });
|
|
166
|
+
const reacceptance = activeState.legalAccepted || activeState.legalAcceptance !== undefined;
|
|
167
|
+
return _jsxs("div", { className: cx("rk-onboarding rk-onboarding--legal", className), "data-testid": "onboarding-legal", "data-variant": reacceptance ? "re-acceptance" : "first-run", children: [_jsx(TitleStrip, { titlebar: titlebar, dragRegion: dragRegion }), _jsx(LegalGate, { ...legal, variant: reacceptance ? "re-acceptance" : "first-run", onQuit: () => void legal.onQuit?.(), onAgree: async ({ eligibilityBasis }) => {
|
|
168
|
+
const legalAcceptance = { version: requiredVersion ?? "1", documentsHash: documentsHash ?? await hashDocuments(legal.documents), acceptedAt: new Date().toISOString(), eligibilityBasis };
|
|
169
|
+
const progress = reacceptance ? {} : { completed: ["legal"], currentStep: builtins.length > 1 ? 1 : 0 };
|
|
170
|
+
await persist({ legalAccepted: true, eligibilityBasis, legalAcceptance, ...progress });
|
|
171
|
+
if (!reacceptance && builtins.length === 1)
|
|
172
|
+
await onComplete();
|
|
173
|
+
} })] });
|
|
94
174
|
}
|
|
95
175
|
const body = active.render(context);
|
|
96
|
-
return _jsxs("main", { className: cx("rk-onboarding", className), "data-testid": "onboarding", "data-step-id": active.id, children: [_jsxs("aside", { className: "rk-onboarding__rail", children: [_jsx("div", { className: "rk-onboarding__brand", children: legal.appName }), _jsx("nav", { "aria-label": "Setup progress", children: builtins.map((step, i) => _jsxs("button", { type: "button", className: cx("rk-onboarding__step", i === index && "is-active", activeState.completed.includes(step.id) && "is-done"), "aria-current": i === index ? "step" : undefined, onClick: () => { if (i > 0 ||
|
|
97
|
-
void save({ currentStep: i }); }, children: [_jsx("span", { children: activeState.completed.includes(step.id) ? "✓" : i + 1 }), step.label] }, step.id)) })] }), _jsxs("section", { className: "rk-onboarding__main", children: [_jsxs("header", { children: [_jsxs("p", { className: "rk-onboarding__eyebrow", children: ["Step ", index + 1, " of ", builtins.length] }), _jsx("h1", { children: active.title }), active.description ? _jsx("p", { className: "rk-onboarding__description", children: active.description }) : null] }), _jsx("div", { className: "rk-onboarding__content", children: body }), error ? _jsx("p", { className: "rk-onboarding__error", role: "alert", children: error }) : null, _jsxs("footer", { children: [_jsx(Button, { variant: "ghost", disabled: saving, onClick: () => { void save({ currentStep: index, skipped: true }).then((ok) => ok ? runCallback(onSkip) : undefined); }, children: "Set up later" }), _jsx("span", {}), _jsx(Button, { variant: "secondary", disabled: index
|
|
176
|
+
return _jsxs("main", { className: cx("rk-onboarding", className), "data-testid": "onboarding", "data-step-id": active.id, children: [_jsx(TitleStrip, { titlebar: titlebar, dragRegion: dragRegion }), _jsxs("aside", { className: "rk-onboarding__rail", children: [_jsx("div", { className: "rk-onboarding__brand", children: legal.appName }), _jsx("nav", { "aria-label": "Setup progress", children: builtins.map((step, i) => _jsxs("button", { type: "button", className: cx("rk-onboarding__step", i === index && "is-active", activeState.completed.includes(step.id) && "is-done"), "aria-current": i === index ? "step" : undefined, disabled: i === 0 && builtins.length > 1, onClick: () => { if (i > 0 && (i <= index || canContinue))
|
|
177
|
+
void save({ currentStep: i }); }, children: [_jsx("span", { children: activeState.completed.includes(step.id) ? "✓" : i + 1 }), step.label] }, step.id)) })] }), _jsxs("section", { className: "rk-onboarding__main", children: [_jsxs("header", { children: [_jsxs("p", { className: "rk-onboarding__eyebrow", children: ["Step ", index + 1, " of ", builtins.length] }), _jsx("h1", { children: active.title }), active.description ? _jsx("p", { className: "rk-onboarding__description", children: active.description }) : null] }), _jsx("div", { className: "rk-onboarding__content", children: body }), error ? _jsx("p", { className: "rk-onboarding__error", role: "alert", children: error }) : null, _jsxs("footer", { children: [allowSkip ? _jsx(Button, { variant: "ghost", disabled: saving, onClick: () => { void save({ currentStep: index, skipped: true }).then((ok) => ok ? runCallback(onSkip) : undefined); }, children: "Set up later" }) : null, _jsx("span", { className: "rk-onboarding__hint", children: !canContinue && active.blockedHint ? active.blockedHint : null }), _jsx(Button, { variant: "secondary", disabled: index <= 1 || saving, onClick: () => void save({ currentStep: index - 1 }), children: "Back" }), _jsx(Button, { variant: "primary", disabled: saving || !canContinue, onClick: () => void markAndMove(index + 1, active.id), children: index === builtins.length - 1 ? "Finish setup" : "Continue" })] })] })] });
|
|
98
178
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { Onboarding, onboardingStateKey } from "./Onboarding.js";
|
|
1
|
+
export { Onboarding, isLegalAccepted, onboardingStateKey } from "./Onboarding.js";
|
|
2
2
|
export { licenseStep, modelsStep, permissionsStep } from "./steps.js";
|
|
3
|
+
export type { ModelsStepOptions } from "./steps.js";
|
|
3
4
|
export type * from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Onboarding, onboardingStateKey } from "./Onboarding.js";
|
|
1
|
+
export { Onboarding, isLegalAccepted, onboardingStateKey } from "./Onboarding.js";
|
|
2
2
|
export { licenseStep, modelsStep, permissionsStep } from "./steps.js";
|
package/dist/steps.d.ts
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
1
2
|
import type { LicenseBackend, ModelsBackend, OnboardingStep, PermissionsBackend } from "./types.js";
|
|
2
3
|
export declare function permissionsStep(backend: PermissionsBackend, options?: {
|
|
3
4
|
label?: string;
|
|
4
5
|
title?: string;
|
|
5
6
|
description?: string;
|
|
6
7
|
}): OnboardingStep;
|
|
7
|
-
export
|
|
8
|
+
export interface ModelsStepOptions {
|
|
8
9
|
label?: string;
|
|
9
10
|
title?: string;
|
|
10
11
|
description?: string;
|
|
11
|
-
|
|
12
|
+
/** Continue/Finish wait until at least one model is installed. Default false. */
|
|
13
|
+
required?: boolean;
|
|
14
|
+
/** Start downloading the first missing model when the step opens. Default false. */
|
|
15
|
+
autoStartDownload?: boolean;
|
|
16
|
+
/** App copy rendered at the top of the step. */
|
|
17
|
+
intro?: ReactNode;
|
|
18
|
+
}
|
|
19
|
+
export declare function modelsStep(backend: ModelsBackend, options?: ModelsStepOptions): OnboardingStep;
|
|
12
20
|
export declare function licenseStep(backend: LicenseBackend, options?: {
|
|
13
21
|
label?: string;
|
|
14
22
|
title?: string;
|
package/dist/steps.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
3
|
import { Button, Input, Badge } from "@rightkit/app-shell/react";
|
|
4
4
|
function ProgressBar({ value, label }) {
|
|
5
5
|
const pct = Math.max(0, Math.min(1, value));
|
|
@@ -29,32 +29,61 @@ function PermissionsBody({ backend }) {
|
|
|
29
29
|
export function permissionsStep(backend, options = {}) {
|
|
30
30
|
return { id: "permissions", label: options.label ?? "Permissions", title: options.title ?? "Allow what this app needs", description: options.description ?? "You can change these permissions later in System Settings.", skippable: true, render: () => _jsx(PermissionsBody, { backend: backend }) };
|
|
31
31
|
}
|
|
32
|
-
function ModelsBody({ backend }) {
|
|
32
|
+
function ModelsBody({ backend, onReady, autoStartDownload, intro }) {
|
|
33
33
|
const [models, setModels] = useState([]);
|
|
34
|
+
const [loaded, setLoaded] = useState(false);
|
|
34
35
|
const [busy, setBusy] = useState(null);
|
|
35
36
|
const [error, setError] = useState(null);
|
|
36
|
-
const
|
|
37
|
+
const autoStarted = useRef(false);
|
|
38
|
+
const reload = useCallback(() => backend.list().then((list) => { setModels(list); setLoaded(true); }, (e) => setError(e instanceof Error ? e.message : String(e))), [backend]);
|
|
37
39
|
useEffect(() => {
|
|
38
40
|
void reload();
|
|
39
41
|
if (!backend.subscribe)
|
|
40
42
|
return;
|
|
41
43
|
let off;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
let live = true;
|
|
45
|
+
void backend.subscribe((entry) => setModels((current) => current.some((m) => m.id === entry.id) ? current.map((m) => m.id === entry.id ? entry : m) : [...current, entry])).then((unsubscribe) => { if (live)
|
|
46
|
+
off = unsubscribe;
|
|
47
|
+
else
|
|
48
|
+
unsubscribe(); });
|
|
49
|
+
return () => { live = false; off?.(); };
|
|
44
50
|
}, [backend, reload]);
|
|
45
|
-
const
|
|
46
|
-
|
|
51
|
+
const hasInstalled = models.some((m) => m.state === "installed");
|
|
52
|
+
useEffect(() => { onReady?.(hasInstalled); }, [hasInstalled, onReady]);
|
|
53
|
+
const run = (id, request) => {
|
|
54
|
+
setBusy(id);
|
|
47
55
|
setError(null);
|
|
48
|
-
const request = model.state === "downloading" || model.state === "verifying" ? backend.cancel(model.id) : backend.install(model.id);
|
|
49
56
|
void request.then(reload, (e) => setError(e instanceof Error ? e.message : String(e))).finally(() => setBusy(null));
|
|
50
57
|
};
|
|
51
|
-
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (!autoStartDownload || !loaded || autoStarted.current)
|
|
60
|
+
return;
|
|
61
|
+
autoStarted.current = true;
|
|
62
|
+
if (models.some((m) => m.state === "installed" || m.state === "downloading" || m.state === "verifying"))
|
|
63
|
+
return;
|
|
64
|
+
const first = models.find((m) => m.state === "missing");
|
|
65
|
+
if (first)
|
|
66
|
+
run(first.id, backend.install(first.id));
|
|
67
|
+
// run is intentionally omitted: it only closes over setters.
|
|
68
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
69
|
+
}, [autoStartDownload, loaded, models, backend]);
|
|
70
|
+
return (_jsxs("div", { className: "rk-onboarding__card", "data-testid": "onboarding-models", children: [intro ? _jsx("div", { className: "rk-onboarding__intro", "data-testid": "onboarding-models-intro", children: intro }) : null, error ? _jsx("p", { className: "rk-onboarding__error", role: "alert", children: error }) : null, models.map((model) => {
|
|
52
71
|
const progress = model.progress ?? (model.state === "installed" ? 1 : 0);
|
|
53
|
-
|
|
72
|
+
const active = model.state === "downloading" || model.state === "verifying";
|
|
73
|
+
const cancel = backend.cancel;
|
|
74
|
+
return _jsxs("div", { className: "rk-onboarding__row", "data-model-id": model.id, children: [_jsxs("div", { className: "rk-onboarding__grow", children: [_jsx("strong", { children: model.label }), _jsxs("p", { children: [model.description ?? "", model.sizeBytes ? ` · ${formatBytes(model.sizeBytes)}` : ""] }), active ? _jsx(ProgressBar, { value: progress, label: `${model.label} download` }) : null] }), _jsxs("div", { className: "rk-onboarding__row-actions", children: [_jsx(Badge, { tone: model.state === "installed" ? "ok" : model.state === "error" ? "bad" : "neutral", children: model.state }), model.state === "installed" ? null
|
|
75
|
+
: model.state === "error" ? _jsx(Button, { size: "sm", variant: "secondary", disabled: busy === model.id, onClick: () => run(model.id, backend.install(model.id)), children: "Retry" })
|
|
76
|
+
: active ? (cancel ? _jsx(Button, { size: "sm", variant: "secondary", disabled: busy === model.id, onClick: () => run(model.id, cancel.call(backend, model.id)), children: "Pause" }) : null)
|
|
77
|
+
: _jsx(Button, { size: "sm", variant: "secondary", disabled: busy === model.id, onClick: () => run(model.id, backend.install(model.id)), children: "Download" })] })] }, model.id);
|
|
54
78
|
}), models.length === 0 && !error ? _jsx("p", { className: "rk-onboarding__muted", children: "No models available." }) : null] }));
|
|
55
79
|
}
|
|
56
80
|
export function modelsStep(backend, options = {}) {
|
|
57
|
-
return {
|
|
81
|
+
return {
|
|
82
|
+
id: "models", label: options.label ?? "Models", title: options.title ?? "Choose local models", description: options.description ?? "Downloads are verified before a model is activated.", skippable: true,
|
|
83
|
+
canContinue: options.required ? (ctx) => ctx.ready.models === true : undefined,
|
|
84
|
+
blockedHint: options.required ? "Download a model to continue." : undefined,
|
|
85
|
+
render: (ctx) => _jsx(ModelsBody, { backend: backend, onReady: ctx.setReady, autoStartDownload: options.autoStartDownload, intro: options.intro }),
|
|
86
|
+
};
|
|
58
87
|
}
|
|
59
88
|
function LicenseBody({ backend }) {
|
|
60
89
|
const [state, setState] = useState({ status: "none" });
|
package/dist/types.d.ts
CHANGED
|
@@ -39,7 +39,8 @@ export interface ModelEntry {
|
|
|
39
39
|
export interface ModelsBackend {
|
|
40
40
|
list(): Promise<ModelEntry[]>;
|
|
41
41
|
install(id: string): Promise<void>;
|
|
42
|
-
cancel
|
|
42
|
+
/** Optional. The cancel/pause control is shown only when the backend supplies this. */
|
|
43
|
+
cancel?(id: string): Promise<void>;
|
|
43
44
|
subscribe?(handler: (entry: ModelEntry) => void): Promise<() => void>;
|
|
44
45
|
}
|
|
45
46
|
export interface LicenseState {
|
|
@@ -56,13 +57,25 @@ export interface LicenseBackend {
|
|
|
56
57
|
purchaseUrl?: string;
|
|
57
58
|
openExternal?: (url: string) => void | Promise<void>;
|
|
58
59
|
}
|
|
60
|
+
export type EligibilityBasis = "individual" | "enterprise";
|
|
61
|
+
/** Full record of one legal acceptance, persisted so version changes can re-prompt. */
|
|
62
|
+
export interface LegalAcceptanceRecord {
|
|
63
|
+
version: string;
|
|
64
|
+
documentsHash: string;
|
|
65
|
+
/** UTC ISO-8601 timestamp (`Date#toISOString`). */
|
|
66
|
+
acceptedAt: string;
|
|
67
|
+
eligibilityBasis: EligibilityBasis;
|
|
68
|
+
}
|
|
59
69
|
export interface PersistedOnboardingState {
|
|
60
70
|
version: 1;
|
|
61
71
|
currentStep: number;
|
|
62
72
|
completed: string[];
|
|
63
73
|
skipped: boolean;
|
|
74
|
+
/** Legacy boolean, still written for older readers. Prefer `legalAcceptance`. */
|
|
64
75
|
legalAccepted: boolean;
|
|
65
|
-
|
|
76
|
+
/** Legacy mirror of `legalAcceptance.eligibilityBasis`. */
|
|
77
|
+
eligibilityBasis?: EligibilityBasis;
|
|
78
|
+
legalAcceptance?: LegalAcceptanceRecord;
|
|
66
79
|
}
|
|
67
80
|
export interface OnboardingStepContext {
|
|
68
81
|
state: PersistedOnboardingState;
|
|
@@ -71,6 +84,10 @@ export interface OnboardingStepContext {
|
|
|
71
84
|
permissions?: PermissionsBackend;
|
|
72
85
|
models?: ModelsBackend;
|
|
73
86
|
license?: LicenseBackend;
|
|
87
|
+
/** Readiness reported by steps via `setReady`, keyed by step id. */
|
|
88
|
+
ready: Readonly<Record<string, boolean>>;
|
|
89
|
+
/** Reports whether the active step is ready (used by `canContinue`). Stable per step. */
|
|
90
|
+
setReady: (ready: boolean) => void;
|
|
74
91
|
}
|
|
75
92
|
export interface OnboardingStep {
|
|
76
93
|
id: string;
|
|
@@ -78,6 +95,10 @@ export interface OnboardingStep {
|
|
|
78
95
|
title: string;
|
|
79
96
|
description?: string;
|
|
80
97
|
skippable?: boolean;
|
|
98
|
+
/** Continue/Finish stay disabled until this returns true. Default: always allowed. */
|
|
99
|
+
canContinue?: (context: OnboardingStepContext) => boolean;
|
|
100
|
+
/** Shown beside the disabled Continue/Finish button. */
|
|
101
|
+
blockedHint?: string;
|
|
81
102
|
render: (context: OnboardingStepContext) => ReactNode;
|
|
82
103
|
}
|
|
83
104
|
export interface LegalStepConfig extends Omit<LegalGateProps, "variant" | "onAgree" | "onQuit"> {
|
|
@@ -94,5 +115,25 @@ export interface OnboardingProps {
|
|
|
94
115
|
onComplete: () => void | Promise<void>;
|
|
95
116
|
onSkip?: () => void | Promise<void>;
|
|
96
117
|
className?: string;
|
|
118
|
+
/** Version the user must have accepted. A different (or missing) stored version re-prompts with `variant: "re-acceptance"`. */
|
|
119
|
+
requiredVersion?: string;
|
|
120
|
+
/** Custom acceptance check; takes precedence over `requiredVersion`. */
|
|
121
|
+
isAccepted?: (state: PersistedOnboardingState) => boolean;
|
|
122
|
+
/** Hash of the legal documents recorded with the acceptance. Default: hash of document titles and URLs. */
|
|
123
|
+
documentsHash?: string;
|
|
124
|
+
/** Runs (and is awaited) before the legal gate is shown, e.g. to resize or reveal the window. */
|
|
125
|
+
beforeLegalGate?: () => void | Promise<void>;
|
|
126
|
+
/** Require at least one downloaded model before Continue/Finish on the models step. Default false. */
|
|
127
|
+
requireModel?: boolean;
|
|
128
|
+
/** Start downloading the first missing model when the models step opens. Default false. */
|
|
129
|
+
autoStartDownload?: boolean;
|
|
130
|
+
/** App copy shown at the top of the models step. */
|
|
131
|
+
modelsIntro?: ReactNode;
|
|
132
|
+
/** Show "Set up later". Default true. */
|
|
133
|
+
allowSkip?: boolean;
|
|
134
|
+
/** Optional titlebar content rendered in a strip along the top. */
|
|
135
|
+
titlebar?: ReactNode;
|
|
136
|
+
/** Render a `data-tauri-drag-region` strip at the top. Default false. */
|
|
137
|
+
dragRegion?: boolean;
|
|
97
138
|
}
|
|
98
139
|
export type { LegalGateDocument, LegalGateTheme };
|
package/onboarding.css
CHANGED
|
@@ -1,37 +1,41 @@
|
|
|
1
1
|
/* @rightkit/onboarding — uses app-shell tokens and legal-ui's locked light gate. */
|
|
2
|
-
.rk-onboarding { min-height: 100vh; display: grid; grid-template-columns: 220px minmax(0, 1fr); background: var(--plane, #fffcf5); color: var(--ink, #231f1a); font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; }
|
|
2
|
+
.rk-onboarding { position: relative; min-height: 100vh; display: grid; grid-template-columns: 220px minmax(0, 1fr); background: var(--rk-plane, #fffcf5); color: var(--rk-ink, #231f1a); font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; }
|
|
3
3
|
.rk-onboarding *, .rk-onboarding *::before, .rk-onboarding *::after { box-sizing: border-box; }
|
|
4
|
-
.rk-onboarding__rail { display: flex; flex-direction: column; gap: 22px; padding: 28px 14px; background: var(--chrome, #eee9df); border-right: .5px solid var(--hairline, rgba(35,31,26,.11)); }
|
|
4
|
+
.rk-onboarding__rail { display: flex; flex-direction: column; gap: 22px; padding: 28px 14px; background: var(--rk-chrome, #eee9df); border-right: .5px solid var(--rk-hairline, rgba(35,31,26,.11)); }
|
|
5
5
|
.rk-onboarding__brand { padding: 0 10px; font-size: 19px; font-weight: 650; letter-spacing: -.02em; }
|
|
6
6
|
.rk-onboarding__rail nav { display: grid; gap: 3px; }
|
|
7
|
-
.rk-onboarding__step { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: 8px; background: transparent; color: var(--ink-2, #6b655c); font: inherit; text-align: left; cursor: pointer; }
|
|
8
|
-
.rk-onboarding__step span { display: grid; place-items: center; width: 20px; height: 20px; border: 1px solid var(--line-strong, rgba(35,31,26,.18)); border-radius: 50%; font-size: 11px; }
|
|
9
|
-
.rk-onboarding__step:hover { background: var(--fill, rgba(35,31,26,.05)); color: var(--ink); }
|
|
10
|
-
.rk-onboarding__step.is-active { background: var(--sel, rgba(35,31,26,.06)); color: var(--ink); font-weight: 600; }
|
|
11
|
-
.rk-onboarding__step.is-done span { border-color: var(--ok, #1e7f3c); color: var(--ok, #1e7f3c); }
|
|
7
|
+
.rk-onboarding__step { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: 8px; background: transparent; color: var(--rk-ink-2, #6b655c); font: inherit; text-align: left; cursor: pointer; }
|
|
8
|
+
.rk-onboarding__step span { display: grid; place-items: center; width: 20px; height: 20px; border: 1px solid var(--rk-line-strong, rgba(35,31,26,.18)); border-radius: 50%; font-size: 11px; }
|
|
9
|
+
.rk-onboarding__step:hover { background: var(--rk-fill, rgba(35,31,26,.05)); color: var(--rk-ink); }
|
|
10
|
+
.rk-onboarding__step.is-active { background: var(--rk-sel, rgba(35,31,26,.06)); color: var(--rk-ink); font-weight: 600; }
|
|
11
|
+
.rk-onboarding__step.is-done span { border-color: var(--rk-ok, #1e7f3c); color: var(--rk-ok, #1e7f3c); }
|
|
12
12
|
.rk-onboarding__main { display: flex; flex-direction: column; min-width: 0; max-width: 840px; width: 100%; padding: 64px clamp(24px, 7vw, 88px) 32px; }
|
|
13
13
|
.rk-onboarding__main header { max-width: 620px; }
|
|
14
|
-
.rk-onboarding__eyebrow { margin: 0 0 8px; color: var(--accent, #7040c4); font-size: 12px; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; }
|
|
14
|
+
.rk-onboarding__eyebrow { margin: 0 0 8px; color: var(--rk-accent, #7040c4); font-size: 12px; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; }
|
|
15
15
|
.rk-onboarding__main h1 { margin: 0; font-size: clamp(24px, 4vw, 34px); line-height: 1.1; letter-spacing: -.025em; }
|
|
16
|
-
.rk-onboarding__description { margin: 10px 0 0; color: var(--ink-2, #6b655c); font-size: 15px; max-width: 58ch; }
|
|
16
|
+
.rk-onboarding__description { margin: 10px 0 0; color: var(--rk-ink-2, #6b655c); font-size: 15px; max-width: 58ch; }
|
|
17
17
|
.rk-onboarding__content { flex: 1; padding: 30px 0; }
|
|
18
18
|
.rk-onboarding__card { display: grid; gap: 2px; max-width: 680px; padding: 6px 0; }
|
|
19
|
-
.rk-onboarding__card > p { color: var(--ink-2, #6b655c); }
|
|
20
|
-
.rk-onboarding__row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 16px 0; border-bottom: .5px solid var(--hairline, rgba(35,31,26,.11)); }
|
|
19
|
+
.rk-onboarding__card > p { color: var(--rk-ink-2, #6b655c); }
|
|
20
|
+
.rk-onboarding__row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 16px 0; border-bottom: .5px solid var(--rk-hairline, rgba(35,31,26,.11)); }
|
|
21
21
|
.rk-onboarding__row:last-child { border-bottom: 0; }
|
|
22
|
-
.rk-onboarding__row p { margin: 3px 0 0; color: var(--ink-2, #6b655c); font-size: 12.5px; }
|
|
22
|
+
.rk-onboarding__row p { margin: 3px 0 0; color: var(--rk-ink-2, #6b655c); font-size: 12.5px; }
|
|
23
23
|
.rk-onboarding__row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; flex: none; }
|
|
24
24
|
.rk-onboarding__grow { min-width: 0; flex: 1; }
|
|
25
|
-
.rk-onboarding__muted { color: var(--ink-2, #6b655c); }
|
|
26
|
-
.rk-onboarding__error { color: var(--bad, #c4001a); }
|
|
27
|
-
.rk-onboarding__state { color: var(--ink-2, #6b655c); text-transform: capitalize; }
|
|
28
|
-
.rk-onboarding__progress { height: 6px; margin-top: 8px; border-radius: 99px; background: var(--fill-3, rgba(35,31,26,.13)); overflow: hidden; }
|
|
29
|
-
.rk-onboarding__progress i { display: block; height: 100%; background: var(--accent, #7040c4); }
|
|
25
|
+
.rk-onboarding__muted { color: var(--rk-ink-2, #6b655c); }
|
|
26
|
+
.rk-onboarding__error { color: var(--rk-bad, #c4001a); }
|
|
27
|
+
.rk-onboarding__state { color: var(--rk-ink-2, #6b655c); text-transform: capitalize; }
|
|
28
|
+
.rk-onboarding__progress { height: 6px; margin-top: 8px; border-radius: 99px; background: var(--rk-fill-3, rgba(35,31,26,.13)); overflow: hidden; }
|
|
29
|
+
.rk-onboarding__progress i { display: block; height: 100%; background: var(--rk-accent, #7040c4); }
|
|
30
30
|
.rk-onboarding__license-state { display: flex; align-items: center; gap: 10px; margin: 8px 0 18px; }
|
|
31
|
-
.rk-onboarding__license-state small { color: var(--ink-2, #6b655c); }
|
|
31
|
+
.rk-onboarding__license-state small { color: var(--rk-ink-2, #6b655c); }
|
|
32
32
|
.rk-onboarding__form { display: flex; gap: 8px; margin-bottom: 14px; }
|
|
33
33
|
.rk-onboarding__form .rk-input { flex: 1; }
|
|
34
|
-
.rk-onboarding footer { display: flex; align-items: center; gap: 8px; padding-top: 16px; border-top: .5px solid var(--hairline, rgba(35,31,26,.11)); }
|
|
34
|
+
.rk-onboarding footer { display: flex; align-items: center; gap: 8px; padding-top: 16px; border-top: .5px solid var(--rk-hairline, rgba(35,31,26,.11)); }
|
|
35
35
|
.rk-onboarding footer span { flex: 1; }
|
|
36
36
|
.rk-onboarding--legal { display: block; }
|
|
37
|
-
@media (max-width: 640px) { .rk-onboarding { grid-template-columns: 1fr; } .rk-onboarding__rail { padding: 18px 12px; border-right: 0; border-bottom: .5px solid var(--hairline, rgba(35,31,26,.11)); } .rk-onboarding__rail nav { grid-template-columns: repeat(2, minmax(0, 1fr)); } .rk-onboarding__main { padding: 34px 20px 24px; } .rk-onboarding__row { align-items: flex-start; flex-direction: column; gap: 10px; } .rk-onboarding__row-actions { justify-content: flex-start; } }
|
|
37
|
+
@media (max-width: 640px) { .rk-onboarding { grid-template-columns: 1fr; } .rk-onboarding__rail { padding: 18px 12px; border-right: 0; border-bottom: .5px solid var(--rk-hairline, rgba(35,31,26,.11)); } .rk-onboarding__rail nav { grid-template-columns: repeat(2, minmax(0, 1fr)); } .rk-onboarding__main { padding: 34px 20px 24px; } .rk-onboarding__row { align-items: flex-start; flex-direction: column; gap: 10px; } .rk-onboarding__row-actions { justify-content: flex-start; } }
|
|
38
|
+
/* Optional window chrome strip (titlebar slot / data-tauri-drag-region). Height is app-tunable. */
|
|
39
|
+
.rk-onboarding__titlebar { position: absolute; inset: 0 0 auto 0; z-index: 2; display: flex; align-items: center; height: var(--rk-onboarding-titlebar-h, 32px); padding: 0 12px; }
|
|
40
|
+
.rk-onboarding__hint { color: var(--rk-ink-2, #6b655c); font-size: 12px; text-align: right; }
|
|
41
|
+
.rk-onboarding__intro { margin-bottom: 12px; color: var(--rk-ink-2, #6b655c); }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rightkit/onboarding",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "First-run onboarding framework: ordered steps, progress, skip/resume, legal gate first, permissions, model download and licence/trial steps.",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -24,15 +24,19 @@
|
|
|
24
24
|
"*.css"
|
|
25
25
|
],
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@rightkit/app-shell": ">=0.
|
|
28
|
-
"@rightkit/legal-ui": ">=0.1.
|
|
27
|
+
"@rightkit/app-shell": ">=0.2.0 <1",
|
|
28
|
+
"@rightkit/legal-ui": ">=0.1.2 <1",
|
|
29
29
|
"react": ">=18 <20"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@rightkit/app-shell": "0.
|
|
33
|
-
"@rightkit/legal-ui": "0.1.
|
|
32
|
+
"@rightkit/app-shell": "0.2.0",
|
|
33
|
+
"@rightkit/legal-ui": "0.1.2",
|
|
34
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
35
|
+
"@testing-library/react": "^16.1.0",
|
|
36
|
+
"@testing-library/user-event": "^14.5.2",
|
|
34
37
|
"@types/react": "^19.0.0",
|
|
35
38
|
"@types/react-dom": "^19.0.0",
|
|
39
|
+
"jsdom": "^25.0.1",
|
|
36
40
|
"react": "^19.0.0",
|
|
37
41
|
"react-dom": "^19.0.0",
|
|
38
42
|
"typescript": "^5.7.0",
|