fluid-dnd 2.0.1 → 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.
Files changed (60) hide show
  1. package/dist/core/HandlerPublisher.js +20 -0
  2. package/dist/core/configHandler.d.ts +2 -3
  3. package/dist/core/configHandler.js +33 -0
  4. package/dist/core/dragAndDrop.d.ts +3 -3
  5. package/dist/core/dragAndDrop.js +62 -0
  6. package/dist/core/index.js +2 -0
  7. package/dist/core/useDraggable.d.ts +2 -3
  8. package/dist/core/useDraggable.js +328 -0
  9. package/dist/core/useDroppable.d.ts +2 -3
  10. package/dist/core/useDroppable.js +55 -0
  11. package/dist/core/utils/GetStyles.d.ts +2 -3
  12. package/dist/core/utils/GetStyles.js +138 -0
  13. package/dist/core/utils/ParseStyles.d.ts +2 -3
  14. package/dist/core/utils/ParseStyles.js +40 -0
  15. package/dist/core/utils/SetStyles.d.ts +1 -2
  16. package/dist/core/utils/SetStyles.js +192 -0
  17. package/dist/core/utils/SetTransform.d.ts +2 -3
  18. package/dist/core/utils/SetTransform.js +148 -0
  19. package/dist/core/utils/classes.js +9 -0
  20. package/dist/core/utils/config.d.ts +3 -3
  21. package/dist/core/utils/config.js +55 -0
  22. package/dist/core/utils/dom/classList.js +35 -0
  23. package/dist/core/utils/droppableConfigurator.d.ts +3 -4
  24. package/dist/core/utils/droppableConfigurator.js +106 -0
  25. package/dist/core/utils/events/emitEvents.d.ts +5 -6
  26. package/dist/core/utils/events/emitEvents.js +333 -0
  27. package/dist/core/utils/index.js +9 -0
  28. package/dist/core/utils/observer.js +11 -0
  29. package/dist/core/utils/scroll.d.ts +2 -3
  30. package/dist/core/utils/scroll.js +17 -0
  31. package/dist/core/utils/tempChildren.d.ts +1 -2
  32. package/dist/core/utils/tempChildren.js +146 -0
  33. package/dist/core/utils/touchDevice.js +3 -0
  34. package/dist/core/utils/translate/GetTranslateBeforeDropping.d.ts +2 -3
  35. package/dist/core/utils/translate/GetTranslateBeforeDropping.js +129 -0
  36. package/dist/core/utils/translate/GetTranslationByDraggingAndEvent.d.ts +2 -3
  37. package/dist/core/utils/translate/GetTranslationByDraggingAndEvent.js +48 -0
  38. package/dist/index.d.ts +4 -0
  39. package/dist/index.js +2 -0
  40. package/dist/react/index.d.ts +1 -2
  41. package/dist/react/index.js +2 -0
  42. package/dist/react/useDragAndDrop.d.ts +2 -3
  43. package/dist/react/useDragAndDrop.js +28 -0
  44. package/dist/react/utils/ReactLilstConfig.d.ts +3 -4
  45. package/dist/react/utils/ReactLilstConfig.js +64 -0
  46. package/dist/svelte/index.d.ts +1 -2
  47. package/dist/svelte/index.js +2 -0
  48. package/dist/svelte/useDragAndDrop.d.ts +1 -2
  49. package/dist/svelte/useDragAndDrop.js +25 -0
  50. package/dist/svelte/utils/SvelteListCondig.d.ts +2 -2
  51. package/dist/svelte/utils/SvelteListCondig.js +36 -0
  52. package/dist/vue/index.d.ts +1 -2
  53. package/dist/vue/index.js +2 -0
  54. package/dist/vue/useDragAndDrop.d.ts +2 -3
  55. package/dist/vue/useDragAndDrop.js +23 -0
  56. package/dist/vue/utils/DropMethods.d.ts +1 -2
  57. package/dist/vue/utils/DropMethods.js +19 -0
  58. package/dist/vue/utils/VueListCondig.d.ts +3 -3
  59. package/dist/vue/utils/VueListCondig.js +28 -0
  60. package/package.json +2 -5
