cogsbox-state 0.5.362 → 0.5.365

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