@picked/client 0.0.1-dev.1773804563218 → 0.0.1-dev.1773878362211

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 (112) hide show
  1. package/dist/{api-CQ1Lb-dB.js → api-4YC7Dkcf.js} +1 -1
  2. package/dist/{api-C90ugp6M.cjs → api-dQTozK5u.cjs} +1 -1
  3. package/dist/cjs/form/index.js +1 -0
  4. package/dist/cjs/index.js +2 -2
  5. package/dist/cjs/plugins/create-experience/index.js +1 -1
  6. package/dist/cjs/plugins/dynamic-experiences/index.js +1 -1
  7. package/dist/cjs/plugins/experience-browser-storage/index.js +1 -1
  8. package/dist/cjs/plugins/history-browser-storage/index.js +1 -1
  9. package/dist/cjs/plugins/responses-browser-storage/index.js +1 -1
  10. package/dist/cjs/plugins/responses-indexeddb/index.js +1 -1
  11. package/dist/cjs/plugins/single-page-app/index.js +1 -1
  12. package/dist/cjs/server/index.js +1 -1
  13. package/dist/esm/form/index.js +393 -0
  14. package/dist/esm/index.js +684 -770
  15. package/dist/esm/plugins/create-experience/index.js +284 -359
  16. package/dist/esm/plugins/dynamic-experiences/index.js +80 -146
  17. package/dist/esm/plugins/experience-browser-storage/index.js +1 -1
  18. package/dist/esm/plugins/history-browser-storage/index.js +1 -1
  19. package/dist/esm/plugins/responses-browser-storage/index.js +1 -1
  20. package/dist/esm/plugins/responses-indexeddb/index.js +51 -46
  21. package/dist/esm/plugins/single-page-app/index.js +24 -24
  22. package/dist/esm/server/index.js +7 -7
  23. package/dist/experience-instance-Bd4kkjE6.js +559 -0
  24. package/dist/experience-instance-UAZPiG2b.cjs +1 -0
  25. package/dist/{object-JwZ58NOH.js → object-CJssU1Pm.js} +1 -1
  26. package/dist/object-mwaxtjLG.cjs +1 -0
  27. package/dist/rules-logic-CZfip-Wl.js +265 -0
  28. package/dist/rules-logic-Cgia6n5p.cjs +1 -0
  29. package/dist/storage-58NoTSsc.cjs +1 -0
  30. package/dist/{storage-Co_LbKr_.js → storage-B2d81EOI.js} +35 -30
  31. package/dist/types/entities/action/action.d.ts.map +1 -1
  32. package/dist/types/entities/experience/experience.d.ts +31 -46
  33. package/dist/types/entities/experience/experience.d.ts.map +1 -1
  34. package/dist/types/entities/experience-instance/experience-instance.d.ts +2 -2
  35. package/dist/types/entities/experience-instance/experience-instance.d.ts.map +1 -1
  36. package/dist/types/entities/feature/feature.d.ts.map +1 -1
  37. package/dist/types/entities/field/field.d.ts +12 -17
  38. package/dist/types/entities/field/field.d.ts.map +1 -1
  39. package/dist/types/entities/history/history.d.ts.map +1 -1
  40. package/dist/types/entities/project/project.d.ts.map +1 -1
  41. package/dist/types/entities/response/response.d.ts +7 -9
  42. package/dist/types/entities/response/response.d.ts.map +1 -1
  43. package/dist/types/form/build-responses.d.ts +14 -0
  44. package/dist/types/form/build-responses.d.ts.map +1 -0
  45. package/dist/types/form/create-field-evaluator.d.ts +19 -0
  46. package/dist/types/form/create-field-evaluator.d.ts.map +1 -0
  47. package/dist/types/form/create-field-validation.d.ts +44 -0
  48. package/dist/types/form/create-field-validation.d.ts.map +1 -0
  49. package/dist/types/form/create-form.d.ts +56 -0
  50. package/dist/types/form/create-form.d.ts.map +1 -0
  51. package/dist/types/form/create-submit-pipeline.d.ts +58 -0
  52. package/dist/types/form/create-submit-pipeline.d.ts.map +1 -0
  53. package/dist/types/form/get-step-fields.d.ts +5 -0
  54. package/dist/types/form/get-step-fields.d.ts.map +1 -0
  55. package/dist/types/form/index.d.ts +10 -0
  56. package/dist/types/form/index.d.ts.map +1 -0
  57. package/dist/types/index.d.ts +1 -2
  58. package/dist/types/index.d.ts.map +1 -1
  59. package/dist/types/logic-engine.d.ts +2 -8
  60. package/dist/types/logic-engine.d.ts.map +1 -1
  61. package/dist/types/picked.d.ts +23 -41
  62. package/dist/types/picked.d.ts.map +1 -1
  63. package/dist/types/plugins/create-experience/create-experience.d.ts +41 -70
  64. package/dist/types/plugins/create-experience/create-experience.d.ts.map +1 -1
  65. package/dist/types/plugins/create-experience/index.d.ts +1 -1
  66. package/dist/types/plugins/create-experience/index.d.ts.map +1 -1
  67. package/dist/types/plugins/create-experience/plugin.d.ts.map +1 -1
  68. package/dist/types/plugins/dynamic-experiences/plugin.d.ts +5 -20
  69. package/dist/types/plugins/dynamic-experiences/plugin.d.ts.map +1 -1
  70. package/dist/types/plugins/dynamic-experiences/types.d.ts +0 -46
  71. package/dist/types/plugins/dynamic-experiences/types.d.ts.map +1 -1
  72. package/dist/types/plugins/experience-browser-storage/plugin.d.ts +2 -1
  73. package/dist/types/plugins/experience-browser-storage/plugin.d.ts.map +1 -1
  74. package/dist/types/plugins/history-browser-storage/plugin.d.ts +2 -1
  75. package/dist/types/plugins/history-browser-storage/plugin.d.ts.map +1 -1
  76. package/dist/types/plugins/responses-browser-storage/plugin.d.ts +2 -1
  77. package/dist/types/plugins/responses-browser-storage/plugin.d.ts.map +1 -1
  78. package/dist/types/plugins/responses-indexeddb/plugin.d.ts.map +1 -1
  79. package/dist/types/plugins/single-page-app/plugin.d.ts +1 -1
  80. package/dist/types/plugins/single-page-app/plugin.d.ts.map +1 -1
  81. package/dist/types/utils/dom.d.ts +0 -3
  82. package/dist/types/utils/dom.d.ts.map +1 -1
  83. package/dist/types/utils/events.d.ts +2 -2
  84. package/dist/types/utils/events.d.ts.map +1 -1
  85. package/dist/types/utils/global-obj.d.ts +0 -1
  86. package/dist/types/utils/global-obj.d.ts.map +1 -1
  87. package/dist/types/utils/indexed-db.d.ts +2 -1
  88. package/dist/types/utils/indexed-db.d.ts.map +1 -1
  89. package/dist/types/utils/logger.d.ts.map +1 -1
  90. package/dist/types/utils/node-tree/min-max-steps-to-leaf.d.ts.map +1 -1
  91. package/dist/types/utils/node-tree/min-max-steps-to-origin.d.ts.map +1 -1
  92. package/dist/types/utils/node-tree/next-reachable-step-nodes.d.ts +3 -3
  93. package/dist/types/utils/node-tree/next-reachable-step-nodes.d.ts.map +1 -1
  94. package/dist/types/utils/nodes.d.ts +2 -2
  95. package/dist/types/utils/nodes.d.ts.map +1 -1
  96. package/dist/types/utils/object.d.ts +0 -8
  97. package/dist/types/utils/object.d.ts.map +1 -1
  98. package/dist/types/utils/picked-config.d.ts +1 -1
  99. package/dist/types/utils/picked-config.d.ts.map +1 -1
  100. package/dist/types/utils/search-params.d.ts.map +1 -1
  101. package/dist/types/utils/storage.d.ts.map +1 -1
  102. package/package.json +27 -3
  103. package/dist/experience-instance-8P1fJuPC.js +0 -819
  104. package/dist/experience-instance-Bi3-1tP5.cjs +0 -1
  105. package/dist/object-BbFTsGh3.cjs +0 -1
  106. package/dist/storage-Be5xWNPC.cjs +0 -1
  107. package/dist/types/entities/condition/condition.d.ts +0 -17
  108. package/dist/types/entities/condition/condition.d.ts.map +0 -1
  109. package/dist/types/entities/step/step.d.ts +0 -20
  110. package/dist/types/entities/step/step.d.ts.map +0 -1
  111. package/dist/types/utils/key.d.ts +0 -12
  112. package/dist/types/utils/key.d.ts.map +0 -1
