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
package/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
<h1 align="center">
|
2
|
-
<img src="public/fluid-dnd.
|
3
|
-
alt="Icon" width="
|
4
|
-
<br>Fluid DnD<br>
|
2
|
+
<img src="public/fluid-dnd-logo.png"
|
3
|
+
alt="Icon" width="200" height="200" />
|
5
4
|
</h1>
|
6
5
|
|
7
6
|
<div align="center">
|
@@ -11,15 +10,20 @@
|
|
11
10
|
[](https://www.npmjs.com/package/fluid-dnd)
|
12
11
|

|
13
12
|

|
14
|
-
[](https://codeclimate.com/github/carlosjorger/fluid-dnd/test_coverage)
|
15
13
|
|
16
|
-
|
14
|
+
_Drag and drop elements of your list smoothly and effortlessly_
|
17
15
|
|
18
|
-
|
19
|
-
library for lists; with support for **Vue**, **React** and **Svelte**](https://fluid-dnd.netlify.app/). It's a **lightweight** tool ~8 Kb (gzip) with no depenencies.
|
16
|
+
[📖 **Documentation**](https://fluid-dnd.netlify.app/) | [🤹 **Examples**](https://fluid-dnd.netlify.app/vue/example/vertical-list/single-vertical-list/)
|
20
17
|
|
21
18
|
<img src="https://github.com/user-attachments/assets/1b7ac5e3-48e9-43f9-a577-e78c6b9eacae" width="100%"/>
|
22
19
|
|
20
|
+
</div>
|
21
|
+
|
22
|
+
## 🪪 About
|
23
|
+
|
24
|
+
Fluid DnD is a **fluid**, **agnostic** and **versatile** drag and drop
|
25
|
+
library for lists; with support for **Vue**, **React** and **Svelte**. It's a **lightweight** tool ~8 Kb (gzip) with no depenencies.
|
26
|
+
|
23
27
|
## 🧰 Features
|
24
28
|
|
25
29
|
- ✅ **Fully customizable 🎨**.
|
@@ -50,21 +54,16 @@ library for lists; with support for **Vue**, **React** and **Svelte**](https://f
|
|
50
54
|
pnpm i fluid-dnd
|
51
55
|
```
|
52
56
|
|
53
|
-
3. **Documentation**
|
54
|
-
|
55
|
-
- 📚 Check out all the [docs](https://fluid-dnd.netlify.app/).
|
56
|
-
- 🛠️ Edit this example [here](https://codesandbox.io/s/nifty-hooks-5plkpl).
|
57
|
-
- 📘 See other examples [here](https://fluid-dnd.netlify.app/vue/example/vertical-list/single-vertical-list/).
|
58
|
-
|
59
57
|
## 📚 Libraries Support
|
58
|
+
|
60
59
|
- **Vue** >=3.0.0
|
61
60
|
- **React** >= 18.0.0
|
62
61
|
- **Svelte** >= 5.0.0
|
63
62
|
|
64
63
|
## 🤝 Contributing
|
65
64
|
|
66
|
-
If you're interested in contributing to [fluid-dnd](https://github.com/carlosjorger/fluid-dnd), please read our [CONTRIBUTING
|
65
|
+
If you're interested in contributing to [fluid-dnd](https://github.com/carlosjorger/fluid-dnd), please read our [CONTRIBUTING GUIDELINES](./CONTRIBUTING.md) before submitting a pull request.
|
67
66
|
|
68
67
|
## 🔑 License
|
69
68
|
|
70
|
-
- [MIT](https://github.com/carlosjorger/fluid-dnd/blob/main/LICENSE).
|
69
|
+
- [MIT](https://github.com/carlosjorger/fluid-dnd/blob/main/LICENSE).
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";var d=Object.defineProperty;var n=(e,s,l)=>s in e?d(e,s,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[s]=l;var a=(e,s,l)=>n(e,typeof s!="symbol"?s+"":s,l);const r=require("./index-
|
1
|
+
"use strict";var d=Object.defineProperty;var n=(e,s,l)=>s in e?d(e,s,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[s]=l;var a=(e,s,l)=>n(e,typeof s!="symbol"?s+"":s,l);const r=require("./index-BdOAK6C7.cjs");class h{constructor(){a(this,"handlers");this.handlers=[]}addSubscriber(s){this.handlers.includes(s)||(this.handlers.push(s),r.addClass(s,r.GRAB_CLASS))}toggleGrabClass(s){for(const l of this.handlers)r.toggleClass(l,r.GRAB_CLASS,s)}}exports.HandlerPublisher=h;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
var d = Object.defineProperty;
|
2
2
|
var e = (a, s, l) => s in a ? d(a, s, { enumerable: !0, configurable: !0, writable: !0, value: l }) : a[s] = l;
|
3
3
|
var r = (a, s, l) => e(a, typeof s != "symbol" ? s + "" : s, l);
|
4
|
-
import { a as h, t as n, G as t } from "./index-
|
4
|
+
import { a as h, t as n, G as t } from "./index-HczUoMBK.js";
|
5
5
|
class c {
|
6
6
|
constructor() {
|
7
7
|
r(this, "handlers");
|
@@ -1,9 +1,9 @@
|
|
1
|
-
import { getScrollElement } from '../utils/GetStyles';
|
1
|
+
import { getScrollElement, isSameNode } from '../utils/GetStyles';
|
2
2
|
import { containstClasses } from '../utils/dom/classList';
|
3
3
|
export default class ConfigHandler {
|
4
4
|
static configs = [];
|
5
5
|
static addConfig(droppable, config) {
|
6
|
-
const configs = ConfigHandler.configs.filter((configHandler) => !configHandler.droppable
|
6
|
+
const configs = ConfigHandler.configs.filter((configHandler) => !isSameNode(configHandler.droppable, droppable));
|
7
7
|
const scroll = getScrollElement(droppable);
|
8
8
|
configs.push({
|
9
9
|
droppable,
|
@@ -20,13 +20,13 @@ export default class ConfigHandler {
|
|
20
20
|
for (const configHandler of ConfigHandler.configs) {
|
21
21
|
const { droppable } = configHandler;
|
22
22
|
if ((droppableGroupClass && containstClasses(droppable, droppableGroupClass)) ||
|
23
|
-
|
23
|
+
isSameNode(currentDroppable, droppable)) {
|
24
24
|
configHandler.scroll = getScrollElement(droppable);
|
25
25
|
}
|
26
26
|
}
|
27
27
|
}
|
28
28
|
static getConfig(curerntDroppable) {
|
29
|
-
const config = ConfigHandler.configs.find(({ droppable }) =>
|
29
|
+
const config = ConfigHandler.configs.find(({ droppable }) => isSameNode(curerntDroppable, droppable));
|
30
30
|
return config;
|
31
31
|
}
|
32
32
|
}
|
@@ -19,7 +19,8 @@ export declare class DroppableConfigurator<T> {
|
|
19
19
|
private onScrollEvent;
|
20
20
|
private setOnScroll;
|
21
21
|
getConfigFrom(element: Element): DroppableConfig<any> | undefined;
|
22
|
+
droppableIfInsideCurrent(droppable: Element | null | undefined, current: HTMLElement): boolean | null | undefined;
|
22
23
|
getCurrentConfig(event: DragMouseTouchEvent): DroppableConfig<any> | DroppableConfig<T> | undefined;
|
23
24
|
updateConfig(event: DragMouseTouchEvent): void;
|
24
|
-
isOutside(event: DragMouseTouchEvent
|
25
|
+
isOutside(event: DragMouseTouchEvent): boolean;
|
25
26
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import ConfigHandler from './configHandler';
|
2
|
-
import { draggableIsOutside } from '../utils/GetStyles';
|
2
|
+
import { draggableIsOutside, isSameNode } from '../utils/GetStyles';
|
3
3
|
import { IsHTMLElement } from '../utils/typesCheckers';
|
4
4
|
import { setEventWithInterval } from '../utils/SetStyles';
|
5
5
|
import { getClassesSelector } from '../utils/dom/classList';
|
@@ -34,32 +34,23 @@ export class DroppableConfigurator {
|
|
34
34
|
this.groupClass = droppableGroupClass;
|
35
35
|
this.dragEvent = setTransformDragEvent;
|
36
36
|
this.mapFrom = mapFrom;
|
37
|
-
this.initial =
|
37
|
+
this.initial = ConfigHandler.getConfig(parent);
|
38
38
|
this.changeDroppable = changeDroppable;
|
39
39
|
}
|
40
40
|
getDraggableAncestor(clientX, clientY, draggable) {
|
41
41
|
return document
|
42
42
|
.elementsFromPoint(clientX, clientY)
|
43
|
-
.filter((element) => !
|
43
|
+
.filter((element) => !isSameNode(draggable, element));
|
44
44
|
}
|
45
|
-
getElementBelow(currentElement, event
|
45
|
+
getElementBelow(currentElement, event) {
|
46
46
|
const getElementBelow = (config) => {
|
47
47
|
const [elementBelow] = config.getDraggableAncestor(event.clientX, event.clientY, currentElement);
|
48
48
|
return elementBelow;
|
49
49
|
};
|
50
|
-
|
51
|
-
if (hiddenDraggable) {
|
52
|
-
currentElement.hidden = true;
|
53
|
-
elementBelow = getElementBelow(this);
|
54
|
-
currentElement.hidden = false;
|
55
|
-
}
|
56
|
-
else {
|
57
|
-
elementBelow = getElementBelow(this);
|
58
|
-
}
|
59
|
-
return elementBelow;
|
50
|
+
return getElementBelow(this);
|
60
51
|
}
|
61
|
-
getCurrent(currentElement, event
|
62
|
-
const elementBelow = this.getElementBelow(currentElement, event
|
52
|
+
getCurrent(currentElement, event) {
|
53
|
+
const elementBelow = this.getElementBelow(currentElement, event);
|
63
54
|
if (!this.groupClass || !elementBelow) {
|
64
55
|
return;
|
65
56
|
}
|
@@ -89,7 +80,7 @@ export class DroppableConfigurator {
|
|
89
80
|
if (!coreConfig) {
|
90
81
|
return undefined;
|
91
82
|
}
|
92
|
-
if (
|
83
|
+
if (isSameNode(this.parent, element)) {
|
93
84
|
return coreConfig;
|
94
85
|
}
|
95
86
|
return {
|
@@ -97,12 +88,17 @@ export class DroppableConfigurator {
|
|
97
88
|
config: MapConfig(coreConfig, this.mapFrom)
|
98
89
|
};
|
99
90
|
}
|
91
|
+
droppableIfInsideCurrent(droppable, current) {
|
92
|
+
return droppable && !isSameNode(current, droppable) && current.contains(droppable);
|
93
|
+
}
|
100
94
|
getCurrentConfig(event) {
|
101
95
|
const currentElement = this.draggableElement;
|
102
|
-
|
96
|
+
const currentDroppable = this.getCurrent(currentElement, event);
|
97
|
+
if (this.current &&
|
98
|
+
this.isNotInsideAnotherDroppable(currentElement, this.current?.droppable) &&
|
99
|
+
!this.droppableIfInsideCurrent(currentDroppable, this.current?.droppable)) {
|
103
100
|
return this.current;
|
104
101
|
}
|
105
|
-
const currentDroppable = this.getCurrent(currentElement, event);
|
106
102
|
if (!currentDroppable) {
|
107
103
|
return this.getConfigFrom(this.parent);
|
108
104
|
}
|
@@ -116,8 +112,8 @@ export class DroppableConfigurator {
|
|
116
112
|
this.current = this.getCurrentConfig(event);
|
117
113
|
this.changeDroppable(this.current, oldDroppableConfig);
|
118
114
|
}
|
119
|
-
isOutside(event
|
115
|
+
isOutside(event) {
|
120
116
|
const currentElement = this.draggableElement;
|
121
|
-
return !Boolean(this.getCurrent(currentElement, event
|
117
|
+
return !Boolean(this.getCurrent(currentElement, event));
|
122
118
|
}
|
123
119
|
}
|
@@ -1,14 +1,13 @@
|
|
1
1
|
import { DRAGGING_CLASS, DRAGGING_HANDLER_CLASS, GRABBING_CLASS } from '../utils/classes';
|
2
2
|
import { toggleClass } from '../utils/dom/classList';
|
3
|
-
import { moveTranslate, setCustomFixedSize, setTranistion } from '../utils/SetStyles';
|
3
|
+
import { moveTranslate, removeTranslateWhitoutTransition, setCustomFixedSize, setTranistion } from '../utils/SetStyles';
|
4
4
|
import { draggableTargetTimingFunction } from '../utils';
|
5
5
|
export const useChangeDraggableStyles = (currentConfig, handlerPublisher, endDraggingAction) => {
|
6
6
|
const { handlerSelector, animationDuration } = currentConfig;
|
7
7
|
const removeElementDraggingStyles = (element) => {
|
8
8
|
endDraggingAction();
|
9
9
|
toggleDraggingClass(element, false);
|
10
|
-
element
|
11
|
-
element.style.transition = '';
|
10
|
+
removeTranslateWhitoutTransition(element);
|
12
11
|
element.style.top = '';
|
13
12
|
element.style.left = '';
|
14
13
|
setCustomFixedSize(element, {
|
@@ -32,9 +31,8 @@ export const useChangeDraggableStyles = (currentConfig, handlerPublisher, endDra
|
|
32
31
|
}
|
33
32
|
};
|
34
33
|
const dragEventOverElement = (element, translation) => {
|
35
|
-
const { width, height } = translation;
|
36
|
-
moveTranslate(element, height, width);
|
37
34
|
setTranistion(element, animationDuration, draggableTargetTimingFunction);
|
35
|
+
moveTranslate(element, translation);
|
38
36
|
};
|
39
37
|
return [removeElementDraggingStyles, toggleDraggingClass, dragEventOverElement];
|
40
38
|
};
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { draggableIsOutside,
|
2
|
-
import { moveTranslate } from '../../utils/SetStyles';
|
1
|
+
import { draggableIsOutside, getAxisValue, getBefore, getDistanceValue, getRect, getSiblings, getTransform, getWindowScroll, isSameNode } from '../../utils/GetStyles';
|
2
|
+
import { moveTranslate, removeTranslateWhitoutTransition } from '../../utils/SetStyles';
|
3
3
|
import getTranslationByDragging from './getTranslationByDraggingAndEvent';
|
4
4
|
import getTranslateBeforeDropping from './getTranslateBeforeDropping';
|
5
|
-
import { DRAG_EVENT, START_DRAG_EVENT, START_DROP_EVENT, TEMP_CHILD_CLASS } from '../../utils';
|
5
|
+
import { DRAG_EVENT, NONE_TRANSLATE, START_DRAG_EVENT, START_DROP_EVENT, TEMP_CHILD_CLASS } from '../../utils';
|
6
6
|
import { IsHTMLElement } from '../../utils/typesCheckers';
|
7
7
|
import { removeTempChild } from '../../tempChildren';
|
8
8
|
import { DRAGGABLE_CLASS, DROPPING_CLASS } from '../../utils/classes';
|
@@ -11,7 +11,7 @@ import { useChangeDraggableStyles } from '../changeDraggableStyles';
|
|
11
11
|
const DELAY_TIME_TO_SWAP = 50;
|
12
12
|
export default function useDragAndDropEvents(currentConfig, index, parent, droppableGroupClass, handlerPublisher, endDraggingAction) {
|
13
13
|
let actualIndex = index;
|
14
|
-
const {
|
14
|
+
const { onRemoveAtEvent, animationDuration, draggingClass } = currentConfig;
|
15
15
|
const [removeElementDraggingStyles, toggleDraggingClass, dragEventOverElement] = useChangeDraggableStyles(currentConfig, handlerPublisher, endDraggingAction);
|
16
16
|
const emitDraggingEvent = (draggedElement, event, droppableConfig) => {
|
17
17
|
if (!droppableConfig) {
|
@@ -19,29 +19,29 @@ export default function useDragAndDropEvents(currentConfig, index, parent, dropp
|
|
19
19
|
}
|
20
20
|
const { droppable, config } = droppableConfig;
|
21
21
|
const tranlation = getTranslationByDragging(draggedElement, event, config.direction, droppable);
|
22
|
-
emitDraggingEventToSiblings(draggedElement, event, tranlation,
|
22
|
+
emitDraggingEventToSiblings(draggedElement, event, tranlation, droppable, config);
|
23
23
|
};
|
24
24
|
const emitDroppingEvent = (draggedElement, event, droppableConfig, initialWindowScroll, positionOnSourceDroppable) => {
|
25
25
|
if (!droppableConfig) {
|
26
26
|
return;
|
27
27
|
}
|
28
|
-
const { droppable, config } = droppableConfig;
|
28
|
+
const { droppable, scroll, config } = droppableConfig;
|
29
29
|
const tranlation = getTranslationByDragging(draggedElement, event, config.direction, droppable);
|
30
|
-
emitDroppingEventToSiblings(draggedElement, event, tranlation, initialWindowScroll,
|
30
|
+
emitDroppingEventToSiblings(draggedElement, event, tranlation, initialWindowScroll, droppable, scroll, config, positionOnSourceDroppable);
|
31
31
|
};
|
32
32
|
// #region Drag events
|
33
|
-
const emitDraggingEventToSiblings = (draggedElement, event, translation,
|
34
|
-
const { config, droppable } = droppableConfig;
|
33
|
+
const emitDraggingEventToSiblings = (draggedElement, event, translation, droppable, config) => {
|
35
34
|
const [siblings] = getSiblings(draggedElement, droppable);
|
36
35
|
const isOutside = draggableIsOutside(draggedElement, droppable);
|
36
|
+
const { direction } = config;
|
37
37
|
if (siblings.length == 0) {
|
38
|
-
updateActualIndexBaseOnTranslation(translation, 1,
|
38
|
+
updateActualIndexBaseOnTranslation(translation, 1, direction, siblings);
|
39
39
|
}
|
40
40
|
for (const [index, sibling] of siblings.entries()) {
|
41
41
|
if (!containClass(sibling, DRAGGABLE_CLASS)) {
|
42
42
|
continue;
|
43
43
|
}
|
44
|
-
const siblingTransition = canChangeDraggable(
|
44
|
+
const siblingTransition = canChangeDraggable(direction, draggedElement, sibling, translation);
|
45
45
|
if (!isOutside && siblingTransition) {
|
46
46
|
translation = siblingTransition;
|
47
47
|
}
|
@@ -49,9 +49,9 @@ export default function useDragAndDropEvents(currentConfig, index, parent, dropp
|
|
49
49
|
continue;
|
50
50
|
}
|
51
51
|
const siblingRealIndex = siblings.length - index;
|
52
|
-
updateActualIndexBaseOnTranslation(translation, siblingRealIndex,
|
52
|
+
updateActualIndexBaseOnTranslation(translation, siblingRealIndex, direction, siblings);
|
53
53
|
if (event === START_DRAG_EVENT) {
|
54
|
-
|
54
|
+
moveTranslate(sibling, translation);
|
55
55
|
}
|
56
56
|
else if (event === DRAG_EVENT) {
|
57
57
|
dragEventOverElement(sibling, translation);
|
@@ -59,24 +59,23 @@ export default function useDragAndDropEvents(currentConfig, index, parent, dropp
|
|
59
59
|
}
|
60
60
|
};
|
61
61
|
const canChangeDraggable = (direction, sourceElement, targetElement, translation) => {
|
62
|
-
const { before, distance, axis, getRect } = getPropByDirection(direction);
|
63
62
|
const currentBoundingClientRect = getRect(sourceElement);
|
64
63
|
const targetBoundingClientRect = getRect(targetElement);
|
65
|
-
const currentPosition = currentBoundingClientRect
|
66
|
-
const targetPosition = targetBoundingClientRect
|
67
|
-
const targetSize = targetBoundingClientRect
|
64
|
+
const currentPosition = getBefore(direction, currentBoundingClientRect);
|
65
|
+
const targetPosition = getBefore(direction, targetBoundingClientRect);
|
66
|
+
const [targetSize] = getDistanceValue(direction, targetBoundingClientRect);
|
68
67
|
const targetMiddle = targetPosition + targetSize / 2;
|
69
|
-
const targetTransform = getTransform(targetElement)
|
68
|
+
const targetTransform = getAxisValue(direction, getTransform(targetElement));
|
70
69
|
const targetMiddleWithoutTransform = targetMiddle - targetTransform;
|
71
70
|
if (currentPosition > targetMiddleWithoutTransform) {
|
72
|
-
return
|
71
|
+
return NONE_TRANSLATE;
|
73
72
|
}
|
74
73
|
return translation;
|
75
74
|
};
|
76
75
|
const updateActualIndexBaseOnTranslation = (translation, siblingIndex, direction, siblings) => {
|
77
76
|
const itemsCount = siblings.filter((sibling) => containClass(sibling, DRAGGABLE_CLASS)).length;
|
78
|
-
const
|
79
|
-
if (
|
77
|
+
const [distance] = getDistanceValue(direction, translation);
|
78
|
+
if (distance == 0) {
|
80
79
|
actualIndex = Math.max(actualIndex, siblingIndex);
|
81
80
|
}
|
82
81
|
else {
|
@@ -84,13 +83,8 @@ export default function useDragAndDropEvents(currentConfig, index, parent, dropp
|
|
84
83
|
}
|
85
84
|
actualIndex = Math.min(actualIndex, itemsCount);
|
86
85
|
};
|
87
|
-
const startDragEventOverElement = (element, translation) => {
|
88
|
-
const { width, height } = translation;
|
89
|
-
moveTranslate(element, height, width);
|
90
|
-
};
|
91
86
|
// #region Drop events
|
92
|
-
const emitDroppingEventToSiblings = (draggedElement, event, translation, initialWindowScroll,
|
93
|
-
const { droppable, scroll, config } = droppableConfig;
|
87
|
+
const emitDroppingEventToSiblings = (draggedElement, event, translation, initialWindowScroll, droppable, scroll, config, positionOnSourceDroppable) => {
|
94
88
|
const [siblings, positionOnDroppable] = getSiblings(draggedElement, droppable);
|
95
89
|
const allSiblings = siblings.toReversed();
|
96
90
|
const realPositionOnDroppable = positionOnDroppable === -1 ? allSiblings.length : positionOnDroppable;
|
@@ -105,7 +99,7 @@ export default function useDragAndDropEvents(currentConfig, index, parent, dropp
|
|
105
99
|
for (const [index, sibling] of siblings.toReversed().entries()) {
|
106
100
|
let newTranslation = translation;
|
107
101
|
if (targetIndex - 1 >= index) {
|
108
|
-
newTranslation =
|
102
|
+
newTranslation = NONE_TRANSLATE;
|
109
103
|
}
|
110
104
|
if (event === START_DROP_EVENT && !containClass(sibling, TEMP_CHILD_CLASS)) {
|
111
105
|
startDropEventOverElement(sibling, newTranslation, draggedElement, draggableTranslation);
|
@@ -133,8 +127,8 @@ export default function useDragAndDropEvents(currentConfig, index, parent, dropp
|
|
133
127
|
return [previousElement, nextElement, targetIndex];
|
134
128
|
};
|
135
129
|
const startDropEventOverElement = (targetElement, translation, element, sourceElementTranlation) => {
|
136
|
-
moveTranslate(targetElement, translation
|
137
|
-
moveTranslate(element, sourceElementTranlation
|
130
|
+
moveTranslate(targetElement, translation);
|
131
|
+
moveTranslate(element, sourceElementTranlation);
|
138
132
|
};
|
139
133
|
const dropEventOverElement = (targetIndex, element, config, droppable, positionOnSourceDroppable) => {
|
140
134
|
const { onInsertEvent, onDragEnd } = config;
|
@@ -177,7 +171,7 @@ export default function useDragAndDropEvents(currentConfig, index, parent, dropp
|
|
177
171
|
}, animationDuration);
|
178
172
|
};
|
179
173
|
const removeTempChildOnDroppables = (parent, droppable) => {
|
180
|
-
if (
|
174
|
+
if (isSameNode(parent, droppable)) {
|
181
175
|
removeTempChild(parent, animationDuration);
|
182
176
|
}
|
183
177
|
else {
|
@@ -186,16 +180,16 @@ export default function useDragAndDropEvents(currentConfig, index, parent, dropp
|
|
186
180
|
}
|
187
181
|
};
|
188
182
|
const reduceTempchildSize = (droppable) => {
|
189
|
-
if (
|
183
|
+
if (isSameNode(parent, droppable)) {
|
190
184
|
return;
|
191
185
|
}
|
192
186
|
var [lastChildren] = parent.querySelectorAll(`.${TEMP_CHILD_CLASS}`);
|
193
187
|
if (!lastChildren) {
|
194
188
|
return;
|
195
189
|
}
|
196
|
-
const { distance } = getPropByDirection(direction);
|
197
190
|
if (IsHTMLElement(lastChildren)) {
|
198
|
-
lastChildren.style
|
191
|
+
lastChildren.style.height = '0px';
|
192
|
+
lastChildren.style.width = '0px';
|
199
193
|
}
|
200
194
|
};
|
201
195
|
const removeTranslateFromSiblings = (element, parent) => {
|
@@ -204,11 +198,5 @@ export default function useDragAndDropEvents(currentConfig, index, parent, dropp
|
|
204
198
|
removeTranslateWhitoutTransition(sibling);
|
205
199
|
}
|
206
200
|
};
|
207
|
-
const removeTranslateWhitoutTransition = (element) => {
|
208
|
-
if (IsHTMLElement(element)) {
|
209
|
-
element.style.transition = '';
|
210
|
-
element.style.transform = '';
|
211
|
-
}
|
212
|
-
};
|
213
201
|
return [emitDraggingEvent, emitDroppingEvent, toggleDraggingClass];
|
214
202
|
}
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import { HORIZONTAL, VERTICAL } from '../..';
|
2
|
-
import { getPropByDirection, getValueFromProperty } from '../../utils/GetStyles';
|
3
|
-
import {
|
2
|
+
import { getAfterMargin, getAxisValue, getBeforeMargin, getBorderBeforeWidthValue, getDistanceValue, getPropByDirection, getRect, getScrollElementValue, getScrollValue, getValueFromProperty } from '../../utils/GetStyles';
|
3
|
+
import { getBeforeStyles, getGapInfo } from '../../utils/ParseStyles';
|
4
4
|
const getContentPosition = (direction, droppable) => {
|
5
|
-
const {
|
6
|
-
const borderBeforeWidthDroppable =
|
5
|
+
const { paddingBefore } = getPropByDirection(direction);
|
6
|
+
const borderBeforeWidthDroppable = getBorderBeforeWidthValue(direction, droppable);
|
7
7
|
const paddingBeforeDroppable = getValueFromProperty(droppable, paddingBefore);
|
8
|
-
const axisValue = getRect(droppable)
|
8
|
+
const axisValue = getAxisValue(direction, getRect(droppable));
|
9
9
|
return borderBeforeWidthDroppable + paddingBeforeDroppable + axisValue;
|
10
10
|
};
|
11
11
|
const getGroupTranslate = (droppable, draggable) => {
|
@@ -27,14 +27,14 @@ export default function getTranslateBeforeDropping(direction, siblings, sourceIn
|
|
27
27
|
height += y;
|
28
28
|
width += x;
|
29
29
|
}
|
30
|
-
const
|
31
|
-
const [
|
32
|
-
const [
|
33
|
-
const [beforeSpace, space, afterSpace] = spaceWithMargins(beforeMarginProp, afterMarginProp, spaceProp, siblingsBetween, gap, hasGaps);
|
30
|
+
const [gap, hasGaps] = getGapInfo(droppable, direction);
|
31
|
+
const [afterMarginOutside, beforeMarginOutside, spaceBeforeDraggedElement] = getBeforeAfterMarginBaseOnDraggedDirection(sourceElement, targetElement?.previousElementSibling, isDraggedFoward, hasGaps, isGroupDropping, direction);
|
32
|
+
const [beforeSpace, space, afterSpace] = spaceWithMargins(siblingsBetween, gap, hasGaps, direction);
|
34
33
|
const spaceBetween = getSpaceBetween(space, beforeSpace, afterSpace, beforeMarginOutside, afterMarginOutside, gap);
|
34
|
+
const [scrollElementValue] = getScrollElementValue(direction, droppable);
|
35
35
|
const scrollChange = isGroupDropping
|
36
|
-
?
|
37
|
-
: getScrollChange(
|
36
|
+
? scrollElementValue
|
37
|
+
: getScrollChange(droppable, previousScroll, direction);
|
38
38
|
const spaceCalc = isDraggedFoward
|
39
39
|
? spaceBetween - spaceBeforeDraggedElement
|
40
40
|
: spaceBeforeDraggedElement - spaceBetween;
|
@@ -47,9 +47,9 @@ export default function getTranslateBeforeDropping(direction, siblings, sourceIn
|
|
47
47
|
}
|
48
48
|
return addScrollToTranslate({ height, width }, direction, scroll, initialWindowScroll, isGroupDropping);
|
49
49
|
}
|
50
|
-
const getScrollChange = (
|
51
|
-
const scrollParent = parentElement
|
52
|
-
const previousScrollValue = previousScroll
|
50
|
+
const getScrollChange = (parentElement, previousScroll, direction) => {
|
51
|
+
const [scrollParent] = getScrollElementValue(direction, parentElement);
|
52
|
+
const [previousScrollValue] = getScrollElementValue(direction, previousScroll);
|
53
53
|
return scrollParent - previousScrollValue;
|
54
54
|
};
|
55
55
|
const getSpaceBetween = (innerSpace, beforeMarginSpace, afterMarginSpace, beforeMarginOutside, afterMarginOutside, gap) => {
|
@@ -70,16 +70,16 @@ const getElementsRange = (siblings, sourceIndex, targetIndex, draggable) => {
|
|
70
70
|
}
|
71
71
|
return [sourceElement, targetElement, siblingsBetween, isDraggedFoward];
|
72
72
|
};
|
73
|
-
const spaceWithMargins = (
|
73
|
+
const spaceWithMargins = (siblings, gap, hasGaps, direction) => {
|
74
74
|
if (siblings.length == 0) {
|
75
75
|
return [0, 0, 0];
|
76
76
|
}
|
77
|
-
const beforeSpace =
|
77
|
+
const beforeSpace = getAfterMargin(direction, siblings[0]);
|
78
78
|
let afterSpace = 0;
|
79
79
|
let space = -beforeSpace;
|
80
80
|
for (const [index, sibling] of siblings.entries()) {
|
81
|
-
const siblingSpace = sibling
|
82
|
-
const siblingBeforeMargin =
|
81
|
+
const [siblingSpace] = getDistanceValue(direction, getRect(sibling));
|
82
|
+
const siblingBeforeMargin = getBeforeMargin(direction, sibling);
|
83
83
|
if (hasGaps) {
|
84
84
|
afterSpace += siblingBeforeMargin;
|
85
85
|
}
|
@@ -90,32 +90,32 @@ const spaceWithMargins = (beforeMargin, afterMargin, distance, siblings, gap, ha
|
|
90
90
|
afterSpace = Math.max(afterSpace, siblingBeforeMargin);
|
91
91
|
}
|
92
92
|
space += afterSpace + siblingSpace;
|
93
|
-
afterSpace =
|
93
|
+
afterSpace = getAfterMargin(direction, sibling);
|
94
94
|
}
|
95
95
|
return [beforeSpace, space, afterSpace];
|
96
96
|
};
|
97
97
|
const addScrollToTranslate = (translate, direction, initialScroll, initialWindowScroll, isGroupDropping) => {
|
98
|
-
const
|
99
|
-
const
|
100
|
-
const initialScrollProp = initialScroll[scroll];
|
98
|
+
const actualWindowScroll = getScrollValue(direction, window);
|
99
|
+
const initialScrollProp = getScrollValue(direction, initialScroll);
|
101
100
|
const scrollChange = isGroupDropping
|
102
101
|
? 0
|
103
|
-
: initialScrollProp - 2 * actualWindowScroll + initialWindowScroll
|
102
|
+
: initialScrollProp - 2 * actualWindowScroll + getScrollValue(direction, initialWindowScroll);
|
103
|
+
const [, distance] = getDistanceValue(direction, translate);
|
104
104
|
translate[distance] += scrollChange;
|
105
105
|
return translate;
|
106
106
|
};
|
107
|
-
const getBeforeAfterMarginBaseOnDraggedDirection = (
|
107
|
+
const getBeforeAfterMarginBaseOnDraggedDirection = (draggedElement, previousElement, isDraggedFoward, hasGaps, isGroupDropping, direction) => {
|
108
108
|
const previousElementByDirection = isDraggedFoward
|
109
109
|
? draggedElement.previousElementSibling
|
110
110
|
: previousElement;
|
111
|
-
return getBeforeAfterMargin(
|
111
|
+
return getBeforeAfterMargin(previousElementByDirection, draggedElement, hasGaps, isGroupDropping, direction);
|
112
112
|
};
|
113
|
-
const getBeforeAfterMargin = (
|
113
|
+
const getBeforeAfterMargin = (previousElement, nextElement, hasGaps, isGroupDropping, direction) => {
|
114
114
|
if (hasGaps) {
|
115
115
|
return [0, 0, 0];
|
116
116
|
}
|
117
|
-
const
|
118
|
-
const
|
119
|
-
let spaceBeforeDraggedElement = Math.max(
|
120
|
-
return [
|
117
|
+
const afterMarginValue = getAfterMargin(direction, isGroupDropping ? null : previousElement);
|
118
|
+
const beforeMarginValue = getBeforeMargin(direction, nextElement);
|
119
|
+
let spaceBeforeDraggedElement = Math.max(afterMarginValue, beforeMarginValue);
|
120
|
+
return [afterMarginValue, beforeMarginValue, spaceBeforeDraggedElement];
|
121
121
|
};
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { HORIZONTAL } from '../..';
|
2
2
|
import { DRAG_EVENT } from '../../utils';
|
3
|
-
import { draggableIsOutside,
|
4
|
-
import {
|
3
|
+
import { draggableIsOutside, getAfterMargin, getBeforeMarginValue, getDistanceValue, getRect } from '../../utils/GetStyles';
|
4
|
+
import { getGapInfo } from '../../utils/ParseStyles';
|
5
5
|
export default function getTranslationByDraggingAndEvent(current, event, direction, droppable, previousElement = current.previousElementSibling, nextElement = current.nextElementSibling) {
|
6
6
|
let { height, width } = getTranslationByDragging(direction, current, previousElement, nextElement);
|
7
7
|
const intersection = draggableIsOutside(current, droppable);
|
@@ -12,24 +12,23 @@ export default function getTranslationByDraggingAndEvent(current, event, directi
|
|
12
12
|
return { height, width };
|
13
13
|
}
|
14
14
|
const getTranslationByDragging = (direction, current, previous, nextElement) => {
|
15
|
-
const
|
16
|
-
const
|
17
|
-
const
|
18
|
-
const
|
19
|
-
const [
|
20
|
-
const space = getRect(current)[distance];
|
15
|
+
const after = getAfterMargin(direction, current);
|
16
|
+
const before = getBeforeMarginValue(direction, current);
|
17
|
+
const nextBefore = getBeforeMarginValue(direction, nextElement);
|
18
|
+
const [gap, hasGaps] = getGapInfo(current.parentElement, direction);
|
19
|
+
const [space] = getDistanceValue(direction, getRect(current));
|
21
20
|
if (hasGaps) {
|
22
21
|
return getTranslation(space, before, after, gap, 0, direction);
|
23
22
|
}
|
24
|
-
const [afterSpace, beforeScace, rest] = getTranslationByDraggingWithoutGaps(previous, nextBefore, after, before,
|
23
|
+
const [afterSpace, beforeScace, rest] = getTranslationByDraggingWithoutGaps(previous, nextBefore, after, before, direction);
|
25
24
|
return getTranslation(space, beforeScace, afterSpace, 0, rest, direction);
|
26
25
|
};
|
27
|
-
const getTranslationByDraggingWithoutGaps = (previousElement, nextBeforeMargin, currentAfterMargin, currentBeforeMargin,
|
26
|
+
const getTranslationByDraggingWithoutGaps = (previousElement, nextBeforeMargin, currentAfterMargin, currentBeforeMargin, direction) => {
|
28
27
|
const afterSpace = Math.max(nextBeforeMargin, currentAfterMargin);
|
29
28
|
let beforeScace = currentBeforeMargin;
|
30
29
|
let rest = nextBeforeMargin;
|
31
30
|
if (previousElement) {
|
32
|
-
const previousAfterMargin =
|
31
|
+
const previousAfterMargin = getAfterMargin(direction, previousElement);
|
33
32
|
beforeScace = Math.max(previousAfterMargin, currentBeforeMargin);
|
34
33
|
rest = Math.max(rest, previousAfterMargin);
|
35
34
|
}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { CoreConfig } from '../index';
|
2
2
|
import HandlerPublisher from '../HandlerPublisher';
|
3
|
-
|
3
|
+
import { DroppableConfig } from '../config/configHandler';
|
4
|
+
export default function useInsertEvents<T>(currentConfig: CoreConfig<T>, parent: HTMLElement, handlerPublisher: HandlerPublisher, endDraggingAction: () => void): readonly [(targetIndex: number, draggedElement: HTMLElement, droppable: HTMLElement, value: T, droppableConfigurator: DroppableConfig<T> | undefined) => void];
|
4
5
|
export declare const insertToListEmpty: <T>(config: CoreConfig<T>, droppable: HTMLElement | undefined | null, targetIndex: number, value: T) => void;
|
@@ -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
|
-
import { CoreConfig } from '..';
|
1
|
+
import { CoreConfig, DraggingState } 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 [(
|
4
|
+
export default function useRemoveEvents<T>(currentConfig: CoreConfig<T>, parent: HTMLElement, handlerPublisher: HandlerPublisher, endDraggingAction: () => void): readonly [(index: number, targetIndex: number, draggableElement: HTMLElement, draggingState: DraggingState, config: DroppableConfig<T>) => void];
|