winbox-ui-next
Version:
We Design Vue 2.0: A Vue.js 3 UI Library
92 lines (91 loc) • 3.15 kB
JavaScript
;
var __defProp = Object.defineProperty;
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 vue = require("vue");
var dom = require("../_utils/dom.js");
var globalConfig = require("../_utils/global-config.js");
var is = require("../_utils/is.js");
var omit = require("../_utils/omit.js");
var vueUtils = require("../_utils/vue-utils.js");
var drawer = require("./drawer.js");
const open = (config, appContext) => {
let container = dom.getOverlay("drawer");
const handleOk = () => {
if (vm.component) {
vm.component.props.visible = false;
}
if (is.isFunction(config.onOk)) {
config.onOk();
}
};
const handleCancel = () => {
if (vm.component) {
vm.component.props.visible = false;
}
if (is.isFunction(config.onCancel)) {
config.onCancel();
}
};
const handleClose = () => {
if (container) {
vue.render(null, container);
document.body.removeChild(container);
}
container = null;
if (is.isFunction(config.onClose)) {
config.onClose();
}
};
const defaultConfig = {
visible: true,
renderToBody: false,
onOk: handleOk,
onCancel: handleCancel,
onClose: handleClose
};
const vm = vue.createVNode(drawer, __spreadValues(__spreadValues(__spreadValues({}, omit.omit(config, ["content", "title", "footer"])), {
header: typeof config.header === "boolean" ? config.header : void 0,
footer: typeof config.footer === "boolean" ? config.footer : void 0
}), defaultConfig), {
default: vueUtils.getSlotFunction(config.content),
header: typeof config.header !== "boolean" ? vueUtils.getSlotFunction(config.header) : void 0,
title: vueUtils.getSlotFunction(config.title),
footer: typeof config.footer !== "boolean" ? vueUtils.getSlotFunction(config.footer) : void 0
});
if (appContext != null ? appContext : Drawer._context) {
vm.appContext = appContext != null ? appContext : Drawer._context;
}
vue.render(vm, container);
document.body.appendChild(container);
return {
close: handleClose
};
};
const Drawer = Object.assign(drawer, {
open,
install: (app, options) => {
globalConfig.setGlobalConfig(app, options);
const componentPrefix = globalConfig.getComponentPrefix(options);
app.component(componentPrefix + drawer.name, drawer);
const drawerWithContext = {
open: (config, appContext = app._context) => open(config, appContext)
};
app.config.globalProperties.$drawer = drawerWithContext;
},
_context: null
});
module.exports = Drawer;