Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify plugin drop support #1723

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions v3/src/components/web-view/web-view-drop-overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@
const mouseX = useRef<number|undefined>()
const mouseY = useRef<number|undefined>()

const sendNotification = (notification: INotification) => {
const { message, callback } = notification
tile?.content.broadcastMessage(message, callback ?? (() => null))
}

// Broadcast dragstart and dragend notifications
const handleDragStartEnd = (
notification: (dataSet: IDataSet, attributeId: string) => INotification, _active: Active
) => {
const _info = getDragAttributeInfo(_active)
if (_info?.dataSet && _info.attributeId) {
tile?.applyModelChange(() => {}, {
notify: notification(_info.dataSet, _info.attributeId),
notifyTileId: tileId
})
sendNotification(
notification(_info.dataSet, _info.attributeId)
)
}
}

Expand All @@ -45,10 +49,9 @@
useDropHandler(dropId, (_active: Active) => {
const { dataSet: dropDataSet, attributeId: dropAttributeId } = getDragAttributeInfo(_active) || {}
if (dropDataSet && dropAttributeId && mouseX.current != null && mouseY.current != null) {
tile?.applyModelChange(() => {}, {
notify: dragWithPositionNotification("drop", dropDataSet, dropAttributeId, mouseX.current, mouseY.current),
notifyTileId: tileId
})
sendNotification(

Check warning on line 52 in v3/src/components/web-view/web-view-drop-overlay.tsx

View check run for this annotation

Codecov / codecov/patch

v3/src/components/web-view/web-view-drop-overlay.tsx#L52

Added line #L52 was not covered by tests
dragWithPositionNotification("drop", dropDataSet, dropAttributeId, mouseX.current, mouseY.current)
)
}
})

Expand All @@ -62,21 +65,19 @@
const y = event.clientY - top

if (mouseX.current !== x || mouseY.current !== y) {
tile?.applyModelChange(() => {}, {
notify: dragWithPositionNotification("drag", dataSet, attributeId, x, y),
notifyTileId: tileId
})
sendNotification(

Check warning on line 68 in v3/src/components/web-view/web-view-drop-overlay.tsx

View check run for this annotation

Codecov / codecov/patch

v3/src/components/web-view/web-view-drop-overlay.tsx#L68

Added line #L68 was not covered by tests
dragWithPositionNotification("drag", dataSet, attributeId, x, y)
)
mouseX.current = x
mouseY.current = y
}
}

// Broadcast dragenter and dragleave notifications
const handlePointerEnterLeave = (operation: string) => {
tile?.applyModelChange(() => {}, {
notify: dragNotification(operation, dataSet, attributeId),
notifyTileId: tileId
})
sendNotification(

Check warning on line 78 in v3/src/components/web-view/web-view-drop-overlay.tsx

View check run for this annotation

Codecov / codecov/patch

v3/src/components/web-view/web-view-drop-overlay.tsx#L78

Added line #L78 was not covered by tests
dragNotification(operation, dataSet, attributeId)
)
}

const setRef = (ref: HTMLDivElement) => {
Expand Down
Loading