svelte-dnd-action 0.9.60 → 0.9.62

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/dist/index.js CHANGED
@@ -2629,10 +2629,10 @@
2629
2629
  }
2630
2630
 
2631
2631
  var isItemsDragDisabled = createStore(true);
2632
+ var userDragDisabled = createStore(false);
2632
2633
  function getAddedOptions() {
2633
- var isItemsDragDisabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
2634
2634
  return {
2635
- dragDisabled: isItemsDragDisabled,
2635
+ dragDisabled: userDragDisabled.get() || isItemsDragDisabled.get(),
2636
2636
  zoneItemTabIndex: -1
2637
2637
  };
2638
2638
  }
@@ -2647,12 +2647,22 @@
2647
2647
  * @return {{update: (newOptions: Object) => {}, destroy: () => {}}}
2648
2648
  */
2649
2649
  function dragHandleZone(node, options) {
2650
+ var _options$dragDisabled;
2651
+ // Initialise stores from initial options
2652
+ userDragDisabled.set((_options$dragDisabled = options === null || options === void 0 ? void 0 : options.dragDisabled) !== null && _options$dragDisabled !== void 0 ? _options$dragDisabled : false);
2650
2653
  var currentOptions = options;
2651
2654
  var zone = dndzone(node, _objectSpread2(_objectSpread2({}, currentOptions), getAddedOptions()));
2652
- function isItemDisabledCB(isItemsDragDisabled) {
2653
- zone.update(_objectSpread2(_objectSpread2({}, currentOptions), getAddedOptions(isItemsDragDisabled)));
2655
+ function updateZone() {
2656
+ zone.update(_objectSpread2(_objectSpread2({}, currentOptions), getAddedOptions()));
2654
2657
  }
2655
- isItemsDragDisabled.subscribe(isItemDisabledCB);
2658
+
2659
+ // Subscribe to internal store so finishing a drag updates the zone
2660
+ isItemsDragDisabled.subscribe(updateZone);
2661
+
2662
+ // We don't need to subscribe to userDragDisabled here because updates to
2663
+ // it always come through the `update` lifecycle and will call `updateZone`
2664
+ // anyway.
2665
+
2656
2666
  function consider(e) {
2657
2667
  var _e$detail$info = e.detail.info,
2658
2668
  source = _e$detail$info.source,
@@ -2673,13 +2683,16 @@
2673
2683
  node.addEventListener("finalize", finalize);
2674
2684
  return {
2675
2685
  update: function update(newOptions) {
2686
+ var _currentOptions$dragD, _currentOptions;
2676
2687
  currentOptions = newOptions;
2677
- zone.update(_objectSpread2(_objectSpread2({}, currentOptions), getAddedOptions(isItemsDragDisabled.get())));
2688
+ // keep store in sync with external prop
2689
+ userDragDisabled.set((_currentOptions$dragD = (_currentOptions = currentOptions) === null || _currentOptions === void 0 ? void 0 : _currentOptions.dragDisabled) !== null && _currentOptions$dragD !== void 0 ? _currentOptions$dragD : false);
2690
+ updateZone();
2678
2691
  },
2679
2692
  destroy: function destroy() {
2680
2693
  node.removeEventListener("consider", consider);
2681
2694
  node.removeEventListener("finalize", finalize);
2682
- isItemsDragDisabled.unsubscribe(isItemDisabledCB);
2695
+ isItemsDragDisabled.unsubscribe(updateZone);
2683
2696
  }
2684
2697
  };
2685
2698
  }
@@ -2695,14 +2708,34 @@
2695
2708
  // preventing default to prevent lag on touch devices (because of the browser checking for screen scrolling)
2696
2709
  e.preventDefault();
2697
2710
  isItemsDragDisabled.set(false);
2711
+
2712
+ // Reset the startDrag/isItemsDragDisabled if the user releases the mouse/touch without initiating a drag
2713
+ window.addEventListener("mouseup", resetStartDrag);
2714
+ window.addEventListener("touchend", resetStartDrag);
2698
2715
  }
2699
2716
  function handleKeyDown(e) {
2700
2717
  if (e.key === "Enter" || e.key === " ") isItemsDragDisabled.set(false);
2701
2718
  }
2702
- isItemsDragDisabled.subscribe(function (disabled) {
2703
- handle.tabIndex = disabled ? 0 : -1;
2704
- handle.style.cursor = disabled ? "grab" : "grabbing";
2705
- });
2719
+ function resetStartDrag() {
2720
+ isItemsDragDisabled.set(true);
2721
+ window.removeEventListener("mouseup", resetStartDrag);
2722
+ window.removeEventListener("touchend", resetStartDrag);
2723
+ }
2724
+ var recomputeHandleState = function recomputeHandleState() {
2725
+ var userDisabled = userDragDisabled.get();
2726
+ var internalDisabled = isItemsDragDisabled.get();
2727
+ if (userDisabled) {
2728
+ handle.tabIndex = -1;
2729
+ handle.style.cursor = ""; // default cursor
2730
+ } else {
2731
+ handle.tabIndex = internalDisabled ? 0 : -1;
2732
+ handle.style.cursor = internalDisabled ? "grab" : "grabbing";
2733
+ }
2734
+ };
2735
+
2736
+ // Subscribe to both stores
2737
+ userDragDisabled.subscribe(recomputeHandleState);
2738
+ isItemsDragDisabled.subscribe(recomputeHandleState);
2706
2739
  handle.addEventListener("mousedown", startDrag);
2707
2740
  handle.addEventListener("touchstart", startDrag);
2708
2741
  handle.addEventListener("keydown", handleKeyDown);
@@ -2712,6 +2745,8 @@
2712
2745
  handle.removeEventListener("mousedown", startDrag);
2713
2746
  handle.removeEventListener("touchstart", startDrag);
2714
2747
  handle.removeEventListener("keydown", handleKeyDown);
2748
+ userDragDisabled.unsubscribe(recomputeHandleState);
2749
+ isItemsDragDisabled.unsubscribe(recomputeHandleState);
2715
2750
  }
