framer-motion 8.2.4 → 8.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -1057,10 +1057,20 @@ function createUseRender(forwardMotionProps = false) {
1057
1057
  ...visualProps,
1058
1058
  ref,
1059
1059
  };
1060
+ /**
1061
+ * If component has been handed a motion value as its child,
1062
+ * memoise its initial value and render that. Subsequent updates
1063
+ * will be handled by the onChange handler
1064
+ */
1065
+ const { children } = props;
1066
+ const renderedChildren = React.useMemo(() => (isMotionValue(children) ? children.get() : children), [children]);
1060
1067
  if (projectionId) {
1061
1068
  elementProps["data-projection-id"] = projectionId;
1062
1069
  }
1063
- return React.createElement(Component, elementProps);
1070
+ return React.createElement(Component, {
1071
+ ...elementProps,
1072
+ children: renderedChildren,
1073
+ });
1064
1074
  };
1065
1075
  return useRender;
1066
1076
  }
@@ -1537,6 +1547,7 @@ function useTapGesture({ onTap, onTapStart, onTapCancel, whileTap, visualElement
1537
1547
  return !isDragActive();
1538
1548
  }
1539
1549
  function onPointerUp(event, info) {
1550
+ var _a, _b, _c, _d;
1540
1551
  if (!checkPointerEnd())
1541
1552
  return;
1542
1553
  /**
@@ -1544,15 +1555,17 @@ function useTapGesture({ onTap, onTapStart, onTapCancel, whileTap, visualElement
1544
1555
  * as, or a child of, this component's element
1545
1556
  */
1546
1557
  !isNodeOrChild(visualElement.current, event.target)
1547
- ? onTapCancel && onTapCancel(event, info)
1548
- : onTap && onTap(event, info);
1558
+ ? (_b = (_a = visualElement.getProps()).onTapCancel) === null || _b === void 0 ? void 0 : _b.call(_a, event, info)
1559
+ : (_d = (_c = visualElement.getProps()).onTap) === null || _d === void 0 ? void 0 : _d.call(_c, event, info);
1549
1560
  }
1550
1561
  function onPointerCancel(event, info) {
1562
+ var _a, _b;
1551
1563
  if (!checkPointerEnd())
1552
1564
  return;
1553
- onTapCancel && onTapCancel(event, info);
1565
+ (_b = (_a = visualElement.getProps()).onTapCancel) === null || _b === void 0 ? void 0 : _b.call(_a, event, info);
1554
1566
  }
1555
1567
  const startPress = React.useCallback((event, info) => {
1568
+ var _a, _b;
1556
1569
  removePointerEndListener();
1557
1570
  if (isPressing.current)
1558
1571
  return;
@@ -1563,8 +1576,8 @@ function useTapGesture({ onTap, onTapStart, onTapCancel, whileTap, visualElement
1563
1576
  */
1564
1577
  visualElement.animationState &&
1565
1578
  visualElement.animationState.setActive(exports.AnimationType.Tap, true);
1566
- onTapStart && onTapStart(event, info);
1567
- }, [onTapStart, visualElement]);
1579
+ (_b = (_a = visualElement.getProps()).onTapStart) === null || _b === void 0 ? void 0 : _b.call(_a, event, info);
1580
+ }, [Boolean(onTapStart), visualElement]);
1568
1581
  usePointerEvent(visualElement, "pointerdown", hasPressListeners ? startPress : undefined, eventOptions);
1569
1582
  useUnmountEffect(removePointerEndListener);
1570
1583
  }
@@ -2062,7 +2075,7 @@ class MotionValue {
2062
2075
  * This will be replaced by the build step with the latest version number.
2063
2076
  * When MotionValues are provided to motion components, warn if versions are mixed.
2064
2077
  */
2065
- this.version = "8.2.4";
2078
+ this.version = "8.3.1";
2066
2079
  /**
2067
2080
  * Duration, in milliseconds, since last updating frame.
2068
2081
  *
@@ -5918,7 +5931,7 @@ function updateMotionValuesFromProps(element, next, prev) {
5918
5931
  * and warn against mismatches.
5919
5932
  */
5920
5933
  if (process.env.NODE_ENV === "development") {
5921
- warnOnce(nextValue.version === "8.2.4", `Attempting to mix Framer Motion versions ${nextValue.version} with 8.2.4 may not work as expected.`);
5934
+ warnOnce(nextValue.version === "8.3.1", `Attempting to mix Framer Motion versions ${nextValue.version} with 8.3.1 may not work as expected.`);
5922
5935
  }
5923
5936
  }
