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,138 @@
|
|
1
|
+
import { HORIZONTAL, VERTICAL } from "..";
|
2
|
+
import { DRAGGABLE_CLASS } from "./classes";
|
3
|
+
import { containClass } from "./dom/classList";
|
4
|
+
export const getWindowScroll = () => {
|
5
|
+
const { scrollX, scrollY } = window;
|
6
|
+
return { scrollX, scrollY };
|
7
|
+
};
|
8
|
+
export const parseFloatEmpty = (value) => {
|
9
|
+
if (!value || value.trim().length == 0 || value == "normal") {
|
10
|
+
return 0;
|
11
|
+
}
|
12
|
+
return parseFloat(value);
|
13
|
+
};
|
14
|
+
export const parseIntEmpty = (value) => {
|
15
|
+
if (!value) {
|
16
|
+
return -1;
|
17
|
+
}
|
18
|
+
return parseInt(value);
|
19
|
+
};
|
20
|
+
export const getTransform = (element) => {
|
21
|
+
const style = getComputedStyle(element);
|
22
|
+
const matrix = new DOMMatrixReadOnly(style.transform);
|
23
|
+
return {
|
24
|
+
x: matrix.m41,
|
25
|
+
y: matrix.m42,
|
26
|
+
};
|
27
|
+
};
|
28
|
+
const intersection = (firstInterval, secondInterval) => {
|
29
|
+
if (firstInterval.x1 > secondInterval.x1) {
|
30
|
+
return intersection(secondInterval, firstInterval);
|
31
|
+
}
|
32
|
+
if (firstInterval.x2 < secondInterval.x1) {
|
33
|
+
return 0;
|
34
|
+
}
|
35
|
+
if (firstInterval.x2 >= secondInterval.x2) {
|
36
|
+
return firstInterval.x2 - firstInterval.x1;
|
37
|
+
}
|
38
|
+
return firstInterval.x2 - secondInterval.x1;
|
39
|
+
};
|
40
|
+
export const draggableIsOutside = (draggable, droppable) => {
|
41
|
+
return !hasIntersection(draggable, droppable);
|
42
|
+
};
|
43
|
+
export const hasIntersection = (element1, element2) => {
|
44
|
+
const rect1 = getRect(element1);
|
45
|
+
const rect2 = getRect(element2);
|
46
|
+
const intersectionY = intersectionByDirection(rect1, rect2, VERTICAL);
|
47
|
+
const intersectionX = intersectionByDirection(rect1, rect2, HORIZONTAL);
|
48
|
+
return (intersectionY >= Math.min(rect1.height, rect2.height) / 2 &&
|
49
|
+
intersectionX >= Math.min(rect1.width, rect2.width) / 2);
|
50
|
+
};
|
51
|
+
const intersectionByDirection = (rect1, rect2, direction) => {
|
52
|
+
const { before, distance } = getPropByDirection(direction);
|
53
|
+
return intersection({
|
54
|
+
x1: rect1[before],
|
55
|
+
x2: rect1[before] + rect1[distance],
|
56
|
+
}, {
|
57
|
+
x1: rect2[before],
|
58
|
+
x2: rect2[before] + rect2[distance],
|
59
|
+
});
|
60
|
+
};
|
61
|
+
export const getValueFromProperty = (element, property) => {
|
62
|
+
if (element) {
|
63
|
+
return parseFloatEmpty(getComputedStyle(element)[property]);
|
64
|
+
}
|
65
|
+
return 0;
|
66
|
+
};
|
67
|
+
export const getScrollElement = (element) => {
|
68
|
+
const { scrollLeft, scrollTop } = element;
|
69
|
+
return { scrollLeft, scrollTop };
|
70
|
+
};
|
71
|
+
const getRect = (element) => {
|
72
|
+
return element.getBoundingClientRect();
|
73
|
+
};
|
74
|
+
export const getPropByDirection = (direction) => {
|
75
|
+
const ifHorizontal = direction == HORIZONTAL;
|
76
|
+
return {
|
77
|
+
beforeMargin: ifHorizontal ? "marginLeft" : "marginTop",
|
78
|
+
afterMargin: ifHorizontal ? "marginRight" : "marginBottom",
|
79
|
+
borderBeforeWidth: ifHorizontal ? "borderLeftWidth" : "borderTopWidth",
|
80
|
+
before: ifHorizontal ? "left" : "top",
|
81
|
+
after: ifHorizontal ? "right" : "down",
|
82
|
+
gap: ifHorizontal ? "columnGap" : "rowGap",
|
83
|
+
distance: ifHorizontal ? "width" : "height",
|
84
|
+
axis: ifHorizontal ? "x" : "y",
|
85
|
+
offset: ifHorizontal ? "offsetX" : "offsetY",
|
86
|
+
scroll: ifHorizontal ? "scrollX" : "scrollY",
|
87
|
+
scrollElement: ifHorizontal ? "scrollLeft" : "scrollTop",
|
88
|
+
page: ifHorizontal ? "pageX" : "pageY",
|
89
|
+
inner: ifHorizontal ? "innerWidth" : "innerHeight",
|
90
|
+
offsetElement: ifHorizontal ? "offsetLeft" : "offsetTop",
|
91
|
+
scrollDistance: ifHorizontal ? "scrollWidth" : "scrollHeight",
|
92
|
+
clientDistance: ifHorizontal ? "clientWidth" : "clientHeight",
|
93
|
+
paddingBefore: ifHorizontal ? 'paddingLeft' : 'paddingTop',
|
94
|
+
getRect
|
95
|
+
};
|
96
|
+
};
|
97
|
+
export const getSiblings = (current, parent) => {
|
98
|
+
return getSiblingsByParent(current, parent);
|
99
|
+
};
|
100
|
+
export const getGroupDroppables = (currentDroppable, droppableGroup) => {
|
101
|
+
if (!droppableGroup) {
|
102
|
+
return [currentDroppable];
|
103
|
+
}
|
104
|
+
return Array.from(document.querySelectorAll(`.droppable-group-${droppableGroup}`));
|
105
|
+
};
|
106
|
+
export const getParentDraggableChildren = (parent) => {
|
107
|
+
const siblings = [...parent.children]
|
108
|
+
.filter((child) => containClass(child, DRAGGABLE_CLASS));
|
109
|
+
return siblings;
|
110
|
+
};
|
111
|
+
export const getSiblingsByParent = (current, parent) => {
|
112
|
+
const siblings = [...parent.children]
|
113
|
+
.filter((child) => containClass(child, DRAGGABLE_CLASS) &&
|
114
|
+
!child.isEqualNode(current))
|
115
|
+
.toReversed();
|
116
|
+
const positionOnDroppable = [...parent.children].findLastIndex((child) => child.isEqualNode(current));
|
117
|
+
return [
|
118
|
+
siblings,
|
119
|
+
positionOnDroppable,
|
120
|
+
parent,
|
121
|
+
];
|
122
|
+
};
|
123
|
+
const getNearestFixedParent = (element) => {
|
124
|
+
let parent = element.parentElement;
|
125
|
+
while (parent) {
|
126
|
+
const position = window.getComputedStyle(parent).position;
|
127
|
+
if (position === 'fixed') {
|
128
|
+
return parent;
|
129
|
+
}
|
130
|
+
parent = parent.parentElement;
|
131
|
+
}
|
132
|
+
return null; // No fixed parent found
|
133
|
+
};
|
134
|
+
export const getNearestFixedParentPosition = (element, direction) => {
|
135
|
+
const { before, borderBeforeWidth } = getPropByDirection(direction);
|
136
|
+
const fixedParent = getNearestFixedParent(element);
|
137
|
+
return fixedParent ? (getRect(fixedParent)[before] + getValueFromProperty(fixedParent, borderBeforeWidth)) : 0;
|
138
|
+
};
|
@@ -1,6 +1,5 @@
|
|
1
|
-
import { GapStyle } from
|
2
|
-
import { Direction } from
|
3
|
-
|
1
|
+
import { GapStyle } from "../../../index";
|
2
|
+
import { Direction } from "..";
|
4
3
|
export declare const getNumberFromPixels: (pixels: string | undefined) => number;
|
5
4
|
export declare const computeGapPixels: (element: Element, gapType: GapStyle) => number;
|
6
5
|
export declare const gapAndDisplayInformation: (element: Element | null, gapStyle: GapStyle) => [number, boolean];
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { getPropByDirection, parseFloatEmpty } from "./GetStyles";
|
2
|
+
export const getNumberFromPixels = (pixels) => {
|
3
|
+
if (!pixels || pixels.length == 0) {
|
4
|
+
return 0;
|
5
|
+
}
|
6
|
+
return parseFloatEmpty(pixels.replace("px", ""));
|
7
|
+
};
|
8
|
+
export const computeGapPixels = (element, gapType) => {
|
9
|
+
const gap = getComputedStyle(element)[gapType];
|
10
|
+
if (gap.match("%")) {
|
11
|
+
const gap_percent = parseFloatEmpty(gap.replace("%", ""));
|
12
|
+
const { width } = element.getBoundingClientRect();
|
13
|
+
return width * (gap_percent / 100);
|
14
|
+
}
|
15
|
+
const gap_px = getNumberFromPixels(gap);
|
16
|
+
return gap_px;
|
17
|
+
};
|
18
|
+
export const gapAndDisplayInformation = (element, gapStyle) => {
|
19
|
+
if (!(element instanceof Element))
|
20
|
+
return [
|
21
|
+
0,
|
22
|
+
false,
|
23
|
+
];
|
24
|
+
const gap = computeGapPixels(element, gapStyle);
|
25
|
+
const display = getComputedStyle(element).display;
|
26
|
+
const hasGaps = gap > 0 || display === "flex";
|
27
|
+
return [gap, hasGaps];
|
28
|
+
};
|
29
|
+
export const getBeforeStyles = (element) => {
|
30
|
+
const { top, left } = getComputedStyle(element);
|
31
|
+
return [getNumberFromPixels(top), getNumberFromPixels(left)];
|
32
|
+
};
|
33
|
+
export const getGapPixels = (element, direction) => {
|
34
|
+
const { gap: gapStyle } = getPropByDirection(direction);
|
35
|
+
const [gap, hasGaps] = gapAndDisplayInformation(element, gapStyle);
|
36
|
+
if (hasGaps) {
|
37
|
+
return gap;
|
38
|
+
}
|
39
|
+
return 0;
|
40
|
+
};
|
@@ -1,5 +1,4 @@
|
|
1
|
-
import { DragMouseTouchEvent, fixedSize } from
|
2
|
-
|
1
|
+
import { DragMouseTouchEvent, fixedSize } from "../../../index";
|
3
2
|
type onTouchEvent = "ontouchstart" | "ontouchmove" | "ontouchend";
|
4
3
|
declare const onMouseEvents: readonly ["onmouseup", "onmousedown", "onmousemove"];
|
5
4
|
type onMouseEvent = (typeof onMouseEvents)[number];
|
@@ -0,0 +1,192 @@
|
|
1
|
+
import { HORIZONTAL, VERTICAL } from "..";
|
2
|
+
import { getPropByDirection, getValueFromProperty } from "./GetStyles";
|
3
|
+
import { IsHTMLElement, IsMouseEvent, isTouchEvent } from "./touchDevice";
|
4
|
+
const onMouseEvents = ["onmouseup", "onmousedown", "onmousemove"];
|
5
|
+
const mouseEvents = ["mouseup", "mousedown", "mousemove"];
|
6
|
+
export const setSizeStyles = (element, height, width) => {
|
7
|
+
if (!element) {
|
8
|
+
return;
|
9
|
+
}
|
10
|
+
element.style.height = `${height}px`;
|
11
|
+
element.style.width = `${width}px`;
|
12
|
+
};
|
13
|
+
export const fixSizeStyle = (element) => {
|
14
|
+
if (!element) {
|
15
|
+
return;
|
16
|
+
}
|
17
|
+
const { height, width } = element.getBoundingClientRect();
|
18
|
+
setSizeStyles(element, height, width);
|
19
|
+
};
|
20
|
+
export const moveTranslate = (element, height, width) => {
|
21
|
+
if (!element || !IsHTMLElement(element)) {
|
22
|
+
return;
|
23
|
+
}
|
24
|
+
if (width == 0 && height == 0) {
|
25
|
+
element.style.transform = "";
|
26
|
+
}
|
27
|
+
else {
|
28
|
+
element.style.transform = `translate(${width}px,${height}px)`;
|
29
|
+
}
|
30
|
+
};
|
31
|
+
const assignDraggingTouchEvent = (element, onEvent, callback, touchCallback) => {
|
32
|
+
element[onEvent] = (event) => {
|
33
|
+
if (event.defaultPrevented) {
|
34
|
+
return;
|
35
|
+
}
|
36
|
+
touchCallback && touchCallback(event);
|
37
|
+
const dragMouseTouchEvent = convetEventToDragMouseTouchEvent(event);
|
38
|
+
callback(dragMouseTouchEvent);
|
39
|
+
};
|
40
|
+
};
|
41
|
+
export const assignDraggingEvent = (element, onEvent, callback, touchCallback) => {
|
42
|
+
if (!callback) {
|
43
|
+
return;
|
44
|
+
}
|
45
|
+
if (isOnMouseEvent(onEvent)) {
|
46
|
+
element[onEvent] = callback;
|
47
|
+
}
|
48
|
+
else {
|
49
|
+
assignDraggingTouchEvent(element, onEvent, callback, touchCallback);
|
50
|
+
}
|
51
|
+
};
|
52
|
+
export const addDragMouseToucEventListener = (event, callback) => {
|
53
|
+
if (!callback) {
|
54
|
+
return;
|
55
|
+
}
|
56
|
+
if (isMouseEvent(event)) {
|
57
|
+
document.addEventListener(event, callback);
|
58
|
+
}
|
59
|
+
else {
|
60
|
+
document.addEventListener(event, (event) => {
|
61
|
+
const dragMouseTouchEvent = convetEventToDragMouseTouchEvent(event);
|
62
|
+
callback(dragMouseTouchEvent);
|
63
|
+
});
|
64
|
+
}
|
65
|
+
};
|
66
|
+
const isOnMouseEvent = (x) => onMouseEvents.includes(x);
|
67
|
+
const isMouseEvent = (x) => mouseEvents.includes(x);
|
68
|
+
const getDefaultEvent = (event) => {
|
69
|
+
const { target } = event;
|
70
|
+
return {
|
71
|
+
clientX: 0,
|
72
|
+
clientY: 0,
|
73
|
+
pageX: 0,
|
74
|
+
pageY: 0,
|
75
|
+
screenX: 0,
|
76
|
+
screenY: 0,
|
77
|
+
target,
|
78
|
+
offsetX: 0,
|
79
|
+
offsetY: 0,
|
80
|
+
};
|
81
|
+
};
|
82
|
+
const getOffsetFromEvent = (event, tempEvent) => {
|
83
|
+
const getTouchEventOffset = (element, direction) => {
|
84
|
+
return getOffset(tempEvent, window, direction, element);
|
85
|
+
};
|
86
|
+
if (IsMouseEvent(event)) {
|
87
|
+
const { offsetX, offsetY } = event;
|
88
|
+
return [offsetX, offsetY];
|
89
|
+
}
|
90
|
+
else {
|
91
|
+
const element = event.target;
|
92
|
+
return [
|
93
|
+
getTouchEventOffset(element, HORIZONTAL),
|
94
|
+
getTouchEventOffset(element, VERTICAL),
|
95
|
+
];
|
96
|
+
}
|
97
|
+
};
|
98
|
+
export const convetEventToDragMouseTouchEvent = (event) => {
|
99
|
+
const tempEvent = getEvent(event);
|
100
|
+
if (!tempEvent) {
|
101
|
+
return getDefaultEvent(event);
|
102
|
+
}
|
103
|
+
const [offsetX, offsetY] = getOffsetFromEvent(event, tempEvent);
|
104
|
+
const { clientX, clientY, pageX, pageY, screenX, screenY, target } = tempEvent;
|
105
|
+
return {
|
106
|
+
clientX,
|
107
|
+
clientY,
|
108
|
+
pageX,
|
109
|
+
pageY,
|
110
|
+
screenX,
|
111
|
+
screenY,
|
112
|
+
target,
|
113
|
+
offsetX,
|
114
|
+
offsetY,
|
115
|
+
};
|
116
|
+
};
|
117
|
+
const getEvent = (event) => {
|
118
|
+
if (isTouchEvent(event)) {
|
119
|
+
return event.touches[0] ?? event.changedTouches[0];
|
120
|
+
}
|
121
|
+
if (IsMouseEvent(event)) {
|
122
|
+
return event;
|
123
|
+
}
|
124
|
+
};
|
125
|
+
const getOffset = (event, window, direction, element) => {
|
126
|
+
const { page, scroll, before, borderBeforeWidth, getRect } = getPropByDirection(direction);
|
127
|
+
const boundingClientRect = getRect(element);
|
128
|
+
return (event[page] -
|
129
|
+
window[scroll] -
|
130
|
+
boundingClientRect[before] -
|
131
|
+
getValueFromProperty(element, borderBeforeWidth));
|
132
|
+
};
|
133
|
+
export const setTranistion = (element, duration, timingFunction = "ease-out", types = "transform") => {
|
134
|
+
if (IsHTMLElement(element)) {
|
135
|
+
element.style.transitionDuration = `${duration}ms`;
|
136
|
+
element.style.transitionTimingFunction = `${timingFunction}`;
|
137
|
+
element.style.transitionProperty = `${types}`;
|
138
|
+
}
|
139
|
+
};
|
140
|
+
export const setEventWithInterval = (element, eventName, callback) => {
|
141
|
+
if (!element || !IsHTMLElement(element)) {
|
142
|
+
return;
|
143
|
+
}
|
144
|
+
element[eventName] = () => {
|
145
|
+
callback();
|
146
|
+
};
|
147
|
+
};
|
148
|
+
const getStyles = (node) => {
|
149
|
+
var style = node.querySelector("style");
|
150
|
+
if (!style) {
|
151
|
+
var newStyle = document.createElement("style");
|
152
|
+
node.appendChild(newStyle);
|
153
|
+
return newStyle;
|
154
|
+
}
|
155
|
+
return style;
|
156
|
+
};
|
157
|
+
const containRule = (sheet, cssCode) => {
|
158
|
+
const selectorTextRegex = /\.-?[_a-zA-Z0-9-*\s<>():]+/g;
|
159
|
+
const [selectorText] = cssCode.match(selectorTextRegex) || [];
|
160
|
+
for (const rule of sheet.cssRules) {
|
161
|
+
const [ruleSelectorText] = rule.cssText.match(selectorTextRegex) || [];
|
162
|
+
if (selectorText === ruleSelectorText) {
|
163
|
+
return true;
|
164
|
+
}
|
165
|
+
}
|
166
|
+
return false;
|
167
|
+
};
|
168
|
+
export const AddCssStylesToElement = (node, cssCodes) => {
|
169
|
+
cssCodes.forEach((cssCode) => {
|
170
|
+
AddCssStyleToElement(node, cssCode);
|
171
|
+
});
|
172
|
+
};
|
173
|
+
const AddCssStyleToElement = (node, cssCode) => {
|
174
|
+
var style = getStyles(node);
|
175
|
+
if (!style.sheet) {
|
176
|
+
return;
|
177
|
+
}
|
178
|
+
if (!containRule(style.sheet, cssCode)) {
|
179
|
+
style.sheet?.insertRule(cssCode, style.sheet.cssRules.length);
|
180
|
+
}
|
181
|
+
};
|
182
|
+
export const setCustomFixedSize = (element, fixedProps = {}) => {
|
183
|
+
for (const fixedProp of Object.keys(fixedProps)) {
|
184
|
+
const fixedValue = fixedProps[fixedProp];
|
185
|
+
if (fixedValue != undefined) {
|
186
|
+
setCustomProperty(element, `--${fixedProp}`, fixedValue);
|
187
|
+
}
|
188
|
+
}
|
189
|
+
};
|
190
|
+
const setCustomProperty = (element, fixedProp, newFixedSize) => {
|
191
|
+
return element && element.style.setProperty(fixedProp, newFixedSize);
|
192
|
+
};
|
@@ -1,6 +1,5 @@
|
|
1
|
-
import { DragMouseTouchEvent, TransformEvent } from
|
2
|
-
import { Direction } from
|
3
|
-
|
1
|
+
import { DragMouseTouchEvent, TransformEvent } from "../../../index";
|
2
|
+
import { Direction } from "..";
|
4
3
|
export declare const useTransform: (draggedElement: HTMLElement) => readonly [(element: HTMLElement, parent: HTMLElement, pagePosition: {
|
5
4
|
pageX: number;
|
6
5
|
pageY: number;
|
@@ -0,0 +1,148 @@
|
|
1
|
+
import { draggableIsOutside, getNearestFixedParentPosition, getPropByDirection, getValueFromProperty, } from "./GetStyles";
|
2
|
+
import { HORIZONTAL, VERTICAL } from "..";
|
3
|
+
import { scrollByDirection } from "./scroll";
|
4
|
+
import { HANDLER_CLASS, DRAGGING_CLASS } from "./classes";
|
5
|
+
import { containClass } from "./dom/classList";
|
6
|
+
export const useTransform = (draggedElement) => {
|
7
|
+
let currentOffset = { offsetX: 0, offsetY: 0 };
|
8
|
+
let position = { top: 0, left: 0 };
|
9
|
+
let translate = { x: 0, y: 0 };
|
10
|
+
const updateTranform = (newTranslate) => {
|
11
|
+
draggedElement.style.transform = `translate( ${newTranslate.x}px, ${newTranslate.y}px)`;
|
12
|
+
};
|
13
|
+
const updatePosition = (newPosition) => {
|
14
|
+
draggedElement.style.top = `${newPosition.top}px`;
|
15
|
+
draggedElement.style.left = `${newPosition.left}px`;
|
16
|
+
};
|
17
|
+
const setTransform = (element, parent, pagePosition, direction) => {
|
18
|
+
const getTranslateWihtDirection = (translateDirection) => {
|
19
|
+
const { beforeMargin, borderBeforeWidth, before, offset, scroll, page, inner, distance, axis, getRect } = getPropByDirection(translateDirection);
|
20
|
+
const pageValue = pagePosition[page];
|
21
|
+
const scrollValue = window[scroll];
|
22
|
+
const innerDistance = window[inner];
|
23
|
+
const distanceValue = getRect(element)[distance];
|
24
|
+
const border = getValueFromProperty(element, borderBeforeWidth);
|
25
|
+
const margin = getValueFromProperty(element, beforeMargin);
|
26
|
+
const elementPosittion = pageValue - currentOffset[offset];
|
27
|
+
const beforefixecParentValue = getNearestFixedParentPosition(element, translateDirection);
|
28
|
+
if (elementPosittion >= scrollValue - distanceValue / 2 &&
|
29
|
+
elementPosittion <= scrollValue + innerDistance) {
|
30
|
+
const newTranslate = elementPosittion -
|
31
|
+
position[before] -
|
32
|
+
border -
|
33
|
+
margin -
|
34
|
+
scrollValue -
|
35
|
+
beforefixecParentValue;
|
36
|
+
updateScroll(translateDirection);
|
37
|
+
return newTranslate;
|
38
|
+
}
|
39
|
+
const defaultTransalation = translate[axis];
|
40
|
+
return defaultTransalation;
|
41
|
+
};
|
42
|
+
const updateScroll = (translateDirection) => {
|
43
|
+
if (element &&
|
44
|
+
containClass(element, DRAGGING_CLASS) &&
|
45
|
+
translateDirection === direction) {
|
46
|
+
const { before, distance, axis, getRect } = getPropByDirection(direction);
|
47
|
+
const distanceValue = getRect(element)[distance];
|
48
|
+
const parentBoundingClientRect = getRect(parent);
|
49
|
+
const positionInsideParent = position[before] -
|
50
|
+
parentBoundingClientRect[before] +
|
51
|
+
translate[axis];
|
52
|
+
const parentDistance = parentBoundingClientRect[distance];
|
53
|
+
const totalDistance = parentDistance - distanceValue;
|
54
|
+
const relativePosition = positionInsideParent / totalDistance;
|
55
|
+
const relativeDistanceValue = distanceValue / totalDistance;
|
56
|
+
const velocity = 0.1;
|
57
|
+
const infLimit = 0.2;
|
58
|
+
const upperLimit = 0.8;
|
59
|
+
let percent = 0;
|
60
|
+
const isOutside = draggableIsOutside(element, parent);
|
61
|
+
if (!isOutside &&
|
62
|
+
relativePosition < infLimit &&
|
63
|
+
relativePosition > -relativeDistanceValue) {
|
64
|
+
percent = relativePosition / infLimit - 1;
|
65
|
+
}
|
66
|
+
else if (!isOutside &&
|
67
|
+
relativePosition > upperLimit &&
|
68
|
+
relativePosition < 1 + relativeDistanceValue) {
|
69
|
+
percent = (1 / (1 - upperLimit)) * (relativePosition - upperLimit);
|
70
|
+
}
|
71
|
+
const scrollAmount = velocity * distanceValue * percent;
|
72
|
+
scrollByDirection(parent, direction, scrollAmount);
|
73
|
+
}
|
74
|
+
};
|
75
|
+
const updateTranlateByDirection = (direction) => {
|
76
|
+
const { axis } = getPropByDirection(direction);
|
77
|
+
translate[axis] = getTranslateWihtDirection(direction);
|
78
|
+
updateTranform(translate);
|
79
|
+
};
|
80
|
+
updateTranlateByDirection(HORIZONTAL);
|
81
|
+
updateTranlateByDirection(VERTICAL);
|
82
|
+
};
|
83
|
+
const updateTransformState = (event, element) => {
|
84
|
+
const [top, left, offsetX, offsetY] = getTransformState(event, element, draggedElement);
|
85
|
+
position = {
|
86
|
+
top,
|
87
|
+
left,
|
88
|
+
};
|
89
|
+
updatePosition(position);
|
90
|
+
currentOffset = { offsetX, offsetY };
|
91
|
+
};
|
92
|
+
return [
|
93
|
+
setTransform,
|
94
|
+
updateTransformState,
|
95
|
+
];
|
96
|
+
};
|
97
|
+
const getOffsetWithDraggable = (direction, element, draggable) => {
|
98
|
+
const { borderBeforeWidth, before, getRect } = getPropByDirection(direction);
|
99
|
+
return (getRect(element)[before] -
|
100
|
+
getRect(draggable)[before] -
|
101
|
+
getValueFromProperty(draggable, borderBeforeWidth));
|
102
|
+
};
|
103
|
+
const getOffset = (event, draggable) => {
|
104
|
+
let { offsetX, offsetY, target } = event;
|
105
|
+
let targetHandler = getHandlerElementAncestor(target, draggable);
|
106
|
+
const targetElement = target;
|
107
|
+
if (targetElement && targetHandler && !targetElement.isSameNode(targetHandler)) {
|
108
|
+
offsetX += getOffsetWithDraggable(HORIZONTAL, targetElement, targetHandler);
|
109
|
+
offsetY += getOffsetWithDraggable(VERTICAL, targetElement, targetHandler);
|
110
|
+
}
|
111
|
+
if (targetHandler && draggable != target) {
|
112
|
+
offsetX += getOffsetWithDraggable(HORIZONTAL, targetHandler, draggable);
|
113
|
+
offsetY += getOffsetWithDraggable(VERTICAL, targetHandler, draggable);
|
114
|
+
}
|
115
|
+
return [offsetX, offsetY];
|
116
|
+
};
|
117
|
+
const getHandlerElementAncestor = (target, draggable) => {
|
118
|
+
const targetHandler = target?.closest(`.${HANDLER_CLASS}`);
|
119
|
+
if (targetHandler && targetHandler.isSameNode(draggable)) {
|
120
|
+
return target;
|
121
|
+
}
|
122
|
+
return targetHandler;
|
123
|
+
};
|
124
|
+
const getPositionByDistance = (direction, event, element, offsetEvent) => {
|
125
|
+
const { offset, beforeMargin, page, borderBeforeWidth, scroll } = getPropByDirection(direction);
|
126
|
+
const beforefixecParentValue = getNearestFixedParentPosition(element, direction);
|
127
|
+
return (event[page] -
|
128
|
+
offsetEvent[offset] -
|
129
|
+
getValueFromProperty(element, beforeMargin) -
|
130
|
+
getValueFromProperty(element, borderBeforeWidth) -
|
131
|
+
window[scroll] -
|
132
|
+
beforefixecParentValue);
|
133
|
+
};
|
134
|
+
export const getTransformState = (event, element, draggable) => {
|
135
|
+
const [offsetX, offsetY] = getOffset(event, draggable);
|
136
|
+
return [
|
137
|
+
getPositionByDistance(VERTICAL, event, element, {
|
138
|
+
offsetX,
|
139
|
+
offsetY,
|
140
|
+
}),
|
141
|
+
getPositionByDistance(HORIZONTAL, event, element, {
|
142
|
+
offsetX,
|
143
|
+
offsetY,
|
144
|
+
}),
|
145
|
+
offsetX,
|
146
|
+
offsetY
|
147
|
+
];
|
148
|
+
};
|
@@ -0,0 +1,9 @@
|
|
1
|
+
export const DRAGGABLE_CLASS = "draggable";
|
2
|
+
export const DROPPABLE_CLASS = "droppable";
|
3
|
+
export const HANDLER_CLASS = "handler-class";
|
4
|
+
export const DRAGGING_CLASS = 'dragging';
|
5
|
+
export const DRAGGING_HANDLER_CLASS = "dragging-handler-class";
|
6
|
+
export const DROPPING_CLASS = "dropping";
|
7
|
+
export const GRABBING_CLASS = "grabbing";
|
8
|
+
export const GRAB_CLASS = "grab";
|
9
|
+
export const DISABLE_TRANSITION = "disable-transition";
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { ListCondig, MapFrom
|
2
|
-
import {
|
3
|
-
|
1
|
+
import { ListCondig, MapFrom } from "..";
|
2
|
+
import { Config, CoreConfig } from "..";
|
3
|
+
import { DroppableConfig } from "../configHandler";
|
4
4
|
export declare const getConfig: <T>(listCondig: ListCondig<T>, config?: Config<T>) => CoreConfig<T>;
|
5
5
|
export declare const MapConfig: <T>(coreConfig: DroppableConfig<any>, mapFrom: MapFrom<T>) => CoreConfig<any>;
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import { VERTICAL, } from "..";
|
2
|
+
import { DRAGGABLE_CLASS } from "./classes";
|
3
|
+
export const getConfig = (listCondig, config) => {
|
4
|
+
const onRemoveAtEvent = (index, sync) => {
|
5
|
+
return listCondig.removeAtEvent(index, sync);
|
6
|
+
};
|
7
|
+
const onInsertEvent = (index, value, sync) => {
|
8
|
+
return listCondig.insertEvent(index, value, sync);
|
9
|
+
};
|
10
|
+
const onGetLegth = () => {
|
11
|
+
return listCondig.getLength();
|
12
|
+
};
|
13
|
+
const onGetValue = (index) => {
|
14
|
+
return listCondig.getValue(index);
|
15
|
+
};
|
16
|
+
const defaultMapFrom = (object) => {
|
17
|
+
return object;
|
18
|
+
};
|
19
|
+
return {
|
20
|
+
direction: config?.direction ?? VERTICAL,
|
21
|
+
handlerSelector: config?.handlerSelector ?? DRAGGABLE_CLASS,
|
22
|
+
draggingClass: config?.draggingClass ?? "dragging",
|
23
|
+
droppableClass: config?.droppableClass ?? 'droppable-hover',
|
24
|
+
isDraggable: config?.isDraggable ?? (() => true),
|
25
|
+
onDragStart: config?.onDragStart ?? (() => { }),
|
26
|
+
onDragEnd: config?.onDragEnd ?? (() => { }),
|
27
|
+
droppableGroup: config?.droppableGroup,
|
28
|
+
onRemoveAtEvent,
|
29
|
+
onInsertEvent,
|
30
|
+
onGetLegth,
|
31
|
+
onGetValue,
|
32
|
+
animationDuration: config?.animationDuration ?? 200,
|
33
|
+
removingClass: config?.removingClass ?? "removing",
|
34
|
+
insertingFromClass: config?.insertingFromClass ?? 'from-inserting',
|
35
|
+
delayBeforeRemove: config?.delayBeforeRemove ?? 200,
|
36
|
+
delayBeforeInsert: config?.delayBeforeInsert ?? 200,
|
37
|
+
mapFrom: config?.mapFrom ?? defaultMapFrom,
|
38
|
+
};
|
39
|
+
};
|
40
|
+
export const MapConfig = (coreConfig, mapFrom) => {
|
41
|
+
const { config, droppable } = coreConfig;
|
42
|
+
const { onInsertEvent, onDragEnd } = config;
|
43
|
+
const mapOnInsertEvent = (index, value) => {
|
44
|
+
return onInsertEvent(index, mapFrom(value, droppable), true);
|
45
|
+
};
|
46
|
+
const mapOnDragEnd = (eventData) => {
|
47
|
+
const { index, value } = eventData;
|
48
|
+
onDragEnd({ index, value: mapFrom(value, droppable) });
|
49
|
+
};
|
50
|
+
return {
|
51
|
+
...config,
|
52
|
+
onDragEnd: mapOnDragEnd,
|
53
|
+
onInsertEvent: mapOnInsertEvent
|
54
|
+
};
|
55
|
+
};
|
@@ -0,0 +1,35 @@
|
|
1
|
+
export const containClass = (element, cssClass) => {
|
2
|
+
return element.classList.contains(cssClass);
|
3
|
+
};
|
4
|
+
export const toggleClass = (element, cssClass, force = false) => {
|
5
|
+
element.classList.toggle(cssClass, force);
|
6
|
+
};
|
7
|
+
export const addClass = (element, cssClass) => {
|
8
|
+
element.classList.add(cssClass);
|
9
|
+
};
|
10
|
+
export const removeClass = (element, cssClass) => {
|
11
|
+
element.classList.remove(cssClass);
|
12
|
+
};
|
13
|
+
export const containstClasses = (element, classes) => {
|
14
|
+
return getClassesList(classes).every((cssClass) => containClass(element, cssClass));
|
15
|
+
};
|
16
|
+
export const getClassesSelector = (classes) => {
|
17
|
+
if (!classes) {
|
18
|
+
return "";
|
19
|
+
}
|
20
|
+
const classesSelector = getClassesList(classes).join(".");
|
21
|
+
return `.${classesSelector}`;
|
22
|
+
};
|
23
|
+
export const addMultipleClasses = (element, classes) => {
|
24
|
+
if (!classes) {
|
25
|
+
return;
|
26
|
+
}
|
27
|
+
const classesList = getClassesList(classes);
|
28
|
+
element.classList.add(...classesList);
|
29
|
+
};
|
30
|
+
export const getClassesList = (classes) => {
|
31
|
+
if (!classes) {
|
32
|
+
return [];
|
33
|
+
}
|
34
|
+
return classes.split(" ").filter((cssClass) => cssClass);
|
35
|
+
};
|
@@ -1,7 +1,6 @@
|
|
1
|
-
import { DroppableConfig } from
|
2
|
-
import { DragMouseTouchEvent } from
|
3
|
-
import { MapFrom } from
|
4
|
-
|
1
|
+
import { DroppableConfig } from "../configHandler";
|
2
|
+
import { DragMouseTouchEvent } from "../../../index";
|
3
|
+
import { MapFrom } from "..";
|
5
4
|
export declare class DroppableConfigurator<T> {
|
6
5
|
initial: DroppableConfig<any> | undefined;
|
7
6
|
current: DroppableConfig<T> | undefined;
|