完全跑通1.0版本

This commit is contained in:
2026-05-26 12:56:03 +08:00
parent 2ece5174a7
commit 93c714a93b
11557 changed files with 1648225 additions and 36 deletions

View File

@@ -0,0 +1,17 @@
import { LoadingOptions, LoadingOptionsResolved, LoadingParentElement } from "./src/types.js";
import { LoadingInstance } from "./src/loading.js";
import Loading from "./src/service.js";
import vLoading, { ElementLoading, LoadingBinding } from "./src/directive.js";
import { App, AppContext, Directive } from "vue";
//#region ../../packages/components/loading/index.d.ts
declare const ElLoading: {
install(app: App): void;
directive: Directive<ElementLoading, LoadingBinding>;
service: {
(options?: LoadingOptions, context?: AppContext | null): LoadingInstance;
_context: AppContext | null;
};
};
//#endregion
export { ElLoading, ElLoading as default, vLoading as ElLoadingDirective, vLoading, Loading as ElLoadingService, type LoadingInstance, LoadingOptions, LoadingOptionsResolved, LoadingParentElement };

View File

@@ -0,0 +1,25 @@
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
const require_service = require("./src/service.js");
const require_directive = require("./src/directive.js");
//#region ../../packages/components/loading/index.ts
const ElLoading = {
install(app) {
require_service.default._context = app._context;
require_directive.default._context = app._context;
app.directive("loading", require_directive.default);
app.config.globalProperties.$loading = require_service.default;
},
directive: require_directive.default,
service: require_service.default
};
//#endregion
exports.ElLoading = ElLoading;
exports.default = ElLoading;
exports.ElLoadingDirective = require_directive.default;
exports.vLoading = require_directive.default;
exports.ElLoadingService = require_service.default;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","names":["vLoading","Loading"],"sources":["../../../../../packages/components/loading/index.ts"],"sourcesContent":["import Loading from './src/service'\nimport vLoading from './src/directive'\n\nimport type { App, AppContext, Directive } from 'vue'\nimport type { ElementLoading, LoadingBinding } from './src/directive'\n\n// installer and everything in all\nexport const ElLoading = {\n install(app: App) {\n Loading._context = app._context\n ;(\n vLoading as Directive<ElementLoading, LoadingBinding> & {\n _context: AppContext | null\n }\n )._context = app._context\n app.directive('loading', vLoading)\n app.config.globalProperties.$loading = Loading\n },\n directive: vLoading,\n service: Loading,\n}\n\nexport default ElLoading\nexport { vLoading, vLoading as ElLoadingDirective, Loading as ElLoadingService }\n\nexport * from './src/types'\nexport type { LoadingInstance } from './src/loading'\n"],"mappings":";;;;;;;AAOA,MAAa,YAAY;CACvB,QAAQ,KAAU;EAChB,gBAAA,QAAQ,WAAW,IAAI;EACtB,kBACCA,QAGA,WAAW,IAAI;EACjB,IAAI,UAAU,WAAWA,kBAAAA,QAAS;EAClC,IAAI,OAAO,iBAAiB,WAAWC,gBAAAA;;CAEzC,WAAWD,kBAAAA;CACX,SAASC,gBAAAA;CACV"}

View File

@@ -0,0 +1,16 @@
import { LoadingOptions } from "./types.js";
import { LoadingInstance } from "./loading.js";
import { Directive, UnwrapRef } from "vue";
//#region ../../packages/components/loading/src/directive.d.ts
declare const INSTANCE_KEY: unique symbol;
type LoadingBinding = boolean | UnwrapRef<LoadingOptions>;
interface ElementLoading extends HTMLElement {
[INSTANCE_KEY]?: {
instance: LoadingInstance;
options: LoadingOptions;
};
}
declare const vLoading: Directive<ElementLoading, LoadingBinding>;
//#endregion
export { ElementLoading, LoadingBinding, vLoading as default };

View File

