@tamagui/animate-presence 2.0.0-rc.9 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/cjs/AnimatePresence.cjs +112 -91
  2. package/dist/cjs/AnimatePresence.native.js +127 -106
  3. package/dist/cjs/AnimatePresence.native.js.map +1 -1
  4. package/dist/cjs/LayoutGroupContext.cjs +24 -22
  5. package/dist/cjs/LayoutGroupContext.native.js +26 -24
  6. package/dist/cjs/LayoutGroupContext.native.js.map +1 -1
  7. package/dist/cjs/PresenceChild.cjs +58 -45
  8. package/dist/cjs/PresenceChild.native.js +103 -91
  9. package/dist/cjs/PresenceChild.native.js.map +1 -1
  10. package/dist/cjs/index.cjs +7 -5
  11. package/dist/cjs/index.native.js +7 -5
  12. package/dist/cjs/index.native.js.map +1 -1
  13. package/dist/cjs/types.cjs +7 -5
  14. package/dist/cjs/types.native.js +7 -5
  15. package/dist/cjs/types.native.js.map +1 -1
  16. package/dist/esm/AnimatePresence.mjs +96 -77
  17. package/dist/esm/AnimatePresence.mjs.map +1 -1
  18. package/dist/esm/AnimatePresence.native.js +111 -92
  19. package/dist/esm/AnimatePresence.native.js.map +1 -1
  20. package/dist/esm/PresenceChild.mjs +29 -18
  21. package/dist/esm/PresenceChild.mjs.map +1 -1
  22. package/dist/esm/PresenceChild.native.js +60 -50
  23. package/dist/esm/PresenceChild.native.js.map +1 -1
  24. package/dist/esm/index.js +3 -3
  25. package/dist/esm/index.js.map +1 -6
  26. package/package.json +10 -9
  27. package/src/AnimatePresence.tsx +150 -143
  28. package/src/types.ts +10 -9
  29. package/types/AnimatePresence.d.ts.map +1 -1
  30. package/types/types.d.ts +9 -9
  31. package/types/types.d.ts.map +1 -1
  32. package/dist/cjs/AnimatePresence.js +0 -121
  33. package/dist/cjs/AnimatePresence.js.map +0 -6
  34. package/dist/cjs/LayoutGroupContext.js +0 -30
  35. package/dist/cjs/LayoutGroupContext.js.map +0 -6
  36. package/dist/cjs/PresenceChild.js +0 -77
  37. package/dist/cjs/PresenceChild.js.map +0 -6
  38. package/dist/cjs/index.js +0 -18
  39. package/dist/cjs/index.js.map +0 -6
  40. package/dist/cjs/types.js +0 -14
  41. package/dist/cjs/types.js.map +0 -6
  42. package/dist/esm/AnimatePresence.js +0 -110
  43. package/dist/esm/AnimatePresence.js.map +0 -6
  44. package/dist/esm/LayoutGroupContext.js +0 -6
  45. package/dist/esm/LayoutGroupContext.js.map +0 -6
  46. package/dist/esm/PresenceChild.js +0 -57
  47. package/dist/esm/PresenceChild.js.map +0 -6
  48. package/dist/esm/types.js +0 -1
  49. package/dist/esm/types.js.map +0 -6
