@glimstone/react 4.8.5 → 4.9.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/dist/ListRow.d.ts CHANGED
@@ -5,6 +5,10 @@ export interface ListRowProps extends Omit<HTMLAttributes<HTMLDivElement>, "chil
5
5
  tip?: string | null;
6
6
  /** Sets the name in monospace, for a path. */
7
7
  mono?: boolean;
8
+ /** A quiet line under the name, such as when it was made or where it comes from. */
9
+ meta?: string;
10
+ /** Keeps the buttons in view at rest, for a short list of the person's own things, where each row's buttons are the point. */
11
+ steady?: boolean;
8
12
  /** The glyph at the row's start, which fills with the accent while the row is reached. */
9
13
  tile?: ReactNode;
10
14
  /** What stands at the row's end at rest. */
@@ -13,4 +17,4 @@ export interface ListRowProps extends Omit<HTMLAttributes<HTMLDivElement>, "chil
13
17
  actions?: ReactNode;
14
18
  className?: string;
15
19
  }
16
- export declare function ListRow({ name, tip, mono, tile, badges, actions, className, onClick, onKeyDown, ...rest }: ListRowProps): import("react").JSX.Element;
20
+ export declare function ListRow({ name, tip, mono, meta, steady, tile, badges, actions, className, onClick, onKeyDown, ...rest }: ListRowProps): import("react").JSX.Element;
package/dist/ListRow.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { InfoBubble } from "./InfoBubble.js";
3
3
  const stay = (e) => e.stopPropagation();