@@ -0,0 +1,106 @@
1
+ import ConfigHandler from "../configHandler";
2
+ import { draggableIsOutside } from "./GetStyles";
3
+ import { IsHTMLElement } from "./touchDevice";
4
+ import { setEventWithInterval } from "./SetStyles";
5
+ import { getClassesSelector } from "./dom/classList";
6
+ import { MapConfig } from "./config";
7
+ export class DroppableConfigurator {
8
+ initial;
9
+ current;
10
+ parent;
11
+ draggableElement;
12
+ groupClass;
13
+ dragEvent;
14
+ changeDroppable;
15
+ mapFrom;
16
+ constructor(draggableElement, droppableGroupClass, parent, setTransformDragEvent, changeDroppable, mapFrom) {
17
+ this.parent = parent;
18
+ this.draggableElement = draggableElement;
19
+ this.groupClass = droppableGroupClass;
20
+ this.dragEvent = setTransformDragEvent;
21
+ this.mapFrom = mapFrom;
22
+ this.initial = parent ? ConfigHandler.getConfig(parent) : undefined;
23
+ this.changeDroppable = changeDroppable;
24
+ }
25
+ getDraggableAncestor(clientX, clientY, draggable) {
26
+ return document
27
+ .elementsFromPoint(clientX, clientY)
28
+ .filter((element) => !element.isSameNode(draggable));
29
+ }
30
+ getElementBelow(currentElement, event, hiddenDraggable = true) {
31
+ const getElementBelow = (config) => {
32
+ const [elementBelow] = config.getDraggableAncestor(event.clientX, event.clientY, currentElement);
33
+ return elementBelow;
34
+ };
35
+ let elementBelow = null;
36
+ if (hiddenDraggable) {
37
+ currentElement.hidden = true;
38
+ elementBelow = getElementBelow(this);
39
+ currentElement.hidden = false;
40
+ }
41
+ else {
42
+ elementBelow = getElementBelow(this);
43
+ }
44
+ return elementBelow;
45
+ }
46
+ getCurrent(currentElement, event, hiddenDraggable = true) {
47
+ const elementBelow = this.getElementBelow(currentElement, event, hiddenDraggable);
48
+ if (!this.groupClass || !elementBelow) {
49
+ return;
50
+ }
51
+ const currentDroppable = elementBelow.closest(getClassesSelector(this.groupClass));
52
+ return currentDroppable;
53
+ }
54
+ isOutsideOfAllDroppables(currentElement) {
55
+ const droppables = this.groupClass ? Array.from(document.querySelectorAll(getClassesSelector(this.groupClass))) : [this.parent];
56
+ return droppables.every((droppable) => draggableIsOutside(currentElement, droppable));
57
+ }
58
+ isNotInsideAnotherDroppable(currentElement, droppable) {
59
+ const isOutside = draggableIsOutside(currentElement, droppable);
60
+ return !isOutside || this.isOutsideOfAllDroppables(currentElement);
61
+ }
62
+ onScrollEvent() {
63
+ this.dragEvent();
64
+ }
65
+ ;
66
+ setOnScroll(droppable) {
67
+ setEventWithInterval(droppable, "onscroll", () => { this.onScrollEvent(); });
68
+ }
69
+ getConfigFrom(element) {
70
+ const coreConfig = ConfigHandler.getConfig(element);
71
+ if (!coreConfig) {
72
+ return undefined;
73
+ }
74
+ if (element.isSameNode(this.parent)) {
75
+ return coreConfig;
76
+ }
77
+ return {
78
+ ...coreConfig,
79
+ config: MapConfig(coreConfig, this.mapFrom)
80
+ };
81
+ }
82
+ getCurrentConfig(event) {
83
+ const currentElement = this.draggableElement;
84
+ if (this.current &&
85
+ this.isNotInsideAnotherDroppable(currentElement, this.current?.droppable)) {
86
+ return this.current;
87
+ }
88
+ const currentDroppable = this.getCurrent(currentElement, event);
89
+ if (!currentDroppable) {
90
+ return this.getConfigFrom(this.parent);
91
+ }
92
+ if (IsHTMLElement(currentDroppable) && !currentDroppable.onscroll) {
93
+ this.setOnScroll(currentDroppable);
94
+ }
95
+ return this.getConfigFrom(currentDroppable);
96
+ }
97
+ updateConfig(event) {
98
+ const oldDroppableConfig = this.current;
99
+ this.current = this.getCurrentConfig(event);
100
+ this.changeDroppable(this.current, oldDroppableConfig);
101
+ }
102
+ isOutside(event, hiddenDraggable = true) {
103
+ const currentElement = this.draggableElement;
104
+ return !Boolean(this.getCurrent(currentElement, event, hiddenDraggable));
105
+ }
106
+ }
@@ -1,9 +1,8 @@
1
- import { WindowScroll } from '../../../../index';
2
- import { CoreConfig } from '../..';
3
- import { DRAG_EVENT, START_DRAG_EVENT, START_DROP_EVENT } from '..';
4
- import { DroppableConfig } from '../../configHandler';
5
- import { default as HandlerPublisher } from '../../HandlerPublisher';
6
-
1
+ import { WindowScroll } from "../../../../index";
2
+ import { CoreConfig } from "../..";
3
+ import { DRAG_EVENT, START_DRAG_EVENT, START_DROP_EVENT } from "..";
4
+ import { DroppableConfig } from "../../configHandler";
5
+ import HandlerPublisher from '../../HandlerPublisher';
7
6
  type DraggingEvent = typeof DRAG_EVENT | typeof START_DRAG_EVENT;
