mirror of
https://github.com/koel/koel
synced 2024-12-20 09:33:23 +00:00
31 lines
719 B
TypeScript
31 lines
719 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()
|
|
|
|
const trigger = (func: Closure) => {
|
|
close()
|
|
func()
|
|
}
|
|
|
|
return {
|
|
base,
|
|
ContextMenuBase,
|
|
open,
|
|
close,
|
|
trigger,
|
|
context
|
|
}
|
|
}
|