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

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 (74) hide show
  1. package/dist/api-WKe5XBeR.cjs +1 -0
  2. package/dist/api-ZK-H-MlI.js +37 -0
  3. package/dist/cjs/form/index.js +1 -1
  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/plugins/web-components/index.js +1 -1
  13. package/dist/cjs/plugins/window-object/index.js +1 -1
  14. package/dist/cjs/server/index.js +1 -1
  15. package/dist/esm/form/index.js +416 -381
  16. package/dist/esm/index.js +1138 -1204
  17. package/dist/esm/plugins/create-experience/index.js +425 -434
  18. package/dist/esm/plugins/dynamic-experiences/index.js +106 -123
  19. package/dist/esm/plugins/experience-browser-storage/index.js +32 -37
  20. package/dist/esm/plugins/history-browser-storage/index.js +23 -25
  21. package/dist/esm/plugins/responses-browser-storage/index.js +36 -39
  22. package/dist/esm/plugins/responses-indexeddb/index.js +77 -85
  23. package/dist/esm/plugins/single-page-app/index.js +31 -35
  24. package/dist/esm/plugins/web-components/index.js +18 -20
  25. package/dist/esm/plugins/window-object/index.js +9 -9
  26. package/dist/esm/server/index.js +95 -89
  27. package/dist/experience-instance-DZiAwXph.js +481 -0
  28. package/dist/experience-instance-Ddk4Jktn.cjs +1 -0
  29. package/dist/id-Bv44ilEo.cjs +1 -0
  30. package/dist/id-CRqy981z.js +4 -0
  31. package/dist/logger-6z_gb4rA.js +4 -0
  32. package/dist/logger-fbvQC40v.cjs +1 -0
  33. package/dist/object-C82v79xc.js +25 -0
  34. package/dist/object-CUJOjanb.cjs +1 -0
  35. package/dist/rules-logic-B7vJrWyO.js +231 -0
  36. package/dist/rules-logic-CXr4wXcG.cjs +1 -0
  37. package/dist/storage-6Xk0uAxB.js +103 -0
  38. package/dist/storage-B6lQtc4-.cjs +1 -0
  39. package/dist/supports-0XIfd4-R.js +85 -0
  40. package/dist/supports-Dsjg-82e.cjs +1 -0
  41. package/dist/types/entities/field/field.d.ts +1 -1
  42. package/dist/types/entities/field/field.d.ts.map +1 -1
  43. package/dist/types/entities/response/response.d.ts.map +1 -1
  44. package/dist/types/form/create-form.d.ts +13 -3
  45. package/dist/types/form/create-form.d.ts.map +1 -1
  46. package/dist/types/form/create-submit-pipeline.d.ts +4 -4
  47. package/dist/types/form/create-submit-pipeline.d.ts.map +1 -1
  48. package/dist/types/index.d.ts +0 -1
  49. package/dist/types/index.d.ts.map +1 -1
  50. package/dist/types/picked.d.ts +0 -1
  51. package/dist/types/picked.d.ts.map +1 -1
  52. package/dist/types/plugins/create-experience/create-experience.d.ts +0 -4
  53. package/dist/types/plugins/create-experience/create-experience.d.ts.map +1 -1
  54. package/dist/types/plugins/history-browser-storage/plugin.d.ts +2 -2
  55. package/dist/types/plugins/history-browser-storage/plugin.d.ts.map +1 -1
  56. package/package.json +7 -21
  57. package/dist/api-4YC7Dkcf.js +0 -32
  58. package/dist/api-dQTozK5u.cjs +0 -1
  59. package/dist/experience-instance-Bd4kkjE6.js +0 -559
  60. package/dist/experience-instance-UAZPiG2b.cjs +0 -1
  61. package/dist/id-BKIWbSTy.cjs +0 -1
  62. package/dist/id-BW-g3y32.js +0 -6
  63. package/dist/logger-BsmHUUw1.cjs +0 -1
  64. package/dist/logger-C9a75KZn.js +0 -5
  65. package/dist/object-CJssU1Pm.js +0 -28
  66. package/dist/object-mwaxtjLG.cjs +0 -1
  67. package/dist/rules-logic-CZfip-Wl.js +0 -265
  68. package/dist/rules-logic-Cgia6n5p.cjs +0 -1
  69. package/dist/storage-58NoTSsc.cjs +0 -1
  70. package/dist/storage-B2d81EOI.js +0 -244
  71. package/dist/supports-8YT4QKI7.js +0 -95
  72. package/dist/supports-YvpQZxbh.cjs +0 -1
  73. package/dist/types/entities/project/project.d.ts +0 -9
  74. package/dist/types/entities/project/project.d.ts.map +0 -1
@@ -1,7 +1,7 @@
1
1
  import { Plugin } from '../../entities/plugin/plugin';
