cogsbox-state 0.5.5 → 0.5.7

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.
Files changed (48) hide show
  1. package/dist/CogsState.d.ts +30 -13
  2. package/dist/CogsState.jsx +544 -480
  3. package/dist/CogsState.jsx.map +1 -1
  4. package/dist/CogsStateClient.jsx +6 -6
  5. package/dist/CogsStateClient.jsx.map +1 -1
  6. package/dist/Functions.d.ts +3 -4
  7. package/dist/Functions.jsx +173 -128
  8. package/dist/Functions.jsx.map +1 -1
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.js +21 -17
  11. package/dist/index.js.map +1 -1
  12. package/dist/node_modules/zustand/esm/react.js +1 -1
  13. package/dist/store.d.ts +19 -9
  14. package/dist/store.js +77 -60
  15. package/dist/store.js.map +1 -1
  16. package/dist/useValidateZodPath.d.ts +34 -0
  17. package/dist/useValidateZodPath.js +60 -0
  18. package/dist/useValidateZodPath.js.map +1 -0
  19. package/dist/utility.d.ts +6 -0
  20. package/dist/utility.js +90 -80
  21. package/dist/utility.js.map +1 -1
  22. package/package.json +68 -64
  23. package/dist/_virtual/_commonjsHelpers.js +0 -7
  24. package/dist/_virtual/_commonjsHelpers.js.map +0 -1
  25. package/dist/_virtual/index.js +0 -5
  26. package/dist/_virtual/index.js.map +0 -1
  27. package/dist/_virtual/jsx-runtime.jsx +0 -5
  28. package/dist/_virtual/jsx-runtime.jsx.map +0 -1
  29. package/dist/_virtual/react-jsx-runtime.jsx +0 -5
  30. package/dist/_virtual/react-jsx-runtime.jsx.map +0 -1
  31. package/dist/_virtual/react-jsx-runtime.production.jsx +0 -5
  32. package/dist/_virtual/react-jsx-runtime.production.jsx.map +0 -1
  33. package/dist/_virtual/react.js +0 -5
  34. package/dist/_virtual/react.js.map +0 -1
  35. package/dist/_virtual/react.production.js +0 -5
  36. package/dist/_virtual/react.production.js.map +0 -1
  37. package/dist/node_modules/react/cjs/react-jsx-runtime.jsx +0 -605
  38. package/dist/node_modules/react/cjs/react-jsx-runtime.jsx.map +0 -1
  39. package/dist/node_modules/react/cjs/react-jsx-runtime.production.jsx +0 -29
  40. package/dist/node_modules/react/cjs/react-jsx-runtime.production.jsx.map +0 -1
  41. package/dist/node_modules/react/cjs/react.js +0 -1274
  42. package/dist/node_modules/react/cjs/react.js.map +0 -1
  43. package/dist/node_modules/react/cjs/react.production.js +0 -209
  44. package/dist/node_modules/react/cjs/react.production.js.map +0 -1
  45. package/dist/node_modules/react/index.js +0 -12
  46. package/dist/node_modules/react/index.js.map +0 -1
  47. package/dist/node_modules/react/jsx-runtime.jsx +0 -9
  48. package/dist/node_modules/react/jsx-runtime.jsx.map +0 -1
@@ -1,72 +1,75 @@
1
1
  "use client";
2
- import { j as Y } from "./node_modules/react/jsx-runtime.jsx";
3
- import { r as w } from "./node_modules/react/index.js";
4
- import { transformStateFunc as ut, isFunction as at, getNestedValue as R, isDeepEqual as L } from "./utility.js";
5
- import { pushFunc as Z, cutFunc as K, updateFn as tt, ValidationWrapper as St, FormControlComponent as gt } from "./Functions.jsx";
2
+ import { jsx as at } from "react/jsx-runtime";
3
+ import { useState as Y, useRef as z, useEffect as K, useLayoutEffect as vt, useMemo as It, createElement as H, useSyncExternalStore as pt, startTransition as J } from "react";
4
+ import { transformStateFunc as _t, isFunction as ut, getNestedValue as D, isDeepEqual as L, debounce as Et } from "./utility.js";
5
+ import { pushFunc as it, updateFn as q, cutFunc as st, ValidationWrapper as wt, FormControlComponent as $t } from "./Functions.jsx";
6
6
  import "zod";
