@tamagui/animate-presence 1.0.0-beta.172

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.
Files changed (52) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +1 -0
  3. package/dist/cjs/AnimatePresence.js +149 -0
  4. package/dist/cjs/AnimatePresence.js.map +7 -0
  5. package/dist/cjs/AnimatePresenceContext.js +25 -0
  6. package/dist/cjs/AnimatePresenceContext.js.map +7 -0
  7. package/dist/cjs/LayoutGroupContext.js +25 -0
  8. package/dist/cjs/LayoutGroupContext.js.map +7 -0
  9. package/dist/cjs/PresenceChild.js +77 -0
  10. package/dist/cjs/PresenceChild.js.map +7 -0
  11. package/dist/cjs/index.js +27 -0
  12. package/dist/cjs/index.js.map +7 -0
  13. package/dist/cjs/types.js +16 -0
  14. package/dist/cjs/types.js.map +7 -0
  15. package/dist/cjs/usePresence.js +51 -0
  16. package/dist/cjs/usePresence.js.map +7 -0
  17. package/dist/esm/AnimatePresence.js +139 -0
  18. package/dist/esm/AnimatePresence.js.map +7 -0
  19. package/dist/esm/AnimatePresenceContext.js +6 -0
  20. package/dist/esm/AnimatePresenceContext.js.map +7 -0
  21. package/dist/esm/LayoutGroupContext.js +6 -0
  22. package/dist/esm/LayoutGroupContext.js.map +7 -0
  23. package/dist/esm/PresenceChild.js +56 -0
  24. package/dist/esm/PresenceChild.js.map +7 -0
  25. package/dist/esm/index.js +7 -0
  26. package/dist/esm/index.js.map +7 -0
  27. package/dist/esm/types.js +1 -0
  28. package/dist/esm/types.js.map +7 -0
  29. package/dist/esm/usePresence.js +33 -0
  30. package/dist/esm/usePresence.js.map +7 -0
  31. package/dist/jsx/AnimatePresence.js +122 -0
  32. package/dist/jsx/AnimatePresenceContext.js +5 -0
  33. package/dist/jsx/LayoutGroupContext.js +5 -0
  34. package/dist/jsx/PresenceChild.js +53 -0
  35. package/dist/jsx/index.js +6 -0
  36. package/dist/jsx/types.js +0 -0
  37. package/dist/jsx/usePresence.js +32 -0
  38. package/package.json +30 -0
  39. package/types/AnimatePresence.d.ts +10 -0
  40. package/types/AnimatePresence.d.ts.map +1 -0
  41. package/types/AnimatePresenceContext.d.ts +12 -0
  42. package/types/AnimatePresenceContext.d.ts.map +1 -0
  43. package/types/LayoutGroupContext.d.ts +7 -0
  44. package/types/LayoutGroupContext.d.ts.map +1 -0
  45. package/types/PresenceChild.d.ts +13 -0
  46. package/types/PresenceChild.d.ts.map +1 -0
  47. package/types/index.d.ts +4 -0
  48. package/types/index.d.ts.map +1 -0
  49. package/types/types.d.ts +10 -0
  50. package/types/types.d.ts.map +1 -0
  51. package/types/usePresence.d.ts +10 -0
  52. package/types/usePresence.d.ts.map +1 -0
