@tamagui/animate-presence 1.0.0-beta.149 → 1.0.0-beta.15
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/dist/cjs/AnimatePresence.js +6 -1
- package/dist/cjs/AnimatePresence.js.map +2 -2
- package/dist/cjs/AnimatePresenceContext.js +4 -0
- package/dist/cjs/LayoutGroupContext.js +4 -0
- package/dist/cjs/PresenceChild.js +5 -3
- package/dist/cjs/PresenceChild.js.map +2 -2
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/useEntering.js +8 -2
- package/dist/cjs/useEntering.js.map +2 -2
- package/dist/esm/AnimatePresence.js +2 -2
- package/dist/esm/AnimatePresence.js.map +2 -2
- package/dist/esm/PresenceChild.js +1 -3
- package/dist/esm/PresenceChild.js.map +2 -2
- package/dist/esm/useEntering.js +1 -1
- package/dist/esm/useEntering.js.map +2 -2
- package/dist/jsx/AnimatePresence.js +2 -2
- package/dist/jsx/PresenceChild.js +1 -3
- package/dist/jsx/useEntering.js +1 -1
- package/package.json +4 -4
- package/types/AnimatePresence.d.ts.map +1 -1
- package/types/AnimatePresenceContext.d.ts.map +1 -1
- package/types/PresenceChild.d.ts.map +1 -1
- package/types/useEntering.d.ts.map +1 -1
- package/dist/cjs/usePresence.js +0 -51
- package/dist/cjs/usePresence.js.map +0 -7
- package/dist/esm/usePresence.js +0 -33
- package/dist/esm/usePresence.js.map +0 -7
- package/dist/jsx/usePresence.js +0 -32
- package/types/usePresence.d.ts +0 -10
- package/types/usePresence.d.ts.map +0 -1
|
@@ -66,7 +66,7 @@ const AnimatePresence = /* @__PURE__ */ __name(({
|
|
|
66
66
|
if (forceRenderLayoutGroup)
|
|
67
67
|
forceRender = forceRenderLayoutGroup;
|
|
68
68
|
const [isMounted, setIsMounted] = (0, import_react.useState)(false);
|
|
69
|
-
(0,
|
|
69
|
+
(0, import_core.useIsomorphicLayoutEffect)(() => {
|
|
70
70
|
setIsMounted(true);
|
|
71
71
|
}, []);
|
|
72
72
|
const filteredChildren = onlyElements(children);
|
|
@@ -151,4 +151,9 @@ const AnimatePresence = /* @__PURE__ */ __name(({
|
|
|
151
151
|
}
|
|
152
152
|
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, exiting.size ? childrenToRender : childrenToRender.map((child) => (0, import_react.cloneElement)(child)));
|
|
153
153
|
}, "AnimatePresence");
|
|
154
|
+
AnimatePresence.displayName = "AnimatePresence";
|
|
155
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
156
|
+
0 && (module.exports = {
|
|
157
|
+
AnimatePresence
|
|
158
|
+
});
|
|
154
159
|
//# sourceMappingURL=AnimatePresence.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/AnimatePresence.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useForceUpdate, useIsomorphicLayoutEffect, useUnmountEffect } from '@tamagui/core'\nimport React, {\n Children,\n ReactElement,\n ReactNode,\n cloneElement,\n isValidElement,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react'\n\nimport { LayoutGroupContext } from './LayoutGroupContext'\nimport { PresenceChild } from './PresenceChild'\n\nReact['keep']\n\nexport interface AnimatePresenceProps {\n /**\n * By passing `initial={false}`, `AnimatePresence` will disable any initial animations on children\n * that are present when the component is first rendered.\n */\n initial?: boolean\n\n /**\n * When a component is removed, there's no longer a chance to update its props. So if a component's `exit`\n * prop is defined as a dynamic variant and you want to pass a new `custom` prop, you can do so via `AnimatePresence`.\n * This will ensure all leaving components animate using the latest data.\n */\n exitVariant?: string | null\n\n enterVariant?: string | null\n\n /**\n * Fires when all exiting nodes have completed animating out.\n */\n onExitComplete?: () => void\n\n /**\n * If set to `true`, `AnimatePresence` will only render one component at a time. The exiting component\n * will finish its exit animation before the entering component is rendered.\n */\n exitBeforeEnter?: boolean\n\n /**\n * Used in Framer to flag that sibling children *shouldn't* re-render as a result of a\n * child being removed.\n */\n presenceAffectsLayout?: boolean\n}\n\ntype ComponentKey = string | number\n\nconst getChildKey = (child: ReactElement<any>): ComponentKey => child.key || ''\n\nconst isDev = process.env.NODE_ENV !== 'production'\n\nfunction updateChildLookup(\n children: ReactElement<any>[],\n allChildren: Map<ComponentKey, ReactElement<any>>\n) {\n const seenChildren = isDev ? new Set<ComponentKey>() : null\n\n children.forEach((child) => {\n const key = getChildKey(child)\n\n if (isDev && seenChildren && seenChildren.has(key)) {\n console.warn(`Children of AnimatePresence require unique keys. \"${key}\" is a duplicate.`)\n\n seenChildren.add(key)\n }\n\n allChildren.set(key, child)\n })\n}\n\nfunction onlyElements(children: ReactNode): ReactElement<any>[] {\n const filtered: ReactElement<any>[] = []\n\n // We use forEach here instead of map as map mutates the component key by preprending `.$`\n Children.forEach(children, (child) => {\n if (isValidElement(child)) filtered.push(child)\n })\n\n return filtered\n}\n\n/**\n * `AnimatePresence` enables the animation of components that have been removed from the tree.\n *\n * When adding/removing more than a single child, every child **must** be given a unique `key` prop.\n *\n * Any `motion` components that have an `exit` property defined will animate out when removed from\n * the tree.\n *\n * ```jsx\n * import { motion, AnimatePresence } from 'framer-motion'\n *\n * export const Items = ({ items }) => (\n * <AnimatePresence>\n * {items.map(item => (\n * <motion.div\n * key={item.id}\n * initial={{ opacity: 0 }}\n * animate={{ opacity: 1 }}\n * exit={{ opacity: 0 }}\n * />\n * ))}\n * </AnimatePresence>\n * )\n * ```\n *\n * You can sequence exit animations throughout a tree using variants.\n *\n * If a child contains multiple `motion` components with `exit` props, it will only unmount the child\n * once all `motion` components have finished animating out. Likewise, any components using\n * `useEntering` all need to call `safeToRemove`.\n *\n * @public\n */\nexport const AnimatePresence: React.FunctionComponent<\n React.PropsWithChildren<AnimatePresenceProps>\n> = ({\n children,\n enterVariant,\n exitVariant,\n initial = true,\n onExitComplete,\n exitBeforeEnter,\n presenceAffectsLayout = true,\n}) => {\n // We want to force a re-render once all exiting animations have finished. We\n // either use a local forceRender function, or one from a parent context if it exists.\n let forceRender = useForceUpdate()\n const forceRenderLayoutGroup = useContext(LayoutGroupContext).forceRender\n if (forceRenderLayoutGroup) forceRender = forceRenderLayoutGroup\n\n const [isMounted, setIsMounted] = useState(false)\n useEffect(() => {\n setIsMounted(true)\n }, [])\n\n // Filter out any children that aren't ReactElements. We can only track ReactElements with a props.key\n const filteredChildren = onlyElements(children)\n let childrenToRender = filteredChildren\n\n const exiting = new Set<ComponentKey>()\n\n // Keep a living record of the children we're actually rendering so we\n // can diff to figure out which are entering and exiting\n const presentChildren = useRef(childrenToRender)\n\n // A lookup table to quickly reference components by key\n const allChildren = useRef(new Map<ComponentKey, ReactElement<any>>()).current\n\n // If this is the initial component render, just deal with logic surrounding whether\n // we play onMount animations or not.\n const isInitialRender = useRef(true)\n\n useIsomorphicLayoutEffect(() => {\n isInitialRender.current = false\n updateChildLookup(filteredChildren, allChildren)\n presentChildren.current = childrenToRender\n })\n\n useUnmountEffect(() => {\n isInitialRender.current = true\n allChildren.clear()\n exiting.clear()\n })\n\n if (isInitialRender.current) {\n return (\n <>\n {childrenToRender.map((child) => (\n <PresenceChild\n key={getChildKey(child)}\n isEntering\n exitVariant={exitVariant}\n enterVariant={enterVariant}\n initial={initial ? undefined : false}\n presenceAffectsLayout={presenceAffectsLayout}\n >\n {child}\n </PresenceChild>\n ))}\n </>\n )\n }\n\n // If this is a subsequent render, deal with entering and exiting children\n childrenToRender = [...childrenToRender]\n\n // Diff the keys of the currently-present and target children to update our\n // exiting list.\n const presentKeys = presentChildren.current.map(getChildKey)\n const targetKeys = filteredChildren.map(getChildKey)\n\n // Diff the present children with our target children and mark those that are exiting\n const numPresent = presentKeys.length\n for (let i = 0; i < numPresent; i++) {\n const key = presentKeys[i]\n\n if (targetKeys.indexOf(key) === -1) {\n exiting.add(key)\n }\n }\n\n // If we currently have exiting children, and we're deferring rendering incoming children\n // until after all current children have exiting, empty the childrenToRender array\n if (exitBeforeEnter && exiting.size) {\n childrenToRender = []\n }\n\n // Loop through all currently exiting components and clone them to overwrite `animate`\n // with any `exit` prop they might have defined.\n exiting.forEach((key) => {\n // If this component is actually entering again, early return\n if (targetKeys.indexOf(key) !== -1) return\n\n const child = allChildren.get(key)\n if (!child) return\n\n const insertionIndex = presentKeys.indexOf(key)\n\n childrenToRender.splice(\n insertionIndex,\n 0,\n <PresenceChild\n key={getChildKey(child)}\n isEntering={false}\n onExitComplete={() => {\n allChildren.delete(key)\n exiting.delete(key)\n\n // Remove this child from the present children\n const removeIndex = presentChildren.current.findIndex(\n (presentChild) => presentChild.key === key\n )\n presentChildren.current.splice(removeIndex, 1)\n\n // Defer re-rendering until all exiting children have indeed left\n if (!exiting.size) {\n presentChildren.current = filteredChildren\n\n if (isMounted === false) return\n\n forceRender()\n onExitComplete?.()\n }\n }}\n exitVariant={exitVariant}\n enterVariant={enterVariant}\n presenceAffectsLayout={presenceAffectsLayout}\n >\n {child}\n </PresenceChild>\n )\n })\n\n // Add `MotionContext` even to children that don't need it to ensure we're rendering\n // the same tree between renders\n childrenToRender = childrenToRender.map((child) => {\n const key = child.key as string | number\n return exiting.has(key) ? (\n child\n ) : (\n <PresenceChild\n key={getChildKey(child)}\n isEntering={undefined}\n exitVariant={exitVariant}\n enterVariant={enterVariant}\n presenceAffectsLayout={presenceAffectsLayout}\n >\n {child}\n </PresenceChild>\n )\n })\n\n if (process.env.NODE_ENV !== 'production' && exitBeforeEnter && childrenToRender.length > 1) {\n console.warn(\n `You're attempting to animate multiple children within AnimatePresence, but its exitBeforeEnter prop is set to true. This will lead to odd visual behaviour.`\n )\n }\n\n return (\n <>{exiting.size ? childrenToRender : childrenToRender.map((child) => cloneElement(child))}</>\n )\n}\n\n// import { useForceUpdate, useIsomorphicLayoutEffect, useUnmountEffect } from '@tamagui/core'\n// import React, {\n// Children,\n// ReactElement,\n// ReactNode,\n// cloneElement,\n// isValidElement,\n// useContext,\n// useEffect,\n// useRef,\n// useState,\n// } from 'react'\n\n// import { LayoutGroupContext } from './LayoutGroupContext'\n// import { PresenceChild } from './PresenceChild'\n\n// React['keep']\n\n// export interface AnimatePresenceProps {\n// /**\n// * By passing `initial={false}`, `AnimatePresence` will disable any initial animations on children\n// * that are present when the component is first rendered.\n// */\n// initial?: boolean\n\n// /**\n// * When a component is removed, there's no longer a chance to update its props. So if a component's `exit`\n// * prop is defined as a dynamic variant and you want to pass a new `custom` prop, you can do so via `AnimatePresence`.\n// * This will ensure all leaving components animate using the latest data.\n// */\n// exitVariant?: string | null\n\n// enterVariant?: string | null\n\n// /**\n// * Fires when all exiting nodes have completed animating out.\n// */\n// onExitComplete?: () => void\n\n// /**\n// * If set to `true`, `AnimatePresence` will only render one component at a time. The exiting component\n// * will finish its exit animation before the entering component is rendered.\n// */\n// exitBeforeEnter?: boolean\n\n// /**\n// * Used in Framer to flag that sibling children *shouldn't* re-render as a result of a\n// * child being removed.\n// */\n// presenceAffectsLayout?: boolean\n// }\n\n// type ComponentKey = string | number\n\n// const getChildKey = (child: ReactElement<any>): ComponentKey => child.key || ''\n// const isDev = process.env.NODE_ENV !== 'production'\n\n// function updateChildLookup(\n// children: ReactElement<any>[],\n// allChildren: Map<ComponentKey, ReactElement<any>>\n// ) {\n// const seenChildren = isDev ? new Set<ComponentKey>() : null\n\n// for (const child of children) {\n// const key = getChildKey(child)\n// if (isDev && seenChildren && seenChildren.has(key)) {\n// console.warn(`Children of AnimatePresence require unique keys. \"${key}\" is a duplicate.`)\n// seenChildren.add(key)\n// }\n// allChildren.set(key, child)\n// }\n// }\n\n// function onlyElements(children: ReactNode): ReactElement<any>[] {\n// const filtered: ReactElement<any>[] = []\n\n// // We use forEach here instead of map as map mutates the component key by preprending `.$`\n// Children.forEach(children, (child) => {\n// if (isValidElement(child)) filtered.push(child)\n// })\n\n// return filtered\n// }\n\n// /**\n// * `AnimatePresence` enables the animation of components that have been removed from the tree.\n// *\n// * When adding/removing more than a single child, every child **must** be given a unique `key` prop.\n// *\n// * Any animated components that have an `exit` property defined will animate out when removed from\n// * the tree.\n// *\n// * ```jsx\n// * import { motion, AnimatePresence } from 'framer-motion'\n// *\n// * export const Items = ({ items }) => (\n// * <AnimatePresence>\n// * {items.map(item => (\n// * <motion.div\n// * key={item.id}\n// * initial={{ opacity: 0 }}\n// * animate={{ opacity: 1 }}\n// * exit={{ opacity: 0 }}\n// * />\n// * ))}\n// * </AnimatePresence>\n// * )\n// * ```\n// *\n// * You can sequence exit animations throughout a tree using variants.\n// *\n// * If a child contains multiple animated components with `exit` props, it will only unmount the child\n// * once all animated components have finished animating out. Likewise, any components using\n// * `useEntering` all need to call `safeToRemove`.\n// *\n// * @public\n// */\n// export const AnimatePresence: React.FunctionComponent<AnimatePresenceProps> = ({\n// children,\n// exitVariant,\n// enterVariant,\n// initial = true,\n// onExitComplete,\n// exitBeforeEnter,\n// presenceAffectsLayout = true,\n// }) => {\n// // We want to force a re-render once all exiting animations have finished. We\n// // either use a local forceRender function, or one from a parent context if it exists.\n// let forceRender = useForceUpdate()\n// const forceRenderLayoutGroup = useContext(LayoutGroupContext).forceRender\n// if (forceRenderLayoutGroup) forceRender = forceRenderLayoutGroup\n\n// const [isMounted, setIsMounted] = useState(false)\n// useEffect(() => {\n// setIsMounted(true)\n// }, [])\n\n// // Filter out any children that aren't ReactElements. We can only track ReactElements with a props.key\n// const filteredChildren = onlyElements(children)\n// let childrenToRender = filteredChildren\n\n// const exiting = new Set<ComponentKey>()\n\n// // Keep a living record of the children we're actually rendering so we\n// // can diff to figure out which are entering and exiting\n// const presentChildren = useRef(childrenToRender)\n\n// // A lookup table to quickly reference components by key\n// const allChildren = useRef(new Map<ComponentKey, ReactElement<any>>()).current\n\n// // If this is the initial component render, just deal with logic surrounding whether\n// // we play onMount animations or not.\n// const isInitialRender = useRef(true)\n\n// useIsomorphicLayoutEffect(() => {\n// isInitialRender.current = false\n// updateChildLookup(filteredChildren, allChildren)\n// presentChildren.current = childrenToRender\n// })\n\n// useUnmountEffect(() => {\n// isInitialRender.current = true\n// allChildren.clear()\n// exiting.clear()\n// })\n\n// if (isInitialRender.current) {\n// console.log('AnimatePresence (iniital)', isInitialRender.current, {\n// isMounted,\n// childrenToRender,\n// })\n// return (\n// <>\n// {childrenToRender.map((child) => (\n// <PresenceChild\n// key={getChildKey(child)}\n// isEntering\n// initial={initial ? undefined : false}\n// presenceAffectsLayout={presenceAffectsLayout}\n// exitVariant={exitVariant}\n// enterVariant={enterVariant}\n// >\n// {child}\n// </PresenceChild>\n// ))}\n// </>\n// )\n// }\n\n// // If this is a subsequent render, deal with entering and exiting children\n// childrenToRender = [...childrenToRender]\n\n// // Diff the keys of the currently-present and target children to update our\n// // exiting list.\n// const presentKeys = presentChildren.current.map(getChildKey)\n// const targetKeys = filteredChildren.map(getChildKey)\n\n// // Diff the present children with our target children and mark those that are exiting\n// const numPresent = presentKeys.length\n// for (let i = 0; i < numPresent; i++) {\n// const key = presentKeys[i]\n// if (targetKeys.indexOf(key) === -1) {\n// exiting.add(key)\n// }\n// }\n\n// // If we currently have exiting children, and we're deferring rendering incoming children\n// // until after all current children have exiting, empty the childrenToRender array\n// if (exitBeforeEnter && exiting.size) {\n// childrenToRender = []\n// }\n\n// // Loop through all currently exiting components and clone them to overwrite `animate`\n// // with any `exit` prop they might have defined.\n// for (const key of exiting) {\n// // If this component is actually entering again, early return\n// if (targetKeys.indexOf(key) !== -1) {\n// continue\n// }\n\n// const child = allChildren.get(key)\n// if (!child) {\n// continue\n// }\n\n// const insertionIndex = presentKeys.indexOf(key)\n\n// const onExit = () => {\n// allChildren.delete(key)\n// exiting.delete(key)\n\n// // Remove this child from the present children\n// const removeIndex = presentChildren.current.findIndex(\n// (presentChild) => presentChild.key === key\n// )\n// presentChildren.current.splice(removeIndex, 1)\n\n// // Defer re-rendering until all exiting children have indeed left\n// if (!exiting.size) {\n// presentChildren.current = filteredChildren\n// if (isMounted === false) {\n// return\n// }\n// forceRender()\n// onExitComplete?.()\n// }\n// }\n\n// childrenToRender.splice(\n// insertionIndex,\n// 0,\n// <PresenceChild\n// key={getChildKey(child)}\n// isEntering={false}\n// onExitComplete={onExit}\n// exitVariant={exitVariant}\n// enterVariant={enterVariant}\n// presenceAffectsLayout={presenceAffectsLayout}\n// >\n// {child}\n// </PresenceChild>\n// )\n// }\n\n// // Add `MotionContext` even to children that don't need it to ensure we're rendering\n// // the same tree between renders\n// childrenToRender = childrenToRender.map((child) => {\n// const key = child.key as string | number\n// return exiting.has(key) ? (\n// child\n// ) : (\n// <PresenceChild\n// key={getChildKey(child)}\n// isEntering={undefined}\n// exitVariant={exitVariant}\n// enterVariant={enterVariant}\n// presenceAffectsLayout={presenceAffectsLayout}\n// >\n// {child}\n// </PresenceChild>\n// )\n// })\n\n// console.log(\n// 'AnimatePresence ()',\n// isInitialRender.current,\n// {\n// isMounted,\n// },\n// childrenToRender.map((x) => x.props.children.props.children.props.src)\n// )\n\n// if (process.env.NODE_ENV !== 'production' && exitBeforeEnter && childrenToRender.length > 1) {\n// console.warn(\n// `You're attempting to animate multiple children within AnimatePresence, but its exitBeforeEnter prop is set to true. This will lead to odd visual behaviour.`\n// )\n// }\n\n// return (\n// <>{exiting.size ? childrenToRender : childrenToRender.map((child) => cloneElement(child))}</>\n// )\n// }\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA4E;AAC5E,
|
|
4
|
+
"sourcesContent": ["import { useForceUpdate, useIsomorphicLayoutEffect, useUnmountEffect } from '@tamagui/core'\nimport React, {\n Children,\n ReactElement,\n ReactNode,\n cloneElement,\n isValidElement,\n useContext,\n useRef,\n useState,\n} from 'react'\n\nimport { LayoutGroupContext } from './LayoutGroupContext'\nimport { PresenceChild } from './PresenceChild'\n\nReact['keep']\n\nexport interface AnimatePresenceProps {\n /**\n * By passing `initial={false}`, `AnimatePresence` will disable any initial animations on children\n * that are present when the component is first rendered.\n */\n initial?: boolean\n\n /**\n * When a component is removed, there's no longer a chance to update its props. So if a component's `exit`\n * prop is defined as a dynamic variant and you want to pass a new `custom` prop, you can do so via `AnimatePresence`.\n * This will ensure all leaving components animate using the latest data.\n */\n exitVariant?: string | null\n\n enterVariant?: string | null\n\n /**\n * Fires when all exiting nodes have completed animating out.\n */\n onExitComplete?: () => void\n\n /**\n * If set to `true`, `AnimatePresence` will only render one component at a time. The exiting component\n * will finish its exit animation before the entering component is rendered.\n */\n exitBeforeEnter?: boolean\n\n /**\n * Used in Framer to flag that sibling children *shouldn't* re-render as a result of a\n * child being removed.\n */\n presenceAffectsLayout?: boolean\n}\n\ntype ComponentKey = string | number\n\nconst getChildKey = (child: ReactElement<any>): ComponentKey => child.key || ''\n\nconst isDev = process.env.NODE_ENV !== 'production'\n\nfunction updateChildLookup(\n children: ReactElement<any>[],\n allChildren: Map<ComponentKey, ReactElement<any>>\n) {\n const seenChildren = isDev ? new Set<ComponentKey>() : null\n\n children.forEach((child) => {\n const key = getChildKey(child)\n\n if (isDev && seenChildren && seenChildren.has(key)) {\n console.warn(`Children of AnimatePresence require unique keys. \"${key}\" is a duplicate.`)\n\n seenChildren.add(key)\n }\n\n allChildren.set(key, child)\n })\n}\n\nfunction onlyElements(children: ReactNode): ReactElement<any>[] {\n const filtered: ReactElement<any>[] = []\n\n // We use forEach here instead of map as map mutates the component key by preprending `.$`\n Children.forEach(children, (child) => {\n if (isValidElement(child)) filtered.push(child)\n })\n\n return filtered\n}\n\n/**\n * `AnimatePresence` enables the animation of components that have been removed from the tree.\n *\n * When adding/removing more than a single child, every child **must** be given a unique `key` prop.\n *\n * Any `motion` components that have an `exit` property defined will animate out when removed from\n * the tree.\n *\n * ```jsx\n * import { motion, AnimatePresence } from 'framer-motion'\n *\n * export const Items = ({ items }) => (\n * <AnimatePresence>\n * {items.map(item => (\n * <motion.div\n * key={item.id}\n * initial={{ opacity: 0 }}\n * animate={{ opacity: 1 }}\n * exit={{ opacity: 0 }}\n * />\n * ))}\n * </AnimatePresence>\n * )\n * ```\n *\n * You can sequence exit animations throughout a tree using variants.\n *\n * If a child contains multiple `motion` components with `exit` props, it will only unmount the child\n * once all `motion` components have finished animating out. Likewise, any components using\n * `useEntering` all need to call `safeToRemove`.\n *\n * @public\n */\nexport const AnimatePresence: React.FunctionComponent<\n React.PropsWithChildren<AnimatePresenceProps>\n> = ({\n children,\n enterVariant,\n exitVariant,\n initial = true,\n onExitComplete,\n exitBeforeEnter,\n presenceAffectsLayout = true,\n}) => {\n // We want to force a re-render once all exiting animations have finished. We\n // either use a local forceRender function, or one from a parent context if it exists.\n let forceRender = useForceUpdate()\n const forceRenderLayoutGroup = useContext(LayoutGroupContext).forceRender\n if (forceRenderLayoutGroup) forceRender = forceRenderLayoutGroup\n\n const [isMounted, setIsMounted] = useState(false)\n\n useIsomorphicLayoutEffect(() => {\n setIsMounted(true)\n }, [])\n\n // Filter out any children that aren't ReactElements. We can only track ReactElements with a props.key\n const filteredChildren = onlyElements(children)\n let childrenToRender = filteredChildren\n\n const exiting = new Set<ComponentKey>()\n\n // Keep a living record of the children we're actually rendering so we\n // can diff to figure out which are entering and exiting\n const presentChildren = useRef(childrenToRender)\n\n // A lookup table to quickly reference components by key\n const allChildren = useRef(new Map<ComponentKey, ReactElement<any>>()).current\n\n // If this is the initial component render, just deal with logic surrounding whether\n // we play onMount animations or not.\n const isInitialRender = useRef(true)\n\n useIsomorphicLayoutEffect(() => {\n isInitialRender.current = false\n updateChildLookup(filteredChildren, allChildren)\n presentChildren.current = childrenToRender\n })\n\n useUnmountEffect(() => {\n isInitialRender.current = true\n allChildren.clear()\n exiting.clear()\n })\n\n if (isInitialRender.current) {\n return (\n <>\n {childrenToRender.map((child) => (\n <PresenceChild\n key={getChildKey(child)}\n isEntering\n exitVariant={exitVariant}\n enterVariant={enterVariant}\n initial={initial ? undefined : false}\n presenceAffectsLayout={presenceAffectsLayout}\n >\n {child}\n </PresenceChild>\n ))}\n </>\n )\n }\n\n // If this is a subsequent render, deal with entering and exiting children\n childrenToRender = [...childrenToRender]\n\n // Diff the keys of the currently-present and target children to update our\n // exiting list.\n const presentKeys = presentChildren.current.map(getChildKey)\n const targetKeys = filteredChildren.map(getChildKey)\n\n // Diff the present children with our target children and mark those that are exiting\n const numPresent = presentKeys.length\n for (let i = 0; i < numPresent; i++) {\n const key = presentKeys[i]\n\n if (targetKeys.indexOf(key) === -1) {\n exiting.add(key)\n }\n }\n\n // If we currently have exiting children, and we're deferring rendering incoming children\n // until after all current children have exiting, empty the childrenToRender array\n if (exitBeforeEnter && exiting.size) {\n childrenToRender = []\n }\n\n // Loop through all currently exiting components and clone them to overwrite `animate`\n // with any `exit` prop they might have defined.\n exiting.forEach((key) => {\n // If this component is actually entering again, early return\n if (targetKeys.indexOf(key) !== -1) return\n\n const child = allChildren.get(key)\n if (!child) return\n\n const insertionIndex = presentKeys.indexOf(key)\n\n childrenToRender.splice(\n insertionIndex,\n 0,\n <PresenceChild\n key={getChildKey(child)}\n isEntering={false}\n onExitComplete={() => {\n allChildren.delete(key)\n exiting.delete(key)\n\n // Remove this child from the present children\n const removeIndex = presentChildren.current.findIndex(\n (presentChild) => presentChild.key === key\n )\n presentChildren.current.splice(removeIndex, 1)\n\n // Defer re-rendering until all exiting children have indeed left\n if (!exiting.size) {\n presentChildren.current = filteredChildren\n\n if (isMounted === false) return\n\n forceRender()\n onExitComplete?.()\n }\n }}\n exitVariant={exitVariant}\n enterVariant={enterVariant}\n presenceAffectsLayout={presenceAffectsLayout}\n >\n {child}\n </PresenceChild>\n )\n })\n\n // Add `MotionContext` even to children that don't need it to ensure we're rendering\n // the same tree between renders\n childrenToRender = childrenToRender.map((child) => {\n const key = child.key as string | number\n return exiting.has(key) ? (\n child\n ) : (\n <PresenceChild\n key={getChildKey(child)}\n isEntering={undefined}\n exitVariant={exitVariant}\n enterVariant={enterVariant}\n presenceAffectsLayout={presenceAffectsLayout}\n >\n {child}\n </PresenceChild>\n )\n })\n\n if (process.env.NODE_ENV !== 'production' && exitBeforeEnter && childrenToRender.length > 1) {\n console.warn(\n `You're attempting to animate multiple children within AnimatePresence, but its exitBeforeEnter prop is set to true. This will lead to odd visual behaviour.`\n )\n }\n\n return (\n <>{exiting.size ? childrenToRender : childrenToRender.map((child) => cloneElement(child))}</>\n )\n}\n\nAnimatePresence.displayName = 'AnimatePresence'\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -22,4 +22,8 @@ __export(AnimatePresenceContext_exports, {
|
|
|
22
22
|
module.exports = __toCommonJS(AnimatePresenceContext_exports);
|
|
23
23
|
var import_react = require("react");
|
|
24
24
|
const AnimatePresenceContext = (0, import_react.createContext)(null);
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
AnimatePresenceContext
|
|
28
|
+
});
|
|
25
29
|
//# sourceMappingURL=AnimatePresenceContext.js.map
|
|
@@ -22,4 +22,8 @@ __export(LayoutGroupContext_exports, {
|
|
|
22
22
|
module.exports = __toCommonJS(LayoutGroupContext_exports);
|
|
23
23
|
var import_react = require("react");
|
|
24
24
|
const LayoutGroupContext = (0, import_react.createContext)({});
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
LayoutGroupContext
|
|
28
|
+
});
|
|
25
29
|
//# sourceMappingURL=LayoutGroupContext.js.map
|
|
@@ -24,7 +24,6 @@ __export(PresenceChild_exports, {
|
|
|
24
24
|
PresenceChild: () => PresenceChild
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(PresenceChild_exports);
|
|
27
|
-
var import_utils = require("@react-aria/utils");
|
|
28
27
|
var import_core = require("@tamagui/core");
|
|
29
28
|
var React = __toESM(require("react"));
|
|
30
29
|
var import_AnimatePresenceContext = require("./AnimatePresenceContext");
|
|
@@ -38,7 +37,7 @@ const PresenceChild = /* @__PURE__ */ __name(({
|
|
|
38
37
|
presenceAffectsLayout
|
|
39
38
|
}) => {
|
|
40
39
|
const presenceChildren = (0, import_core.useConstant)(newChildrenMap);
|
|
41
|
-
const id = (0,
|
|
40
|
+
const id = (0, import_core.useId)();
|
|
42
41
|
const context = React.useMemo(() => {
|
|
43
42
|
return {
|
|
44
43
|
id,
|
|
@@ -47,7 +46,6 @@ const PresenceChild = /* @__PURE__ */ __name(({
|
|
|
47
46
|
exitVariant,
|
|
48
47
|
enterVariant,
|
|
49
48
|
onExitComplete: (childId) => {
|
|
50
|
-
console.log("on exist complete", childId);
|
|
51
49
|
presenceChildren.set(childId, true);
|
|
52
50
|
for (const isComplete of presenceChildren.values()) {
|
|
53
51
|
if (!isComplete) {
|
|
@@ -78,4 +76,8 @@ function newChildrenMap() {
|
|
|
78
76
|
return /* @__PURE__ */ new Map();
|
|
79
77
|
}
|
|
80
78
|
__name(newChildrenMap, "newChildrenMap");
|
|
79
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
80
|
+
0 && (module.exports = {
|
|
81
|
+
PresenceChild
|
|
82
|
+
});
|
|
81
83
|
//# sourceMappingURL=PresenceChild.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/PresenceChild.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useId } from '@
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import { useConstant, useId } from '@tamagui/core'\nimport * as React from 'react'\n\nimport { AnimatePresenceContext, AnimatePresenceContextProps } from './AnimatePresenceContext'\nimport { VariantLabels } from './types'\n\ninterface PresenceChildProps {\n children: React.ReactElement<any>\n isEntering: boolean | undefined\n onExitComplete?: () => void\n initial?: false | VariantLabels\n exitVariant?: string | null\n enterVariant?: string | null\n presenceAffectsLayout: boolean\n}\n\nexport const PresenceChild = ({\n children,\n initial,\n isEntering,\n onExitComplete,\n exitVariant,\n enterVariant,\n presenceAffectsLayout,\n}: PresenceChildProps) => {\n const presenceChildren = useConstant(newChildrenMap)\n const id = useId()\n\n const context = React.useMemo(\n (): AnimatePresenceContextProps => {\n return {\n id,\n initial,\n isEntering,\n exitVariant,\n enterVariant,\n onExitComplete: (childId: string) => {\n presenceChildren.set(childId, true)\n for (const isComplete of presenceChildren.values()) {\n if (!isComplete) {\n return // can stop searching when any is incomplete\n }\n }\n onExitComplete?.()\n },\n register: (childId: string) => {\n presenceChildren.set(childId, false)\n return () => presenceChildren.delete(childId)\n },\n }\n },\n /**\n * If the presence of a child affects the layout of the components around it,\n * we want to make a new context value to ensure they get re-rendered\n * so they can detect that layout change.\n */\n presenceAffectsLayout ? undefined : [isEntering, onExitComplete, exitVariant, enterVariant]\n )\n\n // cant this be a useEffect?\n React.useMemo(() => {\n presenceChildren.forEach((_, key) => presenceChildren.set(key, false))\n }, [isEntering])\n\n /**\n * If there's no animated components to fire exit animations, we want to remove this\n * component immediately.\n */\n React.useEffect(() => {\n if (isEntering === false && !presenceChildren.size) {\n onExitComplete?.()\n }\n }, [isEntering])\n\n return (\n <AnimatePresenceContext.Provider value={context}>{children}</AnimatePresenceContext.Provider>\n )\n}\n\nfunction newChildrenMap(): Map<string, boolean> {\n return new Map()\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAmC;AACnC,YAAuB;AAEvB,oCAAoE;AAa7D,MAAM,gBAAgB,wBAAC;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,MACwB;AACxB,QAAM,mBAAmB,6BAAY,cAAc;AACnD,QAAM,KAAK,uBAAM;AAEjB,QAAM,UAAU,MAAM,QACpB,MAAmC;AACjC,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,gBAAgB,CAAC,YAAoB;AACnC,yBAAiB,IAAI,SAAS,IAAI;AAClC,mBAAW,cAAc,iBAAiB,OAAO,GAAG;AAClD,cAAI,CAAC,YAAY;AACf;AAAA,UACF;AAAA,QACF;AACA;AAAA,MACF;AAAA,MACA,UAAU,CAAC,YAAoB;AAC7B,yBAAiB,IAAI,SAAS,KAAK;AACnC,eAAO,MAAM,iBAAiB,OAAO,OAAO;AAAA,MAC9C;AAAA,IACF;AAAA,EACF,GAMA,wBAAwB,SAAY,CAAC,YAAY,gBAAgB,aAAa,YAAY,CAC5F;AAGA,QAAM,QAAQ,MAAM;AAClB,qBAAiB,QAAQ,CAAC,GAAG,QAAQ,iBAAiB,IAAI,KAAK,KAAK,CAAC;AAAA,EACvE,GAAG,CAAC,UAAU,CAAC;AAMf,QAAM,UAAU,MAAM;AACpB,QAAI,eAAe,SAAS,CAAC,iBAAiB,MAAM;AAClD;AAAA,IACF;AAAA,EACF,GAAG,CAAC,UAAU,CAAC;AAEf,SACE,oCAAC,qDAAuB,UAAvB;AAAA,IAAgC,OAAO;AAAA,KAAU,QAAS;AAE/D,GA7D6B;AA+D7B,0BAAgD;AAC9C,SAAO,oBAAI,IAAI;AACjB;AAFS;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -24,4 +24,8 @@ module.exports = __toCommonJS(src_exports);
|
|
|
24
24
|
__reExport(src_exports, require("./AnimatePresence"), module.exports);
|
|
25
25
|
__reExport(src_exports, require("./useEntering"), module.exports);
|
|
26
26
|
var import_AnimatePresenceContext = require("./AnimatePresenceContext");
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
AnimatePresenceContext
|
|
30
|
+
});
|
|
27
31
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/useEntering.js
CHANGED
|
@@ -23,7 +23,7 @@ __export(useEntering_exports, {
|
|
|
23
23
|
useIsEntering: () => useIsEntering
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(useEntering_exports);
|
|
26
|
-
var
|
|
26
|
+
var import_core = require("@tamagui/core");
|
|
27
27
|
var import_react = require("react");
|
|
28
28
|
var import_AnimatePresenceContext = require("./AnimatePresenceContext");
|
|
29
29
|
function useEntering() {
|
|
@@ -32,7 +32,7 @@ function useEntering() {
|
|
|
32
32
|
return [void 0, void 0];
|
|
33
33
|
}
|
|
34
34
|
const { isEntering: isEntering2, onExitComplete, register } = context;
|
|
35
|
-
const id = (0,
|
|
35
|
+
const id = (0, import_core.useId)();
|
|
36
36
|
const safeToRemove = /* @__PURE__ */ __name(() => onExitComplete == null ? void 0 : onExitComplete(id), "safeToRemove");
|
|
37
37
|
(0, import_react.useEffect)(() => {
|
|
38
38
|
register(id);
|
|
@@ -48,4 +48,10 @@ function isEntering(context) {
|
|
|
48
48
|
return context === null ? void 0 : context.isEntering;
|
|
49
49
|
}
|
|
50
50
|
__name(isEntering, "isEntering");
|
|
51
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
+
0 && (module.exports = {
|
|
53
|
+
isEntering,
|
|
54
|
+
useEntering,
|
|
55
|
+
useIsEntering
|
|
56
|
+
});
|
|
51
57
|
//# sourceMappingURL=useEntering.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/useEntering.ts"],
|
|
4
|
-
"sourcesContent": ["import { useId } from '@
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import { useId } from '@tamagui/core'\nimport { useContext, useEffect } from 'react'\n\nimport { AnimatePresenceContext, AnimatePresenceContextProps } from './AnimatePresenceContext'\n\nexport type SafeToRemove = () => void\n\nexport function useEntering(): [boolean | undefined, undefined | (() => void)] {\n const context = useContext(AnimatePresenceContext)\n\n if (context === null) {\n return [undefined, undefined]\n }\n\n const { isEntering, onExitComplete, register } = context\n const id = useId()\n const safeToRemove = () => onExitComplete?.(id)\n\n // It's safe to call the following hooks conditionally (after an early return) because the context will always\n // either be null or non-null for the lifespan of the component.\n\n useEffect(() => {\n register(id)\n }, [])\n\n return isEntering === false\n ? [false, safeToRemove]\n : isEntering === true\n ? [true, safeToRemove]\n : [undefined, safeToRemove]\n}\n\n/**\n * Similar to `useEntering`, except `useIsEntering` simply returns whether or not the component is present.\n * There is no `safeToRemove` function. ```\n */\nexport function useIsEntering() {\n return isEntering(useContext(AnimatePresenceContext))\n}\n\nexport function isEntering(context: AnimatePresenceContextProps | null) {\n return context === null ? undefined : context.isEntering\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAsB;AACtB,mBAAsC;AAEtC,oCAAoE;AAI7D,uBAAwE;AAC7E,QAAM,UAAU,6BAAW,oDAAsB;AAEjD,MAAI,YAAY,MAAM;AACpB,WAAO,CAAC,QAAW,MAAS;AAAA,EAC9B;AAEA,QAAM,EAAE,yBAAY,gBAAgB,aAAa;AACjD,QAAM,KAAK,uBAAM;AACjB,QAAM,eAAe,6BAAM,iDAAiB,KAAvB;AAKrB,8BAAU,MAAM;AACd,aAAS,EAAE;AAAA,EACb,GAAG,CAAC,CAAC;AAEL,SAAO,gBAAe,QAClB,CAAC,OAAO,YAAY,IACpB,gBAAe,OACf,CAAC,MAAM,YAAY,IACnB,CAAC,QAAW,YAAY;AAC9B;AAvBgB;AA6BT,yBAAyB;AAC9B,SAAO,WAAW,6BAAW,oDAAsB,CAAC;AACtD;AAFgB;AAIT,oBAAoB,SAA6C;AACtE,SAAO,YAAY,OAAO,SAAY,QAAQ;AAChD;AAFgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -6,7 +6,6 @@ import React, {
|
|
|
6
6
|
cloneElement,
|
|
7
7
|
isValidElement,
|
|
8
8
|
useContext,
|
|
9
|
-
useEffect,
|
|
10
9
|
useRef,
|
|
11
10
|
useState
|
|
12
11
|
} from "react";
|
|
@@ -50,7 +49,7 @@ const AnimatePresence = /* @__PURE__ */ __name(({
|
|
|
50
49
|
if (forceRenderLayoutGroup)
|
|
51
50
|
forceRender = forceRenderLayoutGroup;
|
|
52
51
|
const [isMounted, setIsMounted] = useState(false);
|
|
53
|
-
|
|
52
|
+
useIsomorphicLayoutEffect(() => {
|
|
54
53
|
setIsMounted(true);
|
|
55
54
|
}, []);
|
|
56
55
|
const filteredChildren = onlyElements(children);
|
|
@@ -135,6 +134,7 @@ const AnimatePresence = /* @__PURE__ */ __name(({
|
|
|
135
134
|
}
|
|
136
135
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, exiting.size ? childrenToRender : childrenToRender.map((child) => cloneElement(child)));
|
|
137
136
|
}, "AnimatePresence");
|
|
137
|
+
AnimatePresence.displayName = "AnimatePresence";
|
|
138
138
|
export {
|
|
139
139
|
AnimatePresence
|
|
140
140
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/AnimatePresence.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useForceUpdate, useIsomorphicLayoutEffect, useUnmountEffect } from '@tamagui/core'\nimport React, {\n Children,\n ReactElement,\n ReactNode,\n cloneElement,\n isValidElement,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react'\n\nimport { LayoutGroupContext } from './LayoutGroupContext'\nimport { PresenceChild } from './PresenceChild'\n\nReact['keep']\n\nexport interface AnimatePresenceProps {\n /**\n * By passing `initial={false}`, `AnimatePresence` will disable any initial animations on children\n * that are present when the component is first rendered.\n */\n initial?: boolean\n\n /**\n * When a component is removed, there's no longer a chance to update its props. So if a component's `exit`\n * prop is defined as a dynamic variant and you want to pass a new `custom` prop, you can do so via `AnimatePresence`.\n * This will ensure all leaving components animate using the latest data.\n */\n exitVariant?: string | null\n\n enterVariant?: string | null\n\n /**\n * Fires when all exiting nodes have completed animating out.\n */\n onExitComplete?: () => void\n\n /**\n * If set to `true`, `AnimatePresence` will only render one component at a time. The exiting component\n * will finish its exit animation before the entering component is rendered.\n */\n exitBeforeEnter?: boolean\n\n /**\n * Used in Framer to flag that sibling children *shouldn't* re-render as a result of a\n * child being removed.\n */\n presenceAffectsLayout?: boolean\n}\n\ntype ComponentKey = string | number\n\nconst getChildKey = (child: ReactElement<any>): ComponentKey => child.key || ''\n\nconst isDev = process.env.NODE_ENV !== 'production'\n\nfunction updateChildLookup(\n children: ReactElement<any>[],\n allChildren: Map<ComponentKey, ReactElement<any>>\n) {\n const seenChildren = isDev ? new Set<ComponentKey>() : null\n\n children.forEach((child) => {\n const key = getChildKey(child)\n\n if (isDev && seenChildren && seenChildren.has(key)) {\n console.warn(`Children of AnimatePresence require unique keys. \"${key}\" is a duplicate.`)\n\n seenChildren.add(key)\n }\n\n allChildren.set(key, child)\n })\n}\n\nfunction onlyElements(children: ReactNode): ReactElement<any>[] {\n const filtered: ReactElement<any>[] = []\n\n // We use forEach here instead of map as map mutates the component key by preprending `.$`\n Children.forEach(children, (child) => {\n if (isValidElement(child)) filtered.push(child)\n })\n\n return filtered\n}\n\n/**\n * `AnimatePresence` enables the animation of components that have been removed from the tree.\n *\n * When adding/removing more than a single child, every child **must** be given a unique `key` prop.\n *\n * Any `motion` components that have an `exit` property defined will animate out when removed from\n * the tree.\n *\n * ```jsx\n * import { motion, AnimatePresence } from 'framer-motion'\n *\n * export const Items = ({ items }) => (\n * <AnimatePresence>\n * {items.map(item => (\n * <motion.div\n * key={item.id}\n * initial={{ opacity: 0 }}\n * animate={{ opacity: 1 }}\n * exit={{ opacity: 0 }}\n * />\n * ))}\n * </AnimatePresence>\n * )\n * ```\n *\n * You can sequence exit animations throughout a tree using variants.\n *\n * If a child contains multiple `motion` components with `exit` props, it will only unmount the child\n * once all `motion` components have finished animating out. Likewise, any components using\n * `useEntering` all need to call `safeToRemove`.\n *\n * @public\n */\nexport const AnimatePresence: React.FunctionComponent<\n React.PropsWithChildren<AnimatePresenceProps>\n> = ({\n children,\n enterVariant,\n exitVariant,\n initial = true,\n onExitComplete,\n exitBeforeEnter,\n presenceAffectsLayout = true,\n}) => {\n // We want to force a re-render once all exiting animations have finished. We\n // either use a local forceRender function, or one from a parent context if it exists.\n let forceRender = useForceUpdate()\n const forceRenderLayoutGroup = useContext(LayoutGroupContext).forceRender\n if (forceRenderLayoutGroup) forceRender = forceRenderLayoutGroup\n\n const [isMounted, setIsMounted] = useState(false)\n useEffect(() => {\n setIsMounted(true)\n }, [])\n\n // Filter out any children that aren't ReactElements. We can only track ReactElements with a props.key\n const filteredChildren = onlyElements(children)\n let childrenToRender = filteredChildren\n\n const exiting = new Set<ComponentKey>()\n\n // Keep a living record of the children we're actually rendering so we\n // can diff to figure out which are entering and exiting\n const presentChildren = useRef(childrenToRender)\n\n // A lookup table to quickly reference components by key\n const allChildren = useRef(new Map<ComponentKey, ReactElement<any>>()).current\n\n // If this is the initial component render, just deal with logic surrounding whether\n // we play onMount animations or not.\n const isInitialRender = useRef(true)\n\n useIsomorphicLayoutEffect(() => {\n isInitialRender.current = false\n updateChildLookup(filteredChildren, allChildren)\n presentChildren.current = childrenToRender\n })\n\n useUnmountEffect(() => {\n isInitialRender.current = true\n allChildren.clear()\n exiting.clear()\n })\n\n if (isInitialRender.current) {\n return (\n <>\n {childrenToRender.map((child) => (\n <PresenceChild\n key={getChildKey(child)}\n isEntering\n exitVariant={exitVariant}\n enterVariant={enterVariant}\n initial={initial ? undefined : false}\n presenceAffectsLayout={presenceAffectsLayout}\n >\n {child}\n </PresenceChild>\n ))}\n </>\n )\n }\n\n // If this is a subsequent render, deal with entering and exiting children\n childrenToRender = [...childrenToRender]\n\n // Diff the keys of the currently-present and target children to update our\n // exiting list.\n const presentKeys = presentChildren.current.map(getChildKey)\n const targetKeys = filteredChildren.map(getChildKey)\n\n // Diff the present children with our target children and mark those that are exiting\n const numPresent = presentKeys.length\n for (let i = 0; i < numPresent; i++) {\n const key = presentKeys[i]\n\n if (targetKeys.indexOf(key) === -1) {\n exiting.add(key)\n }\n }\n\n // If we currently have exiting children, and we're deferring rendering incoming children\n // until after all current children have exiting, empty the childrenToRender array\n if (exitBeforeEnter && exiting.size) {\n childrenToRender = []\n }\n\n // Loop through all currently exiting components and clone them to overwrite `animate`\n // with any `exit` prop they might have defined.\n exiting.forEach((key) => {\n // If this component is actually entering again, early return\n if (targetKeys.indexOf(key) !== -1) return\n\n const child = allChildren.get(key)\n if (!child) return\n\n const insertionIndex = presentKeys.indexOf(key)\n\n childrenToRender.splice(\n insertionIndex,\n 0,\n <PresenceChild\n key={getChildKey(child)}\n isEntering={false}\n onExitComplete={() => {\n allChildren.delete(key)\n exiting.delete(key)\n\n // Remove this child from the present children\n const removeIndex = presentChildren.current.findIndex(\n (presentChild) => presentChild.key === key\n )\n presentChildren.current.splice(removeIndex, 1)\n\n // Defer re-rendering until all exiting children have indeed left\n if (!exiting.size) {\n presentChildren.current = filteredChildren\n\n if (isMounted === false) return\n\n forceRender()\n onExitComplete?.()\n }\n }}\n exitVariant={exitVariant}\n enterVariant={enterVariant}\n presenceAffectsLayout={presenceAffectsLayout}\n >\n {child}\n </PresenceChild>\n )\n })\n\n // Add `MotionContext` even to children that don't need it to ensure we're rendering\n // the same tree between renders\n childrenToRender = childrenToRender.map((child) => {\n const key = child.key as string | number\n return exiting.has(key) ? (\n child\n ) : (\n <PresenceChild\n key={getChildKey(child)}\n isEntering={undefined}\n exitVariant={exitVariant}\n enterVariant={enterVariant}\n presenceAffectsLayout={presenceAffectsLayout}\n >\n {child}\n </PresenceChild>\n )\n })\n\n if (process.env.NODE_ENV !== 'production' && exitBeforeEnter && childrenToRender.length > 1) {\n console.warn(\n `You're attempting to animate multiple children within AnimatePresence, but its exitBeforeEnter prop is set to true. This will lead to odd visual behaviour.`\n )\n }\n\n return (\n <>{exiting.size ? childrenToRender : childrenToRender.map((child) => cloneElement(child))}</>\n )\n}\n\n// import { useForceUpdate, useIsomorphicLayoutEffect, useUnmountEffect } from '@tamagui/core'\n// import React, {\n// Children,\n// ReactElement,\n// ReactNode,\n// cloneElement,\n// isValidElement,\n// useContext,\n// useEffect,\n// useRef,\n// useState,\n// } from 'react'\n\n// import { LayoutGroupContext } from './LayoutGroupContext'\n// import { PresenceChild } from './PresenceChild'\n\n// React['keep']\n\n// export interface AnimatePresenceProps {\n// /**\n// * By passing `initial={false}`, `AnimatePresence` will disable any initial animations on children\n// * that are present when the component is first rendered.\n// */\n// initial?: boolean\n\n// /**\n// * When a component is removed, there's no longer a chance to update its props. So if a component's `exit`\n// * prop is defined as a dynamic variant and you want to pass a new `custom` prop, you can do so via `AnimatePresence`.\n// * This will ensure all leaving components animate using the latest data.\n// */\n// exitVariant?: string | null\n\n// enterVariant?: string | null\n\n// /**\n// * Fires when all exiting nodes have completed animating out.\n// */\n// onExitComplete?: () => void\n\n// /**\n// * If set to `true`, `AnimatePresence` will only render one component at a time. The exiting component\n// * will finish its exit animation before the entering component is rendered.\n// */\n// exitBeforeEnter?: boolean\n\n// /**\n// * Used in Framer to flag that sibling children *shouldn't* re-render as a result of a\n// * child being removed.\n// */\n// presenceAffectsLayout?: boolean\n// }\n\n// type ComponentKey = string | number\n\n// const getChildKey = (child: ReactElement<any>): ComponentKey => child.key || ''\n// const isDev = process.env.NODE_ENV !== 'production'\n\n// function updateChildLookup(\n// children: ReactElement<any>[],\n// allChildren: Map<ComponentKey, ReactElement<any>>\n// ) {\n// const seenChildren = isDev ? new Set<ComponentKey>() : null\n\n// for (const child of children) {\n// const key = getChildKey(child)\n// if (isDev && seenChildren && seenChildren.has(key)) {\n// console.warn(`Children of AnimatePresence require unique keys. \"${key}\" is a duplicate.`)\n// seenChildren.add(key)\n// }\n// allChildren.set(key, child)\n// }\n// }\n\n// function onlyElements(children: ReactNode): ReactElement<any>[] {\n// const filtered: ReactElement<any>[] = []\n\n// // We use forEach here instead of map as map mutates the component key by preprending `.$`\n// Children.forEach(children, (child) => {\n// if (isValidElement(child)) filtered.push(child)\n// })\n\n// return filtered\n// }\n\n// /**\n// * `AnimatePresence` enables the animation of components that have been removed from the tree.\n// *\n// * When adding/removing more than a single child, every child **must** be given a unique `key` prop.\n// *\n// * Any animated components that have an `exit` property defined will animate out when removed from\n// * the tree.\n// *\n// * ```jsx\n// * import { motion, AnimatePresence } from 'framer-motion'\n// *\n// * export const Items = ({ items }) => (\n// * <AnimatePresence>\n// * {items.map(item => (\n// * <motion.div\n// * key={item.id}\n// * initial={{ opacity: 0 }}\n// * animate={{ opacity: 1 }}\n// * exit={{ opacity: 0 }}\n// * />\n// * ))}\n// * </AnimatePresence>\n// * )\n// * ```\n// *\n// * You can sequence exit animations throughout a tree using variants.\n// *\n// * If a child contains multiple animated components with `exit` props, it will only unmount the child\n// * once all animated components have finished animating out. Likewise, any components using\n// * `useEntering` all need to call `safeToRemove`.\n// *\n// * @public\n// */\n// export const AnimatePresence: React.FunctionComponent<AnimatePresenceProps> = ({\n// children,\n// exitVariant,\n// enterVariant,\n// initial = true,\n// onExitComplete,\n// exitBeforeEnter,\n// presenceAffectsLayout = true,\n// }) => {\n// // We want to force a re-render once all exiting animations have finished. We\n// // either use a local forceRender function, or one from a parent context if it exists.\n// let forceRender = useForceUpdate()\n// const forceRenderLayoutGroup = useContext(LayoutGroupContext).forceRender\n// if (forceRenderLayoutGroup) forceRender = forceRenderLayoutGroup\n\n// const [isMounted, setIsMounted] = useState(false)\n// useEffect(() => {\n// setIsMounted(true)\n// }, [])\n\n// // Filter out any children that aren't ReactElements. We can only track ReactElements with a props.key\n// const filteredChildren = onlyElements(children)\n// let childrenToRender = filteredChildren\n\n// const exiting = new Set<ComponentKey>()\n\n// // Keep a living record of the children we're actually rendering so we\n// // can diff to figure out which are entering and exiting\n// const presentChildren = useRef(childrenToRender)\n\n// // A lookup table to quickly reference components by key\n// const allChildren = useRef(new Map<ComponentKey, ReactElement<any>>()).current\n\n// // If this is the initial component render, just deal with logic surrounding whether\n// // we play onMount animations or not.\n// const isInitialRender = useRef(true)\n\n// useIsomorphicLayoutEffect(() => {\n// isInitialRender.current = false\n// updateChildLookup(filteredChildren, allChildren)\n// presentChildren.current = childrenToRender\n// })\n\n// useUnmountEffect(() => {\n// isInitialRender.current = true\n// allChildren.clear()\n// exiting.clear()\n// })\n\n// if (isInitialRender.current) {\n// console.log('AnimatePresence (iniital)', isInitialRender.current, {\n// isMounted,\n// childrenToRender,\n// })\n// return (\n// <>\n// {childrenToRender.map((child) => (\n// <PresenceChild\n// key={getChildKey(child)}\n// isEntering\n// initial={initial ? undefined : false}\n// presenceAffectsLayout={presenceAffectsLayout}\n// exitVariant={exitVariant}\n// enterVariant={enterVariant}\n// >\n// {child}\n// </PresenceChild>\n// ))}\n// </>\n// )\n// }\n\n// // If this is a subsequent render, deal with entering and exiting children\n// childrenToRender = [...childrenToRender]\n\n// // Diff the keys of the currently-present and target children to update our\n// // exiting list.\n// const presentKeys = presentChildren.current.map(getChildKey)\n// const targetKeys = filteredChildren.map(getChildKey)\n\n// // Diff the present children with our target children and mark those that are exiting\n// const numPresent = presentKeys.length\n// for (let i = 0; i < numPresent; i++) {\n// const key = presentKeys[i]\n// if (targetKeys.indexOf(key) === -1) {\n// exiting.add(key)\n// }\n// }\n\n// // If we currently have exiting children, and we're deferring rendering incoming children\n// // until after all current children have exiting, empty the childrenToRender array\n// if (exitBeforeEnter && exiting.size) {\n// childrenToRender = []\n// }\n\n// // Loop through all currently exiting components and clone them to overwrite `animate`\n// // with any `exit` prop they might have defined.\n// for (const key of exiting) {\n// // If this component is actually entering again, early return\n// if (targetKeys.indexOf(key) !== -1) {\n// continue\n// }\n\n// const child = allChildren.get(key)\n// if (!child) {\n// continue\n// }\n\n// const insertionIndex = presentKeys.indexOf(key)\n\n// const onExit = () => {\n// allChildren.delete(key)\n// exiting.delete(key)\n\n// // Remove this child from the present children\n// const removeIndex = presentChildren.current.findIndex(\n// (presentChild) => presentChild.key === key\n// )\n// presentChildren.current.splice(removeIndex, 1)\n\n// // Defer re-rendering until all exiting children have indeed left\n// if (!exiting.size) {\n// presentChildren.current = filteredChildren\n// if (isMounted === false) {\n// return\n// }\n// forceRender()\n// onExitComplete?.()\n// }\n// }\n\n// childrenToRender.splice(\n// insertionIndex,\n// 0,\n// <PresenceChild\n// key={getChildKey(child)}\n// isEntering={false}\n// onExitComplete={onExit}\n// exitVariant={exitVariant}\n// enterVariant={enterVariant}\n// presenceAffectsLayout={presenceAffectsLayout}\n// >\n// {child}\n// </PresenceChild>\n// )\n// }\n\n// // Add `MotionContext` even to children that don't need it to ensure we're rendering\n// // the same tree between renders\n// childrenToRender = childrenToRender.map((child) => {\n// const key = child.key as string | number\n// return exiting.has(key) ? (\n// child\n// ) : (\n// <PresenceChild\n// key={getChildKey(child)}\n// isEntering={undefined}\n// exitVariant={exitVariant}\n// enterVariant={enterVariant}\n// presenceAffectsLayout={presenceAffectsLayout}\n// >\n// {child}\n// </PresenceChild>\n// )\n// })\n\n// console.log(\n// 'AnimatePresence ()',\n// isInitialRender.current,\n// {\n// isMounted,\n// },\n// childrenToRender.map((x) => x.props.children.props.children.props.src)\n// )\n\n// if (process.env.NODE_ENV !== 'production' && exitBeforeEnter && childrenToRender.length > 1) {\n// console.warn(\n// `You're attempting to animate multiple children within AnimatePresence, but its exitBeforeEnter prop is set to true. This will lead to odd visual behaviour.`\n// )\n// }\n\n// return (\n// <>{exiting.size ? childrenToRender : childrenToRender.map((child) => cloneElement(child))}</>\n// )\n// }\n"],
|
|
5
|
-
"mappings": ";;AAAA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import { useForceUpdate, useIsomorphicLayoutEffect, useUnmountEffect } from '@tamagui/core'\nimport React, {\n Children,\n ReactElement,\n ReactNode,\n cloneElement,\n isValidElement,\n useContext,\n useRef,\n useState,\n} from 'react'\n\nimport { LayoutGroupContext } from './LayoutGroupContext'\nimport { PresenceChild } from './PresenceChild'\n\nReact['keep']\n\nexport interface AnimatePresenceProps {\n /**\n * By passing `initial={false}`, `AnimatePresence` will disable any initial animations on children\n * that are present when the component is first rendered.\n */\n initial?: boolean\n\n /**\n * When a component is removed, there's no longer a chance to update its props. So if a component's `exit`\n * prop is defined as a dynamic variant and you want to pass a new `custom` prop, you can do so via `AnimatePresence`.\n * This will ensure all leaving components animate using the latest data.\n */\n exitVariant?: string | null\n\n enterVariant?: string | null\n\n /**\n * Fires when all exiting nodes have completed animating out.\n */\n onExitComplete?: () => void\n\n /**\n * If set to `true`, `AnimatePresence` will only render one component at a time. The exiting component\n * will finish its exit animation before the entering component is rendered.\n */\n exitBeforeEnter?: boolean\n\n /**\n * Used in Framer to flag that sibling children *shouldn't* re-render as a result of a\n * child being removed.\n */\n presenceAffectsLayout?: boolean\n}\n\ntype ComponentKey = string | number\n\nconst getChildKey = (child: ReactElement<any>): ComponentKey => child.key || ''\n\nconst isDev = process.env.NODE_ENV !== 'production'\n\nfunction updateChildLookup(\n children: ReactElement<any>[],\n allChildren: Map<ComponentKey, ReactElement<any>>\n) {\n const seenChildren = isDev ? new Set<ComponentKey>() : null\n\n children.forEach((child) => {\n const key = getChildKey(child)\n\n if (isDev && seenChildren && seenChildren.has(key)) {\n console.warn(`Children of AnimatePresence require unique keys. \"${key}\" is a duplicate.`)\n\n seenChildren.add(key)\n }\n\n allChildren.set(key, child)\n })\n}\n\nfunction onlyElements(children: ReactNode): ReactElement<any>[] {\n const filtered: ReactElement<any>[] = []\n\n // We use forEach here instead of map as map mutates the component key by preprending `.$`\n Children.forEach(children, (child) => {\n if (isValidElement(child)) filtered.push(child)\n })\n\n return filtered\n}\n\n/**\n * `AnimatePresence` enables the animation of components that have been removed from the tree.\n *\n * When adding/removing more than a single child, every child **must** be given a unique `key` prop.\n *\n * Any `motion` components that have an `exit` property defined will animate out when removed from\n * the tree.\n *\n * ```jsx\n * import { motion, AnimatePresence } from 'framer-motion'\n *\n * export const Items = ({ items }) => (\n * <AnimatePresence>\n * {items.map(item => (\n * <motion.div\n * key={item.id}\n * initial={{ opacity: 0 }}\n * animate={{ opacity: 1 }}\n * exit={{ opacity: 0 }}\n * />\n * ))}\n * </AnimatePresence>\n * )\n * ```\n *\n * You can sequence exit animations throughout a tree using variants.\n *\n * If a child contains multiple `motion` components with `exit` props, it will only unmount the child\n * once all `motion` components have finished animating out. Likewise, any components using\n * `useEntering` all need to call `safeToRemove`.\n *\n * @public\n */\nexport const AnimatePresence: React.FunctionComponent<\n React.PropsWithChildren<AnimatePresenceProps>\n> = ({\n children,\n enterVariant,\n exitVariant,\n initial = true,\n onExitComplete,\n exitBeforeEnter,\n presenceAffectsLayout = true,\n}) => {\n // We want to force a re-render once all exiting animations have finished. We\n // either use a local forceRender function, or one from a parent context if it exists.\n let forceRender = useForceUpdate()\n const forceRenderLayoutGroup = useContext(LayoutGroupContext).forceRender\n if (forceRenderLayoutGroup) forceRender = forceRenderLayoutGroup\n\n const [isMounted, setIsMounted] = useState(false)\n\n useIsomorphicLayoutEffect(() => {\n setIsMounted(true)\n }, [])\n\n // Filter out any children that aren't ReactElements. We can only track ReactElements with a props.key\n const filteredChildren = onlyElements(children)\n let childrenToRender = filteredChildren\n\n const exiting = new Set<ComponentKey>()\n\n // Keep a living record of the children we're actually rendering so we\n // can diff to figure out which are entering and exiting\n const presentChildren = useRef(childrenToRender)\n\n // A lookup table to quickly reference components by key\n const allChildren = useRef(new Map<ComponentKey, ReactElement<any>>()).current\n\n // If this is the initial component render, just deal with logic surrounding whether\n // we play onMount animations or not.\n const isInitialRender = useRef(true)\n\n useIsomorphicLayoutEffect(() => {\n isInitialRender.current = false\n updateChildLookup(filteredChildren, allChildren)\n presentChildren.current = childrenToRender\n })\n\n useUnmountEffect(() => {\n isInitialRender.current = true\n allChildren.clear()\n exiting.clear()\n })\n\n if (isInitialRender.current) {\n return (\n <>\n {childrenToRender.map((child) => (\n <PresenceChild\n key={getChildKey(child)}\n isEntering\n exitVariant={exitVariant}\n enterVariant={enterVariant}\n initial={initial ? undefined : false}\n presenceAffectsLayout={presenceAffectsLayout}\n >\n {child}\n </PresenceChild>\n ))}\n </>\n )\n }\n\n // If this is a subsequent render, deal with entering and exiting children\n childrenToRender = [...childrenToRender]\n\n // Diff the keys of the currently-present and target children to update our\n // exiting list.\n const presentKeys = presentChildren.current.map(getChildKey)\n const targetKeys = filteredChildren.map(getChildKey)\n\n // Diff the present children with our target children and mark those that are exiting\n const numPresent = presentKeys.length\n for (let i = 0; i < numPresent; i++) {\n const key = presentKeys[i]\n\n if (targetKeys.indexOf(key) === -1) {\n exiting.add(key)\n }\n }\n\n // If we currently have exiting children, and we're deferring rendering incoming children\n // until after all current children have exiting, empty the childrenToRender array\n if (exitBeforeEnter && exiting.size) {\n childrenToRender = []\n }\n\n // Loop through all currently exiting components and clone them to overwrite `animate`\n // with any `exit` prop they might have defined.\n exiting.forEach((key) => {\n // If this component is actually entering again, early return\n if (targetKeys.indexOf(key) !== -1) return\n\n const child = allChildren.get(key)\n if (!child) return\n\n const insertionIndex = presentKeys.indexOf(key)\n\n childrenToRender.splice(\n insertionIndex,\n 0,\n <PresenceChild\n key={getChildKey(child)}\n isEntering={false}\n onExitComplete={() => {\n allChildren.delete(key)\n exiting.delete(key)\n\n // Remove this child from the present children\n const removeIndex = presentChildren.current.findIndex(\n (presentChild) => presentChild.key === key\n )\n presentChildren.current.splice(removeIndex, 1)\n\n // Defer re-rendering until all exiting children have indeed left\n if (!exiting.size) {\n presentChildren.current = filteredChildren\n\n if (isMounted === false) return\n\n forceRender()\n onExitComplete?.()\n }\n }}\n exitVariant={exitVariant}\n enterVariant={enterVariant}\n presenceAffectsLayout={presenceAffectsLayout}\n >\n {child}\n </PresenceChild>\n )\n })\n\n // Add `MotionContext` even to children that don't need it to ensure we're rendering\n // the same tree between renders\n childrenToRender = childrenToRender.map((child) => {\n const key = child.key as string | number\n return exiting.has(key) ? (\n child\n ) : (\n <PresenceChild\n key={getChildKey(child)}\n isEntering={undefined}\n exitVariant={exitVariant}\n enterVariant={enterVariant}\n presenceAffectsLayout={presenceAffectsLayout}\n >\n {child}\n </PresenceChild>\n )\n })\n\n if (process.env.NODE_ENV !== 'production' && exitBeforeEnter && childrenToRender.length > 1) {\n console.warn(\n `You're attempting to animate multiple children within AnimatePresence, but its exitBeforeEnter prop is set to true. This will lead to odd visual behaviour.`\n )\n }\n\n return (\n <>{exiting.size ? childrenToRender : childrenToRender.map((child) => cloneElement(child))}</>\n )\n}\n\nAnimatePresence.displayName = 'AnimatePresence'\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import { useId } from "@
|
|
4
|
-
import { useConstant } from "@tamagui/core";
|
|
3
|
+
import { useConstant, useId } from "@tamagui/core";
|
|
5
4
|
import * as React from "react";
|
|
6
5
|
import { AnimatePresenceContext } from "./AnimatePresenceContext";
|
|
7
6
|
const PresenceChild = /* @__PURE__ */ __name(({
|
|
@@ -23,7 +22,6 @@ const PresenceChild = /* @__PURE__ */ __name(({
|
|
|
23
22
|
exitVariant,
|
|
24
23
|
enterVariant,
|
|
25
24
|
onExitComplete: (childId) => {
|
|
26
|
-
console.log("on exist complete", childId);
|
|
27
25
|
presenceChildren.set(childId, true);
|
|
28
26
|
for (const isComplete of presenceChildren.values()) {
|
|
29
27
|
if (!isComplete) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/PresenceChild.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useId } from '@
|
|
5
|
-
"mappings": ";;AAAA;AACA;
|
|
4
|
+
"sourcesContent": ["import { useConstant, useId } from '@tamagui/core'\nimport * as React from 'react'\n\nimport { AnimatePresenceContext, AnimatePresenceContextProps } from './AnimatePresenceContext'\nimport { VariantLabels } from './types'\n\ninterface PresenceChildProps {\n children: React.ReactElement<any>\n isEntering: boolean | undefined\n onExitComplete?: () => void\n initial?: false | VariantLabels\n exitVariant?: string | null\n enterVariant?: string | null\n presenceAffectsLayout: boolean\n}\n\nexport const PresenceChild = ({\n children,\n initial,\n isEntering,\n onExitComplete,\n exitVariant,\n enterVariant,\n presenceAffectsLayout,\n}: PresenceChildProps) => {\n const presenceChildren = useConstant(newChildrenMap)\n const id = useId()\n\n const context = React.useMemo(\n (): AnimatePresenceContextProps => {\n return {\n id,\n initial,\n isEntering,\n exitVariant,\n enterVariant,\n onExitComplete: (childId: string) => {\n presenceChildren.set(childId, true)\n for (const isComplete of presenceChildren.values()) {\n if (!isComplete) {\n return // can stop searching when any is incomplete\n }\n }\n onExitComplete?.()\n },\n register: (childId: string) => {\n presenceChildren.set(childId, false)\n return () => presenceChildren.delete(childId)\n },\n }\n },\n /**\n * If the presence of a child affects the layout of the components around it,\n * we want to make a new context value to ensure they get re-rendered\n * so they can detect that layout change.\n */\n presenceAffectsLayout ? undefined : [isEntering, onExitComplete, exitVariant, enterVariant]\n )\n\n // cant this be a useEffect?\n React.useMemo(() => {\n presenceChildren.forEach((_, key) => presenceChildren.set(key, false))\n }, [isEntering])\n\n /**\n * If there's no animated components to fire exit animations, we want to remove this\n * component immediately.\n */\n React.useEffect(() => {\n if (isEntering === false && !presenceChildren.size) {\n onExitComplete?.()\n }\n }, [isEntering])\n\n return (\n <AnimatePresenceContext.Provider value={context}>{children}</AnimatePresenceContext.Provider>\n )\n}\n\nfunction newChildrenMap(): Map<string, boolean> {\n return new Map()\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA;AACA;AAEA;AAaO,MAAM,gBAAgB,wBAAC;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,MACwB;AACxB,QAAM,mBAAmB,YAAY,cAAc;AACnD,QAAM,KAAK,MAAM;AAEjB,QAAM,UAAU,MAAM,QACpB,MAAmC;AACjC,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,gBAAgB,CAAC,YAAoB;AACnC,yBAAiB,IAAI,SAAS,IAAI;AAClC,mBAAW,cAAc,iBAAiB,OAAO,GAAG;AAClD,cAAI,CAAC,YAAY;AACf;AAAA,UACF;AAAA,QACF;AACA;AAAA,MACF;AAAA,MACA,UAAU,CAAC,YAAoB;AAC7B,yBAAiB,IAAI,SAAS,KAAK;AACnC,eAAO,MAAM,iBAAiB,OAAO,OAAO;AAAA,MAC9C;AAAA,IACF;AAAA,EACF,GAMA,wBAAwB,SAAY,CAAC,YAAY,gBAAgB,aAAa,YAAY,CAC5F;AAGA,QAAM,QAAQ,MAAM;AAClB,qBAAiB,QAAQ,CAAC,GAAG,QAAQ,iBAAiB,IAAI,KAAK,KAAK,CAAC;AAAA,EACvE,GAAG,CAAC,UAAU,CAAC;AAMf,QAAM,UAAU,MAAM;AACpB,QAAI,eAAe,SAAS,CAAC,iBAAiB,MAAM;AAClD;AAAA,IACF;AAAA,EACF,GAAG,CAAC,UAAU,CAAC;AAEf,SACE,oCAAC,uBAAuB,UAAvB;AAAA,IAAgC,OAAO;AAAA,KAAU,QAAS;AAE/D,GA7D6B;AA+D7B,0BAAgD;AAC9C,SAAO,oBAAI,IAAI;AACjB;AAFS;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/useEntering.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import { useId } from "@
|
|
3
|
+
import { useId } from "@tamagui/core";
|
|
4
4
|
import { useContext, useEffect } from "react";
|
|
5
5
|
import { AnimatePresenceContext } from "./AnimatePresenceContext";
|
|
6
6
|
function useEntering() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/useEntering.ts"],
|
|
4
|
-
"sourcesContent": ["import { useId } from '@
|
|
5
|
-
"mappings": ";;AAAA;AACA;AAEA;AAIO,uBAAwE;AAC7E,QAAM,UAAU,WAAW,sBAAsB;AAEjD,MAAI,YAAY,MAAM;AACpB,WAAO,CAAC,QAAW,MAAS;AAAA,EAC9B;AAEA,QAAM,EAAE,yBAAY,gBAAgB,aAAa;
|
|
4
|
+
"sourcesContent": ["import { useId } from '@tamagui/core'\nimport { useContext, useEffect } from 'react'\n\nimport { AnimatePresenceContext, AnimatePresenceContextProps } from './AnimatePresenceContext'\n\nexport type SafeToRemove = () => void\n\nexport function useEntering(): [boolean | undefined, undefined | (() => void)] {\n const context = useContext(AnimatePresenceContext)\n\n if (context === null) {\n return [undefined, undefined]\n }\n\n const { isEntering, onExitComplete, register } = context\n const id = useId()\n const safeToRemove = () => onExitComplete?.(id)\n\n // It's safe to call the following hooks conditionally (after an early return) because the context will always\n // either be null or non-null for the lifespan of the component.\n\n useEffect(() => {\n register(id)\n }, [])\n\n return isEntering === false\n ? [false, safeToRemove]\n : isEntering === true\n ? [true, safeToRemove]\n : [undefined, safeToRemove]\n}\n\n/**\n * Similar to `useEntering`, except `useIsEntering` simply returns whether or not the component is present.\n * There is no `safeToRemove` function. ```\n */\nexport function useIsEntering() {\n return isEntering(useContext(AnimatePresenceContext))\n}\n\nexport function isEntering(context: AnimatePresenceContextProps | null) {\n return context === null ? undefined : context.isEntering\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA;AACA;AAEA;AAIO,uBAAwE;AAC7E,QAAM,UAAU,WAAW,sBAAsB;AAEjD,MAAI,YAAY,MAAM;AACpB,WAAO,CAAC,QAAW,MAAS;AAAA,EAC9B;AAEA,QAAM,EAAE,yBAAY,gBAAgB,aAAa;AACjD,QAAM,KAAK,MAAM;AACjB,QAAM,eAAe,6BAAM,iDAAiB,KAAvB;AAKrB,YAAU,MAAM;AACd,aAAS,EAAE;AAAA,EACb,GAAG,CAAC,CAAC;AAEL,SAAO,gBAAe,QAClB,CAAC,OAAO,YAAY,IACpB,gBAAe,OACf,CAAC,MAAM,YAAY,IACnB,CAAC,QAAW,YAAY;AAC9B;AAvBgB;AA6BT,yBAAyB;AAC9B,SAAO,WAAW,WAAW,sBAAsB,CAAC;AACtD;AAFgB;AAIT,oBAAoB,SAA6C;AACtE,SAAO,YAAY,OAAO,SAAY,QAAQ;AAChD;AAFgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -6,7 +6,6 @@ import React, {
|
|
|
6
6
|
cloneElement,
|
|
7
7
|
isValidElement,
|
|
8
8
|
useContext,
|
|
9
|
-
useEffect,
|
|
10
9
|
useRef,
|
|
11
10
|
useState
|
|
12
11
|
} from "react";
|
|
@@ -50,7 +49,7 @@ const AnimatePresence = /* @__PURE__ */ __name(({
|
|
|
50
49
|
if (forceRenderLayoutGroup)
|
|
51
50
|
forceRender = forceRenderLayoutGroup;
|
|
52
51
|
const [isMounted, setIsMounted] = useState(false);
|
|
53
|
-
|
|
52
|
+
useIsomorphicLayoutEffect(() => {
|
|
54
53
|
setIsMounted(true);
|
|
55
54
|
}, []);
|
|
56
55
|
const filteredChildren = onlyElements(children);
|
|
@@ -115,6 +114,7 @@ const AnimatePresence = /* @__PURE__ */ __name(({
|
|
|
115
114
|
}
|
|
116
115
|
return <>{exiting.size ? childrenToRender : childrenToRender.map((child) => cloneElement(child))}</>;
|
|
117
116
|
}, "AnimatePresence");
|
|
117
|
+
AnimatePresence.displayName = "AnimatePresence";
|
|
118
118
|
export {
|
|
119
119
|
AnimatePresence
|
|
120
120
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import { useId } from "@
|
|
4
|
-
import { useConstant } from "@tamagui/core";
|
|
3
|
+
import { useConstant, useId } from "@tamagui/core";
|
|
5
4
|
import * as React from "react";
|
|
6
5
|
import { AnimatePresenceContext } from "./AnimatePresenceContext";
|
|
7
6
|
const PresenceChild = /* @__PURE__ */ __name(({
|
|
@@ -23,7 +22,6 @@ const PresenceChild = /* @__PURE__ */ __name(({
|
|
|
23
22
|
exitVariant,
|
|
24
23
|
enterVariant,
|
|
25
24
|
onExitComplete: (childId) => {
|
|
26
|
-
console.log("on exist complete", childId);
|
|
27
25
|
presenceChildren.set(childId, true);
|
|
28
26
|
for (const isComplete of presenceChildren.values()) {
|
|
29
27
|
if (!isComplete) {
|
package/dist/jsx/useEntering.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import { useId } from "@
|
|
3
|
+
import { useId } from "@tamagui/core";
|
|
4
4
|
import { useContext, useEffect } from "react";
|
|
5
5
|
import { AnimatePresenceContext } from "./AnimatePresenceContext";
|
|
6
6
|
function useEntering() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/animate-presence",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.15",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"typings": "types",
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
"dist"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@tamagui/core": "^1.0.0-beta.
|
|
15
|
+
"@tamagui/core": "^1.0.0-beta.15"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@tamagui/build": "^1.0.0-beta.
|
|
18
|
+
"@tamagui/build": "^1.0.0-beta.15"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"build": "tamagui-build",
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"publishConfig": {
|
|
27
27
|
"access": "public"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14"
|
|
30
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnimatePresence.d.ts","sourceRoot":"","sources":["../src/AnimatePresence.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AnimatePresence.d.ts","sourceRoot":"","sources":["../src/AnimatePresence.tsx"],"names":[],"mappings":"AACA,OAAO,KASN,MAAM,OAAO,CAAA;AAOd,MAAM,WAAW,oBAAoB;IAKnC,OAAO,CAAC,EAAE,OAAO,CAAA;IAOjB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAE3B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAK5B,cAAc,CAAC,EAAE,MAAM,IAAI,CAAA;IAM3B,eAAe,CAAC,EAAE,OAAO,CAAA;IAMzB,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC;AAuED,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,iBAAiB,CACnD,KAAK,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,CAwK9C,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnimatePresenceContext.d.ts","sourceRoot":"","sources":["../src/AnimatePresenceContext.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAEvC,MAAM,WAAW,2BAA2B;IAC1C,EAAE,EAAE,MAAM,CAAA;IACV,
|
|
1
|
+
{"version":3,"file":"AnimatePresenceContext.d.ts","sourceRoot":"","sources":["../src/AnimatePresenceContext.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAEvC,MAAM,WAAW,2BAA2B;IAC1C,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,OAAO,GAAG,SAAS,CAAA;IAC/B,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,IAAI,CAAA;IACpC,cAAc,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;IACrC,OAAO,CAAC,EAAE,KAAK,GAAG,aAAa,CAAA;IAC/B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC7B;AAED,eAAO,MAAM,sBAAsB,6DAA0D,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PresenceChild.d.ts","sourceRoot":"","sources":["../src/PresenceChild.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PresenceChild.d.ts","sourceRoot":"","sources":["../src/PresenceChild.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAEvC,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA;IACjC,UAAU,EAAE,OAAO,GAAG,SAAS,CAAA;IAC/B,cAAc,CAAC,EAAE,MAAM,IAAI,CAAA;IAC3B,OAAO,CAAC,EAAE,KAAK,GAAG,aAAa,CAAA;IAC/B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,qBAAqB,EAAE,OAAO,CAAA;CAC/B;AAED,eAAO,MAAM,aAAa,yGAQvB,kBAAkB,gBAqDpB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEntering.d.ts","sourceRoot":"","sources":["../src/useEntering.ts"],"names":[],"mappings":"AAGA,OAAO,EAA0B,2BAA2B,EAAE,MAAM,0BAA0B,CAAA;AAE9F,oBAAY,YAAY,GAAG,MAAM,IAAI,CAAA;AAErC,wBAAgB,WAAW,IAAI,CAAC,OAAO,GAAG,SAAS,EAAE,SAAS,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"useEntering.d.ts","sourceRoot":"","sources":["../src/useEntering.ts"],"names":[],"mappings":"AAGA,OAAO,EAA0B,2BAA2B,EAAE,MAAM,0BAA0B,CAAA;AAE9F,oBAAY,YAAY,GAAG,MAAM,IAAI,CAAA;AAErC,wBAAgB,WAAW,IAAI,CAAC,OAAO,GAAG,SAAS,EAAE,SAAS,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,CAuB7E;AAMD,wBAAgB,aAAa,wBAE5B;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,2BAA2B,GAAG,IAAI,uBAErE"}
|
package/dist/cjs/usePresence.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var usePresence_exports = {};
|
|
20
|
-
__export(usePresence_exports, {
|
|
21
|
-
isPresent: () => isPresent,
|
|
22
|
-
useIsPresent: () => useIsPresent,
|
|
23
|
-
usePresence: () => usePresence
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(usePresence_exports);
|
|
26
|
-
var import_utils = require("@react-aria/utils");
|
|
27
|
-
var import_react = require("react");
|
|
28
|
-
var import_AnimatePresenceContext = require("./AnimatePresenceContext");
|
|
29
|
-
function usePresence() {
|
|
30
|
-
const context = (0, import_react.useContext)(import_AnimatePresenceContext.AnimatePresenceContext);
|
|
31
|
-
if (context === null) {
|
|
32
|
-
return [true, null];
|
|
33
|
-
}
|
|
34
|
-
const { isPresent: isPresent2, onExitComplete, register } = context;
|
|
35
|
-
const id = (0, import_utils.useId)();
|
|
36
|
-
(0, import_react.useEffect)(() => {
|
|
37
|
-
register(id);
|
|
38
|
-
}, []);
|
|
39
|
-
const safeToRemove = /* @__PURE__ */ __name(() => onExitComplete == null ? void 0 : onExitComplete(id), "safeToRemove");
|
|
40
|
-
return !isPresent2 ? [false, safeToRemove] : [true];
|
|
41
|
-
}
|
|
42
|
-
__name(usePresence, "usePresence");
|
|
43
|
-
function useIsPresent() {
|
|
44
|
-
return isPresent((0, import_react.useContext)(import_AnimatePresenceContext.AnimatePresenceContext));
|
|
45
|
-
}
|
|
46
|
-
__name(useIsPresent, "useIsPresent");
|
|
47
|
-
function isPresent(context) {
|
|
48
|
-
return context === null ? true : context.isPresent;
|
|
49
|
-
}
|
|
50
|
-
__name(isPresent, "isPresent");
|
|
51
|
-
//# sourceMappingURL=usePresence.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/usePresence.ts"],
|
|
4
|
-
"sourcesContent": ["import { useId } from '@react-aria/utils'\nimport { useContext, useEffect } from 'react'\n\nimport { AnimatePresenceContext, AnimatePresenceContextProps } from './AnimatePresenceContext'\n\nexport type SafeToRemove = () => void\n\ntype AlwaysPresent = [true, null]\ntype Present = [true]\ntype NotPresent = [false, SafeToRemove]\n\nexport function usePresence(): AlwaysPresent | Present | NotPresent {\n const context = useContext(AnimatePresenceContext)\n\n if (context === null) {\n return [true, null]\n }\n\n const { isPresent, onExitComplete, register } = context\n\n // It's safe to call the following hooks conditionally (after an early return) because the context will always\n // either be null or non-null for the lifespan of the component.\n\n // Replace with useId when released in React\n const id = useId()\n\n useEffect(() => {\n register(id)\n }, [])\n\n const safeToRemove = () => onExitComplete?.(id)\n\n return !isPresent ? [false, safeToRemove] : [true]\n}\n\n/**\n * Similar to `usePresence`, except `useIsPresent` simply returns whether or not the component is present.\n * There is no `safeToRemove` function. ```\n */\nexport function useIsPresent() {\n return isPresent(useContext(AnimatePresenceContext))\n}\n\nexport function isPresent(context: AnimatePresenceContextProps | null) {\n return context === null ? true : context.isPresent\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AACtB,mBAAsC;AAEtC,oCAAoE;AAQ7D,uBAA6D;AAClE,QAAM,UAAU,6BAAW,oDAAsB;AAEjD,MAAI,YAAY,MAAM;AACpB,WAAO,CAAC,MAAM,IAAI;AAAA,EACpB;AAEA,QAAM,EAAE,uBAAW,gBAAgB,aAAa;AAMhD,QAAM,KAAK,wBAAM;AAEjB,8BAAU,MAAM;AACd,aAAS,EAAE;AAAA,EACb,GAAG,CAAC,CAAC;AAEL,QAAM,eAAe,6BAAM,iDAAiB,KAAvB;AAErB,SAAO,CAAC,aAAY,CAAC,OAAO,YAAY,IAAI,CAAC,IAAI;AACnD;AAtBgB;AA4BT,wBAAwB;AAC7B,SAAO,UAAU,6BAAW,oDAAsB,CAAC;AACrD;AAFgB;AAIT,mBAAmB,SAA6C;AACrE,SAAO,YAAY,OAAO,OAAO,QAAQ;AAC3C;AAFgB;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/esm/usePresence.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import { useId } from "@react-aria/utils";
|
|
4
|
-
import { useContext, useEffect } from "react";
|
|
5
|
-
import { AnimatePresenceContext } from "./AnimatePresenceContext";
|
|
6
|
-
function usePresence() {
|
|
7
|
-
const context = useContext(AnimatePresenceContext);
|
|
8
|
-
if (context === null) {
|
|
9
|
-
return [true, null];
|
|
10
|
-
}
|
|
11
|
-
const { isPresent: isPresent2, onExitComplete, register } = context;
|
|
12
|
-
const id = useId();
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
register(id);
|
|
15
|
-
}, []);
|
|
16
|
-
const safeToRemove = /* @__PURE__ */ __name(() => onExitComplete == null ? void 0 : onExitComplete(id), "safeToRemove");
|
|
17
|
-
return !isPresent2 ? [false, safeToRemove] : [true];
|
|
18
|
-
}
|
|
19
|
-
__name(usePresence, "usePresence");
|
|
20
|
-
function useIsPresent() {
|
|
21
|
-
return isPresent(useContext(AnimatePresenceContext));
|
|
22
|
-
}
|
|
23
|
-
__name(useIsPresent, "useIsPresent");
|
|
24
|
-
function isPresent(context) {
|
|
25
|
-
return context === null ? true : context.isPresent;
|
|
26
|
-
}
|
|
27
|
-
__name(isPresent, "isPresent");
|
|
28
|
-
export {
|
|
29
|
-
isPresent,
|
|
30
|
-
useIsPresent,
|
|
31
|
-
usePresence
|
|
32
|
-
};
|
|
33
|
-
//# sourceMappingURL=usePresence.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/usePresence.ts"],
|
|
4
|
-
"sourcesContent": ["import { useId } from '@react-aria/utils'\nimport { useContext, useEffect } from 'react'\n\nimport { AnimatePresenceContext, AnimatePresenceContextProps } from './AnimatePresenceContext'\n\nexport type SafeToRemove = () => void\n\ntype AlwaysPresent = [true, null]\ntype Present = [true]\ntype NotPresent = [false, SafeToRemove]\n\nexport function usePresence(): AlwaysPresent | Present | NotPresent {\n const context = useContext(AnimatePresenceContext)\n\n if (context === null) {\n return [true, null]\n }\n\n const { isPresent, onExitComplete, register } = context\n\n // It's safe to call the following hooks conditionally (after an early return) because the context will always\n // either be null or non-null for the lifespan of the component.\n\n // Replace with useId when released in React\n const id = useId()\n\n useEffect(() => {\n register(id)\n }, [])\n\n const safeToRemove = () => onExitComplete?.(id)\n\n return !isPresent ? [false, safeToRemove] : [true]\n}\n\n/**\n * Similar to `usePresence`, except `useIsPresent` simply returns whether or not the component is present.\n * There is no `safeToRemove` function. ```\n */\nexport function useIsPresent() {\n return isPresent(useContext(AnimatePresenceContext))\n}\n\nexport function isPresent(context: AnimatePresenceContextProps | null) {\n return context === null ? true : context.isPresent\n}\n"],
|
|
5
|
-
"mappings": ";;AAAA;AACA;AAEA;AAQO,uBAA6D;AAClE,QAAM,UAAU,WAAW,sBAAsB;AAEjD,MAAI,YAAY,MAAM;AACpB,WAAO,CAAC,MAAM,IAAI;AAAA,EACpB;AAEA,QAAM,EAAE,uBAAW,gBAAgB,aAAa;AAMhD,QAAM,KAAK,MAAM;AAEjB,YAAU,MAAM;AACd,aAAS,EAAE;AAAA,EACb,GAAG,CAAC,CAAC;AAEL,QAAM,eAAe,6BAAM,iDAAiB,KAAvB;AAErB,SAAO,CAAC,aAAY,CAAC,OAAO,YAAY,IAAI,CAAC,IAAI;AACnD;AAtBgB;AA4BT,wBAAwB;AAC7B,SAAO,UAAU,WAAW,sBAAsB,CAAC;AACrD;AAFgB;AAIT,mBAAmB,SAA6C;AACrE,SAAO,YAAY,OAAO,OAAO,QAAQ;AAC3C;AAFgB;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/jsx/usePresence.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import { useId } from "@react-aria/utils";
|
|
4
|
-
import { useContext, useEffect } from "react";
|
|
5
|
-
import { AnimatePresenceContext } from "./AnimatePresenceContext";
|
|
6
|
-
function usePresence() {
|
|
7
|
-
const context = useContext(AnimatePresenceContext);
|
|
8
|
-
if (context === null) {
|
|
9
|
-
return [true, null];
|
|
10
|
-
}
|
|
11
|
-
const { isPresent: isPresent2, onExitComplete, register } = context;
|
|
12
|
-
const id = useId();
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
register(id);
|
|
15
|
-
}, []);
|
|
16
|
-
const safeToRemove = /* @__PURE__ */ __name(() => onExitComplete == null ? void 0 : onExitComplete(id), "safeToRemove");
|
|
17
|
-
return !isPresent2 ? [false, safeToRemove] : [true];
|
|
18
|
-
}
|
|
19
|
-
__name(usePresence, "usePresence");
|
|
20
|
-
function useIsPresent() {
|
|
21
|
-
return isPresent(useContext(AnimatePresenceContext));
|
|
22
|
-
}
|
|
23
|
-
__name(useIsPresent, "useIsPresent");
|
|
24
|
-
function isPresent(context) {
|
|
25
|
-
return context === null ? true : context.isPresent;
|
|
26
|
-
}
|
|
27
|
-
__name(isPresent, "isPresent");
|
|
28
|
-
export {
|
|
29
|
-
isPresent,
|
|
30
|
-
useIsPresent,
|
|
31
|
-
usePresence
|
|
32
|
-
};
|
package/types/usePresence.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { AnimatePresenceContextProps } from './AnimatePresenceContext';
|
|
2
|
-
export declare type SafeToRemove = () => void;
|
|
3
|
-
declare type AlreadyPresent = [undefined];
|
|
4
|
-
declare type Entering = [true];
|
|
5
|
-
declare type Leaving = [false, SafeToRemove];
|
|
6
|
-
export declare function useEntering(): Entering | Leaving | AlreadyPresent;
|
|
7
|
-
export declare function useIsEntering(): boolean | undefined;
|
|
8
|
-
export declare function isEntering(context: AnimatePresenceContextProps | null): boolean | undefined;
|
|
9
|
-
export {};
|
|
10
|
-
//# sourceMappingURL=usePresence.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usePresence.d.ts","sourceRoot":"","sources":["../src/usePresence.ts"],"names":[],"mappings":"AAGA,OAAO,EAA0B,2BAA2B,EAAE,MAAM,0BAA0B,CAAA;AAE9F,oBAAY,YAAY,GAAG,MAAM,IAAI,CAAA;AAErC,aAAK,aAAa,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;AACjC,aAAK,OAAO,GAAG,CAAC,IAAI,CAAC,CAAA;AACrB,aAAK,UAAU,GAAG,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;AAEvC,wBAAgB,WAAW,IAAI,aAAa,GAAG,OAAO,GAAG,UAAU,CAsBlE;AAMD,wBAAgB,YAAY,YAE3B;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,2BAA2B,GAAG,IAAI,WAEpE"}
|