cogsbox-state 0.5.434 → 0.5.435

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,393 +1,443 @@
1
1
  "use client";
2
- import { jsx as ae, Fragment as ke } from "react/jsx-runtime";
3
- import { memo as Re, useState as Z, useRef as q, useCallback as ce, useEffect as Y, useLayoutEffect as ue, useMemo as de, createElement as le, startTransition as je } from "react";
2
+ import { jsx as re, Fragment as ke } from "react/jsx-runtime";
3
+ import { memo as Re, useState as X, useRef as G, useCallback as ce, useEffect as Q, useLayoutEffect as de, useMemo as ge, createElement as le, startTransition as je } from "react";
4
4
  import { createRoot as Ce } from "react-dom/client";
5
- import { transformStateFunc as Fe, isFunction as K, isArray as Te, getDifferences as Ae, isDeepEqual as ie } from "./utility.js";
6
- import { ValidationWrapper as Me } from "./Functions.jsx";
7
- import De from "superjson";
8
- import { v4 as ee } from "uuid";
9
- import "zod";
10
- import { getGlobalStore as t, formRefStore as ye } from "./store.js";
11
- import { useCogsConfig as $e } from "./CogsStateClient.jsx";
12
- import { applyPatch as Le } from "fast-json-patch";
13
- import { useInView as Oe } from "react-intersection-observer";
14
- function me(e, s) {
15
- const p = t.getState().getInitialOptions, g = t.getState().setInitialStateOptions, v = p(e) || {};
5
+ import { transformStateFunc as Fe, isFunction as ee, isArray as Te, getDifferences as Pe, isDeepEqual as se } from "./utility.js";
6
+ import { ValidationWrapper as be } from "./Functions.jsx";
7
+ import Oe from "superjson";
8
+ import { v4 as te } from "uuid";
9
+ import { getGlobalStore as t, formRefStore as pe } from "./store.js";
10
+ import { useCogsConfig as _e } from "./CogsStateClient.jsx";
11
+ import { useInView as Le } from "react-intersection-observer";
12
+ function he(e, i) {
13
+ const f = t.getState().getInitialOptions, g = t.getState().setInitialStateOptions, h = f(e) || {};
16
14
  g(e, {
17
- ...v,
18
- ...s
15
+ ...h,
16
+ ...i
19
17
  });
20
18
  }
21
- function Ve({
19
+ function Ee({
22
20
  stateKey: e,
23
- options: s,
24
- initialOptionsPart: p
21
+ options: i,
22
+ initialOptionsPart: f
25
23
  }) {
26
- const g = te(e) || {}, v = p[e] || {}, h = t.getState().setInitialStateOptions, V = { ...v, ...g };
27
- let u = !1;
28
- if (s)
29
- for (const l in s)
30
- V.hasOwnProperty(l) ? (l == "localStorage" && s[l] && V[l].key !== s[l]?.key && (u = !0, V[l] = s[l]), l == "defaultState" && s[l] && V[l] !== s[l] && !ie(V[l], s[l]) && (u = !0, V[l] = s[l])) : (u = !0, V[l] = s[l]);
31
- u && h(e, V);
24
+ const g = ae(e) || {}, h = f[e] || {}, p = t.getState().setInitialStateOptions, M = { ...h, ...g };
25
+ let l = !1;
26
+ if (i)
27
+ for (const u in i)
28
+ M.hasOwnProperty(u) ? (u == "localStorage" && i[u] && M[u].key !== i[u]?.key && (l = !0, M[u] = i[u]), u == "defaultState" && i[u] && M[u] !== i[u] && !se(M[u], i[u]) && (l = !0, M[u] = i[u])) : (l = !0, M[u] = i[u]);
29
+ l && p(e, M);
32
30
  }
33
- function lt(e, { formElements: s, validation: p }) {
34
- return { initialState: e, formElements: s, validation: p };
31
+ function it(e, { formElements: i, validation: f }) {
32
+ return { initialState: e, formElements: i, validation: f };
35
33
  }
36
- const ut = (e, s) => {
37
- let p = e;
38
- const [g, v] = Fe(p);
39
- Object.keys(g).forEach((u) => {
40
- let l = v[u] || {};
41
- const E = {
42
- ...l
34
+ const ct = (e, i) => {
35
+ let f = e;
36
+ const [g, h] = Fe(f);
37
+ Object.keys(g).forEach((l) => {
38
+ let u = h[l] || {};
39
+ const A = {
40
+ ...u
43
41
  };
44
- if (s?.formElements && (E.formElements = {
45
- ...s.formElements,
46
- ...l.formElements || {}
47
- }), s?.validation && (E.validation = {
48
- ...s.validation,
49
- ...l.validation || {}
50
- }, s.validation.key && !l.validation?.key && (E.validation.key = `${s.validation.key}.${u}`)), Object.keys(E).length > 0) {
51
- const T = te(u);
52
- T ? t.getState().setInitialStateOptions(u, {
53
- ...T,
54
- ...E
55
- }) : t.getState().setInitialStateOptions(u, E);
42
+ if (i?.formElements && (A.formElements = {
43
+ ...i.formElements,
44
+ ...u.formElements || {}
45
+ }), i?.validation && (A.validation = {
46
+ ...i.validation,
47
+ ...u.validation || {}
48
+ }, i.validation.key && !u.validation?.key && (A.validation.key = `${i.validation.key}.${l}`)), Object.keys(A).length > 0) {
49
+ const b = ae(l);
50
+ b ? t.getState().setInitialStateOptions(l, {
51
+ ...b,
52
+ ...A
53
+ }) : t.getState().setInitialStateOptions(l, A);
56
54
  }
57
- }), Object.keys(g).forEach((u) => {
58
- t.getState().initializeShadowState(u, g[u]);
55
+ }), Object.keys(g).forEach((l) => {
56
+ t.getState().initializeShadowState(l, g[l]);
59
57
  });
60
- const h = (u, l) => {
61
- const [E] = Z(l?.componentId ?? ee());
62
- Ve({
63
- stateKey: u,
64
- options: l,
65
- initialOptionsPart: v
58
+ const p = (l, u) => {
59
+ const [A] = X(u?.componentId ?? te());
60
+ Ee({
61
+ stateKey: l,
62
+ options: u,
63
+ initialOptionsPart: h
66
64
  });
67
- const T = t.getState().getShadowValue(u) || g[u], o = l?.modifyState ? l.modifyState(T) : T;
65
+ const b = t.getState().getShadowValue(l) || g[l], o = u?.modifyState ? u.modifyState(b) : b;
68
66
  return Be(o, {
69
- stateKey: u,
70
- syncUpdate: l?.syncUpdate,
71
- componentId: E,
72
- localStorage: l?.localStorage,
73
- middleware: l?.middleware,
74
- reactiveType: l?.reactiveType,
75
- reactiveDeps: l?.reactiveDeps,
76
- defaultState: l?.defaultState,
77
- dependencies: l?.dependencies,
78
- serverState: l?.serverState
67
+ stateKey: l,
68
+ syncUpdate: u?.syncUpdate,
69
+ componentId: A,
70
+ localStorage: u?.localStorage,
71
+ middleware: u?.middleware,
72
+ reactiveType: u?.reactiveType,
73
+ reactiveDeps: u?.reactiveDeps,
74
+ defaultState: u?.defaultState,
75
+ dependencies: u?.dependencies,
76
+ serverState: u?.serverState
79
77
  });
80
78
  };
81
- function V(u, l) {
82
- Ve({ stateKey: u, options: l, initialOptionsPart: v }), l.localStorage && xe(u, l), re(u);
79
+ function M(l, u) {
80
+ Ee({ stateKey: l, options: u, initialOptionsPart: h }), u.localStorage && xe(l, u), ie(l);
83
81
  }
84
- return { useCogsState: h, setCogsOptions: V };
82
+ return { useCogsState: p, setCogsOptions: M };
85
83
  }, {
86
- getInitialOptions: te,
84
+ getInitialOptions: ae,
87
85
  getValidationErrors: Ne,
88
86
  setStateLog: We,
89
- updateInitialStateGlobal: _e,
90
- addValidationError: pe,
87
+ updateInitialStateGlobal: $e,
88
+ addValidationError: ve,
91
89
  removeValidationError: ne
92
- } = t.getState(), He = (e, s, p, g, v) => {
93
- p?.log && console.log(
90
+ } = t.getState(), He = (e, i, f, g, h) => {
91
+ f?.log && console.log(
94
92
  "saving to localstorage",
95
- s,
96
- p.localStorage?.key,
93
+ i,
94
+ f.localStorage?.key,
97
95
  g
98
96
  );
99
- const h = K(p?.localStorage?.key) ? p.localStorage?.key(e) : p?.localStorage?.key;
100
- if (h && g) {
101
- const V = `${g}-${s}-${h}`;
102
- let u;
97
+ const p = ee(f?.localStorage?.key) ? f.localStorage?.key(e) : f?.localStorage?.key;
98
+ if (p && g) {
99
+ const M = `${g}-${i}-${p}`;
100
+ let l;
103
101
  try {
104
- u = fe(V)?.lastSyncedWithServer;
102
+ l = Se(M)?.lastSyncedWithServer;
105
103
  } catch {
106
104
  }
107
- const l = t.getState().getShadowMetadata(s, []), E = {
105
+ const u = t.getState().getShadowMetadata(i, []), A = {
108
106
  state: e,
109
107
  lastUpdated: Date.now(),
110
- lastSyncedWithServer: u,
111
- stateSource: l?.stateSource,
112
- baseServerState: l?.baseServerState
113
- }, T = De.serialize(E);
108
+ lastSyncedWithServer: l,
109
+ stateSource: u?.stateSource,
110
+ baseServerState: u?.baseServerState
111
+ }, b = Oe.serialize(A);
114
112
  window.localStorage.setItem(
115
- V,
116
- JSON.stringify(T.json)
113
+ M,
114
+ JSON.stringify(b.json)
117
115
  );
118
116
  }
119
- }, fe = (e) => {
117
+ }, Se = (e) => {
120
118
  if (!e) return null;
121
119
  try {
122
- const s = window.localStorage.getItem(e);
123
- return s ? JSON.parse(s) : null;
124
- } catch (s) {
125
- return console.error("Error loading from localStorage:", s), null;
120
+ const i = window.localStorage.getItem(e);
121
+ return i ? JSON.parse(i) : null;
122
+ } catch (i) {
123
+ return console.error("Error loading from localStorage:", i), null;
126
124
  }
127
- }, xe = (e, s) => {
128
- const p = t.getState().getShadowValue(e), { sessionId: g } = $e(), v = K(s?.localStorage?.key) ? s.localStorage.key(p) : s?.localStorage?.key;
129
- if (v && g) {
130
- const h = fe(
131
- `${g}-${e}-${v}`
125
+ }, xe = (e, i) => {
126
+ const f = t.getState().getShadowValue(e), { sessionId: g } = _e(), h = ee(i?.localStorage?.key) ? i.localStorage.key(f) : i?.localStorage?.key;
127
+ if (h && g) {
128
+ const p = Se(
129
+ `${g}-${e}-${h}`
132
130
  );
133
- if (h && h.lastUpdated > (h.lastSyncedWithServer || 0))
134
- return re(e), !0;
131
+ if (p && p.lastUpdated > (p.lastSyncedWithServer || 0))
132
+ return ie(e), !0;
135
133
  }
136
134
  return !1;
137
- }, re = (e) => {
138
- const s = t.getState().getShadowMetadata(e, []);
139
- if (!s) return;
140
- const p = /* @__PURE__ */ new Set();
141
- s?.components?.forEach((g) => {
142
- (g ? Array.isArray(g.reactiveType) ? g.reactiveType : [g.reactiveType || "component"] : null)?.includes("none") || p.add(() => g.forceUpdate());
135
+ }, ie = (e) => {
136
+ const i = t.getState().getShadowMetadata(e, []);
137
+ if (!i) return;
138
+ const f = /* @__PURE__ */ new Set();
139
+ i?.components?.forEach((g) => {
140
+ (g ? Array.isArray(g.reactiveType) ? g.reactiveType : [g.reactiveType || "component"] : null)?.includes("none") || f.add(() => g.forceUpdate());
143
141
  }), queueMicrotask(() => {
144
- p.forEach((g) => g());
142
+ f.forEach((g) => g());
145
143
  });
146
- }, dt = (e, s) => {
147
- const p = t.getState().getShadowMetadata(e, []);
148
- if (p) {
149
- const g = `${e}////${s}`, v = p?.components?.get(g);
150
- if ((v ? Array.isArray(v.reactiveType) ? v.reactiveType : [v.reactiveType || "component"] : null)?.includes("none"))
144
+ }, lt = (e, i) => {
145
+ const f = t.getState().getShadowMetadata(e, []);
146
+ if (f) {
147
+ const g = `${e}////${i}`, h = f?.components?.get(g);
148
+ if ((h ? Array.isArray(h.reactiveType) ? h.reactiveType : [h.reactiveType || "component"] : null)?.includes("none"))
151
149
  return;
152
- v && v.forceUpdate();
150
+ h && h.forceUpdate();
153
151
  }
154
152
  };
153
+ function we(e, i, f, g) {
154
+ const h = t.getState(), p = h.getShadowMetadata(e, i);
155
+ if (h.setShadowMetadata(e, i, {
156
+ ...p,
157
+ isDirty: !1,
158
+ stateSource: "server",
159
+ lastServerSync: g || Date.now()
160
+ }), Array.isArray(f)) {
161
+ const M = h.getShadowMetadata(e, i);
162
+ M?.arrayKeys && M.arrayKeys.forEach((l, u) => {
163
+ const A = l.split(".").slice(1), b = f[u];
164
+ b !== void 0 && we(
165
+ e,
166
+ A,
167
+ b,
168
+ g
169
+ );
170
+ });
171
+ } else f && typeof f == "object" && f.constructor === Object && Object.keys(f).forEach((M) => {
172
+ const l = [...i, M], u = f[M];
173
+ we(e, l, u, g);
174
+ });
175
+ }
155
176
  function Be(e, {
156
- stateKey: s,
157
- serverSync: p,
158
- localStorage: g,
159
- formElements: v,
177
+ stateKey: i,
178
+ localStorage: f,
179
+ formElements: g,
160
180
  reactiveDeps: h,
161
- reactiveType: V,
162
- componentId: u,
181
+ reactiveType: p,
182
+ componentId: M,
163
183
  defaultState: l,
164
- syncUpdate: E,
165
- dependencies: T,
166
- serverState: o
184
+ syncUpdate: u,
185
+ dependencies: A,
186
+ serverState: b
167
187
  } = {}) {
168
- const [S, M] = Z({}), { sessionId: L } = $e();
169
- let N = !s;
170
- const [c] = Z(s ?? ee()), J = t.getState().stateLog[c], G = q(/* @__PURE__ */ new Set()), H = q(u ?? ee()), f = q(
188
+ const [o, S] = X({}), { sessionId: T } = _e();
189
+ let W = !i;
190
+ const [c] = X(i ?? te()), x = t.getState().stateLog[c], Y = G(/* @__PURE__ */ new Set()), J = G(M ?? te()), U = G(
171
191
  null
172
192
  );
173
- f.current = te(c) ?? null, Y(() => {
174
- if (E && E.stateKey === c && E.path?.[0]) {
175
- const a = `${E.stateKey}:${E.path.join(".")}`;
176
- t.getState().setSyncInfo(a, {
177
- timeStamp: E.timeStamp,
178
- userId: E.userId
193
+ U.current = ae(c) ?? null, Q(() => {
194
+ if (u && u.stateKey === c && u.path?.[0]) {
195
+ const n = `${u.stateKey}:${u.path.join(".")}`;
196
+ t.getState().setSyncInfo(n, {
197
+ timeStamp: u.timeStamp,
198
+ userId: u.userId
179
199
  });
180
200
  }
181
- }, [E]);
182
- const oe = ce(
183
- (a) => {
184
- const r = a ? { ...te(c), ...a } : te(c), i = r?.defaultState || l || e;
185
- if (r?.serverState?.status === "success" && r?.serverState?.data !== void 0)
201
+ }, [u]);
202
+ const v = ce(
203
+ (n) => {
204
+ const a = n ? { ...ae(c), ...n } : ae(c), d = a?.defaultState || l || e;
205
+ if (a?.serverState?.status === "success" && a?.serverState?.data !== void 0)
186
206
  return {
187
- value: r.serverState.data,
207
+ value: a.serverState.data,
188
208
  source: "server",
189
- timestamp: r.serverState.timestamp || Date.now()
209
+ timestamp: a.serverState.timestamp || Date.now()
190
210
  };
191
- if (r?.localStorage?.key && L) {
192
- const d = K(r.localStorage.key) ? r.localStorage.key(i) : r.localStorage.key, I = fe(
193
- `${L}-${c}-${d}`
211
+ if (a?.localStorage?.key && T) {
212
+ const m = ee(a.localStorage.key) ? a.localStorage.key(d) : a.localStorage.key, P = Se(
213
+ `${T}-${c}-${m}`
194
214
  );
195
- if (I && I.lastUpdated > (r?.serverState?.timestamp || 0))
215
+ if (P && P.lastUpdated > (a?.serverState?.timestamp || 0))
196
216
  return {
197
- value: I.state,
217
+ value: P.state,
198
218
  source: "localStorage",
199
- timestamp: I.lastUpdated
219
+ timestamp: P.lastUpdated
200
220
  };
201
221
  }
202
222
  return {
203
- value: i || e,
223
+ value: d || e,
204
224
  source: "default",
205
225
  timestamp: Date.now()
206
226
  };
207
227
  },
208
- [c, l, e, L]
228
+ [c, l, e, T]
209
229
  );
210
- Y(() => {
211
- t.getState().setServerStateUpdate(c, o);
212
- }, [o, c]), Y(() => t.getState().subscribeToPath(c, (n) => {
213
- if (n?.type === "SERVER_STATE_UPDATE") {
214
- const r = n.serverState;
215
- if (r?.status === "success" && r.data !== void 0) {
216
- me(c, { serverState: r });
217
- const m = typeof r.merge == "object" ? r.merge : r.merge === !0 ? {} : null, d = t.getState().getShadowValue(c), I = r.data;
218
- if (m && Array.isArray(d) && Array.isArray(I)) {
219
- const U = m.key || "id", x = new Set(
220
- d.map((R) => R[U])
221
- ), _ = I.filter((R) => !x.has(R[U]));
222
- if (console.log("newUniqueItems", _), _.length > 0)
223
- _.forEach((R) => {
224
- t.getState().insertShadowArrayElement(c, [], R);
225
- });
226
- else
227
- return;
230
+ Q(() => {
231
+ t.getState().setServerStateUpdate(c, b);
232
+ }, [b, c]), Q(() => t.getState().subscribeToPath(c, (r) => {
233
+ if (r?.type === "SERVER_STATE_UPDATE") {
234
+ const a = r.serverState;
235
+ if (a?.status === "success" && a.data !== void 0) {
236
+ he(c, { serverState: a });
237
+ const w = typeof a.merge == "object" ? a.merge : a.merge === !0 ? {} : null, m = t.getState().getShadowValue(c), P = a.data;
238
+ if (w && Array.isArray(m) && Array.isArray(P)) {
239
+ const D = w.key || "id", j = new Set(
240
+ m.map((O) => O[D])
241
+ ), F = P.filter((O) => !j.has(O[D]));
242
+ F.length > 0 && F.forEach((O) => {
243
+ t.getState().insertShadowArrayElement(c, [], O);
244
+ const L = t.getState().getShadowMetadata(c, []);
245
+ if (L?.arrayKeys) {
246
+ const N = L.arrayKeys[L.arrayKeys.length - 1];
247
+ if (N) {
248
+ const B = N.split(".").slice(1);
249
+ t.getState().setShadowMetadata(c, B, {
250
+ isDirty: !1,
251
+ stateSource: "server",
252
+ lastServerSync: a.timestamp || Date.now()
253
+ });
254
+ const V = t.getState().getShadowValue(N);
255
+ V && typeof V == "object" && !Array.isArray(V) && Object.keys(V).forEach((E) => {
256
+ const $ = [...B, E];
257
+ t.getState().setShadowMetadata(c, $, {
258
+ isDirty: !1,
259
+ stateSource: "server",
260
+ lastServerSync: a.timestamp || Date.now()
261
+ });
262
+ });
263
+ }
264
+ }
265
+ });
228
266
  } else
229
- t.getState().initializeShadowState(c, I);
230
- const P = t.getState().getShadowMetadata(c, []);
267
+ t.getState().initializeShadowState(c, P), we(
268
+ c,
269
+ [],
270
+ P,
271
+ a.timestamp
272
+ );
273
+ const R = t.getState().getShadowMetadata(c, []);
231
274
  t.getState().setShadowMetadata(c, [], {
232
- ...P,
275
+ ...R,
233
276
  stateSource: "server",
234
- lastServerSync: r.timestamp || Date.now(),
277
+ lastServerSync: a.timestamp || Date.now(),
235
278
  isDirty: !1
236
279
  });
237
280
  }
238
281
  }
239
- }), [c, oe]), Y(() => {
240
- const a = t.getState().getShadowMetadata(c, []);
241
- if (a && a.stateSource)
282
+ }), [c, v]), Q(() => {
283
+ const n = t.getState().getShadowMetadata(c, []);
284
+ if (n && n.stateSource)
242
285
  return;
243
- const n = te(c);
244
- if (n?.defaultState !== void 0 || l !== void 0) {
245
- const r = n?.defaultState || l;
246
- n?.defaultState || me(c, {
247
- defaultState: r
286
+ const r = ae(c);
287
+ if (r?.defaultState !== void 0 || l !== void 0) {
288
+ const a = r?.defaultState || l;
289
+ r?.defaultState || he(c, {
290
+ defaultState: a
248
291
  });
249
- const { value: i, source: m, timestamp: d } = oe();
250
- t.getState().initializeShadowState(c, i), t.getState().setShadowMetadata(c, [], {
251
- stateSource: m,
252
- lastServerSync: m === "server" ? d : void 0,
292
+ const { value: d, source: w, timestamp: m } = v();
293
+ t.getState().initializeShadowState(c, d), t.getState().setShadowMetadata(c, [], {
294
+ stateSource: w,
295
+ lastServerSync: w === "server" ? m : void 0,
253
296
  isDirty: !1,
254
- baseServerState: m === "server" ? i : void 0
255
- }), re(c);
297
+ baseServerState: w === "server" ? d : void 0
298
+ }), ie(c);
256
299
  }
257
- }, [c, ...T || []]), ue(() => {
258
- N && me(c, {
259
- serverSync: p,
260
- formElements: v,
300
+ }, [c, ...A || []]), de(() => {
301
+ W && he(c, {
302
+ formElements: g,
261
303
  defaultState: l,
262
- localStorage: g,
263
- middleware: f.current?.middleware
304
+ localStorage: f,
305
+ middleware: U.current?.middleware
264
306
  });
265
- const a = `${c}////${H.current}`, n = t.getState().getShadowMetadata(c, []), r = n?.components || /* @__PURE__ */ new Map();
266
- return r.set(a, {
267
- forceUpdate: () => M({}),
268
- reactiveType: V ?? ["component", "deps"],
307
+ const n = `${c}////${J.current}`, r = t.getState().getShadowMetadata(c, []), a = r?.components || /* @__PURE__ */ new Map();
308
+ return a.set(n, {
309
+ forceUpdate: () => S({}),
310
+ reactiveType: p ?? ["component", "deps"],
269
311
  paths: /* @__PURE__ */ new Set(),
270
312
  depsFunction: h || void 0,
271
313
  deps: h ? h(t.getState().getShadowValue(c)) : [],
272
314
  prevDeps: h ? h(t.getState().getShadowValue(c)) : []
273
315
  }), t.getState().setShadowMetadata(c, [], {
274
- ...n,
275
- components: r
276
- }), M({}), () => {
277
- const i = t.getState().getShadowMetadata(c, []), m = i?.components?.get(a);
278
- m?.paths && m.paths.forEach((d) => {
279
- const P = d.split(".").slice(1), U = t.getState().getShadowMetadata(c, P);
280
- U?.pathComponents && U.pathComponents.size === 0 && (delete U.pathComponents, t.getState().setShadowMetadata(c, P, U));
281
- }), i?.components && t.getState().setShadowMetadata(c, [], i);
316
+ ...r,
317
+ components: a
318
+ }), S({}), () => {
319
+ const d = t.getState().getShadowMetadata(c, []), w = d?.components?.get(n);
320
+ w?.paths && w.paths.forEach((m) => {
321
+ const R = m.split(".").slice(1), D = t.getState().getShadowMetadata(c, R);
322
+ D?.pathComponents && D.pathComponents.size === 0 && (delete D.pathComponents, t.getState().setShadowMetadata(c, R, D));
323
+ }), d?.components && t.getState().setShadowMetadata(c, [], d);
282
324
  };
283
325
  }, []);
284
- const se = (a, n, r, i) => {
285
- const m = [c, ...n].join(".");
286
- if (Array.isArray(n)) {
287
- const b = `${c}-${n.join(".")}`;
288
- G.current.add(b);
326
+ const K = G(null), oe = (n, r, a, d) => {
327
+ const w = [c, ...r].join(".");
328
+ if (Array.isArray(r)) {
329
+ const V = `${c}-${r.join(".")}`;
330
+ Y.current.add(V);
289
331
  }
290
- const d = t.getState(), I = d.getShadowMetadata(c, n), P = d.getShadowValue(m), U = r.updateType === "insert" && K(a) ? a({ state: P, uuid: ee() }) : K(a) ? a(P) : a, _ = {
332
+ const m = t.getState(), P = m.getShadowMetadata(c, r), R = m.getShadowValue(w), D = a.updateType === "insert" && ee(n) ? n({ state: R, uuid: te() }) : ee(n) ? n(R) : n, F = {
291
333
  timeStamp: Date.now(),
292
334
  stateKey: c,
293
- path: n,
294
- updateType: r.updateType,
335
+ path: r,
336
+ updateType: a.updateType,
295
337
  status: "new",
296
- oldValue: P,
297
- newValue: U
338
+ oldValue: R,
339
+ newValue: D
298
340
  };
299
- switch (r.updateType) {
341
+ switch (a.updateType) {
300
342
  case "insert": {
301
- d.insertShadowArrayElement(c, n, _.newValue), d.markAsDirty(c, n, { bubble: !0 });
343
+ m.insertShadowArrayElement(c, r, F.newValue), m.markAsDirty(c, r, { bubble: !0 });
344
+ const V = m.getShadowMetadata(c, r);
345
+ if (V?.arrayKeys) {
346
+ const E = V.arrayKeys[V.arrayKeys.length - 1];
347
+ if (E) {
348
+ const $ = E.split(".").slice(1);
349
+ m.markAsDirty(c, $, { bubble: !1 });
350
+ }
351
+ }
302
352
  break;
303
353
  }
304
354
  case "cut": {
305
- const b = n.slice(0, -1);
306
- d.removeShadowArrayElement(c, n), d.markAsDirty(c, b, { bubble: !0 });
355
+ const V = r.slice(0, -1);
356
+ m.removeShadowArrayElement(c, r), m.markAsDirty(c, V, { bubble: !0 });
307
357
  break;
308
358
  }
309
359
  case "update": {
310
- d.updateShadowAtPath(c, n, _.newValue), d.markAsDirty(c, n, { bubble: !0 });
360
+ m.updateShadowAtPath(c, r, F.newValue), m.markAsDirty(c, r, { bubble: !0 });
311
361
  break;
312
362
  }
313
363
  }
314
- if (I?.signals && I.signals.length > 0) {
315
- const b = r.updateType === "cut" ? null : U;
316
- I.signals.forEach(({ parentId: k, position: A, effect: F }) => {
317
- const y = document.querySelector(`[data-parent-id="${k}"]`);
364
+ if (console.log("sdadasdasd", K.current, F), K.current && K.current.connected && K.current.updateState({ operation: F }), P?.signals && P.signals.length > 0) {
365
+ const V = a.updateType === "cut" ? null : D;
366
+ P.signals.forEach(({ parentId: E, position: $, effect: I }) => {
367
+ const y = document.querySelector(`[data-parent-id="${E}"]`);
318
368
  if (y) {
319
- const w = Array.from(y.childNodes);
320
- if (w[A]) {
321
- let C = b;
322
- if (F && b !== null)
369
+ const k = Array.from(y.childNodes);
370
+ if (k[$]) {
371
+ let C = V;
372
+ if (I && V !== null)
323
373
  try {
324
374
  C = new Function(
325
375
  "state",
326
- `return (${F})(state)`
327
- )(b);
328
- } catch ($) {
329
- console.error("Error evaluating effect function:", $);
376
+ `return (${I})(state)`
377
+ )(V);
378
+ } catch (_) {
379
+ console.error("Error evaluating effect function:", _);
330
380
  }
331
- C != null && typeof C == "object" && (C = JSON.stringify(C)), w[A].textContent = String(C ?? "");
381
+ C != null && typeof C == "object" && (C = JSON.stringify(C)), k[$].textContent = String(C ?? "");
332
382
  }
333
383
  }
334
384
  });
335
385
  }
336
- if (r.updateType === "insert" && I?.mapWrappers && I.mapWrappers.length > 0) {
337
- const b = d.getShadowMetadata(c, n)?.arrayKeys || [], k = b[b.length - 1], A = d.getShadowValue(k), F = d.getShadowValue(
338
- [c, ...n].join(".")
386
+ if (a.updateType === "insert" && P?.mapWrappers && P.mapWrappers.length > 0) {
387
+ const V = m.getShadowMetadata(c, r)?.arrayKeys || [], E = V[V.length - 1], $ = m.getShadowValue(E), I = m.getShadowValue(
388
+ [c, ...r].join(".")
339
389
  );
340
- if (!k || A === void 0) return;
341
- I.mapWrappers.forEach((y) => {
342
- let w = !0, C = -1;
390
+ if (!E || $ === void 0) return;
391
+ P.mapWrappers.forEach((y) => {
392
+ let k = !0, C = -1;
343
393
  if (y.meta?.transforms && y.meta.transforms.length > 0) {
344
- for (const $ of y.meta.transforms)
345
- if ($.type === "filter" && !$.fn(A, -1)) {
346
- w = !1;
394
+ for (const _ of y.meta.transforms)
395
+ if (_.type === "filter" && !_.fn($, -1)) {
396
+ k = !1;
347
397
  break;
348
398
  }
349
- if (w) {
350
- const $ = ve(
399
+ if (k) {
400
+ const _ = Ie(
351
401
  c,
352
- n,
402
+ r,
353
403
  y.meta.transforms
354
- ), j = y.meta.transforms.find(
355
- (D) => D.type === "sort"
404
+ ), q = y.meta.transforms.find(
405
+ (H) => H.type === "sort"
356
406
  );
357
- if (j) {
358
- const D = $.map((z) => ({
407
+ if (q) {
408
+ const H = _.map((z) => ({
359
409
  key: z,
360
- value: d.getShadowValue(z)
410
+ value: m.getShadowValue(z)
361
411
  }));
362
- D.push({ key: k, value: A }), D.sort((z, Q) => j.fn(z.value, Q.value)), C = D.findIndex(
363
- (z) => z.key === k
412
+ H.push({ key: E, value: $ }), H.sort((z, Z) => q.fn(z.value, Z.value)), C = H.findIndex(
413
+ (z) => z.key === E
364
414
  );
365
415
  } else
366
- C = $.length;
416
+ C = _.length;
367
417
  }
368
418
  } else
369
- w = !0, C = b.length - 1;
370
- if (w && y.containerRef && y.containerRef.isConnected) {
371
- const $ = document.createElement("div");
372
- $.setAttribute("data-item-path", k);
373
- const j = Array.from(y.containerRef.children);
374
- C >= 0 && C < j.length ? y.containerRef.insertBefore(
375
- $,
376
- j[C]
377
- ) : y.containerRef.appendChild($);
378
- const D = Ce($), z = ee(), Q = k.split(".").slice(1), X = y.rebuildStateShape({
419
+ k = !0, C = V.length - 1;
420
+ if (k && y.containerRef && y.containerRef.isConnected) {
421
+ const _ = document.createElement("div");
422
+ _.setAttribute("data-item-path", E);
423
+ const q = Array.from(y.containerRef.children);
424
+ C >= 0 && C < q.length ? y.containerRef.insertBefore(
425
+ _,
426
+ q[C]
427
+ ) : y.containerRef.appendChild(_);
428
+ const H = Ce(_), z = te(), Z = E.split(".").slice(1), ue = y.rebuildStateShape({
379
429
  path: y.path,
380
- currentState: F,
430
+ currentState: I,
381
431
  componentId: y.componentId,
382
432
  meta: y.meta
383
433
  });
384
- D.render(
385
- le(we, {
434
+ H.render(
435
+ le(Me, {
386
436
  stateKey: c,
387
437
  itemComponentId: z,
388
- itemPath: Q,
438
+ itemPath: Z,
389
439
  localIndex: C,
390
- arraySetter: X,
440
+ arraySetter: ue,
391
441
  rebuildStateShape: y.rebuildStateShape,
392
442
  renderFn: y.mapFn
393
443
  })
@@ -395,451 +445,453 @@ function Be(e, {
395
445
  }
396
446
  });
397
447
  }
398
- if (r.updateType === "cut") {
399
- const b = n.slice(0, -1), k = d.getShadowMetadata(c, b);
400
- k?.mapWrappers && k.mapWrappers.length > 0 && k.mapWrappers.forEach((A) => {
401
- if (A.containerRef && A.containerRef.isConnected) {
402
- const F = A.containerRef.querySelector(
403
- `[data-item-path="${m}"]`
448
+ if (a.updateType === "cut") {
449
+ const V = r.slice(0, -1), E = m.getShadowMetadata(c, V);
450
+ E?.mapWrappers && E.mapWrappers.length > 0 && E.mapWrappers.forEach(($) => {
451
+ if ($.containerRef && $.containerRef.isConnected) {
452
+ const I = $.containerRef.querySelector(
453
+ `[data-item-path="${w}"]`
404
454
  );
405
- F && F.remove();
455
+ I && I.remove();
406
456
  }
407
457
  });
408
458
  }
409
- r.updateType === "update" && (i || f.current?.validation?.key) && n && ne(
410
- (i || f.current?.validation?.key) + "." + n.join(".")
459
+ a.updateType === "update" && (d || U.current?.validation?.key) && r && ne(
460
+ (d || U.current?.validation?.key) + "." + r.join(".")
411
461
  );
412
- const R = n.slice(0, n.length - 1);
413
- r.updateType === "cut" && f.current?.validation?.key && ne(
414
- f.current?.validation?.key + "." + R.join(".")
415
- ), r.updateType === "insert" && f.current?.validation?.key && Ne(
416
- f.current?.validation?.key + "." + R.join(".")
417
- ).filter((k) => {
418
- let A = k?.split(".").length;
419
- const F = "";
420
- if (k == R.join(".") && A == R.length - 1) {
421
- let y = k + "." + R;
422
- ne(k), pe(y, F);
462
+ const O = r.slice(0, r.length - 1);
463
+ a.updateType === "cut" && U.current?.validation?.key && ne(
464
+ U.current?.validation?.key + "." + O.join(".")
465
+ ), a.updateType === "insert" && U.current?.validation?.key && Ne(
466
+ U.current?.validation?.key + "." + O.join(".")
467
+ ).filter((E) => {
468
+ let $ = E?.split(".").length;
469
+ const I = "";
470
+ if (E == O.join(".") && $ == O.length - 1) {
471
+ let y = E + "." + O;
472
+ ne(E), ve(y, I);
423
473
  }
424
474
  });
425
- const B = d.getShadowValue(c), O = d.getShadowMetadata(c, []), W = /* @__PURE__ */ new Set();
426
- if (!O?.components)
427
- return B;
428
- if (r.updateType === "update")
429
- I?.pathComponents && I.pathComponents.forEach((b) => {
430
- if (W.has(b))
475
+ const L = m.getShadowValue(c), N = m.getShadowMetadata(c, []), B = /* @__PURE__ */ new Set();
476
+ if (!N?.components)
477
+ return L;
478
+ if (a.updateType === "update")
479
+ P?.pathComponents && P.pathComponents.forEach((V) => {
480
+ if (B.has(V))
431
481
  return;
432
- const k = O.components?.get(b);
433
- k && ((Array.isArray(k.reactiveType) ? k.reactiveType : [k.reactiveType || "component"]).includes("none") || (k.forceUpdate(), W.add(b)));
434
- }), U && typeof U == "object" && !Te(U) && P && typeof P == "object" && !Te(P) && Ae(U, P).forEach((k) => {
435
- const A = k.split("."), F = [...n, ...A], y = d.getShadowMetadata(c, F);
436
- y?.pathComponents && y.pathComponents.forEach((w) => {
437
- if (W.has(w))
482
+ const E = N.components?.get(V);
483
+ E && ((Array.isArray(E.reactiveType) ? E.reactiveType : [E.reactiveType || "component"]).includes("none") || (E.forceUpdate(), B.add(V)));
484
+ }), D && typeof D == "object" && !Te(D) && R && typeof R == "object" && !Te(R) && Pe(D, R).forEach((E) => {
485
+ const $ = E.split("."), I = [...r, ...$], y = m.getShadowMetadata(c, I);
486
+ y?.pathComponents && y.pathComponents.forEach((k) => {
487
+ if (B.has(k))
438
488
  return;
439
- const C = O.components?.get(w);
440
- C && ((Array.isArray(C.reactiveType) ? C.reactiveType : [C.reactiveType || "component"]).includes("none") || (C.forceUpdate(), W.add(w)));
489
+ const C = N.components?.get(k);
490
+ C && ((Array.isArray(C.reactiveType) ? C.reactiveType : [C.reactiveType || "component"]).includes("none") || (C.forceUpdate(), B.add(k)));
441
491
  });
442
492
  });
443
- else if (r.updateType === "insert" || r.updateType === "cut") {
444
- const b = r.updateType === "insert" ? n : n.slice(0, -1), k = d.getShadowMetadata(c, b);
445
- if (k?.signals && k.signals.length > 0) {
446
- const A = [c, ...b].join("."), F = d.getShadowValue(A);
447
- k.signals.forEach(({ parentId: y, position: w, effect: C }) => {
448
- const $ = document.querySelector(
493
+ else if (a.updateType === "insert" || a.updateType === "cut") {
494
+ const V = a.updateType === "insert" ? r : r.slice(0, -1), E = m.getShadowMetadata(c, V);
495
+ if (E?.signals && E.signals.length > 0) {
496
+ const $ = [c, ...V].join("."), I = m.getShadowValue($);
497
+ E.signals.forEach(({ parentId: y, position: k, effect: C }) => {
498
+ const _ = document.querySelector(
449
499
  `[data-parent-id="${y}"]`
450
500
  );
451
- if ($) {
452
- const j = Array.from($.childNodes);
453
- if (j[w]) {
454
- let D = F;
501
+ if (_) {
502
+ const q = Array.from(_.childNodes);
503
+ if (q[k]) {
504
+ let H = I;
455
505
  if (C)
456
506
  try {
457
- D = new Function(
507
+ H = new Function(
458
508
  "state",
459
509
  `return (${C})(state)`
460
- )(F);
510
+ )(I);
461
511
  } catch (z) {
462
- console.error("Error evaluating effect function:", z), D = F;
512
+ console.error("Error evaluating effect function:", z), H = I;
463
513
  }
464
- D != null && typeof D == "object" && (D = JSON.stringify(D)), j[w].textContent = String(D ?? "");
514
+ H != null && typeof H == "object" && (H = JSON.stringify(H)), q[k].textContent = String(H ?? "");
465
515
  }
466
516
  }
467
517
  });
468
518
  }
469
- k?.pathComponents && k.pathComponents.forEach((A) => {
470
- if (!W.has(A)) {
471
- const F = O.components?.get(A);
472
- F && (F.forceUpdate(), W.add(A));
519
+ E?.pathComponents && E.pathComponents.forEach(($) => {
520
+ if (!B.has($)) {
521
+ const I = N.components?.get($);
522
+ I && (I.forceUpdate(), B.add($));
473
523
  }
474
524
  });
475
525
  }
476
- return O.components.forEach((b, k) => {
477
- if (W.has(k))
526
+ return N.components.forEach((V, E) => {
527
+ if (B.has(E))
478
528
  return;
479
- const A = Array.isArray(b.reactiveType) ? b.reactiveType : [b.reactiveType || "component"];
480
- if (A.includes("all")) {
481
- b.forceUpdate(), W.add(k);
529
+ const $ = Array.isArray(V.reactiveType) ? V.reactiveType : [V.reactiveType || "component"];
530
+ if ($.includes("all")) {
531
+ V.forceUpdate(), B.add(E);
482
532
  return;
483
533
  }
484
- if (A.includes("deps") && b.depsFunction) {
485
- const F = d.getShadowValue(c), y = b.depsFunction(F);
486
- let w = !1;
487
- y === !0 ? w = !0 : Array.isArray(y) && (ie(b.prevDeps, y) || (b.prevDeps = y, w = !0)), w && (b.forceUpdate(), W.add(k));
534
+ if ($.includes("deps") && V.depsFunction) {
535
+ const I = m.getShadowValue(c), y = V.depsFunction(I);
536
+ let k = !1;
537
+ y === !0 ? k = !0 : Array.isArray(y) && (se(V.prevDeps, y) || (V.prevDeps = y, k = !0)), k && (V.forceUpdate(), B.add(E));
488
538
  }
489
- }), W.clear(), We(c, (b) => {
490
- const k = [...b ?? [], _], A = /* @__PURE__ */ new Map();
491
- return k.forEach((F) => {
492
- const y = `${F.stateKey}:${JSON.stringify(F.path)}`, w = A.get(y);
493
- w ? (w.timeStamp = Math.max(w.timeStamp, F.timeStamp), w.newValue = F.newValue, w.oldValue = w.oldValue ?? F.oldValue, w.updateType = F.updateType) : A.set(y, { ...F });
494
- }), Array.from(A.values());
539
+ }), B.clear(), We(c, (V) => {
540
+ const E = [...V ?? [], F], $ = /* @__PURE__ */ new Map();
541
+ return E.forEach((I) => {
542
+ const y = `${I.stateKey}:${JSON.stringify(I.path)}`, k = $.get(y);
543
+ k ? (k.timeStamp = Math.max(k.timeStamp, I.timeStamp), k.newValue = I.newValue, k.oldValue = k.oldValue ?? I.oldValue, k.updateType = I.updateType) : $.set(y, { ...I });
544
+ }), Array.from($.values());
495
545
  }), He(
496
- U,
546
+ D,
497
547
  c,
498
- f.current,
499
- L
500
- ), f.current?.middleware && f.current.middleware({
501
- updateLog: J,
502
- update: _
503
- }), B;
548
+ U.current,
549
+ T
550
+ ), U.current?.middleware && U.current.middleware({
551
+ updateLog: x,
552
+ update: F
553
+ }), L;
504
554
  };
505
- return t.getState().initialStateGlobal[c] || _e(c, e), de(() => Pe(
555
+ t.getState().initialStateGlobal[c] || $e(c, e);
556
+ const fe = ge(() => De(
506
557
  c,
507
- se,
508
- H.current,
509
- L
510
- ), [c, L]);
558
+ oe,
559
+ J.current,
560
+ T
561
+ ), [c, T]), s = U.current?.cogsSync;
562
+ return s && (K.current = s(fe)), fe;
511
563
  }
512
564
  function qe(e) {
513
565
  return !e || e.length === 0 ? "" : e.map(
514
- (s) => (
566
+ (i) => (
515
567
  // Safely stringify dependencies. An empty array becomes '[]'.
516
- `${s.type}${JSON.stringify(s.dependencies || [])}`
568
+ `${i.type}${JSON.stringify(i.dependencies || [])}`
517
569
  )
518
570
  ).join("");
519
571
  }
520
- const ve = (e, s, p) => {
521
- let g = t.getState().getShadowMetadata(e, s)?.arrayKeys || [];
522
- if (!p || p.length === 0)
572
+ const Ie = (e, i, f) => {
573
+ let g = t.getState().getShadowMetadata(e, i)?.arrayKeys || [];
574
+ if (!f || f.length === 0)
523
575
  return g;
524
- let v = g.map((h) => ({
525
- key: h,
526
- value: t.getState().getShadowValue(h)
576
+ let h = g.map((p) => ({
577
+ key: p,
578
+ value: t.getState().getShadowValue(p)
527
579
  }));
528
- for (const h of p)
529
- h.type === "filter" ? v = v.filter(
530
- ({ value: V }, u) => h.fn(V, u)
531
- ) : h.type === "sort" && v.sort((V, u) => h.fn(V.value, u.value));
532
- return v.map(({ key: h }) => h);
533
- }, Ee = (e, s, p) => {
534
- const g = `${e}////${s}`, h = t.getState().getShadowMetadata(e, [])?.components?.get(g);
535
- if (!h || h.reactiveType == "none" || !(Array.isArray(h.reactiveType) ? h.reactiveType : [h.reactiveType]).includes("component"))
580
+ for (const p of f)
581
+ p.type === "filter" ? h = h.filter(
582
+ ({ value: M }, l) => p.fn(M, l)
583
+ ) : p.type === "sort" && h.sort((M, l) => p.fn(M.value, l.value));
584
+ return h.map(({ key: p }) => p);
585
+ }, Ve = (e, i, f) => {
586
+ const g = `${e}////${i}`, p = t.getState().getShadowMetadata(e, [])?.components?.get(g);
587
+ if (!p || p.reactiveType == "none" || !(Array.isArray(p.reactiveType) ? p.reactiveType : [p.reactiveType]).includes("component"))
536
588
  return;
537
- const V = [e, ...p].join(".");
538
- h.paths.add(V);
539
- const u = t.getState().getShadowMetadata(e, p) || {}, l = u.pathComponents || /* @__PURE__ */ new Set();
540
- l.add(g), t.getState().setShadowMetadata(e, p, {
541
- ...u,
542
- pathComponents: l
589
+ const M = [e, ...f].join(".");
590
+ p.paths.add(M);
591
+ const l = t.getState().getShadowMetadata(e, f) || {}, u = l.pathComponents || /* @__PURE__ */ new Set();
592
+ u.add(g), t.getState().setShadowMetadata(e, f, {
593
+ ...l,
594
+ pathComponents: u
543
595
  });
544
- }, he = (e, s, p) => {
545
- const g = t.getState(), v = g.getShadowMetadata(e, []), h = /* @__PURE__ */ new Set();
546
- v?.components && v.components.forEach((u, l) => {
547
- (Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType || "component"]).includes("all") && (u.forceUpdate(), h.add(l));
548
- }), g.getShadowMetadata(e, [...s, "getSelected"])?.pathComponents?.forEach((u) => {
549
- v?.components?.get(u)?.forceUpdate();
596
+ }, ye = (e, i, f) => {
597
+ const g = t.getState(), h = g.getShadowMetadata(e, []), p = /* @__PURE__ */ new Set();
598
+ h?.components && h.components.forEach((l, u) => {
599
+ (Array.isArray(l.reactiveType) ? l.reactiveType : [l.reactiveType || "component"]).includes("all") && (l.forceUpdate(), p.add(u));
600
+ }), g.getShadowMetadata(e, [...i, "getSelected"])?.pathComponents?.forEach((l) => {
601
+ h?.components?.get(l)?.forceUpdate();
550
602
  });
551
- const V = g.getShadowMetadata(e, s);
552
- for (let u of V?.arrayKeys || []) {
553
- const l = u + ".selected", E = g.getShadowMetadata(
603
+ const M = g.getShadowMetadata(e, i);
604
+ for (let l of M?.arrayKeys || []) {
605
+ const u = l + ".selected", A = g.getShadowMetadata(
554
606
  e,
555
- l.split(".").slice(1)
607
+ u.split(".").slice(1)
556
608
  );
557
- u == p && E?.pathComponents?.forEach((T) => {
558
- v?.components?.get(T)?.forceUpdate();
609
+ l == f && A?.pathComponents?.forEach((b) => {
610
+ h?.components?.get(b)?.forceUpdate();
559
611
  });
560
612
  }
561
613
  };
562
- function Pe(e, s, p, g) {
563
- const v = /* @__PURE__ */ new Map();
564
- let h = 0;
565
- const V = (T) => {
566
- const o = T.join(".");
567
- for (const [S] of v)
568
- (S === o || S.startsWith(o + ".")) && v.delete(S);
569
- h++;
614
+ function De(e, i, f, g) {
615
+ const h = /* @__PURE__ */ new Map();
616
+ let p = 0;
617
+ const M = (b) => {
618
+ const o = b.join(".");
619
+ for (const [S] of h)
620
+ (S === o || S.startsWith(o + ".")) && h.delete(S);
621
+ p++;
570
622
  };
571
- function u({
572
- currentState: T,
623
+ function l({
624
+ currentState: b,
573
625
  path: o = [],
574
626
  meta: S,
575
- componentId: M
627
+ componentId: T
576
628
  }) {
577
- const L = o.map(String).join("."), N = [e, ...o].join(".");
578
- T = t.getState().getShadowValue(N, S?.validIds);
579
- const c = function() {
629
+ const W = o.map(String).join("."), c = [e, ...o].join(".");
630
+ b = t.getState().getShadowValue(c, S?.validIds);
631
+ const x = function() {
580
632
  return t().getShadowValue(e, o);
581
- }, J = {
582
- apply(H, f, oe) {
633
+ }, Y = {
634
+ apply(U, v, K) {
583
635
  },
584
- get(H, f) {
585
- if (f === "_rebuildStateShape")
586
- return u;
587
- if (Object.getOwnPropertyNames(l).includes(f) && o.length === 0)
588
- return l[f];
589
- if (f === "getDifferences")
636
+ get(U, v) {
637
+ if (v === "_rebuildStateShape")
638
+ return l;
639
+ if (Object.getOwnPropertyNames(u).includes(v) && o.length === 0)
640
+ return u[v];
641
+ if (v === "getDifferences")
590
642
  return () => {
591
- const a = t.getState().getShadowMetadata(e, []), n = t.getState().getShadowValue(e);
643
+ const s = t.getState().getShadowMetadata(e, []), n = t.getState().getShadowValue(e);
592
644
  let r;
593
- return a?.stateSource === "server" && a.baseServerState ? r = a.baseServerState : r = t.getState().initialStateGlobal[e], Ae(n, r);
645
+ return s?.stateSource === "server" && s.baseServerState ? r = s.baseServerState : r = t.getState().initialStateGlobal[e], Pe(n, r);
594
646
  };
595
- if (f === "sync" && o.length === 0)
647
+ if (v === "sync" && o.length === 0)
596
648
  return async function() {
597
- const a = t.getState().getInitialOptions(e), n = a?.sync;
649
+ const s = t.getState().getInitialOptions(e), n = s?.sync;
598
650
  if (!n)
599
651
  return console.error(`No mutation defined for state key "${e}"`), { success: !1, error: "No mutation defined" };
600
- const r = t.getState().getShadowValue(e, []), i = a?.validation?.key;
652
+ const r = t.getState().getShadowValue(e, []), a = s?.validation?.key;
601
653
  try {
602
- const m = await n.action(r);
603
- if (m && !m.success && m.errors && i && (t.getState().removeValidationError(i), m.errors.forEach((d) => {
604
- const I = [i, ...d.path].join(".");
605
- t.getState().addValidationError(I, d.message);
606
- }), re(e)), m?.success) {
607
- const d = t.getState().getShadowMetadata(e, []);
654
+ const d = await n.action(r);
655
+ if (d && !d.success && d.errors && a && (t.getState().removeValidationError(a), d.errors.forEach((w) => {
656
+ const m = [a, ...w.path].join(".");
657
+ t.getState().addValidationError(m, w.message);
658
+ }), ie(e)), d?.success) {
659
+ const w = t.getState().getShadowMetadata(e, []);
608
660
  t.getState().setShadowMetadata(e, [], {
609
- ...d,
661
+ ...w,
610
662
  isDirty: !1,
611
663
  lastServerSync: Date.now(),
612
664
  stateSource: "server",
613
665
  baseServerState: r
614
666
  // Update base server state
615
- }), n.onSuccess && n.onSuccess(m.data);
616
- } else !m?.success && n.onError && n.onError(m.error);
617
- return m;
618
- } catch (m) {
619
- return n.onError && n.onError(m), { success: !1, error: m };
667
+ }), n.onSuccess && n.onSuccess(d.data);
668
+ } else !d?.success && n.onError && n.onError(d.error);
669
+ return d;
670
+ } catch (d) {
671
+ return n.onError && n.onError(d), { success: !1, error: d };
620
672
  }
621
673
  };
622
- if (f === "_status" || f === "getStatus") {
623
- const a = () => {
624
- const n = t.getState().getShadowMetadata(e, []);
625
- return n?.stateSource === "server" && !n.isDirty ? "synced" : n?.isDirty ? "dirty" : n?.stateSource === "localStorage" ? "restored" : n?.stateSource === "default" ? "fresh" : "unknown";
674
+ if (v === "_status" || v === "getStatus") {
675
+ const s = () => {
676
+ const n = t.getState().getShadowMetadata(e, o), r = t.getState().getShadowValue(c);
677
+ return n?.isDirty === !0 ? "dirty" : n?.isDirty === !1 || n?.stateSource === "server" ? "synced" : n?.stateSource === "localStorage" ? "restored" : n?.stateSource === "default" ? "fresh" : t.getState().getShadowMetadata(e, [])?.stateSource === "server" && !n?.isDirty ? "synced" : r !== void 0 && !n ? "fresh" : "unknown";
626
678
  };
627
- return f === "_status" ? a() : a;
679
+ return v === "_status" ? s() : s;
628
680
  }
629
- if (f === "removeStorage")
681
+ if (v === "removeStorage")
630
682
  return () => {
631
- const a = t.getState().initialStateGlobal[e], n = te(e), r = K(n?.localStorage?.key) ? n.localStorage.key(a) : n?.localStorage?.key, i = `${g}-${e}-${r}`;
632
- i && localStorage.removeItem(i);
683
+ const s = t.getState().initialStateGlobal[e], n = ae(e), r = ee(n?.localStorage?.key) ? n.localStorage.key(s) : n?.localStorage?.key, a = `${g}-${e}-${r}`;
684
+ a && localStorage.removeItem(a);
633
685
  };
634
- if (f === "showValidationErrors")
686
+ if (v === "showValidationErrors")
635
687
  return () => {
636
- const a = t.getState().getInitialOptions(e)?.validation;
637
- if (!a?.key) throw new Error("Validation key not found");
638
- return t.getState().getValidationErrors(a.key + "." + o.join("."));
688
+ const s = t.getState().getInitialOptions(e)?.validation;
689
+ if (!s?.key) throw new Error("Validation key not found");
690
+ return t.getState().getValidationErrors(s.key + "." + o.join("."));
639
691
  };
640
- if (Array.isArray(T)) {
641
- if (f === "getSelected")
692
+ if (Array.isArray(b)) {
693
+ if (v === "getSelected")
642
694
  return () => {
643
- const a = e + "." + o.join(".");
644
- Ee(e, M, [
695
+ const s = e + "." + o.join(".");
696
+ Ve(e, T, [
645
697
  ...o,
646
698
  "getSelected"
647
699
  ]);
648
700
  const n = t.getState().selectedIndicesMap;
649
- if (!n || !n.has(a))
701
+ if (!n || !n.has(s))
650
702
  return;
651
- const r = n.get(a);
703
+ const r = n.get(s);
652
704
  if (S?.validIds && !S.validIds.includes(r))
653
705
  return;
654
- const i = t.getState().getShadowValue(r);
655
- if (i)
656
- return u({
657
- currentState: i,
706
+ const a = t.getState().getShadowValue(r);
707
+ if (a)
708
+ return l({
709
+ currentState: a,
658
710
  path: r.split(".").slice(1),
659
- componentId: M
711
+ componentId: T
660
712
  });
661
713
  };
662
- if (f === "getSelectedIndex")
714
+ if (v === "getSelectedIndex")
663
715
  return () => t.getState().getSelectedIndex(
664
716
  e + "." + o.join("."),
665
717
  S?.validIds
666
718
  );
667
- if (f === "clearSelected")
668
- return he(e, o), () => {
719
+ if (v === "clearSelected")
720
+ return ye(e, o), () => {
669
721
  t.getState().clearSelectedIndex({
670
722
  arrayKey: e + "." + o.join(".")
671
723
  });
672
724
  };
673
- if (f === "useVirtualView")
674
- return (a) => {
725
+ if (v === "useVirtualView")
726
+ return (s) => {
675
727
  const {
676
728
  itemHeight: n = 50,
677
729
  overscan: r = 6,
678
- stickToBottom: i = !1,
679
- scrollStickTolerance: m = 75
680
- } = a, d = q(null), [I, P] = Z({
730
+ stickToBottom: a = !1,
731
+ scrollStickTolerance: d = 75
732
+ } = s, w = G(null), [m, P] = X({
681
733
  startIndex: 0,
682
734
  endIndex: 10
683
- }), [U, x] = Z({}), _ = q(!0), R = q({
735
+ }), [R, D] = X({}), j = G(!0), F = G({
684
736
  isUserScrolling: !1,
685
737
  lastScrollTop: 0,
686
738
  scrollUpCount: 0,
687
739
  isNearBottom: !0
688
- }), B = q(
740
+ }), O = G(
689
741
  /* @__PURE__ */ new Map()
690
742
  );
691
- ue(() => {
692
- if (!i || !d.current || R.current.isUserScrolling)
743
+ de(() => {
744
+ if (!a || !w.current || F.current.isUserScrolling)
693
745
  return;
694
- const y = d.current;
695
- y.scrollTo({
696
- top: y.scrollHeight,
697
- behavior: _.current ? "instant" : "smooth"
746
+ const I = w.current;
747
+ I.scrollTo({
748
+ top: I.scrollHeight,
749
+ behavior: j.current ? "instant" : "smooth"
698
750
  });
699
- }, [U, i]);
700
- const O = t.getState().getShadowMetadata(e, o)?.arrayKeys || [], { totalHeight: W, itemOffsets: b } = de(() => {
701
- let y = 0;
702
- const w = /* @__PURE__ */ new Map();
703
- return (t.getState().getShadowMetadata(e, o)?.arrayKeys || []).forEach(($) => {
704
- const j = $.split(".").slice(1), D = t.getState().getShadowMetadata(e, j)?.virtualizer?.itemHeight || n;
705
- w.set($, {
706
- height: D,
707
- offset: y
708
- }), y += D;
709
- }), B.current = w, { totalHeight: y, itemOffsets: w };
710
- }, [O.length, n]);
711
- ue(() => {
712
- if (i && O.length > 0 && d.current && !R.current.isUserScrolling && _.current) {
713
- const y = d.current, w = () => {
714
- if (y.clientHeight > 0) {
715
- const C = Math.ceil(
716
- y.clientHeight / n
717
- ), $ = O.length - 1, j = Math.max(
751
+ }, [R, a]);
752
+ const L = t.getState().getShadowMetadata(e, o)?.arrayKeys || [], { totalHeight: N, itemOffsets: B } = ge(() => {
753
+ let I = 0;
754
+ const y = /* @__PURE__ */ new Map();
755
+ return (t.getState().getShadowMetadata(e, o)?.arrayKeys || []).forEach((C) => {
756
+ const _ = C.split(".").slice(1), q = t.getState().getShadowMetadata(e, _)?.virtualizer?.itemHeight || n;
757
+ y.set(C, {
758
+ height: q,
759
+ offset: I
760
+ }), I += q;
761
+ }), O.current = y, { totalHeight: I, itemOffsets: y };
762
+ }, [L.length, n]);
763
+ de(() => {
764
+ if (a && L.length > 0 && w.current && !F.current.isUserScrolling && j.current) {
765
+ const I = w.current, y = () => {
766
+ if (I.clientHeight > 0) {
767
+ const k = Math.ceil(
768
+ I.clientHeight / n
769
+ ), C = L.length - 1, _ = Math.max(
718
770
  0,
719
- $ - C - r
771
+ C - k - r
720
772
  );
721
- P({ startIndex: j, endIndex: $ }), requestAnimationFrame(() => {
722
- A("instant"), _.current = !1;
773
+ P({ startIndex: _, endIndex: C }), requestAnimationFrame(() => {
774
+ E("instant"), j.current = !1;
723
775
  });
724
776
  } else
725
- requestAnimationFrame(w);
777
+ requestAnimationFrame(y);
726
778
  };
727
- w();
779
+ y();
728
780
  }
729
- }, [O.length, i, n, r]);
730
- const k = ce(() => {
731
- const y = d.current;
732
- if (!y) return;
733
- const w = y.scrollTop, { scrollHeight: C, clientHeight: $ } = y, j = R.current, D = C - (w + $), z = j.isNearBottom;
734
- j.isNearBottom = D <= m, w < j.lastScrollTop ? (j.scrollUpCount++, j.scrollUpCount > 3 && z && (j.isUserScrolling = !0, console.log("User scrolled away from bottom"))) : j.isNearBottom && (j.isUserScrolling = !1, j.scrollUpCount = 0), j.lastScrollTop = w;
735
- let Q = 0;
736
- for (let X = 0; X < O.length; X++) {
737
- const ge = O[X], Se = B.current.get(ge);
738
- if (Se && Se.offset + Se.height > w) {
739
- Q = X;
781
+ }, [L.length, a, n, r]);
782
+ const V = ce(() => {
783
+ const I = w.current;
784
+ if (!I) return;
785
+ const y = I.scrollTop, { scrollHeight: k, clientHeight: C } = I, _ = F.current, q = k - (y + C), H = _.isNearBottom;
786
+ _.isNearBottom = q <= d, y < _.lastScrollTop ? (_.scrollUpCount++, _.scrollUpCount > 3 && H && (_.isUserScrolling = !0, console.log("User scrolled away from bottom"))) : _.isNearBottom && (_.isUserScrolling = !1, _.scrollUpCount = 0), _.lastScrollTop = y;
787
+ let z = 0;
788
+ for (let Z = 0; Z < L.length; Z++) {
789
+ const ue = L[Z], me = O.current.get(ue);
790
+ if (me && me.offset + me.height > y) {
791
+ z = Z;
740
792
  break;
741
793
  }
742
794
  }
743
- if (Q !== I.startIndex) {
744
- const X = Math.ceil($ / n);
795
+ if (z !== m.startIndex) {
796
+ const Z = Math.ceil(C / n);
745
797
  P({
746
- startIndex: Math.max(0, Q - r),
798
+ startIndex: Math.max(0, z - r),
747
799
  endIndex: Math.min(
748
- O.length - 1,
749
- Q + X + r
800
+ L.length - 1,
801
+ z + Z + r
750
802
  )
751
803
  });
752
804
  }
753
805
  }, [
754
- O.length,
755
- I.startIndex,
806
+ L.length,
807
+ m.startIndex,
756
808
  n,
757
809
  r,
758
- m
810
+ d
759
811
  ]);
760
- Y(() => {
761
- const y = d.current;
762
- if (!(!y || !i))
763
- return y.addEventListener("scroll", k, {
812
+ Q(() => {
813
+ const I = w.current;
814
+ if (!(!I || !a))
815
+ return I.addEventListener("scroll", V, {
764
816
  passive: !0
765
817
  }), () => {
766
- y.removeEventListener("scroll", k);
818
+ I.removeEventListener("scroll", V);
767
819
  };
768
- }, [k, i]);
769
- const A = ce(
770
- (y = "smooth") => {
771
- const w = d.current;
772
- if (!w) return;
773
- R.current.isUserScrolling = !1, R.current.isNearBottom = !0, R.current.scrollUpCount = 0;
774
- const C = () => {
775
- const $ = (j = 0) => {
776
- if (j > 5) return;
777
- const D = w.scrollHeight, z = w.scrollTop, Q = w.clientHeight;
778
- z + Q >= D - 1 || (w.scrollTo({
779
- top: D,
780
- behavior: y
820
+ }, [V, a]);
821
+ const E = ce(
822
+ (I = "smooth") => {
823
+ const y = w.current;
824
+ if (!y) return;
825
+ F.current.isUserScrolling = !1, F.current.isNearBottom = !0, F.current.scrollUpCount = 0;
826
+ const k = () => {
827
+ const C = (_ = 0) => {
828
+ if (_ > 5) return;
829
+ const q = y.scrollHeight, H = y.scrollTop, z = y.clientHeight;
830
+ H + z >= q - 1 || (y.scrollTo({
831
+ top: q,
832
+ behavior: I
781
833
  }), setTimeout(() => {
782
- const X = w.scrollHeight, ge = w.scrollTop;
783
- (X !== D || ge + Q < X - 1) && $(j + 1);
834
+ const Z = y.scrollHeight, ue = y.scrollTop;
835
+ (Z !== q || ue + z < Z - 1) && C(_ + 1);
784
836
  }, 50));
785
837
  };
786
- $();
838
+ C();
787
839
  };
788
- "requestIdleCallback" in window ? requestIdleCallback(C, { timeout: 100 }) : requestAnimationFrame(() => {
789
- requestAnimationFrame(C);
840
+ "requestIdleCallback" in window ? requestIdleCallback(k, { timeout: 100 }) : requestAnimationFrame(() => {
841
+ requestAnimationFrame(k);
790
842
  });
791
843
  },
792
844
  []
793
845
  );
794
- return Y(() => {
795
- if (!i || !d.current) return;
796
- const y = d.current, w = R.current;
797
- let C;
798
- const $ = () => {
799
- clearTimeout(C), C = setTimeout(() => {
800
- !w.isUserScrolling && w.isNearBottom && A(
801
- _.current ? "instant" : "smooth"
846
+ return Q(() => {
847
+ if (!a || !w.current) return;
848
+ const I = w.current, y = F.current;
849
+ let k;
850
+ const C = () => {
851
+ clearTimeout(k), k = setTimeout(() => {
852
+ !y.isUserScrolling && y.isNearBottom && E(
853
+ j.current ? "instant" : "smooth"
802
854
  );
803
855
  }, 100);
804
- }, j = new MutationObserver(() => {
805
- w.isUserScrolling || $();
856
+ }, _ = new MutationObserver(() => {
857
+ y.isUserScrolling || C();
806
858
  });
807
- j.observe(y, {
859
+ _.observe(I, {
808
860
  childList: !0,
809
861
  subtree: !0,
810
862
  attributes: !0,
811
863
  attributeFilter: ["style", "class"]
812
864
  // More specific than just 'height'
813
865
  });
814
- const D = (z) => {
815
- z.target instanceof HTMLImageElement && !w.isUserScrolling && $();
866
+ const q = (H) => {
867
+ H.target instanceof HTMLImageElement && !y.isUserScrolling && C();
816
868
  };
817
- return y.addEventListener("load", D, !0), _.current ? setTimeout(() => {
818
- A("instant");
819
- }, 0) : $(), () => {
820
- clearTimeout(C), j.disconnect(), y.removeEventListener("load", D, !0);
869
+ return I.addEventListener("load", q, !0), j.current ? setTimeout(() => {
870
+ E("instant");
871
+ }, 0) : C(), () => {
872
+ clearTimeout(k), _.disconnect(), I.removeEventListener("load", q, !0);
821
873
  };
822
- }, [i, O.length, A]), {
823
- virtualState: de(() => {
824
- const y = t.getState(), w = y.getShadowValue(
874
+ }, [a, L.length, E]), {
875
+ virtualState: ge(() => {
876
+ const I = t.getState(), y = I.getShadowValue(
825
877
  [e, ...o].join(".")
826
- ), C = y.getShadowMetadata(e, o)?.arrayKeys || [], $ = w.slice(
827
- I.startIndex,
828
- I.endIndex + 1
829
- ), j = C.slice(
830
- I.startIndex,
831
- I.endIndex + 1
878
+ ), k = I.getShadowMetadata(e, o)?.arrayKeys || [], C = y.slice(
879
+ m.startIndex,
880
+ m.endIndex + 1
881
+ ), _ = k.slice(
882
+ m.startIndex,
883
+ m.endIndex + 1
832
884
  );
833
- return u({
834
- currentState: $,
885
+ return l({
886
+ currentState: C,
835
887
  path: o,
836
- componentId: M,
837
- meta: { ...S, validIds: j }
888
+ componentId: T,
889
+ meta: { ...S, validIds: _ }
838
890
  });
839
- }, [I.startIndex, I.endIndex, O.length]),
891
+ }, [m.startIndex, m.endIndex, L.length]),
840
892
  virtualizerProps: {
841
893
  outer: {
842
- ref: d,
894
+ ref: w,
843
895
  style: {
844
896
  overflowY: "auto",
845
897
  height: "100%",
@@ -848,855 +900,910 @@ function Pe(e, s, p, g) {
848
900
  },
849
901
  inner: {
850
902
  style: {
851
- height: `${W}px`,
903
+ height: `${N}px`,
852
904
  position: "relative"
853
905
  }
854
906
  },
855
907
  list: {
856
908
  style: {
857
- transform: `translateY(${B.current.get(
858
- O[I.startIndex]
909
+ transform: `translateY(${O.current.get(
910
+ L[m.startIndex]
859
911
  )?.offset || 0}px)`
860
912
  }
861
913
  }
862
914
  },
863
- scrollToBottom: A,
864
- scrollToIndex: (y, w = "smooth") => {
865
- if (d.current && O[y]) {
866
- const C = B.current.get(O[y])?.offset || 0;
867
- d.current.scrollTo({ top: C, behavior: w });
915
+ scrollToBottom: E,
916
+ scrollToIndex: (I, y = "smooth") => {
917
+ if (w.current && L[I]) {
918
+ const k = O.current.get(L[I])?.offset || 0;
919
+ w.current.scrollTo({ top: k, behavior: y });
868
920
  }
869
921
  }
870
922
  };
871
923
  };
872
- if (f === "stateMap")
873
- return (a) => {
874
- const [n, r] = Z(
924
+ if (v === "stateMap")
925
+ return (s) => {
926
+ const [n, r] = X(
875
927
  S?.validIds ?? t.getState().getShadowMetadata(e, o)?.arrayKeys
876
- ), i = t.getState().getShadowValue(N, S?.validIds);
928
+ ), a = t.getState().getShadowValue(c, S?.validIds);
877
929
  if (!n)
878
930
  throw new Error("No array keys found for mapping");
879
- const m = u({
880
- currentState: i,
931
+ const d = l({
932
+ currentState: a,
881
933
  path: o,
882
- componentId: M,
934
+ componentId: T,
883
935
  meta: S
884
936
  });
885
- return i.map((d, I) => {
886
- const P = n[I]?.split(".").slice(1), U = u({
887
- currentState: d,
937
+ return a.map((w, m) => {
938
+ const P = n[m]?.split(".").slice(1), R = l({
939
+ currentState: w,
888
940
  path: P,
889
- componentId: M,
941
+ componentId: T,
890
942
  meta: S
891
943
  });
892
- return a(
893
- U,
894
- I,
895
- m
944
+ return s(
945
+ R,
946
+ m,
947
+ d
896
948
  );
897
949
  });
898
950
  };
899
- if (f === "$stateMap")
900
- return (a) => le(ze, {
951
+ if (v === "$stateMap")
952
+ return (s) => le(Ge, {
901
953
  proxy: {
902
954
  _stateKey: e,
903
955
  _path: o,
904
- _mapFn: a,
956
+ _mapFn: s,
905
957
  _meta: S
906
958
  },
907
- rebuildStateShape: u
959
+ rebuildStateShape: l
908
960
  });
909
- if (f === "stateFilter")
910
- return (a) => {
961
+ if (v === "stateFind")
962
+ return (s) => {
963
+ const n = S?.validIds ?? t.getState().getShadowMetadata(e, o)?.arrayKeys;
964
+ if (n)
965
+ for (let r = 0; r < n.length; r++) {
966
+ const a = n[r];
967
+ if (!a) continue;
968
+ const d = t.getState().getShadowValue(a);
969
+ if (s(d, r)) {
970
+ const w = a.split(".").slice(1);
971
+ return l({
972
+ currentState: d,
973
+ path: w,
974
+ componentId: T,
975
+ meta: S
976
+ // Pass along meta for potential further chaining
977
+ });
978
+ }
979
+ }
980
+ };
981
+ if (v === "stateFilter")
982
+ return (s) => {
911
983
  const n = S?.validIds ?? t.getState().getShadowMetadata(e, o)?.arrayKeys;
912
984
  if (!n)
913
985
  throw new Error("No array keys found for filtering.");
914
- const r = [], i = T.filter(
915
- (m, d) => a(m, d) ? (r.push(n[d]), !0) : !1
986
+ const r = [], a = b.filter(
987
+ (d, w) => s(d, w) ? (r.push(n[w]), !0) : !1
916
988
  );
917
- return u({
918
- currentState: i,
989
+ return l({
990
+ currentState: a,
919
991
  path: o,
920
- componentId: M,
992
+ componentId: T,
921
993
  meta: {
922
994
  validIds: r,
923
995
  transforms: [
924
996
  ...S?.transforms || [],
925
997
  {
926
998
  type: "filter",
927
- fn: a
999
+ fn: s
928
1000
  }
929
1001
  ]
930
1002
  }
931
1003
  });
932
1004
  };
933
- if (f === "stateSort")
934
- return (a) => {
1005
+ if (v === "stateSort")
1006
+ return (s) => {
935
1007
  const n = S?.validIds ?? t.getState().getShadowMetadata(e, o)?.arrayKeys;
936
1008
  if (!n)
937
1009
  throw new Error("No array keys found for sorting");
938
- const r = T.map((i, m) => ({
939
- item: i,
940
- key: n[m]
1010
+ const r = b.map((a, d) => ({
1011
+ item: a,
1012
+ key: n[d]
941
1013
  }));
942
- return r.sort((i, m) => a(i.item, m.item)).filter(Boolean), u({
943
- currentState: r.map((i) => i.item),
1014
+ return r.sort((a, d) => s(a.item, d.item)).filter(Boolean), l({
1015
+ currentState: r.map((a) => a.item),
944
1016
  path: o,
945
- componentId: M,
1017
+ componentId: T,
946
1018
  meta: {
947
- validIds: r.map((i) => i.key),
1019
+ validIds: r.map((a) => a.key),
948
1020
  transforms: [
949
1021
  ...S?.transforms || [],
950
- { type: "sort", fn: a }
1022
+ { type: "sort", fn: s }
951
1023
  ]
952
1024
  }
953
1025
  });
954
1026
  };
955
- if (f === "stream")
956
- return function(a = {}) {
1027
+ if (v === "stream")
1028
+ return function(s = {}) {
957
1029
  const {
958
1030
  bufferSize: n = 100,
959
1031
  flushInterval: r = 100,
960
- bufferStrategy: i = "accumulate",
961
- store: m,
962
- onFlush: d
963
- } = a;
964
- let I = [], P = !1, U = null;
965
- const x = (W) => {
1032
+ bufferStrategy: a = "accumulate",
1033
+ store: d,
1034
+ onFlush: w
1035
+ } = s;
1036
+ let m = [], P = !1, R = null;
1037
+ const D = (N) => {
966
1038
  if (!P) {
967
- if (i === "sliding" && I.length >= n)
968
- I.shift();
969
- else if (i === "dropping" && I.length >= n)
1039
+ if (a === "sliding" && m.length >= n)
1040
+ m.shift();
1041
+ else if (a === "dropping" && m.length >= n)
970
1042
  return;
971
- I.push(W), I.length >= n && _();
1043
+ m.push(N), m.length >= n && j();
972
1044
  }
973
- }, _ = () => {
974
- if (I.length === 0) return;
975
- const W = [...I];
976
- if (I = [], m) {
977
- const b = m(W);
978
- b !== void 0 && (Array.isArray(b) ? b : [b]).forEach((A) => {
979
- s(A, o, {
1045
+ }, j = () => {
1046
+ if (m.length === 0) return;
1047
+ const N = [...m];
1048
+ if (m = [], d) {
1049
+ const B = d(N);
1050
+ B !== void 0 && (Array.isArray(B) ? B : [B]).forEach((E) => {
1051
+ i(E, o, {
980
1052
  updateType: "insert"
981
1053
  });
982
1054
  });
983
1055
  } else
984
- W.forEach((b) => {
985
- s(b, o, {
1056
+ N.forEach((B) => {
1057
+ i(B, o, {
986
1058
  updateType: "insert"
987
1059
  });
988
1060
  });
989
- d?.(W);
1061
+ w?.(N);
990
1062
  };
991
- r > 0 && (U = setInterval(_, r));
992
- const R = ee(), B = t.getState().getShadowMetadata(e, o) || {}, O = B.streams || /* @__PURE__ */ new Map();
993
- return O.set(R, { buffer: I, flushTimer: U }), t.getState().setShadowMetadata(e, o, {
994
- ...B,
995
- streams: O
1063
+ r > 0 && (R = setInterval(j, r));
1064
+ const F = te(), O = t.getState().getShadowMetadata(e, o) || {}, L = O.streams || /* @__PURE__ */ new Map();
1065
+ return L.set(F, { buffer: m, flushTimer: R }), t.getState().setShadowMetadata(e, o, {
1066
+ ...O,
1067
+ streams: L
996
1068
  }), {
997
- write: (W) => x(W),
998
- writeMany: (W) => W.forEach(x),
999
- flush: () => _(),
1069
+ write: (N) => D(N),
1070
+ writeMany: (N) => N.forEach(D),
1071
+ flush: () => j(),
1000
1072
  pause: () => {
1001
1073
  P = !0;
1002
1074
  },
1003
1075
  resume: () => {
1004
- P = !1, I.length > 0 && _();
1076
+ P = !1, m.length > 0 && j();
1005
1077
  },
1006
1078
  close: () => {
1007
- _(), U && clearInterval(U);
1008
- const W = t.getState().getShadowMetadata(e, o);
1009
- W?.streams && W.streams.delete(R);
1079
+ j(), R && clearInterval(R);
1080
+ const N = t.getState().getShadowMetadata(e, o);
1081
+ N?.streams && N.streams.delete(F);
1010
1082
  }
1011
1083
  };
1012
1084
  };
1013
- if (f === "stateList")
1014
- return (a) => /* @__PURE__ */ ae(() => {
1015
- const r = q(/* @__PURE__ */ new Map()), i = S?.transforms && S.transforms.length > 0 ? `${M}-${qe(S.transforms)}` : `${M}-base`, [m, d] = Z({}), { validIds: I, arrayValues: P } = de(() => {
1016
- const x = t.getState().getShadowMetadata(e, o)?.transformCaches?.get(i);
1017
- let _;
1018
- x && x.validIds ? _ = x.validIds : (_ = ve(
1085
+ if (v === "stateList")
1086
+ return (s) => /* @__PURE__ */ re(() => {
1087
+ const r = G(/* @__PURE__ */ new Map()), a = S?.transforms && S.transforms.length > 0 ? `${T}-${qe(S.transforms)}` : `${T}-base`, [d, w] = X({}), { validIds: m, arrayValues: P } = ge(() => {
1088
+ const D = t.getState().getShadowMetadata(e, o)?.transformCaches?.get(a);
1089
+ let j;
1090
+ D && D.validIds ? j = D.validIds : (j = Ie(
1019
1091
  e,
1020
1092
  o,
1021
1093
  S?.transforms
1022
- ), t.getState().setTransformCache(e, o, i, {
1023
- validIds: _,
1094
+ ), t.getState().setTransformCache(e, o, a, {
1095
+ validIds: j,
1024
1096
  computedAt: Date.now(),
1025
1097
  transforms: S?.transforms || []
1026
1098
  }));
1027
- const R = t.getState().getShadowValue(N, _);
1099
+ const F = t.getState().getShadowValue(c, j);
1028
1100
  return {
1029
- validIds: _,
1030
- arrayValues: R || []
1101
+ validIds: j,
1102
+ arrayValues: F || []
1031
1103
  };
1032
- }, [i, m]);
1033
- if (Y(() => {
1034
- const x = t.getState().subscribeToPath(N, (_) => {
1035
- if (console.log("statelsit subscribed to path", _), _.type === "GET_SELECTED")
1104
+ }, [a, d]);
1105
+ if (console.log("freshValues", m, P), Q(() => {
1106
+ const D = t.getState().subscribeToPath(c, (j) => {
1107
+ if (j.type === "GET_SELECTED")
1036
1108
  return;
1037
- const B = t.getState().getShadowMetadata(e, o)?.transformCaches;
1038
- if (B)
1039
- for (const O of B.keys())
1040
- O.startsWith(M) && B.delete(O);
1041
- _.type === "INSERT" && d({});
1109
+ const O = t.getState().getShadowMetadata(e, o)?.transformCaches;
1110
+ if (O)
1111
+ for (const L of O.keys())
1112
+ L.startsWith(T) && O.delete(L);
1113
+ (j.type === "INSERT" || j.type === "REMOVE" || j.type === "CLEAR_SELECTION") && (console.log("sssssssssssssssssssssssssssss", j), w({}));
1042
1114
  });
1043
1115
  return () => {
1044
- x();
1116
+ D();
1045
1117
  };
1046
- }, [M, N]), !Array.isArray(P))
1118
+ }, [T, c]), !Array.isArray(P))
1047
1119
  return null;
1048
- const U = u({
1120
+ const R = l({
1049
1121
  currentState: P,
1050
1122
  path: o,
1051
- componentId: M,
1123
+ componentId: T,
1052
1124
  meta: {
1053
1125
  ...S,
1054
- validIds: I
1126
+ validIds: m
1055
1127
  }
1056
1128
  });
1057
- return /* @__PURE__ */ ae(ke, { children: P.map((x, _) => {
1058
- const R = I[_];
1059
- if (!R)
1129
+ return console.log("sssssssssssssssssssssssssssss", R), /* @__PURE__ */ re(ke, { children: P.map((D, j) => {
1130
+ const F = m[j];
1131
+ if (!F)
1060
1132
  return null;
1061
- let B = r.current.get(R);
1062
- B || (B = ee(), r.current.set(R, B));
1063
- const O = R.split(".").slice(1);
1064
- return le(we, {
1065
- key: R,
1133
+ let O = r.current.get(F);
1134
+ O || (O = te(), r.current.set(F, O));
1135
+ const L = F.split(".").slice(1);
1136
+ return le(Me, {
1137
+ key: F,
1066
1138
  stateKey: e,
1067
- itemComponentId: B,
1068
- itemPath: O,
1069
- localIndex: _,
1070
- arraySetter: U,
1071
- rebuildStateShape: u,
1072
- renderFn: a
1139
+ itemComponentId: O,
1140
+ itemPath: L,
1141
+ localIndex: j,
1142
+ arraySetter: R,
1143
+ rebuildStateShape: l,
1144
+ renderFn: s
1073
1145
  });
1074
1146
  }) });
1075
1147
  }, {});
1076
- if (f === "stateFlattenOn")
1077
- return (a) => {
1078
- const n = T;
1079
- v.clear(), h++;
1148
+ if (v === "stateFlattenOn")
1149
+ return (s) => {
1150
+ const n = b;
1151
+ h.clear(), p++;
1080
1152
  const r = n.flatMap(
1081
- (i) => i[a] ?? []
1153
+ (a) => a[s] ?? []
1082
1154
  );
1083
- return u({
1155
+ return l({
1084
1156
  currentState: r,
1085
- path: [...o, "[*]", a],
1086
- componentId: M,
1157
+ path: [...o, "[*]", s],
1158
+ componentId: T,
1087
1159
  meta: S
1088
1160
  });
1089
1161
  };
1090
- if (f === "index")
1091
- return (a) => {
1162
+ if (v === "index")
1163
+ return (s) => {
1092
1164
  const r = t.getState().getShadowMetadata(e, o)?.arrayKeys?.filter(
1093
- (d) => !S?.validIds || S?.validIds && S?.validIds?.includes(d)
1094
- )?.[a];
1165
+ (w) => !S?.validIds || S?.validIds && S?.validIds?.includes(w)
1166
+ )?.[s];
1095
1167
  if (!r) return;
1096
- const i = t.getState().getShadowValue(r, S?.validIds);
1097
- return u({
1098
- currentState: i,
1168
+ const a = t.getState().getShadowValue(r, S?.validIds);
1169
+ return l({
1170
+ currentState: a,
1099
1171
  path: r.split(".").slice(1),
1100
- componentId: M,
1172
+ componentId: T,
1101
1173
  meta: S
1102
1174
  });
1103
1175
  };
1104
- if (f === "last")
1176
+ if (v === "last")
1105
1177
  return () => {
1106
- const a = t.getState().getShadowValue(e, o);
1107
- if (a.length === 0) return;
1108
- const n = a.length - 1, r = a[n], i = [...o, n.toString()];
1109
- return u({
1178
+ const s = t.getState().getShadowValue(e, o);
1179
+ if (s.length === 0) return;
1180
+ const n = s.length - 1, r = s[n], a = [...o, n.toString()];
1181
+ return l({
1110
1182
  currentState: r,
1111
- path: i,
1112
- componentId: M,
1183
+ path: a,
1184
+ componentId: T,
1113
1185
  meta: S
1114
1186
  });
1115
1187
  };
1116
- if (f === "insert")
1117
- return (a, n) => (s(a, o, { updateType: "insert" }), u({
1188
+ if (v === "insert")
1189
+ return (s, n) => (i(s, o, { updateType: "insert" }), l({
1118
1190
  currentState: t.getState().getShadowValue(e, o),
1119
1191
  path: o,
1120
- componentId: M,
1192
+ componentId: T,
1121
1193
  meta: S
1122
1194
  }));
1123
- if (f === "uniqueInsert")
1124
- return (a, n, r) => {
1125
- const i = t.getState().getShadowValue(e, o), m = K(a) ? a(i) : a;
1126
- let d = null;
1127
- if (!i.some((P) => {
1128
- const U = n ? n.every(
1129
- (x) => ie(P[x], m[x])
1130
- ) : ie(P, m);
1131
- return U && (d = P), U;
1195
+ if (v === "uniqueInsert")
1196
+ return (s, n, r) => {
1197
+ const a = t.getState().getShadowValue(e, o), d = ee(s) ? s(a) : s;
1198
+ let w = null;
1199
+ if (!a.some((P) => {
1200
+ const R = n ? n.every(
1201
+ (D) => se(P[D], d[D])
1202
+ ) : se(P, d);
1203
+ return R && (w = P), R;
1132
1204
  }))
1133
- V(o), s(m, o, { updateType: "insert" });
1134
- else if (r && d) {
1135
- const P = r(d), U = i.map(
1136
- (x) => ie(x, d) ? P : x
1205
+ M(o), i(d, o, { updateType: "insert" });
1206
+ else if (r && w) {
1207
+ const P = r(w), R = a.map(
1208
+ (D) => se(D, w) ? P : D
1137
1209
  );
1138
- V(o), s(U, o, {
1210
+ M(o), i(R, o, {
1139
1211
  updateType: "update"
1140
1212
  });
1141
1213
  }
1142
1214
  };
1143
- if (f === "cut")
1144
- return (a, n) => {
1215
+ if (v === "cut")
1216
+ return (s, n) => {
1145
1217
  const r = S?.validIds ?? t.getState().getShadowMetadata(e, o)?.arrayKeys;
1146
1218
  if (!r || r.length === 0) return;
1147
- const i = a == -1 ? r.length - 1 : a !== void 0 ? a : r.length - 1, m = r[i];
1148
- if (!m) return;
1149
- const d = m.split(".").slice(1);
1150
- s(T, d, {
1219
+ const a = s == -1 ? r.length - 1 : s !== void 0 ? s : r.length - 1, d = r[a];
1220
+ if (!d) return;
1221
+ const w = d.split(".").slice(1);
1222
+ i(b, w, {
1151
1223
  updateType: "cut"
1152
1224
  });
1153
1225
  };
1154
- if (f === "cutSelected")
1226
+ if (v === "cutSelected")
1155
1227
  return () => {
1156
1228
  t.getState().getShadowMetadata(e, o)?.arrayKeys;
1157
- const a = ve(
1229
+ const s = Ie(
1158
1230
  e,
1159
1231
  o,
1160
1232
  S?.transforms
1161
1233
  );
1162
- if (console.log("validKeys", a), !a || a.length === 0) return;
1163
- const n = t.getState().selectedIndicesMap.get(N);
1164
- let r = a.findIndex(
1165
- (m) => m === n
1234
+ if (console.log("validKeys", s), !s || s.length === 0) return;
1235
+ const n = t.getState().selectedIndicesMap.get(c);
1236
+ let r = s.findIndex(
1237
+ (d) => d === n
1166
1238
  );
1167
1239
  console.log("indexToCut", r);
1168
- const i = a[r == -1 ? a.length - 1 : r]?.split(".").slice(1);
1169
- console.log("pathForCut", i), s(T, i, {
1240
+ const a = s[r == -1 ? s.length - 1 : r]?.split(".").slice(1);
1241
+ console.log("pathForCut", a), i(b, a, {
1170
1242
  updateType: "cut"
1171
1243
  });
1172
1244
  };
1173
- if (f === "cutByValue")
1174
- return (a) => {
1245
+ if (v === "cutByValue")
1246
+ return (s) => {
1175
1247
  const n = t.getState().getShadowMetadata(e, o), r = S?.validIds ?? n?.arrayKeys;
1176
1248
  if (!r) return;
1177
- let i = null;
1178
- for (const m of r)
1179
- if (t.getState().getShadowValue(m) === a) {
1180
- i = m;
1249
+ let a = null;
1250
+ for (const d of r)
1251
+ if (t.getState().getShadowValue(d) === s) {
1252
+ a = d;
1181
1253
  break;
1182
1254
  }
1183
- if (i) {
1184
- const m = i.split(".").slice(1);
1185
- s(null, m, { updateType: "cut" });
1255
+ if (a) {
1256
+ const d = a.split(".").slice(1);
1257
+ i(null, d, { updateType: "cut" });
1186
1258
  }
1187
1259
  };
1188
- if (f === "toggleByValue")
1189
- return (a) => {
1260
+ if (v === "toggleByValue")
1261
+ return (s) => {
1190
1262
  const n = t.getState().getShadowMetadata(e, o), r = S?.validIds ?? n?.arrayKeys;
1191
1263
  if (!r) return;
1192
- let i = null;
1193
- for (const m of r) {
1194
- const d = t.getState().getShadowValue(m);
1195
- if (console.log("itemValue sdasdasdasd", d), d === a) {
1196
- i = m;
1264
+ let a = null;
1265
+ for (const d of r) {
1266
+ const w = t.getState().getShadowValue(d);
1267
+ if (console.log("itemValue sdasdasdasd", w), w === s) {
1268
+ a = d;
1197
1269
  break;
1198
1270
  }
1199
1271
  }
1200
- if (console.log("itemValue keyToCut", i), i) {
1201
- const m = i.split(".").slice(1);
1202
- console.log("itemValue keyToCut", i), s(a, m, {
1272
+ if (console.log("itemValue keyToCut", a), a) {
1273
+ const d = a.split(".").slice(1);
1274
+ console.log("itemValue keyToCut", a), i(s, d, {
1203
1275
  updateType: "cut"
1204
1276
  });
1205
1277
  } else
1206
- s(a, o, { updateType: "insert" });
1278
+ i(s, o, { updateType: "insert" });
1207
1279
  };
1208
- if (f === "findWith")
1209
- return (a, n) => {
1280
+ if (v === "findWith")
1281
+ return (s, n) => {
1210
1282
  const r = t.getState().getShadowMetadata(e, o)?.arrayKeys;
1211
1283
  if (!r)
1212
1284
  throw new Error("No array keys found for sorting");
1213
- let i = null, m = [];
1214
- for (const d of r) {
1215
- let I = t.getState().getShadowValue(d, S?.validIds);
1216
- if (I && I[a] === n) {
1217
- i = I, m = d.split(".").slice(1);
1285
+ let a = null, d = [];
1286
+ for (const w of r) {
1287
+ let m = t.getState().getShadowValue(w, S?.validIds);
1288
+ if (m && m[s] === n) {
1289
+ a = m, d = w.split(".").slice(1);
1218
1290
  break;
1219
1291
  }
1220
1292
  }
1221
- return u({
1222
- currentState: i,
1223
- path: m,
1224
- componentId: M,
1293
+ return l({
1294
+ currentState: a,
1295
+ path: d,
1296
+ componentId: T,
1225
1297
  meta: S
1226
1298
  });
1227
1299
  };
1228
1300
  }
1229
- if (f === "cut") {
1230
- let a = t.getState().getShadowValue(o.join("."));
1301
+ if (v === "cut") {
1302
+ let s = t.getState().getShadowValue(o.join("."));
1231
1303
  return () => {
1232
- s(a, o, { updateType: "cut" });
1304
+ i(s, o, { updateType: "cut" });
1233
1305
  };
1234
1306
  }
1235
- if (f === "get")
1236
- return () => (Ee(e, M, o), t.getState().getShadowValue(N, S?.validIds));
1237
- if (f === "$derive")
1238
- return (a) => be({
1307
+ if (v === "get")
1308
+ return () => (Ve(e, T, o), t.getState().getShadowValue(c, S?.validIds));
1309
+ if (v === "$derive")
1310
+ return (s) => Ae({
1239
1311
  _stateKey: e,
1240
1312
  _path: o,
1241
- _effect: a.toString(),
1313
+ _effect: s.toString(),
1242
1314
  _meta: S
1243
1315
  });
1244
- if (f === "$get")
1245
- return () => be({ _stateKey: e, _path: o, _meta: S });
1246
- if (f === "lastSynced") {
1247
- const a = `${e}:${o.join(".")}`;
1248
- return t.getState().getSyncInfo(a);
1316
+ if (v === "$get")
1317
+ return () => Ae({ _stateKey: e, _path: o, _meta: S });
1318
+ if (v === "lastSynced") {
1319
+ const s = `${e}:${o.join(".")}`;
1320
+ return t.getState().getSyncInfo(s);
1249
1321
  }
1250
- if (f == "getLocalStorage")
1251
- return (a) => fe(g + "-" + e + "-" + a);
1252
- if (f === "isSelected") {
1253
- const a = [e, ...o].slice(0, -1);
1254
- if (he(e, o, void 0), Array.isArray(
1255
- t.getState().getShadowValue(a.join("."), S?.validIds)
1322
+ if (v == "getLocalStorage")
1323
+ return (s) => Se(g + "-" + e + "-" + s);
1324
+ if (v === "isSelected") {
1325
+ const s = [e, ...o].slice(0, -1);
1326
+ if (ye(e, o, void 0), Array.isArray(
1327
+ t.getState().getShadowValue(s.join("."), S?.validIds)
1256
1328
  )) {
1257
1329
  o[o.length - 1];
1258
- const n = a.join("."), r = t.getState().selectedIndicesMap.get(n), i = e + "." + o.join(".");
1259
- return r === i;
1330
+ const n = s.join("."), r = t.getState().selectedIndicesMap.get(n), a = e + "." + o.join(".");
1331
+ return r === a;
1260
1332
  }
1261
1333
  return;
1262
1334
  }
1263
- if (f === "setSelected")
1264
- return (a) => {
1265
- const n = o.slice(0, -1), r = e + "." + n.join("."), i = e + "." + o.join(".");
1266
- he(e, n, void 0), t.getState().selectedIndicesMap.get(r), a && t.getState().setSelectedIndex(r, i);
1335
+ if (v === "setSelected")
1336
+ return (s) => {
1337
+ const n = o.slice(0, -1), r = e + "." + n.join("."), a = e + "." + o.join(".");
1338
+ ye(e, n, void 0), t.getState().selectedIndicesMap.get(r), s && t.getState().setSelectedIndex(r, a);
1267
1339
  };
1268
- if (f === "toggleSelected")
1340
+ if (v === "toggleSelected")
1269
1341
  return () => {
1270
- const a = o.slice(0, -1), n = e + "." + a.join("."), r = e + "." + o.join(".");
1342
+ const s = o.slice(0, -1), n = e + "." + s.join("."), r = e + "." + o.join(".");
1271
1343
  t.getState().selectedIndicesMap.get(n) === r ? t.getState().clearSelectedIndex({ arrayKey: n }) : t.getState().setSelectedIndex(n, r);
1272
1344
  };
1273
- if (f === "_componentId")
1274
- return M;
1345
+ if (v === "_componentId")
1346
+ return T;
1275
1347
  if (o.length == 0) {
1276
- if (f === "addValidation")
1277
- return (a) => {
1348
+ if (v === "addValidation")
1349
+ return (s) => {
1278
1350
  const n = t.getState().getInitialOptions(e)?.validation;
1279
1351
  if (!n?.key) throw new Error("Validation key not found");
1280
- ne(n.key), a.forEach((r) => {
1281
- const i = [n.key, ...r.path].join(".");
1282
- pe(i, r.message);
1283
- }), re(e);
1352
+ ne(n.key), s.forEach((r) => {
1353
+ const a = [n.key, ...r.path].join(".");
1354
+ ve(a, r.message);
1355
+ }), ie(e);
1284
1356
  };
1285
- if (f === "applyJsonPatch")
1286
- return (a) => {
1287
- const n = t.getState().getShadowValue(N, S?.validIds);
1288
- Le(n, a).newDocument, re(e);
1357
+ if (v === "applyJsonPatch")
1358
+ return (s) => {
1359
+ const n = t.getState(), r = (a) => !a || a === "/" ? [] : a.split("/").slice(1).map((d) => d.replace(/~1/g, "/").replace(/~0/g, "~"));
1360
+ for (const a of s) {
1361
+ const d = r(a.path);
1362
+ switch (a.op) {
1363
+ case "add":
1364
+ case "replace": {
1365
+ const { value: w } = a;
1366
+ n.updateShadowAtPath(e, d, w), n.markAsDirty(e, d, { bubble: !0 });
1367
+ break;
1368
+ }
1369
+ case "remove": {
1370
+ n.removeShadowArrayElement(e, d);
1371
+ const w = d.slice(0, -1);
1372
+ n.markAsDirty(e, w, { bubble: !0 });
1373
+ break;
1374
+ }
1375
+ }
1376
+ }
1289
1377
  };
1290
- if (f === "validateZodSchema")
1378
+ if (v === "validateZodSchema")
1291
1379
  return () => {
1292
- const a = t.getState().getInitialOptions(e)?.validation;
1293
- if (!a?.zodSchema || !a?.key)
1380
+ const s = t.getState().getInitialOptions(e)?.validation;
1381
+ if (!s?.zodSchema || !s?.key)
1294
1382
  throw new Error("Zod schema or validation key not found");
1295
- ne(a.key);
1296
- const n = t.getState().getShadowValue(e), r = a.zodSchema.safeParse(n);
1297
- return r.success ? !0 : (r.error.errors.forEach((i) => {
1298
- const m = [a.key, ...i.path].join(".");
1299
- pe(m, i.message);
1300
- }), re(e), !1);
1383
+ ne(s.key);
1384
+ const n = t.getState().getShadowValue(e), r = s.zodSchema.safeParse(n);
1385
+ return r.success ? !0 : (r.error.errors.forEach((a) => {
1386
+ const d = [s.key, ...a.path].join(".");
1387
+ ve(d, a.message);
1388
+ }), ie(e), !1);
1301
1389
  };
1302
- if (f === "getComponents")
1390
+ if (v === "getComponents")
1303
1391
  return () => t.getState().getShadowMetadata(e, [])?.components;
1304
- if (f === "getAllFormRefs")
1305
- return () => ye.getState().getFormRefsByStateKey(e);
1392
+ if (v === "getAllFormRefs")
1393
+ return () => pe.getState().getFormRefsByStateKey(e);
1306
1394
  }
1307
- if (f === "getFormRef")
1308
- return () => ye.getState().getFormRef(e + "." + o.join("."));
1309
- if (f === "validationWrapper")
1395
+ if (v === "getFormRef")
1396
+ return () => pe.getState().getFormRef(e + "." + o.join("."));
1397
+ if (v === "validationWrapper")
1310
1398
  return ({
1311
- children: a,
1399
+ children: s,
1312
1400
  hideMessage: n
1313
- }) => /* @__PURE__ */ ae(
1314
- Me,
1401
+ }) => /* @__PURE__ */ re(
1402
+ be,
1315
1403
  {
1316
1404
  formOpts: n ? { validation: { message: "" } } : void 0,
1317
1405
  path: o,
1318
1406
  stateKey: e,
1319
- children: a
1407
+ children: s
1320
1408
  }
1321
1409
  );
1322
- if (f === "_stateKey") return e;
1323
- if (f === "_path") return o;
1324
- if (f === "update")
1325
- return (a) => {
1326
- s(a, o, { updateType: "update" });
1327
- };
1328
- if (f === "toggle") {
1329
- const a = t.getState().getShadowValue([e, ...o].join("."));
1330
- if (console.log("currentValueAtPath", a), typeof T != "boolean")
1410
+ if (v === "_stateKey") return e;
1411
+ if (v === "_path") return o;
1412
+ if (v === "update")
1413
+ return (s) => (i(s, o, { updateType: "update" }), {
1414
+ /**
1415
+ * Marks this specific item, which was just updated, as 'synced' (not dirty).
1416
+ */
1417
+ synced: () => {
1418
+ const n = t.getState().getShadowMetadata(e, o);
1419
+ t.getState().setShadowMetadata(e, o, {
1420
+ ...n,
1421
+ isDirty: !1,
1422
+ // EXPLICITLY set to false, not just undefined
1423
+ stateSource: "server",
1424
+ // Mark as coming from server
1425
+ lastServerSync: Date.now()
1426
+ // Add timestamp
1427
+ });
1428
+ const r = [e, ...o].join(".");
1429
+ t.getState().notifyPathSubscribers(r, {
1430
+ type: "SYNC_STATUS_CHANGE",
1431
+ isDirty: !1
1432
+ });
1433
+ }
1434
+ });
1435
+ if (v === "toggle") {
1436
+ const s = t.getState().getShadowValue([e, ...o].join("."));
1437
+ if (console.log("currentValueAtPath", s), typeof b != "boolean")
1331
1438
  throw new Error("toggle() can only be used on boolean values");
1332
1439
  return () => {
1333
- s(!a, o, {
1440
+ i(!s, o, {
1334
1441
  updateType: "update"
1335
1442
  });
1336
1443
  };
1337
1444
  }
1338
- if (f === "formElement")
1339
- return (a, n) => /* @__PURE__ */ ae(
1340
- Me,
1445
+ if (v === "formElement")
1446
+ return (s, n) => /* @__PURE__ */ re(
1447
+ be,
1341
1448
  {
1342
1449
  formOpts: n,
1343
1450
  path: o,
1344
1451
  stateKey: e,
1345
- children: /* @__PURE__ */ ae(
1452
+ children: /* @__PURE__ */ re(
1346
1453
  Ze,
1347
1454
  {
1348
1455
  stateKey: e,
1349
1456
  path: o,
1350
- rebuildStateShape: u,
1351
- setState: s,
1457
+ rebuildStateShape: l,
1458
+ setState: i,
1352
1459
  formOpts: n,
1353
- renderFn: a
1460
+ renderFn: s
1354
1461
  }
1355
1462
  )
1356
1463
  }
1357
1464
  );
1358
- const se = [...o, f], Ie = t.getState().getShadowValue(e, se);
1359
- return u({
1360
- currentState: Ie,
1361
- path: se,
1362
- componentId: M,
1465
+ const oe = [...o, v], fe = t.getState().getShadowValue(e, oe);
1466
+ return l({
1467
+ currentState: fe,
1468
+ path: oe,
1469
+ componentId: T,
1363
1470
  meta: S
1364
1471
  });
1365
1472
  }
1366
- }, G = new Proxy(c, J);
1367
- return v.set(L, {
1368
- proxy: G,
1369
- stateVersion: h
1370
- }), G;
1473
+ }, J = new Proxy(x, Y);
1474
+ return h.set(W, {
1475
+ proxy: J,
1476
+ stateVersion: p
1477
+ }), J;
1371
1478
  }
1372
- const l = {
1373
- removeValidation: (T) => {
1374
- T?.validationKey && ne(T.validationKey);
1479
+ const u = {
1480
+ removeValidation: (b) => {
1481
+ b?.validationKey && ne(b.validationKey);
1375
1482
  },
1376
- revertToInitialState: (T) => {
1483
+ revertToInitialState: (b) => {
1377
1484
  const o = t.getState().getInitialOptions(e)?.validation;
1378
- o?.key && ne(o.key), T?.validationKey && ne(T.validationKey);
1485
+ o?.key && ne(o.key), b?.validationKey && ne(b.validationKey);
1379
1486
  const S = t.getState().getShadowMetadata(e, []);
1380
1487
  S?.stateSource === "server" && S.baseServerState ? S.baseServerState : t.getState().initialStateGlobal[e];
1381
- const M = t.getState().initialStateGlobal[e];
1382
- t.getState().clearSelectedIndexesForState(e), v.clear(), h++, t.getState().initializeShadowState(e, M), u({
1383
- currentState: M,
1488
+ const T = t.getState().initialStateGlobal[e];
1489
+ t.getState().clearSelectedIndexesForState(e), h.clear(), p++, t.getState().initializeShadowState(e, T), l({
1490
+ currentState: T,
1384
1491
  path: [],
1385
- componentId: p
1492
+ componentId: f
1386
1493
  });
1387
- const L = te(e), N = K(L?.localStorage?.key) ? L?.localStorage?.key(M) : L?.localStorage?.key, c = `${g}-${e}-${N}`;
1388
- c && localStorage.removeItem(c);
1389
- const J = t.getState().getShadowMetadata(e, []);
1390
- return J && J?.components?.forEach((G) => {
1391
- G.forceUpdate();
1392
- }), M;
1494
+ const W = ae(e), c = ee(W?.localStorage?.key) ? W?.localStorage?.key(T) : W?.localStorage?.key, x = `${g}-${e}-${c}`;
1495
+ x && localStorage.removeItem(x);
1496
+ const Y = t.getState().getShadowMetadata(e, []);
1497
+ return Y && Y?.components?.forEach((J) => {
1498
+ J.forceUpdate();
1499
+ }), T;
1393
1500
  },
1394
- updateInitialState: (T) => {
1395
- v.clear(), h++;
1396
- const o = Pe(
1501
+ updateInitialState: (b) => {
1502
+ h.clear(), p++;
1503
+ const o = De(
1397
1504
  e,
1398
- s,
1399
- p,
1505
+ i,
1506
+ f,
1400
1507
  g
1401
- ), S = t.getState().initialStateGlobal[e], M = te(e), L = K(M?.localStorage?.key) ? M?.localStorage?.key(S) : M?.localStorage?.key, N = `${g}-${e}-${L}`;
1402
- return localStorage.getItem(N) && localStorage.removeItem(N), je(() => {
1403
- _e(e, T), t.getState().initializeShadowState(e, T);
1404
- const c = t.getState().getShadowMetadata(e, []);
1405
- c && c?.components?.forEach((J) => {
1406
- J.forceUpdate();
1508
+ ), S = t.getState().initialStateGlobal[e], T = ae(e), W = ee(T?.localStorage?.key) ? T?.localStorage?.key(S) : T?.localStorage?.key, c = `${g}-${e}-${W}`;
1509
+ return localStorage.getItem(c) && localStorage.removeItem(c), je(() => {
1510
+ $e(e, b), t.getState().initializeShadowState(e, b);
1511
+ const x = t.getState().getShadowMetadata(e, []);
1512
+ x && x?.components?.forEach((Y) => {
1513
+ Y.forceUpdate();
1407
1514
  });
1408
1515
  }), {
1409
- fetchId: (c) => o.get()[c]
1516
+ fetchId: (x) => o.get()[x]
1410
1517
  };
1411
1518
  }
1412
1519
  };
1413
- return u({
1520
+ return l({
1414
1521
  currentState: t.getState().getShadowValue(e, []),
1415
- componentId: p,
1522
+ componentId: f,
1416
1523
  path: []
1417
1524
  });
1418
1525
  }
1419
- function be(e) {
1420
- return le(Ge, { proxy: e });
1526
+ function Ae(e) {
1527
+ return le(ze, { proxy: e });
1421
1528
  }
1422
- function ze({
1529
+ function Ge({
1423
1530
  proxy: e,
1424
- rebuildStateShape: s
1531
+ rebuildStateShape: i
1425
1532
  }) {
1426
- const p = q(null), g = q(`map-${crypto.randomUUID()}`), v = q(!1), h = q(/* @__PURE__ */ new Map());
1427
- Y(() => {
1428
- const u = p.current;
1429
- if (!u || v.current) return;
1430
- const l = setTimeout(() => {
1431
- const E = t.getState().getShadowMetadata(e._stateKey, e._path) || {}, T = E.mapWrappers || [];
1432
- T.push({
1533
+ const f = G(null), g = G(`map-${crypto.randomUUID()}`), h = G(!1), p = G(/* @__PURE__ */ new Map());
1534
+ Q(() => {
1535
+ const l = f.current;
1536
+ if (!l || h.current) return;
1537
+ const u = setTimeout(() => {
1538
+ const A = t.getState().getShadowMetadata(e._stateKey, e._path) || {}, b = A.mapWrappers || [];
1539
+ b.push({
1433
1540
  instanceId: g.current,
1434
1541
  mapFn: e._mapFn,
1435
- containerRef: u,
1436
- rebuildStateShape: s,
1542
+ containerRef: l,
1543
+ rebuildStateShape: i,
1437
1544
  path: e._path,
1438
1545
  componentId: g.current,
1439
1546
  meta: e._meta
1440
1547
  }), t.getState().setShadowMetadata(e._stateKey, e._path, {
1441
- ...E,
1442
- mapWrappers: T
1443
- }), v.current = !0, V();
1548
+ ...A,
1549
+ mapWrappers: b
1550
+ }), h.current = !0, M();
1444
1551
  }, 0);
1445
1552
  return () => {
1446
- if (clearTimeout(l), g.current) {
1447
- const E = t.getState().getShadowMetadata(e._stateKey, e._path) || {};
1448
- E.mapWrappers && (E.mapWrappers = E.mapWrappers.filter(
1449
- (T) => T.instanceId !== g.current
1450
- ), t.getState().setShadowMetadata(e._stateKey, e._path, E));
1553
+ if (clearTimeout(u), g.current) {
1554
+ const A = t.getState().getShadowMetadata(e._stateKey, e._path) || {};
1555
+ A.mapWrappers && (A.mapWrappers = A.mapWrappers.filter(
1556
+ (b) => b.instanceId !== g.current
1557
+ ), t.getState().setShadowMetadata(e._stateKey, e._path, A));
1451
1558
  }
1452
- h.current.forEach((E) => E.unmount());
1559
+ p.current.forEach((A) => A.unmount());
1453
1560
  };
1454
1561
  }, []);
1455
- const V = () => {
1456
- const u = p.current;
1457
- if (!u) return;
1458
- const l = t.getState().getShadowValue(
1562
+ const M = () => {
1563
+ const l = f.current;
1564
+ if (!l) return;
1565
+ const u = t.getState().getShadowValue(
1459
1566
  [e._stateKey, ...e._path].join("."),
1460
1567
  e._meta?.validIds
1461
1568
  );
1462
- if (!Array.isArray(l)) return;
1463
- const E = e._meta?.validIds ?? t.getState().getShadowMetadata(e._stateKey, e._path)?.arrayKeys ?? [], T = s({
1464
- currentState: l,
1569
+ if (!Array.isArray(u)) return;
1570
+ const A = e._meta?.validIds ?? t.getState().getShadowMetadata(e._stateKey, e._path)?.arrayKeys ?? [], b = i({
1571
+ currentState: u,
1465
1572
  path: e._path,
1466
1573
  componentId: g.current,
1467
1574
  meta: e._meta
1468
1575
  });
1469
- l.forEach((o, S) => {
1470
- const M = E[S];
1471
- if (!M) return;
1472
- const L = ee(), N = document.createElement("div");
1473
- N.setAttribute("data-item-path", M), u.appendChild(N);
1474
- const c = Ce(N);
1475
- h.current.set(M, c);
1476
- const J = M.split(".").slice(1);
1477
- c.render(
1478
- le(we, {
1576
+ u.forEach((o, S) => {
1577
+ const T = A[S];
1578
+ if (!T) return;
1579
+ const W = te(), c = document.createElement("div");
1580
+ c.setAttribute("data-item-path", T), l.appendChild(c);
1581
+ const x = Ce(c);
1582
+ p.current.set(T, x);
1583
+ const Y = T.split(".").slice(1);
1584
+ x.render(
1585
+ le(Me, {
1479
1586
  stateKey: e._stateKey,
1480
- itemComponentId: L,
1481
- itemPath: J,
1587
+ itemComponentId: W,
1588
+ itemPath: Y,
1482
1589
  localIndex: S,
1483
- arraySetter: T,
1484
- rebuildStateShape: s,
1590
+ arraySetter: b,
1591
+ rebuildStateShape: i,
1485
1592
  renderFn: e._mapFn
1486
1593
  })
1487
1594
  );
1488
1595
  });
1489
1596
  };
1490
- return /* @__PURE__ */ ae("div", { ref: p, "data-map-container": g.current });
1597
+ return /* @__PURE__ */ re("div", { ref: f, "data-map-container": g.current });
1491
1598
  }
1492
- function Ge({
1599
+ function ze({
1493
1600
  proxy: e
1494
1601
  }) {
1495
- const s = q(null), p = q(null), g = q(!1), v = `${e._stateKey}-${e._path.join(".")}`, h = t.getState().getShadowValue(
1602
+ const i = G(null), f = G(null), g = G(!1), h = `${e._stateKey}-${e._path.join(".")}`, p = t.getState().getShadowValue(
1496
1603
  [e._stateKey, ...e._path].join("."),
1497
1604
  e._meta?.validIds
1498
1605
  );
1499
- return Y(() => {
1500
- const V = s.current;
1501
- if (!V || g.current) return;
1502
- const u = setTimeout(() => {
1503
- if (!V.parentElement) {
1504
- console.warn("Parent element not found for signal", v);
1606
+ return Q(() => {
1607
+ const M = i.current;
1608
+ if (!M || g.current) return;
1609
+ const l = setTimeout(() => {
1610
+ if (!M.parentElement) {
1611
+ console.warn("Parent element not found for signal", h);
1505
1612
  return;
1506
1613
  }
1507
- const l = V.parentElement, T = Array.from(l.childNodes).indexOf(V);
1508
- let o = l.getAttribute("data-parent-id");
1509
- o || (o = `parent-${crypto.randomUUID()}`, l.setAttribute("data-parent-id", o)), p.current = `instance-${crypto.randomUUID()}`;
1510
- const S = t.getState().getShadowMetadata(e._stateKey, e._path) || {}, M = S.signals || [];
1511
- M.push({
1512
- instanceId: p.current,
1614
+ const u = M.parentElement, b = Array.from(u.childNodes).indexOf(M);
1615
+ let o = u.getAttribute("data-parent-id");
1616
+ o || (o = `parent-${crypto.randomUUID()}`, u.setAttribute("data-parent-id", o)), f.current = `instance-${crypto.randomUUID()}`;
1617
+ const S = t.getState().getShadowMetadata(e._stateKey, e._path) || {}, T = S.signals || [];
1618
+ T.push({
1619
+ instanceId: f.current,
1513
1620
  parentId: o,
1514
- position: T,
1621
+ position: b,
1515
1622
  effect: e._effect
1516
1623
  }), t.getState().setShadowMetadata(e._stateKey, e._path, {
1517
1624
  ...S,
1518
- signals: M
1625
+ signals: T
1519
1626
  });
1520
- let L = h;
1627
+ let W = p;
1521
1628
  if (e._effect)
1522
1629
  try {
1523
- L = new Function(
1630
+ W = new Function(
1524
1631
  "state",
1525
1632
  `return (${e._effect})(state)`
1526
- )(h);
1527
- } catch (c) {
1528
- console.error("Error evaluating effect function:", c);
1633
+ )(p);
1634
+ } catch (x) {
1635
+ console.error("Error evaluating effect function:", x);
1529
1636
  }
1530
- L !== null && typeof L == "object" && (L = JSON.stringify(L));
1531
- const N = document.createTextNode(String(L ?? ""));
1532
- V.replaceWith(N), g.current = !0;
1637
+ W !== null && typeof W == "object" && (W = JSON.stringify(W));
1638
+ const c = document.createTextNode(String(W ?? ""));
1639
+ M.replaceWith(c), g.current = !0;
1533
1640
  }, 0);
1534
1641
  return () => {
1535
- if (clearTimeout(u), p.current) {
1536
- const l = t.getState().getShadowMetadata(e._stateKey, e._path) || {};
1537
- l.signals && (l.signals = l.signals.filter(
1538
- (E) => E.instanceId !== p.current
1539
- ), t.getState().setShadowMetadata(e._stateKey, e._path, l));
1642
+ if (clearTimeout(l), f.current) {
1643
+ const u = t.getState().getShadowMetadata(e._stateKey, e._path) || {};
1644
+ u.signals && (u.signals = u.signals.filter(
1645
+ (A) => A.instanceId !== f.current
1646
+ ), t.getState().setShadowMetadata(e._stateKey, e._path, u));
1540
1647
  }
1541
1648
  };
1542
1649
  }, []), le("span", {
1543
- ref: s,
1650
+ ref: i,
1544
1651
  style: { display: "contents" },
1545
- "data-signal-id": v
1652
+ "data-signal-id": h
1546
1653
  });
1547
1654
  }
1548
- const we = Re(
1655
+ const Me = Re(
1549
1656
  Ye,
1550
- (e, s) => e.itemPath.join(".") === s.itemPath.join(".") && e.stateKey === s.stateKey && e.itemComponentId === s.itemComponentId && e.localIndex === s.localIndex
1657
+ (e, i) => e.itemPath.join(".") === i.itemPath.join(".") && e.stateKey === i.stateKey && e.itemComponentId === i.itemComponentId && e.localIndex === i.localIndex
1551
1658
  ), Je = (e) => {
1552
- const [s, p] = Z(!1);
1553
- return ue(() => {
1659
+ const [i, f] = X(!1);
1660
+ return de(() => {
1554
1661
  if (!e.current) {
1555
- p(!0);
1662
+ f(!0);
1556
1663
  return;
1557
1664
  }
1558
1665
  const g = Array.from(e.current.querySelectorAll("img"));
1559
1666
  if (g.length === 0) {
1560
- p(!0);
1667
+ f(!0);
1561
1668
  return;
1562
1669
  }
1563
- let v = 0;
1564
- const h = () => {
1565
- v++, v === g.length && p(!0);
1670
+ let h = 0;
1671
+ const p = () => {
1672
+ h++, h === g.length && f(!0);
1566
1673
  };
1567
- return g.forEach((V) => {
1568
- V.complete ? h() : (V.addEventListener("load", h), V.addEventListener("error", h));
1674
+ return g.forEach((M) => {
1675
+ M.complete ? p() : (M.addEventListener("load", p), M.addEventListener("error", p));
1569
1676
  }), () => {
1570
- g.forEach((V) => {
1571
- V.removeEventListener("load", h), V.removeEventListener("error", h);
1677
+ g.forEach((M) => {
1678
+ M.removeEventListener("load", p), M.removeEventListener("error", p);
1572
1679
  });
1573
1680
  };
1574
- }, [e.current]), s;
1681
+ }, [e.current]), i;
1575
1682
  };
1576
1683
  function Ye({
1577
1684
  stateKey: e,
1578
- itemComponentId: s,
1579
- itemPath: p,
1685
+ itemComponentId: i,
1686
+ itemPath: f,
1580
1687
  localIndex: g,
1581
- arraySetter: v,
1582
- rebuildStateShape: h,
1583
- renderFn: V
1688
+ arraySetter: h,
1689
+ rebuildStateShape: p,
1690
+ renderFn: M
1584
1691
  }) {
1585
- const [, u] = Z({}), { ref: l, inView: E } = Oe(), T = q(null), o = Je(T), S = q(!1), M = [e, ...p].join(".");
1586
- Ue(e, s, u);
1587
- const L = ce(
1588
- (H) => {
1589
- T.current = H, l(H);
1692
+ const [, l] = X({}), { ref: u, inView: A } = Le(), b = G(null), o = Je(b), S = G(!1), T = [e, ...f].join(".");
1693
+ Ue(e, i, l);
1694
+ const W = ce(
1695
+ (U) => {
1696
+ b.current = U, u(U);
1590
1697
  },
1591
- [l]
1698
+ [u]
1592
1699
  );
1593
- Y(() => {
1594
- t.getState().subscribeToPath(M, (H) => {
1595
- u({});
1700
+ Q(() => {
1701
+ t.getState().subscribeToPath(T, (U) => {
1702
+ l({});
1596
1703
  });
1597
- }, []), Y(() => {
1598
- if (!E || !o || S.current)
1704
+ }, []), Q(() => {
1705
+ if (!A || !o || S.current)
1599
1706
  return;
1600
- const H = T.current;
1601
- if (H && H.offsetHeight > 0) {
1707
+ const U = b.current;
1708
+ if (U && U.offsetHeight > 0) {
1602
1709
  S.current = !0;
1603
- const f = H.offsetHeight;
1604
- t.getState().setShadowMetadata(e, p, {
1710
+ const v = U.offsetHeight;
1711
+ t.getState().setShadowMetadata(e, f, {
1605
1712
  virtualizer: {
1606
- itemHeight: f,
1607
- domRef: H
1713
+ itemHeight: v,
1714
+ domRef: U
1608
1715
  }
1609
1716
  });
1610
- const oe = p.slice(0, -1), se = [e, ...oe].join(".");
1611
- t.getState().notifyPathSubscribers(se, {
1717
+ const K = f.slice(0, -1), oe = [e, ...K].join(".");
1718
+ t.getState().notifyPathSubscribers(oe, {
1612
1719
  type: "ITEMHEIGHT",
1613
- itemKey: p.join("."),
1614
- ref: T.current
1720
+ itemKey: f.join("."),
1721
+ ref: b.current
1615
1722
  });
1616
1723
  }
1617
- }, [E, o, e, p]);
1618
- const N = [e, ...p].join("."), c = t.getState().getShadowValue(N);
1619
- if (c === void 0)
1724
+ }, [A, o, e, f]);
1725
+ const c = [e, ...f].join("."), x = t.getState().getShadowValue(c);
1726
+ if (x === void 0)
1620
1727
  return null;
1621
- const J = h({
1622
- currentState: c,
1623
- path: p,
1624
- componentId: s
1625
- }), G = V(J, g, v);
1626
- return /* @__PURE__ */ ae("div", { ref: L, children: G });
1728
+ const Y = p({
1729
+ currentState: x,
1730
+ path: f,
1731
+ componentId: i
1732
+ }), J = M(Y, g, h);
1733
+ return /* @__PURE__ */ re("div", { ref: W, children: J });
1627
1734
  }
1628
1735
  function Ze({
1629
1736
  stateKey: e,
1630
- path: s,
1631
- rebuildStateShape: p,
1737
+ path: i,
1738
+ rebuildStateShape: f,
1632
1739
  renderFn: g,
1633
- formOpts: v,
1634
- setState: h
1740
+ formOpts: h,
1741
+ setState: p
1635
1742
  }) {
1636
- const [V] = Z(() => ee()), [, u] = Z({}), l = [e, ...s].join(".");
1637
- Ue(e, V, u);
1638
- const E = t.getState().getShadowValue(l), [T, o] = Z(E), S = q(!1), M = q(null);
1639
- Y(() => {
1640
- !S.current && !ie(E, T) && o(E);
1641
- }, [E]), Y(() => {
1642
- const G = t.getState().subscribeToPath(l, (H) => {
1643
- u({});
1743
+ const [M] = X(() => te()), [, l] = X({}), u = [e, ...i].join(".");
1744
+ Ue(e, M, l);
1745
+ const A = t.getState().getShadowValue(u), [b, o] = X(A), S = G(!1), T = G(null);
1746
+ Q(() => {
1747
+ !S.current && !se(A, b) && o(A);
1748
+ }, [A]), Q(() => {
1749
+ const J = t.getState().subscribeToPath(u, (U) => {
1750
+ l({});
1644
1751
  });
1645
1752
  return () => {
1646
- G(), M.current && (clearTimeout(M.current), S.current = !1);
1753
+ J(), T.current && (clearTimeout(T.current), S.current = !1);
1647
1754
  };
1648
1755
  }, []);
1649
- const L = ce(
1650
- (G) => {
1651
- o(G), S.current = !0, M.current && clearTimeout(M.current);
1652
- const H = v?.debounceTime ?? 200;
1653
- M.current = setTimeout(() => {
1654
- S.current = !1, h(G, s, { updateType: "update" });
1655
- }, H);
1756
+ const W = ce(
1757
+ (J) => {
1758
+ o(J), S.current = !0, T.current && clearTimeout(T.current);
1759
+ const U = h?.debounceTime ?? 200;
1760
+ T.current = setTimeout(() => {
1761
+ S.current = !1, p(J, i, { updateType: "update" });
1762
+ }, U);
1656
1763
  },
1657
- [h, s, v?.debounceTime]
1658
- ), N = ce(() => {
1659
- M.current && (clearTimeout(M.current), S.current = !1, h(T, s, { updateType: "update" }));
1660
- }, [h, s, T]), c = p({
1661
- currentState: E,
1662
- path: s,
1663
- componentId: V
1664
- }), J = new Proxy(c, {
1665
- get(G, H) {
1666
- return H === "inputProps" ? {
1667
- value: T ?? "",
1668
- onChange: (f) => {
1669
- L(f.target.value);
1764
+ [p, i, h?.debounceTime]
1765
+ ), c = ce(() => {
1766
+ T.current && (clearTimeout(T.current), S.current = !1, p(b, i, { updateType: "update" }));
1767
+ }, [p, i, b]), x = f({
1768
+ currentState: A,
1769
+ path: i,
1770
+ componentId: M
1771
+ }), Y = new Proxy(x, {
1772
+ get(J, U) {
1773
+ return U === "inputProps" ? {
1774
+ value: b ?? "",
1775
+ onChange: (v) => {
1776
+ W(v.target.value);
1670
1777
  },
1671
- onBlur: N,
1672
- ref: ye.getState().getFormRef(e + "." + s.join("."))
1673
- } : G[H];
1778
+ onBlur: c,
1779
+ ref: pe.getState().getFormRef(e + "." + i.join("."))
1780
+ } : J[U];
1674
1781
  }
1675
1782
  });
1676
- return /* @__PURE__ */ ae(ke, { children: g(J) });
1783
+ return /* @__PURE__ */ re(ke, { children: g(Y) });
1677
1784
  }
1678
- function Ue(e, s, p) {
1679
- const g = `${e}////${s}`;
1680
- ue(() => {
1681
- const v = t.getState().getShadowMetadata(e, []), h = v?.components || /* @__PURE__ */ new Map();
1682
- return h.set(g, {
1683
- forceUpdate: () => p({}),
1785
+ function Ue(e, i, f) {
1786
+ const g = `${e}////${i}`;
1787
+ de(() => {
1788
+ const h = t.getState().getShadowMetadata(e, []), p = h?.components || /* @__PURE__ */ new Map();
1789
+ return p.set(g, {
1790
+ forceUpdate: () => f({}),
1684
1791
  paths: /* @__PURE__ */ new Set(),
1685
1792
  reactiveType: ["component"]
1686
1793
  }), t.getState().setShadowMetadata(e, [], {
1687
- ...v,
1688
- components: h
1794
+ ...h,
1795
+ components: p
1689
1796
  }), () => {
1690
- const V = t.getState().getShadowMetadata(e, []);
1691
- V?.components && V.components.delete(g);
1797
+ const M = t.getState().getShadowMetadata(e, []);
1798
+ M?.components && M.components.delete(g);
1692
1799
  };
1693
1800
  }, [e, g]);
1694
1801
  }
1695
1802
  export {
1696
- be as $cogsSignal,
1697
- lt as addStateOptions,
1698
- ut as createCogsState,
1699
- dt as notifyComponent,
1803
+ Ae as $cogsSignal,
1804
+ it as addStateOptions,
1805
+ ct as createCogsState,
1806
+ lt as notifyComponent,
1700
1807
  Be as useCogsStateFn
1701
1808
  };
1702
1809
  //# sourceMappingURL=CogsState.jsx.map