@mdxeditor/editor 3.25.1 → 3.27.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.
package/dist/MDXEditor.js CHANGED
@@ -1,16 +1,16 @@
1
1
  import { useCellValue, usePublisher, useCellValues, useRealm } from "@mdxeditor/gurx";
2
2
  import React__default from "react";
3
3
  import { RealmWithPlugins } from "./RealmWithPlugins.js";
4
- import { corePlugin, rootEditor$, useTranslation, contentEditableRef$, contentEditableClassName$, spellCheck$, composerChildren$, topAreaChildren$, editorWrappers$, placeholder$, editorRootElementRef$, viewMode$, markdownSourceEditorValue$, markdown$, setMarkdown$, insertMarkdown$ } from "./plugins/core/index.js";
5
- import { ContentEditable } from "@lexical/react/LexicalContentEditable.js";
6
- import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary.js";
7
- import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin.js";
4
+ import { corePlugin, rootEditor$, useTranslation, contentEditableRef$, contentEditableClassName$, spellCheck$, composerChildren$, topAreaChildren$, editorWrappers$, placeholder$, bottomAreaChildren$, editorRootElementRef$, viewMode$, markdownSourceEditorValue$, markdown$, setMarkdown$, insertMarkdown$ } from "./plugins/core/index.js";
5
+ import { ContentEditable } from "@lexical/react/LexicalContentEditable";
6
+ import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
8
7
  import classNames from "classnames";
9
8
  import { lexicalTheme } from "./styles/lexicalTheme.js";
10
9
  import styles from "./styles/ui.module.css.js";
11
10
  import { noop } from "./utils/fp.js";
12
11
  import { createLexicalComposerContext, LexicalComposerContext } from "@lexical/react/LexicalComposerContext";
13
12
  import { defaultSvgIcons } from "./defaultSvgIcons.js";
13
+ import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
14
14
  const LexicalProvider = ({ children }) => {
15
15
  const rootEditor = useCellValue(rootEditor$);
16
16
  const composerContextValue = React__default.useMemo(() => {
@@ -24,13 +24,14 @@ const RichTextEditor = () => {
24
24
  const onRef = (_contentEditableRef) => {
25
25
  setContentEditableRef({ current: _contentEditableRef });
26
26
  };
27
- const [contentEditableClassName, spellCheck, composerChildren, topAreaChildren, editorWrappers, placeholder] = useCellValues(
27
+ const [contentEditableClassName, spellCheck, composerChildren, topAreaChildren, editorWrappers, placeholder, bottomAreaChildren] = useCellValues(
28
28
  contentEditableClassName$,
29
29
  spellCheck$,
30
30
  composerChildren$,
31
31
  topAreaChildren$,
32
32
  editorWrappers$,
33
- placeholder$
33
+ placeholder$,
34
+ bottomAreaChildren$
34
35
  );
35
36
  return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, topAreaChildren.map((Child, index) => /* @__PURE__ */ React__default.createElement(Child, { key: index })), /* @__PURE__ */ React__default.createElement(RenderRecursiveWrappers, { wrappers: editorWrappers }, /* @__PURE__ */ React__default.createElement("div", { className: classNames(styles.rootContentEditableWrapper, "mdxeditor-root-contenteditable") }, /* @__PURE__ */ React__default.createElement(
36
37
  RichTextPlugin,
@@ -46,7 +47,7 @@ const RichTextEditor = () => {
46
47
  placeholder: /* @__PURE__ */ React__default.createElement("div", { className: classNames(styles.contentEditable, styles.placeholder, contentEditableClassName) }, /* @__PURE__ */ React__default.createElement("p", null, placeholder)),
47
48
  ErrorBoundary: LexicalErrorBoundary
48
49
  }
49
- ))), composerChildren.map((Child, index) => /* @__PURE__ */ React__default.createElement(Child, { key: index })));
50
+ ))), composerChildren.map((Child, index) => /* @__PURE__ */ React__default.createElement(Child, { key: index })), bottomAreaChildren.map((Child, index) => /* @__PURE__ */ React__default.createElement(Child, { key: index })));
50
51
  };
