wendang-react 0.6.3 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/NOTICE.md +1 -1
  2. package/README.md +105 -0
  3. package/dist/bindings/yjs.js +1 -5
  4. package/dist/chunks/AnchoredPanel-C7jMoPze.js +1 -0
  5. package/dist/chunks/DocumentExportMenu-CUMsgq3w.js +2 -0
  6. package/dist/chunks/Dropdown-D98tXfe0.js +3 -0
  7. package/dist/chunks/MindMapCanvas-CVXQXNOg.js +163 -0
  8. package/dist/chunks/MindMapViewer-BI8zbQM1.js +13 -0
  9. package/dist/chunks/SpreadsheetViewer-CoQ4VIgj.js +23 -0
  10. package/dist/chunks/code-highlight-BmaqTe1m.js +1 -30
  11. package/dist/chunks/code-highlight-engine-BFDzDPzy.js +1 -40
  12. package/dist/chunks/comment-hint-BhUxKjKK.js +14 -0
  13. package/dist/chunks/composition-state-Bl-U1R_2.js +1 -40
  14. package/dist/chunks/extensions-C1fCBnEs.js +14 -0
  15. package/dist/chunks/fuzzy-match-DYQR-4w2.js +1 -89
  16. package/dist/chunks/hooks-C53Dp0pr.js +1 -35
  17. package/dist/chunks/i18n-B0kCsIjc.js +2 -0
  18. package/dist/chunks/index-COeA2QcQ.js +15 -0
  19. package/dist/chunks/katex-WjrodtTU.js +1 -71
  20. package/dist/chunks/locale-DWpIJ_9X.js +1 -0
  21. package/dist/chunks/mind-map-controller-Ce76mETT.js +1 -0
  22. package/dist/chunks/mind-map-delete-CVsxdXfs.js +1 -31
  23. package/dist/chunks/mind-map-input-CEWRz_t6.js +1 -43
  24. package/dist/chunks/mind-topic-text-Bn1waxff.js +31 -0
  25. package/dist/chunks/popover-placement-D3xVYdkt.js +1 -47
  26. package/dist/chunks/worksheet-engine-c84sdD4N.js +1 -0
  27. package/dist/chunks/worksheet-preview-DsDVWxIM.js +1 -129
  28. package/dist/document/viewer.js +30 -289
  29. package/dist/document.js +120 -3811
  30. package/dist/export/json.js +1 -5
  31. package/dist/export/markdown.js +1 -2
  32. package/dist/export/mindmap.js +1 -2
  33. package/dist/export/pdf.js +1 -6
  34. package/dist/export/word.js +1 -2
  35. package/dist/export.js +1 -2
  36. package/dist/i18n.js +1 -0
  37. package/dist/index.js +1 -8
  38. package/dist/locales/en-US.js +1 -0
  39. package/dist/locales/es-ES.js +1 -0
  40. package/dist/locales/ja-JP.js +1 -0
  41. package/dist/locales/ko-KR.js +1 -0
  42. package/dist/locales/zh-CN.js +1 -0
  43. package/dist/locales/zh-TW.js +1 -0
  44. package/dist/mindmap/viewer.js +1 -6
  45. package/dist/mindmap.js +3 -123
  46. package/dist/shared.js +1 -52
  47. package/dist/spreadsheet/viewer.js +1 -5
  48. package/dist/spreadsheet/xlsx.js +1 -299
  49. package/dist/spreadsheet.js +2 -120
  50. package/dist/styles/callout.css +1 -34
  51. package/dist/styles/code-block.css +1 -58
  52. package/dist/styles/content-style.css +1 -619
  53. package/dist/styles/content-tokens.css +1 -29
  54. package/dist/styles/editor-interaction.css +1 -621
  55. package/dist/styles/file-video.css +1 -12
  56. package/dist/styles/image-preview.css +1 -103
  57. package/dist/styles/mind-map-block.css +1 -14
  58. package/dist/styles/mind-map-canvas.css +1 -80
  59. package/dist/styles/mind-map-comments.css +1 -93
  60. package/dist/styles/mind-map-details.css +1 -7
  61. package/dist/styles/mind-map-preview.css +1 -7
  62. package/dist/styles/mind-map-topic.css +1 -112
  63. package/dist/styles/page-picker.css +1 -47
  64. package/dist/styles/renderer.css +1 -45
  65. package/dist/styles/spreadsheet-editor.css +1 -3
  66. package/dist/styles/tokens.css +1 -142
  67. package/dist/styles/video-dialog.css +1 -41
  68. package/dist/styles/video-embed.css +1 -35
  69. package/dist/styles.css +1 -2655
  70. package/dist/types/editor/BlockAffordance.d.ts +5 -2
  71. package/dist/types/editor/CalloutView.d.ts +2 -1
  72. package/dist/types/editor/ImagePreview.d.ts +1 -1
  73. package/dist/types/editor/PagePicker.d.ts +1 -1
  74. package/dist/types/editor/extensions.d.ts +4 -1
  75. package/dist/types/engine/editor/block-commands.d.ts +1 -1
  76. package/dist/types/engine/editor/block-menu-hover.d.ts +16 -0
  77. package/dist/types/engine/editor/extensions/locale.d.ts +3 -0
  78. package/dist/types/engine/editor/nodes/image-nodeview.d.ts +1 -1
  79. package/dist/types/engine/host.d.ts +60 -2
  80. package/dist/types/engine/renderer/attachments.d.ts +3 -3
  81. package/dist/types/engine/shared/video-feedback.d.ts +1 -1
  82. package/dist/types/engine/worksheets/worksheet-engine.d.ts +1 -0
  83. package/dist/types/engine/worksheets/worksheet-xlsx.d.ts +6 -1
  84. package/dist/types/host-types.d.ts +2 -60
  85. package/dist/types/host.d.ts +8 -1
  86. package/dist/types/i18n.d.ts +3 -0
  87. package/dist/types/index.d.ts +2 -0
  88. package/dist/types/locales/en-US.d.ts +1 -0
  89. package/dist/types/locales/es-ES.d.ts +1 -0
  90. package/dist/types/locales/ja-JP.d.ts +1 -0
  91. package/dist/types/locales/ko-KR.d.ts +1 -0
  92. package/dist/types/locales/zh-CN.d.ts +1 -0
  93. package/dist/types/locales/zh-TW.d.ts +1 -0
  94. package/dist/types/spreadsheet/xlsx.d.ts +1 -1
  95. package/dist/types/wui/Dropdown.d.ts +2 -1
  96. package/dist/types/wui/index.d.ts +2 -1
  97. package/integrity.json +3135 -0
  98. package/package.json +15 -5
  99. package/verify-integrity.mjs +138 -0
  100. package/dist/chunks/AnchoredPanel-Cv4RURwF.js +0 -68
  101. package/dist/chunks/DocumentExportMenu-BrGipZ59.js +0 -75
  102. package/dist/chunks/MindMapCanvas-tkFBBs4g.js +0 -2090
  103. package/dist/chunks/MindMapViewer-DJrryb2Y.js +0 -180
  104. package/dist/chunks/SpreadsheetViewer-DxCxIUx_.js +0 -163
  105. package/dist/chunks/comment-hint-B9qcrqvn.js +0 -296
  106. package/dist/chunks/extensions-ByORRoRa.js +0 -4210
  107. package/dist/chunks/host-C-V688Rq.js +0 -197
  108. package/dist/chunks/index-DdfMnva8.js +0 -726
  109. package/dist/chunks/mind-map-controller-B6SxK3GZ.js +0 -479
  110. package/dist/chunks/mind-topic-text-DSyb95vL.js +0 -446
  111. package/dist/chunks/nodes-iKqTGr_N.js +0 -291
  112. package/dist/chunks/worksheet-engine-TJ54m0KC.js +0 -125
  113. package/third-party-notices/wendang-export@0.6.0-NOTICE.md.txt +0 -51
  114. package/third-party-notices/wendang-export@0.6.1-LICENSE.txt +0 -21
  115. package/third-party-notices/wendang-export@0.6.2-LICENSE.txt +0 -21
  116. package/third-party-notices/wendang-export@0.6.2-NOTICE.md.txt +0 -70
  117. /package/third-party-notices/{wendang-export@0.6.0-LICENSE.txt → wendang-export@0.6.3-LICENSE.txt} +0 -0
  118. /package/third-party-notices/{wendang-export@0.6.1-NOTICE.md.txt → wendang-export@0.6.3-NOTICE.md.txt} +0 -0