7
- import { getGlobalStore as a } from "./store.js";
8
- import { useCogsConfig as ft } from "./CogsStateClient.jsx";
9
- import k from "./node_modules/uuid/dist/esm-browser/v4.js";
10
- function Mt(t, { formElements: i, zodSchema: d }) {
11
- return { initialState: t, formElements: i, zodSchema: d };
12
- }
13
- function et(t, i) {
14
- const d = a.getState().getInitialOptions, u = a.getState().setInitialStateOptions, S = d(t) || {};
15
- u(t, {
16
- ...S,
7
+ import { getGlobalStore as o, formRefStore as ct } from "./store.js";
8
+ import { useCogsConfig as Vt } from "./CogsStateClient.jsx";
9
+ import tt from "./node_modules/uuid/dist/esm-browser/v4.js";
10
+ function lt(t, i) {
11
+ const f = o.getState().getInitialOptions, S = o.getState().setInitialStateOptions, g = f(t) || {};
12
+ S(t, {
13
+ ...g,
17
14
  ...i
18
15
  });
19
16
  }
20
- function nt({
17
+ function dt({
21
18
  stateKey: t,
22
19
  options: i,
23
- initialOptionsPart: d
20
+ initialOptionsPart: f
24
21
  }) {
25
- const u = z(t) || {}, S = d[t] || {}, I = a.getState().setInitialStateOptions, _ = { ...S, ...u };
26
- let E = !1;
22
+ const S = et(t) || {}, g = f[t] || {}, I = o.getState().setInitialStateOptions, _ = { ...g, ...S };
23
+ let p = !1;
27
24
  if (i)
28
- for (const y in i)
29
- _.hasOwnProperty(y) || (E = !0, _[y] = i[y]);
30
- E && I(t, _);
25
+ for (const m in i)
26
+ _.hasOwnProperty(m) || (p = !0, _[m] = i[m]);
27
+ p && I(t, _);
31
28
  }
32
- const Ot = (t, i) => {
33
- let d = t;
34
- const [u, S] = ut(d);
35
- a.getState().setInitialStates(u);
36
- const I = (E, y) => {
37
- const [p] = w.useState(k());
38
- nt({ stateKey: E, options: y, initialOptionsPart: S });
39
- const o = a.getState().cogsStateStore[E] || u[E], r = y?.modifyState ? y.modifyState(o) : o, [v, N] = wt(
40
- r,
29
+ const qt = (t, i) => {
30
+ let f = t;
31
+ const [S, g] = _t(f);
32
+ o.getState().setInitialStates(S);
33
+ const I = (p, m) => {
34
+ const [E] = Y(m?.componentId ?? tt());
35
+ dt({
36
+ stateKey: p,
37
+ options: m,
38
+ initialOptionsPart: g
39
+ });
40
+ const l = o.getState().cogsStateStore[p] || S[p], e = m?.modifyState ? m.modifyState(l) : l, [v, h] = jt(
41
+ e,
41
42
  {
42
- stateKey: E,
43
- syncUpdate: y?.syncUpdate,
44
- componentId: p,
45
- localStorage: y?.localStorage,
46
- middleware: y?.middleware,
47
- enabledSync: y?.enabledSync,
48
- reactiveDeps: y?.reactiveDeps,
49
- initState: y?.initState
43
+ stateKey: p,
44
+ syncUpdate: m?.syncUpdate,
45
+ componentId: E,
46
+ localStorage: m?.localStorage,
47
+ middleware: m?.middleware,
48
+ enabledSync: m?.enabledSync,
49
+ reactiveType: m?.reactiveType,
50
+ reactiveDeps: m?.reactiveDeps,
51
+ initState: m?.initState,
52
+ localStorageKey: m?.localStorageKey
50
53
  }
51
54
  );
52
- return N;
55
+ return h;
53
56
  };
54
- function _(E, y) {
55
- nt({ stateKey: E, options: y, initialOptionsPart: S });
57
+ function _(p, m) {
58
+ dt({ stateKey: p, options: m, initialOptionsPart: g });
56
59
  }
57
60
  return { useCogsState: I, setCogsOptions: _ };
58
61
  }, {
59
- setUpdaterState: G,
60
- setState: M,
61
- getInitialOptions: z,
62
- getKeyState: it,
63
- getValidationErrors: mt,
64
- setStateLog: yt,
65
- updateInitialStateGlobal: J,
66
- addValidationError: pt,
67
- removeValidationError: U,
68
- setServerSyncActions: vt
69
- } = a.getState(), ot = (t) => {
62
+ setUpdaterState: B,
63
+ setState: x,
64
+ getInitialOptions: et,
65
+ getKeyState: ft,
66
+ getValidationErrors: Nt,
67
+ setStateLog: ht,
68
+ updateInitialStateGlobal: nt,
69
+ addValidationError: Ct,
70
+ removeValidationError: R,
71
+ setServerSyncActions: Tt
72
+ } = o.getState(), gt = (t) => {
70
73
  if (!t) return null;
71
74
  try {
72
75
  const i = window.localStorage.getItem(t);
@@ -74,584 +77,645 @@ const Ot = (t, i) => {
74
77
  } catch (i) {
75
78
  return console.error("Error loading from localStorage:", i), null;
76
79
  }
77
- }, It = (t, i, d, u) => {
78
- if (d?.initState) {
79
- const S = {
80
+ }, At = (t, i, f, S) => {
81
+ if (f.localStorageKey) {
82
+ const g = {
80
83
  state: t,
81
84
  lastUpdated: Date.now(),
82
- lastSyncedWithServer: a.getState().serverSyncLog[i]?.[0]?.timeStamp,
83
- baseServerState: a.getState().serverState[i]
84
- }, I = d.initState ? `${u}-${i}-${d.initState.localStorageKey}` : i;
85
- window.localStorage.setItem(I, JSON.stringify(S));
85
+ lastSyncedWithServer: o.getState().serverSyncLog[i]?.[0]?.timeStamp,
86
+ baseServerState: o.getState().serverState[i]
87
+ }, I = f.initState ? `${S}-${i}-${f.localStorageKey}` : i;
88
+ window.localStorage.setItem(I, JSON.stringify(g));
86
89
  }
87
- }, _t = (t, i, d, u, S, I) => {
90
+ }, Ft = (t, i, f, S, g, I) => {
88
91
  const _ = {
89
92
  initialState: i,
90
- updaterState: W(
93
+ updaterState: Z(
91
94
  t,
92
- u,
93
95
  S,
96
+ g,
94
97
  I
95
98
  ),
96
- state: d
99
+ state: f
97
100
  };
98
- w.startTransition(() => {
99
- J(t, _.initialState), G(t, _.updaterState), M(t, _.state);
101
+ J(() => {
102
+ nt(t, _.initialState), B(t, _.updaterState), x(t, _.state);
100
103
  });
101
- }, Et = (t) => {
102
- const i = a.getState().stateComponents.get(t);
104
+ }, Mt = (t) => {
105
+ const i = o.getState().stateComponents.get(t);
103
106
  if (!i) return;
104
- const d = /* @__PURE__ */ new Set();
105
- i.components.forEach((u) => {
106
- d.add(() => u.forceUpdate());
107
+ const f = /* @__PURE__ */ new Set();
108
+ i.components.forEach((S) => {
109
+ f.add(() => S.forceUpdate());
107
110
  }), queueMicrotask(() => {
108
- w.startTransition(() => {
109
- d.forEach((u) => u());
111
+ J(() => {
112
+ f.forEach((S) => S());
110
113
  });
111
114
  });
115
+ }, zt = (t, i) => {
116
+ const f = o.getState().stateComponents.get(t);
117
+ if (f) {
118
+ const S = `${t}////${i}`, g = f.components.get(S);
119
+ g && g.forceUpdate();
120
+ }
112
121
  };
113
- function wt(t, {
122
+ function jt(t, {
114
123
  stateKey: i,
115
- serverSync: d,
116
- zodSchema: u,
124
+ serverSync: f,
117
125
  localStorage: S,
118
- formElements: I,
119
- middleware: _,
120
- reactiveDeps: E,
121
- componentId: y,
122
- initState: p,
123
- syncUpdate: o
126
+ formElements: g,
127
+ middleware: I,
128
+ reactiveDeps: _,
129
+ reactiveType: p,
130
+ componentId: m,
131
+ localStorageKey: E,
132
+ initState: l,
133
+ syncUpdate: e
124
134
  } = {}) {
125
- const [r, v] = w.useState({}), { sessionId: N } = ft();
126
- let F = !i;
127
- const [c] = w.useState(i ?? k()), b = a.getState().stateLog[c], B = w.useRef(/* @__PURE__ */ new Set()), s = w.useRef(y ?? k()), A = w.useRef(null);
128
- A.current = z(c), w.useEffect(() => {
129
- if (o && o.stateKey === c && o.path?.[0]) {
130
- M(c, (n) => ({
131
- ...n,
132
- [o.path[0]]: o.newValue
135
+ const [v, h] = Y({}), { sessionId: F } = Vt();
136
+ let U = !i;
137
+ const [d] = Y(i ?? tt()), a = o.getState().stateLog[d], G = z(/* @__PURE__ */ new Set()), b = z(m ?? tt()), A = z(null);
138
+ A.current = et(d), K(() => {
139
+ if (e && e.stateKey === d && e.path?.[0]) {
140
+ x(d, (r) => ({
141
+ ...r,
142
+ [e.path[0]]: e.newValue
133
143
  }));
134
- const e = `${o.stateKey}:${o.path.join(".")}`;
135
- a.getState().setSyncInfo(e, {
136
- timeStamp: o.timeStamp,
137
- userId: o.userId
144
+ const c = `${e.stateKey}:${e.path.join(".")}`;
145
+ o.getState().setSyncInfo(c, {
146
+ timeStamp: e.timeStamp,
147
+ userId: e.userId
138
148
  });
139
149
  }
140
- }, [o]), w.useEffect(() => {
141
- et(c, {
142
- initState: p
150
+ }, [e]), K(() => {
151
+ lt(d, {
152
+ initState: l
143
153
  });
144
- const e = ot(
145
- N + "-" + c + "-" + p?.localStorageKey
146
- );
147
- let n = null;
148
- p?.initialState && (n = p?.initialState, e && e.lastUpdated > (e.lastSyncedWithServer || 0) && (n = e.state), _t(
149
- c,
150
- p?.initialState,
154
+ let c = null;
155
+ E && (c = gt(
156
+ F + "-" + d + "-" + E
157
+ ));
158
+ let r = null;
159
+ l?.initialState && (r = l?.initialState, console.log("newState", r), c && c.lastUpdated > (c.lastSyncedWithServer || 0) && (r = c.state), Ft(
160
+ d,
161
+ l?.initialState,
162
+ r,
151
163
  n,
152
- h,
153
- s.current,
154
- N
155
- )), Et(c);
156
- }, [p?.localStorageKey, ...p?.dependencies || []]), w.useEffect(() => {
157
- F && et(c, {
158
- serverSync: d,
159
- formElements: I,
160
- zodSchema: u,
161
- initState: p,
164
+ b.current,
165
+ F
166
+ ), console.log("newState222", r), h({}));
167
+ }, [E, ...l?.dependencies || []]), vt(() => {
168
+ U && lt(d, {
169
+ serverSync: f,
170
+ formElements: g,
171
+ initState: l,
162
172
  localStorage: S,
163
- middleware: _
173
+ middleware: I
164
174
  });
165
- const e = `${c}////${s.current}`, n = a.getState().stateComponents.get(c) || {
175
+ const c = `${d}////${b.current}`, r = o.getState().stateComponents.get(d) || {
166
176
  components: /* @__PURE__ */ new Map()
167
177
  };
168
- return n.components.set(e, {
169
- forceUpdate: () => v({}),
178
+ return r.components.set(c, {
179
+ forceUpdate: () => h({}),
170
180
  paths: /* @__PURE__ */ new Set(),
171
181
  deps: [],
172
- depsFunction: E || void 0
173
- }), a.getState().stateComponents.set(c, n), () => {
174
- const l = `${c}////${s.current}`;
175
- n && (n.components.delete(l), n.components.size === 0 && a.getState().stateComponents.delete(c));
182
+ depsFunction: _ || void 0,
183
+ reactiveType: p ?? ["component", "deps"]
184
+ }), o.getState().stateComponents.set(d, r), h({}), () => {
185
+ const u = `${d}////${b.current}`;
186
+ r && (r.components.delete(u), r.components.size === 0 && o.getState().stateComponents.delete(d));
176
187
  };
177
188
  }, []);
178
- const h = (e, n, l, g) => {
179
- if (Array.isArray(n)) {
180
- const m = `${c}-${n.join(".")}`;
181
- B.current.add(m);
189
+ const n = (c, r, u, w) => {
190
+ if (Array.isArray(r)) {
191
+ const M = `${d}-${r.join(".")}`;
192
+ G.current.add(M);
182
193
  }
183
- M(c, (m) => {
184
- const $ = at(e) ? e(m) : e, P = `${c}-${n.join(".")}`;
185
- if (P) {
186
- let j = !1, f = a.getState().signalDomElements.get(P);
187
- if ((!f || f.size === 0) && (l.updateType === "insert" || l.updateType === "cut")) {
188
- const V = n.slice(0, -1), x = R($, V);
189
- if (Array.isArray(x)) {
190
- j = !0;
191
- const T = `${c}-${V.join(".")}`;
192
- f = a.getState().signalDomElements.get(T);
194
+ x(d, (M) => {
195
+ const V = ut(c) ? c(M) : c, j = `${d}-${r.join(".")}`;
196
+ if (j) {
197
+ let P = !1, y = o.getState().signalDomElements.get(j);
198
+ if ((!y || y.size === 0) && (u.updateType === "insert" || u.updateType === "cut")) {
199
+ const N = r.slice(0, -1), T = D(V, N);
200
+ if (Array.isArray(T)) {
201
+ P = !0;
202
+ const $ = `${d}-${N.join(".")}`;
203
+ y = o.getState().signalDomElements.get($);
193
204
  }
194
205
  }
195
- if (f) {
196
- const V = j ? R($, n.slice(0, -1)) : R($, n);
197
- f.forEach(({ parentId: x, position: T, effect: D }) => {
198
- const C = document.querySelector(
199
- `[data-parent-id="${x}"]`
206
+ if (y) {
207
+ const N = P ? D(V, r.slice(0, -1)) : D(V, r);
208
+ y.forEach(({ parentId: T, position: $, effect: k }) => {
209
+ const O = document.querySelector(
210
+ `[data-parent-id="${T}"]`
200
211
  );
201
- if (C) {
202
- const X = Array.from(C.childNodes);
203
- if (X[T]) {
204
- const dt = D ? new Function(
205
- "state",
206
- `return (${D})(state)`
207
- )(V) : V;
208
- X[T].textContent = String(dt);
212
+ if (O) {
213
+ const ot = Array.from(O.childNodes);
214
+ if (ot[$]) {
215
+ const yt = k ? new Function("state", `return (${k})(state)`)(N) : N;
216
+ ot[$].textContent = String(yt);
209
217
  }
210
218
  }
211
219
  });
212
220
  }
213
221
  }
214
- l.updateType === "update" && (g || A.current?.validationKey) && n && U(
215
- (g || A.current?.validationKey) + "." + n.join(".")
222
+ u.updateType === "update" && (w || A.current?.validationKey) && r && R(
223
+ (w || A.current?.validationKey) + "." + r.join(".")
216
224
  );
217
- const O = n.slice(0, n.length - 1);
218
- l.updateType === "cut" && A.current?.validationKey && U(
219
- A.current?.validationKey + "." + O.join(".")
220
- ), l.updateType === "insert" && A.current?.validationKey && mt(
221
- A.current?.validationKey + "." + O.join(".")
222
- ).filter(([f, V]) => {
223
- let x = f?.split(".").length;
224
- if (f == O.join(".") && x == O.length - 1) {
225
- let T = f + "." + O;
226
- U(f), pt(T, V);
225
+ const C = r.slice(0, r.length - 1);
226
+ u.updateType === "cut" && A.current?.validationKey && R(
227
+ A.current?.validationKey + "." + C.join(".")
228
+ ), u.updateType === "insert" && A.current?.validationKey && Nt(
229
+ A.current?.validationKey + "." + C.join(".")
230
+ ).filter(([y, N]) => {
231
+ let T = y?.split(".").length;
232
+ if (y == C.join(".") && T == C.length - 1) {
233
+ let $ = y + "." + C;
234
+ R(y), Ct($, N);
227
235
  }
228
236
  });
229
- const st = R(m, n), ct = R($, n), lt = l.updateType === "update" ? n.join(".") : [...n].slice(0, -1).join("."), H = a.getState().stateComponents.get(c);
230
- if (H) {
231
- for (const [
232
- j,
233
- f
234
- ] of H.components.entries())
235
- if (f.depsFunction || f.paths && f.paths.has(lt))
236
- if (f.depsFunction) {
237
- const V = f.depsFunction($);
238
- typeof V == "boolean" ? V && f.forceUpdate() : L(f.deps, V) || (f.deps = V, f.forceUpdate());
239
- } else
240
- f.forceUpdate();
241
- }
242
- const Q = {
237
+ const W = D(M, r), St = D(V, r), mt = u.updateType === "update" ? r.join(".") : [...r].slice(0, -1).join("."), Q = o.getState().stateComponents.get(d);
238
+ if (i == "cart" && (console.log("thisKey", d), console.log("stateEntry", Q)), Q)
239
+ for (const [P, y] of Q.components.entries()) {
240
+ let N = !1;
241
+ const T = Array.isArray(y.reactiveType) ? y.reactiveType : [y.reactiveType || "component"];
242
+ if (!T.includes("none")) {
243
+ if (T.includes("all")) {
244
+ y.forceUpdate();
245
+ continue;
246
+ }
247
+ if (T.includes("component") && y.paths && (y.paths.has(mt) || y.paths.has("")) && (N = !0), !N && T.includes("deps") && y.depsFunction) {
248
+ const $ = y.depsFunction(V);
249
+ typeof $ == "boolean" ? $ && (N = !0) : L(y.deps, $) || (y.deps = $, N = !0);
250
+ }
251
+ N && y.forceUpdate();
252
+ }
253
+ }
254
+ const rt = {
243
255
  timeStamp: Date.now(),
244
- stateKey: c,
245
- path: n,
246
- updateType: l.updateType,
256
+ stateKey: d,
257
+ path: r,
258
+ updateType: u.updateType,
247
259
  status: "new",
248
- oldValue: st,
249
- newValue: ct
260
+ oldValue: W,
261
+ newValue: St
250
262
  };
251
- if (yt(c, (j) => {
252
- const V = [...j ?? [], Q].reduce((x, T) => {
253
- const D = `${T.stateKey}:${JSON.stringify(T.path)}`, C = x.get(D);
254
- return C ? (C.timeStamp = Math.max(
255
- C.timeStamp,
256
- T.timeStamp
257
- ), C.newValue = T.newValue, C.oldValue = C.oldValue ?? T.oldValue, C.updateType = T.updateType) : x.set(D, { ...T }), x;
263
+ if (ht(d, (P) => {
264
+ const N = [...P ?? [], rt].reduce((T, $) => {
265
+ const k = `${$.stateKey}:${JSON.stringify($.path)}`, O = T.get(k);
266
+ return O ? (O.timeStamp = Math.max(O.timeStamp, $.timeStamp), O.newValue = $.newValue, O.oldValue = O.oldValue ?? $.oldValue, O.updateType = $.updateType) : T.set(k, { ...$ }), T;
258
267
  }, /* @__PURE__ */ new Map());
259
- return Array.from(V.values());
260
- }), It(
261
- $,
262
- c,
268
+ return Array.from(N.values());
269
+ }), At(
270
+ V,
271
+ d,
263
272
  A.current,
264
- N
265
- ), _ && _({ updateLog: b, update: Q }), A.current?.serverSync) {
266
- const j = a.getState().serverState[c], f = A.current?.serverSync;
267
- vt(c, {
268
- syncKey: typeof f.syncKey == "string" ? f.syncKey : f.syncKey({ state: $ }),
269
- rollBackState: j,
270
- actionTimeStamp: Date.now() + (f.debounce ?? 3e3),
273
+ F
274
+ ), I && I({
275
+ updateLog: a,
276
+ update: rt
277
+ }), A.current?.serverSync) {
278
+ const P = o.getState().serverState[d], y = A.current?.serverSync;
279
+ Tt(d, {
280
+ syncKey: typeof y.syncKey == "string" ? y.syncKey : y.syncKey({ state: V }),
281
+ rollBackState: P,
282
+ actionTimeStamp: Date.now() + (y.debounce ?? 3e3),
271
283
  status: "waiting"
272
284
  });
273
285
  }
274
- return $;
286
+ return V;
275
287
  });
276
288
  };
277
- a.getState().updaterState[c] || (console.log("Initializing state for", c, t), G(
278
- c,
279
- W(
280
- c,
281
- h,
282
- s.current,
283
- N
289
+ o.getState().updaterState[d] || (console.log("Initializing state for", d, t), B(
290
+ d,
291
+ Z(
292
+ d,
293
+ n,
294
+ b.current,
295
+ F
284
296
  )
285
- ), a.getState().cogsStateStore[c] || M(c, t), a.getState().initialStateGlobal[c] || J(c, t));
286
- const q = w.useMemo(() => W(
287
- c,
288
- h,
289
- s.current,
290
- N
291
- ), [c]);
292
- return [it(c), q];
297
+ ), o.getState().cogsStateStore[d] || x(d, t), o.getState().initialStateGlobal[d] || nt(d, t));
298
+ const s = It(() => Z(
299
+ d,
300
+ n,
301
+ b.current,
302
+ F
303
+ ), [d]);
304
+ return [ft(d), s];
293
305
  }
294
- function W(t, i, d, u) {
295
- const S = /* @__PURE__ */ new Map();
306
+ function Z(t, i, f, S) {
307
+ const g = /* @__PURE__ */ new Map();
296
308
  let I = 0;
297
- const _ = (o) => {
298
- const r = o.join(".");
299
- for (const [v] of S)
300
- (v === r || v.startsWith(r + ".")) && S.delete(v);
309
+ const _ = (l) => {
310
+ const e = l.join(".");
311
+ for (const [v] of g)
312
+ (v === e || v.startsWith(e + ".")) && g.delete(v);
301
313
  I++;
302
- }, E = /* @__PURE__ */ new Map(), y = {
303
- removeValidation: (o) => {
304
- o?.validationKey && U(o.validationKey);
314
+ }, p = /* @__PURE__ */ new Map(), m = {
315
+ removeValidation: (l) => {
316
+ l?.validationKey && R(l.validationKey);
305
317
  },
306
- revertToInitialState: (o) => {
307
- o?.validationKey && U(o.validationKey);
308
- const r = a.getState().initialStateGlobal[t];
309
- S.clear(), I++;
310
- const v = p(r, []);
311
- w.startTransition(() => {
312
- G(t, v), M(t, r);
313
- const N = a.getState().stateComponents.get(t);
314
- N && N.components.forEach((c) => {
315
- c.forceUpdate();
318
+ revertToInitialState: (l) => {
319
+ const e = o.getState().getInitialOptions(t)?.validation;
320
+ e?.key && R(e?.key), l?.validationKey && R(l.validationKey);
321
+ const v = o.getState().initialStateGlobal[t];
322
+ g.clear(), I++;
323
+ const h = E(v, []);
324
+ J(() => {
325
+ B(t, h), x(t, v);
326
+ const F = o.getState().stateComponents.get(t);
327
+ F && F.components.forEach((d) => {
328
+ d.forceUpdate();
316
329
  });
317
- const F = z(t);
318
- F?.initState && localStorage.removeItem(
319
- F?.initState ? u + "-" + t + "-" + F?.initState.localStorageKey : t
330
+ const U = et(t);
331
+ U?.localStorageKey && localStorage.removeItem(
332
+ U?.initState ? S + "-" + t + "-" + U?.localStorageKey : t
320
333
  ), localStorage.removeItem(t);
321
334
  });
322
335
  },
323
- updateInitialState: (o) => {
324
- S.clear(), I++;
325
- const r = W(
336
+ updateInitialState: (l) => {
337
+ g.clear(), I++;
338
+ const e = Z(
326
339
  t,
327
340
  i,
328
- d,
329
- u
341
+ f,
342
+ S
330
343
  );
331
- return w.startTransition(() => {
332
- J(t, o), G(t, r), M(t, o);
333
- const v = a.getState().stateComponents.get(t);
334
- v && v.components.forEach((N) => {
335
- N.forceUpdate();
344
+ return J(() => {
345
+ nt(t, l), B(t, e), x(t, l);
346
+ const v = o.getState().stateComponents.get(t);
347
+ v && v.components.forEach((h) => {
348
+ h.forceUpdate();
336
349
  }), localStorage.removeItem(t);
337
350
  }), {
338
- fetchId: (v) => r.get()[v]
351
+ fetchId: (v) => e.get()[v]
339
352
  };
340
353
  },
341
- _initialState: a.getState().initialStateGlobal[t],
342
- _serverState: a.getState().serverState[t],
343
- _isLoading: a.getState().isLoadingGlobal[t],
354
+ _initialState: o.getState().initialStateGlobal[t],
355
+ _serverState: o.getState().serverState[t],
356
+ _isLoading: o.getState().isLoadingGlobal[t],
344
357
  _isServerSynced: () => {
345
- const o = a.getState().serverState[t];
346
- return !!(o && L(o, it(t)));
358
+ const l = o.getState().serverState[t];
359
+ return !!(l && L(l, ft(t)));
347
360
  }
348
361
  };
349
- function p(o, r = [], v) {
350
- const N = r.map(String).join("."), F = S.get(N);
351
- if (F?.stateVersion === I)
352
- return F.proxy;
353
- const c = {
354
- get(B, s) {
355
- if (s !== "then" && !s.startsWith("$")) {
356
- const e = r.join("."), n = `${t}////${d}`, l = a.getState().stateComponents.get(t);
357
- if (l && e) {
358
- const g = l.components.get(n);
359
- g && g.paths.add(e);
362
+ function E(l, e = [], v) {
363
+ const h = e.map(String).join(".");
364
+ g.get(h);
365
+ const F = {
366
+ get(d, a) {
367
+ if (a !== "then" && !a.startsWith("$") && a !== "stateMapNoRender") {
368
+ const n = e.join("."), s = `${t}////${f}`, c = o.getState().stateComponents.get(t);
369
+ if (c) {
370
+ const r = c.components.get(s);
371
+ r && (e.length > 0 || a === "get") && r.paths.add(n);
360
372
  }
361
373
  }
362
- if (Array.isArray(o)) {
363
- if (s === "getSelected")
374
+ if (a === "showValidationErrors")
375
+ return () => {
376
+ const n = o.getState().getInitialOptions(t)?.validation;
377
+ if (!n?.key)
378
+ throw new Error("Validation key not found");
379
+ return o.getState().getValidationErrors(n.key + "." + e.join("."));
380
+ };
381
+ if (Array.isArray(l)) {
382
+ if (a === "getSelected")
364
383
  return () => {
365
- const e = E.get(
366
- r.join(".")
367
- );
368
- if (e !== void 0)
369
- return p(
370
- o[e],
371
- [...r, e.toString()],
384
+ const n = p.get(e.join("."));
385
+ if (n !== void 0)
386
+ return E(
387
+ l[n],
388
+ [...e, n.toString()],
372
389
  v
373
390
  );
374
391
  };
375
- if (s === "stateMap")
376
- return (e) => {
377
- const n = v?.filtered?.some(
378
- (g) => g.join(".") === r.join(".")
379
- ), l = n ? o : a.getState().getNestedState(t, r);
380
- return S.clear(), I++, l.map((g, m) => {
381
- const $ = n && g.__origIndex ? g.__origIndex : m, P = p(
382
- g,
383
- [...r, $.toString()],
392
+ if (a === "stateMap" || a === "stateMapNoRender")
393
+ return (n) => {
394
+ const s = v?.filtered?.some(
395
+ (r) => r.join(".") === e.join(".")
396
+ ), c = s ? l : o.getState().getNestedState(t, e);
397
+ return a !== "stateMapNoRender" && (g.clear(), I++), c.map((r, u) => {
398
+ const w = s && r.__origIndex ? r.__origIndex : u, M = E(
399
+ r,
400
+ [...e, w.toString()],
384
401
  v
385
402
  );
386
- return e(
387
- g,
388
- P,
389
- m,
390
- o,
391
- p(
392
- o,
393
- r,
394
- v
395
- )
403
+ return n(
404
+ r,
405
+ M,
406
+ u,
407
+ l,
408
+ E(l, e, v)
396
409
  );
397
410
  });
398
411
  };
399
- if (s === "$stateMap")
400
- return (e) => w.createElement($t, {
412
+ if (a === "$stateMap")
413
+ return (n) => H(Ot, {
401
414
  proxy: {
402
415
  _stateKey: t,
403
- _path: r,
404
- _mapFn: e
416
+ _path: e,
417
+ _mapFn: n
405
418
  // Pass the actual function, not string
406
- }
419
+ },
420
+ rebuildStateShape: E
407
421
  });
408
- if (s === "stateFlattenOn")
409
- return (e) => {
410
- const l = v?.filtered?.some(
411
- (m) => m.join(".") === r.join(".")
412
- ) ? o : a.getState().getNestedState(t, r);
413
- S.clear(), I++;
414
- const g = l.flatMap(
415
- (m, $) => m[e] ?? []
422
+ if (a === "stateFlattenOn")
423
+ return (n) => {
424
+ const c = v?.filtered?.some(
425
+ (u) => u.join(".") === e.join(".")
426
+ ) ? l : o.getState().getNestedState(t, e);
427
+ g.clear(), I++;
428
+ const r = c.flatMap(
429
+ (u, w) => u[n] ?? []
416
430
  );
417
- return p(
418
- g,
419
- [...r, "[*]", e],
431
+ return E(
432
+ r,
433
+ [...e, "[*]", n],
420
434
  v
421
435
  );
422
436
  };
423
- if (s === "findWith")
424
- return (e, n) => {
425
- const l = o.findIndex(
426
- ($) => $[e] === n
437
+ if (a === "findWith")
438
+ return (n, s) => {
439
+ const c = l.findIndex(
440
+ (w) => w[n] === s
427
441
  );
428
- if (l === -1) return;
429
- const g = o[l], m = [...r, l.toString()];
430
- return S.clear(), I++, S.clear(), I++, p(g, m);
442
+ if (c === -1) return;
443
+ const r = l[c], u = [...e, c.toString()];
444
+ return g.clear(), I++, g.clear(), I++, E(r, u);
431
445
  };
432
- if (s === "index")
433
- return (e) => {
434
- const n = o[e];
435
- return p(n, [
436
- ...r,
437
- e.toString()
438
- ]);
446
+ if (a === "index")
447
+ return (n) => {
448
+ const s = l[n];
449
+ return E(s, [...e, n.toString()]);
439
450
  };
440
- if (s === "insert")
441
- return (e) => (_(r), Z(
442
- i,
443
- e,
444
- r,
445
- t
446
- ), p(
447
- a.getState().cogsStateStore[t],
451
+ if (a === "insert")
452
+ return (n) => (_(e), it(i, n, e, t), E(
453
+ o.getState().cogsStateStore[t],
448
454
  []
449
455
  ));
450
- if (s === "uniqueInsert")
451
- return (e, n) => {
452
- const l = a.getState().getNestedState(t, r), g = at(e) ? e(l) : e;
453
- !l.some(($) => n ? n.every(
454
- (P) => L(
455
- $[P],
456
- g[P]
457
- )
458
- ) : L($, g)) && (_(r), Z(
459
- i,
460
- g,
461
- r,
462
- t
463
- ));
456
+ if (a === "uniqueInsert")
457
+ return (n, s, c) => {
458
+ const r = o.getState().getNestedState(t, e), u = ut(n) ? n(r) : n;
459
+ let w = null;
460
+ if (!r.some((V) => {
461
+ if (s) {
462
+ const C = s.every(
463
+ (W) => L(V[W], u[W])
464
+ );
465
+ return C && (w = V), C;
466
+ }
467
+ const j = L(V, u);
468
+ return j && (w = V), j;
469
+ }))
470
+ _(e), it(i, u, e, t);
471
+ else if (c && w) {
472
+ const V = c(w), j = r.map(
473
+ (C) => L(C, w) ? V : C
474
+ );
475
+ _(e), q(i, j, e);
476
+ }
464
477
  };
465
- if (s === "cut")
466
- return (e, n) => {
467
- n?.waitForSync || (_(r), K(i, r, t, e));
478
+ if (a === "cut")
479
+ return (n, s) => {
480
+ s?.waitForSync || (_(e), st(i, e, t, n));
468
481
  };
469
- if (s === "stateFilter")
470
- return (e) => {
471
- const n = o.map(
472
- (m, $) => ({
473
- ...m,
474
- __origIndex: $.toString()
475
- })
476
- ), l = [], g = [];
477
- for (let m = 0; m < n.length; m++)
478
- e(n[m], m) && (l.push(m), g.push(n[m]));
479
- return S.clear(), I++, p(
480
- g,
481
- r,
482
- {
483
- filtered: [...v?.filtered || [], r],
484
- validIndices: l
485
- // Pass through the meta
486
- }
487
- );
482
+ if (a === "stateFilter")
483
+ return (n) => {
484
+ const s = l.map((u, w) => ({
485
+ ...u,
486
+ __origIndex: w.toString()
487
+ })), c = [], r = [];
488
+ for (let u = 0; u < s.length; u++)
489
+ n(s[u], u) && (c.push(u), r.push(s[u]));
490
+ return g.clear(), I++, E(r, e, {
491
+ filtered: [...v?.filtered || [], e],
492
+ validIndices: c
493
+ // Pass through the meta
494
+ });
488
495
  };
489
496
  }
490
- const A = r[r.length - 1];
491
- if (!isNaN(Number(A))) {
492
- const e = r.slice(0, -1), n = a.getState().getNestedState(t, e);
493
- if (Array.isArray(n) && s === "cut")
494
- return () => K(
497
+ const G = e[e.length - 1];
498
+ if (!isNaN(Number(G))) {
499
+ const n = e.slice(0, -1), s = o.getState().getNestedState(t, n);
500
+ if (Array.isArray(s) && a === "cut")
501
+ return () => st(
495
502
  i,
496
- e,
503
+ n,
497
504
  t,
498
- Number(A)
505
+ Number(G)
499
506
  );
500
507
  }
501
- if (s === "get")
502
- return () => a.getState().getNestedState(t, r);
503
- if (s === "$effect")
504
- return (e) => rt({
508
+ if (a === "get")
509
+ return () => o.getState().getNestedState(t, e);
510
+ if (a === "$derive")
511
+ return (n) => X({
505
512
  _stateKey: t,
506
- _path: r,
507
- _effect: e.toString()
513
+ _path: e,
514
+ _effect: n.toString()
508
515
  });
509
- if (s === "$get")
510
- return () => rt({
516
+ if (a === "$derive")
517
+ return (n) => X({
511
518
  _stateKey: t,
512
- _path: r
519
+ _path: e,
520
+ _effect: n.toString()
513
521
  });
514
- if (s === "lastSynced") {
515
- const e = `${t}:${r.join(".")}`;
516
- return a.getState().getSyncInfo(e);
522
+ if (a === "$get")
523
+ return () => X({
524
+ _stateKey: t,
525
+ _path: e
526
+ });
527
+ if (a === "lastSynced") {
528
+ const n = `${t}:${e.join(".")}`;
529
+ return o.getState().getSyncInfo(n);
517
530
  }
518
- if (s === "_selected") {
519
- const e = r.slice(0, -1), n = e.join("."), l = a.getState().getNestedState(t, e);
520
- return Array.isArray(l) ? Number(r[r.length - 1]) === E.get(n) : void 0;
531
+ if (a === "_selected") {
532
+ const n = e.slice(0, -1), s = n.join("."), c = o.getState().getNestedState(t, n);
533
+ return Array.isArray(c) ? Number(e[e.length - 1]) === p.get(s) : void 0;
521
534
  }
522
- if (s == "getLocalStorage")
523
- return (e) => ot(
524
- u + "-" + t + "-" + e
525
- );
526
- if (s === "setSelected")
527
- return (e) => {
528
- const n = r.slice(0, -1), l = Number(r[r.length - 1]), g = n.join(".");
529
- e ? E.set(g, l) : E.delete(g);
530
- const m = a.getState().getNestedState(t, [...n]);
531
- tt(i, m, n), _(n);
535
+ if (a == "getLocalStorage")
536
+ return (n) => gt(S + "-" + t + "-" + n);
537
+ if (a === "setSelected")
538
+ return (n) => {
539
+ const s = e.slice(0, -1), c = Number(e[e.length - 1]), r = s.join(".");
540
+ n ? p.set(r, c) : p.delete(r);
541
+ const u = o.getState().getNestedState(t, [...s]);
542
+ q(i, u, s), _(s);
532
543
  };
533
- if (r.length == 0) {
534
- if (s == "_componentId") return d;
535
- if (s === "_initialState")
536
- return a.getState().initialStateGlobal[t];
537
- if (s === "_serverState")
538
- return a.getState().serverState[t];
539
- if (s === "_isLoading")
540
- return a.getState().isLoadingGlobal[t];
541
- if (s === "revertToInitialState")
542
- return y.revertToInitialState;
543
- if (s === "updateInitialState")
544
- return y.updateInitialState;
545
- if (s === "removeValidation")
546
- return y.removeValidation;
544
+ if (e.length == 0) {
545
+ if (a === "validateZodSchema")
546
+ return () => {
547
+ const n = o.getState().getInitialOptions(t)?.validation, s = o.getState().addValidationError;
548
+ if (!n?.zodSchema)
549
+ throw new Error("Zod schema not found");
550
+ if (!n?.key)
551
+ throw new Error("Validation key not found");
552
+ R(n.key);
553
+ const c = o.getState().cogsStateStore[t];
554
+ try {
555
+ const r = o.getState().getValidationErrors(n.key);
556
+ r && r.length > 0 && r.forEach(([w]) => {
557
+ w && w.startsWith(n.key) && R(w);
558
+ });
559
+ const u = n.zodSchema.safeParse(c);
560
+ return u.success ? !0 : (u.error.errors.forEach((M) => {
561
+ const V = M.path, j = M.message, C = [n.key, ...V].join(".");
562
+ s(C, j), console.log(
563
+ `Validation error at ${C}: ${j}`
564
+ );
565
+ }), Mt(t), !1);
566
+ } catch (r) {
567
+ return console.error("Zod schema validation failed", r), !1;
568
+ }
569
+ };
570
+ if (a === "_componentId") return f;
571
+ if (a === "getComponents")
572
+ return () => o().stateComponents.get(t);
573
+ if (a === "getAllFormRefs")
574
+ return () => ct.getState().getFormRefsByStateKey(t);
575
+ if (a === "_initialState")
576
+ return o.getState().initialStateGlobal[t];
577
+ if (a === "_serverState")
578
+ return o.getState().serverState[t];
579
+ if (a === "_isLoading")
580
+ return o.getState().isLoadingGlobal[t];
581
+ if (a === "revertToInitialState")
582
+ return m.revertToInitialState;
583
+ if (a === "updateInitialState") return m.updateInitialState;
584
+ if (a === "removeValidation") return m.removeValidation;
547
585
  }
548
- if (s === "validationWrapper")
586
+ if (a === "getFormRef")
587
+ return () => ct.getState().getFormRef(t + "." + e.join("."));
588
+ if (a === "validationWrapper")
549
589
  return ({
550
- children: e,
551
- hideMessage: n
552
- }) => /* @__PURE__ */ Y.jsx(
553
- St,
590
+ children: n,
591
+ hideMessage: s
592
+ }) => /* @__PURE__ */ at(
593
+ wt,
554
594
  {
555
- formOpts: n ? { validation: { message: "" } } : void 0,
556
- path: r,
557
- validationKey: a.getState().getInitialOptions(t)?.validationKey || "",
595
+ formOpts: s ? { validation: { message: "" } } : void 0,
596
+ path: e,
597
+ validationKey: o.getState().getInitialOptions(t)?.validation?.key || "",
558
598
  stateKey: t,
559
599
  validIndices: v?.validIndices,
560
- children: e
600
+ children: n
561
601
  }
562
602
  );
563
- if (s === "_stateKey") return t;
564
- if (s === "_path") return r;
565
- if (s === "_isServerSynced") return y._isServerSynced;
566
- if (s === "update")
567
- return (e, n) => {
568
- _(r), tt(i, e, r, "");
603
+ if (a === "_stateKey") return t;
604
+ if (a === "_path") return e;
605
+ if (a === "_isServerSynced") return m._isServerSynced;
606
+ if (a === "update")
607
+ return (n, s) => {
608
+ if (s?.debounce)
609
+ Et(() => {
610
+ q(i, n, e, "");
611
+ const c = o.getState().getNestedState(t, e);
612
+ s?.afterUpdate && s.afterUpdate(c);
613
+ }, s.debounce);
614
+ else {
615
+ q(i, n, e, "");
616
+ const c = o.getState().getNestedState(t, e);
617
+ s?.afterUpdate && s.afterUpdate(c);
618
+ }
619
+ _(e);
569
620
  };
570
- if (s === "formElement")
571
- return (e, n, l) => /* @__PURE__ */ Y.jsx(
572
- gt,
621
+ if (a === "formElement")
622
+ return (n, s) => /* @__PURE__ */ at(
623
+ $t,
573
624
  {
574
625
  setState: i,
575
- validationKey: e,
576
626
  stateKey: t,
577
- path: r,
627
+ path: e,
578
628
  child: n,
579
- formOpts: l
629
+ formOpts: s
580
630
  }
581
631
  );
582
- const h = [...r, s], q = a.getState().getNestedState(t, h);
583
- return p(q, h, v);
632
+ const b = [...e, a], A = o.getState().getNestedState(t, b);
633
+ return E(A, b, v);
584
634
  }
585
- }, b = new Proxy(y, c);
586
- return S.set(N, {
587
- proxy: b,
635
+ }, U = new Proxy(m, F);
636
+ return g.set(h, {
637
+ proxy: U,
588
638
  stateVersion: I
589
- }), b;
639
+ }), U;
590
640
  }
591
- return p(
592
- a.getState().getNestedState(t, [])
641
+ return E(
642
+ o.getState().getNestedState(t, [])
593
643
  );
594
644
  }
595
- function rt(t) {
596
- return w.createElement(Nt, { proxy: t });
645
+ function X(t) {
646
+ return H(Ut, { proxy: t });
597
647
  }
598
- function $t({
599
- proxy: t
648
+ function Ot({
649
+ proxy: t,
650
+ rebuildStateShape: i
600
651
  }) {
601
- const i = a().getNestedState(t._stateKey, t._path);
602
- return console.log("value", i), Array.isArray(i) ? i.map((d, u) => t._mapFn(
603
- d,
604
- a.getState().updaterState[t._stateKey],
605
- u,
606
- i,
607
- a.getState().updaterState[t._stateKey]
608
- )) : null;
652
+ const f = o().getNestedState(t._stateKey, t._path);
653
+ return console.log("value", f), Array.isArray(f) ? i(
654
+ f,
655
+ t._path
656
+ ).stateMapNoRender(
657
+ (g, I, _, p, m) => t._mapFn(g, I, _, p, m)
658
+ ) : null;
609
659
  }
610
- function Nt({
660
+ function Ut({
611
661
  proxy: t
612
662
  }) {
613
- const i = w.useRef(null), d = `${t._stateKey}-${t._path.join(".")}`;
614
- return console.log("SignalRenderer", d), w.useEffect(() => {
615
- const u = i.current;
616
- if (!u || !u.parentElement) return;
617
- const S = u.parentElement, _ = Array.from(S.childNodes).indexOf(u);
618
- let E = S.getAttribute("data-parent-id");
619
- E || (E = `parent-${crypto.randomUUID()}`, S.setAttribute("data-parent-id", E));
620
- const p = {
663
+ const i = z(null), f = `${t._stateKey}-${t._path.join(".")}`;
664
+ return K(() => {
665
+ const S = i.current;
666
+ if (!S || !S.parentElement) return;
667
+ const g = S.parentElement, _ = Array.from(g.childNodes).indexOf(S);
668
+ let p = g.getAttribute("data-parent-id");
669
+ p || (p = `parent-${crypto.randomUUID()}`, g.setAttribute("data-parent-id", p));
670
+ const E = {
621
671
  instanceId: `instance-${crypto.randomUUID()}`,
622
- parentId: E,
672
+ parentId: p,
623
673
  position: _,
624
674
  effect: t._effect
625
675
  };
626
- a.getState().addSignalElement(d, p);
627
- const o = a.getState().getNestedState(t._stateKey, t._path), r = document.createTextNode(String(o));
628
- u.replaceWith(r);
629
- }, [t._stateKey, t._path.join("."), t._effect]), w.createElement("span", {
676
+ o.getState().addSignalElement(f, E);
677
+ const l = o.getState().getNestedState(t._stateKey, t._path);
678
+ let e;
679
+ if (t._effect)
680
+ try {
681
+ e = new Function(
682
+ "state",
683
+ `return (${t._effect})(state)`
684
+ )(l);
685
+ } catch (h) {
686
+ console.error("Error evaluating effect function during mount:", h), e = l;
687
+ }
688
+ else
689
+ e = l;
690
+ e !== null && typeof e == "object" && (e = JSON.stringify(e));
691
+ const v = document.createTextNode(String(e));
692
+ S.replaceWith(v);
693
+ }, [t._stateKey, t._path.join("."), t._effect]), H("span", {
630
694
  ref: i,
631
695
  style: { display: "none" },
632
- "data-signal-id": d
696
+ "data-signal-id": f
633
697
  });
634
698
  }
635
- function Dt(t) {
636
- const i = w.useSyncExternalStore(
637
- (d) => {
638
- const u = a.getState().stateComponents.get(t._stateKey) || {
699
+ function Jt(t) {
700
+ const i = pt(
701
+ (f) => {
702
+ const S = o.getState().stateComponents.get(t._stateKey) || {
639
703
  components: /* @__PURE__ */ new Map()
640
704
  };
641
- return u.components.set(t._stateKey, {
642
- forceUpdate: d,
705
+ return S.components.set(t._stateKey, {
706
+ forceUpdate: f,
643
707
  paths: /* @__PURE__ */ new Set([t._path.join(".")])
644
- }), () => u.components.delete(t._stateKey);
708
+ }), () => S.components.delete(t._stateKey);
645
709
  },
646
- () => a.getState().getNestedState(t._stateKey, t._path)
710
+ () => o.getState().getNestedState(t._stateKey, t._path)
647
711
  );
648
- return w.createElement("text", {}, String(i));
712
+ return H("text", {}, String(i));
649
713
  }
650
714
  export {
651
- rt as $cogsSignal,
652
- Dt as $cogsSignalStore,
653
- Mt as addStateOptions,
654
- Ot as createCogsState,
655
- wt as useCogsStateFn
715
+ X as $cogsSignal,
716
+ Jt as $cogsSignalStore,
717
+ qt as createCogsState,
718
+ zt as notifyComponent,
719
+ jt as useCogsStateFn
656
720
  };
657
721
  //# sourceMappingURL=CogsState.jsx.map