tiptap-markdown-react 0.8.9 → 0.8.11
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/README.md +49 -4
- package/dist/ReportContent-c_UlJnVY.js +68 -0
- package/dist/ReportContent-c_UlJnVY.js.map +1 -0
- package/dist/components/EditorToolbar.d.ts +11 -3
- package/dist/{extractToc-DiY1iu1J.js → extractToc-CecK9W_w.js} +16 -81
- package/dist/extractToc-CecK9W_w.js.map +1 -0
- package/dist/importMenu.d.ts +16 -0
- package/dist/importMenu.test.d.ts +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +178 -228
- package/dist/index.js.map +1 -1
- package/dist/labels.d.ts +6 -2
- package/dist/reader.d.ts +16 -0
- package/dist/reader.entry.test.d.ts +1 -0
- package/dist/reader.js +14 -0
- package/dist/reader.js.map +1 -0
- package/dist/scrollToTocHeading-CwapFaVP.js +126 -0
- package/dist/scrollToTocHeading-CwapFaVP.js.map +1 -0
- package/dist/server.js +7 -5
- package/dist/server.js.map +1 -1
- package/package.json +5 -1
- package/dist/extractToc-DiY1iu1J.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -6,8 +6,10 @@ import Image from "@tiptap/extension-image";
|
|
|
6
6
|
import { TableOfContents } from "@tiptap/extension-table-of-contents";
|
|
7
7
|
import { NodeViewWrapper, ReactNodeViewRenderer, NodeViewContent, useEditor, EditorContent, useEditorState } from "@tiptap/react";
|
|
8
8
|
import { forwardRef, useEffect, useRef, useImperativeHandle, useMemo, useState, useId, useCallback, useContext, createContext } from "react";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { e as enrichMarkdownCitations, s as styles$5 } from "./ReportContent-c_UlJnVY.js";
|
|
10
|
+
import { R, a } from "./ReportContent-c_UlJnVY.js";
|
|
11
|
+
import { C as CitationRef, g as mergeCommentIntervals, f as mapCommentAnchors, b as baseExtensions, c as CommentMark, l as lowlight, m as makeTocGetId, p as pureCodeBlock, a as pureImage, h as renderMathInto, i as subscribeMathClick } from "./extractToc-CecK9W_w.js";
|
|
12
|
+
import { d, e, s } from "./extractToc-CecK9W_w.js";
|
|
11
13
|
import { Slice, Fragment } from "@tiptap/pm/model";
|
|
12
14
|
import { Extension, Node as Node$1 } from "@tiptap/core";
|
|
13
15
|
import { PluginKey, Plugin } from "@tiptap/pm/state";
|
|
@@ -16,6 +18,7 @@ import { FileHandlePlugin } from "@tiptap/extension-file-handler";
|
|
|
16
18
|
import * as DropdownMenu from "@radix-ui/react-dropdown-menu";
|
|
17
19
|
import * as Popover from "@radix-ui/react-popover";
|
|
18
20
|
import { createPortal } from "react-dom";
|
|
21
|
+
import { C, R as R2, f, r, s as s2 } from "./scrollToTocHeading-CwapFaVP.js";
|
|
19
22
|
function CitationRefView({ node, extension }) {
|
|
20
23
|
const index = String(node.attrs.index ?? "");
|
|
21
24
|
const url = node.attrs.url || null;
|
|
@@ -132,7 +135,7 @@ function collectCommentRanges(doc) {
|
|
|
132
135
|
return byId;
|
|
133
136
|
}
|
|
134
137
|
function rangesIntersectBlock(ranges, start, end) {
|
|
135
|
-
return ranges.some((
|
|
138
|
+
return ranges.some((r2) => r2.from < end && r2.to > start);
|
|
136
139
|
}
|
|
137
140
|
function gutterDom(commentIds, view, blockPos) {
|
|
138
141
|
const el = document.createElement("span");
|
|
@@ -140,13 +143,13 @@ function gutterDom(commentIds, view, blockPos) {
|
|
|
140
143
|
el.setAttribute("data-comment-ids", commentIds.join(" "));
|
|
141
144
|
el.textContent = String(commentIds.length);
|
|
142
145
|
el.title = `${commentIds.length}`;
|
|
143
|
-
el.addEventListener("mousedown", (
|
|
144
|
-
|
|
145
|
-
|
|
146
|
+
el.addEventListener("mousedown", (e2) => {
|
|
147
|
+
e2.preventDefault();
|
|
148
|
+
e2.stopPropagation();
|
|
146
149
|
});
|
|
147
|
-
el.addEventListener("click", (
|
|
148
|
-
|
|
149
|
-
|
|
150
|
+
el.addEventListener("click", (e2) => {
|
|
151
|
+
e2.preventDefault();
|
|
152
|
+
e2.stopPropagation();
|
|
150
153
|
view.dispatch(
|
|
151
154
|
view.state.tr.setMeta(COMMENT_ACTIVE_META, commentIds[0] ?? null).setMeta(COMMENT_GUTTER_META, {
|
|
152
155
|
commentIds,
|
|
@@ -197,9 +200,9 @@ function commentAnchorPlugin(options = {}) {
|
|
|
197
200
|
const activeId = ((_a = commentAnchorPluginKey.getState(state)) == null ? void 0 : _a.activeCommentId) ?? null;
|
|
198
201
|
if (activeId) {
|
|
199
202
|
const ranges = byId.get(activeId) ?? [];
|
|
200
|
-
for (const
|
|
203
|
+
for (const r2 of ranges) {
|
|
201
204
|
decos.push(
|
|
202
|
-
Decoration.inline(
|
|
205
|
+
Decoration.inline(r2.from, r2.to, { class: "tmr-comment-active" })
|
|
203
206
|
);
|
|
204
207
|
}
|
|
205
208
|
for (const b of bounds) {
|
|
@@ -258,7 +261,7 @@ function applyCommentAnchorsToEditor(editor, comments) {
|
|
|
258
261
|
mapCommentAnchors(
|
|
259
262
|
editor.state.doc,
|
|
260
263
|
comments.map((c) => ({ commentId: c.commentId, segments: c.segments }))
|
|
261
|
-
).map((
|
|
264
|
+
).map((r2) => ({ commentId: r2.commentId, ranges: r2.ranges }))
|
|
262
265
|
) : [];
|
|
263
266
|
const chain = editor.chain().clearCommentAnchors();
|
|
264
267
|
if (intervals.length > 0) chain.applyCommentAnchors(intervals);
|
|
@@ -412,11 +415,11 @@ const ImportPlaceholder = Node$1.create({
|
|
|
412
415
|
const MD_FILE_RE$1 = /\.(md|markdown)$/i;
|
|
413
416
|
const MD_MIME_TYPES = ["text/markdown", "text/x-markdown", ""];
|
|
414
417
|
async function insertMarkdownFiles(editor, files, pos) {
|
|
415
|
-
const mdFiles = files.filter((
|
|
418
|
+
const mdFiles = files.filter((f2) => MD_FILE_RE$1.test(f2.name));
|
|
416
419
|
if (mdFiles.length === 0) return;
|
|
417
420
|
const markdown = editor.markdown;
|
|
418
421
|
if (!markdown) return;
|
|
419
|
-
const texts = await Promise.all(mdFiles.map((
|
|
422
|
+
const texts = await Promise.all(mdFiles.map((f2) => f2.text()));
|
|
420
423
|
const json = markdown.parse(texts.join("\n\n"));
|
|
421
424
|
if (pos != null) {
|
|
422
425
|
editor.chain().focus().insertContentAt(pos, json).run();
|
|
@@ -660,6 +663,8 @@ const defaultToolbarLabels = {
|
|
|
660
663
|
imageUploadFailed: "Image upload failed",
|
|
661
664
|
importMarkdownFailed: "Markdown import failed",
|
|
662
665
|
importDocument: "Import",
|
|
666
|
+
importDocumentHint: "Import a file",
|
|
667
|
+
importDocumentOther: "Document",
|
|
663
668
|
importDocumentBusy: "Importing…",
|
|
664
669
|
importDocumentUploading: (percent) => `Uploading ${percent}%`,
|
|
665
670
|
importDocumentConverting: "Converting…",
|
|
@@ -671,7 +676,7 @@ const defaultToolbarLabels = {
|
|
|
671
676
|
more: "More",
|
|
672
677
|
codeBlock: "Code block",
|
|
673
678
|
hr: "Divider",
|
|
674
|
-
importMarkdown: "
|
|
679
|
+
importMarkdown: "Markdown",
|
|
675
680
|
tableInsert: "Insert table",
|
|
676
681
|
tableAddColumnBefore: "Add column before",
|
|
677
682
|
tableAddColumnAfter: "Add column after",
|
|
@@ -922,7 +927,7 @@ const MarkdownWysiwygEditor = forwardRef(function MarkdownWysiwygEditor2({
|
|
|
922
927
|
getId: makeTocGetId(),
|
|
923
928
|
onUpdate: (anchors) => {
|
|
924
929
|
onTocChange == null ? void 0 : onTocChange(
|
|
925
|
-
anchors.filter((
|
|
930
|
+
anchors.filter((a2) => a2.level <= 6).map((a2) => ({ id: a2.id, level: a2.level, text: a2.textContent }))
|
|
926
931
|
);
|
|
927
932
|
}
|
|
928
933
|
}),
|
|
@@ -1071,6 +1076,32 @@ function MarkdownPreview({
|
|
|
1071
1076
|
}
|
|
1072
1077
|
);
|
|
1073
1078
|
}
|
|
1079
|
+
const MD_FILE_RE = /\.(md|markdown)$/i;
|
|
1080
|
+
const MD_ACCEPT = ".md,.markdown,text/markdown";
|
|
1081
|
+
function resolveImportMenuItems({
|
|
1082
|
+
labels,
|
|
1083
|
+
onImportDocument,
|
|
1084
|
+
importAccept,
|
|
1085
|
+
importMenuItems
|
|
1086
|
+
}) {
|
|
1087
|
+
if (importMenuItems == null ? void 0 : importMenuItems.length) return importMenuItems;
|
|
1088
|
+
const markdown = {
|
|
1089
|
+
key: "markdown",
|
|
1090
|
+
label: labels.importMarkdown,
|
|
1091
|
+
accept: MD_ACCEPT
|
|
1092
|
+
};
|
|
1093
|
+
if (onImportDocument && importAccept) {
|
|
1094
|
+
return [
|
|
1095
|
+
markdown,
|
|
1096
|
+
{
|
|
1097
|
+
key: "document",
|
|
1098
|
+
label: labels.importDocumentOther,
|
|
1099
|
+
accept: importAccept
|
|
1100
|
+
}
|
|
1101
|
+
];
|
|
1102
|
+
}
|
|
1103
|
+
return [markdown];
|
|
1104
|
+
}
|
|
1074
1105
|
function insertMarkdown(editor, markdown, sources = []) {
|
|
1075
1106
|
const prepared = enrichMarkdownCitations(markdown, sources);
|
|
1076
1107
|
if (!prepared) return;
|
|
@@ -1096,9 +1127,9 @@ function insertPlainParagraph(editor, text) {
|
|
|
1096
1127
|
}
|
|
1097
1128
|
function splitTopLevelBlocks(markdown) {
|
|
1098
1129
|
const out = [];
|
|
1099
|
-
for (const [
|
|
1130
|
+
for (const [i, part] of markdown.split(/(```[\s\S]*?```)/).entries()) {
|
|
1100
1131
|
if (!part) continue;
|
|
1101
|
-
if (
|
|
1132
|
+
if (i % 2 === 1) {
|
|
1102
1133
|
out.push(part);
|
|
1103
1134
|
continue;
|
|
1104
1135
|
}
|
|
@@ -1217,7 +1248,7 @@ function ColorPalette({ value, onPick, labels }) {
|
|
|
1217
1248
|
{
|
|
1218
1249
|
type: "button",
|
|
1219
1250
|
className: styles$2.noneRow,
|
|
1220
|
-
onMouseDown: (
|
|
1251
|
+
onMouseDown: (e2) => e2.preventDefault(),
|
|
1221
1252
|
onClick: () => onPick(null),
|
|
1222
1253
|
children: [
|
|
1223
1254
|
/* @__PURE__ */ jsx("span", { className: styles$2.noneIcon, "aria-hidden": true }),
|
|
@@ -1233,7 +1264,7 @@ function ColorPalette({ value, onPick, labels }) {
|
|
|
1233
1264
|
style: { background: c },
|
|
1234
1265
|
title: c,
|
|
1235
1266
|
"aria-label": c,
|
|
1236
|
-
onMouseDown: (
|
|
1267
|
+
onMouseDown: (e2) => e2.preventDefault(),
|
|
1237
1268
|
onClick: () => onPick(c)
|
|
1238
1269
|
},
|
|
1239
1270
|
c
|
|
@@ -1247,7 +1278,7 @@ function ColorPalette({ value, onPick, labels }) {
|
|
|
1247
1278
|
style: { background: c },
|
|
1248
1279
|
title: c,
|
|
1249
1280
|
"aria-label": c,
|
|
1250
|
-
onMouseDown: (
|
|
1281
|
+
onMouseDown: (e2) => e2.preventDefault(),
|
|
1251
1282
|
onClick: () => onPick(c)
|
|
1252
1283
|
},
|
|
1253
1284
|
c
|
|
@@ -1274,8 +1305,8 @@ function getMathLayerStyle(editor, kind, pos) {
|
|
|
1274
1305
|
if (pos != null) {
|
|
1275
1306
|
const el = resolveNodeEl(editor, pos);
|
|
1276
1307
|
if (el) {
|
|
1277
|
-
const
|
|
1278
|
-
const top =
|
|
1308
|
+
const r2 = el.getBoundingClientRect();
|
|
1309
|
+
const top = r2.bottom - hostRect.top + gap;
|
|
1279
1310
|
if (kind === "block") {
|
|
1280
1311
|
return {
|
|
1281
1312
|
left: editorRect.left - hostRect.left,
|
|
@@ -1284,7 +1315,7 @@ function getMathLayerStyle(editor, kind, pos) {
|
|
|
1284
1315
|
};
|
|
1285
1316
|
}
|
|
1286
1317
|
return {
|
|
1287
|
-
left:
|
|
1318
|
+
left: r2.left - hostRect.left,
|
|
1288
1319
|
top
|
|
1289
1320
|
};
|
|
1290
1321
|
}
|
|
@@ -1367,9 +1398,9 @@ function MathEditorPopover({
|
|
|
1367
1398
|
};
|
|
1368
1399
|
}, [pos, editor, isBlock, latex, isNew]);
|
|
1369
1400
|
useEffect(() => {
|
|
1370
|
-
const onPtr = (
|
|
1401
|
+
const onPtr = (e2) => {
|
|
1371
1402
|
var _a;
|
|
1372
|
-
const target =
|
|
1403
|
+
const target = e2.target;
|
|
1373
1404
|
if (!(target instanceof Node)) return;
|
|
1374
1405
|
if ((_a = rootRef.current) == null ? void 0 : _a.contains(target)) return;
|
|
1375
1406
|
if (pos != null) {
|
|
@@ -1387,15 +1418,15 @@ function MathEditorPopover({
|
|
|
1387
1418
|
if (!canSubmit) return;
|
|
1388
1419
|
onConfirm(draft.trim());
|
|
1389
1420
|
};
|
|
1390
|
-
const onKeyDown = (
|
|
1391
|
-
if (
|
|
1392
|
-
|
|
1421
|
+
const onKeyDown = (e2) => {
|
|
1422
|
+
if (e2.key === "Escape") {
|
|
1423
|
+
e2.preventDefault();
|
|
1393
1424
|
onCancel();
|
|
1394
1425
|
return;
|
|
1395
1426
|
}
|
|
1396
|
-
if (
|
|
1397
|
-
if (isBlock && !(
|
|
1398
|
-
|
|
1427
|
+
if (e2.key !== "Enter") return;
|
|
1428
|
+
if (isBlock && !(e2.metaKey || e2.ctrlKey)) return;
|
|
1429
|
+
e2.preventDefault();
|
|
1399
1430
|
submit();
|
|
1400
1431
|
};
|
|
1401
1432
|
const field = isBlock ? /* @__PURE__ */ jsx(
|
|
@@ -1407,7 +1438,7 @@ function MathEditorPopover({
|
|
|
1407
1438
|
placeholder,
|
|
1408
1439
|
rows: Math.max(3, draft.split("\n").length),
|
|
1409
1440
|
"aria-labelledby": titleId,
|
|
1410
|
-
onChange: (
|
|
1441
|
+
onChange: (e2) => setDraft(e2.target.value),
|
|
1411
1442
|
onKeyDown
|
|
1412
1443
|
}
|
|
1413
1444
|
) : /* @__PURE__ */ jsx(
|
|
@@ -1418,7 +1449,7 @@ function MathEditorPopover({
|
|
|
1418
1449
|
value: draft,
|
|
1419
1450
|
placeholder,
|
|
1420
1451
|
"aria-labelledby": titleId,
|
|
1421
|
-
onChange: (
|
|
1452
|
+
onChange: (e2) => setDraft(e2.target.value),
|
|
1422
1453
|
onKeyDown
|
|
1423
1454
|
}
|
|
1424
1455
|
);
|
|
@@ -1499,7 +1530,7 @@ function ToolbarButton({
|
|
|
1499
1530
|
"aria-busy": busy,
|
|
1500
1531
|
disabled,
|
|
1501
1532
|
className: `${styles$3.btn} ${active2 ? styles$3.btnActive : ""}`,
|
|
1502
|
-
onMouseDown: (
|
|
1533
|
+
onMouseDown: (e2) => e2.preventDefault(),
|
|
1503
1534
|
onClick,
|
|
1504
1535
|
children
|
|
1505
1536
|
}
|
|
@@ -1524,8 +1555,8 @@ function MenuPopover({
|
|
|
1524
1555
|
className: styles$3.menu,
|
|
1525
1556
|
sideOffset: 4,
|
|
1526
1557
|
align: "start",
|
|
1527
|
-
onOpenAutoFocus: (
|
|
1528
|
-
onCloseAutoFocus: (
|
|
1558
|
+
onOpenAutoFocus: (e2) => e2.preventDefault(),
|
|
1559
|
+
onCloseAutoFocus: (e2) => e2.preventDefault(),
|
|
1529
1560
|
children: /* @__PURE__ */ jsx(MenuCloseCtx.Provider, { value: close, children })
|
|
1530
1561
|
}
|
|
1531
1562
|
) })
|
|
@@ -1544,7 +1575,7 @@ function MenuItem({
|
|
|
1544
1575
|
type: "button",
|
|
1545
1576
|
disabled,
|
|
1546
1577
|
className: `${styles$3.menuItem} ${selected ? styles$3.menuItemSelected : ""}`,
|
|
1547
|
-
onMouseDown: (
|
|
1578
|
+
onMouseDown: (e2) => e2.preventDefault(),
|
|
1548
1579
|
onClick: () => {
|
|
1549
1580
|
onSelect();
|
|
1550
1581
|
close();
|
|
@@ -1570,7 +1601,7 @@ function ColorPopover({
|
|
|
1570
1601
|
className: styles$3.btn,
|
|
1571
1602
|
title,
|
|
1572
1603
|
"aria-label": title,
|
|
1573
|
-
onMouseDown: (
|
|
1604
|
+
onMouseDown: (e2) => e2.preventDefault(),
|
|
1574
1605
|
children: /* @__PURE__ */ jsxs("span", { className: styles$3.colorIcon, children: [
|
|
1575
1606
|
/* @__PURE__ */ jsx("span", { className: styles$3.colorIconGlyph, children: glyph }),
|
|
1576
1607
|
/* @__PURE__ */ jsx("span", { className: styles$3.colorIconBar, style: { background: bar } })
|
|
@@ -1583,8 +1614,8 @@ function ColorPopover({
|
|
|
1583
1614
|
className: styles$3.popoverContent,
|
|
1584
1615
|
sideOffset: 4,
|
|
1585
1616
|
align: "start",
|
|
1586
|
-
onOpenAutoFocus: (
|
|
1587
|
-
onCloseAutoFocus: (
|
|
1617
|
+
onOpenAutoFocus: (e2) => e2.preventDefault(),
|
|
1618
|
+
onCloseAutoFocus: (e2) => e2.preventDefault(),
|
|
1588
1619
|
children: /* @__PURE__ */ jsx(
|
|
1589
1620
|
ColorPalette,
|
|
1590
1621
|
{
|
|
@@ -1602,14 +1633,13 @@ function ColorPopover({
|
|
|
1602
1633
|
}
|
|
1603
1634
|
const HEADING_LEVELS = [1, 2, 3, 4, 5, 6];
|
|
1604
1635
|
const FONT_SIZES = ["12px", "14px", "16px", "18px", "20px", "24px", "30px"];
|
|
1605
|
-
const MD_FILE_RE = /\.(md|markdown)$/i;
|
|
1606
|
-
const MD_ACCEPT = ".md,.markdown,text/markdown";
|
|
1607
1636
|
function EditorToolbar({
|
|
1608
1637
|
editor,
|
|
1609
1638
|
onImageUpload,
|
|
1610
1639
|
onError,
|
|
1611
1640
|
onImportDocument,
|
|
1612
1641
|
importAccept,
|
|
1642
|
+
importMenuItems,
|
|
1613
1643
|
showImport = true,
|
|
1614
1644
|
labels,
|
|
1615
1645
|
extraToolbarItems,
|
|
@@ -1618,30 +1648,30 @@ function EditorToolbar({
|
|
|
1618
1648
|
const t = { ...defaultToolbarLabels, ...labels };
|
|
1619
1649
|
const state = useEditorState({
|
|
1620
1650
|
editor,
|
|
1621
|
-
selector: ({ editor:
|
|
1622
|
-
bold:
|
|
1623
|
-
italic:
|
|
1624
|
-
underline:
|
|
1625
|
-
strike:
|
|
1626
|
-
code:
|
|
1627
|
-
link:
|
|
1628
|
-
taskList:
|
|
1651
|
+
selector: ({ editor: e2 }) => ({
|
|
1652
|
+
bold: e2.isActive("bold"),
|
|
1653
|
+
italic: e2.isActive("italic"),
|
|
1654
|
+
underline: e2.isActive("underline"),
|
|
1655
|
+
strike: e2.isActive("strike"),
|
|
1656
|
+
code: e2.isActive("code"),
|
|
1657
|
+
link: e2.isActive("link"),
|
|
1658
|
+
taskList: e2.isActive("taskList"),
|
|
1629
1659
|
headingLevel: [1, 2, 3, 4, 5, 6].find(
|
|
1630
|
-
(lv) =>
|
|
1660
|
+
(lv) => e2.isActive("heading", { level: lv })
|
|
1631
1661
|
),
|
|
1632
|
-
fontSize:
|
|
1633
|
-
isParagraph:
|
|
1634
|
-
bulletList:
|
|
1635
|
-
orderedList:
|
|
1636
|
-
blockquote:
|
|
1637
|
-
textColor:
|
|
1638
|
-
highlightColor:
|
|
1639
|
-
superscript:
|
|
1640
|
-
subscript:
|
|
1641
|
-
inTable:
|
|
1642
|
-
inTableHeader:
|
|
1643
|
-
canUndo:
|
|
1644
|
-
canRedo:
|
|
1662
|
+
fontSize: e2.getAttributes("textStyle").fontSize || void 0,
|
|
1663
|
+
isParagraph: e2.isActive("paragraph"),
|
|
1664
|
+
bulletList: e2.isActive("bulletList"),
|
|
1665
|
+
orderedList: e2.isActive("orderedList"),
|
|
1666
|
+
blockquote: e2.isActive("blockquote"),
|
|
1667
|
+
textColor: e2.getAttributes("textStyle").color || void 0,
|
|
1668
|
+
highlightColor: e2.getAttributes("highlight").color || void 0,
|
|
1669
|
+
superscript: e2.isActive("superscript"),
|
|
1670
|
+
subscript: e2.isActive("subscript"),
|
|
1671
|
+
inTable: e2.isActive("table"),
|
|
1672
|
+
inTableHeader: e2.isActive("tableHeader"),
|
|
1673
|
+
canUndo: e2.can().undo(),
|
|
1674
|
+
canRedo: e2.can().redo()
|
|
1645
1675
|
})
|
|
1646
1676
|
});
|
|
1647
1677
|
const [editorFocused, setEditorFocused] = useState(() => editor.isFocused);
|
|
@@ -1663,32 +1693,32 @@ function EditorToolbar({
|
|
|
1663
1693
|
const closeTableMenu = useCallback(() => setTableMenu(null), []);
|
|
1664
1694
|
useEffect(() => {
|
|
1665
1695
|
const dom = editor.view.dom;
|
|
1666
|
-
const onContextMenu = (
|
|
1696
|
+
const onContextMenu = (e2) => {
|
|
1667
1697
|
const coords = editor.view.posAtCoords({
|
|
1668
|
-
left:
|
|
1669
|
-
top:
|
|
1698
|
+
left: e2.clientX,
|
|
1699
|
+
top: e2.clientY
|
|
1670
1700
|
});
|
|
1671
1701
|
if (!coords) return;
|
|
1672
1702
|
const $pos = editor.state.doc.resolve(coords.pos);
|
|
1673
1703
|
let inTable = false;
|
|
1674
|
-
for (let
|
|
1675
|
-
if ($pos.node(
|
|
1704
|
+
for (let d2 = $pos.depth; d2 > 0; d2--) {
|
|
1705
|
+
if ($pos.node(d2).type.name === "table") {
|
|
1676
1706
|
inTable = true;
|
|
1677
1707
|
break;
|
|
1678
1708
|
}
|
|
1679
1709
|
}
|
|
1680
1710
|
if (!inTable) return;
|
|
1681
|
-
|
|
1711
|
+
e2.preventDefault();
|
|
1682
1712
|
editor.chain().focus().setTextSelection(coords.pos).run();
|
|
1683
|
-
setTableMenu({ x:
|
|
1713
|
+
setTableMenu({ x: e2.clientX, y: e2.clientY });
|
|
1684
1714
|
};
|
|
1685
1715
|
dom.addEventListener("contextmenu", onContextMenu);
|
|
1686
1716
|
return () => dom.removeEventListener("contextmenu", onContextMenu);
|
|
1687
1717
|
}, [editor]);
|
|
1688
1718
|
useEffect(() => {
|
|
1689
1719
|
if (!tableMenu) return;
|
|
1690
|
-
const onKey = (
|
|
1691
|
-
if (
|
|
1720
|
+
const onKey = (e2) => {
|
|
1721
|
+
if (e2.key === "Escape") closeTableMenu();
|
|
1692
1722
|
};
|
|
1693
1723
|
document.addEventListener("mousedown", closeTableMenu);
|
|
1694
1724
|
document.addEventListener("keydown", onKey, true);
|
|
@@ -1708,10 +1738,10 @@ function EditorToolbar({
|
|
|
1708
1738
|
var _a;
|
|
1709
1739
|
return (_a = fileInputRef.current) == null ? void 0 : _a.click();
|
|
1710
1740
|
};
|
|
1711
|
-
const handleImageChange = async (
|
|
1741
|
+
const handleImageChange = async (e2) => {
|
|
1712
1742
|
var _a;
|
|
1713
|
-
const file = (_a =
|
|
1714
|
-
|
|
1743
|
+
const file = (_a = e2.target.files) == null ? void 0 : _a[0];
|
|
1744
|
+
e2.target.value = "";
|
|
1715
1745
|
if (!file || !onImageUpload) return;
|
|
1716
1746
|
try {
|
|
1717
1747
|
const url = await onImageUpload(file);
|
|
@@ -1731,10 +1761,10 @@ function EditorToolbar({
|
|
|
1731
1761
|
var _a;
|
|
1732
1762
|
return (_a = importAbortRef.current) == null ? void 0 : _a.abort();
|
|
1733
1763
|
}, []);
|
|
1734
|
-
const handleImportChange = async (
|
|
1764
|
+
const handleImportChange = async (e2) => {
|
|
1735
1765
|
var _a;
|
|
1736
|
-
const file = (_a =
|
|
1737
|
-
|
|
1766
|
+
const file = (_a = e2.target.files) == null ? void 0 : _a[0];
|
|
1767
|
+
e2.target.value = "";
|
|
1738
1768
|
if (!file) return;
|
|
1739
1769
|
if (MD_FILE_RE.test(file.name)) {
|
|
1740
1770
|
try {
|
|
@@ -1778,7 +1808,20 @@ function EditorToolbar({
|
|
|
1778
1808
|
setImporting(null);
|
|
1779
1809
|
}
|
|
1780
1810
|
};
|
|
1781
|
-
const
|
|
1811
|
+
const importItems = resolveImportMenuItems({
|
|
1812
|
+
labels: t,
|
|
1813
|
+
onImportDocument,
|
|
1814
|
+
importAccept,
|
|
1815
|
+
importMenuItems
|
|
1816
|
+
});
|
|
1817
|
+
const pickImport = (accept) => {
|
|
1818
|
+
const input = importInputRef.current;
|
|
1819
|
+
if (!input) return;
|
|
1820
|
+
input.accept = accept;
|
|
1821
|
+
input.value = "";
|
|
1822
|
+
input.click();
|
|
1823
|
+
};
|
|
1824
|
+
const importTitle = importing ? t.importDocumentBusy : t.importDocumentHint;
|
|
1782
1825
|
const applyTextColor = (color) => {
|
|
1783
1826
|
if (color) chain().setColor(color).run();
|
|
1784
1827
|
else chain().unsetColor().run();
|
|
@@ -1908,7 +1951,7 @@ function EditorToolbar({
|
|
|
1908
1951
|
type: "button",
|
|
1909
1952
|
className: styles$3.styleTrigger,
|
|
1910
1953
|
title: t.style,
|
|
1911
|
-
onMouseDown: (
|
|
1954
|
+
onMouseDown: (e2) => e2.preventDefault(),
|
|
1912
1955
|
children: [
|
|
1913
1956
|
/* @__PURE__ */ jsx("span", { className: styles$3.styleTriggerLabel, children: t.style }),
|
|
1914
1957
|
/* @__PURE__ */ jsx(ChevronDownIcon, { size: 12, className: styles$3.styleTriggerCaret })
|
|
@@ -1953,7 +1996,7 @@ function EditorToolbar({
|
|
|
1953
1996
|
title: t.fontSize,
|
|
1954
1997
|
"aria-label": t.fontSize,
|
|
1955
1998
|
disabled: !canEditFontSize,
|
|
1956
|
-
onMouseDown: (
|
|
1999
|
+
onMouseDown: (e2) => e2.preventDefault(),
|
|
1957
2000
|
children: [
|
|
1958
2001
|
/* @__PURE__ */ jsx("span", { className: styles$3.styleTriggerLabel, children: state.fontSize || t.fontSize }),
|
|
1959
2002
|
/* @__PURE__ */ jsx(ChevronDownIcon, { size: 12, className: styles$3.styleTriggerCaret })
|
|
@@ -2065,7 +2108,7 @@ function EditorToolbar({
|
|
|
2065
2108
|
className: `${styles$3.scriptTrigger} ${scriptActive !== "normal" ? styles$3.btnActive : ""}`,
|
|
2066
2109
|
title: t.scriptMenu,
|
|
2067
2110
|
"aria-label": t.scriptMenu,
|
|
2068
|
-
onMouseDown: (
|
|
2111
|
+
onMouseDown: (e2) => e2.preventDefault(),
|
|
2069
2112
|
children: [
|
|
2070
2113
|
/* @__PURE__ */ jsx("span", { className: styles$3.scriptTriggerGlyph, children: "A" }),
|
|
2071
2114
|
/* @__PURE__ */ jsx(ChevronDownIcon, { size: 12, className: styles$3.styleTriggerCaret })
|
|
@@ -2130,19 +2173,41 @@ function EditorToolbar({
|
|
|
2130
2173
|
}
|
|
2131
2174
|
)
|
|
2132
2175
|
] }) : null,
|
|
2133
|
-
showImport ? /* @__PURE__ */ jsx(
|
|
2134
|
-
|
|
2176
|
+
showImport ? /* @__PURE__ */ jsx(
|
|
2177
|
+
MenuPopover,
|
|
2135
2178
|
{
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2179
|
+
trigger: /* @__PURE__ */ jsxs(
|
|
2180
|
+
"button",
|
|
2181
|
+
{
|
|
2182
|
+
type: "button",
|
|
2183
|
+
className: styles$3.styleTrigger,
|
|
2184
|
+
title: importTitle,
|
|
2185
|
+
"aria-label": importTitle,
|
|
2186
|
+
"aria-busy": !!importing,
|
|
2187
|
+
disabled: !!importing,
|
|
2188
|
+
onMouseDown: (e2) => e2.preventDefault(),
|
|
2189
|
+
children: [
|
|
2190
|
+
/* @__PURE__ */ jsx("span", { className: styles$3.styleTriggerLabel, children: t.importDocument }),
|
|
2191
|
+
/* @__PURE__ */ jsx(
|
|
2192
|
+
ChevronDownIcon,
|
|
2193
|
+
{
|
|
2194
|
+
size: 12,
|
|
2195
|
+
className: styles$3.styleTriggerCaret
|
|
2196
|
+
}
|
|
2197
|
+
)
|
|
2198
|
+
]
|
|
2199
|
+
}
|
|
2200
|
+
),
|
|
2201
|
+
children: importItems.map((item2) => /* @__PURE__ */ jsx(
|
|
2202
|
+
MenuItem,
|
|
2203
|
+
{
|
|
2204
|
+
onSelect: () => pickImport(item2.accept),
|
|
2205
|
+
children: item2.label
|
|
2206
|
+
},
|
|
2207
|
+
item2.key
|
|
2208
|
+
))
|
|
2144
2209
|
}
|
|
2145
|
-
)
|
|
2210
|
+
) : null,
|
|
2146
2211
|
/* @__PURE__ */ jsx(
|
|
2147
2212
|
ToolbarButton,
|
|
2148
2213
|
{
|
|
@@ -2190,7 +2255,7 @@ function EditorToolbar({
|
|
|
2190
2255
|
type: "button",
|
|
2191
2256
|
className: styles$3.styleTrigger,
|
|
2192
2257
|
title: t.more,
|
|
2193
|
-
onMouseDown: (
|
|
2258
|
+
onMouseDown: (e2) => e2.preventDefault(),
|
|
2194
2259
|
children: [
|
|
2195
2260
|
/* @__PURE__ */ jsx("span", { className: styles$3.styleTriggerLabel, children: t.more }),
|
|
2196
2261
|
/* @__PURE__ */ jsx(ChevronDownIcon, { size: 12, className: styles$3.styleTriggerCaret })
|
|
@@ -2248,7 +2313,6 @@ function EditorToolbar({
|
|
|
2248
2313
|
{
|
|
2249
2314
|
ref: importInputRef,
|
|
2250
2315
|
type: "file",
|
|
2251
|
-
accept: onImportDocument && importAccept ? `${MD_ACCEPT},${importAccept}` : MD_ACCEPT,
|
|
2252
2316
|
hidden: true,
|
|
2253
2317
|
onChange: handleImportChange
|
|
2254
2318
|
}
|
|
@@ -2275,8 +2339,8 @@ function EditorToolbar({
|
|
|
2275
2339
|
{
|
|
2276
2340
|
className: styles$3.tableBubble,
|
|
2277
2341
|
style: { position: "fixed", left: tableMenu.x, top: tableMenu.y },
|
|
2278
|
-
onMouseDown: (
|
|
2279
|
-
onContextMenu: (
|
|
2342
|
+
onMouseDown: (e2) => e2.stopPropagation(),
|
|
2343
|
+
onContextMenu: (e2) => e2.preventDefault(),
|
|
2280
2344
|
children: [
|
|
2281
2345
|
/* @__PURE__ */ jsx(
|
|
2282
2346
|
ToolbarButton,
|
|
@@ -2407,7 +2471,7 @@ function TocPanel({ items, activeId, onItemClick, labels }) {
|
|
|
2407
2471
|
});
|
|
2408
2472
|
}, [activeId]);
|
|
2409
2473
|
if (!items.length) return null;
|
|
2410
|
-
const minLevel = Math.min(...items.map((
|
|
2474
|
+
const minLevel = Math.min(...items.map((i) => i.level));
|
|
2411
2475
|
const handleClick = (item2) => {
|
|
2412
2476
|
if (item2.locked) return;
|
|
2413
2477
|
onItemClick == null ? void 0 : onItemClick(item2);
|
|
@@ -2421,8 +2485,8 @@ function TocPanel({ items, activeId, onItemClick, labels }) {
|
|
|
2421
2485
|
style: { paddingLeft: `${(item2.level - minLevel) * 12 + 12}px` },
|
|
2422
2486
|
"aria-current": item2.id === activeId ? "true" : void 0,
|
|
2423
2487
|
"aria-disabled": item2.locked ? "true" : void 0,
|
|
2424
|
-
onClick: (
|
|
2425
|
-
|
|
2488
|
+
onClick: (e2) => {
|
|
2489
|
+
e2.preventDefault();
|
|
2426
2490
|
handleClick(item2);
|
|
2427
2491
|
},
|
|
2428
2492
|
children: [
|
|
@@ -2495,120 +2559,6 @@ function TocPanel({ items, activeId, onItemClick, labels }) {
|
|
|
2495
2559
|
list2
|
|
2496
2560
|
] });
|
|
2497
2561
|
}
|
|
2498
|
-
function findCitationRefElement(target, root) {
|
|
2499
|
-
let node = null;
|
|
2500
|
-
if (target instanceof Element) node = target;
|
|
2501
|
-
else if (target instanceof Text) node = target.parentElement;
|
|
2502
|
-
else if (target instanceof Node) node = target.parentElement;
|
|
2503
|
-
if (!(node instanceof Element)) return null;
|
|
2504
|
-
const el = node.closest(".citation-ref");
|
|
2505
|
-
if (!(el instanceof HTMLElement)) return null;
|
|
2506
|
-
if (!root.contains(el)) return null;
|
|
2507
|
-
return el;
|
|
2508
|
-
}
|
|
2509
|
-
function readCitationAttrs(el) {
|
|
2510
|
-
var _a;
|
|
2511
|
-
return {
|
|
2512
|
-
index: el.getAttribute("data-index") || ((_a = el.textContent) == null ? void 0 : _a.trim()) || "",
|
|
2513
|
-
url: el.getAttribute("data-url"),
|
|
2514
|
-
title: el.getAttribute("data-title")
|
|
2515
|
-
};
|
|
2516
|
-
}
|
|
2517
|
-
function CitationInteractive({
|
|
2518
|
-
containerRef,
|
|
2519
|
-
onCitationEnter,
|
|
2520
|
-
onCitationLeave
|
|
2521
|
-
}) {
|
|
2522
|
-
const enterRef = useRef(onCitationEnter);
|
|
2523
|
-
const leaveRef = useRef(onCitationLeave);
|
|
2524
|
-
enterRef.current = onCitationEnter;
|
|
2525
|
-
leaveRef.current = onCitationLeave;
|
|
2526
|
-
useEffect(() => {
|
|
2527
|
-
const root = containerRef.current;
|
|
2528
|
-
if (!root) return;
|
|
2529
|
-
let currentEl = null;
|
|
2530
|
-
const emitEnter = (el) => {
|
|
2531
|
-
currentEl = el;
|
|
2532
|
-
const attrs = readCitationAttrs(el);
|
|
2533
|
-
enterRef.current({ index: attrs.index, attrs, anchorEl: el });
|
|
2534
|
-
};
|
|
2535
|
-
const emitLeave = () => {
|
|
2536
|
-
if (!currentEl) return;
|
|
2537
|
-
currentEl = null;
|
|
2538
|
-
leaveRef.current();
|
|
2539
|
-
};
|
|
2540
|
-
const ACTIVE_ATTR = "data-tmr-citation-active";
|
|
2541
|
-
const onClick = (e) => {
|
|
2542
|
-
const el = findCitationRefElement(e.target, root);
|
|
2543
|
-
if (el) {
|
|
2544
|
-
e.preventDefault();
|
|
2545
|
-
e.stopPropagation();
|
|
2546
|
-
if (el === currentEl && el.hasAttribute(ACTIVE_ATTR)) {
|
|
2547
|
-
emitLeave();
|
|
2548
|
-
return;
|
|
2549
|
-
}
|
|
2550
|
-
emitEnter(el);
|
|
2551
|
-
return;
|
|
2552
|
-
}
|
|
2553
|
-
emitLeave();
|
|
2554
|
-
};
|
|
2555
|
-
const onKeyDown = (e) => {
|
|
2556
|
-
if (e.key === "Escape") emitLeave();
|
|
2557
|
-
};
|
|
2558
|
-
root.addEventListener("click", onClick, true);
|
|
2559
|
-
document.addEventListener("keydown", onKeyDown);
|
|
2560
|
-
return () => {
|
|
2561
|
-
root.removeEventListener("click", onClick, true);
|
|
2562
|
-
document.removeEventListener("keydown", onKeyDown);
|
|
2563
|
-
};
|
|
2564
|
-
}, [containerRef]);
|
|
2565
|
-
return null;
|
|
2566
|
-
}
|
|
2567
|
-
function ReportContentInteractive({
|
|
2568
|
-
onCitationEnter,
|
|
2569
|
-
onCitationLeave,
|
|
2570
|
-
className,
|
|
2571
|
-
html,
|
|
2572
|
-
...rest
|
|
2573
|
-
}) {
|
|
2574
|
-
const ref = useRef(null);
|
|
2575
|
-
return /* @__PURE__ */ jsxs("div", { ref, className, children: [
|
|
2576
|
-
/* @__PURE__ */ jsx(ReportContent, { html, ...rest }),
|
|
2577
|
-
/* @__PURE__ */ jsx(
|
|
2578
|
-
CitationInteractive,
|
|
2579
|
-
{
|
|
2580
|
-
containerRef: ref,
|
|
2581
|
-
onCitationEnter,
|
|
2582
|
-
onCitationLeave
|
|
2583
|
-
}
|
|
2584
|
-
)
|
|
2585
|
-
] });
|
|
2586
|
-
}
|
|
2587
|
-
function easeOutCubic(t) {
|
|
2588
|
-
return 1 - (1 - t) * (1 - t) * (1 - t);
|
|
2589
|
-
}
|
|
2590
|
-
function scrollToTocHeading(headingId, scrollContainer, options) {
|
|
2591
|
-
const el = scrollContainer.querySelector(
|
|
2592
|
-
`[data-toc-id="${CSS.escape(headingId)}"]`
|
|
2593
|
-
);
|
|
2594
|
-
if (!el) return;
|
|
2595
|
-
const startTop = scrollContainer.scrollTop;
|
|
2596
|
-
const rootRect = scrollContainer.getBoundingClientRect();
|
|
2597
|
-
const elRect = el.getBoundingClientRect();
|
|
2598
|
-
const targetTop = startTop + (elRect.top - rootRect.top);
|
|
2599
|
-
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
2600
|
-
scrollContainer.scrollTop = targetTop;
|
|
2601
|
-
return;
|
|
2602
|
-
}
|
|
2603
|
-
const duration = (options == null ? void 0 : options.duration) ?? 400;
|
|
2604
|
-
const start = performance.now();
|
|
2605
|
-
const animate = () => {
|
|
2606
|
-
const t = Math.min((performance.now() - start) / duration, 1);
|
|
2607
|
-
scrollContainer.scrollTop = startTop + (targetTop - startTop) * easeOutCubic(t);
|
|
2608
|
-
if (t < 1) requestAnimationFrame(animate);
|
|
2609
|
-
};
|
|
2610
|
-
requestAnimationFrame(animate);
|
|
2611
|
-
}
|
|
2612
2562
|
const popoverAnchor = "_popoverAnchor_9y5t0_55";
|
|
2613
2563
|
const popoverContent = "_popoverContent_9y5t0_62";
|
|
2614
2564
|
const styles = {
|
|
@@ -2640,8 +2590,8 @@ function CommentPopover({
|
|
|
2640
2590
|
side,
|
|
2641
2591
|
align,
|
|
2642
2592
|
sideOffset,
|
|
2643
|
-
onOpenAutoFocus: (
|
|
2644
|
-
onCloseAutoFocus: (
|
|
2593
|
+
onOpenAutoFocus: (e2) => e2.preventDefault(),
|
|
2594
|
+
onCloseAutoFocus: (e2) => e2.preventDefault(),
|
|
2645
2595
|
children
|
|
2646
2596
|
}
|
|
2647
2597
|
) })
|
|
@@ -2654,7 +2604,7 @@ export {
|
|
|
2654
2604
|
COMMENT_GUTTER_META,
|
|
2655
2605
|
CheckIcon,
|
|
2656
2606
|
ChevronDownIcon,
|
|
2657
|
-
CitationInteractive,
|
|
2607
|
+
C as CitationInteractive,
|
|
2658
2608
|
CitationRef,
|
|
2659
2609
|
CodeBlockView,
|
|
2660
2610
|
CodeIcon,
|
|
@@ -2680,8 +2630,8 @@ export {
|
|
|
2680
2630
|
MarkdownWysiwygEditor,
|
|
2681
2631
|
MenuIcon,
|
|
2682
2632
|
RedoIcon,
|
|
2683
|
-
ReportContent,
|
|
2684
|
-
ReportContentInteractive,
|
|
2633
|
+
R as ReportContent,
|
|
2634
|
+
R2 as ReportContentInteractive,
|
|
2685
2635
|
RowAfterIcon,
|
|
2686
2636
|
RowBeforeIcon,
|
|
2687
2637
|
RowDeleteIcon,
|
|
@@ -2690,10 +2640,10 @@ export {
|
|
|
2690
2640
|
TrashIcon,
|
|
2691
2641
|
UnderlineIcon,
|
|
2692
2642
|
UndoIcon,
|
|
2693
|
-
|
|
2643
|
+
a as applyCitationSources,
|
|
2694
2644
|
applyCommentAnchorsToEditor,
|
|
2695
2645
|
baseExtensions,
|
|
2696
|
-
|
|
2646
|
+
d as blockTextHash,
|
|
2697
2647
|
collectCommentIds,
|
|
2698
2648
|
commentAnchorExtension,
|
|
2699
2649
|
commentAnchorPlugin,
|
|
@@ -2706,8 +2656,8 @@ export {
|
|
|
2706
2656
|
defaultTocLabels,
|
|
2707
2657
|
defaultToolbarLabels,
|
|
2708
2658
|
enrichMarkdownCitations,
|
|
2709
|
-
|
|
2710
|
-
findCitationRefElement,
|
|
2659
|
+
e as extractToc,
|
|
2660
|
+
f as findCitationRefElement,
|
|
2711
2661
|
focusComment,
|
|
2712
2662
|
insertMarkdown,
|
|
2713
2663
|
looksLikeMarkdown,
|
|
@@ -2718,9 +2668,9 @@ export {
|
|
|
2718
2668
|
nextComment,
|
|
2719
2669
|
pureCodeBlock,
|
|
2720
2670
|
pureImage,
|
|
2721
|
-
readCitationAttrs,
|
|
2722
|
-
scrollToTocHeading,
|
|
2723
|
-
|
|
2671
|
+
r as readCitationAttrs,
|
|
2672
|
+
s2 as scrollToTocHeading,
|
|
2673
|
+
s as stabilizeMarkdown,
|
|
2724
2674
|
stripCommentAnchorMarks,
|
|
2725
2675
|
useIsMobile
|
|
2726
2676
|
};
|