55 type SomeEntityModel ,
66} from '@companion-app/shared/Model/EntityModel.js'
77import { observer } from 'mobx-react-lite'
8- import React , { useContext , useState , useCallback , useRef } from 'react'
8+ import React , { useContext , useState , useCallback , useRef , useEffect } from 'react'
99import { usePanelCollapseHelperContextForPanel } from '~/Helpers/CollapseHelper.js'
1010import { useControlEntityService } from '~/Services/Controls/ControlEntitiesService.js'
1111import { RootAppStoreContext } from '~/Stores/RootAppStore.js'
@@ -15,7 +15,8 @@ import { EntityManageChildGroups } from './EntityChildGroup.js'
1515import { EntityCommonCells } from './EntityCommonCells.js'
1616import { faSort } from '@fortawesome/free-solid-svg-icons'
1717import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
18- import { useDrop , useDrag } from 'react-dnd'
18+ import { useDrop , useDrag , useDragLayer } from 'react-dnd'
19+ import { getEmptyImage } from 'react-dnd-html5-backend'
1920import { checkDragStateWithThresholds , DragPlacement } from '~/Resources/DragAndDrop.js'
2021import type { EntityListDragItem } from './EntityListDropZone.js'
2122import type { ClientEntityDefinition } from '@companion-app/shared/Model/EntityDefinitionModel.js'
@@ -101,31 +102,79 @@ export const EntityTableRow = observer(function EntityTableRow({
101102 item . dragState = null
102103 } ,
103104 } )
104- const [ { isDragging } , drag , preview ] = useDrag < EntityListDragItem , unknown , EntityTableRowDragStatus > ( {
105+
106+ const [ _c , drag , preview ] = useDrag < EntityListDragItem , unknown , EntityTableRowDragStatus > ( {
105107 type : dragId ,
106108 canDrag : ! readonly ,
107- item : {
109+ item : ( ) => ( {
108110 entityId : entity . id ,
109111 listId : serviceFactory . listId ,
110112 index : index ,
111113 ownerId : ownerId ,
112- // ref: ref,
113114 dragState : null ,
114- } ,
115- collect : ( monitor ) => ( {
116- isDragging : monitor . isDragging ( ) ,
115+ elementWidth : ref . current ?. offsetWidth ,
117116 } ) ,
118117 } )
119- preview ( drop ( ref ) )
118+
119+ // Check if the current item is being dragged
120+ const { draggingItem } = useDragLayer ( ( monitor ) => ( {
121+ draggingItem : monitor . getItem < EntityListDragItem > ( ) ,
122+ } ) )
123+ const isDragging = draggingItem ?. entityId === entity . id
124+
125+ // Hide default browser preview
126+ useEffect ( ( ) => {
127+ preview ( getEmptyImage ( ) )
128+ } , [ preview ] )
129+
130+ // Connect drag and drop
131+ drop ( ref )
120132
121133 if ( ! entity ) {
122134 // Invalid entity, so skip
123135 return null
124136 }
125137
126138 return (
127- < tr ref = { ref } className = { isDragging ? 'entitylist-dragging' : '' } >
128- < td ref = { drag } className = "td-reorder" >
139+ < EntityTableRowContent
140+ entity = { entity }
141+ ownerId = { ownerId }
142+ entityType = { entityType }
143+ entityTypeLabel = { entityTypeLabel }
144+ feedbackListType = { feedbackListType }
145+ isDragging = { isDragging }
146+ rowRef = { ref }
147+ dragRef = { drag }
148+ />
149+ )
150+ } )
151+
152+ interface EntityTableRowContentProps {
153+ entity : SomeEntityModel
154+ ownerId : EntityOwner | null
155+
156+ entityType : EntityModelType
157+ entityTypeLabel : string
158+ feedbackListType : ClientEntityDefinition [ 'feedbackType' ]
159+
160+ isDragging : boolean
161+ rowRef : React . LegacyRef < HTMLTableRowElement > | null
162+ dragRef : React . LegacyRef < HTMLTableCellElement > | null
163+ }
164+
165+ export const EntityTableRowContent = observer ( function EntityTableRowContent ( {
166+ entity,
167+ ownerId,
168+ entityType,
169+ entityTypeLabel,
170+ feedbackListType,
171+ isDragging,
172+ rowRef,
173+ dragRef,
174+ } : EntityTableRowContentProps ) : React . JSX . Element {
175+ return (
176+ < tr ref = { rowRef } className = { isDragging ? 'entitylist-dragging' : '' } >
177+ < td ref = { dragRef } className = "td-reorder" >
129178 < FontAwesomeIcon icon = { faSort } />
130179 </ td >
131180 < td >
@@ -151,7 +200,7 @@ interface EntityEditorRowContentProps {
151200 feedbackListType : ClientEntityDefinition [ 'feedbackType' ]
152201}
153202
154- export const EntityEditorRowContent = observer ( function EntityEditorRowContent ( {
203+ const EntityEditorRowContent = observer ( function EntityEditorRowContent ( {
155204 ownerId,
156205 entityTypeLabel,
157206 entity,
0 commit comments