@cloudlet/toast 1.0.0-rc.3 → 1.1.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 (72) hide show
  1. package/CHANGELOG.md +84 -16
  2. package/README.md +7 -5
  3. package/dist/contracts/controller.d.ts +7 -2
  4. package/dist/contracts/controller.d.ts.map +1 -1
  5. package/dist/contracts/events.d.ts +1 -1
  6. package/dist/contracts/events.d.ts.map +1 -1
  7. package/dist/contracts/internal.d.ts +23 -0
  8. package/dist/contracts/internal.d.ts.map +1 -1
  9. package/dist/contracts/notifications.d.ts +38 -6
  10. package/dist/contracts/notifications.d.ts.map +1 -1
  11. package/dist/contracts/snapshots.d.ts +3 -1
  12. package/dist/contracts/snapshots.d.ts.map +1 -1
  13. package/dist/core/bridge.d.ts +5 -0
  14. package/dist/core/bridge.d.ts.map +1 -0
  15. package/dist/core/bridge.js +345 -0
  16. package/dist/core/bridge.js.map +1 -0
  17. package/dist/core/controller.d.ts +122 -3
  18. package/dist/core/controller.d.ts.map +1 -1
  19. package/dist/core/controller.js +400 -541
  20. package/dist/core/controller.js.map +1 -1
  21. package/dist/core/validation.d.ts.map +1 -1
  22. package/dist/core/validation.js +181 -89
  23. package/dist/core/validation.js.map +1 -1
  24. package/dist/react/announcer.d.ts.map +1 -1
  25. package/dist/react/announcer.js +29 -23
  26. package/dist/react/announcer.js.map +1 -1
  27. package/dist/react/bindings.d.ts +9 -0
  28. package/dist/react/bindings.d.ts.map +1 -1
  29. package/dist/react/bindings.js +32 -69
  30. package/dist/react/bindings.js.map +1 -1
  31. package/dist/react/card.d.ts +5 -3
  32. package/dist/react/card.d.ts.map +1 -1
  33. package/dist/react/card.js +146 -34
  34. package/dist/react/card.js.map +1 -1
  35. package/dist/react/generators.d.ts +2 -2
  36. package/dist/react/generators.js.map +1 -1
  37. package/dist/react/gestures.js.map +1 -1
  38. package/dist/react/host.d.ts.map +1 -1
  39. package/dist/react/host.js +9 -5
  40. package/dist/react/host.js.map +1 -1
  41. package/dist/react/motion.d.ts +3 -3
  42. package/dist/react/motion.js.map +1 -1
  43. package/dist/react/plan.d.ts +1 -1
  44. package/dist/react/plan.d.ts.map +1 -1
  45. package/dist/react/plan.js +1 -0
  46. package/dist/react/plan.js.map +1 -1
  47. package/dist/react/renderer.d.ts +7 -0
  48. package/dist/react/renderer.d.ts.map +1 -0
  49. package/dist/react/renderer.js +62 -0
  50. package/dist/react/renderer.js.map +1 -0
  51. package/dist/react.d.ts +7 -5
  52. package/dist/react.d.ts.map +1 -1
  53. package/dist/styles.css +1 -1
  54. package/package.json +4 -2
  55. package/src/contracts/controller.ts +7 -2
  56. package/src/contracts/events.ts +2 -1
  57. package/src/contracts/internal.ts +20 -0
  58. package/src/contracts/notifications.ts +45 -6
  59. package/src/contracts/snapshots.ts +3 -0
  60. package/src/core/bridge.ts +336 -0
  61. package/src/core/controller.ts +118 -271
  62. package/src/core/validation.ts +49 -4
  63. package/src/react/announcer.ts +9 -0
  64. package/src/react/bindings.tsx +28 -72
  65. package/src/react/card.tsx +92 -9
  66. package/src/react/generators.ts +2 -2
  67. package/src/react/gestures.ts +1 -1
  68. package/src/react/host.tsx +22 -7
  69. package/src/react/motion.ts +4 -4
  70. package/src/react/plan.ts +4 -3
  71. package/src/react/renderer.tsx +77 -0
  72. package/src/react.ts +7 -5
@@ -10,14 +10,14 @@ var e = ({ content: e }) => [e.title, e.description?.kind === "rich" ? e.descrip
10
10
  resumed: (e) => `${e} current notifications`
11
11
  };
12
12
  function n(e, n, r, i) {
13
- let a = null, o = null, s, c, l = !1, u = !1, d = null, f = null, p, m = r.defaultView, h = () => {
14
- m?.clearTimeout(s), s = void 0;
15
- }, g = () => {
13
+ let a = null, o = null, s, c, l = !1, u = !1, d = null, f = null, p = !1, m, h = r.defaultView, g = () => {
14
+ h?.clearTimeout(s), s = void 0;
15
+ }, _ = () => {
16
16
  if (!l) return;
17
17
  let t = e.getSnapshot();
18
- !t.notifications.length && !t.overflow.pending ? (h(), u = !1) : s === void 0 && r.visibilityState !== "hidden" && (s = m?.setTimeout(v, 300));
18
+ !t.notifications.length && !t.overflow.pending ? (g(), u = !1) : s === void 0 && r.visibilityState !== "hidden" && (s = h?.setTimeout(y, 300));
19
19
  };
20
- function _(r, ...a) {
20
+ function v(r, ...a) {
21
21
  try {
22
22
  let e = (i()?.[r] ?? t[r])(...a);
23
23
  if (typeof e != "string" || !e.trim()) throw TypeError("Announcement must be a nonempty string");
@@ -31,9 +31,15 @@ function n(e, n, r, i) {
31
31
  }), t[r](...a);
32
32
  }
33
33
  }
34
- function v() {
34
+ function y() {
35
35
  if (s = void 0, !l || r.visibilityState === "hidden" || !a || !o) return;
36
- let t = e.getSnapshot(), i = [], c = {
36
+ let t = e.getSnapshot();
37
+ if (t.presentation && !t.presentation.readable && !u) {
38
+ p = !0;
39
+ return;
40
+ }
41
+ p = !1;
42
+ let i = [], c = {
37
43
  polite: [],
38
44
  assertive: []
39
45
  }, d = {
@@ -68,34 +74,34 @@ function n(e, n, r, i) {
68
74
  token: p.token,
69
75
  phase: e
70
76
  });
71
- a.includes(t) || (s(() => _("operation", e, t)), m = !0);
77
+ a.includes(t) || (s(() => v("operation", e, t)), m = !0);
72
78
  }
73
- l && !m ? s(() => _("notification", e)) : f === r && e.location === "current" && !m && a !== "off" && !u && c.polite.push(_("notification", e)), e.occurrences > n.occurrences && (i.push({
79
+ l && !m ? s(() => v("notification", e)) : f === r && e.location === "current" && !m && a !== "off" && !u && c.polite.push(v("notification", e)), e.occurrences > n.occurrences && (i.push({
74
80
  kind: "occurrences",
75
81
  handle: r,
76
82
  count: e.occurrences
77
- }), !l && e.occurrences > 1 && s(() => _("occurrences", e)));
83
+ }), !l && e.occurrences > 1 && s(() => v("occurrences", e)));
78
84
  let h = e.action;
79
85
  h.status !== "idle" && (n.action?.token !== h.token || n.action.status !== h.status) && (i.push({
80
86
  kind: "action",
81
87
  handle: r,
82
88
  token: h.token,
83
89
  status: h.status
84
- }), s(() => h.status === "failed" ? _("actionError", e, h.message) : _("actionPending", e)));
90
+ }), s(() => h.status === "failed" ? v("actionError", e, h.message) : v("actionPending", e)));
85
91
  }
