From ec8f9ce5e8e0ba1131a01ad96c5f6893b82f4a3e Mon Sep 17 00:00:00 2001 From: Martin Wendt Date: Tue, 16 Jan 2024 22:52:41 +0100 Subject: [PATCH] Fix typing of `tree.options.dnd.dropEffect` and others Close #73 --- CHANGELOG.md | 2 ++ src/types.ts | 32 +++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd88210d..ba6c6841 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,9 @@ First release. - v0.8.1: Fix #76: Lazyload could be called for the same node multiple times - v0.8.1: Fix #75: After reloading nodes with "resetLazy", wunderbaum is broken +- v0.8.1: Fix #73: Fix typing of `tree.options.dnd.dropEffect` and others - v0.8.1: Fix #72: DragEnter event does not provide the source node, only the target +- Thanks to @jogibear9988 for the testing and opening #72, #73, #75, #76 - v0.8.0: Add `expand(e)` and `beforeExpand(e)` events. - v0.8.0: Add `tree.findByRefKey()`, `node.getCloneList()`, and `node.isClone()`. diff --git a/src/types.ts b/src/types.ts index 79e545f4..7633699c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -873,6 +873,22 @@ export type DropRegionTypeSet = Set; // | "none" // == false == "" == null // | "over"; // == "child" +export interface DragEventType extends WbNodeEventType { + /** The original event. */ + event: DragEvent; + /** The source node. */ + node: WunderbaumNode; +} + +export interface DropEventType extends WbNodeEventType { + /** The original event. */ + event: DragEvent; + /** The target node. */ + node: WunderbaumNode; + /** The source node if any. */ + sourceNode: WunderbaumNode; +} + export type DndOptionsType = { /** * Expand nodes after n milliseconds of hovering @@ -995,19 +1011,19 @@ export type DndOptionsType = { * @default null * @category Callback */ - dragStart?: null | ((e: WbNodeEventType & { event: DragEvent }) => boolean); + dragStart?: null | ((e: DragEventType) => boolean); /** * Callback(sourceNode, data) * @default null * @category Callback */ - drag?: null | ((e: WbNodeEventType & { event: DragEvent }) => void); + drag?: null | ((e: DragEventType) => void); /** * Callback(sourceNode, data) * @default null * @category Callback */ - dragEnd?: null | ((e: WbNodeEventType & { event: DragEvent }) => void); + dragEnd?: null | ((e: DragEventType) => void); // Events (drop support) /** * Callback(targetNode, data), return true, to enable dnd drop @@ -1016,21 +1032,19 @@ export type DndOptionsType = { */ dragEnter?: | null - | (( - e: WbNodeEventType & { event: DragEvent } - ) => DropRegionTypeSet | boolean); + | ((e: DropEventType) => DropRegionType | DropRegionTypeSet | boolean); /** * Callback(targetNode, data) * @default null * @category Callback */ - dragOver?: null | ((e: WbNodeEventType & { event: DragEvent }) => void); + dragOver?: null | ((e: DropEventType) => void); /** * Callback(targetNode, data), return false to prevent autoExpand * @default null * @category Callback */ - dragExpand?: null | ((e: WbNodeEventType & { event: DragEvent }) => boolean); + dragExpand?: null | ((e: DropEventType) => boolean); /** * Callback(targetNode, data) * @default null @@ -1053,7 +1067,7 @@ export type DndOptionsType = { * @default null * @category Callback */ - dragLeave?: null; + dragLeave?: null | ((e: DropEventType) => void); }; /* -----------------------------------------------------------------------------