cogsbox-state 0.5.460 → 0.5.461

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.
@@ -22,11 +22,11 @@ function Mt({
22
22
  initialOptionsPart: m
23
23
  }) {
24
24
  const g = ot(t) || {}, y = m[t] || {}, I = e.getState().setInitialStateOptions, T = { ...y, ...g };
25
- let i = !1;
25
+ let s = !1;
26
26
  if (a)
27
- for (const f in a)
28
- T.hasOwnProperty(f) ? (f == "localStorage" && a[f] && T[f].key !== a[f]?.key && (i = !0, T[f] = a[f]), f == "defaultState" && a[f] && T[f] !== a[f] && !ct(T[f], a[f]) && (i = !0, T[f] = a[f])) : (i = !0, T[f] = a[f]);
29
- T.syncOptions && (!a || !a.hasOwnProperty("syncOptions")) && (i = !0), i && I(t, T);
27
+ for (const l in a)
28
+ T.hasOwnProperty(l) ? (l == "localStorage" && a[l] && T[l].key !== a[l]?.key && (s = !0, T[l] = a[l]), l == "defaultState" && a[l] && T[l] !== a[l] && !ct(T[l], a[l]) && (s = !0, T[l] = a[l])) : (s = !0, T[l] = a[l]);
29
+ T.syncOptions && (!a || !a.hasOwnProperty("syncOptions")) && (s = !0), s && I(t, T);
30
30
  }
