fluid-dnd 2.0.1 → 2.0.2

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 (60) hide show
  1. package/dist/core/HandlerPublisher.js +20 -0
  2. package/dist/core/configHandler.d.ts +2 -3
  3. package/dist/core/configHandler.js +33 -0
  4. package/dist/core/dragAndDrop.d.ts +3 -3
  5. package/dist/core/dragAndDrop.js +62 -0
  6. package/dist/core/index.js +2 -0
  7. package/dist/core/useDraggable.d.ts +2 -3
  8. package/dist/core/useDraggable.js +328 -0
  9. package/dist/core/useDroppable.d.ts +2 -3
  10. package/dist/core/useDroppable.js +55 -0
  11. package/dist/core/utils/GetStyles.d.ts +2 -3
  12. package/dist/core/utils/GetStyles.js +138 -0
  13. package/dist/core/utils/ParseStyles.d.ts +2 -3
  14. package/dist/core/utils/ParseStyles.js +40 -0
  15. package/dist/core/utils/SetStyles.d.ts +1 -2
  16. package/dist/core/utils/SetStyles.js +192 -0
  17. package/dist/core/utils/SetTransform.d.ts +2 -3
  18. package/dist/core/utils/SetTransform.js +148 -0
  19. package/dist/core/utils/classes.js +9 -0
  20. package/dist/core/utils/config.d.ts +3 -3
  21. package/dist/core/utils/config.js +55 -0
  22. package/dist/core/utils/dom/classList.js +35 -0
  23. package/dist/core/utils/droppableConfigurator.d.ts +3 -4
  24. package/dist/core/utils/droppableConfigurator.js +106 -0
  25. package/dist/core/utils/events/emitEvents.d.ts +5 -6
  26. package/dist/core/utils/events/emitEvents.js +333 -0
  27. package/dist/core/utils/index.js +9 -0
  28. package/dist/core/utils/observer.js +11 -0
  29. package/dist/core/utils/scroll.d.ts +2 -3
  30. package/dist/core/utils/scroll.js +17 -0
  31. package/dist/core/utils/tempChildren.d.ts +1 -2
  32. package/dist/core/utils/tempChildren.js +146 -0
  33. package/dist/core/utils/touchDevice.js +3 -0
  34. package/dist/core/utils/translate/GetTranslateBeforeDropping.d.ts +2 -3
  35. package/dist/core/utils/translate/GetTranslateBeforeDropping.js +129 -0
  36. package/dist/core/utils/translate/GetTranslationByDraggingAndEvent.d.ts +2 -3
  37. package/dist/core/utils/translate/GetTranslationByDraggingAndEvent.js +48 -0
  38. package/dist/index.d.ts +4 -0
  39. package/dist/index.js +2 -0
  40. package/dist/react/index.d.ts +1 -2
  41. package/dist/react/index.js +2 -0
  42. package/dist/react/useDragAndDrop.d.ts +2 -3
  43. package/dist/react/useDragAndDrop.js +28 -0
  44. package/dist/react/utils/ReactLilstConfig.d.ts +3 -4
  45. package/dist/react/utils/ReactLilstConfig.js +64 -0
  46. package/dist/svelte/index.d.ts +1 -2
  47. package/dist/svelte/index.js +2 -0
  48. package/dist/svelte/useDragAndDrop.d.ts +1 -2
  49. package/dist/svelte/useDragAndDrop.js +25 -0
  50. package/dist/svelte/utils/SvelteListCondig.d.ts +2 -2
  51. package/dist/svelte/utils/SvelteListCondig.js +36 -0
  52. package/dist/vue/index.d.ts +1 -2
  53. package/dist/vue/index.js +2 -0
  54. package/dist/vue/useDragAndDrop.d.ts +2 -3
  55. package/dist/vue/useDragAndDrop.js +23 -0
  56. package/dist/vue/utils/DropMethods.d.ts +1 -2
  57. package/dist/vue/utils/DropMethods.js +19 -0
  58. package/dist/vue/utils/VueListCondig.d.ts +3 -3
  59. package/dist/vue/utils/VueListCondig.js +28 -0
  60. package/package.json +2 -5
