@mdxeditor/editor 3.32.2 → 3.33.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.
@@ -10,14 +10,27 @@ 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 BROKEN_IMG_URI = "data:image/svg+xml;charset=utf-8," + encodeURIComponent(
14
+ /* xml */
15
+ `
16
+ <svg id="imgLoadError" xmlns="http://www.w3.org/2000/svg" width="100" height="100">
17
+ <rect x="0" y="0" width="100" height="100" fill="none" stroke="red" stroke-width="4" stroke-dasharray="4" />
18
+ <text x="50" y="55" text-anchor="middle" font-size="20" fill="red">⚠️</text>
19
+ </svg>
20
+ `
21
+ );
13
22
  const imgCache = {
14
23
  __cache: {},
15
24
  read(src) {
16
25
  if (!this.__cache[src]) {
17
26
  this.__cache[src] = new Promise((resolve) => {
18
27
  const img = new Image();
28
+ img.onerror = () => {
29
+ this.__cache[src] = BROKEN_IMG_URI;
30
+ resolve();
31
+ };
19
32
  img.onload = () => {
20
- this.__cache[src] = true;
33
+ this.__cache[src] = src;
21
34
  resolve();
22
35
  };
23
36
  img.src = src;
@@ -38,13 +51,12 @@ function LazyImage({
38
51
  width,
39
52
  height
40
53
  }) {
41
- void imgCache.read(src);
42
54
  return /* @__PURE__ */ React__default.createElement(
43
55
  "img",
44
56
  {
45
57
  className: className ?? void 0,
46
58
  alt,
47
- src,
59
+ src: imgCache.read(src),
48
60
  title,
49
61
  ref: imageRef,
50
62
  draggable: "false",
@@ -243,7 +243,16 @@ function onDrop(event, editor, imageUploadHandler) {
243
243
  if (cbPayload.length > 0) {
244
244
  if (imageUploadHandler !== null) {
245
245
  event.preventDefault();
246
- Promise.all(cbPayload.map((image) => imageUploadHandler(image.getAsFile()))).then((urls) => {
246
+ Promise.all(
247
+ cbPayload.map((image) => {
248
+ if (image.kind === "string") {
249
+ return new Promise((rs) => {
250
+ image.getAsString(rs);
251
+ });
252
+ }
253
+ return imageUploadHandler(image.getAsFile());
254
+ })
255
+ ).then((urls) => {
247
256
  urls.forEach((url) => {
248
257
  editor.dispatchCommand(INSERT_IMAGE_COMMAND, {
249
258
  src: url,
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "*.css"
12
12
  ],
13
13
  "type": "module",
14
- "version": "3.32.2",
14
+ "version": "3.33.0",
15
15
  "description": "React component for rich text markdown editing",
16
16
  "scripts": {
17
17
  "build": "vite build",