4
- export function ListRow({ name, tip, mono, tile, badges, actions, className, onClick, onKeyDown, ...rest }) {
4
+ export function ListRow({ name, tip, mono, meta, steady, tile, badges, actions, className, onClick, onKeyDown, ...rest }) {
5
5
  function keys(e) {
6
6
  onKeyDown?.(e);
7
7
  if (!onClick || e.target !== e.currentTarget || (e.key !== "Enter" && e.key !== " "))
@@ -9,6 +9,7 @@ export function ListRow({ name, tip, mono, tile, badges, actions, className, onC
9
9
  e.preventDefault();
10
10
  e.currentTarget.click();
11
11
  }
12
- const classes = ["glim-list-row", onClick && "glim-list-row--opens", className].filter(Boolean).join(" ");
13
- return (_jsxs("div", { "data-glim": "ListRow", role: "group", "aria-label": name, tabIndex: onClick ? 0 : undefined, ...rest, onClick: onClick, onKeyDown: keys, className: classes, children: [tile && _jsx("span", { className: "glim-list-row-tile", children: tile }), _jsxs("span", { className: mono ? "glim-list-row-name glim-list-row-name--mono" : "glim-list-row-name", children: [_jsx("span", { className: "glim-list-row-title", children: name }), tip && (_jsx("span", { className: "glim-list-row-tip", onClick: stay, children: _jsx(InfoBubble, { tip: tip }) }))] }), badges && _jsx("span", { className: "glim-list-row-badges", children: badges }), actions && (_jsx("span", { className: "glim-list-row-actions", onClick: stay, children: actions }))] }));
12
+ const nameLine = (_jsxs("span", { className: mono ? "glim-list-row-name glim-list-row-name--mono" : "glim-list-row-name", children: [_jsx("span", { className: "glim-list-row-title", children: name }), tip && (_jsx("span", { className: "glim-list-row-tip", onClick: stay, children: _jsx(InfoBubble, { tip: tip }) }))] }));
13
+ const classes = ["glim-list-row", onClick && "glim-list-row--opens", steady && "glim-list-row--steady", className].filter(Boolean).join(" ");
14
+ return (_jsxs("div", { "data-glim": "ListRow", role: "group", "aria-label": name, tabIndex: onClick ? 0 : undefined, ...rest, onClick: onClick, onKeyDown: keys, className: classes, children: [tile && _jsx("span", { className: "glim-list-row-tile", children: tile }), meta ? (_jsxs("span", { className: "glim-list-row-text", children: [nameLine, _jsx("span", { className: "glim-list-row-meta", children: meta })] })) : (nameLine), badges && _jsx("span", { className: "glim-list-row-badges", children: badges }), actions && (_jsx("span", { className: "glim-list-row-actions", onClick: stay, children: actions }))] }));
14
15
  }
@@ -8,6 +8,8 @@ export interface PasswordFieldProps extends Omit<InputHTMLAttributes<HTMLInputEl
8
8
  text?: Partial<PasswordFieldText>;
9
9
  /** Why the value cannot stand, as a line under the field until it is fixed. */
10
10
  error?: string;
11
+ /** A quiet line under the field that only informs, such as a hint about the value. An error takes its place. */
12
+ note?: string;
11
13
  /** Asks for the password again in a second field, which stands once the first holds something. */
12
14
  confirm?: boolean;
13
15
  /** Whether both fields hold the same password, each time that changes. Set password waits for true. */
@@ -16,4 +18,4 @@ export interface PasswordFieldProps extends Omit<InputHTMLAttributes<HTMLInputEl
16
18
  className?: string;
17
19
  ref?: Ref<HTMLInputElement>;
18
20
  }
19
- export declare function PasswordField({ width, eyeAttrs, text, error, confirm, onConfirmedChange, className, ref, disabled, "aria-label": ariaLabel, "aria-describedby": describedBy, ...rest }: PasswordFieldProps): import("react").JSX.Element;
21
+ export declare function PasswordField({ width, eyeAttrs, text, error, note, confirm, onConfirmedChange, className, ref, disabled, "aria-label": ariaLabel, "aria-describedby": describedBy, ...rest }: PasswordFieldProps): import("react").JSX.Element;
@@ -1,11 +1,11 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useId, useState } from "react";
3
- import { fieldErrorView, fieldWidthClass, PASSWORD_FIELD_TEXT, passwordConfirmView } from "@glimstone/core";
3
+ import { fieldErrorView, fieldNoteView, fieldWidthClass, PASSWORD_FIELD_TEXT, passwordConfirmView } from "@glimstone/core";
4
4
  import { FieldError } from "./FieldError.js";
5
5
  import { useFieldName } from "./fieldName.js";
6
6
  import { IconEye, IconEyeOff } from "./glyphs.js";
7
7
  import { IconTipButton } from "./IconTipButton.js";
8
- export function PasswordField({ width, eyeAttrs, text, error, confirm = false, onConfirmedChange, className, ref, disabled, "aria-label": ariaLabel, "aria-describedby": describedBy, ...rest }) {
8
+ export function PasswordField({ width, eyeAttrs, text, error, note, confirm = false, onConfirmedChange, className, ref, disabled, "aria-label": ariaLabel, "aria-describedby": describedBy, ...rest }) {
9
9
  const words = { ...PASSWORD_FIELD_TEXT, ...text };
10
10
  const [shown, setShown] = useState(false);
11
11
  const [repeatShown, setRepeatShown] = useState(false);
@@ -14,7 +14,8 @@ export function PasswordField({ width, eyeAttrs, text, error, confirm = false, o
14
14
  const name = useFieldName(ariaLabel);
15
15
  const own = useId();
16
16
  const id = rest.id ?? own;
17
- const err = fieldErrorView(error, id, describedBy);
17
+ const quiet = fieldNoteView(note, error, id, describedBy);
18
+ const err = fieldErrorView(error, id, quiet.describedBy);
18
19
  const view = passwordConfirmView(rest.value === undefined ? typed : String(rest.value), repeat);
19
20
  if (!view.shown && repeat)
20
21
  setRepeat("");
@@ -22,5 +23,5 @@ export function PasswordField({ width, eyeAttrs, text, error, confirm = false, o
22
23
  const mismatch = fieldErrorView(view.mismatch ? words.mismatch : undefined, repeatId);
23
24
  const confirmed = confirm && view.confirmed;
24
25
  useEffect(() => onConfirmedChange?.(confirmed), [confirmed]);
25
- return (_jsxs(_Fragment, { children: [_jsxs("span", { "data-glim": "PasswordField", className: ["glim-secret", fieldWidthClass(width), className].filter(Boolean).join(" "), onInput: (e) => setTyped(e.target.value), children: [_jsx("input", { autoComplete: confirm ? "new-password" : "current-password", spellCheck: false, ...rest, "aria-label": name, "aria-invalid": err.invalid, "aria-describedby": err.describedBy, ref: ref, disabled: disabled, type: shown ? "text" : "password", className: "glim-input" }), _jsx(IconTipButton, { ...eyeAttrs, tip: shown ? words.hide : words.show, className: "glim-secret-eye", disabled: disabled, onClick: () => setShown(!shown), children: shown ? _jsx(IconEyeOff, {}) : _jsx(IconEye, {}) })] }), err.errorId && _jsx(FieldError, { id: err.errorId, children: error }), confirm && view.shown && (_jsxs("span", { className: "glim-secret-confirm", children: [_jsx("label", { htmlFor: repeatId, className: "glim-secret-confirm-label", children: words.confirm }), _jsxs("span", { className: ["glim-secret-confirm-box", fieldWidthClass(width)].filter(Boolean).join(" "), children: [_jsxs("span", { className: "glim-secret", children: [_jsx("input", { id: repeatId, autoComplete: "new-password", spellCheck: false, value: repeat, onChange: (e) => setRepeat(e.target.value), "aria-invalid": mismatch.invalid, "aria-describedby": mismatch.describedBy, disabled: disabled, type: repeatShown ? "text" : "password", className: "glim-input" }), _jsx(IconTipButton, { tip: repeatShown ? words.hide : words.show, className: "glim-secret-eye", disabled: disabled, onClick: () => setRepeatShown(!repeatShown), children: repeatShown ? _jsx(IconEyeOff, {}) : _jsx(IconEye, {}) })] }), _jsx("span", { "aria-live": "polite", className: "glim-secret-confirm-live", children: mismatch.errorId && _jsx(FieldError, { id: mismatch.errorId, children: words.mismatch }) })] })] }))] }));
26
+ return (_jsxs(_Fragment, { children: [_jsxs("span", { "data-glim": "PasswordField", className: ["glim-secret", fieldWidthClass(width), className].filter(Boolean).join(" "), onInput: (e) => setTyped(e.target.value), children: [_jsx("input", { autoComplete: confirm ? "new-password" : "current-password", spellCheck: false, ...rest, "aria-label": name, "aria-invalid": err.invalid, "aria-describedby": err.describedBy, ref: ref, disabled: disabled, type: shown ? "text" : "password", className: "glim-input" }), _jsx(IconTipButton, { ...eyeAttrs, tip: shown ? words.hide : words.show, className: "glim-secret-eye", disabled: disabled, onClick: () => setShown(!shown), children: shown ? _jsx(IconEyeOff, {}) : _jsx(IconEye, {}) })] }), err.errorId && _jsx(FieldError, { id: err.errorId, children: error }), quiet.noteId && (_jsx("span", { id: quiet.noteId, className: "glim-field-note", children: note })), confirm && view.shown && (_jsxs("span", { className: "glim-secret-confirm", children: [_jsx("label", { htmlFor: repeatId, className: "glim-secret-confirm-label", children: words.confirm }), _jsxs("span", { className: ["glim-secret-confirm-box", fieldWidthClass(width)].filter(Boolean).join(" "), children: [_jsxs("span", { className: "glim-secret", children: [_jsx("input", { id: repeatId, autoComplete: "new-password", spellCheck: false, value: repeat, onChange: (e) => setRepeat(e.target.value), "aria-invalid": mismatch.invalid, "aria-describedby": mismatch.describedBy, disabled: disabled, type: repeatShown ? "text" : "password", className: "glim-input" }), _jsx(IconTipButton, { tip: repeatShown ? words.hide : words.show, className: "glim-secret-eye", disabled: disabled, onClick: () => setRepeatShown(!repeatShown), children: repeatShown ? _jsx(IconEyeOff, {}) : _jsx(IconEye, {}) })] }), _jsx("span", { "aria-live": "polite", className: "glim-secret-confirm-live", children: mismatch.errorId && _jsx(FieldError, { id: mismatch.errorId, children: words.mismatch }) })] })] }))] }));
26
27
  }
package/dist/PathField.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useEffect, useRef, useState } from "react";
2
+ import { useLayoutEffect, useRef, useState } from "react";
3
3
  import { fieldWidthClass, PATH_ROOM_PX } from "@glimstone/core";
4
4
  import { Button } from "./Button.js";
5
5
  import { useFieldName } from "./fieldName.js";
@@ -9,9 +9,12 @@ export function PathField({ value, onChange, pick, onPicked, label, width, text
9
9
  const own = useRef(null);
10
10
  const box = useRef(null);
11
11
  const [tight, setTight] = useState(false);
12
- useEffect(() => {
12
+ // Measured before the first paint as well, so a narrow field never shows its button wide for a frame.
13
+ useLayoutEffect(() => {
14
+ const el = box.current;
15
+ setTight(el.getBoundingClientRect().width < PATH_ROOM_PX);
13
16
  const watcher = new ResizeObserver(([entry]) => setTight(entry.contentRect.width < PATH_ROOM_PX));
14
- watcher.observe(box.current);
17
+ watcher.observe(el);
15
18
  return () => watcher.disconnect();
16
19
  }, []);
17
20
  async function ask() {
@@ -1,6 +1,6 @@
1
1
  import { type ReactNode } from "react";
2
- import { type SignInHandlers, type SignInText, type SignInLabelKeys } from "@glimstone/core";
3
- export type { SignInLabelKeys } from "@glimstone/core";
2
+ import { type SignInCardService, type SignInHandlers, type SignInLabelKeys, type SignInText } from "@glimstone/core";
3
+ export type { SignInCardService, SignInLabelKeys } from "@glimstone/core";
4
4
  export type { ResetAnswer, SignInAnswer, SignInText } from "@glimstone/core";
5
5
  export interface SignInCardProps extends SignInHandlers {
6
6
  /** The app's logo, as an address or as an inline `<svg>` with a viewBox. It stands 7.5rem tall above the name, as wide as its shape asks. */
@@ -8,14 +8,22 @@ export interface SignInCardProps extends SignInHandlers {
8
8
  /** The page's heading. */
9
9
  appName: string;
10
10
  text: SignInText;
11
- /** Offers Sign in with a passkey. Pass it only where a passkey can answer on this address. */
11
+ /** Draws a passkey button, for a server without the browser's offer in the password field. `onPasskeyOffer` needs none. */
12
12
  passkey?: boolean;
13
13
  /** Offers Forgot password? and the reset form. */
14
14
  reset?: boolean;
15
- /** The shortest new password the reset form takes, as the server says. */
15
+ /** Asks for the account's name in the reset form, in an app with several accounts (the kit's options say `owner: false`). */
16
+ resetName?: boolean;
17
+ /** The length, as the server says, under which the reset form suggests a longer password. It never refuses a shorter one. */
16
18
  minPassword?: number;
17
19
  /** One line at the top of the sign-in form, such as "You are signed out". */
18
20
  note?: string;
21
+ /** A refusal from outside the card, such as a sign-in service that sent the person back, said above Sign in until the card's next try. */
22
+ error?: string;
23
+ /** The sign-in service whose button stands under Sign in, the one second way in the page offers. */
24
+ service?: SignInCardService;
25
+ /** Leaves for the sign-in service. */
26
+ onService?: () => void;
19
27
  /** The app's own fields, above the password. */
20
28
  fields?: ReactNode;
21
29
  /** The app's own buttons, under Sign in and the passkey. */
@@ -23,7 +31,7 @@ export interface SignInCardProps extends SignInHandlers {
23
31
  /** A step the app runs itself, in place of the card's forms. */
24
32
  step?: ReactNode;
25
33
  labelKeys?: Partial<SignInLabelKeys>;
26
- /** The start of the fields' ids: `-password`, `-code`, `-reset-code`, `-new` and `-confirm` follow it. */
34
+ /** The start of the fields' ids: `-password`, `-code`, `-reset-code`, `-reset-name`, `-new` and `-confirm` follow it. */
27
35
  idPrefix?: string;
28
36
  /** Puts the focus in the first empty field when the card opens. */
29
37
  autoFocus?: boolean;
@@ -37,4 +45,4 @@ export declare function SignInField({ label, htmlFor, hint, hidden, children }:
37
45
  hidden?: boolean;
38
46
  children: ReactNode;
39
47
  }): import("react").JSX.Element;
40
- export declare function SignInCard({ logo, appName, text, passkey, reset, minPassword, note, fields, actions, step, labelKeys, idPrefix, autoFocus, className, ...handlers }: SignInCardProps): import("react").JSX.Element;
48
+ export declare function SignInCard({ logo, appName, text, passkey, reset, resetName, minPassword, note, error: outside, service, onService, fields, actions, step, labelKeys, idPrefix, autoFocus, className, ...handlers }: SignInCardProps): import("react").JSX.Element;
@@ -1,9 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useId, useRef, useState, useSyncExternalStore } from "react";
3
- import { createSignInFlow, focusFirstField, labelInside, resetBlocked, showRefusal, signInBlocked, signInStage } from "@glimstone/core";
3
+ import { createSignInFlow, focusFirstField, labelInside, passkeyOfferKey, resetBlocked, signInShortHint, showRefusal, signInBlocked, signInStage, } from "@glimstone/core";
4
4
  import { Button } from "./Button.js";
5
+ import { glyphFor } from "./glyphs.js";
5
6
  import { InfoBubble } from "./InfoBubble.js";
6
7
  import { PasswordField } from "./PasswordField.js";
8
+ import { BrandMark } from "./ReadmeButton.js";
7
9
  import { TextField } from "./TextField.js";
8
10
  // The way into an app with a login ("The sign-in card" in the design
9
11
  // language). The flow lives in the core; the app answers each step through a
@@ -14,6 +16,7 @@ const LABEL_KEYS = {
14
16
  forgot: "forgotPassword",
15
17
  back: "back",
16
18
  setPassword: "setPassword",
19
+ service: "signIn",
17
20
  };
18
21
  // A field on the sign-in card. Its label stands inside the field until the
19
22
  // first key, and above it when the field brings a placeholder or a hint.
@@ -26,9 +29,9 @@ export function SignInField({ label, htmlFor, hint, hidden, children }) {
26
29
  }, [htmlFor, label, hint]);
27
30
  return (_jsxs("div", { "data-glim": "SignInField", className: "glim-signin-field", hidden: hidden, children: [_jsxs("label", { htmlFor: htmlFor, className: inside ? "glim-sr-only" : "glim-signin-label", children: [label, hint && _jsx(InfoBubble, { tip: hint })] }), children] }));
28
31
  }
29
- export function SignInCard({ logo, appName, text, passkey = false, reset = false, minPassword = 12, note, fields, actions, step, labelKeys, idPrefix, autoFocus = true, className, ...handlers }) {
30
- const latest = useRef({ ...handlers, text, minPassword });
31
- latest.current = { ...handlers, text, minPassword };
32
+ export function SignInCard({ logo, appName, text, passkey = false, reset = false, resetName = false, minPassword = 12, note, error: outside, service, onService, fields, actions, step, labelKeys, idPrefix, autoFocus = true, className, ...handlers }) {
33
+ const latest = useRef({ ...handlers, text, minPassword, resetName });
34
+ latest.current = { ...handlers, text, minPassword, resetName };
32
35
  const [flow] = useState(() => createSignInFlow(() => latest.current));
33
36
  const s = useSyncExternalStore(flow.subscribe, flow.state, flow.state);
34
37
  const ownId = useId();
@@ -45,14 +48,23 @@ export function SignInCard({ logo, appName, text, passkey = false, reset = false
45
48
  }, [stage]);
46
49
  const refusal = s.refusal;
47
50
  useEffect(() => (refusal ? showRefusal(card.current, refusal) : undefined), [refusal?.count]);
51
+ const offers = !!handlers.onPasskeyOffer && !step;
52
+ const offer = offers ? passkeyOfferKey(s) : null;
53
+ useEffect(() => {
54
+ if (!offer)
55
+ return;
56
+ const stop = new AbortController();
57
+ void flow.offer(stop.signal);
58
+ return () => stop.abort();
59
+ }, [offer]);
48
60
  const submit = (e) => {
49
61
  e.preventDefault();
50
62
  void flow.submit();
51
63
  };
52
- const error = s.error && (_jsx("p", { className: "glim-signin-error", role: "alert", children: s.error }));
64
+ const said = (line) => line && (_jsx("p", { className: "glim-signin-error", role: "alert", children: line }));
53
65
  const back = _jsx(Button, { label: text.back, labelKey: keys.back, tone: "subtle", "data-signin": "back", disabled: !!s.busy, onClick: flow.back });
54
66
  return (_jsx("div", { "data-glim": "SignInCard", className: ["glim-signin", className].filter(Boolean).join(" "), children: _jsxs("div", { ref: card, className: "glim-card glim-signin-card", children: [_jsxs("div", { className: "glim-signin-head", children: [logo && (_jsx("span", { className: "glim-signin-logo", "aria-hidden": "true", children: typeof logo === "string" ? _jsx("img", { src: logo, alt: "", draggable: false }) : logo })), _jsx("h1", { className: "glim-signin-name", children: appName })] }), step ??
55
- (s.view === "reset" ? (_jsxs("form", { className: "glim-signin-form", noValidate: true, onSubmit: submit, children: [_jsx(SignInField, { label: text.resetCode, htmlFor: id("reset-code"), hint: text.resetCodeTip, children: _jsx(TextField, { id: id("reset-code"), "data-signin-field": "resetCode", className: "glim-signin-log-code", value: s.resetCode, onChange: (e) => flow.set("resetCode", e.target.value), autoComplete: "one-time-code", autoCapitalize: "characters", spellCheck: false, placeholder: "XXXX-XXXX-XXXX" }) }), _jsx(SignInField, { label: text.newPassword, htmlFor: id("new"), children: _jsx(PasswordField, { id: id("new"), "data-signin-field": "newPassword", value: s.newPassword, onChange: (e) => flow.set("newPassword", e.target.value), autoComplete: "new-password", text: eye }) }), _jsx(SignInField, { label: text.confirmPassword, htmlFor: id("confirm"), children: _jsx(PasswordField, { id: id("confirm"), "data-signin-field": "confirm", value: s.confirm, onChange: (e) => flow.set("confirm", e.target.value), autoComplete: "new-password", text: eye }) }), error, _jsx(Button, { label: text.setPassword, labelKey: keys.setPassword, tone: "accent", type: "submit", "data-signin": "set-password", disabled: resetBlocked(s), busy: s.busy === "setPassword", title: s.busy === "setPassword" ? text.saving : undefined }), back] })) : (_jsxs("form", { className: "glim-signin-form", noValidate: true, onSubmit: submit, children: [note && (_jsx("p", { className: "glim-signin-note", role: "status", children: note })), !s.viaPasskey && fields, _jsx(SignInField, { label: text.password, htmlFor: id("password"), hidden: s.viaPasskey, children: _jsx(PasswordField, { id: id("password"), "data-signin-field": "password", value: s.password, onChange: (e) => flow.set("password", e.target.value), autoComplete: "current-password", text: eye }) }), s.needCode && (_jsxs("div", { className: "glim-signin-field", children: [_jsx("label", { htmlFor: id("code"), className: "glim-signin-label", children: text.code }), _jsx(TextField, { id: id("code"), "data-signin-field": "code", className: "glim-signin-code", value: s.code, onChange: (e) => flow.set("code", e.target.value), inputMode: "numeric", autoComplete: "one-time-code", spellCheck: false, placeholder: "000000" }), _jsx("p", { className: "glim-signin-hint", children: text.codeHint })] })), error, _jsx(Button, { label: text.signIn, labelKey: keys.signIn, tone: "accent", type: "submit", "data-signin": "submit", disabled: signInBlocked(s), busy: s.busy === "signIn", title: s.busy === "signIn" ? text.signingIn : undefined }), !s.needCode && passkey && (_jsx(Button, { label: text.passkey, labelKey: keys.passkey, "data-signin": "passkey", disabled: !!s.busy, busy: s.busy === "passkey", onClick: () => void flow.passkey() })), !s.needCode && actions, s.needCode
67
+ (s.view === "reset" ? (_jsxs("form", { className: "glim-signin-form", noValidate: true, onSubmit: submit, children: [_jsx(SignInField, { label: text.resetCode, htmlFor: id("reset-code"), hint: text.resetCodeTip, children: _jsx(TextField, { id: id("reset-code"), "data-signin-field": "resetCode", className: "glim-signin-log-code", value: s.resetCode, onChange: (e) => flow.set("resetCode", e.target.value), autoComplete: "one-time-code", autoCapitalize: "characters", spellCheck: false, placeholder: "XXXX-XXXX-XXXX" }) }), resetName && (_jsx(SignInField, { label: text.name, htmlFor: id("reset-name"), children: _jsx(TextField, { id: id("reset-name"), "data-signin-field": "resetName", value: s.resetName, onChange: (e) => flow.set("resetName", e.target.value), autoComplete: "username", autoCapitalize: "none", spellCheck: false }) })), _jsx(SignInField, { label: text.newPassword, htmlFor: id("new"), children: _jsx(PasswordField, { id: id("new"), "data-signin-field": "newPassword", value: s.newPassword, onChange: (e) => flow.set("newPassword", e.target.value), autoComplete: "new-password", text: eye, note: signInShortHint(text.shortHint, s.newPassword, minPassword) }) }), _jsx(SignInField, { label: text.confirmPassword, htmlFor: id("confirm"), children: _jsx(PasswordField, { id: id("confirm"), "data-signin-field": "confirm", value: s.confirm, onChange: (e) => flow.set("confirm", e.target.value), autoComplete: "new-password", text: eye }) }), said(s.error), _jsx(Button, { label: text.setPassword, labelKey: keys.setPassword, tone: "accent", type: "submit", "data-signin": "set-password", disabled: resetBlocked(s, resetName), busy: s.busy === "setPassword", title: s.busy === "setPassword" ? text.saving : undefined }), back] })) : (_jsxs("form", { className: "glim-signin-form", noValidate: true, onSubmit: submit, children: [note && (_jsx("p", { className: "glim-signin-note", role: "status", children: note })), !s.viaPasskey && fields, _jsx(SignInField, { label: text.password, htmlFor: id("password"), hidden: s.viaPasskey, children: _jsx(PasswordField, { id: id("password"), "data-signin-field": "password", value: s.password, onChange: (e) => flow.set("password", e.target.value), autoComplete: offers ? "current-password webauthn" : "current-password", text: eye }) }), s.needCode && (_jsxs("div", { className: "glim-signin-field", children: [_jsx("label", { htmlFor: id("code"), className: "glim-signin-label", children: text.code }), _jsx(TextField, { id: id("code"), "data-signin-field": "code", className: "glim-signin-code", value: s.code, onChange: (e) => flow.set("code", e.target.value), inputMode: "numeric", autoComplete: "one-time-code", spellCheck: false, placeholder: "000000" }), _jsx("p", { className: "glim-signin-hint", children: text.codeHint })] })), said(s.error ?? (s.tried ? null : outside)), _jsx(Button, { label: text.signIn, labelKey: keys.signIn, tone: "accent", type: "submit", "data-signin": "submit", disabled: signInBlocked(s), busy: s.busy === "signIn", title: s.busy === "signIn" ? text.signingIn : undefined }), !s.needCode && passkey && (_jsx(Button, { label: text.passkey, labelKey: keys.passkey, "data-signin": "passkey", disabled: !!s.busy, busy: s.busy === "passkey", onClick: () => void flow.passkey() })), !s.needCode && service && (_jsx(Button, { label: service.name, labelKey: null, glyph: service.mark ? _jsx(BrandMark, { svg: service.mark.svg }) : glyphFor(keys.service), "data-signin": "service", disabled: !!s.busy, onClick: onService })), !s.needCode && actions, s.needCode
56
68
  ? back
57
- : reset && (_jsx(Button, { label: text.forgot, labelKey: keys.forgot, tone: "subtle", "data-signin": "forgot", disabled: !!s.busy, busy: s.busy === "askCode", onClick: () => void flow.forgot() }))] })))] }) }));
69
+ : reset && (_jsx("button", { type: "button", className: "glim-signin-forgot", "data-signin": "forgot", disabled: !!s.busy, "aria-busy": s.busy === "askCode" || undefined, onClick: () => void flow.forgot(), children: text.forgot }))] })))] }) }));
58
70
  }
@@ -0,0 +1,7 @@
1
+ import { type SignInApi, type SignInReauthText } from "@glimstone/core";
2
+ export type { SignInReauthText } from "@glimstone/core";
3
+ export interface SignInReauthWindowProps {
4
+ api: SignInApi;
5
+ text: SignInReauthText;
6
+ }
7
+ export declare function SignInReauthWindow({ api, text }: SignInReauthWindowProps): import("react").JSX.Element | null;
@@ -0,0 +1,37 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useSyncExternalStore } from "react";
3
+ import { shake, signInReauthError } from "@glimstone/core";
4
+ import { FieldRow } from "./FieldRow.js";
5
+ import { PasswordField } from "./PasswordField.js";
6
+ import { Window } from "./Window.js";
7
+ export function SignInReauthWindow({ api, text }) {
8
+ const r = api.reauth;
9
+ const s = useSyncExternalStore(r.subscribe, r.state, r.state);
10
+ useEffect(() => {
11
+ if (s.refused === 0)
12
+ return;
13
+ const button = document.querySelector('[data-signin-reauth="confirm"]');
14
+ return button ? shake(button) : undefined;
15
+ }, [s.refused]);
16
+ if (!s.asking)
17
+ return null;
18
+ return (_jsx(Window, { "data-glim": "SignInReauthWindow", title: text.title, text: { cancel: text.cancel, close: text.close }, closeOnBackdrop: false, onClose: r.cancel, actions: [
19
+ {
20
+ label: text.confirm,
21
+ labelKey: "confirm",
22
+ primary: true,
23
+ busy: s.busy,
24
+ disabled: s.password === "",
25
+ attrs: { "data-signin-reauth": "confirm" },
26
+ onClick: () => {
27
+ void r.submit();
28
+ return false;
29
+ },
30
+ },
31
+ ], children: _jsxs("div", { className: "glim-signin-tile-body", children: [_jsx("p", { className: "glim-signin-tile-text", children: text.text }), _jsx(FieldRow, { label: text.password, children: _jsx(PasswordField, { autoComplete: "current-password", value: s.password, onChange: (e) => r.set(e.target.value), onKeyDown: (e) => {
32
+ if (e.key !== "Enter")
33
+ return;
34
+ e.preventDefault();
35
+ void r.submit();
36
+ }, text: { show: text.show, hide: text.hide }, error: signInReauthError(text, s.error) }) })] }) }));
37
+ }
@@ -0,0 +1,28 @@
1
+ import { type Catalog, type SignInApi, type SignInTileCard, type SignInTileLabelKeys, type SignInTileText, type ToastSeverity } from "@glimstone/core";
2
+ export type { SignInTileCard, SignInTileLabelKeys, SignInTileText } from "@glimstone/core";
3
+ export interface SignInTileProps {
4
+ api: SignInApi;
5
+ text: SignInTileText;
6
+ /** The interface language, for counts, lists and dates. */
7
+ lang: string;
8
+ /** The identity catalog, `IDENTITY_PROVIDERS`, or the part of it the app offers. */
9
+ providers: Catalog;
10
+ /** The cards to draw, in the tile's own order. A card the account may not see stays out. */
11
+ cards?: readonly SignInTileCard[];
12
+ /** The scopes a new token can take, the narrowest first, as the app's kit knows them. */
13
+ scopes?: string[];
14
+ /** Puts what a change did, or why it failed, into the app's toasts. */
15
+ notify?: (message: string, severity: ToastSeverity) => void;
16
+ /** The path a test sign-in comes back to, where the tile stands. */
17
+ returnTo?: string;
18
+ /** The code a sign-in service sent back, from `takeSignInCode()`. */
19
+ arrived?: string | null;
20
+ /** Leaves the page for a test sign-in. Without it the browser goes there. */
21
+ onLeave?: (url: string) => void;
22
+ /** Formats a date the way the app writes them. */
23
+ time?: (iso: string) => string;
24
+ /** The rainbow position the first card takes. */
25
+ hueStart?: number;
26
+ labelKeys?: Partial<SignInTileLabelKeys>;
27
+ }
28
+ export declare function SignInTile(props: SignInTileProps): import("react").JSX.Element;
@@ -0,0 +1,234 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState, useSyncExternalStore } from "react";
3
+ import { accountFacts, connectionTestFace, createSignInTileFlow, fill, passkeyFacts, passwordGoes, plural, qrCode, removalQuestion, sessionFacts, showTileRefusal, SIGN_IN_TILE_CARDS, SIGN_IN_TILE_KEYS, SIGN_IN_TOKEN_LIVES, signInDevice, signInRedirectAddress, signInScopeItems, signInServiceActions, signInServiceBadge, signInServiceLabel, signInRoleItems, signInServiceName, signInServicePicker, signInServiceQuiet, signInServiceStatus, signInTestLabel, signInTileCards, signInWhen, signInCardNotice, signInShortHint, signInPasswordElsewhere, tokenFacts, } from "@glimstone/core";
4
+ import { Accordion } from "./Accordion.js";
5
+ import { Badge } from "./Badge.js";
6
+ import { Button } from "./Button.js";
7
+ import { Card } from "./Card.js";
8
+ import { CopyField } from "./CopyField.js";
9
+ import { EmptyState } from "./EmptyState.js";
10
+ import { FieldRow } from "./FieldRow.js";
11
+ import { FieldRowGroup } from "./FieldRowGroup.js";
12
+ import { GlyphTile } from "./GlyphTile.js";
13
+ import { glyphFor, IconCancel, IconCheck, IconClose, IconPencil, IconTrash } from "./glyphs.js";
14
+ import { BrandMark } from "./ReadmeButton.js";
15
+ import { ListRow } from "./ListRow.js";
16
+ import { PasswordField } from "./PasswordField.js";
17
+ import { PickerWindow } from "./PickerWindow.js";
18
+ import { Selector } from "./Selector.js";
19
+ import { TextField } from "./TextField.js";
20
+ import { Toggle } from "./Toggle.js";
21
+ import { UnavailableNotice } from "./UnavailableNotice.js";
22
+ import { useConfirm } from "./useConfirm.js";
23
+ import { Window } from "./Window.js";
24
+ const enter = (run) => (e) => {
25
+ if (e.key === "Enter") {
26
+ e.preventDefault();
27
+ run();
28
+ }
29
+ };
30
+ export function SignInTile(props) {
31
+ const { text, lang, providers, cards = SIGN_IN_TILE_CARDS, scopes = ["read", "all"], arrived, time, hueStart = 0 } = props;
32
+ const latest = useRef(props);
33
+ latest.current = props;
34
+ const [flow] = useState(() => createSignInTileFlow(() => ({ ...latest.current, cards: latest.current.cards ?? SIGN_IN_TILE_CARDS, scopes: latest.current.scopes ?? ["read", "all"] })));
35
+ const s = useSyncExternalStore(flow.subscribe, flow.state, flow.state);
36
+ useEffect(() => flow.start(), [flow]);
37
+ useEffect(() => {
38
+ if (arrived)
39
+ flow.arrive(arrived);
40
+ }, [arrived]);
41
+ useEffect(() => showTileRefusal(s.refusal), [s.refusal?.count]);
42
+ const { confirm, confirmDialog } = useConfirm({ title: text.confirm, cancel: text.cancel, confirm: text.confirm });
43
+ const ctx = {
44
+ s,
45
+ flow,
46
+ text,
47
+ lang,
48
+ scopes,
49
+ keys: { ...SIGN_IN_TILE_KEYS, ...props.labelKeys },
50
+ when: time ?? signInWhen(lang),
51
+ eye: { show: text.show, hide: text.hide, confirm: text.confirmPassword, mismatch: text.mismatch },
52
+ err: (field) => (s.invalid?.field === field ? s.invalid.message : undefined),
53
+ ask: (what, id, name) => {
54
+ const q = removalQuestion(text, what, name);
55
+ void confirm(q.message, { confirmLabel: q.confirm, confirmLabelKey: ctx.keys.remove }).then((yes) => {
56
+ if (yes)
57
+ void flow.remove(what, id);
58
+ });
59
+ },
60
+ };
61
+ return (_jsxs("div", { "data-glim": "SignInTile", className: "glim-signin-tile", children: [signInTileCards(s, cards).map((c, i) => {
62
+ const hue = hueStart + i;
63
+ if (c === "password")
64
+ return _jsx(PasswordCard, { ctx: ctx, hue: hue }, c);
65
+ if (c === "askPassword")
66
+ return _jsx(AskPasswordCard, { ctx: ctx, hue: hue }, c);
67
+ if (c === "twoFactor")
68
+ return _jsx(TwoFactorCard, { ctx: ctx, hue: hue }, c);
69
+ if (c === "passkeys")
70
+ return _jsx(PasskeysCard, { ctx: ctx, hue: hue }, c);
71
+ if (c === "sessions")
72
+ return _jsx(SessionsCard, { ctx: ctx, hue: hue }, c);
73
+ if (c === "tokens")
74
+ return _jsx(TokensCard, { ctx: ctx, hue: hue }, c);
75
+ if (c === "services")
76
+ return _jsx(ServicesCard, { ctx: ctx, hue: hue, providers: providers }, c);
77
+ return _jsx(AccountsCard, { ctx: ctx, hue: hue }, c);
78
+ }), _jsx(TileWindow, { ctx: ctx, api: props.api, providers: providers }), confirmDialog] }));
79
+ }
80
+ function Notice({ notice }) {
81
+ return _jsx(UnavailableNotice, { title: notice.title, reason: notice.reason });
82
+ }
83
+ function PasswordCard({ ctx, hue }) {
84
+ const { s, flow, text, keys, eye, err } = ctx;
85
+ const t = text.password;
86
+ const had = !!s.me?.password;
87
+ const open = s.me?.via === "open";
88
+ const elsewhere = signInPasswordElsewhere(text, s);
89
+ return (_jsx(Card, { title: t.title, hint: open ? t.openHint : fill(t.hint, { min: s.offer?.minPassword ?? 12 }), hueIndex: hue, "data-signin-card": "password", children: elsewhere ? (_jsx("p", { className: "glim-signin-tile-text", children: elsewhere })) : (_jsxs("div", { className: "glim-signin-tile-body", children: [_jsx(FieldRow, { label: t.state, value: had ? t.set : t.none, tone: had ? undefined : "warn" }), s.editing && (_jsxs(FieldRowGroup, { children: [had && (_jsx(FieldRow, { label: t.current, children: _jsx(PasswordField, { autoComplete: "current-password", value: s.draft.current, onChange: (e) => flow.set("current", e.target.value), text: eye, error: err("current") }) })), _jsx(FieldRow, { label: t.next, children: _jsx(PasswordField, { confirm: true, value: s.draft.next, onChange: (e) => flow.set("next", e.target.value), onConfirmedChange: flow.setConfirmed, text: eye, error: err("next"), note: signInShortHint(t.shortHint, s.draft.next, s.offer?.minPassword ?? 12) }) })] })), _jsx("div", { className: "glim-signin-tile-foot", children: s.editing ? (_jsxs(_Fragment, { children: [_jsx(Button, { label: text.cancel, labelKey: "common.cancel", glyph: _jsx(IconCancel, {}), onClick: flow.cancelPassword }), _jsx(Button, { label: t.save, labelKey: keys.savePassword, tone: "accent", busy: s.busy === "save-password", disabled: !s.confirmed || (had && s.draft.current === ""), "data-signin-tile": "save-password", onClick: () => void flow.savePassword() })] })) : (_jsxs(_Fragment, { children: [had && _jsx(Button, { label: t.remove, labelKey: keys.removePassword, "data-signin-tile": "ask-remove-password", onClick: flow.askRemovePassword }), _jsx(Button, { label: had ? t.change : t.add, labelKey: had ? keys.change : keys.setPassword, "data-signin-tile": "edit-password", onClick: flow.editPassword })] })) })] })) }));
90
+ }
91
+ function AskPasswordCard({ ctx, hue }) {
92
+ const { s, flow, text } = ctx;
93
+ const t = text.askPassword;
94
+ const notice = signInCardNotice(text, s, "askPassword");
95
+ return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "askPassword", children: notice ? (_jsx(Notice, { notice: notice })) : (_jsx(FieldRow, { label: t.label, hint: t.when, children: _jsx(Toggle, { checked: !!s.settings?.askPassword, onChange: (on) => void flow.setAskPassword(on), "data-signin-tile": "ask-password" }) })) }));
96
+ }
97
+ function TwoFactorCard({ ctx, hue }) {
98
+ const { s, flow, text, lang, keys } = ctx;
99
+ const t = text.twoFactor;
100
+ const notice = signInCardNotice(text, s, "twoFactor");
101
+ const on = !!s.me?.twoFactor;
102
+ return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "twoFactor", children: notice ? (_jsx(Notice, { notice: notice })) : (_jsxs("div", { className: "glim-signin-tile-body", children: [_jsxs(FieldRowGroup, { children: [_jsx(FieldRow, { label: t.state, value: on ? t.on : t.off, tone: on ? "ok" : undefined }), on && _jsx(FieldRow, { label: t.codesLeft, value: plural(lang, t.codesLeftValue, s.me?.recoveryLeft ?? 0) })] }), _jsx("div", { className: "glim-signin-tile-foot", children: on ? (_jsxs(_Fragment, { children: [_jsx(Button, { label: t.newCodes, labelKey: keys.newCodes, busy: s.busy === "two-factor-codes", "data-signin-tile": "two-factor-codes", onClick: () => void flow.newCodes() }), _jsx(Button, { label: t.turnOff, labelKey: keys.turnOff, "data-signin-tile": "ask-two-factor-off", onClick: flow.askTwoFactorOff })] })) : (_jsx(Button, { label: t.setUp, labelKey: keys.setUp, busy: s.busy === "two-factor-set-up", "data-signin-tile": "two-factor-set-up", onClick: () => void flow.setUpTwoFactor() })) })] })) }));
103
+ }
104
+ function PasskeysCard({ ctx, hue }) {
105
+ const { s, flow, text, keys, when, ask } = ctx;
106
+ const t = text.passkeys;
107
+ const notice = signInCardNotice(text, s, "passkeys");
108
+ const here = s.passkeysHere;
109
+ return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "passkeys", children: notice ? (_jsx(Notice, { notice: notice })) : (_jsxs("div", { className: "glim-signin-tile-body", children: [!here && _jsx(UnavailableNotice, { title: t.unavailableTitle, reason: t.unavailable }), s.passkeys.length > 0 ? (_jsx("div", { className: "glim-list glim-signin-tile-rows", children: s.passkeys.map((p) => (_jsx(ListRow, { steady: true, name: p.name, tile: _jsx(GlyphTile, { glyph: glyphFor(keys.passkey) }), meta: passkeyFacts(text, p, when).added, tip: passkeyFacts(text, p, when).more, actions: _jsxs(_Fragment, { children: [_jsx(Button, { compact: true, tone: "subtle", label: t.rename, labelKey: keys.rename, glyph: _jsx(IconPencil, {}), "data-signin-tile": `passkey-rename-${p.id}`, onClick: () => flow.askRenamePasskey(p.id) }), _jsx(Button, { compact: true, tone: "subtle", label: text.remove, labelKey: keys.remove, glyph: _jsx(IconTrash, {}), "data-signin-tile": `remove-passkey-${p.id}`, onClick: () => ask("passkey", p.id, p.name) })] }) }, p.id))) })) : (here && _jsx(EmptyState, { nested: true, glyph: glyphFor(keys.passkey), title: t.none, hint: t.noneHint })), here && (_jsx("div", { className: "glim-signin-tile-foot", children: _jsx(Button, { label: t.add, labelKey: keys.add, "data-signin-tile": "passkey-ask-add", onClick: () => flow.askAddPasskey() }) }))] })) }));
110
+ }
111
+ function SessionsCard({ ctx, hue }) {
112
+ const { s, flow, text, keys, when } = ctx;
113
+ const t = text.sessions;
114
+ const others = s.sessions.some((x) => !x.current);
115
+ const notice = signInCardNotice(text, s, "sessions");
116
+ if (notice) {
117
+ return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "sessions", children: _jsx(Notice, { notice: notice }) }));
118
+ }
119
+ return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "sessions", children: _jsxs("div", { className: "glim-signin-tile-body", children: [_jsx("div", { className: "glim-list glim-signin-tile-rows", children: s.sessions.map((x) => {
120
+ const device = signInDevice(x.agent, t);
121
+ return (_jsx(ListRow, { steady: true, name: device.name, tile: _jsx(GlyphTile, { glyph: glyphFor(device.phone ? keys.phone : keys.laptop) }), meta: sessionFacts(text, x, s.serviceLabels, when).join(" · "), badges: x.current && _jsx(Badge, { size: "small", tone: "active", children: t.current }), actions: !x.current && (_jsx(Button, { compact: true, tone: "subtle", label: t.end, labelKey: keys.end, busy: s.busy === `session-end-${x.id}`, "data-signin-tile": `session-end-${x.id}`, onClick: () => void flow.endSession(x.id) })) }, x.id));
122
+ }) }), others && (_jsx("div", { className: "glim-signin-tile-foot", children: _jsx(Button, { label: t.endOthers, labelKey: keys.endOthers, busy: s.busy === "sessions-end-others", "data-signin-tile": "sessions-end-others", onClick: () => void flow.endOtherSessions() }) }))] }) }));
123
+ }
124
+ function TokensCard({ ctx, hue }) {
125
+ const { s, flow, text, keys, when, ask } = ctx;
126
+ const t = text.tokens;
127
+ const notice = signInCardNotice(text, s, "tokens");
128
+ return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "tokens", children: notice ? (_jsx(Notice, { notice: notice })) : (_jsxs("div", { className: "glim-signin-tile-body", children: [s.tokens.length > 0 ? (_jsx("div", { className: "glim-list glim-signin-tile-rows", children: s.tokens.map((k) => (_jsx(ListRow, { steady: true, name: k.name, tile: _jsx(GlyphTile, { glyph: glyphFor(keys.token) }), meta: tokenFacts(text, k, when).join(" · "), badges: k.scopes.length > 0 &&
129
+ k.scopes.map((scope) => (_jsx(Badge, { size: "small", children: t.scopes[scope] ?? scope }, scope))), actions: _jsx(Button, { compact: true, tone: "subtle", label: t.revoke, labelKey: keys.revoke, "data-signin-tile": `remove-token-${k.id}`, onClick: () => ask("token", k.id, k.name) }) }, k.id))) })) : (_jsx(EmptyState, { nested: true, glyph: glyphFor(keys.token), title: t.none, hint: t.noneHint })), _jsx("div", { className: "glim-signin-tile-foot", children: _jsx(Button, { label: t.create, labelKey: keys.createToken, "data-signin-tile": "token-ask", onClick: flow.askToken }) })] })) }));
130
+ }
131
+ function ServicesCard({ ctx, hue, providers }) {
132
+ const { s, flow, text, keys, when, ask } = ctx;
133
+ const t = text.services;
134
+ const notice = signInCardNotice(text, s, "services");
135
+ return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "services", children: notice ? (_jsx(Notice, { notice: notice })) : (_jsxs("div", { className: "glim-signin-tile-body", children: [(s.services?.length ?? 0) > 0 && (_jsx("div", { className: "glim-list glim-signin-tile-rows", children: (s.services ?? []).map((x) => {
136
+ const badge = signInServiceBadge(text, x);
137
+ const label = signInServiceLabel(x, providers, text);
138
+ const face = connectionTestFace(s.rowTests[x.id]);
139
+ return (_jsx(ListRow, { steady: true, name: label.name, tile: _jsx(GlyphTile, { glyph: label.mark ? _jsx(BrandMark, { svg: label.mark.svg }) : glyphFor(keys.service) }), meta: signInServiceStatus(text, x, when), badges: _jsx(Badge, { size: "small", tone: badge.tone, children: badge.label }), "data-signin-service": x.provider, actions: _jsxs(_Fragment, { children: [!x.fromConfig && (_jsx(Toggle, { checked: x.on, label: t.show, hideLabel: true, refused: !x.tested || x.paused ? t.mustTest : undefined, onChange: (on) => void flow.setServiceOn(x.id, on), "data-signin-tile": `service-on-${x.id}` })), signInServiceActions(text, x, s, keys.turnOn, (id) => void flow.confirmService(id)).map((a) => (_jsx(Button, { compact: true, tone: "subtle", label: a.label, labelKey: a.labelKey, busy: a.busy, "data-signin-tile": `service-${a.id}-${x.id}`, onClick: a.onClick }, a.id))), !x.fromConfig && (_jsxs(_Fragment, { children: [_jsx(Button, { compact: true, tone: face.tone === "neutral" ? "subtle" : face.tone, label: t.test, labelKey: keys.test, glyph: face.outcome === "cross" ? _jsx(IconClose, {}) : _jsx(IconCheck, {}), busy: s.rowTests[x.id]?.busy, title: s.rowTests[x.id]?.title, className: face.shake ? "glim-shake" : undefined, "data-signin-tile": `service-test-${x.id}`, onClick: () => void flow.testService(x.id) }), _jsx(Button, { compact: true, tone: "subtle", label: t.edit, labelKey: keys.edit, glyph: _jsx(IconPencil, {}), "data-signin-tile": `service-edit-${x.id}`, onClick: () => flow.editService(x.id) }), _jsx(Button, { compact: true, tone: "subtle", label: text.remove, labelKey: keys.remove, glyph: _jsx(IconTrash, {}), "data-signin-tile": `remove-service-${x.id}`, onClick: () => ask("service", x.id, label.name) })] }))] }) }, x.id));
140
+ }) })), _jsx("div", { className: "glim-signin-tile-foot", children: _jsx(Button, { label: t.add, labelKey: keys.addService, "data-signin-tile": "service-pick", onClick: flow.pickService }) })] })) }));
141
+ }
142
+ function AccountsCard({ ctx, hue }) {
143
+ const { s, flow, text, keys, when, ask } = ctx;
144
+ const t = text.accounts;
145
+ const notice = signInCardNotice(text, s, "accounts");
146
+ if (notice) {
147
+ return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "accounts", children: _jsx(Notice, { notice: notice }) }));
148
+ }
149
+ return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "accounts", children: _jsx("div", { className: "glim-list glim-signin-tile-rows", children: (s.accounts ?? []).map((a) => (_jsx(ListRow, { steady: true, name: a.name, tile: _jsx(GlyphTile, { glyph: glyphFor(keys.account) }), meta: accountFacts(text, a, s.serviceLabels, when).join(" · "), badges: (a.owner || a.blocked) && (_jsxs(_Fragment, { children: [a.owner && _jsx(Badge, { size: "small", children: t.owner }), a.blocked && (_jsx(Badge, { size: "small", tone: "warn", children: t.blocked }))] })), actions: !a.owner &&
150
+ a.id !== s.me?.account && (_jsxs(_Fragment, { children: [_jsx(Button, { compact: true, tone: "subtle", label: a.blocked ? t.unblock : t.block, labelKey: a.blocked ? keys.unblock : keys.block, busy: s.busy === `account-block-${a.id}`, "data-signin-tile": `account-block-${a.id}`, onClick: () => void flow.block(a.id, !a.blocked) }), _jsx(Button, { compact: true, tone: "subtle", label: text.remove, labelKey: keys.remove, glyph: _jsx(IconTrash, {}), "data-signin-tile": `remove-account-${a.id}`, onClick: () => ask("account", a.id, a.name) })] })) }, a.id))) }) }));
151
+ }
152
+ function TileWindow({ ctx, api, providers }) {
153
+ const { s, flow, text, lang, scopes, keys, eye, err } = ctx;
154
+ const w = s.window;
155
+ if (!w)
156
+ return null;
157
+ const words = { cancel: text.cancel, close: text.close };
158
+ const cancel = { label: text.cancel, labelKey: "common.cancel", glyph: _jsx(IconCancel, {}), wayOut: true };
159
+ const act = (label, labelKey, hook, run, more = {}) => ({
160
+ label,
161
+ labelKey,
162
+ busy: s.busy === hook,
163
+ attrs: { "data-signin-tile": hook },
164
+ onClick: () => {
165
+ void run();
166
+ return false;
167
+ },
168
+ ...more,
169
+ });
170
+ if (w.kind === "removePassword") {
171
+ const t = text.password;
172
+ const goes = passwordGoes(text, lang, s);
173
+ return (_jsx(Window, { title: t.removeTitle, text: words, closeOnBackdrop: false, onClose: flow.close, actions: [cancel, act(t.remove, keys.removePassword, "remove-password", flow.removePassword)], children: _jsxs("div", { className: "glim-signin-tile-body", children: [_jsx("p", { className: "glim-signin-tile-text", children: t.removeText }), goes.length > 0 && (_jsx("ul", { className: "glim-signin-tile-goes", children: goes.map((g) => (_jsx("li", { children: g }, g))) })), _jsx(FieldRow, { label: t.current, children: _jsx(PasswordField, { autoComplete: "current-password", value: s.draft.current, onChange: (e) => flow.set("current", e.target.value), onKeyDown: enter(() => void flow.removePassword()), text: eye, error: err("current") }) })] }) }));
174
+ }
175
+ if (w.kind === "twoFactorSetup" || w.kind === "twoFactorOff") {
176
+ const t = text.twoFactor;
177
+ const setup = w.kind === "twoFactorSetup";
178
+ const run = setup ? flow.confirmTwoFactor : flow.turnTwoFactorOff;
179
+ const action = setup
180
+ ? act(t.confirm, keys.confirm, "two-factor-confirm", run, { primary: true, disabled: s.draft.code.trim() === "" })
181
+ : act(t.offConfirm, keys.turnOff, "two-factor-off", run, { disabled: s.draft.code.trim() === "" });
182
+ const qr = setup ? qrCode(w.uri) : null;
183
+ return (_jsx(Window, { title: setup ? t.setupTitle : t.offTitle, text: words, closeOnBackdrop: false, onClose: flow.close, actions: setup ? [action] : [cancel, action], children: _jsxs("div", { className: "glim-signin-tile-body", children: [_jsx("p", { className: "glim-signin-tile-text", children: setup ? t.scan : t.offText }), setup && qr && (_jsx("svg", { className: "glim-signin-tile-qr", viewBox: `-2 -2 ${qr.size + 4} ${qr.size + 4}`, role: "img", "aria-label": t.qr, children: _jsx("path", { d: qr.path }) })), setup && (_jsx(FieldRow, { label: t.key, children: _jsx(CopyField, { value: w.secret.replace(/(.{4})(?=.)/g, "$1 "), text: { copy: text.copy, copied: text.copied } }) })), _jsx(FieldRow, { label: t.code, children: _jsx(TextField, { inputMode: setup ? "numeric" : "text", autoComplete: "one-time-code", spellCheck: false, width: "short", value: s.draft.code, onChange: (e) => flow.set("code", e.target.value), onKeyDown: enter(() => void run()), error: err("code") }) })] }) }));
184
+ }
185
+ if (w.kind === "recoveryCodes") {
186
+ const t = text.twoFactor;
187
+ return (_jsx(Window, { title: t.codesTitle, text: words, closeOnBackdrop: false, onClose: flow.close, actions: [
188
+ act(t.copyCodes, keys.copy, "two-factor-copy", flow.copyCodes),
189
+ { label: t.codesSaved, labelKey: keys.confirm, primary: true, wayOut: true, attrs: { "data-signin-tile": "two-factor-saved" } },
190
+ ], children: _jsxs("div", { className: "glim-signin-tile-body", children: [_jsx("p", { className: "glim-signin-tile-text", children: t.codesText }), _jsx("ul", { className: "glim-signin-tile-codes", children: w.codes.map((c) => (_jsx("li", { children: c }, c))) })] }) }));
191
+ }
192
+ if (w.kind === "addPasskey" || w.kind === "renamePasskey") {
193
+ const t = text.passkeys;
194
+ const add = w.kind === "addPasskey";
195
+ const run = add ? flow.addPasskey : flow.renamePasskey;
196
+ return (_jsx(Window, { title: add ? t.addTitle : t.renameTitle, text: words, closeOnBackdrop: false, onClose: flow.close, actions: [add ? act(t.continue, keys.passkey, "passkey-add", run, { primary: true }) : act(text.save, keys.save, "passkey-rename", run, { primary: true })], children: _jsxs("div", { className: "glim-signin-tile-body", children: [_jsx(FieldRow, { label: t.name, hint: t.nameHint, children: _jsx(TextField, { value: s.draft.name, onChange: (e) => flow.set("name", e.target.value), onKeyDown: enter(() => void run()), error: err("name") }) }), _jsx(Said, { said: s.said })] }) }));
197
+ }
198
+ if (w.kind === "newToken") {
199
+ const t = text.tokens;
200
+ return (_jsx(Window, { title: t.newTitle, text: words, closeOnBackdrop: false, onClose: flow.close, actions: [act(t.make, keys.createToken, "token-make", flow.makeToken, { primary: true })], children: _jsxs("div", { className: "glim-signin-tile-body", children: [s.me?.via === "open" && _jsx("p", { className: "glim-signin-tile-text", children: t.openHint }), _jsxs(FieldRowGroup, { children: [_jsx(FieldRow, { label: t.name, hint: t.nameHint, children: _jsx(TextField, { value: s.draft.name, onChange: (e) => flow.set("name", e.target.value), onKeyDown: enter(() => void flow.makeToken()), error: err("name") }) }), _jsx(FieldRow, { label: t.scope, children: _jsx(Selector, { inline: true, activation: "manual", value: s.draft.scope, onChange: (v) => flow.set("scope", v), items: signInScopeItems(scopes, t.scopes) }) }), _jsx(FieldRow, { label: t.lifetime, children: _jsx(Selector, { inline: true, activation: "manual", value: s.draft.life, onChange: (v) => flow.set("life", v), items: SIGN_IN_TOKEN_LIVES.map((id) => ({ id, label: t.lifetimes[id] })) }) })] })] }) }));
201
+ }
202
+ if (w.kind === "tokenShown") {
203
+ const t = text.tokens;
204
+ return (_jsx(Window, { title: t.shownTitle, text: words, closeOnBackdrop: false, onClose: flow.close, actions: [{ label: t.shownDone, labelKey: keys.confirm, primary: true, wayOut: true }], children: _jsxs("div", { className: "glim-signin-tile-body", children: [_jsx("p", { className: "glim-signin-tile-text", children: t.shownText }), _jsx(FieldRow, { label: w.name, children: _jsx(CopyField, { value: w.value, text: { copy: text.copy, copied: text.copied } }) })] }) }));
205
+ }
206
+ const t = text.services;
207
+ const { items, groups } = signInServicePicker(providers, text, lang, s.services, () => glyphFor(keys.service));
208
+ const pickerText = { search: t.search, none: t.searchNone, clear: t.clear, close: text.close, cancel: text.cancel, back: text.back };
209
+ if (w.kind === "pickService") {
210
+ return _jsx(PickerWindow, { title: t.pick, hint: t.pickHint, items: items, groups: groups, text: pickerText, onPick: flow.chooseService, onClose: flow.close });
211
+ }
212
+ const name = signInServiceName(text, w.provider, s.draft.label, providers.entries.find((e) => e.id === w.provider)?.name);
213
+ const editing = s.services?.find((x) => x.id === w.edit);
214
+ const roleItems = signInRoleItems(text, s.roles);
215
+ const test = s.formTest;
216
+ const field = (key, label, hint, placeholder) => (_jsx(FieldRow, { label: label, hint: hint, children: _jsx(TextField, { mono: key !== "label", value: s.draft[key], placeholder: placeholder, onChange: (e) => flow.set(key, e.target.value), onPaste: key === "clientId" ? (e) => flow.pasteClient(e.clipboardData.getData("text")) && e.preventDefault() : undefined, error: err(key), "data-signin-field": key }) }));
217
+ return (_jsx(PickerWindow, { title: name, items: items, groups: groups, text: pickerText, selected: w.provider, onPick: flow.chooseService, onBack: w.edit ? flow.close : flow.pickService, onClose: flow.close, actions: [
218
+ act(signInTestLabel(text, test), "test", "service-test", flow.testDraft, {
219
+ glyph: test?.tone === "ok" ? _jsx(IconCheck, {}) : test?.tone === "danger" ? _jsx(IconClose, {}) : undefined,
220
+ tone: test?.busy ? undefined : test?.tone,
221
+ busy: !!test?.busy,
222
+ title: test?.title,
223
+ }),
224
+ w.edit
225
+ ? act(text.save, keys.save, "service-save", flow.saveService, { primary: true })
226
+ : { label: t.turnOn, labelKey: keys.turnOn, primary: true, disabled: true, title: t.mustTest, attrs: { "data-signin-tile": "service-turn-on" } },
227
+ ], children: _jsxs("div", { className: "glim-signin-tile-form", "data-signin-form": w.provider, children: [_jsx("p", { className: "glim-signin-tile-text", children: fill(t.formHint, { name }) }), _jsxs(FieldRowGroup, { children: [field("issuer", t.issuer, t.issuerHint), field("clientId", t.clientId), _jsx(FieldRow, { label: t.secret, hint: w.edit ? t.secretKept : undefined, children: _jsx(PasswordField, { autoComplete: "off", value: s.draft.secret, onChange: (e) => flow.set("secret", e.target.value), text: eye, error: err("secret"), "data-signin-field": "secret" }) }), _jsx(FieldRow, { label: t.redirect, hint: t.redirectHint, children: _jsx(CopyField, { value: signInRedirectAddress(api, editing), text: { copy: text.copy, copied: text.copied } }) }), field("label", t.label, undefined, signInServiceLabel({ provider: w.provider }, providers, text).name), roleItems && (_jsx(FieldRow, { label: t.role, "data-signin-field": "role", children: _jsx(Selector, { inline: true, activation: "manual", value: s.draft.role, onChange: (v) => flow.set("role", v), items: roleItems }) }))] }), _jsx(Accordion, { items: [{ value: "more", title: t.more }], content: () => (_jsxs(FieldRowGroup, { children: [field("scopes", t.scopes), field("nameClaim", t.nameClaim), field("groupsClaim", t.groupsClaim)] })) }), _jsx("p", { className: "glim-signin-tile-quiet", children: signInServiceQuiet(text, s, name) }), _jsx(Said, { said: s.said })] }) }));
228
+ }
229
+ // What the last try in a window came to, under its form rather than in its foot.
230
+ function Said({ said }) {
231
+ if (!said)
232
+ return null;
233
+ return (_jsx("p", { className: said.ok ? "glim-signin-tile-said" : "glim-signin-tile-said glim-signin-tile-said--fail", role: said.ok ? "status" : "alert", children: said.message }));
234
+ }
package/dist/index.d.ts CHANGED
@@ -47,6 +47,8 @@ export * from "./Selector.tsx";
47
47
  export * from "./SidebarRow.tsx";
