Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/insertion plugin #81

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export { animations } from "./plugins/animations";
export { selections } from "./plugins/multiDrag/plugins/selections";
export { swap } from "./plugins/swap";
export { place } from "./plugins/place";
export { insertion } from "./plugins/insertion";
export * from "./utils";

const scrollConfig: {
Expand Down Expand Up @@ -454,6 +455,10 @@ export function remapNodes<T>(parent: HTMLElement, force?: boolean) {
parents.set(parent, { ...parentData, enabledNodes: enabledNodeRecords });

config.remapFinished(parentData);

parentData.config.plugins?.forEach((plugin: DNDPlugin) => {
plugin(parent)?.remapFinished?.();
});
}

export function remapFinished() {
Expand All @@ -476,13 +481,16 @@ export function handleDragstart<T>(data: NodeEventData<T>) {
export function dragstartClasses(
el: HTMLElement | Node | Element,
draggingClass: string | undefined,
dropZoneClass: string | undefined
dropZoneClass: string | undefined,
dragPlaceholderClass: string | undefined
) {
addClass([el], draggingClass);

setTimeout(() => {
removeClass([el], draggingClass);

addClass([el], dragPlaceholderClass);

addClass([el], dropZoneClass);
});
}
Expand All @@ -507,7 +515,7 @@ export function initDrag<T>(eventData: NodeDragEventData<T>): DragState<T> {
return dragState;
}

function validateDragHandle<T>(data: NodeEventData<T>): boolean {
export function validateDragHandle<T>(data: NodeEventData<T>): boolean {
if (!(data.e instanceof DragEvent) && !(data.e instanceof TouchEvent))
return false;

Expand Down Expand Up @@ -567,7 +575,8 @@ export function dragstart<T>(data: NodeDragEventData<T>) {
dragstartClasses(
dragState.draggedNode.el,
config.draggingClass,
config.dropZoneClass
config.dropZoneClass,
config.dragPlaceholderClass
);
}

Expand Down Expand Up @@ -988,7 +997,7 @@ function touchmove<T>(data: NodeTouchEventData<T>, touchState: TouchState<T>) {
}
}

function handleScroll() {
export function handleScroll() {
for (const direction of Object.keys(scrollConfig)) {
const [x, y] = scrollConfig[direction];

Expand Down
Loading
Loading