@ada-cx/lovelace 1.21.6 → 1.22.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.
Files changed (53) hide show
  1. package/README.md +2 -2
  2. package/dist/components/AgentMessage/AgentMessage.css.js.map +1 -1
  3. package/dist/components/Button/Button.css.d.ts +3 -0
  4. package/dist/components/Button/Button.css.js +1 -0
  5. package/dist/components/Button/Button.css.js.map +1 -1
  6. package/dist/components/Chip/Chip.css.js +1 -0
  7. package/dist/components/Chip/Chip.css.js.map +1 -1
  8. package/dist/components/Chip/Chip.d.ts +2 -1
  9. package/dist/components/Chip/Chip.js.map +1 -1
  10. package/dist/components/IconButton/IconButton.css.d.ts +3 -0
  11. package/dist/components/IconButton/IconButton.css.js +1 -0
  12. package/dist/components/IconButton/IconButton.css.js.map +1 -1
  13. package/dist/components/Input/Input.css.d.ts +5 -1
  14. package/dist/components/Input/Input.css.js +1 -0
  15. package/dist/components/Input/Input.css.js.map +1 -1
  16. package/dist/components/MessageProse/MessageProse.css.d.ts +5 -6
  17. package/dist/components/MessageProse/MessageProse.css.js.map +1 -1
  18. package/dist/components/MessageRow/MessageRow.css.js.map +1 -1
  19. package/dist/components/PictureMessage/PictureMessage.d.ts +6 -1
  20. package/dist/components/PictureMessage/PictureMessage.js +10 -10
  21. package/dist/components/PictureMessage/PictureMessage.js.map +1 -1
  22. package/dist/components/ScrollMarker/ScrollMarker.css.d.ts +3 -0
  23. package/dist/components/ScrollMarker/ScrollMarker.css.js +1 -0
  24. package/dist/components/ScrollMarker/ScrollMarker.css.js.map +1 -1
  25. package/dist/components/SurveySelect/SurveySelect.d.ts +1 -1
  26. package/dist/components/SurveySelect/SurveySelect.js.map +1 -1
  27. package/dist/components/Toast/Toast.css.d.ts +6 -0
  28. package/dist/components/Toast/Toast.css.js +2 -2
  29. package/dist/components/Toast/Toast.css.js.map +1 -1
  30. package/dist/components/Toast/Toast.d.ts +2 -3
  31. package/dist/components/Toast/Toast.js.map +1 -1
  32. package/dist/components/Toast/ToastAnnouncer.d.ts +21 -0
  33. package/dist/components/Toast/ToastAnnouncer.js +104 -0
  34. package/dist/components/Toast/ToastAnnouncer.js.map +1 -0
  35. package/dist/components/Toast/ToastContainer.d.ts +11 -8
  36. package/dist/components/Toast/ToastContainer.js +46 -51
  37. package/dist/components/Toast/ToastContainer.js.map +1 -1
  38. package/dist/components/Toast/ToastItem.d.ts +7 -1
  39. package/dist/components/UserMessage/UserMessage.css.js.map +1 -1
  40. package/dist/components/VideoMessage/VideoMessage.d.ts +8 -1
  41. package/dist/components/VideoMessage/VideoMessage.js +9 -9
  42. package/dist/components/VideoMessage/VideoMessage.js.map +1 -1
  43. package/dist/runtime/LovelaceProvider.js +29 -26
  44. package/dist/runtime/LovelaceProvider.js.map +1 -1
  45. package/dist/runtime/branding.d.ts +71 -19
  46. package/dist/runtime/branding.js +97 -10
  47. package/dist/runtime/branding.js.map +1 -1
  48. package/dist/style.css +1 -1
  49. package/dist/styles/state-layer.css.d.ts +19 -0
  50. package/dist/styles/state-layer.css.js +23 -0
  51. package/dist/styles/state-layer.css.js.map +1 -0
  52. package/dist/tokens/generated/tokens.d.ts +7 -1
  53. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"Toast.js","names":[],"sources":["../../../src/components/Toast/Toast.tsx"],"sourcesContent":["import type { CSSProperties, HTMLAttributes, ReactNode, Ref } from \"react\";\nimport type { PressEvent } from \"react-aria\";\nimport { cx } from \"../../utils/cx.js\";\nimport {\n\tCheckmarkCircle,\n\tExclamationTriangle,\n\tXmark,\n\tXmarkCircle,\n} from \"../Icon/icons/index.js\";\nimport { IconButton } from \"../IconButton/IconButton.js\";\nimport { Spinner } from \"../Spinner/Spinner.js\";\nimport { toast, toastDismiss, toastIcon, toastMessage } from \"./Toast.css.js\";\n\nexport type ToastStatus =\n\t| \"success\"\n\t| \"warning\"\n\t| \"error\"\n\t| \"custom\"\n\t| \"loading\";\n\nconst STATUS_ICON = {\n\tsuccess: CheckmarkCircle,\n\twarning: ExclamationTriangle,\n\terror: XmarkCircle,\n} as const;\n\nexport interface ToastProps {\n\t/**\n\t * The outcome being reported — selects the leading glyph and its colour. Bind\n\t * it to the result of the action, not the UI. `custom` takes the glyph from\n\t * `icon`; `loading` shows a spinner and refuses a dismiss control.\n\t */\n\tstatus?: ToastStatus;\n\t/** The glyph for `status=\"custom\"`. Ignored for every other status. */\n\ticon?: ReactNode;\n\t/**\n\t * Renders a trailing dismiss button and runs this when the user presses it.\n\t * Ignored while `status=\"loading\"`, whose lifetime belongs to whatever raised\n\t * it rather than to the reader.\n\t */\n\tonDismiss?: (event: PressEvent) => void;\n\t/** Accessible name for the dismiss button. Localize it. */\n\tdismissLabel?: string;\n\t/**\n\t * Takes the press away while the card is on screen only to finish leaving.\n\t * WebKit added `inert` in 15.5, after the iOS 15.4 floor in\n\t * `messaging/vite.browser-targets.mjs`. At that floor, the container's `inert`\n\t * attribute leaves the button tabbable even though its press no longer acts\n\t * on anything. Disabling keeps the card's layout still through the travel,\n\t * which removing the button would not.\n\t */\n\tdismissDisabled?: boolean;\n\t/**\n\t * Attributes for the message element. A container that owns announcement\n\t * passes its live-region props through here, so the dismiss button stays\n\t * outside what gets announced.\n\t */\n\tmessageProps?: HTMLAttributes<HTMLElement>;\n\tclassName?: string;\n\tstyle?: CSSProperties;\n\tref?: Ref<HTMLDivElement>;\n\t/** The message to display. Keep it to a single line. */\n\tchildren?: ReactNode;\n}\n\nfunction LeadingGlyph({\n\tstatus,\n\ticon,\n}: {\n\tstatus: ToastStatus;\n\ticon: ReactNode;\n}) {\n\tif (status === \"loading\") {\n\t\t// Spinner carries its own `role=\"status\" aria-label=\"Loading\"`, and the\n\t\t// container already puts a live region on the message. Two of them inside\n\t\t// one alertdialog announces \"Loading\" ahead of the message, so this one is\n\t\t// hidden — the copy is what the reader needs.\n\t\treturn (\n\t\t\t<span aria-hidden=\"true\">\n\t\t\t\t<Spinner size=\"sm\" />\n\t\t\t</span>\n\t\t);\n\t}\n\tif (status === \"custom\") {\n\t\treturn icon;\n\t}\n\tconst StatusIcon = STATUS_ICON[status];\n\treturn <StatusIcon />;\n}\n\n/**\n * The floating surface for a transient event — a card that sits above the\n * transcript on a neutral background, rather than the tinted full-width strip\n * `Banner` paints for a lasting condition. The two differ on purpose:\n * a card reads as passing through, a strip as part of the page.\n *\n * Purely presentational, and carries no live region of its own, so it can sit\n * inside a container that owns the announcement. Rendering it standalone\n * announces nothing — reach for `ToastContainer`.\n */\nexport function Toast({\n\tstatus = \"success\",\n\ticon,\n\tonDismiss,\n\tdismissLabel = \"Dismiss notification\",\n\tdismissDisabled = false,\n\tmessageProps,\n\tclassName,\n\tchildren,\n\t...rest\n}: ToastProps) {\n\t// Loading owns its own lifetime, so it never offers a dismiss control even\n\t// when the consumer passes one.\n\tconst canDismiss = !!onDismiss && status !== \"loading\";\n\t// Decided before the element exists: an element is truthy even when the\n\t// component returns null, so testing the rendered glyph would leave an empty\n\t// slot — and its `gap-8` — indenting the message of an iconless `custom`.\n\tconst hasGlyph = status !== \"custom\" || !!icon;\n\n\treturn (\n\t\t<div {...rest} data-status={status} className={cx(toast, className)}>\n\t\t\t{hasGlyph ? (\n\t\t\t\t<span className={toastIcon({ status })}>\n\t\t\t\t\t<LeadingGlyph status={status} icon={icon} />\n\t\t\t\t</span>\n\t\t\t) : null}\n\t\t\t{/* A div, not a span: a container that owns announcement puts a live\n\t\t\t region here, and React Aria renders that region as a div. */}\n\t\t\t<div\n\t\t\t\t{...messageProps}\n\t\t\t\tclassName={cx(messageProps?.className, toastMessage)}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t\t{canDismiss && (\n\t\t\t\t<IconButton\n\t\t\t\t\tlabel={dismissLabel}\n\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\tsize=\"xs\"\n\t\t\t\t\tisDisabled={dismissDisabled}\n\t\t\t\t\tonPress={onDismiss}\n\t\t\t\t\tclassName={toastDismiss}\n\t\t\t\t>\n\t\t\t\t\t<Xmark />\n\t\t\t\t</IconButton>\n\t\t\t)}\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;AAoBA,IAAM,IAAc;CACnB,SAAS;CACT,SAAS;CACT,OAAO;AACR;AAyCA,SAAS,EAAa,EACrB,WACA,WAIE;CACF,IAAI,MAAW,WAKd,OACC,kBAAC,QAAD;EAAM,eAAY;YACjB,kBAAC,GAAD,EAAS,MAAK,KAAM,CAAA;CACf,CAAA;CAGR,IAAI,MAAW,UACd,OAAO;CAER,IAAM,IAAa,EAAY;CAC/B,OAAO,kBAAC,GAAD,CAAa,CAAA;AACrB;AAYA,SAAgB,EAAM,EACrB,YAAS,WACT,SACA,cACA,kBAAe,wBACf,qBAAkB,IAClB,iBACA,cACA,aACA,GAAG,KACW;CAGd,IAAM,IAAa,CAAC,CAAC,KAAa,MAAW,WAIvC,IAAW,MAAW,YAAY,CAAC,CAAC;CAE1C,OACC,kBAAC,OAAD;EAAK,GAAI;EAAM,eAAa;EAAQ,WAAW,EAAG,GAAO,CAAS;YAAlE;GACE,IACA,kBAAC,QAAD;IAAM,WAAW,EAAU,EAAE,UAAO,CAAC;cACpC,kBAAC,GAAD;KAAsB;KAAc;IAAO,CAAA;GACtC,CAAA,IACH;GAGJ,kBAAC,OAAD;IACC,GAAI;IACJ,WAAW,EAAG,GAAc,WAAW,CAAY;IAElD;GACG,CAAA;GACJ,KACA,kBAAC,GAAD;IACC,OAAO;IACP,SAAQ;IACR,MAAK;IACL,YAAY;IACZ,SAAS;IACT,WAAA;cAEA,kBAAC,GAAD,CAAQ,CAAA;GACG,CAAA;EAET;;AAEP"}
