cogsbox-state 0.5.465 → 0.5.467

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