@lynx-js/lynx-ui-presence 0.0.0 → 3.130.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/CHANGELOG.md +26 -0
- package/LICENSE +8 -0
- package/README.md +49 -0
- package/dist/Presence.d.ts +8 -0
- package/dist/Presence.d.ts.map +1 -0
- package/dist/Presence.jsx +35 -0
- package/dist/Presence.jsx.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.jsx +5 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.docs.d.ts +49 -0
- package/dist/types/index.docs.d.ts.map +1 -0
- package/dist/types/index.jsx +0 -0
- package/dist/usePresence.d.ts +8 -0
- package/dist/usePresence.d.ts.map +1 -0
- package/dist/usePresence.jsx +176 -0
- package/dist/usePresence.jsx.map +1 -0
- package/dist/usePresenceGroup.d.ts +20 -0
- package/dist/usePresenceGroup.d.ts.map +1 -0
- package/dist/usePresenceGroup.jsx +79 -0
- package/dist/usePresenceGroup.jsx.map +1 -0
- package/dist/useVisibilityFromPresence.d.ts +12 -0
- package/dist/useVisibilityFromPresence.d.ts.map +1 -0
- package/dist/useVisibilityFromPresence.jsx +14 -0
- package/dist/useVisibilityFromPresence.jsx.map +1 -0
- package/dist/utils.d.ts +24 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.jsx +45 -0
- package/dist/utils.jsx.map +1 -0
- package/package.json +46 -4
- package/src/Presence.tsx +64 -0
- package/src/index.tsx +17 -0
- package/src/types/index.docs.ts +72 -0
- package/src/types/index.ts +5 -0
- package/src/usePresence.tsx +322 -0
- package/src/usePresenceGroup.tsx +187 -0
- package/src/useVisibilityFromPresence.ts +39 -0
- package/src/utils.tsx +97 -0
- package/tsconfig.docs.json +7 -0
- package/tsconfig.json +9 -0
- /package/{index.js → dist/types/index.docs.jsx} +0 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @lynx-js/lynx-ui-presence
|
|
2
|
+
|
|
3
|
+
## 3.130.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- feat: Make the controlled mode and controlled/uncontrolled mixed mode more robust. ([#79](https://github.com/lynx-family/lynx-ui/pull/79))
|
|
8
|
+
|
|
9
|
+
- `@lynx-js/lynx-ui-presence`:
|
|
10
|
+
- Refactor `usePresence` to support better mixed controlled mode.
|
|
11
|
+
- Add `debugLog` prop for debugging presence state transitions.
|
|
12
|
+
- `@lynx-js/lynx-ui-popover`:
|
|
13
|
+
- Add `PopoverBackdrop` component.
|
|
14
|
+
- Support robust controlled mode via `isControlled` and `onVisibleChange`.
|
|
15
|
+
- Fix animation/transition cancel event handling.
|
|
16
|
+
- `@lynx-js/lynx-ui-dialog`:
|
|
17
|
+
- Update to use the robust presence logic.
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- optimize: fix type errors ([#79](https://github.com/lynx-family/lynx-ui/pull/79))
|
|
22
|
+
|
|
23
|
+
- Update files field in all packages to include LICENSE file. ([#79](https://github.com/lynx-family/lynx-ui/pull/79))
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [[`bc1d954`](https://github.com/lynx-family/lynx-ui/commit/bc1d9544d25c5483f5bf199dd279094b8d669520), [`bc1d954`](https://github.com/lynx-family/lynx-ui/commit/bc1d9544d25c5483f5bf199dd279094b8d669520), [`bc1d954`](https://github.com/lynx-family/lynx-ui/commit/bc1d9544d25c5483f5bf199dd279094b8d669520), [`bc1d954`](https://github.com/lynx-family/lynx-ui/commit/bc1d9544d25c5483f5bf199dd279094b8d669520), [`bc1d954`](https://github.com/lynx-family/lynx-ui/commit/bc1d9544d25c5483f5bf199dd279094b8d669520), [`bc1d954`](https://github.com/lynx-family/lynx-ui/commit/bc1d9544d25c5483f5bf199dd279094b8d669520)]:
|
|
26
|
+
- @lynx-js/lynx-ui-common@3.130.0
|
package/LICENSE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# @lynx-js/lynx-ui-presence
|
|
2
|
+
|
|
3
|
+
A Presence component for ReactLynx. It animates elements entering and leaving the view tree.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
We strongly recommend installing and using this component through the main `@lynx-js/lynx-ui` package:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# pnpm (recommended)
|
|
11
|
+
pnpm add @lynx-js/lynx-ui
|
|
12
|
+
|
|
13
|
+
# npm
|
|
14
|
+
npm install @lynx-js/lynx-ui
|
|
15
|
+
|
|
16
|
+
# yarn
|
|
17
|
+
yarn add @lynx-js/lynx-ui
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
_(If necessary, you can still install the standalone package via `pnpm add @lynx-js/lynx-ui-presence`)_
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
`@lynx-js/lynx-ui-presence` is an internal primitive used by higher-level components (for example, `@lynx-js/lynx-ui-dialog`, `@lynx-js/lynx-ui-popover`, and `@lynx-js/lynx-ui-sheet`) to control mount/unmount with enter/exit animation states.
|
|
25
|
+
|
|
26
|
+
It is not expected to be consumed directly in application code, and its API may change without notice. If you need enter/exit animations for overlays and panels, prefer using `Dialog`, `Popover`, or `Sheet` from `@lynx-js/lynx-ui`.
|
|
27
|
+
|
|
28
|
+
- [Dialog examples](https://github.com/lynx-family/lynx-ui/tree/main/apps/examples/Dialog)
|
|
29
|
+
- [Popover examples](https://github.com/lynx-family/lynx-ui/tree/main/apps/examples/Popover)
|
|
30
|
+
- [Sheet examples](https://github.com/lynx-family/lynx-ui/tree/main/apps/examples/Sheet)
|
|
31
|
+
|
|
32
|
+
## Component Structure
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
<Presence>
|
|
36
|
+
</Presence>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
- **`Presence`**: Controls mount/unmount with enter/exit animation states.
|
|
40
|
+
- **`usePresenceGroup`**: Hook for managing presence of a list of items.
|
|
41
|
+
- **`useVisibilityFromPresence`**: Hook for deriving visibility from presence context.
|
|
42
|
+
|
|
43
|
+
## About @lynx-js/lynx-ui
|
|
44
|
+
|
|
45
|
+
This component is part of `@lynx-js/lynx-ui`, a headless UI library officially maintained by the Lynx team, provided as a reference for building flexible, universal, and high-performance ReactLynx components.
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
|
|
49
|
+
[**lynx-ui**](https://github.com/lynx-family/lynx-ui) is [**Apache License 2.0**](./LICENSE) licensed.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PresenceAnimationStatus, PresenceContextType, PresenceProps } from './types';
|
|
2
|
+
export declare const PresenceContext: import("react").Context<PresenceContextType>;
|
|
3
|
+
export declare const renderPresenceChildren: (props: {
|
|
4
|
+
children: PresenceProps["children"];
|
|
5
|
+
status: PresenceAnimationStatus;
|
|
6
|
+
}) => import("react").ReactNode;
|
|
7
|
+
export declare function Presence(props: PresenceProps): import("react").JSX.Element;
|
|
8
|
+
//# sourceMappingURL=Presence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Presence.d.ts","sourceRoot":"","sources":["../src/Presence.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,uBAAuB,EACvB,mBAAmB,EACnB,aAAa,EACd,MAAM,SAAS,CAAA;AAIhB,eAAO,MAAM,eAAe,8CAA4C,CAAA;AAExE,eAAO,MAAM,sBAAsB,GACjC,OAAO;IACL,QAAQ,EAAE,aAAa,CAAC,UAAU,CAAC,CAAA;IACnC,MAAM,EAAE,uBAAuB,CAAA;CAChC,8BAMF,CAAA;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,+BAmC5C"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createContext, useState } from "@lynx-js/react";
|
|
2
|
+
import { usePresence } from "./usePresence.jsx";
|
|
3
|
+
import { PresenceState, resolveAnimationStatus } from "./utils.jsx";
|
|
4
|
+
const PresenceContext = createContext(null);
|
|
5
|
+
const renderPresenceChildren = (props)=>{
|
|
6
|
+
const { children, status } = props;
|
|
7
|
+
return 'function' == typeof children ? children(status) : children;
|
|
8
|
+
};
|
|
9
|
+
function Presence(props) {
|
|
10
|
+
const { show, forceMount, state, setPresenceState, children, enableDelay = false, onOpen, onClose, debugLog } = props;
|
|
11
|
+
const [internalState, setInternalState] = useState(PresenceState.Left);
|
|
12
|
+
const presence = usePresence({
|
|
13
|
+
show,
|
|
14
|
+
state: state ?? internalState,
|
|
15
|
+
setPresenceState: setPresenceState ?? setInternalState,
|
|
16
|
+
enableDelay,
|
|
17
|
+
onOpen,
|
|
18
|
+
onClose,
|
|
19
|
+
debugLog
|
|
20
|
+
});
|
|
21
|
+
const { mount } = presence.controllers;
|
|
22
|
+
const status = resolveAnimationStatus({
|
|
23
|
+
state: state ?? internalState,
|
|
24
|
+
enableDelay
|
|
25
|
+
});
|
|
26
|
+
return <PresenceContext.Provider value={presence}>
|
|
27
|
+
{(mount || forceMount) && renderPresenceChildren({
|
|
28
|
+
children,
|
|
29
|
+
status
|
|
30
|
+
})}
|
|
31
|
+
</PresenceContext.Provider>;
|
|
32
|
+
}
|
|
33
|
+
export { Presence, PresenceContext, renderPresenceChildren };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=Presence.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Presence.jsx","sources":["webpack://@lynx-js/lynx-ui-presence/./src/Presence.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, useState } from '@lynx-js/react'\n\nimport type {\n PresenceAnimationStatus,\n PresenceContextType,\n PresenceProps,\n} from './types'\nimport { usePresence } from './usePresence'\nimport { PresenceState, resolveAnimationStatus } from './utils'\n\nexport const PresenceContext = createContext<PresenceContextType>(null!)\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\nexport function Presence(props: PresenceProps) {\n const {\n show,\n forceMount,\n state,\n setPresenceState,\n children,\n enableDelay = false,\n onOpen,\n onClose,\n debugLog,\n } = props\n const [internalState, setInternalState] = useState<PresenceState>(\n PresenceState.Left,\n )\n const presence = usePresence({\n show,\n state: state ?? internalState,\n setPresenceState: setPresenceState ?? setInternalState,\n enableDelay,\n onOpen,\n onClose,\n debugLog,\n })\n const { mount } = presence.controllers\n const status = resolveAnimationStatus({\n state: state ?? internalState,\n enableDelay,\n })\n\n return (\n <PresenceContext.Provider value={presence}>\n {(mount || forceMount) && renderPresenceChildren({ children, status })}\n </PresenceContext.Provider>\n )\n}\n"],"names":["PresenceContext","createContext","renderPresenceChildren","props","children","status","Presence","show","forceMount","state","setPresenceState","enableDelay","onOpen","onClose","debugLog","internalState","setInternalState","useState","PresenceState","presence","usePresence","mount","resolveAnimationStatus"],"mappings":";;;AAcO,MAAMA,kBAAkBC,cAAmC;AAE3D,MAAMC,yBAAyB,CACpCC;IAKA,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAE,GAAGF;IAC7B,OAAO,AAAoB,cAApB,OAAOC,WACVA,SAASC,UACTD;AACN;AAEO,SAASE,SAASH,KAAoB;IAC3C,MAAM,EACJI,IAAI,EACJC,UAAU,EACVC,KAAK,EACLC,gBAAgB,EAChBN,QAAQ,EACRO,cAAc,KAAK,EACnBC,MAAM,EACNC,OAAO,EACPC,QAAQ,EACT,GAAGX;IACJ,MAAM,CAACY,eAAeC,iBAAiB,GAAGC,SACxCC,cAAc,IAAI;IAEpB,MAAMC,WAAWC,YAAY;QAC3Bb;QACA,OAAOE,SAASM;QAChB,kBAAkBL,oBAAoBM;QACtCL;QACAC;QACAC;QACAC;IACF;IACA,MAAM,EAAEO,KAAK,EAAE,GAAGF,SAAS,WAAW;IACtC,MAAMd,SAASiB,uBAAuB;QACpC,OAAOb,SAASM;QAChBJ;IACF;IAEA,QACGX,gBAAgB,SAAS,OAAOmB,UAAU;MACzC,CAAEE,AAAAA,CAAAA,SAASb,UAAS,KAAMN,uBAAuB;QAAEE;QAAUC;IAAO,GAAG;IACzE,EAAEL,gBAAgB;AAEtB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Presence, PresenceContext, renderPresenceChildren } from './Presence';
|
|
2
|
+
export { PresenceState, resolveAnimationStatus, presenceClassVariants, } from './utils';
|
|
3
|
+
export { usePresenceGroup } from './usePresenceGroup';
|
|
4
|
+
export { useVisibilityFromPresence } from './useVisibilityFromPresence';
|
|
5
|
+
export type * from './types';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAE9E,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,SAAS,CAAA;AAEhB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAA;AAEvE,mBAAmB,SAAS,CAAA"}
|
package/dist/index.jsx
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Presence, PresenceContext, renderPresenceChildren } from "./Presence.jsx";
|
|
2
|
+
import { PresenceState, presenceClassVariants, resolveAnimationStatus } from "./utils.jsx";
|
|
3
|
+
import { usePresenceGroup } from "./usePresenceGroup.jsx";
|
|
4
|
+
import { useVisibilityFromPresence } from "./useVisibilityFromPresence.jsx";
|
|
5
|
+
export { Presence, PresenceContext, PresenceState, presenceClassVariants, renderPresenceChildren, resolveAnimationStatus, usePresenceGroup, useVisibilityFromPresence };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAIA,mBAAmB,cAAc,CAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { AnimationEvent, EventHandler, TransitionEvent } from '@lynx-js/types';
|
|
3
|
+
import type { PresenceState } from '../utils';
|
|
4
|
+
export interface PresenceAnimationStatus {
|
|
5
|
+
open?: boolean;
|
|
6
|
+
closed?: boolean;
|
|
7
|
+
leaving?: boolean;
|
|
8
|
+
entering?: boolean;
|
|
9
|
+
animating?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export type PresenceChildrenType = (status: PresenceAnimationStatus) => ReactNode;
|
|
12
|
+
export interface PresenceProps {
|
|
13
|
+
show: boolean;
|
|
14
|
+
forceMount?: boolean;
|
|
15
|
+
children?: ReactNode | PresenceChildrenType;
|
|
16
|
+
state?: PresenceState;
|
|
17
|
+
setPresenceState?: (state: PresenceState) => void;
|
|
18
|
+
enableDelay?: boolean;
|
|
19
|
+
onClose?: () => void;
|
|
20
|
+
onOpen?: () => void;
|
|
21
|
+
debugLog?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface usePresenceProps {
|
|
24
|
+
show: boolean;
|
|
25
|
+
forceMount?: boolean;
|
|
26
|
+
state: PresenceState;
|
|
27
|
+
setPresenceState: (state: PresenceState) => void;
|
|
28
|
+
enableDelay?: boolean;
|
|
29
|
+
onOpen?: () => void;
|
|
30
|
+
onClose?: () => void;
|
|
31
|
+
debugLog?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface PresenceContextType {
|
|
34
|
+
controllers: {
|
|
35
|
+
state: PresenceState;
|
|
36
|
+
mount: boolean;
|
|
37
|
+
setPresenceState: (state: PresenceState) => void;
|
|
38
|
+
};
|
|
39
|
+
animationHandlers: {
|
|
40
|
+
handleKFStart: EventHandler<AnimationEvent>;
|
|
41
|
+
handleKFCancel: EventHandler<AnimationEvent>;
|
|
42
|
+
handleTransitionCancel: EventHandler<TransitionEvent>;
|
|
43
|
+
handleKFEnd: EventHandler<AnimationEvent>;
|
|
44
|
+
handleTransitionStart: EventHandler<TransitionEvent>;
|
|
45
|
+
handleTransitionEnd: EventHandler<TransitionEvent>;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export type usePresenceReturnType = PresenceContextType;
|
|
49
|
+
//# sourceMappingURL=index.docs.d.ts.map
|
|
@@ -0,0 +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,KAAK,EACV,cAAc,EACd,YAAY,EACZ,eAAe,EAChB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAE7C,MAAM,WAAW,uBAAuB;IACtC,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,MAAM,CAAC,EAAE,OAAO,CAAA;IAEhB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,MAAM,MAAM,oBAAoB,GAAG,CACjC,MAAM,EAAE,uBAAuB,KAC5B,SAAS,CAAA;AAEd,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,OAAO,CAAA;IACb,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,QAAQ,CAAC,EAAE,SAAS,GAAG,oBAAoB,CAAA;IAC3C,KAAK,CAAC,EAAE,aAAa,CAAA;IACrB,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAA;IACjD,WAAW,CAAC,EAAE,OAAO,CAAA;IAErB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAA;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,OAAO,CAAA;IACb,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,KAAK,EAAE,aAAa,CAAA;IACpB,gBAAgB,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAA;IAChD,WAAW,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"}
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PresenceAnimationStatus, PresenceContextType, PresenceProps, usePresenceProps, usePresenceReturnType } from './types';
|
|
2
|
+
export declare const PresenceContext: import("react").Context<PresenceContextType>;
|
|
3
|
+
export declare function usePresence(props: usePresenceProps): usePresenceReturnType;
|
|
4
|
+
export declare const renderPresenceChildren: (props: {
|
|
5
|
+
children: PresenceProps["children"];
|
|
6
|
+
status: PresenceAnimationStatus;
|
|
7
|
+
}) => import("react").ReactNode;
|
|
8
|
+
//# sourceMappingURL=usePresence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePresence.d.ts","sourceRoot":"","sources":["../src/usePresence.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,uBAAuB,EACvB,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,SAAS,CAAA;AAGhB,eAAO,MAAM,eAAe,8CAA4C,CAAA;AAExE,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,qBAAqB,CAiS1E;AAED,eAAO,MAAM,sBAAsB,GACjC,OAAO;IACL,QAAQ,EAAE,aAAa,CAAC,UAAU,CAAC,CAAA;IACnC,MAAM,EAAE,uBAAuB,CAAA;CAChC,8BAMF,CAAA"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { createContext, useEffect, useRef, useState } from "@lynx-js/react";
|
|
2
|
+
import { delayFrames, log } from "@lynx-js/lynx-ui-common";
|
|
3
|
+
import { PresenceState } from "./utils.jsx";
|
|
4
|
+
const PresenceContext = createContext(null);
|
|
5
|
+
function usePresence(props) {
|
|
6
|
+
const { show, state, enableDelay = false, setPresenceState, onOpen, onClose, debugLog = false } = props;
|
|
7
|
+
log(debugLog, `[lynx-ui-presence][usePresence] init, show: ${show}, state: ${state}, enableDelay: ${enableDelay}`);
|
|
8
|
+
const enteringStateWithDelay = enableDelay ? PresenceState.DelayedEntering : PresenceState.Entering;
|
|
9
|
+
const isTransitionAnimating = useRef(false);
|
|
10
|
+
const isKFAnimating = useRef(false);
|
|
11
|
+
const isInitialRender = useRef(true);
|
|
12
|
+
const showRef = useRef(show);
|
|
13
|
+
const [mount, setMount] = useState(false);
|
|
14
|
+
const enteringLoopIdRef = useRef(0);
|
|
15
|
+
const leavingLoopIdRef = useRef(0);
|
|
16
|
+
const showScheduleIdRef = useRef(0);
|
|
17
|
+
const enteringWaitFramesRef = useRef(0);
|
|
18
|
+
const leavingWaitFramesRef = useRef(0);
|
|
19
|
+
const MAX_WAIT_FRAMES = 24;
|
|
20
|
+
showRef.current = show;
|
|
21
|
+
const notAnimating = ()=>false === isKFAnimating.current && false === isTransitionAnimating.current;
|
|
22
|
+
const handleAnimationStart = ()=>{
|
|
23
|
+
log(debugLog, `[lynx-ui-presence][usePresence] handleAnimationStart state:${state}, show:${show}, isTransition:${isTransitionAnimating.current}, isKFAnimating:${isKFAnimating.current}`);
|
|
24
|
+
};
|
|
25
|
+
const handleAnimationEnd = ()=>{
|
|
26
|
+
if ((state === PresenceState.Entering || state === PresenceState.DelayedEntering) && notAnimating()) showRef.current ? setPresenceState(PresenceState.Entered) : setPresenceState(PresenceState.Leaving);
|
|
27
|
+
if (state === PresenceState.Leaving && notAnimating()) setPresenceState(PresenceState.Left);
|
|
28
|
+
};
|
|
29
|
+
const handleKFStart = ()=>{
|
|
30
|
+
isKFAnimating.current = true;
|
|
31
|
+
enteringLoopIdRef.current += 1;
|
|
32
|
+
leavingLoopIdRef.current += 1;
|
|
33
|
+
log(debugLog, `[lynx-ui-presence][usePresence] KF start, loopId: ${leavingLoopIdRef.current}`);
|
|
34
|
+
handleAnimationStart();
|
|
35
|
+
};
|
|
36
|
+
const handleTransitionStart = ()=>{
|
|
37
|
+
isTransitionAnimating.current = true;
|
|
38
|
+
enteringLoopIdRef.current += 1;
|
|
39
|
+
leavingLoopIdRef.current += 1;
|
|
40
|
+
log(debugLog, `[lynx-ui-presence][usePresence] Transition start, loopId: ${leavingLoopIdRef.current}`);
|
|
41
|
+
handleAnimationStart();
|
|
42
|
+
};
|
|
43
|
+
const handleKFEnd = (_e)=>{
|
|
44
|
+
isKFAnimating.current = false;
|
|
45
|
+
log(debugLog, `[lynx-ui-presence][usePresence] KF end, loopId: ${leavingLoopIdRef.current}`);
|
|
46
|
+
handleAnimationEnd();
|
|
47
|
+
};
|
|
48
|
+
const handleKFCancel = ()=>{
|
|
49
|
+
isKFAnimating.current = false;
|
|
50
|
+
log(debugLog, `[lynx-ui-presence][usePresence] KF cancel, loopId: ${leavingLoopIdRef.current}`);
|
|
51
|
+
handleAnimationEnd();
|
|
52
|
+
};
|
|
53
|
+
const handleTransitionCancel = ()=>{
|
|
54
|
+
isTransitionAnimating.current = false;
|
|
55
|
+
log(debugLog, `[lynx-ui-presence][usePresence] Transition cancel, loopId: ${leavingLoopIdRef.current}`);
|
|
56
|
+
handleAnimationEnd();
|
|
57
|
+
};
|
|
58
|
+
const handleTransitionEnd = (_e)=>{
|
|
59
|
+
isTransitionAnimating.current = false;
|
|
60
|
+
log(debugLog, `[lynx-ui-presence][usePresence] Transition end, loopId: ${leavingLoopIdRef.current}`);
|
|
61
|
+
handleAnimationEnd();
|
|
62
|
+
};
|
|
63
|
+
const handleStateEntered = ()=>{
|
|
64
|
+
onOpen?.();
|
|
65
|
+
};
|
|
66
|
+
const handleStateLeft = ()=>{
|
|
67
|
+
if (!isInitialRender.current) onClose?.();
|
|
68
|
+
log(debugLog, '[lynx-ui-presence][usePresence] set mount=false (Left)');
|
|
69
|
+
setMount(false);
|
|
70
|
+
};
|
|
71
|
+
const handleStateLeaving = ()=>{
|
|
72
|
+
leavingWaitFramesRef.current = 0;
|
|
73
|
+
leavingLoopIdRef.current += 1;
|
|
74
|
+
const loopId = leavingLoopIdRef.current;
|
|
75
|
+
log(debugLog, `[lynx-ui-presence][usePresence] leaving loop scheduled, loopId: ${loopId}`);
|
|
76
|
+
const tryLeft = ()=>{
|
|
77
|
+
if (loopId !== leavingLoopIdRef.current) return;
|
|
78
|
+
if (!notAnimating()) return;
|
|
79
|
+
if (leavingWaitFramesRef.current >= MAX_WAIT_FRAMES) {
|
|
80
|
+
log(debugLog, `[lynx-ui-presence][usePresence] leaving timeout reached, loopId: ${loopId}, frames: ${leavingWaitFramesRef.current}`);
|
|
81
|
+
setPresenceState(PresenceState.Left);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
leavingWaitFramesRef.current += 1;
|
|
85
|
+
delayFrames(1, tryLeft);
|
|
86
|
+
};
|
|
87
|
+
delayFrames(1, tryLeft);
|
|
88
|
+
};
|
|
89
|
+
const handleStateEnteringWithDelay = ()=>{
|
|
90
|
+
enteringWaitFramesRef.current = 0;
|
|
91
|
+
enteringLoopIdRef.current += 1;
|
|
92
|
+
const loopId = enteringLoopIdRef.current;
|
|
93
|
+
log(debugLog, `[lynx-ui-presence][usePresence] entering loop scheduled, loopId: ${loopId}`);
|
|
94
|
+
const tryEntered = ()=>{
|
|
95
|
+
if (loopId !== enteringLoopIdRef.current) return;
|
|
96
|
+
if (!notAnimating()) return;
|
|
97
|
+
if (enteringWaitFramesRef.current >= MAX_WAIT_FRAMES) {
|
|
98
|
+
log(debugLog, `[lynx-ui-presence][usePresence] entering timeout reached, loopId: ${loopId}, frames: ${enteringWaitFramesRef.current}`);
|
|
99
|
+
setPresenceState(PresenceState.Entered);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
enteringWaitFramesRef.current += 1;
|
|
103
|
+
delayFrames(1, tryEntered);
|
|
104
|
+
};
|
|
105
|
+
delayFrames(1, tryEntered);
|
|
106
|
+
};
|
|
107
|
+
useEffect(()=>{
|
|
108
|
+
log(debugLog, `[lynx-ui-presence][usePresence] state effect, state: ${state}, show: ${show}, enableDelay: ${enableDelay}, isTransitionAnimating: ${isTransitionAnimating.current}, isKFAnimating: ${isKFAnimating.current}`);
|
|
109
|
+
if (state === PresenceState.Entered) handleStateEntered();
|
|
110
|
+
if (state === PresenceState.Left) handleStateLeft();
|
|
111
|
+
if (state === PresenceState.Leaving) handleStateLeaving();
|
|
112
|
+
if (state === enteringStateWithDelay) handleStateEnteringWithDelay();
|
|
113
|
+
}, [
|
|
114
|
+
state
|
|
115
|
+
]);
|
|
116
|
+
const handleShow = (scheduleId)=>{
|
|
117
|
+
log(debugLog, '[lynx-ui-presence][usePresence] set mount=true');
|
|
118
|
+
setMount(true);
|
|
119
|
+
log(debugLog, '[lynx-ui-presence][usePresence] schedule set Entering in 8 frames');
|
|
120
|
+
delayFrames(8, ()=>{
|
|
121
|
+
if (scheduleId !== showScheduleIdRef.current) return;
|
|
122
|
+
setPresenceState(PresenceState.Entering);
|
|
123
|
+
});
|
|
124
|
+
if (enableDelay) {
|
|
125
|
+
log(debugLog, '[lynx-ui-presence][usePresence] schedule set DelayedEntering in 16 frames');
|
|
126
|
+
delayFrames(16, ()=>{
|
|
127
|
+
if (scheduleId !== showScheduleIdRef.current) return;
|
|
128
|
+
setPresenceState(PresenceState.DelayedEntering);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
const handleDismiss = ()=>{
|
|
133
|
+
if (state === PresenceState.Entered || state === PresenceState.Entering || state === PresenceState.DelayedEntering) {
|
|
134
|
+
log(debugLog, '[lynx-ui-presence][usePresence] show=false -> set PresenceState.Leaving');
|
|
135
|
+
setPresenceState(PresenceState.Leaving);
|
|
136
|
+
} else if (state === PresenceState.Initial && mount) {
|
|
137
|
+
log(debugLog, '[lynx-ui-presence][usePresence] show=false in Initial -> set mount=false');
|
|
138
|
+
setMount(false);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
useEffect(()=>{
|
|
142
|
+
log(debugLog, `[lynx-ui-presence][usePresence] show effect show:${show}, enableDelay:${enableDelay}, state:${state}, mount:${mount}`);
|
|
143
|
+
showScheduleIdRef.current += 1;
|
|
144
|
+
const scheduleId = showScheduleIdRef.current;
|
|
145
|
+
if (show) handleShow(scheduleId);
|
|
146
|
+
else handleDismiss();
|
|
147
|
+
}, [
|
|
148
|
+
show,
|
|
149
|
+
enableDelay
|
|
150
|
+
]);
|
|
151
|
+
useEffect(()=>{
|
|
152
|
+
isInitialRender.current = false;
|
|
153
|
+
}, []);
|
|
154
|
+
return {
|
|
155
|
+
controllers: {
|
|
156
|
+
state,
|
|
157
|
+
mount,
|
|
158
|
+
setPresenceState
|
|
159
|
+
},
|
|
160
|
+
animationHandlers: {
|
|
161
|
+
handleKFStart,
|
|
162
|
+
handleKFCancel,
|
|
163
|
+
handleKFEnd,
|
|
164
|
+
handleTransitionStart,
|
|
165
|
+
handleTransitionCancel,
|
|
166
|
+
handleTransitionEnd
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const renderPresenceChildren = (props)=>{
|
|
171
|
+
const { children, status } = props;
|
|
172
|
+
return 'function' == typeof children ? children(status) : children;
|
|
173
|
+
};
|
|
174
|
+
export { PresenceContext, renderPresenceChildren, usePresence };
|
|
175
|
+
|
|
176
|
+
//# sourceMappingURL=usePresence.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePresence.jsx","sources":["webpack://@lynx-js/lynx-ui-presence/./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 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 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 setPresenceState(PresenceState.Left)\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 onOpen?.()\n }\n\n const handleStateLeft = () => {\n if (!isInitialRender.current) {\n onClose?.()\n }\n log(debugLog, '[lynx-ui-presence][usePresence] set mount=false (Left)')\n setMount(false)\n }\n\n const handleStateLeaving = () => {\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 setPresenceState(PresenceState.Left)\n return\n }\n leavingWaitFramesRef.current += 1\n delayFrames(1, tryLeft)\n }\n\n delayFrames(1, tryLeft)\n }\n\n const handleStateEnteringWithDelay = () => {\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 setPresenceState(PresenceState.Entered)\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 handleShow = (scheduleId: number) => {\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) 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) return\n setPresenceState(PresenceState.DelayedEntering)\n })\n }\n }\n\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 setPresenceState(PresenceState.Leaving)\n } else if (state === PresenceState.Initial && mount) {\n log(\n debugLog,\n '[lynx-ui-presence][usePresence] show=false in Initial -> 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 showScheduleIdRef.current += 1\n const scheduleId = showScheduleIdRef.current\n if (show) {\n handleShow(scheduleId)\n } else {\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","showRef","mount","setMount","useState","enteringLoopIdRef","leavingLoopIdRef","showScheduleIdRef","enteringWaitFramesRef","leavingWaitFramesRef","MAX_WAIT_FRAMES","notAnimating","handleAnimationStart","handleAnimationEnd","handleKFStart","handleTransitionStart","handleKFEnd","_e","handleKFCancel","handleTransitionCancel","handleTransitionEnd","handleStateEntered","handleStateLeft","handleStateLeaving","loopId","tryLeft","delayFrames","handleStateEnteringWithDelay","tryEntered","useEffect","handleShow","scheduleId","handleDismiss","renderPresenceChildren","children","status"],"mappings":";;;AAkBO,MAAMA,kBAAkBC,cAAmC;AAE3D,SAASC,YAAYC,KAAuB;IACjD,MAAM,EACJC,IAAI,EACJC,KAAK,EACLC,cAA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Y,IAAI;gBACd,IAAIK,eAAexB,kBAAkB,OAAO,EAAE;gBAC9CjB,iBAAiBM,cAAc,eAAe;YAChD;QACF;IACF;IAEA,MAAMoC,gBAAgB;QACpB,IACE5C,UAAUQ,cAAc,OAAO,IAAIR,UAAUQ,cAAc,QAAQ,IAChER,UAAUQ,cAAc,eAAe,EAC1C;YACAF,IACED,UACA;YAEFH,iBAAiBM,cAAc,OAAO;QACxC,OAAO,IAAIR,UAAUQ,cAAc,OAAO,IAAIM,OAAO;YACnDR,IACED,UACA;YAEFU,SAAS;QACX;IACF;IAEA0B,UAAU;QACRnC,IACED,UACA,CAAC,iDAAiD,EAAEN,KAAK,cAAc,EAAEE,YAAY,QAAQ,EAAED,MAAM,QAAQ,EAAEc,OAAO;QAExHK,kBAAkB,OAAO,IAAI;QAC7B,MAAMwB,aAAaxB,kBAAkB,OAAO;QAC5C,IAAIpB,MACF2C,WAAWC;aAEXC;IAEJ,GAAG;QAAC7C;QAAME;KAAY;IAEtBwC,UAAU;QACR7B,gBAAgB,OAAO,GAAG;IAC5B,GAAG,EAAE;IAEL,OAAO;QACL,aAAa;YAAEZ;YAAOc;YAAOZ;QAAiB;QAC9C,mBAAmB;YACjBwB;YACAI;YACAF;YACAD;YACAI;YACAC;QACF;IACF;AACF;AAEO,MAAMa,yBAAyB,CACpC/C;IAKA,MAAM,EAAEgD,QAAQ,EAAEC,MAAM,EAAE,GAAGjD;IAC7B,OAAO,AAAoB,cAApB,OAAOgD,WACVA,SAASC,UACTD;AACN"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { PresenceChildrenType, PresenceContextType } from './types';
|
|
3
|
+
import { PresenceState } from './utils';
|
|
4
|
+
export declare const PresenceContext: import("react").Context<PresenceContextType>;
|
|
5
|
+
export interface usePresenceGroupProps {
|
|
6
|
+
show: boolean;
|
|
7
|
+
forceMount: boolean;
|
|
8
|
+
setGroupState?: (state: PresenceState) => void;
|
|
9
|
+
enableDelay?: boolean;
|
|
10
|
+
children?: ReactNode | PresenceChildrenType | Array<ReactNode | PresenceChildrenType>;
|
|
11
|
+
onOpen?: () => void;
|
|
12
|
+
onClose?: () => void;
|
|
13
|
+
debugLog?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface usePresenceGroupReturnType {
|
|
16
|
+
renderChildren: ReactNode;
|
|
17
|
+
mountView: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare const usePresenceGroup: (props: usePresenceGroupProps) => usePresenceGroupReturnType;
|
|
20
|
+
//# sourceMappingURL=usePresenceGroup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePresenceGroup.d.ts","sourceRoot":"","sources":["../src/usePresenceGroup.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG/C,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAEvC,eAAO,MAAM,eAAe,8CAA4C,CAAA;AAExE,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,OAAO,CAAA;IACb,UAAU,EAAE,OAAO,CAAA;IACnB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAA;IAC9C,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,QAAQ,CAAC,EACL,SAAS,GACT,oBAAoB,GACpB,KAAK,CAAC,SAAS,GAAG,oBAAoB,CAAC,CAAA;IAC3C,MAAM,CAAC,EAAE,MAAM,IAAI,CAAA;IACnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,MAAM,WAAW,0BAA0B;IACzC,cAAc,EAAE,SAAS,CAAA;IACzB,SAAS,EAAE,OAAO,CAAA;CACnB;AAGD,eAAO,MAAM,gBAAgB,EAAE,CAC7B,KAAK,EAAE,qBAAqB,KACzB,0BAiJJ,CAAA"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { createContext, useCallback, useEffect, useMemo, useState } from "@lynx-js/react";
|
|
2
|
+
import { Presence } from "./Presence.jsx";
|
|
3
|
+
import { PresenceState } from "./utils.jsx";
|
|
4
|
+
const PresenceContext = createContext(null);
|
|
5
|
+
const usePresenceGroup = (props)=>{
|
|
6
|
+
const { show, forceMount = false, children, enableDelay = false, onOpen, onClose, setGroupState, debugLog } = props;
|
|
7
|
+
const [_, setMountingChildrenCount] = useState(0);
|
|
8
|
+
const [mountView, setMountView] = useState(show);
|
|
9
|
+
const childrenSize = Array.isArray(children) ? children.length : children ? 1 : 0;
|
|
10
|
+
const [stateGroup, setStateGroup] = useState(Array.from({
|
|
11
|
+
length: childrenSize
|
|
12
|
+
}, ()=>PresenceState.Left));
|
|
13
|
+
const getGroupState = (states)=>{
|
|
14
|
+
if (states.some((state)=>state === PresenceState.DelayedEntering)) return PresenceState.DelayedEntering;
|
|
15
|
+
if (states.some((state)=>state === PresenceState.Entering)) return PresenceState.Entering;
|
|
16
|
+
if (states.some((state)=>state === PresenceState.Leaving)) return PresenceState.Leaving;
|
|
17
|
+
if (states.every((state)=>state === PresenceState.Entered)) return PresenceState.Entered;
|
|
18
|
+
states.every((state)=>state === PresenceState.Left);
|
|
19
|
+
return PresenceState.Left;
|
|
20
|
+
};
|
|
21
|
+
const updateStateGroup = (index, newState)=>{
|
|
22
|
+
setStateGroup((prev)=>{
|
|
23
|
+
const newStateGroup = [
|
|
24
|
+
...prev
|
|
25
|
+
];
|
|
26
|
+
newStateGroup[index] = newState;
|
|
27
|
+
if (setGroupState) setGroupState(getGroupState(newStateGroup));
|
|
28
|
+
return newStateGroup;
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
const onChildOpen = useCallback(()=>{
|
|
32
|
+
setMountingChildrenCount((prev)=>{
|
|
33
|
+
const count = prev + 1;
|
|
34
|
+
if (children && (Array.isArray(children) && count === children.length || !Array.isArray(children) && 1 === count)) onOpen?.();
|
|
35
|
+
return count;
|
|
36
|
+
});
|
|
37
|
+
}, [
|
|
38
|
+
children,
|
|
39
|
+
onOpen
|
|
40
|
+
]);
|
|
41
|
+
const onChildClose = useCallback(()=>{
|
|
42
|
+
setMountingChildrenCount((prev)=>{
|
|
43
|
+
const count = prev - 1;
|
|
44
|
+
if (0 === count) {
|
|
45
|
+
onClose?.();
|
|
46
|
+
setMountView(false);
|
|
47
|
+
}
|
|
48
|
+
return count;
|
|
49
|
+
});
|
|
50
|
+
}, [
|
|
51
|
+
onClose
|
|
52
|
+
]);
|
|
53
|
+
const renderChildren = useMemo(()=>Array.isArray(children) ? children.map((child, index)=><Presence key={index} show={show} forceMount={forceMount} state={stateGroup[index]} setPresenceState={(state)=>updateStateGroup(index, state)} enableDelay={enableDelay} onOpen={onChildOpen} onClose={onChildClose} debugLog={debugLog}>
|
|
54
|
+
{child}
|
|
55
|
+
</Presence>) : children ? <Presence show={show} forceMount={forceMount} state={stateGroup[0]} setPresenceState={(state)=>updateStateGroup(0, state)} enableDelay={enableDelay} onOpen={onChildOpen} onClose={onChildClose} debugLog={debugLog}>
|
|
56
|
+
{children}
|
|
57
|
+
</Presence> : null, [
|
|
58
|
+
show,
|
|
59
|
+
children,
|
|
60
|
+
stateGroup,
|
|
61
|
+
onChildClose,
|
|
62
|
+
onChildOpen,
|
|
63
|
+
forceMount,
|
|
64
|
+
enableDelay,
|
|
65
|
+
debugLog
|
|
66
|
+
]);
|
|
67
|
+
useEffect(()=>{
|
|
68
|
+
if (show) setMountView(true);
|
|
69
|
+
}, [
|
|
70
|
+
show
|
|
71
|
+
]);
|
|
72
|
+
return {
|
|
73
|
+
renderChildren,
|
|
74
|
+
mountView
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
export { PresenceContext, usePresenceGroup };
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=usePresenceGroup.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePresenceGroup.jsx","sources":["webpack://@lynx-js/lynx-ui-presence/./src/usePresenceGroup.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 {\n createContext,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from '@lynx-js/react'\nimport type { ReactNode } from '@lynx-js/react'\n\nimport { Presence } from './Presence'\nimport type { PresenceChildrenType, PresenceContextType } from './types'\nimport { PresenceState } from './utils'\n\nexport const PresenceContext = createContext<PresenceContextType>(null!)\n\nexport interface usePresenceGroupProps {\n show: boolean\n forceMount: boolean\n setGroupState?: (state: PresenceState) => void\n enableDelay?: boolean\n children?:\n | ReactNode\n | PresenceChildrenType\n | Array<ReactNode | PresenceChildrenType>\n onOpen?: () => void\n onClose?: () => void\n debugLog?: boolean\n}\n\nexport interface usePresenceGroupReturnType {\n renderChildren: ReactNode\n mountView: boolean\n}\n// Manage a group of Presence components.\n// Wrap all child nodes with Presence and ensure that the onOpen and onClose events are triggered after all animations are completed.\nexport const usePresenceGroup: (\n props: usePresenceGroupProps,\n) => usePresenceGroupReturnType = (props) => {\n const {\n show,\n forceMount = false,\n children,\n enableDelay = false,\n onOpen,\n onClose,\n setGroupState,\n debugLog,\n } = props\n\n const [_, setMountingChildrenCount] = useState<number>(\n 0,\n )\n const [mountView, setMountView] = useState<boolean>(show)\n\n const childrenSize = Array.isArray(children)\n ? children.length\n : (children ? 1 : 0)\n const [stateGroup, setStateGroup] = useState<PresenceState[]>(\n Array.from({ length: childrenSize }, () => PresenceState.Left),\n )\n\n // Determine the overall state based on the stateGroup\n const getGroupState = (states: PresenceState[]): PresenceState => {\n // The state in Presence will stop the PresenceState from changing to DelayedEntering if the delay is disabled. No need to double check it in upper presence group.\n if (\n states.some(state => state === PresenceState.DelayedEntering)\n ) {\n return PresenceState.DelayedEntering\n }\n if (\n states.some(state => state === PresenceState.Entering)\n ) {\n return PresenceState.Entering\n }\n if (states.some(state => state === PresenceState.Leaving)) {\n return PresenceState.Leaving\n }\n if (states.every(state => state === PresenceState.Entered)) {\n return PresenceState.Entered\n }\n if (states.every(state => state === PresenceState.Left)) {\n return PresenceState.Left\n }\n return PresenceState.Left\n }\n\n const updateStateGroup = (index: number, newState: PresenceState) => {\n setStateGroup(prev => {\n const newStateGroup = [...prev]\n newStateGroup[index] = newState\n if (setGroupState) {\n setGroupState(getGroupState(newStateGroup))\n }\n return newStateGroup\n })\n }\n\n const onChildOpen = useCallback(() => {\n setMountingChildrenCount((prev) => {\n const count = prev + 1\n if (\n children\n && ((Array.isArray(children) && count === children.length)\n || (!Array.isArray(children) && count === 1))\n ) {\n onOpen?.()\n }\n return count\n })\n }, [children, onOpen])\n\n const onChildClose = useCallback(() => {\n setMountingChildrenCount((prev) => {\n const count = prev - 1\n if (count === 0) {\n onClose?.()\n setMountView(false)\n }\n return count\n })\n }, [onClose])\n\n const renderChildren = useMemo(() => {\n return Array.isArray(children)\n ? children.map(\n (child: ReactNode | PresenceChildrenType, index: number) => {\n return (\n <Presence\n key={index}\n show={show}\n forceMount={forceMount}\n state={stateGroup[index]}\n setPresenceState={(state: PresenceState) =>\n updateStateGroup(index, state)}\n enableDelay={enableDelay}\n onOpen={onChildOpen}\n onClose={onChildClose}\n debugLog={debugLog}\n >\n {child}\n </Presence>\n )\n },\n )\n : (children\n ? (\n <Presence\n show={show}\n forceMount={forceMount}\n state={stateGroup[0]}\n setPresenceState={(state: PresenceState) =>\n updateStateGroup(0, state)}\n enableDelay={enableDelay}\n onOpen={onChildOpen}\n onClose={onChildClose}\n debugLog={debugLog}\n >\n {children}\n </Presence>\n )\n : null)\n }, [\n show,\n children,\n stateGroup,\n onChildClose,\n onChildOpen,\n forceMount,\n enableDelay,\n debugLog,\n ])\n\n useEffect(() => {\n if (show) {\n setMountView(true)\n }\n }, [show])\n\n return {\n renderChildren,\n mountView,\n }\n}\n"],"names":["PresenceContext","createContext","usePresenceGroup","props","show","forceMount","children","enableDelay","onOpen","onClose","setGroupState","debugLog","_","setMountingChildrenCount","useState","mountView","setMountView","childrenSize","Array","stateGroup","setStateGroup","PresenceState","getGroupState","states","state","updateStateGroup","index","newState","prev","newStateGroup","onChildOpen","useCallback","count","onChildClose","renderChildren","useMemo","child","Presence","useEffect"],"mappings":";;;AAiBO,MAAMA,kBAAkBC,cAAmC;AAsB3D,MAAMC,mBAEqB,CAACC;IACjC,MAAM,EACJC,IAAI,EACJC,aAAa,KAAK,EAClBC,QAAQ,EACRC,cAAc,KAAK,EACnBC,MAAM,EACNC,OAAO,EACPC,aAAa,EACbC,QAAQ,EACT,GAAGR;IAEJ,MAAM,CAACS,GAAGC,yBAAyB,GAAGC,SACpC;IAEF,MAAM,CAACC,WAAWC,aAAa,GAAGF,SAAkBV;IAEpD,MAAMa,eAAeC,MAAM,OAAO,CAACZ,YAC/BA,SAAS,MAAM,GACdA,WAAW,IAAI;IACpB,MAAM,CAACa,YAAYC,cAAc,GAAGN,SAClCI,MAAM,IAAI,CAAC;QAAE,QAAQD;IAAa,GAAG,IAAMI,cAAc,IAAI;IAI/D,MAAMC,gBAAgB,CAACC;QAErB,IACEA,OAAO,IAAI,CAACC,CAAAA,QAASA,UAAUH,cAAc,eAAe,GAE5D,OAAOA,cAAc,eAAe;QAEtC,IACEE,OAAO,IAAI,CAACC,CAAAA,QAASA,UAAUH,cAAc,QAAQ,GAErD,OAAOA,cAAc,QAAQ;QAE/B,IAAIE,OAAO,IAAI,CAACC,CAAAA,QAASA,UAAUH,cAAc,OAAO,GACtD,OAAOA,cAAc,OAAO;QAE9B,IAAIE,OAAO,KAAK,CAACC,CAAAA,QAASA,UAAUH,cAAc,OAAO,GACvD,OAAOA,cAAc,OAAO;QAE1BE,OAAO,KAAK,CAACC,CAAAA,QAASA,UAAUH,cAAc,IAAI;QAGtD,OAAOA,cAAc,IAAI;IAC3B;IAEA,MAAMI,mBA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,aAAa;IAEjB,GAAG;QAACZ;KAAK;IAET,OAAO;QACL8B;QACAnB;IACF;AACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
2
|
+
import { PresenceState } from './utils';
|
|
3
|
+
/**
|
|
4
|
+
* A hook that derives visibility state from a PresenceState.
|
|
5
|
+
* It returns 'visible' when the presence state indicates the component
|
|
6
|
+
* is entering, present, or leaving, and 'hidden' otherwise.
|
|
7
|
+
*
|
|
8
|
+
* @param state The current PresenceState.
|
|
9
|
+
* @returns CSSProperties['visibility'] ('visible' or 'hidden').
|
|
10
|
+
*/
|
|
11
|
+
export declare function useVisibilityFromPresence(state: PresenceState): CSSProperties['visibility'];
|
|
12
|
+
//# sourceMappingURL=useVisibilityFromPresence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useVisibilityFromPresence.d.ts","sourceRoot":"","sources":["../src/useVisibilityFromPresence.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAEvC;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,aAAa,GACnB,aAAa,CAAC,YAAY,CAAC,CAkB7B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useEffect, useState } from "@lynx-js/react";
|
|
2
|
+
import { PresenceState } from "./utils.jsx";
|
|
3
|
+
function useVisibilityFromPresence(state) {
|
|
4
|
+
const [visibility, setVisibility] = useState('hidden');
|
|
5
|
+
useEffect(()=>{
|
|
6
|
+
state === PresenceState.DelayedEntering || state === PresenceState.Entered || state === PresenceState.Leaving ? setVisibility('visible') : setVisibility('hidden');
|
|
7
|
+
}, [
|
|
8
|
+
state
|
|
9
|
+
]);
|
|
10
|
+
return visibility;
|
|
11
|
+
}
|
|
12
|
+
export { useVisibilityFromPresence };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=useVisibilityFromPresence.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useVisibilityFromPresence.jsx","sources":["webpack://@lynx-js/lynx-ui-presence/./src/useVisibilityFromPresence.ts"],"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 { useEffect, useState } from '@lynx-js/react'\n\nimport type { CSSProperties } from '@lynx-js/types'\n\nimport { PresenceState } from './utils'\n\n/**\n * A hook that derives visibility state from a PresenceState.\n * It returns 'visible' when the presence state indicates the component\n * is entering, present, or leaving, and 'hidden' otherwise.\n *\n * @param state The current PresenceState.\n * @returns CSSProperties['visibility'] ('visible' or 'hidden').\n */\nexport function useVisibilityFromPresence(\n state: PresenceState,\n): CSSProperties['visibility'] {\n const [visibility, setVisibility] = useState<CSSProperties['visibility']>(\n 'hidden',\n )\n\n useEffect(() => {\n if (\n state === PresenceState.DelayedEntering\n || state === PresenceState.Entered\n || state === PresenceState.Leaving\n ) {\n setVisibility('visible')\n } else {\n setVisibility('hidden')\n }\n }, [state])\n\n return visibility\n}\n"],"names":["useVisibilityFromPresence","state","visibility","setVisibility","useState","useEffect","PresenceState"],"mappings":";;AAkBO,SAASA,0BACdC,KAAoB;IAEpB,MAAM,CAACC,YAAYC,cAAc,GAAGC,SAClC;IAGFC,UAAU;QAENJ,UAAUK,cAAc,eAAe,IACpCL,UAAUK,cAAc,OAAO,IAC/BL,UAAUK,cAAc,OAAO,GAElCH,cAAc,aAEdA,cAAc;IAElB,GAAG;QAACF;KAAM;IAEV,OAAOC;AACT"}
|