@dnd-kit/dom 0.3.2 → 0.4.0-beta-20260219123322

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.d.cts CHANGED
@@ -238,10 +238,6 @@ interface CursorPluginOptions {
238
238
  * @default 'grabbing'
239
239
  */
240
240
  cursor?: string;
241
- /**
242
- * The nonce to be applied to the style element.
243
- */
244
- nonce?: string;
245
241
  }
246
242
  declare class Cursor extends Plugin<DragDropManager> {
247
243
  manager: DragDropManager;
@@ -265,7 +261,6 @@ type DropAnimation = DropAnimationOptions | DropAnimationFunction;
265
261
 
266
262
  interface FeedbackOptions {
267
263
  rootElement?: Element | ((source: Draggable) => Element);
268
- nonce?: string;
269
264
  dropAnimation?: DropAnimation | null;
270
265
  }
271
266
  declare class Feedback extends Plugin<DragDropManager, FeedbackOptions> {
@@ -322,25 +317,22 @@ declare class ScrollListener extends CorePlugin<DragDropManager> {
322
317
  private handleScroll;
323
318
  }
324
319
 
325
- interface PreventSelectionPluginOptions {
326
- /**
327
- * The nonce to be applied to the style element.
328
- */
329
- nonce?: string;
330
- }
331
320
  declare class PreventSelection extends Plugin<DragDropManager> {
332
321
  manager: DragDropManager;
333
- constructor(manager: DragDropManager, options?: PreventSelectionPluginOptions);
322
+ constructor(manager: DragDropManager);
334
323
  }
335
324
 
336
325
  type CleanupFunction = () => void;
337
- declare class StyleSheetManager extends CorePlugin<DragDropManager> {
326
+ interface StyleInjectorOptions {
327
+ nonce?: string;
328
+ }
329
+ declare class StyleInjector extends CorePlugin<DragDropManager, StyleInjectorOptions> {
338
330
  #private;
339
331
  private accessor additionalRoots;
340
- constructor(manager: DragDropManager);
332
+ constructor(manager: DragDropManager, options?: StyleInjectorOptions);
341
333
  /**
342
334
  * Registers CSS rules to be injected into the active drag operation's
343
- * document and shadow roots. The StyleSheetManager handles tracking
335
+ * document and shadow roots. The StyleInjector handles tracking
344
336
  * which roots need the styles and cleaning up when they're no longer needed.
345
337
  *
346
338
  * Returns a cleanup function that unregisters the rules.
@@ -354,6 +346,7 @@ declare class StyleSheetManager extends CorePlugin<DragDropManager> {
354
346
  private get sourceRoot();
355
347
  private get targetRoot();
356
348
  private get roots();
349
+ static configure: (options: StyleInjectorOptions) => _dnd_kit_abstract.PluginDescriptor<any, any, typeof StyleInjector>;
357
350
  }
358
351
 
359
- export { Accessibility, AutoScroller, type BeforeDragStartEvent, type CollisionEvent, Cursor, DragDropManager, type Input as DragDropManagerInput, type DragEndEvent, type DragMoveEvent, type DragOverEvent, type DragStartEvent, Draggable, type Input$2 as DraggableInput, type DropAnimation, type DropAnimationFunction, type DropAnimationOptions, Droppable, type Input$1 as DroppableInput, Feedback, type FeedbackType, KeyboardSensor, type KeyboardSensorOptions, PointerActivationConstraints, PointerSensor, type PointerSensorOptions, PreventSelection, ScrollListener, Scroller, type Sensors, StyleSheetManager, type Transition, defaultPreset };
352
+ export { Accessibility, AutoScroller, type BeforeDragStartEvent, type CollisionEvent, Cursor, DragDropManager, type Input as DragDropManagerInput, type DragEndEvent, type DragMoveEvent, type DragOverEvent, type DragStartEvent, Draggable, type Input$2 as DraggableInput, type DropAnimation, type DropAnimationFunction, type DropAnimationOptions, Droppable, type Input$1 as DroppableInput, Feedback, type FeedbackType, KeyboardSensor, type KeyboardSensorOptions, PointerActivationConstraints, PointerSensor, type PointerSensorOptions, PreventSelection, ScrollListener, Scroller, type Sensors, StyleInjector, type Transition, defaultPreset };
package/index.d.ts CHANGED
@@ -238,10 +238,6 @@ interface CursorPluginOptions {
238
238
  * @default 'grabbing'
239
239
  */
240
240
  cursor?: string;
241
- /**
242
- * The nonce to be applied to the style element.
243
- */
244
- nonce?: string;
245
241
  }
246
242
  declare class Cursor extends Plugin<DragDropManager> {
247
243
  manager: DragDropManager;
@@ -265,7 +261,6 @@ type DropAnimation = DropAnimationOptions | DropAnimationFunction;
265
261
 
266
262
  interface FeedbackOptions {
267
263
  rootElement?: Element | ((source: Draggable) => Element);
268
- nonce?: string;
269
264
  dropAnimation?: DropAnimation | null;
270
265
  }
271
266
  declare class Feedback extends Plugin<DragDropManager, FeedbackOptions> {
@@ -322,25 +317,22 @@ declare class ScrollListener extends CorePlugin<DragDropManager> {
322
317
  private handleScroll;
323
318
  }
324
319
 
325
- interface PreventSelectionPluginOptions {
326
- /**
327
- * The nonce to be applied to the style element.
328
- */
329
- nonce?: string;
330
- }
331
320
  declare class PreventSelection extends Plugin<DragDropManager> {
332
321
  manager: DragDropManager;
333
- constructor(manager: DragDropManager, options?: PreventSelectionPluginOptions);
322
+ constructor(manager: DragDropManager);
334
323
  }
335
324
 
336
325
  type CleanupFunction = () => void;
337
- declare class StyleSheetManager extends CorePlugin<DragDropManager> {
326
+ interface StyleInjectorOptions {
327
+ nonce?: string;
328
+ }
329
+ declare class StyleInjector extends CorePlugin<DragDropManager, StyleInjectorOptions> {
338
330
  #private;
339
331
  private accessor additionalRoots;
340
- constructor(manager: DragDropManager);
332
+ constructor(manager: DragDropManager, options?: StyleInjectorOptions);
341
333
  /**
342
334
  * Registers CSS rules to be injected into the active drag operation's
343
- * document and shadow roots. The StyleSheetManager handles tracking
335
+ * document and shadow roots. The StyleInjector handles tracking
344
336
  * which roots need the styles and cleaning up when they're no longer needed.
345
337
  *
346
338
  * Returns a cleanup function that unregisters the rules.
@@ -354,6 +346,7 @@ declare class StyleSheetManager extends CorePlugin<DragDropManager> {
354
346
  private get sourceRoot();
355
347
  private get targetRoot();
356
348
  private get roots();
349
+ static configure: (options: StyleInjectorOptions) => _dnd_kit_abstract.PluginDescriptor<any, any, typeof StyleInjector>;
357
350
  }
358
351
 
359
- export { Accessibility, AutoScroller, type BeforeDragStartEvent, type CollisionEvent, Cursor, DragDropManager, type Input as DragDropManagerInput, type DragEndEvent, type DragMoveEvent, type DragOverEvent, type DragStartEvent, Draggable, type Input$2 as DraggableInput, type DropAnimation, type DropAnimationFunction, type DropAnimationOptions, Droppable, type Input$1 as DroppableInput, Feedback, type FeedbackType, KeyboardSensor, type KeyboardSensorOptions, PointerActivationConstraints, PointerSensor, type PointerSensorOptions, PreventSelection, ScrollListener, Scroller, type Sensors, StyleSheetManager, type Transition, defaultPreset };
352
+ export { Accessibility, AutoScroller, type BeforeDragStartEvent, type CollisionEvent, Cursor, DragDropManager, type Input as DragDropManagerInput, type DragEndEvent, type DragMoveEvent, type DragOverEvent, type DragStartEvent, Draggable, type Input$2 as DraggableInput, type DropAnimation, type DropAnimationFunction, type DropAnimationOptions, Droppable, type Input$1 as DroppableInput, Feedback, type FeedbackType, KeyboardSensor, type KeyboardSensorOptions, PointerActivationConstraints, PointerSensor, type PointerSensorOptions, PreventSelection, ScrollListener, Scroller, type Sensors, StyleInjector, type Transition, defaultPreset };
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { configurator, Sensor, ActivationController, Plugin, CorePlugin, DragDropManager as DragDropManager$1, resolveCustomizable, Draggable as Draggable$1, Droppable as Droppable$1, ActivationConstraint, descriptor } from '@dnd-kit/abstract';
1
+ import { configurator, Sensor, ActivationController, CorePlugin, Plugin, DragDropManager as DragDropManager$1, resolveCustomizable, Draggable as Draggable$1, Droppable as Droppable$1, ActivationConstraint, descriptor } from '@dnd-kit/abstract';
2
2
  export { resolveCustomizable } from '@dnd-kit/abstract';
3
- import { ScrollDirection, Listeners, isElement, scrollIntoViewIfNeeded, DOMRectangle, getDocument, isHTMLElement, getFrameTransform, getEventCoordinates, getDocuments, scheduler, isInteractiveElement, isTextInput, getRoot, isKeyboardEvent, isPointerEvent, canScroll, detectScrollIntent, getElementFromPoint, getScrollableAncestors, generateUniqueId, isSafari, isDocument, isShadowRoot, Styles, getComputedStyles, parseTranslate, getFixedPositionOffset, supportsPopover, showPopover, getWindow, prefersReducedMotion, getFrameElement, cloneElement, supportsStyle, getFinalKeyframe, animateTransform, ProxiedElements, PositionObserver } from '@dnd-kit/dom/utilities';
4
- import { effect, untracked, computed, deepEqual, signal, batch, effects, reactive, derived } from '@dnd-kit/state';
3
+ import { ScrollDirection, getRoot, Listeners, isElement, scrollIntoViewIfNeeded, DOMRectangle, getDocument, isHTMLElement, getFrameTransform, getEventCoordinates, getDocuments, scheduler, isInteractiveElement, isTextInput, isKeyboardEvent, isPointerEvent, canScroll, detectScrollIntent, getElementFromPoint, getScrollableAncestors, generateUniqueId, isSafari, isDocument, isShadowRoot, Styles, getComputedStyles, parseTranslate, getFixedPositionOffset, supportsPopover, showPopover, getWindow, prefersReducedMotion, getFrameElement, cloneElement, supportsStyle, getFinalKeyframe, animateTransform, ProxiedElements, PositionObserver } from '@dnd-kit/dom/utilities';
4
+ import { untracked, effect, computed, deepEqual, signal, batch, effects, reactive, derived } from '@dnd-kit/state';
5
5
  import { Axes, Point, Rectangle, exceedsDistance } from '@dnd-kit/geometry';
6
6
  import { defaultCollisionDetection } from '@dnd-kit/collision';
7
7
 
@@ -297,47 +297,20 @@ function debounce(fn, wait) {
297
297
  debounced.cancel = () => clearTimeout(timeout);
298
298
  return debounced;
299
299
  }
300
- var Cursor = class extends Plugin {
300
+ var styleRegistry = /* @__PURE__ */ new Map();
301
+ var _roots_dec, _targetRoot_dec, _sourceRoot_dec, _additionalRoots_dec, _a, _registeredRules, _init, _additionalRoots, _StyleInjector_instances, syncStyles_fn, inject_fn, injectStyleElement_fn, injectAdoptedSheet_fn;
302
+ var _StyleInjector = class _StyleInjector extends (_a = CorePlugin, _additionalRoots_dec = [reactive], _sourceRoot_dec = [derived], _targetRoot_dec = [derived], _roots_dec = [derived], _a) {
301
303
  constructor(manager, options) {
302
304
  super(manager, options);
303
- this.manager = manager;
304
- const doc = computed(
305
- () => {
306
- var _a5;
307
- return getDocument((_a5 = this.manager.dragOperation.source) == null ? void 0 : _a5.element);
308
- }
309
- );
310
- this.destroy = effect(() => {
311
- var _a5;
312
- const { dragOperation } = this.manager;
313
- const { cursor = "grabbing", nonce } = (_a5 = this.options) != null ? _a5 : {};
314
- if (dragOperation.status.initialized) {
315
- const document2 = doc.value;
316
- const style = document2.createElement("style");
317
- if (nonce) {
318
- style.setAttribute("nonce", nonce);
319
- }
320
- style.textContent = `* { cursor: ${cursor} !important; }`;
321
- document2.head.appendChild(style);
322
- return () => style.remove();
323
- }
324
- });
325
- }
326
- };
327
- var styleRegistry = /* @__PURE__ */ new Map();
328
- var _roots_dec, _targetRoot_dec, _sourceRoot_dec, _additionalRoots_dec, _a, _registeredRules, _init, _additionalRoots, _StyleSheetManager_instances, syncStyles_fn, inject_fn, injectStyleElement_fn, injectAdoptedSheet_fn;
329
- var StyleSheetManager = class extends (_a = CorePlugin, _additionalRoots_dec = [reactive], _sourceRoot_dec = [derived], _targetRoot_dec = [derived], _roots_dec = [derived], _a) {
330
- constructor(manager) {
331
- super(manager);
332
305
  __runInitializers(_init, 5, this);
333
- __privateAdd(this, _StyleSheetManager_instances);
306
+ __privateAdd(this, _StyleInjector_instances);
334
307
  __privateAdd(this, _registeredRules, /* @__PURE__ */ new Set());
335
308
  __privateAdd(this, _additionalRoots, __runInitializers(_init, 8, this, /* @__PURE__ */ new Set())), __runInitializers(_init, 11, this);
336
- this.registerEffect(__privateMethod(this, _StyleSheetManager_instances, syncStyles_fn));
309
+ this.registerEffect(__privateMethod(this, _StyleInjector_instances, syncStyles_fn));
337
310
  }
338
311
  /**
339
312
  * Registers CSS rules to be injected into the active drag operation's
340
- * document and shadow roots. The StyleSheetManager handles tracking
313
+ * document and shadow roots. The StyleInjector handles tracking
341
314
  * which roots need the styles and cleaning up when they're no longer needed.
342
315
  *
343
316
  * Returns a cleanup function that unregisters the rules.
@@ -390,13 +363,13 @@ var StyleSheetManager = class extends (_a = CorePlugin, _additionalRoots_dec = [
390
363
  _init = __decoratorStart(_a);
391
364
  _registeredRules = new WeakMap();
392
365
  _additionalRoots = new WeakMap();
393
- _StyleSheetManager_instances = new WeakSet();
366
+ _StyleInjector_instances = new WeakSet();
394
367
  syncStyles_fn = function() {
395
368
  const { roots } = this;
396
369
  const cleanups = [];
397
370
  for (const root of roots) {
398
371
  for (const cssRules of __privateGet(this, _registeredRules)) {
399
- cleanups.push(__privateMethod(this, _StyleSheetManager_instances, inject_fn).call(this, root, cssRules));
372
+ cleanups.push(__privateMethod(this, _StyleInjector_instances, inject_fn).call(this, root, cssRules));
400
373
  }
401
374
  }
402
375
  return () => {
@@ -413,7 +386,7 @@ inject_fn = function(root, cssRules) {
413
386
  }
414
387
  let registration = rootStyles.get(cssRules);
415
388
  if (!registration) {
416
- const created = isDocument(root) ? __privateMethod(this, _StyleSheetManager_instances, injectStyleElement_fn).call(this, root, rootStyles, cssRules) : __privateMethod(this, _StyleSheetManager_instances, injectAdoptedSheet_fn).call(this, root, rootStyles, cssRules);
389
+ const created = isDocument(root) ? __privateMethod(this, _StyleInjector_instances, injectStyleElement_fn).call(this, root, rootStyles, cssRules) : __privateMethod(this, _StyleInjector_instances, injectAdoptedSheet_fn).call(this, root, rootStyles, cssRules);
417
390
  if (!created) {
418
391
  return () => {
419
392
  };
@@ -438,7 +411,12 @@ inject_fn = function(root, cssRules) {
438
411
  * giving them the lowest cascade priority.
439
412
  */
440
413
  injectStyleElement_fn = function(root, rootStyles, cssRules) {
414
+ var _a5;
441
415
  const style = root.createElement("style");
416
+ const { nonce } = (_a5 = this.options) != null ? _a5 : {};
417
+ if (nonce) {
418
+ style.setAttribute("nonce", nonce);
419
+ }
442
420
  style.textContent = cssRules;
443
421
  root.head.prepend(style);
444
422
  const observer = new MutationObserver((entries) => {
@@ -504,11 +482,35 @@ injectAdoptedSheet_fn = function(root, rootStyles, cssRules) {
504
482
  }
505
483
  };
506
484
  };
507
- __decorateElement(_init, 4, "additionalRoots", _additionalRoots_dec, StyleSheetManager, _additionalRoots);
508
- __decorateElement(_init, 2, "sourceRoot", _sourceRoot_dec, StyleSheetManager);
509
- __decorateElement(_init, 2, "targetRoot", _targetRoot_dec, StyleSheetManager);
510
- __decorateElement(_init, 2, "roots", _roots_dec, StyleSheetManager);
511
- __decoratorMetadata(_init, StyleSheetManager);
485
+ __decorateElement(_init, 4, "additionalRoots", _additionalRoots_dec, _StyleInjector, _additionalRoots);
486
+ __decorateElement(_init, 2, "sourceRoot", _sourceRoot_dec, _StyleInjector);
487
+ __decorateElement(_init, 2, "targetRoot", _targetRoot_dec, _StyleInjector);
488
+ __decorateElement(_init, 2, "roots", _roots_dec, _StyleInjector);
489
+ __decoratorMetadata(_init, _StyleInjector);
490
+ _StyleInjector.configure = configurator(_StyleInjector);
491
+ var StyleInjector = _StyleInjector;
492
+
493
+ // src/core/plugins/cursor/Cursor.ts
494
+ var Cursor = class extends Plugin {
495
+ constructor(manager, options) {
496
+ super(manager, options);
497
+ this.manager = manager;
498
+ const { cursor = "grabbing" } = options != null ? options : {};
499
+ const styleInjector = manager.registry.plugins.get(
500
+ StyleInjector
501
+ );
502
+ const unregisterStyles = styleInjector == null ? void 0 : styleInjector.register(
503
+ `* { cursor: ${cursor} !important; }`
504
+ );
505
+ if (unregisterStyles) {
506
+ const originalDestroy = this.destroy.bind(this);
507
+ this.destroy = () => {
508
+ unregisterStyles();
509
+ originalDestroy();
510
+ };
511
+ }
512
+ }
513
+ };
512
514
 
513
515
  // src/core/plugins/feedback/constants.ts
514
516
  var ATTR_PREFIX = "data-dnd-";
@@ -854,10 +856,10 @@ var _Feedback = class _Feedback extends (_a2 = Plugin, _overlay_dec = [reactive]
854
856
  initial: {},
855
857
  current: {}
856
858
  };
857
- const styleSheetManager = manager.registry.plugins.get(
858
- StyleSheetManager
859
+ const styleInjector = manager.registry.plugins.get(
860
+ StyleInjector
859
861
  );
860
- const unregisterStyles = styleSheetManager == null ? void 0 : styleSheetManager.register(CSS_RULES);
862
+ const unregisterStyles = styleInjector == null ? void 0 : styleInjector.register(CSS_RULES);
861
863
  if (unregisterStyles) {
862
864
  const originalDestroy = this.destroy.bind(this);
863
865
  this.destroy = () => {
@@ -865,19 +867,19 @@ var _Feedback = class _Feedback extends (_a2 = Plugin, _overlay_dec = [reactive]
865
867
  originalDestroy();
866
868
  };
867
869
  }
868
- this.registerEffect(__privateMethod(this, _Feedback_instances, trackOverlayRoot_fn).bind(this, styleSheetManager));
870
+ this.registerEffect(__privateMethod(this, _Feedback_instances, trackOverlayRoot_fn).bind(this, styleInjector));
869
871
  this.registerEffect(__privateMethod(this, _Feedback_instances, render_fn));
870
872
  }
871
873
  };
872
874
  _init2 = __decoratorStart(_a2);
873
875
  _overlay = new WeakMap();
874
876
  _Feedback_instances = new WeakSet();
875
- trackOverlayRoot_fn = function(styleSheetManager) {
877
+ trackOverlayRoot_fn = function(styleInjector) {
876
878
  const { overlay } = this;
877
- if (!overlay || !styleSheetManager) return;
879
+ if (!overlay || !styleInjector) return;
878
880
  const root = getRoot(overlay);
879
881
  if (!root) return;
880
- return styleSheetManager.addRoot(root);
882
+ return styleInjector.addRoot(root);
881
883
  };
882
884
  render_fn = function() {
883
885
  var _a5, _b2, _c3;
@@ -1536,21 +1538,18 @@ var ScrollListener = class extends CorePlugin {
1536
1538
  }
1537
1539
  };
1538
1540
  _timeout = new WeakMap();
1541
+ var CSS_RULES2 = "* { user-select: none !important; -webkit-user-select: none !important; }";
1539
1542
  var PreventSelection = class extends Plugin {
1540
- constructor(manager, options) {
1541
- super(manager, options);
1543
+ constructor(manager) {
1544
+ super(manager);
1542
1545
  this.manager = manager;
1546
+ const styleInjector = manager.registry.plugins.get(
1547
+ StyleInjector
1548
+ );
1549
+ const unregisterStyles = styleInjector == null ? void 0 : styleInjector.register(CSS_RULES2);
1543
1550
  this.destroy = effect(() => {
1544
- var _a5;
1545
1551
  const { dragOperation } = this.manager;
1546
- const { nonce } = (_a5 = this.options) != null ? _a5 : {};
1547
1552
  if (dragOperation.status.initialized) {
1548
- const style = document.createElement("style");
1549
- if (nonce) {
1550
- style.setAttribute("nonce", nonce);
1551
- }
1552
- style.textContent = `* { user-select: none !important; -webkit-user-select: none !important; }`;
1553
- document.head.appendChild(style);
1554
1553
  removeSelection();
1555
1554
  document.addEventListener("selectionchange", removeSelection, {
1556
1555
  capture: true
@@ -1559,10 +1558,16 @@ var PreventSelection = class extends Plugin {
1559
1558
  document.removeEventListener("selectionchange", removeSelection, {
1560
1559
  capture: true
1561
1560
  });
1562
- style.remove();
1563
1561
  };
1564
1562
  }
1565
1563
  });
1564
+ if (unregisterStyles) {
1565
+ const originalDestroy = this.destroy.bind(this);
1566
+ this.destroy = () => {
1567
+ unregisterStyles();
1568
+ originalDestroy();
1569
+ };
1570
+ }
1566
1571
  }
1567
1572
  };
1568
1573
  function removeSelection() {
@@ -2120,7 +2125,7 @@ var DragDropManager = class extends DragDropManager$1 {
2120
2125
  const sensors = resolveCustomizable(input.sensors, defaultPreset.sensors);
2121
2126
  const modifiers = resolveCustomizable(input.modifiers, defaultPreset.modifiers);
2122
2127
  super(__spreadProps(__spreadValues({}, input), {
2123
- plugins: [ScrollListener, Scroller, StyleSheetManager, ...plugins],
2128
+ plugins: [ScrollListener, Scroller, StyleInjector, ...plugins],
2124
2129
  sensors,
2125
2130
  modifiers
2126
2131
  }));
@@ -2263,6 +2268,6 @@ _d = __decorateElement(_init6, 20, "#element", _element_dec2, _Droppable_instanc
2263
2268
  __decorateElement(_init6, 4, "proxy", _proxy_dec, Droppable, _proxy);
2264
2269
  __decoratorMetadata(_init6, Droppable);
2265
2270
 
2266
- export { Accessibility, AutoScroller, Cursor, DragDropManager, Draggable, Droppable, Feedback, KeyboardSensor, PointerActivationConstraints, PointerSensor, PreventSelection, ScrollListener, Scroller, StyleSheetManager, defaultPreset };
2271
+ export { Accessibility, AutoScroller, Cursor, DragDropManager, Draggable, Droppable, Feedback, KeyboardSensor, PointerActivationConstraints, PointerSensor, PreventSelection, ScrollListener, Scroller, StyleInjector, defaultPreset };
2267
2272
  //# sourceMappingURL=index.js.map
2268
2273
  //# sourceMappingURL=index.js.map