cogsbox-state 0.5.471 → 0.5.473

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 (46) hide show
  1. package/README.md +2 -5
  2. package/dist/CogsState.d.ts +105 -79
  3. package/dist/CogsState.d.ts.map +1 -1
  4. package/dist/CogsState.jsx +1082 -987
  5. package/dist/CogsState.jsx.map +1 -1
  6. package/dist/Components.d.ts.map +1 -1
  7. package/dist/Components.jsx +293 -243
  8. package/dist/Components.jsx.map +1 -1
  9. package/dist/PluginRunner.d.ts +10 -0
  10. package/dist/PluginRunner.d.ts.map +1 -0
  11. package/dist/PluginRunner.jsx +128 -0
  12. package/dist/PluginRunner.jsx.map +1 -0
  13. package/dist/index.d.ts +2 -0
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +33 -26
  16. package/dist/index.js.map +1 -1
  17. package/dist/pluginStore.d.ts +43 -0
  18. package/dist/pluginStore.d.ts.map +1 -0
  19. package/dist/pluginStore.js +52 -0
  20. package/dist/pluginStore.js.map +1 -0
  21. package/dist/plugins.d.ts +1326 -0
  22. package/dist/plugins.d.ts.map +1 -0
  23. package/dist/plugins.js +76 -0
  24. package/dist/plugins.js.map +1 -0
  25. package/dist/store.d.ts +69 -26
  26. package/dist/store.d.ts.map +1 -1
  27. package/dist/store.js +436 -152
  28. package/dist/store.js.map +1 -1
  29. package/dist/utility.d.ts +1 -1
  30. package/dist/utility.d.ts.map +1 -1
  31. package/dist/utility.js +12 -12
  32. package/dist/utility.js.map +1 -1
  33. package/dist/validation.d.ts +7 -0
  34. package/dist/validation.d.ts.map +1 -0
  35. package/dist/validation.js +39 -0
  36. package/dist/validation.js.map +1 -0
  37. package/package.json +18 -13
  38. package/src/CogsState.tsx +719 -458
  39. package/src/Components.tsx +304 -180
  40. package/src/PluginRunner.tsx +208 -0
  41. package/src/index.ts +2 -0
  42. package/src/pluginStore.ts +159 -0
  43. package/src/plugins.ts +548 -0
  44. package/src/store.ts +881 -189
  45. package/src/utility.ts +31 -31
  46. package/src/validation.ts +84 -0
