cogsbox-state 0.5.466 → 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 we, useLayoutEffect as ce, useMemo as le, 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
- import { ValidationWrapper as je, FormElementWrapper as Oe, MemoizedCogsItemWrapper as Ne } from "./Components.jsx";
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,
@@ -20,11 +20,11 @@ const {
20
20
  insertManyShadowArrayElements: qe,
21
21
  removeShadowArrayElement: Be,
22
22
  getSelectedIndex: Tt,
23
- setInitialStateOptions: ue,
23
+ setInitialStateOptions: le,
24
24
  setServerStateUpdate: We,
25
- markAsDirty: de,
26
- registerComponent: It,
27
- unregisterComponent: bt,
25
+ markAsDirty: ue,
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) {
@@ -42,7 +42,7 @@ function B(e, r, l) {
42
42
  const s = r.length > 0 ? r.join(".") : "root", c = l?.arrayViews?.[s] ?? a.arrayKeys;
43
43
  return Array.isArray(c) && c.length === 0 ? { isArray: !0, value: [], keys: [] } : { isArray: !0, value: T.getState().getShadowValue(e, r, c), keys: c ?? [] };
44
44
  }
45
- function ve(e, r, l) {
45
+ function he(e, r, l) {
46
46
  for (let a = 0; a < e.length; a++)
47
47
  if (l(e[a], a)) {
48
48
  const S = r[a];
@@ -51,14 +51,14 @@ function ve(e, r, l) {
51
51
  }
52
52
  return null;
53
53
  }
54
- function pe(e, r) {
54
+ function ve(e, r) {
55
55
  const l = G(e) || {};
56
- ue(e, {
56
+ le(e, {
57
57
  ...l,
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
@@ -68,67 +68,67 @@ function Me({
68
68
  if (r)
69
69
  for (const i in r)
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
- s.syncOptions && (!r || !r.hasOwnProperty("syncOptions")) && (c = !0), c && ue(e, s);
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
- u ? ue(i, {
95
+ u ? le(i, {
96
96
  ...u,
97
97
  ...t
98
- }) : ue(i, t);
98
+ }) : le(i, t);
99
99
  }
100
100
  }), Object.keys(a).forEach((i) => {
101
101
  oe(i, a[i]);
102
- }), console.log("new stateObject ", T.getState().shadowStateStore);
103
- const s = (i, f) => {
104
- const [t] = K(f?.componentId ?? X());
105
- Me({
102
+ });
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];
@@ -154,22 +154,22 @@ const Ke = (e, r, l, a, S) => {
154
154
  const c = `${a}-${r}-${s}`;
155
155
  let i;
156
156
  try {
157
- i = ge(c)?.lastSyncedWithServer;
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,
169
169
  JSON.stringify(u.json)
170
170
  );
171
171
  }
172
- }, ge = (e) => {
172
+ }, Se = (e) => {
173
173
  if (!e) return null;
174
174
  try {
175
175
  const r = window.localStorage.getItem(e);
@@ -180,14 +180,14 @@ const Ke = (e, r, l, a, S) => {
180
180
  }, et = (e, r) => {
181
181
  const l = R(e, []), { sessionId: a } = Ve(), S = z(r?.localStorage?.key) ? r.localStorage.key(l) : r?.localStorage?.key;
182
182
  if (S && a) {
183
- const s = ge(
183
+ const s = Se(
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();
@@ -207,10 +207,10 @@ function fe(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];
210
+ const d = [...r, c], t = l[i];
211
211
  t !== void 0 && fe(
212
212
  e,
213
- f,
213
+ d,
214
214
  t,
215
215
  a
216
216
  );
@@ -220,13 +220,13 @@ function fe(e, r, l, a) {
220
220
  fe(e, c, i, a);
221
221
  });
222
222
  }
223
- let Se = [], Te = !1;
223
+ let de = [], Te = !1;
224
224
  function tt() {
225
225
  Te || (Te = !0, queueMicrotask(it));
226
226
  }
227
227
  function rt(e, r, l) {
228
228
  const a = T.getState().getShadowValue(e, r), S = z(l) ? l(a) : l;
229
- Re(e, r, S), de(e, r, { bubble: !0 });
229
+ Re(e, r, S), ue(e, r, { bubble: !0 });
230
230
  const s = V(e, r);
231
231
  return {
232
232
  type: "update",
@@ -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;
@@ -301,24 +301,24 @@ function ot(e, r, l) {
301
301
  a = l({ state: s, uuid: X() });
302
302
  } else
303
303
  a = l;
304
- Le(e, r, a), de(e, r, { bubble: !0 });
304
+ Le(e, r, a), ue(e, r, { bubble: !0 });
305
305
  const S = V(e, r);
306
306
  if (S?.arrayKeys) {
307
307
  const s = S.arrayKeys[S.arrayKeys.length - 1];
308
308
  if (s) {
309
309
  const c = s.split(".").slice(1);
310
- de(e, c, { bubble: !1 });
310
+ ue(e, c, { bubble: !1 });
311
311
  }
312
312
  }
313
313
  return { type: "insert", newValue: a, shadowMeta: S };
314
314
  }
315
315
  function st(e, r) {
316
316
  const l = r.slice(0, -1), a = R(e, r);
317
- return Be(e, r), de(e, l, { bubble: !0 }), { type: "cut", oldValue: a, parentPath: l };
317
+ return Be(e, r), ue(e, l, { bubble: !0 }), { type: "cut", oldValue: a, parentPath: l };
318
318
  }
319
319
  function it() {
320
320
  const e = /* @__PURE__ */ new Set(), r = [], l = [];
321
- for (const a of Se) {
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
- }), Se = [], 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, Se.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
- Se.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]);
402
+ }, [d]);
403
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 = ge(
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
- pe(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((j) => j[A])
451
- ), E = M.filter(
452
- (j) => !D.has(j[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, []);
454
+ M.length > 0 && qe(p, [], M);
455
+ const k = R(p, []);
456
456
  fe(
457
- w,
457
+ p,
458
458
  [],
459
459
  k,
460
- p.timestamp
460
+ w.timestamp
461
461
  );
462
462
  } else
463
- oe(w, M), fe(
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 || pe(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 && pe(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 = le(() => 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,70 +748,70 @@ 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
- const C = [e, ...t].join("."), P = T.getState().subscribeToPath(C, (N) => {
774
- N.type !== "GET_SELECTED" && N.type;
773
+ const C = [e, ...t].join("."), P = T.getState().subscribeToPath(C, (j) => {
774
+ j.type !== "GET_SELECTED" && j.type;
775
775
  });
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
- const N = Math.ceil(
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 - N - 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 j = L(E);
802
+ const N = L(M);
803
803
  ce(() => {
804
- j.current = E;
805
- }, [E]);
804
+ N.current = M;
805
+ }, [M]);
806
806
  const se = we(() => {
807
807
  const C = g.current;
808
808
  if (!C) return;
809
- const P = C.scrollTop, { scrollHeight: N, clientHeight: q } = C, $ = A.current, re = N - (P + q), ye = $.isNearBottom;
810
- $.isNearBottom = re <= h, P < $.lastScrollTop ? ($.scrollUpCount++, $.scrollUpCount > 3 && ye && ($.isUserScrolling = !0, console.log("User scrolled away from bottom"))) : $.isNearBottom && ($.isUserScrolling = !1, $.scrollUpCount = 0), $.lastScrollTop = P;
809
+ const P = C.scrollTop, { scrollHeight: j, clientHeight: q } = C, $ = I.current, re = j - (P + q), ge = $.isNearBottom;
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 me = E[H], he = D.current.get(me);
814
- if (he && he.offset + he.height > P) {
812
+ for (let H = 0; H < M.length; H++) {
813
+ const ye = M[H], me = D.current.get(ye);
814
+ if (me && me.offset + me.height > P) {
815
815
  Z = H;
816
816
  break;
817
817
  }
@@ -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(() => {
@@ -851,35 +851,35 @@ function Pe(e, r, l, a) {
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;
855
- const N = () => {
854
+ I.current.isUserScrolling = !1, I.current.isNearBottom = !0, I.current.scrollUpCount = 0;
855
+ const j = () => {
856
856
  const q = ($ = 0) => {
857
857
  if ($ > 5) return;
858
- const re = P.scrollHeight, ye = P.scrollTop, Z = P.clientHeight;
859
- ye + Z >= re - 1 || (P.scrollTo({
858
+ const re = P.scrollHeight, ge = P.scrollTop, Z = P.clientHeight;
859
+ ge + Z >= re - 1 || (P.scrollTo({
860
860
  top: re,
861
861
  behavior: C
862
862
  }), setTimeout(() => {
863
- const H = P.scrollHeight, me = P.scrollTop;
864
- (H !== re || me + Z < H - 1) && q($ + 1);
863
+ const H = P.scrollHeight, ye = P.scrollTop;
864
+ (H !== re || ye + Z < H - 1) && q($ + 1);
865
865
  }, 50));
866
866
  };
867
867
  q();
868
868
  };
869
- "requestIdleCallback" in window ? requestIdleCallback(N, { timeout: 100 }) : requestAnimationFrame(() => {
870
- requestAnimationFrame(N);
869
+ "requestIdleCallback" in window ? requestIdleCallback(j, { timeout: 100 }) : requestAnimationFrame(() => {
870
+ requestAnimationFrame(j);
871
871
  });
872
872
  },
873
873
  []
874
874
  );
875
875
  return W(() => {
876
876
  if (!v || !g.current) return;
877
- const C = g.current, P = A.current;
878
- let N;
877
+ const C = g.current, P = I.current;
878
+ let j;
879
879
  const q = () => {
880
- clearTimeout(N), N = setTimeout(() => {
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
- clearTimeout(N), $.disconnect();
896
+ clearTimeout(j), $.disconnect();
897
897
  };
898
- }, [v, E.length, Y]), {
899
- virtualState: le(() => {
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,48 +924,48 @@ 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 N = D.current.get(E[C])?.offset || 0;
935
- g.current.scrollTo({ top: N, behavior: P });
933
+ if (g.current && M[C]) {
934
+ const j = D.current.get(M[C])?.offset || 0;
935
+ g.current.scrollTo({ top: j, behavior: P });
936
936
  }
937
937
  }
938
938
  };
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,136 +1029,130 @@ 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) {
1050
- const j = h(k);
1051
- j !== void 0 && (Array.isArray(j) ? j : [j]).forEach((Y) => {
1050
+ const N = h(k);
1051
+ N !== void 0 && (Array.isArray(N) ? N : [N]).forEach((Y) => {
1052
1052
  r(Y, t, {
1053
1053
  updateType: "insert"
1054
1054
  });
1055
1055
  });
1056
1056
  } else
1057
- k.forEach((j) => {
1058
- r(j, t, {
1057
+ k.forEach((N) => {
1058
+ r(N, t, {
1059
1059
  updateType: "insert"
1060
1060
  });
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 = le(() => ut(e, t, u), [
1089
- e,
1090
- t.join("."),
1091
- // Only recalculate if the underlying array keys or transforms change
1092
- V(e, t)?.arrayKeys,
1093
- u?.transforms
1094
- ]), p = le(() => ({
1088
+ const f = L(/* @__PURE__ */ new Map()), [v, h] = K({}), g = t.length > 0 ? t.join(".") : "root", y = ut(e, t, u), w = pe(() => ({
1095
1089
  ...u,
1096
1090
  arrayViews: {
1097
1091
  ...u?.arrayViews || {},
1098
1092
  [g]: y
1099
1093
  }
1100
- }), [u, g, y]), { value: b } = B(
1094
+ }), [u, g, y]), { value: E } = B(
1101
1095
  e,
1102
1096
  t,
1103
- p
1097
+ w
1104
1098
  );
1105
1099
  if (W(() => {
1106
- const A = T.getState().subscribeToPath(F, (D) => {
1100
+ const I = T.getState().subscribeToPath(F, (D) => {
1107
1101
  if (D.type === "GET_SELECTED")
1108
1102
  return;
1109
1103
  const k = T.getState().getShadowMetadata(e, t)?.transformCaches;
1110
1104
  if (k)
1111
- for (const j of k.keys())
1112
- j.startsWith(I) && k.delete(j);
1105
+ for (const N of k.keys())
1106
+ N.startsWith(b) && k.delete(N);
1113
1107
  (D.type === "INSERT" || D.type === "INSERT_MANY" || D.type === "REMOVE" || D.type === "CLEAR_SELECTION" || D.type === "SERVER_STATE_UPDATE" && !u?.serverStateIsUpStream) && h({});
1114
1108
  });
1115
1109
  return () => {
1116
- A();
1110
+ I();
1117
1111
  };
1118
- }, [I, F]), !Array.isArray(b))
1112
+ }, [b, F]), !Array.isArray(E))
1119
1113
  return null;
1120
1114
  const _ = c({
1121
1115
  path: t,
1122
- componentId: I,
1123
- meta: p
1116
+ componentId: b,
1117
+ meta: w
1124
1118
  // Use updated meta here
1125
- }), M = b.map((A, D) => {
1126
- const E = y[D];
1127
- if (!E)
1119
+ }), A = E.map((I, D) => {
1120
+ const M = y[D];
1121
+ if (!M)
1128
1122
  return null;
1129
- let k = d.current.get(E);
1130
- k || (k = X(), d.current.set(E, k));
1131
- const j = [...t, E];
1132
- return Ie(Ne, {
1133
- 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,
1134
1128
  stateKey: e,
1135
1129
  itemComponentId: k,
1136
- itemPath: j,
1130
+ itemPath: N,
1137
1131
  localIndex: D,
1138
1132
  arraySetter: _,
1139
1133
  rebuildStateShape: c,
1140
1134
  renderFn: o
1141
1135
  });
1142
1136
  });
1143
- return /* @__PURE__ */ ie(Ce, { children: M });
1137
+ return /* @__PURE__ */ ie(Ce, { children: A });
1144
1138
  }, {});
1145
1139
  if (m === "stateFlattenOn")
1146
1140
  return (o) => {
1147
- 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);
1148
1142
  return Array.isArray(v) ? c({
1149
1143
  path: [...t, "[*]", o],
1150
- componentId: I,
1144
+ componentId: b,
1151
1145
  meta: u
1152
1146
  }) : [];
1153
1147
  };
1154
1148
  if (m === "index")
1155
1149
  return (o) => {
1156
- const n = t.length > 0 ? t.join(".") : "root", d = u?.arrayViews?.[n];
1157
- if (d) {
1158
- 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];
1159
1153
  return g ? c({
1160
1154
  path: [...t, g],
1161
- componentId: I,
1155
+ componentId: b,
1162
1156
  meta: u
1163
1157
  }) : void 0;
1164
1158
  }
@@ -1168,7 +1162,7 @@ function Pe(e, r, l, a) {
1168
1162
  if (h)
1169
1163
  return c({
1170
1164
  path: [...t, h],
1171
- componentId: I,
1165
+ componentId: b,
1172
1166
  meta: u
1173
1167
  });
1174
1168
  };
@@ -1180,10 +1174,10 @@ function Pe(e, r, l, a) {
1180
1174
  const n = o[o.length - 1];
1181
1175
  if (!n)
1182
1176
  return;
1183
- const d = [...t, n];
1177
+ const f = [...t, n];
1184
1178
  return c({
1185
- path: d,
1186
- componentId: I,
1179
+ path: f,
1180
+ componentId: b,
1187
1181
  meta: u
1188
1182
  });
1189
1183
  };
@@ -1192,35 +1186,35 @@ function Pe(e, r, l, a) {
1192
1186
  r(o, t, { updateType: "insert" });
1193
1187
  };
1194
1188
  if (m === "uniqueInsert")
1195
- return (o, n, d) => {
1189
+ return (o, n, f) => {
1196
1190
  const { value: v } = Q(
1197
1191
  e,
1198
1192
  t,
1199
1193
  u
1200
1194
  ), h = z(o) ? o(v) : o;
1201
1195
  let g = null;
1202
- if (!v.some((p) => {
1203
- const b = n ? n.every(
1204
- (_) => ae(p[_], h[_])
1205
- ) : ae(p, h);
1206
- 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;
1207
1201
  }))
1208
1202
  r(h, t, { updateType: "insert" });
1209
- else if (d && g) {
1210
- const p = d(g), b = v.map(
1211
- (_) => ae(_, g) ? p : _
1203
+ else if (f && g) {
1204
+ const w = f(g), E = v.map(
1205
+ (_) => ae(_, g) ? w : _
1212
1206
  );
1213
- r(b, t, {
1207
+ r(E, t, {
1214
1208
  updateType: "update"
1215
1209
  });
1216
1210
  }
1217
1211
  };
1218
1212
  if (m === "cut")
1219
1213
  return (o, n) => {
1220
- const d = V(e, t);
1221
- if (!d?.arrayKeys || d.arrayKeys.length === 0)
1214
+ const f = V(e, t);
1215
+ if (!f?.arrayKeys || f.arrayKeys.length === 0)
1222
1216
  return;
1223
- 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];
1224
1218
  h && r(null, [...t, h], {
1225
1219
  updateType: "cut"
1226
1220
  });
@@ -1230,13 +1224,13 @@ function Pe(e, r, l, a) {
1230
1224
  const o = [e, ...t].join("."), { keys: n } = B(e, t, u);
1231
1225
  if (!n || n.length === 0)
1232
1226
  return;
1233
- const d = T.getState().selectedIndicesMap.get(o);
1234
- if (!d)
1227
+ const f = T.getState().selectedIndicesMap.get(o);
1228
+ if (!f)
1235
1229
  return;
1236
- const v = d.split(".").pop();
1230
+ const v = f.split(".").pop();
1237
1231
  if (!n.includes(v))
1238
1232
  return;
1239
- const h = d.split(".").slice(1);
1233
+ const h = f.split(".").slice(1);
1240
1234
  T.getState().clearSelectedIndex({ arrayKey: o });
1241
1235
  const g = h.slice(0, -1);
1242
1236
  ne(e, g), r(null, h, {
@@ -1247,11 +1241,11 @@ function Pe(e, r, l, a) {
1247
1241
  return (o) => {
1248
1242
  const {
1249
1243
  isArray: n,
1250
- value: d,
1244
+ value: f,
1251
1245
  keys: v
1252
1246
  } = B(e, t, u);
1253
1247
  if (!n) return;
1254
- const h = ve(d, v, (g) => g === o);
1248
+ const h = he(f, v, (g) => g === o);
1255
1249
  h && r(null, [...t, h.key], {
1256
1250
  updateType: "cut"
1257
1251
  });
@@ -1260,11 +1254,11 @@ function Pe(e, r, l, a) {
1260
1254
  return (o) => {
1261
1255
  const {
1262
1256
  isArray: n,
1263
- value: d,
1257
+ value: f,
1264
1258
  keys: v
1265
1259
  } = B(e, t, u);
1266
1260
  if (!n) return;
1267
- const h = ve(d, v, (g) => g === o);
1261
+ const h = he(f, v, (g) => g === o);
1268
1262
  if (h) {
1269
1263
  const g = [...t, h.key];
1270
1264
  r(null, g, {
@@ -1275,21 +1269,21 @@ function Pe(e, r, l, a) {
1275
1269
  };
1276
1270
  if (m === "findWith")
1277
1271
  return (o, n) => {
1278
- const { isArray: d, value: v, keys: h } = B(e, t, u);
1279
- if (!d)
1272
+ const { isArray: f, value: v, keys: h } = B(e, t, u);
1273
+ if (!f)
1280
1274
  throw new Error("findWith can only be used on arrays");
1281
- const g = ve(
1275
+ const g = he(
1282
1276
  v,
1283
1277
  h,
1284
1278
  (y) => y?.[o] === n
1285
1279
  );
1286
1280
  return c(g ? {
1287
1281
  path: [...t, g.key],
1288
- componentId: I,
1282
+ componentId: b,
1289
1283
  meta: u
1290
1284
  } : {
1291
1285
  path: [...t, `not_found_${X()}`],
1292
- componentId: I,
1286
+ componentId: b,
1293
1287
  meta: u
1294
1288
  });
1295
1289
  };
@@ -1301,7 +1295,7 @@ function Pe(e, r, l, a) {
1301
1295
  }
1302
1296
  if (m === "get")
1303
1297
  return () => {
1304
- Ae(e, I, t);
1298
+ Ie(e, b, t);
1305
1299
  const { value: o } = Q(e, t, u);
1306
1300
  return o;
1307
1301
  };
@@ -1319,34 +1313,34 @@ function Pe(e, r, l, a) {
1319
1313
  return Ye(o);
1320
1314
  }
1321
1315
  if (m == "getLocalStorage")
1322
- return (o) => ge(a + "-" + e + "-" + o);
1316
+ return (o) => Se(a + "-" + e + "-" + o);
1323
1317
  if (m === "isSelected") {
1324
1318
  const o = t.slice(0, -1);
1325
1319
  if (V(e, o)?.arrayKeys) {
1326
- 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(".");
1327
1321
  return v === h;
1328
1322
  }
1329
1323
  return;
1330
1324
  }
1331
1325
  if (m === "setSelected")
1332
1326
  return (o) => {
1333
- const n = t.slice(0, -1), d = e + "." + n.join("."), v = e + "." + t.join(".");
1334
- 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);
1335
1329
  };
1336
1330
  if (m === "toggleSelected")
1337
1331
  return () => {
1338
- const o = t.slice(0, -1), n = e + "." + o.join("."), d = e + "." + t.join(".");
1339
- 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);
1340
1334
  };
1341
1335
  if (m === "_componentId")
1342
- return I;
1336
+ return b;
1343
1337
  if (t.length == 0) {
1344
1338
  if (m === "addZodValidation")
1345
1339
  return (o) => {
1346
1340
  o.forEach((n) => {
1347
- const d = T.getState().getShadowMetadata(e, n.path) || {};
1341
+ const f = T.getState().getShadowMetadata(e, n.path) || {};
1348
1342
  T.getState().setShadowMetadata(e, n.path, {
1349
- ...d,
1343
+ ...f,
1350
1344
  validation: {
1351
1345
  status: "INVALID",
1352
1346
  errors: [
@@ -1379,48 +1373,48 @@ function Pe(e, r, l, a) {
1379
1373
  };
1380
1374
  if (m === "applyJsonPatch")
1381
1375
  return (o) => {
1382
- const n = T.getState(), d = n.getShadowMetadata(e, []);
1383
- if (!d?.components) return;
1376
+ const n = T.getState(), f = n.getShadowMetadata(e, []);
1377
+ if (!f?.components) return;
1384
1378
  const v = (g) => !g || g === "/" ? [] : g.split("/").slice(1).map((y) => y.replace(/~1/g, "/").replace(/~0/g, "~")), h = /* @__PURE__ */ new Set();
1385
1379
  for (const g of o) {
1386
1380
  const y = v(g.path);
1387
1381
  switch (g.op) {
1388
1382
  case "add":
1389
1383
  case "replace": {
1390
- const { value: p } = g;
1391
- n.updateShadowAtPath(e, y, p), n.markAsDirty(e, y, { bubble: !0 });
1392
- let b = [...y];
1384
+ const { value: w } = g;
1385
+ n.updateShadowAtPath(e, y, w), n.markAsDirty(e, y, { bubble: !0 });
1386
+ let E = [...y];
1393
1387
  for (; ; ) {
1394
1388
  const _ = n.getShadowMetadata(
1395
1389
  e,
1396
- b
1390
+ E
1397
1391
  );
1398
- if (_?.pathComponents && _.pathComponents.forEach((M) => {
1399
- if (!h.has(M)) {
1400
- const A = d.components?.get(M);
1401
- 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));
1402
1396
  }
1403
- }), b.length === 0) break;
1404
- b.pop();
1397
+ }), E.length === 0) break;
1398
+ E.pop();
1405
1399
  }
1406
1400
  break;
1407
1401
  }
1408
1402
  case "remove": {
1409
- const p = y.slice(0, -1);
1410
- n.removeShadowArrayElement(e, y), n.markAsDirty(e, p, { bubble: !0 });
1411
- 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];
1412
1406
  for (; ; ) {
1413
1407
  const _ = n.getShadowMetadata(
1414
1408
  e,
1415
- b
1409
+ E
1416
1410
  );
1417
- if (_?.pathComponents && _.pathComponents.forEach((M) => {
1418
- if (!h.has(M)) {
1419
- const A = d.components?.get(M);
1420
- 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));
1421
1415
  }
1422
- }), b.length === 0) break;
1423
- b.pop();
1416
+ }), E.length === 0) break;
1417
+ E.pop();
1424
1418
  }
1425
1419
  break;
1426
1420
  }
@@ -1430,16 +1424,16 @@ function Pe(e, r, l, a) {
1430
1424
  if (m === "getComponents")
1431
1425
  return () => V(e, [])?.components;
1432
1426
  if (m === "getAllFormRefs")
1433
- return () => Ee.getState().getFormRefsByStateKey(e);
1427
+ return () => Me.getState().getFormRefsByStateKey(e);
1434
1428
  }
1435
1429
  if (m === "getFormRef")
1436
- return () => Ee.getState().getFormRef(e + "." + t.join("."));
1430
+ return () => Me.getState().getFormRef(e + "." + t.join("."));
1437
1431
  if (m === "validationWrapper")
1438
1432
  return ({
1439
1433
  children: o,
1440
1434
  hideMessage: n
1441
1435
  }) => /* @__PURE__ */ ie(
1442
- je,
1436
+ Ne,
1443
1437
  {
1444
1438
  formOpts: n ? { validation: { message: "" } } : void 0,
1445
1439
  path: t,
@@ -1450,7 +1444,7 @@ function Pe(e, r, l, a) {
1450
1444
  if (m === "_stateKey") return e;
1451
1445
  if (m === "_path") return t;
1452
1446
  if (m === "update")
1453
- return (o) => (console.log("udpating", o, t), r(o, t, { updateType: "update" }), {
1447
+ return (o) => (r(o, t, { updateType: "update" }), {
1454
1448
  synced: () => {
1455
1449
  const n = T.getState().getShadowMetadata(e, t);
1456
1450
  J(e, t, {
@@ -1459,8 +1453,8 @@ function Pe(e, r, l, a) {
1459
1453
  stateSource: "server",
1460
1454
  lastServerSync: Date.now()
1461
1455
  });
1462
- const d = [e, ...t].join(".");
1463
- Qe(d, {
1456
+ const f = [e, ...t].join(".");
1457
+ Qe(f, {
1464
1458
  type: "SYNC_STATUS_CHANGE",
1465
1459
  isDirty: !1
1466
1460
  });
@@ -1495,28 +1489,28 @@ function Pe(e, r, l, a) {
1495
1489
  const te = [...t, m];
1496
1490
  return T.getState().getShadowValue(e, te), c({
1497
1491
  path: te,
1498
- componentId: I,
1492
+ componentId: b,
1499
1493
  meta: u
1500
1494
  });
1501
1495
  }
1502
- }, w = new Proxy({}, x);
1503
- return S.set(O, w), w;
1496
+ }, p = new Proxy({}, x);
1497
+ return S.set(O, p), p;
1504
1498
  }
1505
1499
  const i = {
1506
1500
  revertToInitialState: (t) => {
1507
1501
  const u = T.getState().getShadowMetadata(e, []);
1508
1502
  u?.stateSource === "server" && u.baseServerState ? u.baseServerState : T.getState().initialStateGlobal[e];
1509
- const I = T.getState().initialStateGlobal[e];
1510
- He(e), oe(e, I), c({
1503
+ const b = T.getState().initialStateGlobal[e];
1504
+ He(e), oe(e, b), c({
1511
1505
  path: [],
1512
1506
  componentId: l
1513
1507
  });
1514
- 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}`;
1515
1509
  F && localStorage.removeItem(F);
1516
1510
  const x = T.getState().getShadowMetadata(e, []);
1517
- return x && x?.components?.forEach((w) => {
1518
- w.forceUpdate();
1519
- }), I;
1511
+ return x && x?.components?.forEach((p) => {
1512
+ p.forceUpdate();
1513
+ }), b;
1520
1514
  },
1521
1515
  updateInitialState: (t) => {
1522
1516
  const u = Pe(
@@ -1524,12 +1518,12 @@ function Pe(e, r, l, a) {
1524
1518
  r,
1525
1519
  l,
1526
1520
  a
1527
- ), 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}`;
1528
1522
  return localStorage.getItem(F) && localStorage.removeItem(F), De(() => {
1529
1523
  ke(e, t), oe(e, t);
1530
1524
  const x = T.getState().getShadowMetadata(e, []);
1531
- x && x?.components?.forEach((w) => {
1532
- w.forceUpdate();
1525
+ x && x?.components?.forEach((p) => {
1526
+ p.forceUpdate();
1533
1527
  });
1534
1528
  }), {
1535
1529
  fetchId: (x) => u.get()[x]
@@ -1542,21 +1536,21 @@ function Pe(e, r, l, a) {
1542
1536
  });
1543
1537
  }
1544
1538
  function _e(e) {
1545
- return Ie(dt, { proxy: e });
1539
+ return be(ft, { proxy: e });
1546
1540
  }
1547
- function dt({
1541
+ function ft({
1548
1542
  proxy: e
1549
1543
  }) {
1550
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);
1551
1545
  return W(() => {
1552
- const f = r.current;
1553
- if (!f || a.current) return;
1546
+ const d = r.current;
1547
+ if (!d || a.current) return;
1554
1548
  const t = setTimeout(() => {
1555
- if (!f.parentElement) {
1549
+ if (!d.parentElement) {
1556
1550
  console.warn("Parent element not found for signal", S);
1557
1551
  return;
1558
1552
  }
1559
- const u = f.parentElement, U = Array.from(u.childNodes).indexOf(f);
1553
+ const u = d.parentElement, U = Array.from(u.childNodes).indexOf(d);
1560
1554
  let O = u.getAttribute("data-parent-id");
1561
1555
  O || (O = `parent-${crypto.randomUUID()}`, u.setAttribute("data-parent-id", O)), l.current = `instance-${crypto.randomUUID()}`;
1562
1556
  const F = T.getState().getShadowMetadata(e._stateKey, e._path) || {}, x = F.signals || [];
@@ -1569,29 +1563,29 @@ function dt({
1569
1563
  ...F,
1570
1564
  signals: x
1571
1565
  });
1572
- let w = i;
1566
+ let p = i;
1573
1567
  if (e._effect)
1574
1568
  try {
1575
- w = new Function(
1569
+ p = new Function(
1576
1570
  "state",
1577
1571
  `return (${e._effect})(state)`
1578
1572
  )(i);
1579
1573
  } catch (m) {
1580
1574
  console.error("Error evaluating effect function:", m);
1581
1575
  }
1582
- w !== null && typeof w == "object" && (w = JSON.stringify(w));
1583
- const ee = document.createTextNode(String(w ?? ""));
1584
- 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;
1585
1579
  }, 0);
1586
1580
  return () => {
1587
1581
  if (clearTimeout(t), l.current) {
1588
1582
  const u = T.getState().getShadowMetadata(e._stateKey, e._path) || {};
1589
1583
  u.signals && (u.signals = u.signals.filter(
1590
- (I) => I.instanceId !== l.current
1584
+ (b) => b.instanceId !== l.current
1591
1585
  ), T.getState().setShadowMetadata(e._stateKey, e._path, u));
1592
1586
  }
1593
1587
  };
1594
- }, []), Ie("span", {
1588
+ }, []), be("span", {
1595
1589
  ref: r,
1596
1590
  style: { display: "contents" },
1597
1591
  "data-signal-id": S
@@ -1599,9 +1593,9 @@ function dt({
1599
1593
  }
1600
1594
  export {
1601
1595
  _e as $cogsSignal,
1602
- Mt as addStateOptions,
1596
+ At as addStateOptions,
1603
1597
  Xe as createCogsState,
1604
- At as createCogsStateFromSync,
1598
+ It as createCogsStateFromSync,
1605
1599
  lt as useCogsStateFn
1606
1600
  };
1607
1601
  //# sourceMappingURL=CogsState.jsx.map