Convert the bundled backend/internal/plugins/smartblock package into a standalone reactor-mode wasm plugin: - package smartblock -> package main; add wasip1 main.go with wasmguest.Serve(Registration). - Add go.mod (module git.dev.alexdunmow.com/block/smartblock) pinning block/core v0.18.2; no replace directives. - Flesh out plugin.mod (scope=ninja, kind=plugin, categories, tags, display_name, description). - Point web/eslint.config.js at ../../../cms/web/eslint.config.js and switch @block-ninja/ui from workspace:* to the ^0.1.0 registry version; rebuild web/dist. - Add .gitignore (*.bnp, *.wasm, web/node_modules). Behavior unchanged: registers the "smart" block; assets served from web/dist. Builds to smartblock-1.0.0.bnp; check-safety passes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
85 lines
2.8 KiB
JavaScript
85 lines
2.8 KiB
JavaScript
const currentImports = {};
|
|
const exportSet = new Set(["Module", "__esModule", "default", "_export_sfc"]);
|
|
let moduleMap = {
|
|
"./editor": () => {
|
|
dynamicLoadingCss(["style-Bs2zy9jQ.css"], false, "./editor");
|
|
return __federation_import("./__federation_expose_Editor-5Sa5G2Fp.js").then((module) => (Object.keys(module).every((item) => exportSet.has(item)) ? () => module.default : () => module));
|
|
},
|
|
};
|
|
const seen = {};
|
|
const dynamicLoadingCss = (cssFilePaths, dontAppendStylesToHead, exposeItemName) => {
|
|
const metaUrl = import.meta.url;
|
|
if (typeof metaUrl === "undefined") {
|
|
console.warn('The remote style takes effect only when the build.target option in the vite.config.ts file is higher than that of "es2020".');
|
|
return;
|
|
}
|
|
|
|
const curUrl = metaUrl.substring(0, metaUrl.lastIndexOf("remoteEntry.js"));
|
|
const base = "/";
|
|
("assets");
|
|
|
|
cssFilePaths.forEach((cssPath) => {
|
|
let href = "";
|
|
const baseUrl = base || curUrl;
|
|
if (baseUrl) {
|
|
const trimmer = {
|
|
trailing: (path) => (path.endsWith("/") ? path.slice(0, -1) : path),
|
|
leading: (path) => (path.startsWith("/") ? path.slice(1) : path),
|
|
};
|
|
const isAbsoluteUrl = (url) => url.startsWith("http") || url.startsWith("//");
|
|
|
|
const cleanBaseUrl = trimmer.trailing(baseUrl);
|
|
const cleanCssPath = trimmer.leading(cssPath);
|
|
const cleanCurUrl = trimmer.trailing(curUrl);
|
|
|
|
if (isAbsoluteUrl(baseUrl)) {
|
|
href = [cleanBaseUrl, cleanCssPath].filter(Boolean).join("/");
|
|
} else {
|
|
if (cleanCurUrl.includes(cleanBaseUrl)) {
|
|
href = [cleanCurUrl, cleanCssPath].filter(Boolean).join("/");
|
|
} else {
|
|
href = [cleanCurUrl + cleanBaseUrl, cleanCssPath].filter(Boolean).join("/");
|
|
}
|
|
}
|
|
} else {
|
|
href = cssPath;
|
|
}
|
|
|
|
if (dontAppendStylesToHead) {
|
|
const key = "css__smartblock__" + exposeItemName;
|
|
window[key] = window[key] || [];
|
|
window[key].push(href);
|
|
return;
|
|
}
|
|
|
|
if (href in seen) return;
|
|
seen[href] = true;
|
|
|
|
const element = document.createElement("link");
|
|
element.rel = "stylesheet";
|
|
element.href = href;
|
|
document.head.appendChild(element);
|
|
});
|
|
};
|
|
async function __federation_import(name) {
|
|
currentImports[name] ??= import(name);
|
|
return currentImports[name];
|
|
}
|
|
const get = (module) => {
|
|
if (!moduleMap[module]) throw new Error("Can not find remote module " + module);
|
|
return moduleMap[module]();
|
|
};
|
|
const init = (shareScope) => {
|
|
globalThis.__federation_shared__ = globalThis.__federation_shared__ || {};
|
|
Object.entries(shareScope).forEach(([key, value]) => {
|
|
for (const [versionKey, versionValue] of Object.entries(value)) {
|
|
const scope = versionValue.scope || "default";
|
|
globalThis.__federation_shared__[scope] = globalThis.__federation_shared__[scope] || {};
|
|
const shared = globalThis.__federation_shared__[scope];
|
|
(shared[key] = shared[key] || {})[versionKey] = versionValue;
|
|
}
|
|
});
|
|
};
|
|
|
|
export { dynamicLoadingCss, get, init };
|