@mdxeditor/editor 3.32.3 → 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] =
|
|
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",
|