5924
5937
  else if (isMotionValue(prevValue)) {
@@ -6147,7 +6160,7 @@ class VisualElement {
6147
6160
  return 0;
6148
6161
  return this.sortInstanceNodePosition(this.current, other.current);
6149
6162
  }
6150
- loadFeatures(renderedProps, isStrict, preloadedFeatures, projectionId, ProjectionNodeConstructor, initialLayoutGroupConfig) {
6163
+ loadFeatures({ children, ...renderedProps }, isStrict, preloadedFeatures, projectionId, ProjectionNodeConstructor, initialLayoutGroupConfig) {
6151
6164
  const features = [];
6152
6165
  /**
6153
6166
  * If we're in development mode, check to make sure we're not rendering a motion component
@@ -6252,6 +6265,9 @@ class VisualElement {
6252
6265
  }
6253
6266
  }
6254
6267
  this.prevMotionValues = updateMotionValuesFromProps(this, this.scrapeMotionValuesFromProps(props, prevProps), this.prevMotionValues);
6268
+ if (this.handleChildMotionValue) {
6269
+ this.handleChildMotionValue();
6270
+ }
6255
6271
  }
6256
6272
  getProps() {
6257
6273
  return this.props;
@@ -6481,6 +6497,19 @@ class HTMLVisualElement extends DOMVisualElement {
6481
6497
  scrapeMotionValuesFromProps(props, prevProps) {
6482
6498
  return scrapeMotionValuesFromProps$1(props, prevProps);
6483
6499
  }
6500
+ handleChildMotionValue() {
6501
+ if (this.childSubscription) {
6502
+ this.childSubscription();
6503
+ delete this.childSubscription;
6504
+ }
6505
+ const { children } = this.props;
6506
+ if (isMotionValue(children)) {
6507
+ this.childSubscription = children.on("change", (latest) => {
6508
+ if (this.current)
6509
+ this.current.textContent = `${latest}`;
6510
+ });
6511
+ }
6512
+ }
6484
6513
  renderInstance(instance, renderState, styleProp, projection) {
6485
6514
  renderHTML(instance, renderState, styleProp, projection);
6486
6515
  }
@@ -35,6 +35,7 @@ function useTapGesture({ onTap, onTapStart, onTapCancel, whileTap, visualElement
35
35
  return !isDragActive();
36
36
  }
37
37
  function onPointerUp(event, info) {
38
+ var _a, _b, _c, _d;
38
39
  if (!checkPointerEnd())
39
40
  return;
40
41
  /**
@@ -42,15 +43,17 @@ function useTapGesture({ onTap, onTapStart, onTapCancel, whileTap, visualElement
42
43
  * as, or a child of, this component's element
43
44
  */
44
45
  !isNodeOrChild(visualElement.current, event.target)
45
- ? onTapCancel && onTapCancel(event, info)
46
- : onTap && onTap(event, info);
46
+ ? (_b = (_a = visualElement.getProps()).onTapCancel) === null || _b === void 0 ? void 0 : _b.call(_a, event, info)
47
+ : (_d = (_c = visualElement.getProps()).onTap) === null || _d === void 0 ? void 0 : _d.call(_c, event, info);
47
48
  }
48
49
  function onPointerCancel(event, info) {
50
+ var _a, _b;
49
51
  if (!checkPointerEnd())
50
52
  return;
51
- onTapCancel && onTapCancel(event, info);
53
+ (_b = (_a = visualElement.getProps()).onTapCancel) === null || _b === void 0 ? void 0 : _b.call(_a, event, info);
52
54
  }
53
55
  const startPress = useCallback((event, info) => {
56
+ var _a, _b;
54
57
  removePointerEndListener();
55
58
  if (isPressing.current)
56
59
  return;
@@ -61,8 +64,8 @@ function useTapGesture({ onTap, onTapStart, onTapCancel, whileTap, visualElement
61
64
  */
62
65
  visualElement.animationState &&
63
66
  visualElement.animationState.setActive(AnimationType.Tap, true);
64
- onTapStart && onTapStart(event, info);
65
- }, [onTapStart, visualElement]);
67
+ (_b = (_a = visualElement.getProps()).onTapStart) === null || _b === void 0 ? void 0 : _b.call(_a, event, info);
68
+ }, [Boolean(onTapStart), visualElement]);
66
69
  usePointerEvent(visualElement, "pointerdown", hasPressListeners ? startPress : undefined, eventOptions);
67
70
  useUnmountEffect(removePointerEndListener);
68
71
  }
@@ -209,7 +209,7 @@ class VisualElement {
209
209
  return 0;
210
210
  return this.sortInstanceNodePosition(this.current, other.current);
211
211
  }
212
- loadFeatures(renderedProps, isStrict, preloadedFeatures, projectionId, ProjectionNodeConstructor, initialLayoutGroupConfig) {
212
+ loadFeatures({ children, ...renderedProps }, isStrict, preloadedFeatures, projectionId, ProjectionNodeConstructor, initialLayoutGroupConfig) {
213
213
  const features = [];
214
214
  /**
215
215
  * If we're in development mode, check to make sure we're not rendering a motion component
@@ -314,6 +314,9 @@ class VisualElement {
314
314
  }
315
315
  }
316
316
  this.prevMotionValues = updateMotionValuesFromProps(this, this.scrapeMotionValuesFromProps(props, prevProps), this.prevMotionValues);
317
+ if (this.handleChildMotionValue) {
318
+ this.handleChildMotionValue();
319
+ }
317
320
  }
318
321
  getProps() {
319
322
  return this.props;
@@ -1,8 +1,9 @@
1
- import { createElement } from 'react';
1
+ import { useMemo, createElement } from 'react';
2
2
  import { useHTMLProps } from '../html/use-props.mjs';
3
3
  import { filterProps } from './utils/filter-props.mjs';
4
4
  import { isSVGComponent } from './utils/is-svg-component.mjs';
5
5
  import { useSVGProps } from '../svg/use-props.mjs';
6
+ import { isMotionValue } from '../../value/utils/is-motion-value.mjs';
6
7
 
7
8
  function createUseRender(forwardMotionProps = false) {
8
9
  const useRender = (Component, props, projectionId, ref, { latestValues }, isStatic) => {
@@ -16,10 +17,20 @@ function createUseRender(forwardMotionProps = false) {
16
17
  ...visualProps,
17
18
  ref,
18
19
  };
20
+ /**
21
+ * If component has been handed a motion value as its child,
22
+ * memoise its initial value and render that. Subsequent updates
23
+ * will be handled by the onChange handler
24
+ */
25
+ const { children } = props;
26
+ const renderedChildren = useMemo(() => (isMotionValue(children) ? children.get() : children), [children]);
19
27
  if (projectionId) {
20
28
  elementProps["data-projection-id"] = projectionId;
21
29
  }
22
- return createElement(Component, elementProps);
30
+ return createElement(Component, {
31
+ ...elementProps,
32
+ children: renderedChildren,
33
+ });
23
34
  };
24
35
  return useRender;
25
36
  }
@@ -6,6 +6,7 @@ import { renderHTML } from './utils/render.mjs';
6
6
  import { getDefaultValueType } from '../dom/value-types/defaults.mjs';
7
7
  import { measureViewportBox } from '../../projection/utils/measure.mjs';
8
8
  import { DOMVisualElement } from '../dom/DOMVisualElement.mjs';
9
+ import { isMotionValue } from '../../value/utils/is-motion-value.mjs';
9
10
 
10
11
  function getComputedStyle(element) {
11
12
  return window.getComputedStyle(element);
@@ -33,6 +34,19 @@ class HTMLVisualElement extends DOMVisualElement {
33
34
  scrapeMotionValuesFromProps(props, prevProps) {
34
35
  return scrapeMotionValuesFromProps(props, prevProps);
35
36
  }
37
+ handleChildMotionValue() {
38
+ if (this.childSubscription) {
39
+ this.childSubscription();
40
+ delete this.childSubscription;
41
+ }
42
+ const { children } = this.props;
43
+ if (isMotionValue(children)) {
44
+ this.childSubscription = children.on("change", (latest) => {
45
+ if (this.current)
46
+ this.current.textContent = `${latest}`;
47
+ });
48
+ }
49
+ }
36
50
  renderInstance(instance, renderState, styleProp, projection) {
37
51
  renderHTML(instance, renderState, styleProp, projection);
38
52
  }
@@ -22,7 +22,7 @@ function updateMotionValuesFromProps(element, next, prev) {
22
22
  * and warn against mismatches.
23
23
  */
24
24
  if (process.env.NODE_ENV === "development") {
25
- warnOnce(nextValue.version === "8.2.4", `Attempting to mix Framer Motion versions ${nextValue.version} with 8.2.4 may not work as expected.`);
25
+ warnOnce(nextValue.version === "8.3.1", `Attempting to mix Framer Motion versions ${nextValue.version} with 8.3.1 may not work as expected.`);
26
26
  }
27
27
  }
28
28
  else if (isMotionValue(prevValue)) {
@@ -25,7 +25,7 @@ class MotionValue {
25
25
  * This will be replaced by the build step with the latest version number.
26
26
  * When MotionValues are provided to motion components, warn if versions are mixed.
27
27
  */
28
- this.version = "8.2.4";
28
+ this.version = "8.3.1";
29
29
  /**
30
30
  * Duration, in milliseconds, since last updating frame.
31
31
  *
@@ -1055,10 +1055,20 @@
1055
1055
  ...visualProps,
1056
1056
  ref,
1057
1057
  };
1058
+ /**
1059
+ * If component has been handed a motion value as its child,
1060
+ * memoise its initial value and render that. Subsequent updates
1061
+ * will be handled by the onChange handler
1062
+ */
1063
+ const { children } = props;
1064
+ const renderedChildren = React.useMemo(() => (isMotionValue(children) ? children.get() : children), [children]);
1058
1065
  if (projectionId) {
1059
1066
  elementProps["data-projection-id"] = projectionId;
1060
1067
  }
1061
- return React.createElement(Component, elementProps);
1068
+ return React.createElement(Component, {
1069
+ ...elementProps,
1070
+ children: renderedChildren,
1071
+ });
1062
1072
  };
1063
1073
  return useRender;
1064
1074
  }
@@ -1535,6 +1545,7 @@
1535
1545
  return !isDragActive();
1536
1546
  }
1537
1547
  function onPointerUp(event, info) {
1548
+ var _a, _b, _c, _d;
1538
1549
  if (!checkPointerEnd())
1539
1550
  return;
1540
1551
  /**
@@ -1542,15 +1553,17 @@
1542
1553
  * as, or a child of, this component's element
1543
1554
  */
1544
1555
  !isNodeOrChild(visualElement.current, event.target)
1545
- ? onTapCancel && onTapCancel(event, info)
1546
- : onTap && onTap(event, info);
1556
+ ? (_b = (_a = visualElement.getProps()).onTapCancel) === null || _b === void 0 ? void 0 : _b.call(_a, event, info)
1557
+ : (_d = (_c = visualElement.getProps()).onTap) === null || _d === void 0 ? void 0 : _d.call(_c, event, info);
1547
1558
  }
1548
1559
  function onPointerCancel(event, info) {
1560
+ var _a, _b;
1549
1561
  if (!checkPointerEnd())
1550
1562
  return;
1551
- onTapCancel && onTapCancel(event, info);
1563
+ (_b = (_a = visualElement.getProps()).onTapCancel) === null || _b === void 0 ? void 0 : _b.call(_a, event, info);
1552
1564
  }
1553
1565
  const startPress = React.useCallback((event, info) => {
1566
+ var _a, _b;
1554
1567
  removePointerEndListener();
1555
1568
  if (isPressing.current)
1556
1569
  return;
@@ -1561,8 +1574,8 @@
1561
1574
  */
1562
1575
  visualElement.animationState &&
1563
1576
  visualElement.animationState.setActive(exports.AnimationType.Tap, true);
1564
- onTapStart && onTapStart(event, info);
1565
- }, [onTapStart, visualElement]);
1577
+ (_b = (_a = visualElement.getProps()).onTapStart) === null || _b === void 0 ? void 0 : _b.call(_a, event, info);
1578
+ }, [Boolean(onTapStart), visualElement]);
1566
1579
  usePointerEvent(visualElement, "pointerdown", hasPressListeners ? startPress : undefined, eventOptions);