51
52
  const DEFAULT_MARKDOWN_OPTIONS = {
52
53
  listItemIndent: "one"
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { Config } from 'mdast-util-from-markdown/lib';
2
- import { ContentEditable } from '@lexical/react/LexicalContentEditable.js';
2
+ import { ContentEditable } from '@lexical/react/LexicalContentEditable';
3
3
  import { DecoratorNode } from 'lexical';
4
4
  import { default as default_2 } from 'react';
5
5
  import { Directives } from 'mdast-util-directive';
6
6
  import { DOMConversionMap } from 'lexical';
7
+ import { DOMConversionOutput } from 'lexical';
7
8
  import { DOMExportOutput } from 'lexical';
8
9
  import { EditorConfig } from 'lexical';
9
10
  import { EditorThemeClasses } from 'lexical';
@@ -18,7 +19,7 @@ import { LexicalCommand } from 'lexical';
18
19
  import { LexicalEditor } from 'lexical';
19
20
  import { LexicalNode } from 'lexical';
20
21
  import { LinkNode } from '@lexical/link';
21
- import { LinkPlugin } from '@lexical/react/LexicalLinkPlugin.js';
22
+ import { LinkPlugin } from '@lexical/react/LexicalLinkPlugin';
22
23
  import { ListType } from '@lexical/list';
23
24
  import * as Mdast from 'mdast';
24
25
  import { MdxJsxAttribute } from 'mdast-util-mdx-jsx';
@@ -45,6 +46,29 @@ import { TextFormatType } from 'lexical';
45
46
  import { TextNode } from 'lexical';
46
47
  import { Options as ToMarkdownOptions } from 'mdast-util-to-markdown';
47
48
 
49
+ /**
50
+ * Converts a <pre> HTML element into a CodeBlockNode.
51
+ * Extracts the code content, language, and meta information from the element's attributes.
52
+ * The language is determined from the class attribute (e.g., class="language-javascript") or
53
+ * the data-language attribute if available.
54
+ *
55
+ * @param element - The <pre> HTML element to convert.
56
+ * @returns A DOMConversionOutput containing the created CodeBlockNode.
57
+ * @group Code Block
58
+ */
59
+ export declare function $convertPreElement(element: Element): DOMConversionOutput;
60
+
61
+ /**
62
+ * Converts an HTML table element into a {@link TableNode}.
63
+ * This function is used to transform a DOM table element into a format that can be used by Lexical.
64
+ * It extracts the rows and cells from the table, converting them into MDAST-compatible nodes.
65
+ *
66
+ * @param element - The HTML table element to convert.
67
+ * @returns A {@link DOMConversionOutput} containing the converted {@link TableNode}.
68
+ * @group Table
69
+ */
70
+ export declare function $convertTableElement(element: HTMLElement): DOMConversionOutput;
71
+
48
72
  /**
49
73
  * Creates a {@link CodeBlockNode}.
50
74
  * @param options - The code contents, the language (i.e. js, jsx, etc.), and the additional meta data of the block.
@@ -139,6 +163,12 @@ export declare const activePlugins$: NodeRef<string[]>;
139
163
  */
140
164
  export declare const addActivePlugin$: NodeRef<string | string[]>;
141
165
 
166
+ /**
167
+ * Lets you add React components below the editor.
168
+ * @group Core
169
+ */
170
+ export declare const addBottomAreaChild$: NodeRef<default_2.ComponentType<{}> | default_2.ComponentType<{}>[]>;
171
+
142
172
  /**
143
173
  * Lets you add React components to the {@link https://lexical.dev/docs/react/plugins | Lexical Composer} element.
144
174
  * @group Core
@@ -302,6 +332,8 @@ export declare interface BoldItalicUnderlineTogglesProps {
302
332
  options?: ('Bold' | 'Italic' | 'Underline')[];
303
333
  }
304
334
 
335
+ /* Excluded from this release type: bottomAreaChildren$ */
336
+
305
337
  /**
306
338
  * A toolbar button primitive.
307
339
  * @group Toolbar Primitives
@@ -501,6 +533,7 @@ export declare class CodeBlockNode extends DecoratorNode<JSX.Element> {
501
533
  static getType(): string;
502
534
  static clone(node: CodeBlockNode): CodeBlockNode;
503
535
  static importJSON(serializedNode: SerializedCodeBlockNode): CodeBlockNode;
536
+ static importDOM(): DOMConversionMap;
504
537
  constructor(code: string, language: string, meta: string, key?: NodeKey);
505
538
  exportJSON(): SerializedCodeBlockNode;
506
539
  createDOM(_config: EditorConfig): HTMLDivElement;
@@ -2708,6 +2741,7 @@ export declare class TableNode extends DecoratorNode<JSX.Element> {
2708
2741
  /* Excluded from this release type: getType */
2709
2742
  /* Excluded from this release type: clone */
2710
2743
  /* Excluded from this release type: importJSON */
2744
+ /* Excluded from this release type: importDOM */
2711
2745
  /* Excluded from this release type: exportJSON */
2712
2746
  /**
2713
2747
  * Returns the mdast node that this node is constructed from.
@@ -2791,8 +2825,18 @@ export declare const toolbarContents$: NodeRef<() => default_2.ReactNode>;
2791
2825
  * @group Toolbar
2792
2826
  */
2793
2827
  export declare const toolbarPlugin: (params?: {
2828
+ /**
2829
+ * Contents of the toolbar
2830
+ */
2794
2831
  toolbarContents: () => default_2.ReactNode;
2832
+ /**
2833
+ * The class name to apply to the toolbar element
2834
+ */
2795
2835
  toolbarClassName?: string | undefined;
2836
+ /**
2837
+ * Controls the position of the toolbar (top by default)
2838
+ */
2839
+ toolbarPosition?: "top" | "bottom" | undefined;
2796
2840
  } | undefined) => RealmPlugin;
2797
2841
 
2798
2842
  /* Excluded from this release type: ToolbarToggleItem */
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import { MDXEditor } from "./MDXEditor.js";
4
4
  import { defaultSvgIcons } from "./defaultSvgIcons.js";
5
5
  import { MarkdownParseError, UnrecognizedMarkdownConstructError, importMarkdownToLexical, importMdastTreeToLexical } from "./importMarkdownToLexical.js";
6
6
  import { exportLexicalTreeToMdast, exportMarkdownFromLexical } from "./exportMarkdownFromLexical.js";
7
- import { Appender, NESTED_EDITOR_UPDATED_COMMAND, activeEditor$, activeEditorSubscriptions$, activePlugins$, addActivePlugin$, addComposerChild$, addEditorWrapper$, addExportVisitor$, addImportVisitor$, addLexicalNode$, addMdastExtension$, addNestedEditorChild$, addSyntaxExtension$, addToMarkdownExtension$, addTopAreaChild$, applyBlockType$, applyFormat$, autoFocus$, codeBlockEditorDescriptors$, composerChildren$, contentEditableClassName$, contentEditableRef$, convertSelectionToNode$, corePlugin, createActiveEditorSubscription$, createRootEditorSubscription$, currentBlockType$, currentFormat$, currentSelection$, directiveDescriptors$, editorInFocus$, editorRootElementRef$, editorWrappers$, exportVisitors$, historyState$, iconComponentFor$, importVisitors$, inFocus$, initialMarkdown$, initialMarkdownNormalize$, insertDecoratorNode$, insertMarkdown$, jsxComponentDescriptors$, jsxIsAvailable$, lexicalTheme$, markdown$, markdownErrorSignal$, markdownProcessingError$, markdownSourceEditorValue$, mdastExtensions$, muteChange$, nestedEditorChildren$, onBlur$, placeholder$, readOnly$, rootEditor$, rootEditorSubscriptions$, setMarkdown$, spellCheck$, syntaxExtensions$, toMarkdownExtensions$, toMarkdownOptions$, topAreaChildren$, translation$, useTranslation, usedLexicalNodes$, viewMode$ } from "./plugins/core/index.js";
7
+ import { Appender, NESTED_EDITOR_UPDATED_COMMAND, activeEditor$, activeEditorSubscriptions$, activePlugins$, addActivePlugin$, addBottomAreaChild$, addComposerChild$, addEditorWrapper$, addExportVisitor$, addImportVisitor$, addLexicalNode$, addMdastExtension$, addNestedEditorChild$, addSyntaxExtension$, addToMarkdownExtension$, addTopAreaChild$, applyBlockType$, applyFormat$, autoFocus$, bottomAreaChildren$, codeBlockEditorDescriptors$, composerChildren$, contentEditableClassName$, contentEditableRef$, convertSelectionToNode$, corePlugin, createActiveEditorSubscription$, createRootEditorSubscription$, currentBlockType$, currentFormat$, currentSelection$, directiveDescriptors$, editorInFocus$, editorRootElementRef$, editorWrappers$, exportVisitors$, historyState$, iconComponentFor$, importVisitors$, inFocus$, initialMarkdown$, initialMarkdownNormalize$, insertDecoratorNode$, insertMarkdown$, jsxComponentDescriptors$, jsxIsAvailable$, lexicalTheme$, markdown$, markdownErrorSignal$, markdownProcessingError$, markdownSourceEditorValue$, mdastExtensions$, muteChange$, nestedEditorChildren$, onBlur$, placeholder$, readOnly$, rootEditor$, rootEditorSubscriptions$, setMarkdown$, spellCheck$, syntaxExtensions$, toMarkdownExtensions$, toMarkdownOptions$, topAreaChildren$, translation$, useTranslation, usedLexicalNodes$, viewMode$ } from "./plugins/core/index.js";
8
8
  import { ALL_HEADING_LEVELS, allowedHeadingLevels$, headingsPlugin } from "./plugins/headings/index.js";
9
9
  import { insertThematicBreak$, thematicBreakPlugin } from "./plugins/thematic-break/index.js";
10
10
  import { applyListType$, currentListType$, listsPlugin } from "./plugins/lists/index.js";
@@ -63,12 +63,14 @@ import { DEFAULT_FORMAT, IS_BOLD, IS_CODE, IS_HIGHLIGHT, IS_ITALIC, IS_STRIKETHR
63
63
  import { lexicalTheme } from "./styles/lexicalTheme.js";
64
64
  import { htmlTags, isMdastHTMLNode } from "./plugins/core/MdastHTMLNode.js";
65
65
  import { $createGenericHTMLNode, $isGenericHTMLNode, GenericHTMLNode, TYPE_NAME } from "./plugins/core/GenericHTMLNode.js";
66
- import { $createTableNode, $isTableNode, TableNode } from "./plugins/table/TableNode.js";
66
+ import { $convertTableElement, $createTableNode, $isTableNode, TableNode } from "./plugins/table/TableNode.js";
67
67
  import { $createImageNode, $isImageNode, ImageNode } from "./plugins/image/ImageNode.js";
68
68
  import { $createFrontmatterNode, $isFrontmatterNode, FrontmatterNode } from "./plugins/frontmatter/FrontmatterNode.js";
69
- import { $createCodeBlockNode, $isCodeBlockNode, CodeBlockNode, useCodeBlockEditorContext } from "./plugins/codeblock/CodeBlockNode.js";
69
+ import { $convertPreElement, $createCodeBlockNode, $isCodeBlockNode, CodeBlockNode, useCodeBlockEditorContext } from "./plugins/codeblock/CodeBlockNode.js";
70
70
  import { $createDirectiveNode, $isDirectiveNode, DirectiveNode } from "./plugins/directives/DirectiveNode.js";
71
71
  export {
72
+ $convertPreElement,
73
+ $convertTableElement,
72
74
  $createCodeBlockNode,
73
75
  $createDirectiveNode,
74
76
  $createFrontmatterNode,
@@ -157,6 +159,7 @@ export {
157
159
  activeEditorSubscriptions$,
158
160
  activePlugins$,
159
161
  addActivePlugin$,
162
+ addBottomAreaChild$,
160
163
  addComposerChild$,
161
164
  addEditorWrapper$,
162
165
  addExportVisitor$,
@@ -176,6 +179,7 @@ export {
176
179
  applyLinkChanges$,
177
180
  applyListType$,
178
181
  autoFocus$,
182
+ bottomAreaChildren$,
179
183
  call,
180
184
  cancelLinkEdit$,
181
185
  closeImageDialog$,
@@ -53,6 +53,16 @@ class CodeBlockNode extends DecoratorNode {
53
53
  meta
54
54
  });
55
55
  }
56
+ static importDOM() {
57
+ return {
58
+ pre: () => {
59
+ return {
60
+ conversion: $convertPreElement,
61
+ priority: 3
62
+ };
63
+ }
64
+ };
65
+ }
56
66
  exportJSON() {
57
67
  return {
58
68
  code: this.getCode(),
@@ -152,7 +162,20 @@ function $createCodeBlockNode(options) {
152
162
  function $isCodeBlockNode(node) {
153
163
  return node instanceof CodeBlockNode;
154
164
  }
165
+ function $convertPreElement(element) {
166
+ const preElement = element;
167
+ const code = preElement.textContent ?? "";
168
+ const classAttribute = element.getAttribute("class") ?? "";
169
+ const dataLanguageAttribute = element.getAttribute("data-language") ?? "";
170
+ const languageMatch = classAttribute.match(/language-(\w+)/);
171
+ const language = languageMatch ? languageMatch[1] : dataLanguageAttribute;
172
+ const meta = preElement.getAttribute("data-meta") ?? "";
173
+ return {
174
+ node: $createCodeBlockNode({ code, language, meta })
175
+ };
176
+ }
155
177
  export {
178
+ $convertPreElement,
156
179
  $createCodeBlockNode,
157
180
  $isCodeBlockNode,
158
181
  CodeBlockNode,
@@ -2,7 +2,7 @@ import { CodeBlockVisitor } from "./CodeBlockVisitor.js";
2
2
  import { MdastCodeVisitor } from "./MdastCodeVisitor.js";
3
3
  import { insertDecoratorNode$, Appender, codeBlockEditorDescriptors$, addActivePlugin$, addImportVisitor$, addLexicalNode$, addExportVisitor$ } from "../core/index.js";
4
4
  import { $createCodeBlockNode, CodeBlockNode } from "./CodeBlockNode.js";
5
- import { $isCodeBlockNode, useCodeBlockEditorContext } from "./CodeBlockNode.js";
5
+ import { $convertPreElement, $isCodeBlockNode, useCodeBlockEditorContext } from "./CodeBlockNode.js";
6
6
  import { Cell, Signal, withLatestFrom, map } from "@mdxeditor/gurx";
7
7
  import { realmPlugin } from "../../RealmWithPlugins.js";
8
8
  const defaultCodeBlockLanguage$ = Cell("");
@@ -34,6 +34,7 @@ const codeBlockPlugin = realmPlugin({
34
34
  }
35
35
  });
36
36
  export {
37
+ $convertPreElement,
37
38
  $createCodeBlockNode,
38
39
  $isCodeBlockNode,
39
40
  CodeBlockNode,
@@ -1,10 +1,10 @@
1
1
  import { $addUpdateTag, $getNodeByKey, createEditor, $getRoot, FOCUS_COMMAND, COMMAND_PRIORITY_LOW, BLUR_COMMAND, COMMAND_PRIORITY_EDITOR, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_HIGH, KEY_BACKSPACE_COMMAND, COMMAND_PRIORITY_CRITICAL } from "lexical";
2
2
  import React__default from "react";
3
3
  import { NESTED_EDITOR_UPDATED_COMMAND, rootEditor$, importVisitors$, exportVisitors$, usedLexicalNodes$, jsxComponentDescriptors$, directiveDescriptors$, codeBlockEditorDescriptors$, jsxIsAvailable$, nestedEditorChildren$, lexicalTheme$, editorInFocus$ } from "./index.js";
4
- import { ContentEditable } from "@lexical/react/LexicalContentEditable.js";
5
- import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary.js";
6
- import { LexicalNestedComposer } from "@lexical/react/LexicalNestedComposer.js";
7
- import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin.js";
4
+ import { ContentEditable } from "@lexical/react/LexicalContentEditable";
5
+ import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
6
+ import { LexicalNestedComposer } from "@lexical/react/LexicalNestedComposer";
7
+ import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
8
8
  import classNames from "classnames";
9
9
  import { exportLexicalTreeToMdast } from "../../exportMarkdownFromLexical.js";
10
10
  import { importMdastTreeToLexical } from "../../importMarkdownToLexical.js";
@@ -1,4 +1,4 @@
1
- import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin.js";
1
+ import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
2
2
  import React__default from "react";
3
3
  import { historyState$ } from "./index.js";
4
4
  import { useCellValue } from "@mdxeditor/gurx";
@@ -391,6 +391,8 @@ const composerChildren$ = Cell([]);
391
391
  const addComposerChild$ = Appender(composerChildren$);
392
392
  const topAreaChildren$ = Cell([]);
393
393
  const addTopAreaChild$ = Appender(topAreaChildren$);
394
+ const bottomAreaChildren$ = Cell([]);
395
+ const addBottomAreaChild$ = Appender(bottomAreaChildren$);
394
396
  const editorWrappers$ = Cell([]);
395
397
  const addEditorWrapper$ = Appender(editorWrappers$);
396
398
  const nestedEditorChildren$ = Cell([]);
@@ -588,6 +590,7 @@ export {
588
590
  activeEditorSubscriptions$,
589
591
  activePlugins$,
590
592
  addActivePlugin$,
593
+ addBottomAreaChild$,
591
594
  addComposerChild$,
592
595
  addEditorWrapper$,
593
596
  addExportVisitor$,
@@ -601,6 +604,7 @@ export {
601
604
  applyBlockType$,
602
605
  applyFormat$,
603
606
  autoFocus$,
607
+ bottomAreaChildren$,
604
608
  codeBlockEditorDescriptors$,
605
609
  composerChildren$,
606
610
  contentEditableClassName$,
@@ -1,6 +1,6 @@
1
1
  import React__default from "react";
2
- import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext.js";
3
- import { useLexicalNodeSelection } from "@lexical/react/useLexicalNodeSelection.js";
2
+ import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
3
+ import { useLexicalNodeSelection } from "@lexical/react/useLexicalNodeSelection";
4
4
  import { mergeRegister } from "@lexical/utils";
5
5
  import classNames from "classnames";
6
6
  import { $isNodeSelection, $getSelection, $getNodeByKey, $setSelection, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_LOW, CLICK_COMMAND, DRAGSTART_COMMAND, KEY_DELETE_COMMAND, KEY_BACKSPACE_COMMAND, KEY_ENTER_COMMAND, KEY_ESCAPE_COMMAND } from "lexical";
@@ -1,4 +1,4 @@
1
- import { createLinkMatcherWithRegExp, AutoLinkPlugin } from "@lexical/react/LexicalAutoLinkPlugin.js";
1
+ import { createLinkMatcherWithRegExp, AutoLinkPlugin } from "@lexical/react/LexicalAutoLinkPlugin";
2
2
  import React__default from "react";
3
3
  const URL_REGEX = /((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;
4
4
  const EMAIL_REGEX = /(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/;
@@ -2,7 +2,7 @@ import React__default from "react";
2
2
  import { MdastLinkVisitor } from "./MdastLinkVisitor.js";
3
3
  import { LexicalLinkVisitor } from "./LexicalLinkVisitor.js";
4
4
  import { LinkNode, AutoLinkNode } from "@lexical/link";
5
- import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin.js";
5
+ import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin";
6
6
  import { LexicalAutoLinkPlugin } from "./AutoLinkPlugin.js";
7
7
  import { Cell } from "@mdxeditor/gurx";
8
8
  import { realmPlugin } from "../../RealmWithPlugins.js";
@@ -1,11 +1,12 @@
1
1
  import { QUOTE, LINK, ORDERED_LIST, UNORDERED_LIST, CHECK_LIST, CODE, BOLD_ITALIC_STAR, BOLD_ITALIC_UNDERSCORE, BOLD_STAR, BOLD_UNDERSCORE, INLINE_CODE, ITALIC_STAR, ITALIC_UNDERSCORE } from "@lexical/markdown";
2
- import { MarkdownShortcutPlugin } from "@lexical/react/LexicalMarkdownShortcutPlugin.js";
2
+ import { MarkdownShortcutPlugin } from "@lexical/react/LexicalMarkdownShortcutPlugin";
3
3
  import { HeadingNode, $isHeadingNode, $createHeadingNode } from "@lexical/rich-text";
4
4
  import React__default from "react";
5
5
  import { realmPlugin } from "../../RealmWithPlugins.js";
6
6
  import { CodeBlockNode, $createCodeBlockNode } from "../codeblock/CodeBlockNode.js";
7
7
  import { activePlugins$, addComposerChild$, addNestedEditorChild$ } from "../core/index.js";
8
8
  import { allowedHeadingLevels$ } from "../headings/index.js";
9
+ import { HorizontalRuleNode, $isHorizontalRuleNode, $createHorizontalRuleNode } from "@lexical/react/LexicalHorizontalRuleNode";
9
10
  const markdownShortcutPlugin = realmPlugin({
10
11
  init(realm) {
11
12
  const pluginIds = realm.getValue(activePlugins$);
@@ -25,6 +26,18 @@ const createBlockNode = (createNode) => {
25
26
  node.select(0, 0);
26
27
  };
27
28
  };
29
+ const THEMATIC_BREAK = {
30
+ dependencies: [HorizontalRuleNode],
31
+ export: (node) => {
32
+ return $isHorizontalRuleNode(node) ? "***" : null;
33
+ },
34
+ regExp: /^(---|\*\*\*|___)?/,
35
+ replace: (parentNode) => {
36
+ const node = $createHorizontalRuleNode();
37
+ parentNode.replace(node);
38
+ },
39
+ type: "element"
40
+ };
28
41
  function pickTransformersForActivePlugins(pluginIds, allowedHeadingLevels) {
29
42
  const transformers = [
30
43
  BOLD_ITALIC_STAR,
@@ -59,6 +72,9 @@ function pickTransformersForActivePlugins(pluginIds, allowedHeadingLevels) {
59
72
  };
60
73
  transformers.push(HEADING);
61
74
  }
75
+ if (pluginIds.includes("thematicBreak")) {
76
+ transformers.push(THEMATIC_BREAK);
77
+ }
62
78
  if (pluginIds.includes("quote")) {
63
79
  transformers.push(QUOTE);
64
80
  }
@@ -1,14 +1,14 @@
1
- import { ContentEditable } from "@lexical/react/LexicalContentEditable.js";
2
- import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary.js";
3
- import { LexicalNestedComposer } from "@lexical/react/LexicalNestedComposer.js";
4
- import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin.js";
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
5
  import * as RadixPopover from "@radix-ui/react-popover";
6
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";
7
7
  import React__default from "react";
8
8
  import { exportLexicalTreeToMdast } from "../../exportMarkdownFromLexical.js";
9
9
  import { importMdastTreeToLexical } from "../../importMarkdownToLexical.js";
10
10
  import { lexicalTheme } from "../../styles/lexicalTheme.js";
11
- import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin.js";
11
+ import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
12
12
  import { mergeRegister } from "@lexical/utils";
13
13
  import * as RadixToolbar from "@radix-ui/react-toolbar";
14
14
  import classNames from "classnames";
@@ -46,6 +46,17 @@ class TableNode extends DecoratorNode {
46
46
  return $createTableNode(serializedNode.mdastNode);
47
47
  }
48
48
  /** @internal */
49
+ static importDOM() {
50
+ return {
51
+ table: () => {
52
+ return {
53
+ conversion: $convertTableElement,
54
+ priority: 3
55
+ };
56
+ }
57
+ };
58
+ }
59
+ /** @internal */
49
60
  exportJSON() {
50
61
  return {
51
62
  mdastNode: structuredClone(this.__mdastNode),
@@ -173,7 +184,33 @@ function $isTableNode(node) {
173
184
  function $createTableNode(mdastNode) {
174
185
  return new TableNode(mdastNode);
175
186
  }
187
+ function $convertTableElement(element) {
188
+ const rows = element.querySelectorAll("tr");
189
+ const children = Array.from(rows).map((row) => {
190
+ return {
191
+ type: "tableRow",
192
+ children: Array.from(row.querySelectorAll("td, th")).map((cell) => {
193
+ return {
194
+ type: "tableCell",
195
+ children: [
196
+ {
197
+ type: "text",
198
+ value: cell.textContent ?? ""
199
+ }
200
+ ]
201
+ };
202
+ })
203
+ };
204
+ });
205
+ return {
206
+ node: new TableNode({
207
+ type: "table",
208
+ children
209
+ })
210
+ };
211
+ }
176
212
  export {
213
+ $convertTableElement,
177
214
  $createTableNode,
178
215
  $isTableNode,
179
216
  TableNode
@@ -6,7 +6,7 @@ import { insertDecoratorNode$, addMdastExtension$, addSyntaxExtension$, addImpor
6
6
  import { LexicalTableVisitor } from "./LexicalTableVisitor.js";
7
7
  import { MdastTableVisitor } from "./MdastTableVisitor.js";
8
8
  import { $createTableNode, TableNode } from "./TableNode.js";
9
- import { $isTableNode } from "./TableNode.js";
9
+ import { $convertTableElement, $isTableNode } from "./TableNode.js";
10
10
  function seedTable(rows = 1, columns = 1) {
11
11
  const table = {
12
12
  type: "table",
@@ -57,6 +57,7 @@ const tablePlugin = realmPlugin({
57
57
  }
58
58
  });
59
59
  export {
60
+ $convertTableElement,
60
61
  $createTableNode,
61
62
  $isTableNode,
62
63
  TableNode,
@@ -2,7 +2,7 @@ import { realmPlugin } from "../../RealmWithPlugins.js";
2
2
  import { INSERT_HORIZONTAL_RULE_COMMAND, HorizontalRuleNode } from "@lexical/react/LexicalHorizontalRuleNode.js";
3
3
  import { HorizontalRulePlugin } from "@lexical/react/LexicalHorizontalRulePlugin.js";
4
4
  import { Action, withLatestFrom } from "@mdxeditor/gurx";
5
- import { activeEditor$, addImportVisitor$, addLexicalNode$, addExportVisitor$, addComposerChild$ } from "../core/index.js";
5
+ import { activeEditor$, addActivePlugin$, addImportVisitor$, addLexicalNode$, addExportVisitor$, addComposerChild$ } from "../core/index.js";
6
6
  import { LexicalThematicBreakVisitor } from "./LexicalThematicBreakVisitor.js";
7
7
  import { MdastThematicBreakVisitor } from "./MdastThematicBreakVisitor.js";
8
8
  const insertThematicBreak$ = Action((r) => {
@@ -13,6 +13,7 @@ const insertThematicBreak$ = Action((r) => {
13
13
  const thematicBreakPlugin = realmPlugin({
14
14
  init(realm) {
15
15
  realm.pubIn({
16
+ [addActivePlugin$]: "thematicBreak",
16
17
  [addImportVisitor$]: MdastThematicBreakVisitor,
17
18
  [addLexicalNode$]: HorizontalRuleNode,
18
19
  [addExportVisitor$]: LexicalThematicBreakVisitor,
@@ -1,7 +1,7 @@
1
1
  import { realmPlugin } from "../../RealmWithPlugins.js";
2
2
  import { Cell, useCellValues } from "@mdxeditor/gurx";
3
3
  import React__default from "react";
4
- import { addTopAreaChild$, readOnly$ } from "../core/index.js";
4
+ import { addBottomAreaChild$, addTopAreaChild$, readOnly$ } from "../core/index.js";
5
5
  import { Root } from "./primitives/toolbar.js";
6
6
  const toolbarContents$ = Cell(() => null);
7
7
  const toolbarClassName$ = Cell("");
@@ -10,10 +10,11 @@ const DEFAULT_TOOLBAR_CONTENTS = () => {
10
10
  };
11
11
  const toolbarPlugin = realmPlugin({
12
12
  init(realm, params) {
13
+ const toolbarPositionSymbol = (params == null ? void 0 : params.toolbarPosition) === "bottom" ? addBottomAreaChild$ : addTopAreaChild$;
13
14
  realm.pubIn({
14
15
  [toolbarContents$]: (params == null ? void 0 : params.toolbarContents) ?? DEFAULT_TOOLBAR_CONTENTS,
15
16
  [toolbarClassName$]: (params == null ? void 0 : params.toolbarClassName) ?? "",
16
- [addTopAreaChild$]: () => {
17
+ [toolbarPositionSymbol]: () => {
17
18
  const [toolbarContents, readOnly, toolbarClassName] = useCellValues(toolbarContents$, readOnly$, toolbarClassName$);
18
19
  return /* @__PURE__ */ React__default.createElement(Root, { className: toolbarClassName, readOnly }, toolbarContents());
19
20
  }
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "*.css"
12
12
  ],
13
13
  "type": "module",
14
- "version": "3.25.1",
14
+ "version": "3.27.0",
15
15
  "description": "React component for rich text markdown editing",
16
16
  "scripts": {
17
17
  "build": "vite build",
@@ -43,15 +43,15 @@
43
43
  "@codemirror/state": "^6.4.0",
44
44
  "@codemirror/view": "^6.23.0",
45
45
  "@codesandbox/sandpack-react": "^2.19.11",
46
- "@lexical/clipboard": "^0.23.1",
47
- "@lexical/link": "^0.23.1",
48
- "@lexical/list": "^0.23.1",
49
- "@lexical/markdown": "^0.23.1",
50
- "@lexical/plain-text": "^0.23.1",
51
- "@lexical/react": "^0.23.1",
52
- "@lexical/rich-text": "^0.23.1",
53
- "@lexical/selection": "^0.23.1",
54
- "@lexical/utils": "^0.23.1",
46
+ "@lexical/clipboard": "^0.27.1",
47
+ "@lexical/link": "^0.27.1",
48
+ "@lexical/list": "^0.27.1",
49
+ "@lexical/markdown": "^0.27.1",
50
+ "@lexical/plain-text": "^0.27.1",
51
+ "@lexical/react": "^0.27.1",
52
+ "@lexical/rich-text": "^0.27.1",
53
+ "@lexical/selection": "^0.27.1",
54
+ "@lexical/utils": "^0.27.1",
55
55
  "@mdxeditor/gurx": "^1.1.4",
56
56
  "@radix-ui/colors": "^3.0.0",
57
57
  "@radix-ui/react-dialog": "^1.0.5",
@@ -66,7 +66,7 @@
66
66
  "codemirror": "^6.0.1",
67
67
  "downshift": "^7.6.0",
68
68
  "js-yaml": "4.1.0",
69
- "lexical": "^0.23.1",
69
+ "lexical": "^0.27.1",
70
70
  "mdast-util-directive": "^3.0.0",
71
71
  "mdast-util-from-markdown": "^2.0.0",
72
72
  "mdast-util-frontmatter": "^2.0.1",