@helpdice/draggable 0.0.0-stage → 0.0.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/LICENSE +13 -0
- package/README.md +164 -2
- package/dist/draggable.cjs.js +9925 -0
- package/dist/draggable.cjs.js.map +1 -0
- package/dist/draggable.esm.js +9899 -0
- package/dist/draggable.esm.js.map +1 -0
- package/dist/types/animation.d.ts +31 -0
- package/dist/types/debug/middleware/action-timing-average.d.ts +3 -0
- package/dist/types/debug/middleware/action-timing.d.ts +3 -0
- package/dist/types/debug/middleware/log.d.ts +4 -0
- package/dist/types/debug/middleware/user-timing.d.ts +3 -0
- package/dist/types/debug/timings.d.ts +3 -0
- package/dist/types/dev-warning.d.ts +4 -0
- package/dist/types/empty.d.ts +2 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/invariant.d.ts +4 -0
- package/dist/types/native-with-fallback.d.ts +10 -0
- package/dist/types/screen-reader-message-preset.d.ts +9 -0
- package/dist/types/state/action-creators.d.ts +158 -0
- package/dist/types/state/auto-scroller/auto-scroller-types.d.ts +6 -0
- package/dist/types/state/auto-scroller/can-scroll.d.ts +19 -0
- package/dist/types/state/auto-scroller/fluid-scroller/config.d.ts +11 -0
- package/dist/types/state/auto-scroller/fluid-scroller/did-start-in-scrollable-area.d.ts +0 -0
- package/dist/types/state/auto-scroller/fluid-scroller/get-best-scrollable-droppable.d.ts +9 -0
- package/dist/types/state/auto-scroller/fluid-scroller/get-droppable-scroll-change.d.ts +11 -0
- package/dist/types/state/auto-scroller/fluid-scroller/get-percentage.d.ts +7 -0
- package/dist/types/state/auto-scroller/fluid-scroller/get-scroll/adjust-for-size-limits.d.ts +8 -0
- package/dist/types/state/auto-scroller/fluid-scroller/get-scroll/get-scroll-on-axis/dampen-value-by-time.d.ts +2 -0
- package/dist/types/state/auto-scroller/fluid-scroller/get-scroll/get-scroll-on-axis/get-distance-thresholds.d.ts +8 -0
- package/dist/types/state/auto-scroller/fluid-scroller/get-scroll/get-scroll-on-axis/get-value-from-distance.d.ts +3 -0
- package/dist/types/state/auto-scroller/fluid-scroller/get-scroll/get-scroll-on-axis/get-value.d.ts +9 -0
- package/dist/types/state/auto-scroller/fluid-scroller/get-scroll/get-scroll-on-axis/index.d.ts +11 -0
- package/dist/types/state/auto-scroller/fluid-scroller/get-scroll/get-scroll-on-axis/min-scroll.d.ts +2 -0
- package/dist/types/state/auto-scroller/fluid-scroller/get-scroll/index.d.ts +10 -0
- package/dist/types/state/auto-scroller/fluid-scroller/get-window-scroll-change.d.ts +11 -0
- package/dist/types/state/auto-scroller/fluid-scroller/index.d.ts +13 -0
- package/dist/types/state/auto-scroller/fluid-scroller/scroll.d.ts +11 -0
- package/dist/types/state/auto-scroller/index.d.ts +11 -0
- package/dist/types/state/auto-scroller/jump-scroller.d.ts +11 -0
- package/dist/types/state/axis.d.ts +3 -0
- package/dist/types/state/calculate-drag-impact/calculate-reorder-impact.d.ts +13 -0
- package/dist/types/state/can-start-drag.d.ts +3 -0
- package/dist/types/state/create-store.d.ts +16 -0
- package/dist/types/state/did-start-after-critical.d.ts +2 -0
- package/dist/types/state/dimension-marshal/dimension-marshal-types.d.ts +23 -0
- package/dist/types/state/dimension-marshal/dimension-marshal.d.ts +4 -0
- package/dist/types/state/dimension-marshal/get-initial-publish.d.ts +10 -0
- package/dist/types/state/dimension-marshal/while-dragging-publisher.d.ts +17 -0
- package/dist/types/state/dimension-structures.d.ts +5 -0
- package/dist/types/state/droppable/get-droppable.d.ts +21 -0
- package/dist/types/state/droppable/is-home-of.d.ts +3 -0
- package/dist/types/state/droppable/scroll-droppable.d.ts +4 -0
- package/dist/types/state/droppable/should-use-placeholder.d.ts +3 -0
- package/dist/types/state/droppable/util/clip.d.ts +3 -0
- package/dist/types/state/droppable/util/get-subject.d.ts +10 -0
- package/dist/types/state/droppable/what-is-dragged-over-from-result.d.ts +3 -0
- package/dist/types/state/droppable/what-is-dragged-over.d.ts +3 -0
- package/dist/types/state/droppable/with-placeholder.d.ts +3 -0
- package/dist/types/state/get-center-from-impact/get-client-border-box-center/get-client-from-page-border-box-center.d.ts +9 -0
- package/dist/types/state/get-center-from-impact/get-client-border-box-center/index.d.ts +12 -0
- package/dist/types/state/get-center-from-impact/get-page-border-box-center/index.d.ts +11 -0
- package/dist/types/state/get-center-from-impact/get-page-border-box-center/when-combining.d.ts +9 -0
- package/dist/types/state/get-center-from-impact/get-page-border-box-center/when-reordering.d.ts +11 -0
- package/dist/types/state/get-center-from-impact/move-relative-to.d.ts +16 -0
- package/dist/types/state/get-combined-item-displacement.d.ts +10 -0
- package/dist/types/state/get-displaced-by.d.ts +4 -0
- package/dist/types/state/get-displacement-groups.d.ts +12 -0
- package/dist/types/state/get-drag-impact/get-combine-impact.d.ts +13 -0
- package/dist/types/state/get-drag-impact/get-reorder-impact.d.ts +13 -0
- package/dist/types/state/get-drag-impact/index.d.ts +13 -0
- package/dist/types/state/get-draggables-inside-droppable.d.ts +3 -0
- package/dist/types/state/get-droppable-over.d.ts +9 -0
- package/dist/types/state/get-frame.d.ts +3 -0
- package/dist/types/state/get-home-location.d.ts +3 -0
- package/dist/types/state/get-impact-location.d.ts +3 -0
- package/dist/types/state/get-is-displaced.d.ts +7 -0
- package/dist/types/state/get-lift-effect.d.ts +13 -0
- package/dist/types/state/get-max-scroll.d.ts +9 -0
- package/dist/types/state/is-movement-allowed.d.ts +2 -0
- package/dist/types/state/is-within.d.ts +2 -0
- package/dist/types/state/middleware/auto-scroll.d.ts +4 -0
- package/dist/types/state/middleware/dimension-marshal-stopper.d.ts +4 -0
- package/dist/types/state/middleware/drop/drop-animation-finish-middleware.d.ts +3 -0
- package/dist/types/state/middleware/drop/drop-animation-flush-on-scroll-middleware.d.ts +3 -0
- package/dist/types/state/middleware/drop/drop-middleware.d.ts +3 -0
- package/dist/types/state/middleware/drop/get-drop-duration.d.ts +9 -0
- package/dist/types/state/middleware/drop/get-drop-impact.d.ts +16 -0
- package/dist/types/state/middleware/drop/get-new-home-client-offset.d.ts +11 -0
- package/dist/types/state/middleware/drop/index.d.ts +1 -0
- package/dist/types/state/middleware/focus.d.ts +4 -0
- package/dist/types/state/middleware/lift.d.ts +4 -0
- package/dist/types/state/middleware/pending-drop.d.ts +3 -0
- package/dist/types/state/middleware/responders/async-marshal.d.ts +9 -0
- package/dist/types/state/middleware/responders/expiring-announce.d.ts +6 -0
- package/dist/types/state/middleware/responders/index.d.ts +1 -0
- package/dist/types/state/middleware/responders/is-equal.d.ts +4 -0
- package/dist/types/state/middleware/responders/publisher.d.ts +17 -0
- package/dist/types/state/middleware/responders/responders-middleware.d.ts +4 -0
- package/dist/types/state/middleware/scroll-listener.d.ts +3 -0
- package/dist/types/state/middleware/style.d.ts +4 -0
- package/dist/types/state/middleware/util/validate-dimensions.d.ts +2 -0
- package/dist/types/state/move-in-direction/index.d.ts +8 -0
- package/dist/types/state/move-in-direction/move-cross-axis/get-best-cross-axis-droppable.d.ts +11 -0
- package/dist/types/state/move-in-direction/move-cross-axis/get-closest-draggable.d.ts +11 -0
- package/dist/types/state/move-in-direction/move-cross-axis/index.d.ts +15 -0
- package/dist/types/state/move-in-direction/move-cross-axis/move-to-new-droppable.d.ts +14 -0
- package/dist/types/state/move-in-direction/move-cross-axis/without-starting-displacement.d.ts +4 -0
- package/dist/types/state/move-in-direction/move-in-direction-types.d.ts +7 -0
- package/dist/types/state/move-in-direction/move-to-next-place/index.d.ts +16 -0
- package/dist/types/state/move-in-direction/move-to-next-place/is-totally-visible-in-new-location.d.ts +12 -0
- package/dist/types/state/move-in-direction/move-to-next-place/move-to-next-combine/index.d.ts +10 -0
- package/dist/types/state/move-in-direction/move-to-next-place/move-to-next-index/from-combine.d.ts +11 -0
- package/dist/types/state/move-in-direction/move-to-next-place/move-to-next-index/from-reorder.d.ts +9 -0
- package/dist/types/state/move-in-direction/move-to-next-place/move-to-next-index/index.d.ts +14 -0
- package/dist/types/state/no-impact.d.ts +6 -0
- package/dist/types/state/patch-dimension-map.d.ts +3 -0
- package/dist/types/state/patch-droppable-map.d.ts +3 -0
- package/dist/types/state/position.d.ts +10 -0
- package/dist/types/state/post-reducer/when-moving/refresh-snap.d.ts +8 -0
- package/dist/types/state/post-reducer/when-moving/update.d.ts +12 -0
- package/dist/types/state/publish-while-dragging-in-virtual/adjust-additions-for-scroll-changes.d.ts +8 -0
- package/dist/types/state/publish-while-dragging-in-virtual/index.d.ts +7 -0
- package/dist/types/state/publish-while-dragging-in-virtual/offset-draggable.d.ts +9 -0
- package/dist/types/state/recompute-placeholders.d.ts +10 -0
- package/dist/types/state/rect.d.ts +2 -0
- package/dist/types/state/reducer.d.ts +5 -0
- package/dist/types/state/registry/create-registry.d.ts +2 -0
- package/dist/types/state/registry/registry-types.d.ts +62 -0
- package/dist/types/state/registry/use-registry.d.ts +2 -0
- package/dist/types/state/remove-draggable-from-list.d.ts +3 -0
- package/dist/types/state/scroll-viewport.d.ts +4 -0
- package/dist/types/state/spacing.d.ts +6 -0
- package/dist/types/state/store-types.d.ts +10 -0
- package/dist/types/state/update-displacement-visibility/recompute.d.ts +10 -0
- package/dist/types/state/update-displacement-visibility/speculatively-increase.d.ts +11 -0
- package/dist/types/state/visibility/is-partially-visible-through-frame.d.ts +3 -0
- package/dist/types/state/visibility/is-position-in-frame.d.ts +2 -0
- package/dist/types/state/visibility/is-totally-visible-through-frame-on-axis.d.ts +4 -0
- package/dist/types/state/visibility/is-totally-visible-through-frame.d.ts +3 -0
- package/dist/types/state/visibility/is-visible.d.ts +13 -0
- package/dist/types/state/with-scroll-change/with-all-displacement.d.ts +4 -0
- package/dist/types/state/with-scroll-change/with-droppable-displacement.d.ts +4 -0
- package/dist/types/state/with-scroll-change/with-droppable-scroll.d.ts +4 -0
- package/dist/types/state/with-scroll-change/with-viewport-displacement.d.ts +4 -0
- package/dist/types/types.d.ts +323 -0
- package/dist/types/view/animate-in-out/animate-in-out.d.ts +24 -0
- package/dist/types/view/animate-in-out/index.d.ts +1 -0
- package/dist/types/view/check-is-valid-inner-ref.d.ts +1 -0
- package/dist/types/view/context/app-context.d.ts +16 -0
- package/dist/types/view/context/droppable-context.d.ts +9 -0
- package/dist/types/view/context/hooks.d.ts +3 -0
- package/dist/types/view/context/store-context.d.ts +4 -0
- package/dist/types/view/data-attributes.d.ts +22 -0
- package/dist/types/view/drag-drop-context/app.d.ts +13 -0
- package/dist/types/view/drag-drop-context/check-doctype.d.ts +2 -0
- package/dist/types/view/drag-drop-context/check-react-version.d.ts +2 -0
- package/dist/types/view/drag-drop-context/drag-drop-context-types.d.ts +5 -0
- package/dist/types/view/drag-drop-context/drag-drop-context.d.ts +12 -0
- package/dist/types/view/drag-drop-context/error-boundary.d.ts +20 -0
- package/dist/types/view/drag-drop-context/index.d.ts +1 -0
- package/dist/types/view/drag-drop-context/use-startup-validation.d.ts +1 -0
- package/dist/types/view/drag-drop-context/use-unique-context-id.d.ts +3 -0
- package/dist/types/view/draggable/connected-draggable.d.ts +5 -0
- package/dist/types/view/draggable/draggable-api.d.ts +3 -0
- package/dist/types/view/draggable/draggable-types.d.ts +106 -0
- package/dist/types/view/draggable/draggable.d.ts +2 -0
- package/dist/types/view/draggable/get-style.d.ts +3 -0
- package/dist/types/view/draggable/index.d.ts +1 -0
- package/dist/types/view/draggable/use-validation.d.ts +4 -0
- package/dist/types/view/droppable/connected-droppable.d.ts +7 -0
- package/dist/types/view/droppable/droppable-types.d.ts +50 -0
- package/dist/types/view/droppable/droppable.d.ts +2 -0
- package/dist/types/view/droppable/index.d.ts +1 -0
- package/dist/types/view/droppable/use-validation.d.ts +8 -0
- package/dist/types/view/event-bindings/bind-events.d.ts +2 -0
- package/dist/types/view/event-bindings/event-types.d.ts +10 -0
- package/dist/types/view/get-body-element.d.ts +2 -0
- package/dist/types/view/get-border-box-center-position.d.ts +3 -0
- package/dist/types/view/get-document-element.d.ts +2 -0
- package/dist/types/view/get-elements/find-drag-handle.d.ts +2 -0
- package/dist/types/view/get-elements/find-draggable.d.ts +2 -0
- package/dist/types/view/is-strict-equal.d.ts +2 -0
- package/dist/types/view/is-type-of-element/is-element.d.ts +1 -0
- package/dist/types/view/is-type-of-element/is-html-element.d.ts +1 -0
- package/dist/types/view/is-type-of-element/is-svg-element.d.ts +1 -0
- package/dist/types/view/key-codes.d.ts +12 -0
- package/dist/types/view/placeholder/index.d.ts +1 -0
- package/dist/types/view/placeholder/placeholder-types.d.ts +14 -0
- package/dist/types/view/placeholder/placeholder.d.ts +28 -0
- package/dist/types/view/scroll-listener.d.ts +12 -0
- package/dist/types/view/throw-if-invalid-inner-ref.d.ts +2 -0
- package/dist/types/view/use-announcer/index.d.ts +1 -0
- package/dist/types/view/use-announcer/use-announcer.d.ts +3 -0
- package/dist/types/view/use-dev-setup-warning.d.ts +1 -0
- package/dist/types/view/use-dev.d.ts +1 -0
- package/dist/types/view/use-draggable-publisher/get-dimension.d.ts +3 -0
- package/dist/types/view/use-draggable-publisher/index.d.ts +1 -0
- package/dist/types/view/use-draggable-publisher/use-draggable-publisher.d.ts +8 -0
- package/dist/types/view/use-droppable-publisher/check-for-nested-scroll-container.d.ts +2 -0
- package/dist/types/view/use-droppable-publisher/get-closest-scrollable.d.ts +2 -0
- package/dist/types/view/use-droppable-publisher/get-dimension.d.ts +15 -0
- package/dist/types/view/use-droppable-publisher/get-env.d.ts +6 -0
- package/dist/types/view/use-droppable-publisher/get-listener-options.d.ts +5 -0
- package/dist/types/view/use-droppable-publisher/get-scroll.d.ts +3 -0
- package/dist/types/view/use-droppable-publisher/index.d.ts +1 -0
- package/dist/types/view/use-droppable-publisher/is-in-fixed-container.d.ts +2 -0
- package/dist/types/view/use-droppable-publisher/use-droppable-publisher.d.ts +13 -0
- package/dist/types/view/use-focus-marshal/focus-marshal-types.d.ts +9 -0
- package/dist/types/view/use-focus-marshal/index.d.ts +1 -0
- package/dist/types/view/use-focus-marshal/use-focus-marshal.d.ts +3 -0
- package/dist/types/view/use-hidden-text-element/index.d.ts +1 -0
- package/dist/types/view/use-hidden-text-element/use-hidden-text-element.d.ts +12 -0
- package/dist/types/view/use-isomorphic-layout-effect.d.ts +3 -0
- package/dist/types/view/use-previous-ref.d.ts +1 -0
- package/dist/types/view/use-required-context.d.ts +2 -0
- package/dist/types/view/use-sensor-marshal/closest.d.ts +1 -0
- package/dist/types/view/use-sensor-marshal/find-closest-draggable-id-from-event.d.ts +2 -0
- package/dist/types/view/use-sensor-marshal/index.d.ts +4 -0
- package/dist/types/view/use-sensor-marshal/is-event-in-interactive-element.d.ts +5 -0
- package/dist/types/view/use-sensor-marshal/lock.d.ts +11 -0
- package/dist/types/view/use-sensor-marshal/sensors/use-keyboard-sensor.d.ts +2 -0
- package/dist/types/view/use-sensor-marshal/sensors/use-mouse-sensor.d.ts +4 -0
- package/dist/types/view/use-sensor-marshal/sensors/use-touch-sensor.d.ts +4 -0
- package/dist/types/view/use-sensor-marshal/sensors/util/prevent-standard-key-events.d.ts +2 -0
- package/dist/types/view/use-sensor-marshal/sensors/util/supported-page-visibility-event-name.d.ts +2 -0
- package/dist/types/view/use-sensor-marshal/use-sensor-marshal.d.ts +12 -0
- package/dist/types/view/use-sensor-marshal/use-validate-sensor-hooks.d.ts +2 -0
- package/dist/types/view/use-style-marshal/get-styles.d.ts +10 -0
- package/dist/types/view/use-style-marshal/index.d.ts +1 -0
- package/dist/types/view/use-style-marshal/style-marshal-types.d.ts +6 -0
- package/dist/types/view/use-style-marshal/use-style-marshal.d.ts +3 -0
- package/dist/types/view/use-unique-id.d.ts +7 -0
- package/dist/types/view/visually-hidden-style.d.ts +2 -0
- package/dist/types/view/window/get-max-window-scroll.d.ts +3 -0
- package/dist/types/view/window/get-viewport.d.ts +3 -0
- package/dist/types/view/window/get-window-from-el.d.ts +2 -0
- package/dist/types/view/window/get-window-scroll.d.ts +3 -0
- package/dist/types/view/window/scroll-window.d.ts +3 -0
- package/package.json +157 -4
- package/src/animation.ts +75 -0
- package/src/debug/middleware/action-timing-average.ts +52 -0
- package/src/debug/middleware/action-timing.ts +16 -0
- package/src/debug/middleware/log.ts +26 -0
- package/src/debug/middleware/user-timing.ts +16 -0
- package/src/debug/timings.ts +87 -0
- package/src/dev-warning.ts +50 -0
- package/src/empty.ts +6 -0
- package/src/index.ts +67 -0
- package/src/invariant.ts +64 -0
- package/src/native-with-fallback.ts +69 -0
- package/src/screen-reader-message-preset.ts +135 -0
- package/src/state/action-creators.ts +358 -0
- package/src/state/auto-scroller/auto-scroller-types.ts +8 -0
- package/src/state/auto-scroller/can-scroll.ts +320 -0
- package/src/state/auto-scroller/fluid-scroller/config.ts +25 -0
- package/src/state/auto-scroller/fluid-scroller/did-start-in-scrollable-area.ts +1 -0
- package/src/state/auto-scroller/fluid-scroller/get-best-scrollable-droppable.ts +77 -0
- package/src/state/auto-scroller/fluid-scroller/get-droppable-scroll-change.ts +39 -0
- package/src/state/auto-scroller/fluid-scroller/get-percentage.ts +25 -0
- package/src/state/auto-scroller/fluid-scroller/get-scroll/adjust-for-size-limits.ts +30 -0
- package/src/state/auto-scroller/fluid-scroller/get-scroll/get-scroll-on-axis/dampen-value-by-time.ts +37 -0
- package/src/state/auto-scroller/fluid-scroller/get-scroll/get-scroll-on-axis/get-distance-thresholds.ts +25 -0
- package/src/state/auto-scroller/fluid-scroller/get-scroll/get-scroll-on-axis/get-value-from-distance.ts +61 -0
- package/src/state/auto-scroller/fluid-scroller/get-scroll/get-scroll-on-axis/get-value.ts +39 -0
- package/src/state/auto-scroller/fluid-scroller/get-scroll/get-scroll-on-axis/index.ts +46 -0
- package/src/state/auto-scroller/fluid-scroller/get-scroll/get-scroll-on-axis/min-scroll.ts +4 -0
- package/src/state/auto-scroller/fluid-scroller/get-scroll/index.ts +76 -0
- package/src/state/auto-scroller/fluid-scroller/get-window-scroll-change.ts +31 -0
- package/src/state/auto-scroller/fluid-scroller/index.ts +91 -0
- package/src/state/auto-scroller/fluid-scroller/scroll.ts +72 -0
- package/src/state/auto-scroller/index.ts +56 -0
- package/src/state/auto-scroller/jump-scroller.ts +140 -0
- package/src/state/axis.ts +26 -0
- package/src/state/calculate-drag-impact/calculate-reorder-impact.ts +138 -0
- package/src/state/can-start-drag.ts +29 -0
- package/src/state/create-store.ts +98 -0
- package/src/state/did-start-after-critical.ts +9 -0
- package/src/state/dimension-marshal/dimension-marshal-types.ts +49 -0
- package/src/state/dimension-marshal/dimension-marshal.ts +219 -0
- package/src/state/dimension-marshal/get-initial-publish.ts +66 -0
- package/src/state/dimension-marshal/while-dragging-publisher.ts +146 -0
- package/src/state/dimension-structures.ts +35 -0
- package/src/state/droppable/get-droppable.ts +103 -0
- package/src/state/droppable/is-home-of.ts +7 -0
- package/src/state/droppable/scroll-droppable.ts +53 -0
- package/src/state/droppable/should-use-placeholder.ts +7 -0
- package/src/state/droppable/util/clip.ts +17 -0
- package/src/state/droppable/util/get-subject.ts +63 -0
- package/src/state/droppable/what-is-dragged-over-from-result.ts +16 -0
- package/src/state/droppable/what-is-dragged-over.ts +16 -0
- package/src/state/droppable/with-placeholder.ts +174 -0
- package/src/state/get-center-from-impact/get-client-border-box-center/get-client-from-page-border-box-center.ts +30 -0
- package/src/state/get-center-from-impact/get-client-border-box-center/index.ts +45 -0
- package/src/state/get-center-from-impact/get-page-border-box-center/index.ts +71 -0
- package/src/state/get-center-from-impact/get-page-border-box-center/when-combining.ts +40 -0
- package/src/state/get-center-from-impact/get-page-border-box-center/when-reordering.ts +113 -0
- package/src/state/get-center-from-impact/move-relative-to.ts +68 -0
- package/src/state/get-combined-item-displacement.ts +35 -0
- package/src/state/get-displaced-by.ts +17 -0
- package/src/state/get-displacement-groups.ts +131 -0
- package/src/state/get-drag-impact/get-combine-impact.ts +131 -0
- package/src/state/get-drag-impact/get-reorder-impact.ts +145 -0
- package/src/state/get-drag-impact/index.ts +94 -0
- package/src/state/get-draggables-inside-droppable.ts +31 -0
- package/src/state/get-droppable-over.ts +161 -0
- package/src/state/get-frame.ts +10 -0
- package/src/state/get-home-location.ts +7 -0
- package/src/state/get-impact-location.ts +16 -0
- package/src/state/get-is-displaced.ts +12 -0
- package/src/state/get-lift-effect.ts +84 -0
- package/src/state/get-max-scroll.ts +32 -0
- package/src/state/is-movement-allowed.ts +13 -0
- package/src/state/is-within.ts +9 -0
- package/src/state/middleware/auto-scroll.ts +38 -0
- package/src/state/middleware/dimension-marshal-stopper.ts +20 -0
- package/src/state/middleware/drop/drop-animation-finish-middleware.ts +21 -0
- package/src/state/middleware/drop/drop-animation-flush-on-scroll-middleware.ts +63 -0
- package/src/state/middleware/drop/drop-middleware.ts +146 -0
- package/src/state/middleware/drop/get-drop-duration.ts +48 -0
- package/src/state/middleware/drop/get-drop-impact.ts +79 -0
- package/src/state/middleware/drop/get-new-home-client-offset.ts +55 -0
- package/src/state/middleware/drop/index.ts +2 -0
- package/src/state/middleware/focus.ts +42 -0
- package/src/state/middleware/lift.ts +66 -0
- package/src/state/middleware/pending-drop.ts +37 -0
- package/src/state/middleware/responders/async-marshal.ts +58 -0
- package/src/state/middleware/responders/expiring-announce.ts +44 -0
- package/src/state/middleware/responders/index.ts +2 -0
- package/src/state/middleware/responders/is-equal.ts +57 -0
- package/src/state/middleware/responders/publisher.ts +255 -0
- package/src/state/middleware/responders/responders-middleware.ts +81 -0
- package/src/state/middleware/scroll-listener.ts +31 -0
- package/src/state/middleware/style.ts +22 -0
- package/src/state/middleware/util/validate-dimensions.ts +71 -0
- package/src/state/move-in-direction/index.ts +85 -0
- package/src/state/move-in-direction/move-cross-axis/get-best-cross-axis-droppable.ts +169 -0
- package/src/state/move-in-direction/move-cross-axis/get-closest-draggable.ts +80 -0
- package/src/state/move-in-direction/move-cross-axis/index.ts +110 -0
- package/src/state/move-in-direction/move-cross-axis/move-to-new-droppable.ts +122 -0
- package/src/state/move-in-direction/move-cross-axis/without-starting-displacement.ts +31 -0
- package/src/state/move-in-direction/move-in-direction-types.ts +10 -0
- package/src/state/move-in-direction/move-to-next-place/index.ts +133 -0
- package/src/state/move-in-direction/move-to-next-place/is-totally-visible-in-new-location.ts +53 -0
- package/src/state/move-in-direction/move-to-next-place/move-to-next-combine/index.ts +98 -0
- package/src/state/move-in-direction/move-to-next-place/move-to-next-index/from-combine.ts +53 -0
- package/src/state/move-in-direction/move-to-next-place/move-to-next-index/from-reorder.ts +44 -0
- package/src/state/move-in-direction/move-to-next-place/move-to-next-index/index.ts +87 -0
- package/src/state/no-impact.ts +33 -0
- package/src/state/patch-dimension-map.ts +11 -0
- package/src/state/patch-droppable-map.ts +10 -0
- package/src/state/position.ts +65 -0
- package/src/state/post-reducer/when-moving/refresh-snap.ts +68 -0
- package/src/state/post-reducer/when-moving/update.ts +121 -0
- package/src/state/publish-while-dragging-in-virtual/adjust-additions-for-scroll-changes.ts +59 -0
- package/src/state/publish-while-dragging-in-virtual/index.ts +159 -0
- package/src/state/publish-while-dragging-in-virtual/offset-draggable.ts +36 -0
- package/src/state/recompute-placeholders.ts +101 -0
- package/src/state/rect.ts +7 -0
- package/src/state/reducer.ts +467 -0
- package/src/state/registry/create-registry.ts +162 -0
- package/src/state/registry/registry-types.ts +106 -0
- package/src/state/registry/use-registry.ts +20 -0
- package/src/state/remove-draggable-from-list.ts +13 -0
- package/src/state/scroll-viewport.ts +34 -0
- package/src/state/spacing.ts +45 -0
- package/src/state/store-types.ts +19 -0
- package/src/state/update-displacement-visibility/recompute.ts +55 -0
- package/src/state/update-displacement-visibility/speculatively-increase.ts +112 -0
- package/src/state/visibility/is-partially-visible-through-frame.ts +60 -0
- package/src/state/visibility/is-position-in-frame.ts +12 -0
- package/src/state/visibility/is-totally-visible-through-frame-on-axis.ts +19 -0
- package/src/state/visibility/is-totally-visible-through-frame.ts +18 -0
- package/src/state/visibility/is-visible.ts +102 -0
- package/src/state/with-scroll-change/with-all-displacement.ts +15 -0
- package/src/state/with-scroll-change/with-droppable-displacement.ts +13 -0
- package/src/state/with-scroll-change/with-droppable-scroll.ts +13 -0
- package/src/state/with-scroll-change/with-viewport-displacement.ts +7 -0
- package/src/types/redux-devtools.d.ts +17 -0
- package/src/types.ts +495 -0
- package/src/view/animate-in-out/animate-in-out.tsx +98 -0
- package/src/view/animate-in-out/index.ts +2 -0
- package/src/view/check-is-valid-inner-ref.ts +15 -0
- package/src/view/context/app-context.ts +19 -0
- package/src/view/context/droppable-context.ts +12 -0
- package/src/view/context/hooks.ts +21 -0
- package/src/view/context/store-context.ts +8 -0
- package/src/view/data-attributes.ts +37 -0
- package/src/view/drag-drop-context/app.tsx +300 -0
- package/src/view/drag-drop-context/check-doctype.ts +39 -0
- package/src/view/drag-drop-context/check-react-version.ts +72 -0
- package/src/view/drag-drop-context/drag-drop-context-types.ts +8 -0
- package/src/view/drag-drop-context/drag-drop-context.tsx +60 -0
- package/src/view/drag-drop-context/error-boundary.tsx +89 -0
- package/src/view/drag-drop-context/index.ts +2 -0
- package/src/view/drag-drop-context/use-startup-validation.ts +13 -0
- package/src/view/drag-drop-context/use-unique-context-id.ts +13 -0
- package/src/view/draggable/connected-draggable.tsx +420 -0
- package/src/view/draggable/draggable-api.tsx +48 -0
- package/src/view/draggable/draggable-types.ts +204 -0
- package/src/view/draggable/draggable.tsx +167 -0
- package/src/view/draggable/get-style.ts +109 -0
- package/src/view/draggable/index.ts +2 -0
- package/src/view/draggable/use-validation.ts +70 -0
- package/src/view/droppable/connected-droppable.tsx +597 -0
- package/src/view/droppable/droppable-types.ts +96 -0
- package/src/view/droppable/droppable.tsx +167 -0
- package/src/view/droppable/index.ts +2 -0
- package/src/view/droppable/use-validation.ts +102 -0
- package/src/view/event-bindings/bind-events.ts +39 -0
- package/src/view/event-bindings/event-types.ts +15 -0
- package/src/view/get-body-element.ts +8 -0
- package/src/view/get-border-box-center-position.ts +5 -0
- package/src/view/get-document-element.ts +8 -0
- package/src/view/get-elements/find-drag-handle.ts +38 -0
- package/src/view/get-elements/find-draggable.ts +30 -0
- package/src/view/is-strict-equal.ts +2 -0
- package/src/view/is-type-of-element/is-element.ts +10 -0
- package/src/view/is-type-of-element/is-html-element.ts +10 -0
- package/src/view/is-type-of-element/is-svg-element.ts +22 -0
- package/src/view/key-codes.ts +13 -0
- package/src/view/placeholder/index.ts +2 -0
- package/src/view/placeholder/placeholder-types.ts +16 -0
- package/src/view/placeholder/placeholder.tsx +204 -0
- package/src/view/scroll-listener.ts +74 -0
- package/src/view/throw-if-invalid-inner-ref.ts +15 -0
- package/src/view/use-announcer/index.ts +2 -0
- package/src/view/use-announcer/use-announcer.ts +80 -0
- package/src/view/use-dev-setup-warning.ts +22 -0
- package/src/view/use-dev.ts +9 -0
- package/src/view/use-draggable-publisher/get-dimension.ts +44 -0
- package/src/view/use-draggable-publisher/index.ts +2 -0
- package/src/view/use-draggable-publisher/use-draggable-publisher.ts +87 -0
- package/src/view/use-droppable-publisher/check-for-nested-scroll-container.ts +27 -0
- package/src/view/use-droppable-publisher/get-closest-scrollable.ts +96 -0
- package/src/view/use-droppable-publisher/get-dimension.ts +140 -0
- package/src/view/use-droppable-publisher/get-env.ts +32 -0
- package/src/view/use-droppable-publisher/get-listener-options.ts +12 -0
- package/src/view/use-droppable-publisher/get-scroll.ts +7 -0
- package/src/view/use-droppable-publisher/index.ts +2 -0
- package/src/view/use-droppable-publisher/is-in-fixed-container.ts +21 -0
- package/src/view/use-droppable-publisher/use-droppable-publisher.ts +288 -0
- package/src/view/use-focus-marshal/focus-marshal-types.ts +14 -0
- package/src/view/use-focus-marshal/index.ts +2 -0
- package/src/view/use-focus-marshal/use-focus-marshal.ts +128 -0
- package/src/view/use-hidden-text-element/index.ts +2 -0
- package/src/view/use-hidden-text-element/use-hidden-text-element.ts +62 -0
- package/src/view/use-isomorphic-layout-effect.ts +18 -0
- package/src/view/use-previous-ref.ts +26 -0
- package/src/view/use-required-context.ts +22 -0
- package/src/view/use-sensor-marshal/closest.ts +89 -0
- package/src/view/use-sensor-marshal/find-closest-draggable-id-from-event.ts +50 -0
- package/src/view/use-sensor-marshal/index.ts +5 -0
- package/src/view/use-sensor-marshal/is-event-in-interactive-element.ts +67 -0
- package/src/view/use-sensor-marshal/lock.ts +50 -0
- package/src/view/use-sensor-marshal/sensors/use-keyboard-sensor.ts +243 -0
- package/src/view/use-sensor-marshal/sensors/use-mouse-sensor.ts +391 -0
- package/src/view/use-sensor-marshal/sensors/use-touch-sensor.ts +481 -0
- package/src/view/use-sensor-marshal/sensors/util/prevent-standard-key-events.ts +19 -0
- package/src/view/use-sensor-marshal/sensors/util/supported-page-visibility-event-name.ts +29 -0
- package/src/view/use-sensor-marshal/use-sensor-marshal.ts +504 -0
- package/src/view/use-sensor-marshal/use-validate-sensor-hooks.ts +20 -0
- package/src/view/use-style-marshal/get-styles.ts +173 -0
- package/src/view/use-style-marshal/index.ts +2 -0
- package/src/view/use-style-marshal/style-marshal-types.ts +9 -0
- package/src/view/use-style-marshal/use-style-marshal.ts +126 -0
- package/src/view/use-unique-id.ts +25 -0
- package/src/view/visually-hidden-style.ts +16 -0
- package/src/view/window/get-max-window-scroll.ts +19 -0
- package/src/view/window/get-viewport.ts +49 -0
- package/src/view/window/get-window-from-el.ts +12 -0
- package/src/view/window/get-window-scroll.ts +30 -0
- package/src/view/window/scroll-window.ts +7 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import {
|
|
3
|
+
getBox,
|
|
4
|
+
withScroll,
|
|
5
|
+
createBox,
|
|
6
|
+
expand,
|
|
7
|
+
type BoxModel,
|
|
8
|
+
type Position,
|
|
9
|
+
type Spacing,
|
|
10
|
+
} from 'css-box-model';
|
|
11
|
+
import getDroppableDimension, {
|
|
12
|
+
type Closest,
|
|
13
|
+
} from '../../state/droppable/get-droppable';
|
|
14
|
+
import type { Env } from './get-env';
|
|
15
|
+
import type {
|
|
16
|
+
DroppableDimension,
|
|
17
|
+
DroppableDescriptor,
|
|
18
|
+
Direction,
|
|
19
|
+
ScrollSize,
|
|
20
|
+
} from '../../types';
|
|
21
|
+
import getScroll from './get-scroll';
|
|
22
|
+
|
|
23
|
+
const getClient = (
|
|
24
|
+
targetRef: HTMLElement,
|
|
25
|
+
closestScrollable: Element | null,
|
|
26
|
+
): BoxModel => {
|
|
27
|
+
const base: BoxModel = getBox(targetRef);
|
|
28
|
+
|
|
29
|
+
// Droppable has no scroll parent
|
|
30
|
+
if (!closestScrollable) {
|
|
31
|
+
return base;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Droppable is not the same as the closest scrollable
|
|
35
|
+
if (targetRef !== closestScrollable) {
|
|
36
|
+
return base;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Droppable is scrollable
|
|
40
|
+
|
|
41
|
+
// Element.getBoundingClient() returns a clipped padding box:
|
|
42
|
+
// When not scrollable: the full size of the element
|
|
43
|
+
// When scrollable: the visible size of the element
|
|
44
|
+
// (which is not the full width of its scrollable content)
|
|
45
|
+
// So we recalculate the borderBox of a scrollable droppable to give
|
|
46
|
+
// it its full dimensions. This will be cut to the correct size by the frame
|
|
47
|
+
|
|
48
|
+
// Creating the paddingBox based on scrollWidth / scrollTop
|
|
49
|
+
// scrollWidth / scrollHeight are based on the paddingBox of an element
|
|
50
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight
|
|
51
|
+
const top: number = base.paddingBox.top - closestScrollable.scrollTop;
|
|
52
|
+
const left: number = base.paddingBox.left - closestScrollable.scrollLeft;
|
|
53
|
+
const bottom: number = top + closestScrollable.scrollHeight;
|
|
54
|
+
const right: number = left + closestScrollable.scrollWidth;
|
|
55
|
+
|
|
56
|
+
// unclipped padding box
|
|
57
|
+
const paddingBox: Spacing = {
|
|
58
|
+
top,
|
|
59
|
+
right,
|
|
60
|
+
bottom,
|
|
61
|
+
left,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// Creating the borderBox by adding the borders to the paddingBox
|
|
65
|
+
const borderBox: Spacing = expand(paddingBox, base.border);
|
|
66
|
+
|
|
67
|
+
// We are not accounting for scrollbars
|
|
68
|
+
// Adjusting for scrollbars is hard because:
|
|
69
|
+
// - they are different between browsers
|
|
70
|
+
// - scrollbars can be activated and removed during a drag
|
|
71
|
+
// We instead account for this slightly in our auto scroller
|
|
72
|
+
|
|
73
|
+
const client: BoxModel = createBox({
|
|
74
|
+
borderBox,
|
|
75
|
+
margin: base.margin,
|
|
76
|
+
border: base.border,
|
|
77
|
+
padding: base.padding,
|
|
78
|
+
});
|
|
79
|
+
return client;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// Exact
|
|
83
|
+
type Args = {
|
|
84
|
+
ref: HTMLElement,
|
|
85
|
+
descriptor: DroppableDescriptor,
|
|
86
|
+
env: Env,
|
|
87
|
+
windowScroll: Position,
|
|
88
|
+
direction?: Direction,
|
|
89
|
+
isDropDisabled?: boolean,
|
|
90
|
+
isCombineEnabled?: boolean,
|
|
91
|
+
shouldClipSubject: boolean,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export default ({
|
|
95
|
+
ref,
|
|
96
|
+
descriptor,
|
|
97
|
+
env,
|
|
98
|
+
windowScroll,
|
|
99
|
+
direction,
|
|
100
|
+
isDropDisabled,
|
|
101
|
+
isCombineEnabled,
|
|
102
|
+
shouldClipSubject,
|
|
103
|
+
}: Args): DroppableDimension => {
|
|
104
|
+
const closestScrollable: Element | null = env.closestScrollable;
|
|
105
|
+
const client: BoxModel = getClient(ref, closestScrollable);
|
|
106
|
+
const page: BoxModel = withScroll(client, windowScroll);
|
|
107
|
+
|
|
108
|
+
const closest: Closest | null = (() => {
|
|
109
|
+
if (!closestScrollable) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const frameClient: BoxModel = getBox(closestScrollable);
|
|
114
|
+
const scrollSize: ScrollSize = {
|
|
115
|
+
scrollHeight: closestScrollable.scrollHeight,
|
|
116
|
+
scrollWidth: closestScrollable.scrollWidth,
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
client: frameClient,
|
|
121
|
+
page: withScroll(frameClient, windowScroll),
|
|
122
|
+
scroll: getScroll(closestScrollable),
|
|
123
|
+
scrollSize,
|
|
124
|
+
shouldClipSubject,
|
|
125
|
+
};
|
|
126
|
+
})();
|
|
127
|
+
|
|
128
|
+
const dimension: DroppableDimension = getDroppableDimension({
|
|
129
|
+
descriptor,
|
|
130
|
+
isEnabled: !isDropDisabled,
|
|
131
|
+
isCombineEnabled,
|
|
132
|
+
isFixedOnPage: env.isFixedOnPage,
|
|
133
|
+
direction,
|
|
134
|
+
client,
|
|
135
|
+
page,
|
|
136
|
+
closest,
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
return dimension;
|
|
140
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import getClosestScrollable from './get-closest-scrollable';
|
|
3
|
+
|
|
4
|
+
// Exact
|
|
5
|
+
export type Env = {
|
|
6
|
+
closestScrollable: Element | null,
|
|
7
|
+
isFixedOnPage: boolean,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// TODO: do this check at the same time as the closest scrollable
|
|
11
|
+
// in order to avoid double calling getComputedStyle
|
|
12
|
+
// Do this when we move to multiple scroll containers
|
|
13
|
+
const getIsFixed = (el: Element | null): boolean => {
|
|
14
|
+
if (!el) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const style: CSSStyleDeclaration = window.getComputedStyle(el);
|
|
18
|
+
if (style.position === 'fixed') {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
return getIsFixed(el.parentElement);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default (start: Element): Env => {
|
|
25
|
+
const closestScrollable: Element | null = getClosestScrollable(start);
|
|
26
|
+
const isFixedOnPage: boolean = getIsFixed(start);
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
closestScrollable,
|
|
30
|
+
isFixedOnPage,
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import type { ScrollOptions } from '../../types';
|
|
3
|
+
|
|
4
|
+
const immediate = {
|
|
5
|
+
passive: false,
|
|
6
|
+
};
|
|
7
|
+
const delayed = {
|
|
8
|
+
passive: true,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default (options: ScrollOptions) =>
|
|
12
|
+
options.shouldPublishImmediately ? immediate : delayed;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
const isElementFixed = (el: Element): boolean =>
|
|
4
|
+
window.getComputedStyle(el).position === 'fixed';
|
|
5
|
+
|
|
6
|
+
const find = (el: Element | null): boolean => {
|
|
7
|
+
// cannot do anything else!
|
|
8
|
+
if (el == null) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// keep looking
|
|
13
|
+
if (!isElementFixed(el)) {
|
|
14
|
+
return find(el.parentElement);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// success!
|
|
18
|
+
return true;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default find;
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import { useRef } from "react";
|
|
3
|
+
import { type Position } from "css-box-model";
|
|
4
|
+
import rafSchedule from "raf-schd";
|
|
5
|
+
import { useMemo, useCallback } from "@helpdice/memoizer";
|
|
6
|
+
import memoizeOne from "memoize-one";
|
|
7
|
+
import { invariant } from "../../invariant";
|
|
8
|
+
import checkForNestedScrollContainers from "./check-for-nested-scroll-container";
|
|
9
|
+
import * as dataAttr from "../data-attributes";
|
|
10
|
+
import { origin } from "../../state/position";
|
|
11
|
+
import getScroll from "./get-scroll";
|
|
12
|
+
import type {
|
|
13
|
+
DroppableEntry,
|
|
14
|
+
DroppableCallbacks,
|
|
15
|
+
} from "../../state/registry/registry-types";
|
|
16
|
+
import getEnv, { type Env } from "./get-env";
|
|
17
|
+
import type {
|
|
18
|
+
Id,
|
|
19
|
+
DroppableId,
|
|
20
|
+
TypeId,
|
|
21
|
+
DroppableDimension,
|
|
22
|
+
DroppableDescriptor,
|
|
23
|
+
Direction,
|
|
24
|
+
ScrollOptions,
|
|
25
|
+
DroppableMode,
|
|
26
|
+
} from "../../types";
|
|
27
|
+
import getDimension from "./get-dimension";
|
|
28
|
+
import AppContext, { type AppContextValue } from "../context/app-context";
|
|
29
|
+
import { warning } from "../../dev-warning";
|
|
30
|
+
import getListenerOptions from "./get-listener-options";
|
|
31
|
+
import useRequiredContext from "../use-required-context";
|
|
32
|
+
import usePreviousRef from "../use-previous-ref";
|
|
33
|
+
import useLayoutEffect from "../use-isomorphic-layout-effect";
|
|
34
|
+
import useUniqueId from "../use-unique-id";
|
|
35
|
+
|
|
36
|
+
// Exact
|
|
37
|
+
type Props = {
|
|
38
|
+
droppableId: DroppableId,
|
|
39
|
+
type?: TypeId,
|
|
40
|
+
mode?: DroppableMode,
|
|
41
|
+
direction?: Direction,
|
|
42
|
+
isDropDisabled?: boolean,
|
|
43
|
+
isCombineEnabled?: boolean,
|
|
44
|
+
ignoreContainerClipping?: boolean,
|
|
45
|
+
getDroppableRef?: () => HTMLElement | null,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// Exact
|
|
49
|
+
type WhileDragging = {
|
|
50
|
+
ref: HTMLElement,
|
|
51
|
+
descriptor: DroppableDescriptor,
|
|
52
|
+
env: Env,
|
|
53
|
+
scrollOptions: ScrollOptions,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const getClosestScrollableFromDrag = (dragging: WhileDragging | null): Element | null =>
|
|
57
|
+
(dragging && dragging.env.closestScrollable) || null;
|
|
58
|
+
|
|
59
|
+
export default function useDroppablePublisher(args: Props) {
|
|
60
|
+
const whileDraggingRef = useRef<WhileDragging | null>(null);
|
|
61
|
+
const appContext: AppContextValue = useRequiredContext(AppContext);
|
|
62
|
+
const uniqueId: Id = useUniqueId("droppable");
|
|
63
|
+
const { registry, marshal } = appContext;
|
|
64
|
+
const previousRef = usePreviousRef(args);
|
|
65
|
+
|
|
66
|
+
const descriptor = useMemo<DroppableDescriptor>(
|
|
67
|
+
() => ({
|
|
68
|
+
id: args.droppableId,
|
|
69
|
+
type: args.type ?? "",
|
|
70
|
+
mode: args.mode ?? "standard", // By default
|
|
71
|
+
}),
|
|
72
|
+
[args.droppableId, args.mode, args.type],
|
|
73
|
+
);
|
|
74
|
+
const publishedDescriptorRef = useRef<DroppableDescriptor>(descriptor);
|
|
75
|
+
|
|
76
|
+
const memoizedUpdateScroll = useMemo(
|
|
77
|
+
() =>
|
|
78
|
+
memoizeOne((x: number, y: number) => {
|
|
79
|
+
invariant(
|
|
80
|
+
whileDraggingRef.current,
|
|
81
|
+
"Can only update scroll when dragging",
|
|
82
|
+
);
|
|
83
|
+
const scroll: Position = { x, y };
|
|
84
|
+
marshal.updateDroppableScroll(descriptor.id, scroll);
|
|
85
|
+
}),
|
|
86
|
+
[descriptor.id, marshal],
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const getClosestScroll = useCallback((): Position => {
|
|
90
|
+
const dragging: WhileDragging | null = whileDraggingRef.current;
|
|
91
|
+
if (!dragging || !dragging.env.closestScrollable) {
|
|
92
|
+
return origin;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return getScroll(dragging.env.closestScrollable);
|
|
96
|
+
}, []);
|
|
97
|
+
|
|
98
|
+
const updateScroll = useCallback(() => {
|
|
99
|
+
// reading scroll value when called so value will be the latest
|
|
100
|
+
const scroll: Position = getClosestScroll();
|
|
101
|
+
memoizedUpdateScroll(scroll.x, scroll.y);
|
|
102
|
+
}, [getClosestScroll, memoizedUpdateScroll]);
|
|
103
|
+
|
|
104
|
+
const scheduleScrollUpdate = useMemo(
|
|
105
|
+
() => rafSchedule(updateScroll),
|
|
106
|
+
[updateScroll],
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const onClosestScroll = useCallback(() => {
|
|
110
|
+
const dragging: WhileDragging | null = whileDraggingRef.current;
|
|
111
|
+
const closest: Element | null = getClosestScrollableFromDrag(dragging);
|
|
112
|
+
|
|
113
|
+
invariant(
|
|
114
|
+
dragging && closest,
|
|
115
|
+
"Could not find scroll options while scrolling",
|
|
116
|
+
);
|
|
117
|
+
const options: ScrollOptions = dragging.scrollOptions;
|
|
118
|
+
if (options.shouldPublishImmediately) {
|
|
119
|
+
updateScroll();
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
scheduleScrollUpdate();
|
|
123
|
+
}, [scheduleScrollUpdate, updateScroll]);
|
|
124
|
+
|
|
125
|
+
const getDimensionAndWatchScroll = useCallback(
|
|
126
|
+
(windowScroll: Position, options: ScrollOptions) => {
|
|
127
|
+
invariant(
|
|
128
|
+
!whileDraggingRef.current,
|
|
129
|
+
"Cannot collect a droppable while a drag is occurring",
|
|
130
|
+
);
|
|
131
|
+
const previous: Props = previousRef.current;
|
|
132
|
+
const ref: HTMLElement | null = previous.getDroppableRef ? previous.getDroppableRef() : null;
|
|
133
|
+
invariant(ref, "Cannot collect without a droppable ref");
|
|
134
|
+
const env: Env = getEnv(ref);
|
|
135
|
+
|
|
136
|
+
const dragging: WhileDragging = {
|
|
137
|
+
ref,
|
|
138
|
+
descriptor,
|
|
139
|
+
env,
|
|
140
|
+
scrollOptions: options,
|
|
141
|
+
};
|
|
142
|
+
// side effect
|
|
143
|
+
whileDraggingRef.current = dragging;
|
|
144
|
+
|
|
145
|
+
const dimension: DroppableDimension = getDimension({
|
|
146
|
+
ref,
|
|
147
|
+
descriptor,
|
|
148
|
+
env,
|
|
149
|
+
windowScroll,
|
|
150
|
+
direction: previous.direction,
|
|
151
|
+
isDropDisabled: previous.isDropDisabled,
|
|
152
|
+
isCombineEnabled: previous.isCombineEnabled,
|
|
153
|
+
shouldClipSubject: !previous.ignoreContainerClipping,
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const scrollable: Element | null = env.closestScrollable;
|
|
157
|
+
|
|
158
|
+
if (scrollable) {
|
|
159
|
+
scrollable.setAttribute(
|
|
160
|
+
dataAttr.scrollContainer.contextId,
|
|
161
|
+
appContext.contextId,
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
// bind scroll listener
|
|
165
|
+
scrollable.addEventListener(
|
|
166
|
+
"scroll",
|
|
167
|
+
onClosestScroll,
|
|
168
|
+
getListenerOptions(dragging.scrollOptions),
|
|
169
|
+
);
|
|
170
|
+
// print a debug warning if using an unsupported nested scroll container setup
|
|
171
|
+
if (process.env.NODE_ENV !== "production") {
|
|
172
|
+
checkForNestedScrollContainers(scrollable);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return dimension;
|
|
177
|
+
},
|
|
178
|
+
[appContext.contextId, descriptor, onClosestScroll, previousRef],
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
const getScrollWhileDragging = useCallback((): Position => {
|
|
182
|
+
const dragging: WhileDragging | null = whileDraggingRef.current;
|
|
183
|
+
const closest: Element | null = getClosestScrollableFromDrag(dragging);
|
|
184
|
+
invariant(
|
|
185
|
+
dragging && closest,
|
|
186
|
+
"Can only recollect Droppable client for Droppables that have a scroll container",
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
return getScroll(closest);
|
|
190
|
+
}, []);
|
|
191
|
+
|
|
192
|
+
const dragStopped = useCallback(() => {
|
|
193
|
+
const dragging: WhileDragging | null = whileDraggingRef.current;
|
|
194
|
+
invariant(dragging, "Cannot stop drag when no active drag");
|
|
195
|
+
const closest: Element | null = getClosestScrollableFromDrag(dragging);
|
|
196
|
+
|
|
197
|
+
// goodbye old friend
|
|
198
|
+
whileDraggingRef.current = null;
|
|
199
|
+
|
|
200
|
+
if (!closest) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// unwatch scroll
|
|
205
|
+
scheduleScrollUpdate.cancel();
|
|
206
|
+
closest.removeAttribute(dataAttr.scrollContainer.contextId);
|
|
207
|
+
const listenerOptions: AddEventListenerOptions =
|
|
208
|
+
getListenerOptions(dragging.scrollOptions);
|
|
209
|
+
closest.removeEventListener(
|
|
210
|
+
"scroll",
|
|
211
|
+
onClosestScroll,
|
|
212
|
+
listenerOptions,
|
|
213
|
+
);
|
|
214
|
+
}, [onClosestScroll, scheduleScrollUpdate]);
|
|
215
|
+
|
|
216
|
+
const scroll = useCallback((change: Position) => {
|
|
217
|
+
// arrange
|
|
218
|
+
const dragging: WhileDragging | null = whileDraggingRef.current;
|
|
219
|
+
invariant(dragging, "Cannot scroll when there is no drag");
|
|
220
|
+
const closest: Element | null = getClosestScrollableFromDrag(dragging);
|
|
221
|
+
invariant(closest, "Cannot scroll a droppable with no closest scrollable");
|
|
222
|
+
|
|
223
|
+
// act
|
|
224
|
+
closest.scrollTop += change.y;
|
|
225
|
+
closest.scrollLeft += change.x;
|
|
226
|
+
}, []);
|
|
227
|
+
|
|
228
|
+
const callbacks: DroppableCallbacks = useMemo(() => {
|
|
229
|
+
return {
|
|
230
|
+
getDimensionAndWatchScroll,
|
|
231
|
+
getScrollWhileDragging,
|
|
232
|
+
dragStopped,
|
|
233
|
+
scroll,
|
|
234
|
+
};
|
|
235
|
+
}, [dragStopped, getDimensionAndWatchScroll, getScrollWhileDragging, scroll]);
|
|
236
|
+
|
|
237
|
+
const entry: DroppableEntry = useMemo(
|
|
238
|
+
() => ({
|
|
239
|
+
uniqueId,
|
|
240
|
+
descriptor,
|
|
241
|
+
callbacks,
|
|
242
|
+
}),
|
|
243
|
+
[callbacks, descriptor, uniqueId],
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
// Register with the marshal and let it know of:
|
|
247
|
+
// - any descriptor changes
|
|
248
|
+
// - when it unmounts
|
|
249
|
+
useLayoutEffect(() => {
|
|
250
|
+
publishedDescriptorRef.current = entry.descriptor;
|
|
251
|
+
registry.droppable.register(entry);
|
|
252
|
+
|
|
253
|
+
return () => {
|
|
254
|
+
if (whileDraggingRef.current) {
|
|
255
|
+
warning(
|
|
256
|
+
"Unsupported: changing the droppableId or type of a Droppable during a drag",
|
|
257
|
+
);
|
|
258
|
+
dragStopped();
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
registry.droppable.unregister(entry);
|
|
262
|
+
};
|
|
263
|
+
}, [callbacks, descriptor, dragStopped, entry, marshal, registry.droppable]);
|
|
264
|
+
|
|
265
|
+
// update is enabled with the marshal
|
|
266
|
+
// only need to update when there is a drag
|
|
267
|
+
useLayoutEffect(() => {
|
|
268
|
+
if (!whileDraggingRef.current) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
marshal.updateDroppableIsEnabled(
|
|
272
|
+
publishedDescriptorRef.current.id,
|
|
273
|
+
!args.isDropDisabled,
|
|
274
|
+
);
|
|
275
|
+
}, [args.isDropDisabled, marshal]);
|
|
276
|
+
|
|
277
|
+
// update is combine enabled with the marshal
|
|
278
|
+
// only need to update when there is a drag
|
|
279
|
+
useLayoutEffect(() => {
|
|
280
|
+
if (!whileDraggingRef.current) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
marshal.updateDroppableIsCombineEnabled(
|
|
284
|
+
publishedDescriptorRef.current.id,
|
|
285
|
+
args.isCombineEnabled ?? false, // by default
|
|
286
|
+
);
|
|
287
|
+
}, [args.isCombineEnabled, marshal]);
|
|
288
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import type { DraggableId } from '../../types';
|
|
3
|
+
|
|
4
|
+
export type Unregister = () => void;
|
|
5
|
+
|
|
6
|
+
export type Register = (id: DraggableId, focus: () => void) => Unregister;
|
|
7
|
+
|
|
8
|
+
// Exact
|
|
9
|
+
export type FocusMarshal = {
|
|
10
|
+
register: Register,
|
|
11
|
+
tryRecordFocus: (tryRecordFor: DraggableId) => void,
|
|
12
|
+
tryRestoreFocusRecorded: () => void,
|
|
13
|
+
tryShiftRecord: (previous: DraggableId, redirectTo: DraggableId) => void,
|
|
14
|
+
};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import { useRef } from "react";
|
|
3
|
+
import { useMemo, useCallback } from "@helpdice/memoizer";
|
|
4
|
+
import type { DraggableId, ContextId, AnimationFrameID } from "../../types";
|
|
5
|
+
import type { FocusMarshal, Unregister } from "./focus-marshal-types";
|
|
6
|
+
import { dragHandle as dragHandleAttr } from "../data-attributes";
|
|
7
|
+
import useLayoutEffect from "../use-isomorphic-layout-effect";
|
|
8
|
+
import findDragHandle from "../get-elements/find-drag-handle";
|
|
9
|
+
|
|
10
|
+
// Exact
|
|
11
|
+
type Entry = {
|
|
12
|
+
id: DraggableId,
|
|
13
|
+
focus: () => void,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type EntryMap = {
|
|
17
|
+
[id: DraggableId]: Entry,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default function useFocusMarshal(contextId: ContextId): FocusMarshal {
|
|
21
|
+
const entriesRef = useRef<EntryMap>({});
|
|
22
|
+
const recordRef = useRef<DraggableId | null>(null);
|
|
23
|
+
const restoreFocusFrameRef = useRef<AnimationFrameID | null>(null);
|
|
24
|
+
const isMountedRef = useRef<boolean>(false);
|
|
25
|
+
|
|
26
|
+
const register = useCallback(function register(
|
|
27
|
+
id: DraggableId,
|
|
28
|
+
focus: () => void,
|
|
29
|
+
): Unregister {
|
|
30
|
+
const entry: Entry = { id, focus };
|
|
31
|
+
entriesRef.current[id] = entry;
|
|
32
|
+
|
|
33
|
+
return function unregister() {
|
|
34
|
+
const entries: EntryMap = entriesRef.current;
|
|
35
|
+
const current: Entry = entries[id];
|
|
36
|
+
// entry might have been overrided by another registration
|
|
37
|
+
if (current !== entry) {
|
|
38
|
+
delete entries[id];
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}, []);
|
|
42
|
+
|
|
43
|
+
const tryGiveFocus = useCallback(
|
|
44
|
+
function tryGiveFocus(tryGiveFocusTo: DraggableId) {
|
|
45
|
+
const handle: HTMLElement | null = findDragHandle(contextId, tryGiveFocusTo);
|
|
46
|
+
|
|
47
|
+
if (handle && handle !== document.activeElement) {
|
|
48
|
+
handle.focus();
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
[contextId],
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const tryShiftRecord = useCallback(function tryShiftRecord(
|
|
55
|
+
previous: DraggableId,
|
|
56
|
+
redirectTo: DraggableId,
|
|
57
|
+
) {
|
|
58
|
+
if (recordRef.current === previous) {
|
|
59
|
+
recordRef.current = redirectTo;
|
|
60
|
+
}
|
|
61
|
+
}, []);
|
|
62
|
+
|
|
63
|
+
const tryRestoreFocusRecorded = useCallback(
|
|
64
|
+
function tryRestoreFocusRecorded() {
|
|
65
|
+
// frame already queued
|
|
66
|
+
if (restoreFocusFrameRef.current) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// cannot give focus if unmounted
|
|
71
|
+
// this code path is generally not hit expect for some hot-reloading flows
|
|
72
|
+
if (!isMountedRef.current) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
restoreFocusFrameRef.current = requestAnimationFrame(() => {
|
|
77
|
+
restoreFocusFrameRef.current = null;
|
|
78
|
+
const record: DraggableId | null = recordRef.current;
|
|
79
|
+
if (record) {
|
|
80
|
+
tryGiveFocus(record);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
[tryGiveFocus],
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const tryRecordFocus = useCallback(function tryRecordFocus(id: DraggableId) {
|
|
88
|
+
// clear any existing record
|
|
89
|
+
recordRef.current = null;
|
|
90
|
+
|
|
91
|
+
const focused: Element | null = document.activeElement;
|
|
92
|
+
|
|
93
|
+
// no item focused so it cannot be our item
|
|
94
|
+
if (!focused) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// focused element is not a drag handle or does not have the right id
|
|
99
|
+
if (focused.getAttribute(dragHandleAttr.draggableId) !== id) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
recordRef.current = id;
|
|
104
|
+
}, []);
|
|
105
|
+
|
|
106
|
+
useLayoutEffect(() => {
|
|
107
|
+
isMountedRef.current = true;
|
|
108
|
+
return function clearFrameOnUnmount() {
|
|
109
|
+
isMountedRef.current = false;
|
|
110
|
+
const frameId: AnimationFrameID | null = restoreFocusFrameRef.current;
|
|
111
|
+
if (frameId) {
|
|
112
|
+
cancelAnimationFrame(frameId);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}, []);
|
|
116
|
+
|
|
117
|
+
const marshal: FocusMarshal = useMemo(
|
|
118
|
+
() => ({
|
|
119
|
+
register,
|
|
120
|
+
tryRecordFocus,
|
|
121
|
+
tryRestoreFocusRecorded,
|
|
122
|
+
tryShiftRecord,
|
|
123
|
+
}),
|
|
124
|
+
[register, tryRecordFocus, tryRestoreFocusRecorded, tryShiftRecord],
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
return marshal;
|
|
128
|
+
}
|