@@ -1,819 +0,0 @@
1
- import { createDomain as kt, createEvent as I, combine as R, 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 E } 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 K(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 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 ? K(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(K);
113
- return e.filter(K).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 !K(r) || !K(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 (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))), 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 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 ct(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
- }), {}), c = 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: c
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 G = "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
- (c) => !Pt(c, e) && !Ct(c, 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(`${G}-${e}`) : t.classList.contains(G);
321
- }
322
- function Ht(t) {
323
- const e = document.createElement("div");
324
- return e.style.display = "block", e.classList.add(G), e.classList.add(`${G}-${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 at(t) {
354
- return t.type === "conditional";
355
- }
356
- function C(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), C(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
- })), Kt = (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 c = e.filter((d) => d.sourceNodeId === r.id);
375
- if (c.length === 0) return [0, 0];
376
- let o = 1 / 0, u = -1 / 0;
377
- for (const d of c) {
378
- const y = t.find((T) => T.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
- }, Ut = (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 c = 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 && (c = Math.min(c, y + 1), o = Math.max(o, b + 1));
406
- }
407
- return c === 1 / 0 ? [-1, -1] : [c, o];
408
- }, Wt = (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((c) => c.sourceNodeId === t.id);
412
- if (!n)
413
- return null;
414
- const s = e.find((c) => c.id === n.destinationNodeId);
415
- return s || null;
416
- };
417
- async function Gt(t, e, r, n) {
418
- const s = t ? "true" : "false", c = n.find(
419
- (o) => o.sourceNodeHandle === s && o.sourceNodeId === e
420
- );
421
- return r.find((o) => o.id === c?.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 = I(), c = I(), o = I(), u = I(), d = I(), y = I(), b = e.componentStore, F = tt.store("transitioning"), T = t.history.entriesStore.map((i) => i.filter((l) => l.experienceId === e.id)), U = T.map((i) => i.filter((l) => C(l.node))), a = T.map((i) => i.at(-1)?.node || null), S = R(
431
- t.steps.listStore,
432
- a,
433
- (i, l) => i.find((f) => l && C(l) && f.key === l.stepKey) || null
434
- ), x = R(
435
- t.steps.listStore,
436
- U,
437
- (i, l) => {
438
- const f = l.at(-2);
439
- if (!f || !C(f.node))
440
- return null;
441
- const h = f.node;
442
- return i.find((B) => B.key === h.stepKey) || null;
443
- }
444
- ), L = R(
445
- e.treeStore,
446
- a,
447
- ({ nodes: i, edges: l }, f) => f ? Kt(i, l, f) : []
448
- ), H = R(
449
- e.treeStore,
450
- a,
451
- ({ nodes: i, edges: l }, f) => f ? Wt(i, l, f) : [-1, -1]
452
- ), q = R(
453
- e.treeStore,
454
- a,
455
- ({ nodes: i, edges: l }, f) => f ? Ut(i, l, f) : [-1, -1]
456
- ), D = tt.store(!1), W = lt(D, {
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) => C(h) && h.stepKey === l);
467
- f && t.history.push({ experienceId: e.id, node: f });
468
- }
469
- }), et = O({
470
- source: a,
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, conditions: f }, h) => {
485
- if (!at(h))
486
- return;
487
- const B = h.conditionId ?? h.conditionalId, w = t.conditions.listStore.getState().find((_) => _.id === B)?.condition ?? f.find((_) => _.id === B)?.condition;
488
- if (!w)
489
- return;
490
- const A = await ct(t, w);
491
- return Gt(!!A, h.id, 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
- E("warn", `Action node ${f.id} has no action name`);
501
- return;
502
- }
503
- const B = t.actions.getByName(h).getState();
504
- if (!B) {
505
- E("warn", `Action '${h}' not registered on client`);
506
- const k = l.find(
507
- (w) => w.sourceNodeId === f.id && w.sourceNodeHandle === "false"
508
- );
509
- return k ? i.find((w) => w.id === k.destinationNodeId) : null;
510
- }
511
- if (typeof B.action != "function") {
512
- E("warn", `Action '${h}' is not a function`);
513
- const k = l.find(
514
- (w) => w.sourceNodeId === f.id && w.sourceNodeHandle === "false"
515
- );
516
- return k ? i.find((w) => w.id === k.destinationNodeId) : null;
517
- }
518
- try {
519
- E("info", `Executing action: ${h}`), await B.action(h);
520
- const k = l.find(
521
- (A) => A.sourceNodeId === f.id && A.sourceNodeHandle === "true"
522
- );
523
- if (!k)
524
- return E("warn", `No 'true' edge found for action node ${f.id}`), null;
525
- const w = i.find((A) => A.id === k.destinationNodeId);
526
- return E("info", `Action '${h}' succeeded, moving to node ${w?.id}`), w || null;
527
- } catch (k) {
528
- E("warn", `Action '${h}' failed:`, k);
529
- const w = l.find(
530
- (_) => _.sourceNodeId === f.id && _.sourceNodeHandle === "false"
531
- );
532
- if (!w)
533
- return E("warn", `No 'false' edge found for action node ${f.id}`), null;
534
- const A = i.find((_) => _.id === w.destinationNodeId);
535
- return E("info", `Action '${h}' failed, moving to node ${A?.id}`), A || null;
536
- }
537
- }
538
- }), Et = $((i) => {
539
- ut(i) && t.experiences.launch({ id: i.experienceId });
540
- }), rt = O({
541
- source: [a, e.treeStore],
542
- effect: async ([i, { nodes: l, edges: f }]) => Z(i, l, f)
543
- }), j = O({
544
- source: [a, e.treeStore],
545
- effect: async ([i, { nodes: l, edges: f }]) => Z(i, l, f)
546
- }), It = $((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 ct(t, i) : i ?? !1
551
- }), M = Object.freeze({
552
- // eslint-disable-next-line sonarjs/pseudo-random -- instance ID is non-security-sensitive
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: F,
561
- // open close
562
- isOpenStore: D,
563
- open: W.open,
564
- close: W.close,
565
- toggleOpen: W.toggle,
566
- setOpen: W.set,
567
- // nodes
568
- treeStore: e.treeStore,
569
- currentNodeStore: a,
570
- currentStepStore: S,
571
- previousStepStore: x,
572
- nextReachableStepNodesStore: L,
573
- stepsToOriginStore: H,
574
- stepsToLeafStore: q,
575
- // history
576
- goToNextStep: c,
577
- goToPreviousStep: o,
578
- goToStepById: u,
579
- stepsHistoryStore: U
580
- }), Q = I(), it = I();
581
- return m({
582
- source: a,
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) => at(i) ? "condition" : C(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: Et,
600
- action: nt,
601
- __: I()
602
- }
603
- }), m({
604
- clock: [
605
- J.doneData,
606
- X.doneData,
607
- z.doneData,
608
- j.doneData,
609
- rt.doneData,
610
- nt.doneData
611
- ],
612
- filter: Boolean,
613
- target: It
614
- }), m({
615
- clock: c,
616
- target: j
617
- }), m({
618
- clock: c,
619
- source: S,
620
- filter: Boolean,
621
- target: t.eventBus.prepend((i) => ({
622
- type: "step_submit",
623
- step: i,
624
- experience: M
625
- }))
626
- }), m({
627
- clock: j.done,
628
- source: S,
629
- filter: Boolean,
630
- target: t.eventBus.prepend((i) => ({
631
- type: "step_submit_success",
632
- step: i,
633
- experience: M
634
- }))
635
- }), m({
636
- clock: j.fail,
637
- source: S,
638
- filter: Boolean,
639
- target: t.eventBus.prepend((i) => ({
640
- type: "step_submit_error",
641
- step: i,
642
- experience: M
643
- }))
644
- }), m({
645
- clock: o,
646
- target: xt
647
- }), m({ clock: u, target: Nt }), m({
648
- source: R([
649
- J.pending,
650
- X.pending,
651
- z.pending,
652
- j.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: M
664
- }))
665
- }), m({
666
- clock: y,
667
- target: ot
668
- }), m({
669
- source: ot.doneData,
670
- fn: Boolean,
671
- target: D
672
- }), m({
673
- source: a,
674
- clock: s,
675
- filter: (i) => i ? Y(i) : !0,
676
- target: rt
677
- }), m({
678
- source: D,
679
- filter: Boolean,
680
- target: s
681
- }), m({
682
- source: D,
683
- filter: Boolean,
684
- target: t.eventBus.prepend(() => ({
685
- type: "experience_open",
686
- experience: M
687
- }))
688
- }), m({
689
- source: D,
690
- filter: (i) => !i,
691
- target: t.eventBus.prepend(() => ({
692
- type: "experience_close",
693
- experience: M
694
- }))
695
- }), m({
696
- clock: d,
697
- target: [y]
698
- }), d(), M;
699
- }
700
- );
701
- function qt(t) {
702
- return pt(Vt, t);
703
- }
704
- const zt = dt(({ client: t }) => {
705
- const e = tt.store({}), r = I(), n = I(), s = I(), c = lt(e, {
706
- register(a, S) {
707
- const x = [
708
- ...a[S.experienceId] ?? []
709
- ];
710
- return x.push(S), {
711
- ...a,
712
- [S.experienceId]: x
713
- };
714
- },
715
- unregister(a, S) {
716
- const x = S.experienceId, L = a[x]?.filter(
717
- (H) => H !== S
718
- );
719
- return {
720
- ...a,
721
- [x]: L ?? []
722
- };
723
- }
724
- }), o = $(
725
- ({
726
- experience: a,
727
- target: S,
728
- options: x
729
- }) => qt({ client: t, experience: a, target: S, options: x })
730
- ), u = $((a) => {
731
- c.register(a);
732
- }), d = $(
733
- (a) => {
734
- a.target && Dt(a.target, () => {
735
- s(a);
736
- });
737
- }
738
- ), y = $((a) => {
739
- c.unregister(a);
740
- }), b = $((a) => {
741
- const S = a.componentStore.getState();
742
- if (!S) {
743
- E("warn", "No app component registered. Skipping init.");
744
- return;
745
- }
746
- const x = S.frameworkStore.getState();
747
- if (!x) {
748
- E(
749
- "error",
750
- `No framework registered for component '${S.name}'. Skipping rendering.`
751
- );
752
- return;
753
- }
754
- const L = a.target;
755
- if (!L) {
756
- E(
757
- "error",
758
- `No target element registered for experience '${a.experienceId}'. Skipping rendering.`
759
- );
760
- return;
761
- }
762
- const H = Lt(L);
763
- try {
764
- x.render(H, S.component, t, a);
765
- } catch (q) {
766
- E("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((a) => ({
785
- type: "experience_initialize",
786
- experience: a
787
- }))
788
- }), m({
789
- clock: n,
790
- target: b
791
- });
792
- function F(a, S, x) {
793
- r({ experience: a, target: S, options: x });
794
- }
795
- const T = e.map((a) => Object.values(a).flat());
796
- function U(a) {
797
- return e.map((S) => S[a] || [], { skipVoid: !1 });
798
- }
799
- return {
800
- spawn: F,
801
- getByExperienceId: U,
802
- listStore: T
803
- };
804
- });
805
- function oe(t) {
806
- return pt(zt, t);
807
- }
808
- export {
809
- C as a,
810
- oe as b,
811
- ne as c,
812
- te as d,
813
- ct as e,
814
- Ct as f,
815
- ee as g,
816
- qt as h,
817
- $t as i,
818
- re as t
819
- };