tiptap-markdown-react 0.8.10 → 0.8.12

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/index.js CHANGED
@@ -6,8 +6,10 @@ import Image from "@tiptap/extension-image";
6
6
  import { TableOfContents } from "@tiptap/extension-table-of-contents";
7
7
  import { NodeViewWrapper, ReactNodeViewRenderer, NodeViewContent, useEditor, EditorContent, useEditorState } from "@tiptap/react";
8
8
  import { forwardRef, useEffect, useRef, useImperativeHandle, useMemo, useState, useId, useCallback, useContext, createContext } from "react";
9
- import { C as CitationRef, m as mergeCommentIntervals, a as mapCommentAnchors, e as enrichMarkdownCitations, s as styles$5, b as baseExtensions, c as CommentMark, l as lowlight, d as makeTocGetId, p as pureCodeBlock, f as pureImage, r as renderMathInto, g as subscribeMathClick, R as ReportContent } from "./extractToc-DiY1iu1J.js";
10
- import { h, i, j, k } from "./extractToc-DiY1iu1J.js";
9
+ import { e as enrichMarkdownCitations, s as styles$5 } from "./ReportContent-c_UlJnVY.js";
10
+ import { R, a } from "./ReportContent-c_UlJnVY.js";
11
+ import { C as CitationRef, g as mergeCommentIntervals, f as mapCommentAnchors, b as baseExtensions, c as CommentMark, l as lowlight, m as makeTocGetId, p as pureCodeBlock, a as pureImage, h as renderMathInto, i as subscribeMathClick } from "./extractToc-CecK9W_w.js";
12
+ import { d, e, s } from "./extractToc-CecK9W_w.js";
11
13
  import { Slice, Fragment } from "@tiptap/pm/model";
12
14
  import { Extension, Node as Node$1 } from "@tiptap/core";
13
15
  import { PluginKey, Plugin } from "@tiptap/pm/state";
@@ -16,6 +18,8 @@ import { FileHandlePlugin } from "@tiptap/extension-file-handler";
16
18
  import * as DropdownMenu from "@radix-ui/react-dropdown-menu";
17
19
  import * as Popover from "@radix-ui/react-popover";
18
20
  import { createPortal } from "react-dom";
