cogsbox-state 0.5.484 → 0.5.485

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.
package/dist/CogsState.js CHANGED
@@ -1,9 +1,9 @@
1
1
  "use client";
2
2
  import { jsx as Q, Fragment as Te } from "react/jsx-runtime";
3
- import { pluginStore as z } from "./pluginStore.js";
4
- import { useState as ne, useRef as q, useCallback as ke, useEffect as Z, useLayoutEffect as re, useMemo as Ae, createElement as Se, startTransition as Ie } from "react";
5
- import { transformStateFunc as De, isFunction as R, isDeepEqual as X, isArray as Ce, getDifferences as _e } from "./utility.js";
6
- import { ValidationWrapper as Oe, IsolatedComponentWrapper as je, FormElementWrapper as Ue, MemoizedCogsItemWrapper as Ne } from "./Components.js";
3
+ import { pluginStore as R } from "./pluginStore.js";
4
+ import { useState as ne, useRef as q, useCallback as Ie, useEffect as Z, useLayoutEffect as re, useMemo as Ae, createElement as Se, startTransition as ke } from "react";
5
+ import { transformStateFunc as De, isFunction as L, isDeepEqual as X, isArray as Ce, getDifferences as _e } from "./utility.js";
6
+ import { ValidationWrapper as Oe, IsolatedComponentWrapper as je, FormElementWrapper as Ne, MemoizedCogsItemWrapper as Ue } from "./Components.js";
7
7
  import Fe from "superjson";
8
8
  import { v4 as ae } from "uuid";
9
9
  import { getGlobalStore as p, updateShadowTypeInfo as H } from "./store.js";
