@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.
Files changed (40) hide show
  1. package/dist/MDXEditor.js +138 -53
  2. package/dist/RealmWithPlugins.js +27 -9
  3. package/dist/exportMarkdownFromLexical.js +1 -1
  4. package/dist/index.d.ts +12 -10
  5. package/dist/index.js +6 -6
  6. package/dist/mdastUtilHtmlComment.js +2 -1
  7. package/dist/plugins/codeblock/CodeBlockNode.js +4 -5
  8. package/dist/plugins/codeblock/index.js +1 -1
  9. package/dist/plugins/codemirror/CodeMirrorEditor.js +1 -1
  10. package/dist/plugins/core/GenericHTMLNode.js +2 -5
  11. package/dist/plugins/core/NestedLexicalEditor.js +58 -38
  12. package/dist/plugins/core/index.js +26 -30
  13. package/dist/plugins/core/lexicalExtensions.js +143 -0
  14. package/dist/plugins/diff-source/SourceEditor.js +1 -1
  15. package/dist/plugins/directives/DirectiveNode.js +1 -4
  16. package/dist/plugins/frontmatter/FrontmatterNode.js +1 -4
  17. package/dist/plugins/frontmatter/index.js +1 -1
  18. package/dist/plugins/headings/index.js +2 -1
  19. package/dist/plugins/image/ImageDialog.js +1 -2
  20. package/dist/plugins/image/ImageEditor.js +1 -2
  21. package/dist/plugins/image/ImageNode.js +1 -4
  22. package/dist/plugins/image/index.js +4 -6
  23. package/dist/plugins/jsx/LexicalJsxNode.js +1 -4
  24. package/dist/plugins/jsx/LexicalMdxExpressionNode.js +1 -4
  25. package/dist/plugins/link-dialog/LinkDialog.js +3 -3
  26. package/dist/plugins/link-dialog/index.js +16 -4
  27. package/dist/plugins/lists/index.js +3 -3
  28. package/dist/plugins/markdown-shortcut/index.js +1 -1
  29. package/dist/plugins/search/index.js +259 -179
  30. package/dist/plugins/table/TableEditor.js +38 -24
  31. package/dist/plugins/table/TableNode.js +1 -4
  32. package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.js +2 -2
  33. package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +1 -1
  34. package/dist/plugins/toolbar/primitives/toolbar.js +1 -1
  35. package/dist/realmSession.js +38 -0
  36. package/dist/style.css +1511 -1525
  37. package/dist/utils/lexicalHelpers.js +53 -74
  38. package/package.json +23 -12
  39. package/dist/plugins/core/SharedHistoryPlugin.js +0 -10
  40. 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 { LexicalNestedComposer } from "@lexical/react/LexicalNestedComposer";
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, createEditor, $getRoot, KEY_TAB_COMMAND, COMMAND_PRIORITY_CRITICAL, FOCUS_COMMAND, COMMAND_PRIORITY_LOW, KEY_ENTER_COMMAND, BLUR_COMMAND, COMMAND_PRIORITY_EDITOR } from "lexical";
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 = Boolean(activeCell && activeCell[0] === props.colIndex && activeCell[1] === props.rowIndex);
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
- const editor2 = createEditor({
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
- theme: lexicalTheme,
238
- namespace: "TableCellEditor"
239
- });
240
- editor2.update(() => {
241
- importMdastTreeToLexical({
242
- root: $getRoot(),
243
- mdastRoot: { type: "root", children: [{ type: "paragraph", children: contents }] },
244
- visitors: importVisitors,
245
- jsxComponentDescriptors,
246
- directiveDescriptors,
247
- codeBlockEditorDescriptors,
248
- defaultCodeBlockLanguage
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
- return editor2;
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
- return /* @__PURE__ */ React__default.createElement(LexicalNestedComposer, { 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 })), /* @__PURE__ */ React__default.createElement(HistoryPlugin, null));
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 { $isHorizontalRuleNode } from "@lexical/react/LexicalHorizontalRuleNode.js";
1
+ import { HorizontalRuleNode } from "@lexical/react/LexicalHorizontalRuleNode.js";
2
2
  const LexicalThematicBreakVisitor = {
3
- testLexicalNode: $isHorizontalRuleNode,
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 (!node || node.getType() !== "directive") {
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 { useTranslation, readOnly$, editorInFocus$ } from "../../core/index.js";
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
+ };