@webitel/ui-sdk 3.2.88 → 3.2.89
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webitel/ui-sdk",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.89",
|
|
4
4
|
"private": false,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"serve-lib": "vue-cli-service serve",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"dist/*",
|
|
18
18
|
"src/api/*",
|
|
19
19
|
"src/locale/*",
|
|
20
|
+
"src/composables/*",
|
|
20
21
|
"src/css/*",
|
|
21
22
|
"src/components/*",
|
|
22
23
|
"src/directives/*",
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import Sortable from 'sortablejs';
|
|
2
|
+
import {
|
|
3
|
+
ref,
|
|
4
|
+
nextTick,
|
|
5
|
+
onMounted,
|
|
6
|
+
onUnmounted,
|
|
7
|
+
} from 'vue';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param elRef
|
|
11
|
+
* @param options
|
|
12
|
+
* @returns {{reloadSortable: Ref<UnwrapRef<boolean>>}}
|
|
13
|
+
*
|
|
14
|
+
* @description initializes Sortable on passed element ref and reinitializes it after each reorder
|
|
15
|
+
*
|
|
16
|
+
* WHY TO REINITIALIZE SORTABLE AFTER EACH ARRAY REORDER?
|
|
17
|
+
* Sortable and Vue both changing DOM so that there are collisions
|
|
18
|
+
* because both Vue and Sortable try to put element to the position. So element is put incorrectly.
|
|
19
|
+
*
|
|
20
|
+
* There are 2 vue packages for sortable (vue 2 and vue 3), but I had encountered issues when tried to use them.
|
|
21
|
+
* Also, it seems to me that they aren't supported now :(
|
|
22
|
+
*
|
|
23
|
+
* So that I decided to reinitialize Sortable each time order changes to represent it correctly.
|
|
24
|
+
* Bad decision, but I haven't come up with a better one
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
// eslint-disable-next-line import/prefer-default-export
|
|
28
|
+
export function useDestroyableSortable(elRef, options) {
|
|
29
|
+
let sortable = null;
|
|
30
|
+
|
|
31
|
+
const reloadSortable = ref(false);
|
|
32
|
+
|
|
33
|
+
function destroySortable() {
|
|
34
|
+
return sortable.destroy();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function initSortable() {
|
|
38
|
+
const replaceSortable = async () => {
|
|
39
|
+
if (!sortable) return;
|
|
40
|
+
destroySortable();
|
|
41
|
+
reloadSortable.value = true;
|
|
42
|
+
await nextTick();
|
|
43
|
+
reloadSortable.value = false;
|
|
44
|
+
await nextTick();
|
|
45
|
+
initSortable();
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
sortable = Sortable.create(elRef.value, {
|
|
49
|
+
...options,
|
|
50
|
+
onEnd: async (e) => {
|
|
51
|
+
if (options.onEnd) options.onEnd(e);
|
|
52
|
+
await replaceSortable();
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
onMounted(() => {
|
|
58
|
+
initSortable();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
onUnmounted(() => {
|
|
62
|
+
destroySortable();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return { reloadSortable };
|
|
66
|
+
}
|