@react-motion-router/stack 1.0.7 → 1.1.1
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 +6 -0
- package/build/index.js +1 -1
- package/package.json +3 -2
package/build/Stack.d.ts
CHANGED
|
@@ -6,11 +6,17 @@ export declare namespace Stack {
|
|
|
6
6
|
[key: string]: any;
|
|
7
7
|
} = {}> extends ScreenComponentBaseProps<T, Navigation> {
|
|
8
8
|
}
|
|
9
|
+
type Presentation = "default" | "dialog" | "modal";
|
|
9
10
|
interface ScreenProps extends ScreenBaseProps {
|
|
11
|
+
config?: ScreenBaseProps["config"] & {
|
|
12
|
+
presentation?: Presentation;
|
|
13
|
+
};
|
|
10
14
|
}
|
|
11
15
|
interface ScreenState extends ScreenBaseState {
|
|
12
16
|
}
|
|
13
17
|
export class Screen extends ScreenBase<ScreenProps, ScreenState> {
|
|
18
|
+
constructor(props: ScreenProps);
|
|
19
|
+
onEnter: () => void;
|
|
14
20
|
}
|
|
15
21
|
export {};
|
|
16
22
|
}
|
package/build/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as t from"@react-motion-router/core";var i={d:(t,
|
|
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",null==e||e.addEventListener("go-back",(t=>{this.animationProviderRef instanceof HTMLDialogElement&&t.detail.finished.then(this.animationProviderRef.close.bind(this.animationProviderRef,"go-back"))}),{once:!0}),this.animationProviderRef.addEventListener("close",(function(t){"go-back"!==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})}},"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){var a;super(t,i,e),this._next=null;const s=window.location.pathname.replace(this.baseURL.pathname,"")||"/",n=window.location.search;if(i){this.defaultRoute=i;const t=null===(a=this.state.get(this.baseURL.pathname))||void 0===a?void 0:a.stack;this.defaultRoute===s||(null==t?void 0:t.length)||(this.replaceState({},"",o.getURL(this.defaultRoute,this.baseURL)),this.pushState({},"",o.getURL(s,this.baseURL,n)),this._stack.length||(this._stack.push(this.defaultRoute),this._stack.push(s)))}this._stack.length&&this._stack.includes(s)||this._stack.push(s||"/")}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.onPopStateListener=t=>{},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=>{if(t.detail.routerId!==this.id)return;const i=t.detail.route;if(this._routerData.currentPath=i,t.detail.routeParams){const e=this.state.routesData;e.set(i,{params:t.detail.routeParams}),this._routerData.routesData=e,this.setState({routesData:e},(()=>{this.setState({currentPath:i})}))}else this.setState({currentPath:i})},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,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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-motion-router/stack",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
],
|
|
12
12
|
"scripts": {
|
|
13
13
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
14
|
-
"build": "webpack"
|
|
14
|
+
"build": "webpack",
|
|
15
|
+
"dev": "webpack -w"
|
|
15
16
|
},
|
|
16
17
|
"repository": {
|
|
17
18
|
"type": "git",
|