@seafile/sdoc-editor 2.0.0 → 2.0.1

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,6 +62,61 @@
62
62
  caret-color: transparent;
63
63
  }
64
64
 
65
+ .sdoc-editor__article .sdoc-image-wrapper .sdoc-image-placeholder-wrapper {
66
+ width: 100%;
67
+ aspect-ratio: 1;
68
+ background-color: #f0f0f0;
69
+ border: 1px solid #ccc;
70
+ padding: 0 3%;
71
+ max-width: 100%;
72
+ user-select: all;
73
+ pointer-events: all;
74
+ }
75
+
76
+ .sdoc-editor__article .sdoc-image-wrapper .sdoc-image-tip-content,
77
+ .sdoc-editor__article .sdoc-image-wrapper .sdoc-image-title {
78
+ user-select: none;
79
+ pointer-events: none;
80
+ }
81
+
82
+ .sdoc-editor__article .sdoc-image-title .sdoc-exclamation-circle {
83
+ font-size: 18px;
84
+ align-items: center;
85
+ justify-content: center;
86
+ color: red;
87
+ display: flex;
88
+ }
89
+
90
+ .sdoc-editor__article .sdoc-image-title .sdoc-image-tip-title {
91
+ color: red;
92
+ font-size: 18px;
93
+ user-select: none;
94
+ pointer-events: none;
95
+ }
96
+
97
+ .sdoc-editor__article .sdoc-image-process-container {
98
+ width: 40px;
99
+ height: 40px;
100
+ display: flex;
101
+ align-items: center;
102
+ }
103
+
104
+ .sdoc-editor__article .sdoc-image-process-container .loading-spinner {
105
+ border: 5px solid #d8d8d8;
106
+ border-top: 5px solid #939393;
107
+ border-radius: 50%;
108
+ width: 30px;
109
+ height: 30px;
110
+ animation: spin 1s linear infinite;
111
+ user-select: none;
112
+ pointer-events: none;
113
+ }
114
+
115
+ @keyframes spin {
116
+ 0% { transform: rotate(0deg); }
117
+ 100% { transform: rotate(360deg); }
118
+ }
119
+
65
120
  .sdoc-editor__article .sdoc-image-inner {
66
121
  position: relative;
67
122
  display: inline-block;
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.updateImage = exports.selectImageWhenSelectPartial = exports.resetCursor = exports.queryCopyMoveProgressView = exports.isInsertImageMenuDisabled = exports.insertImageFiles = exports.insertImage = exports.hasSdocImages = exports.handleBase64Image = exports.getSingleImageFromFragment = exports.getImageURL = exports.getImageData = exports.generateImageNode = void 0;
7
+ exports.updateImageNode = exports.updateImage = exports.selectImageWhenSelectPartial = exports.resetCursor = exports.queryCopyMoveProgressView = exports.isInsertImageMenuDisabled = exports.insertImageFiles = exports.insertImage = exports.hasSdocImages = exports.handleBase64Image = exports.getSingleImageFromFragment = exports.getImageURL = exports.getImageData = exports.generateImageNode = void 0;
8
8
  var _urlJoin = _interopRequireDefault(require("url-join"));
9
9
  var _slate = require("@seafile/slate");
10
10
  var _slateReact = require("@seafile/slate-react");
@@ -133,6 +133,24 @@ const updateImage = (editor, data) => {
133
133
  });
134
134
  };
135
135
  exports.updateImage = updateImage;
