fluid-dnd 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +8 -9
  2. package/dist/{HandlerPublisher-C-jTncuG.cjs → HandlerPublisher-CsD6p60X.cjs} +1 -1
  3. package/dist/{HandlerPublisher-BYI2bw4n.js → HandlerPublisher-LAmM6gCQ.js} +1 -1
  4. package/dist/core/HandlerPublisher.js +20 -0
  5. package/dist/core/configHandler.d.ts +2 -3
  6. package/dist/core/configHandler.js +33 -0
  7. package/dist/core/dragAndDrop.d.ts +3 -3
  8. package/dist/core/dragAndDrop.js +62 -0
  9. package/dist/core/index.d.ts +11 -0
  10. package/dist/core/index.js +2 -0
  11. package/dist/core/useDraggable.d.ts +2 -3
  12. package/dist/core/useDraggable.js +335 -0
  13. package/dist/core/useDroppable.d.ts +2 -3
  14. package/dist/core/useDroppable.js +55 -0
  15. package/dist/core/utils/GetStyles.d.ts +2 -3
  16. package/dist/core/utils/GetStyles.js +138 -0
  17. package/dist/core/utils/ParseStyles.d.ts +2 -3
  18. package/dist/core/utils/ParseStyles.js +40 -0
  19. package/dist/core/utils/SetStyles.d.ts +1 -2
  20. package/dist/core/utils/SetStyles.js +192 -0
  21. package/dist/core/utils/SetTransform.d.ts +2 -3
  22. package/dist/core/utils/SetTransform.js +148 -0
  23. package/dist/core/utils/classes.js +9 -0
  24. package/dist/core/utils/config.d.ts +3 -3
  25. package/dist/core/utils/config.js +56 -0
  26. package/dist/core/utils/dom/classList.js +35 -0
  27. package/dist/core/utils/droppableConfigurator.d.ts +3 -4
  28. package/dist/core/utils/droppableConfigurator.js +106 -0
  29. package/dist/core/utils/events/emitEvents.d.ts +5 -6
  30. package/dist/core/utils/events/emitEvents.js +333 -0
  31. package/dist/core/utils/index.js +9 -0
  32. package/dist/core/utils/observer.js +11 -0
  33. package/dist/core/utils/scroll.d.ts +2 -3
  34. package/dist/core/utils/scroll.js +17 -0
  35. package/dist/core/utils/tempChildren.d.ts +1 -2
  36. package/dist/core/utils/tempChildren.js +146 -0
  37. package/dist/core/utils/touchDevice.js +3 -0
  38. package/dist/core/utils/translate/GetTranslateBeforeDropping.d.ts +2 -3
  39. package/dist/core/utils/translate/GetTranslateBeforeDropping.js +129 -0
  40. package/dist/core/utils/translate/GetTranslationByDraggingAndEvent.d.ts +2 -3
  41. package/dist/core/utils/translate/GetTranslationByDraggingAndEvent.js +48 -0
  42. package/dist/index-DE3X7xW4.cjs +1 -0
  43. package/dist/index-D_kOy-fH.js +1306 -0
  44. package/dist/index.cjs +1 -1
  45. package/dist/index.d.ts +4 -0
  46. package/dist/index.js +2 -0
  47. package/dist/index.mjs +1 -1
  48. package/dist/react/index.cjs +1 -1
  49. package/dist/react/index.d.ts +1 -2
  50. package/dist/react/index.js +2 -0
  51. package/dist/react/index.mjs +2 -2
  52. package/dist/react/useDragAndDrop.d.ts +2 -3
  53. package/dist/react/useDragAndDrop.js +28 -0
  54. package/dist/react/utils/ReactLilstConfig.d.ts +3 -4
  55. package/dist/react/utils/ReactLilstConfig.js +64 -0
  56. package/dist/svelte/index.cjs +1 -1
  57. package/dist/svelte/index.d.ts +1 -2
  58. package/dist/svelte/index.js +2 -0
  59. package/dist/svelte/index.mjs +2 -2
  60. package/dist/svelte/useDragAndDrop.d.ts +1 -2
  61. package/dist/svelte/useDragAndDrop.js +25 -0
  62. package/dist/svelte/utils/SvelteListCondig.d.ts +2 -2
  63. package/dist/svelte/utils/SvelteListCondig.js +36 -0
  64. package/dist/vue/index.cjs +1 -1
  65. package/dist/vue/index.d.ts +1 -2
  66. package/dist/vue/index.js +2 -0
  67. package/dist/vue/index.mjs +2 -2
  68. package/dist/vue/useDragAndDrop.d.ts +2 -3
  69. package/dist/vue/useDragAndDrop.js +23 -0
  70. package/dist/vue/utils/DropMethods.d.ts +1 -2
  71. package/dist/vue/utils/DropMethods.js +19 -0
  72. package/dist/vue/utils/VueListCondig.d.ts +3 -3
  73. package/dist/vue/utils/VueListCondig.js +28 -0
  74. package/package.json +2 -5
  75. package/dist/index-BQUYvZRn.js +0 -1301
  76. package/dist/index-DNmnvxhi.cjs +0 -1
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-DNmnvxhi.cjs");exports.dragAndDrop=e.dragAndDrop;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-DE3X7xW4.cjs");exports.dragAndDrop=e.dragAndDrop;
@@ -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 };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { d as o } from "./index-BQUYvZRn.js";
1
+ import { d as o } from "./index-D_kOy-fH.js";
2
2
  export {
3
3
  o as dragAndDrop
4
4
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),y=require("../HandlerPublisher-C-jTncuG.cjs"),b=require("../index-DNmnvxhi.cjs"),S=require("react-dom");function A(a,f){const[e,n]=s.useState(a),i=s.useRef(e);s.useEffect(()=>{i.current=e},[e]);function g(t,r=!1){const c=i.current[t],o=()=>{n(u=>[...u.slice(0,t),...u.slice(t+1)])};return r?S.flushSync(o):o(),c}function d(t,r,c=!1){const o=()=>{n(u=>[...u.slice(0,t),r,...u.slice(t)])};c?S.flushSync(o):o()}function h(){return e.length}function m(t){return e[t]}function l(t,r,c){b.insertToListEmpty(t,f.current,r,c)}return[e,n,{removeAtEvent:g,insertEvent:d,getLength:h,getValue:m,insertToListEmpty:l}]}const D=new y.HandlerPublisher;function E(a,f){const e=s.useRef(null),[n,i,g]=A(a,e),[d,h,m]=s.useMemo(()=>b.dragAndDrop(g,D,f,"data-index"),[n.length]);return s.useEffect(()=>{const l=m(e.current);return()=>{l&&(console.log("disconnect"),l.disconnect())}},[n.length]),[e,n,i,h,d]}exports.useDragAndDrop=E;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),y=require("../HandlerPublisher-CsD6p60X.cjs"),b=require("../index-DE3X7xW4.cjs"),S=require("react-dom");function A(a,f){const[e,n]=s.useState(a),i=s.useRef(e);s.useEffect(()=>{i.current=e},[e]);function g(t,r=!1){const c=i.current[t],o=()=>{n(u=>[...u.slice(0,t),...u.slice(t+1)])};return r?S.flushSync(o):o(),c}function d(t,r,c=!1){const o=()=>{n(u=>[...u.slice(0,t),r,...u.slice(t)])};c?S.flushSync(o):o()}function h(){return e.length}function m(t){return e[t]}function l(t,r,c){b.insertToListEmpty(t,f.current,r,c)}return[e,n,{removeAtEvent:g,insertEvent:d,getLength:h,getValue:m,insertToListEmpty:l}]}const D=new y.HandlerPublisher;function E(a,f){const e=s.useRef(null),[n,i,g]=A(a,e),[d,h,m]=s.useMemo(()=>b.dragAndDrop(g,D,f,"data-index"),[n.length]);return s.useEffect(()=>{const l=m(e.current);return()=>{l&&(console.log("disconnect"),l.disconnect())}},[n.length]),[e,n,i,h,d]}exports.useDragAndDrop=E;
@@ -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,6 +1,6 @@
1
1
  import { useState as S, useRef as p, useEffect as E, useMemo as b } from "react";
