@dnd-kit/dom 0.1.19 → 0.1.20-beta-20250611154151

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/index.cjs CHANGED
@@ -524,7 +524,6 @@ render_fn = function() {
524
524
  x: elementFrameTransform.scaleX / frameTransform.scaleX,
525
525
  y: elementFrameTransform.scaleY / frameTransform.scaleY
526
526
  };
527
- let cleanup;
528
527
  let { width, height, top, left } = shape;
529
528
  if (crossFrame) {
530
529
  width = width / scaleDelta.x;
@@ -749,48 +748,6 @@ render_fn = function() {
749
748
  subtree: true
750
749
  });
751
750
  }
752
- const cleanupEffect = state.effect(() => {
753
- var _a5;
754
- const { transform: transform2, status: status2 } = dragOperation;
755
- if (!transform2.x && !transform2.y && !state$1.current.translate) {
756
- return;
757
- }
758
- if (status2.dragging) {
759
- const initialTranslate2 = (_a5 = initial.translate) != null ? _a5 : { x: 0, y: 0 };
760
- const translate2 = {
761
- x: transform2.x / frameTransform.scaleX + initialTranslate2.x,
762
- y: transform2.y / frameTransform.scaleY + initialTranslate2.y
763
- };
764
- const previousTranslate = state$1.current.translate;
765
- const modifiers = state.untracked(() => dragOperation.modifiers);
766
- const currentShape = state.untracked(() => {
767
- var _a6;
768
- return (_a6 = dragOperation.shape) == null ? void 0 : _a6.current;
769
- });
770
- const translateTransition = isKeyboardOperation ? "250ms cubic-bezier(0.25, 1, 0.5, 1)" : "0ms linear";
771
- styles.set(
772
- {
773
- transition: `${transition}, translate ${translateTransition}`,
774
- translate: `${translate2.x}px ${translate2.y}px 0`
775
- },
776
- CSS_PREFIX
777
- );
778
- elementMutationObserver == null ? void 0 : elementMutationObserver.takeRecords();
779
- if (currentShape && currentShape !== initialShape && previousTranslate && !modifiers.length) {
780
- const delta2 = geometry.Point.delta(translate2, previousTranslate);
781
- dragOperation.shape = geometry.Rectangle.from(
782
- currentShape.boundingRectangle
783
- ).translate(
784
- // Need to take into account frame transform when optimistically updating shape
785
- delta2.x * frameTransform.scaleX,
786
- delta2.y * frameTransform.scaleY
787
- );
788
- } else {
789
- dragOperation.shape = new utilities.DOMRectangle(feedbackElement);
790
- }
791
- state$1.current.translate = translate2;
792
- }
793
- });
794
751
  const id = (_c3 = manager.dragOperation.source) == null ? void 0 : _c3.id;
795
752
  const restoreFocus = () => {
796
753
  var _a5;
@@ -803,8 +760,7 @@ render_fn = function() {
803
760
  element2.focus();
804
761
  }
805
762
  };
