sprintify-ui 0.10.59 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sprintify-ui",
3
- "version": "0.10.59",
3
+ "version": "0.10.60",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "rimraf dist && vue-tsc && vite build",
@@ -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({});
@@ -15,6 +15,7 @@
15
15
 
16
16
  <script lang="ts" setup>
17
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<{
@@ -41,6 +42,34 @@ function getKey(element: any) {
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>