mirror of
https://github.com/koel/koel
synced 2024-12-29 22:13:06 +00:00
25 lines
639 B
TypeScript
25 lines
639 B
TypeScript
import { defineAsyncComponent, reactive, ref } from 'vue'
|
|
|
|
export type ContextMenuContext = Record<string, any>
|
|
|
|
export const useContextMenu = () => {
|
|
const ContextMenuBase = defineAsyncComponent(() => import('@/components/ui/ContextMenuBase.vue'))
|
|
const base = ref<InstanceType<typeof ContextMenuBase>>()
|
|
|
|
const context = reactive<ContextMenuContext>({})
|
|
|
|
const open = (top: number, left: number, ctx: ContextMenuContext = {}) => {
|
|
base.value?.open(top, left, ctx)
|
|
Object.assign(context, ctx)
|
|
}
|
|
|
|
const close = () => base.value?.close()
|
|
|
|
return {
|
|
base,
|
|
ContextMenuBase,
|
|
open,
|
|
close,
|
|
context
|
|
}
|
|
}
|