@mdxeditor/editor 0.4.2 → 0.5.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.
@@ -0,0 +1,428 @@
1
+ import { ContentEditable } from "@lexical/react/LexicalContentEditable";
2
+ import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary";
3
+ import { LexicalNestedComposer } from "@lexical/react/LexicalNestedComposer";
4
+ import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
5
+ import { $createParagraphNode, createEditor, KEY_TAB_COMMAND, COMMAND_PRIORITY_CRITICAL, KEY_ENTER_COMMAND, BLUR_COMMAND, $getRoot } from "lexical";
6
+ import * as React from "react";
7
+ import React__default, { useEffect } from "react";
8
+ import { s as styles, u as useEmitterValues, t as theme, i as importMdastTreeToLexical, S as SharedHistoryPlugin, e as exportLexicalTreeToMdast } from "./index-11db5fbf.js";
9
+ import { toHast } from "mdast-util-to-hast";
10
+ import { raw } from "hast-util-raw";
11
+ import { sanitize } from "hast-util-sanitize";
12
+ import { toHtml } from "hast-util-to-html";
13
+ import * as RadixPopover from "@radix-ui/react-popover";
14
+ import classNames from "classnames";
15
+ import * as RadixToolbar from "@radix-ui/react-toolbar";
16
+ import "@lexical/react/LexicalComposer";
17
+ import "@lexical/react/LexicalHorizontalRulePlugin";
18
+ import "@lexical/react/LexicalLinkPlugin";
19
+ import "@lexical/react/LexicalListPlugin";
20
+ import "@lexical/react/LexicalTabIndentationPlugin";
21
+ import "@lexical/code";
22
+ import "@lexical/link";
23
+ import "@lexical/list";
24
+ import "@lexical/react/LexicalHorizontalRuleNode";
25
+ import "@lexical/rich-text";
26
+ import "mdast-util-directive";
27
+ import "mdast-util-from-markdown";
28
+ import "mdast-util-frontmatter";
29
+ import "mdast-util-gfm-table";
30
+ import "mdast-util-mdx";
31
+ import "micromark-extension-directive";
32
+ import "micromark-extension-frontmatter";
33
+ import "micromark-extension-gfm-table";
34
+ import "micromark-extension-mdxjs";
35
+ import "@lexical/utils";
36
+ import "@lexical/react/LexicalComposerContext";
37
+ import "@lexical/selection";
38
+ import "@lexical/react/LexicalHistoryPlugin";
39
+ import "mdast-util-to-markdown";
40
+ import "@radix-ui/react-tooltip";
41
+ import "downshift";
42
+ import "@lexical/markdown";
43
+ import "@lexical/react/LexicalMarkdownShortcutPlugin";
44
+ import "@codemirror/lang-markdown";
45
+ import "@codesandbox/sandpack-react";
46
+ import "react-diff-view";
47
+ import "unidiff";
48
+ import "@radix-ui/react-select";
49
+ import "@radix-ui/react-dialog";
50
+ const MarkdownAstRenderer = (props) => {
51
+ const root = { type: "root", children: props.mdastChildren };
52
+ const hast = raw(toHast(root, { allowDangerousHtml: true }));
53
+ const safeHast = sanitize(hast);
54
+ const html = toHtml(safeHast);
55
+ return /* @__PURE__ */ React__default.createElement("span", { dangerouslySetInnerHTML: { __html: html || " " } });
56
+ };
57
+ const SvgMoreHoriz = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
58
+ maskType: "alpha"
59
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M6 14c-.55 0-1.02-.196-1.412-.588A1.926 1.926 0 0 1 4 12c0-.55.196-1.02.588-1.412A1.926 1.926 0 0 1 6 10c.55 0 1.02.196 1.412.588.392.391.588.862.588 1.412 0 .55-.196 1.02-.588 1.412A1.926 1.926 0 0 1 6 14Zm6 0c-.55 0-1.02-.196-1.412-.588A1.926 1.926 0 0 1 10 12c0-.55.196-1.02.588-1.412A1.926 1.926 0 0 1 12 10c.55 0 1.02.196 1.412.588.392.391.588.862.588 1.412 0 .55-.196 1.02-.588 1.412A1.926 1.926 0 0 1 12 14Zm6 0c-.55 0-1.02-.196-1.413-.588A1.926 1.926 0 0 1 16 12c0-.55.196-1.02.587-1.412A1.926 1.926 0 0 1 18 10c.55 0 1.02.196 1.413.588.391.391.587.862.587 1.412 0 .55-.196 1.02-.587 1.412A1.926 1.926 0 0 1 18 14Z" })));
60
+ const MoreHorizIcon = SvgMoreHoriz;
61
+ const SvgFormatAlignLeft = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 20, height: 20, fill: "currentColor", viewBox: "0 0 20 20", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 20, height: 20, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
62
+ maskType: "alpha"
63
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h20v20H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M3 17v-1.5h14V17H3Zm0-3.125v-1.5h10v1.5H3Zm0-3.125v-1.5h14v1.5H3Zm0-3.125v-1.5h10v1.5H3ZM3 4.5V3h14v1.5H3Z" })));
64
+ const AlignLeftIcon = SvgFormatAlignLeft;
65
+ const SvgFormatAlignCenter = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 20, height: 20, fill: "currentColor", viewBox: "0 0 20 20", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 20, height: 20, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
66
+ maskType: "alpha"
67
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h20v20H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M3 17v-1.5h14V17H3Zm3-3.125v-1.5h8v1.5H6ZM3 10.75v-1.5h14v1.5H3Zm3-3.125v-1.5h8v1.5H6ZM3 4.5V3h14v1.5H3Z" })));
68
+ const AlignCenterIcon = SvgFormatAlignCenter;
69
+ const SvgFormatAlignRight = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 20, height: 20, fill: "currentColor", viewBox: "0 0 20 20", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 20, height: 20, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
70
+ maskType: "alpha"
71
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h20v20H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M3 17v-1.5h14V17H3Zm4-3.125v-1.5h10v1.5H7ZM3 10.75v-1.5h14v1.5H3Zm4-3.125v-1.5h10v1.5H7ZM3 4.5V3h14v1.5H3Z" })));
72
+ const AlignRightIcon = SvgFormatAlignRight;
73
+ const SvgInsertColLeft = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 20, height: 20, fill: "currentColor", viewBox: "0 0 20 20", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 20, height: 20, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
74
+ maskType: "alpha"
75
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 20h20v20H0z", transform: "rotate(-90 0 20)" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M15.75 4.5H13v2.75h-1.5V4.5H8.75V3h2.75V.25H13V3h2.75v1.5ZM13 17H5V3h2.25v1.5H6.5v11h5V8.75H13V17Z" })));
76
+ const InsertColLeftIcon = SvgInsertColLeft;
77
+ const SvgInsertColRight = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 20, height: 20, fill: "currentColor", viewBox: "0 0 20 20", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 20, height: 20, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
78
+ maskType: "alpha"
79
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h20v20H0z", transform: "matrix(0 -1 -1 0 20 20)" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M4.25 4.5H7v2.75h1.5V4.5h2.75V3H8.5V.25H7V3H4.25v1.5ZM7 17h8V3h-2.25v1.5h.75v11h-5V8.75H7V17Z" })));
80
+ const InsertColRightIcon = SvgInsertColRight;
81
+ const SvgDeleteSmall = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 20, height: 20, fill: "currentColor", viewBox: "0 0 20 20", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 20, height: 20, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
82
+ maskType: "alpha"
83
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h20v20H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M6.5 17a1.45 1.45 0 0 1-1.06-.44A1.445 1.445 0 0 1 5 15.5v-10H4V4h4V3h4v1h4v1.5h-1v9.991c0 .423-.147.78-.44 1.072A1.45 1.45 0 0 1 13.5 17h-7Zm7-11.5h-7v10h7v-10ZM8 14h1.5V7H8v7Zm2.5 0H12V7h-1.5v7Z" })));
84
+ const DeleteSmallIcon = SvgDeleteSmall;
85
+ const SvgInsertRowAbove = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 20, height: 20, fill: "currentColor", viewBox: "0 0 20 20", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 20, height: 20, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
86
+ maskType: "alpha"
87
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h20v20H0z", transform: "matrix(-1 0 0 1 20 0)" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M4.5 16.75V14h2.75v-1.5H4.5V9.75H3v2.75H.25V14H3v2.75h1.5ZM17 14V6H3v2.25h1.5V7.5h11v5H8.75V14H17Z" })));
88
+ const InsertRowAboveIcon = SvgInsertRowAbove;
89
+ const SvgInsertRowBelow = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 20, height: 20, fill: "currentColor", viewBox: "0 0 20 20", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 20, height: 20, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
90
+ maskType: "alpha"
91
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M20 20h20v20H20z", transform: "rotate(180 20 20)" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M4.5 3.25V6h2.75v1.5H4.5v2.75H3V7.5H.25V6H3V3.25h1.5ZM17 6v8H3v-2.25h1.5v.75h11v-5H8.75V6H17Z" })));
92
+ const InsertRowBelowIcon = SvgInsertRowBelow;
93
+ const SvgAddRow = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 20, height: 20, fill: "currentColor", viewBox: "0 0 20 20", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 20, height: 20, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
94
+ maskType: "alpha"
95
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M20 20h20v20H20z", transform: "rotate(180 20 20)" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M10.5 3.25V6h2.75v1.5H10.5v2.75H9V7.5H6.25V6H9V3.25h1.5ZM17 6v8H3V6h2.5v1.5h-1v5h11v-5H14V6h3Z" })));
96
+ const AddRowIcon = SvgAddRow;
97
+ const SvgAddColumn = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 20, height: 20, fill: "currentColor", viewBox: "0 0 20 20", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 20, height: 20, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
98
+ maskType: "alpha"
99
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h20v20H0z", transform: "matrix(0 -1 -1 0 20 20)" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M3.25 10.5H6v2.75h1.5V10.5h2.75V9H7.5V6.25H6V9H3.25v1.5ZM6 17h8V3H6v2.5h1.5v-1h5v11h-5V14H6v3Z" })));
100
+ const AddColumnIcon = SvgAddColumn;
101
+ const AlignToTailwindClassMap = {
102
+ center: styles.centeredCell,
103
+ left: styles.leftAlignedCell,
104
+ right: styles.rightAlignedCell
105
+ };
106
+ const TableEditor = ({ mdastNode, parentEditor, lexicalTable }) => {
107
+ const [activeCell, setActiveCell] = React__default.useState(null);
108
+ const setActiveCellWithBoundaries = React__default.useCallback(
109
+ (cell) => {
110
+ const colCount = lexicalTable.getColCount();
111
+ if (cell === null) {
112
+ setActiveCell(null);
113
+ return;
114
+ }
115
+ let [colIndex, rowIndex] = cell;
116
+ if (colIndex > colCount - 1) {
117
+ colIndex = 0;
118
+ rowIndex++;
119
+ }
120
+ if (colIndex < 0) {
121
+ colIndex = colCount - 1;
122
+ rowIndex -= 1;
123
+ }
124
+ if (rowIndex > lexicalTable.getRowCount() - 1) {
125
+ setActiveCell(null);
126
+ parentEditor.update(() => {
127
+ const nextSibling = lexicalTable.getLatest().getNextSibling();
128
+ if (nextSibling) {
129
+ lexicalTable.getLatest().selectNext();
130
+ } else {
131
+ const newParagraph = $createParagraphNode();
132
+ lexicalTable.insertAfter(newParagraph);
133
+ newParagraph.select();
134
+ }
135
+ });
136
+ return;
137
+ }
138
+ if (rowIndex < 0) {
139
+ setActiveCell(null);
140
+ parentEditor.update(() => {
141
+ lexicalTable.getLatest().selectPrevious();
142
+ });
143
+ return;
144
+ }
145
+ setActiveCell([colIndex, rowIndex]);
146
+ },
147
+ [lexicalTable, parentEditor]
148
+ );
149
+ useEffect(() => {
150
+ lexicalTable.focusEmitter.subscribe(setActiveCellWithBoundaries);
151
+ }, [lexicalTable, setActiveCellWithBoundaries]);
152
+ const addRowToBottom = React__default.useCallback(() => {
153
+ parentEditor.update(() => {
154
+ lexicalTable.addRowToBottom();
155
+ setActiveCell([0, lexicalTable.getRowCount()]);
156
+ });
157
+ }, [parentEditor, lexicalTable]);
158
+ const addColumnToRight = React__default.useCallback(() => {
159
+ parentEditor.update(() => {
160
+ lexicalTable.addColumnToRight();
161
+ setActiveCell([lexicalTable.getColCount(), 0]);
162
+ });
163
+ }, [parentEditor, lexicalTable]);
164
+ const [highlightedCoordinates, setHighlightedCoordinates] = React__default.useState([-1, -1]);
165
+ const onTableMouseOver = React__default.useCallback((e) => {
166
+ let tableCell = e.target;
167
+ while (tableCell && !["TH", "TD"].includes(tableCell.tagName)) {
168
+ if (tableCell === e.currentTarget) {
169
+ return;
170
+ }
171
+ tableCell = tableCell.parentElement;
172
+ }
173
+ if (tableCell === null) {
174
+ return;
175
+ }
176
+ const tableRow = tableCell.parentElement;
177
+ const tableContainer = tableRow.parentElement;
178
+ const colIndex = tableContainer.tagName === "TFOOT" ? -1 : Array.from(tableRow.children).indexOf(tableCell);
179
+ const rowIndex = tableCell.tagName === "TH" ? -1 : Array.from(tableRow.parentElement.children).indexOf(tableRow);
180
+ setHighlightedCoordinates([colIndex, rowIndex]);
181
+ }, []);
182
+ return /* @__PURE__ */ React__default.createElement("table", { className: styles.tableEditor, onMouseOver: onTableMouseOver, onMouseLeave: () => setHighlightedCoordinates([-1, -1]) }, /* @__PURE__ */ React__default.createElement("colgroup", null, /* @__PURE__ */ React__default.createElement("col", null), Array.from({ length: mdastNode.children[0].children.length }, (_, colIndex) => {
183
+ const align = mdastNode.align || [];
184
+ const currentColumnAlign = align[colIndex] || "left";
185
+ const className = AlignToTailwindClassMap[currentColumnAlign];
186
+ return /* @__PURE__ */ React__default.createElement("col", { key: colIndex, className });
187
+ }), /* @__PURE__ */ React__default.createElement("col", null)), /* @__PURE__ */ React__default.createElement("thead", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", { className: styles.tableToolsColumn, "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement(
188
+ "button",
189
+ {
190
+ className: styles.iconButton,
191
+ title: "Delete table",
192
+ onClick: () => {
193
+ parentEditor.update(() => {
194
+ lexicalTable.selectNext();
195
+ lexicalTable.remove();
196
+ });
197
+ }
198
+ },
199
+ /* @__PURE__ */ React__default.createElement(DeleteSmallIcon, null)
200
+ )), Array.from({ length: mdastNode.children[0].children.length }, (_, colIndex) => {
201
+ return /* @__PURE__ */ React__default.createElement("th", { key: colIndex, "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement(
202
+ ColumnEditor,
203
+ {
204
+ ...{
205
+ setActiveCellWithBoundaries,
206
+ parentEditor,
207
+ colIndex,
208
+ highlightedCoordinates,
209
+ lexicalTable,
210
+ align: (mdastNode.align || [])[colIndex]
211
+ }
212
+ }
213
+ ));
214
+ }), /* @__PURE__ */ React__default.createElement("th", { className: styles.tableToolsColumn }))), /* @__PURE__ */ React__default.createElement("tbody", null, mdastNode.children.map((row, rowIndex) => {
215
+ return /* @__PURE__ */ React__default.createElement("tr", { key: rowIndex }, /* @__PURE__ */ React__default.createElement("td", { className: styles.toolCell, "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement(RowEditor, { ...{ setActiveCellWithBoundaries, parentEditor, rowIndex, highlightedCoordinates, lexicalTable } })), row.children.map((mdastCell, colIndex) => {
216
+ var _a;
217
+ return /* @__PURE__ */ React__default.createElement(
218
+ Cell,
219
+ {
220
+ align: (_a = mdastNode.align) == null ? void 0 : _a[colIndex],
221
+ key: colIndex,
222
+ contents: mdastCell.children,
223
+ ...{ rowIndex, colIndex, lexicalTable, parentEditor, activeCellTuple: [activeCell, setActiveCellWithBoundaries] }
224
+ }
225
+ );
226
+ }), rowIndex === 0 && /* @__PURE__ */ React__default.createElement("th", { rowSpan: lexicalTable.getRowCount(), "data-tool-cell": true }, /* @__PURE__ */ React__default.createElement("button", { className: styles.addColumnButton, onClick: addColumnToRight }, /* @__PURE__ */ React__default.createElement(AddColumnIcon, null))));
227
+ })), /* @__PURE__ */ React__default.createElement("tfoot", null, /* @__PURE__ */ React__default.createElement("tr", null, /* @__PURE__ */ React__default.createElement("th", null), /* @__PURE__ */ React__default.createElement("th", { colSpan: lexicalTable.getColCount() }, /* @__PURE__ */ React__default.createElement("button", { className: styles.addRowButton, onClick: addRowToBottom }, /* @__PURE__ */ React__default.createElement(AddRowIcon, null))), /* @__PURE__ */ React__default.createElement("th", null))));
228
+ };
229
+ const Cell = ({ align, ...props }) => {
230
+ const [activeCell, setActiveCell] = props.activeCellTuple;
231
+ const isActive = activeCell && activeCell[0] === props.colIndex && activeCell[1] === props.rowIndex;
232
+ const className = AlignToTailwindClassMap[align || "left"];
233
+ return /* @__PURE__ */ React__default.createElement(
234
+ "td",
235
+ {
236
+ className,
237
+ "data-active": isActive,
238
+ onClick: () => {
239
+ setActiveCell([props.colIndex, props.rowIndex]);
240
+ }
241
+ },
242
+ isActive ? /* @__PURE__ */ React__default.createElement(CellEditor, { ...props }) : /* @__PURE__ */ React__default.createElement(MarkdownAstRenderer, { mdastChildren: props.contents })
243
+ );
244
+ };
245
+ const CellEditor = ({ activeCellTuple, parentEditor, lexicalTable, contents, colIndex, rowIndex }) => {
246
+ const [markdownParseOptions, lexicalConvertOptions, jsxComponentDescriptors, lexicalNodes] = useEmitterValues(
247
+ "markdownParseOptions",
248
+ "lexicalConvertOptions",
249
+ "jsxComponentDescriptors",
250
+ "lexicalNodes"
251
+ );
252
+ const [editor] = React__default.useState(() => {
253
+ let disposed = false;
254
+ const editor2 = createEditor({
255
+ nodes: lexicalNodes,
256
+ theme
257
+ });
258
+ function saveAndDispose(nextCell) {
259
+ if (disposed) {
260
+ return;
261
+ }
262
+ disposed = true;
263
+ editor2.getEditorState().read(() => {
264
+ const mdast = exportLexicalTreeToMdast({
265
+ root: $getRoot(),
266
+ jsxComponentDescriptors,
267
+ ...lexicalConvertOptions
268
+ });
269
+ parentEditor.update(() => {
270
+ lexicalTable.updateCellContents(colIndex, rowIndex, mdast.children[0].children);
271
+ });
272
+ });
273
+ activeCellTuple[1](nextCell);
274
+ }
275
+ editor2.registerCommand(
276
+ KEY_TAB_COMMAND,
277
+ (payload) => {
278
+ payload.preventDefault();
279
+ const nextCell = payload.shiftKey ? [colIndex - 1, rowIndex] : [colIndex + 1, rowIndex];
280
+ saveAndDispose(nextCell);
281
+ return true;
282
+ },
283
+ COMMAND_PRIORITY_CRITICAL
284
+ );
285
+ editor2.registerCommand(
286
+ KEY_ENTER_COMMAND,
287
+ (payload) => {
288
+ payload == null ? void 0 : payload.preventDefault();
289
+ const nextCell = (payload == null ? void 0 : payload.shiftKey) ? [colIndex, rowIndex - 1] : [colIndex, rowIndex + 1];
290
+ saveAndDispose(nextCell);
291
+ return true;
292
+ },
293
+ COMMAND_PRIORITY_CRITICAL
294
+ );
295
+ editor2.registerCommand(
296
+ BLUR_COMMAND,
297
+ (payload) => {
298
+ const relatedTarget = payload.relatedTarget;
299
+ if ((relatedTarget == null ? void 0 : relatedTarget.dataset["editorDialog"]) !== void 0) {
300
+ return false;
301
+ }
302
+ saveAndDispose(null);
303
+ return true;
304
+ },
305
+ COMMAND_PRIORITY_CRITICAL
306
+ );
307
+ editor2.registerRootListener((element) => {
308
+ if (element) {
309
+ editor2.focus();
310
+ }
311
+ });
312
+ editor2.update(() => {
313
+ importMdastTreeToLexical({
314
+ root: $getRoot(),
315
+ mdastRoot: { type: "root", children: [{ type: "paragraph", children: contents }] },
316
+ visitors: markdownParseOptions.visitors
317
+ });
318
+ });
319
+ return editor2;
320
+ });
321
+ return /* @__PURE__ */ React__default.createElement(LexicalNestedComposer, { initialEditor: editor }, /* @__PURE__ */ React__default.createElement(RichTextPlugin, { contentEditable: /* @__PURE__ */ React__default.createElement(ContentEditable, { autoFocus: true }), placeholder: /* @__PURE__ */ React__default.createElement("div", null), ErrorBoundary: LexicalErrorBoundary }), /* @__PURE__ */ React__default.createElement(SharedHistoryPlugin, null));
322
+ };
323
+ const ColumnEditor = ({
324
+ parentEditor,
325
+ highlightedCoordinates,
326
+ align,
327
+ lexicalTable,
328
+ colIndex,
329
+ setActiveCellWithBoundaries
330
+ }) => {
331
+ const [editorRootElementRef] = useEmitterValues("editorRootElementRef");
332
+ const insertColumnAt = React__default.useCallback(
333
+ (colIndex2) => {
334
+ parentEditor.update(() => {
335
+ lexicalTable.insertColumnAt(colIndex2);
336
+ });
337
+ setActiveCellWithBoundaries([colIndex2, 0]);
338
+ },
339
+ [parentEditor, lexicalTable, setActiveCellWithBoundaries]
340
+ );
341
+ const deleteColumnAt = React__default.useCallback(
342
+ (colIndex2) => {
343
+ parentEditor.update(() => {
344
+ lexicalTable.deleteColumnAt(colIndex2);
345
+ });
346
+ },
347
+ [parentEditor, lexicalTable]
348
+ );
349
+ const setColumnAlign = React__default.useCallback(
350
+ (colIndex2, align2) => {
351
+ parentEditor.update(() => {
352
+ lexicalTable.setColumnAlign(colIndex2, align2);
353
+ });
354
+ },
355
+ [parentEditor, lexicalTable]
356
+ );
357
+ return /* @__PURE__ */ React__default.createElement(RadixPopover.Root, null, /* @__PURE__ */ React__default.createElement(
358
+ RadixPopover.PopoverTrigger,
359
+ {
360
+ className: styles.tableColumnEditorTrigger,
361
+ "data-active": highlightedCoordinates[0] === colIndex + 1,
362
+ title: "Column menu"
363
+ },
364
+ /* @__PURE__ */ React__default.createElement(MoreHorizIcon, null)
365
+ ), /* @__PURE__ */ React__default.createElement(RadixPopover.Portal, { container: editorRootElementRef == null ? void 0 : editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(
366
+ RadixPopover.PopoverContent,
367
+ {
368
+ className: classNames(styles.tableColumnEditorPopoverContent),
369
+ onOpenAutoFocus: (e) => e.preventDefault(),
370
+ sideOffset: 5,
371
+ side: "top"
372
+ },
373
+ /* @__PURE__ */ React__default.createElement(RadixToolbar.Root, { className: styles.tableColumnEditorToolbar }, /* @__PURE__ */ React__default.createElement(
374
+ RadixToolbar.ToggleGroup,
375
+ {
376
+ className: styles.toggleGroupRoot,
377
+ onValueChange: (value) => {
378
+ setColumnAlign(colIndex, value);
379
+ },
380
+ value: align || "left",
381
+ type: "single",
382
+ "aria-label": "Text alignment"
383
+ },
384
+ /* @__PURE__ */ React__default.createElement(RadixToolbar.ToggleItem, { value: "left", title: "Align left" }, /* @__PURE__ */ React__default.createElement(AlignLeftIcon, null)),
385
+ /* @__PURE__ */ React__default.createElement(RadixToolbar.ToggleItem, { value: "center", title: "Align center" }, /* @__PURE__ */ React__default.createElement(AlignCenterIcon, null)),
386
+ /* @__PURE__ */ React__default.createElement(RadixToolbar.ToggleItem, { value: "right", title: "Align right" }, /* @__PURE__ */ React__default.createElement(AlignRightIcon, null))
387
+ ), /* @__PURE__ */ React__default.createElement(RadixToolbar.Separator, null), /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { onClick: insertColumnAt.bind(null, colIndex), title: "Insert a column to the left of this one" }, /* @__PURE__ */ React__default.createElement(InsertColLeftIcon, null)), /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { onClick: insertColumnAt.bind(null, colIndex + 1), title: "Insert a column to the right of this one" }, /* @__PURE__ */ React__default.createElement(InsertColRightIcon, null)), /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { onClick: deleteColumnAt.bind(null, colIndex), title: "Delete this column" }, /* @__PURE__ */ React__default.createElement(DeleteSmallIcon, null)))
388
+ )));
389
+ };
390
+ const RowEditor = ({
391
+ parentEditor,
392
+ highlightedCoordinates,
393
+ lexicalTable,
394
+ rowIndex,
395
+ setActiveCellWithBoundaries
396
+ }) => {
397
+ const [editorRootElementRef] = useEmitterValues("editorRootElementRef");
398
+ const insertRowAt = React__default.useCallback(
399
+ (rowIndex2) => {
400
+ parentEditor.update(() => {
401
+ lexicalTable.insertRowAt(rowIndex2);
402
+ });
403
+ setActiveCellWithBoundaries([0, rowIndex2]);
404
+ },
405
+ [parentEditor, lexicalTable, setActiveCellWithBoundaries]
406
+ );
407
+ const deleteRowAt = React__default.useCallback(
408
+ (rowIndex2) => {
409
+ parentEditor.update(() => {
410
+ lexicalTable.deleteRowAt(rowIndex2);
411
+ });
412
+ },
413
+ [parentEditor, lexicalTable]
414
+ );
415
+ return /* @__PURE__ */ React__default.createElement(RadixPopover.Root, null, /* @__PURE__ */ React__default.createElement(RadixPopover.PopoverTrigger, { className: styles.tableColumnEditorTrigger, "data-active": highlightedCoordinates[1] === rowIndex }, /* @__PURE__ */ React__default.createElement(MoreHorizIcon, null)), /* @__PURE__ */ React__default.createElement(RadixPopover.Portal, { container: editorRootElementRef == null ? void 0 : editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(
416
+ RadixPopover.PopoverContent,
417
+ {
418
+ className: classNames(styles.tableColumnEditorPopoverContent),
419
+ onOpenAutoFocus: (e) => e.preventDefault(),
420
+ sideOffset: 5,
421
+ side: "bottom"
422
+ },
423
+ /* @__PURE__ */ React__default.createElement(RadixToolbar.Root, { className: styles.tableColumnEditorToolbar }, /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { onClick: insertRowAt.bind(null, rowIndex), title: "Insert a row above this one" }, /* @__PURE__ */ React__default.createElement(InsertRowAboveIcon, null)), /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { onClick: insertRowAt.bind(null, rowIndex + 1), title: "Insert a row below this one" }, /* @__PURE__ */ React__default.createElement(InsertRowBelowIcon, null)), /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { onClick: deleteRowAt.bind(null, rowIndex), title: "Delete this row" }, /* @__PURE__ */ React__default.createElement(DeleteSmallIcon, null)))
424
+ )));
425
+ };
426
+ export {
427
+ TableEditor
428
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@lexical/react/LexicalContentEditable"),t=require("@lexical/react/LexicalErrorBoundary"),l=require("@lexical/react/LexicalNestedComposer"),r=require("@lexical/react/LexicalRichTextPlugin"),a=require("lexical"),n=require("react"),i=require("./index-731c8e58.cjs"),o=require("mdast-util-to-hast"),c=require("hast-util-raw"),s=require("hast-util-sanitize"),m=require("hast-util-to-html"),u=require("@radix-ui/react-popover"),h=require("classnames"),d=require("@radix-ui/react-toolbar");function g(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const l in e)if("default"!==l){const r=Object.getOwnPropertyDescriptor(e,l);Object.defineProperty(t,l,r.get?r:{enumerable:!0,get:()=>e[l]})}return t.default=e,Object.freeze(t)}require("@lexical/react/LexicalComposer"),require("@lexical/react/LexicalHorizontalRulePlugin"),require("@lexical/react/LexicalLinkPlugin"),require("@lexical/react/LexicalListPlugin"),require("@lexical/react/LexicalTabIndentationPlugin"),require("@lexical/code"),require("@lexical/link"),require("@lexical/list"),require("@lexical/react/LexicalHorizontalRuleNode"),require("@lexical/rich-text"),require("mdast-util-directive"),require("mdast-util-from-markdown"),require("mdast-util-frontmatter"),require("mdast-util-gfm-table"),require("mdast-util-mdx"),require("micromark-extension-directive"),require("micromark-extension-frontmatter"),require("micromark-extension-gfm-table"),require("micromark-extension-mdxjs"),require("@lexical/utils"),require("@lexical/react/LexicalComposerContext"),require("@lexical/selection"),require("@lexical/react/LexicalHistoryPlugin"),require("mdast-util-to-markdown"),require("@radix-ui/react-tooltip"),require("downshift"),require("@lexical/markdown"),require("@lexical/react/LexicalMarkdownShortcutPlugin"),require("@codemirror/lang-markdown"),require("@codesandbox/sandpack-react"),require("react-diff-view"),require("unidiff"),require("@radix-ui/react-select"),require("@radix-ui/react-dialog");const E=g(n),v=g(u),p=g(d),x=e=>{const t={type:"root",children:e.mdastChildren},l=c.raw(o.toHast(t,{allowDangerousHtml:!0})),r=s.sanitize(l),a=m.toHtml(r);return n.createElement("span",{dangerouslySetInnerHTML:{__html:a||"&nbsp;"}})},w=e=>E.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:24,height:24,fill:"currentColor",viewBox:"0 0 24 24",...e},E.createElement("mask",{id:"a",width:24,height:24,x:0,y:0,maskUnits:"userSpaceOnUse",style:{maskType:"alpha"}},E.createElement("path",{d:"M0 0h24v24H0z"})),E.createElement("g",{mask:"url(#a)"},E.createElement("path",{d:"M6 14c-.55 0-1.02-.196-1.412-.588A1.926 1.926 0 0 1 4 12c0-.55.196-1.02.588-1.412A1.926 1.926 0 0 1 6 10c.55 0 1.02.196 1.412.588.392.391.588.862.588 1.412 0 .55-.196 1.02-.588 1.412A1.926 1.926 0 0 1 6 14Zm6 0c-.55 0-1.02-.196-1.412-.588A1.926 1.926 0 0 1 10 12c0-.55.196-1.02.588-1.412A1.926 1.926 0 0 1 12 10c.55 0 1.02.196 1.412.588.392.391.588.862.588 1.412 0 .55-.196 1.02-.588 1.412A1.926 1.926 0 0 1 12 14Zm6 0c-.55 0-1.02-.196-1.413-.588A1.926 1.926 0 0 1 16 12c0-.55.196-1.02.587-1.412A1.926 1.926 0 0 1 18 10c.55 0 1.02.196 1.413.588.391.391.587.862.587 1.412 0 .55-.196 1.02-.587 1.412A1.926 1.926 0 0 1 18 14Z"}))),C=e=>E.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:20,height:20,fill:"currentColor",viewBox:"0 0 20 20",...e},E.createElement("mask",{id:"a",width:20,height:20,x:0,y:0,maskUnits:"userSpaceOnUse",style:{maskType:"alpha"}},E.createElement("path",{d:"M0 0h20v20H0z"})),E.createElement("g",{mask:"url(#a)"},E.createElement("path",{d:"M3 17v-1.5h14V17H3Zm0-3.125v-1.5h10v1.5H3Zm0-3.125v-1.5h14v1.5H3Zm0-3.125v-1.5h10v1.5H3ZM3 4.5V3h14v1.5H3Z"}))),k=e=>E.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:20,height:20,fill:"currentColor",viewBox:"0 0 20 20",...e},E.createElement("mask",{id:"a",width:20,height:20,x:0,y:0,maskUnits:"userSpaceOnUse",style:{maskType:"alpha"}},E.createElement("path",{d:"M0 0h20v20H0z"})),E.createElement("g",{mask:"url(#a)"},E.createElement("path",{d:"M3 17v-1.5h14V17H3Zm3-3.125v-1.5h8v1.5H6ZM3 10.75v-1.5h14v1.5H3Zm3-3.125v-1.5h8v1.5H6ZM3 4.5V3h14v1.5H3Z"}))),f=e=>E.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:20,height:20,fill:"currentColor",viewBox:"0 0 20 20",...e},E.createElement("mask",{id:"a",width:20,height:20,x:0,y:0,maskUnits:"userSpaceOnUse",style:{maskType:"alpha"}},E.createElement("path",{d:"M0 0h20v20H0z"})),E.createElement("g",{mask:"url(#a)"},E.createElement("path",{d:"M3 17v-1.5h14V17H3Zm4-3.125v-1.5h10v1.5H7ZM3 10.75v-1.5h14v1.5H3Zm4-3.125v-1.5h10v1.5H7ZM3 4.5V3h14v1.5H3Z"}))),H=e=>E.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:20,height:20,fill:"currentColor",viewBox:"0 0 20 20",...e},E.createElement("mask",{id:"a",width:20,height:20,x:0,y:0,maskUnits:"userSpaceOnUse",style:{maskType:"alpha"}},E.createElement("path",{d:"M0 20h20v20H0z",transform:"rotate(-90 0 20)"})),E.createElement("g",{mask:"url(#a)"},E.createElement("path",{d:"M15.75 4.5H13v2.75h-1.5V4.5H8.75V3h2.75V.25H13V3h2.75v1.5ZM13 17H5V3h2.25v1.5H6.5v11h5V8.75H13V17Z"}))),y=e=>E.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:20,height:20,fill:"currentColor",viewBox:"0 0 20 20",...e},E.createElement("mask",{id:"a",width:20,height:20,x:0,y:0,maskUnits:"userSpaceOnUse",style:{maskType:"alpha"}},E.createElement("path",{d:"M0 0h20v20H0z",transform:"matrix(0 -1 -1 0 20 20)"})),E.createElement("g",{mask:"url(#a)"},E.createElement("path",{d:"M4.25 4.5H7v2.75h1.5V4.5h2.75V3H8.5V.25H7V3H4.25v1.5ZM7 17h8V3h-2.25v1.5h.75v11h-5V8.75H7V17Z"}))),b=e=>E.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:20,height:20,fill:"currentColor",viewBox:"0 0 20 20",...e},E.createElement("mask",{id:"a",width:20,height:20,x:0,y:0,maskUnits:"userSpaceOnUse",style:{maskType:"alpha"}},E.createElement("path",{d:"M0 0h20v20H0z"})),E.createElement("g",{mask:"url(#a)"},E.createElement("path",{d:"M6.5 17a1.45 1.45 0 0 1-1.06-.44A1.445 1.445 0 0 1 5 15.5v-10H4V4h4V3h4v1h4v1.5h-1v9.991c0 .423-.147.78-.44 1.072A1.45 1.45 0 0 1 13.5 17h-7Zm7-11.5h-7v10h7v-10ZM8 14h1.5V7H8v7Zm2.5 0H12V7h-1.5v7Z"}))),T=e=>E.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:20,height:20,fill:"currentColor",viewBox:"0 0 20 20",...e},E.createElement("mask",{id:"a",width:20,height:20,x:0,y:0,maskUnits:"userSpaceOnUse",style:{maskType:"alpha"}},E.createElement("path",{d:"M0 0h20v20H0z",transform:"matrix(-1 0 0 1 20 0)"})),E.createElement("g",{mask:"url(#a)"},E.createElement("path",{d:"M4.5 16.75V14h2.75v-1.5H4.5V9.75H3v2.75H.25V14H3v2.75h1.5ZM17 14V6H3v2.25h1.5V7.5h11v5H8.75V14H17Z"}))),M=e=>E.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:20,height:20,fill:"currentColor",viewBox:"0 0 20 20",...e},E.createElement("mask",{id:"a",width:20,height:20,x:0,y:0,maskUnits:"userSpaceOnUse",style:{maskType:"alpha"}},E.createElement("path",{d:"M20 20h20v20H20z",transform:"rotate(180 20 20)"})),E.createElement("g",{mask:"url(#a)"},E.createElement("path",{d:"M4.5 3.25V6h2.75v1.5H4.5v2.75H3V7.5H.25V6H3V3.25h1.5ZM17 6v8H3v-2.25h1.5v.75h11v-5H8.75V6H17Z"}))),V=e=>E.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:20,height:20,fill:"currentColor",viewBox:"0 0 20 20",...e},E.createElement("mask",{id:"a",width:20,height:20,x:0,y:0,maskUnits:"userSpaceOnUse",style:{maskType:"alpha"}},E.createElement("path",{d:"M20 20h20v20H20z",transform:"rotate(180 20 20)"})),E.createElement("g",{mask:"url(#a)"},E.createElement("path",{d:"M10.5 3.25V6h2.75v1.5H10.5v2.75H9V7.5H6.25V6H9V3.25h1.5ZM17 6v8H3V6h2.5v1.5h-1v5h11v-5H14V6h3Z"}))),q=e=>E.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:20,height:20,fill:"currentColor",viewBox:"0 0 20 20",...e},E.createElement("mask",{id:"a",width:20,height:20,x:0,y:0,maskUnits:"userSpaceOnUse",style:{maskType:"alpha"}},E.createElement("path",{d:"M0 0h20v20H0z",transform:"matrix(0 -1 -1 0 20 20)"})),E.createElement("g",{mask:"url(#a)"},E.createElement("path",{d:"M3.25 10.5H6v2.75h1.5V10.5h2.75V9H7.5V6.25H6V9H3.25v1.5ZM6 17h8V3H6v2.5h1.5v-1h5v11h-5V14H6v3Z"}))),A={center:i.styles.centeredCell,left:i.styles.leftAlignedCell,right:i.styles.rightAlignedCell},O=({align:e,...t})=>{const[l,r]=t.activeCellTuple,a=l&&l[0]===t.colIndex&&l[1]===t.rowIndex,i=A[e||"left"];return n.createElement("td",{className:i,"data-active":a,onClick:()=>{r([t.colIndex,t.rowIndex])}},a?n.createElement(R,{...t}):n.createElement(x,{mdastChildren:t.contents}))},R=({activeCellTuple:o,parentEditor:c,lexicalTable:s,contents:m,colIndex:u,rowIndex:h})=>{const[d,g,E,v]=i.useEmitterValues("markdownParseOptions","lexicalConvertOptions","jsxComponentDescriptors","lexicalNodes"),[p]=n.useState((()=>{let e=!1;const t=a.createEditor({nodes:v,theme:i.theme});function l(l){e||(e=!0,t.getEditorState().read((()=>{const e=i.exportLexicalTreeToMdast({root:a.$getRoot(),jsxComponentDescriptors:E,...g});c.update((()=>{s.updateCellContents(u,h,e.children[0].children)}))})),o[1](l))}return t.registerCommand(a.KEY_TAB_COMMAND,(e=>{e.preventDefault();return l(e.shiftKey?[u-1,h]:[u+1,h]),!0}),a.COMMAND_PRIORITY_CRITICAL),t.registerCommand(a.KEY_ENTER_COMMAND,(e=>{null==e||e.preventDefault();return l((null==e?void 0:e.shiftKey)?[u,h-1]:[u,h+1]),!0}),a.COMMAND_PRIORITY_CRITICAL),t.registerCommand(a.BLUR_COMMAND,(e=>{const t=e.relatedTarget;return void 0===(null==t?void 0:t.dataset.editorDialog)&&(l(null),!0)}),a.COMMAND_PRIORITY_CRITICAL),t.registerRootListener((e=>{e&&t.focus()})),t.update((()=>{i.importMdastTreeToLexical({root:a.$getRoot(),mdastRoot:{type:"root",children:[{type:"paragraph",children:m}]},visitors:d.visitors})})),t}));return n.createElement(l.LexicalNestedComposer,{initialEditor:p},n.createElement(r.RichTextPlugin,{contentEditable:n.createElement(e.ContentEditable,{autoFocus:!0}),placeholder:n.createElement("div",null),ErrorBoundary:t}),n.createElement(i.SharedHistoryPlugin,null))},N=({parentEditor:e,highlightedCoordinates:t,align:l,lexicalTable:r,colIndex:a,setActiveCellWithBoundaries:o})=>{const[c]=i.useEmitterValues("editorRootElementRef"),s=n.useCallback((t=>{e.update((()=>{r.insertColumnAt(t)})),o([t,0])}),[e,r,o]),m=n.useCallback((t=>{e.update((()=>{r.deleteColumnAt(t)}))}),[e,r]),u=n.useCallback(((t,l)=>{e.update((()=>{r.setColumnAlign(t,l)}))}),[e,r]);return n.createElement(v.Root,null,n.createElement(v.PopoverTrigger,{className:i.styles.tableColumnEditorTrigger,"data-active":t[0]===a+1,title:"Column menu"},n.createElement(w,null)),n.createElement(v.Portal,{container:null==c?void 0:c.current},n.createElement(v.PopoverContent,{className:h(i.styles.tableColumnEditorPopoverContent),onOpenAutoFocus:e=>e.preventDefault(),sideOffset:5,side:"top"},n.createElement(p.Root,{className:i.styles.tableColumnEditorToolbar},n.createElement(p.ToggleGroup,{className:i.styles.toggleGroupRoot,onValueChange:e=>{u(a,e)},value:l||"left",type:"single","aria-label":"Text alignment"},n.createElement(p.ToggleItem,{value:"left",title:"Align left"},n.createElement(C,null)),n.createElement(p.ToggleItem,{value:"center",title:"Align center"},n.createElement(k,null)),n.createElement(p.ToggleItem,{value:"right",title:"Align right"},n.createElement(f,null))),n.createElement(p.Separator,null),n.createElement(p.Button,{onClick:s.bind(null,a),title:"Insert a column to the left of this one"},n.createElement(H,null)),n.createElement(p.Button,{onClick:s.bind(null,a+1),title:"Insert a column to the right of this one"},n.createElement(y,null)),n.createElement(p.Button,{onClick:m.bind(null,a),title:"Delete this column"},n.createElement(b,null))))))},Z=({parentEditor:e,highlightedCoordinates:t,lexicalTable:l,rowIndex:r,setActiveCellWithBoundaries:a})=>{const[o]=i.useEmitterValues("editorRootElementRef"),c=n.useCallback((t=>{e.update((()=>{l.insertRowAt(t)})),a([0,t])}),[e,l,a]),s=n.useCallback((t=>{e.update((()=>{l.deleteRowAt(t)}))}),[e,l]);return n.createElement(v.Root,null,n.createElement(v.PopoverTrigger,{className:i.styles.tableColumnEditorTrigger,"data-active":t[1]===r},n.createElement(w,null)),n.createElement(v.Portal,{container:null==o?void 0:o.current},n.createElement(v.PopoverContent,{className:h(i.styles.tableColumnEditorPopoverContent),onOpenAutoFocus:e=>e.preventDefault(),sideOffset:5,side:"bottom"},n.createElement(p.Root,{className:i.styles.tableColumnEditorToolbar},n.createElement(p.Button,{onClick:c.bind(null,r),title:"Insert a row above this one"},n.createElement(T,null)),n.createElement(p.Button,{onClick:c.bind(null,r+1),title:"Insert a row below this one"},n.createElement(M,null)),n.createElement(p.Button,{onClick:s.bind(null,r),title:"Delete this row"},n.createElement(b,null))))))};exports.TableEditor=({mdastNode:e,parentEditor:t,lexicalTable:l})=>{const[r,o]=n.useState(null),c=n.useCallback((e=>{const r=l.getColCount();if(null===e)return void o(null);let[n,i]=e;return n>r-1&&(n=0,i++),n<0&&(n=r-1,i-=1),i>l.getRowCount()-1?(o(null),void t.update((()=>{if(l.getLatest().getNextSibling())l.getLatest().selectNext();else{const e=a.$createParagraphNode();l.insertAfter(e),e.select()}}))):i<0?(o(null),void t.update((()=>{l.getLatest().selectPrevious()}))):void o([n,i])}),[l,t]);n.useEffect((()=>{l.focusEmitter.subscribe(c)}),[l,c]);const s=n.useCallback((()=>{t.update((()=>{l.addRowToBottom(),o([0,l.getRowCount()])}))}),[t,l]),m=n.useCallback((()=>{t.update((()=>{l.addColumnToRight(),o([l.getColCount(),0])}))}),[t,l]),[u,h]=n.useState([-1,-1]),d=n.useCallback((e=>{let t=e.target;for(;t&&!["TH","TD"].includes(t.tagName);){if(t===e.currentTarget)return;t=t.parentElement}if(null===t)return;const l=t.parentElement,r="TFOOT"===l.parentElement.tagName?-1:Array.from(l.children).indexOf(t),a="TH"===t.tagName?-1:Array.from(l.parentElement.children).indexOf(l);h([r,a])}),[]);return n.createElement("table",{className:i.styles.tableEditor,onMouseOver:d,onMouseLeave:()=>h([-1,-1])},n.createElement("colgroup",null,n.createElement("col",null),Array.from({length:e.children[0].children.length},((t,l)=>{const r=(e.align||[])[l]||"left",a=A[r];return n.createElement("col",{key:l,className:a})})),n.createElement("col",null)),n.createElement("thead",null,n.createElement("tr",null,n.createElement("th",{className:i.styles.tableToolsColumn,"data-tool-cell":!0},n.createElement("button",{className:i.styles.iconButton,title:"Delete table",onClick:()=>{t.update((()=>{l.selectNext(),l.remove()}))}},n.createElement(b,null))),Array.from({length:e.children[0].children.length},((r,a)=>n.createElement("th",{key:a,"data-tool-cell":!0},n.createElement(N,{setActiveCellWithBoundaries:c,parentEditor:t,colIndex:a,highlightedCoordinates:u,lexicalTable:l,align:(e.align||[])[a]})))),n.createElement("th",{className:i.styles.tableToolsColumn}))),n.createElement("tbody",null,e.children.map(((a,o)=>n.createElement("tr",{key:o},n.createElement("td",{className:i.styles.toolCell,"data-tool-cell":!0},n.createElement(Z,{setActiveCellWithBoundaries:c,parentEditor:t,rowIndex:o,highlightedCoordinates:u,lexicalTable:l})),a.children.map(((a,i)=>{var s;return n.createElement(O,{align:null==(s=e.align)?void 0:s[i],key:i,contents:a.children,rowIndex:o,colIndex:i,lexicalTable:l,parentEditor:t,activeCellTuple:[r,c]})})),0===o&&n.createElement("th",{rowSpan:l.getRowCount(),"data-tool-cell":!0},n.createElement("button",{className:i.styles.addColumnButton,onClick:m},n.createElement(q,null))))))),n.createElement("tfoot",null,n.createElement("tr",null,n.createElement("th",null),n.createElement("th",{colSpan:l.getColCount()},n.createElement("button",{className:i.styles.addRowButton,onClick:s},n.createElement(V,null))),n.createElement("th",null))))};