@picked/client 0.0.1-dev.1778561735098 → 0.0.1-dev.1778730134956

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 (61) hide show
  1. package/dist/{api-Bzb9pR2r.js → api-B-CbCRqb.js} +1 -1
  2. package/dist/{api-XV6bcv_D.cjs → api-CPRRXVw6.cjs} +1 -1
  3. package/dist/cjs/index.js +2 -2
  4. package/dist/cjs/plugins/create-experience/index.js +1 -1
  5. package/dist/cjs/plugins/dom-observer/index.js +1 -0
  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/server/index.js +1 -1
  11. package/dist/docs/workspaces.mdx +1 -1
  12. package/dist/dom-C3C6Fmwz.cjs +1 -0
  13. package/dist/dom-DGePXPpM.js +84 -0
  14. package/dist/esm/index.js +323 -303
  15. package/dist/esm/plugins/create-experience/index.js +1 -1
  16. package/dist/esm/plugins/dom-observer/index.js +87 -0
  17. package/dist/esm/plugins/dynamic-experiences/index.js +109 -38
  18. package/dist/esm/plugins/experience-browser-storage/index.js +1 -1
  19. package/dist/esm/plugins/history-browser-storage/index.js +14 -53
  20. package/dist/esm/plugins/responses-browser-storage/index.js +1 -1
  21. package/dist/esm/server/index.js +1 -1
  22. package/dist/experience-instance-BOhvCj_F.js +430 -0
  23. package/dist/experience-instance-D8yKenBU.cjs +1 -0
  24. package/dist/types/entities/content/content.d.ts +37 -0
  25. package/dist/types/entities/content/content.d.ts.map +1 -0
  26. package/dist/types/entities/experience/experience.d.ts +22 -2
  27. package/dist/types/entities/experience/experience.d.ts.map +1 -1
  28. package/dist/types/entities/experience-instance/experience-instance.d.ts +12 -0
  29. package/dist/types/entities/experience-instance/experience-instance.d.ts.map +1 -1
  30. package/dist/types/entities/history/history.d.ts +19 -28
  31. package/dist/types/entities/history/history.d.ts.map +1 -1
  32. package/dist/types/entities/response/response.d.ts +1 -0
  33. package/dist/types/entities/response/response.d.ts.map +1 -1
  34. package/dist/types/entities/step/step.d.ts +17 -2
  35. package/dist/types/entities/step/step.d.ts.map +1 -1
  36. package/dist/types/index.d.ts +2 -0
  37. package/dist/types/index.d.ts.map +1 -1
  38. package/dist/types/lifecycle/state-snapshot.d.ts.map +1 -1
  39. package/dist/types/picked.d.ts +57 -8
  40. package/dist/types/picked.d.ts.map +1 -1
  41. package/dist/types/plugins/dom-observer/index.d.ts +3 -0
  42. package/dist/types/plugins/dom-observer/index.d.ts.map +1 -0
  43. package/dist/types/plugins/dom-observer/plugin.d.ts +50 -0
  44. package/dist/types/plugins/dom-observer/plugin.d.ts.map +1 -0
  45. package/dist/types/plugins/dynamic-experiences/index.d.ts +2 -1
  46. package/dist/types/plugins/dynamic-experiences/index.d.ts.map +1 -1
  47. package/dist/types/plugins/dynamic-experiences/plugin.d.ts +18 -1
  48. package/dist/types/plugins/dynamic-experiences/plugin.d.ts.map +1 -1
  49. package/dist/types/plugins/dynamic-experiences/types.d.ts +63 -1
  50. package/dist/types/plugins/dynamic-experiences/types.d.ts.map +1 -1
  51. package/dist/types/plugins/history-browser-storage/plugin.d.ts +0 -16
  52. package/dist/types/plugins/history-browser-storage/plugin.d.ts.map +1 -1
  53. package/dist/types/utils/dom.d.ts +0 -27
  54. package/dist/types/utils/dom.d.ts.map +1 -1
  55. package/package.json +11 -1
  56. package/dist/experience-instance-B16NqD7y.cjs +0 -1
  57. package/dist/experience-instance-CZC0uPuv.js +0 -513
  58. /package/dist/{id-Bv44ilEo.cjs → id-Cg7fVl1O.cjs} +0 -0
  59. /package/dist/{id-CRqy981z.js → id-n2yrHvNo.js} +0 -0
  60. /package/dist/{storage-B6lQtc4-.cjs → storage-BXSlLTRa.cjs} +0 -0
  61. /package/dist/{storage-6Xk0uAxB.js → storage-hOHCCXvP.js} +0 -0