@@ -1,289 +1,30 @@
1
- "use client";
2
- import { jsx, jsxs } from "react/jsx-runtime";
3
- import { useEffect, createElement, Fragment, useState } from "react";
4
- import { resolveInlineComments, splitTextByMarks, safeHref, documentColorAttributes, effectiveCallout, calloutDOMAttributes, cellBackground, tableColumnWidths, tableMinWidth } from "wendang/shared";
5
- import { readMindMap } from "wendang/mindmap";
6
- import { isWorkbookDocument } from "wendang/spreadsheet";
7
- import { b as useContentHost } from "../chunks/host-C-V688Rq.js";
8
- import { M as MathView, V as VideoView, F as FileView, A as AttachmentImage } from "../chunks/mind-topic-text-DSyb95vL.js";
9
- import { M as MindMapBlock } from "../chunks/MindMapViewer-DJrryb2Y.js";
10
- import { S as SpreadsheetViewer } from "../chunks/SpreadsheetViewer-DxCxIUx_.js";
11
- import { e as ensureCodeHighlight, c as codeTokens } from "../chunks/code-highlight-BmaqTe1m.js";
12
- import { h as hideCommentHint, s as showCommentHint, C as CodeToolbar } from "../chunks/comment-hint-B9qcrqvn.js";
13
- import { codeBlockDisplay, codeLineNumbers, codeBlockClass } from "wendang/internal/code-block";
14
- import { D } from "../chunks/DocumentExportMenu-BrGipZ59.js";
15
- function CommentText({ marks, activeId, onMarkClick, children }) {
16
- return /* @__PURE__ */ jsx(
17
- "span",
18
- {
19
- className: [
20
- "doc-inline-comment",
21
- marks.some((mark) => mark.state === "shifted") ? "is-shifted" : "",
22
- marks.some((mark) => mark.hasReplies) ? "has-replies" : "",
23
- marks.some((mark) => mark.commentId === activeId) ? "is-active" : ""
24
- ].filter(Boolean).join(" "),
25
- "data-comment-id": marks[0].commentId,
26
- "data-comment-ids": marks.map((mark) => mark.commentId).join(" "),
27
- "data-comment-hint": "点击查看该处讨论",
28
- onMouseEnter: (event) => showCommentHint(event.currentTarget, "点击查看该处讨论"),
29
- onMouseLeave: () => hideCommentHint(),
30
- onClick: (event) => {
31
- event.stopPropagation();
32
- hideCommentHint();
33
- onMarkClick == null ? void 0 : onMarkClick(marks[0].commentId);
34
- },
35
- children
36
- }
37
- );
38
- }
39
- function CodeView({ text, language, allowExport, marks, activeId, onMarkClick }) {
40
- const [, refresh] = useState(0);
41
- const [display, setDisplay] = useState(codeBlockDisplay);
42
- useEffect(() => {
43
- let active = true;
44
- void ensureCodeHighlight().then(() => {
45
- if (active) refresh((value) => value + 1);
46
- });
47
- return () => {
48
- active = false;
49
- };
50
- }, [text, language]);
51
- const tokens = codeTokens(text, language);
52
- let offset = 0;
53
- function syntaxText(from, to) {
54
- const parts2 = [];
55
- let cursor = from;
56
- for (const token of tokens) {
57
- const start = Math.max(from, token.from), end = Math.min(to, token.to);
58
- if (start >= end) continue;
59
- if (start > cursor) parts2.push(text.slice(cursor, start));
60
- parts2.push(/* @__PURE__ */ jsx("span", { className: token.classes, children: text.slice(start, end) }, start));
61
- cursor = end;
62
- }
63
- if (cursor < to) parts2.push(text.slice(cursor, to));
64
- return parts2;
65
- }
66
- const parts = splitTextByMarks(text, marks).map((piece, index) => {
67
- const start = offset;
68
- offset += piece.text.length;
69
- const content = syntaxText(start, offset);
70
- return piece.marks.length ? /* @__PURE__ */ jsx(CommentText, { marks: piece.marks, activeId, onMarkClick, children: content }, index) : /* @__PURE__ */ jsx("span", { children: content }, index);
71
- });
72
- return /* @__PURE__ */ jsxs("div", { className: ["doc-code-wrap", ...codeBlockClass(display)].join(" "), children: [
73
- /* @__PURE__ */ jsx(CodeToolbar, { text, language, editable: false, canCopy: !!allowExport, display, onLanguage: () => {
74
- }, onDisplay: setDisplay }),
75
- /* @__PURE__ */ jsxs("div", { className: "code-scroll", hidden: display.collapsed, tabIndex: 0, "aria-label": "代码内容", children: [
76
- display.lineNumbers && /* @__PURE__ */ jsx("div", { className: "code-line-numbers", "aria-hidden": "true", children: codeLineNumbers(text) }),
77
- /* @__PURE__ */ jsx("pre", { className: "doc-code", children: /* @__PURE__ */ jsx("code", { children: parts }) })
78
- ] })
79
- ] });
80
- }
81
- const textOf = (node) => {
82
- var _a;
83
- return node.text ?? ((_a = node.content) == null ? void 0 : _a.map(textOf).join("")) ?? "";
84
- };
85
- function cssStyle(css) {
86
- return Object.fromEntries(css.split(";").filter(Boolean).map((part) => {
87
- const index = part.indexOf(":");
88
- const property = part.slice(0, index).trim();
89
- return [property.startsWith("--") ? property : property.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()), part.slice(index + 1).trim()];
90
- }));
91
- }
92
- function DocumentViewer(props) {
93
- var _a;
94
- const host = useContentHost(), doc = props.value ?? props.modelValue;
95
- useEffect(() => () => hideCommentHint(), []);
96
- if (!doc) return /* @__PURE__ */ jsx("div", { className: "doc-renderer ywiki-prose ywiki-content" });
97
- const marks = ((_a = props.inlineMarks) == null ? void 0 : _a.size) ? props.inlineMarks : resolveInlineComments(doc, props.inlineComments ?? []).byTextIndex;
98
- let run = 0;
99
- function children(node, inImageGallery = false) {
100
- var _a2;
101
- return (_a2 = node.content) == null ? void 0 : _a2.map((child, index) => /* @__PURE__ */ jsx(Fragment, { children: render(child, inImageGallery) }, index));
102
- }
103
- function render(node, inImageGallery = false) {
104
- var _a2, _b, _c;
105
- const attrs = node.attrs ?? {};
106
- if (node.type === "text") {
107
- let text = node.text ?? "", index = run++;
108
- const inline = marks.get(index) ?? [];
109
- if (inline.length) text = /* @__PURE__ */ jsx("span", { children: splitTextByMarks(node.text ?? "", inline).map((piece, at) => piece.marks.length ? /* @__PURE__ */ jsx(CommentText, { marks: piece.marks, activeId: props.activeCommentId, onMarkClick: props.onMarkClick, children: piece.text }, at) : /* @__PURE__ */ jsx("span", { children: piece.text }, at)) });
110
- for (const mark of node.marks ?? []) {
111
- const a = mark.attrs ?? {};
112
- const tag = { bold: "strong", italic: "em", strike: "s", underline: "u", code: "code" }[mark.type];
113
- if (tag) text = createElement(tag, null, text);
114
- else if (mark.type === "link") {
115
- const href = safeHref(String(a.href ?? ""));
116
- if (href) text = /* @__PURE__ */ jsx("a", { href, target: "_blank", rel: "noopener noreferrer", children: text });
117
- } else if (mark.type === "textStyle" || mark.type === "highlight") {
118
- const data = documentColorAttributes(mark.type === "highlight" ? "highlight" : "text", a.color);
119
- text = /* @__PURE__ */ jsx("span", { ...Object.fromEntries(Object.entries(data).filter(([key]) => key !== "style")), style: cssStyle(data.style ?? ""), children: text });
120
- }
121
- }
122
- return text;
123
- }
124
- const alignment = attrs.textAlign ?? attrs.align;
125
- const style = { textAlign: ["left", "center", "right", "justify"].includes(String(alignment)) ? alignment : void 0, marginLeft: Number(attrs.indent) > 0 ? `${Math.min(6, Number(attrs.indent)) * 24}px` : void 0 };
126
- switch (node.type) {
127
- case "doc":
128
- return children(node);
129
- case "paragraph":
130
- return /* @__PURE__ */ jsx("p", { style, children: children(node) || /* @__PURE__ */ jsx("br", {}) });
131
- case "heading":
132
- return createElement(`h${Math.max(1, Math.min(6, Number(attrs.level) || 1))}`, { style, id: typeof attrs.anchor === "string" ? attrs.anchor : typeof attrs.id === "string" ? attrs.id : void 0 }, children(node));
133
- case "bulletList":
134
- return /* @__PURE__ */ jsx("ul", { children: children(node) });
135
- case "orderedList":
136
- return /* @__PURE__ */ jsx("ol", { start: Number(attrs.start) || 1, children: children(node) });
137
- case "listItem":
138
- return /* @__PURE__ */ jsx("li", { children: children(node) });
139
- case "taskList":
140
- return /* @__PURE__ */ jsx("ul", { className: "doc-task-list", children: children(node) });
141
- case "taskItem":
142
- return /* @__PURE__ */ jsxs("li", { className: "doc-task-item", children: [
143
- /* @__PURE__ */ jsx("input", { type: "checkbox", checked: attrs.checked === true, disabled: true, "aria-label": textOf(((_a2 = node.content) == null ? void 0 : _a2[0]) ?? node) || "未命名任务" }),
144
- /* @__PURE__ */ jsx("span", { children: children(node) })
145
- ] });
146
- case "blockquote":
147
- return /* @__PURE__ */ jsx("blockquote", { children: children(node) });
148
- case "horizontalRule":
149
- return /* @__PURE__ */ jsx("hr", {});
150
- case "hardBreak":
151
- return /* @__PURE__ */ jsx("br", {});
152
- case "codeBlock": {
153
- const codeMarks = [];
154
- let offset = 0;
155
- const visit = (child) => {
156
- var _a3;
157
- if (child.type === "text") {
158
- for (const mark of marks.get(run++) ?? []) codeMarks.push({ ...mark, from: offset + mark.from, to: offset + mark.to });
159
- offset += ((_a3 = child.text) == null ? void 0 : _a3.length) ?? 0;
160
- } else for (const item of child.content ?? []) visit(item);
161
- };
162
- visit(node);
163
- return /* @__PURE__ */ jsx(
164
- CodeView,
165
- {
166
- text: textOf(node),
167
- language: String(attrs.language ?? ""),
168
- allowExport: props.allowExport,
169
- marks: codeMarks,
170
- activeId: props.activeCommentId,
171
- onMarkClick: props.onMarkClick
172
- }
173
- );
174
- }
175
- case "table": {
176
- const widths = tableColumnWidths(node), minWidth = tableMinWidth(widths), fixed = widths.length > 0 && widths.every((width) => width > 0);
177
- return /* @__PURE__ */ jsx("div", { className: "doc-table-wrap", children: /* @__PURE__ */ jsxs("table", { className: "doc-table", style: minWidth ? fixed ? { width: minWidth } : { minWidth } : void 0, children: [
178
- widths.length > 0 && /* @__PURE__ */ jsx("colgroup", { children: widths.map((width, index) => /* @__PURE__ */ jsx("col", { style: width > 0 ? { width } : { minWidth: 120 } }, index)) }),
179
- /* @__PURE__ */ jsx("tbody", { children: children(node) })
180
- ] }) });
181
- }
182
- case "tableRow":
183
- return /* @__PURE__ */ jsx("tr", { children: children(node) });
184
- case "tableCell":
185
- case "tableHeader":
186
- return createElement(node.type === "tableHeader" ? "th" : "td", {
187
- colSpan: Number(attrs.colspan) || 1,
188
- rowSpan: Number(attrs.rowspan) || 1,
189
- style: { ...style, backgroundColor: cellBackground(attrs.backgroundColor) ?? void 0 }
190
- }, children(node));
191
- case "image": {
192
- const aspectRatio = Number(attrs.aspectRatio) || null, galleryScale = Number(attrs.galleryScale) || null;
193
- const align = ["left", "center", "right"].includes(String(attrs.align)) ? attrs.align : null;
194
- const image = /* @__PURE__ */ jsx(
195
- AttachmentImage,
196
- {
197
- id: String(attrs.attachmentId ?? "") || void 0,
198
- src: String(attrs.src ?? ""),
199
- alt: String(attrs.alt ?? ""),
200
- width: inImageGallery ? void 0 : Number(attrs.width) || void 0,
201
- align,
202
- aspectRatio,
203
- galleryScale,
204
- fetcher: props.attachmentFetcher,
205
- allowExport: props.allowExport
206
- }
207
- );
208
- const caption = typeof attrs.caption === "string" ? attrs.caption.trim() : "";
209
- if (!caption) return image;
210
- return /* @__PURE__ */ jsxs("figure", { className: "doc-image-figure", style: inImageGallery ? {
211
- "--doc-image-aspect-ratio": String(aspectRatio && aspectRatio > 0 ? aspectRatio : 1),
212
- "--doc-image-weight": String(galleryScale && galleryScale > 0 ? galleryScale : 1)
213
- } : void 0, children: [
214
- image,
215
- /* @__PURE__ */ jsx("figcaption", { className: "doc-image-caption", title: caption, children: caption })
216
- ] });
217
- }
218
- case "imageGallery":
219
- return /* @__PURE__ */ jsx("div", { className: "doc-image-gallery", "data-image-gallery": "true", style: { "--image-gallery-height": `${Math.min(480, Math.max(72, Number(attrs.height) || 120))}px` }, children: children(node, true) });
220
- case "fileAttachment":
221
- return /* @__PURE__ */ jsx(FileView, { id: String(attrs.attachmentId ?? ""), filename: String(attrs.filename ?? "附件"), mimeType: String(attrs.mimeType ?? ""), size: Number(attrs.size) || 0, fetcher: props.attachmentFetcher, allowExport: props.allowExport });
222
- case "videoEmbed":
223
- return /* @__PURE__ */ jsx(VideoView, { attrs });
224
- case "mathInline":
225
- case "mathBlock":
226
- return /* @__PURE__ */ jsx(MathView, { latex: String(attrs.latex ?? ""), block: node.type === "mathBlock" });
227
- case "callout": {
228
- const { icon } = effectiveCallout(attrs), data = calloutDOMAttributes(attrs);
229
- return /* @__PURE__ */ jsxs("div", { ...Object.fromEntries(Object.entries(data).filter(([key]) => key !== "style")), className: "doc-callout", style: cssStyle(data.style ?? ""), children: [
230
- icon ? /* @__PURE__ */ jsx("span", { className: "callout-icon", "aria-hidden": "true", "data-callout-decoration": "true", children: icon }) : null,
231
- /* @__PURE__ */ jsx("div", { className: "doc-callout-content", "data-callout-content": "true", children: children(node) })
232
- ] });
233
- }
234
- case "columns":
235
- return /* @__PURE__ */ jsx("div", { className: "doc-columns", children: children(node) });
236
- case "column":
237
- return /* @__PURE__ */ jsx("div", { className: "doc-column", children: children(node) });
238
- case "pageLink": {
239
- const label = String(attrs.label ?? "页面"), id = String(attrs.pageId ?? "");
240
- if (!id) return /* @__PURE__ */ jsx("span", { children: label });
241
- const target = (_c = props.resolvePageLink ?? ((_b = host.references) == null ? void 0 : _b.resolve)) == null ? void 0 : _c(id, label);
242
- const href = safeHref((target == null ? void 0 : target.href) ?? "");
243
- return href ? /* @__PURE__ */ jsx("a", { className: "doc-page-link", rel: "noopener noreferrer", href, onClick: (event) => {
244
- var _a3;
245
- if (!(target == null ? void 0 : target.external) && ((_a3 = host.references) == null ? void 0 : _a3.navigate) && event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey) {
246
- event.preventDefault();
247
- void host.references.navigate(href);
248
- }
249
- }, children: label }) : /* @__PURE__ */ jsx("span", { className: "doc-page-link-plain", children: label });
250
- }
251
- case "mention": {
252
- const label = String(attrs.label ?? "用户");
253
- return attrs.userId ? /* @__PURE__ */ jsxs("span", { className: "doc-mention", title: `提及:${label}`, children: [
254
- "@",
255
- label
256
- ] }) : /* @__PURE__ */ jsxs("span", { children: [
257
- "@",
258
- label
259
- ] });
260
- }
261
- case "mindMap": {
262
- const count = (n) => (n.type === "text" ? 1 : 0) + (n.content ?? []).reduce((sum, child) => sum + count(child), 0);
263
- run += count(node);
264
- const model = readMindMap(node);
265
- return model ? /* @__PURE__ */ jsx(MindMapBlock, { node, allowExport: props.allowExport, pageId: props.pageId, canComment: props.canComment, onCommentsChanged: props.onCommentsChanged, fetchAttachment: props.attachmentFetcher }) : /* @__PURE__ */ jsx("p", { role: "alert", children: "思维导图格式无效" });
266
- }
267
- case "workbook":
268
- return isWorkbookDocument(node) ? /* @__PURE__ */ jsx(SpreadsheetViewer, { value: node, allowExport: props.allowExport }) : /* @__PURE__ */ jsx("p", { role: "alert", children: "工作表格式无效" });
269
- case "mindMapTopic":
270
- case "mindMapDescription":
271
- case "mindMapNote":
272
- case "mindMapRelation":
273
- return null;
274
- default:
275
- return /* @__PURE__ */ jsxs("p", { role: "alert", children: [
276
- "不支持的内容节点:",
277
- node.type
278
- ] });
279
- }
280
- }
281
- return /* @__PURE__ */ jsx("div", { className: "doc-renderer ywiki-prose ywiki-content", children: render(doc) });
282
- }
283
- const DocRenderer = DocumentViewer;
284
- export {
285
- DocRenderer,
286
- D as DocumentExportMenu,
287
- DocumentViewer,
288
- MindMapBlock
289
- };
1
+ "use client";import{jsx as e,jsxs as t}from"react/jsx-runtime";import{c as n,b as r}from"../chunks/i18n-B0kCsIjc.js";import{useEffect as a,createElement as i,Fragment as l,useState as c}from"react";import{resolveInlineComments as o,splitTextByMarks as s,safeHref as d,documentColorAttributes as m,effectiveCallout as h,calloutDOMAttributes as u,cellBackground as p,tableColumnWidths as g,tableMinWidth as f}from"wendang/shared";import{readMindMap as k}from"wendang/mindmap";import{isWorkbookDocument as y}from"wendang/spreadsheet";import{M as x,V as v,F as b,A as w}from"../chunks/mind-topic-text-Bn1waxff.js";import{M as N}from"../chunks/MindMapViewer-BI8zbQM1.js";import{S as C}from"../chunks/SpreadsheetViewer-CoQ4VIgj.js";import{e as M,c as S}from"../chunks/code-highlight-BmaqTe1m.js";import{h as I,s as j,C as E}from"../chunks/comment-hint-BhUxKjKK.js";import{codeBlockDisplay as B,codeLineNumbers as T,codeBlockClass as V}from"wendang/internal/code-block";import{D}from"../chunks/DocumentExportMenu-CUMsgq3w.js";function CommentText({marks:t,activeId:r,onMarkClick:a,children:i}){return n().text,/* @__PURE__ */e("span",{className:["doc-inline-comment",t.some(e=>"shifted"===e.state)?"is-shifted":"",t.some(e=>e.hasReplies)?"has-replies":"",t.some(e=>e.commentId===r)?"is-active":""].filter(Boolean).join(" "),"data-comment-id":t[0].commentId,"data-comment-ids":t.map(e=>e.commentId).join(" "),"data-comment-hint":"点击查看该处讨论",onMouseEnter:e=>j(e.currentTarget,"点击查看该处讨论"),onMouseLeave:()=>I(),onClick:e=>{e.stopPropagation(),I(),null==a||a(t[0].commentId)},children:i})}function CodeView({text:r,language:i,allowExport:l,marks:o,activeId:d,onMarkClick:m}){const h=n().text,[,u]=c(0),[p,g]=c(B);a(()=>{let e=!0;return M().then(()=>{e&&u(e=>e+1)}),()=>{e=!1}},[r,i]);const f=S(r,i);let k=0;const y=s(r,o).map((t,n)=>{const a=k;k+=t.text.length;const i=function syntaxText(t,n){const a=[];let i=t;for(const l of f){const c=Math.max(t,l.from),o=Math.min(n,l.to);c>=o||(c>i&&a.push(r.slice(i,c)),a.push(/* @__PURE__ */e("span",{className:l.classes,children:r.slice(c,o)},c)),i=o)}return i<n&&a.push(r.slice(i,n)),a}(a,k);return t.marks.length?/* @__PURE__ */e(CommentText,{marks:t.marks,activeId:d,onMarkClick:m,children:i},n):/* @__PURE__ */e("span",{children:i},n)});/* @__PURE__ */
2
+ return t("div",{className:["doc-code-wrap",...V(p)].join(" "),children:[
3
+ /* @__PURE__ */e(E,{text:r,language:i,editable:!1,canCopy:!!l,display:p,onLanguage:()=>{},onDisplay:g}),
4
+ /* @__PURE__ */t("div",{className:"code-scroll",hidden:p.collapsed,tabIndex:0,"aria-label":h("代码内容"),children:[p.lineNumbers&&/* @__PURE__ */e("div",{className:"code-line-numbers","aria-hidden":"true",children:T(r)}),
5
+ /* @__PURE__ */e("pre",{className:"doc-code",children:/* @__PURE__ */e("code",{children:y})})]})]})}const textOf=e=>{var t;return e.text??(null==(t=e.content)?void 0:t.map(textOf).join(""))??""};function cssStyle(e){return Object.fromEntries(e.split(";").filter(Boolean).map(e=>{const t=e.indexOf(":"),n=e.slice(0,t).trim();return[n.startsWith("--")?n:n.replace(/-([a-z])/g,(e,t)=>t.toUpperCase()),e.slice(t+1).trim()]}))}function DocumentViewer(c){var M;const S=n().text,j=r(),E=c.value??c.modelValue;if(a(()=>()=>I(),[]),!E)/* @__PURE__ */return e("div",{className:"doc-renderer ywiki-prose ywiki-content"});const B=(null==(M=c.inlineMarks)?void 0:M.size)?c.inlineMarks:o(E,c.inlineComments??[]).byTextIndex;let T=0;function children(t,n=!1){var r;return null==(r=t.content)?void 0:r.map((t,r)=>/* @__PURE__ */e(l,{children:render(t,n)},r))}function render(n,r=!1){var a,l,o;const M=n.attrs??{};if("text"===n.type){let t=n.text??"",r=T++;const a=B.get(r)??[];a.length&&(t=/* @__PURE__ */e("span",{children:s(n.text??"",a).map((t,n)=>t.marks.length?/* @__PURE__ */e(CommentText,{marks:t.marks,activeId:c.activeCommentId,onMarkClick:c.onMarkClick,children:t.text},n):/* @__PURE__ */e("span",{children:t.text},n))}));for(const r of n.marks??[]){const n=r.attrs??{},a={bold:"strong",italic:"em",strike:"s",underline:"u",code:"code"}[r.type];if(a)t=i(a,null,t);else if("link"===r.type){const r=d(String(n.href??""));r&&(t=/* @__PURE__ */e("a",{href:r,target:"_blank",rel:"noopener noreferrer",children:t}))}else if("textStyle"===r.type||"highlight"===r.type){const a=m("highlight"===r.type?"highlight":"text",n.color);t=/* @__PURE__ */e("span",{...Object.fromEntries(Object.entries(a).filter(([e])=>"style"!==e)),style:cssStyle(a.style??""),children:t})}}return t}const I=M.textAlign??M.align,E={textAlign:["left","center","right","justify"].includes(String(I))?I:void 0,marginLeft:Number(M.indent)>0?24*Math.min(6,Number(M.indent))+"px":void 0};switch(n.type){case"doc":return children(n);case"paragraph":/* @__PURE__ */
6
+ return e("p",{style:E,children:children(n)||/* @__PURE__ */e("br",{})});case"heading":return i(`h${Math.max(1,Math.min(6,Number(M.level)||1))}`,{style:E,id:"string"==typeof M.anchor?M.anchor:"string"==typeof M.id?M.id:void 0},children(n));case"bulletList":/* @__PURE__ */
7
+ return e("ul",{children:children(n)});case"orderedList":/* @__PURE__ */
8
+ return e("ol",{start:Number(M.start)||1,children:children(n)});case"listItem":/* @__PURE__ */
9
+ return e("li",{children:children(n)});case"taskList":/* @__PURE__ */
10
+ return e("ul",{className:"doc-task-list",children:children(n)});case"taskItem":/* @__PURE__ */
11
+ return t("li",{className:"doc-task-item",children:[
12
+ /* @__PURE__ */e("input",{type:"checkbox",checked:!0===M.checked,disabled:!0,"aria-label":textOf((null==(a=n.content)?void 0:a[0])??n)||"未命名任务"}),
13
+ /* @__PURE__ */e("span",{children:children(n)})]});case"blockquote":/* @__PURE__ */
14
+ return e("blockquote",{children:children(n)});case"horizontalRule":/* @__PURE__ */
15
+ return e("hr",{});case"hardBreak":/* @__PURE__ */
16
+ return e("br",{});case"codeBlock":{const t=[];let r=0;const visit=e=>{var n;if("text"===e.type){for(const e of B.get(T++)??[])t.push({...e,from:r+e.from,to:r+e.to});r+=(null==(n=e.text)?void 0:n.length)??0}else for(const t of e.content??[])visit(t)};return visit(n),/* @__PURE__ */e(CodeView,{text:textOf(n),language:String(M.language??""),allowExport:c.allowExport,marks:t,activeId:c.activeCommentId,onMarkClick:c.onMarkClick})}case"table":{const r=g(n),a=f(r),i=r.length>0&&r.every(e=>e>0);/* @__PURE__ */
17
+ return e("div",{className:"doc-table-wrap",children:/* @__PURE__ */t("table",{className:"doc-table",style:a?i?{width:a}:{minWidth:a}:void 0,children:[r.length>0&&/* @__PURE__ */e("colgroup",{children:r.map((t,n)=>/* @__PURE__ */e("col",{style:t>0?{width:t}:{minWidth:120}},n))}),
18
+ /* @__PURE__ */e("tbody",{children:children(n)})]})})}case"tableRow":/* @__PURE__ */
19
+ return e("tr",{children:children(n)});case"tableCell":case"tableHeader":return i("tableHeader"===n.type?"th":"td",{colSpan:Number(M.colspan)||1,rowSpan:Number(M.rowspan)||1,style:{...E,backgroundColor:p(M.backgroundColor)??void 0}},children(n));case"image":{const n=Number(M.aspectRatio)||null,a=Number(M.galleryScale)||null,i=["left","center","right"].includes(String(M.align))?M.align:null,l=/* @__PURE__ */e(w,{id:String(M.attachmentId??"")||void 0,src:String(M.src??""),alt:String(M.alt??""),width:r?void 0:Number(M.width)||void 0,align:i,aspectRatio:n,galleryScale:a,fetcher:c.attachmentFetcher,allowExport:c.allowExport}),o="string"==typeof M.caption?M.caption.trim():"";return o?/* @__PURE__ */t("figure",{className:"doc-image-figure",style:r?{"--doc-image-aspect-ratio":String(n&&n>0?n:1),"--doc-image-weight":String(a&&a>0?a:1)}:void 0,children:[l,
20
+ /* @__PURE__ */e("figcaption",{className:"doc-image-caption",title:o,children:o})]}):l}case"imageGallery":/* @__PURE__ */
21
+ return e("div",{className:"doc-image-gallery","data-image-gallery":"true",style:{"--image-gallery-height":`${Math.min(480,Math.max(72,Number(M.height)||120))}px`},children:children(n,!0)});case"fileAttachment":/* @__PURE__ */
22
+ return e(b,{id:String(M.attachmentId??""),filename:String(M.filename??S("附件")),mimeType:String(M.mimeType??""),size:Number(M.size)||0,fetcher:c.attachmentFetcher,allowExport:c.allowExport});case"videoEmbed":/* @__PURE__ */
23
+ return e(v,{attrs:M});case"mathInline":case"mathBlock":/* @__PURE__ */
24
+ return e(x,{latex:String(M.latex??""),block:"mathBlock"===n.type});case"callout":{const{icon:r}=h(M),a=u(M);/* @__PURE__ */
25
+ return t("div",{...Object.fromEntries(Object.entries(a).filter(([e])=>"style"!==e)),className:"doc-callout",style:cssStyle(a.style??""),children:[r?/* @__PURE__ */e("span",{className:"callout-icon","aria-hidden":"true","data-callout-decoration":"true",children:r}):null,
26
+ /* @__PURE__ */e("div",{className:"doc-callout-content","data-callout-content":"true",children:children(n)})]})}case"columns":/* @__PURE__ */
27
+ return e("div",{className:"doc-columns",children:children(n)});case"column":/* @__PURE__ */
28
+ return e("div",{className:"doc-column",children:children(n)});case"pageLink":{const t=String(M.label??S("页面")),n=String(M.pageId??"");if(!n)/* @__PURE__ */return e("span",{children:t});const r=null==(o=c.resolvePageLink??(null==(l=j.references)?void 0:l.resolve))?void 0:o(n,t),a=d((null==r?void 0:r.href)??"");return a?/* @__PURE__ */e("a",{className:"doc-page-link",rel:"noopener noreferrer",href:a,onClick:e=>{var t;(null==r?void 0:r.external)||!(null==(t=j.references)?void 0:t.navigate)||0!==e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||(e.preventDefault(),j.references.navigate(a))},children:t}):/* @__PURE__ */e("span",{className:"doc-page-link-plain",children:t})}case"mention":{const e=String(M.label??S("用户"));return M.userId?/* @__PURE__ */t("span",{className:"doc-mention",title:`提及:${e}`,children:["@",e]}):/* @__PURE__ */t("span",{children:["@",e]})}case"mindMap":{const count=e=>("text"===e.type?1:0)+(e.content??[]).reduce((e,t)=>e+count(t),0);return T+=count(n),k(n)?/* @__PURE__ */e(N,{node:n,allowExport:c.allowExport,pageId:c.pageId,canComment:c.canComment,onCommentsChanged:c.onCommentsChanged,fetchAttachment:c.attachmentFetcher}):/* @__PURE__ */e("p",{role:"alert",children:S("思维导图格式无效")})}case"workbook":return y(n)?/* @__PURE__ */e(C,{value:n,allowExport:c.allowExport}):/* @__PURE__ */e("p",{role:"alert",children:S("工作表格式无效")});case"mindMapTopic":case"mindMapDescription":case"mindMapNote":case"mindMapRelation":return null;default:/* @__PURE__ */
29
+ return t("p",{role:"alert",children:[S("不支持的内容节点:"),n.type]})}}/* @__PURE__ */
30
+ return e("div",{className:"doc-renderer ywiki-prose ywiki-content",children:render(E)})}const L=DocumentViewer;export{L as DocRenderer,D as DocumentExportMenu,DocumentViewer,N as MindMapBlock};