@sfxcode/formkit-primevue 4.2.3 → 4.2.4
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.
|
@@ -123,6 +123,7 @@ type TransferList = 'source' | 'target'
|
|
|
123
123
|
const dragSource = ref<TransferList | null>(null)
|
|
124
124
|
const draggedItems = ref<any[]>([])
|
|
125
125
|
const activeDropzone = ref<TransferList | null>(null)
|
|
126
|
+
const dragOverIndex = ref<number | null>(null)
|
|
126
127
|
|
|
127
128
|
function getComparableValue(item: any): any {
|
|
128
129
|
const valueKey = optionValueKey.value
|
|
@@ -154,14 +155,17 @@ function clearDragState() {
|
|
|
154
155
|
dragSource.value = null
|
|
155
156
|
draggedItems.value = []
|
|
156
157
|
activeDropzone.value = null
|
|
158
|
+
dragOverIndex.value = null
|
|
157
159
|
}
|
|
158
160
|
|
|
159
161
|
function canDropInto(target: TransferList): boolean {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
162
|
+
if (!transferDragDrop.value || props.context.disabled || !dragSource.value || draggedItems.value.length === 0)
|
|
163
|
+
return false
|
|
164
|
+
// The target list accepts cross-list moves as well as same-list reordering.
|
|
165
|
+
if (target === 'target')
|
|
166
|
+
return true
|
|
167
|
+
// The source list only accepts items coming from the target (i.e. removal).
|
|
168
|
+
return dragSource.value !== target
|
|
165
169
|
}
|
|
166
170
|
|
|
167
171
|
function handleOptionDragStart(origin: TransferList, option: any, event: DragEvent) {
|
|
@@ -186,6 +190,8 @@ function handleDropzoneDragOver(target: TransferList, event: DragEvent) {
|
|
|
186
190
|
|
|
187
191
|
event.preventDefault()
|
|
188
192
|
activeDropzone.value = target
|
|
193
|
+
// Hovering empty space (not over a specific item) clears the per-item highlight.
|
|
194
|
+
dragOverIndex.value = null
|
|
189
195
|
if (event.dataTransfer)
|
|
190
196
|
event.dataTransfer.dropEffect = 'move'
|
|
191
197
|
}
|
|
@@ -214,6 +220,57 @@ function handleDropzoneDrop(target: TransferList, event: DragEvent) {
|
|
|
214
220
|
clearDragState()
|
|
215
221
|
}
|
|
216
222
|
|
|
223
|
+
function handleTargetItemDragOver(index: number, event: DragEvent) {
|
|
224
|
+
if (!canDropInto('target'))
|
|
225
|
+
return
|
|
226
|
+
|
|
227
|
+
// Handle the drop at the item level so it lands at a precise position.
|
|
228
|
+
event.preventDefault()
|
|
229
|
+
event.stopPropagation()
|
|
230
|
+
activeDropzone.value = 'target'
|
|
231
|
+
dragOverIndex.value = index
|
|
232
|
+
if (event.dataTransfer)
|
|
233
|
+
event.dataTransfer.dropEffect = 'move'
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function handleTargetItemDrop(index: number, event: DragEvent) {
|
|
237
|
+
if (!canDropInto('target')) {
|
|
238
|
+
clearDragState()
|
|
239
|
+
return
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
event.preventDefault()
|
|
243
|
+
event.stopPropagation()
|
|
244
|
+
|
|
245
|
+
const referenceItem = targetItems.value[index]
|
|
246
|
+
const itemsToInsert = getUniqueItems(draggedItems.value)
|
|
247
|
+
|
|
248
|
+
if (dragSource.value === 'target') {
|
|
249
|
+
// Reorder within the target list: move the dragged items to the drop position.
|
|
250
|
+
if (itemsToInsert.some(dragged => isSameOption(dragged, referenceItem))) {
|
|
251
|
+
clearDragState()
|
|
252
|
+
return
|
|
253
|
+
}
|
|
254
|
+
const remaining = targetItems.value.filter(item => !itemsToInsert.some(dragged => isSameOption(dragged, item)))
|
|
255
|
+
let insertAt = remaining.findIndex(item => isSameOption(item, referenceItem))
|
|
256
|
+
if (insertAt === -1)
|
|
257
|
+
insertAt = remaining.length
|
|
258
|
+
remaining.splice(insertAt, 0, ...itemsToInsert)
|
|
259
|
+
targetItems.value = remaining
|
|
260
|
+
targetSelection.value = []
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
// Cross-list move: insert the dragged source items at the drop position.
|
|
264
|
+
const additions = itemsToInsert.filter(item => !targetItems.value.some(candidate => isSameOption(candidate, item)))
|
|
265
|
+
const updated = [...targetItems.value]
|
|
266
|
+
updated.splice(index, 0, ...additions)
|
|
267
|
+
targetItems.value = updated
|
|
268
|
+
sourceSelection.value = []
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
clearDragState()
|
|
272
|
+
}
|
|
273
|
+
|
|
217
274
|
function resolveOptionDisabled(option: any): boolean {
|
|
218
275
|
const optionDisabled = props.context.optionDisabled
|
|
219
276
|
if (!optionDisabled)
|
|
@@ -495,9 +552,14 @@ watch(() => modelValue.value, (newVal) => {
|
|
|
495
552
|
<div
|
|
496
553
|
:draggable="transferDragDrop && !context.disabled && !resolveOptionDisabled(slotProps.option)"
|
|
497
554
|
class="p-formkit-transfer-option"
|
|
498
|
-
:class="{
|
|
555
|
+
:class="{
|
|
556
|
+
'p-formkit-transfer-option-draggable': transferDragDrop && !context.disabled && !resolveOptionDisabled(slotProps.option),
|
|
557
|
+
'p-formkit-transfer-option-dragover': dragOverIndex === slotProps.index,
|
|
558
|
+
}"
|
|
499
559
|
@dragstart="handleOptionDragStart('target', slotProps.option, $event)"
|
|
500
560
|
@dragend="handleOptionDragEnd"
|
|
561
|
+
@dragover="handleTargetItemDragOver(slotProps.index, $event)"
|
|
562
|
+
@drop="handleTargetItemDrop(slotProps.index, $event)"
|
|
501
563
|
>
|
|
502
564
|
<component
|
|
503
565
|
:is="context?.slots.option"
|
|
@@ -529,4 +591,8 @@ watch(() => modelValue.value, (newVal) => {
|
|
|
529
591
|
outline: 2px dashed var(--p-primary-color);
|
|
530
592
|
outline-offset: 2px;
|
|
531
593
|
}
|
|
594
|
+
|
|
595
|
+
.p-formkit-transfer-option-dragover {
|
|
596
|
+
box-shadow: inset 0 2px 0 0 var(--p-primary-color);
|
|
597
|
+
}
|
|
532
598
|
</style>
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sfxcode/formkit-primevue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.2.
|
|
4
|
+
"version": "4.2.4",
|
|
5
5
|
"packageManager": "pnpm@11.0.9+sha512.34ce82e6780233cf9cad8685029a8f81d2e06196c5a9bad98879f7424940c6817c4e4524fb7d38b8553ceed48b9758b8ebaf1abd3600c232c4c8cf7366086f38",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Tom",
|