@teamturing/react-kit 2.4.0 → 2.6.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.
- package/dist/core/Button/index.d.ts +1 -1
- package/dist/core/Dialog/index.d.ts +16 -0
- package/dist/core/DialogHandler/index.d.ts +13 -0
- package/dist/core/GradientText/index.d.ts +11 -12
- package/dist/core/Grid/index.d.ts +2 -2
- package/dist/core/IconButton/index.d.ts +1 -1
- package/dist/core/ItemList/index.d.ts +2 -2
- package/dist/core/MotionView/index.d.ts +3 -0
- package/dist/core/Spinner/index.d.ts +116 -116
- package/dist/core/Stack/index.d.ts +2 -2
- package/dist/core/TextInput/index.d.ts +39 -0
- package/dist/core/Textarea/index.d.ts +9 -0
- package/dist/hook/useDialogHandler.d.ts +6 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +10732 -593
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/isFunction.d.ts +1 -0
- package/esm/_virtual/index.js +3 -0
- package/esm/_virtual/react-is.development.js +3 -0
- package/esm/_virtual/react-is.production.min.js +3 -0
- package/esm/core/Dialog/index.js +188 -0
- package/esm/core/DialogHandler/index.js +33 -0
- package/esm/core/MotionView/index.js +6 -0
- package/esm/core/TextInput/index.js +220 -0
- package/esm/core/Textarea/index.js +158 -0
- package/esm/hook/useDialogHandler.js +14 -0
- package/esm/index.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/animation/animators/instant.js +40 -0
- package/esm/node_modules/framer-motion/dist/es/animation/animators/js/driver-frameloop.js +16 -0
- package/esm/node_modules/framer-motion/dist/es/animation/animators/js/index.js +303 -0
- package/esm/node_modules/framer-motion/dist/es/animation/animators/waapi/create-accelerated-animation.js +199 -0
- package/esm/node_modules/framer-motion/dist/es/animation/animators/waapi/easing.js +31 -0
- package/esm/node_modules/framer-motion/dist/es/animation/animators/waapi/index.js +23 -0
- package/esm/node_modules/framer-motion/dist/es/animation/animators/waapi/utils/get-final-keyframe.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/animation/generators/inertia.js +87 -0
- package/esm/node_modules/framer-motion/dist/es/animation/generators/keyframes.js +51 -0
- package/esm/node_modules/framer-motion/dist/es/animation/generators/spring/find.js +89 -0
- package/esm/node_modules/framer-motion/dist/es/animation/generators/spring/index.js +129 -0
- package/esm/node_modules/framer-motion/dist/es/animation/generators/utils/calc-duration.js +17 -0
- package/esm/node_modules/framer-motion/dist/es/animation/generators/utils/velocity.js +9 -0
- package/esm/node_modules/framer-motion/dist/es/animation/interfaces/motion-value.js +101 -0
- package/esm/node_modules/framer-motion/dist/es/animation/interfaces/single-value.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/animation/interfaces/visual-element-target.js +71 -0
- package/esm/node_modules/framer-motion/dist/es/animation/interfaces/visual-element-variant.js +63 -0
- package/esm/node_modules/framer-motion/dist/es/animation/interfaces/visual-element.js +24 -0
- package/esm/node_modules/framer-motion/dist/es/animation/optimized-appear/data-id.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/animation/utils/default-transitions.js +40 -0
- package/esm/node_modules/framer-motion/dist/es/animation/utils/is-animatable.js +30 -0
- package/esm/node_modules/framer-motion/dist/es/animation/utils/is-animation-controls.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/animation/utils/is-keyframes-target.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/animation/utils/is-none.js +12 -0
- package/esm/node_modules/framer-motion/dist/es/animation/utils/keyframes.js +45 -0
- package/esm/node_modules/framer-motion/dist/es/animation/utils/transitions.js +13 -0
- package/esm/node_modules/framer-motion/dist/es/components/AnimatePresence/PopChild.js +71 -0
- package/esm/node_modules/framer-motion/dist/es/components/AnimatePresence/PresenceChild.js +56 -0
- package/esm/node_modules/framer-motion/dist/es/components/AnimatePresence/index.js +158 -0
- package/esm/node_modules/framer-motion/dist/es/components/AnimatePresence/use-presence.js +40 -0
- package/esm/node_modules/framer-motion/dist/es/context/LayoutGroupContext.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/context/LazyContext.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/context/MotionConfigContext.js +12 -0
- package/esm/node_modules/framer-motion/dist/es/context/MotionContext/create.js +13 -0
- package/esm/node_modules/framer-motion/dist/es/context/MotionContext/index.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/context/MotionContext/utils.js +17 -0
- package/esm/node_modules/framer-motion/dist/es/context/PresenceContext.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/context/SwitchLayoutGroupContext.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/debug/record.js +7 -0
- package/esm/node_modules/framer-motion/dist/es/easing/anticipate.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/easing/back.js +9 -0
- package/esm/node_modules/framer-motion/dist/es/easing/circ.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/easing/cubic-bezier.js +51 -0
- package/esm/node_modules/framer-motion/dist/es/easing/ease.js +7 -0
- package/esm/node_modules/framer-motion/dist/es/easing/modifiers/mirror.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/easing/modifiers/reverse.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/easing/utils/is-bezier-definition.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/easing/utils/is-easing-array.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/easing/utils/map.js +37 -0
- package/esm/node_modules/framer-motion/dist/es/events/add-dom-event.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/events/add-pointer-event.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/events/event-info.js +15 -0
- package/esm/node_modules/framer-motion/dist/es/events/utils/is-primary-pointer.js +18 -0
- package/esm/node_modules/framer-motion/dist/es/frameloop/batcher.js +60 -0
- package/esm/node_modules/framer-motion/dist/es/frameloop/frame.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/frameloop/render-step.js +104 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/drag/VisualElementDragControls.js +457 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/drag/index.js +27 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/drag/utils/constraints.js +125 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/drag/utils/lock.js +53 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/focus.js +41 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/hover.js +32 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/pan/PanSession.js +148 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/pan/index.js +46 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/press.js +120 -0
- package/esm/node_modules/framer-motion/dist/es/gestures/utils/is-node-or-child.js +20 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/Feature.js +9 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/animation/exit.js +31 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/animation/index.js +38 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/animations.js +13 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/definitions.js +28 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/drag.js +17 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/gestures.js +21 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/layout/MeasureLayout.js +131 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/layout.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/load-features.js +12 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/viewport/index.js +72 -0
- package/esm/node_modules/framer-motion/dist/es/motion/features/viewport/observers.js +49 -0
- package/esm/node_modules/framer-motion/dist/es/motion/index.js +79 -0
- package/esm/node_modules/framer-motion/dist/es/motion/utils/is-forced-motion-value.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/motion/utils/symbol.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/motion/utils/use-motion-ref.js +33 -0
- package/esm/node_modules/framer-motion/dist/es/motion/utils/use-visual-element.js +75 -0
- package/esm/node_modules/framer-motion/dist/es/motion/utils/use-visual-state.js +81 -0
- package/esm/node_modules/framer-motion/dist/es/motion/utils/valid-prop.js +59 -0
- package/esm/node_modules/framer-motion/dist/es/projection/animation/mix-values.js +93 -0
- package/esm/node_modules/framer-motion/dist/es/projection/geometry/conversion.js +33 -0
- package/esm/node_modules/framer-motion/dist/es/projection/geometry/copy.js +20 -0
- package/esm/node_modules/framer-motion/dist/es/projection/geometry/delta-apply.js +122 -0
- package/esm/node_modules/framer-motion/dist/es/projection/geometry/delta-calc.js +41 -0
- package/esm/node_modules/framer-motion/dist/es/projection/geometry/delta-remove.js +54 -0
- package/esm/node_modules/framer-motion/dist/es/projection/geometry/models.js +17 -0
- package/esm/node_modules/framer-motion/dist/es/projection/geometry/utils.js +25 -0
- package/esm/node_modules/framer-motion/dist/es/projection/node/DocumentProjectionNode.js +13 -0
- package/esm/node_modules/framer-motion/dist/es/projection/node/HTMLProjectionNode.js +27 -0
- package/esm/node_modules/framer-motion/dist/es/projection/node/create-projection-node.js +1494 -0
- package/esm/node_modules/framer-motion/dist/es/projection/node/state.js +19 -0
- package/esm/node_modules/framer-motion/dist/es/projection/shared/stack.js +112 -0
- package/esm/node_modules/framer-motion/dist/es/projection/styles/scale-border-radius.js +41 -0
- package/esm/node_modules/framer-motion/dist/es/projection/styles/scale-box-shadow.js +35 -0
- package/esm/node_modules/framer-motion/dist/es/projection/styles/scale-correction.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/projection/styles/transform.js +42 -0
- package/esm/node_modules/framer-motion/dist/es/projection/utils/each-axis.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/projection/utils/has-transform.js +24 -0
- package/esm/node_modules/framer-motion/dist/es/projection/utils/measure.js +17 -0
- package/esm/node_modules/framer-motion/dist/es/render/VisualElement.js +507 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/DOMVisualElement.js +48 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/create-visual-element.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/motion-proxy.js +47 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/motion.js +23 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/use-render.js +35 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/camel-to-dash.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/create-config.js +19 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/css-variables-conversion.js +89 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/filter-props.js +57 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/is-css-variable.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/is-svg-component.js +30 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/is-svg-element.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/parse-dom-variant.js +15 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/utils/unit-conversion.js +230 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/animatable-none.js +15 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/defaults.js +30 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/dimensions.js +15 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/find.js +15 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/get-as-type.js +10 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/number.js +72 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/test.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/type-auto.js +9 -0
- package/esm/node_modules/framer-motion/dist/es/render/dom/value-types/type-int.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/HTMLVisualElement.js +55 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/config-motion.js +12 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/use-props.js +57 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/utils/build-styles.js +74 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/utils/build-transform.js +45 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/utils/create-render-state.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/utils/render.js +9 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/utils/scrape-motion-values.js +17 -0
- package/esm/node_modules/framer-motion/dist/es/render/html/utils/transform.js +28 -0
- package/esm/node_modules/framer-motion/dist/es/render/store.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/SVGVisualElement.js +46 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/config-motion.js +40 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/lowercase-elements.js +33 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/use-props.js +24 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/build-attrs.js +52 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/camel-case-attrs.js +30 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/create-render-state.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/is-svg-tag.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/path.js +32 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/render.js +12 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/scrape-motion-values.js +18 -0
- package/esm/node_modules/framer-motion/dist/es/render/svg/utils/transform-origin.js +18 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/animation-state.js +319 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/compare-by-depth.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/flat-tree.js +24 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/is-controlling-variants.js +13 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/is-variant-label.js +8 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/motion-values.js +63 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/resolve-dynamic-variants.js +24 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/resolve-variants.js +26 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/setters.js +101 -0
- package/esm/node_modules/framer-motion/dist/es/render/utils/variant-props.js +12 -0
- package/esm/node_modules/framer-motion/dist/es/utils/array.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/utils/clamp.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/utils/delay.js +19 -0
- package/esm/node_modules/framer-motion/dist/es/utils/distance.js +9 -0
- package/esm/node_modules/framer-motion/dist/es/utils/errors.js +18 -0
- package/esm/node_modules/framer-motion/dist/es/utils/hsla-to-rgba.js +42 -0
- package/esm/node_modules/framer-motion/dist/es/utils/interpolate.js +92 -0
- package/esm/node_modules/framer-motion/dist/es/utils/is-browser.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/utils/is-numerical-string.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/utils/is-ref-object.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/utils/is-zero-value-string.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/utils/memo.js +10 -0
- package/esm/node_modules/framer-motion/dist/es/utils/mix-color.js +40 -0
- package/esm/node_modules/framer-motion/dist/es/utils/mix-complex.js +64 -0
- package/esm/node_modules/framer-motion/dist/es/utils/mix.js +24 -0
- package/esm/node_modules/framer-motion/dist/es/utils/noop.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/utils/offsets/default.js +9 -0
- package/esm/node_modules/framer-motion/dist/es/utils/offsets/fill.js +12 -0
- package/esm/node_modules/framer-motion/dist/es/utils/offsets/time.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/utils/pipe.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/utils/progress.js +18 -0
- package/esm/node_modules/framer-motion/dist/es/utils/reduced-motion/index.js +19 -0
- package/esm/node_modules/framer-motion/dist/es/utils/reduced-motion/state.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/utils/resolve-value.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/utils/shallow-compare.js +14 -0
- package/esm/node_modules/framer-motion/dist/es/utils/subscription-manager.js +40 -0
- package/esm/node_modules/framer-motion/dist/es/utils/time-conversion.js +10 -0
- package/esm/node_modules/framer-motion/dist/es/utils/use-constant.js +18 -0
- package/esm/node_modules/framer-motion/dist/es/utils/use-force-update.js +19 -0
- package/esm/node_modules/framer-motion/dist/es/utils/use-instant-transition-state.js +5 -0
- package/esm/node_modules/framer-motion/dist/es/utils/use-is-mounted.js +15 -0
- package/esm/node_modules/framer-motion/dist/es/utils/use-isomorphic-effect.js +6 -0
- package/esm/node_modules/framer-motion/dist/es/utils/use-unmount-effect.js +7 -0
- package/esm/node_modules/framer-motion/dist/es/utils/velocity-per-second.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/utils/warn-once.js +11 -0
- package/esm/node_modules/framer-motion/dist/es/value/index.js +331 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/color/hex.js +40 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/color/hsla.js +22 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/color/index.js +28 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/color/rgba.js +25 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/color/utils.js +23 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/complex/filter.js +30 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/complex/index.js +92 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/numbers/index.js +17 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/numbers/units.js +19 -0
- package/esm/node_modules/framer-motion/dist/es/value/types/utils.js +15 -0
- package/esm/node_modules/framer-motion/dist/es/value/use-will-change/is.js +7 -0
- package/esm/node_modules/framer-motion/dist/es/value/utils/is-motion-value.js +3 -0
- package/esm/node_modules/framer-motion/dist/es/value/utils/resolve-motion-value.js +16 -0
- package/esm/node_modules/react-is/cjs/react-is.development.js +211 -0
- package/esm/node_modules/react-is/cjs/react-is.production.min.js +123 -0
- package/esm/node_modules/react-is/index.js +12 -0
- package/esm/packages/icons/esm/Close.js +17 -0
- package/esm/packages/token-studio/esm/token/elevation/index.js +5 -1
- package/esm/utils/isFunction.js +3 -0
- package/package.json +5 -3
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import React__default, { useContext } from 'react';
|
|
2
|
+
import { usePresence } from '../../../components/AnimatePresence/use-presence.js';
|
|
3
|
+
import { LayoutGroupContext } from '../../../context/LayoutGroupContext.js';
|
|
4
|
+
import { SwitchLayoutGroupContext } from '../../../context/SwitchLayoutGroupContext.js';
|
|
5
|
+
import { globalProjectionState } from '../../../projection/node/state.js';
|
|
6
|
+
import { correctBorderRadius } from '../../../projection/styles/scale-border-radius.js';
|
|
7
|
+
import { correctBoxShadow } from '../../../projection/styles/scale-box-shadow.js';
|
|
8
|
+
import { addScaleCorrector } from '../../../projection/styles/scale-correction.js';
|
|
9
|
+
import { frame } from '../../../frameloop/frame.js';
|
|
10
|
+
|
|
11
|
+
class MeasureLayoutWithContext extends React__default.Component {
|
|
12
|
+
/**
|
|
13
|
+
* This only mounts projection nodes for components that
|
|
14
|
+
* need measuring, we might want to do it for all components
|
|
15
|
+
* in order to incorporate transforms
|
|
16
|
+
*/
|
|
17
|
+
componentDidMount() {
|
|
18
|
+
const { visualElement, layoutGroup, switchLayoutGroup, layoutId } = this.props;
|
|
19
|
+
const { projection } = visualElement;
|
|
20
|
+
addScaleCorrector(defaultScaleCorrectors);
|
|
21
|
+
if (projection) {
|
|
22
|
+
if (layoutGroup.group)
|
|
23
|
+
layoutGroup.group.add(projection);
|
|
24
|
+
if (switchLayoutGroup && switchLayoutGroup.register && layoutId) {
|
|
25
|
+
switchLayoutGroup.register(projection);
|
|
26
|
+
}
|
|
27
|
+
projection.root.didUpdate();
|
|
28
|
+
projection.addEventListener("animationComplete", () => {
|
|
29
|
+
this.safeToRemove();
|
|
30
|
+
});
|
|
31
|
+
projection.setOptions({
|
|
32
|
+
...projection.options,
|
|
33
|
+
onExitComplete: () => this.safeToRemove(),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
globalProjectionState.hasEverUpdated = true;
|
|
37
|
+
}
|
|
38
|
+
getSnapshotBeforeUpdate(prevProps) {
|
|
39
|
+
const { layoutDependency, visualElement, drag, isPresent } = this.props;
|
|
40
|
+
const projection = visualElement.projection;
|
|
41
|
+
if (!projection)
|
|
42
|
+
return null;
|
|
43
|
+
/**
|
|
44
|
+
* TODO: We use this data in relegate to determine whether to
|
|
45
|
+
* promote a previous element. There's no guarantee its presence data
|
|
46
|
+
* will have updated by this point - if a bug like this arises it will
|
|
47
|
+
* have to be that we markForRelegation and then find a new lead some other way,
|
|
48
|
+
* perhaps in didUpdate
|
|
49
|
+
*/
|
|
50
|
+
projection.isPresent = isPresent;
|
|
51
|
+
if (drag ||
|
|
52
|
+
prevProps.layoutDependency !== layoutDependency ||
|
|
53
|
+
layoutDependency === undefined) {
|
|
54
|
+
projection.willUpdate();
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this.safeToRemove();
|
|
58
|
+
}
|
|
59
|
+
if (prevProps.isPresent !== isPresent) {
|
|
60
|
+
if (isPresent) {
|
|
61
|
+
projection.promote();
|
|
62
|
+
}
|
|
63
|
+
else if (!projection.relegate()) {
|
|
64
|
+
/**
|
|
65
|
+
* If there's another stack member taking over from this one,
|
|
66
|
+
* it's in charge of the exit animation and therefore should
|
|
67
|
+
* be in charge of the safe to remove. Otherwise we call it here.
|
|
68
|
+
*/
|
|
69
|
+
frame.postRender(() => {
|
|
70
|
+
const stack = projection.getStack();
|
|
71
|
+
if (!stack || !stack.members.length) {
|
|
72
|
+
this.safeToRemove();
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
componentDidUpdate() {
|
|
80
|
+
const { projection } = this.props.visualElement;
|
|
81
|
+
if (projection) {
|
|
82
|
+
projection.root.didUpdate();
|
|
83
|
+
queueMicrotask(() => {
|
|
84
|
+
if (!projection.currentAnimation && projection.isLead()) {
|
|
85
|
+
this.safeToRemove();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
componentWillUnmount() {
|
|
91
|
+
const { visualElement, layoutGroup, switchLayoutGroup: promoteContext, } = this.props;
|
|
92
|
+
const { projection } = visualElement;
|
|
93
|
+
if (projection) {
|
|
94
|
+
projection.scheduleCheckAfterUnmount();
|
|
95
|
+
if (layoutGroup && layoutGroup.group)
|
|
96
|
+
layoutGroup.group.remove(projection);
|
|
97
|
+
if (promoteContext && promoteContext.deregister)
|
|
98
|
+
promoteContext.deregister(projection);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
safeToRemove() {
|
|
102
|
+
const { safeToRemove } = this.props;
|
|
103
|
+
safeToRemove && safeToRemove();
|
|
104
|
+
}
|
|
105
|
+
render() {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function MeasureLayout(props) {
|
|
110
|
+
const [isPresent, safeToRemove] = usePresence();
|
|
111
|
+
const layoutGroup = useContext(LayoutGroupContext);
|
|
112
|
+
return (React__default.createElement(MeasureLayoutWithContext, { ...props, layoutGroup: layoutGroup, switchLayoutGroup: useContext(SwitchLayoutGroupContext), isPresent: isPresent, safeToRemove: safeToRemove }));
|
|
113
|
+
}
|
|
114
|
+
const defaultScaleCorrectors = {
|
|
115
|
+
borderRadius: {
|
|
116
|
+
...correctBorderRadius,
|
|
117
|
+
applyTo: [
|
|
118
|
+
"borderTopLeftRadius",
|
|
119
|
+
"borderTopRightRadius",
|
|
120
|
+
"borderBottomLeftRadius",
|
|
121
|
+
"borderBottomRightRadius",
|
|
122
|
+
],
|
|
123
|
+
},
|
|
124
|
+
borderTopLeftRadius: correctBorderRadius,
|
|
125
|
+
borderTopRightRadius: correctBorderRadius,
|
|
126
|
+
borderBottomLeftRadius: correctBorderRadius,
|
|
127
|
+
borderBottomRightRadius: correctBorderRadius,
|
|
128
|
+
boxShadow: correctBoxShadow,
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export { MeasureLayout };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HTMLProjectionNode } from '../../projection/node/HTMLProjectionNode.js';
|
|
2
|
+
import { MeasureLayout } from './layout/MeasureLayout.js';
|
|
3
|
+
|
|
4
|
+
const layout = {
|
|
5
|
+
layout: {
|
|
6
|
+
ProjectionNode: HTMLProjectionNode,
|
|
7
|
+
MeasureLayout,
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { layout };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Feature } from '../Feature.js';
|
|
2
|
+
import { observeIntersection } from './observers.js';
|
|
3
|
+
|
|
4
|
+
const thresholdNames = {
|
|
5
|
+
some: 0,
|
|
6
|
+
all: 1,
|
|
7
|
+
};
|
|
8
|
+
class InViewFeature extends Feature {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.hasEnteredView = false;
|
|
12
|
+
this.isInView = false;
|
|
13
|
+
}
|
|
14
|
+
startObserver() {
|
|
15
|
+
this.unmount();
|
|
16
|
+
const { viewport = {} } = this.node.getProps();
|
|
17
|
+
const { root, margin: rootMargin, amount = "some", once } = viewport;
|
|
18
|
+
const options = {
|
|
19
|
+
root: root ? root.current : undefined,
|
|
20
|
+
rootMargin,
|
|
21
|
+
threshold: typeof amount === "number" ? amount : thresholdNames[amount],
|
|
22
|
+
};
|
|
23
|
+
const onIntersectionUpdate = (entry) => {
|
|
24
|
+
const { isIntersecting } = entry;
|
|
25
|
+
/**
|
|
26
|
+
* If there's been no change in the viewport state, early return.
|
|
27
|
+
*/
|
|
28
|
+
if (this.isInView === isIntersecting)
|
|
29
|
+
return;
|
|
30
|
+
this.isInView = isIntersecting;
|
|
31
|
+
/**
|
|
32
|
+
* Handle hasEnteredView. If this is only meant to run once, and
|
|
33
|
+
* element isn't visible, early return. Otherwise set hasEnteredView to true.
|
|
34
|
+
*/
|
|
35
|
+
if (once && !isIntersecting && this.hasEnteredView) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
else if (isIntersecting) {
|
|
39
|
+
this.hasEnteredView = true;
|
|
40
|
+
}
|
|
41
|
+
if (this.node.animationState) {
|
|
42
|
+
this.node.animationState.setActive("whileInView", isIntersecting);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Use the latest committed props rather than the ones in scope
|
|
46
|
+
* when this observer is created
|
|
47
|
+
*/
|
|
48
|
+
const { onViewportEnter, onViewportLeave } = this.node.getProps();
|
|
49
|
+
const callback = isIntersecting ? onViewportEnter : onViewportLeave;
|
|
50
|
+
callback && callback(entry);
|
|
51
|
+
};
|
|
52
|
+
return observeIntersection(this.node.current, options, onIntersectionUpdate);
|
|
53
|
+
}
|
|
54
|
+
mount() {
|
|
55
|
+
this.startObserver();
|
|
56
|
+
}
|
|
57
|
+
update() {
|
|
58
|
+
if (typeof IntersectionObserver === "undefined")
|
|
59
|
+
return;
|
|
60
|
+
const { props, prevProps } = this.node;
|
|
61
|
+
const hasOptionsChanged = ["amount", "margin", "root"].some(hasViewportOptionChanged(props, prevProps));
|
|
62
|
+
if (hasOptionsChanged) {
|
|
63
|
+
this.startObserver();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
unmount() { }
|
|
67
|
+
}
|
|
68
|
+
function hasViewportOptionChanged({ viewport = {} }, { viewport: prevViewport = {} } = {}) {
|
|
69
|
+
return (name) => viewport[name] !== prevViewport[name];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { InViewFeature };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map an IntersectionHandler callback to an element. We only ever make one handler for one
|
|
3
|
+
* element, so even though these handlers might all be triggered by different
|
|
4
|
+
* observers, we can keep them in the same map.
|
|
5
|
+
*/
|
|
6
|
+
const observerCallbacks = new WeakMap();
|
|
7
|
+
/**
|
|
8
|
+
* Multiple observers can be created for multiple element/document roots. Each with
|
|
9
|
+
* different settings. So here we store dictionaries of observers to each root,
|
|
10
|
+
* using serialised settings (threshold/margin) as lookup keys.
|
|
11
|
+
*/
|
|
12
|
+
const observers = new WeakMap();
|
|
13
|
+
const fireObserverCallback = (entry) => {
|
|
14
|
+
const callback = observerCallbacks.get(entry.target);
|
|
15
|
+
callback && callback(entry);
|
|
16
|
+
};
|
|
17
|
+
const fireAllObserverCallbacks = (entries) => {
|
|
18
|
+
entries.forEach(fireObserverCallback);
|
|
19
|
+
};
|
|
20
|
+
function initIntersectionObserver({ root, ...options }) {
|
|
21
|
+
const lookupRoot = root || document;
|
|
22
|
+
/**
|
|
23
|
+
* If we don't have an observer lookup map for this root, create one.
|
|
24
|
+
*/
|
|
25
|
+
if (!observers.has(lookupRoot)) {
|
|
26
|
+
observers.set(lookupRoot, {});
|
|
27
|
+
}
|
|
28
|
+
const rootObservers = observers.get(lookupRoot);
|
|
29
|
+
const key = JSON.stringify(options);
|
|
30
|
+
/**
|
|
31
|
+
* If we don't have an observer for this combination of root and settings,
|
|
32
|
+
* create one.
|
|
33
|
+
*/
|
|
34
|
+
if (!rootObservers[key]) {
|
|
35
|
+
rootObservers[key] = new IntersectionObserver(fireAllObserverCallbacks, { root, ...options });
|
|
36
|
+
}
|
|
37
|
+
return rootObservers[key];
|
|
38
|
+
}
|
|
39
|
+
function observeIntersection(element, options, callback) {
|
|
40
|
+
const rootInteresectionObserver = initIntersectionObserver(options);
|
|
41
|
+
observerCallbacks.set(element, callback);
|
|
42
|
+
rootInteresectionObserver.observe(element);
|
|
43
|
+
return () => {
|
|
44
|
+
observerCallbacks.delete(element);
|
|
45
|
+
rootInteresectionObserver.unobserve(element);
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { observeIntersection };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { forwardRef, useContext } from 'react';
|
|
3
|
+
import { MotionConfigContext } from '../context/MotionConfigContext.js';
|
|
4
|
+
import { MotionContext } from '../context/MotionContext/index.js';
|
|
5
|
+
import { useVisualElement } from './utils/use-visual-element.js';
|
|
6
|
+
import { useMotionRef } from './utils/use-motion-ref.js';
|
|
7
|
+
import { useCreateMotionContext } from '../context/MotionContext/create.js';
|
|
8
|
+
import { loadFeatures } from './features/load-features.js';
|
|
9
|
+
import { isBrowser } from '../utils/is-browser.js';
|
|
10
|
+
import { LayoutGroupContext } from '../context/LayoutGroupContext.js';
|
|
11
|
+
import { LazyContext } from '../context/LazyContext.js';
|
|
12
|
+
import { SwitchLayoutGroupContext } from '../context/SwitchLayoutGroupContext.js';
|
|
13
|
+
import { motionComponentSymbol } from './utils/symbol.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Create a `motion` component.
|
|
17
|
+
*
|
|
18
|
+
* This function accepts a Component argument, which can be either a string (ie "div"
|
|
19
|
+
* for `motion.div`), or an actual React component.
|
|
20
|
+
*
|
|
21
|
+
* Alongside this is a config option which provides a way of rendering the provided
|
|
22
|
+
* component "offline", or outside the React render cycle.
|
|
23
|
+
*/
|
|
24
|
+
function createMotionComponent({ preloadedFeatures, createVisualElement, useRender, useVisualState, Component, }) {
|
|
25
|
+
preloadedFeatures && loadFeatures(preloadedFeatures);
|
|
26
|
+
function MotionComponent(props, externalRef) {
|
|
27
|
+
/**
|
|
28
|
+
* If we need to measure the element we load this functionality in a
|
|
29
|
+
* separate class component in order to gain access to getSnapshotBeforeUpdate.
|
|
30
|
+
*/
|
|
31
|
+
let MeasureLayout;
|
|
32
|
+
const configAndProps = {
|
|
33
|
+
...useContext(MotionConfigContext),
|
|
34
|
+
...props,
|
|
35
|
+
layoutId: useLayoutId(props),
|
|
36
|
+
};
|
|
37
|
+
const { isStatic } = configAndProps;
|
|
38
|
+
const context = useCreateMotionContext(props);
|
|
39
|
+
const visualState = useVisualState(props, isStatic);
|
|
40
|
+
if (!isStatic && isBrowser) {
|
|
41
|
+
/**
|
|
42
|
+
* Create a VisualElement for this component. A VisualElement provides a common
|
|
43
|
+
* interface to renderer-specific APIs (ie DOM/Three.js etc) as well as
|
|
44
|
+
* providing a way of rendering to these APIs outside of the React render loop
|
|
45
|
+
* for more performant animations and interactions
|
|
46
|
+
*/
|
|
47
|
+
context.visualElement = useVisualElement(Component, visualState, configAndProps, createVisualElement);
|
|
48
|
+
/**
|
|
49
|
+
* Load Motion gesture and animation features. These are rendered as renderless
|
|
50
|
+
* components so each feature can optionally make use of React lifecycle methods.
|
|
51
|
+
*/
|
|
52
|
+
const initialLayoutGroupConfig = useContext(SwitchLayoutGroupContext);
|
|
53
|
+
const isStrict = useContext(LazyContext).strict;
|
|
54
|
+
if (context.visualElement) {
|
|
55
|
+
MeasureLayout = context.visualElement.loadFeatures(
|
|
56
|
+
// Note: Pass the full new combined props to correctly re-render dynamic feature components.
|
|
57
|
+
configAndProps, isStrict, preloadedFeatures, initialLayoutGroupConfig);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The mount order and hierarchy is specific to ensure our element ref
|
|
62
|
+
* is hydrated by the time features fire their effects.
|
|
63
|
+
*/
|
|
64
|
+
return (React.createElement(MotionContext.Provider, { value: context },
|
|
65
|
+
MeasureLayout && context.visualElement ? (React.createElement(MeasureLayout, { visualElement: context.visualElement, ...configAndProps })) : null,
|
|
66
|
+
useRender(Component, props, useMotionRef(visualState, context.visualElement, externalRef), visualState, isStatic, context.visualElement)));
|
|
67
|
+
}
|
|
68
|
+
const ForwardRefComponent = forwardRef(MotionComponent);
|
|
69
|
+
ForwardRefComponent[motionComponentSymbol] = Component;
|
|
70
|
+
return ForwardRefComponent;
|
|
71
|
+
}
|
|
72
|
+
function useLayoutId({ layoutId }) {
|
|
73
|
+
const layoutGroupId = useContext(LayoutGroupContext).id;
|
|
74
|
+
return layoutGroupId && layoutId !== undefined
|
|
75
|
+
? layoutGroupId + "-" + layoutId
|
|
76
|
+
: layoutId;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { createMotionComponent };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { scaleCorrectors } from '../../projection/styles/scale-correction.js';
|
|
2
|
+
import { transformProps } from '../../render/html/utils/transform.js';
|
|
3
|
+
|
|
4
|
+
function isForcedMotionValue(key, { layout, layoutId }) {
|
|
5
|
+
return (transformProps.has(key) ||
|
|
6
|
+
key.startsWith("origin") ||
|
|
7
|
+
((layout || layoutId !== undefined) &&
|
|
8
|
+
(!!scaleCorrectors[key] || key === "opacity")));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { isForcedMotionValue };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { isRefObject } from '../../utils/is-ref-object.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates a ref function that, when called, hydrates the provided
|
|
6
|
+
* external ref and VisualElement.
|
|
7
|
+
*/
|
|
8
|
+
function useMotionRef(visualState, visualElement, externalRef) {
|
|
9
|
+
return useCallback((instance) => {
|
|
10
|
+
instance && visualState.mount && visualState.mount(instance);
|
|
11
|
+
if (visualElement) {
|
|
12
|
+
instance
|
|
13
|
+
? visualElement.mount(instance)
|
|
14
|
+
: visualElement.unmount();
|
|
15
|
+
}
|
|
16
|
+
if (externalRef) {
|
|
17
|
+
if (typeof externalRef === "function") {
|
|
18
|
+
externalRef(instance);
|
|
19
|
+
}
|
|
20
|
+
else if (isRefObject(externalRef)) {
|
|
21
|
+
externalRef.current = instance;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
/**
|
|
26
|
+
* Only pass a new ref callback to React if we've received a visual element
|
|
27
|
+
* factory. Otherwise we'll be mounting/remounting every time externalRef
|
|
28
|
+
* or other dependencies change.
|
|
29
|
+
*/
|
|
30
|
+
[visualElement]);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { useMotionRef };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { useContext, useRef, useInsertionEffect, useEffect } from 'react';
|
|
2
|
+
import { PresenceContext } from '../../context/PresenceContext.js';
|
|
3
|
+
import { MotionContext } from '../../context/MotionContext/index.js';
|
|
4
|
+
import { useIsomorphicLayoutEffect } from '../../utils/use-isomorphic-effect.js';
|
|
5
|
+
import { LazyContext } from '../../context/LazyContext.js';
|
|
6
|
+
import { MotionConfigContext } from '../../context/MotionConfigContext.js';
|
|
7
|
+
|
|
8
|
+
function useVisualElement(Component, visualState, props, createVisualElement) {
|
|
9
|
+
const { visualElement: parent } = useContext(MotionContext);
|
|
10
|
+
const lazyContext = useContext(LazyContext);
|
|
11
|
+
const presenceContext = useContext(PresenceContext);
|
|
12
|
+
const reducedMotionConfig = useContext(MotionConfigContext).reducedMotion;
|
|
13
|
+
const visualElementRef = useRef();
|
|
14
|
+
/**
|
|
15
|
+
* If we haven't preloaded a renderer, check to see if we have one lazy-loaded
|
|
16
|
+
*/
|
|
17
|
+
createVisualElement = createVisualElement || lazyContext.renderer;
|
|
18
|
+
if (!visualElementRef.current && createVisualElement) {
|
|
19
|
+
visualElementRef.current = createVisualElement(Component, {
|
|
20
|
+
visualState,
|
|
21
|
+
parent,
|
|
22
|
+
props,
|
|
23
|
+
presenceContext,
|
|
24
|
+
blockInitialAnimation: presenceContext
|
|
25
|
+
? presenceContext.initial === false
|
|
26
|
+
: false,
|
|
27
|
+
reducedMotionConfig,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
const visualElement = visualElementRef.current;
|
|
31
|
+
useInsertionEffect(() => {
|
|
32
|
+
visualElement && visualElement.update(props, presenceContext);
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* Cache this value as we want to know whether HandoffAppearAnimations
|
|
36
|
+
* was present on initial render - it will be deleted after this.
|
|
37
|
+
*/
|
|
38
|
+
const canHandoff = useRef(Boolean(window.HandoffAppearAnimations));
|
|
39
|
+
useIsomorphicLayoutEffect(() => {
|
|
40
|
+
if (!visualElement)
|
|
41
|
+
return;
|
|
42
|
+
visualElement.render();
|
|
43
|
+
/**
|
|
44
|
+
* Ideally this function would always run in a useEffect.
|
|
45
|
+
*
|
|
46
|
+
* However, if we have optimised appear animations to handoff from,
|
|
47
|
+
* it needs to happen synchronously to ensure there's no flash of
|
|
48
|
+
* incorrect styles in the event of a hydration error.
|
|
49
|
+
*
|
|
50
|
+
* So if we detect a situtation where optimised appear animations
|
|
51
|
+
* are running, we use useLayoutEffect to trigger animations.
|
|
52
|
+
*/
|
|
53
|
+
if (canHandoff.current && visualElement.animationState) {
|
|
54
|
+
visualElement.animationState.animateChanges();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (!visualElement)
|
|
59
|
+
return;
|
|
60
|
+
visualElement.updateFeatures();
|
|
61
|
+
if (!canHandoff.current && visualElement.animationState) {
|
|
62
|
+
visualElement.animationState.animateChanges();
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Once we've handed off animations we can delete HandoffAppearAnimations
|
|
66
|
+
* so components added after the initial render can animate changes
|
|
67
|
+
* in useEffect vs useLayoutEffect.
|
|
68
|
+
*/
|
|
69
|
+
window.HandoffAppearAnimations = undefined;
|
|
70
|
+
canHandoff.current = false;
|
|
71
|
+
});
|
|
72
|
+
return visualElement;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { useVisualElement };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { isAnimationControls } from '../../animation/utils/is-animation-controls.js';
|
|
3
|
+
import { PresenceContext } from '../../context/PresenceContext.js';
|
|
4
|
+
import { resolveVariantFromProps } from '../../render/utils/resolve-variants.js';
|
|
5
|
+
import { useConstant } from '../../utils/use-constant.js';
|
|
6
|
+
import { resolveMotionValue } from '../../value/utils/resolve-motion-value.js';
|
|
7
|
+
import { MotionContext } from '../../context/MotionContext/index.js';
|
|
8
|
+
import { isControllingVariants, isVariantNode } from '../../render/utils/is-controlling-variants.js';
|
|
9
|
+
|
|
10
|
+
function makeState({ scrapeMotionValuesFromProps, createRenderState, onMount, }, props, context, presenceContext) {
|
|
11
|
+
const state = {
|
|
12
|
+
latestValues: makeLatestValues(props, context, presenceContext, scrapeMotionValuesFromProps),
|
|
13
|
+
renderState: createRenderState(),
|
|
14
|
+
};
|
|
15
|
+
if (onMount) {
|
|
16
|
+
state.mount = (instance) => onMount(props, instance, state);
|
|
17
|
+
}
|
|
18
|
+
return state;
|
|
19
|
+
}
|
|
20
|
+
const makeUseVisualState = (config) => (props, isStatic) => {
|
|
21
|
+
const context = useContext(MotionContext);
|
|
22
|
+
const presenceContext = useContext(PresenceContext);
|
|
23
|
+
const make = () => makeState(config, props, context, presenceContext);
|
|
24
|
+
return isStatic ? make() : useConstant(make);
|
|
25
|
+
};
|
|
26
|
+
function makeLatestValues(props, context, presenceContext, scrapeMotionValues) {
|
|
27
|
+
const values = {};
|
|
28
|
+
const motionValues = scrapeMotionValues(props, {});
|
|
29
|
+
for (const key in motionValues) {
|
|
30
|
+
values[key] = resolveMotionValue(motionValues[key]);
|
|
31
|
+
}
|
|
32
|
+
let { initial, animate } = props;
|
|
33
|
+
const isControllingVariants$1 = isControllingVariants(props);
|
|
34
|
+
const isVariantNode$1 = isVariantNode(props);
|
|
35
|
+
if (context &&
|
|
36
|
+
isVariantNode$1 &&
|
|
37
|
+
!isControllingVariants$1 &&
|
|
38
|
+
props.inherit !== false) {
|
|
39
|
+
if (initial === undefined)
|
|
40
|
+
initial = context.initial;
|
|
41
|
+
if (animate === undefined)
|
|
42
|
+
animate = context.animate;
|
|
43
|
+
}
|
|
44
|
+
let isInitialAnimationBlocked = presenceContext
|
|
45
|
+
? presenceContext.initial === false
|
|
46
|
+
: false;
|
|
47
|
+
isInitialAnimationBlocked = isInitialAnimationBlocked || initial === false;
|
|
48
|
+
const variantToSet = isInitialAnimationBlocked ? animate : initial;
|
|
49
|
+
if (variantToSet &&
|
|
50
|
+
typeof variantToSet !== "boolean" &&
|
|
51
|
+
!isAnimationControls(variantToSet)) {
|
|
52
|
+
const list = Array.isArray(variantToSet) ? variantToSet : [variantToSet];
|
|
53
|
+
list.forEach((definition) => {
|
|
54
|
+
const resolved = resolveVariantFromProps(props, definition);
|
|
55
|
+
if (!resolved)
|
|
56
|
+
return;
|
|
57
|
+
const { transitionEnd, transition, ...target } = resolved;
|
|
58
|
+
for (const key in target) {
|
|
59
|
+
let valueTarget = target[key];
|
|
60
|
+
if (Array.isArray(valueTarget)) {
|
|
61
|
+
/**
|
|
62
|
+
* Take final keyframe if the initial animation is blocked because
|
|
63
|
+
* we want to initialise at the end of that blocked animation.
|
|
64
|
+
*/
|
|
65
|
+
const index = isInitialAnimationBlocked
|
|
66
|
+
? valueTarget.length - 1
|
|
67
|
+
: 0;
|
|
68
|
+
valueTarget = valueTarget[index];
|
|
69
|
+
}
|
|
70
|
+
if (valueTarget !== null) {
|
|
71
|
+
values[key] = valueTarget;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
for (const key in transitionEnd)
|
|
75
|
+
values[key] = transitionEnd[key];
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return values;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { makeUseVisualState };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A list of all valid MotionProps.
|
|
3
|
+
*
|
|
4
|
+
* @privateRemarks
|
|
5
|
+
* This doesn't throw if a `MotionProp` name is missing - it should.
|
|
6
|
+
*/
|
|
7
|
+
const validMotionProps = new Set([
|
|
8
|
+
"animate",
|
|
9
|
+
"exit",
|
|
10
|
+
"variants",
|
|
11
|
+
"initial",
|
|
12
|
+
"style",
|
|
13
|
+
"values",
|
|
14
|
+
"variants",
|
|
15
|
+
"transition",
|
|
16
|
+
"transformTemplate",
|
|
17
|
+
"transformValues",
|
|
18
|
+
"custom",
|
|
19
|
+
"inherit",
|
|
20
|
+
"onLayoutAnimationStart",
|
|
21
|
+
"onLayoutAnimationComplete",
|
|
22
|
+
"onLayoutMeasure",
|
|
23
|
+
"onBeforeLayoutMeasure",
|
|
24
|
+
"onAnimationStart",
|
|
25
|
+
"onAnimationComplete",
|
|
26
|
+
"onUpdate",
|
|
27
|
+
"onDragStart",
|
|
28
|
+
"onDrag",
|
|
29
|
+
"onDragEnd",
|
|
30
|
+
"onMeasureDragConstraints",
|
|
31
|
+
"onDirectionLock",
|
|
32
|
+
"onDragTransitionEnd",
|
|
33
|
+
"_dragX",
|
|
34
|
+
"_dragY",
|
|
35
|
+
"onHoverStart",
|
|
36
|
+
"onHoverEnd",
|
|
37
|
+
"onViewportEnter",
|
|
38
|
+
"onViewportLeave",
|
|
39
|
+
"ignoreStrict",
|
|
40
|
+
"viewport",
|
|
41
|
+
]);
|
|
42
|
+
/**
|
|
43
|
+
* Check whether a prop name is a valid `MotionProp` key.
|
|
44
|
+
*
|
|
45
|
+
* @param key - Name of the property to check
|
|
46
|
+
* @returns `true` is key is a valid `MotionProp`.
|
|
47
|
+
*
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
function isValidMotionProp(key) {
|
|
51
|
+
return (key.startsWith("while") ||
|
|
52
|
+
(key.startsWith("drag") && key !== "draggable") ||
|
|
53
|
+
key.startsWith("layout") ||
|
|
54
|
+
key.startsWith("onTap") ||
|
|
55
|
+
key.startsWith("onPan") ||
|
|
56
|
+
validMotionProps.has(key));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { isValidMotionProp };
|