@mdxeditor/editor 2.2.1 → 2.3.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 +4 -1
- package/dist/index.d.ts +15 -0
- package/dist/index.js +2 -1
- package/dist/plugins/core/index.js +31 -5
- package/dist/plugins/image/index.js +6 -1
- package/dist/plugins/toolbar/index.js +3 -0
- package/package.json +1 -1
package/dist/MDXEditor.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React__default from "react";
|
|
2
|
-
import { corePlugin, initialRootEditorState$, usedLexicalNodes$, readOnly$, contentEditableClassName$, composerChildren$, topAreaChildren$, editorWrappers$, placeholder$, editorRootElementRef$, viewMode$, markdownSourceEditorValue$, markdown$, setMarkdown$, rootEditor$ } from "./plugins/core/index.js";
|
|
2
|
+
import { corePlugin, initialRootEditorState$, usedLexicalNodes$, readOnly$, contentEditableClassName$, composerChildren$, topAreaChildren$, editorWrappers$, placeholder$, editorRootElementRef$, viewMode$, markdownSourceEditorValue$, markdown$, setMarkdown$, insertMarkdown$, rootEditor$ } from "./plugins/core/index.js";
|
|
3
3
|
import { RealmWithPlugins } from "./RealmWithPlugins.js";
|
|
4
4
|
import { useCellValues, usePublisher, useRealm } from "@mdxeditor/gurx";
|
|
5
5
|
import { lexicalTheme } from "./styles/lexicalTheme.js";
|
|
@@ -102,6 +102,9 @@ const Methods = ({ mdxRef }) => {
|
|
|
102
102
|
setMarkdown: (markdown) => {
|
|
103
103
|
realm.pub(setMarkdown$, markdown);
|
|
104
104
|
},
|
|
105
|
+
insertMarkdown: (markdown) => {
|
|
106
|
+
realm.pub(insertMarkdown$, markdown);
|
|
107
|
+
},
|
|
105
108
|
focus: (callbackFn, opts) => {
|
|
106
109
|
var _a;
|
|
107
110
|
(_a = realm.getValue(rootEditor$)) == null ? void 0 : _a.focus(callbackFn, opts);
|
package/dist/index.d.ts
CHANGED
|
@@ -1221,6 +1221,11 @@ export declare type ImageUploadHandler = ((image: File) => Promise<string>) | nu
|
|
|
1221
1221
|
|
|
1222
1222
|
/* Excluded from this release type: importMdastTreeToLexical */
|
|
1223
1223
|
|
|
1224
|
+
export declare interface ImportPoint {
|
|
1225
|
+
append(node: LexicalNode): void;
|
|
1226
|
+
getType(): string;
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1224
1229
|
/* Excluded from this release type: importVisitors$ */
|
|
1225
1230
|
|
|
1226
1231
|
/**
|
|
@@ -1355,6 +1360,12 @@ export declare const insertJsx$: NodeRef<{
|
|
|
1355
1360
|
children?: (Mdast.BlockContent | Mdast.DefinitionContent)[] | undefined;
|
|
1356
1361
|
}>;
|
|
1357
1362
|
|
|
1363
|
+
/**
|
|
1364
|
+
* Inserts new markdown value into the current cursor position of the active editor.
|
|
1365
|
+
* @group Core
|
|
1366
|
+
*/
|
|
1367
|
+
export declare const insertMarkdown$: NodeRef<string>;
|
|
1368
|
+
|
|
1358
1369
|
/**
|
|
1359
1370
|
* A signal that inserts a new sandpack code block with the specified name from the {@link SandpackConfig}.
|
|
1360
1371
|
* If no name is specified, the default preset will be used.
|
|
@@ -1840,6 +1851,10 @@ export declare interface MDXEditorMethods {
|
|
|
1840
1851
|
* Updates the markdown value of the editor.
|
|
1841
1852
|
*/
|
|
1842
1853
|
setMarkdown: (value: string) => void;
|
|
1854
|
+
/**
|
|
1855
|
+
* Inserts markdown at the current cursor position. Use the focus if necessary.
|
|
1856
|
+
*/
|
|
1857
|
+
insertMarkdown: (value: string) => void;
|
|
1843
1858
|
/**
|
|
1844
1859
|
* Sets focus on input
|
|
1845
1860
|
*/
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export * from "@mdxeditor/gurx";
|
|
|
3
3
|
import { MDXEditor } from "./MDXEditor.js";
|
|
4
4
|
import { MarkdownParseError, UnrecognizedMarkdownConstructError, importMarkdownToLexical, importMdastTreeToLexical } from "./importMarkdownToLexical.js";
|
|
5
5
|
import { exportLexicalTreeToMdast, exportMarkdownFromLexical } from "./exportMarkdownFromLexical.js";
|
|
6
|
-
import { Appender, NESTED_EDITOR_UPDATED_COMMAND, activeEditor$, activeEditorSubscriptions$, activePlugins$, addActivePlugin$, addComposerChild$, addEditorWrapper$, addExportVisitor$, addImportVisitor$, addLexicalNode$, addMdastExtension$, addNestedEditorChild$, addSyntaxExtension$, addToMarkdownExtension$, addTopAreaChild$, applyBlockType$, applyFormat$, autoFocus$, composerChildren$, contentEditableClassName$, convertSelectionToNode$, corePlugin, createActiveEditorSubscription$, createRootEditorSubscription$, currentBlockType$, currentFormat$, currentSelection$, editorInFocus$, editorRootElementRef$, editorWrappers$, exportVisitors$, historyState$, iconComponentFor$, importVisitors$, inFocus$, initialMarkdown$, initialRootEditorState$, insertDecoratorNode$, jsxComponentDescriptors$, jsxIsAvailable$, markdown$, markdownErrorSignal$, markdownProcessingError$, markdownSourceEditorValue$, mdastExtensions$, nestedEditorChildren$, onBlur$, placeholder$, readOnly$, rootEditor$, rootEditorSubscriptions$, setMarkdown$, syntaxExtensions$, toMarkdownExtensions$, toMarkdownOptions$, topAreaChildren$, usedLexicalNodes$, viewMode$ } from "./plugins/core/index.js";
|
|
6
|
+
import { Appender, NESTED_EDITOR_UPDATED_COMMAND, activeEditor$, activeEditorSubscriptions$, activePlugins$, addActivePlugin$, addComposerChild$, addEditorWrapper$, addExportVisitor$, addImportVisitor$, addLexicalNode$, addMdastExtension$, addNestedEditorChild$, addSyntaxExtension$, addToMarkdownExtension$, addTopAreaChild$, applyBlockType$, applyFormat$, autoFocus$, composerChildren$, contentEditableClassName$, convertSelectionToNode$, corePlugin, createActiveEditorSubscription$, createRootEditorSubscription$, currentBlockType$, currentFormat$, currentSelection$, editorInFocus$, editorRootElementRef$, editorWrappers$, exportVisitors$, historyState$, iconComponentFor$, importVisitors$, inFocus$, initialMarkdown$, initialRootEditorState$, insertDecoratorNode$, insertMarkdown$, jsxComponentDescriptors$, jsxIsAvailable$, markdown$, markdownErrorSignal$, markdownProcessingError$, markdownSourceEditorValue$, mdastExtensions$, nestedEditorChildren$, onBlur$, placeholder$, readOnly$, rootEditor$, rootEditorSubscriptions$, setMarkdown$, syntaxExtensions$, toMarkdownExtensions$, toMarkdownOptions$, topAreaChildren$, usedLexicalNodes$, viewMode$ } from "./plugins/core/index.js";
|
|
7
7
|
import { ALL_HEADING_LEVELS, allowedHeadingLevels$, headingsPlugin } from "./plugins/headings/index.js";
|
|
8
8
|
import { insertThematicBreak$, thematicBreakPlugin } from "./plugins/thematic-break/index.js";
|
|
9
9
|
import { applyListType$, currentListType$, listsPlugin } from "./plugins/lists/index.js";
|
|
@@ -220,6 +220,7 @@ export {
|
|
|
220
220
|
insertFrontmatter$,
|
|
221
221
|
insertImage$,
|
|
222
222
|
insertJsx$,
|
|
223
|
+
insertMarkdown$,
|
|
223
224
|
insertSandpack$,
|
|
224
225
|
insertTable$,
|
|
225
226
|
insertThematicBreak$,
|
|
@@ -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, scan } from "@mdxeditor/gurx";
|
|
7
|
-
import { createCommand, FORMAT_TEXT_COMMAND, $isRootOrShadowRoot, $getRoot, $setSelection, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_CRITICAL, FOCUS_COMMAND, KEY_DOWN_COMMAND, $isDecoratorNode, BLUR_COMMAND, $
|
|
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, $createParagraphNode, ParagraphNode, TextNode } 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";
|
|
@@ -110,7 +110,7 @@ const setMarkdown$ = Signal((r) => {
|
|
|
110
110
|
([theNewMarkdownValue, , editor, inFocus]) => {
|
|
111
111
|
editor == null ? void 0 : editor.update(() => {
|
|
112
112
|
$getRoot().clear();
|
|
113
|
-
tryImportingMarkdown(r, theNewMarkdownValue);
|
|
113
|
+
tryImportingMarkdown(r, $getRoot(), theNewMarkdownValue);
|
|
114
114
|
if (!inFocus) {
|
|
115
115
|
$setSelection(null);
|
|
116
116
|
} else {
|
|
@@ -120,6 +120,31 @@ const setMarkdown$ = Signal((r) => {
|
|
|
120
120
|
}
|
|
121
121
|
);
|
|
122
122
|
});
|
|
123
|
+
const insertMarkdown$ = Signal((r) => {
|
|
124
|
+
r.sub(r.pipe(insertMarkdown$, withLatestFrom(activeEditor$, inFocus$)), ([markdownToInsert, editor, inFocus]) => {
|
|
125
|
+
editor == null ? void 0 : editor.update(() => {
|
|
126
|
+
const selection = $getSelection();
|
|
127
|
+
if (selection !== null) {
|
|
128
|
+
const importPoint = {
|
|
129
|
+
children: [],
|
|
130
|
+
append(node) {
|
|
131
|
+
this.children.push(node);
|
|
132
|
+
},
|
|
133
|
+
getType() {
|
|
134
|
+
return selection == null ? void 0 : selection.getNodes()[0].getType();
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
tryImportingMarkdown(r, importPoint, markdownToInsert);
|
|
138
|
+
$insertNodes(importPoint.children);
|
|
139
|
+
}
|
|
140
|
+
if (!inFocus) {
|
|
141
|
+
$setSelection(null);
|
|
142
|
+
} else {
|
|
143
|
+
editor.focus();
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
});
|
|
123
148
|
function rebind() {
|
|
124
149
|
return scan((teardowns, [subs, activeEditorValue]) => {
|
|
125
150
|
teardowns.forEach((teardown) => {
|
|
@@ -289,10 +314,10 @@ const createActiveEditorSubscription$ = Appender(activeEditorSubscriptions$, (r,
|
|
|
289
314
|
}
|
|
290
315
|
]);
|
|
291
316
|
});
|
|
292
|
-
function tryImportingMarkdown(r, markdownValue) {
|
|
317
|
+
function tryImportingMarkdown(r, node, markdownValue) {
|
|
293
318
|
try {
|
|
294
319
|
importMarkdownToLexical({
|
|
295
|
-
root:
|
|
320
|
+
root: node,
|
|
296
321
|
visitors: r.getValue(importVisitors$),
|
|
297
322
|
mdastExtensions: r.getValue(mdastExtensions$),
|
|
298
323
|
markdown: markdownValue,
|
|
@@ -317,7 +342,7 @@ const initialRootEditorState$ = Cell(null, (r) => {
|
|
|
317
342
|
r.pub(initialRootEditorState$, (theRootEditor) => {
|
|
318
343
|
r.pub(rootEditor$, theRootEditor);
|
|
319
344
|
r.pub(activeEditor$, theRootEditor);
|
|
320
|
-
tryImportingMarkdown(r, r.getValue(initialMarkdown$));
|
|
345
|
+
tryImportingMarkdown(r, $getRoot(), r.getValue(initialMarkdown$));
|
|
321
346
|
const autoFocusValue = r.getValue(autoFocus$);
|
|
322
347
|
if (autoFocusValue) {
|
|
323
348
|
if (autoFocusValue === true) {
|
|
@@ -516,6 +541,7 @@ export {
|
|
|
516
541
|
initialMarkdown$,
|
|
517
542
|
initialRootEditorState$,
|
|
518
543
|
insertDecoratorNode$,
|
|
544
|
+
insertMarkdown$,
|
|
519
545
|
jsxComponentDescriptors$,
|
|
520
546
|
jsxIsAvailable$,
|
|
521
547
|
markdown$,
|
|
@@ -49,6 +49,7 @@ const imageDialogState$ = Cell(
|
|
|
49
49
|
);
|
|
50
50
|
r.pub(createActiveEditorSubscription$, (editor) => {
|
|
51
51
|
const theUploadHandler = r.getValue(imageUploadHandler$);
|
|
52
|
+
console.log("theUploadHandler", theUploadHandler);
|
|
52
53
|
return mergeRegister(
|
|
53
54
|
editor == null ? void 0 : editor.registerCommand(
|
|
54
55
|
INSERT_IMAGE_COMMAND,
|
|
@@ -135,7 +136,11 @@ const imagePlugin = realmPlugin({
|
|
|
135
136
|
[addImportVisitor$]: [MdastImageVisitor, MdastHtmlImageVisitor, MdastJsxImageVisitor],
|
|
136
137
|
[addLexicalNode$]: ImageNode,
|
|
137
138
|
[addExportVisitor$]: LexicalImageVisitor,
|
|
138
|
-
[addComposerChild$]: (params == null ? void 0 : params.ImageDialog) || ImageDialog
|
|
139
|
+
[addComposerChild$]: (params == null ? void 0 : params.ImageDialog) || ImageDialog,
|
|
140
|
+
[imageUploadHandler$]: (params == null ? void 0 : params.imageUploadHandler) || null,
|
|
141
|
+
[imageAutocompleteSuggestions$]: (params == null ? void 0 : params.imageAutocompleteSuggestions) || [],
|
|
142
|
+
[disableImageResize$]: Boolean(params == null ? void 0 : params.disableImageResize),
|
|
143
|
+
[imagePreviewHandler$]: (params == null ? void 0 : params.imagePreviewHandler) || null
|
|
139
144
|
});
|
|
140
145
|
},
|
|
141
146
|
update(realm, params) {
|
|
@@ -16,6 +16,9 @@ const toolbarPlugin = realmPlugin({
|
|
|
16
16
|
return /* @__PURE__ */ React__default.createElement(Root, { readOnly }, toolbarContents());
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
|
+
},
|
|
20
|
+
update(realm, params) {
|
|
21
|
+
realm.pub(toolbarContents$, (params == null ? void 0 : params.toolbarContents) ?? DEFAULT_TOOLBAR_CONTENTS);
|
|
19
22
|
}
|
|
20
23
|
});
|
|
21
24
|
export {
|