UNPKG

@feedma/vue-gen-ui-resolver

Version:
76 lines (75 loc) 2.67 kB
import { defineComponent as d, ref as p, defineAsyncComponent as u, createElementBlock as i, openBlock as m, createBlock as f, createElementVNode as l, toDisplayString as _, Suspense as g, withCtx as c, createVNode as v, unref as y, normalizeProps as h, guardReactiveProps as R } from "vue"; const C = { key: 0, class: "error" }, k = /* @__PURE__ */ d({ __name: "DynamicRemoteComponentLoader", props: { url: {}, name: {}, module: {}, props: {} }, setup(n) { const o = n, r = p(null), a = async () => { const e = await import("__federation__"); return e.__federation_method_getRemote && e.__federation_method_setRemote ? { getRemote: e.__federation_method_getRemote, setRemote: e.__federation_method_setRemote } : null; }, s = u( { loader: async () => { try { console.log("Loading remote component:", o.name, o.url, o.module); const e = await a(); if (!e) throw new Error( "Module federation is not configured. Please ensure @originjs/vite-plugin-federation is properly set up in your host application. The host application must configure the federation plugin and expose the federation runtime." ); e.setRemote(o.name, { url: () => Promise.resolve(o.url), format: "esm", from: "vite" }); const t = await e.getRemote(o.name, o.module); return console.log("Remote component loaded successfully"), t; } catch (e) { const t = e instanceof Error ? e.message : String(e); throw console.error("Error loading remote component:", e), r.value = t, e; } }, errorComponent: { template: '<div class="error">Failed to load remote component</div>' } } ); return (e, t) => (m(), i("div", null, [ r.value ? (m(), i("div", C, [ t[0] || (t[0] = l("h3", null, "Error loading remote component:", -1)), l("pre", null, _(r.value), 1) ])) : (m(), f(g, { key: 1 }, { default: c(() => [ v(y(s), h(R(o.props)), null, 16) ]), fallback: c(() => t[1] || (t[1] = [ l("div", null, "Loading remote component...", -1) ])), _: 1 })) ])); } }), w = (n, o) => { const r = n.__vccOpts || n; for (const [a, s] of o) r[a] = s; return r; }, x = /* @__PURE__ */ w(k, [["__scopeId", "data-v-196060d2"]]), L = { install(n) { n.component("DynamicRemoteComponentLoader", x); } }; export { x as DynamicRemoteComponentLoader, L as default };