cogsbox-state 0.5.3

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