@seafile/comment-editor 0.0.11 → 0.0.12

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.
@@ -154,6 +154,7 @@ exports.updateImage = updateImage;
154
154
  const getImageURL = (data, editor) => {
155
155
  const {
156
156
  src: url,
157
+ is_upload,
157
158
  column_key
158
159
  } = data;
159
160
  if (column_key) {
@@ -174,10 +175,10 @@ const getImageURL = (data, editor) => {
174
175
  }
175
176
 
176
177
  // upload image | drag drop image | cut image
177
- if (isImageUrlIsFromUpload(url)) return url;
178
+ if (isImageUrlIsFromUpload(url, is_upload)) return url;
178
179
 
179
180
  // copy from others doc
180
- if (isImageUrlIsFromCopy(url)) return url;
181
+ if (isImageUrlIsFromCopy(url, is_upload)) return url;
181
182
  const serviceUrl = _context.default.getSetting('serviceUrl');
182
183
  const assetsUrl = _context.default.getSetting('assetsUrl');
183
184
  return (0, _urlJoin.default)(serviceUrl, assetsUrl, url);
@@ -301,14 +302,15 @@ const handleBase64Image = (editor, path, imgData) => {
301
302
  });
302
303
  };
303
304
  exports.handleBase64Image = handleBase64Image;
304
- const isImageUrlIsFromCopy = (url, uploadFromDtable) => {
305
- if (uploadFromDtable) return false;
305
+ const isImageUrlIsFromCopy = (url, is_upload) => {
306
+ if (is_upload) return false;
306
307
  if (url && url.startsWith('http')) return true;
307
308
  if (url && url.startsWith('attachment')) return true; // from yuque
308
309
  return false;
309
310
  };
310
311
  exports.isImageUrlIsFromCopy = isImageUrlIsFromCopy;
311
- const isImageUrlIsFromUpload = url => {
312
+ const isImageUrlIsFromUpload = (url, is_upload) => {
313
+ if (url && is_upload) return true;
312
314
  if (url && url.startsWith('blob:http')) return true;
313
315
  return false;
314
316
  };
@@ -218,10 +218,10 @@ const Image = _ref => {
218
218
  }
219
219
  }, [data, editor]);
220
220
  const onImageLoaded = (0, _react.useCallback)(() => {
221
- if ((0, _helpers.isImageUrlIsFromCopy)(data.src, data === null || data === void 0 ? void 0 : data.upload_from_dtable)) {
221
+ if ((0, _helpers.isImageUrlIsFromCopy)(data.src, data === null || data === void 0 ? void 0 : data.is_upload)) {
222
222
  setCopyImageLoading(true);
223
223
  }
224
- }, [data.src, data === null || data === void 0 ? void 0 : data.upload_from_dtable, setCopyImageLoading]);
224
+ }, [data.src, data === null || data === void 0 ? void 0 : data.is_upload, setCopyImageLoading]);
225
225
  const onImageLoadError = (0, _react.useCallback)(() => {
226
226
  // Check is due to the image is pasted from the clipboard in base64
227
227
  if (data.src.startsWith('data:image/jpeg;base64')) {
@@ -39,10 +39,11 @@ const useCopyImage = _ref => {
39
39
  const [isCopyError, setIsCopyError] = (0, _react.useState)(is_copy_error);
40
40
  (0, _react.useEffect)(() => {
41
41
  const {
42
- src: url
42
+ src: url,
43
+ is_upload
43
44
  } = data;
44
45
  if (isCopyError) return;
45
- if (!(0, _helpers.isImageUrlIsFromCopy)(url)) return;
46
+ if (!(0, _helpers.isImageUrlIsFromCopy)(url, is_upload)) return;
46
47
  const downloadAndUploadImages = async url => {
47
48
  try {
48
49
  const response = await fetch(url);
@@ -11,12 +11,12 @@ var _slateReact = require("@seafile/slate-react");
11
11
  var _context = _interopRequireDefault(require("../../../context"));
12
12
  var _helpers = require("./helpers");
13
13
  var _imageCache = _interopRequireDefault(require("./image-cache"));
14
- const updateImageNode = async (editor, element, newUrl, uploadFromDtable) => {
14
+ const updateImageNode = async (editor, element, newUrl) => {
15
15
  const nodePath = _slateReact.ReactEditor.findPath(editor, element);
16
16
  const newData = {
17
- src: newUrl
17
+ src: newUrl,
18
+ is_upload: true
18
19
  };
19
- uploadFromDtable && (newData['upload_from_dtable'] = true);
20
20
  _slate.Transforms.setNodes(editor, {
21
21
  data: newData
22
22
  }, {
@@ -45,8 +45,7 @@ const useUploadImage = _ref => {
45
45
  const fileItem = _imageCache.default.getImage(file_uuid);
46
46
  const imageUrl = await _context.default.api.uploadLocalImage([fileItem]);
47
47
  if (imageUrl && imageUrl[0]) {
48
- const uploadFromDtable = imageUrl !== null && imageUrl !== void 0 && imageUrl.upload_from_dtable ? true : false;
49
- updateImageNode(editor, element, imageUrl[0], uploadFromDtable);
48
+ updateImageNode(editor, element, imageUrl[0]);
50
49
  }
51
50
  } catch (error) {
52
51
  console.error(error.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/comment-editor",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "private": false,
5
5
  "description": "This is a comment editor",
6
6
  "main": "dist/index.js",