tdesign-vue-next
Version:
TDesign Component for vue-next
112 lines (108 loc) • 3.7 kB
JavaScript
/**
* tdesign v1.19.2
* (c) 2026 tdesign
* @license MIT
*/
import { ref, defineComponent, reactive, h, createVNode, render } from 'vue';
import { merge } from 'lodash-es';
import _Loading from './loading.mjs';
import { u as usePrefixClass } from '../_chunks/dep-fbeb2963.mjs';
import { g as getAttach, a as addClass, r as removeClass } from '../_chunks/dep-feed89df.mjs';
import '../_chunks/dep-f558ebb8.mjs';
import '../_chunks/dep-b0b422fe.mjs';
import '../_chunks/dep-ba214d75.mjs';
import '../_chunks/dep-e1c62679.mjs';
import './icon/gradient.mjs';
import '../_chunks/dep-58979704.mjs';
import '../_chunks/dep-47c3cae9.mjs';
import '../_chunks/dep-c231a5b4.mjs';
import './props.mjs';
import '../config-provider/hooks/useConfig.mjs';
import '../config-provider/utils/context.mjs';
import '../_chunks/dep-e0ab6d55.mjs';
import '../_chunks/dep-5b510fcd.mjs';
import '../_chunks/dep-75f265c4.mjs';
import '../_chunks/dep-67ffcfeb.mjs';
import '../_chunks/dep-edab0e6a.mjs';
import '../_chunks/dep-76dddedf.mjs';
import '../_chunks/dep-d92220c4.mjs';
import '../_chunks/dep-466a8f31.mjs';
import '../_chunks/dep-e66c0337.mjs';
var fullScreenLoadingInstance = null;
function mergeDefaultProps(props) {
var options = merge({
fullscreen: false,
attach: "body",
loading: true,
preventScrollThrough: true
}, props);
return options;
}
function createLoading(props, context) {
var mergedProps = mergeDefaultProps(props);
if (mergedProps.fullscreen && fullScreenLoadingInstance) {
return fullScreenLoadingInstance;
}
var parentRelativeClass = ref("");
var lockClass = ref("");
var component = defineComponent({
setup: function setup() {
var loadingOptions = reactive(mergedProps);
parentRelativeClass.value = usePrefixClass("loading__parent--relative").value;
lockClass.value = usePrefixClass("loading--lock").value;
return function () {
return h(_Loading, loadingOptions);
};
}
});
var attach = getAttach(mergedProps.fullscreen ? "body" : mergedProps.attach);
var instance = createVNode(component);
if (context !== null && context !== void 0 ? context : LoadingPlugin._context) {
instance.appContext = context !== null && context !== void 0 ? context : LoadingPlugin._context;
}
var wrapper = document.createElement("div");
render(instance, wrapper);
var lockFullscreen = mergedProps.preventScrollThrough && mergedProps.fullscreen;
if (lockFullscreen) {
addClass(document.body, lockClass.value);
}
if (attach) {
addClass(attach, parentRelativeClass.value);
} else {
console.error("attach is not exist");
}
var loadingInstance = {
hide: function hide() {
removeClass(attach, parentRelativeClass.value);
removeClass(document.body, lockClass.value);
render(null, wrapper);
wrapper.remove();
}
};
return loadingInstance;
}
function produceLoading(props, context) {
if (props === true) {
fullScreenLoadingInstance = createLoading({
fullscreen: true,
loading: true,
attach: "body",
preventScrollThrough: true
}, context);
return fullScreenLoadingInstance;
}
if (props === false) {
var _fullScreenLoadingIns;
(_fullScreenLoadingIns = fullScreenLoadingInstance) === null || _fullScreenLoadingIns === void 0 || _fullScreenLoadingIns.hide();
fullScreenLoadingInstance = null;
return;
}
return createLoading(props);
}
var LoadingPlugin = produceLoading;
LoadingPlugin.install = function (app) {
app.config.globalProperties.$loading = produceLoading;
LoadingPlugin._context = app._context;
};
export { LoadingPlugin, LoadingPlugin as default };
//# sourceMappingURL=plugin.mjs.map