@cloudlet/toast 1.3.0 → 1.4.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +112 -0
- package/README.md +5 -1
- package/dist/agent.d.ts +334 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +494 -0
- package/dist/agent.js.map +1 -0
- package/dist/contracts/events.d.ts +14 -0
- package/dist/contracts/events.d.ts.map +1 -1
- package/dist/contracts/internal.d.ts +16 -2
- package/dist/contracts/internal.d.ts.map +1 -1
- package/dist/contracts/notifications.d.ts +16 -0
- package/dist/contracts/notifications.d.ts.map +1 -1
- package/dist/contracts/snapshots.d.ts +8 -0
- package/dist/contracts/snapshots.d.ts.map +1 -1
- package/dist/core/actions.d.ts +69 -0
- package/dist/core/actions.d.ts.map +1 -0
- package/dist/core/actions.js +160 -0
- package/dist/core/actions.js.map +1 -0
- package/dist/core/agent-port.d.ts +116 -0
- package/dist/core/agent-port.d.ts.map +1 -0
- package/dist/core/agent-port.js +138 -0
- package/dist/core/agent-port.js.map +1 -0
- package/dist/core/bridge.d.ts.map +1 -1
- package/dist/core/bridge.js +120 -231
- package/dist/core/bridge.js.map +1 -1
- package/dist/core/controller.d.ts +44 -9
- package/dist/core/controller.d.ts.map +1 -1
- package/dist/core/controller.js +367 -292
- package/dist/core/controller.js.map +1 -1
- package/dist/core/validation.d.ts.map +1 -1
- package/dist/core/validation.js +103 -94
- package/dist/core/validation.js.map +1 -1
- package/dist/react/card.d.ts.map +1 -1
- package/dist/react/card.js +3 -3
- package/dist/react/card.js.map +1 -1
- package/dist/react/host.d.ts.map +1 -1
- package/dist/react/host.js +257 -246
- package/dist/react/host.js.map +1 -1
- package/dist/react.d.ts +7 -0
- package/dist/react.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/agent.ts +879 -0
- package/src/contracts/events.ts +15 -0
- package/src/contracts/internal.ts +14 -1
- package/src/contracts/notifications.ts +16 -0
- package/src/contracts/snapshots.ts +8 -0
- package/src/core/actions.ts +149 -0
- package/src/core/agent-port.ts +237 -0
- package/src/core/bridge.ts +19 -105
- package/src/core/controller.ts +183 -56
- package/src/core/validation.ts +6 -3
- package/src/react/card.tsx +4 -3
- package/src/react/host.tsx +26 -3
- package/src/react.ts +7 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { UNCHANGED as e, getControllerKernel as t, reject as n } from "./controller.js";
|
|
2
|
+
import { fillFormValue as r, invokeAction as i } from "./actions.js";
|
|
3
|
+
//#region src/core/agent-port.ts
|
|
4
|
+
var a = Object.freeze, o = {
|
|
5
|
+
allow: 0,
|
|
6
|
+
confirm: 1,
|
|
7
|
+
deny: 2
|
|
8
|
+
};
|
|
9
|
+
function s(i) {
|
|
10
|
+
let o = t(i), s, l = !1, u, d = () => {
|
|
11
|
+
let e = o.rendererSnapshot, t = o.lease !== null;
|
|
12
|
+
if (u && e === s && t === l) return u;
|
|
13
|
+
s = e, l = t;
|
|
14
|
+
let n = /* @__PURE__ */ new Map();
|
|
15
|
+
for (let t of e.forms) {
|
|
16
|
+
let e = new Set(Object.keys(t.values).filter((e) => t.values[e].trim() !== ""));
|
|
17
|
+
n.set(t.handle, a({
|
|
18
|
+
filled: e,
|
|
19
|
+
authors: new Map(Object.entries(t.authors)),
|
|
20
|
+
errors: t.errors
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
return u = a({
|
|
24
|
+
controller: e,
|
|
25
|
+
mounted: l,
|
|
26
|
+
busy: o.interacting(),
|
|
27
|
+
forms: n
|
|
28
|
+
}), u;
|
|
29
|
+
}, f = o.withRecord;
|
|
30
|
+
return a({
|
|
31
|
+
read: d,
|
|
32
|
+
subscribe: (e) => o.subscribe(() => {
|
|
33
|
+
let t = o.announced;
|
|
34
|
+
t && e({
|
|
35
|
+
events: t.deliveries.filter((e) => !("callback" in e)),
|
|
36
|
+
controller: t.snapshot,
|
|
37
|
+
authors: new Map(t.snapshot.forms.map((e) => [e.handle, new Map(Object.entries(e.authors))])),
|
|
38
|
+
closedBy: t.closedBy
|
|
39
|
+
});
|
|
40
|
+
}),
|
|
41
|
+
open() {
|
|
42
|
+
if (o.disposed) return n("disposed");
|
|
43
|
+
if (o.lease === null) return n("no-host");
|
|
44
|
+
let t = o.newest();
|
|
45
|
+
return t ? o.island ? e : o.interacting() ? n("busy") : o.mutate(() => {
|
|
46
|
+
o.island = {
|
|
47
|
+
reason: "attention",
|
|
48
|
+
current: t,
|
|
49
|
+
source: "agent"
|
|
50
|
+
};
|
|
51
|
+
}) : n("empty");
|
|
52
|
+
},
|
|
53
|
+
close() {
|
|
54
|
+
return o.disposed ? n("disposed") : o.island ? o.dirty(o.island.current) ? n("busy") : o.mutate(() => {
|
|
55
|
+
o.collapse("agent");
|
|
56
|
+
}) : e;
|
|
57
|
+
},
|
|
58
|
+
show: f((t) => o.lease === null ? n("no-host") : o.island?.current === t ? e : o.interacting() ? n("busy") : o.mutate(() => o.reach(t, "agent"))),
|
|
59
|
+
summon: f((e) => o.lease === null ? n("no-host") : a({ status: o.summon(e) })),
|
|
60
|
+
dismiss: (e) => o.dismiss(e, "programmatic", "agent"),
|
|
61
|
+
clear: () => o.clear("clear", "agent"),
|
|
62
|
+
acknowledge: () => o.acknowledgeOverflow("agent"),
|
|
63
|
+
cancel: f((e) => e.operation ? e.operation.cancel(void 0, "agent") : n("no-operation")),
|
|
64
|
+
retry: f((e) => {
|
|
65
|
+
if (!e.operation) return n("no-operation");
|
|
66
|
+
let t = e.operation.retry("agent");
|
|
67
|
+
return t.status === "started" ? a({ status: "started" }) : n(t.reason);
|
|
68
|
+
}),
|
|
69
|
+
fill: f((e, t, n) => r(o, e, t, n)),
|
|
70
|
+
press: f((e, t, n) => c(o, e, t, n))
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function c(e, t, r, s) {
|
|
74
|
+
let c = t.content.action;
|
|
75
|
+
if (!c || c.kind === "link") return n("no-command");
|
|
76
|
+
if (o[c.agent ?? "confirm"] > o[r]) return n("stale");
|
|
77
|
+
if (t.action.status === "pending") return n("already-pending");
|
|
78
|
+
if (s.aborted) return Promise.resolve(a({
|
|
79
|
+
status: "pending",
|
|
80
|
+
gone: !1
|
|
81
|
+
}));
|
|
82
|
+
let l = t.handle;
|
|
83
|
+
return new Promise((n) => {
|
|
84
|
+
let r = !1, o, c = (e) => {
|
|
85
|
+
r || (r = !0, f(), d(), s.removeEventListener("abort", u), n(a(e)));
|
|
86
|
+
}, u = () => {
|
|
87
|
+
c({
|
|
88
|
+
status: "pending",
|
|
89
|
+
gone: e.records.get(l.id) !== t
|
|
90
|
+
});
|
|
91
|
+
}, d = e.onEvent((e) => {
|
|
92
|
+
e.type === "closed" && e.handle === l && c(e.reason === "action-success" ? { status: "done" } : {
|
|
93
|
+
status: "pending",
|
|
94
|
+
gone: !0
|
|
95
|
+
});
|
|
96
|
+
}), f = e.subscribe(() => {
|
|
97
|
+
if (o === void 0 || e.records.get(l.id) !== t) return;
|
|
98
|
+
let n = t.action;
|
|
99
|
+
n.status === "failed" && n.token === o ? c({
|
|
100
|
+
status: "failed",
|
|
101
|
+
message: n.message
|
|
102
|
+
}) : (n.status === "idle" || n.token !== o) && c({
|
|
103
|
+
status: "pending",
|
|
104
|
+
gone: !1
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
s.addEventListener("abort", u, { once: !0 });
|
|
108
|
+
let p = i(e, t, "agent");
|
|
109
|
+
if (p.status === "invalid") {
|
|
110
|
+
c({
|
|
111
|
+
status: "invalid",
|
|
112
|
+
errors: p.errors
|
|
113
|
+
});
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (p.status !== "started") {
|
|
117
|
+
c(p.reason === "action-replaced" ? { status: "replaced" } : {
|
|
118
|
+
status: "pending",
|
|
119
|
+
gone: e.records.get(l.id) !== t
|
|
120
|
+
});
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (r) return;
|
|
124
|
+
o = p.token;
|
|
125
|
+
let m = t.action;
|
|
126
|
+
m.status === "failed" && m.token === o ? c({
|
|
127
|
+
status: "failed",
|
|
128
|
+
message: m.message
|
|
129
|
+
}) : m.status === "idle" || m.token !== o ? c({
|
|
130
|
+
status: "pending",
|
|
131
|
+
gone: !1
|
|
132
|
+
}) : s.aborted && u();
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
136
|
+
export { s as createToasterPort };
|
|
137
|
+
|
|
138
|
+
//# sourceMappingURL=agent-port.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-port.js","names":["freeze","STRICTNESS","createToasterPort","k","getControllerKernel","controller","source","mounted","reading","read","next","lease","forms","form","filled","name","withRecord","commit","listener","delivery","reject","record","UNCHANGED","handle","result","fillFormValue","value","press","grant","signal","action","settled","token","finish","stopState","stopEvents","abort","resolve","outcome","event","state","started","invokeAction"],"sources":["../../src/core/agent-port.ts"],"sourcesContent":["import type { ChangeSource } from '../contracts/events.js';\nimport type { NotificationHandle } from '../contracts/identity.js';\nimport type { FormErrors, RendererSnapshot } from '../contracts/internal.js';\nimport type { CancellationSignal, CancelResult } from '../contracts/operations.js';\nimport type { ControllerSnapshot } from '../contracts/snapshots.js';\nimport { fillFormValue, invokeAction } from './actions.js';\nimport { UNCHANGED, getControllerKernel, reject, type ControllerKernel, type EventPayload, type FieldAuthor, type RecordState } from './controller.js';\n\n// The agent adapter's way into a controller. Only the `agent` entry imports it, so the root entry\n// and the renderer chunk never carry it. It hands out no lease: a step that needs a screen only\n// checks that a `Toaster` holds one, and no step asks for focus. Form values reach the adapter only\n// as \"holds text\" and who wrote them: `forms` is reduced here, and `controller` is typed as the\n// public snapshot, although at runtime it is the renderer's object with its form drafts.\n\nconst freeze = Object.freeze;\n\n/** What a reader may know about a form: which fields hold text, who wrote them, the last submit's messages. */\nexport interface FormReading {\n /** Names of the fields whose value has non-blank text, the same test `required` uses. */\n readonly filled: ReadonlySet<string>;\n /** Who wrote each field last; a field nobody wrote and without a default is missing. */\n readonly authors: ReadonlyMap<string, FieldAuthor>;\n readonly errors: FormErrors;\n}\n\nexport interface ToasterReading<Slot> {\n readonly controller: ControllerSnapshot<Slot>;\n /** A `Toaster` holds the controller's host lease. */\n readonly mounted: boolean;\n /** A person is on the Toaster: hover, focus, a gesture, or a draft in the open Island. */\n readonly busy: boolean;\n /** One entry per record with a form action. */\n readonly forms: ReadonlyMap<NotificationHandle, FormReading>;\n}\n\n/** An event as the commit queued it: its type, source and fields, before it is stamped and delivered. */\nexport type PortEvent = EventPayload;\n\n/**\n * One committed change: its events and the state it left. A listener of an earlier commit may have\n * committed again, so `read()` can be ahead of this state.\n */\nexport interface PortCommit<Slot> {\n readonly events: readonly PortEvent[];\n readonly controller: ControllerSnapshot<Slot>;\n /** Who wrote each field of each form last; never a value. */\n readonly authors: ReadonlyMap<NotificationHandle, ReadonlyMap<string, FieldAuthor>>;\n /** Who closed the Island last; null before the first close. */\n readonly closedBy: ChangeSource | null;\n}\n\n/** The grant a step was approved under; a marker stricter than it stops the step. */\nexport type StepGrant = 'allow' | 'confirm';\n\ntype Rejection<Reason extends string> = { readonly status: 'rejected'; readonly reason: Reason };\ntype HandleReason = 'disposed' | 'invalid-handle' | 'foreign-controller' | 'stale-handle';\ntype Changed = { readonly status: 'applied' | 'unchanged' };\n\n/** How a pressed command or a submitted form ended, as far as the step waited for it. */\nexport type PressOutcome =\n /** The action succeeded and closed its notification. */\n | { readonly status: 'done' }\n /** The action failed; `message` is what the person sees. */\n | { readonly status: 'failed'; readonly message: string }\n /** The form did not pass its checks and was not sent; the person sees the same messages. */\n | { readonly status: 'invalid'; readonly errors: FormErrors }\n /** The form's `validate` replaced the action it was checking; neither ran. */\n | { readonly status: 'replaced' }\n /** The step stopped waiting: the notification closed otherwise, the action was replaced, or the signal ended the wait. */\n | { readonly status: 'pending'; readonly gone: boolean };\n\nexport interface ToasterPort<Slot> {\n /** The same object until the controller publishes again. */\n readonly read: () => ToasterReading<Slot>;\n /**\n * Calls `listener` after every committed change with that commit's events and state, so a reader\n * learns what happened and who did it together with the new state. The controller delivers the\n * events themselves only after its state listeners.\n */\n readonly subscribe: (listener: (commit: PortCommit<Slot>) => void) => () => void;\n /** Opens the Island on the top notification, unless a person is busy with the Toaster. */\n readonly open: () => Changed | Rejection<'disposed' | 'no-host' | 'empty' | 'busy'>;\n /** Collapses the Island, unless it holds a draft. */\n readonly close: () => Changed | Rejection<'disposed' | 'busy'>;\n /** Opens the Island on the notification or moves the open one to it, unless a person is busy. */\n readonly show: (handle: NotificationHandle) => Changed | Rejection<HandleReason | 'no-host' | 'busy'>;\n /**\n * Brings the notification in front of the person for a step only they may take: opens the Island\n * on it now, or once they stop interacting (`waiting`). Never moves focus.\n */\n readonly summon: (handle: NotificationHandle) => { readonly status: 'shown' | 'waiting' | 'unchanged' } | Rejection<HandleReason | 'no-host'>;\n readonly dismiss: (handle: NotificationHandle) => Changed | Rejection<HandleReason>;\n readonly clear: () => { readonly status: 'cleared'; readonly count: number } | Rejection<'disposed'>;\n readonly acknowledge: () => Changed | Rejection<'disposed'>;\n readonly cancel: (handle: NotificationHandle) => CancelResult | Rejection<HandleReason | 'no-operation'>;\n readonly retry: (handle: NotificationHandle) => { readonly status: 'started' } | Rejection<HandleReason | 'no-operation' | 'not-retryable' | 'already-pending'>;\n /** Writes a form field as an agent, never over what the person typed. */\n readonly fill: (handle: NotificationHandle, name: string, value: string)\n => Changed | Rejection<HandleReason | 'no-form' | 'invalid-input' | 'already-pending' | 'too-long' | 'person-typed'>;\n /**\n * Starts the command or submits the form, and waits until it settles, its notification closes or\n * `signal` aborts.\n */\n readonly press: (handle: NotificationHandle, grant: StepGrant, signal: CancellationSignal)\n => Promise<PressOutcome> | Rejection<HandleReason | 'no-command' | 'already-pending' | 'stale'>;\n}\n\nconst STRICTNESS = { allow: 0, confirm: 1, deny: 2 } as const;\n\n/** Throws a TypeError for a controller this package instance did not create. */\nexport function createToasterPort<Slot>(controller: object): ToasterPort<Slot> {\n const k = getControllerKernel<Slot>(controller);\n let source: RendererSnapshot<Slot> | undefined;\n let mounted = false;\n let reading: ToasterReading<Slot> | undefined;\n\n const read = (): ToasterReading<Slot> => {\n // Every change of the lease or of what `interacting` reads publishes a new renderer snapshot.\n const next = k.rendererSnapshot;\n const lease = k.lease !== null;\n if (reading && next === source && lease === mounted) return reading;\n source = next;\n mounted = lease;\n const forms = new Map<NotificationHandle, FormReading>();\n for (const form of next.forms) {\n const filled = new Set(Object.keys(form.values).filter((name) => form.values[name]!.trim() !== ''));\n forms.set(form.handle, freeze({ filled, authors: new Map(Object.entries(form.authors)), errors: form.errors }));\n }\n reading = freeze({ controller: next, mounted, busy: k.interacting(), forms });\n return reading;\n };\n\n const withRecord = k.withRecord;\n\n return freeze<ToasterPort<Slot>>({\n read,\n subscribe: (listener) => k.subscribe(() => {\n const commit = k.announced;\n if (!commit) return;\n listener({\n events: commit.deliveries.filter((delivery): delivery is PortEvent => !('callback' in delivery)),\n controller: commit.snapshot,\n authors: new Map(commit.snapshot.forms.map((form) => [form.handle, new Map(Object.entries(form.authors))])),\n closedBy: commit.closedBy,\n });\n }),\n open() {\n if (k.disposed) return reject('disposed');\n if (k.lease === null) return reject('no-host');\n const record = k.newest();\n if (!record) return reject('empty');\n if (k.island) return UNCHANGED;\n if (k.interacting()) return reject('busy');\n return k.mutate(() => { k.island = { reason: 'attention', current: record, source: 'agent' }; });\n },\n close() {\n if (k.disposed) return reject('disposed');\n if (!k.island) return UNCHANGED;\n // A person's Escape collapses an Island with a draft; an agent is not that person.\n if (k.dirty(k.island.current)) return reject('busy');\n return k.mutate(() => { k.collapse('agent'); });\n },\n show: withRecord((record) => {\n if (k.lease === null) return reject('no-host');\n if (k.island?.current === record) return UNCHANGED;\n if (k.interacting()) return reject('busy');\n // Showing is navigation, as in the renderer: reaching the pending auto-open's record fulfils\n // it, and any other pending auto-open restarts its delay.\n return k.mutate(() => k.reach(record, 'agent'));\n }),\n summon: withRecord((record) => k.lease === null ? reject('no-host') : freeze({ status: k.summon(record) })),\n dismiss: (handle) => k.dismiss(handle, 'programmatic', 'agent'),\n clear: () => k.clear('clear', 'agent'),\n acknowledge: () => k.acknowledgeOverflow('agent'),\n // The current attempt's own capability: no token leaves the port.\n cancel: withRecord((record) => record.operation ? record.operation.cancel(undefined, 'agent') : reject('no-operation')),\n retry: withRecord((record) => {\n if (!record.operation) return reject('no-operation');\n const result = record.operation.retry('agent');\n return result.status === 'started' ? freeze({ status: 'started' as const }) : reject(result.reason);\n }),\n fill: withRecord((record, name: string, value: string) => fillFormValue(k, record, name, value)),\n press: withRecord((record, grant: StepGrant, signal: CancellationSignal) => press(k, record, grant, signal)),\n });\n}\n\nfunction press<Slot>(k: ControllerKernel<Slot>, record: RecordState<Slot>, grant: StepGrant, signal: CancellationSignal) {\n const action = record.content.action;\n if (!action || action.kind === 'link') return reject('no-command');\n // The marker is read from the record's content right before the action runs: one the app made\n // stricter after the step was approved stops it.\n if (STRICTNESS[action.agent ?? 'confirm'] > STRICTNESS[grant]) return reject('stale');\n if (record.action.status === 'pending') return reject('already-pending');\n // A wait that has already ended starts nothing.\n if (signal.aborted) return Promise.resolve<PressOutcome>(freeze({ status: 'pending', gone: false }));\n const handle = record.handle;\n return new Promise<PressOutcome>((resolve) => {\n let settled = false;\n let token: string | undefined;\n const finish = (outcome: PressOutcome): void => {\n if (settled) return;\n settled = true;\n stopState();\n stopEvents();\n signal.removeEventListener('abort', abort);\n resolve(freeze(outcome));\n };\n const abort = (): void => { finish({ status: 'pending', gone: k.records.get(handle.id) !== record }); };\n // Only the closing event says why the notification closed; state listeners run before it.\n const stopEvents = k.onEvent((event) => {\n if (event.type === 'closed' && event.handle === handle) {\n finish(event.reason === 'action-success' ? { status: 'done' } : { status: 'pending', gone: true });\n }\n });\n const stopState = k.subscribe(() => {\n if (token === undefined || k.records.get(handle.id) !== record) return;\n const state = record.action;\n if (state.status === 'failed' && state.token === token) finish({ status: 'failed', message: state.message });\n else if (state.status === 'idle' || state.token !== token) finish({ status: 'pending', gone: false });\n });\n signal.addEventListener('abort', abort, { once: true });\n // Listeners first: the command may close or replace its notification synchronously.\n const started = invokeAction(k, record, 'agent');\n if (started.status === 'invalid') { finish({ status: 'invalid', errors: started.errors }); return; }\n if (started.status !== 'started') {\n finish(started.reason === 'action-replaced' ? { status: 'replaced' } : { status: 'pending', gone: k.records.get(handle.id) !== record });\n return;\n }\n if (settled) return;\n // This press's own attempt: a listener of `action-started` may already have begun another one.\n token = started.token;\n const state = record.action;\n if (state.status === 'failed' && state.token === token) finish({ status: 'failed', message: state.message });\n else if (state.status === 'idle' || state.token !== token) finish({ status: 'pending', gone: false });\n else if (signal.aborted) abort();\n });\n}\n"],"mappings":";;;AAcA,IAAMA,IAAS,OAAO,QA6FhBC,IAAa;CAAE,OAAO;CAAG,SAAS;CAAG,MAAM;AAAE;AAGnD,SAAgBC,EAAwB,GAAuC;CAC7E,IAAMC,IAAIC,EAA0BC,CAAU,GAC1CC,GACAC,IAAU,IACVC,GAEEC,UAAmC;EAEvC,IAAMC,IAAOP,EAAE,kBACTQ,IAAQR,EAAE,UAAU;EAC1B,IAAIK,KAAWE,MAASJ,KAAUK,MAAUJ,GAAS,OAAOC;EAE5D,AADA,IAASE,GACT,IAAUC;EACV,IAAMC,oBAAQ,IAAI,IAAqC;EACvD,KAAK,IAAMC,KAAQH,EAAK,OAAO;GAC7B,IAAMI,IAAS,IAAI,IAAI,OAAO,KAAKD,EAAK,MAAM,CAAC,CAAC,QAAQ,MAASA,EAAK,OAAOE,EAAK,CAAE,KAAK,MAAM,EAAE,CAAC;GAClG,EAAM,IAAIF,EAAK,QAAQb,EAAO;IAAE;IAAQ,SAAS,IAAI,IAAI,OAAO,QAAQa,EAAK,OAAO,CAAC;IAAG,QAAQA,EAAK;GAAO,CAAC,CAAC;EAChH;EAEA,OADA,IAAUb,EAAO;GAAE,YAAYU;GAAM;GAAS,MAAMP,EAAE,YAAY;GAAG;EAAM,CAAC,GACrEK;CACT,GAEMQ,IAA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O,EAAM;EAAQ,CAAC,IAClGA,EAAM,WAAW,UAAUA,EAAM,UAAUR,IAAOC,EAAO;GAAE,QAAQ;GAAW,MAAM;EAAM,CAAC,IAC3FJ,EAAO,WAASO,EAAM;CACjC,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../src/core/bridge.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAES,cAAc,EAClC,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../src/core/bridge.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAES,cAAc,EAClC,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAcrE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,SAAS,kBAAkB,EAAE,UAAU,EAAE,kBAAkB,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,cAAc,CAAC,IAAI,CAAC,CAO7I"}
|
package/dist/core/bridge.js
CHANGED
|
@@ -1,74 +1,36 @@
|
|
|
1
1
|
import { validDelay as e } from "./validation.js";
|
|
2
|
-
import { APPLIED as t,
|
|
2
|
+
import { APPLIED as t, RENDERER_SERVER as n, UNCHANGED as r, getControllerKernel as i, reject as a } from "./controller.js";
|
|
3
|
+
import { invokeAction as o, setFormValue as s } from "./actions.js";
|
|
3
4
|
//#region src/core/bridge.ts
|
|
4
|
-
var
|
|
5
|
-
function
|
|
6
|
-
let t =
|
|
7
|
-
return t || (t =
|
|
5
|
+
var c = Object.freeze, l = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
function u(e) {
|
|
7
|
+
let t = l.get(e);
|
|
8
|
+
return t || (t = d(i(e)), l.set(e, t)), t;
|
|
8
9
|
}
|
|
9
|
-
function
|
|
10
|
-
let
|
|
11
|
-
function u(e) {
|
|
12
|
-
return a.withRecord((t, ...n) => t === a.presented ? e(t, ...n) : o("not-current"));
|
|
13
|
-
}
|
|
10
|
+
function d(i) {
|
|
11
|
+
let l = (e) => i.disposed ? "disposed" : i.lease === null || e !== i.lease ? "stale-lease" : void 0, u = (e) => i.handleError(e) ?? (i.records.get(e.id) === i.presented ? void 0 : "not-current");
|
|
14
12
|
function d(e) {
|
|
15
|
-
return
|
|
13
|
+
return i.withRecord((t, ...n) => t === i.presented ? e(t, ...n) : a("not-current"));
|
|
14
|
+
}
|
|
15
|
+
function f(e) {
|
|
16
|
+
return i.withRecord((t, n, ...r) => {
|
|
16
17
|
let i = t.operation;
|
|
17
|
-
return i ? i.getSnapshot().token === n ? e(i, ...r) :
|
|
18
|
+
return i ? i.getSnapshot().token === n ? e(i, ...r) : a("stale-operation-token") : a("no-operation");
|
|
18
19
|
});
|
|
19
20
|
}
|
|
20
|
-
function
|
|
21
|
+
function p(t) {
|
|
21
22
|
return t === void 0 || typeof t == "object" && !!t && Object.keys(t).every((e) => e === "attentionDelay") && (t.attentionDelay === void 0 || e(t.attentionDelay));
|
|
22
23
|
}
|
|
23
|
-
function
|
|
24
|
+
function m(e) {
|
|
24
25
|
return (t, ...n) => {
|
|
25
|
-
let r =
|
|
26
|
-
return r ?
|
|
26
|
+
let r = l(t);
|
|
27
|
+
return r ? a(r) : e(...n);
|
|
27
28
|
};
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
for (let t of e.action.fields) {
|
|
32
|
-
let i = e.values[t.name] ?? "";
|
|
33
|
-
t.required && !i.trim() ? r[t.name] = n?.fieldRequired ?? "This field is required" : t.maxLength !== void 0 && i.length > t.maxLength && (r[t.name] = n?.fieldTooLong ?? "This text is too long");
|
|
34
|
-
}
|
|
35
|
-
if (Object.keys(r).length) return s({
|
|
36
|
-
form: null,
|
|
37
|
-
fields: s(r)
|
|
38
|
-
});
|
|
39
|
-
if (!e.action.validate) return null;
|
|
40
|
-
let i;
|
|
41
|
-
try {
|
|
42
|
-
i = e.action.validate(e.values);
|
|
43
|
-
} catch (e) {
|
|
44
|
-
return a.failure("callback-error", "action.validate", e, t), s({
|
|
45
|
-
form: n?.actionError ?? "Action failed",
|
|
46
|
-
fields: s({})
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
if (i === !0) return null;
|
|
50
|
-
if (typeof i == "string" && i.trim()) return s({
|
|
51
|
-
form: i,
|
|
52
|
-
fields: s({})
|
|
53
|
-
});
|
|
54
|
-
let o = e.action.fields.map((e) => e.name);
|
|
55
|
-
return typeof i == "object" && i && Object.getPrototypeOf(i) === Object.prototype && Object.entries(i).every(([e, t]) => o.includes(e) && typeof t == "string" && t.trim()) ? Object.keys(i).length ? s({
|
|
56
|
-
form: null,
|
|
57
|
-
fields: s({ ...i })
|
|
58
|
-
}) : null : (a.diagnostic({
|
|
59
|
-
code: "callback-error",
|
|
60
|
-
source: "action.validate",
|
|
61
|
-
handle: t,
|
|
62
|
-
message: "validate must return true, a message, or messages keyed by field name"
|
|
63
|
-
}), s({
|
|
64
|
-
form: n?.actionError ?? "Action failed",
|
|
65
|
-
fields: s({})
|
|
66
|
-
}));
|
|
67
|
-
}
|
|
68
|
-
let h = s({
|
|
69
|
-
renderError: a.options.messages?.renderError ?? "Content unavailable",
|
|
30
|
+
let h = c({
|
|
31
|
+
renderError: i.options.messages?.renderError ?? "Content unavailable",
|
|
70
32
|
reportInvalidContainer(e, t) {
|
|
71
|
-
|
|
33
|
+
i.disposed || i.diagnostic({
|
|
72
34
|
code: "invalid-container",
|
|
73
35
|
source: "Toaster.container",
|
|
74
36
|
message: e,
|
|
@@ -76,61 +38,62 @@ function u(a) {
|
|
|
76
38
|
});
|
|
77
39
|
},
|
|
78
40
|
attach(e) {
|
|
79
|
-
if (
|
|
80
|
-
if (
|
|
41
|
+
if (i.disposed) return a("disposed");
|
|
42
|
+
if (i.lease !== null) return i.diagnostic({
|
|
81
43
|
code: "second-host",
|
|
82
44
|
source: "attach",
|
|
83
45
|
message: "A renderer is already attached"
|
|
84
|
-
}),
|
|
85
|
-
if (!
|
|
86
|
-
let t =
|
|
87
|
-
return
|
|
88
|
-
|
|
46
|
+
}), a("host-exists");
|
|
47
|
+
if (!p(e)) return a("invalid-input");
|
|
48
|
+
let t = i.token();
|
|
49
|
+
return i.mutate(() => {
|
|
50
|
+
i.lease = i.lastLease = t, i.hostDelay = e?.attentionDelay, i.presented && i.assign(i.presented);
|
|
89
51
|
}), {
|
|
90
52
|
status: "attached",
|
|
91
53
|
lease: t
|
|
92
54
|
};
|
|
93
55
|
},
|
|
94
56
|
detach(e) {
|
|
95
|
-
if (
|
|
96
|
-
if (
|
|
97
|
-
let t =
|
|
98
|
-
return t ?
|
|
99
|
-
|
|
100
|
-
for (let e of
|
|
57
|
+
if (i.disposed) return a("disposed");
|
|
58
|
+
if (i.lease === null && i.lastLease !== null && e === i.lastLease) return r;
|
|
59
|
+
let t = l(e);
|
|
60
|
+
return t ? a(t) : i.mutate(() => {
|
|
61
|
+
i.lease = null, i.hostDelay = void 0, i.setHostAutoDismiss(void 0), i.focusRequest = null, i.focused = null, i.globalPauses.clear();
|
|
62
|
+
for (let e of i.records.values()) e.pauses.clear(), e.readable = !1, e.presentation = null;
|
|
101
63
|
});
|
|
102
64
|
},
|
|
103
|
-
getSnapshot: () =>
|
|
104
|
-
getServerSnapshot: () =>
|
|
105
|
-
subscribe:
|
|
106
|
-
onEvent:
|
|
107
|
-
openIsland:
|
|
108
|
-
if (e !== "user" && e !== "attention") return
|
|
65
|
+
getSnapshot: () => i.rendererSnapshot,
|
|
66
|
+
getServerSnapshot: () => n,
|
|
67
|
+
subscribe: i.subscribe,
|
|
68
|
+
onEvent: i.onEvent,
|
|
69
|
+
openIsland: m((e, t) => {
|
|
70
|
+
if (e !== "user" && e !== "attention") return a("invalid-input");
|
|
109
71
|
let n;
|
|
110
|
-
if (t === void 0) n =
|
|
72
|
+
if (t === void 0) n = i.newest();
|
|
111
73
|
else {
|
|
112
|
-
let e =
|
|
113
|
-
if (e) return
|
|
114
|
-
n =
|
|
74
|
+
let e = i.handleError(t);
|
|
75
|
+
if (e) return a(e);
|
|
76
|
+
n = i.records.get(t.id);
|
|
115
77
|
}
|
|
116
|
-
if (!n) return
|
|
117
|
-
let
|
|
118
|
-
return
|
|
119
|
-
|
|
78
|
+
if (!n) return a("empty");
|
|
79
|
+
let o = n;
|
|
80
|
+
return i.island?.current === o ? r : i.mutate(() => {
|
|
81
|
+
i.island ? (i.island.current = o, i.island.source = "user") : i.island = {
|
|
120
82
|
reason: e,
|
|
121
|
-
current:
|
|
83
|
+
current: o,
|
|
84
|
+
source: "user"
|
|
122
85
|
};
|
|
123
86
|
});
|
|
124
87
|
}),
|
|
125
|
-
collapseIsland:
|
|
126
|
-
|
|
127
|
-
}) :
|
|
128
|
-
setAutoDismiss:
|
|
129
|
-
navigate:
|
|
130
|
-
|
|
131
|
-
}) :
|
|
132
|
-
setPause:
|
|
133
|
-
if (!e || typeof e.active != "boolean") return
|
|
88
|
+
collapseIsland: m(() => i.island ? i.mutate(() => {
|
|
89
|
+
i.collapse("user");
|
|
90
|
+
}) : r),
|
|
91
|
+
setAutoDismiss: m((e) => e !== void 0 && typeof e != "boolean" ? a("invalid-input") : i.autoDismissing(e) === i.autoDismissing(i.hostAutoDismiss) ? (i.hostAutoDismiss = e, r) : i.mutate(() => i.setHostAutoDismiss(e))),
|
|
92
|
+
navigate: m(i.withRecord((e) => i.island ? i.island.current === e ? r : i.mutate(() => {
|
|
93
|
+
i.island.current = e, i.island.source = "user", i.attention?.record === e ? i.attention = null : i.attention && (i.attention.waiting = !1, i.attention.due = i.clock.now() + (i.hostDelay ?? i.options.attentionDelay ?? 600));
|
|
94
|
+
}) : a("island-closed"))),
|
|
95
|
+
setPause: m((e) => {
|
|
96
|
+
if (!e || typeof e.active != "boolean") return a("invalid-input");
|
|
134
97
|
let t;
|
|
135
98
|
if (e.scope === "host") {
|
|
136
99
|
if (![
|
|
@@ -138,142 +101,68 @@ function u(a) {
|
|
|
138
101
|
"focus",
|
|
139
102
|
"document-hidden",
|
|
140
103
|
"window-blur"
|
|
141
|
-
].includes(e.reason)) return
|
|
142
|
-
t =
|
|
104
|
+
].includes(e.reason)) return a("invalid-input");
|
|
105
|
+
t = i.globalPauses;
|
|
143
106
|
} else if (e.scope === "notification") {
|
|
144
|
-
let n =
|
|
145
|
-
if (n) return
|
|
146
|
-
if (!["gesture", "content-transition"].includes(e.reason)) return
|
|
147
|
-
t =
|
|
148
|
-
} else return
|
|
149
|
-
return t.has(e.reason) === e.active ?
|
|
107
|
+
let n = u(e.handle);
|
|
108
|
+
if (n) return a(n);
|
|
109
|
+
if (!["gesture", "content-transition"].includes(e.reason)) return a("invalid-input");
|
|
110
|
+
t = i.records.get(e.handle.id).pauses;
|
|
111
|
+
} else return a("invalid-input");
|
|
112
|
+
return t.has(e.reason) === e.active ? r : i.mutate(() => {
|
|
150
113
|
e.active ? t.add(e.reason) : t.delete(e.reason);
|
|
151
114
|
});
|
|
152
115
|
}),
|
|
153
|
-
setFocused:
|
|
154
|
-
let n = e === null ? void 0 :
|
|
155
|
-
return n ?
|
|
116
|
+
setFocused: m((e) => {
|
|
117
|
+
let n = e === null ? void 0 : u(e);
|
|
118
|
+
return n ? a(n) : i.focused === e ? r : (i.focused = e, t);
|
|
156
119
|
}),
|
|
157
|
-
beginPresentation:
|
|
158
|
-
if (e.presentation !== t) return
|
|
159
|
-
let n =
|
|
160
|
-
return
|
|
120
|
+
beginPresentation: m(d((e, t) => {
|
|
121
|
+
if (e.presentation !== t) return a("stale-presentation");
|
|
122
|
+
let n = i.token();
|
|
123
|
+
return i.mutate(() => {
|
|
161
124
|
e.presentation = n, e.readable = !1;
|
|
162
125
|
}), {
|
|
163
126
|
status: "started",
|
|
164
127
|
token: n
|
|
165
128
|
};
|
|
166
129
|
})),
|
|
167
|
-
acknowledgePresentation:
|
|
130
|
+
acknowledgePresentation: m(d((e, t) => e.presentation === t ? e.readable ? r : i.mutate((t) => {
|
|
168
131
|
t.push({
|
|
169
132
|
type: "presented",
|
|
133
|
+
source: "system",
|
|
170
134
|
handle: e.handle,
|
|
171
135
|
firstPresentation: !e.everPresented
|
|
172
136
|
}), e.readable = e.everPresented = !0;
|
|
173
|
-
}) :
|
|
174
|
-
acknowledgeFocus:
|
|
175
|
-
|
|
176
|
-
}) :
|
|
177
|
-
acknowledgeOverflow:
|
|
178
|
-
acknowledgeAnnouncements:
|
|
179
|
-
dismiss:
|
|
180
|
-
let n =
|
|
181
|
-
return n ?
|
|
137
|
+
}) : a("stale-presentation"))),
|
|
138
|
+
acknowledgeFocus: m((e, t) => i.focusRequest?.token === e ? t !== "focused" && t !== "unavailable" ? a("invalid-input") : i.mutate(() => {
|
|
139
|
+
i.focusRequest = null;
|
|
140
|
+
}) : a("stale-focus-request")),
|
|
141
|
+
acknowledgeOverflow: m(() => i.acknowledgeOverflow("user")),
|
|
142
|
+
acknowledgeAnnouncements: m((e) => g(e)),
|
|
143
|
+
dismiss: m((e, t) => {
|
|
144
|
+
let n = i.handleError(e);
|
|
145
|
+
return n ? a(n) : [
|
|
182
146
|
"close-button",
|
|
183
147
|
"swipe",
|
|
184
148
|
"navigation"
|
|
185
|
-
].includes(t) ?
|
|
149
|
+
].includes(t) ? i.dismiss(e, t, "user") : a("invalid-input");
|
|
186
150
|
}),
|
|
187
|
-
clearAll:
|
|
188
|
-
invokeAction:
|
|
189
|
-
let t = e
|
|
190
|
-
|
|
191
|
-
if (e.action.status === "pending") return o("already-pending");
|
|
192
|
-
let i = a.formOf(e);
|
|
193
|
-
if (i) {
|
|
194
|
-
let e = m(i, t);
|
|
195
|
-
if (e) return a.mutate(() => {
|
|
196
|
-
i.errors = e;
|
|
197
|
-
}), {
|
|
198
|
-
status: "invalid",
|
|
199
|
-
errors: e
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
let c = a.token(), l = () => !a.disposed && a.records.get(t.id) === e && e.action.status === "pending" && e.action.token === c, u = a.settle();
|
|
203
|
-
e.action = s({
|
|
204
|
-
status: "pending",
|
|
205
|
-
token: c
|
|
206
|
-
}), i && (i.errors = n), a.commit([{
|
|
207
|
-
type: "action-started",
|
|
208
|
-
handle: t,
|
|
209
|
-
token: c
|
|
210
|
-
}], u);
|
|
211
|
-
function d(n) {
|
|
212
|
-
if (!l()) return;
|
|
213
|
-
let i = a.options.messages?.actionError ?? "Action failed";
|
|
214
|
-
if (r && r.kind !== "link" && r.errorMessage) try {
|
|
215
|
-
let e = r.errorMessage(n);
|
|
216
|
-
if (typeof e != "string" || !e.trim()) throw TypeError("Invalid action error message");
|
|
217
|
-
i = e;
|
|
218
|
-
} catch (e) {
|
|
219
|
-
a.disposed || a.failure("mapper-error", "action.errorMessage", e, t);
|
|
220
|
-
}
|
|
221
|
-
if (!l()) return;
|
|
222
|
-
let o = a.settle();
|
|
223
|
-
e.action = s({
|
|
224
|
-
status: "failed",
|
|
225
|
-
token: c,
|
|
226
|
-
message: i
|
|
227
|
-
}), a.commit([{
|
|
228
|
-
type: "action-failed",
|
|
229
|
-
handle: t,
|
|
230
|
-
token: c,
|
|
231
|
-
message: i
|
|
232
|
-
}], o);
|
|
233
|
-
}
|
|
234
|
-
let f;
|
|
235
|
-
try {
|
|
236
|
-
f = Promise.resolve(i ? i.action.run(s({
|
|
237
|
-
handle: t,
|
|
238
|
-
token: c,
|
|
239
|
-
values: i.values
|
|
240
|
-
})) : r.kind === "command" ? r.run(s({
|
|
241
|
-
handle: t,
|
|
242
|
-
token: c
|
|
243
|
-
})) : void 0);
|
|
244
|
-
} catch (e) {
|
|
245
|
-
f = Promise.reject(e);
|
|
246
|
-
}
|
|
247
|
-
return f.then(() => {
|
|
248
|
-
l() && a.dismiss(t, "action-success");
|
|
249
|
-
}, d).catch((e) => {
|
|
250
|
-
a.disposed || a.failure("callback-error", "action-settlement", e, t);
|
|
251
|
-
}), { status: "started" };
|
|
252
|
-
})),
|
|
253
|
-
setFormValue: p(a.withRecord((e, t, n) => {
|
|
254
|
-
let r = a.formOf(e);
|
|
255
|
-
return r ? typeof n != "string" || !r.action.fields.some((e) => e.name === t) ? o("invalid-input") : e.action.status === "pending" ? o("already-pending") : r.values[t] === n ? i : a.mutate(() => {
|
|
256
|
-
if (r.values = s({
|
|
257
|
-
...r.values,
|
|
258
|
-
[t]: n
|
|
259
|
-
}), r.errors.fields[t] !== void 0) {
|
|
260
|
-
let { [t]: e, ...n } = r.errors.fields;
|
|
261
|
-
r.errors = s({
|
|
262
|
-
form: r.errors.form,
|
|
263
|
-
fields: s(n)
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
}) : o("no-form");
|
|
151
|
+
clearAll: m(() => i.island ? i.clear("clear-button", "user") : a("island-closed")),
|
|
152
|
+
invokeAction: m(i.withRecord((e) => {
|
|
153
|
+
let t = o(i, e, "user");
|
|
154
|
+
return t.status === "started" ? { status: "started" } : t;
|
|
267
155
|
})),
|
|
268
|
-
|
|
269
|
-
|
|
156
|
+
setFormValue: m(i.withRecord((e, t, n) => s(i, e, t, n))),
|
|
157
|
+
retryOperation: m(f((e) => {
|
|
158
|
+
let t = e.retry("user");
|
|
270
159
|
return t.status === "started" ? {
|
|
271
160
|
status: "started",
|
|
272
161
|
token: t.attempt.token
|
|
273
162
|
} : t;
|
|
274
163
|
})),
|
|
275
|
-
cancelOperation:
|
|
276
|
-
reportDiagnostic:
|
|
164
|
+
cancelOperation: m(f((e, t) => e.cancel(t, "user"))),
|
|
165
|
+
reportDiagnostic: m((e) => !e || typeof e.source != "string" || typeof e.message != "string" || ![
|
|
277
166
|
"invalid-input",
|
|
278
167
|
"second-host",
|
|
279
168
|
"stale-host",
|
|
@@ -284,63 +173,63 @@ function u(a) {
|
|
|
284
173
|
"slot-error",
|
|
285
174
|
"formatter-error",
|
|
286
175
|
"invalid-container"
|
|
287
|
-
].includes(e.code) ?
|
|
176
|
+
].includes(e.code) ? a("invalid-input") : (i.diagnostic(e), t))
|
|
288
177
|
});
|
|
289
178
|
function g(e) {
|
|
290
|
-
if (!Array.isArray(e)) return
|
|
179
|
+
if (!Array.isArray(e)) return a("invalid-input");
|
|
291
180
|
let t = [], n = (e, t) => Number.isSafeInteger(e) && e >= 0 && e <= t;
|
|
292
181
|
for (let r of e) {
|
|
293
|
-
if (!r || typeof r != "object") return
|
|
182
|
+
if (!r || typeof r != "object") return a("invalid-input");
|
|
294
183
|
if (r.kind === "overflow") {
|
|
295
|
-
if (!n(r.count,
|
|
296
|
-
r.count >
|
|
297
|
-
|
|
184
|
+
if (!n(r.count, i.overflow)) return a("invalid-input");
|
|
185
|
+
r.count > i.overflowAnnounced && t.push(() => {
|
|
186
|
+
i.overflowAnnounced = Math.max(i.overflowAnnounced, r.count);
|
|
298
187
|
});
|
|
299
188
|
continue;
|
|
300
189
|
}
|
|
301
|
-
let e =
|
|
302
|
-
if (e) return
|
|
303
|
-
let
|
|
190
|
+
let e = i.handleError(r.handle);
|
|
191
|
+
if (e) return a(e);
|
|
192
|
+
let o = i.records.get(r.handle.id);
|
|
304
193
|
if (r.kind === "operation") {
|
|
305
|
-
let e =
|
|
306
|
-
if (!e || e.token !== r.token) return
|
|
194
|
+
let e = o.operation?.getSnapshot();
|
|
195
|
+
if (!e || e.token !== r.token) return a("stale-operation-token");
|
|
307
196
|
if (![
|
|
308
197
|
"started",
|
|
309
198
|
"fulfilled",
|
|
310
199
|
"rejected",
|
|
311
200
|
"cancelled",
|
|
312
201
|
"cancel-requested"
|
|
313
|
-
].includes(r.phase) || (r.phase === "cancel-requested" ? !e.cancelRequested : r.phase !== "started" && r.phase !== e.status)) return
|
|
314
|
-
|
|
315
|
-
|
|
202
|
+
].includes(r.phase) || (r.phase === "cancel-requested" ? !e.cancelRequested : r.phase !== "started" && r.phase !== e.status)) return a("invalid-input");
|
|
203
|
+
o.operationAnnounced.has(r.phase) || t.push(() => {
|
|
204
|
+
o.operationAnnounced.add(r.phase);
|
|
316
205
|
});
|
|
317
206
|
} else if (r.kind === "action") {
|
|
318
|
-
if (
|
|
319
|
-
(
|
|
320
|
-
|
|
207
|
+
if (o.action.status === "idle" || o.action.token !== r.token || o.action.status !== r.status) return a("invalid-input");
|
|
208
|
+
(o.actionAnnounced?.token !== r.token || o.actionAnnounced?.status !== r.status) && t.push(() => {
|
|
209
|
+
o.actionAnnounced = c({
|
|
321
210
|
token: r.token,
|
|
322
211
|
status: r.status
|
|
323
212
|
});
|
|
324
213
|
});
|
|
325
214
|
} else if (r.kind === "occurrences") {
|
|
326
|
-
if (!n(r.count,
|
|
327
|
-
r.count >
|
|
328
|
-
|
|
215
|
+
if (!n(r.count, o.occurrences)) return a("invalid-input");
|
|
216
|
+
r.count > o.occurrencesAnnounced && t.push(() => {
|
|
217
|
+
o.occurrencesAnnounced = Math.max(o.occurrencesAnnounced, r.count);
|
|
329
218
|
});
|
|
330
219
|
} else if (r.kind === "queued" || r.kind === "first-presentation") {
|
|
331
220
|
let e = r.kind === "queued" ? "queuedAnnounced" : "firstAnnounced";
|
|
332
|
-
|
|
333
|
-
|
|
221
|
+
o[e] || t.push(() => {
|
|
222
|
+
o[e] = !0;
|
|
334
223
|
});
|
|
335
|
-
} else return
|
|
224
|
+
} else return a("invalid-input");
|
|
336
225
|
}
|
|
337
|
-
return t.length ?
|
|
226
|
+
return t.length ? i.mutate(() => {
|
|
338
227
|
for (let e of t) e();
|
|
339
|
-
}) :
|
|
228
|
+
}) : r;
|
|
340
229
|
}
|
|
341
230
|
return h;
|
|
342
231
|
}
|
|
343
232
|
//#endregion
|
|
344
|
-
export {
|
|
233
|
+
export { u as getRendererBridge };
|
|
345
234
|
|
|
346
235
|
//# sourceMappingURL=bridge.js.map
|