AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
feat(web): add GitHub-style details fold blocks (#418)
tianma-ife0a2f3844732
diff --git a/apps/ios/EditorSource/bun.lock b/apps/ios/EditorSource/bun.lockindex 81020d44..da3b1f9a 100644--- a/apps/ios/EditorSource/bun.lock+++ b/apps/ios/EditorSource/bun.lock@@ -9,6 +9,7 @@"@edgeever/shared": "file:../../../packages/shared","@tiptap/core": "3.31.0","@tiptap/extension-code-block": "3.31.0",+ "@tiptap/extension-details": "3.31.0","@tiptap/extension-image": "3.31.0","@tiptap/extension-list": "3.31.0","@tiptap/extension-mathematics": "3.31.0",@@ -163,6 +164,8 @@"@tiptap/extension-code-block": ["@tiptap/[email protected]", "", { "peerDependencies": { "@tiptap/core": "3.31.0", "@tiptap/pm": "3.31.0" } }, "sha512-y/A6N96gBPjEHqVYZ3u/yO/Anyo92iDWgYqShMXAvHprn2Ipmn32wIkX05Kv983fa6j6ySXF7A1nJdHcGCl5aQ=="],+ "@tiptap/extension-details": ["@tiptap/[email protected]", "", { "peerDependencies": { "@tiptap/core": "3.31.0", "@tiptap/extension-text-style": "3.31.0", "@tiptap/pm": "3.31.0" } }, "sha512-j1ZDrXRPPvCoOrKrVV1e2BXFpHVsHYmikr2ORtI0+gDh/+4qruqrm7ftGic2lm77B2hzKtm2adoSSi9XL6UQew=="],+"@tiptap/extension-document": ["@tiptap/[email protected]", "", { "peerDependencies": { "@tiptap/core": "3.31.0" } }, "sha512-C2eDFoBlcRAb4sgbc9ZH+mrFFbjIS9VyoERGeDum3QRdqLEKU1h14Th7isHpGQzTvTywhXQxqXC64mgeSGXLsA=="],"@tiptap/extension-dropcursor": ["@tiptap/[email protected]", "", { "peerDependencies": { "@tiptap/extensions": "3.31.0" } }, "sha512-hIZOPfM0sGkAhPV69IK1zWMbWBd3wmhS0XCKBRcXUWrE2MW4kkaSyYprSFqtqFuUa3lVIEFrlME1WOEBJ2/2rg=="],@@ -201,6 +204,8 @@"@tiptap/extension-text": ["@tiptap/[email protected]", "", { "peerDependencies": { "@tiptap/core": "3.31.0" } }, "sha512-K+8nIKgNNBiL1+AarcuzvPoRpjuFk5qOe9MM/n9O3HyTTLeWNfRV/zFifcpSoHmhf0QvEAXqmnxDiIpyCpy9+g=="],+ "@tiptap/extension-text-style": ["@tiptap/[email protected]", "", { "peerDependencies": { "@tiptap/core": "3.31.0" } }, "sha512-eY8mIb/NS22sO1xJQqfzHtSdpL2UCQy1nbSCEohRUoW7eaP/nwp29x097+jjJnxg4LjLMsolyw11Q4mswbXDQQ=="],+"@tiptap/extension-underline": ["@tiptap/[email protected]", "", { "peerDependencies": { "@tiptap/core": "3.31.0" } }, "sha512-B4VK5nu0UdKl7OiMvIcjDPMYmhe8+v1B763Is/GzPSJOMstUHRqAqPx2AsPla6A4UGuZwTx//ajVa5QAGionZQ=="],"@tiptap/extensions": ["@tiptap/[email protected]", "", { "peerDependencies": { "@tiptap/core": "3.31.0", "@tiptap/pm": "3.31.0" } }, "sha512-WOv9Y1VjhzAYycrIGPygwmLkoO/UdFYFE5uDWN+FJWMui5sLmLrmfKtOOYzeWIevxomFGix/wl5hqaVGIev1+g=="],diff --git a/apps/ios/EditorSource/package.json b/apps/ios/EditorSource/package.jsonindex 8e5883d1..43f592da 100644--- a/apps/ios/EditorSource/package.json+++ b/apps/ios/EditorSource/package.json@@ -13,6 +13,7 @@"@edgeever/shared": "file:../../../packages/shared","@tiptap/core": "3.31.0","@tiptap/extension-code-block": "3.31.0",+ "@tiptap/extension-details": "3.31.0","@tiptap/extension-image": "3.31.0","@tiptap/extension-list": "3.31.0","@tiptap/extension-mathematics": "3.31.0",diff --git a/apps/ios/EditorSource/src/main.ts b/apps/ios/EditorSource/src/main.tsindex f90322dc..f310ec09 100644--- a/apps/ios/EditorSource/src/main.ts+++ b/apps/ios/EditorSource/src/main.ts@@ -13,6 +13,7 @@ import { toCanvas } from "html-to-image";import {createEdgeEverDocumentExtensions,createNativeUnsupportedContentExtensions,+ DETAILS_EDITOR_CSS,diagramDocumentToX6Cells,attachDiagramReader,MIND_MAP_CONNECTOR_NAME,@@ -25,6 +26,7 @@ import {resolveAttachmentKind,resolveNativeAttachmentContent,restoreNativeEditorContent,+ wrapDetailsContentHtml,type TiptapDoc,type DiagramDocument,} from "@edgeever/shared";@@ -49,6 +51,10 @@ const galleryStyle = document.createElement("style");galleryStyle.textContent = NATIVE_IMAGE_GALLERY_CSS;document.head.append(galleryStyle);+const detailsStyle = document.createElement("style");+detailsStyle.textContent = DETAILS_EDITOR_CSS;+document.head.append(detailsStyle);+Graph.registerConnector(MIND_MAP_CONNECTOR_NAME, mindMapConnector, true);type BridgeMessage =@@ -785,6 +791,9 @@ const editor = new Editor({class: "edgeever-prose",spellcheck: "true",},+ transformPastedHTML(html) {+ return wrapDetailsContentHtml(html);+ },handleClick(_view, _pos, event) {return handleResourcePointer(event as MouseEvent, "click");},diff --git a/apps/mobile/src/components/LocalTiptapEditor.tsx b/apps/mobile/src/components/LocalTiptapEditor.tsxindex 6eed6e3b..a38a8452 100644--- a/apps/mobile/src/components/LocalTiptapEditor.tsx+++ b/apps/mobile/src/components/LocalTiptapEditor.tsx@@ -28,6 +28,8 @@ import {markdownToDoc,MEMO_CONTENT_STYLE,createEdgeEverDocumentExtensions,+ DETAILS_EDITOR_CSS,+ wrapDetailsContentHtml,NativeAttachmentMetadata,normalizeAiSelectionReplacement,prepareNativeEditorContent,@@ -795,6 +797,7 @@ function LocalTiptapEditorImpl(props: LocalTiptapEditorProps) {attributes: getMobileEditorInputAttributes(isViewer ? "edgeever-editor-content edgeever-viewer-content" : "edgeever-editor-content"),+ transformPastedHTML: (html) => wrapDetailsContentHtml(html),handleDOMEvents: {// Intercept attachment anchors before ProseMirror's later click phase so// the embedded file:// WebView never follows relative resource URLs.@@ -3199,6 +3202,7 @@ const getEditorStyles = (theme: "light" | "dark", options?: { viewer?: boolean }font-size: 12px;font-weight: 600;}+ ${DETAILS_EDITOR_CSS}.edgeever-editor-content .edgeever-unsupported-content--block { display: block; margin: 8px 0; padding: 12px; }.edgeever-editor-content .edgeever-unsupported-content--inline { display: inline-block; margin: 0 2px; padding: 2px 6px; }.edgeever-editor-content .edgeever-unsupported-mark { border-bottom: 1px dashed ${theme === "dark" ? "#94a3b8" : "#64748b"}; }diff --git a/apps/web/src/components/EditorPane.tsx b/apps/web/src/components/EditorPane.tsxindex b3e655bd..3093af15 100644--- a/apps/web/src/components/EditorPane.tsx+++ b/apps/web/src/components/EditorPane.tsx@@ -112,6 +112,7 @@ import {normalizeImageGalleries,PLUGIN_EMBED_NODE_TYPE,pluginEmbedToMarkdown,+ wrapDetailsContentHtml,isPdfAttachment,resolveMemoContentDoc,type Notebook,@@ -609,6 +610,7 @@ const RichEditorPane = ({blockquote: "","code-block": "",divider: "",+ fold: "",table: "","current-date": "","current-time": "",@@ -642,6 +644,7 @@ const RichEditorPane = ({blockquote: t("editorToolbar.quote"),"code-block": t("editorToolbar.codeBlock"),divider: t("editorToolbar.horizontalRule"),+ fold: t("editorToolbar.fold"),table: t("editorToolbar.table"),"current-date": t("slashMenu.items.currentDate"),"current-time": t("slashMenu.items.currentTime"),@@ -1200,6 +1203,7 @@ const RichEditorPane = ({}return true;},+ transformPastedHTML: (html) => wrapDetailsContentHtml(html),handlePaste: (_view, event) => {const files = getResourceFilesFromDataTransfer(event.clipboardData);diff --git a/apps/web/src/components/MobileStandaloneTiptapEditor.tsx b/apps/web/src/components/MobileStandaloneTiptapEditor.tsxindex 84c7b83d..42dae88c 100644--- a/apps/web/src/components/MobileStandaloneTiptapEditor.tsx+++ b/apps/web/src/components/MobileStandaloneTiptapEditor.tsx@@ -7,7 +7,7 @@ import { FileAttachment } from "@/components/editor/FileAttachment";import Image from "@tiptap/extension-image";import { mergeAttributes } from "@tiptap/core";import Placeholder from "@tiptap/extension-placeholder";-import { createExcerpt, createEdgeEverDocumentExtensions, docToMarkdown, docToText, emptyDoc, getImageReferrerPolicy, isPdfAttachment, type MemoDetail, type MemoEditSession, type Notebook, type TagSummary, type TiptapDoc } from "@edgeever/shared";+import { createExcerpt, createEdgeEverDocumentExtensions, docToMarkdown, docToText, emptyDoc, getImageReferrerPolicy, isPdfAttachment, wrapDetailsContentHtml, type MemoDetail, type MemoEditSession, type Notebook, type TagSummary, type TiptapDoc } from "@edgeever/shared";import { createEdgeEverMathematics } from "@edgeever/shared/mathematics";import { getMobileEditorInputAttributes, getMobileEditorPlaceholder } from "@edgeever/shared/mobile-editor";import { EdgeEverLink } from "@edgeever/shared/editor-link";@@ -217,6 +217,7 @@ export const MobileStandaloneTiptapEditor = ({content: emptyDoc(),editorProps: {attributes: getMobileEditorInputAttributes("edgeever-mobile-tiptap-content"),+ transformPastedHTML: (html) => wrapDetailsContentHtml(html),handleKeyDown: (view, event) => {if (event.key !== "Backspace" || !preserveEmptyListIndentOnBackspace(view.state, view.dispatch)) {return false;diff --git a/apps/web/src/components/editor/SlashCommandMenu.test.mjs b/apps/web/src/components/editor/SlashCommandMenu.test.mjsindex 94ba675c..7271b979 100644--- a/apps/web/src/components/editor/SlashCommandMenu.test.mjs+++ b/apps/web/src/components/editor/SlashCommandMenu.test.mjs@@ -27,6 +27,7 @@ const labels = {blockquote: "引用","code-block": "代码块",divider: "分割线",+ fold: "折叠块",table: "表格","current-date": "当前日期","current-time": "当前时间",@@ -44,7 +45,7 @@ describe("slash command menu", () => {const unfilteredItems = filterSlashCommandItems(items, "");const heading6Index = unfilteredItems.findIndex((item) => item.id === "heading-6");- expect(unfilteredItems).toHaveLength(21);+ expect(unfilteredItems).toHaveLength(22);expect(unfilteredItems.slice(heading6Index + 1, heading6Index + 4).map((item) => item.id)).toEqual(["current-date","current-time",@@ -80,6 +81,7 @@ describe("slash command menu", () => {"quote","code","divider",+ "fold","table","upload","note",@@ -87,6 +89,8 @@ describe("slash command menu", () => {]);expect(items.every((item) => /^[a-z][a-z0-9]*$/.test(item.command))).toBe(true);expect(new Set(items.map((item) => item.command)).size).toBe(items.length);+ expect(filterSlashCommandItems(items, "折叠").map((item) => item.id)).toEqual(["fold"]);+ expect(filterSlashCommandItems(items, "collapse").map((item) => item.id)).toEqual(["fold"]);expect(filterSlashCommandItems(items, "table").map((item) => item.id)).toEqual(["table"]);expect(filterSlashCommandItems(items, "task").map((item) => item.id)).toEqual(["task-list"]);});diff --git a/apps/web/src/components/editor/SlashCommandMenu.tsx b/apps/web/src/components/editor/SlashCommandMenu.tsxindex 77cd98ad..56bdc262 100644--- a/apps/web/src/components/editor/SlashCommandMenu.tsx+++ b/apps/web/src/components/editor/SlashCommandMenu.tsx@@ -9,6 +9,7 @@ import {Braces,CalendarClock,CalendarDays,+ ChevronsDownUp,Clock3,FileUp,Heading1,@@ -50,6 +51,7 @@ export type SlashCommandId =| "blockquote"| "code-block"| "divider"+ | "fold"| "table"| "current-date"| "current-time"@@ -116,6 +118,7 @@ export const createSlashCommandItems = (labels: SlashCommandLabels): SlashComman{ id: "blockquote", command: "quote", group: "basic", icon: Quote, label: labels.items.blockquote, keywords: ["引用"] },{ id: "code-block", command: "code", group: "basic", icon: Braces, label: labels.items["code-block"], keywords: ["代码"] },{ id: "divider", command: "divider", group: "insert", icon: BetweenHorizontalStart, label: labels.items.divider, keywords: ["rule", "分割", "分隔"] },+ { id: "fold", command: "fold", group: "insert", icon: ChevronsDownUp, label: labels.items.fold, keywords: ["collapse", "spoiler", "折叠", "折りたたみ"] },{ id: "table", command: "table", group: "insert", icon: Table2, label: labels.items.table, keywords: ["表格"] },{ id: "attachment", command: "upload", group: "insert", icon: FileUp, label: labels.items.attachment, keywords: ["file", "attachment", "文件", "上传", "附件"] },{ id: "note-link", command: "note", group: "insert", icon: Link, label: labels.items["note-link"], keywords: ["link", "memo", "笔记", "引用"] },@@ -243,6 +246,7 @@ const runSlashCommand = ({case "blockquote": chain.toggleBlockquote().run(); break;case "code-block": chain.setCodeBlock().run(); break;case "divider": chain.setHorizontalRule().run(); break;+ case "fold": chain.setDetails().run(); break;case "table": chain.insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run(); break;case "current-date": chain.insertContent(formatCurrentDate(new Date())).run(); break;case "current-time": chain.insertContent(formatCurrentTime(new Date())).run(); break;diff --git a/apps/web/src/lib/wechat-copy.ts b/apps/web/src/lib/wechat-copy.tsindex 7bd9af02..31aa53e2 100644--- a/apps/web/src/lib/wechat-copy.ts+++ b/apps/web/src/lib/wechat-copy.ts@@ -1,5 +1,5 @@import type { Editor } from "@tiptap/react";-import { MEMO_CONTENT_STYLE } from "@edgeever/shared";+import { flattenDetailsForLinearHtml, MEMO_CONTENT_STYLE } from "@edgeever/shared";import { marked } from "marked";import { MERMAID_THEME_PALETTES } from "@/components/ThemeProvider";import { copyHtmlToClipboard } from "@/lib/clipboard";@@ -490,6 +490,7 @@ export const preparePublishArticle = (context.customColors,context.customCss,);+ flattenDetailsForLinearHtml(root);convertImageGalleriesForWeChat(root);return root;};diff --git a/apps/web/src/styles/globals.css b/apps/web/src/styles/globals.cssindex 2b8c9de9..ea313d1f 100644--- a/apps/web/src/styles/globals.css+++ b/apps/web/src/styles/globals.css@@ -694,6 +694,66 @@ textarea {white-space: pre-wrap;}+.ProseMirror [data-type="details"] {+ display: flex;+ align-items: flex-start;+ gap: 0.2rem;+ margin: 0.7em 0;+ padding: 0.45rem 0.7rem 0.55rem 0.3rem;+ border: 1px solid color-mix(in srgb, currentColor 14%, transparent);+ border-radius: 10px;+ background: color-mix(in srgb, currentColor 4%, transparent);+}++.ProseMirror [data-type="details"] > button {+ flex: 0 0 auto;+ width: 1.55rem;+ height: 1.55rem;+ margin-top: 0.05rem;+ padding: 0;+ border: 0;+ border-radius: 999px;+ background: transparent;+ color: #16a06e;+ cursor: pointer;+}++.ProseMirror [data-type="details"] > button::before {+ content: "";+ display: block;+ width: 0.42rem;+ height: 0.42rem;+ margin: 0.38rem auto 0;+ border-right: 2px solid currentColor;+ border-bottom: 2px solid currentColor;+ transform: rotate(-45deg);+}++.ProseMirror [data-type="details"].is-open > button::before {+ margin-top: 0.22rem;+ transform: rotate(45deg);+}++.ProseMirror [data-type="details"] > div {+ flex: 1;+ min-width: 0;+}++.ProseMirror summary {+ display: block;+ font-weight: 650;+ list-style: none;+ cursor: text;+}++.ProseMirror summary::-webkit-details-marker {+ display: none;+}++.ProseMirror [data-type="detailsContent"] {+ margin-top: 0.35rem;+}+.edgeever-public-share .ProseMirror {min-height: 0;padding: 8px 20px 40px;diff --git a/apps/web/src/styles/note-html-export.css b/apps/web/src/styles/note-html-export.cssindex cb9b6108..64e5c9bb 100644--- a/apps/web/src/styles/note-html-export.css+++ b/apps/web/src/styles/note-html-export.css@@ -144,6 +144,23 @@ body {padding-left: 1.5rem;}+.edgeever-html-content details {+ margin: 0.75rem 0;+ padding: 0.55rem 0.85rem;+ border: 1px solid #d1d5db;+ border-radius: 8px;+ background: #f8fafc;+}++.edgeever-html-content summary {+ font-weight: 650;+ cursor: pointer;+}++.edgeever-html-content details > :not(summary) {+ margin-top: 0.5rem;+}+.edgeever-html-content blockquote {margin: 1rem 0;border-left: 4px solid #10b981;diff --git a/apps/web/src/styles/note-print.css b/apps/web/src/styles/note-print.cssindex ae2f03c8..c6160eca 100644--- a/apps/web/src/styles/note-print.css+++ b/apps/web/src/styles/note-print.css@@ -270,6 +270,24 @@font-weight: 700;}+.edgeever-print-content details {+ break-inside: avoid-page;+ margin: 4mm 0;+ padding: 3mm 3.5mm;+ border: 0.3mm solid #cbd5e1;+ border-radius: 2mm;+}++.edgeever-print-content summary {+ font-weight: 700;+}++.edgeever-print-content details > :not(summary),+.edgeever-print-content [data-type="detailsContent"],+.edgeever-print-content [data-type="detailsContent"][hidden] {+ display: block !important;+}+.edgeever-print-content [data-edgeever-theme-block] {break-inside: avoid-page;margin: 5mm 0;diff --git a/bun.lock b/bun.lockindex fbb9dce5..59e08043 100644--- a/bun.lock+++ b/bun.lock@@ -25,6 +25,7 @@"@tanstack/react-query": "latest","@tanstack/react-virtual": "^3.14.13","@tiptap/core": "3.31.0",+ "@tiptap/extension-details": "3.31.0","@tiptap/extension-image": "3.31.0","@tiptap/extension-list": "3.31.0","@tiptap/extension-placeholder": "3.31.0",@@ -96,7 +97,7 @@},"apps/desktop": {"name": "@edgeever/desktop",- "version": "1.77.0",+ "version": "1.78.1","dependencies": {"@edgeever/public-network": "workspace:*","croner": "^10.0.1",@@ -260,6 +261,7 @@"dependencies": {"@dagrejs/dagre": "3.1.1","@tiptap/core": "3.31.0",+ "@tiptap/extension-details": "3.31.0","@tiptap/extension-image": "3.31.0","@tiptap/extension-link": "3.31.0","@tiptap/extension-list": "3.31.0",@@ -1375,6 +1377,8 @@"@tiptap/extension-code-block-lowlight": ["@tiptap/[email protected]", "", { "peerDependencies": { "@tiptap/core": "3.31.0", "@tiptap/extension-code-block": "3.31.0", "@tiptap/pm": "3.31.0", "highlight.js": "^11", "lowlight": "^2 || ^3" } }, "sha512-fFwXqwh0CwJkQzdqgv4ObcS70m0Muq1RbAZUTQNZFqCDcu1krDJW0PWNmua7+nZdmXwOyA2PDUTAtWYFQ+srpw=="],+ "@tiptap/extension-details": ["@tiptap/[email protected]", "", { "peerDependencies": { "@tiptap/core": "3.31.0", "@tiptap/extension-text-style": "3.31.0", "@tiptap/pm": "3.31.0" } }, "sha512-j1ZDrXRPPvCoOrKrVV1e2BXFpHVsHYmikr2ORtI0+gDh/+4qruqrm7ftGic2lm77B2hzKtm2adoSSi9XL6UQew=="],+"@tiptap/extension-document": ["@tiptap/[email protected]", "", { "peerDependencies": { "@tiptap/core": "3.31.0" } }, "sha512-C2eDFoBlcRAb4sgbc9ZH+mrFFbjIS9VyoERGeDum3QRdqLEKU1h14Th7isHpGQzTvTywhXQxqXC64mgeSGXLsA=="],"@tiptap/extension-dropcursor": ["@tiptap/[email protected]", "", { "peerDependencies": { "@tiptap/extensions": "3.31.0" } }, "sha512-hIZOPfM0sGkAhPV69IK1zWMbWBd3wmhS0XCKBRcXUWrE2MW4kkaSyYprSFqtqFuUa3lVIEFrlME1WOEBJ2/2rg=="],@@ -1415,6 +1419,8 @@"@tiptap/extension-text": ["@tiptap/[email protected]", "", { "peerDependencies": { "@tiptap/core": "3.31.0" } }, "sha512-K+8nIKgNNBiL1+AarcuzvPoRpjuFk5qOe9MM/n9O3HyTTLeWNfRV/zFifcpSoHmhf0QvEAXqmnxDiIpyCpy9+g=="],+ "@tiptap/extension-text-style": ["@tiptap/[email protected]", "", { "peerDependencies": { "@tiptap/core": "3.31.0" } }, "sha512-eY8mIb/NS22sO1xJQqfzHtSdpL2UCQy1nbSCEohRUoW7eaP/nwp29x097+jjJnxg4LjLMsolyw11Q4mswbXDQQ=="],+"@tiptap/extension-underline": ["@tiptap/[email protected]", "", { "peerDependencies": { "@tiptap/core": "3.31.0" } }, "sha512-B4VK5nu0UdKl7OiMvIcjDPMYmhe8+v1B763Is/GzPSJOMstUHRqAqPx2AsPla6A4UGuZwTx//ajVa5QAGionZQ=="],"@tiptap/extensions": ["@tiptap/[email protected]", "", { "peerDependencies": { "@tiptap/core": "3.31.0", "@tiptap/pm": "3.31.0" } }, "sha512-WOv9Y1VjhzAYycrIGPygwmLkoO/UdFYFE5uDWN+FJWMui5sLmLrmfKtOOYzeWIevxomFGix/wl5hqaVGIev1+g=="],diff --git a/package.json b/package.jsonindex aca8e102..96bbefb1 100644--- a/package.json+++ b/package.json@@ -137,6 +137,7 @@"@tanstack/react-query": "latest","@tanstack/react-virtual": "^3.14.13","@tiptap/core": "3.31.0",+ "@tiptap/extension-details": "3.31.0","@tiptap/extension-image": "3.31.0","@tiptap/extension-list": "3.31.0","@tiptap/extension-placeholder": "3.31.0",diff --git a/packages/shared/package.json b/packages/shared/package.jsonindex 4c893202..95fefe64 100644--- a/packages/shared/package.json+++ b/packages/shared/package.json@@ -24,6 +24,7 @@"dependencies": {"@dagrejs/dagre": "3.1.1","@tiptap/core": "3.31.0",+ "@tiptap/extension-details": "3.31.0","@tiptap/extension-image": "3.31.0","@tiptap/extension-link": "3.31.0","@tiptap/extension-list": "3.31.0",diff --git a/packages/shared/src/content.test.mjs b/packages/shared/src/content.test.mjsindex 6295f00c..f25a59c4 100644--- a/packages/shared/src/content.test.mjs+++ b/packages/shared/src/content.test.mjs@@ -411,6 +411,91 @@ describe("Theme block compatibility", () => {});});+describe("details fold blocks", () => {+ test("parses GitHub details HTML and round-trips through Markdown", () => {+ const markdown = `<details>+<summary>展开看图</summary>++hello **world**++</details>`;+ const doc = markdownToDoc(markdown);++ expect(doc.content[0]).toMatchObject({+ type: "details",+ content: [+ {+ type: "detailsSummary",+ content: [{ type: "text", text: "展开看图" }],+ },+ {+ type: "detailsContent",+ content: [{+ type: "paragraph",+ content: [+ { type: "text", text: "hello " },+ { type: "text", text: "world", marks: [{ type: "bold" }] },+ ],+ }],+ },+ ],+ });++ const serialized = docToMarkdown(doc);+ expect(serialized).toContain("<details>");+ expect(serialized).toContain("<summary>展开看图</summary>");+ expect(serialized).toContain("hello **world**");+ expect(markdownToDoc(serialized)).toEqual(doc);+ });++ test("converts an HTML image inside details into an image node", () => {+ const markdown = `<details>+<summary> </summary>+<img src="https://example.com/a.png" alt="pic" title="t" />+</details>`;+ const doc = markdownToDoc(markdown);+ expect(doc.content[0]?.content?.[1]?.content?.[0]).toMatchObject({+ type: "image",+ attrs: { src: "https://example.com/a.png", alt: "pic", title: "t" },+ });+ expect(docToMarkdown(doc)).toContain("");+ });++ test("keeps an image inside a details block", () => {+ const markdown = `<details>+<summary>图</summary>++++</details>`;+ const doc = markdownToDoc(markdown);+ expect(doc.content[0]?.type).toBe("details");+ expect(doc.content[0]?.content?.[1]?.content?.[0]).toMatchObject({+ type: "image",+ attrs: { src: "https://example.com/a.png", alt: "pic" },+ });+ expect(docToMarkdown(doc)).toContain("");+ });++ test("recovers details from Markdown when JSON only kept the tags as text", () => {+ const markdown = `<details>+<summary>提示</summary>++hidden++</details>`;+ const legacyDoc = {+ type: "doc",+ content: [{+ type: "paragraph",+ content: [{ type: "text", text: markdown }],+ }],+ };++ expect(resolveMemoContentDoc(legacyDoc, markdown).content[0]?.type).toBe("details");+ });+});+describe("extra blank lines", () => {test("keeps two visual blank lines as an empty paragraph", () => {const doc = markdownToDoc("A\n\n\nB");diff --git a/packages/shared/src/content.ts b/packages/shared/src/content.tsindex f892f3a3..4e8f8a6f 100644--- a/packages/shared/src/content.ts+++ b/packages/shared/src/content.ts@@ -169,6 +169,7 @@ export const resolveMemoContentDoc = (docContainsNodeType(currentDoc, INLINE_MATH_NODE_TYPE)|| docContainsNodeType(currentDoc, PDF_ATTACHMENT_NODE_TYPE)|| docContainsNodeType(currentDoc, FILE_ATTACHMENT_NODE_TYPE)+ || docContainsNodeType(currentDoc, "details")) {return currentDoc;}@@ -184,6 +185,7 @@ export const resolveMemoContentDoc = (|| docContainsNodeType(markdownDoc, MERGE_DIVIDER_NODE_TYPE)|| docContainsNodeType(markdownDoc, BLOCK_MATH_NODE_TYPE)|| docContainsNodeType(markdownDoc, INLINE_MATH_NODE_TYPE)+ || docContainsNodeType(markdownDoc, "details")|| !docToText(currentDoc)? markdownDoc: currentDoc;diff --git a/packages/shared/src/details.test.mjs b/packages/shared/src/details.test.mjsnew file mode 100644index 00000000..00ee75b2--- /dev/null+++ b/packages/shared/src/details.test.mjs@@ -0,0 +1,28 @@+import { describe, expect, test } from "bun:test";+import { flattenDetailsForLinearHtml, wrapDetailsContentHtml } from "./details.ts";++describe("details HTML helpers", () => {+ test("wraps GitHub details bodies for the TipTap schema", () => {+ if (typeof DOMParser === "undefined") return;++ const wrapped = wrapDetailsContentHtml(+ `<details><summary>图</summary><img src="https://example.com/a.png" alt="pic"></details>`,+ );+ expect(wrapped).toContain('data-type="detailsContent"');+ expect(wrapped).toContain("<summary>图</summary>");+ expect(wrapped).toContain('src="https://example.com/a.png"');+ });++ test("unwraps details to a visible title for linear HTML sinks", () => {+ if (typeof DOMParser === "undefined") return;++ const root = new DOMParser().parseFromString(+ `<details><summary>提示</summary><div data-type="detailsContent"><p>hidden</p></div></details>`,+ "text/html",+ ).body;+ flattenDetailsForLinearHtml(root);+ expect(root.querySelector("details")).toBeNull();+ expect(root.textContent).toContain("提示");+ expect(root.textContent).toContain("hidden");+ });+});diff --git a/packages/shared/src/details.ts b/packages/shared/src/details.tsnew file mode 100644index 00000000..a947ef25--- /dev/null+++ b/packages/shared/src/details.ts@@ -0,0 +1,296 @@+import type { JSONContent, MarkdownParseHelpers, MarkdownRendererHelpers, MarkdownToken } from "@tiptap/core";+import { Details, DetailsContent, DetailsSummary } from "@tiptap/extension-details";++export const DETAILS_NODE_TYPE = "details" as const;+export const DETAILS_SUMMARY_NODE_TYPE = "detailsSummary" as const;+export const DETAILS_CONTENT_NODE_TYPE = "detailsContent" as const;++const DETAILS_OPEN_PATTERN = /^<details\b([^>]*)>/i;+const SUMMARY_PATTERN = /^\s*<summary\b[^>]*>([\s\S]*?)<\/summary\s*>\s*/i;+const DETAILS_CONTENT_WRAPPER_PATTERN =+ /^\s*<div\b[^>]*data-type=["']detailsContent["'][^>]*>([\s\S]*)<\/div>\s*$/i;++const collectText = (node: JSONContent | undefined): string => {+ if (!node) return "";+ if (typeof node.text === "string") return node.text;+ if (!Array.isArray(node.content)) return "";+ return node.content.map((child) => collectText(child)).join("");+};++const escapeHtml = (value: string) =>+ value+ .replace(/&/g, "&")+ .replace(/</g, "<")+ .replace(/>/g, ">")+ .replace(/"/g, """);++const decodeHtmlEntities = (value: string) =>+ value+ .replace(/ /gi, " ")+ .replace(/</gi, "<")+ .replace(/>/gi, ">")+ .replace(/"/gi, "\"")+ .replace(/'/gi, "'")+ .replace(/&/gi, "&");++const stripHtmlTags = (value: string) => decodeHtmlEntities(value.replace(/<[^>]+>/g, "")).trim();++const findHtmlBlock = (source: string, tag: string) => {+ const open = new RegExp(`^<${tag}\\b([^>]*)>`, "i").exec(source);+ if (!open) return null;++ const openTag = open[0];+ let depth = 1;+ let index = openTag.length;+ const openPattern = new RegExp(`<${tag}\\b`, "ig");+ const closePattern = new RegExp(`</${tag}\\s*>`, "ig");++ while (index < source.length && depth > 0) {+ openPattern.lastIndex = index;+ closePattern.lastIndex = index;+ const nextOpen = openPattern.exec(source);+ const nextClose = closePattern.exec(source);+ if (!nextClose) return null;+ if (nextOpen && nextOpen.index < nextClose.index) {+ depth += 1;+ index = nextOpen.index + nextOpen[0].length;+ continue;+ }+ depth -= 1;+ index = nextClose.index + nextClose[0].length;+ if (depth === 0) {+ return {+ raw: source.slice(0, index),+ inner: source.slice(openTag.length, nextClose.index),+ };+ }+ }++ return null;+};++const unwrapDetailsContent = (inner: string) => {+ const match = DETAILS_CONTENT_WRAPPER_PATTERN.exec(inner.trim());+ return match ? match[1] : inner;+};++const htmlImagesToMarkdown = (source: string) =>+ source.replace(/<img\b([^>]*)\/?>/gi, (tag, attrs: string) => {+ const src = /\bsrc\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i.exec(attrs);+ const alt = /\balt\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i.exec(attrs);+ const title = /\btitle\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i.exec(attrs);+ const url = (src?.[1] ?? src?.[2] ?? src?.[3] ?? "").trim();+ if (!url) return tag;+ const altText = (alt?.[1] ?? alt?.[2] ?? alt?.[3] ?? "").trim();+ const titleText = (title?.[1] ?? title?.[2] ?? title?.[3] ?? "").trim();+ return titleText ? `` : ``;+ });++/**+ * GitHub-style HTML paste uses <details><summary>…</summary>blocks</details>.+ * TipTap's schema expects the body wrapped in div[data-type=detailsContent].+ */+export const wrapDetailsContentHtml = (html: string): string => {+ if (typeof DOMParser === "undefined" || !html.includes("<details")) {+ return html;+ }++ const document = new DOMParser().parseFromString(html, "text/html");+ const blocks = [...document.querySelectorAll("details")].reverse();+ for (const details of blocks) {+ if (details.querySelector(':scope > [data-type="detailsContent"]')) continue;+ const wrapper = document.createElement("div");+ wrapper.setAttribute("data-type", "detailsContent");+ for (const child of [...details.childNodes]) {+ if (child.nodeName === "SUMMARY") continue;+ wrapper.appendChild(child);+ }+ if (!wrapper.hasChildNodes()) {+ wrapper.appendChild(document.createElement("p"));+ }+ const summary = details.querySelector(":scope > summary");+ if (summary?.nextSibling) {+ details.insertBefore(wrapper, summary.nextSibling);+ } else {+ details.appendChild(wrapper);+ }+ }+ return document.body.innerHTML;+};++/** WeChat and similar HTML sinks do not honor <details>, so unwrap to visible title + body. */+export const flattenDetailsForLinearHtml = (root: HTMLElement) => {+ const document = root.ownerDocument;+ if (!document) return;++ const blocks = [...root.querySelectorAll("details")].reverse();+ for (const details of blocks) {+ const replacement = document.createElement("div");+ replacement.className = "edgeever-details-flat";+ const summary = details.querySelector(":scope > summary");+ const title = summary?.textContent?.trim();+ if (title) {+ const heading = document.createElement("p");+ const strong = document.createElement("strong");+ strong.textContent = title;+ heading.appendChild(strong);+ replacement.appendChild(heading);+ }+ for (const child of [...details.childNodes]) {+ if (child === summary) continue;+ if (child instanceof HTMLElement && child.getAttribute("data-type") === "detailsContent") {+ while (child.firstChild) {+ replacement.appendChild(child.firstChild);+ }+ continue;+ }+ replacement.appendChild(child);+ }+ details.parentNode?.replaceChild(replacement, details);+ }+};++export const DETAILS_EDITOR_CSS = `+.ProseMirror [data-type="details"],+.edgeever-editor-content [data-type="details"] {+ display: flex;+ align-items: flex-start;+ gap: 0.2rem;+ margin: 0.7em 0;+ padding: 0.45rem 0.7rem 0.55rem 0.3rem;+ border: 1px solid color-mix(in srgb, currentColor 14%, transparent);+ border-radius: 10px;+ background: color-mix(in srgb, currentColor 4%, transparent);+}+.ProseMirror [data-type="details"] > button,+.edgeever-editor-content [data-type="details"] > button {+ flex: 0 0 auto;+ width: 1.55rem;+ height: 1.55rem;+ margin-top: 0.05rem;+ padding: 0;+ border: 0;+ border-radius: 999px;+ background: transparent;+ color: #16a06e;+ cursor: pointer;+}+.ProseMirror [data-type="details"] > button::before,+.edgeever-editor-content [data-type="details"] > button::before {+ content: "";+ display: block;+ width: 0.42rem;+ height: 0.42rem;+ margin: 0.38rem auto 0;+ border-right: 2px solid currentColor;+ border-bottom: 2px solid currentColor;+ transform: rotate(-45deg);+}+.ProseMirror [data-type="details"].is-open > button::before,+.edgeever-editor-content [data-type="details"].is-open > button::before {+ margin-top: 0.22rem;+ transform: rotate(45deg);+}+.ProseMirror [data-type="details"] > div,+.edgeever-editor-content [data-type="details"] > div {+ flex: 1;+ min-width: 0;+}+.ProseMirror summary,+.edgeever-editor-content summary {+ display: block;+ font-weight: 650;+ list-style: none;+ cursor: text;+}+.ProseMirror summary::-webkit-details-marker,+.edgeever-editor-content summary::-webkit-details-marker {+ display: none;+}+.ProseMirror [data-type="detailsContent"],+.edgeever-editor-content [data-type="detailsContent"] {+ margin-top: 0.35rem;+}+`;++const parseDetailsMarkdown = (token: MarkdownToken, helpers: MarkdownParseHelpers) => {+ const summaryText = typeof token.summary === "string" ? token.summary : "";+ const parsedBody = helpers.parseChildren(token.tokens || []);+ const body = parsedBody.length > 0 ? parsedBody : [{ type: "paragraph" }];+ return helpers.createNode(DETAILS_NODE_TYPE, undefined, [+ helpers.createNode(+ DETAILS_SUMMARY_NODE_TYPE,+ undefined,+ summaryText ? [helpers.createTextNode(summaryText)] : [],+ ),+ helpers.createNode(DETAILS_CONTENT_NODE_TYPE, undefined, body),+ ]);+};++const renderDetailsMarkdown = (node: JSONContent, helpers: MarkdownRendererHelpers) => {+ const children = Array.isArray(node.content) ? node.content : [];+ const summary = children.find((child) => child.type === DETAILS_SUMMARY_NODE_TYPE);+ const body = children.find((child) => child.type === DETAILS_CONTENT_NODE_TYPE);+ const summaryHtml = escapeHtml(collectText(summary).trim());+ const bodyMarkdown = Array.isArray(body?.content) && body.content.length > 0+ ? helpers.renderChildren(body.content, "\n\n").trim()+ : "";+ return `<details>\n<summary>${summaryHtml}</summary>\n\n${bodyMarkdown}\n\n</details>`;+};++export const EdgeEverDetails = Details.extend({+ addOptions() {+ return {+ persist: false,+ openClassName: "is-open",+ HTMLAttributes: {+ class: "edgeever-details",+ },+ renderToggleButton: ({ element, isOpen }) => {+ element.setAttribute("aria-label", isOpen ? "Collapse details" : "Expand details");+ },+ };+ },++ parseMarkdown: parseDetailsMarkdown,+ renderMarkdown: renderDetailsMarkdown,+ markdownTokenizer: {+ name: DETAILS_NODE_TYPE,+ level: "block",+ start(source: string) {+ const match = /<details\b/i.exec(source);+ return match ? match.index : -1;+ },+ tokenize(source: string, _tokens, lexer) {+ const leading = /^\s*/.exec(source)?.[0] ?? "";+ const rest = source.slice(leading.length);+ if (!DETAILS_OPEN_PATTERN.test(rest)) return undefined;+ const block = findHtmlBlock(rest, "details");+ if (!block) return undefined;++ const summaryMatch = SUMMARY_PATTERN.exec(block.inner);+ const summary = summaryMatch ? stripHtmlTags(summaryMatch[1]) : "";+ const bodySource = htmlImagesToMarkdown(unwrapDetailsContent(+ summaryMatch ? block.inner.slice(summaryMatch[0].length) : block.inner,+ ));+ const tokens = bodySource.trim() ? lexer.blockTokens(bodySource.trim()) : [];+ const trailing = /^\s*\n/.exec(source.slice(leading.length + block.raw.length))?.[0] ?? "";++ return {+ type: DETAILS_NODE_TYPE,+ raw: `${leading}${block.raw}${trailing}`,+ summary,+ tokens,+ };+ },+ },+});++export const EdgeEverDetailsSummary = DetailsSummary;+export const EdgeEverDetailsContent = DetailsContent;++export const createEdgeEverDetailsExtensions = () => [+ EdgeEverDetails,+ EdgeEverDetailsSummary,+ EdgeEverDetailsContent,+];diff --git a/packages/shared/src/document-extensions.test.mjs b/packages/shared/src/document-extensions.test.mjsindex 97969a26..54d52f8c 100644--- a/packages/shared/src/document-extensions.test.mjs+++ b/packages/shared/src/document-extensions.test.mjs@@ -34,6 +34,9 @@ describe("shared document extensions", () => {expect(names).toContain("edgeeverPdfAttachment");expect(names).toContain("edgeeverFileAttachment");expect(names).toContain(MERGE_DIVIDER_NODE_TYPE);+ expect(names).toContain("details");+ expect(names).toContain("detailsSummary");+ expect(names).toContain("detailsContent");expect(names).toContain("edgeeverPluginEmbed");expect(names).toContain("markdown");});diff --git a/packages/shared/src/document-extensions.ts b/packages/shared/src/document-extensions.tsindex 236cbc14..54ae7898 100644--- a/packages/shared/src/document-extensions.ts+++ b/packages/shared/src/document-extensions.ts@@ -4,6 +4,7 @@ import { TaskItem, TaskList } from "@tiptap/extension-list";import { TableKit } from "@tiptap/extension-table";import { Markdown } from "@tiptap/markdown";import StarterKit from "@tiptap/starter-kit";+import { createEdgeEverDetailsExtensions } from "./details";import { FileAttachment } from "./file-attachment";import { ImageGallery } from "./image-gallery";import { MergeDivider } from "./merge-divider";@@ -44,6 +45,7 @@ export const createEdgeEverDocumentExtensions = (...withOptional(options.pdf, PdfAttachment),...withOptional(options.file, FileAttachment),MergeDivider,+ ...createEdgeEverDetailsExtensions(),...withOptional(options.pluginEmbed, PluginEmbed),...options.mathematics,...(options.markdowndiff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.tsindex 8eaf3e26..762e2146 100644--- a/packages/shared/src/i18n/en-US.ts+++ b/packages/shared/src/i18n/en-US.ts@@ -1934,6 +1934,7 @@ export const enUS = {decreaseListIndent: "Decrease list level (Shift + Tab)",listIndentHint: "Tab increases level · Shift + Tab decreases level",quote: "Quote",+ fold: "Fold",codeBlock: "Code block",copyCode: "Copy code",codeCopied: "Copied",diff --git a/packages/shared/src/i18n/ja.ts b/packages/shared/src/i18n/ja.tsindex f19a13a5..484dd507 100644--- a/packages/shared/src/i18n/ja.ts+++ b/packages/shared/src/i18n/ja.ts@@ -1934,6 +1934,7 @@ export const ja = {decreaseListIndent: "リスト階層を下げる(Shift + Tab)",listIndentHint: "Tab で階層を上げる · Shift + Tab で階層を下げる",quote: "引用",+ fold: "折りたたみ",codeBlock: "コードブロック",copyCode: "コードをコピー",codeCopied: "コピーしました",diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.tsindex ee046554..3aef49f9 100644--- a/packages/shared/src/i18n/zh-CN.ts+++ b/packages/shared/src/i18n/zh-CN.ts@@ -1932,6 +1932,7 @@ export const zhCN = {decreaseListIndent: "减少列表层级(Shift + Tab)",listIndentHint: "Tab 增加层级,Shift + Tab 减少层级",quote: "引用",+ fold: "折叠块",codeBlock: "代码块",copyCode: "复制代码",codeCopied: "已复制",diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.tsindex 20c0f489..953cc523 100644--- a/packages/shared/src/index.ts+++ b/packages/shared/src/index.ts@@ -31,6 +31,7 @@ export * from "./schemas";export * from "./sharing";export * from "./sync";export * from "./desktop-rpc";+export * from "./details";export * from "./deployment-metadata";export * from "./diagram";export * from "./diagram-palette";diff --git a/packages/shared/src/mobile-content-compatibility.ts b/packages/shared/src/mobile-content-compatibility.tsindex 624ed1ab..3317d516 100644--- a/packages/shared/src/mobile-content-compatibility.ts+++ b/packages/shared/src/mobile-content-compatibility.ts@@ -29,6 +29,9 @@ export const NATIVE_EDITOR_NODE_TYPES = new Set<string>(["hardBreak","horizontalRule","image",+ "details",+ "detailsSummary",+ "detailsContent","edgeeverImageGallery","table","tableRow",