@picked/client 0.0.50-next.3 → 0.0.50

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 (51) hide show
  1. package/dist/api-BwTaomem.cjs +1 -0
  2. package/dist/api-DWBcrf98.js +37 -0
  3. package/dist/cjs/index.js +2 -2
  4. package/dist/cjs/plugins/create-experience/index.js +1 -1
  5. package/dist/cjs/plugins/dynamic-experiences/index.js +1 -1
  6. package/dist/cjs/plugins/experience-browser-storage/index.js +1 -1
  7. package/dist/cjs/plugins/history-browser-storage/index.js +1 -1
  8. package/dist/cjs/plugins/responses-browser-storage/index.js +1 -1
  9. package/dist/cjs/plugins/responses-indexeddb/index.js +1 -1
  10. package/dist/cjs/plugins/single-page-app/index.js +1 -1
  11. package/dist/cjs/plugins/web-components/index.js +1 -1
  12. package/dist/cjs/plugins/window-object/index.js +1 -1
  13. package/dist/cjs/server/index.js +1 -1
  14. package/dist/esm/index.js +1126 -1220
  15. package/dist/esm/plugins/create-experience/index.js +461 -468
  16. package/dist/esm/plugins/dynamic-experiences/index.js +106 -123
  17. package/dist/esm/plugins/experience-browser-storage/index.js +32 -37
  18. package/dist/esm/plugins/history-browser-storage/index.js +23 -25
  19. package/dist/esm/plugins/responses-browser-storage/index.js +36 -39
  20. package/dist/esm/plugins/responses-indexeddb/index.js +81 -80
  21. package/dist/esm/plugins/single-page-app/index.js +31 -35
  22. package/dist/esm/plugins/web-components/index.js +18 -20
  23. package/dist/esm/plugins/window-object/index.js +9 -9
  24. package/dist/esm/server/index.js +95 -89
  25. package/dist/experience-instance-BRpI9I4s.js +710 -0
  26. package/dist/experience-instance-BUTnwbSJ.cjs +1 -0
  27. package/dist/id-BniPxOdF.js +4 -0
  28. package/dist/id-CIbS4P60.cjs +1 -0
  29. package/dist/logger-6z_gb4rA.js +4 -0
  30. package/dist/logger-fbvQC40v.cjs +1 -0
  31. package/dist/object-BReQiaSS.cjs +1 -0
  32. package/dist/object-Clj5zVr1.js +24 -0
  33. package/dist/storage-BFjb8azI.cjs +1 -0
  34. package/dist/storage-DyxpJ0pg.js +101 -0
  35. package/dist/supports-0XIfd4-R.js +85 -0
  36. package/dist/supports-Dsjg-82e.cjs +1 -0
  37. package/package.json +5 -5
  38. package/dist/api-4mY9vhi4.cjs +0 -1
  39. package/dist/api-D1FqIUly.js +0 -32
  40. package/dist/experience-instance-BsXG5XJ4.cjs +0 -1
  41. package/dist/experience-instance-fvSEb72i.js +0 -819
  42. package/dist/id-BKIWbSTy.cjs +0 -1
  43. package/dist/id-BW-g3y32.js +0 -6
  44. package/dist/logger-BsmHUUw1.cjs +0 -1
  45. package/dist/logger-C9a75KZn.js +0 -5
  46. package/dist/object-BbFTsGh3.cjs +0 -1
  47. package/dist/object-JwZ58NOH.js +0 -28
  48. package/dist/storage-Be5xWNPC.cjs +0 -1
  49. package/dist/storage-Co_LbKr_.js +0 -239
  50. package/dist/supports-8YT4QKI7.js +0 -95
  51. package/dist/supports-YvpQZxbh.cjs +0 -1