@@ -0,0 +1,74 @@
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
require("../../../_virtual/_rolldown/runtime.js");
const require_service = require("./service.js");
let vue = require("vue");
let _vue_shared = require("@vue/shared");
//#region ../../packages/components/loading/src/directive.ts
const INSTANCE_KEY = Symbol("ElLoading");
const getAttributeName = (name) => {
return `element-loading-${(0, _vue_shared.hyphenate)(name)}`;
};
const createInstance = (el, binding) => {
const vm = binding.instance;
const getBindingProp = (key) => (0, _vue_shared.isObject)(binding.value) ? binding.value[key] : void 0;
const resolveExpression = (key) => {
return (0, vue.ref)((0, _vue_shared.isString)(key) && vm?.[key] || key);
};
const getProp = (name) => resolveExpression(getBindingProp(name) || el.getAttribute(getAttributeName(name)));
const fullscreen = getBindingProp("fullscreen") ?? binding.modifiers.fullscreen;
const options = {
text: getProp("text"),
svg: getProp("svg"),
svgViewBox: getProp("svgViewBox"),
spinner: getProp("spinner"),
background: getProp("background"),
customClass: getProp("customClass"),
fullscreen,
target: getBindingProp("target") ?? (fullscreen ? void 0 : el),
body: getBindingProp("body") ?? binding.modifiers.body,
lock: getBindingProp("lock") ?? binding.modifiers.lock
};
const instance = require_service.default(options);
instance._context = vLoading._context;
el[INSTANCE_KEY] = {
options,
instance
};
};
const updateOptions = (originalOptions, newOptions) => {
for (const key of Object.keys(originalOptions)) if ((0, vue.isRef)(originalOptions[key])) originalOptions[key].value = newOptions[key];
};
const vLoading = {
mounted(el, binding) {
if (binding.value) createInstance(el, binding);
},
updated(el, binding) {
const instance = el[INSTANCE_KEY];
if (!binding.value) {
instance?.instance.close();
el[INSTANCE_KEY] = null;
return;
}
if (!instance) createInstance(el, binding);
else updateOptions(instance.options, (0, _vue_shared.isObject)(binding.value) ? binding.value : {
text: el.getAttribute(getAttributeName("text")),
svg: el.getAttribute(getAttributeName("svg")),
svgViewBox: el.getAttribute(getAttributeName("svgViewBox")),
spinner: el.getAttribute(getAttributeName("spinner")),
background: el.getAttribute(getAttributeName("background")),
customClass: el.getAttribute(getAttributeName("customClass"))
});
},
unmounted(el) {
el[INSTANCE_KEY]?.instance.close();
el[INSTANCE_KEY] = null;
}
};
vLoading._context = null;
//#endregion
exports.default = vLoading;
//# sourceMappingURL=directive.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,39 @@
import { LoadingOptionsResolved, LoadingParentElement } from "./types.js";
import * as _$vue from "vue";
import { AppContext, VNode } from "vue";
//#region ../../packages/components/loading/src/loading.d.ts
declare function createLoadingComponent(options: LoadingOptionsResolved, appContext: AppContext | null): {
setText: (text: string | VNode | VNode[]) => void;
removeElLoadingChild: () => void;
close: () => void;
handleAfterLeave: () => void;
vm: _$vue.ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, _$vue.ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string, {}, {}, {}, string, _$vue.ComponentProvideOptions>, {}, {}, "", {}, any>;
$el: HTMLElement;
originalPosition: _$vue.Ref<string, string>;
originalOverflow: _$vue.Ref<string, string>;
visible: _$vue.Ref<boolean, boolean>;
parent: _$vue.Ref<LoadingParentElement, LoadingParentElement>;
background: _$vue.Ref<string, string>;
svg: _$vue.Ref<string, string>;
svgViewBox: _$vue.Ref<string, string>;
spinner: _$vue.Ref<string | boolean, string | boolean>;
text: _$vue.Ref<string | VNode<_$vue.RendererNode, _$vue.RendererElement, {
[key: string]: any;
}> | VNode<_$vue.RendererNode, _$vue.RendererElement, {
[key: string]: any;
}>[], string | VNode<_$vue.RendererNode, _$vue.RendererElement, {
[key: string]: any;
}> | VNode<_$vue.RendererNode, _$vue.RendererElement, {
[key: string]: any;
}>[]>;
fullscreen: _$vue.Ref<boolean, boolean>;
lock: _$vue.Ref<boolean, boolean>;
customClass: _$vue.Ref<string, string>;
target: _$vue.Ref<HTMLElement, HTMLElement>;
beforeClose?: _$vue.Ref<(() => boolean) | undefined, (() => boolean) | undefined> | undefined;
closed?: _$vue.Ref<(() => void) | undefined, (() => void) | undefined> | undefined;
};
type LoadingInstance = ReturnType<typeof createLoadingComponent>;
//#endregion
export { LoadingInstance, createLoadingComponent };

View File

