UNPKG

tdesign-vue-next

Version:
112 lines (108 loc) 3.7 kB
/** * tdesign v1.20.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-9ce910b6.mjs'; import { g as getAttach, a as addClass, r as removeClass } from '../_chunks/dep-05bddb06.mjs'; import '../_chunks/dep-ea5fbe21.mjs'; import '../_chunks/dep-26d65784.mjs'; import '../_chunks/dep-98dac781.mjs'; import '../_chunks/dep-f038e2b4.mjs'; import './icon/gradient.mjs'; import '../_chunks/dep-9b3b77bb.mjs'; import '../_chunks/dep-557b68dd.mjs'; import '../_chunks/dep-4de66dd0.mjs'; import './props.mjs'; import '../config-provider/hooks/useConfig.mjs'; import '../config-provider/utils/context.mjs'; import '../_chunks/dep-57949dcd.mjs'; import '../_chunks/dep-57027bda.mjs'; import '../_chunks/dep-cafb5eac.mjs'; import '../_chunks/dep-f1da7269.mjs'; import '../_chunks/dep-192d0c88.mjs'; import '../_chunks/dep-652c99fe.mjs'; import '../_chunks/dep-5b369203.mjs'; import '../_chunks/dep-a4f55e3b.mjs'; import '../_chunks/dep-920eff5b.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