@@ -12,14 +12,14 @@ import { runValidation as ze } from "./validation.js";
12
12
  const {
13
13
  getInitialOptions: j,
14
14
  updateInitialStateGlobal: be,
15
- getShadowMetadata: $,
16
- setShadowMetadata: L,
15
+ getShadowMetadata: V,
16
+ setShadowMetadata: W,
17
17
  getShadowValue: C,
18
18
  initializeShadowState: K,
19
19
  initializeAndMergeShadowState: Re,
20
20
  updateShadowAtPath: Le,
21
21
  insertShadowArrayElement: We,
22
- insertManyShadowArrayElements: $e,
22
+ insertManyShadowArrayElements: Ve,
23
23
  removeShadowArrayElement: Be,
24
24
  setInitialStateOptions: ye,
25
25
  setServerStateUpdate: me,
@@ -33,17 +33,17 @@ const {
33
33
  getPluginMetaDataMap: he,
34
34
  setPluginMetaData: ve,
35
35
  removePluginMetaData: we
36
- } = p.getState(), { notifyUpdate: Ye } = z.getState();
37
- function N(e, n, c) {
38
- const i = $(e, n);
36
+ } = p.getState(), { notifyUpdate: Ye } = R.getState();
37
+ function F(e, n, l) {
38
+ const i = V(e, n);
39
39
  if (!!!i?.arrayKeys)
40
40
  return { isArray: !1, value: p.getState().getShadowValue(e, n), keys: [] };
41
- const l = n.length > 0 ? n.join(".") : "root", m = c?.arrayViews?.[l] ?? i.arrayKeys;
42
- return Array.isArray(m) && m.length === 0 ? { isArray: !0, value: [], keys: [] } : { isArray: !0, value: p.getState().getShadowValue(e, n, m), keys: m ?? [] };
41
+ const u = n.length > 0 ? n.join(".") : "root", h = l?.arrayViews?.[u] ?? i.arrayKeys;
42
+ return Array.isArray(h) && h.length === 0 ? { isArray: !0, value: [], keys: [] } : { isArray: !0, value: p.getState().getShadowValue(e, n, h), keys: h ?? [] };
43
43
  }
44
- function le(e, n, c) {
44
+ function le(e, n, l) {
45
45
  for (let i = 0; i < e.length; i++)
46
- if (c(e[i], i)) {
46
+ if (l(e[i], i)) {
47
47
  const f = n[i];
48
48
  if (f)
49
49
  return { key: f, index: i, value: e[i] };
@@ -60,61 +60,61 @@ function ue(e, n) {
60
60
  function fe({
61
61
  stateKey: e,
62
62
  options: n,
63
- initialOptionsPart: c
63
+ initialOptionsPart: l
64
64
  }) {
65
- const i = j(e) || {}, f = c[e] || {};
66
- let l = { ...f, ...i }, m = !1;
65
+ const i = j(e) || {}, f = l[e] || {};
66
+ let u = { ...f, ...i }, h = !1;
67
67
  if (n) {
68
- const y = (t, a) => {
69
- for (const d in a)
70
- a.hasOwnProperty(d) && (a[d] instanceof Object && !Array.isArray(a[d]) && t[d] instanceof Object ? X(t[d], a[d]) || (y(t[d], a[d]), m = !0) : t[d] !== a[d] && (t[d] = a[d], m = !0));
68
+ const y = (t, o) => {
69
+ for (const d in o)
70
+ o.hasOwnProperty(d) && (o[d] instanceof Object && !Array.isArray(o[d]) && t[d] instanceof Object ? X(t[d], o[d]) || (y(t[d], o[d]), h = !0) : t[d] !== o[d] && (t[d] = o[d], h = !0));
71
71
  return t;
72
72
  };
73
- l = y(l, n);
73
+ u = y(u, n);
74
74
  }
75
- if (l.validation && (n?.validation?.hasOwnProperty("onBlur") || i?.validation?.hasOwnProperty("onBlur") || f?.validation?.hasOwnProperty("onBlur") || (l.validation.onBlur = "error", m = !0)), m) {
76
- ye(e, l);
77
- const y = l.validation?.zodSchemaV4, t = l.validation?.zodSchemaV3;
78
- (y !== i?.validation?.zodSchemaV4 || t !== i?.validation?.zodSchemaV3) && (y || t) && (y ? H(e, y, "zod4") : t && H(e, t, "zod3"), W(e));
75
+ if (u.validation && (n?.validation?.hasOwnProperty("onBlur") || i?.validation?.hasOwnProperty("onBlur") || f?.validation?.hasOwnProperty("onBlur") || (u.validation.onBlur = "error", h = !0)), h) {
76
+ ye(e, u);
77
+ const y = u.validation?.zodSchemaV4, t = u.validation?.zodSchemaV3;
78
+ (y !== i?.validation?.zodSchemaV4 || t !== i?.validation?.zodSchemaV3) && (y || t) && (y ? H(e, y, "zod4") : t && H(e, t, "zod3"), U(e));
79
79
  }
80
- return l;
80
+ return u;
81
81
  }
82
- const $t = (e, n) => {
83
- n?.plugins && z.getState().setRegisteredPlugins(n.plugins);
84
- const c = {};
82
+ const Vt = (e, n) => {
83
+ n?.plugins && R.getState().setRegisteredPlugins(n.plugins);
84
+ const l = {};
85
85
  if (n?.plugins)
86
- for (const a of n.plugins)
87
- typeof a.initialState == "function" && Object.assign(c, a.initialState());
88
- const i = { ...c, ...e }, [f, l] = De(i);
89
- Object.keys(f).forEach((a) => {
86
+ for (const o of n.plugins)
87
+ typeof o.initialState == "function" && Object.assign(l, o.initialState());
88
+ const i = { ...l, ...e }, [f, u] = De(i);
89
+ Object.keys(f).forEach((o) => {
90
90
  let d = {};
91
91
  n?.formElements && (d.formElements = n.formElements), d.validation = {
92
92
  onBlur: "error",
93
93
  ...n?.validation
94
94
  };
95
- const V = j(a), b = V ? {
96
- ...V,
95
+ const E = j(o), b = E ? {
96
+ ...E,
97
97
  formElements: n?.formElements,
98
98
  validation: {
99
- ...V.validation,
99
+ ...E.validation,
100
100
  ...d.validation
101
101
  }
102
102
  } : d;
103
- Object.keys(b).length > 0 && ye(a, b);
104
- }), Object.keys(f).forEach((a) => {
105
- K(a, f[a]);
103
+ Object.keys(b).length > 0 && ye(o, b);
104
+ }), Object.keys(f).forEach((o) => {
105
+ K(o, f[o]);
106
106
  });
107
- const m = (a, d) => {
108
- const [V] = ne(d?.componentId ?? ae()), b = fe({
109
- stateKey: a,
107
+ const h = (o, d) => {
108
+ const [E] = ne(d?.componentId ?? ae()), b = fe({
109
+ stateKey: o,
110
110
  options: d,
111
- initialOptionsPart: l
112
- }), E = q(b);
113
- E.current = b;
114
- const v = C(a, []) || f[a], _ = ct(v, {
115
- stateKey: a,
111
+ initialOptionsPart: u
112
+ }), $ = q(b);
113
+ $.current = b;
114
+ const v = C(o, []) || f[o], _ = ct(v, {
115
+ stateKey: o,
116
116
  syncUpdate: d?.syncUpdate,
117
- componentId: V,
117
+ componentId: E,
118
118
  localStorage: d?.localStorage,
119
119
  middleware: d?.middleware,
120
120
  reactiveType: d?.reactiveType,
@@ -124,58 +124,58 @@ const $t = (e, n) => {
124
124
  serverState: d?.serverState
125
125
  });
126
126
  return re(() => {
127
- d && z.getState().setPluginOptionsForState(a, d);
128
- }, [a, d]), re(() => (z.getState().registerStateHandler(a, _), () => {
129
- z.getState().unregisterStateHandler(a);
130
- }), [a, _]), re(() => {
131
- const T = j(a)?.validation;
132
- T?.zodSchemaV4 ? H(a, T.zodSchemaV4, "zod4") : T?.zodSchemaV3 && H(a, T.zodSchemaV3, "zod3");
127
+ d && R.getState().setPluginOptionsForState(o, d);
128
+ }, [o, d]), re(() => (R.getState().registerStateHandler(o, _), () => {
129
+ R.getState().unregisterStateHandler(o);
130
+ }), [o, _]), re(() => {
131
+ const T = j(o)?.validation;
132
+ T?.zodSchemaV4 ? H(o, T.zodSchemaV4, "zod4") : T?.zodSchemaV3 && H(o, T.zodSchemaV3, "zod3");
133
133
  }), _;
134
134
  };
135
- function y(a, d) {
136
- if (fe({ stateKey: a, options: d, initialOptionsPart: l }), d.localStorage && Xe(a, d), d.formElements) {
137
- const b = z.getState().registeredPlugins.map((E) => d.formElements.hasOwnProperty(E.name) ? {
138
- ...E,
139
- formWrapper: d.formElements[E.name]
140
- } : E);
141
- z.getState().setRegisteredPlugins(b);
135
+ function y(o, d) {
136
+ if (fe({ stateKey: o, options: d, initialOptionsPart: u }), d.localStorage && Xe(o, d), d.formElements) {
137
+ const b = R.getState().registeredPlugins.map(($) => d.formElements.hasOwnProperty($.name) ? {
138
+ ...$,
139
+ formWrapper: d.formElements[$.name]
140
+ } : $);
141
+ R.getState().setRegisteredPlugins(b);
142
142
  }
143
- W(a);
143
+ U(o);
144
144
  }
145
- function t(a) {
146
- Object.keys(f).forEach((V) => {
147
- y(V, a);
145
+ function t(o) {
146
+ Object.keys(f).forEach((E) => {
147
+ y(E, o);
148
148
  });
149
149
  }
150
150
  return {
151
- useCogsState: m,
151
+ useCogsState: h,
152
152
  setCogsOptionsByKey: y,
153
153
  setCogsOptions: t
154
154
  };
155
- }, Ze = (e, n, c, i, f) => {
156
- c?.log && console.log(
155
+ }, Ze = (e, n, l, i, f) => {
156
+ l?.log && console.log(
157
157
  "saving to localstorage",
158
158
  n,
159
- c.localStorage?.key,
159
+ l.localStorage?.key,
160
160
  i
161
161
  );
162
- const l = R(c?.localStorage?.key) ? c.localStorage?.key(e) : c?.localStorage?.key;
163
- if (l && i) {
164
- const m = `${i}-${n}-${l}`;
162
+ const u = L(l?.localStorage?.key) ? l.localStorage?.key(e) : l?.localStorage?.key;
163
+ if (u && i) {
164
+ const h = `${i}-${n}-${u}`;
165
165
  let y;
166
166
  try {
167
- y = ce(m)?.lastSyncedWithServer;
167
+ y = ce(h)?.lastSyncedWithServer;
168
168
  } catch {
169
169
  }
170
- const t = $(n, []), a = {
170
+ const t = V(n, []), o = {
171
171
  state: e,
172
172
  lastUpdated: Date.now(),
173
173
  lastSyncedWithServer: y,
174
174
  stateSource: t?.stateSource,
175
175
  baseServerState: t?.baseServerState
176
- }, d = Fe.serialize(a);
176
+ }, d = Fe.serialize(o);
177
177
  window.localStorage.setItem(
178
- m,
178
+ h,
179
179
  JSON.stringify(d.json)
180
180
  );
181
181
  }
@@ -195,46 +195,46 @@ const $t = (e, n) => {
195
195
  console.error("Error removing from localStorage:", n);
196
196
  }
197
197
  }, Xe = (e, n) => {
198
- const c = C(e, []), { sessionId: i } = Me(), f = R(n?.localStorage?.key) ? n.localStorage.key(c) : n?.localStorage?.key;
198
+ const l = C(e, []), { sessionId: i } = Me(), f = L(n?.localStorage?.key) ? n.localStorage.key(l) : n?.localStorage?.key;
199
199
  if (f && i) {
200
- const l = ce(
200
+ const u = ce(
201
201
  `${i}-${e}-${f}`
202
202
  );
203
- if (l && l.lastUpdated > (l.lastSyncedWithServer || 0))
204
- return W(e), !0;
203
+ if (u && u.lastUpdated > (u.lastSyncedWithServer || 0))
204
+ return U(e), !0;
205
205
  }
206
206
  return !1;
207
- }, W = (e) => {
208
- const n = $(e, []);
207
+ }, U = (e) => {
208
+ const n = V(e, []);
209
209
  if (!n) return;
210
- const c = /* @__PURE__ */ new Set();
210
+ const l = /* @__PURE__ */ new Set();
211
211
  n?.components?.forEach((i) => {
212
- (i ? Array.isArray(i.reactiveType) ? i.reactiveType : [i.reactiveType || "component"] : null)?.includes("none") || c.add(() => i.forceUpdate());
212
+ (i ? Array.isArray(i.reactiveType) ? i.reactiveType : [i.reactiveType || "component"] : null)?.includes("none") || l.add(() => i.forceUpdate());
213
213
  }), queueMicrotask(() => {
214
- c.forEach((i) => i());
214
+ l.forEach((i) => i());
215
215
  });
216
216
  };
217
- function oe(e, n, c, i) {
218
- const f = $(e, n);
219
- if (L(e, n, {
217
+ function oe(e, n, l, i) {
218
+ const f = V(e, n);
219
+ if (W(e, n, {
220
220
  ...f,
221
221
  isDirty: !1,
222
222
  stateSource: "server",
223
223
  lastServerSync: i || Date.now()
224
- }), Array.isArray(c)) {
225
- const l = $(e, n);
226
- l?.arrayKeys && l.arrayKeys.forEach((m, y) => {
227
- const t = [...n, m], a = c[y];
228
- a !== void 0 && oe(
224
+ }), Array.isArray(l)) {
225
+ const u = V(e, n);
226
+ u?.arrayKeys && u.arrayKeys.forEach((h, y) => {
227
+ const t = [...n, h], o = l[y];
228
+ o !== void 0 && oe(
229
229
  e,
230
230
  t,
231
- a,
231
+ o,
232
232
  i
233
233
  );
234
234
  });
235
- } else c && typeof c == "object" && c.constructor === Object && Object.keys(c).forEach((l) => {
236
- const m = [...n, l], y = c[l];
237
- oe(e, m, y, i);
235
+ } else l && typeof l == "object" && l.constructor === Object && Object.keys(l).forEach((u) => {
236
+ const h = [...n, u], y = l[u];
237
+ oe(e, h, y, i);
238
238
  });
239
239
  }
240
240
  let ie = [], ge = !1;
@@ -244,11 +244,11 @@ function Ke() {
244
244
  }));
245
245
  }
246
246
  function et(e, n) {
247
- e?.signals?.length && e.signals.forEach(({ parentId: c, position: i, effect: f }) => {
248
- const l = document.querySelector(`[data-parent-id="${c}"]`);
249
- if (!l) return;
250
- const m = Array.from(l.childNodes);
251
- if (!m[i]) return;
247
+ e?.signals?.length && e.signals.forEach(({ parentId: l, position: i, effect: f }) => {
248
+ const u = document.querySelector(`[data-parent-id="${l}"]`);
249
+ if (!u) return;
250
+ const h = Array.from(u.childNodes);
251
+ if (!h[i]) return;
252
252
  let y = n;
253
253
  if (f && n !== null)
254
254
  try {
@@ -258,106 +258,106 @@ function et(e, n) {
258
258
  } catch (t) {
259
259
  console.error("Error evaluating effect function:", t);
260
260
  }
261
- y !== null && typeof y == "object" && (y = JSON.stringify(y)), m[i].textContent = String(y ?? "");
261
+ y !== null && typeof y == "object" && (y = JSON.stringify(y)), h[i].textContent = String(y ?? "");
262
262
  });
263
263
  }
264
- function tt(e, n, c) {
265
- const i = $(e, []);
264
+ function tt(e, n, l) {
265
+ const i = V(e, []);
266
266
  if (!i?.components)
267
267
  return /* @__PURE__ */ new Set();
268
268
  const f = /* @__PURE__ */ new Set();
269
- if (c.type === "update") {
270
- let l = [...n];
269
+ if (l.type === "update") {
270
+ let u = [...n];
271
271
  for (; ; ) {
272
- const m = $(e, l);
273
- if (m?.pathComponents && m.pathComponents.forEach((y) => {
272
+ const h = V(e, u);
273
+ if (h?.pathComponents && h.pathComponents.forEach((y) => {
274
274
  const t = i.components?.get(y);
275
275
  t && ((Array.isArray(t.reactiveType) ? t.reactiveType : [t.reactiveType || "component"]).includes("none") || f.add(t));
276
- }), l.length === 0) break;
277
- l.pop();
276
+ }), u.length === 0) break;
277
+ u.pop();
278
278
  }
279
- c.newValue && typeof c.newValue == "object" && !Ce(c.newValue) && _e(c.newValue, c.oldValue).forEach((y) => {
280
- const t = y.split("."), a = [...n, ...t], d = $(e, a);
281
- d?.pathComponents && d.pathComponents.forEach((V) => {
282
- const b = i.components?.get(V);
279
+ l.newValue && typeof l.newValue == "object" && !Ce(l.newValue) && _e(l.newValue, l.oldValue).forEach((y) => {
280
+ const t = y.split("."), o = [...n, ...t], d = V(e, o);
281
+ d?.pathComponents && d.pathComponents.forEach((E) => {
282
+ const b = i.components?.get(E);
283
283
  b && ((Array.isArray(b.reactiveType) ? b.reactiveType : [b.reactiveType || "component"]).includes("none") || f.add(b));
284
284
  });
285
285
  });
286
- } else if (c.type === "insert" || c.type === "cut" || c.type === "insert_many") {
287
- let m = [...c.type === "insert" ? n : n.slice(0, -1)];
286
+ } else if (l.type === "insert" || l.type === "cut" || l.type === "insert_many") {
287
+ let h = [...l.type === "insert" ? n : n.slice(0, -1)];
288
288
  for (; ; ) {
289
- const y = $(e, m);
289
+ const y = V(e, h);
290
290
  if (y?.pathComponents && y.pathComponents.forEach((t) => {
291
- const a = i.components?.get(t);
292
- a && f.add(a);
293
- }), m.length === 0) break;
294
- m.pop();
291
+ const o = i.components?.get(t);
292
+ o && f.add(o);
293
+ }), h.length === 0) break;
294
+ h.pop();
295
295
  }
296
296
  }
297
297
  return f;
298
298
  }
299
- function rt(e, n, c) {
300
- const i = p.getState().getShadowValue(e, n), f = R(c) ? c(i) : c;
299
+ function rt(e, n, l) {
300
+ const i = p.getState().getShadowValue(e, n), f = L(l) ? l(i) : l;
301
301
  if (X(i, f))
302
302
  return null;
303
303
  Le(e, n, f), se(e, n, { bubble: !0 });
304
- const l = $(e, n);
304
+ const u = V(e, n);
305
305
  return {
306
306
  type: "update",
307
307
  oldValue: i,
308
308
  newValue: f,
309
- shadowMeta: l
309
+ shadowMeta: u
310
310
  };
311
311
  }
312
- function nt(e, n, c) {
313
- $e(e, n, c), se(e, n, { bubble: !0 });
314
- const i = $(e, n);
312
+ function nt(e, n, l) {
313
+ Ve(e, n, l), se(e, n, { bubble: !0 });
314
+ const i = V(e, n);
315
315
  return {
316
316
  type: "insert_many",
317
- count: c.length,
317
+ count: l.length,
318
318
  shadowMeta: i,
319
319
  path: n
320
320
  };
321
321
  }
322
- function at(e, n, c, i, f) {
323
- let l;
324
- if (R(c)) {
325
- const { value: a } = U(e, n);
326
- l = c({ state: a });
322
+ function at(e, n, l, i, f) {
323
+ let u;
324
+ if (L(l)) {
325
+ const { value: o } = N(e, n);
326
+ u = l({ state: o });
327
327
  } else
328
- l = c;
329
- const m = We(
328
+ u = l;
329
+ const h = We(
330
330
  e,
331
331
  n,
332
- l,
332
+ u,
333
333
  i,
334
334
  f
335
335
  );
336
336
  se(e, n, { bubble: !0 });
337
- const y = $(e, n);
337
+ const y = V(e, n);
338
338
  let t;
339
339
  return y?.arrayKeys && i !== void 0 && i > 0 && (t = y.arrayKeys[i - 1]), {
340
340
  type: "insert",
341
- newValue: l,
341
+ newValue: u,
342
342
  shadowMeta: y,
343
343
  path: n,
344
- itemId: m,
344
+ itemId: h,
345
345
  insertAfterId: t
346
346
  };
347
347
  }
348
348
  function ot(e, n) {
349
- const c = n.slice(0, -1), i = C(e, n);
350
- return Be(e, n), se(e, c, { bubble: !0 }), { type: "cut", oldValue: i, parentPath: c };
349
+ const l = n.slice(0, -1), i = C(e, n);
350
+ return Be(e, n), se(e, l, { bubble: !0 }), { type: "cut", oldValue: i, parentPath: l };
351
351
  }
352
352
  function it() {
353
- const e = /* @__PURE__ */ new Set(), n = [], c = [];
353
+ const e = /* @__PURE__ */ new Set(), n = [], l = [];
354
354
  for (const i of ie) {
355
355
  if (i.status && i.updateType) {
356
- c.push(i);
356
+ l.push(i);
357
357
  continue;
358
358
  }
359
- const f = i, l = f.type === "cut" ? null : f.newValue;
360
- f.shadowMeta?.signals?.length > 0 && n.push({ shadowMeta: f.shadowMeta, displayValue: l }), tt(
359
+ const f = i, u = f.type === "cut" ? null : f.newValue;
360
+ f.shadowMeta?.signals?.length > 0 && n.push({ shadowMeta: f.shadowMeta, displayValue: u }), tt(
361
361
  f.stateKey,
362
362
  f.path,
363
363
  f
@@ -365,45 +365,45 @@ function it() {
365
365
  e.add(y);
366
366
  });
367
367
  }
368
- c.length > 0 && xe(c), n.forEach(({ shadowMeta: i, displayValue: f }) => {
368
+ l.length > 0 && xe(l), n.forEach(({ shadowMeta: i, displayValue: f }) => {
369
369
  et(i, f);
370
370
  }), e.forEach((i) => {
371
371
  i.forceUpdate();
372
372
  }), ie = [], ge = !1;
373
373
  }
374
- function st(e, n, c) {
375
- return (f, l, m) => {
376
- i(e, l, f, m);
374
+ function st(e, n, l) {
375
+ return (f, u, h) => {
376
+ i(e, u, f, h);
377
377
  };
378
- function i(f, l, m, y) {
378
+ function i(f, u, h, y) {
379
379
  let t;
380
380
  switch (y.updateType) {
381
381
  case "update":
382
- t = rt(f, l, m);
382
+ t = rt(f, u, h);
383
383
  break;
384
384
  case "insert":
385
385
  t = at(
386
386
  f,
387
- l,
388
- m,
387
+ u,
388
+ h,
389
389
  y.index,
390
390
  y.itemId
391
391
  );
392
392
  break;
393
393
  case "insert_many":
394
- t = nt(f, l, m);
394
+ t = nt(f, u, h);
395
395
  break;
396
396
  case "cut":
397
- t = ot(f, l);
397
+ t = ot(f, u);
398
398
  break;
399
399
  }
400
400
  if (t === null)
401
401
  return;
402
- t.stateKey = f, t.path = l, ie.push(t), Ke();
403
- const a = {
402
+ t.stateKey = f, t.path = u, ie.push(t), Ke();
403
+ const o = {
404
404
  timeStamp: Date.now(),
405
405
  stateKey: f,
406
- path: l,
406
+ path: u,
407
407
  updateType: y.updateType,
408
408
  status: "new",
409
409
  oldValue: t.oldValue,
@@ -412,34 +412,34 @@ function st(e, n, c) {
412
412
  insertAfterId: t.insertAfterId,
413
413
  metaData: y.metaData
414
414
  };
415
- ie.push(a), t.newValue !== void 0 && Ze(
415
+ ie.push(o), t.newValue !== void 0 && Ze(
416
416
  t.newValue,
417
417
  f,
418
- c.current,
418
+ l.current,
419
419
  n
420
- ), c.current?.middleware && c.current.middleware({ update: a }), ze(a, y.validationTrigger || "programmatic"), Ye(a);
420
+ ), l.current?.middleware && l.current.middleware({ update: o }), ze(o, y.validationTrigger || "programmatic"), Ye(o);
421
421
  }
422
422
  }
423
423
  function ct(e, {
424
424
  stateKey: n,
425
- localStorage: c,
425
+ localStorage: l,
426
426
  formElements: i,
427
427
  reactiveDeps: f,
428
- reactiveType: l,
429
- componentId: m,
428
+ reactiveType: u,
429
+ componentId: h,
430
430
  defaultState: y,
431
431
  dependencies: t,
432
- serverState: a
432
+ serverState: o
433
433
  } = {}) {
434
- const [d, V] = ne({}), { sessionId: b } = Me();
435
- let E = !n;
436
- const [v] = ne(n ?? ae()), _ = q(m ?? ae()), T = q(
434
+ const [d, E] = ne({}), { sessionId: b } = Me();
435
+ let $ = !n;
436
+ const [v] = ne(n ?? ae()), _ = q(h ?? ae()), T = q(
437
437
  null
438
438
  );
439
439
  T.current = j(v) ?? null;
440
- const x = ke(
441
- (k) => {
442
- const r = k ? { ...j(v), ...k } : j(v), o = r?.defaultState || y || e;
440
+ const x = Ie(
441
+ (I) => {
442
+ const r = I ? { ...j(v), ...I } : j(v), a = r?.defaultState || y || e;
443
443
  if (r?.serverState?.status === "success" && r?.serverState?.data !== void 0)
444
444
  return {
445
445
  value: r.serverState.data,
@@ -447,18 +447,18 @@ function ct(e, {
447
447
  timestamp: r.serverState.timestamp || Date.now()
448
448
  };
449
449
  if (r?.localStorage?.key && b) {
450
- const S = R(r.localStorage.key) ? r.localStorage.key(o) : r.localStorage.key, u = ce(
450
+ const S = L(r.localStorage.key) ? r.localStorage.key(a) : r.localStorage.key, c = ce(
451
451
  `${b}-${v}-${S}`
452
452
  );
453
- if (u && u.lastUpdated > (r?.serverState?.timestamp || 0))
453
+ if (c && c.lastUpdated > (r?.serverState?.timestamp || 0))
454
454
  return {
455
- value: u.state,
455
+ value: c.state,
456
456
  source: "localStorage",
457
- timestamp: u.lastUpdated
457
+ timestamp: c.lastUpdated
458
458
  };
459
459
  }
460
460
  return {
461
- value: o || e,
461
+ value: a || e,
462
462
  source: "default",
463
463
  timestamp: Date.now()
464
464
  };
@@ -466,28 +466,28 @@ function ct(e, {
466
466
  [v, y, e, b]
467
467
  );
468
468
  Z(() => {
469
- a && a.status === "success" && a.data !== void 0 && me(v, a);
470
- }, [a, v]), Z(() => p.getState().subscribeToPath(v, (I) => {
471
- if (I?.type === "SERVER_STATE_UPDATE") {
472
- const r = I.serverState;
469
+ o && o.status === "success" && o.data !== void 0 && me(v, o);
470
+ }, [o, v]), Z(() => p.getState().subscribeToPath(v, (k) => {
471
+ if (k?.type === "SERVER_STATE_UPDATE") {
472
+ const r = k.serverState;
473
473
  if (r?.status !== "success" || r.data === void 0)
474
474
  return;
475
475
  ue(v, { serverState: r });
476
- const o = typeof r.merge == "object" ? r.merge : r.merge === !0 ? { strategy: "append", key: "id" } : null, s = C(v, []), S = r.data;
477
- if (o && o.strategy === "append" && "key" in o && Array.isArray(s) && Array.isArray(S)) {
478
- const u = o.key;
479
- if (!u) {
476
+ const a = typeof r.merge == "object" ? r.merge : r.merge === !0 ? { strategy: "append", key: "id" } : null, s = C(v, []), S = r.data;
477
+ if (a && a.strategy === "append" && "key" in a && Array.isArray(s) && Array.isArray(S)) {
478
+ const c = a.key;
479
+ if (!c) {
480
480
  console.error(
481
481
  "CogsState: Merge strategy 'append' requires a 'key' field."
482
482
  );
483
483
  return;
484
484
  }
485
- const h = new Set(
486
- s.map((M) => M[u])
485
+ const m = new Set(
486
+ s.map((M) => M[c])
487
487
  ), w = S.filter(
488
- (M) => !h.has(M[u])
488
+ (M) => !m.has(M[c])
489
489
  );
490
- w.length > 0 && $e(v, [], w);
490
+ w.length > 0 && Ve(v, [], w);
491
491
  const A = C(v, []);
492
492
  oe(
493
493
  v,
@@ -502,57 +502,57 @@ function ct(e, {
502
502
  S,
503
503
  r.timestamp || Date.now()
504
504
  );
505
- W(v);
505
+ U(v);
506
506
  }
507
507
  }), [v]), Z(() => {
508
- const k = p.getState().getShadowMetadata(v, []);
509
- if (k && k.stateSource)
508
+ const I = p.getState().getShadowMetadata(v, []);
509
+ if (I && I.stateSource)
510
510
  return;
511
- const I = j(v), r = {
512
- localStorageEnabled: !!I?.localStorage?.key
511
+ const k = j(v), r = {
512
+ localStorageEnabled: !!k?.localStorage?.key
513
513
  };
514
- if (L(v, [], {
515
- ...k,
514
+ if (W(v, [], {
515
+ ...I,
516
516
  features: r
517
- }), I?.defaultState !== void 0 || y !== void 0) {
518
- const h = I?.defaultState || y;
519
- I?.defaultState || ue(v, {
520
- defaultState: h
517
+ }), k?.defaultState !== void 0 || y !== void 0) {
518
+ const m = k?.defaultState || y;
519
+ k?.defaultState || ue(v, {
520
+ defaultState: m
521
521
  });
522
522
  }
523
- const { value: o, source: s, timestamp: S } = x();
524
- K(v, o);
525
- const u = j(v)?.validation;
526
- u?.zodSchemaV4 ? H(v, u.zodSchemaV4, "zod4") : u?.zodSchemaV3 && H(v, u.zodSchemaV3, "zod3"), L(v, [], {
523
+ const { value: a, source: s, timestamp: S } = x();
524
+ K(v, a);
525
+ const c = j(v)?.validation;
526
+ c?.zodSchemaV4 ? H(v, c.zodSchemaV4, "zod4") : c?.zodSchemaV3 && H(v, c.zodSchemaV3, "zod3"), W(v, [], {
527
527
  stateSource: s,
528
528
  lastServerSync: s === "server" ? S : void 0,
529
529
  isDirty: s === "server" ? !1 : void 0,
530
- baseServerState: s === "server" ? o : void 0
531
- }), s === "server" && a && me(v, a), W(v);
530
+ baseServerState: s === "server" ? a : void 0
531
+ }), s === "server" && o && me(v, o), U(v);
532
532
  }, [v, ...t || []]), re(() => {
533
- E && ue(v, {
533
+ $ && ue(v, {
534
534
  formElements: i,
535
535
  defaultState: y,
536
- localStorage: c,
536
+ localStorage: l,
537
537
  middleware: T.current?.middleware
538
538
  });
539
- const k = `${v}////${_.current}`, I = $(v, []), r = I?.components || /* @__PURE__ */ new Map();
540
- return r.set(k, {
541
- forceUpdate: () => V({}),
542
- reactiveType: l ?? ["component"],
539
+ const I = `${v}////${_.current}`, k = V(v, []), r = k?.components || /* @__PURE__ */ new Map();
540
+ return r.set(I, {
541
+ forceUpdate: () => E({}),
542
+ reactiveType: u ?? ["component"],
543
543
  paths: /* @__PURE__ */ new Set(),
544
544
  depsFunction: f || void 0,
545
545
  deps: f ? f(C(v, [])) : [],
546
546
  prevDeps: f ? f(C(v, [])) : []
547
- }), L(v, [], {
548
- ...I,
547
+ }), W(v, [], {
548
+ ...k,
549
549
  components: r
550
- }), V({}), () => {
551
- const o = $(v, []), s = o?.components?.get(k);
550
+ }), E({}), () => {
551
+ const a = V(v, []), s = a?.components?.get(I);
552
552
  s?.paths && s.paths.forEach((S) => {
553
- const h = S.split(".").slice(1), w = p.getState().getShadowMetadata(v, h);
554
- w?.pathComponents && w.pathComponents.size === 0 && (delete w.pathComponents, p.getState().setShadowMetadata(v, h, w));
555
- }), o?.components && L(v, [], o);
553
+ const m = S.split(".").slice(1), w = p.getState().getShadowMetadata(v, m);
554
+ w?.pathComponents && w.pathComponents.size === 0 && (delete w.pathComponents, p.getState().setShadowMetadata(v, m, w));
555
+ }), a?.components && W(v, [], a);
556
556
  };
557
557
  }, []);
558
558
  const G = st(
@@ -567,155 +567,155 @@ function ct(e, {
567
567
  b
568
568
  ), [v, b]);
569
569
  }
570
- const lt = (e, n, c) => {
571
- let i = $(e, n)?.arrayKeys || [];
572
- const f = c?.transforms;
570
+ const lt = (e, n, l) => {
571
+ let i = V(e, n)?.arrayKeys || [];
572
+ const f = l?.transforms;
573
573
  if (!f || f.length === 0)
574
574
  return i;
575
- for (const l of f)
576
- if (l.type === "filter") {
577
- const m = [];
575
+ for (const u of f)
576
+ if (u.type === "filter") {
577
+ const h = [];
578
578
  i.forEach((y, t) => {
579
- const a = C(e, [...n, y]);
580
- l.fn(a, t) && m.push(y);
581
- }), i = m;
582
- } else l.type === "sort" && i.sort((m, y) => {
583
- const t = C(e, [...n, m]), a = C(e, [...n, y]);
584
- return l.fn(t, a);
579
+ const o = C(e, [...n, y]);
580
+ u.fn(o, t) && h.push(y);
581
+ }), i = h;
582
+ } else u.type === "sort" && i.sort((h, y) => {
583
+ const t = C(e, [...n, h]), o = C(e, [...n, y]);
584
+ return u.fn(t, o);
585
585
  });
586
586
  return i;
587
- }, te = (e, n, c) => {
588
- const i = `${e}////${n}`, l = $(e, [])?.components?.get(i);
589
- !l || l.reactiveType === "none" || !(Array.isArray(l.reactiveType) ? l.reactiveType : [l.reactiveType]).includes("component") || Ge(e, c, i);
590
- }, Y = (e, n, c) => {
591
- const i = $(e, []), f = /* @__PURE__ */ new Set();
592
- i?.components && i.components.forEach((m, y) => {
593
- (Array.isArray(m.reactiveType) ? m.reactiveType : [m.reactiveType || "component"]).includes("all") && (m.forceUpdate(), f.add(y));
594
- }), $(e, [
587
+ }, te = (e, n, l) => {
588
+ const i = `${e}////${n}`, u = V(e, [])?.components?.get(i);
589
+ !u || u.reactiveType === "none" || !(Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType]).includes("component") || Ge(e, l, i);
590
+ }, Y = (e, n, l) => {
591
+ const i = V(e, []), f = /* @__PURE__ */ new Set();
592
+ i?.components && i.components.forEach((h, y) => {
593
+ (Array.isArray(h.reactiveType) ? h.reactiveType : [h.reactiveType || "component"]).includes("all") && (h.forceUpdate(), f.add(y));
594
+ }), V(e, [
595
595
  ...n,
596
596
  "getSelected"
597
- ])?.pathComponents?.forEach((m) => {
598
- i?.components?.get(m)?.forceUpdate();
597
+ ])?.pathComponents?.forEach((h) => {
598
+ i?.components?.get(h)?.forceUpdate();
599
599
  });
600
- const l = $(e, n);
601
- for (let m of l?.arrayKeys || []) {
602
- const y = m + ".selected", t = $(e, y.split(".").slice(1));
603
- m == c && t?.pathComponents?.forEach((a) => {
604
- i?.components?.get(a)?.forceUpdate();
600
+ const u = V(e, n);
601
+ for (let h of u?.arrayKeys || []) {
602
+ const y = h + ".selected", t = V(e, y.split(".").slice(1));
603
+ h == l && t?.pathComponents?.forEach((o) => {
604
+ i?.components?.get(o)?.forceUpdate();
605
605
  });
606
606
  }
607
607
  };
608
- function U(e, n, c) {
609
- const i = $(e, n), f = n.length > 0 ? n.join(".") : "root", l = c?.arrayViews?.[f];
610
- if (Array.isArray(l) && l.length === 0)
608
+ function N(e, n, l) {
609
+ const i = V(e, n), f = n.length > 0 ? n.join(".") : "root", u = l?.arrayViews?.[f];
610
+ if (Array.isArray(u) && u.length === 0)
611
611
  return {
612
612
  shadowMeta: i,
613
613
  value: [],
614
614
  arrayKeys: i?.arrayKeys
615
615
  };
616
- const m = C(e, n, l);
616
+ const h = C(e, n, u);
617
617
  return {
618
618
  shadowMeta: i,
619
- value: m,
619
+ value: h,
620
620
  arrayKeys: i?.arrayKeys
621
621
  };
622
622
  }
623
623
  function ut(e, n) {
624
- return n ? e.length !== n.length ? !1 : n.every((c, i) => c === "*" || c === e[i]) : !0;
624
+ return n ? e.length !== n.length ? !1 : n.every((l, i) => l === "*" || l === e[i]) : !0;
625
625
  }
626
626
  function dt(e, n) {
627
627
  return n === "any" ? !0 : n === "array" ? Array.isArray(e) : n === "boolean" ? typeof e == "boolean" : n === "object" ? e !== null && typeof e == "object" && !Array.isArray(e) : n === "primitive" ? e === null || typeof e != "object" && !Array.isArray(e) : !1;
628
628
  }
629
- function Ve(e, n) {
630
- const c = p.getState().getShadowMetadata(e, n);
631
- if (!c?.clientActivityState?.elements) return [];
629
+ function Ee(e, n) {
630
+ const l = p.getState().getShadowMetadata(e, n);
631
+ if (!l?.clientActivityState?.elements) return [];
632
632
  const i = [];
633
- return c.clientActivityState.elements.forEach((f) => {
633
+ return l.clientActivityState.elements.forEach((f) => {
634
634
  f.domRef?.current && i.push(f.domRef);
635
635
  }), i;
636
636
  }
637
- function Ee(e, n) {
638
- return Ve(e, n).map((i) => i.current).filter(Boolean);
637
+ function $e(e, n) {
638
+ return Ee(e, n).map((i) => i.current).filter(Boolean);
639
639
  }
640
- function ft(e, n, c) {
641
- Ee(e, n).forEach((i) => {
640
+ function ft(e, n, l) {
641
+ $e(e, n).forEach((i) => {
642
642
  if ("disabled" in i) {
643
- i.disabled = c;
643
+ i.disabled = l;
644
644
  return;
645
645
  }
646
- i.style.pointerEvents = c ? "none" : "", i.setAttribute("aria-disabled", String(c));
646
+ i.style.pointerEvents = l ? "none" : "", i.setAttribute("aria-disabled", String(l));
647
647
  });
648
648
  }
649
- function Pe(e, n, c, i) {
649
+ function Pe(e, n, l, i) {
650
650
  const f = /* @__PURE__ */ new Map();
651
- function l({
651
+ function u({
652
652
  path: t = [],
653
- meta: a,
653
+ meta: o,
654
654
  componentId: d
655
655
  }) {
656
- if ($(e, t)?.isRaw)
656
+ if (V(e, t)?.isRaw)
657
657
  return C(e, t);
658
- const b = a ? JSON.stringify(a.arrayViews || a.transforms) : "", E = t.join(".") + ":" + d + ":" + b;
659
- if (f.has(E))
660
- return f.get(E);
658
+ const b = o ? JSON.stringify(o.arrayViews || o.transforms) : "", $ = t.join(".") + ":" + d + ":" + b;
659
+ if (f.has($))
660
+ return f.get($);
661
661
  const v = [e, ...t].join("."), _ = () => {
662
662
  }, T = {
663
- apply(G, g, k) {
664
- if (k.length === 0) {
665
- const r = t.length > 0 ? t.join(".") : "root", o = a?.arrayViews?.[r];
666
- return te(e, d, t), C(e, t, o);
663
+ apply(G, g, I) {
664
+ if (I.length === 0) {
665
+ const r = t.length > 0 ? t.join(".") : "root", a = o?.arrayViews?.[r];
666
+ return te(e, d, t), C(e, t, a);
667
667
  }
668
- const I = k[0];
669
- return n(I, t, { updateType: "update" }), !0;
668
+ const k = I[0];
669
+ return n(k, t, { updateType: "update" }), !0;
670
670
  },
671
- get(G, g, k) {
671
+ get(G, g, I) {
672
672
  if (g === Symbol.toPrimitive)
673
673
  return (r) => r === "number" ? NaN : r === "string" ? `[CogsState: ${t.join(".") || "root"}]` : null;
674
674
  if (g === Symbol.toStringTag)
675
675
  return "CogsState";
676
676
  if (g === Symbol.iterator) {
677
- const { value: r } = U(e, t, a);
677
+ const { value: r } = N(e, t, o);
678
678
  return Array.isArray(r) ? function* () {
679
- for (let o = 0; o < r.length; o++)
680
- yield r[o];
679
+ for (let a = 0; a < r.length; a++)
680
+ yield r[a];
681
681
  } : void 0;
682
682
  }
683
683
  if (g === "call" || g === "apply" || g === "bind")
684
- return Reflect.get(G, g, k);
684
+ return Reflect.get(G, g, I);
685
685
  if (typeof g != "string")
686
686
  return Reflect.get(G, g);
687
- if (t.length === 0 && g in m)
688
- return m[g];
687
+ if (t.length === 0 && g in h)
688
+ return h[g];
689
689
  if (typeof g == "string" && !g.startsWith("$")) {
690
- const { value: r } = U(e, t, a);
690
+ const { value: r } = N(e, t, o);
691
691
  if (r !== null && typeof r == "object" && !Array.isArray(r) && Object.prototype.hasOwnProperty.call(r, g)) {
692
- const u = [...t, g];
693
- return l({
694
- path: u,
692
+ const c = [...t, g];
693
+ return u({
694
+ path: c,
695
695
  componentId: d,
696
- meta: a
696
+ meta: o
697
697
  });
698
698
  }
699
- const s = z.getState().registeredPlugins;
700
- for (const u of s) {
701
- const h = u.chainMethods?.[g];
702
- if (h && ut(t, h.pathPattern) && dt(r, h.target))
699
+ const s = R.getState().registeredPlugins;
700
+ for (const c of s) {
701
+ const m = c.chainMethods?.[g];
702
+ if (m && ut(t, m.pathPattern) && dt(r, m.target))
703
703
  return (...w) => {
704
- const A = z.getState(), M = A.pluginOptions.get(e)?.get(u.name), D = A.getHookResult(e, u.name);
705
- return h.handler(
704
+ const A = R.getState(), M = A.pluginOptions.get(e)?.get(c.name), D = A.getHookResult(e, c.name);
705
+ return m.handler(
706
706
  {
707
707
  stateKey: e,
708
708
  path: t,
709
- pluginName: u.name,
709
+ pluginName: c.name,
710
710
  options: M,
711
711
  hookData: D,
712
- $get: () => U(e, t, a).value,
712
+ $get: () => N(e, t, o).value,
713
713
  $update: (P) => (n(P, t, {
714
714
  updateType: "update"
715
715
  }), {
716
716
  synced: () => {
717
717
  const O = p.getState().getShadowMetadata(e, t);
718
- L(e, t, {
718
+ W(e, t, {
719
719
  ...O,
720
720
  isDirty: !1,
721
721
  stateSource: "server",
@@ -730,11 +730,11 @@ function Pe(e, n, c, i) {
730
730
  metaData: O
731
731
  });
732
732
  },
733
- getFieldMetaData: () => he(e, t)?.get(u.name),
734
- setFieldMetaData: (P) => ve(e, t, u.name, P),
735
- removeFieldMetaData: () => we(e, t, u.name),
736
- getFieldRefs: () => Ve(e, t),
737
- getFieldElements: () => Ee(e, t),
733
+ getFieldMetaData: () => he(e, t)?.get(c.name),
734
+ setFieldMetaData: (P) => ve(e, t, c.name, P),
735
+ removeFieldMetaData: () => we(e, t, c.name),
736
+ getFieldRefs: () => Ee(e, t),
737
+ getFieldElements: () => $e(e, t),
738
738
  setFieldDisabled: (P) => ft(e, t, P)
739
739
  },
740
740
  ...w
@@ -742,65 +742,65 @@ function Pe(e, n, c, i) {
742
742
  };
743
743
  }
744
744
  const S = [...t, g];
745
- return l({
745
+ return u({
746
746
  path: S,
747
747
  componentId: d,
748
- meta: a
748
+ meta: o
749
749
  });
750
750
  }
751
751
  if (g === "$_rebuildStateShape")
752
- return l;
752
+ return u;
753
753
  if (g === "$sync" && t.length === 0)
754
754
  return async function() {
755
- const r = p.getState().getInitialOptions(e), o = r?.sync;
756
- if (!o)
755
+ const r = p.getState().getInitialOptions(e), a = r?.sync;
756
+ if (!a)
757
757
  return console.error(`No mutation defined for state key "${e}"`), { success: !1, error: "No mutation defined" };
758
758
  const s = p.getState().getShadowValue(e, []), S = r?.validation?.key;
759
759
  try {
760
- const u = await o.action(s);
761
- if (u && !u.success && u.errors, u?.success) {
762
- const h = p.getState().getShadowMetadata(e, []);
763
- L(e, [], {
764
- ...h,
760
+ const c = await a.action(s);
761
+ if (c && !c.success && c.errors, c?.success) {
762
+ const m = p.getState().getShadowMetadata(e, []);
763
+ W(e, [], {
764
+ ...m,
765
765
  isDirty: !1,
766
766
  lastServerSync: Date.now(),
767
767
  stateSource: "server",
768
768
  baseServerState: s
769
769
  // Update base server state
770
- }), o.onSuccess && o.onSuccess(u.data);
771
- } else !u?.success && o.onError && o.onError(u.error);
772
- return u;
773
- } catch (u) {
774
- return o.onError && o.onError(u), { success: !1, error: u };
770
+ }), a.onSuccess && a.onSuccess(c.data);
771
+ } else !c?.success && a.onError && a.onError(c.error);
772
+ return c;
773
+ } catch (c) {
774
+ return a.onError && a.onError(c), { success: !1, error: c };
775
775
  }
776
776
  };
777
777
  if (g === "$_status" || g === "$getStatus") {
778
778
  const r = () => {
779
- const { shadowMeta: o, value: s } = U(e, t, a);
780
- return o?.isDirty === !0 ? "dirty" : o?.stateSource === "server" || o?.isDirty === !1 ? "synced" : o?.stateSource === "localStorage" ? "restored" : o?.stateSource === "default" || s !== void 0 ? "fresh" : "unknown";
779
+ const { shadowMeta: a, value: s } = N(e, t, o);
780
+ return a?.isDirty === !0 ? "dirty" : a?.stateSource === "server" || a?.isDirty === !1 ? "synced" : a?.stateSource === "localStorage" ? "restored" : a?.stateSource === "default" || s !== void 0 ? "fresh" : "unknown";
781
781
  };
782
782
  return g === "$_status" ? r() : r;
783
783
  }
784
784
  if (g === "$removeStorage")
785
785
  return () => {
786
- const r = p.getState().initialStateGlobal[e], o = j(e), s = R(o?.localStorage?.key) ? o.localStorage.key(r) : o?.localStorage?.key, S = i && s ? `${i}-${e}-${s}` : void 0;
786
+ const r = p.getState().initialStateGlobal[e], a = j(e), s = L(a?.localStorage?.key) ? a.localStorage.key(r) : a?.localStorage?.key, S = i && s ? `${i}-${e}-${s}` : void 0;
787
787
  de(S);
788
788
  };
789
789
  if (g === "$setRaw")
790
790
  return (r) => {
791
- const o = $(e, t) || {};
792
- L(e, t, { ...o, isRaw: !0 }), n(r, t, { updateType: "update" });
791
+ const a = V(e, t) || {};
792
+ W(e, t, { ...a, isRaw: !0 }), n(r, t, { updateType: "update" });
793
793
  };
794
794
  if (g === "$validate")
795
795
  return () => {
796
- const r = p.getState(), { value: o } = U(e, t, a), s = r.getInitialOptions(e), S = s?.validation?.zodSchemaV4 || s?.validation?.zodSchemaV3;
796
+ const r = p.getState(), { value: a } = N(e, t, o), s = r.getInitialOptions(e), S = s?.validation?.zodSchemaV4 || s?.validation?.zodSchemaV3;
797
797
  if (!S)
798
- return { success: !0, data: o };
799
- const u = S.safeParse(o);
800
- if (u.success) {
801
- const h = r.getShadowMetadata(e, t) || {};
798
+ return { success: !0, data: a };
799
+ const c = S.safeParse(a);
800
+ if (c.success) {
801
+ const m = r.getShadowMetadata(e, t) || {};
802
802
  r.setShadowMetadata(e, t, {
803
- ...h,
803
+ ...m,
804
804
  validation: {
805
805
  status: "VALID",
806
806
  errors: [],
@@ -808,7 +808,7 @@ function Pe(e, n, c, i) {
808
808
  }
809
809
  });
810
810
  } else
811
- (u.error?.issues || u.error?.errors || []).forEach((w) => {
811
+ (c.error?.issues || c.error?.errors || []).forEach((w) => {
812
812
  const A = [...t, ...w.path.map(String)], M = r.getShadowMetadata(e, A) || {};
813
813
  r.setShadowMetadata(e, A, {
814
814
  ...M,
@@ -827,12 +827,12 @@ function Pe(e, n, c, i) {
827
827
  }
828
828
  });
829
829
  });
830
- return W(e), u;
830
+ return U(e), c;
831
831
  };
832
832
  if (g === "$showValidationErrors")
833
833
  return () => {
834
- const { shadowMeta: r } = U(e, t, a);
835
- return r?.validation?.status === "INVALID" && r.validation.errors.length > 0 ? r.validation.errors.filter((o) => o.severity === "error").map((o) => o.message) : [];
834
+ const { shadowMeta: r } = N(e, t, o);
835
+ return r?.validation?.status === "INVALID" && r.validation.errors.length > 0 ? r.validation.errors.filter((a) => a.severity === "error").map((a) => a.message) : [];
836
836
  };
837
837
  if (g === "$getSelected")
838
838
  return () => {
@@ -841,31 +841,31 @@ function Pe(e, n, c, i) {
841
841
  ...t,
842
842
  "getSelected"
843
843
  ]);
844
- const o = p.getState().selectedIndicesMap.get(r);
845
- if (!o)
844
+ const a = p.getState().selectedIndicesMap.get(r);
845
+ if (!a)
846
846
  return;
847
- const s = t.join("."), S = a?.arrayViews?.[s], u = o.split(".").pop();
848
- if (!(S && !S.includes(u) || C(
847
+ const s = t.join("."), S = o?.arrayViews?.[s], c = a.split(".").pop();
848
+ if (!(S && !S.includes(c) || C(
849
849
  e,
850
- o.split(".").slice(1)
850
+ a.split(".").slice(1)
851
851
  ) === void 0))
852
- return l({
853
- path: o.split(".").slice(1),
852
+ return u({
853
+ path: a.split(".").slice(1),
854
854
  componentId: d,
855
- meta: a
855
+ meta: o
856
856
  });
857
857
  };
858
858
  if (g === "$getSelectedIndex")
859
859
  return () => {
860
860
  const r = e + "." + t.join(".");
861
861
  t.join(".");
862
- const o = p.getState().selectedIndicesMap.get(r);
863
- if (!o)
862
+ const a = p.getState().selectedIndicesMap.get(r);
863
+ if (!a)
864
864
  return -1;
865
- const { keys: s } = N(e, t, a);
865
+ const { keys: s } = F(e, t, o);
866
866
  if (!s)
867
867
  return -1;
868
- const S = o.split(".").pop();
868
+ const S = a.split(".").pop();
869
869
  return s.indexOf(S);
870
870
  };
871
871
  if (g === "$clearSelected")
@@ -876,56 +876,56 @@ function Pe(e, n, c, i) {
876
876
  };
877
877
  if (g === "$map")
878
878
  return (r) => {
879
- const { value: o, keys: s } = N(
879
+ const { value: a, keys: s } = F(
880
880
  e,
881
881
  t,
882
- a
882
+ o
883
883
  );
884
- if (te(e, d, t), !s || !Array.isArray(o))
884
+ if (te(e, d, t), !s || !Array.isArray(a))
885
885
  return [];
886
- const S = l({
886
+ const S = u({
887
887
  path: t,
888
888
  componentId: d,
889
- meta: a
889
+ meta: o
890
890
  });
891
- return o.map((u, h) => {
892
- const w = s[h];
891
+ return a.map((c, m) => {
892
+ const w = s[m];
893
893
  if (!w) return;
894
- const A = [...t, w], M = l({
894
+ const A = [...t, w], M = u({
895
895
  path: A,
896
896
  // This now correctly points to the item in the shadow store.
897
897
  componentId: d,
898
- meta: a
898
+ meta: o
899
899
  });
900
- return r(M, h, S);
900
+ return r(M, m, S);
901
901
  });
902
902
  };
903
903
  if (g === "$filter")
904
904
  return (r) => {
905
- const o = t.length > 0 ? t.join(".") : "root", { keys: s, value: S } = N(
905
+ const a = t.length > 0 ? t.join(".") : "root", { keys: s, value: S } = F(
906
906
  e,
907
907
  t,
908
- a
908
+ o
909
909
  );
910
910
  if (!Array.isArray(S))
911
911
  throw new Error("filter can only be used on arrays");
912
- const u = [];
913
- return S.forEach((h, w) => {
914
- if (r(h, w)) {
912
+ const c = [];
913
+ return S.forEach((m, w) => {
914
+ if (r(m, w)) {
915
915
  const A = s[w];
916
- A && u.push(A);
916
+ A && c.push(A);
917
917
  }
918
- }), l({
918
+ }), u({
919
919
  path: t,
920
920
  componentId: d,
921
921
  meta: {
922
- ...a,
922
+ ...o,
923
923
  arrayViews: {
924
- ...a?.arrayViews || {},
925
- [o]: u
924
+ ...o?.arrayViews || {},
925
+ [a]: c
926
926
  },
927
927
  transforms: [
928
- ...a?.transforms || [],
928
+ ...o?.transforms || [],
929
929
  { type: "filter", fn: r, path: t }
930
930
  ]
931
931
  }
@@ -933,30 +933,30 @@ function Pe(e, n, c, i) {
933
933
  };
934
934
  if (g === "$sort")
935
935
  return (r) => {
936
- const o = t.length > 0 ? t.join(".") : "root", { value: s, keys: S } = N(
936
+ const a = t.length > 0 ? t.join(".") : "root", { value: s, keys: S } = F(
937
937
  e,
938
938
  t,
939
- a
939
+ o
940
940
  );
941
941
  if (!Array.isArray(s) || !S)
942
942
  throw new Error("No array keys found for sorting");
943
- const u = s.map((w, A) => ({
943
+ const c = s.map((w, A) => ({
944
944
  item: w,
945
945
  key: S[A]
946
946
  }));
947
- u.sort((w, A) => r(w.item, A.item));
948
- const h = u.map((w) => w.key);
949
- return l({
947
+ c.sort((w, A) => r(w.item, A.item));
948
+ const m = c.map((w) => w.key);
949
+ return u({
950
950
  path: t,
951
951
  componentId: d,
952
952
  meta: {
953
- ...a,
953
+ ...o,
954
954
  arrayViews: {
955
- ...a?.arrayViews || {},
956
- [o]: h
955
+ ...o?.arrayViews || {},
956
+ [a]: m
957
957
  },
958
958
  transforms: [
959
- ...a?.transforms || [],
959
+ ...o?.transforms || [],
960
960
  { type: "sort", fn: r, path: t }
961
961
  ]
962
962
  }
@@ -964,52 +964,52 @@ function Pe(e, n, c, i) {
964
964
  };
965
965
  if (g === "$list")
966
966
  return (r) => /* @__PURE__ */ Q(() => {
967
- const s = q(/* @__PURE__ */ new Map()), [S, u] = ne({}), h = t.length > 0 ? t.join(".") : "root", w = lt(e, t, a), A = Ae(() => ({
968
- ...a,
967
+ const s = q(/* @__PURE__ */ new Map()), [S, c] = ne({}), m = t.length > 0 ? t.join(".") : "root", w = lt(e, t, o), A = Ae(() => ({
968
+ ...o,
969
969
  arrayViews: {
970
- ...a?.arrayViews || {},
971
- [h]: w
970
+ ...o?.arrayViews || {},
971
+ [m]: w
972
972
  }
973
- }), [a, h, w]), { value: M } = N(
973
+ }), [o, m, w]), { value: M } = F(
974
974
  e,
975
975
  t,
976
976
  A
977
977
  );
978
978
  if (Z(() => {
979
- const O = p.getState().subscribeToPath(v, (F) => {
980
- if (F.type === "GET_SELECTED")
979
+ const O = p.getState().subscribeToPath(v, (z) => {
980
+ if (z.type === "GET_SELECTED")
981
981
  return;
982
982
  const B = p.getState().getShadowMetadata(e, t)?.transformCaches;
983
983
  if (B)
984
984
  for (const ee of B.keys())
985
985
  ee.startsWith(d) && B.delete(ee);
986
- (F.type === "INSERT" || F.type === "INSERT_MANY" || F.type === "REMOVE" || F.type === "CLEAR_SELECTION" || F.type === "SERVER_STATE_UPDATE" && !a?.serverStateIsUpStream) && u({});
986
+ (z.type === "INSERT" || z.type === "INSERT_MANY" || z.type === "REMOVE" || z.type === "CLEAR_SELECTION" || z.type === "SERVER_STATE_UPDATE" && !o?.serverStateIsUpStream) && c({});
987
987
  });
988
988
  return () => {
989
989
  O();
990
990
  };
991
991
  }, [d, v]), !Array.isArray(M))
992
992
  return null;
993
- const D = l({
993
+ const D = u({
994
994
  path: t,
995
995
  componentId: d,
996
996
  meta: A
997
997
  // Use updated meta here
998
- }), P = M.map((O, F) => {
999
- const J = w[F];
998
+ }), P = M.map((O, z) => {
999
+ const J = w[z];
1000
1000
  if (!J)
1001
1001
  return null;
1002
1002
  let B = s.current.get(J);
1003
1003
  B || (B = ae(), s.current.set(J, B));
1004
1004
  const ee = [...t, J];
1005
- return Se(Ne, {
1005
+ return Se(Ue, {
1006
1006
  key: J,
1007
1007
  stateKey: e,
1008
1008
  itemComponentId: B,
1009
1009
  itemPath: ee,
1010
- localIndex: F,
1010
+ localIndex: z,
1011
1011
  arraySetter: D,
1012
- rebuildStateShape: l,
1012
+ rebuildStateShape: u,
1013
1013
  renderFn: r
1014
1014
  });
1015
1015
  });
@@ -1017,54 +1017,54 @@ function Pe(e, n, c, i) {
1017
1017
  }, {});
1018
1018
  if (g === "$stateFlattenOn")
1019
1019
  return (r) => {
1020
- const o = t.length > 0 ? t.join(".") : "root", s = a?.arrayViews?.[o], S = p.getState().getShadowValue(e, t, s);
1021
- return Array.isArray(S) ? l({
1020
+ const a = t.length > 0 ? t.join(".") : "root", s = o?.arrayViews?.[a], S = p.getState().getShadowValue(e, t, s);
1021
+ return Array.isArray(S) ? u({
1022
1022
  path: [...t, "[*]", r],
1023
1023
  componentId: d,
1024
- meta: a
1024
+ meta: o
1025
1025
  }) : [];
1026
1026
  };
1027
1027
  if (g === "$index")
1028
1028
  return (r) => {
1029
- const o = t.length > 0 ? t.join(".") : "root", s = a?.arrayViews?.[o];
1029
+ const a = t.length > 0 ? t.join(".") : "root", s = o?.arrayViews?.[a];
1030
1030
  if (s) {
1031
- const h = s[r];
1032
- return h ? l({
1033
- path: [...t, h],
1031
+ const m = s[r];
1032
+ return m ? u({
1033
+ path: [...t, m],
1034
1034
  componentId: d,
1035
- meta: a
1035
+ meta: o
1036
1036
  }) : void 0;
1037
1037
  }
1038
- const S = $(e, t);
1038
+ const S = V(e, t);
1039
1039
  if (!S?.arrayKeys) return;
1040
- const u = S.arrayKeys[r];
1041
- if (u)
1042
- return l({
1043
- path: [...t, u],
1040
+ const c = S.arrayKeys[r];
1041
+ if (c)
1042
+ return u({
1043
+ path: [...t, c],
1044
1044
  componentId: d,
1045
- meta: a
1045
+ meta: o
1046
1046
  });
1047
1047
  };
1048
1048
  if (g === "$last")
1049
1049
  return () => {
1050
- const { keys: r } = N(e, t, a);
1050
+ const { keys: r } = F(e, t, o);
1051
1051
  if (!r || r.length === 0)
1052
1052
  return;
1053
- const o = r[r.length - 1];
1054
- if (!o)
1053
+ const a = r[r.length - 1];
1054
+ if (!a)
1055
1055
  return;
1056
- const s = [...t, o];
1057
- return l({
1056
+ const s = [...t, a];
1057
+ return u({
1058
1058
  path: s,
1059
1059
  componentId: d,
1060
- meta: a
1060
+ meta: o
1061
1061
  });
1062
1062
  };
1063
1063
  if (g === "$insert")
1064
- return (r, o) => {
1064
+ return (r, a) => {
1065
1065
  n(r, t, {
1066
1066
  updateType: "insert",
1067
- index: o
1067
+ index: a
1068
1068
  });
1069
1069
  };
1070
1070
  if (g === "$insertMany")
@@ -1074,23 +1074,23 @@ function Pe(e, n, c, i) {
1074
1074
  });
1075
1075
  };
1076
1076
  if (g === "$uniqueInsert")
1077
- return (r, o, s) => {
1078
- const { value: S } = U(
1077
+ return (r, a, s) => {
1078
+ const { value: S } = N(
1079
1079
  e,
1080
1080
  t,
1081
- a
1082
- ), u = R(r) ? r(S) : r;
1083
- let h = null;
1081
+ o
1082
+ ), c = L(r) ? r(S) : r;
1083
+ let m = null;
1084
1084
  if (!S.some((A) => {
1085
- const M = o ? o.every(
1086
- (D) => X(A[D], u[D])
1087
- ) : X(A, u);
1088
- return M && (h = A), M;
1085
+ const M = a ? a.every(
1086
+ (D) => X(A[D], c[D])
1087
+ ) : X(A, c);
1088
+ return M && (m = A), M;
1089
1089
  }))
1090
- n(u, t, { updateType: "insert" });
1091
- else if (s && h) {
1092
- const A = s(h), M = S.map(
1093
- (D) => X(D, h) ? A : D
1090
+ n(c, t, { updateType: "insert" });
1091
+ else if (s && m) {
1092
+ const A = s(m), M = S.map(
1093
+ (D) => X(D, m) ? A : D
1094
1094
  );
1095
1095
  n(M, t, {
1096
1096
  updateType: "update"
@@ -1098,89 +1098,89 @@ function Pe(e, n, c, i) {
1098
1098
  }
1099
1099
  };
1100
1100
  if (g === "$cut")
1101
- return (r, o) => {
1102
- const s = $(e, t);
1101
+ return (r, a) => {
1102
+ const s = V(e, t);
1103
1103
  if (!s?.arrayKeys || s.arrayKeys.length === 0)
1104
1104
  return;
1105
- const S = r === -1 ? s.arrayKeys.length - 1 : r !== void 0 ? r : s.arrayKeys.length - 1, u = s.arrayKeys[S];
1106
- u && n(null, [...t, u], {
1105
+ const S = r === -1 ? s.arrayKeys.length - 1 : r !== void 0 ? r : s.arrayKeys.length - 1, c = s.arrayKeys[S];
1106
+ c && n(null, [...t, c], {
1107
1107
  updateType: "cut"
1108
1108
  });
1109
1109
  };
1110
1110
  if (g === "$cutSelected")
1111
1111
  return () => {
1112
- const r = [e, ...t].join("."), { keys: o } = N(e, t, a);
1113
- if (!o || o.length === 0)
1112
+ const r = [e, ...t].join("."), { keys: a } = F(e, t, o);
1113
+ if (!a || a.length === 0)
1114
1114
  return;
1115
1115
  const s = p.getState().selectedIndicesMap.get(r);
1116
1116
  if (!s)
1117
1117
  return;
1118
1118
  const S = s.split(".").pop();
1119
- if (!o.includes(S))
1119
+ if (!a.includes(S))
1120
1120
  return;
1121
- const u = s.split(".").slice(1);
1121
+ const c = s.split(".").slice(1);
1122
1122
  p.getState().clearSelectedIndex({ arrayKey: r });
1123
- const h = u.slice(0, -1);
1124
- Y(e, h), n(null, u, {
1123
+ const m = c.slice(0, -1);
1124
+ Y(e, m), n(null, c, {
1125
1125
  updateType: "cut"
1126
1126
  });
1127
1127
  };
1128
1128
  if (g === "$cutByValue")
1129
1129
  return (r) => {
1130
1130
  const {
1131
- isArray: o,
1131
+ isArray: a,
1132
1132
  value: s,
1133
1133
  keys: S
1134
- } = N(e, t, a);
1135
- if (!o) return;
1136
- const u = le(s, S, (h) => h === r);
1137
- u && n(null, [...t, u.key], {
1134
+ } = F(e, t, o);
1135
+ if (!a) return;
1136
+ const c = le(s, S, (m) => m === r);
1137
+ c && n(null, [...t, c.key], {
1138
1138
  updateType: "cut"
1139
1139
  });
1140
1140
  };
1141
1141
  if (g === "$toggleByValue")
1142
1142
  return (r) => {
1143
1143
  const {
1144
- isArray: o,
1144
+ isArray: a,
1145
1145
  value: s,
1146
1146
  keys: S
1147
- } = N(e, t, a);
1148
- if (!o) return;
1149
- const u = le(s, S, (h) => h === r);
1150
- if (u) {
1151
- const h = [...t, u.key];
1152
- n(null, h, {
1147
+ } = F(e, t, o);
1148
+ if (!a) return;
1149
+ const c = le(s, S, (m) => m === r);
1150
+ if (c) {
1151
+ const m = [...t, c.key];
1152
+ n(null, m, {
1153
1153
  updateType: "cut"
1154
1154
  });
1155
1155
  } else
1156
1156
  n(r, t, { updateType: "insert" });
1157
1157
  };
1158
1158
  if (g === "$findWith")
1159
- return (r, o) => {
1160
- const { isArray: s, value: S, keys: u } = N(e, t, a);
1159
+ return (r, a) => {
1160
+ const { isArray: s, value: S, keys: c } = F(e, t, o);
1161
1161
  if (!s)
1162
1162
  throw new Error("findWith can only be used on arrays");
1163
- const h = le(
1163
+ const m = le(
1164
1164
  S,
1165
- u,
1166
- (w) => w?.[r] === o
1165
+ c,
1166
+ (w) => w?.[r] === a
1167
1167
  );
1168
- return h ? l({
1169
- path: [...t, h.key],
1168
+ return m ? u({
1169
+ path: [...t, m.key],
1170
1170
  componentId: d,
1171
- meta: a
1171
+ meta: o
1172
1172
  }) : null;
1173
1173
  };
1174
1174
  if (g === "$cutThis") {
1175
- const { value: r } = U(e, t, a), o = t.slice(0, -1);
1176
- return Y(e, o), () => {
1175
+ const { value: r } = N(e, t, o), a = t.slice(0, -1);
1176
+ return Y(e, a), () => {
1177
1177
  n(r, t, { updateType: "cut" });
1178
1178
  };
1179
1179
  }
1180
1180
  if (g === "$get")
1181
1181
  return () => {
1182
1182
  te(e, d, t);
1183
- const { value: r } = U(e, t, a);
1183
+ const { value: r } = N(e, t, o);
1184
1184
  return r;
1185
1185
  };
1186
1186
  if (g === "$$derive")
@@ -1188,10 +1188,10 @@ function Pe(e, n, c, i) {
1188
1188
  _stateKey: e,
1189
1189
  _path: t,
1190
1190
  _effect: r.toString(),
1191
- _meta: a
1191
+ _meta: o
1192
1192
  });
1193
1193
  if (g === "$$get")
1194
- return () => pe({ _stateKey: e, _path: t, _meta: a });
1194
+ return () => pe({ _stateKey: e, _path: t, _meta: o });
1195
1195
  if (g === "$lastSynced") {
1196
1196
  const r = `${e}:${t.join(".")}`;
1197
1197
  return He(r);
@@ -1200,32 +1200,32 @@ function Pe(e, n, c, i) {
1200
1200
  return (r) => ce(i + "-" + e + "-" + r);
1201
1201
  if (g === "$isSelected") {
1202
1202
  const r = t.slice(0, -1);
1203
- if ($(e, r)?.arrayKeys) {
1204
- const s = e + "." + r.join("."), S = p.getState().selectedIndicesMap.get(s), u = e + "." + t.join(".");
1205
- return S === u;
1203
+ if (V(e, r)?.arrayKeys) {
1204
+ const s = e + "." + r.join("."), S = p.getState().selectedIndicesMap.get(s), c = e + "." + t.join(".");
1205
+ return S === c;
1206
1206
  }
1207
1207
  return;
1208
1208
  }
1209
1209
  if (g === "$setSelected")
1210
1210
  return (r) => {
1211
- const o = t.slice(0, -1), s = e + "." + o.join("."), S = e + "." + t.join(".");
1212
- Y(e, o, void 0), p.getState().selectedIndicesMap.get(s), r && p.getState().setSelectedIndex(s, S);
1211
+ const a = t.slice(0, -1), s = e + "." + a.join("."), S = e + "." + t.join(".");
1212
+ Y(e, a, void 0), p.getState().selectedIndicesMap.get(s), r && p.getState().setSelectedIndex(s, S);
1213
1213
  };
1214
1214
  if (g === "$toggleSelected")
1215
1215
  return () => {
1216
- const r = t.slice(0, -1), o = e + "." + r.join("."), s = e + "." + t.join(".");
1217
- p.getState().selectedIndicesMap.get(o) === s ? p.getState().clearSelectedIndex({ arrayKey: o }) : p.getState().setSelectedIndex(o, s), Y(e, r);
1216
+ const r = t.slice(0, -1), a = e + "." + r.join("."), s = e + "." + t.join(".");
1217
+ p.getState().selectedIndicesMap.get(a) === s ? p.getState().clearSelectedIndex({ arrayKey: a }) : p.getState().setSelectedIndex(a, s), Y(e, r);
1218
1218
  };
1219
1219
  if (g === "$clearValidation")
1220
1220
  return (r) => {
1221
- const o = r ? [...t, ...r] : t, s = p.getState(), S = s.getShadowNode(e, o);
1221
+ const a = r ? [...t, ...r] : t, s = p.getState(), S = s.getShadowNode(e, a);
1222
1222
  if (console.log("startNode ", S), !S) return;
1223
- const u = [[S, o]];
1224
- for (console.log("stack ", u); u.length > 0; ) {
1225
- const [h, w] = u.pop();
1226
- if (console.log("while (stack.length ", h, w), !h || typeof h != "object") continue;
1227
- if (h._meta?.validation) {
1228
- h._meta.validation = {
1223
+ const c = [[S, a]];
1224
+ for (console.log("stack ", c); c.length > 0; ) {
1225
+ const [m, w] = c.pop();
1226
+ if (console.log("while (stack.length ", m, w), !m || typeof m != "object") continue;
1227
+ if (m._meta?.validation) {
1228
+ m._meta.validation = {
1229
1229
  status: "NOT_VALIDATED",
1230
1230
  errors: [],
1231
1231
  lastValidated: Date.now(),
@@ -1236,11 +1236,11 @@ function Pe(e, n, c, i) {
1236
1236
  type: "VALIDATION_CLEAR"
1237
1237
  });
1238
1238
  }
1239
- const A = Object.keys(h);
1239
+ const A = Object.keys(m);
1240
1240
  for (const M of A)
1241
- M !== "_meta" && u.push([h[M], [...w, M]]);
1241
+ M !== "_meta" && c.push([m[M], [...w, M]]);
1242
1242
  }
1243
- W(e);
1243
+ U(e);
1244
1244
  };
1245
1245
  if (t.length == 0) {
1246
1246
  if (g === "$_componentId")
@@ -1250,49 +1250,72 @@ function Pe(e, n, c, i) {
1250
1250
  fe({ stateKey: e, options: r, initialOptionsPart: {} });
1251
1251
  };
1252
1252
  if (g === "$_applyUpdate")
1253
- return (r, o, s = "update") => {
1254
- n(r, o, { updateType: s });
1253
+ return (r, a, s = "update") => {
1254
+ n(r, a, { updateType: s });
1255
1255
  };
1256
1256
  if (g === "$_getEffectiveSetState")
1257
1257
  return n;
1258
1258
  if (g === "$getPluginMetaData")
1259
1259
  return (r) => he(e, t)?.get(r);
1260
1260
  if (g === "$addPluginMetaData")
1261
- return (r, o) => ve(e, t, r, o);
1261
+ return (r, a) => ve(e, t, r, a);
1262
1262
  if (g === "$removePluginMetaData")
1263
1263
  return (r) => we(e, t, r);
1264
1264
  if (g === "$addZodValidation")
1265
- return (r, o) => {
1266
- r.forEach((s) => {
1267
- const S = p.getState().getShadowMetadata(e, s.path) || {};
1268
- p.getState().setShadowMetadata(e, s.path, {
1269
- ...S,
1265
+ return (r, a) => {
1266
+ const s = p.getState();
1267
+ r.forEach((S) => {
1268
+ const c = S.path.map(String), m = s.getShadowMetadata(e, c) || {};
1269
+ s.setShadowMetadata(e, c, {
1270
+ ...m,
1270
1271
  validation: {
1271
1272
  status: "INVALID",
1272
1273
  errors: [
1273
1274
  {
1274
- source: o || "client",
1275
- message: s.message,
1275
+ source: a || "client",
1276
+ message: S.message,
1276
1277
  severity: "error",
1277
- code: s.code
1278
+ code: S.code
1278
1279
  }
1279
1280
  ],
1280
1281
  lastValidated: Date.now(),
1281
1282
  validatedValue: void 0
1282
1283
  }
1283
- });
1284
- });
1284
+ }), s.notifyPathSubscribers(
1285
+ [e, ...c].join("."),
1286
+ { type: "VALIDATION_UPDATE" }
1287
+ );
1288
+ }), U(e);
1289
+ };
1290
+ if (g === "$clearZodValidationPaths")
1291
+ return (r) => {
1292
+ const a = p.getState();
1293
+ r.forEach((s) => {
1294
+ const S = a.getShadowMetadata(e, s) || {};
1295
+ S.validation && (a.setShadowMetadata(e, s, {
1296
+ ...S,
1297
+ validation: {
1298
+ status: "NOT_VALIDATED",
1299
+ errors: [],
1300
+ lastValidated: Date.now(),
1301
+ validatedValue: void 0
1302
+ }
1303
+ }), a.notifyPathSubscribers(
1304
+ [e, ...s].join("."),
1305
+ { type: "VALIDATION_CLEAR" }
1306
+ ));
1307
+ }), U(e);
1285
1308
  };
1286
1309
  if (g === "$applyOperation")
1287
- return (r, o) => {
1310
+ return (r, a) => {
1288
1311
  let s;
1289
1312
  if (r.insertAfterId && r.updateType === "insert") {
1290
- const S = $(e, r.path);
1313
+ const S = V(e, r.path);
1291
1314
  if (S?.arrayKeys) {
1292
- const u = S.arrayKeys.indexOf(
1315
+ const c = S.arrayKeys.indexOf(
1293
1316
  r.insertAfterId
1294
1317
  );
1295
- u !== -1 && (s = u + 1);
1318
+ c !== -1 && (s = c + 1);
1296
1319
  }
1297
1320
  }
1298
1321
  n(r.newValue, r.path, {
@@ -1300,31 +1323,31 @@ function Pe(e, n, c, i) {
1300
1323
  itemId: r.itemId,
1301
1324
  index: s,
1302
1325
  // Pass the calculated index
1303
- metaData: o
1326
+ metaData: a
1304
1327
  });
1305
1328
  };
1306
1329
  if (g === "$applyJsonPatch")
1307
1330
  return (r) => {
1308
- const o = p.getState(), s = o.getShadowMetadata(e, []);
1331
+ const a = p.getState(), s = a.getShadowMetadata(e, []);
1309
1332
  if (!s?.components) return;
1310
- const S = (h) => !h || h === "/" ? [] : h.split("/").slice(1).map((w) => w.replace(/~1/g, "/").replace(/~0/g, "~")), u = /* @__PURE__ */ new Set();
1311
- for (const h of r) {
1312
- const w = S(h.path);
1313
- switch (h.op) {
1333
+ const S = (m) => !m || m === "/" ? [] : m.split("/").slice(1).map((w) => w.replace(/~1/g, "/").replace(/~0/g, "~")), c = /* @__PURE__ */ new Set();
1334
+ for (const m of r) {
1335
+ const w = S(m.path);
1336
+ switch (m.op) {
1314
1337
  case "add":
1315
1338
  case "replace": {
1316
- const { value: A } = h;
1317
- o.updateShadowAtPath(e, w, A), o.markAsDirty(e, w, { bubble: !0 });
1339
+ const { value: A } = m;
1340
+ a.updateShadowAtPath(e, w, A), a.markAsDirty(e, w, { bubble: !0 });
1318
1341
  let M = [...w];
1319
1342
  for (; ; ) {
1320
- const D = o.getShadowMetadata(
1343
+ const D = a.getShadowMetadata(
1321
1344
  e,
1322
1345
  M
1323
1346
  );
1324
1347
  if (D?.pathComponents && D.pathComponents.forEach((P) => {
1325
- if (!u.has(P)) {
1348
+ if (!c.has(P)) {
1326
1349
  const O = s.components?.get(P);
1327
- O && (O.forceUpdate(), u.add(P));
1350
+ O && (O.forceUpdate(), c.add(P));
1328
1351
  }
1329
1352
  }), M.length === 0) break;
1330
1353
  M.pop();
@@ -1333,17 +1356,17 @@ function Pe(e, n, c, i) {
1333
1356
  }
1334
1357
  case "remove": {
1335
1358
  const A = w.slice(0, -1);
1336
- o.removeShadowArrayElement(e, w), o.markAsDirty(e, A, { bubble: !0 });
1359
+ a.removeShadowArrayElement(e, w), a.markAsDirty(e, A, { bubble: !0 });
1337
1360
  let M = [...A];
1338
1361
  for (; ; ) {
1339
- const D = o.getShadowMetadata(
1362
+ const D = a.getShadowMetadata(
1340
1363
  e,
1341
1364
  M
1342
1365
  );
1343
1366
  if (D?.pathComponents && D.pathComponents.forEach((P) => {
1344
- if (!u.has(P)) {
1367
+ if (!c.has(P)) {
1345
1368
  const O = s.components?.get(P);
1346
- O && (O.forceUpdate(), u.add(P));
1369
+ O && (O.forceUpdate(), c.add(P));
1347
1370
  }
1348
1371
  }), M.length === 0) break;
1349
1372
  M.pop();
@@ -1354,16 +1377,16 @@ function Pe(e, n, c, i) {
1354
1377
  }
1355
1378
  };
1356
1379
  if (g === "$getComponents")
1357
- return () => $(e, [])?.components;
1380
+ return () => V(e, [])?.components;
1358
1381
  }
1359
1382
  if (g === "$validationWrapper")
1360
1383
  return ({
1361
1384
  children: r,
1362
- hideMessage: o
1385
+ hideMessage: a
1363
1386
  }) => /* @__PURE__ */ Q(
1364
1387
  Oe,
1365
1388
  {
1366
- formOpts: o ? { validation: { message: "" } } : void 0,
1389
+ formOpts: a ? { validation: { message: "" } } : void 0,
1367
1390
  path: t,
1368
1391
  stateKey: e,
1369
1392
  children: r
@@ -1374,9 +1397,9 @@ function Pe(e, n, c, i) {
1374
1397
  if (g === "$update")
1375
1398
  return (r) => (n(r, t, { updateType: "update" }), {
1376
1399
  synced: () => {
1377
- const o = p.getState().getShadowMetadata(e, t);
1378
- L(e, t, {
1379
- ...o,
1400
+ const a = p.getState().getShadowMetadata(e, t);
1401
+ W(e, t, {
1402
+ ...a,
1380
1403
  isDirty: !1,
1381
1404
  stateSource: "server",
1382
1405
  lastServerSync: Date.now()
@@ -1389,10 +1412,10 @@ function Pe(e, n, c, i) {
1389
1412
  }
1390
1413
  });
1391
1414
  if (g === "$toggle") {
1392
- const { value: r } = U(
1415
+ const { value: r } = N(
1393
1416
  e,
1394
1417
  t,
1395
- a
1418
+ o
1396
1419
  );
1397
1420
  if (typeof r != "boolean")
1398
1421
  throw new Error("toggle() can only be used on boolean values");
@@ -1403,9 +1426,9 @@ function Pe(e, n, c, i) {
1403
1426
  };
1404
1427
  }
1405
1428
  if (g === "$isolate")
1406
- return (r, o) => {
1407
- const s = Array.isArray(r), S = s ? r : void 0, u = s ? o : r;
1408
- if (!u || typeof u != "function")
1429
+ return (r, a) => {
1430
+ const s = Array.isArray(r), S = s ? r : void 0, c = s ? a : r;
1431
+ if (!c || typeof c != "function")
1409
1432
  throw new Error(
1410
1433
  "CogsState: $isolate requires a render function."
1411
1434
  );
@@ -1415,67 +1438,67 @@ function Pe(e, n, c, i) {
1415
1438
  stateKey: e,
1416
1439
  path: t,
1417
1440
  dependencies: S,
1418
- rebuildStateShape: l,
1419
- renderFn: u
1441
+ rebuildStateShape: u,
1442
+ renderFn: c
1420
1443
  }
1421
1444
  );
1422
1445
  };
1423
1446
  if (g === "$formElement")
1424
- return (r, o) => /* @__PURE__ */ Q(
1425
- Ue,
1447
+ return (r, a) => /* @__PURE__ */ Q(
1448
+ Ne,
1426
1449
  {
1427
1450
  stateKey: e,
1428
1451
  path: t,
1429
- rebuildStateShape: l,
1452
+ rebuildStateShape: u,
1430
1453
  setState: n,
1431
- formOpts: o,
1454
+ formOpts: a,
1432
1455
  renderFn: r
1433
1456
  }
1434
1457
  );
1435
- const I = [...t, g];
1436
- return l({
1437
- path: I,
1458
+ const k = [...t, g];
1459
+ return u({
1460
+ path: k,
1438
1461
  componentId: d,
1439
- meta: a
1462
+ meta: o
1440
1463
  });
1441
1464
  }
1442
1465
  }, x = new Proxy(_, T);
1443
- return f.set(E, x), x;
1466
+ return f.set($, x), x;
1444
1467
  }
1445
- const m = {
1468
+ const h = {
1446
1469
  $revertToInitialState: (t) => {
1447
- const a = p.getState().getShadowMetadata(e, []);
1470
+ const o = p.getState().getShadowMetadata(e, []);
1448
1471
  let d;
1449
- a?.stateSource === "server" && a.baseServerState ? d = a.baseServerState : d = p.getState().initialStateGlobal[e], qe(e), K(e, d), l({
1472
+ o?.stateSource === "server" && o.baseServerState ? d = o.baseServerState : d = p.getState().initialStateGlobal[e], qe(e), K(e, d), u({
1450
1473
  path: [],
1451
- componentId: c
1474
+ componentId: l
1452
1475
  });
1453
- const V = j(e), b = R(V?.localStorage?.key) ? V?.localStorage?.key(d) : V?.localStorage?.key, E = i && b ? `${i}-${e}-${b}` : void 0;
1454
- return de(E), W(e), d;
1476
+ const E = j(e), b = L(E?.localStorage?.key) ? E?.localStorage?.key(d) : E?.localStorage?.key, $ = i && b ? `${i}-${e}-${b}` : void 0;
1477
+ return de($), U(e), d;
1455
1478
  },
1456
1479
  $initializeAndMergeShadowState: (t) => {
1457
- Re(e, t), W(e);
1480
+ Re(e, t), U(e);
1458
1481
  },
1459
1482
  $updateInitialState: (t) => {
1460
- const a = Pe(
1483
+ const o = Pe(
1461
1484
  e,
1462
1485
  n,
1463
- c,
1486
+ l,
1464
1487
  i
1465
- ), d = p.getState().initialStateGlobal[e], V = j(e), b = R(V?.localStorage?.key) ? V?.localStorage?.key(d) : V?.localStorage?.key, E = i && b ? `${i}-${e}-${b}` : void 0;
1466
- return de(E), Ie(() => {
1488
+ ), d = p.getState().initialStateGlobal[e], E = j(e), b = L(E?.localStorage?.key) ? E?.localStorage?.key(d) : E?.localStorage?.key, $ = i && b ? `${i}-${e}-${b}` : void 0;
1489
+ return de($), ke(() => {
1467
1490
  be(e, t), K(e, t);
1468
1491
  const v = p.getState().getShadowMetadata(e, []);
1469
1492
  v && v?.components?.forEach((_) => {
1470
1493
  _.forceUpdate();
1471
1494
  });
1472
1495
  }), {
1473
- fetchId: (v) => a.$get()[v]
1496
+ fetchId: (v) => o.$get()[v]
1474
1497
  };
1475
1498
  }
1476
1499
  };
1477
- return l({
1478
- componentId: c,
1500
+ return u({
1501
+ componentId: l,
1479
1502
  path: []
1480
1503
  });
1481
1504
  }
@@ -1485,22 +1508,22 @@ function pe(e) {
1485
1508
  function gt({
1486
1509
  proxy: e
1487
1510
  }) {
1488
- const n = q(null), c = q(null), i = q(!1), f = `${e._stateKey}-${e._path.join(".")}`, l = e._path.length > 0 ? e._path.join(".") : "root", m = e._meta?.arrayViews?.[l], y = C(e._stateKey, e._path, m);
1511
+ const n = q(null), l = q(null), i = q(!1), f = `${e._stateKey}-${e._path.join(".")}`, u = e._path.length > 0 ? e._path.join(".") : "root", h = e._meta?.arrayViews?.[u], y = C(e._stateKey, e._path, h);
1489
1512
  return Z(() => {
1490
1513
  const t = n.current;
1491
1514
  if (!t || i.current) return;
1492
- const a = setTimeout(() => {
1515
+ const o = setTimeout(() => {
1493
1516
  if (!t.parentElement) {
1494
1517
  console.warn("Parent element not found for signal", f);
1495
1518
  return;
1496
1519
  }
1497
1520
  const d = t.parentElement, b = Array.from(d.childNodes).indexOf(t);
1498
- let E = d.getAttribute("data-parent-id");
1499
- E || (E = `parent-${crypto.randomUUID()}`, d.setAttribute("data-parent-id", E)), c.current = `instance-${crypto.randomUUID()}`;
1521
+ let $ = d.getAttribute("data-parent-id");
1522
+ $ || ($ = `parent-${crypto.randomUUID()}`, d.setAttribute("data-parent-id", $)), l.current = `instance-${crypto.randomUUID()}`;
1500
1523
  const v = p.getState().getShadowMetadata(e._stateKey, e._path) || {}, _ = v.signals || [];
1501
1524
  _.push({
1502
- instanceId: c.current,
1503
- parentId: E,
1525
+ instanceId: l.current,
1526
+ parentId: $,
1504
1527
  position: b,
1505
1528
  effect: e._effect
1506
1529
  }), p.getState().setShadowMetadata(e._stateKey, e._path, {
@@ -1522,10 +1545,10 @@ function gt({
1522
1545
  t.replaceWith(x), i.current = !0;
1523
1546
  }, 0);
1524
1547
  return () => {
1525
- if (clearTimeout(a), c.current) {
1548
+ if (clearTimeout(o), l.current) {
1526
1549
  const d = p.getState().getShadowMetadata(e._stateKey, e._path) || {};
1527
1550
  d.signals && (d.signals = d.signals.filter(
1528
- (V) => V.instanceId !== c.current
1551
+ (E) => E.instanceId !== l.current
1529
1552
  ), p.getState().setShadowMetadata(e._stateKey, e._path, d));
1530
1553
  }
1531
1554
  };
@@ -1537,7 +1560,7 @@ function gt({
1537
1560
  }
1538
1561
  export {
1539
1562
  pe as $cogsSignal,
1540
- $t as createCogsState,
1563
+ Vt as createCogsState,
1541
1564
  ct as useCogsStateFn
1542
1565
  };
1543
1566
  //# sourceMappingURL=CogsState.js.map