fluid-dnd 2.0.0 → 2.0.2
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 +1 -1
- package/dist/{HandlerPublisher-BbQeSll4.js → HandlerPublisher-BYI2bw4n.js} +1 -1
- package/dist/{HandlerPublisher-F9_9P96L.cjs → HandlerPublisher-C-jTncuG.cjs} +1 -1
- package/dist/core/HandlerPublisher.js +20 -0
- package/dist/core/configHandler.d.ts +2 -3
- package/dist/core/configHandler.js +33 -0
- package/dist/core/dragAndDrop.d.ts +3 -3
- package/dist/core/dragAndDrop.js +62 -0
- package/dist/core/index.js +2 -0
- package/dist/core/useDraggable.d.ts +2 -3
- package/dist/core/useDraggable.js +328 -0
- package/dist/core/useDroppable.d.ts +2 -3
- package/dist/core/useDroppable.js +55 -0
- package/dist/core/utils/GetStyles.d.ts +2 -3
- package/dist/core/utils/GetStyles.js +138 -0
- package/dist/core/utils/ParseStyles.d.ts +2 -3
- package/dist/core/utils/ParseStyles.js +40 -0
- package/dist/core/utils/SetStyles.d.ts +1 -2
- package/dist/core/utils/SetStyles.js +192 -0
- package/dist/core/utils/SetTransform.d.ts +2 -3
- package/dist/core/utils/SetTransform.js +148 -0
- package/dist/core/utils/classes.js +9 -0
- package/dist/core/utils/config.d.ts +3 -3
- package/dist/core/utils/config.js +55 -0
- package/dist/core/utils/dom/classList.js +35 -0
- package/dist/core/utils/droppableConfigurator.d.ts +3 -4
- package/dist/core/utils/droppableConfigurator.js +106 -0
- package/dist/core/utils/events/emitEvents.d.ts +5 -6
- package/dist/core/utils/events/emitEvents.js +333 -0
- package/dist/core/utils/index.js +9 -0
- package/dist/core/utils/observer.js +11 -0
- package/dist/core/utils/scroll.d.ts +2 -3
- package/dist/core/utils/scroll.js +17 -0
- package/dist/core/utils/tempChildren.d.ts +1 -2
- package/dist/core/utils/tempChildren.js +146 -0
- package/dist/core/utils/touchDevice.js +3 -0
- package/dist/core/utils/translate/GetTranslateBeforeDropping.d.ts +2 -3
- package/dist/core/utils/translate/GetTranslateBeforeDropping.js +129 -0
- package/dist/core/utils/translate/GetTranslationByDraggingAndEvent.d.ts +2 -3
- package/dist/core/utils/translate/GetTranslationByDraggingAndEvent.js +48 -0
- package/dist/{index-8zYdjZIf.js → index-BQUYvZRn.js} +214 -214
- package/dist/index-DNmnvxhi.cjs +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/dist/index.mjs +4 -0
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.d.ts +1 -2
- package/dist/react/index.js +2 -0
- package/dist/react/index.mjs +2 -2
- package/dist/react/useDragAndDrop.d.ts +2 -3
- package/dist/react/useDragAndDrop.js +28 -0
- package/dist/react/utils/ReactLilstConfig.d.ts +3 -4
- package/dist/react/utils/ReactLilstConfig.js +64 -0
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.d.ts +1 -2
- package/dist/svelte/index.js +2 -0
- package/dist/svelte/index.mjs +2 -2
- package/dist/svelte/useDragAndDrop.d.ts +1 -2
- package/dist/svelte/useDragAndDrop.js +25 -0
- package/dist/svelte/utils/SvelteListCondig.d.ts +2 -2
- package/dist/svelte/utils/SvelteListCondig.js +36 -0
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.d.ts +1 -2
- package/dist/vue/index.js +2 -0
- package/dist/vue/index.mjs +2 -2
- package/dist/vue/useDragAndDrop.d.ts +2 -3
- package/dist/vue/useDragAndDrop.js +23 -0
- package/dist/vue/utils/DropMethods.d.ts +1 -2
- package/dist/vue/utils/DropMethods.js +19 -0
- package/dist/vue/utils/VueListCondig.d.ts +3 -3
- package/dist/vue/utils/VueListCondig.js +28 -0
- package/package.json +5 -8
- package/dist/index/index.cjs +0 -1
- package/dist/index/index.mjs +0 -4
- package/dist/index-C37ab-rG.cjs +0 -1
@@ -0,0 +1,129 @@
|
|
1
|
+
import { HORIZONTAL, VERTICAL } from "../..";
|
2
|
+
import { getPropByDirection, getValueFromProperty, } from "../GetStyles";
|
3
|
+
import { gapAndDisplayInformation, getBeforeStyles } from "../ParseStyles";
|
4
|
+
const getContentPosition = (direction, droppable) => {
|
5
|
+
const { borderBeforeWidth, paddingBefore, axis, getRect } = getPropByDirection(direction);
|
6
|
+
const borderBeforeWidthDroppable = getValueFromProperty(droppable, borderBeforeWidth);
|
7
|
+
const paddingBeforeDroppable = getValueFromProperty(droppable, paddingBefore);
|
8
|
+
const axisValue = getRect(droppable)[axis];
|
9
|
+
return borderBeforeWidthDroppable + paddingBeforeDroppable + axisValue;
|
10
|
+
};
|
11
|
+
const getGroupTranslate = (droppable, draggable) => {
|
12
|
+
const [top, left] = getBeforeStyles(draggable);
|
13
|
+
const verticalContentPosition = getContentPosition(VERTICAL, droppable);
|
14
|
+
const horizontalContentPosition = getContentPosition(HORIZONTAL, droppable);
|
15
|
+
return [
|
16
|
+
horizontalContentPosition - left,
|
17
|
+
verticalContentPosition - top
|
18
|
+
];
|
19
|
+
};
|
20
|
+
export default function getTranslateBeforeDropping(direction, siblings, sourceIndex, targetIndex, scroll, previousScroll, initialWindowScroll, droppable, draggable) {
|
21
|
+
let height = 0;
|
22
|
+
let width = 0;
|
23
|
+
const isGroupDropping = Boolean(sourceIndex < 0 && draggable);
|
24
|
+
if (sourceIndex === targetIndex && !isGroupDropping) {
|
25
|
+
return addScrollToTranslate({ height, width }, direction, scroll, initialWindowScroll, isGroupDropping);
|
26
|
+
}
|
27
|
+
const [sourceElement, targetElement, siblingsBetween, isDraggedFoward] = getElementsRange(siblings, sourceIndex, targetIndex, draggable);
|
28
|
+
if (isGroupDropping) {
|
29
|
+
const [x, y] = getGroupTranslate(droppable, draggable);
|
30
|
+
height += y;
|
31
|
+
width += x;
|
32
|
+
}
|
33
|
+
const { scrollElement, beforeMargin: beforeMarginProp, afterMargin: afterMarginProp, distance: spaceProp, gap: gapStyle, } = getPropByDirection(direction);
|
34
|
+
const [gap, hasGaps] = gapAndDisplayInformation(droppable, gapStyle);
|
35
|
+
const [afterMarginOutside, beforeMarginOutside, spaceBeforeDraggedElement,] = getBeforeAfterMarginBaseOnDraggedDirection(beforeMarginProp, afterMarginProp, sourceElement, targetElement?.previousElementSibling, isDraggedFoward, hasGaps, isGroupDropping);
|
36
|
+
const [beforeSpace, space, afterSpace] = spaceWithMargins(beforeMarginProp, afterMarginProp, spaceProp, siblingsBetween, gap, hasGaps);
|
37
|
+
const spaceBetween = getSpaceBetween(space, beforeSpace, afterSpace, beforeMarginOutside, afterMarginOutside, gap);
|
38
|
+
const scrollChange = isGroupDropping
|
39
|
+
? droppable[scrollElement]
|
40
|
+
: getScrollChange(scrollElement, droppable, previousScroll);
|
41
|
+
const spaceCalc = isDraggedFoward
|
42
|
+
? spaceBetween - spaceBeforeDraggedElement
|
43
|
+
: spaceBeforeDraggedElement - spaceBetween;
|
44
|
+
const translate = spaceCalc - scrollChange;
|
45
|
+
if (direction === VERTICAL) {
|
46
|
+
height += translate;
|
47
|
+
}
|
48
|
+
else if (direction === HORIZONTAL) {
|
49
|
+
width += translate;
|
50
|
+
}
|
51
|
+
return addScrollToTranslate({ height, width }, direction, scroll, initialWindowScroll, isGroupDropping);
|
52
|
+
}
|
53
|
+
const getScrollChange = (scrollElement, parentElement, previousScroll) => {
|
54
|
+
const scrollParent = parentElement[scrollElement];
|
55
|
+
const previousScrollValue = previousScroll[scrollElement];
|
56
|
+
return scrollParent - previousScrollValue;
|
57
|
+
};
|
58
|
+
const getSpaceBetween = (innerSpace, beforeMarginSpace, afterMarginSpace, beforeMarginOutside, afterMarginOutside, gap) => {
|
59
|
+
const beforeMarginCalc = Math.max(beforeMarginSpace, afterMarginOutside);
|
60
|
+
const afterMarginCalc = Math.max(afterMarginSpace, beforeMarginOutside);
|
61
|
+
return afterMarginCalc + innerSpace + beforeMarginCalc + gap;
|
62
|
+
};
|
63
|
+
const getElementsRange = (siblings, sourceIndex, targetIndex, draggable) => {
|
64
|
+
const isDraggedFoward = sourceIndex < targetIndex;
|
65
|
+
const [firstIndex, secondIndex] = [sourceIndex, targetIndex].toSorted((a, b) => a - b);
|
66
|
+
const sourceElement = siblings[sourceIndex] ?? draggable;
|
67
|
+
const targetElement = siblings[targetIndex];
|
68
|
+
let siblingsBetween = isDraggedFoward
|
69
|
+
? siblings.slice(firstIndex + 1, secondIndex + 1)
|
70
|
+
: siblings.slice(firstIndex, secondIndex);
|
71
|
+
if (firstIndex < 0 && draggable) {
|
72
|
+
siblingsBetween = siblings.slice(firstIndex + 1, secondIndex);
|
73
|
+
}
|
74
|
+
return [
|
75
|
+
sourceElement,
|
76
|
+
targetElement,
|
77
|
+
siblingsBetween,
|
78
|
+
isDraggedFoward,
|
79
|
+
];
|
80
|
+
};
|
81
|
+
const spaceWithMargins = (beforeMargin, afterMargin, distance, siblings, gap, hasGaps) => {
|
82
|
+
if (siblings.length == 0) {
|
83
|
+
return [0, 0, 0];
|
84
|
+
}
|
85
|
+
const beforeSpace = getValueFromProperty(siblings[0], beforeMargin);
|
86
|
+
let afterSpace = 0;
|
87
|
+
let space = -beforeSpace;
|
88
|
+
for (const [index, sibling] of siblings.entries()) {
|
89
|
+
const siblingSpace = sibling.getBoundingClientRect()[distance];
|
90
|
+
const siblingBeforeMargin = getValueFromProperty(sibling, beforeMargin);
|
91
|
+
if (hasGaps) {
|
92
|
+
afterSpace += siblingBeforeMargin;
|
93
|
+
}
|
94
|
+
if (hasGaps && index > 0) {
|
95
|
+
afterSpace += gap;
|
96
|
+
}
|
97
|
+
else {
|
98
|
+
afterSpace = Math.max(afterSpace, siblingBeforeMargin);
|
99
|
+
}
|
100
|
+
space += afterSpace + siblingSpace;
|
101
|
+
afterSpace = getValueFromProperty(sibling, afterMargin);
|
102
|
+
}
|
103
|
+
return [beforeSpace, space, afterSpace];
|
104
|
+
};
|
105
|
+
const addScrollToTranslate = (translate, direction, initialScroll, initialWindowScroll, isGroupDropping) => {
|
106
|
+
const { scroll, distance } = getPropByDirection(direction);
|
107
|
+
const actualWindowScroll = window[scroll];
|
108
|
+
const initialScrollProp = initialScroll[scroll];
|
109
|
+
const scrollChange = isGroupDropping
|
110
|
+
? 0
|
111
|
+
: initialScrollProp - 2 * actualWindowScroll + initialWindowScroll[scroll];
|
112
|
+
translate[distance] += scrollChange;
|
113
|
+
return translate;
|
114
|
+
};
|
115
|
+
const getBeforeAfterMarginBaseOnDraggedDirection = (beforeMarginProp, afterMarginProp, draggedElement, previousElement, isDraggedFoward, hasGaps, isGroupDropping) => {
|
116
|
+
const previousElementByDirection = isDraggedFoward
|
117
|
+
? draggedElement.previousElementSibling
|
118
|
+
: previousElement;
|
119
|
+
return getBeforeAfterMargin(beforeMarginProp, afterMarginProp, previousElementByDirection, draggedElement, hasGaps, isGroupDropping);
|
120
|
+
};
|
121
|
+
const getBeforeAfterMargin = (beforeMarginProp, afterMarginProp, previousElement, nextElement, hasGaps, isGroupDropping) => {
|
122
|
+
if (hasGaps) {
|
123
|
+
return [0, 0, 0];
|
124
|
+
}
|
125
|
+
const afterMargin = getValueFromProperty(isGroupDropping ? null : previousElement, afterMarginProp);
|
126
|
+
const beforeMargin = getValueFromProperty(nextElement, beforeMarginProp);
|
127
|
+
let spaceBeforeDraggedElement = Math.max(afterMargin, beforeMargin);
|
128
|
+
return [afterMargin, beforeMargin, spaceBeforeDraggedElement];
|
129
|
+
};
|
@@ -1,6 +1,5 @@
|
|
1
|
-
import { Direction } from
|
2
|
-
import { DragAndDropEvent } from
|
3
|
-
|
1
|
+
import { Direction } from "../..";
|
2
|
+
import { DragAndDropEvent } from "..";
|
4
3
|
export default function getTranslationByDraggingAndEvent(current: HTMLElement, event: DragAndDropEvent, direction: Direction, droppable: HTMLElement, previousElement?: Element | null, nextElement?: Element | null): {
|
5
4
|
height: number;
|
6
5
|
width: number;
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import { HORIZONTAL } from "../..";
|
2
|
+
import { DRAG_EVENT } from "..";
|
3
|
+
import { draggableIsOutside, getPropByDirection, getValueFromProperty, } from "../GetStyles";
|
4
|
+
import { gapAndDisplayInformation } from "../ParseStyles";
|
5
|
+
export default function getTranslationByDraggingAndEvent(current, event, direction, droppable, previousElement = current.previousElementSibling, nextElement = current.nextElementSibling) {
|
6
|
+
let { height, width } = getTranslationByDragging(direction, current, previousElement, nextElement);
|
7
|
+
const intersection = draggableIsOutside(current, droppable);
|
8
|
+
if (intersection && event == DRAG_EVENT) {
|
9
|
+
height = 0;
|
10
|
+
width = 0;
|
11
|
+
}
|
12
|
+
return { height, width };
|
13
|
+
}
|
14
|
+
const getTranslationByDragging = (direction, current, previous, nextElement) => {
|
15
|
+
const { afterMargin, beforeMargin, distance, gap: gapStyle, getRect } = getPropByDirection(direction);
|
16
|
+
const after = getValueFromProperty(current, afterMargin);
|
17
|
+
const before = getValueFromProperty(current, beforeMargin);
|
18
|
+
const nextBefore = getValueFromProperty(nextElement, beforeMargin);
|
19
|
+
const [gap, hasGaps] = gapAndDisplayInformation(current.parentElement, gapStyle);
|
20
|
+
const space = getRect(current)[distance];
|
21
|
+
if (hasGaps) {
|
22
|
+
return getTranslation(space, before, after, gap, 0, direction);
|
23
|
+
}
|
24
|
+
const [afterSpace, beforeScace, rest] = getTranslationByDraggingWithoutGaps(previous, nextBefore, after, before, afterMargin);
|
25
|
+
return getTranslation(space, beforeScace, afterSpace, 0, rest, direction);
|
26
|
+
};
|
27
|
+
const getTranslationByDraggingWithoutGaps = (previousElement, nextBeforeMargin, currentAfterMargin, currentBeforeMargin, afterMargin) => {
|
28
|
+
const afterSpace = Math.max(nextBeforeMargin, currentAfterMargin);
|
29
|
+
let beforeScace = currentBeforeMargin;
|
30
|
+
let rest = nextBeforeMargin;
|
31
|
+
if (previousElement) {
|
32
|
+
const previousAfterMargin = getValueFromProperty(previousElement, afterMargin);
|
33
|
+
beforeScace = Math.max(previousAfterMargin, currentBeforeMargin);
|
34
|
+
rest = Math.max(rest, previousAfterMargin);
|
35
|
+
}
|
36
|
+
return [afterSpace, beforeScace, rest];
|
37
|
+
};
|
38
|
+
const getTranslation = (size, before, after, gap, rest, direction) => {
|
39
|
+
return getDistancesByDirection(direction, size + before + after + gap - rest);
|
40
|
+
};
|
41
|
+
const getDistancesByDirection = (direction, value) => {
|
42
|
+
if (direction == HORIZONTAL) {
|
43
|
+
return { width: value, height: 0 };
|
44
|
+
}
|
45
|
+
else {
|
46
|
+
return { width: 0, height: value };
|
47
|
+
}
|
48
|
+
};
|