@@ -0,0 +1,105 @@
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
require("../../../_virtual/_rolldown/runtime.js");
const require_style = require("../../../utils/dom/style.js");
const require_use_global_config = require("../../config-provider/src/hooks/use-global-config.js");
let vue = require("vue");
//#region ../../packages/components/loading/src/loading.ts
function createLoadingComponent(options, appContext) {
let afterLeaveTimer;
const afterLeaveFlag = (0, vue.ref)(false);
const data = (0, vue.reactive)({
...options,
originalPosition: "",
originalOverflow: "",
visible: false
});
function setText(text) {
data.text = text;
}
function destroySelf() {
const target = data.parent;
const ns = vm.ns;
if (!target.vLoadingAddClassList) {
let loadingNumber = target.getAttribute("loading-number");
loadingNumber = Number.parseInt(loadingNumber) - 1;
if (!loadingNumber) {
require_style.removeClass(target, ns.bm("parent", "relative"));
target.removeAttribute("loading-number");
} else target.setAttribute("loading-number", loadingNumber.toString());
require_style.removeClass(target, ns.bm("parent", "hidden"));
}
removeElLoadingChild();
loadingInstance.unmount();
}
function removeElLoadingChild() {
vm.$el?.parentNode?.removeChild(vm.$el);
}
function close() {
if (options.beforeClose && !options.beforeClose()) return;
afterLeaveFlag.value = true;
clearTimeout(afterLeaveTimer);
afterLeaveTimer = setTimeout(handleAfterLeave, 400);
data.visible = false;
options.closed?.();
}
function handleAfterLeave() {
if (!afterLeaveFlag.value) return;
const target = data.parent;
afterLeaveFlag.value = false;
target.vLoadingAddClassList = void 0;
destroySelf();
}
const loadingInstance = (0, vue.createApp)((0, vue.defineComponent)({
name: "ElLoading",
setup(_, { expose }) {
const { ns, zIndex } = require_use_global_config.useGlobalComponentSettings("loading");
expose({
ns,
zIndex
});
return () => {
const svg = data.spinner || data.svg;
const spinner = (0, vue.h)("svg", {
class: "circular",
viewBox: data.svgViewBox ? data.svgViewBox : "0 0 50 50",
...svg ? { innerHTML: svg } : {}
}, [(0, vue.h)("circle", {
class: "path",
cx: "25",
cy: "25",
r: "20",
fill: "none"
})]);
const spinnerText = data.text ? (0, vue.h)("p", { class: ns.b("text") }, [data.text]) : void 0;
return (0, vue.h)(vue.Transition, {
name: ns.b("fade"),
onAfterLeave: handleAfterLeave
}, { default: (0, vue.withCtx)(() => [(0, vue.withDirectives)((0, vue.createVNode)("div", {
style: { backgroundColor: data.background || "" },
class: [
ns.b("mask"),
data.customClass,
ns.is("fullscreen", data.fullscreen)
]
}, [(0, vue.h)("div", { class: ns.b("spinner") }, [spinner, spinnerText])]), [[vue.vShow, data.visible]])]) });
};
}
}));
Object.assign(loadingInstance._context, appContext ?? {});
const vm = loadingInstance.mount(document.createElement("div"));
return {
...(0, vue.toRefs)(data),
setText,
removeElLoadingChild,
close,
handleAfterLeave,
vm,
get $el() {
return vm.$el;
}
};
}
//#endregion
exports.createLoadingComponent = createLoadingComponent;
//# sourceMappingURL=loading.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,11 @@
import { LoadingOptions } from "./types.js";
import { LoadingInstance } from "./loading.js";
import { AppContext } from "vue";
//#region ../../packages/components/loading/src/service.d.ts
declare const Loading: {
(options?: LoadingOptions, context?: AppContext | null): LoadingInstance;
_context: AppContext | null;
};
//#endregion
export { Loading as default };

View File

