cogsbox-state 0.5.260 → 0.5.262

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