fluid-dnd 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +14 -15
  2. package/dist/{HandlerPublisher-B68XPAcH.cjs → HandlerPublisher-1MmlNkG3.cjs} +1 -1
  3. package/dist/{HandlerPublisher-pcX0Zmas.js → HandlerPublisher-DBjPMiyO.js} +1 -1
  4. package/dist/core/config/configHandler.js +4 -4
  5. package/dist/core/config/droppableConfigurator.d.ts +2 -1
  6. package/dist/core/config/droppableConfigurator.js +17 -21
  7. package/dist/core/events/changeDraggableStyles.js +3 -5
  8. package/dist/core/events/dragAndDrop/dragAndDrop.js +28 -40
  9. package/dist/core/events/dragAndDrop/getTranslateBeforeDropping.js +30 -30
  10. package/dist/core/events/dragAndDrop/getTranslationByDraggingAndEvent.js +10 -11
  11. package/dist/core/events/insert.d.ts +2 -1
  12. package/dist/core/events/insert.js +4 -10
  13. package/dist/core/events/remove.d.ts +2 -2
  14. package/dist/core/events/remove.js +28 -13
  15. package/dist/core/index.d.ts +6 -0
  16. package/dist/core/index.js +7 -0
  17. package/dist/core/positioning/autoScroll.js +6 -5
  18. package/dist/core/positioning/usePositioning.js +20 -23
  19. package/dist/core/tempChildren.js +32 -28
  20. package/dist/core/useDraggable.js +39 -50
  21. package/dist/core/useDroppable.d.ts +2 -2
  22. package/dist/core/useDroppable.js +10 -16
  23. package/dist/core/utils/GetStyles.d.ts +24 -3
  24. package/dist/core/utils/GetStyles.js +53 -5
  25. package/dist/core/utils/ParseStyles.d.ts +3 -2
  26. package/dist/core/utils/ParseStyles.js +12 -12
  27. package/dist/core/utils/SetStyles.d.ts +4 -3
  28. package/dist/core/utils/SetStyles.js +19 -14
  29. package/dist/core/utils/index.d.ts +5 -1
  30. package/dist/core/utils/index.js +7 -6
  31. package/dist/fluid-dnd-logo.png +0 -0
  32. package/dist/index-BdOAK6C7.cjs +1 -0
  33. package/dist/index-HczUoMBK.js +1131 -0
  34. package/dist/index.cjs +1 -1
  35. package/dist/index.mjs +2 -2
  36. package/dist/insert-Dd8savAS.js +51 -0
  37. package/dist/insert-T4Y6rI_j.cjs +1 -0
  38. package/dist/react/index.cjs +1 -1
  39. package/dist/react/index.mjs +32 -30
  40. package/dist/react/utils/ReactLilstConfig.js +3 -2
  41. package/dist/remove-BC4sUY1o.cjs +1 -0
  42. package/dist/remove-M01dmTvo.js +48 -0
  43. package/dist/svelte/index.cjs +1 -1
  44. package/dist/svelte/index.mjs +18 -16
  45. package/dist/svelte/utils/SvelteListCondig.js +3 -2
  46. package/dist/vue/index.cjs +1 -1
  47. package/dist/vue/index.mjs +26 -24
  48. package/dist/vue/utils/VueListCondig.js +3 -2
  49. package/package.json +1 -1
  50. package/dist/index-2hBSSK9_.cjs +0 -1
  51. package/dist/index-DFXw7kYo.js +0 -1223
@@ -1,9 +1,11 @@
1
1
  import { getSiblings } from '../utils/GetStyles';
2
- import { moveTranslate } from '../utils/SetStyles';
2
+ import { moveTranslate, removeTranslateWhitoutTransition, setTranistion } from '../utils/SetStyles';
3
+ import { DraggingState } from '..';
3
4
  import getTranslationByDragging from './dragAndDrop/getTranslationByDraggingAndEvent';
4
- import { IsHTMLElement } from '../utils/typesCheckers';
5
- import { removeTempChild } from '../tempChildren';
5
+ import { addTempChild, removeTempChild } from '../tempChildren';
6
6
  import { useChangeDraggableStyles } from './changeDraggableStyles';
