UNPKG

@extclp/vexip-ui

Version:

A Vue 3 UI library, Highly customizability, full TypeScript, performance pretty good

1 lines 7 kB
{"version":3,"file":"index.mjs","sources":["../../../components/confirm/index.ts"],"sourcesContent":["import { createApp, createVNode, markRaw, render } from 'vue'\r\n\r\nimport Component from './confirm.vue'\r\nimport { proxyExposed, unrefElement } from '@vexip-ui/hooks'\r\nimport { destroyObject, isClient } from '@vexip-ui/utils'\r\n\r\nimport type { App, MaybeRef } from 'vue'\r\nimport type { MaybeInstance } from '@vexip-ui/hooks'\r\nimport type { ConfirmButtonType, ConfirmInstance, ConfirmOptions, ConfirmState } from './symbol'\r\n\r\nexport { confirmProps } from './props'\r\n\r\nexport type { ConfirmProps, ConfirmCProps } from './props'\r\nexport type { ConfirmButtonType, ConfirmOptions, ConfirmState }\r\n\r\ntype FuzzyOptions = string | ConfirmOptions\r\n\r\nComponent.name = 'Confirm'\r\n\r\nexport class ConfirmManager {\r\n name: string\r\n defaults: Record<string, unknown>\r\n\r\n private _mountedApp: App<unknown> | null\r\n private _instance: ConfirmInstance | null\r\n private _innerApp: App<unknown> | null\r\n private _container: HTMLElement | null\r\n private _wrapper: HTMLElement | SVGElement | null\r\n private _mountedEl: HTMLElement | null\r\n\r\n constructor(options: Partial<ConfirmOptions> = {}) {\r\n this._mountedApp = null\r\n this._instance = null\r\n this._innerApp = null\r\n this._container = null\r\n this._wrapper = null\r\n this._mountedEl = null\r\n this.name = 'Confirm'\r\n this.defaults = {}\r\n\r\n this.config(options)\r\n }\r\n\r\n open(content: string, type?: ConfirmButtonType): Promise<boolean>\r\n open(options: ConfirmOptions): Promise<boolean>\r\n open(content: string, title: string, type?: ConfirmButtonType): Promise<boolean>\r\n open(options: FuzzyOptions, title?: string, type?: ConfirmButtonType) {\r\n if (!isClient) {\r\n return\r\n }\r\n\r\n if (typeof options === 'string') {\r\n if (type) {\r\n options = { title, content: options, confirmType: type }\r\n } else {\r\n options = { content: options, confirmType: title as ConfirmButtonType }\r\n }\r\n }\r\n\r\n const item: ConfirmOptions = { ...this.defaults, ...options }\r\n\r\n if (item.icon && typeof item.icon === 'object') {\r\n item.icon = markRaw(item.icon)\r\n }\r\n\r\n return this._getInstance()?.openConfirm(item)\r\n }\r\n\r\n close() {\r\n this._getInstance()?.closeConfirm()\r\n }\r\n\r\n config(options: Record<string, unknown>) {\r\n this.defaults = { ...this.defaults, ...options }\r\n }\r\n\r\n clone() {\r\n const manager = new ConfirmManager(this.defaults)\r\n\r\n manager._mountedApp = this._mountedApp\r\n\r\n return manager\r\n }\r\n\r\n destroy() {\r\n this._mountedEl && this._wrapper?.removeChild(this._mountedEl)\r\n this._innerApp?.unmount()\r\n this._container && render(null, this._container)\r\n destroyObject(this)\r\n }\r\n\r\n isDestroyed() {\r\n return false\r\n }\r\n\r\n install(app: App, options: Partial<ConfirmOptions> & { property?: string } = {}) {\r\n const { property, ...others } = options\r\n\r\n this.config(others)\r\n this._mountedApp = app\r\n\r\n if (property || !app.config.globalProperties.$confirm) {\r\n app.config.globalProperties[property || '$confirm'] = this\r\n }\r\n }\r\n\r\n transferTo(target: MaybeRef<string | MaybeInstance>) {\r\n if (!isClient) return\r\n\r\n const el = unrefElement(target)\r\n\r\n if (el) {\r\n this._wrapper = el\r\n\r\n if (this._instance) {\r\n this._mountedEl && this._wrapper.appendChild(this._mountedEl)\r\n } else {\r\n this._getInstance()\r\n }\r\n }\r\n }\r\n\r\n private _getInstance() {\r\n if (!this._instance && isClient) {\r\n if (!this._mountedApp) {\r\n console.warn('[vexip-ui:Confirm]: App missing, the plugin maybe not installed.')\r\n\r\n this._container = document.createElement('div')\r\n this._innerApp = createApp(Component)\r\n this._instance = this._innerApp.mount(this._container) as ConfirmInstance\r\n } else {\r\n const vnode = createVNode(Component, null, null)\r\n\r\n this._container = document.createElement('div')\r\n vnode.appContext = this._mountedApp._context\r\n\r\n render(vnode, this._container)\r\n\r\n this._instance = proxyExposed<ConfirmInstance>(vnode)\r\n }\r\n\r\n this._mountedEl = this._container.firstElementChild as HTMLElement\r\n ;(this._wrapper || document.body).appendChild(this._mountedEl)\r\n }\r\n\r\n return this._instance\r\n }\r\n}\r\n\r\nexport const Confirm = new ConfirmManager()\r\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,EAAA;AAEQ,IAAAA,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA;AAGN,SAAK,cAAc,MACnB,KAAK,YAAY,MACjB,KAAK,YAAY,MACjB,KAAK,aAAa,MAClB,KAAK,WAAW,MAChB,KAAK,aAAa,MAClB,KAAK,OAAO,WACZ,KAAK,WAAW,CAAC,GAEjB,KAAK,OAAOD,CAAO;AAAA,EAAA;AAAA,EAMrB,KAAKA,GAAuBE,GAAgBC,GAA0B;;AACpE,QAAI,CAACC;AACH;AAGE,IAAA,OAAOJ,KAAY,aACjBG,IACFH,IAAU,EAAE,OAAAE,GAAO,SAASF,GAAS,aAAaG,EAAK,IAEvDH,IAAU,EAAE,SAASA,GAAS,aAAaE,EAA2B;AAI1E,UAAMG,IAAuB,EAAE,GAAG,KAAK,UAAU,GAAGL,EAAQ;AAE5D,WAAIK,EAAK,QAAQ,OAAOA,EAAK,QAAS,aAC/BA,EAAA,OAAOC,EAAQD,EAAK,IAAI,KAGxBE,IAAA,KAAK,mBAAL,gBAAAA,EAAqB,YAAYF;AAAA,EAAI;AAAA,EAG9C,QAAQ;;AACD,KAAAE,IAAA,KAAA,mBAAA,QAAAA,EAAgB;AAAA,EAAa;AAAA,EAGpC,OAAOP,GAAkC;AACvC,SAAK,WAAW,EAAE,GAAG,KAAK,UAAU,GAAGA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