@tamagui/animate-presence 1.0.0-beta.202 → 1.0.0-beta.203
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 +47 -40
- package/dist/cjs/AnimatePresence.js.map +2 -2
- package/dist/cjs/AnimatePresenceContext.js +4 -0
- package/dist/cjs/AnimatePresenceContext.js.map +2 -2
- package/dist/cjs/LayoutGroupContext.js +4 -0
- package/dist/cjs/PresenceChild.js +30 -23
- package/dist/cjs/PresenceChild.js.map +2 -2
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/useEntering.js +6 -0
- package/dist/cjs/useEntering.js.map +0 -0
- package/dist/esm/AnimatePresence.js +43 -43
- package/dist/esm/AnimatePresence.js.map +2 -2
- package/dist/esm/AnimatePresenceContext.js.map +2 -2
- package/dist/esm/PresenceChild.js +26 -23
- package/dist/esm/PresenceChild.js.map +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/useEntering.js +0 -0
- package/dist/esm/useEntering.js.map +0 -0
- package/dist/jsx/AnimatePresence.js +26 -30
- package/dist/jsx/PresenceChild.js +26 -23
- package/dist/jsx/index.js +1 -1
- package/dist/jsx/useEntering.js +0 -0
- 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/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
|
@@ -25,22 +25,22 @@ __export(AnimatePresence_exports, {
|
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(AnimatePresence_exports);
|
|
27
27
|
var import_core = require("@tamagui/core");
|
|
28
|
-
var
|
|
29
|
-
var import_react = require("react");
|
|
28
|
+
var import_react = __toESM(require("react"));
|
|
30
29
|
var import_LayoutGroupContext = require("./LayoutGroupContext");
|
|
31
30
|
var import_PresenceChild = require("./PresenceChild");
|
|
31
|
+
import_react.default["keep"];
|
|
32
32
|
const getChildKey = /* @__PURE__ */ __name((child) => child.key || "", "getChildKey");
|
|
33
33
|
const isDev = process.env.NODE_ENV !== "production";
|
|
34
34
|
function updateChildLookup(children, allChildren) {
|
|
35
35
|
const seenChildren = isDev ? /* @__PURE__ */ new Set() : null;
|
|
36
|
-
|
|
36
|
+
children.forEach((child) => {
|
|
37
37
|
const key = getChildKey(child);
|
|
38
38
|
if (isDev && seenChildren && seenChildren.has(key)) {
|
|
39
39
|
console.warn(`Children of AnimatePresence require unique keys. "${key}" is a duplicate.`);
|
|
40
40
|
seenChildren.add(key);
|
|
41
41
|
}
|
|
42
42
|
allChildren.set(key, child);
|
|
43
|
-
}
|
|
43
|
+
});
|
|
44
44
|
}
|
|
45
45
|
__name(updateChildLookup, "updateChildLookup");
|
|
46
46
|
function onlyElements(children) {
|
|
@@ -54,7 +54,8 @@ function onlyElements(children) {
|
|
|
54
54
|
__name(onlyElements, "onlyElements");
|
|
55
55
|
const AnimatePresence = /* @__PURE__ */ __name(({
|
|
56
56
|
children,
|
|
57
|
-
|
|
57
|
+
enterVariant,
|
|
58
|
+
exitVariant,
|
|
58
59
|
initial = true,
|
|
59
60
|
onExitComplete,
|
|
60
61
|
exitBeforeEnter,
|
|
@@ -64,7 +65,10 @@ const AnimatePresence = /* @__PURE__ */ __name(({
|
|
|
64
65
|
const forceRenderLayoutGroup = (0, import_react.useContext)(import_LayoutGroupContext.LayoutGroupContext).forceRender;
|
|
65
66
|
if (forceRenderLayoutGroup)
|
|
66
67
|
forceRender = forceRenderLayoutGroup;
|
|
67
|
-
const isMounted = (0,
|
|
68
|
+
const [isMounted, setIsMounted] = (0, import_react.useState)(false);
|
|
69
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
70
|
+
setIsMounted(true);
|
|
71
|
+
}, []);
|
|
68
72
|
const filteredChildren = onlyElements(children);
|
|
69
73
|
let childrenToRender = filteredChildren;
|
|
70
74
|
const exiting = /* @__PURE__ */ new Set();
|
|
@@ -82,9 +86,11 @@ const AnimatePresence = /* @__PURE__ */ __name(({
|
|
|
82
86
|
exiting.clear();
|
|
83
87
|
});
|
|
84
88
|
if (isInitialRender.current) {
|
|
85
|
-
return /* @__PURE__ */
|
|
89
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, childrenToRender.map((child) => /* @__PURE__ */ import_react.default.createElement(import_PresenceChild.PresenceChild, {
|
|
86
90
|
key: getChildKey(child),
|
|
87
|
-
|
|
91
|
+
isEntering: true,
|
|
92
|
+
exitVariant,
|
|
93
|
+
enterVariant,
|
|
88
94
|
initial: initial ? void 0 : false,
|
|
89
95
|
presenceAffectsLayout
|
|
90
96
|
}, child)));
|
|
@@ -102,48 +108,49 @@ const AnimatePresence = /* @__PURE__ */ __name(({
|
|
|
102
108
|
if (exitBeforeEnter && exiting.size) {
|
|
103
109
|
childrenToRender = [];
|
|
104
110
|
}
|
|
105
|
-
|
|
106
|
-
if (targetKeys.indexOf(key) !== -1)
|
|
107
|
-
|
|
108
|
-
}
|
|
111
|
+
exiting.forEach((key) => {
|
|
112
|
+
if (targetKeys.indexOf(key) !== -1)
|
|
113
|
+
return;
|
|
109
114
|
const child = allChildren.get(key);
|
|
110
|
-
if (!child)
|
|
111
|
-
|
|
112
|
-
}
|
|
115
|
+
if (!child)
|
|
116
|
+
return;
|
|
113
117
|
const insertionIndex = presentKeys.indexOf(key);
|
|
114
|
-
|
|
115
|
-
allChildren.delete(key);
|
|
116
|
-
exiting.delete(key);
|
|
117
|
-
const removeIndex = presentChildren.current.findIndex((presentChild) => presentChild.key === key);
|
|
118
|
-
presentChildren.current.splice(removeIndex, 1);
|
|
119
|
-
if (!exiting.size) {
|
|
120
|
-
presentChildren.current = filteredChildren;
|
|
121
|
-
if (isMounted.current === false) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
forceRender();
|
|
125
|
-
onExitComplete == null ? void 0 : onExitComplete();
|
|
126
|
-
}
|
|
127
|
-
}, "onExit");
|
|
128
|
-
childrenToRender.splice(insertionIndex, 0, /* @__PURE__ */ React.createElement(import_PresenceChild.PresenceChild, {
|
|
118
|
+
childrenToRender.splice(insertionIndex, 0, /* @__PURE__ */ import_react.default.createElement(import_PresenceChild.PresenceChild, {
|
|
129
119
|
key: getChildKey(child),
|
|
130
|
-
|
|
131
|
-
onExitComplete:
|
|
132
|
-
|
|
120
|
+
isEntering: false,
|
|
121
|
+
onExitComplete: () => {
|
|
122
|
+
allChildren.delete(key);
|
|
123
|
+
exiting.delete(key);
|
|
124
|
+
const removeIndex = presentChildren.current.findIndex((presentChild) => presentChild.key === key);
|
|
125
|
+
presentChildren.current.splice(removeIndex, 1);
|
|
126
|
+
if (!exiting.size) {
|
|
127
|
+
presentChildren.current = filteredChildren;
|
|
128
|
+
if (isMounted === false)
|
|
129
|
+
return;
|
|
130
|
+
forceRender();
|
|
131
|
+
onExitComplete == null ? void 0 : onExitComplete();
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
exitVariant,
|
|
135
|
+
enterVariant,
|
|
133
136
|
presenceAffectsLayout
|
|
134
137
|
}, child));
|
|
135
|
-
}
|
|
138
|
+
});
|
|
136
139
|
childrenToRender = childrenToRender.map((child) => {
|
|
137
140
|
const key = child.key;
|
|
138
|
-
return exiting.has(key) ? child : /* @__PURE__ */
|
|
141
|
+
return exiting.has(key) ? child : /* @__PURE__ */ import_react.default.createElement(import_PresenceChild.PresenceChild, {
|
|
139
142
|
key: getChildKey(child),
|
|
140
|
-
|
|
143
|
+
isEntering: void 0,
|
|
144
|
+
exitVariant,
|
|
145
|
+
enterVariant,
|
|
141
146
|
presenceAffectsLayout
|
|
142
147
|
}, child);
|
|
143
148
|
});
|
|
144
|
-
|
|
145
|
-
console.warn(`You're attempting to animate multiple children within AnimatePresence, but its exitBeforeEnter prop is set to true. This will lead to odd visual behaviour.`);
|
|
146
|
-
}
|
|
147
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, exiting.size ? childrenToRender : childrenToRender.map((child) => (0, import_react.cloneElement)(child)));
|
|
149
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, exiting.size ? childrenToRender : childrenToRender.map((child) => (0, import_react.cloneElement)(child)));
|
|
148
150
|
}, "AnimatePresence");
|
|
151
|
+
AnimatePresence.displayName = "AnimatePresence";
|
|
152
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
153
|
+
0 && (module.exports = {
|
|
154
|
+
AnimatePresence
|
|
155
|
+
});
|
|
149
156
|
//# sourceMappingURL=AnimatePresence.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/AnimatePresence.tsx"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;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 useEffect,\n useLayoutEffect,\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 useLayoutEffect(() => {\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": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA4E;AAC5E,mBAWO;AAEP,gCAAmC;AACnC,2BAA8B;AAE9B,qBAAM;AAsCN,MAAM,cAAc,wBAAC,UAA2C,MAAM,OAAO,IAAzD;AAEpB,MAAM,QAAQ,QAAQ,IAAI,aAAa;AAEvC,2BACE,UACA,aACA;AACA,QAAM,eAAe,QAAQ,oBAAI,IAAkB,IAAI;AAEvD,WAAS,QAAQ,CAAC,UAAU;AAC1B,UAAM,MAAM,YAAY,KAAK;AAE7B,QAAI,SAAS,gBAAgB,aAAa,IAAI,GAAG,GAAG;AAClD,cAAQ,KAAK,qDAAqD,sBAAsB;AAExF,mBAAa,IAAI,GAAG;AAAA,IACtB;AAEA,gBAAY,IAAI,KAAK,KAAK;AAAA,EAC5B,CAAC;AACH;AAjBS;AAmBT,sBAAsB,UAA0C;AAC9D,QAAM,WAAgC,CAAC;AAGvC,wBAAS,QAAQ,UAAU,CAAC,UAAU;AACpC,QAAI,iCAAe,KAAK;AAAG,eAAS,KAAK,KAAK;AAAA,EAChD,CAAC;AAED,SAAO;AACT;AATS;AA4CF,MAAM,kBAET,wBAAC;AAAA,EACH;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA,wBAAwB;AAAA,MACpB;AAGJ,MAAI,cAAc,gCAAe;AACjC,QAAM,yBAAyB,6BAAW,4CAAkB,EAAE;AAC9D,MAAI;AAAwB,kBAAc;AAE1C,QAAM,CAAC,WAAW,gBAAgB,2BAAS,KAAK;AAEhD,oCAAgB,MAAM;AACpB,iBAAa,IAAI;AAAA,EACnB,GAAG,CAAC,CAAC;AAGL,QAAM,mBAAmB,aAAa,QAAQ;AAC9C,MAAI,mBAAmB;AAEvB,QAAM,UAAU,oBAAI,IAAkB;AAItC,QAAM,kBAAkB,yBAAO,gBAAgB;AAG/C,QAAM,cAAc,yBAAO,oBAAI,IAAqC,CAAC,EAAE;AAIvE,QAAM,kBAAkB,yBAAO,IAAI;AAEnC,6CAA0B,MAAM;AAC9B,oBAAgB,UAAU;AAC1B,sBAAkB,kBAAkB,WAAW;AAC/C,oBAAgB,UAAU;AAAA,EAC5B,CAAC;AAED,oCAAiB,MAAM;AACrB,oBAAgB,UAAU;AAC1B,gBAAY,MAAM;AAClB,YAAQ,MAAM;AAAA,EAChB,CAAC;AAED,MAAI,gBAAgB,SAAS;AAC3B,WACE,wFACG,iBAAiB,IAAI,CAAC,UACrB,mDAAC;AAAA,MACC,KAAK,YAAY,KAAK;AAAA,MACtB,YAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA,SAAS,UAAU,SAAY;AAAA,MAC/B;AAAA,OAEC,KACH,CACD,CACH;AAAA,EAEJ;AAGA,qBAAmB,CAAC,GAAG,gBAAgB;AAIvC,QAAM,cAAc,gBAAgB,QAAQ,IAAI,WAAW;AAC3D,QAAM,aAAa,iBAAiB,IAAI,WAAW;AAGnD,QAAM,aAAa,YAAY;AAC/B,WAAS,IAAI,GAAG,IAAI,YAAY,KAAK;AACnC,UAAM,MAAM,YAAY;AAExB,QAAI,WAAW,QAAQ,GAAG,MAAM,IAAI;AAClC,cAAQ,IAAI,GAAG;AAAA,IACjB;AAAA,EACF;AAIA,MAAI,mBAAmB,QAAQ,MAAM;AACnC,uBAAmB,CAAC;AAAA,EACtB;AAIA,UAAQ,QAAQ,CAAC,QAAQ;AAEvB,QAAI,WAAW,QAAQ,GAAG,MAAM;AAAI;AAEpC,UAAM,QAAQ,YAAY,IAAI,GAAG;AACjC,QAAI,CAAC;AAAO;AAEZ,UAAM,iBAAiB,YAAY,QAAQ,GAAG;AAE9C,qBAAiB,OACf,gBACA,GACA,mDAAC;AAAA,MACC,KAAK,YAAY,KAAK;AAAA,MACtB,YAAY;AAAA,MACZ,gBAAgB,MAAM;AACpB,oBAAY,OAAO,GAAG;AACtB,gBAAQ,OAAO,GAAG;AAGlB,cAAM,cAAc,gBAAgB,QAAQ,UAC1C,CAAC,iBAAiB,aAAa,QAAQ,GACzC;AACA,wBAAgB,QAAQ,OAAO,aAAa,CAAC;AAG7C,YAAI,CAAC,QAAQ,MAAM;AACjB,0BAAgB,UAAU;AAE1B,cAAI,cAAc;AAAO;AAEzB,sBAAY;AACZ;AAAA,QACF;AAAA,MACF;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,OAEC,KACH,CACF;AAAA,EACF,CAAC;AAID,qBAAmB,iBAAiB,IAAI,CAAC,UAAU;AACjD,UAAM,MAAM,MAAM;AAClB,WAAO,QAAQ,IAAI,GAAG,IACpB,QAEA,mDAAC;AAAA,MACC,KAAK,YAAY,KAAK;AAAA,MACtB,YAAY;AAAA,MACZ;AAAA,MACA;AAAA,MACA;AAAA,OAEC,KACH;AAAA,EAEJ,CAAC;AAQD,SACE,wFAAG,QAAQ,OAAO,mBAAmB,iBAAiB,IAAI,CAAC,UAAU,+BAAa,KAAK,CAAC,CAAE;AAE9F,GAvKI;AAyKJ,gBAAgB,cAAc;",
|
|
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
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/AnimatePresenceContext.tsx"],
|
|
4
|
-
"sourcesContent": ["import { createContext } from 'react'\n\nimport { VariantLabels } from './types'\n\nexport interface AnimatePresenceContextProps {\n id: string\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA8B;
|
|
4
|
+
"sourcesContent": ["import { createContext } from 'react'\n\nimport { VariantLabels } from './types'\n\nexport interface AnimatePresenceContextProps {\n id: string\n isEntering: boolean | undefined\n register: (id: string) => () => void\n onExitComplete?: (id: string) => void\n initial?: false | VariantLabels\n exitVariant?: string | null\n enterVariant?: string | null\n}\n\nexport const AnimatePresenceContext = createContext<AnimatePresenceContextProps | null>(null)\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA8B;AAcvB,MAAM,yBAAyB,gCAAkD,IAAI;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -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
|
|
@@ -31,41 +31,44 @@ var import_AnimatePresenceContext = require("./AnimatePresenceContext");
|
|
|
31
31
|
const PresenceChild = /* @__PURE__ */ __name(({
|
|
32
32
|
children,
|
|
33
33
|
initial,
|
|
34
|
-
|
|
34
|
+
isEntering,
|
|
35
35
|
onExitComplete,
|
|
36
|
-
|
|
36
|
+
exitVariant,
|
|
37
|
+
enterVariant,
|
|
37
38
|
presenceAffectsLayout
|
|
38
39
|
}) => {
|
|
39
40
|
const presenceChildren = (0, import_core.useConstant)(newChildrenMap);
|
|
40
41
|
const id = (0, import_utils.useId)();
|
|
41
|
-
const context = React.useMemo(() =>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
const context = React.useMemo(() => {
|
|
43
|
+
return {
|
|
44
|
+
id,
|
|
45
|
+
initial,
|
|
46
|
+
isEntering,
|
|
47
|
+
exitVariant,
|
|
48
|
+
enterVariant,
|
|
49
|
+
onExitComplete: (childId) => {
|
|
50
|
+
presenceChildren.set(childId, true);
|
|
51
|
+
for (const isComplete of presenceChildren.values()) {
|
|
52
|
+
if (!isComplete) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
51
55
|
}
|
|
56
|
+
onExitComplete == null ? void 0 : onExitComplete();
|
|
57
|
+
},
|
|
58
|
+
register: (childId) => {
|
|
59
|
+
presenceChildren.set(childId, false);
|
|
60
|
+
return () => presenceChildren.delete(childId);
|
|
52
61
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
register: (childId) => {
|
|
56
|
-
presenceChildren.set(childId, false);
|
|
57
|
-
return () => presenceChildren.delete(childId);
|
|
58
|
-
}
|
|
59
|
-
}), presenceAffectsLayout ? void 0 : [isPresent]);
|
|
62
|
+
};
|
|
63
|
+
}, presenceAffectsLayout ? void 0 : [isEntering, onExitComplete, exitVariant, enterVariant]);
|
|
60
64
|
React.useMemo(() => {
|
|
61
65
|
presenceChildren.forEach((_, key) => presenceChildren.set(key, false));
|
|
62
|
-
}, [
|
|
66
|
+
}, [isEntering]);
|
|
63
67
|
React.useEffect(() => {
|
|
64
|
-
if (
|
|
65
|
-
console.log("on exit complete");
|
|
68
|
+
if (isEntering === false && !presenceChildren.size) {
|
|
66
69
|
onExitComplete == null ? void 0 : onExitComplete();
|
|
67
70
|
}
|
|
68
|
-
}, [
|
|
71
|
+
}, [isEntering]);
|
|
69
72
|
return /* @__PURE__ */ React.createElement(import_AnimatePresenceContext.AnimatePresenceContext.Provider, {
|
|
70
73
|
value: context
|
|
71
74
|
}, children);
|
|
@@ -74,4 +77,8 @@ function newChildrenMap() {
|
|
|
74
77
|
return /* @__PURE__ */ new Map();
|
|
75
78
|
}
|
|
76
79
|
__name(newChildrenMap, "newChildrenMap");
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
PresenceChild
|
|
83
|
+
});
|
|
77
84
|
//# 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 '@react-aria/utils'\nimport { useConstant } 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
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AACtB,kBAA4B;AAC5B,YAAuB;AAEvB,oCAAoE;
|
|
4
|
+
"sourcesContent": ["import { useId } from '@react-aria/utils'\nimport { useConstant } 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,mBAAsB;AACtB,kBAA4B;AAC5B,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,wBAAM;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
|
@@ -22,6 +22,10 @@ __export(src_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(src_exports);
|
|
24
24
|
__reExport(src_exports, require("./AnimatePresence"), module.exports);
|
|
25
|
-
__reExport(src_exports, require("./
|
|
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/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './AnimatePresence'\nexport * from './
|
|
4
|
+
"sourcesContent": ["export * from './AnimatePresence'\nexport * from './useEntering'\nexport { AnimatePresenceContext } from './AnimatePresenceContext'\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAc,8BAAd;AACA,wBAAc,0BADd;AAEA,oCAAuC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/useEntering.js
CHANGED
|
@@ -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
|
|
File without changes
|
|
@@ -1,33 +1,30 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
useIsMounted,
|
|
6
|
-
useIsomorphicLayoutEffect,
|
|
7
|
-
useUnmountEffect
|
|
8
|
-
} from "@tamagui/core";
|
|
9
|
-
import * as React from "react";
|
|
10
|
-
import {
|
|
3
|
+
import { useForceUpdate, useIsomorphicLayoutEffect, useUnmountEffect } from "@tamagui/core";
|
|
4
|
+
import React, {
|
|
11
5
|
Children,
|
|
12
6
|
cloneElement,
|
|
13
7
|
isValidElement,
|
|
14
8
|
useContext,
|
|
15
|
-
|
|
9
|
+
useLayoutEffect,
|
|
10
|
+
useRef,
|
|
11
|
+
useState
|
|
16
12
|
} from "react";
|
|
17
13
|
import { LayoutGroupContext } from "./LayoutGroupContext";
|
|
18
14
|
import { PresenceChild } from "./PresenceChild";
|
|
15
|
+
React["keep"];
|
|
19
16
|
const getChildKey = /* @__PURE__ */ __name((child) => child.key || "", "getChildKey");
|
|
20
17
|
const isDev = process.env.NODE_ENV !== "production";
|
|
21
18
|
function updateChildLookup(children, allChildren) {
|
|
22
19
|
const seenChildren = isDev ? /* @__PURE__ */ new Set() : null;
|
|
23
|
-
|
|
20
|
+
children.forEach((child) => {
|
|
24
21
|
const key = getChildKey(child);
|
|
25
22
|
if (isDev && seenChildren && seenChildren.has(key)) {
|
|
26
23
|
console.warn(`Children of AnimatePresence require unique keys. "${key}" is a duplicate.`);
|
|
27
24
|
seenChildren.add(key);
|
|
28
25
|
}
|
|
29
26
|
allChildren.set(key, child);
|
|
30
|
-
}
|
|
27
|
+
});
|
|
31
28
|
}
|
|
32
29
|
__name(updateChildLookup, "updateChildLookup");
|
|
33
30
|
function onlyElements(children) {
|
|
@@ -41,7 +38,8 @@ function onlyElements(children) {
|
|
|
41
38
|
__name(onlyElements, "onlyElements");
|
|
42
39
|
const AnimatePresence = /* @__PURE__ */ __name(({
|
|
43
40
|
children,
|
|
44
|
-
|
|
41
|
+
enterVariant,
|
|
42
|
+
exitVariant,
|
|
45
43
|
initial = true,
|
|
46
44
|
onExitComplete,
|
|
47
45
|
exitBeforeEnter,
|
|
@@ -51,7 +49,10 @@ const AnimatePresence = /* @__PURE__ */ __name(({
|
|
|
51
49
|
const forceRenderLayoutGroup = useContext(LayoutGroupContext).forceRender;
|
|
52
50
|
if (forceRenderLayoutGroup)
|
|
53
51
|
forceRender = forceRenderLayoutGroup;
|
|
54
|
-
const isMounted =
|
|
52
|
+
const [isMounted, setIsMounted] = useState(false);
|
|
53
|
+
useLayoutEffect(() => {
|
|
54
|
+
setIsMounted(true);
|
|
55
|
+
}, []);
|
|
55
56
|
const filteredChildren = onlyElements(children);
|
|
56
57
|
let childrenToRender = filteredChildren;
|
|
57
58
|
const exiting = /* @__PURE__ */ new Set();
|
|
@@ -71,7 +72,9 @@ const AnimatePresence = /* @__PURE__ */ __name(({
|
|
|
71
72
|
if (isInitialRender.current) {
|
|
72
73
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, childrenToRender.map((child) => /* @__PURE__ */ React.createElement(PresenceChild, {
|
|
73
74
|
key: getChildKey(child),
|
|
74
|
-
|
|
75
|
+
isEntering: true,
|
|
76
|
+
exitVariant,
|
|
77
|
+
enterVariant,
|
|
75
78
|
initial: initial ? void 0 : false,
|
|
76
79
|
presenceAffectsLayout
|
|
77
80
|
}, child)));
|
|
@@ -89,50 +92,47 @@ const AnimatePresence = /* @__PURE__ */ __name(({
|
|
|
89
92
|
if (exitBeforeEnter && exiting.size) {
|
|
90
93
|
childrenToRender = [];
|
|
91
94
|
}
|
|
92
|
-
|
|
93
|
-
if (targetKeys.indexOf(key) !== -1)
|
|
94
|
-
|
|
95
|
-
}
|
|
95
|
+
exiting.forEach((key) => {
|
|
96
|
+
if (targetKeys.indexOf(key) !== -1)
|
|
97
|
+
return;
|
|
96
98
|
const child = allChildren.get(key);
|
|
97
|
-
if (!child)
|
|
98
|
-
|
|
99
|
-
}
|
|
99
|
+
if (!child)
|
|
100
|
+
return;
|
|
100
101
|
const insertionIndex = presentKeys.indexOf(key);
|
|
101
|
-
const onExit = /* @__PURE__ */ __name(() => {
|
|
102
|
-
allChildren.delete(key);
|
|
103
|
-
exiting.delete(key);
|
|
104
|
-
const removeIndex = presentChildren.current.findIndex((presentChild) => presentChild.key === key);
|
|
105
|
-
presentChildren.current.splice(removeIndex, 1);
|
|
106
|
-
if (!exiting.size) {
|
|
107
|
-
presentChildren.current = filteredChildren;
|
|
108
|
-
if (isMounted.current === false) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
forceRender();
|
|
112
|
-
onExitComplete == null ? void 0 : onExitComplete();
|
|
113
|
-
}
|
|
114
|
-
}, "onExit");
|
|
115
102
|
childrenToRender.splice(insertionIndex, 0, /* @__PURE__ */ React.createElement(PresenceChild, {
|
|
116
103
|
key: getChildKey(child),
|
|
117
|
-
|
|
118
|
-
onExitComplete:
|
|
119
|
-
|
|
104
|
+
isEntering: false,
|
|
105
|
+
onExitComplete: () => {
|
|
106
|
+
allChildren.delete(key);
|
|
107
|
+
exiting.delete(key);
|
|
108
|
+
const removeIndex = presentChildren.current.findIndex((presentChild) => presentChild.key === key);
|
|
109
|
+
presentChildren.current.splice(removeIndex, 1);
|
|
110
|
+
if (!exiting.size) {
|
|
111
|
+
presentChildren.current = filteredChildren;
|
|
112
|
+
if (isMounted === false)
|
|
113
|
+
return;
|
|
114
|
+
forceRender();
|
|
115
|
+
onExitComplete == null ? void 0 : onExitComplete();
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
exitVariant,
|
|
119
|
+
enterVariant,
|
|
120
120
|
presenceAffectsLayout
|
|
121
121
|
}, child));
|
|
122
|
-
}
|
|
122
|
+
});
|
|
123
123
|
childrenToRender = childrenToRender.map((child) => {
|
|
124
124
|
const key = child.key;
|
|
125
125
|
return exiting.has(key) ? child : /* @__PURE__ */ React.createElement(PresenceChild, {
|
|
126
126
|
key: getChildKey(child),
|
|
127
|
-
|
|
127
|
+
isEntering: void 0,
|
|
128
|
+
exitVariant,
|
|
129
|
+
enterVariant,
|
|
128
130
|
presenceAffectsLayout
|
|
129
131
|
}, child);
|
|
130
132
|
});
|
|
131
|
-
if (process.env.NODE_ENV !== "production" && exitBeforeEnter && childrenToRender.length > 1) {
|
|
132
|
-
console.warn(`You're attempting to animate multiple children within AnimatePresence, but its exitBeforeEnter prop is set to true. This will lead to odd visual behaviour.`);
|
|
133
|
-
}
|
|
134
133
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, exiting.size ? childrenToRender : childrenToRender.map((child) => cloneElement(child)));
|
|
135
134
|
}, "AnimatePresence");
|
|
135
|
+
AnimatePresence.displayName = "AnimatePresence";
|
|
136
136
|
export {
|
|
137
137
|
AnimatePresence
|
|
138
138
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/AnimatePresence.tsx"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": ";;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 useEffect,\n useLayoutEffect,\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 useLayoutEffect(() => {\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": ";;AAAA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA;AACA;AAEA,MAAM;AAsCN,MAAM,cAAc,wBAAC,UAA2C,MAAM,OAAO,IAAzD;AAEpB,MAAM,QAAQ,QAAQ,IAAI,aAAa;AAEvC,2BACE,UACA,aACA;AACA,QAAM,eAAe,QAAQ,oBAAI,IAAkB,IAAI;AAEvD,WAAS,QAAQ,CAAC,UAAU;AAC1B,UAAM,MAAM,YAAY,KAAK;AAE7B,QAAI,SAAS,gBAAgB,aAAa,IAAI,GAAG,GAAG;AAClD,cAAQ,KAAK,qDAAqD,sBAAsB;AAExF,mBAAa,IAAI,GAAG;AAAA,IACtB;AAEA,gBAAY,IAAI,KAAK,KAAK;AAAA,EAC5B,CAAC;AACH;AAjBS;AAmBT,sBAAsB,UAA0C;AAC9D,QAAM,WAAgC,CAAC;AAGvC,WAAS,QAAQ,UAAU,CAAC,UAAU;AACpC,QAAI,eAAe,KAAK;AAAG,eAAS,KAAK,KAAK;AAAA,EAChD,CAAC;AAED,SAAO;AACT;AATS;AA4CF,MAAM,kBAET,wBAAC;AAAA,EACH;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA,wBAAwB;AAAA,MACpB;AAGJ,MAAI,cAAc,eAAe;AACjC,QAAM,yBAAyB,WAAW,kBAAkB,EAAE;AAC9D,MAAI;AAAwB,kBAAc;AAE1C,QAAM,CAAC,WAAW,gBAAgB,SAAS,KAAK;AAEhD,kBAAgB,MAAM;AACpB,iBAAa,IAAI;AAAA,EACnB,GAAG,CAAC,CAAC;AAGL,QAAM,mBAAmB,aAAa,QAAQ;AAC9C,MAAI,mBAAmB;AAEvB,QAAM,UAAU,oBAAI,IAAkB;AAItC,QAAM,kBAAkB,OAAO,gBAAgB;AAG/C,QAAM,cAAc,OAAO,oBAAI,IAAqC,CAAC,EAAE;AAIvE,QAAM,kBAAkB,OAAO,IAAI;AAEnC,4BAA0B,MAAM;AAC9B,oBAAgB,UAAU;AAC1B,sBAAkB,kBAAkB,WAAW;AAC/C,oBAAgB,UAAU;AAAA,EAC5B,CAAC;AAED,mBAAiB,MAAM;AACrB,oBAAgB,UAAU;AAC1B,gBAAY,MAAM;AAClB,YAAQ,MAAM;AAAA,EAChB,CAAC;AAED,MAAI,gBAAgB,SAAS;AAC3B,WACE,0DACG,iBAAiB,IAAI,CAAC,UACrB,oCAAC;AAAA,MACC,KAAK,YAAY,KAAK;AAAA,MACtB,YAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA,SAAS,UAAU,SAAY;AAAA,MAC/B;AAAA,OAEC,KACH,CACD,CACH;AAAA,EAEJ;AAGA,qBAAmB,CAAC,GAAG,gBAAgB;AAIvC,QAAM,cAAc,gBAAgB,QAAQ,IAAI,WAAW;AAC3D,QAAM,aAAa,iBAAiB,IAAI,WAAW;AAGnD,QAAM,aAAa,YAAY;AAC/B,WAAS,IAAI,GAAG,IAAI,YAAY,KAAK;AACnC,UAAM,MAAM,YAAY;AAExB,QAAI,WAAW,QAAQ,GAAG,MAAM,IAAI;AAClC,cAAQ,IAAI,GAAG;AAAA,IACjB;AAAA,EACF;AAIA,MAAI,mBAAmB,QAAQ,MAAM;AACnC,uBAAmB,CAAC;AAAA,EACtB;AAIA,UAAQ,QAAQ,CAAC,QAAQ;AAEvB,QAAI,WAAW,QAAQ,GAAG,MAAM;AAAI;AAEpC,UAAM,QAAQ,YAAY,IAAI,GAAG;AACjC,QAAI,CAAC;AAAO;AAEZ,UAAM,iBAAiB,YAAY,QAAQ,GAAG;AAE9C,qBAAiB,OACf,gBACA,GACA,oCAAC;AAAA,MACC,KAAK,YAAY,KAAK;AAAA,MACtB,YAAY;AAAA,MACZ,gBAAgB,MAAM;AACpB,oBAAY,OAAO,GAAG;AACtB,gBAAQ,OAAO,GAAG;AAGlB,cAAM,cAAc,gBAAgB,QAAQ,UAC1C,CAAC,iBAAiB,aAAa,QAAQ,GACzC;AACA,wBAAgB,QAAQ,OAAO,aAAa,CAAC;AAG7C,YAAI,CAAC,QAAQ,MAAM;AACjB,0BAAgB,UAAU;AAE1B,cAAI,cAAc;AAAO;AAEzB,sBAAY;AACZ;AAAA,QACF;AAAA,MACF;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,OAEC,KACH,CACF;AAAA,EACF,CAAC;AAID,qBAAmB,iBAAiB,IAAI,CAAC,UAAU;AACjD,UAAM,MAAM,MAAM;AAClB,WAAO,QAAQ,IAAI,GAAG,IACpB,QAEA,oCAAC;AAAA,MACC,KAAK,YAAY,KAAK;AAAA,MACtB,YAAY;AAAA,MACZ;AAAA,MACA;AAAA,MACA;AAAA,OAEC,KACH;AAAA,EAEJ,CAAC;AAQD,SACE,0DAAG,QAAQ,OAAO,mBAAmB,iBAAiB,IAAI,CAAC,UAAU,aAAa,KAAK,CAAC,CAAE;AAE9F,GAvKI;AAyKJ,gBAAgB,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/AnimatePresenceContext.tsx"],
|
|
4
|
-
"sourcesContent": ["import { createContext } from 'react'\n\nimport { VariantLabels } from './types'\n\nexport interface AnimatePresenceContextProps {\n id: string\n
|
|
5
|
-
"mappings": "AAAA;
|
|
4
|
+
"sourcesContent": ["import { createContext } from 'react'\n\nimport { VariantLabels } from './types'\n\nexport interface AnimatePresenceContextProps {\n id: string\n isEntering: boolean | undefined\n register: (id: string) => () => void\n onExitComplete?: (id: string) => void\n initial?: false | VariantLabels\n exitVariant?: string | null\n enterVariant?: string | null\n}\n\nexport const AnimatePresenceContext = createContext<AnimatePresenceContextProps | null>(null)\n"],
|
|
5
|
+
"mappings": "AAAA;AAcO,MAAM,yBAAyB,cAAkD,IAAI;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -7,41 +7,44 @@ import { AnimatePresenceContext } from "./AnimatePresenceContext";
|
|
|
7
7
|
const PresenceChild = /* @__PURE__ */ __name(({
|
|
8
8
|
children,
|
|
9
9
|
initial,
|
|
10
|
-
|
|
10
|
+
isEntering,
|
|
11
11
|
onExitComplete,
|
|
12
|
-
|
|
12
|
+
exitVariant,
|
|
13
|
+
enterVariant,
|
|
13
14
|
presenceAffectsLayout
|
|
14
15
|
}) => {
|
|
15
16
|
const presenceChildren = useConstant(newChildrenMap);
|
|
16
17
|
const id = useId();
|
|
17
|
-
const context = React.useMemo(() =>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
const context = React.useMemo(() => {
|
|
19
|
+
return {
|
|
20
|
+
id,
|
|
21
|
+
initial,
|
|
22
|
+
isEntering,
|
|
23
|
+
exitVariant,
|
|
24
|
+
enterVariant,
|
|
25
|
+
onExitComplete: (childId) => {
|
|
26
|
+
presenceChildren.set(childId, true);
|
|
27
|
+
for (const isComplete of presenceChildren.values()) {
|
|
28
|
+
if (!isComplete) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
27
31
|
}
|
|
32
|
+
onExitComplete == null ? void 0 : onExitComplete();
|
|
33
|
+
},
|
|
34
|
+
register: (childId) => {
|
|
35
|
+
presenceChildren.set(childId, false);
|
|
36
|
+
return () => presenceChildren.delete(childId);
|
|
28
37
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
register: (childId) => {
|
|
32
|
-
presenceChildren.set(childId, false);
|
|
33
|
-
return () => presenceChildren.delete(childId);
|
|
34
|
-
}
|
|
35
|
-
}), presenceAffectsLayout ? void 0 : [isPresent]);
|
|
38
|
+
};
|
|
39
|
+
}, presenceAffectsLayout ? void 0 : [isEntering, onExitComplete, exitVariant, enterVariant]);
|
|
36
40
|
React.useMemo(() => {
|
|
37
41
|
presenceChildren.forEach((_, key) => presenceChildren.set(key, false));
|
|
38
|
-
}, [
|
|
42
|
+
}, [isEntering]);
|
|
39
43
|
React.useEffect(() => {
|
|
40
|
-
if (
|
|
41
|
-
console.log("on exit complete");
|
|
44
|
+
if (isEntering === false && !presenceChildren.size) {
|
|
42
45
|
onExitComplete == null ? void 0 : onExitComplete();
|
|
43
46
|
}
|
|
44
|
-
}, [
|
|
47
|
+
}, [isEntering]);
|
|
45
48
|
return /* @__PURE__ */ React.createElement(AnimatePresenceContext.Provider, {
|
|
46
49
|
value: context
|
|
47
50
|
}, children);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/PresenceChild.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useId } from '@react-aria/utils'\nimport { useConstant } 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
|
|
5
|
-
"mappings": ";;AAAA;AACA;AACA;AAEA;
|
|
4
|
+
"sourcesContent": ["import { useId } from '@react-aria/utils'\nimport { useConstant } 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;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/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './AnimatePresence'\nexport * from './
|
|
4
|
+
"sourcesContent": ["export * from './AnimatePresence'\nexport * from './useEntering'\nexport { AnimatePresenceContext } from './AnimatePresenceContext'\n"],
|
|
5
5
|
"mappings": "AAAA;AACA;AACA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/useEntering.js
CHANGED
|
File without changes
|
|
File without changes
|
|
@@ -1,32 +1,30 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
useIsMounted,
|
|
6
|
-
useIsomorphicLayoutEffect,
|
|
7
|
-
useUnmountEffect
|
|
8
|
-
} from "@tamagui/core";
|
|
9
|
-
import {
|
|
3
|
+
import { useForceUpdate, useIsomorphicLayoutEffect, useUnmountEffect } from "@tamagui/core";
|
|
4
|
+
import React, {
|
|
10
5
|
Children,
|
|
11
6
|
cloneElement,
|
|
12
7
|
isValidElement,
|
|
13
8
|
useContext,
|
|
14
|
-
|
|
9
|
+
useLayoutEffect,
|
|
10
|
+
useRef,
|
|
11
|
+
useState
|
|
15
12
|
} from "react";
|
|
16
13
|
import { LayoutGroupContext } from "./LayoutGroupContext";
|
|
17
14
|
import { PresenceChild } from "./PresenceChild";
|
|
15
|
+
React["keep"];
|
|
18
16
|
const getChildKey = /* @__PURE__ */ __name((child) => child.key || "", "getChildKey");
|
|
19
17
|
const isDev = process.env.NODE_ENV !== "production";
|
|
20
18
|
function updateChildLookup(children, allChildren) {
|
|
21
19
|
const seenChildren = isDev ? /* @__PURE__ */ new Set() : null;
|
|
22
|
-
|
|
20
|
+
children.forEach((child) => {
|
|
23
21
|
const key = getChildKey(child);
|
|
24
22
|
if (isDev && seenChildren && seenChildren.has(key)) {
|
|
25
23
|
console.warn(`Children of AnimatePresence require unique keys. "${key}" is a duplicate.`);
|
|
26
24
|
seenChildren.add(key);
|
|
27
25
|
}
|
|
28
26
|
allChildren.set(key, child);
|
|
29
|
-
}
|
|
27
|
+
});
|
|
30
28
|
}
|
|
31
29
|
__name(updateChildLookup, "updateChildLookup");
|
|
32
30
|
function onlyElements(children) {
|
|
@@ -40,7 +38,8 @@ function onlyElements(children) {
|
|
|
40
38
|
__name(onlyElements, "onlyElements");
|
|
41
39
|
const AnimatePresence = /* @__PURE__ */ __name(({
|
|
42
40
|
children,
|
|
43
|
-
|
|
41
|
+
enterVariant,
|
|
42
|
+
exitVariant,
|
|
44
43
|
initial = true,
|
|
45
44
|
onExitComplete,
|
|
46
45
|
exitBeforeEnter,
|
|
@@ -50,7 +49,10 @@ const AnimatePresence = /* @__PURE__ */ __name(({
|
|
|
50
49
|
const forceRenderLayoutGroup = useContext(LayoutGroupContext).forceRender;
|
|
51
50
|
if (forceRenderLayoutGroup)
|
|
52
51
|
forceRender = forceRenderLayoutGroup;
|
|
53
|
-
const isMounted =
|
|
52
|
+
const [isMounted, setIsMounted] = useState(false);
|
|
53
|
+
useLayoutEffect(() => {
|
|
54
|
+
setIsMounted(true);
|
|
55
|
+
}, []);
|
|
54
56
|
const filteredChildren = onlyElements(children);
|
|
55
57
|
let childrenToRender = filteredChildren;
|
|
56
58
|
const exiting = /* @__PURE__ */ new Set();
|
|
@@ -68,7 +70,7 @@ const AnimatePresence = /* @__PURE__ */ __name(({
|
|
|
68
70
|
exiting.clear();
|
|
69
71
|
});
|
|
70
72
|
if (isInitialRender.current) {
|
|
71
|
-
return <>{childrenToRender.map((child) => <PresenceChild key={getChildKey(child)}
|
|
73
|
+
return <>{childrenToRender.map((child) => <PresenceChild key={getChildKey(child)} isEntering exitVariant={exitVariant} enterVariant={enterVariant} initial={initial ? void 0 : false} presenceAffectsLayout={presenceAffectsLayout}>{child}</PresenceChild>)}</>;
|
|
72
74
|
}
|
|
73
75
|
childrenToRender = [...childrenToRender];
|
|
74
76
|
const presentKeys = presentChildren.current.map(getChildKey);
|
|
@@ -83,40 +85,34 @@ const AnimatePresence = /* @__PURE__ */ __name(({
|
|
|
83
85
|
if (exitBeforeEnter && exiting.size) {
|
|
84
86
|
childrenToRender = [];
|
|
85
87
|
}
|
|
86
|
-
|
|
87
|
-
if (targetKeys.indexOf(key) !== -1)
|
|
88
|
-
|
|
89
|
-
}
|
|
88
|
+
exiting.forEach((key) => {
|
|
89
|
+
if (targetKeys.indexOf(key) !== -1)
|
|
90
|
+
return;
|
|
90
91
|
const child = allChildren.get(key);
|
|
91
|
-
if (!child)
|
|
92
|
-
|
|
93
|
-
}
|
|
92
|
+
if (!child)
|
|
93
|
+
return;
|
|
94
94
|
const insertionIndex = presentKeys.indexOf(key);
|
|
95
|
-
|
|
95
|
+
childrenToRender.splice(insertionIndex, 0, <PresenceChild key={getChildKey(child)} isEntering={false} onExitComplete={() => {
|
|
96
96
|
allChildren.delete(key);
|
|
97
97
|
exiting.delete(key);
|
|
98
98
|
const removeIndex = presentChildren.current.findIndex((presentChild) => presentChild.key === key);
|
|
99
99
|
presentChildren.current.splice(removeIndex, 1);
|
|
100
100
|
if (!exiting.size) {
|
|
101
101
|
presentChildren.current = filteredChildren;
|
|
102
|
-
if (isMounted
|
|
102
|
+
if (isMounted === false)
|
|
103
103
|
return;
|
|
104
|
-
}
|
|
105
104
|
forceRender();
|
|
106
105
|
onExitComplete == null ? void 0 : onExitComplete();
|
|
107
106
|
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
}
|
|
107
|
+
}} exitVariant={exitVariant} enterVariant={enterVariant} presenceAffectsLayout={presenceAffectsLayout}>{child}</PresenceChild>);
|
|
108
|
+
});
|
|
111
109
|
childrenToRender = childrenToRender.map((child) => {
|
|
112
110
|
const key = child.key;
|
|
113
|
-
return exiting.has(key) ? child : <PresenceChild key={getChildKey(child)}
|
|
111
|
+
return exiting.has(key) ? child : <PresenceChild key={getChildKey(child)} isEntering={void 0} exitVariant={exitVariant} enterVariant={enterVariant} presenceAffectsLayout={presenceAffectsLayout}>{child}</PresenceChild>;
|
|
114
112
|
});
|
|
115
|
-
if (process.env.NODE_ENV !== "production" && exitBeforeEnter && childrenToRender.length > 1) {
|
|
116
|
-
console.warn(`You're attempting to animate multiple children within AnimatePresence, but its exitBeforeEnter prop is set to true. This will lead to odd visual behaviour.`);
|
|
117
|
-
}
|
|
118
113
|
return <>{exiting.size ? childrenToRender : childrenToRender.map((child) => cloneElement(child))}</>;
|
|
119
114
|
}, "AnimatePresence");
|
|
115
|
+
AnimatePresence.displayName = "AnimatePresence";
|
|
120
116
|
export {
|
|
121
117
|
AnimatePresence
|
|
122
118
|
};
|
|
@@ -7,41 +7,44 @@ import { AnimatePresenceContext } from "./AnimatePresenceContext";
|
|
|
7
7
|
const PresenceChild = /* @__PURE__ */ __name(({
|
|
8
8
|
children,
|
|
9
9
|
initial,
|
|
10
|
-
|
|
10
|
+
isEntering,
|
|
11
11
|
onExitComplete,
|
|
12
|
-
|
|
12
|
+
exitVariant,
|
|
13
|
+
enterVariant,
|
|
13
14
|
presenceAffectsLayout
|
|
14
15
|
}) => {
|
|
15
16
|
const presenceChildren = useConstant(newChildrenMap);
|
|
16
17
|
const id = useId();
|
|
17
|
-
const context = React.useMemo(() =>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
const context = React.useMemo(() => {
|
|
19
|
+
return {
|
|
20
|
+
id,
|
|
21
|
+
initial,
|
|
22
|
+
isEntering,
|
|
23
|
+
exitVariant,
|
|
24
|
+
enterVariant,
|
|
25
|
+
onExitComplete: (childId) => {
|
|
26
|
+
presenceChildren.set(childId, true);
|
|
27
|
+
for (const isComplete of presenceChildren.values()) {
|
|
28
|
+
if (!isComplete) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
27
31
|
}
|
|
32
|
+
onExitComplete == null ? void 0 : onExitComplete();
|
|
33
|
+
},
|
|
34
|
+
register: (childId) => {
|
|
35
|
+
presenceChildren.set(childId, false);
|
|
36
|
+
return () => presenceChildren.delete(childId);
|
|
28
37
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
register: (childId) => {
|
|
32
|
-
presenceChildren.set(childId, false);
|
|
33
|
-
return () => presenceChildren.delete(childId);
|
|
34
|
-
}
|
|
35
|
-
}), presenceAffectsLayout ? void 0 : [isPresent]);
|
|
38
|
+
};
|
|
39
|
+
}, presenceAffectsLayout ? void 0 : [isEntering, onExitComplete, exitVariant, enterVariant]);
|
|
36
40
|
React.useMemo(() => {
|
|
37
41
|
presenceChildren.forEach((_, key) => presenceChildren.set(key, false));
|
|
38
|
-
}, [
|
|
42
|
+
}, [isEntering]);
|
|
39
43
|
React.useEffect(() => {
|
|
40
|
-
if (
|
|
41
|
-
console.log("on exit complete");
|
|
44
|
+
if (isEntering === false && !presenceChildren.size) {
|
|
42
45
|
onExitComplete == null ? void 0 : onExitComplete();
|
|
43
46
|
}
|
|
44
|
-
}, [
|
|
47
|
+
}, [isEntering]);
|
|
45
48
|
return <AnimatePresenceContext.Provider value={context}>{children}</AnimatePresenceContext.Provider>;
|
|
46
49
|
}, "PresenceChild");
|
|
47
50
|
function newChildrenMap() {
|
package/dist/jsx/index.js
CHANGED
package/dist/jsx/useEntering.js
CHANGED
|
File without changes
|
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.203+bdbb1f11",
|
|
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.203+bdbb1f11"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@tamagui/build": "^1.0.0-beta.
|
|
18
|
+
"@tamagui/build": "^1.0.0-beta.203+bdbb1f11"
|
|
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": "bdbb1f11fae44e3a78133373ef108adccaa68924"
|
|
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,KAWN,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":"AAEA,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,
|
|
1
|
+
{"version":3,"file":"PresenceChild.d.ts","sourceRoot":"","sources":["../src/PresenceChild.tsx"],"names":[],"mappings":"AAEA,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"}
|
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"}
|