@@ -1,4 +1,4 @@
1
- import { t as e } from "../../../id-CRqy981z.js";
1
+ import { t as e } from "../../../id-n2yrHvNo.js";
2
2
  //#region src/plugins/create-experience/serialization.ts
3
3
  var t = {
4
4
  serialize(e) {
@@ -0,0 +1,87 @@
1
+ import "../../../logger-6z_gb4rA.js";
2
+ import { d as e, r as t } from "../../../supports-0XIfd4-R.js";
3
+ import { r as n } from "../../../dom-DGePXPpM.js";
4
+ import { createEffect as r, createEvent as i, createStore as a, sample as o } from "effector";
5
+ //#region src/plugins/dom-observer/plugin.ts
6
+ var s = /* @__PURE__ */ new WeakSet(), c = () => ({
7
+ name: "dom-observer",
8
+ setup: (e) => {
9
+ l() && (s.has(e) || (s.add(e), u(e)));
10
+ }
11
+ });
12
+ function l() {
13
+ return !(!e() || !t() || typeof MutationObserver != "function" || typeof requestAnimationFrame != "function");
14
+ }
15
+ function u(e) {
16
+ n().then(() => {
17
+ document.body && d(e);
18
+ });
19
+ }
20
+ function d(e) {
21
+ let t = i(), n = a(/* @__PURE__ */ new Map()).on(t, (e, { id: t, selectors: n }) => {
22
+ let r = new Map(e);
23
+ return n.length > 0 ? r.set(t, n) : r.delete(t), r;
24
+ }), s = /* @__PURE__ */ new Map();
25
+ e.experiences.listStore.watch((e) => {
26
+ for (let n of e) {
27
+ if (s.has(n.id)) continue;
28
+ let e = n.configStore.watch((e) => {
29
+ t({
30
+ id: n.id,
31
+ selectors: f(e.targetSelectors)
32
+ });
33
+ });
34
+ s.set(n.id, e);
35
+ }
36
+ });
37
+ let c = r(async (e) => {
38
+ await Promise.all(e.map(async (e) => {
39
+ await e.shouldInitialiseFx() && await e.initialiseFx(void 0);
40
+ }));
41
+ });
42
+ c.fail.watch(({ error: e }) => {});
43
+ let l = i();
44
+ o({
45
+ clock: l,
46
+ source: {
47
+ selectorsById: n,
48
+ experiences: e.experiences.listStore
49
+ },
50
+ fn: ({ selectorsById: e, experiences: t }, n) => t.filter((t) => {
51
+ let r = e.get(t.id);
52
+ return r ? r.some((e) => p(n, e)) : !1;
53
+ }),
54
+ target: c
55
+ });
56
+ let u = [], d, m = () => {
57
+ d = void 0;
58
+ let e = u;
59
+ u = [], l(e);
60
+ };
61
+ new MutationObserver((e) => {
62
+ let t = !1;
63
+ for (let n of e) if (n.type === "childList") for (let e of n.addedNodes) e instanceof Element && (u.push(e), t = !0);
64
+ t && (d ??= requestAnimationFrame(m));
65
+ }).observe(document.body, {
66
+ childList: !0,
67
+ subtree: !0
68
+ });
69
+ }
70
+ function f(e) {
71
+ let t = [];
72
+ for (let n of e) {
73
+ let e = n.selector.trim();
74
+ e.length > 0 && t.push(e);
75
+ }
76
+ return t;
77
+ }
78
+ function p(e, t) {
79
+ for (let n of e) try {
80
+ if (n.matches(t) || n.querySelector(t) !== null) return !0;
81
+ } catch {
82
+ return !1;
83
+ }
84
+ return !1;
85
+ }
86
+ //#endregion
87
+ export { c as domObserverPlugin };
@@ -1,5 +1,5 @@
1
1
  import "../../../logger-6z_gb4rA.js";
2
- import { i as e, t } from "../../../api-Bzb9pR2r.js";
2
+ import { i as e, t } from "../../../api-B-CbCRqb.js";
3
3
  import { attach as n } from "effector";
4
4
  //#region src/plugins/dynamic-experiences/hash.ts
5
5
  function r(e) {
@@ -50,12 +50,17 @@ function u(e, t) {
50
50
  }
51
51
  t.push(i);
52
52
  }
53
+ let i = r.layoutContentId ? e.contents.getById(r.layoutContentId) : null;
53
54
  e.registerStep({
54
55
  id: r.id,
55
56
  key: r.key,
56
57
  name: r.name,
57
58
  fieldKeys: t,
58
- layoutName: r.layoutName
59
+ layoutName: r.layoutName,
60
+ ...r.layoutContentId !== void 0 && {
61
+ layoutContentId: r.layoutContentId,
62
+ layoutContentStore: i
63
+ }
59
64
  });
60
65
  }
61
66
  }