package/dist/store.js CHANGED
@@ -1,74 +1,294 @@
1
- import { create as w } from "zustand";
2
- const _ = w((l, a) => ({
3
- formRefs: /* @__PURE__ */ new Map(),
4
- registerFormRef: (e, t) => l((o) => {
5
- const n = new Map(o.formRefs);
6
- return n.set(e, t), { formRefs: n };
7
- }),
8
- getFormRef: (e) => a().formRefs.get(e),
9
- removeFormRef: (e) => l((t) => {
10
- const o = new Map(t.formRefs);
11
- return o.delete(e), { formRefs: o };
12
- }),
13
- getFormRefsByStateKey: (e) => {
14
- const t = a().formRefs, o = e + ".", n = /* @__PURE__ */ new Map();
15
- return t.forEach((s, r) => {
16
- (r.startsWith(o) || r === e) && n.set(r, s);
17
- }), n;
1
+ import { create as A } from "zustand";
2
+ function I(u, a = "zod4") {
3
+ if (!u) return null;
4
+ let e = u, t = !1, o = !1, n, s = !1;
5
+ for (let l = 0; l < 20; l++) {
6
+ const f = e?.def || e?._def;
7
+ if (!f) break;
8
+ const p = f.typeName || f.type || e._type;
9
+ if (p === "ZodUnion" || p === "union")
10
+ if (f.options && f.options.length > 0) {
11
+ e = f.options[0];
12
+ continue;
13
+ } else
14
+ break;
15
+ if (p === "ZodOptional" || p === "optional")
16
+ o = !0;
17
+ else if (p === "ZodNullable" || p === "nullable")
18
+ t = !0;
19
+ else if (p === "ZodDefault" || p === "default")
20
+ s = !0, n = typeof f.defaultValue == "function" ? f.defaultValue() : f.defaultValue;
21
+ else if (p !== "ZodEffects" && p !== "effects")
22
+ break;
23
+ const y = f.innerType || f.schema || e._inner;
24
+ if (!y || y === e)
25
+ break;
26
+ e = y;
18
27
  }
19
- }));
20
- function h(l) {
21
- if (l === null || typeof l != "object")
22
- return { value: l };
23
- if (Array.isArray(l)) {
24
- const a = { _meta: { arrayKeys: [] } }, e = [];
25
- return l.forEach((t) => {
26
- const o = `id:${b()}`;
27
- a[o] = h(t), e.push(o);
28
- }), a._meta.arrayKeys = e, a;
28
+ const r = e, i = r?.def || r?._def, c = i?.typeName || i?.type || r?._type;
29
+ return c === "ZodNumber" || c === "number" ? {
30
+ type: "number",
31
+ schema: u,
32
+ source: a,
33
+ default: s ? n : 0,
34
+ nullable: t,
35
+ optional: o
36
+ } : c === "ZodString" || c === "string" ? {
37
+ type: "string",
38
+ schema: u,
39
+ source: a,
40
+ default: s ? n : "",
41
+ nullable: t,
42
+ optional: o
43
+ } : c === "ZodBoolean" || c === "boolean" ? {
44
+ type: "boolean",
45
+ schema: u,
46
+ source: a,
47
+ default: s ? n : !1,
48
+ nullable: t,
49
+ optional: o
50
+ } : c === "ZodArray" || c === "array" ? {
51
+ type: "array",
52
+ schema: u,
53
+ source: a,
54
+ default: s ? n : [],
55
+ nullable: t,
56
+ optional: o
57
+ } : c === "ZodObject" || c === "object" ? {
58
+ type: "object",
59
+ schema: u,
60
+ source: a,
61
+ default: s ? n : {},
62
+ nullable: t,
63
+ optional: o
64
+ } : c === "ZodDate" || c === "date" ? {
65
+ type: "date",
66
+ schema: u,
67
+ source: a,
68
+ default: s ? n : /* @__PURE__ */ new Date(),
69
+ nullable: t,
70
+ optional: o
71
+ } : null;
72
+ }
73
+ function E(u) {
74
+ if (u === null)
75
+ return {
76
+ type: "unknown",
77
+ schema: null,
78
+ source: "default",
79
+ default: null,
80
+ nullable: !0
81
+ };
82
+ if (u === void 0)
83
+ return {
84
+ type: "unknown",
85
+ schema: null,
86
+ source: "default",
87
+ default: void 0,
88
+ optional: !0
89
+ };
90
+ const a = typeof u;
91
+ return a === "number" ? { type: "number", schema: null, source: "runtime", default: u } : a === "string" ? { type: "string", schema: null, source: "runtime", default: u } : a === "boolean" ? { type: "boolean", schema: null, source: "runtime", default: u } : Array.isArray(u) ? { type: "array", schema: null, source: "runtime", default: [] } : u instanceof Date ? { type: "date", schema: null, source: "runtime", default: u } : a === "object" ? { type: "object", schema: null, source: "runtime", default: {} } : { type: "unknown", schema: null, source: "runtime", default: u };
92
+ }
93
+ function _(u, a, e) {
94
+ if (a == null || typeof a != "object") {
95
+ const t = { _meta: { value: a } };
96
+ return t._meta.typeInfo = M(a, e), t;
97
+ }
98
+ if (Array.isArray(a)) {
99
+ const t = { _meta: { arrayKeys: [] } };
100
+ return t._meta.typeInfo = M(a, e), a.forEach((o, n) => {
101
+ const s = O(), r = e ? {
102
+ ...e,
103
+ path: [...e.path, n.toString()]
104
+ } : void 0;
105
+ t[s] = _(u, o, r), t._meta.arrayKeys.push(s);
106
+ }), t;
29
107
  }
30
- if (l.constructor === Object) {
31
- const a = { _meta: {} };
32
- for (const e in l)
33
- Object.prototype.hasOwnProperty.call(l, e) && (a[e] = h(l[e]));
34
- return a;
108
+ if (a.constructor === Object) {
109
+ const t = { _meta: {} };
110
+ t._meta.typeInfo = M(a, e);
111
+ for (const o in a)
112
+ if (Object.prototype.hasOwnProperty.call(a, o)) {
113
+ const n = e ? {
114
+ ...e,
115
+ path: [...e.path, o]
116
+ } : void 0;
117
+ t[o] = _(u, a[o], n);
118
+ }
119
+ return t;
35
120
  }
36
- return { value: l };
121
+ return {
122
+ _meta: {
123
+ value: a,
124
+ typeInfo: E(a)
125
+ }
126
+ };
37
127
  }
38
- const p = /* @__PURE__ */ new Map();
39
- let M = 0;
40
- function b(l = "id") {
41
- return `${l}:${(M++).toString(36)}`;
128
+ function M(u, a) {
129
+ if (a) {
130
+ let e = null;
131
+ if (a.schemas.zodV4) {
132
+ const t = a.path.length === 0 ? a.schemas.zodV4 : j(a.schemas.zodV4, a.path);
133
+ t && (e = I(t, "zod4"));
134
+ }
135
+ if (!e && a.schemas.zodV3) {
136
+ const t = a.path.length === 0 ? a.schemas.zodV3 : j(a.schemas.zodV3, a.path);
137
+ t && (e = I(t, "zod3"));
138
+ }
139
+ if (!e && a.schemas.sync?.[a.stateKey] && (e = E(u), e.source = "sync"), e) return e;
140
+ }
141
+ return E(u);
42
142
  }
43
- const E = w((l, a) => ({
44
- // Remove shadowStateStore from Zustand state
143
+ function N(u, a, e) {
144
+ const t = h.get(u) || h.get(`[${u}`);
145
+ if (!t) return;
146
+ function o(n, s) {
147
+ if (!n || typeof n != "object") return;
148
+ const r = j(a, s);
149
+ if (r) {
150
+ const i = I(r, e);
151
+ i && (n._meta || (n._meta = {}), n._meta.typeInfo = {
152
+ ...i,
153
+ schema: r
154
+ });
155
+ }
156
+ n._meta?.arrayKeys ? n._meta.arrayKeys.forEach((i) => {
157
+ n[i] && o(n[i], [...s, "0"]);
158
+ }) : n._meta?.hasOwnProperty("value") || Object.keys(n).forEach((i) => {
159
+ i !== "_meta" && o(n[i], [...s, i]);
160
+ });
161
+ }
162
+ o(t, []);
163
+ }
164
+ function z(u) {
165
+ let a = u;
166
+ for (; a; ) {
167
+ const e = a.def || a._def, t = e?.typeName || e?.type || a._type;
168
+ if (t === "ZodOptional" || t === "optional" || t === "ZodNullable" || t === "nullable" || t === "ZodDefault" || t === "default" || t === "ZodEffects" || t === "effects")
169
+ a = e.innerType || e.schema || a._inner || a.unwrap?.();
170
+ else
171
+ break;
172
+ }
173
+ return a;
174
+ }
175
+ function j(u, a) {
176
+ if (!u) return null;
177
+ if (a.length === 0) return u;
178
+ let e = u;
179
+ for (const t of a) {
180
+ const o = z(e);
181
+ if (!o) return null;
182
+ const n = o.def || o._def, s = n?.typeName || n?.type || o._type;
183
+ if (s === "ZodObject" || s === "object")
184
+ e = (n?.shape || o.shape || o._shape)?.[t];
185
+ else if (s === "ZodArray" || s === "array")
186
+ e = o.element || n?.type;
187
+ else
188
+ return null;
189
+ if (!e)
190
+ return null;
191
+ }
192
+ return e;
193
+ }
194
+ const h = /* @__PURE__ */ new Map();
195
+ let D = 0;
196
+ const V = Date.now().toString(36);
197
+ function O(u) {
198
+ return `id:local_${V}_${(D++).toString(36)}`;
199
+ }
200
+ const $ = A((u, a) => ({
201
+ getPluginMetaDataMap: (e, t) => a().getShadowMetadata(e, t)?.pluginMetaData,
202
+ setPluginMetaData: (e, t, o, n) => {
203
+ const s = a().getShadowMetadata(e, t) || {}, r = new Map(s.pluginMetaData || []), i = r.get(o) || {};
204
+ r.set(o, { ...i, ...n }), a().setShadowMetadata(e, t, { ...s, pluginMetaData: r }), a().notifyPathSubscribers([e, ...t].join("."), {
205
+ type: "METADATA_UPDATE"
206
+ });
207
+ },
208
+ removePluginMetaData: (e, t, o) => {
209
+ const n = a().getShadowMetadata(e, t);
210
+ if (!n?.pluginMetaData) return;
211
+ const s = new Map(n.pluginMetaData);
212
+ s.delete(o), a().setShadowMetadata(e, t, { ...n, pluginMetaData: s });
213
+ },
45
214
  setTransformCache: (e, t, o, n) => {
46
215
  const s = a().getShadowMetadata(e, t) || {};
47
216
  s.transformCaches || (s.transformCaches = /* @__PURE__ */ new Map()), s.transformCaches.set(o, n), a().setShadowMetadata(e, t, {
48
217
  transformCaches: s.transformCaches
49
218
  });
50
219
  },
220
+ // Replace your entire `initializeAndMergeShadowState` function with this one.
221
+ initializeAndMergeShadowState: (e, t) => {
222
+ const n = t?._meta?.arrayKeys !== void 0 ? `[${e}` : e, s = h.get(n) || h.get(e) || h.get(`[${e}`);
223
+ let r = {};
224
+ if (s?._meta) {
225
+ const {
226
+ components: f,
227
+ features: p,
228
+ lastServerSync: y,
229
+ stateSource: m,
230
+ baseServerState: d,
231
+ pathComponents: S,
232
+ signals: b,
233
+ validation: g
234
+ } = s._meta;
235
+ f && (r.components = f), p && (r.features = p), y && (r.lastServerSync = y), m && (r.stateSource = m), d && (r.baseServerState = d), S && (r.pathComponents = S), b && (r.signals = b), g && (r.validation = g);
236
+ }
237
+ function i(f, p) {
238
+ if (p._meta || f._meta) {
239
+ const d = f._meta || {}, S = p._meta || {}, b = { ...d, ...S };
240
+ d.typeInfo?.schema && !S.typeInfo?.schema && (b.typeInfo = d.typeInfo), d.validation && !S.validation && (b.validation = d.validation), d.components && (b.components = d.components), f._meta = b;
241
+ }
242
+ if (p._meta?.hasOwnProperty("value")) {
243
+ for (const d in f)
244
+ d !== "_meta" && delete f[d];
245
+ return;
246
+ }
247
+ const y = new Set(
248
+ Object.keys(p).filter((d) => d !== "_meta")
249
+ ), m = new Set(
250
+ Object.keys(f).filter((d) => d !== "_meta")
251
+ );
252
+ for (const d of m)
253
+ y.has(d) || delete f[d];
254
+ for (const d of y) {
255
+ const S = p[d], b = f[d];
256
+ b && typeof b == "object" && S && typeof S == "object" ? i(b, S) : f[d] = S;
257
+ }
258
+ }
259
+ s ? (i(s, t), s._meta || (s._meta = {}), Object.assign(s._meta, r), h.set(n, s)) : (r && Object.keys(r).length > 0 && (t._meta || (t._meta = {}), Object.assign(t._meta, r)), h.set(n, t));
260
+ const c = a().getInitialOptions(e);
261
+ (c?.validation?.zodSchemaV4 || c?.validation?.zodSchemaV3) && (c.validation?.zodSchemaV4 ? N(e, c.validation.zodSchemaV4, "zod4") : c.validation?.zodSchemaV3 && N(e, c.validation.zodSchemaV3, "zod3")), n === e ? h.delete(`[${e}`) : h.delete(e);
262
+ },
51
263
  initializeShadowState: (e, t) => {
52
- const o = p.get(e) || p.get(`[${e}`);
264
+ const o = h.get(e) || h.get(`[${e}`);
53
265
  let n = {};
54
266
  if (o?._meta) {
55
267
  const {
56
- components: i,
57
- features: f,
58
- lastServerSync: c,
59
- stateSource: d,
60
- baseServerState: u
268
+ components: f,
269
+ features: p,
270
+ lastServerSync: y,
271
+ stateSource: m,
272
+ baseServerState: d
61
273
  } = o._meta;
62
- i && (n.components = i), f && (n.features = f), c && (n.lastServerSync = c), d && (n.stateSource = d), u && (n.baseServerState = u);
274
+ f && (n.components = f), p && (n.features = p), y && (n.lastServerSync = y), m && (n.stateSource = m), d && (n.baseServerState = d);
63
275
  }
64
- p.delete(e), p.delete(`[${e}`);
65
- const s = h(t);
66
- s._meta || (s._meta = {}), Object.assign(s._meta, n);
67
- const r = Array.isArray(t) ? `[${e}` : e;
68
- p.set(r, s);
276
+ h.delete(e), h.delete(`[${e}`);
277
+ const s = a().getInitialOptions(e), r = a().getInitialOptions("__syncSchemas"), i = {
278
+ stateKey: e,
279
+ path: [],
280
+ schemas: {
281
+ sync: r,
282
+ zodV4: s?.validation?.zodSchemaV4,
283
+ zodV3: s?.validation?.zodSchemaV3
284
+ }
285
+ }, c = _(e, t, i);
286
+ c._meta || (c._meta = {}), Object.assign(c._meta, n);
287
+ const l = Array.isArray(t) ? `[${e}` : e;
288
+ h.set(l, c);
69
289
  },
70
290
  getShadowNode: (e, t) => {
71
- let o = p.get(e) || p.get(`[${e}`);
291
+ let o = h.get(e) || h.get(`[${e}`);
72
292
  if (o) {
73
293
  if (t.length === 0) return o;
74
294
  for (const n of t)
@@ -78,10 +298,10 @@ const E = w((l, a) => ({
78
298
  },
79
299
  getShadowMetadata: (e, t) => a().getShadowNode(e, t)?._meta,
80
300
  setShadowMetadata: (e, t, o) => {
81
- const n = p.has(`[${e}`) ? `[${e}` : e;
82
- let s = p.get(n);
301
+ const n = h.has(`[${e}`) ? `[${e}` : e;
302
+ let s = h.get(n);
83
303
  if (!s) {
84
- s = { _meta: o }, p.set(n, s);
304
+ s = { _meta: o }, h.set(n, s);
85
305
  return;
86
306
  }
87
307
  let r = s;
@@ -89,87 +309,144 @@ const E = w((l, a) => ({
89
309
  r[i] || (r[i] = {}), r = r[i];
90
310
  r._meta || (r._meta = {}), Object.assign(r._meta, o);
91
311
  },
92
- getShadowValue: (e, t, o, n) => {
93
- const s = a().getShadowNode(e, t);
94
- if (s == null) return;
95
- const r = Object.keys(s);
96
- if (Object.prototype.hasOwnProperty.call(s, "value") && r.every((d) => d === "value" || d === "_meta"))
97
- return s.value;
98
- if (s._meta && Object.prototype.hasOwnProperty.call(s._meta, "arrayKeys"))
99
- return (o !== void 0 && o.length > 0 ? o : s._meta.arrayKeys).map(
100
- (u) => a().getShadowValue(e, [...t, u])
101
- );
102
- const c = {};
103
- for (const d of r)
104
- d !== "_meta" && !d.startsWith("id:") && (c[d] = a().getShadowValue(e, [...t, d]));
105
- return c;
312
+ getShadowValue: (e, t, o) => {
313
+ const n = a().getShadowNode(e, t);
314
+ if (!n)
315
+ return;
316
+ const s = {}, r = [
317
+ [n, s, "final"]
318
+ ];
319
+ for (; r.length > 0; ) {
320
+ const [i, c, l] = r.pop();
321
+ if (i._meta?.hasOwnProperty("value")) {
322
+ c[l] = i._meta.value;
323
+ continue;
324
+ }
325
+ if (i._meta?.arrayKeys) {
326
+ const y = o || i._meta.arrayKeys, m = [];
327
+ c[l] = m;
328
+ for (let d = y.length - 1; d >= 0; d--) {
329
+ const S = y[d];
330
+ i[S] && r.push([i[S], m, d]);
331
+ }
332
+ continue;
333
+ }
334
+ const f = {};
335
+ c[l] = f;
336
+ const p = Object.keys(i);
337
+ for (const y of p)
338
+ y !== "_meta" && r.push([i[y], f, y]);
339
+ }
340
+ return s.final;
106
341
  },
107
342
  updateShadowAtPath: (e, t, o) => {
108
- const n = p.has(`[${e}`) ? `[${e}` : e;
109
- let s = p.get(n);
343
+ const n = h.has(`[${e}`) ? `[${e}` : e;
344
+ let s = h.get(n);
110
345
  if (!s) return;
111
346
  let r = s;
112
- for (let c = 0; c < t.length - 1; c++)
113
- r[t[c]] || (r[t[c]] = {}), r = r[t[c]];
347
+ for (let l = 0; l < t.length - 1; l++)
348
+ r[t[l]] || (r[t[l]] = {}), r = r[t[l]];
114
349
  const i = t.length === 0 ? r : r[t[t.length - 1]];
115
- if (!i) {
116
- r[t[t.length - 1]] = h(o), a().notifyPathSubscribers([e, ...t].join("."), {
117
- type: "UPDATE",
118
- newValue: o
119
- });
120
- return;
121
- }
122
- function f(c, d) {
123
- if (typeof d != "object" || d === null || Array.isArray(d)) {
124
- const S = c._meta;
125
- for (const y in c)
126
- y !== "_meta" && delete c[y];
127
- const m = h(d);
128
- Object.assign(c, m), S && (c._meta = { ...S, ...c._meta || {} });
350
+ function c(l, f, p) {
351
+ if (typeof f != "object" || f === null || f instanceof Date) {
352
+ const m = l._meta || {};
353
+ for (const d in l)
354
+ d !== "_meta" && delete l[d];
355
+ l._meta = { ...m, value: f };
356
+ return;
357
+ }
358
+ if (Array.isArray(f)) {
359
+ l._meta || (l._meta = {}), l._meta.arrayKeys || (l._meta.arrayKeys = []);
360
+ const m = l._meta.arrayKeys, d = f, S = [];
361
+ for (let b = 0; b < d.length; b++) {
362
+ const g = d[b];
363
+ if (b < m.length) {
364
+ const w = m[b];
365
+ c(l[w], g, [
366
+ ...p,
367
+ w
368
+ ]), S.push(w);
369
+ } else {
370
+ const w = O(), K = a().getInitialOptions(e), v = {
371
+ stateKey: e,
372
+ path: [...p, "0"],
373
+ // Use '0' for array element schema lookup
374
+ schemas: {
375
+ zodV4: K?.validation?.zodSchemaV4,
376
+ zodV3: K?.validation?.zodSchemaV3
377
+ }
378
+ };
379
+ l[w] = _(
380
+ e,
381
+ g,
382
+ v
383
+ ), S.push(w);
384
+ }
385
+ }
386
+ m.length > d.length && m.slice(d.length).forEach((g) => {
387
+ delete l[g];
388
+ }), l._meta.arrayKeys = S;
129
389
  return;
130
390
  }
131
- const u = new Set(Object.keys(d));
132
- for (const S of u) {
133
- const m = d[S];
134
- c[S] ? f(c[S], m) : c[S] = h(m);
391
+ const y = new Set(Object.keys(f));
392
+ l._meta?.hasOwnProperty("value") && delete l._meta.value;
393
+ for (const m of y) {
394
+ const d = f[m];
395
+ if (l[m])
396
+ c(l[m], d, [
397
+ ...p,
398
+ m
399
+ ]);
400
+ else {
401
+ const S = a().getInitialOptions(e), b = {
402
+ stateKey: e,
403
+ path: [...p, m],
404
+ schemas: {
405
+ zodV4: S?.validation?.zodSchemaV4,
406
+ zodV3: S?.validation?.zodSchemaV3
407
+ }
408
+ };
409
+ l[m] = _(e, d, b);
410
+ }
135
411
  }
136
- for (const S in c)
137
- S === "_meta" || !Object.prototype.hasOwnProperty.call(c, S) || u.has(S) || delete c[S];
412
+ for (const m in l)
413
+ m === "_meta" || !Object.prototype.hasOwnProperty.call(l, m) || y.has(m) || delete l[m];
138
414
  }
139
- f(i, o), a().notifyPathSubscribers([e, ...t].join("."), {
415
+ i ? c(i, o, t) : r[t[t.length - 1]] = _(e, o), a().notifyPathSubscribers([e, ...t].join("."), {
140
416
  type: "UPDATE",
141
417
  newValue: o
142
418
  });
143
419
  },
144
- addItemsToArrayNode: (e, t, o, n) => {
145
- const s = p.has(`[${e}`) ? `[${e}` : e;
146
- let r = p.get(s);
147
- if (!r) {
420
+ addItemsToArrayNode: (e, t, o) => {
421
+ const n = h.has(`[${e}`) ? `[${e}` : e;
422
+ let s = h.get(n);
423
+ if (!s) {
148
424
  console.error("Root not found for state key:", e);
149
425
  return;
150
426
  }
151
- let i = r;
152
- for (const f of t)
153
- i[f] || (i[f] = {}), i = i[f];
154
- Object.assign(i, o), i._meta || (i._meta = {}), i._meta.arrayKeys = n;
427
+ let r = s;
428
+ for (const i of t)
429
+ r[i] || (r[i] = {}), r = r[i];
430
+ Object.assign(r, o);
155
431
  },
156
- insertShadowArrayElement: (e, t, o, n) => {
157
- const s = a().getShadowNode(e, t);
158
- if (!s?._meta?.arrayKeys) {
159
- console.error(
432
+ insertShadowArrayElement: (e, t, o, n, s) => {
433
+ const r = a().getShadowNode(e, t);
434
+ if (!r?._meta?.arrayKeys)
435
+ throw new Error(
160
436
  `Array not found at path: ${[e, ...t].join(".")}`
161
437
  );
162
- return;
163
- }
164
- const r = `id:${b()}`, i = { [r]: h(o) }, f = s._meta.arrayKeys, c = n !== void 0 && n >= 0 && n <= f.length ? n : f.length;
165
- c >= f.length ? f.push(r) : f.splice(c, 0, r), a().addItemsToArrayNode(e, t, i, f);
166
- const d = [e, ...t].join(".");
167
- a().notifyPathSubscribers(d, {
438
+ console.log("OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO");
439
+ const i = s || `${O()}`;
440
+ r[i] = _(e, o);
441
+ const c = r._meta.arrayKeys, l = n !== void 0 && n >= 0 && n <= c.length ? n : c.length;
442
+ l >= c.length ? c.push(i) : c.splice(l, 0, i);
443
+ const f = [e, ...t].join(".");
444
+ return a().notifyPathSubscribers(f, {
168
445
  type: "INSERT",
169
- path: d,
170
- itemKey: `${d}.${r}`,
171
- index: c
172
- });
446
+ path: f,
447
+ itemKey: `${f}.${i}`,
448
+ index: l
449
+ }), i;
173
450
  },
174
451
  insertManyShadowArrayElements: (e, t, o, n) => {
175
452
  if (!o || o.length === 0)
@@ -181,17 +458,17 @@ const E = w((l, a) => ({
181
458
  );
182
459
  return;
183
460
  }
184
- const r = {}, i = [];
185
- o.forEach((u) => {
186
- const S = `id:${b()}`;
187
- i.push(S), r[S] = h(u);
461
+ const r = [];
462
+ o.forEach((f) => {
463
+ const p = `${O()}`;
464
+ r.push(p), s[p] = _(e, f);
188
465
  });
189
- const f = s._meta.arrayKeys, c = n !== void 0 && n >= 0 && n <= f.length ? n : f.length;
190
- c >= f.length ? f.push(...i) : f.splice(c, 0, ...i), a().addItemsToArrayNode(e, t, r, f);
191
- const d = [e, ...t].join(".");
192
- a().notifyPathSubscribers(d, {
466
+ const i = s._meta.arrayKeys, c = n !== void 0 && n >= 0 && n <= i.length ? n : i.length;
467
+ c >= i.length ? i.push(...r) : i.splice(c, 0, ...r);
468
+ const l = [e, ...t].join(".");
469
+ a().notifyPathSubscribers(l, {
193
470
  type: "INSERT_MANY",
194
- path: d,
471
+ path: l,
195
472
  count: o.length,
196
473
  index: c
197
474
  });
@@ -205,11 +482,11 @@ const E = w((l, a) => ({
205
482
  const r = s._meta.arrayKeys, i = r.indexOf(n);
206
483
  if (i === -1) return;
207
484
  i === r.length - 1 ? r.pop() : i === 0 ? r.shift() : r.splice(i, 1), delete s[n];
208
- const f = [e, ...o].join(".");
209
- a().notifyPathSubscribers(f, {
485
+ const c = [e, ...o].join(".");
486
+ a().notifyPathSubscribers(c, {
210
487
  type: "REMOVE",
211
- path: f,
212
- itemKey: `${f}.${n}`
488
+ path: c,
489
+ itemKey: `${c}.${n}`
213
490
  });
214
491
  },
215
492
  registerComponent: (e, t, o) => {
@@ -231,25 +508,31 @@ const E = w((l, a) => ({
231
508
  if (r?.components) {
232
509
  const i = r.components.get(o);
233
510
  if (i) {
234
- const f = [e, ...t].join("."), c = new Set(i.paths);
235
- c.add(f);
236
- const d = { ...i, paths: c }, u = new Map(r.components);
237
- u.set(o, d), a().setShadowMetadata(e, [], { components: u });
511
+ const c = [e, ...t].join("."), l = new Set(i.paths);
512
+ l.add(c);
513
+ const f = { ...i, paths: l }, p = new Map(r.components);
514
+ p.set(o, f), a().setShadowMetadata(e, [], { components: p });
238
515
  }
239
516
  }
240
517
  },
241
518
  markAsDirty: (e, t, o = { bubble: !0 }) => {
242
- const n = (s) => a().getShadowNode(e, s)?._meta?.isDirty ? !0 : (a().setShadowMetadata(e, s, { isDirty: !0 }), !1);
243
- if (n(t), o.bubble) {
244
- let s = [...t];
245
- for (; s.length > 0 && (s.pop(), !n(s)); )
246
- ;
519
+ let n = a().getShadowNode(e, []);
520
+ if (!n) return;
521
+ let s = n;
522
+ for (const i of t)
523
+ if (s = s[i], !s) return;
524
+ if (s._meta || (s._meta = {}), s._meta.isDirty = !0, !o.bubble) return;
525
+ let r = n;
526
+ for (let i = 0; i < t.length; i++) {
527
+ if (r._meta?.isDirty)
528
+ return;
529
+ r._meta || (r._meta = {}), r._meta.isDirty = !0, r = r[t[i]];
247
530
  }
248
531
  },
249
532
  // Keep these in Zustand as they need React reactivity
250
533
  serverStateUpdates: /* @__PURE__ */ new Map(),
251
534
  setServerStateUpdate: (e, t) => {
252
- l((o) => ({
535
+ u((o) => ({
253
536
  serverStateUpdates: new Map(o.serverStateUpdates).set(
254
537
  e,
255
538
  t
@@ -282,7 +565,7 @@ const E = w((l, a) => ({
282
565
  return s ? s.indexOf(o) : -1;
283
566
  },
284
567
  setSelectedIndex: (e, t) => {
285
- l((o) => {
568
+ u((o) => {
286
569
  const n = new Map(o.selectedIndicesMap);
287
570
  return t === void 0 ? n.delete(e) : (n.has(e) && a().notifyPathSubscribers(n.get(e), {
288
571
  type: "THIS_UNSELECTED"
@@ -293,7 +576,7 @@ const E = w((l, a) => ({
293
576
  });
294
577
  },
295
578
  clearSelectedIndex: ({ arrayKey: e }) => {
296
- l((t) => {
579
+ u((t) => {
297
580
  const o = new Map(t.selectedIndicesMap), n = o.get(e);
298
581
  return n && a().notifyPathSubscribers(n, {
299
582
  type: "CLEAR_SELECTION"
@@ -306,7 +589,7 @@ const E = w((l, a) => ({
306
589
  });
307
590
  },
308
591
  clearSelectedIndexesForState: (e) => {
309
- l((t) => {
592
+ u((t) => {
310
593
  const o = new Map(t.selectedIndicesMap);
311
594
  let n = !1;
312
595
  for (const s of o.keys())
@@ -318,7 +601,7 @@ const E = w((l, a) => ({
318
601
  stateLog: /* @__PURE__ */ new Map(),
319
602
  initialStateGlobal: {},
320
603
  addStateLog: (e) => {
321
- !e || e.length === 0 || l((t) => {
604
+ !e || e.length === 0 || u((t) => {
322
605
  const o = new Map(t.stateLog), n = /* @__PURE__ */ new Map();
323
606
  for (const s of e) {
324
607
  const r = n.get(s.stateKey) || [];
@@ -326,8 +609,8 @@ const E = w((l, a) => ({
326
609
  }
327
610
  for (const [s, r] of n.entries()) {
328
611
  const i = new Map(o.get(s));
329
- for (const f of r)
330
- i.set(JSON.stringify(f.path), { ...f });
612
+ for (const c of r)
613
+ i.set(JSON.stringify(c.path), { ...c });
331
614
  o.set(s, i);
332
615
  }
333
616
  return { stateLog: o };
@@ -335,26 +618,27 @@ const E = w((l, a) => ({
335
618
  },
336
619
  getInitialOptions: (e) => a().initialStateOptions[e],
337
620
  setInitialStateOptions: (e, t) => {
338
- l((o) => ({
621
+ u((o) => ({
339
622
  initialStateOptions: { ...o.initialStateOptions, [e]: t }
340
623
  }));
341
624
  },
342
625
  updateInitialStateGlobal: (e, t) => {
343
- l((o) => ({
626
+ u((o) => ({
344
627
  initialStateGlobal: { ...o.initialStateGlobal, [e]: t }
345
628
  }));
346
629
  },
347
630
  syncInfoStore: /* @__PURE__ */ new Map(),
348
- setSyncInfo: (e, t) => l((o) => {
631
+ setSyncInfo: (e, t) => u((o) => {
349
632
  const n = new Map(o.syncInfoStore);
350
633
  return n.set(e, t), { syncInfoStore: n };
351
634
  }),
352
635
  getSyncInfo: (e) => a().syncInfoStore.get(e) || null
353
636
  }));
354
637
  export {
355
- h as buildShadowNode,
356
- _ as formRefStore,
357
- b as generateId,
358
- E as getGlobalStore
638
+ _ as buildShadowNode,
639
+ O as generateId,
640
+ $ as getGlobalStore,
641
+ h as shadowStateStore,
642
+ N as updateShadowTypeInfo
359
643
  };
360
644
  //# sourceMappingURL=store.js.map