@eifi1/ui-kit 0.29.0 → 0.31.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 +65 -6
- package/dist/account/account-parts.d.ts +21 -0
- package/dist/account/account-parts.js +40 -0
- package/dist/account/account-parts.js.map +1 -0
- package/dist/account/data-export-setting.d.ts +73 -0
- package/dist/account/data-export-setting.js +114 -0
- package/dist/account/data-export-setting.js.map +1 -0
- package/dist/account/delete-account-setting.d.ts +95 -0
- package/dist/account/delete-account-setting.js +200 -0
- package/dist/account/delete-account-setting.js.map +1 -0
- package/dist/account/email-change-setting.d.ts +136 -0
- package/dist/account/email-change-setting.js +278 -0
- package/dist/account/email-change-setting.js.map +1 -0
- package/dist/account/sessions-setting.d.ts +110 -0
- package/dist/account/sessions-setting.js +147 -0
- package/dist/account/sessions-setting.js.map +1 -0
- package/dist/admin/admin-action-confirm.d.ts +95 -0
- package/dist/admin/admin-action-confirm.js +276 -0
- package/dist/admin/admin-action-confirm.js.map +1 -0
- package/dist/admin/admin-action-log.d.ts +105 -0
- package/dist/admin/admin-action-log.js +153 -0
- package/dist/admin/admin-action-log.js.map +1 -0
- package/dist/admin/admin-parts.d.ts +40 -0
- package/dist/admin/admin-parts.js +45 -0
- package/dist/admin/admin-parts.js.map +1 -0
- package/dist/admin/invitations-panel.d.ts +95 -0
- package/dist/admin/invitations-panel.js +290 -0
- package/dist/admin/invitations-panel.js.map +1 -0
- package/dist/admin/reviewer-scope-editor.d.ts +95 -0
- package/dist/admin/reviewer-scope-editor.js +134 -0
- package/dist/admin/reviewer-scope-editor.js.map +1 -0
- package/dist/admin/role-select.d.ts +95 -0
- package/dist/admin/role-select.js +128 -0
- package/dist/admin/role-select.js.map +1 -0
- package/dist/admin/transfer-ownership-dialog.d.ts +95 -0
- package/dist/admin/transfer-ownership-dialog.js +83 -0
- package/dist/admin/transfer-ownership-dialog.js.map +1 -0
- package/dist/admin/user-roster.d.ts +95 -0
- package/dist/admin/user-roster.js +285 -0
- package/dist/admin/user-roster.js.map +1 -0
- package/dist/auth/auth-errors.d.ts +103 -6
- package/dist/auth/auth-errors.js +68 -2
- package/dist/auth/auth-errors.js.map +1 -1
- package/dist/auth/forgot-password-form.d.ts +10 -3
- package/dist/auth/forgot-password-form.js +6 -3
- package/dist/auth/forgot-password-form.js.map +1 -1
- package/dist/auth/register-form.d.ts +21 -12
- package/dist/auth/register-form.js +6 -4
- package/dist/auth/register-form.js.map +1 -1
- package/dist/auth/reset-password-form.d.ts +10 -3
- package/dist/auth/reset-password-form.js +6 -3
- package/dist/auth/reset-password-form.js.map +1 -1
- package/dist/auth/sign-in-form.d.ts +75 -9
- package/dist/auth/sign-in-form.js +105 -15
- package/dist/auth/sign-in-form.js.map +1 -1
- package/dist/auth/verify-email.d.ts +7 -2
- package/dist/auth/verify-email.js +44 -8
- package/dist/auth/verify-email.js.map +1 -1
- package/dist/chart.d.ts +20 -11
- package/dist/components/account-chips.d.ts +47 -7
- package/dist/components/account-chips.js +19 -3
- package/dist/components/account-chips.js.map +1 -1
- package/dist/components/account-settings-labels.d.ts +24 -1
- package/dist/components/account-settings-labels.js +6 -2
- package/dist/components/account-settings-labels.js.map +1 -1
- package/dist/components/account-settings.d.ts +69 -8
- package/dist/components/account-settings.js +133 -25
- package/dist/components/account-settings.js.map +1 -1
- package/dist/components/amount-input.d.ts +21 -12
- package/dist/components/button-group.d.ts +21 -12
- package/dist/components/calculator.d.ts +21 -12
- package/dist/components/confirm-dialog.d.ts +21 -12
- package/dist/components/copy-button.d.ts +18 -9
- package/dist/components/danger-confirm.d.ts +21 -12
- package/dist/components/data-table.js +8 -1
- package/dist/components/data-table.js.map +1 -1
- package/dist/components/date-picker.js +9 -4
- package/dist/components/date-picker.js.map +1 -1
- package/dist/components/facing-pair.d.ts +21 -12
- package/dist/components/file-button.d.ts +21 -12
- package/dist/components/file-dropzone.d.ts +21 -12
- package/dist/components/form-actions.d.ts +21 -12
- package/dist/components/iban-input.d.ts +21 -12
- package/dist/components/language-select.d.ts +21 -12
- package/dist/components/legal-page.d.ts +21 -12
- package/dist/components/legal.d.ts +21 -12
- package/dist/components/money-field.d.ts +21 -12
- package/dist/components/number-field.d.ts +21 -12
- package/dist/components/number-input.d.ts +21 -12
- package/dist/components/numpad-sheet.d.ts +21 -12
- package/dist/components/passkeys-setting.js +2 -1
- package/dist/components/passkeys-setting.js.map +1 -1
- package/dist/components/phone-input.d.ts +21 -12
- package/dist/components/series-chart.d.ts +21 -12
- package/dist/components/settings-fields.d.ts +55 -13
- package/dist/components/settings-fields.js +20 -1
- package/dist/components/settings-fields.js.map +1 -1
- package/dist/components/share-card.d.ts +20 -11
- package/dist/components/text-link.d.ts +21 -12
- package/dist/components/time-input.d.ts +21 -12
- package/dist/components/ui.d.ts +17 -8
- package/dist/{register-form-V1OeNlMr.d.ts → delete-account-setting-DCFS5Vof.d.ts} +6612 -5612
- package/dist/demo/demo-banner.d.ts +51 -0
- package/dist/demo/demo-banner.js +97 -0
- package/dist/demo/demo-banner.js.map +1 -0
- package/dist/demo/demo-countdown.d.ts +58 -0
- package/dist/demo/demo-countdown.js +79 -0
- package/dist/demo/demo-countdown.js.map +1 -0
- package/dist/demo/demo-ended.d.ts +45 -0
- package/dist/demo/demo-ended.js +42 -0
- package/dist/demo/demo-ended.js.map +1 -0
- package/dist/demo/demo-labels.d.ts +53 -0
- package/dist/demo/demo-labels.js +29 -0
- package/dist/demo/demo-labels.js.map +1 -0
- package/dist/demo/demo-session.d.ts +30 -0
- package/dist/demo/demo-session.js +8 -0
- package/dist/demo/demo-session.js.map +1 -0
- package/dist/demo/demo-start.d.ts +54 -0
- package/dist/demo/demo-start.js +68 -0
- package/dist/demo/demo-start.js.map +1 -0
- package/dist/feedback/feedback-attachment.d.ts +21 -12
- package/dist/feedback/feedback-context.d.ts +21 -12
- package/dist/feedback/feedback-crash.d.ts +21 -12
- package/dist/feedback/feedback-dialog.d.ts +21 -12
- package/dist/feedback/feedback-inbox.d.ts +21 -12
- package/dist/feedback/feedback-inbox.js +12 -2
- package/dist/feedback/feedback-inbox.js.map +1 -1
- package/dist/feedback/feedback-labels.d.ts +21 -12
- package/dist/feedback/feedback-labels.js +1 -0
- package/dist/feedback/feedback-labels.js.map +1 -1
- package/dist/feedback/feedback-menu.d.ts +21 -12
- package/dist/feedback/feedback-record.d.ts +21 -12
- package/dist/feedback/feedback-record.js +2 -0
- package/dist/feedback/feedback-record.js.map +1 -1
- package/dist/feedback/feedback-row-detail.d.ts +21 -12
- package/dist/feedback/feedback-row-detail.js +7 -0
- package/dist/feedback/feedback-row-detail.js.map +1 -1
- package/dist/feedback/feedback-status-undo.d.ts +21 -12
- package/dist/feedback/feedback-submit.d.ts +21 -12
- package/dist/feedback/feedback-swipe.d.ts +22 -13
- package/dist/feedback/feedback-swipe.js.map +1 -1
- package/dist/feedback/feedback-table.d.ts +18 -9
- package/dist/feedback/feedback-thread.d.ts +21 -12
- package/dist/feedback.d.ts +21 -12
- package/dist/hooks/use-anchored-panel.d.ts +6 -2
- package/dist/hooks/use-anchored-panel.js +2 -1
- package/dist/hooks/use-anchored-panel.js.map +1 -1
- package/dist/hooks/use-file-drop.d.ts +21 -12
- package/dist/i18n/defaults.d.ts +21 -12
- package/dist/i18n/defaults.js +28 -0
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/german.d.ts +21 -12
- package/dist/i18n/german.js +298 -12
- package/dist/i18n/german.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +14 -5
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/languages.d.ts +15 -6
- package/dist/i18n/locales/de-CH.d.ts +21 -12
- package/dist/i18n/locales/en.d.ts +21 -12
- package/dist/i18n/locales/es.d.ts +21 -12
- package/dist/i18n/locales/es.js +287 -10
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.d.ts +21 -12
- package/dist/i18n/locales/fr.js +290 -7
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.d.ts +21 -12
- package/dist/i18n/locales/hu.js +288 -12
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.d.ts +21 -12
- package/dist/i18n/locales/it.js +289 -7
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.d.ts +21 -12
- package/dist/i18n/locales/zh.js +279 -7
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/i18n/review.d.ts +21 -12
- package/dist/i18n/review.js +50 -1
- package/dist/i18n/review.js.map +1 -1
- package/dist/index.d.ts +31 -4
- package/dist/index.js +148 -0
- package/dist/index.js.map +1 -1
- package/dist/landing/access.d.ts +48 -0
- package/dist/landing/access.js +38 -0
- package/dist/landing/access.js.map +1 -0
- package/dist/landing/landing-actions.d.ts +138 -0
- package/dist/landing/landing-actions.js +39 -0
- package/dist/landing/landing-actions.js.map +1 -0
- package/dist/landing/landing-labels.d.ts +43 -0
- package/dist/landing/landing-labels.js +23 -0
- package/dist/landing/landing-labels.js.map +1 -0
- package/dist/landing/landing-sections.d.ts +218 -0
- package/dist/landing/landing-sections.js +167 -0
- package/dist/landing/landing-sections.js.map +1 -0
- package/dist/landing/page-seo.d.ts +99 -0
- package/dist/landing/page-seo.js +121 -0
- package/dist/landing/page-seo.js.map +1 -0
- package/dist/landing/public-header.d.ts +148 -0
- package/dist/landing/public-header.js +49 -0
- package/dist/landing/public-header.js.map +1 -0
- package/dist/landing/routing.d.ts +218 -0
- package/dist/landing/routing.js +81 -0
- package/dist/landing/routing.js.map +1 -0
- package/dist/rhf/fields.d.ts +21 -12
- package/dist/rhf/form.d.ts +21 -12
- package/dist/rhf.d.ts +21 -12
- package/dist/settings/settings-catalogue.d.ts +84 -0
- package/dist/settings/settings-catalogue.js +47 -0
- package/dist/settings/settings-catalogue.js.map +1 -0
- package/dist/settings/settings-context.d.ts +31 -0
- package/dist/settings/settings-context.js +11 -0
- package/dist/settings/settings-context.js.map +1 -0
- package/dist/settings/settings-heading.d.ts +50 -0
- package/dist/settings/settings-heading.js +27 -0
- package/dist/settings/settings-heading.js.map +1 -0
- package/dist/settings/settings-labels.d.ts +41 -0
- package/dist/settings/settings-labels.js +38 -0
- package/dist/settings/settings-labels.js.map +1 -0
- package/dist/settings/settings-layout.d.ts +77 -0
- package/dist/settings/settings-layout.js +242 -0
- package/dist/settings/settings-layout.js.map +1 -0
- package/dist/settings/settings-section.d.ts +133 -0
- package/dist/settings/settings-section.js +63 -0
- package/dist/settings/settings-section.js.map +1 -0
- package/dist/settings/use-account-language.d.ts +83 -0
- package/dist/settings/use-account-language.js +62 -0
- package/dist/settings/use-account-language.js.map +1 -0
- package/dist/settings/use-settings-focus.d.ts +34 -0
- package/dist/settings/use-settings-focus.js +77 -0
- package/dist/settings/use-settings-focus.js.map +1 -0
- package/dist/settings/use-settings-route.d.ts +118 -0
- package/dist/settings/use-settings-route.js +120 -0
- package/dist/settings/use-settings-route.js.map +1 -0
- package/dist/shell/app-shell.d.ts +27 -12
- package/dist/shell/app-shell.js +3 -2
- package/dist/shell/app-shell.js.map +1 -1
- package/dist/shell/top-bar-brand.d.ts +21 -12
- package/dist/shell.d.ts +25 -6
- package/dist/shell.js +56 -0
- package/dist/shell.js.map +1 -1
- package/dist/wizard/stepper-nav.d.ts +21 -12
- package/dist/wizard.d.ts +21 -12
- package/package.json +2 -1
- package/src/account/account-parts.ts +67 -0
- package/src/account/data-export-setting.tsx +219 -0
- package/src/account/delete-account-setting.tsx +363 -0
- package/src/account/email-change-setting.tsx +454 -0
- package/src/account/sessions-setting.tsx +284 -0
- package/src/admin/admin-action-confirm.tsx +495 -0
- package/src/admin/admin-action-log.tsx +297 -0
- package/src/admin/admin-parts.ts +82 -0
- package/src/admin/invitations-panel.tsx +523 -0
- package/src/admin/reviewer-scope-editor.tsx +234 -0
- package/src/admin/role-select.tsx +286 -0
- package/src/admin/transfer-ownership-dialog.tsx +172 -0
- package/src/admin/user-roster.tsx +573 -0
- package/src/auth/auth-errors.ts +196 -8
- package/src/auth/forgot-password-form.tsx +21 -5
- package/src/auth/register-form.tsx +24 -6
- package/src/auth/reset-password-form.tsx +19 -5
- package/src/auth/sign-in-form.tsx +241 -38
- package/src/auth/verify-email.tsx +59 -8
- package/src/components/account-chips.tsx +64 -7
- package/src/components/account-settings-labels.ts +28 -1
- package/src/components/account-settings.tsx +231 -34
- package/src/components/data-table.tsx +8 -0
- package/src/components/date-picker.tsx +9 -4
- package/src/components/passkeys-setting.tsx +2 -1
- package/src/components/settings-fields.tsx +50 -1
- package/src/demo/demo-banner.tsx +159 -0
- package/src/demo/demo-countdown.ts +141 -0
- package/src/demo/demo-ended.tsx +89 -0
- package/src/demo/demo-labels.ts +78 -0
- package/src/demo/demo-session.ts +32 -0
- package/src/demo/demo-start.tsx +150 -0
- package/src/feedback/feedback-inbox.tsx +21 -8
- package/src/feedback/feedback-labels.ts +2 -1
- package/src/feedback/feedback-record.ts +10 -7
- package/src/feedback/feedback-row-detail.tsx +28 -4
- package/src/feedback/feedback-swipe.tsx +1 -1
- package/src/hooks/use-anchored-panel.ts +14 -3
- package/src/i18n/defaults.ts +28 -0
- package/src/i18n/german.ts +327 -5
- package/src/i18n/kit-labels.tsx +42 -0
- package/src/i18n/locales/es.ts +313 -3
- package/src/i18n/locales/fr.ts +316 -0
- package/src/i18n/locales/hu.ts +308 -5
- package/src/i18n/locales/it.ts +313 -0
- package/src/i18n/locales/zh.ts +286 -0
- package/src/i18n/review.ts +49 -0
- package/src/index.ts +184 -0
- package/src/landing/access.ts +97 -0
- package/src/landing/landing-actions.tsx +92 -0
- package/src/landing/landing-labels.ts +59 -0
- package/src/landing/landing-sections.tsx +337 -0
- package/src/landing/page-seo.ts +251 -0
- package/src/landing/public-header.tsx +120 -0
- package/src/landing/routing.tsx +209 -0
- package/src/settings/settings-catalogue.ts +132 -0
- package/src/settings/settings-context.ts +33 -0
- package/src/settings/settings-heading.tsx +65 -0
- package/src/settings/settings-labels.ts +75 -0
- package/src/settings/settings-layout.tsx +379 -0
- package/src/settings/settings-section.tsx +108 -0
- package/src/settings/use-account-language.ts +146 -0
- package/src/settings/use-settings-focus.ts +120 -0
- package/src/settings/use-settings-route.ts +258 -0
- package/src/shell/app-shell.tsx +10 -2
- package/src/shell.ts +45 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentPropsWithoutRef } from 'react';
|
|
3
|
+
import { AccessChoice } from '../landing/access.js';
|
|
4
|
+
import { LandingLabels } from '../landing/landing-labels.js';
|
|
5
|
+
import { DemoExpiry } from './demo-countdown.js';
|
|
6
|
+
import { DemoLabels } from './demo-labels.js';
|
|
7
|
+
import { DemoModel } from './demo-session.js';
|
|
8
|
+
|
|
9
|
+
interface DemoBannerProps extends Omit<ComponentPropsWithoutRef<"div">, "children" | "onClick"> {
|
|
10
|
+
/** The demo's end: `expires_at` from the `TokenResponse`, or `demo_expires_at` from
|
|
11
|
+
* `/auth/me` (§5.3). */
|
|
12
|
+
expiresAt: DemoExpiry | null | undefined;
|
|
13
|
+
/** Which line the banner says about the data (§2.3). */
|
|
14
|
+
model: DemoModel;
|
|
15
|
+
/** "Request access". */
|
|
16
|
+
access: AccessChoice;
|
|
17
|
+
/** "Sign in" — let through for a demo session by `RedirectIfAuthed allowDemo`. Default
|
|
18
|
+
* `/login`. */
|
|
19
|
+
signInHref?: string;
|
|
20
|
+
/** The countdown reached zero: clear the session and replace to `/demo/ended` (§5.5). */
|
|
21
|
+
onEnded?: () => void;
|
|
22
|
+
/** Where the collapsed state is kept for the tab's session. Default
|
|
23
|
+
* `kit.demoBanner.collapsed`. */
|
|
24
|
+
collapseKey?: string;
|
|
25
|
+
/** The clock, for tests and previews. Default `Date.now`. Keep it stable. */
|
|
26
|
+
now?: () => number;
|
|
27
|
+
labels?: Partial<DemoLabels>;
|
|
28
|
+
/** The access words (`landing` namespace) for this instance. */
|
|
29
|
+
landingLabels?: Partial<LandingLabels>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The demo's strip under the top bar, on every page of a demo session
|
|
33
|
+
* (docs/landing-demo-harmonization.md §5.4) — a kit `AlertBanner` strip:
|
|
34
|
+
*
|
|
35
|
+
* - the time left, "Demo · 23 h 12 min left" — minutes only in the last hour, and the
|
|
36
|
+
* warning tone in the last ten minutes (`useDemoCountdown`);
|
|
37
|
+
* - one line on the model: R "You're looking at sample data. Changes aren't possible.",
|
|
38
|
+
* S "Your own work is deleted when the demo ends.";
|
|
39
|
+
* - "Request access" (the mail) and "Sign in".
|
|
40
|
+
*
|
|
41
|
+
* It collapses to the countdown alone, for the tab's session (`sessionStorage`) — never
|
|
42
|
+
* hidden for good: it is a live state, like keksdose's preview banner, which a demo user
|
|
43
|
+
* gets instead of. At zero it calls `onEnded`.
|
|
44
|
+
*
|
|
45
|
+
* The countdown is no live region: a sentence read out every minute would drown the
|
|
46
|
+
* page. A screen-reader user meets it at the top of the page, and the end page says
|
|
47
|
+
* the rest.
|
|
48
|
+
*/
|
|
49
|
+
declare function DemoBanner({ expiresAt, model, access, signInHref, onEnded, collapseKey, now, labels: labelsProp, landingLabels, className, ...rest }: DemoBannerProps): react.JSX.Element;
|
|
50
|
+
|
|
51
|
+
export { DemoBanner, type DemoBannerProps };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { ChevronDown, ChevronUp, Timer } from "lucide-react";
|
|
5
|
+
import { cn } from "../lib/cn.js";
|
|
6
|
+
import { AlertBanner } from "../components/alert-banner.js";
|
|
7
|
+
import { Button, IconButton } from "../components/ui.js";
|
|
8
|
+
import { useAccessAction } from "../landing/access.js";
|
|
9
|
+
import { useLandingLabels } from "../landing/landing-labels.js";
|
|
10
|
+
import { useDemoCountdown } from "./demo-countdown.js";
|
|
11
|
+
import { useDemoLabels } from "./demo-labels.js";
|
|
12
|
+
const COLLAPSE_KEY = "kit.demoBanner.collapsed";
|
|
13
|
+
function readSession(key) {
|
|
14
|
+
if (typeof window === "undefined") return null;
|
|
15
|
+
try {
|
|
16
|
+
return window.sessionStorage.getItem(key);
|
|
17
|
+
} catch {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function writeSession(key, value) {
|
|
22
|
+
if (typeof window === "undefined") return;
|
|
23
|
+
try {
|
|
24
|
+
if (value === null) window.sessionStorage.removeItem(key);
|
|
25
|
+
else window.sessionStorage.setItem(key, value);
|
|
26
|
+
} catch {
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function timeText(countdown, labels) {
|
|
30
|
+
if (countdown.minutesLeft === null) return labels.badge;
|
|
31
|
+
if (countdown.ended) return labels.endedTitle;
|
|
32
|
+
return countdown.lastHour ? labels.minutesLeft(countdown.minutes) : labels.hoursLeft(countdown.hours, countdown.minutes);
|
|
33
|
+
}
|
|
34
|
+
function DemoBanner({
|
|
35
|
+
expiresAt,
|
|
36
|
+
model,
|
|
37
|
+
access,
|
|
38
|
+
signInHref = "/login",
|
|
39
|
+
onEnded,
|
|
40
|
+
collapseKey = COLLAPSE_KEY,
|
|
41
|
+
now,
|
|
42
|
+
labels: labelsProp,
|
|
43
|
+
landingLabels,
|
|
44
|
+
className,
|
|
45
|
+
...rest
|
|
46
|
+
}) {
|
|
47
|
+
const labels = useDemoLabels(labelsProp);
|
|
48
|
+
const landing = useLandingLabels(landingLabels);
|
|
49
|
+
const accessLink = useAccessAction(access, landingLabels);
|
|
50
|
+
const countdown = useDemoCountdown(expiresAt, { now, onEnded });
|
|
51
|
+
const [collapsed, setCollapsed] = useState(() => readSession(collapseKey) === "1");
|
|
52
|
+
const toggle = () => {
|
|
53
|
+
const next = !collapsed;
|
|
54
|
+
setCollapsed(next);
|
|
55
|
+
writeSession(collapseKey, next ? "1" : null);
|
|
56
|
+
};
|
|
57
|
+
return /* @__PURE__ */ jsxs(
|
|
58
|
+
AlertBanner,
|
|
59
|
+
{
|
|
60
|
+
...rest,
|
|
61
|
+
variant: "strip",
|
|
62
|
+
size: "sm",
|
|
63
|
+
tone: countdown.warning || countdown.ended ? "warning" : "info",
|
|
64
|
+
icon: /* @__PURE__ */ jsx(Timer, {}),
|
|
65
|
+
"data-demo-model": model,
|
|
66
|
+
className: cn("sm:text-sm", className),
|
|
67
|
+
action: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
68
|
+
!collapsed && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
69
|
+
/* @__PURE__ */ jsx(Button, { href: accessLink.href, variant: "brand", size: "sm", children: accessLink.label }),
|
|
70
|
+
/* @__PURE__ */ jsx(Button, { href: signInHref, variant: "secondary", size: "sm", children: landing.signIn })
|
|
71
|
+
] }),
|
|
72
|
+
/* @__PURE__ */ jsx(
|
|
73
|
+
IconButton,
|
|
74
|
+
{
|
|
75
|
+
size: "2xs",
|
|
76
|
+
variant: "ghost",
|
|
77
|
+
label: labels.details,
|
|
78
|
+
"aria-expanded": !collapsed,
|
|
79
|
+
onClick: toggle,
|
|
80
|
+
children: collapsed ? /* @__PURE__ */ jsx(ChevronDown, {}) : /* @__PURE__ */ jsx(ChevronUp, {})
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
] }),
|
|
84
|
+
children: [
|
|
85
|
+
/* @__PURE__ */ jsx("span", { className: "font-semibold", children: timeText(countdown, labels) }),
|
|
86
|
+
!collapsed && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
87
|
+
" ",
|
|
88
|
+
/* @__PURE__ */ jsx("span", { children: model === "read-only" ? labels.readOnly : labels.sandbox })
|
|
89
|
+
] })
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
export {
|
|
95
|
+
DemoBanner
|
|
96
|
+
};
|
|
97
|
+
//# sourceMappingURL=demo-banner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/demo/demo-banner.tsx"],"sourcesContent":["import { useState } from \"react\";\nimport type { ComponentPropsWithoutRef } from \"react\";\nimport { ChevronDown, ChevronUp, Timer } from \"lucide-react\";\n\nimport { cn } from \"../lib/cn\";\nimport { AlertBanner } from \"../components/alert-banner\";\nimport { Button, IconButton } from \"../components/ui\";\nimport { useAccessAction } from \"../landing/access\";\nimport type { AccessChoice } from \"../landing/access\";\nimport { useLandingLabels } from \"../landing/landing-labels\";\nimport type { LandingLabels } from \"../landing/landing-labels\";\nimport { useDemoCountdown } from \"./demo-countdown\";\nimport type { DemoCountdown, DemoExpiry } from \"./demo-countdown\";\nimport { useDemoLabels } from \"./demo-labels\";\nimport type { DemoLabels } from \"./demo-labels\";\nimport type { DemoModel } from \"./demo-session\";\n\n/** The default `sessionStorage` key of the collapsed state. */\nconst COLLAPSE_KEY = \"kit.demoBanner.collapsed\";\n\n/** `sessionStorage`, guarded like `lib/safe-storage`'s `localStorage`: blocked storage\n * reads as \"not set\" and writes nothing. */\nfunction readSession(key: string): string | null {\n if (typeof window === \"undefined\") return null;\n try {\n return window.sessionStorage.getItem(key);\n } catch {\n return null;\n }\n}\n\nfunction writeSession(key: string, value: string | null): void {\n if (typeof window === \"undefined\") return;\n try {\n if (value === null) window.sessionStorage.removeItem(key);\n else window.sessionStorage.setItem(key, value);\n } catch {\n // storage blocked: the banner just opens again next time\n }\n}\n\n/** \"Demo · 23 h 12 min left\", \"Demo · 50 min left\", the end, or plain \"Demo\". */\nfunction timeText(countdown: DemoCountdown, labels: DemoLabels): string {\n if (countdown.minutesLeft === null) return labels.badge;\n if (countdown.ended) return labels.endedTitle;\n return countdown.lastHour\n ? labels.minutesLeft(countdown.minutes)\n : labels.hoursLeft(countdown.hours, countdown.minutes);\n}\n\nexport interface DemoBannerProps extends Omit<ComponentPropsWithoutRef<\"div\">, \"children\" | \"onClick\"> {\n /** The demo's end: `expires_at` from the `TokenResponse`, or `demo_expires_at` from\n * `/auth/me` (§5.3). */\n expiresAt: DemoExpiry | null | undefined;\n /** Which line the banner says about the data (§2.3). */\n model: DemoModel;\n /** \"Request access\". */\n access: AccessChoice;\n /** \"Sign in\" — let through for a demo session by `RedirectIfAuthed allowDemo`. Default\n * `/login`. */\n signInHref?: string;\n /** The countdown reached zero: clear the session and replace to `/demo/ended` (§5.5). */\n onEnded?: () => void;\n /** Where the collapsed state is kept for the tab's session. Default\n * `kit.demoBanner.collapsed`. */\n collapseKey?: string;\n /** The clock, for tests and previews. Default `Date.now`. Keep it stable. */\n now?: () => number;\n labels?: Partial<DemoLabels>;\n /** The access words (`landing` namespace) for this instance. */\n landingLabels?: Partial<LandingLabels>;\n}\n\n/**\n * The demo's strip under the top bar, on every page of a demo session\n * (docs/landing-demo-harmonization.md §5.4) — a kit `AlertBanner` strip:\n *\n * - the time left, \"Demo · 23 h 12 min left\" — minutes only in the last hour, and the\n * warning tone in the last ten minutes (`useDemoCountdown`);\n * - one line on the model: R \"You're looking at sample data. Changes aren't possible.\",\n * S \"Your own work is deleted when the demo ends.\";\n * - \"Request access\" (the mail) and \"Sign in\".\n *\n * It collapses to the countdown alone, for the tab's session (`sessionStorage`) — never\n * hidden for good: it is a live state, like keksdose's preview banner, which a demo user\n * gets instead of. At zero it calls `onEnded`.\n *\n * The countdown is no live region: a sentence read out every minute would drown the\n * page. A screen-reader user meets it at the top of the page, and the end page says\n * the rest.\n */\nexport function DemoBanner({\n expiresAt,\n model,\n access,\n signInHref = \"/login\",\n onEnded,\n collapseKey = COLLAPSE_KEY,\n now,\n labels: labelsProp,\n landingLabels,\n className,\n ...rest\n}: DemoBannerProps) {\n const labels = useDemoLabels(labelsProp);\n const landing = useLandingLabels(landingLabels);\n const accessLink = useAccessAction(access, landingLabels);\n const countdown = useDemoCountdown(expiresAt, { now, onEnded });\n const [collapsed, setCollapsed] = useState(() => readSession(collapseKey) === \"1\");\n\n const toggle = () => {\n const next = !collapsed;\n setCollapsed(next);\n writeSession(collapseKey, next ? \"1\" : null);\n };\n\n return (\n <AlertBanner\n {...rest}\n variant=\"strip\"\n size=\"sm\"\n tone={countdown.warning || countdown.ended ? \"warning\" : \"info\"}\n icon={<Timer />}\n data-demo-model={model}\n className={cn(\"sm:text-sm\", className)}\n action={\n <>\n {!collapsed && (\n <>\n <Button href={accessLink.href} variant=\"brand\" size=\"sm\">\n {accessLink.label}\n </Button>\n <Button href={signInHref} variant=\"secondary\" size=\"sm\">\n {landing.signIn}\n </Button>\n </>\n )}\n <IconButton\n size=\"2xs\"\n variant=\"ghost\"\n label={labels.details}\n aria-expanded={!collapsed}\n onClick={toggle}\n >\n {collapsed ? <ChevronDown /> : <ChevronUp />}\n </IconButton>\n </>\n }\n >\n <span className=\"font-semibold\">{timeText(countdown, labels)}</span>\n {!collapsed && (\n <>\n {\" \"}\n <span>{model === \"read-only\" ? labels.readOnly : labels.sandbox}</span>\n </>\n )}\n </AlertBanner>\n );\n}\n"],"mappings":";AA0HY,SAMA,UANA,KAMA,YANA;AA1HZ,SAAS,gBAAgB;AAEzB,SAAS,aAAa,WAAW,aAAa;AAE9C,SAAS,UAAU;AACnB,SAAS,mBAAmB;AAC5B,SAAS,QAAQ,kBAAkB;AACnC,SAAS,uBAAuB;AAEhC,SAAS,wBAAwB;AAEjC,SAAS,wBAAwB;AAEjC,SAAS,qBAAqB;AAK9B,MAAM,eAAe;AAIrB,SAAS,YAAY,KAA4B;AAC/C,MAAI,OAAO,WAAW,YAAa,QAAO;AAC1C,MAAI;AACF,WAAO,OAAO,eAAe,QAAQ,GAAG;AAAA,EAC1C,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,aAAa,KAAa,OAA4B;AAC7D,MAAI,OAAO,WAAW,YAAa;AACnC,MAAI;AACF,QAAI,UAAU,KAAM,QAAO,eAAe,WAAW,GAAG;AAAA,QACnD,QAAO,eAAe,QAAQ,KAAK,KAAK;AAAA,EAC/C,QAAQ;AAAA,EAER;AACF;AAGA,SAAS,SAAS,WAA0B,QAA4B;AACtE,MAAI,UAAU,gBAAgB,KAAM,QAAO,OAAO;AAClD,MAAI,UAAU,MAAO,QAAO,OAAO;AACnC,SAAO,UAAU,WACb,OAAO,YAAY,UAAU,OAAO,IACpC,OAAO,UAAU,UAAU,OAAO,UAAU,OAAO;AACzD;AA2CO,SAAS,WAAW;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA,aAAa;AAAA,EACb;AAAA,EACA,cAAc;AAAA,EACd;AAAA,EACA,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAoB;AAClB,QAAM,SAAS,cAAc,UAAU;AACvC,QAAM,UAAU,iBAAiB,aAAa;AAC9C,QAAM,aAAa,gBAAgB,QAAQ,aAAa;AACxD,QAAM,YAAY,iBAAiB,WAAW,EAAE,KAAK,QAAQ,CAAC;AAC9D,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,MAAM,YAAY,WAAW,MAAM,GAAG;AAEjF,QAAM,SAAS,MAAM;AACnB,UAAM,OAAO,CAAC;AACd,iBAAa,IAAI;AACjB,iBAAa,aAAa,OAAO,MAAM,IAAI;AAAA,EAC7C;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,SAAQ;AAAA,MACR,MAAK;AAAA,MACL,MAAM,UAAU,WAAW,UAAU,QAAQ,YAAY;AAAA,MACzD,MAAM,oBAAC,SAAM;AAAA,MACb,mBAAiB;AAAA,MACjB,WAAW,GAAG,cAAc,SAAS;AAAA,MACrC,QACE,iCACG;AAAA,SAAC,aACA,iCACE;AAAA,8BAAC,UAAO,MAAM,WAAW,MAAM,SAAQ,SAAQ,MAAK,MACjD,qBAAW,OACd;AAAA,UACA,oBAAC,UAAO,MAAM,YAAY,SAAQ,aAAY,MAAK,MAChD,kBAAQ,QACX;AAAA,WACF;AAAA,QAEF;AAAA,UAAC;AAAA;AAAA,YACC,MAAK;AAAA,YACL,SAAQ;AAAA,YACR,OAAO,OAAO;AAAA,YACd,iBAAe,CAAC;AAAA,YAChB,SAAS;AAAA,YAER,sBAAY,oBAAC,eAAY,IAAK,oBAAC,aAAU;AAAA;AAAA,QAC5C;AAAA,SACF;AAAA,MAGF;AAAA,4BAAC,UAAK,WAAU,iBAAiB,mBAAS,WAAW,MAAM,GAAE;AAAA,QAC5D,CAAC,aACA,iCACG;AAAA;AAAA,UACD,oBAAC,UAAM,oBAAU,cAAc,OAAO,WAAW,OAAO,SAAQ;AAAA,WAClE;AAAA;AAAA;AAAA,EAEJ;AAEJ;","names":[]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The demo's countdown (docs/landing-demo-harmonization.md §5.3, §5.4): the time left to
|
|
3
|
+
* the demo account's end, from `expires_at` (the `TokenResponse`) or `demo_expires_at`
|
|
4
|
+
* (`/auth/me`). The client never decodes the JWT.
|
|
5
|
+
*/
|
|
6
|
+
/** When the demo ends: an ISO timestamp from the server, epoch milliseconds, or a
|
|
7
|
+
* `Date`. */
|
|
8
|
+
type DemoExpiry = string | number | Date;
|
|
9
|
+
/** The last stretch, in minutes, in which the banner turns to the warning tone (§5.4). */
|
|
10
|
+
declare const DEMO_WARNING_MINUTES = 10;
|
|
11
|
+
/** Below this many minutes the countdown shows minutes only (§5.4). */
|
|
12
|
+
declare const DEMO_MINUTES_ONLY = 60;
|
|
13
|
+
interface DemoCountdown {
|
|
14
|
+
/**
|
|
15
|
+
* Whole minutes left, ROUNDED UP — 30 s left is "1 min", and 0 only once the demo has
|
|
16
|
+
* ended. `null` when `expiresAt` cannot be read: the countdown then shows no time and
|
|
17
|
+
* never ends by itself (a parse slip must not throw a visitor out).
|
|
18
|
+
*/
|
|
19
|
+
minutesLeft: number | null;
|
|
20
|
+
/** The display split: whole hours, and the minutes past them. In the last hour
|
|
21
|
+
* (`lastHour`) `hours` is 0 and `minutes` is `minutesLeft`. */
|
|
22
|
+
hours: number;
|
|
23
|
+
minutes: number;
|
|
24
|
+
/** `minutesLeft <= 60`: show minutes only. */
|
|
25
|
+
lastHour: boolean;
|
|
26
|
+
/** `minutesLeft <= 10`: the warning tone. */
|
|
27
|
+
warning: boolean;
|
|
28
|
+
/** The demo's time is up. */
|
|
29
|
+
ended: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The countdown at `now` — pure, for a test or a server-rendered value. See
|
|
33
|
+
* {@link DemoCountdown} for the rounding and the thresholds.
|
|
34
|
+
*/
|
|
35
|
+
declare function demoCountdown(expiresAt: DemoExpiry | null | undefined, now: number): DemoCountdown;
|
|
36
|
+
interface DemoCountdownOptions {
|
|
37
|
+
/**
|
|
38
|
+
* The clock, in epoch milliseconds. Default `Date.now`. A test passes its own (or uses
|
|
39
|
+
* fake timers, which move `Date.now` too). Keep it a stable function — a new one each
|
|
40
|
+
* render re-arms the timer each render.
|
|
41
|
+
*/
|
|
42
|
+
now?: () => number;
|
|
43
|
+
/** Called once when the countdown reaches zero — also on mount, if it already has.
|
|
44
|
+
* The app clears the session and replaces to `/demo/ended` (§5.5). */
|
|
45
|
+
onEnded?: () => void;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The time left to `expiresAt`, re-rendering when the shown minute changes — one timer
|
|
49
|
+
* to the next minute boundary, not a tick a second — and once more when the tab comes
|
|
50
|
+
* back from the background (a hidden tab's timers are throttled).
|
|
51
|
+
*
|
|
52
|
+
* `onEnded` fires at zero (§5.5). The countdown is the client's, from `expires_at`; the
|
|
53
|
+
* server's answer to a request after the end (a 401) ends the demo as well — the app's
|
|
54
|
+
* 401 handler, not this hook.
|
|
55
|
+
*/
|
|
56
|
+
declare function useDemoCountdown(expiresAt: DemoExpiry | null | undefined, { now, onEnded }?: DemoCountdownOptions): DemoCountdown;
|
|
57
|
+
|
|
58
|
+
export { DEMO_MINUTES_ONLY, DEMO_WARNING_MINUTES, type DemoCountdown, type DemoCountdownOptions, type DemoExpiry, demoCountdown, useDemoCountdown };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useEffectEvent, useSyncExternalStore } from "react";
|
|
3
|
+
const DEMO_WARNING_MINUTES = 10;
|
|
4
|
+
const DEMO_MINUTES_ONLY = 60;
|
|
5
|
+
const MINUTE = 6e4;
|
|
6
|
+
function expiryMs(expiresAt) {
|
|
7
|
+
if (expiresAt === null || expiresAt === void 0) return Number.NaN;
|
|
8
|
+
if (typeof expiresAt === "number") return expiresAt;
|
|
9
|
+
if (expiresAt instanceof Date) return expiresAt.getTime();
|
|
10
|
+
return Date.parse(expiresAt);
|
|
11
|
+
}
|
|
12
|
+
function minutesAt(expiry, now) {
|
|
13
|
+
if (!Number.isFinite(expiry)) return null;
|
|
14
|
+
return Math.max(0, Math.ceil((expiry - now) / MINUTE));
|
|
15
|
+
}
|
|
16
|
+
function demoCountdown(expiresAt, now) {
|
|
17
|
+
return countdownOf(minutesAt(expiryMs(expiresAt), now));
|
|
18
|
+
}
|
|
19
|
+
function countdownOf(minutesLeft) {
|
|
20
|
+
if (minutesLeft === null) {
|
|
21
|
+
return { minutesLeft, hours: 0, minutes: 0, lastHour: false, warning: false, ended: false };
|
|
22
|
+
}
|
|
23
|
+
const lastHour = minutesLeft <= DEMO_MINUTES_ONLY;
|
|
24
|
+
return {
|
|
25
|
+
minutesLeft,
|
|
26
|
+
hours: lastHour ? 0 : Math.floor(minutesLeft / 60),
|
|
27
|
+
minutes: lastHour ? minutesLeft : minutesLeft % 60,
|
|
28
|
+
lastHour,
|
|
29
|
+
warning: minutesLeft <= DEMO_WARNING_MINUTES,
|
|
30
|
+
ended: minutesLeft === 0
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function useDemoCountdown(expiresAt, { now = Date.now, onEnded } = {}) {
|
|
34
|
+
const expiry = expiryMs(expiresAt);
|
|
35
|
+
const subscribe = useCallback(
|
|
36
|
+
(notify) => {
|
|
37
|
+
if (!Number.isFinite(expiry)) return () => {
|
|
38
|
+
};
|
|
39
|
+
let timer;
|
|
40
|
+
const arm = () => {
|
|
41
|
+
const left = expiry - now();
|
|
42
|
+
if (left <= 0) return;
|
|
43
|
+
const delay = left - (Math.ceil(left / MINUTE) - 1) * MINUTE;
|
|
44
|
+
timer = setTimeout(() => {
|
|
45
|
+
notify();
|
|
46
|
+
arm();
|
|
47
|
+
}, delay);
|
|
48
|
+
};
|
|
49
|
+
const onVisible = () => {
|
|
50
|
+
if (document.visibilityState !== "visible") return;
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
notify();
|
|
53
|
+
arm();
|
|
54
|
+
};
|
|
55
|
+
arm();
|
|
56
|
+
document.addEventListener("visibilitychange", onVisible);
|
|
57
|
+
return () => {
|
|
58
|
+
clearTimeout(timer);
|
|
59
|
+
document.removeEventListener("visibilitychange", onVisible);
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
[expiry, now]
|
|
63
|
+
);
|
|
64
|
+
const snapshot = () => minutesAt(expiry, now());
|
|
65
|
+
const minutesLeft = useSyncExternalStore(subscribe, snapshot, snapshot);
|
|
66
|
+
const countdown = countdownOf(minutesLeft);
|
|
67
|
+
const fireEnded = useEffectEvent(() => onEnded?.());
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
if (countdown.ended) fireEnded();
|
|
70
|
+
}, [countdown.ended]);
|
|
71
|
+
return countdown;
|
|
72
|
+
}
|
|
73
|
+
export {
|
|
74
|
+
DEMO_MINUTES_ONLY,
|
|
75
|
+
DEMO_WARNING_MINUTES,
|
|
76
|
+
demoCountdown,
|
|
77
|
+
useDemoCountdown
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=demo-countdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/demo/demo-countdown.ts"],"sourcesContent":["import { useCallback, useEffect, useEffectEvent, useSyncExternalStore } from \"react\";\n\n/**\n * The demo's countdown (docs/landing-demo-harmonization.md §5.3, §5.4): the time left to\n * the demo account's end, from `expires_at` (the `TokenResponse`) or `demo_expires_at`\n * (`/auth/me`). The client never decodes the JWT.\n */\n\n/** When the demo ends: an ISO timestamp from the server, epoch milliseconds, or a\n * `Date`. */\nexport type DemoExpiry = string | number | Date;\n\n/** The last stretch, in minutes, in which the banner turns to the warning tone (§5.4). */\nexport const DEMO_WARNING_MINUTES = 10;\n/** Below this many minutes the countdown shows minutes only (§5.4). */\nexport const DEMO_MINUTES_ONLY = 60;\n\nconst MINUTE = 60_000;\n\nexport interface DemoCountdown {\n /**\n * Whole minutes left, ROUNDED UP — 30 s left is \"1 min\", and 0 only once the demo has\n * ended. `null` when `expiresAt` cannot be read: the countdown then shows no time and\n * never ends by itself (a parse slip must not throw a visitor out).\n */\n minutesLeft: number | null;\n /** The display split: whole hours, and the minutes past them. In the last hour\n * (`lastHour`) `hours` is 0 and `minutes` is `minutesLeft`. */\n hours: number;\n minutes: number;\n /** `minutesLeft <= 60`: show minutes only. */\n lastHour: boolean;\n /** `minutesLeft <= 10`: the warning tone. */\n warning: boolean;\n /** The demo's time is up. */\n ended: boolean;\n}\n\n/** `expiresAt` as epoch milliseconds, or NaN. */\nfunction expiryMs(expiresAt: DemoExpiry | null | undefined): number {\n if (expiresAt === null || expiresAt === undefined) return Number.NaN;\n if (typeof expiresAt === \"number\") return expiresAt;\n if (expiresAt instanceof Date) return expiresAt.getTime();\n return Date.parse(expiresAt);\n}\n\n/** Whole minutes left at `now`, rounded up, never below 0; null for an unreadable end. */\nfunction minutesAt(expiry: number, now: number): number | null {\n if (!Number.isFinite(expiry)) return null;\n return Math.max(0, Math.ceil((expiry - now) / MINUTE));\n}\n\n/**\n * The countdown at `now` — pure, for a test or a server-rendered value. See\n * {@link DemoCountdown} for the rounding and the thresholds.\n */\nexport function demoCountdown(expiresAt: DemoExpiry | null | undefined, now: number): DemoCountdown {\n return countdownOf(minutesAt(expiryMs(expiresAt), now));\n}\n\nfunction countdownOf(minutesLeft: number | null): DemoCountdown {\n if (minutesLeft === null) {\n return { minutesLeft, hours: 0, minutes: 0, lastHour: false, warning: false, ended: false };\n }\n const lastHour = minutesLeft <= DEMO_MINUTES_ONLY;\n return {\n minutesLeft,\n hours: lastHour ? 0 : Math.floor(minutesLeft / 60),\n minutes: lastHour ? minutesLeft : minutesLeft % 60,\n lastHour,\n warning: minutesLeft <= DEMO_WARNING_MINUTES,\n ended: minutesLeft === 0,\n };\n}\n\nexport interface DemoCountdownOptions {\n /**\n * The clock, in epoch milliseconds. Default `Date.now`. A test passes its own (or uses\n * fake timers, which move `Date.now` too). Keep it a stable function — a new one each\n * render re-arms the timer each render.\n */\n now?: () => number;\n /** Called once when the countdown reaches zero — also on mount, if it already has.\n * The app clears the session and replaces to `/demo/ended` (§5.5). */\n onEnded?: () => void;\n}\n\n/**\n * The time left to `expiresAt`, re-rendering when the shown minute changes — one timer\n * to the next minute boundary, not a tick a second — and once more when the tab comes\n * back from the background (a hidden tab's timers are throttled).\n *\n * `onEnded` fires at zero (§5.5). The countdown is the client's, from `expires_at`; the\n * server's answer to a request after the end (a 401) ends the demo as well — the app's\n * 401 handler, not this hook.\n */\nexport function useDemoCountdown(\n expiresAt: DemoExpiry | null | undefined,\n { now = Date.now, onEnded }: DemoCountdownOptions = {},\n): DemoCountdown {\n const expiry = expiryMs(expiresAt);\n const subscribe = useCallback(\n (notify: () => void) => {\n if (!Number.isFinite(expiry)) return () => {};\n let timer: ReturnType<typeof setTimeout> | undefined;\n const arm = () => {\n const left = expiry - now();\n if (left <= 0) return;\n // The rounded-up minute changes when `left` crosses the next whole minute below.\n const delay = left - (Math.ceil(left / MINUTE) - 1) * MINUTE;\n timer = setTimeout(() => {\n notify();\n arm();\n }, delay);\n };\n const onVisible = () => {\n if (document.visibilityState !== \"visible\") return;\n clearTimeout(timer);\n notify();\n arm();\n };\n arm();\n document.addEventListener(\"visibilitychange\", onVisible);\n return () => {\n clearTimeout(timer);\n document.removeEventListener(\"visibilitychange\", onVisible);\n };\n },\n [expiry, now],\n );\n const snapshot = () => minutesAt(expiry, now());\n const minutesLeft = useSyncExternalStore(subscribe, snapshot, snapshot);\n const countdown = countdownOf(minutesLeft);\n\n const fireEnded = useEffectEvent(() => onEnded?.());\n useEffect(() => {\n if (countdown.ended) fireEnded();\n }, [countdown.ended]);\n\n return countdown;\n}\n"],"mappings":";AAAA,SAAS,aAAa,WAAW,gBAAgB,4BAA4B;AAatE,MAAM,uBAAuB;AAE7B,MAAM,oBAAoB;AAEjC,MAAM,SAAS;AAsBf,SAAS,SAAS,WAAkD;AAClE,MAAI,cAAc,QAAQ,cAAc,OAAW,QAAO,OAAO;AACjE,MAAI,OAAO,cAAc,SAAU,QAAO;AAC1C,MAAI,qBAAqB,KAAM,QAAO,UAAU,QAAQ;AACxD,SAAO,KAAK,MAAM,SAAS;AAC7B;AAGA,SAAS,UAAU,QAAgB,KAA4B;AAC7D,MAAI,CAAC,OAAO,SAAS,MAAM,EAAG,QAAO;AACrC,SAAO,KAAK,IAAI,GAAG,KAAK,MAAM,SAAS,OAAO,MAAM,CAAC;AACvD;AAMO,SAAS,cAAc,WAA0C,KAA4B;AAClG,SAAO,YAAY,UAAU,SAAS,SAAS,GAAG,GAAG,CAAC;AACxD;AAEA,SAAS,YAAY,aAA2C;AAC9D,MAAI,gBAAgB,MAAM;AACxB,WAAO,EAAE,aAAa,OAAO,GAAG,SAAS,GAAG,UAAU,OAAO,SAAS,OAAO,OAAO,MAAM;AAAA,EAC5F;AACA,QAAM,WAAW,eAAe;AAChC,SAAO;AAAA,IACL;AAAA,IACA,OAAO,WAAW,IAAI,KAAK,MAAM,cAAc,EAAE;AAAA,IACjD,SAAS,WAAW,cAAc,cAAc;AAAA,IAChD;AAAA,IACA,SAAS,eAAe;AAAA,IACxB,OAAO,gBAAgB;AAAA,EACzB;AACF;AAuBO,SAAS,iBACd,WACA,EAAE,MAAM,KAAK,KAAK,QAAQ,IAA0B,CAAC,GACtC;AACf,QAAM,SAAS,SAAS,SAAS;AACjC,QAAM,YAAY;AAAA,IAChB,CAAC,WAAuB;AACtB,UAAI,CAAC,OAAO,SAAS,MAAM,EAAG,QAAO,MAAM;AAAA,MAAC;AAC5C,UAAI;AACJ,YAAM,MAAM,MAAM;AAChB,cAAM,OAAO,SAAS,IAAI;AAC1B,YAAI,QAAQ,EAAG;AAEf,cAAM,QAAQ,QAAQ,KAAK,KAAK,OAAO,MAAM,IAAI,KAAK;AACtD,gBAAQ,WAAW,MAAM;AACvB,iBAAO;AACP,cAAI;AAAA,QACN,GAAG,KAAK;AAAA,MACV;AACA,YAAM,YAAY,MAAM;AACtB,YAAI,SAAS,oBAAoB,UAAW;AAC5C,qBAAa,KAAK;AAClB,eAAO;AACP,YAAI;AAAA,MACN;AACA,UAAI;AACJ,eAAS,iBAAiB,oBAAoB,SAAS;AACvD,aAAO,MAAM;AACX,qBAAa,KAAK;AAClB,iBAAS,oBAAoB,oBAAoB,SAAS;AAAA,MAC5D;AAAA,IACF;AAAA,IACA,CAAC,QAAQ,GAAG;AAAA,EACd;AACA,QAAM,WAAW,MAAM,UAAU,QAAQ,IAAI,CAAC;AAC9C,QAAM,cAAc,qBAAqB,WAAW,UAAU,QAAQ;AACtE,QAAM,YAAY,YAAY,WAAW;AAEzC,QAAM,YAAY,eAAe,MAAM,UAAU,CAAC;AAClD,YAAU,MAAM;AACd,QAAI,UAAU,MAAO,WAAU;AAAA,EACjC,GAAG,CAAC,UAAU,KAAK,CAAC;AAEpB,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentPropsWithoutRef, ReactNode } from 'react';
|
|
3
|
+
import { AuthHeadingLevel } from '../auth/status-parts.js';
|
|
4
|
+
import { AccessChoice } from '../landing/access.js';
|
|
5
|
+
import { LandingLabels } from '../landing/landing-labels.js';
|
|
6
|
+
import { DemoLabels } from './demo-labels.js';
|
|
7
|
+
import { DemoModel } from './demo-session.js';
|
|
8
|
+
|
|
9
|
+
interface DemoEndedProps extends Omit<ComponentPropsWithoutRef<"div">, "children" | "title"> {
|
|
10
|
+
/** Which line the page says about the data (§2.3). */
|
|
11
|
+
model: DemoModel;
|
|
12
|
+
/** "Request access". */
|
|
13
|
+
access: AccessChoice;
|
|
14
|
+
/** "Start a new demo". Default `/demo` — a new demo may start after one ends, within
|
|
15
|
+
* the per-IP window (§2.7). */
|
|
16
|
+
restartHref?: string;
|
|
17
|
+
/** "Sign in". Default `/login`. */
|
|
18
|
+
signInHref?: string;
|
|
19
|
+
/** App content under the line. */
|
|
20
|
+
children?: ReactNode;
|
|
21
|
+
/** `false` adds no `noindex` — for a preview. Default `true` (§4.3). */
|
|
22
|
+
noIndex?: boolean;
|
|
23
|
+
/** Default `h2`, under `AuthLayout`'s `h1`. */
|
|
24
|
+
headingAs?: AuthHeadingLevel;
|
|
25
|
+
labels?: Partial<DemoLabels>;
|
|
26
|
+
/** The access words (`landing` namespace) for this instance. */
|
|
27
|
+
landingLabels?: Partial<LandingLabels>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The `/demo/ended` page's content (docs/landing-demo-harmonization.md §5.5): "The demo
|
|
31
|
+
* has ended", one line on what became of the data, and three ways on — "Start a new
|
|
32
|
+
* demo", "Request access", "Sign in".
|
|
33
|
+
*
|
|
34
|
+
* Where a demo lands at `expires_at`, or on ANY 401 while the session is a demo: the
|
|
35
|
+
* client clears the session and replaces to `/demo/ended`, never to `/login`. keksdose's
|
|
36
|
+
* expired demo met an unexplained sign-in form. The server deletes the user at the next
|
|
37
|
+
* reap; nothing is kept.
|
|
38
|
+
*
|
|
39
|
+
* Content, like `NotFoundPage`: put it in the app's `AuthLayout` (its logo, language
|
|
40
|
+
* menu and legal footer). It marks the page `noindex`; robots.txt must NOT disallow it,
|
|
41
|
+
* or a crawler could never read that (§10.8).
|
|
42
|
+
*/
|
|
43
|
+
declare function DemoEnded({ model, access, restartHref, signInHref, children, noIndex, headingAs: Heading, labels: labelsProp, landingLabels, className, ...rest }: DemoEndedProps): react.JSX.Element;
|
|
44
|
+
|
|
45
|
+
export { DemoEnded, type DemoEndedProps };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Hourglass } from "lucide-react";
|
|
4
|
+
import { cn } from "../lib/cn.js";
|
|
5
|
+
import { Button } from "../components/ui.js";
|
|
6
|
+
import { useNoIndex } from "../hooks/use-noindex.js";
|
|
7
|
+
import { useAccessAction } from "../landing/access.js";
|
|
8
|
+
import { useLandingLabels } from "../landing/landing-labels.js";
|
|
9
|
+
import { useDemoLabels } from "./demo-labels.js";
|
|
10
|
+
function DemoEnded({
|
|
11
|
+
model,
|
|
12
|
+
access,
|
|
13
|
+
restartHref = "/demo",
|
|
14
|
+
signInHref = "/login",
|
|
15
|
+
children,
|
|
16
|
+
noIndex = true,
|
|
17
|
+
headingAs: Heading = "h2",
|
|
18
|
+
labels: labelsProp,
|
|
19
|
+
landingLabels,
|
|
20
|
+
className,
|
|
21
|
+
...rest
|
|
22
|
+
}) {
|
|
23
|
+
const labels = useDemoLabels(labelsProp);
|
|
24
|
+
const landing = useLandingLabels(landingLabels);
|
|
25
|
+
const accessLink = useAccessAction(access, landingLabels);
|
|
26
|
+
useNoIndex(noIndex);
|
|
27
|
+
return /* @__PURE__ */ jsxs("div", { ...rest, className: cn("flex flex-col items-center gap-2 py-4 text-center", className), children: [
|
|
28
|
+
/* @__PURE__ */ jsx(Hourglass, { "aria-hidden": true, className: "size-10 text-[var(--text-placeholder)]" }),
|
|
29
|
+
/* @__PURE__ */ jsx(Heading, { className: "mt-2 text-xl font-semibold text-[var(--text-primary)]", children: labels.endedTitle }),
|
|
30
|
+
/* @__PURE__ */ jsx("p", { className: "max-w-prose text-sm text-[var(--text-secondary)]", children: model === "sandbox" ? labels.endedSandbox : labels.endedReadOnly }),
|
|
31
|
+
children,
|
|
32
|
+
/* @__PURE__ */ jsxs("div", { className: "mt-4 flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:flex-wrap sm:justify-center", children: [
|
|
33
|
+
/* @__PURE__ */ jsx(Button, { href: restartHref, variant: "brand", children: labels.restart }),
|
|
34
|
+
/* @__PURE__ */ jsx(Button, { href: accessLink.href, variant: "secondary", children: accessLink.label }),
|
|
35
|
+
/* @__PURE__ */ jsx(Button, { href: signInHref, variant: "secondary", children: landing.signIn })
|
|
36
|
+
] })
|
|
37
|
+
] });
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
DemoEnded
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=demo-ended.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/demo/demo-ended.tsx"],"sourcesContent":["import type { ComponentPropsWithoutRef, ReactNode } from \"react\";\nimport { Hourglass } from \"lucide-react\";\n\nimport { cn } from \"../lib/cn\";\nimport { Button } from \"../components/ui\";\nimport { useNoIndex } from \"../hooks/use-noindex\";\nimport type { AuthHeadingLevel } from \"../auth/status-parts\";\nimport { useAccessAction } from \"../landing/access\";\nimport type { AccessChoice } from \"../landing/access\";\nimport { useLandingLabels } from \"../landing/landing-labels\";\nimport type { LandingLabels } from \"../landing/landing-labels\";\nimport { useDemoLabels } from \"./demo-labels\";\nimport type { DemoLabels } from \"./demo-labels\";\nimport type { DemoModel } from \"./demo-session\";\n\nexport interface DemoEndedProps extends Omit<ComponentPropsWithoutRef<\"div\">, \"children\" | \"title\"> {\n /** Which line the page says about the data (§2.3). */\n model: DemoModel;\n /** \"Request access\". */\n access: AccessChoice;\n /** \"Start a new demo\". Default `/demo` — a new demo may start after one ends, within\n * the per-IP window (§2.7). */\n restartHref?: string;\n /** \"Sign in\". Default `/login`. */\n signInHref?: string;\n /** App content under the line. */\n children?: ReactNode;\n /** `false` adds no `noindex` — for a preview. Default `true` (§4.3). */\n noIndex?: boolean;\n /** Default `h2`, under `AuthLayout`'s `h1`. */\n headingAs?: AuthHeadingLevel;\n labels?: Partial<DemoLabels>;\n /** The access words (`landing` namespace) for this instance. */\n landingLabels?: Partial<LandingLabels>;\n}\n\n/**\n * The `/demo/ended` page's content (docs/landing-demo-harmonization.md §5.5): \"The demo\n * has ended\", one line on what became of the data, and three ways on — \"Start a new\n * demo\", \"Request access\", \"Sign in\".\n *\n * Where a demo lands at `expires_at`, or on ANY 401 while the session is a demo: the\n * client clears the session and replaces to `/demo/ended`, never to `/login`. keksdose's\n * expired demo met an unexplained sign-in form. The server deletes the user at the next\n * reap; nothing is kept.\n *\n * Content, like `NotFoundPage`: put it in the app's `AuthLayout` (its logo, language\n * menu and legal footer). It marks the page `noindex`; robots.txt must NOT disallow it,\n * or a crawler could never read that (§10.8).\n */\nexport function DemoEnded({\n model,\n access,\n restartHref = \"/demo\",\n signInHref = \"/login\",\n children,\n noIndex = true,\n headingAs: Heading = \"h2\",\n labels: labelsProp,\n landingLabels,\n className,\n ...rest\n}: DemoEndedProps) {\n const labels = useDemoLabels(labelsProp);\n const landing = useLandingLabels(landingLabels);\n const accessLink = useAccessAction(access, landingLabels);\n useNoIndex(noIndex);\n return (\n <div {...rest} className={cn(\"flex flex-col items-center gap-2 py-4 text-center\", className)}>\n <Hourglass aria-hidden className=\"size-10 text-[var(--text-placeholder)]\" />\n <Heading className=\"mt-2 text-xl font-semibold text-[var(--text-primary)]\">{labels.endedTitle}</Heading>\n <p className=\"max-w-prose text-sm text-[var(--text-secondary)]\">\n {model === \"sandbox\" ? labels.endedSandbox : labels.endedReadOnly}\n </p>\n {children}\n <div className=\"mt-4 flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:flex-wrap sm:justify-center\">\n <Button href={restartHref} variant=\"brand\">\n {labels.restart}\n </Button>\n <Button href={accessLink.href} variant=\"secondary\">\n {accessLink.label}\n </Button>\n <Button href={signInHref} variant=\"secondary\">\n {landing.signIn}\n </Button>\n </div>\n </div>\n );\n}\n"],"mappings":";AAqEM,cAMA,YANA;AApEN,SAAS,iBAAiB;AAE1B,SAAS,UAAU;AACnB,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAE3B,SAAS,uBAAuB;AAEhC,SAAS,wBAAwB;AAEjC,SAAS,qBAAqB;AAuCvB,SAAS,UAAU;AAAA,EACxB;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,aAAa;AAAA,EACb;AAAA,EACA,UAAU;AAAA,EACV,WAAW,UAAU;AAAA,EACrB,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAmB;AACjB,QAAM,SAAS,cAAc,UAAU;AACvC,QAAM,UAAU,iBAAiB,aAAa;AAC9C,QAAM,aAAa,gBAAgB,QAAQ,aAAa;AACxD,aAAW,OAAO;AAClB,SACE,qBAAC,SAAK,GAAG,MAAM,WAAW,GAAG,qDAAqD,SAAS,GACzF;AAAA,wBAAC,aAAU,eAAW,MAAC,WAAU,0CAAyC;AAAA,IAC1E,oBAAC,WAAQ,WAAU,yDAAyD,iBAAO,YAAW;AAAA,IAC9F,oBAAC,OAAE,WAAU,oDACV,oBAAU,YAAY,OAAO,eAAe,OAAO,eACtD;AAAA,IACC;AAAA,IACD,qBAAC,SAAI,WAAU,wFACb;AAAA,0BAAC,UAAO,MAAM,aAAa,SAAQ,SAChC,iBAAO,SACV;AAAA,MACA,oBAAC,UAAO,MAAM,WAAW,MAAM,SAAQ,aACpC,qBAAW,OACd;AAAA,MACA,oBAAC,UAAO,MAAM,YAAY,SAAQ,aAC/B,kBAAQ,QACX;AAAA,OACF;AAAA,KACF;AAEJ;","names":[]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The demo's words (docs/landing-demo-harmonization.md §5) — the `demo` namespace of
|
|
3
|
+
* `<UiKitProvider labels>`: `DemoStart`'s progress and refusals, `DemoBanner`'s
|
|
4
|
+
* countdown and model line, `DemoEnded`, and the reason of the read-only lock.
|
|
5
|
+
*
|
|
6
|
+
* "Demo" means the demo session and the shared demo data it shows (§2.10) — never
|
|
7
|
+
* keksdose's blur toggle, which is "Presentation mode" now. "Request access" and "Sign
|
|
8
|
+
* in" are the `landing` namespace's, so they read the same on every public page.
|
|
9
|
+
*/
|
|
10
|
+
interface DemoLabels {
|
|
11
|
+
/** `DemoStart` while the demo is being created. */
|
|
12
|
+
starting: string;
|
|
13
|
+
/** `demo_rate_limited`: too many demos from one network, given the wait in whole
|
|
14
|
+
* minutes from `Retry-After` — or `undefined` without one. */
|
|
15
|
+
rateLimited: (minutes?: number) => string;
|
|
16
|
+
/** `demo_capacity`: the live cap is reached. */
|
|
17
|
+
capacity: string;
|
|
18
|
+
/** `demo_disabled` and `demo_not_ready`: the demo is off, or its data isn't there. */
|
|
19
|
+
unavailable: string;
|
|
20
|
+
/** Any other failure — the network, a 500. */
|
|
21
|
+
failed: string;
|
|
22
|
+
/** `DemoStart`'s way out after a refusal, to the landing. */
|
|
23
|
+
backToStart: string;
|
|
24
|
+
/** The banner's countdown with an hour or more left: "Demo · 23 h 12 min left". */
|
|
25
|
+
hoursLeft: (hours: number, minutes: number) => string;
|
|
26
|
+
/** …and in the last hour, minutes only: "Demo · 50 min left". */
|
|
27
|
+
minutesLeft: (minutes: number) => string;
|
|
28
|
+
/** The banner's word when the end is unknown (no readable `expiresAt`). */
|
|
29
|
+
badge: string;
|
|
30
|
+
/** The banner's line for model R, shared read-only data. */
|
|
31
|
+
readOnly: string;
|
|
32
|
+
/** The banner's line for model S, a sandbox of one's own. */
|
|
33
|
+
sandbox: string;
|
|
34
|
+
/** The name of the banner's show/hide toggle (`aria-expanded` says which). */
|
|
35
|
+
details: string;
|
|
36
|
+
/** The reason a locked commit shows in a read-only demo (model R) — for the app's
|
|
37
|
+
* `<WriteLockProvider locked reason={…}>` (§5.4). */
|
|
38
|
+
writeLocked: string;
|
|
39
|
+
/** `DemoEnded`'s heading; also the banner's text at zero. */
|
|
40
|
+
endedTitle: string;
|
|
41
|
+
/** `DemoEnded`'s line for model R. */
|
|
42
|
+
endedReadOnly: string;
|
|
43
|
+
/** `DemoEnded`'s line for model S. */
|
|
44
|
+
endedSandbox: string;
|
|
45
|
+
/** `DemoEnded`'s first action, to `/demo`. */
|
|
46
|
+
restart: string;
|
|
47
|
+
}
|
|
48
|
+
declare const DEFAULT_DEMO_LABELS: DemoLabels;
|
|
49
|
+
/** The `demo` namespace, resolved: English, then the provider, then `labels`. The app
|
|
50
|
+
* reads `writeLocked` from here for its `WriteLockProvider`. */
|
|
51
|
+
declare function useDemoLabels(labels?: Partial<DemoLabels>): DemoLabels;
|
|
52
|
+
|
|
53
|
+
export { DEFAULT_DEMO_LABELS, type DemoLabels, useDemoLabels };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useKitLabels } from "../i18n/kit-labels.js";
|
|
3
|
+
const DEFAULT_DEMO_LABELS = {
|
|
4
|
+
starting: "Starting the demo\u2026",
|
|
5
|
+
rateLimited: (minutes) => minutes ? `Too many demos from this network. Try again in ${minutes} min.` : "Too many demos from this network. Try again later.",
|
|
6
|
+
capacity: "The demo is full right now. Try again later.",
|
|
7
|
+
unavailable: "The demo isn\u2019t available right now.",
|
|
8
|
+
failed: "The demo could not be started. Please try again.",
|
|
9
|
+
backToStart: "Back to the start page",
|
|
10
|
+
hoursLeft: (hours, minutes) => `Demo \xB7 ${hours} h ${minutes} min left`,
|
|
11
|
+
minutesLeft: (minutes) => `Demo \xB7 ${minutes} min left`,
|
|
12
|
+
badge: "Demo",
|
|
13
|
+
readOnly: "You\u2019re looking at sample data. Changes aren\u2019t possible.",
|
|
14
|
+
sandbox: "Your own work is deleted when the demo ends.",
|
|
15
|
+
details: "Demo details",
|
|
16
|
+
writeLocked: "Not possible in the demo.",
|
|
17
|
+
endedTitle: "The demo has ended",
|
|
18
|
+
endedReadOnly: "Sample data is reset regularly.",
|
|
19
|
+
endedSandbox: "Sample data is reset regularly; your own work from the demo is deleted.",
|
|
20
|
+
restart: "Start a new demo"
|
|
21
|
+
};
|
|
22
|
+
function useDemoLabels(labels) {
|
|
23
|
+
return useKitLabels("demo", DEFAULT_DEMO_LABELS, labels);
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
DEFAULT_DEMO_LABELS,
|
|
27
|
+
useDemoLabels
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=demo-labels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/demo/demo-labels.ts"],"sourcesContent":["import { useKitLabels } from \"../i18n/kit-labels\";\n\n/**\n * The demo's words (docs/landing-demo-harmonization.md §5) — the `demo` namespace of\n * `<UiKitProvider labels>`: `DemoStart`'s progress and refusals, `DemoBanner`'s\n * countdown and model line, `DemoEnded`, and the reason of the read-only lock.\n *\n * \"Demo\" means the demo session and the shared demo data it shows (§2.10) — never\n * keksdose's blur toggle, which is \"Presentation mode\" now. \"Request access\" and \"Sign\n * in\" are the `landing` namespace's, so they read the same on every public page.\n */\nexport interface DemoLabels {\n /** `DemoStart` while the demo is being created. */\n starting: string;\n /** `demo_rate_limited`: too many demos from one network, given the wait in whole\n * minutes from `Retry-After` — or `undefined` without one. */\n rateLimited: (minutes?: number) => string;\n /** `demo_capacity`: the live cap is reached. */\n capacity: string;\n /** `demo_disabled` and `demo_not_ready`: the demo is off, or its data isn't there. */\n unavailable: string;\n /** Any other failure — the network, a 500. */\n failed: string;\n /** `DemoStart`'s way out after a refusal, to the landing. */\n backToStart: string;\n /** The banner's countdown with an hour or more left: \"Demo · 23 h 12 min left\". */\n hoursLeft: (hours: number, minutes: number) => string;\n /** …and in the last hour, minutes only: \"Demo · 50 min left\". */\n minutesLeft: (minutes: number) => string;\n /** The banner's word when the end is unknown (no readable `expiresAt`). */\n badge: string;\n /** The banner's line for model R, shared read-only data. */\n readOnly: string;\n /** The banner's line for model S, a sandbox of one's own. */\n sandbox: string;\n /** The name of the banner's show/hide toggle (`aria-expanded` says which). */\n details: string;\n /** The reason a locked commit shows in a read-only demo (model R) — for the app's\n * `<WriteLockProvider locked reason={…}>` (§5.4). */\n writeLocked: string;\n /** `DemoEnded`'s heading; also the banner's text at zero. */\n endedTitle: string;\n /** `DemoEnded`'s line for model R. */\n endedReadOnly: string;\n /** `DemoEnded`'s line for model S. */\n endedSandbox: string;\n /** `DemoEnded`'s first action, to `/demo`. */\n restart: string;\n}\n\nexport const DEFAULT_DEMO_LABELS: DemoLabels = {\n starting: \"Starting the demo…\",\n rateLimited: (minutes) =>\n minutes\n ? `Too many demos from this network. Try again in ${minutes} min.`\n : \"Too many demos from this network. Try again later.\",\n capacity: \"The demo is full right now. Try again later.\",\n unavailable: \"The demo isn’t available right now.\",\n failed: \"The demo could not be started. Please try again.\",\n backToStart: \"Back to the start page\",\n hoursLeft: (hours, minutes) => `Demo · ${hours} h ${minutes} min left`,\n minutesLeft: (minutes) => `Demo · ${minutes} min left`,\n badge: \"Demo\",\n readOnly: \"You’re looking at sample data. Changes aren’t possible.\",\n sandbox: \"Your own work is deleted when the demo ends.\",\n details: \"Demo details\",\n writeLocked: \"Not possible in the demo.\",\n endedTitle: \"The demo has ended\",\n endedReadOnly: \"Sample data is reset regularly.\",\n endedSandbox: \"Sample data is reset regularly; your own work from the demo is deleted.\",\n restart: \"Start a new demo\",\n};\n\n/** The `demo` namespace, resolved: English, then the provider, then `labels`. The app\n * reads `writeLocked` from here for its `WriteLockProvider`. */\nexport function useDemoLabels(labels?: Partial<DemoLabels>): DemoLabels {\n return useKitLabels(\"demo\", DEFAULT_DEMO_LABELS, labels);\n}\n"],"mappings":";AAAA,SAAS,oBAAoB;AAkDtB,MAAM,sBAAkC;AAAA,EAC7C,UAAU;AAAA,EACV,aAAa,CAAC,YACZ,UACI,kDAAkD,OAAO,UACzD;AAAA,EACN,UAAU;AAAA,EACV,aAAa;AAAA,EACb,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,WAAW,CAAC,OAAO,YAAY,aAAU,KAAK,MAAM,OAAO;AAAA,EAC3D,aAAa,CAAC,YAAY,aAAU,OAAO;AAAA,EAC3C,OAAO;AAAA,EACP,UAAU;AAAA,EACV,SAAS;AAAA,EACT,SAAS;AAAA,EACT,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,cAAc;AAAA,EACd,SAAS;AACX;AAIO,SAAS,cAAc,QAA0C;AACtE,SAAO,aAAa,QAAQ,qBAAqB,MAAM;AACzD;","names":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two demo models (docs/landing-demo-harmonization.md §2.3):
|
|
3
|
+
*
|
|
4
|
+
* - `read-only` (R) — keksdose and kastlan: one pre-filled shared dataset a throwaway
|
|
5
|
+
* demo user may look at but not change;
|
|
6
|
+
* - `sandbox` (S) — Kurvenschmiede: the demo user reads system-owned worked examples and
|
|
7
|
+
* may create or copy work of its own, deleted with the demo account.
|
|
8
|
+
*/
|
|
9
|
+
type DemoModel = "read-only" | "sandbox";
|
|
10
|
+
/** The fields of an `/auth/me` answer {@link isDemoSession} reads — server-kit's
|
|
11
|
+
* `UserResponse.is_demo` (0.5: and `demo_expires_at`), or a client's camel-cased copy. */
|
|
12
|
+
interface DemoSessionUser {
|
|
13
|
+
is_demo?: boolean | null;
|
|
14
|
+
isDemo?: boolean | null;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Whether the signed-in user is a demo (§5, §6.5): server-kit's `is_demo` on
|
|
18
|
+
* `/auth/me`, or a client's `isDemo`. `false` for no user at all.
|
|
19
|
+
*
|
|
20
|
+
* What the client branches on: the demo banner instead of keksdose's preview banner, the
|
|
21
|
+
* header's "Continue the demo", a 401 that ends at `/demo/ended` instead of `/login`, and
|
|
22
|
+
* the crash reporter, which files nothing for a demo:
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* createCrashReporter({ …, suppress: () => isDemoSession(useAuth.getState().user) });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare function isDemoSession(me: DemoSessionUser | null | undefined): boolean;
|
|
29
|
+
|
|
30
|
+
export { type DemoModel, type DemoSessionUser, isDemoSession };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/demo/demo-session.ts"],"sourcesContent":["/**\n * The two demo models (docs/landing-demo-harmonization.md §2.3):\n *\n * - `read-only` (R) — keksdose and kastlan: one pre-filled shared dataset a throwaway\n * demo user may look at but not change;\n * - `sandbox` (S) — Kurvenschmiede: the demo user reads system-owned worked examples and\n * may create or copy work of its own, deleted with the demo account.\n */\nexport type DemoModel = \"read-only\" | \"sandbox\";\n\n/** The fields of an `/auth/me` answer {@link isDemoSession} reads — server-kit's\n * `UserResponse.is_demo` (0.5: and `demo_expires_at`), or a client's camel-cased copy. */\nexport interface DemoSessionUser {\n is_demo?: boolean | null;\n isDemo?: boolean | null;\n}\n\n/**\n * Whether the signed-in user is a demo (§5, §6.5): server-kit's `is_demo` on\n * `/auth/me`, or a client's `isDemo`. `false` for no user at all.\n *\n * What the client branches on: the demo banner instead of keksdose's preview banner, the\n * header's \"Continue the demo\", a 401 that ends at `/demo/ended` instead of `/login`, and\n * the crash reporter, which files nothing for a demo:\n *\n * ```ts\n * createCrashReporter({ …, suppress: () => isDemoSession(useAuth.getState().user) });\n * ```\n */\nexport function isDemoSession(me: DemoSessionUser | null | undefined): boolean {\n return me?.is_demo === true || me?.isDemo === true;\n}\n"],"mappings":";AA6BO,SAAS,cAAc,IAAiD;AAC7E,SAAO,IAAI,YAAY,QAAQ,IAAI,WAAW;AAChD;","names":[]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentPropsWithoutRef } from 'react';
|
|
3
|
+
import { AccessChoice } from '../landing/access.js';
|
|
4
|
+
import { LandingLabels } from '../landing/landing-labels.js';
|
|
5
|
+
import { DemoLabels } from './demo-labels.js';
|
|
6
|
+
|
|
7
|
+
interface DemoStartProps<T> extends Omit<ComponentPropsWithoutRef<"div">, "children"> {
|
|
8
|
+
/**
|
|
9
|
+
* Create the demo: the app's `POST /auth/demo-session {locale}`. Resolve with what it
|
|
10
|
+
* answered (the `TokenResponse`, `refresh_token: null`, `expires_at`); reject with the
|
|
11
|
+
* client's error — the codes are read out of it. Called once per mount.
|
|
12
|
+
*/
|
|
13
|
+
start: () => Promise<T>;
|
|
14
|
+
/** The demo exists: store the session (and, for kastlan, `kastlan.demoSession`) and
|
|
15
|
+
* replace to the app's home. The page keeps saying "Starting the demo…" meanwhile. */
|
|
16
|
+
onStarted: (session: T) => void;
|
|
17
|
+
/** "Request access" beside a refusal. */
|
|
18
|
+
access: AccessChoice;
|
|
19
|
+
/** "Back to the start page". Default `/`. */
|
|
20
|
+
backHref?: string;
|
|
21
|
+
/** `false` adds no `noindex` — for a preview. Default `true`: `/demo` is never indexed
|
|
22
|
+
* (§4.3). */
|
|
23
|
+
noIndex?: boolean;
|
|
24
|
+
labels?: Partial<DemoLabels>;
|
|
25
|
+
/** The access words (`landing` namespace) for this instance. */
|
|
26
|
+
landingLabels?: Partial<LandingLabels>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The `/demo` page's content (docs/landing-demo-harmonization.md §5.2): it starts the
|
|
30
|
+
* demo ONCE — StrictMode's double mount included, keksdose's ref guard — and says
|
|
31
|
+
* "Starting the demo…" until the app has the session and has moved on.
|
|
32
|
+
*
|
|
33
|
+
* A refusal says why, in the visitor's words, and offers "Request access" and "Back to
|
|
34
|
+
* the start page":
|
|
35
|
+
*
|
|
36
|
+
* | code | says |
|
|
37
|
+
* |---|---|
|
|
38
|
+
* | `demo_rate_limited` (429) | "Too many demos from this network. Try again in N min." — N from `Retry-After` |
|
|
39
|
+
* | `demo_capacity` (429) | "The demo is full right now. Try again later." |
|
|
40
|
+
* | `demo_disabled` (404), `demo_not_ready` (503) | "The demo isn't available right now." |
|
|
41
|
+
* | anything else | "The demo could not be started. Please try again." |
|
|
42
|
+
*
|
|
43
|
+
* keksdose fell back to `/register` with a toast; registration is invitation-only now,
|
|
44
|
+
* so the way on is the access mail.
|
|
45
|
+
*
|
|
46
|
+
* Put it in the app's `AuthLayout`. A live demo session never reaches it: the `/demo`
|
|
47
|
+
* route sits in `RedirectIfAuthed` WITHOUT `allowDemo`, which continues the live demo at
|
|
48
|
+
* its resume target instead of starting a second one. A cold start is the kit's
|
|
49
|
+
* `ServerWakeNotice`'s, once the app's watcher counts this POST
|
|
50
|
+
* (`watchReadsAnd(/\/auth\/demo-session\b/)`).
|
|
51
|
+
*/
|
|
52
|
+
declare function DemoStart<T>({ start, onStarted, access, backHref, noIndex, labels: labelsProp, landingLabels, className, ...rest }: DemoStartProps<T>): react.JSX.Element;
|
|
53
|
+
|
|
54
|
+
export { DemoStart, type DemoStartProps };
|