svelte-dnd-action 0.9.14 → 0.9.15
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 +37 -8
- package/dist/index.mjs +37 -8
- package/package.json +1 -1
- package/src/helpers/aria.js +19 -0
- package/src/keyboardAction.js +12 -9
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
|
@@ -1955,7 +1955,12 @@
|
|
|
1955
1955
|
var alertsDiv;
|
|
1956
1956
|
|
|
1957
1957
|
function initAriaOnBrowser() {
|
|
1958
|
-
|
|
1958
|
+
if (alertsDiv) {
|
|
1959
|
+
// it is already initialized
|
|
1960
|
+
return;
|
|
1961
|
+
} // setting the dynamic alerts
|
|
1962
|
+
|
|
1963
|
+
|
|
1959
1964
|
alertsDiv = document.createElement("div");
|
|
1960
1965
|
|
|
1961
1966
|
(function initAlertsDiv() {
|
|
@@ -1999,6 +2004,20 @@
|
|
|
1999
2004
|
|
|
2000
2005
|
return _objectSpread2({}, INSTRUCTION_IDs);
|
|
2001
2006
|
}
|
|
2007
|
+
/**
|
|
2008
|
+
* Removes all the artifacts (dom elements) added by this module
|
|
2009
|
+
*/
|
|
2010
|
+
|
|
2011
|
+
function destroyAria() {
|
|
2012
|
+
if (isOnServer || !alertsDiv) return;
|
|
2013
|
+
Object.keys(ID_TO_INSTRUCTION).forEach(function (id) {
|
|
2014
|
+
var _document$getElementB;
|
|
2015
|
+
|
|
2016
|
+
return (_document$getElementB = document.getElementById(id)) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.remove();
|
|
2017
|
+
});
|
|
2018
|
+
alertsDiv.remove();
|
|
2019
|
+
alertsDiv = undefined;
|
|
2020
|
+
}
|
|
2002
2021
|
|
|
2003
2022
|
function instructionToHiddenDiv(id, txt) {
|
|
2004
2023
|
var div = document.createElement("div");
|
|
@@ -2016,6 +2035,12 @@
|
|
|
2016
2035
|
|
|
2017
2036
|
|
|
2018
2037
|
function alertToScreenReader(txt) {
|
|
2038
|
+
if (isOnServer) return;
|
|
2039
|
+
|
|
2040
|
+
if (!alertsDiv) {
|
|
2041
|
+
initAriaOnBrowser();
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2019
2044
|
alertsDiv.innerHTML = "";
|
|
2020
2045
|
var alertText = document.createTextNode(txt);
|
|
2021
2046
|
alertsDiv.appendChild(alertText); // this is needed for Safari
|
|
@@ -2046,7 +2071,7 @@
|
|
|
2046
2071
|
* maybe keep focus on the last dragged item upon drop?
|
|
2047
2072
|
*/
|
|
2048
2073
|
|
|
2049
|
-
var INSTRUCTION_IDs$1
|
|
2074
|
+
var INSTRUCTION_IDs$1;
|
|
2050
2075
|
/* drop-zones registration management */
|
|
2051
2076
|
|
|
2052
2077
|
function registerDropZone$1(dropZoneEl, type) {
|
|
@@ -2058,6 +2083,7 @@
|
|
|
2058
2083
|
printDebug(function () {
|
|
2059
2084
|
return "adding global keydown and click handlers";
|
|
2060
2085
|
});
|
|
2086
|
+
INSTRUCTION_IDs$1 = initAria();
|
|
2061
2087
|
window.addEventListener("keydown", globalKeyDownHandler);
|
|
2062
2088
|
window.addEventListener("click", globalClickHandler);
|
|
2063
2089
|
}
|
|
@@ -2094,6 +2120,8 @@
|
|
|
2094
2120
|
});
|
|
2095
2121
|
window.removeEventListener("keydown", globalKeyDownHandler);
|
|
2096
2122
|
window.removeEventListener("click", globalClickHandler);
|
|
2123
|
+
INSTRUCTION_IDs$1 = undefined;
|
|
2124
|
+
destroyAria();
|
|
2097
2125
|
}
|
|
2098
2126
|
}
|
|
2099
2127
|
|
|
@@ -2411,18 +2439,19 @@
|
|
|
2411
2439
|
config.dropTargetClasses = dropTargetClasses;
|
|
2412
2440
|
config.autoAriaDisabled = autoAriaDisabled;
|
|
2413
2441
|
|
|
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
2442
|
if (config.type && newType !== config.type) {
|
|
2421
2443
|
unregisterDropZone$1(node, config.type);
|
|
2422
2444
|
}
|
|
2423
2445
|
|
|
2424
2446
|
config.type = newType;
|
|
2425
2447
|
registerDropZone$1(node, newType);
|
|
2448
|
+
|
|
2449
|
+
if (!autoAriaDisabled) {
|
|
2450
|
+
node.setAttribute("aria-disabled", dragDisabled);
|
|
2451
|
+
node.setAttribute("role", "list");
|
|
2452
|
+
node.setAttribute("aria-describedby", dragDisabled ? INSTRUCTION_IDs$1.DND_ZONE_DRAG_DISABLED : INSTRUCTION_IDs$1.DND_ZONE_ACTIVE);
|
|
2453
|
+
}
|
|
2454
|
+
|
|
2426
2455
|
dzToConfig$1.set(node, config);
|
|
2427
2456
|
|
|
2428
2457
|
if (isDragging) {
|
package/dist/index.mjs
CHANGED
|
@@ -1949,7 +1949,12 @@ var ALERT_DIV_ID = "dnd-action-aria-alert";
|
|
|
1949
1949
|
var alertsDiv;
|
|
1950
1950
|
|
|
1951
1951
|
function initAriaOnBrowser() {
|
|
1952
|
-
|
|
1952
|
+
if (alertsDiv) {
|
|
1953
|
+
// it is already initialized
|
|
1954
|
+
return;
|
|
1955
|
+
} // setting the dynamic alerts
|
|
1956
|
+
|
|
1957
|
+
|
|
1953
1958
|
alertsDiv = document.createElement("div");
|
|
1954
1959
|
|
|
1955
1960
|
(function initAlertsDiv() {
|
|
@@ -1993,6 +1998,20 @@ function initAria() {
|
|
|
1993
1998
|
|
|
1994
1999
|
return _objectSpread2({}, INSTRUCTION_IDs);
|
|
1995
2000
|
}
|
|
2001
|
+
/**
|
|
2002
|
+
* Removes all the artifacts (dom elements) added by this module
|
|
2003
|
+
*/
|
|
2004
|
+
|
|
2005
|
+
function destroyAria() {
|
|
2006
|
+
if (isOnServer || !alertsDiv) return;
|
|
2007
|
+
Object.keys(ID_TO_INSTRUCTION).forEach(function (id) {
|
|
2008
|
+
var _document$getElementB;
|
|
2009
|
+
|
|
2010
|
+
return (_document$getElementB = document.getElementById(id)) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.remove();
|
|
2011
|
+
});
|
|
2012
|
+
alertsDiv.remove();
|
|
2013
|
+
alertsDiv = undefined;
|
|
2014
|
+
}
|
|
1996
2015
|
|
|
1997
2016
|
function instructionToHiddenDiv(id, txt) {
|
|
1998
2017
|
var div = document.createElement("div");
|
|
@@ -2010,6 +2029,12 @@ function instructionToHiddenDiv(id, txt) {
|
|
|
2010
2029
|
|
|
2011
2030
|
|
|
2012
2031
|
function alertToScreenReader(txt) {
|
|
2032
|
+
if (isOnServer) return;
|
|
2033
|
+
|
|
2034
|
+
if (!alertsDiv) {
|
|
2035
|
+
initAriaOnBrowser();
|
|
2036
|
+
}
|
|
2037
|
+
|
|
2013
2038
|
alertsDiv.innerHTML = "";
|
|
2014
2039
|
var alertText = document.createTextNode(txt);
|
|
2015
2040
|
alertsDiv.appendChild(alertText); // this is needed for Safari
|
|
@@ -2040,7 +2065,7 @@ var typeToDropZones$1 = new Map();
|
|
|
2040
2065
|
* maybe keep focus on the last dragged item upon drop?
|
|
2041
2066
|
*/
|
|
2042
2067
|
|
|
2043
|
-
var INSTRUCTION_IDs$1
|
|
2068
|
+
var INSTRUCTION_IDs$1;
|
|
2044
2069
|
/* drop-zones registration management */
|
|
2045
2070
|
|
|
2046
2071
|
function registerDropZone$1(dropZoneEl, type) {
|
|
@@ -2052,6 +2077,7 @@ function registerDropZone$1(dropZoneEl, type) {
|
|
|
2052
2077
|
printDebug(function () {
|
|
2053
2078
|
return "adding global keydown and click handlers";
|
|
2054
2079
|
});
|
|
2080
|
+
INSTRUCTION_IDs$1 = initAria();
|
|
2055
2081
|
window.addEventListener("keydown", globalKeyDownHandler);
|
|
2056
2082
|
window.addEventListener("click", globalClickHandler);
|
|
2057
2083
|
}
|
|
@@ -2088,6 +2114,8 @@ function unregisterDropZone$1(dropZoneEl, type) {
|
|
|
2088
2114
|
});
|
|
2089
2115
|
window.removeEventListener("keydown", globalKeyDownHandler);
|
|
2090
2116
|
window.removeEventListener("click", globalClickHandler);
|
|
2117
|
+
INSTRUCTION_IDs$1 = undefined;
|
|
2118
|
+
destroyAria();
|
|
2091
2119
|
}
|
|
2092
2120
|
}
|
|
2093
2121
|
|
|
@@ -2405,18 +2433,19 @@ function dndzone$1(node, options) {
|
|
|
2405
2433
|
config.dropTargetClasses = dropTargetClasses;
|
|
2406
2434
|
config.autoAriaDisabled = autoAriaDisabled;
|
|
2407
2435
|
|
|
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
2436
|
if (config.type && newType !== config.type) {
|
|
2415
2437
|
unregisterDropZone$1(node, config.type);
|
|
2416
2438
|
}
|
|
2417
2439
|
|
|
2418
2440
|
config.type = newType;
|
|
2419
2441
|
registerDropZone$1(node, newType);
|
|
2442
|
+
|
|
2443
|
+
if (!autoAriaDisabled) {
|
|
2444
|
+
node.setAttribute("aria-disabled", dragDisabled);
|
|
2445
|
+
node.setAttribute("role", "list");
|
|
2446
|
+
node.setAttribute("aria-describedby", dragDisabled ? INSTRUCTION_IDs$1.DND_ZONE_DRAG_DISABLED : INSTRUCTION_IDs$1.DND_ZONE_ACTIVE);
|
|
2447
|
+
}
|
|
2448
|
+
|
|
2420
2449
|
dzToConfig$1.set(node, config);
|
|
2421
2450
|
|
|
2422
2451
|
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.15",
|
|
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/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
|
}
|