{"version":3,"file":"dialog.mjs","sources":["../../src/functions/dialog/index.ts"],"sourcesContent":["/**\n * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\nimport type { AsyncComponent, Component } from 'vue'\n\nimport Vue, { toRaw } from 'vue'\n\ninterface DialogProps {\n\t[index: string]: unknown\n\tcontainer?: string\n}\n\n/**\n * Helper to spawn a Vue dialog without having to mount it from a component\n *\n * @param dialog The dialog component to spawn\n * @param props Properties to pass to the dialog\n * @param props.container Optionally pass a query selector for the dialog container element\n * @param onClose Callback when the dialog is closed\n */\nexport function spawnDialog(\n\tdialog: Component | AsyncComponent,\n\tprops?: DialogProps,\n\tonClose: (...rest: unknown[]) => void = () => {},\n): Vue {\n\tconst el = document.createElement('div')\n\n\tconst container: HTMLElement = typeof props?.container === 'string'\n\t\t? (document.querySelector(props.container) || document.body)\n\t\t: document.body\n\tcontainer.appendChild(el)\n\n\tconst vm = new Vue({\n\t\tel,\n\t\tname: 'VueDialogHelper',\n\t\trender: (h) =>\n\t\t\th(dialog, {\n\t\t\t\tprops,\n\t\t\t\ton: {\n\t\t\t\t\tclose: (...rest: unknown[]) => {\n\t\t\t\t\t\tonClose(...rest.map(v => toRaw(v)))\n\t\t\t\t\t\tvm.$destroy()\n\t\t\t\t\t\tel.remove()\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t})\n\treturn vm\n}\n"],"names":[],"mappings":";AAqBO,SAAS,YACf,QACA,OACA,UAAwC,MAAM;AAAC,GACzC;AACA,QAAA,KAAK,SAAS,cAAc,KAAK;AAEvC,QAAM,YAAyB,OAAO,OAAO,cAAc,WACvD,SAAS,cAAc,MAAM,SAAS,KAAK,SAAS,OACrD,SAAS;AACZ,YAAU,YAAY,EAAE;AAElB,QAAA,KAAK,IAAI,IAAI;AAAA,IAClB;AAAA,IACA,MAAM;AAAA,IACN,QAAQ,CAAC,MACR,EAAE,QAAQ;AAAA,MACT;AAAA,MACA,IAAI;AAAA,QACH,OAAO,IAAI,SAAoB;AAC9B,kBAAQ,GAAG,KAAK,IAAI,OAAK,MAAM,CAAC,CAAC,CAAC;AAClC,aAAG,SAAS;AACZ,aAAG,OAAO;AAAA,QACX;AAAA,MACD;AAAA,IAAA,CACA;AAAA,EAAA,CACF;AACM,SAAA;AACR;"}