cogsbox-state 0.5.254 → 0.5.255

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,32 +1,32 @@
1
1
  "use client";
2
2
  import { jsx as It } from "react/jsx-runtime";
3
- import { useState as X, useRef as Y, useEffect as it, useLayoutEffect as st, useMemo as At, createElement as lt, useSyncExternalStore as Nt, startTransition as Ct, useCallback as ft } from "react";
4
- import { transformStateFunc as Pt, isDeepEqual as H, isFunction as J, getNestedValue as B, getDifferences as mt, debounce as _t } from "./utility.js";
5
- import { pushFunc as St, updateFn as et, cutFunc as at, ValidationWrapper as Ot, FormControlComponent as Mt } from "./Functions.jsx";
6
- import jt from "superjson";
7
- import { v4 as vt } from "uuid";
3
+ import { useState as Q, useRef as Y, useEffect as st, useLayoutEffect as at, useMemo as Ct, createElement as ct, useSyncExternalStore as Pt, startTransition as _t, useCallback as gt } from "react";
4
+ import { transformStateFunc as Ot, isDeepEqual as B, isFunction as J, getNestedValue as H, getDifferences as St, debounce as pt } from "./utility.js";
5
+ import { pushFunc as ft, updateFn as et, cutFunc as ot, ValidationWrapper as Mt, FormControlComponent as jt } from "./Functions.jsx";
6
+ import Rt from "superjson";
7
+ import { v4 as mt } from "uuid";
8
8
  import "zod";
