{"version":3,"file":"index.mjs","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  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":";;;;;;;;;AAiBAA,EAAU,OAAO;AAEV,MAAMC,EAAe;AAAA,EAW1B,YAAYC,IAAmC,IAAI;AAVnD,IAAAC,EAAA;AACA,IAAAA,EA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