@vuesax-alpha/nightly
Version:
A Component Library for Vue 3
80 lines (75 loc) • 2.4 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var core = require('@vueuse/core');
require('../../../utils/index.js');
require('../../../constants/index.js');
var loading$2 = require('./loading2.js');
var types = require('../../../utils/types.js');
var shared = require('@vue/shared');
var error = require('../../../utils/error.js');
var loading$1 = require('../../../constants/loading.js');
const loading = (options = {}) => {
if (!options || !core.isClient)
return {
setPercent: () => void 0,
setProgress: () => void 0,
close: () => void 0,
setText: () => void 0
};
const getOption = (key) => {
const data = (options == null ? void 0 : options[key]) || key;
if (vue.unref(data))
return vue.ref(data);
return data;
};
const optionsRef = {};
Object.keys(options).forEach((e) => {
optionsRef[e] = getOption(e);
});
let appendTo = document.body;
if (types.isElement(core.unrefElement(optionsRef.target))) {
appendTo = core.unrefElement(optionsRef.target);
} else if (shared.isString(vue.unref(optionsRef.target))) {
appendTo = document.querySelector(vue.unref(optionsRef.target));
}
if (!types.isElement(appendTo)) {
error.debugWarn(
"VsLoading",
"the appendTo option is not an HTMLElement. Falling back to document.body."
);
appendTo = document.body;
optionsRef.target.value = void 0;
}
if (appendTo.clientHeight < loading$1.LOADING_RECT.height) {
const eightyPercentParentHeight = appendTo.clientHeight * loading$1.SCALE_PARENT;
const loadingScale = eightyPercentParentHeight / loading$1.LOADING_RECT.height;
optionsRef.scale = vue.ref(loadingScale);
}
const vm = vue.createVNode(loading$2["default"], vue.reactive(optionsRef));
const container = document.createElement("div");
vue.render(vm, container);
appendTo.appendChild(container.firstChild);
const close = () => {
;
vm.component.exposed.close();
};
const setText = (val) => {
optionsRef.text.value = val;
};
const setProgress = (val) => {
optionsRef.progress.value = val;
};
const setPercent = (val) => {
optionsRef.percent.value = val;
};
return {
close,
setText,
setProgress,
setPercent
};
};
exports["default"] = loading;
exports.loading = loading;
//# sourceMappingURL=method.js.map