@mdxeditor/editor 2.20.5 → 2.20.7
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.
|
@@ -7,6 +7,7 @@ var __publicField = (obj, key, value) => {
|
|
|
7
7
|
import { useCellValue } from "@mdxeditor/gurx";
|
|
8
8
|
import { DecoratorNode } from "lexical";
|
|
9
9
|
import React__default from "react";
|
|
10
|
+
import { defaultCodeBlockLanguage$ } from "./index.js";
|
|
10
11
|
import { voidEmitter } from "../../utils/voidEmitter.js";
|
|
11
12
|
import { codeBlockEditorDescriptors$, NESTED_EDITOR_UPDATED_COMMAND } from "../core/index.js";
|
|
12
13
|
class CodeBlockNode extends DecoratorNode {
|
|
@@ -134,7 +135,11 @@ function useCodeBlockEditorContext() {
|
|
|
134
135
|
}
|
|
135
136
|
const CodeBlockEditorContainer = (props) => {
|
|
136
137
|
const codeBlockEditorDescriptors = useCellValue(codeBlockEditorDescriptors$);
|
|
137
|
-
const
|
|
138
|
+
const defaultCodeBlockLanguage = useCellValue(defaultCodeBlockLanguage$);
|
|
139
|
+
let descriptor = codeBlockEditorDescriptors.sort((a, b) => b.priority - a.priority).find((descriptor2) => descriptor2.match(props.language || "", props.meta || ""));
|
|
140
|
+
if (!descriptor) {
|
|
141
|
+
descriptor = codeBlockEditorDescriptors.find((descriptor2) => descriptor2.match(defaultCodeBlockLanguage || "", props.meta || ""));
|
|
142
|
+
}
|
|
138
143
|
if (!descriptor) {
|
|
139
144
|
throw new Error(`No CodeBlockEditor registered for language=${props.language} meta=${props.meta}`);
|
|
140
145
|
}
|
|
@@ -4,7 +4,7 @@ import { $isHeadingNode } from "@lexical/rich-text";
|
|
|
4
4
|
import { $setBlocksType } from "@lexical/selection";
|
|
5
5
|
import { $findMatchingParent, $wrapNodeInElement, $insertNodeToNearestRoot } from "@lexical/utils";
|
|
6
6
|
import { Cell, withLatestFrom, Signal, filter, map, useCellValue, scan } from "@mdxeditor/gurx";
|
|
7
|
-
import { createCommand, FORMAT_TEXT_COMMAND, $isRootOrShadowRoot, $getRoot, $setSelection, $getSelection, $insertNodes, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_CRITICAL, FOCUS_COMMAND, KEY_DOWN_COMMAND, $isDecoratorNode, BLUR_COMMAND, $isRangeSelection,
|
|
7
|
+
import { createCommand, FORMAT_TEXT_COMMAND, $isRootOrShadowRoot, $getRoot, $setSelection, $getSelection, $insertNodes, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_CRITICAL, DecoratorNode, $createParagraphNode, FOCUS_COMMAND, KEY_DOWN_COMMAND, $isDecoratorNode, BLUR_COMMAND, $isRangeSelection, ParagraphNode, TextNode, createEditor } from "lexical";
|
|
8
8
|
import { mdxJsxFromMarkdown, mdxJsxToMarkdown } from "mdast-util-mdx-jsx";
|
|
9
9
|
import { mdxJsx } from "micromark-extension-mdx-jsx";
|
|
10
10
|
import { mdxMd } from "micromark-extension-mdx-md";
|
|
@@ -251,6 +251,15 @@ const createRootEditorSubscription$ = Appender(rootEditorSubscriptions$, (r, sig
|
|
|
251
251
|
}
|
|
252
252
|
let theNewMarkdownValue;
|
|
253
253
|
editorState.read(() => {
|
|
254
|
+
const lastChild = $getRoot().getLastChild();
|
|
255
|
+
if (lastChild instanceof DecoratorNode) {
|
|
256
|
+
rootEditor.update(
|
|
257
|
+
() => {
|
|
258
|
+
$getRoot().append($createParagraphNode());
|
|
259
|
+
},
|
|
260
|
+
{ discrete: true }
|
|
261
|
+
);
|
|
262
|
+
}
|
|
254
263
|
theNewMarkdownValue = exportMarkdownFromLexical({
|
|
255
264
|
root: $getRoot(),
|
|
256
265
|
visitors: r.getValue(exportVisitors$),
|