Skip to content

Commit 83cc24f

Browse files
reverts most requestanimationframes related to adding and removing of classes
1 parent 6a53278 commit 83cc24f

File tree

8 files changed

+88
-24
lines changed

8 files changed

+88
-24
lines changed

dist/index.cjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,6 +2234,7 @@ function handleEnd3(state2) {
22342234
if (state2.originalZIndex !== void 0) {
22352235
state2.draggedNode.el.style.zIndex = state2.originalZIndex;
22362236
}
2237+
<<<<<<< Updated upstream
22372238
removeClass(
22382239
state2.draggedNodes.map((x) => x.el),
22392240
dropZoneClass
@@ -2246,6 +2247,22 @@ function handleEnd3(state2) {
22462247
state2.draggedNodes.map((x) => x.el),
22472248
isSynth ? state2.initialParent.data.config.synthDragPlaceholderClass : state2.initialParent.data?.config?.dragPlaceholderClass
22482249
);
2250+
=======
2251+
requestAnimationFrame(() => {
2252+
removeClass(
2253+
state2.draggedNodes.map((x) => x.el),
2254+
dropZoneClass
2255+
);
2256+
removeClass(
2257+
state2.draggedNodes.map((x) => x.el),
2258+
state2.initialParent.data?.config?.longPressClass
2259+
);
2260+
removeClass(
2261+
state2.draggedNodes.map((x) => x.el),
2262+
isSynth ? state2.initialParent.data.config.synthDragPlaceholderClass : state2.initialParent.data?.config?.dragPlaceholderClass
2263+
);
2264+
});
2265+
>>>>>>> Stashed changes
22492266
deselect(state2.draggedNodes, state2.currentParent, state2);
22502267
setActive(state2.currentParent, void 0, state2);
22512268
resetState();

dist/index.cjs.map

Lines changed: 5 additions & 1 deletion
Large diffs are not rendered by default.

dist/index.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,6 +2144,7 @@ function handleEnd3(state2) {
21442144
if (state2.originalZIndex !== void 0) {
21452145
state2.draggedNode.el.style.zIndex = state2.originalZIndex;
21462146
}
2147+
<<<<<<< Updated upstream
21472148
removeClass(
21482149
state2.draggedNodes.map((x) => x.el),
21492150
dropZoneClass
@@ -2156,6 +2157,22 @@ function handleEnd3(state2) {
21562157
state2.draggedNodes.map((x) => x.el),
21572158
isSynth ? state2.initialParent.data.config.synthDragPlaceholderClass : state2.initialParent.data?.config?.dragPlaceholderClass
21582159
);
2160+
=======
2161+
requestAnimationFrame(() => {
2162+
removeClass(
2163+
state2.draggedNodes.map((x) => x.el),
2164+
dropZoneClass
2165+
);
2166+
removeClass(
2167+
state2.draggedNodes.map((x) => x.el),
2168+
state2.initialParent.data?.config?.longPressClass
2169+
);
2170+
removeClass(
2171+
state2.draggedNodes.map((x) => x.el),
2172+
isSynth ? state2.initialParent.data.config.synthDragPlaceholderClass : state2.initialParent.data?.config?.dragPlaceholderClass
2173+
);
2174+
});
2175+
>>>>>>> Stashed changes
21592176
deselect(state2.draggedNodes, state2.currentParent, state2);
21602177
setActive(state2.currentParent, void 0, state2);
21612178
resetState();

dist/index.mjs.map

Lines changed: 5 additions & 1 deletion
Large diffs are not rendered by default.

playwright/tests/synthetic-drag/place.spec.ts renamed to playwright/tests/synthetic-drag/drop-or-swap.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ test.beforeEach(async ({ browser }) => {
99
page = await browser.newPage();
1010
});
1111

12-
test.describe("Place plugin synthetic", async () => {
12+
test.describe("Drop or swap plugin synthetic", async () => {
1313
test("Test #1", async () => {
1414
await page.goto("http://localhost:3001/drop-or-swap");
1515
await new Promise((r) => setTimeout(r, 1000));

playwright/tests/synthetic-drag/swap.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test.describe("Synthetic swap", async () => {
2121
dragStart: true,
2222
});
2323
await expect(page.locator("#Apple")).toHaveClass(
24-
"item synthDragPlaceholder synthDropZone"
24+
"item synthDropZone synthDragPlaceholder"
2525
);
2626

2727
await syntheticDrag(page, {

src/index.ts

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,7 @@ export function dragstartClasses<T>(
15581558
isSynth ? config.synthDraggingClass : config.draggingClass
15591559
);
15601560

1561-
requestAnimationFrame(() => {
1561+
setTimeout(() => {
15621562
removeClass(
15631563
nodes.map((x) => x.el),
15641564
isSynth ? config.synthDraggingClass : config.draggingClass
@@ -1862,12 +1862,15 @@ export function handleEnd<T>(state: DragState<T> | SynthDragState<T>) {
18621862
clearTimeout(state.longPressTimeout);
18631863
}
18641864

1865+
// Ensure scrolling is properly cancelled
18651866
cancelSynthScroll(state);
18661867

1868+
// Clear any lingering scroll directions and timeouts
18671869
state.lastScrollDirectionX = undefined;
18681870
state.lastScrollDirectionY = undefined;
18691871
state.preventEnter = false;
18701872

1873+
// CRITICAL: Clear the scroll debounce timeout
18711874
if (state.scrollDebounceTimeout) {
18721875
clearTimeout(state.scrollDebounceTimeout);
18731876
state.scrollDebounceTimeout = undefined;
@@ -1881,11 +1884,11 @@ export function handleEnd<T>(state: DragState<T> | SynthDragState<T>) {
18811884
? config?.synthDropZoneClass
18821885
: config?.dropZoneClass;
18831886

1884-
requestAnimationFrame(() => {
1885-
if (state.originalZIndex !== undefined) {
1886-
state.draggedNode.el.style.zIndex = state.originalZIndex;
1887-
}
1887+
if (state.originalZIndex !== undefined) {
1888+
state.draggedNode.el.style.zIndex = state.originalZIndex;
1889+
}
18881890

1891+
requestAnimationFrame(() => {
18891892
removeClass(
18901893
state.draggedNodes.map((x) => x.el),
18911894
dropZoneClass
@@ -1902,12 +1905,14 @@ export function handleEnd<T>(state: DragState<T> | SynthDragState<T>) {
19021905
? state.initialParent.data.config.synthDragPlaceholderClass
19031906
: state.initialParent.data?.config?.dragPlaceholderClass
19041907
);
1905-
1906-
deselect(state.draggedNodes, state.currentParent, state);
1907-
setActive(state.currentParent, undefined, state);
19081908
});
19091909

1910+
deselect(state.draggedNodes, state.currentParent, state);
1911+
1912+
setActive(state.currentParent, undefined, state);
1913+
19101914
resetState();
1915+
19111916
state.selectedState = undefined;
19121917

19131918
config?.onDragend?.({
@@ -2703,24 +2708,19 @@ export function addNodeClass<T>(
27032708
className: string | undefined,
27042709
omitAppendPrivateClass = false
27052710
) {
2706-
if (!className) return;
2707-
27082711
function nodeSetter<T>(node: Node, nodeData: NodeData<T>) {
27092712
nodes.set(node, nodeData);
27102713
}
27112714

2712-
// Use requestAnimationFrame to ensure class addition happens during proper rendering cycle
2713-
requestAnimationFrame(() => {
2714-
for (const el of els) {
2715-
const nodeData = nodes.get(el as Node);
2715+
for (const el of els) {
2716+
const nodeData = nodes.get(el as Node);
27162717

2717-
const newData = addClass(el, className, nodeData, omitAppendPrivateClass);
2718+
const newData = addClass(el, className, nodeData, omitAppendPrivateClass);
27182719

2719-
if (!newData) continue;
2720+
if (!newData) continue;
27202721

2721-
nodeSetter(el as Node, newData as NodeData<T>);
2722-
}
2723-
});
2722+
nodeSetter(el as Node, newData as NodeData<T>);
2723+
}
27242724
}
27252725

27262726
/**
@@ -2801,7 +2801,11 @@ export function addClass(
28012801
}
28022802

28032803
/**
2804+
<<<<<<< Updated upstream
28042805
* Remove class from the nodes using requestAnimationFrame for better timing.
2806+
=======
2807+
* Remove class from the nodes.
2808+
>>>>>>> Stashed changes
28052809
*
28062810
* @param els - The nodes.
28072811
* @param className - The class name.
@@ -2818,6 +2822,7 @@ export function removeClass(
28182822

28192823
if (!classNames.length) return;
28202824

2825+
<<<<<<< Updated upstream
28212826
// Use requestAnimationFrame to ensure class removal happens during proper rendering cycle
28222827
requestAnimationFrame(() => {
28232828
for (const node of els) {
@@ -2837,6 +2842,24 @@ export function removeClass(
28372842
}
28382843
}
28392844
});
2845+
=======
2846+
for (const node of els) {
2847+
if (!isNode(node)) {
2848+
node.classList.remove(...classNames);
2849+
continue;
2850+
}
2851+
2852+
const nodeData = nodes.get(node) || parents.get(node);
2853+
2854+
if (!nodeData) continue;
2855+
2856+
for (const className of classNames) {
2857+
if (!nodeData.privateClasses.includes(className)) {
2858+
node.classList.remove(className);
2859+
}
2860+
}
2861+
}
2862+
>>>>>>> Stashed changes
28402863
}
28412864

28422865
type ScrollDirection<T> = { axis: "x"; state: DragState<T> } | { axis: "y" };

tests/pages/drop-or-swap/index.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ const [parent2, values2] = useDragAndDrop(["Tomato", "Potato", "Onion"], {
109109
text-align: center;
110110
background-color: #f9f9f9;
111111
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.1);
112-
transition: transform 0.2s;
113112
width: 400px;
114113
height: 50px;
115114
}

0 commit comments

Comments
 (0)