cogsbox-state 0.5.475-canary.8 → 0.5.475-canary.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,9 @@
1
1
  "use client";
2
- import { jsx as Z, Fragment as Me } from "react/jsx-runtime";
2
+ import { jsx as Q, Fragment as Me } from "react/jsx-runtime";
3
3
  import { pluginStore as q } from "./pluginStore.js";
4
4
  import { useState as ee, useRef as x, useCallback as Ae, useEffect as J, useLayoutEffect as $e, useMemo as ye, createElement as ue, startTransition as Ee } from "react";
5
- import { transformStateFunc as Ve, isFunction as R, isDeepEqual as Y, isArray as Te, getDifferences as Ie } from "./utility.js";
6
- import { ValidationWrapper as be, IsolatedComponentWrapper as Pe, FormElementWrapper as ke, MemoizedCogsItemWrapper as De } from "./Components.jsx";
5
+ import { transformStateFunc as Ve, isFunction as R, isDeepEqual as Z, isArray as Te, getDifferences as be } from "./utility.js";
6
+ import { ValidationWrapper as Ie, IsolatedComponentWrapper as Pe, FormElementWrapper as ke, MemoizedCogsItemWrapper as De } from "./Components.jsx";
7
7
  import Ce from "superjson";
8
8
  import { v4 as X } from "uuid";
9
9
  import { getGlobalStore as p, updateShadowTypeInfo as fe } from "./store.js";
