@dnd-kit/dom 0.0.2 → 0.0.3-beta-20240617115949

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
@@ -193,7 +193,7 @@ var Cursor = class extends abstract.Plugin {
193
193
  var ATTR_PREFIX = "data-dnd-";
194
194
  var CSS_PREFIX = "--dnd-";
195
195
  var ATTRIBUTE = `${ATTR_PREFIX}dragging`;
196
- var cssRules = `[${ATTRIBUTE}] {position: fixed !important; pointer-events: none !important; touch-action: none !important; z-index: calc(infinity); will-change: transform;top: var(${CSS_PREFIX}top, 0px) !important;left: var(${CSS_PREFIX}left, 0px) !important;width: var(${CSS_PREFIX}width, auto) !important;height: var(${CSS_PREFIX}height, auto) !important;}[${ATTRIBUTE}][style*="${CSS_PREFIX}translate"] {translate: var(${CSS_PREFIX}translate) !important;}[style*="${CSS_PREFIX}transition"] {transition: var(${CSS_PREFIX}transition) !important;}*:where([${ATTRIBUTE}][popover]){overflow:visible;background:unset;border:unset;margin:unset;padding:unset;color:inherit;}[${ATTRIBUTE}]::backdrop {display: none}`;
196
+ var cssRules = `[${ATTRIBUTE}] {position: fixed !important; pointer-events: none !important; touch-action: none !important; z-index: calc(infinity); will-change: transform;top: var(${CSS_PREFIX}top, 0px) !important;left: var(${CSS_PREFIX}left, 0px) !important;width: var(${CSS_PREFIX}width, auto) !important;height: var(${CSS_PREFIX}height, auto) !important;}[${ATTRIBUTE}][style*="${CSS_PREFIX}translate"] {translate: var(${CSS_PREFIX}translate) !important;}[style*="${CSS_PREFIX}transition"] {transition: var(${CSS_PREFIX}transition) !important;}*:where([${ATTRIBUTE}][popover]){overflow:visible;background:var(${CSS_PREFIX}background);border:var(${CSS_PREFIX}border);margin:unset;padding:unset;color:inherit;}[${ATTRIBUTE}]::backdrop {display: none}`;
197
197
  var PLACEHOLDER_ATTRIBUTE = `${ATTR_PREFIX}placeholder`;
198
198
  var IGNORED_ATTRIBUTES = [ATTRIBUTE, PLACEHOLDER_ATTRIBUTE, "popover"];
199
199
  var IGNORED_STYLES = ["view-transition-name"];
@@ -202,6 +202,7 @@ var Feedback = class extends abstract.Plugin {
202
202
  super(manager);
203
203
  let style;
204
204
  let initialCoordinates;
205
+ let initialTranslate = { x: 0, y: 0 };
205
206
  let currentTransform;
206
207
  let transformOrigin;
207
208
  let moved = false;
@@ -220,7 +221,7 @@ var Feedback = class extends abstract.Plugin {
220
221
  initialCoordinates = void 0;
221
222
  currentTransform = void 0;
222
223
  transformOrigin = void 0;
223
- moved = false;
224
+ initialTranslate = { x: 0, y: 0 };
224
225
  return;
225
226
  }
226
227
  if (!source)
@@ -231,15 +232,21 @@ var Feedback = class extends abstract.Plugin {
231
232
  const shape = new utilities.DOMRectangle(element, true);
232
233
  const { width, height, top, left } = shape;
233
234
  const styles = new utilities.Styles(element);
234
- const { transition } = utilities.getWindow(element).getComputedStyle(element);
235
+ const { background, border, transition, translate } = utilities.getComputedStyles(element);
235
236
  const droppable = manager.registry.droppables.get(source.id);
236
237
  const clone = feedback === "clone";
237
- const placeholder = utilities.createPlaceholder(element, clone, {
238
+ const placeholder = feedback !== "move" ? utilities.createPlaceholder(element, clone, {
238
239
  [PLACEHOLDER_ATTRIBUTE]: ""
239
- });
240
+ }) : null;
240
241
  const isKeyboardOperation = state.untracked(
241
242
  () => utilities.isKeyboardEvent(manager.dragOperation.activatorEvent)
242
243
  );
244
+ if (translate !== "none") {
245
+ const parsedTranslate = utilities.parseTranslate(translate);
246
+ if (parsedTranslate) {
247
+ initialTranslate = parsedTranslate;
248
+ }
249
+ }
243
250
  if (!initialCoordinates) {
244
251
  initialCoordinates = {
245
252
  x: left,
@@ -268,11 +275,14 @@ var Feedback = class extends abstract.Plugin {
268
275
  height,
269
276
  top: projected.top,
270
277
  left: projected.left,
278
+ background,
279
+ border,
271
280
  translate: currentTransform ? `${currentTransform.x}px ${currentTransform.y}px 0` : ""
272
281
  },
273
282
  CSS_PREFIX
274
283
  );
275
- element.insertAdjacentElement("afterend", placeholder);
284
+ if (placeholder)
285
+ element.insertAdjacentElement("afterend", placeholder);
276
286
  if (utilities.supportsPopover(element)) {
277
287
  if (!element.hasAttribute("popover")) {
278
288
  element.setAttribute("popover", "");
@@ -284,7 +294,7 @@ var Feedback = class extends abstract.Plugin {
284
294
  top: projected.top - actual.top,
285
295
  left: projected.left - actual.left
286
296
  };
287
- if (Math.abs(offset.top) || Math.abs(offset.left)) {
297
+ if (offset.left > 0.01 || offset.top > 0.01) {
288
298
  styles.set(
289
299
  {
290
300
  top: projected.top + offset.top,
@@ -292,8 +302,13 @@ var Feedback = class extends abstract.Plugin {
292
302
  },
293
303
  CSS_PREFIX
294
304
  );
305
+ } else {
306
+ offset.left = 0;
307
+ offset.top = 0;
295
308
  }
296
309
  const resizeObserver = new ResizeObserver(() => {
310
+ if (!placeholder)
311
+ return;
297
312
  const placeholderShape = new utilities.DOMRectangle(placeholder, true);
298
313
  const origin = transformOrigin ?? { x: 1, y: 1 };
299
314
  const dX = (width - placeholderShape.width) * origin.x + delta.x;
@@ -317,60 +332,63 @@ var Feedback = class extends abstract.Plugin {
317
332
  }
318
333
  manager.dragOperation.shape = new utilities.DOMRectangle(element);
319
334
  });
320
- if (droppable) {
335
+ if (droppable && placeholder) {
321
336
  droppable.placeholder = placeholder;
322
337
  state.untracked(droppable.refreshShape);
323
338
  }
324
- dragOperation.shape = shape;
325
- resizeObserver.observe(placeholder);
326
- const elementMutationObserver = new MutationObserver(() => {
327
- for (const attribute of Array.from(element.attributes)) {
328
- if (attribute.name.startsWith("aria-") || IGNORED_ATTRIBUTES.includes(attribute.name)) {
329
- continue;
330
- }
331
- if (attribute.name === "style") {
332
- if (utilities.supportsStyle(element) && utilities.supportsStyle(placeholder)) {
333
- placeholder.setAttribute("style", clone ? "" : "opacity: 0;");
334
- placeholder.style.setProperty("transition", "none");
335
- for (const key of Object.values(element.style)) {
336
- if (key.startsWith(CSS_PREFIX) || IGNORED_STYLES.includes(key)) {
337
- continue;
339
+ dragOperation.shape = new utilities.DOMRectangle(element);
340
+ let elementMutationObserver;
341
+ let documentMutationObserver;
342
+ if (placeholder) {
343
+ resizeObserver.observe(placeholder);
344
+ elementMutationObserver = new MutationObserver(() => {
345
+ for (const attribute of Array.from(element.attributes)) {
346
+ if (attribute.name.startsWith("aria-") || IGNORED_ATTRIBUTES.includes(attribute.name)) {
347
+ continue;
348
+ }
349
+ if (attribute.name === "style") {
350
+ if (utilities.supportsStyle(element) && utilities.supportsStyle(placeholder)) {
351
+ placeholder.setAttribute("style", clone ? "" : "opacity: 0;");
352
+ placeholder.style.setProperty("transition", "none");
353
+ for (const key of Object.values(element.style)) {
354
+ if (key.startsWith(CSS_PREFIX) || IGNORED_STYLES.includes(key)) {
355
+ continue;
356
+ }
357
+ placeholder.style.setProperty(
358
+ key,
359
+ element.style.getPropertyValue(key)
360
+ );
338
361
  }
339
- placeholder.style.setProperty(
340
- key,
341
- element.style.getPropertyValue(key)
342
- );
343
362
  }
363
+ continue;
344
364
  }
345
- continue;
365
+ placeholder.setAttribute(attribute.name, attribute.value);
346
366
  }
347
- placeholder.setAttribute(attribute.name, attribute.value);
348
- }
349
- if (clone) {
350
- placeholder.innerHTML = element.innerHTML;
351
- }
352
- });
353
- elementMutationObserver.observe(element, {
354
- attributes: true,
355
- subtree: true
356
- });
357
- const documentMutationObserver = new MutationObserver((entries) => {
358
- for (const entry of entries) {
359
- if (Array.from(entry.addedNodes).includes(element)) {
360
- element.insertAdjacentElement("afterend", placeholder);
361
- utilities.showPopover(element);
362
- return;
367
+ if (clone) {
368
+ placeholder.innerHTML = element.innerHTML;
363
369
  }
364
- }
365
- });
366
- documentMutationObserver.observe(element.ownerDocument.body, {
367
- childList: true,
368
- subtree: true
369
- });
370
+ });
371
+ elementMutationObserver.observe(element, {
372
+ attributes: true,
373
+ subtree: true
374
+ });
375
+ documentMutationObserver = new MutationObserver((entries) => {
376
+ for (const entry of entries) {
377
+ if (Array.from(entry.addedNodes).includes(element)) {
378
+ element.insertAdjacentElement("afterend", placeholder);
379
+ utilities.showPopover(element);
380
+ return;
381
+ }
382
+ }
383
+ });
384
+ documentMutationObserver.observe(element.ownerDocument.body, {
385
+ childList: true,
386
+ subtree: true
387
+ });
388
+ }
370
389
  const cleanupEffect2 = state.effect(function updateTransform() {
371
390
  const { transform, status: status2 } = dragOperation;
372
- const { x, y } = transform;
373
- if (!x && !y && !moved) {
391
+ if (!transform.x && !transform.y && !moved) {
374
392
  return;
375
393
  }
376
394
  if (!moved) {
@@ -378,6 +396,8 @@ var Feedback = class extends abstract.Plugin {
378
396
  }
379
397
  if (status2.dragging) {
380
398
  const translateTransition = isKeyboardOperation ? "250ms ease" : "0ms linear";
399
+ const x = transform.x + initialTranslate.x;
400
+ const y = transform.y + initialTranslate.y;
381
401
  const shape2 = new utilities.DOMRectangle(element);
382
402
  styles.set(
383
403
  {
@@ -411,14 +431,14 @@ var Feedback = class extends abstract.Plugin {
411
431
  }
412
432
  };
413
433
  let cleanup = () => {
414
- elementMutationObserver.disconnect();
415
- documentMutationObserver.disconnect();
434
+ elementMutationObserver?.disconnect();
435
+ documentMutationObserver?.disconnect();
416
436
  resizeObserver.disconnect();
417
437
  styles.reset();
418
438
  if (moved && element.isConnected) {
419
- placeholder.replaceWith(element);
439
+ placeholder?.replaceWith(element);
420
440
  }
421
- placeholder.remove();
441
+ placeholder?.remove();
422
442
  element.removeAttribute(ATTRIBUTE);
423
443
  if (utilities.supportsPopover(element)) {
424
444
  element.removeAttribute("popover");
@@ -428,6 +448,7 @@ var Feedback = class extends abstract.Plugin {
428
448
  if (droppable) {
429
449
  droppable.placeholder = void 0;
430
450
  }
451
+ moved = false;
431
452
  };
432
453
  const dropEffectCleanup = state.effect(function dropAnimation() {
433
454
  if (dragOperation.status.dropped) {
@@ -440,7 +461,9 @@ var Feedback = class extends abstract.Plugin {
440
461
  }
441
462
  manager.renderer.rendering.then(() => {
442
463
  utilities.showPopover(element);
443
- const shape2 = new utilities.DOMRectangle(placeholder, true);
464
+ const target = placeholder ?? element;
465
+ styles.remove(["translate"], CSS_PREFIX);
466
+ const shape2 = new utilities.DOMRectangle(target);
444
467
  const currentShape = new utilities.DOMRectangle(element, true).translate(
445
468
  transform.x,
446
469
  transform.y
@@ -466,9 +489,6 @@ var Feedback = class extends abstract.Plugin {
466
489
  duration: moved ? 250 : 0,
467
490
  easing: "ease"
468
491
  },
469
- onReady() {
470
- styles.remove(["translate", "transition"], CSS_PREFIX);
471
- },
472
492
  onFinish() {
473
493
  requestAnimationFrame(restoreFocus);
474
494
  onComplete?.();
@@ -1333,12 +1353,11 @@ var Droppable = class extends abstract.Droppable {
1333
1353
  return this.placeholder ?? this.internal?.element.value;
1334
1354
  }
1335
1355
  refreshShape(ignoreTransform) {
1336
- const { element } = this;
1356
+ const { element, shape } = this;
1337
1357
  if (!element || this.visible === false) {
1338
1358
  this.shape = void 0;
1339
1359
  return void 0;
1340
1360
  }
1341
- const { shape } = this;
1342
1361
  const updatedShape = new utilities.DOMRectangle(element, ignoreTransform);
1343
1362
  if (updatedShape && shape?.equals(updatedShape)) {
1344
1363
  return shape;