@dnd-kit/dom 0.1.8 → 0.1.9-beta-20250505155644

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.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { configurator, Sensor, Plugin, CorePlugin, DragDropManager as DragDropManager$1, Draggable as Draggable$1, Droppable as Droppable$1, descriptor } from '@dnd-kit/abstract';
2
2
  import { effect, computed, deepEqual, signal, batch, effects, untracked, reactive } from '@dnd-kit/state';
3
- import { ScrollDirection, Listeners, isElement, scrollIntoViewIfNeeded, DOMRectangle, getDocument, getWindow, isHTMLElement, getFrameTransform, scheduler, isKeyboardEvent, isPointerEvent, canScroll, detectScrollIntent, getElementFromPoint, getScrollableAncestors, generateUniqueId, isSafari, Styles, getComputedStyles, parseTranslate, supportsPopover, showPopover, getFrameElement, cloneElement, isKeyframeEffect, animateTransform, ProxiedElements, PositionObserver } from '@dnd-kit/dom/utilities';
3
+ import { ScrollDirection, Listeners, isElement, scrollIntoViewIfNeeded, DOMRectangle, getDocument, getWindow, isHTMLElement, getFrameTransform, scheduler, isKeyboardEvent, isPointerEvent, canScroll, detectScrollIntent, getElementFromPoint, getScrollableAncestors, generateUniqueId, isSafari, Styles, getComputedStyles, parseTranslate, supportsPopover, showPopover, supportsStyle, getFrameElement, cloneElement, isKeyframeEffect, animateTransform, ProxiedElements, PositionObserver } from '@dnd-kit/dom/utilities';
4
4
  import { exceedsDistance, Axes, Rectangle } from '@dnd-kit/geometry';
5
5
  import { defaultCollisionDetection } from '@dnd-kit/collision';
6
6
 