1567
1580
  useUnmountEffect(removePointerEndListener);
1568
1581
  }
@@ -2060,7 +2073,7 @@
2060
2073
  * This will be replaced by the build step with the latest version number.
2061
2074
  * When MotionValues are provided to motion components, warn if versions are mixed.
2062
2075
  */
2063
- this.version = "8.2.4";
2076
+ this.version = "8.3.1";
2064
2077
  /**
2065
2078
  * Duration, in milliseconds, since last updating frame.
2066
2079
  *
@@ -5931,7 +5944,7 @@
5931
5944
  * and warn against mismatches.
5932
5945
  */
5933
5946
  {
5934
- warnOnce(nextValue.version === "8.2.4", `Attempting to mix Framer Motion versions ${nextValue.version} with 8.2.4 may not work as expected.`);
5947
+ warnOnce(nextValue.version === "8.3.1", `Attempting to mix Framer Motion versions ${nextValue.version} with 8.3.1 may not work as expected.`);
5935
5948
  }
5936
5949
  }
5937
5950
  else if (isMotionValue(prevValue)) {
@@ -6160,7 +6173,7 @@
6160
6173
  return 0;
6161
6174
  return this.sortInstanceNodePosition(this.current, other.current);
6162
6175
  }
6163
- loadFeatures(renderedProps, isStrict, preloadedFeatures, projectionId, ProjectionNodeConstructor, initialLayoutGroupConfig) {
6176
+ loadFeatures({ children, ...renderedProps }, isStrict, preloadedFeatures, projectionId, ProjectionNodeConstructor, initialLayoutGroupConfig) {
6164
6177
  const features = [];
6165
6178
  /**
6166
6179
  * If we're in development mode, check to make sure we're not rendering a motion component
@@ -6264,6 +6277,9 @@
6264
6277
  }
6265
6278
  }
6266
6279
  this.prevMotionValues = updateMotionValuesFromProps(this, this.scrapeMotionValuesFromProps(props, prevProps), this.prevMotionValues);
6280
+ if (this.handleChildMotionValue) {
6281
+ this.handleChildMotionValue();
6282
+ }
6267
6283
  }
6268
6284
  getProps() {
6269
6285
  return this.props;
@@ -6493,6 +6509,19 @@
6493
6509
  scrapeMotionValuesFromProps(props, prevProps) {
6494
6510
  return scrapeMotionValuesFromProps$1(props, prevProps);
6495
6511
  }
6512
+ handleChildMotionValue() {
6513
+ if (this.childSubscription) {
6514
+ this.childSubscription();
6515
+ delete this.childSubscription;
6516
+ }
6517
+ const { children } = this.props;
6518
+ if (isMotionValue(children)) {
6519
+ this.childSubscription = children.on("change", (latest) => {
6520
+ if (this.current)
6521
+ this.current.textContent = `${latest}`;
6522
+ });
6523
+ }
6524
+ }
6496
6525
  renderInstance(instance, renderState, styleProp, projection) {
6497
6526
  renderHTML(instance, renderState, styleProp, projection);
6498
6527
  }