2022-04-20 10:20:09 +00:00
|
|
|
import { defineAsyncComponent, reactive, ref } from 'vue'
|
|
|
|
|
|
|
|
export type ContextMenuContext = Record<string, any>
|
2022-04-15 17:00:08 +00:00
|
|
|
|
|
|
|
export const useContextMenu = () => {
|
|
|
|
const BaseContextMenu = defineAsyncComponent(() => import('@/components/ui/context-menu.vue'))
|
|
|
|
const base = ref<InstanceType<typeof BaseContextMenu>>()
|
|
|
|
|
2022-04-20 10:20:09 +00:00
|
|
|
const context = reactive<ContextMenuContext>({})
|
|
|
|
|
|
|
|
const open = (top: number, left: number, ctx: ContextMenuContext = {}) => {
|
|
|
|
base.value?.open(top, left, ctx)
|
|
|
|
Object.assign(context, ctx)
|
|
|
|
}
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
const close = () => base.value?.close()
|
|
|
|
|
|
|
|
return {
|
|
|
|
base,
|
|
|
|
BaseContextMenu,
|
|
|
|
open,
|
2022-04-20 10:20:09 +00:00
|
|
|
close,
|
|
|
|
context
|
2022-04-15 17:00:08 +00:00
|
|
|
}
|
|
|
|
}
|