package/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Framer B.V.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ Much of this is taken from framer-motion.
@@ -0,0 +1,149 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var AnimatePresence_exports = {};
23
+ __export(AnimatePresence_exports, {
24
+ AnimatePresence: () => AnimatePresence
25
+ });
26
+ module.exports = __toCommonJS(AnimatePresence_exports);
27
+ var import_core = require("@tamagui/core");
28
+ var React = __toESM(require("react"));
29
+ var import_react = require("react");
30
+ var import_LayoutGroupContext = require("./LayoutGroupContext");
31
+ var import_PresenceChild = require("./PresenceChild");
32
+ const getChildKey = /* @__PURE__ */ __name((child) => child.key || "", "getChildKey");
33
+ const isDev = process.env.NODE_ENV !== "production";
34
+ function updateChildLookup(children, allChildren) {
35
+ const seenChildren = isDev ? /* @__PURE__ */ new Set() : null;
36
+ for (const child of children) {
37
+ const key = getChildKey(child);
38
+ if (isDev && seenChildren && seenChildren.has(key)) {
39
+ console.warn(`Children of AnimatePresence require unique keys. "${key}" is a duplicate.`);
40
+ seenChildren.add(key);
41
+ }
42
+ allChildren.set(key, child);
43
+ }
44
+ }
45
+ __name(updateChildLookup, "updateChildLookup");
46
+ function onlyElements(children) {
47
+ const filtered = [];
48
+ import_react.Children.forEach(children, (child) => {
49
+ if ((0, import_react.isValidElement)(child))
50
+ filtered.push(child);
51
+ });
52
+ return filtered;
53
+ }
54
+ __name(onlyElements, "onlyElements");
55
+ const AnimatePresence = /* @__PURE__ */ __name(({
56
+ children,
57
+ custom,
58
+ initial = true,
59
+ onExitComplete,
60
+ exitBeforeEnter,
61
+ presenceAffectsLayout = true
62
+ }) => {
63
+ let forceRender = (0, import_core.useForceUpdate)();
64
+ const forceRenderLayoutGroup = (0, import_react.useContext)(import_LayoutGroupContext.LayoutGroupContext).forceRender;
65
+ if (forceRenderLayoutGroup)
66
+ forceRender = forceRenderLayoutGroup;
67
+ const isMounted = (0, import_core.useIsMounted)();
68
+ const filteredChildren = onlyElements(children);
69
+ let childrenToRender = filteredChildren;
70
+ const exiting = /* @__PURE__ */ new Set();
71
+ const presentChildren = (0, import_react.useRef)(childrenToRender);
72
+ const allChildren = (0, import_react.useRef)(/* @__PURE__ */ new Map()).current;
73
+ const isInitialRender = (0, import_react.useRef)(true);
74
+ (0, import_core.useIsomorphicLayoutEffect)(() => {
75
+ isInitialRender.current = false;
76
+ updateChildLookup(filteredChildren, allChildren);
77
+ presentChildren.current = childrenToRender;
78
+ });
79
+ (0, import_core.useUnmountEffect)(() => {
80
+ isInitialRender.current = true;
81
+ allChildren.clear();
82
+ exiting.clear();
83
+ });
84
+ if (isInitialRender.current) {
85
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, childrenToRender.map((child) => /* @__PURE__ */ React.createElement(import_PresenceChild.PresenceChild, {
86
+ key: getChildKey(child),
87
+ isPresent: true,
88
+ initial: initial ? void 0 : false,
89
+ presenceAffectsLayout
90
+ }, child)));
91
+ }
92
+ childrenToRender = [...childrenToRender];
93
+ const presentKeys = presentChildren.current.map(getChildKey);
94
+ const targetKeys = filteredChildren.map(getChildKey);
95
+ const numPresent = presentKeys.length;
96
+ for (let i = 0; i < numPresent; i++) {
97
+ const key = presentKeys[i];
98
+ if (targetKeys.indexOf(key) === -1) {
99
+ exiting.add(key);
100
+ }
101
+ }
102
+ if (exitBeforeEnter && exiting.size) {
103
+ childrenToRender = [];
104
+ }
105
+ for (const key of exiting) {
106
+ if (targetKeys.indexOf(key) !== -1) {
107
+ continue;
108
+ }
109
+ const child = allChildren.get(key);
110
+ if (!child) {
111
+ continue;
112
+ }
113
+ const insertionIndex = presentKeys.indexOf(key);
114
+ const onExit = /* @__PURE__ */ __name(() => {
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, {
129
+ key: getChildKey(child),
130
+ isPresent: false,
131
+ onExitComplete: onExit,
132
+ custom,
133
+ presenceAffectsLayout
134
+ }, child));
135
+ }
136
+ childrenToRender = childrenToRender.map((child) => {
137
+ const key = child.key;
138
+ return exiting.has(key) ? child : /* @__PURE__ */ React.createElement(import_PresenceChild.PresenceChild, {
139
+ key: getChildKey(child),
140
+ isPresent: true,
141
+ presenceAffectsLayout
142
+ }, child);
143
+ });
144
+ if (process.env.NODE_ENV !== "production" && exitBeforeEnter && childrenToRender.length > 1) {
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)));
148
+ }, "AnimatePresence");
149
+ //# sourceMappingURL=AnimatePresence.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/AnimatePresence.tsx"],
4
+ "sourcesContent": ["import {\n useForceUpdate,\n useIsMounted,\n useIsomorphicLayoutEffect,\n useUnmountEffect,\n} from '@tamagui/core'\nimport * as React from 'react'\nimport {\n Children,\n ReactElement,\n ReactNode,\n cloneElement,\n isValidElement,\n useContext,\n useRef,\n} from 'react'\n\nimport { LayoutGroupContext } from './LayoutGroupContext'\nimport { PresenceChild } from './PresenceChild'\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 custom?: any\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 || ''\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 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\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 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 * `usePresence` all need to call `safeToRemove`.\n *\n * @public\n */\nexport const AnimatePresence: React.FunctionComponent<AnimatePresenceProps> = ({\n children,\n custom,\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 = useIsMounted()\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 isPresent\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 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.current === 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 isPresent={false}\n onExitComplete={onExit}\n custom={custom}\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 isPresent\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"],
5
+ "mappings": "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",
6
+ "names": []
7
+ }
@@ -0,0 +1,25 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var AnimatePresenceContext_exports = {};
19
+ __export(AnimatePresenceContext_exports, {
20
+ AnimatePresenceContext: () => AnimatePresenceContext
21
+ });
22
+ module.exports = __toCommonJS(AnimatePresenceContext_exports);
23
+ var import_react = require("react");
24
+ const AnimatePresenceContext = (0, import_react.createContext)(null);
25
+ //# sourceMappingURL=AnimatePresenceContext.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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 isPresent: boolean\n register: (id: string) => () => void\n onExitComplete?: (id: string) => void\n initial?: false | VariantLabels\n custom?: any\n}\n\nexport const AnimatePresenceContext = createContext<AnimatePresenceContextProps | null>(null)\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA8B;AAavB,MAAM,yBAAyB,gCAAkD,IAAI;",
6
+ "names": []
7
+ }
@@ -0,0 +1,25 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var LayoutGroupContext_exports = {};
19
+ __export(LayoutGroupContext_exports, {
20
+ LayoutGroupContext: () => LayoutGroupContext
21
+ });
22
+ module.exports = __toCommonJS(LayoutGroupContext_exports);
23
+ var import_react = require("react");
24
+ const LayoutGroupContext = (0, import_react.createContext)({});
25
+ //# sourceMappingURL=LayoutGroupContext.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/LayoutGroupContext.tsx"],
4
+ "sourcesContent": ["import { createContext } from 'react'\n\nexport interface LayoutGroupContextProps {\n id?: string\n forceRender?: VoidFunction\n}\n\nexport const LayoutGroupContext = createContext<LayoutGroupContextProps>({})\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA8B;AAOvB,MAAM,qBAAqB,gCAAuC,CAAC,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,77 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var PresenceChild_exports = {};
23
+ __export(PresenceChild_exports, {
24
+ PresenceChild: () => PresenceChild
25
+ });
26
+ module.exports = __toCommonJS(PresenceChild_exports);
27
+ var import_utils = require("@react-aria/utils");
28
+ var import_core = require("@tamagui/core");
29
+ var React = __toESM(require("react"));
30
+ var import_AnimatePresenceContext = require("./AnimatePresenceContext");
31
+ const PresenceChild = /* @__PURE__ */ __name(({
32
+ children,
33
+ initial,
34
+ isPresent,
35
+ onExitComplete,
36
+ custom,
37
+ presenceAffectsLayout
38
+ }) => {
39
+ const presenceChildren = (0, import_core.useConstant)(newChildrenMap);
40
+ const id = (0, import_utils.useId)();
41
+ const context = React.useMemo(() => ({
42
+ id,
43
+ initial,
44
+ isPresent,
45
+ custom,
46
+ onExitComplete: (childId) => {
47
+ presenceChildren.set(childId, true);
48
+ for (const isComplete of presenceChildren.values()) {
49
+ if (!isComplete) {
50
+ return;
51
+ }
52
+ }
53
+ onExitComplete == null ? void 0 : onExitComplete();
54
+ },
55
+ register: (childId) => {
56
+ presenceChildren.set(childId, false);
57
+ return () => presenceChildren.delete(childId);
58
+ }
59
+ }), presenceAffectsLayout ? void 0 : [isPresent]);
60
+ React.useMemo(() => {
61
+ presenceChildren.forEach((_, key) => presenceChildren.set(key, false));
62
+ }, [isPresent]);
63
+ React.useEffect(() => {
64
+ if (!isPresent && !presenceChildren.size) {
65
+ console.log("on exit complete");
66
+ onExitComplete == null ? void 0 : onExitComplete();
67
+ }
68
+ }, [isPresent]);
69
+ return /* @__PURE__ */ React.createElement(import_AnimatePresenceContext.AnimatePresenceContext.Provider, {
70
+ value: context
71
+ }, children);
72
+ }, "PresenceChild");
73
+ function newChildrenMap() {
74
+ return /* @__PURE__ */ new Map();
75
+ }
76
+ __name(newChildrenMap, "newChildrenMap");
77
+ //# sourceMappingURL=PresenceChild.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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 isPresent: boolean\n onExitComplete?: () => void\n initial?: false | VariantLabels\n custom?: any\n presenceAffectsLayout: boolean\n}\n\nexport const PresenceChild = ({\n children,\n initial,\n isPresent,\n onExitComplete,\n custom,\n presenceAffectsLayout,\n}: PresenceChildProps) => {\n const presenceChildren = useConstant(newChildrenMap)\n const id = useId()\n\n const context = React.useMemo(\n (): AnimatePresenceContextProps => ({\n id,\n initial,\n isPresent,\n custom,\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 * 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 : [isPresent]\n )\n\n // cant this be a useEffect?\n React.useMemo(() => {\n presenceChildren.forEach((_, key) => presenceChildren.set(key, false))\n }, [isPresent])\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 (!isPresent && !presenceChildren.size) {\n console.log('on exit complete')\n onExitComplete?.()\n }\n }, [isPresent])\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;AAY7D,MAAM,gBAAgB,wBAAC;AAAA,EAC5B;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,MAAoC;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB,CAAC,YAAoB;AACnC,uBAAiB,IAAI,SAAS,IAAI;AAClC,iBAAW,cAAc,iBAAiB,OAAO,GAAG;AAClD,YAAI,CAAC,YAAY;AACf;AAAA,QACF;AAAA,MACF;AACA;AAAA,IACF;AAAA,IACA,UAAU,CAAC,YAAoB;AAC7B,uBAAiB,IAAI,SAAS,KAAK;AACnC,aAAO,MAAM,iBAAiB,OAAO,OAAO;AAAA,IAC9C;AAAA,EACF,IAMA,wBAAwB,SAAY,CAAC,SAAS,CAChD;AAGA,QAAM,QAAQ,MAAM;AAClB,qBAAiB,QAAQ,CAAC,GAAG,QAAQ,iBAAiB,IAAI,KAAK,KAAK,CAAC;AAAA,EACvE,GAAG,CAAC,SAAS,CAAC;AAMd,QAAM,UAAU,MAAM;AACpB,QAAI,CAAC,aAAa,CAAC,iBAAiB,MAAM;AACxC,cAAQ,IAAI,kBAAkB;AAC9B;AAAA,IACF;AAAA,EACF,GAAG,CAAC,SAAS,CAAC;AAEd,SACE,oCAAC,qDAAuB,UAAvB;AAAA,IAAgC,OAAO;AAAA,KAAU,QAAS;AAE/D,GA1D6B;AA4D7B,0BAAgD;AAC9C,SAAO,oBAAI,IAAI;AACjB;AAFS;",
6
+ "names": []
7
+ }
@@ -0,0 +1,27 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var src_exports = {};
20
+ __export(src_exports, {
21
+ AnimatePresenceContext: () => import_AnimatePresenceContext.AnimatePresenceContext
22
+ });
23
+ module.exports = __toCommonJS(src_exports);
24
+ __reExport(src_exports, require("./AnimatePresence"), module.exports);
25
+ __reExport(src_exports, require("./usePresence"), module.exports);
26
+ var import_AnimatePresenceContext = require("./AnimatePresenceContext");
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["export * from './AnimatePresence'\nexport * from './usePresence'\nexport { AnimatePresenceContext } from './AnimatePresenceContext'\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAc,8BAAd;AACA,wBAAc,0BADd;AAEA,oCAAuC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,16 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var types_exports = {};
15
+ module.exports = __toCommonJS(types_exports);
16
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/types.ts"],
4
+ "sourcesContent": ["export interface Axis {\n min: number\n max: number\n}\n\nexport interface Box {\n x: Axis\n y: Axis\n}\n\nexport type VariantLabels = string | string[]\n"],
5
+ "mappings": ";;;;;;;;;;;;;AAAA;AAAA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,51 @@
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
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,139 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import {
4
+ useForceUpdate,
5
+ useIsMounted,
6
+ useIsomorphicLayoutEffect,
7
+ useUnmountEffect
8
+ } from "@tamagui/core";
9
+ import * as React from "react";
10
+ import {
11
+ Children,
12
+ cloneElement,
13
+ isValidElement,
14
+ useContext,
15
+ useRef
16
+ } from "react";
17
+ import { LayoutGroupContext } from "./LayoutGroupContext";
18
+ import { PresenceChild } from "./PresenceChild";
19
+ const getChildKey = /* @__PURE__ */ __name((child) => child.key || "", "getChildKey");
20
+ const isDev = process.env.NODE_ENV !== "production";
21
+ function updateChildLookup(children, allChildren) {
22
+ const seenChildren = isDev ? /* @__PURE__ */ new Set() : null;
23
+ for (const child of children) {
24
+ const key = getChildKey(child);
25
+ if (isDev && seenChildren && seenChildren.has(key)) {
26
+ console.warn(`Children of AnimatePresence require unique keys. "${key}" is a duplicate.`);
27
+ seenChildren.add(key);
28
+ }
29
+ allChildren.set(key, child);
30
+ }
31
+ }
32
+ __name(updateChildLookup, "updateChildLookup");
33
+ function onlyElements(children) {
34
+ const filtered = [];
35
+ Children.forEach(children, (child) => {
36
+ if (isValidElement(child))
37
+ filtered.push(child);
38
+ });
39
+ return filtered;
40
+ }
41
+ __name(onlyElements, "onlyElements");
42
+ const AnimatePresence = /* @__PURE__ */ __name(({
43
+ children,
44
+ custom,
45
+ initial = true,
46
+ onExitComplete,
47
+ exitBeforeEnter,
48
+ presenceAffectsLayout = true
49
+ }) => {
50
+ let forceRender = useForceUpdate();
51
+ const forceRenderLayoutGroup = useContext(LayoutGroupContext).forceRender;
52
+ if (forceRenderLayoutGroup)
53
+ forceRender = forceRenderLayoutGroup;
54
+ const isMounted = useIsMounted();
55
+ const filteredChildren = onlyElements(children);
56
+ let childrenToRender = filteredChildren;
57
+ const exiting = /* @__PURE__ */ new Set();
58
+ const presentChildren = useRef(childrenToRender);
59
+ const allChildren = useRef(/* @__PURE__ */ new Map()).current;
60
+ const isInitialRender = useRef(true);
61
+ useIsomorphicLayoutEffect(() => {
62
+ isInitialRender.current = false;
63
+ updateChildLookup(filteredChildren, allChildren);
64
+ presentChildren.current = childrenToRender;
65
+ });
66
+ useUnmountEffect(() => {
67
+ isInitialRender.current = true;
68
+ allChildren.clear();
69
+ exiting.clear();
70
+ });
71
+ if (isInitialRender.current) {
72
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, childrenToRender.map((child) => /* @__PURE__ */ React.createElement(PresenceChild, {
73
+ key: getChildKey(child),
74
+ isPresent: true,
75
+ initial: initial ? void 0 : false,
76
+ presenceAffectsLayout
77
+ }, child)));
78
+ }
79
+ childrenToRender = [...childrenToRender];
80
+ const presentKeys = presentChildren.current.map(getChildKey);
81
+ const targetKeys = filteredChildren.map(getChildKey);
82
+ const numPresent = presentKeys.length;
83
+ for (let i = 0; i < numPresent; i++) {
84
+ const key = presentKeys[i];
85
+ if (targetKeys.indexOf(key) === -1) {
86
+ exiting.add(key);
87
+ }
88
+ }
89
+ if (exitBeforeEnter && exiting.size) {
90
+ childrenToRender = [];
91
+ }
92
+ for (const key of exiting) {
93
+ if (targetKeys.indexOf(key) !== -1) {
94
+ continue;
95
+ }
96
+ const child = allChildren.get(key);
97
+ if (!child) {
98
+ continue;
99
+ }
100
+ 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
+ childrenToRender.splice(insertionIndex, 0, /* @__PURE__ */ React.createElement(PresenceChild, {
116
+ key: getChildKey(child),
117
+ isPresent: false,
118
+ onExitComplete: onExit,
119
+ custom,
120
+ presenceAffectsLayout
121
+ }, child));
122
+ }
123
+ childrenToRender = childrenToRender.map((child) => {
124
+ const key = child.key;
125
+ return exiting.has(key) ? child : /* @__PURE__ */ React.createElement(PresenceChild, {
126
+ key: getChildKey(child),
127
+ isPresent: true,
128
+ presenceAffectsLayout
129
+ }, child);
130
+ });
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
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, exiting.size ? childrenToRender : childrenToRender.map((child) => cloneElement(child)));
135
+ }, "AnimatePresence");
136
+ export {
137
+ AnimatePresence
138
+ };
139
+ //# sourceMappingURL=AnimatePresence.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/AnimatePresence.tsx"],
4
+ "sourcesContent": ["import {\n useForceUpdate,\n useIsMounted,\n useIsomorphicLayoutEffect,\n useUnmountEffect,\n} from '@tamagui/core'\nimport * as React from 'react'\nimport {\n Children,\n ReactElement,\n ReactNode,\n cloneElement,\n isValidElement,\n useContext,\n useRef,\n} from 'react'\n\nimport { LayoutGroupContext } from './LayoutGroupContext'\nimport { PresenceChild } from './PresenceChild'\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 custom?: any\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 || ''\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 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\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 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 * `usePresence` all need to call `safeToRemove`.\n *\n * @public\n */\nexport const AnimatePresence: React.FunctionComponent<AnimatePresenceProps> = ({\n children,\n custom,\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 = useIsMounted()\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 isPresent\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 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.current === 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 isPresent={false}\n onExitComplete={onExit}\n custom={custom}\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 isPresent\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"],
5
+ "mappings": "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",
6
+ "names": []
7
+ }
@@ -0,0 +1,6 @@
1
+ import { createContext } from "react";
2
+ const AnimatePresenceContext = createContext(null);
3
+ export {
4
+ AnimatePresenceContext
5
+ };
6
+ //# sourceMappingURL=AnimatePresenceContext.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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 isPresent: boolean\n register: (id: string) => () => void\n onExitComplete?: (id: string) => void\n initial?: false | VariantLabels\n custom?: any\n}\n\nexport const AnimatePresenceContext = createContext<AnimatePresenceContextProps | null>(null)\n"],
5
+ "mappings": "AAAA;AAaO,MAAM,yBAAyB,cAAkD,IAAI;",
6
+ "names": []
7
+ }
@@ -0,0 +1,6 @@
1
+ import { createContext } from "react";
2
+ const LayoutGroupContext = createContext({});
3
+ export {
4
+ LayoutGroupContext
5
+ };
6
+ //# sourceMappingURL=LayoutGroupContext.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/LayoutGroupContext.tsx"],
4
+ "sourcesContent": ["import { createContext } from 'react'\n\nexport interface LayoutGroupContextProps {\n id?: string\n forceRender?: VoidFunction\n}\n\nexport const LayoutGroupContext = createContext<LayoutGroupContextProps>({})\n"],
5
+ "mappings": "AAAA;AAOO,MAAM,qBAAqB,cAAuC,CAAC,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,56 @@
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 { useConstant } from "@tamagui/core";
5
+ import * as React from "react";
6
+ import { AnimatePresenceContext } from "./AnimatePresenceContext";
7
+ const PresenceChild = /* @__PURE__ */ __name(({
8
+ children,
9
+ initial,
10
+ isPresent,
11
+ onExitComplete,
12
+ custom,
13
+ presenceAffectsLayout
14
+ }) => {
15
+ const presenceChildren = useConstant(newChildrenMap);
16
+ const id = useId();
17
+ const context = React.useMemo(() => ({
18
+ id,
19
+ initial,
20
+ isPresent,
21
+ custom,
22
+ onExitComplete: (childId) => {
23
+ presenceChildren.set(childId, true);
24
+ for (const isComplete of presenceChildren.values()) {
25
+ if (!isComplete) {
26
+ return;
27
+ }
28
+ }
29
+ onExitComplete == null ? void 0 : onExitComplete();
30
+ },
31
+ register: (childId) => {
32
+ presenceChildren.set(childId, false);
33
+ return () => presenceChildren.delete(childId);
34
+ }
35
+ }), presenceAffectsLayout ? void 0 : [isPresent]);
36
+ React.useMemo(() => {
37
+ presenceChildren.forEach((_, key) => presenceChildren.set(key, false));
38
+ }, [isPresent]);
39
+ React.useEffect(() => {
40
+ if (!isPresent && !presenceChildren.size) {
41
+ console.log("on exit complete");
42
+ onExitComplete == null ? void 0 : onExitComplete();
43
+ }
44
+ }, [isPresent]);
45
+ return /* @__PURE__ */ React.createElement(AnimatePresenceContext.Provider, {
46
+ value: context
47
+ }, children);
48
+ }, "PresenceChild");
49
+ function newChildrenMap() {
50
+ return /* @__PURE__ */ new Map();
51
+ }
52
+ __name(newChildrenMap, "newChildrenMap");
53
+ export {
54
+ PresenceChild
55
+ };
56
+ //# sourceMappingURL=PresenceChild.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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 isPresent: boolean\n onExitComplete?: () => void\n initial?: false | VariantLabels\n custom?: any\n presenceAffectsLayout: boolean\n}\n\nexport const PresenceChild = ({\n children,\n initial,\n isPresent,\n onExitComplete,\n custom,\n presenceAffectsLayout,\n}: PresenceChildProps) => {\n const presenceChildren = useConstant(newChildrenMap)\n const id = useId()\n\n const context = React.useMemo(\n (): AnimatePresenceContextProps => ({\n id,\n initial,\n isPresent,\n custom,\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 * 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 : [isPresent]\n )\n\n // cant this be a useEffect?\n React.useMemo(() => {\n presenceChildren.forEach((_, key) => presenceChildren.set(key, false))\n }, [isPresent])\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 (!isPresent && !presenceChildren.size) {\n console.log('on exit complete')\n onExitComplete?.()\n }\n }, [isPresent])\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;AAYO,MAAM,gBAAgB,wBAAC;AAAA,EAC5B;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,MAAoC;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB,CAAC,YAAoB;AACnC,uBAAiB,IAAI,SAAS,IAAI;AAClC,iBAAW,cAAc,iBAAiB,OAAO,GAAG;AAClD,YAAI,CAAC,YAAY;AACf;AAAA,QACF;AAAA,MACF;AACA;AAAA,IACF;AAAA,IACA,UAAU,CAAC,YAAoB;AAC7B,uBAAiB,IAAI,SAAS,KAAK;AACnC,aAAO,MAAM,iBAAiB,OAAO,OAAO;AAAA,IAC9C;AAAA,EACF,IAMA,wBAAwB,SAAY,CAAC,SAAS,CAChD;AAGA,QAAM,QAAQ,MAAM;AAClB,qBAAiB,QAAQ,CAAC,GAAG,QAAQ,iBAAiB,IAAI,KAAK,KAAK,CAAC;AAAA,EACvE,GAAG,CAAC,SAAS,CAAC;AAMd,QAAM,UAAU,MAAM;AACpB,QAAI,CAAC,aAAa,CAAC,iBAAiB,MAAM;AACxC,cAAQ,IAAI,kBAAkB;AAC9B;AAAA,IACF;AAAA,EACF,GAAG,CAAC,SAAS,CAAC;AAEd,SACE,oCAAC,uBAAuB,UAAvB;AAAA,IAAgC,OAAO;AAAA,KAAU,QAAS;AAE/D,GA1D6B;AA4D7B,0BAAgD;AAC9C,SAAO,oBAAI,IAAI;AACjB;AAFS;",
6
+ "names": []
7
+ }
@@ -0,0 +1,7 @@
1
+ export * from "./AnimatePresence";
2
+ export * from "./usePresence";
3
+ import { AnimatePresenceContext } from "./AnimatePresenceContext";
4
+ export {
5
+ AnimatePresenceContext
6
+ };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["export * from './AnimatePresence'\nexport * from './usePresence'\nexport { AnimatePresenceContext } from './AnimatePresenceContext'\n"],
5
+ "mappings": "AAAA;AACA;AACA;",
6
+ "names": []
7
+ }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,33 @@
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
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,122 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import {
4
+ useForceUpdate,
5
+ useIsMounted,
6
+ useIsomorphicLayoutEffect,
7
+ useUnmountEffect
8
+ } from "@tamagui/core";
9
+ import {
10
+ Children,
11
+ cloneElement,
12
+ isValidElement,
13
+ useContext,
14
+ useRef
15
+ } from "react";
16
+ import { LayoutGroupContext } from "./LayoutGroupContext";
17
+ import { PresenceChild } from "./PresenceChild";
18
+ const getChildKey = /* @__PURE__ */ __name((child) => child.key || "", "getChildKey");
19
+ const isDev = process.env.NODE_ENV !== "production";
20
+ function updateChildLookup(children, allChildren) {
21
+ const seenChildren = isDev ? /* @__PURE__ */ new Set() : null;
22
+ for (const child of children) {
23
+ const key = getChildKey(child);
24
+ if (isDev && seenChildren && seenChildren.has(key)) {
25
+ console.warn(`Children of AnimatePresence require unique keys. "${key}" is a duplicate.`);
26
+ seenChildren.add(key);
27
+ }
28
+ allChildren.set(key, child);
29
+ }
30
+ }
31
+ __name(updateChildLookup, "updateChildLookup");
32
+ function onlyElements(children) {
33
+ const filtered = [];
34
+ Children.forEach(children, (child) => {
35
+ if (isValidElement(child))
36
+ filtered.push(child);
37
+ });
38
+ return filtered;
39
+ }
40
+ __name(onlyElements, "onlyElements");
41
+ const AnimatePresence = /* @__PURE__ */ __name(({
42
+ children,
43
+ custom,
44
+ initial = true,
45
+ onExitComplete,
46
+ exitBeforeEnter,
47
+ presenceAffectsLayout = true
48
+ }) => {
49
+ let forceRender = useForceUpdate();
50
+ const forceRenderLayoutGroup = useContext(LayoutGroupContext).forceRender;
51
+ if (forceRenderLayoutGroup)
52
+ forceRender = forceRenderLayoutGroup;
53
+ const isMounted = useIsMounted();
54
+ const filteredChildren = onlyElements(children);
55
+ let childrenToRender = filteredChildren;
56
+ const exiting = /* @__PURE__ */ new Set();
57
+ const presentChildren = useRef(childrenToRender);
58
+ const allChildren = useRef(/* @__PURE__ */ new Map()).current;
59
+ const isInitialRender = useRef(true);
60
+ useIsomorphicLayoutEffect(() => {
61
+ isInitialRender.current = false;
62
+ updateChildLookup(filteredChildren, allChildren);
63
+ presentChildren.current = childrenToRender;
64
+ });
65
+ useUnmountEffect(() => {
66
+ isInitialRender.current = true;
67
+ allChildren.clear();
68
+ exiting.clear();
69
+ });
70
+ if (isInitialRender.current) {
71
+ return <>{childrenToRender.map((child) => <PresenceChild key={getChildKey(child)} isPresent initial={initial ? void 0 : false} presenceAffectsLayout={presenceAffectsLayout}>{child}</PresenceChild>)}</>;
72
+ }
73
+ childrenToRender = [...childrenToRender];
74
+ const presentKeys = presentChildren.current.map(getChildKey);
75
+ const targetKeys = filteredChildren.map(getChildKey);
76
+ const numPresent = presentKeys.length;
77
+ for (let i = 0; i < numPresent; i++) {
78
+ const key = presentKeys[i];
79
+ if (targetKeys.indexOf(key) === -1) {
80
+ exiting.add(key);
81
+ }
82
+ }
83
+ if (exitBeforeEnter && exiting.size) {
84
+ childrenToRender = [];
85
+ }
86
+ for (const key of exiting) {
87
+ if (targetKeys.indexOf(key) !== -1) {
88
+ continue;
89
+ }
90
+ const child = allChildren.get(key);
91
+ if (!child) {
92
+ continue;
93
+ }
94
+ const insertionIndex = presentKeys.indexOf(key);
95
+ const onExit = /* @__PURE__ */ __name(() => {
96
+ allChildren.delete(key);
97
+ exiting.delete(key);
98
+ const removeIndex = presentChildren.current.findIndex((presentChild) => presentChild.key === key);
99
+ presentChildren.current.splice(removeIndex, 1);
100
+ if (!exiting.size) {
101
+ presentChildren.current = filteredChildren;
102
+ if (isMounted.current === false) {
103
+ return;
104
+ }
105
+ forceRender();
106
+ onExitComplete == null ? void 0 : onExitComplete();
107
+ }
108
+ }, "onExit");
109
+ childrenToRender.splice(insertionIndex, 0, <PresenceChild key={getChildKey(child)} isPresent={false} onExitComplete={onExit} custom={custom} presenceAffectsLayout={presenceAffectsLayout}>{child}</PresenceChild>);
110
+ }
111
+ childrenToRender = childrenToRender.map((child) => {
112
+ const key = child.key;
113
+ return exiting.has(key) ? child : <PresenceChild key={getChildKey(child)} isPresent presenceAffectsLayout={presenceAffectsLayout}>{child}</PresenceChild>;
114
+ });
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
+ return <>{exiting.size ? childrenToRender : childrenToRender.map((child) => cloneElement(child))}</>;
119
+ }, "AnimatePresence");
120
+ export {
121
+ AnimatePresence
122
+ };
@@ -0,0 +1,5 @@
1
+ import { createContext } from "react";
2
+ const AnimatePresenceContext = createContext(null);
3
+ export {
4
+ AnimatePresenceContext
5
+ };
@@ -0,0 +1,5 @@
1
+ import { createContext } from "react";
2
+ const LayoutGroupContext = createContext({});
3
+ export {
4
+ LayoutGroupContext
5
+ };
@@ -0,0 +1,53 @@
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 { useConstant } from "@tamagui/core";
5
+ import * as React from "react";
6
+ import { AnimatePresenceContext } from "./AnimatePresenceContext";
7
+ const PresenceChild = /* @__PURE__ */ __name(({
8
+ children,
9
+ initial,
10
+ isPresent,
11
+ onExitComplete,
12
+ custom,
13
+ presenceAffectsLayout
14
+ }) => {
15
+ const presenceChildren = useConstant(newChildrenMap);
16
+ const id = useId();
17
+ const context = React.useMemo(() => ({
18
+ id,
19
+ initial,
20
+ isPresent,
21
+ custom,
22
+ onExitComplete: (childId) => {
23
+ presenceChildren.set(childId, true);
24
+ for (const isComplete of presenceChildren.values()) {
25
+ if (!isComplete) {
26
+ return;
27
+ }
28
+ }
29
+ onExitComplete == null ? void 0 : onExitComplete();
30
+ },
31
+ register: (childId) => {
32
+ presenceChildren.set(childId, false);
33
+ return () => presenceChildren.delete(childId);
34
+ }
35
+ }), presenceAffectsLayout ? void 0 : [isPresent]);
36
+ React.useMemo(() => {
37
+ presenceChildren.forEach((_, key) => presenceChildren.set(key, false));
38
+ }, [isPresent]);
39
+ React.useEffect(() => {
40
+ if (!isPresent && !presenceChildren.size) {
41
+ console.log("on exit complete");
42
+ onExitComplete == null ? void 0 : onExitComplete();
43
+ }
44
+ }, [isPresent]);
45
+ return <AnimatePresenceContext.Provider value={context}>{children}</AnimatePresenceContext.Provider>;
46
+ }, "PresenceChild");
47
+ function newChildrenMap() {
48
+ return /* @__PURE__ */ new Map();
49
+ }
50
+ __name(newChildrenMap, "newChildrenMap");
51
+ export {
52
+ PresenceChild
53
+ };
@@ -0,0 +1,6 @@
1
+ export * from "./AnimatePresence";
2
+ export * from "./usePresence";
3
+ import { AnimatePresenceContext } from "./AnimatePresenceContext";
4
+ export {
5
+ AnimatePresenceContext
6
+ };
File without changes
@@ -0,0 +1,32 @@
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/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@tamagui/animate-presence",
3
+ "version": "1.0.0-beta.172+0f3fd8dc",
4
+ "source": "src/index.ts",
5
+ "license": "MIT",
6
+ "typings": "types",
7
+ "main": "dist/cjs",
8
+ "module": "dist/esm",
9
+ "module:jsx": "dist/jsx",
10
+ "files": [
11
+ "types",
12
+ "dist"
13
+ ],
14
+ "dependencies": {
15
+ "@tamagui/core": "^1.0.0-beta.172+0f3fd8dc"
16
+ },
17
+ "devDependencies": {
18
+ "@tamagui/build": "^1.0.0-beta.172+0f3fd8dc"
19
+ },
20
+ "scripts": {
21
+ "build": "tamagui-build",
22
+ "watch": "tamagui-build --watch",
23
+ "clean": "tamagui-build clean",
24
+ "clean:build": "tamagui-build clean:build"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "gitHead": "0f3fd8dc83eede20419fb180704eb9ad1d63e814"
30
+ }
@@ -0,0 +1,10 @@
1
+ import * as React from 'react';
2
+ export interface AnimatePresenceProps {
3
+ initial?: boolean;
4
+ custom?: any;
5
+ onExitComplete?: () => void;
6
+ exitBeforeEnter?: boolean;
7
+ presenceAffectsLayout?: boolean;
8
+ }
9
+ export declare const AnimatePresence: React.FunctionComponent<AnimatePresenceProps>;
10
+ //# sourceMappingURL=AnimatePresence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnimatePresence.d.ts","sourceRoot":"","sources":["../src/AnimatePresence.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAc9B,MAAM,WAAW,oBAAoB;IAKnC,OAAO,CAAC,EAAE,OAAO,CAAA;IAOjB,MAAM,CAAC,EAAE,GAAG,CAAA;IAKZ,cAAc,CAAC,EAAE,MAAM,IAAI,CAAA;IAM3B,eAAe,CAAC,EAAE,OAAO,CAAA;IAMzB,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC;AAmED,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,iBAAiB,CAAC,oBAAoB,CAkKzE,CAAA"}
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { VariantLabels } from './types';
3
+ export interface AnimatePresenceContextProps {
4
+ id: string;
5
+ isPresent: boolean;
6
+ register: (id: string) => () => void;
7
+ onExitComplete?: (id: string) => void;
8
+ initial?: false | VariantLabels;
9
+ custom?: any;
10
+ }
11
+ export declare const AnimatePresenceContext: import("react").Context<AnimatePresenceContextProps | null>;
12
+ //# sourceMappingURL=AnimatePresenceContext.d.ts.map
@@ -0,0 +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,SAAS,EAAE,OAAO,CAAA;IAClB,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,MAAM,CAAC,EAAE,GAAG,CAAA;CACb;AAED,eAAO,MAAM,sBAAsB,6DAA0D,CAAA"}
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ export interface LayoutGroupContextProps {
3
+ id?: string;
4
+ forceRender?: VoidFunction;
5
+ }
6
+ export declare const LayoutGroupContext: import("react").Context<LayoutGroupContextProps>;
7
+ //# sourceMappingURL=LayoutGroupContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LayoutGroupContext.d.ts","sourceRoot":"","sources":["../src/LayoutGroupContext.tsx"],"names":[],"mappings":";AAEA,MAAM,WAAW,uBAAuB;IACtC,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,WAAW,CAAC,EAAE,YAAY,CAAA;CAC3B;AAED,eAAO,MAAM,kBAAkB,kDAA6C,CAAA"}
@@ -0,0 +1,13 @@
1
+ import * as React from 'react';
2
+ import { VariantLabels } from './types';
3
+ interface PresenceChildProps {
4
+ children: React.ReactElement<any>;
5
+ isPresent: boolean;
6
+ onExitComplete?: () => void;
7
+ initial?: false | VariantLabels;
8
+ custom?: any;
9
+ presenceAffectsLayout: boolean;
10
+ }
11
+ export declare const PresenceChild: ({ children, initial, isPresent, onExitComplete, custom, presenceAffectsLayout, }: PresenceChildProps) => JSX.Element;
12
+ export {};
13
+ //# sourceMappingURL=PresenceChild.d.ts.map
@@ -0,0 +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,SAAS,EAAE,OAAO,CAAA;IAClB,cAAc,CAAC,EAAE,MAAM,IAAI,CAAA;IAC3B,OAAO,CAAC,EAAE,KAAK,GAAG,aAAa,CAAA;IAC/B,MAAM,CAAC,EAAE,GAAG,CAAA;IACZ,qBAAqB,EAAE,OAAO,CAAA;CAC/B;AAED,eAAO,MAAM,aAAa,qFAOvB,kBAAkB,gBAmDpB,CAAA"}
@@ -0,0 +1,4 @@
1
+ export * from './AnimatePresence';
2
+ export * from './usePresence';
3
+ export { AnimatePresenceContext } from './AnimatePresenceContext';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA"}
@@ -0,0 +1,10 @@
1
+ export interface Axis {
2
+ min: number;
3
+ max: number;
4
+ }
5
+ export interface Box {
6
+ x: Axis;
7
+ y: Axis;
8
+ }
9
+ export declare type VariantLabels = string | string[];
10
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,IAAI;IACnB,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,MAAM,WAAW,GAAG;IAClB,CAAC,EAAE,IAAI,CAAA;IACP,CAAC,EAAE,IAAI,CAAA;CACR;AAED,oBAAY,aAAa,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { AnimatePresenceContextProps } from './AnimatePresenceContext';
2
+ export declare type SafeToRemove = () => void;
3
+ declare type AlwaysPresent = [true, null];
4
+ declare type Present = [true];
5
+ declare type NotPresent = [false, SafeToRemove];
6
+ export declare function usePresence(): AlwaysPresent | Present | NotPresent;
7
+ export declare function useIsPresent(): boolean;
8
+ export declare function isPresent(context: AnimatePresenceContextProps | null): boolean;
9
+ export {};
10
+ //# sourceMappingURL=usePresence.d.ts.map
@@ -0,0 +1 @@
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"}