2
- interface HistoryBrowserStoragePlugin {
2
+ /** @public */
3
+ export interface HistoryBrowserStoragePlugin {
3
4
  storage?: 'local' | 'session';
4
5
  }
5
6
  export declare const historyBrowserStoragePlugin: ({ storage, }?: HistoryBrowserStoragePlugin) => Plugin;
6
- export {};
7
7
  //# sourceMappingURL=plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../src/plugins/history-browser-storage/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAK1D,UAAU,2BAA2B;IACnC,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAC9B;AAED,eAAO,MAAM,2BAA2B,GAAI,eAEzC,2BAAgC,KAAG,MA4BrC,CAAA"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../src/plugins/history-browser-storage/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAK1D,cAAc;AACd,MAAM,WAAW,2BAA2B;IAC1C,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAC9B;AAED,eAAO,MAAM,2BAA2B,GAAI,eAEzC,2BAAgC,KAAG,MA4BrC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@picked/client",
3
- "version": "0.0.1-dev.1773878362211",
3
+ "version": "0.0.1-dev.1774224866171",
4
4
  "dependencies": {
5
5
  "@withease/factories": "^1.0.5"
6
6
  },
@@ -10,17 +10,17 @@
10
10
  "@rollup/plugin-replace": "^6.0.2",
11
11
  "@size-limit/preset-small-lib": "^12.0.0",
12
12
  "@testing-library/dom": "^10.4.0",
13
- "@vitest/browser": "^4.0.17",
14
- "@vitest/coverage-istanbul": "^4.0.17",
13
+ "@vitest/browser": "^4.1.0",
14
+ "@vitest/coverage-istanbul": "^4.1.0",
15
15
  "effector": "^23.3.0",
16
16
  "happy-dom": "^20.0.2",
17
17
  "size-limit": "^12.0.0",
18
18
  "tslib": "^2.8.1",
19
19
  "typedoc": "^0.28.5",
20
20
  "typedoc-plugin-markdown": "^4.6.3",
21
- "vite": "^7.3.1",
21
+ "vite": "^8.0.1",
22
22
  "vite-plugin-dts": "^4.5.4",
23
- "vitest": "^4.0.17"
23
+ "vitest": "^4.1.0"
24
24
  },
25
25
  "exports": {
26
26
  ".": {
@@ -100,25 +100,11 @@
100
100
  "dist"
101
101
  ],
102
102
  "knip": {
103
- "ignoreFiles": [
104
- "eslint.config.js"
105
- ],
106
103
  "ignoreBinaries": [
107
104
  "knip",
108
105
  "jscpd",
109
106
  "eslint",
110
- "tsc",
111
- "attw",
112
- "size-limit"
113
- ],
114
- "ignoreDependencies": [
115
- "@repo/eslint-config",
116
- "@repo/typescript-config",
117
- "@testing-library/dom",
118
- "@vitest/browser",
119
- "size-limit",
120
- "tslib",
121
- "@vitest/coverage-v8"
107
+ "tsgo"
122
108
  ]
123
109
  },
124
110
  "main": "./dist/cjs/index.js",
@@ -143,7 +129,7 @@
143
129
  "test:coverage": "vitest run --coverage",
144
130
  "test:packaged-types": "attw --pack",
145
131
  "test:watch": "vitest",
146
- "type-check": "tsc -p . --noEmit"
132
+ "type-check": "tsgo -p . --noEmit"
147
133
  },
