refactor: remove Tiptap editor dependency and legacy JSON format support from wiki components

This commit is contained in:
taDuc
2026-05-15 00:04:44 +07:00
parent 57e3d6b3e5
commit 3682f25282
10 changed files with 30 additions and 1402 deletions
@@ -20,24 +20,6 @@ type Props = {
onWikiLinkRequest: (request: { slug: string; rect: DOMRect }) => void;
};
function isRecord(value: unknown): value is Record<string, unknown> {
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
}
function tiptapJsonToPlainText(node: unknown): string {
if (node == null) return "";
if (typeof node === "string") return node;
if (Array.isArray(node)) return node.map(tiptapJsonToPlainText).join("");
if (isRecord(node)) {
if (node.type === "text" && typeof node.text === "string") return node.text;
if (node.type === "hardBreak") return "\n";
if ("content" in node) return tiptapJsonToPlainText(node.content);
}
return "";
}
function escapeHtml(input: string): string {
return input
.replaceAll("&", "&amp;")
@@ -53,17 +35,6 @@ function normalizeWikiContentToHtml(raw: string | null | undefined): string {
if (value[0] === "<") return value;
if (value[0] === "{") {
try {
const json: unknown = JSON.parse(value);
const text = tiptapJsonToPlainText(json).trim();
if (!text.length) return "";
return `<p>${escapeHtml(text).replace(/\n/g, "<br/>")}</p>`;
} catch {
// fall through
}
}
return `<p>${escapeHtml(value).replace(/\n/g, "<br/>")}</p>`;
}