@mdxeditor/editor 3.31.1 → 3.32.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/index.d.ts +7 -0
- package/dist/index.js +2 -1
- package/dist/plugins/image/ImageEditor.js +23 -16
- package/dist/plugins/image/ImagePlaceholder.js +9 -0
- package/dist/plugins/image/index.js +7 -2
- package/dist/style.css +256 -246
- package/dist/styles/ui.module.css.js +96 -93
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1383,6 +1383,12 @@ export declare class ImageNode extends DecoratorNode<JSX.Element> {
|
|
|
1383
1383
|
/* Excluded from this release type: decorate */
|
|
1384
1384
|
}
|
|
1385
1385
|
|
|
1386
|
+
/**
|
|
1387
|
+
* Holds the image placeholder.
|
|
1388
|
+
* @group Image
|
|
1389
|
+
*/
|
|
1390
|
+
export declare const imagePlaceholder$: NodeRef< FC<{}> | null>;
|
|
1391
|
+
|
|
1386
1392
|
/**
|
|
1387
1393
|
* A plugin that adds support for images.
|
|
1388
1394
|
* @group Image
|
|
@@ -1395,6 +1401,7 @@ export declare const imagePlugin: (params?: {
|
|
|
1395
1401
|
imagePreviewHandler?: ImagePreviewHandler | undefined;
|
|
1396
1402
|
ImageDialog?: FC<{}> | (() => JSX.Element) | undefined;
|
|
1397
1403
|
EditImageToolbar?: FC<{}> | (() => JSX.Element) | undefined;
|
|
1404
|
+
imagePlaceholder?: (() => JSX.Element) | null | undefined;
|
|
1398
1405
|
} | undefined) => RealmPlugin;
|
|
1399
1406
|
|
|
1400
1407
|
/**
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { insertThematicBreak$, thematicBreakPlugin } from "./plugins/thematic-br
|
|
|
10
10
|
import { applyListType$, currentListType$, listsPlugin } from "./plugins/lists/index.js";
|
|
11
11
|
import { insertTable$, tablePlugin } from "./plugins/table/index.js";
|
|
12
12
|
import { disableAutoLink$, linkPlugin } from "./plugins/link/index.js";
|
|
13
|
-
import { INSERT_IMAGE_COMMAND, closeImageDialog$, disableImageResize$, disableImageSettingsButton$, editImageToolbarComponent$, imageAutocompleteSuggestions$, imageDialogState$, imagePlugin, imagePreviewHandler$, imageUploadHandler$, insertImage$, openEditImageDialog$, openNewImageDialog$, saveImage$ } from "./plugins/image/index.js";
|
|
13
|
+
import { INSERT_IMAGE_COMMAND, closeImageDialog$, disableImageResize$, disableImageSettingsButton$, editImageToolbarComponent$, imageAutocompleteSuggestions$, imageDialogState$, imagePlaceholder$, imagePlugin, imagePreviewHandler$, imageUploadHandler$, insertImage$, openEditImageDialog$, openNewImageDialog$, saveImage$ } from "./plugins/image/index.js";
|
|
14
14
|
import { frontmatterDialogOpen$, frontmatterPlugin, hasFrontmatter$, insertFrontmatter$, removeFrontmatter$ } from "./plugins/frontmatter/index.js";
|
|
15
15
|
import { quotePlugin } from "./plugins/quote/index.js";
|
|
16
16
|
import { maxLengthPlugin } from "./plugins/maxlength/index.js";
|
|
@@ -236,6 +236,7 @@ export {
|
|
|
236
236
|
iconComponentFor$,
|
|
237
237
|
imageAutocompleteSuggestions$,
|
|
238
238
|
imageDialogState$,
|
|
239
|
+
imagePlaceholder$,
|
|
239
240
|
imagePlugin,
|
|
240
241
|
imagePreviewHandler$,
|
|
241
242
|
imageUploadHandler$,
|
|
@@ -5,24 +5,30 @@ import { mergeRegister } from "@lexical/utils";
|
|
|
5
5
|
import { useCellValues } from "@mdxeditor/gurx";
|
|
6
6
|
import classNames from "classnames";
|
|
7
7
|
import { $isNodeSelection, $getSelection, $getNodeByKey, $setSelection, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_LOW, CLICK_COMMAND, DRAGSTART_COMMAND, KEY_DELETE_COMMAND, KEY_BACKSPACE_COMMAND, KEY_ENTER_COMMAND, KEY_ESCAPE_COMMAND } from "lexical";
|
|
8
|
-
import { disableImageResize$, imagePreviewHandler$, editImageToolbarComponent$ } from "./index.js";
|
|
8
|
+
import { imagePlaceholder$, disableImageResize$, imagePreviewHandler$, editImageToolbarComponent$ } from "./index.js";
|
|
9
9
|
import styles from "../../styles/ui.module.css.js";
|
|
10
10
|
import { readOnly$ } from "../core/index.js";
|
|
11
11
|
import { $isImageNode } from "./ImageNode.js";
|
|
12
12
|
import ImageResizer from "./ImageResizer.js";
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
const imgCache = {
|
|
14
|
+
__cache: {},
|
|
15
|
+
read(src) {
|
|
16
|
+
if (!this.__cache[src]) {
|
|
17
|
+
this.__cache[src] = new Promise((resolve) => {
|
|
18
|
+
const img = new Image();
|
|
19
|
+
img.onload = () => {
|
|
20
|
+
this.__cache[src] = true;
|
|
21
|
+
resolve();
|
|
22
|
+
};
|
|
23
|
+
img.src = src;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (this.__cache[src] instanceof Promise) {
|
|
27
|
+
throw this.__cache[src];
|
|
28
|
+
}
|
|
29
|
+
return this.__cache[src];
|
|
24
30
|
}
|
|
25
|
-
}
|
|
31
|
+
};
|
|
26
32
|
function LazyImage({
|
|
27
33
|
title,
|
|
28
34
|
alt,
|
|
@@ -32,7 +38,7 @@ function LazyImage({
|
|
|
32
38
|
width,
|
|
33
39
|
height
|
|
34
40
|
}) {
|
|
35
|
-
|
|
41
|
+
void imgCache.read(src);
|
|
36
42
|
return /* @__PURE__ */ React__default.createElement(
|
|
37
43
|
"img",
|
|
38
44
|
{
|
|
@@ -48,7 +54,8 @@ function LazyImage({
|
|
|
48
54
|
);
|
|
49
55
|
}
|
|
50
56
|
function ImageEditor({ src, title, alt, nodeKey, width, height, rest }) {
|
|
51
|
-
const [disableImageResize, imagePreviewHandler, readOnly, EditImageToolbar] = useCellValues(
|
|
57
|
+
const [ImagePlaceholderComponent, disableImageResize, imagePreviewHandler, readOnly, EditImageToolbar] = useCellValues(
|
|
58
|
+
imagePlaceholder$,
|
|
52
59
|
disableImageResize$,
|
|
53
60
|
imagePreviewHandler$,
|
|
54
61
|
readOnly$,
|
|
@@ -207,7 +214,7 @@ function ImageEditor({ src, title, alt, nodeKey, width, height, rest }) {
|
|
|
207
214
|
}
|
|
208
215
|
return null;
|
|
209
216
|
}, [rest]);
|
|
210
|
-
return imageSource !== null ? /* @__PURE__ */ React__default.createElement(React__default.Suspense, { fallback: null }, /* @__PURE__ */ React__default.createElement("div", { className: styles.imageWrapper, "data-editor-block-type": "image" }, /* @__PURE__ */ React__default.createElement("div", { draggable }, /* @__PURE__ */ React__default.createElement(
|
|
217
|
+
return imageSource !== null ? /* @__PURE__ */ React__default.createElement(React__default.Suspense, { fallback: ImagePlaceholderComponent ? /* @__PURE__ */ React__default.createElement(ImagePlaceholderComponent, null) : null }, /* @__PURE__ */ React__default.createElement("div", { className: styles.imageWrapper, "data-editor-block-type": "image" }, /* @__PURE__ */ React__default.createElement("div", { draggable }, /* @__PURE__ */ React__default.createElement(
|
|
211
218
|
LazyImage,
|
|
212
219
|
{
|
|
213
220
|
width,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React__default from "react";
|
|
2
|
+
import { ImageIcon } from "@radix-ui/react-icons";
|
|
3
|
+
import styles from "../../styles/ui.module.css.js";
|
|
4
|
+
const ImagePlaceholder = () => {
|
|
5
|
+
return /* @__PURE__ */ React__default.createElement("div", { className: styles.imagePlaceholder }, /* @__PURE__ */ React__default.createElement(ImageIcon, null));
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
ImagePlaceholder
|
|
9
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ImagePlaceholder } from "./ImagePlaceholder.js";
|
|
1
2
|
import { mergeRegister, $wrapNodeInElement } from "@lexical/utils";
|
|
2
3
|
import { Signal, Cell, Action, withLatestFrom, mapTo, map } from "@mdxeditor/gurx";
|
|
3
4
|
import { createCommand, $getNodeByKey, $insertNodes, $isRootOrShadowRoot, $createParagraphNode, COMMAND_PRIORITY_EDITOR, DRAGSTART_COMMAND, COMMAND_PRIORITY_HIGH, DRAGOVER_COMMAND, COMMAND_PRIORITY_LOW, DROP_COMMAND, PASTE_COMMAND, COMMAND_PRIORITY_CRITICAL, $createRangeSelection, $setSelection, $getSelection, $isNodeSelection } from "lexical";
|
|
@@ -38,6 +39,7 @@ const imageAutocompleteSuggestions$ = Cell([]);
|
|
|
38
39
|
const disableImageResize$ = Cell(false);
|
|
39
40
|
const imageUploadHandler$ = Cell(null);
|
|
40
41
|
const imagePreviewHandler$ = Cell(null);
|
|
42
|
+
const imagePlaceholder$ = Cell(null);
|
|
41
43
|
const imageDialogState$ = Cell(
|
|
42
44
|
{ type: "inactive" },
|
|
43
45
|
(r) => {
|
|
@@ -170,7 +172,8 @@ const imagePlugin = realmPlugin({
|
|
|
170
172
|
[disableImageResize$]: Boolean(params == null ? void 0 : params.disableImageResize),
|
|
171
173
|
[disableImageSettingsButton$]: Boolean(params == null ? void 0 : params.disableImageSettingsButton),
|
|
172
174
|
[imagePreviewHandler$]: (params == null ? void 0 : params.imagePreviewHandler) ?? null,
|
|
173
|
-
[editImageToolbarComponent$]: (params == null ? void 0 : params.EditImageToolbar) ?? EditImageToolbar
|
|
175
|
+
[editImageToolbarComponent$]: (params == null ? void 0 : params.EditImageToolbar) ?? EditImageToolbar,
|
|
176
|
+
[imagePlaceholder$]: (params == null ? void 0 : params.imagePlaceholder) ?? ImagePlaceholder
|
|
174
177
|
});
|
|
175
178
|
},
|
|
176
179
|
update(realm, params) {
|
|
@@ -179,7 +182,8 @@ const imagePlugin = realmPlugin({
|
|
|
179
182
|
[imageAutocompleteSuggestions$]: (params == null ? void 0 : params.imageAutocompleteSuggestions) ?? [],
|
|
180
183
|
[disableImageResize$]: Boolean(params == null ? void 0 : params.disableImageResize),
|
|
181
184
|
[imagePreviewHandler$]: (params == null ? void 0 : params.imagePreviewHandler) ?? null,
|
|
182
|
-
[editImageToolbarComponent$]: (params == null ? void 0 : params.EditImageToolbar) ?? EditImageToolbar
|
|
185
|
+
[editImageToolbarComponent$]: (params == null ? void 0 : params.EditImageToolbar) ?? EditImageToolbar,
|
|
186
|
+
[imagePlaceholder$]: (params == null ? void 0 : params.imagePlaceholder) ?? ImagePlaceholder
|
|
183
187
|
});
|
|
184
188
|
}
|
|
185
189
|
});
|
|
@@ -324,6 +328,7 @@ export {
|
|
|
324
328
|
editImageToolbarComponent$,
|
|
325
329
|
imageAutocompleteSuggestions$,
|
|
326
330
|
imageDialogState$,
|
|
331
|
+
imagePlaceholder$,
|
|
327
332
|
imagePlugin,
|
|
328
333
|
imagePreviewHandler$,
|
|
329
334
|
imageUploadHandler$,
|