cogsbox-state 0.5.242 → 0.5.244

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