@mdxeditor/editor 4.0.4 → 4.1.1
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/MDXEditor.js +138 -53
- package/dist/RealmWithPlugins.js +27 -9
- package/dist/exportMarkdownFromLexical.js +1 -1
- package/dist/index.d.ts +12 -10
- package/dist/index.js +6 -6
- package/dist/mdastUtilHtmlComment.js +2 -1
- package/dist/plugins/codeblock/CodeBlockNode.js +4 -5
- package/dist/plugins/codeblock/index.js +1 -1
- package/dist/plugins/codemirror/CodeMirrorEditor.js +1 -1
- package/dist/plugins/core/GenericHTMLNode.js +2 -5
- package/dist/plugins/core/NestedLexicalEditor.js +58 -38
- package/dist/plugins/core/index.js +26 -30
- package/dist/plugins/core/lexicalExtensions.js +143 -0
- package/dist/plugins/diff-source/SourceEditor.js +1 -1
- package/dist/plugins/directives/DirectiveNode.js +1 -4
- package/dist/plugins/frontmatter/FrontmatterNode.js +1 -4
- package/dist/plugins/frontmatter/index.js +1 -1
- package/dist/plugins/headings/index.js +2 -1
- package/dist/plugins/image/ImageDialog.js +1 -2
- package/dist/plugins/image/ImageEditor.js +1 -2
- package/dist/plugins/image/ImageNode.js +1 -4
- package/dist/plugins/image/index.js +4 -6
- package/dist/plugins/jsx/LexicalJsxNode.js +1 -4
- package/dist/plugins/jsx/LexicalMdxExpressionNode.js +1 -4
- package/dist/plugins/link-dialog/LinkDialog.js +3 -3
- package/dist/plugins/link-dialog/index.js +16 -4
- package/dist/plugins/lists/index.js +3 -3
- package/dist/plugins/markdown-shortcut/index.js +1 -1
- package/dist/plugins/search/index.js +259 -179
- package/dist/plugins/table/TableEditor.js +38 -24
- package/dist/plugins/table/TableNode.js +1 -4
- package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.js +2 -2
- package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +1 -1
- package/dist/plugins/toolbar/primitives/toolbar.js +1 -1
- package/dist/realmSession.js +38 -0
- package/dist/style.css +1511 -1525
- package/dist/utils/lexicalHelpers.js +53 -74
- package/package.json +23 -12
- package/dist/plugins/core/SharedHistoryPlugin.js +0 -10
- package/dist/styles/globals.css.js +0 -1
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { ContentEditable } from "@lexical/react/LexicalContentEditable";
|
|
2
2
|
import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
|
|
3
|
-
import {
|
|
3
|
+
import { LexicalExtensionEditorComposer } from "@lexical/react/LexicalExtensionEditorComposer";
|
|
4
4
|
import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
|
|
5
5
|
import * as RadixPopover from "@radix-ui/react-popover";
|
|
6
|
-
import { $createParagraphNode,
|
|
6
|
+
import { $createParagraphNode, $getRoot, KEY_TAB_COMMAND, COMMAND_PRIORITY_CRITICAL, FOCUS_COMMAND, COMMAND_PRIORITY_LOW, KEY_ENTER_COMMAND, BLUR_COMMAND, COMMAND_PRIORITY_EDITOR } from "lexical";
|
|
7
7
|
import React__default from "react";
|
|
8
8
|
import { exportLexicalTreeToMdast } from "../../exportMarkdownFromLexical.js";
|
|
9
9
|
import { importMdastTreeToLexical } from "../../importMarkdownToLexical.js";
|
|
10
|
-
import { lexicalTheme } from "../../styles/lexicalTheme.js";
|
|
11
|
-
import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
|
|
12
10
|
import { mergeRegister } from "@lexical/utils";
|
|
13
11
|
import * as RadixToolbar from "@radix-ui/react-toolbar";
|
|
14
12
|
import classNames from "classnames";
|
|
@@ -17,6 +15,7 @@ import { isPartOftheEditorUI } from "../../utils/isPartOftheEditorUI.js";
|
|
|
17
15
|
import { uuidv4 } from "../../utils/uuid4.js";
|
|
18
16
|
import { iconComponentFor$, readOnly$, useTranslation, editorRootElementRef$, importVisitors$, exportVisitors$, usedLexicalNodes$, jsxComponentDescriptors$, directiveDescriptors$, codeBlockEditorDescriptors$, defaultCodeBlockLanguage$, jsxIsAvailable$, rootEditor$, tableCellEditorChildren$, NESTED_EDITOR_UPDATED_COMMAND } from "../core/index.js";
|
|
19
17
|
import { useCellValues } from "@mdxeditor/gurx";
|
|
18
|
+
import { createExtensionEditor } from "../core/lexicalExtensions.js";
|
|
20
19
|
const getCellType = (rowIndex) => {
|
|
21
20
|
if (rowIndex === 0) {
|
|
22
21
|
return "th";
|
|
@@ -192,7 +191,7 @@ const TableEditor = ({ mdastNode, parentEditor, lexicalTable }) => {
|
|
|
192
191
|
};
|
|
193
192
|
const Cell = ({ align, ...props }) => {
|
|
194
193
|
const { activeCell, setActiveCell } = props;
|
|
195
|
-
const isActive =
|
|
194
|
+
const isActive = (activeCell == null ? void 0 : activeCell[0]) === props.colIndex && activeCell[1] === props.rowIndex;
|
|
196
195
|
const className = AlignToTailwindClassMap[align ?? "left"];
|
|
197
196
|
const CellElement = getCellType(props.rowIndex);
|
|
198
197
|
return /* @__PURE__ */ React__default.createElement(
|
|
@@ -231,27 +230,36 @@ const CellEditor = ({ focus, setActiveCell, parentEditor, lexicalTable, contents
|
|
|
231
230
|
rootEditor$,
|
|
232
231
|
tableCellEditorChildren$
|
|
233
232
|
);
|
|
234
|
-
const [editor] = React__default.useState(
|
|
235
|
-
|
|
233
|
+
const [editor, setEditor] = React__default.useState(null);
|
|
234
|
+
React__default.useEffect(() => {
|
|
235
|
+
const editor2 = createExtensionEditor({
|
|
236
|
+
name: "@mdxeditor/table-cell",
|
|
236
237
|
nodes: usedLexicalNodes,
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
238
|
+
namespace: "TableCellEditor",
|
|
239
|
+
parentEditor,
|
|
240
|
+
historyMode: "table-local",
|
|
241
|
+
initialEditorState: () => {
|
|
242
|
+
importMdastTreeToLexical({
|
|
243
|
+
root: $getRoot(),
|
|
244
|
+
mdastRoot: { type: "root", children: [{ type: "paragraph", children: contents }] },
|
|
245
|
+
visitors: importVisitors,
|
|
246
|
+
jsxComponentDescriptors,
|
|
247
|
+
directiveDescriptors,
|
|
248
|
+
codeBlockEditorDescriptors,
|
|
249
|
+
defaultCodeBlockLanguage
|
|
250
|
+
});
|
|
251
|
+
}
|
|
250
252
|
});
|
|
251
|
-
|
|
252
|
-
|
|
253
|
+
setEditor(editor2);
|
|
254
|
+
return () => {
|
|
255
|
+
editor2.dispose();
|
|
256
|
+
};
|
|
257
|
+
}, []);
|
|
253
258
|
const saveAndFocus = React__default.useCallback(
|
|
254
259
|
(nextCell) => {
|
|
260
|
+
if (!editor) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
255
263
|
editor.getEditorState().read(() => {
|
|
256
264
|
const mdast = exportLexicalTreeToMdast({
|
|
257
265
|
root: $getRoot(),
|
|
@@ -272,6 +280,9 @@ const CellEditor = ({ focus, setActiveCell, parentEditor, lexicalTable, contents
|
|
|
272
280
|
[colIndex, editor, exportVisitors, jsxComponentDescriptors, jsxIsAvailable, lexicalTable, parentEditor, rowIndex, setActiveCell]
|
|
273
281
|
);
|
|
274
282
|
React__default.useEffect(() => {
|
|
283
|
+
if (!editor) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
275
286
|
return mergeRegister(
|
|
276
287
|
editor.registerCommand(
|
|
277
288
|
KEY_TAB_COMMAND,
|
|
@@ -324,11 +335,14 @@ const CellEditor = ({ focus, setActiveCell, parentEditor, lexicalTable, contents
|
|
|
324
335
|
);
|
|
325
336
|
}, [colIndex, editor, rootEditor, rowIndex, saveAndFocus, setActiveCell]);
|
|
326
337
|
React__default.useEffect(() => {
|
|
327
|
-
if (focus) {
|
|
338
|
+
if (focus && editor) {
|
|
328
339
|
editor.focus();
|
|
329
340
|
}
|
|
330
341
|
}, [focus, editor]);
|
|
331
|
-
|
|
342
|
+
if (!editor) {
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
345
|
+
return /* @__PURE__ */ React__default.createElement(LexicalExtensionEditorComposer, { initialEditor: editor }, /* @__PURE__ */ React__default.createElement(RichTextPlugin, { contentEditable: /* @__PURE__ */ React__default.createElement(ContentEditable, null), placeholder: /* @__PURE__ */ React__default.createElement("div", null), ErrorBoundary: LexicalErrorBoundary }), tableCellEditorChildren.map((Child, index) => /* @__PURE__ */ React__default.createElement(Child, { key: index })));
|
|
332
346
|
};
|
|
333
347
|
const ColumnEditor = ({
|
|
334
348
|
parentEditor,
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) =>
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
4
|
import { DecoratorNode } from "lexical";
|
|
8
5
|
import React__default from "react";
|
|
9
6
|
import { noop } from "../../utils/fp.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HorizontalRuleNode } from "@lexical/react/LexicalHorizontalRuleNode.js";
|
|
2
2
|
const LexicalThematicBreakVisitor = {
|
|
3
|
-
testLexicalNode:
|
|
3
|
+
testLexicalNode: (node) => node instanceof HorizontalRuleNode,
|
|
4
4
|
visitLexicalNode({ actions }) {
|
|
5
5
|
actions.addAndStepInto("thematicBreak");
|
|
6
6
|
}
|
|
@@ -18,7 +18,7 @@ import { CreateLink } from "./CreateLink.js";
|
|
|
18
18
|
import { HighlightToggle } from "./HighlightToggle.js";
|
|
19
19
|
function whenInAdmonition(editorInFocus) {
|
|
20
20
|
const node = editorInFocus == null ? void 0 : editorInFocus.rootNode;
|
|
21
|
-
if (
|
|
21
|
+
if ((node == null ? void 0 : node.getType()) !== "directive") {
|
|
22
22
|
return false;
|
|
23
23
|
}
|
|
24
24
|
return ["note", "tip", "danger", "info", "caution"].includes(node.getMdastNode().name);
|
|
@@ -5,7 +5,7 @@ import React__default from "react";
|
|
|
5
5
|
import styles from "../../../styles/ui.module.css.js";
|
|
6
6
|
import { TooltipWrap } from "./TooltipWrap.js";
|
|
7
7
|
import { SelectButtonTrigger, SelectContent, SelectItem } from "./select.js";
|
|
8
|
-
import {
|
|
8
|
+
import { readOnly$, editorInFocus$, useTranslation } from "../../core/index.js";
|
|
9
9
|
import { useCellValue } from "@mdxeditor/gurx";
|
|
10
10
|
function decorateWithRef(Component, decoratedProps) {
|
|
11
11
|
return React__default.forwardRef((props, ref) => {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const realmCleanups = /* @__PURE__ */ new WeakMap();
|
|
2
|
+
function registerRealmCleanup(realm, cleanup) {
|
|
3
|
+
let cleanups = realmCleanups.get(realm);
|
|
4
|
+
if (!cleanups) {
|
|
5
|
+
cleanups = /* @__PURE__ */ new Set();
|
|
6
|
+
realmCleanups.set(realm, cleanups);
|
|
7
|
+
}
|
|
8
|
+
cleanups.add(cleanup);
|
|
9
|
+
return () => {
|
|
10
|
+
cleanups.delete(cleanup);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function disposeRealmSession(realm) {
|
|
14
|
+
const cleanups = realmCleanups.get(realm);
|
|
15
|
+
realmCleanups.delete(realm);
|
|
16
|
+
if (!cleanups) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
let hasError = false;
|
|
20
|
+
let firstError;
|
|
21
|
+
for (const cleanup of [...cleanups].reverse()) {
|
|
22
|
+
try {
|
|
23
|
+
cleanup();
|
|
24
|
+
} catch (error) {
|
|
25
|
+
if (!hasError) {
|
|
26
|
+
hasError = true;
|
|
27
|
+
firstError = error;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (hasError) {
|
|
32
|
+
throw firstError instanceof Error ? firstError : new Error("Realm cleanup failed with a non-Error value");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
disposeRealmSession,
|
|
37
|
+
registerRealmCleanup
|
|
38
|
+
};
|