@mdxeditor/editor 0.22.2 → 0.22.4
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
|
@@ -8,7 +8,7 @@ import { ContentEditable } from "@lexical/react/LexicalContentEditable.js";
|
|
|
8
8
|
import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary.js";
|
|
9
9
|
import classNames from "classnames";
|
|
10
10
|
import { noop } from "./utils/fp.js";
|
|
11
|
-
import { RealmPluginInitializer } from "./gurx/react.js";
|
|
11
|
+
import { RealmPluginInitializer, useHasPlugin } from "./gurx/react.js";
|
|
12
12
|
const LexicalProvider = ({ children }) => {
|
|
13
13
|
const [initialRootEditorState, nodes, readOnly] = corePluginHooks.useEmitterValues(
|
|
14
14
|
"initialRootEditorState",
|
|
@@ -79,11 +79,17 @@ const EditorRootElement = ({ children, className }) => {
|
|
|
79
79
|
};
|
|
80
80
|
const Methods = ({ mdxRef }) => {
|
|
81
81
|
const realm = corePluginHooks.useRealmContext();
|
|
82
|
+
const hasDiffSourcePlugin = useHasPlugin("diff-source");
|
|
82
83
|
React__default.useImperativeHandle(
|
|
83
84
|
mdxRef,
|
|
84
85
|
() => {
|
|
85
86
|
return {
|
|
86
87
|
getMarkdown: () => {
|
|
88
|
+
if (hasDiffSourcePlugin) {
|
|
89
|
+
if (realm.getKeyValue("viewMode") === "source") {
|
|
90
|
+
return realm.getKeyValue("markdownSourceEditorValue");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
87
93
|
return realm.getKeyValue("markdown");
|
|
88
94
|
},
|
|
89
95
|
setMarkdown: (markdown) => {
|
|
@@ -95,7 +101,7 @@ const Methods = ({ mdxRef }) => {
|
|
|
95
101
|
}
|
|
96
102
|
};
|
|
97
103
|
},
|
|
98
|
-
[realm]
|
|
104
|
+
[realm, hasDiffSourcePlugin]
|
|
99
105
|
);
|
|
100
106
|
return null;
|
|
101
107
|
};
|
|
@@ -2,7 +2,7 @@ import { createEmptyHistoryState } from "@lexical/react/LexicalHistoryPlugin.js"
|
|
|
2
2
|
import { $isHeadingNode } from "@lexical/rich-text";
|
|
3
3
|
import { $setBlocksType } from "@lexical/selection";
|
|
4
4
|
import { $findMatchingParent, $wrapNodeInElement, $insertNodeToNearestRoot } from "@lexical/utils";
|
|
5
|
-
import { createCommand, SELECTION_CHANGE_COMMAND, $getRoot, COMMAND_PRIORITY_CRITICAL, BLUR_COMMAND, KEY_DOWN_COMMAND, FORMAT_TEXT_COMMAND, $isRootOrShadowRoot, $getSelection, $isRangeSelection, $insertNodes, $createParagraphNode, ParagraphNode, TextNode } from "lexical";
|
|
5
|
+
import { createCommand, SELECTION_CHANGE_COMMAND, $getRoot, COMMAND_PRIORITY_CRITICAL, BLUR_COMMAND, KEY_DOWN_COMMAND, $isDecoratorNode, FORMAT_TEXT_COMMAND, $isRootOrShadowRoot, $getSelection, $isRangeSelection, $insertNodes, $createParagraphNode, ParagraphNode, TextNode } from "lexical";
|
|
6
6
|
import { exportMarkdownFromLexical } from "../../exportMarkdownFromLexical.js";
|
|
7
7
|
import { importMarkdownToLexical } from "../../importMarkdownToLexical.js";
|
|
8
8
|
import { LexicalLinebreakVisitor } from "./LexicalLinebreakVisitor.js";
|
|
@@ -198,23 +198,24 @@ const coreSystem = system((r) => {
|
|
|
198
198
|
KEY_DOWN_COMMAND,
|
|
199
199
|
(event) => {
|
|
200
200
|
const { keyCode, ctrlKey, metaKey } = event;
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
});
|
|
206
|
-
if (keyCode === 65 && controlOrMeta(metaKey, ctrlKey) && shouldOverride) {
|
|
207
|
-
event.preventDefault();
|
|
208
|
-
event.stopImmediatePropagation();
|
|
209
|
-
theRootEditor.update(() => {
|
|
210
|
-
var _a;
|
|
211
|
-
const rootElement = theRootEditor.getRootElement();
|
|
212
|
-
(_a = window.getSelection()) == null ? void 0 : _a.selectAllChildren(rootElement);
|
|
213
|
-
rootElement.focus({
|
|
214
|
-
preventScroll: true
|
|
215
|
-
});
|
|
201
|
+
if (keyCode === 65 && controlOrMeta(metaKey, ctrlKey)) {
|
|
202
|
+
let shouldOverride = false;
|
|
203
|
+
theRootEditor.getEditorState().read(() => {
|
|
204
|
+
shouldOverride = $isDecoratorNode($getRoot().getFirstChild()) || $isDecoratorNode($getRoot().getLastChild());
|
|
216
205
|
});
|
|
217
|
-
|
|
206
|
+
if (shouldOverride) {
|
|
207
|
+
event.preventDefault();
|
|
208
|
+
event.stopImmediatePropagation();
|
|
209
|
+
theRootEditor.update(() => {
|
|
210
|
+
var _a;
|
|
211
|
+
const rootElement = theRootEditor.getRootElement();
|
|
212
|
+
(_a = window.getSelection()) == null ? void 0 : _a.selectAllChildren(rootElement);
|
|
213
|
+
rootElement.focus({
|
|
214
|
+
preventScroll: true
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
218
219
|
}
|
|
219
220
|
return false;
|
|
220
221
|
},
|
|
@@ -296,7 +296,7 @@ diffSourcePluginHooks: {
|
|
|
296
296
|
insertDecoratorNode: RealmNode<() => DecoratorNode<unknown>>;
|
|
297
297
|
onBlur: RealmNode<FocusEvent>;
|
|
298
298
|
}>;
|
|
299
|
-
useEmitter: <K extends "jsxComponentDescriptors" | "jsxIsAvailable" | "toMarkdownOptions" | "toMarkdownExtensions" | "mdastExtensions" | "syntaxExtensions" | "markdown" | "activeEditor" | "inFocus" | "historyState" | "currentSelection" | "initialRootEditorState" | "rootEditor" | "createRootEditorSubscription" | "createActiveEditorSubscription" | "importVisitors" | "usedLexicalNodes" | "addImportVisitor" | "addLexicalNode" | "addSyntaxExtension" | "addMdastExtension" | "addToMarkdownExtension" | "addExportVisitor" | "exportVisitors" | "initialMarkdown" | "setMarkdown" | "editorRootElementRef" | "contentEditableClassName" | "placeholder" | "autoFocus" | "readOnly" | "composerChildren" | "addComposerChild" | "topAreaChildren" | "addTopAreaChild" | "nestedEditorChildren" | "addNestedEditorChild" | "editorWrappers" | "addEditorWrapper" | "currentFormat" | "editorInFocus" | "applyFormat" | "currentBlockType" | "applyBlockType" | "convertSelectionToNode" | "insertDecoratorNode" | "onBlur" | "
|
|
299
|
+
useEmitter: <K extends "jsxComponentDescriptors" | "jsxIsAvailable" | "toMarkdownOptions" | "toMarkdownExtensions" | "mdastExtensions" | "syntaxExtensions" | "markdown" | "activeEditor" | "inFocus" | "historyState" | "currentSelection" | "initialRootEditorState" | "rootEditor" | "createRootEditorSubscription" | "createActiveEditorSubscription" | "importVisitors" | "usedLexicalNodes" | "addImportVisitor" | "addLexicalNode" | "addSyntaxExtension" | "addMdastExtension" | "addToMarkdownExtension" | "addExportVisitor" | "exportVisitors" | "initialMarkdown" | "setMarkdown" | "editorRootElementRef" | "contentEditableClassName" | "placeholder" | "autoFocus" | "readOnly" | "composerChildren" | "addComposerChild" | "topAreaChildren" | "addTopAreaChild" | "nestedEditorChildren" | "addNestedEditorChild" | "editorWrappers" | "addEditorWrapper" | "currentFormat" | "editorInFocus" | "applyFormat" | "currentBlockType" | "applyBlockType" | "convertSelectionToNode" | "insertDecoratorNode" | "onBlur" | "markdownSourceEditorValue" | "viewMode" | "diffMarkdown">(key: K, callback: (value: ValueForKey<{
|
|
300
300
|
viewMode: RealmNode<ViewMode>;
|
|
301
301
|
diffMarkdown: RealmNode<string>;
|
|
302
302
|
markdownSourceEditorValue: RealmNode<string>;
|
|
@@ -523,7 +523,7 @@ diffSourcePluginHooks: {
|
|
|
523
523
|
insertDecoratorNode: RealmNode<() => DecoratorNode<unknown>>;
|
|
524
524
|
onBlur: RealmNode<FocusEvent>;
|
|
525
525
|
}>) => void;
|
|
526
|
-
usePublisher: <K_2 extends "jsxComponentDescriptors" | "jsxIsAvailable" | "toMarkdownOptions" | "toMarkdownExtensions" | "mdastExtensions" | "syntaxExtensions" | "markdown" | "activeEditor" | "inFocus" | "historyState" | "currentSelection" | "initialRootEditorState" | "rootEditor" | "createRootEditorSubscription" | "createActiveEditorSubscription" | "importVisitors" | "usedLexicalNodes" | "addImportVisitor" | "addLexicalNode" | "addSyntaxExtension" | "addMdastExtension" | "addToMarkdownExtension" | "addExportVisitor" | "exportVisitors" | "initialMarkdown" | "setMarkdown" | "editorRootElementRef" | "contentEditableClassName" | "placeholder" | "autoFocus" | "readOnly" | "composerChildren" | "addComposerChild" | "topAreaChildren" | "addTopAreaChild" | "nestedEditorChildren" | "addNestedEditorChild" | "editorWrappers" | "addEditorWrapper" | "currentFormat" | "editorInFocus" | "applyFormat" | "currentBlockType" | "applyBlockType" | "convertSelectionToNode" | "insertDecoratorNode" | "onBlur" | "
|
|
526
|
+
usePublisher: <K_2 extends "jsxComponentDescriptors" | "jsxIsAvailable" | "toMarkdownOptions" | "toMarkdownExtensions" | "mdastExtensions" | "syntaxExtensions" | "markdown" | "activeEditor" | "inFocus" | "historyState" | "currentSelection" | "initialRootEditorState" | "rootEditor" | "createRootEditorSubscription" | "createActiveEditorSubscription" | "importVisitors" | "usedLexicalNodes" | "addImportVisitor" | "addLexicalNode" | "addSyntaxExtension" | "addMdastExtension" | "addToMarkdownExtension" | "addExportVisitor" | "exportVisitors" | "initialMarkdown" | "setMarkdown" | "editorRootElementRef" | "contentEditableClassName" | "placeholder" | "autoFocus" | "readOnly" | "composerChildren" | "addComposerChild" | "topAreaChildren" | "addTopAreaChild" | "nestedEditorChildren" | "addNestedEditorChild" | "editorWrappers" | "addEditorWrapper" | "currentFormat" | "editorInFocus" | "applyFormat" | "currentBlockType" | "applyBlockType" | "convertSelectionToNode" | "insertDecoratorNode" | "onBlur" | "markdownSourceEditorValue" | "viewMode" | "diffMarkdown">(key: K_2) => (value: ValueForKey<{
|
|
527
527
|
viewMode: RealmNode<ViewMode>;
|
|
528
528
|
diffMarkdown: RealmNode<string>;
|
|
529
529
|
markdownSourceEditorValue: RealmNode<string>;
|
|
@@ -26,6 +26,7 @@ import { corePluginHooks } from "../core/index.js";
|
|
|
26
26
|
import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin.js";
|
|
27
27
|
import { mergeRegister } from "@lexical/utils";
|
|
28
28
|
import { isPartOftheEditorUI } from "../../utils/isPartOftheEditorUI.js";
|
|
29
|
+
import { uuidv4 } from "../../utils/uuid4.js";
|
|
29
30
|
const AlignToTailwindClassMap = {
|
|
30
31
|
center: styles.centeredCell,
|
|
31
32
|
left: styles.leftAlignedCell,
|
|
@@ -33,6 +34,15 @@ const AlignToTailwindClassMap = {
|
|
|
33
34
|
};
|
|
34
35
|
const TableEditor = ({ mdastNode, parentEditor, lexicalTable }) => {
|
|
35
36
|
const [activeCell, setActiveCell] = React__default.useState(null);
|
|
37
|
+
const getCellKey = React__default.useMemo(() => {
|
|
38
|
+
const cellKeyMap = /* @__PURE__ */ new WeakMap();
|
|
39
|
+
return (cell) => {
|
|
40
|
+
if (!cellKeyMap.has(cell)) {
|
|
41
|
+
cellKeyMap.set(cell, uuidv4());
|
|
42
|
+
}
|
|
43
|
+
return cellKeyMap.get(cell);
|
|
44
|
+
};
|
|
45
|
+
}, []);
|
|
36
46
|
const setActiveCellWithBoundaries = React__default.useCallback(
|
|
37
47
|
(cell) => {
|
|
38
48
|
const colCount = lexicalTable.getColCount();
|
|
@@ -156,7 +166,7 @@ const TableEditor = ({ mdastNode, parentEditor, lexicalTable }) => {
|
|
|
156
166
|
Cell,
|
|
157
167
|
{
|
|
158
168
|
align: (_a = mdastNode.align) == null ? void 0 : _a[colIndex],
|
|
159
|
-
key:
|
|
169
|
+
key: getCellKey(mdastCell),
|
|
160
170
|
contents: mdastCell.children,
|
|
161
171
|
setActiveCell: setActiveCellWithBoundaries,
|
|
162
172
|
...{
|