@real-router/sources 0.8.3 → 0.8.4

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/cjs/index.js CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@real-router/route-utils`),t=require(`@real-router/core`),n=require(`@real-router/core/api`);var r=class{#e;#t=!1;#n=new Set;#r;#i;#a;constructor(e,t){this.#e=e,this.#r=t?.onFirstSubscribe,this.#i=t?.onLastUnsubscribe,this.#a=t?.onDestroy,this.subscribe=this.subscribe.bind(this),this.getSnapshot=this.getSnapshot.bind(this),this.destroy=this.destroy.bind(this)}subscribe(e){if(this.#t)return()=>{};let t=this.#n.size===0;return this.#n.add(e),t&&this.#r&&this.#r(),()=>{this.#n.delete(e),!this.#t&&this.#n.size===0&&this.#i&&this.#i()}}getSnapshot(){return this.#e}updateSnapshot(e){if(!this.#t){this.#e=e;for(let e of this.#n)try{e()}catch(e){queueMicrotask(()=>{throw e})}}}destroy(){this.#t||(this.#t=!0,this.#a?.(),this.#n.clear())}};function i(e){return(e?.context)?.url?.hash}function a(e,t){return e===t?e:e?.path!==t?.path||i(e)!==i(t)||o(t)?t:e}function o(e){return e?.transition?.reload===!0}function s(e){let t=null,n=()=>{let e=t;t=null,e?.()},i=new r({route:e.getState(),previousRoute:void 0},{onFirstSubscribe:()=>{t=e.subscribe(e=>{let t=i.getSnapshot(),n=a(t.route,e.route),r=a(t.previousRoute,e.previousRoute);(n!==t.route||r!==t.previousRoute)&&i.updateSnapshot({route:n,previousRoute:r})})},onLastUnsubscribe:n,onDestroy:n});return i}function c(e,t,n,r){let i=r?.route??t.getState(),o=r?.previousRoute,s=n===``||i!==void 0&&(i.name===n||i.name.startsWith(`${n}.`))?i:void 0;if(s===e.route&&o===e.previousRoute)return e;let c=a(e.route,s),l=a(e.previousRoute,o);return c===e.route&&l===e.previousRoute?e:{route:c,previousRoute:l}}function l(){}const u=new WeakMap;function d(e,t){let n=u.get(e);n||(n=new Map,u.set(e,n));let r=n.get(t);if(!r){let i=f(e,t);r={subscribe:i.subscribe,getSnapshot:i.getSnapshot,destroy:l},n.set(t,r)}return r}function f(e,t){let n=null,i=e.shouldUpdateNode(t),a=new r(c({route:void 0,previousRoute:void 0},e,t),{onFirstSubscribe:()=>{let r=c(a.getSnapshot(),e,t);Object.is(r,a.getSnapshot())||a.updateSnapshot(r),n=e.subscribe(n=>{if(!i(n.route,n.previousRoute))return;let r=c(a.getSnapshot(),e,t,n);Object.is(a.getSnapshot(),r)||a.updateSnapshot(r)})},onLastUnsubscribe:()=>{let e=n;n=null,e?.()}});return a}function p(e){return JSON.stringify(h(e,new Set))}function m(e,t){return e<t?-1:1}function h(e,t){if(typeof e!=`object`||!e||e instanceof Date)return e;if(e instanceof Map||e instanceof Set||e instanceof WeakMap||e instanceof WeakSet||e instanceof RegExp)throw TypeError(`canonicalJson: cannot serialize ${e.constructor.name} — non-enumerable own keys collapse to "{}" and would cause cache-key collisions. Pass primitive params (string | number | boolean) instead.`);if(t.has(e))throw TypeError(`canonicalJson: cannot serialize circular structure (cycle detected during traversal).`);t.add(e);try{if(Array.isArray(e))return e.map(e=>h(e,t));let n=Object.create(null),r=Object.keys(e).toSorted(m);for(let i of r)n[i]=h(e[i],t);return n}finally{t.delete(e)}}const g=Object.freeze({strict:!1,ignoreQueryParams:!0,hash:void 0});function _(e){return{strict:e?.strict??g.strict,ignoreQueryParams:e?.ignoreQueryParams??g.ignoreQueryParams,hash:e?.hash}}const v=new WeakMap;function y(e,t,n,r){let{strict:i,ignoreQueryParams:a,hash:o}=_(r),s;try{let e=o===void 0?``:`#${o}`;s=`${t}|${n===void 0?``:p(n)}|${String(i)}|${String(a)}|${e}`}catch{s=void 0}if(s===void 0)return x(e,t,n,i,a,o);let c=v.get(e);c||(c=new Map,v.set(e,c));let u=c.get(s);if(!u){let r=x(e,t,n,i,a,o);u={subscribe:r.subscribe,getSnapshot:r.getSnapshot,destroy:l},c.set(s,u)}return u}function b(e,t,n,r,a,o){return e.isActiveRoute(t,n,r,a)?o===void 0?!0:(i(e.getState())??``)===o:!1}function x(t,n,i,a,o,s){let c=b(t,n,i,a,o,s),l,u=new r(c,{onDestroy:()=>{l?.(),l=void 0}});return l=t.subscribe(r=>{let c=(0,e.areRoutesRelated)(n,r.route.name),l=r.previousRoute&&(0,e.areRoutesRelated)(n,r.previousRoute.name),d=s!==void 0&&(r.route.context?.url?.hashChanged??!1);if(!c&&!l&&!d)return;let f=c?b(t,n,i,a,o,s):!1;Object.is(u.getSnapshot(),f)||u.updateSnapshot(f)}),u}const S=Object.freeze({isTransitioning:!1,isLeaveApproved:!1,toRoute:null,fromRoute:null}),C=new WeakMap;function w(e,t,n){let r=a(e.toRoute,t),i=a(e.fromRoute,n??null);return e.isTransitioning&&r===e.toRoute&&i===e.fromRoute?null:{isTransitioning:!0,isLeaveApproved:!1,toRoute:r,fromRoute:i}}function T(e,t,n){let r=a(e.toRoute,t),i=a(e.fromRoute,n??null);return e.isLeaveApproved&&r===e.toRoute&&i===e.fromRoute?null:{isTransitioning:!0,isLeaveApproved:!0,toRoute:r,fromRoute:i}}function E(e){let i=new r(S,{onDestroy:()=>{for(let e of s)e()}}),a=(0,n.getPluginApi)(e),o=()=>{i.updateSnapshot(S)},s=[a.addEventListener(t.events.TRANSITION_START,(e,t)=>{let n=w(i.getSnapshot(),e,t);n!==null&&i.updateSnapshot(n)}),a.addEventListener(t.events.TRANSITION_LEAVE_APPROVE,(e,t)=>{let n=T(i.getSnapshot(),e,t);n!==null&&i.updateSnapshot(n)}),a.addEventListener(t.events.TRANSITION_SUCCESS,o),a.addEventListener(t.events.TRANSITION_ERROR,o),a.addEventListener(t.events.TRANSITION_CANCEL,o)];return i}function D(e){let t=C.get(e);if(!t){let n=E(e);t={subscribe:n.subscribe,getSnapshot:n.getSnapshot,destroy:l},C.set(e,t)}return t}const O={error:null,toRoute:null,fromRoute:null,version:0},k=new WeakMap;function A(e){let i=0,a=!1,o=new r(O,{onDestroy:()=>{for(let e of c)e()}}),s=(0,n.getPluginApi)(e),c=[s.addEventListener(t.events.TRANSITION_ERROR,(e,t,n)=>{i++,a=!0,o.updateSnapshot({error:n,toRoute:e??null,fromRoute:t??null,version:i})}),s.addEventListener(t.events.TRANSITION_SUCCESS,()=>{a&&(a=!1,o.updateSnapshot({error:null,toRoute:null,fromRoute:null,version:i}))})];return o}function j(e){let t=k.get(e);if(!t){let n=A(e);t={subscribe:n.subscribe,getSnapshot:n.getSnapshot,destroy:l},k.set(e,t)}return t}const M=new WeakMap;function N(e){let t=M.get(e);if(t)return t;let n=j(e),i=-1,a=null,o=()=>{let e=n.getSnapshot(),t=e.version<=i;return{error:t?null:e.error,toRoute:t?null:e.toRoute,fromRoute:t?null:e.fromRoute,version:e.version,resetError:c}},s=new r(o(),{onFirstSubscribe:()=>{a=n.subscribe(()=>{s.updateSnapshot(o())})},onLastUnsubscribe:()=>{u()}});function c(){let e=n.getSnapshot().version;e<=i||(i=e,s.updateSnapshot(o()))}function u(){let e=a;a=null,e?.()}let d={subscribe:s.subscribe,getSnapshot:s.getSnapshot,destroy:l};return M.set(e,d),d}const P=new WeakMap;function F(t){let n=P.get(t);if(n)return n;let r=new Map,i=new Map,a=null,o=e=>{let n=t.getState();return n?e===``?!0:n.name===e||n.name.startsWith(`${e}.`):!1},s=()=>{a=t.subscribe(t=>{for(let[n,a]of r){if(n!==``){let r=(0,e.areRoutesRelated)(n,t.route.name),i=t.previousRoute&&(0,e.areRoutesRelated)(n,t.previousRoute.name);if(!r&&!i)continue}let r=i.get(n)===!0,s=o(n);if(r!==s){i.set(n,s);for(let e of a)e()}}})},c=()=>{let e=a;a=null,e?.()},u={subscribe:(e,t)=>{let n=r.get(e);n||(n=new Set,r.set(e,n),i.set(e,o(e))),n.add(t),a||s();let l=!1;return()=>{l||(l=!0,n.delete(t),n.size===0&&(r.delete(e),i.delete(e)),r.size===0&&c())}},isActive:e=>{let t=i.get(e);return t===void 0?o(e):t},destroy:l};return P.set(t,u),u}exports.DEFAULT_ACTIVE_OPTIONS=g,exports.canonicalJson=p,exports.createActiveNameSelector=F,exports.createActiveRouteSource=y,exports.createDismissableError=N,exports.createErrorSource=A,exports.createRouteNodeSource=d,exports.createRouteSource=s,exports.createTransitionSource=E,exports.getErrorSource=j,exports.getTransitionSource=D,exports.normalizeActiveOptions=_;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@real-router/route-utils"),t=require("@real-router/core"),n=require("@real-router/core/api");var r=class{#e;#t=!1;#n=new Set;#r;#i;#a;constructor(e,t){this.#e=e,this.#r=t?.onFirstSubscribe,this.#i=t?.onLastUnsubscribe,this.#a=t?.onDestroy,this.subscribe=this.subscribe.bind(this),this.getSnapshot=this.getSnapshot.bind(this),this.destroy=this.destroy.bind(this)}subscribe(e){if(this.#t)return()=>{};let t=this.#n.size===0;return this.#n.add(e),t&&this.#r&&this.#r(),()=>{this.#n.delete(e),!this.#t&&this.#n.size===0&&this.#i&&this.#i()}}getSnapshot(){return this.#e}updateSnapshot(e){if(!this.#t){this.#e=e;for(let e of this.#n)try{e()}catch(e){queueMicrotask(()=>{throw e})}}}destroy(){this.#t||(this.#t=!0,this.#a?.(),this.#n.clear())}};function i(e){return(e?.context)?.url?.hash}function a(e,t){return e===t?e:e?.path!==t?.path||i(e)!==i(t)||o(t)?t:e}function o(e){return e?.transition?.reload===!0}function s(e){let t=null,n=()=>{let e=t;t=null,e?.()},i=new r({route:e.getState(),previousRoute:void 0},{onFirstSubscribe:()=>{t=e.subscribe(e=>{let t=i.getSnapshot(),n=a(t.route,e.route),r=a(t.previousRoute,e.previousRoute);(n!==t.route||r!==t.previousRoute)&&i.updateSnapshot({route:n,previousRoute:r})})},onLastUnsubscribe:n,onDestroy:n});return i}function c(e,t,n,r){let i=r?.route??t.getState(),o=r?.previousRoute,s=n===``||i!==void 0&&(i.name===n||i.name.startsWith(`${n}.`))?i:void 0;if(s===e.route&&o===e.previousRoute)return e;let c=a(e.route,s),l=a(e.previousRoute,o);return c===e.route&&l===e.previousRoute?e:{route:c,previousRoute:l}}function l(){}const u=new WeakMap;function d(e,t){let n=u.get(e);n||(n=new Map,u.set(e,n));let r=n.get(t);if(!r){let i=f(e,t);r={subscribe:i.subscribe,getSnapshot:i.getSnapshot,destroy:l},n.set(t,r)}return r}function f(e,t){let n=null,i=e.shouldUpdateNode(t),a=new r(c({route:void 0,previousRoute:void 0},e,t),{onFirstSubscribe:()=>{let r=c(a.getSnapshot(),e,t);Object.is(r,a.getSnapshot())||a.updateSnapshot(r),n=e.subscribe(n=>{if(!i(n.route,n.previousRoute))return;let r=c(a.getSnapshot(),e,t,n);Object.is(a.getSnapshot(),r)||a.updateSnapshot(r)})},onLastUnsubscribe:()=>{let e=n;n=null,e?.()}});return a}function p(e){return JSON.stringify(h(e,new Set))}function m(e,t){return e<t?-1:1}function h(e,t){if(typeof e!=`object`||!e||e instanceof Date)return e;if(e instanceof Map||e instanceof Set||e instanceof WeakMap||e instanceof WeakSet||e instanceof RegExp)throw TypeError(`canonicalJson: cannot serialize ${e.constructor.name} — non-enumerable own keys collapse to "{}" and would cause cache-key collisions. Pass primitive params (string | number | boolean) instead.`);if(t.has(e))throw TypeError(`canonicalJson: cannot serialize circular structure (cycle detected during traversal).`);t.add(e);try{if(Array.isArray(e))return e.map(e=>h(e,t));let n=Object.create(null),r=Object.keys(e).toSorted(m);for(let i of r)n[i]=h(e[i],t);return n}finally{t.delete(e)}}const g=Object.freeze({strict:!1,ignoreQueryParams:!0,hash:void 0});function _(e){return{strict:e?.strict??g.strict,ignoreQueryParams:e?.ignoreQueryParams??g.ignoreQueryParams,hash:e?.hash}}const v=new WeakMap;function y(e,t,n,r){let{strict:i,ignoreQueryParams:a,hash:o}=_(r),s;try{let e=o===void 0?``:`#${o}`;s=`${t}|${n===void 0?``:p(n)}|${String(i)}|${String(a)}|${e}`}catch{s=void 0}if(s===void 0)return x(e,t,n,i,a,o);let c=v.get(e);c||(c=new Map,v.set(e,c));let u=c.get(s);if(!u){let r=x(e,t,n,i,a,o);u={subscribe:r.subscribe,getSnapshot:r.getSnapshot,destroy:l},c.set(s,u)}return u}function b(e,t,n,r,a,o){return e.isActiveRoute(t,n,r,a)?o===void 0?!0:(i(e.getState())??``)===o:!1}function x(t,n,i,a,o,s){let c=b(t,n,i,a,o,s),l,u=new r(c,{onDestroy:()=>{l?.(),l=void 0}});return l=t.subscribe(r=>{let c=(0,e.areRoutesRelated)(n,r.route.name),l=r.previousRoute&&(0,e.areRoutesRelated)(n,r.previousRoute.name),d=s!==void 0&&(r.route.context?.url?.hashChanged??!1);if(!c&&!l&&!d)return;let f=c?b(t,n,i,a,o,s):!1;Object.is(u.getSnapshot(),f)||u.updateSnapshot(f)}),u}const S=Object.freeze({isTransitioning:!1,isLeaveApproved:!1,toRoute:null,fromRoute:null}),C=new WeakMap;function w(e,t,n){let r=a(e.toRoute,t),i=a(e.fromRoute,n??null);return e.isTransitioning&&r===e.toRoute&&i===e.fromRoute?null:{isTransitioning:!0,isLeaveApproved:!1,toRoute:r,fromRoute:i}}function T(e,t,n){let r=a(e.toRoute,t),i=a(e.fromRoute,n??null);return e.isLeaveApproved&&r===e.toRoute&&i===e.fromRoute?null:{isTransitioning:!0,isLeaveApproved:!0,toRoute:r,fromRoute:i}}function E(e){let i=new r(S,{onDestroy:()=>{for(let e of s)e()}}),a=(0,n.getPluginApi)(e),o=()=>{i.updateSnapshot(S)},s=[a.addEventListener(t.events.TRANSITION_START,(e,t)=>{let n=w(i.getSnapshot(),e,t);n!==null&&i.updateSnapshot(n)}),a.addEventListener(t.events.TRANSITION_LEAVE_APPROVE,(e,t)=>{let n=T(i.getSnapshot(),e,t);n!==null&&i.updateSnapshot(n)}),a.addEventListener(t.events.TRANSITION_SUCCESS,o),a.addEventListener(t.events.TRANSITION_ERROR,o),a.addEventListener(t.events.TRANSITION_CANCEL,o)];return i}function D(e){let t=C.get(e);if(!t){let n=E(e);t={subscribe:n.subscribe,getSnapshot:n.getSnapshot,destroy:l},C.set(e,t)}return t}const O={error:null,toRoute:null,fromRoute:null,version:0},k=new WeakMap;function A(e){let i=0,a=!1,o=new r(O,{onDestroy:()=>{for(let e of c)e()}}),s=(0,n.getPluginApi)(e),c=[s.addEventListener(t.events.TRANSITION_ERROR,(e,t,n)=>{i++,a=!0,o.updateSnapshot({error:n,toRoute:e??null,fromRoute:t??null,version:i})}),s.addEventListener(t.events.TRANSITION_SUCCESS,()=>{a&&(a=!1,o.updateSnapshot({error:null,toRoute:null,fromRoute:null,version:i}))})];return o}function j(e){let t=k.get(e);if(!t){let n=A(e);t={subscribe:n.subscribe,getSnapshot:n.getSnapshot,destroy:l},k.set(e,t)}return t}const M=new WeakMap;function N(e){let t=M.get(e);if(t)return t;let n=j(e),i=-1,a=null,o=()=>{let e=n.getSnapshot(),t=e.version<=i;return{error:t?null:e.error,toRoute:t?null:e.toRoute,fromRoute:t?null:e.fromRoute,version:e.version,resetError:c}},s=new r(o(),{onFirstSubscribe:()=>{a=n.subscribe(()=>{s.updateSnapshot(o())})},onLastUnsubscribe:()=>{u()}});function c(){let e=n.getSnapshot().version;e<=i||(i=e,s.updateSnapshot(o()))}function u(){let e=a;a=null,e?.()}let d={subscribe:s.subscribe,getSnapshot:s.getSnapshot,destroy:l};return M.set(e,d),d}const P=new WeakMap;function F(t){let n=P.get(t);if(n)return n;let r=new Map,i=new Map,a=null,o=e=>{let n=t.getState();return n?e===``?!0:n.name===e||n.name.startsWith(`${e}.`):!1},s=()=>{a=t.subscribe(t=>{for(let[n,a]of r){if(n!==``){let r=(0,e.areRoutesRelated)(n,t.route.name),i=t.previousRoute&&(0,e.areRoutesRelated)(n,t.previousRoute.name);if(!r&&!i)continue}let r=i.get(n)===!0,s=o(n);if(r!==s){i.set(n,s);for(let e of a)e()}}})},c=()=>{let e=a;a=null,e?.()},u={subscribe:(e,t)=>{let n=r.get(e);n||(n=new Set,r.set(e,n),i.set(e,o(e))),n.add(t),a||s();let l=!1;return()=>{l||(l=!0,n.delete(t),n.size===0&&(r.delete(e),i.delete(e)),r.size===0&&c())}},isActive:e=>{let t=i.get(e);return t===void 0?o(e):t},destroy:l};return P.set(t,u),u}exports.DEFAULT_ACTIVE_OPTIONS=g,exports.canonicalJson=p,exports.createActiveNameSelector=F,exports.createActiveRouteSource=y,exports.createDismissableError=N,exports.createErrorSource=A,exports.createRouteNodeSource=d,exports.createRouteSource=s,exports.createTransitionSource=E,exports.getErrorSource=j,exports.getTransitionSource=D,exports.normalizeActiveOptions=_;
2
2
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@real-router/sources",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "type": "commonjs",
5
5
  "description": "Framework-agnostic subscription layer for Real-Router state",
6
6
  "main": "./dist/cjs/index.js",
@@ -43,7 +43,7 @@
43
43
  "homepage": "https://github.com/greydragon888/real-router",
44
44
  "sideEffects": false,
45
45
  "dependencies": {
46
- "@real-router/core": "^0.54.1",
46
+ "@real-router/core": "^0.55.0",
47
47
  "@real-router/route-utils": "^0.2.2"
48
48
  },
49
49
  "devDependencies": {