page-transition 0.1.0-beta.8 → 0.1.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/README.md +223 -55
- package/dist/components/{TransitionLink.js → css/TransitionLink.js} +2 -2
- package/dist/components/manual/TransitionLink.d.ts +10 -0
- package/dist/components/manual/TransitionLink.js +10 -0
- package/dist/context/CssContext.d.ts +12 -0
- package/dist/context/CssContext.js +9 -0
- package/dist/context/CssTransitionProvider.d.ts +8 -5
- package/dist/context/CssTransitionProvider.js +45 -44
- package/dist/context/ManualContext.d.ts +9 -0
- package/dist/context/ManualContext.js +9 -0
- package/dist/context/ManualTransitionProvider.d.ts +2 -1
- package/dist/context/ManualTransitionProvider.js +14 -3
- package/dist/context/TransitionProvider.d.ts +23 -0
- package/dist/context/TransitionProvider.js +10 -0
- package/dist/css.d.ts +2 -0
- package/dist/css.js +3 -0
- package/dist/functions/checkTransitionStart.d.ts +1 -5
- package/dist/functions/checkTransitionStart.js +5 -10
- package/dist/functions/pollTransitionStart.d.ts +1 -4
- package/dist/functions/pollTransitionStart.js +2 -0
- package/dist/functions/transitionEnd.d.ts +2 -15
- package/dist/functions/transitionEnd.js +8 -17
- package/dist/functions/transitionRunning.d.ts +2 -0
- package/dist/functions/transitionRunning.js +29 -0
- package/dist/hooks/manual/useHandleLinkClick.d.ts +3 -1
- package/dist/hooks/manual/useHandleLinkClick.js +6 -1
- package/dist/hooks/manual/usePopState.d.ts +2 -1
- package/dist/hooks/manual/usePopState.js +7 -2
- package/dist/hooks/useHandleLinkClick.d.ts +4 -14
- package/dist/hooks/useHandleLinkClick.js +56 -36
- package/dist/hooks/usePopState.d.ts +3 -14
- package/dist/hooks/usePopState.js +51 -36
- package/dist/hooks/useScrollRestoration.d.ts +5 -1
- package/dist/hooks/useScrollRestoration.js +4 -1
- package/dist/hooks/useTransitionEndData.d.ts +5 -6
- package/dist/hooks/useTransitionEndData.js +4 -4
- package/dist/hooks/useTransitionEndHandler.d.ts +1 -5
- package/dist/hooks/useTransitionEndObj.d.ts +1 -9
- package/dist/hooks/useTransitionEndObj.js +3 -3
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/manual.d.ts +2 -0
- package/dist/manual.js +3 -0
- package/dist/types/transitionEnd.types.d.ts +15 -0
- package/dist/types/transitionEnd.types.js +1 -0
- package/dist/types/transitionPropertys.types.d.ts +1 -0
- package/dist/types/transitionPropertys.types.js +1 -0
- package/package.json +15 -3
- package/dist/context/TransitionContext.d.ts +0 -24
- package/dist/context/TransitionContext.js +0 -17
- package/dist/functions/checkTransitionFinish.d.ts +0 -6
- package/dist/functions/checkTransitionFinish.js +0 -13
- package/dist/functions/parseClipPath.d.ts +0 -1
- package/dist/functions/parseClipPath.js +0 -9
- package/dist/functions/parseClipPathAll.d.ts +0 -1
- package/dist/functions/parseClipPathAll.js +0 -20
- package/dist/functions/parseDelay.d.ts +0 -1
- package/dist/functions/parseDelay.js +0 -10
- package/dist/functions/parseOpacity.d.ts +0 -1
- package/dist/functions/parseOpacity.js +0 -6
- package/dist/functions/parseOpacityAll.d.ts +0 -1
- package/dist/functions/parseOpacityAll.js +0 -13
- package/dist/functions/resetDelay.d.ts +0 -1
- package/dist/functions/resetDelay.js +0 -7
- package/dist/functions/transitionEndReverse.d.ts +0 -21
- package/dist/functions/transitionEndReverse.js +0 -36
- package/dist/functions/wait.d.ts +0 -2
- package/dist/functions/wait.js +0 -12
- /package/dist/components/{TransitionLink.d.ts → css/TransitionLink.d.ts} +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
interface ProviderProps {
|
|
3
|
+
scroll: 'auto' | 'top';
|
|
3
4
|
children: ReactNode;
|
|
4
5
|
}
|
|
5
|
-
export declare function ManualTransitionProvider({ children }: ProviderProps): import("react").JSX.Element;
|
|
6
|
+
export declare function ManualTransitionProvider({ scroll, children }: ProviderProps): import("react").JSX.Element;
|
|
6
7
|
export {};
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import { ManualContext } from "./ManualContext";
|
|
4
4
|
import { useEffect, useRef, useMemo } from "react";
|
|
5
5
|
import { usePathname } from "next/navigation";
|
|
6
6
|
import { usePopState } from "../hooks/manual/usePopState";
|
|
7
7
|
import { useHandleLinkClick } from "../hooks/manual/useHandleLinkClick";
|
|
8
|
-
|
|
8
|
+
import { useScrollRestoration } from "../hooks/useScrollRestoration";
|
|
9
|
+
export function ManualTransitionProvider({ scroll, children }) {
|
|
9
10
|
const pathname = usePathname();
|
|
10
11
|
const handleLinkClick = useRef(() => { });
|
|
11
12
|
const resolveFn = useRef(null);
|
|
12
13
|
const state = useRef('idle');
|
|
14
|
+
const currentPathname = useRef(pathname);
|
|
15
|
+
const basePath = useRef(null);
|
|
13
16
|
const useUse = useRef(false);
|
|
14
17
|
const resolveUseFn = useRef(null);
|
|
15
18
|
usePopState({
|
|
16
19
|
resolveFn,
|
|
17
20
|
state,
|
|
21
|
+
currentPathname,
|
|
18
22
|
useUse,
|
|
19
23
|
resolveUseFn
|
|
20
24
|
});
|
|
@@ -22,12 +26,19 @@ export function ManualTransitionProvider({ children }) {
|
|
|
22
26
|
handleLinkClick,
|
|
23
27
|
resolveFn,
|
|
24
28
|
state,
|
|
29
|
+
currentPathname,
|
|
30
|
+
basePath,
|
|
25
31
|
useUse,
|
|
26
32
|
resolveUseFn
|
|
27
33
|
});
|
|
34
|
+
useScrollRestoration({ scroll });
|
|
28
35
|
useEffect(() => {
|
|
36
|
+
if (basePath.current === null) {
|
|
37
|
+
basePath.current = window.location.pathname.slice(0, -pathname.length);
|
|
38
|
+
}
|
|
29
39
|
state.current = 'entering';
|
|
40
|
+
currentPathname.current = window.location.pathname;
|
|
30
41
|
}, [pathname]);
|
|
31
42
|
const value = useMemo(() => ({ handleLinkClick, resolveFn, state }), []);
|
|
32
|
-
return (_jsx(
|
|
43
|
+
return (_jsx(ManualContext.Provider, { value: value, children: children }));
|
|
33
44
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { TransitionProperty } from "../types/transitionPropertys.types";
|
|
3
|
+
interface TransitionOptions {
|
|
4
|
+
transitionProperty: TransitionProperty;
|
|
5
|
+
overlays?: number;
|
|
6
|
+
items?: [number, number];
|
|
7
|
+
}
|
|
8
|
+
interface BaseProps {
|
|
9
|
+
scroll?: 'auto' | 'top';
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
type ModeProps = {
|
|
13
|
+
mode?: 'css';
|
|
14
|
+
outside?: ReactNode;
|
|
15
|
+
options: TransitionOptions;
|
|
16
|
+
} | {
|
|
17
|
+
mode: 'manual';
|
|
18
|
+
outside?: never;
|
|
19
|
+
options?: never;
|
|
20
|
+
};
|
|
21
|
+
type ProviderProps = BaseProps & ModeProps;
|
|
22
|
+
export declare function TransitionProvider(props: ProviderProps): import("react").JSX.Element;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { CssTransitionProvider } from "./CssTransitionProvider";
|
|
4
|
+
import { ManualTransitionProvider } from "./ManualTransitionProvider";
|
|
5
|
+
export function TransitionProvider(props) {
|
|
6
|
+
const { scroll = 'auto', children } = props;
|
|
7
|
+
return (props.mode === 'manual' ?
|
|
8
|
+
_jsx(ManualTransitionProvider, { scroll: scroll, children: children }) :
|
|
9
|
+
_jsx(CssTransitionProvider, { scroll: scroll, outside: props.outside, options: props.options, children: children }));
|
|
10
|
+
}
|
package/dist/css.d.ts
ADDED
package/dist/css.js
ADDED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
elArray: (HTMLDivElement | null)[];
|
|
3
|
-
propertyName: 'opacity' | 'clip-path';
|
|
4
|
-
}
|
|
1
|
+
import type { TransitionEndData } from "../types/transitionEnd.types";
|
|
5
2
|
export declare function checkTransitionStart(transitionEndData: TransitionEndData, fn: (() => void) | null): boolean;
|
|
6
|
-
export {};
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { parseClipPathAll } from "./parseClipPathAll";
|
|
1
|
+
import { transitionRunning } from "./transitionRunning";
|
|
3
2
|
export function checkTransitionStart(transitionEndData, fn) {
|
|
4
|
-
|
|
5
|
-
'opacity': () => parseOpacityAll(transitionEndData.elArray),
|
|
6
|
-
'clip-path': () => parseClipPathAll(transitionEndData.elArray)
|
|
7
|
-
};
|
|
8
|
-
if (parse[transitionEndData.propertyName]()) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
3
|
+
if (transitionRunning(transitionEndData.elArray, transitionEndData.transitionProperty, transitionEndData.group)) {
|
|
12
4
|
fn?.();
|
|
13
5
|
return true;
|
|
14
6
|
}
|
|
7
|
+
else {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
15
10
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import type { RefObject } from "react";
|
|
2
|
-
|
|
3
|
-
elArray: (HTMLDivElement | null)[];
|
|
4
|
-
propertyName: 'opacity' | 'clip-path';
|
|
5
|
-
}
|
|
2
|
+
import type { TransitionEndData } from "../types/transitionEnd.types";
|
|
6
3
|
interface Props {
|
|
7
4
|
id: RefObject<number | null>;
|
|
8
5
|
fn: () => void;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { checkTransitionStart } from "./checkTransitionStart";
|
|
2
2
|
export function pollTransitionStart({ id, fn, transitionEndData }) {
|
|
3
|
+
if (id.current !== null)
|
|
4
|
+
cancelAnimationFrame(id.current);
|
|
3
5
|
id.current = requestAnimationFrame(() => {
|
|
4
6
|
if (checkTransitionStart(transitionEndData.current, fn)) {
|
|
5
7
|
return;
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
import type { RefObject } from "react";
|
|
2
|
-
|
|
3
|
-
elArray: (HTMLDivElement | null)[];
|
|
4
|
-
propertyName: 'opacity' | 'clip-path';
|
|
5
|
-
fn: (() => void) | null;
|
|
6
|
-
}
|
|
7
|
-
interface TransitionEndHandler {
|
|
8
|
-
handler: ((e: TransitionEvent) => void) | null;
|
|
9
|
-
handlerEl: HTMLDivElement | null;
|
|
10
|
-
}
|
|
2
|
+
import type { TransitionEndObj, TransitionEndHandler } from "../types/transitionEnd.types";
|
|
11
3
|
interface Props {
|
|
12
4
|
transitionEndObj: RefObject<TransitionEndObj>;
|
|
13
5
|
transitionEndHandler: RefObject<TransitionEndHandler>;
|
|
14
|
-
reverse: RefObject<{
|
|
15
|
-
_lock: boolean;
|
|
16
|
-
lock: boolean;
|
|
17
|
-
}>;
|
|
18
|
-
delay: RefObject<number | null>;
|
|
19
6
|
}
|
|
20
|
-
export declare function transitionEnd({ transitionEndObj, transitionEndHandler
|
|
7
|
+
export declare function transitionEnd({ transitionEndObj, transitionEndHandler }: Props): void;
|
|
21
8
|
export {};
|
|
@@ -1,29 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
export function transitionEnd({ transitionEndObj, transitionEndHandler, reverse, delay }) {
|
|
1
|
+
export function transitionEnd({ transitionEndObj, transitionEndHandler }) {
|
|
3
2
|
const lastIndex = transitionEndObj.current.elArray.length - 1;
|
|
4
3
|
if (transitionEndHandler.current.handler &&
|
|
5
4
|
transitionEndHandler.current.handlerEl) {
|
|
6
5
|
transitionEndHandler.current.handlerEl.removeEventListener('transitionend', transitionEndHandler.current.handler);
|
|
7
6
|
}
|
|
8
|
-
|
|
9
|
-
transtionEndReverse({
|
|
10
|
-
transitionEndObj,
|
|
11
|
-
transitionEndHandler,
|
|
12
|
-
reverse,
|
|
13
|
-
delay
|
|
14
|
-
});
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
7
|
+
const endObj = transitionEndObj.current;
|
|
17
8
|
const handler = (e) => {
|
|
18
9
|
if (e.target !== e.currentTarget)
|
|
19
10
|
return;
|
|
20
|
-
if (
|
|
21
|
-
e.propertyName !==
|
|
11
|
+
if (endObj.transitionProperty &&
|
|
12
|
+
e.propertyName !== endObj.transitionProperty)
|
|
22
13
|
return;
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
endObj.elArray[lastIndex]?.removeEventListener('transitionend', handler);
|
|
15
|
+
endObj.fn?.();
|
|
25
16
|
};
|
|
26
17
|
transitionEndHandler.current.handler = handler;
|
|
27
|
-
transitionEndHandler.current.handlerEl =
|
|
28
|
-
|
|
18
|
+
transitionEndHandler.current.handlerEl = endObj.elArray[lastIndex];
|
|
19
|
+
endObj.elArray[lastIndex]?.addEventListener('transitionend', transitionEndHandler.current.handler);
|
|
29
20
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function transitionRunning(elArray, transitionProperty, group) {
|
|
2
|
+
let el;
|
|
3
|
+
if (group === 'overlay') {
|
|
4
|
+
el = elArray[elArray.length - 1];
|
|
5
|
+
}
|
|
6
|
+
else {
|
|
7
|
+
if (!elArray[0])
|
|
8
|
+
return null;
|
|
9
|
+
el = elArray[0];
|
|
10
|
+
}
|
|
11
|
+
const property = {
|
|
12
|
+
opacity: 'opacity',
|
|
13
|
+
'clip-path': 'clipPath',
|
|
14
|
+
'transform': 'transform'
|
|
15
|
+
};
|
|
16
|
+
if (!el)
|
|
17
|
+
return null;
|
|
18
|
+
if (el.getAnimations().some((obj) => {
|
|
19
|
+
const progress = obj.effect?.getComputedTiming().progress;
|
|
20
|
+
return obj.playState === 'running' &&
|
|
21
|
+
obj.effect instanceof KeyframeEffect &&
|
|
22
|
+
obj.effect.getKeyframes().some(frame => {
|
|
23
|
+
return frame[property[transitionProperty]] !== undefined;
|
|
24
|
+
}) && progress != null && progress !== 0;
|
|
25
|
+
})) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
@@ -3,8 +3,10 @@ interface Props {
|
|
|
3
3
|
handleLinkClick: RefObject<((e: React.MouseEvent, url: string) => void)>;
|
|
4
4
|
resolveFn: RefObject<(() => void) | null>;
|
|
5
5
|
state: RefObject<'idle' | 'exiting' | 'entering'>;
|
|
6
|
+
currentPathname: RefObject<string>;
|
|
7
|
+
basePath: RefObject<string | null>;
|
|
6
8
|
useUse: RefObject<boolean>;
|
|
7
9
|
resolveUseFn: RefObject<(() => void) | null>;
|
|
8
10
|
}
|
|
9
|
-
export declare function useHandleLinkClick({ handleLinkClick, resolveFn, state, useUse, resolveUseFn }: Props): void;
|
|
11
|
+
export declare function useHandleLinkClick({ handleLinkClick, resolveFn, state, currentPathname, basePath, useUse, resolveUseFn }: Props): void;
|
|
10
12
|
export {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useCallback } from "react";
|
|
3
3
|
import { useRouter } from "next/navigation";
|
|
4
|
-
export function useHandleLinkClick({ handleLinkClick, resolveFn, state, useUse, resolveUseFn }) {
|
|
4
|
+
export function useHandleLinkClick({ handleLinkClick, resolveFn, state, currentPathname, basePath, useUse, resolveUseFn }) {
|
|
5
5
|
const router = useRouter();
|
|
6
6
|
handleLinkClick.current = useCallback((e, url) => {
|
|
7
7
|
e.preventDefault();
|
|
8
|
+
const basePathUrl = basePath.current ? basePath.current + url : url;
|
|
8
9
|
new Promise((resolve) => {
|
|
9
10
|
resolveFn.current = resolve;
|
|
10
11
|
state.current = 'exiting';
|
|
@@ -12,6 +13,10 @@ export function useHandleLinkClick({ handleLinkClick, resolveFn, state, useUse,
|
|
|
12
13
|
if (useUse.current)
|
|
13
14
|
resolveUseFn.current?.();
|
|
14
15
|
router.push(url);
|
|
16
|
+
resolveFn.current = null;
|
|
17
|
+
if (basePathUrl === currentPathname.current) {
|
|
18
|
+
state.current = 'entering';
|
|
19
|
+
}
|
|
15
20
|
});
|
|
16
21
|
}, []);
|
|
17
22
|
}
|
|
@@ -2,8 +2,9 @@ import type { RefObject } from "react";
|
|
|
2
2
|
interface Props {
|
|
3
3
|
resolveFn: RefObject<(() => void) | null>;
|
|
4
4
|
state: RefObject<'idle' | 'exiting' | 'entering'>;
|
|
5
|
+
currentPathname: RefObject<string>;
|
|
5
6
|
useUse: RefObject<boolean>;
|
|
6
7
|
resolveUseFn: RefObject<(() => void) | null>;
|
|
7
8
|
}
|
|
8
|
-
export declare function usePopState({ resolveFn, state, useUse, resolveUseFn }: Props): void;
|
|
9
|
+
export declare function usePopState({ resolveFn, state, currentPathname, useUse, resolveUseFn }: Props): void;
|
|
9
10
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useEffect, useState, use } from "react";
|
|
3
|
-
export function usePopState({ resolveFn, state, useUse, resolveUseFn }) {
|
|
3
|
+
export function usePopState({ resolveFn, state, currentPathname, useUse, resolveUseFn }) {
|
|
4
4
|
const [promise, setPromise] = useState(null);
|
|
5
5
|
if (promise) {
|
|
6
6
|
useUse.current = true;
|
|
@@ -15,7 +15,12 @@ export function usePopState({ resolveFn, state, useUse, resolveUseFn }) {
|
|
|
15
15
|
resolveFn.current = resolve;
|
|
16
16
|
resolveUseFn.current = reject;
|
|
17
17
|
state.current = 'exiting';
|
|
18
|
-
}).then(() =>
|
|
18
|
+
}).then(() => {
|
|
19
|
+
setPromise(null);
|
|
20
|
+
if (window.location.pathname === currentPathname.current) {
|
|
21
|
+
state.current = 'entering';
|
|
22
|
+
}
|
|
23
|
+
}).catch(() => setPromise(null)));
|
|
19
24
|
};
|
|
20
25
|
window.addEventListener('popstate', handlePopstate);
|
|
21
26
|
return () => window.removeEventListener('popstate', handlePopstate);
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import type { RefObject } from "react";
|
|
2
|
-
|
|
3
|
-
elArray: (HTMLDivElement | null)[];
|
|
4
|
-
propertyName: 'opacity' | 'clip-path';
|
|
5
|
-
}
|
|
6
|
-
interface TransitionEndHandler {
|
|
7
|
-
handler: ((e: TransitionEvent) => void) | null;
|
|
8
|
-
handlerEl: HTMLDivElement | null;
|
|
9
|
-
}
|
|
2
|
+
import type { TransitionEndData, TransitionEndHandler } from "../types/transitionEnd.types";
|
|
10
3
|
interface Props {
|
|
11
4
|
container: RefObject<HTMLDivElement | null>;
|
|
12
5
|
handleLinkClick: RefObject<((e: React.MouseEvent, url: string) => void)>;
|
|
@@ -14,13 +7,10 @@ interface Props {
|
|
|
14
7
|
transitionEndData: RefObject<TransitionEndData>;
|
|
15
8
|
transitionEndHandler: RefObject<TransitionEndHandler>;
|
|
16
9
|
state: RefObject<'idle' | 'exiting' | 'entering' | 'navigating'>;
|
|
17
|
-
reverse: RefObject<{
|
|
18
|
-
_lock: boolean;
|
|
19
|
-
lock: boolean;
|
|
20
|
-
}>;
|
|
21
|
-
delay: RefObject<number | null>;
|
|
22
10
|
useUse: RefObject<boolean>;
|
|
23
11
|
resolveUseFn: RefObject<(() => void) | null>;
|
|
12
|
+
basePath: RefObject<string | null>;
|
|
13
|
+
pollRafId: RefObject<number | null>;
|
|
24
14
|
}
|
|
25
|
-
export declare function useHandleLinkClick({ container, handleLinkClick, currentPathname, transitionEndData, transitionEndHandler,
|
|
15
|
+
export declare function useHandleLinkClick({ container, handleLinkClick, currentPathname, transitionEndData, transitionEndHandler, state, useUse, resolveUseFn, basePath, pollRafId }: Props): void;
|
|
26
16
|
export {};
|
|
@@ -3,13 +3,11 @@ import { useCallback, useRef } from "react";
|
|
|
3
3
|
import { useRouter } from "next/navigation";
|
|
4
4
|
import { useTransitionEndObj } from "../hooks/useTransitionEndObj";
|
|
5
5
|
import { transitionEnd } from "../functions/transitionEnd";
|
|
6
|
-
import { checkTransitionFinish } from "../functions/checkTransitionFinish";
|
|
7
6
|
import { pollTransitionStart } from "../functions/pollTransitionStart";
|
|
8
|
-
export function useHandleLinkClick({ container, handleLinkClick, currentPathname, transitionEndData, transitionEndHandler,
|
|
7
|
+
export function useHandleLinkClick({ container, handleLinkClick, currentPathname, transitionEndData, transitionEndHandler, state, useUse, resolveUseFn, basePath, pollRafId }) {
|
|
9
8
|
const router = useRouter();
|
|
10
9
|
const afterExitFn = useRef(null);
|
|
11
10
|
const nextPage = useRef(null);
|
|
12
|
-
const pollRafId = useRef(null);
|
|
13
11
|
const push = useTransitionEndObj({
|
|
14
12
|
transitionEndData,
|
|
15
13
|
fn: () => {
|
|
@@ -27,7 +25,6 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
|
|
|
27
25
|
fn: () => {
|
|
28
26
|
container.current?.classList.remove('enter');
|
|
29
27
|
state.current = 'idle';
|
|
30
|
-
reverse.current.lock = true;
|
|
31
28
|
}
|
|
32
29
|
});
|
|
33
30
|
const afterExit = useTransitionEndObj({
|
|
@@ -35,73 +32,96 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
|
|
|
35
32
|
fn: afterExitFn.current = () => {
|
|
36
33
|
transitionEnd({
|
|
37
34
|
transitionEndObj: removeEnter,
|
|
38
|
-
transitionEndHandler
|
|
39
|
-
reverse,
|
|
40
|
-
delay
|
|
35
|
+
transitionEndHandler
|
|
41
36
|
});
|
|
42
37
|
if (useUse.current) {
|
|
43
38
|
resolveUseFn.current?.();
|
|
44
39
|
state.current = 'navigating';
|
|
45
|
-
|
|
40
|
+
if (!nextPage.current)
|
|
41
|
+
return;
|
|
42
|
+
router.push(nextPage.current);
|
|
46
43
|
}
|
|
47
44
|
state.current = 'navigating';
|
|
48
45
|
container.current?.classList.remove('exit');
|
|
49
46
|
container.current?.classList.add('enter');
|
|
50
47
|
pollTransitionStart({
|
|
51
|
-
transitionEndData,
|
|
52
48
|
id: pollRafId,
|
|
49
|
+
transitionEndData,
|
|
53
50
|
fn: () => {
|
|
54
51
|
state.current = 'entering';
|
|
55
|
-
reverse.current.lock = false;
|
|
56
52
|
}
|
|
57
53
|
});
|
|
58
54
|
}
|
|
59
55
|
});
|
|
56
|
+
const afterEntering = useTransitionEndObj({
|
|
57
|
+
transitionEndData,
|
|
58
|
+
fn: () => {
|
|
59
|
+
container.current?.classList.remove('enter');
|
|
60
|
+
void container.current?.offsetWidth;
|
|
61
|
+
container.current?.classList.add('exit');
|
|
62
|
+
state.current = 'exiting';
|
|
63
|
+
transitionEnd({
|
|
64
|
+
transitionEndObj: push,
|
|
65
|
+
transitionEndHandler
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
});
|
|
60
69
|
handleLinkClick.current = useCallback((e, url) => {
|
|
61
70
|
e.preventDefault();
|
|
62
71
|
nextPage.current = url;
|
|
72
|
+
const basePathUrl = basePath.current ? basePath.current + url : url;
|
|
63
73
|
new Promise((resolve) => {
|
|
64
74
|
if (state.current === 'navigating') {
|
|
65
|
-
|
|
66
|
-
if (url === currentPathname.current) {
|
|
75
|
+
if (basePathUrl === currentPathname.current) {
|
|
67
76
|
return;
|
|
68
77
|
}
|
|
69
|
-
else if (
|
|
70
|
-
if (
|
|
71
|
-
if (!nextPage.current)
|
|
72
|
-
return;
|
|
73
|
-
state.current = 'navigating';
|
|
74
|
-
router.push(nextPage.current);
|
|
75
|
-
nextPage.current = null;
|
|
76
|
-
}))
|
|
78
|
+
else if (basePathUrl !== currentPathname.current) {
|
|
79
|
+
if (!nextPage.current)
|
|
77
80
|
return;
|
|
78
|
-
|
|
81
|
+
state.current = 'navigating';
|
|
82
|
+
router.push(nextPage.current);
|
|
83
|
+
nextPage.current = null;
|
|
84
|
+
return;
|
|
79
85
|
}
|
|
80
86
|
}
|
|
81
87
|
else {
|
|
82
88
|
resolve();
|
|
83
89
|
}
|
|
84
90
|
}).then(() => {
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
|
|
91
|
+
if (state.current === 'idle' &&
|
|
92
|
+
currentPathname.current === basePathUrl)
|
|
93
|
+
return;
|
|
94
|
+
if (currentPathname.current === basePathUrl
|
|
95
|
+
&& state.current === 'exiting') {
|
|
88
96
|
transitionEnd({
|
|
89
97
|
transitionEndObj: afterExit,
|
|
90
|
-
transitionEndHandler
|
|
91
|
-
reverse,
|
|
92
|
-
delay
|
|
98
|
+
transitionEndHandler
|
|
93
99
|
});
|
|
94
100
|
return;
|
|
95
101
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
state.current
|
|
102
|
+
if (state.current === 'entering' &&
|
|
103
|
+
currentPathname.current === basePathUrl) {
|
|
104
|
+
transitionEnd({
|
|
105
|
+
transitionEndObj: removeEnter,
|
|
106
|
+
transitionEndHandler
|
|
107
|
+
});
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (state.current === 'idle' || state.current === 'exiting') {
|
|
111
|
+
transitionEnd({
|
|
112
|
+
transitionEndObj: push,
|
|
113
|
+
transitionEndHandler
|
|
114
|
+
});
|
|
115
|
+
container.current?.classList.remove('enter');
|
|
116
|
+
container.current?.classList.add('exit');
|
|
117
|
+
state.current = 'exiting';
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
transitionEnd({
|
|
121
|
+
transitionEndObj: afterEntering,
|
|
122
|
+
transitionEndHandler
|
|
123
|
+
});
|
|
124
|
+
}
|
|
105
125
|
});
|
|
106
126
|
}, [router]);
|
|
107
127
|
}
|
|
@@ -1,25 +1,14 @@
|
|
|
1
1
|
import type { RefObject } from "react";
|
|
2
|
-
|
|
3
|
-
elArray: (HTMLDivElement | null)[];
|
|
4
|
-
propertyName: 'opacity' | 'clip-path';
|
|
5
|
-
}
|
|
6
|
-
interface TransitionEndHandler {
|
|
7
|
-
handler: ((e: TransitionEvent) => void) | null;
|
|
8
|
-
handlerEl: HTMLDivElement | null;
|
|
9
|
-
}
|
|
2
|
+
import type { TransitionEndData, TransitionEndHandler } from "../types/transitionEnd.types";
|
|
10
3
|
interface Props {
|
|
11
4
|
container: RefObject<HTMLDivElement | null>;
|
|
12
5
|
currentPathname: RefObject<string>;
|
|
13
6
|
transitionEndData: RefObject<TransitionEndData>;
|
|
14
7
|
transitionEndHandler: RefObject<TransitionEndHandler>;
|
|
15
|
-
reverse: RefObject<{
|
|
16
|
-
_lock: boolean;
|
|
17
|
-
lock: boolean;
|
|
18
|
-
}>;
|
|
19
|
-
delay: RefObject<number | null>;
|
|
20
8
|
state: RefObject<'idle' | 'exiting' | 'entering' | 'navigating'>;
|
|
21
9
|
useUse: RefObject<boolean>;
|
|
22
10
|
resolveUseFn: RefObject<(() => void) | null>;
|
|
11
|
+
pollRafId: RefObject<number | null>;
|
|
23
12
|
}
|
|
24
|
-
export declare function usePopState({ container, currentPathname, transitionEndData, transitionEndHandler,
|
|
13
|
+
export declare function usePopState({ container, currentPathname, transitionEndData, transitionEndHandler, state, useUse, resolveUseFn, pollRafId }: Props): void;
|
|
25
14
|
export {};
|