yanzhen-design-vue
Version:
124 lines (123 loc) • 3.33 kB
JavaScript
import { h, mergeProps, withCtx, createVNode } from "vue";
import { omit } from "lodash-es";
import "../../_utils/index.mjs";
import { ConfigProvider } from "ant-design-vue";
import { globalConfigForApi } from "ant-design-vue/es/config-provider";
import destroyFns from "./destroyFns.mjs";
import "./contacts-select.vue.mjs";
import { render } from "../../_utils/render.mjs";
import { triggerVNodeUpdate } from "../../_utils/triggerVNodeUpdate.mjs";
import _sfc_main from "./contacts-select.vue2.mjs";
const confirm = (props) => {
var _a;
const { content = "", ...config } = props;
const dom = (_a = window == null ? void 0 : window.$vueApp) == null ? void 0 : _a._container;
const container = document.createElement("div");
dom == null ? void 0 : dom.appendChild(container);
let currentConfig = {
...omit(config, "parentContext", "appContext"),
style: {
display: "none"
},
listType: false,
modalOpen: true,
onClose: close
};
let confirmDialogInstance = null;
function destroy(...args) {
if (confirmDialogInstance) {
render(null, container);
confirmDialogInstance = null;
}
const triggerCancel = args.some((param) => param && param.triggerCancel);
if (config.onCancel && triggerCancel) {
config.onCancel(
() => {
},
...args.slice(1)
);
}
for (let i = 0; i < destroyFns.length; i++) {
const fn = destroyFns[i];
if (fn === close) {
destroyFns.splice(i, 1);
break;
}
}
}
function close(...args) {
const modalProps = { ...currentConfig.modalProps ?? {} };
const afterClose = modalProps == null ? void 0 : modalProps.afterClose;
currentConfig = {
...currentConfig,
modalOpen: false,
modalProps: {
...modalProps,
afterClose: () => {
if (typeof afterClose === "function") {
afterClose();
}
destroy.apply(this, args);
}
}
};
if (currentConfig.visible) {
delete currentConfig.visible;
}
update(currentConfig);
}
function update(configUpdate) {
if (typeof configUpdate === "function") {
currentConfig = configUpdate(currentConfig);
} else {
currentConfig = {
...currentConfig,
...configUpdate
};
}
if (confirmDialogInstance) {
triggerVNodeUpdate(confirmDialogInstance, currentConfig, container);
}
}
const Wrapper = (p) => {
return h(
ConfigProvider,
mergeProps({}, globalConfigForApi, {
//@ts-ignore
appContext: config.parentContext ?? config.appContext ?? p.appContext
}),
{
default: withCtx(() => {
return [
h(_sfc_main, p, {
default: withCtx(() => [h(content)])
})
];
})
}
);
};
function render$1(props2) {
const vm = createVNode(Wrapper, { ...props2 });
vm.appContext = config.parentContext ?? config.appContext ?? vm.appContext;
render(vm, container);
return vm;
}
confirmDialogInstance = render$1(currentConfig);
destroyFns.push(close);
return {
destroy: close,
update
};
};
function withConfirm(props) {
return {
...props,
type: "confirm"
};
}
export {
confirm,
confirm as default,
withConfirm
};