8
7
  type DragAndDropEvent = DraggingEvent | DropEvent;
9
8
  type DropEvent = "drop" | typeof START_DROP_EVENT;
@@ -0,0 +1,333 @@
1
+ import { draggableIsOutside, getParentDraggableChildren, getPropByDirection, getSiblings, getTransform, getWindowScroll, } from "../GetStyles";
2
+ import { moveTranslate, setCustomFixedSize, setTranistion } from "../SetStyles";
3
+ import getTranslationByDragging from "../translate/GetTranslationByDraggingAndEvent";
4
+ import getTranslateBeforeDropping from "../translate/GetTranslateBeforeDropping";
5
+ import { DRAG_EVENT, draggableTargetTimingFunction, IsDropEvent, START_DRAG_EVENT, START_DROP_EVENT, TEMP_CHILD_CLASS } from "..";
6
+ import { IsHTMLElement } from "../touchDevice";
7
+ import { isTempElement, removeTempChild } from "../tempChildren";
8
+ import { DISABLE_TRANSITION, DRAGGABLE_CLASS, DRAGGING_CLASS, DRAGGING_HANDLER_CLASS, DROPPING_CLASS, GRABBING_CLASS } from "../classes";
9
+ import { addClass, containClass, getClassesSelector, removeClass, toggleClass } from "../dom/classList";
10
+ import { observeMutation } from "../observer";
11
+ const DELAY_TIME_TO_SWAP = 50;
12
+ export default function useEmitEvents(currentConfig, index, parent, droppableGroupClass, handlerPublisher, endDraggingAction) {
13
+ let actualIndex = index;
14
+ const { direction, handlerSelector, onRemoveAtEvent, animationDuration, delayBeforeInsert, draggingClass } = currentConfig;
15
+ const emitEventToSiblings = (draggedElement, event, initialWindowScroll, droppableConfig, positionOnSourceDroppable) => {
16
+ if (!droppableConfig) {
17
+ return;
18
+ }
19
+ const { droppable, config } = droppableConfig;
20
+ const tranlation = getTranslationByDragging(draggedElement, event, config.direction, droppable);
21
+ const dropping = IsDropEvent(event);
22
+ if (!dropping) {
23
+ emitDraggingEventToSiblings(draggedElement, event, tranlation, droppableConfig);
24
+ }
25
+ else {
26
+ emitDroppingEventToSiblings(draggedElement, event, tranlation, initialWindowScroll, droppableConfig, positionOnSourceDroppable);
27
+ }
28
+ };
29
+ // #region Insert
30
+ const emitInsertEventToSiblings = (targetIndex, draggedElement, droppable, value, startInserting) => {
31
+ const translation = getTranslationByDragging(draggedElement, 'insert', currentConfig.direction, droppable);
32
+ const { onInsertEvent } = currentConfig;
33
+ const siblings = getParentDraggableChildren(droppable);
34
+ for (const [index, sibling] of siblings.entries()) {
35
+ if (!containClass(sibling, DRAGGABLE_CLASS)) {
36
+ continue;
37
+ }
38
+ if (index >= targetIndex) {
39
+ dragEventOverElement(sibling, translation);
40
+ }
41
+ }
42
+ startInserting();
43
+ setTimeout(() => {
44
+ onInsertEvent(targetIndex, value);
45
+ onFinishInsertElement(targetIndex, droppable, currentConfig);
46
+ removeElementDraggingStyles(draggedElement);
47
+ removeTranslateFromSiblings(draggedElement, parent);
48
+ removeTempChild(parent, 0, true);
49
+ }, delayBeforeInsert);
50
+ };
51
+ // #region Remove
52
+ const emitRemoveEventToSiblings = (targetIndex, draggedElement, droppableConfig, onFinishRemoveEvent) => {
53
+ if (!droppableConfig ||
54
+ !droppableConfig.droppable ||
55
+ !droppableConfig.config) {
56
+ return;
57
+ }
58
+ const { droppable, config } = droppableConfig;
59
+ let [siblings] = getSiblings(draggedElement, droppable);
60
+ siblings = [draggedElement, ...siblings].toReversed();
61
+ const translation = getTranslationByDragging(draggedElement, "remove", config.direction, droppable);
62
+ for (const [index, sibling] of siblings.entries()) {
63
+ if (index >= targetIndex) {
64
+ startDragEventOverElement(sibling, translation);
65
+ setTimeout(() => {
66
+ onFinishRemoveEvent(sibling);
67
+ }, animationDuration);
68
+ }
69
+ }
70
+ };
71
+ const emitFinishRemoveEventToSiblings = (draggedElement) => {
72
+ removeTempChild(parent, animationDuration, true);
73
+ setTimeout(() => {
74
+ removeElementDraggingStyles(draggedElement);
75
+ removeTranslateFromSiblings(draggedElement, parent);
76
+ }, animationDuration);
77
+ };
78
+ // #region Drag events
79
+ const emitDraggingEventToSiblings = (draggedElement, event, translation, droppableConfig) => {
80
+ const { config, droppable } = droppableConfig;
81
+ const [siblings] = getSiblings(draggedElement, droppable);
82
+ const isOutside = draggableIsOutside(draggedElement, droppable);
83
+ if (siblings.length == 0) {
84
+ updateActualIndexBaseOnTranslation(translation, 1, config.direction, siblings);
85
+ }
86
+ for (const [index, sibling] of siblings.entries()) {
87
+ if (!containClass(sibling, DRAGGABLE_CLASS)) {
88
+ continue;
89
+ }
90
+ const siblingTransition = canChangeDraggable(config.direction, draggedElement, sibling, translation);
91
+ if (!isOutside && siblingTransition) {
92
+ translation = siblingTransition;
93
+ }
94
+ else if (!isOutside) {
95
+ continue;
96
+ }
97
+ const siblingRealIndex = siblings.length - index;
98
+ updateActualIndexBaseOnTranslation(translation, siblingRealIndex, config.direction, siblings);
99
+ if (event === START_DRAG_EVENT) {
100
+ startDragEventOverElement(sibling, translation);
101
+ }
102
+ else if (event === DRAG_EVENT) {
103
+ dragEventOverElement(sibling, translation);
104
+ }
105
+ }
106
+ };
107
+ const canChangeDraggable = (direction, sourceElement, targetElement, translation) => {
108
+ const { before, distance, axis, getRect } = getPropByDirection(direction);
109
+ const currentBoundingClientRect = getRect(sourceElement);
110
+ const targetBoundingClientRect = getRect(targetElement);
111
+ const currentPosition = currentBoundingClientRect[before];
112
+ const targetPosition = targetBoundingClientRect[before];
113
+ const targetSize = targetBoundingClientRect[distance];
114
+ const targetMiddle = targetPosition + targetSize / 2;
115
+ const targetTransform = getTransform(targetElement)[axis];
116
+ const targetMiddleWithoutTransform = targetMiddle - targetTransform;
117
+ if (currentPosition > targetMiddleWithoutTransform) {
118
+ return { height: 0, width: 0 };
119
+ }
120
+ return translation;
121
+ };
122
+ const updateActualIndexBaseOnTranslation = (translation, siblingIndex, direction, siblings) => {
123
+ const itemsCount = siblings.filter((sibling) => containClass(sibling, DRAGGABLE_CLASS)).length;
124
+ const { distance } = getPropByDirection(direction);
125
+ if (translation[distance] == 0) {
126
+ actualIndex = Math.max(actualIndex, siblingIndex);
127
+ }
128
+ else {
129
+ actualIndex = Math.min(actualIndex, siblingIndex - 1);
130
+ }
131
+ actualIndex = Math.min(actualIndex, itemsCount);
132
+ };
133
+ const startDragEventOverElement = (element, translation) => {
134
+ const { width, height } = translation;
135
+ moveTranslate(element, height, width);
136
+ };
137
+ const dragEventOverElement = (element, translation) => {
138
+ const { width, height } = translation;
139
+ moveTranslate(element, height, width);
140
+ setTranistion(element, animationDuration, draggableTargetTimingFunction);
141
+ };
142
+ // #region Drop events
143
+ const emitDroppingEventToSiblings = (draggedElement, event, translation, initialWindowScroll, droppableConfig, positionOnSourceDroppable) => {
144
+ const { droppable, scroll, config } = droppableConfig;
145
+ const [siblings, positionOnDroppable] = getSiblings(draggedElement, droppable);
146
+ const allSiblings = siblings.toReversed();
147
+ const realPositionOnDroppable = (positionOnDroppable === -1) ? allSiblings.length : positionOnDroppable;
148
+ allSiblings.splice(realPositionOnDroppable, 0, draggedElement);
149
+ const [previousElement, nextElement, targetIndex] = getPreviousAndNextElement(draggedElement, positionOnDroppable, allSiblings, droppable);
150
+ translation = getTranslationByDragging(draggedElement, event, config.direction, parent, previousElement, nextElement);
151
+ const windowScroll = getWindowScroll();
152
+ const draggableTranslation = getTranslateBeforeDropping(config.direction, allSiblings, positionOnDroppable, targetIndex, windowScroll, scroll, initialWindowScroll, droppable, draggedElement);
153
+ if (siblings.length == 0) {
154
+ startDropEventOverElement(undefined, translation, draggedElement, draggableTranslation);
155
+ }
156
+ for (const [index, sibling] of siblings.toReversed().entries()) {
157
+ let newTranslation = translation;
158
+ if (targetIndex - 1 >= index) {
159
+ newTranslation = { height: 0, width: 0 };
160
+ }
161
+ if (event === START_DROP_EVENT &&
162
+ !containClass(sibling, TEMP_CHILD_CLASS)) {
163
+ startDropEventOverElement(sibling, newTranslation, draggedElement, draggableTranslation);
164
+ }
165
+ }
166
+ dropEventOverElement(targetIndex, draggedElement, config, droppable, positionOnSourceDroppable);
167
+ };
168
+ const getPreviousAndNextElement = (draggedElement, elementPosition, allSiblings, droppable) => {
169
+ const isOutside = draggableIsOutside(draggedElement, droppable);
170
+ const targetIndex = isOutside ? elementPosition : actualIndex;
171
+ const getPreviousAndNextElementIndex = () => {
172
+ if (elementPosition < targetIndex) {
173
+ return [targetIndex, targetIndex + 1];
174
+ }
175
+ else if (elementPosition > targetIndex) {
176
+ return [targetIndex - 1, targetIndex];
177
+ }
178
+ else {
179
+ return [targetIndex - 1, targetIndex + 1];
180
+ }
181
+ };
182
+ const [previousIndex, nextIndex] = getPreviousAndNextElementIndex();
183
+ const previousElement = allSiblings[previousIndex] ?? null;
184
+ const nextElement = allSiblings[nextIndex] ?? null;
185
+ return [
186
+ previousElement,
187
+ nextElement,
188
+ targetIndex,
189
+ ];
190
+ };
191
+ const startDropEventOverElement = (targetElement, translation, element, sourceElementTranlation) => {
192
+ moveTranslate(targetElement, translation.height, translation.width);
193
+ moveTranslate(element, sourceElementTranlation.height, sourceElementTranlation.width);
194
+ };
195
+ const dropEventOverElement = (targetIndex, element, config, droppable, positionOnSourceDroppable) => {
196
+ const { onInsertEvent, onDragEnd } = config;
197
+ addClass(element, DROPPING_CLASS);
198
+ removeStytes(element, parent, droppable, () => {
199
+ removeClass(element, DROPPING_CLASS);
200
+ if (positionOnSourceDroppable != undefined) {
201
+ const value = onRemoveAtEvent(positionOnSourceDroppable, true);
202
+ if (value != undefined) {
203
+ onInsertEvent(targetIndex, value, true);
204
+ onDragEnd({ value, index: targetIndex });
205
+ }
206
+ manageDraggingClass(element);
207
+ clearExcessTranslateStyles();
208
+ }
209
+ });
210
+ };
211
+ const clearExcessTranslateStyles = () => {
212
+ if (!droppableGroupClass) {
213
+ return;
214
+ }
215
+ var children = document.querySelectorAll(`${getClassesSelector(droppableGroupClass)} > .${DRAGGABLE_CLASS}`);
216
+ for (const element of children) {
217
+ removeTranslateWhitoutTransition(element);
218
+ }
219
+ };
220
+ const manageDraggingClass = (element) => {
221
+ setTimeout(() => {
222
+ removeClass(element, draggingClass);
223
+ }, DELAY_TIME_TO_SWAP);
224
+ };
225
+ const removeStytes = (element, parent, droppable, func) => {
226
+ setTimeout(() => {
227
+ func && func();
228
+ removeTempChildOnDroppables(parent, droppable);
229
+ reduceTempchildSize(droppable);
230
+ removeElementDraggingStyles(element);
231
+ removeTranslateFromSiblings(element, parent);
232
+ removeTranslateFromSiblings(element, droppable);
233
+ }, animationDuration);
234
+ };
235
+ const removeTempChildOnDroppables = (parent, droppable) => {
236
+ if (parent.isSameNode(droppable)) {
237
+ removeTempChild(parent, animationDuration);
238
+ }
239
+ else {
240
+ removeTempChild(parent, animationDuration, true);
241
+ removeTempChild(droppable, animationDuration);
242
+ }
243
+ };
244
+ const reduceTempchildSize = (droppable) => {
245
+ if (parent.isSameNode(droppable)) {
246
+ return;
247
+ }
248
+ var [lastChildren] = parent.querySelectorAll(`.${TEMP_CHILD_CLASS}`);
249
+ if (!lastChildren) {
250
+ return;
251
+ }
252
+ const { distance } = getPropByDirection(direction);
253
+ if (IsHTMLElement(lastChildren)) {
254
+ lastChildren.style[distance] = "0px";
255
+ }
256
+ };
257
+ const removeTranslateFromSiblings = (element, parent) => {
258
+ const [siblings] = getSiblings(element, parent);
259
+ for (const sibling of [...siblings, element]) {
260
+ removeTranslateWhitoutTransition(sibling);
261
+ }
262
+ };
263
+ const removeTranslateWhitoutTransition = (element) => {
264
+ if (IsHTMLElement(element)) {
265
+ element.style.transition = "";
266
+ element.style.transform = "";
267
+ }
268
+ };
269
+ const removeElementDraggingStyles = (element) => {
270
+ endDraggingAction();
271
+ toggleDraggingClass(element, false);
272
+ element.style.transform = "";
273
+ element.style.transition = "";
274
+ element.style.top = "";
275
+ element.style.left = "";
276
+ setCustomFixedSize(element, {
277
+ fixedHeight: '',
278
+ fixedWidth: ''
279
+ });
280
+ };
281
+ const toogleHandlerDraggingClass = (force, element) => {
282
+ const handlerElement = element.querySelector(handlerSelector);
283
+ toggleClass(document.body, GRABBING_CLASS, force);
284
+ if (handlerElement) {
285
+ toggleClass(handlerElement, DRAGGING_HANDLER_CLASS, force);
286
+ }
287
+ else {
288
+ toggleClass(element, DRAGGING_HANDLER_CLASS, force);
289
+ }
290
+ };
291
+ const toggleDraggingClass = (element, force) => {
292
+ toggleClass(element, DRAGGING_CLASS, force);
293
+ toogleHandlerDraggingClass(force, element);
294
+ handlerPublisher.toggleGrabClass(!force);
295
+ };
296
+ return [
297
+ emitEventToSiblings,
298
+ emitRemoveEventToSiblings,
299
+ emitInsertEventToSiblings,
300
+ emitFinishRemoveEventToSiblings,
301
+ toggleDraggingClass,
302
+ ];
303
+ }
304
+ const childrenMutationFilter = (mutation) => {
305
+ const addedNodes = mutation.addedNodes.values().filter((element) => !isTempElement(element)).toArray();
306
+ return addedNodes.length > 0;
307
+ };
308
+ const onFinishInsertElement = (targetIndex, droppable, config) => {
309
+ const { insertingFromClass, animationDuration } = config;
310
+ const observer = observeMutation(() => {
311
+ const siblings = getParentDraggableChildren(droppable);
312
+ const newElement = siblings[targetIndex];
313
+ addClass(newElement, insertingFromClass);
314
+ addClass(newElement, DISABLE_TRANSITION);
315
+ setTimeout(() => {
316
+ removeClass(newElement, DISABLE_TRANSITION);
317
+ removeClass(newElement, insertingFromClass);
318
+ observer.disconnect();
319
+ }, animationDuration);
320
+ }, droppable, {
321
+ childList: true,
322
+ }, childrenMutationFilter);
323
+ };
324
+ export const insertToListEmpty = (config, droppable, targetIndex, value) => {
325
+ if (!droppable) {
326
+ return;
327
+ }
328
+ const { onInsertEvent, delayBeforeInsert } = config;
329
+ setTimeout(() => {
330
+ onInsertEvent(targetIndex, value);
331
+ onFinishInsertElement(targetIndex, droppable, config);
332
+ }, delayBeforeInsert);
333
+ };
@@ -0,0 +1,9 @@
1
+ export const START_DRAG_EVENT = "startDrag";
2
+ export const DRAG_EVENT = "drag";
3
+ export const START_DROP_EVENT = "startDrop";
4
+ export const DROP_EVENT = "drop";
5
+ export const TEMP_CHILD_CLASS = "temp-child";
6
+ export const draggableTargetTimingFunction = "cubic-bezier(0.2, 0, 0, 1)";
7
+ export const IsDropEvent = (event) => {
8
+ return event === DROP_EVENT || event === START_DROP_EVENT;
9
+ };
@@ -0,0 +1,11 @@
1
+ export const observeMutation = (callback, element, options, mutationFilter = () => true) => {
2
+ const observe = new MutationObserver((mutations) => {
3
+ mutations = mutations.filter(mutationFilter);
4
+ if (mutations.length > 0) {
5
+ const mutation = mutations[0];
6
+ callback(observe, mutation);
7
+ }
8
+ });
9
+ observe.observe(element, options);
10
+ return observe;
11
+ };
@@ -1,5 +1,4 @@
1
- import { ElementScroll } from 'index';
2
- import { Direction } from '..';
3
-
1
+ import { ElementScroll } from "index";
2
+ import { Direction } from "..";
4
3
  export declare const scrollByDirection: (element: HTMLElement, direction: Direction, scrollAmount: number) => void;
