framer-motion 7.0.3 → 7.1.2
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 +2090 -2304
- package/dist/es/animation/animate.mjs +4 -5
- package/dist/es/animation/animation-controls.mjs +22 -24
- package/dist/es/animation/use-animated-state.mjs +23 -25
- package/dist/es/animation/use-animation.mjs +2 -2
- package/dist/es/animation/utils/default-transitions.mjs +13 -14
- package/dist/es/animation/utils/easing.mjs +20 -21
- package/dist/es/animation/utils/is-animatable.mjs +1 -1
- package/dist/es/animation/utils/is-keyframes-target.mjs +1 -1
- package/dist/es/animation/utils/transitions.mjs +30 -31
- package/dist/es/components/AnimatePresence/PresenceChild.mjs +18 -31
- package/dist/es/components/AnimatePresence/index.mjs +33 -35
- package/dist/es/components/AnimatePresence/use-presence.mjs +5 -5
- package/dist/es/components/AnimateSharedLayout.mjs +4 -5
- package/dist/es/components/LayoutGroup/index.mjs +12 -16
- package/dist/es/components/LazyMotion/index.mjs +9 -10
- package/dist/es/components/MotionConfig/index.mjs +5 -5
- package/dist/es/components/Reorder/Group.mjs +16 -16
- package/dist/es/components/Reorder/Item.mjs +14 -18
- package/dist/es/components/Reorder/index.mjs +3 -3
- package/dist/es/components/Reorder/utils/check-reorder.mjs +6 -6
- package/dist/es/context/DeprecatedLayoutGroupContext.mjs +1 -1
- package/dist/es/context/LayoutGroupContext.mjs +1 -1
- package/dist/es/context/LazyContext.mjs +1 -1
- package/dist/es/context/MotionConfigContext.mjs +2 -2
- package/dist/es/context/MotionContext/create.mjs +2 -2
- package/dist/es/context/MotionContext/index.mjs +1 -1
- package/dist/es/context/MotionContext/utils.mjs +1 -1
- package/dist/es/context/PresenceContext.mjs +1 -1
- package/dist/es/context/ReorderContext.mjs +1 -1
- package/dist/es/context/SwitchLayoutGroupContext.mjs +1 -1
- package/dist/es/events/event-info.mjs +11 -17
- package/dist/es/events/use-dom-event.mjs +4 -5
- package/dist/es/events/use-pointer-event.mjs +2 -2
- package/dist/es/events/utils.mjs +3 -9
- package/dist/es/gestures/PanSession.mjs +42 -47
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +147 -157
- package/dist/es/gestures/drag/use-drag-controls.mjs +10 -12
- package/dist/es/gestures/drag/use-drag.mjs +4 -4
- package/dist/es/gestures/drag/utils/constraints.mjs +12 -17
- package/dist/es/gestures/drag/utils/lock.mjs +17 -17
- package/dist/es/gestures/use-focus-gesture.mjs +3 -4
- package/dist/es/gestures/use-hover-gesture.mjs +2 -3
- package/dist/es/gestures/use-pan-gesture.mjs +9 -10
- package/dist/es/gestures/use-tap-gesture.mjs +5 -6
- package/dist/es/gestures/utils/event-type.mjs +1 -1
- package/dist/es/gestures/utils/is-node-or-child.mjs +1 -1
- package/dist/es/index.mjs +1 -0
- package/dist/es/motion/features/animations.mjs +9 -11
- package/dist/es/motion/features/definitions.mjs +5 -5
- package/dist/es/motion/features/drag.mjs +1 -1
- package/dist/es/motion/features/gestures.mjs +1 -1
- package/dist/es/motion/features/layout/MeasureLayout.mjs +32 -40
- package/dist/es/motion/features/layout/index.mjs +1 -1
- package/dist/es/motion/features/use-features.mjs +8 -9
- package/dist/es/motion/features/use-projection.mjs +10 -11
- package/dist/es/motion/features/viewport/observers.mjs +12 -12
- package/dist/es/motion/features/viewport/use-viewport.mjs +17 -20
- package/dist/es/motion/index.mjs +13 -16
- package/dist/es/motion/utils/VisualElementHandler.mjs +10 -16
- package/dist/es/motion/utils/is-forced-motion-value.mjs +1 -2
- package/dist/es/motion/utils/make-renderless-component.mjs +2 -2
- package/dist/es/motion/utils/use-motion-ref.mjs +1 -1
- package/dist/es/motion/utils/use-visual-element.mjs +13 -13
- package/dist/es/motion/utils/use-visual-state.mjs +26 -31
- package/dist/es/motion/utils/valid-prop.mjs +1 -1
- package/dist/es/projection/animation/mix-values.mjs +12 -16
- package/dist/es/projection/geometry/conversion.mjs +4 -6
- package/dist/es/projection/geometry/delta-apply.mjs +14 -20
- package/dist/es/projection/geometry/delta-calc.mjs +2 -5
- package/dist/es/projection/geometry/delta-remove.mjs +6 -13
- package/dist/es/projection/geometry/models.mjs +7 -7
- package/dist/es/projection/node/DocumentProjectionNode.mjs +5 -5
- package/dist/es/projection/node/HTMLProjectionNode.mjs +8 -10
- package/dist/es/projection/node/create-projection-node.mjs +283 -307
- package/dist/es/projection/node/group.mjs +6 -8
- package/dist/es/projection/node/id.mjs +2 -2
- package/dist/es/projection/node/state.mjs +1 -1
- package/dist/es/projection/shared/stack.mjs +26 -27
- package/dist/es/projection/styles/scale-border-radius.mjs +5 -5
- package/dist/es/projection/styles/scale-box-shadow.mjs +18 -19
- package/dist/es/projection/styles/scale-correction.mjs +1 -1
- package/dist/es/projection/styles/transform.mjs +12 -12
- package/dist/es/projection/use-reset-projection.mjs +2 -2
- package/dist/es/projection/utils/has-transform.mjs +1 -2
- package/dist/es/projection/utils/measure.mjs +2 -2
- package/dist/es/render/dom/create-visual-element.mjs +1 -1
- package/dist/es/render/dom/features-animation.mjs +1 -2
- package/dist/es/render/dom/features-max.mjs +1 -2
- package/dist/es/render/dom/motion-minimal.mjs +1 -1
- package/dist/es/render/dom/motion-proxy.mjs +3 -4
- package/dist/es/render/dom/motion.mjs +2 -5
- package/dist/es/render/dom/use-render.mjs +6 -9
- package/dist/es/render/dom/utils/camel-to-dash.mjs +3 -5
- package/dist/es/render/dom/utils/create-config.mjs +5 -5
- package/dist/es/render/dom/utils/css-variables-conversion.mjs +19 -20
- package/dist/es/render/dom/utils/filter-props.mjs +4 -6
- package/dist/es/render/dom/utils/parse-dom-variant.mjs +2 -2
- package/dist/es/render/dom/utils/unit-conversion.mjs +68 -99
- package/dist/es/render/dom/value-types/animatable-none.mjs +1 -1
- package/dist/es/render/dom/value-types/defaults.mjs +4 -5
- package/dist/es/render/dom/value-types/dimensions.mjs +2 -4
- package/dist/es/render/dom/value-types/find.mjs +2 -3
- package/dist/es/render/dom/value-types/get-as-type.mjs +1 -1
- package/dist/es/render/dom/value-types/number.mjs +2 -2
- package/dist/es/render/dom/value-types/test.mjs +1 -1
- package/dist/es/render/dom/value-types/type-auto.mjs +3 -3
- package/dist/es/render/dom/value-types/type-int.mjs +1 -2
- package/dist/es/render/html/config-motion.mjs +1 -1
- package/dist/es/render/html/use-props.mjs +11 -13
- package/dist/es/render/html/utils/build-styles.mjs +8 -8
- package/dist/es/render/html/utils/build-transform.mjs +11 -16
- package/dist/es/render/html/utils/create-render-state.mjs +2 -2
- package/dist/es/render/html/utils/render.mjs +2 -3
- package/dist/es/render/html/utils/scrape-motion-values.mjs +3 -3
- package/dist/es/render/html/utils/transform.mjs +6 -10
- package/dist/es/render/html/visual-element.mjs +22 -23
- package/dist/es/render/index.mjs +359 -364
- package/dist/es/render/svg/config-motion.mjs +2 -3
- package/dist/es/render/svg/lowercase-elements.mjs +1 -1
- package/dist/es/render/svg/use-props.mjs +5 -6
- package/dist/es/render/svg/utils/build-attrs.mjs +2 -2
- package/dist/es/render/svg/utils/camel-case-attrs.mjs +1 -1
- package/dist/es/render/svg/utils/create-render-state.mjs +1 -2
- package/dist/es/render/svg/utils/path.mjs +7 -10
- package/dist/es/render/svg/utils/render.mjs +1 -1
- package/dist/es/render/svg/utils/scrape-motion-values.mjs +3 -3
- package/dist/es/render/svg/utils/transform-origin.mjs +3 -3
- package/dist/es/render/svg/visual-element.mjs +6 -4
- package/dist/es/render/utils/animation-state.mjs +71 -87
- package/dist/es/render/utils/animation.mjs +48 -60
- package/dist/es/render/utils/compare-by-depth.mjs +1 -3
- package/dist/es/render/utils/flat-tree.mjs +9 -10
- package/dist/es/render/utils/lifecycles.mjs +12 -19
- package/dist/es/render/utils/motion-values.mjs +16 -8
- package/dist/es/render/utils/setters.mjs +19 -19
- package/dist/es/render/utils/variants.mjs +6 -8
- package/dist/es/utils/array.mjs +9 -10
- package/dist/es/utils/is-browser.mjs +1 -1
- package/dist/es/utils/is-numerical-string.mjs +1 -1
- package/dist/es/utils/is-zero-value-string.mjs +1 -1
- package/dist/es/utils/process.mjs +2 -2
- package/dist/es/utils/resolve-value.mjs +2 -2
- package/dist/es/utils/shallow-compare.mjs +2 -2
- package/dist/es/utils/subscription-manager.mjs +15 -17
- package/dist/es/utils/time-conversion.mjs +1 -1
- package/dist/es/utils/transform.mjs +10 -15
- package/dist/es/utils/use-animation-frame.mjs +5 -6
- package/dist/es/utils/use-constant.mjs +1 -1
- package/dist/es/utils/use-cycle.mjs +9 -10
- package/dist/es/utils/use-force-update.mjs +4 -5
- package/dist/es/utils/use-in-view.mjs +7 -9
- package/dist/es/utils/use-instant-transition-state.mjs +1 -1
- package/dist/es/utils/use-instant-transition.mjs +6 -9
- package/dist/es/utils/use-is-mounted.mjs +3 -3
- package/dist/es/utils/use-isomorphic-effect.mjs +1 -1
- package/dist/es/utils/use-reduced-motion.mjs +8 -11
- package/dist/es/utils/use-unmount-effect.mjs +1 -1
- package/dist/es/utils/warn-once.mjs +1 -1
- package/dist/es/value/index.mjs +53 -59
- package/dist/es/value/use-combine-values.mjs +3 -3
- package/dist/es/value/use-inverted-scale.mjs +9 -11
- package/dist/es/value/use-motion-template.mjs +5 -9
- package/dist/es/value/use-motion-value.mjs +4 -5
- package/dist/es/value/use-on-change.mjs +4 -4
- package/dist/es/value/use-scroll.mjs +9 -11
- package/dist/es/value/use-spring.mjs +8 -10
- package/dist/es/value/use-time.mjs +2 -2
- package/dist/es/value/use-transform.mjs +6 -10
- package/dist/es/value/use-velocity.mjs +3 -3
- package/dist/es/value/use-will-change/index.mjs +50 -0
- package/dist/es/value/use-will-change/is.mjs +7 -0
- package/dist/es/value/utils/is-motion-value.mjs +1 -1
- package/dist/es/value/utils/resolve-motion-value.mjs +1 -1
- package/dist/framer-motion.dev.js +2134 -2414
- package/dist/framer-motion.js +1 -1
- package/dist/index.d.ts +9 -2
- package/dist/projection.dev.js +1154 -1300
- package/dist/size-rollup-dom-animation.js +1 -1
- package/dist/size-rollup-dom-max.js +1 -1
- package/dist/size-rollup-m.js +1 -1
- package/dist/size-webpack-dom-animation.js +1 -1
- package/dist/size-webpack-dom-max.js +1 -1
- package/dist/size-webpack-m.js +1 -1
- package/dist/three-entry.d.ts +0 -1
- package/package.json +12 -12
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __read, __spreadArray } from 'tslib';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
import { useContext, useRef, cloneElement, Children, isValidElement } from 'react';
|
|
4
3
|
import { env } from '../../utils/process.mjs';
|
|
@@ -9,17 +8,17 @@ import { LayoutGroupContext } from '../../context/LayoutGroupContext.mjs';
|
|
|
9
8
|
import { useIsomorphicLayoutEffect } from '../../utils/use-isomorphic-effect.mjs';
|
|
10
9
|
import { useUnmountEffect } from '../../utils/use-unmount-effect.mjs';
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
const getChildKey = (child) => child.key || "";
|
|
13
12
|
function updateChildLookup(children, allChildren) {
|
|
14
|
-
children.forEach(
|
|
15
|
-
|
|
13
|
+
children.forEach((child) => {
|
|
14
|
+
const key = getChildKey(child);
|
|
16
15
|
allChildren.set(key, child);
|
|
17
16
|
});
|
|
18
17
|
}
|
|
19
18
|
function onlyElements(children) {
|
|
20
|
-
|
|
19
|
+
const filtered = [];
|
|
21
20
|
// We use forEach here instead of map as map mutates the component key by preprending `.$`
|
|
22
|
-
Children.forEach(children,
|
|
21
|
+
Children.forEach(children, (child) => {
|
|
23
22
|
if (isValidElement(child))
|
|
24
23
|
filtered.push(child);
|
|
25
24
|
});
|
|
@@ -58,50 +57,49 @@ function onlyElements(children) {
|
|
|
58
57
|
*
|
|
59
58
|
* @public
|
|
60
59
|
*/
|
|
61
|
-
|
|
62
|
-
var children = _a.children, custom = _a.custom, _b = _a.initial, initial = _b === void 0 ? true : _b, onExitComplete = _a.onExitComplete, exitBeforeEnter = _a.exitBeforeEnter, _c = _a.presenceAffectsLayout, presenceAffectsLayout = _c === void 0 ? true : _c;
|
|
60
|
+
const AnimatePresence = ({ children, custom, initial = true, onExitComplete, exitBeforeEnter, presenceAffectsLayout = true, }) => {
|
|
63
61
|
// We want to force a re-render once all exiting animations have finished. We
|
|
64
62
|
// either use a local forceRender function, or one from a parent context if it exists.
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
let [forceRender] = useForceUpdate();
|
|
64
|
+
const forceRenderLayoutGroup = useContext(LayoutGroupContext).forceRender;
|
|
67
65
|
if (forceRenderLayoutGroup)
|
|
68
66
|
forceRender = forceRenderLayoutGroup;
|
|
69
|
-
|
|
67
|
+
const isMounted = useIsMounted();
|
|
70
68
|
// Filter out any children that aren't ReactElements. We can only track ReactElements with a props.key
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
const filteredChildren = onlyElements(children);
|
|
70
|
+
let childrenToRender = filteredChildren;
|
|
71
|
+
const exiting = new Set();
|
|
74
72
|
// Keep a living record of the children we're actually rendering so we
|
|
75
73
|
// can diff to figure out which are entering and exiting
|
|
76
|
-
|
|
74
|
+
const presentChildren = useRef(childrenToRender);
|
|
77
75
|
// A lookup table to quickly reference components by key
|
|
78
|
-
|
|
76
|
+
const allChildren = useRef(new Map()).current;
|
|
79
77
|
// If this is the initial component render, just deal with logic surrounding whether
|
|
80
78
|
// we play onMount animations or not.
|
|
81
|
-
|
|
82
|
-
useIsomorphicLayoutEffect(
|
|
79
|
+
const isInitialRender = useRef(true);
|
|
80
|
+
useIsomorphicLayoutEffect(() => {
|
|
83
81
|
isInitialRender.current = false;
|
|
84
82
|
updateChildLookup(filteredChildren, allChildren);
|
|
85
83
|
presentChildren.current = childrenToRender;
|
|
86
84
|
});
|
|
87
|
-
useUnmountEffect(
|
|
85
|
+
useUnmountEffect(() => {
|
|
88
86
|
isInitialRender.current = true;
|
|
89
87
|
allChildren.clear();
|
|
90
88
|
exiting.clear();
|
|
91
89
|
});
|
|
92
90
|
if (isInitialRender.current) {
|
|
93
|
-
return (React.createElement(React.Fragment, null, childrenToRender.map(
|
|
91
|
+
return (React.createElement(React.Fragment, null, childrenToRender.map((child) => (React.createElement(PresenceChild, { key: getChildKey(child), isPresent: true, initial: initial ? undefined : false, presenceAffectsLayout: presenceAffectsLayout }, child)))));
|
|
94
92
|
}
|
|
95
93
|
// If this is a subsequent render, deal with entering and exiting children
|
|
96
|
-
childrenToRender =
|
|
94
|
+
childrenToRender = [...childrenToRender];
|
|
97
95
|
// Diff the keys of the currently-present and target children to update our
|
|
98
96
|
// exiting list.
|
|
99
|
-
|
|
100
|
-
|
|
97
|
+
const presentKeys = presentChildren.current.map(getChildKey);
|
|
98
|
+
const targetKeys = filteredChildren.map(getChildKey);
|
|
101
99
|
// Diff the present children with our target children and mark those that are exiting
|
|
102
|
-
|
|
103
|
-
for (
|
|
104
|
-
|
|
100
|
+
const numPresent = presentKeys.length;
|
|
101
|
+
for (let i = 0; i < numPresent; i++) {
|
|
102
|
+
const key = presentKeys[i];
|
|
105
103
|
if (targetKeys.indexOf(key) === -1) {
|
|
106
104
|
exiting.add(key);
|
|
107
105
|
}
|
|
@@ -113,19 +111,19 @@ var AnimatePresence = function (_a) {
|
|
|
113
111
|
}
|
|
114
112
|
// Loop through all currently exiting components and clone them to overwrite `animate`
|
|
115
113
|
// with any `exit` prop they might have defined.
|
|
116
|
-
exiting.forEach(
|
|
114
|
+
exiting.forEach((key) => {
|
|
117
115
|
// If this component is actually entering again, early return
|
|
118
116
|
if (targetKeys.indexOf(key) !== -1)
|
|
119
117
|
return;
|
|
120
|
-
|
|
118
|
+
const child = allChildren.get(key);
|
|
121
119
|
if (!child)
|
|
122
120
|
return;
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
const insertionIndex = presentKeys.indexOf(key);
|
|
122
|
+
const onExit = () => {
|
|
125
123
|
allChildren.delete(key);
|
|
126
124
|
exiting.delete(key);
|
|
127
125
|
// Remove this child from the present children
|
|
128
|
-
|
|
126
|
+
const removeIndex = presentChildren.current.findIndex((presentChild) => presentChild.key === key);
|
|
129
127
|
presentChildren.current.splice(removeIndex, 1);
|
|
130
128
|
// Defer re-rendering until all exiting children have indeed left
|
|
131
129
|
if (!exiting.size) {
|
|
@@ -140,18 +138,18 @@ var AnimatePresence = function (_a) {
|
|
|
140
138
|
});
|
|
141
139
|
// Add `MotionContext` even to children that don't need it to ensure we're rendering
|
|
142
140
|
// the same tree between renders
|
|
143
|
-
childrenToRender = childrenToRender.map(
|
|
144
|
-
|
|
141
|
+
childrenToRender = childrenToRender.map((child) => {
|
|
142
|
+
const key = child.key;
|
|
145
143
|
return exiting.has(key) ? (child) : (React.createElement(PresenceChild, { key: getChildKey(child), isPresent: true, presenceAffectsLayout: presenceAffectsLayout }, child));
|
|
146
144
|
});
|
|
147
145
|
if (env !== "production" &&
|
|
148
146
|
exitBeforeEnter &&
|
|
149
147
|
childrenToRender.length > 1) {
|
|
150
|
-
console.warn(
|
|
148
|
+
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.`);
|
|
151
149
|
}
|
|
152
150
|
return (React.createElement(React.Fragment, null, exiting.size
|
|
153
151
|
? childrenToRender
|
|
154
|
-
: childrenToRender.map(
|
|
152
|
+
: childrenToRender.map((child) => cloneElement(child))));
|
|
155
153
|
};
|
|
156
154
|
|
|
157
155
|
export { AnimatePresence };
|
|
@@ -25,16 +25,16 @@ import { PresenceContext } from '../../context/PresenceContext.mjs';
|
|
|
25
25
|
* @public
|
|
26
26
|
*/
|
|
27
27
|
function usePresence() {
|
|
28
|
-
|
|
28
|
+
const context = useContext(PresenceContext);
|
|
29
29
|
if (context === null)
|
|
30
30
|
return [true, null];
|
|
31
|
-
|
|
31
|
+
const { isPresent, onExitComplete, register } = context;
|
|
32
32
|
// It's safe to call the following hooks conditionally (after an early return) because the context will always
|
|
33
33
|
// either be null or non-null for the lifespan of the component.
|
|
34
34
|
// Replace with useId when released in React
|
|
35
|
-
|
|
36
|
-
useEffect(
|
|
37
|
-
|
|
35
|
+
const id = useId();
|
|
36
|
+
useEffect(() => register(id), []);
|
|
37
|
+
const safeToRemove = () => onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete(id);
|
|
38
38
|
return !isPresent && onExitComplete ? [false, safeToRemove] : [true];
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
@@ -3,13 +3,12 @@ import * as React from 'react';
|
|
|
3
3
|
import { useConstant } from '../utils/use-constant.mjs';
|
|
4
4
|
import { LayoutGroup } from './LayoutGroup/index.mjs';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
React.useEffect(function () {
|
|
6
|
+
let id = 0;
|
|
7
|
+
const AnimateSharedLayout = ({ children, }) => {
|
|
8
|
+
React.useEffect(() => {
|
|
10
9
|
warning(false, "AnimateSharedLayout is deprecated: https://www.framer.com/docs/guide-upgrade/##shared-layout-animations");
|
|
11
10
|
}, []);
|
|
12
|
-
return (React.createElement(LayoutGroup, { id: useConstant(
|
|
11
|
+
return (React.createElement(LayoutGroup, { id: useConstant(() => `asl-${id++}`) }, children));
|
|
13
12
|
};
|
|
14
13
|
|
|
15
14
|
export { AnimateSharedLayout };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __read, __assign } from 'tslib';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
import { useContext, useRef, useMemo } from 'react';
|
|
4
3
|
import { LayoutGroupContext } from '../../context/LayoutGroupContext.mjs';
|
|
@@ -6,33 +5,30 @@ import { DeprecatedLayoutGroupContext } from '../../context/DeprecatedLayoutGrou
|
|
|
6
5
|
import { useForceUpdate } from '../../utils/use-force-update.mjs';
|
|
7
6
|
import { nodeGroup } from '../../projection/node/group.mjs';
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var LayoutGroup = function (_a) {
|
|
14
|
-
var _b, _c;
|
|
15
|
-
var children = _a.children, id = _a.id, inheritId = _a.inheritId, _d = _a.inherit, inherit = _d === void 0 ? true : _d;
|
|
8
|
+
const shouldInheritGroup = (inherit) => inherit === true;
|
|
9
|
+
const shouldInheritId = (inherit) => shouldInheritGroup(inherit === true) || inherit === "id";
|
|
10
|
+
const LayoutGroup = ({ children, id, inheritId, inherit = true, }) => {
|
|
11
|
+
var _a, _b;
|
|
16
12
|
// Maintain backwards-compatibility with inheritId until 7.0
|
|
17
13
|
if (inheritId !== undefined)
|
|
18
14
|
inherit = inheritId;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
const layoutGroupContext = useContext(LayoutGroupContext);
|
|
16
|
+
const deprecatedLayoutGroupContext = useContext(DeprecatedLayoutGroupContext);
|
|
17
|
+
const [forceRender, key] = useForceUpdate();
|
|
18
|
+
const context = useRef(null);
|
|
19
|
+
const upstreamId = (_a = layoutGroupContext.id) !== null && _a !== void 0 ? _a : deprecatedLayoutGroupContext;
|
|
24
20
|
if (context.current === null) {
|
|
25
21
|
if (shouldInheritId(inherit) && upstreamId) {
|
|
26
22
|
id = id ? upstreamId + "-" + id : upstreamId;
|
|
27
23
|
}
|
|
28
24
|
context.current = {
|
|
29
|
-
id
|
|
25
|
+
id,
|
|
30
26
|
group: shouldInheritGroup(inherit)
|
|
31
|
-
? (
|
|
27
|
+
? (_b = layoutGroupContext === null || layoutGroupContext === void 0 ? void 0 : layoutGroupContext.group) !== null && _b !== void 0 ? _b : nodeGroup()
|
|
32
28
|
: nodeGroup(),
|
|
33
29
|
};
|
|
34
30
|
}
|
|
35
|
-
|
|
31
|
+
const memoizedContext = useMemo(() => (Object.assign(Object.assign({}, context.current), { forceRender })), [key]);
|
|
36
32
|
return (React.createElement(LayoutGroupContext.Provider, { value: memoizedContext }, children));
|
|
37
33
|
};
|
|
38
34
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __rest } from 'tslib';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { useState, useRef, useEffect } from 'react';
|
|
4
4
|
import { LazyContext } from '../../context/LazyContext.mjs';
|
|
@@ -39,29 +39,28 @@ import { loadFeatures } from '../../motion/features/definitions.mjs';
|
|
|
39
39
|
*
|
|
40
40
|
* @public
|
|
41
41
|
*/
|
|
42
|
-
function LazyMotion(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
var loadedRenderer = useRef(undefined);
|
|
42
|
+
function LazyMotion({ children, features, strict = false }) {
|
|
43
|
+
const [, setIsLoaded] = useState(!isLazyBundle(features));
|
|
44
|
+
const loadedRenderer = useRef(undefined);
|
|
46
45
|
/**
|
|
47
46
|
* If this is a synchronous load, load features immediately
|
|
48
47
|
*/
|
|
49
48
|
if (!isLazyBundle(features)) {
|
|
50
|
-
|
|
49
|
+
const { renderer } = features, loadedFeatures = __rest(features, ["renderer"]);
|
|
51
50
|
loadedRenderer.current = renderer;
|
|
52
51
|
loadFeatures(loadedFeatures);
|
|
53
52
|
}
|
|
54
|
-
useEffect(
|
|
53
|
+
useEffect(() => {
|
|
55
54
|
if (isLazyBundle(features)) {
|
|
56
|
-
features().then(
|
|
57
|
-
var renderer = _a
|
|
55
|
+
features().then((_a) => {
|
|
56
|
+
var { renderer } = _a, loadedFeatures = __rest(_a, ["renderer"]);
|
|
58
57
|
loadFeatures(loadedFeatures);
|
|
59
58
|
loadedRenderer.current = renderer;
|
|
60
59
|
setIsLoaded(true);
|
|
61
60
|
});
|
|
62
61
|
}
|
|
63
62
|
}, []);
|
|
64
|
-
return (React.createElement(LazyContext.Provider, { value: { renderer: loadedRenderer.current, strict
|
|
63
|
+
return (React.createElement(LazyContext.Provider, { value: { renderer: loadedRenderer.current, strict } }, children));
|
|
65
64
|
}
|
|
66
65
|
function isLazyBundle(features) {
|
|
67
66
|
return typeof features === "function";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __rest
|
|
1
|
+
import { __rest } from 'tslib';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { useContext, useMemo } from 'react';
|
|
4
4
|
import { MotionConfigContext } from '../../context/MotionConfigContext.mjs';
|
|
@@ -23,22 +23,22 @@ import { useConstant } from '../../utils/use-constant.mjs';
|
|
|
23
23
|
* @public
|
|
24
24
|
*/
|
|
25
25
|
function MotionConfig(_a) {
|
|
26
|
-
var
|
|
26
|
+
var { children, isValidProp } = _a, config = __rest(_a, ["children", "isValidProp"]);
|
|
27
27
|
isValidProp && loadExternalIsValidProp(isValidProp);
|
|
28
28
|
/**
|
|
29
29
|
* Inherit props from any parent MotionConfig components
|
|
30
30
|
*/
|
|
31
|
-
config =
|
|
31
|
+
config = Object.assign(Object.assign({}, useContext(MotionConfigContext)), config);
|
|
32
32
|
/**
|
|
33
33
|
* Don't allow isStatic to change between renders as it affects how many hooks
|
|
34
34
|
* motion components fire.
|
|
35
35
|
*/
|
|
36
|
-
config.isStatic = useConstant(
|
|
36
|
+
config.isStatic = useConstant(() => config.isStatic);
|
|
37
37
|
/**
|
|
38
38
|
* Creating a new config context object will re-render every `motion` component
|
|
39
39
|
* every time it renders. So we only want to create a new one sparingly.
|
|
40
40
|
*/
|
|
41
|
-
|
|
41
|
+
const context = useMemo(() => config, [JSON.stringify(config.transition), config.transformPagePoint, config.reducedMotion]);
|
|
42
42
|
return (React.createElement(MotionConfigContext.Provider, { value: context }, children));
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __rest
|
|
1
|
+
import { __rest } from 'tslib';
|
|
2
2
|
import { invariant } from 'hey-listen';
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { forwardRef, useRef, useEffect } from 'react';
|
|
@@ -8,42 +8,42 @@ import { useConstant } from '../../utils/use-constant.mjs';
|
|
|
8
8
|
import { checkReorder } from './utils/check-reorder.mjs';
|
|
9
9
|
|
|
10
10
|
function ReorderGroup(_a, externalRef) {
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
var { children, as = "ul", axis = "y", onReorder, values } = _a, props = __rest(_a, ["children", "as", "axis", "onReorder", "values"]);
|
|
12
|
+
const Component = useConstant(() => motion(as));
|
|
13
|
+
const order = [];
|
|
14
|
+
const isReordering = useRef(false);
|
|
15
15
|
invariant(Boolean(values), "Reorder.Group must be provided a values prop");
|
|
16
|
-
|
|
17
|
-
axis
|
|
18
|
-
registerItem:
|
|
16
|
+
const context = {
|
|
17
|
+
axis,
|
|
18
|
+
registerItem: (value, layout) => {
|
|
19
19
|
/**
|
|
20
20
|
* Ensure entries can't add themselves more than once
|
|
21
21
|
*/
|
|
22
22
|
if (layout &&
|
|
23
|
-
order.findIndex(
|
|
24
|
-
order.push({ value
|
|
23
|
+
order.findIndex((entry) => value === entry.value) === -1) {
|
|
24
|
+
order.push({ value, layout: layout[axis] });
|
|
25
25
|
order.sort(compareMin);
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
|
-
updateOrder:
|
|
28
|
+
updateOrder: (id, offset, velocity) => {
|
|
29
29
|
if (isReordering.current)
|
|
30
30
|
return;
|
|
31
|
-
|
|
31
|
+
const newOrder = checkReorder(order, id, offset, velocity);
|
|
32
32
|
if (order !== newOrder) {
|
|
33
33
|
isReordering.current = true;
|
|
34
34
|
onReorder(newOrder
|
|
35
35
|
.map(getValue)
|
|
36
|
-
.filter(
|
|
36
|
+
.filter((value) => values.indexOf(value) !== -1));
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
};
|
|
40
|
-
useEffect(
|
|
40
|
+
useEffect(() => {
|
|
41
41
|
isReordering.current = false;
|
|
42
42
|
});
|
|
43
|
-
return (React.createElement(Component,
|
|
43
|
+
return (React.createElement(Component, Object.assign({}, props, { ref: externalRef }),
|
|
44
44
|
React.createElement(ReorderContext.Provider, { value: context }, children)));
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
const Group = forwardRef(ReorderGroup);
|
|
47
47
|
function getValue(item) {
|
|
48
48
|
return item.value;
|
|
49
49
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __rest
|
|
1
|
+
import { __rest } from 'tslib';
|
|
2
2
|
import { invariant } from 'hey-listen';
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { forwardRef, useContext, useRef, useEffect } from 'react';
|
|
@@ -9,37 +9,33 @@ import { useMotionValue } from '../../value/use-motion-value.mjs';
|
|
|
9
9
|
import { useTransform } from '../../value/use-transform.mjs';
|
|
10
10
|
import { isMotionValue } from '../../value/utils/is-motion-value.mjs';
|
|
11
11
|
|
|
12
|
-
function useDefaultMotionValue(value, defaultValue) {
|
|
13
|
-
if (defaultValue === void 0) { defaultValue = 0; }
|
|
12
|
+
function useDefaultMotionValue(value, defaultValue = 0) {
|
|
14
13
|
return isMotionValue(value) ? value : useMotionValue(defaultValue);
|
|
15
14
|
}
|
|
16
15
|
function ReorderItem(_a, externalRef) {
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
var { children, style, value, as = "li", onDrag, layout = true } = _a, props = __rest(_a, ["children", "style", "value", "as", "onDrag", "layout"]);
|
|
17
|
+
const Component = useConstant(() => motion(as));
|
|
18
|
+
const context = useContext(ReorderContext);
|
|
19
|
+
const point = {
|
|
21
20
|
x: useDefaultMotionValue(style === null || style === void 0 ? void 0 : style.x),
|
|
22
21
|
y: useDefaultMotionValue(style === null || style === void 0 ? void 0 : style.y),
|
|
23
22
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return latestX || latestY ? 1 : "unset";
|
|
27
|
-
});
|
|
28
|
-
var measuredLayout = useRef(null);
|
|
23
|
+
const zIndex = useTransform([point.x, point.y], ([latestX, latestY]) => latestX || latestY ? 1 : "unset");
|
|
24
|
+
const measuredLayout = useRef(null);
|
|
29
25
|
invariant(Boolean(context), "Reorder.Item must be a child of Reorder.Group");
|
|
30
|
-
|
|
31
|
-
useEffect(
|
|
26
|
+
const { axis, registerItem, updateOrder } = context;
|
|
27
|
+
useEffect(() => {
|
|
32
28
|
registerItem(value, measuredLayout.current);
|
|
33
29
|
}, [context]);
|
|
34
|
-
return (React.createElement(Component,
|
|
35
|
-
|
|
30
|
+
return (React.createElement(Component, Object.assign({ drag: axis }, props, { dragSnapToOrigin: true, style: Object.assign(Object.assign({}, style), { x: point.x, y: point.y, zIndex }), layout: layout, onDrag: (event, gesturePoint) => {
|
|
31
|
+
const { velocity } = gesturePoint;
|
|
36
32
|
velocity[axis] &&
|
|
37
33
|
updateOrder(value, point[axis].get(), velocity[axis]);
|
|
38
34
|
onDrag === null || onDrag === void 0 ? void 0 : onDrag(event, gesturePoint);
|
|
39
|
-
}, onLayoutMeasure:
|
|
35
|
+
}, onLayoutMeasure: (measured) => {
|
|
40
36
|
measuredLayout.current = measured;
|
|
41
37
|
}, ref: externalRef }), children));
|
|
42
38
|
}
|
|
43
|
-
|
|
39
|
+
const Item = forwardRef(ReorderItem);
|
|
44
40
|
|
|
45
41
|
export { Item, ReorderItem };
|
|
@@ -4,16 +4,16 @@ import { moveItem } from '../../../utils/array.mjs';
|
|
|
4
4
|
function checkReorder(order, value, offset, velocity) {
|
|
5
5
|
if (!velocity)
|
|
6
6
|
return order;
|
|
7
|
-
|
|
7
|
+
const index = order.findIndex((item) => item.value === value);
|
|
8
8
|
if (index === -1)
|
|
9
9
|
return order;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const nextOffset = velocity > 0 ? 1 : -1;
|
|
11
|
+
const nextItem = order[index + nextOffset];
|
|
12
12
|
if (!nextItem)
|
|
13
13
|
return order;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const item = order[index];
|
|
15
|
+
const nextLayout = nextItem.layout;
|
|
16
|
+
const nextItemCenter = mix(nextLayout.min, nextLayout.max, 0.5);
|
|
17
17
|
if ((nextOffset === 1 && item.layout.max + offset > nextItemCenter) ||
|
|
18
18
|
(nextOffset === -1 && item.layout.min + offset < nextItemCenter)) {
|
|
19
19
|
return moveItem(order, index, index + nextOffset);
|
|
@@ -3,8 +3,8 @@ import { createContext } from 'react';
|
|
|
3
3
|
/**
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
transformPagePoint:
|
|
6
|
+
const MotionConfigContext = createContext({
|
|
7
|
+
transformPagePoint: (p) => p,
|
|
8
8
|
isStatic: false,
|
|
9
9
|
reducedMotion: "never",
|
|
10
10
|
});
|
|
@@ -3,8 +3,8 @@ import { MotionContext } from './index.mjs';
|
|
|
3
3
|
import { getCurrentTreeVariants } from './utils.mjs';
|
|
4
4
|
|
|
5
5
|
function useCreateMotionContext(props) {
|
|
6
|
-
|
|
7
|
-
return useMemo(
|
|
6
|
+
const { initial, animate } = getCurrentTreeVariants(props, useContext(MotionContext));
|
|
7
|
+
return useMemo(() => ({ initial, animate }), [variantLabelsAsDependency(initial), variantLabelsAsDependency(animate)]);
|
|
8
8
|
}
|
|
9
9
|
function variantLabelsAsDependency(prop) {
|
|
10
10
|
return Array.isArray(prop) ? prop.join(" ") : prop;
|
|
@@ -2,7 +2,7 @@ import { checkIfControllingVariants, isVariantLabel } from '../../render/utils/v
|
|
|
2
2
|
|
|
3
3
|
function getCurrentTreeVariants(props, context) {
|
|
4
4
|
if (checkIfControllingVariants(props)) {
|
|
5
|
-
|
|
5
|
+
const { initial, animate } = props;
|
|
6
6
|
return {
|
|
7
7
|
initial: initial === false || isVariantLabel(initial)
|
|
8
8
|
? initial
|
|
@@ -5,45 +5,39 @@ import { isTouchEvent } from '../gestures/utils/event-type.mjs';
|
|
|
5
5
|
* @param eventHandler
|
|
6
6
|
*/
|
|
7
7
|
function filterPrimaryPointer(eventHandler) {
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
return (event) => {
|
|
9
|
+
const isMouseEvent = event instanceof MouseEvent;
|
|
10
|
+
const isPrimaryPointer = !isMouseEvent ||
|
|
11
11
|
(isMouseEvent && event.button === 0);
|
|
12
12
|
if (isPrimaryPointer) {
|
|
13
13
|
eventHandler(event);
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
function pointFromTouch(e, pointType) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var point = primaryTouch || defaultPagePoint;
|
|
17
|
+
const defaultPagePoint = { pageX: 0, pageY: 0 };
|
|
18
|
+
function pointFromTouch(e, pointType = "page") {
|
|
19
|
+
const primaryTouch = e.touches[0] || e.changedTouches[0];
|
|
20
|
+
const point = primaryTouch || defaultPagePoint;
|
|
22
21
|
return {
|
|
23
22
|
x: point[pointType + "X"],
|
|
24
23
|
y: point[pointType + "Y"],
|
|
25
24
|
};
|
|
26
25
|
}
|
|
27
|
-
function pointFromMouse(point, pointType) {
|
|
28
|
-
if (pointType === void 0) { pointType = "page"; }
|
|
26
|
+
function pointFromMouse(point, pointType = "page") {
|
|
29
27
|
return {
|
|
30
28
|
x: point[pointType + "X"],
|
|
31
29
|
y: point[pointType + "Y"],
|
|
32
30
|
};
|
|
33
31
|
}
|
|
34
|
-
function extractEventInfo(event, pointType) {
|
|
35
|
-
if (pointType === void 0) { pointType = "page"; }
|
|
32
|
+
function extractEventInfo(event, pointType = "page") {
|
|
36
33
|
return {
|
|
37
34
|
point: isTouchEvent(event)
|
|
38
35
|
? pointFromTouch(event, pointType)
|
|
39
36
|
: pointFromMouse(event, pointType),
|
|
40
37
|
};
|
|
41
38
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var listener = function (event) {
|
|
45
|
-
return handler(event, extractEventInfo(event));
|
|
46
|
-
};
|
|
39
|
+
const wrapHandler = (handler, shouldFilterPrimaryPointer = false) => {
|
|
40
|
+
const listener = (event) => handler(event, extractEventInfo(event));
|
|
47
41
|
return shouldFilterPrimaryPointer
|
|
48
42
|
? filterPrimaryPointer(listener)
|
|
49
43
|
: listener;
|