cogsbox-state 0.5.249 → 0.5.250

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