-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
removes all dropzone typings from main index types and moves them exc…
…lusively to dropzone plugin.
- Loading branch information
1 parent
03ac66f
commit d89e3f5
Showing
6 changed files
with
166 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,30 @@ | ||
import type { DropZoneConfig, DNDGlobals } from "../../types"; | ||
import type { ParentRecord } from "../../types"; | ||
|
||
export interface InitDropZone { | ||
dropZone: HTMLElement; | ||
parent: HTMLElement; | ||
globals: DNDGlobals; | ||
config?: Partial<DropZoneConfig>; | ||
export type DropZoneEventToHandler = Array< | ||
[keyof HTMLElementEventMap, DropZoneEvent] | ||
>; | ||
|
||
export type DropZoneEvent = (data: DropZoneEventData) => void; | ||
|
||
export interface DropZoneEventData { | ||
e: Event; | ||
targetData: DropZoneTargetData; | ||
} | ||
|
||
export interface DropZoneTargetData { | ||
parent: ParentRecord; | ||
dropZone?: DropZoneRecord; | ||
} | ||
|
||
export interface DropZoneRecord { | ||
el: HTMLElement; | ||
config: DropZoneConfig; | ||
} | ||
|
||
export interface DropZoneConfig { | ||
group?: string; | ||
parentDropZone?: HTMLElement | boolean; | ||
name?: string; | ||
accepts?: (any: any) => boolean; | ||
disabled?: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import type { DropZoneEventToHandler, DropZoneEventData } from "./types"; | ||
|
||
import { dropZones } from "./index"; | ||
|
||
import { parents } from "../../index"; | ||
|
||
export function addDropZoneEvents( | ||
dropZone: HTMLElement, | ||
events: DropZoneEventToHandler, | ||
abortControllerKey: string | ||
): void { | ||
const dropZoneData = dropZones.get(dropZone); | ||
|
||
console.log("dropZoneData", dropZoneData); | ||
|
||
if (!dropZoneData) return; | ||
|
||
const abortController = new AbortController(); | ||
|
||
function handleEvent(e: Event, cb: (eventData: DropZoneEventData) => void) { | ||
const eventData = dzEventData(e); | ||
|
||
if (eventData) cb(eventData); | ||
} | ||
|
||
for (const event of events) { | ||
dropZone.addEventListener(event[0], (e) => handleEvent(e, event[1]), { | ||
signal: abortController.signal, | ||
}); | ||
} | ||
|
||
dropZoneData.abortControllers[abortControllerKey] = abortController; | ||
} | ||
|
||
/** | ||
* Event listener used for all parents and dropzones. | ||
*/ | ||
export function dzEventData(e: Event): DropZoneEventData | undefined { | ||
if (!(e.currentTarget instanceof HTMLElement)) return; | ||
|
||
const parentData = parents.get(e.currentTarget); | ||
|
||
if (parentData) { | ||
return { | ||
e, | ||
targetData: { | ||
parent: { | ||
el: e.currentTarget, | ||
data: parentData, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
const dzData = dropZones.get(e.currentTarget); | ||
|
||
if (dzData) { | ||
const parentData = dzData.parent && parents.get(dzData.parent); | ||
|
||
if (!parentData) return; | ||
|
||
return { | ||
e, | ||
|
||
targetData: { | ||
parent: { | ||
el: dzData.parent, | ||
data: parentData, | ||
}, | ||
|
||
dropZone: { | ||
el: e.currentTarget, | ||
config: dzData.config, | ||
}, | ||
}, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.