9
- import { getGlobalStore as n, formRefStore as pt } from "./store.js";
10
- import { useCogsConfig as bt } from "./CogsStateClient.jsx";
11
- import { applyPatch as Rt } from "fast-json-patch";
12
- function wt(t, s) {
13
- const v = n.getState().getInitialOptions, g = n.getState().setInitialStateOptions, h = v(t) || {};
9
+ import { getGlobalStore as n, formRefStore as wt } from "./store.js";
10
+ import { useCogsConfig as kt } from "./CogsStateClient.jsx";
11
+ import { applyPatch as Ut } from "fast-json-patch";
12
+ function Et(t, s) {
13
+ const v = n.getState().getInitialOptions, g = n.getState().setInitialStateOptions, y = v(t) || {};
14
14
  g(t, {
15
- ...h,
15
+ ...y,
16
16
  ...s
17
17
  });
18
18
  }
19
- function Et({
19
+ function $t({
20
20
  stateKey: t,
21
21
  options: s,
22
22
  initialOptionsPart: v
23
23
  }) {
24
- const g = Q(t) || {}, h = v[t] || {}, V = n.getState().setInitialStateOptions, E = { ...h, ...g };
24
+ const g = K(t) || {}, y = v[t] || {}, V = n.getState().setInitialStateOptions, E = { ...y, ...g };
25
25
  let I = !1;
26
26
  if (s)
27
27
  for (const i in s)
28
28
  E.hasOwnProperty(i) ? (i == "localStorage" && s[i] && E[i].key !== s[i]?.key && (I = !0, E[i] = s[i]), i == "initialState" && s[i] && E[i] !== s[i] && // Different references
29
- !H(E[i], s[i]) && (I = !0, E[i] = s[i])) : (I = !0, E[i] = s[i]);
29
+ !B(E[i], s[i]) && (I = !0, E[i] = s[i])) : (I = !0, E[i] = s[i]);
30
30
  I && V(t, E);
31
31
  }
32
32
  function oe(t, { formElements: s, validation: v }) {
@@ -34,29 +34,29 @@ function oe(t, { formElements: s, validation: v }) {
34
34
  }
35
35
  const ae = (t, s) => {
36
36
  let v = t;
37
- const [g, h] = Pt(v);
38
- (Object.keys(h).length > 0 || s && Object.keys(s).length > 0) && Object.keys(h).forEach((I) => {
39
- h[I] = h[I] || {}, h[I].formElements = {
37
+ const [g, y] = Ot(v);
38
+ (Object.keys(y).length > 0 || s && Object.keys(s).length > 0) && Object.keys(y).forEach((I) => {
39
+ y[I] = y[I] || {}, y[I].formElements = {
40
40
  ...s?.formElements,
41
41
  // Global defaults first
42
42
  ...s?.validation,
43
- ...h[I].formElements || {}
43
+ ...y[I].formElements || {}
44
44
  // State-specific overrides
45
- }, Q(I) || n.getState().setInitialStateOptions(I, h[I]);
45
+ }, K(I) || n.getState().setInitialStateOptions(I, y[I]);
46
46
  }), n.getState().setInitialStates(g), n.getState().setCreatedState(g);
47
47
  const V = (I, i) => {
48
- const [y] = X(i?.componentId ?? vt());
49
- Et({
48
+ const [h] = Q(i?.componentId ?? mt());
49
+ $t({
50
50
  stateKey: I,
51
51
  options: i,
52
- initialOptionsPart: h
52
+ initialOptionsPart: y
53
53
  });
54
- const o = n.getState().cogsStateStore[I] || g[I], S = i?.modifyState ? i.modifyState(o) : o, [G, j] = Ht(
54
+ const o = n.getState().cogsStateStore[I] || g[I], S = i?.modifyState ? i.modifyState(o) : o, [G, M] = Ht(
55
55
  S,
56
56
  {
57
57
  stateKey: I,
58
58
  syncUpdate: i?.syncUpdate,
59
- componentId: y,
59
+ componentId: h,
60
60
  localStorage: i?.localStorage,
61
61
  middleware: i?.middleware,
62
62
  enabledSync: i?.enabledSync,
@@ -67,24 +67,24 @@ const ae = (t, s) => {
67
67
  serverState: i?.serverState
68
68
  }
69
69
  );
70
- return j;
70
+ return M;
71
71
  };
72
72
  function E(I, i) {
73
- Et({ stateKey: I, options: i, initialOptionsPart: h }), i.localStorage && Gt(I, i), ut(I);
73
+ $t({ stateKey: I, options: i, initialOptionsPart: y }), i.localStorage && Lt(I, i), dt(I);
74
74
  }
75
75
  return { useCogsState: V, setCogsOptions: E };
76
76
  }, {
77
- setUpdaterState: ct,
77
+ setUpdaterState: it,
78
78
  setState: Z,
79
- getInitialOptions: Q,
80
- getKeyState: kt,
81
- getValidationErrors: Ut,
82
- setStateLog: Ft,
83
- updateInitialStateGlobal: ht,
84
- addValidationError: Dt,
79
+ getInitialOptions: K,
80
+ getKeyState: xt,
81
+ getValidationErrors: Ft,
82
+ setStateLog: Dt,
83
+ updateInitialStateGlobal: vt,
84
+ addValidationError: Wt,
85
85
  removeValidationError: z,
86
- setServerSyncActions: Wt
87
- } = n.getState(), $t = (t, s, v, g, h) => {
86
+ setServerSyncActions: Gt
87
+ } = n.getState(), Tt = (t, s, v, g, y) => {
88
88
  v?.log && console.log(
89
89
  "saving to localstorage",
90
90
  s,
@@ -96,20 +96,20 @@ const ae = (t, s) => {
96
96
  const E = `${g}-${s}-${V}`;
97
97
  let I;
98
98
  try {
99
- I = dt(E)?.lastSyncedWithServer;
99
+ I = lt(E)?.lastSyncedWithServer;
100
100
  } catch {
101
101
  }
102
102
  const i = {
103
103
  state: t,
104
104
  lastUpdated: Date.now(),
105
- lastSyncedWithServer: h ?? I
106
- }, y = jt.serialize(i);
105
+ lastSyncedWithServer: y ?? I
106
+ }, h = Rt.serialize(i);
107
107
  window.localStorage.setItem(
108
108
  E,
109
- JSON.stringify(y.json)
109
+ JSON.stringify(h.json)
110
110
  );
111
111
  }
112
- }, dt = (t) => {
112
+ }, lt = (t) => {
113
113
  if (!t) return null;
114
114
  try {
115
115
  const s = window.localStorage.getItem(t);
@@ -117,29 +117,29 @@ const ae = (t, s) => {
117
117
  } catch (s) {
118
118
  return console.error("Error loading from localStorage:", s), null;
119
119
  }
120
- }, Gt = (t, s) => {
121
- const v = n.getState().cogsStateStore[t], { sessionId: g } = bt(), h = J(s?.localStorage?.key) ? s.localStorage.key(v) : s?.localStorage?.key;
122
- if (h && g) {
123
- const V = dt(
124
- `${g}-${t}-${h}`
120
+ }, Lt = (t, s) => {
121
+ const v = n.getState().cogsStateStore[t], { sessionId: g } = kt(), y = J(s?.localStorage?.key) ? s.localStorage.key(v) : s?.localStorage?.key;
122
+ if (y && g) {
123
+ const V = lt(
124
+ `${g}-${t}-${y}`
125
125
  );
126
126
  if (V && V.lastUpdated > (V.lastSyncedWithServer || 0))
127
- return Z(t, V.state), ut(t), !0;
127
+ return Z(t, V.state), dt(t), !0;
128
128
  }
129
129
  return !1;
130
- }, xt = (t, s, v, g, h, V) => {
130
+ }, Vt = (t, s, v, g, y, V) => {
131
131
  const E = {
132
132
  initialState: s,
133
133
  updaterState: nt(
134
134
  t,
135
135
  g,
136
- h,
136
+ y,
137
137
  V
138
138
  ),
139
139
  state: v
140
140
  };
141
- ht(t, E.initialState), ct(t, E.updaterState), Z(t, E.state);
142
- }, ut = (t) => {
141
+ vt(t, E.initialState), it(t, E.updaterState), Z(t, E.state);
142
+ }, dt = (t) => {
143
143
  const s = n.getState().stateComponents.get(t);
144
144
  if (!s) return;
145
145
  const v = /* @__PURE__ */ new Set();
@@ -151,27 +151,27 @@ const ae = (t, s) => {
151
151
  }, se = (t, s) => {
152
152
  const v = n.getState().stateComponents.get(t);
153
153
  if (v) {
154
- const g = `${t}////${s}`, h = v.components.get(g);
155
- if ((h ? Array.isArray(h.reactiveType) ? h.reactiveType : [h.reactiveType || "component"] : null)?.includes("none"))
154
+ const g = `${t}////${s}`, y = v.components.get(g);
155
+ if ((y ? Array.isArray(y.reactiveType) ? y.reactiveType : [y.reactiveType || "component"] : null)?.includes("none"))
156
156
  return;
157
- h && h.forceUpdate();
157
+ y && y.forceUpdate();
158
158
  }
159
- }, Lt = (t, s, v, g) => {
159
+ }, Bt = (t, s, v, g) => {
160
160
  switch (t) {
161
161
  case "update":
162
162
  return {
163
- oldValue: B(s, g),
164
- newValue: B(v, g)
163
+ oldValue: H(s, g),
164
+ newValue: H(v, g)
165
165
  };
166
166
  case "insert":
167
167
  return {
168
168
  oldValue: null,
169
169
  // or undefined
170
- newValue: B(v, g)
170
+ newValue: H(v, g)
171
171
  };
172
172
  case "cut":
173
173
  return {
174
- oldValue: B(s, g),
174
+ oldValue: H(s, g),
175
175
  newValue: null
176
176
  // or undefined
177
177
  };
@@ -183,63 +183,63 @@ function Ht(t, {
183
183
  stateKey: s,
184
184
  serverSync: v,
185
185
  localStorage: g,
186
- formElements: h,
186
+ formElements: y,
187
187
  reactiveDeps: V,
188
188
  reactiveType: E,
189
189
  componentId: I,
190
190
  initialState: i,
191
- syncUpdate: y,
191
+ syncUpdate: h,
192
192
  dependencies: o,
193
193
  serverState: S
194
194
  } = {}) {
195
- const [G, j] = X({}), { sessionId: R } = bt();
195
+ const [G, M] = Q({}), { sessionId: j } = kt();
196
196
  let L = !s;
197
- const [m] = X(s ?? vt()), l = n.getState().stateLog[m], rt = Y(/* @__PURE__ */ new Set()), q = Y(I ?? vt()), _ = Y(
197
+ const [m] = Q(s ?? mt()), l = n.getState().stateLog[m], rt = Y(/* @__PURE__ */ new Set()), q = Y(I ?? mt()), _ = Y(
198
198
  null
199
199
  );
200
- _.current = Q(m) ?? null, it(() => {
201
- if (y && y.stateKey === m && y.path?.[0]) {
200
+ _.current = K(m) ?? null, st(() => {
201
+ if (h && h.stateKey === m && h.path?.[0]) {
202
202
  Z(m, (r) => ({
203
203
  ...r,
204
- [y.path[0]]: y.newValue
204
+ [h.path[0]]: h.newValue
205
205
  }));
206
- const e = `${y.stateKey}:${y.path.join(".")}`;
206
+ const e = `${h.stateKey}:${h.path.join(".")}`;
207
207
  n.getState().setSyncInfo(e, {
208
- timeStamp: y.timeStamp,
209
- userId: y.userId
208
+ timeStamp: h.timeStamp,
209
+ userId: h.userId
210
210
  });
211
211
  }
212
- }, [y]), it(() => {
212
+ }, [h]), st(() => {
213
213
  if (i) {
214
- wt(m, {
214
+ Et(m, {
215
215
  initialState: i
216
216
  });
217
217
  const e = _.current, a = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, c = n.getState().initialStateGlobal[m];
218
- if (!(c && !H(c, i) || !c) && !a)
218
+ if (!(c && !B(c, i) || !c) && !a)
219
219
  return;
220
220
  let u = null;
221
221
  const k = J(e?.localStorage?.key) ? e?.localStorage?.key(i) : e?.localStorage?.key;
222
- k && R && (u = dt(`${R}-${m}-${k}`));
222
+ k && j && (u = lt(`${j}-${m}-${k}`));
223
223
  let p = i, w = !1;
224
224
  const C = a ? Date.now() : 0, A = u?.lastUpdated || 0, N = u?.lastSyncedWithServer || 0;
225
- a && C > A ? (p = e.serverState.data, w = !0) : u && A > N && (p = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(p)), xt(
225
+ a && C > A ? (p = e.serverState.data, w = !0) : u && A > N && (p = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(p)), Vt(
226
226
  m,
227
227
  i,
228
228
  p,
229
- K,
229
+ tt,
230
230
  q.current,
231
- R
232
- ), w && k && R && $t(p, m, e, R, Date.now()), ut(m), (Array.isArray(E) ? E : [E || "component"]).includes("none") || j({});
231
+ j
232
+ ), w && k && j && Tt(p, m, e, j, Date.now()), dt(m), (Array.isArray(E) ? E : [E || "component"]).includes("none") || M({});
233
233
  }
234
234
  }, [
235
235
  i,
236
236
  S?.status,
237
237
  S?.data,
238
238
  ...o || []
239
- ]), st(() => {
240
- L && wt(m, {
239
+ ]), at(() => {
240
+ L && Et(m, {
241
241
  serverSync: v,
242
- formElements: h,
242
+ formElements: y,
243
243
  initialState: i,
244
244
  localStorage: g,
245
245
  middleware: _.current?.middleware
@@ -248,17 +248,17 @@ function Ht(t, {
248
248
  components: /* @__PURE__ */ new Map()
249
249
  };
250
250
  return r.components.set(e, {
251
- forceUpdate: () => j({}),
251
+ forceUpdate: () => M({}),
252
252
  paths: /* @__PURE__ */ new Set(),
253
253
  deps: [],
254
254
  depsFunction: V || void 0,
255
255
  reactiveType: E ?? ["component", "deps"]
256
- }), n.getState().stateComponents.set(m, r), j({}), () => {
256
+ }), n.getState().stateComponents.set(m, r), M({}), () => {
257
257
  const a = `${m}////${q.current}`;
258
258
  r && (r.components.delete(a), r.components.size === 0 && n.getState().stateComponents.delete(m));
259
259
  };
260
260
  }, []);
261
- const K = (e, r, a, c) => {
261
+ const tt = (e, r, a, c) => {
262
262
  if (Array.isArray(r)) {
263
263
  const f = `${m}-${r.join(".")}`;
264
264
  rt.current.add(f);
@@ -266,26 +266,26 @@ function Ht(t, {
266
266
  Z(m, (f) => {
267
267
  const u = J(e) ? e(f) : e, k = `${m}-${r.join(".")}`;
268
268
  if (k) {
269
- let U = !1, x = n.getState().signalDomElements.get(k);
269
+ let R = !1, x = n.getState().signalDomElements.get(k);
270
270
  if ((!x || x.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
271
- const O = r.slice(0, -1), D = B(u, O);
271
+ const O = r.slice(0, -1), D = H(u, O);
272
272
  if (Array.isArray(D)) {
273
- U = !0;
273
+ R = !0;
274
274
  const T = `${m}-${O.join(".")}`;
275
275
  x = n.getState().signalDomElements.get(T);
276
276
  }
277
277
  }
278
278
  if (x) {
279
- const O = U ? B(u, r.slice(0, -1)) : B(u, r);
279
+ const O = R ? H(u, r.slice(0, -1)) : H(u, r);
280
280
  x.forEach(({ parentId: D, position: T, effect: $ }) => {
281
281
  const b = document.querySelector(
282
282
  `[data-parent-id="${D}"]`
283
283
  );
284
284
  if (b) {
285
- const F = Array.from(b.childNodes);
286
- if (F[T]) {
285
+ const U = Array.from(b.childNodes);
286
+ if (U[T]) {
287
287
  const P = $ ? new Function("state", `return (${$})(state)`)(O) : O;
288
- F[T].textContent = String(P);
288
+ U[T].textContent = String(P);
289
289
  }
290
290
  }
291
291
  });
@@ -297,18 +297,18 @@ function Ht(t, {
297
297
  const p = r.slice(0, r.length - 1);
298
298
  a.updateType === "cut" && _.current?.validation?.key && z(
299
299
  _.current?.validation?.key + "." + p.join(".")
300
- ), a.updateType === "insert" && _.current?.validation?.key && Ut(
300
+ ), a.updateType === "insert" && _.current?.validation?.key && Ft(
301
301
  _.current?.validation?.key + "." + p.join(".")
302
302
  ).filter(([x, O]) => {
303
303
  let D = x?.split(".").length;
304
304
  if (x == p.join(".") && D == p.length - 1) {
305
305
  let T = x + "." + p;
306
- z(x), Dt(T, O);
306
+ z(x), Wt(T, O);
307
307
  }
308
308
  });
309
309
  const w = n.getState().stateComponents.get(m);
310
310
  if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", w), w) {
311
- const U = mt(f, u), x = new Set(U), O = a.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
311
+ const R = St(f, u), x = new Set(R), O = a.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
312
312
  for (const [
313
313
  D,
314
314
  T
@@ -321,26 +321,26 @@ function Ht(t, {
321
321
  continue;
322
322
  }
323
323
  if (b.includes("component") && ((T.paths.has(O) || T.paths.has("")) && ($ = !0), !$))
324
- for (const F of x) {
325
- let P = F;
324
+ for (const U of x) {
325
+ let P = U;
326
326
  for (; ; ) {
327
327
  if (T.paths.has(P)) {
328
328
  $ = !0;
329
329
  break;
330
330
  }
331
- const M = P.lastIndexOf(".");
332
- if (M !== -1) {
333
- const tt = P.substring(
331
+ const F = P.lastIndexOf(".");
332
+ if (F !== -1) {
333
+ const X = P.substring(
334
334
  0,
335
- M
335
+ F
336
336
  );
337
337
  if (!isNaN(
338
- Number(P.substring(M + 1))
339
- ) && T.paths.has(tt)) {
338
+ Number(P.substring(F + 1))
339
+ ) && T.paths.has(X)) {
340
340
  $ = !0;
341
341
  break;
342
342
  }
343
- P = tt;
343
+ P = X;
344
344
  } else
345
345
  P = "";
346
346
  if (P === "")
@@ -349,20 +349,20 @@ function Ht(t, {
349
349
  if ($) break;
350
350
  }
351
351
  if (!$ && b.includes("deps") && T.depsFunction) {
352
- const F = T.depsFunction(u);
352
+ const U = T.depsFunction(u);
353
353
  let P = !1;
354
- typeof F == "boolean" ? F && (P = !0) : H(T.deps, F) || (T.deps = F, P = !0), P && ($ = !0);
354
+ typeof U == "boolean" ? U && (P = !0) : B(T.deps, U) || (T.deps = U, P = !0), P && ($ = !0);
355
355
  }
356
356
  $ && T.forceUpdate();
357
357
  }
358
358
  }
359
359
  }
360
360
  const C = Date.now();
361
- r = r.map((U, x) => {
362
- const O = r.slice(0, -1), D = B(u, O);
363
- return x === r.length - 1 && ["insert", "cut"].includes(a.updateType) ? (D.length - 1).toString() : U;
361
+ r = r.map((R, x) => {
362
+ const O = r.slice(0, -1), D = H(u, O);
363
+ return x === r.length - 1 && ["insert", "cut"].includes(a.updateType) ? (D.length - 1).toString() : R;
364
364
  });
365
- const { oldValue: A, newValue: N } = Lt(
365
+ const { oldValue: A, newValue: N } = Bt(
366
366
  a.updateType,
367
367
  f,
368
368
  u,
@@ -376,25 +376,25 @@ function Ht(t, {
376
376
  oldValue: A,
377
377
  newValue: N
378
378
  };
379
- if (Ft(m, (U) => {
380
- const O = [...U ?? [], W].reduce((D, T) => {
379
+ if (Dt(m, (R) => {
380
+ const O = [...R ?? [], W].reduce((D, T) => {
381
381
  const $ = `${T.stateKey}:${JSON.stringify(T.path)}`, b = D.get($);
382
382
  return b ? (b.timeStamp = Math.max(b.timeStamp, T.timeStamp), b.newValue = T.newValue, b.oldValue = b.oldValue ?? T.oldValue, b.updateType = T.updateType) : D.set($, { ...T }), D;
383
383
  }, /* @__PURE__ */ new Map());
384
384
  return Array.from(O.values());
385
- }), $t(
385
+ }), Tt(
386
386
  u,
387
387
  m,
388
388
  _.current,
389
- R
389
+ j
390
390
  ), _.current?.middleware && _.current.middleware({
391
391
  updateLog: l,
392
392
  update: W
393
393
  }), _.current?.serverSync) {
394
- const U = n.getState().serverState[m], x = _.current?.serverSync;
395
- Wt(m, {
394
+ const R = n.getState().serverState[m], x = _.current?.serverSync;
395
+ Gt(m, {
396
396
  syncKey: typeof x.syncKey == "string" ? x.syncKey : x.syncKey({ state: u }),
397
- rollBackState: U,
397
+ rollBackState: R,
398
398
  actionTimeStamp: Date.now() + (x.debounce ?? 3e3),
399
399
  status: "waiting"
400
400
  });
@@ -402,57 +402,57 @@ function Ht(t, {
402
402
  return u;
403
403
  });
404
404
  };
405
- n.getState().updaterState[m] || (ct(
405
+ n.getState().updaterState[m] || (it(
406
406
  m,
407
407
  nt(
408
408
  m,
409
- K,
409
+ tt,
410
410
  q.current,
411
- R
411
+ j
412
412
  )
413
- ), n.getState().cogsStateStore[m] || Z(m, t), n.getState().initialStateGlobal[m] || ht(m, t));
414
- const d = At(() => nt(
413
+ ), n.getState().cogsStateStore[m] || Z(m, t), n.getState().initialStateGlobal[m] || vt(m, t));
414
+ const d = Ct(() => nt(
415
415
  m,
416
- K,
416
+ tt,
417
417
  q.current,
418
- R
419
- ), [m, R]);
420
- return [kt(m), d];
418
+ j
419
+ ), [m, j]);
420
+ return [xt(m), d];
421
421
  }
422
422
  function nt(t, s, v, g) {
423
- const h = /* @__PURE__ */ new Map();
423
+ const y = /* @__PURE__ */ new Map();
424
424
  let V = 0;
425
- const E = (y) => {
426
- const o = y.join(".");
427
- for (const [S] of h)
428
- (S === o || S.startsWith(o + ".")) && h.delete(S);
425
+ const E = (h) => {
426
+ const o = h.join(".");
427
+ for (const [S] of y)
428
+ (S === o || S.startsWith(o + ".")) && y.delete(S);
429
429
  V++;
430
430
  }, I = {
431
- removeValidation: (y) => {
432
- y?.validationKey && z(y.validationKey);
431
+ removeValidation: (h) => {
432
+ h?.validationKey && z(h.validationKey);
433
433
  },
434
- revertToInitialState: (y) => {
434
+ revertToInitialState: (h) => {
435
435
  const o = n.getState().getInitialOptions(t)?.validation;
436
- o?.key && z(o?.key), y?.validationKey && z(y.validationKey);
436
+ o?.key && z(o?.key), h?.validationKey && z(h.validationKey);
437
437
  const S = n.getState().initialStateGlobal[t];
438
- n.getState().clearSelectedIndexesForState(t), h.clear(), V++;
439
- const G = i(S, []), j = Q(t), R = J(j?.localStorage?.key) ? j?.localStorage?.key(S) : j?.localStorage?.key, L = `${g}-${t}-${R}`;
440
- L && localStorage.removeItem(L), ct(t, G), Z(t, S);
438
+ n.getState().clearSelectedIndexesForState(t), y.clear(), V++;
439
+ const G = i(S, []), M = K(t), j = J(M?.localStorage?.key) ? M?.localStorage?.key(S) : M?.localStorage?.key, L = `${g}-${t}-${j}`;
440
+ L && localStorage.removeItem(L), it(t, G), Z(t, S);
441
441
  const m = n.getState().stateComponents.get(t);
442
442
  return m && m.components.forEach((l) => {
443
443
  l.forceUpdate();
444
444
  }), S;
445
445
  },
446
- updateInitialState: (y) => {
447
- h.clear(), V++;
446
+ updateInitialState: (h) => {
447
+ y.clear(), V++;
448
448
  const o = nt(
449
449
  t,
450
450
  s,
451
451
  v,
452
452
  g
453
- ), S = n.getState().initialStateGlobal[t], G = Q(t), j = J(G?.localStorage?.key) ? G?.localStorage?.key(S) : G?.localStorage?.key, R = `${g}-${t}-${j}`;
454
- return localStorage.getItem(R) && localStorage.removeItem(R), Ct(() => {
455
- ht(t, y), ct(t, o), Z(t, y);
453
+ ), S = n.getState().initialStateGlobal[t], G = K(t), M = J(G?.localStorage?.key) ? G?.localStorage?.key(S) : G?.localStorage?.key, j = `${g}-${t}-${M}`;
454
+ return localStorage.getItem(j) && localStorage.removeItem(j), _t(() => {
455
+ vt(t, h), it(t, o), Z(t, h);
456
456
  const L = n.getState().stateComponents.get(t);
457
457
  L && L.components.forEach((m) => {
458
458
  m.forceUpdate();
@@ -465,27 +465,27 @@ function nt(t, s, v, g) {
465
465
  _serverState: n.getState().serverState[t],
466
466
  _isLoading: n.getState().isLoadingGlobal[t],
467
467
  _isServerSynced: () => {
468
- const y = n.getState().serverState[t];
469
- return !!(y && H(y, kt(t)));
468
+ const h = n.getState().serverState[t];
469
+ return !!(h && B(h, xt(t)));
470
470
  }
471
471
  };
472
- function i(y, o = [], S) {
472
+ function i(h, o = [], S) {
473
473
  const G = o.map(String).join(".");
474
- h.get(G);
475
- const j = function() {
474
+ y.get(G);
475
+ const M = function() {
476
476
  return n().getNestedState(t, o);
477
477
  };
478
478
  Object.keys(I).forEach((m) => {
479
- j[m] = I[m];
479
+ M[m] = I[m];
480
480
  });
481
- const R = {
481
+ const j = {
482
482
  apply(m, l, rt) {
483
483
  return console.log(
484
484
  `PROXY APPLY TRAP HIT: stateKey=${t}, path=${o.join(".")}`
485
485
  ), console.trace("Apply trap stack trace"), n().getNestedState(t, o);
486
486
  },
487
487
  get(m, l) {
488
- S?.validIndices && !Array.isArray(y) && (S = { ...S, validIndices: void 0 });
488
+ S?.validIndices && !Array.isArray(h) && (S = { ...S, validIndices: void 0 });
489
489
  const rt = /* @__PURE__ */ new Set([
490
490
  "insert",
491
491
  "cut",
@@ -526,7 +526,7 @@ function nt(t, s, v, g) {
526
526
  }
527
527
  }
528
528
  if (l === "getDifferences")
529
- return () => mt(
529
+ return () => St(
530
530
  n.getState().cogsStateStore[t],
531
531
  n.getState().initialStateGlobal[t]
532
532
  );
@@ -554,20 +554,20 @@ function nt(t, s, v, g) {
554
554
  }
555
555
  };
556
556
  if (l === "_status") {
557
- const d = n.getState().getNestedState(t, o), e = n.getState().initialStateGlobal[t], r = B(e, o);
558
- return H(d, r) ? "fresh" : "stale";
557
+ const d = n.getState().getNestedState(t, o), e = n.getState().initialStateGlobal[t], r = H(e, o);
558
+ return B(d, r) ? "fresh" : "stale";
559
559
  }
560
560
  if (l === "getStatus")
561
561
  return function() {
562
562
  const d = n().getNestedState(
563
563
  t,
564
564
  o
565
- ), e = n.getState().initialStateGlobal[t], r = B(e, o);
566
- return H(d, r) ? "fresh" : "stale";
565
+ ), e = n.getState().initialStateGlobal[t], r = H(e, o);
566
+ return B(d, r) ? "fresh" : "stale";
567
567
  };
568
568
  if (l === "removeStorage")
569
569
  return () => {
570
- const d = n.getState().initialStateGlobal[t], e = Q(t), r = J(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, a = `${g}-${t}-${r}`;
570
+ const d = n.getState().initialStateGlobal[t], e = K(t), r = J(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, a = `${g}-${t}-${r}`;
571
571
  a && localStorage.removeItem(a);
572
572
  };
573
573
  if (l === "showValidationErrors")
@@ -577,8 +577,8 @@ function nt(t, s, v, g) {
577
577
  throw new Error("Validation key not found");
578
578
  return n.getState().getValidationErrors(d.key + "." + o.join("."));
579
579
  };
580
- if (Array.isArray(y)) {
581
- const d = () => S?.validIndices ? y.map((r, a) => ({
580
+ if (Array.isArray(h)) {
581
+ const d = () => S?.validIndices ? h.map((r, a) => ({
582
582
  item: r,
583
583
  originalIndex: S.validIndices[a]
584
584
  })) : n.getState().getNestedState(t, o).map((r, a) => ({
@@ -590,7 +590,7 @@ function nt(t, s, v, g) {
590
590
  const e = n.getState().getSelectedIndex(t, o.join("."));
591
591
  if (e !== void 0)
592
592
  return i(
593
- y[e],
593
+ h[e],
594
594
  [...o, e.toString()],
595
595
  S
596
596
  );
@@ -612,16 +612,16 @@ function nt(t, s, v, g) {
612
612
  throw new Error(
613
613
  "[cogs-state] `useVirtualView` requires a positive number for `itemHeight` option."
614
614
  );
615
- const f = Y(null), u = Y(!0), [k, p] = X({
615
+ const f = Y(null), u = Y(!0), [k, p] = Q({
616
616
  startIndex: 0,
617
617
  endIndex: 10
618
618
  }), w = Y(
619
619
  `${t}-virtual-${o.join(".")}-${Math.random()}`
620
- ).current, [, C] = X({}), A = n().getNestedState(
620
+ ).current, [, C] = Q({}), A = n().getNestedState(
621
621
  t,
622
622
  o
623
623
  ), N = A.length, W = N * r;
624
- st(() => {
624
+ at(() => {
625
625
  const $ = A.slice(
626
626
  k.startIndex,
627
627
  k.endIndex
@@ -635,20 +635,20 @@ function nt(t, s, v, g) {
635
635
  g
636
636
  )
637
637
  );
638
- const b = `${t}////${v}-virtual`, F = n.getState().stateComponents.get(t) || {
638
+ const b = `${t}////${v}-virtual`, U = n.getState().stateComponents.get(t) || {
639
639
  components: /* @__PURE__ */ new Map()
640
640
  };
641
- return F.components.set(b, {
641
+ return U.components.set(b, {
642
642
  forceUpdate: () => C({}),
643
643
  paths: /* @__PURE__ */ new Set([o.join(".")]),
644
644
  reactiveType: ["component"]
645
- }), n.getState().stateComponents.set(t, F), () => {
645
+ }), n.getState().stateComponents.set(t, U), () => {
646
646
  const P = n.getState().stateComponents.get(t);
647
647
  P && P.components.delete(b);
648
- const M = n.getState();
649
- delete M.cogsStateStore[w], delete M.updaterState[w], M.stateComponents.delete(w);
648
+ const F = n.getState();
649
+ delete F.cogsStateStore[w], delete F.updaterState[w], F.stateComponents.delete(w);
650
650
  };
651
- }, []), it(() => {
651
+ }, []), st(() => {
652
652
  const $ = A.slice(
653
653
  k.startIndex,
654
654
  k.endIndex
@@ -659,42 +659,42 @@ function nt(t, s, v, g) {
659
659
  k.endIndex,
660
660
  w,
661
661
  A.length
662
- ]), st(() => {
662
+ ]), at(() => {
663
663
  const $ = f.current;
664
664
  if (!$) return;
665
665
  const b = () => {
666
- const M = $.scrollTop, tt = $.clientHeight, Vt = $.scrollHeight - (M + tt) < 50, yt = Math.max(
667
- 0,
668
- Math.floor(M / r) - a
669
- );
670
- let ot;
671
- Vt ? ot = N : ot = Math.min(
672
- N,
673
- Math.ceil((M + tt) / r) + a
674
- ), p((gt) => gt.startIndex === yt && gt.endIndex === ot ? gt : { startIndex: yt, endIndex: ot });
675
- }, F = () => {
676
- const M = f.current;
677
- M && (u.current = M.scrollHeight > 0 && Math.abs(
678
- M.scrollHeight - M.scrollTop - M.clientHeight
679
- ) < 1, b());
680
- };
681
- b(), $.addEventListener("scroll", F, {
666
+ if (!$) return;
667
+ const F = $.scrollTop, X = $.clientHeight, At = Math.floor(F / r), Nt = Math.ceil(
668
+ (F + X) / r
669
+ ), yt = Math.max(0, At - a), ht = Math.min(N, Nt + a);
670
+ p((ut) => ut.startIndex === yt && ut.endIndex === ht ? ut : { startIndex: yt, endIndex: ht });
671
+ }, U = pt(() => {
672
+ const F = f.current;
673
+ if (!F) return;
674
+ const X = F.scrollHeight - F.scrollTop - F.clientHeight < 1;
675
+ u.current = X, b();
676
+ }, 10);
677
+ b(), $.addEventListener("scroll", U, {
682
678
  passive: !0
683
679
  });
684
- const P = new ResizeObserver(b);
685
- return P.observe($), c && u.current && $.scrollTo({
686
- top: $.scrollHeight,
687
- behavior: "auto"
680
+ const P = new ResizeObserver(() => {
681
+ b();
682
+ });
683
+ return P.observe($), c && u.current && N > 0 && requestAnimationFrame(() => {
684
+ $.scrollTo({
685
+ top: $.scrollHeight,
686
+ behavior: "auto"
687
+ });
688
688
  }), () => {
689
- $.removeEventListener("scroll", F), P.disconnect();
689
+ $.removeEventListener("scroll", U), P.disconnect();
690
690
  };
691
691
  }, [N, r, a, c]);
692
- const U = n.getState().updaterState[w], x = ft(
692
+ const R = n.getState().updaterState[w], x = gt(
693
693
  ($, b = "auto") => {
694
694
  f.current?.scrollTo({ top: $, behavior: b });
695
695
  },
696
696
  []
697
- ), O = ft(
697
+ ), O = gt(
698
698
  ($ = "smooth") => {
699
699
  const b = f.current;
700
700
  b && b.scrollTo({
@@ -703,7 +703,7 @@ function nt(t, s, v, g) {
703
703
  });
704
704
  },
705
705
  []
706
- ), D = ft(
706
+ ), D = gt(
707
707
  ($, b = "smooth") => {
708
708
  x($ * r, b);
709
709
  },
@@ -735,7 +735,7 @@ function nt(t, s, v, g) {
735
735
  }
736
736
  };
737
737
  return {
738
- virtualState: U,
738
+ virtualState: R,
739
739
  virtualizerProps: T,
740
740
  scrollToBottom: O,
741
741
  scrollToIndex: D
@@ -774,8 +774,8 @@ function nt(t, s, v, g) {
774
774
  const u = [...o, f.toString()], k = i(a, u, S);
775
775
  return e(a, k, {
776
776
  register: () => {
777
- const [, w] = X({}), C = `${v}-${o.join(".")}-${f}`;
778
- st(() => {
777
+ const [, w] = Q({}), C = `${v}-${o.join(".")}-${f}`;
778
+ at(() => {
779
779
  const A = `${t}////${C}`, N = n.getState().stateComponents.get(t) || {
780
780
  components: /* @__PURE__ */ new Map()
781
781
  };
@@ -798,7 +798,7 @@ function nt(t, s, v, g) {
798
798
  ), null);
799
799
  };
800
800
  if (l === "stateMapNoRender")
801
- return (e) => y.map((a, c) => {
801
+ return (e) => h.map((a, c) => {
802
802
  let f;
803
803
  S?.validIndices && S.validIndices[c] !== void 0 ? f = S.validIndices[c] : f = c;
804
804
  const u = [...o, f.toString()], k = i(a, u, S);
@@ -806,12 +806,12 @@ function nt(t, s, v, g) {
806
806
  a,
807
807
  k,
808
808
  c,
809
- y,
810
- i(y, o, S)
809
+ h,
810
+ i(h, o, S)
811
811
  );
812
812
  });
813
813
  if (l === "$stateMap")
814
- return (e) => lt(Bt, {
814
+ return (e) => ct(qt, {
815
815
  proxy: {
816
816
  _stateKey: t,
817
817
  _path: o,
@@ -822,8 +822,8 @@ function nt(t, s, v, g) {
822
822
  });
823
823
  if (l === "stateFlattenOn")
824
824
  return (e) => {
825
- const r = y;
826
- h.clear(), V++;
825
+ const r = h;
826
+ y.clear(), V++;
827
827
  const a = r.flatMap(
828
828
  (c) => c[e] ?? []
829
829
  );
@@ -835,7 +835,7 @@ function nt(t, s, v, g) {
835
835
  };
836
836
  if (l === "index")
837
837
  return (e) => {
838
- const r = y[e];
838
+ const r = h[e];
839
839
  return i(r, [...o, e.toString()]);
840
840
  };
841
841
  if (l === "last")
@@ -846,7 +846,7 @@ function nt(t, s, v, g) {
846
846
  return i(a, c);
847
847
  };
848
848
  if (l === "insert")
849
- return (e) => (E(o), St(s, e, o, t), i(
849
+ return (e) => (E(o), ft(s, e, o, t), i(
850
850
  n.getState().getNestedState(t, o),
851
851
  o
852
852
  ));
@@ -857,17 +857,17 @@ function nt(t, s, v, g) {
857
857
  if (!c.some((p) => {
858
858
  if (r) {
859
859
  const C = r.every(
860
- (A) => H(p[A], f[A])
860
+ (A) => B(p[A], f[A])
861
861
  );
862
862
  return C && (u = p), C;
863
863
  }
864
- const w = H(p, f);
864
+ const w = B(p, f);
865
865
  return w && (u = p), w;
866
866
  }))
867
- E(o), St(s, f, o, t);
867
+ E(o), ft(s, f, o, t);
868
868
  else if (a && u) {
869
869
  const p = a(u), w = c.map(
870
- (C) => H(C, u) ? p : C
870
+ (C) => B(C, u) ? p : C
871
871
  );
872
872
  E(o), et(s, w, o);
873
873
  }
@@ -875,20 +875,20 @@ function nt(t, s, v, g) {
875
875
  if (l === "cut")
876
876
  return (e, r) => {
877
877
  if (!r?.waitForSync)
878
- return E(o), at(s, o, t, e), i(
878
+ return E(o), ot(s, o, t, e), i(
879
879
  n.getState().getNestedState(t, o),
880
880
  o
881
881
  );
882
882
  };
883
883
  if (l === "cutByValue")
884
884
  return (e) => {
885
- for (let r = 0; r < y.length; r++)
886
- y[r] === e && at(s, o, t, r);
885
+ for (let r = 0; r < h.length; r++)
886
+ h[r] === e && ot(s, o, t, r);
887
887
  };
888
888
  if (l === "toggleByValue")
889
889
  return (e) => {
890
- const r = y.findIndex((a) => a === e);
891
- r > -1 ? at(s, o, t, r) : St(s, e, o, t);
890
+ const r = h.findIndex((a) => a === e);
891
+ r > -1 ? ot(s, o, t, r) : ft(s, e, o, t);
892
892
  };
893
893
  if (l === "stateFind")
894
894
  return (e) => {
@@ -913,7 +913,7 @@ function nt(t, s, v, g) {
913
913
  if (!isNaN(Number(q))) {
914
914
  const d = o.slice(0, -1), e = n.getState().getNestedState(t, d);
915
915
  if (Array.isArray(e) && l === "cut")
916
- return () => at(
916
+ return () => ot(
917
917
  s,
918
918
  d,
919
919
  t,
@@ -923,13 +923,13 @@ function nt(t, s, v, g) {
923
923
  if (l === "get")
924
924
  return () => n.getState().getNestedState(t, o);
925
925
  if (l === "$derive")
926
- return (d) => Tt({
926
+ return (d) => bt({
927
927
  _stateKey: t,
928
928
  _path: o,
929
929
  _effect: d.toString()
930
930
  });
931
931
  if (l === "$get")
932
- return () => Tt({
932
+ return () => bt({
933
933
  _stateKey: t,
934
934
  _path: o
935
935
  });
@@ -938,7 +938,7 @@ function nt(t, s, v, g) {
938
938
  return n.getState().getSyncInfo(d);
939
939
  }
940
940
  if (l == "getLocalStorage")
941
- return (d) => dt(g + "-" + t + "-" + d);
941
+ return (d) => lt(g + "-" + t + "-" + d);
942
942
  if (l === "_selected") {
943
943
  const d = o.slice(0, -1), e = d.join("."), r = n.getState().getNestedState(t, d);
944
944
  return Array.isArray(r) ? Number(o[o.length - 1]) === n.getState().getSelectedIndex(t, e) : void 0;
@@ -964,8 +964,8 @@ function nt(t, s, v, g) {
964
964
  if (o.length == 0) {
965
965
  if (l === "applyJsonPatch")
966
966
  return (d) => {
967
- const e = n.getState().cogsStateStore[t], a = Rt(e, d).newDocument;
968
- xt(
967
+ const e = n.getState().cogsStateStore[t], a = Ut(e, d).newDocument;
968
+ Vt(
969
969
  t,
970
970
  n.getState().initialStateGlobal[t],
971
971
  a,
@@ -975,7 +975,7 @@ function nt(t, s, v, g) {
975
975
  );
976
976
  const c = n.getState().stateComponents.get(t);
977
977
  if (c) {
978
- const f = mt(e, a), u = new Set(f);
978
+ const f = St(e, a), u = new Set(f);
979
979
  for (const [
980
980
  k,
981
981
  p
@@ -1000,10 +1000,10 @@ function nt(t, s, v, g) {
1000
1000
  w = !0;
1001
1001
  break;
1002
1002
  }
1003
- const U = A.substring(
1003
+ const R = A.substring(
1004
1004
  N + 1
1005
1005
  );
1006
- if (!isNaN(Number(U))) {
1006
+ if (!isNaN(Number(R))) {
1007
1007
  const x = W.lastIndexOf(".");
1008
1008
  if (x !== -1) {
1009
1009
  const O = W.substring(
@@ -1023,7 +1023,7 @@ function nt(t, s, v, g) {
1023
1023
  if (!w && C.includes("deps") && p.depsFunction) {
1024
1024
  const A = p.depsFunction(a);
1025
1025
  let N = !1;
1026
- typeof A == "boolean" ? A && (N = !0) : H(p.deps, A) || (p.deps = A, N = !0), N && (w = !0);
1026
+ typeof A == "boolean" ? A && (N = !0) : B(p.deps, A) || (p.deps = A, N = !0), N && (w = !0);
1027
1027
  }
1028
1028
  w && p.forceUpdate();
1029
1029
  }
@@ -1048,7 +1048,7 @@ function nt(t, s, v, g) {
1048
1048
  return c.success ? !0 : (c.error.errors.forEach((u) => {
1049
1049
  const k = u.path, p = u.message, w = [d.key, ...k].join(".");
1050
1050
  e(w, p);
1051
- }), ut(t), !1);
1051
+ }), dt(t), !1);
1052
1052
  } catch (a) {
1053
1053
  return console.error("Zod schema validation failed", a), !1;
1054
1054
  }
@@ -1057,7 +1057,7 @@ function nt(t, s, v, g) {
1057
1057
  if (l === "getComponents")
1058
1058
  return () => n().stateComponents.get(t);
1059
1059
  if (l === "getAllFormRefs")
1060
- return () => pt.getState().getFormRefsByStateKey(t);
1060
+ return () => wt.getState().getFormRefsByStateKey(t);
1061
1061
  if (l === "_initialState")
1062
1062
  return n.getState().initialStateGlobal[t];
1063
1063
  if (l === "_serverState")
@@ -1070,13 +1070,13 @@ function nt(t, s, v, g) {
1070
1070
  if (l === "removeValidation") return I.removeValidation;
1071
1071
  }
1072
1072
  if (l === "getFormRef")
1073
- return () => pt.getState().getFormRef(t + "." + o.join("."));
1073
+ return () => wt.getState().getFormRef(t + "." + o.join("."));
1074
1074
  if (l === "validationWrapper")
1075
1075
  return ({
1076
1076
  children: d,
1077
1077
  hideMessage: e
1078
1078
  }) => /* @__PURE__ */ It(
1079
- Ot,
1079
+ Mt,
1080
1080
  {
1081
1081
  formOpts: e ? { validation: { message: "" } } : void 0,
1082
1082
  path: o,
@@ -1092,7 +1092,7 @@ function nt(t, s, v, g) {
1092
1092
  if (l === "update")
1093
1093
  return (d, e) => {
1094
1094
  if (e?.debounce)
1095
- _t(() => {
1095
+ pt(() => {
1096
1096
  et(s, d, o, "");
1097
1097
  const r = n.getState().getNestedState(t, o);
1098
1098
  e?.afterUpdate && e.afterUpdate(r);
@@ -1106,7 +1106,7 @@ function nt(t, s, v, g) {
1106
1106
  };
1107
1107
  if (l === "formElement")
1108
1108
  return (d, e) => /* @__PURE__ */ It(
1109
- Mt,
1109
+ jt,
1110
1110
  {
1111
1111
  setState: s,
1112
1112
  stateKey: t,
@@ -1115,11 +1115,11 @@ function nt(t, s, v, g) {
1115
1115
  formOpts: e
1116
1116
  }
1117
1117
  );
1118
- const _ = [...o, l], K = n.getState().getNestedState(t, _);
1119
- return i(K, _, S);
1118
+ const _ = [...o, l], tt = n.getState().getNestedState(t, _);
1119
+ return i(tt, _, S);
1120
1120
  }
1121
- }, L = new Proxy(j, R);
1122
- return h.set(G, {
1121
+ }, L = new Proxy(M, j);
1122
+ return y.set(G, {
1123
1123
  proxy: L,
1124
1124
  stateVersion: V
1125
1125
  }), L;
@@ -1128,10 +1128,10 @@ function nt(t, s, v, g) {
1128
1128
  n.getState().getNestedState(t, [])
1129
1129
  );
1130
1130
  }
1131
- function Tt(t) {
1132
- return lt(qt, { proxy: t });
1131
+ function bt(t) {
1132
+ return ct(zt, { proxy: t });
1133
1133
  }
1134
- function Bt({
1134
+ function qt({
1135
1135
  proxy: t,
1136
1136
  rebuildStateShape: s
1137
1137
  }) {
@@ -1140,26 +1140,26 @@ function Bt({
1140
1140
  v,
1141
1141
  t._path
1142
1142
  ).stateMapNoRender(
1143
- (h, V, E, I, i) => t._mapFn(h, V, E, I, i)
1143
+ (y, V, E, I, i) => t._mapFn(y, V, E, I, i)
1144
1144
  ) : null;
1145
1145
  }
1146
- function qt({
1146
+ function zt({
1147
1147
  proxy: t
1148
1148
  }) {
1149
1149
  const s = Y(null), v = `${t._stateKey}-${t._path.join(".")}`;
1150
- return it(() => {
1150
+ return st(() => {
1151
1151
  const g = s.current;
1152
1152
  if (!g || !g.parentElement) return;
1153
- const h = g.parentElement, E = Array.from(h.childNodes).indexOf(g);
1154
- let I = h.getAttribute("data-parent-id");
1155
- I || (I = `parent-${crypto.randomUUID()}`, h.setAttribute("data-parent-id", I));
1156
- const y = {
1153
+ const y = g.parentElement, E = Array.from(y.childNodes).indexOf(g);
1154
+ let I = y.getAttribute("data-parent-id");
1155
+ I || (I = `parent-${crypto.randomUUID()}`, y.setAttribute("data-parent-id", I));
1156
+ const h = {
1157
1157
  instanceId: `instance-${crypto.randomUUID()}`,
1158
1158
  parentId: I,
1159
1159
  position: E,
1160
1160
  effect: t._effect
1161
1161
  };
1162
- n.getState().addSignalElement(v, y);
1162
+ n.getState().addSignalElement(v, h);
1163
1163
  const o = n.getState().getNestedState(t._stateKey, t._path);
1164
1164
  let S;
1165
1165
  if (t._effect)
@@ -1168,22 +1168,22 @@ function qt({
1168
1168
  "state",
1169
1169
  `return (${t._effect})(state)`
1170
1170
  )(o);
1171
- } catch (j) {
1172
- console.error("Error evaluating effect function during mount:", j), S = o;
1171
+ } catch (M) {
1172
+ console.error("Error evaluating effect function during mount:", M), S = o;
1173
1173
  }
1174
1174
  else
1175
1175
  S = o;
1176
1176
  S !== null && typeof S == "object" && (S = JSON.stringify(S));
1177
1177
  const G = document.createTextNode(String(S));
1178
1178
  g.replaceWith(G);
1179
- }, [t._stateKey, t._path.join("."), t._effect]), lt("span", {
1179
+ }, [t._stateKey, t._path.join("."), t._effect]), ct("span", {
1180
1180
  ref: s,
1181
1181
  style: { display: "none" },
1182
1182
  "data-signal-id": v
1183
1183
  });
1184
1184
  }
1185
1185
  function ie(t) {
1186
- const s = Nt(
1186
+ const s = Pt(
1187
1187
  (v) => {
1188
1188
  const g = n.getState().stateComponents.get(t._stateKey) || {
1189
1189
  components: /* @__PURE__ */ new Map()
@@ -1195,10 +1195,10 @@ function ie(t) {
1195
1195
  },
1196
1196
  () => n.getState().getNestedState(t._stateKey, t._path)
1197
1197
  );
1198
- return lt("text", {}, String(s));
1198
+ return ct("text", {}, String(s));
1199
1199
  }
1200
1200
  export {
1201
- Tt as $cogsSignal,
1201
+ bt as $cogsSignal,
1202
1202
  ie as $cogsSignalStore,
1203
1203
  oe as addStateOptions,
1204
1204
  ae as createCogsState,