148
134
  "size-limit": [
149
135
  {
@@ -1,32 +0,0 @@
1
- const i = "Picked-Client", a = "Picked-Version";
2
- function u(n, t) {
3
- return {
4
- [i]: n,
5
- [a]: t
6
- };
7
- }
8
- const d = () => "0.0.1-dev.1773878362211", E = "v1";
9
- function s(n, t) {
10
- return new URL(`/api/${E}/${t}`, n).toString();
11
- }
12
- function o(n) {
13
- return { ...u("sdk", d()), ...n };
14
- }
15
- async function f(n, t, e) {
16
- const r = s(n, t);
17
- return fetch(r, { headers: o(e) });
18
- }
19
- async function p(n, t, e, r) {
20
- const c = s(n, t);
21
- return fetch(c, {
22
- method: "POST",
23
- headers: { "Content-Type": "application/json", ...o(r) },
24
- body: JSON.stringify(e)
25
- });
26
- }
27
- export {
28
- f as a,
29
- u as c,
30
- d as g,
31
- p
32
- };
@@ -1 +0,0 @@
1
- "use strict";const a="Picked-Client",d="Picked-Version";function s(e,t){return{[a]:e,[d]:t}}const o=()=>"0.0.1-dev.1773878362211",E="v1";function c(e,t){return new URL(`/api/${E}/${t}`,e).toString()}function i(e){return{...s("sdk",o()),...e}}async function f(e,t,n){const r=c(e,t);return fetch(r,{headers:i(n)})}async function l(e,t,n,r){const u=c(e,t);return fetch(u,{method:"POST",headers:{"Content-Type":"application/json",...i(r)},body:JSON.stringify(n)})}exports.createClientHeaders=s;exports.get=f;exports.getVersion=o;exports.post=l;
@@ -1,559 +0,0 @@
1
- import { createDomain as me, createEvent as I, combine as $, createApi as re, createEffect as v, attach as k, sample as f, split as xe } from "effector";
2
- import { createFactory as ie, invoke as se } from "@withease/factories";
3
- import { a as ye, s as ce, j as Ne } from "./supports-8YT4QKI7.js";
4
- import { l as y } from "./logger-C9a75KZn.js";
5
- import { e as ee, i as Ie } from "./rules-logic-CZfip-Wl.js";
6
- function Ee(e) {
7
- return !ye() || !ce() ? [] : Array.from(window.document.querySelectorAll(e)).filter(
8
- (t) => t instanceof HTMLElement
9
- );
10
- }
11
- const he = "open";
12
- function ke(e) {
13
- if (!Ne())
14
- throw new Error("Shadow DOM is not supported in this environment");
15
- return e.attachShadow({ mode: he });
16
- }
17
- function We() {
18
- return new Promise((e, t) => {
19
- if (!ce()) {
20
- t();
21
- return;
22
- }
23
- document.readyState !== "loading" ? e() : document.addEventListener("readystatechange", () => e(), { once: !0 });
24
- });
25
- }
26
- function we(e, t) {
27
- const o = new MutationObserver((a) => {
28
- document.contains(e) || (o.disconnect(), t());
29
- });
30
- o.observe(document.body, { childList: !0, subtree: !0 });
31
- }
32
- const C = "picked-root", P = "picked-target", Oe = "picked-root";
33
- function je(e, t) {
34
- return [
35
- ...e,
36
- // Target and replace picked-root web components
37
- {
38
- selector: `${Oe}[experience-id="${t}"]`,
39
- placement: "replace"
40
- }
41
- ].flatMap((a) => {
42
- const c = Ee(a.selector).filter(
43
- (d) => !Fe(d, t) && !ve(d, t)
44
- );
45
- return {
46
- ...a,
47
- elements: c
48
- };
49
- });
50
- }
51
- function Ge(e, t) {
52
- return e.flatMap((o) => o.elements.map((a) => _e(a, o.placement, t)));
53
- }
54
- function Ke(e, t) {
55
- e.classList.add(P), e.classList.add(`${P}-${t}`);
56
- }
57
- function Fe(e, t) {
58
- return t ? e.classList.contains(`${P}-${t}`) : e.classList.contains(`${P}`);
59
- }
60
- function ve(e, t) {
61
- return t ? e.classList.contains(`${C}-${t}`) : e.classList.contains(C);
62
- }
63
- function be(e) {
64
- const t = document.createElement("div");
65
- return t.style.display = "block", t.classList.add(C), t.classList.add(`${C}-${e}`), t;
66
- }
67
- function _e(e, t, o) {
68
- let a;
69
- const c = be(o);
70
- if (e instanceof Document)
71
- a = e.body.appendChild(c);
72
- else {
73
- switch (t) {
74
- case "replace":
75
- e.replaceWith(c);
76
- break;
77
- case "before":
78
- e.before(c);
79
- break;
80
- case "after":
81
- e.after(c);
82
- break;
83
- case "prepend":
84
- e.prepend(c);
85
- break;
86
- case "append":
87
- e.append(c);
88
- break;
89
- }
90
- a = c;
91
- }
92
- return a;
93
- }
94
- function te(e) {
95
- return e.type === "conditional";
96
- }
97
- function M(e) {
98
- return e.type === "step";
99
- }
100
- function ne(e) {
101
- return e.type === "experience";
102
- }
103
- function q(e) {
104
- return e.type === "origin";
105
- }
106
- function oe(e) {
107
- return e.type === "action";
108
- }
109
- const ae = (e, t, o, a, c = /* @__PURE__ */ new Set()) => c.has(o.id) ? [] : (c.add(o.id), M(o) && !a ? [o] : t.filter((u) => u.sourceNodeId === o.id).flatMap((u) => {
110
- const S = e.find((x) => x.id === u.destinationNodeId);
111
- return S ? ae(e, t, S, !1, c) : [];
112
- })), Be = (e, t, o) => ae(e, t, o, !0, /* @__PURE__ */ new Set()), de = (e, t, o, a, c = /* @__PURE__ */ new Set()) => {
113
- if (c.has(o.id)) return [-1, -1];
114
- c.add(o.id);
115
- const d = t.filter((x) => x.sourceNodeId === o.id);
116
- if (d.length === 0) return [0, 0];
117
- let u = 1 / 0, S = -1 / 0;
118
- for (const x of d) {
119
- const E = e.find((_) => _.id === x.destinationNodeId);
120
- if (!E) continue;
121
- const [w, O] = de(
122
- e,
123
- t,
124
- E,
125
- !1,
126
- new Set(c)
127
- );
128
- w !== -1 && (u = Math.min(u, w + 1), S = Math.max(S, O + 1));
129
- }
130
- return u === 1 / 0 ? [-1, -1] : [u, S];
131
- }, Te = (e, t, o) => de(e, t, o, !0, /* @__PURE__ */ new Set()), ue = (e, t, o, a = /* @__PURE__ */ new Set()) => {
132
- if (a.has(o.id)) return [-1, -1];
133
- if (a.add(o.id), o.type === "origin") return [0, 0];
134
- const c = t.filter((S) => S.destinationNodeId === o.id);
135
- if (c.length === 0) return [-1, -1];
136
- let d = 1 / 0, u = -1 / 0;
137
- for (const S of c) {
138
- const x = e.find((O) => O.id === S.sourceNodeId);
139
- if (!x) continue;
140
- const [E, w] = ue(
141
- e,
142
- t,
143
- x,
144
- new Set(a)
145
- );
146
- E !== -1 && (d = Math.min(d, E + 1), u = Math.max(u, w + 1));
147
- }
148
- return d === 1 / 0 ? [-1, -1] : [d, u];
149
- }, $e = (e, t, o) => ue(e, t, o, /* @__PURE__ */ new Set()), fe = (e) => e.find((o) => o.type === "origin") || null, V = (e, t, o) => {
150
- if (!e)
151
- return fe(t);
152
- const a = o.find((d) => d.sourceNodeId === e.id);
153
- if (!a)
154
- return null;
155
- const c = t.find((d) => d.id === a.destinationNodeId);
156
- return c || null;
157
- };
158
- async function Me(e, t, o, a) {
159
- const c = e ? "true" : "false", d = a.find(
160
- (u) => u.sourceNodeHandle === c && u.sourceNodeId === t
161
- );
162
- return o.find((u) => u.id === d?.destinationNodeId);
163
- }
164
- const X = me("experience-instance"), De = ie(
165
- ({
166
- client: e,
167
- experience: t,
168
- target: o,
169
- options: a
170
- }) => {
171
- const c = I(), d = I(), u = I(), S = I(), x = I(), E = I(), w = t.componentStore, O = X.store("transitioning"), _ = e.history.entriesStore.map((n) => n.filter((s) => s.experienceId === t.id)), L = _.map((n) => n.filter((s) => M(s.node))), r = _.map((n) => n.at(-1)?.node || null), p = $(
172
- t.treeStore,
173
- r,
174
- ({ steps: n }, s) => n.find((i) => s && M(s) && i.id === s.stepId) || null
175
- ), m = $(
176
- t.treeStore,
177
- L,
178
- ({ steps: n }, s) => {
179
- const i = s.at(-2);
180
- if (!i || !M(i.node))
181
- return null;
182
- const l = i.node;
183
- return n.find((F) => F.id === l.stepId) || null;
184
- }
185
- ), B = $(
186
- t.treeStore,
187
- r,
188
- ({ nodes: n, edges: s }, i) => i ? Be(n, s, i) : []
189
- ), D = $(
190
- t.treeStore,
191
- r,
192
- ({ nodes: n, edges: s }, i) => i ? $e(n, s, i) : [-1, -1]
193
- ), U = $(
194
- t.treeStore,
195
- r,
196
- ({ nodes: n, edges: s }, i) => i ? Te(n, s, i) : [-1, -1]
197
- ), T = X.store(!1), R = re(T, {
198
- open: () => !0,
199
- close: () => !1,
200
- toggle: (n) => !n,
201
- set: (n, s) => s
202
- }), pe = v(async () => {
203
- e.history.back({ experienceId: t.id });
204
- }), le = k({
205
- source: t.treeStore,
206
- effect: async (n, s) => {
207
- const i = n.nodes.find((l) => M(l) && l.stepId === s);
208
- i && e.history.push({ experienceId: t.id, node: i });
209
- }
210
- }), z = k({
211
- source: r,
212
- effect: (n) => {
213
- }
214
- }), W = k({
215
- source: t.treeStore,
216
- effect: async ({ nodes: n }) => fe(n)
217
- }), j = k({
218
- source: t.treeStore,
219
- effect: async ({ nodes: n, edges: s }, i) => {
220
- if (q(i))
221
- return V(i, n, s);
222
- }
223
- }), G = k({
224
- source: t.treeStore,
225
- effect: async ({ nodes: n, edges: s, conditionals: i }, l) => {
226
- if (!te(l))
227
- return;
228
- const F = i.find((h) => h.id === l.conditionalId);
229
- if (!F)
230
- return;
231
- const N = l.id, g = await ee(e, F.condition);
232
- return Me(!!g, N, n, s);
233
- }
234
- }), J = k({
235
- source: t.treeStore,
236
- effect: async ({ nodes: n, edges: s }, i) => {
237
- if (!oe(i))
238
- return;
239
- const l = i.action;
240
- if (!l) {
241
- y("warn", `Action node ${i.id} has no action name`);
242
- return;
243
- }
244
- const F = e.actions.getByName(l).getState();
245
- if (!F) {
246
- y("warn", `Action '${l}' not registered on client`);
247
- const N = s.find(
248
- (g) => g.sourceNodeId === i.id && g.sourceNodeHandle === "false"
249
- );
250
- return N ? n.find((g) => g.id === N.destinationNodeId) : null;
251
- }
252
- if (typeof F.action != "function") {
253
- y("warn", `Action '${l}' is not a function`);
254
- const N = s.find(
255
- (g) => g.sourceNodeId === i.id && g.sourceNodeHandle === "false"
256
- );
257
- return N ? n.find((g) => g.id === N.destinationNodeId) : null;
258
- }
259
- try {
260
- y("info", `Executing action: ${l}`), await F.action(l);
261
- const N = s.find(
262
- (h) => h.sourceNodeId === i.id && h.sourceNodeHandle === "true"
263
- );
264
- if (!N)
265
- return y("warn", `No 'true' edge found for action node ${i.id}`), null;
266
- const g = n.find((h) => h.id === N.destinationNodeId);
267
- return y("info", `Action '${l}' succeeded, moving to node ${g?.id}`), g || null;
268
- } catch (N) {
269
- y("warn", `Action '${l}' failed:`, N);
270
- const g = s.find(
271
- (H) => H.sourceNodeId === i.id && H.sourceNodeHandle === "false"
272
- );
273
- if (!g)
274
- return y("warn", `No 'false' edge found for action node ${i.id}`), null;
275
- const h = n.find((H) => H.id === g.destinationNodeId);
276
- return y("info", `Action '${l}' failed, moving to node ${h?.id}`), h || null;
277
- }
278
- }
279
- }), ge = v((n) => {
280
- ne(n) && e.experiences.launch({ id: n.experienceId });
281
- }), Q = k({
282
- source: [r, t.treeStore],
283
- effect: async ([n, { nodes: s, edges: i }]) => V(n, s, i)
284
- }), A = k({
285
- source: [r, t.treeStore],
286
- effect: async ([n, { nodes: s, edges: i }]) => V(n, s, i)
287
- }), Se = v((n) => {
288
- e.history.push({ experienceId: t.id, node: n });
289
- }), Y = k({
290
- source: t.configStore,
291
- effect: async ({ initializeOpenLogic: n }) => a?.initialiseOpen !== void 0 ? a.initialiseOpen : Ie(n) ? !!await ee(e, n) : n ?? !1
292
- }), b = Object.freeze({
293
- // eslint-disable-next-line sonarjs/pseudo-random -- non-security use: generating a unique runtime ID for UI tracking
294
- id: Math.random().toString(36).substring(7),
295
- // config
296
- experienceId: t.id,
297
- configStore: t.configStore,
298
- target: o,
299
- componentStore: w,
300
- // state
301
- stateStore: O,
302
- // open close
303
- isOpenStore: T,
304
- open: R.open,
305
- close: R.close,
306
- toggleOpen: R.toggle,
307
- setOpen: R.set,
308
- // nodes
309
- treeStore: t.treeStore,
310
- fieldsStore: t.fieldsStore,
311
- currentNodeStore: r,
312
- currentStepStore: p,
313
- previousStepStore: m,
314
- nextReachableStepNodesStore: B,
315
- stepsToOriginStore: D,
316
- stepsToLeafStore: U,
317
- // history
318
- goToNextStep: d,
319
- goToPreviousStep: u,
320
- goToStepById: S,
321
- stepsHistoryStore: L
322
- }), K = I(), Z = I();
323
- return f({
324
- source: r,
325
- target: K
326
- }), f({
327
- clock: K,
328
- filter: (n) => n === null,
329
- target: W
330
- }), f({
331
- clock: K,
332
- filter: (n) => n !== null,
333
- target: Z
334
- }), xe({
335
- source: Z,
336
- match: (n) => te(n) ? "condition" : M(n) ? "step" : ne(n) ? "launchExperience" : q(n) ? "origin" : oe(n) ? "action" : "other",
337
- cases: {
338
- origin: j,
339
- condition: G,
340
- step: z,
341
- launchExperience: ge,
342
- action: J,
343
- __: I()
344
- }
345
- }), f({
346
- clock: [
347
- G.doneData,
348
- j.doneData,
349
- W.doneData,
350
- A.doneData,
351
- Q.doneData,
352
- J.doneData
353
- ],
354
- filter: Boolean,
355
- target: Se
356
- }), f({
357
- clock: d,
358
- target: A
359
- }), f({
360
- clock: d,
361
- source: p,
362
- filter: Boolean,
363
- target: e.eventBus.prepend((n) => ({
364
- type: "step_submit",
365
- step: n,
366
- experience: b
367
- }))
368
- }), f({
369
- clock: A.done,
370
- source: p,
371
- filter: Boolean,
372
- target: e.eventBus.prepend((n) => ({
373
- type: "step_submit_success",
374
- step: n,
375
- experience: b
376
- }))
377
- }), f({
378
- clock: A.fail,
379
- source: p,
380
- filter: Boolean,
381
- target: e.eventBus.prepend((n) => ({
382
- type: "step_submit_error",
383
- step: n,
384
- experience: b
385
- }))
386
- }), f({
387
- clock: u,
388
- target: pe
389
- }), f({ clock: S, target: le }), f({
390
- source: $([
391
- G.pending,
392
- j.pending,
393
- W.pending,
394
- A.pending
395
- ]),
396
- fn: (n) => n.some(Boolean) ? "transitioning" : "ready",
397
- target: O
398
- }), f({
399
- clock: z.doneData,
400
- source: p,
401
- filter: Boolean,
402
- target: e.eventBus.prepend((n) => ({
403
- type: "step_enter",
404
- step: n,
405
- experience: b
406
- }))
407
- }), f({
408
- clock: E,
409
- target: Y
410
- }), f({
411
- source: Y.doneData,
412
- fn: Boolean,
413
- target: T
414
- }), f({
415
- source: r,
416
- clock: c,
417
- filter: (n) => n ? q(n) : !0,
418
- target: Q
419
- }), f({
420
- source: T,
421
- filter: Boolean,
422
- target: c
423
- }), f({
424
- source: T,
425
- filter: Boolean,
426
- target: e.eventBus.prepend(() => ({
427
- type: "experience_open",
428
- experience: b
429
- }))
430
- }), f({
431
- source: T,
432
- filter: (n) => !n,
433
- target: e.eventBus.prepend(() => ({
434
- type: "experience_close",
435
- experience: b
436
- }))
437
- }), f({
438
- clock: x,
439
- target: [E]
440
- }), x(), b;
441
- }
442
- );
443
- function Ae(e) {
444
- return se(De, e);
445
- }
446
- const Le = ie(({ client: e }) => {
447
- const t = X.store({}), o = I(), a = I(), c = I(), d = re(t, {
448
- register(r, p) {
449
- const m = [
450
- ...r[p.experienceId] ?? []
451
- ];
452
- return m.push(p), {
453
- ...r,
454
- [p.experienceId]: m
455
- };
456
- },
457
- unregister(r, p) {
458
- const m = p.experienceId, B = r[m]?.filter(
459
- (D) => D !== p
460
- );
461
- return {
462
- ...r,
463
- [m]: B ?? []
464
- };
465
- }
466
- }), u = v(
467
- ({
468
- experience: r,
469
- target: p,
470
- options: m
471
- }) => Ae({ client: e, experience: r, target: p, options: m })
472
- ), S = v((r) => {
473
- d.register(r);
474
- }), x = v(
475
- (r) => {
476
- r.target && we(r.target, () => {
477
- c(r);
478
- });
479
- }
480
- ), E = v((r) => {
481
- d.unregister(r);
482
- }), w = v((r) => {
483
- const p = r.componentStore.getState();
484
- if (!p) {
485
- y("warn", "No app component registered. Skipping init.");
486
- return;
487
- }
488
- const m = p.frameworkStore.getState();
489
- if (!m) {
490
- y(
491
- "error",
492
- `No framework registered for component '${p.name}'. Skipping rendering.`
493
- );
494
- return;
495
- }
496
- const B = r.target;
497
- if (!B) {
498
- y(
499
- "error",
500
- `No target element registered for experience '${r.experienceId}'. Skipping rendering.`
501
- );
502
- return;
503
- }
504
- const D = ke(B);
505
- try {
506
- m.render(D, p.component, e, r);
507
- } catch (U) {
508
- y("error", U);
509
- }
510
- });
511
- f({
512
- clock: o,
513
- target: u
514
- }), f({
515
- clock: c,
516
- target: E
517
- }), f({
518
- clock: u.doneData,
519
- target: [
520
- S,
521
- x,
522
- a
523
- ]
524
- }), f({
525
- clock: u.doneData,
526
- target: e.eventBus.prepend((r) => ({
527
- type: "experience_initialize",
528
- experience: r
529
- }))
530
- }), f({
531
- clock: a,
532
- target: w
533
- });
534
- function O(r, p, m) {
535
- o({ experience: r, target: p, options: m });
536
- }
537
- const _ = t.map((r) => Object.values(r).flat());
538
- function L(r) {
539
- return t.map((p) => p[r] || [], { skipVoid: !1 });
540
- }
541
- return {
542
- spawn: O,
543
- getByExperienceId: L,
544
- listStore: _
545
- };
546
- });
547
- function qe(e) {
548
- return se(Le, e);
549
- }
550
- export {
551
- qe as a,
552
- ve as b,
553
- Ge as c,
554
- We as d,
555
- Ae as e,
556
- je as g,
557
- M as i,
558
- Ke as t
559
- };
@@ -1 +0,0 @@
1
- "use strict";const o=require("effector"),H=require("@withease/factories"),D=require("./supports-YvpQZxbh.cjs"),x=require("./logger-BsmHUUw1.cjs"),G=require("./rules-logic-Cgia6n5p.cjs");function fe(e){return!D.supportsWindow()||!D.supportsDocument()?[]:Array.from(window.document.querySelectorAll(e)).filter(t=>t instanceof HTMLElement)}const pe="open";function ge(e){if(!D.supportsShadowRoot())throw new Error("Shadow DOM is not supported in this environment");return e.attachShadow({mode:pe})}function me(){return new Promise((e,t)=>{if(!D.supportsDocument()){t();return}document.readyState!=="loading"?e():document.addEventListener("readystatechange",()=>e(),{once:!0})})}function Se(e,t){const r=new MutationObserver(d=>{document.contains(e)||(r.disconnect(),t())});r.observe(document.body,{childList:!0,subtree:!0})}const L="picked-root",R="picked-target",Ee="picked-root";function xe(e,t){return[...e,{selector:`${Ee}[experience-id="${t}"]`,placement:"replace"}].flatMap(d=>{const a=fe(d.selector).filter(u=>!Ie(u,t)&&!ne(u,t));return{...d,elements:a}})}function ye(e,t){return e.flatMap(r=>r.elements.map(d=>ke(d,r.placement,t)))}function Ne(e,t){e.classList.add(R),e.classList.add(`${R}-${t}`)}function Ie(e,t){return t?e.classList.contains(`${R}-${t}`):e.classList.contains(`${R}`)}function ne(e,t){return t?e.classList.contains(`${L}-${t}`):e.classList.contains(L)}function he(e){const t=document.createElement("div");return t.style.display="block",t.classList.add(L),t.classList.add(`${L}-${e}`),t}function ke(e,t,r){let d;const a=he(r);if(e instanceof Document)d=e.body.appendChild(a);else{switch(t){case"replace":e.replaceWith(a);break;case"before":e.before(a);break;case"after":e.after(a);break;case"prepend":e.prepend(a);break;case"append":e.append(a);break}d=a}return d}function Z(e){return e.type==="conditional"}function O(e){return e.type==="step"}function ee(e){return e.type==="experience"}function K(e){return e.type==="origin"}function te(e){return e.type==="action"}const oe=(e,t,r,d,a=new Set)=>a.has(r.id)?[]:(a.add(r.id),O(r)&&!d?[r]:t.filter(l=>l.sourceNodeId===r.id).flatMap(l=>{const m=e.find(E=>E.id===l.destinationNodeId);return m?oe(e,t,m,!1,a):[]})),ve=(e,t,r)=>oe(e,t,r,!0,new Set),re=(e,t,r,d,a=new Set)=>{if(a.has(r.id))return[-1,-1];a.add(r.id);const u=t.filter(E=>E.sourceNodeId===r.id);if(u.length===0)return[0,0];let l=1/0,m=-1/0;for(const E of u){const N=e.find(b=>b.id===E.destinationNodeId);if(!N)continue;const[h,k]=re(e,t,N,!1,new Set(a));h!==-1&&(l=Math.min(l,h+1),m=Math.max(m,k+1))}return l===1/0?[-1,-1]:[l,m]},we=(e,t,r)=>re(e,t,r,!0,new Set),ie=(e,t,r,d=new Set)=>{if(d.has(r.id))return[-1,-1];if(d.add(r.id),r.type==="origin")return[0,0];const a=t.filter(m=>m.destinationNodeId===r.id);if(a.length===0)return[-1,-1];let u=1/0,l=-1/0;for(const m of a){const E=e.find(k=>k.id===m.sourceNodeId);if(!E)continue;const[N,h]=ie(e,t,E,new Set(d));N!==-1&&(u=Math.min(u,N+1),l=Math.max(l,h+1))}return u===1/0?[-1,-1]:[u,l]},Oe=(e,t,r)=>ie(e,t,r,new Set),ce=e=>e.find(r=>r.type==="origin")||null,j=(e,t,r)=>{if(!e)return ce(t);const d=r.find(u=>u.sourceNodeId===e.id);if(!d)return null;const a=t.find(u=>u.id===d.destinationNodeId);return a||null};async function be(e,t,r,d){const a=e?"true":"false",u=d.find(l=>l.sourceNodeHandle===a&&l.sourceNodeId===t);return r.find(l=>l.id===u?.destinationNodeId)}const V=o.createDomain("experience-instance"),Fe=H.createFactory(({client:e,experience:t,target:r,options:d})=>{const a=o.createEvent(),u=o.createEvent(),l=o.createEvent(),m=o.createEvent(),E=o.createEvent(),N=o.createEvent(),h=t.componentStore,k=V.store("transitioning"),b=e.history.entriesStore.map(n=>n.filter(s=>s.experienceId===t.id)),$=b.map(n=>n.filter(s=>O(s.node))),i=b.map(n=>n.at(-1)?.node||null),f=o.combine(t.treeStore,i,({steps:n},s)=>n.find(c=>s&&O(s)&&c.id===s.stepId)||null),S=o.combine(t.treeStore,$,({steps:n},s)=>{const c=s.at(-2);if(!c||!O(c.node))return null;const p=c.node;return n.find(v=>v.id===p.stepId)||null}),F=o.combine(t.treeStore,i,({nodes:n,edges:s},c)=>c?ve(n,s,c):[]),_=o.combine(t.treeStore,i,({nodes:n,edges:s},c)=>c?Oe(n,s,c):[-1,-1]),C=o.combine(t.treeStore,i,({nodes:n,edges:s},c)=>c?we(n,s,c):[-1,-1]),T=V.store(!1),M=o.createApi(T,{open:()=>!0,close:()=>!1,toggle:n=>!n,set:(n,s)=>s}),ae=o.createEffect(async()=>{e.history.back({experienceId:t.id})}),de=o.attach({source:t.treeStore,effect:async(n,s)=>{const c=n.nodes.find(p=>O(p)&&p.stepId===s);c&&e.history.push({experienceId:t.id,node:c})}}),X=o.attach({source:i,effect:n=>{}}),P=o.attach({source:t.treeStore,effect:async({nodes:n})=>ce(n)}),q=o.attach({source:t.treeStore,effect:async({nodes:n,edges:s},c)=>{if(K(c))return j(c,n,s)}}),U=o.attach({source:t.treeStore,effect:async({nodes:n,edges:s,conditionals:c},p)=>{if(!Z(p))return;const v=c.find(I=>I.id===p.conditionalId);if(!v)return;const y=p.id,g=await G.evaluateRuleLogic(e,v.condition);return be(!!g,y,n,s)}}),z=o.attach({source:t.treeStore,effect:async({nodes:n,edges:s},c)=>{if(!te(c))return;const p=c.action;if(!p){x.logger("warn",`Action node ${c.id} has no action name`);return}const v=e.actions.getByName(p).getState();if(!v){x.logger("warn",`Action '${p}' not registered on client`);const y=s.find(g=>g.sourceNodeId===c.id&&g.sourceNodeHandle==="false");return y?n.find(g=>g.id===y.destinationNodeId):null}if(typeof v.action!="function"){x.logger("warn",`Action '${p}' is not a function`);const y=s.find(g=>g.sourceNodeId===c.id&&g.sourceNodeHandle==="false");return y?n.find(g=>g.id===y.destinationNodeId):null}try{x.logger("info",`Executing action: ${p}`),await v.action(p);const y=s.find(I=>I.sourceNodeId===c.id&&I.sourceNodeHandle==="true");if(!y)return x.logger("warn",`No 'true' edge found for action node ${c.id}`),null;const g=n.find(I=>I.id===y.destinationNodeId);return x.logger("info",`Action '${p}' succeeded, moving to node ${g?.id}`),g||null}catch(y){x.logger("warn",`Action '${p}' failed:`,y);const g=s.find(A=>A.sourceNodeId===c.id&&A.sourceNodeHandle==="false");if(!g)return x.logger("warn",`No 'false' edge found for action node ${c.id}`),null;const I=n.find(A=>A.id===g.destinationNodeId);return x.logger("info",`Action '${p}' failed, moving to node ${I?.id}`),I||null}}}),ue=o.createEffect(n=>{ee(n)&&e.experiences.launch({id:n.experienceId})}),J=o.attach({source:[i,t.treeStore],effect:async([n,{nodes:s,edges:c}])=>j(n,s,c)}),B=o.attach({source:[i,t.treeStore],effect:async([n,{nodes:s,edges:c}])=>j(n,s,c)}),le=o.createEffect(n=>{e.history.push({experienceId:t.id,node:n})}),Q=o.attach({source:t.configStore,effect:async({initializeOpenLogic:n})=>d?.initialiseOpen!==void 0?d.initialiseOpen:G.isRulesLogic(n)?!!await G.evaluateRuleLogic(e,n):n??!1}),w=Object.freeze({id:Math.random().toString(36).substring(7),experienceId:t.id,configStore:t.configStore,target:r,componentStore:h,stateStore:k,isOpenStore:T,open:M.open,close:M.close,toggleOpen:M.toggle,setOpen:M.set,treeStore:t.treeStore,fieldsStore:t.fieldsStore,currentNodeStore:i,currentStepStore:f,previousStepStore:S,nextReachableStepNodesStore:F,stepsToOriginStore:_,stepsToLeafStore:C,goToNextStep:u,goToPreviousStep:l,goToStepById:m,stepsHistoryStore:$}),W=o.createEvent(),Y=o.createEvent();return o.sample({source:i,target:W}),o.sample({clock:W,filter:n=>n===null,target:P}),o.sample({clock:W,filter:n=>n!==null,target:Y}),o.split({source:Y,match:n=>Z(n)?"condition":O(n)?"step":ee(n)?"launchExperience":K(n)?"origin":te(n)?"action":"other",cases:{origin:q,condition:U,step:X,launchExperience:ue,action:z,__:o.createEvent()}}),o.sample({clock:[U.doneData,q.doneData,P.doneData,B.doneData,J.doneData,z.doneData],filter:Boolean,target:le}),o.sample({clock:u,target:B}),o.sample({clock:u,source:f,filter:Boolean,target:e.eventBus.prepend(n=>({type:"step_submit",step:n,experience:w}))}),o.sample({clock:B.done,source:f,filter:Boolean,target:e.eventBus.prepend(n=>({type:"step_submit_success",step:n,experience:w}))}),o.sample({clock:B.fail,source:f,filter:Boolean,target:e.eventBus.prepend(n=>({type:"step_submit_error",step:n,experience:w}))}),o.sample({clock:l,target:ae}),o.sample({clock:m,target:de}),o.sample({source:o.combine([U.pending,q.pending,P.pending,B.pending]),fn:n=>n.some(Boolean)?"transitioning":"ready",target:k}),o.sample({clock:X.doneData,source:f,filter:Boolean,target:e.eventBus.prepend(n=>({type:"step_enter",step:n,experience:w}))}),o.sample({clock:N,target:Q}),o.sample({source:Q.doneData,fn:Boolean,target:T}),o.sample({source:i,clock:a,filter:n=>n?K(n):!0,target:J}),o.sample({source:T,filter:Boolean,target:a}),o.sample({source:T,filter:Boolean,target:e.eventBus.prepend(()=>({type:"experience_open",experience:w}))}),o.sample({source:T,filter:n=>!n,target:e.eventBus.prepend(()=>({type:"experience_close",experience:w}))}),o.sample({clock:E,target:[N]}),E(),w});function se(e){return H.invoke(Fe,e)}const Te=H.createFactory(({client:e})=>{const t=V.store({}),r=o.createEvent(),d=o.createEvent(),a=o.createEvent(),u=o.createApi(t,{register(i,f){const S=[...i[f.experienceId]??[]];return S.push(f),{...i,[f.experienceId]:S}},unregister(i,f){const S=f.experienceId,F=i[S]?.filter(_=>_!==f);return{...i,[S]:F??[]}}}),l=o.createEffect(({experience:i,target:f,options:S})=>se({client:e,experience:i,target:f,options:S})),m=o.createEffect(i=>{u.register(i)}),E=o.createEffect(i=>{i.target&&Se(i.target,()=>{a(i)})}),N=o.createEffect(i=>{u.unregister(i)}),h=o.createEffect(i=>{const f=i.componentStore.getState();if(!f){x.logger("warn","No app component registered. Skipping init.");return}const S=f.frameworkStore.getState();if(!S){x.logger("error",`No framework registered for component '${f.name}'. Skipping rendering.`);return}const F=i.target;if(!F){x.logger("error",`No target element registered for experience '${i.experienceId}'. Skipping rendering.`);return}const _=ge(F);try{S.render(_,f.component,e,i)}catch(C){x.logger("error",C)}});o.sample({clock:r,target:l}),o.sample({clock:a,target:N}),o.sample({clock:l.doneData,target:[m,E,d]}),o.sample({clock:l.doneData,target:e.eventBus.prepend(i=>({type:"experience_initialize",experience:i}))}),o.sample({clock:d,target:h});function k(i,f,S){r({experience:i,target:f,options:S})}const b=t.map(i=>Object.values(i).flat());function $(i){return t.map(f=>f[i]||[],{skipVoid:!1})}return{spawn:k,getByExperienceId:$,listStore:b}});function _e(e){return H.invoke(Te,e)}exports.createAppHosts=ye;exports.createExperienceInstance=se;exports.createExperienceInstanceIndex=_e;exports.domInteractive=me;exports.getTargetElements=xe;exports.isPickedRoot=ne;exports.isStepNode=O;exports.tagTargetElement=Ne;
@@ -1 +0,0 @@
1
- "use strict";const e={};let n=0;const r=t=>(e[t]||(e[t]=`${(n++).toString(36)}`),`${e[t]}:${(n++).toString(36)}`);exports.generateId=r;