cogsbox-state 0.5.467 → 0.5.468

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.
@@ -1,11 +1,11 @@
1
1
  "use client";
2
2
  import { jsx as ie, Fragment as Ce } from "react/jsx-runtime";
3
- import { useState as K, useRef as L, useEffect as W, useCallback as pe, useLayoutEffect as ce, useMemo as we, createElement as Ie, startTransition as De } from "react";
3
+ import { useState as K, useRef as L, useEffect as W, useCallback as we, useLayoutEffect as ce, useMemo as pe, createElement as be, startTransition as De } from "react";
4
4
  import { transformStateFunc as Ue, isFunction as z, isDeepEqual as ae, isArray as Fe, getDifferences as $e } from "./utility.js";
5
5
  import { ValidationWrapper as Ne, FormElementWrapper as Oe, MemoizedCogsItemWrapper as je } from "./Components.jsx";
6
6
  import xe from "superjson";
7
7
  import { v4 as X } from "uuid";
8
- import { getGlobalStore as T, formRefStore as Ee } from "./store.js";
8
+ import { getGlobalStore as T, formRefStore as Me } from "./store.js";
9
9
  import { useCogsConfig as Ve } from "./CogsStateClient.jsx";
10
10
  const {
11
11
  getInitialOptions: G,
@@ -23,8 +23,8 @@ const {
23
23
  setInitialStateOptions: le,
24
24
  setServerStateUpdate: We,
25
25
  markAsDirty: ue,
26
- registerComponent: It,
27
- unregisterComponent: bt,
26
+ registerComponent: bt,
27
+ unregisterComponent: Et,
28
28
  addPathComponent: Ge,
29
29
  clearSelectedIndexesForState: He,
30
30
  addStateLog: ze,
@@ -32,7 +32,7 @@ const {
32
32
  clearSelectedIndex: Ze,
33
33
  getSyncInfo: Ye,
34
34
  notifyPathSubscribers: Qe,
35
- subscribeToPath: Et
35
+ subscribeToPath: Mt
36
36
  // Note: The old functions are no longer imported under their original names
37
37
  } = T.getState();
38
38
  function B(e, r, l) {
@@ -58,7 +58,7 @@ function ve(e, r) {
58
58
  ...r
59
59
  });
60
60
  }
61
- function Me({
61
+ function Ae({
62
62
  stateKey: e,
63
63
  options: r,
64
64
  initialOptionsPart: l
@@ -70,26 +70,26 @@ function Me({
70
70
  s.hasOwnProperty(i) ? (i == "localStorage" && r[i] && s[i].key !== r[i]?.key && (c = !0, s[i] = r[i]), i == "defaultState" && r[i] && s[i] !== r[i] && !ae(s[i], r[i]) && (c = !0, s[i] = r[i])) : (c = !0, s[i] = r[i]);
71
71
  s.syncOptions && (!r || !r.hasOwnProperty("syncOptions")) && (c = !0), c && le(e, s);
72
72
  }
73
- function Mt(e, { formElements: r, validation: l }) {
73
+ function At(e, { formElements: r, validation: l }) {
74
74
  return { initialState: e, formElements: r, validation: l };
75
75
  }
76
76
  const Xe = (e, r) => {
77
77
  let l = e;
78
78
  const [a, S] = Ue(l);
79
79
  r?.__fromSyncSchema && r?.__syncNotifications && T.getState().setInitialStateOptions("__notifications", r.__syncNotifications), r?.__fromSyncSchema && r?.__apiParamsMap && T.getState().setInitialStateOptions("__apiParamsMap", r.__apiParamsMap), Object.keys(a).forEach((i) => {
80
- let f = S[i] || {};
80
+ let d = S[i] || {};
81
81
  const t = {
82
- ...f
82
+ ...d
83
83
  };
84
84
  if (r?.formElements && (t.formElements = {
85
85
  ...r.formElements,
86
- ...f.formElements || {}
86
+ ...d.formElements || {}
87
87
  }), r?.validation && (t.validation = {
88
88
  ...r.validation,
89
- ...f.validation || {}
90
- }, r.validation.key && !f.validation?.key && (t.validation.key = `${r.validation.key}.${i}`)), r?.__syncSchemas?.[i]?.schemas?.validation && (t.validation = {
89
+ ...d.validation || {}
90
+ }, r.validation.key && !d.validation?.key && (t.validation.key = `${r.validation.key}.${i}`)), r?.__syncSchemas?.[i]?.schemas?.validation && (t.validation = {
91
91
  zodSchemaV4: r.__syncSchemas[i].schemas.validation,
92
- ...f.validation
92
+ ...d.validation
93
93
  }), Object.keys(t).length > 0) {
94
94
  const u = G(i);
95
95
  u ? le(i, {
@@ -100,35 +100,35 @@ const Xe = (e, r) => {
100
100
  }), Object.keys(a).forEach((i) => {
101
101
  oe(i, a[i]);
102
102
  });
103
- const s = (i, f) => {
104
- const [t] = K(f?.componentId ?? X());
105
- Me({
103
+ const s = (i, d) => {
104
+ const [t] = K(d?.componentId ?? X());
105
+ Ae({
106
106
  stateKey: i,
107
- options: f,
107
+ options: d,
108
108
  initialOptionsPart: S
109
109
  });
110
- const u = R(i, []) || a[i], I = f?.modifyState ? f.modifyState(u) : u;
111
- return lt(I, {
110
+ const u = R(i, []) || a[i], b = d?.modifyState ? d.modifyState(u) : u;
111
+ return lt(b, {
112
112
  stateKey: i,
113
- syncUpdate: f?.syncUpdate,
113
+ syncUpdate: d?.syncUpdate,
114
114
  componentId: t,
115
- localStorage: f?.localStorage,
116
- middleware: f?.middleware,
117
- reactiveType: f?.reactiveType,
118
- reactiveDeps: f?.reactiveDeps,
119
- defaultState: f?.defaultState,
120
- dependencies: f?.dependencies,
121
- serverState: f?.serverState,
122
- syncOptions: f?.syncOptions,
115
+ localStorage: d?.localStorage,
116
+ middleware: d?.middleware,
117
+ reactiveType: d?.reactiveType,
118
+ reactiveDeps: d?.reactiveDeps,
119
+ defaultState: d?.defaultState,
120
+ dependencies: d?.dependencies,
121
+ serverState: d?.serverState,
122
+ syncOptions: d?.syncOptions,
123
123
  __useSync: r?.__useSync
124
124
  });
125
125
  };
126
- function c(i, f) {
127
- Me({ stateKey: i, options: f, initialOptionsPart: S }), f.localStorage && et(i, f), be(i);
126
+ function c(i, d) {
127
+ Ae({ stateKey: i, options: d, initialOptionsPart: S }), d.localStorage && et(i, d), Ee(i);
128
128
  }
129
129
  return { useCogsState: s, setCogsOptions: c };
130
130
  };
131
- function At(e, r) {
131
+ function It(e, r) {
132
132
  const l = e.schemas, a = {}, S = {};
133
133
  for (const s in l) {
134
134
  const c = l[s];
@@ -157,12 +157,12 @@ const Ke = (e, r, l, a, S) => {
157
157
  i = Se(c)?.lastSyncedWithServer;
158
158
  } catch {
159
159
  }
160
- const f = V(r, []), t = {
160
+ const d = V(r, []), t = {
161
161
  state: e,
162
162
  lastUpdated: Date.now(),
163
163
  lastSyncedWithServer: i,
164
- stateSource: f?.stateSource,
165
- baseServerState: f?.baseServerState
164
+ stateSource: d?.stateSource,
165
+ baseServerState: d?.baseServerState
166
166
  }, u = xe.serialize(t);
167
167
  window.localStorage.setItem(
168
168
  c,
@@ -184,10 +184,10 @@ const Ke = (e, r, l, a, S) => {
184
184
  `${a}-${e}-${S}`
185
185
  );
186
186
  if (s && s.lastUpdated > (s.lastSyncedWithServer || 0))
187
- return be(e), !0;
187
+ return Ee(e), !0;
188
188
  }
189
189
  return !1;
190
- }, be = (e) => {
190
+ }, Ee = (e) => {
191
191
  const r = V(e, []);
192
192
  if (!r) return;
193
193
  const l = /* @__PURE__ */ new Set();
@@ -197,7 +197,7 @@ const Ke = (e, r, l, a, S) => {
197
197
  l.forEach((a) => a());
198
198
  });
199
199
  };
200
- function de(e, r, l, a) {
200
+ function fe(e, r, l, a) {
201
201
  const S = V(e, r);
202
202
  if (J(e, r, {
203
203
  ...S,
@@ -207,20 +207,20 @@ function de(e, r, l, a) {
207
207
  }), Array.isArray(l)) {
208
208
  const s = V(e, r);
209
209
  s?.arrayKeys && s.arrayKeys.forEach((c, i) => {
210
- const f = [...r, c], t = l[i];
211
- t !== void 0 && de(
210
+ const d = [...r, c], t = l[i];
211
+ t !== void 0 && fe(
212
212
  e,
213
- f,
213
+ d,
214
214
  t,
215
215
  a
216
216
  );
217
217
  });
218
218
  } else l && typeof l == "object" && l.constructor === Object && Object.keys(l).forEach((s) => {
219
219
  const c = [...r, s], i = l[s];
220
- de(e, c, i, a);
220
+ fe(e, c, i, a);
221
221
  });
222
222
  }
223
- let fe = [], Te = !1;
223
+ let de = [], Te = !1;
224
224
  function tt() {
225
225
  Te || (Te = !0, queueMicrotask(it));
226
226
  }
@@ -247,8 +247,8 @@ function nt(e, r) {
247
247
  i = new Function("state", `return (${S})(state)`)(
248
248
  r
249
249
  );
250
- } catch (f) {
251
- console.error("Error evaluating effect function:", f);
250
+ } catch (d) {
251
+ console.error("Error evaluating effect function:", d);
252
252
  }
253
253
  i !== null && typeof i == "object" && (i = JSON.stringify(i)), c[a].textContent = String(i ?? "");
254
254
  });
@@ -263,23 +263,23 @@ function at(e, r, l) {
263
263
  for (; ; ) {
264
264
  const c = V(e, s);
265
265
  if (c?.pathComponents && c.pathComponents.forEach((i) => {
266
- const f = a.components?.get(i);
267
- f && ((Array.isArray(f.reactiveType) ? f.reactiveType : [f.reactiveType || "component"]).includes("none") || S.add(f));
266
+ const d = a.components?.get(i);
267
+ d && ((Array.isArray(d.reactiveType) ? d.reactiveType : [d.reactiveType || "component"]).includes("none") || S.add(d));
268
268
  }), s.length === 0) break;
269
269
  s.pop();
270
270
  }
271
271
  l.newValue && typeof l.newValue == "object" && !Fe(l.newValue) && $e(l.newValue, l.oldValue).forEach((i) => {
272
- const f = i.split("."), t = [...r, ...f], u = V(e, t);
273
- u?.pathComponents && u.pathComponents.forEach((I) => {
274
- const U = a.components?.get(I);
272
+ const d = i.split("."), t = [...r, ...d], u = V(e, t);
273
+ u?.pathComponents && u.pathComponents.forEach((b) => {
274
+ const U = a.components?.get(b);
275
275
  U && ((Array.isArray(U.reactiveType) ? U.reactiveType : [U.reactiveType || "component"]).includes("none") || S.add(U));
276
276
  });
277
277
  });
278
278
  } else if (l.type === "insert" || l.type === "cut") {
279
279
  const s = l.type === "insert" ? r : r.slice(0, -1), c = V(e, s);
280
280
  c?.pathComponents && c.pathComponents.forEach((i) => {
281
- const f = a.components?.get(i);
282
- f && S.add(f);
281
+ const d = a.components?.get(i);
282
+ d && S.add(d);
283
283
  });
284
284
  }
285
285
  return a.components.forEach((s, c) => {
@@ -289,7 +289,7 @@ function at(e, r, l) {
289
289
  if (i.includes("all"))
290
290
  S.add(s);
291
291
  else if (i.includes("deps") && s.depsFunction) {
292
- const f = R(e, []), t = s.depsFunction(f);
292
+ const d = R(e, []), t = s.depsFunction(d);
293
293
  (t === !0 || Array.isArray(t) && !ae(s.prevDeps, t)) && (s.prevDeps = t, S.add(s));
294
294
  }
295
295
  }), S;
@@ -318,7 +318,7 @@ function st(e, r) {
318
318
  }
319
319
  function it() {
320
320
  const e = /* @__PURE__ */ new Set(), r = [], l = [];
321
- for (const a of fe) {
321
+ for (const a of de) {
322
322
  if (a.status && a.updateType) {
323
323
  l.push(a);
324
324
  continue;
@@ -336,15 +336,15 @@ function it() {
336
336
  nt(a, S);
337
337
  }), e.forEach((a) => {
338
338
  a.forceUpdate();
339
- }), fe = [], Te = !1;
339
+ }), de = [], Te = !1;
340
340
  }
341
341
  function ct(e, r, l, a) {
342
- return (s, c, i, f) => {
342
+ return (s, c, i, d) => {
343
343
  S(e, c, s, i);
344
344
  };
345
- function S(s, c, i, f) {
345
+ function S(s, c, i, d) {
346
346
  let t;
347
- switch (f.updateType) {
347
+ switch (d.updateType) {
348
348
  case "update":
349
349
  t = rt(s, c, i);
350
350
  break;
@@ -355,22 +355,22 @@ function ct(e, r, l, a) {
355
355
  t = st(s, c);
356
356
  break;
357
357
  }
358
- t.stateKey = s, t.path = c, fe.push(t), tt();
358
+ t.stateKey = s, t.path = c, de.push(t), tt();
359
359
  const u = {
360
360
  timeStamp: Date.now(),
361
361
  stateKey: s,
362
362
  path: c,
363
- updateType: f.updateType,
363
+ updateType: d.updateType,
364
364
  status: "new",
365
365
  oldValue: t.oldValue,
366
366
  newValue: t.newValue ?? null
367
367
  };
368
- fe.push(u), t.newValue !== void 0 && Ke(
368
+ de.push(u), t.newValue !== void 0 && Ke(
369
369
  t.newValue,
370
370
  s,
371
371
  a.current,
372
372
  l
373
- ), a.current?.middleware && a.current.middleware({ update: u }), f.sync !== !1 && r.current?.connected && r.current.updateState({ operation: u });
373
+ ), a.current?.middleware && a.current.middleware({ update: u }), d.sync !== !1 && r.current?.connected && r.current.updateState({ operation: u });
374
374
  }
375
375
  }
376
376
  function lt(e, {
@@ -381,160 +381,160 @@ function lt(e, {
381
381
  reactiveType: s,
382
382
  componentId: c,
383
383
  defaultState: i,
384
- syncUpdate: f,
384
+ syncUpdate: d,
385
385
  dependencies: t,
386
386
  serverState: u,
387
- __useSync: I
387
+ __useSync: b
388
388
  } = {}) {
389
389
  const [U, O] = K({}), { sessionId: F } = Ve();
390
390
  let x = !r;
391
- const [w] = K(r ?? X()), ee = L(c ?? X()), m = L(
391
+ const [p] = K(r ?? X()), ee = L(c ?? X()), m = L(
392
392
  null
393
393
  );
394
- m.current = G(w) ?? null, W(() => {
395
- if (f && f.stateKey === w && f.path?.[0]) {
396
- const g = `${f.stateKey}:${f.path.join(".")}`;
394
+ m.current = G(p) ?? null, W(() => {
395
+ if (d && d.stateKey === p && d.path?.[0]) {
396
+ const g = `${d.stateKey}:${d.path.join(".")}`;
397
397
  Je(g, {
398
- timeStamp: f.timeStamp,
399
- userId: f.userId
398
+ timeStamp: d.timeStamp,
399
+ userId: d.userId
400
400
  });
401
401
  }
402
- }, [f]);
403
- const te = pe(
402
+ }, [d]);
403
+ const te = we(
404
404
  (g) => {
405
- const p = g ? { ...G(w), ...g } : G(w), b = p?.defaultState || i || e;
406
- if (p?.serverState?.status === "success" && p?.serverState?.data !== void 0)
405
+ const w = g ? { ...G(p), ...g } : G(p), E = w?.defaultState || i || e;
406
+ if (w?.serverState?.status === "success" && w?.serverState?.data !== void 0)
407
407
  return {
408
- value: p.serverState.data,
408
+ value: w.serverState.data,
409
409
  source: "server",
410
- timestamp: p.serverState.timestamp || Date.now()
410
+ timestamp: w.serverState.timestamp || Date.now()
411
411
  };
412
- if (p?.localStorage?.key && F) {
413
- const M = z(p.localStorage.key) ? p.localStorage.key(b) : p.localStorage.key, A = Se(
414
- `${F}-${w}-${M}`
412
+ if (w?.localStorage?.key && F) {
413
+ const A = z(w.localStorage.key) ? w.localStorage.key(E) : w.localStorage.key, I = Se(
414
+ `${F}-${p}-${A}`
415
415
  );
416
- if (A && A.lastUpdated > (p?.serverState?.timestamp || 0))
416
+ if (I && I.lastUpdated > (w?.serverState?.timestamp || 0))
417
417
  return {
418
- value: A.state,
418
+ value: I.state,
419
419
  source: "localStorage",
420
- timestamp: A.lastUpdated
420
+ timestamp: I.lastUpdated
421
421
  };
422
422
  }
423
423
  return {
424
- value: b || e,
424
+ value: E || e,
425
425
  source: "default",
426
426
  timestamp: Date.now()
427
427
  };
428
428
  },
429
- [w, i, e, F]
429
+ [p, i, e, F]
430
430
  );
431
431
  W(() => {
432
- We(w, u);
433
- }, [u, w]), W(() => T.getState().subscribeToPath(w, (y) => {
432
+ We(p, u);
433
+ }, [u, p]), W(() => T.getState().subscribeToPath(p, (y) => {
434
434
  if (y?.type === "SERVER_STATE_UPDATE") {
435
- const p = y.serverState;
436
- if (p?.status !== "success" || p.data === void 0)
435
+ const w = y.serverState;
436
+ if (w?.status !== "success" || w.data === void 0)
437
437
  return;
438
- ve(w, { serverState: p });
439
- const b = typeof p.merge == "object" ? p.merge : p.merge === !0 ? { strategy: "append" } : null, _ = R(w, []), M = p.data;
440
- if (b && b.strategy === "append" && "key" in b && // Type guard for key
441
- Array.isArray(_) && Array.isArray(M)) {
442
- const A = b.key;
443
- if (!A) {
438
+ ve(p, { serverState: w });
439
+ const E = typeof w.merge == "object" ? w.merge : w.merge === !0 ? { strategy: "append" } : null, _ = R(p, []), A = w.data;
440
+ if (E && E.strategy === "append" && "key" in E && // Type guard for key
441
+ Array.isArray(_) && Array.isArray(A)) {
442
+ const I = E.key;
443
+ if (!I) {
444
444
  console.error(
445
445
  "CogsState: Merge strategy 'append' requires a 'key' field."
446
446
  );
447
447
  return;
448
448
  }
449
449
  const D = new Set(
450
- _.map((N) => N[A])
451
- ), E = M.filter(
452
- (N) => !D.has(N[A])
450
+ _.map((N) => N[I])
451
+ ), M = A.filter(
452
+ (N) => !D.has(N[I])
453
453
  );
454
- E.length > 0 && qe(w, [], E);
455
- const k = R(w, []);
456
- de(
457
- w,
454
+ M.length > 0 && qe(p, [], M);
455
+ const k = R(p, []);
456
+ fe(
457
+ p,
458
458
  [],
459
459
  k,
460
- p.timestamp
460
+ w.timestamp
461
461
  );
462
462
  } else
463
- oe(w, M), de(
464
- w,
463
+ oe(p, A), fe(
464
+ p,
465
465
  [],
466
- M,
467
- p.timestamp
466
+ A,
467
+ w.timestamp
468
468
  );
469
469
  }
470
- }), [w, te]), W(() => {
471
- const g = T.getState().getShadowMetadata(w, []);
470
+ }), [p, te]), W(() => {
471
+ const g = T.getState().getShadowMetadata(p, []);
472
472
  if (g && g.stateSource)
473
473
  return;
474
- const y = G(w), p = {
474
+ const y = G(p), w = {
475
475
  syncEnabled: !!v && !!h,
476
476
  validationEnabled: !!(y?.validation?.zodSchemaV4 || y?.validation?.zodSchemaV3),
477
477
  localStorageEnabled: !!y?.localStorage?.key
478
478
  };
479
- if (J(w, [], {
479
+ if (J(p, [], {
480
480
  ...g,
481
- features: p
481
+ features: w
482
482
  }), y?.defaultState !== void 0 || i !== void 0) {
483
- const b = y?.defaultState || i;
484
- y?.defaultState || ve(w, {
485
- defaultState: b
483
+ const E = y?.defaultState || i;
484
+ y?.defaultState || ve(p, {
485
+ defaultState: E
486
486
  });
487
- const { value: _, source: M, timestamp: A } = te();
488
- oe(w, _), J(w, [], {
489
- stateSource: M,
490
- lastServerSync: M === "server" ? A : void 0,
487
+ const { value: _, source: A, timestamp: I } = te();
488
+ oe(p, _), J(p, [], {
489
+ stateSource: A,
490
+ lastServerSync: A === "server" ? I : void 0,
491
491
  isDirty: !1,
492
- baseServerState: M === "server" ? _ : void 0
493
- }), be(w);
492
+ baseServerState: A === "server" ? _ : void 0
493
+ }), Ee(p);
494
494
  }
495
- }, [w, ...t || []]), ce(() => {
496
- x && ve(w, {
495
+ }, [p, ...t || []]), ce(() => {
496
+ x && ve(p, {
497
497
  formElements: a,
498
498
  defaultState: i,
499
499
  localStorage: l,
500
500
  middleware: m.current?.middleware
501
501
  });
502
- const g = `${w}////${ee.current}`, y = V(w, []), p = y?.components || /* @__PURE__ */ new Map();
503
- return p.set(g, {
502
+ const g = `${p}////${ee.current}`, y = V(p, []), w = y?.components || /* @__PURE__ */ new Map();
503
+ return w.set(g, {
504
504
  forceUpdate: () => O({}),
505
505
  reactiveType: s ?? ["component"],
506
506
  paths: /* @__PURE__ */ new Set(),
507
507
  depsFunction: S || void 0,
508
- deps: S ? S(R(w, [])) : [],
509
- prevDeps: S ? S(R(w, [])) : []
510
- }), J(w, [], {
508
+ deps: S ? S(R(p, [])) : [],
509
+ prevDeps: S ? S(R(p, [])) : []
510
+ }), J(p, [], {
511
511
  ...y,
512
- components: p
512
+ components: w
513
513
  }), O({}), () => {
514
- const b = V(w, []), _ = b?.components?.get(g);
515
- _?.paths && _.paths.forEach((M) => {
516
- const D = M.split(".").slice(1), E = T.getState().getShadowMetadata(w, D);
517
- E?.pathComponents && E.pathComponents.size === 0 && (delete E.pathComponents, T.getState().setShadowMetadata(w, D, E));
518
- }), b?.components && J(w, [], b);
514
+ const E = V(p, []), _ = E?.components?.get(g);
515
+ _?.paths && _.paths.forEach((A) => {
516
+ const D = A.split(".").slice(1), M = T.getState().getShadowMetadata(p, D);
517
+ M?.pathComponents && M.pathComponents.size === 0 && (delete M.pathComponents, T.getState().setShadowMetadata(p, D, M));
518
+ }), E?.components && J(p, [], E);
519
519
  };
520
520
  }, []);
521
521
  const o = L(null), n = ct(
522
- w,
522
+ p,
523
523
  o,
524
524
  F,
525
525
  m
526
526
  );
527
- T.getState().initialStateGlobal[w] || ke(w, e);
528
- const d = we(() => Pe(
529
- w,
527
+ T.getState().initialStateGlobal[p] || ke(p, e);
528
+ const f = pe(() => Pe(
529
+ p,
530
530
  n,
531
531
  ee.current,
532
532
  F
533
- ), [w, F]), v = I, h = m.current?.syncOptions;
533
+ ), [p, F]), v = b, h = m.current?.syncOptions;
534
534
  return v && (o.current = v(
535
- d,
535
+ f,
536
536
  h ?? {}
537
- )), d;
537
+ )), f;
538
538
  }
539
539
  const ut = (e, r, l) => {
540
540
  let a = V(e, r)?.arrayKeys || [];
@@ -544,16 +544,16 @@ const ut = (e, r, l) => {
544
544
  for (const s of S)
545
545
  if (s.type === "filter") {
546
546
  const c = [];
547
- a.forEach((i, f) => {
547
+ a.forEach((i, d) => {
548
548
  const t = R(e, [...r, i]);
549
- s.fn(t, f) && c.push(i);
549
+ s.fn(t, d) && c.push(i);
550
550
  }), a = c;
551
551
  } else s.type === "sort" && a.sort((c, i) => {
552
- const f = R(e, [...r, c]), t = R(e, [...r, i]);
553
- return s.fn(f, t);
552
+ const d = R(e, [...r, c]), t = R(e, [...r, i]);
553
+ return s.fn(d, t);
554
554
  });
555
555
  return a;
556
- }, Ae = (e, r, l) => {
556
+ }, Ie = (e, r, l) => {
557
557
  const a = `${e}////${r}`, s = V(e, [])?.components?.get(a);
558
558
  !s || s.reactiveType === "none" || !(Array.isArray(s.reactiveType) ? s.reactiveType : [s.reactiveType]).includes("component") || Ge(e, l, a);
559
559
  }, ne = (e, r, l) => {
@@ -568,8 +568,8 @@ const ut = (e, r, l) => {
568
568
  });
569
569
  const s = V(e, r);
570
570
  for (let c of s?.arrayKeys || []) {
571
- const i = c + ".selected", f = V(e, i.split(".").slice(1));
572
- c == l && f?.pathComponents?.forEach((t) => {
571
+ const i = c + ".selected", d = V(e, i.split(".").slice(1));
572
+ c == l && d?.pathComponents?.forEach((t) => {
573
573
  a?.components?.get(t)?.forceUpdate();
574
574
  });
575
575
  }
@@ -644,9 +644,9 @@ function Pe(e, r, l, a) {
644
644
  function c({
645
645
  path: t = [],
646
646
  meta: u,
647
- componentId: I
647
+ componentId: b
648
648
  }) {
649
- const U = u ? JSON.stringify(u.arrayViews || u.transforms) : "", O = t.join(".") + ":" + U;
649
+ const U = u ? JSON.stringify(u.arrayViews || u.transforms) : "", O = t.join(".") + ":" + b + ":" + U;
650
650
  if (S.has(O))
651
651
  return S.get(O);
652
652
  const F = [e, ...t].join("."), x = {
@@ -657,7 +657,7 @@ function Pe(e, r, l, a) {
657
657
  const o = [...t, m];
658
658
  return c({
659
659
  path: o,
660
- componentId: I,
660
+ componentId: b,
661
661
  meta: u
662
662
  });
663
663
  }
@@ -668,9 +668,9 @@ function Pe(e, r, l, a) {
668
668
  const o = T.getState().getInitialOptions(e), n = o?.sync;
669
669
  if (!n)
670
670
  return console.error(`No mutation defined for state key "${e}"`), { success: !1, error: "No mutation defined" };
671
- const d = T.getState().getShadowValue(e, []), v = o?.validation?.key;
671
+ const f = T.getState().getShadowValue(e, []), v = o?.validation?.key;
672
672
  try {
673
- const h = await n.action(d);
673
+ const h = await n.action(f);
674
674
  if (h && !h.success && h.errors, h?.success) {
675
675
  const g = T.getState().getShadowMetadata(e, []);
676
676
  J(e, [], {
@@ -678,7 +678,7 @@ function Pe(e, r, l, a) {
678
678
  isDirty: !1,
679
679
  lastServerSync: Date.now(),
680
680
  stateSource: "server",
681
- baseServerState: d
681
+ baseServerState: f
682
682
  // Update base server state
683
683
  }), n.onSuccess && n.onSuccess(h.data);
684
684
  } else !h?.success && n.onError && n.onError(h.error);
@@ -689,14 +689,14 @@ function Pe(e, r, l, a) {
689
689
  };
690
690
  if (m === "_status" || m === "getStatus") {
691
691
  const o = () => {
692
- const { shadowMeta: n, value: d } = Q(e, t, u);
693
- return n?.isDirty === !0 ? "dirty" : n?.stateSource === "server" || n?.isDirty === !1 ? "synced" : n?.stateSource === "localStorage" ? "restored" : n?.stateSource === "default" || d !== void 0 && !n ? "fresh" : "unknown";
692
+ const { shadowMeta: n, value: f } = Q(e, t, u);
693
+ return n?.isDirty === !0 ? "dirty" : n?.stateSource === "server" || n?.isDirty === !1 ? "synced" : n?.stateSource === "localStorage" ? "restored" : n?.stateSource === "default" || f !== void 0 && !n ? "fresh" : "unknown";
694
694
  };
695
695
  return m === "_status" ? o() : o;
696
696
  }
697
697
  if (m === "removeStorage")
698
698
  return () => {
699
- const o = T.getState().initialStateGlobal[e], n = G(e), d = z(n?.localStorage?.key) ? n.localStorage.key(o) : n?.localStorage?.key, v = `${a}-${e}-${d}`;
699
+ const o = T.getState().initialStateGlobal[e], n = G(e), f = z(n?.localStorage?.key) ? n.localStorage.key(o) : n?.localStorage?.key, v = `${a}-${e}-${f}`;
700
700
  v && localStorage.removeItem(v);
701
701
  };
702
702
  if (m === "showValidationErrors")
@@ -707,21 +707,21 @@ function Pe(e, r, l, a) {
707
707
  if (m === "getSelected")
708
708
  return () => {
709
709
  const o = [e, ...t].join(".");
710
- Ae(e, I, [
710
+ Ie(e, b, [
711
711
  ...t,
712
712
  "getSelected"
713
713
  ]);
714
714
  const n = T.getState().selectedIndicesMap.get(o);
715
715
  if (!n)
716
716
  return;
717
- const d = t.join("."), v = u?.arrayViews?.[d], h = n.split(".").pop();
717
+ const f = t.join("."), v = u?.arrayViews?.[f], h = n.split(".").pop();
718
718
  if (!(v && !v.includes(h) || R(
719
719
  e,
720
720
  n.split(".").slice(1)
721
721
  ) === void 0))
722
722
  return c({
723
723
  path: n.split(".").slice(1),
724
- componentId: I,
724
+ componentId: b,
725
725
  meta: u
726
726
  });
727
727
  };
@@ -732,11 +732,11 @@ function Pe(e, r, l, a) {
732
732
  const n = T.getState().selectedIndicesMap.get(o);
733
733
  if (!n)
734
734
  return -1;
735
- const { keys: d } = B(e, t, u);
736
- if (!d)
735
+ const { keys: f } = B(e, t, u);
736
+ if (!f)
737
737
  return -1;
738
738
  const v = n.split(".").pop();
739
- return d.indexOf(v);
739
+ return f.indexOf(v);
740
740
  };
741
741
  if (m === "clearSelected")
742
742
  return ne(e, t), () => {
@@ -748,27 +748,27 @@ function Pe(e, r, l, a) {
748
748
  return (o) => {
749
749
  const {
750
750
  itemHeight: n = 50,
751
- overscan: d = 6,
751
+ overscan: f = 6,
752
752
  stickToBottom: v = !1,
753
753
  scrollStickTolerance: h = 75
754
- } = o, g = L(null), [y, p] = K({
754
+ } = o, g = L(null), [y, w] = K({
755
755
  startIndex: 0,
756
756
  endIndex: 10
757
- }), [b, _] = K({}), M = L(!0);
757
+ }), [E, _] = K({}), A = L(!0);
758
758
  W(() => {
759
759
  const C = setInterval(() => {
760
760
  _({});
761
761
  }, 1e3);
762
762
  return () => clearInterval(C);
763
763
  }, []);
764
- const A = L({
764
+ const I = L({
765
765
  isUserScrolling: !1,
766
766
  lastScrollTop: 0,
767
767
  scrollUpCount: 0,
768
768
  isNearBottom: !0
769
769
  }), D = L(
770
770
  /* @__PURE__ */ new Map()
771
- ), { keys: E } = B(e, t, u);
771
+ ), { keys: M } = B(e, t, u);
772
772
  W(() => {
773
773
  const C = [e, ...t].join("."), P = T.getState().subscribeToPath(C, (j) => {
774
774
  j.type !== "GET_SELECTED" && j.type;
@@ -776,41 +776,41 @@ function Pe(e, r, l, a) {
776
776
  return () => {
777
777
  P();
778
778
  };
779
- }, [I, e, t.join(".")]), ce(() => {
780
- if (v && E.length > 0 && g.current && !A.current.isUserScrolling && M.current) {
779
+ }, [b, e, t.join(".")]), ce(() => {
780
+ if (v && M.length > 0 && g.current && !I.current.isUserScrolling && A.current) {
781
781
  const C = g.current, P = () => {
782
782
  if (C.clientHeight > 0) {
783
783
  const j = Math.ceil(
784
784
  C.clientHeight / n
785
- ), q = E.length - 1, $ = Math.max(
785
+ ), q = M.length - 1, $ = Math.max(
786
786
  0,
787
- q - j - d
787
+ q - j - f
788
788
  );
789
- p({ startIndex: $, endIndex: q }), requestAnimationFrame(() => {
790
- Y("instant"), M.current = !1;
789
+ w({ startIndex: $, endIndex: q }), requestAnimationFrame(() => {
790
+ Y("instant"), A.current = !1;
791
791
  });
792
792
  } else
793
793
  requestAnimationFrame(P);
794
794
  };
795
795
  P();
796
796
  }
797
- }, [E.length, v, n, d]);
797
+ }, [M.length, v, n, f]);
798
798
  const k = L(y);
799
799
  ce(() => {
800
800
  k.current = y;
801
801
  }, [y]);
802
- const N = L(E);
802
+ const N = L(M);
803
803
  ce(() => {
804
- N.current = E;
805
- }, [E]);
806
- const se = pe(() => {
804
+ N.current = M;
805
+ }, [M]);
806
+ const se = we(() => {
807
807
  const C = g.current;
808
808
  if (!C) return;
809
- const P = C.scrollTop, { scrollHeight: j, clientHeight: q } = C, $ = A.current, re = j - (P + q), ge = $.isNearBottom;
809
+ const P = C.scrollTop, { scrollHeight: j, clientHeight: q } = C, $ = I.current, re = j - (P + q), ge = $.isNearBottom;
810
810
  $.isNearBottom = re <= h, P < $.lastScrollTop ? ($.scrollUpCount++, $.scrollUpCount > 3 && ge && ($.isUserScrolling = !0, console.log("User scrolled away from bottom"))) : $.isNearBottom && ($.isUserScrolling = !1, $.scrollUpCount = 0), $.lastScrollTop = P;
811
811
  let Z = 0;
812
- for (let H = 0; H < E.length; H++) {
813
- const ye = E[H], me = D.current.get(ye);
812
+ for (let H = 0; H < M.length; H++) {
813
+ const ye = M[H], me = D.current.get(ye);
814
814
  if (me && me.offset + me.height > P) {
815
815
  Z = H;
816
816
  break;
@@ -823,19 +823,19 @@ function Pe(e, r, l, a) {
823
823
  y
824
824
  ), Z !== y.startIndex && y.startIndex != 0) {
825
825
  const H = Math.ceil(q / n);
826
- p({
827
- startIndex: Math.max(0, Z - d),
826
+ w({
827
+ startIndex: Math.max(0, Z - f),
828
828
  endIndex: Math.min(
829
- E.length - 1,
830
- Z + H + d
829
+ M.length - 1,
830
+ Z + H + f
831
831
  )
832
832
  });
833
833
  }
834
834
  }, [
835
- E.length,
835
+ M.length,
836
836
  y.startIndex,
837
837
  n,
838
- d,
838
+ f,
839
839
  h
840
840
  ]);
841
841
  W(() => {
@@ -847,11 +847,11 @@ function Pe(e, r, l, a) {
847
847
  C.removeEventListener("scroll", se);
848
848
  };
849
849
  }, [se, v]);
850
- const Y = pe(
850
+ const Y = we(
851
851
  (C = "smooth") => {
852
852
  const P = g.current;
853
853
  if (!P) return;
854
- A.current.isUserScrolling = !1, A.current.isNearBottom = !0, A.current.scrollUpCount = 0;
854
+ I.current.isUserScrolling = !1, I.current.isNearBottom = !0, I.current.scrollUpCount = 0;
855
855
  const j = () => {
856
856
  const q = ($ = 0) => {
857
857
  if ($ > 5) return;
@@ -874,12 +874,12 @@ function Pe(e, r, l, a) {
874
874
  );
875
875
  return W(() => {
876
876
  if (!v || !g.current) return;
877
- const C = g.current, P = A.current;
877
+ const C = g.current, P = I.current;
878
878
  let j;
879
879
  const q = () => {
880
880
  clearTimeout(j), j = setTimeout(() => {
881
881
  !P.isUserScrolling && P.isNearBottom && Y(
882
- M.current ? "instant" : "smooth"
882
+ A.current ? "instant" : "smooth"
883
883
  );
884
884
  }, 100);
885
885
  }, $ = new MutationObserver(() => {
@@ -890,24 +890,24 @@ function Pe(e, r, l, a) {
890
890
  subtree: !0,
891
891
  attributes: !0,
892
892
  attributeFilter: ["style", "class"]
893
- }), M.current ? setTimeout(() => {
893
+ }), A.current ? setTimeout(() => {
894
894
  Y("instant");
895
895
  }, 0) : q(), () => {
896
896
  clearTimeout(j), $.disconnect();
897
897
  };
898
- }, [v, E.length, Y]), {
899
- virtualState: we(() => {
900
- const C = Array.isArray(E) ? E.slice(y.startIndex, y.endIndex + 1) : [], P = t.length > 0 ? t.join(".") : "root";
898
+ }, [v, M.length, Y]), {
899
+ virtualState: pe(() => {
900
+ const C = Array.isArray(M) ? M.slice(y.startIndex, y.endIndex + 1) : [], P = t.length > 0 ? t.join(".") : "root";
901
901
  return c({
902
902
  path: t,
903
- componentId: I,
903
+ componentId: b,
904
904
  meta: {
905
905
  ...u,
906
906
  arrayViews: { [P]: C },
907
907
  serverStateIsUpStream: !0
908
908
  }
909
909
  });
910
- }, [y.startIndex, y.endIndex, E, u]),
910
+ }, [y.startIndex, y.endIndex, M, u]),
911
911
  virtualizerProps: {
912
912
  outer: {
913
913
  ref: g,
@@ -924,14 +924,14 @@ function Pe(e, r, l, a) {
924
924
  },
925
925
  list: {
926
926
  style: {
927
- transform: `translateY(${D.current.get(E[y.startIndex])?.offset || 0}px)`
927
+ transform: `translateY(${D.current.get(M[y.startIndex])?.offset || 0}px)`
928
928
  }
929
929
  }
930
930
  },
931
931
  scrollToBottom: Y,
932
932
  scrollToIndex: (C, P = "smooth") => {
933
- if (g.current && E[C]) {
934
- const j = D.current.get(E[C])?.offset || 0;
933
+ if (g.current && M[C]) {
934
+ const j = D.current.get(M[C])?.offset || 0;
935
935
  g.current.scrollTo({ top: j, behavior: P });
936
936
  }
937
937
  }
@@ -939,33 +939,33 @@ function Pe(e, r, l, a) {
939
939
  };
940
940
  if (m === "stateMap")
941
941
  return (o) => {
942
- const { value: n, keys: d } = B(
942
+ const { value: n, keys: f } = B(
943
943
  e,
944
944
  t,
945
945
  u
946
946
  );
947
- if (!d || !Array.isArray(n))
947
+ if (!f || !Array.isArray(n))
948
948
  return [];
949
949
  const v = c({
950
950
  path: t,
951
- componentId: I,
951
+ componentId: b,
952
952
  meta: u
953
953
  });
954
954
  return n.map((h, g) => {
955
- const y = d[g];
955
+ const y = f[g];
956
956
  if (!y) return;
957
- const p = [...t, y], b = c({
958
- path: p,
957
+ const w = [...t, y], E = c({
958
+ path: w,
959
959
  // This now correctly points to the item in the shadow store.
960
- componentId: I,
960
+ componentId: b,
961
961
  meta: u
962
962
  });
963
- return o(b, g, v);
963
+ return o(E, g, v);
964
964
  });
965
965
  };
966
966
  if (m === "stateFilter")
967
967
  return (o) => {
968
- const n = t.length > 0 ? t.join(".") : "root", { keys: d, value: v } = B(
968
+ const n = t.length > 0 ? t.join(".") : "root", { keys: f, value: v } = B(
969
969
  e,
970
970
  t,
971
971
  u
@@ -975,12 +975,12 @@ function Pe(e, r, l, a) {
975
975
  const h = [];
976
976
  return v.forEach((g, y) => {
977
977
  if (o(g, y)) {
978
- const p = d[y];
979
- p && h.push(p);
978
+ const w = f[y];
979
+ w && h.push(w);
980
980
  }
981
981
  }), c({
982
982
  path: t,
983
- componentId: I,
983
+ componentId: b,
984
984
  meta: {
985
985
  ...u,
986
986
  arrayViews: {
@@ -996,22 +996,22 @@ function Pe(e, r, l, a) {
996
996
  };
997
997
  if (m === "stateSort")
998
998
  return (o) => {
999
- const n = t.length > 0 ? t.join(".") : "root", { value: d, keys: v } = B(
999
+ const n = t.length > 0 ? t.join(".") : "root", { value: f, keys: v } = B(
1000
1000
  e,
1001
1001
  t,
1002
1002
  u
1003
1003
  );
1004
- if (!Array.isArray(d) || !v)
1004
+ if (!Array.isArray(f) || !v)
1005
1005
  throw new Error("No array keys found for sorting");
1006
- const h = d.map((y, p) => ({
1006
+ const h = f.map((y, w) => ({
1007
1007
  item: y,
1008
- key: v[p]
1008
+ key: v[w]
1009
1009
  }));
1010
- h.sort((y, p) => o(y.item, p.item));
1010
+ h.sort((y, w) => o(y.item, w.item));
1011
1011
  const g = h.map((y) => y.key);
1012
1012
  return c({
1013
1013
  path: t,
1014
- componentId: I,
1014
+ componentId: b,
1015
1015
  meta: {
1016
1016
  ...u,
1017
1017
  arrayViews: {
@@ -1029,21 +1029,21 @@ function Pe(e, r, l, a) {
1029
1029
  return function(o = {}) {
1030
1030
  const {
1031
1031
  bufferSize: n = 100,
1032
- flushInterval: d = 100,
1032
+ flushInterval: f = 100,
1033
1033
  bufferStrategy: v = "accumulate",
1034
1034
  store: h,
1035
1035
  onFlush: g
1036
1036
  } = o;
1037
- let y = [], p = !1, b = null;
1037
+ let y = [], w = !1, E = null;
1038
1038
  const _ = (k) => {
1039
- if (!p) {
1039
+ if (!w) {
1040
1040
  if (v === "sliding" && y.length >= n)
1041
1041
  y.shift();
1042
1042
  else if (v === "dropping" && y.length >= n)
1043
1043
  return;
1044
- y.push(k), y.length >= n && M();
1044
+ y.push(k), y.length >= n && A();
1045
1045
  }
1046
- }, M = () => {
1046
+ }, A = () => {
1047
1047
  if (y.length === 0) return;
1048
1048
  const k = [...y];
1049
1049
  if (y = [], h) {
@@ -1061,70 +1061,70 @@ function Pe(e, r, l, a) {
1061
1061
  });
1062
1062
  g?.(k);
1063
1063
  };
1064
- d > 0 && (b = setInterval(M, d));
1065
- const A = X(), D = V(e, t) || {}, E = D.streams || /* @__PURE__ */ new Map();
1066
- return E.set(A, { buffer: y, flushTimer: b }), J(e, t, {
1064
+ f > 0 && (E = setInterval(A, f));
1065
+ const I = X(), D = V(e, t) || {}, M = D.streams || /* @__PURE__ */ new Map();
1066
+ return M.set(I, { buffer: y, flushTimer: E }), J(e, t, {
1067
1067
  ...D,
1068
- streams: E
1068
+ streams: M
1069
1069
  }), {
1070
1070
  write: (k) => _(k),
1071
1071
  writeMany: (k) => k.forEach(_),
1072
- flush: () => M(),
1072
+ flush: () => A(),
1073
1073
  pause: () => {
1074
- p = !0;
1074
+ w = !0;
1075
1075
  },
1076
1076
  resume: () => {
1077
- p = !1, y.length > 0 && M();
1077
+ w = !1, y.length > 0 && A();
1078
1078
  },
1079
1079
  close: () => {
1080
- M(), b && clearInterval(b);
1080
+ A(), E && clearInterval(E);
1081
1081
  const k = T.getState().getShadowMetadata(e, t);
1082
- k?.streams && k.streams.delete(A);
1082
+ k?.streams && k.streams.delete(I);
1083
1083
  }
1084
1084
  };
1085
1085
  };
1086
1086
  if (m === "stateList")
1087
1087
  return (o) => /* @__PURE__ */ ie(() => {
1088
- const d = L(/* @__PURE__ */ new Map()), [v, h] = K({}), g = t.length > 0 ? t.join(".") : "root", y = ut(e, t, u), p = we(() => ({
1088
+ const f = L(/* @__PURE__ */ new Map()), [v, h] = K({}), g = t.length > 0 ? t.join(".") : "root", y = ut(e, t, u), w = pe(() => ({
1089
1089
  ...u,
1090
1090
  arrayViews: {
1091
1091
  ...u?.arrayViews || {},
1092
1092
  [g]: y
1093
1093
  }
1094
- }), [u, g, y]), { value: b } = B(
1094
+ }), [u, g, y]), { value: E } = B(
1095
1095
  e,
1096
1096
  t,
1097
- p
1097
+ w
1098
1098
  );
1099
1099
  if (W(() => {
1100
- const A = T.getState().subscribeToPath(F, (D) => {
1100
+ const I = T.getState().subscribeToPath(F, (D) => {
1101
1101
  if (D.type === "GET_SELECTED")
1102
1102
  return;
1103
1103
  const k = T.getState().getShadowMetadata(e, t)?.transformCaches;
1104
1104
  if (k)
1105
1105
  for (const N of k.keys())
1106
- N.startsWith(I) && k.delete(N);
1106
+ N.startsWith(b) && k.delete(N);
1107
1107
  (D.type === "INSERT" || D.type === "INSERT_MANY" || D.type === "REMOVE" || D.type === "CLEAR_SELECTION" || D.type === "SERVER_STATE_UPDATE" && !u?.serverStateIsUpStream) && h({});
1108
1108
  });
1109
1109
  return () => {
1110
- A();
1110
+ I();
1111
1111
  };
1112
- }, [I, F]), !Array.isArray(b))
1112
+ }, [b, F]), !Array.isArray(E))
1113
1113
  return null;
1114
1114
  const _ = c({
1115
1115
  path: t,
1116
- componentId: I,
1117
- meta: p
1116
+ componentId: b,
1117
+ meta: w
1118
1118
  // Use updated meta here
1119
- }), M = b.map((A, D) => {
1120
- const E = y[D];
1121
- if (!E)
1119
+ }), A = E.map((I, D) => {
1120
+ const M = y[D];
1121
+ if (!M)
1122
1122
  return null;
1123
- let k = d.current.get(E);
1124
- k || (k = X(), d.current.set(E, k));
1125
- const N = [...t, E];
1126
- return Ie(je, {
1127
- key: E,
1123
+ let k = f.current.get(M);
1124
+ k || (k = X(), f.current.set(M, k));
1125
+ const N = [...t, M];
1126
+ return be(je, {
1127
+ key: M,
1128
1128
  stateKey: e,
1129
1129
  itemComponentId: k,
1130
1130
  itemPath: N,
@@ -1134,25 +1134,25 @@ function Pe(e, r, l, a) {
1134
1134
  renderFn: o
1135
1135
  });
1136
1136
  });
1137
- return /* @__PURE__ */ ie(Ce, { children: M });
1137
+ return /* @__PURE__ */ ie(Ce, { children: A });
1138
1138
  }, {});
1139
1139
  if (m === "stateFlattenOn")
1140
1140
  return (o) => {
1141
- const n = t.length > 0 ? t.join(".") : "root", d = u?.arrayViews?.[n], v = T.getState().getShadowValue(e, t, d);
1141
+ const n = t.length > 0 ? t.join(".") : "root", f = u?.arrayViews?.[n], v = T.getState().getShadowValue(e, t, f);
1142
1142
  return Array.isArray(v) ? c({
1143
1143
  path: [...t, "[*]", o],
1144
- componentId: I,
1144
+ componentId: b,
1145
1145
  meta: u
1146
1146
  }) : [];
1147
1147
  };
1148
1148
  if (m === "index")
1149
1149
  return (o) => {
1150
- const n = t.length > 0 ? t.join(".") : "root", d = u?.arrayViews?.[n];
1151
- if (d) {
1152
- const g = d[o];
1150
+ const n = t.length > 0 ? t.join(".") : "root", f = u?.arrayViews?.[n];
1151
+ if (f) {
1152
+ const g = f[o];
1153
1153
  return g ? c({
1154
1154
  path: [...t, g],
1155
- componentId: I,
1155
+ componentId: b,
1156
1156
  meta: u
1157
1157
  }) : void 0;
1158
1158
  }
@@ -1162,7 +1162,7 @@ function Pe(e, r, l, a) {
1162
1162
  if (h)
1163
1163
  return c({
1164
1164
  path: [...t, h],
1165
- componentId: I,
1165
+ componentId: b,
1166
1166
  meta: u
1167
1167
  });
1168
1168
  };
@@ -1174,10 +1174,10 @@ function Pe(e, r, l, a) {
1174
1174
  const n = o[o.length - 1];
1175
1175
  if (!n)
1176
1176
  return;
1177
- const d = [...t, n];
1177
+ const f = [...t, n];
1178
1178
  return c({
1179
- path: d,
1180
- componentId: I,
1179
+ path: f,
1180
+ componentId: b,
1181
1181
  meta: u
1182
1182
  });
1183
1183
  };
@@ -1186,35 +1186,35 @@ function Pe(e, r, l, a) {
1186
1186
  r(o, t, { updateType: "insert" });
1187
1187
  };
1188
1188
  if (m === "uniqueInsert")
1189
- return (o, n, d) => {
1189
+ return (o, n, f) => {
1190
1190
  const { value: v } = Q(
1191
1191
  e,
1192
1192
  t,
1193
1193
  u
1194
1194
  ), h = z(o) ? o(v) : o;
1195
1195
  let g = null;
1196
- if (!v.some((p) => {
1197
- const b = n ? n.every(
1198
- (_) => ae(p[_], h[_])
1199
- ) : ae(p, h);
1200
- return b && (g = p), b;
1196
+ if (!v.some((w) => {
1197
+ const E = n ? n.every(
1198
+ (_) => ae(w[_], h[_])
1199
+ ) : ae(w, h);
1200
+ return E && (g = w), E;
1201
1201
  }))
1202
1202
  r(h, t, { updateType: "insert" });
1203
- else if (d && g) {
1204
- const p = d(g), b = v.map(
1205
- (_) => ae(_, g) ? p : _
1203
+ else if (f && g) {
1204
+ const w = f(g), E = v.map(
1205
+ (_) => ae(_, g) ? w : _
1206
1206
  );
1207
- r(b, t, {
1207
+ r(E, t, {
1208
1208
  updateType: "update"
1209
1209
  });
1210
1210
  }
1211
1211
  };
1212
1212
  if (m === "cut")
1213
1213
  return (o, n) => {
1214
- const d = V(e, t);
1215
- if (!d?.arrayKeys || d.arrayKeys.length === 0)
1214
+ const f = V(e, t);
1215
+ if (!f?.arrayKeys || f.arrayKeys.length === 0)
1216
1216
  return;
1217
- const v = o === -1 ? d.arrayKeys.length - 1 : o !== void 0 ? o : d.arrayKeys.length - 1, h = d.arrayKeys[v];
1217
+ const v = o === -1 ? f.arrayKeys.length - 1 : o !== void 0 ? o : f.arrayKeys.length - 1, h = f.arrayKeys[v];
1218
1218
  h && r(null, [...t, h], {
1219
1219
  updateType: "cut"
1220
1220
  });
@@ -1224,13 +1224,13 @@ function Pe(e, r, l, a) {
1224
1224
  const o = [e, ...t].join("."), { keys: n } = B(e, t, u);
1225
1225
  if (!n || n.length === 0)
1226
1226
  return;
1227
- const d = T.getState().selectedIndicesMap.get(o);
1228
- if (!d)
1227
+ const f = T.getState().selectedIndicesMap.get(o);
1228
+ if (!f)
1229
1229
  return;
1230
- const v = d.split(".").pop();
1230
+ const v = f.split(".").pop();
1231
1231
  if (!n.includes(v))
1232
1232
  return;
1233
- const h = d.split(".").slice(1);
1233
+ const h = f.split(".").slice(1);
1234
1234
  T.getState().clearSelectedIndex({ arrayKey: o });
1235
1235
  const g = h.slice(0, -1);
1236
1236
  ne(e, g), r(null, h, {
@@ -1241,11 +1241,11 @@ function Pe(e, r, l, a) {
1241
1241
  return (o) => {
1242
1242
  const {
1243
1243
  isArray: n,
1244
- value: d,
1244
+ value: f,
1245
1245
  keys: v
1246
1246
  } = B(e, t, u);
1247
1247
  if (!n) return;
1248
- const h = he(d, v, (g) => g === o);
1248
+ const h = he(f, v, (g) => g === o);
1249
1249
  h && r(null, [...t, h.key], {
1250
1250
  updateType: "cut"
1251
1251
  });
@@ -1254,11 +1254,11 @@ function Pe(e, r, l, a) {
1254
1254
  return (o) => {
1255
1255
  const {
1256
1256
  isArray: n,
1257
- value: d,
1257
+ value: f,
1258
1258
  keys: v
1259
1259
  } = B(e, t, u);
1260
1260
  if (!n) return;
1261
- const h = he(d, v, (g) => g === o);
1261
+ const h = he(f, v, (g) => g === o);
1262
1262
  if (h) {
1263
1263
  const g = [...t, h.key];
1264
1264
  r(null, g, {
@@ -1269,8 +1269,8 @@ function Pe(e, r, l, a) {
1269
1269
  };
1270
1270
  if (m === "findWith")
1271
1271
  return (o, n) => {
1272
- const { isArray: d, value: v, keys: h } = B(e, t, u);
1273
- if (!d)
1272
+ const { isArray: f, value: v, keys: h } = B(e, t, u);
1273
+ if (!f)
1274
1274
  throw new Error("findWith can only be used on arrays");
1275
1275
  const g = he(
1276
1276
  v,
@@ -1279,11 +1279,11 @@ function Pe(e, r, l, a) {
1279
1279
  );
1280
1280
  return c(g ? {
1281
1281
  path: [...t, g.key],
1282
- componentId: I,
1282
+ componentId: b,
1283
1283
  meta: u
1284
1284
  } : {
1285
1285
  path: [...t, `not_found_${X()}`],
1286
- componentId: I,
1286
+ componentId: b,
1287
1287
  meta: u
1288
1288
  });
1289
1289
  };
@@ -1295,7 +1295,7 @@ function Pe(e, r, l, a) {
1295
1295
  }
1296
1296
  if (m === "get")
1297
1297
  return () => {
1298
- Ae(e, I, t);
1298
+ Ie(e, b, t);
1299
1299
  const { value: o } = Q(e, t, u);
1300
1300
  return o;
1301
1301
  };
@@ -1317,30 +1317,30 @@ function Pe(e, r, l, a) {
1317
1317
  if (m === "isSelected") {
1318
1318
  const o = t.slice(0, -1);
1319
1319
  if (V(e, o)?.arrayKeys) {
1320
- const d = e + "." + o.join("."), v = T.getState().selectedIndicesMap.get(d), h = e + "." + t.join(".");
1320
+ const f = e + "." + o.join("."), v = T.getState().selectedIndicesMap.get(f), h = e + "." + t.join(".");
1321
1321
  return v === h;
1322
1322
  }
1323
1323
  return;
1324
1324
  }
1325
1325
  if (m === "setSelected")
1326
1326
  return (o) => {
1327
- const n = t.slice(0, -1), d = e + "." + n.join("."), v = e + "." + t.join(".");
1328
- ne(e, n, void 0), T.getState().selectedIndicesMap.get(d), o && T.getState().setSelectedIndex(d, v);
1327
+ const n = t.slice(0, -1), f = e + "." + n.join("."), v = e + "." + t.join(".");
1328
+ ne(e, n, void 0), T.getState().selectedIndicesMap.get(f), o && T.getState().setSelectedIndex(f, v);
1329
1329
  };
1330
1330
  if (m === "toggleSelected")
1331
1331
  return () => {
1332
- const o = t.slice(0, -1), n = e + "." + o.join("."), d = e + "." + t.join(".");
1333
- T.getState().selectedIndicesMap.get(n) === d ? T.getState().clearSelectedIndex({ arrayKey: n }) : T.getState().setSelectedIndex(n, d), ne(e, o);
1332
+ const o = t.slice(0, -1), n = e + "." + o.join("."), f = e + "." + t.join(".");
1333
+ T.getState().selectedIndicesMap.get(n) === f ? T.getState().clearSelectedIndex({ arrayKey: n }) : T.getState().setSelectedIndex(n, f), ne(e, o);
1334
1334
  };
1335
1335
  if (m === "_componentId")
1336
- return I;
1336
+ return b;
1337
1337
  if (t.length == 0) {
1338
1338
  if (m === "addZodValidation")
1339
1339
  return (o) => {
1340
1340
  o.forEach((n) => {
1341
- const d = T.getState().getShadowMetadata(e, n.path) || {};
1341
+ const f = T.getState().getShadowMetadata(e, n.path) || {};
1342
1342
  T.getState().setShadowMetadata(e, n.path, {
1343
- ...d,
1343
+ ...f,
1344
1344
  validation: {
1345
1345
  status: "INVALID",
1346
1346
  errors: [
@@ -1373,48 +1373,48 @@ function Pe(e, r, l, a) {
1373
1373
  };
1374
1374
  if (m === "applyJsonPatch")
1375
1375
  return (o) => {
1376
- const n = T.getState(), d = n.getShadowMetadata(e, []);
1377
- if (!d?.components) return;
1376
+ const n = T.getState(), f = n.getShadowMetadata(e, []);
1377
+ if (!f?.components) return;
1378
1378
  const v = (g) => !g || g === "/" ? [] : g.split("/").slice(1).map((y) => y.replace(/~1/g, "/").replace(/~0/g, "~")), h = /* @__PURE__ */ new Set();
1379
1379
  for (const g of o) {
1380
1380
  const y = v(g.path);
1381
1381
  switch (g.op) {
1382
1382
  case "add":
1383
1383
  case "replace": {
1384
- const { value: p } = g;
1385
- n.updateShadowAtPath(e, y, p), n.markAsDirty(e, y, { bubble: !0 });
1386
- let b = [...y];
1384
+ const { value: w } = g;
1385
+ n.updateShadowAtPath(e, y, w), n.markAsDirty(e, y, { bubble: !0 });
1386
+ let E = [...y];
1387
1387
  for (; ; ) {
1388
1388
  const _ = n.getShadowMetadata(
1389
1389
  e,
1390
- b
1390
+ E
1391
1391
  );
1392
- if (_?.pathComponents && _.pathComponents.forEach((M) => {
1393
- if (!h.has(M)) {
1394
- const A = d.components?.get(M);
1395
- A && (A.forceUpdate(), h.add(M));
1392
+ if (_?.pathComponents && _.pathComponents.forEach((A) => {
1393
+ if (!h.has(A)) {
1394
+ const I = f.components?.get(A);
1395
+ I && (I.forceUpdate(), h.add(A));
1396
1396
  }
1397
- }), b.length === 0) break;
1398
- b.pop();
1397
+ }), E.length === 0) break;
1398
+ E.pop();
1399
1399
  }
1400
1400
  break;
1401
1401
  }
1402
1402
  case "remove": {
1403
- const p = y.slice(0, -1);
1404
- n.removeShadowArrayElement(e, y), n.markAsDirty(e, p, { bubble: !0 });
1405
- let b = [...p];
1403
+ const w = y.slice(0, -1);
1404
+ n.removeShadowArrayElement(e, y), n.markAsDirty(e, w, { bubble: !0 });
1405
+ let E = [...w];
1406
1406
  for (; ; ) {
1407
1407
  const _ = n.getShadowMetadata(
1408
1408
  e,
1409
- b
1409
+ E
1410
1410
  );
1411
- if (_?.pathComponents && _.pathComponents.forEach((M) => {
1412
- if (!h.has(M)) {
1413
- const A = d.components?.get(M);
1414
- A && (A.forceUpdate(), h.add(M));
1411
+ if (_?.pathComponents && _.pathComponents.forEach((A) => {
1412
+ if (!h.has(A)) {
1413
+ const I = f.components?.get(A);
1414
+ I && (I.forceUpdate(), h.add(A));
1415
1415
  }
1416
- }), b.length === 0) break;
1417
- b.pop();
1416
+ }), E.length === 0) break;
1417
+ E.pop();
1418
1418
  }
1419
1419
  break;
1420
1420
  }
@@ -1424,10 +1424,10 @@ function Pe(e, r, l, a) {
1424
1424
  if (m === "getComponents")
1425
1425
  return () => V(e, [])?.components;
1426
1426
  if (m === "getAllFormRefs")
1427
- return () => Ee.getState().getFormRefsByStateKey(e);
1427
+ return () => Me.getState().getFormRefsByStateKey(e);
1428
1428
  }
1429
1429
  if (m === "getFormRef")
1430
- return () => Ee.getState().getFormRef(e + "." + t.join("."));
1430
+ return () => Me.getState().getFormRef(e + "." + t.join("."));
1431
1431
  if (m === "validationWrapper")
1432
1432
  return ({
1433
1433
  children: o,
@@ -1453,8 +1453,8 @@ function Pe(e, r, l, a) {
1453
1453
  stateSource: "server",
1454
1454
  lastServerSync: Date.now()
1455
1455
  });
1456
- const d = [e, ...t].join(".");
1457
- Qe(d, {
1456
+ const f = [e, ...t].join(".");
1457
+ Qe(f, {
1458
1458
  type: "SYNC_STATUS_CHANGE",
1459
1459
  isDirty: !1
1460
1460
  });
@@ -1489,28 +1489,28 @@ function Pe(e, r, l, a) {
1489
1489
  const te = [...t, m];
1490
1490
  return T.getState().getShadowValue(e, te), c({
1491
1491
  path: te,
1492
- componentId: I,
1492
+ componentId: b,
1493
1493
  meta: u
1494
1494
  });
1495
1495
  }
1496
- }, w = new Proxy({}, x);
1497
- return S.set(O, w), w;
1496
+ }, p = new Proxy({}, x);
1497
+ return S.set(O, p), p;
1498
1498
  }
1499
1499
  const i = {
1500
1500
  revertToInitialState: (t) => {
1501
1501
  const u = T.getState().getShadowMetadata(e, []);
1502
1502
  u?.stateSource === "server" && u.baseServerState ? u.baseServerState : T.getState().initialStateGlobal[e];
1503
- const I = T.getState().initialStateGlobal[e];
1504
- He(e), oe(e, I), c({
1503
+ const b = T.getState().initialStateGlobal[e];
1504
+ He(e), oe(e, b), c({
1505
1505
  path: [],
1506
1506
  componentId: l
1507
1507
  });
1508
- const U = G(e), O = z(U?.localStorage?.key) ? U?.localStorage?.key(I) : U?.localStorage?.key, F = `${a}-${e}-${O}`;
1508
+ const U = G(e), O = z(U?.localStorage?.key) ? U?.localStorage?.key(b) : U?.localStorage?.key, F = `${a}-${e}-${O}`;
1509
1509
  F && localStorage.removeItem(F);
1510
1510
  const x = T.getState().getShadowMetadata(e, []);
1511
- return x && x?.components?.forEach((w) => {
1512
- w.forceUpdate();
1513
- }), I;
1511
+ return x && x?.components?.forEach((p) => {
1512
+ p.forceUpdate();
1513
+ }), b;
1514
1514
  },
1515
1515
  updateInitialState: (t) => {
1516
1516
  const u = Pe(
@@ -1518,12 +1518,12 @@ function Pe(e, r, l, a) {
1518
1518
  r,
1519
1519
  l,
1520
1520
  a
1521
- ), I = T.getState().initialStateGlobal[e], U = G(e), O = z(U?.localStorage?.key) ? U?.localStorage?.key(I) : U?.localStorage?.key, F = `${a}-${e}-${O}`;
1521
+ ), b = T.getState().initialStateGlobal[e], U = G(e), O = z(U?.localStorage?.key) ? U?.localStorage?.key(b) : U?.localStorage?.key, F = `${a}-${e}-${O}`;
1522
1522
  return localStorage.getItem(F) && localStorage.removeItem(F), De(() => {
1523
1523
  ke(e, t), oe(e, t);
1524
1524
  const x = T.getState().getShadowMetadata(e, []);
1525
- x && x?.components?.forEach((w) => {
1526
- w.forceUpdate();
1525
+ x && x?.components?.forEach((p) => {
1526
+ p.forceUpdate();
1527
1527
  });
1528
1528
  }), {
1529
1529
  fetchId: (x) => u.get()[x]
@@ -1536,21 +1536,21 @@ function Pe(e, r, l, a) {
1536
1536
  });
1537
1537
  }
1538
1538
  function _e(e) {
1539
- return Ie(dt, { proxy: e });
1539
+ return be(ft, { proxy: e });
1540
1540
  }
1541
- function dt({
1541
+ function ft({
1542
1542
  proxy: e
1543
1543
  }) {
1544
1544
  const r = L(null), l = L(null), a = L(!1), S = `${e._stateKey}-${e._path.join(".")}`, s = e._path.length > 0 ? e._path.join(".") : "root", c = e._meta?.arrayViews?.[s], i = R(e._stateKey, e._path, c);
1545
1545
  return W(() => {
1546
- const f = r.current;
1547
- if (!f || a.current) return;
1546
+ const d = r.current;
1547
+ if (!d || a.current) return;
1548
1548
  const t = setTimeout(() => {
1549
- if (!f.parentElement) {
1549
+ if (!d.parentElement) {
1550
1550
  console.warn("Parent element not found for signal", S);
1551
1551
  return;
1552
1552
  }
1553
- const u = f.parentElement, U = Array.from(u.childNodes).indexOf(f);
1553
+ const u = d.parentElement, U = Array.from(u.childNodes).indexOf(d);
1554
1554
  let O = u.getAttribute("data-parent-id");
1555
1555
  O || (O = `parent-${crypto.randomUUID()}`, u.setAttribute("data-parent-id", O)), l.current = `instance-${crypto.randomUUID()}`;
1556
1556
  const F = T.getState().getShadowMetadata(e._stateKey, e._path) || {}, x = F.signals || [];
@@ -1563,29 +1563,29 @@ function dt({
1563
1563
  ...F,
1564
1564
  signals: x
1565
1565
  });
1566
- let w = i;
1566
+ let p = i;
1567
1567
  if (e._effect)
1568
1568
  try {
1569
- w = new Function(
1569
+ p = new Function(
1570
1570
  "state",
1571
1571
  `return (${e._effect})(state)`
1572
1572
  )(i);
1573
1573
  } catch (m) {
1574
1574
  console.error("Error evaluating effect function:", m);
1575
1575
  }
1576
- w !== null && typeof w == "object" && (w = JSON.stringify(w));
1577
- const ee = document.createTextNode(String(w ?? ""));
1578
- f.replaceWith(ee), a.current = !0;
1576
+ p !== null && typeof p == "object" && (p = JSON.stringify(p));
1577
+ const ee = document.createTextNode(String(p ?? ""));
1578
+ d.replaceWith(ee), a.current = !0;
1579
1579
  }, 0);
1580
1580
  return () => {
1581
1581
  if (clearTimeout(t), l.current) {
1582
1582
  const u = T.getState().getShadowMetadata(e._stateKey, e._path) || {};
1583
1583
  u.signals && (u.signals = u.signals.filter(
1584
- (I) => I.instanceId !== l.current
1584
+ (b) => b.instanceId !== l.current
1585
1585
  ), T.getState().setShadowMetadata(e._stateKey, e._path, u));
1586
1586
  }
1587
1587
  };
1588
- }, []), Ie("span", {
1588
+ }, []), be("span", {
1589
1589
  ref: r,
1590
1590
  style: { display: "contents" },
1591
1591
  "data-signal-id": S
@@ -1593,9 +1593,9 @@ function dt({
1593
1593
  }
1594
1594
  export {
1595
1595
  _e as $cogsSignal,
1596
- Mt as addStateOptions,
1596
+ At as addStateOptions,
1597
1597
  Xe as createCogsState,
1598
- At as createCogsStateFromSync,
1598
+ It as createCogsStateFromSync,
1599
1599
  lt as useCogsStateFn
1600
1600
  };
1601
1601
  //# sourceMappingURL=CogsState.jsx.map