fluid-dnd 2.4.0 → 2.5.1

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 (55) hide show
  1. package/README.md +14 -15
  2. package/dist/{HandlerPublisher-pcX0Zmas.js → HandlerPublisher-CRu7xI9p.js} +1 -1
  3. package/dist/{HandlerPublisher-B68XPAcH.cjs → HandlerPublisher-CrUNmzg-.cjs} +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.d.ts +1 -1
  8. package/dist/core/events/changeDraggableStyles.js +3 -5
  9. package/dist/core/events/dragAndDrop/dragAndDrop.d.ts +1 -1
  10. package/dist/core/events/dragAndDrop/dragAndDrop.js +29 -45
  11. package/dist/core/events/dragAndDrop/getTranslateBeforeDropping.js +30 -30
  12. package/dist/core/events/dragAndDrop/getTranslationByDraggingAndEvent.js +10 -11
  13. package/dist/core/events/insert.d.ts +2 -1
  14. package/dist/core/events/insert.js +4 -10
  15. package/dist/core/events/remove.d.ts +1 -1
  16. package/dist/core/events/remove.js +27 -13
  17. package/dist/core/positioning/autoScroll.js +6 -5
  18. package/dist/core/positioning/usePositioning.d.ts +2 -2
  19. package/dist/core/positioning/usePositioning.js +54 -46
  20. package/dist/core/tempChildren.d.ts +2 -2
  21. package/dist/core/tempChildren.js +32 -31
  22. package/dist/core/useDraggable.js +43 -47
  23. package/dist/core/useDroppable.d.ts +2 -2
  24. package/dist/core/useDroppable.js +11 -19
  25. package/dist/core/utils/GetStyles.d.ts +25 -3
  26. package/dist/core/utils/GetStyles.js +56 -5
  27. package/dist/core/utils/ParseStyles.d.ts +4 -3
  28. package/dist/core/utils/ParseStyles.js +13 -13
  29. package/dist/core/utils/SetStyles.d.ts +4 -8
  30. package/dist/core/utils/SetStyles.js +19 -42
  31. package/dist/core/utils/dom/classList.d.ts +2 -2
  32. package/dist/core/utils/dom/classList.js +2 -11
  33. package/dist/core/utils/index.d.ts +5 -1
  34. package/dist/core/utils/index.js +7 -6
  35. package/dist/fluid-dnd-logo.png +0 -0
  36. package/dist/index-BOqB07mI.cjs +1 -0
  37. package/dist/index-CJpjY7r7.js +1130 -0
  38. package/dist/index.cjs +1 -1
  39. package/dist/index.mjs +2 -2
  40. package/dist/insert--mO_a1mv.js +51 -0
  41. package/dist/insert-CEcy9QNd.cjs +1 -0
  42. package/dist/react/index.cjs +1 -1
  43. package/dist/react/index.mjs +33 -31
  44. package/dist/react/utils/ReactLilstConfig.js +3 -2
  45. package/dist/remove-C4YcWK2S.js +48 -0
  46. package/dist/remove-dSzXNYxs.cjs +1 -0
  47. package/dist/svelte/index.cjs +1 -1
  48. package/dist/svelte/index.mjs +18 -16
  49. package/dist/svelte/utils/SvelteListCondig.js +3 -2
  50. package/dist/vue/index.cjs +1 -1
  51. package/dist/vue/index.mjs +26 -24
  52. package/dist/vue/utils/VueListCondig.js +3 -2
  53. package/package.json +1 -1
  54. package/dist/index-2hBSSK9_.cjs +0 -1
  55. package/dist/index-DFXw7kYo.js +0 -1223
@@ -1,15 +1,15 @@
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';
4
3
  import { DRAG_EVENT, draggableTargetTimingFunction, START_DRAG_EVENT, START_DROP_EVENT } from './utils';
5
4
  import ConfigHandler from './config/configHandler';
