cogsbox-state 0.5.250 → 0.5.251

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