@hiai-gg/docsmint 0.3.7 → 0.3.9
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/backend/src/lib/logger.ts +45 -15
- package/dist/backend/index.js +238 -150
- package/dist/client.d.ts +11 -0
- package/dist/client.js +9 -0
- package/dist/frontend/CategoryDialog-CxVyaBV5.js +611 -0
- package/dist/frontend/ConfirmDialog-NFGXRa3E.js +214 -0
- package/dist/frontend/CreateSnapshotDialog-BDgFTeFn.js +216 -0
- package/dist/frontend/DatePicker-BZRBluzF.js +256 -0
- package/dist/frontend/DeleteDialog-CvAr2WPu.js +174 -0
- package/dist/frontend/FolderNode-C6FJv99G.js +298 -0
- package/dist/frontend/FolderTreeSelector-CyB8y2Sm.js +103 -0
- package/dist/frontend/HiaiDocsExtensionProvider-DHWLzRUu.js +11 -0
- package/dist/frontend/Icon-CooFj4Ee.js +64 -0
- package/dist/frontend/SettingsDialog-BHh68rTB.js +1016 -0
- package/dist/frontend/ShareDialog-BUOkYSlw.js +165 -0
- package/dist/frontend/Sidebar-Cu3JrKDC.js +2021 -0
- package/dist/frontend/TagCreateDialog-B9YZBNHi.js +260 -0
- package/dist/frontend/api/settings.js +1 -1
- package/dist/frontend/app-shell.d.ts +8 -0
- package/dist/frontend/app-shell.js +291 -0
- package/dist/frontend/{bundle-mjs-CP6Owz-8.js → bundle-mjs-DllmqUxV.js} +583 -568
- package/dist/frontend/camera-iKXDOOWT.js +29 -0
- package/dist/frontend/check-D-UuvBuh.js +25 -0
- package/dist/frontend/chevron-down-CiPtYyFh.js +25 -0
- package/dist/frontend/circle-check-tSPE1V6t.js +29 -0
- package/dist/frontend/clock-DJHbHZb8.js +29 -0
- package/dist/frontend/components/category-dialog.js +1 -1
- package/dist/frontend/components/create-snapshot-dialog.js +1 -1
- package/dist/frontend/components/delete-dialog.js +1 -1
- package/dist/frontend/components/editor/document-editor.js +1367 -1356
- package/dist/frontend/components/editor/document-title.js +25 -25
- package/dist/frontend/components/editor/markdown-toggle.js +45 -45
- package/dist/frontend/components/folder-node.js +1 -1
- package/dist/frontend/components/folder-tree-selector.js +1 -1
- package/dist/frontend/components/save-as-dialog.js +169 -151
- package/dist/frontend/components/settings.js +1 -1
- package/dist/frontend/components/share-dialog.js +1 -1
- package/dist/frontend/components/sidebar.js +2 -2013
- package/dist/frontend/components/tag-create-dialog.js +1 -1
- package/dist/frontend/components/version-history.js +188 -187
- package/dist/frontend/confirm-dialog-C4jTRbiS.js +250 -0
- package/dist/frontend/copy-GppwRMjX.js +32 -0
- package/dist/frontend/dashboard.js +1187 -1155
- package/dist/frontend/dialog-Bevp9mmM.js +213 -0
- package/dist/frontend/{loader-circle-Bk-WFz9g.js → dist-C3857Spp.js} +93 -92
- package/dist/frontend/doc-tabs.js +2 -2
- package/dist/frontend/dropdown-menu-CRSby3e9.js +530 -0
- package/dist/frontend/extension.js +2 -11
- package/dist/frontend/{floating-layer-anchor-C51M4l6v.js → floating-layer-anchor-BDs7vO-M.js} +1414 -1412
- package/dist/frontend/folder-DeWhnD7O.js +45 -0
- package/dist/frontend/folder-refresh.js +1 -1
- package/dist/frontend/frontend.css +1 -1
- package/dist/frontend/i18n.js +2 -2
- package/dist/frontend/input-BWlOML_m.js +23 -0
- package/dist/frontend/keyboard.js +1 -1
- package/dist/frontend/{keyboard.svelte-D7H8DihC.js → keyboard.svelte-CApmX0vl.js} +53 -53
- package/dist/frontend/label-C2HfJNQ2.js +30 -0
- package/dist/frontend/{messages-BpYaLbzE.js → messages-C5Q890i2.js} +8 -8
- package/dist/frontend/rotate-ccw-B4Q7brmV.js +25 -0
- package/dist/frontend/search.js +673 -647
- package/dist/frontend/select-value-GXwx90Pr.js +1446 -0
- package/dist/frontend/{settings-blyobazp.js → settings-DSrUl4hW.js} +9 -9
- package/dist/frontend/shared-document.js +94 -94
- package/dist/frontend/subfolders-refresh-store.svelte-B2dKVmgz.js +65 -0
- package/dist/frontend/tag-HxRazVN_.js +54 -0
- package/dist/frontend/tag-store.svelte-CqrUXo0o.js +29 -0
- package/dist/frontend/textarea-DOAE-h42.js +23 -0
- package/dist/frontend/theme.js +1 -1
- package/dist/frontend/theme.svelte-DKfCy12k.js +49 -0
- package/dist/frontend/{utils-D8kmM3ub.js → utils-BPDRytUU.js} +2 -3
- package/dist/frontend/{utils-C0OW2678.js → utils-DrfHTcei.js} +2 -3
- package/dist/frontend/utils.js +1 -1
- package/dist/frontend/x-CzBsnJ2x.js +25 -0
- package/dist/frontend-ssr/api/attachments.js +2 -0
- package/dist/frontend-ssr/api/categories.js +2 -0
- package/dist/frontend-ssr/api/documents.js +2 -0
- package/dist/frontend-ssr/api/folders.js +2 -0
- package/dist/frontend-ssr/api/settings.js +2 -0
- package/dist/frontend-ssr/api/share.js +2 -0
- package/dist/frontend-ssr/api/tags.js +2 -0
- package/dist/frontend-ssr/app-shell.js +294 -0
- package/dist/frontend-ssr/assets/CategoryDialog-BcGW8-Kf.js +584 -0
- package/dist/frontend-ssr/assets/ConfirmDialog-DjMFKc0V.js +420 -0
- package/dist/frontend-ssr/assets/CreateSnapshotDialog-1bROJ-Rn.js +214 -0
- package/dist/frontend-ssr/assets/DatePicker-B1ML8OVz.js +312 -0
- package/dist/frontend-ssr/assets/DeleteDialog-tBYaP0L3.js +154 -0
- package/dist/frontend-ssr/assets/FolderNode-BZ0Q2QUS.js +171 -0
- package/dist/frontend-ssr/assets/FolderTreeSelector-DZNZ2oI6.js +147 -0
- package/dist/frontend-ssr/assets/HiaiDocsExtensionProvider-DAM-lX4R.js +13 -0
- package/dist/frontend-ssr/assets/Icon-B0Zqppjo.js +231 -0
- package/dist/frontend-ssr/assets/SettingsDialog-B8L_YqNA.js +1107 -0
- package/dist/frontend-ssr/assets/ShareDialog-vMvJLRfn.js +54 -0
- package/dist/frontend-ssr/assets/Sidebar-EHuUAx3W.js +2033 -0
- package/dist/frontend-ssr/assets/TagCreateDialog-B0DPEfmQ.js +264 -0
- package/dist/frontend-ssr/assets/api-keys-DFqX39MT.js +35 -0
- package/dist/frontend-ssr/assets/attachments-CWBxE3Vz.js +85 -0
- package/dist/frontend-ssr/assets/auth-client-x26kqY8Z.js +1286 -0
- package/dist/frontend-ssr/assets/camera-CdxscTw-.js +84 -0
- package/dist/frontend-ssr/assets/categories-AOqgcsn4.js +75 -0
- package/dist/frontend-ssr/assets/chevron-down-CSSNGNh_.js +80 -0
- package/dist/frontend-ssr/assets/chevron-right-B4p7Sk6X.js +80 -0
- package/dist/frontend-ssr/assets/circle-check-CI1v4vYh.js +84 -0
- package/dist/frontend-ssr/assets/client-DZMkDkDn.js +129 -0
- package/dist/frontend-ssr/assets/clipboard-CXOaoz2W.js +30 -0
- package/dist/frontend-ssr/assets/clock-IL-eX2di.js +84 -0
- package/dist/frontend-ssr/assets/confirm-dialog-BCthVwUY.js +429 -0
- package/dist/frontend-ssr/assets/context-jz1GGEUi.js +45 -0
- package/dist/frontend-ssr/assets/copy-CjV57nGQ.js +87 -0
- package/dist/frontend-ssr/assets/db-CnxeO66n.js +65 -0
- package/dist/frontend-ssr/assets/dialog-BOV1u6zP.js +157 -0
- package/dist/frontend-ssr/assets/dndzone-DMvTO_Jz.js +2114 -0
- package/dist/frontend-ssr/assets/document-drop-coordinator-CEaYACsC.js +109 -0
- package/dist/frontend-ssr/assets/documents-BnOTRdTY.js +108 -0
- package/dist/frontend-ssr/assets/dropdown-menu-Bj5rbqbB.js +555 -0
- package/dist/frontend-ssr/assets/editorExtensions-DUzwndMy.js +186 -0
- package/dist/frontend-ssr/assets/floating-layer-anchor-CYIE8Oj6.js +6114 -0
- package/dist/frontend-ssr/assets/folder-DChhG7qN.js +80 -0
- package/dist/frontend-ssr/assets/folders-CTfbS24J.js +127 -0
- package/dist/frontend-ssr/assets/identity-B3uHoDtf.js +99 -0
- package/dist/frontend-ssr/assets/input-DezGsU3y.js +19 -0
- package/dist/frontend-ssr/assets/keyboard.svelte-BgF47N3L.js +174 -0
- package/dist/frontend-ssr/assets/label-Bj8-TfFN.js +21 -0
- package/dist/frontend-ssr/assets/loader-circle-DZsrZ-er.js +80 -0
- package/dist/frontend-ssr/assets/markdown-CjqvGi5W.js +20 -0
- package/dist/frontend-ssr/assets/messages-CvqpZNJe.js +11125 -0
- package/dist/frontend-ssr/assets/resolve-BqHozBXl.js +32 -0
- package/dist/frontend-ssr/assets/rotate-ccw-BlgWwaiq.js +80 -0
- package/dist/frontend-ssr/assets/select-value-6Lk0ToYd.js +1526 -0
- package/dist/frontend-ssr/assets/settings-Bk5Hk9Vq.js +64 -0
- package/dist/frontend-ssr/assets/share-BTBJelxA.js +30 -0
- package/dist/frontend-ssr/assets/subfolders-refresh-store.svelte-DAh4gT16.js +77 -0
- package/dist/frontend-ssr/assets/tag-GZEuGWk1.js +166 -0
- package/dist/frontend-ssr/assets/tag-store.svelte-DPodKj6Z.js +21 -0
- package/dist/frontend-ssr/assets/tags-BId2wdYd.js +49 -0
- package/dist/frontend-ssr/assets/textarea-Dev-qSEc.js +21 -0
- package/dist/frontend-ssr/assets/theme.svelte-Co0-ssaD.js +67 -0
- package/dist/frontend-ssr/assets/utils-DtlPPXpJ.js +9 -0
- package/dist/frontend-ssr/assets/utils-DvZnctjz.js +23 -0
- package/dist/frontend-ssr/collaboration.js +39 -0
- package/dist/frontend-ssr/components/category-dialog.js +2 -0
- package/dist/frontend-ssr/components/create-snapshot-dialog.js +2 -0
- package/dist/frontend-ssr/components/delete-dialog.js +2 -0
- package/dist/frontend-ssr/components/editor/document-editor.js +2499 -0
- package/dist/frontend-ssr/components/editor/document-title.js +11 -0
- package/dist/frontend-ssr/components/editor/docx-serializer.js +186 -0
- package/dist/frontend-ssr/components/editor/extensions.js +2 -0
- package/dist/frontend-ssr/components/editor/markdown-toggle.js +20 -0
- package/dist/frontend-ssr/components/editor/markdown.js +2 -0
- package/dist/frontend-ssr/components/folder-node.js +2 -0
- package/dist/frontend-ssr/components/folder-tree-selector.js +2 -0
- package/dist/frontend-ssr/components/save-as-dialog.js +280 -0
- package/dist/frontend-ssr/components/settings.js +2 -0
- package/dist/frontend-ssr/components/share-dialog.js +2 -0
- package/dist/frontend-ssr/components/sidebar.js +2 -0
- package/dist/frontend-ssr/components/tag-create-dialog.js +2 -0
- package/dist/frontend-ssr/components/version-history.js +370 -0
- package/dist/frontend-ssr/dashboard.js +2542 -0
- package/dist/frontend-ssr/doc-tabs.js +23 -0
- package/dist/frontend-ssr/document-drop-coordinator.js +2 -0
- package/dist/frontend-ssr/extension.js +2 -0
- package/dist/frontend-ssr/folder-refresh.js +2 -0
- package/dist/frontend-ssr/i18n.js +10 -0
- package/dist/frontend-ssr/keyboard.js +2 -0
- package/dist/frontend-ssr/offline/identity.js +2 -0
- package/dist/frontend-ssr/search.js +332 -0
- package/dist/frontend-ssr/shared-document.js +273 -0
- package/dist/frontend-ssr/theme.js +9 -0
- package/dist/frontend-ssr/types.js +1 -0
- package/dist/frontend-ssr/utils/clipboard.js +2 -0
- package/dist/frontend-ssr/utils/dndzone.js +2 -0
- package/dist/frontend-ssr/utils.js +2 -0
- package/package.json +28 -1
- package/packages/cli/src/index.ts +1 -1
- package/packages/db/src/schema.ts +3 -0
- package/packages/mcp-server/src/index.ts +1 -1
- package/dist/frontend/CategoryDialog--rIE7FrH.js +0 -580
- package/dist/frontend/ConfirmDialog-Cpzyb55f.js +0 -212
- package/dist/frontend/CreateSnapshotDialog-CmkV-n2A.js +0 -216
- package/dist/frontend/DatePicker-Byynca7V.js +0 -257
- package/dist/frontend/DeleteDialog-ap6nOywZ.js +0 -174
- package/dist/frontend/FolderDialog-DmN_trV0.js +0 -247
- package/dist/frontend/FolderNode-C4B8a2fd.js +0 -317
- package/dist/frontend/FolderTreeSelector-D6ijiZTA.js +0 -100
- package/dist/frontend/Icon-DtNo0N1U.js +0 -64
- package/dist/frontend/SettingsDialog-2kTaTXAs.js +0 -992
- package/dist/frontend/ShareDialog-BBDGNF5n.js +0 -165
- package/dist/frontend/TagCreateDialog-DiLZnJo4.js +0 -258
- package/dist/frontend/camera-B7dAOd4s.js +0 -28
- package/dist/frontend/check-CDwRlG9T.js +0 -24
- package/dist/frontend/chevron-down-B7ZrjUmT.js +0 -24
- package/dist/frontend/circle-check-CDqeMB2d.js +0 -28
- package/dist/frontend/client-Bc5Fzx40.js +0 -2785
- package/dist/frontend/clock-Ck5Sn-Zl.js +0 -28
- package/dist/frontend/clsx-nmtDPO_P.js +0 -16
- package/dist/frontend/copy-CMAA6GP0.js +0 -31
- package/dist/frontend/dialog-BDkiG42a.js +0 -213
- package/dist/frontend/disclose-version-5I57E3LD.js +0 -3
- package/dist/frontend/ellipsis-vertical-BBuPldbW.js +0 -519
- package/dist/frontend/folder-TQjKY4yn.js +0 -44
- package/dist/frontend/index-client-jobkrWVL.js +0 -86
- package/dist/frontend/input-CBI6p4Xl.js +0 -23
- package/dist/frontend/label-C-GkhEp4.js +0 -30
- package/dist/frontend/rotate-ccw-CleZtJ5D.js +0 -24
- package/dist/frontend/select-value-CvrWRkXW.js +0 -1436
- package/dist/frontend/subfolders-refresh-store.svelte-BsheoQma.js +0 -65
- package/dist/frontend/tag-Dx3SmucJ.js +0 -53
- package/dist/frontend/tag-store.svelte-CIaF4sdZ.js +0 -29
- package/dist/frontend/textarea-Dfp78XlL.js +0 -23
- package/dist/frontend/theme.svelte-CROg1Hi5.js +0 -49
- package/dist/frontend/x-DaTdeDXv.js +0 -24
|
@@ -0,0 +1,2114 @@
|
|
|
1
|
+
//#region ../node_modules/.bun/svelte-dnd-action@0.9.70+ff5f301bb2db9a0d/node_modules/svelte-dnd-action/dist/index.mjs
|
|
2
|
+
function ownKeys(object, enumerableOnly) {
|
|
3
|
+
var keys = Object.keys(object);
|
|
4
|
+
if (Object.getOwnPropertySymbols) {
|
|
5
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
6
|
+
enumerableOnly && (symbols = symbols.filter(function(sym) {
|
|
7
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
8
|
+
})), keys.push.apply(keys, symbols);
|
|
9
|
+
}
|
|
10
|
+
return keys;
|
|
11
|
+
}
|
|
12
|
+
function _objectSpread2(target) {
|
|
13
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
14
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
15
|
+
i % 2 ? ownKeys(Object(source), !0).forEach(function(key) {
|
|
16
|
+
_defineProperty(target, key, source[key]);
|
|
17
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
|
|
18
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return target;
|
|
22
|
+
}
|
|
23
|
+
function _typeof(obj) {
|
|
24
|
+
"@babel/helpers - typeof";
|
|
25
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj) {
|
|
26
|
+
return typeof obj;
|
|
27
|
+
} : function(obj) {
|
|
28
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
29
|
+
}, _typeof(obj);
|
|
30
|
+
}
|
|
31
|
+
function _defineProperty(obj, key, value) {
|
|
32
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
33
|
+
value,
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true
|
|
37
|
+
});
|
|
38
|
+
else obj[key] = value;
|
|
39
|
+
return obj;
|
|
40
|
+
}
|
|
41
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
42
|
+
if (source == null) return {};
|
|
43
|
+
var target = {};
|
|
44
|
+
var sourceKeys = Object.keys(source);
|
|
45
|
+
var key, i;
|
|
46
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
47
|
+
key = sourceKeys[i];
|
|
48
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
49
|
+
target[key] = source[key];
|
|
50
|
+
}
|
|
51
|
+
return target;
|
|
52
|
+
}
|
|
53
|
+
function _objectWithoutProperties(source, excluded) {
|
|
54
|
+
if (source == null) return {};
|
|
55
|
+
var target = _objectWithoutPropertiesLoose(source, excluded);
|
|
56
|
+
var key, i;
|
|
57
|
+
if (Object.getOwnPropertySymbols) {
|
|
58
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
59
|
+
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
|
60
|
+
key = sourceSymbolKeys[i];
|
|
61
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
62
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
63
|
+
target[key] = source[key];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return target;
|
|
67
|
+
}
|
|
68
|
+
function _slicedToArray(arr, i) {
|
|
69
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
70
|
+
}
|
|
71
|
+
function _toConsumableArray(arr) {
|
|
72
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
73
|
+
}
|
|
74
|
+
function _arrayWithoutHoles(arr) {
|
|
75
|
+
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
76
|
+
}
|
|
77
|
+
function _arrayWithHoles(arr) {
|
|
78
|
+
if (Array.isArray(arr)) return arr;
|
|
79
|
+
}
|
|
80
|
+
function _iterableToArray(iter) {
|
|
81
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
82
|
+
}
|
|
83
|
+
function _iterableToArrayLimit(arr, i) {
|
|
84
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
85
|
+
if (_i == null) return;
|
|
86
|
+
var _arr = [];
|
|
87
|
+
var _n = true;
|
|
88
|
+
var _d = false;
|
|
89
|
+
var _s, _e;
|
|
90
|
+
try {
|
|
91
|
+
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
92
|
+
_arr.push(_s.value);
|
|
93
|
+
if (i && _arr.length === i) break;
|
|
94
|
+
}
|
|
95
|
+
} catch (err) {
|
|
96
|
+
_d = true;
|
|
97
|
+
_e = err;
|
|
98
|
+
} finally {
|
|
99
|
+
try {
|
|
100
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
101
|
+
} finally {
|
|
102
|
+
if (_d) throw _e;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return _arr;
|
|
106
|
+
}
|
|
107
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
108
|
+
if (!o) return;
|
|
109
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
110
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
111
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
112
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
113
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
114
|
+
}
|
|
115
|
+
function _arrayLikeToArray(arr, len) {
|
|
116
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
117
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
118
|
+
return arr2;
|
|
119
|
+
}
|
|
120
|
+
function _nonIterableSpread() {
|
|
121
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
122
|
+
}
|
|
123
|
+
function _nonIterableRest() {
|
|
124
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
125
|
+
}
|
|
126
|
+
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
127
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
128
|
+
if (!it) {
|
|
129
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
130
|
+
if (it) o = it;
|
|
131
|
+
var i = 0;
|
|
132
|
+
var F = function() {};
|
|
133
|
+
return {
|
|
134
|
+
s: F,
|
|
135
|
+
n: function() {
|
|
136
|
+
if (i >= o.length) return { done: true };
|
|
137
|
+
return {
|
|
138
|
+
done: false,
|
|
139
|
+
value: o[i++]
|
|
140
|
+
};
|
|
141
|
+
},
|
|
142
|
+
e: function(e) {
|
|
143
|
+
throw e;
|
|
144
|
+
},
|
|
145
|
+
f: F
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
149
|
+
}
|
|
150
|
+
var normalCompletion = true, didErr = false, err;
|
|
151
|
+
return {
|
|
152
|
+
s: function() {
|
|
153
|
+
it = it.call(o);
|
|
154
|
+
},
|
|
155
|
+
n: function() {
|
|
156
|
+
var step = it.next();
|
|
157
|
+
normalCompletion = step.done;
|
|
158
|
+
return step;
|
|
159
|
+
},
|
|
160
|
+
e: function(e) {
|
|
161
|
+
didErr = true;
|
|
162
|
+
err = e;
|
|
163
|
+
},
|
|
164
|
+
f: function() {
|
|
165
|
+
try {
|
|
166
|
+
if (!normalCompletion && it.return != null) it.return();
|
|
167
|
+
} finally {
|
|
168
|
+
if (didErr) throw err;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
var FINALIZE_EVENT_NAME = "finalize";
|
|
174
|
+
var CONSIDER_EVENT_NAME = "consider";
|
|
175
|
+
/**
|
|
176
|
+
* @typedef {Object} Info
|
|
177
|
+
* @property {string} trigger
|
|
178
|
+
* @property {string} id
|
|
179
|
+
* @property {string} source
|
|
180
|
+
* @param {Node} el
|
|
181
|
+
* @param {Array} items
|
|
182
|
+
* @param {Info} info
|
|
183
|
+
*/
|
|
184
|
+
function dispatchFinalizeEvent(el, items, info) {
|
|
185
|
+
el.dispatchEvent(new CustomEvent(FINALIZE_EVENT_NAME, { detail: {
|
|
186
|
+
items,
|
|
187
|
+
info
|
|
188
|
+
} }));
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Dispatches a consider event
|
|
192
|
+
* @param {Node} el
|
|
193
|
+
* @param {Array} items
|
|
194
|
+
* @param {Info} info
|
|
195
|
+
*/
|
|
196
|
+
function dispatchConsiderEvent(el, items, info) {
|
|
197
|
+
el.dispatchEvent(new CustomEvent(CONSIDER_EVENT_NAME, { detail: {
|
|
198
|
+
items,
|
|
199
|
+
info
|
|
200
|
+
} }));
|
|
201
|
+
}
|
|
202
|
+
var DRAGGED_ENTERED_EVENT_NAME = "draggedEntered";
|
|
203
|
+
var DRAGGED_LEFT_EVENT_NAME = "draggedLeft";
|
|
204
|
+
var DRAGGED_OVER_INDEX_EVENT_NAME = "draggedOverIndex";
|
|
205
|
+
var DRAGGED_LEFT_DOCUMENT_EVENT_NAME = "draggedLeftDocument";
|
|
206
|
+
var DRAGGED_LEFT_TYPES = {
|
|
207
|
+
LEFT_FOR_ANOTHER: "leftForAnother",
|
|
208
|
+
OUTSIDE_OF_ANY: "outsideOfAny"
|
|
209
|
+
};
|
|
210
|
+
function dispatchDraggedElementEnteredContainer(containerEl, indexObj, draggedEl) {
|
|
211
|
+
containerEl.dispatchEvent(new CustomEvent(DRAGGED_ENTERED_EVENT_NAME, { detail: {
|
|
212
|
+
indexObj,
|
|
213
|
+
draggedEl
|
|
214
|
+
} }));
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* @param containerEl - the dropzone the element left
|
|
218
|
+
* @param draggedEl - the dragged element
|
|
219
|
+
* @param theOtherDz - the new dropzone the element entered
|
|
220
|
+
*/
|
|
221
|
+
function dispatchDraggedElementLeftContainerForAnother(containerEl, draggedEl, theOtherDz) {
|
|
222
|
+
containerEl.dispatchEvent(new CustomEvent(DRAGGED_LEFT_EVENT_NAME, { detail: {
|
|
223
|
+
draggedEl,
|
|
224
|
+
type: DRAGGED_LEFT_TYPES.LEFT_FOR_ANOTHER,
|
|
225
|
+
theOtherDz
|
|
226
|
+
} }));
|
|
227
|
+
}
|
|
228
|
+
function dispatchDraggedElementLeftContainerForNone(containerEl, draggedEl) {
|
|
229
|
+
containerEl.dispatchEvent(new CustomEvent(DRAGGED_LEFT_EVENT_NAME, { detail: {
|
|
230
|
+
draggedEl,
|
|
231
|
+
type: DRAGGED_LEFT_TYPES.OUTSIDE_OF_ANY
|
|
232
|
+
} }));
|
|
233
|
+
}
|
|
234
|
+
function dispatchDraggedElementIsOverIndex(containerEl, indexObj, draggedEl) {
|
|
235
|
+
containerEl.dispatchEvent(new CustomEvent(DRAGGED_OVER_INDEX_EVENT_NAME, { detail: {
|
|
236
|
+
indexObj,
|
|
237
|
+
draggedEl
|
|
238
|
+
} }));
|
|
239
|
+
}
|
|
240
|
+
function dispatchDraggedLeftDocument(draggedEl) {
|
|
241
|
+
window.dispatchEvent(new CustomEvent(DRAGGED_LEFT_DOCUMENT_EVENT_NAME, { detail: { draggedEl } }));
|
|
242
|
+
}
|
|
243
|
+
var TRIGGERS = {
|
|
244
|
+
DRAG_STARTED: "dragStarted",
|
|
245
|
+
DRAGGED_ENTERED: DRAGGED_ENTERED_EVENT_NAME,
|
|
246
|
+
DRAGGED_ENTERED_ANOTHER: "dragEnteredAnother",
|
|
247
|
+
DRAGGED_OVER_INDEX: DRAGGED_OVER_INDEX_EVENT_NAME,
|
|
248
|
+
DRAGGED_LEFT: DRAGGED_LEFT_EVENT_NAME,
|
|
249
|
+
DRAGGED_LEFT_ALL: "draggedLeftAll",
|
|
250
|
+
DROPPED_INTO_ZONE: "droppedIntoZone",
|
|
251
|
+
DROPPED_INTO_ANOTHER: "droppedIntoAnother",
|
|
252
|
+
DROPPED_OUTSIDE_OF_ANY: "droppedOutsideOfAny",
|
|
253
|
+
DRAG_STOPPED: "dragStopped"
|
|
254
|
+
};
|
|
255
|
+
var SOURCES = {
|
|
256
|
+
POINTER: "pointer",
|
|
257
|
+
KEYBOARD: "keyboard"
|
|
258
|
+
};
|
|
259
|
+
var SHADOW_ITEM_MARKER_PROPERTY_NAME = "isDndShadowItem";
|
|
260
|
+
var SHADOW_ELEMENT_ATTRIBUTE_NAME = "data-is-dnd-shadow-item-internal";
|
|
261
|
+
var SHADOW_ELEMENT_HINT_ATTRIBUTE_NAME = "data-is-dnd-shadow-item-hint";
|
|
262
|
+
var SHADOW_PLACEHOLDER_ITEM_ID = "id:dnd-shadow-placeholder-0000";
|
|
263
|
+
var DRAGGED_ELEMENT_ID = "dnd-action-dragged-el";
|
|
264
|
+
var ITEM_ID_KEY = "id";
|
|
265
|
+
var activeDndZoneCount = 0;
|
|
266
|
+
function incrementActiveDropZoneCount() {
|
|
267
|
+
activeDndZoneCount++;
|
|
268
|
+
}
|
|
269
|
+
function decrementActiveDropZoneCount() {
|
|
270
|
+
if (activeDndZoneCount === 0) throw new Error("Bug! trying to decrement when there are no dropzones");
|
|
271
|
+
activeDndZoneCount--;
|
|
272
|
+
}
|
|
273
|
+
var isOnServer = typeof window === "undefined";
|
|
274
|
+
/**
|
|
275
|
+
* Gets the bounding rect but removes transforms (ex: flip animation)
|
|
276
|
+
* @param {HTMLElement} el
|
|
277
|
+
* @param {boolean} [onlyVisible] - use the visible rect defaults to true
|
|
278
|
+
* @return {{top: number, left: number, bottom: number, right: number}}
|
|
279
|
+
*/
|
|
280
|
+
function getBoundingRectNoTransforms(el) {
|
|
281
|
+
var onlyVisible = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
|
|
282
|
+
var ta;
|
|
283
|
+
var rect = onlyVisible ? getVisibleRectRecursive(el) : el.getBoundingClientRect();
|
|
284
|
+
var style = getComputedStyle(el);
|
|
285
|
+
var tx = style.transform;
|
|
286
|
+
if (tx) {
|
|
287
|
+
var sx, sy, dx, dy;
|
|
288
|
+
if (tx.startsWith("matrix3d(")) {
|
|
289
|
+
ta = tx.slice(9, -1).split(/, /);
|
|
290
|
+
sx = +ta[0];
|
|
291
|
+
sy = +ta[5];
|
|
292
|
+
dx = +ta[12];
|
|
293
|
+
dy = +ta[13];
|
|
294
|
+
} else if (tx.startsWith("matrix(")) {
|
|
295
|
+
ta = tx.slice(7, -1).split(/, /);
|
|
296
|
+
sx = +ta[0];
|
|
297
|
+
sy = +ta[3];
|
|
298
|
+
dx = +ta[4];
|
|
299
|
+
dy = +ta[5];
|
|
300
|
+
} else return rect;
|
|
301
|
+
var to = style.transformOrigin;
|
|
302
|
+
var x = rect.x - dx - (1 - sx) * parseFloat(to);
|
|
303
|
+
var y = rect.y - dy - (1 - sy) * parseFloat(to.slice(to.indexOf(" ") + 1));
|
|
304
|
+
var w = sx ? rect.width / sx : el.offsetWidth;
|
|
305
|
+
var h = sy ? rect.height / sy : el.offsetHeight;
|
|
306
|
+
return {
|
|
307
|
+
x,
|
|
308
|
+
y,
|
|
309
|
+
width: w,
|
|
310
|
+
height: h,
|
|
311
|
+
top: y,
|
|
312
|
+
right: x + w,
|
|
313
|
+
bottom: y + h,
|
|
314
|
+
left: x
|
|
315
|
+
};
|
|
316
|
+
} else return rect;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Gets the absolute bounding rect (accounts for the window's scroll position and removes transforms)
|
|
320
|
+
* @param {HTMLElement} el
|
|
321
|
+
* @return {{top: number, left: number, bottom: number, right: number}}
|
|
322
|
+
*/
|
|
323
|
+
function getAbsoluteRectNoTransforms(el) {
|
|
324
|
+
var rect = getBoundingRectNoTransforms(el);
|
|
325
|
+
return {
|
|
326
|
+
top: rect.top + window.scrollY,
|
|
327
|
+
bottom: rect.bottom + window.scrollY,
|
|
328
|
+
left: rect.left + window.scrollX,
|
|
329
|
+
right: rect.right + window.scrollX
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Gets the absolute bounding rect (accounts for the window's scroll position)
|
|
334
|
+
* @param {HTMLElement} el
|
|
335
|
+
* @return {{top: number, left: number, bottom: number, right: number}}
|
|
336
|
+
*/
|
|
337
|
+
function getAbsoluteRect(el) {
|
|
338
|
+
var rect = el.getBoundingClientRect();
|
|
339
|
+
return {
|
|
340
|
+
top: rect.top + window.scrollY,
|
|
341
|
+
bottom: rect.bottom + window.scrollY,
|
|
342
|
+
left: rect.left + window.scrollX,
|
|
343
|
+
right: rect.right + window.scrollX
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* finds the center :)
|
|
348
|
+
* @typedef {Object} Rect
|
|
349
|
+
* @property {number} top
|
|
350
|
+
* @property {number} bottom
|
|
351
|
+
* @property {number} left
|
|
352
|
+
* @property {number} right
|
|
353
|
+
* @param {Rect} rect
|
|
354
|
+
* @return {{x: number, y: number}}
|
|
355
|
+
*/
|
|
356
|
+
function findCenter(rect) {
|
|
357
|
+
return {
|
|
358
|
+
x: (rect.left + rect.right) / 2,
|
|
359
|
+
y: (rect.top + rect.bottom) / 2
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* @typedef {Object} Point
|
|
364
|
+
* @property {number} x
|
|
365
|
+
* @property {number} y
|
|
366
|
+
* @param {Point} pointA
|
|
367
|
+
* @param {Point} pointB
|
|
368
|
+
* @return {number}
|
|
369
|
+
*/
|
|
370
|
+
function calcDistance(pointA, pointB) {
|
|
371
|
+
return Math.sqrt(Math.pow(pointA.x - pointB.x, 2) + Math.pow(pointA.y - pointB.y, 2));
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* @param {Point} point
|
|
375
|
+
* @param {Rect} rect
|
|
376
|
+
* @return {boolean|boolean}
|
|
377
|
+
*/
|
|
378
|
+
function isPointInsideRect(point, rect) {
|
|
379
|
+
return point.y <= rect.bottom && point.y >= rect.top && point.x >= rect.left && point.x <= rect.right;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* find the absolute coordinates of the center of a dom element
|
|
383
|
+
* @param el {HTMLElement}
|
|
384
|
+
* @returns {{x: number, y: number}}
|
|
385
|
+
*/
|
|
386
|
+
function findCenterOfElement(el) {
|
|
387
|
+
return findCenter(getAbsoluteRect(el));
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Calculate distance from a point to the center of an element
|
|
391
|
+
* @param {{x: number, y: number}} point
|
|
392
|
+
* @param {HTMLElement|ChildNode} el
|
|
393
|
+
* @return {number}
|
|
394
|
+
*/
|
|
395
|
+
function calcDistanceFromPointToCenter(point, el) {
|
|
396
|
+
return calcDistance(point, findCenterOfElement(el));
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* @param {HTMLElement} el - the element to check
|
|
400
|
+
* @returns {boolean} - true if the element in its entirety is off-screen including the scrollable area (the normal dom events look at the mouse rather than the element)
|
|
401
|
+
*/
|
|
402
|
+
function isElementOffDocument(el) {
|
|
403
|
+
var rect = getAbsoluteRect(el);
|
|
404
|
+
return rect.right < 0 || rect.left > document.documentElement.scrollWidth || rect.bottom < 0 || rect.top > document.documentElement.scrollHeight;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Computes the portion of an element that is actually visible inside its scrollable
|
|
408
|
+
* ancestor containers. If the element is clipped by any scrollable ancestor (overflow: auto|scroll),
|
|
409
|
+
* the returned rect is the clipped one. If it is not clipped by any scrollable ancestor but is
|
|
410
|
+
* partially or fully outside the viewport, the function returns the element's full bounding rect
|
|
411
|
+
* (i.e. it does NOT clip to the viewport).
|
|
412
|
+
*
|
|
413
|
+
* This is useful for distinguishing "hidden because parent scrolls" from
|
|
414
|
+
* "hidden because off-screen".
|
|
415
|
+
*
|
|
416
|
+
* @param {HTMLElement} element - The DOM element to measure.
|
|
417
|
+
* @returns {{top: number, bottom: number, left: number, right: number, width: number, height: number}}
|
|
418
|
+
* An object describing the visible rectangle in viewport coordinates.
|
|
419
|
+
*/
|
|
420
|
+
function getVisibleRectRecursive(element) {
|
|
421
|
+
var rect = element.getBoundingClientRect();
|
|
422
|
+
var visibleRect = {
|
|
423
|
+
top: rect.top,
|
|
424
|
+
bottom: rect.bottom,
|
|
425
|
+
left: rect.left,
|
|
426
|
+
right: rect.right
|
|
427
|
+
};
|
|
428
|
+
var wasClippedByScrollY = false;
|
|
429
|
+
var wasClippedByScrollX = false;
|
|
430
|
+
var parent = element.parentElement;
|
|
431
|
+
while (parent && parent !== document.body) {
|
|
432
|
+
var style = window.getComputedStyle(parent);
|
|
433
|
+
var overflowY = style.overflowY;
|
|
434
|
+
var overflowX = style.overflowX;
|
|
435
|
+
var isScrollableY = overflowY === "scroll" || overflowY === "auto";
|
|
436
|
+
var isScrollableX = overflowX === "scroll" || overflowX === "auto";
|
|
437
|
+
if (isScrollableY || isScrollableX) {
|
|
438
|
+
var parentRect = parent.getBoundingClientRect();
|
|
439
|
+
if (isScrollableY) {
|
|
440
|
+
var newTop = Math.max(visibleRect.top, parentRect.top);
|
|
441
|
+
var newBottom = Math.min(visibleRect.bottom, parentRect.bottom);
|
|
442
|
+
if (newTop !== visibleRect.top || newBottom !== visibleRect.bottom) wasClippedByScrollY = true;
|
|
443
|
+
visibleRect.top = newTop;
|
|
444
|
+
visibleRect.bottom = newBottom;
|
|
445
|
+
}
|
|
446
|
+
if (isScrollableX) {
|
|
447
|
+
var newLeft = Math.max(visibleRect.left, parentRect.left);
|
|
448
|
+
var newRight = Math.min(visibleRect.right, parentRect.right);
|
|
449
|
+
if (newLeft !== visibleRect.left || newRight !== visibleRect.right) wasClippedByScrollX = true;
|
|
450
|
+
visibleRect.left = newLeft;
|
|
451
|
+
visibleRect.right = newRight;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
parent = parent.parentElement;
|
|
455
|
+
}
|
|
456
|
+
if (wasClippedByScrollY || wasClippedByScrollX) return {
|
|
457
|
+
top: visibleRect.top,
|
|
458
|
+
bottom: visibleRect.bottom,
|
|
459
|
+
left: visibleRect.left,
|
|
460
|
+
right: visibleRect.right,
|
|
461
|
+
width: Math.max(0, visibleRect.right - visibleRect.left),
|
|
462
|
+
height: Math.max(0, visibleRect.bottom - visibleRect.top)
|
|
463
|
+
};
|
|
464
|
+
return {
|
|
465
|
+
top: rect.top,
|
|
466
|
+
bottom: rect.bottom,
|
|
467
|
+
left: rect.left,
|
|
468
|
+
right: rect.right,
|
|
469
|
+
width: Math.max(0, rect.right - rect.left),
|
|
470
|
+
height: Math.max(0, rect.bottom - rect.top)
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
var dzToShadowIndexToRect;
|
|
474
|
+
/**
|
|
475
|
+
* Resets the cache that allows for smarter "would be index" resolution. Should be called after every drag operation
|
|
476
|
+
*/
|
|
477
|
+
function resetIndexesCache() {
|
|
478
|
+
dzToShadowIndexToRect = /* @__PURE__ */ new Map();
|
|
479
|
+
}
|
|
480
|
+
resetIndexesCache();
|
|
481
|
+
/**
|
|
482
|
+
* Caches the coordinates of the shadow element when it's in a certain index in a certain dropzone.
|
|
483
|
+
* Helpful in order to determine "would be index" more effectively
|
|
484
|
+
* @param {HTMLElement} dz
|
|
485
|
+
* @return {number} - the shadow element index
|
|
486
|
+
*/
|
|
487
|
+
function cacheShadowRect(dz) {
|
|
488
|
+
var shadowElIndex = Array.from(dz.children).findIndex(function(child) {
|
|
489
|
+
return child.getAttribute(SHADOW_ELEMENT_ATTRIBUTE_NAME);
|
|
490
|
+
});
|
|
491
|
+
if (shadowElIndex >= 0) {
|
|
492
|
+
if (!dzToShadowIndexToRect.has(dz)) dzToShadowIndexToRect.set(dz, /* @__PURE__ */ new Map());
|
|
493
|
+
dzToShadowIndexToRect.get(dz).set(shadowElIndex, getAbsoluteRectNoTransforms(dz.children[shadowElIndex]));
|
|
494
|
+
return shadowElIndex;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* @typedef {Object} Index
|
|
499
|
+
* @property {number} index - the would be index
|
|
500
|
+
* @property {boolean} isProximityBased - false if the element is actually over the index, true if it is not over it but this index is the closest
|
|
501
|
+
*/
|
|
502
|
+
/**
|
|
503
|
+
* Find the index for the dragged element in the list it is dragged over
|
|
504
|
+
* @param {{x: number, y: number}} referencePoint - The reference point for detection (cursor position or element center)
|
|
505
|
+
* @param {HTMLElement} collectionBelowEl
|
|
506
|
+
* @returns {Index|null} - if the element is over the container the Index object otherwise null
|
|
507
|
+
*/
|
|
508
|
+
function findWouldBeIndex(referencePoint, collectionBelowEl) {
|
|
509
|
+
if (!isPointInsideRect(referencePoint, getAbsoluteRectNoTransforms(collectionBelowEl))) return null;
|
|
510
|
+
var children = collectionBelowEl.children;
|
|
511
|
+
if (children.length === 0) return {
|
|
512
|
+
index: 0,
|
|
513
|
+
isProximityBased: true
|
|
514
|
+
};
|
|
515
|
+
var shadowElIndex = cacheShadowRect(collectionBelowEl);
|
|
516
|
+
for (var i = 0; i < children.length; i++) if (isPointInsideRect(referencePoint, getAbsoluteRectNoTransforms(children[i]))) {
|
|
517
|
+
var cachedShadowRect = dzToShadowIndexToRect.has(collectionBelowEl) && dzToShadowIndexToRect.get(collectionBelowEl).get(i);
|
|
518
|
+
if (cachedShadowRect) {
|
|
519
|
+
if (!isPointInsideRect(referencePoint, cachedShadowRect)) return {
|
|
520
|
+
index: shadowElIndex,
|
|
521
|
+
isProximityBased: false
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
return {
|
|
525
|
+
index: i,
|
|
526
|
+
isProximityBased: false
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
var minDistanceSoFar = Number.MAX_VALUE;
|
|
530
|
+
var indexOfMin = void 0;
|
|
531
|
+
for (var _i = 0; _i < children.length; _i++) {
|
|
532
|
+
var distance = calcDistanceFromPointToCenter(referencePoint, children[_i]);
|
|
533
|
+
if (distance < minDistanceSoFar) {
|
|
534
|
+
minDistanceSoFar = distance;
|
|
535
|
+
indexOfMin = _i;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
if (children.length > 0) {
|
|
539
|
+
var originalLen = children.length;
|
|
540
|
+
var phantom = children[originalLen - 1].cloneNode(false);
|
|
541
|
+
phantom.style.visibility = "hidden";
|
|
542
|
+
phantom.style.pointerEvents = "none";
|
|
543
|
+
collectionBelowEl.appendChild(phantom);
|
|
544
|
+
if (calcDistanceFromPointToCenter(referencePoint, phantom) < minDistanceSoFar) indexOfMin = originalLen;
|
|
545
|
+
collectionBelowEl.removeChild(phantom);
|
|
546
|
+
}
|
|
547
|
+
return {
|
|
548
|
+
index: indexOfMin,
|
|
549
|
+
isProximityBased: true
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* @param {Object} object
|
|
554
|
+
* @return {string}
|
|
555
|
+
*/
|
|
556
|
+
function toString(object) {
|
|
557
|
+
return JSON.stringify(object, null, 2);
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Finds the depth of the given node in the DOM tree
|
|
561
|
+
* @param {HTMLElement} node
|
|
562
|
+
* @return {number} - the depth of the node
|
|
563
|
+
*/
|
|
564
|
+
function getDepth(node) {
|
|
565
|
+
if (!node) throw new Error("cannot get depth of a falsy node");
|
|
566
|
+
return _getDepth(node, 0);
|
|
567
|
+
}
|
|
568
|
+
function _getDepth(node) {
|
|
569
|
+
var countSoFar = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
|
|
570
|
+
if (!node.parentElement) return countSoFar - 1;
|
|
571
|
+
return _getDepth(node.parentElement, countSoFar + 1);
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* A simple util to shallow compare objects quickly, it doesn't validate the arguments so pass objects in
|
|
575
|
+
* @param {Object} objA
|
|
576
|
+
* @param {Object} objB
|
|
577
|
+
* @return {boolean} - true if objA and objB are shallow equal
|
|
578
|
+
*/
|
|
579
|
+
function areObjectsShallowEqual(objA, objB) {
|
|
580
|
+
if (Object.keys(objA).length !== Object.keys(objB).length) return false;
|
|
581
|
+
for (var keyA in objA) if (!{}.hasOwnProperty.call(objB, keyA) || objB[keyA] !== objA[keyA]) return false;
|
|
582
|
+
return true;
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Shallow compares two arrays
|
|
586
|
+
* @param arrA
|
|
587
|
+
* @param arrB
|
|
588
|
+
* @return {boolean} - whether the arrays are shallow equal
|
|
589
|
+
*/
|
|
590
|
+
function areArraysShallowEqualSameOrder(arrA, arrB) {
|
|
591
|
+
if (arrA.length !== arrB.length) return false;
|
|
592
|
+
for (var i = 0; i < arrA.length; i++) if (arrA[i] !== arrB[i]) return false;
|
|
593
|
+
return true;
|
|
594
|
+
}
|
|
595
|
+
var INTERVAL_MS = 200;
|
|
596
|
+
var TOLERANCE_PX = 10;
|
|
597
|
+
var next;
|
|
598
|
+
/**
|
|
599
|
+
* Tracks the dragged elements and performs the side effects when it is dragged over a drop zone (basically dispatching custom-events scrolling)
|
|
600
|
+
* @param {Set<HTMLElement>} dropZones
|
|
601
|
+
* @param {HTMLElement} draggedEl
|
|
602
|
+
* @param {number} [intervalMs = INTERVAL_MS]
|
|
603
|
+
* @param {MultiScroller} multiScroller
|
|
604
|
+
* @param {function(): {x: number, y: number}} getReferencePoint - Function that returns the reference point for detection (cursor or element center)
|
|
605
|
+
*/
|
|
606
|
+
function observe(draggedEl, dropZones) {
|
|
607
|
+
var intervalMs = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : INTERVAL_MS;
|
|
608
|
+
var multiScroller = arguments.length > 3 ? arguments[3] : void 0;
|
|
609
|
+
var getReferencePoint = arguments.length > 4 ? arguments[4] : void 0;
|
|
610
|
+
var lastDropZoneFound;
|
|
611
|
+
var lastIndexFound;
|
|
612
|
+
var lastIsDraggedInADropZone = false;
|
|
613
|
+
var lastCentrePositionOfDragged;
|
|
614
|
+
var dropZonesFromDeepToShallow = Array.from(dropZones).sort(function(dz1, dz2) {
|
|
615
|
+
return getDepth(dz2) - getDepth(dz1);
|
|
616
|
+
});
|
|
617
|
+
/**
|
|
618
|
+
* The main function in this module. Tracks where everything is/ should be a take the actions
|
|
619
|
+
*/
|
|
620
|
+
function andNow() {
|
|
621
|
+
var referencePoint = getReferencePoint();
|
|
622
|
+
var scrolled = multiScroller.multiScrollIfNeeded();
|
|
623
|
+
if (!scrolled && lastCentrePositionOfDragged && Math.abs(lastCentrePositionOfDragged.x - referencePoint.x) < TOLERANCE_PX && Math.abs(lastCentrePositionOfDragged.y - referencePoint.y) < TOLERANCE_PX) {
|
|
624
|
+
next = window.setTimeout(andNow, intervalMs);
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
if (isElementOffDocument(draggedEl)) {
|
|
628
|
+
dispatchDraggedLeftDocument(draggedEl);
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
lastCentrePositionOfDragged = referencePoint;
|
|
632
|
+
var isDraggedInADropZone = false;
|
|
633
|
+
var _iterator = _createForOfIteratorHelper(dropZonesFromDeepToShallow), _step;
|
|
634
|
+
try {
|
|
635
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
636
|
+
var dz = _step.value;
|
|
637
|
+
if (scrolled) resetIndexesCache();
|
|
638
|
+
var indexObj = findWouldBeIndex(referencePoint, dz);
|
|
639
|
+
if (indexObj === null) continue;
|
|
640
|
+
var index = indexObj.index;
|
|
641
|
+
isDraggedInADropZone = true;
|
|
642
|
+
if (dz !== lastDropZoneFound) {
|
|
643
|
+
lastDropZoneFound && dispatchDraggedElementLeftContainerForAnother(lastDropZoneFound, draggedEl, dz);
|
|
644
|
+
dispatchDraggedElementEnteredContainer(dz, indexObj, draggedEl);
|
|
645
|
+
lastDropZoneFound = dz;
|
|
646
|
+
} else if (index !== lastIndexFound) {
|
|
647
|
+
dispatchDraggedElementIsOverIndex(dz, indexObj, draggedEl);
|
|
648
|
+
lastIndexFound = index;
|
|
649
|
+
}
|
|
650
|
+
break;
|
|
651
|
+
}
|
|
652
|
+
} catch (err) {
|
|
653
|
+
_iterator.e(err);
|
|
654
|
+
} finally {
|
|
655
|
+
_iterator.f();
|
|
656
|
+
}
|
|
657
|
+
if (!isDraggedInADropZone && lastIsDraggedInADropZone && lastDropZoneFound) {
|
|
658
|
+
dispatchDraggedElementLeftContainerForNone(lastDropZoneFound, draggedEl);
|
|
659
|
+
lastDropZoneFound = void 0;
|
|
660
|
+
lastIndexFound = void 0;
|
|
661
|
+
lastIsDraggedInADropZone = false;
|
|
662
|
+
} else lastIsDraggedInADropZone = true;
|
|
663
|
+
next = window.setTimeout(andNow, intervalMs);
|
|
664
|
+
}
|
|
665
|
+
andNow();
|
|
666
|
+
}
|
|
667
|
+
function unobserve() {
|
|
668
|
+
clearTimeout(next);
|
|
669
|
+
resetIndexesCache();
|
|
670
|
+
}
|
|
671
|
+
var SCROLL_ZONE_PX = 30;
|
|
672
|
+
/**
|
|
673
|
+
* Will make a scroller that can scroll any element given to it in any direction
|
|
674
|
+
* @returns {{scrollIfNeeded: function(Point, HTMLElement): boolean, resetScrolling: function(void):void}}
|
|
675
|
+
*/
|
|
676
|
+
function makeScroller() {
|
|
677
|
+
var scrollingInfo;
|
|
678
|
+
function resetScrolling() {
|
|
679
|
+
scrollingInfo = {
|
|
680
|
+
directionObj: void 0,
|
|
681
|
+
stepPx: 0
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
resetScrolling();
|
|
685
|
+
function scrollContainer(containerEl) {
|
|
686
|
+
var _scrollingInfo = scrollingInfo, directionObj = _scrollingInfo.directionObj, stepPx = _scrollingInfo.stepPx;
|
|
687
|
+
if (directionObj) {
|
|
688
|
+
containerEl.scrollBy(directionObj.x * stepPx, directionObj.y * stepPx);
|
|
689
|
+
window.requestAnimationFrame(function() {
|
|
690
|
+
return scrollContainer(containerEl);
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
function calcScrollStepPx(distancePx) {
|
|
695
|
+
return SCROLL_ZONE_PX - distancePx;
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* @param {Point} pointer - the pointer will be used to decide in which direction to scroll
|
|
699
|
+
* @param {HTMLElement} elementToScroll - the scroll container
|
|
700
|
+
* If the pointer is next to the sides of the element to scroll, will trigger scrolling
|
|
701
|
+
* Can be called repeatedly with updated pointer and elementToScroll values without issues
|
|
702
|
+
* @return {boolean} - true if scrolling was needed
|
|
703
|
+
*/
|
|
704
|
+
function scrollIfNeeded(pointer, elementToScroll) {
|
|
705
|
+
if (!elementToScroll) return false;
|
|
706
|
+
var distances = calcInnerDistancesBetweenPointAndSidesOfElement(pointer, elementToScroll);
|
|
707
|
+
var isAlreadyScrolling = !!scrollingInfo.directionObj;
|
|
708
|
+
if (distances === null) {
|
|
709
|
+
if (isAlreadyScrolling) resetScrolling();
|
|
710
|
+
return false;
|
|
711
|
+
}
|
|
712
|
+
var scrollingVertically = false, scrollingHorizontally = false;
|
|
713
|
+
if (elementToScroll.scrollHeight > elementToScroll.clientHeight) {
|
|
714
|
+
if (distances.bottom < SCROLL_ZONE_PX) {
|
|
715
|
+
scrollingVertically = true;
|
|
716
|
+
scrollingInfo.directionObj = {
|
|
717
|
+
x: 0,
|
|
718
|
+
y: 1
|
|
719
|
+
};
|
|
720
|
+
scrollingInfo.stepPx = calcScrollStepPx(distances.bottom);
|
|
721
|
+
} else if (distances.top < SCROLL_ZONE_PX) {
|
|
722
|
+
scrollingVertically = true;
|
|
723
|
+
scrollingInfo.directionObj = {
|
|
724
|
+
x: 0,
|
|
725
|
+
y: -1
|
|
726
|
+
};
|
|
727
|
+
scrollingInfo.stepPx = calcScrollStepPx(distances.top);
|
|
728
|
+
}
|
|
729
|
+
if (!isAlreadyScrolling && scrollingVertically) {
|
|
730
|
+
scrollContainer(elementToScroll);
|
|
731
|
+
return true;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
if (elementToScroll.scrollWidth > elementToScroll.clientWidth) {
|
|
735
|
+
if (distances.right < SCROLL_ZONE_PX) {
|
|
736
|
+
scrollingHorizontally = true;
|
|
737
|
+
scrollingInfo.directionObj = {
|
|
738
|
+
x: 1,
|
|
739
|
+
y: 0
|
|
740
|
+
};
|
|
741
|
+
scrollingInfo.stepPx = calcScrollStepPx(distances.right);
|
|
742
|
+
} else if (distances.left < SCROLL_ZONE_PX) {
|
|
743
|
+
scrollingHorizontally = true;
|
|
744
|
+
scrollingInfo.directionObj = {
|
|
745
|
+
x: -1,
|
|
746
|
+
y: 0
|
|
747
|
+
};
|
|
748
|
+
scrollingInfo.stepPx = calcScrollStepPx(distances.left);
|
|
749
|
+
}
|
|
750
|
+
if (!isAlreadyScrolling && scrollingHorizontally) {
|
|
751
|
+
scrollContainer(elementToScroll);
|
|
752
|
+
return true;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
resetScrolling();
|
|
756
|
+
return false;
|
|
757
|
+
}
|
|
758
|
+
return {
|
|
759
|
+
scrollIfNeeded,
|
|
760
|
+
resetScrolling
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* If the point is inside the element returns its distances from the sides, otherwise returns null
|
|
765
|
+
* @param {Point} point
|
|
766
|
+
* @param {HTMLElement} el
|
|
767
|
+
* @return {null|{top: number, left: number, bottom: number, right: number}}
|
|
768
|
+
*/
|
|
769
|
+
function calcInnerDistancesBetweenPointAndSidesOfElement(point, el) {
|
|
770
|
+
var rect = el === document.scrollingElement ? {
|
|
771
|
+
top: 0,
|
|
772
|
+
bottom: window.innerHeight,
|
|
773
|
+
left: 0,
|
|
774
|
+
right: window.innerWidth
|
|
775
|
+
} : el.getBoundingClientRect();
|
|
776
|
+
if (!isPointInsideRect(point, rect)) return null;
|
|
777
|
+
return {
|
|
778
|
+
top: point.y - rect.top,
|
|
779
|
+
bottom: rect.bottom - point.y,
|
|
780
|
+
left: point.x - rect.left,
|
|
781
|
+
right: rect.right - point.x
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
@typedef {Object} MultiScroller
|
|
786
|
+
@property {function():boolean} multiScrollIfNeeded - call this on every "tick" to scroll containers if needed, returns true if anything was scrolled
|
|
787
|
+
/**
|
|
788
|
+
* Creates a scroller than can scroll any of the provided containers or any of their scrollable parents (including the document's scrolling element)
|
|
789
|
+
* @param {HTMLElement[]} baseElementsForScrolling
|
|
790
|
+
* @param {function():Point} getPointerPosition
|
|
791
|
+
* @return {MultiScroller}
|
|
792
|
+
*/
|
|
793
|
+
function createMultiScroller() {
|
|
794
|
+
var baseElementsForScrolling = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
|
|
795
|
+
var getPointerPosition = arguments.length > 1 ? arguments[1] : void 0;
|
|
796
|
+
var scrollingContainersSet = findRelevantScrollContainers(baseElementsForScrolling);
|
|
797
|
+
var scrollingContainersDeepToShallow = Array.from(scrollingContainersSet).sort(function(dz1, dz2) {
|
|
798
|
+
return getDepth(dz2) - getDepth(dz1);
|
|
799
|
+
});
|
|
800
|
+
var _makeScroller = makeScroller(), scrollIfNeeded = _makeScroller.scrollIfNeeded, resetScrolling = _makeScroller.resetScrolling;
|
|
801
|
+
/**
|
|
802
|
+
* @return {boolean} - was any container scrolled
|
|
803
|
+
*/
|
|
804
|
+
function tick() {
|
|
805
|
+
var mousePosition = getPointerPosition();
|
|
806
|
+
if (!mousePosition || !scrollingContainersDeepToShallow) return false;
|
|
807
|
+
var scrollContainersUnderCursor = scrollingContainersDeepToShallow.filter(function(el) {
|
|
808
|
+
return isPointInsideRect(mousePosition, el.getBoundingClientRect()) || el === document.scrollingElement;
|
|
809
|
+
});
|
|
810
|
+
for (var i = 0; i < scrollContainersUnderCursor.length; i++) if (scrollIfNeeded(mousePosition, scrollContainersUnderCursor[i])) return true;
|
|
811
|
+
return false;
|
|
812
|
+
}
|
|
813
|
+
return {
|
|
814
|
+
multiScrollIfNeeded: scrollingContainersSet.size > 0 ? tick : function() {
|
|
815
|
+
return false;
|
|
816
|
+
},
|
|
817
|
+
destroy: function destroy() {
|
|
818
|
+
return resetScrolling();
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
function findScrollableParents(element) {
|
|
823
|
+
if (!element) return [];
|
|
824
|
+
var scrollableContainers = [];
|
|
825
|
+
var parent = element;
|
|
826
|
+
while (parent) {
|
|
827
|
+
if (window.getComputedStyle(parent).overflow.split(" ").some(function(o) {
|
|
828
|
+
return o.includes("auto") || o.includes("scroll");
|
|
829
|
+
})) scrollableContainers.push(parent);
|
|
830
|
+
parent = parent.parentElement;
|
|
831
|
+
}
|
|
832
|
+
return scrollableContainers;
|
|
833
|
+
}
|
|
834
|
+
function findRelevantScrollContainers(dropZones) {
|
|
835
|
+
var scrollingContainers = /* @__PURE__ */ new Set();
|
|
836
|
+
var _iterator = _createForOfIteratorHelper(dropZones), _step;
|
|
837
|
+
try {
|
|
838
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
839
|
+
var dz = _step.value;
|
|
840
|
+
findScrollableParents(dz).forEach(function(container) {
|
|
841
|
+
return scrollingContainers.add(container);
|
|
842
|
+
});
|
|
843
|
+
}
|
|
844
|
+
} catch (err) {
|
|
845
|
+
_iterator.e(err);
|
|
846
|
+
} finally {
|
|
847
|
+
_iterator.f();
|
|
848
|
+
}
|
|
849
|
+
if (document.scrollingElement.scrollHeight > document.scrollingElement.clientHeight || document.scrollingElement.scrollWidth > document.scrollingElement.clientHeight) scrollingContainers.add(document.scrollingElement);
|
|
850
|
+
return scrollingContainers;
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* Fixes svelte issue when cloning node containing (or being) <select> which will loose it's value.
|
|
854
|
+
* Since svelte manages select value internally.
|
|
855
|
+
* @see https://github.com/sveltejs/svelte/issues/6717
|
|
856
|
+
* @see https://github.com/isaacHagoel/svelte-dnd-action/issues/306
|
|
857
|
+
*
|
|
858
|
+
* @param {HTMLElement} el
|
|
859
|
+
* @returns
|
|
860
|
+
*/
|
|
861
|
+
function svelteNodeClone(el) {
|
|
862
|
+
var cloned = el.cloneNode(true);
|
|
863
|
+
var values = [];
|
|
864
|
+
var elIsSelect = el.tagName === "SELECT";
|
|
865
|
+
var selects = elIsSelect ? [el] : _toConsumableArray(el.querySelectorAll("select"));
|
|
866
|
+
var _iterator = _createForOfIteratorHelper(selects), _step;
|
|
867
|
+
try {
|
|
868
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
869
|
+
var _select = _step.value;
|
|
870
|
+
values.push(_select.value);
|
|
871
|
+
}
|
|
872
|
+
} catch (err) {
|
|
873
|
+
_iterator.e(err);
|
|
874
|
+
} finally {
|
|
875
|
+
_iterator.f();
|
|
876
|
+
}
|
|
877
|
+
if (selects.length > 0) {
|
|
878
|
+
var clonedSelects = elIsSelect ? [cloned] : _toConsumableArray(cloned.querySelectorAll("select"));
|
|
879
|
+
for (var i = 0; i < clonedSelects.length; i++) {
|
|
880
|
+
var select = clonedSelects[i];
|
|
881
|
+
var value = values[i];
|
|
882
|
+
var optionEl = select.querySelector("option[value=\"".concat(value, "\""));
|
|
883
|
+
if (optionEl) optionEl.setAttribute("selected", true);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
var elIsCanvas = el.tagName === "CANVAS";
|
|
887
|
+
var canvases = elIsCanvas ? [el] : _toConsumableArray(el.querySelectorAll("canvas"));
|
|
888
|
+
if (canvases.length > 0) {
|
|
889
|
+
var clonedCanvases = elIsCanvas ? [cloned] : _toConsumableArray(cloned.querySelectorAll("canvas"));
|
|
890
|
+
for (var _i = 0; _i < clonedCanvases.length; _i++) {
|
|
891
|
+
var canvas = canvases[_i];
|
|
892
|
+
var clonedCanvas = clonedCanvases[_i];
|
|
893
|
+
clonedCanvas.width = canvas.width;
|
|
894
|
+
clonedCanvas.height = canvas.height;
|
|
895
|
+
if (canvas.width > 0 && canvas.height > 0) clonedCanvas.getContext("2d").drawImage(canvas, 0, 0);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
return cloned;
|
|
899
|
+
}
|
|
900
|
+
/**
|
|
901
|
+
* @type {{USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT: string}}
|
|
902
|
+
*/
|
|
903
|
+
var FEATURE_FLAG_NAMES = Object.freeze({ USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT: "USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT" });
|
|
904
|
+
var featureFlagsMap = _defineProperty({}, FEATURE_FLAG_NAMES.USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT, false);
|
|
905
|
+
/**
|
|
906
|
+
*
|
|
907
|
+
* @param {FEATURE_FLAG_NAMES} flagName
|
|
908
|
+
* @return {boolean}
|
|
909
|
+
*/
|
|
910
|
+
function getFeatureFlag(flagName) {
|
|
911
|
+
if (!FEATURE_FLAG_NAMES[flagName]) throw new Error("Can't get non existing feature flag ".concat(flagName, "! Supported flags: ").concat(Object.keys(FEATURE_FLAG_NAMES)));
|
|
912
|
+
return featureFlagsMap[flagName];
|
|
913
|
+
}
|
|
914
|
+
var TRANSITION_DURATION_SECONDS = .2;
|
|
915
|
+
/**
|
|
916
|
+
* private helper function - creates a transition string for a property
|
|
917
|
+
* @param {string} property
|
|
918
|
+
* @return {string} - the transition string
|
|
919
|
+
*/
|
|
920
|
+
function trs(property) {
|
|
921
|
+
return "".concat(property, " ").concat(TRANSITION_DURATION_SECONDS, "s ease");
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* clones the given element and applies proper styles and transitions to the dragged element
|
|
925
|
+
* @param {HTMLElement} originalElement
|
|
926
|
+
* @param {Point} [positionCenterOnXY]
|
|
927
|
+
* @return {Node} - the cloned, styled element
|
|
928
|
+
*/
|
|
929
|
+
function createDraggedElementFrom(originalElement, positionCenterOnXY) {
|
|
930
|
+
var rect = originalElement.getBoundingClientRect();
|
|
931
|
+
var draggedEl = svelteNodeClone(originalElement);
|
|
932
|
+
copyStylesFromTo(originalElement, draggedEl);
|
|
933
|
+
draggedEl.id = DRAGGED_ELEMENT_ID;
|
|
934
|
+
draggedEl.style.position = "fixed";
|
|
935
|
+
var elTopPx = rect.top;
|
|
936
|
+
var elLeftPx = rect.left;
|
|
937
|
+
draggedEl.style.top = "".concat(elTopPx, "px");
|
|
938
|
+
draggedEl.style.left = "".concat(elLeftPx, "px");
|
|
939
|
+
if (positionCenterOnXY) {
|
|
940
|
+
var center = findCenter(rect);
|
|
941
|
+
elTopPx -= center.y - positionCenterOnXY.y;
|
|
942
|
+
elLeftPx -= center.x - positionCenterOnXY.x;
|
|
943
|
+
window.setTimeout(function() {
|
|
944
|
+
draggedEl.style.top = "".concat(elTopPx, "px");
|
|
945
|
+
draggedEl.style.left = "".concat(elLeftPx, "px");
|
|
946
|
+
}, 0);
|
|
947
|
+
}
|
|
948
|
+
draggedEl.style.margin = "0";
|
|
949
|
+
draggedEl.style.boxSizing = "border-box";
|
|
950
|
+
draggedEl.style.height = "".concat(rect.height, "px");
|
|
951
|
+
draggedEl.style.width = "".concat(rect.width, "px");
|
|
952
|
+
draggedEl.style.transition = "".concat(trs("top"), ", ").concat(trs("left"), ", ").concat(trs("background-color"), ", ").concat(trs("opacity"), ", ").concat(trs("color"), " ");
|
|
953
|
+
window.setTimeout(function() {
|
|
954
|
+
return draggedEl.style.transition += ", ".concat(trs("width"), ", ").concat(trs("height"));
|
|
955
|
+
}, 0);
|
|
956
|
+
draggedEl.style.zIndex = "9999";
|
|
957
|
+
draggedEl.style.cursor = "grabbing";
|
|
958
|
+
return draggedEl;
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* styles the dragged element to a 'dropped' state
|
|
962
|
+
* @param {HTMLElement} draggedEl
|
|
963
|
+
*/
|
|
964
|
+
function moveDraggedElementToWasDroppedState(draggedEl) {
|
|
965
|
+
draggedEl.style.cursor = "grab";
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Morphs the dragged element style, maintains the mouse pointer within the element
|
|
969
|
+
* @param {HTMLElement} draggedEl
|
|
970
|
+
* @param {HTMLElement} copyFromEl - the element the dragged element should look like, typically the shadow element
|
|
971
|
+
* @param {number} currentMouseX
|
|
972
|
+
* @param {number} currentMouseY
|
|
973
|
+
*/
|
|
974
|
+
function morphDraggedElementToBeLike(draggedEl, copyFromEl, currentMouseX, currentMouseY) {
|
|
975
|
+
copyStylesFromTo(copyFromEl, draggedEl);
|
|
976
|
+
var newRect = copyFromEl.getBoundingClientRect();
|
|
977
|
+
var draggedElRect = draggedEl.getBoundingClientRect();
|
|
978
|
+
var widthChange = newRect.width - draggedElRect.width;
|
|
979
|
+
var heightChange = newRect.height - draggedElRect.height;
|
|
980
|
+
if (widthChange || heightChange) {
|
|
981
|
+
var relativeDistanceOfMousePointerFromDraggedSides = {
|
|
982
|
+
left: (currentMouseX - draggedElRect.left) / draggedElRect.width,
|
|
983
|
+
top: (currentMouseY - draggedElRect.top) / draggedElRect.height
|
|
984
|
+
};
|
|
985
|
+
if (!getFeatureFlag(FEATURE_FLAG_NAMES.USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT)) {
|
|
986
|
+
draggedEl.style.height = "".concat(newRect.height, "px");
|
|
987
|
+
draggedEl.style.width = "".concat(newRect.width, "px");
|
|
988
|
+
}
|
|
989
|
+
draggedEl.style.left = "".concat(parseFloat(draggedEl.style.left) - relativeDistanceOfMousePointerFromDraggedSides.left * widthChange, "px");
|
|
990
|
+
draggedEl.style.top = "".concat(parseFloat(draggedEl.style.top) - relativeDistanceOfMousePointerFromDraggedSides.top * heightChange, "px");
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
/**
|
|
994
|
+
* @param {HTMLElement} copyFromEl
|
|
995
|
+
* @param {HTMLElement} copyToEl
|
|
996
|
+
*/
|
|
997
|
+
function copyStylesFromTo(copyFromEl, copyToEl) {
|
|
998
|
+
var computedStyle = window.getComputedStyle(copyFromEl);
|
|
999
|
+
Array.from(computedStyle).filter(function(s) {
|
|
1000
|
+
return s.startsWith("background") || s.startsWith("padding") || s.startsWith("font") || s.startsWith("text") || s.startsWith("align") || s.startsWith("justify") || s.startsWith("display") || s.startsWith("flex") || s.startsWith("border") || s === "opacity" || s === "color" || s === "list-style-type" || getFeatureFlag(FEATURE_FLAG_NAMES.USE_COMPUTED_STYLE_INSTEAD_OF_BOUNDING_RECT) && (s === "width" || s === "height");
|
|
1001
|
+
}).forEach(function(s) {
|
|
1002
|
+
return copyToEl.style.setProperty(s, computedStyle.getPropertyValue(s), computedStyle.getPropertyPriority(s));
|
|
1003
|
+
});
|
|
1004
|
+
}
|
|
1005
|
+
/**
|
|
1006
|
+
* makes the element compatible with being draggable
|
|
1007
|
+
* @param {HTMLElement} draggableEl
|
|
1008
|
+
* @param {boolean} dragDisabled
|
|
1009
|
+
*/
|
|
1010
|
+
function styleDraggable(draggableEl, dragDisabled) {
|
|
1011
|
+
draggableEl.draggable = false;
|
|
1012
|
+
draggableEl.ondragstart = function() {
|
|
1013
|
+
return false;
|
|
1014
|
+
};
|
|
1015
|
+
if (!dragDisabled) {
|
|
1016
|
+
draggableEl.style.userSelect = "none";
|
|
1017
|
+
draggableEl.style.WebkitUserSelect = "none";
|
|
1018
|
+
draggableEl.style.cursor = "grab";
|
|
1019
|
+
} else {
|
|
1020
|
+
draggableEl.style.userSelect = "";
|
|
1021
|
+
draggableEl.style.WebkitUserSelect = "";
|
|
1022
|
+
draggableEl.style.cursor = "";
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
/**
|
|
1026
|
+
* Hides the provided element so that it can stay in the dom without interrupting
|
|
1027
|
+
* @param {HTMLElement} dragTarget
|
|
1028
|
+
*/
|
|
1029
|
+
function hideElement(dragTarget) {
|
|
1030
|
+
dragTarget.style.display = "none";
|
|
1031
|
+
dragTarget.style.position = "fixed";
|
|
1032
|
+
dragTarget.style.zIndex = "-5";
|
|
1033
|
+
}
|
|
1034
|
+
/**
|
|
1035
|
+
* styles the shadow element
|
|
1036
|
+
* @param {HTMLElement} shadowEl
|
|
1037
|
+
*/
|
|
1038
|
+
function decorateShadowEl(shadowEl) {
|
|
1039
|
+
shadowEl.style.visibility = "hidden";
|
|
1040
|
+
shadowEl.setAttribute(SHADOW_ELEMENT_ATTRIBUTE_NAME, "true");
|
|
1041
|
+
}
|
|
1042
|
+
/**
|
|
1043
|
+
* undo the styles the shadow element
|
|
1044
|
+
* @param {HTMLElement} shadowEl
|
|
1045
|
+
*/
|
|
1046
|
+
function unDecorateShadowElement(shadowEl) {
|
|
1047
|
+
shadowEl.style.visibility = "";
|
|
1048
|
+
shadowEl.removeAttribute(SHADOW_ELEMENT_ATTRIBUTE_NAME);
|
|
1049
|
+
}
|
|
1050
|
+
/**
|
|
1051
|
+
* will mark the given dropzones as visually active
|
|
1052
|
+
* @param {Array<HTMLElement>} dropZones
|
|
1053
|
+
* @param {Function} getStyles - maps a dropzone to a styles object (so the styles can be removed)
|
|
1054
|
+
* @param {Function} getClasses - maps a dropzone to a classList
|
|
1055
|
+
*/
|
|
1056
|
+
function styleActiveDropZones(dropZones) {
|
|
1057
|
+
var getStyles = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : function() {};
|
|
1058
|
+
var getClasses = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : function() {
|
|
1059
|
+
return [];
|
|
1060
|
+
};
|
|
1061
|
+
dropZones.forEach(function(dz) {
|
|
1062
|
+
var styles = getStyles(dz);
|
|
1063
|
+
Object.keys(styles).forEach(function(style) {
|
|
1064
|
+
dz.style[style] = styles[style];
|
|
1065
|
+
});
|
|
1066
|
+
getClasses(dz).forEach(function(c) {
|
|
1067
|
+
return dz.classList.add(c);
|
|
1068
|
+
});
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* will remove the 'active' styling from given dropzones
|
|
1073
|
+
* @param {Array<HTMLElement>} dropZones
|
|
1074
|
+
* @param {Function} getStyles - maps a dropzone to a styles object
|
|
1075
|
+
* @param {Function} getClasses - maps a dropzone to a classList
|
|
1076
|
+
*/
|
|
1077
|
+
function styleInactiveDropZones(dropZones) {
|
|
1078
|
+
var getStyles = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : function() {};
|
|
1079
|
+
var getClasses = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : function() {
|
|
1080
|
+
return [];
|
|
1081
|
+
};
|
|
1082
|
+
dropZones.forEach(function(dz) {
|
|
1083
|
+
var styles = getStyles(dz);
|
|
1084
|
+
Object.keys(styles).forEach(function(style) {
|
|
1085
|
+
dz.style[style] = "";
|
|
1086
|
+
});
|
|
1087
|
+
getClasses(dz).forEach(function(c) {
|
|
1088
|
+
return dz.classList.contains(c) && dz.classList.remove(c);
|
|
1089
|
+
});
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* will prevent the provided element from shrinking by setting its minWidth and minHeight to the current width and height values
|
|
1094
|
+
* @param {HTMLElement} el
|
|
1095
|
+
* @return {function(): void} - run this function to undo the operation and restore the original values
|
|
1096
|
+
*/
|
|
1097
|
+
function preventShrinking(el) {
|
|
1098
|
+
var originalMinHeight = el.style.minHeight;
|
|
1099
|
+
el.style.minHeight = window.getComputedStyle(el).getPropertyValue("height");
|
|
1100
|
+
var originalMinWidth = el.style.minWidth;
|
|
1101
|
+
el.style.minWidth = window.getComputedStyle(el).getPropertyValue("width");
|
|
1102
|
+
return function undo() {
|
|
1103
|
+
el.style.minHeight = originalMinHeight;
|
|
1104
|
+
el.style.minWidth = originalMinWidth;
|
|
1105
|
+
};
|
|
1106
|
+
}
|
|
1107
|
+
var DEFAULT_DROP_ZONE_TYPE$1 = "--any--";
|
|
1108
|
+
var MIN_OBSERVATION_INTERVAL_MS = 100;
|
|
1109
|
+
var DISABLED_OBSERVATION_INTERVAL_MS = 20;
|
|
1110
|
+
var MIN_MOVEMENT_BEFORE_DRAG_START_PX = 3;
|
|
1111
|
+
var DEFAULT_TOUCH_DELAY_MS = 80;
|
|
1112
|
+
var DEFAULT_DROP_TARGET_STYLE$1 = { outline: "rgba(255, 255, 102, 0.7) solid 2px" };
|
|
1113
|
+
var ORIGINAL_DRAGGED_ITEM_MARKER_ATTRIBUTE = "data-is-dnd-original-dragged-item";
|
|
1114
|
+
var originalDragTarget;
|
|
1115
|
+
var draggedEl;
|
|
1116
|
+
var draggedElData;
|
|
1117
|
+
var draggedElType;
|
|
1118
|
+
var originDropZone;
|
|
1119
|
+
var originIndex;
|
|
1120
|
+
var shadowElData;
|
|
1121
|
+
var shadowElDropZone;
|
|
1122
|
+
var dragStartMousePosition;
|
|
1123
|
+
var currentMousePosition;
|
|
1124
|
+
var isWorkingOnPreviousDrag = false;
|
|
1125
|
+
var finalizingPreviousDrag = false;
|
|
1126
|
+
var unlockOriginDzMinDimensions;
|
|
1127
|
+
var isDraggedOutsideOfAnyDz = false;
|
|
1128
|
+
var scheduledForRemovalAfterDrop = [];
|
|
1129
|
+
var multiScroller;
|
|
1130
|
+
var touchDragHoldTimer;
|
|
1131
|
+
var touchHoldElapsed = false;
|
|
1132
|
+
var useCursorForDetectionActive = false;
|
|
1133
|
+
var typeToDropZones$1 = /* @__PURE__ */ new Map();
|
|
1134
|
+
var dzToConfig$1 = /* @__PURE__ */ new Map();
|
|
1135
|
+
var elToMouseDownListener = /* @__PURE__ */ new WeakMap();
|
|
1136
|
+
function registerDropZone$1(dropZoneEl, type) {
|
|
1137
|
+
if (!typeToDropZones$1.has(type)) typeToDropZones$1.set(type, /* @__PURE__ */ new Set());
|
|
1138
|
+
if (!typeToDropZones$1.get(type).has(dropZoneEl)) {
|
|
1139
|
+
typeToDropZones$1.get(type).add(dropZoneEl);
|
|
1140
|
+
incrementActiveDropZoneCount();
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
function unregisterDropZone$1(dropZoneEl, type) {
|
|
1144
|
+
typeToDropZones$1.get(type)["delete"](dropZoneEl);
|
|
1145
|
+
decrementActiveDropZoneCount();
|
|
1146
|
+
if (typeToDropZones$1.get(type).size === 0) typeToDropZones$1["delete"](type);
|
|
1147
|
+
}
|
|
1148
|
+
function watchDraggedElement() {
|
|
1149
|
+
var dropZones = typeToDropZones$1.get(draggedElType);
|
|
1150
|
+
var _iterator = _createForOfIteratorHelper(dropZones), _step;
|
|
1151
|
+
try {
|
|
1152
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1153
|
+
var dz = _step.value;
|
|
1154
|
+
dz.addEventListener(DRAGGED_ENTERED_EVENT_NAME, handleDraggedEntered);
|
|
1155
|
+
dz.addEventListener(DRAGGED_LEFT_EVENT_NAME, handleDraggedLeft);
|
|
1156
|
+
dz.addEventListener(DRAGGED_OVER_INDEX_EVENT_NAME, handleDraggedIsOverIndex);
|
|
1157
|
+
}
|
|
1158
|
+
} catch (err) {
|
|
1159
|
+
_iterator.e(err);
|
|
1160
|
+
} finally {
|
|
1161
|
+
_iterator.f();
|
|
1162
|
+
}
|
|
1163
|
+
window.addEventListener(DRAGGED_LEFT_DOCUMENT_EVENT_NAME, handleDrop$1);
|
|
1164
|
+
var setIntervalMs = Math.max.apply(Math, _toConsumableArray(Array.from(dropZones.keys()).map(function(dz) {
|
|
1165
|
+
return dzToConfig$1.get(dz).dropAnimationDurationMs;
|
|
1166
|
+
})));
|
|
1167
|
+
var observationIntervalMs = setIntervalMs === 0 ? DISABLED_OBSERVATION_INTERVAL_MS : Math.max(setIntervalMs, MIN_OBSERVATION_INTERVAL_MS);
|
|
1168
|
+
multiScroller = createMultiScroller(dropZones, function() {
|
|
1169
|
+
return currentMousePosition;
|
|
1170
|
+
});
|
|
1171
|
+
var getReferencePoint = useCursorForDetectionActive ? function() {
|
|
1172
|
+
return {
|
|
1173
|
+
x: currentMousePosition.x + window.scrollX,
|
|
1174
|
+
y: currentMousePosition.y + window.scrollY
|
|
1175
|
+
};
|
|
1176
|
+
} : function() {
|
|
1177
|
+
return findCenterOfElement(draggedEl);
|
|
1178
|
+
};
|
|
1179
|
+
observe(draggedEl, dropZones, observationIntervalMs * 1.07, multiScroller, getReferencePoint);
|
|
1180
|
+
}
|
|
1181
|
+
function unWatchDraggedElement() {
|
|
1182
|
+
var _iterator2 = _createForOfIteratorHelper(typeToDropZones$1.get(draggedElType)), _step2;
|
|
1183
|
+
try {
|
|
1184
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
1185
|
+
var dz = _step2.value;
|
|
1186
|
+
dz.removeEventListener(DRAGGED_ENTERED_EVENT_NAME, handleDraggedEntered);
|
|
1187
|
+
dz.removeEventListener(DRAGGED_LEFT_EVENT_NAME, handleDraggedLeft);
|
|
1188
|
+
dz.removeEventListener(DRAGGED_OVER_INDEX_EVENT_NAME, handleDraggedIsOverIndex);
|
|
1189
|
+
}
|
|
1190
|
+
} catch (err) {
|
|
1191
|
+
_iterator2.e(err);
|
|
1192
|
+
} finally {
|
|
1193
|
+
_iterator2.f();
|
|
1194
|
+
}
|
|
1195
|
+
window.removeEventListener(DRAGGED_LEFT_DOCUMENT_EVENT_NAME, handleDrop$1);
|
|
1196
|
+
if (multiScroller) {
|
|
1197
|
+
multiScroller.destroy();
|
|
1198
|
+
multiScroller = void 0;
|
|
1199
|
+
}
|
|
1200
|
+
unobserve();
|
|
1201
|
+
}
|
|
1202
|
+
function findShadowElementIdx(items) {
|
|
1203
|
+
return items.findIndex(function(item) {
|
|
1204
|
+
return !!item[SHADOW_ITEM_MARKER_PROPERTY_NAME];
|
|
1205
|
+
});
|
|
1206
|
+
}
|
|
1207
|
+
function createShadowElData(draggedElData) {
|
|
1208
|
+
var _objectSpread2$1;
|
|
1209
|
+
return _objectSpread2(_objectSpread2({}, draggedElData), {}, (_objectSpread2$1 = {}, _defineProperty(_objectSpread2$1, SHADOW_ITEM_MARKER_PROPERTY_NAME, true), _defineProperty(_objectSpread2$1, ITEM_ID_KEY, SHADOW_PLACEHOLDER_ITEM_ID), _objectSpread2$1));
|
|
1210
|
+
}
|
|
1211
|
+
function handleDraggedEntered(e) {
|
|
1212
|
+
var _dzToConfig$get = dzToConfig$1.get(e.currentTarget), items = _dzToConfig$get.items;
|
|
1213
|
+
if (_dzToConfig$get.dropFromOthersDisabled && e.currentTarget !== originDropZone) return;
|
|
1214
|
+
isDraggedOutsideOfAnyDz = false;
|
|
1215
|
+
items = items.filter(function(item) {
|
|
1216
|
+
return item[ITEM_ID_KEY] !== shadowElData[ITEM_ID_KEY] && item[ITEM_ID_KEY] !== "id:dnd-shadow-placeholder-0000";
|
|
1217
|
+
});
|
|
1218
|
+
if (originDropZone !== e.currentTarget) {
|
|
1219
|
+
var newOriginZoneItems = dzToConfig$1.get(originDropZone).items.filter(function(item) {
|
|
1220
|
+
return !item[SHADOW_ITEM_MARKER_PROPERTY_NAME];
|
|
1221
|
+
});
|
|
1222
|
+
dispatchConsiderEvent(originDropZone, newOriginZoneItems, {
|
|
1223
|
+
trigger: TRIGGERS.DRAGGED_ENTERED_ANOTHER,
|
|
1224
|
+
id: draggedElData[ITEM_ID_KEY],
|
|
1225
|
+
source: SOURCES.POINTER
|
|
1226
|
+
});
|
|
1227
|
+
}
|
|
1228
|
+
var shadowElIdx = e.detail.indexObj.index;
|
|
1229
|
+
shadowElDropZone = e.currentTarget;
|
|
1230
|
+
items.splice(shadowElIdx, 0, shadowElData);
|
|
1231
|
+
dispatchConsiderEvent(e.currentTarget, items, {
|
|
1232
|
+
trigger: TRIGGERS.DRAGGED_ENTERED,
|
|
1233
|
+
id: draggedElData[ITEM_ID_KEY],
|
|
1234
|
+
source: SOURCES.POINTER
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
function handleDraggedLeft(e) {
|
|
1238
|
+
if (!isWorkingOnPreviousDrag) return;
|
|
1239
|
+
var _dzToConfig$get2 = dzToConfig$1.get(e.currentTarget), originalItems = _dzToConfig$get2.items;
|
|
1240
|
+
if (_dzToConfig$get2.dropFromOthersDisabled && e.currentTarget !== originDropZone && e.currentTarget !== shadowElDropZone) return;
|
|
1241
|
+
var items = _toConsumableArray(originalItems);
|
|
1242
|
+
var shadowElIdx = findShadowElementIdx(items);
|
|
1243
|
+
if (shadowElIdx !== -1) items.splice(shadowElIdx, 1);
|
|
1244
|
+
var origShadowDz = shadowElDropZone;
|
|
1245
|
+
shadowElDropZone = void 0;
|
|
1246
|
+
var _e$detail = e.detail, type = _e$detail.type, theOtherDz = _e$detail.theOtherDz;
|
|
1247
|
+
if (type === DRAGGED_LEFT_TYPES.OUTSIDE_OF_ANY || type === DRAGGED_LEFT_TYPES.LEFT_FOR_ANOTHER && theOtherDz !== originDropZone && dzToConfig$1.get(theOtherDz).dropFromOthersDisabled) {
|
|
1248
|
+
isDraggedOutsideOfAnyDz = true;
|
|
1249
|
+
shadowElDropZone = originDropZone;
|
|
1250
|
+
var originZoneItems = origShadowDz === originDropZone ? items : _toConsumableArray(dzToConfig$1.get(originDropZone).items);
|
|
1251
|
+
originZoneItems.splice(originIndex, 0, shadowElData);
|
|
1252
|
+
dispatchConsiderEvent(originDropZone, originZoneItems, {
|
|
1253
|
+
trigger: TRIGGERS.DRAGGED_LEFT_ALL,
|
|
1254
|
+
id: draggedElData[ITEM_ID_KEY],
|
|
1255
|
+
source: SOURCES.POINTER
|
|
1256
|
+
});
|
|
1257
|
+
}
|
|
1258
|
+
dispatchConsiderEvent(e.currentTarget, items, {
|
|
1259
|
+
trigger: TRIGGERS.DRAGGED_LEFT,
|
|
1260
|
+
id: draggedElData[ITEM_ID_KEY],
|
|
1261
|
+
source: SOURCES.POINTER
|
|
1262
|
+
});
|
|
1263
|
+
}
|
|
1264
|
+
function handleDraggedIsOverIndex(e) {
|
|
1265
|
+
var _dzToConfig$get3 = dzToConfig$1.get(e.currentTarget), originalItems = _dzToConfig$get3.items;
|
|
1266
|
+
if (_dzToConfig$get3.dropFromOthersDisabled && e.currentTarget !== originDropZone) return;
|
|
1267
|
+
var items = _toConsumableArray(originalItems);
|
|
1268
|
+
isDraggedOutsideOfAnyDz = false;
|
|
1269
|
+
var index = e.detail.indexObj.index;
|
|
1270
|
+
var shadowElIdx = findShadowElementIdx(items);
|
|
1271
|
+
if (shadowElIdx !== -1) items.splice(shadowElIdx, 1);
|
|
1272
|
+
items.splice(index, 0, shadowElData);
|
|
1273
|
+
dispatchConsiderEvent(e.currentTarget, items, {
|
|
1274
|
+
trigger: TRIGGERS.DRAGGED_OVER_INDEX,
|
|
1275
|
+
id: draggedElData[ITEM_ID_KEY],
|
|
1276
|
+
source: SOURCES.POINTER
|
|
1277
|
+
});
|
|
1278
|
+
}
|
|
1279
|
+
function handleMouseMove(e) {
|
|
1280
|
+
e.preventDefault();
|
|
1281
|
+
var c = e.touches ? e.touches[0] : e;
|
|
1282
|
+
currentMousePosition = {
|
|
1283
|
+
x: c.clientX,
|
|
1284
|
+
y: c.clientY
|
|
1285
|
+
};
|
|
1286
|
+
draggedEl.style.transform = "translate3d(".concat(currentMousePosition.x - dragStartMousePosition.x, "px, ").concat(currentMousePosition.y - dragStartMousePosition.y, "px, 0)");
|
|
1287
|
+
}
|
|
1288
|
+
function handleDrop$1() {
|
|
1289
|
+
finalizingPreviousDrag = true;
|
|
1290
|
+
window.removeEventListener("mousemove", handleMouseMove);
|
|
1291
|
+
window.removeEventListener("touchmove", handleMouseMove);
|
|
1292
|
+
window.removeEventListener("mouseup", handleDrop$1);
|
|
1293
|
+
window.removeEventListener("touchend", handleDrop$1);
|
|
1294
|
+
unWatchDraggedElement();
|
|
1295
|
+
moveDraggedElementToWasDroppedState(draggedEl);
|
|
1296
|
+
if (!shadowElDropZone) shadowElDropZone = originDropZone;
|
|
1297
|
+
var _dzToConfig$get4 = dzToConfig$1.get(shadowElDropZone), items = _dzToConfig$get4.items, type = _dzToConfig$get4.type;
|
|
1298
|
+
styleInactiveDropZones(typeToDropZones$1.get(type), function(dz) {
|
|
1299
|
+
return dzToConfig$1.get(dz).dropTargetStyle;
|
|
1300
|
+
}, function(dz) {
|
|
1301
|
+
return dzToConfig$1.get(dz).dropTargetClasses;
|
|
1302
|
+
});
|
|
1303
|
+
var shadowElIdx = findShadowElementIdx(items);
|
|
1304
|
+
if (shadowElIdx === -1) {
|
|
1305
|
+
if (shadowElDropZone === originDropZone) shadowElIdx = originIndex;
|
|
1306
|
+
}
|
|
1307
|
+
items = items.map(function(item) {
|
|
1308
|
+
return item["isDndShadowItem"] ? draggedElData : item;
|
|
1309
|
+
});
|
|
1310
|
+
function finalizeWithinZone() {
|
|
1311
|
+
unlockOriginDzMinDimensions();
|
|
1312
|
+
dispatchFinalizeEvent(shadowElDropZone, items, {
|
|
1313
|
+
trigger: isDraggedOutsideOfAnyDz ? TRIGGERS.DROPPED_OUTSIDE_OF_ANY : TRIGGERS.DROPPED_INTO_ZONE,
|
|
1314
|
+
id: draggedElData[ITEM_ID_KEY],
|
|
1315
|
+
source: SOURCES.POINTER
|
|
1316
|
+
});
|
|
1317
|
+
if (shadowElDropZone !== originDropZone) dispatchFinalizeEvent(originDropZone, dzToConfig$1.get(originDropZone).items, {
|
|
1318
|
+
trigger: TRIGGERS.DROPPED_INTO_ANOTHER,
|
|
1319
|
+
id: draggedElData[ITEM_ID_KEY],
|
|
1320
|
+
source: SOURCES.POINTER
|
|
1321
|
+
});
|
|
1322
|
+
var domShadowEl = Array.from(shadowElDropZone.children).find(function(c) {
|
|
1323
|
+
return c.getAttribute(SHADOW_ELEMENT_ATTRIBUTE_NAME);
|
|
1324
|
+
});
|
|
1325
|
+
if (domShadowEl) unDecorateShadowElement(domShadowEl);
|
|
1326
|
+
cleanupPostDrop();
|
|
1327
|
+
}
|
|
1328
|
+
if (dzToConfig$1.get(shadowElDropZone).dropAnimationDisabled) finalizeWithinZone();
|
|
1329
|
+
else animateDraggedToFinalPosition(shadowElIdx, finalizeWithinZone);
|
|
1330
|
+
}
|
|
1331
|
+
function animateDraggedToFinalPosition(shadowElIdx, callback) {
|
|
1332
|
+
var shadowElRect = shadowElIdx > -1 ? getBoundingRectNoTransforms(shadowElDropZone.children[shadowElIdx], false) : getBoundingRectNoTransforms(shadowElDropZone, false);
|
|
1333
|
+
var newTransform = {
|
|
1334
|
+
x: shadowElRect.left - parseFloat(draggedEl.style.left),
|
|
1335
|
+
y: shadowElRect.top - parseFloat(draggedEl.style.top)
|
|
1336
|
+
};
|
|
1337
|
+
var dropAnimationDurationMs = dzToConfig$1.get(shadowElDropZone).dropAnimationDurationMs;
|
|
1338
|
+
var transition = "transform ".concat(dropAnimationDurationMs, "ms ease");
|
|
1339
|
+
draggedEl.style.transition = draggedEl.style.transition ? draggedEl.style.transition + "," + transition : transition;
|
|
1340
|
+
draggedEl.style.transform = "translate3d(".concat(newTransform.x, "px, ").concat(newTransform.y, "px, 0)");
|
|
1341
|
+
window.setTimeout(callback, dropAnimationDurationMs);
|
|
1342
|
+
}
|
|
1343
|
+
function scheduleDZForRemovalAfterDrop(dz, destroy) {
|
|
1344
|
+
scheduledForRemovalAfterDrop.push({
|
|
1345
|
+
dz,
|
|
1346
|
+
destroy
|
|
1347
|
+
});
|
|
1348
|
+
window.requestAnimationFrame(function() {
|
|
1349
|
+
hideElement(dz);
|
|
1350
|
+
document.body.appendChild(dz);
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
function cleanupPostDrop() {
|
|
1354
|
+
if (draggedEl && draggedEl.remove) draggedEl.remove();
|
|
1355
|
+
if (originalDragTarget && originalDragTarget.remove) originalDragTarget.remove();
|
|
1356
|
+
draggedEl = void 0;
|
|
1357
|
+
originalDragTarget = void 0;
|
|
1358
|
+
draggedElData = void 0;
|
|
1359
|
+
draggedElType = void 0;
|
|
1360
|
+
originDropZone = void 0;
|
|
1361
|
+
originIndex = void 0;
|
|
1362
|
+
shadowElData = void 0;
|
|
1363
|
+
shadowElDropZone = void 0;
|
|
1364
|
+
dragStartMousePosition = void 0;
|
|
1365
|
+
currentMousePosition = void 0;
|
|
1366
|
+
isWorkingOnPreviousDrag = false;
|
|
1367
|
+
finalizingPreviousDrag = false;
|
|
1368
|
+
unlockOriginDzMinDimensions = void 0;
|
|
1369
|
+
isDraggedOutsideOfAnyDz = false;
|
|
1370
|
+
if (touchDragHoldTimer) clearTimeout(touchDragHoldTimer);
|
|
1371
|
+
touchDragHoldTimer = void 0;
|
|
1372
|
+
touchHoldElapsed = false;
|
|
1373
|
+
useCursorForDetectionActive = false;
|
|
1374
|
+
if (scheduledForRemovalAfterDrop.length) {
|
|
1375
|
+
scheduledForRemovalAfterDrop.forEach(function(_ref) {
|
|
1376
|
+
var dz = _ref.dz, destroy = _ref.destroy;
|
|
1377
|
+
destroy();
|
|
1378
|
+
dz.remove();
|
|
1379
|
+
});
|
|
1380
|
+
scheduledForRemovalAfterDrop = [];
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
function dndzone$2(node, options) {
|
|
1384
|
+
var initialized = false;
|
|
1385
|
+
var config = {
|
|
1386
|
+
items: void 0,
|
|
1387
|
+
type: void 0,
|
|
1388
|
+
flipDurationMs: 0,
|
|
1389
|
+
dragDisabled: false,
|
|
1390
|
+
morphDisabled: false,
|
|
1391
|
+
dropFromOthersDisabled: false,
|
|
1392
|
+
dropTargetStyle: DEFAULT_DROP_TARGET_STYLE$1,
|
|
1393
|
+
dropTargetClasses: [],
|
|
1394
|
+
transformDraggedElement: function transformDraggedElement() {},
|
|
1395
|
+
centreDraggedOnCursor: false,
|
|
1396
|
+
useCursorForDetection: false,
|
|
1397
|
+
dropAnimationDisabled: false,
|
|
1398
|
+
delayTouchStartMs: 0
|
|
1399
|
+
};
|
|
1400
|
+
var elToIdx = /* @__PURE__ */ new Map();
|
|
1401
|
+
function addMaybeListeners() {
|
|
1402
|
+
window.addEventListener("mousemove", handleMouseMoveMaybeDragStart, { passive: false });
|
|
1403
|
+
window.addEventListener("touchmove", handleMouseMoveMaybeDragStart, {
|
|
1404
|
+
passive: false,
|
|
1405
|
+
capture: false
|
|
1406
|
+
});
|
|
1407
|
+
window.addEventListener("mouseup", handleFalseAlarm, { passive: false });
|
|
1408
|
+
window.addEventListener("touchend", handleFalseAlarm, { passive: false });
|
|
1409
|
+
}
|
|
1410
|
+
function removeMaybeListeners() {
|
|
1411
|
+
window.removeEventListener("mousemove", handleMouseMoveMaybeDragStart);
|
|
1412
|
+
window.removeEventListener("touchmove", handleMouseMoveMaybeDragStart);
|
|
1413
|
+
window.removeEventListener("mouseup", handleFalseAlarm);
|
|
1414
|
+
window.removeEventListener("touchend", handleFalseAlarm);
|
|
1415
|
+
if (touchDragHoldTimer) {
|
|
1416
|
+
clearTimeout(touchDragHoldTimer);
|
|
1417
|
+
touchDragHoldTimer = void 0;
|
|
1418
|
+
touchHoldElapsed = false;
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
function handleFalseAlarm(e) {
|
|
1422
|
+
removeMaybeListeners();
|
|
1423
|
+
originalDragTarget = void 0;
|
|
1424
|
+
dragStartMousePosition = void 0;
|
|
1425
|
+
currentMousePosition = void 0;
|
|
1426
|
+
if (e.type === "touchend") {
|
|
1427
|
+
var clickEvent = new Event("click", {
|
|
1428
|
+
bubbles: true,
|
|
1429
|
+
cancelable: true
|
|
1430
|
+
});
|
|
1431
|
+
e.target.dispatchEvent(clickEvent);
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
function handleMouseMoveMaybeDragStart(e) {
|
|
1435
|
+
var isTouch = !!e.touches;
|
|
1436
|
+
var c = isTouch ? e.touches[0] : e;
|
|
1437
|
+
if (isTouch && config.delayTouchStartMs > 0 && !touchHoldElapsed) {
|
|
1438
|
+
currentMousePosition = {
|
|
1439
|
+
x: c.clientX,
|
|
1440
|
+
y: c.clientY
|
|
1441
|
+
};
|
|
1442
|
+
if (Math.abs(currentMousePosition.x - dragStartMousePosition.x) >= MIN_MOVEMENT_BEFORE_DRAG_START_PX || Math.abs(currentMousePosition.y - dragStartMousePosition.y) >= MIN_MOVEMENT_BEFORE_DRAG_START_PX) {
|
|
1443
|
+
if (touchDragHoldTimer) {
|
|
1444
|
+
clearTimeout(touchDragHoldTimer);
|
|
1445
|
+
touchDragHoldTimer = void 0;
|
|
1446
|
+
}
|
|
1447
|
+
handleFalseAlarm(e);
|
|
1448
|
+
}
|
|
1449
|
+
return;
|
|
1450
|
+
}
|
|
1451
|
+
e.preventDefault();
|
|
1452
|
+
currentMousePosition = {
|
|
1453
|
+
x: c.clientX,
|
|
1454
|
+
y: c.clientY
|
|
1455
|
+
};
|
|
1456
|
+
if (Math.abs(currentMousePosition.x - dragStartMousePosition.x) >= MIN_MOVEMENT_BEFORE_DRAG_START_PX || Math.abs(currentMousePosition.y - dragStartMousePosition.y) >= MIN_MOVEMENT_BEFORE_DRAG_START_PX) {
|
|
1457
|
+
removeMaybeListeners();
|
|
1458
|
+
handleDragStart();
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
function handleMouseDown(e) {
|
|
1462
|
+
if (e.target !== e.currentTarget && (e.target.value !== void 0 || e.target.isContentEditable)) return;
|
|
1463
|
+
if (e.button) return;
|
|
1464
|
+
if (isWorkingOnPreviousDrag) return;
|
|
1465
|
+
var isTouchStart = !!e.touches;
|
|
1466
|
+
var useDelay = isTouchStart && config.delayTouchStartMs > 0;
|
|
1467
|
+
if (!useDelay) e.preventDefault();
|
|
1468
|
+
e.stopPropagation();
|
|
1469
|
+
var c = isTouchStart ? e.touches[0] : e;
|
|
1470
|
+
dragStartMousePosition = {
|
|
1471
|
+
x: c.clientX,
|
|
1472
|
+
y: c.clientY
|
|
1473
|
+
};
|
|
1474
|
+
currentMousePosition = _objectSpread2({}, dragStartMousePosition);
|
|
1475
|
+
originalDragTarget = e.currentTarget;
|
|
1476
|
+
if (useDelay) {
|
|
1477
|
+
touchHoldElapsed = false;
|
|
1478
|
+
touchDragHoldTimer = window.setTimeout(function() {
|
|
1479
|
+
if (!originalDragTarget) return;
|
|
1480
|
+
touchHoldElapsed = true;
|
|
1481
|
+
removeMaybeListeners();
|
|
1482
|
+
handleDragStart();
|
|
1483
|
+
}, config.delayTouchStartMs);
|
|
1484
|
+
}
|
|
1485
|
+
addMaybeListeners();
|
|
1486
|
+
}
|
|
1487
|
+
function handleDragStart() {
|
|
1488
|
+
isWorkingOnPreviousDrag = true;
|
|
1489
|
+
var currentIdx = elToIdx.get(originalDragTarget);
|
|
1490
|
+
originIndex = currentIdx;
|
|
1491
|
+
originDropZone = originalDragTarget.parentElement;
|
|
1492
|
+
/** @type {ShadowRoot | HTMLDocument | Element } */
|
|
1493
|
+
var rootNode = originDropZone.closest("dialog") || originDropZone.closest("[popover]") || originDropZone.getRootNode();
|
|
1494
|
+
var originDropZoneRoot = rootNode.body || rootNode;
|
|
1495
|
+
var originalItems = config.items, type = config.type, centreDraggedOnCursor = config.centreDraggedOnCursor, useCursorForDetection = config.useCursorForDetection;
|
|
1496
|
+
var items = _toConsumableArray(originalItems);
|
|
1497
|
+
draggedElData = items[currentIdx];
|
|
1498
|
+
draggedElType = type;
|
|
1499
|
+
shadowElData = createShadowElData(draggedElData);
|
|
1500
|
+
useCursorForDetectionActive = useCursorForDetection;
|
|
1501
|
+
draggedEl = createDraggedElementFrom(originalDragTarget, centreDraggedOnCursor && currentMousePosition);
|
|
1502
|
+
originDropZoneRoot.appendChild(draggedEl);
|
|
1503
|
+
function keepOriginalElementInDom() {
|
|
1504
|
+
if (!draggedEl) return;
|
|
1505
|
+
if (!originalDragTarget.parentElement) {
|
|
1506
|
+
originalDragTarget.setAttribute(ORIGINAL_DRAGGED_ITEM_MARKER_ATTRIBUTE, true);
|
|
1507
|
+
originDropZoneRoot.appendChild(originalDragTarget);
|
|
1508
|
+
watchDraggedElement();
|
|
1509
|
+
hideElement(originalDragTarget);
|
|
1510
|
+
shadowElData[ITEM_ID_KEY] = draggedElData[ITEM_ID_KEY];
|
|
1511
|
+
draggedEl.focus();
|
|
1512
|
+
} else window.requestAnimationFrame(keepOriginalElementInDom);
|
|
1513
|
+
}
|
|
1514
|
+
window.requestAnimationFrame(keepOriginalElementInDom);
|
|
1515
|
+
styleActiveDropZones(Array.from(typeToDropZones$1.get(config.type)).filter(function(dz) {
|
|
1516
|
+
return dz === originDropZone || !dzToConfig$1.get(dz).dropFromOthersDisabled;
|
|
1517
|
+
}), function(dz) {
|
|
1518
|
+
return dzToConfig$1.get(dz).dropTargetStyle;
|
|
1519
|
+
}, function(dz) {
|
|
1520
|
+
return dzToConfig$1.get(dz).dropTargetClasses;
|
|
1521
|
+
});
|
|
1522
|
+
items.splice(currentIdx, 1, shadowElData);
|
|
1523
|
+
unlockOriginDzMinDimensions = preventShrinking(originDropZone);
|
|
1524
|
+
dispatchConsiderEvent(originDropZone, items, {
|
|
1525
|
+
trigger: TRIGGERS.DRAG_STARTED,
|
|
1526
|
+
id: draggedElData[ITEM_ID_KEY],
|
|
1527
|
+
source: SOURCES.POINTER
|
|
1528
|
+
});
|
|
1529
|
+
window.addEventListener("mousemove", handleMouseMove, { passive: false });
|
|
1530
|
+
window.addEventListener("touchmove", handleMouseMove, {
|
|
1531
|
+
passive: false,
|
|
1532
|
+
capture: false
|
|
1533
|
+
});
|
|
1534
|
+
window.addEventListener("mouseup", handleDrop$1, { passive: false });
|
|
1535
|
+
window.addEventListener("touchend", handleDrop$1, { passive: false });
|
|
1536
|
+
}
|
|
1537
|
+
function configure(_ref2) {
|
|
1538
|
+
var _ref2$items = _ref2.items, items = _ref2$items === void 0 ? void 0 : _ref2$items, _ref2$flipDurationMs = _ref2.flipDurationMs, dropAnimationDurationMs = _ref2$flipDurationMs === void 0 ? 0 : _ref2$flipDurationMs, _ref2$type = _ref2.type, newType = _ref2$type === void 0 ? DEFAULT_DROP_ZONE_TYPE$1 : _ref2$type, _ref2$dragDisabled = _ref2.dragDisabled, dragDisabled = _ref2$dragDisabled === void 0 ? false : _ref2$dragDisabled, _ref2$morphDisabled = _ref2.morphDisabled, morphDisabled = _ref2$morphDisabled === void 0 ? false : _ref2$morphDisabled, _ref2$dropFromOthersD = _ref2.dropFromOthersDisabled, dropFromOthersDisabled = _ref2$dropFromOthersD === void 0 ? false : _ref2$dropFromOthersD, _ref2$dropTargetStyle = _ref2.dropTargetStyle, dropTargetStyle = _ref2$dropTargetStyle === void 0 ? DEFAULT_DROP_TARGET_STYLE$1 : _ref2$dropTargetStyle, _ref2$dropTargetClass = _ref2.dropTargetClasses, dropTargetClasses = _ref2$dropTargetClass === void 0 ? [] : _ref2$dropTargetClass, _ref2$transformDragge = _ref2.transformDraggedElement, transformDraggedElement = _ref2$transformDragge === void 0 ? function() {} : _ref2$transformDragge, _ref2$centreDraggedOn = _ref2.centreDraggedOnCursor, centreDraggedOnCursor = _ref2$centreDraggedOn === void 0 ? false : _ref2$centreDraggedOn, _ref2$useCursorForDet = _ref2.useCursorForDetection, useCursorForDetection = _ref2$useCursorForDet === void 0 ? false : _ref2$useCursorForDet, _ref2$dropAnimationDi = _ref2.dropAnimationDisabled, dropAnimationDisabled = _ref2$dropAnimationDi === void 0 ? false : _ref2$dropAnimationDi, _ref2$delayTouchStart = _ref2.delayTouchStart, delayTouchStartOpt = _ref2$delayTouchStart === void 0 ? false : _ref2$delayTouchStart;
|
|
1539
|
+
config.dropAnimationDurationMs = dropAnimationDurationMs;
|
|
1540
|
+
var effectiveDelayMs = 0;
|
|
1541
|
+
if (delayTouchStartOpt === true) effectiveDelayMs = DEFAULT_TOUCH_DELAY_MS;
|
|
1542
|
+
else if (typeof delayTouchStartOpt === "number" && isFinite(delayTouchStartOpt) && delayTouchStartOpt >= 0) effectiveDelayMs = delayTouchStartOpt;
|
|
1543
|
+
config.delayTouchStartMs = effectiveDelayMs;
|
|
1544
|
+
if (config.type && newType !== config.type) unregisterDropZone$1(node, config.type);
|
|
1545
|
+
config.type = newType;
|
|
1546
|
+
config.items = _toConsumableArray(items);
|
|
1547
|
+
config.dragDisabled = dragDisabled;
|
|
1548
|
+
config.morphDisabled = morphDisabled;
|
|
1549
|
+
config.transformDraggedElement = transformDraggedElement;
|
|
1550
|
+
config.centreDraggedOnCursor = centreDraggedOnCursor;
|
|
1551
|
+
config.useCursorForDetection = useCursorForDetection;
|
|
1552
|
+
config.dropAnimationDisabled = dropAnimationDisabled;
|
|
1553
|
+
if (initialized && isWorkingOnPreviousDrag && !finalizingPreviousDrag && (!areObjectsShallowEqual(dropTargetStyle, config.dropTargetStyle) || !areArraysShallowEqualSameOrder(dropTargetClasses, config.dropTargetClasses))) {
|
|
1554
|
+
styleInactiveDropZones([node], function() {
|
|
1555
|
+
return config.dropTargetStyle;
|
|
1556
|
+
}, function() {
|
|
1557
|
+
return dropTargetClasses;
|
|
1558
|
+
});
|
|
1559
|
+
styleActiveDropZones([node], function() {
|
|
1560
|
+
return dropTargetStyle;
|
|
1561
|
+
}, function() {
|
|
1562
|
+
return dropTargetClasses;
|
|
1563
|
+
});
|
|
1564
|
+
}
|
|
1565
|
+
config.dropTargetStyle = dropTargetStyle;
|
|
1566
|
+
config.dropTargetClasses = _toConsumableArray(dropTargetClasses);
|
|
1567
|
+
function getConfigProp(dz, propName) {
|
|
1568
|
+
return dzToConfig$1.get(dz) ? dzToConfig$1.get(dz)[propName] : config[propName];
|
|
1569
|
+
}
|
|
1570
|
+
if (initialized && isWorkingOnPreviousDrag && config.dropFromOthersDisabled !== dropFromOthersDisabled) if (dropFromOthersDisabled) styleInactiveDropZones([node], function(dz) {
|
|
1571
|
+
return getConfigProp(dz, "dropTargetStyle");
|
|
1572
|
+
}, function(dz) {
|
|
1573
|
+
return getConfigProp(dz, "dropTargetClasses");
|
|
1574
|
+
});
|
|
1575
|
+
else styleActiveDropZones([node], function(dz) {
|
|
1576
|
+
return getConfigProp(dz, "dropTargetStyle");
|
|
1577
|
+
}, function(dz) {
|
|
1578
|
+
return getConfigProp(dz, "dropTargetClasses");
|
|
1579
|
+
});
|
|
1580
|
+
config.dropFromOthersDisabled = dropFromOthersDisabled;
|
|
1581
|
+
dzToConfig$1.set(node, config);
|
|
1582
|
+
registerDropZone$1(node, newType);
|
|
1583
|
+
var shadowElIdx = isWorkingOnPreviousDrag ? findShadowElementIdx(config.items) : -1;
|
|
1584
|
+
for (var idx = 0; idx < node.children.length; idx++) {
|
|
1585
|
+
var draggableEl = node.children[idx];
|
|
1586
|
+
styleDraggable(draggableEl, dragDisabled);
|
|
1587
|
+
if (idx === shadowElIdx) {
|
|
1588
|
+
if (!morphDisabled) morphDraggedElementToBeLike(draggedEl, draggableEl, currentMousePosition.x, currentMousePosition.y);
|
|
1589
|
+
config.transformDraggedElement(draggedEl, draggedElData, idx);
|
|
1590
|
+
decorateShadowEl(draggableEl);
|
|
1591
|
+
continue;
|
|
1592
|
+
}
|
|
1593
|
+
draggableEl.removeEventListener("mousedown", elToMouseDownListener.get(draggableEl));
|
|
1594
|
+
draggableEl.removeEventListener("touchstart", elToMouseDownListener.get(draggableEl));
|
|
1595
|
+
if (!dragDisabled) {
|
|
1596
|
+
draggableEl.addEventListener("mousedown", handleMouseDown);
|
|
1597
|
+
draggableEl.addEventListener("touchstart", handleMouseDown);
|
|
1598
|
+
elToMouseDownListener.set(draggableEl, handleMouseDown);
|
|
1599
|
+
}
|
|
1600
|
+
elToIdx.set(draggableEl, idx);
|
|
1601
|
+
if (!initialized) initialized = true;
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
configure(options);
|
|
1605
|
+
return {
|
|
1606
|
+
update: function update(newOptions) {
|
|
1607
|
+
configure(newOptions);
|
|
1608
|
+
},
|
|
1609
|
+
destroy: function destroy() {
|
|
1610
|
+
function destroyDz() {
|
|
1611
|
+
unregisterDropZone$1(node, dzToConfig$1.get(node).type);
|
|
1612
|
+
dzToConfig$1["delete"](node);
|
|
1613
|
+
}
|
|
1614
|
+
if (isWorkingOnPreviousDrag && !node.closest("[".concat(ORIGINAL_DRAGGED_ITEM_MARKER_ATTRIBUTE, "]"))) scheduleDZForRemovalAfterDrop(node, destroyDz);
|
|
1615
|
+
else destroyDz();
|
|
1616
|
+
}
|
|
1617
|
+
};
|
|
1618
|
+
}
|
|
1619
|
+
var _ID_TO_INSTRUCTION;
|
|
1620
|
+
var INSTRUCTION_IDs$1 = {
|
|
1621
|
+
DND_ZONE_ACTIVE: "dnd-zone-active",
|
|
1622
|
+
DND_ZONE_DRAG_DISABLED: "dnd-zone-drag-disabled"
|
|
1623
|
+
};
|
|
1624
|
+
var ID_TO_INSTRUCTION = (_ID_TO_INSTRUCTION = {}, _defineProperty(_ID_TO_INSTRUCTION, INSTRUCTION_IDs$1.DND_ZONE_ACTIVE, "Tab to one the items and press space-bar or enter to start dragging it"), _defineProperty(_ID_TO_INSTRUCTION, INSTRUCTION_IDs$1.DND_ZONE_DRAG_DISABLED, "This is a disabled drag and drop list"), _ID_TO_INSTRUCTION);
|
|
1625
|
+
var ALERT_DIV_ID = "dnd-action-aria-alert";
|
|
1626
|
+
var alertsDiv;
|
|
1627
|
+
function initAriaOnBrowser() {
|
|
1628
|
+
if (alertsDiv) return;
|
|
1629
|
+
alertsDiv = document.createElement("div");
|
|
1630
|
+
(function initAlertsDiv() {
|
|
1631
|
+
alertsDiv.id = ALERT_DIV_ID;
|
|
1632
|
+
alertsDiv.style.position = "fixed";
|
|
1633
|
+
alertsDiv.style.bottom = "0";
|
|
1634
|
+
alertsDiv.style.left = "0";
|
|
1635
|
+
alertsDiv.style.zIndex = "-5";
|
|
1636
|
+
alertsDiv.style.opacity = "0";
|
|
1637
|
+
alertsDiv.style.height = "0";
|
|
1638
|
+
alertsDiv.style.width = "0";
|
|
1639
|
+
alertsDiv.setAttribute("role", "alert");
|
|
1640
|
+
})();
|
|
1641
|
+
document.body.prepend(alertsDiv);
|
|
1642
|
+
Object.entries(ID_TO_INSTRUCTION).forEach(function(_ref) {
|
|
1643
|
+
var _ref2 = _slicedToArray(_ref, 2), id = _ref2[0], txt = _ref2[1];
|
|
1644
|
+
return document.body.prepend(instructionToHiddenDiv(id, txt));
|
|
1645
|
+
});
|
|
1646
|
+
}
|
|
1647
|
+
/**
|
|
1648
|
+
* Initializes the static aria instructions so they can be attached to zones
|
|
1649
|
+
* @return {{DND_ZONE_ACTIVE: string, DND_ZONE_DRAG_DISABLED: string} | null} - the IDs for static aria instruction (to be used via aria-describedby) or null on the server
|
|
1650
|
+
*/
|
|
1651
|
+
function initAria() {
|
|
1652
|
+
if (isOnServer) return null;
|
|
1653
|
+
if (document.readyState === "complete") initAriaOnBrowser();
|
|
1654
|
+
else window.addEventListener("DOMContentLoaded", initAriaOnBrowser);
|
|
1655
|
+
return _objectSpread2({}, INSTRUCTION_IDs$1);
|
|
1656
|
+
}
|
|
1657
|
+
/**
|
|
1658
|
+
* Removes all the artifacts (dom elements) added by this module
|
|
1659
|
+
*/
|
|
1660
|
+
function destroyAria() {
|
|
1661
|
+
if (isOnServer || !alertsDiv) return;
|
|
1662
|
+
Object.keys(ID_TO_INSTRUCTION).forEach(function(id) {
|
|
1663
|
+
var _document$getElementB;
|
|
1664
|
+
return (_document$getElementB = document.getElementById(id)) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.remove();
|
|
1665
|
+
});
|
|
1666
|
+
alertsDiv.remove();
|
|
1667
|
+
alertsDiv = void 0;
|
|
1668
|
+
}
|
|
1669
|
+
function instructionToHiddenDiv(id, txt) {
|
|
1670
|
+
var div = document.createElement("div");
|
|
1671
|
+
div.id = id;
|
|
1672
|
+
div.innerHTML = "<p>".concat(txt, "</p>");
|
|
1673
|
+
div.style.display = "none";
|
|
1674
|
+
div.style.position = "fixed";
|
|
1675
|
+
div.style.zIndex = "-5";
|
|
1676
|
+
return div;
|
|
1677
|
+
}
|
|
1678
|
+
/**
|
|
1679
|
+
* Will make the screen reader alert the provided text to the user
|
|
1680
|
+
* @param {string} txt
|
|
1681
|
+
*/
|
|
1682
|
+
function alertToScreenReader(txt) {
|
|
1683
|
+
if (isOnServer) return;
|
|
1684
|
+
if (!alertsDiv) initAriaOnBrowser();
|
|
1685
|
+
alertsDiv.innerHTML = "";
|
|
1686
|
+
var alertText = document.createTextNode(txt);
|
|
1687
|
+
alertsDiv.appendChild(alertText);
|
|
1688
|
+
alertsDiv.style.display = "none";
|
|
1689
|
+
alertsDiv.style.display = "inline";
|
|
1690
|
+
}
|
|
1691
|
+
var DEFAULT_DROP_ZONE_TYPE = "--any--";
|
|
1692
|
+
var DEFAULT_DROP_TARGET_STYLE = { outline: "rgba(255, 255, 102, 0.7) solid 2px" };
|
|
1693
|
+
var isDragging = false;
|
|
1694
|
+
var draggedItemType;
|
|
1695
|
+
var focusedDz;
|
|
1696
|
+
var focusedDzLabel = "";
|
|
1697
|
+
var focusedItem;
|
|
1698
|
+
var focusedItemId;
|
|
1699
|
+
var focusedItemLabel = "";
|
|
1700
|
+
var allDragTargets = /* @__PURE__ */ new WeakSet();
|
|
1701
|
+
var elToKeyDownListeners = /* @__PURE__ */ new WeakMap();
|
|
1702
|
+
var elToFocusListeners = /* @__PURE__ */ new WeakMap();
|
|
1703
|
+
var dzToHandles = /* @__PURE__ */ new Map();
|
|
1704
|
+
var dzToConfig = /* @__PURE__ */ new Map();
|
|
1705
|
+
var typeToDropZones = /* @__PURE__ */ new Map();
|
|
1706
|
+
var INSTRUCTION_IDs;
|
|
1707
|
+
function registerDropZone(dropZoneEl, type) {
|
|
1708
|
+
if (typeToDropZones.size === 0) {
|
|
1709
|
+
INSTRUCTION_IDs = initAria();
|
|
1710
|
+
window.addEventListener("keydown", globalKeyDownHandler);
|
|
1711
|
+
window.addEventListener("click", globalClickHandler);
|
|
1712
|
+
}
|
|
1713
|
+
if (!typeToDropZones.has(type)) typeToDropZones.set(type, /* @__PURE__ */ new Set());
|
|
1714
|
+
if (!typeToDropZones.get(type).has(dropZoneEl)) {
|
|
1715
|
+
typeToDropZones.get(type).add(dropZoneEl);
|
|
1716
|
+
incrementActiveDropZoneCount();
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
function unregisterDropZone(dropZoneEl, type) {
|
|
1720
|
+
if (focusedDz === dropZoneEl) handleDrop();
|
|
1721
|
+
typeToDropZones.get(type)["delete"](dropZoneEl);
|
|
1722
|
+
decrementActiveDropZoneCount();
|
|
1723
|
+
if (typeToDropZones.get(type).size === 0) typeToDropZones["delete"](type);
|
|
1724
|
+
if (typeToDropZones.size === 0) {
|
|
1725
|
+
window.removeEventListener("keydown", globalKeyDownHandler);
|
|
1726
|
+
window.removeEventListener("click", globalClickHandler);
|
|
1727
|
+
INSTRUCTION_IDs = void 0;
|
|
1728
|
+
destroyAria();
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
function globalKeyDownHandler(e) {
|
|
1732
|
+
if (!isDragging) return;
|
|
1733
|
+
switch (e.key) {
|
|
1734
|
+
case "Escape":
|
|
1735
|
+
handleDrop();
|
|
1736
|
+
break;
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
function globalClickHandler() {
|
|
1740
|
+
if (!isDragging) return;
|
|
1741
|
+
if (!allDragTargets.has(document.activeElement)) handleDrop();
|
|
1742
|
+
}
|
|
1743
|
+
function handleZoneFocus(e) {
|
|
1744
|
+
if (!isDragging) return;
|
|
1745
|
+
var newlyFocusedDz = e.currentTarget;
|
|
1746
|
+
if (newlyFocusedDz === focusedDz) return;
|
|
1747
|
+
focusedDzLabel = newlyFocusedDz.getAttribute("aria-label") || "";
|
|
1748
|
+
var originItems = dzToConfig.get(focusedDz).items;
|
|
1749
|
+
var originItem = originItems.find(function(item) {
|
|
1750
|
+
return item[ITEM_ID_KEY] === focusedItemId;
|
|
1751
|
+
});
|
|
1752
|
+
var originIdx = originItems.indexOf(originItem);
|
|
1753
|
+
var itemToMove = originItems.splice(originIdx, 1)[0];
|
|
1754
|
+
var _dzToConfig$get2 = dzToConfig.get(newlyFocusedDz), targetItems = _dzToConfig$get2.items, autoAriaDisabled = _dzToConfig$get2.autoAriaDisabled;
|
|
1755
|
+
if (newlyFocusedDz.getBoundingClientRect().top < focusedDz.getBoundingClientRect().top || newlyFocusedDz.getBoundingClientRect().left < focusedDz.getBoundingClientRect().left) {
|
|
1756
|
+
targetItems.push(itemToMove);
|
|
1757
|
+
if (!autoAriaDisabled) alertToScreenReader("Moved item ".concat(focusedItemLabel, " to the end of the list ").concat(focusedDzLabel));
|
|
1758
|
+
} else {
|
|
1759
|
+
targetItems.unshift(itemToMove);
|
|
1760
|
+
if (!autoAriaDisabled) alertToScreenReader("Moved item ".concat(focusedItemLabel, " to the beginning of the list ").concat(focusedDzLabel));
|
|
1761
|
+
}
|
|
1762
|
+
dispatchFinalizeEvent(focusedDz, originItems, {
|
|
1763
|
+
trigger: TRIGGERS.DROPPED_INTO_ANOTHER,
|
|
1764
|
+
id: focusedItemId,
|
|
1765
|
+
source: SOURCES.KEYBOARD
|
|
1766
|
+
});
|
|
1767
|
+
dispatchFinalizeEvent(newlyFocusedDz, targetItems, {
|
|
1768
|
+
trigger: TRIGGERS.DROPPED_INTO_ZONE,
|
|
1769
|
+
id: focusedItemId,
|
|
1770
|
+
source: SOURCES.KEYBOARD
|
|
1771
|
+
});
|
|
1772
|
+
focusedDz = newlyFocusedDz;
|
|
1773
|
+
}
|
|
1774
|
+
function triggerAllDzsUpdate() {
|
|
1775
|
+
dzToHandles.forEach(function(_ref, dz) {
|
|
1776
|
+
var update = _ref.update;
|
|
1777
|
+
return update(dzToConfig.get(dz));
|
|
1778
|
+
});
|
|
1779
|
+
}
|
|
1780
|
+
function handleDrop() {
|
|
1781
|
+
var dispatchConsider = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
|
|
1782
|
+
if (!dzToConfig.get(focusedDz).autoAriaDisabled) alertToScreenReader("Stopped dragging item ".concat(focusedItemLabel));
|
|
1783
|
+
if (allDragTargets.has(document.activeElement)) document.activeElement.blur();
|
|
1784
|
+
if (dispatchConsider) dispatchConsiderEvent(focusedDz, dzToConfig.get(focusedDz).items, {
|
|
1785
|
+
trigger: TRIGGERS.DRAG_STOPPED,
|
|
1786
|
+
id: focusedItemId,
|
|
1787
|
+
source: SOURCES.KEYBOARD
|
|
1788
|
+
});
|
|
1789
|
+
styleInactiveDropZones(typeToDropZones.get(draggedItemType), function(dz) {
|
|
1790
|
+
return dzToConfig.get(dz).dropTargetStyle;
|
|
1791
|
+
}, function(dz) {
|
|
1792
|
+
return dzToConfig.get(dz).dropTargetClasses;
|
|
1793
|
+
});
|
|
1794
|
+
focusedItem = null;
|
|
1795
|
+
focusedItemId = null;
|
|
1796
|
+
focusedItemLabel = "";
|
|
1797
|
+
draggedItemType = null;
|
|
1798
|
+
focusedDz = null;
|
|
1799
|
+
focusedDzLabel = "";
|
|
1800
|
+
isDragging = false;
|
|
1801
|
+
triggerAllDzsUpdate();
|
|
1802
|
+
}
|
|
1803
|
+
function dndzone$1(node, options) {
|
|
1804
|
+
var config = {
|
|
1805
|
+
items: void 0,
|
|
1806
|
+
type: void 0,
|
|
1807
|
+
dragDisabled: false,
|
|
1808
|
+
zoneTabIndex: 0,
|
|
1809
|
+
zoneItemTabIndex: 0,
|
|
1810
|
+
dropFromOthersDisabled: false,
|
|
1811
|
+
dropTargetStyle: DEFAULT_DROP_TARGET_STYLE,
|
|
1812
|
+
dropTargetClasses: [],
|
|
1813
|
+
autoAriaDisabled: false
|
|
1814
|
+
};
|
|
1815
|
+
function swap(arr, i, j) {
|
|
1816
|
+
if (arr.length <= 1) return;
|
|
1817
|
+
arr.splice(j, 1, arr.splice(i, 1, arr[j])[0]);
|
|
1818
|
+
}
|
|
1819
|
+
function handleKeyDown(e) {
|
|
1820
|
+
switch (e.key) {
|
|
1821
|
+
case "Enter":
|
|
1822
|
+
case " ":
|
|
1823
|
+
if ((e.target.disabled !== void 0 || e.target.href || e.target.isContentEditable) && !allDragTargets.has(e.target)) return;
|
|
1824
|
+
e.preventDefault();
|
|
1825
|
+
e.stopPropagation();
|
|
1826
|
+
if (isDragging) handleDrop();
|
|
1827
|
+
else handleDragStart(e);
|
|
1828
|
+
break;
|
|
1829
|
+
case "ArrowDown":
|
|
1830
|
+
case "ArrowRight":
|
|
1831
|
+
if (!isDragging) return;
|
|
1832
|
+
e.preventDefault();
|
|
1833
|
+
e.stopPropagation();
|
|
1834
|
+
var items = dzToConfig.get(node).items;
|
|
1835
|
+
var children = Array.from(node.children);
|
|
1836
|
+
var idx = children.indexOf(e.currentTarget);
|
|
1837
|
+
if (idx < children.length - 1) {
|
|
1838
|
+
if (!config.autoAriaDisabled) alertToScreenReader("Moved item ".concat(focusedItemLabel, " to position ").concat(idx + 2, " in the list ").concat(focusedDzLabel));
|
|
1839
|
+
swap(items, idx, idx + 1);
|
|
1840
|
+
dispatchFinalizeEvent(node, items, {
|
|
1841
|
+
trigger: TRIGGERS.DROPPED_INTO_ZONE,
|
|
1842
|
+
id: focusedItemId,
|
|
1843
|
+
source: SOURCES.KEYBOARD
|
|
1844
|
+
});
|
|
1845
|
+
}
|
|
1846
|
+
break;
|
|
1847
|
+
case "ArrowUp":
|
|
1848
|
+
case "ArrowLeft":
|
|
1849
|
+
if (!isDragging) return;
|
|
1850
|
+
e.preventDefault();
|
|
1851
|
+
e.stopPropagation();
|
|
1852
|
+
var _items = dzToConfig.get(node).items;
|
|
1853
|
+
var _idx = Array.from(node.children).indexOf(e.currentTarget);
|
|
1854
|
+
if (_idx > 0) {
|
|
1855
|
+
if (!config.autoAriaDisabled) alertToScreenReader("Moved item ".concat(focusedItemLabel, " to position ").concat(_idx, " in the list ").concat(focusedDzLabel));
|
|
1856
|
+
swap(_items, _idx, _idx - 1);
|
|
1857
|
+
dispatchFinalizeEvent(node, _items, {
|
|
1858
|
+
trigger: TRIGGERS.DROPPED_INTO_ZONE,
|
|
1859
|
+
id: focusedItemId,
|
|
1860
|
+
source: SOURCES.KEYBOARD
|
|
1861
|
+
});
|
|
1862
|
+
}
|
|
1863
|
+
break;
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
function handleDragStart(e) {
|
|
1867
|
+
setCurrentFocusedItem(e.currentTarget);
|
|
1868
|
+
focusedDz = node;
|
|
1869
|
+
draggedItemType = config.type;
|
|
1870
|
+
isDragging = true;
|
|
1871
|
+
var dropTargets = Array.from(typeToDropZones.get(config.type)).filter(function(dz) {
|
|
1872
|
+
return dz === focusedDz || !dzToConfig.get(dz).dropFromOthersDisabled;
|
|
1873
|
+
});
|
|
1874
|
+
styleActiveDropZones(dropTargets, function(dz) {
|
|
1875
|
+
return dzToConfig.get(dz).dropTargetStyle;
|
|
1876
|
+
}, function(dz) {
|
|
1877
|
+
return dzToConfig.get(dz).dropTargetClasses;
|
|
1878
|
+
});
|
|
1879
|
+
if (!config.autoAriaDisabled) {
|
|
1880
|
+
var msg = "Started dragging item ".concat(focusedItemLabel, ". Use the arrow keys to move it within its list ").concat(focusedDzLabel);
|
|
1881
|
+
if (dropTargets.length > 1) msg += ", or tab to another list in order to move the item into it";
|
|
1882
|
+
alertToScreenReader(msg);
|
|
1883
|
+
}
|
|
1884
|
+
dispatchConsiderEvent(node, dzToConfig.get(node).items, {
|
|
1885
|
+
trigger: TRIGGERS.DRAG_STARTED,
|
|
1886
|
+
id: focusedItemId,
|
|
1887
|
+
source: SOURCES.KEYBOARD
|
|
1888
|
+
});
|
|
1889
|
+
triggerAllDzsUpdate();
|
|
1890
|
+
}
|
|
1891
|
+
function handleClick(e) {
|
|
1892
|
+
if (!isDragging) return;
|
|
1893
|
+
if (e.currentTarget === focusedItem) return;
|
|
1894
|
+
e.stopPropagation();
|
|
1895
|
+
handleDrop(false);
|
|
1896
|
+
handleDragStart(e);
|
|
1897
|
+
}
|
|
1898
|
+
function setCurrentFocusedItem(draggableEl) {
|
|
1899
|
+
var items = dzToConfig.get(node).items;
|
|
1900
|
+
var children = Array.from(node.children);
|
|
1901
|
+
var focusedItemIdx = children.indexOf(draggableEl);
|
|
1902
|
+
focusedItem = draggableEl;
|
|
1903
|
+
focusedItem.tabIndex = config.zoneItemTabIndex;
|
|
1904
|
+
focusedItemId = items[focusedItemIdx][ITEM_ID_KEY];
|
|
1905
|
+
focusedItemLabel = children[focusedItemIdx].getAttribute("aria-label") || "";
|
|
1906
|
+
}
|
|
1907
|
+
function configure(_ref2) {
|
|
1908
|
+
var _ref2$items = _ref2.items, items = _ref2$items === void 0 ? [] : _ref2$items, _ref2$type = _ref2.type, newType = _ref2$type === void 0 ? DEFAULT_DROP_ZONE_TYPE : _ref2$type, _ref2$dragDisabled = _ref2.dragDisabled, dragDisabled = _ref2$dragDisabled === void 0 ? false : _ref2$dragDisabled, _ref2$zoneTabIndex = _ref2.zoneTabIndex, zoneTabIndex = _ref2$zoneTabIndex === void 0 ? 0 : _ref2$zoneTabIndex, _ref2$zoneItemTabInde = _ref2.zoneItemTabIndex, zoneItemTabIndex = _ref2$zoneItemTabInde === void 0 ? 0 : _ref2$zoneItemTabInde, _ref2$dropFromOthersD = _ref2.dropFromOthersDisabled, dropFromOthersDisabled = _ref2$dropFromOthersD === void 0 ? false : _ref2$dropFromOthersD, _ref2$dropTargetStyle = _ref2.dropTargetStyle, dropTargetStyle = _ref2$dropTargetStyle === void 0 ? DEFAULT_DROP_TARGET_STYLE : _ref2$dropTargetStyle, _ref2$dropTargetClass = _ref2.dropTargetClasses, dropTargetClasses = _ref2$dropTargetClass === void 0 ? [] : _ref2$dropTargetClass, _ref2$autoAriaDisable = _ref2.autoAriaDisabled, autoAriaDisabled = _ref2$autoAriaDisable === void 0 ? false : _ref2$autoAriaDisable;
|
|
1909
|
+
config.items = _toConsumableArray(items);
|
|
1910
|
+
config.dragDisabled = dragDisabled;
|
|
1911
|
+
config.dropFromOthersDisabled = dropFromOthersDisabled;
|
|
1912
|
+
config.zoneTabIndex = zoneTabIndex;
|
|
1913
|
+
config.zoneItemTabIndex = zoneItemTabIndex;
|
|
1914
|
+
config.dropTargetStyle = dropTargetStyle;
|
|
1915
|
+
config.dropTargetClasses = dropTargetClasses;
|
|
1916
|
+
config.autoAriaDisabled = autoAriaDisabled;
|
|
1917
|
+
if (config.type && newType !== config.type) unregisterDropZone(node, config.type);
|
|
1918
|
+
config.type = newType;
|
|
1919
|
+
registerDropZone(node, newType);
|
|
1920
|
+
if (!autoAriaDisabled) {
|
|
1921
|
+
node.setAttribute("role", "list");
|
|
1922
|
+
node.setAttribute("aria-describedby", dragDisabled ? INSTRUCTION_IDs.DND_ZONE_DRAG_DISABLED : INSTRUCTION_IDs.DND_ZONE_ACTIVE);
|
|
1923
|
+
}
|
|
1924
|
+
dzToConfig.set(node, config);
|
|
1925
|
+
if (isDragging) node.tabIndex = node === focusedDz || focusedItem.contains(node) || config.dropFromOthersDisabled || focusedDz && config.type !== dzToConfig.get(focusedDz).type ? -1 : 0;
|
|
1926
|
+
else node.tabIndex = config.zoneTabIndex;
|
|
1927
|
+
node.addEventListener("focus", handleZoneFocus);
|
|
1928
|
+
var _loop = function _loop(i) {
|
|
1929
|
+
var draggableEl = node.children[i];
|
|
1930
|
+
allDragTargets.add(draggableEl);
|
|
1931
|
+
draggableEl.tabIndex = isDragging ? -1 : config.zoneItemTabIndex;
|
|
1932
|
+
if (!autoAriaDisabled) draggableEl.setAttribute("role", "listitem");
|
|
1933
|
+
draggableEl.removeEventListener("keydown", elToKeyDownListeners.get(draggableEl));
|
|
1934
|
+
draggableEl.removeEventListener("click", elToFocusListeners.get(draggableEl));
|
|
1935
|
+
if (!dragDisabled) {
|
|
1936
|
+
draggableEl.addEventListener("keydown", handleKeyDown);
|
|
1937
|
+
elToKeyDownListeners.set(draggableEl, handleKeyDown);
|
|
1938
|
+
draggableEl.addEventListener("click", handleClick);
|
|
1939
|
+
elToFocusListeners.set(draggableEl, handleClick);
|
|
1940
|
+
}
|
|
1941
|
+
if (isDragging && config.items[i][ITEM_ID_KEY] === focusedItemId) {
|
|
1942
|
+
focusedItem = draggableEl;
|
|
1943
|
+
focusedItem.tabIndex = config.zoneItemTabIndex;
|
|
1944
|
+
draggableEl.focus();
|
|
1945
|
+
}
|
|
1946
|
+
};
|
|
1947
|
+
for (var i = 0; i < node.children.length; i++) _loop(i);
|
|
1948
|
+
}
|
|
1949
|
+
configure(options);
|
|
1950
|
+
var handles = {
|
|
1951
|
+
update: function update(newOptions) {
|
|
1952
|
+
configure(newOptions);
|
|
1953
|
+
},
|
|
1954
|
+
destroy: function destroy() {
|
|
1955
|
+
unregisterDropZone(node, config.type);
|
|
1956
|
+
dzToConfig["delete"](node);
|
|
1957
|
+
dzToHandles["delete"](node);
|
|
1958
|
+
}
|
|
1959
|
+
};
|
|
1960
|
+
dzToHandles.set(node, handles);
|
|
1961
|
+
return handles;
|
|
1962
|
+
}
|
|
1963
|
+
var _excluded = [
|
|
1964
|
+
"items",
|
|
1965
|
+
"flipDurationMs",
|
|
1966
|
+
"type",
|
|
1967
|
+
"dragDisabled",
|
|
1968
|
+
"morphDisabled",
|
|
1969
|
+
"dropFromOthersDisabled",
|
|
1970
|
+
"zoneTabIndex",
|
|
1971
|
+
"zoneItemTabIndex",
|
|
1972
|
+
"dropTargetStyle",
|
|
1973
|
+
"dropTargetClasses",
|
|
1974
|
+
"transformDraggedElement",
|
|
1975
|
+
"autoAriaDisabled",
|
|
1976
|
+
"centreDraggedOnCursor",
|
|
1977
|
+
"useCursorForDetection",
|
|
1978
|
+
"delayTouchStart",
|
|
1979
|
+
"dropAnimationDisabled"
|
|
1980
|
+
];
|
|
1981
|
+
/**
|
|
1982
|
+
* A custom action to turn any container to a dnd zone and all of its direct children to draggables
|
|
1983
|
+
* Supports mouse, touch and keyboard interactions.
|
|
1984
|
+
* Dispatches two events that the container is expected to react to by modifying its list of items,
|
|
1985
|
+
* which will then feed back in to this action via the update function
|
|
1986
|
+
*
|
|
1987
|
+
* @typedef {object} Options
|
|
1988
|
+
* @property {array} items - the list of items that was used to generate the children of the given node (the list used in the #each block
|
|
1989
|
+
* @property {string} [type] - the type of the dnd zone. children dragged from here can only be dropped in other zones of the same type, default to a base type
|
|
1990
|
+
* @property {number} [flipDurationMs] - if the list animated using flip (recommended), specifies the flip duration such that everything syncs with it without conflict, defaults to zero
|
|
1991
|
+
* @property {boolean} [dragDisabled]
|
|
1992
|
+
* @property {boolean} [morphDisabled] - whether dragged element should morph to zone dimensions
|
|
1993
|
+
* @property {boolean} [dropFromOthersDisabled]
|
|
1994
|
+
* @property {number} [zoneTabIndex] - set the tabindex of the list container when not dragging
|
|
1995
|
+
* @property {number} [zoneItemTabIndex] - set the tabindex of the list container items when not dragging
|
|
1996
|
+
* @property {object} [dropTargetStyle]
|
|
1997
|
+
* @property {string[]} [dropTargetClasses]
|
|
1998
|
+
* @property {boolean|number} [delayTouchStart] - On touch devices, wait this long before converting the gesture to a drag.
|
|
1999
|
+
* `true` uses the built-in default (80 ms).
|
|
2000
|
+
* @property {boolean} [dropAnimationDisabled] - cancels the drop animation to place
|
|
2001
|
+
* @property {function} [transformDraggedElement]
|
|
2002
|
+
* @param {HTMLElement} node - the element to enhance
|
|
2003
|
+
* @param {Options} options
|
|
2004
|
+
* @return {{update: function, destroy: function}}
|
|
2005
|
+
*/
|
|
2006
|
+
function dndzone$3(node, options) {
|
|
2007
|
+
if (shouldIgnoreZone(node)) return {
|
|
2008
|
+
update: function update() {},
|
|
2009
|
+
destroy: function destroy() {}
|
|
2010
|
+
};
|
|
2011
|
+
validateOptions(options);
|
|
2012
|
+
var pointerZone = dndzone$2(node, options);
|
|
2013
|
+
var keyboardZone = dndzone$1(node, options);
|
|
2014
|
+
return {
|
|
2015
|
+
update: function update(newOptions) {
|
|
2016
|
+
validateOptions(newOptions);
|
|
2017
|
+
pointerZone.update(newOptions);
|
|
2018
|
+
keyboardZone.update(newOptions);
|
|
2019
|
+
},
|
|
2020
|
+
destroy: function destroy() {
|
|
2021
|
+
pointerZone.destroy();
|
|
2022
|
+
keyboardZone.destroy();
|
|
2023
|
+
}
|
|
2024
|
+
};
|
|
2025
|
+
}
|
|
2026
|
+
/**
|
|
2027
|
+
* If the user marked something in the ancestry of our node as shadow element, we can ignore it
|
|
2028
|
+
* We need the user to mark it for us because svelte updates the action from deep to shallow (but renders top down)
|
|
2029
|
+
* @param {HTMLElement} node
|
|
2030
|
+
* @return {boolean}
|
|
2031
|
+
*/
|
|
2032
|
+
function shouldIgnoreZone(node) {
|
|
2033
|
+
return !!node.closest("[".concat(SHADOW_ELEMENT_HINT_ATTRIBUTE_NAME, "=\"true\"]"));
|
|
2034
|
+
}
|
|
2035
|
+
function validateOptions(options) {
|
|
2036
|
+
var items = options.items;
|
|
2037
|
+
options.flipDurationMs;
|
|
2038
|
+
options.type;
|
|
2039
|
+
options.dragDisabled;
|
|
2040
|
+
options.morphDisabled;
|
|
2041
|
+
options.dropFromOthersDisabled;
|
|
2042
|
+
var zoneTabIndex = options.zoneTabIndex, zoneItemTabIndex = options.zoneItemTabIndex;
|
|
2043
|
+
options.dropTargetStyle;
|
|
2044
|
+
var dropTargetClasses = options.dropTargetClasses;
|
|
2045
|
+
options.transformDraggedElement;
|
|
2046
|
+
options.autoAriaDisabled;
|
|
2047
|
+
options.centreDraggedOnCursor;
|
|
2048
|
+
options.useCursorForDetection;
|
|
2049
|
+
var delayTouchStart = options.delayTouchStart;
|
|
2050
|
+
options.dropAnimationDisabled;
|
|
2051
|
+
var rest = _objectWithoutProperties(options, _excluded);
|
|
2052
|
+
if (Object.keys(rest).length > 0) console.warn("dndzone will ignore unknown options", rest);
|
|
2053
|
+
if (!items) throw new Error("no 'items' key provided to dndzone");
|
|
2054
|
+
var itemWithMissingId = items.find(function(item) {
|
|
2055
|
+
return !{}.hasOwnProperty.call(item, ITEM_ID_KEY);
|
|
2056
|
+
});
|
|
2057
|
+
if (itemWithMissingId) throw new Error("missing '".concat(ITEM_ID_KEY, "' property for item ").concat(toString(itemWithMissingId)));
|
|
2058
|
+
if (dropTargetClasses && !Array.isArray(dropTargetClasses)) throw new Error("dropTargetClasses should be an array but instead it is a ".concat(_typeof(dropTargetClasses), ", ").concat(toString(dropTargetClasses)));
|
|
2059
|
+
if (zoneTabIndex && !isInt(zoneTabIndex)) throw new Error("zoneTabIndex should be a number but instead it is a ".concat(_typeof(zoneTabIndex), ", ").concat(toString(zoneTabIndex)));
|
|
2060
|
+
if (zoneItemTabIndex && !isInt(zoneItemTabIndex)) throw new Error("zoneItemTabIndex should be a number but instead it is a ".concat(_typeof(zoneItemTabIndex), ", ").concat(toString(zoneItemTabIndex)));
|
|
2061
|
+
if (delayTouchStart !== void 0 && delayTouchStart !== false) {
|
|
2062
|
+
if (!(delayTouchStart === true) && !(typeof delayTouchStart === "number" && isFinite(delayTouchStart) && delayTouchStart >= 0)) throw new Error("delayTouchStart should be a boolean (true/false) or a non-negative number but instead it is a ".concat(_typeof(delayTouchStart), ", ").concat(toString(delayTouchStart)));
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
function isInt(value) {
|
|
2066
|
+
return !isNaN(value) && function(x) {
|
|
2067
|
+
return (x | 0) === x;
|
|
2068
|
+
}(parseFloat(value));
|
|
2069
|
+
}
|
|
2070
|
+
//#endregion
|
|
2071
|
+
//#region src/lib/utils/dndzone.ts
|
|
2072
|
+
/**
|
|
2073
|
+
* Hydration-safe `dndzone` action. Defers the real setup to a microtask so
|
|
2074
|
+
* the library's `document.body.prepend(...)` aria injection runs *after*
|
|
2075
|
+
* Svelte has finished hydrating the page, not during.
|
|
2076
|
+
*/
|
|
2077
|
+
function dndzone(node, options) {
|
|
2078
|
+
const initialOptions = options;
|
|
2079
|
+
let real = null;
|
|
2080
|
+
let pendingUpdate = null;
|
|
2081
|
+
let pendingDestroy = false;
|
|
2082
|
+
let scheduled = false;
|
|
2083
|
+
const schedule = () => {
|
|
2084
|
+
if (scheduled) return;
|
|
2085
|
+
scheduled = true;
|
|
2086
|
+
(typeof queueMicrotask === "function" ? queueMicrotask : (fn) => Promise.resolve().then(fn))(init);
|
|
2087
|
+
};
|
|
2088
|
+
const init = () => {
|
|
2089
|
+
if (pendingDestroy) return;
|
|
2090
|
+
real = dndzone$3(node, initialOptions);
|
|
2091
|
+
if (pendingUpdate) {
|
|
2092
|
+
real.update(pendingUpdate);
|
|
2093
|
+
pendingUpdate = null;
|
|
2094
|
+
}
|
|
2095
|
+
};
|
|
2096
|
+
schedule();
|
|
2097
|
+
return {
|
|
2098
|
+
update(newOptions) {
|
|
2099
|
+
if (real) real.update(newOptions);
|
|
2100
|
+
else {
|
|
2101
|
+
pendingUpdate = newOptions;
|
|
2102
|
+
schedule();
|
|
2103
|
+
}
|
|
2104
|
+
},
|
|
2105
|
+
destroy() {
|
|
2106
|
+
if (real) {
|
|
2107
|
+
real.destroy();
|
|
2108
|
+
real = null;
|
|
2109
|
+
} else pendingDestroy = true;
|
|
2110
|
+
}
|
|
2111
|
+
};
|
|
2112
|
+
}
|
|
2113
|
+
//#endregion
|
|
2114
|
+
export { SHADOW_ITEM_MARKER_PROPERTY_NAME as n, dndzone as t };
|