1
+ {"version":3,"file":"Toast.js","names":[],"sources":["../../../src/components/Toast/Toast.tsx"],"sourcesContent":["import type { CSSProperties, HTMLAttributes, ReactNode, Ref } from \"react\";\nimport type { PressEvent } from \"react-aria\";\nimport { cx } from \"../../utils/cx.js\";\nimport {\n\tCheckmarkCircle,\n\tExclamationTriangle,\n\tXmark,\n\tXmarkCircle,\n} from \"../Icon/icons/index.js\";\nimport { IconButton } from \"../IconButton/IconButton.js\";\nimport { Spinner } from \"../Spinner/Spinner.js\";\nimport { toast, toastDismiss, toastIcon, toastMessage } from \"./Toast.css.js\";\n\nexport type ToastStatus =\n\t| \"success\"\n\t| \"warning\"\n\t| \"error\"\n\t| \"custom\"\n\t| \"loading\";\n\nconst STATUS_ICON = {\n\tsuccess: CheckmarkCircle,\n\twarning: ExclamationTriangle,\n\terror: XmarkCircle,\n} as const;\n\nexport interface ToastProps {\n\t/**\n\t * The outcome being reported — selects the leading glyph and its colour. Bind\n\t * it to the result of the action, not the UI. `custom` takes the glyph from\n\t * `icon`; `loading` shows a spinner and refuses a dismiss control.\n\t */\n\tstatus?: ToastStatus;\n\t/** The glyph for `status=\"custom\"`. Ignored for every other status. */\n\ticon?: ReactNode;\n\t/**\n\t * Renders a trailing dismiss button and runs this when the user presses it.\n\t * Ignored while `status=\"loading\"`, whose lifetime belongs to whatever raised\n\t * it rather than to the reader.\n\t */\n\tonDismiss?: (event: PressEvent) => void;\n\t/** Accessible name for the dismiss button. Localize it. */\n\tdismissLabel?: string;\n\t/**\n\t * Takes the press away while the card is on screen only to finish leaving.\n\t * WebKit added `inert` in 15.5, after the iOS 15.4 floor in\n\t * `messaging/vite.browser-targets.mjs`. At that floor, the container's `inert`\n\t * attribute leaves the button tabbable even though its press no longer acts\n\t * on anything. Disabling keeps the card's layout still through the travel,\n\t * which removing the button would not.\n\t */\n\tdismissDisabled?: boolean;\n\t/**\n\t * Attributes for the message element. A container passes the id that names\n\t * the card through here.\n\t */\n\tmessageProps?: HTMLAttributes<HTMLElement>;\n\tclassName?: string;\n\tstyle?: CSSProperties;\n\tref?: Ref<HTMLDivElement>;\n\t/** The message to display. Keep it to a single line. */\n\tchildren?: ReactNode;\n}\n\nfunction LeadingGlyph({\n\tstatus,\n\ticon,\n}: {\n\tstatus: ToastStatus;\n\ticon: ReactNode;\n}) {\n\tif (status === \"loading\") {\n\t\t// Spinner carries its own `role=\"status\" aria-label=\"Loading\"`. Inside the\n\t\t// card, a reader would say \"Loading\" ahead of the message, so this one is\n\t\t// hidden. The copy is what the reader needs.\n\t\treturn (\n\t\t\t<span aria-hidden=\"true\">\n\t\t\t\t<Spinner size=\"sm\" />\n\t\t\t</span>\n\t\t);\n\t}\n\tif (status === \"custom\") {\n\t\treturn icon;\n\t}\n\tconst StatusIcon = STATUS_ICON[status];\n\treturn <StatusIcon />;\n}\n\n/**\n * The floating surface for a transient event — a card that sits above the\n * transcript on a neutral background, rather than the tinted full-width strip\n * `Banner` paints for a lasting condition. The two differ on purpose:\n * a card reads as passing through, a strip as part of the page.\n *\n * Purely presentational, and carries no live region of its own, so it can sit\n * inside a container that owns the announcement. Rendering it standalone\n * announces nothing — reach for `ToastContainer`.\n */\nexport function Toast({\n\tstatus = \"success\",\n\ticon,\n\tonDismiss,\n\tdismissLabel = \"Dismiss notification\",\n\tdismissDisabled = false,\n\tmessageProps,\n\tclassName,\n\tchildren,\n\t...rest\n}: ToastProps) {\n\t// Loading owns its own lifetime, so it never offers a dismiss control even\n\t// when the consumer passes one.\n\tconst canDismiss = !!onDismiss && status !== \"loading\";\n\t// Decided before the element exists: an element is truthy even when the\n\t// component returns null, so testing the rendered glyph would leave an empty\n\t// slot — and its `gap-8` — indenting the message of an iconless `custom`.\n\tconst hasGlyph = status !== \"custom\" || !!icon;\n\n\treturn (\n\t\t<div {...rest} data-status={status} className={cx(toast, className)}>\n\t\t\t{hasGlyph ? (\n\t\t\t\t<span className={toastIcon({ status })}>\n\t\t\t\t\t<LeadingGlyph status={status} icon={icon} />\n\t\t\t\t</span>\n\t\t\t) : null}\n\t\t\t<div\n\t\t\t\t{...messageProps}\n\t\t\t\tclassName={cx(messageProps?.className, toastMessage)}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t\t{canDismiss && (\n\t\t\t\t<IconButton\n\t\t\t\t\tlabel={dismissLabel}\n\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\tsize=\"xs\"\n\t\t\t\t\tisDisabled={dismissDisabled}\n\t\t\t\t\tonPress={onDismiss}\n\t\t\t\t\tclassName={toastDismiss}\n\t\t\t\t>\n\t\t\t\t\t<Xmark />\n\t\t\t\t</IconButton>\n\t\t\t)}\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;AAoBA,IAAM,IAAc;CACnB,SAAS;CACT,SAAS;CACT,OAAO;AACR;AAwCA,SAAS,EAAa,EACrB,WACA,WAIE;CACF,IAAI,MAAW,WAId,OACC,kBAAC,QAAD;EAAM,eAAY;YACjB,kBAAC,GAAD,EAAS,MAAK,KAAM,CAAA;CACf,CAAA;CAGR,IAAI,MAAW,UACd,OAAO;CAER,IAAM,IAAa,EAAY;CAC/B,OAAO,kBAAC,GAAD,CAAa,CAAA;AACrB;AAYA,SAAgB,EAAM,EACrB,YAAS,WACT,SACA,cACA,kBAAe,wBACf,qBAAkB,IAClB,iBACA,cACA,aACA,GAAG,KACW;CAGd,IAAM,IAAa,CAAC,CAAC,KAAa,MAAW,WAIvC,IAAW,MAAW,YAAY,CAAC,CAAC;CAE1C,OACC,kBAAC,OAAD;EAAK,GAAI;EAAM,eAAa;EAAQ,WAAW,EAAG,GAAO,CAAS;YAAlE;GACE,IACA,kBAAC,QAAD;IAAM,WAAW,EAAU,EAAE,UAAO,CAAC;cACpC,kBAAC,GAAD;KAAsB;KAAc;IAAO,CAAA;GACtC,CAAA,IACH;GACJ,kBAAC,OAAD;IACC,GAAI;IACJ,WAAW,EAAG,GAAc,WAAW,CAAY;IAElD;GACG,CAAA;GACJ,KACA,kBAAC,GAAD;IACC,OAAO;IACP,SAAQ;IACR,MAAK;IACL,YAAY;IACZ,SAAS;IACT,WAAA;cAEA,kBAAC,GAAD,CAAQ,CAAA;GACG,CAAA;EAET;;AAEP"}
@@ -0,0 +1,21 @@
1
+ import type { ToastQueue } from "react-stately";
2
+ import type { ToastItem } from "./ToastItem.js";
3
+ /**
4
+ * Speaks each toast once, when it joins the queue's visible toasts.
5
+ *
6
+ * React Aria mounts the region, the card and its text in one commit, and a
7
+ * screen reader speaks a live region only when its content changes after the
8
+ * region is in the page. These slots are in the page before any toast, so a
9
+ * toast is spoken when its text is written into one.
10
+ *
11
+ * It speaks a toast raised under a modal overlay as well. The region stands down
12
+ * under the overlay, but this sits in the anchor, which React Aria keeps exposed,
13
+ * so the reader hears the event when it happens rather than when the overlay
14
+ * closes.
15
+ *
16
+ * The slots carry `aria-live` and no `role`, so they add no empty `alert` or
17
+ * `status` to the page. Each `alert` and `status` in the page is a real message.
18
+ */
19
+ export declare function ToastAnnouncer({ queue }: {
20
+ queue: ToastQueue<ToastItem>;
21
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,104 @@
1
+ import { toastAnnouncer as e } from "./Toast.css.js";
2
+ import { jsx as t, jsxs as n } from "react/jsx-runtime";
3
+ import { useEffect as r, useState as i } from "react";
4
+ import { useToastQueue as a } from "react-stately";
5
+ //#region src/components/Toast/ToastAnnouncer.tsx
6
+ var o = {
7
+ slots: [[], []],
8
+ last: 1
9
+ }, s = /* @__PURE__ */ new WeakMap(), c = 100;
10
+ function l(e) {
11
+ return e.content.status === "error" ? "assertive" : "polite";
12
+ }
13
+ function u({ message: e, announcement: t }) {
14
+ return t === void 0 ? typeof e == "string" || typeof e == "number" ? String(e) : null : t;
15
+ }
16
+ function d(e, t) {
17
+ let n = +(e.last === 0), r = [[], []];
18
+ return r[n] = t, {
19
+ slots: r,
20
+ last: n
21
+ };
22
+ }
23
+ function f(e, t) {
24
+ let n = (e) => e.length > 0 && e.every(({ key: e }) => !t.has(e));
25
+ return e.slots.some(n) ? {
26
+ ...e,
27
+ slots: [n(e.slots[0]) ? [] : e.slots[0], n(e.slots[1]) ? [] : e.slots[1]]
28
+ } : e;
29
+ }
30
+ function p({ urgency: e, announcements: n }) {
31
+ return /* @__PURE__ */ t("div", {
32
+ "aria-live": e,
33
+ "aria-atomic": "true",
34
+ children: n.map(({ key: e, text: n }) => /* @__PURE__ */ t("div", { children: n }, e))
35
+ });
36
+ }
37
+ function m({ queue: m }) {
38
+ let { visibleToasts: h } = a(m), [g, _] = i({
39
+ polite: o,
40
+ assertive: o
41
+ }), [v, y] = i(!1);
42
+ return r(() => {
43
+ let e = window.setTimeout(() => y(!0), c);
44
+ return () => window.clearTimeout(e);
45
+ }, []), r(() => {
46
+ if (!v) return;
47
+ let e = s.get(m);
48
+ e || (e = /* @__PURE__ */ new Set(), s.set(m, e));
49
+ let t = new Set(h.map(({ key: e }) => e));
50
+ for (let n of e) t.has(n) || e.delete(n);
51
+ let n = {
52
+ polite: [],
53
+ assertive: []
54
+ };
55
+ for (let t of [...h].reverse()) {
56
+ if (e.has(t.key)) continue;
57
+ e.add(t.key);
58
+ let r = u(t.content);
59
+ r && n[l(t)].push({
60
+ key: t.key,
61
+ text: r
62
+ });
63
+ }
64
+ _((e) => {
65
+ let r = (r) => {
66
+ let i = f(e[r], t);
67
+ return n[r].length > 0 ? d(i, n[r]) : i;
68
+ }, i = r("polite"), a = r("assertive");
69
+ return i === e.polite && a === e.assertive ? e : {
70
+ polite: i,
71
+ assertive: a
72
+ };
73
+ });
74
+ }, [
75
+ m,
76
+ h,
77
+ v
78
+ ]), /* @__PURE__ */ n("div", {
79
+ "data-live-announcer": "true",
80
+ className: e,
81
+ children: [
82
+ /* @__PURE__ */ t(p, {
83
+ urgency: "polite",
84
+ announcements: g.polite.slots[0]
85
+ }),
86
+ /* @__PURE__ */ t(p, {
87
+ urgency: "polite",
88
+ announcements: g.polite.slots[1]
89
+ }),
90
+ /* @__PURE__ */ t(p, {
91
+ urgency: "assertive",
92
+ announcements: g.assertive.slots[0]
93
+ }),
94
+ /* @__PURE__ */ t(p, {
95
+ urgency: "assertive",
96
+ announcements: g.assertive.slots[1]
97
+ })
98
+ ]
99
+ });
100
+ }
101
+ //#endregion
102
+ export { m as ToastAnnouncer };
103
+
104
+ //# sourceMappingURL=ToastAnnouncer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToastAnnouncer.js","names":[],"sources":["../../../src/components/Toast/ToastAnnouncer.tsx"],"sourcesContent":["import { useEffect, useState } from \"react\";\nimport type { QueuedToast, ToastQueue } from \"react-stately\";\nimport { useToastQueue } from \"react-stately\";\nimport { toastAnnouncer } from \"./Toast.css.js\";\nimport type { ToastItem } from \"./ToastItem.js\";\n\ninterface Announcement {\n\tkey: string;\n\ttext: string;\n}\n\ninterface Lane {\n\tslots: readonly [Announcement[], Announcement[]];\n\tlast: 0 | 1;\n}\n\ninterface Lanes {\n\tpolite: Lane;\n\tassertive: Lane;\n}\n\ntype Urgency = keyof Lanes;\n\nconst EMPTY_LANE: Lane = { slots: [[], []], last: 1 };\n\n/**\n * The keys each queue has already announced. Kept per queue rather than per\n * container, so a container that remounts over a queue still holding toasts\n * does not speak them a second time.\n */\nconst announcedByQueue = new WeakMap<ToastQueue<ToastItem>, Set<string>>();\n\n/**\n * How long the empty regions stay in the page before the first write. A region\n * that gets its text in the same task it is inserted can be missed, and Safari\n * needs the longest. React Aria's own announcer waits the same 100 ms.\n */\nconst SETTLE_MS = 100;\n\nfunction urgencyOf(toast: QueuedToast<ToastItem>): Urgency {\n\treturn toast.content.status === \"error\" ? \"assertive\" : \"polite\";\n}\n\n/**\n * The text to speak. Only text is written into the regions: a copy of an\n * element message would mount its effects twice and put a hidden, focusable\n * copy of any link it holds into the tab order.\n */\nfunction textOf({ message, announcement }: ToastItem): string | null {\n\tif (announcement !== undefined) {\n\t\treturn announcement;\n\t}\n\treturn typeof message === \"string\" || typeof message === \"number\"\n\t\t? String(message)\n\t\t: null;\n}\n\n/**\n * Writes the arrivals into the slot not written last, and empties the other.\n * Every write therefore lands in an empty slot, so the same words twice still\n * change the text of a region, which is what gets them spoken.\n */\nfunction write(lane: Lane, arrivals: Announcement[]): Lane {\n\tconst next = lane.last === 0 ? 1 : 0;\n\tconst slots: [Announcement[], Announcement[]] = [[], []];\n\tslots[next] = arrivals;\n\treturn { slots, last: next };\n}\n\n/**\n * Empties a slot once every toast it announced has left the queue. A slot that\n * still holds one toast keeps the others too: removing part of an atomic\n * region's text can make a reader speak the rest again.\n */\nfunction prune(lane: Lane, visible: ReadonlySet<string>): Lane {\n\tconst stale = (slot: Announcement[]) =>\n\t\tslot.length > 0 && slot.every(({ key }) => !visible.has(key));\n\tif (!lane.slots.some(stale)) {\n\t\treturn lane;\n\t}\n\treturn {\n\t\t...lane,\n\t\tslots: [\n\t\t\tstale(lane.slots[0]) ? [] : lane.slots[0],\n\t\t\tstale(lane.slots[1]) ? [] : lane.slots[1],\n\t\t],\n\t};\n}\n\nfunction Slot({\n\turgency,\n\tannouncements,\n}: {\n\turgency: Urgency;\n\tannouncements: Announcement[];\n}) {\n\treturn (\n\t\t<div aria-live={urgency} aria-atomic=\"true\">\n\t\t\t{announcements.map(({ key, text }) => (\n\t\t\t\t<div key={key}>{text}</div>\n\t\t\t))}\n\t\t</div>\n\t);\n}\n\n/**\n * Speaks each toast once, when it joins the queue's visible toasts.\n *\n * React Aria mounts the region, the card and its text in one commit, and a\n * screen reader speaks a live region only when its content changes after the\n * region is in the page. These slots are in the page before any toast, so a\n * toast is spoken when its text is written into one.\n *\n * It speaks a toast raised under a modal overlay as well. The region stands down\n * under the overlay, but this sits in the anchor, which React Aria keeps exposed,\n * so the reader hears the event when it happens rather than when the overlay\n * closes.\n *\n * The slots carry `aria-live` and no `role`, so they add no empty `alert` or\n * `status` to the page. Each `alert` and `status` in the page is a real message.\n */\nexport function ToastAnnouncer({ queue }: { queue: ToastQueue<ToastItem> }) {\n\tconst { visibleToasts } = useToastQueue(queue);\n\tconst [lanes, setLanes] = useState<Lanes>({\n\t\tpolite: EMPTY_LANE,\n\t\tassertive: EMPTY_LANE,\n\t});\n\tconst [settled, setSettled] = useState(false);\n\n\tuseEffect(() => {\n\t\tconst timer = window.setTimeout(() => setSettled(true), SETTLE_MS);\n\t\treturn () => window.clearTimeout(timer);\n\t}, []);\n\n\tuseEffect(() => {\n\t\tif (!settled) {\n\t\t\treturn;\n\t\t}\n\t\tlet announced = announcedByQueue.get(queue);\n\t\tif (!announced) {\n\t\t\tannounced = new Set();\n\t\t\tannouncedByQueue.set(queue, announced);\n\t\t}\n\t\tconst visible = new Set(visibleToasts.map(({ key }) => key));\n\t\tfor (const key of announced) {\n\t\t\tif (!visible.has(key)) {\n\t\t\t\tannounced.delete(key);\n\t\t\t}\n\t\t}\n\t\tconst arrivals: Record<Urgency, Announcement[]> = {\n\t\t\tpolite: [],\n\t\t\tassertive: [],\n\t\t};\n\t\t// The queue lists its toasts newest first, and a reader hears them oldest\n\t\t// first.\n\t\tfor (const toast of [...visibleToasts].reverse()) {\n\t\t\tif (announced.has(toast.key)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tannounced.add(toast.key);\n\t\t\tconst text = textOf(toast.content);\n\t\t\tif (text) {\n\t\t\t\tarrivals[urgencyOf(toast)].push({ key: toast.key, text });\n\t\t\t}\n\t\t}\n\t\tsetLanes((previous) => {\n\t\t\tconst update = (urgency: Urgency) => {\n\t\t\t\tconst lane = prune(previous[urgency], visible);\n\t\t\t\treturn arrivals[urgency].length > 0\n\t\t\t\t\t? write(lane, arrivals[urgency])\n\t\t\t\t\t: lane;\n\t\t\t};\n\t\t\tconst polite = update(\"polite\");\n\t\t\tconst assertive = update(\"assertive\");\n\t\t\treturn polite === previous.polite && assertive === previous.assertive\n\t\t\t\t? previous\n\t\t\t\t: { polite, assertive };\n\t\t});\n\t}, [queue, visibleToasts, settled]);\n\n\treturn (\n\t\t<div data-live-announcer=\"true\" className={toastAnnouncer}>\n\t\t\t<Slot urgency=\"polite\" announcements={lanes.polite.slots[0]} />\n\t\t\t<Slot urgency=\"polite\" announcements={lanes.polite.slots[1]} />\n\t\t\t<Slot urgency=\"assertive\" announcements={lanes.assertive.slots[0]} />\n\t\t\t<Slot urgency=\"assertive\" announcements={lanes.assertive.slots[1]} />\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;AAuB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eAAe,EAAM,OAAO,MAAM;GAAK,CAAA;GAC9D,kBAAC,GAAD;IAAM,SAAQ;IAAY,eAAe,EAAM,UAAU,MAAM;GAAK,CAAA;GACpE,kBAAC,GAAD;IAAM,SAAQ;IAAY,eAAe,EAAM,UAAU,MAAM;GAAK,CAAA;EAChE;;AAEP"}
@@ -33,16 +33,19 @@ export interface ToastContainerProps {
33
33
  * take it off the queue when `onExited` reports it.
34
34
  *
35
35
  * No region renders while the queue is empty, so it does not sit in the
36
- * accessibility tree between notifications. The anchor it renders into stays
37
- * mounted regardless, carrying `data-react-aria-top-layer`: React Aria reads that
38
- * attribute to decide what an open overlay hides, what a press outside an overlay
39
- * counts as, and what a focus scope lets go. An anchor that came and went with the
40
- * toasts would leave the consumer's chrome hidden, and a toast raised afterwards
41
- * would mount inside that hidden subtree and never be announced.
36
+ * accessibility tree between notifications. A region that mounts with its text
37
+ * is not spoken, so the anchor holds live regions from its first render and
38
+ * speaks each toast through them. The anchor stays mounted regardless, carrying
39
+ * `data-react-aria-top-layer`: React Aria reads that attribute to decide what an
40
+ * open overlay hides, what a press outside an overlay counts as, and what a focus
41
+ * scope lets go. An anchor that came and went with the toasts would leave the
42
+ * consumer's chrome hidden, and a toast raised afterwards would mount inside that
43
+ * hidden subtree and never be announced.
42
44
  *
43
45
  * That exemption is why no region renders while a modal overlay is open. The
44
46
  * region is anchored in the consumer's chrome, which the overlay paints over and
45
- * seals off from the pointer, so a toast there would be announced and F6-reachable
46
- * with a dismiss control nobody could press.
47
+ * seals off from the pointer, so a toast there would be reachable with F6 and
48
+ * offer a dismiss control nobody could press. The anchor's live regions still
49
+ * speak a toast raised under the overlay.
47
50
  */
48
51
  export declare function ToastContainer({ queue, exiting, onExited, onDismiss, className, style, ref, "aria-label": ariaLabel, }: ToastContainerProps): import("react/jsx-runtime").JSX.Element;
@@ -3,91 +3,86 @@ import { useEnterAnimation as t, useExitAnimation as n } from "../../utils/anima
3
3
  import { useHasOpenOverlay as r } from "../../hooks/overlayRegistry.js";
4
4
  import { toastAnchor as i, toastCard as a } from "./Toast.css.js";
5
5
  import { Toast as o } from "./Toast.js";
6
- import { jsx as s } from "react/jsx-runtime";
7
- import { ButtonContext as c, TextContext as l, UNSTABLE_Toast as u, UNSTABLE_ToastList as d, UNSTABLE_ToastRegion as f, useSlottedContext as p } from "react-aria-components";
8
- import { useCallback as m, useEffect as h, useLayoutEffect as g, useRef as _, useState as v } from "react";
9
- import { UNSAFE_PortalProvider as y, useFocusVisible as b } from "react-aria";
6
+ import { ToastAnnouncer as s } from "./ToastAnnouncer.js";
7
+ import { jsx as c, jsxs as l } from "react/jsx-runtime";
8
+ import { ButtonContext as u, TextContext as d, UNSTABLE_Toast as f, UNSTABLE_ToastList as p, UNSTABLE_ToastRegion as m, useSlottedContext as h } from "react-aria-components";
9
+ import { useCallback as g, useEffect as _, useLayoutEffect as v, useRef as y, useState as b } from "react";
10
+ import { UNSAFE_PortalProvider as x, useFocusVisible as S } from "react-aria";
10
11
  //#region src/components/Toast/ToastContainer.tsx
11
- function x({ status: e, icon: t, message: n, isExiting: r, onPress: i }) {
12
- let a = p(c, "close"), u = p(l, "title"), [d, f] = v(!1);
13
- return g(() => f(!0), []), /* @__PURE__ */ s(o, {
12
+ function C({ status: e, icon: t, message: n, isExiting: r, onPress: i }) {
13
+ let a = h(u, "close"), s = h(d, "title");
14
+ return /* @__PURE__ */ c(o, {
14
15
  status: e,
15
16
  icon: t,
16
17
  onDismiss: i,
17
18
  dismissDisabled: r,
18
19
  dismissLabel: a?.["aria-label"],
19
- messageProps: {
20
- id: u && "id" in u ? u.id : void 0,
21
- role: e === "error" ? "alert" : "status",
22
- "aria-live": e === "error" ? "assertive" : "polite",
23
- "aria-atomic": "true",
24
- "aria-hidden": d ? void 0 : "true"
25
- },
20
+ messageProps: { id: s && "id" in s ? s.id : void 0 },
26
21
  children: n
27
22
  });
28
23
  }
29
- function S(e) {
30
- let t = e.closest("[role=\"region\"]"), n = [...t?.querySelectorAll("._1699160d") ?? []], r = n.indexOf(e);
24
+ function w(e) {
25
+ let t = e.closest("[role=\"region\"]"), n = [...t?.querySelectorAll("._1699160e") ?? []], r = n.indexOf(e);
31
26
  if (r === -1) return t;
32
27
  let i = (e) => !e.hasAttribute("data-exiting");
33
28
  return n.slice(0, r).reverse().find(i) ?? n.slice(r + 1).find(i) ?? t;
34
29
  }
35
- function C({ toast: e, isExiting: r, onExited: i, onDismiss: o }) {
36
- let c = _(null), l = t(c), d = n(c, !r), { isFocusVisible: f } = b();
37
- h(() => {
38
- r && !d && i(e.key);
30
+ function T({ toast: e, isExiting: r, onExited: i, onDismiss: o }) {
31
+ let s = y(null), l = t(s), u = n(s, !r), { isFocusVisible: d } = S();
32
+ _(() => {
33
+ r && !u && i(e.key);
39
34
  }, [
40
35
  r,
41
- d,
36
+ u,
42
37
  i,
43
38
  e.key
44
- ]), g(() => {
45
- let e = c.current;
46
- !r || !e || !f || e.contains(document.activeElement) && S(e)?.focus();
47
- }, [r, f]), g(() => {
48
- let e = c.current;
39
+ ]), v(() => {
40
+ let e = s.current;
41
+ !r || !e || !d || e.contains(document.activeElement) && w(e)?.focus();
42
+ }, [r, d]), v(() => {
43
+ let e = s.current;
49
44
  !r || !e || (e.setAttribute("inert", ""), e.setAttribute("aria-hidden", "true"), e.tabIndex = -1, e.removeAttribute("role"));
50
45
  }, [r]);
51
- let { status: p = "success", message: m, icon: v } = e.content;
52
- return /* @__PURE__ */ s(u, {
46
+ let { status: p = "success", message: m, icon: h } = e.content;
47
+ return /* @__PURE__ */ c(f, {
53
48
  toast: e,
54
- ref: c,
49
+ ref: s,
55
50
  className: a,
56
51
  "data-entering": l || void 0,
57
52
  "data-exiting": r || void 0,
58
- children: /* @__PURE__ */ s(x, {
53
+ children: /* @__PURE__ */ c(C, {
59
54
  status: p,
60
- icon: v,
55
+ icon: h,
61
56
  message: m,
62
57
  isExiting: r,
63
58
  onPress: (t) => {
64
59
  if (t.pointerType === "keyboard") {
65
- let e = c.current;
66
- e?.contains(document.activeElement) && S(e)?.focus();
60
+ let e = s.current;
61
+ e?.contains(document.activeElement) && w(e)?.focus();
67
62
  }
68
63
  o(e.key);
69
64
  }
70
65
  })
71
66
  });
72
67
  }
73
- function w({ queue: t, exiting: n, onExited: a, onDismiss: o, className: c, style: l, ref: u, "aria-label": p }) {
74
- let [h, g] = v(null), _ = r(), b = m((e) => {
75
- g(e), typeof u == "function" ? u(e) : u && (u.current = e);
76
- }, [u]), x = m(() => h ?? document.body, [h]);
77
- return /* @__PURE__ */ s("div", {
68
+ function E({ queue: t, exiting: n, onExited: a, onDismiss: o, className: u, style: d, ref: f, "aria-label": h }) {
69
+ let [_, v] = b(null), y = r(), S = g((e) => {
70
+ v(e), typeof f == "function" ? f(e) : f && (f.current = e);
71
+ }, [f]), C = g(() => _ ?? document.body, [_]);
72
+ return /* @__PURE__ */ l("div", {
78
73
  "data-react-aria-top-layer": "true",
79
- ref: b,
80
- className: e(i, c),
81
- style: l,
82
- children: h && !_ && /* @__PURE__ */ s(y, {
83
- getContainer: x,
84
- children: /* @__PURE__ */ s(f, {
74
+ ref: S,
75
+ className: e(i, u),
76
+ style: d,
77
+ children: [/* @__PURE__ */ c(s, { queue: t }), _ && !y && /* @__PURE__ */ c(x, {
78
+ getContainer: C,
79
+ children: /* @__PURE__ */ c(m, {
85
80
  queue: t,
86
- "aria-label": p,
87
- className: "_1699160b",
88
- children: /* @__PURE__ */ s(d, {
89
- className: "_1699160c",
90
- children: ({ toast: e }) => /* @__PURE__ */ s(C, {
81
+ "aria-label": h,
82
+ className: "_1699160c",
83
+ children: /* @__PURE__ */ c(p, {
84
+ className: "_1699160d",
85
+ children: ({ toast: e }) => /* @__PURE__ */ c(T, {
91
86
  toast: e,
92
87
  isExiting: n.has(e.key),
93
88
  onExited: a,
@@ -95,10 +90,10 @@ function w({ queue: t, exiting: n, onExited: a, onDismiss: o, className: c, styl
95
90
  })
96
91
  })
97
92
  })
98
- })
93
+ })]
99
94
  });
100
95
  }
101
96
  //#endregion
102
- export { w as ToastContainer };
97
+ export { E as ToastContainer };
103
98
 
104
99
  //# sourceMappingURL=ToastContainer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ToastContainer.js","names":[],"sources":["../../../src/components/Toast/ToastContainer.tsx"],"sourcesContent":["import type { CSSProperties, Ref } from \"react\";\nimport {\n\tuseCallback,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseRef,\n\tuseState,\n} from \"react\";\nimport type { PressEvent } from \"react-aria\";\nimport { UNSAFE_PortalProvider, useFocusVisible } from \"react-aria\";\nimport {\n\tButtonContext,\n\tTextContext,\n\tUNSTABLE_Toast,\n\tUNSTABLE_ToastList,\n\tUNSTABLE_ToastRegion,\n\tuseSlottedContext,\n} from \"react-aria-components\";\nimport type { QueuedToast, ToastQueue } from \"react-stately\";\nimport { useHasOpenOverlay } from \"../../hooks/overlayRegistry.js\";\nimport { useEnterAnimation, useExitAnimation } from \"../../utils/animation.js\";\nimport { cx } from \"../../utils/cx.js\";\nimport { toastAnchor, toastCard, toastList, toastRegion } from \"./Toast.css.js\";\nimport { Toast } from \"./Toast.js\";\nimport type { ToastItem } from \"./ToastItem.js\";\n\nexport interface ToastContainerProps {\n\t/** The queue to display. Create one per surface with `new ToastQueue()`. */\n\tqueue: ToastQueue<ToastItem>;\n\t/**\n\t * Keys of the toasts that are leaving. Keep each one on the queue until\n\t * `onExited` reports it, or it unmounts part-way through its travel.\n\t */\n\texiting: ReadonlySet<string>;\n\t/** Runs when a leaving toast finishes its travel and can be closed. */\n\tonExited: (key: string) => void;\n\t/** Runs when the reader presses a toast's dismiss button. */\n\tonDismiss: (key: string) => void;\n\t/**\n\t * Overrides the region's accessible name. Leave it unset: the default is\n\t * already localized and counts the toasts on show (\"2 notifications.\"), which\n\t * is what a screen-reader user hears on navigating here with F6.\n\t */\n\t\"aria-label\"?: string;\n\tclassName?: string;\n\tstyle?: CSSProperties;\n\t/** Attaches to the always-mounted anchor, not the region. */\n\tref?: Ref<HTMLDivElement>;\n}\n\ninterface ToastCardProps {\n\ttoast: QueuedToast<ToastItem>;\n\tisExiting: boolean;\n\tonExited: (key: string) => void;\n\tonDismiss: (key: string) => void;\n}\n\n/**\n * The card's own dismiss control, named from the one React Aria would have\n * rendered.\n *\n * React Aria hands its close button down through `ButtonContext` under a `close`\n * slot, carrying both the localized name and a press handler that closes the\n * toast outright. `mergeProps` chains `on*` handlers rather than replacing them,\n * so a React Aria button given the container's handler would run both and take\n * the card off the queue before it could travel. Taking the name alone leaves the\n * lifetime with the caller.\n */\nfunction ToastDismiss({\n\tstatus,\n\ticon,\n\tmessage,\n\tisExiting,\n\tonPress,\n}: {\n\tstatus: NonNullable<ToastItem[\"status\"]>;\n\ticon: ToastItem[\"icon\"];\n\tmessage: ToastItem[\"message\"];\n\tisExiting: boolean;\n\tonPress: (event: PressEvent) => void;\n}) {\n\tconst closeButton = useSlottedContext(ButtonContext, \"close\");\n\t// React Aria names the card through `aria-labelledby`, pointing at the id it\n\t// hands down under the `title` slot. Nothing here renders its `Text`, so the\n\t// message has to carry that id or the card has no accessible name at all.\n\tconst title = useSlottedContext(TextContext, \"title\");\n\t// React Aria hides its own content element on the first render and reveals it\n\t// on the next, which is what makes NVDA announce a toast that mounts with its\n\t// text already in place. Those props reach that element through a context the\n\t// package does not export, so the reveal is repeated here.\n\tconst [isRevealed, setIsRevealed] = useState(false);\n\tuseLayoutEffect(() => setIsRevealed(true), []);\n\treturn (\n\t\t<Toast\n\t\t\tstatus={status}\n\t\t\ticon={icon}\n\t\t\tonDismiss={onPress}\n\t\t\t// The card carries `inert` by now, but WebKit added `inert` in 15.5,\n\t\t\t// after the iOS 15.4 floor in `messaging/vite.browser-targets.mjs`. At\n\t\t\t// that floor the button stays tabbable and offers a press that no longer\n\t\t\t// acts on anything, so it has to be disabled in its own right.\n\t\t\tdismissDisabled={isExiting}\n\t\t\tdismissLabel={closeButton?.[\"aria-label\"]}\n\t\t\t// The live region rides the message box itself. React Aria's own\n\t\t\t// `ToastContent` would need `display: contents` to stay out of the card's\n\t\t\t// row, and WebKit drops a box-less element from the accessibility tree\n\t\t\t// until 16, below the floor above, so the announcement would never reach\n\t\t\t// the reader there.\n\t\t\tmessageProps={{\n\t\t\t\tid: title && \"id\" in title ? title.id : undefined,\n\t\t\t\t// React Aria hardcodes `role=\"alert\"` for every toast, which interrupts\n\t\t\t\t// the reader whatever the outcome. The queue is one shared surface, so\n\t\t\t\t// urgency is chosen per card: a failure interrupts, anything else waits\n\t\t\t\t// its turn.\n\t\t\t\trole: status === \"error\" ? \"alert\" : \"status\",\n\t\t\t\t\"aria-live\": status === \"error\" ? \"assertive\" : \"polite\",\n\t\t\t\t\"aria-atomic\": \"true\",\n\t\t\t\t\"aria-hidden\": isRevealed ? undefined : \"true\",\n\t\t\t}}\n\t\t>\n\t\t\t{message}\n\t\t</Toast>\n\t);\n}\n\n/**\n * Where focus goes when the card under it leaves: the next card down the stack,\n * then the one above it, then the region itself. Landing on the region keeps\n * focus inside it, so React Aria still holds the element the reader came from and\n * restores it once the last card has gone.\n */\nfunction nextFocusTarget(element: HTMLElement): HTMLElement | null {\n\tconst region = element.closest<HTMLElement>('[role=\"region\"]');\n\t// React Aria wraps each card in a list item of its own, so the cards are read\n\t// off the region rather than from the element's own parent.\n\tconst cards = [\n\t\t...(region?.querySelectorAll<HTMLElement>(`.${toastCard}`) ?? []),\n\t];\n\tconst index = cards.indexOf(element);\n\tif (index === -1) {\n\t\treturn region;\n\t}\n\tconst settled = (card: HTMLElement) => !card.hasAttribute(\"data-exiting\");\n\t// `toastList` is `column-reverse`, so a higher DOM index sits visually above\n\t// and a lower one below. Take the card below first, nearest first, then walk\n\t// up, so focus lands on the card that rises into the freed row.\n\treturn (\n\t\tcards.slice(0, index).reverse().find(settled) ??\n\t\tcards.slice(index + 1).find(settled) ??\n\t\tregion\n\t);\n}\n\nfunction ToastCard({ toast, isExiting, onExited, onDismiss }: ToastCardProps) {\n\tconst ref = useRef<HTMLDivElement>(null);\n\t// The card rises in from `[data-entering]` and falls back out to\n\t// `[data-exiting]`, both off-screen, with a transition between. A transition\n\t// resumes from the current computed value, so a card dismissed mid-entry\n\t// reverses from wherever it stands. `useExitAnimation` and `useEnterAnimation`\n\t// watch the same transition, the way `BannerContainerSlide` does.\n\tconst isEntering = useEnterAnimation(ref);\n\tconst isLeaving = useExitAnimation(ref, !isExiting);\n\tconst { isFocusVisible } = useFocusVisible();\n\n\tuseEffect(() => {\n\t\tif (isExiting && !isLeaving) {\n\t\t\tonExited(toast.key);\n\t\t}\n\t}, [isExiting, isLeaving, onExited, toast.key]);\n\n\t// `inert` below drops the focus it holds to the document body. React Aria moves\n\t// focus for a toast that leaves the queue, and the card stays on the queue until\n\t// its travel is over, so the reader is handed on from here instead. It runs\n\t// before the effect below, which is what leaves it a card to read focus off.\n\t//\n\t// Only for a reader working the keyboard, though. A dismiss button focuses\n\t// itself under a mouse press in Chrome, so handing that on would park an\n\t// invisible focus on the card left standing, and a consumer that reads focus as\n\t// the reader asking for more time would hold its countdown there for as long as\n\t// the reader left the page alone.\n\tuseLayoutEffect(() => {\n\t\tconst element = ref.current;\n\t\tif (!isExiting || !element || !isFocusVisible) {\n\t\t\treturn;\n\t\t}\n\t\tif (element.contains(document.activeElement)) {\n\t\t\tnextFocusTarget(element)?.focus();\n\t\t}\n\t}, [isExiting, isFocusVisible]);\n\n\t// The caller has already let the card go, so it is on screen only to finish its\n\t// travel. `inert` takes it out of the accessibility tree, out of the tab order\n\t// and away from the pointer in one attribute. WebKit added `inert` in 15.5, and\n\t// the floor in `messaging/vite.browser-targets.mjs` is 15.4, so `role` and\n\t// `tabIndex` come off the element as well. React Aria pins both through props,\n\t// and a card never comes back from leaving, so nothing puts them back.\n\tuseLayoutEffect(() => {\n\t\tconst element = ref.current;\n\t\tif (!isExiting || !element) {\n\t\t\treturn;\n\t\t}\n\t\telement.setAttribute(\"inert\", \"\");\n\t\t// At the 15.4 floor `inert` does nothing, so the card would keep announcing\n\t\t// and stay in the reader's tree for the whole of its travel.\n\t\telement.setAttribute(\"aria-hidden\", \"true\");\n\t\telement.tabIndex = -1;\n\t\telement.removeAttribute(\"role\");\n\t}, [isExiting]);\n\n\tconst { status = \"success\", message, icon } = toast.content;\n\n\treturn (\n\t\t<UNSTABLE_Toast\n\t\t\ttoast={toast}\n\t\t\tref={ref}\n\t\t\tclassName={toastCard}\n\t\t\tdata-entering={isEntering || undefined}\n\t\t\tdata-exiting={isExiting || undefined}\n\t\t>\n\t\t\t<ToastDismiss\n\t\t\t\tstatus={status}\n\t\t\t\ticon={icon}\n\t\t\t\tmessage={message}\n\t\t\t\tisExiting={isExiting}\n\t\t\t\tonPress={(event) => {\n\t\t\t\t\t// The exit re-render disables this button, and a native disabled\n\t\t\t\t\t// button drops its focus to the document body in the same commit,\n\t\t\t\t\t// before the layout effect below can read focus off the card. Hand a\n\t\t\t\t\t// keyboard reader on here, while the button still holds focus.\n\t\t\t\t\tif (event.pointerType === \"keyboard\") {\n\t\t\t\t\t\tconst element = ref.current;\n\t\t\t\t\t\tif (element?.contains(document.activeElement)) {\n\t\t\t\t\t\t\tnextFocusTarget(element)?.focus();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tonDismiss(toast.key);\n\t\t\t\t}}\n\t\t\t/>\n\t\t</UNSTABLE_Toast>\n\t);\n}\n\n/**\n * Displays the toasts on a queue as a labelled landmark region.\n *\n * The container owns announcement, the card surface and the motion. It does not\n * own the clock: the caller decides which toasts exist, when each one leaves, and\n * what a dismiss press means. Mark a toast in `exiting` to start its travel, and\n * take it off the queue when `onExited` reports it.\n *\n * No region renders while the queue is empty, so it does not sit in the\n * accessibility tree between notifications. The anchor it renders into stays\n * mounted regardless, carrying `data-react-aria-top-layer`: React Aria reads that\n * attribute to decide what an open overlay hides, what a press outside an overlay\n * counts as, and what a focus scope lets go. An anchor that came and went with the\n * toasts would leave the consumer's chrome hidden, and a toast raised afterwards\n * would mount inside that hidden subtree and never be announced.\n *\n * That exemption is why no region renders while a modal overlay is open. The\n * region is anchored in the consumer's chrome, which the overlay paints over and\n * seals off from the pointer, so a toast there would be announced and F6-reachable\n * with a dismiss control nobody could press.\n */\nexport function ToastContainer({\n\tqueue,\n\texiting,\n\tonExited,\n\tonDismiss,\n\tclassName,\n\tstyle,\n\tref,\n\t\"aria-label\": ariaLabel,\n}: ToastContainerProps) {\n\tconst [anchor, setAnchor] = useState<HTMLDivElement | null>(null);\n\tconst hasOpenOverlay = useHasOpenOverlay();\n\n\tconst attachAnchor = useCallback(\n\t\t(node: HTMLDivElement | null) => {\n\t\t\tsetAnchor(node);\n\t\t\tif (typeof ref === \"function\") {\n\t\t\t\tref(node);\n\t\t\t} else if (ref) {\n\t\t\t\tref.current = node;\n\t\t\t}\n\t\t},\n\t\t[ref],\n\t);\n\n\t// React Aria's region portals itself through whatever `UNSAFE_PortalProvider`\n\t// it finds, and a consumer that scopes one to its app root would take the\n\t// toasts out of this container entirely. Pointing a nested provider at the\n\t// anchor keeps them where the consumer placed them.\n\tconst getContainer = useCallback(() => anchor ?? document.body, [anchor]);\n\n\treturn (\n\t\t<div\n\t\t\tdata-react-aria-top-layer=\"true\"\n\t\t\tref={attachAnchor}\n\t\t\tclassName={cx(toastAnchor, className)}\n\t\t\tstyle={style}\n\t\t>\n\t\t\t{anchor && !hasOpenOverlay && (\n\t\t\t\t<UNSAFE_PortalProvider getContainer={getContainer}>\n\t\t\t\t\t<UNSTABLE_ToastRegion\n\t\t\t\t\t\tqueue={queue}\n\t\t\t\t\t\taria-label={ariaLabel}\n\t\t\t\t\t\tclassName={toastRegion}\n\t\t\t\t\t>\n\t\t\t\t\t\t<UNSTABLE_ToastList<ToastItem> className={toastList}>\n\t\t\t\t\t\t\t{({ toast }) => (\n\t\t\t\t\t\t\t\t<ToastCard\n\t\t\t\t\t\t\t\t\ttoast={toast}\n\t\t\t\t\t\t\t\t\tisExiting={exiting.has(toast.key)}\n\t\t\t\t\t\t\t\t\tonExited={onExited}\n\t\t\t\t\t\t\t\t\tonDismiss={onD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CAAC,CAAM,CAAC;CAExE,OACC,kBAAC,OAAD;EACC,6BAA0B;EAC1B,KAAK;EACL,WAAW,EAAG,GAAa,CAAS;EAC7B;YAEN,KAAU,CAAC,KACX,kBAAC,GAAD;GAAqC;aACpC,kBAAC,GAAD;IACQ;IACP,cAAY;IACZ,WAAA;cAEA,kBAAC,GAAD;KAA+B,WAAA;gBAC5B,EAAE,eACH,kBAAC,GAAD;MACQ;MACP,WAAW,EAAQ,IAAI,EAAM,GAAG;MACtB;MACC;KACX,CAAA;IAEiB,CAAA;GACC,CAAA;EACA,CAAA;CAEpB,CAAA;AAEP"}
1
+ {"version":3,"file":"ToastContainer.js","names":[],"sources":["../../../src/components/Toast/ToastContainer.tsx"],"sourcesContent":["import type { CSSProperties, Ref } from \"react\";\nimport {\n\tuseCallback,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseRef,\n\tuseState,\n} from \"react\";\nimport type { PressEvent } from \"react-aria\";\nimport { UNSAFE_PortalProvider, useFocusVisible } from \"react-aria\";\nimport {\n\tButtonContext,\n\tTextContext,\n\tUNSTABLE_Toast,\n\tUNSTABLE_ToastList,\n\tUNSTABLE_ToastRegion,\n\tuseSlottedContext,\n} from \"react-aria-components\";\nimport type { QueuedToast, ToastQueue } from \"react-stately\";\nimport { useHasOpenOverlay } from \"../../hooks/overlayRegistry.js\";\nimport { useEnterAnimation, useExitAnimation } from \"../../utils/animation.js\";\nimport { cx } from \"../../utils/cx.js\";\nimport { toastAnchor, toastCard, toastList, toastRegion } from \"./Toast.css.js\";\nimport { Toast } from \"./Toast.js\";\nimport { ToastAnnouncer } from \"./ToastAnnouncer.js\";\nimport type { ToastItem } from \"./ToastItem.js\";\n\nexport interface ToastContainerProps {\n\t/** The queue to display. Create one per surface with `new ToastQueue()`. */\n\tqueue: ToastQueue<ToastItem>;\n\t/**\n\t * Keys of the toasts that are leaving. Keep each one on the queue until\n\t * `onExited` reports it, or it unmounts part-way through its travel.\n\t */\n\texiting: ReadonlySet<string>;\n\t/** Runs when a leaving toast finishes its travel and can be closed. */\n\tonExited: (key: string) => void;\n\t/** Runs when the reader presses a toast's dismiss button. */\n\tonDismiss: (key: string) => void;\n\t/**\n\t * Overrides the region's accessible name. Leave it unset: the default is\n\t * already localized and counts the toasts on show (\"2 notifications.\"), which\n\t * is what a screen-reader user hears on navigating here with F6.\n\t */\n\t\"aria-label\"?: string;\n\tclassName?: string;\n\tstyle?: CSSProperties;\n\t/** Attaches to the always-mounted anchor, not the region. */\n\tref?: Ref<HTMLDivElement>;\n}\n\ninterface ToastCardProps {\n\ttoast: QueuedToast<ToastItem>;\n\tisExiting: boolean;\n\tonExited: (key: string) => void;\n\tonDismiss: (key: string) => void;\n}\n\n/**\n * The card's own dismiss control, named from the one React Aria would have\n * rendered.\n *\n * React Aria hands its close button down through `ButtonContext` under a `close`\n * slot, carrying both the localized name and a press handler that closes the\n * toast outright. `mergeProps` chains `on*` handlers rather than replacing them,\n * so a React Aria button given the container's handler would run both and take\n * the card off the queue before it could travel. Taking the name alone leaves the\n * lifetime with the caller.\n */\nfunction ToastDismiss({\n\tstatus,\n\ticon,\n\tmessage,\n\tisExiting,\n\tonPress,\n}: {\n\tstatus: NonNullable<ToastItem[\"status\"]>;\n\ticon: ToastItem[\"icon\"];\n\tmessage: ToastItem[\"message\"];\n\tisExiting: boolean;\n\tonPress: (event: PressEvent) => void;\n}) {\n\tconst closeButton = useSlottedContext(ButtonContext, \"close\");\n\t// React Aria names the card through `aria-labelledby`, pointing at the id it\n\t// hands down under the `title` slot. Nothing here renders its `Text`, so the\n\t// message has to carry that id or the card has no accessible name at all.\n\tconst title = useSlottedContext(TextContext, \"title\");\n\treturn (\n\t\t<Toast\n\t\t\tstatus={status}\n\t\t\ticon={icon}\n\t\t\tonDismiss={onPress}\n\t\t\t// The card carries `inert` by now, but WebKit added `inert` in 15.5,\n\t\t\t// after the iOS 15.4 floor in `messaging/vite.browser-targets.mjs`. At\n\t\t\t// that floor the button stays tabbable and offers a press that no longer\n\t\t\t// acts on anything, so it has to be disabled in its own right.\n\t\t\tdismissDisabled={isExiting}\n\t\t\tdismissLabel={closeButton?.[\"aria-label\"]}\n\t\t\t// No live region here: the message mounts with its text, so a reader\n\t\t\t// would not speak it. `ToastAnnouncer` speaks it instead.\n\t\t\tmessageProps={{\n\t\t\t\tid: title && \"id\" in title ? title.id : undefined,\n\t\t\t}}\n\t\t>\n\t\t\t{message}\n\t\t</Toast>\n\t);\n}\n\n/**\n * Where focus goes when the card under it leaves: the next card down the stack,\n * then the one above it, then the region itself. Landing on the region keeps\n * focus inside it, so React Aria still holds the element the reader came from and\n * restores it once the last card has gone.\n */\nfunction nextFocusTarget(element: HTMLElement): HTMLElement | null {\n\tconst region = element.closest<HTMLElement>('[role=\"region\"]');\n\t// React Aria wraps each card in a list item of its own, so the cards are read\n\t// off the region rather than from the element's own parent.\n\tconst cards = [\n\t\t...(region?.querySelectorAll<HTMLElement>(`.${toastCard}`) ?? []),\n\t];\n\tconst index = cards.indexOf(element);\n\tif (index === -1) {\n\t\treturn region;\n\t}\n\tconst settled = (card: HTMLElement) => !card.hasAttribute(\"data-exiting\");\n\t// `toastList` is `column-reverse`, so a higher DOM index sits visually above\n\t// and a lower one below. Take the card below first, nearest first, then walk\n\t// up, so focus lands on the card that rises into the freed row.\n\treturn (\n\t\tcards.slice(0, index).reverse().find(settled) ??\n\t\tcards.slice(index + 1).find(settled) ??\n\t\tregion\n\t);\n}\n\nfunction ToastCard({ toast, isExiting, onExited, onDismiss }: ToastCardProps) {\n\tconst ref = useRef<HTMLDivElement>(null);\n\t// The card rises in from `[data-entering]` and falls back out to\n\t// `[data-exiting]`, both off-screen, with a transition between. A transition\n\t// resumes from the current computed value, so a card dismissed mid-entry\n\t// reverses from wherever it stands. `useExitAnimation` and `useEnterAnimation`\n\t// watch the same transition, the way `BannerContainerSlide` does.\n\tconst isEntering = useEnterAnimation(ref);\n\tconst isLeaving = useExitAnimation(ref, !isExiting);\n\tconst { isFocusVisible } = useFocusVisible();\n\n\tuseEffect(() => {\n\t\tif (isExiting && !isLeaving) {\n\t\t\tonExited(toast.key);\n\t\t}\n\t}, [isExiting, isLeaving, onExited, toast.key]);\n\n\t// `inert` below drops the focus it holds to the document body. React Aria moves\n\t// focus for a toast that leaves the queue, and the card stays on the queue until\n\t// its travel is over, so the reader is handed on from here instead. It runs\n\t// before the effect below, which is what leaves it a card to read focus off.\n\t//\n\t// Only for a reader working the keyboard, though. A dismiss button focuses\n\t// itself under a mouse press in Chrome, so handing that on would park an\n\t// invisible focus on the card left standing, and a consumer that reads focus as\n\t// the reader asking for more time would hold its countdown there for as long as\n\t// the reader left the page alone.\n\tuseLayoutEffect(() => {\n\t\tconst element = ref.current;\n\t\tif (!isExiting || !element || !isFocusVisible) {\n\t\t\treturn;\n\t\t}\n\t\tif (element.contains(document.activeElement)) {\n\t\t\tnextFocusTarget(element)?.focus();\n\t\t}\n\t}, [isExiting, isFocusVisible]);\n\n\t// The caller has already let the card go, so it is on screen only to finish its\n\t// travel. `inert` takes it out of the accessibility tree, out of the tab order\n\t// and away from the pointer in one attribute. WebKit added `inert` in 15.5, and\n\t// the floor in `messaging/vite.browser-targets.mjs` is 15.4, so `role` and\n\t// `tabIndex` come off the element as well. React Aria pins both through props,\n\t// and a card never comes back from leaving, so nothing puts them back.\n\tuseLayoutEffect(() => {\n\t\tconst element = ref.current;\n\t\tif (!isExiting || !element) {\n\t\t\treturn;\n\t\t}\n\t\telement.setAttribute(\"inert\", \"\");\n\t\t// At the 15.4 floor `inert` does nothing, so the card would stay in the\n\t\t// reader's tree for the whole of its travel.\n\t\telement.setAttribute(\"aria-hidden\", \"true\");\n\t\telement.tabIndex = -1;\n\t\telement.removeAttribute(\"role\");\n\t}, [isExiting]);\n\n\tconst { status = \"success\", message, icon } = toast.content;\n\n\treturn (\n\t\t<UNSTABLE_Toast\n\t\t\ttoast={toast}\n\t\t\tref={ref}\n\t\t\tclassName={toastCard}\n\t\t\tdata-entering={isEntering || undefined}\n\t\t\tdata-exiting={isExiting || undefined}\n\t\t>\n\t\t\t<ToastDismiss\n\t\t\t\tstatus={status}\n\t\t\t\ticon={icon}\n\t\t\t\tmessage={message}\n\t\t\t\tisExiting={isExiting}\n\t\t\t\tonPress={(event) => {\n\t\t\t\t\t// The exit re-render disables this button, and a native disabled\n\t\t\t\t\t// button drops its focus to the document body in the same commit,\n\t\t\t\t\t// before the layout effect below can read focus off the card. Hand a\n\t\t\t\t\t// keyboard reader on here, while the button still holds focus.\n\t\t\t\t\tif (event.pointerType === \"keyboard\") {\n\t\t\t\t\t\tconst element = ref.current;\n\t\t\t\t\t\tif (element?.contains(document.activeElement)) {\n\t\t\t\t\t\t\tnextFocusTarget(element)?.focus();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tonDismiss(toast.key);\n\t\t\t\t}}\n\t\t\t/>\n\t\t</UNSTABLE_Toast>\n\t);\n}\n\n/**\n * Displays the toasts on a queue as a labelled landmark region.\n *\n * The container owns announcement, the card surface and the motion. It does not\n * own the clock: the caller decides which toasts exist, when each one leaves, and\n * what a dismiss press means. Mark a toast in `exiting` to start its travel, and\n * take it off the queue when `onExited` reports it.\n *\n * No region renders while the queue is empty, so it does not sit in the\n * accessibility tree between notifications. A region that mounts with its text\n * is not spoken, so the anchor holds live regions from its first render and\n * speaks each toast through them. The anchor stays mounted regardless, carrying\n * `data-react-aria-top-layer`: React Aria reads that attribute to decide what an\n * open overlay hides, what a press outside an overlay counts as, and what a focus\n * scope lets go. An anchor that came and went with the toasts would leave the\n * consumer's chrome hidden, and a toast raised afterwards would mount inside that\n * hidden subtree and never be announced.\n *\n * That exemption is why no region renders while a modal overlay is open. The\n * region is anchored in the consumer's chrome, which the overlay paints over and\n * seals off from the pointer, so a toast there would be reachable with F6 and\n * offer a dismiss control nobody could press. The anchor's live regions still\n * speak a toast raised under the overlay.\n */\nexport function ToastContainer({\n\tqueue,\n\texiting,\n\tonExited,\n\tonDismiss,\n\tclassName,\n\tstyle,\n\tref,\n\t\"aria-label\": ariaLabel,\n}: ToastContainerProps) {\n\tconst [anchor, setAnchor] = useState<HTMLDivElement | null>(null);\n\tconst hasOpenOverlay = useHasOpenOverlay();\n\n\tconst attachAnchor = useCallback(\n\t\t(node: HTMLDivElement | null) => {\n\t\t\tsetAnchor(node);\n\t\t\tif (typeof ref === \"function\") {\n\t\t\t\tref(node);\n\t\t\t} else if (ref) {\n\t\t\t\tref.current = node;\n\t\t\t}\n\t\t},\n\t\t[ref],\n\t);\n\n\t// React Aria's region portals itself through whatever `UNSAFE_PortalProvider`\n\t// it finds, and a consumer that scopes one to its app root would take the\n\t// toasts out of this container entirely. Pointing a nested provider at the\n\t// anchor keeps them where the consumer placed them.\n\tconst getContainer = useCallback(() => anchor ?? document.body, [anchor]);\n\n\treturn (\n\t\t<div\n\t\t\tdata-react-aria-top-layer=\"true\"\n\t\t\tref={attachAnchor}\n\t\t\tclassName={cx(toastAnchor, className)}\n\t\t\tstyle={style}\n\t\t>\n\t\t\t<ToastAnnouncer queue={queue} />\n\t\t\t{anchor && !hasOpenOverlay && (\n\t\t\t\t<UNSAFE_PortalProvider getContainer={getContainer}>\n\t\t\t\t\t<UNSTABLE_ToastRegion\n\t\t\t\t\t\tqueue={queue}\n\t\t\t\t\t\taria-label={ariaLabel}\n\t\t\t\t\t\tclassName={toastRegion}\n\t\t\t\t\t>\n\t\t\t\t\t\t<UNSTABLE_ToastList<ToastItem> className={toastList}>\n\t\t\t\t\t\t\t{({ toast }) => (\n\t\t\t\t\t\t\t\t<ToastCard\n\t\t\t\t\t\t\t\t\ttoast={toast}\n\t\t\t\t\t\t\t\t\tisExiting={exiting.has(toast.key)}\n\t\t\t\t\t\t\t\t\tonExited={onExited}\n\t\t\t\t\t\t\t\t\tonDismiss={onDismiss}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t</UNSTABLE_ToastList>\n\t\t\t\t\t</UNSTABLE_ToastRegion>\n\t\t\t\t</UNSAFE_PortalProv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,IAAI,EAAM,GAAG;MACtB;MACC;KACX,CAAA;IAEiB,CAAA;GACC,CAAA;EACA,CAAA,CAEpB;;AAEP"}
@@ -2,8 +2,14 @@ import type { ReactNode } from "react";
2
2
  import type { ToastStatus } from "../Toast/Toast.js";
3
3
  /** What a caller puts on the queue via `queue.add(content, options)`. */
4
4
  export interface ToastItem {
5
- /** The message to announce and display. */
5
+ /** The message to display. A string or number message is also announced. */
6
6
  message: ReactNode;
7
+ /**
8
+ * The text a screen reader speaks. Defaults to the message when it is a
9
+ * string or number. Set it for an element message, or the toast is not
10
+ * announced.
11
+ */
12
+ announcement?: string;
7
13
  /** The outcome being reported. Defaults to `success`. */
8
14
  status?: ToastStatus;
9
15
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"UserMessage.css.js","names":[],"sources":["../../../src/components/UserMessage/UserMessage.css.ts"],"sourcesContent":["import { style } from \"@vanilla-extract/css\";\nimport { t, tokenName } from \"../../tokens/index.js\";\n\nexport const userMessageBubble = style({\n\tdisplay: \"flex\",\n\t// The bubble is placed by the transcript, so it sizes to its own content\n\t// rather than filling a column it no longer owns.\n\twidth: \"fit-content\",\n\talignItems: \"center\",\n\tboxSizing: \"border-box\",\n\t// The transcript decides how wide a message may grow, so the bubble adds no\n\t// cap of its own and only stops itself overflowing whatever it is given.\n\tmaxWidth: \"100%\",\n\tpaddingInline: t(\"padding-12\"),\n\tpaddingBlock: t(\"padding-8\"),\n\tborderRadius: t(\"border-radius-message\"),\n\tbackgroundColor: t(\"message-user-background\"),\n});\n\nexport const userMessageText = style({\n\t// Body text and links here sit on the accent fill, so the prose defaults read\n\t// against the wrong background. Re-pointed, not overridden, so a component\n\t// placed in the bubble keeps its own styling.\n\tvars: {\n\t\t[tokenName(\"message-content-default\")]: t(\"message-user-content\"),\n\t\t[tokenName(\"message-content-link\")]: t(\"message-user-content\"),\n\t},\n});\n"],"mappings":""}
1
+ {"version":3,"file":"UserMessage.css.js","names":[],"sources":["../../../src/components/UserMessage/UserMessage.css.ts"],"sourcesContent":["import { style } from \"@vanilla-extract/css\";\nimport { t, tokenName } from \"../../tokens/index.js\";\n\nexport const userMessageBubble = style({\n\tdisplay: \"flex\",\n\t// The bubble is placed by the transcript, so it sizes to its own content\n\t// rather than filling a column it no longer owns.\n\twidth: \"fit-content\",\n\talignItems: \"center\",\n\tboxSizing: \"border-box\",\n\t// The transcript decides how wide a message may grow, so the bubble adds no\n\t// cap of its own and only stops itself overflowing whatever it is given.\n\tmaxWidth: \"100%\",\n\tpaddingInline: t(\"padding-12\"),\n\tpaddingBlock: t(\"padding-8\"),\n\tborderRadius: t(\"border-radius-message\"),\n\tbackgroundColor: t(\"message-user-background\"),\n});\n\nexport const userMessageText = style({\n\t// Body text and links here sit on the accent fill, so the prose defaults read\n\t// against the wrong background. The text inherits this colour, and the link\n\t// token is re-pointed rather than overridden on the anchor. A component\n\t// placed in the bubble sets its own colour, so it keeps its own styling.\n\tcolor: t(\"message-user-content\"),\n\tvars: {\n\t\t[tokenName(\"message-content-link\")]: t(\"message-user-content\"),\n\t},\n});\n"],"mappings":""}
@@ -18,6 +18,13 @@ export interface VideoMessageProps {
18
18
  aspectRatio?: VideoAspectRatio;
19
19
  /** Force the "video unavailable" placeholder (media-slash on a muted box). */
20
20
  unavailable?: boolean;
21
+ /**
22
+ * Name of the unavailable placeholder, in the language of the surrounding UI.
23
+ * Defaults to "Video unavailable". The alt text follows it after a colon.
24
+ */
25
+ unavailableLabel?: string;
26
+ /** Name of the frame when `alt` is empty, in the language of the surrounding UI. Defaults to "Video". */
27
+ groupLabel?: string;
21
28
  className?: string;
22
29
  style?: CSSProperties;
23
30
  ref?: Ref<HTMLDivElement>;
@@ -29,4 +36,4 @@ export interface VideoMessageProps {
29
36
  * `children`; when the video is unavailable — or no player is supplied — the
30
37
  * frame shows a muted media-slash placeholder instead.
31
38
  */
32
- export declare function VideoMessage({ children, alt, aspectRatio, unavailable, className, ...rest }: VideoMessageProps): import("react/jsx-runtime").JSX.Element;
39
+ export declare function VideoMessage({ children, alt, aspectRatio, unavailable, unavailableLabel: unavailableName, groupLabel, className, ...rest }: VideoMessageProps): import("react/jsx-runtime").JSX.Element;
@@ -6,20 +6,20 @@ import { Group as o } from "react-aria-components";
6
6
  import { Children as s } from "react";
7
7
  //#region src/components/VideoMessage/VideoMessage.tsx
8
8
  var c = "Video unavailable", l = "Video", u = "16:9";
9
- function d({ children: d, alt: f, aspectRatio: p = u, unavailable: m = !1, className: h, ...g }) {
10
- let _ = s.toArray(d).length > 0, v = m || !_, y = typeof f == "string" ? f.trim() : "", b = y ? `${c}: ${y}` : c;
9
+ function d({ children: d, alt: f, aspectRatio: p = u, unavailable: m = !1, unavailableLabel: h = c, groupLabel: g = l, className: _, ...v }) {
10
+ let y = s.toArray(d).length > 0, b = m || !y, x = typeof f == "string" ? f.trim() : "", S = x ? `${h}: ${x}` : h;
11
11
  return /* @__PURE__ */ a(o, {
12
- ...g,
13
- "aria-label": y || l,
12
+ ...v,
13
+ "aria-label": x || g,
14
14
  "data-aspect-ratio": p,
15
- "data-unavailable": v || void 0,
15
+ "data-unavailable": b || void 0,
16
16
  className: e(r({
17
17
  aspectRatio: p,
18
- unavailable: v
19
- }), h),
20
- children: v ? /* @__PURE__ */ a(t, {
18
+ unavailable: b
19
+ }), _),
20
+ children: b ? /* @__PURE__ */ a(t, {
21
21
  className: n,
22
- label: b
22
+ label: S
23
23
  }) : /* @__PURE__ */ a("div", {
24
24
  className: i,
25
25
  children: d
@@ -1 +1 @@
1
- {"version":3,"file":"VideoMessage.js","names":[],"sources":["../../../src/components/VideoMessage/VideoMessage.tsx"],"sourcesContent":["import type { CSSProperties, ReactNode, Ref } from \"react\";\nimport { Children } from \"react\";\nimport { Group } from \"react-aria-components\";\nimport { cx } from \"../../utils/cx.js\";\nimport { MediaSlash } from \"../Icon/icons/MediaSlash.js\";\nimport {\n\tvideoPlaceholderIcon,\n\tvideoRoot,\n\tvideoSlot,\n} from \"./VideoMessage.css.js\";\n\nexport type VideoAspectRatio = \"16:9\" | \"4:3\" | \"1:1\" | \"3:4\" | \"9:16\";\n\nexport interface VideoMessageProps {\n\t/**\n\t * The player rendered inside the frame. The shell carries no playback logic\n\t * of its own — the supplied player owns its controls, load state and error\n\t * handling; drive the placeholder through `unavailable`. When absent, the\n\t * frame shows the unavailable placeholder.\n\t */\n\tchildren?: ReactNode;\n\t/** Accessible name for the video — describe what it shows. */\n\talt: string;\n\t/**\n\t * Frame proportions — bind to the source video's proportions so it isn't\n\t * cropped. Defaults to `\"16:9\"`. The frame is context-sized (fills its\n\t * container's width); the consumer constrains it to the message column.\n\t */\n\taspectRatio?: VideoAspectRatio;\n\t/** Force the \"video unavailable\" placeholder (media-slash on a muted box). */\n\tunavailable?: boolean;\n\tclassName?: string;\n\tstyle?: CSSProperties;\n\tref?: Ref<HTMLDivElement>;\n}\n\nconst UNAVAILABLE_LABEL = \"Video unavailable\";\nconst GROUP_LABEL = \"Video\";\nconst DEFAULT_ASPECT_RATIO: VideoAspectRatio = \"16:9\";\n\n/**\n * The presentational frame for a video attachment rendered inside a chat\n * message: rounded clipping to the media-preview corner radius, a fixed aspect\n * ratio, and an accessible grouping label. The consumer supplies the player as\n * `children`; when the video is unavailable — or no player is supplied — the\n * frame shows a muted media-slash placeholder instead.\n */\nexport function VideoMessage({\n\tchildren,\n\talt,\n\taspectRatio = DEFAULT_ASPECT_RATIO,\n\tunavailable = false,\n\tclassName,\n\t...rest\n}: VideoMessageProps) {\n\t// Normalized emptiness, not a `!== false` check: a consumer gating its player\n\t// with `{ready && <Player />}` — alone or alongside siblings, where children\n\t// arrives as an array — renders nothing, and treating that as a supplied\n\t// player would leave the frame permanently empty. `Children.toArray` strips\n\t// null/undefined/booleans at any depth.\n\tconst supplied = Children.toArray(children).length > 0;\n\tconst showPlaceholder = unavailable || !supplied;\n\n\t// Lovelace can be consumed from older/untyped JavaScript even though the TS\n\t// contract requires a string, so the failure path must remain total.\n\tconst description = typeof alt === \"string\" ? alt.trim() : \"\";\n\tconst unavailableLabel = description\n\t\t? `${UNAVAILABLE_LABEL}: ${description}`\n\t\t: UNAVAILABLE_LABEL;\n\n\treturn (\n\t\t// RAC `Group` (role=\"group\"), not a bare div: `aria-label` on a generic\n\t\t// element is prohibited and assistive tech drops it (axe\n\t\t// `aria-prohibited-attr`), so a supplied player — which carries no label of\n\t\t// its own — would reach nobody.\n\t\t<Group\n\t\t\t{...rest}\n\t\t\taria-label={description || GROUP_LABEL}\n\t\t\tdata-aspect-ratio={aspectRatio}\n\t\t\tdata-unavailable={showPlaceholder || undefined}\n\t\t\tclassName={cx(\n\t\t\t\tvideoRoot({ aspectRatio, unavailable: showPlaceholder }),\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t>\n\t\t\t{showPlaceholder ? (\n\t\t\t\t<MediaSlash className={videoPlaceholderIcon} label={unavailableLabel} />\n\t\t\t) : (\n\t\t\t\t<div className={videoSlot}>{children}</div>\n\t\t\t)}\n\t\t</Group>\n\t);\n}\n"],"mappings":";;;;;;;AAoCA,IAAM,IAAoB,qBACpB,IAAc,SACd,IAAyC;AAS/C,SAAgB,EAAa,EAC5B,aACA,QACA,iBAAc,GACd,iBAAc,IACd,cACA,GAAG,KACkB;CAMrB,IAAM,IAAW,EAAS,QAAQ,CAAQ,CAAC,CAAC,SAAS,GAC/C,IAAkB,KAAe,CAAC,GAIlC,IAAc,OAAO,KAAQ,WAAW,EAAI,KAAK,IAAI,IACrD,IAAmB,IACtB,GAAG,EAAkB,IAAI,MACzB;CAEH,OAKC,kBAAC,GAAD;EACC,GAAI;EACJ,cAAY,KAAe;EAC3B,qBAAmB;EACnB,oBAAkB,KAAmB,KAAA;EACrC,WAAW,EACV,EAAU;GAAE;GAAa,aAAa;EAAgB,CAAC,GACvD,CACD;YAEC,IACA,kBAAC,GAAD;GAAY,WAAW;GAAsB,OAAO;EAAmB,CAAA,IAEvE,kBAAC,OAAD;GAAK,WAAW;GAAY;EAAc,CAAA;CAErC,CAAA;AAET"}
1
+ {"version":3,"file":"VideoMessage.js","names":[],"sources":["../../../src/components/VideoMessage/VideoMessage.tsx"],"sourcesContent":["import type { CSSProperties, ReactNode, Ref } from \"react\";\nimport { Children } from \"react\";\nimport { Group } from \"react-aria-components\";\nimport { cx } from \"../../utils/cx.js\";\nimport { MediaSlash } from \"../Icon/icons/MediaSlash.js\";\nimport {\n\tvideoPlaceholderIcon,\n\tvideoRoot,\n\tvideoSlot,\n} from \"./VideoMessage.css.js\";\n\nexport type VideoAspectRatio = \"16:9\" | \"4:3\" | \"1:1\" | \"3:4\" | \"9:16\";\n\nexport interface VideoMessageProps {\n\t/**\n\t * The player rendered inside the frame. The shell carries no playback logic\n\t * of its own — the supplied player owns its controls, load state and error\n\t * handling; drive the placeholder through `unavailable`. When absent, the\n\t * frame shows the unavailable placeholder.\n\t */\n\tchildren?: ReactNode;\n\t/** Accessible name for the video — describe what it shows. */\n\talt: string;\n\t/**\n\t * Frame proportions — bind to the source video's proportions so it isn't\n\t * cropped. Defaults to `\"16:9\"`. The frame is context-sized (fills its\n\t * container's width); the consumer constrains it to the message column.\n\t */\n\taspectRatio?: VideoAspectRatio;\n\t/** Force the \"video unavailable\" placeholder (media-slash on a muted box). */\n\tunavailable?: boolean;\n\t/**\n\t * Name of the unavailable placeholder, in the language of the surrounding UI.\n\t * Defaults to \"Video unavailable\". The alt text follows it after a colon.\n\t */\n\tunavailableLabel?: string;\n\t/** Name of the frame when `alt` is empty, in the language of the surrounding UI. Defaults to \"Video\". */\n\tgroupLabel?: string;\n\tclassName?: string;\n\tstyle?: CSSProperties;\n\tref?: Ref<HTMLDivElement>;\n}\n\nconst UNAVAILABLE_LABEL = \"Video unavailable\";\nconst GROUP_LABEL = \"Video\";\nconst DEFAULT_ASPECT_RATIO: VideoAspectRatio = \"16:9\";\n\n/**\n * The presentational frame for a video attachment rendered inside a chat\n * message: rounded clipping to the media-preview corner radius, a fixed aspect\n * ratio, and an accessible grouping label. The consumer supplies the player as\n * `children`; when the video is unavailable — or no player is supplied — the\n * frame shows a muted media-slash placeholder instead.\n */\nexport function VideoMessage({\n\tchildren,\n\talt,\n\taspectRatio = DEFAULT_ASPECT_RATIO,\n\tunavailable = false,\n\tunavailableLabel: unavailableName = UNAVAILABLE_LABEL,\n\tgroupLabel = GROUP_LABEL,\n\tclassName,\n\t...rest\n}: VideoMessageProps) {\n\t// Normalized emptiness, not a `!== false` check: a consumer gating its player\n\t// with `{ready && <Player />}` — alone or alongside siblings, where children\n\t// arrives as an array — renders nothing, and treating that as a supplied\n\t// player would leave the frame permanently empty. `Children.toArray` strips\n\t// null/undefined/booleans at any depth.\n\tconst supplied = Children.toArray(children).length > 0;\n\tconst showPlaceholder = unavailable || !supplied;\n\n\t// Lovelace can be consumed from older/untyped JavaScript even though the TS\n\t// contract requires a string, so the failure path must remain total.\n\tconst description = typeof alt === \"string\" ? alt.trim() : \"\";\n\tconst unavailableLabel = description\n\t\t? `${unavailableName}: ${description}`\n\t\t: unavailableName;\n\n\treturn (\n\t\t// RAC `Group` (role=\"group\"), not a bare div: `aria-label` on a generic\n\t\t// element is prohibited and assistive tech drops it (axe\n\t\t// `aria-prohibited-attr`), so a supplied player — which carries no label of\n\t\t// its own — would reach nobody.\n\t\t<Group\n\t\t\t{...rest}\n\t\t\taria-label={description || groupLabel}\n\t\t\tdata-aspect-ratio={aspectRatio}\n\t\t\tdata-unavailable={showPlaceholder || undefined}\n\t\t\tclassName={cx(\n\t\t\t\tvideoRoot({ aspectRatio, unavailable: showPlaceholder }),\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t>\n\t\t\t{showPlaceholder ? (\n\t\t\t\t<MediaSlash className={videoPlaceholderIcon} label={unavailableLabel} />\n\t\t\t) : (\n\t\t\t\t<div className={videoSlot}>{children}</div>\n\t\t\t)}\n\t\t</Group>\n\t);\n}\n"],"mappings":";;;;;;;AA2CA,IAAM,IAAoB,qBACpB,IAAc,SACd,IAAyC;AAS/C,SAAgB,EAAa,EAC5B,aACA,QACA,iBAAc,GACd,iBAAc,IACd,kBAAkB,IAAkB,GACpC,gBAAa,GACb,cACA,GAAG,KACkB;CAMrB,IAAM,IAAW,EAAS,QAAQ,CAAQ,CAAC,CAAC,SAAS,GAC/C,IAAkB,KAAe,CAAC,GAIlC,IAAc,OAAO,KAAQ,WAAW,EAAI,KAAK,IAAI,IACrD,IAAmB,IACtB,GAAG,EAAgB,IAAI,MACvB;CAEH,OAKC,kBAAC,GAAD;EACC,GAAI;EACJ,cAAY,KAAe;EAC3B,qBAAmB;EACnB,oBAAkB,KAAmB,KAAA;EACrC,WAAW,EACV,EAAU;GAAE;GAAa,aAAa;EAAgB,CAAC,GACvD,CACD;YAEC,IACA,kBAAC,GAAD;GAAY,WAAW;GAAsB,OAAO;EAAmB,CAAA,IAEvE,kBAAC,OAAD;GAAK,WAAW;GAAY;EAAc,CAAA;CAErC,CAAA;AAET"}
@@ -1,45 +1,48 @@
1
1
  import { tokenName as e } from "../tokens/tokens.js";
2
- import { jsx as t } from "react/jsx-runtime";
3
- import { useEffect as n, useMemo as r, useState as i } from "react";
4
- import { UNSAFE_PortalProvider as a } from "react-aria";
2
+ import { accentStateLayers as t } from "./branding.js";
3
+ import { accentStateLayerScope as n } from "../styles/state-layer.css.js";
4
+ import { jsx as r } from "react/jsx-runtime";
5
+ import { useEffect as i, useMemo as a, useState as o } from "react";
6
+ import { UNSAFE_PortalProvider as s } from "react-aria";
5
7
  //#region src/runtime/LovelaceProvider.tsx
6
- var o = "(prefers-color-scheme: dark)";
7
- function s() {
8
- return typeof window > "u" || typeof window.matchMedia != "function" ? !1 : window.matchMedia(o).matches;
8
+ var c = "(prefers-color-scheme: dark)";
9
+ function l() {
10
+ return typeof window > "u" || typeof window.matchMedia != "function" ? !1 : window.matchMedia(c).matches;
9
11
  }
10
- function c(e) {
11
- let [t, r] = i(() => e === "auto" ? s() ? "dark" : "light" : e);
12
- return n(() => {
12
+ function u(e) {
13
+ let [t, n] = o(() => e === "auto" ? l() ? "dark" : "light" : e);
14
+ return i(() => {
13
15
  if (e !== "auto") {
14
- r(e);
16
+ n(e);
15
17
  return;
16
18
  }
17
19
  if (typeof window > "u" || typeof window.matchMedia != "function") return;
18
- let t = window.matchMedia(o), n = (e) => {
19
- r(e ? "dark" : "light");
20
+ let t = window.matchMedia(c), r = (e) => {
21
+ n(e ? "dark" : "light");
20
22
  };
21
- n(t.matches);
22
- let i = (e) => n(e.matches);
23
+ r(t.matches);
24
+ let i = (e) => r(e.matches);
23
25
  return t.addEventListener("change", i), () => t.removeEventListener("change", i);
24
26
  }, [e]), t;
25
27
  }
26
- function l({ theme: n = "auto", override: o, children: s }) {
27
- let l = c(n), [u, d] = i(null);
28
- return /* @__PURE__ */ t("div", {
29
- ref: d,
30
- "data-theme": l,
31
- style: r(() => {
28
+ function d({ theme: i = "auto", override: c, children: l }) {
29
+ let d = u(i), [f, p] = o(null), m = t(c);
30
+ return /* @__PURE__ */ r("div", {
31
+ ref: p,
32
+ className: Object.keys(m).map((e) => n[e][m[e]]).join(" "),
33
+ "data-theme": d,
34
+ style: a(() => {
32
35
  let t = { display: "contents" };
33
- for (let [n, r] of Object.entries(o ?? {})) r != null && (t[e(n)] = r);
36
+ for (let [n, r] of Object.entries(c ?? {})) r != null && (t[e(n)] = r);
34
37
  return t;
35
- }, [o]),
36
- children: u != null && /* @__PURE__ */ t(a, {
37
- getContainer: () => u,
38
- children: s
38
+ }, [c]),
39
+ children: f != null && /* @__PURE__ */ r(s, {
40
+ getContainer: () => f,
41
+ children: l
39
42
  })
40
43
  });
41
44
  }
42
45
  //#endregion
43
- export { l as LovelaceProvider, c as useResolvedTheme };
46
+ export { d as LovelaceProvider, u as useResolvedTheme };
44
47
 
45
48
  //# sourceMappingURL=LovelaceProvider.js.map