31
31
  function se(t, { formElements: a, validation: m }) {
32
32
  return { initialState: t, formElements: a, validation: m };
@@ -35,52 +35,55 @@ const Ft = (t, a) => {
35
35
  let m = t;
36
36
  console.log("optsc", a?.__useSync);
37
37
  const [g, y] = Rt(m);
38
- a?.__fromSyncSchema && a?.__syncNotifications && e.getState().setInitialStateOptions("__notifications", a.__syncNotifications), a?.__fromSyncSchema && a?.__apiParamsMap && e.getState().setInitialStateOptions("__apiParamsMap", a.__apiParamsMap), Object.keys(g).forEach((i) => {
39
- let f = y[i] || {};
38
+ a?.__fromSyncSchema && a?.__syncNotifications && e.getState().setInitialStateOptions("__notifications", a.__syncNotifications), a?.__fromSyncSchema && a?.__apiParamsMap && e.getState().setInitialStateOptions("__apiParamsMap", a.__apiParamsMap), Object.keys(g).forEach((s) => {
39
+ let l = y[s] || {};
40
40
  const P = {
41
- ...f
41
+ ...l
42
42
  };
43
43
  if (a?.formElements && (P.formElements = {
44
44
  ...a.formElements,
45
- ...f.formElements || {}
45
+ ...l.formElements || {}
46
46
  }), a?.validation && (P.validation = {
47
47
  ...a.validation,
48
- ...f.validation || {}
49
- }, a.validation.key && !f.validation?.key && (P.validation.key = `${a.validation.key}.${i}`)), Object.keys(P).length > 0) {
50
- const b = ot(i);
51
- b ? e.getState().setInitialStateOptions(i, {
48
+ ...l.validation || {}
49
+ }, a.validation.key && !l.validation?.key && (P.validation.key = `${a.validation.key}.${s}`)), a?.__syncSchemas?.[s]?.schemas?.validation && (P.validation = {
50
+ zodSchemaV4: a.__syncSchemas[s].schemas.validation,
51
+ ...l.validation
52
+ }), Object.keys(P).length > 0) {
53
+ const b = ot(s);
54
+ b ? e.getState().setInitialStateOptions(s, {
52
55
  ...b,
53
56
  ...P
54
- }) : e.getState().setInitialStateOptions(i, P);
57
+ }) : e.getState().setInitialStateOptions(s, P);
55
58
  }
56
- }), Object.keys(g).forEach((i) => {
57
- e.getState().initializeShadowState(i, g[i]);
59
+ }), Object.keys(g).forEach((s) => {
60
+ e.getState().initializeShadowState(s, g[s]);
58
61
  });
59
- const I = (i, f) => {
60
- const [P] = at(f?.componentId ?? nt());
62
+ const I = (s, l) => {
63
+ const [P] = at(l?.componentId ?? nt());
61
64
  Mt({
62
- stateKey: i,
63
- options: f,
65
+ stateKey: s,
66
+ options: l,
64
67
  initialOptionsPart: y
65
68
  });
66
- const b = e.getState().getShadowValue(i) || g[i], n = f?.modifyState ? f.modifyState(b) : b;
67
- return xt(n, {
68
- stateKey: i,
69
- syncUpdate: f?.syncUpdate,
69
+ const b = e.getState().getShadowValue(s) || g[s], o = l?.modifyState ? l.modifyState(b) : b;
70
+ return xt(o, {
71
+ stateKey: s,
72
+ syncUpdate: l?.syncUpdate,
70
73
  componentId: P,
71
- localStorage: f?.localStorage,
72
- middleware: f?.middleware,
73
- reactiveType: f?.reactiveType,
74
- reactiveDeps: f?.reactiveDeps,
75
- defaultState: f?.defaultState,
76
- dependencies: f?.dependencies,
77
- serverState: f?.serverState,
78
- syncOptions: f?.syncOptions,
74
+ localStorage: l?.localStorage,
75
+ middleware: l?.middleware,
76
+ reactiveType: l?.reactiveType,
77
+ reactiveDeps: l?.reactiveDeps,
78
+ defaultState: l?.defaultState,
79
+ dependencies: l?.dependencies,
80
+ serverState: l?.serverState,
81
+ syncOptions: l?.syncOptions,
79
82
  __useSync: a?.__useSync
80
83
  });
81
84
  };
82
- function T(i, f) {
83
- Mt({ stateKey: i, options: f, initialOptionsPart: y }), f.localStorage && Ht(i, f), vt(i);
85
+ function T(s, l) {
86
+ Mt({ stateKey: s, options: l, initialOptionsPart: y }), l.localStorage && Ht(s, l), vt(s);
84
87
  }
85
88
  return { useCogsState: I, setCogsOptions: T };
86
89
  };
@@ -94,7 +97,8 @@ function ie(t, a) {
94
97
  __fromSyncSchema: !0,
95
98
  __syncNotifications: t.notifications,
96
99
  __apiParamsMap: y,
97
- __useSync: a
100
+ __useSync: a,
101
+ __syncSchemas: m
98
102
  });
99
103
  }
100
104
  const {
@@ -111,17 +115,17 @@ const {
111
115
  const I = rt(m?.localStorage?.key) ? m.localStorage?.key(t) : m?.localStorage?.key;
112
116
  if (I && g) {
113
117
  const T = `${g}-${a}-${I}`;
114
- let i;
118
+ let s;
115
119
  try {
116
- i = gt(T)?.lastSyncedWithServer;
120
+ s = gt(T)?.lastSyncedWithServer;
117
121
  } catch {
118
122
  }
119
- const f = e.getState().getShadowMetadata(a, []), P = {
123
+ const l = e.getState().getShadowMetadata(a, []), P = {
120
124
  state: t,
121
125
  lastUpdated: Date.now(),
122
- lastSyncedWithServer: i,
123
- stateSource: f?.stateSource,
124
- baseServerState: f?.baseServerState
126
+ lastSyncedWithServer: s,
127
+ stateSource: l?.stateSource,
128
+ baseServerState: l?.baseServerState
125
129
  }, b = Lt.serialize(P);
126
130
  window.localStorage.setItem(
127
131
  T,
@@ -173,8 +177,8 @@ function yt(t, a, m, g) {
173
177
  lastServerSync: g || Date.now()
174
178
  }), Array.isArray(m)) {
175
179
  const T = y.getShadowMetadata(t, a);
176
- T?.arrayKeys && T.arrayKeys.forEach((i, f) => {
177
- const P = i.split(".").slice(1), b = m[f];
180
+ T?.arrayKeys && T.arrayKeys.forEach((s, l) => {
181
+ const P = s.split(".").slice(1), b = m[l];
178
182
  b !== void 0 && yt(
179
183
  t,
180
184
  P,
@@ -183,8 +187,8 @@ function yt(t, a, m, g) {
183
187
  );
184
188
  });
185
189
  } else m && typeof m == "object" && m.constructor === Object && Object.keys(m).forEach((T) => {
186
- const i = [...a, T], f = m[T];
187
- yt(t, i, f, g);
190
+ const s = [...a, T], l = m[T];
191
+ yt(t, s, l, g);
188
192
  });
189
193
  }
190
194
  function xt(t, {
@@ -194,11 +198,11 @@ function xt(t, {
194
198
  reactiveDeps: y,
195
199
  reactiveType: I,
196
200
  componentId: T,
197
- defaultState: i,
198
- syncUpdate: f,
201
+ defaultState: s,
202
+ syncUpdate: l,
199
203
  dependencies: P,
200
204
  serverState: b,
201
- __useSync: n,
205
+ __useSync: o,
202
206
  syncOptions: h
203
207
  } = {}) {
204
208
  const [_, x] = at({}), { sessionId: R } = _t();
@@ -207,28 +211,28 @@ function xt(t, {
207
211
  null
208
212
  );
209
213
  Y.current = ot(S) ?? null, et(() => {
210
- if (f && f.stateKey === S && f.path?.[0]) {
211
- const u = `${f.stateKey}:${f.path.join(".")}`;
212
- e.getState().setSyncInfo(u, {
213
- timeStamp: f.timeStamp,
214
- userId: f.userId
214
+ if (l && l.stateKey === S && l.path?.[0]) {
215
+ const d = `${l.stateKey}:${l.path.join(".")}`;
216
+ e.getState().setSyncInfo(d, {
217
+ timeStamp: l.timeStamp,
218
+ userId: l.userId
215
219
  });
216
220
  }
217
- }, [f]);
221
+ }, [l]);
218
222
  const tt = lt(
219
- (u) => {
220
- const d = u ? { ...ot(S), ...u } : ot(S), k = d?.defaultState || i || t;
221
- if (d?.serverState?.status === "success" && d?.serverState?.data !== void 0)
223
+ (d) => {
224
+ const f = d ? { ...ot(S), ...d } : ot(S), D = f?.defaultState || s || t;
225
+ if (f?.serverState?.status === "success" && f?.serverState?.data !== void 0)
222
226
  return {
223
- value: d.serverState.data,
227
+ value: f.serverState.data,
224
228
  source: "server",
225
- timestamp: d.serverState.timestamp || Date.now()
229
+ timestamp: f.serverState.timestamp || Date.now()
226
230
  };
227
- if (d?.localStorage?.key && R) {
228
- const D = rt(d.localStorage.key) ? d.localStorage.key(k) : d.localStorage.key, V = gt(
229
- `${R}-${S}-${D}`
231
+ if (f?.localStorage?.key && R) {
232
+ const k = rt(f.localStorage.key) ? f.localStorage.key(D) : f.localStorage.key, V = gt(
233
+ `${R}-${S}-${k}`
230
234
  );
231
- if (V && V.lastUpdated > (d?.serverState?.timestamp || 0))
235
+ if (V && V.lastUpdated > (f?.serverState?.timestamp || 0))
232
236
  return {
233
237
  value: V.state,
234
238
  source: "localStorage",
@@ -236,24 +240,24 @@ function xt(t, {
236
240
  };
237
241
  }
238
242
  return {
239
- value: k || t,
243
+ value: D || t,
240
244
  source: "default",
241
245
  timestamp: Date.now()
242
246
  };
243
247
  },
244
- [S, i, t, R]
248
+ [S, s, t, R]
245
249
  );
246
250
  et(() => {
247
251
  e.getState().setServerStateUpdate(S, b);
248
252
  }, [b, S]), et(() => e.getState().subscribeToPath(S, (c) => {
249
253
  if (c?.type === "SERVER_STATE_UPDATE") {
250
- const d = c.serverState;
251
- if (console.log("SERVER_STATE_UPDATE", c), d?.status === "success" && d.data !== void 0) {
252
- mt(S, { serverState: d });
253
- const M = typeof d.merge == "object" ? d.merge : d.merge === !0 ? {} : null, D = e.getState().getShadowValue(S), V = d.data;
254
- if (M && Array.isArray(D) && Array.isArray(V)) {
254
+ const f = c.serverState;
255
+ if (console.log("SERVER_STATE_UPDATE", c), f?.status === "success" && f.data !== void 0) {
256
+ mt(S, { serverState: f });
257
+ const M = typeof f.merge == "object" ? f.merge : f.merge === !0 ? {} : null, k = e.getState().getShadowValue(S), V = f.data;
258
+ if (M && Array.isArray(k) && Array.isArray(V)) {
255
259
  const j = M.key, L = new Set(
256
- D.map((Z) => Z[j])
260
+ k.map((Z) => Z[j])
257
261
  ), G = V.filter((Z) => !L.has(Z[j]));
258
262
  G.length > 0 && G.forEach((Z) => {
259
263
  e.getState().insertShadowArrayElement(S, [], Z);
@@ -265,7 +269,7 @@ function xt(t, {
265
269
  e.getState().setShadowMetadata(S, O, {
266
270
  isDirty: !1,
267
271
  stateSource: "server",
268
- lastServerSync: d.timestamp || Date.now()
272
+ lastServerSync: f.timestamp || Date.now()
269
273
  });
270
274
  const v = e.getState().getShadowValue(H);
271
275
  v && typeof v == "object" && !Array.isArray(v) && Object.keys(v).forEach((w) => {
@@ -273,7 +277,7 @@ function xt(t, {
273
277
  e.getState().setShadowMetadata(S, E, {
274
278
  isDirty: !1,
275
279
  stateSource: "server",
276
- lastServerSync: d.timestamp || Date.now()
280
+ lastServerSync: f.timestamp || Date.now()
277
281
  });
278
282
  });
279
283
  }
@@ -284,44 +288,44 @@ function xt(t, {
284
288
  S,
285
289
  [],
286
290
  V,
287
- d.timestamp
291
+ f.timestamp
288
292
  );
289
293
  const $ = e.getState().getShadowMetadata(S, []);
290
294
  e.getState().setShadowMetadata(S, [], {
291
295
  ...$,
292
296
  stateSource: "server",
293
- lastServerSync: d.timestamp || Date.now(),
297
+ lastServerSync: f.timestamp || Date.now(),
294
298
  isDirty: !1
295
299
  });
296
300
  }
297
301
  }
298
302
  }), [S, tt]), et(() => {
299
- const u = e.getState().getShadowMetadata(S, []);
300
- if (u && u.stateSource)
303
+ const d = e.getState().getShadowMetadata(S, []);
304
+ if (d && d.stateSource)
301
305
  return;
302
306
  const c = ot(S);
303
- if (c?.defaultState !== void 0 || i !== void 0) {
304
- const d = c?.defaultState || i;
307
+ if (c?.defaultState !== void 0 || s !== void 0) {
308
+ const f = c?.defaultState || s;
305
309
  c?.defaultState || mt(S, {
306
- defaultState: d
310
+ defaultState: f
307
311
  });
308
- const { value: k, source: M, timestamp: D } = tt();
309
- e.getState().initializeShadowState(S, k), e.getState().setShadowMetadata(S, [], {
312
+ const { value: D, source: M, timestamp: k } = tt();
313
+ e.getState().initializeShadowState(S, D), e.getState().setShadowMetadata(S, [], {
310
314
  stateSource: M,
311
- lastServerSync: M === "server" ? D : void 0,
315
+ lastServerSync: M === "server" ? k : void 0,
312
316
  isDirty: !1,
313
- baseServerState: M === "server" ? k : void 0
317
+ baseServerState: M === "server" ? D : void 0
314
318
  }), vt(S);
315
319
  }
316
320
  }, [S, ...P || []]), dt(() => {
317
321
  B && mt(S, {
318
322
  formElements: g,
319
- defaultState: i,
323
+ defaultState: s,
320
324
  localStorage: m,
321
325
  middleware: Y.current?.middleware
322
326
  });
323
- const u = `${S}////${p.current}`, c = e.getState().getShadowMetadata(S, []), d = c?.components || /* @__PURE__ */ new Map();
324
- return d.set(u, {
327
+ const d = `${S}////${p.current}`, c = e.getState().getShadowMetadata(S, []), f = c?.components || /* @__PURE__ */ new Map();
328
+ return f.set(d, {
325
329
  forceUpdate: () => x({}),
326
330
  reactiveType: I ?? ["component", "deps"],
327
331
  paths: /* @__PURE__ */ new Set(),
@@ -330,31 +334,31 @@ function xt(t, {
330
334
  prevDeps: y ? y(e.getState().getShadowValue(S)) : []
331
335
  }), e.getState().setShadowMetadata(S, [], {
332
336
  ...c,
333
- components: d
337
+ components: f
334
338
  }), x({}), () => {
335
- const k = e.getState().getShadowMetadata(S, []), M = k?.components?.get(u);
336
- M?.paths && M.paths.forEach((D) => {
337
- const $ = D.split(".").slice(1), j = e.getState().getShadowMetadata(S, $);
339
+ const D = e.getState().getShadowMetadata(S, []), M = D?.components?.get(d);
340
+ M?.paths && M.paths.forEach((k) => {
341
+ const $ = k.split(".").slice(1), j = e.getState().getShadowMetadata(S, $);
338
342
  j?.pathComponents && j.pathComponents.size === 0 && (delete j.pathComponents, e.getState().setShadowMetadata(S, $, j));
339
- }), k?.components && e.getState().setShadowMetadata(S, [], k);
343
+ }), D?.components && e.getState().setShadowMetadata(S, [], D);
340
344
  };
341
345
  }, []);
342
- const Q = z(null), r = (u, c, d) => {
343
- const k = [S, ...c].join(".");
346
+ const Q = z(null), r = (d, c, f) => {
347
+ const D = [S, ...c].join(".");
344
348
  if (Array.isArray(c)) {
345
349
  const O = `${S}-${c.join(".")}`;
346
350
  q.current.add(O);
347
351
  }
348
- const M = e.getState(), D = M.getShadowMetadata(S, c), V = M.getShadowValue(k), $ = d.updateType === "insert" && rt(u) ? u({ state: V, uuid: nt() }) : rt(u) ? u(V) : u, L = {
352
+ const M = e.getState(), k = M.getShadowMetadata(S, c), V = M.getShadowValue(D), $ = f.updateType === "insert" && rt(d) ? d({ state: V, uuid: nt() }) : rt(d) ? d(V) : d, L = {
349
353
  timeStamp: Date.now(),
350
354
  stateKey: S,
351
355
  path: c,
352
- updateType: d.updateType,
356
+ updateType: f.updateType,
353
357
  status: "new",
354
358
  oldValue: V,
355
359
  newValue: $
356
360
  };
357
- switch (d.updateType) {
361
+ switch (f.updateType) {
358
362
  case "insert": {
359
363
  M.insertShadowArrayElement(S, c, L.newValue), M.markAsDirty(S, c, { bubble: !0 });
360
364
  const O = M.getShadowMetadata(S, c);
@@ -377,9 +381,9 @@ function xt(t, {
377
381
  break;
378
382
  }
379
383
  }
380
- if (d.sync !== !1 && Q.current && Q.current.connected && Q.current.updateState({ operation: L }), D?.signals && D.signals.length > 0) {
381
- const O = d.updateType === "cut" ? null : $;
382
- D.signals.forEach(({ parentId: v, position: w, effect: E }) => {
384
+ if (f.sync !== !1 && Q.current && Q.current.connected && Q.current.updateState({ operation: L }), k?.signals && k.signals.length > 0) {
385
+ const O = f.updateType === "cut" ? null : $;
386
+ k.signals.forEach(({ parentId: v, position: w, effect: E }) => {
383
387
  const A = document.querySelector(`[data-parent-id="${v}"]`);
384
388
  if (A) {
385
389
  const C = Array.from(A.childNodes);
@@ -399,12 +403,12 @@ function xt(t, {
399
403
  }
400
404
  });
401
405
  }
402
- if (d.updateType === "insert" && D?.mapWrappers && D.mapWrappers.length > 0) {
406
+ if (f.updateType === "insert" && k?.mapWrappers && k.mapWrappers.length > 0) {
403
407
  const O = M.getShadowMetadata(S, c)?.arrayKeys || [], v = O[O.length - 1], w = M.getShadowValue(v), E = M.getShadowValue(
404
408
  [S, ...c].join(".")
405
409
  );
406
410
  if (!v || w === void 0) return;
407
- D.mapWrappers.forEach((A) => {
411
+ k.mapWrappers.forEach((A) => {
408
412
  let C = !0, U = -1;
409
413
  if (A.meta?.transforms && A.meta.transforms.length > 0) {
410
414
  for (const N of A.meta.transforms)
@@ -441,7 +445,7 @@ function xt(t, {
441
445
  N,
442
446
  J[U]
443
447
  ) : A.containerRef.appendChild(N);
444
- const F = Vt(N), K = nt(), st = v.split(".").slice(1), Dt = A.rebuildStateShape({
448
+ const F = Vt(N), K = nt(), st = v.split(".").slice(1), kt = A.rebuildStateShape({
445
449
  path: A.path,
446
450
  currentState: E,
447
451
  componentId: A.componentId,
@@ -453,7 +457,7 @@ function xt(t, {
453
457
  itemComponentId: K,
454
458
  itemPath: st,
455
459
  localIndex: U,
456
- arraySetter: Dt,
460
+ arraySetter: kt,
457
461
  rebuildStateShape: A.rebuildStateShape,
458
462
  renderFn: A.mapFn
459
463
  })
@@ -461,12 +465,12 @@ function xt(t, {
461
465
  }
462
466
  });
463
467
  }
464
- if (d.updateType === "cut") {
468
+ if (f.updateType === "cut") {
465
469
  const O = c.slice(0, -1), v = M.getShadowMetadata(S, O);
466
470
  v?.mapWrappers && v.mapWrappers.length > 0 && v.mapWrappers.forEach((w) => {
467
471
  if (w.containerRef && w.containerRef.isConnected) {
468
472
  const E = w.containerRef.querySelector(
469
- `[data-item-path="${k}"]`
473
+ `[data-item-path="${D}"]`
470
474
  );
471
475
  E && E.remove();
472
476
  }
@@ -475,7 +479,7 @@ function xt(t, {
475
479
  const Z = e.getState().getShadowValue(S), X = e.getState().getShadowMetadata(S, []), H = /* @__PURE__ */ new Set();
476
480
  if (!X?.components)
477
481
  return Z;
478
- if (d.updateType === "update") {
482
+ if (f.updateType === "update") {
479
483
  let O = [...c];
480
484
  for (; ; ) {
481
485
  const v = M.getShadowMetadata(S, O);
@@ -497,8 +501,8 @@ function xt(t, {
497
501
  N && ((Array.isArray(N.reactiveType) ? N.reactiveType : [N.reactiveType || "component"]).includes("none") || (N.forceUpdate(), H.add(U)));
498
502
  });
499
503
  });
500
- } else if (d.updateType === "insert" || d.updateType === "cut") {
501
- const O = d.updateType === "insert" ? c : c.slice(0, -1), v = M.getShadowMetadata(S, O);
504
+ } else if (f.updateType === "insert" || f.updateType === "cut") {
505
+ const O = f.updateType === "insert" ? c : c.slice(0, -1), v = M.getShadowMetadata(S, O);
502
506
  if (v?.signals && v.signals.length > 0) {
503
507
  const w = [S, ...O].join("."), E = M.getShadowValue(w);
504
508
  v.signals.forEach(({ parentId: A, position: C, effect: U }) => {
@@ -560,16 +564,16 @@ function xt(t, {
560
564
  }), Z;
561
565
  };
562
566
  e.getState().initialStateGlobal[S] || Ct(S, t);
563
- const o = St(() => Pt(
567
+ const n = St(() => Pt(
564
568
  S,
565
569
  r,
566
570
  p.current,
567
571
  R
568
- ), [S, R]), s = n, l = Y.current?.syncOptions;
569
- return s && (Q.current = s(
570
- o,
571
- l ?? {}
572
- )), o;
572
+ ), [S, R]), i = o, u = Y.current?.syncOptions;
573
+ return i && (Q.current = i(
574
+ n,
575
+ u ?? {}
576
+ )), n;
573
577
  }
574
578
  function Bt(t) {
575
579
  return !t || t.length === 0 ? "" : t.map(
@@ -589,26 +593,26 @@ const pt = (t, a, m) => {
589
593
  }));
590
594
  for (const I of m)
591
595
  I.type === "filter" ? y = y.filter(
592
- ({ value: T }, i) => I.fn(T, i)
593
- ) : I.type === "sort" && y.sort((T, i) => I.fn(T.value, i.value));
596
+ ({ value: T }, s) => I.fn(T, s)
597
+ ) : I.type === "sort" && y.sort((T, s) => I.fn(T.value, s.value));
594
598
  return y.map(({ key: I }) => I);
595
599
  }, Tt = (t, a, m) => {
596
- const g = `${t}////${a}`, { addPathComponent: y, getShadowMetadata: I } = e.getState(), i = I(t, [])?.components?.get(g);
597
- !i || i.reactiveType === "none" || !(Array.isArray(i.reactiveType) ? i.reactiveType : [i.reactiveType]).includes("component") || y(t, m, g);
600
+ const g = `${t}////${a}`, { addPathComponent: y, getShadowMetadata: I } = e.getState(), s = I(t, [])?.components?.get(g);
601
+ !s || s.reactiveType === "none" || !(Array.isArray(s.reactiveType) ? s.reactiveType : [s.reactiveType]).includes("component") || y(t, m, g);
598
602
  }, ft = (t, a, m) => {
599
603
  const g = e.getState(), y = g.getShadowMetadata(t, []), I = /* @__PURE__ */ new Set();
600
- y?.components && y.components.forEach((i, f) => {
601
- (Array.isArray(i.reactiveType) ? i.reactiveType : [i.reactiveType || "component"]).includes("all") && (i.forceUpdate(), I.add(f));
602
- }), g.getShadowMetadata(t, [...a, "getSelected"])?.pathComponents?.forEach((i) => {
603
- y?.components?.get(i)?.forceUpdate();
604
+ y?.components && y.components.forEach((s, l) => {
605
+ (Array.isArray(s.reactiveType) ? s.reactiveType : [s.reactiveType || "component"]).includes("all") && (s.forceUpdate(), I.add(l));
606
+ }), g.getShadowMetadata(t, [...a, "getSelected"])?.pathComponents?.forEach((s) => {
607
+ y?.components?.get(s)?.forceUpdate();
604
608
  });
605
609
  const T = g.getShadowMetadata(t, a);
606
- for (let i of T?.arrayKeys || []) {
607
- const f = i + ".selected", P = g.getShadowMetadata(
610
+ for (let s of T?.arrayKeys || []) {
611
+ const l = s + ".selected", P = g.getShadowMetadata(
608
612
  t,
609
- f.split(".").slice(1)
613
+ l.split(".").slice(1)
610
614
  );
611
- i == m && P?.pathComponents?.forEach((b) => {
615
+ s == m && P?.pathComponents?.forEach((b) => {
612
616
  y?.components?.get(b)?.forceUpdate();
613
617
  });
614
618
  }
@@ -617,120 +621,120 @@ function Pt(t, a, m, g) {
617
621
  const y = /* @__PURE__ */ new Map();
618
622
  let I = 0;
619
623
  const T = (b) => {
620
- const n = b.join(".");
624
+ const o = b.join(".");
621
625
  for (const [h] of y)
622
- (h === n || h.startsWith(n + ".")) && y.delete(h);
626
+ (h === o || h.startsWith(o + ".")) && y.delete(h);
623
627
  I++;
624
628
  };
625
- function i({
629
+ function s({
626
630
  currentState: b,
627
- path: n = [],
631
+ path: o = [],
628
632
  meta: h,
629
633
  componentId: _
630
634
  }) {
631
- const x = n.map(String).join("."), R = [t, ...n].join(".");
635
+ const x = o.map(String).join("."), R = [t, ...o].join(".");
632
636
  b = e.getState().getShadowValue(R, h?.validIds);
633
637
  const B = function() {
634
- return e().getShadowValue(t, n);
638
+ return e().getShadowValue(t, o);
635
639
  }, S = {
636
640
  apply(q, p, Y) {
637
641
  },
638
642
  get(q, p) {
639
643
  if (p === "_rebuildStateShape")
640
- return i;
641
- if (Object.getOwnPropertyNames(f).includes(p) && n.length === 0)
642
- return f[p];
644
+ return s;
645
+ if (Object.getOwnPropertyNames(l).includes(p) && o.length === 0)
646
+ return l[p];
643
647
  if (p === "getDifferences")
644
648
  return () => {
645
- const r = e.getState().getShadowMetadata(t, []), o = e.getState().getShadowValue(t);
646
- let s;
647
- return r?.stateSource === "server" && r.baseServerState ? s = r.baseServerState : s = e.getState().initialStateGlobal[t], Et(o, s);
649
+ const r = e.getState().getShadowMetadata(t, []), n = e.getState().getShadowValue(t);
650
+ let i;
651
+ return r?.stateSource === "server" && r.baseServerState ? i = r.baseServerState : i = e.getState().initialStateGlobal[t], Et(n, i);
648
652
  };
649
- if (p === "sync" && n.length === 0)
653
+ if (p === "sync" && o.length === 0)
650
654
  return async function() {
651
- const r = e.getState().getInitialOptions(t), o = r?.sync;
652
- if (!o)
655
+ const r = e.getState().getInitialOptions(t), n = r?.sync;
656
+ if (!n)
653
657
  return console.error(`No mutation defined for state key "${t}"`), { success: !1, error: "No mutation defined" };
654
- const s = e.getState().getShadowValue(t, []), l = r?.validation?.key;
658
+ const i = e.getState().getShadowValue(t, []), u = r?.validation?.key;
655
659
  try {
656
- const u = await o.action(s);
657
- if (u && !u.success && u.errors, u?.success) {
660
+ const d = await n.action(i);
661
+ if (d && !d.success && d.errors, d?.success) {
658
662
  const c = e.getState().getShadowMetadata(t, []);
659
663
  e.getState().setShadowMetadata(t, [], {
660
664
  ...c,
661
665
  isDirty: !1,
662
666
  lastServerSync: Date.now(),
663
667
  stateSource: "server",
664
- baseServerState: s
668
+ baseServerState: i
665
669
  // Update base server state
666
- }), o.onSuccess && o.onSuccess(u.data);
667
- } else !u?.success && o.onError && o.onError(u.error);
668
- return u;
669
- } catch (u) {
670
- return o.onError && o.onError(u), { success: !1, error: u };
670
+ }), n.onSuccess && n.onSuccess(d.data);
671
+ } else !d?.success && n.onError && n.onError(d.error);
672
+ return d;
673
+ } catch (d) {
674
+ return n.onError && n.onError(d), { success: !1, error: d };
671
675
  }
672
676
  };
673
677
  if (p === "_status" || p === "getStatus") {
674
678
  const r = () => {
675
- const o = e.getState().getShadowMetadata(t, n), s = e.getState().getShadowValue(R);
676
- return o?.isDirty === !0 ? "dirty" : o?.isDirty === !1 || o?.stateSource === "server" ? "synced" : o?.stateSource === "localStorage" ? "restored" : o?.stateSource === "default" ? "fresh" : e.getState().getShadowMetadata(t, [])?.stateSource === "server" && !o?.isDirty ? "synced" : s !== void 0 && !o ? "fresh" : "unknown";
679
+ const n = e.getState().getShadowMetadata(t, o), i = e.getState().getShadowValue(R);
680
+ return n?.isDirty === !0 ? "dirty" : n?.isDirty === !1 || n?.stateSource === "server" ? "synced" : n?.stateSource === "localStorage" ? "restored" : n?.stateSource === "default" ? "fresh" : e.getState().getShadowMetadata(t, [])?.stateSource === "server" && !n?.isDirty ? "synced" : i !== void 0 && !n ? "fresh" : "unknown";
677
681
  };
678
682
  return p === "_status" ? r() : r;
679
683
  }
680
684
  if (p === "removeStorage")
681
685
  return () => {
682
- const r = e.getState().initialStateGlobal[t], o = ot(t), s = rt(o?.localStorage?.key) ? o.localStorage.key(r) : o?.localStorage?.key, l = `${g}-${t}-${s}`;
683
- l && localStorage.removeItem(l);
686
+ const r = e.getState().initialStateGlobal[t], n = ot(t), i = rt(n?.localStorage?.key) ? n.localStorage.key(r) : n?.localStorage?.key, u = `${g}-${t}-${i}`;
687
+ u && localStorage.removeItem(u);
684
688
  };
685
689
  if (p === "showValidationErrors")
686
690
  return () => {
687
- const r = e.getState().getShadowMetadata(t, n);
691
+ const r = e.getState().getShadowMetadata(t, o);
688
692
  return r?.validation?.status === "VALIDATION_FAILED" && r.validation.message ? [r.validation.message] : [];
689
693
  };
690
694
  if (Array.isArray(b)) {
691
695
  if (p === "getSelected")
692
696
  return () => {
693
- const r = t + "." + n.join(".");
697
+ const r = t + "." + o.join(".");
694
698
  Tt(t, _, [
695
- ...n,
699
+ ...o,
696
700
  "getSelected"
697
701
  ]);
698
- const o = e.getState().selectedIndicesMap;
699
- if (!o || !o.has(r))
702
+ const n = e.getState().selectedIndicesMap;
703
+ if (!n || !n.has(r))
700
704
  return;
701
- const s = o.get(r);
702
- if (h?.validIds && !h.validIds.includes(s))
705
+ const i = n.get(r);
706
+ if (h?.validIds && !h.validIds.includes(i))
703
707
  return;
704
- const l = e.getState().getShadowValue(s);
705
- if (l)
706
- return i({
707
- currentState: l,
708
- path: s.split(".").slice(1),
708
+ const u = e.getState().getShadowValue(i);
709
+ if (u)
710
+ return s({
711
+ currentState: u,
712
+ path: i.split(".").slice(1),
709
713
  componentId: _
710
714
  });
711
715
  };
712
716
  if (p === "getSelectedIndex")
713
717
  return () => e.getState().getSelectedIndex(
714
- t + "." + n.join("."),
718
+ t + "." + o.join("."),
715
719
  h?.validIds
716
720
  );
717
721
  if (p === "clearSelected")
718
- return ft(t, n), () => {
722
+ return ft(t, o), () => {
719
723
  e.getState().clearSelectedIndex({
720
- arrayKey: t + "." + n.join(".")
724
+ arrayKey: t + "." + o.join(".")
721
725
  });
722
726
  };
723
727
  if (p === "useVirtualView")
724
728
  return (r) => {
725
729
  const {
726
- itemHeight: o = 50,
727
- overscan: s = 6,
728
- stickToBottom: l = !1,
729
- scrollStickTolerance: u = 75
730
- } = r, c = z(null), [d, k] = at({
730
+ itemHeight: n = 50,
731
+ overscan: i = 6,
732
+ stickToBottom: u = !1,
733
+ scrollStickTolerance: d = 75
734
+ } = r, c = z(null), [f, D] = at({
731
735
  startIndex: 0,
732
736
  endIndex: 10
733
- }), [M, D] = at({}), V = z(!0), $ = z({
737
+ }), [M, k] = at({}), V = z(!0), $ = z({
734
738
  isUserScrolling: !1,
735
739
  lastScrollTop: 0,
736
740
  scrollUpCount: 0,
@@ -739,36 +743,36 @@ function Pt(t, a, m, g) {
739
743
  /* @__PURE__ */ new Map()
740
744
  );
741
745
  dt(() => {
742
- if (!l || !c.current || $.current.isUserScrolling)
746
+ if (!u || !c.current || $.current.isUserScrolling)
743
747
  return;
744
748
  const v = c.current;
745
749
  v.scrollTo({
746
750
  top: v.scrollHeight,
747
751
  behavior: V.current ? "instant" : "smooth"
748
752
  });
749
- }, [M, l]);
750
- const L = e.getState().getShadowMetadata(t, n)?.arrayKeys || [], { totalHeight: G, itemOffsets: Z } = St(() => {
753
+ }, [M, u]);
754
+ const L = e.getState().getShadowMetadata(t, o)?.arrayKeys || [], { totalHeight: G, itemOffsets: Z } = St(() => {
751
755
  let v = 0;
752
756
  const w = /* @__PURE__ */ new Map();
753
- return (e.getState().getShadowMetadata(t, n)?.arrayKeys || []).forEach((A) => {
754
- const C = A.split(".").slice(1), U = e.getState().getShadowMetadata(t, C)?.virtualizer?.itemHeight || o;
757
+ return (e.getState().getShadowMetadata(t, o)?.arrayKeys || []).forEach((A) => {
758
+ const C = A.split(".").slice(1), U = e.getState().getShadowMetadata(t, C)?.virtualizer?.itemHeight || n;
755
759
  w.set(A, {
756
760
  height: U,
757
761
  offset: v
758
762
  }), v += U;
759
763
  }), j.current = w, { totalHeight: v, itemOffsets: w };
760
- }, [L.length, o]);
764
+ }, [L.length, n]);
761
765
  dt(() => {
762
- if (l && L.length > 0 && c.current && !$.current.isUserScrolling && V.current) {
766
+ if (u && L.length > 0 && c.current && !$.current.isUserScrolling && V.current) {
763
767
  const v = c.current, w = () => {
764
768
  if (v.clientHeight > 0) {
765
769
  const E = Math.ceil(
766
- v.clientHeight / o
770
+ v.clientHeight / n
767
771
  ), A = L.length - 1, C = Math.max(
768
772
  0,
769
- A - E - s
773
+ A - E - i
770
774
  );
771
- k({ startIndex: C, endIndex: A }), requestAnimationFrame(() => {
775
+ D({ startIndex: C, endIndex: A }), requestAnimationFrame(() => {
772
776
  H("instant"), V.current = !1;
773
777
  });
774
778
  } else
@@ -776,12 +780,12 @@ function Pt(t, a, m, g) {
776
780
  };
777
781
  w();
778
782
  }
779
- }, [L.length, l, o, s]);
783
+ }, [L.length, u, n, i]);
780
784
  const X = lt(() => {
781
785
  const v = c.current;
782
786
  if (!v) return;
783
787
  const w = v.scrollTop, { scrollHeight: E, clientHeight: A } = v, C = $.current, U = E - (w + A), N = C.isNearBottom;
784
- C.isNearBottom = U <= u, w < C.lastScrollTop ? (C.scrollUpCount++, C.scrollUpCount > 3 && N && (C.isUserScrolling = !0, console.log("User scrolled away from bottom"))) : C.isNearBottom && (C.isUserScrolling = !1, C.scrollUpCount = 0), C.lastScrollTop = w;
788
+ C.isNearBottom = U <= d, w < C.lastScrollTop ? (C.scrollUpCount++, C.scrollUpCount > 3 && N && (C.isUserScrolling = !0, console.log("User scrolled away from bottom"))) : C.isNearBottom && (C.isUserScrolling = !1, C.scrollUpCount = 0), C.lastScrollTop = w;
785
789
  let J = 0;
786
790
  for (let F = 0; F < L.length; F++) {
787
791
  const K = L[F], st = j.current.get(K);
@@ -790,32 +794,32 @@ function Pt(t, a, m, g) {
790
794
  break;
791
795
  }
792
796
  }
793
- if (J !== d.startIndex) {
794
- const F = Math.ceil(A / o);
795
- k({
796
- startIndex: Math.max(0, J - s),
797
+ if (J !== f.startIndex) {
798
+ const F = Math.ceil(A / n);
799
+ D({
800
+ startIndex: Math.max(0, J - i),
797
801
  endIndex: Math.min(
798
802
  L.length - 1,
799
- J + F + s
803
+ J + F + i
800
804
  )
801
805
  });
802
806
  }
803
807
  }, [
804
808
  L.length,
805
- d.startIndex,
806
- o,
807
- s,
808
- u
809
+ f.startIndex,
810
+ n,
811
+ i,
812
+ d
809
813
  ]);
810
814
  et(() => {
811
815
  const v = c.current;
812
- if (!(!v || !l))
816
+ if (!(!v || !u))
813
817
  return v.addEventListener("scroll", X, {
814
818
  passive: !0
815
819
  }), () => {
816
820
  v.removeEventListener("scroll", X);
817
821
  };
818
- }, [X, l]);
822
+ }, [X, u]);
819
823
  const H = lt(
820
824
  (v = "smooth") => {
821
825
  const w = c.current;
@@ -842,7 +846,7 @@ function Pt(t, a, m, g) {
842
846
  []
843
847
  );
844
848
  return et(() => {
845
- if (!l || !c.current) return;
849
+ if (!u || !c.current) return;
846
850
  const v = c.current, w = $.current;
847
851
  let E;
848
852
  const A = () => {
@@ -869,24 +873,24 @@ function Pt(t, a, m, g) {
869
873
  }, 0) : A(), () => {
870
874
  clearTimeout(E), C.disconnect(), v.removeEventListener("load", U, !0);
871
875
  };
872
- }, [l, L.length, H]), {
876
+ }, [u, L.length, H]), {
873
877
  virtualState: St(() => {
874
878
  const v = e.getState(), w = v.getShadowValue(
875
- [t, ...n].join(".")
876
- ), E = v.getShadowMetadata(t, n)?.arrayKeys || [], A = w.slice(
877
- d.startIndex,
878
- d.endIndex + 1
879
+ [t, ...o].join(".")
880
+ ), E = v.getShadowMetadata(t, o)?.arrayKeys || [], A = w.slice(
881
+ f.startIndex,
882
+ f.endIndex + 1
879
883
  ), C = E.slice(
880
- d.startIndex,
881
- d.endIndex + 1
884
+ f.startIndex,
885
+ f.endIndex + 1
882
886
  );
883
- return i({
887
+ return s({
884
888
  currentState: A,
885
- path: n,
889
+ path: o,
886
890
  componentId: _,
887
891
  meta: { ...h, validIds: C }
888
892
  });
889
- }, [d.startIndex, d.endIndex, L.length]),
893
+ }, [f.startIndex, f.endIndex, L.length]),
890
894
  virtualizerProps: {
891
895
  outer: {
892
896
  ref: c,
@@ -905,7 +909,7 @@ function Pt(t, a, m, g) {
905
909
  list: {
906
910
  style: {
907
911
  transform: `translateY(${j.current.get(
908
- L[d.startIndex]
912
+ L[f.startIndex]
909
913
  )?.offset || 0}px)`
910
914
  }
911
915
  }
@@ -921,28 +925,28 @@ function Pt(t, a, m, g) {
921
925
  };
922
926
  if (p === "stateMap")
923
927
  return (r) => {
924
- const [o, s] = at(
925
- h?.validIds ?? e.getState().getShadowMetadata(t, n)?.arrayKeys
926
- ), l = e.getState().getShadowValue(R, h?.validIds);
927
- if (!o)
928
+ const [n, i] = at(
929
+ h?.validIds ?? e.getState().getShadowMetadata(t, o)?.arrayKeys
930
+ ), u = e.getState().getShadowValue(R, h?.validIds);
931
+ if (!n)
928
932
  throw new Error("No array keys found for mapping");
929
- const u = i({
930
- currentState: l,
931
- path: n,
933
+ const d = s({
934
+ currentState: u,
935
+ path: o,
932
936
  componentId: _,
933
937
  meta: h
934
938
  });
935
- return l.map((c, d) => {
936
- const k = o[d]?.split(".").slice(1), M = i({
939
+ return u.map((c, f) => {
940
+ const D = n[f]?.split(".").slice(1), M = s({
937
941
  currentState: c,
938
- path: k,
942
+ path: D,
939
943
  componentId: _,
940
944
  meta: h
941
945
  });
942
946
  return r(
943
947
  M,
944
- d,
945
- u
948
+ f,
949
+ d
946
950
  );
947
951
  });
948
952
  };
@@ -950,24 +954,24 @@ function Pt(t, a, m, g) {
950
954
  return (r) => ut(qt, {
951
955
  proxy: {
952
956
  _stateKey: t,
953
- _path: n,
957
+ _path: o,
954
958
  _mapFn: r,
955
959
  _meta: h
956
960
  },
957
- rebuildStateShape: i
961
+ rebuildStateShape: s
958
962
  });
959
963
  if (p === "stateFind")
960
964
  return (r) => {
961
- const o = h?.validIds ?? e.getState().getShadowMetadata(t, n)?.arrayKeys;
962
- if (o)
963
- for (let s = 0; s < o.length; s++) {
964
- const l = o[s];
965
- if (!l) continue;
966
- const u = e.getState().getShadowValue(l);
967
- if (r(u, s)) {
968
- const c = l.split(".").slice(1);
969
- return i({
970
- currentState: u,
965
+ const n = h?.validIds ?? e.getState().getShadowMetadata(t, o)?.arrayKeys;
966
+ if (n)
967
+ for (let i = 0; i < n.length; i++) {
968
+ const u = n[i];
969
+ if (!u) continue;
970
+ const d = e.getState().getShadowValue(u);
971
+ if (r(d, i)) {
972
+ const c = u.split(".").slice(1);
973
+ return s({
974
+ currentState: d,
971
975
  path: c,
972
976
  componentId: _,
973
977
  meta: h
@@ -978,18 +982,18 @@ function Pt(t, a, m, g) {
978
982
  };
979
983
  if (p === "stateFilter")
980
984
  return (r) => {
981
- const o = h?.validIds ?? e.getState().getShadowMetadata(t, n)?.arrayKeys;
982
- if (!o)
985
+ const n = h?.validIds ?? e.getState().getShadowMetadata(t, o)?.arrayKeys;
986
+ if (!n)
983
987
  throw new Error("No array keys found for filtering.");
984
- const s = [], l = b.filter(
985
- (u, c) => r(u, c) ? (s.push(o[c]), !0) : !1
988
+ const i = [], u = b.filter(
989
+ (d, c) => r(d, c) ? (i.push(n[c]), !0) : !1
986
990
  );
987
- return i({
988
- currentState: l,
989
- path: n,
991
+ return s({
992
+ currentState: u,
993
+ path: o,
990
994
  componentId: _,
991
995
  meta: {
992
- validIds: s,
996
+ validIds: i,
993
997
  transforms: [
994
998
  ...h?.transforms || [],
995
999
  {
@@ -1002,19 +1006,19 @@ function Pt(t, a, m, g) {
1002
1006
  };
1003
1007
  if (p === "stateSort")
1004
1008
  return (r) => {
1005
- const o = h?.validIds ?? e.getState().getShadowMetadata(t, n)?.arrayKeys;
1006
- if (!o)
1009
+ const n = h?.validIds ?? e.getState().getShadowMetadata(t, o)?.arrayKeys;
1010
+ if (!n)
1007
1011
  throw new Error("No array keys found for sorting");
1008
- const s = b.map((l, u) => ({
1009
- item: l,
1010
- key: o[u]
1012
+ const i = b.map((u, d) => ({
1013
+ item: u,
1014
+ key: n[d]
1011
1015
  }));
1012
- return s.sort((l, u) => r(l.item, u.item)).filter(Boolean), i({
1013
- currentState: s.map((l) => l.item),
1014
- path: n,
1016
+ return i.sort((u, d) => r(u.item, d.item)).filter(Boolean), s({
1017
+ currentState: i.map((u) => u.item),
1018
+ path: o,
1015
1019
  componentId: _,
1016
1020
  meta: {
1017
- validIds: s.map((l) => l.key),
1021
+ validIds: i.map((u) => u.key),
1018
1022
  transforms: [
1019
1023
  ...h?.transforms || [],
1020
1024
  { type: "sort", fn: r }
@@ -1025,71 +1029,71 @@ function Pt(t, a, m, g) {
1025
1029
  if (p === "stream")
1026
1030
  return function(r = {}) {
1027
1031
  const {
1028
- bufferSize: o = 100,
1029
- flushInterval: s = 100,
1030
- bufferStrategy: l = "accumulate",
1031
- store: u,
1032
+ bufferSize: n = 100,
1033
+ flushInterval: i = 100,
1034
+ bufferStrategy: u = "accumulate",
1035
+ store: d,
1032
1036
  onFlush: c
1033
1037
  } = r;
1034
- let d = [], k = !1, M = null;
1035
- const D = (G) => {
1036
- if (!k) {
1037
- if (l === "sliding" && d.length >= o)
1038
- d.shift();
1039
- else if (l === "dropping" && d.length >= o)
1038
+ let f = [], D = !1, M = null;
1039
+ const k = (G) => {
1040
+ if (!D) {
1041
+ if (u === "sliding" && f.length >= n)
1042
+ f.shift();
1043
+ else if (u === "dropping" && f.length >= n)
1040
1044
  return;
1041
- d.push(G), d.length >= o && V();
1045
+ f.push(G), f.length >= n && V();
1042
1046
  }
1043
1047
  }, V = () => {
1044
- if (d.length === 0) return;
1045
- const G = [...d];
1046
- if (d = [], u) {
1047
- const Z = u(G);
1048
+ if (f.length === 0) return;
1049
+ const G = [...f];
1050
+ if (f = [], d) {
1051
+ const Z = d(G);
1048
1052
  Z !== void 0 && (Array.isArray(Z) ? Z : [Z]).forEach((H) => {
1049
- a(H, n, {
1053
+ a(H, o, {
1050
1054
  updateType: "insert"
1051
1055
  });
1052
1056
  });
1053
1057
  } else
1054
1058
  G.forEach((Z) => {
1055
- a(Z, n, {
1059
+ a(Z, o, {
1056
1060
  updateType: "insert"
1057
1061
  });
1058
1062
  });
1059
1063
  c?.(G);
1060
1064
  };
1061
- s > 0 && (M = setInterval(V, s));
1062
- const $ = nt(), j = e.getState().getShadowMetadata(t, n) || {}, L = j.streams || /* @__PURE__ */ new Map();
1063
- return L.set($, { buffer: d, flushTimer: M }), e.getState().setShadowMetadata(t, n, {
1065
+ i > 0 && (M = setInterval(V, i));
1066
+ const $ = nt(), j = e.getState().getShadowMetadata(t, o) || {}, L = j.streams || /* @__PURE__ */ new Map();
1067
+ return L.set($, { buffer: f, flushTimer: M }), e.getState().setShadowMetadata(t, o, {
1064
1068
  ...j,
1065
1069
  streams: L
1066
1070
  }), {
1067
- write: (G) => D(G),
1068
- writeMany: (G) => G.forEach(D),
1071
+ write: (G) => k(G),
1072
+ writeMany: (G) => G.forEach(k),
1069
1073
  flush: () => V(),
1070
1074
  pause: () => {
1071
- k = !0;
1075
+ D = !0;
1072
1076
  },
1073
1077
  resume: () => {
1074
- k = !1, d.length > 0 && V();
1078
+ D = !1, f.length > 0 && V();
1075
1079
  },
1076
1080
  close: () => {
1077
1081
  V(), M && clearInterval(M);
1078
- const G = e.getState().getShadowMetadata(t, n);
1082
+ const G = e.getState().getShadowMetadata(t, o);
1079
1083
  G?.streams && G.streams.delete($);
1080
1084
  }
1081
1085
  };
1082
1086
  };
1083
1087
  if (p === "stateList")
1084
1088
  return (r) => /* @__PURE__ */ it(() => {
1085
- const s = z(/* @__PURE__ */ new Map()), l = h?.transforms && h.transforms.length > 0 ? `${_}-${Bt(h.transforms)}` : `${_}-base`, [u, c] = at({}), { validIds: d, arrayValues: k } = St(() => {
1086
- const D = e.getState().getShadowMetadata(t, n)?.transformCaches?.get(l);
1089
+ const i = z(/* @__PURE__ */ new Map()), u = h?.transforms && h.transforms.length > 0 ? `${_}-${Bt(h.transforms)}` : `${_}-base`, [d, c] = at({}), { validIds: f, arrayValues: D } = St(() => {
1090
+ const k = e.getState().getShadowMetadata(t, o)?.transformCaches?.get(u);
1087
1091
  let V;
1088
- D && D.validIds ? V = D.validIds : (V = pt(
1092
+ k && k.validIds ? V = k.validIds : (V = pt(
1089
1093
  t,
1090
- n,
1094
+ o,
1091
1095
  h?.transforms
1092
- ), e.getState().setTransformCache(t, n, l, {
1096
+ ), e.getState().setTransformCache(t, o, u, {
1093
1097
  validIds: V,
1094
1098
  computedAt: Date.now(),
1095
1099
  transforms: h?.transforms || []
@@ -1099,37 +1103,37 @@ function Pt(t, a, m, g) {
1099
1103
  validIds: V,
1100
1104
  arrayValues: $ || []
1101
1105
  };
1102
- }, [l, u]);
1106
+ }, [u, d]);
1103
1107
  if (et(() => {
1104
- const D = e.getState().subscribeToPath(R, (V) => {
1108
+ const k = e.getState().subscribeToPath(R, (V) => {
1105
1109
  if (V.type === "GET_SELECTED")
1106
1110
  return;
1107
- const j = e.getState().getShadowMetadata(t, n)?.transformCaches;
1111
+ const j = e.getState().getShadowMetadata(t, o)?.transformCaches;
1108
1112
  if (j)
1109
1113
  for (const L of j.keys())
1110
1114
  L.startsWith(_) && j.delete(L);
1111
1115
  (V.type === "INSERT" || V.type === "REMOVE" || V.type === "CLEAR_SELECTION") && c({});
1112
1116
  });
1113
1117
  return () => {
1114
- D();
1118
+ k();
1115
1119
  };
1116
- }, [_, R]), !Array.isArray(k))
1120
+ }, [_, R]), !Array.isArray(D))
1117
1121
  return null;
1118
- const M = i({
1119
- currentState: k,
1120
- path: n,
1122
+ const M = s({
1123
+ currentState: D,
1124
+ path: o,
1121
1125
  componentId: _,
1122
1126
  meta: {
1123
1127
  ...h,
1124
- validIds: d
1128
+ validIds: f
1125
1129
  }
1126
1130
  });
1127
- return /* @__PURE__ */ it(Ot, { children: k.map((D, V) => {
1128
- const $ = d[V];
1131
+ return /* @__PURE__ */ it(Ot, { children: D.map((k, V) => {
1132
+ const $ = f[V];
1129
1133
  if (!$)
1130
1134
  return null;
1131
- let j = s.current.get($);
1132
- j || (j = nt(), s.current.set($, j));
1135
+ let j = i.current.get($);
1136
+ j || (j = nt(), i.current.set($, j));
1133
1137
  const L = $.split(".").slice(1);
1134
1138
  return ut(wt, {
1135
1139
  key: $,
@@ -1138,85 +1142,85 @@ function Pt(t, a, m, g) {
1138
1142
  itemPath: L,
1139
1143
  localIndex: V,
1140
1144
  arraySetter: M,
1141
- rebuildStateShape: i,
1145
+ rebuildStateShape: s,
1142
1146
  renderFn: r
1143
1147
  });
1144
1148
  }) });
1145
1149
  }, {});
1146
1150
  if (p === "stateFlattenOn")
1147
1151
  return (r) => {
1148
- const o = b;
1152
+ const n = b;
1149
1153
  y.clear(), I++;
1150
- const s = o.flatMap(
1151
- (l) => l[r] ?? []
1154
+ const i = n.flatMap(
1155
+ (u) => u[r] ?? []
1152
1156
  );
1153
- return i({
1154
- currentState: s,
1155
- path: [...n, "[*]", r],
1157
+ return s({
1158
+ currentState: i,
1159
+ path: [...o, "[*]", r],
1156
1160
  componentId: _,
1157
1161
  meta: h
1158
1162
  });
1159
1163
  };
1160
1164
  if (p === "index")
1161
1165
  return (r) => {
1162
- const s = e.getState().getShadowMetadata(t, n)?.arrayKeys?.filter(
1166
+ const i = e.getState().getShadowMetadata(t, o)?.arrayKeys?.filter(
1163
1167
  (c) => !h?.validIds || h?.validIds && h?.validIds?.includes(c)
1164
1168
  )?.[r];
1165
- if (!s) return;
1166
- const l = e.getState().getShadowValue(s, h?.validIds);
1167
- return i({
1168
- currentState: l,
1169
- path: s.split(".").slice(1),
1169
+ if (!i) return;
1170
+ const u = e.getState().getShadowValue(i, h?.validIds);
1171
+ return s({
1172
+ currentState: u,
1173
+ path: i.split(".").slice(1),
1170
1174
  componentId: _,
1171
1175
  meta: h
1172
1176
  });
1173
1177
  };
1174
1178
  if (p === "last")
1175
1179
  return () => {
1176
- const r = e.getState().getShadowValue(t, n);
1180
+ const r = e.getState().getShadowValue(t, o);
1177
1181
  if (r.length === 0) return;
1178
- const o = r.length - 1, s = r[o], l = [...n, o.toString()];
1179
- return i({
1180
- currentState: s,
1181
- path: l,
1182
+ const n = r.length - 1, i = r[n], u = [...o, n.toString()];
1183
+ return s({
1184
+ currentState: i,
1185
+ path: u,
1182
1186
  componentId: _,
1183
1187
  meta: h
1184
1188
  });
1185
1189
  };
1186
1190
  if (p === "insert")
1187
- return (r, o) => (a(r, n, { updateType: "insert" }), i({
1188
- currentState: e.getState().getShadowValue(t, n),
1189
- path: n,
1191
+ return (r, n) => (a(r, o, { updateType: "insert" }), s({
1192
+ currentState: e.getState().getShadowValue(t, o),
1193
+ path: o,
1190
1194
  componentId: _,
1191
1195
  meta: h
1192
1196
  }));
1193
1197
  if (p === "uniqueInsert")
1194
- return (r, o, s) => {
1195
- const l = e.getState().getShadowValue(t, n), u = rt(r) ? r(l) : r;
1198
+ return (r, n, i) => {
1199
+ const u = e.getState().getShadowValue(t, o), d = rt(r) ? r(u) : r;
1196
1200
  let c = null;
1197
- if (!l.some((k) => {
1198
- const M = o ? o.every(
1199
- (D) => ct(k[D], u[D])
1200
- ) : ct(k, u);
1201
- return M && (c = k), M;
1201
+ if (!u.some((D) => {
1202
+ const M = n ? n.every(
1203
+ (k) => ct(D[k], d[k])
1204
+ ) : ct(D, d);
1205
+ return M && (c = D), M;
1202
1206
  }))
1203
- T(n), a(u, n, { updateType: "insert" });
1204
- else if (s && c) {
1205
- const k = s(c), M = l.map(
1206
- (D) => ct(D, c) ? k : D
1207
+ T(o), a(d, o, { updateType: "insert" });
1208
+ else if (i && c) {
1209
+ const D = i(c), M = u.map(
1210
+ (k) => ct(k, c) ? D : k
1207
1211
  );
1208
- T(n), a(M, n, {
1212
+ T(o), a(M, o, {
1209
1213
  updateType: "update"
1210
1214
  });
1211
1215
  }
1212
1216
  };
1213
1217
  if (p === "cut")
1214
- return (r, o) => {
1215
- const s = h?.validIds ?? e.getState().getShadowMetadata(t, n)?.arrayKeys;
1216
- if (!s || s.length === 0) return;
1217
- const l = r == -1 ? s.length - 1 : r !== void 0 ? r : s.length - 1, u = s[l];
1218
- if (!u) return;
1219
- const c = u.split(".").slice(1);
1218
+ return (r, n) => {
1219
+ const i = h?.validIds ?? e.getState().getShadowMetadata(t, o)?.arrayKeys;
1220
+ if (!i || i.length === 0) return;
1221
+ const u = r == -1 ? i.length - 1 : r !== void 0 ? r : i.length - 1, d = i[u];
1222
+ if (!d) return;
1223
+ const c = d.split(".").slice(1);
1220
1224
  a(b, c, {
1221
1225
  updateType: "cut"
1222
1226
  });
@@ -1225,141 +1229,140 @@ function Pt(t, a, m, g) {
1225
1229
  return () => {
1226
1230
  const r = pt(
1227
1231
  t,
1228
- n,
1232
+ o,
1229
1233
  h?.transforms
1230
1234
  );
1231
1235
  if (!r || r.length === 0) return;
1232
- const o = e.getState().selectedIndicesMap.get(R);
1233
- let s = r.findIndex(
1234
- (c) => c === o
1236
+ const n = e.getState().selectedIndicesMap.get(R);
1237
+ let i = r.findIndex(
1238
+ (c) => c === n
1235
1239
  );
1236
- const l = r[s == -1 ? r.length - 1 : s]?.split(".").slice(1);
1240
+ const u = r[i == -1 ? r.length - 1 : i]?.split(".").slice(1);
1237
1241
  e.getState().clearSelectedIndex({ arrayKey: R });
1238
- const u = l?.slice(0, -1);
1239
- ft(t, u), a(b, l, {
1242
+ const d = u?.slice(0, -1);
1243
+ ft(t, d), a(b, u, {
1240
1244
  updateType: "cut"
1241
1245
  });
1242
1246
  };
1243
1247
  if (p === "cutByValue")
1244
1248
  return (r) => {
1245
- const o = e.getState().getShadowMetadata(t, n), s = h?.validIds ?? o?.arrayKeys;
1246
- if (!s) return;
1247
- let l = null;
1248
- for (const u of s)
1249
- if (e.getState().getShadowValue(u) === r) {
1250
- l = u;
1249
+ const n = e.getState().getShadowMetadata(t, o), i = h?.validIds ?? n?.arrayKeys;
1250
+ if (!i) return;
1251
+ let u = null;
1252
+ for (const d of i)
1253
+ if (e.getState().getShadowValue(d) === r) {
1254
+ u = d;
1251
1255
  break;
1252
1256
  }
1253
- if (l) {
1254
- const u = l.split(".").slice(1);
1255
- a(null, u, { updateType: "cut" });
1257
+ if (u) {
1258
+ const d = u.split(".").slice(1);
1259
+ a(null, d, { updateType: "cut" });
1256
1260
  }
1257
1261
  };
1258
1262
  if (p === "toggleByValue")
1259
1263
  return (r) => {
1260
- const o = e.getState().getShadowMetadata(t, n), s = h?.validIds ?? o?.arrayKeys;
1261
- if (!s) return;
1262
- let l = null;
1263
- for (const u of s) {
1264
- const c = e.getState().getShadowValue(u);
1264
+ const n = e.getState().getShadowMetadata(t, o), i = h?.validIds ?? n?.arrayKeys;
1265
+ if (!i) return;
1266
+ let u = null;
1267
+ for (const d of i) {
1268
+ const c = e.getState().getShadowValue(d);
1265
1269
  if (console.log("itemValue sdasdasdasd", c), c === r) {
1266
- l = u;
1270
+ u = d;
1267
1271
  break;
1268
1272
  }
1269
1273
  }
1270
- if (console.log("itemValue keyToCut", l), l) {
1271
- const u = l.split(".").slice(1);
1272
- console.log("itemValue keyToCut", l), a(r, u, {
1274
+ if (console.log("itemValue keyToCut", u), u) {
1275
+ const d = u.split(".").slice(1);
1276
+ console.log("itemValue keyToCut", u), a(r, d, {
1273
1277
  updateType: "cut"
1274
1278
  });
1275
1279
  } else
1276
- a(r, n, { updateType: "insert" });
1280
+ a(r, o, { updateType: "insert" });
1277
1281
  };
1278
1282
  if (p === "findWith")
1279
- return (r, o) => {
1280
- const s = e.getState().getShadowMetadata(t, n)?.arrayKeys;
1281
- if (!s)
1283
+ return (r, n) => {
1284
+ const i = e.getState().getShadowMetadata(t, o)?.arrayKeys;
1285
+ if (!i)
1282
1286
  throw new Error("No array keys found for sorting");
1283
- let l = null, u = [];
1284
- for (const c of s) {
1285
- let d = e.getState().getShadowValue(c, h?.validIds);
1286
- if (d && d[r] === o) {
1287
- l = d, u = c.split(".").slice(1);
1287
+ let u = null, d = [];
1288
+ for (const c of i) {
1289
+ let f = e.getState().getShadowValue(c, h?.validIds);
1290
+ if (f && f[r] === n) {
1291
+ u = f, d = c.split(".").slice(1);
1288
1292
  break;
1289
1293
  }
1290
1294
  }
1291
- return i({
1292
- currentState: l,
1293
- path: u,
1295
+ return s({
1296
+ currentState: u,
1297
+ path: d,
1294
1298
  componentId: _,
1295
1299
  meta: h
1296
1300
  });
1297
1301
  };
1298
1302
  }
1299
1303
  if (p === "cut") {
1300
- let r = e.getState().getShadowValue(n.join("."));
1304
+ let r = e.getState().getShadowValue(o.join("."));
1301
1305
  return () => {
1302
- a(r, n, { updateType: "cut" });
1306
+ a(r, o, { updateType: "cut" });
1303
1307
  };
1304
1308
  }
1305
1309
  if (p === "get")
1306
- return () => (Tt(t, _, n), e.getState().getShadowValue(R, h?.validIds));
1310
+ return () => (Tt(t, _, o), e.getState().getShadowValue(R, h?.validIds));
1307
1311
  if (p === "getState")
1308
1312
  return () => e.getState().getShadowValue(R, h?.validIds);
1309
1313
  if (p === "$derive")
1310
1314
  return (r) => bt({
1311
1315
  _stateKey: t,
1312
- _path: n,
1316
+ _path: o,
1313
1317
  _effect: r.toString(),
1314
1318
  _meta: h
1315
1319
  });
1316
1320
  if (p === "$get")
1317
- return () => bt({ _stateKey: t, _path: n, _meta: h });
1321
+ return () => bt({ _stateKey: t, _path: o, _meta: h });
1318
1322
  if (p === "lastSynced") {
1319
- const r = `${t}:${n.join(".")}`;
1323
+ const r = `${t}:${o.join(".")}`;
1320
1324
  return e.getState().getSyncInfo(r);
1321
1325
  }
1322
1326
  if (p == "getLocalStorage")
1323
1327
  return (r) => gt(g + "-" + t + "-" + r);
1324
1328
  if (p === "isSelected") {
1325
- const r = [t, ...n].slice(0, -1);
1326
- if (ft(t, n, void 0), Array.isArray(
1329
+ const r = [t, ...o].slice(0, -1);
1330
+ if (ft(t, o, void 0), Array.isArray(
1327
1331
  e.getState().getShadowValue(r.join("."), h?.validIds)
1328
1332
  )) {
1329
- n[n.length - 1];
1330
- const o = r.join("."), s = e.getState().selectedIndicesMap.get(o), l = t + "." + n.join(".");
1331
- return s === l;
1333
+ o[o.length - 1];
1334
+ const n = r.join("."), i = e.getState().selectedIndicesMap.get(n), u = t + "." + o.join(".");
1335
+ return i === u;
1332
1336
  }
1333
1337
  return;
1334
1338
  }
1335
1339
  if (p === "setSelected")
1336
1340
  return (r) => {
1337
- const o = n.slice(0, -1), s = t + "." + o.join("."), l = t + "." + n.join(".");
1338
- ft(t, o, void 0), e.getState().selectedIndicesMap.get(s), r && e.getState().setSelectedIndex(s, l);
1341
+ const n = o.slice(0, -1), i = t + "." + n.join("."), u = t + "." + o.join(".");
1342
+ ft(t, n, void 0), e.getState().selectedIndicesMap.get(i), r && e.getState().setSelectedIndex(i, u);
1339
1343
  };
1340
1344
  if (p === "toggleSelected")
1341
1345
  return () => {
1342
- const r = n.slice(0, -1), o = t + "." + r.join("."), s = t + "." + n.join(".");
1343
- e.getState().selectedIndicesMap.get(o) === s ? e.getState().clearSelectedIndex({ arrayKey: o }) : e.getState().setSelectedIndex(o, s);
1346
+ const r = o.slice(0, -1), n = t + "." + r.join("."), i = t + "." + o.join(".");
1347
+ e.getState().selectedIndicesMap.get(n) === i ? e.getState().clearSelectedIndex({ arrayKey: n }) : e.getState().setSelectedIndex(n, i);
1344
1348
  };
1345
1349
  if (p === "_componentId")
1346
1350
  return _;
1347
- if (n.length == 0) {
1351
+ if (o.length == 0) {
1348
1352
  if (p === "addZodValidation")
1349
1353
  return (r) => {
1350
- if (!e.getState().getInitialOptions(t)?.validation?.key) throw new Error("Validation key not found");
1351
- r.forEach((s) => {
1352
- const l = e.getState().getShadowMetadata(t, s.path) || {};
1353
- e.getState().setShadowMetadata(t, s.path, {
1354
- ...l,
1354
+ e.getState().getInitialOptions(t)?.validation, r.forEach((n) => {
1355
+ const i = e.getState().getShadowMetadata(t, n.path) || {};
1356
+ e.getState().setShadowMetadata(t, n.path, {
1357
+ ...i,
1355
1358
  validation: {
1356
1359
  status: "VALIDATION_FAILED",
1357
- message: s.message,
1360
+ message: n.message,
1358
1361
  validatedValue: void 0
1359
1362
  }
1360
- }), e.getState().notifyPathSubscribers(s.path, {
1363
+ }), e.getState().notifyPathSubscribers(n.path, {
1361
1364
  type: "VALIDATION_FAILED",
1362
- message: s.message,
1365
+ message: n.message,
1363
1366
  validatedValue: void 0
1364
1367
  });
1365
1368
  });
@@ -1368,9 +1371,9 @@ function Pt(t, a, m, g) {
1368
1371
  return (r) => {
1369
1372
  if (!r)
1370
1373
  throw new Error("clearZodValidation requires a path");
1371
- const o = e.getState().getShadowMetadata(t, r) || {};
1372
- o.validation && (e.getState().setShadowMetadata(t, r, {
1373
- ...o,
1374
+ const n = e.getState().getShadowMetadata(t, r) || {};
1375
+ n.validation && (e.getState().setShadowMetadata(t, r, {
1376
+ ...n,
1374
1377
  validation: void 0
1375
1378
  }), e.getState().notifyPathSubscribers([t, ...r].join("."), {
1376
1379
  type: "VALIDATION_CLEARED"
@@ -1378,26 +1381,26 @@ function Pt(t, a, m, g) {
1378
1381
  };
1379
1382
  if (p === "applyJsonPatch")
1380
1383
  return (r) => {
1381
- const o = e.getState(), s = o.getShadowMetadata(t, []);
1382
- if (!s?.components) return;
1383
- const l = (c) => !c || c === "/" ? [] : c.split("/").slice(1).map((d) => d.replace(/~1/g, "/").replace(/~0/g, "~")), u = /* @__PURE__ */ new Set();
1384
+ const n = e.getState(), i = n.getShadowMetadata(t, []);
1385
+ if (!i?.components) return;
1386
+ const u = (c) => !c || c === "/" ? [] : c.split("/").slice(1).map((f) => f.replace(/~1/g, "/").replace(/~0/g, "~")), d = /* @__PURE__ */ new Set();
1384
1387
  for (const c of r) {
1385
- const d = l(c.path);
1388
+ const f = u(c.path);
1386
1389
  switch (c.op) {
1387
1390
  case "add":
1388
1391
  case "replace": {
1389
- const { value: k } = c;
1390
- o.updateShadowAtPath(t, d, k), o.markAsDirty(t, d, { bubble: !0 });
1391
- let M = [...d];
1392
+ const { value: D } = c;
1393
+ n.updateShadowAtPath(t, f, D), n.markAsDirty(t, f, { bubble: !0 });
1394
+ let M = [...f];
1392
1395
  for (; ; ) {
1393
- const D = o.getShadowMetadata(
1396
+ const k = n.getShadowMetadata(
1394
1397
  t,
1395
1398
  M
1396
1399
  );
1397
- if (D?.pathComponents && D.pathComponents.forEach((V) => {
1398
- if (!u.has(V)) {
1399
- const $ = s.components?.get(V);
1400
- $ && ($.forceUpdate(), u.add(V));
1400
+ if (k?.pathComponents && k.pathComponents.forEach((V) => {
1401
+ if (!d.has(V)) {
1402
+ const $ = i.components?.get(V);
1403
+ $ && ($.forceUpdate(), d.add(V));
1401
1404
  }
1402
1405
  }), M.length === 0) break;
1403
1406
  M.pop();
@@ -1405,18 +1408,18 @@ function Pt(t, a, m, g) {
1405
1408
  break;
1406
1409
  }
1407
1410
  case "remove": {
1408
- const k = d.slice(0, -1);
1409
- o.removeShadowArrayElement(t, d), o.markAsDirty(t, k, { bubble: !0 });
1410
- let M = [...k];
1411
+ const D = f.slice(0, -1);
1412
+ n.removeShadowArrayElement(t, f), n.markAsDirty(t, D, { bubble: !0 });
1413
+ let M = [...D];
1411
1414
  for (; ; ) {
1412
- const D = o.getShadowMetadata(
1415
+ const k = n.getShadowMetadata(
1413
1416
  t,
1414
1417
  M
1415
1418
  );
1416
- if (D?.pathComponents && D.pathComponents.forEach((V) => {
1417
- if (!u.has(V)) {
1418
- const $ = s.components?.get(V);
1419
- $ && ($.forceUpdate(), u.add(V));
1419
+ if (k?.pathComponents && k.pathComponents.forEach((V) => {
1420
+ if (!d.has(V)) {
1421
+ const $ = i.components?.get(V);
1422
+ $ && ($.forceUpdate(), d.add(V));
1420
1423
  }
1421
1424
  }), M.length === 0) break;
1422
1425
  M.pop();
@@ -1432,31 +1435,31 @@ function Pt(t, a, m, g) {
1432
1435
  return () => ht.getState().getFormRefsByStateKey(t);
1433
1436
  }
1434
1437
  if (p === "getFormRef")
1435
- return () => ht.getState().getFormRef(t + "." + n.join("."));
1438
+ return () => ht.getState().getFormRef(t + "." + o.join("."));
1436
1439
  if (p === "validationWrapper")
1437
1440
  return ({
1438
1441
  children: r,
1439
- hideMessage: o
1442
+ hideMessage: n
1440
1443
  }) => /* @__PURE__ */ it(
1441
1444
  At,
1442
1445
  {
1443
- formOpts: o ? { validation: { message: "" } } : void 0,
1444
- path: n,
1446
+ formOpts: n ? { validation: { message: "" } } : void 0,
1447
+ path: o,
1445
1448
  stateKey: t,
1446
1449
  children: r
1447
1450
  }
1448
1451
  );
1449
1452
  if (p === "_stateKey") return t;
1450
- if (p === "_path") return n;
1453
+ if (p === "_path") return o;
1451
1454
  if (p === "update")
1452
- return (r) => (a(r, n, { updateType: "update" }), {
1455
+ return (r) => (a(r, o, { updateType: "update" }), {
1453
1456
  /**
1454
1457
  * Marks this specific item, which was just updated, as 'synced' (not dirty).
1455
1458
  */
1456
1459
  synced: () => {
1457
- const o = e.getState().getShadowMetadata(t, n);
1458
- e.getState().setShadowMetadata(t, n, {
1459
- ...o,
1460
+ const n = e.getState().getShadowMetadata(t, o);
1461
+ e.getState().setShadowMetadata(t, o, {
1462
+ ...n,
1460
1463
  isDirty: !1,
1461
1464
  // EXPLICITLY set to false, not just undefined
1462
1465
  stateSource: "server",
@@ -1464,37 +1467,37 @@ function Pt(t, a, m, g) {
1464
1467
  lastServerSync: Date.now()
1465
1468
  // Add timestamp
1466
1469
  });
1467
- const s = [t, ...n].join(".");
1468
- e.getState().notifyPathSubscribers(s, {
1470
+ const i = [t, ...o].join(".");
1471
+ e.getState().notifyPathSubscribers(i, {
1469
1472
  type: "SYNC_STATUS_CHANGE",
1470
1473
  isDirty: !1
1471
1474
  });
1472
1475
  }
1473
1476
  });
1474
1477
  if (p === "toggle") {
1475
- const r = e.getState().getShadowValue([t, ...n].join("."));
1478
+ const r = e.getState().getShadowValue([t, ...o].join("."));
1476
1479
  if (console.log("currentValueAtPath", r), typeof b != "boolean")
1477
1480
  throw new Error("toggle() can only be used on boolean values");
1478
1481
  return () => {
1479
- a(!r, n, {
1482
+ a(!r, o, {
1480
1483
  updateType: "update"
1481
1484
  });
1482
1485
  };
1483
1486
  }
1484
1487
  if (p === "formElement")
1485
- return (r, o) => /* @__PURE__ */ it(
1488
+ return (r, n) => /* @__PURE__ */ it(
1486
1489
  Yt,
1487
1490
  {
1488
1491
  stateKey: t,
1489
- path: n,
1490
- rebuildStateShape: i,
1492
+ path: o,
1493
+ rebuildStateShape: s,
1491
1494
  setState: a,
1492
- formOpts: o,
1495
+ formOpts: n,
1493
1496
  renderFn: r
1494
1497
  }
1495
1498
  );
1496
- const tt = [...n, p], Q = e.getState().getShadowValue(t, tt);
1497
- return i({
1499
+ const tt = [...o, p], Q = e.getState().getShadowValue(t, tt);
1500
+ return s({
1498
1501
  currentState: Q,
1499
1502
  path: tt,
1500
1503
  componentId: _,
@@ -1507,13 +1510,13 @@ function Pt(t, a, m, g) {
1507
1510
  stateVersion: I
1508
1511
  }), W;
1509
1512
  }
1510
- const f = {
1513
+ const l = {
1511
1514
  revertToInitialState: (b) => {
1512
1515
  e.getState().getInitialOptions(t)?.validation;
1513
- const n = e.getState().getShadowMetadata(t, []);
1514
- n?.stateSource === "server" && n.baseServerState ? n.baseServerState : e.getState().initialStateGlobal[t];
1516
+ const o = e.getState().getShadowMetadata(t, []);
1517
+ o?.stateSource === "server" && o.baseServerState ? o.baseServerState : e.getState().initialStateGlobal[t];
1515
1518
  const h = e.getState().initialStateGlobal[t];
1516
- e.getState().clearSelectedIndexesForState(t), y.clear(), I++, e.getState().initializeShadowState(t, h), i({
1519
+ e.getState().clearSelectedIndexesForState(t), y.clear(), I++, e.getState().initializeShadowState(t, h), s({
1517
1520
  currentState: h,
1518
1521
  path: [],
1519
1522
  componentId: m
@@ -1527,7 +1530,7 @@ function Pt(t, a, m, g) {
1527
1530
  },
1528
1531
  updateInitialState: (b) => {
1529
1532
  y.clear(), I++;
1530
- const n = Pt(
1533
+ const o = Pt(
1531
1534
  t,
1532
1535
  a,
1533
1536
  m,
@@ -1540,11 +1543,11 @@ function Pt(t, a, m, g) {
1540
1543
  S.forceUpdate();
1541
1544
  });
1542
1545
  }), {
1543
- fetchId: (B) => n.get()[B]
1546
+ fetchId: (B) => o.get()[B]
1544
1547
  };
1545
1548
  }
1546
1549
  };
1547
- return i({
1550
+ return s({
1548
1551
  currentState: e.getState().getShadowValue(t, []),
1549
1552
  componentId: m,
1550
1553
  path: []
@@ -1559,14 +1562,14 @@ function qt({
1559
1562
  }) {
1560
1563
  const m = z(null), g = z(`map-${crypto.randomUUID()}`), y = z(!1), I = z(/* @__PURE__ */ new Map());
1561
1564
  et(() => {
1562
- const i = m.current;
1563
- if (!i || y.current) return;
1564
- const f = setTimeout(() => {
1565
+ const s = m.current;
1566
+ if (!s || y.current) return;
1567
+ const l = setTimeout(() => {
1565
1568
  const P = e.getState().getShadowMetadata(t._stateKey, t._path) || {}, b = P.mapWrappers || [];
1566
1569
  b.push({
1567
1570
  instanceId: g.current,
1568
1571
  mapFn: t._mapFn,
1569
- containerRef: i,
1572
+ containerRef: s,
1570
1573
  rebuildStateShape: a,
1571
1574
  path: t._path,
1572
1575
  componentId: g.current,
@@ -1577,7 +1580,7 @@ function qt({
1577
1580
  }), y.current = !0, T();
1578
1581
  }, 0);
1579
1582
  return () => {
1580
- if (clearTimeout(f), g.current) {
1583
+ if (clearTimeout(l), g.current) {
1581
1584
  const P = e.getState().getShadowMetadata(t._stateKey, t._path) || {};
1582
1585
  P.mapWrappers && (P.mapWrappers = P.mapWrappers.filter(
1583
1586
  (b) => b.instanceId !== g.current
@@ -1587,24 +1590,24 @@ function qt({
1587
1590
  };
1588
1591
  }, []);
1589
1592
  const T = () => {
1590
- const i = m.current;
1591
- if (!i) return;
1592
- const f = e.getState().getShadowValue(
1593
+ const s = m.current;
1594
+ if (!s) return;
1595
+ const l = e.getState().getShadowValue(
1593
1596
  [t._stateKey, ...t._path].join("."),
1594
1597
  t._meta?.validIds
1595
1598
  );
1596
- if (!Array.isArray(f)) return;
1599
+ if (!Array.isArray(l)) return;
1597
1600
  const P = t._meta?.validIds ?? e.getState().getShadowMetadata(t._stateKey, t._path)?.arrayKeys ?? [], b = a({
1598
- currentState: f,
1601
+ currentState: l,
1599
1602
  path: t._path,
1600
1603
  componentId: g.current,
1601
1604
  meta: t._meta
1602
1605
  });
1603
- f.forEach((n, h) => {
1606
+ l.forEach((o, h) => {
1604
1607
  const _ = P[h];
1605
1608
  if (!_) return;
1606
1609
  const x = nt(), R = document.createElement("div");
1607
- R.setAttribute("data-item-path", _), i.appendChild(R);
1610
+ R.setAttribute("data-item-path", _), s.appendChild(R);
1608
1611
  const B = Vt(R);
1609
1612
  I.current.set(_, B);
1610
1613
  const S = _.split(".").slice(1);
@@ -1633,18 +1636,18 @@ function zt({
1633
1636
  return et(() => {
1634
1637
  const T = a.current;
1635
1638
  if (!T || g.current) return;
1636
- const i = setTimeout(() => {
1639
+ const s = setTimeout(() => {
1637
1640
  if (!T.parentElement) {
1638
1641
  console.warn("Parent element not found for signal", y);
1639
1642
  return;
1640
1643
  }
1641
- const f = T.parentElement, b = Array.from(f.childNodes).indexOf(T);
1642
- let n = f.getAttribute("data-parent-id");
1643
- n || (n = `parent-${crypto.randomUUID()}`, f.setAttribute("data-parent-id", n)), m.current = `instance-${crypto.randomUUID()}`;
1644
+ const l = T.parentElement, b = Array.from(l.childNodes).indexOf(T);
1645
+ let o = l.getAttribute("data-parent-id");
1646
+ o || (o = `parent-${crypto.randomUUID()}`, l.setAttribute("data-parent-id", o)), m.current = `instance-${crypto.randomUUID()}`;
1644
1647
  const h = e.getState().getShadowMetadata(t._stateKey, t._path) || {}, _ = h.signals || [];
1645
1648
  _.push({
1646
1649
  instanceId: m.current,
1647
- parentId: n,
1650
+ parentId: o,
1648
1651
  position: b,
1649
1652
  effect: t._effect
1650
1653
  }), e.getState().setShadowMetadata(t._stateKey, t._path, {
@@ -1666,11 +1669,11 @@ function zt({
1666
1669
  T.replaceWith(R), g.current = !0;
1667
1670
  }, 0);
1668
1671
  return () => {
1669
- if (clearTimeout(i), m.current) {
1670
- const f = e.getState().getShadowMetadata(t._stateKey, t._path) || {};
1671
- f.signals && (f.signals = f.signals.filter(
1672
+ if (clearTimeout(s), m.current) {
1673
+ const l = e.getState().getShadowMetadata(t._stateKey, t._path) || {};
1674
+ l.signals && (l.signals = l.signals.filter(
1672
1675
  (P) => P.instanceId !== m.current
1673
- ), e.getState().setShadowMetadata(t._stateKey, t._path, f));
1676
+ ), e.getState().setShadowMetadata(t._stateKey, t._path, l));
1674
1677
  }
1675
1678
  };
1676
1679
  }, []), ut("span", {
@@ -1716,20 +1719,20 @@ function Jt({
1716
1719
  rebuildStateShape: I,
1717
1720
  renderFn: T
1718
1721
  }) {
1719
- const [, i] = at({}), { ref: f, inView: P } = Nt(), b = z(null), n = Gt(b), h = z(!1), _ = [t, ...m].join(".");
1720
- kt(t, a, i);
1722
+ const [, s] = at({}), { ref: l, inView: P } = Nt(), b = z(null), o = Gt(b), h = z(!1), _ = [t, ...m].join(".");
1723
+ Dt(t, a, s);
1721
1724
  const x = lt(
1722
1725
  (q) => {
1723
- b.current = q, f(q);
1726
+ b.current = q, l(q);
1724
1727
  },
1725
- [f]
1728
+ [l]
1726
1729
  );
1727
1730
  et(() => {
1728
1731
  e.getState().subscribeToPath(_, (q) => {
1729
- i({});
1732
+ s({});
1730
1733
  });
1731
1734
  }, []), et(() => {
1732
- if (!P || !n || h.current)
1735
+ if (!P || !o || h.current)
1733
1736
  return;
1734
1737
  const q = b.current;
1735
1738
  if (q && q.offsetHeight > 0) {
@@ -1748,7 +1751,7 @@ function Jt({
1748
1751
  ref: b.current
1749
1752
  });
1750
1753
  }
1751
- }, [P, n, t, m]);
1754
+ }, [P, o, t, m]);
1752
1755
  const R = [t, ...m].join("."), B = e.getState().getShadowValue(R);
1753
1756
  if (B === void 0)
1754
1757
  return null;
@@ -1767,14 +1770,14 @@ function Yt({
1767
1770
  formOpts: y,
1768
1771
  setState: I
1769
1772
  }) {
1770
- const [T] = at(() => nt()), [, i] = at({}), f = [t, ...a].join(".");
1771
- kt(t, T, i);
1772
- const P = e.getState().getShadowValue(f), [b, n] = at(P), h = z(!1), _ = z(null);
1773
+ const [T] = at(() => nt()), [, s] = at({}), l = [t, ...a].join(".");
1774
+ Dt(t, T, s);
1775
+ const P = e.getState().getShadowValue(l), [b, o] = at(P), h = z(!1), _ = z(null);
1773
1776
  et(() => {
1774
- !h.current && !ct(P, b) && n(P);
1777
+ !h.current && !ct(P, b) && o(P);
1775
1778
  }, [P]), et(() => {
1776
- const W = e.getState().subscribeToPath(f, (q) => {
1777
- !h.current && b !== q && i({});
1779
+ const W = e.getState().subscribeToPath(l, (q) => {
1780
+ !h.current && b !== q && s({});
1778
1781
  });
1779
1782
  return () => {
1780
1783
  W(), _.current && (clearTimeout(_.current), h.current = !1);
@@ -1782,16 +1785,16 @@ function Yt({
1782
1785
  }, []);
1783
1786
  const x = lt(
1784
1787
  (W) => {
1785
- typeof P === "number" && typeof W == "string" && (W = W === "" ? 0 : Number(W)), n(W), h.current = !0, _.current && clearTimeout(_.current);
1788
+ typeof P === "number" && typeof W == "string" && (W = W === "" ? 0 : Number(W)), o(W), h.current = !0, _.current && clearTimeout(_.current);
1786
1789
  const p = y?.debounceTime ?? 200;
1787
1790
  _.current = setTimeout(() => {
1788
1791
  h.current = !1, I(W, a, { updateType: "update" });
1789
- const { getInitialOptions: Y, setShadowMetadata: tt, getShadowMetadata: Q } = e.getState(), r = Y(t)?.validation, o = r?.zodSchemaV4 || r?.zodSchemaV3;
1790
- if (o) {
1791
- const s = e.getState().getShadowValue(t), l = o.safeParse(s), u = Q(t, a) || {};
1792
- if (l.success)
1792
+ const { getInitialOptions: Y, setShadowMetadata: tt, getShadowMetadata: Q } = e.getState(), r = Y(t)?.validation, n = r?.zodSchemaV4 || r?.zodSchemaV3;
1793
+ if (n) {
1794
+ const i = e.getState().getShadowValue(t), u = n.safeParse(i), d = Q(t, a) || {};
1795
+ if (u.success)
1793
1796
  tt(t, a, {
1794
- ...u,
1797
+ ...d,
1795
1798
  validation: {
1796
1799
  status: "VALID_LIVE",
1797
1800
  validatedValue: W,
@@ -1799,18 +1802,18 @@ function Yt({
1799
1802
  }
1800
1803
  });
1801
1804
  else {
1802
- const d = ("issues" in l.error ? l.error.issues : l.error.errors).filter(
1803
- (k) => JSON.stringify(k.path) === JSON.stringify(a)
1805
+ const f = ("issues" in u.error ? u.error.issues : u.error.errors).filter(
1806
+ (D) => JSON.stringify(D.path) === JSON.stringify(a)
1804
1807
  );
1805
- d.length > 0 ? tt(t, a, {
1806
- ...u,
1808
+ f.length > 0 ? tt(t, a, {
1809
+ ...d,
1807
1810
  validation: {
1808
1811
  status: "INVALID_LIVE",
1809
- message: d[0]?.message,
1812
+ message: f[0]?.message,
1810
1813
  validatedValue: W
1811
1814
  }
1812
1815
  }) : tt(t, a, {
1813
- ...u,
1816
+ ...d,
1814
1817
  validation: {
1815
1818
  status: "VALID_LIVE",
1816
1819
  validatedValue: W,
@@ -1819,7 +1822,7 @@ function Yt({
1819
1822
  });
1820
1823
  }
1821
1824
  }
1822
- }, p), i({});
1825
+ }, p), s({});
1823
1826
  },
1824
1827
  [I, a, y?.debounceTime, t]
1825
1828
  ), R = lt(async () => {
@@ -1846,40 +1849,40 @@ function Yt({
1846
1849
  else {
1847
1850
  const r = "issues" in Q.error ? Q.error.issues : Q.error.errors;
1848
1851
  console.log("All validation errors:", r), console.log("Current blur path:", a);
1849
- const o = r.filter((s) => {
1850
- if (console.log("Processing error:", s), a.some((u) => u.startsWith("id:"))) {
1852
+ const n = r.filter((i) => {
1853
+ if (console.log("Processing error:", i), a.some((d) => d.startsWith("id:"))) {
1851
1854
  console.log("Detected array path with ULID");
1852
- const u = a[0].startsWith("id:") ? [] : a.slice(0, -1);
1853
- console.log("Parent path:", u);
1854
- const c = e.getState().getShadowMetadata(t, u);
1855
+ const d = a[0].startsWith("id:") ? [] : a.slice(0, -1);
1856
+ console.log("Parent path:", d);
1857
+ const c = e.getState().getShadowMetadata(t, d);
1855
1858
  if (console.log("Array metadata:", c), c?.arrayKeys) {
1856
- const d = [t, ...a.slice(0, -1)].join("."), k = c.arrayKeys.indexOf(d);
1857
- console.log("Item key:", d, "Index:", k);
1858
- const M = [...u, k, ...a.slice(-1)], D = JSON.stringify(s.path) === JSON.stringify(M);
1859
+ const f = [t, ...a.slice(0, -1)].join("."), D = c.arrayKeys.indexOf(f);
1860
+ console.log("Item key:", f, "Index:", D);
1861
+ const M = [...d, D, ...a.slice(-1)], k = JSON.stringify(i.path) === JSON.stringify(M);
1859
1862
  return console.log("Zod path comparison:", {
1860
1863
  zodPath: M,
1861
- errorPath: s.path,
1862
- match: D
1863
- }), D;
1864
+ errorPath: i.path,
1865
+ match: k
1866
+ }), k;
1864
1867
  }
1865
1868
  }
1866
- const l = JSON.stringify(s.path) === JSON.stringify(a);
1869
+ const u = JSON.stringify(i.path) === JSON.stringify(a);
1867
1870
  return console.log("Direct path comparison:", {
1868
- errorPath: s.path,
1871
+ errorPath: i.path,
1869
1872
  currentPath: a,
1870
- match: l
1871
- }), l;
1873
+ match: u
1874
+ }), u;
1872
1875
  });
1873
- console.log("Filtered path errors:", o), e.getState().setShadowMetadata(t, a, {
1876
+ console.log("Filtered path errors:", n), e.getState().setShadowMetadata(t, a, {
1874
1877
  ...Y,
1875
1878
  validation: {
1876
1879
  status: "VALIDATION_FAILED",
1877
- message: o[0]?.message,
1880
+ message: n[0]?.message,
1878
1881
  validatedValue: b
1879
1882
  }
1880
1883
  });
1881
1884
  }
1882
- i({});
1885
+ s({});
1883
1886
  }, [t, a, b, I]), B = m({
1884
1887
  currentState: P,
1885
1888
  path: a,
@@ -1899,7 +1902,7 @@ function Yt({
1899
1902
  });
1900
1903
  return /* @__PURE__ */ it(At, { formOpts: y, path: a, stateKey: t, children: g(S) });
1901
1904
  }
1902
- function kt(t, a, m) {
1905
+ function Dt(t, a, m) {
1903
1906
  const g = `${t}////${a}`;
1904
1907
  dt(() => {
1905
1908
  const { registerComponent: y, unregisterComponent: I } = e.getState();