48
48
  export * from "./Sheet.tsx";
49
49
  export * from "./SignInCard.tsx";
50
+ export * from "./SignInReauthWindow.tsx";
51
+ export * from "./SignInTile.tsx";
50
52
  export * from "./SkeletonRow.tsx";
51
53
  export * from "./SubCard.tsx";
52
54
  export * from "./Table.tsx";
package/dist/index.js CHANGED
@@ -47,6 +47,8 @@ export * from "./Selector.js";
47
47
  export * from "./SidebarRow.js";
48
48
  export * from "./Sheet.js";
49
49
  export * from "./SignInCard.js";
50
+ export * from "./SignInReauthWindow.js";
51
+ export * from "./SignInTile.js";
50
52
  export * from "./SkeletonRow.js";
51
53
  export * from "./SubCard.js";
52
54
  export * from "./Table.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glimstone/react",
3
- "version": "4.8.5",
3
+ "version": "4.9.0",
4
4
  "description": "GlimStone's components for React",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": { "type": "git", "url": "git+https://github.com/junkerderprovinz/glimstone.git", "directory": "packages/react" },
@@ -16,7 +16,7 @@
16
16
  "build": "tsc -p tsconfig.build.json"
17
17
  },
18
18
  "dependencies": {
19
- "@glimstone/core": "4.8.5"
19
+ "@glimstone/core": "4.9.0"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "@internationalized/date": "^3.12.4",