@@ -0,0 +1,102 @@
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
require("../../../_virtual/_rolldown/runtime.js");
const require_style = require("../../../utils/dom/style.js");
const require_loading = require("./loading.js");
let vue = require("vue");
let _vueuse_core = require("@vueuse/core");
let _vue_shared = require("@vue/shared");
//#region ../../packages/components/loading/src/service.ts
let fullscreenInstance = void 0;
const Loading = function(options = {}, context) {
if (!_vueuse_core.isClient) return void 0;
const resolved = resolveOptions(options);
if (resolved.fullscreen && fullscreenInstance) return fullscreenInstance;
const instance = require_loading.createLoadingComponent({
...resolved,
closed: () => {
resolved.closed?.();
if (resolved.fullscreen) fullscreenInstance = void 0;
}
}, context ?? Loading._context);
addStyle(resolved, resolved.parent, instance);
addClassList(resolved, resolved.parent, instance);
resolved.parent.vLoadingAddClassList = () => addClassList(resolved, resolved.parent, instance);
/**
* add loading-number to parent.
* because if a fullscreen loading is triggered when somewhere
* a v-loading.body was triggered before and it's parent is
* document.body which with a margin , the fullscreen loading's
* destroySelf function will remove 'el-loading-parent--relative',
* and then the position of v-loading.body will be error.
*/
let loadingNumber = resolved.parent.getAttribute("loading-number");
if (!loadingNumber) loadingNumber = "1";
else loadingNumber = `${Number.parseInt(loadingNumber) + 1}`;
resolved.parent.setAttribute("loading-number", loadingNumber);
resolved.parent.appendChild(instance.$el);
(0, vue.nextTick)(() => instance.visible.value = resolved.visible);
if (resolved.fullscreen) fullscreenInstance = instance;
return instance;
};
const resolveOptions = (options) => {
let target;
if ((0, _vue_shared.isString)(options.target)) target = document.querySelector(options.target) ?? document.body;
else target = options.target || document.body;
return {
parent: target === document.body || options.body ? document.body : target,
background: options.background || "",
svg: options.svg || "",
svgViewBox: options.svgViewBox || "",
spinner: options.spinner || false,
text: options.text || "",
fullscreen: target === document.body && (options.fullscreen ?? true),
lock: options.lock ?? false,
customClass: options.customClass || "",
visible: options.visible ?? true,
beforeClose: options.beforeClose,
closed: options.closed,
target
};
};
const addStyle = async (options, parent, instance) => {
const { nextZIndex } = instance.vm.zIndex || instance.vm._.exposed.zIndex;
const maskStyle = {};
if (options.fullscreen) {
instance.originalPosition.value = require_style.getStyle(document.body, "position");
instance.originalOverflow.value = require_style.getStyle(document.body, "overflow");
maskStyle.zIndex = nextZIndex();
} else if (options.parent === document.body) {
instance.originalPosition.value = require_style.getStyle(document.body, "position");
/**
* await dom render when visible is true in init,
* because some component's height maybe 0.
* e.g. el-table.
*/
await (0, vue.nextTick)();
for (const property of ["top", "left"]) {
const scroll = property === "top" ? "scrollTop" : "scrollLeft";
maskStyle[property] = `${options.target.getBoundingClientRect()[property] + document.body[scroll] + document.documentElement[scroll] - Number.parseInt(require_style.getStyle(document.body, `margin-${property}`), 10)}px`;
}
for (const property of ["height", "width"]) maskStyle[property] = `${options.target.getBoundingClientRect()[property]}px`;
} else instance.originalPosition.value = require_style.getStyle(parent, "position");
for (const [key, value] of Object.entries(maskStyle)) instance.$el.style[key] = value;
};
const addClassList = (options, parent, instance) => {
const ns = instance.vm.ns || instance.vm._.exposed.ns;
if (![
"absolute",
"fixed",
"sticky"
].includes(instance.originalPosition.value)) require_style.addClass(parent, ns.bm("parent", "relative"));
else require_style.removeClass(parent, ns.bm("parent", "relative"));
if (options.fullscreen && options.lock) require_style.addClass(parent, ns.bm("parent", "hidden"));
else require_style.removeClass(parent, ns.bm("parent", "hidden"));
};
Loading._context = null;
//#endregion
exports.default = Loading;
//# sourceMappingURL=service.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,51 @@
import { MaybeRef, VNode } from "vue";
//#region ../../packages/components/loading/src/types.d.ts
type LoadingOptionsResolved = {
parent: LoadingParentElement;
/**
* @description background color of the mask
*/
background: MaybeRef<string>;
svg: MaybeRef<string>;
svgViewBox: MaybeRef<string>;
/**
* @description class name of the custom spinner
*/
spinner: MaybeRef<boolean | string>;
/**
* @description loading text that displays under the spinner
*/
text: MaybeRef<string | VNode | VNode[]>;
/**
* @description same as the `fullscreen` modifier of `v-loading`
*/
fullscreen: boolean;
/**
* @description same as the `lock` modifier of `v-loading`
*/
lock: boolean;
/**
* @description custom class name for Loading
*/
customClass: MaybeRef<string>;
visible: boolean;
target: HTMLElement;
beforeClose?: () => boolean;
closed?: () => void;
};
type LoadingOptions = Partial<Omit<LoadingOptionsResolved, 'parent' | 'target'> & {
/**
* @description the DOM node Loading needs to cover. Accepts a DOM object or a string. If it's a string, it will be passed to `document.querySelector` to get the corresponding DOM node
*/
target: HTMLElement | string;
/**
* @description same as the `body` modifier of `v-loading`
*/
body: boolean;
}>;
interface LoadingParentElement extends HTMLElement {
vLoadingAddClassList?: () => void;
}
//#endregion
export { LoadingOptions, LoadingOptionsResolved, LoadingParentElement };

View File

@@ -0,0 +1 @@
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });

View File

@@ -0,0 +1,3 @@
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
require("../../base/style/css.js");
require("element-plus/theme-chalk/el-loading.css");

View File

@@ -0,0 +1,3 @@
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
require("../../base/style/index.js");
require("element-plus/theme-chalk/src/loading.scss");