fluid-dnd 2.3.0 → 2.4.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.
- package/dist/{HandlerPublisher-BNn5KECH.cjs → HandlerPublisher-B68XPAcH.cjs} +1 -1
- package/dist/{HandlerPublisher-xM3zyGAn.js → HandlerPublisher-pcX0Zmas.js} +1 -1
- package/dist/core/{configHandler.d.ts → config/configHandler.d.ts} +2 -2
- package/dist/core/{configHandler.js → config/configHandler.js} +4 -5
- package/dist/core/{utils → config}/droppableConfigurator.d.ts +3 -3
- package/dist/core/{utils → config}/droppableConfigurator.js +28 -11
- package/dist/core/dragAndDrop.d.ts +3 -3
- package/dist/core/dragAndDrop.js +53 -9
- package/dist/core/events/changeDraggableStyles.d.ts +4 -0
- package/dist/core/events/changeDraggableStyles.js +40 -0
- package/dist/core/events/dragAndDrop/dragAndDrop.d.ts +9 -0
- package/dist/core/{utils/events/emitEvents.js → events/dragAndDrop/dragAndDrop.js} +26 -145
- package/dist/core/{utils/translate/GetTranslateBeforeDropping.d.ts → events/dragAndDrop/getTranslateBeforeDropping.d.ts} +2 -2
- package/dist/core/{utils/translate/GetTranslateBeforeDropping.js → events/dragAndDrop/getTranslateBeforeDropping.js} +7 -15
- package/dist/core/{utils/translate/GetTranslationByDraggingAndEvent.d.ts → events/dragAndDrop/getTranslationByDraggingAndEvent.d.ts} +2 -2
- package/dist/core/{utils/translate/GetTranslationByDraggingAndEvent.js → events/dragAndDrop/getTranslationByDraggingAndEvent.js} +4 -4
- package/dist/core/events/insert.d.ts +4 -0
- package/dist/core/events/insert.js +80 -0
- package/dist/core/events/remove.d.ts +4 -0
- package/dist/core/events/remove.js +51 -0
- package/dist/core/{utils/scroll.d.ts → positioning/autoScroll.d.ts} +0 -2
- package/dist/core/{utils/scroll.js → positioning/autoScroll.js} +1 -5
- package/dist/core/{utils/SetTransform.d.ts → positioning/usePositioning.d.ts} +1 -1
- package/dist/core/{utils/SetTransform.js → positioning/usePositioning.js} +5 -5
- package/dist/core/{utils/tempChildren.d.ts → tempChildren.d.ts} +1 -2
- package/dist/core/{utils/tempChildren.js → tempChildren.js} +22 -29
- package/dist/core/useDraggable.js +16 -12
- package/dist/core/utils/SetStyles.d.ts +3 -3
- package/dist/core/utils/SetStyles.js +12 -12
- package/dist/core/utils/observer.d.ts +1 -0
- package/dist/core/utils/observer.js +8 -0
- package/dist/index-2hBSSK9_.cjs +1 -0
- package/dist/index-DFXw7kYo.js +1223 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.mjs +4 -11
- package/dist/react/utils/ReactLilstConfig.d.ts +2 -2
- package/dist/react/utils/ReactLilstConfig.js +7 -17
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.mjs +2 -2
- package/dist/svelte/utils/SvelteListCondig.js +1 -1
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.mjs +2 -2
- package/dist/vue/utils/VueListCondig.d.ts +3 -3
- package/dist/vue/utils/VueListCondig.js +2 -5
- package/package.json +1 -1
- package/dist/core/utils/config.d.ts +0 -5
- package/dist/core/utils/config.js +0 -57
- package/dist/core/utils/events/emitEvents.d.ts +0 -11
- package/dist/index-BYT3HBbe.cjs +0 -1
- package/dist/index-m7C-XuaH.js +0 -1275
- /package/dist/core/utils/{touchDevice.d.ts → typesCheckers.d.ts} +0 -0
- /package/dist/core/utils/{touchDevice.js → typesCheckers.js} +0 -0
@@ -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-
|
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,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-DFXw7kYo.js";
|
5
5
|
class c {
|
6
6
|
constructor() {
|
7
7
|
r(this, "handlers");
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { getScrollElement } from
|
2
|
-
import { containstClasses } from
|
1
|
+
import { getScrollElement } from '../utils/GetStyles';
|
2
|
+
import { containstClasses } from '../utils/dom/classList';
|
3
3
|
export default class ConfigHandler {
|
4
4
|
static configs = [];
|
5
5
|
static addConfig(droppable, config) {
|
@@ -8,7 +8,7 @@ export default class ConfigHandler {
|
|
8
8
|
configs.push({
|
9
9
|
droppable,
|
10
10
|
config,
|
11
|
-
scroll
|
11
|
+
scroll
|
12
12
|
});
|
13
13
|
ConfigHandler.configs = configs;
|
14
14
|
}
|
@@ -19,8 +19,7 @@ export default class ConfigHandler {
|
|
19
19
|
static updateScrolls(currentDroppable, droppableGroupClass) {
|
20
20
|
for (const configHandler of ConfigHandler.configs) {
|
21
21
|
const { droppable } = configHandler;
|
22
|
-
if ((droppableGroupClass &&
|
23
|
-
containstClasses(droppable, droppableGroupClass)) ||
|
22
|
+
if ((droppableGroupClass && containstClasses(droppable, droppableGroupClass)) ||
|
24
23
|
droppable.isSameNode(currentDroppable)) {
|
25
24
|
configHandler.scroll = getScrollElement(droppable);
|
26
25
|
}
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { DroppableConfig } from
|
2
|
-
import { DragMouseTouchEvent } from
|
3
|
-
import { MapFrom } from
|
1
|
+
import { DroppableConfig } from './configHandler';
|
2
|
+
import { DragMouseTouchEvent } from '../../../index';
|
3
|
+
import { MapFrom } from '..';
|
4
4
|
export declare class DroppableConfigurator<T> {
|
5
5
|
initial: DroppableConfig<any> | undefined;
|
6
6
|
current: DroppableConfig<T> | undefined;
|
@@ -1,9 +1,24 @@
|
|
1
|
-
import ConfigHandler from
|
2
|
-
import { draggableIsOutside } from
|
3
|
-
import { IsHTMLElement } from
|
4
|
-
import { setEventWithInterval } from
|
5
|
-
import { getClassesSelector } from
|
6
|
-
|
1
|
+
import ConfigHandler from './configHandler';
|
2
|
+
import { draggableIsOutside } from '../utils/GetStyles';
|
3
|
+
import { IsHTMLElement } from '../utils/typesCheckers';
|
4
|
+
import { setEventWithInterval } from '../utils/SetStyles';
|
5
|
+
import { getClassesSelector } from '../utils/dom/classList';
|
6
|
+
const MapConfig = (coreConfig, mapFrom) => {
|
7
|
+
const { config, droppable } = coreConfig;
|
8
|
+
const { onInsertEvent, onDragEnd } = config;
|
9
|
+
const mapOnInsertEvent = (index, value) => {
|
10
|
+
return onInsertEvent(index, mapFrom(value, droppable), true);
|
11
|
+
};
|
12
|
+
const mapOnDragEnd = (eventData) => {
|
13
|
+
const { index, value } = eventData;
|
14
|
+
onDragEnd({ index, value: mapFrom(value, droppable) });
|
15
|
+
};
|
16
|
+
return {
|
17
|
+
...config,
|
18
|
+
onDragEnd: mapOnDragEnd,
|
19
|
+
onInsertEvent: mapOnInsertEvent
|
20
|
+
};
|
21
|
+
};
|
7
22
|
export class DroppableConfigurator {
|
8
23
|
initial;
|
9
24
|
current;
|
@@ -52,7 +67,9 @@ export class DroppableConfigurator {
|
|
52
67
|
return currentDroppable;
|
53
68
|
}
|
54
69
|
isOutsideOfAllDroppables(currentElement) {
|
55
|
-
const droppables = this.groupClass
|
70
|
+
const droppables = this.groupClass
|
71
|
+
? Array.from(document.querySelectorAll(getClassesSelector(this.groupClass)))
|
72
|
+
: [this.parent];
|
56
73
|
return droppables.every((droppable) => draggableIsOutside(currentElement, droppable));
|
57
74
|
}
|
58
75
|
isNotInsideAnotherDroppable(currentElement, droppable) {
|
@@ -62,9 +79,10 @@ export class DroppableConfigurator {
|
|
62
79
|
onScrollEvent() {
|
63
80
|
this.dragEvent();
|
64
81
|
}
|
65
|
-
;
|
66
82
|
setOnScroll(droppable) {
|
67
|
-
setEventWithInterval(droppable,
|
83
|
+
setEventWithInterval(droppable, 'onscroll', () => {
|
84
|
+
this.onScrollEvent();
|
85
|
+
});
|
68
86
|
}
|
69
87
|
getConfigFrom(element) {
|
70
88
|
const coreConfig = ConfigHandler.getConfig(element);
|
@@ -81,8 +99,7 @@ export class DroppableConfigurator {
|
|
81
99
|
}
|
82
100
|
getCurrentConfig(event) {
|
83
101
|
const currentElement = this.draggableElement;
|
84
|
-
if (this.current &&
|
85
|
-
this.isNotInsideAnotherDroppable(currentElement, this.current?.droppable)) {
|
102
|
+
if (this.current && this.isNotInsideAnotherDroppable(currentElement, this.current?.droppable)) {
|
86
103
|
return this.current;
|
87
104
|
}
|
88
105
|
const currentDroppable = this.getCurrent(currentElement, event);
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ListCondig } from
|
2
|
-
import { Config } from
|
3
|
-
import HandlerPublisher from
|
1
|
+
import { ListCondig } from '.';
|
2
|
+
import { Config } from '.';
|
3
|
+
import HandlerPublisher from './HandlerPublisher';
|
4
4
|
export default function dragAndDrop<T>(listCondig: ListCondig<T>, handlerPublisher: HandlerPublisher, config?: Config<T>, indexAttr?: string): readonly [(index: number) => void, (index: number, value: T) => void, (parent: HTMLElement | null | undefined) => MutationObserver | undefined];
|
package/dist/core/dragAndDrop.js
CHANGED
@@ -1,10 +1,48 @@
|
|
1
|
-
import {
|
2
|
-
import useDroppable from
|
3
|
-
import ConfigHandler from
|
4
|
-
import { observeMutation } from
|
5
|
-
import { addClass } from
|
6
|
-
import { DROPPABLE_CLASS } from
|
7
|
-
|
1
|
+
import { VERTICAL } from '.';
|
2
|
+
import useDroppable from './useDroppable';
|
3
|
+
import ConfigHandler from './config/configHandler';
|
4
|
+
import { isTempElement, observeMutation } from './utils/observer';
|
5
|
+
import { addClass } from './utils/dom/classList';
|
6
|
+
import { DRAGGABLE_CLASS, DROPPABLE_CLASS } from './utils/classes';
|
7
|
+
const getConfig = (listCondig, config) => {
|
8
|
+
const onRemoveAtEvent = (index, sync) => {
|
9
|
+
return listCondig.removeAtEvent(index, sync);
|
10
|
+
};
|
11
|
+
const onInsertEvent = (index, value, sync) => {
|
12
|
+
return listCondig.insertEvent(index, value, sync);
|
13
|
+
};
|
14
|
+
const onGetLegth = () => {
|
15
|
+
return listCondig.getLength();
|
16
|
+
};
|
17
|
+
const onGetValue = (index) => {
|
18
|
+
return listCondig.getValue(index);
|
19
|
+
};
|
20
|
+
const defaultMapFrom = (object) => {
|
21
|
+
return object;
|
22
|
+
};
|
23
|
+
return {
|
24
|
+
direction: config?.direction ?? VERTICAL,
|
25
|
+
handlerSelector: config?.handlerSelector ?? DRAGGABLE_CLASS,
|
26
|
+
draggingClass: config?.draggingClass ?? 'dragging',
|
27
|
+
droppableClass: config?.droppableClass ?? 'droppable-hover',
|
28
|
+
isDraggable: config?.isDraggable ?? (() => true),
|
29
|
+
onDragStart: config?.onDragStart ?? (() => { }),
|
30
|
+
onDragEnd: config?.onDragEnd ?? (() => { }),
|
31
|
+
droppableGroup: config?.droppableGroup,
|
32
|
+
onRemoveAtEvent,
|
33
|
+
onInsertEvent,
|
34
|
+
onGetLegth,
|
35
|
+
onGetValue,
|
36
|
+
animationDuration: config?.animationDuration ?? 200,
|
37
|
+
removingClass: config?.removingClass ?? 'removing',
|
38
|
+
insertingFromClass: config?.insertingFromClass ?? 'from-inserting',
|
39
|
+
delayBeforeRemove: config?.delayBeforeRemove ?? 200,
|
40
|
+
delayBeforeInsert: config?.delayBeforeInsert ?? 200,
|
41
|
+
mapFrom: config?.mapFrom ?? defaultMapFrom,
|
42
|
+
delayBeforeTouchMoveEvent: config?.delayBeforeTouchMoveEvent ?? 150,
|
43
|
+
coordinateTransform: config?.coordinateTransform ?? [(coordinate) => coordinate]
|
44
|
+
};
|
45
|
+
};
|
8
46
|
export default function dragAndDrop(listCondig, handlerPublisher, config, indexAttr = 'index') {
|
9
47
|
let removeAtFromElements = [];
|
10
48
|
let insertAtFromElements = [];
|
@@ -32,8 +70,14 @@ export default function dragAndDrop(listCondig, handlerPublisher, config, indexA
|
|
32
70
|
insertAtFromElements = insertAtFromElementList;
|
33
71
|
};
|
34
72
|
const childrenMutationFilter = (mutation) => {
|
35
|
-
const addedNodes = mutation.addedNodes
|
36
|
-
|
73
|
+
const addedNodes = mutation.addedNodes
|
74
|
+
.values()
|
75
|
+
.filter((element) => !isTempElement(element))
|
76
|
+
.toArray();
|
77
|
+
const removedNodes = mutation.removedNodes
|
78
|
+
.values()
|
79
|
+
.filter((element) => !isTempElement(element))
|
80
|
+
.toArray();
|
37
81
|
return addedNodes.length > 0 || removedNodes.length > 0;
|
38
82
|
};
|
39
83
|
const observeChildrens = (parent) => {
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { Translate } from 'index';
|
2
|
+
import { CoreConfig } from '..';
|
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];
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { DRAGGING_CLASS, DRAGGING_HANDLER_CLASS, GRABBING_CLASS } from '../utils/classes';
|
2
|
+
import { toggleClass } from '../utils/dom/classList';
|
3
|
+
import { moveTranslate, setCustomFixedSize, setTranistion } from '../utils/SetStyles';
|
4
|
+
import { draggableTargetTimingFunction } from '../utils';
|
5
|
+
export const useChangeDraggableStyles = (currentConfig, handlerPublisher, endDraggingAction) => {
|
6
|
+
const { handlerSelector, animationDuration } = currentConfig;
|
7
|
+
const removeElementDraggingStyles = (element) => {
|
8
|
+
endDraggingAction();
|
9
|
+
toggleDraggingClass(element, false);
|
10
|
+
element.style.transform = '';
|
11
|
+
element.style.transition = '';
|
12
|
+
element.style.top = '';
|
13
|
+
element.style.left = '';
|
14
|
+
setCustomFixedSize(element, {
|
15
|
+
fixedHeight: '',
|
16
|
+
fixedWidth: ''
|
17
|
+
});
|
18
|
+
};
|
19
|
+
const toggleDraggingClass = (element, force) => {
|
20
|
+
toggleClass(element, DRAGGING_CLASS, force);
|
21
|
+
toogleHandlerDraggingClass(force, element);
|
22
|
+
handlerPublisher.toggleGrabClass(!force);
|
23
|
+
};
|
24
|
+
const toogleHandlerDraggingClass = (force, element) => {
|
25
|
+
const handlerElement = element.querySelector(handlerSelector);
|
26
|
+
toggleClass(document.body, GRABBING_CLASS, force);
|
27
|
+
if (handlerElement) {
|
28
|
+
toggleClass(handlerElement, DRAGGING_HANDLER_CLASS, force);
|
29
|
+
}
|
30
|
+
else {
|
31
|
+
toggleClass(element, DRAGGING_HANDLER_CLASS, force);
|
32
|
+
}
|
33
|
+
};
|
34
|
+
const dragEventOverElement = (element, translation) => {
|
35
|
+
const { width, height } = translation;
|
36
|
+
moveTranslate(element, height, width);
|
37
|
+
setTranistion(element, animationDuration, draggableTargetTimingFunction);
|
38
|
+
};
|
39
|
+
return [removeElementDraggingStyles, toggleDraggingClass, dragEventOverElement];
|
40
|
+
};
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { WindowScroll } from '../../../../index';
|
2
|
+
import { CoreConfig } from '../..';
|
3
|
+
import { DRAG_EVENT, START_DRAG_EVENT, START_DROP_EVENT } from '../../utils';
|
4
|
+
import { DroppableConfig } from '../../config/configHandler';
|
5
|
+
import HandlerPublisher from '../../HandlerPublisher';
|
6
|
+
type DraggingEvent = typeof DRAG_EVENT | typeof START_DRAG_EVENT;
|
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];
|
9
|
+
export {};
|
@@ -1,79 +1,33 @@
|
|
1
|
-
import { draggableIsOutside,
|
2
|
-
import { moveTranslate
|
3
|
-
import getTranslationByDragging from
|
4
|
-
import getTranslateBeforeDropping from
|
5
|
-
import { DRAG_EVENT,
|
6
|
-
import { IsHTMLElement } from
|
7
|
-
import {
|
8
|
-
import {
|
9
|
-
import { addClass, containClass, getClassesSelector, removeClass
|
10
|
-
import {
|
1
|
+
import { draggableIsOutside, getPropByDirection, getSiblings, getTransform, getWindowScroll } from '../../utils/GetStyles';
|
2
|
+
import { moveTranslate } from '../../utils/SetStyles';
|
3
|
+
import getTranslationByDragging from './getTranslationByDraggingAndEvent';
|
4
|
+
import getTranslateBeforeDropping from './getTranslateBeforeDropping';
|
5
|
+
import { DRAG_EVENT, START_DRAG_EVENT, START_DROP_EVENT, TEMP_CHILD_CLASS } from '../../utils';
|
6
|
+
import { IsHTMLElement } from '../../utils/typesCheckers';
|
7
|
+
import { removeTempChild } from '../../tempChildren';
|
8
|
+
import { DRAGGABLE_CLASS, DROPPING_CLASS } from '../../utils/classes';
|
9
|
+
import { addClass, containClass, getClassesSelector, removeClass } from '../../utils/dom/classList';
|
10
|
+
import { useChangeDraggableStyles } from '../changeDraggableStyles';
|
11
11
|
const DELAY_TIME_TO_SWAP = 50;
|
12
|
-
export default function
|
12
|
+
export default function useDragAndDropEvents(currentConfig, index, parent, droppableGroupClass, handlerPublisher, endDraggingAction) {
|
13
13
|
let actualIndex = index;
|
14
|
-
const { direction,
|
15
|
-
const
|
14
|
+
const { direction, onRemoveAtEvent, animationDuration, draggingClass } = currentConfig;
|
15
|
+
const [removeElementDraggingStyles, toggleDraggingClass, dragEventOverElement] = useChangeDraggableStyles(currentConfig, handlerPublisher, endDraggingAction);
|
16
|
+
const emitDraggingEvent = (draggedElement, event, droppableConfig) => {
|
16
17
|
if (!droppableConfig) {
|
17
18
|
return;
|
18
19
|
}
|
19
20
|
const { droppable, config } = droppableConfig;
|
20
21
|
const tranlation = getTranslationByDragging(draggedElement, event, config.direction, droppable);
|
21
|
-
|
22
|
-
if (!dropping) {
|
23
|
-
emitDraggingEventToSiblings(draggedElement, event, tranlation, droppableConfig);
|
24
|
-
}
|
25
|
-
else {
|
26
|
-
emitDroppingEventToSiblings(draggedElement, event, tranlation, initialWindowScroll, droppableConfig, positionOnSourceDroppable);
|
27
|
-
}
|
22
|
+
emitDraggingEventToSiblings(draggedElement, event, tranlation, droppableConfig);
|
28
23
|
};
|
29
|
-
|
30
|
-
|
31
|
-
const translation = getTranslationByDragging(draggedElement, 'insert', currentConfig.direction, droppable);
|
32
|
-
const { onInsertEvent } = currentConfig;
|
33
|
-
const siblings = getParentDraggableChildren(droppable);
|
34
|
-
for (const [index, sibling] of siblings.entries()) {
|
35
|
-
if (!containClass(sibling, DRAGGABLE_CLASS)) {
|
36
|
-
continue;
|
37
|
-
}
|
38
|
-
if (index >= targetIndex) {
|
39
|
-
dragEventOverElement(sibling, translation);
|
40
|
-
}
|
41
|
-
}
|
42
|
-
startInserting();
|
43
|
-
setTimeout(() => {
|
44
|
-
onInsertEvent(targetIndex, value);
|
45
|
-
onFinishInsertElement(targetIndex, droppable, currentConfig);
|
46
|
-
removeElementDraggingStyles(draggedElement);
|
47
|
-
removeTranslateFromSiblings(draggedElement, parent);
|
48
|
-
removeTempChild(parent, 0, true);
|
49
|
-
}, delayBeforeInsert);
|
50
|
-
};
|
51
|
-
// #region Remove
|
52
|
-
const emitRemoveEventToSiblings = (targetIndex, draggedElement, droppableConfig, onFinishRemoveEvent) => {
|
53
|
-
if (!droppableConfig ||
|
54
|
-
!droppableConfig.droppable ||
|
55
|
-
!droppableConfig.config) {
|
24
|
+
const emitDroppingEvent = (draggedElement, event, droppableConfig, initialWindowScroll, positionOnSourceDroppable) => {
|
25
|
+
if (!droppableConfig) {
|
56
26
|
return;
|
57
27
|
}
|
58
28
|
const { droppable, config } = droppableConfig;
|
59
|
-
|
60
|
-
|
61
|
-
const translation = getTranslationByDragging(draggedElement, "remove", config.direction, droppable);
|
62
|
-
for (const [index, sibling] of siblings.entries()) {
|
63
|
-
if (index >= targetIndex) {
|
64
|
-
startDragEventOverElement(sibling, translation);
|
65
|
-
setTimeout(() => {
|
66
|
-
onFinishRemoveEvent(sibling);
|
67
|
-
}, animationDuration);
|
68
|
-
}
|
69
|
-
}
|
70
|
-
};
|
71
|
-
const emitFinishRemoveEventToSiblings = (draggedElement) => {
|
72
|
-
removeTempChild(parent, animationDuration, true);
|
73
|
-
setTimeout(() => {
|
74
|
-
removeElementDraggingStyles(draggedElement);
|
75
|
-
removeTranslateFromSiblings(draggedElement, parent);
|
76
|
-
}, animationDuration);
|
29
|
+
const tranlation = getTranslationByDragging(draggedElement, event, config.direction, droppable);
|
30
|
+
emitDroppingEventToSiblings(draggedElement, event, tranlation, initialWindowScroll, droppableConfig, positionOnSourceDroppable);
|
77
31
|
};
|
78
32
|
// #region Drag events
|
79
33
|
const emitDraggingEventToSiblings = (draggedElement, event, translation, droppableConfig) => {
|
@@ -134,17 +88,12 @@ export default function useEmitEvents(currentConfig, index, parent, droppableGro
|
|
134
88
|
const { width, height } = translation;
|
135
89
|
moveTranslate(element, height, width);
|
136
90
|
};
|
137
|
-
const dragEventOverElement = (element, translation) => {
|
138
|
-
const { width, height } = translation;
|
139
|
-
moveTranslate(element, height, width);
|
140
|
-
setTranistion(element, animationDuration, draggableTargetTimingFunction);
|
141
|
-
};
|
142
91
|
// #region Drop events
|
143
92
|
const emitDroppingEventToSiblings = (draggedElement, event, translation, initialWindowScroll, droppableConfig, positionOnSourceDroppable) => {
|
144
93
|
const { droppable, scroll, config } = droppableConfig;
|
145
94
|
const [siblings, positionOnDroppable] = getSiblings(draggedElement, droppable);
|
146
95
|
const allSiblings = siblings.toReversed();
|
147
|
-
const realPositionOnDroppable =
|
96
|
+
const realPositionOnDroppable = positionOnDroppable === -1 ? allSiblings.length : positionOnDroppable;
|
148
97
|
allSiblings.splice(realPositionOnDroppable, 0, draggedElement);
|
149
98
|
const [previousElement, nextElement, targetIndex] = getPreviousAndNextElement(draggedElement, positionOnDroppable, allSiblings, droppable);
|
150
99
|
translation = getTranslationByDragging(draggedElement, event, config.direction, parent, previousElement, nextElement);
|
@@ -158,8 +107,7 @@ export default function useEmitEvents(currentConfig, index, parent, droppableGro
|
|
158
107
|
if (targetIndex - 1 >= index) {
|
159
108
|
newTranslation = { height: 0, width: 0 };
|
160
109
|
}
|
161
|
-
if (event === START_DROP_EVENT &&
|
162
|
-
!containClass(sibling, TEMP_CHILD_CLASS)) {
|
110
|
+
if (event === START_DROP_EVENT && !containClass(sibling, TEMP_CHILD_CLASS)) {
|
163
111
|
startDropEventOverElement(sibling, newTranslation, draggedElement, draggableTranslation);
|
164
112
|
}
|
165
113
|
}
|
@@ -182,11 +130,7 @@ export default function useEmitEvents(currentConfig, index, parent, droppableGro
|
|
182
130
|
const [previousIndex, nextIndex] = getPreviousAndNextElementIndex();
|
183
131
|
const previousElement = allSiblings[previousIndex] ?? null;
|
184
132
|
const nextElement = allSiblings[nextIndex] ?? null;
|
185
|
-
return [
|
186
|
-
previousElement,
|
187
|
-
nextElement,
|
188
|
-
targetIndex,
|
189
|
-
];
|
133
|
+
return [previousElement, nextElement, targetIndex];
|
190
134
|
};
|
191
135
|
const startDropEventOverElement = (targetElement, translation, element, sourceElementTranlation) => {
|
192
136
|
moveTranslate(targetElement, translation.height, translation.width);
|
@@ -251,7 +195,7 @@ export default function useEmitEvents(currentConfig, index, parent, droppableGro
|
|
251
195
|
}
|
252
196
|
const { distance } = getPropByDirection(direction);
|
253
197
|
if (IsHTMLElement(lastChildren)) {
|
254
|
-
lastChildren.style[distance] =
|
198
|
+
lastChildren.style[distance] = '0px';
|
255
199
|
}
|
256
200
|
};
|
257
201
|
const removeTranslateFromSiblings = (element, parent) => {
|
@@ -262,72 +206,9 @@ export default function useEmitEvents(currentConfig, index, parent, droppableGro
|
|
262
206
|
};
|
263
207
|
const removeTranslateWhitoutTransition = (element) => {
|
264
208
|
if (IsHTMLElement(element)) {
|
265
|
-
element.style.transition =
|
266
|
-
element.style.transform =
|
267
|
-
}
|
268
|
-
};
|
269
|
-
const removeElementDraggingStyles = (element) => {
|
270
|
-
endDraggingAction();
|
271
|
-
toggleDraggingClass(element, false);
|
272
|
-
element.style.transform = "";
|
273
|
-
element.style.transition = "";
|
274
|
-
element.style.top = "";
|
275
|
-
element.style.left = "";
|
276
|
-
setCustomFixedSize(element, {
|
277
|
-
fixedHeight: '',
|
278
|
-
fixedWidth: ''
|
279
|
-
});
|
280
|
-
};
|
281
|
-
const toogleHandlerDraggingClass = (force, element) => {
|
282
|
-
const handlerElement = element.querySelector(handlerSelector);
|
283
|
-
toggleClass(document.body, GRABBING_CLASS, force);
|
284
|
-
if (handlerElement) {
|
285
|
-
toggleClass(handlerElement, DRAGGING_HANDLER_CLASS, force);
|
286
|
-
}
|
287
|
-
else {
|
288
|
-
toggleClass(element, DRAGGING_HANDLER_CLASS, force);
|
209
|
+
element.style.transition = '';
|
210
|
+
element.style.transform = '';
|
289
211
|
}
|
290
212
|
};
|
291
|
-
|
292
|
-
toggleClass(element, DRAGGING_CLASS, force);
|
293
|
-
toogleHandlerDraggingClass(force, element);
|
294
|
-
handlerPublisher.toggleGrabClass(!force);
|
295
|
-
};
|
296
|
-
return [
|
297
|
-
emitEventToSiblings,
|
298
|
-
emitRemoveEventToSiblings,
|
299
|
-
emitInsertEventToSiblings,
|
300
|
-
emitFinishRemoveEventToSiblings,
|
301
|
-
toggleDraggingClass,
|
302
|
-
];
|
213
|
+
return [emitDraggingEvent, emitDroppingEvent, toggleDraggingClass];
|
303
214
|
}
|
304
|
-
const childrenMutationFilter = (mutation) => {
|
305
|
-
const addedNodes = mutation.addedNodes.values().filter((element) => !isTempElement(element)).toArray();
|
306
|
-
return addedNodes.length > 0;
|
307
|
-
};
|
308
|
-
const onFinishInsertElement = (targetIndex, droppable, config) => {
|
309
|
-
const { insertingFromClass, animationDuration } = config;
|
310
|
-
const observer = observeMutation(() => {
|
311
|
-
const siblings = getParentDraggableChildren(droppable);
|
312
|
-
const newElement = siblings[targetIndex];
|
313
|
-
addClass(newElement, insertingFromClass);
|
314
|
-
addClass(newElement, DISABLE_TRANSITION);
|
315
|
-
setTimeout(() => {
|
316
|
-
removeClass(newElement, DISABLE_TRANSITION);
|
317
|
-
removeClass(newElement, insertingFromClass);
|
318
|
-
observer.disconnect();
|
319
|
-
}, animationDuration);
|
320
|
-
}, droppable, {
|
321
|
-
childList: true,
|
322
|
-
}, childrenMutationFilter);
|
323
|
-
};
|
324
|
-
export const insertToListEmpty = (config, droppable, targetIndex, value) => {
|
325
|
-
if (!droppable) {
|
326
|
-
return;
|
327
|
-
}
|
328
|
-
const { onInsertEvent, delayBeforeInsert } = config;
|
329
|
-
setTimeout(() => {
|
330
|
-
onInsertEvent(targetIndex, value);
|
331
|
-
onFinishInsertElement(targetIndex, droppable, config);
|
332
|
-
}, delayBeforeInsert);
|
333
|
-
};
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { Direction } from
|
2
|
-
import { Translate, WindowScroll } from
|
1
|
+
import { Direction } from '../..';
|
2
|
+
import { Translate, WindowScroll } from '../../../../index';
|
3
3
|
export default function getTranslateBeforeDropping(direction: Direction, siblings: Element[], sourceIndex: number, targetIndex: number, scroll: WindowScroll, previousScroll: {
|
4
4
|
scrollLeft: number;
|
5
5
|
scrollTop: number;
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { HORIZONTAL, VERTICAL } from
|
2
|
-
import { getPropByDirection, getValueFromProperty
|
3
|
-
import { gapAndDisplayInformation, getBeforeStyles } from
|
1
|
+
import { HORIZONTAL, VERTICAL } from '../..';
|
2
|
+
import { getPropByDirection, getValueFromProperty } from '../../utils/GetStyles';
|
3
|
+
import { gapAndDisplayInformation, getBeforeStyles } from '../../utils/ParseStyles';
|
4
4
|
const getContentPosition = (direction, droppable) => {
|
5
5
|
const { borderBeforeWidth, paddingBefore, axis, getRect } = getPropByDirection(direction);
|
6
6
|
const borderBeforeWidthDroppable = getValueFromProperty(droppable, borderBeforeWidth);
|
@@ -12,10 +12,7 @@ const getGroupTranslate = (droppable, draggable) => {
|
|
12
12
|
const [top, left] = getBeforeStyles(draggable);
|
13
13
|
const verticalContentPosition = getContentPosition(VERTICAL, droppable);
|
14
14
|
const horizontalContentPosition = getContentPosition(HORIZONTAL, droppable);
|
15
|
-
return [
|
16
|
-
horizontalContentPosition - left,
|
17
|
-
verticalContentPosition - top
|
18
|
-
];
|
15
|
+
return [horizontalContentPosition - left, verticalContentPosition - top];
|
19
16
|
};
|
20
17
|
export default function getTranslateBeforeDropping(direction, siblings, sourceIndex, targetIndex, scroll, previousScroll, initialWindowScroll, droppable, draggable) {
|
21
18
|
let height = 0;
|
@@ -30,9 +27,9 @@ export default function getTranslateBeforeDropping(direction, siblings, sourceIn
|
|
30
27
|
height += y;
|
31
28
|
width += x;
|
32
29
|
}
|
33
|
-
const { scrollElement, beforeMargin: beforeMarginProp, afterMargin: afterMarginProp, distance: spaceProp, gap: gapStyle
|
30
|
+
const { scrollElement, beforeMargin: beforeMarginProp, afterMargin: afterMarginProp, distance: spaceProp, gap: gapStyle } = getPropByDirection(direction);
|
34
31
|
const [gap, hasGaps] = gapAndDisplayInformation(droppable, gapStyle);
|
35
|
-
const [afterMarginOutside, beforeMarginOutside, spaceBeforeDraggedElement
|
32
|
+
const [afterMarginOutside, beforeMarginOutside, spaceBeforeDraggedElement] = getBeforeAfterMarginBaseOnDraggedDirection(beforeMarginProp, afterMarginProp, sourceElement, targetElement?.previousElementSibling, isDraggedFoward, hasGaps, isGroupDropping);
|
36
33
|
const [beforeSpace, space, afterSpace] = spaceWithMargins(beforeMarginProp, afterMarginProp, spaceProp, siblingsBetween, gap, hasGaps);
|
37
34
|
const spaceBetween = getSpaceBetween(space, beforeSpace, afterSpace, beforeMarginOutside, afterMarginOutside, gap);
|
38
35
|
const scrollChange = isGroupDropping
|
@@ -71,12 +68,7 @@ const getElementsRange = (siblings, sourceIndex, targetIndex, draggable) => {
|
|
71
68
|
if (firstIndex < 0 && draggable) {
|
72
69
|
siblingsBetween = siblings.slice(firstIndex + 1, secondIndex);
|
73
70
|
}
|
74
|
-
return [
|
75
|
-
sourceElement,
|
76
|
-
targetElement,
|
77
|
-
siblingsBetween,
|
78
|
-
isDraggedFoward,
|
79
|
-
];
|
71
|
+
return [sourceElement, targetElement, siblingsBetween, isDraggedFoward];
|
80
72
|
};
|
81
73
|
const spaceWithMargins = (beforeMargin, afterMargin, distance, siblings, gap, hasGaps) => {
|
82
74
|
if (siblings.length == 0) {
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { Direction } from
|
2
|
-
import { DragAndDropEvent } from
|
1
|
+
import { Direction } from '../..';
|
2
|
+
import { DragAndDropEvent } from '../../utils';
|
3
3
|
export default function getTranslationByDraggingAndEvent(current: HTMLElement, event: DragAndDropEvent, direction: Direction, droppable: HTMLElement, previousElement?: Element | null, nextElement?: Element | null): {
|
4
4
|
height: number;
|
5
5
|
width: number;
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import { HORIZONTAL } from
|
2
|
-
import { DRAG_EVENT } from
|
3
|
-
import { draggableIsOutside, getPropByDirection, getValueFromProperty
|
4
|
-
import { gapAndDisplayInformation } from
|
1
|
+
import { HORIZONTAL } from '../..';
|
2
|
+
import { DRAG_EVENT } from '../../utils';
|
3
|
+
import { draggableIsOutside, getPropByDirection, getValueFromProperty } from '../../utils/GetStyles';
|
4
|
+
import { gapAndDisplayInformation } 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);
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { CoreConfig } from '../index';
|
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];
|
4
|
+
export declare const insertToListEmpty: <T>(config: CoreConfig<T>, droppable: HTMLElement | undefined | null, targetIndex: number, value: T) => void;
|