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