tiptap-markdown-react 0.8.12 → 0.9.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 +32 -0
- package/dist/ReportContent-Re3hNps8.js +368 -0
- package/dist/ReportContent-Re3hNps8.js.map +1 -0
- package/dist/chart/ChartExtension.d.ts +21 -0
- package/dist/chart/chartRoundTrip.test.d.ts +1 -0
- package/dist/chart/columnMatching.d.ts +19 -0
- package/dist/chart/createChart.d.ts +19 -0
- package/dist/chart/mapData.d.ts +22 -0
- package/dist/chart/mapData.test.d.ts +1 -0
- package/dist/chart/parse.d.ts +31 -0
- package/dist/chart/parse.test.d.ts +1 -0
- package/dist/chart/prepareChartMarkdown.d.ts +5 -0
- package/dist/chart/renderChart.d.ts +12 -0
- package/dist/chart/serialize.d.ts +1 -0
- package/dist/chart/theme.d.ts +3 -0
- package/dist/chart/types.d.ts +41 -0
- package/dist/components/ChartEditorPopover.d.ts +12 -0
- package/dist/components/ChartMount.d.ts +14 -0
- package/dist/components/ChartView.d.ts +2 -0
- package/dist/components/MarkdownPreview.d.ts +3 -2
- package/dist/components/ReportContentWithCharts.d.ts +13 -0
- package/dist/extensions.d.ts +4 -3
- package/dist/{extractToc-CecK9W_w.js → extractToc-Dv40DtV5.js} +145 -9
- package/dist/extractToc-Dv40DtV5.js.map +1 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.js +423 -126
- package/dist/index.js.map +1 -1
- package/dist/labels.d.ts +9 -0
- package/dist/reader.d.ts +3 -8
- package/dist/reader.js +9 -6
- package/dist/scrollToTocHeading-CIJu2AcX.js +496 -0
- package/dist/scrollToTocHeading-CIJu2AcX.js.map +1 -0
- package/dist/server.d.ts +4 -1
- package/dist/server.js +17 -9
- package/dist/server.js.map +1 -1
- package/dist/style.css +144 -0
- package/package.json +12 -4
- package/dist/ReportContent-c_UlJnVY.js +0 -68
- package/dist/ReportContent-c_UlJnVY.js.map +0 -1
- package/dist/extractToc-CecK9W_w.js.map +0 -1
- package/dist/scrollToTocHeading-CwapFaVP.js +0 -126
- package/dist/scrollToTocHeading-CwapFaVP.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Markdown } from "@tiptap/markdown";
|
|
3
|
+
import { c as renderOrUpdateChart, d as destroyChart } from "./scrollToTocHeading-CIJu2AcX.js";
|
|
4
|
+
import { C, a, R, b, f, m, r, s } from "./scrollToTocHeading-CIJu2AcX.js";
|
|
3
5
|
import { jsx, jsxs, Fragment as Fragment$1 } from "react/jsx-runtime";
|
|
4
6
|
import CodeBlockLowlight from "@tiptap/extension-code-block-lowlight";
|
|
5
7
|
import Image from "@tiptap/extension-image";
|
|
6
8
|
import { TableOfContents } from "@tiptap/extension-table-of-contents";
|
|
7
9
|
import { NodeViewWrapper, ReactNodeViewRenderer, NodeViewContent, useEditor, EditorContent, useEditorState } from "@tiptap/react";
|
|
8
|
-
import {
|
|
9
|
-
import { e as enrichMarkdownCitations,
|
|
10
|
-
import { R, a } from "./ReportContent-
|
|
11
|
-
import { C as CitationRef,
|
|
12
|
-
import {
|
|
10
|
+
import { useId, useState, useRef, useEffect, useMemo, forwardRef, useImperativeHandle, useCallback, useContext, createContext } from "react";
|
|
11
|
+
import { s as serializeChartPayload, u as unwrapChartConfigs, b as parseGfmTable, c as normalizeChartPayload, e as enrichMarkdownCitations, d as styles$5 } from "./ReportContent-Re3hNps8.js";
|
|
12
|
+
import { R as R2, a as a2 } from "./ReportContent-Re3hNps8.js";
|
|
13
|
+
import { C as CitationRef, i as mergeCommentIntervals, h as mapCommentAnchors, j as reportChart, p as prepareChartMarkdown, b as baseExtensions, f as CommentMark, l as lowlight, m as makeTocGetId, a as pureCodeBlock, c as pureImage, k as renderMathInto, n as subscribeMathClick } from "./extractToc-Dv40DtV5.js";
|
|
14
|
+
import { g, e, d, s as s2 } from "./extractToc-Dv40DtV5.js";
|
|
13
15
|
import { Slice, Fragment } from "@tiptap/pm/model";
|
|
14
16
|
import { Extension, Node as Node$1 } from "@tiptap/core";
|
|
15
17
|
import { PluginKey, Plugin } from "@tiptap/pm/state";
|
|
16
18
|
import { DecorationSet, Decoration } from "@tiptap/pm/view";
|
|
17
19
|
import { FileHandlePlugin } from "@tiptap/extension-file-handler";
|
|
20
|
+
import { createPortal } from "react-dom";
|
|
18
21
|
import * as DropdownMenu from "@radix-ui/react-dropdown-menu";
|
|
19
22
|
import * as Popover from "@radix-ui/react-popover";
|
|
20
|
-
import { createPortal } from "react-dom";
|
|
21
23
|
import { isInTable, selectedRect, rowIsHeader, CellSelection } from "@tiptap/pm/tables";
|
|
22
|
-
import { C, R as R2, f, r, s as s2 } from "./scrollToTocHeading-CwapFaVP.js";
|
|
23
24
|
function CitationRefView({ node, extension }) {
|
|
24
25
|
const index = String(node.attrs.index ?? "");
|
|
25
26
|
const url = node.attrs.url || null;
|
|
@@ -86,9 +87,9 @@ function stripCommentAnchorMarks(slice, markType) {
|
|
|
86
87
|
const strip = (fragment) => {
|
|
87
88
|
const children = [];
|
|
88
89
|
fragment.forEach((child) => {
|
|
89
|
-
if (child.isText && child.marks.some((
|
|
90
|
+
if (child.isText && child.marks.some((m2) => m2.type === markType)) {
|
|
90
91
|
children.push(
|
|
91
|
-
child.mark(child.marks.filter((
|
|
92
|
+
child.mark(child.marks.filter((m2) => m2.type !== markType))
|
|
92
93
|
);
|
|
93
94
|
} else if (child.content.size > 0) {
|
|
94
95
|
children.push(child.copy(strip(child.content)));
|
|
@@ -103,7 +104,7 @@ function stripCommentAnchorMarks(slice, markType) {
|
|
|
103
104
|
function sliceHasCommentMarks(slice, markType) {
|
|
104
105
|
let found = false;
|
|
105
106
|
slice.content.descendants((node) => {
|
|
106
|
-
if (node.isText && node.marks.some((
|
|
107
|
+
if (node.isText && node.marks.some((m2) => m2.type === markType)) {
|
|
107
108
|
found = true;
|
|
108
109
|
return false;
|
|
109
110
|
}
|
|
@@ -122,9 +123,9 @@ function collectCommentRanges(doc) {
|
|
|
122
123
|
const byId = /* @__PURE__ */ new Map();
|
|
123
124
|
doc.descendants((node, pos) => {
|
|
124
125
|
if (!node.isText) return true;
|
|
125
|
-
for (const
|
|
126
|
-
if (
|
|
127
|
-
const ids =
|
|
126
|
+
for (const m2 of node.marks) {
|
|
127
|
+
if (m2.type.name !== "commentAnchor") continue;
|
|
128
|
+
const ids = m2.attrs.commentIds ?? [];
|
|
128
129
|
for (const id of ids) {
|
|
129
130
|
const arr = byId.get(id) ?? [];
|
|
130
131
|
arr.push({ from: pos, to: pos + node.nodeSize });
|
|
@@ -180,19 +181,19 @@ function commentAnchorPlugin(options = {}) {
|
|
|
180
181
|
const decos = [];
|
|
181
182
|
const bounds = blockBounds(state.doc);
|
|
182
183
|
if (showGutter) {
|
|
183
|
-
for (const
|
|
184
|
+
for (const b2 of bounds) {
|
|
184
185
|
const idsInBlock = [];
|
|
185
186
|
for (const [id, ranges] of byId) {
|
|
186
|
-
if (rangesIntersectBlock(ranges,
|
|
187
|
+
if (rangesIntersectBlock(ranges, b2.start, b2.end)) {
|
|
187
188
|
idsInBlock.push(id);
|
|
188
189
|
}
|
|
189
190
|
}
|
|
190
191
|
if (idsInBlock.length > 0) {
|
|
191
192
|
decos.push(
|
|
192
193
|
Decoration.widget(
|
|
193
|
-
|
|
194
|
-
(view) => gutterDom(idsInBlock, view,
|
|
195
|
-
{ side: -1, key: `tmr-gutter:${
|
|
194
|
+
b2.start,
|
|
195
|
+
(view) => gutterDom(idsInBlock, view, b2.start),
|
|
196
|
+
{ side: -1, key: `tmr-gutter:${b2.start}` }
|
|
196
197
|
)
|
|
197
198
|
);
|
|
198
199
|
}
|
|
@@ -206,10 +207,10 @@ function commentAnchorPlugin(options = {}) {
|
|
|
206
207
|
Decoration.inline(r2.from, r2.to, { class: "tmr-comment-active" })
|
|
207
208
|
);
|
|
208
209
|
}
|
|
209
|
-
for (const
|
|
210
|
-
if (rangesIntersectBlock(ranges,
|
|
210
|
+
for (const b2 of bounds) {
|
|
211
|
+
if (rangesIntersectBlock(ranges, b2.start, b2.end)) {
|
|
211
212
|
decos.push(
|
|
212
|
-
Decoration.node(
|
|
213
|
+
Decoration.node(b2.start, b2.end, {
|
|
213
214
|
class: "tmr-comment-block-active"
|
|
214
215
|
})
|
|
215
216
|
);
|
|
@@ -272,9 +273,9 @@ function collectCommentIds(editor) {
|
|
|
272
273
|
const ids = [];
|
|
273
274
|
editor.state.doc.descendants((node) => {
|
|
274
275
|
if (!node.isText) return true;
|
|
275
|
-
for (const
|
|
276
|
-
if (
|
|
277
|
-
for (const id of
|
|
276
|
+
for (const m2 of node.marks) {
|
|
277
|
+
if (m2.type.name !== "commentAnchor") continue;
|
|
278
|
+
for (const id of m2.attrs.commentIds ?? []) {
|
|
278
279
|
if (!ids.includes(id)) ids.push(id);
|
|
279
280
|
}
|
|
280
281
|
}
|
|
@@ -286,9 +287,9 @@ function commentRangesById(editor, commentId) {
|
|
|
286
287
|
const ranges = [];
|
|
287
288
|
editor.state.doc.descendants((node, pos) => {
|
|
288
289
|
if (!node.isText) return true;
|
|
289
|
-
for (const
|
|
290
|
-
if (
|
|
291
|
-
const ids =
|
|
290
|
+
for (const m2 of node.marks) {
|
|
291
|
+
if (m2.type.name !== "commentAnchor") continue;
|
|
292
|
+
const ids = m2.attrs.commentIds ?? [];
|
|
292
293
|
if (ids.includes(commentId)) {
|
|
293
294
|
ranges.push({ from: pos, to: pos + node.nodeSize });
|
|
294
295
|
}
|
|
@@ -496,6 +497,374 @@ const MarkdownPaste = Extension.create({
|
|
|
496
497
|
];
|
|
497
498
|
}
|
|
498
499
|
});
|
|
500
|
+
const defaultChartLabels = {
|
|
501
|
+
tabLabel: (chartType, index) => `${chartType} ${index + 1}`,
|
|
502
|
+
done: "Done",
|
|
503
|
+
cancel: "Cancel",
|
|
504
|
+
configLabel: "Chart config (JSON)",
|
|
505
|
+
tableLabel: "Data table (Markdown)"
|
|
506
|
+
};
|
|
507
|
+
const defaultToolbarLabels = {
|
|
508
|
+
undo: "Undo",
|
|
509
|
+
redo: "Redo",
|
|
510
|
+
style: "Style",
|
|
511
|
+
normalText: "Normal text",
|
|
512
|
+
headingLabel: (level) => `Heading ${level}`,
|
|
513
|
+
fontSize: "Font size",
|
|
514
|
+
fontSizeDefault: "Default",
|
|
515
|
+
bold: "Bold",
|
|
516
|
+
italic: "Italic",
|
|
517
|
+
underline: "Underline",
|
|
518
|
+
strike: "Strikethrough",
|
|
519
|
+
code: "Inline code",
|
|
520
|
+
textColor: "Text color",
|
|
521
|
+
highlight: "Highlight",
|
|
522
|
+
colorNone: "None",
|
|
523
|
+
colorTheme: "THEME",
|
|
524
|
+
scriptMenu: "Superscript / Subscript",
|
|
525
|
+
scriptNormal: "Normal",
|
|
526
|
+
superscript: "Superscript",
|
|
527
|
+
subscript: "Subscript",
|
|
528
|
+
link: "Link",
|
|
529
|
+
linkPrompt: "Enter URL",
|
|
530
|
+
image: "Image",
|
|
531
|
+
imageUploadFailed: "Image upload failed",
|
|
532
|
+
importMarkdownFailed: "Markdown import failed",
|
|
533
|
+
importDocument: "Import",
|
|
534
|
+
importDocumentHint: "Import a file",
|
|
535
|
+
importDocumentOther: "Document",
|
|
536
|
+
importDocumentBusy: "Importing…",
|
|
537
|
+
importDocumentUploading: (percent) => `Uploading ${percent}%`,
|
|
538
|
+
importDocumentConverting: "Converting…",
|
|
539
|
+
importDocumentFailed: "Import failed",
|
|
540
|
+
blockquote: "Blockquote",
|
|
541
|
+
bulletList: "Bullet list",
|
|
542
|
+
orderedList: "Ordered list",
|
|
543
|
+
taskList: "Task list",
|
|
544
|
+
more: "More",
|
|
545
|
+
codeBlock: "Code block",
|
|
546
|
+
hr: "Divider",
|
|
547
|
+
importMarkdown: "Markdown",
|
|
548
|
+
tableInsert: "Insert table",
|
|
549
|
+
tableSizeSelected: (cols, rows) => `${cols} × ${rows}`,
|
|
550
|
+
tableAddColumnBefore: "Add column before",
|
|
551
|
+
tableAddColumnAfter: "Add column after",
|
|
552
|
+
tableDeleteColumn: "Delete column",
|
|
553
|
+
tableAddRowBefore: "Add row before",
|
|
554
|
+
tableAddRowAfter: "Add row after",
|
|
555
|
+
tableDeleteRow: "Delete row",
|
|
556
|
+
tableAddColumnBeforeN: (n) => `Add ${n} columns before`,
|
|
557
|
+
tableAddColumnAfterN: (n) => `Add ${n} columns after`,
|
|
558
|
+
tableDeleteColumnN: (n) => `Delete ${n} columns`,
|
|
559
|
+
tableAddRowBeforeN: (n) => `Add ${n} rows before`,
|
|
560
|
+
tableAddRowAfterN: (n) => `Add ${n} rows after`,
|
|
561
|
+
tableDeleteRowN: (n) => `Delete ${n} rows`,
|
|
562
|
+
tableDeleteTable: "Delete table",
|
|
563
|
+
inlineMath: "Inline equation",
|
|
564
|
+
blockMath: "Block equation",
|
|
565
|
+
mathPlaceholder: "E = mc^2",
|
|
566
|
+
mathDone: "Done",
|
|
567
|
+
mathCancel: "Cancel",
|
|
568
|
+
mathNewInline: "New equation",
|
|
569
|
+
mathNewBlock: "Add a TeX equation"
|
|
570
|
+
};
|
|
571
|
+
const defaultColorPaletteLabels = {
|
|
572
|
+
none: "None",
|
|
573
|
+
theme: "THEME"
|
|
574
|
+
};
|
|
575
|
+
const defaultTocLabels = {
|
|
576
|
+
title: "Contents",
|
|
577
|
+
expand: "Expand",
|
|
578
|
+
collapse: "Collapse"
|
|
579
|
+
};
|
|
580
|
+
const defaultCodeBlockLabels = {
|
|
581
|
+
autoDetect: "Auto-detect",
|
|
582
|
+
delete: "Delete code block"
|
|
583
|
+
};
|
|
584
|
+
const defaultCommentLabels = {
|
|
585
|
+
open: "Open",
|
|
586
|
+
resolved: "Resolved",
|
|
587
|
+
dismissed: "Dismissed",
|
|
588
|
+
outdated: "Outdated",
|
|
589
|
+
ambiguous: "Ambiguous",
|
|
590
|
+
partial: "Partially matched",
|
|
591
|
+
gutterTitle: "Comment"
|
|
592
|
+
};
|
|
593
|
+
function buildEditors(payload) {
|
|
594
|
+
const flat = payload.config.length === 1 ? payload.config[0] : payload.config;
|
|
595
|
+
const full = serializeChartPayload(payload);
|
|
596
|
+
const lines = full.split("\n");
|
|
597
|
+
const tableText = lines.slice(2).join("\n");
|
|
598
|
+
return {
|
|
599
|
+
configText: JSON.stringify(flat, null, 2),
|
|
600
|
+
tableText
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
function ChartEditorPopover({
|
|
604
|
+
payload,
|
|
605
|
+
anchor,
|
|
606
|
+
doneLabel = "Done",
|
|
607
|
+
cancelLabel = "Cancel",
|
|
608
|
+
configLabel = "Chart config (JSON)",
|
|
609
|
+
tableLabel = "Data table (Markdown)",
|
|
610
|
+
onConfirm,
|
|
611
|
+
onCancel
|
|
612
|
+
}) {
|
|
613
|
+
const titleId = useId();
|
|
614
|
+
const initial = buildEditors(payload);
|
|
615
|
+
const [configText, setConfigText] = useState(initial.configText);
|
|
616
|
+
const [tableText, setTableText] = useState(initial.tableText);
|
|
617
|
+
const [error, setError] = useState(null);
|
|
618
|
+
const panelRef = useRef(null);
|
|
619
|
+
useEffect(() => {
|
|
620
|
+
const onKey = (e2) => {
|
|
621
|
+
if (e2.key === "Escape") onCancel();
|
|
622
|
+
};
|
|
623
|
+
window.addEventListener("keydown", onKey);
|
|
624
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
625
|
+
}, [onCancel]);
|
|
626
|
+
useEffect(() => {
|
|
627
|
+
const onDown = (e2) => {
|
|
628
|
+
var _a;
|
|
629
|
+
const t = e2.target;
|
|
630
|
+
if ((_a = panelRef.current) == null ? void 0 : _a.contains(t)) return;
|
|
631
|
+
if (anchor == null ? void 0 : anchor.contains(t)) return;
|
|
632
|
+
onCancel();
|
|
633
|
+
};
|
|
634
|
+
window.addEventListener("mousedown", onDown);
|
|
635
|
+
return () => window.removeEventListener("mousedown", onDown);
|
|
636
|
+
}, [anchor, onCancel]);
|
|
637
|
+
const style = (() => {
|
|
638
|
+
if (!anchor) return { top: 80, left: 80 };
|
|
639
|
+
const r2 = anchor.getBoundingClientRect();
|
|
640
|
+
const top = Math.min(r2.bottom + 8, window.innerHeight - 40);
|
|
641
|
+
const left = Math.min(Math.max(8, r2.left), window.innerWidth - 340);
|
|
642
|
+
return { top, left };
|
|
643
|
+
})();
|
|
644
|
+
const submit = () => {
|
|
645
|
+
try {
|
|
646
|
+
const parsed = JSON.parse(configText);
|
|
647
|
+
const configs = unwrapChartConfigs(parsed);
|
|
648
|
+
if (!(configs == null ? void 0 : configs.length)) {
|
|
649
|
+
setError("Invalid chart config JSON");
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
const table = parseGfmTable(
|
|
653
|
+
tableText.endsWith("\n") ? tableText : `${tableText}
|
|
654
|
+
`
|
|
655
|
+
);
|
|
656
|
+
if (!table) {
|
|
657
|
+
setError("Invalid Markdown table");
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
const next = normalizeChartPayload(
|
|
661
|
+
configs,
|
|
662
|
+
table.columns,
|
|
663
|
+
table.dataSource
|
|
664
|
+
);
|
|
665
|
+
if (!next) {
|
|
666
|
+
setError("No supported chartType / axes in config");
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
onConfirm(next);
|
|
670
|
+
} catch (e2) {
|
|
671
|
+
setError(e2.message || "Parse error");
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
const onKeyDown = (e2) => {
|
|
675
|
+
if ((e2.metaKey || e2.ctrlKey) && e2.key === "Enter") {
|
|
676
|
+
e2.preventDefault();
|
|
677
|
+
submit();
|
|
678
|
+
}
|
|
679
|
+
};
|
|
680
|
+
return createPortal(
|
|
681
|
+
/* @__PURE__ */ jsxs(
|
|
682
|
+
"div",
|
|
683
|
+
{
|
|
684
|
+
ref: panelRef,
|
|
685
|
+
className: "tmr-chart-popover",
|
|
686
|
+
style: { top: style.top, left: style.left },
|
|
687
|
+
role: "dialog",
|
|
688
|
+
"aria-labelledby": titleId,
|
|
689
|
+
onKeyDown,
|
|
690
|
+
children: [
|
|
691
|
+
/* @__PURE__ */ jsx("div", { id: titleId, className: "tmr-chart-title", children: "Edit chart" }),
|
|
692
|
+
/* @__PURE__ */ jsxs("label", { children: [
|
|
693
|
+
configLabel,
|
|
694
|
+
/* @__PURE__ */ jsx(
|
|
695
|
+
"textarea",
|
|
696
|
+
{
|
|
697
|
+
value: configText,
|
|
698
|
+
onChange: (e2) => setConfigText(e2.target.value),
|
|
699
|
+
spellCheck: false
|
|
700
|
+
}
|
|
701
|
+
)
|
|
702
|
+
] }),
|
|
703
|
+
/* @__PURE__ */ jsxs("label", { children: [
|
|
704
|
+
tableLabel,
|
|
705
|
+
/* @__PURE__ */ jsx(
|
|
706
|
+
"textarea",
|
|
707
|
+
{
|
|
708
|
+
value: tableText,
|
|
709
|
+
onChange: (e2) => setTableText(e2.target.value),
|
|
710
|
+
spellCheck: false
|
|
711
|
+
}
|
|
712
|
+
)
|
|
713
|
+
] }),
|
|
714
|
+
error ? /* @__PURE__ */ jsx("div", { className: "tmr-chart-popover-error", children: error }) : null,
|
|
715
|
+
/* @__PURE__ */ jsxs("div", { className: "tmr-chart-popover-actions", children: [
|
|
716
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: onCancel, children: cancelLabel }),
|
|
717
|
+
/* @__PURE__ */ jsx("button", { type: "button", "data-primary": "true", onClick: submit, children: doneLabel })
|
|
718
|
+
] })
|
|
719
|
+
]
|
|
720
|
+
}
|
|
721
|
+
),
|
|
722
|
+
document.body
|
|
723
|
+
);
|
|
724
|
+
}
|
|
725
|
+
function tabLabel(chartType, title, index, fallback) {
|
|
726
|
+
if (title == null ? void 0 : title.trim()) return title;
|
|
727
|
+
return fallback(chartType, index);
|
|
728
|
+
}
|
|
729
|
+
function ChartView({
|
|
730
|
+
node,
|
|
731
|
+
updateAttributes,
|
|
732
|
+
editor,
|
|
733
|
+
extension,
|
|
734
|
+
selected
|
|
735
|
+
}) {
|
|
736
|
+
const canvasRef = useRef(null);
|
|
737
|
+
const chartRef = useRef(null);
|
|
738
|
+
const rootRef = useRef(null);
|
|
739
|
+
const [active2, setActive2] = useState(0);
|
|
740
|
+
const [editing, setEditing] = useState(false);
|
|
741
|
+
const payload = useMemo(
|
|
742
|
+
() => ({
|
|
743
|
+
config: node.attrs.config ?? [],
|
|
744
|
+
columns: node.attrs.columns ?? [],
|
|
745
|
+
dataSource: node.attrs.dataSource ?? []
|
|
746
|
+
}),
|
|
747
|
+
[node.attrs.config, node.attrs.columns, node.attrs.dataSource]
|
|
748
|
+
);
|
|
749
|
+
const editable = Boolean(editor == null ? void 0 : editor.isEditable) && extension.options.chartEditable !== false;
|
|
750
|
+
const theme = extension.options.chartTheme ?? null;
|
|
751
|
+
const configs = payload.config;
|
|
752
|
+
const safeIndex = Math.min(active2, Math.max(0, configs.length - 1));
|
|
753
|
+
const config = configs[safeIndex];
|
|
754
|
+
const height = (config == null ? void 0 : config.height) ?? 320;
|
|
755
|
+
useEffect(() => {
|
|
756
|
+
const canvas = canvasRef.current;
|
|
757
|
+
if (!canvas || !config) return;
|
|
758
|
+
chartRef.current = renderOrUpdateChart({
|
|
759
|
+
canvas,
|
|
760
|
+
config,
|
|
761
|
+
payload,
|
|
762
|
+
theme,
|
|
763
|
+
chart: chartRef.current
|
|
764
|
+
});
|
|
765
|
+
return () => {
|
|
766
|
+
};
|
|
767
|
+
}, [config, payload, theme]);
|
|
768
|
+
useEffect(() => {
|
|
769
|
+
return () => {
|
|
770
|
+
destroyChart(chartRef.current);
|
|
771
|
+
chartRef.current = null;
|
|
772
|
+
};
|
|
773
|
+
}, []);
|
|
774
|
+
useEffect(() => {
|
|
775
|
+
destroyChart(chartRef.current);
|
|
776
|
+
chartRef.current = null;
|
|
777
|
+
const canvas = canvasRef.current;
|
|
778
|
+
if (!canvas || !config) return;
|
|
779
|
+
chartRef.current = renderOrUpdateChart({
|
|
780
|
+
canvas,
|
|
781
|
+
config,
|
|
782
|
+
payload,
|
|
783
|
+
theme,
|
|
784
|
+
chart: null
|
|
785
|
+
});
|
|
786
|
+
}, [safeIndex]);
|
|
787
|
+
const labels = {
|
|
788
|
+
...defaultChartLabels,
|
|
789
|
+
...extension.options.chartLabels
|
|
790
|
+
};
|
|
791
|
+
const onOpenEdit = () => {
|
|
792
|
+
if (!editable) return;
|
|
793
|
+
setEditing(true);
|
|
794
|
+
};
|
|
795
|
+
return /* @__PURE__ */ jsxs(
|
|
796
|
+
NodeViewWrapper,
|
|
797
|
+
{
|
|
798
|
+
as: "div",
|
|
799
|
+
className: `tmr-chart${editable ? " tmr-chart--interactive" : ""}`,
|
|
800
|
+
"data-type": "chart",
|
|
801
|
+
"data-selected": selected ? "true" : void 0,
|
|
802
|
+
ref: rootRef,
|
|
803
|
+
onClick: (e2) => {
|
|
804
|
+
if (e2.target.closest("button")) return;
|
|
805
|
+
onOpenEdit();
|
|
806
|
+
},
|
|
807
|
+
children: [
|
|
808
|
+
(config == null ? void 0 : config.title) ? /* @__PURE__ */ jsx("div", { className: "tmr-chart-title", children: config.title }) : null,
|
|
809
|
+
(config == null ? void 0 : config.dataTime) ? /* @__PURE__ */ jsx("div", { className: "tmr-chart-time", children: config.dataTime }) : null,
|
|
810
|
+
configs.length > 1 ? /* @__PURE__ */ jsx("div", { className: "tmr-chart-tabs", role: "tablist", children: configs.map((c, i) => /* @__PURE__ */ jsx(
|
|
811
|
+
"button",
|
|
812
|
+
{
|
|
813
|
+
type: "button",
|
|
814
|
+
role: "tab",
|
|
815
|
+
className: "tmr-chart-tab",
|
|
816
|
+
"data-active": i === safeIndex ? "true" : "false",
|
|
817
|
+
"aria-selected": i === safeIndex,
|
|
818
|
+
onClick: (e2) => {
|
|
819
|
+
e2.stopPropagation();
|
|
820
|
+
setActive2(i);
|
|
821
|
+
},
|
|
822
|
+
children: tabLabel(c.chartType, c.title, i, labels.tabLabel)
|
|
823
|
+
},
|
|
824
|
+
`${c.chartType}-${i}`
|
|
825
|
+
)) }) : null,
|
|
826
|
+
/* @__PURE__ */ jsx("div", { className: "tmr-chart-canvas-host", style: { height }, children: /* @__PURE__ */ jsx("canvas", { ref: canvasRef }) }),
|
|
827
|
+
editing ? /* @__PURE__ */ jsx(
|
|
828
|
+
ChartEditorPopover,
|
|
829
|
+
{
|
|
830
|
+
payload,
|
|
831
|
+
anchor: rootRef.current,
|
|
832
|
+
doneLabel: labels.done,
|
|
833
|
+
cancelLabel: labels.cancel,
|
|
834
|
+
configLabel: labels.configLabel,
|
|
835
|
+
tableLabel: labels.tableLabel,
|
|
836
|
+
onCancel: () => setEditing(false),
|
|
837
|
+
onConfirm: (next) => {
|
|
838
|
+
updateAttributes({
|
|
839
|
+
config: next.config,
|
|
840
|
+
columns: next.columns,
|
|
841
|
+
dataSource: next.dataSource
|
|
842
|
+
});
|
|
843
|
+
setEditing(false);
|
|
844
|
+
setActive2(0);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
) : null
|
|
848
|
+
]
|
|
849
|
+
}
|
|
850
|
+
);
|
|
851
|
+
}
|
|
852
|
+
function createChart(options = {}) {
|
|
853
|
+
const { editable = true, chartTheme = null, chartLabels } = options;
|
|
854
|
+
return reportChart.extend({
|
|
855
|
+
addOptions() {
|
|
856
|
+
return {
|
|
857
|
+
HTMLAttributes: {},
|
|
858
|
+
chartEditable: editable,
|
|
859
|
+
chartTheme,
|
|
860
|
+
chartLabels
|
|
861
|
+
};
|
|
862
|
+
},
|
|
863
|
+
addNodeView() {
|
|
864
|
+
return ReactNodeViewRenderer(ChartView);
|
|
865
|
+
}
|
|
866
|
+
});
|
|
867
|
+
}
|
|
499
868
|
function Svg({ size = "1em", children, ...rest }) {
|
|
500
869
|
return /* @__PURE__ */ jsx(
|
|
501
870
|
"svg",
|
|
@@ -644,92 +1013,6 @@ const TableDeleteIcon = (p) => /* @__PURE__ */ jsxs(Svg, { ...p, children: [
|
|
|
644
1013
|
/* @__PURE__ */ jsx("path", { d: "M15 5v14" }),
|
|
645
1014
|
/* @__PURE__ */ jsx("path", { d: "m7 2 10 20" })
|
|
646
1015
|
] });
|
|
647
|
-
const defaultToolbarLabels = {
|
|
648
|
-
undo: "Undo",
|
|
649
|
-
redo: "Redo",
|
|
650
|
-
style: "Style",
|
|
651
|
-
normalText: "Normal text",
|
|
652
|
-
headingLabel: (level) => `Heading ${level}`,
|
|
653
|
-
fontSize: "Font size",
|
|
654
|
-
fontSizeDefault: "Default",
|
|
655
|
-
bold: "Bold",
|
|
656
|
-
italic: "Italic",
|
|
657
|
-
underline: "Underline",
|
|
658
|
-
strike: "Strikethrough",
|
|
659
|
-
code: "Inline code",
|
|
660
|
-
textColor: "Text color",
|
|
661
|
-
highlight: "Highlight",
|
|
662
|
-
colorNone: "None",
|
|
663
|
-
colorTheme: "THEME",
|
|
664
|
-
scriptMenu: "Superscript / Subscript",
|
|
665
|
-
scriptNormal: "Normal",
|
|
666
|
-
superscript: "Superscript",
|
|
667
|
-
subscript: "Subscript",
|
|
668
|
-
link: "Link",
|
|
669
|
-
linkPrompt: "Enter URL",
|
|
670
|
-
image: "Image",
|
|
671
|
-
imageUploadFailed: "Image upload failed",
|
|
672
|
-
importMarkdownFailed: "Markdown import failed",
|
|
673
|
-
importDocument: "Import",
|
|
674
|
-
importDocumentHint: "Import a file",
|
|
675
|
-
importDocumentOther: "Document",
|
|
676
|
-
importDocumentBusy: "Importing…",
|
|
677
|
-
importDocumentUploading: (percent) => `Uploading ${percent}%`,
|
|
678
|
-
importDocumentConverting: "Converting…",
|
|
679
|
-
importDocumentFailed: "Import failed",
|
|
680
|
-
blockquote: "Blockquote",
|
|
681
|
-
bulletList: "Bullet list",
|
|
682
|
-
orderedList: "Ordered list",
|
|
683
|
-
taskList: "Task list",
|
|
684
|
-
more: "More",
|
|
685
|
-
codeBlock: "Code block",
|
|
686
|
-
hr: "Divider",
|
|
687
|
-
importMarkdown: "Markdown",
|
|
688
|
-
tableInsert: "Insert table",
|
|
689
|
-
tableSizeSelected: (cols, rows) => `${cols} × ${rows}`,
|
|
690
|
-
tableAddColumnBefore: "Add column before",
|
|
691
|
-
tableAddColumnAfter: "Add column after",
|
|
692
|
-
tableDeleteColumn: "Delete column",
|
|
693
|
-
tableAddRowBefore: "Add row before",
|
|
694
|
-
tableAddRowAfter: "Add row after",
|
|
695
|
-
tableDeleteRow: "Delete row",
|
|
696
|
-
tableAddColumnBeforeN: (n) => `Add ${n} columns before`,
|
|
697
|
-
tableAddColumnAfterN: (n) => `Add ${n} columns after`,
|
|
698
|
-
tableDeleteColumnN: (n) => `Delete ${n} columns`,
|
|
699
|
-
tableAddRowBeforeN: (n) => `Add ${n} rows before`,
|
|
700
|
-
tableAddRowAfterN: (n) => `Add ${n} rows after`,
|
|
701
|
-
tableDeleteRowN: (n) => `Delete ${n} rows`,
|
|
702
|
-
tableDeleteTable: "Delete table",
|
|
703
|
-
inlineMath: "Inline equation",
|
|
704
|
-
blockMath: "Block equation",
|
|
705
|
-
mathPlaceholder: "E = mc^2",
|
|
706
|
-
mathDone: "Done",
|
|
707
|
-
mathCancel: "Cancel",
|
|
708
|
-
mathNewInline: "New equation",
|
|
709
|
-
mathNewBlock: "Add a TeX equation"
|
|
710
|
-
};
|
|
711
|
-
const defaultColorPaletteLabels = {
|
|
712
|
-
none: "None",
|
|
713
|
-
theme: "THEME"
|
|
714
|
-
};
|
|
715
|
-
const defaultTocLabels = {
|
|
716
|
-
title: "Contents",
|
|
717
|
-
expand: "Expand",
|
|
718
|
-
collapse: "Collapse"
|
|
719
|
-
};
|
|
720
|
-
const defaultCodeBlockLabels = {
|
|
721
|
-
autoDetect: "Auto-detect",
|
|
722
|
-
delete: "Delete code block"
|
|
723
|
-
};
|
|
724
|
-
const defaultCommentLabels = {
|
|
725
|
-
open: "Open",
|
|
726
|
-
resolved: "Resolved",
|
|
727
|
-
dismissed: "Dismissed",
|
|
728
|
-
outdated: "Outdated",
|
|
729
|
-
ambiguous: "Ambiguous",
|
|
730
|
-
partial: "Partially matched",
|
|
731
|
-
gutterTitle: "Comment"
|
|
732
|
-
};
|
|
733
1016
|
const wrapper = "_wrapper_5i2vi_2";
|
|
734
1017
|
const header$1 = "_header_5i2vi_18";
|
|
735
1018
|
const langTrigger = "_langTrigger_5i2vi_28";
|
|
@@ -922,9 +1205,8 @@ const MarkdownWysiwygEditor = forwardRef(function MarkdownWysiwygEditor2({
|
|
|
922
1205
|
showCommentGutter = true,
|
|
923
1206
|
commentInteractive = true
|
|
924
1207
|
}, ref) {
|
|
925
|
-
const preparedInitial =
|
|
926
|
-
initialMarkdown,
|
|
927
|
-
sources ?? []
|
|
1208
|
+
const preparedInitial = prepareChartMarkdown(
|
|
1209
|
+
enrichMarkdownCitations(initialMarkdown, sources ?? [])
|
|
928
1210
|
);
|
|
929
1211
|
const editor = useEditor({
|
|
930
1212
|
extensions: [
|
|
@@ -932,6 +1214,7 @@ const MarkdownWysiwygEditor = forwardRef(function MarkdownWysiwygEditor2({
|
|
|
932
1214
|
CodeBlock.configure({ lowlight, codeBlockLabels }),
|
|
933
1215
|
ImageWithConfirmDelete.configure({ inline: false }),
|
|
934
1216
|
ImportPlaceholder,
|
|
1217
|
+
createChart({ editable: true }),
|
|
935
1218
|
createCitationRef({ renderCitation }),
|
|
936
1219
|
CommentMark,
|
|
937
1220
|
commentAnchorExtension({
|
|
@@ -943,7 +1226,7 @@ const MarkdownWysiwygEditor = forwardRef(function MarkdownWysiwygEditor2({
|
|
|
943
1226
|
getId: makeTocGetId(),
|
|
944
1227
|
onUpdate: (anchors) => {
|
|
945
1228
|
onTocChange == null ? void 0 : onTocChange(
|
|
946
|
-
anchors.filter((
|
|
1229
|
+
anchors.filter((a3) => a3.level <= 6).map((a3) => ({ id: a3.id, level: a3.level, text: a3.textContent }))
|
|
947
1230
|
);
|
|
948
1231
|
}
|
|
949
1232
|
}),
|
|
@@ -1054,7 +1337,9 @@ function MarkdownPreview({
|
|
|
1054
1337
|
className
|
|
1055
1338
|
}) {
|
|
1056
1339
|
const prepared = useMemo(
|
|
1057
|
-
() =>
|
|
1340
|
+
() => prepareChartMarkdown(
|
|
1341
|
+
enrichMarkdownCitations(markdown, sources ?? [])
|
|
1342
|
+
),
|
|
1058
1343
|
[markdown, sources]
|
|
1059
1344
|
);
|
|
1060
1345
|
const extensions = useMemo(
|
|
@@ -1062,6 +1347,7 @@ function MarkdownPreview({
|
|
|
1062
1347
|
...baseExtensions,
|
|
1063
1348
|
pureCodeBlock,
|
|
1064
1349
|
pureImage,
|
|
1350
|
+
createChart({ editable: false }),
|
|
1065
1351
|
createCitationRef({ renderCitation }),
|
|
1066
1352
|
Markdown
|
|
1067
1353
|
],
|
|
@@ -1119,7 +1405,9 @@ function resolveImportMenuItems({
|
|
|
1119
1405
|
return [markdown];
|
|
1120
1406
|
}
|
|
1121
1407
|
function insertMarkdown(editor, markdown, sources = []) {
|
|
1122
|
-
const prepared =
|
|
1408
|
+
const prepared = prepareChartMarkdown(
|
|
1409
|
+
enrichMarkdownCitations(markdown, sources)
|
|
1410
|
+
);
|
|
1123
1411
|
if (!prepared) return;
|
|
1124
1412
|
if (tryInsertMarkdown(editor, prepared)) return;
|
|
1125
1413
|
for (const block of splitTopLevelBlocks(prepared)) {
|
|
@@ -2849,9 +3137,10 @@ export {
|
|
|
2849
3137
|
COMMENT_ACTIVE_META,
|
|
2850
3138
|
COMMENT_CLICK_META,
|
|
2851
3139
|
COMMENT_GUTTER_META,
|
|
3140
|
+
C as ChartMount,
|
|
2852
3141
|
CheckIcon,
|
|
2853
3142
|
ChevronDownIcon,
|
|
2854
|
-
|
|
3143
|
+
a as CitationInteractive,
|
|
2855
3144
|
CitationRef,
|
|
2856
3145
|
CodeBlockView,
|
|
2857
3146
|
CodeIcon,
|
|
@@ -2877,8 +3166,9 @@ export {
|
|
|
2877
3166
|
MarkdownWysiwygEditor,
|
|
2878
3167
|
MenuIcon,
|
|
2879
3168
|
RedoIcon,
|
|
2880
|
-
|
|
2881
|
-
|
|
3169
|
+
R2 as ReportContent,
|
|
3170
|
+
R as ReportContentInteractive,
|
|
3171
|
+
b as ReportContentWithCharts,
|
|
2882
3172
|
RowAfterIcon,
|
|
2883
3173
|
RowBeforeIcon,
|
|
2884
3174
|
RowDeleteIcon,
|
|
@@ -2888,16 +3178,18 @@ export {
|
|
|
2888
3178
|
TrashIcon,
|
|
2889
3179
|
UnderlineIcon,
|
|
2890
3180
|
UndoIcon,
|
|
2891
|
-
|
|
3181
|
+
a2 as applyCitationSources,
|
|
2892
3182
|
applyCommentAnchorsToEditor,
|
|
2893
3183
|
baseExtensions,
|
|
2894
|
-
|
|
3184
|
+
g as blockTextHash,
|
|
2895
3185
|
collectCommentIds,
|
|
2896
3186
|
commentAnchorExtension,
|
|
2897
3187
|
commentAnchorPlugin,
|
|
2898
3188
|
commentAnchorPluginKey,
|
|
2899
3189
|
commentRangesById,
|
|
3190
|
+
createChart,
|
|
2900
3191
|
createCitationRef,
|
|
3192
|
+
defaultChartLabels,
|
|
2901
3193
|
defaultCodeBlockLabels,
|
|
2902
3194
|
defaultColorPaletteLabels,
|
|
2903
3195
|
defaultCommentLabels,
|
|
@@ -2913,12 +3205,17 @@ export {
|
|
|
2913
3205
|
makeTocGetId,
|
|
2914
3206
|
mapCommentAnchors,
|
|
2915
3207
|
mergeCommentIntervals,
|
|
3208
|
+
m as mountChartsInContainer,
|
|
2916
3209
|
nextComment,
|
|
3210
|
+
prepareChartMarkdown,
|
|
3211
|
+
d as pureChart,
|
|
2917
3212
|
pureCodeBlock,
|
|
2918
3213
|
pureImage,
|
|
2919
3214
|
r as readCitationAttrs,
|
|
2920
|
-
|
|
2921
|
-
s as
|
|
3215
|
+
reportChart,
|
|
3216
|
+
s as scrollToTocHeading,
|
|
3217
|
+
serializeChartPayload,
|
|
3218
|
+
s2 as stabilizeMarkdown,
|
|
2922
3219
|
stripCommentAnchorMarks,
|
|
2923
3220
|
useIsMobile
|
|
2924
3221
|
};
|