21
+ import { isInTable, selectedRect, rowIsHeader, CellSelection } from "@tiptap/pm/tables";
22
+ import { C, R as R2, f, r, s as s2 } from "./scrollToTocHeading-CwapFaVP.js";
19
23
  function CitationRefView({ node, extension }) {
20
24
  const index = String(node.attrs.index ?? "");
21
25
  const url = node.attrs.url || null;
@@ -132,7 +136,7 @@ function collectCommentRanges(doc) {
132
136
  return byId;
133
137
  }
134
138
  function rangesIntersectBlock(ranges, start, end) {
135
- return ranges.some((r) => r.from < end && r.to > start);
139
+ return ranges.some((r2) => r2.from < end && r2.to > start);
136
140
  }
137
141
  function gutterDom(commentIds, view, blockPos) {
138
142
  const el = document.createElement("span");
@@ -140,13 +144,13 @@ function gutterDom(commentIds, view, blockPos) {
140
144
  el.setAttribute("data-comment-ids", commentIds.join(" "));
141
145
  el.textContent = String(commentIds.length);
142
146
  el.title = `${commentIds.length}`;
143
- el.addEventListener("mousedown", (e) => {
144
- e.preventDefault();
145
- e.stopPropagation();
147
+ el.addEventListener("mousedown", (e2) => {
148
+ e2.preventDefault();
149
+ e2.stopPropagation();
146
150
  });
147
- el.addEventListener("click", (e) => {
148
- e.preventDefault();
149
- e.stopPropagation();
151
+ el.addEventListener("click", (e2) => {
152
+ e2.preventDefault();
153
+ e2.stopPropagation();
150
154
  view.dispatch(
151
155
  view.state.tr.setMeta(COMMENT_ACTIVE_META, commentIds[0] ?? null).setMeta(COMMENT_GUTTER_META, {
152
156
  commentIds,
@@ -197,9 +201,9 @@ function commentAnchorPlugin(options = {}) {
197
201
  const activeId = ((_a = commentAnchorPluginKey.getState(state)) == null ? void 0 : _a.activeCommentId) ?? null;
198
202
  if (activeId) {
199
203
  const ranges = byId.get(activeId) ?? [];
200
- for (const r of ranges) {
204
+ for (const r2 of ranges) {
201
205
  decos.push(
202
- Decoration.inline(r.from, r.to, { class: "tmr-comment-active" })
206
+ Decoration.inline(r2.from, r2.to, { class: "tmr-comment-active" })
203
207
  );
204
208
  }
205
209
  for (const b of bounds) {
@@ -258,7 +262,7 @@ function applyCommentAnchorsToEditor(editor, comments) {
258
262
  mapCommentAnchors(
259
263
  editor.state.doc,
260
264
  comments.map((c) => ({ commentId: c.commentId, segments: c.segments }))
261
- ).map((r) => ({ commentId: r.commentId, ranges: r.ranges }))
265
+ ).map((r2) => ({ commentId: r2.commentId, ranges: r2.ranges }))
262
266
  ) : [];
263
267
  const chain = editor.chain().clearCommentAnchors();
264
268
  if (intervals.length > 0) chain.applyCommentAnchors(intervals);
@@ -412,11 +416,11 @@ const ImportPlaceholder = Node$1.create({
412
416
  const MD_FILE_RE$1 = /\.(md|markdown)$/i;
413
417
  const MD_MIME_TYPES = ["text/markdown", "text/x-markdown", ""];
414
418
  async function insertMarkdownFiles(editor, files, pos) {
415
- const mdFiles = files.filter((f) => MD_FILE_RE$1.test(f.name));
419
+ const mdFiles = files.filter((f2) => MD_FILE_RE$1.test(f2.name));
416
420
  if (mdFiles.length === 0) return;
417
421
  const markdown = editor.markdown;
418
422
  if (!markdown) return;
419
- const texts = await Promise.all(mdFiles.map((f) => f.text()));
423
+ const texts = await Promise.all(mdFiles.map((f2) => f2.text()));
420
424
  const json = markdown.parse(texts.join("\n\n"));
421
425
  if (pos != null) {
422
426
  editor.chain().focus().insertContentAt(pos, json).run();
@@ -633,6 +637,13 @@ const RowDeleteIcon = (p) => /* @__PURE__ */ jsxs(Svg, { ...p, children: [
633
637
  /* @__PURE__ */ jsx("path", { d: "m9 8 6 8" }),
634
638
  /* @__PURE__ */ jsx("path", { d: "m15 8-6 8" })
635
639
  ] });
640
+ const TableDeleteIcon = (p) => /* @__PURE__ */ jsxs(Svg, { ...p, children: [
641
+ /* @__PURE__ */ jsx("rect", { x: "3", y: "5", width: "18", height: "14", rx: "1" }),
642
+ /* @__PURE__ */ jsx("path", { d: "M3 9h18" }),
643
+ /* @__PURE__ */ jsx("path", { d: "M9 5v14" }),
644
+ /* @__PURE__ */ jsx("path", { d: "M15 5v14" }),
645
+ /* @__PURE__ */ jsx("path", { d: "m7 2 10 20" })
646
+ ] });
636
647
  const defaultToolbarLabels = {
637
648
  undo: "Undo",
638
649
  redo: "Redo",
@@ -675,12 +686,20 @@ const defaultToolbarLabels = {
675
686
  hr: "Divider",
676
687
  importMarkdown: "Markdown",
677
688
  tableInsert: "Insert table",
689
+ tableSizeSelected: (cols, rows) => `${cols} × ${rows}`,
678
690
  tableAddColumnBefore: "Add column before",
679
691
  tableAddColumnAfter: "Add column after",
680
692
  tableDeleteColumn: "Delete column",
681
693
  tableAddRowBefore: "Add row before",
682
694
  tableAddRowAfter: "Add row after",
683
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",
684
703
  inlineMath: "Inline equation",
685
704
  blockMath: "Block equation",
686
705
  mathPlaceholder: "E = mc^2",
@@ -924,7 +943,7 @@ const MarkdownWysiwygEditor = forwardRef(function MarkdownWysiwygEditor2({
924
943
  getId: makeTocGetId(),
925
944
  onUpdate: (anchors) => {
926
945
  onTocChange == null ? void 0 : onTocChange(
927
- anchors.filter((a) => a.level <= 6).map((a) => ({ id: a.id, level: a.level, text: a.textContent }))
946
+ anchors.filter((a2) => a2.level <= 6).map((a2) => ({ id: a2.id, level: a2.level, text: a2.textContent }))
928
947
  );
929
948
  }
930
949
  }),
@@ -1124,9 +1143,9 @@ function insertPlainParagraph(editor, text) {
1124
1143
  }
1125
1144
  function splitTopLevelBlocks(markdown) {
1126
1145
  const out = [];
1127
- for (const [i2, part] of markdown.split(/(```[\s\S]*?```)/).entries()) {
1146
+ for (const [i, part] of markdown.split(/(```[\s\S]*?```)/).entries()) {
1128
1147
  if (!part) continue;
1129
- if (i2 % 2 === 1) {
1148
+ if (i % 2 === 1) {
1130
1149
  out.push(part);
1131
1150
  continue;
1132
1151
  }
@@ -1139,45 +1158,140 @@ function splitTopLevelBlocks(markdown) {
1139
1158
  function stripToPlainText(markdown) {
1140
1159
  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();
1141
1160
  }
1142
- const toolbar = "_toolbar_16b09_2";
1143
- const inner = "_inner_16b09_15";
1144
- const btn = "_btn_16b09_27";
1145
- const btnActive = "_btnActive_16b09_50";
1146
- const tableBubble = "_tableBubble_16b09_66";
1147
- const txtIcon = "_txtIcon_16b09_78";
1148
- const colorIcon = "_colorIcon_16b09_86";
1149
- const colorIconGlyph = "_colorIconGlyph_16b09_94";
1150
- const colorIconBar = "_colorIconBar_16b09_100";
1151
- const scriptTrigger = "_scriptTrigger_16b09_107";
1152
- const scriptTriggerGlyph = "_scriptTriggerGlyph_16b09_127";
1153
- const divider = "_divider_16b09_135";
1154
- const styleTrigger = "_styleTrigger_16b09_144";
1155
- const styleTriggerLabel = "_styleTriggerLabel_16b09_173";
1156
- const styleTriggerCaret = "_styleTriggerCaret_16b09_181";
1157
- const styleItem = "_styleItem_16b09_187";
1158
- const styleIcon = "_styleIcon_16b09_193";
1159
- const scriptGlyph = "_scriptGlyph_16b09_203";
1160
- const menu = "_menu_16b09_215";
1161
- const menuItem = "_menuItem_16b09_226";
1162
- const menuItemSelected = "_menuItemSelected_16b09_252";
1163
- const popoverContent$1 = "_popoverContent_16b09_266";
1164
- const mathLayer = "_mathLayer_16b09_270";
1165
- const mathStack = "_mathStack_16b09_275";
1166
- const mathStackBlock = "_mathStackBlock_16b09_282";
1167
- const mathHint = "_mathHint_16b09_287";
1168
- const mathHintBlock = "_mathHintBlock_16b09_299";
1169
- const mathHintIcon = "_mathHintIcon_16b09_305";
1170
- const mathField = "_mathField_16b09_336";
1171
- const mathFieldBlock = "_mathFieldBlock_16b09_348";
1172
- const mathInput = "_mathInput_16b09_355";
1173
- const mathDone = "_mathDone_16b09_373";
1174
- const mathDoneKbd = "_mathDoneKbd_16b09_398";
1161
+ function getTableSelectionInfo(state) {
1162
+ if (!isInTable(state)) return null;
1163
+ const rect = selectedRect(state);
1164
+ const rowCount = Math.max(1, rect.bottom - rect.top);
1165
+ const colCount = Math.max(1, rect.right - rect.left);
1166
+ let includesHeaderRow = false;
1167
+ for (let row = rect.top; row < rect.bottom; row++) {
1168
+ if (rowIsHeader(rect.map, rect.table, row)) {
1169
+ includesHeaderRow = true;
1170
+ break;
1171
+ }
1172
+ }
1173
+ return {
1174
+ rowCount,
1175
+ colCount,
1176
+ isMultiCell: rowCount > 1 || colCount > 1,
1177
+ includesHeaderRow,
1178
+ coversAllRows: rect.top === 0 && rect.bottom === rect.map.height,
1179
+ coversAllCols: rect.left === 0 && rect.right === rect.map.width
1180
+ };
1181
+ }
1182
+ function isPosInCellSelection(selection, pos) {
1183
+ let found = false;
1184
+ selection.forEachCell((node, cellPos) => {
1185
+ if (pos >= cellPos && pos <= cellPos + node.nodeSize) {
1186
+ found = true;
1187
+ }
1188
+ });
1189
+ return found;
1190
+ }
1191
+ function preserveTableSelectionOnContextMenu(editor, pos) {
1192
+ const { selection } = editor.state;
1193
+ if (selection instanceof CellSelection && isPosInCellSelection(selection, pos)) {
1194
+ editor.view.focus();
1195
+ return;
1196
+ }
1197
+ editor.chain().focus().setTextSelection(pos).run();
1198
+ }
1199
+ function addRowsBefore(editor, count) {
1200
+ const n = Math.max(1, count);
1201
+ for (let i = 0; i < n; i++) {
1202
+ if (!editor.commands.addRowBefore()) return false;
1203
+ }
1204
+ return true;
1205
+ }
1206
+ function addRowsAfter(editor, count) {
1207
+ const n = Math.max(1, count);
1208
+ for (let i = 0; i < n; i++) {
1209
+ if (!editor.commands.addRowAfter()) return false;
1210
+ }
1211
+ return true;
1212
+ }
1213
+ function addColumnsBefore(editor, count) {
1214
+ const n = Math.max(1, count);
1215
+ for (let i = 0; i < n; i++) {
1216
+ if (!editor.commands.addColumnBefore()) return false;
1217
+ }
1218
+ return true;
1219
+ }
1220
+ function addColumnsAfter(editor, count) {
1221
+ const n = Math.max(1, count);
1222
+ for (let i = 0; i < n; i++) {
1223
+ if (!editor.commands.addColumnAfter()) return false;
1224
+ }
1225
+ return true;
1226
+ }
1227
+ function deleteSelectedRows(editor) {
1228
+ const info = getTableSelectionInfo(editor.state);
1229
+ if (!info) return false;
1230
+ if (info.coversAllRows) return editor.commands.deleteTable();
1231
+ return editor.commands.deleteRow();
1232
+ }
1233
+ function deleteSelectedColumns(editor) {
1234
+ const info = getTableSelectionInfo(editor.state);
1235
+ if (!info) return false;
1236
+ if (info.coversAllCols) {
1237
+ if (info.coversAllRows) return editor.commands.deleteTable();
1238
+ return false;
1239
+ }
1240
+ return editor.commands.deleteColumn();
1241
+ }
1242
+ const toolbar = "_toolbar_1f7fb_2";
1243
+ const inner = "_inner_1f7fb_15";
1244
+ const btn = "_btn_1f7fb_27";
1245
+ const btnActive = "_btnActive_1f7fb_50";
1246
+ const tableBubble = "_tableBubble_1f7fb_66";
1247
+ const tableMenuItem = "_tableMenuItem_1f7fb_77";
1248
+ const tableMenuItemIcon = "_tableMenuItemIcon_1f7fb_103";
1249
+ const tableMenuItemLabel = "_tableMenuItemLabel_1f7fb_113";
1250
+ const tableMenuDivider = "_tableMenuDivider_1f7fb_118";
1251
+ const txtIcon = "_txtIcon_1f7fb_126";
1252
+ const colorIcon = "_colorIcon_1f7fb_134";
1253
+ const colorIconGlyph = "_colorIconGlyph_1f7fb_142";
1254
+ const colorIconBar = "_colorIconBar_1f7fb_148";
1255
+ const scriptTrigger = "_scriptTrigger_1f7fb_155";
1256
+ const scriptTriggerGlyph = "_scriptTriggerGlyph_1f7fb_175";
1257
+ const divider = "_divider_1f7fb_183";
1258
+ const styleTrigger = "_styleTrigger_1f7fb_192";
1259
+ const styleTriggerLabel = "_styleTriggerLabel_1f7fb_221";
1260
+ const styleTriggerCaret = "_styleTriggerCaret_1f7fb_229";
1261
+ const styleItem = "_styleItem_1f7fb_235";
1262
+ const styleIcon = "_styleIcon_1f7fb_241";
1263
+ const scriptGlyph = "_scriptGlyph_1f7fb_251";
1264
+ const menu = "_menu_1f7fb_263";
1265
+ const menuItem = "_menuItem_1f7fb_274";
1266
+ const menuItemSelected = "_menuItemSelected_1f7fb_301";
1267
+ const tableInsertCaret = "_tableInsertCaret_1f7fb_314";
1268
+ const tableSizePicker = "_tableSizePicker_1f7fb_322";
1269
+ const tableSizeGrid = "_tableSizeGrid_1f7fb_332";
1270
+ const tableSizeCell = "_tableSizeCell_1f7fb_337";
1271
+ const tableSizeCellActive = "_tableSizeCellActive_1f7fb_347";
1272
+ const tableSizeLabel = "_tableSizeLabel_1f7fb_352";
1273
+ const popoverContent$1 = "_popoverContent_1f7fb_361";
1274
+ const mathLayer = "_mathLayer_1f7fb_365";
1275
+ const mathStack = "_mathStack_1f7fb_370";
1276
+ const mathStackBlock = "_mathStackBlock_1f7fb_377";
1277
+ const mathHint = "_mathHint_1f7fb_382";
1278
+ const mathHintBlock = "_mathHintBlock_1f7fb_394";
1279
+ const mathHintIcon = "_mathHintIcon_1f7fb_400";
1280
+ const mathField = "_mathField_1f7fb_431";
1281
+ const mathFieldBlock = "_mathFieldBlock_1f7fb_443";
1282
+ const mathInput = "_mathInput_1f7fb_450";
1283
+ const mathDone = "_mathDone_1f7fb_468";
1284
+ const mathDoneKbd = "_mathDoneKbd_1f7fb_493";
1175
1285
  const styles$3 = {
1176
1286
  toolbar,
1177
1287
  inner,
1178
1288
  btn,
1179
1289
  btnActive,
1180
1290
  tableBubble,
1291
+ tableMenuItem,
1292
+ tableMenuItemIcon,
1293
+ tableMenuItemLabel,
1294
+ tableMenuDivider,
1181
1295
  txtIcon,
1182
1296
  colorIcon,
1183
1297
  colorIconGlyph,
@@ -1194,6 +1308,12 @@ const styles$3 = {
1194
1308
  menu,
1195
1309
  menuItem,
1196
1310
  menuItemSelected,
1311
+ tableInsertCaret,
1312
+ tableSizePicker,
1313
+ tableSizeGrid,
1314
+ tableSizeCell,
1315
+ tableSizeCellActive,
1316
+ tableSizeLabel,
1197
1317
  popoverContent: popoverContent$1,
1198
1318
  mathLayer,
1199
1319
  mathStack,
@@ -1245,7 +1365,7 @@ function ColorPalette({ value, onPick, labels }) {
1245
1365
  {
1246
1366
  type: "button",
1247
1367
  className: styles$2.noneRow,
1248
- onMouseDown: (e) => e.preventDefault(),
1368
+ onMouseDown: (e2) => e2.preventDefault(),
1249
1369
  onClick: () => onPick(null),
1250
1370
  children: [
1251
1371
  /* @__PURE__ */ jsx("span", { className: styles$2.noneIcon, "aria-hidden": true }),
@@ -1261,7 +1381,7 @@ function ColorPalette({ value, onPick, labels }) {
1261
1381
  style: { background: c },
1262
1382
  title: c,
1263
1383
  "aria-label": c,
1264
- onMouseDown: (e) => e.preventDefault(),
1384
+ onMouseDown: (e2) => e2.preventDefault(),
1265
1385
  onClick: () => onPick(c)
1266
1386
  },
1267
1387
  c
@@ -1275,7 +1395,7 @@ function ColorPalette({ value, onPick, labels }) {
1275
1395
  style: { background: c },
1276
1396
  title: c,
1277
1397
  "aria-label": c,
1278
- onMouseDown: (e) => e.preventDefault(),
1398
+ onMouseDown: (e2) => e2.preventDefault(),
1279
1399
  onClick: () => onPick(c)
1280
1400
  },
1281
1401
  c
@@ -1302,8 +1422,8 @@ function getMathLayerStyle(editor, kind, pos) {
1302
1422
  if (pos != null) {
1303
1423
  const el = resolveNodeEl(editor, pos);
1304
1424
  if (el) {
1305
- const r = el.getBoundingClientRect();
1306
- const top = r.bottom - hostRect.top + gap;
1425
+ const r2 = el.getBoundingClientRect();
1426
+ const top = r2.bottom - hostRect.top + gap;
1307
1427
  if (kind === "block") {
1308
1428
  return {
1309
1429
  left: editorRect.left - hostRect.left,
@@ -1312,7 +1432,7 @@ function getMathLayerStyle(editor, kind, pos) {
1312
1432
  };
1313
1433
  }
1314
1434
  return {
1315
- left: r.left - hostRect.left,
1435
+ left: r2.left - hostRect.left,
1316
1436
  top
1317
1437
  };
1318
1438
  }
@@ -1395,9 +1515,9 @@ function MathEditorPopover({
1395
1515
  };
1396
1516
  }, [pos, editor, isBlock, latex, isNew]);
1397
1517
  useEffect(() => {
1398
- const onPtr = (e) => {
1518
+ const onPtr = (e2) => {
1399
1519
  var _a;
1400
- const target = e.target;
1520
+ const target = e2.target;
1401
1521
  if (!(target instanceof Node)) return;
1402
1522
  if ((_a = rootRef.current) == null ? void 0 : _a.contains(target)) return;
1403
1523
  if (pos != null) {
@@ -1415,15 +1535,15 @@ function MathEditorPopover({
1415
1535
  if (!canSubmit) return;
1416
1536
  onConfirm(draft.trim());
1417
1537
  };
1418
- const onKeyDown = (e) => {
1419
- if (e.key === "Escape") {
1420
- e.preventDefault();
1538
+ const onKeyDown = (e2) => {
1539
+ if (e2.key === "Escape") {
1540
+ e2.preventDefault();
1421
1541
  onCancel();
1422
1542
  return;
1423
1543
  }
1424
- if (e.key !== "Enter") return;
1425
- if (isBlock && !(e.metaKey || e.ctrlKey)) return;
1426
- e.preventDefault();
1544
+ if (e2.key !== "Enter") return;
1545
+ if (isBlock && !(e2.metaKey || e2.ctrlKey)) return;
1546
+ e2.preventDefault();
1427
1547
  submit();
1428
1548
  };
1429
1549
  const field = isBlock ? /* @__PURE__ */ jsx(
@@ -1435,7 +1555,7 @@ function MathEditorPopover({
1435
1555
  placeholder,
1436
1556
  rows: Math.max(3, draft.split("\n").length),
1437
1557
  "aria-labelledby": titleId,
1438
- onChange: (e) => setDraft(e.target.value),
1558
+ onChange: (e2) => setDraft(e2.target.value),
1439
1559
  onKeyDown
1440
1560
  }
1441
1561
  ) : /* @__PURE__ */ jsx(
@@ -1446,7 +1566,7 @@ function MathEditorPopover({
1446
1566
  value: draft,
1447
1567
  placeholder,
1448
1568
  "aria-labelledby": titleId,
1449
- onChange: (e) => setDraft(e.target.value),
1569
+ onChange: (e2) => setDraft(e2.target.value),
1450
1570
  onKeyDown
1451
1571
  }
1452
1572
  );
@@ -1527,7 +1647,7 @@ function ToolbarButton({
1527
1647
  "aria-busy": busy,
1528
1648
  disabled,
1529
1649
  className: `${styles$3.btn} ${active2 ? styles$3.btnActive : ""}`,
1530
- onMouseDown: (e) => e.preventDefault(),
1650
+ onMouseDown: (e2) => e2.preventDefault(),
1531
1651
  onClick,
1532
1652
  children
1533
1653
  }
@@ -1536,6 +1656,30 @@ function ToolbarButton({
1536
1656
  function Divider() {
1537
1657
  return /* @__PURE__ */ jsx("span", { className: styles$3.divider, "aria-hidden": true });
1538
1658
  }
1659
+ function TableMenuItem({
1660
+ label,
1661
+ disabled,
1662
+ onClick,
1663
+ children
1664
+ }) {
1665
+ return /* @__PURE__ */ jsxs(
1666
+ "button",
1667
+ {
1668
+ type: "button",
1669
+ disabled,
1670
+ className: styles$3.tableMenuItem,
1671
+ onMouseDown: (e2) => e2.preventDefault(),
1672
+ onClick,
1673
+ children: [
1674
+ /* @__PURE__ */ jsx("span", { className: styles$3.tableMenuItemIcon, "aria-hidden": true, children }),
1675
+ /* @__PURE__ */ jsx("span", { className: styles$3.tableMenuItemLabel, children: label })
1676
+ ]
1677
+ }
1678
+ );
1679
+ }
1680
+ function TableMenuDivider() {
1681
+ return /* @__PURE__ */ jsx("div", { className: styles$3.tableMenuDivider, "aria-hidden": true });
1682
+ }
1539
1683
  const MenuCloseCtx = createContext(() => {
1540
1684
  });
1541
1685
  function MenuPopover({
@@ -1552,8 +1696,8 @@ function MenuPopover({
1552
1696
  className: styles$3.menu,
1553
1697
  sideOffset: 4,
1554
1698
  align: "start",
1555
- onOpenAutoFocus: (e) => e.preventDefault(),
1556
- onCloseAutoFocus: (e) => e.preventDefault(),
1699
+ onOpenAutoFocus: (e2) => e2.preventDefault(),
1700
+ onCloseAutoFocus: (e2) => e2.preventDefault(),
1557
1701
  children: /* @__PURE__ */ jsx(MenuCloseCtx.Provider, { value: close, children })
1558
1702
  }
1559
1703
  ) })
@@ -1572,7 +1716,7 @@ function MenuItem({
1572
1716
  type: "button",
1573
1717
  disabled,
1574
1718
  className: `${styles$3.menuItem} ${selected ? styles$3.menuItemSelected : ""}`,
1575
- onMouseDown: (e) => e.preventDefault(),
1719
+ onMouseDown: (e2) => e2.preventDefault(),
1576
1720
  onClick: () => {
1577
1721
  onSelect();
1578
1722
  close();
@@ -1581,6 +1725,92 @@ function MenuItem({
1581
1725
  }
1582
1726
  );
1583
1727
  }
1728
+ const TABLE_PICKER_COLS = 10;
1729
+ const TABLE_PICKER_ROWS = 8;
1730
+ function TableInsertItem({
1731
+ disabled,
1732
+ labels,
1733
+ onInsert
1734
+ }) {
1735
+ const closeMenu = useContext(MenuCloseCtx);
1736
+ const [open, setOpen] = useState(false);
1737
+ const [hover, setHover] = useState({ cols: 0, rows: 0 });
1738
+ const resetHover = useCallback(() => setHover({ cols: 0, rows: 0 }), []);
1739
+ return /* @__PURE__ */ jsxs(
1740
+ Popover.Root,
1741
+ {
1742
+ open,
1743
+ onOpenChange: (next) => {
1744
+ setOpen(next);
1745
+ if (!next) resetHover();
1746
+ },
1747
+ children: [
1748
+ /* @__PURE__ */ jsx(Popover.Trigger, { asChild: true, children: /* @__PURE__ */ jsxs(
1749
+ "button",
1750
+ {
1751
+ type: "button",
1752
+ disabled,
1753
+ className: `${styles$3.menuItem} ${open ? styles$3.menuItemSelected : ""}`,
1754
+ onMouseDown: (e2) => e2.preventDefault(),
1755
+ children: [
1756
+ /* @__PURE__ */ jsxs("span", { className: styles$3.styleItem, children: [
1757
+ /* @__PURE__ */ jsx("span", { className: styles$3.styleIcon, children: "⊞" }),
1758
+ labels.tableInsert
1759
+ ] }),
1760
+ /* @__PURE__ */ jsx(ChevronDownIcon, { size: 12, className: styles$3.tableInsertCaret })
1761
+ ]
1762
+ }
1763
+ ) }),
1764
+ /* @__PURE__ */ jsx(Popover.Portal, { children: /* @__PURE__ */ jsxs(
1765
+ Popover.Content,
1766
+ {
1767
+ className: styles$3.tableSizePicker,
1768
+ side: "right",
1769
+ align: "start",
1770
+ sideOffset: 6,
1771
+ onOpenAutoFocus: (e2) => e2.preventDefault(),
1772
+ onCloseAutoFocus: (e2) => e2.preventDefault(),
1773
+ children: [
1774
+ /* @__PURE__ */ jsx(
1775
+ "div",
1776
+ {
1777
+ className: styles$3.tableSizeGrid,
1778
+ style: {
1779
+ gridTemplateColumns: `repeat(${TABLE_PICKER_COLS}, 1fr)`
1780
+ },
1781
+ onMouseLeave: resetHover,
1782
+ children: Array.from({ length: TABLE_PICKER_ROWS * TABLE_PICKER_COLS }, (_, i) => {
1783
+ const col = i % TABLE_PICKER_COLS + 1;
1784
+ const row = Math.floor(i / TABLE_PICKER_COLS) + 1;
1785
+ const active2 = hover.cols > 0 && col <= hover.cols && row <= hover.rows;
1786
+ return /* @__PURE__ */ jsx(
1787
+ "button",
1788
+ {
1789
+ type: "button",
1790
+ "aria-label": labels.tableSizeSelected(col, row),
1791
+ className: `${styles$3.tableSizeCell} ${active2 ? styles$3.tableSizeCellActive : ""}`,
1792
+ onMouseDown: (e2) => e2.preventDefault(),
1793
+ onMouseEnter: () => setHover({ cols: col, rows: row }),
1794
+ onClick: () => {
1795
+ onInsert(row, col);
1796
+ setOpen(false);
1797
+ resetHover();
1798
+ closeMenu();
1799
+ }
1800
+ },
1801
+ i
1802
+ );
1803
+ })
1804
+ }
1805
+ ),
1806
+ /* @__PURE__ */ jsx("div", { className: styles$3.tableSizeLabel, children: hover.cols > 0 ? labels.tableSizeSelected(hover.cols, hover.rows) : labels.tableInsert })
1807
+ ]
1808
+ }
1809
+ ) })
1810
+ ]
1811
+ }
1812
+ );
1813
+ }
1584
1814
  function ColorPopover({
1585
1815
  title,
1586
1816
  glyph,
@@ -1598,7 +1828,7 @@ function ColorPopover({
1598
1828
  className: styles$3.btn,
1599
1829
  title,
1600
1830
  "aria-label": title,
1601
- onMouseDown: (e) => e.preventDefault(),
1831
+ onMouseDown: (e2) => e2.preventDefault(),
1602
1832
  children: /* @__PURE__ */ jsxs("span", { className: styles$3.colorIcon, children: [
1603
1833
  /* @__PURE__ */ jsx("span", { className: styles$3.colorIconGlyph, children: glyph }),
1604
1834
  /* @__PURE__ */ jsx("span", { className: styles$3.colorIconBar, style: { background: bar } })
@@ -1611,8 +1841,8 @@ function ColorPopover({
1611
1841
  className: styles$3.popoverContent,
1612
1842
  sideOffset: 4,
1613
1843
  align: "start",
1614
- onOpenAutoFocus: (e) => e.preventDefault(),
1615
- onCloseAutoFocus: (e) => e.preventDefault(),
1844
+ onOpenAutoFocus: (e2) => e2.preventDefault(),
1845
+ onCloseAutoFocus: (e2) => e2.preventDefault(),
1616
1846
  children: /* @__PURE__ */ jsx(
1617
1847
  ColorPalette,
1618
1848
  {
@@ -1645,30 +1875,29 @@ function EditorToolbar({
1645
1875
  const t = { ...defaultToolbarLabels, ...labels };
1646
1876
  const state = useEditorState({
1647
1877
  editor,
1648
- selector: ({ editor: e }) => ({
1649
- bold: e.isActive("bold"),
1650
- italic: e.isActive("italic"),
1651
- underline: e.isActive("underline"),
1652
- strike: e.isActive("strike"),
1653
- code: e.isActive("code"),
1654
- link: e.isActive("link"),
1655
- taskList: e.isActive("taskList"),
1878
+ selector: ({ editor: e2 }) => ({
1879
+ bold: e2.isActive("bold"),
1880
+ italic: e2.isActive("italic"),
1881
+ underline: e2.isActive("underline"),
1882
+ strike: e2.isActive("strike"),
1883
+ code: e2.isActive("code"),
1884
+ link: e2.isActive("link"),
1885
+ taskList: e2.isActive("taskList"),
1656
1886
  headingLevel: [1, 2, 3, 4, 5, 6].find(
1657
- (lv) => e.isActive("heading", { level: lv })
1887
+ (lv) => e2.isActive("heading", { level: lv })
1658
1888
  ),
1659
- fontSize: e.getAttributes("textStyle").fontSize || void 0,
1660
- isParagraph: e.isActive("paragraph"),
1661
- bulletList: e.isActive("bulletList"),
1662
- orderedList: e.isActive("orderedList"),
1663
- blockquote: e.isActive("blockquote"),
1664
- textColor: e.getAttributes("textStyle").color || void 0,
1665
- highlightColor: e.getAttributes("highlight").color || void 0,
1666
- superscript: e.isActive("superscript"),
1667
- subscript: e.isActive("subscript"),
1668
- inTable: e.isActive("table"),
1669
- inTableHeader: e.isActive("tableHeader"),
1670
- canUndo: e.can().undo(),
1671
- canRedo: e.can().redo()
1889
+ fontSize: e2.getAttributes("textStyle").fontSize || void 0,
1890
+ isParagraph: e2.isActive("paragraph"),
1891
+ bulletList: e2.isActive("bulletList"),
1892
+ orderedList: e2.isActive("orderedList"),
1893
+ blockquote: e2.isActive("blockquote"),
1894
+ textColor: e2.getAttributes("textStyle").color || void 0,
1895
+ highlightColor: e2.getAttributes("highlight").color || void 0,
1896
+ superscript: e2.isActive("superscript"),
1897
+ subscript: e2.isActive("subscript"),
1898
+ inTable: e2.isActive("table"),
1899
+ canUndo: e2.can().undo(),
1900
+ canRedo: e2.can().redo()
1672
1901
  })
1673
1902
  });
1674
1903
  const [editorFocused, setEditorFocused] = useState(() => editor.isFocused);
@@ -1690,32 +1919,32 @@ function EditorToolbar({
1690
1919
  const closeTableMenu = useCallback(() => setTableMenu(null), []);
1691
1920
  useEffect(() => {
1692
1921
  const dom = editor.view.dom;
1693
- const onContextMenu = (e) => {
1922
+ const onContextMenu = (e2) => {
1694
1923
  const coords = editor.view.posAtCoords({
1695
- left: e.clientX,
1696
- top: e.clientY
1924
+ left: e2.clientX,
1925
+ top: e2.clientY
1697
1926
  });
1698
1927
  if (!coords) return;
1699
1928
  const $pos = editor.state.doc.resolve(coords.pos);
1700
1929
  let inTable = false;
1701
- for (let d = $pos.depth; d > 0; d--) {
1702
- if ($pos.node(d).type.name === "table") {
1930
+ for (let d2 = $pos.depth; d2 > 0; d2--) {
1931
+ if ($pos.node(d2).type.name === "table") {
1703
1932
  inTable = true;
1704
1933
  break;
1705
1934
  }
1706
1935
  }
1707
1936
  if (!inTable) return;
1708
- e.preventDefault();
1709
- editor.chain().focus().setTextSelection(coords.pos).run();
1710
- setTableMenu({ x: e.clientX, y: e.clientY });
1937
+ e2.preventDefault();
1938
+ preserveTableSelectionOnContextMenu(editor, coords.pos);
1939
+ setTableMenu({ x: e2.clientX, y: e2.clientY });
1711
1940
  };
1712
1941
  dom.addEventListener("contextmenu", onContextMenu);
1713
1942
  return () => dom.removeEventListener("contextmenu", onContextMenu);
1714
1943
  }, [editor]);
1715
1944
  useEffect(() => {
1716
1945
  if (!tableMenu) return;
1717
- const onKey = (e) => {
1718
- if (e.key === "Escape") closeTableMenu();
1946
+ const onKey = (e2) => {
1947
+ if (e2.key === "Escape") closeTableMenu();
1719
1948
  };
1720
1949
  document.addEventListener("mousedown", closeTableMenu);
1721
1950
  document.addEventListener("keydown", onKey, true);
@@ -1731,14 +1960,21 @@ function EditorToolbar({
1731
1960
  },
1732
1961
  [closeTableMenu]
1733
1962
  );
1963
+ const tableSel = tableMenu ? getTableSelectionInfo(editor.state) : null;
1964
+ const tableRowN = (tableSel == null ? void 0 : tableSel.rowCount) ?? 1;
1965
+ const tableColN = (tableSel == null ? void 0 : tableSel.colCount) ?? 1;
1966
+ const tableMulti = (tableSel == null ? void 0 : tableSel.isMultiCell) ?? false;
1967
+ const disableAddRowBefore = !!(tableSel == null ? void 0 : tableSel.includesHeaderRow);
1968
+ const disableDeleteRow = !!(tableSel == null ? void 0 : tableSel.includesHeaderRow);
1969
+ const disableDeleteColumn = !!(tableSel == null ? void 0 : tableSel.coversAllCols) && !(tableSel == null ? void 0 : tableSel.coversAllRows);
1734
1970
  const handlePickImage = () => {
1735
1971
  var _a;
1736
1972
  return (_a = fileInputRef.current) == null ? void 0 : _a.click();
1737
1973
  };
1738
- const handleImageChange = async (e) => {
1974
+ const handleImageChange = async (e2) => {
1739
1975
  var _a;
1740
- const file = (_a = e.target.files) == null ? void 0 : _a[0];
1741
- e.target.value = "";
1976
+ const file = (_a = e2.target.files) == null ? void 0 : _a[0];
1977
+ e2.target.value = "";
1742
1978
  if (!file || !onImageUpload) return;
1743
1979
  try {
1744
1980
  const url = await onImageUpload(file);
@@ -1758,10 +1994,10 @@ function EditorToolbar({
1758
1994
  var _a;
1759
1995
  return (_a = importAbortRef.current) == null ? void 0 : _a.abort();
1760
1996
  }, []);
1761
- const handleImportChange = async (e) => {
1997
+ const handleImportChange = async (e2) => {
1762
1998
  var _a;
1763
- const file = (_a = e.target.files) == null ? void 0 : _a[0];
1764
- e.target.value = "";
1999
+ const file = (_a = e2.target.files) == null ? void 0 : _a[0];
2000
+ e2.target.value = "";
1765
2001
  if (!file) return;
1766
2002
  if (MD_FILE_RE.test(file.name)) {
1767
2003
  try {
@@ -1948,7 +2184,7 @@ function EditorToolbar({
1948
2184
  type: "button",
1949
2185
  className: styles$3.styleTrigger,
1950
2186
  title: t.style,
1951
- onMouseDown: (e) => e.preventDefault(),
2187
+ onMouseDown: (e2) => e2.preventDefault(),
1952
2188
  children: [
1953
2189
  /* @__PURE__ */ jsx("span", { className: styles$3.styleTriggerLabel, children: t.style }),
1954
2190
  /* @__PURE__ */ jsx(ChevronDownIcon, { size: 12, className: styles$3.styleTriggerCaret })
@@ -1993,7 +2229,7 @@ function EditorToolbar({
1993
2229
  title: t.fontSize,
1994
2230
  "aria-label": t.fontSize,
1995
2231
  disabled: !canEditFontSize,
1996
- onMouseDown: (e) => e.preventDefault(),
2232
+ onMouseDown: (e2) => e2.preventDefault(),
1997
2233
  children: [
1998
2234
  /* @__PURE__ */ jsx("span", { className: styles$3.styleTriggerLabel, children: state.fontSize || t.fontSize }),
1999
2235
  /* @__PURE__ */ jsx(ChevronDownIcon, { size: 12, className: styles$3.styleTriggerCaret })
@@ -2105,7 +2341,7 @@ function EditorToolbar({
2105
2341
  className: `${styles$3.scriptTrigger} ${scriptActive !== "normal" ? styles$3.btnActive : ""}`,
2106
2342
  title: t.scriptMenu,
2107
2343
  "aria-label": t.scriptMenu,
2108
- onMouseDown: (e) => e.preventDefault(),
2344
+ onMouseDown: (e2) => e2.preventDefault(),
2109
2345
  children: [
2110
2346
  /* @__PURE__ */ jsx("span", { className: styles$3.scriptTriggerGlyph, children: "A" }),
2111
2347
  /* @__PURE__ */ jsx(ChevronDownIcon, { size: 12, className: styles$3.styleTriggerCaret })
@@ -2182,7 +2418,7 @@ function EditorToolbar({
2182
2418
  "aria-label": importTitle,
2183
2419
  "aria-busy": !!importing,
2184
2420
  disabled: !!importing,
2185
- onMouseDown: (e) => e.preventDefault(),
2421
+ onMouseDown: (e2) => e2.preventDefault(),
2186
2422
  children: [
2187
2423
  /* @__PURE__ */ jsx("span", { className: styles$3.styleTriggerLabel, children: t.importDocument }),
2188
2424
  /* @__PURE__ */ jsx(
@@ -2252,7 +2488,7 @@ function EditorToolbar({
2252
2488
  type: "button",
2253
2489
  className: styles$3.styleTrigger,
2254
2490
  title: t.more,
2255
- onMouseDown: (e) => e.preventDefault(),
2491
+ onMouseDown: (e2) => e2.preventDefault(),
2256
2492
  children: [
2257
2493
  /* @__PURE__ */ jsx("span", { className: styles$3.styleTriggerLabel, children: t.more }),
2258
2494
  /* @__PURE__ */ jsx(ChevronDownIcon, { size: 12, className: styles$3.styleTriggerCaret })
@@ -2277,14 +2513,11 @@ function EditorToolbar({
2277
2513
  t.hr
2278
2514
  ] }) }),
2279
2515
  /* @__PURE__ */ jsx(
2280
- MenuItem,
2516
+ TableInsertItem,
2281
2517
  {
2282
2518
  disabled: state.inTable,
2283
- onSelect: () => chain().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run(),
2284
- children: /* @__PURE__ */ jsxs("span", { className: styles$3.styleItem, children: [
2285
- /* @__PURE__ */ jsx("span", { className: styles$3.styleIcon, children: "⊞" }),
2286
- t.tableInsert
2287
- ] })
2519
+ labels: t,
2520
+ onInsert: (rows, cols) => chain().insertTable({ rows, cols, withHeaderRow: true }).run()
2288
2521
  }
2289
2522
  ),
2290
2523
  extraToolbarItems == null ? void 0 : extraToolbarItems.map((item2) => /* @__PURE__ */ jsx(
@@ -2336,59 +2569,76 @@ function EditorToolbar({
2336
2569
  {
2337
2570
  className: styles$3.tableBubble,
2338
2571
  style: { position: "fixed", left: tableMenu.x, top: tableMenu.y },
2339
- onMouseDown: (e) => e.stopPropagation(),
2340
- onContextMenu: (e) => e.preventDefault(),
2572
+ role: "menu",
2573
+ onMouseDown: (e2) => e2.stopPropagation(),
2574
+ onContextMenu: (e2) => e2.preventDefault(),
2341
2575
  children: [
2342
2576
  /* @__PURE__ */ jsx(
2343
- ToolbarButton,
2577
+ TableMenuItem,
2344
2578
  {
2345
- title: t.tableAddColumnBefore,
2346
- onClick: () => runTable(() => chain().addColumnBefore().run()),
2579
+ label: tableMulti ? t.tableAddColumnBeforeN(tableColN) : t.tableAddColumnBefore,
2580
+ onClick: () => runTable(() => addColumnsBefore(editor, tableColN)),
2347
2581
  children: /* @__PURE__ */ jsx(ColumnBeforeIcon, {})
2348
2582
  }
2349
2583
  ),
2350
2584
  /* @__PURE__ */ jsx(
2351
- ToolbarButton,
2585
+ TableMenuItem,
2352
2586
  {
2353
- title: t.tableAddColumnAfter,
2354
- onClick: () => runTable(() => chain().addColumnAfter().run()),
2587
+ label: tableMulti ? t.tableAddColumnAfterN(tableColN) : t.tableAddColumnAfter,
2588
+ onClick: () => runTable(() => addColumnsAfter(editor, tableColN)),
2355
2589
  children: /* @__PURE__ */ jsx(ColumnAfterIcon, {})
2356
2590
  }
2357
2591
  ),
2358
2592
  /* @__PURE__ */ jsx(
2359
- ToolbarButton,
2593
+ TableMenuItem,
2360
2594
  {
2361
- title: t.tableDeleteColumn,
2362
- onClick: () => runTable(() => chain().deleteColumn().run()),
2595
+ label: tableMulti ? t.tableDeleteColumnN(tableColN) : t.tableDeleteColumn,
2596
+ disabled: disableDeleteColumn,
2597
+ onClick: () => runTable(() => {
2598
+ deleteSelectedColumns(editor);
2599
+ }),
2363
2600
  children: /* @__PURE__ */ jsx(ColumnDeleteIcon, {})
2364
2601
  }
2365
2602
  ),
2366
- /* @__PURE__ */ jsx(Divider, {}),
2603
+ /* @__PURE__ */ jsx(TableMenuDivider, {}),
2367
2604
  /* @__PURE__ */ jsx(
2368
- ToolbarButton,
2605
+ TableMenuItem,
2369
2606
  {
2370
- title: t.tableAddRowBefore,
2371
- disabled: state.inTableHeader,
2372
- onClick: () => runTable(() => chain().addRowBefore().run()),
2607
+ label: tableMulti ? t.tableAddRowBeforeN(tableRowN) : t.tableAddRowBefore,
2608
+ disabled: disableAddRowBefore,
2609
+ onClick: () => runTable(() => addRowsBefore(editor, tableRowN)),
2373
2610
  children: /* @__PURE__ */ jsx(RowBeforeIcon, {})
2374
2611
  }
2375
2612
  ),
2376
2613
  /* @__PURE__ */ jsx(
2377
- ToolbarButton,
2614
+ TableMenuItem,
2378
2615
  {
2379
- title: t.tableAddRowAfter,
2380
- onClick: () => runTable(() => chain().addRowAfter().run()),
2616
+ label: tableMulti ? t.tableAddRowAfterN(tableRowN) : t.tableAddRowAfter,
2617
+ onClick: () => runTable(() => addRowsAfter(editor, tableRowN)),
2381
2618
  children: /* @__PURE__ */ jsx(RowAfterIcon, {})
2382
2619
  }
2383
2620
  ),
2384
2621
  /* @__PURE__ */ jsx(
2385
- ToolbarButton,
2622
+ TableMenuItem,
2386
2623
  {
2387
- title: t.tableDeleteRow,
2388
- disabled: state.inTableHeader,
2389
- onClick: () => runTable(() => chain().deleteRow().run()),
2624
+ label: tableMulti ? t.tableDeleteRowN(tableRowN) : t.tableDeleteRow,
2625
+ disabled: disableDeleteRow,
2626
+ onClick: () => runTable(() => {
2627
+ deleteSelectedRows(editor);
2628
+ }),
2390
2629
  children: /* @__PURE__ */ jsx(RowDeleteIcon, {})
2391
2630
  }
2631
+ ),
2632
+ /* @__PURE__ */ jsx(TableMenuDivider, {}),
2633
+ /* @__PURE__ */ jsx(
2634
+ TableMenuItem,
2635
+ {
2636
+ label: t.tableDeleteTable,
2637
+ onClick: () => runTable(() => {
2638
+ editor.commands.deleteTable();
2639
+ }),
2640
+ children: /* @__PURE__ */ jsx(TableDeleteIcon, {})
2641
+ }
2392
2642
  )
2393
2643
  ]
2394
2644
  }
@@ -2468,7 +2718,7 @@ function TocPanel({ items, activeId, onItemClick, labels }) {
2468
2718
  });
2469
2719
  }, [activeId]);
2470
2720
  if (!items.length) return null;
2471
- const minLevel = Math.min(...items.map((i2) => i2.level));
2721
+ const minLevel = Math.min(...items.map((i) => i.level));
2472
2722
  const handleClick = (item2) => {
2473
2723
  if (item2.locked) return;
2474
2724
  onItemClick == null ? void 0 : onItemClick(item2);
@@ -2482,8 +2732,8 @@ function TocPanel({ items, activeId, onItemClick, labels }) {
2482
2732
  style: { paddingLeft: `${(item2.level - minLevel) * 12 + 12}px` },
2483
2733
  "aria-current": item2.id === activeId ? "true" : void 0,
2484
2734
  "aria-disabled": item2.locked ? "true" : void 0,
2485
- onClick: (e) => {
2486
- e.preventDefault();
2735
+ onClick: (e2) => {
2736
+ e2.preventDefault();
2487
2737
  handleClick(item2);
2488
2738
  },
2489
2739
  children: [
@@ -2556,120 +2806,6 @@ function TocPanel({ items, activeId, onItemClick, labels }) {
2556
2806
  list2
2557
2807
  ] });
2558
2808
  }
2559
- function findCitationRefElement(target, root) {
2560
- let node = null;
2561
- if (target instanceof Element) node = target;
2562
- else if (target instanceof Text) node = target.parentElement;
2563
- else if (target instanceof Node) node = target.parentElement;
2564
- if (!(node instanceof Element)) return null;
2565
- const el = node.closest(".citation-ref");
2566
- if (!(el instanceof HTMLElement)) return null;
2567
- if (!root.contains(el)) return null;
2568
- return el;
2569
- }
2570
- function readCitationAttrs(el) {
2571
- var _a;
2572
- return {
2573
- index: el.getAttribute("data-index") || ((_a = el.textContent) == null ? void 0 : _a.trim()) || "",
2574
- url: el.getAttribute("data-url"),
2575
- title: el.getAttribute("data-title")
2576
- };
2577
- }
2578
- function CitationInteractive({
2579
- containerRef,
2580
- onCitationEnter,
2581
- onCitationLeave
2582
- }) {
2583
- const enterRef = useRef(onCitationEnter);
2584
- const leaveRef = useRef(onCitationLeave);
2585
- enterRef.current = onCitationEnter;
2586
- leaveRef.current = onCitationLeave;
2587
- useEffect(() => {
2588
- const root = containerRef.current;
2589
- if (!root) return;
2590
- let currentEl = null;
2591
- const emitEnter = (el) => {
2592
- currentEl = el;
2593
- const attrs = readCitationAttrs(el);
2594
- enterRef.current({ index: attrs.index, attrs, anchorEl: el });
2595
- };
2596
- const emitLeave = () => {
2597
- if (!currentEl) return;
2598
- currentEl = null;
2599
- leaveRef.current();
2600
- };
2601
- const ACTIVE_ATTR = "data-tmr-citation-active";
2602
- const onClick = (e) => {
2603
- const el = findCitationRefElement(e.target, root);
2604
- if (el) {
2605
- e.preventDefault();
2606
- e.stopPropagation();
2607
- if (el === currentEl && el.hasAttribute(ACTIVE_ATTR)) {
2608
- emitLeave();
2609
- return;
2610
- }
2611
- emitEnter(el);
2612
- return;
2613
- }
2614
- emitLeave();
2615
- };
2616
- const onKeyDown = (e) => {
2617
- if (e.key === "Escape") emitLeave();
2618
- };
2619
- root.addEventListener("click", onClick, true);
2620
- document.addEventListener("keydown", onKeyDown);
2621
- return () => {
2622
- root.removeEventListener("click", onClick, true);
2623
- document.removeEventListener("keydown", onKeyDown);
2624
- };
2625
- }, [containerRef]);
2626
- return null;
2627
- }
2628
- function ReportContentInteractive({
2629
- onCitationEnter,
2630
- onCitationLeave,
2631
- className,
2632
- html,
2633
- ...rest
2634
- }) {
2635
- const ref = useRef(null);
2636
- return /* @__PURE__ */ jsxs("div", { ref, className, children: [
2637
- /* @__PURE__ */ jsx(ReportContent, { html, ...rest }),
2638
- /* @__PURE__ */ jsx(
2639
- CitationInteractive,
2640
- {
2641
- containerRef: ref,
2642
- onCitationEnter,
2643
- onCitationLeave
2644
- }
2645
- )
2646
- ] });
2647
- }
2648
- function easeOutCubic(t) {
2649
- return 1 - (1 - t) * (1 - t) * (1 - t);
2650
- }
2651
- function scrollToTocHeading(headingId, scrollContainer, options) {
2652
- const el = scrollContainer.querySelector(
2653
- `[data-toc-id="${CSS.escape(headingId)}"]`
2654
- );
2655
- if (!el) return;
2656
- const startTop = scrollContainer.scrollTop;
2657
- const rootRect = scrollContainer.getBoundingClientRect();
2658
- const elRect = el.getBoundingClientRect();
2659
- const targetTop = startTop + (elRect.top - rootRect.top);
2660
- if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
2661
- scrollContainer.scrollTop = targetTop;
2662
- return;
2663
- }
2664
- const duration = (options == null ? void 0 : options.duration) ?? 400;
2665
- const start = performance.now();
2666
- const animate = () => {
2667
- const t = Math.min((performance.now() - start) / duration, 1);
2668
- scrollContainer.scrollTop = startTop + (targetTop - startTop) * easeOutCubic(t);
2669
- if (t < 1) requestAnimationFrame(animate);
2670
- };
2671
- requestAnimationFrame(animate);
2672
- }
2673
2809
  const popoverAnchor = "_popoverAnchor_9y5t0_55";
2674
2810
  const popoverContent = "_popoverContent_9y5t0_62";
2675
2811
  const styles = {
@@ -2701,8 +2837,8 @@ function CommentPopover({
2701
2837
  side,
2702
2838
  align,
2703
2839
  sideOffset,
2704
- onOpenAutoFocus: (e) => e.preventDefault(),
2705
- onCloseAutoFocus: (e) => e.preventDefault(),
2840
+ onOpenAutoFocus: (e2) => e2.preventDefault(),
2841
+ onCloseAutoFocus: (e2) => e2.preventDefault(),
2706
2842
  children
2707
2843
  }
2708
2844
  ) })
@@ -2715,7 +2851,7 @@ export {
2715
2851
  COMMENT_GUTTER_META,
2716
2852
  CheckIcon,
2717
2853
  ChevronDownIcon,
2718
- CitationInteractive,
2854
+ C as CitationInteractive,
2719
2855
  CitationRef,
2720
2856
  CodeBlockView,
2721
2857
  CodeIcon,
@@ -2741,20 +2877,21 @@ export {
2741
2877
  MarkdownWysiwygEditor,
2742
2878
  MenuIcon,
2743
2879
  RedoIcon,
2744
- ReportContent,
2745
- ReportContentInteractive,
2880
+ R as ReportContent,
2881
+ R2 as ReportContentInteractive,
2746
2882
  RowAfterIcon,
2747
2883
  RowBeforeIcon,
2748
2884
  RowDeleteIcon,
2749
2885
  StrikethroughIcon,
2886
+ TableDeleteIcon,
2750
2887
  TocPanel,
2751
2888
  TrashIcon,
2752
2889
  UnderlineIcon,
2753
2890
  UndoIcon,
2754
- h as applyCitationSources,
2891
+ a as applyCitationSources,
2755
2892
  applyCommentAnchorsToEditor,
2756
2893
  baseExtensions,
2757
- i as blockTextHash,
2894
+ d as blockTextHash,
2758
2895
  collectCommentIds,
2759
2896
  commentAnchorExtension,
2760
2897
  commentAnchorPlugin,
@@ -2767,8 +2904,8 @@ export {
2767
2904
  defaultTocLabels,
2768
2905
  defaultToolbarLabels,
2769
2906
  enrichMarkdownCitations,
2770
- j as extractToc,
2771
- findCitationRefElement,
2907
+ e as extractToc,
2908
+ f as findCitationRefElement,
2772
2909
  focusComment,
2773
2910
  insertMarkdown,
2774
2911
  looksLikeMarkdown,
@@ -2779,9 +2916,9 @@ export {
2779
2916
  nextComment,
2780
2917
  pureCodeBlock,
2781
2918
  pureImage,
2782
- readCitationAttrs,
2783
- scrollToTocHeading,
2784
- k as stabilizeMarkdown,
2919
+ r as readCitationAttrs,
2920
+ s2 as scrollToTocHeading,
2921
+ s as stabilizeMarkdown,
2785
2922
  stripCommentAnchorMarks,
2786
2923
  useIsMobile
2787
2924
  };