@picked/client 0.0.1-dev.1771973228237 → 0.0.1-dev.1772057362040

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 (48) hide show
  1. package/dist/cjs/index.js +2 -2
  2. package/dist/cjs/plugins/create-experience/index.js +1 -1
  3. package/dist/cjs/server/index.js +1 -1
  4. package/dist/esm/index.js +697 -608
  5. package/dist/esm/plugins/create-experience/index.js +194 -228
  6. package/dist/esm/server/index.js +1 -1
  7. package/dist/experience-instance-5rr_D--s.cjs +1 -0
  8. package/dist/experience-instance-CLR80xop.js +819 -0
  9. package/dist/types/client.d.ts +0 -10
  10. package/dist/types/client.d.ts.map +1 -1
  11. package/dist/types/entities/action/action.d.ts +5 -2
  12. package/dist/types/entities/action/action.d.ts.map +1 -1
  13. package/dist/types/entities/experience/experience.d.ts +2 -2
  14. package/dist/types/entities/experience/experience.d.ts.map +1 -1
  15. package/dist/types/entities/experience-instance/experience-instance.d.ts +3 -4
  16. package/dist/types/entities/experience-instance/experience-instance.d.ts.map +1 -1
  17. package/dist/types/entities/field/field.d.ts +51 -14
  18. package/dist/types/entities/field/field.d.ts.map +1 -1
  19. package/dist/types/entities/plugin/plugin.d.ts +1 -4
  20. package/dist/types/entities/plugin/plugin.d.ts.map +1 -1
  21. package/dist/types/entities/response/response.d.ts.map +1 -1
  22. package/dist/types/exports.d.ts +0 -1
  23. package/dist/types/exports.d.ts.map +1 -1
  24. package/dist/types/picked.d.ts +15 -15
  25. package/dist/types/picked.d.ts.map +1 -1
  26. package/dist/types/ping.d.ts.map +1 -1
  27. package/dist/types/plugins/create-experience/create-experience.d.ts +24 -21
  28. package/dist/types/plugins/create-experience/create-experience.d.ts.map +1 -1
  29. package/dist/types/utils/get-step-fields.d.ts +2 -1
  30. package/dist/types/utils/get-step-fields.d.ts.map +1 -1
  31. package/dist/types/utils/rules-logic.d.ts.map +1 -1
  32. package/package.json +1 -7
  33. package/dist/api-CbXfbi_s.js +0 -19
  34. package/dist/api-DzSCgBQ2.cjs +0 -1
  35. package/dist/cjs/plugins/dynamic-experiences/index.js +0 -1
  36. package/dist/esm/plugins/dynamic-experiences/index.js +0 -102
  37. package/dist/experience-instance-CU_pYPyd.js +0 -820
  38. package/dist/experience-instance-D_Mwuzb4.cjs +0 -1
  39. package/dist/types/plugins/dynamic-experiences/hash.d.ts +0 -12
  40. package/dist/types/plugins/dynamic-experiences/hash.d.ts.map +0 -1
  41. package/dist/types/plugins/dynamic-experiences/index.d.ts +0 -3
  42. package/dist/types/plugins/dynamic-experiences/index.d.ts.map +0 -1
  43. package/dist/types/plugins/dynamic-experiences/plugin.d.ts +0 -23
  44. package/dist/types/plugins/dynamic-experiences/plugin.d.ts.map +0 -1
  45. package/dist/types/plugins/dynamic-experiences/types.d.ts +0 -15
  46. package/dist/types/plugins/dynamic-experiences/types.d.ts.map +0 -1
  47. package/dist/types/utils/api.d.ts +0 -3
  48. package/dist/types/utils/api.d.ts.map +0 -1
