@lynx-js/lynx-ui-presence 3.137.0 → 3.140.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/CHANGELOG.md +18 -0
- package/dist/types/index.docs.d.ts +12 -4
- package/dist/types/index.docs.d.ts.map +1 -1
- package/dist/usePresence.d.ts +2 -2
- package/dist/usePresence.jsx.map +1 -1
- package/package.json +2 -2
- package/src/types/index.docs.ts +15 -4
- package/src/usePresence.tsx +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @lynx-js/lynx-ui-presence
|
|
2
2
|
|
|
3
|
+
## 3.140.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add PascalCase names for public hook types and normalize supporting type names, ([#355](https://github.com/lynx-family/lynx-ui/pull/355))
|
|
8
|
+
retaining deprecated aliases for existing public names.
|
|
9
|
+
|
|
10
|
+
## 3.139.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- Add the canonical `PresenceUIVariants` type name and deprecate the previous `PresenceUiVariants` alias. ([#333](https://github.com/lynx-family/lynx-ui/pull/333))
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [[`1a4ad19`](https://github.com/lynx-family/lynx-ui/commit/1a4ad190993d57425b4c377a7dd63882cc65a8d2)]:
|
|
19
|
+
- @lynx-js/lynx-ui-common@3.139.0
|
|
20
|
+
|
|
3
21
|
## 3.137.0
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -32,9 +32,9 @@ export interface PresenceAnimationStatus {
|
|
|
32
32
|
/**
|
|
33
33
|
* UI variants applied by Presence based on animation status.
|
|
34
34
|
* Use them as CSS selectors to style different states.
|
|
35
|
-
* @zh Presence 根据状态注入的
|
|
35
|
+
* @zh Presence 根据状态注入的 UI variants,可用于 CSS selector 按状态定制样式。
|
|
36
36
|
*/
|
|
37
|
-
export interface
|
|
37
|
+
export interface PresenceUIVariants {
|
|
38
38
|
/**
|
|
39
39
|
* Applied when `status.open` is true.
|
|
40
40
|
* @zh 当 status.open 为 true 时生效,可用于 `.ui-open { ... }`。
|
|
@@ -61,6 +61,10 @@ export interface PresenceUiVariants {
|
|
|
61
61
|
*/
|
|
62
62
|
'ui-animating'?: boolean;
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* @deprecated Use `PresenceUIVariants` instead.
|
|
66
|
+
*/
|
|
67
|
+
export type PresenceUiVariants = PresenceUIVariants;
|
|
64
68
|
export type PresenceChildrenType = (status: PresenceAnimationStatus) => ReactNode;
|
|
65
69
|
export interface PresenceProps {
|
|
66
70
|
show: boolean;
|
|
@@ -73,7 +77,7 @@ export interface PresenceProps {
|
|
|
73
77
|
onOpen?: () => void;
|
|
74
78
|
debugLog?: boolean;
|
|
75
79
|
}
|
|
76
|
-
export interface
|
|
80
|
+
export interface UsePresenceProps {
|
|
77
81
|
show: boolean;
|
|
78
82
|
forceMount?: boolean;
|
|
79
83
|
state: PresenceState;
|
|
@@ -98,5 +102,9 @@ export interface PresenceContextType {
|
|
|
98
102
|
handleTransitionEnd: EventHandler<TransitionEvent>;
|
|
99
103
|
};
|
|
100
104
|
}
|
|
101
|
-
export type
|
|
105
|
+
export type UsePresenceReturnType = PresenceContextType;
|
|
106
|
+
/** @deprecated Use `UsePresenceProps` instead. */
|
|
107
|
+
export type usePresenceProps = UsePresenceProps;
|
|
108
|
+
/** @deprecated Use `UsePresenceReturnType` instead. */
|
|
109
|
+
export type usePresenceReturnType = UsePresenceReturnType;
|
|
102
110
|
//# sourceMappingURL=index.docs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.docs.d.ts","sourceRoot":"","sources":["../../src/types/index.docs.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE/C,OAAO,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W,CAAC,EAAE,OAAO,CAAA;IAErB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAA;IACnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE;QACX,KAAK,EAAE,aAAa,CAAA;QACpB,KAAK,EAAE,OAAO,CAAA;QACd,gBAAgB,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAA;KAIjD,CAAA;IACD,iBAAiB,EAAE;QACjB,aAAa,EAAE,YAAY,CAAC,cAAc,CAAC,CAAA;QAC3C,cAAc,EAAE,YAAY,CAAC,cAAc,CAAC,CAAA;QAC5C,sBAAsB,EAAE,YAAY,CAAC,eAAe,CAAC,CAAA;QACrD,WAAW,EAAE,YAAY,CAAC,cAAc,CAAC,CAAA;QACzC,qBAAqB,EAAE,YAAY,CAAC,eAAe,CAAC,CAAA;QACpD,mBAAmB,EAAE,YAAY,CAAC,eAAe,CAAC,CAAA;KACnD,CAAA;CACF;AAED,MAAM,MAAM,qBAAqB,GAAG,mBAAmB,CAAA;AAEvD,kDAAkD;AAClD,MAAM,MAAM,gBAAgB,GAAG,gBAAgB,CAAA;AAE/C,uDAAuD;AACvD,MAAM,MAAM,qBAAqB,GAAG,qBAAqB,CAAA"}
|
package/dist/usePresence.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { PresenceAnimationStatus, PresenceContextType, PresenceProps,
|
|
1
|
+
import type { PresenceAnimationStatus, PresenceContextType, PresenceProps, UsePresenceProps, UsePresenceReturnType } from './types/index.js';
|
|
2
2
|
export declare const PresenceContext: import("react").Context<PresenceContextType>;
|
|
3
|
-
export declare function usePresence(props:
|
|
3
|
+
export declare function usePresence(props: UsePresenceProps): UsePresenceReturnType;
|
|
4
4
|
export declare const renderPresenceChildren: (props: {
|
|
5
5
|
children: PresenceProps["children"];
|
|
6
6
|
status: PresenceAnimationStatus;
|
package/dist/usePresence.jsx.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePresence.jsx","sources":["../src/usePresence.tsx"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { createContext, useEffect, useRef, useState } from '@lynx-js/react'\n\nimport { delayFrames, log } from '@lynx-js/lynx-ui-common'\nimport type { AnimationEvent, TransitionEvent } from '@lynx-js/types'\n\nimport type {\n PresenceAnimationStatus,\n PresenceContextType,\n PresenceProps,\n usePresenceProps,\n usePresenceReturnType,\n} from './types'\nimport { PresenceState } from './utils'\n\nexport const PresenceContext = createContext<PresenceContextType>(null!)\n\nexport function usePresence(props: usePresenceProps): usePresenceReturnType {\n const {\n show,\n state,\n enableDelay = false,\n setPresenceState,\n onOpen,\n onClose,\n debugLog = false,\n } = props\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] init, show: ${show}, state: ${state}, enableDelay: ${enableDelay}`,\n )\n const enteringStateWithDelay = enableDelay\n ? PresenceState.DelayedEntering\n : PresenceState.Entering\n\n const isTransitionAnimating = useRef<boolean>(false)\n const isKFAnimating = useRef<boolean>(false)\n // Track the initial render, to prevent effects from running on mount.\n const isInitialRender = useRef(true)\n const hasNotifiedOpen = useRef(false)\n const showRef = useRef(show)\n // The core state to control the mounting and unmounting of the component.\n const [mount, setMount] = useState<boolean>(false)\n // These three id record the loop ID for the entering progress animation and show state to prevent race conditions.\n const enteringLoopIdRef = useRef<number>(0)\n const leavingLoopIdRef = useRef<number>(0)\n const showScheduleIdRef = useRef(0)\n // Two timing windows to wait for the animation to start before forcing a state change.\n const enteringWaitFramesRef = useRef<number>(0)\n const leavingWaitFramesRef = useRef<number>(0)\n\n // The maximum number of frames to wait for an animation to start before forcing a state change.\n const MAX_WAIT_FRAMES = 24\n\n showRef.current = show\n\n const cancelShowTimer = () => {\n showScheduleIdRef.current += 1\n }\n\n const cancelEnteringWait = () => {\n enteringLoopIdRef.current += 1\n }\n\n const cancelLeavingWait = () => {\n leavingLoopIdRef.current += 1\n }\n\n const scheduleShow = () => {\n const scheduleId = showScheduleIdRef.current\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] set mount=true',\n )\n setMount(true)\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] schedule set Entering in 8 frames',\n )\n delayFrames(8, () => {\n if (scheduleId !== showScheduleIdRef.current || !showRef.current) return\n setPresenceState(PresenceState.Entering)\n })\n if (enableDelay) {\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] schedule set DelayedEntering in 16 frames',\n )\n delayFrames(16, () => {\n if (scheduleId !== showScheduleIdRef.current || !showRef.current) {\n return\n }\n setPresenceState(PresenceState.DelayedEntering)\n })\n }\n }\n\n const restartShow = () => {\n cancelShowTimer()\n scheduleShow()\n }\n\n const notAnimating = () => (isKFAnimating.current === false\n && isTransitionAnimating.current === false)\n\n const handleAnimationStart = () => {\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] handleAnimationStart state:${state}, show:${show}, isTransition:${isTransitionAnimating.current}, isKFAnimating:${isKFAnimating.current}`,\n )\n }\n\n const handleAnimationEnd = () => {\n // still need to check if the other kind of animation is running.\n if (\n (state === PresenceState.Entering\n || state === PresenceState.DelayedEntering)\n && notAnimating()\n ) {\n if (showRef.current) {\n setPresenceState(PresenceState.Entered)\n } else {\n // Safeguard: entering animation may still fire after show turns false.\n // Why not Left? Because Left will also cancel the ongoing leaving animation.\n setPresenceState(PresenceState.Leaving)\n }\n }\n if (state === PresenceState.Leaving && notAnimating()) {\n cancelLeavingWait()\n if (showRef.current) {\n restartShow()\n } else {\n setPresenceState(PresenceState.Left)\n }\n }\n }\n\n // ==== Animation events =====\n const handleKFStart = () => {\n isKFAnimating.current = true\n enteringLoopIdRef.current += 1\n leavingLoopIdRef.current += 1\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] KF start, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationStart()\n }\n\n const handleTransitionStart = () => {\n isTransitionAnimating.current = true\n enteringLoopIdRef.current += 1\n leavingLoopIdRef.current += 1\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] Transition start, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationStart()\n }\n\n const handleKFEnd = (_e: AnimationEvent) => {\n isKFAnimating.current = false\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] KF end, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationEnd()\n }\n\n const handleKFCancel = () => {\n isKFAnimating.current = false\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] KF cancel, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationEnd()\n }\n\n const handleTransitionCancel = () => {\n isTransitionAnimating.current = false\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] Transition cancel, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationEnd()\n }\n\n const handleTransitionEnd = (_e: TransitionEvent) => {\n isTransitionAnimating.current = false\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] Transition end, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationEnd()\n }\n\n // ==== state controller ====\n const handleStateEntered = () => {\n if (hasNotifiedOpen.current) {\n return\n }\n hasNotifiedOpen.current = true\n onOpen?.()\n }\n\n const handleStateLeft = () => {\n if (showRef.current) {\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] skip mount=false because show=true (Left)',\n )\n restartShow()\n return\n }\n if (!isInitialRender.current && hasNotifiedOpen.current) {\n hasNotifiedOpen.current = false\n onClose?.()\n }\n log(debugLog, '[lynx-ui-presence][usePresence] set mount=false (Left)')\n setMount(false)\n }\n\n const handleStateLeaving = () => {\n cancelEnteringWait()\n leavingWaitFramesRef.current = 0\n leavingLoopIdRef.current += 1\n const loopId = leavingLoopIdRef.current\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] leaving loop scheduled, loopId: ${loopId}`,\n )\n const tryLeft = () => {\n // The loopId is inconsistent with the current animation state, means the animation started during the delay period, so we should stop this trying.\n if (loopId !== leavingLoopIdRef.current) return\n if (!notAnimating()) return\n // timeout reached => treat as no animation\n if (leavingWaitFramesRef.current >= MAX_WAIT_FRAMES) {\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] leaving timeout reached, loopId: ${loopId}, frames: ${leavingWaitFramesRef.current}`,\n )\n if (showRef.current) {\n restartShow()\n } else {\n setPresenceState(PresenceState.Left)\n }\n return\n }\n leavingWaitFramesRef.current += 1\n delayFrames(1, tryLeft)\n }\n\n delayFrames(1, tryLeft)\n }\n\n const handleStateEnteringWithDelay = () => {\n cancelLeavingWait()\n enteringWaitFramesRef.current = 0\n enteringLoopIdRef.current += 1\n const loopId = enteringLoopIdRef.current\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] entering loop scheduled, loopId: ${loopId}`,\n )\n const tryEntered = () => {\n // The loopId is inconsistent with the current animation state, means the animation started during the delay period, so we should stop this trying.\n if (loopId !== enteringLoopIdRef.current) return\n if (!notAnimating()) return\n if (enteringWaitFramesRef.current >= MAX_WAIT_FRAMES) {\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] entering timeout reached, loopId: ${loopId}, frames: ${enteringWaitFramesRef.current}`,\n )\n if (showRef.current) {\n setPresenceState(PresenceState.Entered)\n } else {\n setPresenceState(PresenceState.Leaving)\n }\n return\n }\n enteringWaitFramesRef.current += 1\n delayFrames(1, tryEntered)\n }\n\n delayFrames(1, tryEntered)\n }\n\n useEffect(() => {\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] state effect, state: ${state}, show: ${show}, enableDelay: ${enableDelay}, isTransitionAnimating: ${isTransitionAnimating.current}, isKFAnimating: ${isKFAnimating.current}`,\n )\n if (state === PresenceState.Entered) {\n handleStateEntered()\n }\n if (state === PresenceState.Left) {\n handleStateLeft()\n }\n if (state === PresenceState.Leaving) {\n handleStateLeaving()\n }\n if (state === enteringStateWithDelay) {\n handleStateEnteringWithDelay()\n }\n }, [state])\n\n // ==== Show change part ====\n const handleDismiss = () => {\n if (\n state === PresenceState.Entered || state === PresenceState.Entering\n || state === PresenceState.DelayedEntering\n ) {\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] show=false -> set PresenceState.Leaving',\n )\n cancelEnteringWait()\n setPresenceState(PresenceState.Leaving)\n } else if (\n (state === PresenceState.Initial || state === PresenceState.Left) && mount\n ) {\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] show=false before entering -> set mount=false',\n )\n setMount(false)\n }\n }\n\n useEffect(() => {\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] show effect show:${show}, enableDelay:${enableDelay}, state:${state}, mount:${mount}`,\n )\n if (show) {\n restartShow()\n } else {\n cancelShowTimer()\n handleDismiss()\n }\n }, [show, enableDelay])\n\n useEffect(() => {\n isInitialRender.current = false\n }, [])\n\n return {\n controllers: { state, mount, setPresenceState },\n animationHandlers: {\n handleKFStart,\n handleKFCancel,\n handleKFEnd,\n handleTransitionStart,\n handleTransitionCancel,\n handleTransitionEnd,\n },\n }\n}\n\nexport const renderPresenceChildren = (\n props: {\n children: PresenceProps['children']\n status: PresenceAnimationStatus\n },\n) => {\n const { children, status } = props\n return typeof children === 'function'\n ? children(status)\n : children\n}\n"],"names":["PresenceContext","createContext","usePresence","props","show","state","enableDelay","setPresenceState","onOpen","onClose","debugLog","log","enteringStateWithDelay","PresenceState","isTransitionAnimating","useRef","isKFAnimating","isInitialRender","hasNotifiedOpen","showRef","mount","setMount","useState","enteringLoopIdRef","leavingLoopIdRef","showScheduleIdRef","enteringWaitFramesRef","leavingWaitFramesRef","MAX_WAIT_FRAMES","cancelShowTimer","cancelEnteringWait","cancelLeavingWait","scheduleShow","scheduleId","delayFrames","restartShow","notAnimating","handleAnimationStart","handleAnimationEnd","handleKFStart","handleTransitionStart","handleKFEnd","_e","handleKFCancel","handleTransitionCancel","handleTransitionEnd","handleStateEntered","handleStateLeft","handleStateLeaving","loopId","tryLeft","handleStateEnteringWithDelay","tryEntered","useEffect","handleD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AAU;QACR1C,IACED,UACA,CAAC,iDAAiD,EAAEN,KAAK,cAAc,EAAEE,YAAY,QAAQ,EAAED,MAAM,QAAQ,EAAEe,OAAO;QAExH,IAAIhB,MACF+B;aACK;YACLN;YACAyB;QACF;IACF,GAAG;QAAClD;QAAME;KAAY;IAEtB+C,UAAU;QACRpC,gBAAgB,OAAO,GAAG;IAC5B,GAAG,EAAE;IAEL,OAAO;QACL,aAAa;YAAEZ;YAAOe;YAAOb;QAAiB;QAC9C,mBAAmB;YACjBgC;YACAI;YACAF;YACAD;YACAI;YACAC;QACF;IACF;AACF;AAEO,MAAMU,yBAAyB,CACpCpD;IAKA,MAAM,EAAEqD,QAAQ,EAAEC,MAAM,EAAE,GAAGtD;IAC7B,OAAO,AAAoB,cAApB,OAAOqD,WACVA,SAASC,UACTD;AACN"}
|
|
1
|
+
{"version":3,"file":"usePresence.jsx","sources":["../src/usePresence.tsx"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { createContext, useEffect, useRef, useState } from '@lynx-js/react'\n\nimport { delayFrames, log } from '@lynx-js/lynx-ui-common'\nimport type { AnimationEvent, TransitionEvent } from '@lynx-js/types'\n\nimport type {\n PresenceAnimationStatus,\n PresenceContextType,\n PresenceProps,\n UsePresenceProps,\n UsePresenceReturnType,\n} from './types'\nimport { PresenceState } from './utils'\n\nexport const PresenceContext = createContext<PresenceContextType>(null!)\n\nexport function usePresence(props: UsePresenceProps): UsePresenceReturnType {\n const {\n show,\n state,\n enableDelay = false,\n setPresenceState,\n onOpen,\n onClose,\n debugLog = false,\n } = props\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] init, show: ${show}, state: ${state}, enableDelay: ${enableDelay}`,\n )\n const enteringStateWithDelay = enableDelay\n ? PresenceState.DelayedEntering\n : PresenceState.Entering\n\n const isTransitionAnimating = useRef<boolean>(false)\n const isKFAnimating = useRef<boolean>(false)\n // Track the initial render, to prevent effects from running on mount.\n const isInitialRender = useRef(true)\n const hasNotifiedOpen = useRef(false)\n const showRef = useRef(show)\n // The core state to control the mounting and unmounting of the component.\n const [mount, setMount] = useState<boolean>(false)\n // These three id record the loop ID for the entering progress animation and show state to prevent race conditions.\n const enteringLoopIdRef = useRef<number>(0)\n const leavingLoopIdRef = useRef<number>(0)\n const showScheduleIdRef = useRef(0)\n // Two timing windows to wait for the animation to start before forcing a state change.\n const enteringWaitFramesRef = useRef<number>(0)\n const leavingWaitFramesRef = useRef<number>(0)\n\n // The maximum number of frames to wait for an animation to start before forcing a state change.\n const MAX_WAIT_FRAMES = 24\n\n showRef.current = show\n\n const cancelShowTimer = () => {\n showScheduleIdRef.current += 1\n }\n\n const cancelEnteringWait = () => {\n enteringLoopIdRef.current += 1\n }\n\n const cancelLeavingWait = () => {\n leavingLoopIdRef.current += 1\n }\n\n const scheduleShow = () => {\n const scheduleId = showScheduleIdRef.current\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] set mount=true',\n )\n setMount(true)\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] schedule set Entering in 8 frames',\n )\n delayFrames(8, () => {\n if (scheduleId !== showScheduleIdRef.current || !showRef.current) return\n setPresenceState(PresenceState.Entering)\n })\n if (enableDelay) {\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] schedule set DelayedEntering in 16 frames',\n )\n delayFrames(16, () => {\n if (scheduleId !== showScheduleIdRef.current || !showRef.current) {\n return\n }\n setPresenceState(PresenceState.DelayedEntering)\n })\n }\n }\n\n const restartShow = () => {\n cancelShowTimer()\n scheduleShow()\n }\n\n const notAnimating = () => (isKFAnimating.current === false\n && isTransitionAnimating.current === false)\n\n const handleAnimationStart = () => {\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] handleAnimationStart state:${state}, show:${show}, isTransition:${isTransitionAnimating.current}, isKFAnimating:${isKFAnimating.current}`,\n )\n }\n\n const handleAnimationEnd = () => {\n // still need to check if the other kind of animation is running.\n if (\n (state === PresenceState.Entering\n || state === PresenceState.DelayedEntering)\n && notAnimating()\n ) {\n if (showRef.current) {\n setPresenceState(PresenceState.Entered)\n } else {\n // Safeguard: entering animation may still fire after show turns false.\n // Why not Left? Because Left will also cancel the ongoing leaving animation.\n setPresenceState(PresenceState.Leaving)\n }\n }\n if (state === PresenceState.Leaving && notAnimating()) {\n cancelLeavingWait()\n if (showRef.current) {\n restartShow()\n } else {\n setPresenceState(PresenceState.Left)\n }\n }\n }\n\n // ==== Animation events =====\n const handleKFStart = () => {\n isKFAnimating.current = true\n enteringLoopIdRef.current += 1\n leavingLoopIdRef.current += 1\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] KF start, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationStart()\n }\n\n const handleTransitionStart = () => {\n isTransitionAnimating.current = true\n enteringLoopIdRef.current += 1\n leavingLoopIdRef.current += 1\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] Transition start, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationStart()\n }\n\n const handleKFEnd = (_e: AnimationEvent) => {\n isKFAnimating.current = false\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] KF end, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationEnd()\n }\n\n const handleKFCancel = () => {\n isKFAnimating.current = false\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] KF cancel, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationEnd()\n }\n\n const handleTransitionCancel = () => {\n isTransitionAnimating.current = false\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] Transition cancel, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationEnd()\n }\n\n const handleTransitionEnd = (_e: TransitionEvent) => {\n isTransitionAnimating.current = false\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] Transition end, loopId: ${leavingLoopIdRef.current}`,\n )\n handleAnimationEnd()\n }\n\n // ==== state controller ====\n const handleStateEntered = () => {\n if (hasNotifiedOpen.current) {\n return\n }\n hasNotifiedOpen.current = true\n onOpen?.()\n }\n\n const handleStateLeft = () => {\n if (showRef.current) {\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] skip mount=false because show=true (Left)',\n )\n restartShow()\n return\n }\n if (!isInitialRender.current && hasNotifiedOpen.current) {\n hasNotifiedOpen.current = false\n onClose?.()\n }\n log(debugLog, '[lynx-ui-presence][usePresence] set mount=false (Left)')\n setMount(false)\n }\n\n const handleStateLeaving = () => {\n cancelEnteringWait()\n leavingWaitFramesRef.current = 0\n leavingLoopIdRef.current += 1\n const loopId = leavingLoopIdRef.current\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] leaving loop scheduled, loopId: ${loopId}`,\n )\n const tryLeft = () => {\n // The loopId is inconsistent with the current animation state, means the animation started during the delay period, so we should stop this trying.\n if (loopId !== leavingLoopIdRef.current) return\n if (!notAnimating()) return\n // timeout reached => treat as no animation\n if (leavingWaitFramesRef.current >= MAX_WAIT_FRAMES) {\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] leaving timeout reached, loopId: ${loopId}, frames: ${leavingWaitFramesRef.current}`,\n )\n if (showRef.current) {\n restartShow()\n } else {\n setPresenceState(PresenceState.Left)\n }\n return\n }\n leavingWaitFramesRef.current += 1\n delayFrames(1, tryLeft)\n }\n\n delayFrames(1, tryLeft)\n }\n\n const handleStateEnteringWithDelay = () => {\n cancelLeavingWait()\n enteringWaitFramesRef.current = 0\n enteringLoopIdRef.current += 1\n const loopId = enteringLoopIdRef.current\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] entering loop scheduled, loopId: ${loopId}`,\n )\n const tryEntered = () => {\n // The loopId is inconsistent with the current animation state, means the animation started during the delay period, so we should stop this trying.\n if (loopId !== enteringLoopIdRef.current) return\n if (!notAnimating()) return\n if (enteringWaitFramesRef.current >= MAX_WAIT_FRAMES) {\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] entering timeout reached, loopId: ${loopId}, frames: ${enteringWaitFramesRef.current}`,\n )\n if (showRef.current) {\n setPresenceState(PresenceState.Entered)\n } else {\n setPresenceState(PresenceState.Leaving)\n }\n return\n }\n enteringWaitFramesRef.current += 1\n delayFrames(1, tryEntered)\n }\n\n delayFrames(1, tryEntered)\n }\n\n useEffect(() => {\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] state effect, state: ${state}, show: ${show}, enableDelay: ${enableDelay}, isTransitionAnimating: ${isTransitionAnimating.current}, isKFAnimating: ${isKFAnimating.current}`,\n )\n if (state === PresenceState.Entered) {\n handleStateEntered()\n }\n if (state === PresenceState.Left) {\n handleStateLeft()\n }\n if (state === PresenceState.Leaving) {\n handleStateLeaving()\n }\n if (state === enteringStateWithDelay) {\n handleStateEnteringWithDelay()\n }\n }, [state])\n\n // ==== Show change part ====\n const handleDismiss = () => {\n if (\n state === PresenceState.Entered || state === PresenceState.Entering\n || state === PresenceState.DelayedEntering\n ) {\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] show=false -> set PresenceState.Leaving',\n )\n cancelEnteringWait()\n setPresenceState(PresenceState.Leaving)\n } else if (\n (state === PresenceState.Initial || state === PresenceState.Left) && mount\n ) {\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] show=false before entering -> set mount=false',\n )\n setMount(false)\n }\n }\n\n useEffect(() => {\n log(\n debugLog,\n `[lynx-ui-presence][usePresence] show effect show:${show}, enableDelay:${enableDelay}, state:${state}, mount:${mount}`,\n )\n if (show) {\n restartShow()\n } else {\n cancelShowTimer()\n handleDismiss()\n }\n }, [show, enableDelay])\n\n useEffect(() => {\n isInitialRender.current = false\n }, [])\n\n return {\n controllers: { state, mount, setPresenceState },\n animationHandlers: {\n handleKFStart,\n handleKFCancel,\n handleKFEnd,\n handleTransitionStart,\n handleTransitionCancel,\n handleTransitionEnd,\n },\n }\n}\n\nexport const renderPresenceChildren = (\n props: {\n children: PresenceProps['children']\n status: PresenceAnimationStatus\n },\n) => {\n const { children, status } = props\n return typeof children === 'function'\n ? children(status)\n : children\n}\n"],"names":["PresenceContext","createContext","usePresence","props","show","state","enableDelay","setPresenceState","onOpen","onClose","debugLog","log","enteringStateWithDelay","PresenceState","isTransitionAnimating","useRef","isKFAnimating","isInitialRender","hasNotifiedOpen","showRef","mount","setMount","useState","enteringLoopIdRef","leavingLoopIdRef","showScheduleIdRef","enteringWaitFramesRef","leavingWaitFramesRef","MAX_WAIT_FRAMES","cancelShowTimer","cancelEnteringWait","cancelLeavingWait","scheduleShow","scheduleId","delayFrames","restartShow","notAnimating","handleAnimationStart","handleAnimationEnd","handleKFStart","handleTransitionStart","handleKFEnd","_e","handleKFCancel","handleTransitionCancel","handleTransitionEnd","handleStateEntered","handleStateLeft","handleStateLeaving","loopId","tryLeft","handleStateEnteringWithDelay","tryEntered","useEffect","handleDismiss","renderPresenceChildren","children","status"],"mappings":";;;AAkBO,MAAMA,kBAAkBC,cAAmC;AAE3D,SAASC,YAAYC,KAAuB;IACjD,MAAM,EACJC,IAAI,EACJC,KAAK,EACLC,cAAc,KAAK,EACnBC,gBAAgB,EAChBC,MAAM,EACNC,OAAO,EACPC,WAAW,KAAK,EACjB,GAAGP;IACJQ,IACED,UACA,CAAC,4CAA4C,EAAEN,KAAK,SAAS,EAAEC,MAAM,eAAe,EAAEC,aAAa;IAErG,MAAMM,yBAAyBN,cAC3BO,cAAc,eAAe,GAC7BA,cAAc,QAAQ;IAE1B,MAAMC,wBAAwBC,OAAgB;IAC9C,MAAMC,gBAAgBD,OAAgB;IAEtC,MAAME,kBAAkBF,OAAO;IAC/B,MAAMG,kBAAkBH,OAAO;IAC/B,MAAMI,UAAUJ,OAAOX;IAEvB,MAAM,CAACgB,OAAOC,SAAS,GAAGC,SAAkB;IAE5C,MAAMC,oBAAoBR,OAAe;IACzC,MAAMS,mBAAmBT,OAAe;IACxC,MAAMU,oBAAoBV,OAAO;IAEjC,MAAMW,wBAAwBX,OAAe;IAC7C,MAAMY,uBAAuBZ,OAAe;IAG5C,MAAMa,kBAAkB;IAExBT,QAAQ,OAAO,GAAGf;IAEl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iC;QAEF,IAAIzC,UAAUQ,cAAc,IAAI,EAC9BkC;QAEF,IAAI1C,UAAUQ,cAAc,OAAO,EACjCmC;QAEF,IAAI3C,UAAUO,wBACZuC;IAEJ,GAAG;QAAC9C;KAAM;IAGV,MAAMiD,gBAAgB;QACpB,IACEjD,UAAUQ,cAAc,OAAO,IAAIR,UAAUQ,cAAc,QAAQ,IAChER,UAAUQ,cAAc,eAAe,EAC1C;YACAF,IACED,UACA;YAEFoB;YACAvB,iBAAiBM,cAAc,OAAO;QACxC,OAAO,IACJR,AAAAA,CAAAA,UAAUQ,cAAc,OAAO,IAAIR,UAAUQ,cAAc,IAAG,KAAMO,OACrE;YACAT,IACED,UACA;YAEFW,SAAS;QACX;IACF;IAEAgC,UAAU;QACR1C,IACED,UACA,CAAC,iDAAiD,EAAEN,KAAK,cAAc,EAAEE,YAAY,QAAQ,EAAED,MAAM,QAAQ,EAAEe,OAAO;QAExH,IAAIhB,MACF+B;aACK;YACLN;YACAyB;QACF;IACF,GAAG;QAAClD;QAAME;KAAY;IAEtB+C,UAAU;QACRpC,gBAAgB,OAAO,GAAG;IAC5B,GAAG,EAAE;IAEL,OAAO;QACL,aAAa;YAAEZ;YAAOe;YAAOb;QAAiB;QAC9C,mBAAmB;YACjBgC;YACAI;YACAF;YACAD;YACAI;YACAC;QACF;IACF;AACF;AAEO,MAAMU,yBAAyB,CACpCpD;IAKA,MAAM,EAAEqD,QAAQ,EAAEC,MAAM,EAAE,GAAGtD;IAC7B,OAAO,AAAoB,cAApB,OAAOqD,WACVA,SAASC,UACTD;AACN"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/lynx-ui-presence",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.140.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/lynx-family/lynx-ui.git",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"clsx": "^2.1.1",
|
|
28
|
-
"@lynx-js/lynx-ui-common": "3.
|
|
28
|
+
"@lynx-js/lynx-ui-common": "3.139.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@lynx-js/react": "0.123.1",
|
package/src/types/index.docs.ts
CHANGED
|
@@ -48,9 +48,9 @@ export interface PresenceAnimationStatus {
|
|
|
48
48
|
/**
|
|
49
49
|
* UI variants applied by Presence based on animation status.
|
|
50
50
|
* Use them as CSS selectors to style different states.
|
|
51
|
-
* @zh Presence 根据状态注入的
|
|
51
|
+
* @zh Presence 根据状态注入的 UI variants,可用于 CSS selector 按状态定制样式。
|
|
52
52
|
*/
|
|
53
|
-
export interface
|
|
53
|
+
export interface PresenceUIVariants {
|
|
54
54
|
/**
|
|
55
55
|
* Applied when `status.open` is true.
|
|
56
56
|
* @zh 当 status.open 为 true 时生效,可用于 `.ui-open { ... }`。
|
|
@@ -82,6 +82,11 @@ export interface PresenceUiVariants {
|
|
|
82
82
|
'ui-animating'?: boolean
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
/**
|
|
86
|
+
* @deprecated Use `PresenceUIVariants` instead.
|
|
87
|
+
*/
|
|
88
|
+
export type PresenceUiVariants = PresenceUIVariants
|
|
89
|
+
|
|
85
90
|
export type PresenceChildrenType = (
|
|
86
91
|
status: PresenceAnimationStatus,
|
|
87
92
|
) => ReactNode
|
|
@@ -99,7 +104,7 @@ export interface PresenceProps {
|
|
|
99
104
|
debugLog?: boolean
|
|
100
105
|
}
|
|
101
106
|
|
|
102
|
-
export interface
|
|
107
|
+
export interface UsePresenceProps {
|
|
103
108
|
show: boolean // The one and only entry for showing the presence content.
|
|
104
109
|
forceMount?: boolean // Force to mount the presence container event the content is not shown.
|
|
105
110
|
state: PresenceState // The core animation state of Presence.
|
|
@@ -130,4 +135,10 @@ export interface PresenceContextType {
|
|
|
130
135
|
}
|
|
131
136
|
}
|
|
132
137
|
|
|
133
|
-
export type
|
|
138
|
+
export type UsePresenceReturnType = PresenceContextType
|
|
139
|
+
|
|
140
|
+
/** @deprecated Use `UsePresenceProps` instead. */
|
|
141
|
+
export type usePresenceProps = UsePresenceProps
|
|
142
|
+
|
|
143
|
+
/** @deprecated Use `UsePresenceReturnType` instead. */
|
|
144
|
+
export type usePresenceReturnType = UsePresenceReturnType
|
package/src/usePresence.tsx
CHANGED
|
@@ -11,14 +11,14 @@ import type {
|
|
|
11
11
|
PresenceAnimationStatus,
|
|
12
12
|
PresenceContextType,
|
|
13
13
|
PresenceProps,
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
UsePresenceProps,
|
|
15
|
+
UsePresenceReturnType,
|
|
16
16
|
} from './types'
|
|
17
17
|
import { PresenceState } from './utils'
|
|
18
18
|
|
|
19
19
|
export const PresenceContext = createContext<PresenceContextType>(null!)
|
|
20
20
|
|
|
21
|
-
export function usePresence(props:
|
|
21
|
+
export function usePresence(props: UsePresenceProps): UsePresenceReturnType {
|
|
22
22
|
const {
|
|
23
23
|
show,
|
|
24
24
|
state,
|