fluid-dnd 2.3.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.
Files changed (71) hide show
  1. package/README.md +14 -15
  2. package/dist/{HandlerPublisher-BNn5KECH.cjs → HandlerPublisher-1MmlNkG3.cjs} +1 -1
  3. package/dist/{HandlerPublisher-xM3zyGAn.js → HandlerPublisher-DBjPMiyO.js} +1 -1
  4. package/dist/core/{configHandler.d.ts → config/configHandler.d.ts} +2 -2
  5. package/dist/core/{configHandler.js → config/configHandler.js} +7 -8
  6. package/dist/core/{utils → config}/droppableConfigurator.d.ts +5 -4
  7. package/dist/core/{utils → config}/droppableConfigurator.js +42 -29
  8. package/dist/core/dragAndDrop.d.ts +3 -3
  9. package/dist/core/dragAndDrop.js +53 -9
  10. package/dist/core/events/changeDraggableStyles.d.ts +4 -0
  11. package/dist/core/events/changeDraggableStyles.js +38 -0
  12. package/dist/core/events/dragAndDrop/dragAndDrop.d.ts +9 -0
  13. package/dist/core/events/dragAndDrop/dragAndDrop.js +202 -0
  14. package/dist/core/{utils/translate/GetTranslateBeforeDropping.d.ts → events/dragAndDrop/getTranslateBeforeDropping.d.ts} +2 -2
  15. package/dist/core/{utils/translate/GetTranslateBeforeDropping.js → events/dragAndDrop/getTranslateBeforeDropping.js} +33 -41
  16. package/dist/core/{utils/translate/GetTranslationByDraggingAndEvent.d.ts → events/dragAndDrop/getTranslationByDraggingAndEvent.d.ts} +2 -2
  17. package/dist/core/{utils/translate/GetTranslationByDraggingAndEvent.js → events/dragAndDrop/getTranslationByDraggingAndEvent.js} +12 -13
  18. package/dist/core/events/insert.d.ts +5 -0
  19. package/dist/core/events/insert.js +74 -0
  20. package/dist/core/events/remove.d.ts +4 -0
  21. package/dist/core/events/remove.js +66 -0
  22. package/dist/core/index.d.ts +6 -0
  23. package/dist/core/index.js +7 -0
  24. package/dist/core/{utils/scroll.d.ts → positioning/autoScroll.d.ts} +0 -2
  25. package/dist/core/{utils/scroll.js → positioning/autoScroll.js} +6 -9
  26. package/dist/core/{utils/SetTransform.d.ts → positioning/usePositioning.d.ts} +1 -1
  27. package/dist/core/{utils/SetTransform.js → positioning/usePositioning.js} +24 -27
  28. package/dist/core/{utils/tempChildren.d.ts → tempChildren.d.ts} +1 -2
  29. package/dist/core/{utils/tempChildren.js → tempChildren.js} +44 -47
  30. package/dist/core/useDraggable.js +50 -57
  31. package/dist/core/useDroppable.d.ts +2 -2
  32. package/dist/core/useDroppable.js +10 -16
  33. package/dist/core/utils/GetStyles.d.ts +24 -3
  34. package/dist/core/utils/GetStyles.js +53 -5
  35. package/dist/core/utils/ParseStyles.d.ts +3 -2
  36. package/dist/core/utils/ParseStyles.js +12 -12
  37. package/dist/core/utils/SetStyles.d.ts +6 -5
  38. package/dist/core/utils/SetStyles.js +30 -25
  39. package/dist/core/utils/index.d.ts +5 -1
  40. package/dist/core/utils/index.js +7 -6
  41. package/dist/core/utils/observer.d.ts +1 -0
  42. package/dist/core/utils/observer.js +8 -0
  43. package/dist/fluid-dnd-logo.png +0 -0
  44. package/dist/index-BdOAK6C7.cjs +1 -0
  45. package/dist/index-HczUoMBK.js +1131 -0
  46. package/dist/index.cjs +1 -1
  47. package/dist/index.mjs +2 -2
  48. package/dist/insert-Dd8savAS.js +51 -0
  49. package/dist/insert-T4Y6rI_j.cjs +1 -0
  50. package/dist/react/index.cjs +1 -1
  51. package/dist/react/index.mjs +32 -37
  52. package/dist/react/utils/ReactLilstConfig.d.ts +2 -2
  53. package/dist/react/utils/ReactLilstConfig.js +9 -18
  54. package/dist/remove-BC4sUY1o.cjs +1 -0
  55. package/dist/remove-M01dmTvo.js +48 -0
  56. package/dist/svelte/index.cjs +1 -1
  57. package/dist/svelte/index.mjs +18 -16
  58. package/dist/svelte/utils/SvelteListCondig.js +3 -2
  59. package/dist/vue/index.cjs +1 -1
  60. package/dist/vue/index.mjs +26 -24
  61. package/dist/vue/utils/VueListCondig.d.ts +3 -3
  62. package/dist/vue/utils/VueListCondig.js +4 -6
  63. package/package.json +1 -1
  64. package/dist/core/utils/config.d.ts +0 -5
  65. package/dist/core/utils/config.js +0 -57
  66. package/dist/core/utils/events/emitEvents.d.ts +0 -11
  67. package/dist/core/utils/events/emitEvents.js +0 -333
  68. package/dist/index-BYT3HBbe.cjs +0 -1
  69. package/dist/index-m7C-XuaH.js +0 -1275
  70. /package/dist/core/utils/{touchDevice.d.ts → typesCheckers.d.ts} +0 -0
  71. /package/dist/core/utils/{touchDevice.js → typesCheckers.js} +0 -0
