@react-motion-router/stack 1.1.6 → 1.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/build/Stack.d.ts +2 -1
- package/build/index.js +1 -1
- package/package.json +1 -1
package/build/Stack.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import Navigation from './Navigation';
|
|
|
4
4
|
export declare namespace Stack {
|
|
5
5
|
export interface ScreenComponentProps<T extends {
|
|
6
6
|
[key: string]: any;
|
|
7
|
-
} = {}> extends ScreenComponentBaseProps<T, Navigation> {
|
|
7
|
+
} = {}> extends ScreenComponentBaseProps<ScreenProps, T, Navigation> {
|
|
8
8
|
}
|
|
9
9
|
type Presentation = "default" | "dialog" | "modal";
|
|
10
10
|
interface ScreenProps extends ScreenBaseProps {
|
|
@@ -17,6 +17,7 @@ export declare namespace Stack {
|
|
|
17
17
|
export class Screen extends ScreenBase<ScreenProps, ScreenState> {
|
|
18
18
|
constructor(props: ScreenProps);
|
|
19
19
|
onEnter: () => void;
|
|
20
|
+
onExit(): void;
|
|
20
21
|
onExited: () => void;
|
|
21
22
|
}
|
|
22
23
|
export {};
|
package/build/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as t from"@react-motion-router/core";var i={d:(t,e)=>{for(var a in e)i.o(e,a)&&!i.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:e[a]})},o:(t,i)=>Object.prototype.hasOwnProperty.call(t,i)},e={};i.d(e,{Ay:()=>o,W_:()=>n,F0:()=>r,Kq:()=>s});const a=(t=>{var e={};return i.d(e,t),e})({DEFAULT_ANIMATION:()=>t.DEFAULT_ANIMATION,HistoryBase:()=>t.HistoryBase,NavigationBase:()=>t.NavigationBase,RouterBase:()=>t.RouterBase,RouterData:()=>t.RouterData,ScreenBase:()=>t.ScreenBase,concatenateURL:()=>t.concatenateURL,searchParamsFromObject:()=>t.searchParamsFromObject});var s;!function(t){class i extends a.ScreenBase{constructor(t){var i,e;super(t),this.onEnter=()=>{var t,i;if(super.onEnter(),this.animationProviderRef instanceof HTMLDialogElement&&!1===this.animationProviderRef.open){const e=null===(t=this.context)||void 0===t?void 0:t.navigation;"modal"===(null===(i=this.props.config)||void 0===i?void 0:i.presentation)?this.animationProviderRef.showModal():this.animationProviderRef.show(),this.animationProviderRef.style.maxHeight="unset",this.animationProviderRef.style.maxWidth="unset",this.animationProviderRef.style.width="max-content",this.animationProviderRef.style.height="max-content",this.ref&&(this.ref.style.width="max-content",this.ref.style.height="max-content"),this.animationProviderRef.addEventListener("close",(function(t){"screen-exit"!==this.returnValue&&(this.style.display="block",null==e||e.goBack())}),{once:!0}),this.animationProviderRef.addEventListener("click",(function(t){const i=this.getBoundingClientRect();i.top<=t.clientY&&t.clientY<=i.top+i.height&&i.left<=t.clientX&&t.clientX<=i.left+i.width||null==e||e.goBack()}),{once:!0})}},this.onExited=()=>{super.onExited(),this.animationProviderRef instanceof HTMLDialogElement&&this.animationProviderRef.close("screen-exit")},"dialog"!==(null===(i=t.config)||void 0===i?void 0:i.presentation)&&"modal"!==(null===(e=t.config)||void 0===e?void 0:e.presentation)||(this.elementType="dialog")}}t.Screen=i}(s||(s={}));class n extends a.NavigationBase{constructor(t,i,e,a,s=!1,n=null){super(t,i,s,n),this.isInternalBack=!1,this._finished=new Promise((()=>{})),this.onPopState=t=>{if(t.preventDefault(),this.isInternalBack)return void(this.isInternalBack=!1);const i=window.location.pathname.replace(this.history.baseURL.pathname,"")||"/";i===this.history.previous?this.implicitBack():this.implicitNavigate(i)},this._history=e,this._animationLayerData=a}navigate(t,i,e={}){var s;const{replace:n,hash:o}=e,r=(0,a.searchParamsFromObject)(i||{},this.paramsSerializer||null);this._disableBrowserRouting?this._history.implicitPush(t,Boolean(n)):this._history.push(t,r,o||"",Boolean(n));const h=new AbortController;h.signal.addEventListener("abort",this.onNavigateAbort.bind(this),{once:!0}),null===(s=e.signal)||void 0===s||s.addEventListener("abort",this.onNavigateAbort.bind(this),{once:!0}),this._finished=this.createFinishedPromise(h);const c=this.createNavigateEvent(t,i,Boolean(n),h);return this.dispatchEvent&&this.dispatchEvent(c),this._currentParams=i||{},this._finished}implicitNavigate(t,i){this._history.implicitPush(t);const e=new AbortController;this._finished=this.createFinishedPromise(e);const a=this.createNavigateEvent(t,i,!1,e);return this.dispatchEvent&&this.dispatchEvent(a),this._currentParams=i||{},this._finished}implicitBack(){this._history.implicitBack();const t=new AbortController;this._finished=this.createFinishedPromise(t);let i=this.createBackEvent(t);return this.dispatchEvent&&this.dispatchEvent(i),this._finished}goBack(t={}){var i,e;this.isInternalBack=!0;const a=new AbortController;if(a.signal.addEventListener("abort",this.onBackAbort.bind(this),{once:!0}),null===(i=t.signal)||void 0===i||i.addEventListener("abort",this.onBackAbort.bind(this),{once:!0}),this._finished=this.createFinishedPromise(a),1===this._history.length){if(null===this.parent)return void window.history.back();this.parent.goBack()}else{let t=this.createBackEvent(a);if(this._disableBrowserRouting)this._history.implicitBack();else if(this.history.state.get("routerId")!==this.routerId){let t=0,i=this;for(;i;)i.disableBrowserRouting||(i===this?t+=1:i.history.length>1&&(t+=i.history.length)),i=null===(e=i.routerData.childRouterData)||void 0===e?void 0:e.navigation;window.history.go(-t),this._history.implicitBack()}else this._history.back();this.dispatchEvent&&this.dispatchEvent(t)}return this._finished}createBackEvent(t){return new CustomEvent("go-back",{bubbles:!0,detail:{routerId:this.routerId,signal:t.signal,finished:this._finished}})}createNavigateEvent(t,i,e,a){return new CustomEvent("navigate",{bubbles:!0,detail:{routerId:this.routerId,route:t,routeParams:i,replace:e,signal:a.signal,finished:this._finished}})}createFinishedPromise(t){return new Promise((async(i,e)=>{try{await this._animationLayerData.finished,i()}catch(i){t.abort(i),e(i)}}))}onNavigateAbort(){this._animationLayerData.cancel(),this.goBack()}onBackAbort(){this._animationLayerData.cancel(),this.history.next&&this.navigate(this.history.next)}assign(t){(t=new URL(t,window.location.origin)).origin===location.origin?this.navigate(t.pathname):location.assign(t)}replace(t){(t=new URL(t,window.location.origin)).origin===location.origin?this.navigate(t.pathname,{},{hash:t.hash,replace:!0}):location.replace(t)}get finished(){return this._finished}get parent(){var t,i;return null!==(i=null===(t=this.routerData.parentRouterData)||void 0===t?void 0:t.navigation)&&void 0!==i?i:null}get location(){const{location:t}=window,i=(0,a.concatenateURL)(this._history.current,this.history.baseURL);return{ancestorOrigins:t.ancestorOrigins,assign:this.assign.bind(this),hash:t.hash,host:t.host,hostname:t.hostname,href:i.href,origin:t.origin,pathname:i.pathname,port:t.port,protocol:t.protocol,reload(){t.reload()},replace:this.replace.bind(this),search:(0,a.searchParamsFromObject)(this._currentParams,this.paramsSerializer||null)}}}class o extends a.HistoryBase{constructor(t,i,e,a){var s;super(t,e,a),this._next=null;const n=window.location.pathname.replace(this.baseURL.pathname,"")||"/",r=window.location.search;if(e){this.defaultRoute=e;const t=null===(s=this.state.get(this.baseURL.pathname))||void 0===s?void 0:s.stack;this.defaultRoute===n||(null==t?void 0:t.length)||(this.replaceState({},"",o.getURL(this.defaultRoute,this.baseURL)),this.pushState({},"",o.getURL(n,this.baseURL,r)),this._stack.length||(this._stack.push(this.defaultRoute),this._stack.push(n)))}this._stack.length||this._stack.push(n||"/")}push(t,i="",e="",a=!1){const s=o.getURL(t,this.baseURL);s.hash=e||s.hash,s.search=i||s.search,t=s.pathname.replace(this.baseURL.pathname,""),this.next=null,a?(this._stack.pop(),this._stack.push(t),this.replaceState({stack:this._stack},"",s)):(this._stack.push(t),this.pushState({stack:this._stack},"",s))}implicitPush(t,i=!1){this.next=null,i?(this._stack.pop(),this._stack.push(t)):this._stack.push(t)}back(){return this.next=this._stack.pop()||null,window.history.back(),this.previous}implicitBack(){return this.next=this._stack.pop()||null,this.previous}canGoBack(){return this.stack.length>1}set next(t){this._next=t}get current(){return this._stack.at(-1)||"/"}get next(){let{_next:t}=this;return t||null}get previous(){return this._stack.length>1&&this._stack.at(-2)||null}get stack(){return this._stack}}class r extends a.RouterBase{constructor(t){super(t),this.onGestureNavigationStart=()=>{this._routerData.gestureNavigating=!0,this.setState({gestureNavigating:!0})},this.onGestureNavigationEnd=()=>{this._routerData.gestureNavigating=!1,this.setState({implicitBack:!0,gestureNavigating:!1},(()=>{this.navigation.goBack(),this.setState({backNavigating:!1}),this._routerData.backNavigating=!1}))},this.onAnimationEnd=()=>{this.state.backNavigating&&(this._routerData.backNavigating=!1,this.setState({backNavigating:!1}))},this.onBackListener=t=>{if(t.detail.routerId!==this.id)return;let i=this.navigation.location.pathname;this.config.disableBrowserRouting||(this._routerData.currentPath=i,this.setState({currentPath:i})),this.config.disableBrowserRouting&&(this._routerData.currentPath=i,this.setState({currentPath:i}),this.state.implicitBack&&this.setState({implicitBack:!1})),this.state.backNavigating||(this.state.implicitBack?this.setState({implicitBack:!1}):(this.setState({backNavigating:!0},(()=>{this.animationLayerData.finished.then(this.onAnimationEnd.bind(this))})),this._routerData.backNavigating=!0))},this.onNavigateListener=t=>{var i,e;if(t.detail.routerId!==this.id)return;const a=t.detail.route;if(this._routerData.currentPath=a,t.detail.routeParams){const s=this.state.routesData,n=this.state.routesData.get(a);s.set(a,{preloaded:null!==(i=null==n?void 0:n.preloaded)&&void 0!==i&&i,setParams:null!==(e=null==n?void 0:n.setParams)&&void 0!==e?e:()=>{},params:t.detail.routeParams}),this._routerData.routesData=s,this.setState({routesData:s},(()=>{this.setState({currentPath:a})}))}else this.setState({currentPath:a})},this._routerData=new a.RouterData(this),this.config.animation||(this.config.animation=a.DEFAULT_ANIMATION),"in"in this.config.animation?this._routerData.animation={in:this.config.animation.in,out:this.config.animation.out||this.config.animation.in}:this._routerData.animation={in:this.config.animation,out:this.config.animation}}componentDidMount(){var t;super.componentDidMount(),this._routerData.navigation=new n(this.id,this._routerData,new o(this.id,Boolean(this.props.config.disableBrowserRouting),null!==(t=this.props.config.defaultRoute)&&void 0!==t?t:null,this.baseURL),this.animationLayerData,this.props.config.disableBrowserRouting,this.props.config.defaultRoute),this.initialise(this.navigation)}get navigation(){return this._routerData.navigation}}var h=e.Ay,c=e.W_,l=e.F0,u=e.Kq;export{h as History,c as Navigation,l as Router,u as Stack};
|
|
1
|
+
import*as t from"@react-motion-router/core";var i={d:(t,e)=>{for(var a in e)i.o(e,a)&&!i.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:e[a]})},o:(t,i)=>Object.prototype.hasOwnProperty.call(t,i)},e={};i.d(e,{Ay:()=>r,W_:()=>o,F0:()=>h,Kq:()=>n});const a=(t=>{var e={};return i.d(e,t),e})({DEFAULT_ANIMATION:()=>t.DEFAULT_ANIMATION,HistoryBase:()=>t.HistoryBase,NavigationBase:()=>t.NavigationBase,RouterBase:()=>t.RouterBase,RouterData:()=>t.RouterData,ScreenBase:()=>t.ScreenBase,concatenateURL:()=>t.concatenateURL,matchRoute:()=>t.matchRoute,searchParamsFromObject:()=>t.searchParamsFromObject}),s=require("react");var n;!function(t){class i extends a.ScreenBase{constructor(t){var i,e;super(t),this.onEnter=()=>{var t,i;if(super.onEnter(),this.animationProviderRef instanceof HTMLDialogElement&&!1===this.animationProviderRef.open){const e=null===(t=this.context)||void 0===t?void 0:t.navigation;"modal"===(null===(i=this.props.config)||void 0===i?void 0:i.presentation)?this.animationProviderRef.showModal():this.animationProviderRef.show(),this.animationProviderRef.style.maxHeight="unset",this.animationProviderRef.style.maxWidth="unset",this.animationProviderRef.style.width="max-content",this.animationProviderRef.style.height="max-content",this.ref&&(this.ref.style.width="max-content",this.ref.style.height="max-content"),this.animationProviderRef.addEventListener("close",(function(t){"screen-exit"!==this.returnValue&&(this.style.display="block",null==e||e.goBack())}),{once:!0}),this.animationProviderRef.addEventListener("click",(function(t){const i=this.getBoundingClientRect();i.top<=t.clientY&&t.clientY<=i.top+i.height&&i.left<=t.clientX&&t.clientX<=i.left+i.width||null==e||e.goBack()}),{once:!0})}},this.onExited=()=>{super.onExited(),this.animationProviderRef instanceof HTMLDialogElement&&this.animationProviderRef.close("screen-exit")},"dialog"!==(null===(i=t.config)||void 0===i?void 0:i.presentation)&&"modal"!==(null===(e=t.config)||void 0===e?void 0:e.presentation)||(this.elementType="dialog")}onExit(){var t,i,e,n;const o=null===(t=this.context)||void 0===t?void 0:t.navigation.history.current,r=s.Children.toArray(null===(i=this.context)||void 0===i?void 0:i.routes).find((t=>(0,s.isValidElement)(t)&&(0,a.matchRoute)(t.props.path,o)));"modal"!==(null===(e=null==r?void 0:r.props.config)||void 0===e?void 0:e.presentation)&&"dialog"!==(null===(n=null==r?void 0:r.props.config)||void 0===n?void 0:n.presentation)||(this.setState({shouldKeepAlive:!0}),this.setConfig({keepAlive:!0}))}}t.Screen=i}(n||(n={}));class o extends a.NavigationBase{constructor(t,i,e,a,s=!1,n=null){super(t,i,s,n),this.isInternalBack=!1,this._finished=new Promise((()=>{})),this.onPopState=t=>{if(t.preventDefault(),this.isInternalBack)return void(this.isInternalBack=!1);const i=window.location.pathname.replace(this.history.baseURL.pathname,"")||"/";i===this.history.previous?this.implicitBack():this.implicitNavigate(i)},this._history=e,this._animationLayerData=a}navigate(t,i,e={}){var s;const{replace:n,hash:o}=e,r=(0,a.searchParamsFromObject)(i||{},this.paramsSerializer||null);this._disableBrowserRouting?this._history.implicitPush(t,Boolean(n)):this._history.push(t,r,o||"",Boolean(n));const h=new AbortController;h.signal.addEventListener("abort",this.onNavigateAbort.bind(this),{once:!0}),null===(s=e.signal)||void 0===s||s.addEventListener("abort",this.onNavigateAbort.bind(this),{once:!0}),this._finished=this.createFinishedPromise(h);const c=this.createNavigateEvent(t,i,Boolean(n),h);return this.dispatchEvent&&this.dispatchEvent(c),this._currentParams=i||{},this._finished}implicitNavigate(t,i){this._history.implicitPush(t);const e=new AbortController;this._finished=this.createFinishedPromise(e);const a=this.createNavigateEvent(t,i,!1,e);return this.dispatchEvent&&this.dispatchEvent(a),this._currentParams=i||{},this._finished}implicitBack(){this._history.implicitBack();const t=new AbortController;this._finished=this.createFinishedPromise(t);let i=this.createBackEvent(t);return this.dispatchEvent&&this.dispatchEvent(i),this._finished}goBack(t={}){var i,e;this.isInternalBack=!0;const a=new AbortController;if(a.signal.addEventListener("abort",this.onBackAbort.bind(this),{once:!0}),null===(i=t.signal)||void 0===i||i.addEventListener("abort",this.onBackAbort.bind(this),{once:!0}),this._finished=this.createFinishedPromise(a),1===this._history.length){if(null===this.parent)return void window.history.back();this.parent.goBack()}else{let t=this.createBackEvent(a);if(this._disableBrowserRouting)this._history.implicitBack();else if(this.history.state.get("routerId")!==this.routerId){let t=0,i=this;for(;i;)i.disableBrowserRouting||(i===this?t+=1:i.history.length>1&&(t+=i.history.length)),i=null===(e=i.routerData.childRouterData)||void 0===e?void 0:e.navigation;window.history.go(-t),this._history.implicitBack()}else this._history.back();this.dispatchEvent&&this.dispatchEvent(t)}return this._finished}createBackEvent(t){return new CustomEvent("go-back",{bubbles:!0,detail:{routerId:this.routerId,signal:t.signal,finished:this._finished}})}createNavigateEvent(t,i,e,a){return new CustomEvent("navigate",{bubbles:!0,detail:{routerId:this.routerId,route:t,routeParams:i,replace:e,signal:a.signal,finished:this._finished}})}createFinishedPromise(t){return new Promise((async(i,e)=>{try{await this._animationLayerData.finished,i()}catch(i){t.abort(i),e(i)}}))}onNavigateAbort(){this._animationLayerData.cancel(),this.goBack()}onBackAbort(){this._animationLayerData.cancel(),this.history.next&&this.navigate(this.history.next)}assign(t){(t=new URL(t,window.location.origin)).origin===location.origin?this.navigate(t.pathname):location.assign(t)}replace(t){(t=new URL(t,window.location.origin)).origin===location.origin?this.navigate(t.pathname,{},{hash:t.hash,replace:!0}):location.replace(t)}get finished(){return this._finished}get parent(){var t,i;return null!==(i=null===(t=this.routerData.parentRouterData)||void 0===t?void 0:t.navigation)&&void 0!==i?i:null}get location(){const{location:t}=window,i=(0,a.concatenateURL)(this._history.current,this.history.baseURL);return{ancestorOrigins:t.ancestorOrigins,assign:this.assign.bind(this),hash:t.hash,host:t.host,hostname:t.hostname,href:i.href,origin:t.origin,pathname:i.pathname,port:t.port,protocol:t.protocol,reload(){t.reload()},replace:this.replace.bind(this),search:(0,a.searchParamsFromObject)(this._currentParams,this.paramsSerializer||null)}}}class r extends a.HistoryBase{constructor(t,i,e,a){var s;super(t,e,a),this._next=null;const n=window.location.pathname.replace(this.baseURL.pathname,"")||"/",o=window.location.search;if(e){this.defaultRoute=e;const t=null===(s=this.state.get(this.baseURL.pathname))||void 0===s?void 0:s.stack;this.defaultRoute===n||(null==t?void 0:t.length)||(this.replaceState({},"",r.getURL(this.defaultRoute,this.baseURL)),this.pushState({},"",r.getURL(n,this.baseURL,o)),this._stack.length||(this._stack.push(this.defaultRoute),this._stack.push(n)))}this._stack.length||this._stack.push(n||"/")}push(t,i="",e="",a=!1){const s=r.getURL(t,this.baseURL);s.hash=e||s.hash,s.search=i||s.search,t=s.pathname.replace(this.baseURL.pathname,""),this.next=null,a?(this._stack.pop(),this._stack.push(t),this.replaceState({stack:this._stack},"",s)):(this._stack.push(t),this.pushState({stack:this._stack},"",s))}implicitPush(t,i=!1){this.next=null,i?(this._stack.pop(),this._stack.push(t)):this._stack.push(t)}back(){return this.next=this._stack.pop()||null,window.history.back(),this.previous}implicitBack(){return this.next=this._stack.pop()||null,this.previous}canGoBack(){return this.stack.length>1}set next(t){this._next=t}get current(){return this._stack.at(-1)||"/"}get next(){let{_next:t}=this;return t||null}get previous(){return this._stack.length>1&&this._stack.at(-2)||null}get stack(){return this._stack}}class h extends a.RouterBase{constructor(t){super(t),this.onGestureNavigationStart=()=>{this._routerData.gestureNavigating=!0,this.setState({gestureNavigating:!0})},this.onGestureNavigationEnd=()=>{this._routerData.gestureNavigating=!1,this.setState({implicitBack:!0,gestureNavigating:!1},(()=>{this.navigation.goBack(),this.setState({backNavigating:!1}),this._routerData.backNavigating=!1}))},this.onAnimationEnd=()=>{this.state.backNavigating&&(this._routerData.backNavigating=!1,this.setState({backNavigating:!1}))},this.onBackListener=t=>{if(t.detail.routerId!==this.id)return;let i=this.navigation.location.pathname;this.config.disableBrowserRouting||(this._routerData.currentPath=i,this.setState({currentPath:i})),this.config.disableBrowserRouting&&(this._routerData.currentPath=i,this.setState({currentPath:i}),this.state.implicitBack&&this.setState({implicitBack:!1})),this.state.backNavigating||(this.state.implicitBack?this.setState({implicitBack:!1}):(this.setState({backNavigating:!0},(()=>{this.animationLayerData.finished.then(this.onAnimationEnd.bind(this))})),this._routerData.backNavigating=!0))},this.onNavigateListener=t=>{var i,e,a,s,n;if(t.detail.routerId!==this.id)return;const o=t.detail.route;if(this._routerData.currentPath=o,t.detail.routeParams){const r=this.state.routesData,h=this.state.routesData.get(o);r.set(o,{focused:null!==(i=null==h?void 0:h.focused)&&void 0!==i&&i,preloaded:null!==(e=null==h?void 0:h.preloaded)&&void 0!==e&&e,setParams:null!==(a=null==h?void 0:h.setParams)&&void 0!==a?a:()=>{},params:t.detail.routeParams,config:null!==(s=null==h?void 0:h.config)&&void 0!==s?s:{},setConfig:null!==(n=null==h?void 0:h.setConfig)&&void 0!==n?n:()=>{}}),this._routerData.routesData=r,this.setState({routesData:r},(()=>{this.setState({currentPath:o})}))}else this.setState({currentPath:o})},this._routerData=new a.RouterData(this),this.config.animation||(this.config.animation=a.DEFAULT_ANIMATION),"in"in this.config.animation?this._routerData.animation={in:this.config.animation.in,out:this.config.animation.out||this.config.animation.in}:this._routerData.animation={in:this.config.animation,out:this.config.animation}}componentDidMount(){var t;super.componentDidMount(),this._routerData.navigation=new o(this.id,this._routerData,new r(this.id,Boolean(this.props.config.disableBrowserRouting),null!==(t=this.props.config.defaultRoute)&&void 0!==t?t:null,this.baseURL),this.animationLayerData,this.props.config.disableBrowserRouting,this.props.config.defaultRoute),this.initialise(this.navigation)}get navigation(){return this._routerData.navigation}}var c=e.Ay,l=e.W_,u=e.F0,d=e.Kq;export{c as History,l as Navigation,u as Router,d as Stack};
|