1
0
Fork 0
mirror of synced 2024-09-10 22:46:09 +12:00

Handle context menu events in header cells

This commit is contained in:
Andrew Kingston 2023-03-07 08:23:50 +00:00
parent 9579c9c0d2
commit f516011182
2 changed files with 19 additions and 8 deletions

View file

@ -18,14 +18,23 @@
$: canMoveLeft = orderable && column.idx > 0
$: canMoveRight = orderable && column.idx < $columns.length - 1
const startReordering = e => {
timeout = setTimeout(() => {
reorder.actions.startReordering(column.name, e)
}, 200)
const onMouseDown = e => {
if (e.button === 0 && orderable) {
timeout = setTimeout(() => {
reorder.actions.startReordering(column.name, e)
}, 200)
}
}
const stopReordering = () => {
clearTimeout(timeout)
const onMouseUp = e => {
if (e.button === 0 && orderable) {
clearTimeout(timeout)
}
}
const onContextMenu = e => {
e.preventDefault()
open = true
}
const sortAscending = () => {
@ -66,8 +75,9 @@
<SheetCell
reorderSource={$reorder.sourceColumn === column.name}
reorderTarget={$reorder.targetColumn === column.name}
on:mousedown={orderable ? startReordering : null}
on:mouseup={orderable ? stopReordering : null}
on:mousedown={onMouseDown}
on:mouseup={onMouseUp}
on:contextmenu={onContextMenu}
width={column.width}
left={column.left}
>

View file

@ -39,6 +39,7 @@
on:mousedown
on:mouseup
on:click
on:contextmenu
{style}
data-row={rowIdx}
>