@@ -258,7 +258,6 @@ var Cursor = class extends Plugin {
258
258
  var ATTR_PREFIX = "data-dnd-";
259
259
  var DROPPING_ATTRIBUTE = `${ATTR_PREFIX}dropping`;
260
260
  var CSS_PREFIX = "--dnd-";
261
- var ROOT_ATTRIBUTE = `${ATTR_PREFIX}root`;
262
261
  var ATTRIBUTE = `${ATTR_PREFIX}dragging`;
263
262
  var PLACEHOLDER_ATTRIBUTE = `${ATTR_PREFIX}placeholder`;
264
263
  var IGNORED_ATTRIBUTES = [
@@ -268,6 +267,7 @@ var IGNORED_ATTRIBUTES = [
268
267
  "aria-pressed",
269
268
  "aria-grabbing"
270
269
  ];
270
+ var IGNORED_STYLES = ["view-transition-name"];
271
271
  var CSS_RULES = `
272
272
  :root [${ATTRIBUTE}] {
273
273
  position: fixed !important;
@@ -303,11 +303,9 @@ var CSS_RULES = `
303
303
  translate: var(${CSS_PREFIX}translate) !important;
304
304
  }
305
305
 
306
- [${ROOT_ATTRIBUTE}][style*='${CSS_PREFIX}scale'] {
307
- &:is([${ATTRIBUTE}]), [${ATTRIBUTE}] {
308
- scale: var(${CSS_PREFIX}scale) !important;
309
- transform-origin: var(${CSS_PREFIX}transform-origin) !important;
310
- }
306
+ [${ATTRIBUTE}][style*='${CSS_PREFIX}scale'] {
307
+ scale: var(${CSS_PREFIX}scale) !important;
308
+ transform-origin: var(${CSS_PREFIX}transform-origin) !important;
311
309
  }
312
310
 
313
311
  @layer {
@@ -422,7 +420,7 @@ _init = __decoratorStart(_a);
422
420
  _overlay = new WeakMap();
423
421
  _Feedback_instances = new WeakSet();
424
422
  render_fn = function() {
425
- var _a4, _b2, _c3, _d2;
423
+ var _a4, _b2, _c3;
426
424
  const { state, manager, options } = this;
427
425
  const { dragOperation } = manager;
428
426
  const { position, source, status } = dragOperation;
@@ -455,11 +453,9 @@ render_fn = function() {
455
453
  width = width / scaleDelta.x;
456
454
  height = height / scaleDelta.y;
457
455
  }
458
- let root = (_b2 = this.overlay) != null ? _b2 : feedbackElement.ownerDocument.body;
459
- if (options == null ? void 0 : options.rootElement) {
460
- root = typeof options.rootElement === "function" ? options.rootElement(source) : options.rootElement;
461
- }
462
- const styles = new Styles(root);
456
+ let elementMutationObserver;
457
+ let documentMutationObserver;
458
+ const styles = new Styles(feedbackElement);
463
459
  const { transition, translate } = getComputedStyles(element);
464
460
  const clone = feedback === "clone";
465
461
  const placeholder = feedback !== "move" && !this.overlay ? createPlaceholder(source, clone ? "clone" : "hidden") : null;
@@ -518,11 +514,10 @@ render_fn = function() {
518
514
  };
519
515
  feedbackElement.setAttribute(ATTRIBUTE, "true");
520
516
  const transform = untracked(() => dragOperation.transform);
521
- const initialTranslate = (_c3 = initial.translate) != null ? _c3 : { x: 0, y: 0 };
517
+ const initialTranslate = (_b2 = initial.translate) != null ? _b2 : { x: 0, y: 0 };
522
518
  const tX = transform.x * frameTransform.scaleX + initialTranslate.x;
523
519
  const tY = transform.y * frameTransform.scaleY + initialTranslate.y;
524
520
  const translateString = `${tX}px ${tY}px 0`;
525
- root.setAttribute(ROOT_ATTRIBUTE, "");
526
521
  styles.set(
527
522
  {
528
523
  width,
@@ -539,6 +534,7 @@ render_fn = function() {
539
534
  if (placeholder) {
540
535
  element.insertAdjacentElement("afterend", placeholder);
541
536
  if (options == null ? void 0 : options.rootElement) {
537
+ const root = typeof options.rootElement === "function" ? options.rootElement(source) : options.rootElement;
542
538
  root.appendChild(element);
543
539
  }
544
540
  }
@@ -567,6 +563,7 @@ render_fn = function() {
567
563
  },
568
564
  CSS_PREFIX
569
565
  );
566
+ elementMutationObserver == null ? void 0 : elementMutationObserver.takeRecords();
570
567
  if (isTableRow(element) && isTableRow(placeholder)) {
571
568
  const cells = Array.from(element.cells);
572
569
  const placeholderCells = Array.from(placeholder.cells);
@@ -581,8 +578,6 @@ render_fn = function() {
581
578
  if (untracked(() => source.status) === "idle") {
582
579
  requestAnimationFrame(() => source.status = "dragging");
583
580
  }
584
- let elementMutationObserver;
585
- let documentMutationObserver;
586
581
  if (placeholder) {
587
582
  resizeObserver.observe(placeholder);
588
583
  elementMutationObserver = new MutationObserver((mutations) => {
@@ -600,7 +595,23 @@ render_fn = function() {
600
595
  continue;
601
596
  }
602
597
  const attributeValue = element.getAttribute(attributeName);
603
- if (attributeValue !== null) {
598
+ if (attributeName === "style") {
599
+ if (supportsStyle(element) && supportsStyle(placeholder)) {
600
+ const styles2 = element.style;
601
+ for (const key of Array.from(placeholder.style)) {
602
+ if (styles2.getPropertyValue(key) === "") {
603
+ placeholder.style.removeProperty(key);
604
+ }
605
+ }
606
+ for (const key of Array.from(styles2)) {
607
+ if (IGNORED_STYLES.includes(key) || key.startsWith(CSS_PREFIX)) {
608
+ continue;
609
+ }
610
+ const value = styles2.getPropertyValue(key);
611
+ placeholder.style.setProperty(key, value);
612
+ }
613
+ }
614
+ } else if (attributeValue !== null) {
604
615
  placeholder.setAttribute(attributeName, attributeValue);
605
616
  } else {
606
617
  placeholder.removeAttribute(attributeName);
@@ -655,6 +666,7 @@ render_fn = function() {
655
666
  },
656
667
  CSS_PREFIX
657
668
  );
669
+ elementMutationObserver == null ? void 0 : elementMutationObserver.takeRecords();
658
670
  dragOperation.shape = new DOMRectangle(feedbackElement);
659
671
  state.current.translate = {
660
672
  x,
@@ -662,7 +674,7 @@ render_fn = function() {
662
674
  };
663
675
  }
664
676
  });
665
- const id = (_d2 = manager.dragOperation.source) == null ? void 0 : _d2.id;
677
+ const id = (_c3 = manager.dragOperation.source) == null ? void 0 : _c3.id;
666
678
  const restoreFocus = () => {
667
679
  var _a5;
668
680
  if (!isKeyboardOperation || id == null) {
@@ -694,7 +706,6 @@ render_fn = function() {
694
706
  placeholder.replaceWith(feedbackElement);
695
707
  }
696
708
  placeholder == null ? void 0 : placeholder.remove();
697
- root.removeAttribute(ROOT_ATTRIBUTE);
698
709
  cleanupEffect();
699
710
  dropEffectCleanup == null ? void 0 : dropEffectCleanup();
700
711
  };
@@ -760,6 +771,7 @@ render_fn = function() {
760
771
  } : {};
761
772
  styles.set({ transition }, CSS_PREFIX);
762
773
  feedbackElement.setAttribute(DROPPING_ATTRIBUTE, "");
774
+ elementMutationObserver == null ? void 0 : elementMutationObserver.takeRecords();
763
775
  animateTransform({
764
776
  element: feedbackElement,
765
777
  keyframes: __spreadProps(__spreadValues(__spreadValues({}, heightKeyframes), widthKeyframes), {