2
- import { H as A } from "../HandlerPublisher-BYI2bw4n.js";
3
- import { i as C, d as L } from "../index-BQUYvZRn.js";
2
+ import { H as A } from "../HandlerPublisher-LAmM6gCQ.js";
3
+ import { i as C, d as L } from "../index-D_kOy-fH.js";
4
4
  import { flushSync as h } from "react-dom";
5
5
  function v(a, l) {
6
6
  const [t, n] = S(a), i = p(t);
@@ -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 +1 @@
1
- "use strict";var u=Object.defineProperty;var d=(n,t,e)=>t in n?u(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var s=(n,t,e)=>d(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../HandlerPublisher-C-jTncuG.cjs"),o=require("../index-DNmnvxhi.cjs");class g{constructor(t){s(this,"items");s(this,"parent");this.items=t}setParent(t){this.parent=t}removeAtEvent(t){const e=this.items;if(e.length<=0)return;const[r]=e.splice(t,1);return r}insertEvent(t,e){this.items.splice(t,0,e)}getLength(){return this.items.length}getValue(t){return this.items[t]}insertToListEmpty(t,e,r){o.insertToListEmpty(t,this.parent,e,r)}}const h=new c.HandlerPublisher;function m(n,t){const e=new g(n),[r,l,a]=o.dragAndDrop(e,h,t,"data-index");return[i=>(e.setParent(i),a(i),{destroy(){}}),l,r]}exports.useDragAndDrop=m;
1
+ "use strict";var u=Object.defineProperty;var d=(n,t,e)=>t in n?u(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var s=(n,t,e)=>d(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../HandlerPublisher-CsD6p60X.cjs"),o=require("../index-DE3X7xW4.cjs");class g{constructor(t){s(this,"items");s(this,"parent");this.items=t}setParent(t){this.parent=t}removeAtEvent(t){const e=this.items;if(e.length<=0)return;const[r]=e.splice(t,1);return r}insertEvent(t,e){this.items.splice(t,0,e)}getLength(){return this.items.length}getValue(t){return this.items[t]}insertToListEmpty(t,e,r){o.insertToListEmpty(t,this.parent,e,r)}}const h=new c.HandlerPublisher;function m(n,t){const e=new g(n),[r,l,a]=o.dragAndDrop(e,h,t,"data-index");return[i=>(e.setParent(i),a(i),{destroy(){}}),l,r]}exports.useDragAndDrop=m;
@@ -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,8 +1,8 @@
1
1
  var l = Object.defineProperty;
2
2
  var d = (n, t, e) => t in n ? l(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
3
  var r = (n, t, e) => d(n, typeof t != "symbol" ? t + "" : t, e);
4
- import { H as c } from "../HandlerPublisher-BYI2bw4n.js";
5
- import { i as m, d as u } from "../index-BQUYvZRn.js";
4
+ import { H as c } from "../HandlerPublisher-LAmM6gCQ.js";
5
+ import { i as m, d as u } from "../index-D_kOy-fH.js";
6
6
  class h {
7
7
  constructor(t) {
8
8
  r(this, "items");
@@ -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 +1 @@
1
- "use strict";var c=Object.defineProperty;var h=(n,e,t)=>e in n?c(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var s=(n,e,t)=>h(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("vue"),g=require("../HandlerPublisher-C-jTncuG.cjs"),u=require("../index-DNmnvxhi.cjs"),v=(n,e)=>{const t=n.value;if(t.length<=0)return;const[r]=t.splice(e,1);return r},d=(n,e,t)=>{n.value.splice(e,0,t)},m=n=>n.value.length,p=(n,e)=>n.value[e];class V{constructor(e,t){s(this,"items");s(this,"parent");this.items=e,this.parent=t}removeAtEvent(e){return v(this.items,e)}insertEvent(e,t){return d(this.items,e,t)}getLength(){return m(this.items)}getValue(e){return p(this.items,e)}insertToListEmpty(e,t,r){u.insertToListEmpty(e,this.parent.value,t,r)}}const A=new g.HandlerPublisher;function L(n,e){const t=i.ref();var r=new V(n,t);const[l,o,a]=u.dragAndDrop(r,A,e);return i.watch(t,()=>{a(t.value)}),[t,o,l]}exports.useDragAndDrop=L;
1
+ "use strict";var c=Object.defineProperty;var h=(n,e,t)=>e in n?c(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var s=(n,e,t)=>h(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("vue"),g=require("../HandlerPublisher-CsD6p60X.cjs"),u=require("../index-DE3X7xW4.cjs"),v=(n,e)=>{const t=n.value;if(t.length<=0)return;const[r]=t.splice(e,1);return r},d=(n,e,t)=>{n.value.splice(e,0,t)},m=n=>n.value.length,p=(n,e)=>n.value[e];class V{constructor(e,t){s(this,"items");s(this,"parent");this.items=e,this.parent=t}removeAtEvent(e){return v(this.items,e)}insertEvent(e,t){return d(this.items,e,t)}getLength(){return m(this.items)}getValue(e){return p(this.items,e)}insertToListEmpty(e,t,r){u.insertToListEmpty(e,this.parent.value,t,r)}}const A=new g.HandlerPublisher;function L(n,e){const t=i.ref();var r=new V(n,t);const[l,o,a]=u.dragAndDrop(r,A,e);return i.watch(t,()=>{a(t.value)}),[t,o,l]}exports.useDragAndDrop=L;
@@ -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 };
@@ -2,8 +2,8 @@ var l = Object.defineProperty;
2
2
  var u = (n, t, e) => t in n ? l(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
3
  var r = (n, t, e) => u(n, typeof t != "symbol" ? t + "" : t, e);
4
4
  import { ref as c, watch as m } from "vue";
5
- import { H as h } from "../HandlerPublisher-BYI2bw4n.js";
6
- import { i as p, d as v } from "../index-BQUYvZRn.js";
5
+ import { H as h } from "../HandlerPublisher-LAmM6gCQ.js";
6
+ import { i as p, d as v } from "../index-D_kOy-fH.js";
7
7
  const g = (n, t) => {
8
8
  const e = n.value;
9
9
  if (e.length <= 0)
@@ -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.1.0",
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
  }