cogsbox-state 0.5.461 → 0.5.463

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