cogsbox-state 0.5.278 → 0.5.280

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