fluid-dnd 2.4.0 → 2.5.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/README.md +14 -15
- package/dist/{HandlerPublisher-B68XPAcH.cjs → HandlerPublisher-1MmlNkG3.cjs} +1 -1
- package/dist/{HandlerPublisher-pcX0Zmas.js → HandlerPublisher-DBjPMiyO.js} +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.js +3 -5
- package/dist/core/events/dragAndDrop/dragAndDrop.js +28 -40
- 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 +2 -2
- package/dist/core/events/remove.js +28 -13
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.js +7 -0
- package/dist/core/positioning/autoScroll.js +6 -5
- package/dist/core/positioning/usePositioning.js +20 -23
- package/dist/core/tempChildren.js +32 -28
- package/dist/core/useDraggable.js +39 -50
- package/dist/core/useDroppable.d.ts +2 -2
- package/dist/core/useDroppable.js +10 -16
- package/dist/core/utils/GetStyles.d.ts +24 -3
- package/dist/core/utils/GetStyles.js +53 -5
- package/dist/core/utils/ParseStyles.d.ts +3 -2
- package/dist/core/utils/ParseStyles.js +12 -12
- package/dist/core/utils/SetStyles.d.ts +4 -3
- package/dist/core/utils/SetStyles.js +19 -14
- 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-BdOAK6C7.cjs +1 -0
- package/dist/index-HczUoMBK.js +1131 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +2 -2
- package/dist/insert-Dd8savAS.js +51 -0
- package/dist/insert-T4Y6rI_j.cjs +1 -0
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.mjs +32 -30
- package/dist/react/utils/ReactLilstConfig.js +3 -2
- package/dist/remove-BC4sUY1o.cjs +1 -0
- package/dist/remove-M01dmTvo.js +48 -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,9 +1,11 @@
|
|
1
1
|
import { getSiblings } from '../utils/GetStyles';
|
2
|
-
import { moveTranslate } from '../utils/SetStyles';
|
2
|
+
import { moveTranslate, removeTranslateWhitoutTransition, setTranistion } from '../utils/SetStyles';
|
3
|
+
import { DraggingState } from '..';
|
3
4
|
import getTranslationByDragging from './dragAndDrop/getTranslationByDraggingAndEvent';
|
4
|
-
import {
|
5
|
-
import { removeTempChild } from '../tempChildren';
|
5
|
+
import { addTempChild, removeTempChild } from '../tempChildren';
|
6
6
|
import { useChangeDraggableStyles } from './changeDraggableStyles';
|
7
|
+
import { addClass, removeClass } from '../utils/dom/classList';
|
8
|
+
import { draggableTargetTimingFunction } from '../utils';
|
7
9
|
export default function useRemoveEvents(currentConfig, parent, handlerPublisher, endDraggingAction) {
|
8
10
|
const { animationDuration } = currentConfig;
|
9
11
|
const [removeElementDraggingStyles] = useChangeDraggableStyles(currentConfig, handlerPublisher, endDraggingAction);
|
@@ -17,7 +19,7 @@ export default function useRemoveEvents(currentConfig, parent, handlerPublisher,
|
|
17
19
|
const translation = getTranslationByDragging(draggedElement, 'remove', config.direction, droppable);
|
18
20
|
for (const [index, sibling] of siblings.entries()) {
|
19
21
|
if (index >= targetIndex) {
|
20
|
-
|
22
|
+
moveTranslate(sibling, translation);
|
21
23
|
setTimeout(() => {
|
22
24
|
onFinishRemoveEvent(sibling);
|
23
25
|
}, animationDuration);
|
@@ -31,21 +33,34 @@ export default function useRemoveEvents(currentConfig, parent, handlerPublisher,
|
|
31
33
|
removeTranslateFromSiblings(draggedElement, parent);
|
32
34
|
}, animationDuration);
|
33
35
|
};
|
34
|
-
const startDragEventOverElement = (element, translation) => {
|
35
|
-
const { width, height } = translation;
|
36
|
-
moveTranslate(element, height, width);
|
37
|
-
};
|
38
36
|
const removeTranslateFromSiblings = (element, parent) => {
|
39
37
|
const [siblings] = getSiblings(element, parent);
|
40
38
|
for (const sibling of [...siblings, element]) {
|
41
39
|
removeTranslateWhitoutTransition(sibling);
|
42
40
|
}
|
43
41
|
};
|
44
|
-
const
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
const removeAt = (index, targetIndex, draggableElement, draggingState, config) => {
|
43
|
+
const { removingClass, delayBeforeRemove } = currentConfig;
|
44
|
+
if (targetIndex == index) {
|
45
|
+
addClass(draggableElement, removingClass);
|
46
|
+
setTimeout(() => {
|
47
|
+
removeAfterRemovingClass(index, targetIndex, draggableElement, draggingState, config);
|
48
|
+
}, delayBeforeRemove);
|
48
49
|
}
|
49
50
|
};
|
50
|
-
|
51
|
+
const removeAfterRemovingClass = (index, targetIndex, draggableElement, draggingState, config) => {
|
52
|
+
const { removingClass, onRemoveAtEvent } = currentConfig;
|
53
|
+
removeClass(draggableElement, removingClass);
|
54
|
+
addTempChild(draggableElement, parent, draggingState == DraggingState.START_DRAGGING, config);
|
55
|
+
emitRemoveEventToSiblings(targetIndex, draggableElement, config, (sibling) => {
|
56
|
+
removeDraggingStyles(sibling);
|
57
|
+
emitFinishRemoveEventToSiblings(draggableElement);
|
58
|
+
});
|
59
|
+
onRemoveAtEvent(index, true);
|
60
|
+
};
|
61
|
+
const removeDraggingStyles = (element) => {
|
62
|
+
setTranistion(element, animationDuration, draggableTargetTimingFunction);
|
63
|
+
moveTranslate(element);
|
64
|
+
};
|
65
|
+
return [removeAt];
|
51
66
|
}
|
package/dist/core/index.d.ts
CHANGED
package/dist/core/index.js
CHANGED
@@ -1,2 +1,9 @@
|
|
1
1
|
export const HORIZONTAL = 'horizontal';
|
2
2
|
export const VERTICAL = 'vertical';
|
3
|
+
export var DraggingState;
|
4
|
+
(function (DraggingState) {
|
5
|
+
DraggingState[DraggingState["NOT_DRAGGING"] = 0] = "NOT_DRAGGING";
|
6
|
+
DraggingState[DraggingState["START_DRAGGING"] = 1] = "START_DRAGGING";
|
7
|
+
DraggingState[DraggingState["DRAGING"] = 2] = "DRAGING";
|
8
|
+
DraggingState[DraggingState["END_DRAGGING"] = 3] = "END_DRAGGING";
|
9
|
+
})(DraggingState || (DraggingState = {}));
|
@@ -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,4 +1,4 @@
|
|
1
|
-
import { getNearestFixedParentPosition, getPropByDirection,
|
1
|
+
import { getAxisValue, getBefore, getBeforeMarginValue, getBorderBeforeWidthValue, getDistanceValue, getInnerDistance, getNearestFixedParentPosition, getOffsetValue, getPageValue, getPropByDirection, getRect, getScrollValue, 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';
|
@@ -17,19 +17,18 @@ export const usePositioning = (draggedElement, coordinateTransforms) => {
|
|
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) {
|
31
30
|
const newTranslate = elementPosittion -
|
32
|
-
position
|
31
|
+
getBefore(translateDirection, position) -
|
33
32
|
border -
|
34
33
|
margin -
|
35
34
|
scrollValue -
|
@@ -37,7 +36,7 @@ export const usePositioning = (draggedElement, coordinateTransforms) => {
|
|
37
36
|
updateScroll(translateDirection);
|
38
37
|
return newTranslate;
|
39
38
|
}
|
40
|
-
const defaultTransalation = translate
|
39
|
+
const defaultTransalation = getAxisValue(translateDirection, translate);
|
41
40
|
return defaultTransalation;
|
42
41
|
};
|
43
42
|
const updateScroll = (translateDirection) => {
|
@@ -72,16 +71,15 @@ export const usePositioning = (draggedElement, coordinateTransforms) => {
|
|
72
71
|
return [setTransform, updateTransformState];
|
73
72
|
};
|
74
73
|
const getOffsetWithDraggable = (direction, element, draggable) => {
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
getValueFromProperty(draggable, borderBeforeWidth));
|
74
|
+
return (getBefore(direction, getRect(element)) -
|
75
|
+
getBefore(direction, getRect(draggable)) -
|
76
|
+
getBorderBeforeWidthValue(direction, draggable));
|
79
77
|
};
|
80
78
|
const getOffset = (event, draggable) => {
|
81
79
|
let { offsetX, offsetY, target } = event;
|
82
80
|
let targetHandler = getHandlerElementAncestor(target, draggable);
|
83
81
|
const targetElement = target;
|
84
|
-
if (targetElement && targetHandler && !
|
82
|
+
if (targetElement && targetHandler && !isSameNode(targetElement, targetHandler)) {
|
85
83
|
offsetX += getOffsetWithDraggable(HORIZONTAL, targetElement, targetHandler);
|
86
84
|
offsetY += getOffsetWithDraggable(VERTICAL, targetElement, targetHandler);
|
87
85
|
}
|
@@ -93,19 +91,18 @@ const getOffset = (event, draggable) => {
|
|
93
91
|
};
|
94
92
|
const getHandlerElementAncestor = (target, draggable) => {
|
95
93
|
const targetHandler = target?.closest(`.${HANDLER_CLASS}`);
|
96
|
-
if (targetHandler &&
|
94
|
+
if (targetHandler && isSameNode(draggable, targetHandler)) {
|
97
95
|
return target;
|
98
96
|
}
|
99
97
|
return targetHandler;
|
100
98
|
};
|
101
99
|
const getPositionByDistance = (direction, event, element, offsetEvent) => {
|
102
|
-
const { offset, beforeMargin, page, borderBeforeWidth, scroll } = getPropByDirection(direction);
|
103
100
|
const beforefixecParentValue = getNearestFixedParentPosition(element, direction);
|
104
|
-
return (event
|
105
|
-
offsetEvent
|
106
|
-
|
107
|
-
|
108
|
-
window
|
101
|
+
return (getPageValue(direction, event) -
|
102
|
+
getOffsetValue(direction, offsetEvent) -
|
103
|
+
getBeforeMarginValue(direction, element) -
|
104
|
+
getBorderBeforeWidthValue(direction, element) -
|
105
|
+
getScrollValue(direction, window) -
|
109
106
|
beforefixecParentValue);
|
110
107
|
};
|
111
108
|
export const getTransformState = (event, element, draggable) => {
|
@@ -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,57 @@ 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
60
|
if (!droppableConfig) {
|
57
61
|
return;
|
58
62
|
}
|
59
|
-
const { droppable, config } = droppableConfig;
|
63
|
+
const { droppable, config, scroll } = droppableConfig;
|
60
64
|
const { direction, animationDuration } = config;
|
61
|
-
fixScrollInitialChange(
|
65
|
+
fixScrollInitialChange(droppable, config, scroll, ifStartDragging);
|
62
66
|
if (droppable.querySelector(`.${TEMP_CHILD_CLASS}`) || !draggedElement) {
|
63
67
|
return;
|
64
68
|
}
|
65
69
|
var tempChildTag = draggedElement.tagName == 'LI' ? 'DIV' : draggedElement.tagName;
|
66
70
|
var child = document.createElement(tempChildTag);
|
67
71
|
addClass(child, TEMP_CHILD_CLASS);
|
68
|
-
setSizes(child
|
72
|
+
setSizes(child);
|
69
73
|
const distances = getDistance(droppable, draggedElement, direction);
|
70
|
-
setTranistion(child, addingAnimationDuration ?? animationDuration, timingFunction,
|
74
|
+
setTranistion(child, addingAnimationDuration ?? animationDuration, timingFunction, TRANSITION_PROPERTY);
|
71
75
|
return [child, distances, droppable];
|
72
76
|
};
|
73
77
|
export const addTempChild = (draggedElement, parent, ifStartDragging, droppableConfig, addingAnimationDuration) => {
|
@@ -76,8 +80,8 @@ export const addTempChild = (draggedElement, parent, ifStartDragging, droppableC
|
|
76
80
|
return;
|
77
81
|
}
|
78
82
|
const [child, distances, droppable] = result;
|
79
|
-
if (
|
80
|
-
setSizes(child, distances
|
83
|
+
if (isSameNode(parent, droppable)) {
|
84
|
+
setSizes(child, distances);
|
81
85
|
}
|
82
86
|
observeMutation(updateChildAfterCreated(child, droppable, distances), droppable, {
|
83
87
|
childList: true,
|
@@ -96,9 +100,9 @@ export const addTempChildOnInsert = (draggedElement, ifStartDragging, droppableC
|
|
96
100
|
};
|
97
101
|
const setSizeAfterAppendChild = (child, size) => {
|
98
102
|
return requestAnimationFrame(() => {
|
99
|
-
setSizes(child, size
|
103
|
+
setSizes(child, size);
|
100
104
|
requestAnimationFrame(() => {
|
101
|
-
setTranistion(child, 0, timingFunction,
|
105
|
+
setTranistion(child, 0, timingFunction, TRANSITION_PROPERTY);
|
102
106
|
});
|
103
107
|
});
|
104
108
|
};
|
@@ -109,12 +113,12 @@ export const removeTempChildrens = (droppable, parent, droppableGroupClass, anim
|
|
109
113
|
var children = document.querySelectorAll(`${getClassesSelector(droppableGroupClass)} > .${TEMP_CHILD_CLASS}`);
|
110
114
|
children.forEach((tempChild) => {
|
111
115
|
const childParent = tempChild.parentElement;
|
112
|
-
if (
|
113
|
-
(!draggedElementIsOutside &&
|
116
|
+
if (isSameNode(parent, childParent) ||
|
117
|
+
(!draggedElementIsOutside && isSameNode(droppable, childParent))) {
|
114
118
|
return;
|
115
119
|
}
|
116
120
|
const tempChildElement = tempChild;
|
117
|
-
setSizes(tempChildElement
|
121
|
+
setSizes(tempChildElement);
|
118
122
|
setTimeout(() => {
|
119
123
|
tempChild.parentNode?.removeChild(tempChild);
|
120
124
|
}, animationDuration + DELAY_TIME);
|
@@ -125,7 +129,7 @@ export const removeTempChild = (parent, animationDuration, isAnimated = false) =
|
|
125
129
|
lastChildren.forEach((lastChild) => {
|
126
130
|
const tempChildElement = lastChild;
|
127
131
|
if (isAnimated) {
|
128
|
-
setSizes(tempChildElement
|
132
|
+
setSizes(tempChildElement);
|
129
133
|
setTimeout(() => {
|
130
134
|
if (parent.contains(tempChildElement)) {
|
131
135
|
parent.removeChild(tempChildElement);
|
@@ -1,24 +1,18 @@
|
|
1
1
|
import { assignDraggingEvent, convetEventToDragMouseTouchEvent, moveTranslate, setCustomFixedSize, setEventWithInterval, setTranistion } from './utils/SetStyles';
|
2
2
|
import { usePositioning } from './positioning/usePositioning';
|
3
|
-
import
|
3
|
+
import { DraggingState } from '.';
|
4
4
|
import { DRAG_EVENT, draggableTargetTimingFunction, START_DRAG_EVENT, START_DROP_EVENT } from './utils';
|
5
5
|
import ConfigHandler from './config/configHandler';
|
6
6
|
import { IsHTMLElement, isTouchEvent } from './utils/typesCheckers';
|
7
|
-
import { addTempChild,
|
7
|
+
import { addTempChild, removeTempChildrens } from './tempChildren';
|
8
8
|
import { DroppableConfigurator } from './config/droppableConfigurator';
|
9
|
-
import { addClass, containClass, getClassesList, getClassesSelector,
|
9
|
+
import { addClass, containClass, getClassesList, getClassesSelector, toggleClass } from './utils/dom/classList';
|
10
10
|
import { DRAGGABLE_CLASS, DRAGGING_CLASS, DROPPABLE_CLASS, HANDLER_CLASS } from './utils/classes';
|
11
11
|
import useDragAndDropEvents from './events/dragAndDrop/dragAndDrop';
|
12
|
-
import
|
13
|
-
|
14
|
-
(function (DraggingState) {
|
15
|
-
DraggingState[DraggingState["NOT_DRAGGING"] = 0] = "NOT_DRAGGING";
|
16
|
-
DraggingState[DraggingState["START_DRAGGING"] = 1] = "START_DRAGGING";
|
17
|
-
DraggingState[DraggingState["DRAGING"] = 2] = "DRAGING";
|
18
|
-
DraggingState[DraggingState["END_DRAGGING"] = 3] = "END_DRAGGING";
|
19
|
-
})(DraggingState || (DraggingState = {}));
|
12
|
+
import { getRect, isSameNode } from './utils/GetStyles';
|
13
|
+
const ON_MOUSEDOWN = 'onmousedown';
|
20
14
|
export default function useDraggable(draggableElement, index, config, parent, handlerPublisher) {
|
21
|
-
const { handlerSelector, isDraggable, droppableGroup, animationDuration,
|
15
|
+
const { handlerSelector, isDraggable, droppableGroup, animationDuration, draggingClass, droppableClass, onDragStart, delayBeforeTouchMoveEvent, coordinateTransform } = config;
|
22
16
|
const droppableGroupClass = getClassesList(droppableGroup)
|
23
17
|
.map((classGroup) => `droppable-group-${classGroup}`)
|
24
18
|
.join(' ');
|
@@ -34,9 +28,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
34
28
|
const endDraggingState = () => {
|
35
29
|
draggingState = DraggingState.NOT_DRAGGING;
|
36
30
|
};
|
37
|
-
const [emitRemoveEventToSiblings, emitFinishRemoveEventToSiblings] = useRemoveEvents(config, parent, handlerPublisher, endDraggingState);
|
38
31
|
const [emitDraggingEvent, emitDroppingEvent, toggleDraggingClass] = useDragAndDropEvents(config, index, parent, droppableGroupClass, handlerPublisher, endDraggingState);
|
39
|
-
const [emitInsertEventToSiblings] = useInsertEvents(config, parent, handlerPublisher, endDraggingState);
|
40
32
|
const setDraggable = () => {
|
41
33
|
addClass(draggableElement, DRAGGABLE_CLASS);
|
42
34
|
};
|
@@ -65,7 +57,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
65
57
|
if (handler &&
|
66
58
|
handlerParent &&
|
67
59
|
containClass(handlerParent, DROPPABLE_CLASS) &&
|
68
|
-
!
|
60
|
+
!isSameNode(parent, handlerParent)) {
|
69
61
|
return null;
|
70
62
|
}
|
71
63
|
return handler;
|
@@ -73,22 +65,22 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
73
65
|
const setSlotRefElementParams = (element) => {
|
74
66
|
const handlerElement = (getHandler(element) ?? element);
|
75
67
|
if (handlerElement && isDraggable(element)) {
|
76
|
-
assignDraggingEvent(handlerElement,
|
68
|
+
assignDraggingEvent(handlerElement, ON_MOUSEDOWN, onmousedown('mousemove', 'mouseup'));
|
77
69
|
assignDraggingEvent(handlerElement, 'ontouchstart', onmousedown('touchmove', 'touchend'), (event) => {
|
70
|
+
const touch = event.touches[0];
|
78
71
|
initialTouch = {
|
79
|
-
x:
|
80
|
-
y:
|
72
|
+
x: touch.clientX,
|
73
|
+
y: touch.clientY
|
81
74
|
};
|
82
75
|
});
|
83
76
|
disableMousedownEventFromImages(handlerElement);
|
84
77
|
}
|
85
|
-
if (!
|
86
|
-
assignDraggingEvent(element,
|
78
|
+
if (!isSameNode(element, handlerElement)) {
|
79
|
+
assignDraggingEvent(element, ON_MOUSEDOWN, mousedownOnDraggablefunction);
|
87
80
|
}
|
88
81
|
addClass(parent, DROPPABLE_CLASS);
|
89
82
|
};
|
90
83
|
const disableMousedownEventFromImages = (handlerElement) => {
|
91
|
-
// Avoid dragging inner images
|
92
84
|
const images = handlerElement.querySelectorAll('img');
|
93
85
|
Array.from(images).forEach((image) => {
|
94
86
|
image.onmousedown = () => false;
|
@@ -105,11 +97,18 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
105
97
|
setTransform(draggableElement, droppable, pagePosition, config.direction);
|
106
98
|
emitDraggingEvent(draggableElement, DRAG_EVENT, droppableConfigurator.current);
|
107
99
|
};
|
100
|
+
const removeTranslates = (droppable) => {
|
101
|
+
const drgagables = droppable.querySelectorAll(`.${DRAGGABLE_CLASS}`);
|
102
|
+
for (const draggable of drgagables) {
|
103
|
+
moveTranslate(draggable);
|
104
|
+
}
|
105
|
+
};
|
108
106
|
const changeDroppable = (newdDroppableConfig, oldDroppableConfig) => {
|
109
107
|
if (oldDroppableConfig &&
|
110
108
|
draggingState == DraggingState.DRAGING &&
|
111
|
-
!newdDroppableConfig?.droppable
|
109
|
+
!isSameNode(newdDroppableConfig?.droppable, oldDroppableConfig.droppable)) {
|
112
110
|
emitDraggingEvent(draggableElement, DRAG_EVENT, oldDroppableConfig);
|
111
|
+
removeTranslates(oldDroppableConfig.droppable);
|
113
112
|
}
|
114
113
|
};
|
115
114
|
const droppableConfigurator = new DroppableConfigurator(draggableElement, droppableGroupClass, parent, setTransformDragEvent, changeDroppable, config.mapFrom);
|
@@ -121,7 +120,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
121
120
|
? Array.from(document.querySelectorAll(getClassesSelector(droppableGroupClass)))
|
122
121
|
: [parent];
|
123
122
|
for (const droppable of droppables) {
|
124
|
-
droppable.classList.toggle(droppableClass, !isOutside &&
|
123
|
+
droppable.classList.toggle(droppableClass, !isOutside && isSameNode(droppable, droppableConfigurator.current.droppable));
|
125
124
|
}
|
126
125
|
};
|
127
126
|
const onMove = (event, isTouchEvent = false) => {
|
@@ -149,8 +148,9 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
149
148
|
};
|
150
149
|
const cursorWasNotMoved = (event) => {
|
151
150
|
if (isTouchEvent(event) && initialTouch && draggingState == DraggingState.START_DRAGGING) {
|
152
|
-
const
|
153
|
-
const
|
151
|
+
const touch = event.touches[0];
|
152
|
+
const movedX = Math.abs(touch.clientX - initialTouch.x);
|
153
|
+
const movedY = Math.abs(touch.clientY - initialTouch.y);
|
154
154
|
if (Math.abs(movedX) > 5 && Math.abs(movedY) > 5) {
|
155
155
|
clearTimeout(delayTimeout);
|
156
156
|
return false;
|
@@ -184,7 +184,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
184
184
|
const { clientX, clientY } = event;
|
185
185
|
const elementBelow = document.elementFromPoint(clientX, clientY);
|
186
186
|
const draggableAncestor = elementBelow?.closest(`.${DRAGGABLE_CLASS}`);
|
187
|
-
return draggableAncestor &&
|
187
|
+
return draggableAncestor && isSameNode(element, draggableAncestor);
|
188
188
|
};
|
189
189
|
const getDragStartEventData = (element) => {
|
190
190
|
const value = config.onGetValue(index);
|
@@ -233,7 +233,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
233
233
|
const disableDragging = (moveEvent, event) => {
|
234
234
|
toggleDroppableClass(true);
|
235
235
|
const convertedEvent = convetEventToDragMouseTouchEvent(event);
|
236
|
-
onDropDraggingEvent(droppableConfigurator.isOutside(convertedEvent
|
236
|
+
onDropDraggingEvent(droppableConfigurator.isOutside(convertedEvent));
|
237
237
|
clearTimeout(delayTimeout);
|
238
238
|
document.removeEventListener(moveEvent, handleMove);
|
239
239
|
droppableConfigurator.updateConfig(convertedEvent);
|
@@ -291,10 +291,10 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
291
291
|
};
|
292
292
|
const removeDraggingStyles = (element) => {
|
293
293
|
setTranistion(element, animationDuration, draggableTargetTimingFunction);
|
294
|
-
moveTranslate(element
|
294
|
+
moveTranslate(element);
|
295
295
|
};
|
296
296
|
const setDraggingStyles = (element) => {
|
297
|
-
const { height, width } = element
|
297
|
+
const { height, width } = getRect(element);
|
298
298
|
setCustomFixedSize(element, {
|
299
299
|
fixedHeight: `${height}px`,
|
300
300
|
fixedWidth: `${width}px`
|
@@ -303,32 +303,21 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
303
303
|
toggleClass(element, draggingClass, true);
|
304
304
|
element.style.transition = '';
|
305
305
|
};
|
306
|
-
const removeAfterRemovingClass = (targetIndex, config) => {
|
307
|
-
removeClass(draggableElement, removingClass);
|
308
|
-
addTempChild(draggableElement, parent, draggingState == DraggingState.START_DRAGGING, droppableConfigurator.initial);
|
309
|
-
emitRemoveEventToSiblings(targetIndex, draggableElement, config, (sibling) => {
|
310
|
-
removeDraggingStyles(sibling);
|
311
|
-
emitFinishRemoveEventToSiblings(draggableElement);
|
312
|
-
});
|
313
|
-
onRemoveAtEvent(index, true);
|
314
|
-
};
|
315
306
|
const removeAtFromElement = (targetIndex) => {
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
removeAfterRemovingClass(targetIndex, config);
|
324
|
-
}, delayBeforeRemove);
|
325
|
-
}
|
307
|
+
import('./events/remove').then((module) => {
|
308
|
+
const [removeAt] = module.default(config, parent, handlerPublisher, endDraggingState);
|
309
|
+
if (!droppableConfigurator.initial) {
|
310
|
+
return;
|
311
|
+
}
|
312
|
+
removeAt(index, targetIndex, draggableElement, draggingState, droppableConfigurator.initial);
|
313
|
+
});
|
326
314
|
};
|
327
315
|
const insertAtFromElement = (targetIndex, value) => {
|
328
316
|
if (targetIndex === index ||
|
329
317
|
(targetIndex === config.onGetLegth() && index === targetIndex - 1)) {
|
330
|
-
|
331
|
-
|
318
|
+
import('./events/insert').then((module) => {
|
319
|
+
const [emitInsertEventToSiblings] = module.default(config, parent, handlerPublisher, endDraggingState);
|
320
|
+
emitInsertEventToSiblings(targetIndex, draggableElement, parent, value, droppableConfigurator.initial);
|
332
321
|
});
|
333
322
|
}
|
334
323
|
};
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import { CoreConfig } from
|
2
|
-
import HandlerPublisher from
|
1
|
+
import { CoreConfig } from '.';
|
2
|
+
import HandlerPublisher from './HandlerPublisher';
|
3
3
|
export default function useDroppable<T>(coreConfig: CoreConfig<T>, handlerPublisher: HandlerPublisher, droppable?: HTMLElement, indexAttr?: string): readonly [((targetIndex: number) => void)[], ((targetIndex: number, value: T) => void)[]];
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { parseIntEmpty } from
|
2
|
-
import { addMultipleClasses, getClassesList } from
|
3
|
-
import useDraggable from
|
4
|
-
import { AddCssStylesToElement } from
|
5
|
-
import { DRAGGABLE_CLASS, DRAGGING_CLASS, DRAGGING_HANDLER_CLASS, DROPPING_CLASS, GRAB_CLASS, GRABBING_CLASS, HANDLER_CLASS } from
|
1
|
+
import { parseIntEmpty } from './utils/GetStyles';
|
2
|
+
import { addMultipleClasses, getClassesList } from './utils/dom/classList';
|
3
|
+
import useDraggable from './useDraggable';
|
4
|
+
import { AddCssStylesToElement } from './utils/SetStyles';
|
5
|
+
import { DRAGGABLE_CLASS, DRAGGING_CLASS, DRAGGING_HANDLER_CLASS, DROPPING_CLASS, GRAB_CLASS, GRABBING_CLASS, HANDLER_CLASS } from './utils/classes';
|
6
6
|
const setDroppableGroupClass = (droppableGroupClass, droppable) => {
|
7
7
|
if (droppableGroupClass) {
|
8
8
|
addMultipleClasses(droppable, droppableGroupClass);
|
@@ -13,13 +13,13 @@ const createDraggableCssStyles = () => {
|
|
13
13
|
`.${DRAGGABLE_CLASS}{touch-action:manipulation;user-select:none;box-sizing:border-box!important;-webkit-user-select:none;}`,
|
14
14
|
`.${HANDLER_CLASS}{pointer-events:auto!important;}`,
|
15
15
|
`.${GRAB_CLASS}{cursor:grab;}`,
|
16
|
-
|
16
|
+
'.temp-child{touch-action:none;pointer-events:none;box-sizing:border-box!important;}',
|
17
17
|
`.droppable{box-sizing:border-box!important;}`,
|
18
18
|
`.${DRAGGING_CLASS}{position:fixed;z-index:5000;width:var(--fixedWidth)!important;height:var(--fixedHeight)!important;}`,
|
19
19
|
`.${DRAGGING_HANDLER_CLASS}{pointer-events:none!important;}`,
|
20
20
|
`.${DROPPING_CLASS}{pointer-events:none!important;}`,
|
21
21
|
`.${GRABBING_CLASS}{cursor:grabbing;}`,
|
22
|
-
`.disable-transition{transition:none!important;}
|
22
|
+
`.disable-transition{transition:none!important;}`
|
23
23
|
]);
|
24
24
|
};
|
25
25
|
export default function useDroppable(coreConfig, handlerPublisher, droppable, indexAttr = 'index') {
|
@@ -28,14 +28,11 @@ export default function useDroppable(coreConfig, handlerPublisher, droppable, in
|
|
28
28
|
let insertAtFromElementList = [];
|
29
29
|
const { droppableGroup } = coreConfig;
|
30
30
|
if (!droppable) {
|
31
|
-
return [
|
32
|
-
removeAtFromElementList,
|
33
|
-
insertAtFromElementList
|
34
|
-
];
|
31
|
+
return [removeAtFromElementList, insertAtFromElementList];
|
35
32
|
}
|
36
33
|
const droppableGroupClass = getClassesList(droppableGroup)
|
37
34
|
.map((classGroup) => `droppable-group-${classGroup}`)
|
38
|
-
.join(
|
35
|
+
.join(' ');
|
39
36
|
createDraggableCssStyles();
|
40
37
|
setDroppableGroupClass(droppableGroupClass, droppable);
|
41
38
|
for (const child of droppable.children) {
|
@@ -48,8 +45,5 @@ export default function useDroppable(coreConfig, handlerPublisher, droppable, in
|
|
48
45
|
insertAtFromElementList.push(insertAtFromElement);
|
49
46
|
}
|
50
47
|
}
|
51
|
-
return [
|
52
|
-
removeAtFromElementList,
|
53
|
-
insertAtFromElementList
|
54
|
-
];
|
48
|
+
return [removeAtFromElementList, insertAtFromElementList];
|
55
49
|
}
|