7
+ import { addClass, removeClass } from '../utils/dom/classList';
8
+ import { draggableTargetTimingFunction } from '../utils';
7
9
  export default function useRemoveEvents(currentConfig, parent, handlerPublisher, endDraggingAction) {
8
10
  const { animationDuration } = currentConfig;
9
11
  const [removeElementDraggingStyles] = useChangeDraggableStyles(currentConfig, handlerPublisher, endDraggingAction);
@@ -17,7 +19,7 @@ export default function useRemoveEvents(currentConfig, parent, handlerPublisher,
17
19
  const translation = getTranslationByDragging(draggedElement, 'remove', config.direction, droppable);
18
20
  for (const [index, sibling] of siblings.entries()) {
19
21
  if (index >= targetIndex) {
20
- startDragEventOverElement(sibling, translation);
22
+ moveTranslate(sibling, translation);
21
23
  setTimeout(() => {
22
24
  onFinishRemoveEvent(sibling);
23
25
  }, animationDuration);
@@ -31,21 +33,34 @@ export default function useRemoveEvents(currentConfig, parent, handlerPublisher,
31
33
  removeTranslateFromSiblings(draggedElement, parent);
32
34
  }, animationDuration);
33
35
  };
34
- const startDragEventOverElement = (element, translation) => {
35
- const { width, height } = translation;
36
- moveTranslate(element, height, width);
37
- };
38
36
  const removeTranslateFromSiblings = (element, parent) => {
39
37
  const [siblings] = getSiblings(element, parent);
40
38
  for (const sibling of [...siblings, element]) {
41
39
  removeTranslateWhitoutTransition(sibling);
42
40
  }
43
41
  };
44
- const removeTranslateWhitoutTransition = (element) => {
45
- if (IsHTMLElement(element)) {
46
- element.style.transition = '';
47
- element.style.transform = '';
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);
48
49
  }
49
50
  };
50
- return [emitRemoveEventToSiblings, emitFinishRemoveEventToSiblings];
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];
51
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,4 +1,4 @@
1
- import { draggableIsCompleteOutside, getPropByDirection } from '../utils/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;
@@ -14,11 +14,12 @@ export const useScroll = (draggedElement) => {
14
14
  let lastScrollAmount = 0.5;
15
15
  const minScrollAmountDiff = 0.03;
16
16
  const updateScrollByPosition = (direction, parent, position, translate) => {
17
- const { before, distance, axis, getRect } = getPropByDirection(direction);
18
- const distanceValue = getRect(draggedElement)[distance];
17
+ const [distanceValue] = getDistanceValue(direction, getRect(draggedElement));
19
18
  const parentBoundingClientRect = getRect(parent);
20
- const positionInsideParent = position[before] - parentBoundingClientRect[before] + translate[axis];
21
- const parentDistance = parentBoundingClientRect[distance];
19
+ const positionInsideParent = getBefore(direction, position) -
20
+ getBefore(direction, parentBoundingClientRect) +
21
+ getAxisValue(direction, translate);
22
+ const [parentDistance] = getDistanceValue(direction, parentBoundingClientRect);
22
23
  const totalDistance = parentDistance - distanceValue;
23
24
  const relativePosition = positionInsideParent / totalDistance;
24
25
  const relativeDistanceValue = distanceValue / totalDistance;
@@ -1,4 +1,4 @@
1
- import { getNearestFixedParentPosition, getPropByDirection, getValueFromProperty } from '../utils/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
3
  import { useScroll } from './autoScroll';
4
4
  import { HANDLER_CLASS, DRAGGING_CLASS } from '../utils/classes';
@@ -17,19 +17,18 @@ export const usePositioning = (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 usePositioning = (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 usePositioning = (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,18 +1,19 @@
1
1
  import { HORIZONTAL, VERTICAL } from '.';
2
- import { getPropByDirection } from './utils/GetStyles';
2
+ import { getDistanceValue, getPropByDirection, getRect, getScrollElementValue, isSameNode } from './utils/GetStyles';
3
3
  import { getGapPixels } from './utils/ParseStyles';
4
4
  import { setSizeStyles, setTranistion } from './utils/SetStyles';
5
5
  import { observeMutation } from './utils/observer';
6
6
  import getTranslationByDragging from './events/dragAndDrop/getTranslationByDraggingAndEvent';
7
- import { TEMP_CHILD_CLASS } from './utils';
7
+ import { NONE_TRANSLATE, TEMP_CHILD_CLASS } from './utils';
8
8
  import { addClass, getClassesSelector } from './utils/dom/classList';
9
9
  const START_DRAG_EVENT = 'startDrag';
10
10
  const timingFunction = 'cubic-bezier(0.2, 0, 0, 1)';
11
11
  const DELAY_TIME = 50;
12
+ const TRANSITION_PROPERTY = 'width, min-width, height';
12
13
  const getDistance = (droppable, draggedElement, direction) => {
13
14
  let distances = getTranslationByDragging(draggedElement, START_DRAG_EVENT, direction, droppable);
14
15
  const gap = getGapPixels(droppable, direction);
15
- const { distance } = getPropByDirection(direction);
16
+ const [, distance] = getDistanceValue(direction, distances);
16
17
  distances[distance] -= gap;
17
18
  const [large, largeDistance] = getlarge(direction, draggedElement);
18
19
  distances[largeDistance] = large;
@@ -20,54 +21,57 @@ const getDistance = (droppable, draggedElement, direction) => {
20
21
  };
21
22
  const getlarge = (direction, draggedElement) => {
22
23
  const largeDirection = direction == HORIZONTAL ? VERTICAL : HORIZONTAL;
23
- const { distance, getRect } = getPropByDirection(largeDirection);
24
- return [getRect(draggedElement)[distance], distance];
24
+ const distanceValue = getDistanceValue(largeDirection, getRect(draggedElement));
25
+ return distanceValue;
25
26
  };
26
- const setSizes = (element, height, width) => {
27
- setSizeStyles(element, height, width);
28
- element.style.minWidth = `${width}px`;
27
+ const setSizes = (element, translate = NONE_TRANSLATE) => {
28
+ setSizeStyles(element, translate);
29
+ element.style.minWidth = `${translate.width}px`;
29
30
  };
30
31
  const updateChildAfterCreated = (child, droppable, distances) => {
31
32
  return (observer) => {
32
33
  if (!droppable.contains(child)) {
33
34
  return;
34
35
  }
35
- setSizes(child, distances.height, distances.width);
36
+ setSizes(child, distances);
36
37
  observer.disconnect();
37
38
  };
38
39
  };
40
+ const overflowScroll = (droppable, direction) => {
41
+ const { scrollDistance, clientDistance } = getPropByDirection(direction);
42
+ return droppable[scrollDistance] - droppable[clientDistance];
43
+ };
39
44
  const scrollPercent = (direction, droppable, droppableScroll) => {
40
- const { scrollDistance, clientDistance, scrollElement } = getPropByDirection(direction);
41
- return droppableScroll[scrollElement] / (droppable[scrollDistance] - droppable[clientDistance]);
45
+ const [scrollElementValue] = getScrollElementValue(direction, droppableScroll);
46
+ return scrollElementValue / overflowScroll(droppable, direction);
42
47
  };
43
- const fixScrollInitialChange = (droppableConfig, ifStartDragging) => {
48
+ const fixScrollInitialChange = (droppable, config, scroll, ifStartDragging) => {
44
49
  if (!ifStartDragging) {
45
50
  return;
46
51
  }
47
- const { droppable, config, scroll } = droppableConfig;
48
52
  const { direction } = config;
49
- const scrollCompleted = scrollPercent(config.direction, droppable, scroll) > 0.99;
50
- const { scrollDistance, clientDistance, scrollElement } = getPropByDirection(direction);
53
+ const scrollCompleted = scrollPercent(direction, droppable, scroll) > 0.99;
54
+ const [, scrollElement] = getScrollElementValue(direction, droppable);
51
55
  if (scrollCompleted) {
52
- droppable[scrollElement] = droppable[scrollDistance] - droppable[clientDistance];
56
+ droppable[scrollElement] = overflowScroll(droppable, direction);
53
57
  }
54
58
  };
55
59
  const getTempChild = (draggedElement, ifStartDragging, droppableConfig, addingAnimationDuration) => {
56
60
  if (!droppableConfig) {
57
61
  return;
58
62
  }
59
- const { droppable, config } = droppableConfig;
63
+ const { droppable, config, scroll } = droppableConfig;
60
64
  const { direction, animationDuration } = config;
61
- fixScrollInitialChange(droppableConfig, ifStartDragging);
65
+ fixScrollInitialChange(droppable, config, scroll, ifStartDragging);
62
66
  if (droppable.querySelector(`.${TEMP_CHILD_CLASS}`) || !draggedElement) {
63
67
  return;
64
68
  }
65
69
  var tempChildTag = draggedElement.tagName == 'LI' ? 'DIV' : draggedElement.tagName;
66
70
  var child = document.createElement(tempChildTag);
67
71
  addClass(child, TEMP_CHILD_CLASS);
68
- setSizes(child, 0, 0);
72
+ setSizes(child);
69
73
  const distances = getDistance(droppable, draggedElement, direction);
70
- setTranistion(child, addingAnimationDuration ?? animationDuration, timingFunction, 'width, min-width, height');
74
+ setTranistion(child, addingAnimationDuration ?? animationDuration, timingFunction, TRANSITION_PROPERTY);
71
75
  return [child, distances, droppable];
72
76
  };
73
77
  export const addTempChild = (draggedElement, parent, ifStartDragging, droppableConfig, addingAnimationDuration) => {
@@ -76,8 +80,8 @@ export const addTempChild = (draggedElement, parent, ifStartDragging, droppableC
76
80
  return;
77
81
  }
78
82
  const [child, distances, droppable] = result;
79
- if (parent.isSameNode(droppable)) {
80
- setSizes(child, distances.height, distances.width);
83
+ if (isSameNode(parent, droppable)) {
84
+ setSizes(child, distances);
81
85
  }
82
86
  observeMutation(updateChildAfterCreated(child, droppable, distances), droppable, {
83
87
  childList: true,
@@ -96,9 +100,9 @@ export const addTempChildOnInsert = (draggedElement, ifStartDragging, droppableC
96
100
  };
97
101
  const setSizeAfterAppendChild = (child, size) => {
98
102
  return requestAnimationFrame(() => {
99
- setSizes(child, size.height, size.width);
103
+ setSizes(child, size);
100
104
  requestAnimationFrame(() => {
101
- setTranistion(child, 0, timingFunction, 'width, min-width, height');
105
+ setTranistion(child, 0, timingFunction, TRANSITION_PROPERTY);
102
106
  });
103
107
  });
104
108
  };
@@ -109,12 +113,12 @@ export const removeTempChildrens = (droppable, parent, droppableGroupClass, anim
109
113
  var children = document.querySelectorAll(`${getClassesSelector(droppableGroupClass)} > .${TEMP_CHILD_CLASS}`);
110
114
  children.forEach((tempChild) => {
111
115
  const childParent = tempChild.parentElement;
112
- if (childParent?.isSameNode(parent) ||
113
- (!draggedElementIsOutside && childParent?.isSameNode(droppable))) {
116
+ if (isSameNode(parent, childParent) ||
117
+ (!draggedElementIsOutside && isSameNode(droppable, childParent))) {
114
118
  return;
115
119
  }
116
120
  const tempChildElement = tempChild;
117
- setSizes(tempChildElement, 0, 0);
121
+ setSizes(tempChildElement);
118
122
  setTimeout(() => {
119
123
  tempChild.parentNode?.removeChild(tempChild);
120
124
  }, animationDuration + DELAY_TIME);
@@ -125,7 +129,7 @@ export const removeTempChild = (parent, animationDuration, isAnimated = false) =
125
129
  lastChildren.forEach((lastChild) => {
126
130
  const tempChildElement = lastChild;
127
131
  if (isAnimated) {
128
- setSizes(tempChildElement, 0, 0);
132
+ setSizes(tempChildElement);
129
133
  setTimeout(() => {
130
134
  if (parent.contains(tempChildElement)) {
131
135
  parent.removeChild(tempChildElement);
@@ -1,24 +1,18 @@
1
1
  import { assignDraggingEvent, convetEventToDragMouseTouchEvent, moveTranslate, setCustomFixedSize, setEventWithInterval, setTranistion } from './utils/SetStyles';
2
2
  import { usePositioning } from './positioning/usePositioning';
3
- import useRemoveEvents from './events/remove';
3
+ import { DraggingState } from '.';
4
4
  import { DRAG_EVENT, draggableTargetTimingFunction, START_DRAG_EVENT, START_DROP_EVENT } from './utils';
5
5
  import ConfigHandler from './config/configHandler';
6
6
  import { IsHTMLElement, isTouchEvent } from './utils/typesCheckers';
7
- import { addTempChild, addTempChildOnInsert, removeTempChildrens } from './tempChildren';
7
+ import { addTempChild, removeTempChildrens } from './tempChildren';
8
8
  import { DroppableConfigurator } from './config/droppableConfigurator';
9
- import { addClass, containClass, getClassesList, getClassesSelector, removeClass, toggleClass } from './utils/dom/classList';
9
+ import { addClass, containClass, getClassesList, getClassesSelector, toggleClass } from './utils/dom/classList';
10
10
  import { DRAGGABLE_CLASS, DRAGGING_CLASS, DROPPABLE_CLASS, HANDLER_CLASS } from './utils/classes';
11
11
  import useDragAndDropEvents from './events/dragAndDrop/dragAndDrop';
12
- import useInsertEvents from './events/insert';
13
- var DraggingState;
14
- (function (DraggingState) {
15
- DraggingState[DraggingState["NOT_DRAGGING"] = 0] = "NOT_DRAGGING";
16
- DraggingState[DraggingState["START_DRAGGING"] = 1] = "START_DRAGGING";
17
- DraggingState[DraggingState["DRAGING"] = 2] = "DRAGING";
18
- DraggingState[DraggingState["END_DRAGGING"] = 3] = "END_DRAGGING";
19
- })(DraggingState || (DraggingState = {}));
12
+ import { getRect, isSameNode } from './utils/GetStyles';
13
+ const ON_MOUSEDOWN = 'onmousedown';
20
14
  export default function useDraggable(draggableElement, index, config, parent, handlerPublisher) {
21
- const { handlerSelector, isDraggable, droppableGroup, animationDuration, delayBeforeRemove, draggingClass, removingClass, onRemoveAtEvent, droppableClass, onDragStart, delayBeforeTouchMoveEvent, coordinateTransform } = config;
15
+ const { handlerSelector, isDraggable, droppableGroup, animationDuration, draggingClass, droppableClass, onDragStart, delayBeforeTouchMoveEvent, coordinateTransform } = config;
22
16
  const droppableGroupClass = getClassesList(droppableGroup)
23
17
  .map((classGroup) => `droppable-group-${classGroup}`)
24
18
  .join(' ');
@@ -34,9 +28,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
34
28
  const endDraggingState = () => {
35
29
  draggingState = DraggingState.NOT_DRAGGING;
36
30
  };
37
- const [emitRemoveEventToSiblings, emitFinishRemoveEventToSiblings] = useRemoveEvents(config, parent, handlerPublisher, endDraggingState);
38
31
  const [emitDraggingEvent, emitDroppingEvent, toggleDraggingClass] = useDragAndDropEvents(config, index, parent, droppableGroupClass, handlerPublisher, endDraggingState);
39
- const [emitInsertEventToSiblings] = useInsertEvents(config, parent, handlerPublisher, endDraggingState);
40
32
  const setDraggable = () => {
41
33
  addClass(draggableElement, DRAGGABLE_CLASS);
42
34
  };
@@ -65,7 +57,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
65
57
  if (handler &&
66
58
  handlerParent &&
67
59
  containClass(handlerParent, DROPPABLE_CLASS) &&
68
- !handlerParent.isSameNode(parent)) {
60
+ !isSameNode(parent, handlerParent)) {
69
61
  return null;
70
62
  }
71
63
  return handler;
@@ -73,22 +65,22 @@ export default function useDraggable(draggableElement, index, config, parent, ha
73
65
  const setSlotRefElementParams = (element) => {
74
66
  const handlerElement = (getHandler(element) ?? element);
75
67
  if (handlerElement && isDraggable(element)) {
76
- assignDraggingEvent(handlerElement, 'onmousedown', onmousedown('mousemove', 'mouseup'));
68
+ assignDraggingEvent(handlerElement, ON_MOUSEDOWN, onmousedown('mousemove', 'mouseup'));
77
69
  assignDraggingEvent(handlerElement, 'ontouchstart', onmousedown('touchmove', 'touchend'), (event) => {
70
+ const touch = event.touches[0];
78
71
  initialTouch = {
79
- x: event.touches[0].clientX,
80
- y: event.touches[0].clientY
72
+ x: touch.clientX,
73
+ y: touch.clientY
81
74
  };
82
75
  });
83
76
  disableMousedownEventFromImages(handlerElement);
84
77
  }
85
- if (!element?.isSameNode(handlerElement)) {
86
- assignDraggingEvent(element, 'onmousedown', mousedownOnDraggablefunction);
78
+ if (!isSameNode(element, handlerElement)) {
79
+ assignDraggingEvent(element, ON_MOUSEDOWN, mousedownOnDraggablefunction);
87
80
  }
88
81
  addClass(parent, DROPPABLE_CLASS);
89
82
  };
90
83
  const disableMousedownEventFromImages = (handlerElement) => {
91
- // Avoid dragging inner images
92
84
  const images = handlerElement.querySelectorAll('img');
93
85
  Array.from(images).forEach((image) => {
94
86
  image.onmousedown = () => false;
@@ -105,11 +97,18 @@ export default function useDraggable(draggableElement, index, config, parent, ha
105
97
  setTransform(draggableElement, droppable, pagePosition, config.direction);
106
98
  emitDraggingEvent(draggableElement, DRAG_EVENT, droppableConfigurator.current);
107
99
  };
100
+ const removeTranslates = (droppable) => {
101
+ const drgagables = droppable.querySelectorAll(`.${DRAGGABLE_CLASS}`);
102
+ for (const draggable of drgagables) {
103
+ moveTranslate(draggable);
104
+ }
105
+ };
108
106
  const changeDroppable = (newdDroppableConfig, oldDroppableConfig) => {
109
107
  if (oldDroppableConfig &&
110
108
  draggingState == DraggingState.DRAGING &&
111
- !newdDroppableConfig?.droppable.isSameNode(oldDroppableConfig.droppable)) {
109
+ !isSameNode(newdDroppableConfig?.droppable, oldDroppableConfig.droppable)) {
112
110
  emitDraggingEvent(draggableElement, DRAG_EVENT, oldDroppableConfig);
111
+ removeTranslates(oldDroppableConfig.droppable);
113
112
  }
114
113
  };
115
114
  const droppableConfigurator = new DroppableConfigurator(draggableElement, droppableGroupClass, parent, setTransformDragEvent, changeDroppable, config.mapFrom);
@@ -121,7 +120,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
121
120
  ? Array.from(document.querySelectorAll(getClassesSelector(droppableGroupClass)))
122
121
  : [parent];
123
122
  for (const droppable of droppables) {
124
- droppable.classList.toggle(droppableClass, !isOutside && droppable.isSameNode(droppableConfigurator.current.droppable));
123
+ droppable.classList.toggle(droppableClass, !isOutside && isSameNode(droppable, droppableConfigurator.current.droppable));
125
124
  }
126
125
  };
127
126
  const onMove = (event, isTouchEvent = false) => {
@@ -149,8 +148,9 @@ export default function useDraggable(draggableElement, index, config, parent, ha
149
148
  };
150
149
  const cursorWasNotMoved = (event) => {
151
150
  if (isTouchEvent(event) && initialTouch && draggingState == DraggingState.START_DRAGGING) {
152
- const movedX = Math.abs(event.touches[0].clientX - initialTouch.x);
153
- const movedY = Math.abs(event.touches[0].clientY - initialTouch.y);
151
+ const touch = event.touches[0];
152
+ const movedX = Math.abs(touch.clientX - initialTouch.x);
153
+ const movedY = Math.abs(touch.clientY - initialTouch.y);
154
154
  if (Math.abs(movedX) > 5 && Math.abs(movedY) > 5) {
155
155
  clearTimeout(delayTimeout);
156
156
  return false;
@@ -184,7 +184,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
184
184
  const { clientX, clientY } = event;
185
185
  const elementBelow = document.elementFromPoint(clientX, clientY);
186
186
  const draggableAncestor = elementBelow?.closest(`.${DRAGGABLE_CLASS}`);
187
- return draggableAncestor && element.isSameNode(draggableAncestor);
187
+ return draggableAncestor && isSameNode(element, draggableAncestor);
188
188
  };
189
189
  const getDragStartEventData = (element) => {
190
190
  const value = config.onGetValue(index);
@@ -233,7 +233,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
233
233
  const disableDragging = (moveEvent, event) => {
234
234
  toggleDroppableClass(true);
235
235
  const convertedEvent = convetEventToDragMouseTouchEvent(event);
236
- onDropDraggingEvent(droppableConfigurator.isOutside(convertedEvent, false));
236
+ onDropDraggingEvent(droppableConfigurator.isOutside(convertedEvent));
237
237
  clearTimeout(delayTimeout);
238
238
  document.removeEventListener(moveEvent, handleMove);
239
239
  droppableConfigurator.updateConfig(convertedEvent);
@@ -291,10 +291,10 @@ export default function useDraggable(draggableElement, index, config, parent, ha
291
291
  };
292
292
  const removeDraggingStyles = (element) => {
293
293
  setTranistion(element, animationDuration, draggableTargetTimingFunction);
294
- moveTranslate(element, 0, 0);
294
+ moveTranslate(element);
295
295
  };
296
296
  const setDraggingStyles = (element) => {
297
- const { height, width } = element.getBoundingClientRect();
297
+ const { height, width } = getRect(element);
298
298
  setCustomFixedSize(element, {
299
299
  fixedHeight: `${height}px`,
300
300
  fixedWidth: `${width}px`
@@ -303,32 +303,21 @@ export default function useDraggable(draggableElement, index, config, parent, ha
303
303
  toggleClass(element, draggingClass, true);
304
304
  element.style.transition = '';
305
305
  };
306
- const removeAfterRemovingClass = (targetIndex, config) => {
307
- removeClass(draggableElement, removingClass);
308
- addTempChild(draggableElement, parent, draggingState == DraggingState.START_DRAGGING, droppableConfigurator.initial);
309
- emitRemoveEventToSiblings(targetIndex, draggableElement, config, (sibling) => {
310
- removeDraggingStyles(sibling);
311
- emitFinishRemoveEventToSiblings(draggableElement);
312
- });
313
- onRemoveAtEvent(index, true);
314
- };
315
306
  const removeAtFromElement = (targetIndex) => {
316
- if (!droppableConfigurator.initial) {
317
- return;
318
- }
319
- const config = droppableConfigurator.initial;
320
- if (targetIndex == index) {
321
- addClass(draggableElement, removingClass);
322
- setTimeout(() => {
323
- removeAfterRemovingClass(targetIndex, config);
324
- }, delayBeforeRemove);
325
- }
307
+ import('./events/remove').then((module) => {
308
+ const [removeAt] = module.default(config, parent, handlerPublisher, endDraggingState);
309
+ if (!droppableConfigurator.initial) {
310
+ return;
311
+ }
312
+ removeAt(index, targetIndex, draggableElement, draggingState, droppableConfigurator.initial);
313
+ });
326
314
  };
327
315
  const insertAtFromElement = (targetIndex, value) => {
328
316
  if (targetIndex === index ||
329
317
  (targetIndex === config.onGetLegth() && index === targetIndex - 1)) {
330
- emitInsertEventToSiblings(targetIndex, draggableElement, parent, value, () => {
331
- addTempChildOnInsert(draggableElement, draggingState == DraggingState.START_DRAGGING, droppableConfigurator.initial);
318
+ import('./events/insert').then((module) => {
319
+ const [emitInsertEventToSiblings] = module.default(config, parent, handlerPublisher, endDraggingState);
320
+ emitInsertEventToSiblings(targetIndex, draggableElement, parent, value, droppableConfigurator.initial);
332
321
  });
333
322
  }
334
323
  };
@@ -1,3 +1,3 @@
1
- import { CoreConfig } from ".";
2
- import HandlerPublisher from "./HandlerPublisher";
1
+ import { CoreConfig } from '.';
2
+ import HandlerPublisher from './HandlerPublisher';
3
3
  export default function useDroppable<T>(coreConfig: CoreConfig<T>, handlerPublisher: HandlerPublisher, droppable?: HTMLElement, indexAttr?: string): readonly [((targetIndex: number) => void)[], ((targetIndex: number, value: T) => void)[]];
@@ -1,8 +1,8 @@
1
- import { parseIntEmpty } from "./utils/GetStyles";
2
- import { addMultipleClasses, getClassesList } from "./utils/dom/classList";
3
- import useDraggable from "./useDraggable";
4
- import { AddCssStylesToElement } from "./utils/SetStyles";
5
- import { DRAGGABLE_CLASS, DRAGGING_CLASS, DRAGGING_HANDLER_CLASS, DROPPING_CLASS, GRAB_CLASS, GRABBING_CLASS, HANDLER_CLASS } from "./utils/classes";
1
+ import { parseIntEmpty } from './utils/GetStyles';
2
+ import { addMultipleClasses, getClassesList } from './utils/dom/classList';
3
+ import useDraggable from './useDraggable';
4
+ import { AddCssStylesToElement } from './utils/SetStyles';
5
+ import { DRAGGABLE_CLASS, DRAGGING_CLASS, DRAGGING_HANDLER_CLASS, DROPPING_CLASS, GRAB_CLASS, GRABBING_CLASS, HANDLER_CLASS } from './utils/classes';
6
6
  const setDroppableGroupClass = (droppableGroupClass, droppable) => {
7
7
  if (droppableGroupClass) {
8
8
  addMultipleClasses(droppable, droppableGroupClass);
@@ -13,13 +13,13 @@ const createDraggableCssStyles = () => {
13
13
  `.${DRAGGABLE_CLASS}{touch-action:manipulation;user-select:none;box-sizing:border-box!important;-webkit-user-select:none;}`,
14
14
  `.${HANDLER_CLASS}{pointer-events:auto!important;}`,
15
15
  `.${GRAB_CLASS}{cursor:grab;}`,
16
- ".temp-child{touch-action:none;pointer-events:none;box-sizing:border-box!important;}",
16
+ '.temp-child{touch-action:none;pointer-events:none;box-sizing:border-box!important;}',
17
17
  `.droppable{box-sizing:border-box!important;}`,
18
18
  `.${DRAGGING_CLASS}{position:fixed;z-index:5000;width:var(--fixedWidth)!important;height:var(--fixedHeight)!important;}`,
19
19
  `.${DRAGGING_HANDLER_CLASS}{pointer-events:none!important;}`,
20
20
  `.${DROPPING_CLASS}{pointer-events:none!important;}`,
21
21
  `.${GRABBING_CLASS}{cursor:grabbing;}`,
22
- `.disable-transition{transition:none!important;}`,
22
+ `.disable-transition{transition:none!important;}`
23
23
  ]);
24
24
  };
25
25
  export default function useDroppable(coreConfig, handlerPublisher, droppable, indexAttr = 'index') {
@@ -28,14 +28,11 @@ export default function useDroppable(coreConfig, handlerPublisher, droppable, in
28
28
  let insertAtFromElementList = [];
29
29
  const { droppableGroup } = coreConfig;
30
30
  if (!droppable) {
31
- return [
32
- removeAtFromElementList,
33
- insertAtFromElementList
34
- ];
31
+ return [removeAtFromElementList, insertAtFromElementList];
35
32
  }
36
33
  const droppableGroupClass = getClassesList(droppableGroup)
37
34
  .map((classGroup) => `droppable-group-${classGroup}`)
38
- .join(" ");
35
+ .join(' ');
39
36
  createDraggableCssStyles();
40
37
  setDroppableGroupClass(droppableGroupClass, droppable);
41
38
  for (const child of droppable.children) {
@@ -48,8 +45,5 @@ export default function useDroppable(coreConfig, handlerPublisher, droppable, in
48
45
  insertAtFromElementList.push(insertAtFromElement);
49
46
  }
50
47
  }
51
- return [
52
- removeAtFromElementList,
53
- insertAtFromElementList
54
- ];
48
+ return [removeAtFromElementList, insertAtFromElementList];
55
49
  }