2716
2751
  };
2717
2752
  }
package/dist/index.mjs CHANGED
@@ -2623,10 +2623,10 @@ function createStore(initialValue) {
2623
2623
  }
2624
2624
 
2625
2625
  var isItemsDragDisabled = createStore(true);
2626
+ var userDragDisabled = createStore(false);
2626
2627
  function getAddedOptions() {
2627
- var isItemsDragDisabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
2628
2628
  return {
2629
- dragDisabled: isItemsDragDisabled,
2629
+ dragDisabled: userDragDisabled.get() || isItemsDragDisabled.get(),
2630
2630
  zoneItemTabIndex: -1
2631
2631
  };
2632
2632
  }
@@ -2641,12 +2641,22 @@ function getAddedOptions() {
2641
2641
  * @return {{update: (newOptions: Object) => {}, destroy: () => {}}}
2642
2642
  */
2643
2643
  function dragHandleZone(node, options) {
2644
+ var _options$dragDisabled;
2645
+ // Initialise stores from initial options
2646
+ userDragDisabled.set((_options$dragDisabled = options === null || options === void 0 ? void 0 : options.dragDisabled) !== null && _options$dragDisabled !== void 0 ? _options$dragDisabled : false);
2644
2647
  var currentOptions = options;
2645
2648
  var zone = dndzone(node, _objectSpread2(_objectSpread2({}, currentOptions), getAddedOptions()));
2646
- function isItemDisabledCB(isItemsDragDisabled) {
2647
- zone.update(_objectSpread2(_objectSpread2({}, currentOptions), getAddedOptions(isItemsDragDisabled)));
2649
+ function updateZone() {
2650
+ zone.update(_objectSpread2(_objectSpread2({}, currentOptions), getAddedOptions()));
2648
2651
  }
2649
- isItemsDragDisabled.subscribe(isItemDisabledCB);
2652
+
2653
+ // Subscribe to internal store so finishing a drag updates the zone
2654
+ isItemsDragDisabled.subscribe(updateZone);
2655
+
2656
+ // We don't need to subscribe to userDragDisabled here because updates to
2657
+ // it always come through the `update` lifecycle and will call `updateZone`
2658
+ // anyway.
2659
+
2650
2660
  function consider(e) {
2651
2661
  var _e$detail$info = e.detail.info,
2652
2662
  source = _e$detail$info.source,
@@ -2667,13 +2677,16 @@ function dragHandleZone(node, options) {
2667
2677
  node.addEventListener("finalize", finalize);
2668
2678
  return {
2669
2679
  update: function update(newOptions) {
2680
+ var _currentOptions$dragD, _currentOptions;
2670
2681
  currentOptions = newOptions;
2671
- zone.update(_objectSpread2(_objectSpread2({}, currentOptions), getAddedOptions(isItemsDragDisabled.get())));
2682
+ // keep store in sync with external prop
2683
+ userDragDisabled.set((_currentOptions$dragD = (_currentOptions = currentOptions) === null || _currentOptions === void 0 ? void 0 : _currentOptions.dragDisabled) !== null && _currentOptions$dragD !== void 0 ? _currentOptions$dragD : false);
2684
+ updateZone();
2672
2685
  },
2673
2686
  destroy: function destroy() {
2674
2687
  node.removeEventListener("consider", consider);
2675
2688
  node.removeEventListener("finalize", finalize);
2676
- isItemsDragDisabled.unsubscribe(isItemDisabledCB);
2689
+ isItemsDragDisabled.unsubscribe(updateZone);
2677
2690
  }
2678
2691
  };
2679
2692
  }
@@ -2689,14 +2702,34 @@ function dragHandle(handle) {
2689
2702
  // preventing default to prevent lag on touch devices (because of the browser checking for screen scrolling)
2690
2703
  e.preventDefault();
2691
2704
  isItemsDragDisabled.set(false);
2705
+
2706
+ // Reset the startDrag/isItemsDragDisabled if the user releases the mouse/touch without initiating a drag
2707
+ window.addEventListener("mouseup", resetStartDrag);
2708
+ window.addEventListener("touchend", resetStartDrag);
2692
2709
  }
2693
2710
  function handleKeyDown(e) {
2694
2711
  if (e.key === "Enter" || e.key === " ") isItemsDragDisabled.set(false);
2695
2712
  }
2696
- isItemsDragDisabled.subscribe(function (disabled) {
2697
- handle.tabIndex = disabled ? 0 : -1;
2698
- handle.style.cursor = disabled ? "grab" : "grabbing";
2699
- });
2713
+ function resetStartDrag() {
2714
+ isItemsDragDisabled.set(true);
2715
+ window.removeEventListener("mouseup", resetStartDrag);
2716
+ window.removeEventListener("touchend", resetStartDrag);
2717
+ }
2718
+ var recomputeHandleState = function recomputeHandleState() {
2719
+ var userDisabled = userDragDisabled.get();
2720
+ var internalDisabled = isItemsDragDisabled.get();
2721
+ if (userDisabled) {
2722
+ handle.tabIndex = -1;
2723
+ handle.style.cursor = ""; // default cursor
2724
+ } else {
2725
+ handle.tabIndex = internalDisabled ? 0 : -1;
2726
+ handle.style.cursor = internalDisabled ? "grab" : "grabbing";
2727
+ }
2728
+ };
2729
+
2730
+ // Subscribe to both stores
2731
+ userDragDisabled.subscribe(recomputeHandleState);
2732
+ isItemsDragDisabled.subscribe(recomputeHandleState);
2700
2733
  handle.addEventListener("mousedown", startDrag);
2701
2734
  handle.addEventListener("touchstart", startDrag);
2702
2735
  handle.addEventListener("keydown", handleKeyDown);
@@ -2706,6 +2739,8 @@ function dragHandle(handle) {
2706
2739
  handle.removeEventListener("mousedown", startDrag);
2707
2740
  handle.removeEventListener("touchstart", startDrag);
2708
2741
  handle.removeEventListener("keydown", handleKeyDown);
2742
+ userDragDisabled.unsubscribe(recomputeHandleState);
2743
+ isItemsDragDisabled.unsubscribe(recomputeHandleState);
2709
2744
  }
2710
2745
  };
2711
2746
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "svelte-dnd-action",
3
3
  "description": "*An awesome drag and drop library for Svelte 3 and 4 (not using the browser's built-in dnd, thanks god): Rich animations, nested containers, touch support and more *",
4
- "version": "0.9.60",
4
+ "version": "0.9.62",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/isaacHagoel/svelte-dnd-action.git"
@@ -3,10 +3,11 @@ import {dndzone} from "../action";
3
3
  import {createStore} from "./simpleStore";
4
4
 
5
5
  const isItemsDragDisabled = createStore(true);
6
+ const userDragDisabled = createStore(false);
6
7
 
7
- function getAddedOptions(isItemsDragDisabled = true) {
8
+ function getAddedOptions() {
8
9
  return {
9
- dragDisabled: isItemsDragDisabled,
10
+ dragDisabled: userDragDisabled.get() || isItemsDragDisabled.get(),
10
11
  zoneItemTabIndex: -1
11
12
  };
12
13
  }
@@ -21,18 +22,30 @@ function getAddedOptions(isItemsDragDisabled = true) {
21
22
  * @return {{update: (newOptions: Object) => {}, destroy: () => {}}}
22
23
  */
23
24
  export function dragHandleZone(node, options) {
25
+ // Initialise stores from initial options
26
+ userDragDisabled.set(options?.dragDisabled ?? false);
27
+
24
28
  let currentOptions = options;
29
+
25
30
  const zone = dndzone(node, {
26
31
  ...currentOptions,
27
32
  ...getAddedOptions()
28
33
  });
29
- function isItemDisabledCB(isItemsDragDisabled) {
34
+
35
+ function updateZone() {
30
36
  zone.update({
31
37
  ...currentOptions,
32
- ...getAddedOptions(isItemsDragDisabled)
38
+ ...getAddedOptions()
33
39
  });
34
40
  }
35
- isItemsDragDisabled.subscribe(isItemDisabledCB);
41
+
42
+ // Subscribe to internal store so finishing a drag updates the zone
43
+ isItemsDragDisabled.subscribe(updateZone);
44
+
45
+ // We don't need to subscribe to userDragDisabled here because updates to
46
+ // it always come through the `update` lifecycle and will call `updateZone`
47
+ // anyway.
48
+
36
49
  function consider(e) {
37
50
  const {
38
51
  info: {source, trigger}
@@ -59,15 +72,14 @@ export function dragHandleZone(node, options) {
59
72
  return {
60
73
  update: newOptions => {
61
74
  currentOptions = newOptions;
62
- zone.update({
63
- ...currentOptions,
64
- ...getAddedOptions(isItemsDragDisabled.get())
65
- });
75
+ // keep store in sync with external prop
76
+ userDragDisabled.set(currentOptions?.dragDisabled ?? false);
77
+ updateZone();
66
78
  },
67
79
  destroy: () => {
68
80
  node.removeEventListener("consider", consider);
69
81
  node.removeEventListener("finalize", finalize);
70
- isItemsDragDisabled.unsubscribe(isItemDisabledCB);
82
+ isItemsDragDisabled.unsubscribe(updateZone);
71
83
  }
72
84
  };
73
85
  }
@@ -84,15 +96,38 @@ export function dragHandle(handle) {
84
96
  // preventing default to prevent lag on touch devices (because of the browser checking for screen scrolling)
85
97
  e.preventDefault();
86
98
  isItemsDragDisabled.set(false);
99
+
100
+ // Reset the startDrag/isItemsDragDisabled if the user releases the mouse/touch without initiating a drag
101
+ window.addEventListener("mouseup", resetStartDrag);
102
+ window.addEventListener("touchend", resetStartDrag);
87
103
  }
104
+
88
105
  function handleKeyDown(e) {
89
106
  if (e.key === "Enter" || e.key === " ") isItemsDragDisabled.set(false);
90
107
  }
91
108
 
92
- isItemsDragDisabled.subscribe(disabled => {
93
- handle.tabIndex = disabled ? 0 : -1;
94
- handle.style.cursor = disabled ? "grab" : "grabbing";
95
- });
109
+ function resetStartDrag() {
110
+ isItemsDragDisabled.set(true);
111
+ window.removeEventListener("mouseup", resetStartDrag);
112
+ window.removeEventListener("touchend", resetStartDrag);
113
+ }
114
+
115
+ const recomputeHandleState = () => {
116
+ const userDisabled = userDragDisabled.get();
117
+ const internalDisabled = isItemsDragDisabled.get();
118
+
119
+ if (userDisabled) {
120
+ handle.tabIndex = -1;
121
+ handle.style.cursor = ""; // default cursor
122
+ } else {
123
+ handle.tabIndex = internalDisabled ? 0 : -1;
124
+ handle.style.cursor = internalDisabled ? "grab" : "grabbing";
125
+ }
126
+ };
127
+
128
+ // Subscribe to both stores
129
+ userDragDisabled.subscribe(recomputeHandleState);
130
+ isItemsDragDisabled.subscribe(recomputeHandleState);
96
131
 
97
132
  handle.addEventListener("mousedown", startDrag);
98
133
  handle.addEventListener("touchstart", startDrag);
@@ -103,6 +138,8 @@ export function dragHandle(handle) {
103
138
  handle.removeEventListener("mousedown", startDrag);
104
139
  handle.removeEventListener("touchstart", startDrag);
105
140
  handle.removeEventListener("keydown", handleKeyDown);
141
+ userDragDisabled.unsubscribe(recomputeHandleState);
142
+ isItemsDragDisabled.unsubscribe(recomputeHandleState);
106
143
  }
107
144
  };
108
145
  }