fluid-dnd 2.2.1 → 2.4.0
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.
- package/dist/{HandlerPublisher-DGYFIYDd.cjs → HandlerPublisher-B68XPAcH.cjs} +1 -1
- package/dist/{HandlerPublisher-CRBvk0J7.js → HandlerPublisher-pcX0Zmas.js} +1 -1
- package/dist/core/{configHandler.d.ts → config/configHandler.d.ts} +2 -2
- package/dist/core/{configHandler.js → config/configHandler.js} +4 -5
- package/dist/core/{utils → config}/droppableConfigurator.d.ts +3 -3
- package/dist/core/{utils → config}/droppableConfigurator.js +28 -11
- package/dist/core/dragAndDrop.d.ts +3 -3
- package/dist/core/dragAndDrop.js +53 -9
- package/dist/core/events/changeDraggableStyles.d.ts +4 -0
- package/dist/core/events/changeDraggableStyles.js +40 -0
- package/dist/core/events/dragAndDrop/dragAndDrop.d.ts +9 -0
- package/dist/core/{utils/events/emitEvents.js → events/dragAndDrop/dragAndDrop.js} +26 -145
- package/dist/core/{utils/translate/GetTranslateBeforeDropping.d.ts → events/dragAndDrop/getTranslateBeforeDropping.d.ts} +2 -2
- package/dist/core/{utils/translate/GetTranslateBeforeDropping.js → events/dragAndDrop/getTranslateBeforeDropping.js} +7 -15
- package/dist/core/{utils/translate/GetTranslationByDraggingAndEvent.d.ts → events/dragAndDrop/getTranslationByDraggingAndEvent.d.ts} +2 -2
- package/dist/core/{utils/translate/GetTranslationByDraggingAndEvent.js → events/dragAndDrop/getTranslationByDraggingAndEvent.js} +4 -4
- package/dist/core/events/insert.d.ts +4 -0
- package/dist/core/events/insert.js +80 -0
- package/dist/core/events/remove.d.ts +4 -0
- package/dist/core/events/remove.js +51 -0
- package/dist/core/positioning/autoScroll.d.ts +5 -0
- package/dist/core/positioning/autoScroll.js +51 -0
- package/dist/core/{utils/SetTransform.d.ts → positioning/usePositioning.d.ts} +1 -1
- package/dist/core/{utils/SetTransform.js → positioning/usePositioning.js} +7 -30
- package/dist/core/{utils/tempChildren.d.ts → tempChildren.d.ts} +1 -2
- package/dist/core/{utils/tempChildren.js → tempChildren.js} +22 -29
- package/dist/core/useDraggable.js +16 -12
- package/dist/core/utils/GetStyles.d.ts +3 -3
- package/dist/core/utils/GetStyles.js +48 -36
- package/dist/core/utils/SetStyles.d.ts +3 -3
- package/dist/core/utils/SetStyles.js +12 -12
- package/dist/core/utils/observer.d.ts +1 -0
- package/dist/core/utils/observer.js +8 -0
- package/dist/index-2hBSSK9_.cjs +1 -0
- package/dist/index-DFXw7kYo.js +1223 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.mjs +4 -11
- package/dist/react/utils/ReactLilstConfig.d.ts +2 -2
- package/dist/react/utils/ReactLilstConfig.js +7 -17
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.mjs +2 -2
- package/dist/svelte/utils/SvelteListCondig.js +1 -1
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.mjs +2 -2
- package/dist/vue/utils/VueListCondig.d.ts +3 -3
- package/dist/vue/utils/VueListCondig.js +2 -5
- package/package.json +1 -1
- package/dist/core/utils/config.d.ts +0 -5
- package/dist/core/utils/config.js +0 -57
- package/dist/core/utils/events/emitEvents.d.ts +0 -11
- package/dist/core/utils/scroll.d.ts +0 -4
- package/dist/core/utils/scroll.js +0 -17
- package/dist/index-Dc95WWpv.js +0 -1271
- package/dist/index-DxKyk1TO.cjs +0 -1
- /package/dist/core/utils/{touchDevice.d.ts → typesCheckers.d.ts} +0 -0
- /package/dist/core/utils/{touchDevice.js → typesCheckers.js} +0 -0
@@ -0,0 +1,80 @@
|
|
1
|
+
import { getParentDraggableChildren, getSiblings } from '../utils/GetStyles';
|
2
|
+
import getTranslationByDragging from '../events/dragAndDrop/getTranslationByDraggingAndEvent';
|
3
|
+
import { IsHTMLElement } from '../utils/typesCheckers';
|
4
|
+
import { removeTempChild } from '../tempChildren';
|
5
|
+
import { DISABLE_TRANSITION, DRAGGABLE_CLASS } from '../utils/classes';
|
6
|
+
import { addClass, containClass, removeClass } from '../utils/dom/classList';
|
7
|
+
import { isTempElement, observeMutation } from '../utils/observer';
|
8
|
+
import { useChangeDraggableStyles } from './changeDraggableStyles';
|
9
|
+
export default function useInsertEvents(currentConfig, parent, handlerPublisher, endDraggingAction) {
|
10
|
+
const { delayBeforeInsert } = currentConfig;
|
11
|
+
const [removeElementDraggingStyles, _, dragEventOverElement] = useChangeDraggableStyles(currentConfig, handlerPublisher, endDraggingAction);
|
12
|
+
// #region Insert
|
13
|
+
const emitInsertEventToSiblings = (targetIndex, draggedElement, droppable, value, startInserting) => {
|
14
|
+
const translation = getTranslationByDragging(draggedElement, 'insert', currentConfig.direction, droppable);
|
15
|
+
const { onInsertEvent } = currentConfig;
|
16
|
+
const siblings = getParentDraggableChildren(droppable);
|
17
|
+
for (const [index, sibling] of siblings.entries()) {
|
18
|
+
if (!containClass(sibling, DRAGGABLE_CLASS)) {
|
19
|
+
continue;
|
20
|
+
}
|
21
|
+
if (index >= targetIndex) {
|
22
|
+
dragEventOverElement(sibling, translation);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
startInserting();
|
26
|
+
setTimeout(() => {
|
27
|
+
onInsertEvent(targetIndex, value);
|
28
|
+
onFinishInsertElement(targetIndex, droppable, currentConfig);
|
29
|
+
removeElementDraggingStyles(draggedElement);
|
30
|
+
removeTranslateFromSiblings(draggedElement, parent);
|
31
|
+
removeTempChild(parent, 0, true);
|
32
|
+
}, delayBeforeInsert);
|
33
|
+
};
|
34
|
+
const removeTranslateFromSiblings = (element, parent) => {
|
35
|
+
const [siblings] = getSiblings(element, parent);
|
36
|
+
for (const sibling of [...siblings, element]) {
|
37
|
+
removeTranslateWhitoutTransition(sibling);
|
38
|
+
}
|
39
|
+
};
|
40
|
+
const removeTranslateWhitoutTransition = (element) => {
|
41
|
+
if (IsHTMLElement(element)) {
|
42
|
+
element.style.transition = '';
|
43
|
+
element.style.transform = '';
|
44
|
+
}
|
45
|
+
};
|
46
|
+
return [emitInsertEventToSiblings];
|
47
|
+
}
|
48
|
+
const childrenMutationFilter = (mutation) => {
|
49
|
+
const addedNodes = mutation.addedNodes
|
50
|
+
.values()
|
51
|
+
.filter((element) => !isTempElement(element))
|
52
|
+
.toArray();
|
53
|
+
return addedNodes.length > 0;
|
54
|
+
};
|
55
|
+
const onFinishInsertElement = (targetIndex, droppable, config) => {
|
56
|
+
const { insertingFromClass, animationDuration } = config;
|
57
|
+
const observer = observeMutation(() => {
|
58
|
+
const siblings = getParentDraggableChildren(droppable);
|
59
|
+
const newElement = siblings[targetIndex];
|
60
|
+
addClass(newElement, insertingFromClass);
|
61
|
+
addClass(newElement, DISABLE_TRANSITION);
|
62
|
+
setTimeout(() => {
|
63
|
+
removeClass(newElement, DISABLE_TRANSITION);
|
64
|
+
removeClass(newElement, insertingFromClass);
|
65
|
+
observer.disconnect();
|
66
|
+
}, animationDuration);
|
67
|
+
}, droppable, {
|
68
|
+
childList: true
|
69
|
+
}, childrenMutationFilter);
|
70
|
+
};
|
71
|
+
export const insertToListEmpty = (config, droppable, targetIndex, value) => {
|
72
|
+
if (!droppable) {
|
73
|
+
return;
|
74
|
+
}
|
75
|
+
const { onInsertEvent, delayBeforeInsert } = config;
|
76
|
+
setTimeout(() => {
|
77
|
+
onInsertEvent(targetIndex, value);
|
78
|
+
onFinishInsertElement(targetIndex, droppable, config);
|
79
|
+
}, delayBeforeInsert);
|
80
|
+
};
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { CoreConfig } from '..';
|
2
|
+
import { DroppableConfig } from '../config/configHandler';
|
3
|
+
import HandlerPublisher from '@/core/HandlerPublisher';
|
4
|
+
export default function useRemoveEvents<T>(currentConfig: CoreConfig<T>, parent: HTMLElement, handlerPublisher: HandlerPublisher, endDraggingAction: () => void): readonly [(targetIndex: number, draggedElement: HTMLElement, droppableConfig: DroppableConfig<T>, onFinishRemoveEvent: (element: HTMLElement) => void) => void, (draggedElement: HTMLElement) => void];
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import { getSiblings } from '../utils/GetStyles';
|
2
|
+
import { moveTranslate } from '../utils/SetStyles';
|
3
|
+
import getTranslationByDragging from './dragAndDrop/getTranslationByDraggingAndEvent';
|
4
|
+
import { IsHTMLElement } from '../utils/typesCheckers';
|
5
|
+
import { removeTempChild } from '../tempChildren';
|
6
|
+
import { useChangeDraggableStyles } from './changeDraggableStyles';
|
7
|
+
export default function useRemoveEvents(currentConfig, parent, handlerPublisher, endDraggingAction) {
|
8
|
+
const { animationDuration } = currentConfig;
|
9
|
+
const [removeElementDraggingStyles] = useChangeDraggableStyles(currentConfig, handlerPublisher, endDraggingAction);
|
10
|
+
const emitRemoveEventToSiblings = (targetIndex, draggedElement, droppableConfig, onFinishRemoveEvent) => {
|
11
|
+
if (!droppableConfig || !droppableConfig.droppable || !droppableConfig.config) {
|
12
|
+
return;
|
13
|
+
}
|
14
|
+
const { droppable, config } = droppableConfig;
|
15
|
+
let [siblings] = getSiblings(draggedElement, droppable);
|
16
|
+
siblings = [draggedElement, ...siblings].toReversed();
|
17
|
+
const translation = getTranslationByDragging(draggedElement, 'remove', config.direction, droppable);
|
18
|
+
for (const [index, sibling] of siblings.entries()) {
|
19
|
+
if (index >= targetIndex) {
|
20
|
+
startDragEventOverElement(sibling, translation);
|
21
|
+
setTimeout(() => {
|
22
|
+
onFinishRemoveEvent(sibling);
|
23
|
+
}, animationDuration);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
};
|
27
|
+
const emitFinishRemoveEventToSiblings = (draggedElement) => {
|
28
|
+
removeTempChild(parent, animationDuration, true);
|
29
|
+
setTimeout(() => {
|
30
|
+
removeElementDraggingStyles(draggedElement);
|
31
|
+
removeTranslateFromSiblings(draggedElement, parent);
|
32
|
+
}, animationDuration);
|
33
|
+
};
|
34
|
+
const startDragEventOverElement = (element, translation) => {
|
35
|
+
const { width, height } = translation;
|
36
|
+
moveTranslate(element, height, width);
|
37
|
+
};
|
38
|
+
const removeTranslateFromSiblings = (element, parent) => {
|
39
|
+
const [siblings] = getSiblings(element, parent);
|
40
|
+
for (const sibling of [...siblings, element]) {
|
41
|
+
removeTranslateWhitoutTransition(sibling);
|
42
|
+
}
|
43
|
+
};
|
44
|
+
const removeTranslateWhitoutTransition = (element) => {
|
45
|
+
if (IsHTMLElement(element)) {
|
46
|
+
element.style.transition = '';
|
47
|
+
element.style.transform = '';
|
48
|
+
}
|
49
|
+
};
|
50
|
+
return [emitRemoveEventToSiblings, emitFinishRemoveEventToSiblings];
|
51
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import { draggableIsCompleteOutside, getPropByDirection } from '../utils/GetStyles';
|
2
|
+
const scrollByDirection = (element, direction, scrollAmount) => {
|
3
|
+
if (scrollAmount == 0) {
|
4
|
+
return;
|
5
|
+
}
|
6
|
+
if (direction === 'vertical') {
|
7
|
+
element.scrollBy(0, scrollAmount);
|
8
|
+
}
|
9
|
+
else {
|
10
|
+
element.scrollBy(scrollAmount, 0);
|
11
|
+
}
|
12
|
+
};
|
13
|
+
export const useScroll = (draggedElement) => {
|
14
|
+
let lastScrollAmount = 0.5;
|
15
|
+
const minScrollAmountDiff = 0.03;
|
16
|
+
const updateScrollByPosition = (direction, parent, position, translate) => {
|
17
|
+
const { before, distance, axis, getRect } = getPropByDirection(direction);
|
18
|
+
const distanceValue = getRect(draggedElement)[distance];
|
19
|
+
const parentBoundingClientRect = getRect(parent);
|
20
|
+
const positionInsideParent = position[before] - parentBoundingClientRect[before] + translate[axis];
|
21
|
+
const parentDistance = parentBoundingClientRect[distance];
|
22
|
+
const totalDistance = parentDistance - distanceValue;
|
23
|
+
const relativePosition = positionInsideParent / totalDistance;
|
24
|
+
const relativeDistanceValue = distanceValue / totalDistance;
|
25
|
+
const velocity = 0.25;
|
26
|
+
const infLimit = 0.2;
|
27
|
+
const upperLimit = 0.8;
|
28
|
+
let percent = 0;
|
29
|
+
const isOutside = draggableIsCompleteOutside(draggedElement, parent);
|
30
|
+
if (!isOutside && relativePosition < infLimit && relativePosition > -relativeDistanceValue) {
|
31
|
+
percent = scrollFuncionToStart(relativePosition < 0 ? 0 : relativePosition, infLimit);
|
32
|
+
}
|
33
|
+
else if (!isOutside &&
|
34
|
+
relativePosition > upperLimit &&
|
35
|
+
relativePosition < 1 + relativeDistanceValue) {
|
36
|
+
percent = scrollFuncionToEnd(relativePosition, upperLimit);
|
37
|
+
}
|
38
|
+
const scrollAmount = velocity * distanceValue * percent;
|
39
|
+
lastScrollAmount =
|
40
|
+
Math.sign(scrollAmount) *
|
41
|
+
Math.min(Math.abs(scrollAmount), Math.abs(lastScrollAmount) + minScrollAmountDiff);
|
42
|
+
scrollByDirection(parent, direction, lastScrollAmount);
|
43
|
+
};
|
44
|
+
const scrollFuncionToStart = (relativePosition, infLimit) => {
|
45
|
+
return Math.pow(relativePosition / infLimit, 1 / 3) - 1;
|
46
|
+
};
|
47
|
+
const scrollFuncionToEnd = (relativePosition, upperLimit) => {
|
48
|
+
return Math.pow((1 / (1 - upperLimit)) * (relativePosition - upperLimit), 3);
|
49
|
+
};
|
50
|
+
return [updateScrollByPosition];
|
51
|
+
};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { DragMouseTouchEvent, TransformEvent } from '../../../index';
|
2
2
|
import { CoordinateMap, Direction } from '..';
|
3
|
-
export declare const
|
3
|
+
export declare const usePositioning: (draggedElement: HTMLElement, coordinateTransforms: CoordinateMap[]) => readonly [(element: HTMLElement, parent: HTMLElement, pagePosition: {
|
4
4
|
pageX: number;
|
5
5
|
pageY: number;
|
6
6
|
}, direction?: Direction) => void, (event: DragMouseTouchEvent, element: HTMLElement) => void];
|
@@ -1,12 +1,13 @@
|
|
1
|
-
import {
|
1
|
+
import { getNearestFixedParentPosition, getPropByDirection, getValueFromProperty } from '../utils/GetStyles';
|
2
2
|
import { HORIZONTAL, VERTICAL } from '..';
|
3
|
-
import {
|
4
|
-
import { HANDLER_CLASS, DRAGGING_CLASS } from '
|
5
|
-
import { containClass } from '
|
6
|
-
export const
|
3
|
+
import { useScroll } from './autoScroll';
|
4
|
+
import { HANDLER_CLASS, DRAGGING_CLASS } from '../utils/classes';
|
5
|
+
import { containClass } from '../utils/dom/classList';
|
6
|
+
export const usePositioning = (draggedElement, coordinateTransforms) => {
|
7
7
|
let currentOffset = { offsetX: 0, offsetY: 0 };
|
8
8
|
let position = { top: 0, left: 0 };
|
9
9
|
let translate = { x: 0, y: 0 };
|
10
|
+
const [updateScrollByPosition] = useScroll(draggedElement);
|
10
11
|
const updateTranform = (newTranslate) => {
|
11
12
|
draggedElement.style.transform = `translate( ${newTranslate.x}px, ${newTranslate.y}px)`;
|
12
13
|
};
|
@@ -41,31 +42,7 @@ export const useTransform = (draggedElement, coordinateTransforms) => {
|
|
41
42
|
};
|
42
43
|
const updateScroll = (translateDirection) => {
|
43
44
|
if (element && containClass(element, DRAGGING_CLASS) && translateDirection === direction) {
|
44
|
-
|
45
|
-
const distanceValue = getRect(element)[distance];
|
46
|
-
const parentBoundingClientRect = getRect(parent);
|
47
|
-
const positionInsideParent = position[before] - parentBoundingClientRect[before] + translate[axis];
|
48
|
-
const parentDistance = parentBoundingClientRect[distance];
|
49
|
-
const totalDistance = parentDistance - distanceValue;
|
50
|
-
const relativePosition = positionInsideParent / totalDistance;
|
51
|
-
const relativeDistanceValue = distanceValue / totalDistance;
|
52
|
-
const velocity = 0.1;
|
53
|
-
const infLimit = 0.2;
|
54
|
-
const upperLimit = 0.8;
|
55
|
-
let percent = 0;
|
56
|
-
const isOutside = draggableIsOutside(element, parent);
|
57
|
-
if (!isOutside &&
|
58
|
-
relativePosition < infLimit &&
|
59
|
-
relativePosition > -relativeDistanceValue) {
|
60
|
-
percent = relativePosition / infLimit - 1;
|
61
|
-
}
|
62
|
-
else if (!isOutside &&
|
63
|
-
relativePosition > upperLimit &&
|
64
|
-
relativePosition < 1 + relativeDistanceValue) {
|
65
|
-
percent = (1 / (1 - upperLimit)) * (relativePosition - upperLimit);
|
66
|
-
}
|
67
|
-
const scrollAmount = velocity * distanceValue * percent;
|
68
|
-
scrollByDirection(parent, direction, scrollAmount);
|
45
|
+
updateScrollByPosition(direction, parent, position, translate);
|
69
46
|
}
|
70
47
|
};
|
71
48
|
const updateTranlateByDirection = (direction) => {
|
@@ -1,5 +1,4 @@
|
|
1
|
-
import { DroppableConfig } from
|
2
|
-
export declare const isTempElement: (element: Node) => boolean;
|
1
|
+
import { DroppableConfig } from './config/configHandler';
|
3
2
|
export declare const addTempChild: <T>(draggedElement: HTMLElement | undefined, parent: Element, ifStartDragging: boolean, droppableConfig?: DroppableConfig<T>, addingAnimationDuration?: number) => void;
|
4
3
|
export declare const addTempChildOnInsert: <T>(draggedElement: HTMLElement | undefined, ifStartDragging: boolean, droppableConfig?: DroppableConfig<T>) => void;
|
5
4
|
export declare const removeTempChildrens: (droppable: HTMLElement, parent: HTMLElement, droppableGroupClass: string | null, animationDuration: number, draggedElementIsOutside?: boolean) => void;
|
@@ -1,22 +1,14 @@
|
|
1
|
-
import { HORIZONTAL, VERTICAL } from
|
2
|
-
import { getPropByDirection } from
|
3
|
-
import { getGapPixels } from
|
4
|
-
import { setSizeStyles, setTranistion } from
|
5
|
-
import { observeMutation } from
|
6
|
-
import getTranslationByDragging from
|
7
|
-
import {
|
8
|
-
import {
|
9
|
-
|
10
|
-
|
11
|
-
const START_DRAG_EVENT = "startDrag";
|
12
|
-
const timingFunction = "cubic-bezier(0.2, 0, 0, 1)";
|
1
|
+
import { HORIZONTAL, VERTICAL } from '.';
|
2
|
+
import { getPropByDirection } from './utils/GetStyles';
|
3
|
+
import { getGapPixels } from './utils/ParseStyles';
|
4
|
+
import { setSizeStyles, setTranistion } from './utils/SetStyles';
|
5
|
+
import { observeMutation } from './utils/observer';
|
6
|
+
import getTranslationByDragging from './events/dragAndDrop/getTranslationByDraggingAndEvent';
|
7
|
+
import { TEMP_CHILD_CLASS } from './utils';
|
8
|
+
import { addClass, getClassesSelector } from './utils/dom/classList';
|
9
|
+
const START_DRAG_EVENT = 'startDrag';
|
10
|
+
const timingFunction = 'cubic-bezier(0.2, 0, 0, 1)';
|
13
11
|
const DELAY_TIME = 50;
|
14
|
-
export const isTempElement = (element) => {
|
15
|
-
if (!IsHTMLElement(element)) {
|
16
|
-
return false;
|
17
|
-
}
|
18
|
-
return element.classList.contains(TEMP_CHILD_CLASS);
|
19
|
-
};
|
20
12
|
const getDistance = (droppable, draggedElement, direction) => {
|
21
13
|
let distances = getTranslationByDragging(draggedElement, START_DRAG_EVENT, direction, droppable);
|
22
14
|
const gap = getGapPixels(droppable, direction);
|
@@ -29,10 +21,7 @@ const getDistance = (droppable, draggedElement, direction) => {
|
|
29
21
|
const getlarge = (direction, draggedElement) => {
|
30
22
|
const largeDirection = direction == HORIZONTAL ? VERTICAL : HORIZONTAL;
|
31
23
|
const { distance, getRect } = getPropByDirection(largeDirection);
|
32
|
-
return [
|
33
|
-
getRect(draggedElement)[distance],
|
34
|
-
distance,
|
35
|
-
];
|
24
|
+
return [getRect(draggedElement)[distance], distance];
|
36
25
|
};
|
37
26
|
const setSizes = (element, height, width) => {
|
38
27
|
setSizeStyles(element, height, width);
|
@@ -47,6 +36,10 @@ const updateChildAfterCreated = (child, droppable, distances) => {
|
|
47
36
|
observer.disconnect();
|
48
37
|
};
|
49
38
|
};
|
39
|
+
const scrollPercent = (direction, droppable, droppableScroll) => {
|
40
|
+
const { scrollDistance, clientDistance, scrollElement } = getPropByDirection(direction);
|
41
|
+
return droppableScroll[scrollElement] / (droppable[scrollDistance] - droppable[clientDistance]);
|
42
|
+
};
|
50
43
|
const fixScrollInitialChange = (droppableConfig, ifStartDragging) => {
|
51
44
|
if (!ifStartDragging) {
|
52
45
|
return;
|
@@ -56,8 +49,7 @@ const fixScrollInitialChange = (droppableConfig, ifStartDragging) => {
|
|
56
49
|
const scrollCompleted = scrollPercent(config.direction, droppable, scroll) > 0.99;
|
57
50
|
const { scrollDistance, clientDistance, scrollElement } = getPropByDirection(direction);
|
58
51
|
if (scrollCompleted) {
|
59
|
-
droppable[scrollElement] =
|
60
|
-
droppable[scrollDistance] - droppable[clientDistance];
|
52
|
+
droppable[scrollElement] = droppable[scrollDistance] - droppable[clientDistance];
|
61
53
|
}
|
62
54
|
};
|
63
55
|
const getTempChild = (draggedElement, ifStartDragging, droppableConfig, addingAnimationDuration) => {
|
@@ -70,12 +62,12 @@ const getTempChild = (draggedElement, ifStartDragging, droppableConfig, addingAn
|
|
70
62
|
if (droppable.querySelector(`.${TEMP_CHILD_CLASS}`) || !draggedElement) {
|
71
63
|
return;
|
72
64
|
}
|
73
|
-
var tempChildTag = draggedElement.tagName ==
|
65
|
+
var tempChildTag = draggedElement.tagName == 'LI' ? 'DIV' : draggedElement.tagName;
|
74
66
|
var child = document.createElement(tempChildTag);
|
75
67
|
addClass(child, TEMP_CHILD_CLASS);
|
76
68
|
setSizes(child, 0, 0);
|
77
69
|
const distances = getDistance(droppable, draggedElement, direction);
|
78
|
-
setTranistion(child, addingAnimationDuration ?? animationDuration, timingFunction,
|
70
|
+
setTranistion(child, addingAnimationDuration ?? animationDuration, timingFunction, 'width, min-width, height');
|
79
71
|
return [child, distances, droppable];
|
80
72
|
};
|
81
73
|
export const addTempChild = (draggedElement, parent, ifStartDragging, droppableConfig, addingAnimationDuration) => {
|
@@ -89,7 +81,7 @@ export const addTempChild = (draggedElement, parent, ifStartDragging, droppableC
|
|
89
81
|
}
|
90
82
|
observeMutation(updateChildAfterCreated(child, droppable, distances), droppable, {
|
91
83
|
childList: true,
|
92
|
-
subtree: true
|
84
|
+
subtree: true
|
93
85
|
});
|
94
86
|
droppable.appendChild(child);
|
95
87
|
};
|
@@ -106,7 +98,7 @@ const setSizeAfterAppendChild = (child, size) => {
|
|
106
98
|
return requestAnimationFrame(() => {
|
107
99
|
setSizes(child, size.height, size.width);
|
108
100
|
requestAnimationFrame(() => {
|
109
|
-
setTranistion(child, 0, timingFunction,
|
101
|
+
setTranistion(child, 0, timingFunction, 'width, min-width, height');
|
110
102
|
});
|
111
103
|
});
|
112
104
|
};
|
@@ -117,7 +109,8 @@ export const removeTempChildrens = (droppable, parent, droppableGroupClass, anim
|
|
117
109
|
var children = document.querySelectorAll(`${getClassesSelector(droppableGroupClass)} > .${TEMP_CHILD_CLASS}`);
|
118
110
|
children.forEach((tempChild) => {
|
119
111
|
const childParent = tempChild.parentElement;
|
120
|
-
if (
|
112
|
+
if (childParent?.isSameNode(parent) ||
|
113
|
+
(!draggedElementIsOutside && childParent?.isSameNode(droppable))) {
|
121
114
|
return;
|
122
115
|
}
|
123
116
|
const tempChildElement = tempChild;
|
@@ -1,13 +1,15 @@
|
|
1
1
|
import { assignDraggingEvent, convetEventToDragMouseTouchEvent, moveTranslate, setCustomFixedSize, setEventWithInterval, setTranistion } from './utils/SetStyles';
|
2
|
-
import {
|
3
|
-
import
|
2
|
+
import { usePositioning } from './positioning/usePositioning';
|
3
|
+
import useRemoveEvents from './events/remove';
|
4
4
|
import { DRAG_EVENT, draggableTargetTimingFunction, START_DRAG_EVENT, START_DROP_EVENT } from './utils';
|
5
|
-
import ConfigHandler from './configHandler';
|
6
|
-
import { IsHTMLElement, isTouchEvent } from './utils/
|
7
|
-
import { addTempChild, addTempChildOnInsert, removeTempChildrens } from './
|
8
|
-
import { DroppableConfigurator } from './
|
5
|
+
import ConfigHandler from './config/configHandler';
|
6
|
+
import { IsHTMLElement, isTouchEvent } from './utils/typesCheckers';
|
7
|
+
import { addTempChild, addTempChildOnInsert, removeTempChildrens } from './tempChildren';
|
8
|
+
import { DroppableConfigurator } from './config/droppableConfigurator';
|
9
9
|
import { addClass, containClass, getClassesList, getClassesSelector, removeClass, toggleClass } from './utils/dom/classList';
|
10
10
|
import { DRAGGABLE_CLASS, DRAGGING_CLASS, DROPPABLE_CLASS, HANDLER_CLASS } from './utils/classes';
|
11
|
+
import useDragAndDropEvents from './events/dragAndDrop/dragAndDrop';
|
12
|
+
import useInsertEvents from './events/insert';
|
11
13
|
var DraggingState;
|
12
14
|
(function (DraggingState) {
|
13
15
|
DraggingState[DraggingState["NOT_DRAGGING"] = 0] = "NOT_DRAGGING";
|
@@ -28,11 +30,13 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
28
30
|
let pagePosition = { pageX: 0, pageY: 0 };
|
29
31
|
let delayTimeout;
|
30
32
|
let initialTouch;
|
31
|
-
const [setTransform, updateTransformState] =
|
33
|
+
const [setTransform, updateTransformState] = usePositioning(draggableElement, coordinateTransform);
|
32
34
|
const endDraggingState = () => {
|
33
35
|
draggingState = DraggingState.NOT_DRAGGING;
|
34
36
|
};
|
35
|
-
const [
|
37
|
+
const [emitRemoveEventToSiblings, emitFinishRemoveEventToSiblings] = useRemoveEvents(config, parent, handlerPublisher, endDraggingState);
|
38
|
+
const [emitDraggingEvent, emitDroppingEvent, toggleDraggingClass] = useDragAndDropEvents(config, index, parent, droppableGroupClass, handlerPublisher, endDraggingState);
|
39
|
+
const [emitInsertEventToSiblings] = useInsertEvents(config, parent, handlerPublisher, endDraggingState);
|
36
40
|
const setDraggable = () => {
|
37
41
|
addClass(draggableElement, DRAGGABLE_CLASS);
|
38
42
|
};
|
@@ -99,13 +103,13 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
99
103
|
}
|
100
104
|
const { droppable, config } = droppableConfigurator.current;
|
101
105
|
setTransform(draggableElement, droppable, pagePosition, config.direction);
|
102
|
-
|
106
|
+
emitDraggingEvent(draggableElement, DRAG_EVENT, droppableConfigurator.current);
|
103
107
|
};
|
104
108
|
const changeDroppable = (newdDroppableConfig, oldDroppableConfig) => {
|
105
109
|
if (oldDroppableConfig &&
|
106
110
|
draggingState == DraggingState.DRAGING &&
|
107
111
|
!newdDroppableConfig?.droppable.isSameNode(oldDroppableConfig.droppable)) {
|
108
|
-
|
112
|
+
emitDraggingEvent(draggableElement, DRAG_EVENT, oldDroppableConfig);
|
109
113
|
}
|
110
114
|
};
|
111
115
|
const droppableConfigurator = new DroppableConfigurator(draggableElement, droppableGroupClass, parent, setTransformDragEvent, changeDroppable, config.mapFrom);
|
@@ -256,7 +260,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
256
260
|
const startDragging = (event) => {
|
257
261
|
addTempChild(draggableElement, parent, draggingState == DraggingState.START_DRAGGING, droppableConfigurator.current);
|
258
262
|
updateDraggingStateBeforeDragging();
|
259
|
-
|
263
|
+
emitDraggingEvent(draggableElement, START_DRAG_EVENT, droppableConfigurator.current);
|
260
264
|
setDraggingStyles(draggableElement);
|
261
265
|
updateTransformState(event, draggableElement);
|
262
266
|
};
|
@@ -282,7 +286,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
282
286
|
draggingState = DraggingState.END_DRAGGING;
|
283
287
|
removeDraggingStyles(draggableElement);
|
284
288
|
if (draggableElement.classList.contains(DRAGGING_CLASS)) {
|
285
|
-
|
289
|
+
emitDroppingEvent(draggableElement, START_DROP_EVENT, isOutsideAllDroppables ? droppableConfigurator.initial : droppableConfigurator.current, windowScroll, index);
|
286
290
|
}
|
287
291
|
};
|
288
292
|
const removeDraggingStyles = (element) => {
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { Direction } from
|
2
|
-
import { BeforeMargin, AfterMargin, BorderWidth, PaddingBefore, Before } from
|
1
|
+
import { Direction } from '..';
|
2
|
+
import { BeforeMargin, AfterMargin, BorderWidth, PaddingBefore, Before } from '../../../index';
|
3
3
|
export declare const getWindowScroll: () => {
|
4
4
|
scrollX: number;
|
5
5
|
scrollY: number;
|
@@ -11,7 +11,7 @@ export declare const getTransform: (element: Element) => {
|
|
11
11
|
y: number;
|
12
12
|
};
|
13
13
|
export declare const draggableIsOutside: (draggable: Element, droppable: Element) => boolean;
|
14
|
-
export declare const
|
14
|
+
export declare const draggableIsCompleteOutside: (draggable: Element, droppable: Element) => boolean;
|
15
15
|
export declare const getValueFromProperty: (element: HTMLElement | Element | undefined | null, property: PaddingBefore | BorderWidth | BeforeMargin | AfterMargin | Before) => number;
|
16
16
|
export declare const getScrollElement: (element: HTMLElement) => {
|
17
17
|
scrollLeft: number;
|
@@ -1,12 +1,12 @@
|
|
1
|
-
import { HORIZONTAL, VERTICAL } from
|
2
|
-
import { DRAGGABLE_CLASS } from
|
3
|
-
import { containClass } from
|
1
|
+
import { HORIZONTAL, VERTICAL } from '..';
|
2
|
+
import { DRAGGABLE_CLASS } from './classes';
|
3
|
+
import { containClass } from './dom/classList';
|
4
4
|
export const getWindowScroll = () => {
|
5
5
|
const { scrollX, scrollY } = window;
|
6
6
|
return { scrollX, scrollY };
|
7
7
|
};
|
8
8
|
export const parseFloatEmpty = (value) => {
|
9
|
-
if (!value || value.trim().length == 0 || value ==
|
9
|
+
if (!value || value.trim().length == 0 || value == 'normal') {
|
10
10
|
return 0;
|
11
11
|
}
|
12
12
|
return parseFloat(value);
|
@@ -22,7 +22,7 @@ export const getTransform = (element) => {
|
|
22
22
|
const matrix = new DOMMatrixReadOnly(style.transform);
|
23
23
|
return {
|
24
24
|
x: matrix.m41,
|
25
|
-
y: matrix.m42
|
25
|
+
y: matrix.m42
|
26
26
|
};
|
27
27
|
};
|
28
28
|
const intersection = (firstInterval, secondInterval) => {
|
@@ -40,22 +40,38 @@ const intersection = (firstInterval, secondInterval) => {
|
|
40
40
|
export const draggableIsOutside = (draggable, droppable) => {
|
41
41
|
return !hasIntersection(draggable, droppable);
|
42
42
|
};
|
43
|
-
|
43
|
+
const hasIntersection = (element1, element2) => {
|
44
|
+
const { intersectionX, intersectionY, rect1, rect2 } = getIntersection(element1, element2);
|
45
|
+
return (intersectionY >= Math.min(rect1.height, rect2.height) / 2 &&
|
46
|
+
intersectionX >= Math.min(rect1.width, rect2.width) / 2);
|
47
|
+
};
|
48
|
+
export const draggableIsCompleteOutside = (draggable, droppable) => {
|
49
|
+
return !hasCompleteIntersection(draggable, droppable);
|
50
|
+
};
|
51
|
+
const hasCompleteIntersection = (element1, element2) => {
|
52
|
+
const { intersectionX, intersectionY } = getIntersection(element1, element2);
|
53
|
+
return intersectionY >= 0 && intersectionX >= 0;
|
54
|
+
};
|
55
|
+
const getIntersection = (element1, element2) => {
|
44
56
|
const rect1 = getRect(element1);
|
45
57
|
const rect2 = getRect(element2);
|
46
58
|
const intersectionY = intersectionByDirection(rect1, rect2, VERTICAL);
|
47
59
|
const intersectionX = intersectionByDirection(rect1, rect2, HORIZONTAL);
|
48
|
-
return
|
49
|
-
|
60
|
+
return {
|
61
|
+
rect1,
|
62
|
+
rect2,
|
63
|
+
intersectionX,
|
64
|
+
intersectionY
|
65
|
+
};
|
50
66
|
};
|
51
67
|
const intersectionByDirection = (rect1, rect2, direction) => {
|
52
68
|
const { before, distance } = getPropByDirection(direction);
|
53
69
|
return intersection({
|
54
70
|
x1: rect1[before],
|
55
|
-
x2: rect1[before] + rect1[distance]
|
71
|
+
x2: rect1[before] + rect1[distance]
|
56
72
|
}, {
|
57
73
|
x1: rect2[before],
|
58
|
-
x2: rect2[before] + rect2[distance]
|
74
|
+
x2: rect2[before] + rect2[distance]
|
59
75
|
});
|
60
76
|
};
|
61
77
|
export const getValueFromProperty = (element, property) => {
|
@@ -74,22 +90,22 @@ const getRect = (element) => {
|
|
74
90
|
export const getPropByDirection = (direction) => {
|
75
91
|
const ifHorizontal = direction == HORIZONTAL;
|
76
92
|
return {
|
77
|
-
beforeMargin: ifHorizontal ?
|
78
|
-
afterMargin: ifHorizontal ?
|
79
|
-
borderBeforeWidth: ifHorizontal ?
|
80
|
-
before: ifHorizontal ?
|
81
|
-
after: ifHorizontal ?
|
82
|
-
gap: ifHorizontal ?
|
83
|
-
distance: ifHorizontal ?
|
84
|
-
axis: ifHorizontal ?
|
85
|
-
offset: ifHorizontal ?
|
86
|
-
scroll: ifHorizontal ?
|
87
|
-
scrollElement: ifHorizontal ?
|
88
|
-
page: ifHorizontal ?
|
89
|
-
inner: ifHorizontal ?
|
90
|
-
offsetElement: ifHorizontal ?
|
91
|
-
scrollDistance: ifHorizontal ?
|
92
|
-
clientDistance: ifHorizontal ?
|
93
|
+
beforeMargin: ifHorizontal ? 'marginLeft' : 'marginTop',
|
94
|
+
afterMargin: ifHorizontal ? 'marginRight' : 'marginBottom',
|
95
|
+
borderBeforeWidth: ifHorizontal ? 'borderLeftWidth' : 'borderTopWidth',
|
96
|
+
before: ifHorizontal ? 'left' : 'top',
|
97
|
+
after: ifHorizontal ? 'right' : 'down',
|
98
|
+
gap: ifHorizontal ? 'columnGap' : 'rowGap',
|
99
|
+
distance: ifHorizontal ? 'width' : 'height',
|
100
|
+
axis: ifHorizontal ? 'x' : 'y',
|
101
|
+
offset: ifHorizontal ? 'offsetX' : 'offsetY',
|
102
|
+
scroll: ifHorizontal ? 'scrollX' : 'scrollY',
|
103
|
+
scrollElement: ifHorizontal ? 'scrollLeft' : 'scrollTop',
|
104
|
+
page: ifHorizontal ? 'pageX' : 'pageY',
|
105
|
+
inner: ifHorizontal ? 'innerWidth' : 'innerHeight',
|
106
|
+
offsetElement: ifHorizontal ? 'offsetLeft' : 'offsetTop',
|
107
|
+
scrollDistance: ifHorizontal ? 'scrollWidth' : 'scrollHeight',
|
108
|
+
clientDistance: ifHorizontal ? 'clientWidth' : 'clientHeight',
|
93
109
|
paddingBefore: ifHorizontal ? 'paddingLeft' : 'paddingTop',
|
94
110
|
getRect
|
95
111
|
};
|
@@ -104,21 +120,15 @@ export const getGroupDroppables = (currentDroppable, droppableGroup) => {
|
|
104
120
|
return Array.from(document.querySelectorAll(`.droppable-group-${droppableGroup}`));
|
105
121
|
};
|
106
122
|
export const getParentDraggableChildren = (parent) => {
|
107
|
-
const siblings = [...parent.children]
|
108
|
-
.filter((child) => containClass(child, DRAGGABLE_CLASS));
|
123
|
+
const siblings = [...parent.children].filter((child) => containClass(child, DRAGGABLE_CLASS));
|
109
124
|
return siblings;
|
110
125
|
};
|
111
126
|
export const getSiblingsByParent = (current, parent) => {
|
112
127
|
const siblings = [...parent.children]
|
113
|
-
.filter((child) => containClass(child, DRAGGABLE_CLASS) &&
|
114
|
-
!child.isEqualNode(current))
|
128
|
+
.filter((child) => containClass(child, DRAGGABLE_CLASS) && !child.isEqualNode(current))
|
115
129
|
.toReversed();
|
116
130
|
const positionOnDroppable = [...parent.children].findLastIndex((child) => child.isEqualNode(current));
|
117
|
-
return [
|
118
|
-
siblings,
|
119
|
-
positionOnDroppable,
|
120
|
-
parent,
|
121
|
-
];
|
131
|
+
return [siblings, positionOnDroppable, parent];
|
122
132
|
};
|
123
133
|
const getNearestFixedParent = (element) => {
|
124
134
|
let parent = element.parentElement;
|
@@ -134,5 +144,7 @@ const getNearestFixedParent = (element) => {
|
|
134
144
|
export const getNearestFixedParentPosition = (element, direction) => {
|
135
145
|
const { before, borderBeforeWidth } = getPropByDirection(direction);
|
136
146
|
const fixedParent = getNearestFixedParent(element);
|
137
|
-
return fixedParent
|
147
|
+
return fixedParent
|
148
|
+
? getRect(fixedParent)[before] + getValueFromProperty(fixedParent, borderBeforeWidth)
|
149
|
+
: 0;
|
138
150
|
};
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { DragMouseTouchEvent, fixedSize } from
|
2
|
-
type onTouchEvent =
|
1
|
+
import { DragMouseTouchEvent, fixedSize } from '../../../index';
|
2
|
+
type onTouchEvent = 'ontouchstart' | 'ontouchmove' | 'ontouchend';
|
3
3
|
declare const onMouseEvents: readonly ["onmouseup", "onmousedown", "onmousemove"];
|
4
4
|
type onMouseEvent = (typeof onMouseEvents)[number];
|
5
|
-
type TouchEventType =
|
5
|
+
type TouchEventType = 'touchstart' | 'touchmove' | 'touchend';
|
6
6
|
declare const mouseEvents: readonly ["mouseup", "mousedown", "mousemove"];
|
7
7
|
type MouseEventType = (typeof mouseEvents)[number];
|
8
8
|
type DragEventCallback = (event: DragMouseTouchEvent) => void;
|