sprintify-ui 0.10.58 → 0.10.60
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/dist/sprintify-ui.es.js +1883 -1865
- package/dist/types/utils/uuid.d.ts +1 -0
- package/package.json +1 -1
- package/src/components/BaseDraggable.stories.js +34 -0
- package/src/components/BaseDraggable.vue +32 -13
- package/src/utils/uuid.ts +8 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function randomId(length: number): string;
|
package/package.json
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import BaseDraggable from "./BaseDraggable.vue";
|
|
2
|
+
import { options } from "../../.storybook/utils";
|
|
3
|
+
import ShowValue from "@/../.storybook/components/ShowValue.vue";
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: "Components/BaseDraggable",
|
|
7
|
+
component: BaseDraggable,
|
|
8
|
+
args: {
|
|
9
|
+
itemKey: 'value',
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const Template = (args) => ({
|
|
14
|
+
components: { BaseDraggable, ShowValue },
|
|
15
|
+
setup() {
|
|
16
|
+
const modelValue = ref(options.filter(v => v.value != null));
|
|
17
|
+
return { args, modelValue };
|
|
18
|
+
},
|
|
19
|
+
template: `
|
|
20
|
+
<div class="border">
|
|
21
|
+
<BaseDraggable v-bind="args" v-model="modelValue">
|
|
22
|
+
<template #item="{ element }">
|
|
23
|
+
<div class="handle border bg-white text-sm p-2 cursor-move">
|
|
24
|
+
{{ element.label }}
|
|
25
|
+
</div>
|
|
26
|
+
</template>
|
|
27
|
+
</BaseDraggable>
|
|
28
|
+
|
|
29
|
+
<ShowValue :value="modelValue" />
|
|
30
|
+
</div>
|
|
31
|
+
`,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export const Demo = Template.bind({});
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
</template>
|
|
15
15
|
|
|
16
16
|
<script lang="ts" setup>
|
|
17
|
-
import {
|
|
17
|
+
import { randomId } from '@/utils/uuid';
|
|
18
|
+
import { debounce } from 'lodash';
|
|
18
19
|
import Sortable from 'sortablejs';
|
|
19
20
|
|
|
20
21
|
const props = withDefaults(defineProps<{
|
|
@@ -35,12 +36,40 @@ const emit = defineEmits(['update:modelValue']);
|
|
|
35
36
|
const elementsRef = ref<HTMLElement | null>(null);
|
|
36
37
|
|
|
37
38
|
function getKey(element: any) {
|
|
38
|
-
return element[props.itemKey] ??
|
|
39
|
+
return element[props.itemKey] ?? randomId(32);
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
let sortable = null as Sortable | null;
|
|
42
43
|
|
|
43
44
|
onMounted(() => {
|
|
45
|
+
initDebounced();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
onBeforeUnmount(() => {
|
|
49
|
+
sortable?.destroy();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
watch(
|
|
53
|
+
() => props.disabled,
|
|
54
|
+
(disabled) => {
|
|
55
|
+
sortable?.option('disabled', disabled);
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
watch(
|
|
60
|
+
() => props.modelValue,
|
|
61
|
+
() => {
|
|
62
|
+
sortable?.destroy();
|
|
63
|
+
|
|
64
|
+
nextTick(() => {
|
|
65
|
+
initDebounced();
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const initDebounced = debounce(init, 100);
|
|
71
|
+
|
|
72
|
+
function init() {
|
|
44
73
|
if (!elementsRef.value) {
|
|
45
74
|
return;
|
|
46
75
|
}
|
|
@@ -67,7 +96,7 @@ onMounted(() => {
|
|
|
67
96
|
});
|
|
68
97
|
},
|
|
69
98
|
});
|
|
70
|
-
}
|
|
99
|
+
}
|
|
71
100
|
|
|
72
101
|
function arrayMove(array: any[], fromIndex: number, toIndex: number): any[] {
|
|
73
102
|
// without mutating the original array
|
|
@@ -79,14 +108,4 @@ function arrayMove(array: any[], fromIndex: number, toIndex: number): any[] {
|
|
|
79
108
|
return newArray;
|
|
80
109
|
}
|
|
81
110
|
|
|
82
|
-
onBeforeUnmount(() => {
|
|
83
|
-
sortable?.destroy();
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
watch(
|
|
87
|
-
() => props.disabled,
|
|
88
|
-
(disabled) => {
|
|
89
|
-
sortable?.option('disabled', disabled);
|
|
90
|
-
}
|
|
91
|
-
);
|
|
92
111
|
</script>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function randomId(length: number): string {
|
|
2
|
+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
3
|
+
let result = '';
|
|
4
|
+
for (let i = 0; i < length; i++) {
|
|
5
|
+
result += characters.charAt(Math.floor(Math.random() * characters.length));
|
|
6
|
+
}
|
|
7
|
+
return result;
|
|
8
|
+
}
|