@@ -0,0 +1,129 @@
1
+ import { HORIZONTAL, VERTICAL } from "../..";
2
+ import { getPropByDirection, getValueFromProperty, } from "../GetStyles";
3
+ import { gapAndDisplayInformation, getBeforeStyles } from "../ParseStyles";
4
+ const getContentPosition = (direction, droppable) => {
5
+ const { borderBeforeWidth, paddingBefore, axis, getRect } = getPropByDirection(direction);
6
+ const borderBeforeWidthDroppable = getValueFromProperty(droppable, borderBeforeWidth);
7
+ const paddingBeforeDroppable = getValueFromProperty(droppable, paddingBefore);
8
+ const axisValue = getRect(droppable)[axis];
9
+ return borderBeforeWidthDroppable + paddingBeforeDroppable + axisValue;
10
+ };
11
+ const getGroupTranslate = (droppable, draggable) => {
12
+ const [top, left] = getBeforeStyles(draggable);
13
+ const verticalContentPosition = getContentPosition(VERTICAL, droppable);
14
+ const horizontalContentPosition = getContentPosition(HORIZONTAL, droppable);
15
+ return [
16
+ horizontalContentPosition - left,
17
+ verticalContentPosition - top
18
+ ];
19
+ };
20
+ export default function getTranslateBeforeDropping(direction, siblings, sourceIndex, targetIndex, scroll, previousScroll, initialWindowScroll, droppable, draggable) {
21
+ let height = 0;
22
+ let width = 0;
23
+ const isGroupDropping = Boolean(sourceIndex < 0 && draggable);
24
+ if (sourceIndex === targetIndex && !isGroupDropping) {
25
+ return addScrollToTranslate({ height, width }, direction, scroll, initialWindowScroll, isGroupDropping);
26
+ }
27
+ const [sourceElement, targetElement, siblingsBetween, isDraggedFoward] = getElementsRange(siblings, sourceIndex, targetIndex, draggable);
28
+ if (isGroupDropping) {
29
+ const [x, y] = getGroupTranslate(droppable, draggable);
30
+ height += y;
31
+ width += x;
32
+ }
33
+ const { scrollElement, beforeMargin: beforeMarginProp, afterMargin: afterMarginProp, distance: spaceProp, gap: gapStyle, } = getPropByDirection(direction);
34
+ const [gap, hasGaps] = gapAndDisplayInformation(droppable, gapStyle);
35
+ const [afterMarginOutside, beforeMarginOutside, spaceBeforeDraggedElement,] = getBeforeAfterMarginBaseOnDraggedDirection(beforeMarginProp, afterMarginProp, sourceElement, targetElement?.previousElementSibling, isDraggedFoward, hasGaps, isGroupDropping);
36
+ const [beforeSpace, space, afterSpace] = spaceWithMargins(beforeMarginProp, afterMarginProp, spaceProp, siblingsBetween, gap, hasGaps);
37
+ const spaceBetween = getSpaceBetween(space, beforeSpace, afterSpace, beforeMarginOutside, afterMarginOutside, gap);
38
+ const scrollChange = isGroupDropping
39
+ ? droppable[scrollElement]
40
+ : getScrollChange(scrollElement, droppable, previousScroll);
41
+ const spaceCalc = isDraggedFoward
42
+ ? spaceBetween - spaceBeforeDraggedElement
43
+ : spaceBeforeDraggedElement - spaceBetween;
44
+ const translate = spaceCalc - scrollChange;
45
+ if (direction === VERTICAL) {
46
+ height += translate;
47
+ }
48
+ else if (direction === HORIZONTAL) {
49
+ width += translate;
50
+ }
51
+ return addScrollToTranslate({ height, width }, direction, scroll, initialWindowScroll, isGroupDropping);
52
+ }
53
+ const getScrollChange = (scrollElement, parentElement, previousScroll) => {
54
+ const scrollParent = parentElement[scrollElement];
55
+ const previousScrollValue = previousScroll[scrollElement];
56
+ return scrollParent - previousScrollValue;
57
+ };
58
+ const getSpaceBetween = (innerSpace, beforeMarginSpace, afterMarginSpace, beforeMarginOutside, afterMarginOutside, gap) => {
59
+ const beforeMarginCalc = Math.max(beforeMarginSpace, afterMarginOutside);
60
+ const afterMarginCalc = Math.max(afterMarginSpace, beforeMarginOutside);
61
+ return afterMarginCalc + innerSpace + beforeMarginCalc + gap;
62
+ };
63
+ const getElementsRange = (siblings, sourceIndex, targetIndex, draggable) => {
64
+ const isDraggedFoward = sourceIndex < targetIndex;
65
+ const [firstIndex, secondIndex] = [sourceIndex, targetIndex].toSorted((a, b) => a - b);
66
+ const sourceElement = siblings[sourceIndex] ?? draggable;
67
+ const targetElement = siblings[targetIndex];
68
+ let siblingsBetween = isDraggedFoward
69
+ ? siblings.slice(firstIndex + 1, secondIndex + 1)
70
+ : siblings.slice(firstIndex, secondIndex);
71
+ if (firstIndex < 0 && draggable) {
72
+ siblingsBetween = siblings.slice(firstIndex + 1, secondIndex);
73
+ }
74
+ return [
75
+ sourceElement,
76
+ targetElement,
77
+ siblingsBetween,
78
+ isDraggedFoward,
79
+ ];
80
+ };
81
+ const spaceWithMargins = (beforeMargin, afterMargin, distance, siblings, gap, hasGaps) => {
82
+ if (siblings.length == 0) {
83
+ return [0, 0, 0];
84
+ }
85
+ const beforeSpace = getValueFromProperty(siblings[0], beforeMargin);
86
+ let afterSpace = 0;
87
+ let space = -beforeSpace;
88
+ for (const [index, sibling] of siblings.entries()) {
89
+ const siblingSpace = sibling.getBoundingClientRect()[distance];
90
+ const siblingBeforeMargin = getValueFromProperty(sibling, beforeMargin);
91
+ if (hasGaps) {
92
+ afterSpace += siblingBeforeMargin;
93
+ }
94
+ if (hasGaps && index > 0) {
95
+ afterSpace += gap;
96
+ }
97
+ else {
98
+ afterSpace = Math.max(afterSpace, siblingBeforeMargin);
99
+ }
100
+ space += afterSpace + siblingSpace;
101
+ afterSpace = getValueFromProperty(sibling, afterMargin);
102
+ }
103
+ return [beforeSpace, space, afterSpace];
104
+ };
105
+ const addScrollToTranslate = (translate, direction, initialScroll, initialWindowScroll, isGroupDropping) => {
106
+ const { scroll, distance } = getPropByDirection(direction);
107
+ const actualWindowScroll = window[scroll];
108
+ const initialScrollProp = initialScroll[scroll];
109
+ const scrollChange = isGroupDropping
110
+ ? 0
111
+ : initialScrollProp - 2 * actualWindowScroll + initialWindowScroll[scroll];
112
+ translate[distance] += scrollChange;
113
+ return translate;
114
+ };
115
+ const getBeforeAfterMarginBaseOnDraggedDirection = (beforeMarginProp, afterMarginProp, draggedElement, previousElement, isDraggedFoward, hasGaps, isGroupDropping) => {
116
+ const previousElementByDirection = isDraggedFoward
117
+ ? draggedElement.previousElementSibling
118
+ : previousElement;
119
+ return getBeforeAfterMargin(beforeMarginProp, afterMarginProp, previousElementByDirection, draggedElement, hasGaps, isGroupDropping);
120
+ };
121
+ const getBeforeAfterMargin = (beforeMarginProp, afterMarginProp, previousElement, nextElement, hasGaps, isGroupDropping) => {
122
+ if (hasGaps) {
123
+ return [0, 0, 0];
124
+ }
125
+ const afterMargin = getValueFromProperty(isGroupDropping ? null : previousElement, afterMarginProp);
126
+ const beforeMargin = getValueFromProperty(nextElement, beforeMarginProp);
127
+ let spaceBeforeDraggedElement = Math.max(afterMargin, beforeMargin);
128
+ return [afterMargin, beforeMargin, spaceBeforeDraggedElement];
129
+ };
@@ -1,6 +1,5 @@
1
- import { Direction } from '../..';
2
- import { DragAndDropEvent } from '..';
3
-
1
+ import { Direction } from "../..";
2
+ import { DragAndDropEvent } from "..";
4
3
  export default function getTranslationByDraggingAndEvent(current: HTMLElement, event: DragAndDropEvent, direction: Direction, droppable: HTMLElement, previousElement?: Element | null, nextElement?: Element | null): {
5
4
  height: number;
6
5
  width: number;
@@ -0,0 +1,48 @@
1
+ import { HORIZONTAL } from "../..";
2
+ import { DRAG_EVENT } from "..";
3
+ import { draggableIsOutside, getPropByDirection, getValueFromProperty, } from "../GetStyles";
4
+ import { gapAndDisplayInformation } from "../ParseStyles";
5
+ export default function getTranslationByDraggingAndEvent(current, event, direction, droppable, previousElement = current.previousElementSibling, nextElement = current.nextElementSibling) {
6
+ let { height, width } = getTranslationByDragging(direction, current, previousElement, nextElement);
7
+ const intersection = draggableIsOutside(current, droppable);
8
+ if (intersection && event == DRAG_EVENT) {
9
+ height = 0;
10
+ width = 0;
11
+ }
12
+ return { height, width };
13
+ }
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];
21
+ if (hasGaps) {
22
+ return getTranslation(space, before, after, gap, 0, direction);
23
+ }
24
+ const [afterSpace, beforeScace, rest] = getTranslationByDraggingWithoutGaps(previous, nextBefore, after, before, afterMargin);
25
+ return getTranslation(space, beforeScace, afterSpace, 0, rest, direction);
26
+ };
27
+ const getTranslationByDraggingWithoutGaps = (previousElement, nextBeforeMargin, currentAfterMargin, currentBeforeMargin, afterMargin) => {
28
+ const afterSpace = Math.max(nextBeforeMargin, currentAfterMargin);
29
+ let beforeScace = currentBeforeMargin;
30
+ let rest = nextBeforeMargin;
31
+ if (previousElement) {
32
+ const previousAfterMargin = getValueFromProperty(previousElement, afterMargin);
33
+ beforeScace = Math.max(previousAfterMargin, currentBeforeMargin);
34
+ rest = Math.max(rest, previousAfterMargin);
35
+ }
36
+ return [afterSpace, beforeScace, rest];
37
+ };
38
+ const getTranslation = (size, before, after, gap, rest, direction) => {
39
+ return getDistancesByDirection(direction, size + before + after + gap - rest);
40
+ };
41
+ const getDistancesByDirection = (direction, value) => {
42
+ if (direction == HORIZONTAL) {
43
+ return { width: value, height: 0 };
44
+ }
45
+ else {
46
+ return { width: 0, height: value };
47
+ }
48
+ };
@@ -0,0 +1,4 @@
1
+ import { DragEndEventData, DragStartEventData, Direction } from "./core";
2
+ import dragAndDrop from "./core/dragAndDrop";
3
+ export type { DragStartEventData, DragEndEventData, Direction };
4
+ export { dragAndDrop };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import dragAndDrop from "./core/dragAndDrop";
2
+ export { dragAndDrop };
@@ -1,3 +1,2 @@
1
- import { default as useDragAndDrop } from './useDragAndDrop';
2
-
1
+ import useDragAndDrop from "./useDragAndDrop";
3
2
  export { useDragAndDrop };
