Skip to content

Commit 673e7c3

Browse files
committed
refactor: rename onDrop to onExternalDrop
1 parent b32d1b0 commit 673e7c3

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

lib/HeTree.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ export interface HeTreeProps<T extends Record<string, any>> extends Partial<type
6666
onDragStart?: (e: React.DragEvent<HTMLElement>, stat: Stat<T>) => void,
6767
onDragOver?: (e: React.DragEvent<HTMLElement>, stat: Stat<T>, isExternal: boolean) => void,
6868
onExternalDragOver?: (e: React.DragEvent<HTMLElement>) => boolean,
69-
onDrop?: (e: React.DragEvent<HTMLElement>, parentStat: Stat<T> | null, index: number, isExternal: boolean) => void,
69+
onExternalDrop?: (e: React.DragEvent<HTMLElement>, parentStat: Stat<T> | null, index: number, isExternal: boolean) => void,
7070
/**
71-
* Call on drag end in the window. If you use draggedStat in the callback, it will be undefined if onDrop alreay triggered.
71+
* Call on drag end in the window. If you use draggedStat in the callback, it will be undefined if onExternalDrop alreay triggered.
7272
*/
7373
onDragEnd?: (e: React.DragEvent<HTMLElement>, stat: Stat<T>, isOutside: boolean) => void | boolean,
7474
onChange: (data: T[]) => void,
@@ -478,7 +478,7 @@ export function useHeTree<T extends Record<string, any>>(
478478
return r
479479
}
480480
}
481-
const onDropToRoot: React.DragEventHandler<HTMLElement> = (e) => {
481+
const onExternalDropToRoot: React.DragEventHandler<HTMLElement> = (e) => {
482482
if (isExternal && !props.onExternalDragOver?.(e)) {
483483
return
484484
}
@@ -487,7 +487,7 @@ export function useHeTree<T extends Record<string, any>>(
487487
e.preventDefault();
488488
if (isExternal) {
489489
const { index: targetIndexInSiblings } = placeholder
490-
props.onDrop?.(e, placeholder.parentStat, targetIndexInSiblings, isExternal)
490+
props.onExternalDrop?.(e, placeholder.parentStat, targetIndexInSiblings, isExternal)
491491
}
492492
}
493493
}
@@ -598,14 +598,14 @@ export function useHeTree<T extends Record<string, any>>(
598598
}
599599
return index
600600
}
601-
return { visibleIds, attrsList, onDragOverRoot, onDropToRoot, onDragEndOnRoot }
601+
return { visibleIds, attrsList, onDragOverRoot, onExternalDropToRoot, onDragEndOnRoot }
602602
}, [mainCache, indent, draggedStat,
603603
// watch placeholder position
604604
placeholder?.parentStat, placeholder?.index,
605605
// watch props
606606
indent, placeholderId, rtl, props.rootId,
607607
// watch func
608-
...([props.canDrop, props.canDropToRoot, props.customDragImage, props.onDragStart, props.onDragOver, props.onExternalDragOver, props.onDrop, props.onDragEnd, props.onChange, props.onDragOpen].map(func => isFunctionReactive && func)),
608+
...([props.canDrop, props.canDropToRoot, props.customDragImage, props.onDragStart, props.onDragOver, props.onExternalDragOver, props.onExternalDrop, props.onDragEnd, props.onChange, props.onDragOpen].map(func => isFunctionReactive && func)),
609609
])
610610
// listen dragover on window
611611
const t2 = useMemo(() => {
@@ -636,7 +636,7 @@ export function useHeTree<T extends Record<string, any>>(
636636
}, [props.keepPlaceholder])
637637
useAddEventListener(t2.getEl, 'dragover', t2.onDragOverWindow)
638638
//
639-
const { visibleIds, attrsList, onDragOverRoot, onDropToRoot, onDragEndOnRoot } = cacheForVisible
639+
const { visibleIds, attrsList, onDragOverRoot, onExternalDropToRoot, onDragEndOnRoot } = cacheForVisible
640640
const persistentIndices = useMemo(() => draggedStat ? [visibleIds.indexOf(draggedStat.id)] : [], [draggedStat, visibleIds]);
641641
// render
642642
const renderHeTree = (options?: { className?: string, style?: React.CSSProperties }) => {
@@ -648,7 +648,7 @@ export function useHeTree<T extends Record<string, any>>(
648648
</div>
649649
}
650650
return (
651-
<div className={`he-tree ${options?.className || ''}`} style={options?.style} ref={rootRef} onDragOver={onDragOverRoot} onDrop={onDropToRoot} onDragEnd={onDragEndOnRoot}>
651+
<div className={`he-tree ${options?.className || ''}`} style={options?.style} ref={rootRef} onDragOver={onDragOverRoot} onExternalDrop={onExternalDropToRoot} onDragEnd={onDragEndOnRoot}>
652652
<VirtualList<Id> ref={virtualListRef} items={visibleIds} virtual={props.virtual} persistentIndices={persistentIndices} style={{ height: '100%' }}
653653
renderItem={(id, index) => renderNodeBox({
654654
stat: getStat(id)!, attrs: attrsList[index], isPlaceholder: id === placeholderId

src/pages/external_drag.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function BasePage() {
1414
{node.name} - {id}
1515
</div>,
1616
onExternalDragOver: (e) => true,
17-
onDrop: (e, parentStat, index) => {
17+
onExternalDrop: (e, parentStat, index) => {
1818
setdata(draft => {
1919
const newNode = { id: 100 + data.length, parent_id: parentStat?.id ?? null, name: "New Node" }
2020
addToFlatData(draft, newNode, index, keys)

src/test/__snapshots__/useHeTree_flatData.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ exports[`render tree 1`] = `
55
className="he-tree"
66
onDragEnd={[Function]}
77
onDragOver={[Function]}
8-
onDrop={[Function]}
8+
onExternalDrop={[Function]}
99
>
1010
<div
1111
onScroll={[Function]}

src/test/__snapshots__/useHeTree_treeData.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ exports[`render tree 1`] = `
55
className="he-tree"
66
onDragEnd={[Function]}
77
onDragOver={[Function]}
8-
onDrop={[Function]}
8+
onExternalDrop={[Function]}
99
>
1010
<div
1111
onScroll={[Function]}

0 commit comments

Comments
 (0)