cogsbox-state 0.5.156 → 0.5.157

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 (29) hide show
  1. package/dist/CogsState.jsx +67 -66
  2. package/dist/CogsState.jsx.map +1 -1
  3. package/dist/node_modules/copy-anything/dist/index.js +27 -0
  4. package/dist/node_modules/copy-anything/dist/index.js.map +1 -0
  5. package/dist/node_modules/is-what/dist/index.js +18 -0
  6. package/dist/node_modules/is-what/dist/index.js.map +1 -0
  7. package/dist/node_modules/superjson/dist/accessDeep.js +92 -0
  8. package/dist/node_modules/superjson/dist/accessDeep.js.map +1 -0
  9. package/dist/node_modules/superjson/dist/class-registry.js +16 -0
  10. package/dist/node_modules/superjson/dist/class-registry.js.map +1 -0
  11. package/dist/node_modules/superjson/dist/custom-transformer-registry.js +19 -0
  12. package/dist/node_modules/superjson/dist/custom-transformer-registry.js.map +1 -0
  13. package/dist/node_modules/superjson/dist/double-indexed-kv.js +21 -0
  14. package/dist/node_modules/superjson/dist/double-indexed-kv.js.map +1 -0
  15. package/dist/node_modules/superjson/dist/index.js +75 -0
  16. package/dist/node_modules/superjson/dist/index.js.map +1 -0
  17. package/dist/node_modules/superjson/dist/is.js +24 -0
  18. package/dist/node_modules/superjson/dist/is.js.map +1 -0
  19. package/dist/node_modules/superjson/dist/pathstringifier.js +24 -0
  20. package/dist/node_modules/superjson/dist/pathstringifier.js.map +1 -0
  21. package/dist/node_modules/superjson/dist/plainer.js +102 -0
  22. package/dist/node_modules/superjson/dist/plainer.js.map +1 -0
  23. package/dist/node_modules/superjson/dist/registry.js +22 -0
  24. package/dist/node_modules/superjson/dist/registry.js.map +1 -0
  25. package/dist/node_modules/superjson/dist/transformer.js +140 -0
  26. package/dist/node_modules/superjson/dist/transformer.js.map +1 -0
  27. package/dist/node_modules/superjson/dist/util.js +39 -0
  28. package/dist/node_modules/superjson/dist/util.js.map +1 -0
  29. package/package.json +2 -1
@@ -1,11 +1,12 @@
1
1
  "use client";
2
2
  import { jsx as ue } from "react/jsx-runtime";
3
- import { useState as re, useRef as Y, useEffect as ae, useLayoutEffect as Ee, useMemo as _e, createElement as K, useSyncExternalStore as Ne, startTransition as we } from "react";
4
- import { transformStateFunc as $e, isFunction as W, isDeepEqual as F, getNestedValue as L, getDifferences as me, debounce as he } from "./utility.js";
5
- import { pushFunc as te, updateFn as B, cutFunc as H, ValidationWrapper as Ae, FormControlComponent as Ve } from "./Functions.jsx";
3
+ import { useState as re, useRef as Y, useEffect as ae, useLayoutEffect as _e, useMemo as Ne, createElement as K, useSyncExternalStore as we, startTransition as $e } from "react";
4
+ import { transformStateFunc as he, isFunction as W, isDeepEqual as F, getNestedValue as L, getDifferences as me, debounce as Ae } from "./utility.js";
5
+ import { pushFunc as te, updateFn as B, cutFunc as H, ValidationWrapper as Ve, FormControlComponent as Te } from "./Functions.jsx";
6
+ import ye from "./node_modules/superjson/dist/index.js";
6
7
  import "zod";
7
8
  import { getGlobalStore as r, formRefStore as ge } from "./store.js";
8
- import { useCogsConfig as Te } from "./CogsStateClient.jsx";
9
+ import { useCogsConfig as xe } from "./CogsStateClient.jsx";
9
10
  import oe from "./node_modules/uuid/dist/esm-browser/v4.js";
