cogsbox-state 0.5.251 → 0.5.253

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,62 +1,62 @@
1
1
  "use client";
2
- import { jsx as yt } from "react/jsx-runtime";
3
- import { useState as et, useRef as Z, useEffect as ft, useLayoutEffect as ot, useMemo as Tt, createElement as st, useSyncExternalStore as kt, startTransition as At, useCallback as ut } from "react";
4
- import { transformStateFunc as Vt, isDeepEqual as L, isFunction as z, getNestedValue as H, getDifferences as St, debounce as Nt } from "./utility.js";
5
- import { pushFunc as gt, updateFn as tt, cutFunc as rt, ValidationWrapper as Ct, FormControlComponent as Pt } from "./Functions.jsx";
6
- import _t from "superjson";
2
+ import { jsx as It } from "react/jsx-runtime";
3
+ import { useState as X, useRef as Y, useEffect as st, useLayoutEffect as at, useMemo as Vt, createElement as ct, useSyncExternalStore as At, startTransition as Nt, useCallback as gt } from "react";
4
+ import { transformStateFunc as Ct, isDeepEqual as H, isFunction as J, getNestedValue as B, getDifferences as St, debounce as Pt } from "./utility.js";
5
+ import { pushFunc as ft, updateFn as tt, cutFunc as ot, ValidationWrapper as _t, FormControlComponent as Ot } from "./Functions.jsx";
6
+ import Mt from "superjson";
7
7
  import { v4 as mt } from "uuid";
8
8
  import "zod";
