-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vscode): add context menu in preview panel
- Loading branch information
Showing
14 changed files
with
193 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,62 @@ | ||
import { config } from '@react-spring/konva' | ||
import { KonvaCore } from '../../konva' | ||
import type { OnNodeClick, KonvaPointerEvent, DiagramNode } from '../types' | ||
import { mouseDefault, mousePointer } from './utils' | ||
import type { NodeSpringsCtrl } from '../springs' | ||
import { config } from '@react-spring/konva' | ||
import type { DiagramNode, KonvaPointerEvent, OnNodeClick } from '../types' | ||
import { mouseDefault, mousePointer } from './utils' | ||
import type { KonvaNodeEvents } from 'react-konva' | ||
|
||
export function nodeListeners({ | ||
node, | ||
ctrl, | ||
onNodeContextMenu, | ||
onNodeClick | ||
}: { | ||
node: DiagramNode | ||
ctrl: NodeSpringsCtrl | ||
onNodeContextMenu?: OnNodeClick | undefined | ||
onNodeClick?: OnNodeClick | undefined | ||
}) { | ||
if (!onNodeClick) { | ||
return {} as const | ||
} | ||
return { | ||
onPointerEnter: (e: KonvaPointerEvent) => { | ||
mousePointer(e) | ||
void ctrl.start({ | ||
to: { | ||
scaleX: 1.08, | ||
scaleY: 1.08 | ||
}, | ||
default: false, | ||
config: config.stiff | ||
}) | ||
}, | ||
onPointerLeave: (e: KonvaPointerEvent) => { | ||
mouseDefault(e) | ||
void ctrl.start({ | ||
to: { | ||
scaleX: 1, | ||
scaleY: 1 | ||
}, | ||
default: false, | ||
delay: 120, | ||
config: config.slow | ||
}) | ||
}): KonvaNodeEvents { | ||
return Object.assign( | ||
{}, | ||
onNodeContextMenu && { | ||
onContextMenu: (e: KonvaPointerEvent) => { | ||
if (KonvaCore.isDragging()) { | ||
return | ||
} | ||
onNodeContextMenu(node, e) | ||
} | ||
}, | ||
onPointerClick: (e: KonvaPointerEvent) => { | ||
if (KonvaCore.isDragging()) { | ||
return | ||
onNodeClick && { | ||
onPointerEnter: (e: KonvaPointerEvent) => { | ||
mousePointer(e) | ||
void ctrl.start({ | ||
to: { | ||
scaleX: 1.08, | ||
scaleY: 1.08 | ||
}, | ||
default: false, | ||
config: config.stiff | ||
}) | ||
}, | ||
onPointerLeave: (e: KonvaPointerEvent) => { | ||
mouseDefault(e) | ||
void ctrl.start({ | ||
to: { | ||
scaleX: 1, | ||
scaleY: 1 | ||
}, | ||
default: false, | ||
delay: 120, | ||
config: config.slow | ||
}) | ||
}, | ||
onPointerClick: (e: KonvaPointerEvent) => { | ||
if (KonvaCore.isDragging()) { | ||
return | ||
} | ||
e.cancelBubble = true | ||
onNodeClick(node, e) | ||
} | ||
e.cancelBubble = true | ||
onNodeClick(node, e) | ||
} | ||
} as const | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.