tiptap-markdown-react 0.8.11 → 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/icons/index.d.ts +2 -1
- package/dist/index.js +310 -62
- package/dist/index.js.map +1 -1
- package/dist/labels.d.ts +15 -0
- package/dist/style.css +152 -57
- package/dist/tableSelection.d.ts +29 -0
- package/dist/tableSelection.test.d.ts +1 -0
- package/package.json +1 -1
package/dist/icons/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { SVGProps } from 'react';
|
|
|
5
5
|
*
|
|
6
6
|
* 通用图标(粗体/斜体/下划线/列表/撤销等,本文件前 17 个)的 path 取自 Lucide,
|
|
7
7
|
* 其许可证为 ISC,其中部分图形源自 Feather 的 MIT——完整版权声明见
|
|
8
|
-
* 仓库根目录 THIRD_PARTY_LICENSES.md。表格行列操作图标(Column / Row 系列)为自绘。
|
|
8
|
+
* 仓库根目录 THIRD_PARTY_LICENSES.md。表格行列操作图标(Column / Row / TableDelete 系列)为自绘。
|
|
9
9
|
*/
|
|
10
10
|
export interface IconProps extends SVGProps<SVGSVGElement> {
|
|
11
11
|
size?: number | string;
|
|
@@ -34,3 +34,4 @@ export declare const ColumnDeleteIcon: (p: IconProps) => import("react").JSX.Ele
|
|
|
34
34
|
export declare const RowBeforeIcon: (p: IconProps) => import("react").JSX.Element;
|
|
35
35
|
export declare const RowAfterIcon: (p: IconProps) => import("react").JSX.Element;
|
|
36
36
|
export declare const RowDeleteIcon: (p: IconProps) => import("react").JSX.Element;
|
|
37
|
+
export declare const TableDeleteIcon: (p: IconProps) => import("react").JSX.Element;
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ import { FileHandlePlugin } from "@tiptap/extension-file-handler";
|
|
|
18
18
|
import * as DropdownMenu from "@radix-ui/react-dropdown-menu";
|
|
19
19
|
import * as Popover from "@radix-ui/react-popover";
|
|
20
20
|
import { createPortal } from "react-dom";
|
|
21
|
+
import { isInTable, selectedRect, rowIsHeader, CellSelection } from "@tiptap/pm/tables";
|
|
21
22
|
import { C, R as R2, f, r, s as s2 } from "./scrollToTocHeading-CwapFaVP.js";
|
|
22
23
|
function CitationRefView({ node, extension }) {
|
|
23
24
|
const index = String(node.attrs.index ?? "");
|
|
@@ -636,6 +637,13 @@ const RowDeleteIcon = (p) => /* @__PURE__ */ jsxs(Svg, { ...p, children: [
|
|
|
636
637
|
/* @__PURE__ */ jsx("path", { d: "m9 8 6 8" }),
|
|
637
638
|
/* @__PURE__ */ jsx("path", { d: "m15 8-6 8" })
|
|
638
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
|
+
] });
|
|
639
647
|
const defaultToolbarLabels = {
|
|
640
648
|
undo: "Undo",
|
|
641
649
|
redo: "Redo",
|
|
@@ -678,12 +686,20 @@ const defaultToolbarLabels = {
|
|
|
678
686
|
hr: "Divider",
|
|
679
687
|
importMarkdown: "Markdown",
|
|
680
688
|
tableInsert: "Insert table",
|
|
689
|
+
tableSizeSelected: (cols, rows) => `${cols} × ${rows}`,
|
|
681
690
|
tableAddColumnBefore: "Add column before",
|
|
682
691
|
tableAddColumnAfter: "Add column after",
|
|
683
692
|
tableDeleteColumn: "Delete column",
|
|
684
693
|
tableAddRowBefore: "Add row before",
|
|
685
694
|
tableAddRowAfter: "Add row after",
|
|
686
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",
|
|
687
703
|
inlineMath: "Inline equation",
|
|
688
704
|
blockMath: "Block equation",
|
|
689
705
|
mathPlaceholder: "E = mc^2",
|
|
@@ -1142,45 +1158,140 @@ function splitTopLevelBlocks(markdown) {
|
|
|
1142
1158
|
function stripToPlainText(markdown) {
|
|
1143
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();
|
|
1144
1160
|
}
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
const
|
|
1148
|
-
const
|
|
1149
|
-
const
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
const
|
|
1177
|
-
|
|
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";
|
|
1178
1285
|
const styles$3 = {
|
|
1179
1286
|
toolbar,
|
|
1180
1287
|
inner,
|
|
1181
1288
|
btn,
|
|
1182
1289
|
btnActive,
|
|
1183
1290
|
tableBubble,
|
|
1291
|
+
tableMenuItem,
|
|
1292
|
+
tableMenuItemIcon,
|
|
1293
|
+
tableMenuItemLabel,
|
|
1294
|
+
tableMenuDivider,
|
|
1184
1295
|
txtIcon,
|
|
1185
1296
|
colorIcon,
|
|
1186
1297
|
colorIconGlyph,
|
|
@@ -1197,6 +1308,12 @@ const styles$3 = {
|
|
|
1197
1308
|
menu,
|
|
1198
1309
|
menuItem,
|
|
1199
1310
|
menuItemSelected,
|
|
1311
|
+
tableInsertCaret,
|
|
1312
|
+
tableSizePicker,
|
|
1313
|
+
tableSizeGrid,
|
|
1314
|
+
tableSizeCell,
|
|
1315
|
+
tableSizeCellActive,
|
|
1316
|
+
tableSizeLabel,
|
|
1200
1317
|
popoverContent: popoverContent$1,
|
|
1201
1318
|
mathLayer,
|
|
1202
1319
|
mathStack,
|
|
@@ -1539,6 +1656,30 @@ function ToolbarButton({
|
|
|
1539
1656
|
function Divider() {
|
|
1540
1657
|
return /* @__PURE__ */ jsx("span", { className: styles$3.divider, "aria-hidden": true });
|
|
1541
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
|
+
}
|
|
1542
1683
|
const MenuCloseCtx = createContext(() => {
|
|
1543
1684
|
});
|
|
1544
1685
|
function MenuPopover({
|
|
@@ -1584,6 +1725,92 @@ function MenuItem({
|
|
|
1584
1725
|
}
|
|
1585
1726
|
);
|
|
1586
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
|
+
}
|
|
1587
1814
|
function ColorPopover({
|
|
1588
1815
|
title,
|
|
1589
1816
|
glyph,
|
|
@@ -1669,7 +1896,6 @@ function EditorToolbar({
|
|
|
1669
1896
|
superscript: e2.isActive("superscript"),
|
|
1670
1897
|
subscript: e2.isActive("subscript"),
|
|
1671
1898
|
inTable: e2.isActive("table"),
|
|
1672
|
-
inTableHeader: e2.isActive("tableHeader"),
|
|
1673
1899
|
canUndo: e2.can().undo(),
|
|
1674
1900
|
canRedo: e2.can().redo()
|
|
1675
1901
|
})
|
|
@@ -1709,7 +1935,7 @@ function EditorToolbar({
|
|
|
1709
1935
|
}
|
|
1710
1936
|
if (!inTable) return;
|
|
1711
1937
|
e2.preventDefault();
|
|
1712
|
-
editor
|
|
1938
|
+
preserveTableSelectionOnContextMenu(editor, coords.pos);
|
|
1713
1939
|
setTableMenu({ x: e2.clientX, y: e2.clientY });
|
|
1714
1940
|
};
|
|
1715
1941
|
dom.addEventListener("contextmenu", onContextMenu);
|
|
@@ -1734,6 +1960,13 @@ function EditorToolbar({
|
|
|
1734
1960
|
},
|
|
1735
1961
|
[closeTableMenu]
|
|
1736
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);
|
|
1737
1970
|
const handlePickImage = () => {
|
|
1738
1971
|
var _a;
|
|
1739
1972
|
return (_a = fileInputRef.current) == null ? void 0 : _a.click();
|
|
@@ -2280,14 +2513,11 @@ function EditorToolbar({
|
|
|
2280
2513
|
t.hr
|
|
2281
2514
|
] }) }),
|
|
2282
2515
|
/* @__PURE__ */ jsx(
|
|
2283
|
-
|
|
2516
|
+
TableInsertItem,
|
|
2284
2517
|
{
|
|
2285
2518
|
disabled: state.inTable,
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
/* @__PURE__ */ jsx("span", { className: styles$3.styleIcon, children: "⊞" }),
|
|
2289
|
-
t.tableInsert
|
|
2290
|
-
] })
|
|
2519
|
+
labels: t,
|
|
2520
|
+
onInsert: (rows, cols) => chain().insertTable({ rows, cols, withHeaderRow: true }).run()
|
|
2291
2521
|
}
|
|
2292
2522
|
),
|
|
2293
2523
|
extraToolbarItems == null ? void 0 : extraToolbarItems.map((item2) => /* @__PURE__ */ jsx(
|
|
@@ -2339,59 +2569,76 @@ function EditorToolbar({
|
|
|
2339
2569
|
{
|
|
2340
2570
|
className: styles$3.tableBubble,
|
|
2341
2571
|
style: { position: "fixed", left: tableMenu.x, top: tableMenu.y },
|
|
2572
|
+
role: "menu",
|
|
2342
2573
|
onMouseDown: (e2) => e2.stopPropagation(),
|
|
2343
2574
|
onContextMenu: (e2) => e2.preventDefault(),
|
|
2344
2575
|
children: [
|
|
2345
2576
|
/* @__PURE__ */ jsx(
|
|
2346
|
-
|
|
2577
|
+
TableMenuItem,
|
|
2347
2578
|
{
|
|
2348
|
-
|
|
2349
|
-
onClick: () => runTable(() =>
|
|
2579
|
+
label: tableMulti ? t.tableAddColumnBeforeN(tableColN) : t.tableAddColumnBefore,
|
|
2580
|
+
onClick: () => runTable(() => addColumnsBefore(editor, tableColN)),
|
|
2350
2581
|
children: /* @__PURE__ */ jsx(ColumnBeforeIcon, {})
|
|
2351
2582
|
}
|
|
2352
2583
|
),
|
|
2353
2584
|
/* @__PURE__ */ jsx(
|
|
2354
|
-
|
|
2585
|
+
TableMenuItem,
|
|
2355
2586
|
{
|
|
2356
|
-
|
|
2357
|
-
onClick: () => runTable(() =>
|
|
2587
|
+
label: tableMulti ? t.tableAddColumnAfterN(tableColN) : t.tableAddColumnAfter,
|
|
2588
|
+
onClick: () => runTable(() => addColumnsAfter(editor, tableColN)),
|
|
2358
2589
|
children: /* @__PURE__ */ jsx(ColumnAfterIcon, {})
|
|
2359
2590
|
}
|
|
2360
2591
|
),
|
|
2361
2592
|
/* @__PURE__ */ jsx(
|
|
2362
|
-
|
|
2593
|
+
TableMenuItem,
|
|
2363
2594
|
{
|
|
2364
|
-
|
|
2365
|
-
|
|
2595
|
+
label: tableMulti ? t.tableDeleteColumnN(tableColN) : t.tableDeleteColumn,
|
|
2596
|
+
disabled: disableDeleteColumn,
|
|
2597
|
+
onClick: () => runTable(() => {
|
|
2598
|
+
deleteSelectedColumns(editor);
|
|
2599
|
+
}),
|
|
2366
2600
|
children: /* @__PURE__ */ jsx(ColumnDeleteIcon, {})
|
|
2367
2601
|
}
|
|
2368
2602
|
),
|
|
2369
|
-
/* @__PURE__ */ jsx(
|
|
2603
|
+
/* @__PURE__ */ jsx(TableMenuDivider, {}),
|
|
2370
2604
|
/* @__PURE__ */ jsx(
|
|
2371
|
-
|
|
2605
|
+
TableMenuItem,
|
|
2372
2606
|
{
|
|
2373
|
-
|
|
2374
|
-
disabled:
|
|
2375
|
-
onClick: () => runTable(() =>
|
|
2607
|
+
label: tableMulti ? t.tableAddRowBeforeN(tableRowN) : t.tableAddRowBefore,
|
|
2608
|
+
disabled: disableAddRowBefore,
|
|
2609
|
+
onClick: () => runTable(() => addRowsBefore(editor, tableRowN)),
|
|
2376
2610
|
children: /* @__PURE__ */ jsx(RowBeforeIcon, {})
|
|
2377
2611
|
}
|
|
2378
2612
|
),
|
|
2379
2613
|
/* @__PURE__ */ jsx(
|
|
2380
|
-
|
|
2614
|
+
TableMenuItem,
|
|
2381
2615
|
{
|
|
2382
|
-
|
|
2383
|
-
onClick: () => runTable(() =>
|
|
2616
|
+
label: tableMulti ? t.tableAddRowAfterN(tableRowN) : t.tableAddRowAfter,
|
|
2617
|
+
onClick: () => runTable(() => addRowsAfter(editor, tableRowN)),
|
|
2384
2618
|
children: /* @__PURE__ */ jsx(RowAfterIcon, {})
|
|
2385
2619
|
}
|
|
2386
2620
|
),
|
|
2387
2621
|
/* @__PURE__ */ jsx(
|
|
2388
|
-
|
|
2622
|
+
TableMenuItem,
|
|
2389
2623
|
{
|
|
2390
|
-
|
|
2391
|
-
disabled:
|
|
2392
|
-
onClick: () => runTable(() =>
|
|
2624
|
+
label: tableMulti ? t.tableDeleteRowN(tableRowN) : t.tableDeleteRow,
|
|
2625
|
+
disabled: disableDeleteRow,
|
|
2626
|
+
onClick: () => runTable(() => {
|
|
2627
|
+
deleteSelectedRows(editor);
|
|
2628
|
+
}),
|
|
2393
2629
|
children: /* @__PURE__ */ jsx(RowDeleteIcon, {})
|
|
2394
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
|
+
}
|
|
2395
2642
|
)
|
|
2396
2643
|
]
|
|
2397
2644
|
}
|
|
@@ -2636,6 +2883,7 @@ export {
|
|
|
2636
2883
|
RowBeforeIcon,
|
|
2637
2884
|
RowDeleteIcon,
|
|
2638
2885
|
StrikethroughIcon,
|
|
2886
|
+
TableDeleteIcon,
|
|
2639
2887
|
TocPanel,
|
|
2640
2888
|
TrashIcon,
|
|
2641
2889
|
UnderlineIcon,
|