@v-miniapp/router 1.0.5
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/README.md +63 -0
- package/dist/components/error/error-boundary.d.ts +15 -0
- package/dist/components/error/index.d.ts +1 -0
- package/dist/components/freeze/index.d.ts +11 -0
- package/dist/components/layout/index.d.ts +1 -0
- package/dist/components/layout/page-loading.d.ts +2 -0
- package/dist/components/link/index.d.ts +8 -0
- package/dist/components/router/index.d.ts +1 -0
- package/dist/components/router/pages-render.d.ts +2 -0
- package/dist/components/router/render-layout.d.ts +5 -0
- package/dist/components/router/router.d.ts +6 -0
- package/dist/components/router/style-pages-render.d.ts +2 -0
- package/dist/context/location-key.d.ts +4 -0
- package/dist/hooks/index.d.ts +10 -0
- package/dist/hooks/use-app-pause.d.ts +1 -0
- package/dist/hooks/use-app-resume.d.ts +1 -0
- package/dist/hooks/use-app-state.d.ts +7 -0
- package/dist/hooks/use-did-hide.d.ts +1 -0
- package/dist/hooks/use-did-show.d.ts +1 -0
- package/dist/hooks/use-history.d.ts +2 -0
- package/dist/hooks/use-location.d.ts +1 -0
- package/dist/hooks/use-navigate.d.ts +1 -0
- package/dist/hooks/use-navigation-type.d.ts +1 -0
- package/dist/hooks/use-swipe-navigation.d.ts +2 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +2532 -0
- package/dist/stores/router.d.ts +51 -0
- package/dist/stores/router.selector.d.ts +11 -0
- package/dist/styles.css +1 -0
- package/dist/styles.d.ts +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/navigation.d.ts +29 -0
- package/dist/types/router.d.ts +46 -0
- package/dist/utils/analytic.d.ts +14 -0
- package/dist/utils/animation.d.ts +4 -0
- package/dist/utils/classname.d.ts +2 -0
- package/dist/utils/deep-clone.d.ts +1 -0
- package/dist/utils/event-emitter.d.ts +11 -0
- package/dist/utils/history.d.ts +7 -0
- package/dist/utils/url.d.ts +1 -0
- package/package.json +32 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { IHistory, INavigate } from '../types/navigation';
|
|
2
|
+
import { IRouterConfig, IRouterAppState, IRouterPageState } from '../types/router';
|
|
3
|
+
import { EventEmitter } from '../utils/event-emitter';
|
|
4
|
+
export type IRouterStoreState = {
|
|
5
|
+
config: IRouterConfig;
|
|
6
|
+
initialized: boolean;
|
|
7
|
+
appState: IRouterAppState;
|
|
8
|
+
pageStates: Partial<Record<string, IRouterPageState>>;
|
|
9
|
+
histories: IHistory[];
|
|
10
|
+
init: (config: IRouterConfig) => void;
|
|
11
|
+
navigate: INavigate;
|
|
12
|
+
};
|
|
13
|
+
type IBeforeHistoryChangeData = {
|
|
14
|
+
history: IHistory;
|
|
15
|
+
histories: IHistory[];
|
|
16
|
+
nextHistory: IHistory;
|
|
17
|
+
nextHistories: IHistory[];
|
|
18
|
+
};
|
|
19
|
+
type IAfterHistoryChangeData = {
|
|
20
|
+
history: IHistory;
|
|
21
|
+
histories: IHistory[];
|
|
22
|
+
prevHistory: IHistory;
|
|
23
|
+
prevHistories: IHistory[];
|
|
24
|
+
};
|
|
25
|
+
type IAfterInitData = {
|
|
26
|
+
history: IHistory;
|
|
27
|
+
histories: IHistory[];
|
|
28
|
+
};
|
|
29
|
+
type INavigateData = {
|
|
30
|
+
to: string;
|
|
31
|
+
options?: {
|
|
32
|
+
replace?: boolean;
|
|
33
|
+
params?: Record<string, string>;
|
|
34
|
+
state?: any;
|
|
35
|
+
};
|
|
36
|
+
} | {
|
|
37
|
+
to: number;
|
|
38
|
+
};
|
|
39
|
+
type IBeforeNavigateData = IBeforeHistoryChangeData & INavigateData;
|
|
40
|
+
type IAfterNavigateData = IAfterHistoryChangeData & INavigateData;
|
|
41
|
+
export declare const routerEvents: EventEmitter<{
|
|
42
|
+
beforeHistoryChange: IBeforeHistoryChangeData;
|
|
43
|
+
beforeHistoryChangeP2: IBeforeHistoryChangeData;
|
|
44
|
+
afterHistoryChange: IAfterHistoryChangeData;
|
|
45
|
+
afterHistoryChangeP2: IAfterHistoryChangeData;
|
|
46
|
+
afterInit: IAfterInitData;
|
|
47
|
+
beforeNavigate: IBeforeNavigateData;
|
|
48
|
+
afterNavigate: IAfterNavigateData;
|
|
49
|
+
}>;
|
|
50
|
+
export declare const useRouterStore: import('zustand').UseBoundStore<import('zustand').StoreApi<IRouterStoreState>>;
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IRouterStoreState } from './router';
|
|
2
|
+
export declare const historiesSelector: (state: IRouterStoreState) => import('..').IHistory[];
|
|
3
|
+
export declare const lastHistorySelector: (state: IRouterStoreState) => import('..').IHistory;
|
|
4
|
+
export declare const historySelector: (locationKey: string | null) => (state: IRouterStoreState) => import('..').IHistory | undefined;
|
|
5
|
+
export declare const lastLocationSelector: (state: IRouterStoreState) => import('..').ILocation;
|
|
6
|
+
export declare const pageStatesSelector: (state: IRouterStoreState) => Partial<Record<string, import('..').IRouterPageState>>;
|
|
7
|
+
export declare const pageStateSelector: (locationKey: string | null) => (state: IRouterStoreState) => import('..').IRouterPageState | undefined;
|
|
8
|
+
export declare const lastPageStateSelector: (state: IRouterStoreState) => import('..').IRouterPageState | undefined;
|
|
9
|
+
export declare const pageConfigsSelector: (state: IRouterStoreState) => import('..').IRouterPageConfig[];
|
|
10
|
+
export declare const pageConfigSelector: (locationKey: string | null) => (state: IRouterStoreState) => import('..').IRouterPageConfig | undefined;
|
|
11
|
+
export declare const lastPageConfigSelector: (state: IRouterStoreState) => import('..').IRouterPageConfig | undefined;
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
:root{--vt-duration: 0s;--vt-timing: ease-in-out;--vt-new-name: vt-slide-in-forward;--vt-old-name: vt-slide-out-forward;--vt-new-index: 1;--vt-old-index: 0}.vsf-page-container{position:relative;left:0;top:0;right:0;min-height:100%;z-index:999;display:flex;flex-direction:column}.vsf-page-detail{min-height:100%;background-color:var(--color-background-app, #f5f5f5);transform:translateY(0)}.vsf-app .vsf-page-container{bottom:0}.vsf-app .vsf-page-detail{position:absolute!important;inset:0;z-index:0}.vsf-app .view-transition-new{z-index:var(--vt-new-index)}.vsf-app .view-transition-old{z-index:var(--vt-old-index)}.view-transition-new{animation:var(--vt-new-name) var(--vt-duration) var(--vt-timing) forwards;z-index:var(--vt-new-index)}::view-transition-new(root){animation:var(--vt-new-name) var(--vt-duration) var(--vt-timing) forwards;z-index:var(--vt-new-index)}.view-transition-old{animation:var(--vt-old-name) var(--vt-duration) var(--vt-timing) forwards;z-index:var(--vt-old-index)}::view-transition-old(root){animation:var(--vt-old-name) var(--vt-duration) var(--vt-timing) forwards;z-index:var(--vt-old-index)}@keyframes vt-slide_left-in-forward{0%{transform:translate(100%)}to{transform:translate(0)}}@keyframes vt-slide_left-out-forward{to{transform:translate(-20%)}}@keyframes vt-slide_left-in-back{0%{transform:translate(-20%)}to{transform:translate(0)}}@keyframes vt-slide_left-out-back{to{transform:translate(100%)}}@keyframes vt-slide_up-in-forward{0%{transform:translateY(100%)}to{transform:translate(0)}}@keyframes vt-slide_up-out-forward{0%{transform:translate(0)}to{transform:translate(0)}}@keyframes vt-slide_up-in-back{0%{transform:translate(0)}to{transform:translate(0)}}@keyframes vt-slide_up-out-back{0%{transform:translate(0)}to{transform:translateY(100%)}}@keyframes vt-fade_in-in-forward{0%{opacity:0}to{opacity:1}}@keyframes vt-fade_in-out-forward{0%{opacity:1}to{opacity:0}}@keyframes vt-fade_in-in-back{0%{opacity:0}to{opacity:1}}@keyframes vt-fade_in-out-back{0%{opacity:1}to{opacity:0}}
|
package/dist/styles.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { IAnimationState, IRouterPageState } from './router';
|
|
2
|
+
export type INavigatePathnameOptions = {
|
|
3
|
+
replace?: boolean;
|
|
4
|
+
params?: Record<string, string>;
|
|
5
|
+
state?: any;
|
|
6
|
+
} & IRouterPageState;
|
|
7
|
+
export type INavigateDeltaOptions = {
|
|
8
|
+
animation?: IAnimationState;
|
|
9
|
+
};
|
|
10
|
+
export type INavigate = {
|
|
11
|
+
(to: string, options?: INavigatePathnameOptions): void;
|
|
12
|
+
(to: number, options?: INavigateDeltaOptions): void;
|
|
13
|
+
};
|
|
14
|
+
export type IHistoryAction = 'POP' | 'REPLACE' | 'PUSH';
|
|
15
|
+
export type ILocation = {
|
|
16
|
+
key: string;
|
|
17
|
+
pathname: string;
|
|
18
|
+
params?: Record<string, string>;
|
|
19
|
+
state?: any;
|
|
20
|
+
};
|
|
21
|
+
export type IHistoryState = {
|
|
22
|
+
locations: ILocation[];
|
|
23
|
+
idx: number;
|
|
24
|
+
type: 'vsf-router';
|
|
25
|
+
};
|
|
26
|
+
export type IHistory = {
|
|
27
|
+
action: IHistoryAction;
|
|
28
|
+
location: ILocation;
|
|
29
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ComponentType, PropsWithChildren } from 'react';
|
|
2
|
+
export type INavigationAnimationType = 'none' | 'slide_up' | 'slide_left' | 'fade_in';
|
|
3
|
+
export type INavigationAnimationMode = 'view-transition' | 'style-transition';
|
|
4
|
+
export type IAnimationState = {
|
|
5
|
+
type?: INavigationAnimationType;
|
|
6
|
+
};
|
|
7
|
+
export type IAnimationConfig = {
|
|
8
|
+
type?: INavigationAnimationType;
|
|
9
|
+
mode?: INavigationAnimationMode;
|
|
10
|
+
};
|
|
11
|
+
export type IKeepAliveState = {
|
|
12
|
+
enable?: boolean;
|
|
13
|
+
maxStack?: number;
|
|
14
|
+
freeze?: boolean;
|
|
15
|
+
freezeDelay?: number;
|
|
16
|
+
};
|
|
17
|
+
export type ILayout = ComponentType<PropsWithChildren>;
|
|
18
|
+
export type IRouterAppState = {
|
|
19
|
+
animation?: IAnimationState;
|
|
20
|
+
keepAlive?: IKeepAliveState;
|
|
21
|
+
Layouts?: ILayout[];
|
|
22
|
+
};
|
|
23
|
+
export type IRouterPageState = {
|
|
24
|
+
animation?: IAnimationState;
|
|
25
|
+
keepAlive?: boolean;
|
|
26
|
+
freeze?: boolean;
|
|
27
|
+
freezeDelay?: number;
|
|
28
|
+
Layouts?: ILayout[];
|
|
29
|
+
};
|
|
30
|
+
export type IRouterPageConfig = {
|
|
31
|
+
title?: string;
|
|
32
|
+
pathname: string;
|
|
33
|
+
Component: ComponentType;
|
|
34
|
+
Layouts?: ILayout[];
|
|
35
|
+
bottomTabBarId?: string;
|
|
36
|
+
animation?: IAnimationConfig;
|
|
37
|
+
} & Omit<IRouterPageState, 'animation'>;
|
|
38
|
+
export type IRouterConfig = {
|
|
39
|
+
pages: IRouterPageConfig[];
|
|
40
|
+
navigation?: {
|
|
41
|
+
alwaysRootPage?: boolean;
|
|
42
|
+
};
|
|
43
|
+
NotFoundPage?: ComponentType;
|
|
44
|
+
ErrorPage?: ComponentType;
|
|
45
|
+
animation?: IAnimationConfig;
|
|
46
|
+
} & Omit<IRouterAppState, 'animation'>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const AnalyticEventName: {
|
|
2
|
+
readonly PAGE_VIEW: "page_view";
|
|
3
|
+
readonly NAVIGATION: "navigation";
|
|
4
|
+
};
|
|
5
|
+
export type IAnalyticEventName = (typeof AnalyticEventName)[keyof typeof AnalyticEventName];
|
|
6
|
+
type IAnalyticOptions = {
|
|
7
|
+
event: IAnalyticEventName;
|
|
8
|
+
params: Record<string, unknown>;
|
|
9
|
+
};
|
|
10
|
+
declare class Analytic {
|
|
11
|
+
sendEvent(options: IAnalyticOptions): any;
|
|
12
|
+
}
|
|
13
|
+
export declare const analytic: Analytic;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { INavigationAnimationType } from '../types/router';
|
|
2
|
+
import { IHistoryAction } from '../types/navigation';
|
|
3
|
+
export declare const ANIMATION_DURATION = 250;
|
|
4
|
+
export declare const setupAnimation: (animationType: INavigationAnimationType, action: IHistoryAction) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const deepCloneWithoutComponent: <T>(value: T) => T;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type IEventHandler<Data> = (data: Data) => void;
|
|
2
|
+
export declare class EventEmitter<IEventMapping extends Record<string, any>> {
|
|
3
|
+
private emitCustomEvent?;
|
|
4
|
+
constructor(options?: {
|
|
5
|
+
emitCustomEvent?: boolean;
|
|
6
|
+
});
|
|
7
|
+
private listeners;
|
|
8
|
+
on<T extends keyof IEventMapping>(event: T, handler: IEventHandler<IEventMapping[T]>): () => void;
|
|
9
|
+
off<T extends keyof IEventMapping>(event: T, handler: IEventHandler<IEventMapping[T]>): void;
|
|
10
|
+
emit<T extends keyof IEventMapping>(event: T, payload: IEventMapping[T]): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IRouterPageConfig, IRouterConfig } from '../types/router';
|
|
2
|
+
import { IHistory, IHistoryState, ILocation } from '../types/navigation';
|
|
3
|
+
export declare const PAGE_PATH_NAME = "__pagePath";
|
|
4
|
+
export declare const initHistories: (config: IRouterConfig) => IHistory[];
|
|
5
|
+
export declare const getPageByPathname: (pages: IRouterPageConfig[], pathname: string) => IRouterPageConfig | undefined;
|
|
6
|
+
export declare const getHistoryState: (histories: IHistory[]) => IHistoryState;
|
|
7
|
+
export declare const getUrlFromLocation: (location: ILocation) => URL;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function objectToSearchString(params?: Record<string, any>): string;
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@v-miniapp/router",
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"style": "./dist/styles.css"
|
|
14
|
+
},
|
|
15
|
+
"./*": "./dist/*"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@types/lodash": "^4.17.23",
|
|
19
|
+
"classnames": "^2.5.1",
|
|
20
|
+
"lodash": "^4.17.23",
|
|
21
|
+
"nanoid": "^5.1.6",
|
|
22
|
+
"react-freeze": "^1.0.4",
|
|
23
|
+
"zustand": "^5.0.9"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"react": ">=19.0.0",
|
|
27
|
+
"react-dom": ">=19.0.0"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=22"
|
|
31
|
+
}
|
|
32
|
+
}
|