@mdxeditor/editor 2.0.1 → 2.2.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/index.d.ts +6 -4
- package/dist/plugins/core/index.js +1 -1
- package/dist/plugins/image/index.js +66 -65
- package/package.json +1 -2
package/dist/index.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ import { EditorConfig } from 'lexical';
|
|
|
40
40
|
import { ElementNode } from 'lexical';
|
|
41
41
|
import { Extension } from 'micromark-util-types';
|
|
42
42
|
import { Extension as Extension_2 } from '@codemirror/state';
|
|
43
|
+
import { FC } from 'react';
|
|
43
44
|
import { HeadingTagType } from '@lexical/rich-text';
|
|
44
45
|
import { HistoryState } from '@lexical/history';
|
|
45
46
|
import { InitialEditorStateType } from '@lexical/react/LexicalComposer.js';
|
|
@@ -1191,6 +1192,7 @@ export declare const imagePlugin: (params?: {
|
|
|
1191
1192
|
imageAutocompleteSuggestions?: string[] | undefined;
|
|
1192
1193
|
disableImageResize?: boolean | undefined;
|
|
1193
1194
|
imagePreviewHandler?: ImagePreviewHandler | undefined;
|
|
1195
|
+
ImageDialog?: FC<{}> | (() => JSX.Element) | undefined;
|
|
1194
1196
|
} | undefined) => RealmPlugin;
|
|
1195
1197
|
|
|
1196
1198
|
/**
|
|
@@ -1563,7 +1565,7 @@ export declare interface LexicalConvertOptions {
|
|
|
1563
1565
|
* This is part of the process that converts the editor contents to markdown.
|
|
1564
1566
|
* @group Markdown Processing
|
|
1565
1567
|
*/
|
|
1566
|
-
export declare interface LexicalExportVisitor<LN extends LexicalNode, UN extends Mdast.
|
|
1568
|
+
export declare interface LexicalExportVisitor<LN extends LexicalNode, UN extends Mdast.Nodes> {
|
|
1567
1569
|
/**
|
|
1568
1570
|
* Return true if the given node is of the type that this visitor can process.
|
|
1569
1571
|
* You can safely use the node type guard functions (as in $isParagraphNode, $isLinkNode, etc.) here.
|
|
@@ -1614,12 +1616,12 @@ export declare interface LexicalExportVisitor<LN extends LexicalNode, UN extends
|
|
|
1614
1616
|
* Return true if the current node should be joined with the previous node.
|
|
1615
1617
|
* This is necessary due to some inconsistencies between the lexical tree and the mdast tree when it comes to formatting.
|
|
1616
1618
|
*/
|
|
1617
|
-
shouldJoin?(prevNode: Mdast.
|
|
1619
|
+
shouldJoin?(prevNode: Mdast.RootContent, currentNode: UN): boolean;
|
|
1618
1620
|
/**
|
|
1619
1621
|
* Join the current node with the previous node, returning the resulting new node
|
|
1620
1622
|
* For this to be called by the tree walk, shouldJoin must return true.
|
|
1621
1623
|
*/
|
|
1622
|
-
join?<T extends Mdast.
|
|
1624
|
+
join?<T extends Mdast.RootContent>(prevNode: T, currentNode: T): T;
|
|
1623
1625
|
/**
|
|
1624
1626
|
* Default 0, optional, sets the priority of the visitor. The higher the number, the earlier it will be called.
|
|
1625
1627
|
*/
|
|
@@ -1630,7 +1632,7 @@ export declare interface LexicalExportVisitor<LN extends LexicalNode, UN extends
|
|
|
1630
1632
|
* A generic visitor that can be used to process any lexical node.
|
|
1631
1633
|
* @group Markdown Processing
|
|
1632
1634
|
*/
|
|
1633
|
-
export declare type LexicalVisitor = LexicalExportVisitor<LexicalNode, Mdast.
|
|
1635
|
+
export declare type LexicalVisitor = LexicalExportVisitor<LexicalNode, Mdast.RootContent>;
|
|
1634
1636
|
|
|
1635
1637
|
/* Excluded from this release type: linkAutocompleteSuggestions$ */
|
|
1636
1638
|
|
|
@@ -414,7 +414,7 @@ const viewMode$ = Cell("rich-text", (r) => {
|
|
|
414
414
|
filter((mode) => mode.current === "rich-text"),
|
|
415
415
|
withLatestFrom(activeEditor$)
|
|
416
416
|
),
|
|
417
|
-
([
|
|
417
|
+
([, editor]) => {
|
|
418
418
|
editor == null ? void 0 : editor.dispatchCommand(NESTED_EDITOR_UPDATED_COMMAND, void 0);
|
|
419
419
|
}
|
|
420
420
|
);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $wrapNodeInElement } from "@lexical/utils";
|
|
1
|
+
import { $wrapNodeInElement, mergeRegister } from "@lexical/utils";
|
|
3
2
|
import { Signal, Cell, withLatestFrom, Action, mapTo, map } from "@mdxeditor/gurx";
|
|
4
3
|
import { $getNodeByKey, $insertNodes, $isRootOrShadowRoot, $createParagraphNode, COMMAND_PRIORITY_EDITOR, DRAGSTART_COMMAND, COMMAND_PRIORITY_HIGH, DRAGOVER_COMMAND, COMMAND_PRIORITY_LOW, DROP_COMMAND, PASTE_COMMAND, COMMAND_PRIORITY_CRITICAL, createCommand, $createRangeSelection, $setSelection, $getSelection, $isNodeSelection } from "lexical";
|
|
4
|
+
import { realmPlugin } from "../../RealmWithPlugins.js";
|
|
5
5
|
import { CAN_USE_DOM } from "../../utils/detectMac.js";
|
|
6
|
-
import {
|
|
6
|
+
import { activeEditor$, createActiveEditorSubscription$, addImportVisitor$, addLexicalNode$, addExportVisitor$, addComposerChild$ } from "../core/index.js";
|
|
7
7
|
import { ImageDialog } from "./ImageDialog.js";
|
|
8
8
|
import { $createImageNode, ImageNode, $isImageNode } from "./ImageNode.js";
|
|
9
9
|
import { LexicalImageVisitor } from "./LexicalImageVisitor.js";
|
|
@@ -17,7 +17,7 @@ const imageDialogState$ = Cell(
|
|
|
17
17
|
{ type: "inactive" },
|
|
18
18
|
(r) => {
|
|
19
19
|
r.sub(
|
|
20
|
-
r.pipe(saveImage$, withLatestFrom(
|
|
20
|
+
r.pipe(saveImage$, withLatestFrom(activeEditor$, imageUploadHandler$, imageDialogState$)),
|
|
21
21
|
([values, theEditor, imageUploadHandler, dialogState]) => {
|
|
22
22
|
const handler = dialogState.type === "editing" ? (src) => {
|
|
23
23
|
theEditor == null ? void 0 : theEditor.update(() => {
|
|
@@ -47,67 +47,68 @@ const imageDialogState$ = Cell(
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
);
|
|
50
|
-
r.
|
|
51
|
-
editor == null ? void 0 : editor.registerCommand(
|
|
52
|
-
INSERT_IMAGE_COMMAND,
|
|
53
|
-
(payload) => {
|
|
54
|
-
const imageNode = $createImageNode(payload);
|
|
55
|
-
$insertNodes([imageNode]);
|
|
56
|
-
if ($isRootOrShadowRoot(imageNode.getParentOrThrow())) {
|
|
57
|
-
$wrapNodeInElement(imageNode, $createParagraphNode).selectEnd();
|
|
58
|
-
}
|
|
59
|
-
return true;
|
|
60
|
-
},
|
|
61
|
-
COMMAND_PRIORITY_EDITOR
|
|
62
|
-
);
|
|
50
|
+
r.pub(createActiveEditorSubscription$, (editor) => {
|
|
63
51
|
const theUploadHandler = r.getValue(imageUploadHandler$);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
52
|
+
return mergeRegister(
|
|
53
|
+
editor == null ? void 0 : editor.registerCommand(
|
|
54
|
+
INSERT_IMAGE_COMMAND,
|
|
55
|
+
(payload) => {
|
|
56
|
+
const imageNode = $createImageNode(payload);
|
|
57
|
+
$insertNodes([imageNode]);
|
|
58
|
+
if ($isRootOrShadowRoot(imageNode.getParentOrThrow())) {
|
|
59
|
+
$wrapNodeInElement(imageNode, $createParagraphNode).selectEnd();
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
},
|
|
63
|
+
COMMAND_PRIORITY_EDITOR
|
|
64
|
+
),
|
|
65
|
+
editor == null ? void 0 : editor.registerCommand(
|
|
66
|
+
DRAGSTART_COMMAND,
|
|
67
|
+
(event) => {
|
|
68
|
+
return onDragStart(event);
|
|
69
|
+
},
|
|
70
|
+
COMMAND_PRIORITY_HIGH
|
|
71
|
+
),
|
|
72
|
+
editor == null ? void 0 : editor.registerCommand(
|
|
73
|
+
DRAGOVER_COMMAND,
|
|
74
|
+
(event) => {
|
|
75
|
+
return onDragover(event);
|
|
76
|
+
},
|
|
77
|
+
COMMAND_PRIORITY_LOW
|
|
78
|
+
),
|
|
79
|
+
editor == null ? void 0 : editor.registerCommand(
|
|
80
|
+
DROP_COMMAND,
|
|
81
|
+
(event) => {
|
|
82
|
+
return onDrop(event, editor, r.getValue(imageUploadHandler$));
|
|
83
|
+
},
|
|
84
|
+
COMMAND_PRIORITY_HIGH
|
|
85
|
+
),
|
|
86
|
+
...theUploadHandler !== null ? [
|
|
87
|
+
editor == null ? void 0 : editor.registerCommand(
|
|
88
|
+
PASTE_COMMAND,
|
|
89
|
+
(event) => {
|
|
90
|
+
var _a;
|
|
91
|
+
let cbPayload = Array.from(((_a = event.clipboardData) == null ? void 0 : _a.items) || []);
|
|
92
|
+
cbPayload = cbPayload.filter((i) => /image/.test(i.type));
|
|
93
|
+
if (!cbPayload.length || cbPayload.length === 0) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
const imageUploadHandlerValue = r.getValue(imageUploadHandler$);
|
|
97
|
+
Promise.all(cbPayload.map((file) => imageUploadHandlerValue(file.getAsFile()))).then((urls) => {
|
|
98
|
+
urls.forEach((url) => {
|
|
99
|
+
editor.dispatchCommand(INSERT_IMAGE_COMMAND, {
|
|
100
|
+
src: url,
|
|
101
|
+
altText: ""
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}).catch((e) => {
|
|
105
|
+
throw e;
|
|
103
106
|
});
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
},
|
|
110
|
-
COMMAND_PRIORITY_CRITICAL
|
|
107
|
+
return true;
|
|
108
|
+
},
|
|
109
|
+
COMMAND_PRIORITY_CRITICAL
|
|
110
|
+
)
|
|
111
|
+
] : []
|
|
111
112
|
);
|
|
112
113
|
});
|
|
113
114
|
}
|
|
@@ -129,12 +130,12 @@ const closeImageDialog$ = Action((r) => {
|
|
|
129
130
|
});
|
|
130
131
|
const saveImage$ = Signal();
|
|
131
132
|
const imagePlugin = realmPlugin({
|
|
132
|
-
init(realm) {
|
|
133
|
+
init(realm, params) {
|
|
133
134
|
realm.pubIn({
|
|
134
135
|
[addImportVisitor$]: [MdastImageVisitor, MdastHtmlImageVisitor, MdastJsxImageVisitor],
|
|
135
136
|
[addLexicalNode$]: ImageNode,
|
|
136
137
|
[addExportVisitor$]: LexicalImageVisitor,
|
|
137
|
-
[addComposerChild$]: ImageDialog
|
|
138
|
+
[addComposerChild$]: (params == null ? void 0 : params.ImageDialog) || ImageDialog
|
|
138
139
|
});
|
|
139
140
|
},
|
|
140
141
|
update(realm, params) {
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"*.css"
|
|
12
12
|
],
|
|
13
13
|
"type": "module",
|
|
14
|
-
"version": "2.0
|
|
14
|
+
"version": "2.2.0",
|
|
15
15
|
"description": "React component for rich text markdown editing",
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "vite build",
|
|
@@ -104,7 +104,6 @@
|
|
|
104
104
|
"@types/node": "^20.2.5",
|
|
105
105
|
"@types/react": "^18.2.7",
|
|
106
106
|
"@types/react-dom": "^18.2.4",
|
|
107
|
-
"@types/testing-library__jest-dom": "^6.0.0",
|
|
108
107
|
"@types/unist": "^3.0.2",
|
|
109
108
|
"@typescript-eslint/eslint-plugin": "^6.17.0",
|
|
110
109
|
"@typescript-eslint/parser": "^6.17.0",
|