@picked/client 0.0.12-next.13 → 0.0.12-next.2

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