@tamagui/animate-presence 2.0.0-rc.3 → 2.0.0-rc.30

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.
@@ -23,23 +23,22 @@ __export(AnimatePresence_exports, {
23
23
  AnimatePresence: () => AnimatePresence
24
24
  });
25
25
  module.exports = __toCommonJS(AnimatePresence_exports);
26
- var import_constants = require("@tamagui/constants"),
26
+ var import_react = require("react"),
27
+ import_use_constant = require("@tamagui/use-constant"),
27
28
  import_use_force_update = require("@tamagui/use-force-update"),
28
- import_react = require("react"),
29
+ import_react2 = require("react"),
29
30
  import_LayoutGroupContext = require("./LayoutGroupContext.cjs"),
30
31
  import_PresenceChild = require("./PresenceChild.cjs"),
31
32
  import_jsx_runtime = require("react/jsx-runtime");
32
- const getChildKey = child => child.key || "";
33
- function updateChildLookup(children, allChildren) {
34
- children.forEach(child => {
35
- const key = getChildKey(child);
36
- allChildren.set(key, child);
37
- });
38
- }
33
+ const getChildKey = child => child.key || (() => {
34
+ const ct = child.type,
35
+ defaultName = ct.displayName || ct.name || "";
36
+ return ct && typeof ct == "object" && "staticConfig" in ct && ct.staticConfig.componentName || defaultName;
37
+ })();
39
38
  function onlyElements(children) {
40
39
  const filtered = [];
41
- return import_react.Children.forEach(children, child => {
42
- (0, import_react.isValidElement)(child) && filtered.push(child);
40
+ return import_react2.Children.forEach(children, child => {
41
+ (0, import_react2.isValidElement)(child) && filtered.push(child);
43
42
  }), filtered;
44
43
  }
45
44
  const AnimatePresence = ({
@@ -50,75 +49,63 @@ const AnimatePresence = ({
50
49
  initial = !0,
51
50
  onExitComplete,
52
51
  exitBeforeEnter,
52
+ mode,
53
53
  presenceAffectsLayout = !0,
54
54
  custom,
55
55
  passThrough
56
56
  }) => {
57
- let forceRender = (0, import_react.useContext)(import_LayoutGroupContext.LayoutGroupContext).forceRender ?? (0, import_use_force_update.useForceUpdate)();
58
- const filteredChildren = onlyElements(children),
59
- presentChildren = (0, import_react.useRef)(filteredChildren),
60
- allChildren = (0, import_react.useRef)(/* @__PURE__ */new Map()).current,
61
- exiting = (0, import_react.useRef)(/* @__PURE__ */new Set()).current;
62
- updateChildLookup(filteredChildren, allChildren);
63
- const isInitialRender = (0, import_react.useRef)(!0);
57
+ const effectiveMode = mode ?? (exitBeforeEnter ? "wait" : "sync"),
58
+ presentChildren = (0, import_react2.useMemo)(() => onlyElements(children), [children]),
59
+ presentKeys = presentChildren.map(getChildKey),
60
+ isInitialRender = (0, import_react2.useRef)(!0),
61
+ frozenCustomRef = (0, import_react2.useRef)(/* @__PURE__ */new Map()),
62
+ pendingPresentChildren = (0, import_react2.useRef)(presentChildren),
63
+ exitComplete = (0, import_use_constant.useConstant)(() => /* @__PURE__ */new Map()),
64
+ [diffedChildren, setDiffedChildren] = (0, import_react2.useState)(presentChildren),
65
+ [renderedChildren, setRenderedChildren] = (0, import_react2.useState)(presentChildren),
66
+ forceRender = (0, import_react2.useContext)(import_LayoutGroupContext.LayoutGroupContext).forceRender ?? (0, import_use_force_update.useForceUpdate)();
64
67
  if (passThrough) return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
65
68
  children
66
69
  });
67
- if ((0, import_constants.useIsomorphicLayoutEffect)(() => {
68
- isInitialRender.current = !1;
69
- }, []), isInitialRender.current) return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
70
- children: filteredChildren.map(child => /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_PresenceChild.PresenceChild, {
71
- isPresent: !0,
72
- enterExitVariant,
73
- exitVariant,
74
- enterVariant,
75
- initial: initial ? void 0 : !1,
76
- presenceAffectsLayout,
77
- custom,
78
- children: child
79
- }, getChildKey(child)))
80
- });
81
- let childrenToRender = [...filteredChildren];
82
- const presentKeys = presentChildren.current.map(getChildKey),
83
- targetKeys = filteredChildren.map(getChildKey),
84
- numPresent = presentKeys.length;
85
- for (let i = 0; i < numPresent; i++) {
86
- const key = presentKeys[i];
87
- targetKeys.indexOf(key) === -1 ? exiting.add(key) : exiting.delete(key);
70
+ if ((0, import_react.useInsertionEffect)(() => {
71
+ isInitialRender.current = !1, pendingPresentChildren.current = presentChildren;
72
+ for (let i = 0; i < renderedChildren.length; i++) {
73
+ const key = getChildKey(renderedChildren[i]);
74
+ presentKeys.includes(key) ? (exitComplete.delete(key), frozenCustomRef.current.delete(key)) : exitComplete.get(key) !== !0 && exitComplete.set(key, !1);
75
+ }
76
+ }, [renderedChildren, presentKeys.length, presentKeys.join("-")]), presentChildren !== diffedChildren) {
77
+ let nextChildren = [...presentChildren];
78
+ for (let i = 0; i < renderedChildren.length; i++) {
79
+ const child = renderedChildren[i],
80
+ key = getChildKey(child);
81
+ presentKeys.includes(key) || (nextChildren.splice(i, 0, child), frozenCustomRef.current.has(key) || frozenCustomRef.current.set(key, custom));
82
+ }
83
+ const exitingChildren = renderedChildren.filter(child => !presentKeys.includes(getChildKey(child)));
84
+ return effectiveMode === "wait" && exitingChildren.length && (nextChildren = exitingChildren), setRenderedChildren(onlyElements(nextChildren)), setDiffedChildren(presentChildren), null;
88
85
  }
89
- return exitBeforeEnter && exiting.size && (childrenToRender = []), exiting.forEach(key => {
90
- if (targetKeys.indexOf(key) !== -1) return;
91
- const child = allChildren.get(key);
92
- if (!child) return;
93
- const insertionIndex = presentKeys.indexOf(key),
94
- exitingComponent = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_PresenceChild.PresenceChild, {
95
- isPresent: !1,
96
- onExitComplete: () => {
97
- allChildren.delete(key), exiting.delete(key);
98
- const removeIndex = presentChildren.current.findIndex(presentChild => presentChild.key === key);
99
- presentChildren.current.splice(removeIndex, 1), exiting.size || (presentChildren.current = filteredChildren, forceRender(), onExitComplete?.());
100
- },
86
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
87
+ children: renderedChildren.map(child => {
88
+ const key = getChildKey(child),
89
+ isPresent = presentChildren === renderedChildren || presentKeys.includes(key),
90
+ onExit = () => {
91
+ if (exitComplete.has(key)) exitComplete.set(key, !0);else return;
92
+ let isEveryExitComplete = !0;
93
+ exitComplete.forEach(isExitComplete => {
94
+ isExitComplete || (isEveryExitComplete = !1);
95
+ }), isEveryExitComplete && (forceRender?.(), setRenderedChildren(pendingPresentChildren.current), onExitComplete?.());
96
+ };
97
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_PresenceChild.PresenceChild, {
98
+ isPresent,
99
+ initial: !isInitialRender.current || initial ? void 0 : !1,
100
+ custom: isPresent ? custom : frozenCustomRef.current.get(key) ?? custom,
101
101
  presenceAffectsLayout,
102
102
  enterExitVariant,
103
103
  enterVariant,
104
104
  exitVariant,
105
- custom,
105
+ onExitComplete: isPresent ? void 0 : onExit,
106
106
  children: child
107
- }, getChildKey(child));
108
- childrenToRender.splice(insertionIndex, 0, exitingComponent);
109
- }), childrenToRender = childrenToRender.map(child => {
110
- const key = child.key;
111
- return exiting.has(key) ? child : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_PresenceChild.PresenceChild, {
112
- isPresent: !0,
113
- exitVariant,
114
- enterVariant,
115
- enterExitVariant,
116
- presenceAffectsLayout,
117
- custom,
118
- children: child
119
- }, getChildKey(child));
120
- }), presentChildren.current = childrenToRender, /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
121
- children: exiting.size ? childrenToRender : childrenToRender.map(child => (0, import_react.cloneElement)(child))
107
+ }, key);
108
+ })
122
109
  });
