UNPKG

@varlet/ui

Version:

A Vue3 component library based on Material Design 2 and 3, supporting mobile and desktop.

98 lines (97 loc) 3.28 kB
var __defProp = Object.defineProperty; var __defProps = Object.defineProperties; var __getOwnPropDescs = Object.getOwnPropertyDescriptors; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); import { nextTick, reactive } from "vue"; import { call, inBrowser, isString } from "@varlet/shared"; import { mountInstance, withInstall, withPropsDefaultsSetter } from "../utils/components.mjs"; import VarDialog from "./Dialog.mjs"; import { props as dialogProps } from "./props.mjs"; let singletonOptions; let defaultOptions = {}; function normalizeOptions(options = {}) { if (isString(options)) { return __spreadProps(__spreadValues({}, defaultOptions), { message: options }); } return __spreadValues(__spreadValues({}, defaultOptions), options); } function Dialog(options) { if (!inBrowser()) { return Promise.resolve(); } return new Promise((resolve) => { Dialog.close(); const dialogOptions = normalizeOptions(options); const reactiveDialogOptions = reactive(dialogOptions); reactiveDialogOptions.teleport = "body"; singletonOptions = reactiveDialogOptions; const { unmountInstance } = mountInstance(VarDialog, reactiveDialogOptions, { onConfirm: () => { call(reactiveDialogOptions.onConfirm); resolve("confirm"); }, onCancel: () => { call(reactiveDialogOptions.onCancel); resolve("cancel"); }, onClose: () => { call(reactiveDialogOptions.onClose); resolve("close"); }, onClosed: () => { call(reactiveDialogOptions.onClosed); unmountInstance(); singletonOptions === reactiveDialogOptions && (singletonOptions = null); }, onRouteChange: () => { unmountInstance(); singletonOptions === reactiveDialogOptions && (singletonOptions = null); }, "onUpdate:show": (value) => { reactiveDialogOptions.show = value; } }); reactiveDialogOptions.show = true; }); } Dialog.setDefaultOptions = function(options) { defaultOptions = options; }; Dialog.resetDefaultOptions = function() { defaultOptions = {}; }; Dialog.close = function() { if (singletonOptions != null) { const prevSingletonOptions = singletonOptions; singletonOptions = null; nextTick().then(() => { prevSingletonOptions.show = false; }); } }; Dialog.Component = VarDialog; withInstall(VarDialog); withInstall(VarDialog, Dialog); withPropsDefaultsSetter(Dialog, dialogProps); const _DialogComponent = VarDialog; var stdin_default = Dialog; export { _DialogComponent, stdin_default as default, dialogProps };