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

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
@@ -298,47 +298,20 @@ function debounce(fn, wait) {
298
298
  debounced.cancel = () => clearTimeout(timeout);
299
299
  return debounced;
300
300
  }
301
- var Cursor = class extends abstract.Plugin {
301
+ var styleRegistry = /* @__PURE__ */ new Map();
302
+ var _roots_dec, _targetRoot_dec, _sourceRoot_dec, _additionalRoots_dec, _a, _registeredRules, _init, _additionalRoots, _StyleInjector_instances, syncStyles_fn, inject_fn, injectStyleElement_fn, injectAdoptedSheet_fn;
303
+ var _StyleInjector = class _StyleInjector extends (_a = abstract.CorePlugin, _additionalRoots_dec = [state.reactive], _sourceRoot_dec = [state.derived], _targetRoot_dec = [state.derived], _roots_dec = [state.derived], _a) {
302
304
  constructor(manager, options) {
303
305
  super(manager, options);
304
- this.manager = manager;
305
- const doc = state.computed(
306
- () => {
307
- var _a5;
308
- return utilities.getDocument((_a5 = this.manager.dragOperation.source) == null ? void 0 : _a5.element);
309
- }
310
- );
311
- this.destroy = state.effect(() => {
312
- var _a5;
313
- const { dragOperation } = this.manager;
314
- const { cursor = "grabbing", nonce } = (_a5 = this.options) != null ? _a5 : {};
315
- if (dragOperation.status.initialized) {
316
- const document2 = doc.value;
317
- const style = document2.createElement("style");
318
- if (nonce) {
319
- style.setAttribute("nonce", nonce);
320
- }
321
- style.textContent = `* { cursor: ${cursor} !important; }`;
322
- document2.head.appendChild(style);
323
- return () => style.remove();
324
- }
325
- });
326
- }
327
- };
328
- var styleRegistry = /* @__PURE__ */ new Map();
329
- var _roots_dec, _targetRoot_dec, _sourceRoot_dec, _additionalRoots_dec, _a, _registeredRules, _init, _additionalRoots, _StyleSheetManager_instances, syncStyles_fn, inject_fn, injectStyleElement_fn, injectAdoptedSheet_fn;
330
- var StyleSheetManager = class extends (_a = abstract.CorePlugin, _additionalRoots_dec = [state.reactive], _sourceRoot_dec = [state.derived], _targetRoot_dec = [state.derived], _roots_dec = [state.derived], _a) {
331
- constructor(manager) {
332
- super(manager);
333
306
  __runInitializers(_init, 5, this);
334
- __privateAdd(this, _StyleSheetManager_instances);
307
+ __privateAdd(this, _StyleInjector_instances);
335
308
  __privateAdd(this, _registeredRules, /* @__PURE__ */ new Set());
336
309
  __privateAdd(this, _additionalRoots, __runInitializers(_init, 8, this, /* @__PURE__ */ new Set())), __runInitializers(_init, 11, this);
337
- this.registerEffect(__privateMethod(this, _StyleSheetManager_instances, syncStyles_fn));
310
+ this.registerEffect(__privateMethod(this, _StyleInjector_instances, syncStyles_fn));
338
311
  }
339
312
  /**
340
313
  * Registers CSS rules to be injected into the active drag operation's
341
- * document and shadow roots. The StyleSheetManager handles tracking
314
+ * document and shadow roots. The StyleInjector handles tracking
342
315
  * which roots need the styles and cleaning up when they're no longer needed.
343
316
  *
344
317
  * Returns a cleanup function that unregisters the rules.
@@ -391,13 +364,13 @@ var StyleSheetManager = class extends (_a = abstract.CorePlugin, _additionalRoot
391
364
  _init = __decoratorStart(_a);
392
365
  _registeredRules = new WeakMap();
393
366
  _additionalRoots = new WeakMap();
394
- _StyleSheetManager_instances = new WeakSet();
367
+ _StyleInjector_instances = new WeakSet();
395
368
  syncStyles_fn = function() {
396
369
  const { roots } = this;
397
370
  const cleanups = [];
398
371
  for (const root of roots) {
399
372
  for (const cssRules of __privateGet(this, _registeredRules)) {
400
- cleanups.push(__privateMethod(this, _StyleSheetManager_instances, inject_fn).call(this, root, cssRules));
373
+ cleanups.push(__privateMethod(this, _StyleInjector_instances, inject_fn).call(this, root, cssRules));
401
374
  }
402
375
  }
403
376
  return () => {
@@ -414,7 +387,7 @@ inject_fn = function(root, cssRules) {
414
387
  }
415
388
  let registration = rootStyles.get(cssRules);
416
389
  if (!registration) {
417
- const created = utilities.isDocument(root) ? __privateMethod(this, _StyleSheetManager_instances, injectStyleElement_fn).call(this, root, rootStyles, cssRules) : __privateMethod(this, _StyleSheetManager_instances, injectAdoptedSheet_fn).call(this, root, rootStyles, cssRules);
390
+ const created = utilities.isDocument(root) ? __privateMethod(this, _StyleInjector_instances, injectStyleElement_fn).call(this, root, rootStyles, cssRules) : __privateMethod(this, _StyleInjector_instances, injectAdoptedSheet_fn).call(this, root, rootStyles, cssRules);
418
391
  if (!created) {
419
392
  return () => {
420
393
  };
@@ -439,7 +412,12 @@ inject_fn = function(root, cssRules) {
439
412
  * giving them the lowest cascade priority.
440
413
  */
441
414
  injectStyleElement_fn = function(root, rootStyles, cssRules) {
415
+ var _a5;
442
416
  const style = root.createElement("style");
417
+ const { nonce } = (_a5 = this.options) != null ? _a5 : {};
418
+ if (nonce) {
419
+ style.setAttribute("nonce", nonce);
420
+ }
443
421
  style.textContent = cssRules;
444
422
  root.head.prepend(style);
445
423
  const observer = new MutationObserver((entries) => {
@@ -505,11 +483,35 @@ injectAdoptedSheet_fn = function(root, rootStyles, cssRules) {
505
483
  }
506
484
  };
507
485
  };
508
- __decorateElement(_init, 4, "additionalRoots", _additionalRoots_dec, StyleSheetManager, _additionalRoots);
509
- __decorateElement(_init, 2, "sourceRoot", _sourceRoot_dec, StyleSheetManager);
510
- __decorateElement(_init, 2, "targetRoot", _targetRoot_dec, StyleSheetManager);
511
- __decorateElement(_init, 2, "roots", _roots_dec, StyleSheetManager);
512
- __decoratorMetadata(_init, StyleSheetManager);
486
+ __decorateElement(_init, 4, "additionalRoots", _additionalRoots_dec, _StyleInjector, _additionalRoots);
487
+ __decorateElement(_init, 2, "sourceRoot", _sourceRoot_dec, _StyleInjector);
488
+ __decorateElement(_init, 2, "targetRoot", _targetRoot_dec, _StyleInjector);
489
+ __decorateElement(_init, 2, "roots", _roots_dec, _StyleInjector);
490
+ __decoratorMetadata(_init, _StyleInjector);
491
+ _StyleInjector.configure = abstract.configurator(_StyleInjector);
492
+ var StyleInjector = _StyleInjector;
493
+
494
+ // src/core/plugins/cursor/Cursor.ts
495
+ var Cursor = class extends abstract.Plugin {
496
+ constructor(manager, options) {
497
+ super(manager, options);
498
+ this.manager = manager;
499
+ const { cursor = "grabbing" } = options != null ? options : {};
500
+ const styleInjector = manager.registry.plugins.get(
501
+ StyleInjector
502
+ );
503
+ const unregisterStyles = styleInjector == null ? void 0 : styleInjector.register(
504
+ `* { cursor: ${cursor} !important; }`
505
+ );
506
+ if (unregisterStyles) {
507
+ const originalDestroy = this.destroy.bind(this);
508
+ this.destroy = () => {
509
+ unregisterStyles();
510
+ originalDestroy();
511
+ };
512
+ }
513
+ }
514
+ };
513
515
 
514
516
  // src/core/plugins/feedback/constants.ts
515
517
  var ATTR_PREFIX = "data-dnd-";
@@ -855,10 +857,10 @@ var _Feedback = class _Feedback extends (_a2 = abstract.Plugin, _overlay_dec = [
855
857
  initial: {},
856
858
  current: {}
857
859
  };
858
- const styleSheetManager = manager.registry.plugins.get(
859
- StyleSheetManager
860
+ const styleInjector = manager.registry.plugins.get(
861
+ StyleInjector
860
862
  );
861
- const unregisterStyles = styleSheetManager == null ? void 0 : styleSheetManager.register(CSS_RULES);
863
+ const unregisterStyles = styleInjector == null ? void 0 : styleInjector.register(CSS_RULES);
862
864
  if (unregisterStyles) {
863
865
  const originalDestroy = this.destroy.bind(this);
864
866
  this.destroy = () => {
@@ -866,19 +868,19 @@ var _Feedback = class _Feedback extends (_a2 = abstract.Plugin, _overlay_dec = [
866
868
  originalDestroy();
867
869
  };
868
870
  }
869
- this.registerEffect(__privateMethod(this, _Feedback_instances, trackOverlayRoot_fn).bind(this, styleSheetManager));
871
+ this.registerEffect(__privateMethod(this, _Feedback_instances, trackOverlayRoot_fn).bind(this, styleInjector));
870
872
  this.registerEffect(__privateMethod(this, _Feedback_instances, render_fn));
871
873
  }
872
874
  };
873
875
  _init2 = __decoratorStart(_a2);
874
876
  _overlay = new WeakMap();
875
877
  _Feedback_instances = new WeakSet();
876
- trackOverlayRoot_fn = function(styleSheetManager) {
878
+ trackOverlayRoot_fn = function(styleInjector) {
877
879
  const { overlay } = this;
878
- if (!overlay || !styleSheetManager) return;
880
+ if (!overlay || !styleInjector) return;
879
881
  const root = utilities.getRoot(overlay);
880
882
  if (!root) return;
881
- return styleSheetManager.addRoot(root);
883
+ return styleInjector.addRoot(root);
882
884
  };
883
885
  render_fn = function() {
884
886
  var _a5, _b2, _c3;
@@ -1537,21 +1539,18 @@ var ScrollListener = class extends abstract.CorePlugin {
1537
1539
  }
1538
1540
  };
1539
1541
  _timeout = new WeakMap();
1542
+ var CSS_RULES2 = "* { user-select: none !important; -webkit-user-select: none !important; }";
1540
1543
  var PreventSelection = class extends abstract.Plugin {
1541
- constructor(manager, options) {
1542
- super(manager, options);
1544
+ constructor(manager) {
1545
+ super(manager);
1543
1546
  this.manager = manager;
1547
+ const styleInjector = manager.registry.plugins.get(
1548
+ StyleInjector
1549
+ );
1550
+ const unregisterStyles = styleInjector == null ? void 0 : styleInjector.register(CSS_RULES2);
1544
1551
  this.destroy = state.effect(() => {
1545
- var _a5;
1546
1552
  const { dragOperation } = this.manager;
1547
- const { nonce } = (_a5 = this.options) != null ? _a5 : {};
1548
1553
  if (dragOperation.status.initialized) {
1549
- const style = document.createElement("style");
1550
- if (nonce) {
1551
- style.setAttribute("nonce", nonce);
1552
- }
1553
- style.textContent = `* { user-select: none !important; -webkit-user-select: none !important; }`;
1554
- document.head.appendChild(style);
1555
1554
  removeSelection();
1556
1555
  document.addEventListener("selectionchange", removeSelection, {
1557
1556
  capture: true
@@ -1560,10 +1559,16 @@ var PreventSelection = class extends abstract.Plugin {
1560
1559
  document.removeEventListener("selectionchange", removeSelection, {
1561
1560
  capture: true
1562
1561
  });
1563
- style.remove();
1564
1562
  };
1565
1563
  }
1566
1564
  });
1565
+ if (unregisterStyles) {
1566
+ const originalDestroy = this.destroy.bind(this);
1567
+ this.destroy = () => {
1568
+ unregisterStyles();
1569
+ originalDestroy();
1570
+ };
1571
+ }
1567
1572
  }
1568
1573
  };
1569
1574
  function removeSelection() {
@@ -2121,7 +2126,7 @@ var DragDropManager = class extends abstract.DragDropManager {
2121
2126
  const sensors = abstract.resolveCustomizable(input.sensors, defaultPreset.sensors);
2122
2127
  const modifiers = abstract.resolveCustomizable(input.modifiers, defaultPreset.modifiers);
2123
2128
  super(__spreadProps(__spreadValues({}, input), {
2124
- plugins: [ScrollListener, Scroller, StyleSheetManager, ...plugins],
2129
+ plugins: [ScrollListener, Scroller, StyleInjector, ...plugins],
2125
2130
  sensors,
2126
2131
  modifiers
2127
2132
  }));
@@ -2281,7 +2286,7 @@ exports.PointerSensor = PointerSensor;
2281
2286
  exports.PreventSelection = PreventSelection;
2282
2287
  exports.ScrollListener = ScrollListener;
2283
2288
  exports.Scroller = Scroller;
2284
- exports.StyleSheetManager = StyleSheetManager;
2289
+ exports.StyleInjector = StyleInjector;
2285
2290
  exports.defaultPreset = defaultPreset;
2286
2291
  //# sourceMappingURL=index.cjs.map
2287
2292
  //# sourceMappingURL=index.cjs.map