@@ -0,0 +1,2 @@
1
+ import useDragAndDrop from "./useDragAndDrop";
2
+ export { useDragAndDrop };
@@ -1,3 +1,2 @@
1
- import { Config } from '../core';
2
-
3
- export default function useDragAndDrop<T, E extends HTMLElement>(items: T[], config?: Config<T>): readonly [import('react').RefObject<E>, T[], import('react').Dispatch<import('react').SetStateAction<T[]>>, (index: number, value: T) => void, (index: number) => void];
1
+ import { Config } from "../core";
2
+ export default function useDragAndDrop<T, E extends HTMLElement>(items: T[], config?: Config<T>): readonly [import("react").RefObject<E>, T[], import("react").Dispatch<import("react").SetStateAction<T[]>>, (index: number, value: T) => void, (index: number) => void];
@@ -0,0 +1,28 @@
1
+ import { useEffect, useMemo, useRef } from "react";
2
+ import HandlerPublisher from "../core/HandlerPublisher";
3
+ import { dragAndDrop } from "../index";
4
+ import { useReactListConfig } from "./utils/ReactLilstConfig";
5
+ /**
6
+ * Create the parent element of the draggable children and all the drag and drop events and styles.
7
+ *
8
+ * @template T - Type of the items.
9
+ * @param items - List of data to drag and drop.
10
+ * @param config - Configuration of drag and drop tool.
11
+ * @returns The reference of the parent element and function to remove an element.
12
+ */
13
+ const handlerPublisher = new HandlerPublisher();
14
+ export default function useDragAndDrop(items, config) {
15
+ const parent = useRef(null);
16
+ const [itemsState, setItemsState, listCondig] = useReactListConfig(items, parent);
17
+ const [removeAt, insertAt, onChangeParent] = useMemo(() => dragAndDrop(listCondig, handlerPublisher, config, 'data-index'), [itemsState.length]);
18
+ useEffect(() => {
19
+ const observer = onChangeParent(parent.current);
20
+ return () => {
21
+ if (observer) {
22
+ console.log('disconnect');
23
+ observer.disconnect();
24
+ }
25
+ };
26
+ }, [itemsState.length]);
27
+ return [parent, itemsState, setItemsState, insertAt, removeAt];
28
+ }
@@ -1,4 +1,3 @@
1
- import { RefObject } from 'react';
2
- import { ListCondig } from '../../core';
3
-
4
- export declare function useReactListConfig<T, E extends HTMLElement>(items: T[], parent: RefObject<E>): readonly [T[], import('react').Dispatch<import('react').SetStateAction<T[]>>, ListCondig<T>];
1
+ import { RefObject } from "react";
2
+ import { ListCondig } from "../../core";
3
+ export declare function useReactListConfig<T, E extends HTMLElement>(items: T[], parent: RefObject<E>): readonly [T[], import("react").Dispatch<import("react").SetStateAction<T[]>>, ListCondig<T>];
@@ -0,0 +1,64 @@
1
+ import { useEffect, useRef, useState } from "react";
2
+ import { insertToListEmpty as insertToListEmptyEvent } from "../../core/utils/events/emitEvents";
3
+ // @ts-ignore
4
+ import { flushSync } from "react-dom";
5
+ export function useReactListConfig(items, parent) {
6
+ const [itemsState, setItemsState] = useState(items);
7
+ const stateRef = useRef(itemsState);
8
+ useEffect(() => {
9
+ stateRef.current = itemsState;
10
+ }, [itemsState]);
11
+ function removeAtEvent(index, sync = false) {
12
+ const deletedItem = stateRef.current[index];
13
+ const removeCallback = () => {
14
+ setItemsState(prevItems => [
15
+ ...prevItems.slice(0, index),
16
+ ...prevItems.slice(index + 1)
17
+ ]);
18
+ };
19
+ if (sync) {
20
+ flushSync(removeCallback);
21
+ }
22
+ else {
23
+ removeCallback();
24
+ }
25
+ return deletedItem;
26
+ }
27
+ ;
28
+ function insertEvent(index, value, sync = false) {
29
+ const insertCallback = () => {
30
+ setItemsState(prevItems => {
31
+ return [
32
+ ...prevItems.slice(0, index),
33
+ value,
34
+ ...prevItems.slice(index)
35
+ ];
36
+ });
37
+ };
38
+ if (sync) {
39
+ flushSync(insertCallback);
40
+ }
41
+ else {
42
+ insertCallback();
43
+ }
44
+ }
45
+ ;
46
+ function getLength() {
47
+ return itemsState.length;
48
+ }
49
+ ;
50
+ function getValue(index) {
51
+ return itemsState[index];
52
+ }
53
+ function insertToListEmpty(config, index, value) {
54
+ insertToListEmptyEvent(config, parent.current, index, value);
55
+ }
56
+ const actions = {
57
+ removeAtEvent,
58
+ insertEvent,
59
+ getLength,
60
+ getValue,
61
+ insertToListEmpty
62
+ };
63
+ return [itemsState, setItemsState, actions];
64
+ }
@@ -1,3 +1,2 @@
1
- import { default as useDragAndDrop } from './useDragAndDrop';
2
-
1
+ import useDragAndDrop from "./useDragAndDrop";
3
2
  export { useDragAndDrop };
