fix(boards): keep kanban card drag from locking after a few moves
Reset hung move queues, defer drag visuals past dragstart, and prefer card drop identity so HTML5 DnD no longer dies mid-drag. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, ref, watch } from 'vue';
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import axios from 'axios';
|
||||
import type {
|
||||
@@ -71,6 +71,43 @@ let peekLinger = 0;
|
||||
const moving = ref(false);
|
||||
const stageBusy = ref(false);
|
||||
const localOrder = ref<string[] | null>(null);
|
||||
/** صف جابهجایی تا دراپ پشتسرهم قفل نشود؛ در watchdog هم ریست میشود */
|
||||
let moveChain: Promise<void> = Promise.resolve();
|
||||
let moveWatchdog = 0;
|
||||
/** هویت درگ بیرون از reactivity تا clear/re-render وسط drop شناسه را نبلعد */
|
||||
let dragSessionId: string | null = null;
|
||||
let dragVisualTimer = 0;
|
||||
|
||||
function clearDragState() {
|
||||
window.clearTimeout(dragVisualTimer);
|
||||
dragSessionId = null;
|
||||
draggingId.value = null;
|
||||
dropStageId.value = null;
|
||||
overlayDeal.value = null;
|
||||
draggingColumnId.value = null;
|
||||
}
|
||||
|
||||
function resetMoveLock() {
|
||||
window.clearTimeout(moveWatchdog);
|
||||
moving.value = false;
|
||||
moveChain = Promise.resolve();
|
||||
}
|
||||
|
||||
function armMoveWatchdog() {
|
||||
window.clearTimeout(moveWatchdog);
|
||||
moveWatchdog = window.setTimeout(() => {
|
||||
resetMoveLock();
|
||||
}, 12_000);
|
||||
}
|
||||
|
||||
function enqueueMove(task: () => Promise<void>) {
|
||||
const run = moveChain.then(task, task);
|
||||
moveChain = run.then(
|
||||
() => undefined,
|
||||
() => undefined,
|
||||
);
|
||||
return run;
|
||||
}
|
||||
|
||||
const KIND_BADGE: Record<ActivityStageDto['kind'], string | undefined> = {
|
||||
open: undefined,
|
||||
@@ -227,14 +264,12 @@ function onMenuActivity(id: string) {
|
||||
}
|
||||
|
||||
function onDragStart(deal: PipelineDeal, event: DragEvent) {
|
||||
// اگر شناسهٔ درگ ستون گیر کرده باشد، دراپ کارت را ستونجابهجا میبیند
|
||||
draggingColumnId.value = null;
|
||||
draggingId.value = deal.id;
|
||||
overlayDeal.value = deal;
|
||||
const sid = findStageOf(deal.id);
|
||||
overlayAccent.value =
|
||||
(props.stages.find((s) => s.id === sid)?.color as PipelineAccent | undefined) ?? 'green';
|
||||
overlayPos.value = { x: (event.clientX || 0) + 12, y: (event.clientY || 0) + 12 };
|
||||
// قفل/صف مانده از درخواست قبلی را باز کن
|
||||
if (moving.value) resetMoveLock();
|
||||
|
||||
dragSessionId = deal.id;
|
||||
// setData / setDragImage باید همزمان با dragstart باشند
|
||||
event.dataTransfer?.setData('text/plain', deal.id);
|
||||
if (event.dataTransfer) {
|
||||
event.dataTransfer.effectAllowed = 'move';
|
||||
@@ -242,21 +277,44 @@ function onDragStart(deal: PipelineDeal, event: DragEvent) {
|
||||
img.src = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
|
||||
event.dataTransfer.setDragImage(img, 0, 0);
|
||||
}
|
||||
// بستن پیشنمایش وسط dragstart گاهی خودِ درگ را لغو میکند
|
||||
if (quickId.value) void nextTick(() => closeQuick());
|
||||
|
||||
const sid = findStageOf(deal.id);
|
||||
overlayAccent.value =
|
||||
(props.stages.find((s) => s.id === sid)?.color as PipelineAccent | undefined) ?? 'green';
|
||||
overlayPos.value = { x: (event.clientX || 0) + 12, y: (event.clientY || 0) + 12 };
|
||||
|
||||
// تغییر DOM (opacity/overlay/بستن peek) داخل dragstart درگ HTML5 را در کروم لغو میکند
|
||||
window.clearTimeout(dragVisualTimer);
|
||||
dragVisualTimer = window.setTimeout(() => {
|
||||
if (dragSessionId !== deal.id) return;
|
||||
draggingId.value = deal.id;
|
||||
overlayDeal.value = deal;
|
||||
if (quickId.value) closeQuick();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
function onDragEnd() {
|
||||
const endedId = draggingId.value;
|
||||
// drop معمولاً قبل از dragend است؛ کمی تأخیر تا fallback شناسه از بین نرود
|
||||
const endedId = dragSessionId ?? draggingId.value;
|
||||
window.setTimeout(() => {
|
||||
if (draggingId.value !== endedId) return;
|
||||
draggingId.value = null;
|
||||
dropStageId.value = null;
|
||||
overlayDeal.value = null;
|
||||
if (dragSessionId && dragSessionId !== endedId) return;
|
||||
if (draggingId.value && draggingId.value !== endedId) return;
|
||||
clearDragState();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
function onColumnDragStart(id: string) {
|
||||
window.clearTimeout(dragVisualTimer);
|
||||
dragSessionId = null;
|
||||
draggingId.value = null;
|
||||
overlayDeal.value = null;
|
||||
draggingColumnId.value = id;
|
||||
}
|
||||
|
||||
function onColumnDragEnd() {
|
||||
draggingColumnId.value = null;
|
||||
dropStageId.value = null;
|
||||
}
|
||||
|
||||
function onDragOver(stageId: string, event: DragEvent) {
|
||||
event.preventDefault();
|
||||
dropStageId.value = stageId;
|
||||
@@ -269,17 +327,19 @@ function onDragOver(stageId: string, event: DragEvent) {
|
||||
async function moveCard(activityId: string, toStageId: string, index?: number) {
|
||||
const fromStageId = findStageOf(activityId);
|
||||
if (!fromStageId) return;
|
||||
const from = columns.value[fromStageId]!;
|
||||
const from = columns.value[fromStageId];
|
||||
const to = columns.value[toStageId];
|
||||
if (!to) return;
|
||||
if (!from || !to) return;
|
||||
const fromIndex = from.items.findIndex((i) => i.id === activityId);
|
||||
const item = from.items[fromIndex];
|
||||
if (!item) return;
|
||||
const toStage = props.stages.find((s) => s.id === toStageId)!;
|
||||
const toStage = props.stages.find((s) => s.id === toStageId);
|
||||
if (!toStage) return;
|
||||
const same = fromStageId === toStageId;
|
||||
const without = (same ? from.items : to.items).filter((i) => i.id !== activityId);
|
||||
if (same && index == null) return;
|
||||
let insertAt = index == null || index < 0 ? 0 : index;
|
||||
// بدون ایندکس صریح → ته ستون (همتراز با بورد معامله)
|
||||
let insertAt = index == null || index < 0 ? without.length : index;
|
||||
if (same && index != null && index > fromIndex) insertAt -= 1;
|
||||
insertAt = Math.max(0, Math.min(insertAt, without.length));
|
||||
if (same && insertAt === fromIndex) return;
|
||||
@@ -301,6 +361,7 @@ async function moveCard(activityId: string, toStageId: string, index?: number) {
|
||||
}
|
||||
|
||||
moving.value = true;
|
||||
armMoveWatchdog();
|
||||
try {
|
||||
const { data } = await api.patch<ActivityDto>(`/activities/${activityId}/stage`, {
|
||||
stageId: toStageId,
|
||||
@@ -333,6 +394,7 @@ async function moveCard(activityId: string, toStageId: string, index?: number) {
|
||||
}
|
||||
emit('error', apiMessage(e, 'جابهجایی فعالیت ناموفق بود.'));
|
||||
} finally {
|
||||
window.clearTimeout(moveWatchdog);
|
||||
moving.value = false;
|
||||
}
|
||||
}
|
||||
@@ -340,23 +402,24 @@ async function moveCard(activityId: string, toStageId: string, index?: number) {
|
||||
async function onDrop(stageId: string, event: DragEvent, index?: number) {
|
||||
event.preventDefault();
|
||||
const transfer = event.dataTransfer?.getData('text/plain') || '';
|
||||
const cardId = draggingId.value;
|
||||
const cardId = dragSessionId || draggingId.value;
|
||||
const columnId = draggingColumnId.value;
|
||||
dropStageId.value = null;
|
||||
draggingId.value = null;
|
||||
overlayDeal.value = null;
|
||||
draggingColumnId.value = null;
|
||||
clearDragState();
|
||||
|
||||
const isStageDrag = transfer.startsWith('stage:');
|
||||
if (isStageDrag || (!transfer && !cardId && columnId)) {
|
||||
const fromId = isStageDrag ? transfer.slice('stage:'.length) : columnId;
|
||||
if (fromId) await reorderColumn(fromId, stageId);
|
||||
// کارت همیشه بر payload ستون اولویت دارد تا درگ کارت بهاشتباه reorder ستون نشود
|
||||
const activityId =
|
||||
cardId || (transfer && !transfer.startsWith('stage:') ? transfer : '');
|
||||
if (activityId) {
|
||||
// fire-and-forget: await روی زنجیرهٔ گیرکرده نباید drop بعدی را قفل کند
|
||||
void enqueueMove(() => moveCard(activityId, stageId, index));
|
||||
return;
|
||||
}
|
||||
|
||||
const activityId = (!isStageDrag && transfer) || cardId || '';
|
||||
if (!activityId || moving.value) return;
|
||||
await moveCard(activityId, stageId, index);
|
||||
const isStageDrag = transfer.startsWith('stage:');
|
||||
if (isStageDrag || columnId) {
|
||||
const fromId = isStageDrag ? transfer.slice('stage:'.length) : columnId;
|
||||
if (fromId) await reorderColumn(fromId, stageId);
|
||||
}
|
||||
}
|
||||
|
||||
async function persistOrder(ids: string[]) {
|
||||
@@ -514,8 +577,8 @@ function openFullActivity(id: string) {
|
||||
@rename-stage="onRenameStage"
|
||||
@delete-stage="onDeleteStage"
|
||||
@move-stage="onMoveStage"
|
||||
@column-drag-start="(id: string) => { draggingId = null; overlayDeal = null; draggingColumnId = id; }"
|
||||
@column-drag-end="draggingColumnId = null; dropStageId = null"
|
||||
@column-drag-start="onColumnDragStart"
|
||||
@column-drag-end="onColumnDragEnd"
|
||||
@add-stage="onAddStage"
|
||||
@load-more="loadMore"
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user