svelte-dnd-action 0.9.13 → 0.9.16
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 +58 -11
- package/dist/index.mjs +58 -11
- package/package.json +1 -1
- package/src/helpers/aria.js +19 -0
- package/src/helpers/listUtil.js +9 -0
- package/src/helpers/observer.js +2 -1
- package/src/helpers/windowScroller.js +3 -1
- 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
|
@@ -599,6 +599,17 @@
|
|
|
599
599
|
dzToShadowIndexToRect = new Map();
|
|
600
600
|
}
|
|
601
601
|
resetIndexesCache();
|
|
602
|
+
/**
|
|
603
|
+
* Resets the cache that allows for smarter "would be index" resolution for a specific dropzone, should be called after the zone was scrolled
|
|
604
|
+
* @param {HTMLElement} dz
|
|
605
|
+
*/
|
|
606
|
+
|
|
607
|
+
function resetIndexesCacheForDz(dz) {
|
|
608
|
+
printDebug(function () {
|
|
609
|
+
return "resetting indexes cache for dz";
|
|
610
|
+
});
|
|
611
|
+
dzToShadowIndexToRect["delete"](dz);
|
|
612
|
+
}
|
|
602
613
|
/**
|
|
603
614
|
* Caches the coordinates of the shadow element when it's in a certain index in a certain dropzone.
|
|
604
615
|
* Helpful in order to determine "would be index" more effectively
|
|
@@ -931,6 +942,7 @@
|
|
|
931
942
|
try {
|
|
932
943
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
933
944
|
var dz = _step.value;
|
|
945
|
+
if (scrolled) resetIndexesCacheForDz(lastDropZoneFound);
|
|
934
946
|
var indexObj = findWouldBeIndex(draggedEl, dz);
|
|
935
947
|
|
|
936
948
|
if (indexObj === null) {
|
|
@@ -1008,7 +1020,8 @@
|
|
|
1008
1020
|
|
|
1009
1021
|
function loop() {
|
|
1010
1022
|
if (mousePosition) {
|
|
1011
|
-
scrollIfNeeded$1(mousePosition, document.documentElement);
|
|
1023
|
+
var scrolled = scrollIfNeeded$1(mousePosition, document.documentElement);
|
|
1024
|
+
if (scrolled) resetIndexesCache();
|
|
1012
1025
|
}
|
|
1013
1026
|
|
|
1014
1027
|
next$1 = window.setTimeout(loop, INTERVAL_MS$1);
|
|
@@ -1636,6 +1649,7 @@
|
|
|
1636
1649
|
}
|
|
1637
1650
|
|
|
1638
1651
|
function dndzone(node, options) {
|
|
1652
|
+
var initialized = false;
|
|
1639
1653
|
var config = {
|
|
1640
1654
|
items: undefined,
|
|
1641
1655
|
type: undefined,
|
|
@@ -1839,7 +1853,7 @@
|
|
|
1839
1853
|
config.transformDraggedElement = transformDraggedElement;
|
|
1840
1854
|
config.centreDraggedOnCursor = centreDraggedOnCursor; // realtime update for dropTargetStyle
|
|
1841
1855
|
|
|
1842
|
-
if (isWorkingOnPreviousDrag && !finalizingPreviousDrag && (!areObjectsShallowEqual(dropTargetStyle, config.dropTargetStyle) || !areArraysShallowEqualSameOrder(dropTargetClasses, config.dropTargetClasses))) {
|
|
1856
|
+
if (initialized && isWorkingOnPreviousDrag && !finalizingPreviousDrag && (!areObjectsShallowEqual(dropTargetStyle, config.dropTargetStyle) || !areArraysShallowEqualSameOrder(dropTargetClasses, config.dropTargetClasses))) {
|
|
1843
1857
|
styleInactiveDropZones([node], function () {
|
|
1844
1858
|
return config.dropTargetStyle;
|
|
1845
1859
|
}, function () {
|
|
@@ -1859,7 +1873,7 @@
|
|
|
1859
1873
|
return dzToConfig.get(dz) ? dzToConfig.get(dz)[propName] : config[propName];
|
|
1860
1874
|
}
|
|
1861
1875
|
|
|
1862
|
-
if (isWorkingOnPreviousDrag && config.dropFromOthersDisabled !== dropFromOthersDisabled) {
|
|
1876
|
+
if (initialized && isWorkingOnPreviousDrag && config.dropFromOthersDisabled !== dropFromOthersDisabled) {
|
|
1863
1877
|
if (dropFromOthersDisabled) {
|
|
1864
1878
|
styleInactiveDropZones([node], function (dz) {
|
|
1865
1879
|
return getConfigProp(dz, "dropTargetStyle");
|
|
@@ -1905,6 +1919,10 @@
|
|
|
1905
1919
|
|
|
1906
1920
|
|
|
1907
1921
|
elToIdx.set(draggableEl, idx);
|
|
1922
|
+
|
|
1923
|
+
if (!initialized) {
|
|
1924
|
+
initialized = true;
|
|
1925
|
+
}
|
|
1908
1926
|
};
|
|
1909
1927
|
|
|
1910
1928
|
for (var idx = 0; idx < node.children.length; idx++) {
|
|
@@ -1942,7 +1960,12 @@
|
|
|
1942
1960
|
var alertsDiv;
|
|
1943
1961
|
|
|
1944
1962
|
function initAriaOnBrowser() {
|
|
1945
|
-
|
|
1963
|
+
if (alertsDiv) {
|
|
1964
|
+
// it is already initialized
|
|
1965
|
+
return;
|
|
1966
|
+
} // setting the dynamic alerts
|
|
1967
|
+
|
|
1968
|
+
|
|
1946
1969
|
alertsDiv = document.createElement("div");
|
|
1947
1970
|
|
|
1948
1971
|
(function initAlertsDiv() {
|
|
@@ -1986,6 +2009,20 @@
|
|
|
1986
2009
|
|
|
1987
2010
|
return _objectSpread2({}, INSTRUCTION_IDs);
|
|
1988
2011
|
}
|
|
2012
|
+
/**
|
|
2013
|
+
* Removes all the artifacts (dom elements) added by this module
|
|
2014
|
+
*/
|
|
2015
|
+
|
|
2016
|
+
function destroyAria() {
|
|
2017
|
+
if (isOnServer || !alertsDiv) return;
|
|
2018
|
+
Object.keys(ID_TO_INSTRUCTION).forEach(function (id) {
|
|
2019
|
+
var _document$getElementB;
|
|
2020
|
+
|
|
2021
|
+
return (_document$getElementB = document.getElementById(id)) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.remove();
|
|
2022
|
+
});
|
|
2023
|
+
alertsDiv.remove();
|
|
2024
|
+
alertsDiv = undefined;
|
|
2025
|
+
}
|
|
1989
2026
|
|
|
1990
2027
|
function instructionToHiddenDiv(id, txt) {
|
|
1991
2028
|
var div = document.createElement("div");
|
|
@@ -2003,6 +2040,12 @@
|
|
|
2003
2040
|
|
|
2004
2041
|
|
|
2005
2042
|
function alertToScreenReader(txt) {
|
|
2043
|
+
if (isOnServer) return;
|
|
2044
|
+
|
|
2045
|
+
if (!alertsDiv) {
|
|
2046
|
+
initAriaOnBrowser();
|
|
2047
|
+
}
|
|
2048
|
+
|
|
2006
2049
|
alertsDiv.innerHTML = "";
|
|
2007
2050
|
var alertText = document.createTextNode(txt);
|
|
2008
2051
|
alertsDiv.appendChild(alertText); // this is needed for Safari
|
|
@@ -2033,7 +2076,7 @@
|
|
|
2033
2076
|
* maybe keep focus on the last dragged item upon drop?
|
|
2034
2077
|
*/
|
|
2035
2078
|
|
|
2036
|
-
var INSTRUCTION_IDs$1
|
|
2079
|
+
var INSTRUCTION_IDs$1;
|
|
2037
2080
|
/* drop-zones registration management */
|
|
2038
2081
|
|
|
2039
2082
|
function registerDropZone$1(dropZoneEl, type) {
|
|
@@ -2045,6 +2088,7 @@
|
|
|
2045
2088
|
printDebug(function () {
|
|
2046
2089
|
return "adding global keydown and click handlers";
|
|
2047
2090
|
});
|
|
2091
|
+
INSTRUCTION_IDs$1 = initAria();
|
|
2048
2092
|
window.addEventListener("keydown", globalKeyDownHandler);
|
|
2049
2093
|
window.addEventListener("click", globalClickHandler);
|
|
2050
2094
|
}
|
|
@@ -2081,6 +2125,8 @@
|
|
|
2081
2125
|
});
|
|
2082
2126
|
window.removeEventListener("keydown", globalKeyDownHandler);
|
|
2083
2127
|
window.removeEventListener("click", globalClickHandler);
|
|
2128
|
+
INSTRUCTION_IDs$1 = undefined;
|
|
2129
|
+
destroyAria();
|
|
2084
2130
|
}
|
|
2085
2131
|
}
|
|
2086
2132
|
|
|
@@ -2398,18 +2444,19 @@
|
|
|
2398
2444
|
config.dropTargetClasses = dropTargetClasses;
|
|
2399
2445
|
config.autoAriaDisabled = autoAriaDisabled;
|
|
2400
2446
|
|
|
2401
|
-
if (!autoAriaDisabled) {
|
|
2402
|
-
node.setAttribute("aria-disabled", dragDisabled);
|
|
2403
|
-
node.setAttribute("role", "list");
|
|
2404
|
-
node.setAttribute("aria-describedby", dragDisabled ? INSTRUCTION_IDs$1.DND_ZONE_DRAG_DISABLED : INSTRUCTION_IDs$1.DND_ZONE_ACTIVE);
|
|
2405
|
-
}
|
|
2406
|
-
|
|
2407
2447
|
if (config.type && newType !== config.type) {
|
|
2408
2448
|
unregisterDropZone$1(node, config.type);
|
|
2409
2449
|
}
|
|
2410
2450
|
|
|
2411
2451
|
config.type = newType;
|
|
2412
2452
|
registerDropZone$1(node, newType);
|
|
2453
|
+
|
|
2454
|
+
if (!autoAriaDisabled) {
|
|
2455
|
+
node.setAttribute("aria-disabled", dragDisabled);
|
|
2456
|
+
node.setAttribute("role", "list");
|
|
2457
|
+
node.setAttribute("aria-describedby", dragDisabled ? INSTRUCTION_IDs$1.DND_ZONE_DRAG_DISABLED : INSTRUCTION_IDs$1.DND_ZONE_ACTIVE);
|
|
2458
|
+
}
|
|
2459
|
+
|
|
2413
2460
|
dzToConfig$1.set(node, config);
|
|
2414
2461
|
|
|
2415
2462
|
if (isDragging) {
|
package/dist/index.mjs
CHANGED
|
@@ -593,6 +593,17 @@ function resetIndexesCache() {
|
|
|
593
593
|
dzToShadowIndexToRect = new Map();
|
|
594
594
|
}
|
|
595
595
|
resetIndexesCache();
|
|
596
|
+
/**
|
|
597
|
+
* Resets the cache that allows for smarter "would be index" resolution for a specific dropzone, should be called after the zone was scrolled
|
|
598
|
+
* @param {HTMLElement} dz
|
|
599
|
+
*/
|
|
600
|
+
|
|
601
|
+
function resetIndexesCacheForDz(dz) {
|
|
602
|
+
printDebug(function () {
|
|
603
|
+
return "resetting indexes cache for dz";
|
|
604
|
+
});
|
|
605
|
+
dzToShadowIndexToRect["delete"](dz);
|
|
606
|
+
}
|
|
596
607
|
/**
|
|
597
608
|
* Caches the coordinates of the shadow element when it's in a certain index in a certain dropzone.
|
|
598
609
|
* Helpful in order to determine "would be index" more effectively
|
|
@@ -925,6 +936,7 @@ function observe(draggedEl, dropZones) {
|
|
|
925
936
|
try {
|
|
926
937
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
927
938
|
var dz = _step.value;
|
|
939
|
+
if (scrolled) resetIndexesCacheForDz(lastDropZoneFound);
|
|
928
940
|
var indexObj = findWouldBeIndex(draggedEl, dz);
|
|
929
941
|
|
|
930
942
|
if (indexObj === null) {
|
|
@@ -1002,7 +1014,8 @@ var next$1;
|
|
|
1002
1014
|
|
|
1003
1015
|
function loop() {
|
|
1004
1016
|
if (mousePosition) {
|
|
1005
|
-
scrollIfNeeded$1(mousePosition, document.documentElement);
|
|
1017
|
+
var scrolled = scrollIfNeeded$1(mousePosition, document.documentElement);
|
|
1018
|
+
if (scrolled) resetIndexesCache();
|
|
1006
1019
|
}
|
|
1007
1020
|
|
|
1008
1021
|
next$1 = window.setTimeout(loop, INTERVAL_MS$1);
|
|
@@ -1630,6 +1643,7 @@ function cleanupPostDrop() {
|
|
|
1630
1643
|
}
|
|
1631
1644
|
|
|
1632
1645
|
function dndzone(node, options) {
|
|
1646
|
+
var initialized = false;
|
|
1633
1647
|
var config = {
|
|
1634
1648
|
items: undefined,
|
|
1635
1649
|
type: undefined,
|
|
@@ -1833,7 +1847,7 @@ function dndzone(node, options) {
|
|
|
1833
1847
|
config.transformDraggedElement = transformDraggedElement;
|
|
1834
1848
|
config.centreDraggedOnCursor = centreDraggedOnCursor; // realtime update for dropTargetStyle
|
|
1835
1849
|
|
|
1836
|
-
if (isWorkingOnPreviousDrag && !finalizingPreviousDrag && (!areObjectsShallowEqual(dropTargetStyle, config.dropTargetStyle) || !areArraysShallowEqualSameOrder(dropTargetClasses, config.dropTargetClasses))) {
|
|
1850
|
+
if (initialized && isWorkingOnPreviousDrag && !finalizingPreviousDrag && (!areObjectsShallowEqual(dropTargetStyle, config.dropTargetStyle) || !areArraysShallowEqualSameOrder(dropTargetClasses, config.dropTargetClasses))) {
|
|
1837
1851
|
styleInactiveDropZones([node], function () {
|
|
1838
1852
|
return config.dropTargetStyle;
|
|
1839
1853
|
}, function () {
|
|
@@ -1853,7 +1867,7 @@ function dndzone(node, options) {
|
|
|
1853
1867
|
return dzToConfig.get(dz) ? dzToConfig.get(dz)[propName] : config[propName];
|
|
1854
1868
|
}
|
|
1855
1869
|
|
|
1856
|
-
if (isWorkingOnPreviousDrag && config.dropFromOthersDisabled !== dropFromOthersDisabled) {
|
|
1870
|
+
if (initialized && isWorkingOnPreviousDrag && config.dropFromOthersDisabled !== dropFromOthersDisabled) {
|
|
1857
1871
|
if (dropFromOthersDisabled) {
|
|
1858
1872
|
styleInactiveDropZones([node], function (dz) {
|
|
1859
1873
|
return getConfigProp(dz, "dropTargetStyle");
|
|
@@ -1899,6 +1913,10 @@ function dndzone(node, options) {
|
|
|
1899
1913
|
|
|
1900
1914
|
|
|
1901
1915
|
elToIdx.set(draggableEl, idx);
|
|
1916
|
+
|
|
1917
|
+
if (!initialized) {
|
|
1918
|
+
initialized = true;
|
|
1919
|
+
}
|
|
1902
1920
|
};
|
|
1903
1921
|
|
|
1904
1922
|
for (var idx = 0; idx < node.children.length; idx++) {
|
|
@@ -1936,7 +1954,12 @@ var ALERT_DIV_ID = "dnd-action-aria-alert";
|
|
|
1936
1954
|
var alertsDiv;
|
|
1937
1955
|
|
|
1938
1956
|
function initAriaOnBrowser() {
|
|
1939
|
-
|
|
1957
|
+
if (alertsDiv) {
|
|
1958
|
+
// it is already initialized
|
|
1959
|
+
return;
|
|
1960
|
+
} // setting the dynamic alerts
|
|
1961
|
+
|
|
1962
|
+
|
|
1940
1963
|
alertsDiv = document.createElement("div");
|
|
1941
1964
|
|
|
1942
1965
|
(function initAlertsDiv() {
|
|
@@ -1980,6 +2003,20 @@ function initAria() {
|
|
|
1980
2003
|
|
|
1981
2004
|
return _objectSpread2({}, INSTRUCTION_IDs);
|
|
1982
2005
|
}
|
|
2006
|
+
/**
|
|
2007
|
+
* Removes all the artifacts (dom elements) added by this module
|
|
2008
|
+
*/
|
|
2009
|
+
|
|
2010
|
+
function destroyAria() {
|
|
2011
|
+
if (isOnServer || !alertsDiv) return;
|
|
2012
|
+
Object.keys(ID_TO_INSTRUCTION).forEach(function (id) {
|
|
2013
|
+
var _document$getElementB;
|
|
2014
|
+
|
|
2015
|
+
return (_document$getElementB = document.getElementById(id)) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.remove();
|
|
2016
|
+
});
|
|
2017
|
+
alertsDiv.remove();
|
|
2018
|
+
alertsDiv = undefined;
|
|
2019
|
+
}
|
|
1983
2020
|
|
|
1984
2021
|
function instructionToHiddenDiv(id, txt) {
|
|
1985
2022
|
var div = document.createElement("div");
|
|
@@ -1997,6 +2034,12 @@ function instructionToHiddenDiv(id, txt) {
|
|
|
1997
2034
|
|
|
1998
2035
|
|
|
1999
2036
|
function alertToScreenReader(txt) {
|
|
2037
|
+
if (isOnServer) return;
|
|
2038
|
+
|
|
2039
|
+
if (!alertsDiv) {
|
|
2040
|
+
initAriaOnBrowser();
|
|
2041
|
+
}
|
|
2042
|
+
|
|
2000
2043
|
alertsDiv.innerHTML = "";
|
|
2001
2044
|
var alertText = document.createTextNode(txt);
|
|
2002
2045
|
alertsDiv.appendChild(alertText); // this is needed for Safari
|
|
@@ -2027,7 +2070,7 @@ var typeToDropZones$1 = new Map();
|
|
|
2027
2070
|
* maybe keep focus on the last dragged item upon drop?
|
|
2028
2071
|
*/
|
|
2029
2072
|
|
|
2030
|
-
var INSTRUCTION_IDs$1
|
|
2073
|
+
var INSTRUCTION_IDs$1;
|
|
2031
2074
|
/* drop-zones registration management */
|
|
2032
2075
|
|
|
2033
2076
|
function registerDropZone$1(dropZoneEl, type) {
|
|
@@ -2039,6 +2082,7 @@ function registerDropZone$1(dropZoneEl, type) {
|
|
|
2039
2082
|
printDebug(function () {
|
|
2040
2083
|
return "adding global keydown and click handlers";
|
|
2041
2084
|
});
|
|
2085
|
+
INSTRUCTION_IDs$1 = initAria();
|
|
2042
2086
|
window.addEventListener("keydown", globalKeyDownHandler);
|
|
2043
2087
|
window.addEventListener("click", globalClickHandler);
|
|
2044
2088
|
}
|
|
@@ -2075,6 +2119,8 @@ function unregisterDropZone$1(dropZoneEl, type) {
|
|
|
2075
2119
|
});
|
|
2076
2120
|
window.removeEventListener("keydown", globalKeyDownHandler);
|
|
2077
2121
|
window.removeEventListener("click", globalClickHandler);
|
|
2122
|
+
INSTRUCTION_IDs$1 = undefined;
|
|
2123
|
+
destroyAria();
|
|
2078
2124
|
}
|
|
2079
2125
|
}
|
|
2080
2126
|
|
|
@@ -2392,18 +2438,19 @@ function dndzone$1(node, options) {
|
|
|
2392
2438
|
config.dropTargetClasses = dropTargetClasses;
|
|
2393
2439
|
config.autoAriaDisabled = autoAriaDisabled;
|
|
2394
2440
|
|
|
2395
|
-
if (!autoAriaDisabled) {
|
|
2396
|
-
node.setAttribute("aria-disabled", dragDisabled);
|
|
2397
|
-
node.setAttribute("role", "list");
|
|
2398
|
-
node.setAttribute("aria-describedby", dragDisabled ? INSTRUCTION_IDs$1.DND_ZONE_DRAG_DISABLED : INSTRUCTION_IDs$1.DND_ZONE_ACTIVE);
|
|
2399
|
-
}
|
|
2400
|
-
|
|
2401
2441
|
if (config.type && newType !== config.type) {
|
|
2402
2442
|
unregisterDropZone$1(node, config.type);
|
|
2403
2443
|
}
|
|
2404
2444
|
|
|
2405
2445
|
config.type = newType;
|
|
2406
2446
|
registerDropZone$1(node, newType);
|
|
2447
|
+
|
|
2448
|
+
if (!autoAriaDisabled) {
|
|
2449
|
+
node.setAttribute("aria-disabled", dragDisabled);
|
|
2450
|
+
node.setAttribute("role", "list");
|
|
2451
|
+
node.setAttribute("aria-describedby", dragDisabled ? INSTRUCTION_IDs$1.DND_ZONE_DRAG_DISABLED : INSTRUCTION_IDs$1.DND_ZONE_ACTIVE);
|
|
2452
|
+
}
|
|
2453
|
+
|
|
2407
2454
|
dzToConfig$1.set(node, config);
|
|
2408
2455
|
|
|
2409
2456
|
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.16",
|
|
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/listUtil.js
CHANGED
|
@@ -12,6 +12,15 @@ export function resetIndexesCache() {
|
|
|
12
12
|
}
|
|
13
13
|
resetIndexesCache();
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Resets the cache that allows for smarter "would be index" resolution for a specific dropzone, should be called after the zone was scrolled
|
|
17
|
+
* @param {HTMLElement} dz
|
|
18
|
+
*/
|
|
19
|
+
export function resetIndexesCacheForDz(dz) {
|
|
20
|
+
printDebug(() => "resetting indexes cache for dz");
|
|
21
|
+
dzToShadowIndexToRect.delete(dz);
|
|
22
|
+
}
|
|
23
|
+
|
|
15
24
|
/**
|
|
16
25
|
* Caches the coordinates of the shadow element when it's in a certain index in a certain dropzone.
|
|
17
26
|
* Helpful in order to determine "would be index" more effectively
|
package/src/helpers/observer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {findWouldBeIndex, resetIndexesCache} from "./listUtil";
|
|
1
|
+
import {findWouldBeIndex, resetIndexesCache, resetIndexesCacheForDz} from "./listUtil";
|
|
2
2
|
import {findCenterOfElement, isElementOffDocument} from "./intersection";
|
|
3
3
|
import {
|
|
4
4
|
dispatchDraggedElementEnteredContainer,
|
|
@@ -57,6 +57,7 @@ export function observe(draggedEl, dropZones, intervalMs = INTERVAL_MS) {
|
|
|
57
57
|
// this is a simple algorithm, potential improvement: first look at lastDropZoneFound
|
|
58
58
|
let isDraggedInADropZone = false;
|
|
59
59
|
for (const dz of dropZonesFromDeepToShallow) {
|
|
60
|
+
if (scrolled) resetIndexesCacheForDz(lastDropZoneFound);
|
|
60
61
|
const indexObj = findWouldBeIndex(draggedEl, dz);
|
|
61
62
|
if (indexObj === null) {
|
|
62
63
|
// it is not inside
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {makeScroller} from "./scroller";
|
|
2
2
|
import {printDebug} from "../constants";
|
|
3
|
+
import {resetIndexesCache} from "./listUtil";
|
|
3
4
|
|
|
4
5
|
const INTERVAL_MS = 300;
|
|
5
6
|
let mousePosition;
|
|
@@ -18,7 +19,8 @@ let next;
|
|
|
18
19
|
|
|
19
20
|
function loop() {
|
|
20
21
|
if (mousePosition) {
|
|
21
|
-
scrollIfNeeded(mousePosition, document.documentElement);
|
|
22
|
+
const scrolled = scrollIfNeeded(mousePosition, document.documentElement);
|
|
23
|
+
if (scrolled) resetIndexesCache();
|
|
22
24
|
}
|
|
23
25
|
next = window.setTimeout(loop, INTERVAL_MS);
|
|
24
26
|
}
|
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);
|