{"version":3,"file":"index.cjs","sources":["../../../components/confirm/index.ts"],"sourcesContent":["import { createApp, createVNode, markRaw, render } from 'vue'\n\nimport Component from './confirm.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 { ConfirmButtonType, ConfirmInstance, ConfirmOptions, ConfirmState } from './symbol'\n\nexport { confirmProps } from './props'\n\nexport type { ConfirmProps, ConfirmCProps } from './props'\nexport type { ConfirmButtonType, ConfirmOptions, ConfirmState }\n\ntype FuzzyOptions = string | ConfirmOptions\n\nComponent.name = 'Confirm'\n\nexport class ConfirmManager {\n  name: string\n  defaults: Record<string, unknown>\n\n  private _mountedApp: App<unknown> | null\n  private _instance: ConfirmInstance | null\n  private _innerApp: App<unknown> | null\n  private _container: HTMLElement | null\n  private _wrapper: HTMLElement | SVGElement | null\n  private _mountedEl: HTMLElement | null\n\n  constructor(options: Partial<ConfirmOptions> = {}) {\n    this._mountedApp = null\n    this._instance = null\n    this._innerApp = null\n    this._container = null\n    this._wrapper = null\n    this._mountedEl = null\n    this.name = 'Confirm'\n    this.defaults = {}\n\n    this.config(options)\n  }\n\n  open(content: string, type?: ConfirmButtonType): Promise<boolean>\n  open(options: ConfirmOptions): Promise<boolean>\n  open(content: string, title: string, type?: ConfirmButtonType): Promise<boolean>\n  open(options: FuzzyOptions, title?: string, type?: ConfirmButtonType) {\n    if (!isClient) {\n      return\n    }\n\n    if (typeof options === 'string') {\n      if (type) {\n        options = { title, content: options, confirmType: type }\n      } else {\n        options = { content: options, confirmType: title as ConfirmButtonType }\n      }\n    }\n\n    const item: ConfirmOptions = { ...this.defaults, ...options }\n\n    if (item.icon && typeof item.icon === 'object') {\n      item.icon = markRaw(item.icon)\n    }\n\n    return this._getInstance()?.openConfirm(item)\n  }\n\n  close() {\n    this._getInstance()?.closeConfirm()\n  }\n\n  config(options: Record<string, unknown>) {\n    this.defaults = { ...this.defaults, ...options }\n  }\n\n  clone() {\n    const manager = new ConfirmManager(this.defaults)\n\n    manager._mountedApp = this._mountedApp\n\n    return manager\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: Partial<ConfirmOptions> & { property?: string } = {}) {\n    const { property, ...others } = options\n\n    this.config(others)\n    this._mountedApp = app\n\n    if (property || !app.config.globalProperties.$confirm) {\n      app.config.globalProperties[property || '$confirm'] = this\n    }\n  }\n\n  transferTo(target: MaybeRef<string | MaybeInstance>) {\n    if (!isClient) return\n\n    const el = unrefElement(target)\n\n    if (el) {\n      this._wrapper = el\n\n      if (this._instance) {\n        this._mountedEl && this._wrapper.appendChild(this._mountedEl)\n      } else {\n        this._getInstance()\n      }\n    }\n  }\n\n  private _getInstance() {\n    if (!this._instance && isClient) {\n      if (!this._mountedApp) {\n        console.warn('[vexip-ui:Confirm]: 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 ConfirmInstance\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<ConfirmInstance>(vnode)\n      }\n\n      this._mountedEl = this._container.firstElementChild as HTMLElement\n      ;(this._wrapper || document.body).appendChild(this._mountedEl)\n    }\n\n    return this._instance\n  }\n}\n\nexport const Confirm = new ConfirmManager()\n"],"names":["Component","ConfirmManager","options","__publicField","title","type","isClient","item","markRaw","_a","manager","_b","render","destroyObject","app","property","others","target","el","unrefElement","createApp","vnode","createVNode","proxyExposed","Confirm"],"mappings":"iaAiBAA,EAAU,KAAO,UAEV,MAAMC,CAAe,CAW1B,YAAYC,EAAmC,GAAI,CAVnDC,EAA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