@afeefa/vue-app 0.0.291 → 0.0.292
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.
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.292
|
package/package.json
CHANGED
@@ -5,40 +5,38 @@
|
|
5
5
|
</v-label>
|
6
6
|
|
7
7
|
<a-row vertical>
|
8
|
-
<
|
9
|
-
v-
|
10
|
-
|
11
|
-
class="
|
12
|
-
|
13
|
-
@dragover="onDragOver(index, $event)"
|
14
|
-
@dragleave="onDragLeave"
|
15
|
-
@drop="onDrop(index, $event)"
|
8
|
+
<draggable
|
9
|
+
v-model="options_"
|
10
|
+
handle=".drag-handle"
|
11
|
+
ghost-class="ghost"
|
12
|
+
@end="onDragEnd"
|
16
13
|
>
|
17
|
-
<div
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
14
|
+
<div
|
15
|
+
v-for="option in options_"
|
16
|
+
:key="option.itemValue"
|
17
|
+
class="draggable-checkbox"
|
18
|
+
>
|
19
|
+
<div class="checkbox-container">
|
20
|
+
<div class="drag-handle">
|
21
|
+
<a-icon
|
22
|
+
size="1.5rem"
|
23
|
+
:icon="{icon: '$dragIcon', color: '#CCCCCC'}"
|
24
|
+
/>
|
25
|
+
</div>
|
26
|
+
|
27
|
+
<a-checkbox
|
28
|
+
:label="option.itemText"
|
29
|
+
:value="isChecked(option.itemValue)"
|
30
|
+
hide-details
|
31
|
+
@input="checked(option.itemValue, $event)"
|
32
|
+
>
|
33
|
+
<template #label>
|
34
|
+
<div v-html="option.itemText" />
|
35
|
+
</template>
|
36
|
+
</a-checkbox>
|
28
37
|
</div>
|
29
|
-
|
30
|
-
<a-checkbox
|
31
|
-
:label="option.itemText"
|
32
|
-
:value="isChecked(option.itemValue)"
|
33
|
-
hide-details
|
34
|
-
@input="checked(option.itemValue, $event)"
|
35
|
-
>
|
36
|
-
<template #label>
|
37
|
-
<div v-html="option.itemText" />
|
38
|
-
</template>
|
39
|
-
</a-checkbox>
|
40
38
|
</div>
|
41
|
-
</
|
39
|
+
</draggable>
|
42
40
|
</a-row>
|
43
41
|
|
44
42
|
<div
|
@@ -53,17 +51,19 @@
|
|
53
51
|
|
54
52
|
<script>
|
55
53
|
import { Component, Vue, Watch, Inject } from '@a-vue'
|
54
|
+
import draggable from 'vuedraggable'
|
56
55
|
|
57
56
|
@Component({
|
58
|
-
props: ['value', 'options', 'validator']
|
57
|
+
props: ['value', 'options', 'validator'],
|
58
|
+
components: {
|
59
|
+
draggable
|
60
|
+
}
|
59
61
|
})
|
60
62
|
export default class ACheckboxGroup extends Vue {
|
61
63
|
value_ = []
|
62
64
|
options_ = []
|
63
65
|
errorMessages = []
|
64
66
|
hasError = false
|
65
|
-
draggedIndex = null
|
66
|
-
dragOverIndex = null
|
67
67
|
|
68
68
|
@Inject({ from: 'form', default: null }) form
|
69
69
|
|
@@ -130,86 +130,24 @@ export default class ACheckboxGroup extends Vue {
|
|
130
130
|
return !this.errorMessages.length
|
131
131
|
}
|
132
132
|
|
133
|
-
|
134
|
-
this.draggedIndex = index
|
135
|
-
event.dataTransfer.effectAllowed = 'move'
|
136
|
-
event.dataTransfer.setData('text/html', event.target)
|
137
|
-
|
138
|
-
// Set the entire checkbox container as the drag image
|
139
|
-
const checkboxContainer = event.target.closest('.draggable-checkbox')
|
140
|
-
if (checkboxContainer) {
|
141
|
-
event.dataTransfer.setDragImage(checkboxContainer, 0, 0)
|
142
|
-
}
|
143
|
-
}
|
144
|
-
|
145
|
-
onDragEnd () {
|
146
|
-
this.draggedIndex = null
|
147
|
-
this.dragOverIndex = null
|
148
|
-
|
133
|
+
onDragEnd (evt) {
|
149
134
|
this.$emit('orderChanged', this.options_)
|
150
135
|
}
|
151
|
-
|
152
|
-
onDragOver (index, event) {
|
153
|
-
event.preventDefault()
|
154
|
-
event.stopPropagation()
|
155
|
-
event.dataTransfer.dropEffect = 'move'
|
156
|
-
this.dragOverIndex = index
|
157
|
-
}
|
158
|
-
|
159
|
-
onDragLeave (event) {
|
160
|
-
// Only clear dragOverIndex if we're actually leaving the draggable-checkbox container
|
161
|
-
const rect = event.currentTarget.getBoundingClientRect()
|
162
|
-
const x = event.clientX
|
163
|
-
const y = event.clientY
|
164
|
-
|
165
|
-
if (x < rect.left || x > rect.right || y < rect.top || y > rect.bottom) {
|
166
|
-
this.dragOverIndex = null
|
167
|
-
}
|
168
|
-
}
|
169
|
-
|
170
|
-
onDrop (index, event) {
|
171
|
-
event.preventDefault()
|
172
|
-
|
173
|
-
if (this.draggedIndex !== null && this.draggedIndex !== index) {
|
174
|
-
// Create a copy of the options array
|
175
|
-
const newOptions = [...this.options_]
|
176
|
-
|
177
|
-
// Remove the dragged item
|
178
|
-
const draggedItem = newOptions.splice(this.draggedIndex, 1)[0]
|
179
|
-
|
180
|
-
// Insert it at the new position
|
181
|
-
newOptions.splice(index, 0, draggedItem)
|
182
|
-
|
183
|
-
// Update the options
|
184
|
-
this.options_ = newOptions
|
185
|
-
|
186
|
-
// Emit an event to notify parent component about the reorder
|
187
|
-
this.$emit('reorder', newOptions)
|
188
|
-
}
|
189
|
-
|
190
|
-
this.draggedIndex = null
|
191
|
-
this.dragOverIndex = null
|
192
|
-
}
|
193
136
|
}
|
194
137
|
</script>
|
195
138
|
|
196
139
|
<style scoped>
|
197
140
|
.draggable-checkbox {
|
198
141
|
transition: all .2s ease;
|
199
|
-
|
200
|
-
padding: 2px;
|
142
|
+
padding: 0 5px 0 0;
|
201
143
|
}
|
202
144
|
|
203
145
|
.draggable-checkbox:hover {
|
204
146
|
background-color: rgba(0, 0, 0, .04);
|
205
147
|
}
|
206
148
|
|
207
|
-
.
|
149
|
+
.ghost {
|
208
150
|
opacity: .5;
|
209
|
-
transform: scale(.95);
|
210
|
-
}
|
211
|
-
|
212
|
-
.draggable-checkbox.drag-over {
|
213
151
|
background-color: rgba(25, 118, 210, .1);
|
214
152
|
border: 2px dashed rgba(25, 118, 210, .3);
|
215
153
|
}
|
@@ -221,30 +159,11 @@ export default class ACheckboxGroup extends Vue {
|
|
221
159
|
|
222
160
|
.drag-handle {
|
223
161
|
cursor: grab;
|
224
|
-
color: rgba(0, 0, 0, .54);
|
225
162
|
transition: all .2s ease;
|
226
|
-
display: flex;
|
227
|
-
align-items: center;
|
228
|
-
justify-content: center;
|
229
|
-
min-width: 20px;
|
230
163
|
height: 20px;
|
231
164
|
}
|
232
165
|
|
233
|
-
.drag-handle:hover {
|
234
|
-
background-color: rgba(0, 0, 0, .08);
|
235
|
-
color: rgba(0, 0, 0, .87);
|
236
|
-
}
|
237
|
-
|
238
166
|
.drag-handle:active {
|
239
167
|
cursor: grabbing;
|
240
168
|
}
|
241
|
-
|
242
|
-
.draggable-checkbox .v-input--checkbox {
|
243
|
-
pointer-events: auto;
|
244
|
-
flex: 1;
|
245
|
-
}
|
246
|
-
|
247
|
-
.draggable-checkbox .v-input__slot {
|
248
|
-
cursor: pointer;
|
249
|
-
}
|
250
169
|
</style>
|