svelte-dnd-action 0.9.14 → 0.9.17
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/README.md +1 -1
- package/dist/index.js +93 -11
- package/dist/index.mjs +93 -11
- package/package.json +1 -1
- package/src/helpers/aria.js +19 -0
- package/src/helpers/styler.js +2 -1
- package/src/helpers/svelteNodeClone.js +35 -0
- package/src/keyboardAction.js +12 -9
- package/src/pointerAction.js +7 -2
package/README.md
CHANGED
|
@@ -206,7 +206,7 @@ If you want to implement your own custom screen-reader alerts, roles and instruc
|
|
|
206
206
|
- The host component must refresh the items that are passed in to the custom-action when receiving consider and finalize events (do not omit any handler).
|
|
207
207
|
- FYI, the library assumes it is okay to add a temporary item to the items list in any of the dnd-zones while an element is dragged around.
|
|
208
208
|
- If you want dragged items to be able to scroll the container, make sure the scroll-container (the element with overflow:scroll) is the dnd-zone (the element decorated with this custom action)
|
|
209
|
-
- Svelte's built-in transitions might not play nice with this library. Luckily, it is an easy issue to work around. There are examples
|
|
209
|
+
- Svelte's built-in transitions might not play nice with this library. Luckily, it is an easy issue to work around. There are examples above.
|
|
210
210
|
|
|
211
211
|
### Overriding the item id key name
|
|
212
212
|
|
package/dist/index.js
CHANGED
|
@@ -1054,6 +1054,54 @@
|
|
|
1054
1054
|
resetScrolling$1();
|
|
1055
1055
|
}
|
|
1056
1056
|
|
|
1057
|
+
/**
|
|
1058
|
+
* Fixes svelte issue when cloning node containing (or being) <select> which will loose it's value.
|
|
1059
|
+
* Since svelte manages select value internally.
|
|
1060
|
+
* @see https://github.com/sveltejs/svelte/issues/6717
|
|
1061
|
+
* @see https://github.com/isaacHagoel/svelte-dnd-action/issues/306
|
|
1062
|
+
*
|
|
1063
|
+
* @param {HTMLElement} el
|
|
1064
|
+
* @returns
|
|
1065
|
+
*/
|
|
1066
|
+
function svelteNodeClone(el) {
|
|
1067
|
+
var cloned = el.cloneNode(true);
|
|
1068
|
+
var values = [];
|
|
1069
|
+
var elIsSelect = el.tagName === "SELECT";
|
|
1070
|
+
var selects = elIsSelect ? [el] : _toConsumableArray(el.querySelectorAll('select'));
|
|
1071
|
+
|
|
1072
|
+
var _iterator = _createForOfIteratorHelper(selects),
|
|
1073
|
+
_step;
|
|
1074
|
+
|
|
1075
|
+
try {
|
|
1076
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1077
|
+
var _select = _step.value;
|
|
1078
|
+
values.push(_select.value);
|
|
1079
|
+
}
|
|
1080
|
+
} catch (err) {
|
|
1081
|
+
_iterator.e(err);
|
|
1082
|
+
} finally {
|
|
1083
|
+
_iterator.f();
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
if (selects.length <= 0) {
|
|
1087
|
+
return cloned;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
var clonedSelects = elIsSelect ? [cloned] : _toConsumableArray(cloned.querySelectorAll('select'));
|
|
1091
|
+
|
|
1092
|
+
for (var i = 0; i < clonedSelects.length; i++) {
|
|
1093
|
+
var select = clonedSelects[i];
|
|
1094
|
+
var value = values[i];
|
|
1095
|
+
var optionEl = select.querySelector("option[value=\"".concat(value, "\""));
|
|
1096
|
+
|
|
1097
|
+
if (optionEl) {
|
|
1098
|
+
optionEl.setAttribute('selected', true);
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
return cloned;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1057
1105
|
var TRANSITION_DURATION_SECONDS = 0.2;
|
|
1058
1106
|
/**
|
|
1059
1107
|
* private helper function - creates a transition string for a property
|
|
@@ -1074,7 +1122,7 @@
|
|
|
1074
1122
|
|
|
1075
1123
|
function createDraggedElementFrom(originalElement, positionCenterOnXY) {
|
|
1076
1124
|
var rect = originalElement.getBoundingClientRect();
|
|
1077
|
-
var draggedEl = originalElement
|
|
1125
|
+
var draggedEl = svelteNodeClone(originalElement);
|
|
1078
1126
|
copyStylesFromTo(originalElement, draggedEl);
|
|
1079
1127
|
draggedEl.id = DRAGGED_ELEMENT_ID;
|
|
1080
1128
|
draggedEl.style.position = "fixed";
|
|
@@ -1649,6 +1697,7 @@
|
|
|
1649
1697
|
}
|
|
1650
1698
|
|
|
1651
1699
|
function dndzone(node, options) {
|
|
1700
|
+
var initialized = false;
|
|
1652
1701
|
var config = {
|
|
1653
1702
|
items: undefined,
|
|
1654
1703
|
type: undefined,
|
|
@@ -1852,7 +1901,7 @@
|
|
|
1852
1901
|
config.transformDraggedElement = transformDraggedElement;
|
|
1853
1902
|
config.centreDraggedOnCursor = centreDraggedOnCursor; // realtime update for dropTargetStyle
|
|
1854
1903
|
|
|
1855
|
-
if (isWorkingOnPreviousDrag && !finalizingPreviousDrag && (!areObjectsShallowEqual(dropTargetStyle, config.dropTargetStyle) || !areArraysShallowEqualSameOrder(dropTargetClasses, config.dropTargetClasses))) {
|
|
1904
|
+
if (initialized && isWorkingOnPreviousDrag && !finalizingPreviousDrag && (!areObjectsShallowEqual(dropTargetStyle, config.dropTargetStyle) || !areArraysShallowEqualSameOrder(dropTargetClasses, config.dropTargetClasses))) {
|
|
1856
1905
|
styleInactiveDropZones([node], function () {
|
|
1857
1906
|
return config.dropTargetStyle;
|
|
1858
1907
|
}, function () {
|
|
@@ -1872,7 +1921,7 @@
|
|
|
1872
1921
|
return dzToConfig.get(dz) ? dzToConfig.get(dz)[propName] : config[propName];
|
|
1873
1922
|
}
|
|
1874
1923
|
|
|
1875
|
-
if (isWorkingOnPreviousDrag && config.dropFromOthersDisabled !== dropFromOthersDisabled) {
|
|
1924
|
+
if (initialized && isWorkingOnPreviousDrag && config.dropFromOthersDisabled !== dropFromOthersDisabled) {
|
|
1876
1925
|
if (dropFromOthersDisabled) {
|
|
1877
1926
|
styleInactiveDropZones([node], function (dz) {
|
|
1878
1927
|
return getConfigProp(dz, "dropTargetStyle");
|
|
@@ -1918,6 +1967,10 @@
|
|
|
1918
1967
|
|
|
1919
1968
|
|
|
1920
1969
|
elToIdx.set(draggableEl, idx);
|
|
1970
|
+
|
|
1971
|
+
if (!initialized) {
|
|
1972
|
+
initialized = true;
|
|
1973
|
+
}
|
|
1921
1974
|
};
|
|
1922
1975
|
|
|
1923
1976
|
for (var idx = 0; idx < node.children.length; idx++) {
|
|
@@ -1955,7 +2008,12 @@
|
|
|
1955
2008
|
var alertsDiv;
|
|
1956
2009
|
|
|
1957
2010
|
function initAriaOnBrowser() {
|
|
1958
|
-
|
|
2011
|
+
if (alertsDiv) {
|
|
2012
|
+
// it is already initialized
|
|
2013
|
+
return;
|
|
2014
|
+
} // setting the dynamic alerts
|
|
2015
|
+
|
|
2016
|
+
|
|
1959
2017
|
alertsDiv = document.createElement("div");
|
|
1960
2018
|
|
|
1961
2019
|
(function initAlertsDiv() {
|
|
@@ -1999,6 +2057,20 @@
|
|
|
1999
2057
|
|
|
2000
2058
|
return _objectSpread2({}, INSTRUCTION_IDs);
|
|
2001
2059
|
}
|
|
2060
|
+
/**
|
|
2061
|
+
* Removes all the artifacts (dom elements) added by this module
|
|
2062
|
+
*/
|
|
2063
|
+
|
|
2064
|
+
function destroyAria() {
|
|
2065
|
+
if (isOnServer || !alertsDiv) return;
|
|
2066
|
+
Object.keys(ID_TO_INSTRUCTION).forEach(function (id) {
|
|
2067
|
+
var _document$getElementB;
|
|
2068
|
+
|
|
2069
|
+
return (_document$getElementB = document.getElementById(id)) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.remove();
|
|
2070
|
+
});
|
|
2071
|
+
alertsDiv.remove();
|
|
2072
|
+
alertsDiv = undefined;
|
|
2073
|
+
}
|
|
2002
2074
|
|
|
2003
2075
|
function instructionToHiddenDiv(id, txt) {
|
|
2004
2076
|
var div = document.createElement("div");
|
|
@@ -2016,6 +2088,12 @@
|
|
|
2016
2088
|
|
|
2017
2089
|
|
|
2018
2090
|
function alertToScreenReader(txt) {
|
|
2091
|
+
if (isOnServer) return;
|
|
2092
|
+
|
|
2093
|
+
if (!alertsDiv) {
|
|
2094
|
+
initAriaOnBrowser();
|
|
2095
|
+
}
|
|
2096
|
+
|
|
2019
2097
|
alertsDiv.innerHTML = "";
|
|
2020
2098
|
var alertText = document.createTextNode(txt);
|
|
2021
2099
|
alertsDiv.appendChild(alertText); // this is needed for Safari
|
|
@@ -2046,7 +2124,7 @@
|
|
|
2046
2124
|
* maybe keep focus on the last dragged item upon drop?
|
|
2047
2125
|
*/
|
|
2048
2126
|
|
|
2049
|
-
var INSTRUCTION_IDs$1
|
|
2127
|
+
var INSTRUCTION_IDs$1;
|
|
2050
2128
|
/* drop-zones registration management */
|
|
2051
2129
|
|
|
2052
2130
|
function registerDropZone$1(dropZoneEl, type) {
|
|
@@ -2058,6 +2136,7 @@
|
|
|
2058
2136
|
printDebug(function () {
|
|
2059
2137
|
return "adding global keydown and click handlers";
|
|
2060
2138
|
});
|
|
2139
|
+
INSTRUCTION_IDs$1 = initAria();
|
|
2061
2140
|
window.addEventListener("keydown", globalKeyDownHandler);
|
|
2062
2141
|
window.addEventListener("click", globalClickHandler);
|
|
2063
2142
|
}
|
|
@@ -2094,6 +2173,8 @@
|
|
|
2094
2173
|
});
|
|
2095
2174
|
window.removeEventListener("keydown", globalKeyDownHandler);
|
|
2096
2175
|
window.removeEventListener("click", globalClickHandler);
|
|
2176
|
+
INSTRUCTION_IDs$1 = undefined;
|
|
2177
|
+
destroyAria();
|
|
2097
2178
|
}
|
|
2098
2179
|
}
|
|
2099
2180
|
|
|
@@ -2411,18 +2492,19 @@
|
|
|
2411
2492
|
config.dropTargetClasses = dropTargetClasses;
|
|
2412
2493
|
config.autoAriaDisabled = autoAriaDisabled;
|
|
2413
2494
|
|
|
2414
|
-
if (!autoAriaDisabled) {
|
|
2415
|
-
node.setAttribute("aria-disabled", dragDisabled);
|
|
2416
|
-
node.setAttribute("role", "list");
|
|
2417
|
-
node.setAttribute("aria-describedby", dragDisabled ? INSTRUCTION_IDs$1.DND_ZONE_DRAG_DISABLED : INSTRUCTION_IDs$1.DND_ZONE_ACTIVE);
|
|
2418
|
-
}
|
|
2419
|
-
|
|
2420
2495
|
if (config.type && newType !== config.type) {
|
|
2421
2496
|
unregisterDropZone$1(node, config.type);
|
|
2422
2497
|
}
|
|
2423
2498
|
|
|
2424
2499
|
config.type = newType;
|
|
2425
2500
|
registerDropZone$1(node, newType);
|
|
2501
|
+
|
|
2502
|
+
if (!autoAriaDisabled) {
|
|
2503
|
+
node.setAttribute("aria-disabled", dragDisabled);
|
|
2504
|
+
node.setAttribute("role", "list");
|
|
2505
|
+
node.setAttribute("aria-describedby", dragDisabled ? INSTRUCTION_IDs$1.DND_ZONE_DRAG_DISABLED : INSTRUCTION_IDs$1.DND_ZONE_ACTIVE);
|
|
2506
|
+
}
|
|
2507
|
+
|
|
2426
2508
|
dzToConfig$1.set(node, config);
|
|
2427
2509
|
|
|
2428
2510
|
if (isDragging) {
|
package/dist/index.mjs
CHANGED
|
@@ -1048,6 +1048,54 @@ function disarmWindowScroller() {
|
|
|
1048
1048
|
resetScrolling$1();
|
|
1049
1049
|
}
|
|
1050
1050
|
|
|
1051
|
+
/**
|
|
1052
|
+
* Fixes svelte issue when cloning node containing (or being) <select> which will loose it's value.
|
|
1053
|
+
* Since svelte manages select value internally.
|
|
1054
|
+
* @see https://github.com/sveltejs/svelte/issues/6717
|
|
1055
|
+
* @see https://github.com/isaacHagoel/svelte-dnd-action/issues/306
|
|
1056
|
+
*
|
|
1057
|
+
* @param {HTMLElement} el
|
|
1058
|
+
* @returns
|
|
1059
|
+
*/
|
|
1060
|
+
function svelteNodeClone(el) {
|
|
1061
|
+
var cloned = el.cloneNode(true);
|
|
1062
|
+
var values = [];
|
|
1063
|
+
var elIsSelect = el.tagName === "SELECT";
|
|
1064
|
+
var selects = elIsSelect ? [el] : _toConsumableArray(el.querySelectorAll('select'));
|
|
1065
|
+
|
|
1066
|
+
var _iterator = _createForOfIteratorHelper(selects),
|
|
1067
|
+
_step;
|
|
1068
|
+
|
|
1069
|
+
try {
|
|
1070
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1071
|
+
var _select = _step.value;
|
|
1072
|
+
values.push(_select.value);
|
|
1073
|
+
}
|
|
1074
|
+
} catch (err) {
|
|
1075
|
+
_iterator.e(err);
|
|
1076
|
+
} finally {
|
|
1077
|
+
_iterator.f();
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
if (selects.length <= 0) {
|
|
1081
|
+
return cloned;
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
var clonedSelects = elIsSelect ? [cloned] : _toConsumableArray(cloned.querySelectorAll('select'));
|
|
1085
|
+
|
|
1086
|
+
for (var i = 0; i < clonedSelects.length; i++) {
|
|
1087
|
+
var select = clonedSelects[i];
|
|
1088
|
+
var value = values[i];
|
|
1089
|
+
var optionEl = select.querySelector("option[value=\"".concat(value, "\""));
|
|
1090
|
+
|
|
1091
|
+
if (optionEl) {
|
|
1092
|
+
optionEl.setAttribute('selected', true);
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
return cloned;
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1051
1099
|
var TRANSITION_DURATION_SECONDS = 0.2;
|
|
1052
1100
|
/**
|
|
1053
1101
|
* private helper function - creates a transition string for a property
|
|
@@ -1068,7 +1116,7 @@ function trs(property) {
|
|
|
1068
1116
|
|
|
1069
1117
|
function createDraggedElementFrom(originalElement, positionCenterOnXY) {
|
|
1070
1118
|
var rect = originalElement.getBoundingClientRect();
|
|
1071
|
-
var draggedEl = originalElement
|
|
1119
|
+
var draggedEl = svelteNodeClone(originalElement);
|
|
1072
1120
|
copyStylesFromTo(originalElement, draggedEl);
|
|
1073
1121
|
draggedEl.id = DRAGGED_ELEMENT_ID;
|
|
1074
1122
|
draggedEl.style.position = "fixed";
|
|
@@ -1643,6 +1691,7 @@ function cleanupPostDrop() {
|
|
|
1643
1691
|
}
|
|
1644
1692
|
|
|
1645
1693
|
function dndzone(node, options) {
|
|
1694
|
+
var initialized = false;
|
|
1646
1695
|
var config = {
|
|
1647
1696
|
items: undefined,
|
|
1648
1697
|
type: undefined,
|
|
@@ -1846,7 +1895,7 @@ function dndzone(node, options) {
|
|
|
1846
1895
|
config.transformDraggedElement = transformDraggedElement;
|
|
1847
1896
|
config.centreDraggedOnCursor = centreDraggedOnCursor; // realtime update for dropTargetStyle
|
|
1848
1897
|
|
|
1849
|
-
if (isWorkingOnPreviousDrag && !finalizingPreviousDrag && (!areObjectsShallowEqual(dropTargetStyle, config.dropTargetStyle) || !areArraysShallowEqualSameOrder(dropTargetClasses, config.dropTargetClasses))) {
|
|
1898
|
+
if (initialized && isWorkingOnPreviousDrag && !finalizingPreviousDrag && (!areObjectsShallowEqual(dropTargetStyle, config.dropTargetStyle) || !areArraysShallowEqualSameOrder(dropTargetClasses, config.dropTargetClasses))) {
|
|
1850
1899
|
styleInactiveDropZones([node], function () {
|
|
1851
1900
|
return config.dropTargetStyle;
|
|
1852
1901
|
}, function () {
|
|
@@ -1866,7 +1915,7 @@ function dndzone(node, options) {
|
|
|
1866
1915
|
return dzToConfig.get(dz) ? dzToConfig.get(dz)[propName] : config[propName];
|
|
1867
1916
|
}
|
|
1868
1917
|
|
|
1869
|
-
if (isWorkingOnPreviousDrag && config.dropFromOthersDisabled !== dropFromOthersDisabled) {
|
|
1918
|
+
if (initialized && isWorkingOnPreviousDrag && config.dropFromOthersDisabled !== dropFromOthersDisabled) {
|
|
1870
1919
|
if (dropFromOthersDisabled) {
|
|
1871
1920
|
styleInactiveDropZones([node], function (dz) {
|
|
1872
1921
|
return getConfigProp(dz, "dropTargetStyle");
|
|
@@ -1912,6 +1961,10 @@ function dndzone(node, options) {
|
|
|
1912
1961
|
|
|
1913
1962
|
|
|
1914
1963
|
elToIdx.set(draggableEl, idx);
|
|
1964
|
+
|
|
1965
|
+
if (!initialized) {
|
|
1966
|
+
initialized = true;
|
|
1967
|
+
}
|
|
1915
1968
|
};
|
|
1916
1969
|
|
|
1917
1970
|
for (var idx = 0; idx < node.children.length; idx++) {
|
|
@@ -1949,7 +2002,12 @@ var ALERT_DIV_ID = "dnd-action-aria-alert";
|
|
|
1949
2002
|
var alertsDiv;
|
|
1950
2003
|
|
|
1951
2004
|
function initAriaOnBrowser() {
|
|
1952
|
-
|
|
2005
|
+
if (alertsDiv) {
|
|
2006
|
+
// it is already initialized
|
|
2007
|
+
return;
|
|
2008
|
+
} // setting the dynamic alerts
|
|
2009
|
+
|
|
2010
|
+
|
|
1953
2011
|
alertsDiv = document.createElement("div");
|
|
1954
2012
|
|
|
1955
2013
|
(function initAlertsDiv() {
|
|
@@ -1993,6 +2051,20 @@ function initAria() {
|
|
|
1993
2051
|
|
|
1994
2052
|
return _objectSpread2({}, INSTRUCTION_IDs);
|
|
1995
2053
|
}
|
|
2054
|
+
/**
|
|
2055
|
+
* Removes all the artifacts (dom elements) added by this module
|
|
2056
|
+
*/
|
|
2057
|
+
|
|
2058
|
+
function destroyAria() {
|
|
2059
|
+
if (isOnServer || !alertsDiv) return;
|
|
2060
|
+
Object.keys(ID_TO_INSTRUCTION).forEach(function (id) {
|
|
2061
|
+
var _document$getElementB;
|
|
2062
|
+
|
|
2063
|
+
return (_document$getElementB = document.getElementById(id)) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.remove();
|
|
2064
|
+
});
|
|
2065
|
+
alertsDiv.remove();
|
|
2066
|
+
alertsDiv = undefined;
|
|
2067
|
+
}
|
|
1996
2068
|
|
|
1997
2069
|
function instructionToHiddenDiv(id, txt) {
|
|
1998
2070
|
var div = document.createElement("div");
|
|
@@ -2010,6 +2082,12 @@ function instructionToHiddenDiv(id, txt) {
|
|
|
2010
2082
|
|
|
2011
2083
|
|
|
2012
2084
|
function alertToScreenReader(txt) {
|
|
2085
|
+
if (isOnServer) return;
|
|
2086
|
+
|
|
2087
|
+
if (!alertsDiv) {
|
|
2088
|
+
initAriaOnBrowser();
|
|
2089
|
+
}
|
|
2090
|
+
|
|
2013
2091
|
alertsDiv.innerHTML = "";
|
|
2014
2092
|
var alertText = document.createTextNode(txt);
|
|
2015
2093
|
alertsDiv.appendChild(alertText); // this is needed for Safari
|
|
@@ -2040,7 +2118,7 @@ var typeToDropZones$1 = new Map();
|
|
|
2040
2118
|
* maybe keep focus on the last dragged item upon drop?
|
|
2041
2119
|
*/
|
|
2042
2120
|
|
|
2043
|
-
var INSTRUCTION_IDs$1
|
|
2121
|
+
var INSTRUCTION_IDs$1;
|
|
2044
2122
|
/* drop-zones registration management */
|
|
2045
2123
|
|
|
2046
2124
|
function registerDropZone$1(dropZoneEl, type) {
|
|
@@ -2052,6 +2130,7 @@ function registerDropZone$1(dropZoneEl, type) {
|
|
|
2052
2130
|
printDebug(function () {
|
|
2053
2131
|
return "adding global keydown and click handlers";
|
|
2054
2132
|
});
|
|
2133
|
+
INSTRUCTION_IDs$1 = initAria();
|
|
2055
2134
|
window.addEventListener("keydown", globalKeyDownHandler);
|
|
2056
2135
|
window.addEventListener("click", globalClickHandler);
|
|
2057
2136
|
}
|
|
@@ -2088,6 +2167,8 @@ function unregisterDropZone$1(dropZoneEl, type) {
|
|
|
2088
2167
|
});
|
|
2089
2168
|
window.removeEventListener("keydown", globalKeyDownHandler);
|
|
2090
2169
|
window.removeEventListener("click", globalClickHandler);
|
|
2170
|
+
INSTRUCTION_IDs$1 = undefined;
|
|
2171
|
+
destroyAria();
|
|
2091
2172
|
}
|
|
2092
2173
|
}
|
|
2093
2174
|
|
|
@@ -2405,18 +2486,19 @@ function dndzone$1(node, options) {
|
|
|
2405
2486
|
config.dropTargetClasses = dropTargetClasses;
|
|
2406
2487
|
config.autoAriaDisabled = autoAriaDisabled;
|
|
2407
2488
|
|
|
2408
|
-
if (!autoAriaDisabled) {
|
|
2409
|
-
node.setAttribute("aria-disabled", dragDisabled);
|
|
2410
|
-
node.setAttribute("role", "list");
|
|
2411
|
-
node.setAttribute("aria-describedby", dragDisabled ? INSTRUCTION_IDs$1.DND_ZONE_DRAG_DISABLED : INSTRUCTION_IDs$1.DND_ZONE_ACTIVE);
|
|
2412
|
-
}
|
|
2413
|
-
|
|
2414
2489
|
if (config.type && newType !== config.type) {
|
|
2415
2490
|
unregisterDropZone$1(node, config.type);
|
|
2416
2491
|
}
|
|
2417
2492
|
|
|
2418
2493
|
config.type = newType;
|
|
2419
2494
|
registerDropZone$1(node, newType);
|
|
2495
|
+
|
|
2496
|
+
if (!autoAriaDisabled) {
|
|
2497
|
+
node.setAttribute("aria-disabled", dragDisabled);
|
|
2498
|
+
node.setAttribute("role", "list");
|
|
2499
|
+
node.setAttribute("aria-describedby", dragDisabled ? INSTRUCTION_IDs$1.DND_ZONE_DRAG_DISABLED : INSTRUCTION_IDs$1.DND_ZONE_ACTIVE);
|
|
2500
|
+
}
|
|
2501
|
+
|
|
2420
2502
|
dzToConfig$1.set(node, config);
|
|
2421
2503
|
|
|
2422
2504
|
if (isDragging) {
|
package/package.json
CHANGED
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"dist"
|
|
41
41
|
],
|
|
42
42
|
"description": "*An awesome drag and drop library for Svelte 3 (not using the browser's built-in dnd, thanks god): Rich animations, nested containers, touch support and more *",
|
|
43
|
-
"version": "0.9.
|
|
43
|
+
"version": "0.9.17",
|
|
44
44
|
"repository": {
|
|
45
45
|
"type": "git",
|
|
46
46
|
"url": "git+https://github.com/isaacHagoel/svelte-dnd-action.git"
|
package/src/helpers/aria.js
CHANGED
|
@@ -13,6 +13,10 @@ const ALERT_DIV_ID = "dnd-action-aria-alert";
|
|
|
13
13
|
let alertsDiv;
|
|
14
14
|
|
|
15
15
|
function initAriaOnBrowser() {
|
|
16
|
+
if (alertsDiv) {
|
|
17
|
+
// it is already initialized
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
16
20
|
// setting the dynamic alerts
|
|
17
21
|
alertsDiv = document.createElement("div");
|
|
18
22
|
(function initAlertsDiv() {
|
|
@@ -47,6 +51,17 @@ export function initAria() {
|
|
|
47
51
|
}
|
|
48
52
|
return {...INSTRUCTION_IDs};
|
|
49
53
|
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Removes all the artifacts (dom elements) added by this module
|
|
57
|
+
*/
|
|
58
|
+
export function destroyAria() {
|
|
59
|
+
if (isOnServer || !alertsDiv) return;
|
|
60
|
+
Object.keys(ID_TO_INSTRUCTION).forEach(id => document.getElementById(id)?.remove());
|
|
61
|
+
alertsDiv.remove();
|
|
62
|
+
alertsDiv = undefined;
|
|
63
|
+
}
|
|
64
|
+
|
|
50
65
|
function instructionToHiddenDiv(id, txt) {
|
|
51
66
|
const div = document.createElement("div");
|
|
52
67
|
div.id = id;
|
|
@@ -62,6 +77,10 @@ function instructionToHiddenDiv(id, txt) {
|
|
|
62
77
|
* @param {string} txt
|
|
63
78
|
*/
|
|
64
79
|
export function alertToScreenReader(txt) {
|
|
80
|
+
if (isOnServer) return;
|
|
81
|
+
if (!alertsDiv) {
|
|
82
|
+
initAriaOnBrowser();
|
|
83
|
+
}
|
|
65
84
|
alertsDiv.innerHTML = "";
|
|
66
85
|
const alertText = document.createTextNode(txt);
|
|
67
86
|
alertsDiv.appendChild(alertText);
|
package/src/helpers/styler.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {SHADOW_ELEMENT_ATTRIBUTE_NAME, DRAGGED_ELEMENT_ID} from "../constants";
|
|
2
2
|
import {findCenter} from "./intersection";
|
|
3
|
+
import { svelteNodeClone } from "./svelteNodeClone";
|
|
3
4
|
|
|
4
5
|
const TRANSITION_DURATION_SECONDS = 0.2;
|
|
5
6
|
|
|
@@ -19,7 +20,7 @@ function trs(property) {
|
|
|
19
20
|
*/
|
|
20
21
|
export function createDraggedElementFrom(originalElement, positionCenterOnXY) {
|
|
21
22
|
const rect = originalElement.getBoundingClientRect();
|
|
22
|
-
const draggedEl = originalElement
|
|
23
|
+
const draggedEl = svelteNodeClone(originalElement);
|
|
23
24
|
copyStylesFromTo(originalElement, draggedEl);
|
|
24
25
|
draggedEl.id = DRAGGED_ELEMENT_ID;
|
|
25
26
|
draggedEl.style.position = "fixed";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixes svelte issue when cloning node containing (or being) <select> which will loose it's value.
|
|
3
|
+
* Since svelte manages select value internally.
|
|
4
|
+
* @see https://github.com/sveltejs/svelte/issues/6717
|
|
5
|
+
* @see https://github.com/isaacHagoel/svelte-dnd-action/issues/306
|
|
6
|
+
*
|
|
7
|
+
* @param {HTMLElement} el
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export function svelteNodeClone(el) {
|
|
11
|
+
const cloned = el.cloneNode(true);
|
|
12
|
+
|
|
13
|
+
const values = [];
|
|
14
|
+
const elIsSelect = el.tagName === "SELECT";
|
|
15
|
+
const selects = elIsSelect ? [el] : [...el.querySelectorAll('select')];
|
|
16
|
+
for (const select of selects) {
|
|
17
|
+
values.push(select.value);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (selects.length <= 0) {
|
|
21
|
+
return cloned;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const clonedSelects = elIsSelect ? [cloned] : [...cloned.querySelectorAll('select')];
|
|
25
|
+
for (let i = 0; i < clonedSelects.length; i++) {
|
|
26
|
+
const select = clonedSelects[i];
|
|
27
|
+
const value = values[i];
|
|
28
|
+
const optionEl = select.querySelector(`option[value="${value}"`);
|
|
29
|
+
if (optionEl) {
|
|
30
|
+
optionEl.setAttribute('selected', true);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return cloned;
|
|
35
|
+
}
|
package/src/keyboardAction.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {decrementActiveDropZoneCount, incrementActiveDropZoneCount, ITEM_ID_KEY, SOURCES, TRIGGERS} from "./constants";
|
|
2
2
|
import {styleActiveDropZones, styleInactiveDropZones} from "./helpers/styler";
|
|
3
3
|
import {dispatchConsiderEvent, dispatchFinalizeEvent} from "./helpers/dispatcher";
|
|
4
|
-
import {initAria, alertToScreenReader} from "./helpers/aria";
|
|
4
|
+
import {initAria, alertToScreenReader, destroyAria} from "./helpers/aria";
|
|
5
5
|
import {toString} from "./helpers/util";
|
|
6
6
|
import {printDebug} from "./constants";
|
|
7
7
|
|
|
@@ -29,13 +29,14 @@ const typeToDropZones = new Map();
|
|
|
29
29
|
* maybe keep focus on the last dragged item upon drop?
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
let INSTRUCTION_IDs;
|
|
33
33
|
|
|
34
34
|
/* drop-zones registration management */
|
|
35
35
|
function registerDropZone(dropZoneEl, type) {
|
|
36
36
|
printDebug(() => "registering drop-zone if absent");
|
|
37
37
|
if (typeToDropZones.size === 0) {
|
|
38
38
|
printDebug(() => "adding global keydown and click handlers");
|
|
39
|
+
INSTRUCTION_IDs = initAria();
|
|
39
40
|
window.addEventListener("keydown", globalKeyDownHandler);
|
|
40
41
|
window.addEventListener("click", globalClickHandler);
|
|
41
42
|
}
|
|
@@ -61,6 +62,8 @@ function unregisterDropZone(dropZoneEl, type) {
|
|
|
61
62
|
printDebug(() => "removing global keydown and click handlers");
|
|
62
63
|
window.removeEventListener("keydown", globalKeyDownHandler);
|
|
63
64
|
window.removeEventListener("click", globalClickHandler);
|
|
65
|
+
INSTRUCTION_IDs = undefined;
|
|
66
|
+
destroyAria();
|
|
64
67
|
}
|
|
65
68
|
}
|
|
66
69
|
|
|
@@ -280,16 +283,16 @@ export function dndzone(node, options) {
|
|
|
280
283
|
config.dropTargetStyle = dropTargetStyle;
|
|
281
284
|
config.dropTargetClasses = dropTargetClasses;
|
|
282
285
|
config.autoAriaDisabled = autoAriaDisabled;
|
|
283
|
-
if (!autoAriaDisabled) {
|
|
284
|
-
node.setAttribute("aria-disabled", dragDisabled);
|
|
285
|
-
node.setAttribute("role", "list");
|
|
286
|
-
node.setAttribute("aria-describedby", dragDisabled ? INSTRUCTION_IDs.DND_ZONE_DRAG_DISABLED : INSTRUCTION_IDs.DND_ZONE_ACTIVE);
|
|
287
|
-
}
|
|
288
286
|
if (config.type && newType !== config.type) {
|
|
289
287
|
unregisterDropZone(node, config.type);
|
|
290
288
|
}
|
|
291
289
|
config.type = newType;
|
|
292
290
|
registerDropZone(node, newType);
|
|
291
|
+
if (!autoAriaDisabled) {
|
|
292
|
+
node.setAttribute("aria-disabled", dragDisabled);
|
|
293
|
+
node.setAttribute("role", "list");
|
|
294
|
+
node.setAttribute("aria-describedby", dragDisabled ? INSTRUCTION_IDs.DND_ZONE_DRAG_DISABLED : INSTRUCTION_IDs.DND_ZONE_ACTIVE);
|
|
295
|
+
}
|
|
293
296
|
dzToConfig.set(node, config);
|
|
294
297
|
|
|
295
298
|
if (isDragging) {
|
|
@@ -298,8 +301,8 @@ export function dndzone(node, options) {
|
|
|
298
301
|
focusedItem.contains(node) ||
|
|
299
302
|
config.dropFromOthersDisabled ||
|
|
300
303
|
(focusedDz && config.type !== dzToConfig.get(focusedDz).type)
|
|
301
|
-
|
|
302
|
-
|
|
304
|
+
? -1
|
|
305
|
+
: 0;
|
|
303
306
|
} else {
|
|
304
307
|
node.tabIndex = config.zoneTabIndex;
|
|
305
308
|
}
|
package/src/pointerAction.js
CHANGED
|
@@ -301,6 +301,7 @@ function cleanupPostDrop() {
|
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
export function dndzone(node, options) {
|
|
304
|
+
let initialized = false;
|
|
304
305
|
const config = {
|
|
305
306
|
items: undefined,
|
|
306
307
|
type: undefined,
|
|
@@ -442,7 +443,6 @@ export function dndzone(node, options) {
|
|
|
442
443
|
}
|
|
443
444
|
config.type = newType;
|
|
444
445
|
registerDropZone(node, newType);
|
|
445
|
-
|
|
446
446
|
config.items = [...items];
|
|
447
447
|
config.dragDisabled = dragDisabled;
|
|
448
448
|
config.morphDisabled = morphDisabled;
|
|
@@ -451,6 +451,7 @@ export function dndzone(node, options) {
|
|
|
451
451
|
|
|
452
452
|
// realtime update for dropTargetStyle
|
|
453
453
|
if (
|
|
454
|
+
initialized &&
|
|
454
455
|
isWorkingOnPreviousDrag &&
|
|
455
456
|
!finalizingPreviousDrag &&
|
|
456
457
|
(!areObjectsShallowEqual(dropTargetStyle, config.dropTargetStyle) ||
|
|
@@ -474,7 +475,7 @@ export function dndzone(node, options) {
|
|
|
474
475
|
function getConfigProp(dz, propName) {
|
|
475
476
|
return dzToConfig.get(dz) ? dzToConfig.get(dz)[propName] : config[propName];
|
|
476
477
|
}
|
|
477
|
-
if (isWorkingOnPreviousDrag && config.dropFromOthersDisabled !== dropFromOthersDisabled) {
|
|
478
|
+
if (initialized && isWorkingOnPreviousDrag && config.dropFromOthersDisabled !== dropFromOthersDisabled) {
|
|
478
479
|
if (dropFromOthersDisabled) {
|
|
479
480
|
styleInactiveDropZones(
|
|
480
481
|
[node],
|
|
@@ -514,6 +515,10 @@ export function dndzone(node, options) {
|
|
|
514
515
|
}
|
|
515
516
|
// updating the idx
|
|
516
517
|
elToIdx.set(draggableEl, idx);
|
|
518
|
+
|
|
519
|
+
if (!initialized) {
|
|
520
|
+
initialized = true;
|
|
521
|
+
}
|
|
517
522
|
}
|
|
518
523
|
}
|
|
519
524
|
configure(options);
|