@yoltra/react 0.7.0 → 0.8.0

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/index.mjs CHANGED
@@ -1,72 +1,72 @@
1
1
  /*!
2
- * @yoltra/react v0.7.0
2
+ * @yoltra/react v0.8.0
3
3
  * (c) 2026 Manu Ramirez <@pixerael>
4
4
  * License: MIT */
5
- import ge, { createContext as de, useRef as P, useMemo as E, useCallback as me, useEffect as he, useSyncExternalStore as I, useContext as ve } from "react";
6
- import { createStore as Pe } from "@yoltra/core";
7
- const ye = de(null);
8
- var G = { exports: {} }, z = {};
9
- var ue;
10
- function _e() {
11
- if (ue) return z;
12
- ue = 1;
5
+ import Te, { createContext as ye, useRef as _, useMemo as w, useCallback as ve, useSyncExternalStore as J, useEffect as je, useContext as ke } from "react";
6
+ import { createStore as Oe } from "@yoltra/core";
7
+ const be = ye(null);
8
+ var q = { exports: {} }, V = {};
9
+ var ie;
10
+ function xe() {
11
+ if (ie) return V;
12
+ ie = 1;
13
13
  var r = /* @__PURE__ */ Symbol.for("react.transitional.element"), e = /* @__PURE__ */ Symbol.for("react.fragment");
14
- function n(o, s, c) {
14
+ function n(c, o, s) {
15
15
  var u = null;
16
- if (c !== void 0 && (u = "" + c), s.key !== void 0 && (u = "" + s.key), "key" in s) {
17
- c = {};
18
- for (var d in s)
19
- d !== "key" && (c[d] = s[d]);
20
- } else c = s;
21
- return s = c.ref, {
16
+ if (s !== void 0 && (u = "" + s), o.key !== void 0 && (u = "" + o.key), "key" in o) {
17
+ s = {};
18
+ for (var i in o)
19
+ i !== "key" && (s[i] = o[i]);
20
+ } else s = o;
21
+ return o = s.ref, {
22
22
  $$typeof: r,
23
- type: o,
23
+ type: c,
24
24
  key: u,
25
- ref: s !== void 0 ? s : null,
26
- props: c
25
+ ref: o !== void 0 ? o : null,
26
+ props: s
27
27
  };
28
28
  }
29
- return z.Fragment = e, z.jsx = n, z.jsxs = n, z;
29
+ return V.Fragment = e, V.jsx = n, V.jsxs = n, V;
30
30
  }
31
- var W = {};
31
+ var G = {};
32
32
  var ae;
33
- function we() {
33
+ function Ne() {
34
34
  return ae || (ae = 1, process.env.NODE_ENV !== "production" && (function() {
35
35
  function r(t) {
36
36
  if (t == null) return null;
37
37
  if (typeof t == "function")
38
- return t.$$typeof === J ? null : t.displayName || t.name || null;
38
+ return t.$$typeof === O ? null : t.displayName || t.name || null;
39
39
  if (typeof t == "string") return t;
40
40
  switch (t) {
41
- case m:
41
+ case h:
42
42
  return "Fragment";
43
- case j:
43
+ case T:
44
44
  return "Profiler";
45
- case g:
45
+ case P:
46
46
  return "StrictMode";
47
- case D:
47
+ case j:
48
48
  return "Suspense";
49
- case F:
49
+ case C:
50
50
  return "SuspenseList";
51
- case N:
51
+ case v:
52
52
  return "Activity";
53
53
  }
54
54
  if (typeof t == "object")
55
55
  switch (typeof t.tag == "number" && console.error(
56
56
  "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
57
57
  ), t.$$typeof) {
58
- case y:
58
+ case E:
59
59
  return "Portal";
60
- case R:
60
+ case A:
61
61
  return (t.displayName || "Context") + ".Provider";
62
- case w:
62
+ case R:
63
63
  return (t._context.displayName || "Context") + ".Consumer";
64
- case O:
64
+ case $:
65
65
  var a = t.render;
66
66
  return t = t.displayName, t || (t = a.displayName || a.name || "", t = t !== "" ? "ForwardRef(" + t + ")" : "ForwardRef"), t;
67
- case $:
67
+ case I:
68
68
  return a = t.displayName || null, a !== null ? a : r(t.type) || "Memo";
69
- case A:
69
+ case Y:
70
70
  a = t._payload, t = t._init;
71
71
  try {
72
72
  return r(t(a));
@@ -87,17 +87,17 @@ function we() {
87
87
  }
88
88
  if (a) {
89
89
  a = console;
90
- var f = a.error, b = typeof Symbol == "function" && Symbol.toStringTag && t[Symbol.toStringTag] || t.constructor.name || "Object";
91
- return f.call(
90
+ var m = a.error, S = typeof Symbol == "function" && Symbol.toStringTag && t[Symbol.toStringTag] || t.constructor.name || "Object";
91
+ return m.call(
92
92
  a,
93
93
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
94
- b
94
+ S
95
95
  ), e(t);
96
96
  }
97
97
  }
98
- function o(t) {
99
- if (t === m) return "<>";
100
- if (typeof t == "object" && t !== null && t.$$typeof === A)
98
+ function c(t) {
99
+ if (t === h) return "<>";
100
+ if (typeof t == "object" && t !== null && t.$$typeof === Y)
101
101
  return "<...>";
102
102
  try {
103
103
  var a = r(t);
@@ -106,48 +106,48 @@ function we() {
106
106
  return "<...>";
107
107
  }
108
108
  }
109
- function s() {
110
- var t = T.A;
109
+ function o() {
110
+ var t = D.A;
111
111
  return t === null ? null : t.getOwner();
112
112
  }
113
- function c() {
113
+ function s() {
114
114
  return Error("react-stack-top-frame");
115
115
  }
116
116
  function u(t) {
117
- if (B.call(t, "key")) {
117
+ if (x.call(t, "key")) {
118
118
  var a = Object.getOwnPropertyDescriptor(t, "key").get;
119
119
  if (a && a.isReactWarning) return !1;
120
120
  }
121
121
  return t.key !== void 0;
122
122
  }
123
- function d(t, a) {
124
- function f() {
125
- te || (te = !0, console.error(
123
+ function i(t, a) {
124
+ function m() {
125
+ ne || (ne = !0, console.error(
126
126
  "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
127
127
  a
128
128
  ));
129
129
  }
130
- f.isReactWarning = !0, Object.defineProperty(t, "key", {
131
- get: f,
130
+ m.isReactWarning = !0, Object.defineProperty(t, "key", {
131
+ get: m,
132
132
  configurable: !0
133
133
  });
134
134
  }
135
- function h() {
135
+ function d() {
136
136
  var t = r(this.type);
137
- return ne[t] || (ne[t] = !0, console.error(
137
+ return oe[t] || (oe[t] = !0, console.error(
138
138
  "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
139
139
  )), t = this.props.ref, t !== void 0 ? t : null;
140
140
  }
141
- function _(t, a, f, b, C, k, Z, K) {
142
- return f = k.ref, t = {
143
- $$typeof: l,
141
+ function b(t, a, m, S, M, k, H, Z) {
142
+ return m = k.ref, t = {
143
+ $$typeof: p,
144
144
  type: t,
145
145
  key: a,
146
146
  props: k,
147
- _owner: C
148
- }, (f !== void 0 ? f : null) !== null ? Object.defineProperty(t, "ref", {
147
+ _owner: M
148
+ }, (m !== void 0 ? m : null) !== null ? Object.defineProperty(t, "ref", {
149
149
  enumerable: !1,
150
- get: h
150
+ get: d
151
151
  }) : Object.defineProperty(t, "ref", { enumerable: !1, value: null }), t._store = {}, Object.defineProperty(t._store, "validated", {
152
152
  configurable: !1,
153
153
  enumerable: !1,
@@ -162,140 +162,140 @@ function we() {
162
162
  configurable: !1,
163
163
  enumerable: !1,
164
164
  writable: !0,
165
- value: Z
165
+ value: H
166
166
  }), Object.defineProperty(t, "_debugTask", {
167
167
  configurable: !1,
168
168
  enumerable: !1,
169
169
  writable: !0,
170
- value: K
170
+ value: Z
171
171
  }), Object.freeze && (Object.freeze(t.props), Object.freeze(t)), t;
172
172
  }
173
- function p(t, a, f, b, C, k, Z, K) {
174
- var S = a.children;
175
- if (S !== void 0)
176
- if (b)
177
- if (X(S)) {
178
- for (b = 0; b < S.length; b++)
179
- i(S[b]);
180
- Object.freeze && Object.freeze(S);
173
+ function f(t, a, m, S, M, k, H, Z) {
174
+ var g = a.children;
175
+ if (g !== void 0)
176
+ if (S)
177
+ if (te(g)) {
178
+ for (S = 0; S < g.length; S++)
179
+ l(g[S]);
180
+ Object.freeze && Object.freeze(g);
181
181
  } else
182
182
  console.error(
183
183
  "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
184
184
  );
185
- else i(S);
186
- if (B.call(a, "key")) {
187
- S = r(t);
188
- var M = Object.keys(a).filter(function(Re) {
189
- return Re !== "key";
185
+ else l(g);
186
+ if (x.call(a, "key")) {
187
+ g = r(t);
188
+ var z = Object.keys(a).filter(function(_e) {
189
+ return _e !== "key";
190
190
  });
191
- b = 0 < M.length ? "{key: someKey, " + M.join(": ..., ") + ": ...}" : "{key: someKey}", ce[S + b] || (M = 0 < M.length ? "{" + M.join(": ..., ") + ": ...}" : "{}", console.error(
191
+ S = 0 < z.length ? "{key: someKey, " + z.join(": ..., ") + ": ...}" : "{key: someKey}", ue[g + S] || (z = 0 < z.length ? "{" + z.join(": ..., ") + ": ...}" : "{}", console.error(
192
192
  `A props object containing a "key" prop is being spread into JSX:
193
193
  let props = %s;
194
194
  <%s {...props} />
195
195
  React keys must be passed directly to JSX without using spread:
196
196
  let props = %s;
197
197
  <%s key={someKey} {...props} />`,
198
- b,
199
198
  S,
200
- M,
201
- S
202
- ), ce[S + b] = !0);
199
+ g,
200
+ z,
201
+ g
202
+ ), ue[g + S] = !0);
203
203
  }
204
- if (S = null, f !== void 0 && (n(f), S = "" + f), u(a) && (n(a.key), S = "" + a.key), "key" in a) {
205
- f = {};
206
- for (var Q in a)
207
- Q !== "key" && (f[Q] = a[Q]);
208
- } else f = a;
209
- return S && d(
210
- f,
204
+ if (g = null, m !== void 0 && (n(m), g = "" + m), u(a) && (n(a.key), g = "" + a.key), "key" in a) {
205
+ m = {};
206
+ for (var K in a)
207
+ K !== "key" && (m[K] = a[K]);
208
+ } else m = a;
209
+ return g && i(
210
+ m,
211
211
  typeof t == "function" ? t.displayName || t.name || "Unknown" : t
212
- ), _(
212
+ ), b(
213
213
  t,
214
- S,
214
+ g,
215
215
  k,
216
- C,
217
- s(),
218
- f,
219
- Z,
220
- K
216
+ M,
217
+ o(),
218
+ m,
219
+ H,
220
+ Z
221
221
  );
222
222
  }
223
- function i(t) {
224
- typeof t == "object" && t !== null && t.$$typeof === l && t._store && (t._store.validated = 1);
223
+ function l(t) {
224
+ typeof t == "object" && t !== null && t.$$typeof === p && t._store && (t._store.validated = 1);
225
225
  }
226
- var v = ge, l = /* @__PURE__ */ Symbol.for("react.transitional.element"), y = /* @__PURE__ */ Symbol.for("react.portal"), m = /* @__PURE__ */ Symbol.for("react.fragment"), g = /* @__PURE__ */ Symbol.for("react.strict_mode"), j = /* @__PURE__ */ Symbol.for("react.profiler"), w = /* @__PURE__ */ Symbol.for("react.consumer"), R = /* @__PURE__ */ Symbol.for("react.context"), O = /* @__PURE__ */ Symbol.for("react.forward_ref"), D = /* @__PURE__ */ Symbol.for("react.suspense"), F = /* @__PURE__ */ Symbol.for("react.suspense_list"), $ = /* @__PURE__ */ Symbol.for("react.memo"), A = /* @__PURE__ */ Symbol.for("react.lazy"), N = /* @__PURE__ */ Symbol.for("react.activity"), J = /* @__PURE__ */ Symbol.for("react.client.reference"), T = v.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, B = Object.prototype.hasOwnProperty, X = Array.isArray, H = console.createTask ? console.createTask : function() {
226
+ var y = Te, p = /* @__PURE__ */ Symbol.for("react.transitional.element"), E = /* @__PURE__ */ Symbol.for("react.portal"), h = /* @__PURE__ */ Symbol.for("react.fragment"), P = /* @__PURE__ */ Symbol.for("react.strict_mode"), T = /* @__PURE__ */ Symbol.for("react.profiler"), R = /* @__PURE__ */ Symbol.for("react.consumer"), A = /* @__PURE__ */ Symbol.for("react.context"), $ = /* @__PURE__ */ Symbol.for("react.forward_ref"), j = /* @__PURE__ */ Symbol.for("react.suspense"), C = /* @__PURE__ */ Symbol.for("react.suspense_list"), I = /* @__PURE__ */ Symbol.for("react.memo"), Y = /* @__PURE__ */ Symbol.for("react.lazy"), v = /* @__PURE__ */ Symbol.for("react.activity"), O = /* @__PURE__ */ Symbol.for("react.client.reference"), D = y.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, x = Object.prototype.hasOwnProperty, te = Array.isArray, L = console.createTask ? console.createTask : function() {
227
227
  return null;
228
228
  };
229
- v = {
229
+ y = {
230
230
  react_stack_bottom_frame: function(t) {
231
231
  return t();
232
232
  }
233
233
  };
234
- var te, ne = {}, oe = v.react_stack_bottom_frame.bind(
235
- v,
236
- c
237
- )(), se = H(o(c)), ce = {};
238
- W.Fragment = m, W.jsx = function(t, a, f, b, C) {
239
- var k = 1e4 > T.recentlyCreatedOwnerStacks++;
240
- return p(
234
+ var ne, oe = {}, se = y.react_stack_bottom_frame.bind(
235
+ y,
236
+ s
237
+ )(), ce = L(c(s)), ue = {};
238
+ G.Fragment = h, G.jsx = function(t, a, m, S, M) {
239
+ var k = 1e4 > D.recentlyCreatedOwnerStacks++;
240
+ return f(
241
241
  t,
242
242
  a,
243
- f,
243
+ m,
244
244
  !1,
245
- b,
246
- C,
247
- k ? Error("react-stack-top-frame") : oe,
248
- k ? H(o(t)) : se
245
+ S,
246
+ M,
247
+ k ? Error("react-stack-top-frame") : se,
248
+ k ? L(c(t)) : ce
249
249
  );
250
- }, W.jsxs = function(t, a, f, b, C) {
251
- var k = 1e4 > T.recentlyCreatedOwnerStacks++;
252
- return p(
250
+ }, G.jsxs = function(t, a, m, S, M) {
251
+ var k = 1e4 > D.recentlyCreatedOwnerStacks++;
252
+ return f(
253
253
  t,
254
254
  a,
255
- f,
255
+ m,
256
256
  !0,
257
- b,
258
- C,
259
- k ? Error("react-stack-top-frame") : oe,
260
- k ? H(o(t)) : se
257
+ S,
258
+ M,
259
+ k ? Error("react-stack-top-frame") : se,
260
+ k ? L(c(t)) : ce
261
261
  );
262
262
  };
263
- })()), W;
263
+ })()), G;
264
264
  }
265
- var ie;
266
- function Te() {
267
- return ie || (ie = 1, process.env.NODE_ENV === "production" ? G.exports = _e() : G.exports = we()), G.exports;
265
+ var le;
266
+ function $e() {
267
+ return le || (le = 1, process.env.NODE_ENV === "production" ? q.exports = xe() : q.exports = Ne()), q.exports;
268
268
  }
269
- var be = Te();
270
- const Ve = ({ store: r, children: e }) => /* @__PURE__ */ be.jsx(ye.Provider, { value: r, children: e }), le = /* @__PURE__ */ new Set();
271
- function ke(r, e) {
272
- process.env.NODE_ENV !== "production" && (le.has(r) || (le.add(r), console.warn(e)));
269
+ var Ee = $e();
270
+ const Ke = ({ store: r, children: e }) => /* @__PURE__ */ Ee.jsx(be.Provider, { value: r, children: e }), fe = /* @__PURE__ */ new Set();
271
+ function Ce(r, e) {
272
+ process.env.NODE_ENV !== "production" && (fe.has(r) || (fe.add(r), console.warn(e)));
273
273
  }
274
- function L(r) {
274
+ function B(r) {
275
275
  return r.includes("*");
276
276
  }
277
- function x(r) {
277
+ function N(r) {
278
278
  return r.replace(/^\./, "");
279
279
  }
280
- function xe(r) {
281
- return x(r).split(".").filter(Boolean);
280
+ function Ie(r) {
281
+ return N(r).split(".").filter(Boolean);
282
282
  }
283
- function je(r) {
283
+ function Ye(r) {
284
284
  const e = (n) => `${n.length}:${n}`;
285
285
  return r.map((n) => {
286
- const o = Array.isArray(n.property) ? n.property : [n.property];
287
- return e(n.reducer) + e(String(o.length)) + o.map(e).join("");
286
+ const c = Array.isArray(n.property) ? n.property : [n.property];
287
+ return e(n.reducer) + e(String(c.length)) + c.map(e).join("");
288
288
  }).join("");
289
289
  }
290
290
  const Se = /* @__PURE__ */ Symbol("yoltra.pathSegments");
291
- function Ee(r) {
291
+ function ge(r) {
292
292
  const e = () => {
293
293
  };
294
294
  return new Proxy(e, {
295
- get(n, o) {
296
- if (o === Se) return r;
297
- if (typeof o != "symbol")
298
- return Ee([...r, String(o)]);
295
+ get(n, c) {
296
+ if (c === Se) return r;
297
+ if (typeof c != "symbol")
298
+ return ge([...r, String(c)]);
299
299
  },
300
300
  apply() {
301
301
  throw new Error(
@@ -304,104 +304,129 @@ function Ee(r) {
304
304
  }
305
305
  });
306
306
  }
307
- function Oe(r) {
308
- const e = r(Ee([])), n = e?.[Se], s = (Array.isArray(n) ? n : []).join(".");
309
- return s === "" && ke(
307
+ function De(r) {
308
+ const e = r(ge([])), n = e?.[Se], o = (Array.isArray(n) ? n : []).join(".");
309
+ return o === "" && Ce(
310
310
  "yoltra.toDottedPath.empty",
311
311
  "[yoltra] A typed path accessor recorded no property access, so it subscribed to the slice root. That fires only when the slice's whole value is replaced — which for a slice holding an object means never, since its changes are reported at their leaves. The accessor must be a plain member chain like `p => p.items[0].title` and cannot return a computed value or a default. For a dynamic subscription, or for a slice whose state is a single value, use the `{ reducer, property }` string form instead."
312
- ), s;
312
+ ), o;
313
313
  }
314
- function U(r, e) {
314
+ function X(r, e) {
315
315
  if (!e) return r;
316
316
  let n = r;
317
- for (const o of xe(e)) {
317
+ for (const c of Ie(e)) {
318
318
  if (n == null) return;
319
- n = n[o];
319
+ n = n[c];
320
320
  }
321
321
  return n;
322
322
  }
323
- function V(r, e, n) {
324
- const o = P(r);
325
- o.current = r;
326
- const s = P(e);
327
- s.current = e;
328
- const c = E(
329
- () => ({ has: !1, value: void 0 }),
330
- // eslint-disable-next-line react-hooks/exhaustive-deps
331
- n
332
- );
333
- return me(() => {
334
- const u = o.current();
335
- return (!c.has || !s.current(c.value, u)) && (c.has = !0, c.value = u), c.value;
336
- }, [c]);
323
+ function F(r) {
324
+ return typeof r == "object" && r !== null;
337
325
  }
338
- function Ne(r, e) {
326
+ function Me(r, e) {
327
+ const n = e.split("."), c = [], o = (s, u, i) => {
328
+ if (u === n.length) {
329
+ c.push(i.join("."));
330
+ return;
331
+ }
332
+ const d = n[u];
333
+ if (d === "**") {
334
+ if (o(s, u + 1, i), !F(s)) return;
335
+ for (const b of Object.keys(s)) o(s[b], u, [...i, b]);
336
+ return;
337
+ }
338
+ if (d === "*") {
339
+ if (!F(s)) return;
340
+ for (const b of Object.keys(s)) o(s[b], u + 1, [...i, b]);
341
+ return;
342
+ }
343
+ F(s) && Object.prototype.hasOwnProperty.call(s, d) && o(s[d], u + 1, [...i, d]);
344
+ };
345
+ return o(r, 0, []), c;
346
+ }
347
+ const Q = /* @__PURE__ */ new WeakSet();
348
+ function Fe(r, e, n, c) {
349
+ if (n.length === 0) return;
350
+ let o = r, s = e;
351
+ for (let u = 0; u < n.length - 1; u++) {
352
+ const i = n[u], d = F(s) ? s[i] : void 0, b = o[i];
353
+ if (F(b)) {
354
+ if (!Q.has(b)) {
355
+ const f = Array.isArray(b) ? [...b] : { ...b };
356
+ Q.add(f), o[i] = f;
357
+ }
358
+ } else {
359
+ const f = Array.isArray(d) ? [] : {};
360
+ Q.add(f), o[i] = f;
361
+ }
362
+ o = o[i], s = d;
363
+ }
364
+ o[n[n.length - 1]] = c;
365
+ }
366
+ function We(r, e) {
367
+ const n = {};
368
+ for (const { reducer: c, property: o } of e) {
369
+ const s = F(r) ? r[c] : void 0;
370
+ if (o === "") {
371
+ n[c] = s;
372
+ continue;
373
+ }
374
+ const u = B(o) ? Me(s, o) : [o];
375
+ for (const i of u)
376
+ Fe(n, r, [c, ...i.split(".")], X(s, i));
377
+ }
378
+ return n;
379
+ }
380
+ function Ae(r, e, n = []) {
381
+ const c = () => e.map((o) => `{ reducer: "${o.reducer}", property: "${o.property}" }`).join(", ");
382
+ return new Proxy(r, {
383
+ get(o, s, u) {
384
+ if (typeof s == "symbol" || s === "toJSON" || s === "constructor")
385
+ return Reflect.get(o, s, u);
386
+ if (!Object.prototype.hasOwnProperty.call(o, s)) {
387
+ const d = [...n, String(s)].join(".");
388
+ throw new Error(
389
+ `[yoltra] useAtomicProps read "${d}", which it did not subscribe to. The selector only receives the paths declared alongside it, so this read would be \`undefined\` in production and the component would never re-render when it changed. Declared: [${c()}]. Add "${d}" to the list, or stop reading it.`
390
+ );
391
+ }
392
+ const i = Reflect.get(o, s, u);
393
+ return F(i) && !Array.isArray(i) ? Ae(i, e, [...n, String(s)]) : i;
394
+ },
395
+ has: (o, s) => Reflect.has(o, s)
396
+ });
397
+ }
398
+ function ze(r, e) {
339
399
  if (Object.is(r, e)) return !0;
340
400
  if (!r || !e) return !1;
341
- const n = Object.keys(r), o = Object.keys(e);
342
- if (n.length !== o.length) return !1;
343
- for (const s of n)
344
- if (!Object.is(r[s], e[s])) return !1;
401
+ const n = Object.keys(r), c = Object.keys(e);
402
+ if (n.length !== c.length) return !1;
403
+ for (const o of n)
404
+ if (!Object.is(r[o], e[o])) return !1;
345
405
  return !0;
346
406
  }
347
- function q() {
348
- const r = ve(ye);
349
- if (!r) throw new Error("useStore must be used inside <StoreProvider>");
350
- return r;
351
- }
352
- function qe() {
353
- return q().emit;
354
- }
355
- function Je(r, e = Object.is) {
356
- const n = q(), o = E(() => (c) => n.subscribe(c), [n]), s = V(
357
- () => r(n.getState()),
358
- e,
359
- [n]
360
- );
361
- return I(o, s, s);
362
- }
363
- function Ce(r, e, n = Object.is) {
364
- const o = q(), s = E(() => {
365
- const h = x(r.property);
366
- return { reducer: r.reducer, property: h };
367
- }, [r.reducer, r.property]), c = E(
368
- () => (h) => o.connect(
369
- { reducer: s.reducer, property: s.property },
370
- () => h()
371
- ),
372
- [o, s]
373
- ), u = L(s.property), d = V(
374
- () => {
375
- const _ = o.getState()[s.reducer];
376
- return u ? _ : U(_, s.property);
377
- },
378
- n,
379
- [o, s]
407
+ function pe(r, e, n) {
408
+ const c = _(r);
409
+ c.current = r;
410
+ const o = _(e);
411
+ o.current = e;
412
+ const s = w(
413
+ () => ({ has: !1, value: void 0 }),
414
+ // eslint-disable-next-line react-hooks/exhaustive-deps
415
+ n
380
416
  );
381
- return I(c, d, d);
382
- }
383
- function ee(r, e, n = Object.is) {
384
- return Ce(r, e, n);
385
- }
386
- function Be(r, e, n, o = "committed") {
387
- const s = q(), c = P(n);
388
- c.current = n, he(() => s.onEvent(
389
- r,
390
- e,
391
- (u, d, h, _) => {
392
- c.current(u, d, h, _);
393
- },
394
- o
395
- ), [s, r, e, o]);
417
+ return ve(() => {
418
+ const u = c.current();
419
+ return (!s.has || !o.current(s.value, u)) && (s.has = !0, s.value = u), s.value;
420
+ }, [s]);
396
421
  }
397
- function $e(r) {
422
+ function Le(r) {
398
423
  return r == null || r <= 0 ? null : Date.now() + r;
399
424
  }
400
- function Ie(r) {
425
+ function Ve(r) {
401
426
  return r === null ? null : r === void 0 || r <= 0 ? 0 : Date.now() + r;
402
427
  }
403
- const Ye = 2e3;
404
- class De {
428
+ const Ge = 2e3;
429
+ class Je {
405
430
  store = /* @__PURE__ */ new Map();
406
431
  /**
407
432
  * Marks a key as most recently used, and evicts the coldest entries past the cap.
@@ -418,7 +443,7 @@ class De {
418
443
  }
419
444
  /** @internal */
420
445
  evict() {
421
- for (; this.store.size > Ye; ) {
446
+ for (; this.store.size > Ge; ) {
422
447
  const e = this.store.keys().next();
423
448
  if (e.done === !0) return;
424
449
  const n = this.store.get(e.value);
@@ -433,28 +458,28 @@ class De {
433
458
  get size() {
434
459
  return this.store.size;
435
460
  }
436
- read(e, n, o, s) {
437
- const c = Date.now(), u = this.store.get(e);
438
- if (u && u.status === "ready" && (u.expiresAt == null || u.expiresAt > c))
461
+ read(e, n, c, o) {
462
+ const s = Date.now(), u = this.store.get(e);
463
+ if (u && u.status === "ready" && (u.expiresAt == null || u.expiresAt > s))
439
464
  return this.touch(e), this.store.set(e, u), u.value;
440
465
  if (u && u.status === "pending")
441
466
  throw u.promise;
442
467
  if (u && u.status === "error") {
443
468
  if (u.delivered !== !0)
444
469
  throw this.store.set(e, { ...u, delivered: !0 }), u.error;
445
- if (u.expiresAt === null || u.expiresAt > c) throw u.error;
470
+ if (u.expiresAt === null || u.expiresAt > s) throw u.error;
446
471
  this.store.delete(e);
447
472
  }
448
- const d = Promise.resolve().then(n).then((h) => {
449
- this.store.set(e, { status: "ready", value: h, expiresAt: $e(o) });
450
- }).catch((h) => {
473
+ const i = Promise.resolve().then(n).then((d) => {
474
+ this.store.set(e, { status: "ready", value: d, expiresAt: Le(c) });
475
+ }).catch((d) => {
451
476
  this.store.set(e, {
452
477
  status: "error",
453
- error: h,
454
- expiresAt: Ie(s)
478
+ error: d,
479
+ expiresAt: Ve(o)
455
480
  });
456
481
  });
457
- throw this.store.set(e, { status: "pending", promise: d, expiresAt: null }), this.evict(), d;
482
+ throw this.store.set(e, { status: "pending", promise: i, expiresAt: null }), this.evict(), i;
458
483
  }
459
484
  invalidate(e) {
460
485
  this.store.delete(e);
@@ -472,7 +497,7 @@ class De {
472
497
  */
473
498
  invalidatePathKey(e) {
474
499
  for (const n of this.store.keys())
475
- pe(n) === e && this.store.delete(n);
500
+ me(n) === e && this.store.delete(n);
476
501
  }
477
502
  /**
478
503
  * Drops every entry that reads from `reducer`, in any store.
@@ -486,219 +511,275 @@ class De {
486
511
  */
487
512
  invalidateReducer(e) {
488
513
  const n = `${e}::`;
489
- for (const o of this.store.keys())
490
- pe(o).split("||").some((s) => s.startsWith(n)) && this.store.delete(o);
514
+ for (const c of this.store.keys())
515
+ me(c).split("||").some((o) => o.startsWith(n)) && this.store.delete(c);
491
516
  }
492
517
  clear() {
493
518
  this.store.clear();
494
519
  }
495
520
  }
496
- const Y = new De(), fe = /* @__PURE__ */ new WeakMap();
497
- let Fe = 0;
498
- function Ae(r) {
499
- let e = fe.get(r);
500
- return e === void 0 && (e = `s${++Fe}`, fe.set(r, e)), e;
521
+ const W = new Je(), de = /* @__PURE__ */ new WeakMap();
522
+ let Ue = 0;
523
+ function we(r) {
524
+ let e = de.get(r);
525
+ return e === void 0 && (e = `s${++Ue}`, de.set(r, e)), e;
501
526
  }
502
- function pe(r) {
527
+ function me(r) {
503
528
  return r.slice(r.indexOf("::") + 2);
504
529
  }
505
- function re(r, e, n) {
506
- const o = Array.isArray(e) ? e.map(x).sort().join("|") : x(e);
507
- return n ? `${r}::${o}::${n}` : `${r}::${o}`;
508
- }
509
- function Me(r, e, n) {
510
- const o = r(), s = e.reducer, c = x(e.property), u = `${Ae(o)}::${re(s, c, n.key)}`, d = E(() => (i) => o.connect({ reducer: s, property: c }, () => {
511
- Y.invalidate(u), i();
512
- }), [o, s, c, u]), h = P(n);
513
- h.current = n;
514
- const _ = E(() => {
515
- const i = L(c);
530
+ function ee(r, e, n) {
531
+ const c = Array.isArray(e) ? e.map(N).sort().join("|") : N(e);
532
+ return n ? `${r}::${c}::${n}` : `${r}::${c}`;
533
+ }
534
+ function qe(r, e, n) {
535
+ const c = r(), o = e.reducer, s = N(e.property), u = `${we(c)}::${ee(o, s, n.key)}`, i = w(() => (l) => c.connect({ reducer: o, property: s }, () => {
536
+ W.invalidate(u), l();
537
+ }), [c, o, s, u]), d = _(n);
538
+ d.current = n;
539
+ const b = w(() => {
540
+ const l = B(s);
516
541
  return () => {
517
- const l = o.getState()[s], y = i ? l : U(l, c), m = h.current;
518
- return Y.read(u, () => m.load(y, l), m.staleTime ?? 0, m.errorTtlMs);
542
+ const p = c.getState()[o], E = l ? p : X(p, s), h = d.current;
543
+ return W.read(u, () => h.load(E, p), h.staleTime ?? 0, h.errorTtlMs);
519
544
  };
520
- }, [o, s, c, u]), p = E(() => {
521
- const i = L(c);
545
+ }, [c, o, s, u]), f = w(() => {
546
+ const l = B(s);
522
547
  return () => {
523
- const l = o.getState()[s];
524
- return i ? l : U(l, c);
548
+ const p = c.getState()[o];
549
+ return l ? p : X(p, s);
525
550
  };
526
- }, [o, s, c]);
527
- return I(d, _, p);
528
- }
529
- function ze(r, e, n) {
530
- const o = r(), s = E(
531
- () => e.map((p) => ({
532
- reducer: p.reducer,
533
- property: Array.isArray(p.property) ? p.property.map((i) => x(i)) : x(p.property)
551
+ }, [c, o, s]);
552
+ return J(i, b, f);
553
+ }
554
+ function Be(r, e, n) {
555
+ const c = r(), o = w(
556
+ () => e.map((f) => ({
557
+ reducer: f.reducer,
558
+ property: Array.isArray(f.property) ? f.property.map((l) => N(l)) : N(f.property)
534
559
  })),
535
560
  // `specs` is a fresh reference each render; keying the memo on its JSON
536
561
  // signature is intentional and already covers `specs`.
537
562
  // eslint-disable-next-line react-hooks/exhaustive-deps
538
563
  [JSON.stringify(e)]
539
- ), c = E(() => {
540
- const p = s.map((i) => re(i.reducer, i.property)).sort().join("||");
541
- return `${Ae(o)}::${n.key ? `${p}::${n.key}` : p}`;
542
- }, [o, s, n.key]), u = E(() => (p) => {
543
- const i = () => {
544
- Y.invalidate(c), p();
545
- }, v = s.map((l) => o.connect(l, i));
564
+ ), s = w(() => {
565
+ const f = o.map((l) => ee(l.reducer, l.property)).sort().join("||");
566
+ return `${we(c)}::${n.key ? `${f}::${n.key}` : f}`;
567
+ }, [c, o, n.key]), u = w(() => (f) => {
568
+ const l = () => {
569
+ W.invalidate(s), f();
570
+ }, y = o.map((p) => c.connect(p, l));
546
571
  return () => {
547
- for (const l of v) l();
572
+ for (const p of y) p();
548
573
  };
549
- }, [o, s, c]), d = P(n);
550
- d.current = n;
551
- const h = E(() => () => {
552
- const p = o.getState(), i = d.current;
553
- return Y.read(c, () => i.load(p), i.staleTime ?? 0, i.errorTtlMs);
554
- }, [o, c]);
555
- return I(u, h, () => {
556
- const p = d.current.load(o.getState());
557
- return p instanceof Promise ? void 0 : p;
574
+ }, [c, o, s]), i = _(n);
575
+ i.current = n;
576
+ const d = w(() => () => {
577
+ const f = c.getState(), l = i.current;
578
+ return W.read(s, () => l.load(f), l.staleTime ?? 0, l.errorTtlMs);
579
+ }, [c, s]);
580
+ return J(u, d, () => {
581
+ const f = i.current.load(c.getState());
582
+ return f instanceof Promise ? void 0 : f;
558
583
  });
559
584
  }
560
- function Xe(r, e, n) {
561
- Y.invalidatePathKey(re(r, e, n));
585
+ function Qe(r, e, n) {
586
+ W.invalidatePathKey(ee(r, e, n));
562
587
  }
563
- function He(r) {
564
- Y.invalidateReducer(r);
588
+ function er(r) {
589
+ W.invalidateReducer(r);
565
590
  }
566
- function Ze() {
567
- Y.clear();
591
+ function rr() {
592
+ W.clear();
568
593
  }
569
- function We(r) {
594
+ function Xe(r) {
570
595
  return {
571
- useSuspenseAtomicProp: (o, s) => Me(r, o, s),
572
- useSuspenseAtomicProps: (o, s) => ze(r, o, s)
596
+ useSuspenseAtomicProp: (c, o) => qe(r, c, o),
597
+ useSuspenseAtomicProps: (c, o) => Be(r, c, o)
573
598
  };
574
599
  }
575
- function Ge(r) {
600
+ function Pe(r) {
576
601
  function e() {
577
- const i = ve(r);
578
- if (!i)
602
+ const l = ke(r);
603
+ if (!l)
579
604
  throw new Error(
580
605
  "[yoltra] No store in context. Wrap your tree in <StoreProvider store={...}>, or use the hooks returned by createYoltra (which default to their own store)."
581
606
  );
582
- return i;
607
+ return l;
583
608
  }
584
609
  function n() {
585
610
  return e().emit;
586
611
  }
587
- function o(i, v = Object.is) {
588
- const l = e(), y = E(() => (g) => l.subscribe(g), [l]), m = V(() => i(l.getState()), v, [l]);
589
- return I(y, m, m);
612
+ function c(l, y = Object.is) {
613
+ const p = e(), E = w(() => (P) => p.subscribe(P), [p]), h = pe(() => l(p.getState()), y, [p]);
614
+ return J(E, h, h);
590
615
  }
591
- const c = (i, v, l) => {
592
- const y = e(), m = typeof i == "string", g = m ? i : i.reducer, j = m ? Oe(v) : i.property, w = m ? void 0 : v, R = E(() => ({ reducer: g, property: x(j) }), [g, j]), O = E(
593
- () => ($) => y.connect(
594
- { reducer: R.reducer, property: R.property },
595
- () => $()
616
+ const s = (l, y, p) => {
617
+ const E = e(), h = typeof l == "string", P = h ? l : l.reducer, T = h ? De(y) : l.property, R = h ? void 0 : y, A = w(() => ({ reducer: P, property: N(T) }), [P, T]), $ = w(
618
+ () => (I) => E.connect(
619
+ { reducer: A.reducer, property: A.property },
620
+ () => I()
596
621
  ),
597
- [y, R]
598
- ), D = L(R.property), F = V(
622
+ [E, A]
623
+ ), j = B(A.property), C = pe(
599
624
  () => {
600
- const A = y.getState()[R.reducer], N = D ? A : U(A, R.property);
601
- return w ? w(N) : N;
625
+ const Y = E.getState()[A.reducer], v = j ? Y : X(Y, A.property);
626
+ return R ? R(v) : v;
602
627
  },
603
- l ?? Object.is,
604
- [y, R]
628
+ p ?? Object.is,
629
+ [E, A]
605
630
  );
606
- return I(O, F, F);
607
- }, d = (i, v, l = Object.is) => {
608
- const y = e(), m = P(0), g = P(void 0), j = P(-1), w = P(!1), R = P(v);
609
- R.current = v;
610
- const O = P(l);
611
- O.current = l;
612
- const D = E(() => i.map((A) => ({
613
- reducer: A.reducer,
614
- property: Array.isArray(A.property) ? A.property.map((N) => x(N)) : x(A.property)
615
- })), [je(i)]), F = E(
616
- () => (A) => {
617
- const N = () => {
618
- m.current++, A();
619
- }, J = D.flatMap((T) => (Array.isArray(T.property) ? T.property : [T.property]).map((X) => y.connect({ reducer: T.reducer, property: X }, N)));
631
+ return J($, C, C);
632
+ }, i = (l, y, p = Object.is) => {
633
+ const E = e(), h = _(0), P = _(void 0), T = _(-1), R = _(!1), A = _(y);
634
+ A.current = y;
635
+ const $ = _(p);
636
+ $.current = p;
637
+ const j = w(() => l.map((v) => ({
638
+ reducer: v.reducer,
639
+ property: Array.isArray(v.property) ? v.property.map((O) => N(O)) : N(v.property)
640
+ })), [Ye(l)]), C = w(
641
+ () => (v) => {
642
+ const O = () => {
643
+ h.current++, v();
644
+ }, D = j.flatMap((x) => (Array.isArray(x.property) ? x.property : [x.property]).map((L) => E.connect({ reducer: x.reducer, property: L }, O)));
620
645
  return () => {
621
- for (const T of J) T();
646
+ for (const x of D) x();
622
647
  };
623
648
  },
624
- [y, D]
625
- ), $ = me(() => {
626
- if (j.current !== m.current || !w.current) {
627
- const A = R.current(y.getState());
628
- (!w.current || !O.current(g.current, A)) && (g.current = A, w.current = !0), j.current = m.current;
649
+ [E, j]
650
+ ), I = w(
651
+ () => j.flatMap(
652
+ (v) => (Array.isArray(v.property) ? v.property : [v.property]).map((O) => ({
653
+ reducer: v.reducer,
654
+ property: O
655
+ }))
656
+ ),
657
+ [j]
658
+ ), Y = ve(() => {
659
+ if (T.current !== h.current || !R.current) {
660
+ const v = We(E.getState(), I), O = process.env.NODE_ENV !== "production" ? Ae(v, I) : v, D = A.current(O);
661
+ (!R.current || !$.current(P.current, D)) && (P.current = D, R.current = !0), T.current = h.current;
629
662
  }
630
- return g.current;
631
- }, [y]);
632
- return I(F, $, $);
633
- }, h = (i, v, l, y = "committed") => {
634
- const m = e(), g = P(l);
635
- g.current = l, he(() => m.onEvent(
636
- i,
637
- v,
638
- (j, w, R, O) => {
639
- g.current(
663
+ return P.current;
664
+ }, [E, I]);
665
+ return J(C, Y, Y);
666
+ }, d = (l, y, p, E = "committed", h) => {
667
+ const P = e(), T = _(p);
668
+ T.current = p;
669
+ const R = h?.duringReplay === !0;
670
+ je(() => P.onEvent(
671
+ l,
672
+ y,
673
+ (A, $, j, C) => {
674
+ T.current(
675
+ A,
676
+ $,
640
677
  j,
641
- w,
642
- R,
643
- O
678
+ C
644
679
  );
645
680
  },
646
- y
647
- ), [m, i, v, y]);
648
- }, { useSuspenseAtomicProp: _, useSuspenseAtomicProps: p } = We(e);
681
+ E,
682
+ { duringReplay: R }
683
+ ), [P, l, y, E, R]);
684
+ }, { useSuspenseAtomicProp: b, useSuspenseAtomicProps: f } = Xe(e);
649
685
  return {
650
686
  useStore: e,
651
687
  useEmit: n,
652
- useSelector: o,
653
- useAtomicProp: c,
654
- useAtomicProps: d,
655
- useEvent: h,
656
- useSuspenseAtomicProp: _,
657
- useSuspenseAtomicProps: p,
658
- shallowEqual: Ne
688
+ useSelector: c,
689
+ useAtomicProp: s,
690
+ useAtomicProps: i,
691
+ useEvent: d,
692
+ useSuspenseAtomicProp: b,
693
+ useSuspenseAtomicProps: f,
694
+ shallowEqual: ze
659
695
  };
660
696
  }
661
- function Ke(r) {
662
- const e = Pe(r), n = de(e), o = Ge(n);
663
- return { store: e, StoreContext: n, StoreProvider: ({
664
- store: c,
697
+ let he = null;
698
+ function U() {
699
+ return he ??= Pe(
700
+ be
701
+ ), he;
702
+ }
703
+ function tr() {
704
+ return U().useStore();
705
+ }
706
+ function nr() {
707
+ return U().useEmit();
708
+ }
709
+ function or(r, e = Object.is) {
710
+ return U().useSelector(r, e);
711
+ }
712
+ function re(r, e, n = Object.is) {
713
+ return U().useAtomicProp(r, e, n);
714
+ }
715
+ function sr(r, e, n, c = "committed", o) {
716
+ U().useEvent(r, e, n, c, o);
717
+ }
718
+ function cr(r) {
719
+ const e = Oe(r), n = ye(e);
720
+ return Re(e, n);
721
+ }
722
+ function Re(r, e) {
723
+ const n = Pe(e), c = ({
724
+ store: s,
665
725
  children: u
666
- }) => /* @__PURE__ */ be.jsx(n.Provider, { value: c ?? e, children: u }), ...o };
726
+ }) => /* @__PURE__ */ Ee.jsx(e.Provider, { value: s ?? r, children: u }), o = () => Re(r, e);
727
+ return {
728
+ store: r,
729
+ StoreContext: e,
730
+ StoreProvider: c,
731
+ ...n,
732
+ withSlice: (s, u, i) => (r.registerSlice(s, u, i), o()),
733
+ withMiddleware: (s) => (r.registerMiddleware(s), o()),
734
+ withEffect: (s) => (r.registerEffect(s), o())
735
+ };
736
+ }
737
+ function ur(r, e, n, c) {
738
+ return r.withSlice(e, n, c);
739
+ }
740
+ function ir(r, e) {
741
+ return r.withMiddleware(e);
742
+ }
743
+ function ar(r, e) {
744
+ return r.withEffect(e);
667
745
  }
668
- function Qe(r, e) {
669
- return ee({
746
+ function lr(r, e) {
747
+ return re({
670
748
  reducer: r,
671
749
  property: e.idsPath
672
750
  });
673
751
  }
674
- function er(r, e, n) {
675
- return ee({
752
+ function fr(r, e, n) {
753
+ return re({
676
754
  reducer: r,
677
755
  property: e.pathTo(n)
678
756
  });
679
757
  }
680
- function rr(r, e, n, o) {
681
- return ee({
758
+ function pr(r, e, n, c) {
759
+ return re({
682
760
  reducer: r,
683
- property: e.pathTo(n, o)
761
+ property: e.pathTo(n, c)
684
762
  });
685
763
  }
686
764
  export {
687
- ye as StoreContext,
688
- Ve as StoreProvider,
689
- Ze as clearSuspenseCache,
690
- Ge as createHooks,
691
- Ke as createYoltra,
692
- Xe as invalidateAtomicProp,
693
- He as invalidateAtomicPropsByReducer,
694
- Ne as shallowEqual,
695
- Y as suspenseCache,
696
- qe as useEmit,
697
- er as useEntity,
698
- rr as useEntityField,
699
- Qe as useEntityIds,
700
- Be as useEvent,
701
- Je as useSelector,
702
- q as useStore
765
+ be as StoreContext,
766
+ Ke as StoreProvider,
767
+ rr as clearSuspenseCache,
768
+ Pe as createHooks,
769
+ cr as createYoltra,
770
+ Qe as invalidateAtomicProp,
771
+ er as invalidateAtomicPropsByReducer,
772
+ ze as shallowEqual,
773
+ W as suspenseCache,
774
+ nr as useEmit,
775
+ fr as useEntity,
776
+ pr as useEntityField,
777
+ lr as useEntityIds,
778
+ sr as useEvent,
779
+ or as useSelector,
780
+ tr as useStore,
781
+ ar as withEffect,
782
+ ir as withMiddleware,
783
+ ur as withSlice
703
784
  };
704
785
  //# sourceMappingURL=index.mjs.map