9
- import { getGlobalStore as r, formRefStore as ht } from "./store.js";
10
- import { useCogsConfig as $t } from "./CogsStateClient.jsx";
11
- import { applyPatch as Ot } from "fast-json-patch";
12
- function It(t, s) {
13
- const y = r.getState().getInitialOptions, g = r.getState().setInitialStateOptions, v = y(t) || {};
9
+ import { getGlobalStore as n, formRefStore as pt } from "./store.js";
10
+ import { useCogsConfig as bt } from "./CogsStateClient.jsx";
11
+ import { applyPatch as jt } from "fast-json-patch";
12
+ function wt(t, s) {
13
+ const v = n.getState().getInitialOptions, g = n.getState().setInitialStateOptions, h = v(t) || {};
14
14
  g(t, {
15
- ...v,
15
+ ...h,
16
16
  ...s
17
17
  });
18
18
  }
19
- function pt({
19
+ function Et({
20
20
  stateKey: t,
21
21
  options: s,
22
- initialOptionsPart: y
22
+ initialOptionsPart: v
23
23
  }) {
24
- const g = X(t) || {}, v = y[t] || {}, x = r.getState().setInitialStateOptions, E = { ...v, ...g };
25
- let p = !1;
24
+ const g = Q(t) || {}, h = v[t] || {}, V = n.getState().setInitialStateOptions, E = { ...h, ...g };
25
+ let I = !1;
26
26
  if (s)
27
27
  for (const i in s)
28
- E.hasOwnProperty(i) ? (i == "localStorage" && s[i] && E[i].key !== s[i]?.key && (p = !0, E[i] = s[i]), i == "initialState" && s[i] && E[i] !== s[i] && // Different references
29
- !L(E[i], s[i]) && (p = !0, E[i] = s[i])) : (p = !0, E[i] = s[i]);
30
- p && x(t, E);
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]);
30
+ I && V(t, E);
31
31
  }
32
- function te(t, { formElements: s, validation: y }) {
33
- return { initialState: t, formElements: s, validation: y };
32
+ function ne(t, { formElements: s, validation: v }) {
33
+ return { initialState: t, formElements: s, validation: v };
34
34
  }
35
- const ee = (t, s) => {
36
- let y = t;
37
- const [g, v] = Vt(y);
38
- (Object.keys(v).length > 0 || s && Object.keys(s).length > 0) && Object.keys(v).forEach((p) => {
39
- v[p] = v[p] || {}, v[p].formElements = {
35
+ const re = (t, s) => {
36
+ let v = t;
37
+ const [g, h] = Ct(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 = {
40
40
  ...s?.formElements,
41
41
  // Global defaults first
42
42
  ...s?.validation,
43
- ...v[p].formElements || {}
43
+ ...h[I].formElements || {}
44
44
  // State-specific overrides
45
- }, X(p) || r.getState().setInitialStateOptions(p, v[p]);
46
- }), r.getState().setInitialStates(g), r.getState().setCreatedState(g);
47
- const x = (p, i) => {
48
- const [h] = et(i?.componentId ?? mt());
49
- pt({
50
- stateKey: p,
45
+ }, Q(I) || n.getState().setInitialStateOptions(I, h[I]);
46
+ }), n.getState().setInitialStates(g), n.getState().setCreatedState(g);
47
+ const V = (I, i) => {
48
+ const [y] = X(i?.componentId ?? mt());
49
+ Et({
50
+ stateKey: I,
51
51
  options: i,
52
- initialOptionsPart: v
52
+ initialOptionsPart: h
53
53
  });
54
- const o = r.getState().cogsStateStore[p] || g[p], S = i?.modifyState ? i.modifyState(o) : o, [W, j] = Wt(
54
+ const o = n.getState().cogsStateStore[I] || g[I], S = i?.modifyState ? i.modifyState(o) : o, [G, M] = Lt(
55
55
  S,
56
56
  {
57
- stateKey: p,
57
+ stateKey: I,
58
58
  syncUpdate: i?.syncUpdate,
59
- componentId: h,
59
+ componentId: y,
60
60
  localStorage: i?.localStorage,
61
61
  middleware: i?.middleware,
62
62
  enabledSync: i?.enabledSync,
@@ -67,49 +67,49 @@ const ee = (t, s) => {
67
67
  serverState: i?.serverState
68
68
  }
69
69
  );
70
- return j;
70
+ return M;
71
71
  };
72
- function E(p, i) {
73
- pt({ stateKey: p, options: i, initialOptionsPart: v }), i.localStorage && Ut(p, i), lt(p);
72
+ function E(I, i) {
73
+ Et({ stateKey: I, options: i, initialOptionsPart: h }), i.localStorage && Wt(I, i), dt(I);
74
74
  }
75
- return { useCogsState: x, setCogsOptions: E };
75
+ return { useCogsState: V, setCogsOptions: E };
76
76
  }, {
77
- setUpdaterState: at,
78
- setState: J,
79
- getInitialOptions: X,
80
- getKeyState: bt,
81
- getValidationErrors: Mt,
82
- setStateLog: Rt,
77
+ setUpdaterState: it,
78
+ setState: Z,
79
+ getInitialOptions: Q,
80
+ getKeyState: kt,
81
+ getValidationErrors: Rt,
82
+ setStateLog: Ut,
83
83
  updateInitialStateGlobal: vt,
84
- addValidationError: jt,
85
- removeValidationError: q,
86
- setServerSyncActions: Ft
87
- } = r.getState(), wt = (t, s, y, g, v) => {
88
- y?.log && console.log(
84
+ addValidationError: Ft,
85
+ removeValidationError: z,
86
+ setServerSyncActions: Dt
87
+ } = n.getState(), $t = (t, s, v, g, h) => {
88
+ v?.log && console.log(
89
89
  "saving to localstorage",
90
90
  s,
91
- y.localStorage?.key,
91
+ v.localStorage?.key,
92
92
  g
93
93
  );
94
- const x = z(y?.localStorage?.key) ? y.localStorage?.key(t) : y?.localStorage?.key;
95
- if (x && g) {
96
- const E = `${g}-${s}-${x}`;
97
- let p;
94
+ const V = J(v?.localStorage?.key) ? v.localStorage?.key(t) : v?.localStorage?.key;
95
+ if (V && g) {
96
+ const E = `${g}-${s}-${V}`;
97
+ let I;
98
98
  try {
99
- p = ct(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: v ?? p
106
- }, h = _t.serialize(i);
105
+ lastSyncedWithServer: h ?? I
106
+ }, y = Mt.serialize(i);
107
107
  window.localStorage.setItem(
108
108
  E,
109
- JSON.stringify(h.json)
109
+ JSON.stringify(y.json)
110
110
  );
111
111
  }
112
- }, ct = (t) => {
112
+ }, lt = (t) => {
113
113
  if (!t) return null;
114
114
  try {
115
115
  const s = window.localStorage.getItem(t);
@@ -117,61 +117,61 @@ const ee = (t, s) => {
117
117
  } catch (s) {
118
118
  return console.error("Error loading from localStorage:", s), null;
119
119
  }
120
- }, Ut = (t, s) => {
121
- const y = r.getState().cogsStateStore[t], { sessionId: g } = $t(), v = z(s?.localStorage?.key) ? s.localStorage.key(y) : s?.localStorage?.key;
122
- if (v && g) {
123
- const x = ct(
124
- `${g}-${t}-${v}`
120
+ }, Wt = (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 = lt(
124
+ `${g}-${t}-${h}`
125
125
  );
126
- if (x && x.lastUpdated > (x.lastSyncedWithServer || 0))
127
- return J(t, x.state), lt(t), !0;
126
+ if (V && V.lastUpdated > (V.lastSyncedWithServer || 0))
127
+ return Z(t, V.state), dt(t), !0;
128
128
  }
129
129
  return !1;
130
- }, xt = (t, s, y, g, v, x) => {
130
+ }, xt = (t, s, v, g, h, V) => {
131
131
  const E = {
132
132
  initialState: s,
133
- updaterState: it(
133
+ updaterState: et(
134
134
  t,
135
135
  g,
136
- v,
137
- x
136
+ h,
137
+ V
138
138
  ),
139
- state: y
139
+ state: v
140
140
  };
141
- vt(t, E.initialState), at(t, E.updaterState), J(t, E.state);
142
- }, lt = (t) => {
143
- const s = r.getState().stateComponents.get(t);
141
+ vt(t, E.initialState), it(t, E.updaterState), Z(t, E.state);
142
+ }, dt = (t) => {
143
+ const s = n.getState().stateComponents.get(t);
144
144
  if (!s) return;
145
- const y = /* @__PURE__ */ new Set();
145
+ const v = /* @__PURE__ */ new Set();
146
146
  s.components.forEach((g) => {
147
- (g ? Array.isArray(g.reactiveType) ? g.reactiveType : [g.reactiveType || "component"] : null)?.includes("none") || y.add(() => g.forceUpdate());
147
+ (g ? Array.isArray(g.reactiveType) ? g.reactiveType : [g.reactiveType || "component"] : null)?.includes("none") || v.add(() => g.forceUpdate());
148
148
  }), queueMicrotask(() => {
149
- y.forEach((g) => g());
149
+ v.forEach((g) => g());
150
150
  });
151
- }, ne = (t, s) => {
152
- const y = r.getState().stateComponents.get(t);
153
- if (y) {
154
- const g = `${t}////${s}`, v = y.components.get(g);
155
- if ((v ? Array.isArray(v.reactiveType) ? v.reactiveType : [v.reactiveType || "component"] : null)?.includes("none"))
151
+ }, oe = (t, s) => {
152
+ const v = n.getState().stateComponents.get(t);
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"))
156
156
  return;
157
- v && v.forceUpdate();
157
+ h && h.forceUpdate();
158
158
  }
159
- }, Dt = (t, s, y, g) => {
159
+ }, Gt = (t, s, v, g) => {
160
160
  switch (t) {
161
161
  case "update":
162
162
  return {
163
- oldValue: H(s, g),
164
- newValue: H(y, g)
163
+ oldValue: B(s, g),
164
+ newValue: B(v, g)
165
165
  };
166
166
  case "insert":
167
167
  return {
168
168
  oldValue: null,
169
169
  // or undefined
170
- newValue: H(y, g)
170
+ newValue: B(v, g)
171
171
  };
172
172
  case "cut":
173
173
  return {
174
- oldValue: H(s, g),
174
+ oldValue: B(s, g),
175
175
  newValue: null
176
176
  // or undefined
177
177
  };
@@ -179,313 +179,313 @@ const ee = (t, s) => {
179
179
  return { oldValue: null, newValue: null };
180
180
  }
181
181
  };
182
- function Wt(t, {
182
+ function Lt(t, {
183
183
  stateKey: s,
184
- serverSync: y,
184
+ serverSync: v,
185
185
  localStorage: g,
186
- formElements: v,
187
- reactiveDeps: x,
186
+ formElements: h,
187
+ reactiveDeps: V,
188
188
  reactiveType: E,
189
- componentId: p,
189
+ componentId: I,
190
190
  initialState: i,
191
- syncUpdate: h,
191
+ syncUpdate: y,
192
192
  dependencies: o,
193
193
  serverState: S
194
194
  } = {}) {
195
- const [W, j] = et({}), { sessionId: F } = $t();
196
- let G = !s;
197
- const [m] = et(s ?? mt()), l = r.getState().stateLog[m], nt = Z(/* @__PURE__ */ new Set()), B = Z(p ?? mt()), _ = Z(
195
+ const [G, M] = X({}), { sessionId: j } = bt();
196
+ let L = !s;
197
+ const [m] = X(s ?? mt()), l = n.getState().stateLog[m], nt = Y(/* @__PURE__ */ new Set()), q = Y(I ?? mt()), _ = Y(
198
198
  null
199
199
  );
200
- _.current = X(m) ?? null, ft(() => {
201
- if (h && h.stateKey === m && h.path?.[0]) {
202
- J(m, (n) => ({
203
- ...n,
204
- [h.path[0]]: h.newValue
200
+ _.current = Q(m) ?? null, st(() => {
201
+ if (y && y.stateKey === m && y.path?.[0]) {
202
+ Z(m, (r) => ({
203
+ ...r,
204
+ [y.path[0]]: y.newValue
205
205
  }));
206
- const e = `${h.stateKey}:${h.path.join(".")}`;
207
- r.getState().setSyncInfo(e, {
208
- timeStamp: h.timeStamp,
209
- userId: h.userId
206
+ const e = `${y.stateKey}:${y.path.join(".")}`;
207
+ n.getState().setSyncInfo(e, {
208
+ timeStamp: y.timeStamp,
209
+ userId: y.userId
210
210
  });
211
211
  }
212
- }, [h]), ft(() => {
212
+ }, [y]), st(() => {
213
213
  if (i) {
214
- It(m, {
214
+ wt(m, {
215
215
  initialState: i
216
216
  });
217
- const e = _.current, a = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, c = r.getState().initialStateGlobal[m];
218
- if (!(c && !L(c, i) || !c) && !a)
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)
219
219
  return;
220
220
  let u = null;
221
- const T = z(e?.localStorage?.key) ? e?.localStorage?.key(i) : e?.localStorage?.key;
222
- T && F && (u = ct(`${F}-${m}-${T}`));
223
- let w = i, $ = !1;
224
- const A = a ? Date.now() : 0, V = u?.lastUpdated || 0, O = u?.lastSyncedWithServer || 0;
225
- a && A > V ? (w = e.serverState.data, $ = !0) : u && V > O && (w = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(w)), xt(
221
+ const k = J(e?.localStorage?.key) ? e?.localStorage?.key(i) : e?.localStorage?.key;
222
+ k && j && (u = lt(`${j}-${m}-${k}`));
223
+ let p = i, w = !1;
224
+ const N = a ? Date.now() : 0, A = u?.lastUpdated || 0, C = u?.lastSyncedWithServer || 0;
225
+ a && N > A ? (p = e.serverState.data, w = !0) : u && A > C && (p = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(p)), xt(
226
226
  m,
227
227
  i,
228
- w,
229
- Q,
230
- B.current,
231
- F
232
- ), $ && T && F && wt(w, m, e, F, Date.now()), lt(m), (Array.isArray(E) ? E : [E || "component"]).includes("none") || j({});
228
+ p,
229
+ K,
230
+ q.current,
231
+ j
232
+ ), w && k && j && $t(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
- ]), ot(() => {
240
- G && It(m, {
241
- serverSync: y,
242
- formElements: v,
239
+ ]), at(() => {
240
+ L && wt(m, {
241
+ serverSync: v,
242
+ formElements: h,
243
243
  initialState: i,
244
244
  localStorage: g,
245
245
  middleware: _.current?.middleware
246
246
  });
247
- const e = `${m}////${B.current}`, n = r.getState().stateComponents.get(m) || {
247
+ const e = `${m}////${q.current}`, r = n.getState().stateComponents.get(m) || {
248
248
  components: /* @__PURE__ */ new Map()
249
249
  };
250
- return n.components.set(e, {
251
- forceUpdate: () => j({}),
250
+ return r.components.set(e, {
251
+ forceUpdate: () => M({}),
252
252
  paths: /* @__PURE__ */ new Set(),
253
253
  deps: [],
254
- depsFunction: x || void 0,
254
+ depsFunction: V || void 0,
255
255
  reactiveType: E ?? ["component", "deps"]
256
- }), r.getState().stateComponents.set(m, n), j({}), () => {
257
- const a = `${m}////${B.current}`;
258
- n && (n.components.delete(a), n.components.size === 0 && r.getState().stateComponents.delete(m));
256
+ }), n.getState().stateComponents.set(m, r), M({}), () => {
257
+ const a = `${m}////${q.current}`;
258
+ r && (r.components.delete(a), r.components.size === 0 && n.getState().stateComponents.delete(m));
259
259
  };
260
260
  }, []);
261
- const Q = (e, n, a, c) => {
262
- if (Array.isArray(n)) {
263
- const f = `${m}-${n.join(".")}`;
261
+ const K = (e, r, a, c) => {
262
+ if (Array.isArray(r)) {
263
+ const f = `${m}-${r.join(".")}`;
264
264
  nt.current.add(f);
265
265
  }
266
- J(m, (f) => {
267
- const u = z(e) ? e(f) : e, T = `${m}-${n.join(".")}`;
268
- if (T) {
269
- let M = !1, k = r.getState().signalDomElements.get(T);
270
- if ((!k || k.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
271
- const R = n.slice(0, -1), b = H(u, R);
272
- if (Array.isArray(b)) {
273
- M = !0;
274
- const I = `${m}-${R.join(".")}`;
275
- k = r.getState().signalDomElements.get(I);
266
+ Z(m, (f) => {
267
+ const u = J(e) ? e(f) : e, k = `${m}-${r.join(".")}`;
268
+ if (k) {
269
+ let U = !1, x = n.getState().signalDomElements.get(k);
270
+ if ((!x || x.size === 0) && (a.updateType === "insert" || a.updateType === "cut")) {
271
+ const O = r.slice(0, -1), D = B(u, O);
272
+ if (Array.isArray(D)) {
273
+ U = !0;
274
+ const T = `${m}-${O.join(".")}`;
275
+ x = n.getState().signalDomElements.get(T);
276
276
  }
277
277
  }
278
- if (k) {
279
- const R = M ? H(u, n.slice(0, -1)) : H(u, n);
280
- k.forEach(({ parentId: b, position: I, effect: C }) => {
281
- const N = document.querySelector(
282
- `[data-parent-id="${b}"]`
278
+ if (x) {
279
+ const O = U ? B(u, r.slice(0, -1)) : B(u, r);
280
+ x.forEach(({ parentId: D, position: T, effect: $ }) => {
281
+ const b = document.querySelector(
282
+ `[data-parent-id="${D}"]`
283
283
  );
284
- if (N) {
285
- const P = Array.from(N.childNodes);
286
- if (P[I]) {
287
- const U = C ? new Function("state", `return (${C})(state)`)(R) : R;
288
- P[I].textContent = String(U);
284
+ if (b) {
285
+ const F = Array.from(b.childNodes);
286
+ if (F[T]) {
287
+ const P = $ ? new Function("state", `return (${$})(state)`)(O) : O;
288
+ F[T].textContent = String(P);
289
289
  }
290
290
  }
291
291
  });
292
292
  }
293
293
  }
294
- a.updateType === "update" && (c || _.current?.validation?.key) && n && q(
295
- (c || _.current?.validation?.key) + "." + n.join(".")
294
+ a.updateType === "update" && (c || _.current?.validation?.key) && r && z(
295
+ (c || _.current?.validation?.key) + "." + r.join(".")
296
296
  );
297
- const w = n.slice(0, n.length - 1);
298
- a.updateType === "cut" && _.current?.validation?.key && q(
299
- _.current?.validation?.key + "." + w.join(".")
300
- ), a.updateType === "insert" && _.current?.validation?.key && Mt(
301
- _.current?.validation?.key + "." + w.join(".")
302
- ).filter(([k, R]) => {
303
- let b = k?.split(".").length;
304
- if (k == w.join(".") && b == w.length - 1) {
305
- let I = k + "." + w;
306
- q(k), jt(I, R);
297
+ const p = r.slice(0, r.length - 1);
298
+ a.updateType === "cut" && _.current?.validation?.key && z(
299
+ _.current?.validation?.key + "." + p.join(".")
300
+ ), a.updateType === "insert" && _.current?.validation?.key && Rt(
301
+ _.current?.validation?.key + "." + p.join(".")
302
+ ).filter(([x, O]) => {
303
+ let D = x?.split(".").length;
304
+ if (x == p.join(".") && D == p.length - 1) {
305
+ let T = x + "." + p;
306
+ z(x), Ft(T, O);
307
307
  }
308
308
  });
309
- const $ = r.getState().stateComponents.get(m);
310
- if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", $), $) {
311
- const M = St(f, u), k = new Set(M), R = a.updateType === "update" ? n.join(".") : n.slice(0, -1).join(".") || "";
309
+ const w = n.getState().stateComponents.get(m);
310
+ if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", w), w) {
311
+ const U = St(f, u), x = new Set(U), O = a.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
312
312
  for (const [
313
- b,
314
- I
315
- ] of $.components.entries()) {
316
- let C = !1;
317
- const N = Array.isArray(I.reactiveType) ? I.reactiveType : [I.reactiveType || "component"];
318
- if (console.log("component", I), !N.includes("none")) {
319
- if (N.includes("all")) {
320
- I.forceUpdate();
313
+ D,
314
+ T
315
+ ] of w.components.entries()) {
316
+ let $ = !1;
317
+ const b = Array.isArray(T.reactiveType) ? T.reactiveType : [T.reactiveType || "component"];
318
+ if (console.log("component", T), !b.includes("none")) {
319
+ if (b.includes("all")) {
320
+ T.forceUpdate();
321
321
  continue;
322
322
  }
323
- if (N.includes("component") && ((I.paths.has(R) || I.paths.has("")) && (C = !0), !C))
324
- for (const P of k) {
325
- let U = P;
323
+ if (b.includes("component") && ((T.paths.has(O) || T.paths.has("")) && ($ = !0), !$))
324
+ for (const F of x) {
325
+ let P = F;
326
326
  for (; ; ) {
327
- if (I.paths.has(U)) {
328
- C = !0;
327
+ if (T.paths.has(P)) {
328
+ $ = !0;
329
329
  break;
330
330
  }
331
- const Y = U.lastIndexOf(".");
332
- if (Y !== -1) {
333
- const K = U.substring(
331
+ const R = P.lastIndexOf(".");
332
+ if (R !== -1) {
333
+ const rt = P.substring(
334
334
  0,
335
- Y
335
+ R
336
336
  );
337
337
  if (!isNaN(
338
- Number(U.substring(Y + 1))
339
- ) && I.paths.has(K)) {
340
- C = !0;
338
+ Number(P.substring(R + 1))
339
+ ) && T.paths.has(rt)) {
340
+ $ = !0;
341
341
  break;
342
342
  }
343
- U = K;
343
+ P = rt;
344
344
  } else
345
- U = "";
346
- if (U === "")
345
+ P = "";
346
+ if (P === "")
347
347
  break;
348
348
  }
349
- if (C) break;
349
+ if ($) break;
350
350
  }
351
- if (!C && N.includes("deps") && I.depsFunction) {
352
- const P = I.depsFunction(u);
353
- let U = !1;
354
- typeof P == "boolean" ? P && (U = !0) : L(I.deps, P) || (I.deps = P, U = !0), U && (C = !0);
351
+ if (!$ && b.includes("deps") && T.depsFunction) {
352
+ const F = T.depsFunction(u);
353
+ let P = !1;
354
+ typeof F == "boolean" ? F && (P = !0) : H(T.deps, F) || (T.deps = F, P = !0), P && ($ = !0);
355
355
  }
356
- C && I.forceUpdate();
356
+ $ && T.forceUpdate();
357
357
  }
358
358
  }
359
359
  }
360
- const A = Date.now();
361
- n = n.map((M, k) => {
362
- const R = n.slice(0, -1), b = H(u, R);
363
- return k === n.length - 1 && ["insert", "cut"].includes(a.updateType) ? (b.length - 1).toString() : M;
360
+ const N = 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;
364
364
  });
365
- const { oldValue: V, newValue: O } = Dt(
365
+ const { oldValue: A, newValue: C } = Gt(
366
366
  a.updateType,
367
367
  f,
368
368
  u,
369
- n
370
- ), D = {
371
- timeStamp: A,
369
+ r
370
+ ), W = {
371
+ timeStamp: N,
372
372
  stateKey: m,
373
- path: n,
373
+ path: r,
374
374
  updateType: a.updateType,
375
375
  status: "new",
376
- oldValue: V,
377
- newValue: O
376
+ oldValue: A,
377
+ newValue: C
378
378
  };
379
- if (Rt(m, (M) => {
380
- const R = [...M ?? [], D].reduce((b, I) => {
381
- const C = `${I.stateKey}:${JSON.stringify(I.path)}`, N = b.get(C);
382
- return N ? (N.timeStamp = Math.max(N.timeStamp, I.timeStamp), N.newValue = I.newValue, N.oldValue = N.oldValue ?? I.oldValue, N.updateType = I.updateType) : b.set(C, { ...I }), b;
379
+ if (Ut(m, (U) => {
380
+ const O = [...U ?? [], W].reduce((D, T) => {
381
+ const $ = `${T.stateKey}:${JSON.stringify(T.path)}`, b = D.get($);
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
- return Array.from(R.values());
385
- }), wt(
384
+ return Array.from(O.values());
385
+ }), $t(
386
386
  u,
387
387
  m,
388
388
  _.current,
389
- F
389
+ j
390
390
  ), _.current?.middleware && _.current.middleware({
391
391
  updateLog: l,
392
- update: D
392
+ update: W
393
393
  }), _.current?.serverSync) {
394
- const M = r.getState().serverState[m], k = _.current?.serverSync;
395
- Ft(m, {
396
- syncKey: typeof k.syncKey == "string" ? k.syncKey : k.syncKey({ state: u }),
397
- rollBackState: M,
398
- actionTimeStamp: Date.now() + (k.debounce ?? 3e3),
394
+ const U = n.getState().serverState[m], x = _.current?.serverSync;
395
+ Dt(m, {
396
+ syncKey: typeof x.syncKey == "string" ? x.syncKey : x.syncKey({ state: u }),
397
+ rollBackState: U,
398
+ actionTimeStamp: Date.now() + (x.debounce ?? 3e3),
399
399
  status: "waiting"
400
400
  });
401
401
  }
402
402
  return u;
403
403
  });
404
404
  };
405
- r.getState().updaterState[m] || (at(
405
+ n.getState().updaterState[m] || (it(
406
406
  m,
407
- it(
407
+ et(
408
408
  m,
409
- Q,
410
- B.current,
411
- F
409
+ K,
410
+ q.current,
411
+ j
412
412
  )
413
- ), r.getState().cogsStateStore[m] || J(m, t), r.getState().initialStateGlobal[m] || vt(m, t));
414
- const d = Tt(() => it(
413
+ ), n.getState().cogsStateStore[m] || Z(m, t), n.getState().initialStateGlobal[m] || vt(m, t));
414
+ const d = Vt(() => et(
415
415
  m,
416
- Q,
417
- B.current,
418
- F
419
- ), [m, F]);
420
- return [bt(m), d];
416
+ K,
417
+ q.current,
418
+ j
419
+ ), [m, j]);
420
+ return [kt(m), d];
421
421
  }
422
- function it(t, s, y, g) {
423
- const v = /* @__PURE__ */ new Map();
424
- let x = 0;
425
- const E = (h) => {
426
- const o = h.join(".");
427
- for (const [S] of v)
428
- (S === o || S.startsWith(o + ".")) && v.delete(S);
429
- x++;
430
- }, p = {
431
- removeValidation: (h) => {
432
- h?.validationKey && q(h.validationKey);
422
+ function et(t, s, v, g) {
423
+ const h = /* @__PURE__ */ new Map();
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);
429
+ V++;
430
+ }, I = {
431
+ removeValidation: (y) => {
432
+ y?.validationKey && z(y.validationKey);
433
433
  },
434
- revertToInitialState: (h) => {
435
- const o = r.getState().getInitialOptions(t)?.validation;
436
- o?.key && q(o?.key), h?.validationKey && q(h.validationKey);
437
- const S = r.getState().initialStateGlobal[t];
438
- r.getState().clearSelectedIndexesForState(t), v.clear(), x++;
439
- const W = i(S, []), j = X(t), F = z(j?.localStorage?.key) ? j?.localStorage?.key(S) : j?.localStorage?.key, G = `${g}-${t}-${F}`;
440
- G && localStorage.removeItem(G), at(t, W), J(t, S);
441
- const m = r.getState().stateComponents.get(t);
434
+ revertToInitialState: (y) => {
435
+ const o = n.getState().getInitialOptions(t)?.validation;
436
+ o?.key && z(o?.key), y?.validationKey && z(y.validationKey);
437
+ const S = n.getState().initialStateGlobal[t];
438
+ n.getState().clearSelectedIndexesForState(t), h.clear(), V++;
439
+ const G = i(S, []), M = Q(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
+ 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: (h) => {
447
- v.clear(), x++;
448
- const o = it(
446
+ updateInitialState: (y) => {
447
+ h.clear(), V++;
448
+ const o = et(
449
449
  t,
450
450
  s,
451
- y,
451
+ v,
452
452
  g
453
- ), S = r.getState().initialStateGlobal[t], W = X(t), j = z(W?.localStorage?.key) ? W?.localStorage?.key(S) : W?.localStorage?.key, F = `${g}-${t}-${j}`;
454
- return localStorage.getItem(F) && localStorage.removeItem(F), At(() => {
455
- vt(t, h), at(t, o), J(t, h);
456
- const G = r.getState().stateComponents.get(t);
457
- G && G.components.forEach((m) => {
453
+ ), S = n.getState().initialStateGlobal[t], G = Q(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), Nt(() => {
455
+ vt(t, y), it(t, o), Z(t, y);
456
+ const L = n.getState().stateComponents.get(t);
457
+ L && L.components.forEach((m) => {
458
458
  m.forceUpdate();
459
459
  });
460
460
  }), {
461
- fetchId: (G) => o.get()[G]
461
+ fetchId: (L) => o.get()[L]
462
462
  };
463
463
  },
464
- _initialState: r.getState().initialStateGlobal[t],
465
- _serverState: r.getState().serverState[t],
466
- _isLoading: r.getState().isLoadingGlobal[t],
464
+ _initialState: n.getState().initialStateGlobal[t],
465
+ _serverState: n.getState().serverState[t],
466
+ _isLoading: n.getState().isLoadingGlobal[t],
467
467
  _isServerSynced: () => {
468
- const h = r.getState().serverState[t];
469
- return !!(h && L(h, bt(t)));
468
+ const y = n.getState().serverState[t];
469
+ return !!(y && H(y, kt(t)));
470
470
  }
471
471
  };
472
- function i(h, o = [], S) {
473
- const W = o.map(String).join(".");
474
- v.get(W);
475
- const j = function() {
476
- return r().getNestedState(t, o);
472
+ function i(y, o = [], S) {
473
+ const G = o.map(String).join(".");
474
+ h.get(G);
475
+ const M = function() {
476
+ return n().getNestedState(t, o);
477
477
  };
478
- Object.keys(p).forEach((m) => {
479
- j[m] = p[m];
478
+ Object.keys(I).forEach((m) => {
479
+ M[m] = I[m];
480
480
  });
481
- const F = {
481
+ const j = {
482
482
  apply(m, l, nt) {
483
483
  return console.log(
484
484
  `PROXY APPLY TRAP HIT: stateKey=${t}, path=${o.join(".")}`
485
- ), console.trace("Apply trap stack trace"), r().getNestedState(t, o);
485
+ ), console.trace("Apply trap stack trace"), n().getNestedState(t, o);
486
486
  },
487
487
  get(m, l) {
488
- S?.validIndices && !Array.isArray(h) && (S = { ...S, validIndices: void 0 });
488
+ S?.validIndices && !Array.isArray(y) && (S = { ...S, validIndices: void 0 });
489
489
  const nt = /* @__PURE__ */ new Set([
490
490
  "insert",
491
491
  "cut",
@@ -510,40 +510,40 @@ function it(t, s, y, g) {
510
510
  "getComponents"
511
511
  ]);
512
512
  if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !nt.has(l)) {
513
- const d = `${t}////${y}`, e = r.getState().stateComponents.get(t);
513
+ const d = `${t}////${v}`, e = n.getState().stateComponents.get(t);
514
514
  if (e) {
515
- const n = e.components.get(d);
516
- if (n && !n.paths.has("")) {
515
+ const r = e.components.get(d);
516
+ if (r && !r.paths.has("")) {
517
517
  const a = o.join(".");
518
518
  let c = !0;
519
- for (const f of n.paths)
519
+ for (const f of r.paths)
520
520
  if (a.startsWith(f) && (a === f || a[f.length] === ".")) {
521
521
  c = !1;
522
522
  break;
523
523
  }
524
- c && n.paths.add(a);
524
+ c && r.paths.add(a);
525
525
  }
526
526
  }
527
527
  }
528
528
  if (l === "getDifferences")
529
529
  return () => St(
530
- r.getState().cogsStateStore[t],
531
- r.getState().initialStateGlobal[t]
530
+ n.getState().cogsStateStore[t],
531
+ n.getState().initialStateGlobal[t]
532
532
  );
533
533
  if (l === "sync" && o.length === 0)
534
534
  return async function() {
535
- const d = r.getState().getInitialOptions(t), e = d?.sync;
535
+ const d = n.getState().getInitialOptions(t), e = d?.sync;
536
536
  if (!e)
537
537
  return console.error(`No mutation defined for state key "${t}"`), { success: !1, error: "No mutation defined" };
538
- const n = r.getState().getNestedState(t, []), a = d?.validation?.key;
538
+ const r = n.getState().getNestedState(t, []), a = d?.validation?.key;
539
539
  try {
540
- const c = await e.action(n);
540
+ const c = await e.action(r);
541
541
  if (c && !c.success && c.errors && a) {
542
- r.getState().removeValidationError(a), c.errors.forEach((u) => {
543
- const T = [a, ...u.path].join(".");
544
- r.getState().addValidationError(T, u.message);
542
+ n.getState().removeValidationError(a), c.errors.forEach((u) => {
543
+ const k = [a, ...u.path].join(".");
544
+ n.getState().addValidationError(k, u.message);
545
545
  });
546
- const f = r.getState().stateComponents.get(t);
546
+ const f = n.getState().stateComponents.get(t);
547
547
  f && f.components.forEach((u) => {
548
548
  u.forceUpdate();
549
549
  });
@@ -554,139 +554,160 @@ function it(t, s, y, g) {
554
554
  }
555
555
  };
556
556
  if (l === "_status") {
557
- const d = r.getState().getNestedState(t, o), e = r.getState().initialStateGlobal[t], n = H(e, o);
558
- return L(d, n) ? "fresh" : "stale";
557
+ const d = n.getState().getNestedState(t, o), e = n.getState().initialStateGlobal[t], r = B(e, o);
558
+ return H(d, r) ? "fresh" : "stale";
559
559
  }
560
560
  if (l === "getStatus")
561
561
  return function() {
562
- const d = r().getNestedState(
562
+ const d = n().getNestedState(
563
563
  t,
564
564
  o
565
- ), e = r.getState().initialStateGlobal[t], n = H(e, o);
566
- return L(d, n) ? "fresh" : "stale";
565
+ ), e = n.getState().initialStateGlobal[t], r = B(e, o);
566
+ return H(d, r) ? "fresh" : "stale";
567
567
  };
568
568
  if (l === "removeStorage")
569
569
  return () => {
570
- const d = r.getState().initialStateGlobal[t], e = X(t), n = z(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, a = `${g}-${t}-${n}`;
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}`;
571
571
  a && localStorage.removeItem(a);
572
572
  };
573
573
  if (l === "showValidationErrors")
574
574
  return () => {
575
- const d = r.getState().getInitialOptions(t)?.validation;
575
+ const d = n.getState().getInitialOptions(t)?.validation;
576
576
  if (!d?.key)
577
577
  throw new Error("Validation key not found");
578
- return r.getState().getValidationErrors(d.key + "." + o.join("."));
578
+ return n.getState().getValidationErrors(d.key + "." + o.join("."));
579
579
  };
580
- if (Array.isArray(h)) {
581
- const d = () => S?.validIndices ? h.map((n, a) => ({
582
- item: n,
580
+ if (Array.isArray(y)) {
581
+ const d = () => S?.validIndices ? y.map((r, a) => ({
582
+ item: r,
583
583
  originalIndex: S.validIndices[a]
584
- })) : r.getState().getNestedState(t, o).map((n, a) => ({
585
- item: n,
584
+ })) : n.getState().getNestedState(t, o).map((r, a) => ({
585
+ item: r,
586
586
  originalIndex: a
587
587
  }));
588
588
  if (l === "getSelected")
589
589
  return () => {
590
- const e = r.getState().getSelectedIndex(t, o.join("."));
590
+ const e = n.getState().getSelectedIndex(t, o.join("."));
591
591
  if (e !== void 0)
592
592
  return i(
593
- h[e],
593
+ y[e],
594
594
  [...o, e.toString()],
595
595
  S
596
596
  );
597
597
  };
598
598
  if (l === "clearSelected")
599
599
  return () => {
600
- r.getState().clearSelectedIndex({ stateKey: t, path: o });
600
+ n.getState().clearSelectedIndex({ stateKey: t, path: o });
601
601
  };
602
602
  if (l === "getSelectedIndex")
603
- return () => r.getState().getSelectedIndex(t, o.join(".")) ?? -1;
603
+ return () => n.getState().getSelectedIndex(t, o.join(".")) ?? -1;
604
604
  if (l === "useVirtualView")
605
605
  return (e) => {
606
606
  const {
607
- itemHeight: n,
607
+ itemHeight: r,
608
608
  overscan: a = 5,
609
609
  stickToBottom: c = !1
610
610
  } = e;
611
- if (typeof n != "number" || n <= 0)
611
+ if (typeof r != "number" || r <= 0)
612
612
  throw new Error(
613
613
  "[cogs-state] `useVirtualView` requires a positive number for `itemHeight` option."
614
614
  );
615
- const f = Z(null), u = Z(!0), [T, w] = et({
615
+ const f = Y(null), u = Y(!0), [k, p] = X({
616
616
  startIndex: 0,
617
617
  endIndex: 10
618
- // Start with some visible items
619
- }), $ = r().getNestedState(
618
+ }), w = Y(
619
+ `${t}-virtual-${o.join(".")}-${Math.random()}`
620
+ ).current, [, N] = X({}), A = n().getNestedState(
620
621
  t,
621
622
  o
622
- ), A = $.length, V = A * n, O = Tt(() => {
623
- const b = $.slice(
624
- T.startIndex,
625
- T.endIndex
626
- ), I = {
627
- validIndices: Array.from(
628
- { length: T.endIndex - T.startIndex },
629
- (C, N) => T.startIndex + N
623
+ ), C = A.length, W = C * r;
624
+ at(() => {
625
+ const $ = A.slice(
626
+ k.startIndex,
627
+ k.endIndex
628
+ );
629
+ n.getState().setState(w, $), n.getState().updaterState[w] || n.getState().setUpdaterState(
630
+ w,
631
+ et(
632
+ w,
633
+ s,
634
+ v,
635
+ g
630
636
  )
637
+ );
638
+ const b = `${t}////${v}-virtual`, F = n.getState().stateComponents.get(t) || {
639
+ components: /* @__PURE__ */ new Map()
631
640
  };
632
- return i(
633
- b,
634
- o,
635
- I
641
+ return F.components.set(b, {
642
+ forceUpdate: () => N({}),
643
+ paths: /* @__PURE__ */ new Set([o.join(".")]),
644
+ reactiveType: ["component"]
645
+ }), n.getState().stateComponents.set(t, F), () => {
646
+ const P = n.getState().stateComponents.get(t);
647
+ P && P.components.delete(b);
648
+ const R = n.getState();
649
+ delete R.cogsStateStore[w], delete R.updaterState[w], R.stateComponents.delete(w);
650
+ };
651
+ }, []), st(() => {
652
+ const $ = A.slice(
653
+ k.startIndex,
654
+ k.endIndex
636
655
  );
637
- }, [T.startIndex, T.endIndex, A]);
638
- ot(() => {
639
- const b = f.current;
640
- if (!b) return;
641
- const I = () => {
642
- const P = b.scrollTop, U = b.clientHeight, Y = Math.max(
656
+ n.getState().setState(w, $);
657
+ }, [
658
+ k.startIndex,
659
+ k.endIndex,
660
+ w,
661
+ A.length
662
+ ]), at(() => {
663
+ const $ = f.current;
664
+ if (!$) return;
665
+ const b = () => {
666
+ const R = $.scrollTop, rt = $.clientHeight, ht = Math.max(
643
667
  0,
644
- Math.floor(P / n) - a
645
- ), K = Math.min(
646
- A,
647
- Math.ceil((P + U) / n) + a
668
+ Math.floor(R / r) - a
669
+ ), yt = Math.min(
670
+ C,
671
+ Math.ceil((R + rt) / r) + a
648
672
  );
649
- w((dt) => dt.startIndex === Y && dt.endIndex === K ? dt : { startIndex: Y, endIndex: K });
650
- }, C = () => {
651
- const P = f.current;
652
- P && (u.current = P.scrollHeight > 0 && Math.abs(
653
- P.scrollHeight - P.scrollTop - P.clientHeight
654
- ) < 1, I());
673
+ p((ut) => ut.startIndex === ht && ut.endIndex === yt ? ut : { startIndex: ht, endIndex: yt });
674
+ }, F = () => {
675
+ const R = f.current;
676
+ R && (u.current = R.scrollHeight > 0 && Math.abs(
677
+ R.scrollHeight - R.scrollTop - R.clientHeight
678
+ ) < 1, b());
655
679
  };
656
- I(), b.addEventListener("scroll", C, {
680
+ b(), $.addEventListener("scroll", F, {
657
681
  passive: !0
658
682
  });
659
- const N = new ResizeObserver(() => {
660
- I();
661
- });
662
- return N.observe(b), () => {
663
- b.removeEventListener("scroll", C), N.disconnect();
683
+ const P = new ResizeObserver(b);
684
+ return P.observe($), c && u.current && $.scrollTo({
685
+ top: $.scrollHeight,
686
+ behavior: "auto"
687
+ }), () => {
688
+ $.removeEventListener("scroll", F), P.disconnect();
664
689
  };
665
- }, [A, n, a]);
666
- const D = ut(
667
- (b, I = "auto") => {
668
- f.current?.scrollTo({ top: b, behavior: I });
690
+ }, [C, r, a, c]);
691
+ const U = n.getState().updaterState[w], x = gt(
692
+ ($, b = "auto") => {
693
+ f.current?.scrollTo({ top: $, behavior: b });
669
694
  },
670
695
  []
671
- ), M = ut(
672
- (b = "smooth") => {
673
- const I = f.current;
674
- I && I.scrollTo({
675
- top: I.scrollHeight,
676
- behavior: b
696
+ ), O = gt(
697
+ ($ = "smooth") => {
698
+ const b = f.current;
699
+ b && b.scrollTo({
700
+ top: b.scrollHeight,
701
+ behavior: $
677
702
  });
678
703
  },
679
704
  []
680
- ), k = ut(
681
- (b, I = "smooth") => {
682
- D(b * n, I);
705
+ ), D = gt(
706
+ ($, b = "smooth") => {
707
+ x($ * r, b);
683
708
  },
684
- [D, n]
685
- );
686
- ot(() => {
687
- c && u.current && M("auto");
688
- }, [A, c, M]);
689
- const R = {
709
+ [x, r]
710
+ ), T = {
690
711
  outer: {
691
712
  ref: f,
692
713
  style: {
@@ -698,7 +719,7 @@ function it(t, s, y, g) {
698
719
  inner: {
699
720
  style: {
700
721
  position: "relative",
701
- height: `${V}px`,
722
+ height: `${W}px`,
702
723
  width: "100%"
703
724
  }
704
725
  },
@@ -708,21 +729,21 @@ function it(t, s, y, g) {
708
729
  top: 0,
709
730
  left: 0,
710
731
  right: 0,
711
- transform: `translateY(${T.startIndex * n}px)`
732
+ transform: `translateY(${k.startIndex * r}px)`
712
733
  }
713
734
  }
714
735
  };
715
736
  return {
716
- virtualState: O,
717
- virtualizerProps: R,
718
- scrollToBottom: M,
719
- scrollToIndex: k
737
+ virtualState: U,
738
+ virtualizerProps: T,
739
+ scrollToBottom: O,
740
+ scrollToIndex: D
720
741
  };
721
742
  };
722
743
  if (l === "stateSort")
723
744
  return (e) => {
724
745
  const a = [...d()].sort(
725
- (u, T) => e(u.item, T.item)
746
+ (u, k) => e(u.item, k.item)
726
747
  ), c = a.map(({ item: u }) => u), f = {
727
748
  ...S,
728
749
  validIndices: a.map(
@@ -734,7 +755,7 @@ function it(t, s, y, g) {
734
755
  if (l === "stateFilter")
735
756
  return (e) => {
736
757
  const a = d().filter(
737
- ({ item: u }, T) => e(u, T)
758
+ ({ item: u }, k) => e(u, k)
738
759
  ), c = a.map(({ item: u }) => u), f = {
739
760
  ...S,
740
761
  validIndices: a.map(
@@ -745,51 +766,51 @@ function it(t, s, y, g) {
745
766
  };
746
767
  if (l === "stateMap")
747
768
  return (e) => {
748
- const n = r.getState().getNestedState(t, o);
749
- return Array.isArray(n) ? n.map((a, c) => {
769
+ const r = n.getState().getNestedState(t, o);
770
+ return Array.isArray(r) ? r.map((a, c) => {
750
771
  let f;
751
772
  S?.validIndices && S.validIndices[c] !== void 0 ? f = S.validIndices[c] : f = c;
752
- const u = [...o, f.toString()], T = i(a, u, S);
753
- return e(a, T, {
773
+ const u = [...o, f.toString()], k = i(a, u, S);
774
+ return e(a, k, {
754
775
  register: () => {
755
- const [, $] = et({}), A = `${y}-${o.join(".")}-${f}`;
756
- ot(() => {
757
- const V = `${t}////${A}`, O = r.getState().stateComponents.get(t) || {
776
+ const [, w] = X({}), N = `${v}-${o.join(".")}-${f}`;
777
+ at(() => {
778
+ const A = `${t}////${N}`, C = n.getState().stateComponents.get(t) || {
758
779
  components: /* @__PURE__ */ new Map()
759
780
  };
760
- return O.components.set(V, {
761
- forceUpdate: () => $({}),
781
+ return C.components.set(A, {
782
+ forceUpdate: () => w({}),
762
783
  paths: /* @__PURE__ */ new Set([u.join(".")])
763
784
  // ATOMIC: Subscribes only to this item's path.
764
- }), r.getState().stateComponents.set(t, O), () => {
765
- const D = r.getState().stateComponents.get(t);
766
- D && D.components.delete(V);
785
+ }), n.getState().stateComponents.set(t, C), () => {
786
+ const W = n.getState().stateComponents.get(t);
787
+ W && W.components.delete(A);
767
788
  };
768
- }, [t, A]);
789
+ }, [t, N]);
769
790
  },
770
791
  index: c,
771
792
  originalIndex: f
772
793
  });
773
794
  }) : (console.warn(
774
795
  `stateMap called on a non-array value at path: ${o.join(".")}. The current value is:`,
775
- n
796
+ r
776
797
  ), null);
777
798
  };
778
799
  if (l === "stateMapNoRender")
779
- return (e) => h.map((a, c) => {
800
+ return (e) => y.map((a, c) => {
780
801
  let f;
781
802
  S?.validIndices && S.validIndices[c] !== void 0 ? f = S.validIndices[c] : f = c;
782
- const u = [...o, f.toString()], T = i(a, u, S);
803
+ const u = [...o, f.toString()], k = i(a, u, S);
783
804
  return e(
784
805
  a,
785
- T,
806
+ k,
786
807
  c,
787
- h,
788
- i(h, o, S)
808
+ y,
809
+ i(y, o, S)
789
810
  );
790
811
  });
791
812
  if (l === "$stateMap")
792
- return (e) => st(Gt, {
813
+ return (e) => ct(Ht, {
793
814
  proxy: {
794
815
  _stateKey: t,
795
816
  _path: o,
@@ -800,9 +821,9 @@ function it(t, s, y, g) {
800
821
  });
801
822
  if (l === "stateFlattenOn")
802
823
  return (e) => {
803
- const n = h;
804
- v.clear(), x++;
805
- const a = n.flatMap(
824
+ const r = y;
825
+ h.clear(), V++;
826
+ const a = r.flatMap(
806
827
  (c) => c[e] ?? []
807
828
  );
808
829
  return i(
@@ -813,60 +834,60 @@ function it(t, s, y, g) {
813
834
  };
814
835
  if (l === "index")
815
836
  return (e) => {
816
- const n = h[e];
817
- return i(n, [...o, e.toString()]);
837
+ const r = y[e];
838
+ return i(r, [...o, e.toString()]);
818
839
  };
819
840
  if (l === "last")
820
841
  return () => {
821
- const e = r.getState().getNestedState(t, o);
842
+ const e = n.getState().getNestedState(t, o);
822
843
  if (e.length === 0) return;
823
- const n = e.length - 1, a = e[n], c = [...o, n.toString()];
844
+ const r = e.length - 1, a = e[r], c = [...o, r.toString()];
824
845
  return i(a, c);
825
846
  };
826
847
  if (l === "insert")
827
- return (e) => (E(o), gt(s, e, o, t), i(
828
- r.getState().getNestedState(t, o),
848
+ return (e) => (E(o), ft(s, e, o, t), i(
849
+ n.getState().getNestedState(t, o),
829
850
  o
830
851
  ));
831
852
  if (l === "uniqueInsert")
832
- return (e, n, a) => {
833
- const c = r.getState().getNestedState(t, o), f = z(e) ? e(c) : e;
853
+ return (e, r, a) => {
854
+ const c = n.getState().getNestedState(t, o), f = J(e) ? e(c) : e;
834
855
  let u = null;
835
- if (!c.some((w) => {
836
- if (n) {
837
- const A = n.every(
838
- (V) => L(w[V], f[V])
856
+ if (!c.some((p) => {
857
+ if (r) {
858
+ const N = r.every(
859
+ (A) => H(p[A], f[A])
839
860
  );
840
- return A && (u = w), A;
861
+ return N && (u = p), N;
841
862
  }
842
- const $ = L(w, f);
843
- return $ && (u = w), $;
863
+ const w = H(p, f);
864
+ return w && (u = p), w;
844
865
  }))
845
- E(o), gt(s, f, o, t);
866
+ E(o), ft(s, f, o, t);
846
867
  else if (a && u) {
847
- const w = a(u), $ = c.map(
848
- (A) => L(A, u) ? w : A
868
+ const p = a(u), w = c.map(
869
+ (N) => H(N, u) ? p : N
849
870
  );
850
- E(o), tt(s, $, o);
871
+ E(o), tt(s, w, o);
851
872
  }
852
873
  };
853
874
  if (l === "cut")
854
- return (e, n) => {
855
- if (!n?.waitForSync)
856
- return E(o), rt(s, o, t, e), i(
857
- r.getState().getNestedState(t, o),
875
+ return (e, r) => {
876
+ if (!r?.waitForSync)
877
+ return E(o), ot(s, o, t, e), i(
878
+ n.getState().getNestedState(t, o),
858
879
  o
859
880
  );
860
881
  };
861
882
  if (l === "cutByValue")
862
883
  return (e) => {
863
- for (let n = 0; n < h.length; n++)
864
- h[n] === e && rt(s, o, t, n);
884
+ for (let r = 0; r < y.length; r++)
885
+ y[r] === e && ot(s, o, t, r);
865
886
  };
866
887
  if (l === "toggleByValue")
867
888
  return (e) => {
868
- const n = h.findIndex((a) => a === e);
869
- n > -1 ? rt(s, o, t, n) : gt(s, e, o, t);
889
+ const r = y.findIndex((a) => a === e);
890
+ r > -1 ? ot(s, o, t, r) : ft(s, e, o, t);
870
891
  };
871
892
  if (l === "stateFind")
872
893
  return (e) => {
@@ -878,187 +899,187 @@ function it(t, s, y, g) {
878
899
  return i(a.item, c, S);
879
900
  };
880
901
  if (l === "findWith")
881
- return (e, n) => {
902
+ return (e, r) => {
882
903
  const c = d().find(
883
- ({ item: u }) => u[e] === n
904
+ ({ item: u }) => u[e] === r
884
905
  );
885
906
  if (!c) return;
886
907
  const f = [...o, c.originalIndex.toString()];
887
908
  return i(c.item, f, S);
888
909
  };
889
910
  }
890
- const B = o[o.length - 1];
891
- if (!isNaN(Number(B))) {
892
- const d = o.slice(0, -1), e = r.getState().getNestedState(t, d);
911
+ const q = o[o.length - 1];
912
+ if (!isNaN(Number(q))) {
913
+ const d = o.slice(0, -1), e = n.getState().getNestedState(t, d);
893
914
  if (Array.isArray(e) && l === "cut")
894
- return () => rt(
915
+ return () => ot(
895
916
  s,
896
917
  d,
897
918
  t,
898
- Number(B)
919
+ Number(q)
899
920
  );
900
921
  }
901
922
  if (l === "get")
902
- return () => r.getState().getNestedState(t, o);
923
+ return () => n.getState().getNestedState(t, o);
903
924
  if (l === "$derive")
904
- return (d) => Et({
925
+ return (d) => Tt({
905
926
  _stateKey: t,
906
927
  _path: o,
907
928
  _effect: d.toString()
908
929
  });
909
930
  if (l === "$get")
910
- return () => Et({
931
+ return () => Tt({
911
932
  _stateKey: t,
912
933
  _path: o
913
934
  });
914
935
  if (l === "lastSynced") {
915
936
  const d = `${t}:${o.join(".")}`;
916
- return r.getState().getSyncInfo(d);
937
+ return n.getState().getSyncInfo(d);
917
938
  }
918
939
  if (l == "getLocalStorage")
919
- return (d) => ct(g + "-" + t + "-" + d);
940
+ return (d) => lt(g + "-" + t + "-" + d);
920
941
  if (l === "_selected") {
921
- const d = o.slice(0, -1), e = d.join("."), n = r.getState().getNestedState(t, d);
922
- return Array.isArray(n) ? Number(o[o.length - 1]) === r.getState().getSelectedIndex(t, e) : void 0;
942
+ const d = o.slice(0, -1), e = d.join("."), r = n.getState().getNestedState(t, d);
943
+ return Array.isArray(r) ? Number(o[o.length - 1]) === n.getState().getSelectedIndex(t, e) : void 0;
923
944
  }
924
945
  if (l === "setSelected")
925
946
  return (d) => {
926
- const e = o.slice(0, -1), n = Number(o[o.length - 1]), a = e.join(".");
927
- d ? r.getState().setSelectedIndex(t, a, n) : r.getState().setSelectedIndex(t, a, void 0);
928
- const c = r.getState().getNestedState(t, [...e]);
947
+ const e = o.slice(0, -1), r = Number(o[o.length - 1]), a = e.join(".");
948
+ d ? n.getState().setSelectedIndex(t, a, r) : n.getState().setSelectedIndex(t, a, void 0);
949
+ const c = n.getState().getNestedState(t, [...e]);
929
950
  tt(s, c, e), E(e);
930
951
  };
931
952
  if (l === "toggleSelected")
932
953
  return () => {
933
- const d = o.slice(0, -1), e = Number(o[o.length - 1]), n = d.join("."), a = r.getState().getSelectedIndex(t, n);
934
- r.getState().setSelectedIndex(
954
+ const d = o.slice(0, -1), e = Number(o[o.length - 1]), r = d.join("."), a = n.getState().getSelectedIndex(t, r);
955
+ n.getState().setSelectedIndex(
935
956
  t,
936
- n,
957
+ r,
937
958
  a === e ? void 0 : e
938
959
  );
939
- const c = r.getState().getNestedState(t, [...d]);
960
+ const c = n.getState().getNestedState(t, [...d]);
940
961
  tt(s, c, d), E(d);
941
962
  };
942
963
  if (o.length == 0) {
943
964
  if (l === "applyJsonPatch")
944
965
  return (d) => {
945
- const e = r.getState().cogsStateStore[t], a = Ot(e, d).newDocument;
966
+ const e = n.getState().cogsStateStore[t], a = jt(e, d).newDocument;
946
967
  xt(
947
968
  t,
948
- r.getState().initialStateGlobal[t],
969
+ n.getState().initialStateGlobal[t],
949
970
  a,
950
971
  s,
951
- y,
972
+ v,
952
973
  g
953
974
  );
954
- const c = r.getState().stateComponents.get(t);
975
+ const c = n.getState().stateComponents.get(t);
955
976
  if (c) {
956
977
  const f = St(e, a), u = new Set(f);
957
978
  for (const [
958
- T,
959
- w
979
+ k,
980
+ p
960
981
  ] of c.components.entries()) {
961
- let $ = !1;
962
- const A = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
963
- if (!A.includes("none")) {
964
- if (A.includes("all")) {
965
- w.forceUpdate();
982
+ let w = !1;
983
+ const N = Array.isArray(p.reactiveType) ? p.reactiveType : [p.reactiveType || "component"];
984
+ if (!N.includes("none")) {
985
+ if (N.includes("all")) {
986
+ p.forceUpdate();
966
987
  continue;
967
988
  }
968
- if (A.includes("component") && (w.paths.has("") && ($ = !0), !$))
969
- for (const V of u) {
970
- if (w.paths.has(V)) {
971
- $ = !0;
989
+ if (N.includes("component") && (p.paths.has("") && (w = !0), !w))
990
+ for (const A of u) {
991
+ if (p.paths.has(A)) {
992
+ w = !0;
972
993
  break;
973
994
  }
974
- let O = V.lastIndexOf(".");
975
- for (; O !== -1; ) {
976
- const D = V.substring(0, O);
977
- if (w.paths.has(D)) {
978
- $ = !0;
995
+ let C = A.lastIndexOf(".");
996
+ for (; C !== -1; ) {
997
+ const W = A.substring(0, C);
998
+ if (p.paths.has(W)) {
999
+ w = !0;
979
1000
  break;
980
1001
  }
981
- const M = V.substring(
982
- O + 1
1002
+ const U = A.substring(
1003
+ C + 1
983
1004
  );
984
- if (!isNaN(Number(M))) {
985
- const k = D.lastIndexOf(".");
986
- if (k !== -1) {
987
- const R = D.substring(
1005
+ if (!isNaN(Number(U))) {
1006
+ const x = W.lastIndexOf(".");
1007
+ if (x !== -1) {
1008
+ const O = W.substring(
988
1009
  0,
989
- k
1010
+ x
990
1011
  );
991
- if (w.paths.has(R)) {
992
- $ = !0;
1012
+ if (p.paths.has(O)) {
1013
+ w = !0;
993
1014
  break;
994
1015
  }
995
1016
  }
996
1017
  }
997
- O = D.lastIndexOf(".");
1018
+ C = W.lastIndexOf(".");
998
1019
  }
999
- if ($) break;
1020
+ if (w) break;
1000
1021
  }
1001
- if (!$ && A.includes("deps") && w.depsFunction) {
1002
- const V = w.depsFunction(a);
1003
- let O = !1;
1004
- typeof V == "boolean" ? V && (O = !0) : L(w.deps, V) || (w.deps = V, O = !0), O && ($ = !0);
1022
+ if (!w && N.includes("deps") && p.depsFunction) {
1023
+ const A = p.depsFunction(a);
1024
+ let C = !1;
1025
+ typeof A == "boolean" ? A && (C = !0) : H(p.deps, A) || (p.deps = A, C = !0), C && (w = !0);
1005
1026
  }
1006
- $ && w.forceUpdate();
1027
+ w && p.forceUpdate();
1007
1028
  }
1008
1029
  }
1009
1030
  }
1010
1031
  };
1011
1032
  if (l === "validateZodSchema")
1012
1033
  return () => {
1013
- const d = r.getState().getInitialOptions(t)?.validation, e = r.getState().addValidationError;
1034
+ const d = n.getState().getInitialOptions(t)?.validation, e = n.getState().addValidationError;
1014
1035
  if (!d?.zodSchema)
1015
1036
  throw new Error("Zod schema not found");
1016
1037
  if (!d?.key)
1017
1038
  throw new Error("Validation key not found");
1018
- q(d.key);
1019
- const n = r.getState().cogsStateStore[t];
1039
+ z(d.key);
1040
+ const r = n.getState().cogsStateStore[t];
1020
1041
  try {
1021
- const a = r.getState().getValidationErrors(d.key);
1042
+ const a = n.getState().getValidationErrors(d.key);
1022
1043
  a && a.length > 0 && a.forEach(([f]) => {
1023
- f && f.startsWith(d.key) && q(f);
1044
+ f && f.startsWith(d.key) && z(f);
1024
1045
  });
1025
- const c = d.zodSchema.safeParse(n);
1046
+ const c = d.zodSchema.safeParse(r);
1026
1047
  return c.success ? !0 : (c.error.errors.forEach((u) => {
1027
- const T = u.path, w = u.message, $ = [d.key, ...T].join(".");
1028
- e($, w);
1029
- }), lt(t), !1);
1048
+ const k = u.path, p = u.message, w = [d.key, ...k].join(".");
1049
+ e(w, p);
1050
+ }), dt(t), !1);
1030
1051
  } catch (a) {
1031
1052
  return console.error("Zod schema validation failed", a), !1;
1032
1053
  }
1033
1054
  };
1034
- if (l === "_componentId") return y;
1055
+ if (l === "_componentId") return v;
1035
1056
  if (l === "getComponents")
1036
- return () => r().stateComponents.get(t);
1057
+ return () => n().stateComponents.get(t);
1037
1058
  if (l === "getAllFormRefs")
1038
- return () => ht.getState().getFormRefsByStateKey(t);
1059
+ return () => pt.getState().getFormRefsByStateKey(t);
1039
1060
  if (l === "_initialState")
1040
- return r.getState().initialStateGlobal[t];
1061
+ return n.getState().initialStateGlobal[t];
1041
1062
  if (l === "_serverState")
1042
- return r.getState().serverState[t];
1063
+ return n.getState().serverState[t];
1043
1064
  if (l === "_isLoading")
1044
- return r.getState().isLoadingGlobal[t];
1065
+ return n.getState().isLoadingGlobal[t];
1045
1066
  if (l === "revertToInitialState")
1046
- return p.revertToInitialState;
1047
- if (l === "updateInitialState") return p.updateInitialState;
1048
- if (l === "removeValidation") return p.removeValidation;
1067
+ return I.revertToInitialState;
1068
+ if (l === "updateInitialState") return I.updateInitialState;
1069
+ if (l === "removeValidation") return I.removeValidation;
1049
1070
  }
1050
1071
  if (l === "getFormRef")
1051
- return () => ht.getState().getFormRef(t + "." + o.join("."));
1072
+ return () => pt.getState().getFormRef(t + "." + o.join("."));
1052
1073
  if (l === "validationWrapper")
1053
1074
  return ({
1054
1075
  children: d,
1055
1076
  hideMessage: e
1056
- }) => /* @__PURE__ */ yt(
1057
- Ct,
1077
+ }) => /* @__PURE__ */ It(
1078
+ _t,
1058
1079
  {
1059
1080
  formOpts: e ? { validation: { message: "" } } : void 0,
1060
1081
  path: o,
1061
- validationKey: r.getState().getInitialOptions(t)?.validation?.key || "",
1082
+ validationKey: n.getState().getInitialOptions(t)?.validation?.key || "",
1062
1083
  stateKey: t,
1063
1084
  validIndices: S?.validIndices,
1064
1085
  children: d
@@ -1066,25 +1087,25 @@ function it(t, s, y, g) {
1066
1087
  );
1067
1088
  if (l === "_stateKey") return t;
1068
1089
  if (l === "_path") return o;
1069
- if (l === "_isServerSynced") return p._isServerSynced;
1090
+ if (l === "_isServerSynced") return I._isServerSynced;
1070
1091
  if (l === "update")
1071
1092
  return (d, e) => {
1072
1093
  if (e?.debounce)
1073
- Nt(() => {
1094
+ Pt(() => {
1074
1095
  tt(s, d, o, "");
1075
- const n = r.getState().getNestedState(t, o);
1076
- e?.afterUpdate && e.afterUpdate(n);
1096
+ const r = n.getState().getNestedState(t, o);
1097
+ e?.afterUpdate && e.afterUpdate(r);
1077
1098
  }, e.debounce);
1078
1099
  else {
1079
1100
  tt(s, d, o, "");
1080
- const n = r.getState().getNestedState(t, o);
1081
- e?.afterUpdate && e.afterUpdate(n);
1101
+ const r = n.getState().getNestedState(t, o);
1102
+ e?.afterUpdate && e.afterUpdate(r);
1082
1103
  }
1083
1104
  E(o);
1084
1105
  };
1085
1106
  if (l === "formElement")
1086
- return (d, e) => /* @__PURE__ */ yt(
1087
- Pt,
1107
+ return (d, e) => /* @__PURE__ */ It(
1108
+ Ot,
1088
1109
  {
1089
1110
  setState: s,
1090
1111
  stateKey: t,
@@ -1093,52 +1114,52 @@ function it(t, s, y, g) {
1093
1114
  formOpts: e
1094
1115
  }
1095
1116
  );
1096
- const _ = [...o, l], Q = r.getState().getNestedState(t, _);
1097
- return i(Q, _, S);
1117
+ const _ = [...o, l], K = n.getState().getNestedState(t, _);
1118
+ return i(K, _, S);
1098
1119
  }
1099
- }, G = new Proxy(j, F);
1100
- return v.set(W, {
1101
- proxy: G,
1102
- stateVersion: x
1103
- }), G;
1120
+ }, L = new Proxy(M, j);
1121
+ return h.set(G, {
1122
+ proxy: L,
1123
+ stateVersion: V
1124
+ }), L;
1104
1125
  }
1105
1126
  return i(
1106
- r.getState().getNestedState(t, [])
1127
+ n.getState().getNestedState(t, [])
1107
1128
  );
1108
1129
  }
1109
- function Et(t) {
1110
- return st(Lt, { proxy: t });
1130
+ function Tt(t) {
1131
+ return ct(Bt, { proxy: t });
1111
1132
  }
1112
- function Gt({
1133
+ function Ht({
1113
1134
  proxy: t,
1114
1135
  rebuildStateShape: s
1115
1136
  }) {
1116
- const y = r().getNestedState(t._stateKey, t._path);
1117
- return Array.isArray(y) ? s(
1118
- y,
1137
+ const v = n().getNestedState(t._stateKey, t._path);
1138
+ return Array.isArray(v) ? s(
1139
+ v,
1119
1140
  t._path
1120
1141
  ).stateMapNoRender(
1121
- (v, x, E, p, i) => t._mapFn(v, x, E, p, i)
1142
+ (h, V, E, I, i) => t._mapFn(h, V, E, I, i)
1122
1143
  ) : null;
1123
1144
  }
1124
- function Lt({
1145
+ function Bt({
1125
1146
  proxy: t
1126
1147
  }) {
1127
- const s = Z(null), y = `${t._stateKey}-${t._path.join(".")}`;
1128
- return ft(() => {
1148
+ const s = Y(null), v = `${t._stateKey}-${t._path.join(".")}`;
1149
+ return st(() => {
1129
1150
  const g = s.current;
1130
1151
  if (!g || !g.parentElement) return;
1131
- const v = g.parentElement, E = Array.from(v.childNodes).indexOf(g);
1132
- let p = v.getAttribute("data-parent-id");
1133
- p || (p = `parent-${crypto.randomUUID()}`, v.setAttribute("data-parent-id", p));
1134
- const h = {
1152
+ const h = g.parentElement, E = Array.from(h.childNodes).indexOf(g);
1153
+ let I = h.getAttribute("data-parent-id");
1154
+ I || (I = `parent-${crypto.randomUUID()}`, h.setAttribute("data-parent-id", I));
1155
+ const y = {
1135
1156
  instanceId: `instance-${crypto.randomUUID()}`,
1136
- parentId: p,
1157
+ parentId: I,
1137
1158
  position: E,
1138
1159
  effect: t._effect
1139
1160
  };
1140
- r.getState().addSignalElement(y, h);
1141
- const o = r.getState().getNestedState(t._stateKey, t._path);
1161
+ n.getState().addSignalElement(v, y);
1162
+ const o = n.getState().getNestedState(t._stateKey, t._path);
1142
1163
  let S;
1143
1164
  if (t._effect)
1144
1165
  try {
@@ -1146,41 +1167,41 @@ function Lt({
1146
1167
  "state",
1147
1168
  `return (${t._effect})(state)`
1148
1169
  )(o);
1149
- } catch (j) {
1150
- console.error("Error evaluating effect function during mount:", j), S = o;
1170
+ } catch (M) {
1171
+ console.error("Error evaluating effect function during mount:", M), S = o;
1151
1172
  }
1152
1173
  else
1153
1174
  S = o;
1154
1175
  S !== null && typeof S == "object" && (S = JSON.stringify(S));
1155
- const W = document.createTextNode(String(S));
1156
- g.replaceWith(W);
1157
- }, [t._stateKey, t._path.join("."), t._effect]), st("span", {
1176
+ const G = document.createTextNode(String(S));
1177
+ g.replaceWith(G);
1178
+ }, [t._stateKey, t._path.join("."), t._effect]), ct("span", {
1158
1179
  ref: s,
1159
1180
  style: { display: "none" },
1160
- "data-signal-id": y
1181
+ "data-signal-id": v
1161
1182
  });
1162
1183
  }
1163
- function re(t) {
1164
- const s = kt(
1165
- (y) => {
1166
- const g = r.getState().stateComponents.get(t._stateKey) || {
1184
+ function ae(t) {
1185
+ const s = At(
1186
+ (v) => {
1187
+ const g = n.getState().stateComponents.get(t._stateKey) || {
1167
1188
  components: /* @__PURE__ */ new Map()
1168
1189
  };
1169
1190
  return g.components.set(t._stateKey, {
1170
- forceUpdate: y,
1191
+ forceUpdate: v,
1171
1192
  paths: /* @__PURE__ */ new Set([t._path.join(".")])
1172
1193
  }), () => g.components.delete(t._stateKey);
1173
1194
  },
1174
- () => r.getState().getNestedState(t._stateKey, t._path)
1195
+ () => n.getState().getNestedState(t._stateKey, t._path)
1175
1196
  );
1176
- return st("text", {}, String(s));
1197
+ return ct("text", {}, String(s));
1177
1198
  }
1178
1199
  export {
1179
- Et as $cogsSignal,
1180
- re as $cogsSignalStore,
1181
- te as addStateOptions,
1182
- ee as createCogsState,
1183
- ne as notifyComponent,
1184
- Wt as useCogsStateFn
1200
+ Tt as $cogsSignal,
1201
+ ae as $cogsSignalStore,
1202
+ ne as addStateOptions,
1203
+ re as createCogsState,
1204
+ oe as notifyComponent,
1205
+ Lt as useCogsStateFn
1185
1206
  };
1186
1207
  //# sourceMappingURL=CogsState.jsx.map