UNPKG

jv3-loader

Version:

easy loading overlay by cdnagroup

57 lines (56 loc) 1.83 kB
import { defineComponent as l, computed as i, openBlock as c, createElementBlock as s, createCommentVNode as p, pushScopeId as u, popScopeId as g, createElementVNode as _, reactive as f, createApp as m, inject as v } from "vue"; const L = (e) => (u("data-v-a121654f"), e = e(), g(), e), h = { key: 0, class: "loading-overlay" }, C = /* @__PURE__ */ L(() => /* @__PURE__ */ _("div", { class: "spinner" }, null, -1)), b = [ C ], y = /* @__PURE__ */ l({ __name: "LoadingOverlay", setup(e) { const o = k(), t = i(() => o == null ? void 0 : o.isLoading); return (n, d) => t.value ? (c(), s("div", h, b)) : p("", !0); } }), E = (e, o) => { const t = e.__vccOpts || e; for (const [n, d] of o) t[n] = d; return t; }, I = /* @__PURE__ */ E(y, [["__scopeId", "data-v-a121654f"]]), a = f({ loadingCount: 0 }), r = { add(e) { a.loadingCount++, e().finally(() => { a.loadingCount--; }); }, get isLoading() { return a.loadingCount > 0; } }; function k() { const e = v("loader"); return e || console.error("Loader is not available"), e; } const S = { /** * Installs the loader plugin into a Vue application. * @param app - The Vue application instance. */ install(e) { e.config.globalProperties.$loader = r, e.provide("loader", r), window.addEventListener("load", () => { const o = document.getElementById("app"); if (o) { const t = document.createElement("div"); t.setAttribute("id", "global-loader"), o.appendChild(t); let n = m(I); n.config.globalProperties.$loader = e.config.globalProperties.$loader, n.provide("loader", r), n.mount("#global-loader"); } else console.error('Main app container with id "app" not found.'); }); } }; export { S as JV3Loader, S as default, k as useLoader };