@@ -12,13 +12,13 @@ import { runValidation as _e } from "./validation.js";
12
12
  const {
13
13
  getInitialOptions: N,
14
14
  updateInitialStateGlobal: he,
15
- getShadowMetadata: A,
16
- setShadowMetadata: L,
15
+ getShadowMetadata: E,
16
+ setShadowMetadata: B,
17
17
  getShadowValue: D,
18
18
  initializeShadowState: K,
19
19
  initializeAndMergeShadowState: Oe,
20
- updateShadowAtPath: Ue,
21
- insertShadowArrayElement: je,
20
+ updateShadowAtPath: je,
21
+ insertShadowArrayElement: Ue,
22
22
  insertManyShadowArrayElements: ve,
23
23
  removeShadowArrayElement: Ne,
24
24
  setInitialStateOptions: de,
@@ -34,19 +34,19 @@ const {
34
34
  setPluginMetaData: qe,
35
35
  removePluginMetaData: xe
36
36
  } = p.getState(), { notifyUpdate: Je } = q.getState();
37
- function j(e, a, l) {
38
- const s = A(e, a);
37
+ function U(e, a, l) {
38
+ const s = E(e, a);
39
39
  if (!!!s?.arrayKeys)
40
40
  return { isArray: !1, value: p.getState().getShadowValue(e, a), keys: [] };
41
- const c = a.length > 0 ? a.join(".") : "root", m = l?.arrayViews?.[c] ?? s.arrayKeys;
42
- return Array.isArray(m) && m.length === 0 ? { isArray: !0, value: [], keys: [] } : { isArray: !0, value: p.getState().getShadowValue(e, a, m), keys: m ?? [] };
41
+ const c = a.length > 0 ? a.join(".") : "root", h = l?.arrayViews?.[c] ?? s.arrayKeys;
42
+ return Array.isArray(h) && h.length === 0 ? { isArray: !0, value: [], keys: [] } : { isArray: !0, value: p.getState().getShadowValue(e, a, h), keys: h ?? [] };
43
43
  }
44
44
  function oe(e, a, l) {
45
45
  for (let s = 0; s < e.length; s++)
46
46
  if (l(e[s], s)) {
47
- const g = a[s];
48
- if (g)
49
- return { key: g, index: s, value: e[s] };
47
+ const S = a[s];
48
+ if (S)
49
+ return { key: S, index: s, value: e[s] };
50
50
  }
51
51
  return null;
52
52
  }
@@ -62,17 +62,17 @@ function ce({
62
62
  options: a,
63
63
  initialOptionsPart: l
64
64
  }) {
65
- const s = N(e) || {}, g = l[e] || {};
66
- let c = { ...g, ...s }, m = !1;
65
+ const s = N(e) || {}, S = l[e] || {};
66
+ let c = { ...S, ...s }, h = !1;
67
67
  if (a) {
68
68
  const u = (t, o) => {
69
69
  for (const y in o)
70
- o.hasOwnProperty(y) && (o[y] instanceof Object && !Array.isArray(o[y]) && t[y] instanceof Object ? Y(t[y], o[y]) || (u(t[y], o[y]), m = !0) : t[y] !== o[y] && (t[y] = o[y], m = !0));
70
+ o.hasOwnProperty(y) && (o[y] instanceof Object && !Array.isArray(o[y]) && t[y] instanceof Object ? Z(t[y], o[y]) || (u(t[y], o[y]), h = !0) : t[y] !== o[y] && (t[y] = o[y], h = !0));
71
71
  return t;
72
72
  };
73
73
  c = u(c, a);
74
74
  }
75
- if (c.validation && (a?.validation?.hasOwnProperty("onBlur") || s?.validation?.hasOwnProperty("onBlur") || g?.validation?.hasOwnProperty("onBlur") || (c.validation.onBlur = "error", m = !0)), m) {
75
+ if (c.validation && (a?.validation?.hasOwnProperty("onBlur") || s?.validation?.hasOwnProperty("onBlur") || S?.validation?.hasOwnProperty("onBlur") || (c.validation.onBlur = "error", h = !0)), h) {
76
76
  de(e, c);
77
77
  const u = s?.validation?.zodSchemaV4 || s?.validation?.zodSchemaV3, t = c.validation?.zodSchemaV4 && !s?.validation?.zodSchemaV4, o = c.validation?.zodSchemaV3 && !s?.validation?.zodSchemaV3;
78
78
  !u && (t || o) && (t ? fe(
@@ -83,7 +83,7 @@ function ce({
83
83
  e,
84
84
  c.validation.zodSchemaV3,
85
85
  "zod3"
86
- ), B(e));
86
+ ), L(e));
87
87
  }
88
88
  return c;
89
89
  }
@@ -126,14 +126,14 @@ const pt = (e, a) => {
126
126
  }), Object.keys(l).forEach((u) => {
127
127
  K(u, l[u]);
128
128
  });
129
- const g = (u, t) => {
129
+ const S = (u, t) => {
130
130
  const [o] = ee(t?.componentId ?? X()), y = ce({
131
131
  stateKey: u,
132
132
  options: t,
133
133
  initialOptionsPart: s
134
134
  }), $ = x(y);
135
135
  $.current = y;
136
- const V = D(u, []) || l[u], I = ot(
136
+ const V = D(u, []) || l[u], b = ot(
137
137
  V,
138
138
  {
139
139
  stateKey: u,
@@ -150,31 +150,31 @@ const pt = (e, a) => {
150
150
  );
151
151
  return J(() => {
152
152
  t && q.getState().setPluginOptionsForState(u, t);
153
- }, [u, t]), J(() => (q.getState().stateHandlers.set(u, I), () => {
153
+ }, [u, t]), J(() => (q.getState().stateHandlers.set(u, b), () => {
154
154
  q.getState().stateHandlers.delete(u);
155
- }), [u, I]), I;
155
+ }), [u, b]), b;
156
156
  };
157
157
  function c(u, t) {
158
- if (ce({ stateKey: u, options: t, initialOptionsPart: s }), t.localStorage && Ze(u, t), t.formElements) {
158
+ if (ce({ stateKey: u, options: t, initialOptionsPart: s }), t.localStorage && Qe(u, t), t.formElements) {
159
159
  const y = q.getState().registeredPlugins.map(($) => t.formElements.hasOwnProperty($.name) ? {
160
160
  ...$,
161
161
  formWrapper: t.formElements[$.name]
162
162
  } : $);
163
163
  q.getState().setRegisteredPlugins(y);
164
164
  }
165
- B(u);
165
+ L(u);
166
166
  }
167
- function m(u) {
167
+ function h(u) {
168
168
  Object.keys(l).forEach((o) => {
169
169
  c(o, u);
170
170
  });
171
171
  }
172
172
  return {
173
- useCogsState: g,
173
+ useCogsState: S,
174
174
  setCogsOptionsByKey: c,
175
- setCogsOptions: m
175
+ setCogsOptions: h
176
176
  };
177
- }, He = (e, a, l, s, g) => {
177
+ }, He = (e, a, l, s, S) => {
178
178
  l?.log && console.log(
179
179
  "saving to localstorage",
180
180
  a,
@@ -183,13 +183,13 @@ const pt = (e, a) => {
183
183
  );
184
184
  const c = R(l?.localStorage?.key) ? l.localStorage?.key(e) : l?.localStorage?.key;
185
185
  if (c && s) {
186
- const m = `${s}-${a}-${c}`;
186
+ const h = `${s}-${a}-${c}`;
187
187
  let u;
188
188
  try {
189
- u = ae(m)?.lastSyncedWithServer;
189
+ u = ae(h)?.lastSyncedWithServer;
190
190
  } catch {
191
191
  }
192
- const t = A(a, []), o = {
192
+ const t = E(a, []), o = {
193
193
  state: e,
194
194
  lastUpdated: Date.now(),
195
195
  lastSyncedWithServer: u,
@@ -197,7 +197,7 @@ const pt = (e, a) => {
197
197
  baseServerState: t?.baseServerState
198
198
  }, y = Ce.serialize(o);
199
199
  window.localStorage.setItem(
200
- m,
200
+ h,
201
201
  JSON.stringify(y.json)
202
202
  );
203
203
  }
@@ -209,18 +209,18 @@ const pt = (e, a) => {
209
209
  } catch (a) {
210
210
  return console.error("Error loading from localStorage:", a), null;
211
211
  }
212
- }, Ze = (e, a) => {
213
- const l = D(e, []), { sessionId: s } = me(), g = R(a?.localStorage?.key) ? a.localStorage.key(l) : a?.localStorage?.key;
214
- if (g && s) {
212
+ }, Qe = (e, a) => {
213
+ const l = D(e, []), { sessionId: s } = me(), S = R(a?.localStorage?.key) ? a.localStorage.key(l) : a?.localStorage?.key;
214
+ if (S && s) {
215
215
  const c = ae(
216
- `${s}-${e}-${g}`
216
+ `${s}-${e}-${S}`
217
217
  );
218
218
  if (c && c.lastUpdated > (c.lastSyncedWithServer || 0))
219
- return B(e), !0;
219
+ return L(e), !0;
220
220
  }
221
221
  return !1;
222
- }, B = (e) => {
223
- const a = A(e, []);
222
+ }, L = (e) => {
223
+ const a = E(e, []);
224
224
  if (!a) return;
225
225
  const l = /* @__PURE__ */ new Set();
226
226
  a?.components?.forEach((s) => {
@@ -230,16 +230,16 @@ const pt = (e, a) => {
230
230
  });
231
231
  };
232
232
  function te(e, a, l, s) {
233
- const g = A(e, a);
234
- if (L(e, a, {
235
- ...g,
233
+ const S = E(e, a);
234
+ if (B(e, a, {
235
+ ...S,
236
236
  isDirty: !1,
237
237
  stateSource: "server",
238
238
  lastServerSync: s || Date.now()
239
239
  }), Array.isArray(l)) {
240
- const c = A(e, a);
241
- c?.arrayKeys && c.arrayKeys.forEach((m, u) => {
242
- const t = [...a, m], o = l[u];
240
+ const c = E(e, a);
241
+ c?.arrayKeys && c.arrayKeys.forEach((h, u) => {
242
+ const t = [...a, h], o = l[u];
243
243
  o !== void 0 && te(
244
244
  e,
245
245
  t,
@@ -248,85 +248,85 @@ function te(e, a, l, s) {
248
248
  );
249
249
  });
250
250
  } else l && typeof l == "object" && l.constructor === Object && Object.keys(l).forEach((c) => {
251
- const m = [...a, c], u = l[c];
252
- te(e, m, u, s);
251
+ const h = [...a, c], u = l[c];
252
+ te(e, h, u, s);
253
253
  });
254
254
  }
255
255
  let re = [], le = !1;
256
- function Qe() {
256
+ function Ye() {
257
257
  le || (le = !0, queueMicrotask(() => {
258
258
  nt();
259
259
  }));
260
260
  }
261
- function Ye(e, a) {
262
- e?.signals?.length && e.signals.forEach(({ parentId: l, position: s, effect: g }) => {
261
+ function Ze(e, a) {
262
+ e?.signals?.length && e.signals.forEach(({ parentId: l, position: s, effect: S }) => {
263
263
  const c = document.querySelector(`[data-parent-id="${l}"]`);
264
264
  if (!c) return;
265
- const m = Array.from(c.childNodes);
266
- if (!m[s]) return;
265
+ const h = Array.from(c.childNodes);
266
+ if (!h[s]) return;
267
267
  let u = a;
268
- if (g && a !== null)
268
+ if (S && a !== null)
269
269
  try {
270
- u = new Function("state", `return (${g})(state)`)(
270
+ u = new Function("state", `return (${S})(state)`)(
271
271
  a
272
272
  );
273
273
  } catch (t) {
274
274
  console.error("Error evaluating effect function:", t);
275
275
  }
276
- u !== null && typeof u == "object" && (u = JSON.stringify(u)), m[s].textContent = String(u ?? "");
276
+ u !== null && typeof u == "object" && (u = JSON.stringify(u)), h[s].textContent = String(u ?? "");
277
277
  });
278
278
  }
279
279
  function Xe(e, a, l) {
280
- const s = A(e, []);
280
+ const s = E(e, []);
281
281
  if (!s?.components)
282
282
  return /* @__PURE__ */ new Set();
283
- const g = /* @__PURE__ */ new Set();
283
+ const S = /* @__PURE__ */ new Set();
284
284
  if (l.type === "update") {
285
285
  let c = [...a];
286
286
  for (; ; ) {
287
- const m = A(e, c);
288
- if (m?.pathComponents && m.pathComponents.forEach((u) => {
287
+ const h = E(e, c);
288
+ if (h?.pathComponents && h.pathComponents.forEach((u) => {
289
289
  const t = s.components?.get(u);
290
- t && ((Array.isArray(t.reactiveType) ? t.reactiveType : [t.reactiveType || "component"]).includes("none") || g.add(t));
290
+ t && ((Array.isArray(t.reactiveType) ? t.reactiveType : [t.reactiveType || "component"]).includes("none") || S.add(t));
291
291
  }), c.length === 0) break;
292
292
  c.pop();
293
293
  }
294
- l.newValue && typeof l.newValue == "object" && !Te(l.newValue) && Ie(l.newValue, l.oldValue).forEach((u) => {
295
- const t = u.split("."), o = [...a, ...t], y = A(e, o);
294
+ l.newValue && typeof l.newValue == "object" && !Te(l.newValue) && be(l.newValue, l.oldValue).forEach((u) => {
295
+ const t = u.split("."), o = [...a, ...t], y = E(e, o);
296
296
  y?.pathComponents && y.pathComponents.forEach(($) => {
297
297
  const V = s.components?.get($);
298
- V && ((Array.isArray(V.reactiveType) ? V.reactiveType : [V.reactiveType || "component"]).includes("none") || g.add(V));
298
+ V && ((Array.isArray(V.reactiveType) ? V.reactiveType : [V.reactiveType || "component"]).includes("none") || S.add(V));
299
299
  });
300
300
  });
301
301
  } else if (l.type === "insert" || l.type === "cut" || l.type === "insert_many") {
302
- let m = [...l.type === "insert" ? a : a.slice(0, -1)];
302
+ let h = [...l.type === "insert" ? a : a.slice(0, -1)];
303
303
  for (; ; ) {
304
- const u = A(e, m);
304
+ const u = E(e, h);
305
305
  if (u?.pathComponents && u.pathComponents.forEach((t) => {
306
306
  const o = s.components?.get(t);
307
- o && g.add(o);
308
- }), m.length === 0) break;
309
- m.pop();
307
+ o && S.add(o);
308
+ }), h.length === 0) break;
309
+ h.pop();
310
310
  }
311
311
  }
312
- return g;
312
+ return S;
313
313
  }
314
314
  function Ke(e, a, l) {
315
- const s = p.getState().getShadowValue(e, a), g = R(l) ? l(s) : l;
316
- if (Y(s, g))
315
+ const s = p.getState().getShadowValue(e, a), S = R(l) ? l(s) : l;
316
+ if (Z(s, S))
317
317
  return null;
318
- Ue(e, a, g), ne(e, a, { bubble: !0 });
319
- const c = A(e, a);
318
+ je(e, a, S), ne(e, a, { bubble: !0 });
319
+ const c = E(e, a);
320
320
  return {
321
321
  type: "update",
322
322
  oldValue: s,
323
- newValue: g,
323
+ newValue: S,
324
324
  shadowMeta: c
325
325
  };
326
326
  }
327
327
  function et(e, a, l) {
328
328
  ve(e, a, l), ne(e, a, { bubble: !0 });
329
- const s = A(e, a);
329
+ const s = E(e, a);
330
330
  return {
331
331
  type: "insert_many",
332
332
  count: l.length,
@@ -334,29 +334,29 @@ function et(e, a, l) {
334
334
  path: a
335
335
  };
336
336
  }
337
- function tt(e, a, l, s, g) {
337
+ function tt(e, a, l, s, S) {
338
338
  let c;
339
339
  if (R(l)) {
340
340
  const { value: o } = W(e, a);
341
341
  c = l({ state: o });
342
342
  } else
343
343
  c = l;
344
- const m = je(
344
+ const h = Ue(
345
345
  e,
346
346
  a,
347
347
  c,
348
348
  s,
349
- g
349
+ S
350
350
  );
351
351
  ne(e, a, { bubble: !0 });
352
- const u = A(e, a);
352
+ const u = E(e, a);
353
353
  let t;
354
354
  return u?.arrayKeys && s !== void 0 && s > 0 && (t = u.arrayKeys[s - 1]), {
355
355
  type: "insert",
356
356
  newValue: c,
357
357
  shadowMeta: u,
358
358
  path: a,
359
- itemId: m,
359
+ itemId: h,
360
360
  insertAfterId: t
361
361
  };
362
362
  }
@@ -371,53 +371,53 @@ function nt() {
371
371
  l.push(s);
372
372
  continue;
373
373
  }
374
- const g = s, c = g.type === "cut" ? null : g.newValue;
375
- g.shadowMeta?.signals?.length > 0 && a.push({ shadowMeta: g.shadowMeta, displayValue: c }), Xe(
376
- g.stateKey,
377
- g.path,
378
- g
374
+ const S = s, c = S.type === "cut" ? null : S.newValue;
375
+ S.shadowMeta?.signals?.length > 0 && a.push({ shadowMeta: S.shadowMeta, displayValue: c }), Xe(
376
+ S.stateKey,
377
+ S.path,
378
+ S
379
379
  ).forEach((u) => {
380
380
  e.add(u);
381
381
  });
382
382
  }
383
- l.length > 0 && Re(l), a.forEach(({ shadowMeta: s, displayValue: g }) => {
384
- Ye(s, g);
383
+ l.length > 0 && Re(l), a.forEach(({ shadowMeta: s, displayValue: S }) => {
384
+ Ze(s, S);
385
385
  }), e.forEach((s) => {
386
386
  s.forceUpdate();
387
387
  }), re = [], le = !1;
388
388
  }
389
389
  function at(e, a, l) {
390
- return (g, c, m) => {
391
- s(e, c, g, m);
390
+ return (S, c, h) => {
391
+ s(e, c, S, h);
392
392
  };
393
- function s(g, c, m, u) {
393
+ function s(S, c, h, u) {
394
394
  let t;
395
395
  switch (u.updateType) {
396
396
  case "update":
397
- t = Ke(g, c, m);
397
+ t = Ke(S, c, h);
398
398
  break;
399
399
  case "insert":
400
400
  t = tt(
401
- g,
401
+ S,
402
402
  c,
403
- m,
403
+ h,
404
404
  u.index,
405
405
  u.itemId
406
406
  );
407
407
  break;
408
408
  case "insert_many":
409
- t = et(g, c, m);
409
+ t = et(S, c, h);
410
410
  break;
411
411
  case "cut":
412
- t = rt(g, c);
412
+ t = rt(S, c);
413
413
  break;
414
414
  }
415
415
  if (t === null)
416
416
  return;
417
- t.stateKey = g, t.path = c, re.push(t), Qe();
417
+ t.stateKey = S, t.path = c, re.push(t), Ye();
418
418
  const o = {
419
419
  timeStamp: Date.now(),
420
- stateKey: g,
420
+ stateKey: S,
421
421
  path: c,
422
422
  updateType: u.updateType,
423
423
  status: "new",
@@ -429,7 +429,7 @@ function at(e, a, l) {
429
429
  };
430
430
  re.push(o), t.newValue !== void 0 && He(
431
431
  t.newValue,
432
- g,
432
+ S,
433
433
  l.current,
434
434
  a
435
435
  ), l.current?.middleware && l.current.middleware({ update: o }), _e(o, u.validationTrigger || "programmatic"), Je(o);
@@ -439,16 +439,16 @@ function ot(e, {
439
439
  stateKey: a,
440
440
  localStorage: l,
441
441
  formElements: s,
442
- reactiveDeps: g,
442
+ reactiveDeps: S,
443
443
  reactiveType: c,
444
- componentId: m,
444
+ componentId: h,
445
445
  defaultState: u,
446
446
  dependencies: t,
447
447
  serverState: o
448
448
  } = {}) {
449
449
  const [y, $] = ee({}), { sessionId: V } = me();
450
- let I = !a;
451
- const [v] = ee(a ?? X()), F = x(m ?? X()), C = x(
450
+ let b = !a;
451
+ const [v] = ee(a ?? X()), F = x(h ?? X()), C = x(
452
452
  null
453
453
  );
454
454
  C.current = N(v) ?? null;
@@ -462,14 +462,14 @@ function ot(e, {
462
462
  timestamp: n.serverState.timestamp || Date.now()
463
463
  };
464
464
  if (n?.localStorage?.key && V) {
465
- const d = R(n.localStorage.key) ? n.localStorage.key(i) : n.localStorage.key, h = ae(
465
+ const d = R(n.localStorage.key) ? n.localStorage.key(i) : n.localStorage.key, m = ae(
466
466
  `${V}-${v}-${d}`
467
467
  );
468
- if (h && h.lastUpdated > (n?.serverState?.timestamp || 0))
468
+ if (m && m.lastUpdated > (n?.serverState?.timestamp || 0))
469
469
  return {
470
- value: h.state,
470
+ value: m.state,
471
471
  source: "localStorage",
472
- timestamp: h.lastUpdated
472
+ timestamp: m.lastUpdated
473
473
  };
474
474
  }
475
475
  return {
@@ -488,26 +488,26 @@ function ot(e, {
488
488
  if (n?.status !== "success" || n.data === void 0)
489
489
  return;
490
490
  se(v, { serverState: n });
491
- const i = typeof n.merge == "object" ? n.merge : n.merge === !0 ? { strategy: "append", key: "id" } : null, S = D(v, []), d = n.data;
492
- if (i && i.strategy === "append" && "key" in i && Array.isArray(S) && Array.isArray(d)) {
493
- const h = i.key;
494
- if (!h) {
491
+ const i = typeof n.merge == "object" ? n.merge : n.merge === !0 ? { strategy: "append", key: "id" } : null, f = D(v, []), d = n.data;
492
+ if (i && i.strategy === "append" && "key" in i && Array.isArray(f) && Array.isArray(d)) {
493
+ const m = i.key;
494
+ if (!m) {
495
495
  console.error(
496
496
  "CogsState: Merge strategy 'append' requires a 'key' field."
497
497
  );
498
498
  return;
499
499
  }
500
500
  const w = new Set(
501
- S.map((b) => b[h])
501
+ f.map((I) => I[m])
502
502
  ), M = d.filter(
503
- (b) => !w.has(b[h])
503
+ (I) => !w.has(I[m])
504
504
  );
505
505
  M.length > 0 && ve(v, [], M);
506
- const E = D(v, []);
506
+ const A = D(v, []);
507
507
  te(
508
508
  v,
509
509
  [],
510
- E,
510
+ A,
511
511
  n.timestamp || Date.now()
512
512
  );
513
513
  } else
@@ -517,7 +517,7 @@ function ot(e, {
517
517
  d,
518
518
  n.timestamp || Date.now()
519
519
  );
520
- B(v);
520
+ L(v);
521
521
  }
522
522
  }), [v]), J(() => {
523
523
  const P = p.getState().getShadowMetadata(v, []);
@@ -526,126 +526,126 @@ function ot(e, {
526
526
  const r = N(v), n = {
527
527
  localStorageEnabled: !!r?.localStorage?.key
528
528
  };
529
- if (L(v, [], {
529
+ if (B(v, [], {
530
530
  ...P,
531
531
  features: n
532
532
  }), r?.defaultState !== void 0 || u !== void 0) {
533
- const h = r?.defaultState || u;
533
+ const m = r?.defaultState || u;
534
534
  r?.defaultState || se(v, {
535
- defaultState: h
535
+ defaultState: m
536
536
  });
537
537
  }
538
- const { value: i, source: S, timestamp: d } = G();
539
- K(v, i), L(v, [], {
540
- stateSource: S,
541
- lastServerSync: S === "server" ? d : void 0,
542
- isDirty: S === "server" ? !1 : void 0,
543
- baseServerState: S === "server" ? i : void 0
544
- }), S === "server" && o && ge(v, o), B(v);
538
+ const { value: i, source: f, timestamp: d } = G();
539
+ K(v, i), B(v, [], {
540
+ stateSource: f,
541
+ lastServerSync: f === "server" ? d : void 0,
542
+ isDirty: f === "server" ? !1 : void 0,
543
+ baseServerState: f === "server" ? i : void 0
544
+ }), f === "server" && o && ge(v, o), L(v);
545
545
  }, [v, ...t || []]), $e(() => {
546
- I && se(v, {
546
+ b && se(v, {
547
547
  formElements: s,
548
548
  defaultState: u,
549
549
  localStorage: l,
550
550
  middleware: C.current?.middleware
551
551
  });
552
- const P = `${v}////${F.current}`, r = A(v, []), n = r?.components || /* @__PURE__ */ new Map();
552
+ const P = `${v}////${F.current}`, r = E(v, []), n = r?.components || /* @__PURE__ */ new Map();
553
553
  return n.set(P, {
554
554
  forceUpdate: () => $({}),
555
555
  reactiveType: c ?? ["component"],
556
556
  paths: /* @__PURE__ */ new Set(),
557
- depsFunction: g || void 0,
558
- deps: g ? g(D(v, [])) : [],
559
- prevDeps: g ? g(D(v, [])) : []
560
- }), L(v, [], {
557
+ depsFunction: S || void 0,
558
+ deps: S ? S(D(v, [])) : [],
559
+ prevDeps: S ? S(D(v, [])) : []
560
+ }), B(v, [], {
561
561
  ...r,
562
562
  components: n
563
563
  }), $({}), () => {
564
- const i = A(v, []), S = i?.components?.get(P);
565
- S?.paths && S.paths.forEach((d) => {
564
+ const i = E(v, []), f = i?.components?.get(P);
565
+ f?.paths && f.paths.forEach((d) => {
566
566
  const w = d.split(".").slice(1), M = p.getState().getShadowMetadata(v, w);
567
567
  M?.pathComponents && M.pathComponents.size === 0 && (delete M.pathComponents, p.getState().setShadowMetadata(v, w, M));
568
- }), i?.components && L(v, [], i);
568
+ }), i?.components && B(v, [], i);
569
569
  };
570
570
  }, []);
571
- const f = at(
571
+ const g = at(
572
572
  v,
573
573
  V,
574
574
  C
575
575
  );
576
576
  return p.getState().initialStateGlobal[v] || he(v, e), ye(() => we(
577
577
  v,
578
- f,
578
+ g,
579
579
  F.current,
580
580
  V
581
581
  ), [v, V]);
582
582
  }
583
583
  const st = (e, a, l) => {
584
- let s = A(e, a)?.arrayKeys || [];
585
- const g = l?.transforms;
586
- if (!g || g.length === 0)
584
+ let s = E(e, a)?.arrayKeys || [];
585
+ const S = l?.transforms;
586
+ if (!S || S.length === 0)
587
587
  return s;
588
- for (const c of g)
588
+ for (const c of S)
589
589
  if (c.type === "filter") {
590
- const m = [];
590
+ const h = [];
591
591
  s.forEach((u, t) => {
592
592
  const o = D(e, [...a, u]);
593
- c.fn(o, t) && m.push(u);
594
- }), s = m;
595
- } else c.type === "sort" && s.sort((m, u) => {
596
- const t = D(e, [...a, m]), o = D(e, [...a, u]);
593
+ c.fn(o, t) && h.push(u);
594
+ }), s = h;
595
+ } else c.type === "sort" && s.sort((h, u) => {
596
+ const t = D(e, [...a, h]), o = D(e, [...a, u]);
597
597
  return c.fn(t, o);
598
598
  });
599
599
  return s;
600
600
  }, ie = (e, a, l) => {
601
- const s = `${e}////${a}`, c = A(e, [])?.components?.get(s);
601
+ const s = `${e}////${a}`, c = E(e, [])?.components?.get(s);
602
602
  !c || c.reactiveType === "none" || !(Array.isArray(c.reactiveType) ? c.reactiveType : [c.reactiveType]).includes("component") || Fe(e, l, s);
603
- }, Q = (e, a, l) => {
604
- const s = A(e, []), g = /* @__PURE__ */ new Set();
605
- s?.components && s.components.forEach((m, u) => {
606
- (Array.isArray(m.reactiveType) ? m.reactiveType : [m.reactiveType || "component"]).includes("all") && (m.forceUpdate(), g.add(u));
607
- }), A(e, [
603
+ }, Y = (e, a, l) => {
604
+ const s = E(e, []), S = /* @__PURE__ */ new Set();
605
+ s?.components && s.components.forEach((h, u) => {
606
+ (Array.isArray(h.reactiveType) ? h.reactiveType : [h.reactiveType || "component"]).includes("all") && (h.forceUpdate(), S.add(u));
607
+ }), E(e, [
608
608
  ...a,
609
609
  "getSelected"
610
- ])?.pathComponents?.forEach((m) => {
611
- s?.components?.get(m)?.forceUpdate();
610
+ ])?.pathComponents?.forEach((h) => {
611
+ s?.components?.get(h)?.forceUpdate();
612
612
  });
613
- const c = A(e, a);
614
- for (let m of c?.arrayKeys || []) {
615
- const u = m + ".selected", t = A(e, u.split(".").slice(1));
616
- m == l && t?.pathComponents?.forEach((o) => {
613
+ const c = E(e, a);
614
+ for (let h of c?.arrayKeys || []) {
615
+ const u = h + ".selected", t = E(e, u.split(".").slice(1));
616
+ h == l && t?.pathComponents?.forEach((o) => {
617
617
  s?.components?.get(o)?.forceUpdate();
618
618
  });
619
619
  }
620
620
  };
621
621
  function W(e, a, l) {
622
- const s = A(e, a), g = a.length > 0 ? a.join(".") : "root", c = l?.arrayViews?.[g];
622
+ const s = E(e, a), S = a.length > 0 ? a.join(".") : "root", c = l?.arrayViews?.[S];
623
623
  if (Array.isArray(c) && c.length === 0)
624
624
  return {
625
625
  shadowMeta: s,
626
626
  value: [],
627
627
  arrayKeys: s?.arrayKeys
628
628
  };
629
- const m = D(e, a, c);
629
+ const h = D(e, a, c);
630
630
  return {
631
631
  shadowMeta: s,
632
- value: m,
632
+ value: h,
633
633
  arrayKeys: s?.arrayKeys
634
634
  };
635
635
  }
636
636
  function we(e, a, l, s) {
637
- const g = /* @__PURE__ */ new Map();
637
+ const S = /* @__PURE__ */ new Map();
638
638
  function c({
639
639
  path: t = [],
640
640
  meta: o,
641
641
  componentId: y
642
642
  }) {
643
643
  const $ = o ? JSON.stringify(o.arrayViews || o.transforms) : "", V = t.join(".") + ":" + y + ":" + $;
644
- if (g.has(V))
645
- return g.get(V);
646
- const I = [e, ...t].join("."), v = () => {
644
+ if (S.has(V))
645
+ return S.get(V);
646
+ const b = [e, ...t].join("."), v = () => {
647
647
  }, F = {
648
- apply(G, f, H) {
648
+ apply(G, g, H) {
649
649
  if (H.length === 0) {
650
650
  const r = t.length > 0 ? t.join(".") : "root", n = o?.arrayViews?.[r];
651
651
  return D(e, t, n);
@@ -653,35 +653,35 @@ function we(e, a, l, s) {
653
653
  const P = H[0];
654
654
  return a(P, t, { updateType: "update" }), !0;
655
655
  },
656
- get(G, f, H) {
657
- if (f === "call" || f === "apply" || f === "bind")
658
- return Reflect.get(G, f, H);
659
- if (typeof f != "string")
660
- return Reflect.get(G, f);
661
- if (t.length === 0 && f in m)
662
- return m[f];
663
- if (typeof f == "string" && !f.startsWith("$")) {
664
- const r = [...t, f];
656
+ get(G, g, H) {
657
+ if (g === "call" || g === "apply" || g === "bind")
658
+ return Reflect.get(G, g, H);
659
+ if (typeof g != "string")
660
+ return Reflect.get(G, g);
661
+ if (t.length === 0 && g in h)
662
+ return h[g];
663
+ if (typeof g == "string" && !g.startsWith("$")) {
664
+ const r = [...t, g];
665
665
  return c({
666
666
  path: r,
667
667
  componentId: y,
668
668
  meta: o
669
669
  });
670
670
  }
671
- if (f === "$_rebuildStateShape")
671
+ if (g === "$_rebuildStateShape")
672
672
  return c;
673
- if (f === "$sync" && t.length === 0)
673
+ if (g === "$sync" && t.length === 0)
674
674
  return async function() {
675
675
  const r = p.getState().getInitialOptions(e), n = r?.sync;
676
676
  if (!n)
677
677
  return console.error(`No mutation defined for state key "${e}"`), { success: !1, error: "No mutation defined" };
678
- const i = p.getState().getShadowValue(e, []), S = r?.validation?.key;
678
+ const i = p.getState().getShadowValue(e, []), f = r?.validation?.key;
679
679
  try {
680
680
  const d = await n.action(i);
681
681
  if (d && !d.success && d.errors, d?.success) {
682
- const h = p.getState().getShadowMetadata(e, []);
683
- L(e, [], {
684
- ...h,
682
+ const m = p.getState().getShadowMetadata(e, []);
683
+ B(e, [], {
684
+ ...m,
685
685
  isDirty: !1,
686
686
  lastServerSync: Date.now(),
687
687
  stateSource: "server",
@@ -694,28 +694,28 @@ function we(e, a, l, s) {
694
694
  return n.onError && n.onError(d), { success: !1, error: d };
695
695
  }
696
696
  };
697
- if (f === "$_status" || f === "$getStatus") {
697
+ if (g === "$_status" || g === "$getStatus") {
698
698
  const r = () => {
699
699
  const { shadowMeta: n, value: i } = W(e, t, o);
700
700
  return n?.isDirty === !0 ? "dirty" : n?.stateSource === "server" || n?.isDirty === !1 ? "synced" : n?.stateSource === "localStorage" ? "restored" : n?.stateSource === "default" || i !== void 0 ? "fresh" : "unknown";
701
701
  };
702
- return f === "$_status" ? r() : r;
702
+ return g === "$_status" ? r() : r;
703
703
  }
704
- if (f === "$removeStorage")
704
+ if (g === "$removeStorage")
705
705
  return () => {
706
- const r = p.getState().initialStateGlobal[e], n = N(e), i = R(n?.localStorage?.key) ? n.localStorage.key(r) : n?.localStorage?.key, S = `${s}-${e}-${i}`;
707
- S && localStorage.removeItem(S);
706
+ const r = p.getState().initialStateGlobal[e], n = N(e), i = R(n?.localStorage?.key) ? n.localStorage.key(r) : n?.localStorage?.key, f = `${s}-${e}-${i}`;
707
+ f && localStorage.removeItem(f);
708
708
  };
709
- if (f === "$validate")
709
+ if (g === "$validate")
710
710
  return () => {
711
- const r = p.getState(), { value: n } = W(e, t, o), i = r.getInitialOptions(e), S = i?.validation?.zodSchemaV4 || i?.validation?.zodSchemaV3;
712
- if (!S)
711
+ const r = p.getState(), { value: n } = W(e, t, o), i = r.getInitialOptions(e), f = i?.validation?.zodSchemaV4 || i?.validation?.zodSchemaV3;
712
+ if (!f)
713
713
  return { success: !0, data: n };
714
- const d = S.safeParse(n);
714
+ const d = f.safeParse(n);
715
715
  if (d.success) {
716
- const h = r.getShadowMetadata(e, t) || {};
716
+ const m = r.getShadowMetadata(e, t) || {};
717
717
  r.setShadowMetadata(e, t, {
718
- ...h,
718
+ ...m,
719
719
  validation: {
720
720
  status: "VALID",
721
721
  errors: [],
@@ -724,9 +724,9 @@ function we(e, a, l, s) {
724
724
  });
725
725
  } else
726
726
  (d.error?.issues || d.error?.errors || []).forEach((w) => {
727
- const M = [...t, ...w.path.map(String)], E = r.getShadowMetadata(e, M) || {};
727
+ const M = [...t, ...w.path.map(String)], A = r.getShadowMetadata(e, M) || {};
728
728
  r.setShadowMetadata(e, M, {
729
- ...E,
729
+ ...A,
730
730
  validation: {
731
731
  status: "INVALID",
732
732
  errors: [
@@ -742,14 +742,14 @@ function we(e, a, l, s) {
742
742
  }
743
743
  });
744
744
  });
745
- return B(e), d;
745
+ return L(e), d;
746
746
  };
747
- if (f === "$showValidationErrors")
747
+ if (g === "$showValidationErrors")
748
748
  return () => {
749
749
  const { shadowMeta: r } = W(e, t, o);
750
750
  return r?.validation?.status === "INVALID" && r.validation.errors.length > 0 ? r.validation.errors.filter((n) => n.severity === "error").map((n) => n.message) : [];
751
751
  };
752
- if (f === "$getSelected")
752
+ if (g === "$getSelected")
753
753
  return () => {
754
754
  const r = [e, ...t].join(".");
755
755
  ie(e, y, [
@@ -759,8 +759,8 @@ function we(e, a, l, s) {
759
759
  const n = p.getState().selectedIndicesMap.get(r);
760
760
  if (!n)
761
761
  return;
762
- const i = t.join("."), S = o?.arrayViews?.[i], d = n.split(".").pop();
763
- if (!(S && !S.includes(d) || D(
762
+ const i = t.join("."), f = o?.arrayViews?.[i], d = n.split(".").pop();
763
+ if (!(f && !f.includes(d) || D(
764
764
  e,
765
765
  n.split(".").slice(1)
766
766
  ) === void 0))
@@ -770,63 +770,63 @@ function we(e, a, l, s) {
770
770
  meta: o
771
771
  });
772
772
  };
773
- if (f === "$getSelectedIndex")
773
+ if (g === "$getSelectedIndex")
774
774
  return () => {
775
775
  const r = e + "." + t.join(".");
776
776
  t.join(".");
777
777
  const n = p.getState().selectedIndicesMap.get(r);
778
778
  if (!n)
779
779
  return -1;
780
- const { keys: i } = j(e, t, o);
780
+ const { keys: i } = U(e, t, o);
781
781
  if (!i)
782
782
  return -1;
783
- const S = n.split(".").pop();
784
- return i.indexOf(S);
783
+ const f = n.split(".").pop();
784
+ return i.indexOf(f);
785
785
  };
786
- if (f === "$clearSelected")
787
- return Q(e, t), () => {
786
+ if (g === "$clearSelected")
787
+ return Y(e, t), () => {
788
788
  Le({
789
789
  arrayKey: e + "." + t.join(".")
790
790
  });
791
791
  };
792
- if (f === "$map")
792
+ if (g === "$map")
793
793
  return (r) => {
794
- const { value: n, keys: i } = j(
794
+ const { value: n, keys: i } = U(
795
795
  e,
796
796
  t,
797
797
  o
798
798
  );
799
799
  if (ie(e, y, t), !i || !Array.isArray(n))
800
800
  return [];
801
- const S = c({
801
+ const f = c({
802
802
  path: t,
803
803
  componentId: y,
804
804
  meta: o
805
805
  });
806
- return n.map((d, h) => {
807
- const w = i[h];
806
+ return n.map((d, m) => {
807
+ const w = i[m];
808
808
  if (!w) return;
809
- const M = [...t, w], E = c({
809
+ const M = [...t, w], A = c({
810
810
  path: M,
811
811
  // This now correctly points to the item in the shadow store.
812
812
  componentId: y,
813
813
  meta: o
814
814
  });
815
- return r(E, h, S);
815
+ return r(A, m, f);
816
816
  });
817
817
  };
818
- if (f === "$filter")
818
+ if (g === "$filter")
819
819
  return (r) => {
820
- const n = t.length > 0 ? t.join(".") : "root", { keys: i, value: S } = j(
820
+ const n = t.length > 0 ? t.join(".") : "root", { keys: i, value: f } = U(
821
821
  e,
822
822
  t,
823
823
  o
824
824
  );
825
- if (!Array.isArray(S))
825
+ if (!Array.isArray(f))
826
826
  throw new Error("filter can only be used on arrays");
827
827
  const d = [];
828
- return S.forEach((h, w) => {
829
- if (r(h, w)) {
828
+ return f.forEach((m, w) => {
829
+ if (r(m, w)) {
830
830
  const M = i[w];
831
831
  M && d.push(M);
832
832
  }
@@ -846,21 +846,21 @@ function we(e, a, l, s) {
846
846
  }
847
847
  });
848
848
  };
849
- if (f === "$sort")
849
+ if (g === "$sort")
850
850
  return (r) => {
851
- const n = t.length > 0 ? t.join(".") : "root", { value: i, keys: S } = j(
851
+ const n = t.length > 0 ? t.join(".") : "root", { value: i, keys: f } = U(
852
852
  e,
853
853
  t,
854
854
  o
855
855
  );
856
- if (!Array.isArray(i) || !S)
856
+ if (!Array.isArray(i) || !f)
857
857
  throw new Error("No array keys found for sorting");
858
858
  const d = i.map((w, M) => ({
859
859
  item: w,
860
- key: S[M]
860
+ key: f[M]
861
861
  }));
862
862
  d.sort((w, M) => r(w.item, M.item));
863
- const h = d.map((w) => w.key);
863
+ const m = d.map((w) => w.key);
864
864
  return c({
865
865
  path: t,
866
866
  componentId: y,
@@ -868,7 +868,7 @@ function we(e, a, l, s) {
868
868
  ...o,
869
869
  arrayViews: {
870
870
  ...o?.arrayViews || {},
871
- [n]: h
871
+ [n]: m
872
872
  },
873
873
  transforms: [
874
874
  ...o?.transforms || [],
@@ -877,21 +877,21 @@ function we(e, a, l, s) {
877
877
  }
878
878
  });
879
879
  };
880
- if (f === "$stream")
880
+ if (g === "$stream")
881
881
  return function(r = {}) {
882
882
  const {
883
883
  bufferSize: n = 100,
884
884
  flushInterval: i = 100,
885
- bufferStrategy: S = "accumulate",
885
+ bufferStrategy: f = "accumulate",
886
886
  store: d,
887
- onFlush: h
887
+ onFlush: m
888
888
  } = r;
889
- let w = [], M = !1, E = null;
890
- const b = (T) => {
889
+ let w = [], M = !1, A = null;
890
+ const I = (T) => {
891
891
  if (!M) {
892
- if (S === "sliding" && w.length >= n)
892
+ if (f === "sliding" && w.length >= n)
893
893
  w.shift();
894
- else if (S === "dropping" && w.length >= n)
894
+ else if (f === "dropping" && w.length >= n)
895
895
  return;
896
896
  w.push(T), w.length >= n && k();
897
897
  }
@@ -899,28 +899,28 @@ function we(e, a, l, s) {
899
899
  if (w.length === 0) return;
900
900
  const T = [...w];
901
901
  if (w = [], d) {
902
- const U = d(T);
903
- U !== void 0 && (Array.isArray(U) ? U : [U]).forEach((pe) => {
902
+ const j = d(T);
903
+ j !== void 0 && (Array.isArray(j) ? j : [j]).forEach((pe) => {
904
904
  a(pe, t, {
905
905
  updateType: "insert"
906
906
  });
907
907
  });
908
908
  } else
909
- T.forEach((U) => {
910
- a(U, t, {
909
+ T.forEach((j) => {
910
+ a(j, t, {
911
911
  updateType: "insert"
912
912
  });
913
913
  });
914
- h?.(T);
914
+ m?.(T);
915
915
  };
916
- i > 0 && (E = setInterval(k, i));
917
- const O = X(), _ = A(e, t) || {}, z = _.streams || /* @__PURE__ */ new Map();
918
- return z.set(O, { buffer: w, flushTimer: E }), L(e, t, {
916
+ i > 0 && (A = setInterval(k, i));
917
+ const O = X(), _ = E(e, t) || {}, z = _.streams || /* @__PURE__ */ new Map();
918
+ return z.set(O, { buffer: w, flushTimer: A }), B(e, t, {
919
919
  ..._,
920
920
  streams: z
921
921
  }), {
922
- write: (T) => b(T),
923
- writeMany: (T) => T.forEach(b),
922
+ write: (T) => I(T),
923
+ writeMany: (T) => T.forEach(I),
924
924
  flush: () => k(),
925
925
  pause: () => {
926
926
  M = !0;
@@ -929,88 +929,88 @@ function we(e, a, l, s) {
929
929
  M = !1, w.length > 0 && k();
930
930
  },
931
931
  close: () => {
932
- k(), E && clearInterval(E);
932
+ k(), A && clearInterval(A);
933
933
  const T = p.getState().getShadowMetadata(e, t);
934
934
  T?.streams && T.streams.delete(O);
935
935
  }
936
936
  };
937
937
  };
938
- if (f === "$list")
939
- return (r) => /* @__PURE__ */ Z(() => {
940
- const i = x(/* @__PURE__ */ new Map()), [S, d] = ee({}), h = t.length > 0 ? t.join(".") : "root", w = st(e, t, o), M = ye(() => ({
938
+ if (g === "$list")
939
+ return (r) => /* @__PURE__ */ Q(() => {
940
+ const i = x(/* @__PURE__ */ new Map()), [f, d] = ee({}), m = t.length > 0 ? t.join(".") : "root", w = st(e, t, o), M = ye(() => ({
941
941
  ...o,
942
942
  arrayViews: {
943
943
  ...o?.arrayViews || {},
944
- [h]: w
944
+ [m]: w
945
945
  }
946
- }), [o, h, w]), { value: E } = j(
946
+ }), [o, m, w]), { value: A } = U(
947
947
  e,
948
948
  t,
949
949
  M
950
950
  );
951
951
  if (J(() => {
952
- const O = p.getState().subscribeToPath(I, (_) => {
952
+ const O = p.getState().subscribeToPath(b, (_) => {
953
953
  if (_.type === "GET_SELECTED")
954
954
  return;
955
955
  const T = p.getState().getShadowMetadata(e, t)?.transformCaches;
956
956
  if (T)
957
- for (const U of T.keys())
958
- U.startsWith(y) && T.delete(U);
957
+ for (const j of T.keys())
958
+ j.startsWith(y) && T.delete(j);
959
959
  (_.type === "INSERT" || _.type === "INSERT_MANY" || _.type === "REMOVE" || _.type === "CLEAR_SELECTION" || _.type === "SERVER_STATE_UPDATE" && !o?.serverStateIsUpStream) && d({});
960
960
  });
961
961
  return () => {
962
962
  O();
963
963
  };
964
- }, [y, I]), !Array.isArray(E))
964
+ }, [y, b]), !Array.isArray(A))
965
965
  return null;
966
- const b = c({
966
+ const I = c({
967
967
  path: t,
968
968
  componentId: y,
969
969
  meta: M
970
970
  // Use updated meta here
971
- }), k = E.map((O, _) => {
971
+ }), k = A.map((O, _) => {
972
972
  const z = w[_];
973
973
  if (!z)
974
974
  return null;
975
975
  let T = i.current.get(z);
976
976
  T || (T = X(), i.current.set(z, T));
977
- const U = [...t, z];
977
+ const j = [...t, z];
978
978
  return ue(De, {
979
979
  key: z,
980
980
  stateKey: e,
981
981
  itemComponentId: T,
982
- itemPath: U,
982
+ itemPath: j,
983
983
  localIndex: _,
984
- arraySetter: b,
984
+ arraySetter: I,
985
985
  rebuildStateShape: c,
986
986
  renderFn: r
987
987
  });
988
988
  });
989
- return /* @__PURE__ */ Z(Me, { children: k });
989
+ return /* @__PURE__ */ Q(Me, { children: k });
990
990
  }, {});
991
- if (f === "$stateFlattenOn")
991
+ if (g === "$stateFlattenOn")
992
992
  return (r) => {
993
- const n = t.length > 0 ? t.join(".") : "root", i = o?.arrayViews?.[n], S = p.getState().getShadowValue(e, t, i);
994
- return Array.isArray(S) ? c({
993
+ const n = t.length > 0 ? t.join(".") : "root", i = o?.arrayViews?.[n], f = p.getState().getShadowValue(e, t, i);
994
+ return Array.isArray(f) ? c({
995
995
  path: [...t, "[*]", r],
996
996
  componentId: y,
997
997
  meta: o
998
998
  }) : [];
999
999
  };
1000
- if (f === "$index")
1000
+ if (g === "$index")
1001
1001
  return (r) => {
1002
1002
  const n = t.length > 0 ? t.join(".") : "root", i = o?.arrayViews?.[n];
1003
1003
  if (i) {
1004
- const h = i[r];
1005
- return h ? c({
1006
- path: [...t, h],
1004
+ const m = i[r];
1005
+ return m ? c({
1006
+ path: [...t, m],
1007
1007
  componentId: y,
1008
1008
  meta: o
1009
1009
  }) : void 0;
1010
1010
  }
1011
- const S = A(e, t);
1012
- if (!S?.arrayKeys) return;
1013
- const d = S.arrayKeys[r];
1011
+ const f = E(e, t);
1012
+ if (!f?.arrayKeys) return;
1013
+ const d = f.arrayKeys[r];
1014
1014
  if (d)
1015
1015
  return c({
1016
1016
  path: [...t, d],
@@ -1018,9 +1018,9 @@ function we(e, a, l, s) {
1018
1018
  meta: o
1019
1019
  });
1020
1020
  };
1021
- if (f === "$last")
1021
+ if (g === "$last")
1022
1022
  return () => {
1023
- const { keys: r } = j(e, t, o);
1023
+ const { keys: r } = U(e, t, o);
1024
1024
  if (!r || r.length === 0)
1025
1025
  return;
1026
1026
  const n = r[r.length - 1];
@@ -1033,187 +1033,213 @@ function we(e, a, l, s) {
1033
1033
  meta: o
1034
1034
  });
1035
1035
  };
1036
- if (f === "$insert")
1036
+ if (g === "$insert")
1037
1037
  return (r, n) => {
1038
1038
  a(r, t, {
1039
1039
  updateType: "insert",
1040
1040
  index: n
1041
1041
  });
1042
1042
  };
1043
- if (f === "$insertMany")
1043
+ if (g === "$insertMany")
1044
1044
  return (r) => {
1045
1045
  a(r, t, {
1046
1046
  updateType: "insert_many"
1047
1047
  });
1048
1048
  };
1049
- if (f === "$uniqueInsert")
1049
+ if (g === "$uniqueInsert")
1050
1050
  return (r, n, i) => {
1051
- const { value: S } = W(
1051
+ const { value: f } = W(
1052
1052
  e,
1053
1053
  t,
1054
1054
  o
1055
- ), d = R(r) ? r(S) : r;
1056
- let h = null;
1057
- if (!S.some((M) => {
1058
- const E = n ? n.every(
1059
- (b) => Y(M[b], d[b])
1060
- ) : Y(M, d);
1061
- return E && (h = M), E;
1055
+ ), d = R(r) ? r(f) : r;
1056
+ let m = null;
1057
+ if (!f.some((M) => {
1058
+ const A = n ? n.every(
1059
+ (I) => Z(M[I], d[I])
1060
+ ) : Z(M, d);
1061
+ return A && (m = M), A;
1062
1062
  }))
1063
1063
  a(d, t, { updateType: "insert" });
1064
- else if (i && h) {
1065
- const M = i(h), E = S.map(
1066
- (b) => Y(b, h) ? M : b
1064
+ else if (i && m) {
1065
+ const M = i(m), A = f.map(
1066
+ (I) => Z(I, m) ? M : I
1067
1067
  );
1068
- a(E, t, {
1068
+ a(A, t, {
1069
1069
  updateType: "update"
1070
1070
  });
1071
1071
  }
1072
1072
  };
1073
- if (f === "$cut")
1073
+ if (g === "$cut")
1074
1074
  return (r, n) => {
1075
- const i = A(e, t);
1075
+ const i = E(e, t);
1076
1076
  if (!i?.arrayKeys || i.arrayKeys.length === 0)
1077
1077
  return;
1078
- const S = r === -1 ? i.arrayKeys.length - 1 : r !== void 0 ? r : i.arrayKeys.length - 1, d = i.arrayKeys[S];
1078
+ const f = r === -1 ? i.arrayKeys.length - 1 : r !== void 0 ? r : i.arrayKeys.length - 1, d = i.arrayKeys[f];
1079
1079
  d && a(null, [...t, d], {
1080
1080
  updateType: "cut"
1081
1081
  });
1082
1082
  };
1083
- if (f === "$cutSelected")
1083
+ if (g === "$cutSelected")
1084
1084
  return () => {
1085
- const r = [e, ...t].join("."), { keys: n } = j(e, t, o);
1085
+ const r = [e, ...t].join("."), { keys: n } = U(e, t, o);
1086
1086
  if (!n || n.length === 0)
1087
1087
  return;
1088
1088
  const i = p.getState().selectedIndicesMap.get(r);
1089
1089
  if (!i)
1090
1090
  return;
1091
- const S = i.split(".").pop();
1092
- if (!n.includes(S))
1091
+ const f = i.split(".").pop();
1092
+ if (!n.includes(f))
1093
1093
  return;
1094
1094
  const d = i.split(".").slice(1);
1095
1095
  p.getState().clearSelectedIndex({ arrayKey: r });
1096
- const h = d.slice(0, -1);
1097
- Q(e, h), a(null, d, {
1096
+ const m = d.slice(0, -1);
1097
+ Y(e, m), a(null, d, {
1098
1098
  updateType: "cut"
1099
1099
  });
1100
1100
  };
1101
- if (f === "$cutByValue")
1101
+ if (g === "$cutByValue")
1102
1102
  return (r) => {
1103
1103
  const {
1104
1104
  isArray: n,
1105
1105
  value: i,
1106
- keys: S
1107
- } = j(e, t, o);
1106
+ keys: f
1107
+ } = U(e, t, o);
1108
1108
  if (!n) return;
1109
- const d = oe(i, S, (h) => h === r);
1109
+ const d = oe(i, f, (m) => m === r);
1110
1110
  d && a(null, [...t, d.key], {
1111
1111
  updateType: "cut"
1112
1112
  });
1113
1113
  };
1114
- if (f === "$toggleByValue")
1114
+ if (g === "$toggleByValue")
1115
1115
  return (r) => {
1116
1116
  const {
1117
1117
  isArray: n,
1118
1118
  value: i,
1119
- keys: S
1120
- } = j(e, t, o);
1119
+ keys: f
1120
+ } = U(e, t, o);
1121
1121
  if (!n) return;
1122
- const d = oe(i, S, (h) => h === r);
1122
+ const d = oe(i, f, (m) => m === r);
1123
1123
  if (d) {
1124
- const h = [...t, d.key];
1125
- a(null, h, {
1124
+ const m = [...t, d.key];
1125
+ a(null, m, {
1126
1126
  updateType: "cut"
1127
1127
  });
1128
1128
  } else
1129
1129
  a(r, t, { updateType: "insert" });
1130
1130
  };
1131
- if (f === "$findWith")
1131
+ if (g === "$findWith")
1132
1132
  return (r, n) => {
1133
- const { isArray: i, value: S, keys: d } = j(e, t, o);
1133
+ const { isArray: i, value: f, keys: d } = U(e, t, o);
1134
1134
  if (!i)
1135
1135
  throw new Error("findWith can only be used on arrays");
1136
- const h = oe(
1137
- S,
1136
+ const m = oe(
1137
+ f,
1138
1138
  d,
1139
1139
  (w) => w?.[r] === n
1140
1140
  );
1141
- return h ? c({
1142
- path: [...t, h.key],
1141
+ return m ? c({
1142
+ path: [...t, m.key],
1143
1143
  componentId: y,
1144
1144
  meta: o
1145
1145
  }) : null;
1146
1146
  };
1147
- if (f === "$cutThis") {
1147
+ if (g === "$cutThis") {
1148
1148
  const { value: r } = W(e, t, o), n = t.slice(0, -1);
1149
- return Q(e, n), () => {
1149
+ return Y(e, n), () => {
1150
1150
  a(r, t, { updateType: "cut" });
1151
1151
  };
1152
1152
  }
1153
- if (f === "$get")
1153
+ if (g === "$get")
1154
1154
  return () => {
1155
1155
  ie(e, y, t);
1156
1156
  const { value: r } = W(e, t, o);
1157
1157
  return r;
1158
1158
  };
1159
- if (f === "$$derive")
1159
+ if (g === "$$derive")
1160
1160
  return (r) => Se({
1161
1161
  _stateKey: e,
1162
1162
  _path: t,
1163
1163
  _effect: r.toString(),
1164
1164
  _meta: o
1165
1165
  });
1166
- if (f === "$$get")
1166
+ if (g === "$$get")
1167
1167
  return () => Se({ _stateKey: e, _path: t, _meta: o });
1168
- if (f === "$lastSynced") {
1168
+ if (g === "$lastSynced") {
1169
1169
  const r = `${e}:${t.join(".")}`;
1170
1170
  return We(r);
1171
1171
  }
1172
- if (f == "getLocalStorage")
1172
+ if (g == "getLocalStorage")
1173
1173
  return (r) => ae(s + "-" + e + "-" + r);
1174
- if (f === "$isSelected") {
1174
+ if (g === "$isSelected") {
1175
1175
  const r = t.slice(0, -1);
1176
- if (A(e, r)?.arrayKeys) {
1177
- const i = e + "." + r.join("."), S = p.getState().selectedIndicesMap.get(i), d = e + "." + t.join(".");
1178
- return S === d;
1176
+ if (E(e, r)?.arrayKeys) {
1177
+ const i = e + "." + r.join("."), f = p.getState().selectedIndicesMap.get(i), d = e + "." + t.join(".");
1178
+ return f === d;
1179
1179
  }
1180
1180
  return;
1181
1181
  }
1182
- if (f === "$setSelected")
1182
+ if (g === "$setSelected")
1183
1183
  return (r) => {
1184
- const n = t.slice(0, -1), i = e + "." + n.join("."), S = e + "." + t.join(".");
1185
- Q(e, n, void 0), p.getState().selectedIndicesMap.get(i), r && p.getState().setSelectedIndex(i, S);
1184
+ const n = t.slice(0, -1), i = e + "." + n.join("."), f = e + "." + t.join(".");
1185
+ Y(e, n, void 0), p.getState().selectedIndicesMap.get(i), r && p.getState().setSelectedIndex(i, f);
1186
1186
  };
1187
- if (f === "$toggleSelected")
1187
+ if (g === "$toggleSelected")
1188
1188
  return () => {
1189
1189
  const r = t.slice(0, -1), n = e + "." + r.join("."), i = e + "." + t.join(".");
1190
- p.getState().selectedIndicesMap.get(n) === i ? p.getState().clearSelectedIndex({ arrayKey: n }) : p.getState().setSelectedIndex(n, i), Q(e, r);
1190
+ p.getState().selectedIndicesMap.get(n) === i ? p.getState().clearSelectedIndex({ arrayKey: n }) : p.getState().setSelectedIndex(n, i), Y(e, r);
1191
+ };
1192
+ if (g === "$clearValidation")
1193
+ return (r) => {
1194
+ const n = r ? [...t, ...r] : t, i = p.getState(), f = i.getShadowNode(e, n);
1195
+ if (console.log("startNode ", f), !f) return;
1196
+ const d = [[f, n]];
1197
+ for (console.log("stack ", d); d.length > 0; ) {
1198
+ const [m, w] = d.pop();
1199
+ if (console.log("while (stack.length ", m, w), !m || typeof m != "object") continue;
1200
+ if (m._meta?.validation) {
1201
+ m._meta.validation = {
1202
+ status: "NOT_VALIDATED",
1203
+ errors: [],
1204
+ lastValidated: Date.now(),
1205
+ validatedValue: void 0
1206
+ };
1207
+ const A = [e, ...w].join(".");
1208
+ i.notifyPathSubscribers(A, {
1209
+ type: "VALIDATION_CLEAR"
1210
+ });
1211
+ }
1212
+ const M = Object.keys(m);
1213
+ for (const A of M)
1214
+ A !== "_meta" && d.push([m[A], [...w, A]]);
1215
+ }
1216
+ L(e);
1191
1217
  };
1192
- if (f === "$_componentId")
1193
- return y;
1194
1218
  if (t.length == 0) {
1195
- if (f === "$setOptions")
1219
+ if (g === "$_componentId")
1220
+ return y;
1221
+ if (g === "$setOptions")
1196
1222
  return (r) => {
1197
1223
  ce({ stateKey: e, options: r, initialOptionsPart: {} });
1198
1224
  };
1199
- if (f === "$_applyUpdate")
1225
+ if (g === "$_applyUpdate")
1200
1226
  return (r, n, i = "update") => {
1201
1227
  a(r, n, { updateType: i });
1202
1228
  };
1203
- if (f === "$_getEffectiveSetState")
1229
+ if (g === "$_getEffectiveSetState")
1204
1230
  return a;
1205
- if (f === "$getPluginMetaData")
1231
+ if (g === "$getPluginMetaData")
1206
1232
  return (r) => Ge(e, t)?.get(r);
1207
- if (f === "$addPluginMetaData")
1233
+ if (g === "$addPluginMetaData")
1208
1234
  return (r, n) => qe(e, t, r, n);
1209
- if (f === "$removePluginMetaData")
1235
+ if (g === "$removePluginMetaData")
1210
1236
  return (r) => xe(e, t, r);
1211
- if (f === "$addZodValidation")
1237
+ if (g === "$addZodValidation")
1212
1238
  return (r, n) => {
1213
1239
  r.forEach((i) => {
1214
- const S = p.getState().getShadowMetadata(e, i.path) || {};
1240
+ const f = p.getState().getShadowMetadata(e, i.path) || {};
1215
1241
  p.getState().setShadowMetadata(e, i.path, {
1216
- ...S,
1242
+ ...f,
1217
1243
  validation: {
1218
1244
  status: "INVALID",
1219
1245
  errors: [
@@ -1230,27 +1256,13 @@ function we(e, a, l, s) {
1230
1256
  });
1231
1257
  });
1232
1258
  };
1233
- if (f === "$clearZodValidation")
1234
- return (r) => {
1235
- if (!r)
1236
- throw new Error("clearZodValidation requires a path");
1237
- const n = A(e, r) || {};
1238
- L(e, r, {
1239
- ...n,
1240
- validation: {
1241
- status: "NOT_VALIDATED",
1242
- errors: [],
1243
- lastValidated: Date.now()
1244
- }
1245
- });
1246
- };
1247
- if (f === "$applyOperation")
1259
+ if (g === "$applyOperation")
1248
1260
  return (r, n) => {
1249
1261
  let i;
1250
1262
  if (r.insertAfterId && r.updateType === "insert") {
1251
- const S = A(e, r.path);
1252
- if (S?.arrayKeys) {
1253
- const d = S.arrayKeys.indexOf(
1263
+ const f = E(e, r.path);
1264
+ if (f?.arrayKeys) {
1265
+ const d = f.arrayKeys.indexOf(
1254
1266
  r.insertAfterId
1255
1267
  );
1256
1268
  d !== -1 && (i = d + 1);
@@ -1264,65 +1276,65 @@ function we(e, a, l, s) {
1264
1276
  metaData: n
1265
1277
  });
1266
1278
  };
1267
- if (f === "$applyJsonPatch")
1279
+ if (g === "$applyJsonPatch")
1268
1280
  return (r) => {
1269
1281
  const n = p.getState(), i = n.getShadowMetadata(e, []);
1270
1282
  if (!i?.components) return;
1271
- const S = (h) => !h || h === "/" ? [] : h.split("/").slice(1).map((w) => w.replace(/~1/g, "/").replace(/~0/g, "~")), d = /* @__PURE__ */ new Set();
1272
- for (const h of r) {
1273
- const w = S(h.path);
1274
- switch (h.op) {
1283
+ const f = (m) => !m || m === "/" ? [] : m.split("/").slice(1).map((w) => w.replace(/~1/g, "/").replace(/~0/g, "~")), d = /* @__PURE__ */ new Set();
1284
+ for (const m of r) {
1285
+ const w = f(m.path);
1286
+ switch (m.op) {
1275
1287
  case "add":
1276
1288
  case "replace": {
1277
- const { value: M } = h;
1289
+ const { value: M } = m;
1278
1290
  n.updateShadowAtPath(e, w, M), n.markAsDirty(e, w, { bubble: !0 });
1279
- let E = [...w];
1291
+ let A = [...w];
1280
1292
  for (; ; ) {
1281
- const b = n.getShadowMetadata(
1293
+ const I = n.getShadowMetadata(
1282
1294
  e,
1283
- E
1295
+ A
1284
1296
  );
1285
- if (b?.pathComponents && b.pathComponents.forEach((k) => {
1297
+ if (I?.pathComponents && I.pathComponents.forEach((k) => {
1286
1298
  if (!d.has(k)) {
1287
1299
  const O = i.components?.get(k);
1288
1300
  O && (O.forceUpdate(), d.add(k));
1289
1301
  }
1290
- }), E.length === 0) break;
1291
- E.pop();
1302
+ }), A.length === 0) break;
1303
+ A.pop();
1292
1304
  }
1293
1305
  break;
1294
1306
  }
1295
1307
  case "remove": {
1296
1308
  const M = w.slice(0, -1);
1297
1309
  n.removeShadowArrayElement(e, w), n.markAsDirty(e, M, { bubble: !0 });
1298
- let E = [...M];
1310
+ let A = [...M];
1299
1311
  for (; ; ) {
1300
- const b = n.getShadowMetadata(
1312
+ const I = n.getShadowMetadata(
1301
1313
  e,
1302
- E
1314
+ A
1303
1315
  );
1304
- if (b?.pathComponents && b.pathComponents.forEach((k) => {
1316
+ if (I?.pathComponents && I.pathComponents.forEach((k) => {
1305
1317
  if (!d.has(k)) {
1306
1318
  const O = i.components?.get(k);
1307
1319
  O && (O.forceUpdate(), d.add(k));
1308
1320
  }
1309
- }), E.length === 0) break;
1310
- E.pop();
1321
+ }), A.length === 0) break;
1322
+ A.pop();
1311
1323
  }
1312
1324
  break;
1313
1325
  }
1314
1326
  }
1315
1327
  }
1316
1328
  };
1317
- if (f === "$getComponents")
1318
- return () => A(e, [])?.components;
1329
+ if (g === "$getComponents")
1330
+ return () => E(e, [])?.components;
1319
1331
  }
1320
- if (f === "$validationWrapper")
1332
+ if (g === "$validationWrapper")
1321
1333
  return ({
1322
1334
  children: r,
1323
1335
  hideMessage: n
1324
- }) => /* @__PURE__ */ Z(
1325
- be,
1336
+ }) => /* @__PURE__ */ Q(
1337
+ Ie,
1326
1338
  {
1327
1339
  formOpts: n ? { validation: { message: "" } } : void 0,
1328
1340
  path: t,
@@ -1330,13 +1342,13 @@ function we(e, a, l, s) {
1330
1342
  children: r
1331
1343
  }
1332
1344
  );
1333
- if (f === "$_stateKey") return e;
1334
- if (f === "$_path") return t;
1335
- if (f === "$update")
1345
+ if (g === "$_stateKey") return e;
1346
+ if (g === "$_path") return t;
1347
+ if (g === "$update")
1336
1348
  return (r) => (a(r, t, { updateType: "update" }), {
1337
1349
  synced: () => {
1338
1350
  const n = p.getState().getShadowMetadata(e, t);
1339
- L(e, t, {
1351
+ B(e, t, {
1340
1352
  ...n,
1341
1353
  isDirty: !1,
1342
1354
  stateSource: "server",
@@ -1349,7 +1361,7 @@ function we(e, a, l, s) {
1349
1361
  });
1350
1362
  }
1351
1363
  });
1352
- if (f === "$toggle") {
1364
+ if (g === "$toggle") {
1353
1365
  const { value: r } = W(
1354
1366
  e,
1355
1367
  t,
@@ -1363,26 +1375,26 @@ function we(e, a, l, s) {
1363
1375
  });
1364
1376
  };
1365
1377
  }
1366
- if (f === "$isolate")
1378
+ if (g === "$isolate")
1367
1379
  return (r, n) => {
1368
- const i = Array.isArray(r), S = i ? r : void 0, d = i ? n : r;
1380
+ const i = Array.isArray(r), f = i ? r : void 0, d = i ? n : r;
1369
1381
  if (!d || typeof d != "function")
1370
1382
  throw new Error(
1371
1383
  "CogsState: $isolate requires a render function."
1372
1384
  );
1373
- return /* @__PURE__ */ Z(
1385
+ return /* @__PURE__ */ Q(
1374
1386
  Pe,
1375
1387
  {
1376
1388
  stateKey: e,
1377
1389
  path: t,
1378
- dependencies: S,
1390
+ dependencies: f,
1379
1391
  rebuildStateShape: c,
1380
1392
  renderFn: d
1381
1393
  }
1382
1394
  );
1383
1395
  };
1384
- if (f === "$formElement")
1385
- return (r, n) => /* @__PURE__ */ Z(
1396
+ if (g === "$formElement")
1397
+ return (r, n) => /* @__PURE__ */ Q(
1386
1398
  ke,
1387
1399
  {
1388
1400
  stateKey: e,
@@ -1393,7 +1405,7 @@ function we(e, a, l, s) {
1393
1405
  renderFn: r
1394
1406
  }
1395
1407
  );
1396
- const P = [...t, f];
1408
+ const P = [...t, g];
1397
1409
  return c({
1398
1410
  path: P,
1399
1411
  componentId: y,
@@ -1401,9 +1413,9 @@ function we(e, a, l, s) {
1401
1413
  });
1402
1414
  }
1403
1415
  }, C = new Proxy(v, F);
1404
- return g.set(V, C), C;
1416
+ return S.set(V, C), C;
1405
1417
  }
1406
- const m = {
1418
+ const h = {
1407
1419
  $revertToInitialState: (t) => {
1408
1420
  const o = p.getState().getShadowMetadata(e, []);
1409
1421
  let y;
@@ -1411,11 +1423,11 @@ function we(e, a, l, s) {
1411
1423
  path: [],
1412
1424
  componentId: l
1413
1425
  });
1414
- const $ = N(e), V = R($?.localStorage?.key) ? $?.localStorage?.key(y) : $?.localStorage?.key, I = `${s}-${e}-${V}`;
1415
- return I && localStorage.removeItem(I), B(e), y;
1426
+ const $ = N(e), V = R($?.localStorage?.key) ? $?.localStorage?.key(y) : $?.localStorage?.key, b = `${s}-${e}-${V}`;
1427
+ return b && localStorage.removeItem(b), L(e), y;
1416
1428
  },
1417
1429
  $initializeAndMergeShadowState: (t) => {
1418
- Oe(e, t), B(e);
1430
+ Oe(e, t), L(e);
1419
1431
  },
1420
1432
  $updateInitialState: (t) => {
1421
1433
  const o = we(
@@ -1423,8 +1435,8 @@ function we(e, a, l, s) {
1423
1435
  a,
1424
1436
  l,
1425
1437
  s
1426
- ), y = p.getState().initialStateGlobal[e], $ = N(e), V = R($?.localStorage?.key) ? $?.localStorage?.key(y) : $?.localStorage?.key, I = `${s}-${e}-${V}`;
1427
- return localStorage.getItem(I) && localStorage.removeItem(I), Ee(() => {
1438
+ ), y = p.getState().initialStateGlobal[e], $ = N(e), V = R($?.localStorage?.key) ? $?.localStorage?.key(y) : $?.localStorage?.key, b = `${s}-${e}-${V}`;
1439
+ return localStorage.getItem(b) && localStorage.removeItem(b), Ee(() => {
1428
1440
  he(e, t), K(e, t);
1429
1441
  const v = p.getState().getShadowMetadata(e, []);
1430
1442
  v && v?.components?.forEach((F) => {
@@ -1446,22 +1458,22 @@ function Se(e) {
1446
1458
  function it({
1447
1459
  proxy: e
1448
1460
  }) {
1449
- const a = x(null), l = x(null), s = x(!1), g = `${e._stateKey}-${e._path.join(".")}`, c = e._path.length > 0 ? e._path.join(".") : "root", m = e._meta?.arrayViews?.[c], u = D(e._stateKey, e._path, m);
1461
+ const a = x(null), l = x(null), s = x(!1), S = `${e._stateKey}-${e._path.join(".")}`, c = e._path.length > 0 ? e._path.join(".") : "root", h = e._meta?.arrayViews?.[c], u = D(e._stateKey, e._path, h);
1450
1462
  return J(() => {
1451
1463
  const t = a.current;
1452
1464
  if (!t || s.current) return;
1453
1465
  const o = setTimeout(() => {
1454
1466
  if (!t.parentElement) {
1455
- console.warn("Parent element not found for signal", g);
1467
+ console.warn("Parent element not found for signal", S);
1456
1468
  return;
1457
1469
  }
1458
1470
  const y = t.parentElement, V = Array.from(y.childNodes).indexOf(t);
1459
- let I = y.getAttribute("data-parent-id");
1460
- I || (I = `parent-${crypto.randomUUID()}`, y.setAttribute("data-parent-id", I)), l.current = `instance-${crypto.randomUUID()}`;
1471
+ let b = y.getAttribute("data-parent-id");
1472
+ b || (b = `parent-${crypto.randomUUID()}`, y.setAttribute("data-parent-id", b)), l.current = `instance-${crypto.randomUUID()}`;
1461
1473
  const v = p.getState().getShadowMetadata(e._stateKey, e._path) || {}, F = v.signals || [];
1462
1474
  F.push({
1463
1475
  instanceId: l.current,
1464
- parentId: I,
1476
+ parentId: b,
1465
1477
  position: V,
1466
1478
  effect: e._effect
1467
1479
  }), p.getState().setShadowMetadata(e._stateKey, e._path, {
@@ -1475,8 +1487,8 @@ function it({
1475
1487
  "state",
1476
1488
  `return (${e._effect})(state)`
1477
1489
  )(u);
1478
- } catch (f) {
1479
- console.error("Error evaluating effect function:", f);
1490
+ } catch (g) {
1491
+ console.error("Error evaluating effect function:", g);
1480
1492
  }
1481
1493
  C !== null && typeof C == "object" && (C = JSON.stringify(C));
1482
1494
  const G = document.createTextNode(String(C ?? ""));
@@ -1493,7 +1505,7 @@ function it({
1493
1505
  }, []), ue("span", {
1494
1506
  ref: a,
1495
1507
  style: { display: "contents" },
1496
- "data-signal-id": g
1508
+ "data-signal-id": S
1497
1509
  });
1498
1510
  }
1499
1511
  export {