feat(editor): save leptos island and page aggregate alignment progress

- switch main document flow toward leptos tiptap island host and generated runtime assets

- align page aggregate loading, page head single-source updates, and AI tool result recovery

- add tests and smoke scripts for title sync, AI route recovery, and editor host cutover
This commit is contained in:
lix-2026
2026-04-22 05:57:06 +08:00
parent 5d1c94eb9e
commit 8353aea2f9
105 changed files with 14768 additions and 4186 deletions
@@ -0,0 +1,115 @@
#!/usr/bin/env node
"use strict";
const fs = require("fs/promises");
const path = require("path");
const { spawnSync } = require("child_process");
const REPO_ROOT = path.resolve(__dirname, "..", "..");
const SPIKE_ROOT = path.join(REPO_ROOT, "rust", "spikes", "leptos-tiptap-spike");
const GENERATED_ROOT = path.join(SPIKE_ROOT, "generated", "island");
const TOOLCHAIN = "1.89.0-x86_64-unknown-linux-gnu";
const TARGET = "wasm32-unknown-unknown";
const OUT_NAME = "mnote-leptos-tiptap-spike-island";
const MANIFEST_PATH = path.join(SPIKE_ROOT, "Cargo.toml");
const WASM_PATH = path.join(
SPIKE_ROOT,
"target",
TARGET,
"debug",
"mnote_leptos_tiptap_spike.wasm",
);
const ENTRY_PATH = path.join(GENERATED_ROOT, `${OUT_NAME}.js`);
function run(command, args, options = {}) {
const result = spawnSync(command, args, {
cwd: options.cwd ?? REPO_ROOT,
env: process.env,
encoding: "utf8",
stdio: "pipe",
});
if (result.status === 0) {
return result;
}
const stdout = (result.stdout || "").trim();
const stderr = (result.stderr || "").trim();
const details = [stdout, stderr].filter(Boolean).join("\n");
throw new Error(
[`命令失败:${command} ${args.join(" ")}`, details].filter(Boolean).join("\n"),
);
}
async function ensureGeneratedDir() {
await fs.rm(GENERATED_ROOT, { recursive: true, force: true });
await fs.mkdir(GENERATED_ROOT, { recursive: true });
}
async function verifyEntry() {
const source = await fs.readFile(ENTRY_PATH, "utf8");
if (!source.includes("export function mount(container, options)")) {
throw new Error("island 入口缺少 mount 导出");
}
if (!source.includes("export function unmount(mount_id)")) {
throw new Error("island 入口缺少 unmount 导出");
}
}
async function buildLeptosTiptapIsland() {
// 说明:正式主链直接消费 lib.rs 的 wasm-bindgen 产物,不再把 trunk 演示页产物当作页面内 island 入口。
run("rustup", ["target", "add", TARGET, "--toolchain", TOOLCHAIN]);
run(
"cargo",
[
`+${TOOLCHAIN}`,
"build",
"--manifest-path",
MANIFEST_PATH,
"--lib",
"--target",
TARGET,
],
{ cwd: SPIKE_ROOT },
);
await ensureGeneratedDir();
run(
"wasm-bindgen",
[
WASM_PATH,
"--target",
"web",
"--out-dir",
GENERATED_ROOT,
"--out-name",
OUT_NAME,
],
{ cwd: SPIKE_ROOT },
);
await verifyEntry();
return {
generatedRoot: GENERATED_ROOT,
entryPath: ENTRY_PATH,
wasmPath: path.join(GENERATED_ROOT, `${OUT_NAME}_bg.wasm`),
};
}
module.exports = {
buildLeptosTiptapIsland,
GENERATED_ROOT,
OUT_NAME,
};
if (require.main === module) {
buildLeptosTiptapIsland()
.then(({ generatedRoot }) => {
process.stdout.write(`leptos-tiptap island 已生成:${generatedRoot}\n`);
})
.catch((error) => {
process.stderr.write(`${error instanceof Error ? error.stack ?? error.message : String(error)}\n`);
process.exit(1);
});
}
+15 -11
View File
@@ -12,11 +12,12 @@
* - ONLYOFFICE_INTERNAL_URL:可显式指定;未指定或失效时优先探测 8082,再回退 8081
*/
const http = require("http");
const net = require("net");
const path = require("path");
const next = require("next");
const { parse: parseUrl } = require("url");
const http = require("http");
const net = require("net");
const path = require("path");
const next = require("next");
const { parse: parseUrl } = require("url");
const { buildLeptosTiptapIsland } = require("./build-leptos-tiptap-island");
const ONLYOFFICE_PREFIX = "/onlyoffice-server";
const CONVEX_PREFIX = "/convex";
@@ -384,12 +385,15 @@ function proxyConvexHttp(req, res) {
req.pipe(upstreamReq);
}
async function main() {
const port = resolvePort();
const hostname = resolveHostname();
const dev = true;
const app = next({ dev, dir: path.join(__dirname, "..") });
async function main() {
const port = resolvePort();
const hostname = resolveHostname();
const dev = true;
// 说明:3000 主链需要直接挂载正式 Leptos island,因此在 Next dev 启动前先生成 lib.rs 的 wasm-bindgen 产物。
await buildLeptosTiptapIsland();
const app = next({ dev, dir: path.join(__dirname, "..") });
const handle = app.getRequestHandler();
await app.prepare();