@@ -13,6 +13,7 @@ import {
1313import { type TranslateFunction } from './localisation'
1414
1515interface DnDProps {
16+ canDrag : boolean
1617 canDragOnto : boolean
1718 path : CollectionKey [ ]
1819 nodeData : NodeData
@@ -22,6 +23,7 @@ interface DnDProps {
2223}
2324
2425export const useDragNDrop = ( {
26+ canDrag,
2527 canDragOnto,
2628 path,
2729 nodeData,
@@ -30,14 +32,15 @@ export const useDragNDrop = ({
3032 translate,
3133} : DnDProps ) => {
3234 const { getStyles } = useTheme ( )
33- const { dragSource, setDragSource } = useTreeState ( )
35+ const { currentlyEditingElement , dragSource, setDragSource } = useTreeState ( )
3436 const [ isDragTarget , setIsDragTarget ] = useState < Position | false > ( false )
3537
3638 const pathString = toPathString ( path )
3739
3840 // Props added to items being dragged
39- const dragSourceProps = useMemo (
40- ( ) => ( {
41+ const dragSourceProps = useMemo ( ( ) => {
42+ if ( ! canDrag ) return { }
43+ return {
4144 onDragStart : ( e : React . DragEvent ) => {
4245 e . stopPropagation ( )
4346 setDragSource ( { path, pathString } )
@@ -46,57 +49,59 @@ export const useDragNDrop = ({
4649 e . stopPropagation ( )
4750 setDragSource ( { path : null , pathString : null } )
4851 } ,
49- } ) ,
50- [ ]
51- )
52+ }
53+ } , [ canDrag ] )
5254
5355 // Props for the items being dropped onto
5456 const getDropTargetProps = useMemo (
55- ( ) => ( position : Position ) => ( {
56- onDragOver : ( e : React . DragEvent ) => {
57- e . stopPropagation ( )
58- e . preventDefault ( )
59- } ,
60- onDrop : ( e : React . DragEvent ) => {
61- e . stopPropagation ( )
62- if ( ! canDragOnto ) return
63- handleDrop ( position )
64- setDragSource ( { path : null , pathString : null } )
65- setIsDragTarget ( false )
66- } ,
67- onDragEnter : ( e : React . DragEvent ) => {
68- e . stopPropagation ( )
69- if ( ! canDragOnto ) return
70- if ( ! pathString . startsWith ( dragSource . pathString ?? '' ) ) {
71- setIsDragTarget ( position )
72- }
73- } ,
74- onDragExit : ( e : React . DragEvent ) => {
75- e . stopPropagation ( )
76- if ( ! canDragOnto ) return
77- setIsDragTarget ( false )
78- } ,
79- } ) ,
80- [ dragSource ]
57+ ( ) => ( position : Position ) => {
58+ if ( ! canDragOnto ) return { }
59+ return {
60+ onDragOver : ( e : React . DragEvent ) => {
61+ e . stopPropagation ( )
62+ e . preventDefault ( )
63+ } ,
64+ onDrop : ( e : React . DragEvent ) => {
65+ e . stopPropagation ( )
66+ handleDrop ( position )
67+ setDragSource ( { path : null , pathString : null } )
68+ setIsDragTarget ( false )
69+ } ,
70+ onDragEnter : ( e : React . DragEvent ) => {
71+ e . stopPropagation ( )
72+ if ( ! pathString . startsWith ( dragSource . pathString ?? '' ) ) {
73+ setIsDragTarget ( position )
74+ }
75+ } ,
76+ onDragExit : ( e : React . DragEvent ) => {
77+ e . stopPropagation ( )
78+ setIsDragTarget ( false )
79+ } ,
80+ }
81+ } ,
82+ [ dragSource , canDragOnto ]
8183 )
8284
8385 // A dummy component to allow us to detect when dragging onto the *bottom*
8486 // half of an element -- takes up exactly 50% its container height and is
8587 // locked to the bottom.
8688 const BottomDropTarget = useMemo (
87- ( ) => (
88- < div
89- style = { {
90- height : '50%' ,
91- position : 'absolute' ,
92- width : '100%' ,
93- top : '50%' ,
94- zIndex : path . length ,
95- } }
96- { ...getDropTargetProps ( 'below' ) }
97- > </ div >
98- ) ,
99- [ dragSource ]
89+ ( ) =>
90+ canDragOnto && dragSource . pathString !== null ? (
91+ < div
92+ className = "jer-drop-target-bottom"
93+ style = { {
94+ height : '50%' ,
95+ position : 'absolute' ,
96+ width : '100%' ,
97+ top : '50%' ,
98+ zIndex : path . length ,
99+ // border: '1px dotted green',
100+ } }
101+ { ...getDropTargetProps ( 'below' ) }
102+ > </ div >
103+ ) : null ,
104+ [ dragSource , canDragOnto ]
100105 )
101106
102107 // "Padding" element displayed either above or below a node to indicate
0 commit comments