@teamturing/react-kit 2.3.1 → 2.5.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/Dialog/index.d.ts +16 -0
- package/dist/core/DialogHandler/index.d.ts +13 -0
- package/dist/core/Grid/index.d.ts +2 -2
- package/dist/core/MotionView/index.d.ts +3 -0
- package/dist/core/Stack/index.d.ts +2 -2
- package/dist/enigma/EnigmaUI/index.d.ts +12 -2
- package/dist/hook/useDialogHandler.d.ts +6 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +9769 -325
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/isFunction.d.ts +1 -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/enigma/EnigmaUI/index.js +6 -1
- package/esm/hook/useDialogHandler.js +14 -0
- package/esm/index.js +3 -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/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 +3 -3
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
class Queue {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.order = [];
|
|
4
|
+
this.scheduled = new Set();
|
|
5
|
+
}
|
|
6
|
+
add(process) {
|
|
7
|
+
if (!this.scheduled.has(process)) {
|
|
8
|
+
this.scheduled.add(process);
|
|
9
|
+
this.order.push(process);
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
remove(process) {
|
|
14
|
+
const index = this.order.indexOf(process);
|
|
15
|
+
if (index !== -1) {
|
|
16
|
+
this.order.splice(index, 1);
|
|
17
|
+
this.scheduled.delete(process);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
clear() {
|
|
21
|
+
this.order.length = 0;
|
|
22
|
+
this.scheduled.clear();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function createRenderStep(runNextFrame) {
|
|
26
|
+
/**
|
|
27
|
+
* We create and reuse two queues, one to queue jobs for the current frame
|
|
28
|
+
* and one for the next. We reuse to avoid triggering GC after x frames.
|
|
29
|
+
*/
|
|
30
|
+
let thisFrame = new Queue();
|
|
31
|
+
let nextFrame = new Queue();
|
|
32
|
+
let numToRun = 0;
|
|
33
|
+
/**
|
|
34
|
+
* Track whether we're currently processing jobs in this step. This way
|
|
35
|
+
* we can decide whether to schedule new jobs for this frame or next.
|
|
36
|
+
*/
|
|
37
|
+
let isProcessing = false;
|
|
38
|
+
let flushNextFrame = false;
|
|
39
|
+
/**
|
|
40
|
+
* A set of processes which were marked keepAlive when scheduled.
|
|
41
|
+
*/
|
|
42
|
+
const toKeepAlive = new WeakSet();
|
|
43
|
+
const step = {
|
|
44
|
+
/**
|
|
45
|
+
* Schedule a process to run on the next frame.
|
|
46
|
+
*/
|
|
47
|
+
schedule: (callback, keepAlive = false, immediate = false) => {
|
|
48
|
+
const addToCurrentFrame = immediate && isProcessing;
|
|
49
|
+
const queue = addToCurrentFrame ? thisFrame : nextFrame;
|
|
50
|
+
if (keepAlive)
|
|
51
|
+
toKeepAlive.add(callback);
|
|
52
|
+
if (queue.add(callback) && addToCurrentFrame && isProcessing) {
|
|
53
|
+
// If we're adding it to the currently running queue, update its measured size
|
|
54
|
+
numToRun = thisFrame.order.length;
|
|
55
|
+
}
|
|
56
|
+
return callback;
|
|
57
|
+
},
|
|
58
|
+
/**
|
|
59
|
+
* Cancel the provided callback from running on the next frame.
|
|
60
|
+
*/
|
|
61
|
+
cancel: (callback) => {
|
|
62
|
+
nextFrame.remove(callback);
|
|
63
|
+
toKeepAlive.delete(callback);
|
|
64
|
+
},
|
|
65
|
+
/**
|
|
66
|
+
* Execute all schedule callbacks.
|
|
67
|
+
*/
|
|
68
|
+
process: (frameData) => {
|
|
69
|
+
/**
|
|
70
|
+
* If we're already processing we've probably been triggered by a flushSync
|
|
71
|
+
* inside an existing process. Instead of executing, mark flushNextFrame
|
|
72
|
+
* as true and ensure we flush the following frame at the end of this one.
|
|
73
|
+
*/
|
|
74
|
+
if (isProcessing) {
|
|
75
|
+
flushNextFrame = true;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
isProcessing = true;
|
|
79
|
+
[thisFrame, nextFrame] = [nextFrame, thisFrame];
|
|
80
|
+
// Clear the next frame queue
|
|
81
|
+
nextFrame.clear();
|
|
82
|
+
// Execute this frame
|
|
83
|
+
numToRun = thisFrame.order.length;
|
|
84
|
+
if (numToRun) {
|
|
85
|
+
for (let i = 0; i < numToRun; i++) {
|
|
86
|
+
const callback = thisFrame.order[i];
|
|
87
|
+
callback(frameData);
|
|
88
|
+
if (toKeepAlive.has(callback)) {
|
|
89
|
+
step.schedule(callback);
|
|
90
|
+
runNextFrame();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
isProcessing = false;
|
|
95
|
+
if (flushNextFrame) {
|
|
96
|
+
flushNextFrame = false;
|
|
97
|
+
step.process(frameData);
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
return step;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { createRenderStep };
|
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
import { invariant } from '../../utils/errors.js';
|
|
2
|
+
import { PanSession } from '../pan/PanSession.js';
|
|
3
|
+
import { getGlobalLock } from './utils/lock.js';
|
|
4
|
+
import { isRefObject } from '../../utils/is-ref-object.js';
|
|
5
|
+
import { addPointerEvent } from '../../events/add-pointer-event.js';
|
|
6
|
+
import { applyConstraints, calcRelativeConstraints, resolveDragElastic, calcViewportConstraints, rebaseAxisConstraints, calcOrigin, defaultElastic } from './utils/constraints.js';
|
|
7
|
+
import { createBox } from '../../projection/geometry/models.js';
|
|
8
|
+
import { eachAxis } from '../../projection/utils/each-axis.js';
|
|
9
|
+
import { measurePageBox } from '../../projection/utils/measure.js';
|
|
10
|
+
import { extractEventInfo } from '../../events/event-info.js';
|
|
11
|
+
import { convertBoxToBoundingBox, convertBoundingBoxToBox } from '../../projection/geometry/conversion.js';
|
|
12
|
+
import { addDomEvent } from '../../events/add-dom-event.js';
|
|
13
|
+
import { calcLength } from '../../projection/geometry/delta-calc.js';
|
|
14
|
+
import { mix } from '../../utils/mix.js';
|
|
15
|
+
import { percent } from '../../value/types/numbers/units.js';
|
|
16
|
+
import { animateMotionValue } from '../../animation/interfaces/motion-value.js';
|
|
17
|
+
import { frame } from '../../frameloop/frame.js';
|
|
18
|
+
|
|
19
|
+
const elementDragControls = new WeakMap();
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
// let latestPointerEvent: PointerEvent
|
|
24
|
+
class VisualElementDragControls {
|
|
25
|
+
constructor(visualElement) {
|
|
26
|
+
// This is a reference to the global drag gesture lock, ensuring only one component
|
|
27
|
+
// can "capture" the drag of one or both axes.
|
|
28
|
+
// TODO: Look into moving this into pansession?
|
|
29
|
+
this.openGlobalLock = null;
|
|
30
|
+
this.isDragging = false;
|
|
31
|
+
this.currentDirection = null;
|
|
32
|
+
this.originPoint = { x: 0, y: 0 };
|
|
33
|
+
/**
|
|
34
|
+
* The permitted boundaries of travel, in pixels.
|
|
35
|
+
*/
|
|
36
|
+
this.constraints = false;
|
|
37
|
+
this.hasMutatedConstraints = false;
|
|
38
|
+
/**
|
|
39
|
+
* The per-axis resolved elastic values.
|
|
40
|
+
*/
|
|
41
|
+
this.elastic = createBox();
|
|
42
|
+
this.visualElement = visualElement;
|
|
43
|
+
}
|
|
44
|
+
start(originEvent, { snapToCursor = false } = {}) {
|
|
45
|
+
/**
|
|
46
|
+
* Don't start dragging if this component is exiting
|
|
47
|
+
*/
|
|
48
|
+
const { presenceContext } = this.visualElement;
|
|
49
|
+
if (presenceContext && presenceContext.isPresent === false)
|
|
50
|
+
return;
|
|
51
|
+
const onSessionStart = (event) => {
|
|
52
|
+
// Stop any animations on both axis values immediately. This allows the user to throw and catch
|
|
53
|
+
// the component.
|
|
54
|
+
this.stopAnimation();
|
|
55
|
+
if (snapToCursor) {
|
|
56
|
+
this.snapToCursor(extractEventInfo(event, "page").point);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const onStart = (event, info) => {
|
|
60
|
+
// Attempt to grab the global drag gesture lock - maybe make this part of PanSession
|
|
61
|
+
const { drag, dragPropagation, onDragStart } = this.getProps();
|
|
62
|
+
if (drag && !dragPropagation) {
|
|
63
|
+
if (this.openGlobalLock)
|
|
64
|
+
this.openGlobalLock();
|
|
65
|
+
this.openGlobalLock = getGlobalLock(drag);
|
|
66
|
+
// If we don 't have the lock, don't start dragging
|
|
67
|
+
if (!this.openGlobalLock)
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
this.isDragging = true;
|
|
71
|
+
this.currentDirection = null;
|
|
72
|
+
this.resolveConstraints();
|
|
73
|
+
if (this.visualElement.projection) {
|
|
74
|
+
this.visualElement.projection.isAnimationBlocked = true;
|
|
75
|
+
this.visualElement.projection.target = undefined;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Record gesture origin
|
|
79
|
+
*/
|
|
80
|
+
eachAxis((axis) => {
|
|
81
|
+
let current = this.getAxisMotionValue(axis).get() || 0;
|
|
82
|
+
/**
|
|
83
|
+
* If the MotionValue is a percentage value convert to px
|
|
84
|
+
*/
|
|
85
|
+
if (percent.test(current)) {
|
|
86
|
+
const { projection } = this.visualElement;
|
|
87
|
+
if (projection && projection.layout) {
|
|
88
|
+
const measuredAxis = projection.layout.layoutBox[axis];
|
|
89
|
+
if (measuredAxis) {
|
|
90
|
+
const length = calcLength(measuredAxis);
|
|
91
|
+
current = length * (parseFloat(current) / 100);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
this.originPoint[axis] = current;
|
|
96
|
+
});
|
|
97
|
+
// Fire onDragStart event
|
|
98
|
+
if (onDragStart) {
|
|
99
|
+
frame.update(() => onDragStart(event, info), false, true);
|
|
100
|
+
}
|
|
101
|
+
const { animationState } = this.visualElement;
|
|
102
|
+
animationState && animationState.setActive("whileDrag", true);
|
|
103
|
+
};
|
|
104
|
+
const onMove = (event, info) => {
|
|
105
|
+
// latestPointerEvent = event
|
|
106
|
+
const { dragPropagation, dragDirectionLock, onDirectionLock, onDrag, } = this.getProps();
|
|
107
|
+
// If we didn't successfully receive the gesture lock, early return.
|
|
108
|
+
if (!dragPropagation && !this.openGlobalLock)
|
|
109
|
+
return;
|
|
110
|
+
const { offset } = info;
|
|
111
|
+
// Attempt to detect drag direction if directionLock is true
|
|
112
|
+
if (dragDirectionLock && this.currentDirection === null) {
|
|
113
|
+
this.currentDirection = getCurrentDirection(offset);
|
|
114
|
+
// If we've successfully set a direction, notify listener
|
|
115
|
+
if (this.currentDirection !== null) {
|
|
116
|
+
onDirectionLock && onDirectionLock(this.currentDirection);
|
|
117
|
+
}
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
// Update each point with the latest position
|
|
121
|
+
this.updateAxis("x", info.point, offset);
|
|
122
|
+
this.updateAxis("y", info.point, offset);
|
|
123
|
+
/**
|
|
124
|
+
* Ideally we would leave the renderer to fire naturally at the end of
|
|
125
|
+
* this frame but if the element is about to change layout as the result
|
|
126
|
+
* of a re-render we want to ensure the browser can read the latest
|
|
127
|
+
* bounding box to ensure the pointer and element don't fall out of sync.
|
|
128
|
+
*/
|
|
129
|
+
this.visualElement.render();
|
|
130
|
+
/**
|
|
131
|
+
* This must fire after the render call as it might trigger a state
|
|
132
|
+
* change which itself might trigger a layout update.
|
|
133
|
+
*/
|
|
134
|
+
onDrag && onDrag(event, info);
|
|
135
|
+
};
|
|
136
|
+
const onSessionEnd = (event, info) => this.stop(event, info);
|
|
137
|
+
this.panSession = new PanSession(originEvent, {
|
|
138
|
+
onSessionStart,
|
|
139
|
+
onStart,
|
|
140
|
+
onMove,
|
|
141
|
+
onSessionEnd,
|
|
142
|
+
}, { transformPagePoint: this.visualElement.getTransformPagePoint() });
|
|
143
|
+
}
|
|
144
|
+
stop(event, info) {
|
|
145
|
+
const isDragging = this.isDragging;
|
|
146
|
+
this.cancel();
|
|
147
|
+
if (!isDragging)
|
|
148
|
+
return;
|
|
149
|
+
const { velocity } = info;
|
|
150
|
+
this.startAnimation(velocity);
|
|
151
|
+
const { onDragEnd } = this.getProps();
|
|
152
|
+
if (onDragEnd) {
|
|
153
|
+
frame.update(() => onDragEnd(event, info));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
cancel() {
|
|
157
|
+
this.isDragging = false;
|
|
158
|
+
const { projection, animationState } = this.visualElement;
|
|
159
|
+
if (projection) {
|
|
160
|
+
projection.isAnimationBlocked = false;
|
|
161
|
+
}
|
|
162
|
+
this.panSession && this.panSession.end();
|
|
163
|
+
this.panSession = undefined;
|
|
164
|
+
const { dragPropagation } = this.getProps();
|
|
165
|
+
if (!dragPropagation && this.openGlobalLock) {
|
|
166
|
+
this.openGlobalLock();
|
|
167
|
+
this.openGlobalLock = null;
|
|
168
|
+
}
|
|
169
|
+
animationState && animationState.setActive("whileDrag", false);
|
|
170
|
+
}
|
|
171
|
+
updateAxis(axis, _point, offset) {
|
|
172
|
+
const { drag } = this.getProps();
|
|
173
|
+
// If we're not dragging this axis, do an early return.
|
|
174
|
+
if (!offset || !shouldDrag(axis, drag, this.currentDirection))
|
|
175
|
+
return;
|
|
176
|
+
const axisValue = this.getAxisMotionValue(axis);
|
|
177
|
+
let next = this.originPoint[axis] + offset[axis];
|
|
178
|
+
// Apply constraints
|
|
179
|
+
if (this.constraints && this.constraints[axis]) {
|
|
180
|
+
next = applyConstraints(next, this.constraints[axis], this.elastic[axis]);
|
|
181
|
+
}
|
|
182
|
+
axisValue.set(next);
|
|
183
|
+
}
|
|
184
|
+
resolveConstraints() {
|
|
185
|
+
const { dragConstraints, dragElastic } = this.getProps();
|
|
186
|
+
const { layout } = this.visualElement.projection || {};
|
|
187
|
+
const prevConstraints = this.constraints;
|
|
188
|
+
if (dragConstraints && isRefObject(dragConstraints)) {
|
|
189
|
+
if (!this.constraints) {
|
|
190
|
+
this.constraints = this.resolveRefConstraints();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
if (dragConstraints && layout) {
|
|
195
|
+
this.constraints = calcRelativeConstraints(layout.layoutBox, dragConstraints);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
this.constraints = false;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
this.elastic = resolveDragElastic(dragElastic);
|
|
202
|
+
/**
|
|
203
|
+
* If we're outputting to external MotionValues, we want to rebase the measured constraints
|
|
204
|
+
* from viewport-relative to component-relative.
|
|
205
|
+
*/
|
|
206
|
+
if (prevConstraints !== this.constraints &&
|
|
207
|
+
layout &&
|
|
208
|
+
this.constraints &&
|
|
209
|
+
!this.hasMutatedConstraints) {
|
|
210
|
+
eachAxis((axis) => {
|
|
211
|
+
if (this.getAxisMotionValue(axis)) {
|
|
212
|
+
this.constraints[axis] = rebaseAxisConstraints(layout.layoutBox[axis], this.constraints[axis]);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
resolveRefConstraints() {
|
|
218
|
+
const { dragConstraints: constraints, onMeasureDragConstraints } = this.getProps();
|
|
219
|
+
if (!constraints || !isRefObject(constraints))
|
|
220
|
+
return false;
|
|
221
|
+
const constraintsElement = constraints.current;
|
|
222
|
+
invariant(constraintsElement !== null, "If `dragConstraints` is set as a React ref, that ref must be passed to another component's `ref` prop.");
|
|
223
|
+
const { projection } = this.visualElement;
|
|
224
|
+
// TODO
|
|
225
|
+
if (!projection || !projection.layout)
|
|
226
|
+
return false;
|
|
227
|
+
const constraintsBox = measurePageBox(constraintsElement, projection.root, this.visualElement.getTransformPagePoint());
|
|
228
|
+
let measuredConstraints = calcViewportConstraints(projection.layout.layoutBox, constraintsBox);
|
|
229
|
+
/**
|
|
230
|
+
* If there's an onMeasureDragConstraints listener we call it and
|
|
231
|
+
* if different constraints are returned, set constraints to that
|
|
232
|
+
*/
|
|
233
|
+
if (onMeasureDragConstraints) {
|
|
234
|
+
const userConstraints = onMeasureDragConstraints(convertBoxToBoundingBox(measuredConstraints));
|
|
235
|
+
this.hasMutatedConstraints = !!userConstraints;
|
|
236
|
+
if (userConstraints) {
|
|
237
|
+
measuredConstraints = convertBoundingBoxToBox(userConstraints);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return measuredConstraints;
|
|
241
|
+
}
|
|
242
|
+
startAnimation(velocity) {
|
|
243
|
+
const { drag, dragMomentum, dragElastic, dragTransition, dragSnapToOrigin, onDragTransitionEnd, } = this.getProps();
|
|
244
|
+
const constraints = this.constraints || {};
|
|
245
|
+
const momentumAnimations = eachAxis((axis) => {
|
|
246
|
+
if (!shouldDrag(axis, drag, this.currentDirection)) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
let transition = (constraints && constraints[axis]) || {};
|
|
250
|
+
if (dragSnapToOrigin)
|
|
251
|
+
transition = { min: 0, max: 0 };
|
|
252
|
+
/**
|
|
253
|
+
* Overdamp the boundary spring if `dragElastic` is disabled. There's still a frame
|
|
254
|
+
* of spring animations so we should look into adding a disable spring option to `inertia`.
|
|
255
|
+
* We could do something here where we affect the `bounceStiffness` and `bounceDamping`
|
|
256
|
+
* using the value of `dragElastic`.
|
|
257
|
+
*/
|
|
258
|
+
const bounceStiffness = dragElastic ? 200 : 1000000;
|
|
259
|
+
const bounceDamping = dragElastic ? 40 : 10000000;
|
|
260
|
+
const inertia = {
|
|
261
|
+
type: "inertia",
|
|
262
|
+
velocity: dragMomentum ? velocity[axis] : 0,
|
|
263
|
+
bounceStiffness,
|
|
264
|
+
bounceDamping,
|
|
265
|
+
timeConstant: 750,
|
|
266
|
+
restDelta: 1,
|
|
267
|
+
restSpeed: 10,
|
|
268
|
+
...dragTransition,
|
|
269
|
+
...transition,
|
|
270
|
+
};
|
|
271
|
+
// If we're not animating on an externally-provided `MotionValue` we can use the
|
|
272
|
+
// component's animation controls which will handle interactions with whileHover (etc),
|
|
273
|
+
// otherwise we just have to animate the `MotionValue` itself.
|
|
274
|
+
return this.startAxisValueAnimation(axis, inertia);
|
|
275
|
+
});
|
|
276
|
+
// Run all animations and then resolve the new drag constraints.
|
|
277
|
+
return Promise.all(momentumAnimations).then(onDragTransitionEnd);
|
|
278
|
+
}
|
|
279
|
+
startAxisValueAnimation(axis, transition) {
|
|
280
|
+
const axisValue = this.getAxisMotionValue(axis);
|
|
281
|
+
return axisValue.start(animateMotionValue(axis, axisValue, 0, transition));
|
|
282
|
+
}
|
|
283
|
+
stopAnimation() {
|
|
284
|
+
eachAxis((axis) => this.getAxisMotionValue(axis).stop());
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Drag works differently depending on which props are provided.
|
|
288
|
+
*
|
|
289
|
+
* - If _dragX and _dragY are provided, we output the gesture delta directly to those motion values.
|
|
290
|
+
* - Otherwise, we apply the delta to the x/y motion values.
|
|
291
|
+
*/
|
|
292
|
+
getAxisMotionValue(axis) {
|
|
293
|
+
const dragKey = "_drag" + axis.toUpperCase();
|
|
294
|
+
const props = this.visualElement.getProps();
|
|
295
|
+
const externalMotionValue = props[dragKey];
|
|
296
|
+
return externalMotionValue
|
|
297
|
+
? externalMotionValue
|
|
298
|
+
: this.visualElement.getValue(axis, (props.initial ? props.initial[axis] : undefined) || 0);
|
|
299
|
+
}
|
|
300
|
+
snapToCursor(point) {
|
|
301
|
+
eachAxis((axis) => {
|
|
302
|
+
const { drag } = this.getProps();
|
|
303
|
+
// If we're not dragging this axis, do an early return.
|
|
304
|
+
if (!shouldDrag(axis, drag, this.currentDirection))
|
|
305
|
+
return;
|
|
306
|
+
const { projection } = this.visualElement;
|
|
307
|
+
const axisValue = this.getAxisMotionValue(axis);
|
|
308
|
+
if (projection && projection.layout) {
|
|
309
|
+
const { min, max } = projection.layout.layoutBox[axis];
|
|
310
|
+
axisValue.set(point[axis] - mix(min, max, 0.5));
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* When the viewport resizes we want to check if the measured constraints
|
|
316
|
+
* have changed and, if so, reposition the element within those new constraints
|
|
317
|
+
* relative to where it was before the resize.
|
|
318
|
+
*/
|
|
319
|
+
scalePositionWithinConstraints() {
|
|
320
|
+
if (!this.visualElement.current)
|
|
321
|
+
return;
|
|
322
|
+
const { drag, dragConstraints } = this.getProps();
|
|
323
|
+
const { projection } = this.visualElement;
|
|
324
|
+
if (!isRefObject(dragConstraints) || !projection || !this.constraints)
|
|
325
|
+
return;
|
|
326
|
+
/**
|
|
327
|
+
* Stop current animations as there can be visual glitching if we try to do
|
|
328
|
+
* this mid-animation
|
|
329
|
+
*/
|
|
330
|
+
this.stopAnimation();
|
|
331
|
+
/**
|
|
332
|
+
* Record the relative position of the dragged element relative to the
|
|
333
|
+
* constraints box and save as a progress value.
|
|
334
|
+
*/
|
|
335
|
+
const boxProgress = { x: 0, y: 0 };
|
|
336
|
+
eachAxis((axis) => {
|
|
337
|
+
const axisValue = this.getAxisMotionValue(axis);
|
|
338
|
+
if (axisValue) {
|
|
339
|
+
const latest = axisValue.get();
|
|
340
|
+
boxProgress[axis] = calcOrigin({ min: latest, max: latest }, this.constraints[axis]);
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
/**
|
|
344
|
+
* Update the layout of this element and resolve the latest drag constraints
|
|
345
|
+
*/
|
|
346
|
+
const { transformTemplate } = this.visualElement.getProps();
|
|
347
|
+
this.visualElement.current.style.transform = transformTemplate
|
|
348
|
+
? transformTemplate({}, "")
|
|
349
|
+
: "none";
|
|
350
|
+
projection.root && projection.root.updateScroll();
|
|
351
|
+
projection.updateLayout();
|
|
352
|
+
this.resolveConstraints();
|
|
353
|
+
/**
|
|
354
|
+
* For each axis, calculate the current progress of the layout axis
|
|
355
|
+
* within the new constraints.
|
|
356
|
+
*/
|
|
357
|
+
eachAxis((axis) => {
|
|
358
|
+
if (!shouldDrag(axis, drag, null))
|
|
359
|
+
return;
|
|
360
|
+
/**
|
|
361
|
+
* Calculate a new transform based on the previous box progress
|
|
362
|
+
*/
|
|
363
|
+
const axisValue = this.getAxisMotionValue(axis);
|
|
364
|
+
const { min, max } = this.constraints[axis];
|
|
365
|
+
axisValue.set(mix(min, max, boxProgress[axis]));
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
addListeners() {
|
|
369
|
+
if (!this.visualElement.current)
|
|
370
|
+
return;
|
|
371
|
+
elementDragControls.set(this.visualElement, this);
|
|
372
|
+
const element = this.visualElement.current;
|
|
373
|
+
/**
|
|
374
|
+
* Attach a pointerdown event listener on this DOM element to initiate drag tracking.
|
|
375
|
+
*/
|
|
376
|
+
const stopPointerListener = addPointerEvent(element, "pointerdown", (event) => {
|
|
377
|
+
const { drag, dragListener = true } = this.getProps();
|
|
378
|
+
drag && dragListener && this.start(event);
|
|
379
|
+
});
|
|
380
|
+
const measureDragConstraints = () => {
|
|
381
|
+
const { dragConstraints } = this.getProps();
|
|
382
|
+
if (isRefObject(dragConstraints)) {
|
|
383
|
+
this.constraints = this.resolveRefConstraints();
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
const { projection } = this.visualElement;
|
|
387
|
+
const stopMeasureLayoutListener = projection.addEventListener("measure", measureDragConstraints);
|
|
388
|
+
if (projection && !projection.layout) {
|
|
389
|
+
projection.root && projection.root.updateScroll();
|
|
390
|
+
projection.updateLayout();
|
|
391
|
+
}
|
|
392
|
+
measureDragConstraints();
|
|
393
|
+
/**
|
|
394
|
+
* Attach a window resize listener to scale the draggable target within its defined
|
|
395
|
+
* constraints as the window resizes.
|
|
396
|
+
*/
|
|
397
|
+
const stopResizeListener = addDomEvent(window, "resize", () => this.scalePositionWithinConstraints());
|
|
398
|
+
/**
|
|
399
|
+
* If the element's layout changes, calculate the delta and apply that to
|
|
400
|
+
* the drag gesture's origin point.
|
|
401
|
+
*/
|
|
402
|
+
const stopLayoutUpdateListener = projection.addEventListener("didUpdate", (({ delta, hasLayoutChanged }) => {
|
|
403
|
+
if (this.isDragging && hasLayoutChanged) {
|
|
404
|
+
eachAxis((axis) => {
|
|
405
|
+
const motionValue = this.getAxisMotionValue(axis);
|
|
406
|
+
if (!motionValue)
|
|
407
|
+
return;
|
|
408
|
+
this.originPoint[axis] += delta[axis].translate;
|
|
409
|
+
motionValue.set(motionValue.get() + delta[axis].translate);
|
|
410
|
+
});
|
|
411
|
+
this.visualElement.render();
|
|
412
|
+
}
|
|
413
|
+
}));
|
|
414
|
+
return () => {
|
|
415
|
+
stopResizeListener();
|
|
416
|
+
stopPointerListener();
|
|
417
|
+
stopMeasureLayoutListener();
|
|
418
|
+
stopLayoutUpdateListener && stopLayoutUpdateListener();
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
getProps() {
|
|
422
|
+
const props = this.visualElement.getProps();
|
|
423
|
+
const { drag = false, dragDirectionLock = false, dragPropagation = false, dragConstraints = false, dragElastic = defaultElastic, dragMomentum = true, } = props;
|
|
424
|
+
return {
|
|
425
|
+
...props,
|
|
426
|
+
drag,
|
|
427
|
+
dragDirectionLock,
|
|
428
|
+
dragPropagation,
|
|
429
|
+
dragConstraints,
|
|
430
|
+
dragElastic,
|
|
431
|
+
dragMomentum,
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
function shouldDrag(direction, drag, currentDirection) {
|
|
436
|
+
return ((drag === true || drag === direction) &&
|
|
437
|
+
(currentDirection === null || currentDirection === direction));
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Based on an x/y offset determine the current drag direction. If both axis' offsets are lower
|
|
441
|
+
* than the provided threshold, return `null`.
|
|
442
|
+
*
|
|
443
|
+
* @param offset - The x/y offset from origin.
|
|
444
|
+
* @param lockThreshold - (Optional) - the minimum absolute offset before we can determine a drag direction.
|
|
445
|
+
*/
|
|
446
|
+
function getCurrentDirection(offset, lockThreshold = 10) {
|
|
447
|
+
let direction = null;
|
|
448
|
+
if (Math.abs(offset.y) > lockThreshold) {
|
|
449
|
+
direction = "y";
|
|
450
|
+
}
|
|
451
|
+
else if (Math.abs(offset.x) > lockThreshold) {
|
|
452
|
+
direction = "x";
|
|
453
|
+
}
|
|
454
|
+
return direction;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
export { VisualElementDragControls, elementDragControls };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Feature } from '../../motion/features/Feature.js';
|
|
2
|
+
import { noop } from '../../utils/noop.js';
|
|
3
|
+
import { VisualElementDragControls } from './VisualElementDragControls.js';
|
|
4
|
+
|
|
5
|
+
class DragGesture extends Feature {
|
|
6
|
+
constructor(node) {
|
|
7
|
+
super(node);
|
|
8
|
+
this.removeGroupControls = noop;
|
|
9
|
+
this.removeListeners = noop;
|
|
10
|
+
this.controls = new VisualElementDragControls(node);
|
|
11
|
+
}
|
|
12
|
+
mount() {
|
|
13
|
+
// If we've been provided a DragControls for manual control over the drag gesture,
|
|
14
|
+
// subscribe this component to it on mount.
|
|
15
|
+
const { dragControls } = this.node.getProps();
|
|
16
|
+
if (dragControls) {
|
|
17
|
+
this.removeGroupControls = dragControls.subscribe(this.controls);
|
|
18
|
+
}
|
|
19
|
+
this.removeListeners = this.controls.addListeners() || noop;
|
|
20
|
+
}
|
|
21
|
+
unmount() {
|
|
22
|
+
this.removeGroupControls();
|
|
23
|
+
this.removeListeners();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { DragGesture };
|