Skip to content

Commit

Permalink
add autoscroll for outside drop
Browse files Browse the repository at this point in the history
  • Loading branch information
rouk1 committed Oct 17, 2024
1 parent 7cf5528 commit 31a06bc
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions skore-ui/src/components/DraggableList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const movingItemAsPngData = ref("");
const movingItemHeight = ref(0);
const movingItemY = ref(0);
const container = useTemplateRef("container");
const debug = ref("");
let draggable: Interactable;
let direction: "up" | "down" | "none" = "none";
let autoScrollContainer: HTMLElement = document.body;
Expand Down Expand Up @@ -91,11 +90,24 @@ function setDropIndicatorPosition(y: number) {
}
function onDragOver(event: DragEvent) {
// scroll the container if needed
const scrollBounds = autoScrollContainer.getBoundingClientRect();
const distanceToTop = Math.abs(event.pageY - scrollBounds.top);
const distanceToBottom = Math.abs(event.pageY - scrollBounds.bottom);
const threshold = 150;
const speed = 5;
if (distanceToTop < threshold) {
autoScrollContainer.scrollTop -= speed;
} else if (distanceToBottom < threshold) {
const maxScroll = autoScrollContainer.scrollHeight - scrollBounds.height;
autoScrollContainer.scrollTop = Math.min(maxScroll, autoScrollContainer.scrollTop + speed);
}
// show drop indicator to the closest item
setDropIndicatorPosition(event.pageY);
if (dropIndicatorPosition.value !== null) {
currentDropPosition.value = dropIndicatorPosition.value;
currentDropPosition.value = dropIndicatorPosition.value + 1;
}
}
Expand Down Expand Up @@ -198,12 +210,6 @@ onBeforeUnmount(() => {

<template>
<div class="draggable" :class="{ dragging: movingItemIndex !== -1 }" ref="container">
<!-- <div style="position: fixed; top: 0; right: 0; background: black; color: antiquewhite">
> movingItemY: {{ movingItemY }} movingItemIndex: {{ movingItemIndex }} dropIndicatorPosition:
{{ dropIndicatorPosition }} movingItemHeight: {{ movingItemHeight }}
<hr />
{{ debug }}
</div> -->
<div v-for="(item, index) in items" class="item" :key="item.id">
<div class="handle" :data-index="index"><span class="icon-handle" /></div>
<div class="content-wrapper">
Expand Down

0 comments on commit 31a06bc

Please sign in to comment.