5
4
  export declare const scrollPercent: (direction: Direction, droppable: HTMLElement, droppableScroll: ElementScroll) => number;
@@ -0,0 +1,17 @@
1
+ import { getPropByDirection } from "./GetStyles";
2
+ export const scrollByDirection = (element, direction, scrollAmount) => {
3
+ if (scrollAmount == 0) {
4
+ return;
5
+ }
6
+ if (direction === "vertical") {
7
+ element.scrollBy(0, scrollAmount);
8
+ }
9
+ else {
10
+ element.scrollBy(scrollAmount, 0);
11
+ }
12
+ };
13
+ export const scrollPercent = (direction, droppable, droppableScroll) => {
14
+ const { scrollDistance, clientDistance, scrollElement } = getPropByDirection(direction);
15
+ return (droppableScroll[scrollElement] /
16
+ (droppable[scrollDistance] - droppable[clientDistance]));
17
+ };
@@ -1,5 +1,4 @@
1
- import { DroppableConfig } from '../configHandler';
2
-
1
+ import { DroppableConfig } from "../configHandler";
3
2
  export declare const isTempElement: (element: Node) => boolean;
4
3
  export declare const addTempChild: <T>(draggedElement: HTMLElement | undefined, parent: Element, ifStartDragging: boolean, droppableConfig?: DroppableConfig<T>, addingAnimationDuration?: number) => void;
