cogsbox-state 0.5.465 → 0.5.466

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