123
110
  };
124
111
  AnimatePresence.displayName = "AnimatePresence";
@@ -26,24 +26,28 @@ __export(AnimatePresence_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(AnimatePresence_exports);
28
28
  var import_jsx_runtime = require("react/jsx-runtime"),
29
- import_constants = require("@tamagui/constants"),
30
- import_use_force_update = require("@tamagui/use-force-update"),
31
29
  import_react = require("react"),
30
+ import_use_constant = require("@tamagui/use-constant"),
31
+ import_use_force_update = require("@tamagui/use-force-update"),
32
+ import_react2 = require("react"),
32
33
  import_LayoutGroupContext = require("./LayoutGroupContext.native.js"),
33
- import_PresenceChild = require("./PresenceChild.native.js"),
34
- getChildKey = function (child) {
35
- return child.key || "";
36
- };
37
- function updateChildLookup(children, allChildren) {
38
- children.forEach(function (child) {
39
- var key = getChildKey(child);
40
- allChildren.set(key, child);
41
- });
34
+ import_PresenceChild = require("./PresenceChild.native.js");
35
+ function _type_of(obj) {
36
+ "@swc/helpers - typeof";
37
+
38
+ return obj && typeof Symbol < "u" && obj.constructor === Symbol ? "symbol" : typeof obj;
42
39
  }
40
+ var getChildKey = function (child) {
41
+ return child.key || function () {
42
+ var ct = child.type,
43
+ defaultName = ct.displayName || ct.name || "";
44
+ return ct && (typeof ct > "u" ? "undefined" : _type_of(ct)) === "object" && "staticConfig" in ct && ct.staticConfig.componentName || defaultName;
45
+ }();
46
+ };
43
47
  function onlyElements(children) {
44
48
  var filtered = [];
45
- return import_react.Children.forEach(children, function (child) {
46
- /* @__PURE__ */(0, import_react.isValidElement)(child) && filtered.push(child);
49
+ return import_react2.Children.forEach(children, function (child) {
50
+ /* @__PURE__ */(0, import_react2.isValidElement)(child) && filtered.push(child);
47
51
  }), filtered;
48
52
  }
49
53
  var AnimatePresence = function (param) {
@@ -55,80 +59,69 @@ var AnimatePresence = function (param) {
55
59
  initial = !0,
56
60
  onExitComplete,
57
61
  exitBeforeEnter,
62
+ mode,
58
63
  presenceAffectsLayout = !0,
59
64
  custom,
60
65
  passThrough
61
66
  } = param,
67
+ effectiveMode = mode ?? (exitBeforeEnter ? "wait" : "sync"),
68
+ presentChildren = (0, import_react2.useMemo)(function () {
69
+ return onlyElements(children);
70
+ }, [children]),
71
+ presentKeys = presentChildren.map(getChildKey),
72
+ isInitialRender = (0, import_react2.useRef)(!0),
73
+ frozenCustomRef = (0, import_react2.useRef)(/* @__PURE__ */new Map()),
74
+ pendingPresentChildren = (0, import_react2.useRef)(presentChildren),
75
+ exitComplete = (0, import_use_constant.useConstant)(function () {
76
+ return /* @__PURE__ */new Map();
77
+ }),
78
+ [diffedChildren, setDiffedChildren] = (0, import_react2.useState)(presentChildren),
79
+ [renderedChildren, setRenderedChildren] = (0, import_react2.useState)(presentChildren),
62
80
  _useContext_forceRender,
63
- forceRender = (_useContext_forceRender = (0, import_react.useContext)(import_LayoutGroupContext.LayoutGroupContext).forceRender) !== null && _useContext_forceRender !== void 0 ? _useContext_forceRender : (0, import_use_force_update.useForceUpdate)(),
64
- filteredChildren = onlyElements(children),
65
- presentChildren = (0, import_react.useRef)(filteredChildren),
66
- allChildren = (0, import_react.useRef)(/* @__PURE__ */new Map()).current,
67
- exiting = (0, import_react.useRef)(/* @__PURE__ */new Set()).current;
68
- updateChildLookup(filteredChildren, allChildren);
69
- var isInitialRender = (0, import_react.useRef)(!0);
81
+ forceRender = (_useContext_forceRender = (0, import_react2.useContext)(import_LayoutGroupContext.LayoutGroupContext).forceRender) !== null && _useContext_forceRender !== void 0 ? _useContext_forceRender : (0, import_use_force_update.useForceUpdate)();
70
82
  if (passThrough) return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
71
83
  children
72
84
  });
73
- if ((0, import_constants.useIsomorphicLayoutEffect)(function () {
74
- isInitialRender.current = !1;
75
- }, []), isInitialRender.current) return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
76
- children: filteredChildren.map(function (child) {
85
+ if ((0, import_react.useInsertionEffect)(function () {
86
+ isInitialRender.current = !1, pendingPresentChildren.current = presentChildren;
87
+ for (var i2 = 0; i2 < renderedChildren.length; i2++) {
88
+ var key2 = getChildKey(renderedChildren[i2]);
89
+ presentKeys.includes(key2) ? (exitComplete.delete(key2), frozenCustomRef.current.delete(key2)) : exitComplete.get(key2) !== !0 && exitComplete.set(key2, !1);
90
+ }
91
+ }, [renderedChildren, presentKeys.length, presentKeys.join("-")]), presentChildren !== diffedChildren) {
92
+ for (var nextChildren = [...presentChildren], i = 0; i < renderedChildren.length; i++) {
93
+ var child = renderedChildren[i],
94
+ key = getChildKey(child);
95
+ presentKeys.includes(key) || (nextChildren.splice(i, 0, child), frozenCustomRef.current.has(key) || frozenCustomRef.current.set(key, custom));
96
+ }
97
+ var exitingChildren = renderedChildren.filter(function (child2) {
98
+ return !presentKeys.includes(getChildKey(child2));
99
+ });
100
+ return effectiveMode === "wait" && exitingChildren.length && (nextChildren = exitingChildren), setRenderedChildren(onlyElements(nextChildren)), setDiffedChildren(presentChildren), null;
101
+ }
102
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
103
+ children: renderedChildren.map(function (child2) {
104
+ var key2 = getChildKey(child2),
105
+ isPresent = presentChildren === renderedChildren || presentKeys.includes(key2),
106
+ onExit = function () {
107
+ if (exitComplete.has(key2)) exitComplete.set(key2, !0);else return;
108
+ var isEveryExitComplete = !0;
109
+ exitComplete.forEach(function (isExitComplete) {
110
+ isExitComplete || (isEveryExitComplete = !1);
111
+ }), isEveryExitComplete && (forceRender?.(), setRenderedChildren(pendingPresentChildren.current), onExitComplete?.());
112
+ },
113
+ _frozenCustomRef_current_get;
77
114
  return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_PresenceChild.PresenceChild, {
78
- isPresent: !0,
115
+ isPresent,
116
+ initial: !isInitialRender.current || initial ? void 0 : !1,
117
+ custom: isPresent ? custom : (_frozenCustomRef_current_get = frozenCustomRef.current.get(key2)) !== null && _frozenCustomRef_current_get !== void 0 ? _frozenCustomRef_current_get : custom,
118
+ presenceAffectsLayout,
79
119
  enterExitVariant,
80
- exitVariant,
81
120
  enterVariant,
82
- initial: initial ? void 0 : !1,
83
- presenceAffectsLayout,
84
- custom,
85
- children: child
86
- }, getChildKey(child));
87
- })
88
- });
89
- for (var childrenToRender = [...filteredChildren], presentKeys = presentChildren.current.map(getChildKey), targetKeys = filteredChildren.map(getChildKey), numPresent = presentKeys.length, i = 0; i < numPresent; i++) {
90
- var key = presentKeys[i];
91
- targetKeys.indexOf(key) === -1 ? exiting.add(key) : exiting.delete(key);
92
- }
93
- return exitBeforeEnter && exiting.size && (childrenToRender = []), exiting.forEach(function (key2) {
94
- if (targetKeys.indexOf(key2) === -1) {
95
- var child = allChildren.get(key2);
96
- if (child) {
97
- var insertionIndex = presentKeys.indexOf(key2),
98
- onExit = function () {
99
- allChildren.delete(key2), exiting.delete(key2);
100
- var removeIndex = presentChildren.current.findIndex(function (presentChild) {
101
- return presentChild.key === key2;
102
- });
103
- presentChildren.current.splice(removeIndex, 1), exiting.size || (presentChildren.current = filteredChildren, forceRender(), onExitComplete?.());
104
- },
105
- exitingComponent = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_PresenceChild.PresenceChild, {
106
- isPresent: !1,
107
- onExitComplete: onExit,
108
- presenceAffectsLayout,
109
- enterExitVariant,
110
- enterVariant,
111
- exitVariant,
112
- custom,
113
- children: child
114
- }, getChildKey(child));
115
- childrenToRender.splice(insertionIndex, 0, exitingComponent);
116
- }
117
- }
118
- }), childrenToRender = childrenToRender.map(function (child) {
119
- var key2 = child.key;
120
- return exiting.has(key2) ? child : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_PresenceChild.PresenceChild, {
121
- isPresent: !0,
122
- exitVariant,
123
- enterVariant,
124
- enterExitVariant,
125
- presenceAffectsLayout,
126
- custom,
127
- children: child
128
- }, getChildKey(child));
129
- }), presentChildren.current = childrenToRender, /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
130
- children: exiting.size ? childrenToRender : childrenToRender.map(function (child) {
131
- return /* @__PURE__ */(0, import_react.cloneElement)(child);
121
+ exitVariant,
122
+ onExitComplete: isPresent ? void 0 : onExit,
123
+ children: child2
124
+ }, key2);
132
125
  })
