fluid-dnd 2.4.0 → 2.5.1
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/README.md +14 -15
- package/dist/{HandlerPublisher-pcX0Zmas.js → HandlerPublisher-CRu7xI9p.js} +1 -1
- package/dist/{HandlerPublisher-B68XPAcH.cjs → HandlerPublisher-CrUNmzg-.cjs} +1 -1
- package/dist/core/config/configHandler.js +4 -4
- package/dist/core/config/droppableConfigurator.d.ts +2 -1
- package/dist/core/config/droppableConfigurator.js +17 -21
- package/dist/core/events/changeDraggableStyles.d.ts +1 -1
- package/dist/core/events/changeDraggableStyles.js +3 -5
- package/dist/core/events/dragAndDrop/dragAndDrop.d.ts +1 -1
- package/dist/core/events/dragAndDrop/dragAndDrop.js +29 -45
- package/dist/core/events/dragAndDrop/getTranslateBeforeDropping.js +30 -30
- package/dist/core/events/dragAndDrop/getTranslationByDraggingAndEvent.js +10 -11
- package/dist/core/events/insert.d.ts +2 -1
- package/dist/core/events/insert.js +4 -10
- package/dist/core/events/remove.d.ts +1 -1
- package/dist/core/events/remove.js +27 -13
- package/dist/core/positioning/autoScroll.js +6 -5
- package/dist/core/positioning/usePositioning.d.ts +2 -2
- package/dist/core/positioning/usePositioning.js +54 -46
- package/dist/core/tempChildren.d.ts +2 -2
- package/dist/core/tempChildren.js +32 -31
- package/dist/core/useDraggable.js +43 -47
- package/dist/core/useDroppable.d.ts +2 -2
- package/dist/core/useDroppable.js +11 -19
- package/dist/core/utils/GetStyles.d.ts +25 -3
- package/dist/core/utils/GetStyles.js +56 -5
- package/dist/core/utils/ParseStyles.d.ts +4 -3
- package/dist/core/utils/ParseStyles.js +13 -13
- package/dist/core/utils/SetStyles.d.ts +4 -8
- package/dist/core/utils/SetStyles.js +19 -42
- package/dist/core/utils/dom/classList.d.ts +2 -2
- package/dist/core/utils/dom/classList.js +2 -11
- package/dist/core/utils/index.d.ts +5 -1
- package/dist/core/utils/index.js +7 -6
- package/dist/fluid-dnd-logo.png +0 -0
- package/dist/index-BOqB07mI.cjs +1 -0
- package/dist/index-CJpjY7r7.js +1130 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +2 -2
- package/dist/insert--mO_a1mv.js +51 -0
- package/dist/insert-CEcy9QNd.cjs +1 -0
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.mjs +33 -31
- package/dist/react/utils/ReactLilstConfig.js +3 -2
- package/dist/remove-C4YcWK2S.js +48 -0
- package/dist/remove-dSzXNYxs.cjs +1 -0
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.mjs +18 -16
- package/dist/svelte/utils/SvelteListCondig.js +3 -2
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.mjs +26 -24
- package/dist/vue/utils/VueListCondig.js +3 -2
- package/package.json +1 -1
- package/dist/index-2hBSSK9_.cjs +0 -1
- package/dist/index-DFXw7kYo.js +0 -1223
@@ -1,16 +1,16 @@
|
|
1
1
|
import { getParentDraggableChildren, getSiblings } from '../utils/GetStyles';
|
2
2
|
import getTranslationByDragging from '../events/dragAndDrop/getTranslationByDraggingAndEvent';
|
3
|
-
import {
|
4
|
-
import { removeTempChild } from '../tempChildren';
|
3
|
+
import { addTempChildOnInsert, removeTempChild } from '../tempChildren';
|
5
4
|
import { DISABLE_TRANSITION, DRAGGABLE_CLASS } from '../utils/classes';
|
6
5
|
import { addClass, containClass, removeClass } from '../utils/dom/classList';
|
7
6
|
import { isTempElement, observeMutation } from '../utils/observer';
|
8
7
|
import { useChangeDraggableStyles } from './changeDraggableStyles';
|
8
|
+
import { removeTranslateWhitoutTransition } from '../utils/SetStyles';
|
9
9
|
export default function useInsertEvents(currentConfig, parent, handlerPublisher, endDraggingAction) {
|
10
10
|
const { delayBeforeInsert } = currentConfig;
|
11
11
|
const [removeElementDraggingStyles, _, dragEventOverElement] = useChangeDraggableStyles(currentConfig, handlerPublisher, endDraggingAction);
|
12
12
|
// #region Insert
|
13
|
-
const emitInsertEventToSiblings = (targetIndex, draggedElement, droppable, value,
|
13
|
+
const emitInsertEventToSiblings = (targetIndex, draggedElement, droppable, value, droppableConfigurator) => {
|
14
14
|
const translation = getTranslationByDragging(draggedElement, 'insert', currentConfig.direction, droppable);
|
15
15
|
const { onInsertEvent } = currentConfig;
|
16
16
|
const siblings = getParentDraggableChildren(droppable);
|
@@ -22,7 +22,7 @@ export default function useInsertEvents(currentConfig, parent, handlerPublisher,
|
|
22
22
|
dragEventOverElement(sibling, translation);
|
23
23
|
}
|
24
24
|
}
|
25
|
-
|
25
|
+
addTempChildOnInsert(draggedElement, false, droppableConfigurator);
|
26
26
|
setTimeout(() => {
|
27
27
|
onInsertEvent(targetIndex, value);
|
28
28
|
onFinishInsertElement(targetIndex, droppable, currentConfig);
|
@@ -37,12 +37,6 @@ export default function useInsertEvents(currentConfig, parent, handlerPublisher,
|
|
37
37
|
removeTranslateWhitoutTransition(sibling);
|
38
38
|
}
|
39
39
|
};
|
40
|
-
const removeTranslateWhitoutTransition = (element) => {
|
41
|
-
if (IsHTMLElement(element)) {
|
42
|
-
element.style.transition = '';
|
43
|
-
element.style.transform = '';
|
44
|
-
}
|
45
|
-
};
|
46
40
|
return [emitInsertEventToSiblings];
|
47
41
|
}
|
48
42
|
const childrenMutationFilter = (mutation) => {
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import { CoreConfig } from '..';
|
2
2
|
import { DroppableConfig } from '../config/configHandler';
|
3
3
|
import HandlerPublisher from '@/core/HandlerPublisher';
|
4
|
-
export default function useRemoveEvents<T>(currentConfig: CoreConfig<T>, parent: HTMLElement, handlerPublisher: HandlerPublisher, endDraggingAction: () => void): readonly [(targetIndex: number,
|
4
|
+
export default function useRemoveEvents<T>(currentConfig: CoreConfig<T>, parent: HTMLElement, handlerPublisher: HandlerPublisher, endDraggingAction: () => void): readonly [(index: number, targetIndex: number, draggableElement: HTMLElement, config: DroppableConfig<T>) => void];
|
@@ -1,9 +1,10 @@
|
|
1
1
|
import { getSiblings } from '../utils/GetStyles';
|
2
|
-
import { moveTranslate } from '../utils/SetStyles';
|
2
|
+
import { moveTranslate, removeTranslateWhitoutTransition, setTranistion } from '../utils/SetStyles';
|
3
3
|
import getTranslationByDragging from './dragAndDrop/getTranslationByDraggingAndEvent';
|
4
|
-
import {
|
5
|
-
import { removeTempChild } from '../tempChildren';
|
4
|
+
import { addTempChild, removeTempChild } from '../tempChildren';
|
6
5
|
import { useChangeDraggableStyles } from './changeDraggableStyles';
|
6
|
+
import { addClass, removeClass } from '../utils/dom/classList';
|
7
|
+
import { draggableTargetTimingFunction } from '../utils';
|
7
8
|
export default function useRemoveEvents(currentConfig, parent, handlerPublisher, endDraggingAction) {
|
8
9
|
const { animationDuration } = currentConfig;
|
9
10
|
const [removeElementDraggingStyles] = useChangeDraggableStyles(currentConfig, handlerPublisher, endDraggingAction);
|
@@ -17,7 +18,7 @@ export default function useRemoveEvents(currentConfig, parent, handlerPublisher,
|
|
17
18
|
const translation = getTranslationByDragging(draggedElement, 'remove', config.direction, droppable);
|
18
19
|
for (const [index, sibling] of siblings.entries()) {
|
19
20
|
if (index >= targetIndex) {
|
20
|
-
|
21
|
+
moveTranslate(sibling, translation);
|
21
22
|
setTimeout(() => {
|
22
23
|
onFinishRemoveEvent(sibling);
|
23
24
|
}, animationDuration);
|
@@ -31,21 +32,34 @@ export default function useRemoveEvents(currentConfig, parent, handlerPublisher,
|
|
31
32
|
removeTranslateFromSiblings(draggedElement, parent);
|
32
33
|
}, animationDuration);
|
33
34
|
};
|
34
|
-
const startDragEventOverElement = (element, translation) => {
|
35
|
-
const { width, height } = translation;
|
36
|
-
moveTranslate(element, height, width);
|
37
|
-
};
|
38
35
|
const removeTranslateFromSiblings = (element, parent) => {
|
39
36
|
const [siblings] = getSiblings(element, parent);
|
40
37
|
for (const sibling of [...siblings, element]) {
|
41
38
|
removeTranslateWhitoutTransition(sibling);
|
42
39
|
}
|
43
40
|
};
|
44
|
-
const
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
const removeAt = (index, targetIndex, draggableElement, config) => {
|
42
|
+
const { removingClass, delayBeforeRemove } = currentConfig;
|
43
|
+
if (targetIndex == index) {
|
44
|
+
addClass(draggableElement, removingClass);
|
45
|
+
setTimeout(() => {
|
46
|
+
removeAfterRemovingClass(index, targetIndex, draggableElement, config);
|
47
|
+
}, delayBeforeRemove);
|
48
48
|
}
|
49
49
|
};
|
50
|
-
|
50
|
+
const removeAfterRemovingClass = (index, targetIndex, draggableElement, config) => {
|
51
|
+
const { removingClass, onRemoveAtEvent } = currentConfig;
|
52
|
+
removeClass(draggableElement, removingClass);
|
53
|
+
addTempChild(draggableElement, parent, false, config);
|
54
|
+
emitRemoveEventToSiblings(targetIndex, draggableElement, config, (sibling) => {
|
55
|
+
removeDraggingStyles(sibling);
|
56
|
+
emitFinishRemoveEventToSiblings(draggableElement);
|
57
|
+
});
|
58
|
+
onRemoveAtEvent(index, true);
|
59
|
+
};
|
60
|
+
const removeDraggingStyles = (element) => {
|
61
|
+
setTranistion(element, animationDuration, draggableTargetTimingFunction);
|
62
|
+
moveTranslate(element);
|
63
|
+
};
|
64
|
+
return [removeAt];
|
51
65
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { draggableIsCompleteOutside,
|
1
|
+
import { draggableIsCompleteOutside, getAxisValue, getBefore, getDistanceValue, getRect } from '../utils/GetStyles';
|
2
2
|
const scrollByDirection = (element, direction, scrollAmount) => {
|
3
3
|
if (scrollAmount == 0) {
|
4
4
|
return;
|
@@ -14,11 +14,12 @@ export const useScroll = (draggedElement) => {
|
|
14
14
|
let lastScrollAmount = 0.5;
|
15
15
|
const minScrollAmountDiff = 0.03;
|
16
16
|
const updateScrollByPosition = (direction, parent, position, translate) => {
|
17
|
-
const
|
18
|
-
const distanceValue = getRect(draggedElement)[distance];
|
17
|
+
const [distanceValue] = getDistanceValue(direction, getRect(draggedElement));
|
19
18
|
const parentBoundingClientRect = getRect(parent);
|
20
|
-
const positionInsideParent = position
|
21
|
-
|
19
|
+
const positionInsideParent = getBefore(direction, position) -
|
20
|
+
getBefore(direction, parentBoundingClientRect) +
|
21
|
+
getAxisValue(direction, translate);
|
22
|
+
const [parentDistance] = getDistanceValue(direction, parentBoundingClientRect);
|
22
23
|
const totalDistance = parentDistance - distanceValue;
|
23
24
|
const relativePosition = positionInsideParent / totalDistance;
|
24
25
|
const relativeDistanceValue = distanceValue / totalDistance;
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import { DragMouseTouchEvent, TransformEvent } from '../../../index';
|
1
|
+
import { DragMouseTouchEvent, ElementPosition, OffsetCoordinate, TransformEvent } from '../../../index';
|
2
2
|
import { CoordinateMap, Direction } from '..';
|
3
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];
|
7
|
-
export declare const getTransformState: (event: TransformEvent, element: HTMLElement, draggable: Element) => [
|
7
|
+
export declare const getTransformState: (event: TransformEvent, element: HTMLElement, draggable: Element) => [ElementPosition, OffsetCoordinate];
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { getNearestFixedParentPosition, getPropByDirection,
|
1
|
+
import { getAxisValue, getBefore, getBeforeMarginValue, getBorderBeforeWidthValue, getDistanceValue, getInnerDistance, getNearestFixedParentPosition, getOffsetValue, getPageValue, getPropByDirection, getRect, getScrollValue, hasTransform, isSameNode } from '../utils/GetStyles';
|
2
2
|
import { HORIZONTAL, VERTICAL } from '..';
|
3
3
|
import { useScroll } from './autoScroll';
|
4
4
|
import { HANDLER_CLASS, DRAGGING_CLASS } from '../utils/classes';
|
@@ -11,33 +11,34 @@ export const usePositioning = (draggedElement, coordinateTransforms) => {
|
|
11
11
|
const updateTranform = (newTranslate) => {
|
12
12
|
draggedElement.style.transform = `translate( ${newTranslate.x}px, ${newTranslate.y}px)`;
|
13
13
|
};
|
14
|
-
const updatePosition = (
|
15
|
-
draggedElement.style.top = `${
|
16
|
-
draggedElement.style.left = `${
|
14
|
+
const updatePosition = (position) => {
|
15
|
+
draggedElement.style.top = `${position.top}px`;
|
16
|
+
draggedElement.style.left = `${position.left}px`;
|
17
17
|
};
|
18
18
|
const setTransform = (element, parent, pagePosition, direction) => {
|
19
19
|
const getTranslateWihtDirection = (translateDirection) => {
|
20
|
-
const
|
21
|
-
const
|
22
|
-
const
|
23
|
-
const
|
24
|
-
const
|
25
|
-
const
|
26
|
-
const
|
27
|
-
const elementPosittion = pageValue - currentOffset[offset];
|
20
|
+
const pageValue = getPageValue(translateDirection, pagePosition);
|
21
|
+
const scrollValue = getScrollValue(translateDirection, window);
|
22
|
+
const innerDistance = getInnerDistance(translateDirection, window);
|
23
|
+
const [distanceValue] = getDistanceValue(translateDirection, getRect(element));
|
24
|
+
const border = getBorderBeforeWidthValue(translateDirection, element);
|
25
|
+
const margin = getBeforeMarginValue(translateDirection, element);
|
26
|
+
const elementPosittion = pageValue - getOffsetValue(translateDirection, currentOffset);
|
28
27
|
const beforefixecParentValue = getNearestFixedParentPosition(element, translateDirection);
|
29
28
|
if (elementPosittion >= scrollValue - distanceValue / 2 &&
|
30
29
|
elementPosittion <= scrollValue + innerDistance) {
|
30
|
+
const parentPosition = getParentPosition(translateDirection, parent);
|
31
31
|
const newTranslate = elementPosittion -
|
32
|
-
position
|
32
|
+
getBefore(translateDirection, position) -
|
33
33
|
border -
|
34
34
|
margin -
|
35
35
|
scrollValue -
|
36
|
-
beforefixecParentValue
|
36
|
+
beforefixecParentValue -
|
37
|
+
parentPosition;
|
37
38
|
updateScroll(translateDirection);
|
38
39
|
return newTranslate;
|
39
40
|
}
|
40
|
-
const defaultTransalation = translate
|
41
|
+
const defaultTransalation = getAxisValue(translateDirection, translate);
|
41
42
|
return defaultTransalation;
|
42
43
|
};
|
43
44
|
const updateScroll = (translateDirection) => {
|
@@ -61,27 +62,23 @@ export const usePositioning = (draggedElement, coordinateTransforms) => {
|
|
61
62
|
return coordinate;
|
62
63
|
};
|
63
64
|
const updateTransformState = (event, element) => {
|
64
|
-
const [
|
65
|
-
position =
|
66
|
-
top,
|
67
|
-
left
|
68
|
-
};
|
65
|
+
const [tempPosition, offset] = getTransformState(event, element, draggedElement);
|
66
|
+
position = tempPosition;
|
69
67
|
updatePosition(position);
|
70
|
-
currentOffset =
|
68
|
+
currentOffset = offset;
|
71
69
|
};
|
72
70
|
return [setTransform, updateTransformState];
|
73
71
|
};
|
74
72
|
const getOffsetWithDraggable = (direction, element, draggable) => {
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
getValueFromProperty(draggable, borderBeforeWidth));
|
73
|
+
return (getBefore(direction, getRect(element)) -
|
74
|
+
getBefore(direction, getRect(draggable)) -
|
75
|
+
getBorderBeforeWidthValue(direction, draggable));
|
79
76
|
};
|
80
77
|
const getOffset = (event, draggable) => {
|
81
78
|
let { offsetX, offsetY, target } = event;
|
82
79
|
let targetHandler = getHandlerElementAncestor(target, draggable);
|
83
80
|
const targetElement = target;
|
84
|
-
if (targetElement && targetHandler && !
|
81
|
+
if (targetElement && targetHandler && !isSameNode(targetElement, targetHandler)) {
|
85
82
|
offsetX += getOffsetWithDraggable(HORIZONTAL, targetElement, targetHandler);
|
86
83
|
offsetY += getOffsetWithDraggable(VERTICAL, targetElement, targetHandler);
|
87
84
|
}
|
@@ -89,37 +86,48 @@ const getOffset = (event, draggable) => {
|
|
89
86
|
offsetX += getOffsetWithDraggable(HORIZONTAL, targetHandler, draggable);
|
90
87
|
offsetY += getOffsetWithDraggable(VERTICAL, targetHandler, draggable);
|
91
88
|
}
|
92
|
-
return
|
89
|
+
return { offsetX, offsetY };
|
93
90
|
};
|
94
91
|
const getHandlerElementAncestor = (target, draggable) => {
|
95
92
|
const targetHandler = target?.closest(`.${HANDLER_CLASS}`);
|
96
|
-
if (targetHandler &&
|
93
|
+
if (targetHandler && isSameNode(draggable, targetHandler)) {
|
97
94
|
return target;
|
98
95
|
}
|
99
96
|
return targetHandler;
|
100
97
|
};
|
101
98
|
const getPositionByDistance = (direction, event, element, offsetEvent) => {
|
102
|
-
const { offset, beforeMargin, page, borderBeforeWidth, scroll } = getPropByDirection(direction);
|
103
99
|
const beforefixecParentValue = getNearestFixedParentPosition(element, direction);
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
100
|
+
const parent = element.parentElement;
|
101
|
+
const parentPosition = getParentPosition(direction, parent);
|
102
|
+
return (getPageValue(direction, event) -
|
103
|
+
getOffsetValue(direction, offsetEvent) -
|
104
|
+
getBeforeMarginValue(direction, element) -
|
105
|
+
getBorderBeforeWidthValue(direction, element) -
|
106
|
+
getScrollValue(direction, window) -
|
107
|
+
beforefixecParentValue -
|
108
|
+
parentPosition);
|
109
|
+
};
|
110
|
+
const getParentPosition = (direction, element) => {
|
111
|
+
return element && hasAncestorTransform(element) ? getBefore(direction, getRect(element)) : 0;
|
112
|
+
};
|
113
|
+
const hasAncestorTransform = (element) => {
|
114
|
+
let current = element;
|
115
|
+
while (current) {
|
116
|
+
const currentElementHasTransform = hasTransform(current);
|
117
|
+
if (currentElementHasTransform) {
|
118
|
+
return true;
|
119
|
+
}
|
120
|
+
current = current.parentElement;
|
121
|
+
}
|
122
|
+
return false;
|
110
123
|
};
|
111
124
|
export const getTransformState = (event, element, draggable) => {
|
112
|
-
const
|
125
|
+
const offset = getOffset(event, draggable);
|
113
126
|
return [
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
}
|
118
|
-
|
119
|
-
offsetX,
|
120
|
-
offsetY
|
121
|
-
}),
|
122
|
-
offsetX,
|
123
|
-
offsetY
|
127
|
+
{
|
128
|
+
top: getPositionByDistance(VERTICAL, event, element, offset),
|
129
|
+
left: getPositionByDistance(HORIZONTAL, event, element, offset)
|
130
|
+
},
|
131
|
+
offset
|
124
132
|
];
|
125
133
|
};
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { DroppableConfig } from './config/configHandler';
|
2
|
-
export declare const addTempChild: <T>(draggedElement: HTMLElement | undefined, parent: Element, ifStartDragging: boolean, droppableConfig
|
3
|
-
export declare const addTempChildOnInsert: <T>(draggedElement: HTMLElement | undefined, ifStartDragging: boolean, droppableConfig
|
2
|
+
export declare const addTempChild: <T>(draggedElement: HTMLElement | undefined, parent: Element, ifStartDragging: boolean, droppableConfig: DroppableConfig<T>, addingAnimationDuration?: number) => void;
|
3
|
+
export declare const addTempChildOnInsert: <T>(draggedElement: HTMLElement | undefined, ifStartDragging: boolean, droppableConfig: DroppableConfig<T>) => void;
|
4
4
|
export declare const removeTempChildrens: (droppable: HTMLElement, parent: HTMLElement, droppableGroupClass: string | null, animationDuration: number, draggedElementIsOutside?: boolean) => void;
|
5
5
|
export declare const removeTempChild: (parent: HTMLElement, animationDuration: number, isAnimated?: boolean) => void;
|
@@ -1,18 +1,19 @@
|
|
1
1
|
import { HORIZONTAL, VERTICAL } from '.';
|
2
|
-
import { getPropByDirection } from './utils/GetStyles';
|
2
|
+
import { getDistanceValue, getPropByDirection, getRect, getScrollElementValue, isSameNode } from './utils/GetStyles';
|
3
3
|
import { getGapPixels } from './utils/ParseStyles';
|
4
4
|
import { setSizeStyles, setTranistion } from './utils/SetStyles';
|
5
5
|
import { observeMutation } from './utils/observer';
|
6
6
|
import getTranslationByDragging from './events/dragAndDrop/getTranslationByDraggingAndEvent';
|
7
|
-
import { TEMP_CHILD_CLASS } from './utils';
|
7
|
+
import { NONE_TRANSLATE, TEMP_CHILD_CLASS } from './utils';
|
8
8
|
import { addClass, getClassesSelector } from './utils/dom/classList';
|
9
9
|
const START_DRAG_EVENT = 'startDrag';
|
10
10
|
const timingFunction = 'cubic-bezier(0.2, 0, 0, 1)';
|
11
11
|
const DELAY_TIME = 50;
|
12
|
+
const TRANSITION_PROPERTY = 'width, min-width, height';
|
12
13
|
const getDistance = (droppable, draggedElement, direction) => {
|
13
14
|
let distances = getTranslationByDragging(draggedElement, START_DRAG_EVENT, direction, droppable);
|
14
15
|
const gap = getGapPixels(droppable, direction);
|
15
|
-
const
|
16
|
+
const [, distance] = getDistanceValue(direction, distances);
|
16
17
|
distances[distance] -= gap;
|
17
18
|
const [large, largeDistance] = getlarge(direction, draggedElement);
|
18
19
|
distances[largeDistance] = large;
|
@@ -20,54 +21,54 @@ const getDistance = (droppable, draggedElement, direction) => {
|
|
20
21
|
};
|
21
22
|
const getlarge = (direction, draggedElement) => {
|
22
23
|
const largeDirection = direction == HORIZONTAL ? VERTICAL : HORIZONTAL;
|
23
|
-
const
|
24
|
-
return
|
24
|
+
const distanceValue = getDistanceValue(largeDirection, getRect(draggedElement));
|
25
|
+
return distanceValue;
|
25
26
|
};
|
26
|
-
const setSizes = (element,
|
27
|
-
setSizeStyles(element,
|
28
|
-
element.style.minWidth = `${width}px`;
|
27
|
+
const setSizes = (element, translate = NONE_TRANSLATE) => {
|
28
|
+
setSizeStyles(element, translate);
|
29
|
+
element.style.minWidth = `${translate.width}px`;
|
29
30
|
};
|
30
31
|
const updateChildAfterCreated = (child, droppable, distances) => {
|
31
32
|
return (observer) => {
|
32
33
|
if (!droppable.contains(child)) {
|
33
34
|
return;
|
34
35
|
}
|
35
|
-
setSizes(child, distances
|
36
|
+
setSizes(child, distances);
|
36
37
|
observer.disconnect();
|
37
38
|
};
|
38
39
|
};
|
40
|
+
const overflowScroll = (droppable, direction) => {
|
41
|
+
const { scrollDistance, clientDistance } = getPropByDirection(direction);
|
42
|
+
return droppable[scrollDistance] - droppable[clientDistance];
|
43
|
+
};
|
39
44
|
const scrollPercent = (direction, droppable, droppableScroll) => {
|
40
|
-
const
|
41
|
-
return
|
45
|
+
const [scrollElementValue] = getScrollElementValue(direction, droppableScroll);
|
46
|
+
return scrollElementValue / overflowScroll(droppable, direction);
|
42
47
|
};
|
43
|
-
const fixScrollInitialChange = (
|
48
|
+
const fixScrollInitialChange = (droppable, config, scroll, ifStartDragging) => {
|
44
49
|
if (!ifStartDragging) {
|
45
50
|
return;
|
46
51
|
}
|
47
|
-
const { droppable, config, scroll } = droppableConfig;
|
48
52
|
const { direction } = config;
|
49
|
-
const scrollCompleted = scrollPercent(
|
50
|
-
const
|
53
|
+
const scrollCompleted = scrollPercent(direction, droppable, scroll) > 0.99;
|
54
|
+
const [, scrollElement] = getScrollElementValue(direction, droppable);
|
51
55
|
if (scrollCompleted) {
|
52
|
-
droppable[scrollElement] = droppable
|
56
|
+
droppable[scrollElement] = overflowScroll(droppable, direction);
|
53
57
|
}
|
54
58
|
};
|
55
59
|
const getTempChild = (draggedElement, ifStartDragging, droppableConfig, addingAnimationDuration) => {
|
56
|
-
|
57
|
-
return;
|
58
|
-
}
|
59
|
-
const { droppable, config } = droppableConfig;
|
60
|
+
const { droppable, config, scroll } = droppableConfig;
|
60
61
|
const { direction, animationDuration } = config;
|
61
|
-
fixScrollInitialChange(
|
62
|
+
fixScrollInitialChange(droppable, config, scroll, ifStartDragging);
|
62
63
|
if (droppable.querySelector(`.${TEMP_CHILD_CLASS}`) || !draggedElement) {
|
63
64
|
return;
|
64
65
|
}
|
65
66
|
var tempChildTag = draggedElement.tagName == 'LI' ? 'DIV' : draggedElement.tagName;
|
66
67
|
var child = document.createElement(tempChildTag);
|
67
68
|
addClass(child, TEMP_CHILD_CLASS);
|
68
|
-
setSizes(child
|
69
|
+
setSizes(child);
|
69
70
|
const distances = getDistance(droppable, draggedElement, direction);
|
70
|
-
setTranistion(child, addingAnimationDuration ?? animationDuration, timingFunction,
|
71
|
+
setTranistion(child, addingAnimationDuration ?? animationDuration, timingFunction, TRANSITION_PROPERTY);
|
71
72
|
return [child, distances, droppable];
|
72
73
|
};
|
73
74
|
export const addTempChild = (draggedElement, parent, ifStartDragging, droppableConfig, addingAnimationDuration) => {
|
@@ -76,8 +77,8 @@ export const addTempChild = (draggedElement, parent, ifStartDragging, droppableC
|
|
76
77
|
return;
|
77
78
|
}
|
78
79
|
const [child, distances, droppable] = result;
|
79
|
-
if (
|
80
|
-
setSizes(child, distances
|
80
|
+
if (isSameNode(parent, droppable)) {
|
81
|
+
setSizes(child, distances);
|
81
82
|
}
|
82
83
|
observeMutation(updateChildAfterCreated(child, droppable, distances), droppable, {
|
83
84
|
childList: true,
|
@@ -96,9 +97,9 @@ export const addTempChildOnInsert = (draggedElement, ifStartDragging, droppableC
|
|
96
97
|
};
|
97
98
|
const setSizeAfterAppendChild = (child, size) => {
|
98
99
|
return requestAnimationFrame(() => {
|
99
|
-
setSizes(child, size
|
100
|
+
setSizes(child, size);
|
100
101
|
requestAnimationFrame(() => {
|
101
|
-
setTranistion(child, 0, timingFunction,
|
102
|
+
setTranistion(child, 0, timingFunction, TRANSITION_PROPERTY);
|
102
103
|
});
|
103
104
|
});
|
104
105
|
};
|
@@ -109,12 +110,12 @@ export const removeTempChildrens = (droppable, parent, droppableGroupClass, anim
|
|
109
110
|
var children = document.querySelectorAll(`${getClassesSelector(droppableGroupClass)} > .${TEMP_CHILD_CLASS}`);
|
110
111
|
children.forEach((tempChild) => {
|
111
112
|
const childParent = tempChild.parentElement;
|
112
|
-
if (
|
113
|
-
(!draggedElementIsOutside &&
|
113
|
+
if (isSameNode(parent, childParent) ||
|
114
|
+
(!draggedElementIsOutside && isSameNode(droppable, childParent))) {
|
114
115
|
return;
|
115
116
|
}
|
116
117
|
const tempChildElement = tempChild;
|
117
|
-
setSizes(tempChildElement
|
118
|
+
setSizes(tempChildElement);
|
118
119
|
setTimeout(() => {
|
119
120
|
tempChild.parentNode?.removeChild(tempChild);
|
120
121
|
}, animationDuration + DELAY_TIME);
|
@@ -125,7 +126,7 @@ export const removeTempChild = (parent, animationDuration, isAnimated = false) =
|
|
125
126
|
lastChildren.forEach((lastChild) => {
|
126
127
|
const tempChildElement = lastChild;
|
127
128
|
if (isAnimated) {
|
128
|
-
setSizes(tempChildElement
|
129
|
+
setSizes(tempChildElement);
|
129
130
|
setTimeout(() => {
|
130
131
|
if (parent.contains(tempChildElement)) {
|
131
132
|
parent.removeChild(tempChildElement);
|