@@ -1,820 +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 { j as vt, s as gt, a 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 Bt(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 (Bt(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 Ft = {
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 ? Ft[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 !At() || !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 (!vt())
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, B] = 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, B + 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((B) => B.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, B = 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((F) => F.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 F = f.find((A) => A.id === h.conditionalId);
488
- if (!F)
489
- return;
490
- const E = h.id, w = await at(t, F.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 F = t.actions.getByName(h).getState();
504
- if (!F) {
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 F.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 F.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
- if (ut(i))
540
- return t.launchExperienceById(i.experienceId);
541
- }), rt = O({
542
- source: [c, e.treeStore],
543
- effect: async ([i, { nodes: l, edges: f }]) => Z(i, l, f)
544
- }), H = O({
545
- source: [c, e.treeStore],
546
- effect: async ([i, { nodes: l, edges: f }]) => Z(i, l, f)
547
- }), Et = _((i) => {
548
- t.history.push({ experienceId: e.id, node: i });
549
- }), ot = O({
550
- source: e.configStore,
551
- effect: async ({ initializeOpenLogic: i }) => n?.initialiseOpen !== void 0 ? n.initialiseOpen : $t(i) ? !!await at(t, i) : i ?? !1
552
- }), $ = Object.freeze({
553
- id: Math.random().toString(36).substring(7),
554
- // config
555
- experienceId: e.id,
556
- configStore: e.configStore,
557
- target: r,
558
- componentStore: b,
559
- // state
560
- stateStore: B,
561
- // open close
562
- isOpenStore: L,
563
- open: W.open,
564
- close: W.close,
565
- toggleOpen: W.toggle,
566
- setOpen: W.set,
567
- // nodes
568
- treeStore: e.treeStore,
569
- fieldsStore: e.fieldsStore,
570
- currentNodeStore: c,
571
- currentStepStore: S,
572
- previousStepStore: x,
573
- nextReachableStepNodesStore: T,
574
- stepsToOriginStore: C,
575
- stepsToLeafStore: q,
576
- // history
577
- goToNextStep: a,
578
- goToPreviousStep: o,
579
- goToStepById: u,
580
- stepsHistoryStore: U
581
- }), Q = k(), it = k();
582
- return m({
583
- source: c,
584
- target: Q
585
- }), m({
586
- clock: Q,
587
- filter: (i) => i === null,
588
- target: z
589
- }), m({
590
- clock: Q,
591
- filter: (i) => i !== null,
592
- target: it
593
- }), bt({
594
- source: it,
595
- match: (i) => ct(i) ? "condition" : P(i) ? "step" : ut(i) ? "launchExperience" : Y(i) ? "origin" : ft(i) ? "action" : "other",
596
- cases: {
597
- origin: X,
598
- condition: J,
599
- step: et,
600
- launchExperience: It,
601
- action: nt,
602
- __: k()
603
- }
604
- }), m({
605
- clock: [
606
- J.doneData,
607
- X.doneData,
608
- z.doneData,
609
- H.doneData,
610
- rt.doneData,
611
- nt.doneData
612
- ],
613
- filter: Boolean,
614
- target: Et
615
- }), m({
616
- clock: a,
617
- target: H
618
- }), m({
619
- clock: a,
620
- source: S,
621
- filter: Boolean,
622
- target: t.eventBus.prepend((i) => ({
623
- type: "step_submit",
624
- step: i,
625
- experience: $
626
- }))
627
- }), m({
628
- clock: H.done,
629
- source: S,
630
- filter: Boolean,
631
- target: t.eventBus.prepend((i) => ({
632
- type: "step_submit_success",
633
- step: i,
634
- experience: $
635
- }))
636
- }), m({
637
- clock: H.fail,
638
- source: S,
639
- filter: Boolean,
640
- target: t.eventBus.prepend((i) => ({
641
- type: "step_submit_error",
642
- step: i,
643
- experience: $
644
- }))
645
- }), m({
646
- clock: o,
647
- target: xt
648
- }), m({ clock: u, target: Nt }), m({
649
- source: D([
650
- J.pending,
651
- X.pending,
652
- z.pending,
653
- H.pending
654
- ]),
655
- fn: (i) => i.some(Boolean) ? "transitioning" : "ready",
656
- target: B
657
- }), m({
658
- clock: et.doneData,
659
- source: S,
660
- filter: Boolean,
661
- target: t.eventBus.prepend((i) => ({
662
- type: "step_enter",
663
- step: i,
664
- experience: $
665
- }))
666
- }), m({
667
- clock: y,
668
- target: ot
669
- }), m({
670
- source: ot.doneData,
671
- fn: Boolean,
672
- target: L
673
- }), m({
674
- source: c,
675
- clock: s,
676
- filter: (i) => i ? Y(i) : !0,
677
- target: rt
678
- }), m({
679
- source: L,
680
- filter: Boolean,
681
- target: s
682
- }), m({
683
- source: L,
684
- filter: Boolean,
685
- target: t.eventBus.prepend(() => ({
686
- type: "experience_open",
687
- experience: $
688
- }))
689
- }), m({
690
- source: L,
691
- filter: (i) => !i,
692
- target: t.eventBus.prepend(() => ({
693
- type: "experience_close",
694
- experience: $
695
- }))
696
- }), m({
697
- clock: d,
698
- target: [y]
699
- }), d(), $;
700
- }
701
- );
702
- function qt(t) {
703
- return pt(Vt, t);
704
- }
705
- const zt = dt(({ client: t }) => {
706
- const e = tt.store({}), r = k(), n = k(), s = k(), a = lt(e, {
707
- register(c, S) {
708
- const x = [
709
- ...c[S.experienceId] ?? []
710
- ];
711
- return x.push(S), {
712
- ...c,
713
- [S.experienceId]: x
714
- };
715
- },
716
- unregister(c, S) {
717
- const x = S.experienceId, T = c[x]?.filter(
718
- (C) => C !== S
719
- );
720
- return {
721
- ...c,
722
- [x]: T ?? []
723
- };
724
- }
725
- }), o = _(
726
- ({
727
- experience: c,
728
- target: S,
729
- options: x
730
- }) => qt({ client: t, experience: c, target: S, options: x })
731
- ), u = _((c) => {
732
- a.register(c);
733
- }), d = _(
734
- (c) => {
735
- c.target && Dt(c.target, () => {
736
- s(c);
737
- });
738
- }
739
- ), y = _((c) => {
740
- a.unregister(c);
741
- }), b = _((c) => {
742
- const S = c.componentStore.getState();
743
- if (!S) {
744
- I("warn", "No app component registered. Skipping init.");
745
- return;
746
- }
747
- const x = S.frameworkStore.getState();
748
- if (!x) {
749
- I(
750
- "error",
751
- `No framework registered for component '${S.name}'. Skipping rendering.`
752
- );
753
- return;
754
- }
755
- const T = c.target;
756
- if (!T) {
757
- I(
758
- "error",
759
- `No target element registered for experience '${c.experienceId}'. Skipping rendering.`
760
- );
761
- return;
762
- }
763
- const C = Lt(T);
764
- try {
765
- x.render(C, S.component, t, c);
766
- } catch (q) {
767
- I("error", q);
768
- }
769
- });
770
- m({
771
- clock: r,
772
- target: o
773
- }), m({
774
- clock: s,
775
- target: y
776
- }), m({
777
- clock: o.doneData,
778
- target: [
779
- u,
780
- d,
781
- n
782
- ]
783
- }), m({
784
- clock: o.doneData,
785
- target: t.eventBus.prepend((c) => ({
786
- type: "experience_initialize",
787
- experience: c
788
- }))
789
- }), m({
790
- clock: n,
791
- target: b
792
- });
793
- function B(c, S, x) {
794
- r({ experience: c, target: S, options: x });
795
- }
796
- const M = e.map((c) => Object.values(c).flat());
797
- function U(c) {
798
- return e.map((S) => S[c] || [], { skipVoid: !1 });
799
- }
800
- return {
801
- spawn: B,
802
- getByExperienceId: U,
803
- listStore: M
804
- };
805
- });
806
- function oe(t) {
807
- return pt(zt, t);
808
- }
809
- export {
810
- P as a,
811
- oe as b,
812
- ne as c,
813
- te as d,
814
- at as e,
815
- Ct as f,
816
- ee as g,
817
- qt as h,
818
- $t as i,
819
- re as t
820
- };