6
5
  import { IsHTMLElement, isTouchEvent } from './utils/typesCheckers';
7
- import { addTempChild, addTempChildOnInsert, removeTempChildrens } from './tempChildren';
6
+ import { addTempChild, removeTempChildrens } from './tempChildren';
8
7
  import { DroppableConfigurator } from './config/droppableConfigurator';
9
- import { addClass, containClass, getClassesList, getClassesSelector, removeClass, toggleClass } from './utils/dom/classList';
8
+ import { addClass, containClass, getClassesList, getClassesSelector, toggleClass } from './utils/dom/classList';
10
9
  import { DRAGGABLE_CLASS, DRAGGING_CLASS, DROPPABLE_CLASS, HANDLER_CLASS } from './utils/classes';
11
10
  import useDragAndDropEvents from './events/dragAndDrop/dragAndDrop';
12
- import useInsertEvents from './events/insert';
11
+ import { getRect, isSameNode } from './utils/GetStyles';
12
+ const ON_MOUSEDOWN = 'onmousedown';
13
13
  var DraggingState;
14
14
  (function (DraggingState) {
15
15
  DraggingState[DraggingState["NOT_DRAGGING"] = 0] = "NOT_DRAGGING";
@@ -18,7 +18,7 @@ var DraggingState;
18
18
  DraggingState[DraggingState["END_DRAGGING"] = 3] = "END_DRAGGING";
19
19
  })(DraggingState || (DraggingState = {}));
