tiptap-markdown-react 0.8.11 → 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.
Files changed (45) hide show
  1. package/README.md +32 -0
  2. package/dist/ReportContent-Re3hNps8.js +368 -0
  3. package/dist/ReportContent-Re3hNps8.js.map +1 -0
  4. package/dist/chart/ChartExtension.d.ts +21 -0
  5. package/dist/chart/chartRoundTrip.test.d.ts +1 -0
  6. package/dist/chart/columnMatching.d.ts +19 -0
  7. package/dist/chart/createChart.d.ts +19 -0
  8. package/dist/chart/mapData.d.ts +22 -0
  9. package/dist/chart/mapData.test.d.ts +1 -0
  10. package/dist/chart/parse.d.ts +31 -0
  11. package/dist/chart/parse.test.d.ts +1 -0
  12. package/dist/chart/prepareChartMarkdown.d.ts +5 -0
  13. package/dist/chart/renderChart.d.ts +12 -0
  14. package/dist/chart/serialize.d.ts +1 -0
  15. package/dist/chart/theme.d.ts +3 -0
  16. package/dist/chart/types.d.ts +41 -0
  17. package/dist/components/ChartEditorPopover.d.ts +12 -0
  18. package/dist/components/ChartMount.d.ts +14 -0
  19. package/dist/components/ChartView.d.ts +2 -0
  20. package/dist/components/MarkdownPreview.d.ts +3 -2
  21. package/dist/components/ReportContentWithCharts.d.ts +13 -0
  22. package/dist/extensions.d.ts +4 -3
  23. package/dist/{extractToc-CecK9W_w.js → extractToc-Dv40DtV5.js} +145 -9
  24. package/dist/extractToc-Dv40DtV5.js.map +1 -0
  25. package/dist/icons/index.d.ts +2 -1
  26. package/dist/index.d.ts +8 -2
  27. package/dist/index.js +725 -180
  28. package/dist/index.js.map +1 -1
  29. package/dist/labels.d.ts +24 -0
  30. package/dist/reader.d.ts +3 -8
  31. package/dist/reader.js +9 -6
  32. package/dist/scrollToTocHeading-CIJu2AcX.js +496 -0
  33. package/dist/scrollToTocHeading-CIJu2AcX.js.map +1 -0
  34. package/dist/server.d.ts +4 -1
  35. package/dist/server.js +17 -9
  36. package/dist/server.js.map +1 -1
  37. package/dist/style.css +296 -57
  38. package/dist/tableSelection.d.ts +29 -0
  39. package/dist/tableSelection.test.d.ts +1 -0
  40. package/package.json +12 -4
  41. package/dist/ReportContent-c_UlJnVY.js +0 -68
  42. package/dist/ReportContent-c_UlJnVY.js.map +0 -1
  43. package/dist/extractToc-CecK9W_w.js.map +0 -1
  44. package/dist/scrollToTocHeading-CwapFaVP.js +0 -126
  45. package/dist/scrollToTocHeading-CwapFaVP.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,24 +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 { forwardRef, useEffect, useRef, useImperativeHandle, useMemo, useState, useId, useCallback, useContext, createContext } from "react";
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";
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
- import { C, R as R2, f, r, s as s2 } from "./scrollToTocHeading-CwapFaVP.js";
23
+ import { isInTable, selectedRect, rowIsHeader, CellSelection } from "@tiptap/pm/tables";
22
24
  function CitationRefView({ node, extension }) {
23
25
  const index = String(node.attrs.index ?? "");
24
26
  const url = node.attrs.url || null;
@@ -85,9 +87,9 @@ function stripCommentAnchorMarks(slice, markType) {
85
87
  const strip = (fragment) => {
86
88
  const children = [];
87
89
  fragment.forEach((child) => {
88
- if (child.isText && child.marks.some((m) => m.type === markType)) {
90
+ if (child.isText && child.marks.some((m2) => m2.type === markType)) {
89
91
  children.push(
90
- child.mark(child.marks.filter((m) => m.type !== markType))
92
+ child.mark(child.marks.filter((m2) => m2.type !== markType))
91
93
  );
92
94
  } else if (child.content.size > 0) {
93
95
  children.push(child.copy(strip(child.content)));
@@ -102,7 +104,7 @@ function stripCommentAnchorMarks(slice, markType) {
102
104
  function sliceHasCommentMarks(slice, markType) {
103
105
  let found = false;
104
106
  slice.content.descendants((node) => {
105
- if (node.isText && node.marks.some((m) => m.type === markType)) {
107
+ if (node.isText && node.marks.some((m2) => m2.type === markType)) {
106
108
  found = true;
107
109
  return false;
108
110
  }
@@ -121,9 +123,9 @@ function collectCommentRanges(doc) {
121
123
  const byId = /* @__PURE__ */ new Map();
122
124
  doc.descendants((node, pos) => {
123
125
  if (!node.isText) return true;
124
- for (const m of node.marks) {
125
- if (m.type.name !== "commentAnchor") continue;
126
- const ids = m.attrs.commentIds ?? [];
126
+ for (const m2 of node.marks) {
127
+ if (m2.type.name !== "commentAnchor") continue;
128
+ const ids = m2.attrs.commentIds ?? [];
127
129
  for (const id of ids) {
128
130
  const arr = byId.get(id) ?? [];
129
131
  arr.push({ from: pos, to: pos + node.nodeSize });
@@ -179,19 +181,19 @@ function commentAnchorPlugin(options = {}) {
179
181
  const decos = [];
180
182
  const bounds = blockBounds(state.doc);
181
183
  if (showGutter) {
182
- for (const b of bounds) {
184
+ for (const b2 of bounds) {
183
185
  const idsInBlock = [];
184
186
  for (const [id, ranges] of byId) {
185
- if (rangesIntersectBlock(ranges, b.start, b.end)) {
187
+ if (rangesIntersectBlock(ranges, b2.start, b2.end)) {
186
188
  idsInBlock.push(id);
187
189
  }
188
190
  }
189
191
  if (idsInBlock.length > 0) {
190
192
  decos.push(
191
193
  Decoration.widget(
192
- b.start,
193
- (view) => gutterDom(idsInBlock, view, b.start),
194
- { side: -1, key: `tmr-gutter:${b.start}` }
194
+ b2.start,
195
+ (view) => gutterDom(idsInBlock, view, b2.start),
196
+ { side: -1, key: `tmr-gutter:${b2.start}` }
195
197
  )
196
198
  );
197
199
  }
@@ -205,10 +207,10 @@ function commentAnchorPlugin(options = {}) {
205
207
  Decoration.inline(r2.from, r2.to, { class: "tmr-comment-active" })
206
208
  );
207
209
  }
208
- for (const b of bounds) {
209
- if (rangesIntersectBlock(ranges, b.start, b.end)) {
210
+ for (const b2 of bounds) {
211
+ if (rangesIntersectBlock(ranges, b2.start, b2.end)) {
210
212
  decos.push(
211
- Decoration.node(b.start, b.end, {
213
+ Decoration.node(b2.start, b2.end, {
212
214
  class: "tmr-comment-block-active"
213
215
  })
214
216
  );
@@ -271,9 +273,9 @@ function collectCommentIds(editor) {
271
273
  const ids = [];
272
274
  editor.state.doc.descendants((node) => {
273
275
  if (!node.isText) return true;
274
- for (const m of node.marks) {
275
- if (m.type.name !== "commentAnchor") continue;
276
- for (const id of m.attrs.commentIds ?? []) {
276
+ for (const m2 of node.marks) {
277
+ if (m2.type.name !== "commentAnchor") continue;
278
+ for (const id of m2.attrs.commentIds ?? []) {
277
279
  if (!ids.includes(id)) ids.push(id);
278
280
  }
279
281
  }
@@ -285,9 +287,9 @@ function commentRangesById(editor, commentId) {
285
287
  const ranges = [];
286
288
  editor.state.doc.descendants((node, pos) => {
287
289
  if (!node.isText) return true;
288
- for (const m of node.marks) {
289
- if (m.type.name !== "commentAnchor") continue;
290
- const ids = m.attrs.commentIds ?? [];
290
+ for (const m2 of node.marks) {
291
+ if (m2.type.name !== "commentAnchor") continue;
292
+ const ids = m2.attrs.commentIds ?? [];
291
293
  if (ids.includes(commentId)) {
292
294
  ranges.push({ from: pos, to: pos + node.nodeSize });
293
295
  }
@@ -495,6 +497,374 @@ const MarkdownPaste = Extension.create({
495
497
  ];
496
498
  }
497
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
+ }
498
868
  function Svg({ size = "1em", children, ...rest }) {
499
869
  return /* @__PURE__ */ jsx(
500
870
  "svg",
@@ -636,84 +1006,13 @@ const RowDeleteIcon = (p) => /* @__PURE__ */ jsxs(Svg, { ...p, children: [
636
1006
  /* @__PURE__ */ jsx("path", { d: "m9 8 6 8" }),
637
1007
  /* @__PURE__ */ jsx("path", { d: "m15 8-6 8" })
638
1008
  ] });
639
- const defaultToolbarLabels = {
640
- undo: "Undo",
641
- redo: "Redo",
642
- style: "Style",
643
- normalText: "Normal text",
644
- headingLabel: (level) => `Heading ${level}`,
645
- fontSize: "Font size",
646
- fontSizeDefault: "Default",
647
- bold: "Bold",
648
- italic: "Italic",
649
- underline: "Underline",
650
- strike: "Strikethrough",
651
- code: "Inline code",
652
- textColor: "Text color",
653
- highlight: "Highlight",
654
- colorNone: "None",
655
- colorTheme: "THEME",
656
- scriptMenu: "Superscript / Subscript",
657
- scriptNormal: "Normal",
658
- superscript: "Superscript",
659
- subscript: "Subscript",
660
- link: "Link",
661
- linkPrompt: "Enter URL",
662
- image: "Image",
663
- imageUploadFailed: "Image upload failed",
664
- importMarkdownFailed: "Markdown import failed",
665
- importDocument: "Import",
666
- importDocumentHint: "Import a file",
667
- importDocumentOther: "Document",
668
- importDocumentBusy: "Importing…",
669
- importDocumentUploading: (percent) => `Uploading ${percent}%`,
670
- importDocumentConverting: "Converting…",
671
- importDocumentFailed: "Import failed",
672
- blockquote: "Blockquote",
673
- bulletList: "Bullet list",
674
- orderedList: "Ordered list",
675
- taskList: "Task list",
676
- more: "More",
677
- codeBlock: "Code block",
678
- hr: "Divider",
679
- importMarkdown: "Markdown",
680
- tableInsert: "Insert table",
681
- tableAddColumnBefore: "Add column before",
682
- tableAddColumnAfter: "Add column after",
683
- tableDeleteColumn: "Delete column",
684
- tableAddRowBefore: "Add row before",
685
- tableAddRowAfter: "Add row after",
686
- tableDeleteRow: "Delete row",
687
- inlineMath: "Inline equation",
688
- blockMath: "Block equation",
689
- mathPlaceholder: "E = mc^2",
690
- mathDone: "Done",
691
- mathCancel: "Cancel",
692
- mathNewInline: "New equation",
693
- mathNewBlock: "Add a TeX equation"
694
- };
695
- const defaultColorPaletteLabels = {
696
- none: "None",
697
- theme: "THEME"
698
- };
699
- const defaultTocLabels = {
700
- title: "Contents",
701
- expand: "Expand",
702
- collapse: "Collapse"
703
- };
704
- const defaultCodeBlockLabels = {
705
- autoDetect: "Auto-detect",
706
- delete: "Delete code block"
707
- };
708
- const defaultCommentLabels = {
709
- open: "Open",
710
- resolved: "Resolved",
711
- dismissed: "Dismissed",
712
- outdated: "Outdated",
713
- ambiguous: "Ambiguous",
714
- partial: "Partially matched",
715
- gutterTitle: "Comment"
716
- };
1009
+ const TableDeleteIcon = (p) => /* @__PURE__ */ jsxs(Svg, { ...p, children: [
1010
+ /* @__PURE__ */ jsx("rect", { x: "3", y: "5", width: "18", height: "14", rx: "1" }),
1011
+ /* @__PURE__ */ jsx("path", { d: "M3 9h18" }),
1012
+ /* @__PURE__ */ jsx("path", { d: "M9 5v14" }),
1013
+ /* @__PURE__ */ jsx("path", { d: "M15 5v14" }),
1014
+ /* @__PURE__ */ jsx("path", { d: "m7 2 10 20" })
1015
+ ] });
717
1016
  const wrapper = "_wrapper_5i2vi_2";
718
1017
  const header$1 = "_header_5i2vi_18";
719
1018
  const langTrigger = "_langTrigger_5i2vi_28";
@@ -906,9 +1205,8 @@ const MarkdownWysiwygEditor = forwardRef(function MarkdownWysiwygEditor2({
906
1205
  showCommentGutter = true,
907
1206
  commentInteractive = true
908
1207
  }, ref) {
909
- const preparedInitial = enrichMarkdownCitations(
910
- initialMarkdown,
911
- sources ?? []
1208
+ const preparedInitial = prepareChartMarkdown(
1209
+ enrichMarkdownCitations(initialMarkdown, sources ?? [])
912
1210
  );
913
1211
  const editor = useEditor({
914
1212
  extensions: [
@@ -916,6 +1214,7 @@ const MarkdownWysiwygEditor = forwardRef(function MarkdownWysiwygEditor2({
916
1214
  CodeBlock.configure({ lowlight, codeBlockLabels }),
917
1215
  ImageWithConfirmDelete.configure({ inline: false }),
918
1216
  ImportPlaceholder,
1217
+ createChart({ editable: true }),
919
1218
  createCitationRef({ renderCitation }),
920
1219
  CommentMark,
921
1220
  commentAnchorExtension({
@@ -927,7 +1226,7 @@ const MarkdownWysiwygEditor = forwardRef(function MarkdownWysiwygEditor2({
927
1226
  getId: makeTocGetId(),
928
1227
  onUpdate: (anchors) => {
929
1228
  onTocChange == null ? void 0 : onTocChange(
930
- anchors.filter((a2) => a2.level <= 6).map((a2) => ({ id: a2.id, level: a2.level, text: a2.textContent }))
1229
+ anchors.filter((a3) => a3.level <= 6).map((a3) => ({ id: a3.id, level: a3.level, text: a3.textContent }))
931
1230
  );
932
1231
  }
933
1232
  }),
@@ -1038,7 +1337,9 @@ function MarkdownPreview({
1038
1337
  className
1039
1338
  }) {
1040
1339
  const prepared = useMemo(
1041
- () => enrichMarkdownCitations(markdown, sources ?? []),
1340
+ () => prepareChartMarkdown(
1341
+ enrichMarkdownCitations(markdown, sources ?? [])
1342
+ ),
1042
1343
  [markdown, sources]
1043
1344
  );
1044
1345
  const extensions = useMemo(
@@ -1046,6 +1347,7 @@ function MarkdownPreview({
1046
1347
  ...baseExtensions,
1047
1348
  pureCodeBlock,
1048
1349
  pureImage,
1350
+ createChart({ editable: false }),
1049
1351
  createCitationRef({ renderCitation }),
1050
1352
  Markdown
1051
1353
  ],
@@ -1103,7 +1405,9 @@ function resolveImportMenuItems({
1103
1405
  return [markdown];
1104
1406
  }
1105
1407
  function insertMarkdown(editor, markdown, sources = []) {
1106
- const prepared = enrichMarkdownCitations(markdown, sources);
1408
+ const prepared = prepareChartMarkdown(
1409
+ enrichMarkdownCitations(markdown, sources)
1410
+ );
1107
1411
  if (!prepared) return;
1108
1412
  if (tryInsertMarkdown(editor, prepared)) return;
1109
1413
  for (const block of splitTopLevelBlocks(prepared)) {
@@ -1142,45 +1446,140 @@ function splitTopLevelBlocks(markdown) {
1142
1446
  function stripToPlainText(markdown) {
1143
1447
  return markdown.replace(/!\[[^\]]*\]\([^)]+\)/g, "").replace(/\[([^\]]+)\]\([^)]+\)/g, "$1").replace(/^#{1,6}\s+/gm, "").replace(/^[ \t]*[-*+]\s+/gm, "").replace(/^[ \t]*\d+\.\s+/gm, "").replace(/[*_~`]+/g, "").replace(/<[^>]+>/g, "").replace(/\|/g, " ").replace(/\s+/g, " ").trim();
1144
1448
  }
1145
- const toolbar = "_toolbar_16b09_2";
1146
- const inner = "_inner_16b09_15";
1147
- const btn = "_btn_16b09_27";
1148
- const btnActive = "_btnActive_16b09_50";
1149
- const tableBubble = "_tableBubble_16b09_66";
1150
- const txtIcon = "_txtIcon_16b09_78";
1151
- const colorIcon = "_colorIcon_16b09_86";
1152
- const colorIconGlyph = "_colorIconGlyph_16b09_94";
1153
- const colorIconBar = "_colorIconBar_16b09_100";
1154
- const scriptTrigger = "_scriptTrigger_16b09_107";
1155
- const scriptTriggerGlyph = "_scriptTriggerGlyph_16b09_127";
1156
- const divider = "_divider_16b09_135";
1157
- const styleTrigger = "_styleTrigger_16b09_144";
1158
- const styleTriggerLabel = "_styleTriggerLabel_16b09_173";
1159
- const styleTriggerCaret = "_styleTriggerCaret_16b09_181";
1160
- const styleItem = "_styleItem_16b09_187";
1161
- const styleIcon = "_styleIcon_16b09_193";
1162
- const scriptGlyph = "_scriptGlyph_16b09_203";
1163
- const menu = "_menu_16b09_215";
1164
- const menuItem = "_menuItem_16b09_226";
1165
- const menuItemSelected = "_menuItemSelected_16b09_252";
1166
- const popoverContent$1 = "_popoverContent_16b09_266";
1167
- const mathLayer = "_mathLayer_16b09_270";
1168
- const mathStack = "_mathStack_16b09_275";
1169
- const mathStackBlock = "_mathStackBlock_16b09_282";
1170
- const mathHint = "_mathHint_16b09_287";
1171
- const mathHintBlock = "_mathHintBlock_16b09_299";
1172
- const mathHintIcon = "_mathHintIcon_16b09_305";
1173
- const mathField = "_mathField_16b09_336";
1174
- const mathFieldBlock = "_mathFieldBlock_16b09_348";
1175
- const mathInput = "_mathInput_16b09_355";
1176
- const mathDone = "_mathDone_16b09_373";
1177
- const mathDoneKbd = "_mathDoneKbd_16b09_398";
1449
+ function getTableSelectionInfo(state) {
1450
+ if (!isInTable(state)) return null;
1451
+ const rect = selectedRect(state);
1452
+ const rowCount = Math.max(1, rect.bottom - rect.top);
1453
+ const colCount = Math.max(1, rect.right - rect.left);
1454
+ let includesHeaderRow = false;
1455
+ for (let row = rect.top; row < rect.bottom; row++) {
1456
+ if (rowIsHeader(rect.map, rect.table, row)) {
1457
+ includesHeaderRow = true;
1458
+ break;
1459
+ }
1460
+ }
1461
+ return {
1462
+ rowCount,
1463
+ colCount,
1464
+ isMultiCell: rowCount > 1 || colCount > 1,
1465
+ includesHeaderRow,
1466
+ coversAllRows: rect.top === 0 && rect.bottom === rect.map.height,
1467
+ coversAllCols: rect.left === 0 && rect.right === rect.map.width
1468
+ };
1469
+ }
1470
+ function isPosInCellSelection(selection, pos) {
1471
+ let found = false;
1472
+ selection.forEachCell((node, cellPos) => {
1473
+ if (pos >= cellPos && pos <= cellPos + node.nodeSize) {
1474
+ found = true;
1475
+ }
1476
+ });
1477
+ return found;
1478
+ }
1479
+ function preserveTableSelectionOnContextMenu(editor, pos) {
1480
+ const { selection } = editor.state;
1481
+ if (selection instanceof CellSelection && isPosInCellSelection(selection, pos)) {
1482
+ editor.view.focus();
1483
+ return;
1484
+ }
1485
+ editor.chain().focus().setTextSelection(pos).run();
1486
+ }
1487
+ function addRowsBefore(editor, count) {
1488
+ const n = Math.max(1, count);
1489
+ for (let i = 0; i < n; i++) {
1490
+ if (!editor.commands.addRowBefore()) return false;
1491
+ }
1492
+ return true;
1493
+ }
1494
+ function addRowsAfter(editor, count) {
1495
+ const n = Math.max(1, count);
1496
+ for (let i = 0; i < n; i++) {
1497
+ if (!editor.commands.addRowAfter()) return false;
1498
+ }
1499
+ return true;
1500
+ }
1501
+ function addColumnsBefore(editor, count) {
1502
+ const n = Math.max(1, count);
1503
+ for (let i = 0; i < n; i++) {
1504
+ if (!editor.commands.addColumnBefore()) return false;
1505
+ }
1506
+ return true;
1507
+ }
1508
+ function addColumnsAfter(editor, count) {
1509
+ const n = Math.max(1, count);
1510
+ for (let i = 0; i < n; i++) {
1511
+ if (!editor.commands.addColumnAfter()) return false;
1512
+ }
1513
+ return true;
1514
+ }
1515
+ function deleteSelectedRows(editor) {
1516
+ const info = getTableSelectionInfo(editor.state);
1517
+ if (!info) return false;
1518
+ if (info.coversAllRows) return editor.commands.deleteTable();
1519
+ return editor.commands.deleteRow();
1520
+ }
1521
+ function deleteSelectedColumns(editor) {
1522
+ const info = getTableSelectionInfo(editor.state);
1523
+ if (!info) return false;
1524
+ if (info.coversAllCols) {
1525
+ if (info.coversAllRows) return editor.commands.deleteTable();
1526
+ return false;
1527
+ }
1528
+ return editor.commands.deleteColumn();
1529
+ }
1530
+ const toolbar = "_toolbar_1f7fb_2";
1531
+ const inner = "_inner_1f7fb_15";
1532
+ const btn = "_btn_1f7fb_27";
1533
+ const btnActive = "_btnActive_1f7fb_50";
1534
+ const tableBubble = "_tableBubble_1f7fb_66";
1535
+ const tableMenuItem = "_tableMenuItem_1f7fb_77";
1536
+ const tableMenuItemIcon = "_tableMenuItemIcon_1f7fb_103";
1537
+ const tableMenuItemLabel = "_tableMenuItemLabel_1f7fb_113";
1538
+ const tableMenuDivider = "_tableMenuDivider_1f7fb_118";
1539
+ const txtIcon = "_txtIcon_1f7fb_126";
1540
+ const colorIcon = "_colorIcon_1f7fb_134";
1541
+ const colorIconGlyph = "_colorIconGlyph_1f7fb_142";
1542
+ const colorIconBar = "_colorIconBar_1f7fb_148";
1543
+ const scriptTrigger = "_scriptTrigger_1f7fb_155";
1544
+ const scriptTriggerGlyph = "_scriptTriggerGlyph_1f7fb_175";
1545
+ const divider = "_divider_1f7fb_183";
1546
+ const styleTrigger = "_styleTrigger_1f7fb_192";
1547
+ const styleTriggerLabel = "_styleTriggerLabel_1f7fb_221";
1548
+ const styleTriggerCaret = "_styleTriggerCaret_1f7fb_229";
1549
+ const styleItem = "_styleItem_1f7fb_235";
1550
+ const styleIcon = "_styleIcon_1f7fb_241";
1551
+ const scriptGlyph = "_scriptGlyph_1f7fb_251";
1552
+ const menu = "_menu_1f7fb_263";
1553
+ const menuItem = "_menuItem_1f7fb_274";
1554
+ const menuItemSelected = "_menuItemSelected_1f7fb_301";
1555
+ const tableInsertCaret = "_tableInsertCaret_1f7fb_314";
1556
+ const tableSizePicker = "_tableSizePicker_1f7fb_322";
1557
+ const tableSizeGrid = "_tableSizeGrid_1f7fb_332";
1558
+ const tableSizeCell = "_tableSizeCell_1f7fb_337";
1559
+ const tableSizeCellActive = "_tableSizeCellActive_1f7fb_347";
1560
+ const tableSizeLabel = "_tableSizeLabel_1f7fb_352";
1561
+ const popoverContent$1 = "_popoverContent_1f7fb_361";
1562
+ const mathLayer = "_mathLayer_1f7fb_365";
1563
+ const mathStack = "_mathStack_1f7fb_370";
1564
+ const mathStackBlock = "_mathStackBlock_1f7fb_377";
1565
+ const mathHint = "_mathHint_1f7fb_382";
1566
+ const mathHintBlock = "_mathHintBlock_1f7fb_394";
1567
+ const mathHintIcon = "_mathHintIcon_1f7fb_400";
1568
+ const mathField = "_mathField_1f7fb_431";
1569
+ const mathFieldBlock = "_mathFieldBlock_1f7fb_443";
1570
+ const mathInput = "_mathInput_1f7fb_450";
1571
+ const mathDone = "_mathDone_1f7fb_468";
1572
+ const mathDoneKbd = "_mathDoneKbd_1f7fb_493";
1178
1573
  const styles$3 = {
1179
1574
  toolbar,
1180
1575
  inner,
1181
1576
  btn,
1182
1577
  btnActive,
1183
1578
  tableBubble,
1579
+ tableMenuItem,
1580
+ tableMenuItemIcon,
1581
+ tableMenuItemLabel,
1582
+ tableMenuDivider,
1184
1583
  txtIcon,
1185
1584
  colorIcon,
1186
1585
  colorIconGlyph,
@@ -1197,6 +1596,12 @@ const styles$3 = {
1197
1596
  menu,
1198
1597
  menuItem,
1199
1598
  menuItemSelected,
1599
+ tableInsertCaret,
1600
+ tableSizePicker,
1601
+ tableSizeGrid,
1602
+ tableSizeCell,
1603
+ tableSizeCellActive,
1604
+ tableSizeLabel,
1200
1605
  popoverContent: popoverContent$1,
1201
1606
  mathLayer,
1202
1607
  mathStack,
@@ -1539,6 +1944,30 @@ function ToolbarButton({
1539
1944
  function Divider() {
1540
1945
  return /* @__PURE__ */ jsx("span", { className: styles$3.divider, "aria-hidden": true });
1541
1946
  }
1947
+ function TableMenuItem({
1948
+ label,
1949
+ disabled,
1950
+ onClick,
1951
+ children
1952
+ }) {
1953
+ return /* @__PURE__ */ jsxs(
1954
+ "button",
1955
+ {
1956
+ type: "button",
1957
+ disabled,
1958
+ className: styles$3.tableMenuItem,
1959
+ onMouseDown: (e2) => e2.preventDefault(),
1960
+ onClick,
1961
+ children: [
1962
+ /* @__PURE__ */ jsx("span", { className: styles$3.tableMenuItemIcon, "aria-hidden": true, children }),
1963
+ /* @__PURE__ */ jsx("span", { className: styles$3.tableMenuItemLabel, children: label })
1964
+ ]
1965
+ }
1966
+ );
1967
+ }
1968
+ function TableMenuDivider() {
1969
+ return /* @__PURE__ */ jsx("div", { className: styles$3.tableMenuDivider, "aria-hidden": true });
1970
+ }
1542
1971
  const MenuCloseCtx = createContext(() => {
1543
1972
  });
1544
1973
  function MenuPopover({
@@ -1584,6 +2013,92 @@ function MenuItem({
1584
2013
  }
1585
2014
  );
1586
2015
  }
2016
+ const TABLE_PICKER_COLS = 10;
2017
+ const TABLE_PICKER_ROWS = 8;
2018
+ function TableInsertItem({
2019
+ disabled,
2020
+ labels,
2021
+ onInsert
2022
+ }) {
2023
+ const closeMenu = useContext(MenuCloseCtx);
2024
+ const [open, setOpen] = useState(false);
2025
+ const [hover, setHover] = useState({ cols: 0, rows: 0 });
2026
+ const resetHover = useCallback(() => setHover({ cols: 0, rows: 0 }), []);
2027
+ return /* @__PURE__ */ jsxs(
2028
+ Popover.Root,
2029
+ {
2030
+ open,
2031
+ onOpenChange: (next) => {
2032
+ setOpen(next);
2033
+ if (!next) resetHover();
2034
+ },
2035
+ children: [
2036
+ /* @__PURE__ */ jsx(Popover.Trigger, { asChild: true, children: /* @__PURE__ */ jsxs(
2037
+ "button",
2038
+ {
2039
+ type: "button",
2040
+ disabled,
2041
+ className: `${styles$3.menuItem} ${open ? styles$3.menuItemSelected : ""}`,
2042
+ onMouseDown: (e2) => e2.preventDefault(),
2043
+ children: [
2044
+ /* @__PURE__ */ jsxs("span", { className: styles$3.styleItem, children: [
2045
+ /* @__PURE__ */ jsx("span", { className: styles$3.styleIcon, children: "⊞" }),
2046
+ labels.tableInsert
2047
+ ] }),
2048
+ /* @__PURE__ */ jsx(ChevronDownIcon, { size: 12, className: styles$3.tableInsertCaret })
2049
+ ]
2050
+ }
2051
+ ) }),
2052
+ /* @__PURE__ */ jsx(Popover.Portal, { children: /* @__PURE__ */ jsxs(
2053
+ Popover.Content,
2054
+ {
2055
+ className: styles$3.tableSizePicker,
2056
+ side: "right",
2057
+ align: "start",
2058
+ sideOffset: 6,
2059
+ onOpenAutoFocus: (e2) => e2.preventDefault(),
2060
+ onCloseAutoFocus: (e2) => e2.preventDefault(),
2061
+ children: [
2062
+ /* @__PURE__ */ jsx(
2063
+ "div",
2064
+ {
2065
+ className: styles$3.tableSizeGrid,
2066
+ style: {
2067
+ gridTemplateColumns: `repeat(${TABLE_PICKER_COLS}, 1fr)`
2068
+ },
2069
+ onMouseLeave: resetHover,
2070
+ children: Array.from({ length: TABLE_PICKER_ROWS * TABLE_PICKER_COLS }, (_, i) => {
2071
+ const col = i % TABLE_PICKER_COLS + 1;
2072
+ const row = Math.floor(i / TABLE_PICKER_COLS) + 1;
2073
+ const active2 = hover.cols > 0 && col <= hover.cols && row <= hover.rows;
2074
+ return /* @__PURE__ */ jsx(
2075
+ "button",
2076
+ {
2077
+ type: "button",
2078
+ "aria-label": labels.tableSizeSelected(col, row),
2079
+ className: `${styles$3.tableSizeCell} ${active2 ? styles$3.tableSizeCellActive : ""}`,
2080
+ onMouseDown: (e2) => e2.preventDefault(),
2081
+ onMouseEnter: () => setHover({ cols: col, rows: row }),
2082
+ onClick: () => {
2083
+ onInsert(row, col);
2084
+ setOpen(false);
2085
+ resetHover();
2086
+ closeMenu();
2087
+ }
2088
+ },
2089
+ i
2090
+ );
2091
+ })
2092
+ }
2093
+ ),
2094
+ /* @__PURE__ */ jsx("div", { className: styles$3.tableSizeLabel, children: hover.cols > 0 ? labels.tableSizeSelected(hover.cols, hover.rows) : labels.tableInsert })
2095
+ ]
2096
+ }
2097
+ ) })
2098
+ ]
2099
+ }
2100
+ );
2101
+ }
1587
2102
  function ColorPopover({
1588
2103
  title,
1589
2104
  glyph,
@@ -1669,7 +2184,6 @@ function EditorToolbar({
1669
2184
  superscript: e2.isActive("superscript"),
1670
2185
  subscript: e2.isActive("subscript"),
1671
2186
  inTable: e2.isActive("table"),
1672
- inTableHeader: e2.isActive("tableHeader"),
1673
2187
  canUndo: e2.can().undo(),
1674
2188
  canRedo: e2.can().redo()
1675
2189
  })
@@ -1709,7 +2223,7 @@ function EditorToolbar({
1709
2223
  }
1710
2224
  if (!inTable) return;
1711
2225
  e2.preventDefault();
1712
- editor.chain().focus().setTextSelection(coords.pos).run();
2226
+ preserveTableSelectionOnContextMenu(editor, coords.pos);
1713
2227
  setTableMenu({ x: e2.clientX, y: e2.clientY });
1714
2228
  };
1715
2229
  dom.addEventListener("contextmenu", onContextMenu);
@@ -1734,6 +2248,13 @@ function EditorToolbar({
1734
2248
  },
1735
2249
  [closeTableMenu]
1736
2250
  );
2251
+ const tableSel = tableMenu ? getTableSelectionInfo(editor.state) : null;
2252
+ const tableRowN = (tableSel == null ? void 0 : tableSel.rowCount) ?? 1;
2253
+ const tableColN = (tableSel == null ? void 0 : tableSel.colCount) ?? 1;
2254
+ const tableMulti = (tableSel == null ? void 0 : tableSel.isMultiCell) ?? false;
2255
+ const disableAddRowBefore = !!(tableSel == null ? void 0 : tableSel.includesHeaderRow);
2256
+ const disableDeleteRow = !!(tableSel == null ? void 0 : tableSel.includesHeaderRow);
2257
+ const disableDeleteColumn = !!(tableSel == null ? void 0 : tableSel.coversAllCols) && !(tableSel == null ? void 0 : tableSel.coversAllRows);
1737
2258
  const handlePickImage = () => {
1738
2259
  var _a;
1739
2260
  return (_a = fileInputRef.current) == null ? void 0 : _a.click();
@@ -2280,14 +2801,11 @@ function EditorToolbar({
2280
2801
  t.hr
2281
2802
  ] }) }),
2282
2803
  /* @__PURE__ */ jsx(
2283
- MenuItem,
2804
+ TableInsertItem,
2284
2805
  {
2285
2806
  disabled: state.inTable,
2286
- onSelect: () => chain().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run(),
2287
- children: /* @__PURE__ */ jsxs("span", { className: styles$3.styleItem, children: [
2288
- /* @__PURE__ */ jsx("span", { className: styles$3.styleIcon, children: "⊞" }),
2289
- t.tableInsert
2290
- ] })
2807
+ labels: t,
2808
+ onInsert: (rows, cols) => chain().insertTable({ rows, cols, withHeaderRow: true }).run()
2291
2809
  }
2292
2810
  ),
2293
2811
  extraToolbarItems == null ? void 0 : extraToolbarItems.map((item2) => /* @__PURE__ */ jsx(
@@ -2339,59 +2857,76 @@ function EditorToolbar({
2339
2857
  {
2340
2858
  className: styles$3.tableBubble,
2341
2859
  style: { position: "fixed", left: tableMenu.x, top: tableMenu.y },
2860
+ role: "menu",
2342
2861
  onMouseDown: (e2) => e2.stopPropagation(),
2343
2862
  onContextMenu: (e2) => e2.preventDefault(),
2344
2863
  children: [
2345
2864
  /* @__PURE__ */ jsx(
2346
- ToolbarButton,
2865
+ TableMenuItem,
2347
2866
  {
2348
- title: t.tableAddColumnBefore,
2349
- onClick: () => runTable(() => chain().addColumnBefore().run()),
2867
+ label: tableMulti ? t.tableAddColumnBeforeN(tableColN) : t.tableAddColumnBefore,
2868
+ onClick: () => runTable(() => addColumnsBefore(editor, tableColN)),
2350
2869
  children: /* @__PURE__ */ jsx(ColumnBeforeIcon, {})
2351
2870
  }
2352
2871
  ),
2353
2872
  /* @__PURE__ */ jsx(
2354
- ToolbarButton,
2873
+ TableMenuItem,
2355
2874
  {
2356
- title: t.tableAddColumnAfter,
2357
- onClick: () => runTable(() => chain().addColumnAfter().run()),
2875
+ label: tableMulti ? t.tableAddColumnAfterN(tableColN) : t.tableAddColumnAfter,
2876
+ onClick: () => runTable(() => addColumnsAfter(editor, tableColN)),
2358
2877
  children: /* @__PURE__ */ jsx(ColumnAfterIcon, {})
2359
2878
  }
2360
2879
  ),
2361
2880
  /* @__PURE__ */ jsx(
2362
- ToolbarButton,
2881
+ TableMenuItem,
2363
2882
  {
2364
- title: t.tableDeleteColumn,
2365
- onClick: () => runTable(() => chain().deleteColumn().run()),
2883
+ label: tableMulti ? t.tableDeleteColumnN(tableColN) : t.tableDeleteColumn,
2884
+ disabled: disableDeleteColumn,
2885
+ onClick: () => runTable(() => {
2886
+ deleteSelectedColumns(editor);
2887
+ }),
2366
2888
  children: /* @__PURE__ */ jsx(ColumnDeleteIcon, {})
2367
2889
  }
2368
2890
  ),
2369
- /* @__PURE__ */ jsx(Divider, {}),
2891
+ /* @__PURE__ */ jsx(TableMenuDivider, {}),
2370
2892
  /* @__PURE__ */ jsx(
2371
- ToolbarButton,
2893
+ TableMenuItem,
2372
2894
  {
2373
- title: t.tableAddRowBefore,
2374
- disabled: state.inTableHeader,
2375
- onClick: () => runTable(() => chain().addRowBefore().run()),
2895
+ label: tableMulti ? t.tableAddRowBeforeN(tableRowN) : t.tableAddRowBefore,
2896
+ disabled: disableAddRowBefore,
2897
+ onClick: () => runTable(() => addRowsBefore(editor, tableRowN)),
2376
2898
  children: /* @__PURE__ */ jsx(RowBeforeIcon, {})
2377
2899
  }
2378
2900
  ),
2379
2901
  /* @__PURE__ */ jsx(
2380
- ToolbarButton,
2902
+ TableMenuItem,
2381
2903
  {
2382
- title: t.tableAddRowAfter,
2383
- onClick: () => runTable(() => chain().addRowAfter().run()),
2904
+ label: tableMulti ? t.tableAddRowAfterN(tableRowN) : t.tableAddRowAfter,
2905
+ onClick: () => runTable(() => addRowsAfter(editor, tableRowN)),
2384
2906
  children: /* @__PURE__ */ jsx(RowAfterIcon, {})
2385
2907
  }
2386
2908
  ),
2387
2909
  /* @__PURE__ */ jsx(
2388
- ToolbarButton,
2910
+ TableMenuItem,
2389
2911
  {
2390
- title: t.tableDeleteRow,
2391
- disabled: state.inTableHeader,
2392
- onClick: () => runTable(() => chain().deleteRow().run()),
2912
+ label: tableMulti ? t.tableDeleteRowN(tableRowN) : t.tableDeleteRow,
2913
+ disabled: disableDeleteRow,
2914
+ onClick: () => runTable(() => {
2915
+ deleteSelectedRows(editor);
2916
+ }),
2393
2917
  children: /* @__PURE__ */ jsx(RowDeleteIcon, {})
2394
2918
  }
2919
+ ),
2920
+ /* @__PURE__ */ jsx(TableMenuDivider, {}),
2921
+ /* @__PURE__ */ jsx(
2922
+ TableMenuItem,
2923
+ {
2924
+ label: t.tableDeleteTable,
2925
+ onClick: () => runTable(() => {
2926
+ editor.commands.deleteTable();
2927
+ }),
2928
+ children: /* @__PURE__ */ jsx(TableDeleteIcon, {})
2929
+ }
2395
2930
  )
2396
2931
  ]
2397
2932
  }
@@ -2602,9 +3137,10 @@ export {
2602
3137
  COMMENT_ACTIVE_META,
2603
3138
  COMMENT_CLICK_META,
2604
3139
  COMMENT_GUTTER_META,
3140
+ C as ChartMount,
2605
3141
  CheckIcon,
2606
3142
  ChevronDownIcon,
2607
- C as CitationInteractive,
3143
+ a as CitationInteractive,
2608
3144
  CitationRef,
2609
3145
  CodeBlockView,
2610
3146
  CodeIcon,
@@ -2630,26 +3166,30 @@ export {
2630
3166
  MarkdownWysiwygEditor,
2631
3167
  MenuIcon,
2632
3168
  RedoIcon,
2633
- R as ReportContent,
2634
- R2 as ReportContentInteractive,
3169
+ R2 as ReportContent,
3170
+ R as ReportContentInteractive,
3171
+ b as ReportContentWithCharts,
2635
3172
  RowAfterIcon,
2636
3173
  RowBeforeIcon,
2637
3174
  RowDeleteIcon,
2638
3175
  StrikethroughIcon,
3176
+ TableDeleteIcon,
2639
3177
  TocPanel,
2640
3178
  TrashIcon,
2641
3179
  UnderlineIcon,
2642
3180
  UndoIcon,
2643
- a as applyCitationSources,
3181
+ a2 as applyCitationSources,
2644
3182
  applyCommentAnchorsToEditor,
2645
3183
  baseExtensions,
2646
- d as blockTextHash,
3184
+ g as blockTextHash,
2647
3185
  collectCommentIds,
2648
3186
  commentAnchorExtension,
2649
3187
  commentAnchorPlugin,
2650
3188
  commentAnchorPluginKey,
2651
3189
  commentRangesById,
3190
+ createChart,
2652
3191
  createCitationRef,
3192
+ defaultChartLabels,
2653
3193
  defaultCodeBlockLabels,
2654
3194
  defaultColorPaletteLabels,
2655
3195
  defaultCommentLabels,
@@ -2665,12 +3205,17 @@ export {
2665
3205
  makeTocGetId,
2666
3206
  mapCommentAnchors,
2667
3207
  mergeCommentIntervals,
3208
+ m as mountChartsInContainer,
2668
3209
  nextComment,
3210
+ prepareChartMarkdown,
3211
+ d as pureChart,
2669
3212
  pureCodeBlock,
2670
3213
  pureImage,
2671
3214
  r as readCitationAttrs,
2672
- s2 as scrollToTocHeading,
2673
- s as stabilizeMarkdown,
3215
+ reportChart,
3216
+ s as scrollToTocHeading,
3217
+ serializeChartPayload,
3218
+ s2 as stabilizeMarkdown,
2674
3219
  stripCommentAnchorMarks,
2675
3220
  useIsMobile
2676
3221
  };