136
+ const updateImageNode = (editor, originalUrl, newUrl) => {
137
+ _slate.Editor.nodes(editor, {
138
+ match: n => n.type === _constants2.IMAGE && n.data.src === originalUrl,
139
+ at: []
140
+ }).forEach(_ref => {
141
+ let [node, path] = _ref;
142
+ const newData = {
143
+ ...node.data,
144
+ src: newUrl
145
+ };
146
+ _slate.Transforms.setNodes(editor, {
147
+ data: newData
148
+ }, {
149
+ at: path
150
+ });
151
+ });
152
+ };
153
+ exports.updateImageNode = updateImageNode;
136
154
  const getImageURL = (data, editor) => {
137
155
  const {
138
156
  src: url,
@@ -21,6 +21,8 @@ var _constants2 = require("./constants");
21
21
  var _constants3 = require("../../constants");
22
22
  var _constants4 = require("../../../../constants");
23
23
  var _imagePlaceholder = _interopRequireDefault(require("../../../assets/images/image-placeholder.png"));
24
+ var _context = _interopRequireDefault(require("../../../../context"));
25
+ var _copyImageErrorSvg = _interopRequireDefault(require("../../../../components/copy-image-error-svg"));
24
26
  const Image = _ref => {
25
27
  var _imageRef$current, _imageRef$current2;
26
28
  let {
@@ -50,6 +52,7 @@ const Image = _ref => {
50
52
  const imageRef = (0, _react.useRef)(null);
51
53
  const resizerRef = (0, _react.useRef)(null);
52
54
  const imageCaptionInputRef = (0, _react.useRef)(null);
55
+ const isLoadingRef = (0, _react.useRef)(false);
53
56
  const scrollRef = (0, _useScrollContext.useScrollContext)();
54
57
  const [movingWidth, setMovingWidth] = (0, _react.useState)(null);
55
58
  const [isResizing, setIsResizing] = (0, _react.useState)(false);
@@ -57,6 +60,8 @@ const Image = _ref => {
57
60
  const [isShowImageHoverMenu, setIsShowImageHoverMenu] = (0, _react.useState)(false);
58
61
  const [menuPosition, setMenuPosition] = (0, _react.useState)({});
59
62
  const [caption, setCaption] = (0, _react.useState)((data === null || data === void 0 ? void 0 : data.caption) || '');
63
+ const [isLoading, setIsLoading] = (0, _react.useState)(false);
64
+ const [isCopyError, setIsCopyError] = (0, _react.useState)(false);
60
65
  const registerEvent = (0, _react.useCallback)(eventList => {
61
66
  eventList.forEach(element => {
62
67
  document.addEventListener(element.eventName, element.event);
@@ -202,6 +207,15 @@ const Image = _ref => {
202
207
  if (data.src.startsWith('data:image/jpeg;base64')) {
203
208
  return (0, _helpers.handleBase64Image)(editor, path, data);
204
209
  }
210
+
211
+ // Check whether copying images is wrong
212
+ if (data.src.startsWith('attachment') || data.src.endsWith('_copy_error')) {
213
+ if (!isCopyError) {
214
+ setIsCopyError(true);
215
+ }
216
+ return;
217
+ }
218
+ if (isLoadingRef.current) return;
205
219
  setIsShowImagePlaceholder(true);
206
220
  // External network images do not reload after failure to load
207
221
  if (!data.src.startsWith('http')) {
@@ -224,7 +238,66 @@ const Image = _ref => {
224
238
  });
225
239
  }
226
240
  }, [data, editor, element]);
227
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isShowImagePlaceholder && /*#__PURE__*/_react.default.createElement("span", Object.assign({
241
+ (0, _react.useEffect)(() => {
242
+ isLoadingRef.current = isLoading;
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]);
248
+ (0, _react.useEffect)(() => {
249
+ const {
250
+ src: url
251
+ } = data;
252
+ if (url && !url.startsWith('http')) return;
253
+ if (url && url.endsWith('_copy_error')) {
254
+ setIsCopyError(true);
255
+ return;
256
+ }
257
+ // Return if copying image from local server
258
+ const serviceUrl = _context.default.getSetting('serviceUrl');
259
+ if (url && url.startsWith(serviceUrl)) return;
260
+ if (url && url.startsWith('http')) {
261
+ setIsLoading(true);
262
+ const downloadAndUploadImages = async url => {
263
+ try {
264
+ const response = await fetch(url);
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);
278
+ }
279
+ } catch (error) {
280
+ console.error(error);
281
+ const newUrl = url + '_copy_error';
282
+ (0, _helpers.updateImageNode)(editor, url, newUrl);
283
+ } finally {
284
+ setIsLoading(false);
285
+ }
286
+ };
287
+ downloadAndUploadImages(url);
288
+ }
289
+ // eslint-disable-next-line react-hooks/exhaustive-deps
290
+ }, []);
291
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isLoading && /*#__PURE__*/_react.default.createElement("div", {
292
+ className: "sdoc-image-process-container",
293
+ style: {
294
+ display: 'inline-block'
295
+ }
296
+ }, /*#__PURE__*/_react.default.createElement("div", {
297
+ className: "loading-spinner"
298
+ }, /*#__PURE__*/_react.default.createElement("div", {
299
+ className: "spinner"
300
+ }))), isShowImagePlaceholder && /*#__PURE__*/_react.default.createElement("span", Object.assign({
228
301
  className: (0, _classnames.default)('sdoc-image-wrapper', className)
229
302
  }, attributes, {
230
303
  style: {
@@ -239,7 +312,20 @@ const Image = _ref => {
239
312
  style: getImageStyle(),
240
313
  draggable: false,
241
314
  alt: ""
242
- }), children), !isShowImagePlaceholder && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("span", Object.assign({
315
+ }), children), isCopyError && /*#__PURE__*/_react.default.createElement("span", Object.assign({
316
+ className: (0, _classnames.default)('sdoc-image-wrapper', className)
317
+ }, attributes, {
318
+ style: {
319
+ ...style
320
+ },
321
+ onMouseOver: e => (0, _helpers.selectImageWhenSelectPartial)(e, editor, element, isSelected),
322
+ contentEditable: "false",
323
+ suppressContentEditableWarning: true
324
+ }), /*#__PURE__*/_react.default.createElement(_copyImageErrorSvg.default, {
325
+ t: t,
326
+ isSelected: isSelected,
327
+ imageRef: imageRef
328
+ }), children), !isShowImagePlaceholder && !isCopyError && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("span", Object.assign({
243
329
  "data-id": element.id,
244
330
  className: (0, _classnames.default)('sdoc-image-wrapper', className)
245
331
  }, attributes, {
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _classnames = _interopRequireDefault(require("classnames"));
10
+ const Svg = _ref => {
11
+ let {
12
+ t,
13
+ isSelected,
14
+ imageRef
15
+ } = _ref;
16
+ return /*#__PURE__*/_react.default.createElement("svg", {
17
+ xmlns: "http://www.w3.org/2000/svg",
18
+ viewBox: "0 0 360 360",
19
+ preserveAspectRatio: "xMinYMin meet",
20
+ className: (0, _classnames.default)('sdoc-image-placeholder-wrapper', {
21
+ 'image-selected': isSelected
22
+ }),
23
+ ref: imageRef,
24
+ draggable: false
25
+ }, /*#__PURE__*/_react.default.createElement("rect", {
26
+ width: "100%",
27
+ height: "100%",
28
+ fill: "#f0f0f0"
29
+ }), /*#__PURE__*/_react.default.createElement("g", {
30
+ className: "sdoc-image-content-wrapper",
31
+ transform: "translate(180, 180) scale(1)"
32
+ }, /*#__PURE__*/_react.default.createElement("g", {
33
+ className: "sdoc-image-title",
34
+ transform: "translate(0, 0)"
35
+ }, /*#__PURE__*/_react.default.createElement("foreignObject", {
36
+ x: "-85",
37
+ y: "-16",
38
+ width: "20",
39
+ height: "28"
40
+ }, /*#__PURE__*/_react.default.createElement("div", {
41
+ className: "sdocfont sdoc-exclamation-circle"
42
+ })), /*#__PURE__*/_react.default.createElement("text", {
43
+ className: "sdoc-image-tip-title",
44
+ transform: "translate(-55, 4)",
45
+ fontSize: "20",
46
+ fill: "red",
47
+ fontFamily: "Arial, sans-serif"
48
+ }, t('Image_copy_error'))), /*#__PURE__*/_react.default.createElement("text", {
49
+ className: "sdoc-image-tip-content",
50
+ transform: "translate(0, 35)",
51
+ fontSize: "12",
52
+ textAnchor: "middle",
53
+ fill: "black",
54
+ fontFamily: "Arial, sans-serif"
55
+ }, t('Image_cannot_be_copied_Please_download_the_source_image')), /*#__PURE__*/_react.default.createElement("text", {
56
+ className: "sdoc-image-tip-content",
57
+ transform: "translate(0, 55)",
58
+ fontSize: "12",
59
+ textAnchor: "middle",
60
+ fill: "black",
61
+ fontFamily: "Arial, sans-serif"
62
+ }, t('And_select_insert_-_image_to_upload'))));
63
+ };
64
+ var _default = exports.default = Svg;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -39,7 +39,7 @@
39
39
  "remark-rehype": "11.0.0",
40
40
  "remark-stringify": "11.0.0",
41
41
  "slugid": "3.2.0",
42
- "socket.io-client": "4.6.1",
42
+ "socket.io-client": "4.8.1",
43
43
  "type-of": "2.0.1",
44
44
  "unified": "11.0.3",
45
45
  "url-join": "4.0.1",
@@ -99,6 +99,7 @@
99
99
  "css-minimizer-webpack-plugin": "5.0.1",
100
100
  "dotenv": "^10.0.0",
101
101
  "dotenv-expand": "^5.1.0",
102
+ "dtable-sdk": "5.0.6",
102
103
  "dtable-utils": "5.0.1",
103
104
  "ejs": "3.1.10",
104
105
  "eslint": "^8.3.0",
@@ -119,7 +120,7 @@
119
120
  "koa-router": "7.3.0",
120
121
  "koa-send": "5.0.1",
121
122
  "koa2-cors": "2.0.6",
122
- "lint-staged": "14.0.0",
123
+ "lint-staged": "15.4.3",
123
124
  "mini-css-extract-plugin": "^2.4.5",
124
125
  "node-polyfill-webpack-plugin": "2.0.1",
125
126
  "postcss": "^8.4.31",
@@ -140,7 +141,7 @@
140
141
  "react-router-dom": "7.1.3",
141
142
  "release-it": "17.3.0",
142
143
  "resolve": "^1.20.0",
143
- "resolve-url-loader": "^4.0.0",
144
+ "resolve-url-loader": "5.0.0",
144
145
  "sass-loader": "^12.3.0",
145
146
  "seafile-js": "0.2.235",
146
147
  "source-map-loader": "^3.0.0",
@@ -149,8 +150,8 @@
149
150
  "terser-webpack-plugin": "^5.2.5",
150
151
  "url-loader": "^4.1.1",
151
152
  "web-vitals": "2.1.4",
152
- "webpack": "5.64.4",
153
- "webpack-dev-server": "4.15.1",
153
+ "webpack": "5.98.0",
154
+ "webpack-dev-server": "5.2.0",
154
155
  "webpack-manifest-plugin": "5.0.0",
155
156
  "webpack-merge": "5.8.0",
156
157
  "workbox-webpack-plugin": "7.0.0"
@@ -610,5 +610,8 @@
610
610
  "Add_video_link": "Add video link",
611
611
  "Link_Seafile_video_file": "Link Seafile video file",
612
612
  "Select_video_file": "Select video file",
613
- "Support_Youtube_Tencent_Bilibili_and_more": "Support Youtube, Tencent, Bilibili and more"
613
+ "Support_Youtube_Tencent_Bilibili_and_more": "Support Youtube, Tencent, Bilibili and more",
614
+ "Image_cannot_be_copied_Please_download_the_source_image": "Image cannot be copied. Please download the source image,",
615
+ "And_select_insert_-_image_to_upload": "and select 「insert」 - 「image」 to upload.",
616
+ "Image_copy_error": "Image copy error"
614
617
  }
@@ -610,5 +610,8 @@
610
610
  "Add_video_link": "Videolink hinzufügen",
611
611
  "Link_Seafile_video_file": "Link Seafile video file",
612
612
  "Select_video_file": "Select video file",
613
- "Support_Youtube_Tencent_Bilibili_and_more": "Support Youtube, Tencent, Bilibili and more"
613
+ "Support_Youtube_Tencent_Bilibili_and_more": "Support Youtube, Tencent, Bilibili and more",
614
+ "Image_cannot_be_copied_Please_download_the_source_image": "Image cannot be copied. Please download the source image,",
615
+ "And_select_insert_-_image_to_upload": "and select 「insert」 - 「image」 to upload.",
616
+ "Image_copy_error": "Image copy error"
614
617
  }
@@ -610,5 +610,8 @@
610
610
  "Add_video_link": "Add video link",
611
611
  "Link_Seafile_video_file": "Link Seafile video file",
612
612
  "Select_video_file": "Select video file",
613
- "Support_Youtube_Tencent_Bilibili_and_more": "Support Youtube, Tencent, Bilibili and more"
613
+ "Support_Youtube_Tencent_Bilibili_and_more": "Support Youtube, Tencent, Bilibili and more",
614
+ "Image_cannot_be_copied_Please_download_the_source_image": "Image cannot be copied. Please download the source image,",
615
+ "And_select_insert_-_image_to_upload": "and select 「insert」 - 「image」 to upload.",
616
+ "Image_copy_error": "Image copy error"
614
617
  }
@@ -610,5 +610,8 @@
610
610
  "Add_video_link": "Add video link",
611
611
  "Link_Seafile_video_file": "Link Seafile video file",
612
612
  "Select_video_file": "Select video file",
613
- "Support_Youtube_Tencent_Bilibili_and_more": "Support Youtube, Tencent, Bilibili and more"
613
+ "Support_Youtube_Tencent_Bilibili_and_more": "Support Youtube, Tencent, Bilibili and more",
614
+ "Image_cannot_be_copied_Please_download_the_source_image": "Image cannot be copied. Please download the source image,",
615
+ "And_select_insert_-_image_to_upload": "and select 「insert」 - 「image」 to upload.",
616
+ "Image_copy_error": "Image copy error"
614
617
  }
@@ -610,5 +610,8 @@
610
610
  "Add_video_link": "Add video link",
611
611
  "Link_Seafile_video_file": "Link Seafile video file",
612
612
  "Select_video_file": "Select video file",
613
- "Support_Youtube_Tencent_Bilibili_and_more": "Support Youtube, Tencent, Bilibili and more"
613
+ "Support_Youtube_Tencent_Bilibili_and_more": "Support Youtube, Tencent, Bilibili and more",
614
+ "Image_cannot_be_copied_Please_download_the_source_image": "Image cannot be copied. Please download the source image,",
615
+ "And_select_insert_-_image_to_upload": "and select 「insert」 - 「image」 to upload.",
616
+ "Image_copy_error": "Image copy error"
614
617
  }
@@ -610,5 +610,8 @@
610
610
  "Add_video_link": "Add video link",
611
611
  "Link_Seafile_video_file": "Link Seafile video file",
612
612
  "Select_video_file": "Select video file",
613
- "Support_Youtube_Tencent_Bilibili_and_more": "Support Youtube, Tencent, Bilibili and more"
613
+ "Support_Youtube_Tencent_Bilibili_and_more": "Support Youtube, Tencent, Bilibili and more",
614
+ "Image_cannot_be_copied_Please_download_the_source_image": "Image cannot be copied. Please download the source image,",
615
+ "And_select_insert_-_image_to_upload": "and select 「insert」 - 「image」 to upload.",
616
+ "Image_copy_error": "Image copy error"
614
617
  }
@@ -610,5 +610,8 @@
610
610
  "Add_video_link": "Add video link",
611
611
  "Link_Seafile_video_file": "Link Seafile video file",
612
612
  "Select_video_file": "Select video file",
613
- "Support_Youtube_Tencent_Bilibili_and_more": "Support Youtube, Tencent, Bilibili and more"
613
+ "Support_Youtube_Tencent_Bilibili_and_more": "Support Youtube, Tencent, Bilibili and more",
614
+ "Image_cannot_be_copied_Please_download_the_source_image": "Image cannot be copied. Please download the source image,",
615
+ "And_select_insert_-_image_to_upload": "and select 「insert」 - 「image」 to upload.",
616
+ "Image_copy_error": "Image copy error"
614
617
  }
@@ -610,5 +610,8 @@
610
610
  "Add_video_link": "Add video link",
611
611
  "Link_Seafile_video_file": "Link Seafile video file",
612
612
  "Select_video_file": "Select video file",
613
- "Support_Youtube_Tencent_Bilibili_and_more": "Support Youtube, Tencent, Bilibili and more"
613
+ "Support_Youtube_Tencent_Bilibili_and_more": "Support Youtube, Tencent, Bilibili and more",
614
+ "Image_cannot_be_copied_Please_download_the_source_image": "Image cannot be copied. Please download the source image,",
615
+ "And_select_insert_-_image_to_upload": "and select 「insert」 - 「image」 to upload.",
616
+ "Image_copy_error": "Image copy error"
614
617
  }
@@ -610,5 +610,8 @@
610
610
  "Add_video_link": "Добавить ссылку на видео",
611
611
  "Link_Seafile_video_file": "Ссылка на видео файл Seafile",
612
612
  "Select_video_file": "Выбрать видео файл",
613
- "Support_Youtube_Tencent_Bilibili_and_more": "Support Youtube, Tencent, Bilibili and more"
613
+ "Support_Youtube_Tencent_Bilibili_and_more": "Support Youtube, Tencent, Bilibili and more",
614
+ "Image_cannot_be_copied_Please_download_the_source_image": "Изображение не может быть скопировано. Скачайте исходное изображение,",
615
+ "And_select_insert_-_image_to_upload": "и выбрать 「вставить」 - 「изображение」 для загрузки.",
616
+ "Image_copy_error": "Image copy error"
614
617
  }
@@ -610,5 +610,8 @@
610
610
  "Add_video_link": "添加视频链接",
611
611
  "Link_Seafile_video_file": "链接Seafile视频文件",
612
612
  "Select_video_file": "选择视频文件",
613
- "Support_Youtube_Tencent_Bilibili_and_more": "支持Youtube,腾讯视频,B站及其他平台"
613
+ "Support_Youtube_Tencent_Bilibili_and_more": "支持Youtube,腾讯视频,B站及其他平台",
614
+ "Image_cannot_be_copied_Please_download_the_source_image": "此照片不支持复制,请下载原图",
615
+ "And_select_insert_-_image_to_upload": "后点击工具栏「插入」- 「照片」上传",
616
+ "Image_copy_error": "图片复制错误"
614
617
  }