10
11
  function fe(e, i) {
11
12
  const v = r.getState().getInitialOptions, S = r.getState().setInitialStateOptions, u = v(e) || {};
@@ -27,12 +28,12 @@ function Se({
27
28
  !F(E[c], i[c]) && (m = !0, E[c] = i[c])) : (m = !0, E[c] = i[c]);
28
29
  m && N(e, E);
29
30
  }
30
- function Be(e, { formElements: i, validation: v }) {
31
+ function Ze(e, { formElements: i, validation: v }) {
31
32
  return { initialState: e, formElements: i, validation: v };
32
33
  }
33
- const Je = (e, i) => {
34
+ const He = (e, i) => {
34
35
  let v = e;
35
- const [S, u] = $e(v);
36
+ const [S, u] = he(v);
36
37
  (Object.keys(u).length > 0 || i && Object.keys(i).length > 0) && Object.keys(u).forEach((m) => {
37
38
  u[m] = u[m] || {}, u[m].formElements = {
38
39
  ...i?.formElements,
@@ -45,12 +46,12 @@ const Je = (e, i) => {
45
46
  const N = (m, c) => {
46
47
  const [f] = re(c?.componentId ?? oe());
47
48
  if (c && typeof c.initialState < "u" && W(c.initialState)) {
48
- const C = r.getState().cogsStateStore[m] || S[m], R = c.initialState(
49
+ const C = r.getState().cogsStateStore[m] || S[m], p = c.initialState(
49
50
  C
50
51
  );
51
52
  c = {
52
53
  ...c,
53
- initialState: R
54
+ initialState: p
54
55
  };
55
56
  }
56
57
  Se({
@@ -58,7 +59,7 @@ const Je = (e, i) => {
58
59
  options: c,
59
60
  initialOptionsPart: u
60
61
  });
61
- const t = r.getState().cogsStateStore[m] || S[m], y = c?.modifyState ? c.modifyState(t) : t, [j, V] = Oe(
62
+ const t = r.getState().cogsStateStore[m] || S[m], y = c?.modifyState ? c.modifyState(t) : t, [j, V] = Fe(
62
63
  y,
63
64
  {
64
65
  stateKey: m,
@@ -83,22 +84,22 @@ const Je = (e, i) => {
83
84
  setUpdaterState: X,
84
85
  setState: q,
85
86
  getInitialOptions: J,
86
- getKeyState: ye,
87
- getValidationErrors: xe,
88
- setStateLog: be,
87
+ getKeyState: ve,
88
+ getValidationErrors: be,
89
+ setStateLog: ke,
89
90
  updateInitialStateGlobal: ie,
90
- addValidationError: ke,
91
+ addValidationError: Ce,
91
92
  removeValidationError: D,
92
- setServerSyncActions: Ce
93
- } = r.getState(), ve = (e) => {
93
+ setServerSyncActions: Pe
94
+ } = r.getState(), Ie = (e) => {
94
95
  if (!e) return null;
95
96
  try {
96
97
  const i = window.localStorage.getItem(e);
97
- return i ? JSON.parse(i) : null;
98
+ return i ? ye.parse(i) : null;
98
99
  } catch (i) {
99
100
  return console.error("Error loading from localStorage:", i), null;
100
101
  }
101
- }, Pe = (e, i, v, S) => {
102
+ }, je = (e, i, v, S) => {
102
103
  v?.log && console.log(
103
104
  "saving to localstorage",
104
105
  i,
@@ -113,9 +114,9 @@ const Je = (e, i) => {
113
114
  lastSyncedWithServer: r.getState().serverSyncLog[i]?.[0]?.timeStamp,
114
115
  baseServerState: r.getState().serverState[i]
115
116
  }, E = `${S}-${i}-${u}`;
116
- window.localStorage.setItem(E, JSON.stringify(N));
117
+ window.localStorage.setItem(E, ye.stringify(N));
117
118
  }
118
- }, je = (e, i, v, S, u, N) => {
119
+ }, Oe = (e, i, v, S, u, N) => {
119
120
  const E = {
120
121
  initialState: i,
121
122
  updaterState: Q(
@@ -136,7 +137,7 @@ const Je = (e, i) => {
136
137
  }), queueMicrotask(() => {
137
138
  v.forEach((S) => S());
138
139
  });
139
- }, Ze = (e, i) => {
140
+ }, Ye = (e, i) => {
140
141
  const v = r.getState().stateComponents.get(e);
141
142
  if (v) {
142
143
  const S = `${e}////${i}`, u = v.components.get(S);
@@ -145,7 +146,7 @@ const Je = (e, i) => {
145
146
  u && u.forceUpdate();
146
147
  }
147
148
  };
148
- function Oe(e, {
149
+ function Fe(e, {
149
150
  stateKey: i,
150
151
  serverSync: v,
151
152
  localStorage: S,
@@ -158,8 +159,8 @@ function Oe(e, {
158
159
  syncUpdate: t,
159
160
  dependencies: y
160
161
  } = {}) {
161
- const [j, V] = re({}), { sessionId: C } = Te();
162
- let R = !i;
162
+ const [j, V] = re({}), { sessionId: C } = xe();
163
+ let p = !i;
163
164
  const [g] = re(i ?? oe()), s = r.getState().stateLog[g], z = Y(/* @__PURE__ */ new Set()), G = Y(c ?? oe()), x = Y(null);
164
165
  x.current = J(g), ae(() => {
165
166
  if (t && t.stateKey === g && t.path?.[0]) {
@@ -181,7 +182,7 @@ function Oe(e, {
181
182
  const d = x.current;
182
183
  let a = null;
183
184
  const l = W(d?.localStorage?.key) ? d?.localStorage?.key(f) : d?.localStorage?.key;
184
- l && C && (a = ve(
185
+ l && C && (a = Ie(
185
186
  C + "-" + g + "-" + l
186
187
  ));
187
188
  const I = r.getState().initialStateGlobal[g];
@@ -192,7 +193,7 @@ function Oe(e, {
192
193
  F(I, f)
193
194
  ), I && !F(I, f) || !I) {
194
195
  let $ = f;
195
- a && a.lastUpdated > (a.lastSyncedWithServer || 0) && ($ = a.state, d?.localStorage?.onChange && d?.localStorage?.onChange($)), je(
196
+ a && a.lastUpdated > (a.lastSyncedWithServer || 0) && ($ = a.state, d?.localStorage?.onChange && d?.localStorage?.onChange($)), Oe(
196
197
  g,
197
198
  f,
198
199
  $,
@@ -202,8 +203,8 @@ function Oe(e, {
202
203
  ), se(g), (Array.isArray(m) ? m : [m || "component"]).includes("none") || V({});
203
204
  }
204
205
  }
205
- }, [f, ...y || []]), Ee(() => {
206
- R && fe(g, {
206
+ }, [f, ...y || []]), _e(() => {
207
+ p && fe(g, {
207
208
  serverSync: v,
208
209
  formElements: u,
209
210
  initialState: f,
@@ -230,9 +231,9 @@ function Oe(e, {
230
231
  z.current.add($);
231
232
  }
232
233
  q(g, ($) => {
233
- const w = W(d) ? d($) : d, p = `${g}-${a.join(".")}`;
234
- if (p) {
235
- let M = !1, h = r.getState().signalDomElements.get(p);
234
+ const w = W(d) ? d($) : d, R = `${g}-${a.join(".")}`;
235
+ if (R) {
236
+ let M = !1, h = r.getState().signalDomElements.get(R);
236
237
  if ((!h || h.size === 0) && (l.updateType === "insert" || l.updateType === "cut")) {
237
238
  const P = a.slice(0, -1), O = L(w, P);
238
239
  if (Array.isArray(O)) {
@@ -263,16 +264,16 @@ function Oe(e, {
263
264
  const b = a.slice(0, a.length - 1);
264
265
  l.updateType === "cut" && x.current?.validationKey && D(
265
266
  x.current?.validationKey + "." + b.join(".")
266
- ), l.updateType === "insert" && x.current?.validationKey && xe(
267
+ ), l.updateType === "insert" && x.current?.validationKey && be(
267
268
  x.current?.validationKey + "." + b.join(".")
268
269
  ).filter(([h, P]) => {
269
270
  let O = h?.split(".").length;
270
271
  if (h == b.join(".") && O == b.length - 1) {
271
272
  let _ = h + "." + b;
272
- D(h), ke(_, P);
273
+ D(h), Ce(_, P);
273
274
  }
274
275
  });
275
- const Z = L($, a), Ie = L(w, a);
276
+ const Z = L($, a), Ee = L(w, a);
276
277
  l.updateType === "update" ? a.join(".") : [...a].slice(0, -1).join(".");
277
278
  const ce = r.getState().stateComponents.get(g);
278
279
  if (ce) {
@@ -332,15 +333,15 @@ function Oe(e, {
332
333
  updateType: l.updateType,
333
334
  status: "new",
334
335
  oldValue: Z,
335
- newValue: Ie
336
+ newValue: Ee
336
337
  };
337
- if (be(g, (M) => {
338
+ if (ke(g, (M) => {
338
339
  const P = [...M ?? [], le].reduce((O, _) => {
339
340
  const T = `${_.stateKey}:${JSON.stringify(_.path)}`, A = O.get(T);
340
341
  return A ? (A.timeStamp = Math.max(A.timeStamp, _.timeStamp), A.newValue = _.newValue, A.oldValue = A.oldValue ?? _.oldValue, A.updateType = _.updateType) : O.set(T, { ..._ }), O;
341
342
  }, /* @__PURE__ */ new Map());
342
343
  return Array.from(P.values());
343
- }), Pe(
344
+ }), je(
344
345
  w,
345
346
  g,
346
347
  x.current,
@@ -350,7 +351,7 @@ function Oe(e, {
350
351
  update: le
351
352
  }), x.current?.serverSync) {
352
353
  const M = r.getState().serverState[g], h = x.current?.serverSync;
353
- Ce(g, {
354
+ Pe(g, {
354
355
  syncKey: typeof h.syncKey == "string" ? h.syncKey : h.syncKey({ state: w }),
355
356
  rollBackState: M,
356
357
  actionTimeStamp: Date.now() + (h.debounce ?? 3e3),
@@ -369,13 +370,13 @@ function Oe(e, {
369
370
  C
370
371
  )
371
372
  ), r.getState().cogsStateStore[g] || q(g, e), r.getState().initialStateGlobal[g] || ie(g, e));
372
- const o = _e(() => Q(
373
+ const o = Ne(() => Q(
373
374
  g,
374
375
  n,
375
376
  G.current,
376
377
  C
377
378
  ), [g]);
378
- return [ye(g), o];
379
+ return [ve(g), o];
379
380
  }
380
381
  function Q(e, i, v, S) {
381
382
  const u = /* @__PURE__ */ new Map();
@@ -394,8 +395,8 @@ function Q(e, i, v, S) {
394
395
  t?.key && D(t?.key), f?.validationKey && D(f.validationKey);
395
396
  const y = r.getState().initialStateGlobal[e];
396
397
  r.getState().clearSelectedIndexesForState(e), u.clear(), N++;
397
- const j = c(y, []), V = J(e), C = W(V?.localStorage?.key) ? V?.localStorage?.key(y) : V?.localStorage?.key, R = `${S}-${e}-${C}`;
398
- R && localStorage.removeItem(R), X(e, j), q(e, y);
398
+ const j = c(y, []), V = J(e), C = W(V?.localStorage?.key) ? V?.localStorage?.key(y) : V?.localStorage?.key, p = `${S}-${e}-${C}`;
399
+ p && localStorage.removeItem(p), X(e, j), q(e, y);
399
400
  const g = r.getState().stateComponents.get(e);
400
401
  return g && g.components.forEach((s) => {
401
402
  s.forceUpdate();
@@ -409,7 +410,7 @@ function Q(e, i, v, S) {
409
410
  v,
410
411
  S
411
412
  );
412
- return we(() => {
413
+ return $e(() => {
413
414
  ie(e, f), X(e, t), q(e, f);
414
415
  const y = r.getState().stateComponents.get(e);
415
416
  y && y.components.forEach((j) => {
@@ -424,7 +425,7 @@ function Q(e, i, v, S) {
424
425
  _isLoading: r.getState().isLoadingGlobal[e],
425
426
  _isServerSynced: () => {
426
427
  const f = r.getState().serverState[e];
427
- return !!(f && F(f, ye(e)));
428
+ return !!(f && F(f, ve(e)));
428
429
  }
429
430
  };
430
431
  function c(f, t = [], y) {
@@ -553,7 +554,7 @@ function Q(e, i, v, S) {
553
554
  });
554
555
  };
555
556
  if (s === "$stateMap")
556
- return (n) => K(Fe, {
557
+ return (n) => K(pe, {
557
558
  proxy: {
558
559
  _stateKey: e,
559
560
  _path: t,
@@ -612,15 +613,15 @@ function Q(e, i, v, S) {
612
613
  );
613
614
  return b && (I = w), b;
614
615
  }
615
- const p = F(w, l);
616
- return p && (I = w), p;
616
+ const R = F(w, l);
617
+ return R && (I = w), R;
617
618
  }))
618
619
  E(t), te(i, l, t, e);
619
620
  else if (d && I) {
620
- const w = d(I), p = a.map(
621
+ const w = d(I), R = a.map(
621
622
  (b) => F(b, I) ? w : b
622
623
  );
623
- E(t), B(i, p, t);
624
+ E(t), B(i, R, t);
624
625
  }
625
626
  };
626
627
  if (s === "cut")
@@ -691,7 +692,7 @@ function Q(e, i, v, S) {
691
692
  return r.getState().getSyncInfo(n);
692
693
  }
693
694
  if (s == "getLocalStorage")
694
- return (n) => ve(S + "-" + e + "-" + n);
695
+ return (n) => Ie(S + "-" + e + "-" + n);
695
696
  if (s === "_selected") {
696
697
  const n = t.slice(0, -1), o = n.join("."), d = r.getState().getNestedState(e, n);
697
698
  return Array.isArray(d) ? Number(t[t.length - 1]) === r.getState().getSelectedIndex(e, o) : void 0;
@@ -731,8 +732,8 @@ function Q(e, i, v, S) {
731
732
  });
732
733
  const l = n.zodSchema.safeParse(d);
733
734
  return l.success ? !0 : (l.error.errors.forEach(($) => {
734
- const w = $.path, p = $.message, b = [n.key, ...w].join(".");
735
- o(b, p);
735
+ const w = $.path, R = $.message, b = [n.key, ...w].join(".");
736
+ o(b, R);
736
737
  }), se(e), !1);
737
738
  } catch (a) {
738
739
  return console.error("Zod schema validation failed", a), !1;
@@ -761,7 +762,7 @@ function Q(e, i, v, S) {
761
762
  children: n,
762
763
  hideMessage: o
763
764
  }) => /* @__PURE__ */ ue(
764
- Ae,
765
+ Ve,
765
766
  {
766
767
  formOpts: o ? { validation: { message: "" } } : void 0,
767
768
  path: t,
@@ -777,7 +778,7 @@ function Q(e, i, v, S) {
777
778
  if (s === "update")
778
779
  return (n, o) => {
779
780
  if (o?.debounce)
780
- he(() => {
781
+ Ae(() => {
781
782
  B(i, n, t, "");
782
783
  const d = r.getState().getNestedState(e, t);
783
784
  o?.afterUpdate && o.afterUpdate(d);
@@ -791,7 +792,7 @@ function Q(e, i, v, S) {
791
792
  };
792
793
  if (s === "formElement")
793
794
  return (n, o) => /* @__PURE__ */ ue(
794
- Ve,
795
+ Te,
795
796
  {
796
797
  setState: i,
797
798
  stateKey: e,
@@ -803,11 +804,11 @@ function Q(e, i, v, S) {
803
804
  const G = [...t, s], x = r.getState().getNestedState(e, G);
804
805
  return c(x, G, y);
805
806
  }
806
- }, R = new Proxy(V, C);
807
+ }, p = new Proxy(V, C);
807
808
  return u.set(j, {
808
- proxy: R,
809
+ proxy: p,
809
810
  stateVersion: N
810
- }), R;
811
+ }), p;
811
812
  }
812
813
  return c(
813
814
  r.getState().getNestedState(e, [])
@@ -816,7 +817,7 @@ function Q(e, i, v, S) {
816
817
  function ne(e) {
817
818
  return K(Re, { proxy: e });
818
819
  }
819
- function Fe({
820
+ function pe({
820
821
  proxy: e,
821
822
  rebuildStateShape: i
822
823
  }) {
@@ -867,8 +868,8 @@ function Re({
867
868
  "data-signal-id": v
868
869
  });
869
870
  }
870
- function He(e) {
871
- const i = Ne(
871
+ function Xe(e) {
872
+ const i = we(
872
873
  (v) => {
873
874
  const S = r.getState().stateComponents.get(e._stateKey) || {
874
875
  components: /* @__PURE__ */ new Map()
@@ -884,10 +885,10 @@ function He(e) {
884
885
  }
885
886
  export {
886
887
  ne as $cogsSignal,
887
- He as $cogsSignalStore,
888
- Be as addStateOptions,
889
- Je as createCogsState,
890
- Ze as notifyComponent,
891
- Oe as useCogsStateFn
888
+ Xe as $cogsSignalStore,
889
+ Ze as addStateOptions,
890
+ He as createCogsState,
891
+ Ye as notifyComponent,
892
+ Fe as useCogsStateFn
892
893
  };
893
894
  //# sourceMappingURL=CogsState.jsx.map