@mdxeditor/editor 3.31.1 → 3.32.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 CHANGED
@@ -1383,6 +1383,20 @@ 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<typeof ImagePlaceholder | null>;
1391
+
1392
+ declare function ImagePlaceholder(): JSX.Element {
1393
+ return (
1394
+ <div className={styles.imagePlaceholder}>
1395
+ <ImageIcon />
1396
+ </div>
1397
+ )
1398
+ }
1399
+
1386
1400
  /**
1387
1401
  * A plugin that adds support for images.
1388
1402
  * @group Image
@@ -1395,6 +1409,7 @@ export declare const imagePlugin: (params?: {
1395
1409
  imagePreviewHandler?: ImagePreviewHandler | undefined;
1396
1410
  ImageDialog?: FC<{}> | (() => JSX.Element) | undefined;
1397
1411
  EditImageToolbar?: FC<{}> | (() => JSX.Element) | undefined;
1412
+ imagePlaceholder?: (() => JSX.Element) | null | undefined;
1398
1413
  } | undefined) => RealmPlugin;
1399
1414
 
1400
1415
  /**
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$,
@@ -3,26 +3,33 @@ import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext
3
3
  import { useLexicalNodeSelection } from "@lexical/react/useLexicalNodeSelection";
4
4
  import { mergeRegister } from "@lexical/utils";
5
5
  import { useCellValues } from "@mdxeditor/gurx";
6
+ import { ImageIcon } from "@radix-ui/react-icons";
6
7
  import classNames from "classnames";
7
8
  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";
9
+ import { imagePlaceholder$, disableImageResize$, imagePreviewHandler$, editImageToolbarComponent$ } from "./index.js";
9
10
  import styles from "../../styles/ui.module.css.js";
10
11
  import { readOnly$ } from "../core/index.js";
11
12
  import { $isImageNode } from "./ImageNode.js";
12
13
  import ImageResizer from "./ImageResizer.js";
13
- const imageCache = /* @__PURE__ */ new Set();
14
- function useSuspenseImage(src) {
15
- if (!imageCache.has(src)) {
16
- throw new Promise((resolve) => {
17
- const img = new Image();
18
- img.src = src;
19
- img.onerror = img.onload = () => {
20
- imageCache.add(src);
21
- resolve(null);
22
- };
23
- });
14
+ const imgCache = {
15
+ __cache: {},
16
+ read(src) {
17
+ if (!this.__cache[src]) {
18
+ this.__cache[src] = new Promise((resolve) => {
19
+ const img = new Image();
20
+ img.onload = () => {
21
+ this.__cache[src] = true;
22
+ resolve();
23
+ };
24
+ img.src = src;
25
+ });
26
+ }
27
+ if (this.__cache[src] instanceof Promise) {
28
+ throw this.__cache[src];
29
+ }
30
+ return this.__cache[src];
24
31
  }
25
- }
32
+ };
26
33
  function LazyImage({
27
34
  title,
28
35
  alt,
@@ -32,7 +39,7 @@ function LazyImage({
32
39
  width,
33
40
  height
34
41
  }) {
35
- useSuspenseImage(src);
42
+ void imgCache.read(src);
36
43
  return /* @__PURE__ */ React__default.createElement(
37
44
  "img",
38
45
  {
@@ -48,7 +55,8 @@ function LazyImage({
48
55
  );
49
56
  }
50
57
  function ImageEditor({ src, title, alt, nodeKey, width, height, rest }) {
51
- const [disableImageResize, imagePreviewHandler, readOnly, EditImageToolbar] = useCellValues(
58
+ const [ImagePlaceholderComponent, disableImageResize, imagePreviewHandler, readOnly, EditImageToolbar] = useCellValues(
59
+ imagePlaceholder$,
52
60
  disableImageResize$,
53
61
  imagePreviewHandler$,
54
62
  readOnly$,
@@ -207,7 +215,7 @@ function ImageEditor({ src, title, alt, nodeKey, width, height, rest }) {
207
215
  }
208
216
  return null;
209
217
  }, [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(
218
+ 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
219
  LazyImage,
212
220
  {
213
221
  width,
@@ -234,6 +242,10 @@ function ImageEditor({ src, title, alt, nodeKey, width, height, rest }) {
234
242
  }
235
243
  ))) : null;
236
244
  }
245
+ function ImagePlaceholder() {
246
+ return /* @__PURE__ */ React__default.createElement("div", { className: styles.imagePlaceholder }, /* @__PURE__ */ React__default.createElement(ImageIcon, null));
247
+ }
237
248
  export {
238
- ImageEditor
249
+ ImageEditor,
250
+ ImagePlaceholder
239
251
  };
@@ -1,3 +1,4 @@
1
+ import { ImagePlaceholder } from "./ImageEditor.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$,