133
126
  });
134
127
  };
@@ -1 +1 @@
1
- {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","AnimatePresence_exports","__export","AnimatePresence","module","exports","import_jsx_runtime","require","import_constants","import_use_force_update","import_react","import_LayoutGroupContext","import_PresenceChild","getChildKey","child","key","updateChildLookup","children","allChildren","forEach","set","onlyElements","filtered","Children","isValidElement","push","param","enterVariant","exitVariant","enterExitVariant","initial","onExitComplete","exitBeforeEnter","presenceAffectsLayout","custom","passThrough","_useContext_forceRender","forceRender","useContext","LayoutGroupContext","useForceUpdate","filteredChildren","presentChildren","useRef","Map","current","exiting","Set","isInitialRender","jsx","Fragment","useIsomorphicLayoutEffect","map","PresenceChild","isPresent","childrenToRender","presentKeys","targetKeys","numPresent","length","i","indexOf","add","delete","size","key2","get","insertionIndex","onExit","removeIndex","findIndex","presentChild","splice","exitingComponent","has","cloneElement","displayName"],"sources":["../../src/AnimatePresence.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,uBAAA;AAAAC,QAAA,CAAAD,uBAAA;EAAAE,eAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAT,YAA0C,CAAAK,uBAAA,CAC1C;AASA,IAAAK,kBAAqB,GAAAC,OAA2C,oBAAa;EAAAC,gBAAA,GAAAD,OAAA;EAAAE,uBAAA,GAAAF,OAAA;EAAAG,YAAA,GAAAH,OAAA;EAAAI,yBAAA,GAAAJ,OAAA;EAAAK,oBAAA,GAAAL,OAAA;EAAAM,WAAA,YAAAA,CAAAC,KAAA;IAE7E,OAASA,KAAA,CAAAC,GAAA;EAIP;AACE,SAAAC,iBAAYA,CAAAC,QAAiB,EAAAC,WAAA;EAC7BD,QAAA,CAAAE,OAAY,WAASL,KAAK;IAC3B,IAAAC,GAAA,GAAAF,WAAA,CAAAC,KAAA;IACHI,WAAA,CAAAE,GAAA,CAAAL,GAAA,EAAAD,KAAA;EAEA;AACE;AAEA,SAAAO,aAAAJ,QAAA,EAAS;EACP,IAAAK,QAAI;EACN,OACOZ,YAAA,CAAAa,QAAA,CAA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WAAA,MAAAvB,OAAA,CAAAkB,IAAA,KAAAtB,eAAA,CAAAG,OAAA,GAAAJ,gBAAA,EAAAJ,WAAA,IAAAN,cAAA;UAEpC;UAAM0C,gBAAQ,GAAY,eAAO,IAAAnE,kBAAA,CAAA2C,GAAA,EAAArC,oBAAA,CAAAyC,aAAA;YAC5BC,SAAO;YAENvB,cAAA,EAAAqC,MAAiB;YAkBpBnC,qBAAA;YAAAJ,gBAAA;YAECF,YAAW;YACXC,WAAA;YAlBFM,MAAA;YAEAjB,QAAM,EAAAH;UAAsC,GAAAD,WACzC,CAAAC,KAAA,EAAiB;QAAqByC,gBACzC,CAAAiB,MAAA,CAAAL,cAAA,KAAAM,gBAAA;MACA;IAKmB;EAErB,IAAAlB,gBAOI,GAAAA,gBAAA,CAAAH,GAAA,WAAAtC,KAAA;IAAA,IACAmD,IAAA,GAAAnD,KAAA,CAAAC,GAAA;IAAA,OACA+B,OAAA,CAAA4B,GAAA,CAAAT,IAAA,IAAAnD,KAAA,sBAAAR,kBAAA,CAAA2C,GAAA,EAAArC,oBAAA,CAAAyC,aAAA;MAAAC,SACA;MAAA1B,WACA;MAAAD,YAEC;MAAAE,gBAAA;MATII,qBAAiB;MAUxBC,MAAA;MAGFjB,QAAA,EAAAH;IACD,GAIDD,WAAA,CAAAC,KAAA,CAAmB;EACjB,IAAA4B,eAAY,CAAMG,OAAA,GAAAU,gBAAA,qBAAAjD,kBAAA,CAAA2C,GAAA,EAAA3C,kBAAA,CAAA4C,QAAA;IAClBjC,QAAO,EAAA6B,OAAQ,CAAAkB,IAAO,GAAAT,gBAGpB,GAAAA,gBAAA,CAAAH,GAAA,WAAAtC,KAAA;MAAC,0BAAAJ,YAAA,CAAAiE,YAAA,EAAA7D,KAAA;IAAA;EAAA;AAEU;AACTX,eACA,CAAAyE,WAAA","ignoreList":[]}
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","AnimatePresence_exports","__export","AnimatePresence","module","exports","import_jsx_runtime","require","import_react","import_use_constant","import_use_force_update","import_react2","import_LayoutGroupContext","import_PresenceChild","_type_of","obj","Symbol","constructor","getChildKey","child","key","ct","type","defaultName","displayName","name","staticConfig","componentName","onlyElements","children","filtered","Children","forEach","isValidElement","push","param","enterVariant","exitVariant","enterExitVariant","initial","onExitComplete","exitBeforeEnter","mode","presenceAffectsLayout","custom","passThrough","effectiveMode","presentChildren","useMemo","presentKeys","map","isInitialRender","useRef","frozenCustomRef","Map","pendingPresentChildren","exitComplete","useConstant","diffedChildren","setDiffedChildren","useState","renderedChildren","setRenderedChildren","_useContext_forceRender","forceRender","useContext","LayoutGroupContext","useForceUpdate","jsx","Fragment","useInsertionEffect","current","i2","length","key2","includes","delete","get","set","join","nextChildren","i","splice","has","exitingChildren","filter","child2","isPresent","onExit","isEveryExitComplete","isExitComplete","_frozenCustomRef_current_get","PresenceChild"],"sources":["../../src/AnimatePresence.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,uBAAA;AAAAC,QAAA,CAAAD,uBAAA;EAAAE,eAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAT,YAAmC,CAAAK,uBACnC;AAUA,IAAAK,kBAAqB,GAAAC,OAEjB,oBACO;EAAAC,YAAA,GAAAD,OAAA;EAAAE,mBAAA,GAAAF,OAAA;EAAAG,uBAAA,GAAAH,OAAA;EAAAI,aAAA,GAAAJ,OAAA;EAAAK,yBAAA,GAAAL,OAAA;EAAAM,oBAAA,GAAAN,OAAA;AAEL,SAAMO,QAAKA,CAAAC,GAAM;EAEjB,uBAAiB;;EAKnB,OAAGA,GAAA,WAAAC,MAAA,UAAAD,GAAA,CAAAE,WAAA,KAAAD,MAAA,qBAAAD,GAAA;AAIP;AACE,IAAAG,WAAM,YAAAA,CAAiCC,KAAA;EAE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AAhC,OAAA;QAAAK,MAAA,EAAA2C,SAAA,GAAA3C,MAAA,IAAA+C,4BAAA,GAAAtC,eAAA,CAAAkB,OAAA,CAAAM,GAAA,CAAAH,IAAA,eAAAiB,4BAAA,cAAAA,4BAAA,GAAA/C,MAAA;QAVID,qBAAA;QAWPL,gBAAA;QAGNF,YAAA;QAEJC,WAAA;QAEAG,cAAgB,EAAA+C,SAAc,YAAAC,MAAA","ignoreList":[]}
package/dist/cjs/index.js CHANGED
@@ -3,16 +3,19 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
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);
6
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
7
+ get: () => from[key],
8
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
9
+ });
10
+ return to;
11
+ },
12
+ __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
13
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
14
+ value: !0
15
+ }), mod);
12
16
  var index_exports = {};