5
4
  export declare const addTempChildOnInsert: <T>(draggedElement: HTMLElement | undefined, ifStartDragging: boolean, droppableConfig?: DroppableConfig<T>) => void;
@@ -0,0 +1,146 @@
1
+ import { HORIZONTAL, VERTICAL } from "..";
2
+ import { getPropByDirection } from "./GetStyles";
3
+ import { getGapPixels } from "./ParseStyles";
4
+ import { setSizeStyles, setTranistion } from "./SetStyles";
5
+ import { observeMutation } from "./observer";
6
+ import getTranslationByDragging from "./translate/GetTranslationByDraggingAndEvent";
7
+ import { scrollPercent } from "./scroll";
8
+ import { TEMP_CHILD_CLASS } from ".";
9
+ import { addClass, getClassesSelector } from "./dom/classList";
10
+ import { IsHTMLElement } from "./touchDevice";
11
+ const START_DRAG_EVENT = "startDrag";
12
+ const timingFunction = "cubic-bezier(0.2, 0, 0, 1)";
13
+ const DELAY_TIME = 50;
14
+ export const isTempElement = (element) => {
15
+ if (!IsHTMLElement(element)) {
16
+ return false;
17
+ }
18
+ return element.classList.contains(TEMP_CHILD_CLASS);
19
+ };
20
+ const getDistance = (droppable, draggedElement, direction) => {
21
+ let distances = getTranslationByDragging(draggedElement, START_DRAG_EVENT, direction, droppable);
22
+ const gap = getGapPixels(droppable, direction);
23
+ const { distance } = getPropByDirection(direction);
24
+ distances[distance] -= gap;
25
+ const [large, largeDistance] = getlarge(direction, draggedElement);
26
+ distances[largeDistance] = large;
27
+ return distances;
28
+ };
29
+ const getlarge = (direction, draggedElement) => {
30
+ const largeDirection = direction == HORIZONTAL ? VERTICAL : HORIZONTAL;
31
+ const { distance, getRect } = getPropByDirection(largeDirection);
32
+ return [
33
+ getRect(draggedElement)[distance],
34
+ distance,
35
+ ];
36
+ };
37
+ const setSizes = (element, height, width) => {
38
+ setSizeStyles(element, height, width);
39
+ element.style.minWidth = `${width}px`;
40
+ };
41
+ const updateChildAfterCreated = (child, droppable, distances) => {
42
+ return (observer) => {
43
+ if (!droppable.contains(child)) {
44
+ return;
45
+ }
46
+ setSizes(child, distances.height, distances.width);
47
+ observer.disconnect();
48
+ };
49
+ };
50
+ const fixScrollInitialChange = (droppableConfig, ifStartDragging) => {
51
+ if (!ifStartDragging) {
52
+ return;
53
+ }
54
+ const { droppable, config, scroll } = droppableConfig;
55
+ const { direction } = config;
56
+ const scrollCompleted = scrollPercent(config.direction, droppable, scroll) > 0.99;
57
+ const { scrollDistance, clientDistance, scrollElement } = getPropByDirection(direction);
58
+ if (scrollCompleted) {
59
+ droppable[scrollElement] =
60
+ droppable[scrollDistance] - droppable[clientDistance];
61
+ }
62
+ };
63
+ const getTempChild = (draggedElement, ifStartDragging, droppableConfig, addingAnimationDuration) => {
64
+ if (!droppableConfig) {
65
+ return;
66
+ }
67
+ const { droppable, config } = droppableConfig;
68
+ const { direction, animationDuration } = config;
69
+ fixScrollInitialChange(droppableConfig, ifStartDragging);
70
+ if (droppable.querySelector(`.${TEMP_CHILD_CLASS}`) || !draggedElement) {
71
+ return;
72
+ }
73
+ var tempChildTag = draggedElement.tagName == "LI" ? "DIV" : draggedElement.tagName;
74
+ var child = document.createElement(tempChildTag);
75
+ addClass(child, TEMP_CHILD_CLASS);
76
+ setSizes(child, 0, 0);
77
+ const distances = getDistance(droppable, draggedElement, direction);
78
+ setTranistion(child, addingAnimationDuration ?? animationDuration, timingFunction, "width, min-width, height");
79
+ return [child, distances, droppable];
80
+ };
81
+ export const addTempChild = (draggedElement, parent, ifStartDragging, droppableConfig, addingAnimationDuration) => {
82
+ const result = getTempChild(draggedElement, ifStartDragging, droppableConfig, addingAnimationDuration);
83
+ if (!result) {
84
+ return;
85
+ }
86
+ const [child, distances, droppable] = result;
87
+ if (parent.isSameNode(droppable)) {
88
+ setSizes(child, distances.height, distances.width);
89
+ }
90
+ observeMutation(updateChildAfterCreated(child, droppable, distances), droppable, {
91
+ childList: true,
92
+ subtree: true,
93
+ });
94
+ droppable.appendChild(child);
95
+ };
96
+ export const addTempChildOnInsert = (draggedElement, ifStartDragging, droppableConfig) => {
97
+ const result = getTempChild(draggedElement, ifStartDragging, droppableConfig);
98
+ if (!result) {
99
+ return;
100
+ }
101
+ const [child, distances, droppable] = result;
102
+ droppable.appendChild(child);
103
+ setSizeAfterAppendChild(child, distances);
104
+ };
105
+ const setSizeAfterAppendChild = (child, size) => {
106
+ return requestAnimationFrame(() => {
107
+ setSizes(child, size.height, size.width);
108
+ requestAnimationFrame(() => {
109
+ setTranistion(child, 0, timingFunction, "width, min-width, height");
110
+ });
111
+ });
112
+ };
113
+ export const removeTempChildrens = (droppable, parent, droppableGroupClass, animationDuration, draggedElementIsOutside = true) => {
114
+ if (!droppableGroupClass) {
115
+ return;
116
+ }
117
+ var children = document.querySelectorAll(`${getClassesSelector(droppableGroupClass)} > .${TEMP_CHILD_CLASS}`);
118
+ children.forEach((tempChild) => {
119
+ const childParent = tempChild.parentElement;
120
+ if ((childParent?.isSameNode(parent) || !draggedElementIsOutside && childParent?.isSameNode(droppable))) {
121
+ return;
122
+ }
123
+ const tempChildElement = tempChild;
124
+ setSizes(tempChildElement, 0, 0);
125
+ setTimeout(() => {
126
+ tempChild.parentNode?.removeChild(tempChild);
127
+ }, animationDuration + DELAY_TIME);
128
+ });
129
+ };
130
+ export const removeTempChild = (parent, animationDuration, isAnimated = false) => {
131
+ var lastChildren = parent.querySelectorAll(`.${TEMP_CHILD_CLASS}`);
132
+ lastChildren.forEach((lastChild) => {
133
+ const tempChildElement = lastChild;
134
+ if (isAnimated) {
135
+ setSizes(tempChildElement, 0, 0);
136
+ setTimeout(() => {
137
+ if (parent.contains(tempChildElement)) {
138
+ parent.removeChild(tempChildElement);
139
+ }
140
+ }, animationDuration + DELAY_TIME);
141
+ }
142
+ else {
143
+ parent.removeChild(lastChild);
144
+ }
145
+ });
146
+ };
@@ -0,0 +1,3 @@
1
+ export const isTouchEvent = (event) => window.TouchEvent && event instanceof TouchEvent;
2
+ export const IsHTMLElement = (element) => element instanceof HTMLElement;
3
+ export const IsMouseEvent = (event) => event instanceof MouseEvent;
@@ -1,6 +1,5 @@
1
- import { Direction } from '../..';
2
- import { Translate, WindowScroll } from '../../../../index';
3
-
1
+ import { Direction } from "../..";
2
+ import { Translate, WindowScroll } from "../../../../index";
4
3
  export default function getTranslateBeforeDropping(direction: Direction, siblings: Element[], sourceIndex: number, targetIndex: number, scroll: WindowScroll, previousScroll: {
5
4
  scrollLeft: number;
6
5
  scrollTop: number;