cogsbox-state 0.5.463 → 0.5.465

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/store.js CHANGED
@@ -1,353 +1,317 @@
1
- import { create as M } from "zustand";
2
- import { ulid as b } from "ulid";
3
- import { startTransition as g } from "react";
4
- const j = M((f, c) => ({
1
+ import { create as h } from "zustand";
2
+ import { ulid as y } from "ulid";
3
+ const _ = h((d, r) => ({
5
4
  formRefs: /* @__PURE__ */ new Map(),
6
- registerFormRef: (e, s) => f((o) => {
7
- const t = new Map(o.formRefs);
8
- return t.set(e, s), { formRefs: t };
5
+ registerFormRef: (e, s) => d((n) => {
6
+ const o = new Map(n.formRefs);
7
+ return o.set(e, s), { formRefs: o };
9
8
  }),
10
- getFormRef: (e) => c().formRefs.get(e),
11
- removeFormRef: (e) => f((s) => {
12
- const o = new Map(s.formRefs);
13
- return o.delete(e), { formRefs: o };
9
+ getFormRef: (e) => r().formRefs.get(e),
10
+ removeFormRef: (e) => d((s) => {
11
+ const n = new Map(s.formRefs);
12
+ return n.delete(e), { formRefs: n };
14
13
  }),
15
14
  // Get all refs that start with the stateKey prefix
16
15
  getFormRefsByStateKey: (e) => {
17
- const s = c().formRefs, o = e + ".", t = /* @__PURE__ */ new Map();
18
- return s.forEach((n, a) => {
19
- (a.startsWith(o) || a === e) && t.set(a, n);
20
- }), t;
16
+ const s = r().formRefs, n = e + ".", o = /* @__PURE__ */ new Map();
17
+ return s.forEach((t, a) => {
18
+ (a.startsWith(n) || a === e) && o.set(a, t);
19
+ }), o;
21
20
  }
22
- })), m = (f) => f === null || typeof f != "object" ? !1 : !!(Array.isArray(f) || f.constructor === Object), E = M((f, c) => ({
23
- updateQueue: /* @__PURE__ */ new Set(),
24
- // A flag to ensure we only schedule the flush once per event-loop tick.
25
- isFlushScheduled: !1,
26
- // This function is called by queueMicrotask to execute all queued updates.
27
- flushUpdates: () => {
28
- const { updateQueue: e } = c();
29
- e.size > 0 && g(() => {
30
- e.forEach((s) => s());
31
- }), f({ updateQueue: /* @__PURE__ */ new Set(), isFlushScheduled: !1 });
21
+ })), g = /* @__PURE__ */ new Set(["_meta", "value"]);
22
+ function m(d) {
23
+ if (d === null || typeof d != "object")
24
+ return { value: d };
25
+ if (Array.isArray(d)) {
26
+ const r = { _meta: { arrayKeys: [] } }, e = [];
27
+ return d.forEach((s) => {
28
+ const n = `id:${y()}`;
29
+ r[n] = m(s), e.push(n);
30
+ }), r._meta.arrayKeys = e, r;
31
+ }
32
+ if (d.constructor === Object) {
33
+ const r = { _meta: {} };
34
+ for (const e in d)
35
+ Object.prototype.hasOwnProperty.call(d, e) && (r[e] = m(d[e]));
36
+ return r;
37
+ }
38
+ return { value: d };
39
+ }
40
+ const I = h((d, r) => ({
41
+ shadowStateStore: /* @__PURE__ */ new Map(),
42
+ setTransformCache: (e, s, n, o) => {
43
+ const t = r().getShadowMetadata(e, s) || {};
44
+ t.transformCaches || (t.transformCaches = /* @__PURE__ */ new Map()), t.transformCaches.set(n, o), r().setShadowMetadata(e, s, {
45
+ transformCaches: t.transformCaches
46
+ });
32
47
  },
33
- addPathComponent: (e, s, o) => {
34
- f((t) => {
35
- const n = new Map(t.shadowStateStore), a = [e, ...s].join("."), r = n.get(a) || {}, S = new Set(r.pathComponents);
36
- S.add(o), n.set(a, { ...r, pathComponents: S });
37
- const i = n.get(e) || {}, p = i.components?.get(o);
38
- if (p) {
39
- const d = new Set(p.paths);
40
- d.add(a);
41
- const h = { ...p, paths: d }, l = new Map(i.components);
42
- l.set(o, h), n.set(e, {
43
- ...i,
44
- components: l
45
- });
48
+ initializeShadowState: (e, s) => {
49
+ d((n) => {
50
+ const o = new Map(n.shadowStateStore), t = o.get(e) || o.get(`[${e}`);
51
+ let a = {};
52
+ if (t?._meta) {
53
+ const {
54
+ components: i,
55
+ features: f,
56
+ lastServerSync: S,
57
+ stateSource: u,
58
+ baseServerState: l
59
+ } = t._meta;
60
+ i && (a.components = i), f && (a.features = f), S && (a.lastServerSync = S), u && (a.stateSource = u), l && (a.baseServerState = l);
46
61
  }
47
- return { shadowStateStore: n };
62
+ o.delete(e), o.delete(`[${e}`);
63
+ const c = m(s);
64
+ c._meta || (c._meta = {}), Object.assign(c._meta, a);
65
+ const p = Array.isArray(s) ? `[${e}` : e;
66
+ return o.set(p, c), { shadowStateStore: o };
48
67
  });
49
68
  },
50
- registerComponent: (e, s, o) => {
51
- f((t) => {
52
- const n = new Map(t.shadowStateStore), a = n.get(e) || {}, r = new Map(a.components);
53
- return r.set(s, o), n.set(e, { ...a, components: r }), { shadowStateStore: n };
69
+ // ✅ NEW HELPER: Gets the entire node (data and metadata).
70
+ getShadowNode: (e, s) => {
71
+ const n = r().shadowStateStore;
72
+ let o = n.get(e) || n.get(`[${e}`);
73
+ if (o) {
74
+ if (s.length === 0) return o;
75
+ for (const t of s)
76
+ if (typeof o != "object" || o === null || (o = o[t], o === void 0)) return;
77
+ return o;
78
+ }
79
+ },
80
+ // ✅ REFACTORED: Returns only the `_meta` part of a node.
81
+ getShadowMetadata: (e, s) => r().getShadowNode(e, s)?._meta,
82
+ // ✅ REFACTORED: Sets data within the `_meta` object.
83
+ setShadowMetadata: (e, s, n) => {
84
+ d((o) => {
85
+ const t = new Map(o.shadowStateStore), a = t.has(`[${e}`) ? `[${e}` : e;
86
+ let c = t.get(a);
87
+ c || (c = {}, t.set(a, c));
88
+ const p = { ...c };
89
+ t.set(a, p);
90
+ let i = p;
91
+ for (const f of s) {
92
+ const S = i[f] || {};
93
+ i[f] = { ...S }, i = i[f];
94
+ }
95
+ return i._meta = { ...i._meta || {}, ...n }, { shadowStateStore: t };
54
96
  });
55
97
  },
56
- unregisterComponent: (e, s) => {
57
- f((o) => {
58
- const t = new Map(o.shadowStateStore), n = t.get(e);
59
- if (!n?.components)
60
- return o;
61
- const a = new Map(n.components);
62
- return a.delete(s) ? (t.set(e, { ...n, components: a }), { shadowStateStore: t }) : o;
98
+ getShadowValue: (e, s, n, o) => {
99
+ const t = r().getShadowNode(e, s);
100
+ if (t == null) return;
101
+ const a = Object.keys(t);
102
+ if (Object.prototype.hasOwnProperty.call(t, "value") && a.every((f) => f === "value" || f === "_meta"))
103
+ return t.value;
104
+ if (t._meta && Object.prototype.hasOwnProperty.call(t._meta, "arrayKeys"))
105
+ return (n !== void 0 && n.length > 0 ? n : t._meta.arrayKeys).map(
106
+ (S) => r().getShadowValue(e, [...s, S])
107
+ );
108
+ const i = {};
109
+ for (const f of a)
110
+ f !== "_meta" && !f.startsWith("id:") && (i[f] = r().getShadowValue(e, [...s, f]));
111
+ return i;
112
+ },
113
+ // ✅ REFACTORED: Correctly preserves `_meta` on updates.
114
+ updateShadowAtPath: (e, s, n) => {
115
+ d((o) => {
116
+ const t = new Map(o.shadowStateStore), a = t.has(`[${e}`) ? `[${e}` : e;
117
+ let c = t.get(a);
118
+ if (!c) return o;
119
+ const p = { ...c };
120
+ if (t.set(a, p), s.length === 0) {
121
+ const i = m(n);
122
+ p._meta && (i._meta = {
123
+ ...i._meta || {},
124
+ ...p._meta
125
+ }), t.set(a, i);
126
+ } else {
127
+ let i = p;
128
+ const f = s.slice(0, -1);
129
+ for (const w of f)
130
+ i[w] = { ...i[w] }, i = i[w];
131
+ const S = s[s.length - 1], u = i[S] || {}, l = m(n);
132
+ u._meta && (l._meta = {
133
+ ...l._meta || {},
134
+ ...u._meta
135
+ }), i[S] = l;
136
+ }
137
+ return r().notifyPathSubscribers([e, ...s].join("."), {
138
+ type: "UPDATE",
139
+ newValue: n
140
+ }), { shadowStateStore: t };
63
141
  });
64
142
  },
65
- markAsDirty: (e, s, o = { bubble: !0 }) => {
66
- const { shadowStateStore: t } = c(), n = /* @__PURE__ */ new Map(), a = (r) => {
67
- const S = [e, ...r].join("."), i = t.get(S) || {};
68
- return i.isDirty === !0 ? !0 : (n.set(S, { ...i, isDirty: !0 }), !1);
69
- };
70
- if (a(s), o.bubble) {
71
- let r = [...s];
72
- for (; r.length > 0 && (r.pop(), !a(r)); )
143
+ // REFACTORED: Works with `_meta.arrayKeys`.
144
+ insertShadowArrayElement: (e, s, n, o) => {
145
+ const t = r().getShadowNode(e, s);
146
+ if (!t?._meta?.arrayKeys) {
147
+ console.error(
148
+ `Array not found at path: ${[e, ...s].join(".")}`
149
+ );
150
+ return;
151
+ }
152
+ const a = `id:${y()}`, c = m(n), i = [...t._meta.arrayKeys];
153
+ o !== void 0 && o >= 0 && o <= i.length ? i.splice(o, 0, a) : i.push(a), t._meta.transformCaches && t._meta.transformCaches.forEach((S) => {
154
+ S.validIds && Array.isArray(S.validIds) && S.transforms.every(
155
+ (l) => l.type === "filter" ? l.fn(n) : !0
156
+ ) && (S.validIds = [...S.validIds], o !== void 0 ? S.validIds.splice(o, 0, a) : S.validIds.push(a));
157
+ }), t[a] = c, t._meta.arrayKeys = i, r().setShadowMetadata(e, s, { arrayKeys: i });
158
+ const f = [e, ...s].join(".");
159
+ r().notifyPathSubscribers(f, {
160
+ type: "INSERT",
161
+ path: f,
162
+ itemKey: `${f}.${a}`,
163
+ index: o ?? i.length - 1
164
+ });
165
+ },
166
+ // ✅ REFACTORED: Works with `_meta.arrayKeys`.
167
+ removeShadowArrayElement: (e, s) => {
168
+ if (s.length === 0) return;
169
+ const n = s.slice(0, -1), o = s[s.length - 1];
170
+ if (!o?.startsWith("id:")) return;
171
+ const t = r().getShadowNode(e, n);
172
+ if (!t?._meta?.arrayKeys) return;
173
+ const a = t._meta.arrayKeys.filter((p) => p !== o);
174
+ delete t[o], r().setShadowMetadata(e, n, { arrayKeys: a });
175
+ const c = [e, ...n].join(".");
176
+ r().notifyPathSubscribers(c, {
177
+ type: "REMOVE",
178
+ path: c,
179
+ itemKey: `${c}.${o}`
180
+ });
181
+ },
182
+ // The rest of the functions are updated to use the new helpers (`getShadowMetadata`, `setShadowMetadata`)
183
+ // which abstracts away the `_meta` implementation detail.
184
+ addPathComponent: (e, s, n) => {
185
+ const o = r().getShadowMetadata(e, s) || {}, t = new Set(o.pathComponents);
186
+ t.add(n), r().setShadowMetadata(e, s, {
187
+ pathComponents: t
188
+ });
189
+ const a = r().getShadowMetadata(e, []);
190
+ if (a?.components) {
191
+ const c = a.components.get(n);
192
+ if (c) {
193
+ const p = [e, ...s].join("."), i = new Set(c.paths);
194
+ i.add(p);
195
+ const f = { ...c, paths: i }, S = new Map(a.components);
196
+ S.set(n, f), r().setShadowMetadata(e, [], { components: S });
197
+ }
198
+ }
199
+ },
200
+ registerComponent: (e, s, n) => {
201
+ const o = r().getShadowMetadata(e, []) || {}, t = new Map(o.components);
202
+ t.set(s, n), r().setShadowMetadata(e, [], { components: t });
203
+ },
204
+ unregisterComponent: (e, s) => {
205
+ const n = r().getShadowMetadata(e, []);
206
+ if (!n?.components) return;
207
+ const o = new Map(n.components);
208
+ o.delete(s) && r().setShadowMetadata(e, [], { components: o });
209
+ },
210
+ // ✅ REFACTORED: `markAsDirty` now correctly writes to `_meta.isDirty`.
211
+ markAsDirty: (e, s, n = { bubble: !0 }) => {
212
+ const o = (t) => r().getShadowNode(e, t)?._meta?.isDirty ? !0 : (r().setShadowMetadata(e, t, { isDirty: !0 }), !1);
213
+ if (o(s), n.bubble) {
214
+ let t = [...s];
215
+ for (; t.length > 0 && (t.pop(), !o(t)); )
73
216
  ;
74
217
  }
75
- n.size > 0 && f((r) => (n.forEach((S, i) => {
76
- r.shadowStateStore.set(i, S);
77
- }), r));
78
218
  },
79
219
  serverStateUpdates: /* @__PURE__ */ new Map(),
80
220
  setServerStateUpdate: (e, s) => {
81
- f((o) => {
82
- const t = new Map(o.serverStateUpdates);
83
- return t.set(e, s), { serverStateUpdates: t };
84
- }), c().notifyPathSubscribers(e, {
221
+ d((n) => ({
222
+ serverStateUpdates: new Map(n.serverStateUpdates).set(
223
+ e,
224
+ s
225
+ )
226
+ })), r().notifyPathSubscribers(e, {
85
227
  type: "SERVER_STATE_UPDATE",
86
228
  serverState: s
87
229
  });
88
230
  },
89
- shadowStateStore: /* @__PURE__ */ new Map(),
90
- getShadowNode: (e) => c().shadowStateStore.get(e),
91
231
  pathSubscribers: /* @__PURE__ */ new Map(),
92
232
  subscribeToPath: (e, s) => {
93
- const o = c().pathSubscribers, t = o.get(e) || /* @__PURE__ */ new Set();
94
- return t.add(s), o.set(e, t), () => {
95
- const n = c().pathSubscribers.get(e);
96
- n && (n.delete(s), n.size === 0 && c().pathSubscribers.delete(e));
233
+ const n = r().pathSubscribers, o = n.get(e) || /* @__PURE__ */ new Set();
234
+ return o.add(s), n.set(e, o), () => {
235
+ const t = r().pathSubscribers.get(e);
236
+ t && (t.delete(s), t.size === 0 && r().pathSubscribers.delete(e));
97
237
  };
98
238
  },
99
239
  notifyPathSubscribers: (e, s) => {
100
- const t = c().pathSubscribers.get(e);
101
- t && t.forEach((n) => n(s));
102
- },
103
- initializeShadowState: (e, s) => {
104
- f((o) => {
105
- const t = new Map(o.shadowStateStore);
106
- console.log("initializeShadowState");
107
- const a = t.get(e)?.components, r = e + ".";
108
- for (const i of Array.from(t.keys()))
109
- (i === e || i.startsWith(r)) && t.delete(i);
110
- const S = (i, p) => {
111
- const d = [e, ...p].join(".");
112
- if (Array.isArray(i)) {
113
- const h = [];
114
- i.forEach(() => {
115
- const l = `id:${b()}`;
116
- h.push(d + "." + l);
117
- }), t.set(d, { arrayKeys: h }), i.forEach((l, u) => {
118
- const w = h[u].split(".").pop();
119
- S(l, [...p, w]);
120
- });
121
- } else if (m(i)) {
122
- const h = Object.fromEntries(
123
- Object.keys(i).map((l) => [l, d + "." + l])
124
- );
125
- t.set(d, { fields: h }), Object.keys(i).forEach((l) => {
126
- S(i[l], [...p, l]);
127
- });
128
- } else
129
- t.set(d, { value: i });
130
- };
131
- if (S(s, []), a) {
132
- const i = t.get(e) || {};
133
- t.set(e, {
134
- ...i,
135
- components: a
136
- });
137
- }
138
- return { shadowStateStore: t };
139
- });
140
- },
141
- getShadowValue: (e, s) => {
142
- const o = /* @__PURE__ */ new Map(), t = (n, a) => {
143
- if (o.has(n))
144
- return o.get(n);
145
- const r = c().shadowStateStore.get(n);
146
- if (!r)
147
- return;
148
- if (r.value !== void 0)
149
- return r.value;
150
- let S;
151
- if (r.arrayKeys) {
152
- const i = a ?? r.arrayKeys;
153
- S = [], o.set(n, S), i.forEach((p) => {
154
- S.push(t(p));
155
- });
156
- } else r.fields ? (S = {}, o.set(n, S), Object.entries(r.fields).forEach(([i, p]) => {
157
- S[i] = t(p);
158
- })) : S = void 0;
159
- return S;
160
- };
161
- return t(e, s);
162
- },
163
- getShadowMetadata: (e, s) => {
164
- const o = [e, ...s].join(".");
165
- return c().shadowStateStore.get(o);
166
- },
167
- setShadowMetadata: (e, s, o) => {
168
- const t = [e, ...s].join("."), n = c().shadowStateStore.get(t);
169
- n?.components && !o.components && (console.group(
170
- "%c🚨 RACE CONDITION DETECTED! 🚨",
171
- "color: red; font-size: 18px; font-weight: bold;"
172
- ), console.error(
173
- `An overwrite is about to happen on stateKey: "${e}" at path: [${s.join(", ")}]`
174
- ), console.log(
175
- "The EXISTING metadata had a components map:",
176
- n.components
177
- ), console.log(
178
- "The NEW metadata is trying to save WITHOUT a components map:",
179
- o
180
- ), console.log(
181
- "%cStack trace to the function that caused this overwrite:",
182
- "font-weight: bold;"
183
- ), console.trace(), console.groupEnd());
184
- const a = new Map(c().shadowStateStore), r = { ...n || {}, ...o };
185
- a.set(t, r), f({ shadowStateStore: a });
186
- },
187
- setTransformCache: (e, s, o, t) => {
188
- const n = [e, ...s].join("."), a = new Map(c().shadowStateStore), r = a.get(n) || {};
189
- r.transformCaches || (r.transformCaches = /* @__PURE__ */ new Map()), r.transformCaches.set(o, t), a.set(n, r), f({ shadowStateStore: a });
190
- },
191
- insertShadowArrayElement: (e, s, o) => {
192
- const t = new Map(c().shadowStateStore), n = [e, ...s].join("."), a = t.get(n);
193
- if (!a || !a.arrayKeys) return;
194
- const r = `id:${b()}`, S = n + "." + r, i = [...a.arrayKeys];
195
- i.push(S), t.set(n, { ...a, arrayKeys: i });
196
- const p = (d, h) => {
197
- const l = [e, ...h].join(".");
198
- if (!Array.isArray(d)) if (typeof d == "object" && d !== null) {
199
- const u = Object.fromEntries(
200
- Object.keys(d).map((w) => [w, l + "." + w])
201
- );
202
- t.set(l, { fields: u }), Object.entries(d).forEach(([w, y]) => {
203
- p(y, [...h, w]);
204
- });
205
- } else
206
- t.set(l, { value: d });
207
- };
208
- p(o, [...s, r]), f({ shadowStateStore: t }), c().notifyPathSubscribers(n, {
209
- type: "INSERT",
210
- path: n,
211
- itemKey: S
212
- });
213
- },
214
- removeShadowArrayElement: (e, s) => {
215
- const o = new Map(c().shadowStateStore), t = [e, ...s].join("."), n = s.slice(0, -1), a = [e, ...n].join("."), r = o.get(a);
216
- if (r && r.arrayKeys && r.arrayKeys.findIndex(
217
- (i) => i === t
218
- ) !== -1) {
219
- const i = r.arrayKeys.filter(
220
- (d) => d !== t
221
- );
222
- o.set(a, {
223
- ...r,
224
- arrayKeys: i
225
- });
226
- const p = t + ".";
227
- for (const d of Array.from(o.keys()))
228
- (d === t || d.startsWith(p)) && o.delete(d);
229
- }
230
- f({ shadowStateStore: o }), c().notifyPathSubscribers(a, {
231
- type: "REMOVE",
232
- path: a,
233
- itemKey: t
234
- // The exact ID of the removed item
235
- });
236
- },
237
- updateShadowAtPath: (e, s, o) => {
238
- const t = [e, ...s].join(".");
239
- c().shadowStateStore.get(t)?.value === o && !m(o) || f((a) => {
240
- const r = a.shadowStateStore;
241
- if (m(o)) {
242
- const S = (i, p) => {
243
- const d = [e, ...i].join("."), h = r.get(d);
244
- if (h && h.fields) {
245
- for (const l in p)
246
- if (Object.prototype.hasOwnProperty.call(p, l)) {
247
- const u = p[l], w = h.fields[l];
248
- if (w)
249
- if (m(u))
250
- S(
251
- w.split(".").slice(1),
252
- u
253
- );
254
- else {
255
- const y = r.get(w) || {};
256
- r.set(w, {
257
- ...y,
258
- value: u
259
- });
260
- }
261
- }
262
- }
263
- };
264
- S(s, o);
265
- } else {
266
- const S = r.get(t) || {};
267
- r.set(t, { ...S, value: o });
268
- }
269
- return c().notifyPathSubscribers(t, { type: "UPDATE", newValue: o }), a;
270
- });
240
+ const o = r().pathSubscribers.get(e);
241
+ o && o.forEach((t) => t(s));
271
242
  },
272
243
  selectedIndicesMap: /* @__PURE__ */ new Map(),
273
244
  getSelectedIndex: (e, s) => {
274
- const o = c().selectedIndicesMap.get(e);
275
- if (!o) return -1;
276
- const t = s || E.getState().getShadowMetadata(e, [])?.arrayKeys;
277
- return t ? t.indexOf(o) : -1;
245
+ const n = r().selectedIndicesMap.get(e);
246
+ if (!n) return -1;
247
+ const o = r().getShadowMetadata(
248
+ e.split(".")[0],
249
+ e.split(".").slice(1)
250
+ ), t = s || o?.arrayKeys;
251
+ return t ? t.indexOf(n) : -1;
278
252
  },
279
253
  setSelectedIndex: (e, s) => {
280
- f((o) => {
281
- const t = o.selectedIndicesMap;
282
- return s === void 0 ? t.delete(e) : (t.has(e) && c().notifyPathSubscribers(t.get(e), {
283
- type: "THIS_UNSELECTED"
284
- }), t.set(e, s), c().notifyPathSubscribers(s, {
285
- type: "THIS_SELECTED"
286
- })), c().notifyPathSubscribers(e, {
287
- type: "GET_SELECTED"
288
- }), {
289
- ...o,
290
- selectedIndicesMap: t
291
- };
254
+ d((n) => {
255
+ const o = new Map(n.selectedIndicesMap), t = o.get(e);
256
+ return t && r().notifyPathSubscribers(t, { type: "THIS_UNSELECTED" }), s === void 0 ? o.delete(e) : (o.set(e, s), r().notifyPathSubscribers(s, { type: "THIS_SELECTED" })), r().notifyPathSubscribers(e, { type: "GET_SELECTED" }), { selectedIndicesMap: o };
292
257
  });
293
258
  },
294
259
  clearSelectedIndex: ({ arrayKey: e }) => {
295
- f((s) => {
296
- const o = s.selectedIndicesMap, t = o.get(e);
297
- return t && c().notifyPathSubscribers(t, {
298
- type: "CLEAR_SELECTION"
299
- }), o.delete(e), c().notifyPathSubscribers(e, {
300
- type: "CLEAR_SELECTION"
301
- }), {
302
- ...s,
303
- selectedIndicesMap: o
304
- };
260
+ d((s) => {
261
+ const n = new Map(s.selectedIndicesMap), o = n.get(e);
262
+ return o && r().notifyPathSubscribers(o, { type: "CLEAR_SELECTION" }), n.delete(e), r().notifyPathSubscribers(e, { type: "CLEAR_SELECTION" }), { selectedIndicesMap: n };
305
263
  });
306
264
  },
307
265
  clearSelectedIndexesForState: (e) => {
308
- f((s) => {
309
- const o = new Map(s.selectedIndicesMap);
310
- return o.delete(e) ? { selectedIndicesMap: o } : {};
266
+ d((s) => {
267
+ const n = new Map(s.selectedIndicesMap);
268
+ let o = !1;
269
+ for (const t of n.keys())
270
+ (t === e || t.startsWith(e + ".")) && (n.delete(t), o = !0);
271
+ return o ? { selectedIndicesMap: n } : {};
311
272
  });
312
273
  },
313
274
  initialStateOptions: {},
314
- stateTimeline: {},
315
- cogsStateStore: {},
316
275
  stateLog: /* @__PURE__ */ new Map(),
317
276
  initialStateGlobal: {},
318
- validationErrors: /* @__PURE__ */ new Map(),
319
- addStateLog: (e, s) => {
320
- f((o) => {
321
- const t = new Map(o.stateLog), n = new Map(t.get(e)), a = JSON.stringify(s.path), r = n.get(a);
322
- return r ? (r.newValue = s.newValue, r.timeStamp = s.timeStamp) : n.set(a, { ...s }), t.set(e, n), { stateLog: t };
277
+ addStateLog: (e) => {
278
+ !e || e.length === 0 || d((s) => {
279
+ const n = new Map(s.stateLog), o = /* @__PURE__ */ new Map();
280
+ for (const t of e) {
281
+ const a = o.get(t.stateKey) || [];
282
+ a.push(t), o.set(t.stateKey, a);
283
+ }
284
+ for (const [t, a] of o.entries()) {
285
+ const c = new Map(n.get(t));
286
+ for (const p of a)
287
+ c.set(JSON.stringify(p.path), { ...p });
288
+ n.set(t, c);
289
+ }
290
+ return { stateLog: n };
323
291
  });
324
292
  },
325
- getInitialOptions: (e) => c().initialStateOptions[e],
293
+ getInitialOptions: (e) => r().initialStateOptions[e],
326
294
  setInitialStateOptions: (e, s) => {
327
- f((o) => ({
328
- initialStateOptions: {
329
- ...o.initialStateOptions,
330
- [e]: s
331
- }
295
+ d((n) => ({
296
+ initialStateOptions: { ...n.initialStateOptions, [e]: s }
332
297
  }));
333
298
  },
334
299
  updateInitialStateGlobal: (e, s) => {
335
- f((o) => ({
336
- initialStateGlobal: {
337
- ...o.initialStateGlobal,
338
- [e]: s
339
- }
300
+ d((n) => ({
301
+ initialStateGlobal: { ...n.initialStateGlobal, [e]: s }
340
302
  }));
341
303
  },
342
304
  syncInfoStore: /* @__PURE__ */ new Map(),
343
- setSyncInfo: (e, s) => f((o) => {
344
- const t = new Map(o.syncInfoStore);
345
- return t.set(e, s), { ...o, syncInfoStore: t };
305
+ setSyncInfo: (e, s) => d((n) => {
306
+ const o = new Map(n.syncInfoStore);
307
+ return o.set(e, s), { syncInfoStore: o };
346
308
  }),
347
- getSyncInfo: (e) => c().syncInfoStore.get(e) || null
309
+ getSyncInfo: (e) => r().syncInfoStore.get(e) || null
348
310
  }));
349
311
  export {
350
- j as formRefStore,
351
- E as getGlobalStore
312
+ g as METADATA_KEYS,
313
+ m as buildShadowNode,
314
+ _ as formRefStore,
315
+ I as getGlobalStore
352
316
  };
353
317
  //# sourceMappingURL=store.js.map