cogsbox-state 0.5.411 → 0.5.412

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