@mdxeditor/editor 3.9.1 → 3.9.3
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.
|
@@ -51,7 +51,7 @@ const ImageDialog = () => {
|
|
|
51
51
|
},
|
|
52
52
|
className: styles.multiFieldForm
|
|
53
53
|
},
|
|
54
|
-
imageUploadHandler
|
|
54
|
+
imageUploadHandler === null ? /* @__PURE__ */ React__default.createElement("input", { type: "hidden", accept: "image/*", ...register("file") }) : /* @__PURE__ */ React__default.createElement("div", { className: styles.formField }, /* @__PURE__ */ React__default.createElement("label", { htmlFor: "file" }, t("uploadImage.uploadInstructions", "Upload an image from your device:")), /* @__PURE__ */ React__default.createElement("input", { type: "file", accept: "image/*", ...register("file") })),
|
|
55
55
|
/* @__PURE__ */ React__default.createElement("div", { className: styles.formField }, /* @__PURE__ */ React__default.createElement("label", { htmlFor: "src" }, imageUploadHandler !== null ? t("uploadImage.addViaUrlInstructions", "Or add an image from an URL:") : t("uploadImage.addViaUrlInstructionsNoUpload", "Add an image from an URL:")), /* @__PURE__ */ React__default.createElement(
|
|
56
56
|
DownshiftAutoComplete,
|
|
57
57
|
{
|
|
@@ -219,6 +219,7 @@ function ImageEditor({ src, title, alt, nodeKey, width, height }) {
|
|
|
219
219
|
className: styles.iconButton,
|
|
220
220
|
type: "button",
|
|
221
221
|
title: t("image.delete", "Delete image"),
|
|
222
|
+
disabled: readOnly,
|
|
222
223
|
onClick: (e) => {
|
|
223
224
|
e.preventDefault();
|
|
224
225
|
editor.update(() => {
|
|
@@ -35,8 +35,8 @@ class ImageNode extends DecoratorNode {
|
|
|
35
35
|
this.__src = src;
|
|
36
36
|
this.__title = title;
|
|
37
37
|
this.__altText = altText;
|
|
38
|
-
this.__width = width
|
|
39
|
-
this.__height = height
|
|
38
|
+
this.__width = width ? width : "inherit";
|
|
39
|
+
this.__height = height ? height : "inherit";
|
|
40
40
|
}
|
|
41
41
|
/** @internal */
|
|
42
42
|
static getType() {
|
|
@@ -83,9 +83,6 @@ const imageDialogState$ = Cell(
|
|
|
83
83
|
editor.registerCommand(
|
|
84
84
|
DRAGSTART_COMMAND,
|
|
85
85
|
(event) => {
|
|
86
|
-
if (!theUploadHandler) {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
86
|
return onDragStart(event);
|
|
90
87
|
},
|
|
91
88
|
COMMAND_PRIORITY_HIGH
|
|
@@ -93,7 +90,7 @@ const imageDialogState$ = Cell(
|
|
|
93
90
|
editor.registerCommand(
|
|
94
91
|
DRAGOVER_COMMAND,
|
|
95
92
|
(event) => {
|
|
96
|
-
return onDragover(event);
|
|
93
|
+
return onDragover(event, !!theUploadHandler);
|
|
97
94
|
},
|
|
98
95
|
COMMAND_PRIORITY_LOW
|
|
99
96
|
),
|
|
@@ -104,32 +101,38 @@ const imageDialogState$ = Cell(
|
|
|
104
101
|
},
|
|
105
102
|
COMMAND_PRIORITY_HIGH
|
|
106
103
|
),
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
let
|
|
113
|
-
|
|
114
|
-
if (!
|
|
115
|
-
return
|
|
104
|
+
editor.registerCommand(
|
|
105
|
+
PASTE_COMMAND,
|
|
106
|
+
(event) => {
|
|
107
|
+
var _a, _b;
|
|
108
|
+
if (!theUploadHandler) {
|
|
109
|
+
let fromWeb = Array.from(((_a = event.clipboardData) == null ? void 0 : _a.items) ?? []);
|
|
110
|
+
fromWeb = fromWeb.filter((i) => i.type.includes("text"));
|
|
111
|
+
if (!fromWeb.length || fromWeb.length === 0) {
|
|
112
|
+
return true;
|
|
116
113
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
let cbPayload = Array.from(((_b = event.clipboardData) == null ? void 0 : _b.items) ?? []);
|
|
117
|
+
cbPayload = cbPayload.filter((i) => i.type.includes("image"));
|
|
118
|
+
if (!cbPayload.length || cbPayload.length === 0) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
const imageUploadHandlerValue = r.getValue(imageUploadHandler$);
|
|
122
|
+
Promise.all(cbPayload.map((file) => imageUploadHandlerValue(file.getAsFile()))).then((urls) => {
|
|
123
|
+
urls.forEach((url) => {
|
|
124
|
+
editor.dispatchCommand(INSERT_IMAGE_COMMAND, {
|
|
125
|
+
src: url,
|
|
126
|
+
altText: ""
|
|
124
127
|
});
|
|
125
|
-
}).catch((e) => {
|
|
126
|
-
throw e;
|
|
127
128
|
});
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
129
|
+
}).catch((e) => {
|
|
130
|
+
throw e;
|
|
131
|
+
});
|
|
132
|
+
return true;
|
|
133
|
+
},
|
|
134
|
+
COMMAND_PRIORITY_CRITICAL
|
|
135
|
+
)
|
|
133
136
|
);
|
|
134
137
|
});
|
|
135
138
|
}
|
|
@@ -204,13 +207,15 @@ function onDragStart(event) {
|
|
|
204
207
|
);
|
|
205
208
|
return true;
|
|
206
209
|
}
|
|
207
|
-
function onDragover(event) {
|
|
210
|
+
function onDragover(event, hasUploadHandler) {
|
|
208
211
|
var _a;
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
212
|
+
if (hasUploadHandler) {
|
|
213
|
+
let cbPayload = Array.from(((_a = event.dataTransfer) == null ? void 0 : _a.items) ?? []);
|
|
214
|
+
cbPayload = cbPayload.filter((i) => i.type.includes("image"));
|
|
215
|
+
if (cbPayload.length > 0) {
|
|
216
|
+
event.preventDefault();
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
214
219
|
}
|
|
215
220
|
const node = getImageNodeInSelection();
|
|
216
221
|
if (!node) {
|