cogsbox-state 0.5.471 → 0.5.472

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