@@ -1,819 +0,0 @@
1
- import { createDomain as kt, createEvent as k, combine as D, createApi as lt, createEffect as _, attach as O, sample as m, split as bt } from "effector";
2
- import { createFactory as dt, invoke as pt } from "@withease/factories";
3
- import { a as vt, s as gt, j as At } from "./supports-8YT4QKI7.js";
4
- import { l as I } from "./logger-C9a75KZn.js";
5
- import { i as Ot } from "./object-JwZ58NOH.js";
6
- function Ft(t) {
7
- return typeof t == "number" && !isNaN(t);
8
- }
9
- function j(t) {
10
- return typeof t == "string";
11
- }
12
- function N(t) {
13
- return Array.isArray(t);
14
- }
15
- function mt(t) {
16
- return t instanceof Promise;
17
- }
18
- function st(t) {
19
- return typeof t == "object" && t !== null && !Array.isArray(t) && Object.keys(t).length === 1;
20
- }
21
- function g(t) {
22
- if (Ft(t)) return t;
23
- const e = parseFloat(`${t}`);
24
- return isNaN(e) ? 0 : e;
25
- }
26
- function R(t) {
27
- return `${t}`;
28
- }
29
- const Bt = {
30
- // eslint-disable-next-line eqeqeq
31
- "==": (t, e) => t == e,
32
- "===": (t, e) => t === e,
33
- // eslint-disable-next-line eqeqeq
34
- "!=": (t, e) => t != e,
35
- "!==": (t, e) => t !== e,
36
- ">": (t, e) => g(t) > g(e),
37
- ">=": (t, e) => g(t) >= g(e),
38
- "<": (t, e, r) => {
39
- const n = g(t), s = g(e);
40
- if (r === void 0) return n < s;
41
- const a = g(r);
42
- return n < s && s < a;
43
- },
44
- "<=": (t, e, r) => {
45
- const n = g(t), s = g(e);
46
- if (r === void 0) return n <= s;
47
- const a = g(r);
48
- return n <= s && s <= a;
49
- },
50
- "!!": async (t) => await v(t),
51
- "!": async (t) => !await v(t),
52
- "%": (t, e) => g(t) % g(e),
53
- // eslint-disable-next-line sonarjs/function-return-type
54
- log: (t) => (console.log(t), t),
55
- in: (t, e) => e ? j(e) ? e.indexOf(R(t)) !== -1 : N(e) ? e.includes(t) : !1 : !1,
56
- cat: (...t) => t.map(R).join(""),
57
- /* eslint-disable sonarjs/deprecation */
58
- substr: (t, e, r) => {
59
- const n = R(t), s = g(e);
60
- if (r === void 0) return n.substr(s);
61
- const a = g(r);
62
- if (a < 0) {
63
- const o = n.substr(s);
64
- return o.substr(0, o.length + a);
65
- }
66
- return n.substr(s, a);
67
- },
68
- /* eslint-enable sonarjs/deprecation */
69
- "+": (...t) => t.reduce((e, r) => g(e) + g(r), 0),
70
- "*": (...t) => t.reduce((e, r) => g(e) * g(r), 1),
71
- "-": (t, e) => {
72
- const r = g(t);
73
- return e === void 0 ? -r : r - g(e);
74
- },
75
- "/": (t, e) => g(t) / g(e),
76
- min: (...t) => Math.min(...t.map(g)),
77
- max: (...t) => Math.max(...t.map(g)),
78
- merge: (...t) => t.reduce((e, r) => N(r) ? e.concat(r) : e.concat([r]), []),
79
- var(t, e) {
80
- const r = arguments.length > 1 ? e : null;
81
- if (t === "" || t === "." || t === null || t === void 0)
82
- return this;
83
- if (typeof t == "number" && Array.isArray(this))
84
- return t >= 0 && t < this.length ? this[t] : r;
85
- const n = R(t);
86
- if (n === "" || n === ".")
87
- return this;
88
- const s = n.split(".");
89
- let a = this;
90
- for (const o of s) {
91
- if (a == null)
92
- return r;
93
- if (Array.isArray(a)) {
94
- const u = parseInt(o, 10);
95
- isNaN(u) ? a = a[o] : a = a[u];
96
- } else
97
- a = a[o];
98
- }
99
- return a !== void 0 ? a : r;
100
- },
101
- async missing(...t) {
102
- const e = N(t[0]) ? t[0] : t, r = [];
103
- for (const n of e) {
104
- const s = await p({ var: n }, this);
105
- (s === null || s === "") && r.push(`${n}`);
106
- }
107
- return r;
108
- },
109
- async missing_some(t, e) {
110
- const r = await p({ missing: e }, this);
111
- if (!N(r) || !N(e)) return [];
112
- const n = r.filter(j);
113
- return e.filter(j).length - n.length >= g(t) ? [] : n;
114
- },
115
- /**
116
- * Invoke operator - executes a function with optional arguments
117
- *
118
- * Object format (no arguments):
119
- * { "invoke": { "var": "functionName" } }
120
- *
121
- * Array format (with arguments):
122
- * { "invoke": [{ "var": "functionName" }, arg1, arg2, ...] }
123
- *
124
- * Arguments are evaluated as JSONLogic expressions before being passed to the function.
125
- */
126
- // eslint-disable-next-line sonarjs/function-return-type
127
- invoke(...t) {
128
- const [e, ...r] = t;
129
- return typeof e != "function" ? null : Reflect.apply(e, null, r);
130
- },
131
- regexp_matches(t, e) {
132
- let r = t, n = "";
133
- if (N(t)) {
134
- const [a, o] = t;
135
- r = a, n = o;
136
- }
137
- return !j(r) || !j(n) ? !1 : new RegExp(r, n).test(R(e));
138
- },
139
- throw(t) {
140
- throw new Error(R(t));
141
- }
142
- };
143
- async function p(t, e) {
144
- if (!t) return t;
145
- if (mt(t))
146
- return p(await t, e);
147
- if (N(t))
148
- return Promise.all(t.map((o) => p(o, e)));
149
- if (!st(t)) return t;
150
- const r = _t(t);
151
- let n = r ? t[r] ?? [] : [];
152
- switch (N(n) || (n = [n]), r) {
153
- case "if":
154
- case "?:":
155
- for (let o = 0; o < n.length - 1; o += 2)
156
- if (await v(await p(n[o], e)))
157
- return p(n[o + 1], e);
158
- return n.length % 2 === 1 ? p(n[n.length - 1], e) : null;
159
- case "and": {
160
- let o = null;
161
- for (const u of n)
162
- if (o = await p(u, e), !await v(o))
163
- return o;
164
- return o;
165
- }
166
- case "or": {
167
- let o = null;
168
- for (const u of n)
169
- if (o = await p(u, e), await v(o)) return o;
170
- return o;
171
- }
172
- case "map": {
173
- const o = await p(n[0], e);
174
- return N(o) ? await Promise.all(o.map((u) => p(n[1], u))) : [];
175
- }
176
- case "filter": {
177
- const o = await p(n[0], e);
178
- return N(o) ? (await Promise.all(
179
- o.map(async (d) => {
180
- const y = await v(await p(n[1], d));
181
- return { item: d, shouldInclude: y };
182
- })
183
- )).filter(({ shouldInclude: d }) => d).map(({ item: d }) => d) : [];
184
- }
185
- case "reduce": {
186
- const o = await p(n[0], e);
187
- if (!N(o))
188
- return n.length > 2 ? await p(n[2], e) : null;
189
- const u = n[1];
190
- let y = n.length > 2 ? await p(n[2], e) : null;
191
- for (const b of o)
192
- y = await p(u, { current: b, accumulator: y });
193
- return y;
194
- }
195
- case "all": {
196
- const o = await p(n[0], e);
197
- if (!N(o) || o.length === 0) return !1;
198
- for (const u of o)
199
- if (!await v(await p(n[1], u))) return !1;
200
- return !0;
201
- }
202
- case "some": {
203
- const o = await p(n[0], e);
204
- if (!N(o)) return !1;
205
- for (const u of o)
206
- if (await v(await p(n[1], u))) return !0;
207
- return !1;
208
- }
209
- case "none": {
210
- const o = await p(n[0], e);
211
- if (!N(o)) return !0;
212
- for (const u of o)
213
- if (await v(await p(n[1], u))) return !1;
214
- return !0;
215
- }
216
- case "catch":
217
- try {
218
- return await p(n[0], e);
219
- } catch (o) {
220
- return st(o) ? await p(o, e) : n[1] ? await p(n[1], o) : o instanceof Error ? o.message : o;
221
- }
222
- }
223
- const s = await Promise.all(n.map((o) => p(o, e))), a = r ? Bt[r] : void 0;
224
- if (!a) throw new Error(`Unrecognized operation ${r}`);
225
- return a.apply(e, s);
226
- }
227
- async function v(t) {
228
- return mt(t) ? v(await t) : !(Array.isArray(t) && t.length === 0) && !!t;
229
- }
230
- function _t(t) {
231
- return Object.keys(t)[0];
232
- }
233
- function $t(t) {
234
- return !Ot(t);
235
- }
236
- async function at(t, e, r) {
237
- const n = t.getStateSnapshot(), s = t.predicates.listStore.getState().reduce((u, d) => ({
238
- ...u,
239
- [d.name]: (...y) => d.predicate({ ...n, args: y })
240
- }), {}), a = t.features.listStore.getState().reduce((u, d) => ({
241
- ...u,
242
- [d.id]: async () => {
243
- const { bucket: y } = await d.getBucket();
244
- return y;
245
- }
246
- }), {}), o = {
247
- ...r,
248
- responses: t.responses.getAllStore.getState(),
249
- location: typeof n.location == "object" ? {
250
- hash: n.location.hash,
251
- host: n.location.host,
252
- hostname: n.location.hostname,
253
- href: n.location.href,
254
- origin: n.location.origin,
255
- pathname: n.location.pathname,
256
- port: n.location.port,
257
- protocol: n.location.protocol,
258
- search: n.location.search
259
- } : void 0,
260
- predicates: s,
261
- features: a
262
- };
263
- return await p(e, o);
264
- }
265
- function Mt(t) {
266
- return !vt() || !gt() ? [] : Array.from(window.document.querySelectorAll(t)).filter(
267
- (e) => e instanceof HTMLElement
268
- );
269
- }
270
- const Tt = "open";
271
- function Lt(t) {
272
- if (!At())
273
- throw new Error("Shadow DOM is not supported in this environment");
274
- return t.attachShadow({ mode: Tt });
275
- }
276
- function te() {
277
- return new Promise((t, e) => {
278
- if (!gt()) {
279
- e();
280
- return;
281
- }
282
- document.readyState !== "loading" ? t() : document.addEventListener("readystatechange", () => t(), { once: !0 });
283
- });
284
- }
285
- function Dt(t, e) {
286
- const r = new MutationObserver((n) => {
287
- document.contains(t) || (r.disconnect(), e());
288
- });
289
- r.observe(document.body, { childList: !0, subtree: !0 });
290
- }
291
- const K = "picked-root", V = "picked-target", Rt = "picked-root";
292
- function ee(t, e) {
293
- return [
294
- ...t,
295
- // Target and replace picked-root web components
296
- {
297
- selector: `${Rt}[experience-id="${e}"]`,
298
- placement: "replace"
299
- }
300
- ].flatMap((n) => {
301
- const s = Mt(n.selector).filter(
302
- (a) => !Pt(a, e) && !Ct(a, e)
303
- );
304
- return {
305
- ...n,
306
- elements: s
307
- };
308
- });
309
- }
310
- function ne(t, e) {
311
- return t.flatMap((r) => r.elements.map((n) => jt(n, r.placement, e)));
312
- }
313
- function re(t, e) {
314
- t.classList.add(V), t.classList.add(`${V}-${e}`);
315
- }
316
- function Pt(t, e) {
317
- return e ? t.classList.contains(`${V}-${e}`) : t.classList.contains(`${V}`);
318
- }
319
- function Ct(t, e) {
320
- return e ? t.classList.contains(`${K}-${e}`) : t.classList.contains(K);
321
- }
322
- function Ht(t) {
323
- const e = document.createElement("div");
324
- return e.style.display = "block", e.classList.add(K), e.classList.add(`${K}-${t}`), e;
325
- }
326
- function jt(t, e, r) {
327
- let n;
328
- const s = Ht(r);
329
- if (t instanceof Document)
330
- n = t.body.appendChild(s);
331
- else {
332
- switch (e) {
333
- case "replace":
334
- t.replaceWith(s);
335
- break;
336
- case "before":
337
- t.before(s);
338
- break;
339
- case "after":
340
- t.after(s);
341
- break;
342
- case "prepend":
343
- t.prepend(s);
344
- break;
345
- default:
346
- t.append(s);
347
- break;
348
- }
349
- n = s;
350
- }
351
- return n;
352
- }
353
- function ct(t) {
354
- return t.type === "conditional";
355
- }
356
- function P(t) {
357
- return t.type === "step";
358
- }
359
- function ut(t) {
360
- return t.type === "experience";
361
- }
362
- function Y(t) {
363
- return t.type === "origin";
364
- }
365
- function ft(t) {
366
- return t.type === "action";
367
- }
368
- const St = (t, e, r, n, s = /* @__PURE__ */ new Set()) => s.has(r.id) ? [] : (s.add(r.id), P(r) && !n ? [r] : e.filter((o) => o.sourceNodeId === r.id).flatMap((o) => {
369
- const u = t.find((d) => d.id === o.destinationNodeId);
370
- return u ? St(t, e, u, !1, s) : [];
371
- })), Ut = (t, e, r) => St(t, e, r, !0, /* @__PURE__ */ new Set()), yt = (t, e, r, n, s = /* @__PURE__ */ new Set()) => {
372
- if (s.has(r.id)) return [-1, -1];
373
- s.add(r.id);
374
- const a = e.filter((d) => d.sourceNodeId === r.id);
375
- if (a.length === 0) return [0, 0];
376
- let o = 1 / 0, u = -1 / 0;
377
- for (const d of a) {
378
- const y = t.find((M) => M.id === d.destinationNodeId);
379
- if (!y) continue;
380
- const [b, F] = yt(
381
- t,
382
- e,
383
- y,
384
- !1,
385
- new Set(s)
386
- );
387
- b !== -1 && (o = Math.min(o, b + 1), u = Math.max(u, F + 1));
388
- }
389
- return o === 1 / 0 ? [-1, -1] : [o, u];
390
- }, Wt = (t, e, r) => yt(t, e, r, !0, /* @__PURE__ */ new Set()), ht = (t, e, r, n = /* @__PURE__ */ new Set()) => {
391
- if (n.has(r.id)) return [-1, -1];
392
- if (n.add(r.id), r.type === "origin") return [0, 0];
393
- const s = e.filter((u) => u.destinationNodeId === r.id);
394
- if (s.length === 0) return [-1, -1];
395
- let a = 1 / 0, o = -1 / 0;
396
- for (const u of s) {
397
- const d = t.find((F) => F.id === u.sourceNodeId);
398
- if (!d) continue;
399
- const [y, b] = ht(
400
- t,
401
- e,
402
- d,
403
- new Set(n)
404
- );
405
- y !== -1 && (a = Math.min(a, y + 1), o = Math.max(o, b + 1));
406
- }
407
- return a === 1 / 0 ? [-1, -1] : [a, o];
408
- }, Gt = (t, e, r) => ht(t, e, r, /* @__PURE__ */ new Set()), wt = (t) => t.find((r) => r.type === "origin") || null, Z = (t, e, r) => {
409
- if (!t)
410
- return wt(e);
411
- const n = r.find((a) => a.sourceNodeId === t.id);
412
- if (!n)
413
- return null;
414
- const s = e.find((a) => a.id === n.destinationNodeId);
415
- return s || null;
416
- };
417
- async function Kt(t, e, r, n) {
418
- const s = t ? "true" : "false", a = n.find(
419
- (o) => o.sourceNodeHandle === s && o.sourceNodeId === e
420
- );
421
- return r.find((o) => o.id === a?.destinationNodeId);
422
- }
423
- const tt = kt("experience-instance"), Vt = dt(
424
- ({
425
- client: t,
426
- experience: e,
427
- target: r,
428
- options: n
429
- }) => {
430
- const s = k(), a = k(), o = k(), u = k(), d = k(), y = k(), b = e.componentStore, F = tt.store("transitioning"), M = t.history.entriesStore.map((i) => i.filter((l) => l.experienceId === e.id)), U = M.map((i) => i.filter((l) => P(l.node))), c = M.map((i) => i.at(-1)?.node || null), S = D(
431
- e.treeStore,
432
- c,
433
- ({ steps: i }, l) => i.find((f) => l && P(l) && f.id === l.stepId) || null
434
- ), x = D(
435
- e.treeStore,
436
- U,
437
- ({ steps: i }, l) => {
438
- const f = l.at(-2);
439
- if (!f || !P(f.node))
440
- return null;
441
- const h = f.node;
442
- return i.find((B) => B.id === h.stepId) || null;
443
- }
444
- ), T = D(
445
- e.treeStore,
446
- c,
447
- ({ nodes: i, edges: l }, f) => f ? Ut(i, l, f) : []
448
- ), C = D(
449
- e.treeStore,
450
- c,
451
- ({ nodes: i, edges: l }, f) => f ? Gt(i, l, f) : [-1, -1]
452
- ), q = D(
453
- e.treeStore,
454
- c,
455
- ({ nodes: i, edges: l }, f) => f ? Wt(i, l, f) : [-1, -1]
456
- ), L = tt.store(!1), W = lt(L, {
457
- open: () => !0,
458
- close: () => !1,
459
- toggle: (i) => !i,
460
- set: (i, l) => l
461
- }), xt = _(async () => {
462
- t.history.back({ experienceId: e.id });
463
- }), Nt = O({
464
- source: e.treeStore,
465
- effect: async (i, l) => {
466
- const f = i.nodes.find((h) => P(h) && h.stepId === l);
467
- f && t.history.push({ experienceId: e.id, node: f });
468
- }
469
- }), et = O({
470
- source: c,
471
- effect: (i) => {
472
- }
473
- }), z = O({
474
- source: e.treeStore,
475
- effect: async ({ nodes: i }) => wt(i)
476
- }), X = O({
477
- source: e.treeStore,
478
- effect: async ({ nodes: i, edges: l }, f) => {
479
- if (Y(f))
480
- return Z(f, i, l);
481
- }
482
- }), J = O({
483
- source: e.treeStore,
484
- effect: async ({ nodes: i, edges: l, conditionals: f }, h) => {
485
- if (!ct(h))
486
- return;
487
- const B = f.find((A) => A.id === h.conditionalId);
488
- if (!B)
489
- return;
490
- const E = h.id, w = await at(t, B.condition);
491
- return Kt(!!w, E, i, l);
492
- }
493
- }), nt = O({
494
- source: e.treeStore,
495
- effect: async ({ nodes: i, edges: l }, f) => {
496
- if (!ft(f))
497
- return;
498
- const h = f.action;
499
- if (!h) {
500
- I("warn", `Action node ${f.id} has no action name`);
501
- return;
502
- }
503
- const B = t.actions.getByName(h).getState();
504
- if (!B) {
505
- I("warn", `Action '${h}' not registered on client`);
506
- const E = l.find(
507
- (w) => w.sourceNodeId === f.id && w.sourceNodeHandle === "false"
508
- );
509
- return E ? i.find((w) => w.id === E.destinationNodeId) : null;
510
- }
511
- if (typeof B.action != "function") {
512
- I("warn", `Action '${h}' is not a function`);
513
- const E = l.find(
514
- (w) => w.sourceNodeId === f.id && w.sourceNodeHandle === "false"
515
- );
516
- return E ? i.find((w) => w.id === E.destinationNodeId) : null;
517
- }
518
- try {
519
- I("info", `Executing action: ${h}`), await B.action(h);
520
- const E = l.find(
521
- (A) => A.sourceNodeId === f.id && A.sourceNodeHandle === "true"
522
- );
523
- if (!E)
524
- return I("warn", `No 'true' edge found for action node ${f.id}`), null;
525
- const w = i.find((A) => A.id === E.destinationNodeId);
526
- return I("info", `Action '${h}' succeeded, moving to node ${w?.id}`), w || null;
527
- } catch (E) {
528
- I("warn", `Action '${h}' failed:`, E);
529
- const w = l.find(
530
- (G) => G.sourceNodeId === f.id && G.sourceNodeHandle === "false"
531
- );
532
- if (!w)
533
- return I("warn", `No 'false' edge found for action node ${f.id}`), null;
534
- const A = i.find((G) => G.id === w.destinationNodeId);
535
- return I("info", `Action '${h}' failed, moving to node ${A?.id}`), A || null;
536
- }
537
- }
538
- }), It = _((i) => {
539
- ut(i) && t.experiences.launch({ id: i.experienceId });
540
- }), rt = O({
541
- source: [c, e.treeStore],
542
- effect: async ([i, { nodes: l, edges: f }]) => Z(i, l, f)
543
- }), H = O({
544
- source: [c, e.treeStore],
545
- effect: async ([i, { nodes: l, edges: f }]) => Z(i, l, f)
546
- }), Et = _((i) => {
547
- t.history.push({ experienceId: e.id, node: i });
548
- }), ot = O({
549
- source: e.configStore,
550
- effect: async ({ initializeOpenLogic: i }) => n?.initialiseOpen !== void 0 ? n.initialiseOpen : $t(i) ? !!await at(t, i) : i ?? !1
551
- }), $ = Object.freeze({
552
- id: Math.random().toString(36).substring(7),
553
- // config
554
- experienceId: e.id,
555
- configStore: e.configStore,
556
- target: r,
557
- componentStore: b,
558
- // state
559
- stateStore: F,
560
- // open close
561
- isOpenStore: L,
562
- open: W.open,
563
- close: W.close,
564
- toggleOpen: W.toggle,
565
- setOpen: W.set,
566
- // nodes
567
- treeStore: e.treeStore,
568
- fieldsStore: e.fieldsStore,
569
- currentNodeStore: c,
570
- currentStepStore: S,
571
- previousStepStore: x,
572
- nextReachableStepNodesStore: T,
573
- stepsToOriginStore: C,
574
- stepsToLeafStore: q,
575
- // history
576
- goToNextStep: a,
577
- goToPreviousStep: o,
578
- goToStepById: u,
579
- stepsHistoryStore: U
580
- }), Q = k(), it = k();
581
- return m({
582
- source: c,
583
- target: Q
584
- }), m({
585
- clock: Q,
586
- filter: (i) => i === null,
587
- target: z
588
- }), m({
589
- clock: Q,
590
- filter: (i) => i !== null,
591
- target: it
592
- }), bt({
593
- source: it,
594
- match: (i) => ct(i) ? "condition" : P(i) ? "step" : ut(i) ? "launchExperience" : Y(i) ? "origin" : ft(i) ? "action" : "other",
595
- cases: {
596
- origin: X,
597
- condition: J,
598
- step: et,
599
- launchExperience: It,
600
- action: nt,
601
- __: k()
602
- }
603
- }), m({
604
- clock: [
605
- J.doneData,
606
- X.doneData,
607
- z.doneData,
608
- H.doneData,
609
- rt.doneData,
610
- nt.doneData
611
- ],
612
- filter: Boolean,
613
- target: Et
614
- }), m({
615
- clock: a,
616
- target: H
617
- }), m({
618
- clock: a,
619
- source: S,
620
- filter: Boolean,
621
- target: t.eventBus.prepend((i) => ({
622
- type: "step_submit",
623
- step: i,
624
- experience: $
625
- }))
626
- }), m({
627
- clock: H.done,
628
- source: S,
629
- filter: Boolean,
630
- target: t.eventBus.prepend((i) => ({
631
- type: "step_submit_success",
632
- step: i,
633
- experience: $
634
- }))
635
- }), m({
636
- clock: H.fail,
637
- source: S,
638
- filter: Boolean,
639
- target: t.eventBus.prepend((i) => ({
640
- type: "step_submit_error",
641
- step: i,
642
- experience: $
643
- }))
644
- }), m({
645
- clock: o,
646
- target: xt
647
- }), m({ clock: u, target: Nt }), m({
648
- source: D([
649
- J.pending,
650
- X.pending,
651
- z.pending,
652
- H.pending
653
- ]),
654
- fn: (i) => i.some(Boolean) ? "transitioning" : "ready",
655
- target: F
656
- }), m({
657
- clock: et.doneData,
658
- source: S,
659
- filter: Boolean,
660
- target: t.eventBus.prepend((i) => ({
661
- type: "step_enter",
662
- step: i,
663
- experience: $
664
- }))
665
- }), m({
666
- clock: y,
667
- target: ot
668
- }), m({
669
- source: ot.doneData,
670
- fn: Boolean,
671
- target: L
672
- }), m({
673
- source: c,
674
- clock: s,
675
- filter: (i) => i ? Y(i) : !0,
676
- target: rt
677
- }), m({
678
- source: L,
679
- filter: Boolean,
680
- target: s
681
- }), m({
682
- source: L,
683
- filter: Boolean,
684
- target: t.eventBus.prepend(() => ({
685
- type: "experience_open",
686
- experience: $
687
- }))
688
- }), m({
689
- source: L,
690
- filter: (i) => !i,
691
- target: t.eventBus.prepend(() => ({
692
- type: "experience_close",
693
- experience: $
694
- }))
695
- }), m({
696
- clock: d,
697
- target: [y]
698
- }), d(), $;
699
- }
700
- );
701
- function qt(t) {
702
- return pt(Vt, t);
703
- }
704
- const zt = dt(({ client: t }) => {
705
- const e = tt.store({}), r = k(), n = k(), s = k(), a = lt(e, {
706
- register(c, S) {
707
- const x = [
708
- ...c[S.experienceId] ?? []
709
- ];
710
- return x.push(S), {
711
- ...c,
712
- [S.experienceId]: x
713
- };
714
- },
715
- unregister(c, S) {
716
- const x = S.experienceId, T = c[x]?.filter(
717
- (C) => C !== S
718
- );
719
- return {
720
- ...c,
721
- [x]: T ?? []
722
- };
723
- }
724
- }), o = _(
725
- ({
726
- experience: c,
727
- target: S,
728
- options: x
729
- }) => qt({ client: t, experience: c, target: S, options: x })
730
- ), u = _((c) => {
731
- a.register(c);
732
- }), d = _(
733
- (c) => {
734
- c.target && Dt(c.target, () => {
735
- s(c);
736
- });
737
- }
738
- ), y = _((c) => {
739
- a.unregister(c);
740
- }), b = _((c) => {
741
- const S = c.componentStore.getState();
742
- if (!S) {
743
- I("warn", "No app component registered. Skipping init.");
744
- return;
745
- }
746
- const x = S.frameworkStore.getState();
747
- if (!x) {
748
- I(
749
- "error",
750
- `No framework registered for component '${S.name}'. Skipping rendering.`
751
- );
752
- return;
753
- }
754
- const T = c.target;
755
- if (!T) {
756
- I(
757
- "error",
758
- `No target element registered for experience '${c.experienceId}'. Skipping rendering.`
759
- );
760
- return;
761
- }
762
- const C = Lt(T);
763
- try {
764
- x.render(C, S.component, t, c);
765
- } catch (q) {
766
- I("error", q);
767
- }
768
- });
769
- m({
770
- clock: r,
771
- target: o
772
- }), m({
773
- clock: s,
774
- target: y
775
- }), m({
776
- clock: o.doneData,
777
- target: [
778
- u,
779
- d,
780
- n
781
- ]
782
- }), m({
783
- clock: o.doneData,
784
- target: t.eventBus.prepend((c) => ({
785
- type: "experience_initialize",
786
- experience: c
787
- }))
788
- }), m({
789
- clock: n,
790
- target: b
791
- });
792
- function F(c, S, x) {
793
- r({ experience: c, target: S, options: x });
794
- }
795
- const M = e.map((c) => Object.values(c).flat());
796
- function U(c) {
797
- return e.map((S) => S[c] || [], { skipVoid: !1 });
798
- }
799
- return {
800
- spawn: F,
801
- getByExperienceId: U,
802
- listStore: M
803
- };
804
- });
805
- function oe(t) {
806
- return pt(zt, t);
807
- }
808
- export {
809
- P as a,
810
- oe as b,
811
- ne as c,
812
- te as d,
813
- at as e,
814
- Ct as f,
815
- ee as g,
816
- qt as h,
817
- $t as i,
818
- re as t
819
- };