wendang-react 0.6.3 → 0.6.5
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.
- package/NOTICE.md +1 -1
- package/README.md +133 -1
- package/dist/bindings/yjs.js +1 -5
- package/dist/chunks/AnchoredPanel-C7jMoPze.js +1 -0
- package/dist/chunks/DocumentExportMenu-CUMsgq3w.js +2 -0
- package/dist/chunks/Dropdown-D98tXfe0.js +3 -0
- package/dist/chunks/MindMapCanvas-C46Q5JBU.js +163 -0
- package/dist/chunks/MindMapViewer-C9zxZIW8.js +13 -0
- package/dist/chunks/SpreadsheetViewer-CoQ4VIgj.js +23 -0
- package/dist/chunks/code-highlight-BmaqTe1m.js +1 -30
- package/dist/chunks/code-highlight-engine-BFDzDPzy.js +1 -40
- package/dist/chunks/comment-hint-BhUxKjKK.js +14 -0
- package/dist/chunks/composition-state-Bl-U1R_2.js +1 -40
- package/dist/chunks/extensions-BefQ1tDm.js +14 -0
- package/dist/chunks/fuzzy-match-DYQR-4w2.js +1 -89
- package/dist/chunks/hooks-C53Dp0pr.js +1 -35
- package/dist/chunks/i18n-B0kCsIjc.js +2 -0
- package/dist/chunks/index-COeA2QcQ.js +15 -0
- package/dist/chunks/katex-WjrodtTU.js +1 -71
- package/dist/chunks/locale-DWpIJ_9X.js +1 -0
- package/dist/chunks/mind-map-controller-Ce76mETT.js +1 -0
- package/dist/chunks/mind-map-delete-CVsxdXfs.js +1 -31
- package/dist/chunks/mind-map-input-CEWRz_t6.js +1 -43
- package/dist/chunks/mind-topic-text-BHXkxexr.js +30 -0
- package/dist/chunks/popover-placement-D3xVYdkt.js +1 -47
- package/dist/chunks/worksheet-engine-c84sdD4N.js +1 -0
- package/dist/chunks/worksheet-preview-DsDVWxIM.js +1 -129
- package/dist/document/viewer.js +30 -289
- package/dist/document.js +120 -3811
- package/dist/export/json.js +1 -5
- package/dist/export/markdown.js +1 -2
- package/dist/export/mindmap.js +1 -2
- package/dist/export/pdf.js +1 -6
- package/dist/export/word.js +1 -2
- package/dist/export.js +1 -2
- package/dist/i18n.js +1 -0
- package/dist/index.js +1 -8
- package/dist/locales/en-US.js +1 -0
- package/dist/locales/es-ES.js +1 -0
- package/dist/locales/ja-JP.js +1 -0
- package/dist/locales/ko-KR.js +1 -0
- package/dist/locales/zh-CN.js +1 -0
- package/dist/locales/zh-TW.js +1 -0
- package/dist/mindmap/viewer.js +1 -6
- package/dist/mindmap.js +3 -123
- package/dist/shared.js +1 -52
- package/dist/spreadsheet/viewer.js +1 -5
- package/dist/spreadsheet/xlsx.js +1 -299
- package/dist/spreadsheet.js +2 -120
- package/dist/styles/callout.css +1 -34
- package/dist/styles/code-block.css +1 -58
- package/dist/styles/content-style.css +1 -619
- package/dist/styles/content-tokens.css +1 -29
- package/dist/styles/editor-interaction.css +1 -621
- package/dist/styles/file-video.css +1 -12
- package/dist/styles/image-preview.css +1 -103
- package/dist/styles/mind-map-block.css +1 -14
- package/dist/styles/mind-map-canvas.css +1 -80
- package/dist/styles/mind-map-comments.css +1 -93
- package/dist/styles/mind-map-details.css +1 -7
- package/dist/styles/mind-map-preview.css +1 -7
- package/dist/styles/mind-map-topic.css +1 -112
- package/dist/styles/page-picker.css +1 -47
- package/dist/styles/renderer.css +1 -45
- package/dist/styles/spreadsheet-editor.css +1 -3
- package/dist/styles/tokens.css +1 -142
- package/dist/styles/video-dialog.css +1 -41
- package/dist/styles/video-embed.css +1 -35
- package/dist/styles.css +1 -2655
- package/dist/types/editor/BlockAffordance.d.ts +5 -2
- package/dist/types/editor/CalloutView.d.ts +2 -1
- package/dist/types/editor/ImagePreview.d.ts +1 -1
- package/dist/types/editor/PagePicker.d.ts +1 -1
- package/dist/types/editor/extensions.d.ts +4 -1
- package/dist/types/engine/editor/block-commands.d.ts +1 -1
- package/dist/types/engine/editor/block-menu-hover.d.ts +16 -0
- package/dist/types/engine/editor/extensions/locale.d.ts +3 -0
- package/dist/types/engine/editor/nodes/image-nodeview.d.ts +1 -1
- package/dist/types/engine/editor/video-block-controls.d.ts +13 -0
- package/dist/types/engine/host.d.ts +60 -2
- package/dist/types/engine/renderer/attachments.d.ts +3 -3
- package/dist/types/engine/shared/video-feedback.d.ts +1 -1
- package/dist/types/engine/worksheets/worksheet-engine.d.ts +1 -0
- package/dist/types/engine/worksheets/worksheet-xlsx.d.ts +6 -1
- package/dist/types/host-types.d.ts +2 -60
- package/dist/types/host.d.ts +8 -1
- package/dist/types/i18n.d.ts +3 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/locales/en-US.d.ts +1 -0
- package/dist/types/locales/es-ES.d.ts +1 -0
- package/dist/types/locales/ja-JP.d.ts +1 -0
- package/dist/types/locales/ko-KR.d.ts +1 -0
- package/dist/types/locales/zh-CN.d.ts +1 -0
- package/dist/types/locales/zh-TW.d.ts +1 -0
- package/dist/types/renderer/media.d.ts +2 -1
- package/dist/types/spreadsheet/xlsx.d.ts +1 -1
- package/dist/types/wui/Dropdown.d.ts +2 -1
- package/dist/types/wui/index.d.ts +2 -1
- package/integrity.json +3140 -0
- package/package.json +15 -5
- package/verify-integrity.mjs +138 -0
- package/dist/chunks/AnchoredPanel-Cv4RURwF.js +0 -68
- package/dist/chunks/DocumentExportMenu-BrGipZ59.js +0 -75
- package/dist/chunks/MindMapCanvas-tkFBBs4g.js +0 -2090
- package/dist/chunks/MindMapViewer-DJrryb2Y.js +0 -180
- package/dist/chunks/SpreadsheetViewer-DxCxIUx_.js +0 -163
- package/dist/chunks/comment-hint-B9qcrqvn.js +0 -296
- package/dist/chunks/extensions-ByORRoRa.js +0 -4210
- package/dist/chunks/host-C-V688Rq.js +0 -197
- package/dist/chunks/index-DdfMnva8.js +0 -726
- package/dist/chunks/mind-map-controller-B6SxK3GZ.js +0 -479
- package/dist/chunks/mind-topic-text-DSyb95vL.js +0 -446
- package/dist/chunks/nodes-iKqTGr_N.js +0 -291
- package/dist/chunks/worksheet-engine-TJ54m0KC.js +0 -125
- package/third-party-notices/wendang-export@0.6.0-NOTICE.md.txt +0 -51
- package/third-party-notices/wendang-export@0.6.1-LICENSE.txt +0 -21
- package/third-party-notices/wendang-export@0.6.2-LICENSE.txt +0 -21
- package/third-party-notices/wendang-export@0.6.2-NOTICE.md.txt +0 -70
- /package/third-party-notices/{wendang-export@0.6.0-LICENSE.txt → wendang-export@0.6.4-LICENSE.txt} +0 -0
- /package/third-party-notices/{wendang-export@0.6.1-NOTICE.md.txt → wendang-export@0.6.4-NOTICE.md.txt} +0 -0
|
@@ -1,446 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
3
|
-
import { useState, useRef, useEffect, Fragment as Fragment$1 } from "react";
|
|
4
|
-
import { w as whenNearViewport, e as ensureKatexCss, r as renderMathAsync } from "./katex-WjrodtTU.js";
|
|
5
|
-
import { a as useContentContext, b as useContentHost, f as formatBytes, c as attachmentObjectUrl, u as unavailableAttachment, d as downloadAttachment } from "./host-C-V688Rq.js";
|
|
6
|
-
import { safeHref, documentColorAttributes } from "wendang/shared";
|
|
7
|
-
import { normalizeVideoEmbed, videoSourceUrl, VIDEO_PROVIDER_LABELS, videoPlayerUrl } from "wendang/internal/video-embed";
|
|
8
|
-
import { createPortal } from "react-dom";
|
|
9
|
-
import { l as lockScroll, t as trapTab } from "./index-DdfMnva8.js";
|
|
10
|
-
import { setMindTextMeasureFactory, MIND_TOPIC_FONT } from "wendang/internal/mind-topic-text";
|
|
11
|
-
const ROW_SELECTOR = ".ywiki-image-gallery, .doc-image-gallery";
|
|
12
|
-
function previewItemsFrom(image, fallbackLabel = "图片预览") {
|
|
13
|
-
const toItem = (img) => ({
|
|
14
|
-
src: img.getAttribute("src") ?? "",
|
|
15
|
-
label: img.getAttribute("alt") || fallbackLabel
|
|
16
|
-
});
|
|
17
|
-
const lonely = () => {
|
|
18
|
-
if (!(image instanceof HTMLImageElement)) return { items: [], index: 0 };
|
|
19
|
-
const src = image.getAttribute("src");
|
|
20
|
-
return src ? { items: [{ src, label: image.getAttribute("alt") || fallbackLabel }], index: 0 } : { items: [], index: 0 };
|
|
21
|
-
};
|
|
22
|
-
if (!image || typeof image.closest !== "function") return { items: [], index: 0 };
|
|
23
|
-
const row = image.closest(ROW_SELECTOR);
|
|
24
|
-
if (!row) return lonely();
|
|
25
|
-
const images = Array.from(row.querySelectorAll("img")).filter(
|
|
26
|
-
(el) => el instanceof HTMLImageElement && !!el.getAttribute("src")
|
|
27
|
-
);
|
|
28
|
-
if (images.length === 0) return { items: [], index: 0 };
|
|
29
|
-
const found = images.indexOf(image);
|
|
30
|
-
if (found < 0) return lonely();
|
|
31
|
-
return { items: images.map(toItem), index: found };
|
|
32
|
-
}
|
|
33
|
-
function stepPreviewIndex(index, length, delta) {
|
|
34
|
-
if (!Number.isFinite(index) || length <= 0) return 0;
|
|
35
|
-
const next = index + (Number.isFinite(delta) ? delta : 0);
|
|
36
|
-
return Math.max(0, Math.min(length - 1, Math.round(next)));
|
|
37
|
-
}
|
|
38
|
-
function canStepPreview(index, length, delta) {
|
|
39
|
-
if (length <= 1) return false;
|
|
40
|
-
return stepPreviewIndex(index, length, delta) !== stepPreviewIndex(index, length, 0);
|
|
41
|
-
}
|
|
42
|
-
function ImagePreview({ src, label = "图片预览", items, index = 0, onClose }) {
|
|
43
|
-
const { portal } = useContentContext();
|
|
44
|
-
const [current, setCurrent] = useState(index), [scale, setScale] = useState(1), [rotation, setRotation] = useState(0);
|
|
45
|
-
const [offset, setOffset] = useState({ x: 0, y: 0 }), [dragging, setDragging] = useState(false);
|
|
46
|
-
const mask = useRef(null), panel = useRef(null);
|
|
47
|
-
const drag = useRef(null), closeRef = useRef(onClose);
|
|
48
|
-
closeRef.current = onClose;
|
|
49
|
-
const list = (items == null ? void 0 : items.length) ? items : [{ src, label }], listRef = useRef(list);
|
|
50
|
-
listRef.current = list;
|
|
51
|
-
const currentRef = useRef(current);
|
|
52
|
-
currentRef.current = current;
|
|
53
|
-
const active = list[current] ?? list[0];
|
|
54
|
-
function reset() {
|
|
55
|
-
setScale(1);
|
|
56
|
-
setRotation(0);
|
|
57
|
-
setOffset({ x: 0, y: 0 });
|
|
58
|
-
}
|
|
59
|
-
function zoomBy(factor) {
|
|
60
|
-
setScale((value) => Math.min(8, Math.max(0.25, value * factor)));
|
|
61
|
-
}
|
|
62
|
-
function step(delta) {
|
|
63
|
-
const next = stepPreviewIndex(currentRef.current, listRef.current.length, delta);
|
|
64
|
-
if (next !== currentRef.current) {
|
|
65
|
-
currentRef.current = next;
|
|
66
|
-
setCurrent(next);
|
|
67
|
-
reset();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
currentRef.current = index;
|
|
72
|
-
setCurrent(index);
|
|
73
|
-
reset();
|
|
74
|
-
}, [src, index]);
|
|
75
|
-
useEffect(() => {
|
|
76
|
-
if (!portal) return;
|
|
77
|
-
const previous = document.activeElement, scroll = lockScroll();
|
|
78
|
-
const keydown = (event) => {
|
|
79
|
-
if (event.isComposing) return;
|
|
80
|
-
if (event.key === "Escape") {
|
|
81
|
-
event.preventDefault();
|
|
82
|
-
event.stopPropagation();
|
|
83
|
-
closeRef.current();
|
|
84
|
-
} else if (event.key === "ArrowLeft") {
|
|
85
|
-
event.preventDefault();
|
|
86
|
-
step(-1);
|
|
87
|
-
} else if (event.key === "ArrowRight") {
|
|
88
|
-
event.preventDefault();
|
|
89
|
-
step(1);
|
|
90
|
-
} else if (event.key === "+" || event.key === "=") {
|
|
91
|
-
event.preventDefault();
|
|
92
|
-
zoomBy(1.2);
|
|
93
|
-
} else if (event.key === "-" || event.key === "_") {
|
|
94
|
-
event.preventDefault();
|
|
95
|
-
zoomBy(1 / 1.2);
|
|
96
|
-
} else if (event.key === "0") {
|
|
97
|
-
event.preventDefault();
|
|
98
|
-
reset();
|
|
99
|
-
} else if (mask.current && trapTab(mask.current, event)) event.preventDefault();
|
|
100
|
-
};
|
|
101
|
-
window.addEventListener("keydown", keydown, true);
|
|
102
|
-
const frame = requestAnimationFrame(() => {
|
|
103
|
-
var _a;
|
|
104
|
-
return (_a = panel.current) == null ? void 0 : _a.focus();
|
|
105
|
-
});
|
|
106
|
-
return () => {
|
|
107
|
-
cancelAnimationFrame(frame);
|
|
108
|
-
window.removeEventListener("keydown", keydown, true);
|
|
109
|
-
scroll.release();
|
|
110
|
-
if (previous == null ? void 0 : previous.isConnected) previous.focus();
|
|
111
|
-
};
|
|
112
|
-
}, [portal]);
|
|
113
|
-
useEffect(() => {
|
|
114
|
-
const node = mask.current;
|
|
115
|
-
if (!node) return;
|
|
116
|
-
const wheel = (event) => {
|
|
117
|
-
event.preventDefault();
|
|
118
|
-
zoomBy(event.deltaY < 0 ? 1.12 : 1 / 1.12);
|
|
119
|
-
};
|
|
120
|
-
node.addEventListener("wheel", wheel, { passive: false });
|
|
121
|
-
return () => node.removeEventListener("wheel", wheel);
|
|
122
|
-
}, [portal]);
|
|
123
|
-
function endDrag() {
|
|
124
|
-
drag.current = null;
|
|
125
|
-
setDragging(false);
|
|
126
|
-
}
|
|
127
|
-
if (!portal) return null;
|
|
128
|
-
return createPortal(/* @__PURE__ */ jsxs("div", { ref: mask, className: "img-preview-mask", onMouseDown: (event) => {
|
|
129
|
-
if (drag.current || !(event.target instanceof Element) || event.target.closest(".img-preview-image,.img-preview-toolbar,.img-preview-nav")) return;
|
|
130
|
-
closeRef.current();
|
|
131
|
-
}, children: [
|
|
132
|
-
/* @__PURE__ */ jsx("div", { ref: panel, className: "img-preview-stage", role: "dialog", "aria-modal": "true", "aria-label": active.label, tabIndex: -1, children: /* @__PURE__ */ jsx(
|
|
133
|
-
"img",
|
|
134
|
-
{
|
|
135
|
-
className: `img-preview-image${dragging ? " is-dragging" : ""}`,
|
|
136
|
-
src: active.src,
|
|
137
|
-
alt: active.label,
|
|
138
|
-
draggable: false,
|
|
139
|
-
style: { transform: `translate(${offset.x}px, ${offset.y}px) scale(${scale}) rotate(${rotation}deg)` },
|
|
140
|
-
onPointerDown: (event) => {
|
|
141
|
-
var _a, _b;
|
|
142
|
-
if (event.button !== 0) return;
|
|
143
|
-
drag.current = { x: event.clientX, y: event.clientY, ox: offset.x, oy: offset.y };
|
|
144
|
-
setDragging(true);
|
|
145
|
-
(_b = (_a = event.currentTarget).setPointerCapture) == null ? void 0 : _b.call(_a, event.pointerId);
|
|
146
|
-
},
|
|
147
|
-
onPointerMove: (event) => {
|
|
148
|
-
const origin = drag.current;
|
|
149
|
-
if (origin) setOffset({ x: origin.ox + event.clientX - origin.x, y: origin.oy + event.clientY - origin.y });
|
|
150
|
-
},
|
|
151
|
-
onPointerUp: endDrag,
|
|
152
|
-
onPointerCancel: endDrag,
|
|
153
|
-
onLostPointerCapture: endDrag
|
|
154
|
-
}
|
|
155
|
-
) }),
|
|
156
|
-
list.length > 1 && /* @__PURE__ */ jsxs("div", { className: "img-preview-nav", role: "group", "aria-label": "图片翻页", children: [
|
|
157
|
-
/* @__PURE__ */ jsx(
|
|
158
|
-
"button",
|
|
159
|
-
{
|
|
160
|
-
type: "button",
|
|
161
|
-
className: "img-preview-nav-btn is-prev",
|
|
162
|
-
"aria-label": "上一张",
|
|
163
|
-
title: "上一张(←)",
|
|
164
|
-
disabled: !canStepPreview(current, list.length, -1),
|
|
165
|
-
onClick: () => step(-1),
|
|
166
|
-
children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "22", height: "22", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "m15 18-6-6 6-6" }) })
|
|
167
|
-
}
|
|
168
|
-
),
|
|
169
|
-
/* @__PURE__ */ jsx(
|
|
170
|
-
"button",
|
|
171
|
-
{
|
|
172
|
-
type: "button",
|
|
173
|
-
className: "img-preview-nav-btn is-next",
|
|
174
|
-
"aria-label": "下一张",
|
|
175
|
-
title: "下一张(→)",
|
|
176
|
-
disabled: !canStepPreview(current, list.length, 1),
|
|
177
|
-
onClick: () => step(1),
|
|
178
|
-
children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "22", height: "22", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "m9 18 6-6-6-6" }) })
|
|
179
|
-
}
|
|
180
|
-
)
|
|
181
|
-
] }),
|
|
182
|
-
/* @__PURE__ */ jsxs("div", { className: "img-preview-toolbar", role: "toolbar", "aria-label": "图片预览操作", children: [
|
|
183
|
-
/* @__PURE__ */ jsx("button", { type: "button", "aria-label": "缩小", title: "缩小(-)", onClick: () => zoomBy(1 / 1.2), children: "−" }),
|
|
184
|
-
/* @__PURE__ */ jsxs("span", { className: "img-preview-scale", "aria-live": "polite", children: [
|
|
185
|
-
Math.round(scale * 100),
|
|
186
|
-
"%"
|
|
187
|
-
] }),
|
|
188
|
-
/* @__PURE__ */ jsx("button", { type: "button", "aria-label": "放大", title: "放大(+)", onClick: () => zoomBy(1.2), children: "+" }),
|
|
189
|
-
/* @__PURE__ */ jsx("span", { className: "img-preview-divider" }),
|
|
190
|
-
/* @__PURE__ */ jsx("button", { type: "button", "aria-label": "向左旋转", title: "向左旋转", onClick: () => setRotation((value) => value - 90), children: "↺" }),
|
|
191
|
-
/* @__PURE__ */ jsx("button", { type: "button", "aria-label": "向右旋转", title: "向右旋转", onClick: () => setRotation((value) => value + 90), children: "↻" }),
|
|
192
|
-
/* @__PURE__ */ jsx("span", { className: "img-preview-divider" }),
|
|
193
|
-
/* @__PURE__ */ jsx("button", { type: "button", "aria-label": "还原", title: "还原(0)", onClick: reset, children: "还原" }),
|
|
194
|
-
list.length > 1 && /* @__PURE__ */ jsxs("span", { className: "img-preview-count", "aria-live": "polite", children: [
|
|
195
|
-
current + 1,
|
|
196
|
-
" / ",
|
|
197
|
-
list.length
|
|
198
|
-
] }),
|
|
199
|
-
/* @__PURE__ */ jsx("button", { type: "button", "aria-label": "关闭预览", title: "关闭(Esc)", onClick: onClose, children: "关闭" })
|
|
200
|
-
] })
|
|
201
|
-
] }), portal);
|
|
202
|
-
}
|
|
203
|
-
function AttachmentImage({ id, alt = "", width, fetcher, src, align, aspectRatio, galleryScale, className = "" }) {
|
|
204
|
-
var _a;
|
|
205
|
-
const host = useContentHost(), element = useRef(null);
|
|
206
|
-
const [result, setResult] = useState({ id: "", url: "", failed: false });
|
|
207
|
-
const [preview, setPreview] = useState(null);
|
|
208
|
-
useEffect(() => {
|
|
209
|
-
setResult({ id: id ?? "", url: "", failed: false });
|
|
210
|
-
const node = element.current;
|
|
211
|
-
if (!id || !node) return;
|
|
212
|
-
let alive = true, release;
|
|
213
|
-
const stop = whenNearViewport(node, () => {
|
|
214
|
-
var _a2;
|
|
215
|
-
release = attachmentObjectUrl(
|
|
216
|
-
id,
|
|
217
|
-
(url) => {
|
|
218
|
-
if (alive) setResult({ id, url, failed: false });
|
|
219
|
-
},
|
|
220
|
-
fetcher ?? ((_a2 = host.attachments) == null ? void 0 : _a2.fetch) ?? unavailableAttachment,
|
|
221
|
-
() => {
|
|
222
|
-
if (alive) setResult({ id, url: "", failed: true });
|
|
223
|
-
},
|
|
224
|
-
host.scope
|
|
225
|
-
);
|
|
226
|
-
});
|
|
227
|
-
return () => {
|
|
228
|
-
alive = false;
|
|
229
|
-
stop();
|
|
230
|
-
release == null ? void 0 : release();
|
|
231
|
-
};
|
|
232
|
-
}, [id, fetcher, (_a = host.attachments) == null ? void 0 : _a.fetch, host.scope]);
|
|
233
|
-
const source = id ? result.id === id ? result.url : "" : safeHref(src);
|
|
234
|
-
const failed = result.id === (id ?? "") && result.failed;
|
|
235
|
-
const transparent = "data:image/svg+xml;charset=utf-8,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%221%22 height=%221%22 preserveAspectRatio=%22none%22%3E%3C/svg%3E";
|
|
236
|
-
function open(image) {
|
|
237
|
-
if (source && !failed) setPreview(previewItemsFrom(image, alt || "图片预览"));
|
|
238
|
-
}
|
|
239
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
240
|
-
/* @__PURE__ */ jsx(
|
|
241
|
-
"img",
|
|
242
|
-
{
|
|
243
|
-
ref: element,
|
|
244
|
-
className: `doc-image${className ? ` ${className}` : ""}`,
|
|
245
|
-
"data-attachment-id": id,
|
|
246
|
-
src: source || (failed ? transparent : void 0),
|
|
247
|
-
alt: source ? alt : void 0,
|
|
248
|
-
title: failed ? alt : void 0,
|
|
249
|
-
"data-sized": width ? "true" : void 0,
|
|
250
|
-
"data-align": align ?? void 0,
|
|
251
|
-
"data-aspect-ratio": aspectRatio && aspectRatio > 0 ? aspectRatio : void 0,
|
|
252
|
-
"data-gallery-scale": galleryScale && galleryScale !== 1 ? galleryScale : void 0,
|
|
253
|
-
"data-loading": !source && !failed ? "true" : void 0,
|
|
254
|
-
"data-image-error": failed ? "true" : void 0,
|
|
255
|
-
style: {
|
|
256
|
-
...width ? { width: `${width}px` } : {},
|
|
257
|
-
...aspectRatio && aspectRatio > 0 ? { "--doc-image-aspect-ratio": String(aspectRatio) } : {},
|
|
258
|
-
...galleryScale && galleryScale > 0 && galleryScale !== 1 ? { "--doc-image-weight": String(galleryScale) } : {}
|
|
259
|
-
},
|
|
260
|
-
tabIndex: 0,
|
|
261
|
-
onError: () => setResult((previous) => ({ ...previous, failed: true })),
|
|
262
|
-
onClick: (event) => open(event.currentTarget),
|
|
263
|
-
onKeyDown: (event) => {
|
|
264
|
-
if (event.key === "Enter") open(event.currentTarget);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
),
|
|
268
|
-
preview && /* @__PURE__ */ jsx(ImagePreview, { src: source, label: alt || "图片预览", items: preview.items, index: preview.index, onClose: () => setPreview(null) })
|
|
269
|
-
] });
|
|
270
|
-
}
|
|
271
|
-
function MathView({ latex, block = false }) {
|
|
272
|
-
const [result, setResult] = useState({ html: "", error: null });
|
|
273
|
-
useEffect(() => {
|
|
274
|
-
let active = true;
|
|
275
|
-
void ensureKatexCss();
|
|
276
|
-
void renderMathAsync(latex, block).then((value) => {
|
|
277
|
-
if (active) setResult(value);
|
|
278
|
-
});
|
|
279
|
-
return () => {
|
|
280
|
-
active = false;
|
|
281
|
-
};
|
|
282
|
-
}, [latex, block]);
|
|
283
|
-
return result.html ? /* @__PURE__ */ jsx("span", { className: block ? "doc-math-block" : "doc-math-inline", dangerouslySetInnerHTML: { __html: result.html } }) : /* @__PURE__ */ jsx("span", { role: result.error ? "alert" : void 0, children: result.error ? `公式错误:${latex}` : latex });
|
|
284
|
-
}
|
|
285
|
-
function FileVideo({ id, mimeType, fetcher }) {
|
|
286
|
-
var _a;
|
|
287
|
-
const host = useContentHost(), root = useRef(null), [state, setState] = useState({ id: "", url: "", failed: false });
|
|
288
|
-
useEffect(() => {
|
|
289
|
-
setState({ id, url: "", failed: false });
|
|
290
|
-
if (!root.current || !id) return;
|
|
291
|
-
let active = true, release;
|
|
292
|
-
const stop = whenNearViewport(root.current, () => {
|
|
293
|
-
var _a2;
|
|
294
|
-
release = attachmentObjectUrl(
|
|
295
|
-
id,
|
|
296
|
-
(url2) => {
|
|
297
|
-
if (active) setState({ id, url: url2, failed: false });
|
|
298
|
-
},
|
|
299
|
-
fetcher ?? ((_a2 = host.attachments) == null ? void 0 : _a2.fetch) ?? unavailableAttachment,
|
|
300
|
-
() => {
|
|
301
|
-
if (active) setState({ id, url: "", failed: true });
|
|
302
|
-
},
|
|
303
|
-
host.scope
|
|
304
|
-
);
|
|
305
|
-
});
|
|
306
|
-
return () => {
|
|
307
|
-
active = false;
|
|
308
|
-
stop();
|
|
309
|
-
release == null ? void 0 : release();
|
|
310
|
-
};
|
|
311
|
-
}, [id, fetcher, (_a = host.attachments) == null ? void 0 : _a.fetch, host.scope]);
|
|
312
|
-
const url = state.id === id ? state.url : "", failed = state.id === id && state.failed;
|
|
313
|
-
return /* @__PURE__ */ jsx("div", { ref: root, className: "doc-file-video", children: url && !failed ? /* @__PURE__ */ jsx("video", { src: url, controls: true, preload: "metadata", onError: () => setState((value) => ({ ...value, failed: true })), children: /* @__PURE__ */ jsx("source", { src: url, type: mimeType }) }) : /* @__PURE__ */ jsx("p", { className: "doc-file-video-fallback", children: failed ? "视频加载失败。" : "视频加载中…" }) });
|
|
314
|
-
}
|
|
315
|
-
function FileView({ id, filename, mimeType = "", size = 0, fetcher, allowExport = false }) {
|
|
316
|
-
const host = useContentHost(), [failure, setFailure] = useState(""), [busy, setBusy] = useState(false), allowed = useRef(allowExport), alive = useRef(true);
|
|
317
|
-
allowed.current = allowExport;
|
|
318
|
-
useEffect(() => {
|
|
319
|
-
alive.current = true;
|
|
320
|
-
return () => {
|
|
321
|
-
alive.current = false;
|
|
322
|
-
};
|
|
323
|
-
}, []);
|
|
324
|
-
useEffect(() => {
|
|
325
|
-
setFailure("");
|
|
326
|
-
}, [id]);
|
|
327
|
-
async function download() {
|
|
328
|
-
if (busy || !allowed.current) return;
|
|
329
|
-
setBusy(true);
|
|
330
|
-
setFailure("");
|
|
331
|
-
try {
|
|
332
|
-
await downloadAttachment(id, filename, async (value) => {
|
|
333
|
-
var _a;
|
|
334
|
-
const blob = await (fetcher ?? ((_a = host.attachments) == null ? void 0 : _a.fetch) ?? unavailableAttachment)(value);
|
|
335
|
-
if (!alive.current || !allowed.current) throw new Error("当前不允许导出附件");
|
|
336
|
-
return blob;
|
|
337
|
-
});
|
|
338
|
-
} catch (error) {
|
|
339
|
-
if (alive.current) setFailure(error instanceof Error ? error.message : "附件下载失败");
|
|
340
|
-
} finally {
|
|
341
|
-
if (alive.current) setBusy(false);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
if (!id) return /* @__PURE__ */ jsx("div", { className: "doc-file is-missing", children: "[附件缺失]" });
|
|
345
|
-
return /* @__PURE__ */ jsxs("div", { className: "doc-file", children: [
|
|
346
|
-
/* @__PURE__ */ jsxs("div", { className: "doc-file-head", children: [
|
|
347
|
-
/* @__PURE__ */ jsx("span", { className: "doc-file-icon", children: mimeType.startsWith("video/") ? "▶" : mimeType.startsWith("image/") ? "🖼" : "📎" }),
|
|
348
|
-
/* @__PURE__ */ jsx("span", { className: "doc-file-name", title: filename, children: filename }),
|
|
349
|
-
/* @__PURE__ */ jsx("span", { className: "doc-file-size", children: formatBytes(size) }),
|
|
350
|
-
allowExport && /* @__PURE__ */ jsx("button", { type: "button", className: "doc-file-action", disabled: busy, onClick: () => void download(), children: busy ? "下载中…" : "下载" })
|
|
351
|
-
] }),
|
|
352
|
-
mimeType.startsWith("video/") ? /* @__PURE__ */ jsx(FileVideo, { id, mimeType, fetcher }) : mimeType.startsWith("image/") ? /* @__PURE__ */ jsx(AttachmentImage, { id, alt: filename, fetcher, className: "doc-file-image" }) : null,
|
|
353
|
-
failure && /* @__PURE__ */ jsx("p", { role: "alert", className: "doc-file-video-fallback", children: failure })
|
|
354
|
-
] });
|
|
355
|
-
}
|
|
356
|
-
function VideoView({ attrs }) {
|
|
357
|
-
const data = normalizeVideoEmbed(attrs), source = data ? videoSourceUrl(data) : "", platform = data ? VIDEO_PROVIDER_LABELS[data.provider] : "外部";
|
|
358
|
-
const [playing, setPlaying] = useState(""), [fits, setFits] = useState(true), [delayed, setDelayed] = useState(false);
|
|
359
|
-
const root = useRef(null), timer = useRef(void 0);
|
|
360
|
-
useEffect(() => {
|
|
361
|
-
if (!root.current || typeof ResizeObserver === "undefined") return;
|
|
362
|
-
const observer = new ResizeObserver(([entry]) => setFits(entry.contentRect.width >= 200));
|
|
363
|
-
observer.observe(root.current);
|
|
364
|
-
return () => observer.disconnect();
|
|
365
|
-
}, []);
|
|
366
|
-
useEffect(() => {
|
|
367
|
-
setPlaying("");
|
|
368
|
-
setDelayed(false);
|
|
369
|
-
clearTimeout(timer.current);
|
|
370
|
-
return () => clearTimeout(timer.current);
|
|
371
|
-
}, [source, fits]);
|
|
372
|
-
const active = !!source && playing === source;
|
|
373
|
-
return /* @__PURE__ */ jsx("section", { ref: root, className: "doc-video-embed", contentEditable: false, "aria-label": `${platform} 视频`, children: data ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
374
|
-
!active || !fits ? /* @__PURE__ */ jsxs("div", { className: "video-placeholder", children: [
|
|
375
|
-
/* @__PURE__ */ jsx("span", { className: "video-play-icon", "aria-hidden": "true", children: "▶" }),
|
|
376
|
-
/* @__PURE__ */ jsxs("strong", { children: [
|
|
377
|
-
platform,
|
|
378
|
-
" 视频",
|
|
379
|
-
data.page > 1 ? ` · 第 ${data.page} P` : ""
|
|
380
|
-
] }),
|
|
381
|
-
/* @__PURE__ */ jsx("span", { className: "video-id", children: data.videoId }),
|
|
382
|
-
fits && /* @__PURE__ */ jsx("button", { type: "button", className: "video-load", onClick: () => {
|
|
383
|
-
setPlaying(source);
|
|
384
|
-
timer.current = setTimeout(() => setDelayed(true), 12e3);
|
|
385
|
-
}, children: "加载视频" }),
|
|
386
|
-
/* @__PURE__ */ jsx("span", { className: "small muted", children: fits ? `点击后连接 ${platform} 播放器` : "当前栏宽较窄,请在原站观看" })
|
|
387
|
-
] }) : /* @__PURE__ */ jsx(
|
|
388
|
-
"iframe",
|
|
389
|
-
{
|
|
390
|
-
src: videoPlayerUrl(data),
|
|
391
|
-
title: `${platform} 视频 ${data.videoId}`,
|
|
392
|
-
loading: "lazy",
|
|
393
|
-
allow: "fullscreen; picture-in-picture; encrypted-media",
|
|
394
|
-
allowFullScreen: true,
|
|
395
|
-
sandbox: "allow-scripts allow-same-origin allow-presentation allow-popups",
|
|
396
|
-
referrerPolicy: "strict-origin-when-cross-origin",
|
|
397
|
-
onLoad: () => {
|
|
398
|
-
clearTimeout(timer.current);
|
|
399
|
-
setDelayed(false);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
),
|
|
403
|
-
/* @__PURE__ */ jsxs("div", { className: "video-footer", children: [
|
|
404
|
-
/* @__PURE__ */ jsx("span", { className: "small muted", children: active ? delayed ? "加载较慢,可在原站观看" : "无法播放时可在原站观看" : "外部视频" }),
|
|
405
|
-
/* @__PURE__ */ jsx("a", { href: source, target: "_blank", rel: "noopener noreferrer", onClick: (event) => event.stopPropagation(), children: "在原站打开 ↗" })
|
|
406
|
-
] })
|
|
407
|
-
] }) : /* @__PURE__ */ jsx("p", { className: "muted", children: "视频地址无效,请重新插入。" }) });
|
|
408
|
-
}
|
|
409
|
-
function TopicLabel({ topic }) {
|
|
410
|
-
return /* @__PURE__ */ jsx("span", { children: (topic.runs ?? [{ text: topic.text || "未命名主题" }]).map((run, index) => {
|
|
411
|
-
var _a, _b, _c, _d;
|
|
412
|
-
let child = run.text;
|
|
413
|
-
for (const mark of run.marks ?? []) {
|
|
414
|
-
if (mark.type === "bold") child = /* @__PURE__ */ jsx("strong", { children: child });
|
|
415
|
-
else if (mark.type === "italic") child = /* @__PURE__ */ jsx("em", { children: child });
|
|
416
|
-
else if (mark.type === "strike") child = /* @__PURE__ */ jsx("s", { children: child });
|
|
417
|
-
else if (mark.type === "link") child = /* @__PURE__ */ jsx("a", { href: safeHref((_a = mark.attrs) == null ? void 0 : _a.href), target: "_blank", rel: "noopener noreferrer", onClick: (event) => event.stopPropagation(), children: child });
|
|
418
|
-
else if (mark.type === "textStyle" || mark.type === "highlight") {
|
|
419
|
-
const data = documentColorAttributes(mark.type === "highlight" ? "highlight" : "text", (_b = mark.attrs) == null ? void 0 : _b.color);
|
|
420
|
-
const style = mark.type === "highlight" ? { backgroundColor: (_c = data.style) == null ? void 0 : _c.slice(data.style.indexOf(":") + 1).trim() } : { color: (_d = data.style) == null ? void 0 : _d.slice(data.style.indexOf(":") + 1).trim() };
|
|
421
|
-
child = /* @__PURE__ */ jsx("span", { style, children: child });
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
return /* @__PURE__ */ jsx(Fragment$1, { children: child }, index);
|
|
425
|
-
}) });
|
|
426
|
-
}
|
|
427
|
-
let context;
|
|
428
|
-
setMindTextMeasureFactory((fontSize, weight) => {
|
|
429
|
-
if (typeof document === "undefined") return null;
|
|
430
|
-
context ?? (context = document.createElement("canvas").getContext("2d"));
|
|
431
|
-
if (!context) return null;
|
|
432
|
-
const canvas = context, font = `${weight} ${fontSize}px ${MIND_TOPIC_FONT}`;
|
|
433
|
-
return (text) => {
|
|
434
|
-
canvas.font = font;
|
|
435
|
-
return canvas.measureText(text).width;
|
|
436
|
-
};
|
|
437
|
-
});
|
|
438
|
-
export {
|
|
439
|
-
AttachmentImage as A,
|
|
440
|
-
FileView as F,
|
|
441
|
-
ImagePreview as I,
|
|
442
|
-
MathView as M,
|
|
443
|
-
TopicLabel as T,
|
|
444
|
-
VideoView as V,
|
|
445
|
-
previewItemsFrom as p
|
|
446
|
-
};
|