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,26 +1,19 @@
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)";
1
+ import { HORIZONTAL, VERTICAL } from '.';
2
+ import { getDistanceValue, getPropByDirection, getRect, getScrollElementValue, isSameNode } from './utils/GetStyles';
3
+ import { getGapPixels } from './utils/ParseStyles';
4
+ import { setSizeStyles, setTranistion } from './utils/SetStyles';
5
+ import { observeMutation } from './utils/observer';
6
+ import getTranslationByDragging from './events/dragAndDrop/getTranslationByDraggingAndEvent';
7
+ import { NONE_TRANSLATE, TEMP_CHILD_CLASS } from './utils';
8
+ import { addClass, getClassesSelector } from './utils/dom/classList';
9
+ const START_DRAG_EVENT = 'startDrag';
10
+ const timingFunction = 'cubic-bezier(0.2, 0, 0, 1)';
13
11
  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
- };
12
+ const TRANSITION_PROPERTY = 'width, min-width, height';
20
13
  const getDistance = (droppable, draggedElement, direction) => {
21
14
  let distances = getTranslationByDragging(draggedElement, START_DRAG_EVENT, direction, droppable);
22
15
  const gap = getGapPixels(droppable, direction);
23
- const { distance } = getPropByDirection(direction);
16
+ const [, distance] = getDistanceValue(direction, distances);
24
17
  distances[distance] -= gap;
25
18
  const [large, largeDistance] = getlarge(direction, draggedElement);
26
19
  distances[largeDistance] = large;
@@ -28,54 +21,57 @@ const getDistance = (droppable, draggedElement, direction) => {
28
21
  };
29
22
  const getlarge = (direction, draggedElement) => {
30
23
  const largeDirection = direction == HORIZONTAL ? VERTICAL : HORIZONTAL;
31
- const { distance, getRect } = getPropByDirection(largeDirection);
32
- return [
33
- getRect(draggedElement)[distance],
34
- distance,
35
- ];
24
+ const distanceValue = getDistanceValue(largeDirection, getRect(draggedElement));
25
+ return distanceValue;
36
26
  };
37
- const setSizes = (element, height, width) => {
38
- setSizeStyles(element, height, width);
39
- element.style.minWidth = `${width}px`;
27
+ const setSizes = (element, translate = NONE_TRANSLATE) => {
28
+ setSizeStyles(element, translate);
29
+ element.style.minWidth = `${translate.width}px`;
40
30
  };
41
31
  const updateChildAfterCreated = (child, droppable, distances) => {
42
32
  return (observer) => {
43
33
  if (!droppable.contains(child)) {
44
34
  return;
45
35
  }
46
- setSizes(child, distances.height, distances.width);
36
+ setSizes(child, distances);
47
37
  observer.disconnect();
48
38
  };
49
39
  };
50
- const fixScrollInitialChange = (droppableConfig, ifStartDragging) => {
40
+ const overflowScroll = (droppable, direction) => {
41
+ const { scrollDistance, clientDistance } = getPropByDirection(direction);
42
+ return droppable[scrollDistance] - droppable[clientDistance];
43
+ };
44
+ const scrollPercent = (direction, droppable, droppableScroll) => {
45
+ const [scrollElementValue] = getScrollElementValue(direction, droppableScroll);
46
+ return scrollElementValue / overflowScroll(droppable, direction);
47
+ };
48
+ const fixScrollInitialChange = (droppable, config, scroll, ifStartDragging) => {
51
49
  if (!ifStartDragging) {
52
50
  return;
53
51
  }
54
- const { droppable, config, scroll } = droppableConfig;
55
52
  const { direction } = config;
56
- const scrollCompleted = scrollPercent(config.direction, droppable, scroll) > 0.99;
57
- const { scrollDistance, clientDistance, scrollElement } = getPropByDirection(direction);
53
+ const scrollCompleted = scrollPercent(direction, droppable, scroll) > 0.99;
54
+ const [, scrollElement] = getScrollElementValue(direction, droppable);
58
55
  if (scrollCompleted) {
59
- droppable[scrollElement] =
60
- droppable[scrollDistance] - droppable[clientDistance];
56
+ droppable[scrollElement] = overflowScroll(droppable, direction);
61
57
  }
62
58
  };
63
59
  const getTempChild = (draggedElement, ifStartDragging, droppableConfig, addingAnimationDuration) => {
64
60
  if (!droppableConfig) {
65
61
  return;
66
62
  }
67
- const { droppable, config } = droppableConfig;
63
+ const { droppable, config, scroll } = droppableConfig;
68
64
  const { direction, animationDuration } = config;
69
- fixScrollInitialChange(droppableConfig, ifStartDragging);
65
+ fixScrollInitialChange(droppable, config, scroll, ifStartDragging);
70
66
  if (droppable.querySelector(`.${TEMP_CHILD_CLASS}`) || !draggedElement) {
71
67
  return;
72
68
  }
73
- var tempChildTag = draggedElement.tagName == "LI" ? "DIV" : draggedElement.tagName;
69
+ var tempChildTag = draggedElement.tagName == 'LI' ? 'DIV' : draggedElement.tagName;
74
70
  var child = document.createElement(tempChildTag);
75
71
  addClass(child, TEMP_CHILD_CLASS);
76
- setSizes(child, 0, 0);
72
+ setSizes(child);
77
73
  const distances = getDistance(droppable, draggedElement, direction);
78
- setTranistion(child, addingAnimationDuration ?? animationDuration, timingFunction, "width, min-width, height");
74
+ setTranistion(child, addingAnimationDuration ?? animationDuration, timingFunction, TRANSITION_PROPERTY);
79
75
  return [child, distances, droppable];
80
76
  };
81
77
  export const addTempChild = (draggedElement, parent, ifStartDragging, droppableConfig, addingAnimationDuration) => {
@@ -84,12 +80,12 @@ export const addTempChild = (draggedElement, parent, ifStartDragging, droppableC
84
80
  return;
85
81
  }
86
82
  const [child, distances, droppable] = result;
87
- if (parent.isSameNode(droppable)) {
88
- setSizes(child, distances.height, distances.width);
83
+ if (isSameNode(parent, droppable)) {
84
+ setSizes(child, distances);
89
85
  }
90
86
  observeMutation(updateChildAfterCreated(child, droppable, distances), droppable, {
91
87
  childList: true,
92
- subtree: true,
88
+ subtree: true
93
89
  });
94
90
  droppable.appendChild(child);
95
91
  };
@@ -104,9 +100,9 @@ export const addTempChildOnInsert = (draggedElement, ifStartDragging, droppableC
104
100
  };
105
101
  const setSizeAfterAppendChild = (child, size) => {
106
102
  return requestAnimationFrame(() => {
107
- setSizes(child, size.height, size.width);
103
+ setSizes(child, size);
108
104
  requestAnimationFrame(() => {
109
- setTranistion(child, 0, timingFunction, "width, min-width, height");
105
+ setTranistion(child, 0, timingFunction, TRANSITION_PROPERTY);
110
106
  });
111
107
  });
112
108
  };
@@ -117,11 +113,12 @@ export const removeTempChildrens = (droppable, parent, droppableGroupClass, anim
117
113
  var children = document.querySelectorAll(`${getClassesSelector(droppableGroupClass)} > .${TEMP_CHILD_CLASS}`);
118
114
  children.forEach((tempChild) => {
119
115
  const childParent = tempChild.parentElement;
120
- if ((childParent?.isSameNode(parent) || !draggedElementIsOutside && childParent?.isSameNode(droppable))) {
116
+ if (isSameNode(parent, childParent) ||
117
+ (!draggedElementIsOutside && isSameNode(droppable, childParent))) {
121
118
  return;
122
119
  }
123
120
  const tempChildElement = tempChild;
124
- setSizes(tempChildElement, 0, 0);
121
+ setSizes(tempChildElement);
125
122
  setTimeout(() => {
126
123
  tempChild.parentNode?.removeChild(tempChild);
127
124
  }, animationDuration + DELAY_TIME);
@@ -132,7 +129,7 @@ export const removeTempChild = (parent, animationDuration, isAnimated = false) =
132
129
  lastChildren.forEach((lastChild) => {
133
130
  const tempChildElement = lastChild;
134
131
  if (isAnimated) {
135
- setSizes(tempChildElement, 0, 0);
132
+ setSizes(tempChildElement);
136
133
  setTimeout(() => {
137
134
  if (parent.contains(tempChildElement)) {
138
135
  parent.removeChild(tempChildElement);
@@ -1,22 +1,18 @@
1
1
  import { assignDraggingEvent, convetEventToDragMouseTouchEvent, moveTranslate, setCustomFixedSize, setEventWithInterval, setTranistion } from './utils/SetStyles';
2
- import { useTransform } from './utils/SetTransform';
3
- import useEmitEvents from './utils/events/emitEvents';
2
+ import { usePositioning } from './positioning/usePositioning';
3
+ import { DraggingState } from '.';
4
4
  import { DRAG_EVENT, draggableTargetTimingFunction, START_DRAG_EVENT, START_DROP_EVENT } from './utils';
5
- import ConfigHandler from './configHandler';
6
- import { IsHTMLElement, isTouchEvent } from './utils/touchDevice';
7
- import { addTempChild, addTempChildOnInsert, removeTempChildrens } from './utils/tempChildren';
8
- import { DroppableConfigurator } from './utils/droppableConfigurator';
9
- import { addClass, containClass, getClassesList, getClassesSelector, removeClass, toggleClass } from './utils/dom/classList';
5
+ import ConfigHandler from './config/configHandler';
6
+ import { IsHTMLElement, isTouchEvent } from './utils/typesCheckers';
7
+ import { addTempChild, removeTempChildrens } from './tempChildren';
8
+ import { DroppableConfigurator } from './config/droppableConfigurator';
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
- var DraggingState;
12
- (function (DraggingState) {
13
- DraggingState[DraggingState["NOT_DRAGGING"] = 0] = "NOT_DRAGGING";
14
- DraggingState[DraggingState["START_DRAGGING"] = 1] = "START_DRAGGING";
15
- DraggingState[DraggingState["DRAGING"] = 2] = "DRAGING";
16
- DraggingState[DraggingState["END_DRAGGING"] = 3] = "END_DRAGGING";
17
- })(DraggingState || (DraggingState = {}));
11
+ import useDragAndDropEvents from './events/dragAndDrop/dragAndDrop';
12
+ import { getRect, isSameNode } from './utils/GetStyles';
13
+ const ON_MOUSEDOWN = 'onmousedown';
18
14
  export default function useDraggable(draggableElement, index, config, parent, handlerPublisher) {
19
- 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;
20
16
  const droppableGroupClass = getClassesList(droppableGroup)
21
17
  .map((classGroup) => `droppable-group-${classGroup}`)
22
18
  .join(' ');
@@ -28,11 +24,11 @@ export default function useDraggable(draggableElement, index, config, parent, ha
28
24
  let pagePosition = { pageX: 0, pageY: 0 };
29
25
  let delayTimeout;
30
26
  let initialTouch;
31
- const [setTransform, updateTransformState] = useTransform(draggableElement, coordinateTransform);
27
+ const [setTransform, updateTransformState] = usePositioning(draggableElement, coordinateTransform);
32
28
  const endDraggingState = () => {
33
29
  draggingState = DraggingState.NOT_DRAGGING;
34
30
  };
35
- const [emitEventToSiblings, emitRemoveEventToSiblings, emitInsertEventToSiblings, emitFinishRemoveEventToSiblings, toggleDraggingClass] = useEmitEvents(config, index, parent, droppableGroupClass, handlerPublisher, endDraggingState);
31
+ const [emitDraggingEvent, emitDroppingEvent, toggleDraggingClass] = useDragAndDropEvents(config, index, parent, droppableGroupClass, handlerPublisher, endDraggingState);
36
32
  const setDraggable = () => {
37
33
  addClass(draggableElement, DRAGGABLE_CLASS);
38
34
  };
@@ -61,7 +57,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
61
57
  if (handler &&
62
58
  handlerParent &&
63
59
  containClass(handlerParent, DROPPABLE_CLASS) &&
64
- !handlerParent.isSameNode(parent)) {
60
+ !isSameNode(parent, handlerParent)) {
65
61
  return null;
66
62
  }
67
63
  return handler;
@@ -69,22 +65,22 @@ export default function useDraggable(draggableElement, index, config, parent, ha
69
65
  const setSlotRefElementParams = (element) => {
70
66
  const handlerElement = (getHandler(element) ?? element);
71
67
  if (handlerElement && isDraggable(element)) {
72
- assignDraggingEvent(handlerElement, 'onmousedown', onmousedown('mousemove', 'mouseup'));
68
+ assignDraggingEvent(handlerElement, ON_MOUSEDOWN, onmousedown('mousemove', 'mouseup'));
73
69
  assignDraggingEvent(handlerElement, 'ontouchstart', onmousedown('touchmove', 'touchend'), (event) => {
70
+ const touch = event.touches[0];
74
71
  initialTouch = {
75
- x: event.touches[0].clientX,
76
- y: event.touches[0].clientY
72
+ x: touch.clientX,
73
+ y: touch.clientY
77
74
  };
78
75
  });
79
76
  disableMousedownEventFromImages(handlerElement);
80
77
  }
81
- if (!element?.isSameNode(handlerElement)) {
82
- assignDraggingEvent(element, 'onmousedown', mousedownOnDraggablefunction);
78
+ if (!isSameNode(element, handlerElement)) {
79
+ assignDraggingEvent(element, ON_MOUSEDOWN, mousedownOnDraggablefunction);
83
80
  }
84
81
  addClass(parent, DROPPABLE_CLASS);
85
82
  };
86
83
  const disableMousedownEventFromImages = (handlerElement) => {
87
- // Avoid dragging inner images
88
84
  const images = handlerElement.querySelectorAll('img');
89
85
  Array.from(images).forEach((image) => {
90
86
  image.onmousedown = () => false;
@@ -99,13 +95,20 @@ export default function useDraggable(draggableElement, index, config, parent, ha
99
95
  }
100
96
  const { droppable, config } = droppableConfigurator.current;
101
97
  setTransform(draggableElement, droppable, pagePosition, config.direction);
102
- emitEventToSiblings(draggableElement, DRAG_EVENT, windowScroll, droppableConfigurator.current);
98
+ emitDraggingEvent(draggableElement, DRAG_EVENT, droppableConfigurator.current);
99
+ };
100
+ const removeTranslates = (droppable) => {
101
+ const drgagables = droppable.querySelectorAll(`.${DRAGGABLE_CLASS}`);
102
+ for (const draggable of drgagables) {
103
+ moveTranslate(draggable);
104
+ }
103
105
  };
104
106
  const changeDroppable = (newdDroppableConfig, oldDroppableConfig) => {
105
107
  if (oldDroppableConfig &&
106
108
  draggingState == DraggingState.DRAGING &&
107
- !newdDroppableConfig?.droppable.isSameNode(oldDroppableConfig.droppable)) {
108
- emitEventToSiblings(draggableElement, DRAG_EVENT, windowScroll, oldDroppableConfig);
109
+ !isSameNode(newdDroppableConfig?.droppable, oldDroppableConfig.droppable)) {
110
+ emitDraggingEvent(draggableElement, DRAG_EVENT, oldDroppableConfig);
111
+ removeTranslates(oldDroppableConfig.droppable);
109
112
  }
110
113
  };
111
114
  const droppableConfigurator = new DroppableConfigurator(draggableElement, droppableGroupClass, parent, setTransformDragEvent, changeDroppable, config.mapFrom);
@@ -117,7 +120,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
117
120
  ? Array.from(document.querySelectorAll(getClassesSelector(droppableGroupClass)))
118
121
  : [parent];
119
122
  for (const droppable of droppables) {
120
- droppable.classList.toggle(droppableClass, !isOutside && droppable.isSameNode(droppableConfigurator.current.droppable));
123
+ droppable.classList.toggle(droppableClass, !isOutside && isSameNode(droppable, droppableConfigurator.current.droppable));
121
124
  }
122
125
  };
123
126
  const onMove = (event, isTouchEvent = false) => {
@@ -145,8 +148,9 @@ export default function useDraggable(draggableElement, index, config, parent, ha
145
148
  };
146
149
  const cursorWasNotMoved = (event) => {
147
150
  if (isTouchEvent(event) && initialTouch && draggingState == DraggingState.START_DRAGGING) {
148
- const movedX = Math.abs(event.touches[0].clientX - initialTouch.x);
149
- 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);
150
154
  if (Math.abs(movedX) > 5 && Math.abs(movedY) > 5) {
151
155
  clearTimeout(delayTimeout);
152
156
  return false;
@@ -180,7 +184,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
180
184
  const { clientX, clientY } = event;
181
185
  const elementBelow = document.elementFromPoint(clientX, clientY);
182
186
  const draggableAncestor = elementBelow?.closest(`.${DRAGGABLE_CLASS}`);
183
- return draggableAncestor && element.isSameNode(draggableAncestor);
187
+ return draggableAncestor && isSameNode(element, draggableAncestor);
184
188
  };
185
189
  const getDragStartEventData = (element) => {
186
190
  const value = config.onGetValue(index);
@@ -229,7 +233,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
229
233
  const disableDragging = (moveEvent, event) => {
230
234
  toggleDroppableClass(true);
231
235
  const convertedEvent = convetEventToDragMouseTouchEvent(event);
232
- onDropDraggingEvent(droppableConfigurator.isOutside(convertedEvent, false));
236
+ onDropDraggingEvent(droppableConfigurator.isOutside(convertedEvent));
233
237
  clearTimeout(delayTimeout);
234
238
  document.removeEventListener(moveEvent, handleMove);
235
239
  droppableConfigurator.updateConfig(convertedEvent);
@@ -256,7 +260,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
256
260
  const startDragging = (event) => {
257
261
  addTempChild(draggableElement, parent, draggingState == DraggingState.START_DRAGGING, droppableConfigurator.current);
258
262
  updateDraggingStateBeforeDragging();
259
- emitEventToSiblings(draggableElement, START_DRAG_EVENT, windowScroll, droppableConfigurator.current);
263
+ emitDraggingEvent(draggableElement, START_DRAG_EVENT, droppableConfigurator.current);
260
264
  setDraggingStyles(draggableElement);
261
265
  updateTransformState(event, draggableElement);
262
266
  };
@@ -282,15 +286,15 @@ export default function useDraggable(draggableElement, index, config, parent, ha
282
286
  draggingState = DraggingState.END_DRAGGING;
283
287
  removeDraggingStyles(draggableElement);
284
288
  if (draggableElement.classList.contains(DRAGGING_CLASS)) {
285
- emitEventToSiblings(draggableElement, START_DROP_EVENT, windowScroll, isOutsideAllDroppables ? droppableConfigurator.initial : droppableConfigurator.current, index);
289
+ emitDroppingEvent(draggableElement, START_DROP_EVENT, isOutsideAllDroppables ? droppableConfigurator.initial : droppableConfigurator.current, windowScroll, index);
286
290
  }
287
291
  };
288
292
  const removeDraggingStyles = (element) => {
289
293
  setTranistion(element, animationDuration, draggableTargetTimingFunction);
290
- moveTranslate(element, 0, 0);
294
+ moveTranslate(element);
291
295
  };
292
296
  const setDraggingStyles = (element) => {
293
- const { height, width } = element.getBoundingClientRect();
297
+ const { height, width } = getRect(element);
294
298
  setCustomFixedSize(element, {
295
299
  fixedHeight: `${height}px`,
296
300
  fixedWidth: `${width}px`
@@ -299,32 +303,21 @@ export default function useDraggable(draggableElement, index, config, parent, ha
299
303
  toggleClass(element, draggingClass, true);
300
304
  element.style.transition = '';
301
305
  };
302
- const removeAfterRemovingClass = (targetIndex, config) => {
303
- removeClass(draggableElement, removingClass);
304
- addTempChild(draggableElement, parent, draggingState == DraggingState.START_DRAGGING, droppableConfigurator.initial);
305
- emitRemoveEventToSiblings(targetIndex, draggableElement, config, (sibling) => {
306
- removeDraggingStyles(sibling);
307
- emitFinishRemoveEventToSiblings(draggableElement);
308
- });
309
- onRemoveAtEvent(index, true);
310
- };
311
306
  const removeAtFromElement = (targetIndex) => {
312
- if (!droppableConfigurator.initial) {
313
- return;
314
- }
315
- const config = droppableConfigurator.initial;
316
- if (targetIndex == index) {
317
- addClass(draggableElement, removingClass);
318
- setTimeout(() => {
319
- removeAfterRemovingClass(targetIndex, config);
320
- }, delayBeforeRemove);
321
- }
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
+ });
322
314
  };
323
315
  const insertAtFromElement = (targetIndex, value) => {
324
316
  if (targetIndex === index ||
325
317
  (targetIndex === config.onGetLegth() && index === targetIndex - 1)) {
326
- emitInsertEventToSiblings(targetIndex, draggableElement, parent, value, () => {
327
- 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);
328
321
  });
329
322
  }
330
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
  }
@@ -1,5 +1,5 @@
1
1
  import { Direction } from '..';
2
- import { BeforeMargin, AfterMargin, BorderWidth, PaddingBefore, Before } from '../../../index';
2
+ import { BeforeMargin, AfterMargin, BorderWidth, PaddingBefore, Before, Translate, Coordinate, ElementPosition, ElementScroll, WindowScroll } from '../../../index';
3
3
  export declare const getWindowScroll: () => {
4
4
  scrollX: number;
5
5
  scrollY: number;
@@ -17,12 +17,33 @@ export declare const getScrollElement: (element: HTMLElement) => {
17
17
  scrollLeft: number;
18
18
  scrollTop: number;
19
19
  };
20
+ export declare const getRect: (element: Element) => DOMRect;
21
+ export declare const getDistanceValue: (direction: Direction, translation: Translate) => readonly [number, "width" | "height"];
22
+ export declare const getAxisValue: (direction: Direction, coordinate: Coordinate) => number;
23
+ export declare const getBorderBeforeWidthValue: (direction: Direction, element: Element) => number;
24
+ export declare const getBeforeMarginValue: (direction: Direction, element: Element | null) => number;
25
+ export declare const getBeforeMargin: (direction: Direction, element: Element | null) => number;
26
+ export declare const getAfterMargin: (direction: Direction, element: Element | null) => number;
27
+ export declare const getBefore: (direction: Direction, elementPosition: ElementPosition) => number;
28
+ export declare const getScrollElementValue: (direction: Direction, element: ElementScroll) => readonly [number, "scrollLeft" | "scrollTop"];
29
+ export declare const getScrollValue: (direction: Direction, elementScroll: WindowScroll) => number;
30
+ export declare const getInnerDistance: (direction: Direction, innerElement: {
31
+ innerWidth: number;
32
+ innerHeight: number;
33
+ }) => number;
34
+ export declare const getPageValue: (direction: Direction, event: {
35
+ pageX: number;
36
+ pageY: number;
37
+ }) => number;
38
+ export declare const getOffsetValue: (direction: Direction, event: {
39
+ offsetX: number;
40
+ offsetY: number;
41
+ }) => number;
20
42
  export declare const getPropByDirection: (direction: Direction) => {
21
43
  readonly beforeMargin: "marginTop" | "marginLeft";
22
44
  readonly afterMargin: "marginBottom" | "marginRight";
23
45
  readonly borderBeforeWidth: "borderTopWidth" | "borderLeftWidth";
24
46
  readonly before: "left" | "top";
25
- readonly after: "right" | "down";
26
47
  readonly gap: "columnGap" | "rowGap";
27
48
  readonly distance: "width" | "height";
28
49
  readonly axis: "x" | "y";
@@ -31,7 +52,6 @@ export declare const getPropByDirection: (direction: Direction) => {
31
52
  readonly scrollElement: "scrollLeft" | "scrollTop";
32
53
  readonly page: "pageX" | "pageY";
33
54
  readonly inner: "innerWidth" | "innerHeight";
34
- readonly offsetElement: "offsetLeft" | "offsetTop";
35
55
  readonly scrollDistance: "scrollWidth" | "scrollHeight";
36
56
  readonly clientDistance: "clientWidth" | "clientHeight";
37
57
  readonly paddingBefore: "paddingLeft" | "paddingTop";
@@ -42,3 +62,4 @@ export declare const getGroupDroppables: (currentDroppable: HTMLElement, droppab
42
62
  export declare const getParentDraggableChildren: (parent: HTMLElement) => Element[];
43
63
  export declare const getSiblingsByParent: (current: HTMLElement, parent: HTMLElement) => readonly [Element[], number, HTMLElement];
44
64
  export declare const getNearestFixedParentPosition: (element: Element, direction: Direction) => number;
65
+ export declare const isSameNode: (element1: Element | null | undefined, element2: Element | null) => boolean | undefined;
@@ -84,9 +84,57 @@ export const getScrollElement = (element) => {
84
84
  const { scrollLeft, scrollTop } = element;
85
85
  return { scrollLeft, scrollTop };
86
86
  };
87
- const getRect = (element) => {
87
+ export const getRect = (element) => {
88
88
  return element.getBoundingClientRect();
89
89
  };
90
+ export const getDistanceValue = (direction, translation) => {
91
+ const { distance } = getPropByDirection(direction);
92
+ return [translation[distance], distance];
93
+ };
94
+ export const getAxisValue = (direction, coordinate) => {
95
+ const { axis } = getPropByDirection(direction);
96
+ return coordinate[axis];
97
+ };
98
+ export const getBorderBeforeWidthValue = (direction, element) => {
99
+ const { borderBeforeWidth } = getPropByDirection(direction);
100
+ return getValueFromProperty(element, borderBeforeWidth);
101
+ };
102
+ export const getBeforeMarginValue = (direction, element) => {
103
+ const { beforeMargin } = getPropByDirection(direction);
104
+ return getValueFromProperty(element, beforeMargin);
105
+ };
106
+ export const getBeforeMargin = (direction, element) => {
107
+ const { beforeMargin } = getPropByDirection(direction);
108
+ return getValueFromProperty(element, beforeMargin);
109
+ };
110
+ export const getAfterMargin = (direction, element) => {
111
+ const { afterMargin } = getPropByDirection(direction);
112
+ return getValueFromProperty(element, afterMargin);
113
+ };
114
+ export const getBefore = (direction, elementPosition) => {
115
+ const { before } = getPropByDirection(direction);
116
+ return elementPosition[before];
117
+ };
118
+ export const getScrollElementValue = (direction, element) => {
119
+ const { scrollElement } = getPropByDirection(direction);
120
+ return [element[scrollElement], scrollElement];
121
+ };
122
+ export const getScrollValue = (direction, elementScroll) => {
123
+ const { scroll } = getPropByDirection(direction);
124
+ return elementScroll[scroll];
125
+ };
126
+ export const getInnerDistance = (direction, innerElement) => {
127
+ const { inner } = getPropByDirection(direction);
128
+ return innerElement[inner];
129
+ };
130
+ export const getPageValue = (direction, event) => {
131
+ const { page } = getPropByDirection(direction);
132
+ return event[page];
133
+ };
134
+ export const getOffsetValue = (direction, event) => {
135
+ const { offset } = getPropByDirection(direction);
136
+ return event[offset];
137
+ };
90
138
  export const getPropByDirection = (direction) => {
91
139
  const ifHorizontal = direction == HORIZONTAL;
92
140
  return {
@@ -94,7 +142,6 @@ export const getPropByDirection = (direction) => {
94
142
  afterMargin: ifHorizontal ? 'marginRight' : 'marginBottom',
95
143
  borderBeforeWidth: ifHorizontal ? 'borderLeftWidth' : 'borderTopWidth',
96
144
  before: ifHorizontal ? 'left' : 'top',
97
- after: ifHorizontal ? 'right' : 'down',
98
145
  gap: ifHorizontal ? 'columnGap' : 'rowGap',
99
146
  distance: ifHorizontal ? 'width' : 'height',
100
147
  axis: ifHorizontal ? 'x' : 'y',
@@ -103,7 +150,6 @@ export const getPropByDirection = (direction) => {
103
150
  scrollElement: ifHorizontal ? 'scrollLeft' : 'scrollTop',
104
151
  page: ifHorizontal ? 'pageX' : 'pageY',
105
152
  inner: ifHorizontal ? 'innerWidth' : 'innerHeight',
106
- offsetElement: ifHorizontal ? 'offsetLeft' : 'offsetTop',
107
153
  scrollDistance: ifHorizontal ? 'scrollWidth' : 'scrollHeight',
108
154
  clientDistance: ifHorizontal ? 'clientWidth' : 'clientHeight',
109
155
  paddingBefore: ifHorizontal ? 'paddingLeft' : 'paddingTop',
@@ -142,9 +188,11 @@ const getNearestFixedParent = (element) => {
142
188
  return null; // No fixed parent found
143
189
  };
144
190
  export const getNearestFixedParentPosition = (element, direction) => {
145
- const { before, borderBeforeWidth } = getPropByDirection(direction);
146
191
  const fixedParent = getNearestFixedParent(element);
147
192
  return fixedParent
148
- ? getRect(fixedParent)[before] + getValueFromProperty(fixedParent, borderBeforeWidth)
193
+ ? getBefore(direction, getRect(fixedParent)) + getBorderBeforeWidthValue(direction, fixedParent)
149
194
  : 0;
150
195
  };
196
+ export const isSameNode = (element1, element2) => {
197
+ return element1?.isSameNode(element2);
198
+ };
@@ -1,7 +1,8 @@
1
- import { GapStyle } from "../../../index";
2
- import { Direction } from "..";
1
+ import { GapStyle } from '../../../index';
2
+ import { Direction } from '..';
3
3
  export declare const getNumberFromPixels: (pixels: string | undefined) => number;
4
4
  export declare const computeGapPixels: (element: Element, gapType: GapStyle) => number;
5
5
  export declare const gapAndDisplayInformation: (element: Element | null, gapStyle: GapStyle) => [number, boolean];
6
6
  export declare const getBeforeStyles: (element: HTMLElement) => [number, number];
7
+ export declare const getGapInfo: (element: HTMLElement | null, direction: Direction) => [number, boolean];
7
8
  export declare const getGapPixels: (element: HTMLElement, direction: Direction) => number;