fluid-dnd 2.1.0 → 2.1.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.
- package/dist/{HandlerPublisher-LAmM6gCQ.js → HandlerPublisher-CVvTsXrJ.js} +1 -1
- package/dist/core/index.d.ts +3 -3
- package/dist/core/index.js +2 -2
- package/dist/core/useDraggable.d.ts +2 -2
- package/dist/core/useDraggable.js +37 -38
- package/dist/{index-D_kOy-fH.js → index-C6IKL-bo.js} +16 -51
- package/dist/index.mjs +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.mjs +34 -29
- package/dist/react/useDragAndDrop.d.ts +1 -1
- package/dist/react/useDragAndDrop.js +5 -6
- package/dist/svelte/index.mjs +2 -2
- package/dist/svelte/utils/SvelteListCondig.d.ts +2 -2
- package/dist/svelte/utils/SvelteListCondig.js +1 -5
- package/dist/vue/index.mjs +2 -2
- package/package.json +4 -3
@@ -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-
|
4
|
+
import { a as h, t as n, G as t } from "./index-C6IKL-bo.js";
|
5
5
|
class c {
|
6
6
|
constructor() {
|
7
7
|
r(this, "handlers");
|
package/dist/core/index.d.ts
CHANGED
@@ -92,7 +92,7 @@ export interface Config<T> {
|
|
92
92
|
/**
|
93
93
|
* The delay before the touchmove event is fired.
|
94
94
|
*/
|
95
|
-
delayBeforeTouchMoveEvent
|
95
|
+
delayBeforeTouchMoveEvent?: number;
|
96
96
|
}
|
97
97
|
/**
|
98
98
|
* onDrop event function.
|
@@ -141,8 +141,8 @@ export type CoreConfig<T> = {
|
|
141
141
|
*/
|
142
142
|
isDraggable: (element: HTMLElement) => boolean;
|
143
143
|
/**
|
144
|
-
|
145
|
-
|
144
|
+
* A function that is called when the draggable element starts being dragged.
|
145
|
+
*/
|
146
146
|
onDragStart: (element: DragStartEventData<T>) => void;
|
147
147
|
/**
|
148
148
|
* A function that is called when the draggable element is dropped.
|
package/dist/core/index.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export const HORIZONTAL =
|
2
|
-
export const VERTICAL =
|
1
|
+
export const HORIZONTAL = 'horizontal';
|
2
|
+
export const VERTICAL = 'vertical';
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import { CoreConfig } from
|
2
|
-
import HandlerPublisher from
|
1
|
+
import { CoreConfig } from '.';
|
2
|
+
import HandlerPublisher from './HandlerPublisher';
|
3
3
|
export default function useDraggable<T>(draggableElement: HTMLElement, index: number, config: CoreConfig<T>, parent: HTMLElement, handlerPublisher: HandlerPublisher): readonly [(targetIndex: number) => void, (targetIndex: number, value: T) => void];
|
@@ -1,13 +1,13 @@
|
|
1
|
-
import { assignDraggingEvent, convetEventToDragMouseTouchEvent, moveTranslate, setCustomFixedSize, setEventWithInterval, setTranistion
|
2
|
-
import { useTransform } from
|
3
|
-
import useEmitEvents from
|
4
|
-
import { DRAG_EVENT, draggableTargetTimingFunction, START_DRAG_EVENT, START_DROP_EVENT } from
|
5
|
-
import ConfigHandler from
|
6
|
-
import { IsHTMLElement, isTouchEvent } from
|
7
|
-
import { addTempChild, addTempChildOnInsert, removeTempChildrens } from
|
8
|
-
import { DroppableConfigurator } from
|
9
|
-
import { addClass, containClass, getClassesList, getClassesSelector, removeClass, toggleClass
|
10
|
-
import { DRAGGABLE_CLASS, DRAGGING_CLASS, DROPPABLE_CLASS, HANDLER_CLASS } from
|
1
|
+
import { assignDraggingEvent, convetEventToDragMouseTouchEvent, moveTranslate, setCustomFixedSize, setEventWithInterval, setTranistion } from './utils/SetStyles';
|
2
|
+
import { useTransform } from './utils/SetTransform';
|
3
|
+
import useEmitEvents from './utils/events/emitEvents';
|
4
|
+
import { DRAG_EVENT, draggableTargetTimingFunction, START_DRAG_EVENT, START_DROP_EVENT } from './utils';
|
5
|
+
import ConfigHandler from './configHandler';
|
6
|
+
import { IsHTMLElement, isTouchEvent } from './utils/touchDevice';
|
7
|
+
import { addTempChild, addTempChildOnInsert, removeTempChildrens } from './utils/tempChildren';
|
8
|
+
import { DroppableConfigurator } from './utils/droppableConfigurator';
|
9
|
+
import { addClass, containClass, getClassesList, getClassesSelector, removeClass, toggleClass } from './utils/dom/classList';
|
10
|
+
import { DRAGGABLE_CLASS, DRAGGING_CLASS, DROPPABLE_CLASS, HANDLER_CLASS } from './utils/classes';
|
11
11
|
var DraggingState;
|
12
12
|
(function (DraggingState) {
|
13
13
|
DraggingState[DraggingState["NOT_DRAGGING"] = 0] = "NOT_DRAGGING";
|
@@ -19,11 +19,11 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
19
19
|
const { handlerSelector, isDraggable, droppableGroup, animationDuration, delayBeforeRemove, draggingClass, removingClass, onRemoveAtEvent, droppableClass, onDragStart, delayBeforeTouchMoveEvent } = config;
|
20
20
|
const droppableGroupClass = getClassesList(droppableGroup)
|
21
21
|
.map((classGroup) => `droppable-group-${classGroup}`)
|
22
|
-
.join(
|
22
|
+
.join(' ');
|
23
23
|
let draggingState = DraggingState.NOT_DRAGGING;
|
24
24
|
let windowScroll = {
|
25
25
|
scrollX: 0,
|
26
|
-
scrollY: 0
|
26
|
+
scrollY: 0
|
27
27
|
};
|
28
28
|
let pagePosition = { pageX: 0, pageY: 0 };
|
29
29
|
let delayTimeout;
|
@@ -32,7 +32,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
32
32
|
const endDraggingState = () => {
|
33
33
|
draggingState = DraggingState.NOT_DRAGGING;
|
34
34
|
};
|
35
|
-
const [emitEventToSiblings, emitRemoveEventToSiblings, emitInsertEventToSiblings, emitFinishRemoveEventToSiblings, toggleDraggingClass
|
35
|
+
const [emitEventToSiblings, emitRemoveEventToSiblings, emitInsertEventToSiblings, emitFinishRemoveEventToSiblings, toggleDraggingClass] = useEmitEvents(config, index, parent, droppableGroupClass, handlerPublisher, endDraggingState);
|
36
36
|
const setDraggable = () => {
|
37
37
|
addClass(draggableElement, DRAGGABLE_CLASS);
|
38
38
|
};
|
@@ -58,9 +58,10 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
58
58
|
const getHandler = (element) => {
|
59
59
|
const handler = element?.querySelector(`.${HANDLER_CLASS}`);
|
60
60
|
const handlerParent = handler?.parentElement;
|
61
|
-
if (handler &&
|
62
|
-
|
63
|
-
|
61
|
+
if (handler &&
|
62
|
+
handlerParent &&
|
63
|
+
containClass(handlerParent, DROPPABLE_CLASS) &&
|
64
|
+
!handlerParent.isSameNode(parent)) {
|
64
65
|
return null;
|
65
66
|
}
|
66
67
|
return handler;
|
@@ -68,23 +69,23 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
68
69
|
const setSlotRefElementParams = (element) => {
|
69
70
|
const handlerElement = (getHandler(element) ?? element);
|
70
71
|
if (handlerElement && isDraggable(element)) {
|
71
|
-
assignDraggingEvent(handlerElement,
|
72
|
-
assignDraggingEvent(handlerElement,
|
72
|
+
assignDraggingEvent(handlerElement, 'onmousedown', onmousedown('mousemove', 'mouseup'));
|
73
|
+
assignDraggingEvent(handlerElement, 'ontouchstart', onmousedown('touchmove', 'touchend'), (event) => {
|
73
74
|
initialTouch = {
|
74
75
|
x: event.touches[0].clientX,
|
75
|
-
y: event.touches[0].clientY
|
76
|
+
y: event.touches[0].clientY
|
76
77
|
};
|
77
78
|
});
|
78
79
|
disableMousedownEventFromImages(handlerElement);
|
79
80
|
}
|
80
81
|
if (!element?.isSameNode(handlerElement)) {
|
81
|
-
assignDraggingEvent(element,
|
82
|
+
assignDraggingEvent(element, 'onmousedown', mousedownOnDraggablefunction);
|
82
83
|
}
|
83
84
|
addClass(parent, DROPPABLE_CLASS);
|
84
85
|
};
|
85
86
|
const disableMousedownEventFromImages = (handlerElement) => {
|
86
87
|
// Avoid dragging inner images
|
87
|
-
const images = handlerElement.querySelectorAll(
|
88
|
+
const images = handlerElement.querySelectorAll('img');
|
88
89
|
Array.from(images).forEach((image) => {
|
89
90
|
image.onmousedown = () => false;
|
90
91
|
});
|
@@ -112,11 +113,11 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
112
113
|
if (!droppableConfigurator.current) {
|
113
114
|
return;
|
114
115
|
}
|
115
|
-
const droppables = droppableGroupClass
|
116
|
+
const droppables = droppableGroupClass
|
117
|
+
? Array.from(document.querySelectorAll(getClassesSelector(droppableGroupClass)))
|
118
|
+
: [parent];
|
116
119
|
for (const droppable of droppables) {
|
117
|
-
droppable
|
118
|
-
.classList
|
119
|
-
.toggle(droppableClass, !isOutside && droppable.isSameNode(droppableConfigurator.current.droppable));
|
120
|
+
droppable.classList.toggle(droppableClass, !isOutside && droppable.isSameNode(droppableConfigurator.current.droppable));
|
120
121
|
}
|
121
122
|
};
|
122
123
|
const onMove = (event, isTouchEvent = false) => {
|
@@ -159,15 +160,14 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
159
160
|
if (isTouchEvent(event) && event.cancelable && draggingState == DraggingState.DRAGING) {
|
160
161
|
event.preventDefault();
|
161
162
|
}
|
162
|
-
if ((isTouchEvent(event) && !event.cancelable)
|
163
|
-
|
164
|
-
disableDragging("touchmove", event);
|
163
|
+
if ((isTouchEvent(event) && !event.cancelable) || !cursorWasNotMoved(event)) {
|
164
|
+
disableDragging('touchmove', event);
|
165
165
|
return;
|
166
166
|
}
|
167
167
|
onMove(eventToDragMouse, isTouchEvent(event));
|
168
168
|
};
|
169
169
|
const addTouchDeviceDelay = (event, callback) => {
|
170
|
-
if (event ==
|
170
|
+
if (event == 'touchmove') {
|
171
171
|
delayTimeout = setTimeout(() => {
|
172
172
|
callback();
|
173
173
|
}, delayBeforeTouchMoveEvent);
|
@@ -184,7 +184,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
184
184
|
};
|
185
185
|
const getDragStartEventData = (element) => {
|
186
186
|
const value = config.onGetValue(index);
|
187
|
-
return
|
187
|
+
return { index, element, value };
|
188
188
|
};
|
189
189
|
const startTouchMoveEvent = (event) => {
|
190
190
|
droppableConfigurator.updateConfig(event);
|
@@ -209,11 +209,11 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
209
209
|
}
|
210
210
|
});
|
211
211
|
document.addEventListener(moveEvent, handleMove, {
|
212
|
-
passive: false
|
212
|
+
passive: false
|
213
213
|
});
|
214
214
|
makeScrollEventOnDroppable(parent);
|
215
215
|
document.addEventListener(onLeaveEvent, onLeave(moveEvent), {
|
216
|
-
once: true
|
216
|
+
once: true
|
217
217
|
});
|
218
218
|
}
|
219
219
|
};
|
@@ -269,7 +269,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
269
269
|
setTransformDragEvent();
|
270
270
|
};
|
271
271
|
const makeScrollEventOnDroppable = (droppable) => {
|
272
|
-
return setEventWithInterval(droppable,
|
272
|
+
return setEventWithInterval(droppable, 'onscroll', onScrollEvent);
|
273
273
|
};
|
274
274
|
const onScrollEvent = () => {
|
275
275
|
return setTransformDragEvent();
|
@@ -282,9 +282,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
282
282
|
draggingState = DraggingState.END_DRAGGING;
|
283
283
|
removeDraggingStyles(draggableElement);
|
284
284
|
if (draggableElement.classList.contains(DRAGGING_CLASS)) {
|
285
|
-
emitEventToSiblings(draggableElement, START_DROP_EVENT, windowScroll, isOutsideAllDroppables ?
|
286
|
-
droppableConfigurator.initial :
|
287
|
-
droppableConfigurator.current, index);
|
285
|
+
emitEventToSiblings(draggableElement, START_DROP_EVENT, windowScroll, isOutsideAllDroppables ? droppableConfigurator.initial : droppableConfigurator.current, index);
|
288
286
|
}
|
289
287
|
};
|
290
288
|
const removeDraggingStyles = (element) => {
|
@@ -299,7 +297,7 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
299
297
|
});
|
300
298
|
toggleDraggingClass(element, true);
|
301
299
|
toggleClass(element, draggingClass, true);
|
302
|
-
element.style.transition =
|
300
|
+
element.style.transition = '';
|
303
301
|
};
|
304
302
|
const removeAfterRemovingClass = (targetIndex, config) => {
|
305
303
|
removeClass(draggableElement, removingClass);
|
@@ -323,7 +321,8 @@ export default function useDraggable(draggableElement, index, config, parent, ha
|
|
323
321
|
}
|
324
322
|
};
|
325
323
|
const insertAtFromElement = (targetIndex, value) => {
|
326
|
-
if (targetIndex === index ||
|
324
|
+
if (targetIndex === index ||
|
325
|
+
(targetIndex === config.onGetLegth() && index === targetIndex - 1)) {
|
327
326
|
emitInsertEventToSiblings(targetIndex, draggableElement, parent, value, () => {
|
328
327
|
addTempChildOnInsert(draggableElement, draggingState == DraggingState.START_DRAGGING, droppableConfigurator.initial);
|
329
328
|
});
|
@@ -967,9 +967,7 @@ function Ln(e, t, n, s, o) {
|
|
967
967
|
scrollX: 0,
|
968
968
|
scrollY: 0
|
969
969
|
}, x = { pageX: 0, pageY: 0 }, $, G;
|
970
|
-
const [j, st] = Qe(
|
971
|
-
e
|
972
|
-
), I = () => {
|
970
|
+
const [j, st] = Qe(e), I = () => {
|
973
971
|
v = 0;
|
974
972
|
}, [
|
975
973
|
L,
|
@@ -1000,11 +998,7 @@ function Ln(e, t, n, s, o) {
|
|
1000
998
|
return g && D && et(D, Xt) && !D.isSameNode(s) ? null : g;
|
1001
999
|
}, ut = (i) => {
|
1002
1000
|
const g = lt(i) ?? i;
|
1003
|
-
g && c(i) && (It(
|
1004
|
-
g,
|
1005
|
-
"onmousedown",
|
1006
|
-
ft("mousemove", "mouseup")
|
1007
|
-
), It(
|
1001
|
+
g && c(i) && (It(g, "onmousedown", ft("mousemove", "mouseup")), It(
|
1008
1002
|
g,
|
1009
1003
|
"ontouchstart",
|
1010
1004
|
ft("touchmove", "touchend"),
|
@@ -1024,19 +1018,9 @@ function Ln(e, t, n, s, o) {
|
|
1024
1018
|
if (x.pageX == 0 && x.pageY == 0 || !d.current)
|
1025
1019
|
return;
|
1026
1020
|
const { droppable: i, config: g } = d.current;
|
1027
|
-
j(e, i, x, g.direction), L(
|
1028
|
-
e,
|
1029
|
-
Pt,
|
1030
|
-
w,
|
1031
|
-
d.current
|
1032
|
-
);
|
1021
|
+
j(e, i, x, g.direction), L(e, Pt, w, d.current);
|
1033
1022
|
}, h = (i, g) => {
|
1034
|
-
g && v == 2 && !(i != null && i.droppable.isSameNode(g.droppable)) && L(
|
1035
|
-
e,
|
1036
|
-
Pt,
|
1037
|
-
w,
|
1038
|
-
g
|
1039
|
-
);
|
1023
|
+
g && v == 2 && !(i != null && i.droppable.isSameNode(g.droppable)) && L(e, Pt, w, g);
|
1040
1024
|
}, d = new Rn(
|
1041
1025
|
e,
|
1042
1026
|
m,
|
@@ -1047,9 +1031,7 @@ function Ln(e, t, n, s, o) {
|
|
1047
1031
|
), y = (i) => {
|
1048
1032
|
if (!d.current)
|
1049
1033
|
return;
|
1050
|
-
const g = m ? Array.from(
|
1051
|
-
document.querySelectorAll(gt(m))
|
1052
|
-
) : [s];
|
1034
|
+
const g = m ? Array.from(document.querySelectorAll(gt(m))) : [s];
|
1053
1035
|
for (const D of g)
|
1054
1036
|
D.classList.toggle(
|
1055
1037
|
N,
|
@@ -1063,13 +1045,7 @@ function Ln(e, t, n, s, o) {
|
|
1063
1045
|
if (!d.current)
|
1064
1046
|
return;
|
1065
1047
|
const { droppable: g } = d.current;
|
1066
|
-
xn(
|
1067
|
-
g,
|
1068
|
-
s,
|
1069
|
-
m,
|
1070
|
-
u,
|
1071
|
-
i
|
1072
|
-
), !i && Yt(
|
1048
|
+
xn(g, s, m, u, i), !i && Yt(
|
1073
1049
|
e,
|
1074
1050
|
s,
|
1075
1051
|
v == 1,
|
@@ -1181,14 +1157,9 @@ function Ln(e, t, n, s, o) {
|
|
1181
1157
|
s,
|
1182
1158
|
v == 1,
|
1183
1159
|
d.initial
|
1184
|
-
), Z(
|
1185
|
-
|
1186
|
-
|
1187
|
-
g,
|
1188
|
-
(D) => {
|
1189
|
-
Jt(D), k(e);
|
1190
|
-
}
|
1191
|
-
), M(t, !0);
|
1160
|
+
), Z(i, e, g, (D) => {
|
1161
|
+
Jt(D), k(e);
|
1162
|
+
}), M(t, !0);
|
1192
1163
|
}, Ee = (i) => {
|
1193
1164
|
if (!d.initial)
|
1194
1165
|
return;
|
@@ -1197,19 +1168,13 @@ function Ln(e, t, n, s, o) {
|
|
1197
1168
|
Te(i, g);
|
1198
1169
|
}, p));
|
1199
1170
|
}, ye = (i, g) => {
|
1200
|
-
(i === t || i === n.onGetLegth() && t === i - 1) && H(
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
e,
|
1208
|
-
v == 1,
|
1209
|
-
d.initial
|
1210
|
-
);
|
1211
|
-
}
|
1212
|
-
);
|
1171
|
+
(i === t || i === n.onGetLegth() && t === i - 1) && H(i, e, s, g, () => {
|
1172
|
+
Cn(
|
1173
|
+
e,
|
1174
|
+
v == 1,
|
1175
|
+
d.initial
|
1176
|
+
);
|
1177
|
+
});
|
1213
1178
|
};
|
1214
1179
|
return tt(), ut(e), [Ee, ye];
|
1215
1180
|
}
|
package/dist/index.mjs
CHANGED
package/dist/react/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react"),y=require("../HandlerPublisher-CsD6p60X.cjs"),b=require("../index-DE3X7xW4.cjs"),S=require("react-dom");function A(l,f){const[e,n]=u.useState(l),i=u.useRef(e);u.useEffect(()=>{i.current=e},[e]);function d(t,r=!1){const s=i.current[t],c=()=>{n(o=>[...o.slice(0,t),...o.slice(t+1)])};return r?S.flushSync(c):c(),s}function g(t,r,s=!1){const c=()=>{n(o=>[...o.slice(0,t),r,...o.slice(t)])};s?S.flushSync(c):c()}function h(){return e.length}function m(t){return e[t]}function a(t,r,s){b.insertToListEmpty(t,f.current,r,s)}return[e,n,{removeAtEvent:d,insertEvent:g,getLength:h,getValue:m,insertToListEmpty:a}]}const D=new y.HandlerPublisher;function E(l,f){const e=u.useRef(null),[n,i,d]=A(l,e),[g,h,m]=b.dragAndDrop(d,D,f,"data-index");return u.useEffect(()=>{const a=m(e.current);return()=>{a&&a.disconnect()}},[n.length]),[e,n,i,h,g]}exports.useDragAndDrop=E;
|
package/dist/react/index.mjs
CHANGED
@@ -1,30 +1,30 @@
|
|
1
|
-
import { useState as S, useRef as
|
2
|
-
import { H as
|
3
|
-
import { i as
|
4
|
-
import { flushSync as
|
5
|
-
function
|
6
|
-
const [t, n] = S(
|
1
|
+
import { useState as S, useRef as h, useEffect as E } from "react";
|
2
|
+
import { H as b } from "../HandlerPublisher-CVvTsXrJ.js";
|
3
|
+
import { i as A, d as C } from "../index-C6IKL-bo.js";
|
4
|
+
import { flushSync as p } from "react-dom";
|
5
|
+
function L(u, l) {
|
6
|
+
const [t, n] = S(u), c = h(t);
|
7
7
|
E(() => {
|
8
|
-
|
8
|
+
c.current = t;
|
9
9
|
}, [t]);
|
10
|
-
function f(e,
|
11
|
-
const
|
12
|
-
n((
|
13
|
-
...
|
14
|
-
...
|
10
|
+
function f(e, r = !1) {
|
11
|
+
const s = c.current[e], o = () => {
|
12
|
+
n((i) => [
|
13
|
+
...i.slice(0, e),
|
14
|
+
...i.slice(e + 1)
|
15
15
|
]);
|
16
16
|
};
|
17
|
-
return
|
17
|
+
return r ? p(o) : o(), s;
|
18
18
|
}
|
19
|
-
function m(e,
|
19
|
+
function m(e, r, s = !1) {
|
20
20
|
const o = () => {
|
21
|
-
n((
|
22
|
-
...
|
23
|
-
|
24
|
-
...
|
21
|
+
n((i) => [
|
22
|
+
...i.slice(0, e),
|
23
|
+
r,
|
24
|
+
...i.slice(e)
|
25
25
|
]);
|
26
26
|
};
|
27
|
-
|
27
|
+
s ? p(o) : o();
|
28
28
|
}
|
29
29
|
function g() {
|
30
30
|
return t.length;
|
@@ -32,27 +32,32 @@ function v(a, l) {
|
|
32
32
|
function d(e) {
|
33
33
|
return t[e];
|
34
34
|
}
|
35
|
-
function
|
36
|
-
|
35
|
+
function a(e, r, s) {
|
36
|
+
A(e, l.current, r, s);
|
37
37
|
}
|
38
38
|
return [t, n, {
|
39
39
|
removeAtEvent: f,
|
40
40
|
insertEvent: m,
|
41
41
|
getLength: g,
|
42
42
|
getValue: d,
|
43
|
-
insertToListEmpty:
|
43
|
+
insertToListEmpty: a
|
44
44
|
}];
|
45
45
|
}
|
46
|
-
const
|
47
|
-
function
|
48
|
-
const t =
|
46
|
+
const v = new b();
|
47
|
+
function k(u, l) {
|
48
|
+
const t = h(null), [n, c, f] = L(u, t), [m, g, d] = C(
|
49
|
+
f,
|
50
|
+
v,
|
51
|
+
l,
|
52
|
+
"data-index"
|
53
|
+
);
|
49
54
|
return E(() => {
|
50
|
-
const
|
55
|
+
const a = d(t.current);
|
51
56
|
return () => {
|
52
|
-
|
57
|
+
a && a.disconnect();
|
53
58
|
};
|
54
|
-
}, [n.length]), [t, n,
|
59
|
+
}, [n.length]), [t, n, c, g, m];
|
55
60
|
}
|
56
61
|
export {
|
57
|
-
|
62
|
+
k as useDragAndDrop
|
58
63
|
};
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import { Config } from
|
1
|
+
import { Config } from '../core';
|
2
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];
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import { useEffect,
|
2
|
-
import HandlerPublisher from
|
3
|
-
import { dragAndDrop } from
|
4
|
-
import { useReactListConfig } from
|
1
|
+
import { useEffect, useRef } from 'react';
|
2
|
+
import HandlerPublisher from '../core/HandlerPublisher';
|
3
|
+
import { dragAndDrop } from '../index';
|
4
|
+
import { useReactListConfig } from './utils/ReactLilstConfig';
|
5
5
|
/**
|
6
6
|
* Create the parent element of the draggable children and all the drag and drop events and styles.
|
7
7
|
*
|
@@ -14,12 +14,11 @@ const handlerPublisher = new HandlerPublisher();
|
|
14
14
|
export default function useDragAndDrop(items, config) {
|
15
15
|
const parent = useRef(null);
|
16
16
|
const [itemsState, setItemsState, listCondig] = useReactListConfig(items, parent);
|
17
|
-
const [removeAt, insertAt, onChangeParent] =
|
17
|
+
const [removeAt, insertAt, onChangeParent] = dragAndDrop(listCondig, handlerPublisher, config, 'data-index');
|
18
18
|
useEffect(() => {
|
19
19
|
const observer = onChangeParent(parent.current);
|
20
20
|
return () => {
|
21
21
|
if (observer) {
|
22
|
-
console.log('disconnect');
|
23
22
|
observer.disconnect();
|
24
23
|
}
|
25
24
|
};
|
package/dist/svelte/index.mjs
CHANGED
@@ -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-
|
5
|
-
import { i as m, d as u } from "../index-
|
4
|
+
import { H as c } from "../HandlerPublisher-CVvTsXrJ.js";
|
5
|
+
import { i as m, d as u } from "../index-C6IKL-bo.js";
|
6
6
|
class h {
|
7
7
|
constructor(t) {
|
8
8
|
r(this, "items");
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { CoreConfig } from
|
2
|
-
import { ListCondig } from
|
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;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { insertToListEmpty } from
|
1
|
+
import { insertToListEmpty } from '../../core/utils/events/emitEvents';
|
2
2
|
export class SvelteListCondig {
|
3
3
|
items;
|
4
4
|
parent;
|
@@ -8,7 +8,6 @@ export class SvelteListCondig {
|
|
8
8
|
setParent(parent) {
|
9
9
|
this.parent = parent;
|
10
10
|
}
|
11
|
-
;
|
12
11
|
removeAtEvent(index) {
|
13
12
|
const listValue = this.items;
|
14
13
|
if (listValue.length <= 0) {
|
@@ -17,16 +16,13 @@ export class SvelteListCondig {
|
|
17
16
|
const [deletedItem] = listValue.splice(index, 1);
|
18
17
|
return deletedItem;
|
19
18
|
}
|
20
|
-
;
|
21
19
|
insertEvent(index, value) {
|
22
20
|
const listValue = this.items;
|
23
21
|
listValue.splice(index, 0, value);
|
24
22
|
}
|
25
|
-
;
|
26
23
|
getLength() {
|
27
24
|
return this.items.length;
|
28
25
|
}
|
29
|
-
;
|
30
26
|
getValue(index) {
|
31
27
|
return this.items[index];
|
32
28
|
}
|
package/dist/vue/index.mjs
CHANGED
@@ -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-
|
6
|
-
import { i as p, d as v } from "../index-
|
5
|
+
import { H as h } from "../HandlerPublisher-CVvTsXrJ.js";
|
6
|
+
import { i as p, d as v } from "../index-C6IKL-bo.js";
|
7
7
|
const g = (n, t) => {
|
8
8
|
const e = n.value;
|
9
9
|
if (e.length <= 0)
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "fluid-dnd",
|
3
|
-
"version": "2.1.
|
3
|
+
"version": "2.1.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",
|
@@ -62,12 +62,13 @@
|
|
62
62
|
"@types/react": "^18.3.20",
|
63
63
|
"@types/react-dom": "^19.1.2",
|
64
64
|
"jsdom": "^24.0.0",
|
65
|
+
"prettier": "3.5.3",
|
66
|
+
"prettier-plugin-svelte": "^3.3.3",
|
67
|
+
"svelte": "^5.0.0",
|
65
68
|
"typescript": "^5.2.2",
|
66
69
|
"vite": "^5.0.8",
|
67
70
|
"vite-plugin-dts": "^3.7.0",
|
68
71
|
"vitest": "^1.2.2",
|
69
|
-
"prettier-plugin-svelte": "^3.3.3",
|
70
|
-
"svelte": "^5.0.0",
|
71
72
|
"vue": ">=3.4.0"
|
72
73
|
},
|
73
74
|
"scripts": {
|