@@ -1,121 +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 __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: !0 });
8
- }, __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from == "object" || typeof from == "function")
10
- for (let key of __getOwnPropNames(from))
11
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
- var AnimatePresence_exports = {};
16
- __export(AnimatePresence_exports, {
17
- AnimatePresence: () => AnimatePresence
18
- });
19
- module.exports = __toCommonJS(AnimatePresence_exports);
20
- var import_constants = require("@tamagui/constants"), import_use_force_update = require("@tamagui/use-force-update"), import_react = require("react"), import_LayoutGroupContext = require("./LayoutGroupContext"), import_PresenceChild = require("./PresenceChild"), import_jsx_runtime = require("react/jsx-runtime");
21
- const getChildKey = (child) => child.key || (() => {
22
- const ct = child.type, defaultName = ct.displayName || ct.name || "";
23
- return ct && typeof ct == "object" && "staticConfig" in ct && ct.staticConfig.componentName || defaultName;
24
- })();
25
- function updateChildLookup(children, allChildren) {
26
- children.forEach((child) => {
27
- const key = getChildKey(child);
28
- allChildren.set(key, child);
29
- });
30
- }
31
- function onlyElements(children) {
32
- const filtered = [];
33
- return import_react.Children.forEach(children, (child) => {
34
- (0, import_react.isValidElement)(child) && filtered.push(child);
35
- }), filtered;
36
- }
37
- const AnimatePresence = ({
38
- children,
39
- enterVariant,
40
- exitVariant,
41
- enterExitVariant,
42
- initial = !0,
43
- onExitComplete,
44
- exitBeforeEnter,
45
- presenceAffectsLayout = !0,
46
- custom,
47
- passThrough
48
- }) => {
49
- let forceRender = (0, import_react.useContext)(import_LayoutGroupContext.LayoutGroupContext).forceRender ?? (0, import_use_force_update.useForceUpdate)();
50
- const filteredChildren = onlyElements(children), presentChildren = (0, import_react.useRef)(filteredChildren), allChildren = (0, import_react.useRef)(/* @__PURE__ */ new Map()).current, exiting = (0, import_react.useRef)(/* @__PURE__ */ new Set()).current;
51
- updateChildLookup(filteredChildren, allChildren);
52
- const isInitialRender = (0, import_react.useRef)(!0);
53
- if (passThrough)
54
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
55
- if ((0, import_constants.useIsomorphicLayoutEffect)(() => {
56
- isInitialRender.current = !1;
57
- }, []), isInitialRender.current)
58
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: filteredChildren.map((child) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
59
- import_PresenceChild.PresenceChild,
60
- {
61
- isPresent: !0,
62
- enterExitVariant,
63
- exitVariant,
64
- enterVariant,
65
- initial: initial ? void 0 : !1,
66
- presenceAffectsLayout,
67
- custom,
68
- children: child
69
- },
70
- getChildKey(child)
71
- )) });
72
- let childrenToRender = [...filteredChildren];
73
- const presentKeys = presentChildren.current.map(getChildKey), targetKeys = filteredChildren.map(getChildKey), numPresent = presentKeys.length;
74
- for (let i = 0; i < numPresent; i++) {
75
- const key = presentKeys[i];
76
- targetKeys.indexOf(key) === -1 ? exiting.add(key) : exiting.delete(key);
77
- }
78
- return exitBeforeEnter && exiting.size && (childrenToRender = []), exiting.forEach((key) => {
79
- if (targetKeys.indexOf(key) !== -1) return;
80
- const child = allChildren.get(key);
81
- if (!child) return;
82
- const insertionIndex = presentKeys.indexOf(key), exitingComponent = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
83
- import_PresenceChild.PresenceChild,
84
- {
85
- isPresent: !1,
86
- onExitComplete: () => {
87
- allChildren.delete(key), exiting.delete(key);
88
- const removeIndex = presentChildren.current.findIndex(
89
- (presentChild) => presentChild.key === key
90
- );
91
- presentChildren.current.splice(removeIndex, 1), exiting.size || (presentChildren.current = filteredChildren, forceRender(), onExitComplete?.());
92
- },
93
- presenceAffectsLayout,
94
- enterExitVariant,
95
- enterVariant,
96
- exitVariant,
97
- custom,
98
- children: child
99
- },
100
- getChildKey(child)
101
- );
102
- childrenToRender.splice(insertionIndex, 0, exitingComponent);
103
- }), childrenToRender = childrenToRender.map((child) => {
104
- const key = child.key;
105
- return exiting.has(key) ? child : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
106
- import_PresenceChild.PresenceChild,
107
- {
108
- isPresent: !0,
109
- exitVariant,
110
- enterVariant,
111
- enterExitVariant,
112
- presenceAffectsLayout,
113
- custom,
114
- children: child
115
- },
116
- getChildKey(child)
117
- );
118
- }), presentChildren.current = childrenToRender, /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: exiting.size ? childrenToRender : childrenToRender.map((child) => (0, import_react.cloneElement)(child)) });
119
- };
120
- AnimatePresence.displayName = "AnimatePresence";
121
- //# sourceMappingURL=AnimatePresence.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/AnimatePresence.tsx"],
4
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA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CAAC,UAAU;AACjD,UAAM,MAAM,MAAM;AAClB,WAAO,QAAQ,IAAI,GAAG,IACpB,QAEA;AAAA,MAAC;AAAA;AAAA,QAEC,WAAS;AAAA,QACT;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QAEC;AAAA;AAAA,MARI,YAAY,KAAK;AAAA,IASxB;AAAA,EAEJ,CAAC,GAED,gBAAgB,UAAU,kBAGxB,2EACG,kBAAQ,OACL,mBACA,iBAAiB,IAAI,CAAC,cAAU,2BAAa,KAAK,CAAC,GACzD;AAEJ;AAEA,gBAAgB,cAAc;",
5
- "names": []
6
- }
@@ -1,30 +0,0 @@
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, __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: !0 });
9
- }, __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from == "object" || typeof from == "function")
11
- for (let key of __getOwnPropNames(from))
12
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- return to;
14
- };
15
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
- // If the importer is in node compatibility mode or this is not an ESM
17
- // file that has been converted to a CommonJS file using a Babel-
18
- // compatible transform (i.e. "__esModule" has not been set), then set
19
- // "default" to the CommonJS "module.exports" for node compatibility.
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
- mod
22
- )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
23
- var LayoutGroupContext_exports = {};
24
- __export(LayoutGroupContext_exports, {
25
- LayoutGroupContext: () => LayoutGroupContext
26
- });
27
- module.exports = __toCommonJS(LayoutGroupContext_exports);
28
- var import_react = __toESM(require("react"), 1);
29
- const LayoutGroupContext = import_react.default.createContext({});
30
- //# sourceMappingURL=LayoutGroupContext.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/LayoutGroupContext.tsx"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAOX,MAAM,qBAAqB,aAAAA,QAAM,cAAuC,CAAC,CAAC;",
5
- "names": ["React"]
6
- }
@@ -1,77 +0,0 @@
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, __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: !0 });
9
- }, __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from == "object" || typeof from == "function")
11
- for (let key of __getOwnPropNames(from))
12
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- return to;
14
- };
15
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
- // If the importer is in node compatibility mode or this is not an ESM
17
- // file that has been converted to a CommonJS file using a Babel-
18
- // compatible transform (i.e. "__esModule" has not been set), then set
19
- // "default" to the CommonJS "module.exports" for node compatibility.
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
- mod
22
- )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
23
- var PresenceChild_exports = {};
24
- __export(PresenceChild_exports, {
25
- PresenceChild: () => PresenceChild
26
- });
27
- module.exports = __toCommonJS(PresenceChild_exports);
28
- var import_use_constant = require("@tamagui/use-constant"), import_use_presence = require("@tamagui/use-presence"), React = __toESM(require("react"), 1), import_react = require("react"), import_jsx_runtime = require("react/jsx-runtime");
29
- const PresenceChild = React.memo(
30
- ({
31
- children,
32
- initial,
33
- isPresent,
34
- onExitComplete,
35
- exitVariant,
36
- enterVariant,
37
- enterExitVariant,
38
- presenceAffectsLayout,
39
- custom
40
- }) => {
41
- const presenceChildren = (0, import_use_constant.useConstant)(newChildrenMap), id = (0, import_react.useId)() || "", context = React.useMemo(
42
- () => ({
43
- id,
44
- initial,
45
- isPresent,
46
- custom,
47
- exitVariant,
48
- enterVariant,
49
- enterExitVariant,
50
- onExitComplete: () => {
51
- presenceChildren.set(id, !0);
52
- for (const isComplete of presenceChildren.values())
53
- if (!isComplete)
54
- return;
55
- onExitComplete?.();
56
- },
57
- register: () => (presenceChildren.set(id, !1), () => presenceChildren.delete(id))
58
- }),
59
- /**
60
- * If the presence of a child affects the layout of the components around it,
61
- * we want to make a new context value to ensure they get re-rendered
62
- * so they can detect that layout change.
63
- */
64
- // @ts-expect-error its ok
65
- presenceAffectsLayout ? void 0 : [isPresent, exitVariant, enterVariant]
66
- );
67
- return React.useMemo(() => {
68
- presenceChildren.forEach((_, key) => presenceChildren.set(key, !1));
69
- }, [isPresent]), React.useEffect(() => {
70
- !isPresent && !presenceChildren.size && onExitComplete?.();
71
- }, [isPresent]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_use_presence.PresenceContext.Provider, { value: context, children });
72
- }
73
- );
74
- function newChildrenMap() {
75
- return /* @__PURE__ */ new Map();
76
- }
77
- //# sourceMappingURL=PresenceChild.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/PresenceChild.tsx"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA4B,kCAC5B,sBAAgC,kCAEhC,QAAuB,8BACvB,eAAsB,kBA+EX;AA9DJ,MAAM,gBAAgB,MAAM;AAAA,EACjC,CAAC;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,MAA0B;AACxB,UAAM,uBAAmB,iCAAY,cAAc,GAC7C,SAAK,oBAAM,KAAK,IAEhB,UAAU,MAAM;AAAA,MACpB,OACS;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,gBAAgB,MAAM;AACpB,2BAAiB,IAAI,IAAI,EAAI;AAC7B,qBAAW,cAAc,iBAAiB,OAAO;AAC/C,gBAAI,CAAC;AACH;AAGJ,2BAAiB;AAAA,QACnB;AAAA,QACA,UAAU,OACR,iBAAiB,IAAI,IAAI,EAAK,GACvB,MAAM,iBAAiB,OAAO,EAAE;AAAA,MAE3C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MASF,wBAAwB,SAAY,CAAC,WAAW,aAAa,YAAY;AAAA,IAC3E;AAEA,iBAAM,QAAQ,MAAM;AAClB,uBAAiB,QAAQ,CAAC,GAAG,QAAQ,iBAAiB,IAAI,KAAK,EAAK,CAAC;AAAA,IACvE,GAAG,CAAC,SAAS,CAAC,GAMd,MAAM,UAAU,MAAM;AACpB,OAAC,aAAa,CAAC,iBAAiB,QAAQ,iBAAiB;AAAA,IAC3D,GAAG,CAAC,SAAS,CAAC,GAEP,4CAAC,oCAAgB,UAAhB,EAAyB,OAAO,SAAU,UAAS;AAAA,EAC7D;AACF;AAEA,SAAS,iBAAuC;AAC9C,SAAO,oBAAI,IAAI;AACjB;",
5
- "names": []
6
- }
package/dist/cjs/index.js DELETED
@@ -1,18 +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 __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from == "object" || typeof from == "function")
7
- for (let key of __getOwnPropNames(from))
8
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
- return to;
10
- }, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
11
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
12
- var index_exports = {};
13
- module.exports = __toCommonJS(index_exports);
14
- __reExport(index_exports, require("./AnimatePresence"), module.exports);
15
- __reExport(index_exports, require("@tamagui/use-presence"), module.exports);
16
- __reExport(index_exports, require("./types"), module.exports);
17
- __reExport(index_exports, require("./PresenceChild"), module.exports);
18
- //# sourceMappingURL=index.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/index.ts"],
4
- "mappings": ";;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,8BAAd;AACA,0BAAc,kCADd;AAEA,0BAAc,oBAFd;AAGA,0BAAc,4BAHd;",
5
- "names": []
6
- }
package/dist/cjs/types.js DELETED
@@ -1,14 +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 __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from == "object" || typeof from == "function")
7
- for (let key of __getOwnPropNames(from))
8
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
- return to;
10
- };
11
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
12
- var types_exports = {};
13
- module.exports = __toCommonJS(types_exports);
14
- //# sourceMappingURL=types.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/types.ts"],
4
- "mappings": ";;;;;;;;;;;AAAA;AAAA;",
5
- "names": []
6
- }
@@ -1,110 +0,0 @@
1
- import { useIsomorphicLayoutEffect } from "@tamagui/constants";
2
- import { useForceUpdate } from "@tamagui/use-force-update";
3
- import { Children, cloneElement, isValidElement, useContext, useRef } from "react";
4
- import { LayoutGroupContext } from "./LayoutGroupContext";
5
- import { PresenceChild } from "./PresenceChild";
6
- import { Fragment, jsx } from "react/jsx-runtime";
7
- const getChildKey = (child) => child.key || (() => {
8
- const ct = child.type, defaultName = ct.displayName || ct.name || "";
9
- return ct && typeof ct == "object" && "staticConfig" in ct && ct.staticConfig.componentName || defaultName;
10
- })();
11
- function updateChildLookup(children, allChildren) {
12
- children.forEach((child) => {
13
- const key = getChildKey(child);
14
- allChildren.set(key, child);
15
- });
16
- }
17
- function onlyElements(children) {
18
- const filtered = [];
19
- return Children.forEach(children, (child) => {
20
- isValidElement(child) && filtered.push(child);
21
- }), filtered;
22
- }
23
- const AnimatePresence = ({
24
- children,
25
- enterVariant,
26
- exitVariant,
27
- enterExitVariant,
28
- initial = !0,
29
- onExitComplete,
30
- exitBeforeEnter,
31
- presenceAffectsLayout = !0,
32
- custom,
33
- passThrough
34
- }) => {
35
- let forceRender = useContext(LayoutGroupContext).forceRender ?? useForceUpdate();
36
- const filteredChildren = onlyElements(children), presentChildren = useRef(filteredChildren), allChildren = useRef(/* @__PURE__ */ new Map()).current, exiting = useRef(/* @__PURE__ */ new Set()).current;
37
- updateChildLookup(filteredChildren, allChildren);
38
- const isInitialRender = useRef(!0);
39
- if (passThrough)
40
- return /* @__PURE__ */ jsx(Fragment, { children });
41
- if (useIsomorphicLayoutEffect(() => {
42
- isInitialRender.current = !1;
43
- }, []), isInitialRender.current)
44
- return /* @__PURE__ */ jsx(Fragment, { children: filteredChildren.map((child) => /* @__PURE__ */ jsx(
45
- PresenceChild,
46
- {
47
- isPresent: !0,
48
- enterExitVariant,
49
- exitVariant,
50
- enterVariant,
51
- initial: initial ? void 0 : !1,
52
- presenceAffectsLayout,
53
- custom,
54
- children: child
55
- },
56
- getChildKey(child)
57
- )) });
58
- let childrenToRender = [...filteredChildren];
59
- const presentKeys = presentChildren.current.map(getChildKey), targetKeys = filteredChildren.map(getChildKey), numPresent = presentKeys.length;
60
- for (let i = 0; i < numPresent; i++) {
61
- const key = presentKeys[i];
62
- targetKeys.indexOf(key) === -1 ? exiting.add(key) : exiting.delete(key);
63
- }
64
- return exitBeforeEnter && exiting.size && (childrenToRender = []), exiting.forEach((key) => {
65
- if (targetKeys.indexOf(key) !== -1) return;
66
- const child = allChildren.get(key);
67
- if (!child) return;
68
- const insertionIndex = presentKeys.indexOf(key), exitingComponent = /* @__PURE__ */ jsx(
69
- PresenceChild,
70
- {
71
- isPresent: !1,
72
- onExitComplete: () => {
73
- allChildren.delete(key), exiting.delete(key);
74
- const removeIndex = presentChildren.current.findIndex(
75
- (presentChild) => presentChild.key === key
76
- );
77
- presentChildren.current.splice(removeIndex, 1), exiting.size || (presentChildren.current = filteredChildren, forceRender(), onExitComplete?.());
78
- },
79
- presenceAffectsLayout,
80
- enterExitVariant,
81
- enterVariant,
82
- exitVariant,
83
- custom,
84
- children: child
85
- },
86
- getChildKey(child)
87
- );
88
- childrenToRender.splice(insertionIndex, 0, exitingComponent);
89
- }), childrenToRender = childrenToRender.map((child) => {
90
- const key = child.key;
91
- return exiting.has(key) ? child : /* @__PURE__ */ jsx(
92
- PresenceChild,
93
- {
94
- isPresent: !0,
95
- exitVariant,
96
- enterVariant,
97
- enterExitVariant,
98
- presenceAffectsLayout,
99
- custom,
100
- children: child
101
- },
102
- getChildKey(child)
103
- );
104
- }), presentChildren.current = childrenToRender, /* @__PURE__ */ jsx(Fragment, { children: exiting.size ? childrenToRender : childrenToRender.map((child) => cloneElement(child)) });
105
- };
106
- AnimatePresence.displayName = "AnimatePresence";
107
- export {
108
- Animat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QACA;AAAA,QACA;AAAA,QACA;AAAA,QAEC;AAAA;AAAA,MATI,YAAY,KAAK;AAAA,IAUxB;AAGF,qBAAiB,OAAO,gBAAgB,GAAG,gBAAgB;AAAA,EAC7D,CAAC,GAID,mBAAmB,iBAAiB,IAAI,CAAC,UAAU;AACjD,UAAM,MAAM,MAAM;AAClB,WAAO,QAAQ,IAAI,GAAG,IACpB,QAEA;AAAA,MAAC;AAAA;AAAA,QAEC,WAAS;AAAA,QACT;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QAEC;AAAA;AAAA,MARI,YAAY,KAAK;AAAA,IASxB;AAAA,EAEJ,CAAC,GAED,gBAAgB,UAAU,kBAGxB,gCACG,kBAAQ,OACL,mBACA,iBAAiB,IAAI,CAAC,UAAU,aAAa,KAAK,CAAC,GACzD;AAEJ;AAEA,gBAAgB,cAAc;",
5
- "names": []
6
- }
@@ -1,6 +0,0 @@
1
- import React from "react";
2
- const LayoutGroupContext = React.createContext({});
3
- export {
4
- LayoutGroupContext
5
- };
6
- //# sourceMappingURL=LayoutGroupContext.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/LayoutGroupContext.tsx"],
4
- "mappings": "AAAA,OAAO,WAAW;AAOX,MAAM,qBAAqB,MAAM,cAAuC,CAAC,CAAC;",
5
- "names": []
6
- }
@@ -1,57 +0,0 @@
1
- import { useConstant } from "@tamagui/use-constant";
2
- import { PresenceContext } from "@tamagui/use-presence";
3
- import * as React from "react";
4
- import { useId } from "react";
5
- import { jsx } from "react/jsx-runtime";
6
- const PresenceChild = React.memo(
7
- ({
8
- children,
9
- initial,
10
- isPresent,
11
- onExitComplete,
12
- exitVariant,
13
- enterVariant,
14
- enterExitVariant,
15
- presenceAffectsLayout,
16
- custom
17
- }) => {
18
- const presenceChildren = useConstant(newChildrenMap), id = useId() || "", context = React.useMemo(
19
- () => ({
20
- id,
21
- initial,
22
- isPresent,
23
- custom,
24
- exitVariant,
25
- enterVariant,
26
- enterExitVariant,
27
- onExitComplete: () => {
28
- presenceChildren.set(id, !0);
29
- for (const isComplete of presenceChildren.values())
30
- if (!isComplete)
31
- return;
32
- onExitComplete?.();
33
- },
34
- register: () => (presenceChildren.set(id, !1), () => presenceChildren.delete(id))
35
- }),
36
- /**
37
- * If the presence of a child affects the layout of the components around it,
38
- * we want to make a new context value to ensure they get re-rendered
39
- * so they can detect that layout change.
40
- */
41
- // @ts-expect-error its ok
42
- presenceAffectsLayout ? void 0 : [isPresent, exitVariant, enterVariant]
43
- );
44
- return React.useMemo(() => {
45
- presenceChildren.forEach((_, key) => presenceChildren.set(key, !1));
46
- }, [isPresent]), React.useEffect(() => {
47
- !isPresent && !presenceChildren.size && onExitComplete?.();
48
- }, [isPresent]), /* @__PURE__ */ jsx(PresenceContext.Provider, { value: context, children });
49
- }
50
- );
51
- function newChildrenMap() {
52
- return /* @__PURE__ */ new Map();
53
- }
54
- export {
55
- PresenceChild
56
- };
57
- //# sourceMappingURL=PresenceChild.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/PresenceChild.tsx"],
4
- "mappings": "AAAA,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAEhC,YAAY,WAAW;AACvB,SAAS,aAAa;AA+EX;AA9DJ,MAAM,gBAAgB,MAAM;AAAA,EACjC,CAAC;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,MAA0B;AACxB,UAAM,mBAAmB,YAAY,cAAc,GAC7C,KAAK,MAAM,KAAK,IAEhB,UAAU,MAAM;AAAA,MACpB,OACS;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,gBAAgB,MAAM;AACpB,2BAAiB,IAAI,IAAI,EAAI;AAC7B,qBAAW,cAAc,iBAAiB,OAAO;AAC/C,gBAAI,CAAC;AACH;AAGJ,2BAAiB;AAAA,QACnB;AAAA,QACA,UAAU,OACR,iBAAiB,IAAI,IAAI,EAAK,GACvB,MAAM,iBAAiB,OAAO,EAAE;AAAA,MAE3C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MASF,wBAAwB,SAAY,CAAC,WAAW,aAAa,YAAY;AAAA,IAC3E;AAEA,iBAAM,QAAQ,MAAM;AAClB,uBAAiB,QAAQ,CAAC,GAAG,QAAQ,iBAAiB,IAAI,KAAK,EAAK,CAAC;AAAA,IACvE,GAAG,CAAC,SAAS,CAAC,GAMd,MAAM,UAAU,MAAM;AACpB,OAAC,aAAa,CAAC,iBAAiB,QAAQ,iBAAiB;AAAA,IAC3D,GAAG,CAAC,SAAS,CAAC,GAEP,oBAAC,gBAAgB,UAAhB,EAAyB,OAAO,SAAU,UAAS;AAAA,EAC7D;AACF;AAEA,SAAS,iBAAuC;AAC9C,SAAO,oBAAI,IAAI;AACjB;",
5
- "names": []
6
- }
package/dist/esm/types.js DELETED
@@ -1 +0,0 @@
1
- //# sourceMappingURL=types.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "mappings": "",
5
- "names": []
6
- }