@seafile/sdoc-editor 1.0.211-test-0.1 → 1.0.211-test-0.2

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.
@@ -41,7 +41,6 @@ class SeafileAPI {
41
41
  const url = '/api/v2.1/seadoc/upload-image/' + docUuid + '/';
42
42
  const form = new FormData();
43
43
  for (const fileItem of imageFiles) {
44
- console.log(imageFiles, fileItem);
45
44
  if (fileItem.type.startsWith('image/')) {
46
45
  const fileName = this.getImageFileNameWithUuid(fileItem);
47
46
  const file = new File([fileItem], fileName, {
@@ -50,7 +49,6 @@ class SeafileAPI {
50
49
  form.append('file', file);
51
50
  }
52
51
  }
53
- console.log(this.req.post(url, form));
54
52
  return this.req.post(url, form);
55
53
  }
56
54
  getSdocDownloadImageUrl(docUuid, imageName) {
@@ -64,32 +64,22 @@
64
64
 
65
65
  .sdoc-editor__article .sdoc-image-wrapper .sdoc-image-placeholder-wrapper {
66
66
  width: 360px;
67
- /* vertical-align: middle; */
68
67
  aspect-ratio: 1 / 1;
69
68
  background-color: #f0f0f0;
70
69
  border: 1px solid #ccc;
71
- /* position: relative; */
72
- /* overflow: hidden; */
73
70
  padding: 0 3%;
74
- /* font-size: 1.2vw; */
75
- /* transform-origin: top left; */
76
- /* transform: scale(1); */
71
+ max-width: 100%;
72
+ user-select: all;
73
+ pointer-events: all;
77
74
  }
78
75
 
76
+ .sdoc-editor__article .sdoc-image-wrapper .sdoc-image-tip-content,
79
77
  .sdoc-editor__article .sdoc-image-wrapper .sdoc-image-title {
80
- /* width: 100%;
81
- height: 5%;
82
- flex-direction: row;
83
- display: flex;
84
- align-items: center;
85
- justify-content: center;
86
- gap: 0.5em; */
87
78
  user-select: none;
79
+ pointer-events: none;
88
80
  }
89
81
 
90
82
  .sdoc-editor__article .sdoc-image-title .sdoc-exclamation-circle {
91
- /* width: 10%;
92
- height: 10%; */
93
83
  font-size: 18px;
94
84
  align-items: center;
95
85
  justify-content: center;
@@ -101,29 +91,10 @@
101
91
  color: red;
102
92
  font-size: 18px;
103
93
  user-select: none;
94
+ pointer-events: none;
104
95
  }
105
96
 
106
- .sdoc-editor__article .sdoc-image-wrapper .sdoc-image-tip-content {
107
- /* width: 100%;
108
- font-size: 0.7em;
109
- margin-top: 2%;
110
- text-align: center;
111
- white-space: nowrap; */
112
- user-select: none;
113
- }
114
-
115
- /* .sdoc-editor__article .sdoc-image-title .sdoc-exclamation-circle { */
116
- /* width: 10%;
117
- height: 10%;
118
- font-size: 1em; */
119
- /* align-items: center;
120
- justify-content: center; */
121
- /* color: red; */
122
- /* display: flex; */
123
- /* } */
124
-
125
97
  .sdoc-editor__article .sdoc-image-process-container {
126
- /* background-color: #F2F2F2; */
127
98
  width: 40px;
128
99
  height: 40px;
129
100
  display: flex;
@@ -138,6 +109,7 @@
138
109
  height: 30px;
139
110
  animation: spin 1s linear infinite;
140
111
  user-select: none;
112
+ pointer-events: none;
141
113
  }
142
114
 
143
115
  @keyframes spin {
@@ -134,7 +134,6 @@ const updateImage = (editor, data) => {
134
134
  };
135
135
  exports.updateImage = updateImage;
136
136
  const getImageURL = (data, editor) => {
137
- console.log(5, data);
138
137
  const {
139
138
  src: url,
140
139
  column_key
@@ -278,11 +277,4 @@ const handleBase64Image = (editor, path, imgData) => {
278
277
  });
279
278
  });
280
279
  };
281
-
282
- // export const updateFontSize = () => {
283
- // const placeholder = document.querySelector('.sdoc-image-placeholder-wrapper');
284
- // const parentWidth = placeholder.offsetWidth;
285
- // placeholder.style.fontSize = `${parentWidth * 0.05}px`;
286
- // console.log(parentWidth * 0.05);
287
- // };
288
280
  exports.handleBase64Image = handleBase64Image;
@@ -51,7 +51,6 @@ const withImage = editor => {
51
51
  const fragment = data.getData(`application/${_constants.CLIPBOARD_FORMAT_KEY}`) || (0, _documentUtils.getSlateFragmentAttribute)(data);
52
52
  const originSdocUuid = data.getData(`text/${_constants.CLIPBOARD_ORIGIN_SDOC_KEY}`);
53
53
  if (fragment && originSdocUuid) {
54
- console.log('1');
55
54
  const decoded = decodeURIComponent(window.atob(fragment));
56
55
  const fragmentData = JSON.parse(decoded);
57
56
  if ((0, _helpers.hasSdocImages)(originSdocUuid, fragmentData)) {
@@ -76,29 +75,11 @@ const withImage = editor => {
76
75
  }
77
76
  }
78
77
  if (data.types && data.types.includes('Files') && data.files[0].type.includes(_constants.IMAGE)) {
79
- console.log(data.files);
80
78
  _context.default.uploadLocalImage(data.files).then(fileUrl => {
81
79
  (0, _helpers.insertImage)(newEditor, fileUrl, editor.selection, _constants.INSERT_POSITION.CURRENT);
82
80
  });
83
81
  return;
84
82
  }
85
-
86
- // const otherDataTypes = data.types.filter(
87
- // (type) => type !== 'text/html' && type !== 'text/plain' && type !== 'Files'
88
- // );
89
- // if (otherDataTypes.length > 0) {
90
- // otherDataTypes.forEach((type) => {
91
- // if(data.getData(type).includes(IMAGE)) {
92
- // const url;
93
- // }
94
- // conti
95
-
96
- // });
97
- // };
98
-
99
- const notionBlockData = data.getData('text/_notion-blocks-v3-production');
100
- const notionPageSourceData = data.getData('text/_notion-page-source-production');
101
- console.log(notionBlockData, notionPageSourceData);
102
83
  insertData(data);
103
84
  };
104
85
  newEditor.insertFragment = data => {
@@ -71,21 +71,16 @@ const Image = _ref => {
71
71
  var _resizerRef$current;
72
72
  event.preventDefault();
73
73
  event.stopPropagation();
74
+ if (!imageRef.current) return;
74
75
  const changeX = event.clientX - ((_resizerRef$current = resizerRef.current) === null || _resizerRef$current === void 0 ? void 0 : _resizerRef$current.getBoundingClientRect().left) - 5;
75
- console.log(3, isShowImagePlaceholder);
76
+ let newWidth = isShowImagePlaceholder ? imageRef.current.getBoundingClientRect().width + changeX : imageRef.current.width + changeX;
77
+ if (newWidth < 20) return;
76
78
  if (isShowImagePlaceholder) {
77
- const imageWidth = imageRef.current.getBoundingClientRect().width + changeX;
78
- if (imageWidth < 20) return;
79
- imageRef.current.width.baseVal.value = imageWidth;
80
- setMovingWidth(imageWidth);
81
- // updateFontSize();
79
+ imageRef.current.width.baseVal.value = newWidth;
82
80
  } else {
83
- const imageWidth = imageRef.current.width + changeX;
84
- if (imageWidth < 20) return;
85
- imageRef.current.width = imageWidth;
86
- setMovingWidth(imageWidth);
81
+ imageRef.current.width = newWidth;
87
82
  }
88
- // console.log(44, imageRef.current.width, imageRef.current.width.baseVal)
83
+ setMovingWidth(newWidth);
89
84
  }, [isShowImagePlaceholder]);
90
85
  const onResizeEnd = (0, _react.useCallback)(event => {
91
86
  event.preventDefault();
@@ -128,10 +123,9 @@ const Image = _ref => {
128
123
  let imageWidth = element.data.width || '';
129
124
  if (movingWidth) imageWidth = movingWidth;
130
125
  return {
131
- width: imageWidth,
132
- display: isLoading ? 'none' : 'inline-block'
126
+ width: imageWidth
133
127
  };
134
- }, [element.data, movingWidth, isLoading]);
128
+ }, [element.data, movingWidth]);
135
129
  const onScroll = (0, _react.useCallback)(() => {
136
130
  setPosition();
137
131
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -203,27 +197,23 @@ const Image = _ref => {
203
197
  setIsShowImageHoverMenu(true);
204
198
  }, [setPosition]);
205
199
  const reloadImage = (0, _react.useCallback)(() => {
206
- setIsLoading(false);
207
- console.log(66666);
208
200
  if (imageRef.current) {
209
201
  imageRef.current['src'] = (0, _helpers.getImageURL)(data, editor);
210
202
  setIsShowImagePlaceholder(false);
211
203
  }
212
204
  }, [data, editor]);
213
205
  const onImageLoadError = (0, _react.useCallback)(() => {
214
- setIsLoading(false);
215
- console.log(666, data.src);
216
206
  // Check is due to the image is pasted from the clipboard in base64
217
207
  if (data.src.startsWith('data:image/jpeg;base64')) {
218
208
  return (0, _helpers.handleBase64Image)(editor, path, data);
219
209
  }
210
+ setIsLoading(false);
220
211
  setIsShowImagePlaceholder(true);
221
212
  // External network images do not reload after failure to load
222
213
  if (!data.src.startsWith('http')) {
223
214
  const eventBus = _eventBus.default.getInstance();
224
215
  eventBus.subscribe(_constants.INTERNAL_EVENT.RELOAD_IMAGE, reloadImage);
225
216
  }
226
- console.log(5);
227
217
  // eslint-disable-next-line react-hooks/exhaustive-deps
228
218
  }, []);
229
219
  const onSetCaption = (0, _react.useCallback)(e => {
@@ -240,8 +230,17 @@ const Image = _ref => {
240
230
  });
241
231
  }
242
232
  }, [data, editor, element]);
243
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isLoading && /*#__PURE__*/_react.default.createElement("div", {
244
- className: "sdoc-image-process-container"
233
+ (0, _react.useEffect)(() => {
234
+ if (imageRef.current) {
235
+ imageRef.current.onload = () => setIsLoading(false);
236
+ imageRef.current.onerror = onImageLoadError;
237
+ }
238
+ }, [data, editor]);
239
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
240
+ className: "sdoc-image-process-container",
241
+ style: {
242
+ display: isLoading ? 'inline-block' : 'none'
243
+ }
245
244
  }, /*#__PURE__*/_react.default.createElement("div", {
246
245
  className: "loading-spinner"
247
246
  }, /*#__PURE__*/_react.default.createElement("div", {
@@ -254,7 +253,8 @@ const Image = _ref => {
254
253
  },
255
254
  onMouseOver: e => (0, _helpers.selectImageWhenSelectPartial)(e, editor, element, isSelected),
256
255
  contentEditable: "false",
257
- suppressContentEditableWarning: true
256
+ suppressContentEditableWarning: true,
257
+ tabindex: "0"
258
258
  }), /*#__PURE__*/_react.default.createElement("svg", {
259
259
  xmlns: "http://www.w3.org/2000/svg",
260
260
  viewBox: "0 0 360 360",
@@ -264,7 +264,8 @@ const Image = _ref => {
264
264
  }),
265
265
  ref: imageRef,
266
266
  style: getImageStyle(),
267
- draggable: false
267
+ draggable: false,
268
+ tabindex: "0"
268
269
  }, /*#__PURE__*/_react.default.createElement("rect", {
269
270
  width: "100%",
270
271
  height: "100%",
@@ -273,7 +274,8 @@ const Image = _ref => {
273
274
  className: "sdoc-image-content-wrapper",
274
275
  textAnchor: "middle",
275
276
  dominantBaseline: "middle",
276
- transform: "translate(180, 180)"
277
+ transform: "translate(180, 180)",
278
+ contentEditable: "false"
277
279
  }, /*#__PURE__*/_react.default.createElement("g", {
278
280
  className: "sdoc-image-title",
279
281
  transform: "translate(0, 0)"
@@ -317,8 +319,7 @@ const Image = _ref => {
317
319
  className: (0, _classnames.default)('sdoc-image-wrapper', className)
318
320
  }, attributes, {
319
321
  style: {
320
- ...style,
321
- userSelect: 'none'
322
+ ...style
322
323
  },
323
324
  onMouseOver: e => (0, _helpers.selectImageWhenSelectPartial)(e, editor, element, isSelected),
324
325
  contentEditable: "false",
package/dist/context.js CHANGED
@@ -36,7 +36,6 @@ class Context {
36
36
  (0, _defineProperty2.default)(this, "uploadLocalImage", imageFiles => {
37
37
  const docUuid = this.getSetting('docUuid');
38
38
  return this.api.uploadSdocImage(docUuid, imageFiles).then(res => {
39
- console.log('res', res);
40
39
  const {
41
40
  relative_path
42
41
  } = res.data;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "1.0.211-test-0.1",
3
+ "version": "1.0.211-test-0.2",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",