@react-motion-router/stack 1.2.0 → 2.0.0-beta.2e4c2ad

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Nathan Johnson
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Nathan Johnson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
package/package.json CHANGED
@@ -1,31 +1,32 @@
1
- {
2
- "name": "@react-motion-router/stack",
3
- "version": "1.2.0",
4
- "description": "",
5
- "main": "build/index.js",
6
- "publishConfig": {
7
- "access": "public"
8
- },
9
- "files": [
10
- "build"
11
- ],
12
- "scripts": {
13
- "test": "echo \"Error: no test specified\" && exit 1",
14
- "build": "webpack",
15
- "dev": "webpack -w"
16
- },
17
- "repository": {
18
- "type": "git",
19
- "url": "git+https://github.com/nxtexe/react-motion-router.git"
20
- },
21
- "author": "nxtexe",
22
- "license": "Apache-2.0",
23
- "bugs": {
24
- "url": "https://github.com/nxtexe/react-motion-router/issues"
25
- },
26
- "homepage": "https://github.com/nxtexe/react-motion-router#readme",
27
- "peerDependencies": {
28
- "@react-motion-router/core": "*"
29
- },
30
- "gitHead": "38a495e365799d870713ad00fcffd26af293582f"
31
- }
1
+ {
2
+ "name": "@react-motion-router/stack",
3
+ "version": "2.0.0-beta.2e4c2ad",
4
+ "description": "",
5
+ "main": "build/index.js",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "files": [
10
+ "build"
11
+ ],
12
+ "scripts": {
13
+ "test": "echo \"Error: no test specified\" && exit 1",
14
+ "build": "webpack --env production",
15
+ "dev": "webpack watch --env development"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/nxtexe/react-motion-router.git"
20
+ },
21
+ "author": "nxtexe",
22
+ "license": "MIT",
23
+ "bugs": {
24
+ "url": "https://github.com/nxtexe/react-motion-router/issues"
25
+ },
26
+ "homepage": "https://github.com/nxtexe/react-motion-router#readme",
27
+ "peerDependencies": {
28
+ "@react-motion-router/core": "*",
29
+ "web-animations-extension": "*"
30
+ },
31
+ "gitHead": "2e4c2ad02ca4b3753b2995b8a04b17752d502398"
32
+ }
@@ -1,15 +0,0 @@
1
- import { HistoryBase } from "@react-motion-router/core";
2
- export default class History extends HistoryBase {
3
- private _next;
4
- constructor(_routerId: string, _disableBrowserRouting: boolean, _defaultRoute: string | null, _baseURL: URL);
5
- push(route: string, search?: string, hash?: string, replace?: boolean): void;
6
- implicitPush(route: string, replace?: boolean): void;
7
- back(): string | null;
8
- implicitBack(): string | null;
9
- canGoBack(): boolean;
10
- set next(_next: string | null);
11
- get current(): string;
12
- get next(): string | null;
13
- get previous(): string | null;
14
- get stack(): string[];
15
- }
@@ -1,39 +0,0 @@
1
- import { GoBackOptions, NavigateOptions, NavigationBase, RouterData } from '@react-motion-router/core';
2
- import type { AnimationLayerData, PlainObject } from '@react-motion-router/core';
3
- import History from './History';
4
- export default class Navigation extends NavigationBase {
5
- protected _history: History;
6
- private _animationLayerData;
7
- private isInternalBack;
8
- private _finished;
9
- constructor(_routerId: string, _routerData: RouterData<Navigation>, _history: History, _animationLayerData: AnimationLayerData, _disableBrowserRouting?: boolean, _defaultRoute?: string | null);
10
- onPopState: (e: Event) => void;
11
- navigate<T extends PlainObject = PlainObject>(route: string, routeParams?: T, options?: NavigateOptions): Promise<void>;
12
- private implicitNavigate;
13
- private implicitBack;
14
- goBack(options?: GoBackOptions): Promise<void> | undefined;
15
- private createBackEvent;
16
- private createNavigateEvent;
17
- private createFinishedPromise;
18
- private onNavigateAbort;
19
- private onBackAbort;
20
- assign(url: string | URL): void;
21
- replace(url: string | URL): void;
22
- get finished(): Promise<void>;
23
- get parent(): NavigationBase | null;
24
- get location(): {
25
- ancestorOrigins: DOMStringList;
26
- assign: (url: string | URL) => void;
27
- hash: string;
28
- host: string;
29
- hostname: string;
30
- href: string;
31
- origin: string;
32
- pathname: string;
33
- port: string;
34
- protocol: string;
35
- reload(): void;
36
- replace: (url: string | URL) => void;
37
- search: string;
38
- };
39
- }
package/build/Router.d.ts DELETED
@@ -1,18 +0,0 @@
1
- import { BackEvent, NavigateEvent, RouterBase, RouterData } from '@react-motion-router/core';
2
- import type { RouterBaseProps, RouterBaseState } from '@react-motion-router/core';
3
- import Navigation from './Navigation';
4
- export interface RouterProps extends RouterBaseProps {
5
- }
6
- export interface RouterState extends RouterBaseState {
7
- }
8
- export default class Router extends RouterBase {
9
- protected _routerData: RouterData<Navigation>;
10
- constructor(props: RouterProps);
11
- componentDidMount(): void;
12
- get navigation(): Navigation;
13
- onGestureNavigationStart: () => void;
14
- onGestureNavigationEnd: () => void;
15
- onAnimationEnd: () => void;
16
- onBackListener: (e: BackEvent) => void;
17
- onNavigateListener: (e: NavigateEvent) => void;
18
- }
package/build/Stack.d.ts DELETED
@@ -1,24 +0,0 @@
1
- import { ScreenBase } from '@react-motion-router/core';
2
- import type { ScreenBaseProps, ScreenBaseState, ScreenComponentBaseProps } from '@react-motion-router/core';
3
- import Navigation from './Navigation';
4
- export declare namespace Stack {
5
- export interface ScreenComponentProps<T extends {
6
- [key: string]: any;
7
- } = {}> extends ScreenComponentBaseProps<ScreenProps, T, Navigation> {
8
- }
9
- type Presentation = "default" | "dialog" | "modal";
10
- interface ScreenProps extends ScreenBaseProps {
11
- config?: ScreenBaseProps["config"] & {
12
- presentation?: Presentation;
13
- };
14
- }
15
- interface ScreenState extends ScreenBaseState {
16
- }
17
- export class Screen extends ScreenBase<ScreenProps, ScreenState> {
18
- constructor(props: ScreenProps);
19
- onEnter: () => void;
20
- onExit(): void;
21
- onExited: () => void;
22
- }
23
- export {};
24
- }
package/build/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { Stack } from './Stack';
2
- import Router, { RouterProps, RouterState } from './Router';
3
- import History from './History';
4
- import Navigation from './Navigation';
5
- export { Stack, Router, Navigation, History };
6
- export type { RouterState, RouterProps };
package/build/index.js DELETED
@@ -1 +0,0 @@
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};