svelte-dnd-action 0.9.61 → 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
  }
@@ -2708,10 +2721,21 @@
2708
2721
  window.removeEventListener("mouseup", resetStartDrag);
2709
2722
  window.removeEventListener("touchend", resetStartDrag);
2710
2723
  }
2711
- isItemsDragDisabled.subscribe(function (disabled) {
2712
- handle.tabIndex = disabled ? 0 : -1;
2713
- handle.style.cursor = disabled ? "grab" : "grabbing";
2714
- });
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);
2715
2739
  handle.addEventListener("mousedown", startDrag);
2716
2740
  handle.addEventListener("touchstart", startDrag);
2717
2741
  handle.addEventListener("keydown", handleKeyDown);
@@ -2721,6 +2745,8 @@
2721
2745
  handle.removeEventListener("mousedown", startDrag);
2722
2746
  handle.removeEventListener("touchstart", startDrag);
2723
2747
  handle.removeEventListener("keydown", handleKeyDown);
2748
+ userDragDisabled.unsubscribe(recomputeHandleState);
2749
+ isItemsDragDisabled.unsubscribe(recomputeHandleState);
2724
2750
  }
2725
2751
  };
2726
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
  }
@@ -2702,10 +2715,21 @@ function dragHandle(handle) {
2702
2715
  window.removeEventListener("mouseup", resetStartDrag);
2703
2716
  window.removeEventListener("touchend", resetStartDrag);
2704
2717
  }
2705
- isItemsDragDisabled.subscribe(function (disabled) {
2706
- handle.tabIndex = disabled ? 0 : -1;
2707
- handle.style.cursor = disabled ? "grab" : "grabbing";
2708
- });
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);
2709
2733
  handle.addEventListener("mousedown", startDrag);
2710
2734
  handle.addEventListener("touchstart", startDrag);
2711
2735
  handle.addEventListener("keydown", handleKeyDown);
@@ -2715,6 +2739,8 @@ function dragHandle(handle) {
2715
2739
  handle.removeEventListener("mousedown", startDrag);
2716
2740
  handle.removeEventListener("touchstart", startDrag);
2717
2741
  handle.removeEventListener("keydown", handleKeyDown);
2742
+ userDragDisabled.unsubscribe(recomputeHandleState);
2743
+ isItemsDragDisabled.unsubscribe(recomputeHandleState);
2718
2744
  }
2719
2745
  };
2720
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.61",
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
  }
@@ -100,10 +112,22 @@ export function dragHandle(handle) {
100
112
  window.removeEventListener("touchend", resetStartDrag);
101
113
  }
102
114
 
103
- isItemsDragDisabled.subscribe(disabled => {
104
- handle.tabIndex = disabled ? 0 : -1;
105
- handle.style.cursor = disabled ? "grab" : "grabbing";
106
- });
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);
107
131
 
108
132
  handle.addEventListener("mousedown", startDrag);
109
133
  handle.addEventListener("touchstart", startDrag);
@@ -114,6 +138,8 @@ export function dragHandle(handle) {
114
138
  handle.removeEventListener("mousedown", startDrag);
115
139
  handle.removeEventListener("touchstart", startDrag);
116
140
  handle.removeEventListener("keydown", handleKeyDown);
141
+ userDragDisabled.unsubscribe(recomputeHandleState);
142
+ isItemsDragDisabled.unsubscribe(recomputeHandleState);
117
143
  }
118
144
  };
119
145
  }