@seafile/sdoc-editor 1.0.218-test-0.0.1 → 1.0.219
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.
|
@@ -62,7 +62,6 @@ const Image = _ref => {
|
|
|
62
62
|
const [caption, setCaption] = (0, _react.useState)((data === null || data === void 0 ? void 0 : data.caption) || '');
|
|
63
63
|
const [isLoading, setIsLoading] = (0, _react.useState)(false);
|
|
64
64
|
const [isCopyError, setIsCopyError] = (0, _react.useState)(false);
|
|
65
|
-
console.log(data);
|
|
66
65
|
const registerEvent = (0, _react.useCallback)(eventList => {
|
|
67
66
|
eventList.forEach(element => {
|
|
68
67
|
document.addEventListener(element.eventName, element.event);
|
|
@@ -204,8 +203,6 @@ const Image = _ref => {
|
|
|
204
203
|
}
|
|
205
204
|
}, [data, editor]);
|
|
206
205
|
const onImageLoadError = (0, _react.useCallback)(() => {
|
|
207
|
-
console.log(isLoadingRef.current);
|
|
208
|
-
console.log(data);
|
|
209
206
|
// Check is due to the image is pasted from the clipboard in base64
|
|
210
207
|
if (data.src.startsWith('data:image/jpeg;base64')) {
|
|
211
208
|
return (0, _helpers.handleBase64Image)(editor, path, data);
|
|
@@ -213,7 +210,9 @@ const Image = _ref => {
|
|
|
213
210
|
|
|
214
211
|
// Check whether copying images is wrong
|
|
215
212
|
if (data.src.startsWith('attachment') || data.src.endsWith('_copy_error')) {
|
|
216
|
-
|
|
213
|
+
if (!isCopyError) {
|
|
214
|
+
setIsCopyError(true);
|
|
215
|
+
}
|
|
217
216
|
return;
|
|
218
217
|
}
|
|
219
218
|
if (isLoadingRef.current) return;
|
|
@@ -241,12 +240,15 @@ const Image = _ref => {
|
|
|
241
240
|
}, [data, editor, element]);
|
|
242
241
|
(0, _react.useEffect)(() => {
|
|
243
242
|
isLoadingRef.current = isLoading;
|
|
244
|
-
|
|
243
|
+
if (data.src.endsWith('_copy_error') && !isCopyError) {
|
|
244
|
+
setIsCopyError(true);
|
|
245
|
+
}
|
|
246
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
247
|
+
}, [isLoading, data.src]);
|
|
245
248
|
(0, _react.useEffect)(() => {
|
|
246
249
|
const {
|
|
247
250
|
src: url
|
|
248
251
|
} = data;
|
|
249
|
-
console.log(0, data);
|
|
250
252
|
if (url && !url.startsWith('http')) return;
|
|
251
253
|
if (url && url.endsWith('_copy_error')) {
|
|
252
254
|
setIsCopyError(true);
|
|
@@ -260,13 +262,19 @@ const Image = _ref => {
|
|
|
260
262
|
const downloadAndUploadImages = async url => {
|
|
261
263
|
try {
|
|
262
264
|
const response = await fetch(url);
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
265
|
+
if (response.ok) {
|
|
266
|
+
const blob = await response.blob();
|
|
267
|
+
const file = new File([blob], 'downloaded_image.png', {
|
|
268
|
+
type: blob.type
|
|
269
|
+
});
|
|
270
|
+
const imageUrl = await _context.default.uploadLocalImage([file]);
|
|
271
|
+
if (imageUrl && imageUrl[0]) {
|
|
272
|
+
(0, _helpers.updateImageNode)(editor, url, imageUrl[0]);
|
|
273
|
+
}
|
|
274
|
+
} else {
|
|
275
|
+
console.error(response.status);
|
|
276
|
+
const newUrl = url + '_copy_error';
|
|
277
|
+
(0, _helpers.updateImageNode)(editor, url, newUrl);
|
|
270
278
|
}
|
|
271
279
|
} catch (error) {
|
|
272
280
|
console.error(error);
|