@yoltra/react 0.1.0 → 0.2.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,620 +1,650 @@
1
1
  /*!
2
- * @yoltra/react v0.1.0
2
+ * @yoltra/react v0.2.0
3
3
  * (c) 2026 Manu Ramirez <@pixerael>
4
4
  * License: MIT
5
5
  * Homepage: https://yoltra.dev
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree
6
9
  */
7
- var de = Object.defineProperty;
8
- var me = (t, r, n) => r in t ? de(t, r, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[r] = n;
9
- var te = (t, r, n) => me(t, typeof r != "symbol" ? r + "" : r, n);
10
- import be, { createContext as ye, useRef as N, useEffect as ce, useMemo as y, useSyncExternalStore as x, useContext as ue } from "react";
11
- const ae = ye(null);
12
- var W = { exports: {} }, D = {};
13
- var ne;
14
- function ve() {
15
- if (ne) return D;
16
- ne = 1;
17
- var t = /* @__PURE__ */ Symbol.for("react.transitional.element"), r = /* @__PURE__ */ Symbol.for("react.fragment");
18
- function n(c, o, s) {
10
+ var Re = Object.defineProperty;
11
+ var Ae = (t, e, n) => e in t ? Re(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
12
+ var ce = (t, e, n) => Ae(t, typeof e != "symbol" ? e + "" : e, n);
13
+ import Pe, { createContext as fe, useRef as v, useMemo as h, useCallback as Z, useEffect as pe, useSyncExternalStore as N, useContext as de } from "react";
14
+ import { createStore as ge } from "@yoltra/core";
15
+ const me = fe(null);
16
+ var G = { exports: {} }, W = {};
17
+ var ue;
18
+ function _e() {
19
+ if (ue) return W;
20
+ ue = 1;
21
+ var t = /* @__PURE__ */ Symbol.for("react.transitional.element"), e = /* @__PURE__ */ Symbol.for("react.fragment");
22
+ function n(o, s, c) {
19
23
  var p = null;
20
- if (s !== void 0 && (p = "" + s), o.key !== void 0 && (p = "" + o.key), "key" in o) {
21
- s = {};
22
- for (var u in o)
23
- u !== "key" && (s[u] = o[u]);
24
- } else s = o;
25
- return o = s.ref, {
24
+ if (c !== void 0 && (p = "" + c), s.key !== void 0 && (p = "" + s.key), "key" in s) {
25
+ c = {};
26
+ for (var m in s)
27
+ m !== "key" && (c[m] = s[m]);
28
+ } else c = s;
29
+ return s = c.ref, {
26
30
  $$typeof: t,
27
- type: c,
31
+ type: o,
28
32
  key: p,
29
- ref: o !== void 0 ? o : null,
30
- props: s
33
+ ref: s !== void 0 ? s : null,
34
+ props: c
31
35
  };
32
36
  }
33
- return D.Fragment = r, D.jsx = n, D.jsxs = n, D;
34
- }
35
- var M = {};
36
- var oe;
37
- function Se() {
38
- return oe || (oe = 1, process.env.NODE_ENV !== "production" && (function() {
39
- function t(e) {
40
- if (e == null) return null;
41
- if (typeof e == "function")
42
- return e.$$typeof === le ? null : e.displayName || e.name || null;
43
- if (typeof e == "string") return e;
44
- switch (e) {
45
- case A:
37
+ return W.Fragment = e, W.jsx = n, W.jsxs = n, W;
38
+ }
39
+ var z = {};
40
+ var ae;
41
+ function ke() {
42
+ return ae || (ae = 1, process.env.NODE_ENV !== "production" && (function() {
43
+ function t(r) {
44
+ if (r == null) return null;
45
+ if (typeof r == "function")
46
+ return r.$$typeof === K ? null : r.displayName || r.name || null;
47
+ if (typeof r == "string") return r;
48
+ switch (r) {
49
+ case E:
46
50
  return "Fragment";
47
- case T:
51
+ case g:
48
52
  return "Profiler";
49
- case P:
53
+ case S:
50
54
  return "StrictMode";
51
- case $:
55
+ case C:
52
56
  return "Suspense";
53
- case k:
57
+ case _:
54
58
  return "SuspenseList";
55
- case ie:
59
+ case j:
56
60
  return "Activity";
57
61
  }
58
- if (typeof e == "object")
59
- switch (typeof e.tag == "number" && console.error(
62
+ if (typeof r == "object")
63
+ switch (typeof r.tag == "number" && console.error(
60
64
  "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
61
- ), e.$$typeof) {
62
- case S:
65
+ ), r.$$typeof) {
66
+ case b:
63
67
  return "Portal";
64
- case _:
65
- return (e.displayName || "Context") + ".Provider";
66
- case j:
67
- return (e._context.displayName || "Context") + ".Consumer";
68
- case g:
69
- var i = e.render;
70
- return e = e.displayName, e || (e = i.displayName || i.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
71
- case H:
72
- return i = e.displayName || null, i !== null ? i : t(e.type) || "Memo";
73
- case F:
74
- i = e._payload, e = e._init;
68
+ case Y:
69
+ return (r.displayName || "Context") + ".Provider";
70
+ case w:
71
+ return (r._context.displayName || "Context") + ".Consumer";
72
+ case D:
73
+ var a = r.render;
74
+ return r = r.displayName, r || (r = a.displayName || a.name || "", r = r !== "" ? "ForwardRef(" + r + ")" : "ForwardRef"), r;
75
+ case x:
76
+ return a = r.displayName || null, a !== null ? a : t(r.type) || "Memo";
77
+ case V:
78
+ a = r._payload, r = r._init;
75
79
  try {
76
- return t(e(i));
80
+ return t(r(a));
77
81
  } catch {
78
82
  }
79
83
  }
80
84
  return null;
81
85
  }
82
- function r(e) {
83
- return "" + e;
86
+ function e(r) {
87
+ return "" + r;
84
88
  }
85
- function n(e) {
89
+ function n(r) {
86
90
  try {
87
- r(e);
88
- var i = !1;
91
+ e(r);
92
+ var a = !1;
89
93
  } catch {
90
- i = !0;
94
+ a = !0;
91
95
  }
92
- if (i) {
93
- i = console;
94
- var v = i.error, E = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
95
- return v.call(
96
- i,
96
+ if (a) {
97
+ a = console;
98
+ var y = a.error, R = typeof Symbol == "function" && Symbol.toStringTag && r[Symbol.toStringTag] || r.constructor.name || "Object";
99
+ return y.call(
100
+ a,
97
101
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
98
- E
99
- ), r(e);
102
+ R
103
+ ), e(r);
100
104
  }
101
105
  }
102
- function c(e) {
103
- if (e === A) return "<>";
104
- if (typeof e == "object" && e !== null && e.$$typeof === F)
106
+ function o(r) {
107
+ if (r === E) return "<>";
108
+ if (typeof r == "object" && r !== null && r.$$typeof === V)
105
109
  return "<...>";
106
110
  try {
107
- var i = t(e);
108
- return i ? "<" + i + ">" : "<...>";
111
+ var a = t(r);
112
+ return a ? "<" + a + ">" : "<...>";
109
113
  } catch {
110
114
  return "<...>";
111
115
  }
112
116
  }
113
- function o() {
114
- var e = L.A;
115
- return e === null ? null : e.getOwner();
116
- }
117
117
  function s() {
118
+ var r = M.A;
119
+ return r === null ? null : r.getOwner();
120
+ }
121
+ function c() {
118
122
  return Error("react-stack-top-frame");
119
123
  }
120
- function p(e) {
121
- if (q.call(e, "key")) {
122
- var i = Object.getOwnPropertyDescriptor(e, "key").get;
123
- if (i && i.isReactWarning) return !1;
124
+ function p(r) {
125
+ if (ee.call(r, "key")) {
126
+ var a = Object.getOwnPropertyDescriptor(r, "key").get;
127
+ if (a && a.isReactWarning) return !1;
124
128
  }
125
- return e.key !== void 0;
129
+ return r.key !== void 0;
126
130
  }
127
- function u(e, i) {
128
- function v() {
129
- Z || (Z = !0, console.error(
131
+ function m(r, a) {
132
+ function y() {
133
+ re || (re = !0, console.error(
130
134
  "%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)",
131
- i
135
+ a
132
136
  ));
133
137
  }
134
- v.isReactWarning = !0, Object.defineProperty(e, "key", {
135
- get: v,
138
+ y.isReactWarning = !0, Object.defineProperty(r, "key", {
139
+ get: y,
136
140
  configurable: !0
137
141
  });
138
142
  }
139
- function d() {
140
- var e = t(this.type);
141
- return Q[e] || (Q[e] = !0, console.error(
143
+ function P() {
144
+ var r = t(this.type);
145
+ return te[r] || (te[r] = !0, console.error(
142
146
  "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."
143
- )), e = this.props.ref, e !== void 0 ? e : null;
147
+ )), r = this.props.ref, r !== void 0 ? r : null;
144
148
  }
145
- function l(e, i, v, E, w, O, U, V) {
146
- return v = O.ref, e = {
147
- $$typeof: b,
148
- type: e,
149
- key: i,
150
- props: O,
151
- _owner: w
152
- }, (v !== void 0 ? v : null) !== null ? Object.defineProperty(e, "ref", {
149
+ function u(r, a, y, R, O, T, X, B) {
150
+ return y = T.ref, r = {
151
+ $$typeof: f,
152
+ type: r,
153
+ key: a,
154
+ props: T,
155
+ _owner: O
156
+ }, (y !== void 0 ? y : null) !== null ? Object.defineProperty(r, "ref", {
153
157
  enumerable: !1,
154
- get: d
155
- }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
158
+ get: P
159
+ }) : Object.defineProperty(r, "ref", { enumerable: !1, value: null }), r._store = {}, Object.defineProperty(r._store, "validated", {
156
160
  configurable: !1,
157
161
  enumerable: !1,
158
162
  writable: !0,
159
163
  value: 0
160
- }), Object.defineProperty(e, "_debugInfo", {
164
+ }), Object.defineProperty(r, "_debugInfo", {
161
165
  configurable: !1,
162
166
  enumerable: !1,
163
167
  writable: !0,
164
168
  value: null
165
- }), Object.defineProperty(e, "_debugStack", {
169
+ }), Object.defineProperty(r, "_debugStack", {
166
170
  configurable: !1,
167
171
  enumerable: !1,
168
172
  writable: !0,
169
- value: U
170
- }), Object.defineProperty(e, "_debugTask", {
173
+ value: X
174
+ }), Object.defineProperty(r, "_debugTask", {
171
175
  configurable: !1,
172
176
  enumerable: !1,
173
177
  writable: !0,
174
- value: V
175
- }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
178
+ value: B
179
+ }), Object.freeze && (Object.freeze(r.props), Object.freeze(r)), r;
176
180
  }
177
- function a(e, i, v, E, w, O, U, V) {
178
- var R = i.children;
179
- if (R !== void 0)
180
- if (E)
181
- if (fe(R)) {
182
- for (E = 0; E < R.length; E++)
183
- f(R[E]);
184
- Object.freeze && Object.freeze(R);
181
+ function i(r, a, y, R, O, T, X, B) {
182
+ var A = a.children;
183
+ if (A !== void 0)
184
+ if (R)
185
+ if (Se(A)) {
186
+ for (R = 0; R < A.length; R++)
187
+ d(A[R]);
188
+ Object.freeze && Object.freeze(A);
185
189
  } else
186
190
  console.error(
187
191
  "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
188
192
  );
189
- else f(R);
190
- if (q.call(i, "key")) {
191
- R = t(e);
192
- var Y = Object.keys(i).filter(function(pe) {
193
- return pe !== "key";
193
+ else d(A);
194
+ if (ee.call(a, "key")) {
195
+ A = t(r);
196
+ var F = Object.keys(a).filter(function(Ee) {
197
+ return Ee !== "key";
194
198
  });
195
- E = 0 < Y.length ? "{key: someKey, " + Y.join(": ..., ") + ": ...}" : "{key: someKey}", re[R + E] || (Y = 0 < Y.length ? "{" + Y.join(": ..., ") + ": ...}" : "{}", console.error(
199
+ R = 0 < F.length ? "{key: someKey, " + F.join(": ..., ") + ": ...}" : "{key: someKey}", se[A + R] || (F = 0 < F.length ? "{" + F.join(": ..., ") + ": ...}" : "{}", console.error(
196
200
  `A props object containing a "key" prop is being spread into JSX:
197
201
  let props = %s;
198
202
  <%s {...props} />
199
203
  React keys must be passed directly to JSX without using spread:
200
204
  let props = %s;
201
205
  <%s key={someKey} {...props} />`,
202
- E,
203
206
  R,
204
- Y,
205
- R
206
- ), re[R + E] = !0);
207
+ A,
208
+ F,
209
+ A
210
+ ), se[A + R] = !0);
207
211
  }
208
- if (R = null, v !== void 0 && (n(v), R = "" + v), p(i) && (n(i.key), R = "" + i.key), "key" in i) {
209
- v = {};
210
- for (var X in i)
211
- X !== "key" && (v[X] = i[X]);
212
- } else v = i;
213
- return R && u(
214
- v,
215
- typeof e == "function" ? e.displayName || e.name || "Unknown" : e
216
- ), l(
217
- e,
218
- R,
212
+ if (A = null, y !== void 0 && (n(y), A = "" + y), p(a) && (n(a.key), A = "" + a.key), "key" in a) {
213
+ y = {};
214
+ for (var H in a)
215
+ H !== "key" && (y[H] = a[H]);
216
+ } else y = a;
217
+ return A && m(
218
+ y,
219
+ typeof r == "function" ? r.displayName || r.name || "Unknown" : r
220
+ ), u(
221
+ r,
222
+ A,
223
+ T,
219
224
  O,
220
- w,
221
- o(),
222
- v,
223
- U,
224
- V
225
+ s(),
226
+ y,
227
+ X,
228
+ B
225
229
  );
226
230
  }
227
- function f(e) {
228
- typeof e == "object" && e !== null && e.$$typeof === b && e._store && (e._store.validated = 1);
231
+ function d(r) {
232
+ typeof r == "object" && r !== null && r.$$typeof === f && r._store && (r._store.validated = 1);
229
233
  }
230
- var m = be, b = /* @__PURE__ */ Symbol.for("react.transitional.element"), S = /* @__PURE__ */ Symbol.for("react.portal"), A = /* @__PURE__ */ Symbol.for("react.fragment"), P = /* @__PURE__ */ Symbol.for("react.strict_mode"), T = /* @__PURE__ */ Symbol.for("react.profiler"), j = /* @__PURE__ */ Symbol.for("react.consumer"), _ = /* @__PURE__ */ Symbol.for("react.context"), g = /* @__PURE__ */ Symbol.for("react.forward_ref"), $ = /* @__PURE__ */ Symbol.for("react.suspense"), k = /* @__PURE__ */ Symbol.for("react.suspense_list"), H = /* @__PURE__ */ Symbol.for("react.memo"), F = /* @__PURE__ */ Symbol.for("react.lazy"), ie = /* @__PURE__ */ Symbol.for("react.activity"), le = /* @__PURE__ */ Symbol.for("react.client.reference"), L = m.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, q = Object.prototype.hasOwnProperty, fe = Array.isArray, G = console.createTask ? console.createTask : function() {
234
+ var l = Pe, f = /* @__PURE__ */ Symbol.for("react.transitional.element"), b = /* @__PURE__ */ Symbol.for("react.portal"), E = /* @__PURE__ */ Symbol.for("react.fragment"), S = /* @__PURE__ */ Symbol.for("react.strict_mode"), g = /* @__PURE__ */ Symbol.for("react.profiler"), w = /* @__PURE__ */ Symbol.for("react.consumer"), Y = /* @__PURE__ */ Symbol.for("react.context"), D = /* @__PURE__ */ Symbol.for("react.forward_ref"), C = /* @__PURE__ */ Symbol.for("react.suspense"), _ = /* @__PURE__ */ Symbol.for("react.suspense_list"), x = /* @__PURE__ */ Symbol.for("react.memo"), V = /* @__PURE__ */ Symbol.for("react.lazy"), j = /* @__PURE__ */ Symbol.for("react.activity"), K = /* @__PURE__ */ Symbol.for("react.client.reference"), M = l.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, ee = Object.prototype.hasOwnProperty, Se = Array.isArray, q = console.createTask ? console.createTask : function() {
231
235
  return null;
232
236
  };
233
- m = {
234
- react_stack_bottom_frame: function(e) {
235
- return e();
237
+ l = {
238
+ react_stack_bottom_frame: function(r) {
239
+ return r();
236
240
  }
237
241
  };
238
- var Z, Q = {}, K = m.react_stack_bottom_frame.bind(
239
- m,
240
- s
241
- )(), ee = G(c(s)), re = {};
242
- M.Fragment = A, M.jsx = function(e, i, v, E, w) {
243
- var O = 1e4 > L.recentlyCreatedOwnerStacks++;
244
- return a(
245
- e,
246
- i,
247
- v,
242
+ var re, te = {}, ne = l.react_stack_bottom_frame.bind(
243
+ l,
244
+ c
245
+ )(), oe = q(o(c)), se = {};
246
+ z.Fragment = E, z.jsx = function(r, a, y, R, O) {
247
+ var T = 1e4 > M.recentlyCreatedOwnerStacks++;
248
+ return i(
249
+ r,
250
+ a,
251
+ y,
248
252
  !1,
249
- E,
250
- w,
251
- O ? Error("react-stack-top-frame") : K,
252
- O ? G(c(e)) : ee
253
+ R,
254
+ O,
255
+ T ? Error("react-stack-top-frame") : ne,
256
+ T ? q(o(r)) : oe
253
257
  );
254
- }, M.jsxs = function(e, i, v, E, w) {
255
- var O = 1e4 > L.recentlyCreatedOwnerStacks++;
256
- return a(
257
- e,
258
- i,
259
- v,
258
+ }, z.jsxs = function(r, a, y, R, O) {
259
+ var T = 1e4 > M.recentlyCreatedOwnerStacks++;
260
+ return i(
261
+ r,
262
+ a,
263
+ y,
260
264
  !0,
261
- E,
262
- w,
263
- O ? Error("react-stack-top-frame") : K,
264
- O ? G(c(e)) : ee
265
+ R,
266
+ O,
267
+ T ? Error("react-stack-top-frame") : ne,
268
+ T ? q(o(r)) : oe
265
269
  );
266
270
  };
267
- })()), M;
271
+ })()), z;
268
272
  }
269
- var se;
270
- function Ae() {
271
- return se || (se = 1, process.env.NODE_ENV === "production" ? W.exports = ve() : W.exports = Se()), W.exports;
273
+ var ie;
274
+ function we() {
275
+ return ie || (ie = 1, process.env.NODE_ENV === "production" ? G.exports = _e() : G.exports = ke()), G.exports;
272
276
  }
273
- var Ee = Ae();
274
- const we = ({ store: t, children: r }) => /* @__PURE__ */ Ee.jsx(ae.Provider, { value: t, children: r });
275
- function z(t) {
277
+ var ye = we();
278
+ const Ve = ({ store: t, children: e }) => /* @__PURE__ */ ye.jsx(me.Provider, { value: t, children: e }), le = /* @__PURE__ */ new Set();
279
+ function Te(t, e) {
280
+ process.env.NODE_ENV !== "production" && (le.has(t) || (le.add(t), console.warn(e)));
281
+ }
282
+ function L(t) {
276
283
  return t.includes("*");
277
284
  }
278
- function h(t) {
285
+ function k(t) {
279
286
  return t.replace(/^\./, "");
280
287
  }
281
- function Re(t) {
282
- return h(t).split(".").filter(Boolean);
288
+ function xe(t) {
289
+ return k(t).split(".").filter(Boolean);
290
+ }
291
+ function be(t) {
292
+ const e = (n) => `${n.length}:${n}`;
293
+ return t.map((n) => {
294
+ const o = Array.isArray(n.property) ? n.property : [n.property];
295
+ return e(n.reducer) + e(String(o.length)) + o.map(e).join("");
296
+ }).join("");
297
+ }
298
+ const ve = /* @__PURE__ */ Symbol("yoltra.pathSegments");
299
+ function he(t) {
300
+ const e = () => {
301
+ };
302
+ return new Proxy(e, {
303
+ get(n, o) {
304
+ if (o === ve) return t;
305
+ if (typeof o != "symbol")
306
+ return he([...t, String(o)]);
307
+ },
308
+ apply() {
309
+ throw new Error(
310
+ `[yoltra] A typed path accessor called a method (near "${t.join(".")}"). The accessor must be a plain member chain like \`p => p.items[0].title\` — it cannot call functions such as \`.map()\` or \`.toString()\`. Compute derived values in the component or a selector, or use the \`{ reducer, property }\` string form.`
311
+ );
312
+ }
313
+ });
314
+ }
315
+ function je(t) {
316
+ const e = t(he([])), n = e != null ? e[ve] : void 0, s = (Array.isArray(n) ? n : []).join(".");
317
+ return s === "" && Te(
318
+ "yoltra.toDottedPath.empty",
319
+ "[yoltra] A typed path accessor recorded no property access, so it will subscribe to the entire slice. 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 whole-slice or dynamic subscription, use the `{ reducer, property }` string form instead."
320
+ ), s;
283
321
  }
284
- function J(t, r) {
285
- if (!r) return t;
322
+ function U(t, e) {
323
+ if (!e) return t;
286
324
  let n = t;
287
- for (const c of Re(r)) {
325
+ for (const o of xe(e)) {
288
326
  if (n == null) return;
289
- n = n[c];
327
+ n = n[o];
290
328
  }
291
329
  return n;
292
330
  }
293
- function C() {
294
- const t = ue(ae);
331
+ function J(t, e, n) {
332
+ const o = v(t);
333
+ o.current = t;
334
+ const s = v(e);
335
+ s.current = e;
336
+ const c = h(
337
+ () => ({ has: !1, value: void 0 }),
338
+ // eslint-disable-next-line react-hooks/exhaustive-deps
339
+ n
340
+ );
341
+ return Z(() => {
342
+ const p = o.current();
343
+ return (!c.has || !s.current(c.value, p)) && (c.has = !0, c.value = p), c.value;
344
+ }, [c]);
345
+ }
346
+ function Oe(t, e) {
347
+ if (Object.is(t, e)) return !0;
348
+ if (!t || !e) return !1;
349
+ const n = Object.keys(t), o = Object.keys(e);
350
+ if (n.length !== o.length) return !1;
351
+ for (const s of n)
352
+ if (!Object.is(t[s], e[s])) return !1;
353
+ return !0;
354
+ }
355
+ function I() {
356
+ const t = de(me);
295
357
  if (!t) throw new Error("useStore must be used inside <StoreProvider>");
296
358
  return t;
297
359
  }
298
- function Ne() {
299
- return C().emit;
360
+ function Ge() {
361
+ return I().emit;
300
362
  }
301
- function Ce(t, r) {
302
- if (Object.is(t, r)) return !0;
303
- if (!t || !r) return !1;
304
- const n = Object.keys(t), c = Object.keys(r);
305
- if (n.length !== c.length) return !1;
306
- for (const o of n)
307
- if (!Object.is(t[o], r[o])) return !1;
308
- return !0;
363
+ function Le(t, e = Object.is) {
364
+ const n = I(), o = h(() => (c) => n.subscribe(c), [n]), s = J(
365
+ () => t(n.getState()),
366
+ e,
367
+ [n]
368
+ );
369
+ return N(o, s, s);
309
370
  }
310
- function Ie(t, r = Object.is) {
311
- const n = C(), c = y(() => (s) => n.subscribe(s), [n]), o = y(() => {
312
- let s = t(n.getState());
313
- return () => {
314
- const p = t(n.getState());
315
- return r(s, p) ? s : s = p;
316
- };
317
- }, [n, t, r]);
318
- return x(c, o, o);
319
- }
320
- function _e(t) {
321
- const r = C(), n = y(() => {
322
- const s = h(t.property);
323
- return { reducer: t.reducer, property: s };
324
- }, [t.reducer, t.property]), c = y(
325
- () => (s) => r.connect(
326
- { reducer: n.reducer, property: n.property },
327
- () => s()
371
+ function Ne(t, e, n = Object.is) {
372
+ const o = I(), s = h(() => {
373
+ const P = k(t.property);
374
+ return { reducer: t.reducer, property: P };
375
+ }, [t.reducer, t.property]), c = h(
376
+ () => (P) => o.connect(
377
+ { reducer: s.reducer, property: s.property },
378
+ () => P()
328
379
  ),
329
- [r, n]
330
- ), o = y(() => {
331
- const s = z(n.property), p = () => {
332
- const l = r.getState()[n.reducer];
333
- return s ? l : J(l, n.property);
334
- };
335
- let u = p();
336
- return () => {
337
- const d = p();
338
- return Object.is(u, d) ? u : u = d;
339
- };
340
- }, [r, n]);
341
- return x(c, o, o);
342
- }
343
- function he(t, r, n = Object.is) {
344
- const c = C(), o = y(() => {
345
- const u = h(t.property);
346
- return { reducer: t.reducer, property: u };
347
- }, [t.reducer, t.property]), s = y(
348
- () => (u) => c.connect(
349
- { reducer: o.reducer, property: o.property },
350
- () => u()
351
- ),
352
- [c, o]
353
- ), p = y(() => {
354
- const u = z(o.property), d = () => {
355
- const f = c.getState()[o.reducer], m = u ? f : J(f, o.property);
356
- return r ? r(m) : m;
357
- };
358
- let l = d();
359
- return () => {
360
- const a = d();
361
- return n(l, a) ? l : l = a;
362
- };
363
- }, [c, o, r, n]);
364
- return x(s, p, p);
365
- }
366
- function $e(t, r, n = Object.is) {
367
- return !r && !z(t.property) ? _e(t) : he(t, r, n);
368
- }
369
- function Ye(t, r, n = Object.is) {
370
- return Pe(t, r, n);
371
- }
372
- function Pe(t, r, n = Object.is) {
373
- const c = C(), o = N(0), s = N(void 0), p = N(-1), u = y(() => t.map((a) => ({
374
- reducer: a.reducer,
375
- property: Array.isArray(a.property) ? a.property.map((f) => h(f)) : h(a.property)
376
- })), [JSON.stringify(t)]), d = y(
377
- () => (a) => {
378
- const f = () => {
379
- o.current++, a();
380
- }, m = u.flatMap((b) => (Array.isArray(b.property) ? b.property : [b.property]).map((A) => c.connect({ reducer: b.reducer, property: A }, f)));
380
+ [o, s]
381
+ ), p = L(s.property), m = J(
382
+ () => {
383
+ const u = o.getState()[s.reducer], i = p ? u : U(u, s.property);
384
+ return e ? e(i) : i;
385
+ },
386
+ n,
387
+ [o, s]
388
+ );
389
+ return N(c, m, m);
390
+ }
391
+ function Ue(t, e, n = Object.is) {
392
+ return Ne(t, e, n);
393
+ }
394
+ function Je(t, e, n = Object.is) {
395
+ return Ce(t, e, n);
396
+ }
397
+ function Ce(t, e, n = Object.is) {
398
+ const o = I(), s = v(0), c = v(void 0), p = v(-1), m = v(!1), P = v(e);
399
+ P.current = e;
400
+ const u = v(n);
401
+ u.current = n;
402
+ const i = h(() => t.map((f) => ({
403
+ reducer: f.reducer,
404
+ property: Array.isArray(f.property) ? f.property.map((b) => k(b)) : k(f.property)
405
+ })), [be(t)]), d = h(
406
+ () => (f) => {
407
+ const b = () => {
408
+ s.current++, f();
409
+ }, E = i.flatMap((S) => (Array.isArray(S.property) ? S.property : [S.property]).map((w) => o.connect({ reducer: S.reducer, property: w }, b)));
381
410
  return () => {
382
- for (const b of m) b();
411
+ for (const S of E) S();
383
412
  };
384
413
  },
385
- [c, u]
386
- ), l = y(() => () => {
387
- if (p.current !== o.current) {
388
- const a = r(c.getState()), f = s.current;
389
- (f === void 0 || !n(f, a)) && (s.current = a), p.current = o.current;
414
+ [o, i]
415
+ ), l = Z(() => {
416
+ if (p.current !== s.current || !m.current) {
417
+ const f = P.current(o.getState());
418
+ (!m.current || !u.current(c.current, f)) && (c.current = f, m.current = !0), p.current = s.current;
390
419
  }
391
- return s.current;
392
- }, [c, r, n]);
393
- return x(d, l, l);
420
+ return c.current;
421
+ }, [o]);
422
+ return N(d, l, l);
394
423
  }
395
- function De(t, r, n, c = "committed") {
396
- const o = C(), s = N(n);
397
- s.current = n, ce(() => o.onEvent(
424
+ function qe(t, e, n, o = "committed") {
425
+ const s = I(), c = v(n);
426
+ c.current = n, pe(() => s.onEvent(
398
427
  t,
399
- r,
400
- (p, u, d, l) => {
401
- s.current(p, u, d, l);
428
+ e,
429
+ (p, m, P, u) => {
430
+ c.current(p, m, P, u);
402
431
  },
403
- c
404
- ), [o, t, r, c]);
432
+ o
433
+ ), [s, t, e, o]);
405
434
  }
406
- class ge {
435
+ function $e(t) {
436
+ return t == null || t <= 0 ? null : Date.now() + t;
437
+ }
438
+ class Ie {
407
439
  constructor() {
408
- te(this, "store", /* @__PURE__ */ new Map());
440
+ ce(this, "store", /* @__PURE__ */ new Map());
409
441
  }
410
- read(r, n, c) {
411
- const o = Date.now(), s = this.store.get(r);
412
- if (s && s.status === "ready" && (s.expiresAt == null || s.expiresAt > o))
413
- return s.value;
414
- if (s && s.status === "pending" && (s.expiresAt == null || s.expiresAt > o))
415
- throw s.promise;
416
- if (s && s.status === "error" && (s.expiresAt == null || s.expiresAt > o))
417
- throw s.error;
418
- const p = Promise.resolve().then(n).then((u) => {
419
- this.store.set(r, {
420
- status: "ready",
421
- value: u,
422
- expiresAt: c == null ? null : Date.now() + c
423
- });
424
- }).catch((u) => {
425
- this.store.set(r, {
426
- status: "error",
427
- error: u,
428
- expiresAt: c == null ? null : Date.now() + c
429
- });
442
+ read(e, n, o) {
443
+ const s = Date.now(), c = this.store.get(e);
444
+ if (c && c.status === "ready" && (c.expiresAt == null || c.expiresAt > s))
445
+ return c.value;
446
+ if (c && c.status === "pending")
447
+ throw c.promise;
448
+ if (c && c.status === "error")
449
+ throw c.error;
450
+ const p = Promise.resolve().then(n).then((m) => {
451
+ this.store.set(e, { status: "ready", value: m, expiresAt: $e(o) });
452
+ }).catch((m) => {
453
+ this.store.set(e, { status: "error", error: m, expiresAt: null });
430
454
  });
431
- throw this.store.set(r, {
432
- status: "pending",
433
- promise: p,
434
- expiresAt: c == null ? null : Date.now() + c
435
- }), p;
455
+ throw this.store.set(e, { status: "pending", promise: p, expiresAt: null }), p;
436
456
  }
437
- invalidate(r) {
438
- this.store.delete(r);
457
+ invalidate(e) {
458
+ this.store.delete(e);
439
459
  }
440
- invalidatePrefix(r) {
460
+ invalidatePrefix(e) {
441
461
  for (const n of this.store.keys())
442
- n.startsWith(r) && this.store.delete(n);
462
+ n.startsWith(e) && this.store.delete(n);
443
463
  }
444
464
  clear() {
445
465
  this.store.clear();
446
466
  }
447
467
  }
448
- const I = new ge();
449
- function B(t, r, n) {
450
- const c = Array.isArray(r) ? r.map(h).sort().join("|") : h(r);
451
- return n ? `${t}::${c}::${n}` : `${t}::${c}`;
468
+ const $ = new Ie();
469
+ function Q(t, e, n) {
470
+ const o = Array.isArray(e) ? e.map(k).sort().join("|") : k(e);
471
+ return n ? `${t}::${o}::${n}` : `${t}::${o}`;
452
472
  }
453
- function Me(t, r) {
454
- return ke(t, r);
473
+ function Xe(t, e) {
474
+ return Ye(t, e);
455
475
  }
456
- function ke(t, r) {
457
- const n = C(), c = t.reducer, o = h(t.property), s = B(c, o, r.key), p = y(() => (d) => n.connect({ reducer: c, property: o }, () => {
458
- I.invalidate(s), d();
459
- }), [n, c, o, s]), u = y(() => {
460
- const d = z(o);
476
+ function Ye(t, e) {
477
+ const n = I(), o = t.reducer, s = k(t.property), c = Q(o, s, e.key), p = h(() => (i) => n.connect({ reducer: o, property: s }, () => {
478
+ $.invalidate(c), i();
479
+ }), [n, o, s, c]), m = v(e);
480
+ m.current = e;
481
+ const P = h(() => {
482
+ const i = L(s);
461
483
  return () => {
462
- var m;
463
- const a = n.getState()[c], f = d ? a : J(a, o);
464
- return I.read(s, () => r.load(f, a), (m = r.staleTime) != null ? m : 0);
484
+ var E;
485
+ const l = n.getState()[o], f = i ? l : U(l, s), b = m.current;
486
+ return $.read(c, () => b.load(f, l), (E = b.staleTime) != null ? E : 0);
465
487
  };
466
- }, [n, c, o, s, r]);
467
- return x(p, u, u);
488
+ }, [n, o, s, c]), u = h(() => {
489
+ const i = L(s);
490
+ return () => {
491
+ const l = n.getState()[o];
492
+ return i ? l : U(l, s);
493
+ };
494
+ }, [n, o, s]);
495
+ return N(p, P, u);
468
496
  }
469
- function ze(t, r) {
470
- return Oe(t, r);
497
+ function Be(t, e) {
498
+ return De(t, e);
471
499
  }
472
- function Oe(t, r) {
473
- const n = C(), c = y(
500
+ function De(t, e) {
501
+ const n = I(), o = h(
474
502
  () => t.map((u) => ({
475
503
  reducer: u.reducer,
476
- property: Array.isArray(u.property) ? u.property.map((d) => h(d)) : h(u.property)
504
+ property: Array.isArray(u.property) ? u.property.map((i) => k(i)) : k(u.property)
477
505
  })),
506
+ // `specs` is a fresh reference each render; keying the memo on its JSON
507
+ // signature is intentional and already covers `specs`.
508
+ // eslint-disable-next-line react-hooks/exhaustive-deps
478
509
  [JSON.stringify(t)]
479
- ), o = y(() => {
480
- const u = c.map((d) => B(d.reducer, d.property)).sort().join("||");
481
- return r.key ? `${u}::${r.key}` : u;
482
- }, [c, r.key]), s = y(() => (u) => {
483
- const d = () => {
484
- I.invalidate(o), u();
485
- }, l = c.map((a) => n.connect(a, d));
510
+ ), s = h(() => {
511
+ const u = o.map((i) => Q(i.reducer, i.property)).sort().join("||");
512
+ return e.key ? `${u}::${e.key}` : u;
513
+ }, [o, e.key]), c = h(() => (u) => {
514
+ const i = () => {
515
+ $.invalidate(s), u();
516
+ }, d = o.map((l) => n.connect(l, i));
486
517
  return () => {
487
- for (const a of l) a();
518
+ for (const l of d) l();
488
519
  };
489
- }, [n, c, o]), p = y(() => () => {
520
+ }, [n, o, s]), p = v(e);
521
+ p.current = e;
522
+ const m = h(() => () => {
490
523
  var d;
491
- const u = n.getState();
492
- return I.read(o, () => r.load(u), (d = r.staleTime) != null ? d : 0);
493
- }, [n, o, r]);
494
- return x(s, p, p);
495
- }
496
- function Fe(t, r, n) {
497
- I.invalidate(B(t, r, n));
498
- }
499
- function We(t) {
500
- I.invalidatePrefix(`${t}::`);
501
- }
502
- function Je() {
503
- I.clear();
504
- }
505
- function xe(t, r) {
506
- if (Object.is(t, r)) return !0;
507
- if (!t || !r) return !1;
508
- const n = Object.keys(t), c = Object.keys(r);
509
- if (n.length !== c.length) return !1;
510
- for (const o of n)
511
- if (!Object.is(t[o], r[o])) return !1;
512
- return !0;
524
+ const u = n.getState(), i = p.current;
525
+ return $.read(s, () => i.load(u), (d = i.staleTime) != null ? d : 0);
526
+ }, [n, s]);
527
+ return N(c, m, () => {
528
+ const u = p.current.load(n.getState());
529
+ return u instanceof Promise ? void 0 : u;
530
+ });
531
+ }
532
+ function He(t, e, n) {
533
+ $.invalidate(Q(t, e, n));
513
534
  }
514
- function Le(t) {
515
- function r() {
516
- const l = ue(t);
517
- if (!l) throw new Error("useStore must be used inside <StoreProvider>");
518
- return l;
535
+ function Ze(t) {
536
+ $.invalidatePrefix(`${t}::`);
537
+ }
538
+ function Qe() {
539
+ $.clear();
540
+ }
541
+ function Fe(t) {
542
+ function e() {
543
+ const u = de(t);
544
+ if (!u)
545
+ throw new Error(
546
+ "[yoltra] No store in context. Wrap your tree in <StoreProvider store={...}>, or use the hooks returned by createYoltra (which default to their own store)."
547
+ );
548
+ return u;
519
549
  }
520
550
  function n() {
521
- return r().emit;
551
+ return e().emit;
522
552
  }
523
- function c(l, a = Object.is) {
524
- const f = r(), m = y(() => (S) => f.subscribe(S), [f]), b = y(() => {
525
- let S = l(f.getState());
526
- return () => {
527
- const A = l(f.getState());
528
- return a(S, A) ? S : S = A;
529
- };
530
- }, [f, l, a]);
531
- return x(m, b, b);
553
+ function o(u, i = Object.is) {
554
+ const d = e(), l = h(() => (b) => d.subscribe(b), [d]), f = J(() => u(d.getState()), i, [d]);
555
+ return N(l, f, f);
532
556
  }
533
557
  return {
534
- useStore: r,
558
+ useStore: e,
535
559
  useEmit: n,
536
- useSelector: c,
537
- useAtomicProp: (l, a, f) => {
538
- const m = r(), b = y(() => {
539
- const P = h(l.property);
540
- return { reducer: l.reducer, property: P };
541
- }, [l.reducer, l.property]), S = y(
542
- () => (P) => m.connect(
543
- { reducer: b.reducer, property: b.property },
544
- () => P()
560
+ useSelector: o,
561
+ useAtomicProp: (u, i, d) => {
562
+ const l = e(), f = typeof u == "string", b = f ? u : u.reducer, E = f ? je(i) : u.property, S = f ? void 0 : i, g = h(() => ({ reducer: b, property: k(E) }), [b, E]), w = h(
563
+ () => (C) => l.connect(
564
+ { reducer: g.reducer, property: g.property },
565
+ () => C()
545
566
  ),
546
- [m, b]
547
- ), A = y(() => {
548
- const P = z(b.property), T = () => {
549
- const $ = m.getState()[b.reducer], k = P ? $ : J($, b.property);
550
- return a ? a(k) : k;
551
- }, j = f != null ? f : Object.is;
552
- let _ = T();
553
- return () => {
554
- const g = T();
555
- return j(_, g) ? _ : _ = g;
556
- };
557
- }, [m, b, a, f]);
558
- return x(S, A, A);
567
+ [l, g]
568
+ ), Y = L(g.property), D = J(
569
+ () => {
570
+ const _ = l.getState()[g.reducer], x = Y ? _ : U(_, g.property);
571
+ return S ? S(x) : x;
572
+ },
573
+ d != null ? d : Object.is,
574
+ [l, g]
575
+ );
576
+ return N(w, D, D);
559
577
  },
560
- useAtomicProps: (l, a, f = Object.is) => {
561
- const m = r(), b = N(0), S = N(void 0), A = N(-1), P = y(() => l.map((_) => ({
578
+ useAtomicProps: (u, i, d = Object.is) => {
579
+ const l = e(), f = v(0), b = v(void 0), E = v(-1), S = v(!1), g = v(i);
580
+ g.current = i;
581
+ const w = v(d);
582
+ w.current = d;
583
+ const Y = h(() => u.map((_) => ({
562
584
  reducer: _.reducer,
563
- property: Array.isArray(_.property) ? _.property.map((g) => h(g)) : h(_.property)
564
- })), [JSON.stringify(l)]), T = y(
585
+ property: Array.isArray(_.property) ? _.property.map((x) => k(x)) : k(_.property)
586
+ })), [be(u)]), D = h(
565
587
  () => (_) => {
566
- const g = () => {
567
- b.current++, _();
568
- }, $ = P.flatMap((k) => (Array.isArray(k.property) ? k.property : [k.property]).map((F) => m.connect({ reducer: k.reducer, property: F }, g)));
588
+ const x = () => {
589
+ f.current++, _();
590
+ }, V = Y.flatMap((j) => (Array.isArray(j.property) ? j.property : [j.property]).map((M) => l.connect({ reducer: j.reducer, property: M }, x)));
569
591
  return () => {
570
- for (const k of $) k();
592
+ for (const j of V) j();
571
593
  };
572
594
  },
573
- [m, P]
574
- ), j = y(() => () => {
575
- if (A.current !== b.current) {
576
- const _ = a(m.getState()), g = S.current;
577
- (g === void 0 || !f(g, _)) && (S.current = _), A.current = b.current;
595
+ [l, Y]
596
+ ), C = Z(() => {
597
+ if (E.current !== f.current || !S.current) {
598
+ const _ = g.current(l.getState());
599
+ (!S.current || !w.current(b.current, _)) && (b.current = _, S.current = !0), E.current = f.current;
578
600
  }
579
- return S.current;
580
- }, [m, a, f]);
581
- return x(T, j, j);
601
+ return b.current;
602
+ }, [l]);
603
+ return N(D, C, C);
582
604
  },
583
- useEvent: (l, a, f, m = "committed") => {
584
- const b = r(), S = N(f);
585
- S.current = f, ce(() => b.onEvent(
586
- l,
587
- a,
588
- (A, P, T, j) => {
589
- S.current(
590
- A,
591
- P,
592
- T,
593
- j
605
+ useEvent: (u, i, d, l = "committed") => {
606
+ const f = e(), b = v(d);
607
+ b.current = d, pe(() => f.onEvent(
608
+ u,
609
+ i,
610
+ (E, S, g, w) => {
611
+ b.current(
612
+ E,
613
+ S,
614
+ g,
615
+ w
594
616
  );
595
617
  },
596
- m
597
- ), [b, l, a, m]);
618
+ l
619
+ ), [f, u, i, l]);
598
620
  },
599
- shallowEqual: xe
621
+ shallowEqual: Oe
600
622
  };
601
623
  }
624
+ function Ke(t) {
625
+ const e = ge(t), n = fe(e), o = Fe(n);
626
+ return { store: e, StoreContext: n, StoreProvider: ({
627
+ store: c,
628
+ children: p
629
+ }) => /* @__PURE__ */ ye.jsx(n.Provider, { value: c != null ? c : e, children: p }), ...o };
630
+ }
602
631
  export {
603
- ae as StoreContext,
604
- we as StoreProvider,
605
- Je as clearSuspenseCache,
606
- Le as createHooks,
607
- Fe as invalidateAtomicProp,
608
- We as invalidateAtomicPropsByReducer,
609
- Ce as shallowEqual,
610
- I as suspenseCache,
611
- $e as useAtomicProp,
612
- Ye as useAtomicProps,
613
- Ne as useEmit,
614
- De as useEvent,
615
- Ie as useSelector,
616
- C as useStore,
617
- Me as useSuspenseAtomicProp,
618
- ze as useSuspenseAtomicProps
632
+ me as StoreContext,
633
+ Ve as StoreProvider,
634
+ Qe as clearSuspenseCache,
635
+ Fe as createHooks,
636
+ Ke as createYoltra,
637
+ He as invalidateAtomicProp,
638
+ Ze as invalidateAtomicPropsByReducer,
639
+ Oe as shallowEqual,
640
+ $ as suspenseCache,
641
+ Ue as useAtomicProp,
642
+ Je as useAtomicProps,
643
+ Ge as useEmit,
644
+ qe as useEvent,
645
+ Le as useSelector,
646
+ I as useStore,
647
+ Xe as useSuspenseAtomicProp,
648
+ Be as useSuspenseAtomicProps
619
649
  };
620
650
  //# sourceMappingURL=index.mjs.map