@picked/client 0.0.12-next.9 → 0.0.12
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/server/index.js +1 -1
- package/dist/esm/index.js +481 -535
- package/dist/esm/plugins/create-experience/index.js +178 -229
- package/dist/esm/server/index.js +1 -1
- package/dist/experience-instance-DXWLnF-R.cjs +1 -0
- package/dist/experience-instance-XlIuqLrL.js +716 -0
- package/dist/types/client.d.ts +0 -26
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/entities/experience/experience.d.ts +6 -19
- 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 +2 -5
- package/dist/types/entities/feature/feature.d.ts.map +1 -1
- package/dist/types/picked.d.ts +4 -14
- package/dist/types/picked.d.ts.map +1 -1
- package/dist/types/plugins/create-experience/create-experience.d.ts +5 -23
- package/dist/types/plugins/create-experience/create-experience.d.ts.map +1 -1
- package/dist/types/utils/events.d.ts +4 -10
- package/dist/types/utils/events.d.ts.map +1 -1
- package/dist/types/utils/nodes.d.ts +1 -2
- package/dist/types/utils/nodes.d.ts.map +1 -1
- package/package.json +6 -6
- package/dist/experience-instance-Bs9t-zff.js +0 -777
- package/dist/experience-instance-COUhADSj.cjs +0 -1
- package/dist/types/entities/action/action.d.ts +0 -15
- package/dist/types/entities/action/action.d.ts.map +0 -1
|
@@ -1,74 +1,36 @@
|
|
|
1
|
-
import { g as
|
|
2
|
-
const
|
|
3
|
-
serialize(
|
|
4
|
-
return JSON.stringify(
|
|
1
|
+
import { g as f } from "../../../id-BW-g3y32.js";
|
|
2
|
+
const r = {
|
|
3
|
+
serialize(e) {
|
|
4
|
+
return JSON.stringify(e);
|
|
5
5
|
},
|
|
6
|
-
deserialize(
|
|
7
|
-
return JSON.parse(
|
|
6
|
+
deserialize(e) {
|
|
7
|
+
return JSON.parse(e);
|
|
8
8
|
}
|
|
9
|
-
},
|
|
9
|
+
}, b = (e) => ({
|
|
10
10
|
name: "create-experience",
|
|
11
|
-
setup: (
|
|
12
|
-
|
|
13
|
-
const s =
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
setup: (a) => {
|
|
12
|
+
e.experiences.forEach((o) => {
|
|
13
|
+
const s = o.serialize(), d = r.deserialize(s);
|
|
14
|
+
d.component = o.component, a.registerExperience(d), d.fields.forEach((h) => {
|
|
15
|
+
a.registerField(h);
|
|
16
16
|
});
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
}),
|
|
20
|
-
id:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const o = c(
|
|
28
|
-
{ sourceNode: this, destinationNode: s.node, sourceNodeHandle: null },
|
|
29
|
-
d
|
|
30
|
-
);
|
|
31
|
-
d.edges.push(o);
|
|
32
|
-
},
|
|
33
|
-
onSuccess(s) {
|
|
34
|
-
if (!s.node) throw new Error("Cannot connect to node");
|
|
35
|
-
const o = c(
|
|
36
|
-
{ sourceNode: this, destinationNode: s.node, sourceNodeHandle: "true" },
|
|
37
|
-
d
|
|
38
|
-
);
|
|
39
|
-
d.edges.push(o);
|
|
40
|
-
},
|
|
41
|
-
onFail(s) {
|
|
42
|
-
if (!s.node) throw new Error("Cannot connect to node");
|
|
43
|
-
const o = c(
|
|
44
|
-
{ sourceNode: this, destinationNode: s.node, sourceNodeHandle: "false" },
|
|
45
|
-
d
|
|
46
|
-
);
|
|
47
|
-
d.edges.push(o);
|
|
48
|
-
},
|
|
49
|
-
serialize() {
|
|
50
|
-
return a.serialize({
|
|
51
|
-
id: this.id,
|
|
52
|
-
type: this.type,
|
|
53
|
-
action: this.action,
|
|
54
|
-
position: this.position
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}), v = (i) => ({
|
|
58
|
-
id: i.id ?? p("step"),
|
|
59
|
-
label: i.label,
|
|
60
|
-
fields: i.fields ?? [],
|
|
61
|
-
addField(d) {
|
|
62
|
-
var s, o;
|
|
63
|
-
const l = "serialize" in d ? d : N(d);
|
|
64
|
-
return (s = this.fields) != null && s.includes(l) || (o = this.fields) == null || o.push(l), l;
|
|
19
|
+
}), x = (e) => ({
|
|
20
|
+
id: e.id ?? f("step"),
|
|
21
|
+
label: e.label,
|
|
22
|
+
fields: e.fields ?? [],
|
|
23
|
+
addField(a) {
|
|
24
|
+
var s, d;
|
|
25
|
+
const o = "serialize" in a ? a : m(a);
|
|
26
|
+
return (s = this.fields) != null && s.includes(o) || (d = this.fields) == null || d.push(o), o;
|
|
65
27
|
}
|
|
66
|
-
}),
|
|
67
|
-
const
|
|
68
|
-
id:
|
|
69
|
-
label:
|
|
70
|
-
experience:
|
|
71
|
-
fields:
|
|
28
|
+
}), y = (e, a) => {
|
|
29
|
+
const o = {
|
|
30
|
+
id: e.id ?? f("step"),
|
|
31
|
+
label: e.label,
|
|
32
|
+
experience: a,
|
|
33
|
+
fields: e.fields ?? [],
|
|
72
34
|
node: null,
|
|
73
35
|
nextStep(s) {
|
|
74
36
|
return this.experience.addStep(s, this);
|
|
@@ -83,27 +45,27 @@ const a = {
|
|
|
83
45
|
return this.experience.addField(s, this);
|
|
84
46
|
},
|
|
85
47
|
serialize() {
|
|
86
|
-
return
|
|
48
|
+
return r.serialize({
|
|
87
49
|
id: this.id,
|
|
88
50
|
label: this.label,
|
|
89
51
|
fieldIds: this.fields.map((s) => s.id)
|
|
90
52
|
});
|
|
91
53
|
}
|
|
92
54
|
};
|
|
93
|
-
return
|
|
94
|
-
},
|
|
95
|
-
const
|
|
96
|
-
id:
|
|
97
|
-
position:
|
|
98
|
-
experience:
|
|
55
|
+
return c({ step: o, type: "step" }, a), o;
|
|
56
|
+
}, z = () => [0, 0], c = (e, a) => {
|
|
57
|
+
const o = {
|
|
58
|
+
id: f("node"),
|
|
59
|
+
position: z(),
|
|
60
|
+
experience: a
|
|
99
61
|
};
|
|
100
|
-
if (
|
|
101
|
-
const
|
|
102
|
-
...
|
|
62
|
+
if (e.type === "step") {
|
|
63
|
+
const d = {
|
|
64
|
+
...o,
|
|
103
65
|
type: "step",
|
|
104
|
-
connectedStep:
|
|
66
|
+
connectedStep: e.step,
|
|
105
67
|
serialize() {
|
|
106
|
-
return
|
|
68
|
+
return r.serialize({
|
|
107
69
|
id: this.id,
|
|
108
70
|
type: this.type,
|
|
109
71
|
stepId: this.connectedStep.id,
|
|
@@ -112,15 +74,15 @@ const a = {
|
|
|
112
74
|
});
|
|
113
75
|
}
|
|
114
76
|
};
|
|
115
|
-
return
|
|
77
|
+
return d.connectedStep.node = d, d;
|
|
116
78
|
}
|
|
117
|
-
if (
|
|
118
|
-
const
|
|
119
|
-
...
|
|
79
|
+
if (e.type === "conditional") {
|
|
80
|
+
const d = {
|
|
81
|
+
...o,
|
|
120
82
|
type: "conditional",
|
|
121
|
-
connectedConditional:
|
|
83
|
+
connectedConditional: e.conditional,
|
|
122
84
|
serialize() {
|
|
123
|
-
return
|
|
85
|
+
return r.serialize({
|
|
124
86
|
id: this.id,
|
|
125
87
|
type: this.type,
|
|
126
88
|
conditionalId: this.connectedConditional.id,
|
|
@@ -128,14 +90,14 @@ const a = {
|
|
|
128
90
|
});
|
|
129
91
|
}
|
|
130
92
|
};
|
|
131
|
-
return
|
|
93
|
+
return d.connectedConditional.node = d, d;
|
|
132
94
|
}
|
|
133
|
-
return
|
|
134
|
-
...
|
|
95
|
+
return e.type === "experience" ? {
|
|
96
|
+
...o,
|
|
135
97
|
type: "experience",
|
|
136
|
-
connectedExperience:
|
|
98
|
+
connectedExperience: e.experience,
|
|
137
99
|
serialize() {
|
|
138
|
-
return
|
|
100
|
+
return r.serialize({
|
|
139
101
|
id: this.id,
|
|
140
102
|
type: this.type,
|
|
141
103
|
experienceId: this.connectedExperience.id,
|
|
@@ -143,81 +105,81 @@ const a = {
|
|
|
143
105
|
});
|
|
144
106
|
}
|
|
145
107
|
} : {
|
|
146
|
-
...
|
|
108
|
+
...o,
|
|
147
109
|
type: "origin",
|
|
148
110
|
serialize() {
|
|
149
|
-
return
|
|
111
|
+
return r.serialize({
|
|
150
112
|
id: this.id,
|
|
151
113
|
type: this.type,
|
|
152
114
|
position: this.position
|
|
153
115
|
});
|
|
154
116
|
}
|
|
155
117
|
};
|
|
156
|
-
},
|
|
157
|
-
id:
|
|
158
|
-
sourceNode:
|
|
159
|
-
sourceNodeHandle:
|
|
160
|
-
destinationNode:
|
|
161
|
-
experience:
|
|
118
|
+
}, p = (e, a) => ({
|
|
119
|
+
id: f("edge"),
|
|
120
|
+
sourceNode: e.sourceNode,
|
|
121
|
+
sourceNodeHandle: e.sourceNodeHandle,
|
|
122
|
+
destinationNode: e.destinationNode,
|
|
123
|
+
experience: a,
|
|
162
124
|
serialize() {
|
|
163
|
-
return
|
|
125
|
+
return r.serialize({
|
|
164
126
|
id: this.id,
|
|
165
127
|
sourceNodeHandle: this.sourceNodeHandle ?? void 0,
|
|
166
128
|
sourceNodeId: this.sourceNode.id,
|
|
167
129
|
destinationNodeId: this.destinationNode.id
|
|
168
130
|
});
|
|
169
131
|
}
|
|
170
|
-
}),
|
|
171
|
-
const
|
|
172
|
-
id:
|
|
173
|
-
condition:
|
|
132
|
+
}), N = (e, a) => {
|
|
133
|
+
const o = {
|
|
134
|
+
id: f("conditional"),
|
|
135
|
+
condition: e.condition,
|
|
174
136
|
node: null,
|
|
175
|
-
experience:
|
|
137
|
+
experience: a,
|
|
176
138
|
addTrue(s) {
|
|
177
139
|
if (!this.node || !s.node)
|
|
178
140
|
throw new Error("todo no node");
|
|
179
|
-
const
|
|
141
|
+
const d = p(
|
|
180
142
|
{ sourceNode: this.node, destinationNode: s.node, sourceNodeHandle: "true" },
|
|
181
143
|
this.experience
|
|
182
144
|
);
|
|
183
|
-
this.experience.edges.push(
|
|
145
|
+
this.experience.edges.push(d);
|
|
184
146
|
},
|
|
185
147
|
addFalse(s) {
|
|
186
148
|
if (!this.node || !s.node)
|
|
187
149
|
throw new Error("todo no node");
|
|
188
|
-
const
|
|
150
|
+
const d = p(
|
|
189
151
|
{ sourceNode: this.node, destinationNode: s.node, sourceNodeHandle: "false" },
|
|
190
152
|
this.experience
|
|
191
153
|
);
|
|
192
|
-
this.experience.edges.push(
|
|
154
|
+
this.experience.edges.push(d);
|
|
193
155
|
},
|
|
194
156
|
serialize() {
|
|
195
|
-
return
|
|
157
|
+
return r.serialize({
|
|
196
158
|
id: this.id,
|
|
197
159
|
condition: this.condition
|
|
198
160
|
});
|
|
199
161
|
}
|
|
200
162
|
};
|
|
201
|
-
return
|
|
202
|
-
},
|
|
203
|
-
var
|
|
163
|
+
return c({ conditional: o, type: "conditional" }, a), o;
|
|
164
|
+
}, m = (e) => {
|
|
165
|
+
var o;
|
|
204
166
|
return {
|
|
205
|
-
id:
|
|
206
|
-
name:
|
|
207
|
-
type:
|
|
208
|
-
label:
|
|
209
|
-
placeholder:
|
|
210
|
-
description:
|
|
211
|
-
helpText:
|
|
212
|
-
defaultValue:
|
|
213
|
-
multiple:
|
|
214
|
-
validation:
|
|
215
|
-
condition:
|
|
216
|
-
required:
|
|
217
|
-
options: ((
|
|
167
|
+
id: e.id,
|
|
168
|
+
name: e.name,
|
|
169
|
+
type: e.type,
|
|
170
|
+
label: e.label,
|
|
171
|
+
placeholder: e.placeholder,
|
|
172
|
+
description: e.description,
|
|
173
|
+
helpText: e.helpText,
|
|
174
|
+
defaultValue: e.defaultValue ?? null,
|
|
175
|
+
multiple: e.multiple,
|
|
176
|
+
validation: e.validation ?? {},
|
|
177
|
+
condition: e.condition,
|
|
178
|
+
required: e.required,
|
|
179
|
+
options: ((o = e.options) == null ? void 0 : o.map((s) => ({
|
|
218
180
|
...s
|
|
219
181
|
}))) ?? null,
|
|
220
|
-
policies:
|
|
182
|
+
policies: e.policies,
|
|
221
183
|
serialize() {
|
|
222
184
|
const s = {
|
|
223
185
|
id: this.id,
|
|
@@ -230,22 +192,22 @@ const a = {
|
|
|
230
192
|
validation: this.validation,
|
|
231
193
|
condition: this.condition,
|
|
232
194
|
policies: this.policies
|
|
233
|
-
},
|
|
195
|
+
}, d = typeof this.defaultValue == "string" ? this.defaultValue : void 0, h = typeof this.defaultValue == "number" ? this.defaultValue : void 0, n = typeof this.defaultValue == "boolean" ? this.defaultValue : void 0;
|
|
234
196
|
switch (this.type) {
|
|
235
197
|
case "text":
|
|
236
198
|
if (this.multiple) {
|
|
237
|
-
let
|
|
199
|
+
let i;
|
|
238
200
|
if (Array.isArray(this.defaultValue)) {
|
|
239
|
-
|
|
201
|
+
i = [];
|
|
240
202
|
for (const t of this.defaultValue)
|
|
241
|
-
typeof t == "string" &&
|
|
242
|
-
|
|
203
|
+
typeof t == "string" && i.push(t);
|
|
204
|
+
i.length === 0 && (i = void 0);
|
|
243
205
|
}
|
|
244
|
-
return
|
|
206
|
+
return r.serialize({
|
|
245
207
|
...s,
|
|
246
208
|
type: "text",
|
|
247
209
|
multiple: !0,
|
|
248
|
-
defaultValue:
|
|
210
|
+
defaultValue: i,
|
|
249
211
|
options: this.options ? this.options.map((t) => ({
|
|
250
212
|
id: t.id,
|
|
251
213
|
label: t.label,
|
|
@@ -254,32 +216,32 @@ const a = {
|
|
|
254
216
|
})) : null
|
|
255
217
|
});
|
|
256
218
|
}
|
|
257
|
-
return
|
|
219
|
+
return r.serialize({
|
|
258
220
|
...s,
|
|
259
221
|
type: "text",
|
|
260
222
|
multiple: !1,
|
|
261
|
-
defaultValue:
|
|
262
|
-
options: this.options ? this.options.map((
|
|
263
|
-
id:
|
|
264
|
-
label:
|
|
265
|
-
value: `${
|
|
266
|
-
condition:
|
|
223
|
+
defaultValue: d,
|
|
224
|
+
options: this.options ? this.options.map((i) => ({
|
|
225
|
+
id: i.id,
|
|
226
|
+
label: i.label,
|
|
227
|
+
value: `${i.value}`,
|
|
228
|
+
condition: i.condition
|
|
267
229
|
})) : null
|
|
268
230
|
});
|
|
269
231
|
case "number":
|
|
270
232
|
if (this.multiple) {
|
|
271
|
-
let
|
|
233
|
+
let i;
|
|
272
234
|
if (Array.isArray(this.defaultValue)) {
|
|
273
|
-
|
|
235
|
+
i = [];
|
|
274
236
|
for (const t of this.defaultValue)
|
|
275
|
-
typeof t == "number" &&
|
|
276
|
-
|
|
237
|
+
typeof t == "number" && i.push(t);
|
|
238
|
+
i.length === 0 && (i = void 0);
|
|
277
239
|
}
|
|
278
|
-
return
|
|
240
|
+
return r.serialize({
|
|
279
241
|
...s,
|
|
280
242
|
type: "number",
|
|
281
243
|
multiple: !0,
|
|
282
|
-
defaultValue:
|
|
244
|
+
defaultValue: i,
|
|
283
245
|
options: this.options ? this.options.map((t) => ({
|
|
284
246
|
id: t.id,
|
|
285
247
|
label: t.label,
|
|
@@ -288,32 +250,32 @@ const a = {
|
|
|
288
250
|
})) : null
|
|
289
251
|
});
|
|
290
252
|
}
|
|
291
|
-
return
|
|
253
|
+
return r.serialize({
|
|
292
254
|
...s,
|
|
293
255
|
type: "number",
|
|
294
256
|
multiple: !1,
|
|
295
|
-
defaultValue:
|
|
296
|
-
options: this.options ? this.options.map((
|
|
297
|
-
id:
|
|
298
|
-
label:
|
|
299
|
-
value: Number(
|
|
300
|
-
condition:
|
|
257
|
+
defaultValue: h,
|
|
258
|
+
options: this.options ? this.options.map((i) => ({
|
|
259
|
+
id: i.id,
|
|
260
|
+
label: i.label,
|
|
261
|
+
value: Number(i.value),
|
|
262
|
+
condition: i.condition
|
|
301
263
|
})) : null
|
|
302
264
|
});
|
|
303
265
|
case "boolean":
|
|
304
266
|
if (this.multiple) {
|
|
305
|
-
let
|
|
267
|
+
let i;
|
|
306
268
|
if (Array.isArray(this.defaultValue)) {
|
|
307
|
-
|
|
269
|
+
i = [];
|
|
308
270
|
for (const t of this.defaultValue)
|
|
309
|
-
typeof t == "boolean" &&
|
|
310
|
-
|
|
271
|
+
typeof t == "boolean" && i.push(t);
|
|
272
|
+
i.length === 0 && (i = void 0);
|
|
311
273
|
}
|
|
312
|
-
return
|
|
274
|
+
return r.serialize({
|
|
313
275
|
...s,
|
|
314
276
|
type: "boolean",
|
|
315
277
|
multiple: !0,
|
|
316
|
-
defaultValue:
|
|
278
|
+
defaultValue: i,
|
|
317
279
|
options: this.options ? this.options.map((t) => ({
|
|
318
280
|
id: t.id,
|
|
319
281
|
label: t.label,
|
|
@@ -322,16 +284,16 @@ const a = {
|
|
|
322
284
|
})) : null
|
|
323
285
|
});
|
|
324
286
|
}
|
|
325
|
-
return
|
|
287
|
+
return r.serialize({
|
|
326
288
|
...s,
|
|
327
289
|
type: "boolean",
|
|
328
290
|
multiple: !1,
|
|
329
291
|
defaultValue: n,
|
|
330
|
-
options: this.options ? this.options.map((
|
|
331
|
-
id:
|
|
332
|
-
label:
|
|
333
|
-
value: !!
|
|
334
|
-
condition:
|
|
292
|
+
options: this.options ? this.options.map((i) => ({
|
|
293
|
+
id: i.id,
|
|
294
|
+
label: i.label,
|
|
295
|
+
value: !!i.value,
|
|
296
|
+
condition: i.condition
|
|
335
297
|
})) : null
|
|
336
298
|
});
|
|
337
299
|
// todo: support for object type fields
|
|
@@ -357,111 +319,98 @@ const a = {
|
|
|
357
319
|
}
|
|
358
320
|
}
|
|
359
321
|
};
|
|
360
|
-
},
|
|
361
|
-
const
|
|
322
|
+
}, v = (e) => {
|
|
323
|
+
const a = [], o = [], s = [], d = [], h = [];
|
|
362
324
|
return {
|
|
363
|
-
id:
|
|
364
|
-
component:
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
decide:
|
|
368
|
-
targets:
|
|
369
|
-
steps:
|
|
370
|
-
nodes:
|
|
325
|
+
id: e.id,
|
|
326
|
+
component: e.component,
|
|
327
|
+
type: e.type,
|
|
328
|
+
name: e.name,
|
|
329
|
+
decide: e.decide,
|
|
330
|
+
targets: e.targets,
|
|
331
|
+
steps: a,
|
|
332
|
+
nodes: o,
|
|
371
333
|
edges: s,
|
|
372
|
-
fields:
|
|
373
|
-
conditionals:
|
|
374
|
-
addStep(n,
|
|
375
|
-
let t =
|
|
376
|
-
this.nodes.length === 0 && (t =
|
|
377
|
-
const
|
|
334
|
+
fields: h,
|
|
335
|
+
conditionals: d,
|
|
336
|
+
addStep(n, i) {
|
|
337
|
+
let t = i == null ? void 0 : i.node;
|
|
338
|
+
this.nodes.length === 0 && (t = c({ type: "origin" }, this), this.nodes.push(t));
|
|
339
|
+
const l = "serialize" in n ? n : y(n, this);
|
|
378
340
|
if (t) {
|
|
379
|
-
if (!
|
|
341
|
+
if (!l.node)
|
|
380
342
|
throw new Error("todo no node");
|
|
381
|
-
const u =
|
|
382
|
-
{ sourceNode: t, destinationNode:
|
|
343
|
+
const u = p(
|
|
344
|
+
{ sourceNode: t, destinationNode: l.node, sourceNodeHandle: null },
|
|
383
345
|
this
|
|
384
346
|
);
|
|
385
347
|
this.edges.push(u);
|
|
386
348
|
}
|
|
387
|
-
return
|
|
349
|
+
return l.fields.length > 0 && l.fields.forEach((u) => {
|
|
388
350
|
this.fields.includes(u) || this.fields.push(u);
|
|
389
|
-
}), this.steps.includes(
|
|
351
|
+
}), this.steps.includes(l) || (this.steps.push(l), l.node && this.nodes.push(l.node)), l;
|
|
390
352
|
},
|
|
391
|
-
|
|
392
|
-
let t =
|
|
393
|
-
this.nodes.length === 0 && (t =
|
|
394
|
-
const
|
|
353
|
+
addConditional(n, i) {
|
|
354
|
+
let t = i == null ? void 0 : i.node;
|
|
355
|
+
this.nodes.length === 0 && (t = c({ type: "origin" }, this), this.nodes.push(t));
|
|
356
|
+
const l = "serialize" in n ? n : N(n, this);
|
|
395
357
|
if (t) {
|
|
396
|
-
|
|
397
|
-
{ sourceNode: t, destinationNode: r, sourceNodeHandle: null },
|
|
398
|
-
this
|
|
399
|
-
);
|
|
400
|
-
this.edges.push(u);
|
|
401
|
-
}
|
|
402
|
-
return this.nodes.push(r), r;
|
|
403
|
-
},
|
|
404
|
-
addConditional(n, e) {
|
|
405
|
-
let t = e == null ? void 0 : e.node;
|
|
406
|
-
this.nodes.length === 0 && (t = h({ type: "origin" }, this), this.nodes.push(t));
|
|
407
|
-
const r = "serialize" in n ? n : z(n, this);
|
|
408
|
-
if (t) {
|
|
409
|
-
if (!r.node)
|
|
358
|
+
if (!l.node)
|
|
410
359
|
throw new Error("todo no node");
|
|
411
|
-
const u =
|
|
412
|
-
{ sourceNode: t, destinationNode:
|
|
360
|
+
const u = p(
|
|
361
|
+
{ sourceNode: t, destinationNode: l.node, sourceNodeHandle: null },
|
|
413
362
|
this
|
|
414
363
|
);
|
|
415
364
|
this.edges.push(u);
|
|
416
365
|
}
|
|
417
|
-
return this.conditionals.includes(
|
|
366
|
+
return this.conditionals.includes(l) || (this.conditionals.push(l), l.node && this.nodes.push(l.node)), l;
|
|
418
367
|
},
|
|
419
|
-
addExperience(n,
|
|
420
|
-
let t =
|
|
421
|
-
this.nodes.length === 0 && (t =
|
|
422
|
-
const
|
|
368
|
+
addExperience(n, i) {
|
|
369
|
+
let t = i == null ? void 0 : i.node;
|
|
370
|
+
this.nodes.length === 0 && (t = c({ type: "origin" }, this), this.nodes.push(t));
|
|
371
|
+
const l = c(
|
|
423
372
|
{ type: "experience", experience: n },
|
|
424
373
|
this
|
|
425
374
|
);
|
|
426
|
-
if (this.nodes.push(
|
|
427
|
-
const u =
|
|
428
|
-
{ sourceNode: t, destinationNode:
|
|
375
|
+
if (this.nodes.push(l), t) {
|
|
376
|
+
const u = p(
|
|
377
|
+
{ sourceNode: t, destinationNode: l, sourceNodeHandle: null },
|
|
429
378
|
this
|
|
430
379
|
);
|
|
431
380
|
this.edges.push(u);
|
|
432
381
|
}
|
|
433
382
|
return n;
|
|
434
383
|
},
|
|
435
|
-
addField(n,
|
|
436
|
-
const t = "serialize" in n ? n :
|
|
437
|
-
return
|
|
384
|
+
addField(n, i) {
|
|
385
|
+
const t = "serialize" in n ? n : m(n);
|
|
386
|
+
return i && i.fields.push(t), this.fields.includes(t) || this.fields.push(t), t;
|
|
438
387
|
},
|
|
439
388
|
serialize() {
|
|
440
|
-
return
|
|
389
|
+
return r.serialize({
|
|
441
390
|
id: this.id,
|
|
391
|
+
type: this.type,
|
|
442
392
|
component: this.component,
|
|
443
393
|
name: this.name,
|
|
444
|
-
initializeOpen: this.initializeOpen,
|
|
445
394
|
decide: this.decide,
|
|
446
395
|
targets: this.targets,
|
|
447
|
-
steps: this.steps.map((n) =>
|
|
448
|
-
nodes: this.nodes.map((n) =>
|
|
449
|
-
edges: this.edges.map((n) =>
|
|
396
|
+
steps: this.steps.map((n) => r.deserialize(n.serialize())),
|
|
397
|
+
nodes: this.nodes.map((n) => r.deserialize(n.serialize())),
|
|
398
|
+
edges: this.edges.map((n) => r.deserialize(n.serialize())),
|
|
450
399
|
conditionals: this.conditionals.map(
|
|
451
|
-
(n) =>
|
|
400
|
+
(n) => r.deserialize(n.serialize())
|
|
452
401
|
),
|
|
453
|
-
fields: this.fields.map((n) =>
|
|
402
|
+
fields: this.fields.map((n) => r.deserialize(n.serialize()))
|
|
454
403
|
});
|
|
455
404
|
}
|
|
456
405
|
};
|
|
457
406
|
};
|
|
458
407
|
export {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
408
|
+
N as createConditional,
|
|
409
|
+
p as createEdge,
|
|
410
|
+
v as createExperience,
|
|
411
|
+
b as createExperiencePlugin,
|
|
412
|
+
m as createField,
|
|
413
|
+
c as createNode,
|
|
414
|
+
x as createStep,
|
|
415
|
+
r as serialization
|
|
467
416
|
};
|
package/dist/esm/server/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createEvent as i, createStore as v, createEffect as C, sample as n, attach as S } from "effector";
|
|
2
|
-
import { h as F } from "../../experience-instance-
|
|
2
|
+
import { h as F } from "../../experience-instance-XlIuqLrL.js";
|
|
3
3
|
function R() {
|
|
4
4
|
let c, p;
|
|
5
5
|
return {
|
|
@@ -0,0 +1 @@
|
|
|
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;
|