@mdxeditor/editor 2.1.0 → 2.2.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/plugins/image/index.js +64 -63
- package/dist/plugins/jsx/index.js +3 -2
- package/package.json +2 -2
|
@@ -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
|
}
|
|
@@ -46,7 +46,7 @@ const insertJsx$ = Signal((r) => {
|
|
|
46
46
|
);
|
|
47
47
|
});
|
|
48
48
|
const jsxPlugin = realmPlugin({
|
|
49
|
-
init: (realm) => {
|
|
49
|
+
init: (realm, params) => {
|
|
50
50
|
realm.pubIn({
|
|
51
51
|
// import
|
|
52
52
|
[jsxIsAvailable$]: true,
|
|
@@ -56,7 +56,8 @@ const jsxPlugin = realmPlugin({
|
|
|
56
56
|
// export
|
|
57
57
|
[addLexicalNode$]: LexicalJsxNode,
|
|
58
58
|
[addExportVisitor$]: LexicalJsxVisitor,
|
|
59
|
-
[addToMarkdownExtension$]: mdxToMarkdown()
|
|
59
|
+
[addToMarkdownExtension$]: mdxToMarkdown(),
|
|
60
|
+
[jsxComponentDescriptors$]: (params == null ? void 0 : params.jsxComponentDescriptors) || []
|
|
60
61
|
});
|
|
61
62
|
},
|
|
62
63
|
update(realm, params) {
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"*.css"
|
|
12
12
|
],
|
|
13
13
|
"type": "module",
|
|
14
|
-
"version": "2.1
|
|
14
|
+
"version": "2.2.1",
|
|
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",
|
|
@@ -125,6 +124,7 @@
|
|
|
125
124
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
126
125
|
"express": "^4.18.2",
|
|
127
126
|
"jsdom": "^23.0.1",
|
|
127
|
+
"mermaid": "^10.6.1",
|
|
128
128
|
"micromark-util-types": "^2.0.0",
|
|
129
129
|
"multer": "1.4.5-lts.1",
|
|
130
130
|
"postcss": "^8.4.24",
|