@@ -0,0 +1,2 @@
1
+ import useDragAndDrop from "./useDragAndDrop";
2
+ export { useDragAndDrop };
@@ -1,5 +1,4 @@
1
- import { Config } from '../core';
2
-
1
+ import { Config } from "../core";
3
2
  export default function useDragAndDrop<T>(items: T[], config?: Config<T>): readonly [(parent: HTMLElement) => {
4
3
  destroy(): void;
5
4
  }, (index: number, value: T) => void, (index: number) => void];
@@ -0,0 +1,25 @@
1
+ import HandlerPublisher from "../core/HandlerPublisher";
2
+ import { dragAndDrop } from "../index";
3
+ import { SvelteListCondig } from "./utils/SvelteListCondig";
4
+ /**
5
+ * Create the parent element of the draggable children and all the drag and drop events and styles.
6
+ *
7
+ * @template T - Type of the items.
8
+ * @param items - List of data to drag and drop.
9
+ * @param config - Configuration of drag and drop tool.
10
+ * @returns The reference of the parent element and function to remove an element.
11
+ */
12
+ const handlerPublisher = new HandlerPublisher();
13
+ export default function useDragAndDrop(items, config) {
14
+ const listCondig = new SvelteListCondig(items);
15
+ const [removeAt, insertAt, onChangeParent] = dragAndDrop(listCondig, handlerPublisher, config, 'data-index');
16
+ const dragAndDropAction = (parent) => {
17
+ listCondig.setParent(parent);
18
+ onChangeParent(parent);
19
+ return {
20
+ destroy() {
21
+ }
22
+ };
23
+ };
24
+ return [dragAndDropAction, insertAt, removeAt];
25
+ }
@@ -1,5 +1,5 @@
1
- import { CoreConfig, ListCondig } from '../../core';
2
-
1
+ import { CoreConfig } from "../../core";
2
+ import { ListCondig } from "../../core";
3
3
  export declare class SvelteListCondig<T> implements ListCondig<T> {
4
4
  private items;
5
5
  private parent;
@@ -0,0 +1,36 @@
1
+ import { insertToListEmpty } from "../../core/utils/events/emitEvents";
2
+ export class SvelteListCondig {
3
+ items;
4
+ parent;
5
+ constructor(items) {
6
+ this.items = items;
7
+ }
8
+ setParent(parent) {
9
+ this.parent = parent;
10
+ }
11
+ ;
12
+ removeAtEvent(index) {
13
+ const listValue = this.items;
14
+ if (listValue.length <= 0) {
15
+ return;
16
+ }
17
+ const [deletedItem] = listValue.splice(index, 1);
18
+ return deletedItem;
19
+ }
20
+ ;
21
+ insertEvent(index, value) {
22
+ const listValue = this.items;
23
+ listValue.splice(index, 0, value);
24
+ }
25
+ ;
26
+ getLength() {
27
+ return this.items.length;
28
+ }
29
+ ;
30
+ getValue(index) {
31
+ return this.items[index];
32
+ }
33
+ insertToListEmpty(config, index, value) {
34
+ insertToListEmpty(config, this.parent, index, value);
35
+ }
36
+ }
@@ -1,3 +1,2 @@
1
- import { default as useDragAndDrop } from './useDragAndDrop';
2
-
1
+ import useDragAndDrop from "./useDragAndDrop";
3
2
  export { useDragAndDrop };
@@ -0,0 +1,2 @@
1
+ import useDragAndDrop from "./useDragAndDrop";
2
+ export { useDragAndDrop };
@@ -1,4 +1,3 @@
1
- import { Ref } from 'vue';
2
- import { Config } from '../core';
3
-
1
+ import { Ref } from "vue";
2
+ import { Config } from "../core";
4
3
  export default function useDragAndDrop<T>(items: Ref<T[]>, config?: Config<T>): readonly [Ref<HTMLElement | undefined, HTMLElement | undefined>, (index: number, value: T) => void, (index: number) => void];
@@ -0,0 +1,23 @@
1
+ // @ts-ignore
2
+ import { ref, watch } from "vue";
3
+ import HandlerPublisher from "../core/HandlerPublisher";
4
+ import { VueListCondig } from "./utils/VueListCondig";
5
+ import { dragAndDrop } from "../index";
6
+ /**
7
+ * Create the parent element of the draggable children and all the drag and drop events and styles.
8
+ *
9
+ * @template T - Type of the items.
10
+ * @param items - List of data to drag and drop.
11
+ * @param config - Configuration of drag and drop tool.
12
+ * @returns The reference of the parent element and function to remove an element.
13
+ */
14
+ const handlerPublisher = new HandlerPublisher();
15
+ export default function useDragAndDrop(items, config) {
16
+ const parent = ref();
17
+ var listCondig = new VueListCondig(items, parent);
18
+ const [removeAt, insertAt, onChangeParent] = dragAndDrop(listCondig, handlerPublisher, config);
19
+ watch(parent, () => {
20
+ onChangeParent(parent.value);
21
+ });
22
+ return [parent, insertAt, removeAt];
23
+ }
@@ -1,5 +1,4 @@
1
- import { Ref } from 'vue';
2
-
1
+ import { Ref } from "vue";
3
2
  export declare const removeAtEventOnList: <T>(list: Ref<T[]>, index: number) => T | undefined;
4
3
  export declare const onInsertEventOnList: <T>(list: Ref<T[]>, index: number, value: T) => void;
5
4
  export declare const getLength: <T>(list: Ref<T[]>) => number;
@@ -0,0 +1,19 @@
1
+ export const removeAtEventOnList = (list, index) => {
2
+ const listValue = list.value;
3
+ if (listValue.length <= 0) {
4
+ return;
5
+ }
6
+ const [deletedItem] = listValue.splice(index, 1);
7
+ return deletedItem;
8
+ };
9
+ export const onInsertEventOnList = (list, index, value) => {
10
+ const listValue = list.value;
11
+ listValue.splice(index, 0, value);
12
+ };
13
+ export const getLength = (list) => {
14
+ const listValue = list.value;
15
+ return listValue.length;
16
+ };
17
+ export const getValue = (list, index) => {
18
+ return list.value[index];
19
+ };
@@ -1,6 +1,6 @@
1
- import { CoreConfig, ListCondig } from '../../core';
2
- import { Ref } from 'vue';
3
-
1
+ import { CoreConfig } from "../../core";
2
+ import { ListCondig } from "../../core";
3
+ import { Ref } from "vue";
4
4
  export declare class VueListCondig<T> implements ListCondig<T> {
5
5
  private items;
6
6
  private parent;
@@ -0,0 +1,28 @@
1
+ import { getLength, getValue, onInsertEventOnList, removeAtEventOnList } from "./DropMethods";
2
+ import { insertToListEmpty } from "../../core/utils/events/emitEvents";
3
+ export class VueListCondig {
4
+ items;
5
+ parent;
6
+ constructor(items, parent) {
7
+ this.items = items;
8
+ this.parent = parent;
9
+ }
10
+ removeAtEvent(index) {
11
+ return removeAtEventOnList(this.items, index);
12
+ }
13
+ ;
14
+ insertEvent(index, value) {
15
+ return onInsertEventOnList(this.items, index, value);
16
+ }
17
+ ;
18
+ getLength() {
19
+ return getLength(this.items);
20
+ }
21
+ ;
22
+ getValue(index) {
23
+ return getValue(this.items, index);
24
+ }
25
+ insertToListEmpty(config, index, value) {
26
+ insertToListEmpty(config, this.parent.value, index, value);
27
+ }
28
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fluid-dnd",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "An agnostic drag and drop library to sort all kind of lists. With current support for vue, react and svelte",
5
5
  "type": "module",
6
6
  "homepage": "https://fluid-dnd.netlify.app",
@@ -58,9 +58,7 @@
58
58
  "license": "MIT",
59
59
  "devDependencies": {
60
60
  "@playwright/test": "^1.43.0",
61
- "eslint-plugin-vue": "^9.33.0",
62
61
  "@types/node": "^20.12.5",
63
- "@vitejs/plugin-vue": "^4.5.2",
64
62
  "@types/react": "^18.3.20",
65
63
  "@types/react-dom": "^19.1.2",
66
64
  "jsdom": "^24.0.0",
@@ -68,14 +66,13 @@
68
66
  "vite": "^5.0.8",
69
67
  "vite-plugin-dts": "^3.7.0",
70
68
  "vitest": "^1.2.2",
71
- "vue-tsc": "^2.2.8",
72
69
  "prettier-plugin-svelte": "^3.3.3",
73
70
  "svelte": "^5.0.0",
74
71
  "vue": ">=3.4.0"
75
72
  },
76
73
  "scripts": {
77
74
  "dev": "cd my-test-examples && vite",
78
- "build": "vite build",
75
+ "build": "vite build && tsc",
79
76
  "preview": "vite preview",
80
77
  "test": "vitest"
81
78
  }