tdesign-vue-next
Version:
TDesign Component for vue-next
172 lines (168 loc) • 6.06 kB
JavaScript
/**
* tdesign v1.11.5
* (c) 2025 tdesign
* @license MIT
*/
import { _ as _toConsumableArray } from '../_chunks/dep-03e058e5.mjs';
import { _ as _defineProperty } from '../_chunks/dep-da95471f.mjs';
import { ref, defineComponent, onMounted, nextTick, h, createApp } from 'vue';
import _Dialog from './dialog.mjs';
import { getAttach } from '../utils/dom.mjs';
import { omit } from 'lodash-es';
import '../_chunks/dep-9f375e51.mjs';
import '../_chunks/dep-4ed7019e.mjs';
import '../_chunks/dep-6a79c950.mjs';
import './props.mjs';
import '../hooks/useConfig.mjs';
import '../config-provider/hooks/useConfig.mjs';
import '../config-provider/utils/context.mjs';
import '../_chunks/dep-a5ae2f3f.mjs';
import '../_chunks/dep-82d2a14f.mjs';
import '../_chunks/dep-37fa6ccb.mjs';
import '../_chunks/dep-7fb24b17.mjs';
import './hooks/index.mjs';
import './hooks/useAction.mjs';
import '../_chunks/dep-46ec3e86.mjs';
import '../utils/render-tnode.mjs';
import '../button/index.mjs';
import '../button/button.mjs';
import '../loading/index.mjs';
import '../loading/directive.mjs';
import '../loading/plugin.mjs';
import '../loading/loading.mjs';
import '../_chunks/dep-6d9c1bfc.mjs';
import '../loading/icon/gradient.mjs';
import '../_chunks/dep-6cfc5734.mjs';
import '../_chunks/dep-3d81ac0a.mjs';
import '../hooks/useTeleport.mjs';
import '../loading/props.mjs';
import '../utils/withInstall.mjs';
import './style/css.mjs';
import '../button/props.mjs';
import '../hooks/useRipple.mjs';
import '../hooks/useKeepAnimation.mjs';
import '../hooks/useDisabled.mjs';
import './hooks/useSameTarget.mjs';
import '../hooks/useDestroyOnClose.mjs';
import '../_chunks/dep-57b3d767.mjs';
import '../hooks/usePopupManager.mjs';
import '../_chunks/dep-7dcc7954.mjs';
import './utils/index.mjs';
import './dialog-card.mjs';
import 'tdesign-icons-vue-next';
import './dialog-card-props.mjs';
import '../hooks/useGlobalIcon.mjs';
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var createDialog = function createDialog(props) {
var options = _objectSpread({}, props);
var wrapper = document.createElement("div");
var visible = ref(false);
var className = options.className,
style = options.style;
var preClassName = className;
var updateClassNameStyle = function updateClassNameStyle(className2, style2) {
if (className2) {
if (preClassName && preClassName !== className2) {
var _wrapper$firstElement;
(_wrapper$firstElement = wrapper.firstElementChild.classList).remove.apply(_wrapper$firstElement, _toConsumableArray(preClassName.split(" ").map(function (name) {
return name.trim();
})));
}
className2.split(" ").forEach(function (name) {
wrapper.firstElementChild.classList.add(name.trim());
});
}
if (style2) {
wrapper.firstElementChild.style.cssText += style2;
}
preClassName = className2;
};
var component = defineComponent({
setup: function setup(props2, _ref) {
var expose = _ref.expose;
var dialogOptions = ref(options);
onMounted(function () {
visible.value = true;
document.activeElement.blur();
nextTick(function () {
updateClassNameStyle(className, style);
});
});
var update = function update(newOptions) {
dialogOptions.value = _objectSpread(_objectSpread({}, options), newOptions);
};
expose({
update: update
});
return function () {
var onClose = options.onClose || function () {
visible.value = false;
};
delete options.className;
delete options.style;
return h(_Dialog, _objectSpread({
onClose: onClose,
visible: visible.value
}, dialogOptions.value));
};
}
});
var dialogComponent = createApp(component);
var dialog = dialogComponent.mount(wrapper);
var container = getAttach(options.attach);
if (container) {
container.appendChild(wrapper);
} else {
console.error("attach is not exist");
}
var dialogNode = {
show: function show() {
visible.value = true;
},
hide: function hide() {
visible.value = false;
},
update: function update(newOptions) {
dialog.update(omit(newOptions, ["className", "style"]));
updateClassNameStyle(newOptions.className, newOptions.style);
},
destroy: function destroy() {
visible.value = false;
setTimeout(function () {
dialogComponent.unmount();
wrapper.remove();
}, 300);
},
setConfirmLoading: function setConfirmLoading(val) {
dialog.update({
confirmLoading: val
});
}
};
return dialogNode;
};
var confirm = function confirm(props) {
return createDialog(props);
};
var alert = function alert(props) {
var options = _objectSpread({}, props);
options.cancelBtn = null;
return createDialog(options);
};
var extraApi = {
confirm: confirm,
alert: alert
};
var DialogPlugin = createDialog;
DialogPlugin.install = function (app) {
app.config.globalProperties.$dialog = createDialog;
Object.keys(extraApi).forEach(function (funcName) {
app.config.globalProperties.$dialog[funcName] = extraApi[funcName];
});
};
Object.keys(extraApi).forEach(function (funcName) {
DialogPlugin[funcName] = extraApi[funcName];
});
export { DialogPlugin, DialogPlugin as default };
//# sourceMappingURL=plugin.mjs.map