feat: restore Wolai workspace navigation and assets
This commit is contained in:
@@ -15,7 +15,15 @@ function loadConversionRuntime() {
|
||||
const source = fs
|
||||
.readFileSync(RUNTIME_PATH, "utf8")
|
||||
.replace(/\bexport const\s+([A-Za-z0-9_]+)\s*=/g, "const $1 =");
|
||||
const sandbox = { console };
|
||||
const sandbox = {
|
||||
console,
|
||||
URL,
|
||||
window: {
|
||||
location: {
|
||||
origin: "http://127.0.0.1:3000",
|
||||
},
|
||||
},
|
||||
};
|
||||
vm.runInNewContext(
|
||||
`${source}\n;globalThis.__mnoteExports = { pageBodyTiptapDocumentSource, pageBodyTiptapDocument };`,
|
||||
sandbox,
|
||||
@@ -36,6 +44,10 @@ function taskItemChecked(doc) {
|
||||
return doc?.content?.[0]?.content?.[0]?.attrs?.checked;
|
||||
}
|
||||
|
||||
function firstLinkMarkAttrs(doc) {
|
||||
return doc?.content?.[0]?.content?.[0]?.marks?.find((mark) => mark.type === "link")?.attrs || {};
|
||||
}
|
||||
|
||||
const {
|
||||
pageBodyTiptapDocumentSource,
|
||||
pageBodyTiptapDocument,
|
||||
@@ -121,6 +133,93 @@ assert.equal(
|
||||
true,
|
||||
);
|
||||
|
||||
const localWithPdfAttachment = {
|
||||
projectionSource: "local_markdown.content",
|
||||
blockDocument: {
|
||||
documentId: "local-md:实验资料~2F核磁~2F核磁.md",
|
||||
rootBlockIds: ["pdf-1"],
|
||||
blocks: [{
|
||||
blockId: "pdf-1",
|
||||
type: "media",
|
||||
attrs: {
|
||||
name: "核磁常见杂质化学位移表.pdf",
|
||||
sourcePath: ".assets/file/核磁常见杂质化学位移表.pdf",
|
||||
},
|
||||
contentNodes: [{
|
||||
payload: {
|
||||
type: "text",
|
||||
text: "核磁常见杂质化学位移表.pdf",
|
||||
marks: [],
|
||||
},
|
||||
}],
|
||||
}],
|
||||
},
|
||||
content: [{
|
||||
id: "pdf-1",
|
||||
type: "media",
|
||||
props: {
|
||||
name: "核磁常见杂质化学位移表.pdf",
|
||||
sourcePath: ".assets/file/核磁常见杂质化学位移表.pdf",
|
||||
},
|
||||
}],
|
||||
attachmentRefs: [{
|
||||
rawHref: ".assets/file/核磁常见杂质化学位移表.pdf",
|
||||
normalizedHref: ".assets/file/核磁常见杂质化学位移表.pdf",
|
||||
label: "核磁常见杂质化学位移表.pdf",
|
||||
ext: "pdf",
|
||||
fileSize: 49510,
|
||||
exists: true,
|
||||
}],
|
||||
};
|
||||
const pdfLinkAttrs = firstLinkMarkAttrs(pageBodyTiptapDocument(localWithPdfAttachment, "", {
|
||||
sourceKind: "local_folder",
|
||||
rootUri: "file:///tmp/mnote-task522",
|
||||
documentId: "local-md:实验资料~2F核磁~2F核磁.md",
|
||||
}));
|
||||
const pdfOpenUrl = new URL(pdfLinkAttrs.href);
|
||||
assert.equal(pdfOpenUrl.pathname, "/api/local-folder/files/open");
|
||||
assert.equal(pdfOpenUrl.searchParams.get("rootUri"), "file:///tmp/mnote-task522");
|
||||
assert.equal(
|
||||
pdfOpenUrl.searchParams.get("path"),
|
||||
"实验资料/核磁/.assets/file/核磁常见杂质化学位移表.pdf",
|
||||
);
|
||||
assert.ok(pdfLinkAttrs.class.includes("mnote-uploaded-attachment-pdf"));
|
||||
assert.equal(pdfLinkAttrs["data-file-size"], "48.35 KB");
|
||||
|
||||
const localWithPageReference = {
|
||||
projectionSource: "local_markdown.content",
|
||||
blockDocument: {
|
||||
documentId: "local-md:liaibo~2F项目~2F项目.md",
|
||||
rootBlockIds: ["page-ref-1"],
|
||||
blocks: [{
|
||||
blockId: "page-ref-1",
|
||||
type: "page_reference",
|
||||
attrs: {
|
||||
title: "完结项目",
|
||||
sourcePath: "liaibo/项目/完结项目/完结项目.md",
|
||||
},
|
||||
contentNodes: [{
|
||||
payload: {
|
||||
type: "text",
|
||||
text: "完结项目",
|
||||
marks: [],
|
||||
},
|
||||
}],
|
||||
}],
|
||||
},
|
||||
};
|
||||
const pageRefMarkAttrs = firstLinkMarkAttrs(pageBodyTiptapDocument(localWithPageReference, "", {
|
||||
sourceKind: "local_folder",
|
||||
rootUri: "file:///tmp/mnote-task522",
|
||||
documentId: "local-md:liaibo~2F项目~2F项目.md",
|
||||
}));
|
||||
assert.equal(pageRefMarkAttrs.class, "mnote-page-block-link");
|
||||
assert.equal(pageRefMarkAttrs.target, "_self");
|
||||
assert.ok(pageRefMarkAttrs.href.startsWith("/documents/local-md:liaibo"));
|
||||
const pageRefUrl = new URL(pageRefMarkAttrs.href, "http://127.0.0.1:3000");
|
||||
assert.equal(pageRefUrl.searchParams.get("sourceKind"), "local_folder");
|
||||
assert.equal(pageRefUrl.searchParams.get("rootUri"), "file:///tmp/mnote-task522");
|
||||
|
||||
const localLegacyOnly = {
|
||||
projectionSource: "local_markdown.content",
|
||||
content: legacyContent,
|
||||
|
||||
Reference in New Issue
Block a user