806
- let dropEffectCleanup;
807
- cleanup = () => {
763
+ const cleanup = () => {
808
764
  elementMutationObserver == null ? void 0 : elementMutationObserver.disconnect();
809
765
  documentMutationObserver == null ? void 0 : documentMutationObserver.disconnect();
810
766
  resizeObserver.disconnect();
@@ -824,95 +780,140 @@ render_fn = function() {
824
780
  placeholder.replaceWith(feedbackElement);
825
781
  }
826
782
  placeholder == null ? void 0 : placeholder.remove();
827
- cleanupEffect();
828
- dropEffectCleanup == null ? void 0 : dropEffectCleanup();
829
783
  };
830
- dropEffectCleanup = state.effect(() => {
831
- if (dragOperation.status.dropped) {
832
- queueMicrotask(() => dropEffectCleanup == null ? void 0 : dropEffectCleanup());
833
- const onComplete = cleanup;
834
- cleanup = void 0;
835
- source.status = "dropping";
836
- let translate2 = state$1.current.translate;
837
- const moved = translate2 != null;
838
- if (!translate2 && element !== feedbackElement) {
839
- translate2 = {
840
- x: 0,
841
- y: 0
842
- };
843
- }
844
- if (!translate2) {
845
- onComplete == null ? void 0 : onComplete();
784
+ const cleanupEffects = state.effects(
785
+ // Update transform on move
786
+ () => {
787
+ var _a5;
788
+ const { transform: transform2, status: status2 } = dragOperation;
789
+ if (!transform2.x && !transform2.y && !state$1.current.translate) {
846
790
  return;
847
791
  }
848
- const dropAnimation = () => {
849
- var _a5, _b3;
850
- {
851
- utilities.showPopover(feedbackElement);
852
- const [, animation] = (_a5 = utilities.getFinalKeyframe(
853
- feedbackElement,
854
- (keyframe) => "translate" in keyframe
855
- )) != null ? _a5 : [];
856
- animation == null ? void 0 : animation.pause();
857
- const target = placeholder != null ? placeholder : element;
858
- const options2 = {
859
- frameTransform: isSameFrame(feedbackElement, target) ? null : void 0
860
- };
861
- const current = new utilities.DOMRectangle(feedbackElement, options2);
862
- const currentTranslate = (_b3 = utilities.parseTranslate(utilities.getComputedStyles(feedbackElement).translate)) != null ? _b3 : translate2;
863
- const final = new utilities.DOMRectangle(target, options2);
864
- const delta2 = geometry.Rectangle.delta(current, final, source.alignment);
865
- const finalTranslate = {
866
- x: currentTranslate.x - delta2.x,
867
- y: currentTranslate.y - delta2.y
792
+ if (status2.dragging) {
793
+ const initialTranslate2 = (_a5 = initial.translate) != null ? _a5 : { x: 0, y: 0 };
794
+ const translate2 = {
795
+ x: transform2.x / frameTransform.scaleX + initialTranslate2.x,
796
+ y: transform2.y / frameTransform.scaleY + initialTranslate2.y
797
+ };
798
+ const previousTranslate = state$1.current.translate;
799
+ const modifiers = state.untracked(() => dragOperation.modifiers);
800
+ const currentShape = state.untracked(() => {
801
+ var _a6;
802
+ return (_a6 = dragOperation.shape) == null ? void 0 : _a6.current;
803
+ });
804
+ const translateTransition = isKeyboardOperation ? "250ms cubic-bezier(0.25, 1, 0.5, 1)" : "0ms linear";
805
+ styles.set(
806
+ {
807
+ transition: `${transition}, translate ${translateTransition}`,
808
+ translate: `${translate2.x}px ${translate2.y}px 0`
809
+ },
810
+ CSS_PREFIX
811
+ );
812
+ elementMutationObserver == null ? void 0 : elementMutationObserver.takeRecords();
813
+ if (currentShape && currentShape !== initialShape && previousTranslate && !modifiers.length) {
814
+ const delta2 = geometry.Point.delta(translate2, previousTranslate);
815
+ dragOperation.shape = geometry.Rectangle.from(
816
+ currentShape.boundingRectangle
817
+ ).translate(
818
+ // Need to take into account frame transform when optimistically updating shape
819
+ delta2.x * frameTransform.scaleX,
820
+ delta2.y * frameTransform.scaleY
821
+ );
822
+ } else {
823
+ dragOperation.shape = new utilities.DOMRectangle(feedbackElement);
824
+ }
825
+ state$1.current.translate = translate2;
826
+ }
827
+ },
828
+ // Drop animation
829
+ function() {
830
+ if (dragOperation.status.dropped) {
831
+ this.dispose();
832
+ source.status = "dropping";
833
+ let translate2 = state$1.current.translate;
834
+ const moved = translate2 != null;
835
+ if (!translate2 && element !== feedbackElement) {
836
+ translate2 = {
837
+ x: 0,
838
+ y: 0
868
839
  };
869
- const heightKeyframes = Math.round(current.intrinsicHeight) !== Math.round(final.intrinsicHeight) ? {
870
- minHeight: [
871
- `${current.intrinsicHeight}px`,
872
- `${final.intrinsicHeight}px`
873
- ],
874
- maxHeight: [
875
- `${current.intrinsicHeight}px`,
876
- `${final.intrinsicHeight}px`
877
- ]
878
- } : {};
879
- const widthKeyframes = Math.round(current.intrinsicWidth) !== Math.round(final.intrinsicWidth) ? {
880
- minWidth: [
881
- `${current.intrinsicWidth}px`,
882
- `${final.intrinsicWidth}px`
883
- ],
884
- maxWidth: [
885
- `${current.intrinsicWidth}px`,
886
- `${final.intrinsicWidth}px`
887
- ]
888
- } : {};
889
- styles.set({ transition }, CSS_PREFIX);
890
- feedbackElement.setAttribute(DROPPING_ATTRIBUTE, "");
891
- elementMutationObserver == null ? void 0 : elementMutationObserver.takeRecords();
892
- utilities.animateTransform({
893
- element: feedbackElement,
894
- keyframes: __spreadProps(__spreadValues(__spreadValues({}, heightKeyframes), widthKeyframes), {
895
- translate: [
896
- `${currentTranslate.x}px ${currentTranslate.y}px 0`,
897
- `${finalTranslate.x}px ${finalTranslate.y}px 0`
898
- ]
899
- }),
900
- options: {
901
- duration: moved || feedbackElement !== element ? 250 : 0,
902
- easing: "ease"
903
- }
904
- }).then(() => {
905
- feedbackElement.removeAttribute(DROPPING_ATTRIBUTE);
906
- animation == null ? void 0 : animation.finish();
907
- onComplete == null ? void 0 : onComplete();
908
- requestAnimationFrame(restoreFocus);
909
- });
910
840
  }
911
- };
912
- manager.renderer.rendering.then(dropAnimation);
841
+ if (!translate2) {
842
+ cleanup();
843
+ return;
844
+ }
845
+ const dropAnimation = () => {
846
+ var _a5, _b3;
847
+ {
848
+ utilities.showPopover(feedbackElement);
849
+ const [, animation] = (_a5 = utilities.getFinalKeyframe(
850
+ feedbackElement,
851
+ (keyframe) => "translate" in keyframe
852
+ )) != null ? _a5 : [];
853
+ animation == null ? void 0 : animation.pause();
854
+ const target = placeholder != null ? placeholder : element;
855
+ const options2 = {
856
+ frameTransform: isSameFrame(feedbackElement, target) ? null : void 0
857
+ };
858
+ const current = new utilities.DOMRectangle(feedbackElement, options2);
859
+ const currentTranslate = (_b3 = utilities.parseTranslate(utilities.getComputedStyles(feedbackElement).translate)) != null ? _b3 : translate2;
860
+ const final = new utilities.DOMRectangle(target, options2);
861
+ const delta2 = geometry.Rectangle.delta(current, final, source.alignment);
862
+ const finalTranslate = {
863
+ x: currentTranslate.x - delta2.x,
864
+ y: currentTranslate.y - delta2.y
865
+ };
866
+ const heightKeyframes = Math.round(current.intrinsicHeight) !== Math.round(final.intrinsicHeight) ? {
867
+ minHeight: [
868
+ `${current.intrinsicHeight}px`,
869
+ `${final.intrinsicHeight}px`
870
+ ],
871
+ maxHeight: [
872
+ `${current.intrinsicHeight}px`,
873
+ `${final.intrinsicHeight}px`
874
+ ]
875
+ } : {};
876
+ const widthKeyframes = Math.round(current.intrinsicWidth) !== Math.round(final.intrinsicWidth) ? {
877
+ minWidth: [
878
+ `${current.intrinsicWidth}px`,
879
+ `${final.intrinsicWidth}px`
880
+ ],
881
+ maxWidth: [
882
+ `${current.intrinsicWidth}px`,
883
+ `${final.intrinsicWidth}px`
884
+ ]
885
+ } : {};
886
+ styles.set({ transition }, CSS_PREFIX);
887
+ feedbackElement.setAttribute(DROPPING_ATTRIBUTE, "");
888
+ elementMutationObserver == null ? void 0 : elementMutationObserver.takeRecords();
889
+ utilities.animateTransform({
890
+ element: feedbackElement,
891
+ keyframes: __spreadProps(__spreadValues(__spreadValues({}, heightKeyframes), widthKeyframes), {
892
+ translate: [
893
+ `${currentTranslate.x}px ${currentTranslate.y}px 0`,
894
+ `${finalTranslate.x}px ${finalTranslate.y}px 0`
895
+ ]
896
+ }),
897
+ options: {
898
+ duration: moved || feedbackElement !== element ? 250 : 0,
899
+ easing: "ease"
900
+ }
901
+ }).then(() => {
902
+ feedbackElement.removeAttribute(DROPPING_ATTRIBUTE);
903
+ animation == null ? void 0 : animation.finish();
904
+ cleanup();
905
+ requestAnimationFrame(restoreFocus);
906
+ });
907
+ }
908
+ };
909
+ manager.renderer.rendering.then(dropAnimation);
910
+ }
913
911
  }
914
- });
915
- return () => cleanup == null ? void 0 : cleanup();
912
+ );
913
+ return () => {
914
+ cleanup();
915
+ cleanupEffects();
916
+ };
916
917
  };
917
918
  injectStyles_fn = function() {
918
919
  var _a4, _b2;
@@ -1829,7 +1830,7 @@ var Draggable = class extends (_c = abstract.Draggable, _handle_dec = [state.rea
1829
1830
  constructor(_a4, manager) {
1830
1831
  var _b2 = _a4, {
1831
1832
  element,
1832
- effects = () => [],
1833
+ effects: effects2 = () => [],
1833
1834
  handle,
1834
1835
  feedback = "default"
1835
1836
  } = _b2, input = __objRest(_b2, [
@@ -1841,7 +1842,7 @@ var Draggable = class extends (_c = abstract.Draggable, _handle_dec = [state.rea
1841
1842
  super(
1842
1843
  __spreadValues({
1843
1844
  effects: () => [
1844
- ...effects(),
1845
+ ...effects2(),
1845
1846
  () => {
1846
1847
  var _a5, _b3;
1847
1848
  const { manager: manager2 } = this;
@@ -1882,7 +1883,7 @@ __decoratorMetadata(_init4, Draggable);
1882
1883
  var _proxy_dec, _element_dec2, _c2, _init5, _element2, _d, element_get, element_set, _Droppable_instances, _proxy;
1883
1884
  var Droppable = class extends (_c2 = abstract.Droppable, _element_dec2 = [state.reactive], _proxy_dec = [state.reactive], _c2) {
1884
1885
  constructor(_a4, manager) {
1885
- var _b2 = _a4, { element, effects = () => [] } = _b2, input = __objRest(_b2, ["element", "effects"]);
1886
+ var _b2 = _a4, { element, effects: effects2 = () => [] } = _b2, input = __objRest(_b2, ["element", "effects"]);
1886
1887
  const { collisionDetector = collision.defaultCollisionDetection } = input;
1887
1888
  const updateShape = (boundingClientRect) => {
1888
1889
  const { manager: manager2, element: element2 } = this;
@@ -1904,7 +1905,7 @@ var Droppable = class extends (_c2 = abstract.Droppable, _element_dec2 = [state.
1904
1905
  __spreadProps(__spreadValues({}, input), {
1905
1906
  collisionDetector,
1906
1907
  effects: () => [
1907
- ...effects(),
1908
+ ...effects2(),
1908
1909
  () => {
1909
1910
  const { element: element2, manager: manager2 } = this;
1910
1911
  if (!manager2) return;