{"version":3,"file":"index.cjs","sources":["../../../components/contextmenu/index.ts"],"sourcesContent":["import { createApp, createVNode, render } from 'vue'\n\nimport Component from './contextmenu.vue'\nimport { proxyExposed, unrefElement } from '@vexip-ui/hooks'\nimport { destroyObject, isClient } from '@vexip-ui/utils'\n\nimport type { App, MaybeRef } from 'vue'\nimport type { MaybeInstance } from '@vexip-ui/hooks'\nimport type { ContextmenuConfig, ContextmenuInstance, ContextmenuOptions, Key } from './symbol'\n\nexport type { ContextmenuConfig, ContextmenuOptions }\n\nexport class ContextmenuManager {\n  name: string\n\n  private _mountedApp: App<unknown> | null\n  private _instance: ContextmenuInstance | null\n  private _innerApp: App<unknown> | null\n  private _container: HTMLElement | null\n  private _pending: Promise<Key[] | null> | null\n  private _wrapper: HTMLElement | SVGElement | null\n  private _mountedEl: HTMLElement | null\n\n  constructor() {\n    this._mountedApp = null\n    this._instance = null\n    this._innerApp = null\n    this._container = null\n    this._pending = null\n    this._wrapper = null\n    this._mountedEl = null\n    this.name = 'Contextmenu'\n  }\n\n  open(options: ContextmenuOptions) {\n    if (!isClient) {\n      return\n    }\n\n    const { target = document.body, ...others } = options\n\n    this._pending = this._getInstance(target)!.openContextmenu(others)\n\n    return this._pending\n  }\n\n  destroy() {\n    this._mountedEl && this._wrapper?.removeChild(this._mountedEl)\n    this._innerApp?.unmount()\n    this._container && render(null, this._container)\n    destroyObject(this)\n  }\n\n  isDestroyed() {\n    return false\n  }\n\n  install(app: App, options: { property?: string } = {}) {\n    const { property } = options\n\n    this._mountedApp = app\n\n    if (property || !app.config.globalProperties.$contextmenu) {\n      app.config.globalProperties[property || '$contextmenu'] = this\n    }\n  }\n\n  private _getInstance(target: MaybeRef<string | MaybeInstance>) {\n    if (!isClient) return\n\n    if (this._pending) {\n      let innerApp = this._innerApp\n      let container = this._container\n\n      const unmount = () => {\n        innerApp?.unmount()\n        container && render(null, container)\n\n        innerApp = null\n        container = null\n      }\n\n      this._pending.finally(unmount)\n      this._instance?.handleCancel()\n    } else {\n      this._innerApp?.unmount()\n      this._container && render(null, this._container)\n    }\n\n    this._pending = null\n\n    if (!this._mountedApp) {\n      console.warn('[vexip-ui:Contextmenu]: App missing, the plugin maybe not installed.')\n\n      this._container = document.createElement('div')\n      this._innerApp = createApp(Component)\n      this._instance = this._innerApp.mount(this._container) as ContextmenuInstance\n    } else {\n      const vnode = createVNode(Component, null, null)\n\n      this._container = document.createElement('div')\n      vnode.appContext = this._mountedApp._context\n\n      render(vnode, this._container)\n\n      this._instance = proxyExposed<ContextmenuInstance>(vnode)\n    }\n\n    this._mountedEl = this._container.firstElementChild as HTMLElement\n    this._wrapper = unrefElement(target) || document.body\n\n    this._wrapper.appendChild(this._mountedEl)\n\n    return this._instance\n  }\n}\n\nexport const Contextmenu = new ContextmenuManager()\n"],"names":["ContextmenuManager","__publicField","options","isClient","target","others","_a","_b","render","destroyObject","app","property","innerApp","container","unmount","createApp","Component","vnode","createVNode","proxyExposed","unrefElement","Contextmenu"],"mappings":"gZAYO,MAAMA,CAAmB,CAW9B,aAAc,CAVdC,EAAA,aAEQA,EAAA,oBACAA,EAAA,kBACAA,EAAA,kBACAA,EAAA,mBACAA,EAAA,iBACAA,EAAA,iBACAA,EAAA,mBAGN,KAAK,YAAc,KACnB,KAAK,UAAY,KACjB,KAAK,UAAY,KACjB,KAAK,WAAa,KAClB,KAAK,SAAW,KAChB,KAAK,SAAW,KAChB,KAAK,WAAa,KAClB,KAAK,KAAO,aAAA,CAGd,KAAKC,EAA6B,CAChC,GAAI,CAACC,EAAAA,SACH,OAGF,KAAM,CAAE,OAAAC,EAAS,SAAS,KAAM,GAAGC,CAAW,EAAAH,EAE9C,YAAK,SAAW,KAAK,aAAaE,CAAM,EAAG,gBAAgBC,CAAM,EAE1D,KAAK,QAAA,CAGd,SAAU,SACR,KAAK,cAAcC,EAAA,KAAK,WAAL,MAAAA,EAAe,YAAY,KAAK,cACnDC,EAAA,KAAK,YAAL,MAAAA,EAAgB,UAChB,KAAK,YAAcC,EAAA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