86
- for (let e of ["polite", "assertive"]) d[e] && c[e].push(_("queued", d[e]));
92
+ for (let e of ["polite", "assertive"]) d[e] && c[e].push(v("queued", d[e]));
87
93
  if (t.overflow.count > t.announcements.overflowCount && (i.push({
88
94
  kind: "overflow",
89
95
  count: t.overflow.count
90
- }), u || c.polite.push(_("overflow", t.overflow.count))), u) {
96
+ }), u || c.polite.push(v("overflow", t.overflow.count))), u) {
91
97
  for (let e of ["polite", "assertive"]) {
92
98
  let n = t.notifications.filter((t) => (t.content.announcementPriority ?? "polite") === e).length;
93
- n && c[e].push(_("resumed", n));
99
+ n && c[e].push(v("resumed", n));
94
100
  }
95
- t.overflow.pending && c.polite.push(_("overflow", t.overflow.count));
101
+ t.overflow.pending && c.polite.push(v("overflow", t.overflow.count));
96
102
  }
97
103
  if (l) {
98
- if (e.getSnapshot() !== t) g();
104
+ if (e.getSnapshot() !== t) _();
99
105
  else {
100
106
  u = !1, f = null;
101
107
  for (let [e, t] of [[a, c.polite], [o, c.assertive]]) {
@@ -107,8 +113,8 @@ function n(e, n, r, i) {
107
113
  }
108
114
  }
109
115
  }
110
- function y() {
111
- h(), r.visibilityState === "hidden" ? (a?.replaceChildren(), o?.replaceChildren()) : (u = !0, g());
116
+ function b() {
117
+ g(), r.visibilityState === "hidden" ? (a?.replaceChildren(), o?.replaceChildren()) : (u = !0, _());
112
118
  }
113
119
  return {
114
120
  mount(t) {
@@ -117,14 +123,14 @@ function n(e, n, r, i) {
117
123
  let t = r.createElement("div");
118
124
  return t.className = "cloudlet-announcer", t.dataset.cloudletAnnouncer = e, t.setAttribute("aria-live", e), t.setAttribute("aria-atomic", "true"), t;
119
125
  };
120
- a = n("polite"), o = n("assertive"), t.after(a, o), p = m?.requestAnimationFrame?.(() => {
121
- p = void 0, a && o && t.after(a, o);
126
+ a = n("polite"), o = n("assertive"), t.after(a, o), m = h?.requestAnimationFrame?.(() => {
127
+ m = void 0, a && o && t.after(a, o);
122
128
  }), c = e.onEvent((t) => {
123
- t.type === "presented" && (!t.firstPresentation && d !== null && t.handle !== d && e.getSnapshot().island.open && (f = t.handle), d = t.handle), t.type !== "updated" && t.type !== "diagnostic" && g();
124
- }), r.addEventListener("visibilitychange", y), g();
129
+ t.type === "presented" && (!t.firstPresentation && d !== null && t.handle !== d && e.getSnapshot().island.open && (f = t.handle), d = t.handle, p) ? (p = !1, g(), s = h?.setTimeout(y, 0)) : t.type !== "updated" && t.type !== "diagnostic" && _();
130
+ }), r.addEventListener("visibilitychange", b), _();
125
131
  },
126
132
  dispose() {
127
- l = !1, h(), c?.(), r.removeEventListener("visibilitychange", y), p !== void 0 && m?.cancelAnimationFrame(p), a?.remove(), o?.remove(), a = o = null;
133
+ l = !1, g(), c?.(), r.removeEventListener("visibilitychange", b), m !== void 0 && h?.cancelAnimationFrame(m), a?.remove(), o?.remove(), a = o = null;
128
134
  }
129
135
  };
130
136
  }
@@ -1 +1 @@
1
- {"version":3,"file":"announcer.js","names":["content","value","defaults","count","item","message","createAnnouncer","polite","assertive","timer","unsubscribe","mounted","resumed","shown","revisit","reinsert","view","doc","cancel","schedule","snapshot","bridge","flush","format","args","options","key","error","lease","acks","messages","queued","ledger","handle","priority","readable","say","text","first","operation","operationText","phase","phases","current","action","host","lines","visibility","region","element","event"],"sources":["../../src/react/announcer.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport type { AnnouncementAcknowledgement, HostLease, OperationAnnouncementPhase, RendererBridge } from '../contracts/internal.js';\nimport type { NotificationHandle } from '../contracts/identity.js';\nimport type { NotificationSnapshot } from '../contracts/snapshots.js';\nimport type { AnnouncementFormatters } from '../react.js';\n\ntype Notification = NotificationSnapshot<ReactNode>;\nconst content = ({ content: value }: Notification) => [value.title,\n value.description?.kind === 'rich' ? value.description.announcement : value.description?.text,\n].filter(Boolean).join('. ');\n\nconst defaults: Required<AnnouncementFormatters> = {\n notification: content,\n queued: count => `${count} notifications queued`,\n occurrences: item => `${item.content.title}. ${item.occurrences} occurrences`,\n overflow: count => `${count} missed notifications`,\n operation: content,\n actionError: (item, message) => `${item.content.title}. ${message}`,\n actionPending: item => `${item.content.title}. ${item.content.action?.label}. In progress`,\n resumed: count => `${count} current notifications`,\n};\n\n/** One attachment, two existing live hosts, one fixed batch window. No event history. */\nexport function createAnnouncer(bridge: RendererBridge<ReactNode>, lease: HostLease, doc: Document,\n options: () => Partial<AnnouncementFormatters> | undefined) {\n let polite: Element | null = null;\n let assertive: Element | null = null;\n let timer: number | undefined;\n let unsubscribe: (() => void) | undefined;\n let mounted = false;\n let resumed = false;\n /** The record last presented, and one shown again inside the open Island (a slide back, or the next after a close). */\n let shown: NotificationHandle | null = null;\n let revisit: NotificationHandle | null = null;\n let reinsert: number | undefined;\n const view = doc.defaultView;\n const cancel = () => { view?.clearTimeout(timer); timer = undefined; };\n const schedule = () => {\n if (!mounted) return;\n const snapshot = bridge.getSnapshot();\n if (!snapshot.notifications.length && !snapshot.overflow.pending) { cancel(); resumed = false; return; }\n if (timer === undefined && doc.visibilityState !== 'hidden') timer = view?.setTimeout(flush, 300);\n };\n function format<K extends keyof AnnouncementFormatters>(key: K,\n ...args: Parameters<Required<AnnouncementFormatters>[K]>): string {\n // The correlated tuple is preserved at all callers; the cast is local to dispatch.\n type Formatter = (...values: typeof args) => string;\n try {\n const text = (options()?.[key] ?? defaults[key]) as Formatter;\n const value = text(...args);\n if (typeof value !== 'string' || !value.trim()) throw new TypeError('Announcement must be a nonempty string');\n return value;\n } catch (error) {\n bridge.reportDiagnostic(lease, { code: 'formatter-error', source: `Toaster.announcements.${key}`,\n message: 'Announcement formatter failed', error });\n return (defaults[key] as Formatter)(...args);\n }\n }\n function flush() {\n timer = undefined;\n if (!mounted || doc.visibilityState === 'hidden' || !polite || !assertive) return;\n const snapshot = bridge.getSnapshot();\n const acks: AnnouncementAcknowledgement[] = [];\n const messages = { polite: [] as string[], assertive: [] as string[] };\n const queued = { polite: 0, assertive: 0 };\n for (const item of snapshot.notifications) {\n const ledger = snapshot.announcements.notifications.find(value => value.handle === item.handle)!;\n const handle = item.handle;\n const priority = item.content.announcementPriority ?? 'polite';\n const readable = snapshot.presentation?.handle === handle && snapshot.presentation.readable;\n const say = (text: () => string) => { if (priority !== 'off' && !resumed) messages[priority].push(text()); };\n // Stack records behind the presented one speak only as an aggregate, like a queue.\n if (item.location === 'stack') {\n if (!ledger.queued) {\n acks.push({ kind: 'queued', handle });\n if (priority !== 'off' && !ledger.firstPresentation && !resumed) queued[priority]++;\n }\n // Queued payloads/progress never speak; first presentation reads the latest state.\n if (!resumed) continue;\n } else if (!readable && !resumed) continue;\n\n const first = item.location === 'current' && readable && !ledger.firstPresentation;\n if (first) acks.push({ kind: 'first-presentation', handle });\n const operation = item.operation;\n let operationText = false;\n if (operation) {\n const phase = operation.status === 'pending' ? operation.cancelRequested ? 'cancel-requested' : 'started' : operation.status;\n const phases = ledger.operation?.token === operation.token ? ledger.operation.phases : [];\n for (const current of new Set<OperationAnnouncementPhase>(['started', ...(operation.cancelRequested ? ['cancel-requested' as const] : []), phase])) {\n if (!phases.includes(current)) acks.push({ kind: 'operation', handle, token: operation.token, phase: current });\n }\n if (!phases.includes(phase)) { say(() => format('operation', item, phase)); operationText = true; }\n }\n if (first && !operationText) say(() => format('notification', item));\n // The title node is shared by every slide, so focus never moves when a slide comes back:\n // speak the record once more so a screen reader hears where the user landed.\n else if (revisit === handle && item.location === 'current' && !operationText && priority !== 'off' && !resumed) {\n messages.polite.push(format('notification', item));\n }\n if (item.occurrences > ledger.occurrences) {\n acks.push({ kind: 'occurrences', handle, count: item.occurrences });\n if (!first && item.occurrences > 1) say(() => format('occurrences', item));\n }\n const action = item.action;\n if (action.status !== 'idle' && (ledger.action?.token !== action.token || ledger.action.status !== action.status)) {\n acks.push({ kind: 'action', handle, token: action.token, status: action.status });\n say(() => action.status === 'failed' ? format('actionError', item, action.message) : format('actionPending', item));\n }\n }\n for (const priority of ['polite', 'assertive'] as const) {\n if (queued[priority]) messages[priority].push(format('queued', queued[priority]));\n }\n if (snapshot.overflow.count > snapshot.announcements.overflowCount) {\n acks.push({ kind: 'overflow', count: snapshot.overflow.count });\n if (!resumed) messages.polite.push(format('overflow', snapshot.overflow.count));\n }\n if (resumed) {\n for (const priority of ['polite', 'assertive'] as const) {\n const count = snapshot.notifications.filter(item => (item.content.announcementPriority ?? 'polite') === priority).length;\n if (count) messages[priority].push(format('resumed', count));\n }\n if (snapshot.overflow.pending) messages.polite.push(format('overflow', snapshot.overflow.count));\n }\n // A user formatter/diagnostic can reenter the controller. Never deliver its stale batch.\n if (!mounted) return;\n if (bridge.getSnapshot() !== snapshot) { schedule(); return; }\n resumed = false;\n revisit = null;\n for (const [host, lines] of [[polite, messages.polite], [assertive, messages.assertive]] as const) {\n if (!lines.length) continue;\n let text = lines.join('. ');\n // The same message again (a second failed attempt) would leave the region unchanged and silent;\n // a trailing no-break space makes it a change without changing what is spoken.\n if (host.textContent === text) text += '\\u00a0';\n host.replaceChildren(doc.createTextNode(text));\n }\n bridge.acknowledgeAnnouncements(lease, acks);\n }\n function visibility() {\n cancel();\n if (doc.visibilityState === 'hidden') {\n polite?.replaceChildren(); assertive?.replaceChildren();\n } else { resumed = true; schedule(); }\n }\n return {\n /**\n * The announcer owns its live regions: created here, next to the host (React owns the host's\n * children), and inserted twice. VoiceOver in Safari ignored assertive changes made while focus\n * was in the open Island in regions inserted only once (0 of 6 runs), and spoke them after one\n * re-insertion on the next frame (6 of 6, rc.2 gate); a zero timeout was not enough (3 of 5).\n */\n mount(host: HTMLElement) {\n mounted = true;\n const region = (priority: 'polite' | 'assertive') => {\n const element = doc.createElement('div');\n element.className = 'cloudlet-announcer';\n element.dataset.cloudletAnnouncer = priority;\n element.setAttribute('aria-live', priority);\n element.setAttribute('aria-atomic', 'true');\n return element;\n };\n polite = region('polite');\n assertive = region('assertive');\n host.after(polite, assertive);\n reinsert = view?.requestAnimationFrame?.(() => {\n reinsert = undefined;\n if (polite && assertive) host.after(polite, assertive);\n });\n unsubscribe = bridge.onEvent(event => {\n if (event.type === 'presented') {\n if (!event.firstPresentation && shown !== null && event.handle !== shown && bridge.getSnapshot().island.open) revisit = event.handle;\n shown = event.handle;\n }\n // Updated includes progress, reflow and ordinary text edits, not a new semantic phase.\n if (event.type !== 'updated' && event.type !== 'diagnostic') schedule();\n });\n doc.addEventListener('visibilitychange', visibility);\n schedule();\n },\n dispose() {\n mounted = false;\n cancel(); unsubscribe?.();\n doc.removeEventListener('visibilitychange', visibility);\n if (reinsert !== undefined) view?.cancelAnimationFrame(reinsert);\n polite?.remove(); assertive?.remove();\n polite = assertive = null;\n },\n };\n}\n"],"mappings":";AAOA,IAAMA,KAAW,EAAE,SAASC,QAA0B,CAACA,EAAM,OAC3DA,EAAM,aAAa,SAAS,SAASA,EAAM,YAAY,eAAeA,EAAM,aAAa,IAC3F,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,IAAI,GAErBC,IAA6C;CACjD,cAAcF;CACd,SAAQ,MAAS,GAAGG,EAAM;CAC1B,cAAa,MAAQ,GAAGC,EAAK,QAAQ,MAAM,IAAIA,EAAK,YAAY;CAChE,WAAU,MAAS,GAAGD,EAAM;CAC5B,WAAWH;CACX,cAAc,GAAM,MAAY,GAAGI,EAAK,QAAQ,MAAM,IAAIC;CAC1D,gBAAe,MAAQ,GAAGD,EAAK,QAAQ,MAAM,IAAIA,EAAK,QAAQ,QAAQ,MAAM;CAC5E,UAAS,MAAS,GAAGD,EAAM;AAC7B;AAGA,SAAgBG,EAAgB,GAAmC,GAAkB,GACnF,GAA4D;CAC5D,IAAIC,IAAyB,MACzBC,IAA4B,MAC5BC,GACAC,GACAC,IAAU,IACVC,IAAU,IAEVC,IAAmC,MACnCC,IAAqC,MACrCC,GACEC,IAAOC,EAAI,aACXC,UAAe;EAA6B,AAA3BF,GAAM,aAAaP,CAAK,GAAG,IAAQ,KAAA;CAA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B,CAAU,GAClDhC,MAAa,KAAA,KAAWC,GAAM,qBAAqBD,CAAQ,GAC/DR,GAAQ,OAAO,GAAGC,GAAW,OAAO,GACpC,IAAS,IAAY;EACvB;CACF;AACF"}
1
+ {"version":3,"file":"announcer.js","names":["content","value","defaults","count","item","message","createAnnouncer","polite","assertive","timer","unsubscribe","mounted","resumed","shown","revisit","waiting","reinsert","view","doc","cancel","schedule","snapshot","bridge","flush","format","args","options","key","error","lease","acks","messages","queued","ledger","handle","priority","readable","say","text","first","operation","operationText","phase","phases","current","action","host","lines","visibility","region","element","event"],"sources":["../../src/react/announcer.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport type { AnnouncementAcknowledgement, HostLease, OperationAnnouncementPhase, RendererBridge } from '../contracts/internal.js';\nimport type { NotificationHandle } from '../contracts/identity.js';\nimport type { NotificationSnapshot } from '../contracts/snapshots.js';\nimport type { AnnouncementFormatters } from '../react.js';\n\ntype Notification = NotificationSnapshot<ReactNode>;\nconst content = ({ content: value }: Notification) => [value.title,\n value.description?.kind === 'rich' ? value.description.announcement : value.description?.text,\n].filter(Boolean).join('. ');\n\nconst defaults: Required<AnnouncementFormatters> = {\n notification: content,\n queued: count => `${count} notifications queued`,\n occurrences: item => `${item.content.title}. ${item.occurrences} occurrences`,\n overflow: count => `${count} missed notifications`,\n operation: content,\n actionError: (item, message) => `${item.content.title}. ${message}`,\n actionPending: item => `${item.content.title}. ${item.content.action?.label}. In progress`,\n resumed: count => `${count} current notifications`,\n};\n\n/** One attachment, two existing live hosts, one fixed batch window. No event history. */\nexport function createAnnouncer(bridge: RendererBridge<ReactNode>, lease: HostLease, doc: Document,\n options: () => Partial<AnnouncementFormatters> | undefined) {\n let polite: Element | null = null;\n let assertive: Element | null = null;\n let timer: number | undefined;\n let unsubscribe: (() => void) | undefined;\n let mounted = false;\n let resumed = false;\n /** The record last presented, and one shown again inside the open Island (a slide back, or the next after a close). */\n let shown: NotificationHandle | null = null;\n let revisit: NotificationHandle | null = null;\n /** A flush held back until the presented record is readable (see `flush`). */\n let waiting = false;\n let reinsert: number | undefined;\n const view = doc.defaultView;\n const cancel = () => { view?.clearTimeout(timer); timer = undefined; };\n const schedule = () => {\n if (!mounted) return;\n const snapshot = bridge.getSnapshot();\n if (!snapshot.notifications.length && !snapshot.overflow.pending) { cancel(); resumed = false; return; }\n if (timer === undefined && doc.visibilityState !== 'hidden') timer = view?.setTimeout(flush, 300);\n };\n function format<K extends keyof AnnouncementFormatters>(key: K,\n ...args: Parameters<Required<AnnouncementFormatters>[K]>): string {\n // The correlated tuple is preserved at all callers; the cast is local to dispatch.\n type Formatter = (...values: typeof args) => string;\n try {\n const text = (options()?.[key] ?? defaults[key]) as Formatter;\n const value = text(...args);\n if (typeof value !== 'string' || !value.trim()) throw new TypeError('Announcement must be a nonempty string');\n return value;\n } catch (error) {\n bridge.reportDiagnostic(lease, { code: 'formatter-error', source: `Toaster.announcements.${key}`,\n message: 'Announcement formatter failed', error });\n return (defaults[key] as Formatter)(...args);\n }\n }\n function flush() {\n timer = undefined;\n if (!mounted || doc.visibilityState === 'hidden' || !polite || !assertive) return;\n const snapshot = bridge.getSnapshot();\n // The presented record speaks first and the queue after it. While its pill or slide is still\n // arriving (a slow first frame), sending now would say the queue alone; its `presented` event\n // flushes instead.\n if (snapshot.presentation && !snapshot.presentation.readable && !resumed) { waiting = true; return; }\n waiting = false;\n const acks: AnnouncementAcknowledgement[] = [];\n const messages = { polite: [] as string[], assertive: [] as string[] };\n const queued = { polite: 0, assertive: 0 };\n for (const item of snapshot.notifications) {\n const ledger = snapshot.announcements.notifications.find(value => value.handle === item.handle)!;\n const handle = item.handle;\n const priority = item.content.announcementPriority ?? 'polite';\n const readable = snapshot.presentation?.handle === handle && snapshot.presentation.readable;\n const say = (text: () => string) => { if (priority !== 'off' && !resumed) messages[priority].push(text()); };\n // Stack records behind the presented one speak only as an aggregate, like a queue.\n if (item.location === 'stack') {\n if (!ledger.queued) {\n acks.push({ kind: 'queued', handle });\n if (priority !== 'off' && !ledger.firstPresentation && !resumed) queued[priority]++;\n }\n // Queued payloads/progress never speak; first presentation reads the latest state.\n if (!resumed) continue;\n } else if (!readable && !resumed) continue;\n\n const first = item.location === 'current' && readable && !ledger.firstPresentation;\n if (first) acks.push({ kind: 'first-presentation', handle });\n const operation = item.operation;\n let operationText = false;\n if (operation) {\n const phase = operation.status === 'pending' ? operation.cancelRequested ? 'cancel-requested' : 'started' : operation.status;\n const phases = ledger.operation?.token === operation.token ? ledger.operation.phases : [];\n for (const current of new Set<OperationAnnouncementPhase>(['started', ...(operation.cancelRequested ? ['cancel-requested' as const] : []), phase])) {\n if (!phases.includes(current)) acks.push({ kind: 'operation', handle, token: operation.token, phase: current });\n }\n if (!phases.includes(phase)) { say(() => format('operation', item, phase)); operationText = true; }\n }\n if (first && !operationText) say(() => format('notification', item));\n // The title node is shared by every slide, so focus never moves when a slide comes back:\n // speak the record once more so a screen reader hears where the user landed.\n else if (revisit === handle && item.location === 'current' && !operationText && priority !== 'off' && !resumed) {\n messages.polite.push(format('notification', item));\n }\n if (item.occurrences > ledger.occurrences) {\n acks.push({ kind: 'occurrences', handle, count: item.occurrences });\n if (!first && item.occurrences > 1) say(() => format('occurrences', item));\n }\n const action = item.action;\n if (action.status !== 'idle' && (ledger.action?.token !== action.token || ledger.action.status !== action.status)) {\n acks.push({ kind: 'action', handle, token: action.token, status: action.status });\n say(() => action.status === 'failed' ? format('actionError', item, action.message) : format('actionPending', item));\n }\n }\n for (const priority of ['polite', 'assertive'] as const) {\n if (queued[priority]) messages[priority].push(format('queued', queued[priority]));\n }\n if (snapshot.overflow.count > snapshot.announcements.overflowCount) {\n acks.push({ kind: 'overflow', count: snapshot.overflow.count });\n if (!resumed) messages.polite.push(format('overflow', snapshot.overflow.count));\n }\n if (resumed) {\n for (const priority of ['polite', 'assertive'] as const) {\n const count = snapshot.notifications.filter(item => (item.content.announcementPriority ?? 'polite') === priority).length;\n if (count) messages[priority].push(format('resumed', count));\n }\n if (snapshot.overflow.pending) messages.polite.push(format('overflow', snapshot.overflow.count));\n }\n // A user formatter/diagnostic can reenter the controller. Never deliver its stale batch.\n if (!mounted) return;\n if (bridge.getSnapshot() !== snapshot) { schedule(); return; }\n resumed = false;\n revisit = null;\n for (const [host, lines] of [[polite, messages.polite], [assertive, messages.assertive]] as const) {\n if (!lines.length) continue;\n let text = lines.join('. ');\n // The same message again (a second failed attempt) would leave the region unchanged and silent;\n // a trailing no-break space makes it a change without changing what is spoken.\n if (host.textContent === text) text += '\\u00a0';\n host.replaceChildren(doc.createTextNode(text));\n }\n bridge.acknowledgeAnnouncements(lease, acks);\n }\n function visibility() {\n cancel();\n if (doc.visibilityState === 'hidden') {\n polite?.replaceChildren(); assertive?.replaceChildren();\n } else { resumed = true; schedule(); }\n }\n return {\n /**\n * The announcer owns its live regions: created here, next to the host (React owns the host's\n * children), and inserted twice. VoiceOver in Safari ignored assertive changes made while focus\n * was in the open Island in regions inserted only once (0 of 6 runs), and spoke them after one\n * re-insertion on the next frame (6 of 6, rc.2 gate); a zero timeout was not enough (3 of 5).\n */\n mount(host: HTMLElement) {\n mounted = true;\n const region = (priority: 'polite' | 'assertive') => {\n const element = doc.createElement('div');\n element.className = 'cloudlet-announcer';\n element.dataset.cloudletAnnouncer = priority;\n element.setAttribute('aria-live', priority);\n element.setAttribute('aria-atomic', 'true');\n return element;\n };\n polite = region('polite');\n assertive = region('assertive');\n host.after(polite, assertive);\n reinsert = view?.requestAnimationFrame?.(() => {\n reinsert = undefined;\n if (polite && assertive) host.after(polite, assertive);\n });\n unsubscribe = bridge.onEvent(event => {\n if (event.type === 'presented') {\n if (!event.firstPresentation && shown !== null && event.handle !== shown && bridge.getSnapshot().island.open) revisit = event.handle;\n shown = event.handle;\n // The window already passed while the presentation was pending: deliver right away.\n if (waiting) { waiting = false; cancel(); timer = view?.setTimeout(flush, 0); return; }\n }\n // Updated includes progress, reflow and ordinary text edits, not a new semantic phase.\n if (event.type !== 'updated' && event.type !== 'diagnostic') schedule();\n });\n doc.addEventListener('visibilitychange', visibility);\n schedule();\n },\n dispose() {\n mounted = false;\n cancel(); unsubscribe?.();\n doc.removeEventListener('visibilitychange', visibility);\n if (reinsert !== undefined) view?.cancelAnimationFrame(reinsert);\n polite?.remove(); assertive?.remove();\n polite = assertive = null;\n },\n };\n}\n"],"mappings":";AAOA,IAAMA,KAAW,EAAE,SAASC,QAA0B,CAACA,EAAM,OAC3DA,EAAM,aAAa,SAAS,SAASA,EAAM,YAAY,eAAeA,EAAM,aAAa,IAC3F,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,IAAI,GAErBC,IAA6C;CACjD,cAAcF;CACd,SAAQ,MAAS,GAAGG,EAAM;CAC1B,cAAa,MAAQ,GAAGC,EAAK,QAAQ,MAAM,IAAIA,EAAK,YAAY;CAChE,WAAU,MAAS,GAAGD,EAAM;CAC5B,WAAWH;CACX,cAAc,GAAM,MAAY,GAAGI,EAAK,QAAQ,MAAM,IAAIC;CAC1D,gBAAe,MAAQ,GAAGD,EAAK,QAAQ,MAAM,IAAIA,EAAK,QAAQ,QAAQ,MAAM;CAC5E,UAAS,MAAS,GAAGD,EAAM;AAC7B;AAGA,SAAgBG,EAAgB,GAAmC,GAAkB,GACnF,GAA4D;CAC5D,IAAIC,IAAyB,MACzBC,IAA4B,MAC5BC,GACAC,GACAC,IAAU,IACVC,IAAU,IAEVC,IAAmC,MACnCC,IAAqC,MAErCC,IAAU,IACVC,GACEC,IAAOC,EAAI,aACXC,UAAe;EAA6B,AAA3BF,GAAM,aAAaR,CAAK,GAAG,IAAQ,KAAA;CAAW,GAC/DW,UAAiB;EACrB,IAAI,CAACT,GAAS;EACd,IAAMU,IAAWC,EAAO,YAAY;EACpC,AAAI,CAACD,EAAS,cAAc,UAAU,CAACA,EAAS,SAAS,WAAWF,EAAO,GAAG,IAAU,MACpFV,MAAU,KAAA,KAAaS,EAAI,oBAAoB,aAAU,IAAQD,GAAM,WAAWM,GAAO,GAAG;CAClG;CACA,SAASC,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Q,OAAO,GAAGC,GAAW,OAAO,GACpC,IAAS,IAAY;EACvB;CACF;AACF"}
@@ -1,8 +1,17 @@
1
1
  import type { ReactElement } from 'react';
2
2
  import type { CloudletProviderProps, ReactCloudletController, ToasterProps } from '../react.js';
3
+ type Renderer = typeof import('./renderer.js');
3
4
  export declare function CloudletProvider({ controller, children }: CloudletProviderProps): ReactElement;
4
5
  export declare function useCloudlet(): ReactCloudletController;
5
6
  /** The controller, or null outside a provider and while the provider's controller is null. */
6
7
  export declare function useOptionalCloudlet(): ReactCloudletController | null;
8
+ /** Fetches the renderer chunk once for every Toaster; after a failure the next attempt fetches again. */
9
+ export declare function loadRenderer(): Promise<Renderer>;
10
+ /**
11
+ * The renderer stays out of the start bundle: the chunk loads after mount, and
12
+ * notifications shown meanwhile wait in the controller. On the server and during
13
+ * hydration this renders nothing, exactly like the attached renderer does.
14
+ */
7
15
  export declare function Toaster(options: ToasterProps): ReactElement | null;
16
+ export {};
8
17
  //# sourceMappingURL=bindings.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bindings.d.ts","sourceRoot":"","sources":["../../src/react/bindings.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAI1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAShG,wBAAgB,gBAAgB,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,qBAAqB,GAAG,YAAY,CAE9F;AAED,wBAAgB,WAAW,IAAI,uBAAuB,CAIrD;AAED,8FAA8F;AAC9F,wBAAgB,mBAAmB,IAAI,uBAAuB,GAAG,IAAI,CAEpE;AASD,wBAAgB,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,YAAY,GAAG,IAAI,CAKlE"}
1
+ {"version":3,"file":"bindings.d.ts","sourceRoot":"","sources":["../../src/react/bindings.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhG,KAAK,QAAQ,GAAG,cAAc,eAAe,CAAC,CAAC;AAO/C,wBAAgB,gBAAgB,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,qBAAqB,GAAG,YAAY,CAE9F;AAED,wBAAgB,WAAW,IAAI,uBAAuB,CAIrD;AAED,8FAA8F;AAC9F,wBAAgB,mBAAmB,IAAI,uBAAuB,GAAG,IAAI,CAEpE;AAED,yGAAyG;AACzG,wBAAgB,YAAY,IAAI,OAAO,CAAC,QAAQ,CAAC,CAMhD;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,YAAY,GAAG,IAAI,CAclE"}
@@ -1,84 +1,47 @@
1
- import { getRendererBridge as e } from "../core/controller.js";
2
- import { Host as t } from "./host.js";
3
- import { createContext as n, useContext as r, useEffect as i, useRef as a, useState as o, useSyncExternalStore as s } from "react";
4
- import { createPortal as c } from "react-dom";
5
- import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime";
1
+ import { getControllerKernel as e } from "../core/controller.js";
2
+ import { createContext as t, useContext as n, useEffect as r, useState as i } from "react";
3
+ import { jsx as a } from "react/jsx-runtime";
6
4
  //#region src/react/bindings.tsx
7
- var f = n(void 0), p = () => () => {}, m = () => !0, h = () => !1;
8
- function g({ controller: e, children: t }) {
9
- return /* @__PURE__ */ u(f.Provider, {
5
+ var o = t(void 0), s, c;
6
+ function l({ controller: e, children: t }) {
7
+ return /* @__PURE__ */ a(o.Provider, {
10
8
  value: e,
11
9
  children: t
12
10
  });
13
11
  }
14
- function _() {
15
- let e = r(f);
12
+ function u() {
13
+ let e = n(o);
16
14
  if (!e) throw Error("useCloudlet must be used within a CloudletProvider that has a controller");
17
15
  return e;
18
16
  }
19
- function v() {
20
- return r(f) ?? null;
17
+ function d() {
18
+ return n(o) ?? null;
21
19
  }
22
- function y(e) {
23
- let t = r(f);
24
- if (t === void 0) throw Error("Toaster must be used within a CloudletProvider");
25
- return t ? /* @__PURE__ */ u(b, {
26
- controller: t,
27
- options: e
28
- }) : null;
20
+ function f() {
21
+ return c ??= import("./renderer.js").then((e) => s = e, (e) => {
22
+ throw c = void 0, e;
23
+ }), c;
29
24
  }
30
- function b({ controller: n, options: r }) {
31
- let f = s(p, m, h), g = e(n), _ = s(g.subscribe, g.getSnapshot, g.getServerSnapshot), v = a(null), [y, b] = o(null);
32
- i(() => {
33
- if (!f || !v.current) return;
34
- let e = v.current.ownerDocument, t;
35
- try {
36
- let n = (typeof r.container == "function" ? r.container() : r.container) ?? e.body;
37
- if (!n || n.nodeType !== 1 || n.ownerDocument !== e || n.namespaceURI !== "http://www.w3.org/1999/xhtml" || !n.isConnected || n.getRootNode().nodeType === 11) {
38
- g.reportInvalidContainer("Toaster container must be a connected HTML Element in the mounting document, outside Shadow DOM");
39
- return;
40
- }
41
- t = n;
42
- } catch (e) {
43
- g.reportInvalidContainer("Toaster container resolver failed", e);
44
- return;
45
- }
46
- let i = r.attention?.delay, a = g.attach(i === void 0 ? void 0 : { attentionDelay: i }), o = a.status === "rejected" && a.reason === "invalid-input";
47
- if (o && (a = g.attach()), a.status !== "attached") return;
48
- o && g.reportDiagnostic(a.lease, {
49
- code: "invalid-input",
50
- source: "Toaster.attention",
51
- message: "attention.delay must be a finite nonnegative number of milliseconds"
52
- });
53
- let s = {
54
- controller: n,
55
- lease: a.lease,
56
- container: t,
57
- document: e
58
- };
59
- return x(s.lease, !1), b(s), () => {
60
- g.detach(s.lease);
25
+ function p(t) {
26
+ let c = n(o);
27
+ if (c === void 0) throw Error("Toaster must be used within a CloudletProvider");
28
+ let [l, u] = i(s);
29
+ return r(() => {
30
+ if (l) return;
31
+ let t = !0;
32
+ return f().then((e) => {
33
+ t && u(e);
34
+ }, (n) => {
35
+ t && c && e(c).reportRendererLoadError(n);
36
+ }), () => {
37
+ t = !1;
61
38
  };
62
- }, [n, f]);
63
- function x(e, t) {
64
- let n = r.autoDismiss, i = n === void 0 || typeof n == "boolean";
65
- g.setAutoDismiss(e, i ? n : void 0), !i && t && g.reportDiagnostic(e, {
66
- code: "invalid-input",
67
- source: "Toaster.autoDismiss",
68
- message: "autoDismiss must be a boolean"
69
- });
70
- }
71
- return i(() => {
72
- y && x(y.lease, !0);
73
- }, [y, r.autoDismiss]), f ? /* @__PURE__ */ d(l, { children: [/* @__PURE__ */ u("template", { ref: v }), y?.controller === n && !_.disposed ? c(/* @__PURE__ */ u(t, {
74
- bridge: g,
75
- lease: y.lease,
76
- snapshot: _,
77
- options: r,
78
- document: y.document
79
- }, y.lease), y.container) : null] }) : null;
39
+ }, [l, c]), c && l ? /* @__PURE__ */ a(l.AttachedToaster, {
40
+ controller: c,
41
+ options: t
42
+ }) : null;
80
43
  }
81
44
  //#endregion
82
- export { g as CloudletProvider, y as Toaster, _ as useCloudlet, v as useOptionalCloudlet };
45
+ export { l as CloudletProvider, p as Toaster, f as loadRenderer, u as useCloudlet, d as useOptionalCloudlet };
83
46
 
84
47
  //# sourceMappingURL=bindings.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bindings.js","names":["_Fragment","CloudletContext","createContext","subscribeMount","clientMounted","serverMounted","CloudletProvider","controller","useCloudlet","useContext","useOptionalCloudlet","Toaster","AttachedToaster","mounted","useSyncExternalStore","bridge","getRendererBridge","snapshot","marker","useRef","attachment","setAttachment","useState","ownerDocument","container","candidate","options","error","delay","attached","invalidDelay","current","applyAutoDismiss","value","valid","lease","report","useEffect","Fragment","createPortal","Host"],"sources":["../../src/react/bindings.tsx"],"sourcesContent":["import { createContext, useContext, useEffect, useRef, useState, useSyncExternalStore } from 'react';\nimport type { ReactElement } from 'react';\nimport { createPortal } from 'react-dom';\nimport { getRendererBridge } from '../core/controller.js';\nimport type { HostLease } from '../contracts/internal.js';\nimport type { CloudletProviderProps, ReactCloudletController, ToasterProps } from '../react.js';\nimport { Host } from './host.js';\n\n/** Undefined outside a provider; null inside one whose controller does not exist yet. */\nconst CloudletContext = createContext<ReactCloudletController | null | undefined>(undefined);\nconst subscribeMount = () => () => {};\nconst clientMounted = () => true;\nconst serverMounted = () => false;\n\nexport function CloudletProvider({ controller, children }: CloudletProviderProps): ReactElement {\n return <CloudletContext.Provider value={controller}>{children}</CloudletContext.Provider>;\n}\n\nexport function useCloudlet(): ReactCloudletController {\n const controller = useContext(CloudletContext);\n if (!controller) throw new Error('useCloudlet must be used within a CloudletProvider that has a controller');\n return controller;\n}\n\n/** The controller, or null outside a provider and while the provider's controller is null. */\nexport function useOptionalCloudlet(): ReactCloudletController | null {\n return useContext(CloudletContext) ?? null;\n}\n\ninterface Attachment {\n readonly controller: ReactCloudletController;\n readonly lease: HostLease;\n readonly container: Element;\n readonly document: Document;\n}\n\nexport function Toaster(options: ToasterProps): ReactElement | null {\n const controller = useContext(CloudletContext);\n if (controller === undefined) throw new Error('Toaster must be used within a CloudletProvider');\n // A provider without a controller yet (server, first client render) renders nothing.\n return controller ? <AttachedToaster controller={controller} options={options} /> : null;\n}\n\nfunction AttachedToaster({ controller, options }: { controller: ReactCloudletController; options: ToasterProps }): ReactElement | null {\n // React supplies the server value during hydration, then the client value.\n // The inert marker can therefore identify the owner document without a store\n // or effect whose only purpose is an extra mounting render.\n const mounted = useSyncExternalStore(subscribeMount, clientMounted, serverMounted);\n const bridge = getRendererBridge(controller);\n const snapshot = useSyncExternalStore(bridge.subscribe, bridge.getSnapshot, bridge.getServerSnapshot);\n const marker = useRef<HTMLTemplateElement>(null);\n const [attachment, setAttachment] = useState<Attachment | null>(null);\n useEffect(() => {\n if (!mounted || !marker.current) return;\n const ownerDocument = marker.current.ownerDocument;\n let container: Element;\n try {\n const requested = typeof options.container === 'function' ? options.container() : options.container;\n const candidate = requested ?? ownerDocument.body;\n // nodeType/ownerDocument also work when the mounting React root is in another realm.\n if (!candidate || candidate.nodeType !== 1 || candidate.ownerDocument !== ownerDocument\n || candidate.namespaceURI !== 'http://www.w3.org/1999/xhtml' || !candidate.isConnected\n || candidate.getRootNode().nodeType === 11) {\n bridge.reportInvalidContainer('Toaster container must be a connected HTML Element in the mounting document, outside Shadow DOM');\n return;\n }\n container = candidate;\n } catch (error) {\n bridge.reportInvalidContainer('Toaster container resolver failed', error);\n return;\n }\n const delay = options.attention?.delay;\n let attached = bridge.attach(delay === undefined ? undefined : { attentionDelay: delay });\n // An invalid delay must not suppress the host: fall back to the controller default and report it.\n const invalidDelay = attached.status === 'rejected' && attached.reason === 'invalid-input';\n if (invalidDelay) attached = bridge.attach();\n if (attached.status !== 'attached') return;\n if (invalidDelay) bridge.reportDiagnostic(attached.lease, { code: 'invalid-input', source: 'Toaster.attention',\n message: 'attention.delay must be a finite nonnegative number of milliseconds' });\n const current = { controller, lease: attached.lease, container, document: ownerDocument };\n applyAutoDismiss(current.lease, false);\n setAttachment(current);\n return () => { bridge.detach(current.lease); };\n // Container and attention delay are fixed for this attachment; changing them requires remount.\n }, [controller, mounted]);\n // Applied before the first presentation, then whenever the prop changes (which reports an invalid value once).\n function applyAutoDismiss(lease: HostLease, report: boolean) {\n const value = options.autoDismiss;\n const valid = value === undefined || typeof value === 'boolean';\n bridge.setAutoDismiss(lease, valid ? value : undefined);\n if (!valid && report) bridge.reportDiagnostic(lease, { code: 'invalid-input', source: 'Toaster.autoDismiss',\n message: 'autoDismiss must be a boolean' });\n }\n useEffect(() => { if (attachment) applyAutoDismiss(attachment.lease, true); }, [attachment, options.autoDismiss]);\n\n if (!mounted) return null;\n return <><template ref={marker} />{attachment?.controller === controller && !snapshot.disposed\n ? createPortal(<Host key={attachment.lease} bridge={bridge} lease={attachment.lease} snapshot={snapshot}\n options={options} document={attachment.document} />, attachment.container) : null}</>;\n}\n"],"mappings":";;;;;;AASA,IAAMC,IAAkBC,EAA0D,KAAA,CAAS,GACrFC,gBAA6B,CAAC,GAC9BC,UAAsB,IACtBC,UAAsB;AAE5B,SAAgBC,EAAi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CloudletProvider","controller","useCloudlet","useContext","useOptionalCloudlet","loadRenderer","module","error","Toaster","loaded","setLoaded","useState","useEffect","live","getControllerKernel"],"sources":["../../src/react/bindings.tsx"],"sourcesContent":["import { createContext, useContext, useEffect, useState } from 'react';\nimport type { ReactElement } from 'react';\nimport { getControllerKernel } from '../core/controller.js';\nimport type { CloudletProviderProps, ReactCloudletController, ToasterProps } from '../react.js';\n\ntype Renderer = typeof import('./renderer.js');\n\n/** Undefined outside a provider; null inside one whose controller does not exist yet. */\nconst CloudletContext = createContext<ReactCloudletController | null | undefined>(undefined);\nlet renderer: Renderer | undefined;\nlet loading: Promise<Renderer> | undefined;\n\nexport function CloudletProvider({ controller, children }: CloudletProviderProps): ReactElement {\n return <CloudletContext.Provider value={controller}>{children}</CloudletContext.Provider>;\n}\n\nexport function useCloudlet(): ReactCloudletController {\n const controller = useContext(CloudletContext);\n if (!controller) throw new Error('useCloudlet must be used within a CloudletProvider that has a controller');\n return controller;\n}\n\n/** The controller, or null outside a provider and while the provider's controller is null. */\nexport function useOptionalCloudlet(): ReactCloudletController | null {\n return useContext(CloudletContext) ?? null;\n}\n\n/** Fetches the renderer chunk once for every Toaster; after a failure the next attempt fetches again. */\nexport function loadRenderer(): Promise<Renderer> {\n loading ??= import('./renderer.js').then((module) => (renderer = module), (error: unknown) => {\n loading = undefined;\n throw error;\n });\n return loading;\n}\n\n/**\n * The renderer stays out of the start bundle: the chunk loads after mount, and\n * notifications shown meanwhile wait in the controller. On the server and during\n * hydration this renders nothing, exactly like the attached renderer does.\n */\nexport function Toaster(options: ToasterProps): ReactElement | null {\n const controller = useContext(CloudletContext);\n if (controller === undefined) throw new Error('Toaster must be used within a CloudletProvider');\n const [loaded, setLoaded] = useState(renderer);\n useEffect(() => {\n if (loaded) return;\n let live = true;\n loadRenderer().then((module) => { if (live) setLoaded(module); }, (error: unknown) => {\n if (live && controller) getControllerKernel(controller).reportRendererLoadError(error);\n });\n return () => { live = false; };\n }, [loaded, controller]);\n // A provider without a controller yet (server, first client render) renders nothing.\n return controller && loaded ? <loaded.AttachedToaster controller={controller} options={options} /> : null;\n}\n"],"mappings":";;;;AAQA,IAAMA,IAAkBC,EAA0D,KAAA,CAAS,GACvFC,GACAC;AAEJ,SAAgBC,EAAiB,EAAE,eAAY,eAAiD;CAC9F,OAAO,kBAACJ,EAAgB,UAAjB;EAA0B,OAAOK;EAAa;CAAmC,CAAA;AAC1F;AAEA,SAAgBC,IAAuC;CACrD,IAAMD,IAAaE,EAAWP,CAAe;CAC7C,IAAI,CAACK,GAAY,MAAU,MAAM,0EAA0E;CAC3G,OAAOA;AACT;AAGA,SAAgBG,IAAsD;CACpE,OAAOD,EAAWP,CAAe,KAAK;AACxC;AAGA,SAAgBS,IAAkC;CAKhD,OAJA,MAAY,OAAO,gBAAgB,CAAC,MAAM,MAAY,IAAWC,IAAU,MAAmB;EAE5F,MADA,IAAU,KAAA,GACJC;CACR,CAAC,GACMR;AACT;AAOA,SAAgBS,EAAQ,GAA4C;CAClE,IAAMP,IAAaE,EAAWP,CAAe;CAC7C,IAAIK,MAAe,KAAA,GAAW,MAAU,MAAM,gDAAgD;CAC9F,IAAM,CAACQ,GAAQC,KAAaC,EAASb,CAAQ;CAU7C,OATAc,QAAgB;EACd,IAAIH,GAAQ;EACZ,IAAII,IAAO;EAIX,OAHAR,EAAa,CAAC,CAAC,MAAM,MAAW;GAAE,AAAIQ,KAAMH,EAAUJ,CAAM;EAAG,IAAI,MAAmB;GACpF,AAAIO,KAAQZ,KAAYa,EAAoBb,CAAU,CAAC,CAAC,wBAAwBM,CAAK;EACvF,CAAC,SACY;GAAE,IAAO;EAAO;CAC/B,GAAG,CAACE,GAAQR,CAAU,CAAC,GAEhBA,KAAcQ,IAAS,kBAACA,EAAO,iBAAR;EAAoC;EAAqB;CAAU,CAAA,IAAI;AACvG"}
@@ -1,5 +1,5 @@
1
1
  import type { ReactNode } from 'react';
2
- import type { HostLease, RendererBridge } from '../contracts/internal.js';
2
+ import type { FormDraft, HostLease, RendererBridge } from '../contracts/internal.js';
3
3
  import type { NotificationHandle } from '../contracts/identity.js';
4
4
  import type { NotificationSnapshot } from '../contracts/snapshots.js';
5
5
  import type { CloudletLabels, CloudletPart, ToasterProps } from '../react.js';
@@ -35,7 +35,7 @@ export declare function Heading({ notification, slot, part, titleId }: {
35
35
  /** Rich content of the inert neighbour preview: rendered as is, never checked or reported twice. */
36
36
  export declare const previewSlot: (value: ReactNode) => import("react").JSX.Element;
37
37
  /**
38
- * The neighbour shown only while a finger drags the Island content (DESIGN §3, §9):
38
+ * The neighbour shown only while a finger drags the Island content:
39
39
  * the same layout as a live slide, but every control is a lookalike without
40
40
  * handlers, ids, links or tab stops. The caller puts it in an `inert` container.
41
41
  */
@@ -45,14 +45,16 @@ export declare function SlidePreview({ notification, labels, part }: {
45
45
  part: PartClass;
46
46
  }): import("react").JSX.Element;
47
47
  /** Island slide body: description, progress, actions and the action error. */
48
- export declare function Body({ notification, bridge, lease, labels, navigate, slot, part }: {
48
+ export declare function Body({ notification, form, bridge, lease, labels, navigate, slot, part, titleId }: {
49
49
  notification: NotificationSnapshot<ReactNode>;
50
+ form: FormDraft | undefined;
50
51
  bridge: RendererBridge<ReactNode>;
51
52
  lease: HostLease;
52
53
  labels: CloudletLabels;
53
54
  navigate: (handle: NotificationHandle) => void;
54
55
  slot: (value: ReactNode) => ReactNode;
55
56
  part: PartClass;
57
+ titleId: string;
56
58
  }): import("react").JSX.Element;
57
59
  export declare function closeButton(labels: CloudletLabels, part: PartClass, onClick: () => void): import("react").JSX.Element;
58
60
  //# sourceMappingURL=card.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"card.d.ts","sourceRoot":"","sources":["../../src/react/card.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAyB,SAAS,EAAE,MAAM,OAAO,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1E,OAAO,KAAK,EAAE,kBAAkB,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