20
20
  export default function useDraggable(draggableElement, index, config, parent, handlerPublisher) {
21
- const { handlerSelector, isDraggable, droppableGroup, animationDuration, delayBeforeRemove, draggingClass, removingClass, onRemoveAtEvent, droppableClass, onDragStart, delayBeforeTouchMoveEvent, coordinateTransform } = config;
21
+ const { handlerSelector, isDraggable, droppableGroup, animationDuration, draggingClass, droppableClass, onDragStart, delayBeforeTouchMoveEvent, coordinateTransform } = config;
22
22
  const droppableGroupClass = getClassesList(droppableGroup)
23
23
  .map((classGroup) => `droppable-group-${classGroup}`)
24
24
  .join(' ');
@@ -34,9 +34,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
34
34
  const endDraggingState = () => {
35
35
  draggingState = DraggingState.NOT_DRAGGING;
36
36
  };
37
- const [emitRemoveEventToSiblings, emitFinishRemoveEventToSiblings] = useRemoveEvents(config, parent, handlerPublisher, endDraggingState);
38
37
  const [emitDraggingEvent, emitDroppingEvent, toggleDraggingClass] = useDragAndDropEvents(config, index, parent, droppableGroupClass, handlerPublisher, endDraggingState);
39
- const [emitInsertEventToSiblings] = useInsertEvents(config, parent, handlerPublisher, endDraggingState);
40
38
  const setDraggable = () => {
41
39
  addClass(draggableElement, DRAGGABLE_CLASS);
42
40
  };
@@ -65,7 +63,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
65
63
  if (handler &&
66
64
  handlerParent &&
67
65
  containClass(handlerParent, DROPPABLE_CLASS) &&
68
- !handlerParent.isSameNode(parent)) {
66
+ !isSameNode(parent, handlerParent)) {
69
67
  return null;
70
68
  }
71
69
  return handler;
@@ -73,22 +71,22 @@ export default function useDraggable(draggableElement, index, config, parent, ha
73
71
  const setSlotRefElementParams = (element) => {
74
72
  const handlerElement = (getHandler(element) ?? element);
75
73
  if (handlerElement && isDraggable(element)) {
76
- assignDraggingEvent(handlerElement, 'onmousedown', onmousedown('mousemove', 'mouseup'));
74
+ assignDraggingEvent(handlerElement, ON_MOUSEDOWN, onmousedown('mousemove', 'mouseup'));
77
75
  assignDraggingEvent(handlerElement, 'ontouchstart', onmousedown('touchmove', 'touchend'), (event) => {
76
+ const touch = event.touches[0];
78
77
  initialTouch = {
79
- x: event.touches[0].clientX,
80
- y: event.touches[0].clientY
78
+ x: touch.clientX,
79
+ y: touch.clientY
81
80
  };
82
81
  });
83
82
  disableMousedownEventFromImages(handlerElement);
84
83
  }
85
- if (!element?.isSameNode(handlerElement)) {
86
- assignDraggingEvent(element, 'onmousedown', mousedownOnDraggablefunction);
84
+ if (!isSameNode(element, handlerElement)) {
85
+ assignDraggingEvent(element, ON_MOUSEDOWN, mousedownOnDraggablefunction);
87
86
  }
88
87
  addClass(parent, DROPPABLE_CLASS);
89
88
  };
90
89
  const disableMousedownEventFromImages = (handlerElement) => {
91
- // Avoid dragging inner images
92
90
  const images = handlerElement.querySelectorAll('img');
93
91
  Array.from(images).forEach((image) => {
94
92
  image.onmousedown = () => false;
@@ -103,13 +101,20 @@ export default function useDraggable(draggableElement, index, config, parent, ha
103
101
  }
104
102
  const { droppable, config } = droppableConfigurator.current;
105
103
  setTransform(draggableElement, droppable, pagePosition, config.direction);
106
- emitDraggingEvent(draggableElement, DRAG_EVENT, droppableConfigurator.current);
104
+ emitDraggingEvent(draggableElement, DRAG_EVENT, droppable, config);
105
+ };
106
+ const removeTranslates = (droppable) => {
107
+ const drgagables = droppable.querySelectorAll(`.${DRAGGABLE_CLASS}`);
108
+ for (const draggable of drgagables) {
109
+ moveTranslate(draggable);
110
+ }
107
111
  };
108
112
  const changeDroppable = (newdDroppableConfig, oldDroppableConfig) => {
109
113
  if (oldDroppableConfig &&
110
114
  draggingState == DraggingState.DRAGING &&
111
- !newdDroppableConfig?.droppable.isSameNode(oldDroppableConfig.droppable)) {
112
- emitDraggingEvent(draggableElement, DRAG_EVENT, oldDroppableConfig);
115
+ !isSameNode(newdDroppableConfig?.droppable, oldDroppableConfig.droppable)) {
116
+ emitDraggingEvent(draggableElement, DRAG_EVENT, oldDroppableConfig.droppable, oldDroppableConfig.config);
117
+ removeTranslates(oldDroppableConfig.droppable);
113
118
  }
114
119
  };
115
120
  const droppableConfigurator = new DroppableConfigurator(draggableElement, droppableGroupClass, parent, setTransformDragEvent, changeDroppable, config.mapFrom);
@@ -121,7 +126,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
121
126
  ? Array.from(document.querySelectorAll(getClassesSelector(droppableGroupClass)))
122
127
  : [parent];
123
128
  for (const droppable of droppables) {
124
- droppable.classList.toggle(droppableClass, !isOutside && droppable.isSameNode(droppableConfigurator.current.droppable));
129
+ droppable.classList.toggle(droppableClass, !isOutside && isSameNode(droppable, droppableConfigurator.current.droppable));
125
130
  }
126
131
  };
127
132
  const onMove = (event, isTouchEvent = false) => {
@@ -149,8 +154,9 @@ export default function useDraggable(draggableElement, index, config, parent, ha
149
154
  };
150
155
  const cursorWasNotMoved = (event) => {
151
156
  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);
157
+ const touch = event.touches[0];
158
+ const movedX = Math.abs(touch.clientX - initialTouch.x);
159
+ const movedY = Math.abs(touch.clientY - initialTouch.y);
154
160
  if (Math.abs(movedX) > 5 && Math.abs(movedY) > 5) {
155
161
  clearTimeout(delayTimeout);
156
162
  return false;
@@ -184,7 +190,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
184
190
  const { clientX, clientY } = event;
185
191
  const elementBelow = document.elementFromPoint(clientX, clientY);
186
192
  const draggableAncestor = elementBelow?.closest(`.${DRAGGABLE_CLASS}`);
187
- return draggableAncestor && element.isSameNode(draggableAncestor);
193
+ return draggableAncestor && isSameNode(element, draggableAncestor);
188
194
  };
189
195
  const getDragStartEventData = (element) => {
190
196
  const value = config.onGetValue(index);
@@ -233,7 +239,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
233
239
  const disableDragging = (moveEvent, event) => {
234
240
  toggleDroppableClass(true);
235
241
  const convertedEvent = convetEventToDragMouseTouchEvent(event);
236
- onDropDraggingEvent(droppableConfigurator.isOutside(convertedEvent, false));
242
+ onDropDraggingEvent(droppableConfigurator.isOutside(convertedEvent));
237
243
  clearTimeout(delayTimeout);
238
244
  document.removeEventListener(moveEvent, handleMove);
239
245
  droppableConfigurator.updateConfig(convertedEvent);
@@ -258,9 +264,11 @@ export default function useDraggable(draggableElement, index, config, parent, ha
258
264
  }
259
265
  };
260
266
  const startDragging = (event) => {
261
- addTempChild(draggableElement, parent, draggingState == DraggingState.START_DRAGGING, droppableConfigurator.current);
267
+ droppableConfigurator.current &&
268
+ addTempChild(draggableElement, parent, draggingState == DraggingState.START_DRAGGING, droppableConfigurator.current);
262
269
  updateDraggingStateBeforeDragging();
263
- emitDraggingEvent(draggableElement, START_DRAG_EVENT, droppableConfigurator.current);
270
+ droppableConfigurator.current &&
271
+ emitDraggingEvent(draggableElement, START_DRAG_EVENT, droppableConfigurator.current.droppable, droppableConfigurator.current.config);
264
272
  setDraggingStyles(draggableElement);
265
273
  updateTransformState(event, draggableElement);
266
274
  };
@@ -291,10 +299,10 @@ export default function useDraggable(draggableElement, index, config, parent, ha
291
299
  };
292
300
  const removeDraggingStyles = (element) => {
293
301
  setTranistion(element, animationDuration, draggableTargetTimingFunction);
294
- moveTranslate(element, 0, 0);
302
+ moveTranslate(element);
295
303
  };
296
304
  const setDraggingStyles = (element) => {
297
- const { height, width } = element.getBoundingClientRect();
305
+ const { height, width } = getRect(element);
298
306
  setCustomFixedSize(element, {
299
307
  fixedHeight: `${height}px`,
300
308
  fixedWidth: `${width}px`
@@ -303,32 +311,20 @@ export default function useDraggable(draggableElement, index, config, parent, ha
303
311
  toggleClass(element, draggingClass, true);
304
312
  element.style.transition = '';
305
313
  };
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
314
  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
- }
315
+ import('./events/remove').then((module) => {
316
+ const [removeAt] = module.default(config, parent, handlerPublisher, endDraggingState);
317
+ droppableConfigurator.initial &&
318
+ removeAt(index, targetIndex, draggableElement, droppableConfigurator.initial);
319
+ });
326
320
  };
327
321
  const insertAtFromElement = (targetIndex, value) => {
328
322
  if (targetIndex === index ||
329
323
  (targetIndex === config.onGetLegth() && index === targetIndex - 1)) {
330
- emitInsertEventToSiblings(targetIndex, draggableElement, parent, value, () => {
331
- addTempChildOnInsert(draggableElement, draggingState == DraggingState.START_DRAGGING, droppableConfigurator.initial);
324
+ import('./events/insert').then((module) => {
325
+ const [emitInsertEventToSiblings] = module.default(config, parent, handlerPublisher, endDraggingState);
326
+ droppableConfigurator.initial &&
327
+ emitInsertEventToSiblings(targetIndex, draggableElement, parent, value, droppableConfigurator.initial);
332
328
  });
333
329
  }
334
330
  };
@@ -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,25 +1,23 @@
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
- if (droppableGroupClass) {
8
- addMultipleClasses(droppable, droppableGroupClass);
9
- }
7
+ droppableGroupClass && addMultipleClasses(droppable, droppableGroupClass);
10
8
  };
11
9
  const createDraggableCssStyles = () => {
12
10
  AddCssStylesToElement(document.body, [
13
11
  `.${DRAGGABLE_CLASS}{touch-action:manipulation;user-select:none;box-sizing:border-box!important;-webkit-user-select:none;}`,
14
12
  `.${HANDLER_CLASS}{pointer-events:auto!important;}`,
15
13
  `.${GRAB_CLASS}{cursor:grab;}`,
16
- ".temp-child{touch-action:none;pointer-events:none;box-sizing:border-box!important;}",
14
+ '.temp-child{touch-action:none;pointer-events:none;box-sizing:border-box!important;}',
17
15
  `.droppable{box-sizing:border-box!important;}`,
18
16
  `.${DRAGGING_CLASS}{position:fixed;z-index:5000;width:var(--fixedWidth)!important;height:var(--fixedHeight)!important;}`,
19
17
  `.${DRAGGING_HANDLER_CLASS}{pointer-events:none!important;}`,
20
18
  `.${DROPPING_CLASS}{pointer-events:none!important;}`,
21
19
  `.${GRABBING_CLASS}{cursor:grabbing;}`,
22
- `.disable-transition{transition:none!important;}`,
20
+ `.disable-transition{transition:none!important;}`
23
21
  ]);
24
22
  };
25
23
  export default function useDroppable(coreConfig, handlerPublisher, droppable, indexAttr = 'index') {
@@ -28,14 +26,11 @@ export default function useDroppable(coreConfig, handlerPublisher, droppable, in
28
26
  let insertAtFromElementList = [];
29
27
  const { droppableGroup } = coreConfig;
30
28
  if (!droppable) {
31
- return [
32
- removeAtFromElementList,
33
- insertAtFromElementList
34
- ];
29
+ return [removeAtFromElementList, insertAtFromElementList];
35
30
  }
36
31
  const droppableGroupClass = getClassesList(droppableGroup)
37
32
  .map((classGroup) => `droppable-group-${classGroup}`)
38
- .join(" ");
33
+ .join(' ');
39
34
  createDraggableCssStyles();
40
35
  setDroppableGroupClass(droppableGroupClass, droppable);
41
36
  for (const child of droppable.children) {
@@ -48,8 +43,5 @@ export default function useDroppable(coreConfig, handlerPublisher, droppable, in
48
43
  insertAtFromElementList.push(insertAtFromElement);
49
44
  }
50
45
  }
51
- return [
52
- removeAtFromElementList,
53
- insertAtFromElementList
54
- ];
46
+ return [removeAtFromElementList, insertAtFromElementList];
55
47
  }
@@ -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,5 @@ 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;
66
+ export declare const hasTransform: (element: HTMLElement | null) => boolean | null;
@@ -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,14 @@ 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
+ };
199
+ export const hasTransform = (element) => {
200
+ return element && getComputedStyle(element).transform !== 'none';
201
+ };
@@ -1,7 +1,8 @@
1
- import { GapStyle } from "../../../index";
2
- import { Direction } from "..";
3
- export declare const getNumberFromPixels: (pixels: string | undefined) => number;
1
+ import { GapStyle } from '../../../index';
2
+ import { Direction } from '..';
3
+ export declare const getNumberFromPixels: (pixels: string) => 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;
@@ -1,15 +1,15 @@
1
- import { getPropByDirection, parseFloatEmpty } from "./GetStyles";
1
+ import { getPropByDirection, getRect, parseFloatEmpty } from './GetStyles';
2
2
  export const getNumberFromPixels = (pixels) => {
3
- if (!pixels || pixels.length == 0) {
3
+ if (pixels.length == 0) {
4
4
  return 0;
5
5
  }
6
- return parseFloatEmpty(pixels.replace("px", ""));
6
+ return parseFloatEmpty(pixels.replace('px', ''));
7
7
  };
8
8
  export const computeGapPixels = (element, gapType) => {
9
9
  const gap = getComputedStyle(element)[gapType];
10
- if (gap.match("%")) {
11
- const gap_percent = parseFloatEmpty(gap.replace("%", ""));
12
- const { width } = element.getBoundingClientRect();
10
+ if (gap.match('%')) {
11
+ const gap_percent = parseFloatEmpty(gap.replace('%', ''));
12
+ const { width } = getRect(element);
13
13
  return width * (gap_percent / 100);
14
14
  }
15
15
  const gap_px = getNumberFromPixels(gap);
@@ -17,22 +17,22 @@ export const computeGapPixels = (element, gapType) => {
17
17
  };
18
18
  export const gapAndDisplayInformation = (element, gapStyle) => {
19
19
  if (!(element instanceof Element))
20
- return [
21
- 0,
22
- false,
23
- ];
20
+ return [0, false];
24
21
  const gap = computeGapPixels(element, gapStyle);
25
22
  const display = getComputedStyle(element).display;
26
- const hasGaps = gap > 0 || display === "flex";
23
+ const hasGaps = gap > 0 || display === 'flex';
27
24
  return [gap, hasGaps];
28
25
  };
29
26
  export const getBeforeStyles = (element) => {
30
27
  const { top, left } = getComputedStyle(element);
31
28
  return [getNumberFromPixels(top), getNumberFromPixels(left)];
32
29
  };
33
- export const getGapPixels = (element, direction) => {
30
+ export const getGapInfo = (element, direction) => {
34
31
  const { gap: gapStyle } = getPropByDirection(direction);
35
- const [gap, hasGaps] = gapAndDisplayInformation(element, gapStyle);
32
+ return gapAndDisplayInformation(element, gapStyle);
33
+ };
34
+ export const getGapPixels = (element, direction) => {
35
+ const [gap, hasGaps] = getGapInfo(element, direction);
36
36
  if (hasGaps) {
37
37
  return gap;
38
38
  }
@@ -1,20 +1,16 @@
1
- import { DragMouseTouchEvent, fixedSize } from '../../../index';
1
+ import { DragMouseTouchEvent, fixedSize, Translate } from '../../../index';
2
2
  type onTouchEvent = 'ontouchstart' | 'ontouchmove' | 'ontouchend';
3
3
  declare const onMouseEvents: readonly ["onmouseup", "onmousedown", "onmousemove"];
4
4
  type onMouseEvent = (typeof onMouseEvents)[number];
5
- type TouchEventType = 'touchstart' | 'touchmove' | 'touchend';
6
- declare const mouseEvents: readonly ["mouseup", "mousedown", "mousemove"];
7
- type MouseEventType = (typeof mouseEvents)[number];
8
5
  type DragEventCallback = (event: DragMouseTouchEvent) => void;
9
6
  type TouchEventCallback = (event: TouchEvent) => void;
10
- export declare const setSizeStyles: (element: HTMLElement | undefined | null, height: number, width: number) => void;
11
- export declare const fixSizeStyle: (element: HTMLElement | undefined | null) => void;
12
- export declare const moveTranslate: (element: Element | undefined | null, height: number, width: number) => void;
7
+ export declare const setSizeStyles: (element: HTMLElement, translate: Translate) => void;
8
+ export declare const moveTranslate: (element: Element | undefined | null, translation?: Translate) => void;
13
9
  export declare const assignDraggingEvent: (element: HTMLElement, onEvent: onMouseEvent | onTouchEvent, callback: DragEventCallback | null, touchCallback?: TouchEventCallback) => void;
14
- export declare const addDragMouseToucEventListener: (event: TouchEventType | MouseEventType, callback: DragEventCallback | null) => void;
15
10
  export declare const convetEventToDragMouseTouchEvent: (event: MouseEvent | TouchEvent) => DragMouseTouchEvent;
16
11
  export declare const setTranistion: (element: Element | undefined, duration: number, timingFunction?: string, types?: string) => void;
17
12
  export declare const setEventWithInterval: (element: Element | undefined, eventName: "onscroll", callback: () => void) => void;
18
13
  export declare const AddCssStylesToElement: (node: ParentNode, cssCodes: string[]) => void;
19
14
  export declare const setCustomFixedSize: (element: HTMLElement | undefined, fixedProps?: fixedSize) => void;
15
+ export declare const removeTranslateWhitoutTransition: (element?: Element) => void;
20
16
  export {};
@@ -1,31 +1,21 @@
1
+ import { NONE_TRANSLATE } from '.';
1
2
  import { HORIZONTAL, VERTICAL } from '..';
2
- import { getPropByDirection, getValueFromProperty } from './GetStyles';
3
+ import { getBefore, getBorderBeforeWidthValue, getPageValue, getRect, getScrollValue } from './GetStyles';
3
4
  import { IsHTMLElement, IsMouseEvent, isTouchEvent } from './typesCheckers';
4
5
  const onMouseEvents = ['onmouseup', 'onmousedown', 'onmousemove'];
5
- const mouseEvents = ['mouseup', 'mousedown', 'mousemove'];
6
- export const setSizeStyles = (element, height, width) => {
7
- if (!element) {
8
- return;
9
- }
10
- element.style.height = `${height}px`;
11
- element.style.width = `${width}px`;
12
- };
13
- export const fixSizeStyle = (element) => {
14
- if (!element) {
15
- return;
16
- }
17
- const { height, width } = element.getBoundingClientRect();
18
- setSizeStyles(element, height, width);
6
+ export const setSizeStyles = (element, translate) => {
7
+ element.style.height = `${translate.height}px`;
8
+ element.style.width = `${translate.width}px`;
19
9
  };
20
- export const moveTranslate = (element, height, width) => {
10
+ export const moveTranslate = (element, translation = NONE_TRANSLATE) => {
21
11
  if (!element || !IsHTMLElement(element)) {
22
12
  return;
23
13
  }
24
- if (width == 0 && height == 0) {
14
+ if (translation.width == 0 && translation.height == 0) {
25
15
  element.style.transform = '';
26
16
  }
27
17
  else {
28
- element.style.transform = `translate(${width}px,${height}px)`;
18
+ element.style.transform = `translate(${translation.width}px,${translation.height}px)`;
29
19
  }
30
20
  };
31
21
  const assignDraggingTouchEvent = (element, onEvent, callback, touchCallback) => {
@@ -49,22 +39,7 @@ export const assignDraggingEvent = (element, onEvent, callback, touchCallback) =
49
39
  assignDraggingTouchEvent(element, onEvent, callback, touchCallback);
50
40
  }
51
41
  };
52
- export const addDragMouseToucEventListener = (event, callback) => {
53
- if (!callback) {
54
- return;
55
- }
56
- if (isMouseEvent(event)) {
57
- document.addEventListener(event, callback);
58
- }
59
- else {
60
- document.addEventListener(event, (event) => {
61
- const dragMouseTouchEvent = convetEventToDragMouseTouchEvent(event);
62
- callback(dragMouseTouchEvent);
63
- });
64
- }
65
- };
66
42
  const isOnMouseEvent = (x) => onMouseEvents.includes(x);
67
- const isMouseEvent = (x) => mouseEvents.includes(x);
68
43
  const getDefaultEvent = (event) => {
69
44
  const { target } = event;
70
45
  return {
@@ -123,12 +98,11 @@ const getEvent = (event) => {
123
98
  }
124
99
  };
125
100
  const getOffset = (event, window, direction, element) => {
126
- const { page, scroll, before, borderBeforeWidth, getRect } = getPropByDirection(direction);
127
101
  const boundingClientRect = getRect(element);
128
- return (event[page] -
129
- window[scroll] -
130
- boundingClientRect[before] -
131
- getValueFromProperty(element, borderBeforeWidth));
102
+ return (getPageValue(direction, event) -
103
+ getScrollValue(direction, window) -
104
+ getBefore(direction, boundingClientRect) -
105
+ getBorderBeforeWidthValue(direction, element));
132
106
  };
133
107
  export const setTranistion = (element, duration, timingFunction = 'ease-out', types = 'transform') => {
134
108
  if (IsHTMLElement(element)) {
@@ -172,10 +146,7 @@ export const AddCssStylesToElement = (node, cssCodes) => {
172
146
  };
173
147
  const AddCssStyleToElement = (node, cssCode) => {
174
148
  var style = getStyles(node);
175
- if (!style.sheet) {
176
- return;
177
- }
178
- if (!containRule(style.sheet, cssCode)) {
149
+ if (style.sheet && !containRule(style.sheet, cssCode)) {
179
150
  style.sheet?.insertRule(cssCode, style.sheet.cssRules.length);
180
151
  }
181
152
  };
@@ -190,3 +161,9 @@ export const setCustomFixedSize = (element, fixedProps = {}) => {
190
161
  const setCustomProperty = (element, fixedProp, newFixedSize) => {
191
162
  return element && element.style.setProperty(fixedProp, newFixedSize);
192
163
  };
164
+ export const removeTranslateWhitoutTransition = (element) => {
165
+ if (IsHTMLElement(element)) {
166
+ element.style.transition = '';
167
+ element.style.transform = '';
168
+ }
169
+ };
@@ -3,6 +3,6 @@ export declare const toggleClass: (element: Element, cssClass: string, force?: b
3
3
  export declare const addClass: (element: Element, cssClass: string) => void;
4
4
  export declare const removeClass: (element: Element, cssClass: string) => void;
5
5
  export declare const containstClasses: (element: HTMLElement, classes: string) => boolean;
6
- export declare const getClassesSelector: (classes: string | null) => string;
7
- export declare const addMultipleClasses: (element: HTMLElement, classes: string | null) => void;
6
+ export declare const getClassesSelector: (classes: string) => string;
7
+ export declare const addMultipleClasses: (element: HTMLElement, classes: string) => void;
8
8
  export declare const getClassesList: (classes: string | null | undefined) => string[];
@@ -14,22 +14,13 @@ export const containstClasses = (element, classes) => {
14
14
  return getClassesList(classes).every((cssClass) => containClass(element, cssClass));
15
15
  };
16
16
  export const getClassesSelector = (classes) => {
17
- if (!classes) {
18
- return "";
19
- }
20
- const classesSelector = getClassesList(classes).join(".");
17
+ const classesSelector = getClassesList(classes).join('.');
21
18
  return `.${classesSelector}`;
22
19
  };
23
20
  export const addMultipleClasses = (element, classes) => {
24
- if (!classes) {
25
- return;
26
- }
27
21
  const classesList = getClassesList(classes);
28
22
  element.classList.add(...classesList);
29
23
  };
30
24
  export const getClassesList = (classes) => {
31
- if (!classes) {
32
- return [];
33
- }
34
- return classes.split(" ").filter((cssClass) => cssClass);
25
+ return (classes?.split(' ') ?? []).filter((cssClass) => cssClass);
35
26
  };