13
17
  module.exports = __toCommonJS(index_exports);
14
- __reExport(index_exports, require("./AnimatePresence"), module.exports);
18
+ __reExport(index_exports, require("./AnimatePresence.cjs"), module.exports);
15
19
  __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
20
+ __reExport(index_exports, require("./types.cjs"), module.exports);
21
+ __reExport(index_exports, require("./PresenceChild.cjs"), module.exports);
@@ -1,16 +1,15 @@
1
- import { useIsomorphicLayoutEffect } from "@tamagui/constants";
1
+ import { useInsertionEffect } from "react";
2
+ import { useConstant } from "@tamagui/use-constant";
2
3
  import { useForceUpdate } from "@tamagui/use-force-update";
3
- import { Children, cloneElement, isValidElement, useContext, useRef } from "react";
4
+ import { Children, isValidElement, useContext, useMemo, useRef, useState } from "react";
4
5
  import { LayoutGroupContext } from "./LayoutGroupContext.mjs";
5
6
  import { PresenceChild } from "./PresenceChild.mjs";
6
7
  import { Fragment, jsx } from "react/jsx-runtime";
7
- const getChildKey = child => child.key || "";
8
- function updateChildLookup(children, allChildren) {
9
- children.forEach(child => {
10
- const key = getChildKey(child);
11
- allChildren.set(key, child);
12
- });
13
- }
8
+ const getChildKey = child => child.key || (() => {
9
+ const ct = child.type,
10
+ defaultName = ct.displayName || ct.name || "";
11
+ return ct && typeof ct == "object" && "staticConfig" in ct && ct.staticConfig.componentName || defaultName;
12
+ })();
14
13
  function onlyElements(children) {
15
14
  const filtered = [];
16
15
  return Children.forEach(children, child => {
@@ -25,75 +24,63 @@ const AnimatePresence = ({
25
24
  initial = !0,
26
25
  onExitComplete,
27
26
  exitBeforeEnter,
27
+ mode,
28
28
  presenceAffectsLayout = !0,
29
29
  custom,
30
30
  passThrough
31
31
  }) => {
32
- let forceRender = useContext(LayoutGroupContext).forceRender ?? useForceUpdate();
33
- const filteredChildren = onlyElements(children),
34
- presentChildren = useRef(filteredChildren),
35
- allChildren = useRef(/* @__PURE__ */new Map()).current,
36
- exiting = useRef(/* @__PURE__ */new Set()).current;
37
- updateChildLookup(filteredChildren, allChildren);
38
- const isInitialRender = useRef(!0);
32
+ const effectiveMode = mode ?? (exitBeforeEnter ? "wait" : "sync"),
33
+ presentChildren = useMemo(() => onlyElements(children), [children]),
34
+ presentKeys = presentChildren.map(getChildKey),
35
+ isInitialRender = useRef(!0),
36
+ frozenCustomRef = useRef(/* @__PURE__ */new Map()),
37
+ pendingPresentChildren = useRef(presentChildren),
38
+ exitComplete = useConstant(() => /* @__PURE__ */new Map()),
39
+ [diffedChildren, setDiffedChildren] = useState(presentChildren),
40
+ [renderedChildren, setRenderedChildren] = useState(presentChildren),
41
+ forceRender = useContext(LayoutGroupContext).forceRender ?? useForceUpdate();
39
42
  if (passThrough) return /* @__PURE__ */jsx(Fragment, {
40
43
  children
41
44
  });
42
- if (useIsomorphicLayoutEffect(() => {
43
- isInitialRender.current = !1;
44
- }, []), isInitialRender.current) return /* @__PURE__ */jsx(Fragment, {
45
- children: filteredChildren.map(child => /* @__PURE__ */jsx(PresenceChild, {
46
- isPresent: !0,
47
- enterExitVariant,
48
- exitVariant,
49
- enterVariant,
50
- initial: initial ? void 0 : !1,
51
- presenceAffectsLayout,
52
- custom,
53
- children: child
54
- }, getChildKey(child)))
55
- });
56
- let childrenToRender = [...filteredChildren];
57
- const presentKeys = presentChildren.current.map(getChildKey),
58
- targetKeys = filteredChildren.map(getChildKey),
59
- 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);
45
+ if (useInsertionEffect(() => {
46
+ isInitialRender.current = !1, pendingPresentChildren.current = presentChildren;
47
+ for (let i = 0; i < renderedChildren.length; i++) {
48
+ const key = getChildKey(renderedChildren[i]);
49
+ presentKeys.includes(key) ? (exitComplete.delete(key), frozenCustomRef.current.delete(key)) : exitComplete.get(key) !== !0 && exitComplete.set(key, !1);
50
+ }
51
+ }, [renderedChildren, presentKeys.length, presentKeys.join("-")]), presentChildren !== diffedChildren) {
52
+ let nextChildren = [...presentChildren];
53
+ for (let i = 0; i < renderedChildren.length; i++) {
54
+ const child = renderedChildren[i],
55
+ key = getChildKey(child);
56
+ presentKeys.includes(key) || (nextChildren.splice(i, 0, child), frozenCustomRef.current.has(key) || frozenCustomRef.current.set(key, custom));
57
+ }
58
+ const exitingChildren = renderedChildren.filter(child => !presentKeys.includes(getChildKey(child)));
59
+ return effectiveMode === "wait" && exitingChildren.length && (nextChildren = exitingChildren), setRenderedChildren(onlyElements(nextChildren)), setDiffedChildren(presentChildren), null;
63
60
  }
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),
69
- exitingComponent = /* @__PURE__ */jsx(PresenceChild, {
70
- isPresent: !1,
71
- onExitComplete: () => {
72
- allChildren.delete(key), exiting.delete(key);
73
- const removeIndex = presentChildren.current.findIndex(presentChild => presentChild.key === key);
74
- presentChildren.current.splice(removeIndex, 1), exiting.size || (presentChildren.current = filteredChildren, forceRender(), onExitComplete?.());
75
- },
61
+ return /* @__PURE__ */jsx(Fragment, {
62
+ children: renderedChildren.map(child => {
63
+ const key = getChildKey(child),
64
+ isPresent = presentChildren === renderedChildren || presentKeys.includes(key),
65
+ onExit = () => {
66
+ if (exitComplete.has(key)) exitComplete.set(key, !0);else return;
67
+ let isEveryExitComplete = !0;
68
+ exitComplete.forEach(isExitComplete => {
69
+ isExitComplete || (isEveryExitComplete = !1);
70
+ }), isEveryExitComplete && (forceRender?.(), setRenderedChildren(pendingPresentChildren.current), onExitComplete?.());
71
+ };
72
+ return /* @__PURE__ */jsx(PresenceChild, {
73
+ isPresent,
74
+ initial: !isInitialRender.current || initial ? void 0 : !1,
75
+ custom: isPresent ? custom : frozenCustomRef.current.get(key) ?? custom,
76
76
  presenceAffectsLayout,
77
77
  enterExitVariant,
78
78
  enterVariant,
79
79
  exitVariant,
80
- custom,
80
+ onExitComplete: isPresent ? void 0 : onExit,
81
81
  children: child
82
- }, getChildKey(child));
83
- childrenToRender.splice(insertionIndex, 0, exitingComponent);
84
- }), childrenToRender = childrenToRender.map(child => {
85
- const key = child.key;
86
- return exiting.has(key) ? child : /* @__PURE__ */jsx(PresenceChild, {
87
- isPresent: !0,
88
- exitVariant,
89
- enterVariant,
90
- enterExitVariant,
91
- presenceAffectsLayout,
92
- custom,
93
- children: child
94
- }, getChildKey(child));
95
- }), presentChildren.current = childrenToRender, /* @__PURE__ */jsx(Fragment, {
96
- children: exiting.size ? childrenToRender : childrenToRender.map(child => cloneElement(child))
82
+ }, key);
83
+ })
97
84
  });
98
85
  };
99
86
  AnimatePresence.displayName = "AnimatePresence";
@@ -1 +1 @@
1
- {"version":3,"names":["useIsomorphicLayoutEffect","useForceUpdate","Children","cloneElement","isValidElement","useContext","useRef","LayoutGroupContext","PresenceChild","Fragment","jsx","getChildKey","child","key","updateChildLookup","children","allChildren","forEach","set","onlyElements","filtered","push","AnimatePresence","enterVariant","exitVariant","enterExitVariant","initial","onExitComplete","exitBeforeEnter","presenceAffectsLayout","custom","passThrough","forceRender","filteredChildren","presentChildren","Map","current","exiting","Set","isInitialRender","map","isPresent","childrenToRender","presentKeys","targetKeys","numPresent","length","i","indexOf","add","delete","size","get","insertionIndex","exitingComponent","removeIndex","findIndex","presentChild","splice","has","displayName"],"sources":["../../src/AnimatePresence.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,yBAAA,QAAiC;AAC1C,SAASC,cAAA,QAAsB;AAE/B,SAASC,QAAA,EAAUC,YAAA,EAAcC,cAAA,EAAgBC,UAAA,EAAYC,MAAA,QAAc;AAC3E,SAASC,kBAAA,QAA0B;AACnC,SAASC,aAAA,QAAqB;AA+DnB,SAAAC,QAAA,EAAAC,GAAA;AA1DX,MAAMC,WAAA,GAAeC,KAAA,IAA2CA,KAAA,CAAMC,GAAA,IAAO;AAE7E,SAASC,kBACPC,QAAA,EACAC,WAAA,EACA;EACAD,QAAA,CAASE,OAAA,CAASL,KAAA,IAAU;IAC1B,MAAMC,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CAAOrC,GAAG;UAClB,MAAM0C,WAAA,GAAcrB,eAAA,CAAgBE,OAAA,CAAQoB,SAAA,CACzCC,YAAA,IAAiBA,YAAA,CAAa5C,GAAA,KAAQA,GACzC;UACAqB,eAAA,CAAgBE,OAAA,CAAQsB,MAAA,CAAOH,WAAA,EAAa,CAAC,GAExClB,OAAA,CAAQc,IAAA,KACXjB,eAAA,CAAgBE,OAAA,GAAUH,gBAAA,EAC1BD,WAAA,CAAY,GACZL,cAAA,GAAiB;QAErB;QAOIE,qBAAA;QACAJ,gBAAA;QACAF,YAAA;QACAC,WAAA;QACAM,MAAA;QAECf,QAAA,EAAAH;MAAA,GATID,WAAA,CAAYC,KAAK,CAUxB;IAGF8B,gBAAA,CAAiBgB,MAAA,CAAOL,cAAA,EAAgB,GAAGC,gBAAgB;EAC7D,CAAC,GAIDZ,gBAAA,GAAmBA,gBAAA,CAAiBF,GAAA,CAAK5B,KAAA,IAAU;IACjD,MAAMC,GAAA,GAAMD,KAAA,CAAMC,GAAA;IAClB,OAAOwB,OAAA,CAAQsB,GAAA,CAAI9C,GAAG,IACpBD,KAAA,GAEA,eAAAF,GAAA,CAACF,aAAA;MAECiC,SAAA,EAAS;MACTjB,WAAA;MACAD,YAAA;MACAE,gBAAA;MACAI,qBAAA;MACAC,MAAA;MAECf,QAAA,EAAAH;IAAA,GARID,WAAA,CAAYC,KAAK,CASxB;EAEJ,CAAC,GAEDsB,eAAA,CAAgBE,OAAA,GAAUM,gBAAA,EAGxB,eAAAhC,GAAA,CAAAD,QAAA;IACGM,QAAA,EAAAsB,OAAA,CAAQc,IAAA,GACLT,gBAAA,GACAA,gBAAA,CAAiBF,GAAA,CAAK5B,KAAA,IAAUT,YAAA,CAAaS,KAAK,CAAC;EAAA,CACzD;AAEJ;AAEAU,eAAA,CAAgBsC,WAAA,GAAc","ignoreList":[]}
1
+ {"version":3,"names":["useInsertionEffect","useConstant","useForceUpdate","Children","isValidElement","useContext","useMemo","useRef","useState","LayoutGroupContext","PresenceChild","Fragment","jsx","getChildKey","child","key","ct","type","defaultName","displayName","name","staticConfig","componentName","onlyElements","children","filtered","forEach","push","AnimatePresence","enterVariant","exitVariant","enterExitVariant","initial","onExitComplete","exitBeforeEnter","mode","presenceAffectsLayout","custom","passThrough","effectiveMode","presentChildren","presentKeys","map","isInitialRender","frozenCustomRef","Map","pendingPresentChildren","exitComplete","diffedChildren","setDiffedChildren","renderedChildren","setRenderedChildren","forceRender","current","i","length","includes","delete","get","set","join","nextChildren","splice","has","exitingChildren","filter","isPresent","onExit","isEveryExitComplete","isExitComplete"],"sources":["../../src/AnimatePresence.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,kBAAA,QAA0B;AACnC,SAASC,WAAA,QAAmB;AAC5B,SAASC,cAAA,QAAsB;AAE/B,SAASC,QAAA,EAAUC,cAAA,EAAgBC,UAAA,EAAYC,OAAA,EAASC,MAAA,EAAQC,QAAA,QAAgB;AAChF,SAASC,kBAAA,QAA0B;AACnC,SAASC,aAAA,QAAqB;AAiGnB,SAAAC,QAAA,EAAAC,GAAA;AA5FX,MAAMC,WAAA,GAAeC,KAAA,IAEjBA,KAAA,CAAMC,GAAA,KACL,MAAM;EAEL,MAAMC,EAAA,GAAKF,KAAA,CAAMG,IAAA;IACXC,WAAA,GAAcF,EAAA,CAAGG,WAAA,IAAkBH,EAAA,CAAGI,IAAA,IAAW;EACvD,OAAIJ,EAAA,IAAM,OAAOA,EAAA,IAAO,YAAY,kBAAkBA,EAAA,IAE7CA,EAAA,CAAGK,YAAA,CAAaC,aAAA,IAAiBJ,WAAA;AAG5C,GAAG;AAIP,SAASK,aAAaC,QAAA,EAA0C;EAC9D,MAAMC,QAAA,GAAgC,EAAC;EAEvC,OAAAtB,QAAA,CAASuB,OAAA,CAAQF,QAAA,EAAWV,KAAA,IAAU;IAChCV,cAAA,CAAeU,KAAK,KAAGW,QAAA,CAASE,IAAA,CAAKb,KAAK;EAChD,CAAC,GACMW,QAAA;AACT;AAEO,MAAMG,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