@@ -1,21 +1,18 @@
1
- import { HORIZONTAL, VERTICAL } from "../..";
2
- import { getPropByDirection, getValueFromProperty, } from "../GetStyles";
3
- import { gapAndDisplayInformation, getBeforeStyles } from "../ParseStyles";
1
+ import { HORIZONTAL, VERTICAL } from '../..';
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 { borderBeforeWidth, paddingBefore, axis, getRect } = getPropByDirection(direction);
6
- const borderBeforeWidthDroppable = getValueFromProperty(droppable, borderBeforeWidth);
5
+ const { paddingBefore } = getPropByDirection(direction);
6
+ const borderBeforeWidthDroppable = getBorderBeforeWidthValue(direction, droppable);
7
7
  const paddingBeforeDroppable = getValueFromProperty(droppable, paddingBefore);
8
- const axisValue = getRect(droppable)[axis];
8
+ const axisValue = getAxisValue(direction, getRect(droppable));
9
9
  return borderBeforeWidthDroppable + paddingBeforeDroppable + axisValue;
10
10
  };
11
11
  const getGroupTranslate = (droppable, draggable) => {
12
12
  const [top, left] = getBeforeStyles(draggable);
13
13
  const verticalContentPosition = getContentPosition(VERTICAL, droppable);
14
14
  const horizontalContentPosition = getContentPosition(HORIZONTAL, droppable);
15
- return [
16
- horizontalContentPosition - left,
17
- verticalContentPosition - top
18
- ];
15
+ return [horizontalContentPosition - left, verticalContentPosition - top];
19
16
  };
20
17
  export default function getTranslateBeforeDropping(direction, siblings, sourceIndex, targetIndex, scroll, previousScroll, initialWindowScroll, droppable, draggable) {
21
18
  let height = 0;
@@ -30,14 +27,14 @@ export default function getTranslateBeforeDropping(direction, siblings, sourceIn
30
27
  height += y;
31
28
  width += x;
32
29
  }
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);
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);
37
33
  const spaceBetween = getSpaceBetween(space, beforeSpace, afterSpace, beforeMarginOutside, afterMarginOutside, gap);
34
+ const [scrollElementValue] = getScrollElementValue(direction, droppable);
38
35
  const scrollChange = isGroupDropping
39
- ? droppable[scrollElement]
40
- : getScrollChange(scrollElement, droppable, previousScroll);
36
+ ? scrollElementValue
37
+ : getScrollChange(droppable, previousScroll, direction);
41
38
  const spaceCalc = isDraggedFoward
42
39
  ? spaceBetween - spaceBeforeDraggedElement
43
40
  : spaceBeforeDraggedElement - spaceBetween;
@@ -50,9 +47,9 @@ export default function getTranslateBeforeDropping(direction, siblings, sourceIn
50
47
  }
51
48
  return addScrollToTranslate({ height, width }, direction, scroll, initialWindowScroll, isGroupDropping);
52
49
  }
