tiptap-markdown-react 0.3.1 → 0.4.1
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/dist/CitationRef.d.ts +26 -0
- package/dist/CitationRef.test.d.ts +1 -0
- package/dist/citationDom.d.ts +11 -0
- package/dist/citationDom.test.d.ts +1 -0
- package/dist/citationTypes.d.ts +31 -0
- package/dist/citationUtils.d.ts +23 -0
- package/dist/citationUtils.test.d.ts +1 -0
- package/dist/components/CitationInteractive.d.ts +51 -0
- package/dist/components/CitationRefView.d.ts +6 -0
- package/dist/components/MarkdownPreview.d.ts +13 -1
- package/dist/components/MarkdownWysiwygEditor.d.ts +12 -0
- package/dist/components/ReportContentInteractive.d.ts +15 -0
- package/dist/createCitationRef.d.ts +12 -0
- package/dist/extensions.d.ts +8 -8
- package/dist/extractToc-DW6HOiGt.js +253 -0
- package/dist/extractToc-DW6HOiGt.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +328 -96
- package/dist/index.js.map +1 -1
- package/dist/insertMarkdown.d.ts +6 -2
- package/dist/renderReportHtml.d.ts +11 -1
- package/dist/server.d.ts +3 -1
- package/dist/server.js +23 -7
- package/dist/server.js.map +1 -1
- package/dist/style.css +87 -32
- package/package.json +6 -2
- package/dist/extractToc-C7e1DuVc.js +0 -97
- package/dist/extractToc-C7e1DuVc.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,19 +1,75 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Markdown } from "@tiptap/markdown";
|
|
3
|
-
import {
|
|
3
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
4
4
|
import CodeBlockLowlight from "@tiptap/extension-code-block-lowlight";
|
|
5
5
|
import Image from "@tiptap/extension-image";
|
|
6
6
|
import { TableOfContents } from "@tiptap/extension-table-of-contents";
|
|
7
|
-
import { NodeViewWrapper, NodeViewContent, useEditor, EditorContent,
|
|
8
|
-
import { forwardRef, useEffect, useImperativeHandle, useState, useRef, useCallback, useContext, createContext } from "react";
|
|
9
|
-
import { s as styles$4, b as baseExtensions, l as lowlight, m as makeTocGetId, p as pureCodeBlock, a as pureImage } from "./extractToc-
|
|
10
|
-
import {
|
|
7
|
+
import { NodeViewWrapper, ReactNodeViewRenderer, NodeViewContent, useEditor, EditorContent, useEditorState } from "@tiptap/react";
|
|
8
|
+
import { forwardRef, useEffect, useImperativeHandle, useMemo, useState, useRef, useCallback, useContext, createContext } from "react";
|
|
9
|
+
import { C as CitationRef, e as enrichMarkdownCitations, s as styles$4, b as baseExtensions, l as lowlight, m as makeTocGetId, p as pureCodeBlock, a as pureImage, R as ReportContent } from "./extractToc-DW6HOiGt.js";
|
|
10
|
+
import { c, d } from "./extractToc-DW6HOiGt.js";
|
|
11
11
|
import { Extension } from "@tiptap/core";
|
|
12
12
|
import { FileHandlePlugin } from "@tiptap/extension-file-handler";
|
|
13
13
|
import { PluginKey, Plugin } from "@tiptap/pm/state";
|
|
14
14
|
import * as DropdownMenu from "@radix-ui/react-dropdown-menu";
|
|
15
15
|
import * as Popover from "@radix-ui/react-popover";
|
|
16
16
|
import { createPortal } from "react-dom";
|
|
17
|
+
function CitationRefView({ node, extension }) {
|
|
18
|
+
const index = String(node.attrs.index ?? "");
|
|
19
|
+
const url = node.attrs.url || null;
|
|
20
|
+
const title = node.attrs.title || "";
|
|
21
|
+
const renderCitation = extension.options.renderCitation;
|
|
22
|
+
const pill = /* @__PURE__ */ jsx(
|
|
23
|
+
"span",
|
|
24
|
+
{
|
|
25
|
+
className: "citation-ref",
|
|
26
|
+
"data-index": index,
|
|
27
|
+
...url ? { "data-url": url } : {},
|
|
28
|
+
...title ? { "data-title": title } : {},
|
|
29
|
+
children: !renderCitation && url ? /* @__PURE__ */ jsx(
|
|
30
|
+
"a",
|
|
31
|
+
{
|
|
32
|
+
href: url,
|
|
33
|
+
title,
|
|
34
|
+
target: "_blank",
|
|
35
|
+
rel: "noopener noreferrer",
|
|
36
|
+
children: index
|
|
37
|
+
}
|
|
38
|
+
) : index
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
const content = renderCitation ? renderCitation({
|
|
42
|
+
index,
|
|
43
|
+
attrs: { index, url, title: title || null },
|
|
44
|
+
defaultDom: pill
|
|
45
|
+
}) : pill;
|
|
46
|
+
return /* @__PURE__ */ jsx(
|
|
47
|
+
NodeViewWrapper,
|
|
48
|
+
{
|
|
49
|
+
as: "span",
|
|
50
|
+
"data-citation-ref": "",
|
|
51
|
+
style: { display: "inline" },
|
|
52
|
+
children: content
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
function createCitationRef(options = {}) {
|
|
57
|
+
return CitationRef.extend({
|
|
58
|
+
addOptions() {
|
|
59
|
+
var _a;
|
|
60
|
+
return {
|
|
61
|
+
HTMLAttributes: {},
|
|
62
|
+
...(_a = this.parent) == null ? void 0 : _a.call(this),
|
|
63
|
+
renderCitation: options.renderCitation
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
addNodeView() {
|
|
67
|
+
return ReactNodeViewRenderer(CitationRefView);
|
|
68
|
+
}
|
|
69
|
+
}).configure({
|
|
70
|
+
renderCitation: options.renderCitation
|
|
71
|
+
});
|
|
72
|
+
}
|
|
17
73
|
const MD_FILE_RE = /\.(md|markdown)$/i;
|
|
18
74
|
const MD_MIME_TYPES = ["text/markdown", "text/x-markdown", ""];
|
|
19
75
|
async function insertMarkdownFiles(editor, files, pos) {
|
|
@@ -454,6 +510,8 @@ const ImageWithConfirmDelete = Image.extend({
|
|
|
454
510
|
});
|
|
455
511
|
const MarkdownWysiwygEditor = forwardRef(function MarkdownWysiwygEditor2({
|
|
456
512
|
initialMarkdown = "",
|
|
513
|
+
sources,
|
|
514
|
+
renderCitation,
|
|
457
515
|
placeholder,
|
|
458
516
|
onEditorReady,
|
|
459
517
|
onTocChange,
|
|
@@ -463,11 +521,16 @@ const MarkdownWysiwygEditor = forwardRef(function MarkdownWysiwygEditor2({
|
|
|
463
521
|
codeBlockLabels,
|
|
464
522
|
className
|
|
465
523
|
}, ref) {
|
|
524
|
+
const preparedInitial = enrichMarkdownCitations(
|
|
525
|
+
initialMarkdown,
|
|
526
|
+
sources ?? []
|
|
527
|
+
);
|
|
466
528
|
const editor = useEditor({
|
|
467
529
|
extensions: [
|
|
468
530
|
...baseExtensions,
|
|
469
531
|
CodeBlock.configure({ lowlight, codeBlockLabels }),
|
|
470
532
|
ImageWithConfirmDelete.configure({ inline: false }),
|
|
533
|
+
createCitationRef({ renderCitation }),
|
|
471
534
|
Markdown,
|
|
472
535
|
TableOfContents.configure({
|
|
473
536
|
getId: makeTocGetId(),
|
|
@@ -481,7 +544,7 @@ const MarkdownWysiwygEditor = forwardRef(function MarkdownWysiwygEditor2({
|
|
|
481
544
|
...markdownFileDrop ? [MarkdownFileDrop] : [],
|
|
482
545
|
...extraExtensions ?? []
|
|
483
546
|
],
|
|
484
|
-
content:
|
|
547
|
+
content: preparedInitial,
|
|
485
548
|
contentType: "markdown",
|
|
486
549
|
// Next.js SSR:服务端不立即渲染,避免 hydration 不一致
|
|
487
550
|
immediatelyRender: false,
|
|
@@ -523,23 +586,43 @@ const MarkdownWysiwygEditor = forwardRef(function MarkdownWysiwygEditor2({
|
|
|
523
586
|
}
|
|
524
587
|
);
|
|
525
588
|
});
|
|
526
|
-
function MarkdownPreview({
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
589
|
+
function MarkdownPreview({
|
|
590
|
+
markdown,
|
|
591
|
+
sources,
|
|
592
|
+
renderCitation,
|
|
593
|
+
className
|
|
594
|
+
}) {
|
|
595
|
+
const prepared = useMemo(
|
|
596
|
+
() => enrichMarkdownCitations(markdown, sources ?? []),
|
|
597
|
+
[markdown, sources]
|
|
598
|
+
);
|
|
599
|
+
const extensions = useMemo(
|
|
600
|
+
() => [
|
|
601
|
+
...baseExtensions,
|
|
602
|
+
pureCodeBlock,
|
|
603
|
+
pureImage,
|
|
604
|
+
createCitationRef({ renderCitation }),
|
|
605
|
+
Markdown
|
|
606
|
+
],
|
|
607
|
+
[renderCitation]
|
|
608
|
+
);
|
|
609
|
+
const editor = useEditor(
|
|
610
|
+
{
|
|
611
|
+
extensions,
|
|
612
|
+
content: prepared,
|
|
613
|
+
contentType: "markdown",
|
|
614
|
+
editable: false,
|
|
615
|
+
immediatelyRender: false,
|
|
616
|
+
editorProps: {
|
|
617
|
+
attributes: { class: styles$4.editorContent }
|
|
618
|
+
}
|
|
619
|
+
},
|
|
620
|
+
[extensions]
|
|
621
|
+
);
|
|
539
622
|
useEffect(() => {
|
|
540
623
|
if (!editor) return;
|
|
541
|
-
editor.commands.setContent(
|
|
542
|
-
}, [editor,
|
|
624
|
+
editor.commands.setContent(prepared, { contentType: "markdown" });
|
|
625
|
+
}, [editor, prepared]);
|
|
543
626
|
return /* @__PURE__ */ jsx(
|
|
544
627
|
EditorContent,
|
|
545
628
|
{
|
|
@@ -548,8 +631,9 @@ function MarkdownPreview({ markdown, className }) {
|
|
|
548
631
|
}
|
|
549
632
|
);
|
|
550
633
|
}
|
|
551
|
-
function insertMarkdown(editor, markdown) {
|
|
552
|
-
|
|
634
|
+
function insertMarkdown(editor, markdown, sources = []) {
|
|
635
|
+
const prepared = enrichMarkdownCitations(markdown, sources);
|
|
636
|
+
editor.chain().focus().insertContent(prepared, { contentType: "markdown" }).run();
|
|
553
637
|
}
|
|
554
638
|
const toolbar = "_toolbar_i2emf_2";
|
|
555
639
|
const inner = "_inner_i2emf_15";
|
|
@@ -635,7 +719,7 @@ function ColorPalette({ value, onPick, labels }) {
|
|
|
635
719
|
{
|
|
636
720
|
type: "button",
|
|
637
721
|
className: styles$1.noneRow,
|
|
638
|
-
onMouseDown: (
|
|
722
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
639
723
|
onClick: () => onPick(null),
|
|
640
724
|
children: [
|
|
641
725
|
/* @__PURE__ */ jsx("span", { className: styles$1.noneIcon, "aria-hidden": true }),
|
|
@@ -643,32 +727,32 @@ function ColorPalette({ value, onPick, labels }) {
|
|
|
643
727
|
]
|
|
644
728
|
}
|
|
645
729
|
),
|
|
646
|
-
/* @__PURE__ */ jsx("div", { className: styles$1.grid, children: PALETTE.flat().map((
|
|
730
|
+
/* @__PURE__ */ jsx("div", { className: styles$1.grid, children: PALETTE.flat().map((c2) => /* @__PURE__ */ jsx(
|
|
647
731
|
"button",
|
|
648
732
|
{
|
|
649
733
|
type: "button",
|
|
650
|
-
className: `${styles$1.swatch} ${current ===
|
|
651
|
-
style: { background:
|
|
652
|
-
title:
|
|
653
|
-
"aria-label":
|
|
654
|
-
onMouseDown: (
|
|
655
|
-
onClick: () => onPick(
|
|
734
|
+
className: `${styles$1.swatch} ${current === c2.toLowerCase() ? styles$1.swatchActive : ""}`,
|
|
735
|
+
style: { background: c2 },
|
|
736
|
+
title: c2,
|
|
737
|
+
"aria-label": c2,
|
|
738
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
739
|
+
onClick: () => onPick(c2)
|
|
656
740
|
},
|
|
657
|
-
|
|
741
|
+
c2
|
|
658
742
|
)) }),
|
|
659
743
|
/* @__PURE__ */ jsx("div", { className: styles$1.themeLabel, children: t.theme }),
|
|
660
|
-
/* @__PURE__ */ jsx("div", { className: styles$1.themeRow, children: THEME_COLORS.map((
|
|
744
|
+
/* @__PURE__ */ jsx("div", { className: styles$1.themeRow, children: THEME_COLORS.map((c2) => /* @__PURE__ */ jsx(
|
|
661
745
|
"button",
|
|
662
746
|
{
|
|
663
747
|
type: "button",
|
|
664
|
-
className: `${styles$1.swatch} ${current ===
|
|
665
|
-
style: { background:
|
|
666
|
-
title:
|
|
667
|
-
"aria-label":
|
|
668
|
-
onMouseDown: (
|
|
669
|
-
onClick: () => onPick(
|
|
748
|
+
className: `${styles$1.swatch} ${current === c2.toLowerCase() ? styles$1.swatchActive : ""}`,
|
|
749
|
+
style: { background: c2 },
|
|
750
|
+
title: c2,
|
|
751
|
+
"aria-label": c2,
|
|
752
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
753
|
+
onClick: () => onPick(c2)
|
|
670
754
|
},
|
|
671
|
-
|
|
755
|
+
c2
|
|
672
756
|
)) })
|
|
673
757
|
] });
|
|
674
758
|
}
|
|
@@ -688,7 +772,7 @@ function ToolbarButton({
|
|
|
688
772
|
"aria-pressed": active2,
|
|
689
773
|
disabled,
|
|
690
774
|
className: `${styles$2.btn} ${active2 ? styles$2.btnActive : ""}`,
|
|
691
|
-
onMouseDown: (
|
|
775
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
692
776
|
onClick,
|
|
693
777
|
children
|
|
694
778
|
}
|
|
@@ -713,8 +797,8 @@ function MenuPopover({
|
|
|
713
797
|
className: styles$2.menu,
|
|
714
798
|
sideOffset: 4,
|
|
715
799
|
align: "start",
|
|
716
|
-
onOpenAutoFocus: (
|
|
717
|
-
onCloseAutoFocus: (
|
|
800
|
+
onOpenAutoFocus: (e) => e.preventDefault(),
|
|
801
|
+
onCloseAutoFocus: (e) => e.preventDefault(),
|
|
718
802
|
children: /* @__PURE__ */ jsx(MenuCloseCtx.Provider, { value: close, children })
|
|
719
803
|
}
|
|
720
804
|
) })
|
|
@@ -733,7 +817,7 @@ function MenuItem({
|
|
|
733
817
|
type: "button",
|
|
734
818
|
disabled,
|
|
735
819
|
className: `${styles$2.menuItem} ${selected ? styles$2.menuItemSelected : ""}`,
|
|
736
|
-
onMouseDown: (
|
|
820
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
737
821
|
onClick: () => {
|
|
738
822
|
onSelect();
|
|
739
823
|
close();
|
|
@@ -759,7 +843,7 @@ function ColorPopover({
|
|
|
759
843
|
className: styles$2.btn,
|
|
760
844
|
title,
|
|
761
845
|
"aria-label": title,
|
|
762
|
-
onMouseDown: (
|
|
846
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
763
847
|
children: /* @__PURE__ */ jsxs("span", { className: styles$2.colorIcon, children: [
|
|
764
848
|
/* @__PURE__ */ jsx("span", { className: styles$2.colorIconGlyph, children: glyph }),
|
|
765
849
|
/* @__PURE__ */ jsx("span", { className: styles$2.colorIconBar, style: { background: bar } })
|
|
@@ -772,14 +856,14 @@ function ColorPopover({
|
|
|
772
856
|
className: styles$2.popoverContent,
|
|
773
857
|
sideOffset: 4,
|
|
774
858
|
align: "start",
|
|
775
|
-
onOpenAutoFocus: (
|
|
776
|
-
onCloseAutoFocus: (
|
|
859
|
+
onOpenAutoFocus: (e) => e.preventDefault(),
|
|
860
|
+
onCloseAutoFocus: (e) => e.preventDefault(),
|
|
777
861
|
children: /* @__PURE__ */ jsx(
|
|
778
862
|
ColorPalette,
|
|
779
863
|
{
|
|
780
864
|
value,
|
|
781
|
-
onPick: (
|
|
782
|
-
onPick(
|
|
865
|
+
onPick: (c2) => {
|
|
866
|
+
onPick(c2);
|
|
783
867
|
setOpen(false);
|
|
784
868
|
},
|
|
785
869
|
labels: paletteLabels
|
|
@@ -802,30 +886,30 @@ function EditorToolbar({
|
|
|
802
886
|
const t = { ...defaultToolbarLabels, ...labels };
|
|
803
887
|
const state = useEditorState({
|
|
804
888
|
editor,
|
|
805
|
-
selector: ({ editor:
|
|
806
|
-
bold:
|
|
807
|
-
italic:
|
|
808
|
-
underline:
|
|
809
|
-
strike:
|
|
810
|
-
code:
|
|
811
|
-
link:
|
|
812
|
-
taskList:
|
|
889
|
+
selector: ({ editor: e }) => ({
|
|
890
|
+
bold: e.isActive("bold"),
|
|
891
|
+
italic: e.isActive("italic"),
|
|
892
|
+
underline: e.isActive("underline"),
|
|
893
|
+
strike: e.isActive("strike"),
|
|
894
|
+
code: e.isActive("code"),
|
|
895
|
+
link: e.isActive("link"),
|
|
896
|
+
taskList: e.isActive("taskList"),
|
|
813
897
|
headingLevel: [1, 2, 3, 4, 5, 6].find(
|
|
814
|
-
(lv) =>
|
|
898
|
+
(lv) => e.isActive("heading", { level: lv })
|
|
815
899
|
),
|
|
816
|
-
fontSize:
|
|
817
|
-
isParagraph:
|
|
818
|
-
bulletList:
|
|
819
|
-
orderedList:
|
|
820
|
-
blockquote:
|
|
821
|
-
textColor:
|
|
822
|
-
highlightColor:
|
|
823
|
-
superscript:
|
|
824
|
-
subscript:
|
|
825
|
-
inTable:
|
|
826
|
-
inTableHeader:
|
|
827
|
-
canUndo:
|
|
828
|
-
canRedo:
|
|
900
|
+
fontSize: e.getAttributes("textStyle").fontSize || void 0,
|
|
901
|
+
isParagraph: e.isActive("paragraph"),
|
|
902
|
+
bulletList: e.isActive("bulletList"),
|
|
903
|
+
orderedList: e.isActive("orderedList"),
|
|
904
|
+
blockquote: e.isActive("blockquote"),
|
|
905
|
+
textColor: e.getAttributes("textStyle").color || void 0,
|
|
906
|
+
highlightColor: e.getAttributes("highlight").color || void 0,
|
|
907
|
+
superscript: e.isActive("superscript"),
|
|
908
|
+
subscript: e.isActive("subscript"),
|
|
909
|
+
inTable: e.isActive("table"),
|
|
910
|
+
inTableHeader: e.isActive("tableHeader"),
|
|
911
|
+
canUndo: e.can().undo(),
|
|
912
|
+
canRedo: e.can().redo()
|
|
829
913
|
})
|
|
830
914
|
});
|
|
831
915
|
const [editorFocused, setEditorFocused] = useState(() => editor.isFocused);
|
|
@@ -847,32 +931,32 @@ function EditorToolbar({
|
|
|
847
931
|
const closeTableMenu = useCallback(() => setTableMenu(null), []);
|
|
848
932
|
useEffect(() => {
|
|
849
933
|
const dom = editor.view.dom;
|
|
850
|
-
const onContextMenu = (
|
|
934
|
+
const onContextMenu = (e) => {
|
|
851
935
|
const coords = editor.view.posAtCoords({
|
|
852
|
-
left:
|
|
853
|
-
top:
|
|
936
|
+
left: e.clientX,
|
|
937
|
+
top: e.clientY
|
|
854
938
|
});
|
|
855
939
|
if (!coords) return;
|
|
856
940
|
const $pos = editor.state.doc.resolve(coords.pos);
|
|
857
941
|
let inTable = false;
|
|
858
|
-
for (let
|
|
859
|
-
if ($pos.node(
|
|
942
|
+
for (let d2 = $pos.depth; d2 > 0; d2--) {
|
|
943
|
+
if ($pos.node(d2).type.name === "table") {
|
|
860
944
|
inTable = true;
|
|
861
945
|
break;
|
|
862
946
|
}
|
|
863
947
|
}
|
|
864
948
|
if (!inTable) return;
|
|
865
|
-
|
|
949
|
+
e.preventDefault();
|
|
866
950
|
editor.chain().focus().setTextSelection(coords.pos).run();
|
|
867
|
-
setTableMenu({ x:
|
|
951
|
+
setTableMenu({ x: e.clientX, y: e.clientY });
|
|
868
952
|
};
|
|
869
953
|
dom.addEventListener("contextmenu", onContextMenu);
|
|
870
954
|
return () => dom.removeEventListener("contextmenu", onContextMenu);
|
|
871
955
|
}, [editor]);
|
|
872
956
|
useEffect(() => {
|
|
873
957
|
if (!tableMenu) return;
|
|
874
|
-
const onKey = (
|
|
875
|
-
if (
|
|
958
|
+
const onKey = (e) => {
|
|
959
|
+
if (e.key === "Escape") closeTableMenu();
|
|
876
960
|
};
|
|
877
961
|
document.addEventListener("mousedown", closeTableMenu);
|
|
878
962
|
document.addEventListener("keydown", onKey, true);
|
|
@@ -892,10 +976,10 @@ function EditorToolbar({
|
|
|
892
976
|
var _a;
|
|
893
977
|
return (_a = fileInputRef.current) == null ? void 0 : _a.click();
|
|
894
978
|
};
|
|
895
|
-
const handleImageChange = async (
|
|
979
|
+
const handleImageChange = async (e) => {
|
|
896
980
|
var _a;
|
|
897
|
-
const file = (_a =
|
|
898
|
-
|
|
981
|
+
const file = (_a = e.target.files) == null ? void 0 : _a[0];
|
|
982
|
+
e.target.value = "";
|
|
899
983
|
if (!file || !onImageUpload) return;
|
|
900
984
|
try {
|
|
901
985
|
const url = await onImageUpload(file);
|
|
@@ -907,10 +991,10 @@ function EditorToolbar({
|
|
|
907
991
|
}
|
|
908
992
|
};
|
|
909
993
|
const mdFileInputRef = useRef(null);
|
|
910
|
-
const handleMdFileChange = async (
|
|
994
|
+
const handleMdFileChange = async (e) => {
|
|
911
995
|
var _a;
|
|
912
|
-
const file = (_a =
|
|
913
|
-
|
|
996
|
+
const file = (_a = e.target.files) == null ? void 0 : _a[0];
|
|
997
|
+
e.target.value = "";
|
|
914
998
|
if (!file) return;
|
|
915
999
|
try {
|
|
916
1000
|
const text = await file.text();
|
|
@@ -981,7 +1065,7 @@ function EditorToolbar({
|
|
|
981
1065
|
type: "button",
|
|
982
1066
|
className: styles$2.styleTrigger,
|
|
983
1067
|
title: t.style,
|
|
984
|
-
onMouseDown: (
|
|
1068
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
985
1069
|
children: [
|
|
986
1070
|
/* @__PURE__ */ jsx("span", { className: styles$2.styleTriggerLabel, children: t.style }),
|
|
987
1071
|
/* @__PURE__ */ jsx(ChevronDownIcon, { size: 12, className: styles$2.styleTriggerCaret })
|
|
@@ -1026,7 +1110,7 @@ function EditorToolbar({
|
|
|
1026
1110
|
title: t.fontSize,
|
|
1027
1111
|
"aria-label": t.fontSize,
|
|
1028
1112
|
disabled: !canEditFontSize,
|
|
1029
|
-
onMouseDown: (
|
|
1113
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
1030
1114
|
children: [
|
|
1031
1115
|
/* @__PURE__ */ jsx("span", { className: styles$2.styleTriggerLabel, children: state.fontSize || t.fontSize }),
|
|
1032
1116
|
/* @__PURE__ */ jsx(ChevronDownIcon, { size: 12, className: styles$2.styleTriggerCaret })
|
|
@@ -1138,7 +1222,7 @@ function EditorToolbar({
|
|
|
1138
1222
|
className: `${styles$2.scriptTrigger} ${scriptActive !== "normal" ? styles$2.btnActive : ""}`,
|
|
1139
1223
|
title: t.scriptMenu,
|
|
1140
1224
|
"aria-label": t.scriptMenu,
|
|
1141
|
-
onMouseDown: (
|
|
1225
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
1142
1226
|
children: [
|
|
1143
1227
|
/* @__PURE__ */ jsx("span", { className: styles$2.scriptTriggerGlyph, children: "A" }),
|
|
1144
1228
|
/* @__PURE__ */ jsx(ChevronDownIcon, { size: 12, className: styles$2.styleTriggerCaret })
|
|
@@ -1250,7 +1334,7 @@ function EditorToolbar({
|
|
|
1250
1334
|
type: "button",
|
|
1251
1335
|
className: styles$2.styleTrigger,
|
|
1252
1336
|
title: t.more,
|
|
1253
|
-
onMouseDown: (
|
|
1337
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
1254
1338
|
children: [
|
|
1255
1339
|
/* @__PURE__ */ jsx("span", { className: styles$2.styleTriggerLabel, children: t.more }),
|
|
1256
1340
|
/* @__PURE__ */ jsx(ChevronDownIcon, { size: 12, className: styles$2.styleTriggerCaret })
|
|
@@ -1318,8 +1402,8 @@ function EditorToolbar({
|
|
|
1318
1402
|
{
|
|
1319
1403
|
className: styles$2.tableBubble,
|
|
1320
1404
|
style: { position: "fixed", left: tableMenu.x, top: tableMenu.y },
|
|
1321
|
-
onMouseDown: (
|
|
1322
|
-
onContextMenu: (
|
|
1405
|
+
onMouseDown: (e) => e.stopPropagation(),
|
|
1406
|
+
onContextMenu: (e) => e.preventDefault(),
|
|
1323
1407
|
children: [
|
|
1324
1408
|
/* @__PURE__ */ jsx(
|
|
1325
1409
|
ToolbarButton,
|
|
@@ -1464,8 +1548,8 @@ function TocPanel({ items, activeId, onItemClick, labels }) {
|
|
|
1464
1548
|
style: { paddingLeft: `${(item2.level - minLevel) * 12 + 12}px` },
|
|
1465
1549
|
"aria-current": item2.id === activeId ? "true" : void 0,
|
|
1466
1550
|
"aria-disabled": item2.locked ? "true" : void 0,
|
|
1467
|
-
onClick: (
|
|
1468
|
-
|
|
1551
|
+
onClick: (e) => {
|
|
1552
|
+
e.preventDefault();
|
|
1469
1553
|
handleClick(item2);
|
|
1470
1554
|
},
|
|
1471
1555
|
children: [
|
|
@@ -1538,6 +1622,145 @@ function TocPanel({ items, activeId, onItemClick, labels }) {
|
|
|
1538
1622
|
list2
|
|
1539
1623
|
] });
|
|
1540
1624
|
}
|
|
1625
|
+
function findCitationRefElement(target, root) {
|
|
1626
|
+
if (!(target instanceof Element)) return null;
|
|
1627
|
+
const el = target.closest(".citation-ref");
|
|
1628
|
+
if (!(el instanceof HTMLElement)) return null;
|
|
1629
|
+
if (!root.contains(el)) return null;
|
|
1630
|
+
return el;
|
|
1631
|
+
}
|
|
1632
|
+
function readCitationAttrs(el) {
|
|
1633
|
+
var _a;
|
|
1634
|
+
return {
|
|
1635
|
+
index: el.getAttribute("data-index") || ((_a = el.textContent) == null ? void 0 : _a.trim()) || "",
|
|
1636
|
+
url: el.getAttribute("data-url"),
|
|
1637
|
+
title: el.getAttribute("data-title")
|
|
1638
|
+
};
|
|
1639
|
+
}
|
|
1640
|
+
const CITATION_POPOVER_ATTR = "data-tmr-citation-popover";
|
|
1641
|
+
function isCitationPopoverTarget(target) {
|
|
1642
|
+
return target instanceof Element && !!target.closest(`[${CITATION_POPOVER_ATTR}]`);
|
|
1643
|
+
}
|
|
1644
|
+
function CitationInteractive({
|
|
1645
|
+
containerRef,
|
|
1646
|
+
renderCitation,
|
|
1647
|
+
trigger = "click",
|
|
1648
|
+
hoverCloseDelayMs = 200
|
|
1649
|
+
}) {
|
|
1650
|
+
const [active2, setActive] = useState(null);
|
|
1651
|
+
const closeTimerRef = useRef(null);
|
|
1652
|
+
useEffect(() => {
|
|
1653
|
+
const root = containerRef.current;
|
|
1654
|
+
if (!root) return;
|
|
1655
|
+
const clearCloseTimer = () => {
|
|
1656
|
+
if (closeTimerRef.current != null) {
|
|
1657
|
+
clearTimeout(closeTimerRef.current);
|
|
1658
|
+
closeTimerRef.current = null;
|
|
1659
|
+
}
|
|
1660
|
+
};
|
|
1661
|
+
const scheduleClose = () => {
|
|
1662
|
+
clearCloseTimer();
|
|
1663
|
+
closeTimerRef.current = setTimeout(() => {
|
|
1664
|
+
closeTimerRef.current = null;
|
|
1665
|
+
setActive(null);
|
|
1666
|
+
}, hoverCloseDelayMs);
|
|
1667
|
+
};
|
|
1668
|
+
const activate = (el, e) => {
|
|
1669
|
+
e == null ? void 0 : e.preventDefault();
|
|
1670
|
+
e == null ? void 0 : e.stopPropagation();
|
|
1671
|
+
clearCloseTimer();
|
|
1672
|
+
const attrs = readCitationAttrs(el);
|
|
1673
|
+
setActive({ index: attrs.index, attrs, anchorEl: el });
|
|
1674
|
+
};
|
|
1675
|
+
const onClick = (e) => {
|
|
1676
|
+
const el = findCitationRefElement(e.target, root);
|
|
1677
|
+
if (el) {
|
|
1678
|
+
activate(el, e);
|
|
1679
|
+
return;
|
|
1680
|
+
}
|
|
1681
|
+
setActive(null);
|
|
1682
|
+
};
|
|
1683
|
+
const onMouseOver = (e) => {
|
|
1684
|
+
const el = findCitationRefElement(e.target, root);
|
|
1685
|
+
if (el) {
|
|
1686
|
+
activate(el, e);
|
|
1687
|
+
return;
|
|
1688
|
+
}
|
|
1689
|
+
scheduleClose();
|
|
1690
|
+
};
|
|
1691
|
+
const onRootMouseLeave = () => scheduleClose();
|
|
1692
|
+
const onDocMouseOver = (e) => {
|
|
1693
|
+
if (isCitationPopoverTarget(e.target)) {
|
|
1694
|
+
clearCloseTimer();
|
|
1695
|
+
}
|
|
1696
|
+
};
|
|
1697
|
+
const onDocMouseOut = (e) => {
|
|
1698
|
+
if (!isCitationPopoverTarget(e.target)) return;
|
|
1699
|
+
if (isCitationPopoverTarget(e.relatedTarget)) return;
|
|
1700
|
+
if (findCitationRefElement(e.relatedTarget, root)) return;
|
|
1701
|
+
scheduleClose();
|
|
1702
|
+
};
|
|
1703
|
+
const onKeyDown = (e) => {
|
|
1704
|
+
if (e.key === "Escape") {
|
|
1705
|
+
clearCloseTimer();
|
|
1706
|
+
setActive(null);
|
|
1707
|
+
}
|
|
1708
|
+
};
|
|
1709
|
+
if (trigger === "hover") {
|
|
1710
|
+
root.addEventListener("mouseover", onMouseOver);
|
|
1711
|
+
root.addEventListener("mouseleave", onRootMouseLeave);
|
|
1712
|
+
document.addEventListener("mouseover", onDocMouseOver);
|
|
1713
|
+
document.addEventListener("mouseout", onDocMouseOut);
|
|
1714
|
+
} else {
|
|
1715
|
+
root.addEventListener("click", onClick);
|
|
1716
|
+
}
|
|
1717
|
+
document.addEventListener("keydown", onKeyDown);
|
|
1718
|
+
return () => {
|
|
1719
|
+
clearCloseTimer();
|
|
1720
|
+
root.removeEventListener("mouseover", onMouseOver);
|
|
1721
|
+
root.removeEventListener("mouseleave", onRootMouseLeave);
|
|
1722
|
+
root.removeEventListener("click", onClick);
|
|
1723
|
+
document.removeEventListener("mouseover", onDocMouseOver);
|
|
1724
|
+
document.removeEventListener("mouseout", onDocMouseOut);
|
|
1725
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
1726
|
+
};
|
|
1727
|
+
}, [containerRef, trigger, hoverCloseDelayMs]);
|
|
1728
|
+
if (!active2) return null;
|
|
1729
|
+
return /* @__PURE__ */ jsx(Fragment, { children: renderCitation({
|
|
1730
|
+
index: active2.index,
|
|
1731
|
+
attrs: active2.attrs,
|
|
1732
|
+
anchorEl: active2.anchorEl,
|
|
1733
|
+
close: () => {
|
|
1734
|
+
if (closeTimerRef.current != null) {
|
|
1735
|
+
clearTimeout(closeTimerRef.current);
|
|
1736
|
+
closeTimerRef.current = null;
|
|
1737
|
+
}
|
|
1738
|
+
setActive(null);
|
|
1739
|
+
}
|
|
1740
|
+
}) });
|
|
1741
|
+
}
|
|
1742
|
+
function ReportContentInteractive({
|
|
1743
|
+
renderCitation,
|
|
1744
|
+
trigger,
|
|
1745
|
+
hoverCloseDelayMs,
|
|
1746
|
+
className,
|
|
1747
|
+
html,
|
|
1748
|
+
...rest
|
|
1749
|
+
}) {
|
|
1750
|
+
const ref = useRef(null);
|
|
1751
|
+
return /* @__PURE__ */ jsxs("div", { ref, className, children: [
|
|
1752
|
+
/* @__PURE__ */ jsx(ReportContent, { html, ...rest }),
|
|
1753
|
+
/* @__PURE__ */ jsx(
|
|
1754
|
+
CitationInteractive,
|
|
1755
|
+
{
|
|
1756
|
+
containerRef: ref,
|
|
1757
|
+
renderCitation,
|
|
1758
|
+
trigger,
|
|
1759
|
+
hoverCloseDelayMs
|
|
1760
|
+
}
|
|
1761
|
+
)
|
|
1762
|
+
] });
|
|
1763
|
+
}
|
|
1541
1764
|
function easeOutCubic(t) {
|
|
1542
1765
|
return 1 - (1 - t) * (1 - t) * (1 - t);
|
|
1543
1766
|
}
|
|
@@ -1565,8 +1788,11 @@ function scrollToTocHeading(headingId, scrollContainer, options) {
|
|
|
1565
1788
|
}
|
|
1566
1789
|
export {
|
|
1567
1790
|
BoldIcon,
|
|
1791
|
+
CITATION_POPOVER_ATTR,
|
|
1568
1792
|
CheckIcon,
|
|
1569
1793
|
ChevronDownIcon,
|
|
1794
|
+
CitationInteractive,
|
|
1795
|
+
CitationRef,
|
|
1570
1796
|
CodeBlockView,
|
|
1571
1797
|
CodeIcon,
|
|
1572
1798
|
ColorPalette,
|
|
@@ -1587,7 +1813,8 @@ export {
|
|
|
1587
1813
|
MarkdownWysiwygEditor,
|
|
1588
1814
|
MenuIcon,
|
|
1589
1815
|
RedoIcon,
|
|
1590
|
-
|
|
1816
|
+
ReportContent,
|
|
1817
|
+
ReportContentInteractive,
|
|
1591
1818
|
RowAfterIcon,
|
|
1592
1819
|
RowBeforeIcon,
|
|
1593
1820
|
RowDeleteIcon,
|
|
@@ -1596,18 +1823,23 @@ export {
|
|
|
1596
1823
|
TrashIcon,
|
|
1597
1824
|
UnderlineIcon,
|
|
1598
1825
|
UndoIcon,
|
|
1826
|
+
c as applyCitationSources,
|
|
1599
1827
|
baseExtensions,
|
|
1828
|
+
createCitationRef,
|
|
1600
1829
|
defaultCodeBlockLabels,
|
|
1601
1830
|
defaultColorPaletteLabels,
|
|
1602
1831
|
defaultTocLabels,
|
|
1603
1832
|
defaultToolbarLabels,
|
|
1604
|
-
|
|
1833
|
+
enrichMarkdownCitations,
|
|
1834
|
+
d as extractToc,
|
|
1835
|
+
findCitationRefElement,
|
|
1605
1836
|
insertMarkdown,
|
|
1606
1837
|
looksLikeMarkdown,
|
|
1607
1838
|
lowlight,
|
|
1608
1839
|
makeTocGetId,
|
|
1609
1840
|
pureCodeBlock,
|
|
1610
1841
|
pureImage,
|
|
1842
|
+
readCitationAttrs,
|
|
1611
1843
|
scrollToTocHeading,
|
|
1612
1844
|
useIsMobile
|
|
1613
1845
|
};
|