tiptap-markdown-react 0.11.0 → 0.12.0
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 +33 -1
- package/dist/{ReportContent-By-tSiNn.js → ReportContent-CfvE4CYH.js} +6 -6
- package/dist/{ReportContent-By-tSiNn.js.map → ReportContent-CfvE4CYH.js.map} +1 -1
- package/dist/components/FindReplaceBar.d.ts +4 -2
- package/dist/components/MarkdownWysiwygEditor.d.ts +35 -6
- package/dist/{extractToc-CB4RYsMJ.js → extractToc-BT3OquOq.js} +2 -2
- package/dist/{extractToc-CB4RYsMJ.js.map → extractToc-BT3OquOq.js.map} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +128 -83
- package/dist/index.js.map +1 -1
- package/dist/reader.js +2 -2
- package/dist/{scrollToTocHeading-EkePiWil.js → scrollToTocHeading-DVdii3VR.js} +2 -2
- package/dist/{scrollToTocHeading-EkePiWil.js.map → scrollToTocHeading-DVdii3VR.js.map} +1 -1
- package/dist/server.js +4 -4
- package/dist/style.css +94 -77
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Markdown, MarkdownManager } from "@tiptap/markdown";
|
|
3
|
-
import { c as renderOrUpdateChart, d as destroyChart } from "./scrollToTocHeading-
|
|
4
|
-
import { C, a, R, b, f, m, r, s } from "./scrollToTocHeading-
|
|
3
|
+
import { c as renderOrUpdateChart, d as destroyChart } from "./scrollToTocHeading-DVdii3VR.js";
|
|
4
|
+
import { C, a, R, b, f, m, r, s } from "./scrollToTocHeading-DVdii3VR.js";
|
|
5
5
|
import { jsx, jsxs, Fragment as Fragment$1 } from "react/jsx-runtime";
|
|
6
6
|
import CodeBlockLowlight from "@tiptap/extension-code-block-lowlight";
|
|
7
7
|
import FindAndReplace, { FindAndReplacePluginKey, createSearchRegex } from "@tiptap/extension-find-and-replace";
|
|
@@ -9,11 +9,12 @@ import { default as default2 } from "@tiptap/extension-find-and-replace";
|
|
|
9
9
|
import Image from "@tiptap/extension-image";
|
|
10
10
|
import { TableOfContents } from "@tiptap/extension-table-of-contents";
|
|
11
11
|
import { NodeViewWrapper, ReactNodeViewRenderer, useEditorState, NodeViewContent, useEditor, EditorContent } from "@tiptap/react";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
12
|
+
import { createPortal } from "react-dom";
|
|
13
|
+
import { useState, useEffect, useCallback, useRef, useMemo, forwardRef, useImperativeHandle, useId, useContext, createContext } from "react";
|
|
14
|
+
import { e as enrichMarkdownCitations, b as styles$6 } from "./ReportContent-CfvE4CYH.js";
|
|
15
|
+
import { R as R2, a as a2, s as s2 } from "./ReportContent-CfvE4CYH.js";
|
|
16
|
+
import { C as CitationRef, i as mergeCommentIntervals, h as mapCommentAnchors, p as prepareChartMarkdown, j as reportChart, b as baseExtensions, f as CommentMark, l as lowlight, m as makeTocGetId, k as parseCodeTokenAsChartOrCodeBlock, a as pureCodeBlock, c as pureImage, n as renderMathInto, o as subscribeMathClick, d as pureChart } from "./extractToc-BT3OquOq.js";
|
|
17
|
+
import { g, e, s as s3 } from "./extractToc-BT3OquOq.js";
|
|
17
18
|
import { Slice, Fragment } from "@tiptap/pm/model";
|
|
18
19
|
import { Extension, Node as Node$1 } from "@tiptap/core";
|
|
19
20
|
import { PluginKey, Plugin, NodeSelection, TextSelection } from "@tiptap/pm/state";
|
|
@@ -23,7 +24,6 @@ import { skipTrailingNodeMeta } from "@tiptap/extensions";
|
|
|
23
24
|
import { CellSelection, isInTable, selectedRect, rowIsHeader } from "@tiptap/pm/tables";
|
|
24
25
|
import * as DropdownMenu from "@radix-ui/react-dropdown-menu";
|
|
25
26
|
import * as Popover from "@radix-ui/react-popover";
|
|
26
|
-
import { createPortal } from "react-dom";
|
|
27
27
|
function CitationRefView({ node, extension }) {
|
|
28
28
|
const index = String(node.attrs.index ?? "");
|
|
29
29
|
const url = node.attrs.url || null;
|
|
@@ -614,19 +614,20 @@ const defaultFindLabels = {
|
|
|
614
614
|
invalidRegex: "Invalid pattern",
|
|
615
615
|
readOnly: "Read-only"
|
|
616
616
|
};
|
|
617
|
-
const bar = "
|
|
618
|
-
const row = "
|
|
619
|
-
const field = "
|
|
620
|
-
const fieldIcon = "
|
|
621
|
-
const input = "
|
|
622
|
-
const counter = "
|
|
623
|
-
const counterInvalid = "
|
|
624
|
-
const btn$1 = "
|
|
625
|
-
const toggle = "
|
|
626
|
-
const toggleOn = "
|
|
627
|
-
const
|
|
628
|
-
const
|
|
629
|
-
const
|
|
617
|
+
const bar = "_bar_1lvby_3";
|
|
618
|
+
const row = "_row_1lvby_25";
|
|
619
|
+
const field = "_field_1lvby_40";
|
|
620
|
+
const fieldIcon = "_fieldIcon_1lvby_59";
|
|
621
|
+
const input = "_input_1lvby_64";
|
|
622
|
+
const counter = "_counter_1lvby_75";
|
|
623
|
+
const counterInvalid = "_counterInvalid_1lvby_84";
|
|
624
|
+
const btn$1 = "_btn_1lvby_88";
|
|
625
|
+
const toggle = "_toggle_1lvby_116";
|
|
626
|
+
const toggleOn = "_toggleOn_1lvby_128";
|
|
627
|
+
const closeBtn = "_closeBtn_1lvby_136";
|
|
628
|
+
const textBtn = "_textBtn_1lvby_140";
|
|
629
|
+
const spacer = "_spacer_1lvby_145";
|
|
630
|
+
const readOnly = "_readOnly_1lvby_150";
|
|
630
631
|
const styles$5 = {
|
|
631
632
|
bar,
|
|
632
633
|
row,
|
|
@@ -638,6 +639,7 @@ const styles$5 = {
|
|
|
638
639
|
btn: btn$1,
|
|
639
640
|
toggle,
|
|
640
641
|
toggleOn,
|
|
642
|
+
closeBtn,
|
|
641
643
|
textBtn,
|
|
642
644
|
spacer,
|
|
643
645
|
readOnly
|
|
@@ -647,11 +649,20 @@ function FindReplaceBar({
|
|
|
647
649
|
onClose,
|
|
648
650
|
labels,
|
|
649
651
|
inputRef,
|
|
650
|
-
className
|
|
652
|
+
className,
|
|
653
|
+
style
|
|
651
654
|
}) {
|
|
652
655
|
const t = { ...defaultFindLabels, ...labels };
|
|
653
656
|
const [term, setTerm] = useState("");
|
|
654
657
|
const [replaceTerm, setReplaceTerm] = useState("");
|
|
658
|
+
const hasExtension = typeof editor.commands.setSearchTerm === "function";
|
|
659
|
+
useEffect(() => {
|
|
660
|
+
if (!hasExtension) {
|
|
661
|
+
console.warn(
|
|
662
|
+
"[tiptap-markdown-react] FindReplaceBar 需要官方 find 扩展:请让 <MarkdownWysiwygEditor findReplace> 保持开启(默认 true),否则 setSearchTerm / replaceAll 等命令不存在。"
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
}, [hasExtension]);
|
|
655
666
|
const state = useEditorState({
|
|
656
667
|
editor,
|
|
657
668
|
selector: ({ editor: instance }) => {
|
|
@@ -665,13 +676,20 @@ function FindReplaceBar({
|
|
|
665
676
|
};
|
|
666
677
|
}
|
|
667
678
|
});
|
|
679
|
+
const runCommand = useCallback(
|
|
680
|
+
(run) => {
|
|
681
|
+
if (!hasExtension) return;
|
|
682
|
+
runFindCommand(run);
|
|
683
|
+
},
|
|
684
|
+
[hasExtension]
|
|
685
|
+
);
|
|
668
686
|
const appliedTermRef = useRef(null);
|
|
669
687
|
const pushTerm = useCallback(
|
|
670
688
|
(value) => {
|
|
671
689
|
appliedTermRef.current = value;
|
|
672
|
-
|
|
690
|
+
runCommand(() => editor.commands.setSearchTerm(value));
|
|
673
691
|
},
|
|
674
|
-
[editor]
|
|
692
|
+
[editor, runCommand]
|
|
675
693
|
);
|
|
676
694
|
const flushTerm = useCallback(() => {
|
|
677
695
|
if (appliedTermRef.current !== term) pushTerm(term);
|
|
@@ -682,19 +700,19 @@ function FindReplaceBar({
|
|
|
682
700
|
return () => clearTimeout(timer);
|
|
683
701
|
}, [term, pushTerm]);
|
|
684
702
|
useEffect(() => {
|
|
685
|
-
|
|
686
|
-
}, [editor, replaceTerm]);
|
|
703
|
+
runCommand(() => editor.commands.setReplaceTerm(replaceTerm));
|
|
704
|
+
}, [editor, replaceTerm, runCommand]);
|
|
687
705
|
useEffect(() => {
|
|
688
706
|
return () => {
|
|
689
|
-
if (!editor.isDestroyed) editor.commands.clearSearch();
|
|
707
|
+
if (!editor.isDestroyed) runCommand(() => editor.commands.clearSearch());
|
|
690
708
|
};
|
|
691
|
-
}, [editor]);
|
|
709
|
+
}, [editor, runCommand]);
|
|
692
710
|
const runAction = useCallback(
|
|
693
711
|
(action) => {
|
|
694
712
|
flushTerm();
|
|
695
|
-
|
|
713
|
+
runCommand(action);
|
|
696
714
|
},
|
|
697
|
-
[flushTerm]
|
|
715
|
+
[flushTerm, runCommand]
|
|
698
716
|
);
|
|
699
717
|
const invalidPattern = useMemo(
|
|
700
718
|
() => term !== "" && state.useRegex && createSearchRegex(term, {
|
|
@@ -725,17 +743,19 @@ function FindReplaceBar({
|
|
|
725
743
|
}
|
|
726
744
|
};
|
|
727
745
|
const toggle2 = (key, value) => {
|
|
728
|
-
|
|
746
|
+
runCommand(() => {
|
|
729
747
|
if (key === "caseSensitive") editor.commands.setCaseSensitive(value);
|
|
730
748
|
else if (key === "wholeWord") editor.commands.setWholeWord(value);
|
|
731
749
|
else editor.commands.setUseRegex(value);
|
|
732
750
|
});
|
|
733
751
|
};
|
|
752
|
+
if (!hasExtension) return null;
|
|
734
753
|
const toggleClass = (on) => `${styles$5.btn} ${styles$5.toggle}${on ? ` ${styles$5.toggleOn}` : ""}`;
|
|
735
754
|
return /* @__PURE__ */ jsxs(
|
|
736
755
|
"div",
|
|
737
756
|
{
|
|
738
757
|
className: className ? `${styles$5.bar} ${className}` : styles$5.bar,
|
|
758
|
+
style,
|
|
739
759
|
role: "dialog",
|
|
740
760
|
"aria-label": t.find,
|
|
741
761
|
onKeyDown: (e2) => {
|
|
@@ -763,6 +783,46 @@ function FindReplaceBar({
|
|
|
763
783
|
}
|
|
764
784
|
)
|
|
765
785
|
] }),
|
|
786
|
+
/* @__PURE__ */ jsx(
|
|
787
|
+
"button",
|
|
788
|
+
{
|
|
789
|
+
type: "button",
|
|
790
|
+
className: toggleClass(state.caseSensitive),
|
|
791
|
+
title: t.caseSensitive,
|
|
792
|
+
"aria-label": t.caseSensitive,
|
|
793
|
+
"aria-pressed": state.caseSensitive,
|
|
794
|
+
onMouseDown: keepFocus,
|
|
795
|
+
onClick: () => toggle2("caseSensitive", !state.caseSensitive),
|
|
796
|
+
children: "Aa"
|
|
797
|
+
}
|
|
798
|
+
),
|
|
799
|
+
/* @__PURE__ */ jsx(
|
|
800
|
+
"button",
|
|
801
|
+
{
|
|
802
|
+
type: "button",
|
|
803
|
+
className: toggleClass(state.wholeWord),
|
|
804
|
+
title: t.wholeWord,
|
|
805
|
+
"aria-label": t.wholeWord,
|
|
806
|
+
"aria-pressed": state.wholeWord,
|
|
807
|
+
onMouseDown: keepFocus,
|
|
808
|
+
onClick: () => toggle2("wholeWord", !state.wholeWord),
|
|
809
|
+
children: "ab"
|
|
810
|
+
}
|
|
811
|
+
),
|
|
812
|
+
/* @__PURE__ */ jsx(
|
|
813
|
+
"button",
|
|
814
|
+
{
|
|
815
|
+
type: "button",
|
|
816
|
+
className: toggleClass(state.useRegex),
|
|
817
|
+
title: t.useRegex,
|
|
818
|
+
"aria-label": t.useRegex,
|
|
819
|
+
"aria-pressed": state.useRegex,
|
|
820
|
+
onMouseDown: keepFocus,
|
|
821
|
+
onClick: () => toggle2("useRegex", !state.useRegex),
|
|
822
|
+
children: ".*"
|
|
823
|
+
}
|
|
824
|
+
),
|
|
825
|
+
/* @__PURE__ */ jsx("span", { className: styles$5.spacer }),
|
|
766
826
|
/* @__PURE__ */ jsx(
|
|
767
827
|
"span",
|
|
768
828
|
{
|
|
@@ -802,7 +862,7 @@ function FindReplaceBar({
|
|
|
802
862
|
"button",
|
|
803
863
|
{
|
|
804
864
|
type: "button",
|
|
805
|
-
className: styles$5.btn
|
|
865
|
+
className: `${styles$5.btn} ${styles$5.closeBtn}`,
|
|
806
866
|
title: t.close,
|
|
807
867
|
"aria-label": t.close,
|
|
808
868
|
onClick: onClose,
|
|
@@ -823,45 +883,6 @@ function FindReplaceBar({
|
|
|
823
883
|
spellCheck: false
|
|
824
884
|
}
|
|
825
885
|
) }),
|
|
826
|
-
/* @__PURE__ */ jsx(
|
|
827
|
-
"button",
|
|
828
|
-
{
|
|
829
|
-
type: "button",
|
|
830
|
-
className: toggleClass(state.caseSensitive),
|
|
831
|
-
title: t.caseSensitive,
|
|
832
|
-
"aria-label": t.caseSensitive,
|
|
833
|
-
"aria-pressed": state.caseSensitive,
|
|
834
|
-
onMouseDown: keepFocus,
|
|
835
|
-
onClick: () => toggle2("caseSensitive", !state.caseSensitive),
|
|
836
|
-
children: "Aa"
|
|
837
|
-
}
|
|
838
|
-
),
|
|
839
|
-
/* @__PURE__ */ jsx(
|
|
840
|
-
"button",
|
|
841
|
-
{
|
|
842
|
-
type: "button",
|
|
843
|
-
className: toggleClass(state.wholeWord),
|
|
844
|
-
title: t.wholeWord,
|
|
845
|
-
"aria-label": t.wholeWord,
|
|
846
|
-
"aria-pressed": state.wholeWord,
|
|
847
|
-
onMouseDown: keepFocus,
|
|
848
|
-
onClick: () => toggle2("wholeWord", !state.wholeWord),
|
|
849
|
-
children: "ab"
|
|
850
|
-
}
|
|
851
|
-
),
|
|
852
|
-
/* @__PURE__ */ jsx(
|
|
853
|
-
"button",
|
|
854
|
-
{
|
|
855
|
-
type: "button",
|
|
856
|
-
className: toggleClass(state.useRegex),
|
|
857
|
-
title: t.useRegex,
|
|
858
|
-
"aria-label": t.useRegex,
|
|
859
|
-
"aria-pressed": state.useRegex,
|
|
860
|
-
onMouseDown: keepFocus,
|
|
861
|
-
onClick: () => toggle2("useRegex", !state.useRegex),
|
|
862
|
-
children: ".*"
|
|
863
|
-
}
|
|
864
|
-
),
|
|
865
886
|
/* @__PURE__ */ jsx("span", { className: styles$5.spacer }),
|
|
866
887
|
/* @__PURE__ */ jsx(
|
|
867
888
|
"button",
|
|
@@ -1425,6 +1446,17 @@ const ImageWithConfirmDelete = Image.extend({
|
|
|
1425
1446
|
};
|
|
1426
1447
|
}
|
|
1427
1448
|
});
|
|
1449
|
+
const DEFAULT_FIND_BAR_OFFSET = { top: 4, right: 4 };
|
|
1450
|
+
function findBarOffsetStyle(offset) {
|
|
1451
|
+
const px = (v) => typeof v === "number" ? `${v}px` : v;
|
|
1452
|
+
return {
|
|
1453
|
+
position: "absolute",
|
|
1454
|
+
top: px(offset.top),
|
|
1455
|
+
right: px(offset.right),
|
|
1456
|
+
bottom: px(offset.bottom),
|
|
1457
|
+
left: px(offset.left)
|
|
1458
|
+
};
|
|
1459
|
+
}
|
|
1428
1460
|
const MarkdownWysiwygEditor = forwardRef(function MarkdownWysiwygEditor2({
|
|
1429
1461
|
initialMarkdown = "",
|
|
1430
1462
|
editable = true,
|
|
@@ -1448,6 +1480,9 @@ const MarkdownWysiwygEditor = forwardRef(function MarkdownWysiwygEditor2({
|
|
|
1448
1480
|
onAnchorClick,
|
|
1449
1481
|
onSelectionChange,
|
|
1450
1482
|
findReplace = true,
|
|
1483
|
+
findBar = findReplace,
|
|
1484
|
+
findBarContainer,
|
|
1485
|
+
findBarOffset = DEFAULT_FIND_BAR_OFFSET,
|
|
1451
1486
|
findShortcut = true,
|
|
1452
1487
|
findLabels
|
|
1453
1488
|
}, ref) {
|
|
@@ -1513,7 +1548,7 @@ const MarkdownWysiwygEditor = forwardRef(function MarkdownWysiwygEditor2({
|
|
|
1513
1548
|
editor == null ? void 0 : editor.commands.focus();
|
|
1514
1549
|
}, [editor]);
|
|
1515
1550
|
useEffect(() => {
|
|
1516
|
-
if (!editor || !findReplace || !findShortcut) return;
|
|
1551
|
+
if (!editor || !findReplace || !findBar || !findShortcut) return;
|
|
1517
1552
|
const onKeyDown = (event) => {
|
|
1518
1553
|
if (!(event.metaKey || event.ctrlKey) || event.altKey || event.shiftKey) {
|
|
1519
1554
|
return;
|
|
@@ -1535,7 +1570,7 @@ const MarkdownWysiwygEditor = forwardRef(function MarkdownWysiwygEditor2({
|
|
|
1535
1570
|
};
|
|
1536
1571
|
document.addEventListener("keydown", onKeyDown, true);
|
|
1537
1572
|
return () => document.removeEventListener("keydown", onKeyDown, true);
|
|
1538
|
-
}, [editor, findReplace, findShortcut]);
|
|
1573
|
+
}, [editor, findReplace, findBar, findShortcut]);
|
|
1539
1574
|
const commentsSignatureRef = useRef("");
|
|
1540
1575
|
useEffect(() => {
|
|
1541
1576
|
if (!editor || !editable) return;
|
|
@@ -1648,17 +1683,27 @@ const MarkdownWysiwygEditor = forwardRef(function MarkdownWysiwygEditor2({
|
|
|
1648
1683
|
}),
|
|
1649
1684
|
[editor, closeFind]
|
|
1650
1685
|
);
|
|
1686
|
+
const findBarTarget = typeof findBarContainer === "function" ? findBarContainer() : findBarContainer ?? null;
|
|
1687
|
+
useEffect(() => {
|
|
1688
|
+
if (!findBarTarget) return;
|
|
1689
|
+
if (getComputedStyle(findBarTarget).position === "static") {
|
|
1690
|
+
findBarTarget.style.position = "relative";
|
|
1691
|
+
}
|
|
1692
|
+
}, [findBarTarget]);
|
|
1693
|
+
const findBarNode = editor && findBar && findOpen ? /* @__PURE__ */ jsx(
|
|
1694
|
+
FindReplaceBar,
|
|
1695
|
+
{
|
|
1696
|
+
editor,
|
|
1697
|
+
labels: findLabels,
|
|
1698
|
+
onClose: closeFind,
|
|
1699
|
+
inputRef: findInputRef,
|
|
1700
|
+
className: styles$6.findBar,
|
|
1701
|
+
style: findBarOffsetStyle(findBarOffset)
|
|
1702
|
+
}
|
|
1703
|
+
) : null;
|
|
1651
1704
|
return /* @__PURE__ */ jsxs("div", { className: styles$6.editorHost, children: [
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
{
|
|
1655
|
-
editor,
|
|
1656
|
-
labels: findLabels,
|
|
1657
|
-
onClose: closeFind,
|
|
1658
|
-
inputRef: findInputRef,
|
|
1659
|
-
className: styles$6.findBar
|
|
1660
|
-
}
|
|
1661
|
-
) }) : null,
|
|
1705
|
+
findBarNode && !findBarTarget ? /* @__PURE__ */ jsx("div", { className: styles$6.findBarAnchor, children: findBarNode }) : null,
|
|
1706
|
+
findBarNode && findBarTarget ? createPortal(findBarNode, findBarTarget) : null,
|
|
1662
1707
|
/* @__PURE__ */ jsx(
|
|
1663
1708
|
EditorContent,
|
|
1664
1709
|
{
|