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
package/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  <h1 align="center">
2
- <img src="public/fluid-dnd.svg"
3
- alt="Icon" width="150" height="140" />
4
- <br>Fluid DnD<br>
2
+ <img src="public/fluid-dnd-logo.png"
3
+ alt="Icon" width="200" height="200" />
5
4
  </h1>
6
5
 
7
6
  <div align="center">
@@ -11,15 +10,20 @@
11
10
  [![version](https://img.shields.io/npm/v/fluid-dnd)](https://www.npmjs.com/package/fluid-dnd)
12
11
  ![GitHub issues](https://img.shields.io/github/issues/carlosjorger/fluid-dnd)
13
12
  ![GitHub stars](https://img.shields.io/github/stars/carlosjorger/fluid-dnd)
14
- [![test_coverage](https://api.codeclimate.com/v1/badges/6b27047dcf150ccddfac/test_coverage)](https://codeclimate.com/github/carlosjorger/fluid-dnd/test_coverage)
15
13
 
16
- </div>
14
+ _Drag and drop elements of your list smoothly and effortlessly_
17
15
 
18
- Fluid DnD is a [**fluid**, **agnostic** and **versatile** drag and drop
19
- library for lists; with support for **Vue**, **React** and **Svelte**](https://fluid-dnd.netlify.app/). It's a **lightweight** tool ~8 Kb (gzip) with no depenencies.
16
+ [📖 **Documentation**](https://fluid-dnd.netlify.app/) | [🤹 **Examples**](https://fluid-dnd.netlify.app/vue/example/vertical-list/single-vertical-list/)
20
17
 
21
18
  <img src="https://github.com/user-attachments/assets/1b7ac5e3-48e9-43f9-a577-e78c6b9eacae" width="100%"/>
22
19
 
20
+ </div>
21
+
22
+ ## 🪪 About
23
+
24
+ Fluid DnD is a **fluid**, **agnostic** and **versatile** drag and drop
25
+ library for lists; with support for **Vue**, **React** and **Svelte**. It's a **lightweight** tool ~8 Kb (gzip) with no depenencies.
26
+
23
27
  ## 🧰 Features
24
28
 
25
29
  - ✅ **Fully customizable 🎨**.
@@ -50,21 +54,16 @@ library for lists; with support for **Vue**, **React** and **Svelte**](https://f
50
54
  pnpm i fluid-dnd
51
55
  ```
52
56
 
53
- 3. **Documentation**
54
-
55
- - 📚 Check out all the [docs](https://fluid-dnd.netlify.app/).
56
- - 🛠️ Edit this example [here](https://codesandbox.io/s/nifty-hooks-5plkpl).
57
- - 📘 See other examples [here](https://fluid-dnd.netlify.app/vue/example/vertical-list/single-vertical-list/).
58
-
59
57
  ## 📚 Libraries Support
58
+
60
59
  - **Vue** >=3.0.0
61
60
  - **React** >= 18.0.0
62
61
  - **Svelte** >= 5.0.0
63
62
 
64
63
  ## 🤝 Contributing
65
64
 
66
- If you're interested in contributing to [fluid-dnd](https://github.com/carlosjorger/fluid-dnd), please read our [CONTRIBUTING GUIDELINES](./CONTRIBUTING.md) before submitting a pull request.
65
+ If you're interested in contributing to [fluid-dnd](https://github.com/carlosjorger/fluid-dnd), please read our [CONTRIBUTING GUIDELINES](./CONTRIBUTING.md) before submitting a pull request.
67
66
 
68
67
  ## 🔑 License
69
68
 
70
- - [MIT](https://github.com/carlosjorger/fluid-dnd/blob/main/LICENSE).
69
+ - [MIT](https://github.com/carlosjorger/fluid-dnd/blob/main/LICENSE).
@@ -1,7 +1,7 @@
1
1
  var d = Object.defineProperty;
2
2
  var e = (a, s, l) => s in a ? d(a, s, { enumerable: !0, configurable: !0, writable: !0, value: l }) : a[s] = l;
3
3
  var r = (a, s, l) => e(a, typeof s != "symbol" ? s + "" : s, l);
4
- import { a as h, t as n, G as t } from "./index-DFXw7kYo.js";
4
+ import { a as h, t as n, G as t } from "./index-CJpjY7r7.js";
5
5
  class c {
6
6
  constructor() {
7
7
  r(this, "handlers");
@@ -1 +1 @@
1
- "use strict";var d=Object.defineProperty;var n=(e,s,l)=>s in e?d(e,s,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[s]=l;var a=(e,s,l)=>n(e,typeof s!="symbol"?s+"":s,l);const r=require("./index-2hBSSK9_.cjs");class h{constructor(){a(this,"handlers");this.handlers=[]}addSubscriber(s){this.handlers.includes(s)||(this.handlers.push(s),r.addClass(s,r.GRAB_CLASS))}toggleGrabClass(s){for(const l of this.handlers)r.toggleClass(l,r.GRAB_CLASS,s)}}exports.HandlerPublisher=h;
1
+ "use strict";var d=Object.defineProperty;var n=(e,s,l)=>s in e?d(e,s,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[s]=l;var a=(e,s,l)=>n(e,typeof s!="symbol"?s+"":s,l);const r=require("./index-BOqB07mI.cjs");class h{constructor(){a(this,"handlers");this.handlers=[]}addSubscriber(s){this.handlers.includes(s)||(this.handlers.push(s),r.addClass(s,r.GRAB_CLASS))}toggleGrabClass(s){for(const l of this.handlers)r.toggleClass(l,r.GRAB_CLASS,s)}}exports.HandlerPublisher=h;
@@ -1,9 +1,9 @@
1
- import { getScrollElement } from '../utils/GetStyles';
1
+ import { getScrollElement, isSameNode } from '../utils/GetStyles';
2
2
  import { containstClasses } from '../utils/dom/classList';
3
3
  export default class ConfigHandler {
4
4
  static configs = [];
5
5
  static addConfig(droppable, config) {
6
- const configs = ConfigHandler.configs.filter((configHandler) => !configHandler.droppable.isSameNode(droppable));
6
+ const configs = ConfigHandler.configs.filter((configHandler) => !isSameNode(configHandler.droppable, droppable));
7
7
  const scroll = getScrollElement(droppable);
8
8
  configs.push({
9
9
  droppable,
@@ -20,13 +20,13 @@ export default class ConfigHandler {
20
20
  for (const configHandler of ConfigHandler.configs) {
21
21
  const { droppable } = configHandler;
22
22
  if ((droppableGroupClass && containstClasses(droppable, droppableGroupClass)) ||
23
- droppable.isSameNode(currentDroppable)) {
23
+ isSameNode(currentDroppable, droppable)) {
24
24
  configHandler.scroll = getScrollElement(droppable);
25
25
  }
26
26
  }
27
27
  }
28
28
  static getConfig(curerntDroppable) {
29
- const config = ConfigHandler.configs.find(({ droppable }) => droppable.isSameNode(curerntDroppable));
29
+ const config = ConfigHandler.configs.find(({ droppable }) => isSameNode(curerntDroppable, droppable));
30
30
  return config;
31
31
  }
32
32
  }
@@ -19,7 +19,8 @@ export declare class DroppableConfigurator<T> {
19
19
  private onScrollEvent;
20
20
  private setOnScroll;
21
21
  getConfigFrom(element: Element): DroppableConfig<any> | undefined;
22
+ droppableIfInsideCurrent(droppable: Element | null | undefined, current: HTMLElement): boolean | null | undefined;
22
23
  getCurrentConfig(event: DragMouseTouchEvent): DroppableConfig<any> | DroppableConfig<T> | undefined;
23
24
  updateConfig(event: DragMouseTouchEvent): void;
24
- isOutside(event: DragMouseTouchEvent, hiddenDraggable?: boolean): boolean;
25
+ isOutside(event: DragMouseTouchEvent): boolean;
25
26
  }
@@ -1,5 +1,5 @@
1
1
  import ConfigHandler from './configHandler';
2
- import { draggableIsOutside } from '../utils/GetStyles';
2
+ import { draggableIsOutside, isSameNode } from '../utils/GetStyles';
3
3
  import { IsHTMLElement } from '../utils/typesCheckers';
4
4
  import { setEventWithInterval } from '../utils/SetStyles';
5
5
  import { getClassesSelector } from '../utils/dom/classList';
@@ -34,32 +34,23 @@ export class DroppableConfigurator {
34
34
  this.groupClass = droppableGroupClass;
35
35
  this.dragEvent = setTransformDragEvent;
36
36
  this.mapFrom = mapFrom;
37
- this.initial = parent ? ConfigHandler.getConfig(parent) : undefined;
37
+ this.initial = ConfigHandler.getConfig(parent);
38
38
  this.changeDroppable = changeDroppable;
39
39
  }
40
40
  getDraggableAncestor(clientX, clientY, draggable) {
41
41
  return document
42
42
  .elementsFromPoint(clientX, clientY)
43
- .filter((element) => !element.isSameNode(draggable));
43
+ .filter((element) => !isSameNode(draggable, element));
44
44
  }
45
- getElementBelow(currentElement, event, hiddenDraggable = true) {
45
+ getElementBelow(currentElement, event) {
46
46
  const getElementBelow = (config) => {
47
47
  const [elementBelow] = config.getDraggableAncestor(event.clientX, event.clientY, currentElement);
48
48
  return elementBelow;
49
49
  };
50
- let elementBelow = null;
51
- if (hiddenDraggable) {
52
- currentElement.hidden = true;
53
- elementBelow = getElementBelow(this);
54
- currentElement.hidden = false;
55
- }
56
- else {
57
- elementBelow = getElementBelow(this);
58
- }
59
- return elementBelow;
50
+ return getElementBelow(this);
60
51
  }
61
- getCurrent(currentElement, event, hiddenDraggable = true) {
62
- const elementBelow = this.getElementBelow(currentElement, event, hiddenDraggable);
52
+ getCurrent(currentElement, event) {
53
+ const elementBelow = this.getElementBelow(currentElement, event);
63
54
  if (!this.groupClass || !elementBelow) {
64
55
  return;
65
56
  }
@@ -89,7 +80,7 @@ export class DroppableConfigurator {
89
80
  if (!coreConfig) {
90
81
  return undefined;
91
82
  }
92
- if (element.isSameNode(this.parent)) {
83
+ if (isSameNode(this.parent, element)) {
93
84
  return coreConfig;
94
85
  }
95
86
  return {
@@ -97,12 +88,17 @@ export class DroppableConfigurator {
97
88
  config: MapConfig(coreConfig, this.mapFrom)
98
89
  };
99
90
  }
91
+ droppableIfInsideCurrent(droppable, current) {
92
+ return droppable && !isSameNode(current, droppable) && current.contains(droppable);
93
+ }
100
94
  getCurrentConfig(event) {
101
95
  const currentElement = this.draggableElement;
102
- if (this.current && this.isNotInsideAnotherDroppable(currentElement, this.current?.droppable)) {
96
+ const currentDroppable = this.getCurrent(currentElement, event);
97
+ if (this.current &&
98
+ this.isNotInsideAnotherDroppable(currentElement, this.current?.droppable) &&
99
+ !this.droppableIfInsideCurrent(currentDroppable, this.current?.droppable)) {
103
100
  return this.current;
104
101
  }
105
- const currentDroppable = this.getCurrent(currentElement, event);
106
102
  if (!currentDroppable) {
107
103
  return this.getConfigFrom(this.parent);
108
104
  }
@@ -116,8 +112,8 @@ export class DroppableConfigurator {
116
112
  this.current = this.getCurrentConfig(event);
117
113
  this.changeDroppable(this.current, oldDroppableConfig);
118
114
  }
119
- isOutside(event, hiddenDraggable = true) {
115
+ isOutside(event) {
120
116
  const currentElement = this.draggableElement;
121
- return !Boolean(this.getCurrent(currentElement, event, hiddenDraggable));
117
+ return !Boolean(this.getCurrent(currentElement, event));
122
118
  }
123
119
  }
@@ -1,4 +1,4 @@
1
1
  import { Translate } from 'index';
2
2
  import { CoreConfig } from '..';
3
3
  import HandlerPublisher from '../HandlerPublisher';
4
- export declare const useChangeDraggableStyles: <T>(currentConfig: CoreConfig<T>, handlerPublisher: HandlerPublisher, endDraggingAction: () => void) => readonly [(element: HTMLElement) => void, (element: Element, force: boolean) => void, (element: Element, translation: Translate) => void];
4
+ export declare const useChangeDraggableStyles: <T>(currentConfig: CoreConfig<T>, handlerPublisher: HandlerPublisher, endDraggingAction: () => void) => readonly [(element: HTMLElement) => void, (element: Element, force: boolean) => void, (element: Element, translation?: Translate) => void];
@@ -1,14 +1,13 @@
1
1
  import { DRAGGING_CLASS, DRAGGING_HANDLER_CLASS, GRABBING_CLASS } from '../utils/classes';
2
2
  import { toggleClass } from '../utils/dom/classList';
3
- import { moveTranslate, setCustomFixedSize, setTranistion } from '../utils/SetStyles';
3
+ import { moveTranslate, removeTranslateWhitoutTransition, setCustomFixedSize, setTranistion } from '../utils/SetStyles';
4
4
  import { draggableTargetTimingFunction } from '../utils';
5
5
  export const useChangeDraggableStyles = (currentConfig, handlerPublisher, endDraggingAction) => {
6
6
  const { handlerSelector, animationDuration } = currentConfig;
7
7
  const removeElementDraggingStyles = (element) => {
8
8
  endDraggingAction();
9
9
  toggleDraggingClass(element, false);
10
- element.style.transform = '';
11
- element.style.transition = '';
10
+ removeTranslateWhitoutTransition(element);
12
11
  element.style.top = '';
13
12
  element.style.left = '';
14
13
  setCustomFixedSize(element, {
@@ -32,9 +31,8 @@ export const useChangeDraggableStyles = (currentConfig, handlerPublisher, endDra
32
31
  }
33
32
  };
34
33
  const dragEventOverElement = (element, translation) => {
35
- const { width, height } = translation;
36
- moveTranslate(element, height, width);
37
34
  setTranistion(element, animationDuration, draggableTargetTimingFunction);
35
+ moveTranslate(element, translation);
38
36
  };
39
37
  return [removeElementDraggingStyles, toggleDraggingClass, dragEventOverElement];
40
38
  };
@@ -5,5 +5,5 @@ import { DroppableConfig } from '../../config/configHandler';
5
5
  import HandlerPublisher from '../../HandlerPublisher';
6
6
  type DraggingEvent = typeof DRAG_EVENT | typeof START_DRAG_EVENT;
7
7
  type DropEvent = 'drop' | typeof START_DROP_EVENT;
8
- export default function useDragAndDropEvents<T>(currentConfig: CoreConfig<T>, index: number, parent: HTMLElement, droppableGroupClass: string | null, handlerPublisher: HandlerPublisher, endDraggingAction: () => void): readonly [(draggedElement: HTMLElement, event: DraggingEvent, droppableConfig: DroppableConfig<T> | undefined) => void, (draggedElement: HTMLElement, event: DropEvent, droppableConfig: DroppableConfig<T> | undefined, initialWindowScroll: WindowScroll, positionOnSourceDroppable?: number) => void, (element: Element, force: boolean) => void];
8
+ export default function useDragAndDropEvents<T>(currentConfig: CoreConfig<T>, index: number, parent: HTMLElement, droppableGroupClass: string | null, handlerPublisher: HandlerPublisher, endDraggingAction: () => void): readonly [(draggedElement: HTMLElement, event: DraggingEvent, droppable: HTMLElement, config: CoreConfig<T>) => void, (draggedElement: HTMLElement, event: DropEvent, droppableConfig: DroppableConfig<T> | undefined, initialWindowScroll: WindowScroll, positionOnSourceDroppable?: number) => void, (element: Element, force: boolean) => void];
9
9
  export {};
@@ -1,8 +1,8 @@
1
- import { draggableIsOutside, getPropByDirection, getSiblings, getTransform, getWindowScroll } from '../../utils/GetStyles';
2
- import { moveTranslate } from '../../utils/SetStyles';
1
+ import { draggableIsOutside, getAxisValue, getBefore, getDistanceValue, getRect, getSiblings, getTransform, getWindowScroll, isSameNode } from '../../utils/GetStyles';
2
+ import { moveTranslate, removeTranslateWhitoutTransition } from '../../utils/SetStyles';
3
3
  import getTranslationByDragging from './getTranslationByDraggingAndEvent';
4
4
  import getTranslateBeforeDropping from './getTranslateBeforeDropping';
5
- import { DRAG_EVENT, START_DRAG_EVENT, START_DROP_EVENT, TEMP_CHILD_CLASS } from '../../utils';
5
+ import { DRAG_EVENT, NONE_TRANSLATE, START_DRAG_EVENT, START_DROP_EVENT, TEMP_CHILD_CLASS } from '../../utils';
6
6
  import { IsHTMLElement } from '../../utils/typesCheckers';
7
7
  import { removeTempChild } from '../../tempChildren';
8
8
  import { DRAGGABLE_CLASS, DROPPING_CLASS } from '../../utils/classes';
@@ -11,37 +11,33 @@ import { useChangeDraggableStyles } from '../changeDraggableStyles';
11
11
  const DELAY_TIME_TO_SWAP = 50;
12
12
  export default function useDragAndDropEvents(currentConfig, index, parent, droppableGroupClass, handlerPublisher, endDraggingAction) {
13
13
  let actualIndex = index;
14
- const { direction, onRemoveAtEvent, animationDuration, draggingClass } = currentConfig;
14
+ const { onRemoveAtEvent, animationDuration, draggingClass } = currentConfig;
15
15
  const [removeElementDraggingStyles, toggleDraggingClass, dragEventOverElement] = useChangeDraggableStyles(currentConfig, handlerPublisher, endDraggingAction);
16
- const emitDraggingEvent = (draggedElement, event, droppableConfig) => {
17
- if (!droppableConfig) {
18
- return;
19
- }
20
- const { droppable, config } = droppableConfig;
16
+ const emitDraggingEvent = (draggedElement, event, droppable, config) => {
21
17
  const tranlation = getTranslationByDragging(draggedElement, event, config.direction, droppable);
22
- emitDraggingEventToSiblings(draggedElement, event, tranlation, droppableConfig);
18
+ emitDraggingEventToSiblings(draggedElement, event, tranlation, droppable, config);
23
19
  };
24
20
  const emitDroppingEvent = (draggedElement, event, droppableConfig, initialWindowScroll, positionOnSourceDroppable) => {
25
21
  if (!droppableConfig) {
26
22
  return;
27
23
  }
28
- const { droppable, config } = droppableConfig;
24
+ const { droppable, scroll, config } = droppableConfig;
29
25
  const tranlation = getTranslationByDragging(draggedElement, event, config.direction, droppable);
30
- emitDroppingEventToSiblings(draggedElement, event, tranlation, initialWindowScroll, droppableConfig, positionOnSourceDroppable);
26
+ emitDroppingEventToSiblings(draggedElement, event, tranlation, initialWindowScroll, droppable, scroll, config, positionOnSourceDroppable);
31
27
  };
32
28
  // #region Drag events
33
- const emitDraggingEventToSiblings = (draggedElement, event, translation, droppableConfig) => {
34
- const { config, droppable } = droppableConfig;
29
+ const emitDraggingEventToSiblings = (draggedElement, event, translation, droppable, config) => {
35
30
  const [siblings] = getSiblings(draggedElement, droppable);
36
31
  const isOutside = draggableIsOutside(draggedElement, droppable);
32
+ const { direction } = config;
37
33
  if (siblings.length == 0) {
38
- updateActualIndexBaseOnTranslation(translation, 1, config.direction, siblings);
34
+ updateActualIndexBaseOnTranslation(translation, 1, direction, siblings);
39
35
  }
40
36
  for (const [index, sibling] of siblings.entries()) {
41
37
  if (!containClass(sibling, DRAGGABLE_CLASS)) {
42
38
  continue;
43
39
  }
44
- const siblingTransition = canChangeDraggable(config.direction, draggedElement, sibling, translation);
40
+ const siblingTransition = canChangeDraggable(direction, draggedElement, sibling, translation);
45
41
  if (!isOutside && siblingTransition) {
46
42
  translation = siblingTransition;
47
43
  }
@@ -49,9 +45,9 @@ export default function useDragAndDropEvents(currentConfig, index, parent, dropp
49
45
  continue;
50
46
  }
51
47
  const siblingRealIndex = siblings.length - index;
52
- updateActualIndexBaseOnTranslation(translation, siblingRealIndex, config.direction, siblings);
48
+ updateActualIndexBaseOnTranslation(translation, siblingRealIndex, direction, siblings);
53
49
  if (event === START_DRAG_EVENT) {
54
- startDragEventOverElement(sibling, translation);
50
+ moveTranslate(sibling, translation);
55
51
  }
56
52
  else if (event === DRAG_EVENT) {
57
53
  dragEventOverElement(sibling, translation);
@@ -59,24 +55,23 @@ export default function useDragAndDropEvents(currentConfig, index, parent, dropp
59
55
  }
60
56
  };
61
57
  const canChangeDraggable = (direction, sourceElement, targetElement, translation) => {
62
- const { before, distance, axis, getRect } = getPropByDirection(direction);
63
58
  const currentBoundingClientRect = getRect(sourceElement);
64
59
  const targetBoundingClientRect = getRect(targetElement);
65
- const currentPosition = currentBoundingClientRect[before];
66
- const targetPosition = targetBoundingClientRect[before];
67
- const targetSize = targetBoundingClientRect[distance];
60
+ const currentPosition = getBefore(direction, currentBoundingClientRect);
61
+ const targetPosition = getBefore(direction, targetBoundingClientRect);
62
+ const [targetSize] = getDistanceValue(direction, targetBoundingClientRect);
68
63
  const targetMiddle = targetPosition + targetSize / 2;
69
- const targetTransform = getTransform(targetElement)[axis];
64
+ const targetTransform = getAxisValue(direction, getTransform(targetElement));
70
65
  const targetMiddleWithoutTransform = targetMiddle - targetTransform;
71
66
  if (currentPosition > targetMiddleWithoutTransform) {
72
- return { height: 0, width: 0 };
67
+ return NONE_TRANSLATE;
73
68
  }
74
69
  return translation;
75
70
  };
76
71
  const updateActualIndexBaseOnTranslation = (translation, siblingIndex, direction, siblings) => {
77
72
  const itemsCount = siblings.filter((sibling) => containClass(sibling, DRAGGABLE_CLASS)).length;
78
- const { distance } = getPropByDirection(direction);
79
- if (translation[distance] == 0) {
73
+ const [distance] = getDistanceValue(direction, translation);
74
+ if (distance == 0) {
80
75
  actualIndex = Math.max(actualIndex, siblingIndex);
81
76
  }
82
77
  else {
@@ -84,13 +79,8 @@ export default function useDragAndDropEvents(currentConfig, index, parent, dropp
84
79
  }
85
80
  actualIndex = Math.min(actualIndex, itemsCount);
86
81
  };
87
- const startDragEventOverElement = (element, translation) => {
88
- const { width, height } = translation;
89
- moveTranslate(element, height, width);
90
- };
91
82
  // #region Drop events
92
- const emitDroppingEventToSiblings = (draggedElement, event, translation, initialWindowScroll, droppableConfig, positionOnSourceDroppable) => {
93
- const { droppable, scroll, config } = droppableConfig;
83
+ const emitDroppingEventToSiblings = (draggedElement, event, translation, initialWindowScroll, droppable, scroll, config, positionOnSourceDroppable) => {
94
84
  const [siblings, positionOnDroppable] = getSiblings(draggedElement, droppable);
95
85
  const allSiblings = siblings.toReversed();
96
86
  const realPositionOnDroppable = positionOnDroppable === -1 ? allSiblings.length : positionOnDroppable;
@@ -105,7 +95,7 @@ export default function useDragAndDropEvents(currentConfig, index, parent, dropp
105
95
  for (const [index, sibling] of siblings.toReversed().entries()) {
106
96
  let newTranslation = translation;
107
97
  if (targetIndex - 1 >= index) {
108
- newTranslation = { height: 0, width: 0 };
98
+ newTranslation = NONE_TRANSLATE;
109
99
  }
110
100
  if (event === START_DROP_EVENT && !containClass(sibling, TEMP_CHILD_CLASS)) {
111
101
  startDropEventOverElement(sibling, newTranslation, draggedElement, draggableTranslation);
@@ -133,8 +123,8 @@ export default function useDragAndDropEvents(currentConfig, index, parent, dropp
133
123
  return [previousElement, nextElement, targetIndex];
134
124
  };
135
125
  const startDropEventOverElement = (targetElement, translation, element, sourceElementTranlation) => {
136
- moveTranslate(targetElement, translation.height, translation.width);
137
- moveTranslate(element, sourceElementTranlation.height, sourceElementTranlation.width);
126
+ moveTranslate(targetElement, translation);
127
+ moveTranslate(element, sourceElementTranlation);
138
128
  };
139
129
  const dropEventOverElement = (targetIndex, element, config, droppable, positionOnSourceDroppable) => {
140
130
  const { onInsertEvent, onDragEnd } = config;
@@ -177,7 +167,7 @@ export default function useDragAndDropEvents(currentConfig, index, parent, dropp
177
167
  }, animationDuration);
178
168
  };
179
169
  const removeTempChildOnDroppables = (parent, droppable) => {
180
- if (parent.isSameNode(droppable)) {
170
+ if (isSameNode(parent, droppable)) {
181
171
  removeTempChild(parent, animationDuration);
182
172
  }
183
173
  else {
@@ -186,16 +176,16 @@ export default function useDragAndDropEvents(currentConfig, index, parent, dropp
186
176
  }
187
177
  };
188
178
  const reduceTempchildSize = (droppable) => {
189
- if (parent.isSameNode(droppable)) {
179
+ if (isSameNode(parent, droppable)) {
190
180
  return;
191
181
  }
192
182
  var [lastChildren] = parent.querySelectorAll(`.${TEMP_CHILD_CLASS}`);
193
183
  if (!lastChildren) {
194
184
  return;
195
185
  }
196
- const { distance } = getPropByDirection(direction);
197
186
  if (IsHTMLElement(lastChildren)) {
198
- lastChildren.style[distance] = '0px';
187
+ lastChildren.style.height = '0px';
188
+ lastChildren.style.width = '0px';
199
189
  }
200
190
  };
201
191
  const removeTranslateFromSiblings = (element, parent) => {
@@ -204,11 +194,5 @@ export default function useDragAndDropEvents(currentConfig, index, parent, dropp
204
194
  removeTranslateWhitoutTransition(sibling);
205
195
  }
206
196
  };
207
- const removeTranslateWhitoutTransition = (element) => {
208
- if (IsHTMLElement(element)) {
209
- element.style.transition = '';
210
- element.style.transform = '';
211
- }
212
- };
213
197
  return [emitDraggingEvent, emitDroppingEvent, toggleDraggingClass];
214
198
  }
@@ -1,11 +1,11 @@
1
1
  import { HORIZONTAL, VERTICAL } from '../..';
2
- import { getPropByDirection, getValueFromProperty } from '../../utils/GetStyles';
3
- import { gapAndDisplayInformation, getBeforeStyles } from '../../utils/ParseStyles';
2
+ import { getAfterMargin, getAxisValue, getBeforeMargin, getBorderBeforeWidthValue, getDistanceValue, getPropByDirection, getRect, getScrollElementValue, getScrollValue, getValueFromProperty } from '../../utils/GetStyles';
3
+ import { getBeforeStyles, getGapInfo } from '../../utils/ParseStyles';
4
4
  const getContentPosition = (direction, droppable) => {
5
- const { borderBeforeWidth, paddingBefore, axis, getRect } = getPropByDirection(direction);
6
- const borderBeforeWidthDroppable = getValueFromProperty(droppable, borderBeforeWidth);
5
+ const { paddingBefore } = getPropByDirection(direction);
6
+ const borderBeforeWidthDroppable = getBorderBeforeWidthValue(direction, droppable);
7
7
  const paddingBeforeDroppable = getValueFromProperty(droppable, paddingBefore);
8
- const axisValue = getRect(droppable)[axis];
8
+ const axisValue = getAxisValue(direction, getRect(droppable));
9
9
  return borderBeforeWidthDroppable + paddingBeforeDroppable + axisValue;
10
10
  };
11
11
  const getGroupTranslate = (droppable, draggable) => {
@@ -27,14 +27,14 @@ export default function getTranslateBeforeDropping(direction, siblings, sourceIn
27
27
  height += y;
28
28
  width += x;
29
29
  }
30
- const { scrollElement, beforeMargin: beforeMarginProp, afterMargin: afterMarginProp, distance: spaceProp, gap: gapStyle } = getPropByDirection(direction);
31
- const [gap, hasGaps] = gapAndDisplayInformation(droppable, gapStyle);
32
- const [afterMarginOutside, beforeMarginOutside, spaceBeforeDraggedElement] = getBeforeAfterMarginBaseOnDraggedDirection(beforeMarginProp, afterMarginProp, sourceElement, targetElement?.previousElementSibling, isDraggedFoward, hasGaps, isGroupDropping);
33
- const [beforeSpace, space, afterSpace] = spaceWithMargins(beforeMarginProp, afterMarginProp, spaceProp, siblingsBetween, gap, hasGaps);
30
+ const [gap, hasGaps] = getGapInfo(droppable, direction);
31
+ const [afterMarginOutside, beforeMarginOutside, spaceBeforeDraggedElement] = getBeforeAfterMarginBaseOnDraggedDirection(sourceElement, targetElement?.previousElementSibling, isDraggedFoward, hasGaps, isGroupDropping, direction);
32
+ const [beforeSpace, space, afterSpace] = spaceWithMargins(siblingsBetween, gap, hasGaps, direction);
34
33
  const spaceBetween = getSpaceBetween(space, beforeSpace, afterSpace, beforeMarginOutside, afterMarginOutside, gap);
34
+ const [scrollElementValue] = getScrollElementValue(direction, droppable);
35
35
  const scrollChange = isGroupDropping
36
- ? droppable[scrollElement]
37
- : getScrollChange(scrollElement, droppable, previousScroll);
36
+ ? scrollElementValue
37
+ : getScrollChange(droppable, previousScroll, direction);
38
38
  const spaceCalc = isDraggedFoward
39
39
  ? spaceBetween - spaceBeforeDraggedElement
40
40
  : spaceBeforeDraggedElement - spaceBetween;
@@ -47,9 +47,9 @@ export default function getTranslateBeforeDropping(direction, siblings, sourceIn
47
47
  }
48
48
  return addScrollToTranslate({ height, width }, direction, scroll, initialWindowScroll, isGroupDropping);
49
49
  }
50
- const getScrollChange = (scrollElement, parentElement, previousScroll) => {
51
- const scrollParent = parentElement[scrollElement];
52
- const previousScrollValue = previousScroll[scrollElement];
50
+ const getScrollChange = (parentElement, previousScroll, direction) => {
51
+ const [scrollParent] = getScrollElementValue(direction, parentElement);
52
+ const [previousScrollValue] = getScrollElementValue(direction, previousScroll);
53
53
  return scrollParent - previousScrollValue;
54
54
  };
55
55
  const getSpaceBetween = (innerSpace, beforeMarginSpace, afterMarginSpace, beforeMarginOutside, afterMarginOutside, gap) => {
@@ -70,16 +70,16 @@ const getElementsRange = (siblings, sourceIndex, targetIndex, draggable) => {
70
70
  }
71
71
  return [sourceElement, targetElement, siblingsBetween, isDraggedFoward];
72
72
  };
73
- const spaceWithMargins = (beforeMargin, afterMargin, distance, siblings, gap, hasGaps) => {
73
+ const spaceWithMargins = (siblings, gap, hasGaps, direction) => {
74
74
  if (siblings.length == 0) {
75
75
  return [0, 0, 0];
76
76
  }
77
- const beforeSpace = getValueFromProperty(siblings[0], beforeMargin);
77
+ const beforeSpace = getAfterMargin(direction, siblings[0]);
78
78
  let afterSpace = 0;
79
79
  let space = -beforeSpace;
80
80
  for (const [index, sibling] of siblings.entries()) {
81
- const siblingSpace = sibling.getBoundingClientRect()[distance];
82
- const siblingBeforeMargin = getValueFromProperty(sibling, beforeMargin);
81
+ const [siblingSpace] = getDistanceValue(direction, getRect(sibling));
82
+ const siblingBeforeMargin = getBeforeMargin(direction, sibling);
83
83
  if (hasGaps) {
84
84
  afterSpace += siblingBeforeMargin;
85
85
  }
@@ -90,32 +90,32 @@ const spaceWithMargins = (beforeMargin, afterMargin, distance, siblings, gap, ha
90
90
  afterSpace = Math.max(afterSpace, siblingBeforeMargin);
91
91
  }
92
92
  space += afterSpace + siblingSpace;
93
- afterSpace = getValueFromProperty(sibling, afterMargin);
93
+ afterSpace = getAfterMargin(direction, sibling);
94
94
  }
95
95
  return [beforeSpace, space, afterSpace];
96
96
  };
97
97
  const addScrollToTranslate = (translate, direction, initialScroll, initialWindowScroll, isGroupDropping) => {
98
- const { scroll, distance } = getPropByDirection(direction);
99
- const actualWindowScroll = window[scroll];
100
- const initialScrollProp = initialScroll[scroll];
98
+ const actualWindowScroll = getScrollValue(direction, window);
99
+ const initialScrollProp = getScrollValue(direction, initialScroll);
101
100
  const scrollChange = isGroupDropping
102
101
  ? 0
103
- : initialScrollProp - 2 * actualWindowScroll + initialWindowScroll[scroll];
102
+ : initialScrollProp - 2 * actualWindowScroll + getScrollValue(direction, initialWindowScroll);
103
+ const [, distance] = getDistanceValue(direction, translate);
104
104
  translate[distance] += scrollChange;
105
105
  return translate;
106
106
  };
107
- const getBeforeAfterMarginBaseOnDraggedDirection = (beforeMarginProp, afterMarginProp, draggedElement, previousElement, isDraggedFoward, hasGaps, isGroupDropping) => {
107
+ const getBeforeAfterMarginBaseOnDraggedDirection = (draggedElement, previousElement, isDraggedFoward, hasGaps, isGroupDropping, direction) => {
108
108
  const previousElementByDirection = isDraggedFoward
109
109
  ? draggedElement.previousElementSibling
110
110
  : previousElement;
111
- return getBeforeAfterMargin(beforeMarginProp, afterMarginProp, previousElementByDirection, draggedElement, hasGaps, isGroupDropping);
111
+ return getBeforeAfterMargin(previousElementByDirection, draggedElement, hasGaps, isGroupDropping, direction);
112
112
  };
113
- const getBeforeAfterMargin = (beforeMarginProp, afterMarginProp, previousElement, nextElement, hasGaps, isGroupDropping) => {
113
+ const getBeforeAfterMargin = (previousElement, nextElement, hasGaps, isGroupDropping, direction) => {
114
114
  if (hasGaps) {
115
115
  return [0, 0, 0];
116
116
  }
117
- const afterMargin = getValueFromProperty(isGroupDropping ? null : previousElement, afterMarginProp);
118
- const beforeMargin = getValueFromProperty(nextElement, beforeMarginProp);
119
- let spaceBeforeDraggedElement = Math.max(afterMargin, beforeMargin);
120
- return [afterMargin, beforeMargin, spaceBeforeDraggedElement];
117
+ const afterMarginValue = getAfterMargin(direction, isGroupDropping ? null : previousElement);
118
+ const beforeMarginValue = getBeforeMargin(direction, nextElement);
119
+ let spaceBeforeDraggedElement = Math.max(afterMarginValue, beforeMarginValue);
120
+ return [afterMarginValue, beforeMarginValue, spaceBeforeDraggedElement];
121
121
  };
@@ -1,7 +1,7 @@
1
1
  import { HORIZONTAL } from '../..';
2
2
  import { DRAG_EVENT } from '../../utils';
3
- import { draggableIsOutside, getPropByDirection, getValueFromProperty } from '../../utils/GetStyles';
4
- import { gapAndDisplayInformation } from '../../utils/ParseStyles';
3
+ import { draggableIsOutside, getAfterMargin, getBeforeMarginValue, getDistanceValue, getRect } from '../../utils/GetStyles';
4
+ import { getGapInfo } from '../../utils/ParseStyles';
5
5
  export default function getTranslationByDraggingAndEvent(current, event, direction, droppable, previousElement = current.previousElementSibling, nextElement = current.nextElementSibling) {
6
6
  let { height, width } = getTranslationByDragging(direction, current, previousElement, nextElement);
7
7
  const intersection = draggableIsOutside(current, droppable);
@@ -12,24 +12,23 @@ export default function getTranslationByDraggingAndEvent(current, event, directi
12
12
  return { height, width };
13
13
  }
14
14
  const getTranslationByDragging = (direction, current, previous, nextElement) => {
15
- const { afterMargin, beforeMargin, distance, gap: gapStyle, getRect } = getPropByDirection(direction);
16
- const after = getValueFromProperty(current, afterMargin);
17
- const before = getValueFromProperty(current, beforeMargin);
18
- const nextBefore = getValueFromProperty(nextElement, beforeMargin);
19
- const [gap, hasGaps] = gapAndDisplayInformation(current.parentElement, gapStyle);
20
- const space = getRect(current)[distance];
15
+ const after = getAfterMargin(direction, current);
16
+ const before = getBeforeMarginValue(direction, current);
17
+ const nextBefore = getBeforeMarginValue(direction, nextElement);
18
+ const [gap, hasGaps] = getGapInfo(current.parentElement, direction);
19
+ const [space] = getDistanceValue(direction, getRect(current));
21
20
  if (hasGaps) {
22
21
  return getTranslation(space, before, after, gap, 0, direction);
23
22
  }
24
- const [afterSpace, beforeScace, rest] = getTranslationByDraggingWithoutGaps(previous, nextBefore, after, before, afterMargin);
23
+ const [afterSpace, beforeScace, rest] = getTranslationByDraggingWithoutGaps(previous, nextBefore, after, before, direction);
25
24
  return getTranslation(space, beforeScace, afterSpace, 0, rest, direction);
26
25
  };
27
- const getTranslationByDraggingWithoutGaps = (previousElement, nextBeforeMargin, currentAfterMargin, currentBeforeMargin, afterMargin) => {
26
+ const getTranslationByDraggingWithoutGaps = (previousElement, nextBeforeMargin, currentAfterMargin, currentBeforeMargin, direction) => {
28
27
  const afterSpace = Math.max(nextBeforeMargin, currentAfterMargin);
29
28
  let beforeScace = currentBeforeMargin;
30
29
  let rest = nextBeforeMargin;
31
30
  if (previousElement) {
32
- const previousAfterMargin = getValueFromProperty(previousElement, afterMargin);
31
+ const previousAfterMargin = getAfterMargin(direction, previousElement);
33
32
  beforeScace = Math.max(previousAfterMargin, currentBeforeMargin);
34
33
  rest = Math.max(rest, previousAfterMargin);
35
34
  }
@@ -1,4 +1,5 @@
1
1
  import { CoreConfig } from '../index';
2
2
  import HandlerPublisher from '../HandlerPublisher';
3
- export default function useInsertEvents<T>(currentConfig: CoreConfig<T>, parent: HTMLElement, handlerPublisher: HandlerPublisher, endDraggingAction: () => void): readonly [(targetIndex: number, draggedElement: HTMLElement, droppable: HTMLElement, value: T, startInserting: () => void) => void];
3
+ import { DroppableConfig } from '../config/configHandler';
4
+ export default function useInsertEvents<T>(currentConfig: CoreConfig<T>, parent: HTMLElement, handlerPublisher: HandlerPublisher, endDraggingAction: () => void): readonly [(targetIndex: number, draggedElement: HTMLElement, droppable: HTMLElement, value: T, droppableConfigurator: DroppableConfig<T>) => void];
4
5
  export declare const insertToListEmpty: <T>(config: CoreConfig<T>, droppable: HTMLElement | undefined | null, targetIndex: number, value: T) => void;