53
- const getScrollChange = (scrollElement, parentElement, previousScroll) => {
54
- const scrollParent = parentElement[scrollElement];
55
- const previousScrollValue = previousScroll[scrollElement];
50
+ const getScrollChange = (parentElement, previousScroll, direction) => {
51
+ const [scrollParent] = getScrollElementValue(direction, parentElement);
52
+ const [previousScrollValue] = getScrollElementValue(direction, previousScroll);
56
53
  return scrollParent - previousScrollValue;
57
54
  };
58
55
  const getSpaceBetween = (innerSpace, beforeMarginSpace, afterMarginSpace, beforeMarginOutside, afterMarginOutside, gap) => {
@@ -71,23 +68,18 @@ const getElementsRange = (siblings, sourceIndex, targetIndex, draggable) => {
71
68
  if (firstIndex < 0 && draggable) {
72
69
  siblingsBetween = siblings.slice(firstIndex + 1, secondIndex);
73
70
  }
74
- return [
75
- sourceElement,
76
- targetElement,
77
- siblingsBetween,
78
- isDraggedFoward,
79
- ];
71
+ return [sourceElement, targetElement, siblingsBetween, isDraggedFoward];
80
72
  };
81
- const spaceWithMargins = (beforeMargin, afterMargin, distance, siblings, gap, hasGaps) => {
73
+ const spaceWithMargins = (siblings, gap, hasGaps, direction) => {
82
74
  if (siblings.length == 0) {
83
75
  return [0, 0, 0];
84
76
  }
85
- const beforeSpace = getValueFromProperty(siblings[0], beforeMargin);
77
+ const beforeSpace = getAfterMargin(direction, siblings[0]);
86
78
  let afterSpace = 0;
87
79
  let space = -beforeSpace;
88
80
  for (const [index, sibling] of siblings.entries()) {
89
- const siblingSpace = sibling.getBoundingClientRect()[distance];
90
- const siblingBeforeMargin = getValueFromProperty(sibling, beforeMargin);
81
+ const [siblingSpace] = getDistanceValue(direction, getRect(sibling));
82
+ const siblingBeforeMargin = getBeforeMargin(direction, sibling);
91
83
  if (hasGaps) {
92
84
  afterSpace += siblingBeforeMargin;
93
85
  }
@@ -98,32 +90,32 @@ const spaceWithMargins = (beforeMargin, afterMargin, distance, siblings, gap, ha
98
90
  afterSpace = Math.max(afterSpace, siblingBeforeMargin);
99
91
  }
100
92
  space += afterSpace + siblingSpace;
101
- afterSpace = getValueFromProperty(sibling, afterMargin);
93
+ afterSpace = getAfterMargin(direction, sibling);
102
94
  }
103
95
  return [beforeSpace, space, afterSpace];
104
96
  };
105
97
  const addScrollToTranslate = (translate, direction, initialScroll, initialWindowScroll, isGroupDropping) => {
106
- const { scroll, distance } = getPropByDirection(direction);
107
- const actualWindowScroll = window[scroll];
108
- const initialScrollProp = initialScroll[scroll];
98
+ const actualWindowScroll = getScrollValue(direction, window);
99
+ const initialScrollProp = getScrollValue(direction, initialScroll);
109
100
  const scrollChange = isGroupDropping
110
101
  ? 0
111
- : initialScrollProp - 2 * actualWindowScroll + initialWindowScroll[scroll];
102
+ : initialScrollProp - 2 * actualWindowScroll + getScrollValue(direction, initialWindowScroll);
103
+ const [, distance] = getDistanceValue(direction, translate);
112
104
  translate[distance] += scrollChange;
113
105
  return translate;
114
106
  };
115
- const getBeforeAfterMarginBaseOnDraggedDirection = (beforeMarginProp, afterMarginProp, draggedElement, previousElement, isDraggedFoward, hasGaps, isGroupDropping) => {
107
+ const getBeforeAfterMarginBaseOnDraggedDirection = (draggedElement, previousElement, isDraggedFoward, hasGaps, isGroupDropping, direction) => {
116
108
  const previousElementByDirection = isDraggedFoward
117
109
  ? draggedElement.previousElementSibling
118
110
  : previousElement;
119
- return getBeforeAfterMargin(beforeMarginProp, afterMarginProp, previousElementByDirection, draggedElement, hasGaps, isGroupDropping);
111
+ return getBeforeAfterMargin(previousElementByDirection, draggedElement, hasGaps, isGroupDropping, direction);
120
112
  };
121
- const getBeforeAfterMargin = (beforeMarginProp, afterMarginProp, previousElement, nextElement, hasGaps, isGroupDropping) => {
113
+ const getBeforeAfterMargin = (previousElement, nextElement, hasGaps, isGroupDropping, direction) => {
122
114
  if (hasGaps) {
123
115
  return [0, 0, 0];
124
116
  }
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];
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];
129
121
  };
@@ -1,5 +1,5 @@
1
- import { Direction } from "../..";
2
- import { DragAndDropEvent } from "..";
1
+ import { Direction } from '../..';
2
+ import { DragAndDropEvent } from '../../utils';
3
3
  export default function getTranslationByDraggingAndEvent(current: HTMLElement, event: DragAndDropEvent, direction: Direction, droppable: HTMLElement, previousElement?: Element | null, nextElement?: Element | null): {
4
4
  height: number;
5
5
  width: number;
@@ -1,7 +1,7 @@
1
- import { HORIZONTAL } from "../..";
2
- import { DRAG_EVENT } from "..";
3
- import { draggableIsOutside, getPropByDirection, getValueFromProperty, } from "../GetStyles";
4
- import { gapAndDisplayInformation } from "../ParseStyles";
1
+ import { HORIZONTAL } from '../..';
2
+ import { DRAG_EVENT } from '../../utils';
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 { 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];
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, afterMargin);
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, afterMargin) => {
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 = getValueFromProperty(previousElement, afterMargin);
31
+ const previousAfterMargin = getAfterMargin(direction, previousElement);
33
32
  beforeScace = Math.max(previousAfterMargin, currentBeforeMargin);
34
33
  rest = Math.max(rest, previousAfterMargin);
35
34
  }
@@ -0,0 +1,5 @@
1
+ import { CoreConfig } from '../index';
2
+ import HandlerPublisher from '../HandlerPublisher';
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];
5
+ export declare const insertToListEmpty: <T>(config: CoreConfig<T>, droppable: HTMLElement | undefined | null, targetIndex: number, value: T) => void;
@@ -0,0 +1,74 @@
1
+ import { getParentDraggableChildren, getSiblings } from '../utils/GetStyles';
2
+ import getTranslationByDragging from '../events/dragAndDrop/getTranslationByDraggingAndEvent';
3
+ import { addTempChildOnInsert, removeTempChild } from '../tempChildren';
4
+ import { DISABLE_TRANSITION, DRAGGABLE_CLASS } from '../utils/classes';
5
+ import { addClass, containClass, removeClass } from '../utils/dom/classList';
6
+ import { isTempElement, observeMutation } from '../utils/observer';
7
+ import { useChangeDraggableStyles } from './changeDraggableStyles';
8
+ import { removeTranslateWhitoutTransition } from '../utils/SetStyles';
9
+ export default function useInsertEvents(currentConfig, parent, handlerPublisher, endDraggingAction) {
10
+ const { delayBeforeInsert } = currentConfig;
11
+ const [removeElementDraggingStyles, _, dragEventOverElement] = useChangeDraggableStyles(currentConfig, handlerPublisher, endDraggingAction);
12
+ // #region Insert
13
+ const emitInsertEventToSiblings = (targetIndex, draggedElement, droppable, value, droppableConfigurator) => {
14
+ const translation = getTranslationByDragging(draggedElement, 'insert', currentConfig.direction, droppable);
15
+ const { onInsertEvent } = currentConfig;
16
+ const siblings = getParentDraggableChildren(droppable);
17
+ for (const [index, sibling] of siblings.entries()) {
18
+ if (!containClass(sibling, DRAGGABLE_CLASS)) {
19
+ continue;
20
+ }
21
+ if (index >= targetIndex) {
22
+ dragEventOverElement(sibling, translation);
23
+ }
24
+ }
25
+ addTempChildOnInsert(draggedElement, false, droppableConfigurator);
26
+ setTimeout(() => {
27
+ onInsertEvent(targetIndex, value);
28
+ onFinishInsertElement(targetIndex, droppable, currentConfig);
29
+ removeElementDraggingStyles(draggedElement);
30
+ removeTranslateFromSiblings(draggedElement, parent);
31
+ removeTempChild(parent, 0, true);
32
+ }, delayBeforeInsert);
33
+ };
34
+ const removeTranslateFromSiblings = (element, parent) => {
35
+ const [siblings] = getSiblings(element, parent);
36
+ for (const sibling of [...siblings, element]) {
37
+ removeTranslateWhitoutTransition(sibling);
38
+ }
39
+ };
40
+ return [emitInsertEventToSiblings];
41
+ }
42
+ const childrenMutationFilter = (mutation) => {
43
+ const addedNodes = mutation.addedNodes
44
+ .values()
45
+ .filter((element) => !isTempElement(element))
46
+ .toArray();
47
+ return addedNodes.length > 0;
48
+ };
49
+ const onFinishInsertElement = (targetIndex, droppable, config) => {
50
+ const { insertingFromClass, animationDuration } = config;
51
+ const observer = observeMutation(() => {
52
+ const siblings = getParentDraggableChildren(droppable);
53
+ const newElement = siblings[targetIndex];
54
+ addClass(newElement, insertingFromClass);
55
+ addClass(newElement, DISABLE_TRANSITION);
56
+ setTimeout(() => {
57
+ removeClass(newElement, DISABLE_TRANSITION);
58
+ removeClass(newElement, insertingFromClass);
59
+ observer.disconnect();
60
+ }, animationDuration);
61
+ }, droppable, {
62
+ childList: true
63
+ }, childrenMutationFilter);
64
+ };
65
+ export const insertToListEmpty = (config, droppable, targetIndex, value) => {
66
+ if (!droppable) {
67
+ return;
68
+ }
69
+ const { onInsertEvent, delayBeforeInsert } = config;
70
+ setTimeout(() => {
71
+ onInsertEvent(targetIndex, value);
72
+ onFinishInsertElement(targetIndex, droppable, config);
73
+ }, delayBeforeInsert);
74
+ };
@@ -0,0 +1,4 @@
1
+ import { CoreConfig, DraggingState } from '..';
2
+ import { DroppableConfig } from '../config/configHandler';
3
+ import HandlerPublisher from '@/core/HandlerPublisher';
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];
@@ -0,0 +1,66 @@
1
+ import { getSiblings } from '../utils/GetStyles';
2
+ import { moveTranslate, removeTranslateWhitoutTransition, setTranistion } from '../utils/SetStyles';
3
+ import { DraggingState } from '..';
4
+ import getTranslationByDragging from './dragAndDrop/getTranslationByDraggingAndEvent';
5
+ import { addTempChild, removeTempChild } from '../tempChildren';
6
+ import { useChangeDraggableStyles } from './changeDraggableStyles';
7
+ import { addClass, removeClass } from '../utils/dom/classList';
8
+ import { draggableTargetTimingFunction } from '../utils';
9
+ export default function useRemoveEvents(currentConfig, parent, handlerPublisher, endDraggingAction) {
10
+ const { animationDuration } = currentConfig;
11
+ const [removeElementDraggingStyles] = useChangeDraggableStyles(currentConfig, handlerPublisher, endDraggingAction);
12
+ const emitRemoveEventToSiblings = (targetIndex, draggedElement, droppableConfig, onFinishRemoveEvent) => {
13
+ if (!droppableConfig || !droppableConfig.droppable || !droppableConfig.config) {
14
+ return;
15
+ }
16
+ const { droppable, config } = droppableConfig;
17
+ let [siblings] = getSiblings(draggedElement, droppable);
18
+ siblings = [draggedElement, ...siblings].toReversed();
19
+ const translation = getTranslationByDragging(draggedElement, 'remove', config.direction, droppable);
20
+ for (const [index, sibling] of siblings.entries()) {
21
+ if (index >= targetIndex) {
22
+ moveTranslate(sibling, translation);
23
+ setTimeout(() => {
24
+ onFinishRemoveEvent(sibling);
25
+ }, animationDuration);
26
+ }
27
+ }
28
+ };
29
+ const emitFinishRemoveEventToSiblings = (draggedElement) => {
30
+ removeTempChild(parent, animationDuration, true);
31
+ setTimeout(() => {
32
+ removeElementDraggingStyles(draggedElement);
33
+ removeTranslateFromSiblings(draggedElement, parent);
34
+ }, animationDuration);
35
+ };
36
+ const removeTranslateFromSiblings = (element, parent) => {
37
+ const [siblings] = getSiblings(element, parent);
38
+ for (const sibling of [...siblings, element]) {
39
+ removeTranslateWhitoutTransition(sibling);
40
+ }
41
+ };
42
+ const removeAt = (index, targetIndex, draggableElement, draggingState, config) => {
43
+ const { removingClass, delayBeforeRemove } = currentConfig;
44
+ if (targetIndex == index) {
45
+ addClass(draggableElement, removingClass);
46
+ setTimeout(() => {
47
+ removeAfterRemovingClass(index, targetIndex, draggableElement, draggingState, config);
48
+ }, delayBeforeRemove);
49
+ }
50
+ };
51
+ const removeAfterRemovingClass = (index, targetIndex, draggableElement, draggingState, config) => {
52
+ const { removingClass, onRemoveAtEvent } = currentConfig;
53
+ removeClass(draggableElement, removingClass);
54
+ addTempChild(draggableElement, parent, draggingState == DraggingState.START_DRAGGING, config);
55
+ emitRemoveEventToSiblings(targetIndex, draggableElement, config, (sibling) => {
56
+ removeDraggingStyles(sibling);
57
+ emitFinishRemoveEventToSiblings(draggableElement);
58
+ });
59
+ onRemoveAtEvent(index, true);
60
+ };
61
+ const removeDraggingStyles = (element) => {
62
+ setTranistion(element, animationDuration, draggableTargetTimingFunction);
63
+ moveTranslate(element);
64
+ };
65
+ return [removeAt];
66
+ }
@@ -206,3 +206,9 @@ export type CoreConfig<T> = {
206
206
  */
207
207
  coordinateTransform: CoordinateMap[];
208
208
  };