@@ -87,24 +92,7 @@ function h(e, t, n, r) {
87
92
  decide: () => t.enabled ? a(r, t.weight) : !1
88
93
  });
89
94
  }
90
- function g() {
91
- let e;
92
- try {
93
- e = __PICKED_PROJECT_CONFIG__;
94
- } catch {
95
- return;
96
- }
97
- if (e === void 0) return;
98
- let t;
99
- if (typeof e == "string") try {
100
- t = JSON.parse(e);
101
- } catch {
102
- return;
103
- }
104
- else t = e;
105
- if (o(t)) return t;
106
- }
107
- function _(e) {
95
+ function g(e) {
108
96
  try {
109
97
  let t = new URL(e).hostname;
110
98
  return t === "localhost" || t === "127.0.0.1" || t === "::1";
@@ -112,17 +100,17 @@ function _(e) {
112
100
  return !1;
113
101
  }
114
102
  }
115
- function v(e) {
103
+ function _(e) {
116
104
  if (typeof e != "object" || !e || !("cause" in e)) return !1;
117
105
  let { cause: t } = e;
118
106
  return typeof t != "object" || !t || !("code" in t) ? !1 : t.code === "ECONNREFUSED";
119
107
  }
120
- async function y(e, n, r) {
108
+ async function v(e, n, r) {
121
109
  let i = r?.previewToken ? `projects/${n}?preview_token=${encodeURIComponent(r.previewToken)}` : `projects/${n}`, a;
122
110
  try {
123
111
  a = await t(e, i, r?.headers);
124
112
  } catch (t) {
125
- return _(e) && v(t), null;
113
+ return g(e) && _(t), null;
126
114
  }
127
115
  if (!a.ok) return `${a.status.toString()}`, null;
128
116
  let s;
@@ -133,7 +121,97 @@ async function y(e, n, r) {
133
121
  }
134
122
  return o(s) ? s : null;
135
123
  }
136
- function b(e) {
124
+ function y(e) {
125
+ return typeof e != "object" || !e || !("experienceId" in e) || !("content" in e) ? !1 : Array.isArray(e.content);
126
+ }
127
+ async function b(e, n, r, i) {
128
+ let a = i?.previewToken ? `projects/${n}/experiences/${r}/content?preview_token=${encodeURIComponent(i.previewToken)}` : `projects/${n}/experiences/${r}/content`, o;
129
+ try {
130
+ o = await t(e, a, i?.headers);
131
+ } catch (t) {
132
+ return g(e) && _(t) || `${r}`, null;
133
+ }
134
+ if (!o.ok) return `${r}${o.status.toString()}`, null;
135
+ let s;
136
+ try {
137
+ s = await o.json();
138
+ } catch {
139
+ return `${r}`, null;
140
+ }
141
+ return y(s) ? s : (`${r}`, null);
142
+ }
143
+ function x(e, t) {
144
+ for (let n of t.content) e.registerContent({
145
+ id: n.id,
146
+ data: n.data
147
+ });
148
+ }
149
+ function S(e) {
150
+ if (typeof e != "object" || !e || !("projectConfig" in e) || !("experienceContent" in e) || !("manifestMetadata" in e)) return !1;
151
+ let { experienceContent: t } = e;
152
+ return typeof t == "function";
153
+ }
154
+ async function C() {
155
+ try {
156
+ let e = await import("virtual:picked/data");
157
+ return S(e) ? e : null;
158
+ } catch {
159
+ return null;
160
+ }
161
+ }
162
+ function w(e, t, n) {
163
+ return (r) => b(e, t, r.id, n ? { previewToken: n } : void 0);
164
+ }
165
+ function T(e, t) {
166
+ return (n) => e(n, t ? { previewToken: t } : void 0);
167
+ }
168
+ function E(e) {
169
+ return (t, n) => e.experienceContent(t, n);
170
+ }
171
+ function D(e, t) {
172
+ let n = /* @__PURE__ */ new Map();
173
+ return (r, i) => {
174
+ let a = n.get(r.id);
175
+ if (a) return a;
176
+ let o = (async () => {
177
+ try {
178
+ let n = await t(r, i);
179
+ return n && x(e, n), n;
180
+ } finally {
181
+ n.delete(r.id);
182
+ }
183
+ })();
184
+ return n.set(r.id, o), o;
185
+ };
186
+ }
187
+ async function O(e) {
188
+ let { client: t, apiUrl: n, options: r } = e, i = f(t), a = !!i, o = r?.projectConfig ?? null, s = r?.getContent ? T(r.getContent, i) : null, c = null;
189
+ if (i) return o ??= await v(n, t.projectId, { previewToken: i }), s ??= w(n, t.projectId, i), {
190
+ config: o,
191
+ contentLoader: s,
192
+ dataSource: c,
193
+ isPreview: a
194
+ };
195
+ if (o && s) return {
196
+ config: o,
197
+ contentLoader: s,
198
+ dataSource: c,
199
+ isPreview: a
200
+ };
201
+ let l = await C();
202
+ return l ? (o ??= l.projectConfig, s ??= E(l), c = l.manifestMetadata, {
203
+ config: o,
204
+ contentLoader: s,
205
+ dataSource: c,
206
+ isPreview: a
207
+ }) : (o ??= await v(n, t.projectId), s ??= w(n, t.projectId), {
208
+ config: o,
209
+ contentLoader: s,
210
+ dataSource: c,
211
+ isPreview: a
212
+ });
213
+ }
214
+ function k(e) {
137
215
  return {
138
216
  name: "dynamic-experiences",
139
217
  setup: (t) => {
@@ -141,23 +219,16 @@ function b(e) {
141
219
  return { onStart: n({
142
220
  source: t.session.store.map((e) => e.id),
143
221
  effect: async (n) => {
144
- let i = f(t);
145
- if (i) {
146
- let e = await y(r, t.projectId, { previewToken: i });
147
- e && (m(t, e, !0, n), s(t, e), l(t, e), u(t, e), d(t, e));
148
- return;
149
- }
150
- let a = e?.projectConfig ?? g();
151
- if (a) {
152
- m(t, a, !1, n), s(t, a), l(t, a), u(t, a), d(t, a);
153
- return;
154
- }
155
- let o = await y(r, t.projectId);
156
- o && (m(t, o, !1, n), s(t, o), l(t, o), u(t, o), d(t, o));
222
+ let { config: i, contentLoader: a, dataSource: o, isPreview: c } = await O({
223
+ client: t,
224
+ apiUrl: r,
225
+ options: e
226
+ });
227
+ a && (t.contentLoader = D(t, a)), t.dataSource = o, i && (m(t, i, c, n), s(t, i), l(t, i), u(t, i), d(t, i));
157
228
  }
158
229
  }) };
159
230
  }
160
231
  };
161
232
  }
162
233
  //#endregion
163
- export { e as createClientHeaders, b as dynamicExperiencesPlugin, y as fetchProject };
234
+ export { e as createClientHeaders, k as dynamicExperiencesPlugin, b as fetchExperienceContent, v as fetchProject };
@@ -1,6 +1,6 @@
1
1
  import "../../../logger-6z_gb4rA.js";
2
2
  import { d as e } from "../../../supports-0XIfd4-R.js";
3
- import { n as t, r as n, t as r } from "../../../storage-6Xk0uAxB.js";
3
+ import { n as t, r as n, t as r } from "../../../storage-hOHCCXvP.js";
4
4
  import { createEffect as i, sample as a } from "effector";
5
5
  //#region src/plugins/experience-browser-storage/plugin.ts
6
6
  var o = ({ storage: o = "local" } = {}) => ({
@@ -1,65 +1,26 @@
1
- import "../../../logger-6z_gb4rA.js";
2
1
  import { d as e } from "../../../supports-0XIfd4-R.js";
3
- import { n as t, r as n, t as r } from "../../../storage-6Xk0uAxB.js";
2
+ import { n as t, r as n, t as r } from "../../../storage-hOHCCXvP.js";
4
3
  import { createEffect as i, sample as a } from "effector";
5
4
  //#region src/plugins/history-browser-storage/plugin.ts
6
- var o = r("history", "global"), s = 150, c = "__legacy__", l = (e) => Array.isArray(e), u = (e) => !(typeof e != "object" || !e || !("id" in e) || typeof e.id != "string" || !("at" in e) || typeof e.at != "number" || !("experienceId" in e) || typeof e.experienceId != "string" || !("node" in e) || typeof e.node != "object" || e.node === null), d = (e) => !(!u(e) || !("instanceId" in e) || typeof e.instanceId != "string"), f = (e) => {
7
- if (typeof e != "object" || !e || Array.isArray(e)) return !1;
8
- for (let t of Object.values(e)) {
9
- if (!Array.isArray(t)) return !1;
10
- for (let e of t) if (!d(e)) return !1;
11
- }
12
- return !0;
13
- }, p = (e) => {
14
- let t = {};
15
- for (let n of e) {
16
- if (!u(n)) continue;
17
- let e = t[n.experienceId] ?? [];
18
- e.push({
19
- ...n,
20
- instanceId: c
21
- }), t[n.experienceId] = e;
22
- }
23
- return t;
24
- }, m = ({ storage: r = "local" } = {}) => ({
5
+ var o = r("history", "global"), s = ({ storage: r = "local" } = {}) => ({
25
6
  name: "history-browser-storage-plugin",
26
- setup: (c) => {
7
+ setup: (s) => {
27
8
  if (!e()) return;
28
- let u = r === "local" ? t : n, d = i(() => {
29
- let e;
30
- try {
31
- e = u.get(o).json();
32
- } catch {
33
- return;
34
- }
35
- if (e != null) {
36
- if (l(e)) {
37
- c.history.restoreSnapshots({ snapshots: p(e) });
38
- return;
39
- }
40
- if (f(e)) {
41
- c.history.restoreSnapshots({ snapshots: e });
42
- return;
43
- }
44
- }
45
- }), m = null, h = null, g = () => {
46
- m = null;
47
- let e = h;
48
- if (h = null, e !== null) try {
49
- u.set(o, e);
50
- } catch {}
51
- }, _ = i((e) => {
52
- h = e, m === null && (m = setTimeout(g, s));
9
+ let c = r === "local" ? t : n, l = i(async () => {
10
+ let e = c.get(o).json();
11
+ e && s.history.restore({ entries: e });
12
+ }), u = i(async (e) => {
13
+ c.set(o, e);
53
14
  });
54
15
  a({
55
- source: c.eventBus,
16
+ source: s.eventBus,
56
17
  filter: (e) => e.type === "load",
57
- target: d
18
+ target: l
58
19
  }), a({
59
- source: c.history.snapshotStore,
60
- target: _
61
- }), d();
20
+ source: s.history.entriesStore,
21
+ target: u
22
+ });
62
23
  }
63
24
  });
64
25
  //#endregion
65
- export { m as historyBrowserStoragePlugin };
26
+ export { s as historyBrowserStoragePlugin };
@@ -1,5 +1,5 @@
1
1
  import { d as e } from "../../../supports-0XIfd4-R.js";
2
- import { n as t, r as n, t as r } from "../../../storage-6Xk0uAxB.js";
2
+ import { n as t, r as n, t as r } from "../../../storage-hOHCCXvP.js";
3
3
  import { attach as i, createEffect as a, sample as o } from "effector";
4
4
  //#region src/plugins/responses-browser-storage/plugin.ts
5
5
  var s = r("responses", "global");
@@ -1,4 +1,4 @@
1
- import { t as e } from "../../experience-instance-CZC0uPuv.js";
1
+ import { t as e } from "../../experience-instance-BOhvCj_F.js";
2
2
  import { attach as t, createEffect as n, createEvent as r, createStore as i, sample as a } from "effector";
3
3
  //#region src/server/index.ts
4
4
  function o() {