cogsbox-state 0.5.269 → 0.5.270

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