@blumjs/router
Advanced tools
Comparing version 6.6.0 to 6.7.0
import P, { useEffect as et } from "react"; | ||
const J = { | ||
const se = { | ||
subscribers: [], | ||
@@ -29,3 +29,3 @@ historyPush(e) { | ||
addEventListener(e, t, r) { | ||
this.subscribers.push({ type: e, callback: t, index: r }), e === "changestate" && this._trigerEvent("init", !0); | ||
this.subscribers.some((n) => n.index === r) || (this.subscribers.push({ type: e, callback: t, index: r }), e === "changestate" && this._trigerEvent("init", !0)); | ||
}, | ||
@@ -65,3 +65,3 @@ removeEventListener(e) { | ||
addEventListener(e, t, r) { | ||
this.subscribers.push({ type: e, callback: t, index: r }), e === "changestate" && this._trigerEvent("init", !0); | ||
this.subscribers.some((n) => n.index === r) || (this.subscribers.push({ type: e, callback: t, index: r }), e === "changestate" && this._trigerEvent("init", !0)); | ||
}, | ||
@@ -97,5 +97,5 @@ removeEventListener(e) { | ||
function M({ node: e = [], from: t, source: r, parent: n = t || r, to: i, target: s, child: o = i || s, scope: p = {}, meta: g = {}, family: c = { type: "regular" }, regional: S } = {}) { | ||
let l = ie(n), d = ie(c.links), f = ie(c.owners), a = []; | ||
let l = oe(n), d = oe(c.links), f = oe(c.owners), a = []; | ||
k(e, (v) => v && T(a, v)); | ||
let u = { id: kt(), seq: a, next: ie(o), meta: g, scope: p, family: { type: c.type || "crosslink", links: d, owners: f } }; | ||
let u = { id: kt(), seq: a, next: oe(o), meta: g, scope: p, family: { type: c.type || "crosslink", links: d, owners: f } }; | ||
return k(d, (v) => T(fe(v), u)), k(f, (v) => T(de(v), u)), k(l, (v) => T(v.next, u)), S && z && at(Y(z), [u]), u; | ||
@@ -105,3 +105,3 @@ } | ||
let n, i = V, s = null, o = O; | ||
if (e.target && (t = e.params, r = e.defer, n = e.meta, i = "page" in e ? e.page : i, e.stack && (s = e.stack), o = oe(e) || o, e = e.target), o && O && o !== O && (O = null), Array.isArray(e)) | ||
if (e.target && (t = e.params, r = e.defer, n = e.meta, i = "page" in e ? e.page : i, e.stack && (s = e.stack), o = ne(e) || o, e = e.target), o && O && o !== O && (O = null), Array.isArray(e)) | ||
for (let a = 0; a < e.length; a++) | ||
@@ -111,10 +111,10 @@ D("pure", i, C(e[a]), s, t[a], o, n); | ||
D("pure", i, C(e), s, t, o, n); | ||
if (r && !ae) | ||
if (r && !ie) | ||
return; | ||
let p, g, c, S, l, d, f = { isRoot: ae, currentPage: V, scope: O, isWatch: we, isPure: se }; | ||
ae = 0; | ||
let p, g, c, S, l, d, f = { isRoot: ie, currentPage: V, scope: O, isWatch: we, isPure: ae }; | ||
ie = 0; | ||
e: | ||
for (; S = Nt(); ) { | ||
let { idx: a, stack: u, type: v } = S; | ||
c = u.node, V = l = u.page, O = oe(u), l ? d = l.reg : O && (d = O.reg); | ||
c = u.node, V = l = u.page, O = ne(u), l ? d = l.reg : O && (d = O.reg); | ||
let L = !!l, A = !!O, w = { fail: 0, scope: c.scope }; | ||
@@ -136,3 +136,3 @@ p = g = 0; | ||
switch (E.from) { | ||
case X: | ||
case Q: | ||
y = Y(u); | ||
@@ -157,3 +157,3 @@ break; | ||
switch (E.to) { | ||
case X: | ||
case Q: | ||
u.value = y; | ||
@@ -173,5 +173,5 @@ break; | ||
if (m.fn) { | ||
we = R(c, "op") === "watch", se = m.pure; | ||
we = R(c, "op") === "watch", ae = m.pure; | ||
let y = m.safe ? (0, m.fn)(Y(u), w.scope, u) : Wt(w, m.fn, u); | ||
m.filter ? g = !y : u.value = y, we = f.isWatch, se = f.isPure; | ||
m.filter ? g = !y : u.value = y, we = f.isWatch, ae = f.isPure; | ||
} | ||
@@ -182,3 +182,3 @@ } | ||
if (!p) { | ||
let h = Y(u), _ = oe(u); | ||
let h = Y(u), _ = ne(u); | ||
if (k(c.next, (m) => { | ||
@@ -195,3 +195,3 @@ D("child", l, m, u, h, _); | ||
} | ||
ae = f.isRoot, V = f.currentPage, O = oe(f); | ||
ie = f.isRoot, V = f.currentPage, O = ne(f); | ||
} | ||
@@ -216,3 +216,3 @@ function wt(e, t) { | ||
function x(e, t) { | ||
let r = te({ or: t, and: typeof e == "string" ? { name: e } : e }), n = (o, ...p) => (Z(!R(n, "derived"), "call of derived event", "createEvent"), Z(!se, "unit call from pure function", "operators like sample"), V ? ((g, c, S, l) => { | ||
let r = ee({ or: t, and: typeof e == "string" ? { name: e } : e }), n = (o, ...p) => (X(!R(n, "derived"), "call of derived event", "createEvent"), X(!ae, "unit call from pure function", "operators like sample"), V ? ((g, c, S, l) => { | ||
let d = V, f = null; | ||
@@ -225,3 +225,3 @@ if (c) | ||
return Ue(d), a; | ||
})(n, i, o, p) : n.create(o, p)), i = it(), s = Object.assign(n, { graphite: M({ meta: dt("event", n, r), regional: 1 }), create: (o) => (tt({ target: n, params: o, scope: O }), o), watch: (o) => ft(n, o), map: (o) => Ee(n, Q, o, [N()]), filter: (o) => Ee(n, "filter", o.fn ? o : o.fn, [N(Me, 1)]), filterMap: (o) => Ee(n, "filterMap", o, [N(), Ae((p) => !B(p), 1)]), prepend(o) { | ||
})(n, i, o, p) : n.create(o, p)), i = it(), s = Object.assign(n, { graphite: M({ meta: dt("event", n, r), regional: 1 }), create: (o) => (tt({ target: n, params: o, scope: O }), o), watch: (o) => ft(n, o), map: (o) => Ee(n, J, o, [N()]), filter: (o) => Ee(n, "filter", o.fn ? o : o.fn, [N(Me, 1)]), filterMap: (o) => Ee(n, "filterMap", o, [N(), Ae((p) => !B(p), 1)]), prepend(o) { | ||
let p = x("* → " + n.shortName, { parent: j(n) }); | ||
@@ -233,3 +233,3 @@ return F("eventPrepend", C(p)), $e(p, n, [N()], "prepend", o), jt(n, p), p; | ||
function ze(e, t, r, n) { | ||
return Pt(r, t, "first argument"), W(I(n), "second argument should be a function"), Z(!R(e, "derived"), `${t} in derived store`, `${t} in store created via createStore`), k(Array.isArray(r) ? r : [r], (i) => { | ||
return Pt(r, t, "first argument"), W(I(n), "second argument should be a function"), X(!R(e, "derived"), `${t} in derived store`, `${t} in store created via createStore`), k(Array.isArray(r) ? r : [r], (i) => { | ||
e.off(i), le(e).set(i, ct(pt(i, e, "on", Ct, n))); | ||
@@ -239,3 +239,3 @@ }), e; | ||
function rt(e, t) { | ||
let r = te(t), n = It(e), i = x({ named: "updates", derived: 1 }); | ||
let r = ee(t), n = It(e), i = x({ named: "updates", derived: 1 }); | ||
F("storeBase", n); | ||
@@ -256,7 +256,7 @@ let s = n.id, o = { subscribers: /* @__PURE__ */ new Map(), updates: i, defaultState: e, stateRef: n, getState() { | ||
let v, L; | ||
H(a) && (v = a, a = a.fn), Z(B(u), "second argument of store.map", "updateFilter"); | ||
H(a) && (v = a, a = a.fn), X(B(u), "second argument of store.map", "updateFilter"); | ||
let A = o.getState(); | ||
B(A) || (L = a(A, u)); | ||
let w = rt(L, { name: `${o.shortName} → *`, derived: 1, and: v }), h = pt(o, w, Q, He, a); | ||
return Bt(ue(w), { type: Q, fn: a, from: n }), ue(w).noInit = 1, F("storeMap", n, h), w; | ||
let w = rt(L, { name: `${o.shortName} → *`, derived: 1, and: v }), h = pt(o, w, J, He, a); | ||
return Bt(ue(w), { type: J, fn: a, from: n }), ue(w).noInit = 1, F("storeMap", n, h), w; | ||
}, watch(a, u) { | ||
@@ -269,9 +269,9 @@ if (!u || !Ce(a)) { | ||
} }, p = dt("store", o, r), g = o.defaultConfig.updateFilter; | ||
o.graphite = M({ scope: { state: n, fn: g }, node: [Ae((a, u, v) => (v.scope && !v.scope.reg[n.id] && (v.b = 1), a)), Dt(n), Ae((a, u, { a: v, b: L }) => !B(a) && (a !== v || L), 1), g && N(He, 1), pe({ from: X, target: n })], child: i, meta: p, regional: 1 }); | ||
o.graphite = M({ scope: { state: n, fn: g }, node: [Ae((a, u, v) => (v.scope && !v.scope.reg[n.id] && (v.b = 1), a)), Dt(n), Ae((a, u, { a: v, b: L }) => !B(a) && (a !== v || L), 1), g && N(He, 1), pe({ from: Q, target: n })], child: i, meta: p, regional: 1 }); | ||
let c = R(o, "serialize"), S = R(o, "derived"), l = c === "ignore", d = !c || l ? 0 : c, f = R(o, "sid"); | ||
return f && (l || We(o, "storeChange", 1), n.sid = f, d && (n.meta = { ...n == null ? void 0 : n.meta, serialize: d })), f || l || S || We(o, "warnSerialize", 1), W(S || !B(e), "current state can't be undefined, use null instead"), at(o, [i]), r != null && r.domain && r.domain.hooks.store(o), S || (o.reinit = x(), o.reset(o.reinit)), o; | ||
} | ||
let Et = typeof Symbol < "u" && Symbol.observable || "@@observable", Q = "map", X = "stack", C = (e) => e.graphite || e, fe = (e) => e.family.owners, de = (e) => e.family.links, ue = (e) => e.stateRef, Y = (e) => e.value, le = (e) => e.subscribers, j = (e) => e.parent, oe = (e) => e.scope, R = (e, t) => C(e).meta[t], We = (e, t, r) => C(e).meta[t] = r, Ot = (e) => e.compositeName, Ce = (e) => (I(e) || H(e)) && "kind" in e; | ||
const ne = (e) => (t) => Ce(t) && t.kind === e; | ||
let Te = ne("store"), bt = ne("event"), je = ne("effect"), nt = ne("domain"), Lt = ne("scope"); | ||
let Et = typeof Symbol < "u" && Symbol.observable || "@@observable", J = "map", Q = "stack", C = (e) => e.graphite || e, fe = (e) => e.family.owners, de = (e) => e.family.links, ue = (e) => e.stateRef, Y = (e) => e.value, le = (e) => e.subscribers, j = (e) => e.parent, ne = (e) => e.scope, R = (e, t) => C(e).meta[t], We = (e, t, r) => C(e).meta[t] = r, Ot = (e) => e.compositeName, Ce = (e) => (I(e) || H(e)) && "kind" in e; | ||
const re = (e) => (t) => Ce(t) && t.kind === e; | ||
let Te = re("store"), bt = re("event"), je = re("effect"), nt = re("domain"), Lt = re("scope"); | ||
var Rt = { __proto__: null, unit: Ce, store: Te, event: bt, effect: je, domain: nt, scope: Lt, attached: (e) => je(e) && R(e, "attached") == 1 }; | ||
@@ -281,3 +281,3 @@ let ye = (e, t) => { | ||
r !== -1 && e.splice(r, 1); | ||
}, T = (e, t) => e.push(t), Z = (e, t, r) => !e && console.error(`${t} is deprecated${r ? `, use ${r} instead` : ""}`); | ||
}, T = (e, t) => e.push(t), X = (e, t, r) => !e && console.error(`${t} is deprecated${r ? `, use ${r} instead` : ""}`); | ||
const De = () => { | ||
@@ -293,3 +293,3 @@ let e = 0; | ||
}); | ||
}, ie = (e = []) => (Array.isArray(e) ? e : [e]).flat().map(C), H = (e) => typeof e == "object" && e !== null, I = (e) => typeof e == "function", B = (e) => e === void 0, Vt = (e) => W(H(e) || I(e), "expect first argument be an object"); | ||
}, oe = (e = []) => (Array.isArray(e) ? e : [e]).flat().map(C), H = (e) => typeof e == "object" && e !== null, I = (e) => typeof e == "function", B = (e) => e === void 0, Vt = (e) => W(H(e) || I(e), "expect first argument be an object"); | ||
const Ge = (e, t, r, n) => W(!(!H(e) && !I(e) || !("family" in e) && !("graphite" in e)), `${t}: expect ${r} to be a unit (store, event or effect)${n}`); | ||
@@ -303,3 +303,3 @@ let Pt = (e, t, r) => { | ||
}; | ||
let Tt = 0, pe = ({ from: e = "store", store: t, target: r, to: n = r ? "store" : X, batch: i, priority: s }) => st("mov", { from: e, store: t, to: n, target: r }, s, i), ee = ({ fn: e, batch: t, priority: r, safe: n = 0, filter: i = 0, pure: s = 0 }) => st("compute", { fn: e, safe: n, filter: i, pure: s }, r, t), Ie = ({ fn: e }) => ee({ fn: e, priority: "effect" }), Ae = (e, t, r) => ee({ fn: e, safe: 1, filter: t, priority: r && "effect" }), Dt = (e, t, r) => pe({ store: e, to: t ? X : "a", priority: r && "sampler", batch: 1 }), N = (e = Me, t) => ee({ fn: e, pure: 1, filter: t }), Mt = { mov: pe, compute: ee, filter: ({ fn: e, pure: t }) => ee({ fn: e, filter: 1, pure: t }), run: Ie }, It = (e) => ({ id: ot(), current: e }), ut = ({ current: e }) => e, Bt = (e, t) => { | ||
let Tt = 0, pe = ({ from: e = "store", store: t, target: r, to: n = r ? "store" : Q, batch: i, priority: s }) => st("mov", { from: e, store: t, to: n, target: r }, s, i), Z = ({ fn: e, batch: t, priority: r, safe: n = 0, filter: i = 0, pure: s = 0 }) => st("compute", { fn: e, safe: n, filter: i, pure: s }, r, t), Ie = ({ fn: e }) => Z({ fn: e, priority: "effect" }), Ae = (e, t, r) => Z({ fn: e, safe: 1, filter: t, priority: r && "effect" }), Dt = (e, t, r) => pe({ store: e, to: t ? Q : "a", priority: r && "sampler", batch: 1 }), N = (e = Me, t) => Z({ fn: e, pure: 1, filter: t }), Mt = { mov: pe, compute: Z, filter: ({ fn: e, pure: t }) => Z({ fn: e, filter: 1, pure: t }), run: Ie }, It = (e) => ({ id: ot(), current: e }), ut = ({ current: e }) => e, Bt = (e, t) => { | ||
e.before || (e.before = []), T(e.before, t); | ||
@@ -353,3 +353,3 @@ }, $ = null; | ||
}, _e = /* @__PURE__ */ new Set(); | ||
let O, ae = 1, we = 0, se = 0, V = null, Ue = (e) => { | ||
let O, ie = 1, we = 0, ae = 0, V = null, Ue = (e) => { | ||
V = e; | ||
@@ -383,3 +383,3 @@ }; | ||
switch (d.type) { | ||
case Q: { | ||
case J: { | ||
let f = d.from; | ||
@@ -407,5 +407,5 @@ if (f || d.fn) { | ||
}; | ||
let te = (e, t = {}) => (H(e) && (te(e.or, t), _t(e, (r, n) => { | ||
let ee = (e, t = {}) => (H(e) && (ee(e.or, t), _t(e, (r, n) => { | ||
B(r) || n === "or" || n === "and" || (t[n] = r); | ||
}), te(e.and, t)), t); | ||
}), ee(e.and, t)), t); | ||
const qe = (e, t) => { | ||
@@ -438,4 +438,4 @@ ye(e.next, t), ye(fe(e), t), ye(de(e), t); | ||
}, dt = (e, t, r) => { | ||
let n = te(r), i = e === "domain", s = At(), { sid: o = null, named: p = null, domain: g = null, parent: c = g } = n, S = p || n.name || (i ? "" : s), l = wt(S, c), d = { op: t.kind = e, name: t.shortName = S, sid: t.sid = xt(o), named: p, unitId: t.id = s, serialize: n.serialize, derived: n.derived, config: n }; | ||
return t.parent = c, t.compositeName = l, t.defaultConfig = n, t.thru = (f) => (Z(0, "thru", "js pipe"), f(t)), t.getType = () => l.fullName, !i && (t.subscribe = (f) => (Vt(f), t.watch(I(f) ? f : (a) => f.next && f.next(a))), t[Et] = () => t), d; | ||
let n = ee(r), i = e === "domain", s = At(), { sid: o = null, named: p = null, domain: g = null, parent: c = g } = n, S = p || n.name || (i ? "" : s), l = wt(S, c), d = { op: t.kind = e, name: t.shortName = S, sid: t.sid = xt(o), named: p, unitId: t.id = s, serialize: n.serialize, derived: n.derived, config: n }; | ||
return t.parent = c, t.compositeName = l, t.defaultConfig = n, t.thru = (f) => (X(0, "thru", "js pipe"), f(t)), t.getType = () => l.fullName, !i && (t.subscribe = (f) => (Vt(f), t.watch(I(f) ? f : (a) => f.next && f.next(a))), t[Et] = () => t), d; | ||
}; | ||
@@ -449,3 +449,3 @@ const Ee = (e, t, r, n) => { | ||
let s = ue(t), o = pe({ store: s, to: "a", priority: "read" }); | ||
r === Q && (o.data.softRead = 1); | ||
r === J && (o.data.softRead = 1); | ||
let p = [o, N(n)]; | ||
@@ -495,8 +495,8 @@ return F("storeOnMap", s, p, Te(e) && ue(e)), $e(e, t, p, r, i); | ||
} | ||
}, Oe = {}, re = {}, Yt = { | ||
}, Oe = {}, te = {}, Yt = { | ||
get exports() { | ||
return re; | ||
return te; | ||
}, | ||
set exports(e) { | ||
re = e; | ||
te = e; | ||
} | ||
@@ -633,3 +633,3 @@ }, be = {}; | ||
})(Yt); | ||
const Xt = /* @__PURE__ */ qt(re); | ||
const Xt = /* @__PURE__ */ qt(te); | ||
/** | ||
@@ -649,3 +649,3 @@ * @license React | ||
Qe = 1; | ||
var e = P, t = re; | ||
var e = P, t = te; | ||
function r(c, S) { | ||
@@ -704,3 +704,3 @@ return c === S && (c !== 0 || 1 / c === 1 / S) || c !== c && S !== S; | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error()); | ||
var e = P, t = re; | ||
var e = P, t = te; | ||
function r(S, l) { | ||
@@ -789,11 +789,13 @@ return S === l && (S !== 0 || 1 / S === 1 / l) || S !== S && l !== l; | ||
}, [e, r, t]); | ||
}, Ze = (e, t, r, n) => { | ||
et(() => (J.addEventListener(e, t, r), () => J.removeEventListener(r)), [...n]); | ||
}, Ze = (e, t, r) => { | ||
et(() => { | ||
se.addEventListener(e, t, r); | ||
}, [e, t, r]); | ||
}, mr = (e, ...t) => { | ||
const { activeView: r, activePanel: n, activeModal: i, activePopout: s, isRouteInit: o } = lr(); | ||
Ze("init", (p) => { | ||
console.log("[blum]: initialized", p), o || J.historyPush(e); | ||
}, 1, [o]), ur("popstate", async () => { | ||
console.log("[blum]: initialized", p), o || se.historyPush(e); | ||
}, 1), ur("popstate", async () => { | ||
o && (await (async () => { | ||
J.fireChangeStateEvent(); | ||
se.fireChangeStateEvent(); | ||
const { view: g, panel: c, modal: S, popout: l } = window.history.state ?? { | ||
@@ -820,4 +822,4 @@ view: void 0, | ||
} | ||
}, 2, [o]); | ||
}, lr = () => or(Ut), Sr = (e) => e, gr = (e, t) => (r, n) => ["view", "panel", "modal", "popout"].some((s) => r[s] === e && r[s] !== n[s]) && window.isBackFromBrowser ? (t && t(r, n), J.historyPush(r), !1) : !0; | ||
}, 2); | ||
}, lr = () => or(Ut), Sr = (e) => e, gr = (e, t) => (r, n) => ["view", "panel", "modal", "popout"].some((s) => r[s] === e && r[s] !== n[s]) && window.isBackFromBrowser ? (t && t(r, n), se.historyPush(r), !1) : !0; | ||
export { | ||
@@ -829,3 +831,3 @@ ht as _setActiveModal, | ||
fr as back, | ||
J as blumRouter, | ||
se as blumRouter, | ||
gr as createDisableBackBrowserRouteMiddleware, | ||
@@ -832,0 +834,0 @@ Sr as createRouteMiddleware, |
import { BlumRouterEventMap } from "./blum-router"; | ||
export declare const useEventListener: <K extends keyof WindowEventMap>(eventListen: K, callback: (e: WindowEventMap[K]) => void, eventKey?: string) => void; | ||
export declare const useBlumEventListener: <K extends keyof BlumRouterEventMap>(eventListen: K, callback: (payload: BlumRouterEventMap[K]) => void, index: number, deps: any[]) => void; | ||
export declare const useBlumEventListener: <K extends keyof BlumRouterEventMap>(eventListen: K, callback: (payload: BlumRouterEventMap[K]) => void, index: number) => void; |
{ | ||
"name": "@blumjs/router", | ||
"version": "6.6.0", | ||
"version": "6.7.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "exports": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
60762
1021