@picked/client 0.0.12 → 0.0.14-next.1
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.
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/plugins/create-experience/index.js +1 -1
- package/dist/cjs/plugins/shopify/index.js +1 -1
- package/dist/cjs/server/index.js +1 -1
- package/dist/esm/index.js +157 -707
- package/dist/esm/plugins/create-experience/index.js +229 -178
- package/dist/esm/plugins/shopify/index.js +89 -36
- package/dist/esm/plugins/single-page-app/index.js +3 -3
- package/dist/esm/plugins/web-components/index.js +1 -1
- package/dist/esm/plugins/window-object/index.js +1 -1
- package/dist/esm/server/index.js +7 -7
- package/dist/experience-instance-B2l_MG7I.cjs +1 -0
- package/dist/experience-instance-CeuHLrdL.js +781 -0
- package/dist/{supports-BjhuLJ8z.js → supports-DBMT17KZ.js} +10 -10
- package/dist/types/client.d.ts +26 -0
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/entities/action/action.d.ts +15 -0
- package/dist/types/entities/action/action.d.ts.map +1 -0
- package/dist/types/entities/experience/experience.d.ts +19 -6
- package/dist/types/entities/experience/experience.d.ts.map +1 -1
- package/dist/types/entities/experience-instance/experience-instance.d.ts +3 -3
- package/dist/types/entities/experience-instance/experience-instance.d.ts.map +1 -1
- package/dist/types/entities/feature/feature.d.ts +5 -2
- package/dist/types/entities/feature/feature.d.ts.map +1 -1
- package/dist/types/picked.d.ts +14 -4
- package/dist/types/picked.d.ts.map +1 -1
- package/dist/types/plugins/create-experience/create-experience.d.ts +23 -5
- package/dist/types/plugins/create-experience/create-experience.d.ts.map +1 -1
- package/dist/types/plugins/shopify/global-obj.d.ts +49 -0
- package/dist/types/plugins/shopify/global-obj.d.ts.map +1 -0
- package/dist/types/plugins/shopify/index.d.ts +4 -0
- package/dist/types/plugins/shopify/index.d.ts.map +1 -1
- package/dist/types/plugins/shopify/picked-config.d.ts +103 -0
- package/dist/types/plugins/shopify/picked-config.d.ts.map +1 -0
- package/dist/types/plugins/shopify/{shopify.d.ts → predicates.d.ts} +20 -6
- package/dist/types/plugins/shopify/predicates.d.ts.map +1 -0
- package/dist/types/utils/events.d.ts +10 -4
- package/dist/types/utils/events.d.ts.map +1 -1
- package/dist/types/utils/nodes.d.ts +2 -1
- package/dist/types/utils/nodes.d.ts.map +1 -1
- package/dist/user-session-D-l-VMTb.cjs +1 -0
- package/dist/user-session-Ht0ayuo5.js +632 -0
- package/package.json +6 -6
- package/dist/experience-instance-DXWLnF-R.cjs +0 -1
- package/dist/experience-instance-XlIuqLrL.js +0 -716
- package/dist/types/plugins/shopify/shopify.d.ts.map +0 -1
- package/dist/types/plugins/shopify/utils.d.ts +0 -21
- package/dist/types/plugins/shopify/utils.d.ts.map +0 -1
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
import { createDomain as h, createApi as b, createEffect as j, attach as _, sample as x, combine as B, createEvent as O } from "effector";
|
|
2
|
+
import { createFactory as v, invoke as k } from "@withease/factories";
|
|
3
|
+
import { g as N, t as U, b as H, f as q, e as C, h as z } from "./experience-instance-CeuHLrdL.js";
|
|
4
|
+
import { l as E } from "./logger-C9a75KZn.js";
|
|
5
|
+
import { c as D, s as M, l as A } from "./storage-Cb_71y48.js";
|
|
6
|
+
import { g as G } from "./id-BW-g3y32.js";
|
|
7
|
+
import { i as K } from "./object-JwZ58NOH.js";
|
|
8
|
+
import { e as Y, k as J } from "./supports-DBMT17KZ.js";
|
|
9
|
+
const L = h("experience"), Q = v(
|
|
10
|
+
({ client: t, experience: e }) => {
|
|
11
|
+
const i = L.store(e), g = b(i, {
|
|
12
|
+
merge(c, m) {
|
|
13
|
+
return {
|
|
14
|
+
...c,
|
|
15
|
+
...m.experience
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}), p = i.map((c) => ({
|
|
19
|
+
name: c.name,
|
|
20
|
+
decisionLogic: c.decide,
|
|
21
|
+
targetSelectors: c.targets,
|
|
22
|
+
initializeOpenLogic: e.initializeOpen
|
|
23
|
+
})), d = t.components.listStore.map(
|
|
24
|
+
(c) => c.find((m) => m.name === `experience:${e.id}`) || c.find((m) => m.name === "experience"),
|
|
25
|
+
{ skipVoid: !1 }
|
|
26
|
+
), r = i.map((c) => ({
|
|
27
|
+
steps: c.steps,
|
|
28
|
+
nodes: c.nodes,
|
|
29
|
+
edges: c.edges,
|
|
30
|
+
conditionals: c.conditionals
|
|
31
|
+
})), n = e.actions ?? [];
|
|
32
|
+
return {
|
|
33
|
+
id: e.id,
|
|
34
|
+
configStore: p,
|
|
35
|
+
treeStore: r,
|
|
36
|
+
componentStore: d,
|
|
37
|
+
actions: n,
|
|
38
|
+
merge: g.merge
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
function W(t) {
|
|
43
|
+
return k(Q, t);
|
|
44
|
+
}
|
|
45
|
+
const X = v(({ client: t }) => {
|
|
46
|
+
const e = L.store({}), i = b(e, {
|
|
47
|
+
register(r, n) {
|
|
48
|
+
return {
|
|
49
|
+
...r,
|
|
50
|
+
[n.id]: n
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
function g(r) {
|
|
55
|
+
const n = e.getState()[r.id];
|
|
56
|
+
if (n) {
|
|
57
|
+
n.merge({ experience: r, strategy: "override" });
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const c = W({ client: t, experience: r });
|
|
61
|
+
i.register(c);
|
|
62
|
+
}
|
|
63
|
+
const p = e.map((r) => Object.values(r));
|
|
64
|
+
function d(r) {
|
|
65
|
+
return e.map((n) => n[r], { skipVoid: !1 });
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
register: g,
|
|
69
|
+
getById: d,
|
|
70
|
+
listStore: p
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
function Ae(t) {
|
|
74
|
+
return k(X, t);
|
|
75
|
+
}
|
|
76
|
+
const je = (t, e) => {
|
|
77
|
+
e.register(t);
|
|
78
|
+
}, Z = (t, e) => {
|
|
79
|
+
const { targetSelectors: i } = e.configStore.getState(), g = N(i, e.id);
|
|
80
|
+
g.forEach(
|
|
81
|
+
({ elements: d }) => d.forEach((r) => U(r, e.id))
|
|
82
|
+
), H(g, e.id).forEach((d) => {
|
|
83
|
+
t.experienceInstances.spawn(e, d);
|
|
84
|
+
});
|
|
85
|
+
}, Oe = async (t) => {
|
|
86
|
+
await Promise.all(
|
|
87
|
+
t.experiences.listStore.getState().map(async (e) => {
|
|
88
|
+
await ee(t, e) && Z(t, e);
|
|
89
|
+
})
|
|
90
|
+
);
|
|
91
|
+
}, ee = async (t, e) => {
|
|
92
|
+
const { decisionLogic: i, targetSelectors: g } = e.configStore.getState();
|
|
93
|
+
return N(g, e.id).length < 1 || g.length === 0 ? !1 : i && q(i) ? await C(t, i) === !0 : !0;
|
|
94
|
+
}, te = h("component"), re = v(
|
|
95
|
+
({ client: t, component: e, name: i }) => {
|
|
96
|
+
const g = t.frameworks.getByName(e.frameworkName);
|
|
97
|
+
return {
|
|
98
|
+
name: i,
|
|
99
|
+
component: e,
|
|
100
|
+
frameworkStore: g
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
function ne(t) {
|
|
105
|
+
return k(re, t);
|
|
106
|
+
}
|
|
107
|
+
const se = v(({ client: t }) => {
|
|
108
|
+
const e = te.store({}), i = b(e, {
|
|
109
|
+
register(r, n) {
|
|
110
|
+
return {
|
|
111
|
+
...r,
|
|
112
|
+
[n.name]: n
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
function g(r, n) {
|
|
117
|
+
e.getState()[r] && E(
|
|
118
|
+
"warn",
|
|
119
|
+
`Component '${r}' already registered. Registering again will override the previous registration.`
|
|
120
|
+
);
|
|
121
|
+
const m = ne({ client: t, name: r, component: n });
|
|
122
|
+
i.register(m);
|
|
123
|
+
}
|
|
124
|
+
const p = e.map((r) => Object.values(r));
|
|
125
|
+
function d(r) {
|
|
126
|
+
return e.map((n) => n[r], { skipVoid: !1 });
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
register: g,
|
|
130
|
+
getByName: d,
|
|
131
|
+
listStore: p
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
function Me(t) {
|
|
135
|
+
return k(se, t);
|
|
136
|
+
}
|
|
137
|
+
const Pe = (t, e, i) => {
|
|
138
|
+
i.register(t, e);
|
|
139
|
+
}, oe = h("framework"), ie = v(({ client: t }) => {
|
|
140
|
+
const e = oe.store({}), i = b(e, {
|
|
141
|
+
register(r, n) {
|
|
142
|
+
return {
|
|
143
|
+
...r,
|
|
144
|
+
[n.name]: n.framework
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
function g(r, n) {
|
|
149
|
+
e.getState()[r] && E(
|
|
150
|
+
"warn",
|
|
151
|
+
`Framework '${r}' already registered. Registering again will override the previous registration.`
|
|
152
|
+
), i.register({ name: r, framework: n });
|
|
153
|
+
}
|
|
154
|
+
const p = e.map((r) => Object.values(r));
|
|
155
|
+
function d(r) {
|
|
156
|
+
return e.map((n) => n[r], { skipVoid: !1 });
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
register: g,
|
|
160
|
+
getByName: d,
|
|
161
|
+
listStore: p
|
|
162
|
+
};
|
|
163
|
+
});
|
|
164
|
+
function Te(t) {
|
|
165
|
+
return k(ie, t);
|
|
166
|
+
}
|
|
167
|
+
const Ve = (t, e) => {
|
|
168
|
+
e.register(t.name, t);
|
|
169
|
+
}, ae = 6e3, P = D("last_ping", "global"), ce = (t) => `${t}/api/v1/ping`, Ne = async (t) => {
|
|
170
|
+
try {
|
|
171
|
+
const e = Date.now(), i = localStorage.getItem(P);
|
|
172
|
+
if (i && e - parseInt(i) < ae)
|
|
173
|
+
return !0;
|
|
174
|
+
const g = ce(t.apiUrl), p = {
|
|
175
|
+
projectId: t.projectId,
|
|
176
|
+
path: window.location.pathname
|
|
177
|
+
}, d = JSON.stringify(p), r = {
|
|
178
|
+
"Content-Type": "application/json"
|
|
179
|
+
}, n = document.getElementById("picked_script"), c = n == null ? void 0 : n.dataset.verceltoken;
|
|
180
|
+
c && (r["x-vercel-protection-bypass"] = c);
|
|
181
|
+
const S = (await fetch(g, {
|
|
182
|
+
method: "POST",
|
|
183
|
+
headers: r,
|
|
184
|
+
body: d
|
|
185
|
+
})).ok;
|
|
186
|
+
return S && localStorage.setItem(P, e.toString()), S;
|
|
187
|
+
} catch (e) {
|
|
188
|
+
return E("error", e), !1;
|
|
189
|
+
}
|
|
190
|
+
}, ue = h("predicate"), le = v(({ client: t }) => {
|
|
191
|
+
const e = ue.store({}), i = b(e, {
|
|
192
|
+
register(r, n) {
|
|
193
|
+
return {
|
|
194
|
+
...r,
|
|
195
|
+
[n.name]: {
|
|
196
|
+
name: n.name,
|
|
197
|
+
predicate: n.predicate
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
function g(r, n) {
|
|
203
|
+
e.getState()[r] && E(
|
|
204
|
+
"warn",
|
|
205
|
+
`Predicate '${r}' already registered. Registering again will override the previous registration.`
|
|
206
|
+
), i.register(Object.freeze({ name: r, predicate: n }));
|
|
207
|
+
}
|
|
208
|
+
const p = e.map((r) => Object.values(r));
|
|
209
|
+
function d(r) {
|
|
210
|
+
return e.map((n) => n[r], { skipVoid: !1 });
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
register: g,
|
|
214
|
+
getByName: d,
|
|
215
|
+
listStore: p
|
|
216
|
+
};
|
|
217
|
+
});
|
|
218
|
+
function Ce(t) {
|
|
219
|
+
return k(le, t);
|
|
220
|
+
}
|
|
221
|
+
const Le = (t, e, i) => {
|
|
222
|
+
i.register(t, e);
|
|
223
|
+
}, T = h("feature"), ge = v(({ client: t }) => {
|
|
224
|
+
const e = T.store({}), i = T.store([]), g = b(e, {
|
|
225
|
+
register(a, o) {
|
|
226
|
+
return {
|
|
227
|
+
...a,
|
|
228
|
+
[o.id]: o.feature
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
function p(a, o) {
|
|
233
|
+
e.getState()[a] && E(
|
|
234
|
+
"warn",
|
|
235
|
+
`Feature '${a}' already registered. Registering again will override the previous registration.`
|
|
236
|
+
);
|
|
237
|
+
const l = {
|
|
238
|
+
id: a,
|
|
239
|
+
feature: {
|
|
240
|
+
...o,
|
|
241
|
+
id: a
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
g.register(
|
|
245
|
+
Object.freeze({
|
|
246
|
+
id: a,
|
|
247
|
+
feature: l
|
|
248
|
+
})
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
const d = j(
|
|
252
|
+
async ({
|
|
253
|
+
id: a,
|
|
254
|
+
key: o,
|
|
255
|
+
storage: s = "local"
|
|
256
|
+
}) => {
|
|
257
|
+
const l = D(`feature:${a}:${o}`, "global"), u = (s === "session" ? M : A).get(l).boolean();
|
|
258
|
+
return u === null ? null : { id: a, key: o, bucket: u };
|
|
259
|
+
}
|
|
260
|
+
), r = j((a) => {
|
|
261
|
+
if (!a)
|
|
262
|
+
return null;
|
|
263
|
+
const o = D(`feature:${a.id}:${a.key}`, "global");
|
|
264
|
+
(a.storage === "session" ? M : A).set(o, a.bucket);
|
|
265
|
+
}), n = /* @__PURE__ */ new Map(), c = _({
|
|
266
|
+
source: { allFeaturesStore: e, resolvedFeaturesStore: i },
|
|
267
|
+
effect: async ({ allFeaturesStore: a, resolvedFeaturesStore: o }, { id: s, decide: l, key: f }) => {
|
|
268
|
+
const u = o.find((R) => R.id === s);
|
|
269
|
+
if (u)
|
|
270
|
+
return u;
|
|
271
|
+
const y = a[s];
|
|
272
|
+
if (!y)
|
|
273
|
+
throw new Error(`Feature with id '${s}' not found`);
|
|
274
|
+
const w = n.get(`${s}:${f}`);
|
|
275
|
+
if (w !== void 0) {
|
|
276
|
+
const R = await w;
|
|
277
|
+
return { id: y.id, bucket: R, key: f, storage: y.feature.storage };
|
|
278
|
+
}
|
|
279
|
+
const $ = l();
|
|
280
|
+
n.set(`${s}:${f}`, $);
|
|
281
|
+
const F = await $;
|
|
282
|
+
return { id: y.id, bucket: F, key: f, storage: y.feature.storage };
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
x({
|
|
286
|
+
clock: g.register,
|
|
287
|
+
fn: (a) => {
|
|
288
|
+
const { id: o, feature: s } = a;
|
|
289
|
+
return { id: o, key: s.feature.key, storage: s.feature.storage };
|
|
290
|
+
},
|
|
291
|
+
target: d
|
|
292
|
+
}), x({
|
|
293
|
+
source: e,
|
|
294
|
+
clock: c.doneData,
|
|
295
|
+
fn: (a, o) => {
|
|
296
|
+
var y;
|
|
297
|
+
const { id: s, bucket: l, storage: f } = o, u = (y = a[s]) == null ? void 0 : y.feature.key;
|
|
298
|
+
return u ? { key: u, id: s, bucket: l, storage: f } : null;
|
|
299
|
+
},
|
|
300
|
+
target: r
|
|
301
|
+
});
|
|
302
|
+
const m = B({ allFeaturesStore: e, resolvedFeaturesStore: i }).map(
|
|
303
|
+
({
|
|
304
|
+
allFeaturesStore: a,
|
|
305
|
+
resolvedFeaturesStore: o
|
|
306
|
+
}) => Object.values(a).map((s) => {
|
|
307
|
+
const l = o.find((f) => f.id === s.id);
|
|
308
|
+
return l ? {
|
|
309
|
+
id: s.id,
|
|
310
|
+
name: s.feature.name,
|
|
311
|
+
key: s.feature.key,
|
|
312
|
+
getBucket: () => ({ id: s.id, bucket: l.bucket }),
|
|
313
|
+
isResolved: !0
|
|
314
|
+
} : {
|
|
315
|
+
id: s.id,
|
|
316
|
+
name: s.feature.name,
|
|
317
|
+
key: s.feature.key,
|
|
318
|
+
getBucket: async () => await c(s.feature),
|
|
319
|
+
isResolved: !1
|
|
320
|
+
};
|
|
321
|
+
})
|
|
322
|
+
);
|
|
323
|
+
x({
|
|
324
|
+
clock: c.doneData,
|
|
325
|
+
source: { resolvedFeatures: i },
|
|
326
|
+
filter: ({ resolvedFeatures: a }, { id: o }) => !a.some((s) => s.id === o),
|
|
327
|
+
fn: (a, o) => o,
|
|
328
|
+
target: t.eventBus.prepend((a) => ({
|
|
329
|
+
type: "feature_decide",
|
|
330
|
+
feature: a
|
|
331
|
+
}))
|
|
332
|
+
}), x({
|
|
333
|
+
clock: [d.doneData, c.doneData],
|
|
334
|
+
source: i,
|
|
335
|
+
fn: (a, o) => !o || a.some((s) => s.id === o.id) ? a : [...a, o],
|
|
336
|
+
target: i
|
|
337
|
+
});
|
|
338
|
+
function S(a) {
|
|
339
|
+
return e.map((o) => o[a], { skipVoid: !1 });
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
register: p,
|
|
343
|
+
getByName: S,
|
|
344
|
+
listStore: m
|
|
345
|
+
};
|
|
346
|
+
});
|
|
347
|
+
function _e(t) {
|
|
348
|
+
return k(ge, t);
|
|
349
|
+
}
|
|
350
|
+
const Ue = (t, e, i) => {
|
|
351
|
+
i.register(t, e);
|
|
352
|
+
}, I = h("history");
|
|
353
|
+
function V(t, e) {
|
|
354
|
+
return {
|
|
355
|
+
// eslint-disable-next-line sonarjs/pseudo-random
|
|
356
|
+
id: G(`history-entry-${Date.now()}-${Math.random()}}`),
|
|
357
|
+
node: e,
|
|
358
|
+
at: Date.now(),
|
|
359
|
+
experienceId: t
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
const de = v(() => {
|
|
363
|
+
const t = I.store({ entries: [] }), e = I.event(), i = I.event(), g = I.event(), p = I.event();
|
|
364
|
+
t.on(e, (r, n) => ({
|
|
365
|
+
entries: [...r.entries, V(n.experienceId, n.node)]
|
|
366
|
+
})), t.on(i, (r, n) => ({
|
|
367
|
+
entries: [
|
|
368
|
+
...r.entries.slice(0, -1),
|
|
369
|
+
V(n.experienceId, n.node)
|
|
370
|
+
]
|
|
371
|
+
})), t.on(p, (r, n) => n);
|
|
372
|
+
function d(r, n) {
|
|
373
|
+
const c = { lastStepIndex: -1, secondLastStepIndex: -1 };
|
|
374
|
+
for (let m = r.length - 1; m >= 0; m--) {
|
|
375
|
+
const S = r[m], a = S == null ? void 0 : S.node;
|
|
376
|
+
if (!(!a || !z(a)) && !(n && (S == null ? void 0 : S.experienceId) !== n))
|
|
377
|
+
if (c.lastStepIndex === -1)
|
|
378
|
+
c.lastStepIndex = m;
|
|
379
|
+
else {
|
|
380
|
+
c.secondLastStepIndex = m;
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return c;
|
|
385
|
+
}
|
|
386
|
+
return t.on(g, (r, n) => {
|
|
387
|
+
const { secondLastStepIndex: c } = d(r.entries, n.experienceId), m = c !== -1 ? r.entries.slice(0, c + 1) : r.entries;
|
|
388
|
+
return {
|
|
389
|
+
...r,
|
|
390
|
+
entries: m
|
|
391
|
+
};
|
|
392
|
+
}), {
|
|
393
|
+
push: e,
|
|
394
|
+
replace: i,
|
|
395
|
+
back: g,
|
|
396
|
+
restore: p,
|
|
397
|
+
entriesStore: t.map((r) => r.entries)
|
|
398
|
+
};
|
|
399
|
+
});
|
|
400
|
+
function He() {
|
|
401
|
+
return k(de);
|
|
402
|
+
}
|
|
403
|
+
const pe = h("field"), fe = v(() => {
|
|
404
|
+
const t = pe.store({}), e = b(t, {
|
|
405
|
+
register(r, n) {
|
|
406
|
+
return {
|
|
407
|
+
...r,
|
|
408
|
+
[n.field.id]: n.field
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
function i(r) {
|
|
413
|
+
e.register({ field: r });
|
|
414
|
+
}
|
|
415
|
+
const g = t.map((r) => Object.values(r));
|
|
416
|
+
function p(r) {
|
|
417
|
+
return t.map((n) => n[r] || null);
|
|
418
|
+
}
|
|
419
|
+
function d(r) {
|
|
420
|
+
return t.map((n) => Object.values(n).find((c) => c.name === r) || null);
|
|
421
|
+
}
|
|
422
|
+
return {
|
|
423
|
+
register: i,
|
|
424
|
+
getById: p,
|
|
425
|
+
listStore: g,
|
|
426
|
+
getByName: d
|
|
427
|
+
};
|
|
428
|
+
});
|
|
429
|
+
function qe() {
|
|
430
|
+
return k(fe);
|
|
431
|
+
}
|
|
432
|
+
const ze = (t, e) => {
|
|
433
|
+
e.register(t);
|
|
434
|
+
}, me = h("action"), ye = v(() => {
|
|
435
|
+
const t = me.store({}), e = b(t, {
|
|
436
|
+
register(d, r) {
|
|
437
|
+
return {
|
|
438
|
+
...d,
|
|
439
|
+
[r.name]: {
|
|
440
|
+
name: r.name,
|
|
441
|
+
action: r.action
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
function i(d, r) {
|
|
447
|
+
e.register({ name: d, action: r });
|
|
448
|
+
}
|
|
449
|
+
const g = t.map((d) => Object.values(d));
|
|
450
|
+
function p(d) {
|
|
451
|
+
return t.map((r) => r[d], { skipVoid: !1 });
|
|
452
|
+
}
|
|
453
|
+
return {
|
|
454
|
+
register: i,
|
|
455
|
+
getByName: p,
|
|
456
|
+
listStore: g
|
|
457
|
+
};
|
|
458
|
+
});
|
|
459
|
+
function Ge() {
|
|
460
|
+
return k(ye);
|
|
461
|
+
}
|
|
462
|
+
const Ke = (t, e, i) => {
|
|
463
|
+
i.register(t, e);
|
|
464
|
+
}, Se = h("response"), ve = v(({ client: t }) => {
|
|
465
|
+
const e = Se.store({}), i = O(), g = O(), p = b(e, {
|
|
466
|
+
register(o, s) {
|
|
467
|
+
return {
|
|
468
|
+
...o,
|
|
469
|
+
[s.fieldId]: s.response
|
|
470
|
+
};
|
|
471
|
+
},
|
|
472
|
+
registerBatch(o, s) {
|
|
473
|
+
return {
|
|
474
|
+
...o,
|
|
475
|
+
...s
|
|
476
|
+
};
|
|
477
|
+
},
|
|
478
|
+
clear(o, s) {
|
|
479
|
+
const { [s]: l, ...f } = o;
|
|
480
|
+
return f;
|
|
481
|
+
},
|
|
482
|
+
clearAll() {
|
|
483
|
+
return {};
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
function d(o, s) {
|
|
487
|
+
p.register({ fieldId: o, response: s });
|
|
488
|
+
}
|
|
489
|
+
async function r(o) {
|
|
490
|
+
const s = [];
|
|
491
|
+
return await Promise.allSettled(
|
|
492
|
+
Object.entries(o).map(async ([l, f]) => {
|
|
493
|
+
let u = f;
|
|
494
|
+
const y = t.fields.getById(l).getState();
|
|
495
|
+
if (!y) {
|
|
496
|
+
s.push({
|
|
497
|
+
fieldId: l,
|
|
498
|
+
userMessage: `Field '${l}' not found`,
|
|
499
|
+
systemMessage: `No field with ID '${l}' exists. Available field IDs are: ${Object.keys(t.fields.listStore.getState()).join(",")}.`,
|
|
500
|
+
value: u
|
|
501
|
+
});
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
if (y.multiple && (typeof u == "string" || typeof u == "number" || typeof u == "boolean") && (u = [u]), y.validation && !K(y.validation)) {
|
|
505
|
+
const w = await C(t, y.validation, {
|
|
506
|
+
$input: u
|
|
507
|
+
});
|
|
508
|
+
if (typeof w == "string") {
|
|
509
|
+
s.push({
|
|
510
|
+
fieldId: l,
|
|
511
|
+
userMessage: w,
|
|
512
|
+
systemMessage: `Field validation resulted in an error: ${w}.`,
|
|
513
|
+
value: u
|
|
514
|
+
});
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
if (w === !1) {
|
|
518
|
+
s.push({
|
|
519
|
+
fieldId: l,
|
|
520
|
+
userMessage: "This field is invalid",
|
|
521
|
+
systemMessage: "Field validation resulted in an unspecified error.",
|
|
522
|
+
value: u
|
|
523
|
+
});
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
if (y.required && (typeof u > "u" || u === null || u === "" || Array.isArray(u) && !u.length)) {
|
|
528
|
+
s.push({
|
|
529
|
+
fieldId: l,
|
|
530
|
+
userMessage: "This field is required",
|
|
531
|
+
systemMessage: "Field is required.",
|
|
532
|
+
value: u
|
|
533
|
+
});
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
if (!y.multiple && Array.isArray(u) && u.length > 1) {
|
|
537
|
+
s.push({
|
|
538
|
+
fieldId: l,
|
|
539
|
+
userMessage: "This field expects a single response",
|
|
540
|
+
systemMessage: "Field expects a single response.",
|
|
541
|
+
value: u
|
|
542
|
+
});
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
if (y.options) {
|
|
546
|
+
const w = y.options.map((F) => F.value), $ = Array.isArray(u) ? u : [u];
|
|
547
|
+
Array.isArray(u) && ($.every((F) => w.includes(F)) || s.push({
|
|
548
|
+
fieldId: l,
|
|
549
|
+
userMessage: "This field expects a valid option",
|
|
550
|
+
systemMessage: `Field expects a valid option. Valid options are: ${w.join(", ")}`,
|
|
551
|
+
value: u
|
|
552
|
+
}));
|
|
553
|
+
}
|
|
554
|
+
})
|
|
555
|
+
), { responsesToCommit: o, validationErrors: s };
|
|
556
|
+
}
|
|
557
|
+
async function n(o) {
|
|
558
|
+
const { responsesToCommit: s, validationErrors: l } = await r(o);
|
|
559
|
+
return l.length ? { errors: l } : (p.registerBatch(s), { errors: [] });
|
|
560
|
+
}
|
|
561
|
+
const c = e.map((o) => o), m = e.map((o) => Object.keys(o).map((l) => ({
|
|
562
|
+
fieldId: l,
|
|
563
|
+
value: o[l]
|
|
564
|
+
})));
|
|
565
|
+
function S(o) {
|
|
566
|
+
const s = t.fields.getById(o), l = e.map((f) => f[o] || null);
|
|
567
|
+
return B({ f: s, r: l }, ({ f, r: u }) => u || (f != null && f.defaultValue ? f.defaultValue : null));
|
|
568
|
+
}
|
|
569
|
+
function a(o) {
|
|
570
|
+
const s = t.fields.getByName(o);
|
|
571
|
+
return B({ f: s, s: e }, ({ f: l, s: f }) => {
|
|
572
|
+
const u = l && f[l.id] || null;
|
|
573
|
+
return u || (l != null && l.defaultValue ? l.defaultValue : null);
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
return x({
|
|
577
|
+
clock: i,
|
|
578
|
+
target: p.clearAll
|
|
579
|
+
}), x({
|
|
580
|
+
clock: g,
|
|
581
|
+
target: p.clear
|
|
582
|
+
}), {
|
|
583
|
+
register: d,
|
|
584
|
+
clearAll: i,
|
|
585
|
+
clear: g,
|
|
586
|
+
commit: n,
|
|
587
|
+
getResponsesToCommit: r,
|
|
588
|
+
listStore: m,
|
|
589
|
+
getAllStore: c,
|
|
590
|
+
getByFieldId: S,
|
|
591
|
+
getByFieldName: a
|
|
592
|
+
};
|
|
593
|
+
});
|
|
594
|
+
function Ye(t) {
|
|
595
|
+
return k(ve, t);
|
|
596
|
+
}
|
|
597
|
+
function ke() {
|
|
598
|
+
if (J())
|
|
599
|
+
return crypto.randomUUID();
|
|
600
|
+
const t = Date.now().toString(36), e = Math.random().toString(36).substring(2, 15), i = Math.random().toString(36).substring(2, 15), g = Math.random().toString(36).substring(2, 15);
|
|
601
|
+
return `${t}-${e}-${i}-${g}`;
|
|
602
|
+
}
|
|
603
|
+
const we = () => ({
|
|
604
|
+
id: ke()
|
|
605
|
+
}), he = D("session", "global"), be = () => {
|
|
606
|
+
if (!Y()) return null;
|
|
607
|
+
const t = A.get(he);
|
|
608
|
+
let e = t.isSet() ? t.json() : null;
|
|
609
|
+
return e || (e = we(), t.set(e)), e;
|
|
610
|
+
}, Je = () => be();
|
|
611
|
+
export {
|
|
612
|
+
Me as a,
|
|
613
|
+
Ae as b,
|
|
614
|
+
He as c,
|
|
615
|
+
Te as d,
|
|
616
|
+
Ce as e,
|
|
617
|
+
_e as f,
|
|
618
|
+
Ye as g,
|
|
619
|
+
qe as h,
|
|
620
|
+
Ge as i,
|
|
621
|
+
Je as j,
|
|
622
|
+
Pe as k,
|
|
623
|
+
Ue as l,
|
|
624
|
+
Le as m,
|
|
625
|
+
ze as n,
|
|
626
|
+
Ke as o,
|
|
627
|
+
Ne as p,
|
|
628
|
+
je as q,
|
|
629
|
+
Z as r,
|
|
630
|
+
Ve as s,
|
|
631
|
+
Oe as t
|
|
632
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@picked/client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14-next.1",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@withease/factories": "^1.0.5"
|
|
6
6
|
},
|
|
@@ -9,16 +9,16 @@
|
|
|
9
9
|
"@repo/typescript-config": "workspace:*",
|
|
10
10
|
"@rollup/plugin-replace": "^6.0.2",
|
|
11
11
|
"@testing-library/dom": "^10.4.0",
|
|
12
|
-
"@vitest/browser": "^3.2.
|
|
13
|
-
"@vitest/coverage-istanbul": "^3.2.
|
|
12
|
+
"@vitest/browser": "^3.2.4",
|
|
13
|
+
"@vitest/coverage-istanbul": "^3.2.4",
|
|
14
14
|
"effector": "^23.3.0",
|
|
15
|
-
"happy-dom": "^
|
|
15
|
+
"happy-dom": "^20.0.2",
|
|
16
16
|
"tslib": "^2.8.1",
|
|
17
17
|
"typedoc": "^0.28.5",
|
|
18
18
|
"typedoc-plugin-markdown": "^4.6.3",
|
|
19
|
-
"vite": "^6.
|
|
19
|
+
"vite": "^6.4.1",
|
|
20
20
|
"vite-plugin-dts": "^4.5.4",
|
|
21
|
-
"vitest": "^3.2.
|
|
21
|
+
"vitest": "^3.2.4"
|
|
22
22
|
},
|
|
23
23
|
"exports": {
|
|
24
24
|
".": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const a=require("effector"),D=require("@withease/factories"),F=require("./supports-YvpQZxbh.cjs"),M=require("./logger-BsmHUUw1.cjs"),ce=require("./object-BbFTsGh3.cjs");function ae(e){return typeof e=="number"&&!isNaN(e)}function T(e){return typeof e=="string"}function w(e){return Array.isArray(e)}function z(e){return e instanceof Promise}function V(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===1}function g(e){if(ae(e))return e;const t=parseFloat(`${e}`);return isNaN(t)?0:t}function A(e){return`${e}`}const ue={"==":(e,t)=>e==t,"===":(e,t)=>e===t,"!=":(e,t)=>e!=t,"!==":(e,t)=>e!==t,">":(e,t)=>g(e)>g(t),">=":(e,t)=>g(e)>=g(t),"<":(e,t,r)=>{const n=g(e),i=g(t);if(r===void 0)return n<i;const c=g(r);return n<i&&i<c},"<=":(e,t,r)=>{const n=g(e),i=g(t);if(r===void 0)return n<=i;const c=g(r);return n<=i&&i<=c},"!!":async e=>await I(e),"!":async e=>!await I(e),"%":(e,t)=>g(e)%g(t),log:e=>(console.log(e),e),in:(e,t)=>t?T(t)?t.indexOf(A(e))!==-1:w(t)?t.includes(e):!1:!1,cat:(...e)=>e.map(A).join(""),substr:(e,t,r)=>{const n=A(e),i=g(t);if(r===void 0)return n.substr(i);const c=g(r);if(c<0){const o=n.substr(i);return o.substr(0,o.length+c)}return n.substr(i,c)},"+":(...e)=>e.reduce((t,r)=>g(t)+g(r),0),"*":(...e)=>e.reduce((t,r)=>g(t)*g(r),1),"-":(e,t)=>{const r=g(e);return t===void 0?-r:r-g(t)},"/":(e,t)=>g(e)/g(t),min:(...e)=>Math.min(...e.map(g)),max:(...e)=>Math.max(...e.map(g)),merge:(...e)=>e.reduce((t,r)=>w(r)?t.concat(r):t.concat([r]),[]),var(e,t){const r=arguments.length>1?t:null;if(e===""||e==="."||e===null||e===void 0)return this;if(typeof e=="number"&&Array.isArray(this))return e>=0&&e<this.length?this[e]:r;const n=A(e);if(n===""||n===".")return this;const i=n.split(".");let c=this;for(const o of i){if(c==null)return r;if(Array.isArray(c)){const u=parseInt(o,10);isNaN(u)?c=c[o]:c=c[u]}else c=c[o]}return c!==void 0?c:r},async missing(...e){const t=w(e[0])?e[0]:e,r=[];for(const n of t){const i=await d({var:n},this);(i===null||i==="")&&r.push(`${n}`)}return r},async missing_some(e,t){const r=await d({missing:t},this);if(!w(r)||!w(t))return[];const n=r.filter(T);return t.filter(T).length-n.length>=g(e)?[]:n},invoke(e){return typeof e!="function"?null:e()},regexp_matches(e,t){let r=e,n="";if(w(e)){const[c,o]=e;r=c,n=o}return!T(r)||!T(n)?!1:new RegExp(r,n).test(A(t))},throw(e){throw new Error(A(e))}};async function d(e,t){if(!e)return e;if(z(e))return d(await e,t);if(w(e))return Promise.all(e.map(o=>d(o,t)));if(!V(e))return e;const r=fe(e);let n=r?e[r]??[]:[];switch(w(n)||(n=[n]),r){case"if":case"?:":for(let o=0;o<n.length-1;o+=2)if(await I(await d(n[o],t)))return d(n[o+1],t);return n.length%2===1?d(n[n.length-1],t):null;case"and":{let o=null;for(const u of n)if(o=await d(u,t),!await I(o))return o;return o}case"or":{let o=null;for(const u of n)if(o=await d(u,t),await I(o))return o;return o}case"map":{const o=await d(n[0],t);return w(o)?await Promise.all(o.map(u=>d(n[1],u))):[]}case"filter":{const o=await d(n[0],t);return w(o)?(await Promise.all(o.map(async f=>{const S=await I(await d(n[1],f));return{item:f,shouldInclude:S}}))).filter(({shouldInclude:f})=>f).map(({item:f})=>f):[]}case"reduce":{const o=await d(n[0],t);if(!w(o))return n.length>2?await d(n[2],t):null;const u=n[1];let S=n.length>2?await d(n[2],t):null;for(const x of o)S=await d(u,{current:x,accumulator:S});return S}case"all":{const o=await d(n[0],t);if(!w(o)||o.length===0)return!1;for(const u of o)if(!await I(await d(n[1],u)))return!1;return!0}case"some":{const o=await d(n[0],t);if(!w(o))return!1;for(const u of o)if(await I(await d(n[1],u)))return!0;return!1}case"none":{const o=await d(n[0],t);if(!w(o))return!0;for(const u of o)if(await I(await d(n[1],u)))return!1;return!0}case"catch":try{return await d(n[0],t)}catch(o){return V(o)?await d(o,t):n[1]?await d(n[1],o):o instanceof Error?o.message:o}}const i=await Promise.all(n.map(o=>d(o,t))),c=r?ue[r]:void 0;if(!c)throw new Error(`Unrecognized operation ${r}`);return c.apply(t,i)}async function I(e){return z(e)?I(await e):!(Array.isArray(e)&&e.length===0)&&!!e}function fe(e){return Object.keys(e)[0]}function le(e){return!ce.isEmpty(e)}async function X(e,t,r){const n=e.getStateSnapshot(),i=e.predicates.listStore.getState().reduce((u,f)=>({...u,[f.name]:()=>f.predicate(n)}),{}),c=e.features.listStore.getState().reduce((u,f)=>({...u,[f.id]:async()=>{const{bucket:S}=await f.getBucket();return S}}),{}),o={...r,responses:e.responses.getAllStore.getState(),location:typeof n.location=="object"?{hash:n.location.hash,host:n.location.host,hostname:n.location.hostname,href:n.location.href,origin:n.location.origin,pathname:n.location.pathname,port:n.location.port,protocol:n.location.protocol,search:n.location.search}:void 0,predicates:i,features:c};return await d(t,o)}function pe(e){return!F.supportsWindow()||!F.supportsDocument()?[]:Array.from(window.document.querySelectorAll(e)).filter(t=>t instanceof HTMLElement)}function de(e){if(!F.supportsShadowRoot())throw new Error("Shadow DOM is not supported in this environment");return e.attachShadow({mode:"closed"})}function ge(){return new Promise((e,t)=>{if(!F.supportsDocument()){t();return}document.readyState!=="loading"?e():document.addEventListener("readystatechange",()=>e(),{once:!0})})}function me(e,t){const r=new MutationObserver(n=>{document.contains(e)||(r.disconnect(),t())});r.observe(document.body,{childList:!0,subtree:!0})}const O="picked-root",R="picked-target",he="picked-root";function Se(e,t){return[...e,{selector:`${he}[experience-id="${t}"]`,placement:"replace"}].flatMap(n=>{const i=pe(n.selector).filter(c=>!Ee(c,t)&&!J(c,t));return{...n,elements:i}})}function ye(e,t){return e.flatMap(r=>r.elements.map(n=>Ie(n,r.placement,t)))}function we(e,t){e.classList.add(R),e.classList.add(`${R}-${t}`)}function Ee(e,t){return t?e.classList.contains(`${R}-${t}`):e.classList.contains(`${R}`)}function J(e,t){return t?e.classList.contains(`${O}-${t}`):e.classList.contains(O)}function xe(e){const t=document.createElement("div");return t.style.display="block",t.classList.add(O),t.classList.add(`${O}-${e}`),t}function Ie(e,t,r){let n;const i=xe(r);if(e instanceof Document)n=e.body.appendChild(i);else{switch(t){case"replace":e.replaceWith(i);break;case"before":e.before(i);break;case"after":e.after(i);break;case"prepend":e.prepend(i);break;default:e.append(i);break}n=i}return n}function ke(e){return e.type==="conditional"}function _(e){return e.type==="step"}function Ne(e){return e.type==="experience"}function W(e){return e.type==="origin"}const Q=(e,t,r,n,i=new Set)=>i.has(r.id)?[]:(i.add(r.id),_(r)&&!n?[r]:t.filter(o=>o.sourceNodeId===r.id).flatMap(o=>{const u=e.find(f=>f.id===o.destinationNodeId);return u?Q(e,t,u,!1,i):[]})),be=(e,t,r)=>Q(e,t,r,!0,new Set),Y=(e,t,r,n,i=new Set)=>{if(i.has(r.id))return[-1,-1];i.add(r.id);const c=t.filter(f=>f.sourceNodeId===r.id);if(c.length===0)return[0,0];let o=1/0,u=-1/0;for(const f of c){const S=e.find(k=>k.id===f.destinationNodeId);if(!S)continue;const[x,y]=Y(e,t,S,!1,new Set(i));x!==-1&&(o=Math.min(o,x+1),u=Math.max(u,y+1))}return o===1/0?[-1,-1]:[o,u]},ve=(e,t,r)=>Y(e,t,r,!0,new Set),Z=(e,t,r,n=new Set)=>{if(n.has(r.id))return[-1,-1];if(n.add(r.id),r.type==="origin")return[0,0];const i=t.filter(u=>u.destinationNodeId===r.id);if(i.length===0)return[-1,-1];let c=1/0,o=-1/0;for(const u of i){const f=e.find(y=>y.id===u.sourceNodeId);if(!f)continue;const[S,x]=Z(e,t,f,new Set(n));S!==-1&&(c=Math.min(c,S+1),o=Math.max(o,x+1))}return c===1/0?[-1,-1]:[c,o]},Ae=(e,t,r)=>Z(e,t,r,new Set),ee=e=>e.find(r=>r.type==="origin")||null,j=(e,t,r)=>{if(!e)return ee(t);const n=r.find(c=>c.sourceNodeId===e.id);if(!n)return null;const i=t.find(c=>c.id===n.destinationNodeId);return i||null};async function _e(e,t,r,n){const i=e?"true":"false",c=n.find(o=>o.sourceNodeHandle===i&&o.sourceNodeId===t);return r.find(o=>o.id===(c==null?void 0:c.destinationNodeId))}const q=a.createDomain("experience-instance"),Be=D.createFactory(({client:e,experience:t,target:r})=>{const n=a.createEvent(),i=a.createEvent(),c=a.createEvent(),o=a.createEvent(),u=t.componentStore,f=q.store("transitioning"),S=e.history.entriesStore.map(s=>s.filter(p=>p.experienceId===t.id)),x=S.map(s=>s.filter(p=>_(p.node))),y=S.map(s=>{var p;return((p=s[s.length-1])==null?void 0:p.node)||null}),k=a.combine(t.treeStore,y,({steps:s},p)=>s.find(m=>p&&_(p)&&m.id===p.stepId)||null),P=a.combine(t.treeStore,y,({nodes:s,edges:p},m)=>m?be(s,p,m):[]),l=a.combine(t.treeStore,y,({nodes:s,edges:p},m)=>m?Ae(s,p,m):[-1,-1]),h=a.combine(t.treeStore,y,({nodes:s,edges:p},m)=>m?ve(s,p,m):[-1,-1]),E=q.store(!0),N=a.createApi(E,{open:()=>!0,close:()=>!1,toggle:s=>!s,set:(s,p)=>p});a.sample({source:E,filter:Boolean,target:e.eventBus.prepend(()=>({type:"experience_open",experience:t}))}),a.sample({source:E,filter:s=>!s,target:e.eventBus.prepend(()=>({type:"experience_close",experience:t}))});const b=a.createEffect(async()=>{e.history.back({experienceId:t.id})}),B=a.attach({source:t.treeStore,effect:async(s,p)=>{const m=s.nodes.find(v=>_(v)&&v.stepId===p);m&&e.history.push({experienceId:t.id,node:m})}}),G=a.attach({source:y,effect:s=>{}}),$=a.attach({source:t.treeStore,effect:async({nodes:s})=>ee(s)}),C=a.attach({source:t.treeStore,effect:async({nodes:s,edges:p},m)=>j(m,s,p)}),H=a.attach({source:t.treeStore,effect:async({nodes:s,edges:p,conditionals:m},v)=>{if(!v)return;const U=m.find(ie=>ie.id===v.conditionalId);if(!U)return;const oe=v.id,se=await X(e,U.condition);return _e(!!se,oe,s,p)}}),ne=a.createEffect(s=>{if(s)return e.launchExperienceById(s.experienceId)}),K=a.attach({source:[y,t.treeStore],effect:async([s,{nodes:p,edges:m}])=>j(s,p,m)}),L=a.attach({source:[y,t.treeStore],effect:async([s,{nodes:p,edges:m}])=>j(s,p,m)}),re=a.createEffect(s=>{e.history.push({experienceId:t.id,node:s})});return a.split({source:y,match:s=>s?ke(s)?"condition":_(s)?"step":Ne(s)?"launchExperience":W(s)?"origin":"other":"none",cases:{none:$,origin:C,condition:H,step:G,launchExperience:ne,__:a.createEvent()}}),a.sample({clock:[H.doneData,C.doneData,$.doneData,L.doneData,K.doneData],filter:Boolean,target:re}),a.sample({clock:i,target:L}),a.sample({clock:i,source:k,filter:Boolean,target:e.eventBus.prepend(s=>({type:"step_submit",step:s,experience:t}))}),a.sample({clock:L.done,source:k,filter:Boolean,target:e.eventBus.prepend(s=>({type:"step_submit_success",step:s,experience:t}))}),a.sample({clock:L.fail,source:k,filter:Boolean,target:e.eventBus.prepend(s=>({type:"step_submit_error",step:s,experience:t}))}),a.sample({clock:c,target:b}),a.sample({clock:o,target:B}),a.sample({source:a.combine([H.pending,C.pending,$.pending,L.pending]),fn:s=>s.some(Boolean)?"transitioning":"ready",target:f}),a.sample({clock:G.doneData,source:k,filter:Boolean,target:e.eventBus.prepend(s=>({type:"step_enter",step:s,experience:t}))}),a.sample({source:y,clock:n,filter:s=>s?W(s):!0,target:K}),n(),{id:Math.random().toString(36).substring(7),experienceId:t.id,configStore:t.configStore,target:r,componentStore:u,stateStore:f,isOpenStore:E,open:N.open,close:N.close,toggleOpen:N.toggle,setOpen:N.set,treeStore:t.treeStore,currentNodeStore:y,currentStepStore:k,nextReachableStepNodesStore:P,stepsToOriginStore:l,stepsToLeafStore:h,goToNextStep:i,goToPreviousStep:c,goToStepById:o,stepsHistoryStore:x}});function te(e){return D.invoke(Be,e)}const Le=D.createFactory(({client:e})=>{const t=q.store({}),r=a.createEvent(),n=a.createEvent(),i=a.createEvent(),c=a.createApi(t,{register(l,h){const E=[...l[h.experienceId]??[]];return E.push(h),{...l,[h.experienceId]:E}},unregister(l,h){var b;const E=h.experienceId,N=(b=l[E])==null?void 0:b.filter(B=>B!==h);return{...l,[E]:N??[]}}}),o=a.createEffect(({experience:l,target:h})=>te({client:e,experience:l,target:h})),u=a.createEffect(l=>{c.register(l)}),f=a.createEffect(l=>{l.target&&me(l.target,()=>{i(l)})}),S=a.createEffect(l=>{c.unregister(l)}),x=a.createEffect(l=>{const h=l.componentStore.getState();if(!h){M.logger("warn","No app component registered. Skipping init.");return}const E=h.frameworkStore.getState();if(!E){M.logger("error",`No framework registered for component '${h.name}'. Skipping rendering.`);return}const N=l.target;if(!N){M.logger("error",`No target element registered for experience '${l.experienceId}'. Skipping rendering.`);return}const b=de(N);try{E.render(b,h.component,e,l)}catch(B){M.logger("error",B)}});a.sample({clock:r,target:o}),a.sample({clock:i,target:S}),a.sample({clock:o.doneData,target:[u,f,n]}),a.sample({clock:o.doneData,target:e.eventBus.prepend(l=>({type:"experience_initialized",experienceInstance:l}))}),a.sample({clock:n,target:x});function y(l,h){r({experience:l,target:h})}const k=t.map(l=>Object.values(l).flat());function P(l){return t.map(h=>h[l]||[],{skipVoid:!1})}return{spawn:y,getByExperienceId:P,listStore:k}});function Te(e){return D.invoke(Le,e)}exports.createAppHosts=ye;exports.createExperienceInstance=te;exports.createExperienceInstanceIndex=Te;exports.domInteractive=ge;exports.evaluateRuleLogic=X;exports.getTargetElements=Se;exports.isPickedRoot=J;exports.isRulesLogic=le;exports.isStepNode=_;exports.tagTargetElement=we;
|