209
+ export declare enum DraggingState {
210
+ NOT_DRAGGING = 0,
211
+ START_DRAGGING = 1,
212
+ DRAGING = 2,
213
+ END_DRAGGING = 3
214
+ }
@@ -1,2 +1,9 @@
1
1
  export const HORIZONTAL = 'horizontal';
2
2
  export const VERTICAL = 'vertical';
3
+ export var DraggingState;
4
+ (function (DraggingState) {
5
+ DraggingState[DraggingState["NOT_DRAGGING"] = 0] = "NOT_DRAGGING";
6
+ DraggingState[DraggingState["START_DRAGGING"] = 1] = "START_DRAGGING";
7
+ DraggingState[DraggingState["DRAGING"] = 2] = "DRAGING";
8
+ DraggingState[DraggingState["END_DRAGGING"] = 3] = "END_DRAGGING";
9
+ })(DraggingState || (DraggingState = {}));
@@ -1,6 +1,4 @@
1
- import { ElementScroll } from 'index';
2
1
  import { Coordinate, Direction } from '..';
3
- export declare const scrollPercent: (direction: Direction, droppable: HTMLElement, droppableScroll: ElementScroll) => number;
4
2
  export declare const useScroll: (draggedElement: HTMLElement) => readonly [(direction: Direction, parent: HTMLElement, position: {
5
3
  top: number;
6
4
  left: number;
@@ -1,4 +1,4 @@
1
- import { draggableIsCompleteOutside, getPropByDirection } from './GetStyles';
1
+ import { draggableIsCompleteOutside, getAxisValue, getBefore, getDistanceValue, getRect } from '../utils/GetStyles';
2
2
  const scrollByDirection = (element, direction, scrollAmount) => {
3
3
  if (scrollAmount == 0) {
4
4
  return;
@@ -10,19 +10,16 @@ const scrollByDirection = (element, direction, scrollAmount) => {
10
10
  element.scrollBy(scrollAmount, 0);
11
11
  }
12
12
  };
13
- export const scrollPercent = (direction, droppable, droppableScroll) => {
14
- const { scrollDistance, clientDistance, scrollElement } = getPropByDirection(direction);
15
- return droppableScroll[scrollElement] / (droppable[scrollDistance] - droppable[clientDistance]);
16
- };
17
13
  export const useScroll = (draggedElement) => {
18
14
  let lastScrollAmount = 0.5;
19
15
  const minScrollAmountDiff = 0.03;
20
16
  const updateScrollByPosition = (direction, parent, position, translate) => {
21
- const { before, distance, axis, getRect } = getPropByDirection(direction);
22
- const distanceValue = getRect(draggedElement)[distance];
17
+ const [distanceValue] = getDistanceValue(direction, getRect(draggedElement));
23
18
  const parentBoundingClientRect = getRect(parent);
24
- const positionInsideParent = position[before] - parentBoundingClientRect[before] + translate[axis];
25
- const parentDistance = parentBoundingClientRect[distance];
19
+ const positionInsideParent = getBefore(direction, position) -
20
+ getBefore(direction, parentBoundingClientRect) +
21
+ getAxisValue(direction, translate);
22
+ const [parentDistance] = getDistanceValue(direction, parentBoundingClientRect);
26
23
  const totalDistance = parentDistance - distanceValue;
27
24
  const relativePosition = positionInsideParent / totalDistance;
28
25
  const relativeDistanceValue = distanceValue / totalDistance;
@@ -1,6 +1,6 @@
1
1
  import { DragMouseTouchEvent, TransformEvent } from '../../../index';
2
2
  import { CoordinateMap, Direction } from '..';
3
- export declare const useTransform: (draggedElement: HTMLElement, coordinateTransforms: CoordinateMap[]) => readonly [(element: HTMLElement, parent: HTMLElement, pagePosition: {
3
+ export declare const usePositioning: (draggedElement: HTMLElement, coordinateTransforms: CoordinateMap[]) => readonly [(element: HTMLElement, parent: HTMLElement, pagePosition: {
4
4
  pageX: number;
5
5
  pageY: number;
6
6
  }, direction?: Direction) => void, (event: DragMouseTouchEvent, element: HTMLElement) => void];
@@ -1,9 +1,9 @@
1
- import { getNearestFixedParentPosition, getPropByDirection, getValueFromProperty } from './GetStyles';
1
+ import { getAxisValue, getBefore, getBeforeMarginValue, getBorderBeforeWidthValue, getDistanceValue, getInnerDistance, getNearestFixedParentPosition, getOffsetValue, getPageValue, getPropByDirection, getRect, getScrollValue, isSameNode } from '../utils/GetStyles';
2
2
  import { HORIZONTAL, VERTICAL } from '..';
3
- import { useScroll } from './scroll';
4
- import { HANDLER_CLASS, DRAGGING_CLASS } from './classes';
5
- import { containClass } from './dom/classList';
6
- export const useTransform = (draggedElement, coordinateTransforms) => {
3
+ import { useScroll } from './autoScroll';
4
+ import { HANDLER_CLASS, DRAGGING_CLASS } from '../utils/classes';
5
+ import { containClass } from '../utils/dom/classList';
6
+ export const usePositioning = (draggedElement, coordinateTransforms) => {
7
7
  let currentOffset = { offsetX: 0, offsetY: 0 };
8
8
  let position = { top: 0, left: 0 };
9
9
  let translate = { x: 0, y: 0 };
@@ -17,19 +17,18 @@ export const useTransform = (draggedElement, coordinateTransforms) => {
17
17
  };
18
18
  const setTransform = (element, parent, pagePosition, direction) => {
19
19
  const getTranslateWihtDirection = (translateDirection) => {
20
- const { beforeMargin, borderBeforeWidth, before, offset, scroll, page, inner, distance, axis, getRect } = getPropByDirection(translateDirection);
21
- const pageValue = pagePosition[page];
22
- const scrollValue = window[scroll];
23
- const innerDistance = window[inner];
24
- const distanceValue = getRect(element)[distance];
25
- const border = getValueFromProperty(element, borderBeforeWidth);
26
- const margin = getValueFromProperty(element, beforeMargin);
27
- const elementPosittion = pageValue - currentOffset[offset];
20
+ const pageValue = getPageValue(translateDirection, pagePosition);
21
+ const scrollValue = getScrollValue(translateDirection, window);
22
+ const innerDistance = getInnerDistance(translateDirection, window);
23
+ const [distanceValue] = getDistanceValue(translateDirection, getRect(element));
24
+ const border = getBorderBeforeWidthValue(translateDirection, element);
25
+ const margin = getBeforeMarginValue(translateDirection, element);
26
+ const elementPosittion = pageValue - getOffsetValue(translateDirection, currentOffset);
28
27
  const beforefixecParentValue = getNearestFixedParentPosition(element, translateDirection);
29
28
  if (elementPosittion >= scrollValue - distanceValue / 2 &&
30
29
  elementPosittion <= scrollValue + innerDistance) {
31
30
  const newTranslate = elementPosittion -
32
- position[before] -
31
+ getBefore(translateDirection, position) -
33
32
  border -
34
33
  margin -
35
34
  scrollValue -
@@ -37,7 +36,7 @@ export const useTransform = (draggedElement, coordinateTransforms) => {
37
36
  updateScroll(translateDirection);
38
37
  return newTranslate;
39
38
  }
40
- const defaultTransalation = translate[axis];
39
+ const defaultTransalation = getAxisValue(translateDirection, translate);
41
40
  return defaultTransalation;
42
41
  };
43
42
  const updateScroll = (translateDirection) => {
@@ -72,16 +71,15 @@ export const useTransform = (draggedElement, coordinateTransforms) => {
72
71
  return [setTransform, updateTransformState];
73
72
  };
74
73
  const getOffsetWithDraggable = (direction, element, draggable) => {
75
- const { borderBeforeWidth, before, getRect } = getPropByDirection(direction);
76
- return (getRect(element)[before] -
77
- getRect(draggable)[before] -
78
- getValueFromProperty(draggable, borderBeforeWidth));
74
+ return (getBefore(direction, getRect(element)) -
75
+ getBefore(direction, getRect(draggable)) -
76
+ getBorderBeforeWidthValue(direction, draggable));
79
77
  };
80
78
  const getOffset = (event, draggable) => {
81
79
  let { offsetX, offsetY, target } = event;
82
80
  let targetHandler = getHandlerElementAncestor(target, draggable);
83
81
  const targetElement = target;
84
- if (targetElement && targetHandler && !targetElement.isSameNode(targetHandler)) {
82
+ if (targetElement && targetHandler && !isSameNode(targetElement, targetHandler)) {
85
83
  offsetX += getOffsetWithDraggable(HORIZONTAL, targetElement, targetHandler);
86
84
  offsetY += getOffsetWithDraggable(VERTICAL, targetElement, targetHandler);
87
85
  }
@@ -93,19 +91,18 @@ const getOffset = (event, draggable) => {
93
91
  };
94
92
  const getHandlerElementAncestor = (target, draggable) => {
95
93
  const targetHandler = target?.closest(`.${HANDLER_CLASS}`);
96
- if (targetHandler && targetHandler.isSameNode(draggable)) {
94
+ if (targetHandler && isSameNode(draggable, targetHandler)) {
97
95
  return target;
98
96
  }
99
97
  return targetHandler;
100
98
  };
101
99
  const getPositionByDistance = (direction, event, element, offsetEvent) => {
102
- const { offset, beforeMargin, page, borderBeforeWidth, scroll } = getPropByDirection(direction);
103
100
  const beforefixecParentValue = getNearestFixedParentPosition(element, direction);
104
- return (event[page] -
105
- offsetEvent[offset] -
106
- getValueFromProperty(element, beforeMargin) -
107
- getValueFromProperty(element, borderBeforeWidth) -
108
- window[scroll] -
101
+ return (getPageValue(direction, event) -
102
+ getOffsetValue(direction, offsetEvent) -
103
+ getBeforeMarginValue(direction, element) -
104
+ getBorderBeforeWidthValue(direction, element) -
105
+ getScrollValue(direction, window) -
109
106
  beforefixecParentValue);
110
107
  };
111
108
  export const getTransformState = (event, element, draggable) => {
@@ -1,5 +1,4 @@
1
- import { DroppableConfig } from "../configHandler";
2
- export declare const isTempElement: (element: Node) => boolean;
1
+ import { DroppableConfig } from './config/configHandler';
3
2
  export declare const addTempChild: <T>(draggedElement: HTMLElement | undefined, parent: Element, ifStartDragging: boolean, droppableConfig?: DroppableConfig<T>, addingAnimationDuration?: number) => void;
4
3
  export declare const addTempChildOnInsert: <T>(draggedElement: HTMLElement | undefined, ifStartDragging: boolean, droppableConfig?: DroppableConfig<T>) => void;
5
4
  export declare const removeTempChildrens: (droppable: HTMLElement, parent: HTMLElement, droppableGroupClass: string | null, animationDuration: number, draggedElementIsOutside?: boolean) => void;