@seafile/sdoc-editor 1.0.221 → 1.0.222
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.
- package/dist/basic-sdk/assets/css/dropdown-menu.css +14 -1
- package/dist/basic-sdk/assets/css/sdoc-editor-plugins.css +0 -23
- package/dist/basic-sdk/extension/commons/search-list/index.css +28 -0
- package/dist/basic-sdk/extension/commons/search-list/index.js +150 -0
- package/dist/basic-sdk/extension/constants/index.js +2 -6
- package/dist/basic-sdk/extension/constants/menus-config.js +15 -0
- package/dist/basic-sdk/extension/plugins/image/helpers.js +9 -21
- package/dist/basic-sdk/extension/plugins/image/image-loader/index.css +37 -0
- package/dist/basic-sdk/extension/plugins/image/image-loader/index.js +23 -0
- package/dist/basic-sdk/extension/plugins/image/render-elem.js +24 -76
- package/dist/basic-sdk/extension/plugins/image/use-upload-image.js +80 -0
- package/dist/basic-sdk/extension/plugins/multi-column/constants/index.js +1 -1
- package/dist/basic-sdk/extension/plugins/multi-column/helper.js +24 -7
- package/dist/basic-sdk/extension/plugins/multi-column/render/index.css +1 -3
- package/dist/basic-sdk/extension/plugins/multi-column/render/index.js +7 -2
- package/dist/basic-sdk/extension/plugins/multi-column/resize-handlers/index.js +2 -2
- package/dist/basic-sdk/extension/plugins/seatable-column/menu/column-list-item.js +36 -0
- package/dist/basic-sdk/extension/plugins/seatable-column/menu/column-list-menu.css +4 -2
- package/dist/basic-sdk/extension/plugins/seatable-column/menu/column-list-menu.js +8 -13
- package/dist/basic-sdk/extension/plugins/seatable-column/menu/index.js +5 -9
- package/dist/basic-sdk/extension/plugins/seatable-column/render-elem.js +36 -7
- package/dist/basic-sdk/extension/plugins/seatable-tables/menu/index.js +3 -6
- package/dist/basic-sdk/extension/plugins/seatable-tables/menu/seatable-list.js +35 -2
- package/dist/basic-sdk/extension/plugins/seatable-tables/op-menu/index.css +19 -4
- package/dist/basic-sdk/extension/plugins/seatable-tables/op-menu/index.js +39 -9
- package/dist/basic-sdk/extension/plugins/seatable-tables/render-element/seatable-table.js +2 -1
- package/dist/basic-sdk/extension/plugins/seatable-tables/seatable-settings/hide-column-setter/hide-column-popover.js +2 -4
- package/dist/basic-sdk/extension/plugins/table/helpers.js +1 -0
- package/dist/basic-sdk/extension/toolbar/header-toolbar/insert-toolbar/index.js +4 -0
- package/dist/basic-sdk/extension/toolbar/insert-element-toolbar/index.js +7 -0
- package/dist/basic-sdk/extension/toolbar/side-toolbar/helpers.js +51 -1
- package/dist/basic-sdk/extension/toolbar/side-toolbar/index.js +116 -20
- package/dist/basic-sdk/utils/full-width-mode.js +1 -1
- package/package.json +1 -1
- package/public/locales/en/sdoc-editor.json +2 -1
- package/public/locales/zh_CN/sdoc-editor.json +2 -1
|
@@ -8,10 +8,23 @@
|
|
|
8
8
|
background-color: #ffff;
|
|
9
9
|
max-height: 300px;
|
|
10
10
|
max-width: 200px;
|
|
11
|
-
overflow: auto;
|
|
12
11
|
padding: 8px 0px;
|
|
13
12
|
}
|
|
14
13
|
|
|
14
|
+
.sdoc-dropdown-menu .sdoc-seatable-selected-table-list-wrapper .sdoc-seatable-list-search-wrapper {
|
|
15
|
+
padding: 12px;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.sdoc-dropdown-menu .sdoc-seatable-selected-table-list-wrapper .sdoc-seatable-list-search-wrapper>input {
|
|
19
|
+
font-size: 12px;
|
|
20
|
+
max-height: 30px;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.sdoc-dropdown-menu .sdoc-seatable-selected-table-list-wrapper .sdoc-seatable-list-wrapper {
|
|
24
|
+
max-height: 230px;
|
|
25
|
+
overflow-y: auto;
|
|
26
|
+
}
|
|
27
|
+
|
|
15
28
|
.sdoc-dropdown-menu .sdoc-dropdown-menu-divider {
|
|
16
29
|
width: 100%;
|
|
17
30
|
height: 0;
|
|
@@ -94,29 +94,6 @@
|
|
|
94
94
|
pointer-events: none;
|
|
95
95
|
}
|
|
96
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
|
-
|
|
120
97
|
.sdoc-editor__article .sdoc-image-inner {
|
|
121
98
|
position: relative;
|
|
122
99
|
display: inline-block;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
.sdoc-search-list {
|
|
2
|
+
display: flex;
|
|
3
|
+
height: 100%;
|
|
4
|
+
width: 100%;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.sdoc-search-list .sdoc-search-list-wrapper {
|
|
9
|
+
padding: 12px;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.sdoc-search-list .sdoc-search-list-wrapper>input {
|
|
13
|
+
font-size: 12px;
|
|
14
|
+
max-height: 30px;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.sdoc-search-list .sdoc-search-list-content-wrapper {
|
|
18
|
+
min-height: 0;
|
|
19
|
+
min-width: 0;
|
|
20
|
+
flex: 1;
|
|
21
|
+
overflow: auto;
|
|
22
|
+
max-height: 300px;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.sdoc-search-list .sdoc-search-list-with-no-results {
|
|
26
|
+
font-size: 12px;
|
|
27
|
+
padding: 4px 16px;
|
|
28
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = SearchList;
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _reactI18next = require("react-i18next");
|
|
11
|
+
var _reactstrap = require("reactstrap");
|
|
12
|
+
var _keyCodes = _interopRequireDefault(require("../../../../constants/key-codes"));
|
|
13
|
+
require("./index.css");
|
|
14
|
+
function SearchList(_ref) {
|
|
15
|
+
let {
|
|
16
|
+
list: originalList,
|
|
17
|
+
listItem: ListItem,
|
|
18
|
+
onListItemClick,
|
|
19
|
+
onEscClick
|
|
20
|
+
} = _ref;
|
|
21
|
+
const {
|
|
22
|
+
t
|
|
23
|
+
} = (0, _reactI18next.useTranslation)('sdoc-editor');
|
|
24
|
+
const inputWrapperRef = (0, _react.useRef)(null);
|
|
25
|
+
const isComposingRef = (0, _react.useRef)(null);
|
|
26
|
+
const listRefs = (0, _react.useRef)([]);
|
|
27
|
+
const [searchedList, setSearchedList] = (0, _react.useState)(originalList);
|
|
28
|
+
const [currentSelectIndex, setCurrentSelectIndex] = (0, _react.useState)(-1);
|
|
29
|
+
|
|
30
|
+
// search input
|
|
31
|
+
const onChange = (0, _react.useCallback)(event => {
|
|
32
|
+
if (isComposingRef.current) return;
|
|
33
|
+
const value = event.target.value.trim();
|
|
34
|
+
if (value) {
|
|
35
|
+
const list = originalList.filter(item => item.label.indexOf(value) > -1);
|
|
36
|
+
setSearchedList(list);
|
|
37
|
+
} else {
|
|
38
|
+
setSearchedList(originalList);
|
|
39
|
+
}
|
|
40
|
+
}, [originalList]);
|
|
41
|
+
const onCompositionStart = (0, _react.useCallback)(() => {
|
|
42
|
+
isComposingRef.current = true;
|
|
43
|
+
}, []);
|
|
44
|
+
const onCompositionEnd = (0, _react.useCallback)(e => {
|
|
45
|
+
isComposingRef.current = false;
|
|
46
|
+
onChange(e);
|
|
47
|
+
}, [onChange]);
|
|
48
|
+
|
|
49
|
+
// search content list
|
|
50
|
+
const onItemClick = (0, _react.useCallback)(item => {
|
|
51
|
+
onListItemClick && onListItemClick(item);
|
|
52
|
+
}, [onListItemClick]);
|
|
53
|
+
const onHandleInputFocus = (0, _react.useCallback)(isFocus => {
|
|
54
|
+
if (inputWrapperRef.current) {
|
|
55
|
+
queueMicrotask(() => {
|
|
56
|
+
isFocus ? inputWrapperRef.current.focus() : inputWrapperRef.current.blur();
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}, []);
|
|
60
|
+
(0, _react.useEffect)(() => {
|
|
61
|
+
if (currentSelectIndex === -1) {
|
|
62
|
+
onHandleInputFocus(true);
|
|
63
|
+
} else {
|
|
64
|
+
onHandleInputFocus(false);
|
|
65
|
+
}
|
|
66
|
+
}, [currentSelectIndex, onHandleInputFocus]);
|
|
67
|
+
const handleClick = (0, _react.useCallback)(event => {
|
|
68
|
+
var _inputWrapperRef$curr;
|
|
69
|
+
if (inputWrapperRef !== null && inputWrapperRef !== void 0 && (_inputWrapperRef$curr = inputWrapperRef.current) !== null && _inputWrapperRef$curr !== void 0 && _inputWrapperRef$curr.contains(event.target) || inputWrapperRef.current === event.target) {
|
|
70
|
+
event.stopPropagation();
|
|
71
|
+
event.nativeEvent && event.nativeEvent.stopImmediatePropagation && event.nativeEvent.stopImmediatePropagation();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
}, []);
|
|
75
|
+
const scrollIntoView = (0, _react.useCallback)(index => {
|
|
76
|
+
if (index === -1) return;
|
|
77
|
+
listRefs.current[index].scrollIntoView({
|
|
78
|
+
behavior: 'smooth',
|
|
79
|
+
block: 'center',
|
|
80
|
+
inline: 'nearest'
|
|
81
|
+
});
|
|
82
|
+
}, []);
|
|
83
|
+
const handleKeyDown = (0, _react.useCallback)(e => {
|
|
84
|
+
const {
|
|
85
|
+
UpArrow,
|
|
86
|
+
DownArrow,
|
|
87
|
+
Enter,
|
|
88
|
+
Esc
|
|
89
|
+
} = _keyCodes.default;
|
|
90
|
+
const {
|
|
91
|
+
keyCode
|
|
92
|
+
} = e;
|
|
93
|
+
if (keyCode === UpArrow) {
|
|
94
|
+
e.preventDefault();
|
|
95
|
+
if (currentSelectIndex > -1) {
|
|
96
|
+
setCurrentSelectIndex(currentSelectIndex - 1);
|
|
97
|
+
scrollIntoView(currentSelectIndex - 1);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (keyCode === DownArrow) {
|
|
101
|
+
e.preventDefault();
|
|
102
|
+
if (currentSelectIndex === searchedList.length - 1) return;
|
|
103
|
+
if (currentSelectIndex < searchedList.length - 1) {
|
|
104
|
+
setCurrentSelectIndex(currentSelectIndex + 1);
|
|
105
|
+
scrollIntoView(currentSelectIndex + 1);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (keyCode === Enter) {
|
|
109
|
+
e.preventDefault();
|
|
110
|
+
const item = searchedList[currentSelectIndex];
|
|
111
|
+
onItemClick(item);
|
|
112
|
+
}
|
|
113
|
+
if (keyCode === Esc) {
|
|
114
|
+
e.preventDefault();
|
|
115
|
+
onEscClick && onEscClick();
|
|
116
|
+
}
|
|
117
|
+
}, [currentSelectIndex, onEscClick, onItemClick, scrollIntoView, searchedList]);
|
|
118
|
+
(0, _react.useEffect)(() => {
|
|
119
|
+
document.addEventListener('mousedown', handleClick);
|
|
120
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
121
|
+
return () => {
|
|
122
|
+
document.removeEventListener('keydown', handleKeyDown);
|
|
123
|
+
document.removeEventListener('click', handleClick);
|
|
124
|
+
};
|
|
125
|
+
}, [handleClick, handleKeyDown]);
|
|
126
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
127
|
+
className: "sdoc-search-list"
|
|
128
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
129
|
+
className: "sdoc-search-list-wrapper"
|
|
130
|
+
}, /*#__PURE__*/_react.default.createElement(_reactstrap.Input, {
|
|
131
|
+
innerRef: inputWrapperRef,
|
|
132
|
+
placeholder: t('Search_action'),
|
|
133
|
+
onChange: onChange,
|
|
134
|
+
onCompositionStart: onCompositionStart,
|
|
135
|
+
onCompositionEnd: onCompositionEnd
|
|
136
|
+
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
137
|
+
className: "sdoc-search-list-content-wrapper"
|
|
138
|
+
}, searchedList.length === 0 && /*#__PURE__*/_react.default.createElement("div", {
|
|
139
|
+
className: "sdoc-search-list-with-no-results"
|
|
140
|
+
}, t('No_results')), searchedList.map((item, index) => {
|
|
141
|
+
const isSelected = index === currentSelectIndex;
|
|
142
|
+
return /*#__PURE__*/_react.default.createElement(ListItem, {
|
|
143
|
+
innerRef: el => listRefs.current[index] = el,
|
|
144
|
+
key: index,
|
|
145
|
+
item: item,
|
|
146
|
+
onItemClick: onItemClick,
|
|
147
|
+
isSelected: isSelected
|
|
148
|
+
});
|
|
149
|
+
})));
|
|
150
|
+
}
|
|
@@ -128,12 +128,6 @@ Object.defineProperty(exports, "FILE_LINK_INSET_INPUT_TEMP", {
|
|
|
128
128
|
}
|
|
129
129
|
});
|
|
130
130
|
exports.FILE_TYPE = void 0;
|
|
131
|
-
Object.defineProperty(exports, "FIVE_COLUMN", {
|
|
132
|
-
enumerable: true,
|
|
133
|
-
get: function () {
|
|
134
|
-
return _elementType.FIVE_COLUMN;
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
131
|
Object.defineProperty(exports, "FONT", {
|
|
138
132
|
enumerable: true,
|
|
139
133
|
get: function () {
|
|
@@ -276,6 +270,7 @@ Object.defineProperty(exports, "MULTI_COLUMN", {
|
|
|
276
270
|
return _elementType.MULTI_COLUMN;
|
|
277
271
|
}
|
|
278
272
|
});
|
|
273
|
+
exports.MULTI_COLUMN_TYPE = void 0;
|
|
279
274
|
Object.defineProperty(exports, "ORDERED_LIST", {
|
|
280
275
|
enumerable: true,
|
|
281
276
|
get: function () {
|
|
@@ -532,6 +527,7 @@ const INSERT_POSITION = exports.INSERT_POSITION = {
|
|
|
532
527
|
};
|
|
533
528
|
const LOCAL_IMAGE = exports.LOCAL_IMAGE = 'local-image';
|
|
534
529
|
const LOCAL_VIDEO = exports.LOCAL_VIDEO = 'local-video';
|
|
530
|
+
const MULTI_COLUMN_TYPE = exports.MULTI_COLUMN_TYPE = [_elementType.TWO_COLUMN, _elementType.THREE_COLUMN, _elementType.FOUR_COLUMN];
|
|
535
531
|
const LIST_TYPE_ARRAY = exports.LIST_TYPE_ARRAY = [_elementType.UNORDERED_LIST, _elementType.ORDERED_LIST];
|
|
536
532
|
const LIST_ITEM_CORRELATION_TYPE = exports.LIST_ITEM_CORRELATION_TYPE = [_elementType.UNORDERED_LIST, _elementType.ORDERED_LIST, _elementType.LIST_ITEM];
|
|
537
533
|
const LIST_ITEM_SUPPORTED_TRANSFORMATION = exports.LIST_ITEM_SUPPORTED_TRANSFORMATION = [_elementType.UNORDERED_LIST, _elementType.ORDERED_LIST, 'left', 'center', 'right', _elementType.BLOCKQUOTE];
|
|
@@ -297,6 +297,21 @@ const SIDE_TRANSFORM_MENUS_CONFIG = exports.SIDE_TRANSFORM_MENUS_CONFIG = [{
|
|
|
297
297
|
iconClass: 'sdocfont sdoc-callout',
|
|
298
298
|
type: _elementType.CALL_OUT,
|
|
299
299
|
text: 'Callout'
|
|
300
|
+
}, {
|
|
301
|
+
id: _elementType.TWO_COLUMN,
|
|
302
|
+
iconClass: 'sdocfont sdoc-multi-column',
|
|
303
|
+
type: _elementType.TWO_COLUMN,
|
|
304
|
+
text: 'Two_column'
|
|
305
|
+
}, {
|
|
306
|
+
id: _elementType.THREE_COLUMN,
|
|
307
|
+
iconClass: 'sdocfont sdoc-multi-column',
|
|
308
|
+
type: _elementType.THREE_COLUMN,
|
|
309
|
+
text: 'Three_column'
|
|
310
|
+
}, {
|
|
311
|
+
id: _elementType.FOUR_COLUMN,
|
|
312
|
+
iconClass: 'sdocfont sdoc-multi-column',
|
|
313
|
+
type: _elementType.FOUR_COLUMN,
|
|
314
|
+
text: 'Four_column'
|
|
300
315
|
}];
|
|
301
316
|
const SIDE_TRANSFORM_MENUS_SEARCH_MAP = exports.SIDE_TRANSFORM_MENUS_SEARCH_MAP = {
|
|
302
317
|
[_elementType.PARAGRAPH]: 'Paragraph',
|
|
@@ -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.
|
|
7
|
+
exports.updateImage = exports.selectImageWhenSelectPartial = exports.resetCursor = exports.queryCopyMoveProgressView = exports.isInsertImageMenuDisabled = exports.isImagUrlIsFromCopy = 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,24 +133,6 @@ 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;
|
|
154
136
|
const getImageURL = (data, editor) => {
|
|
155
137
|
const {
|
|
156
138
|
src: url,
|
|
@@ -171,7 +153,7 @@ const getImageURL = (data, editor) => {
|
|
|
171
153
|
return imgUrl;
|
|
172
154
|
}
|
|
173
155
|
}
|
|
174
|
-
if (url
|
|
156
|
+
if (isImagUrlIsFromCopy(url)) return url;
|
|
175
157
|
const serviceUrl = _context.default.getSetting('serviceUrl');
|
|
176
158
|
const assetsUrl = _context.default.getSetting('assetsUrl');
|
|
177
159
|
return (0, _urlJoin.default)(serviceUrl, assetsUrl, url);
|
|
@@ -295,4 +277,10 @@ const handleBase64Image = (editor, path, imgData) => {
|
|
|
295
277
|
});
|
|
296
278
|
});
|
|
297
279
|
};
|
|
298
|
-
exports.handleBase64Image = handleBase64Image;
|
|
280
|
+
exports.handleBase64Image = handleBase64Image;
|
|
281
|
+
const isImagUrlIsFromCopy = url => {
|
|
282
|
+
if (url && url.startsWith('http')) return true;
|
|
283
|
+
if (url && url.startsWith('attachment')) return true; // from yuque
|
|
284
|
+
return false;
|
|
285
|
+
};
|
|
286
|
+
exports.isImagUrlIsFromCopy = isImagUrlIsFromCopy;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
.sdoc-image-process-container {
|
|
2
|
+
position: absolute;
|
|
3
|
+
width: 100%;
|
|
4
|
+
height: 100%;
|
|
5
|
+
display: flex;
|
|
6
|
+
flex-direction: column;
|
|
7
|
+
align-items: center;
|
|
8
|
+
justify-content: center;
|
|
9
|
+
top: 0;
|
|
10
|
+
left: 0;
|
|
11
|
+
background-color: 'rgba(0, 0, 0, 0.5)'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@keyframes spin {
|
|
15
|
+
0% {
|
|
16
|
+
transform: rotate(0deg);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
100% {
|
|
20
|
+
transform: rotate(360deg);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.sdoc-image-process-container .loading-spinner {
|
|
25
|
+
border: 3px solid #d8d8d8;
|
|
26
|
+
border-top: 3px solid #939393;
|
|
27
|
+
border-radius: 50%;
|
|
28
|
+
width: 20px;
|
|
29
|
+
height: 20px;
|
|
30
|
+
animation: spin 1s linear infinite;
|
|
31
|
+
user-select: none;
|
|
32
|
+
pointer-events: none;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.sdoc-image-process-container .copyright {
|
|
36
|
+
margin-top: 4px;
|
|
37
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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 = ImageLoader;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
require("./index.css");
|
|
10
|
+
function ImageLoader(_ref) {
|
|
11
|
+
let {
|
|
12
|
+
copyright
|
|
13
|
+
} = _ref;
|
|
14
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
15
|
+
className: "sdoc-image-process-container"
|
|
16
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
17
|
+
className: "loading-spinner"
|
|
18
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
19
|
+
className: "spinner"
|
|
20
|
+
})), copyright && /*#__PURE__*/_react.default.createElement("div", {
|
|
21
|
+
className: "copyright"
|
|
22
|
+
}, copyright));
|
|
23
|
+
}
|
|
@@ -21,8 +21,9 @@ 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
24
|
var _copyImageErrorSvg = _interopRequireDefault(require("../../../../components/copy-image-error-svg"));
|
|
25
|
+
var _useUploadImage = _interopRequireDefault(require("./use-upload-image"));
|
|
26
|
+
var _imageLoader = _interopRequireDefault(require("./image-loader"));
|
|
26
27
|
const Image = _ref => {
|
|
27
28
|
var _imageRef$current, _imageRef$current2;
|
|
28
29
|
let {
|
|
@@ -52,7 +53,6 @@ const Image = _ref => {
|
|
|
52
53
|
const imageRef = (0, _react.useRef)(null);
|
|
53
54
|
const resizerRef = (0, _react.useRef)(null);
|
|
54
55
|
const imageCaptionInputRef = (0, _react.useRef)(null);
|
|
55
|
-
const isLoadingRef = (0, _react.useRef)(false);
|
|
56
56
|
const scrollRef = (0, _useScrollContext.useScrollContext)();
|
|
57
57
|
const [movingWidth, setMovingWidth] = (0, _react.useState)(null);
|
|
58
58
|
const [isResizing, setIsResizing] = (0, _react.useState)(false);
|
|
@@ -60,8 +60,14 @@ const Image = _ref => {
|
|
|
60
60
|
const [isShowImageHoverMenu, setIsShowImageHoverMenu] = (0, _react.useState)(false);
|
|
61
61
|
const [menuPosition, setMenuPosition] = (0, _react.useState)({});
|
|
62
62
|
const [caption, setCaption] = (0, _react.useState)((data === null || data === void 0 ? void 0 : data.caption) || '');
|
|
63
|
-
const
|
|
64
|
-
|
|
63
|
+
const {
|
|
64
|
+
isCopyImageLoading,
|
|
65
|
+
isCopyImageError,
|
|
66
|
+
setCopyImageLoading
|
|
67
|
+
} = (0, _useUploadImage.default)({
|
|
68
|
+
editor,
|
|
69
|
+
element
|
|
70
|
+
});
|
|
65
71
|
const registerEvent = (0, _react.useCallback)(eventList => {
|
|
66
72
|
eventList.forEach(element => {
|
|
67
73
|
document.addEventListener(element.eventName, element.event);
|
|
@@ -202,20 +208,16 @@ const Image = _ref => {
|
|
|
202
208
|
setIsShowImagePlaceholder(false);
|
|
203
209
|
}
|
|
204
210
|
}, [data, editor]);
|
|
211
|
+
const onImageLoaded = (0, _react.useCallback)(() => {
|
|
212
|
+
if ((0, _helpers.isImagUrlIsFromCopy)(data.src)) {
|
|
213
|
+
setCopyImageLoading(true);
|
|
214
|
+
}
|
|
215
|
+
}, [data.src, setCopyImageLoading]);
|
|
205
216
|
const onImageLoadError = (0, _react.useCallback)(() => {
|
|
206
217
|
// Check is due to the image is pasted from the clipboard in base64
|
|
207
218
|
if (data.src.startsWith('data:image/jpeg;base64')) {
|
|
208
219
|
return (0, _helpers.handleBase64Image)(editor, path, data);
|
|
209
220
|
}
|
|
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;
|
|
219
221
|
setIsShowImagePlaceholder(true);
|
|
220
222
|
// External network images do not reload after failure to load
|
|
221
223
|
if (!data.src.startsWith('http')) {
|
|
@@ -238,66 +240,7 @@ const Image = _ref => {
|
|
|
238
240
|
});
|
|
239
241
|
}
|
|
240
242
|
}, [data, editor, element]);
|
|
241
|
-
(
|
|
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({
|
|
243
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isShowImagePlaceholder && /*#__PURE__*/_react.default.createElement("span", Object.assign({
|
|
301
244
|
className: (0, _classnames.default)('sdoc-image-wrapper', className)
|
|
302
245
|
}, attributes, {
|
|
303
246
|
style: {
|
|
@@ -305,6 +248,7 @@ const Image = _ref => {
|
|
|
305
248
|
},
|
|
306
249
|
onMouseOver: e => (0, _helpers.selectImageWhenSelectPartial)(e, editor, element, isSelected),
|
|
307
250
|
contentEditable: "false",
|
|
251
|
+
"data-src": (0, _helpers.getImageURL)(data, editor),
|
|
308
252
|
suppressContentEditableWarning: true
|
|
309
253
|
}), /*#__PURE__*/_react.default.createElement("img", {
|
|
310
254
|
ref: imageRef,
|
|
@@ -312,7 +256,7 @@ const Image = _ref => {
|
|
|
312
256
|
style: getImageStyle(),
|
|
313
257
|
draggable: false,
|
|
314
258
|
alt: ""
|
|
315
|
-
}), children),
|
|
259
|
+
}), children), isCopyImageError && /*#__PURE__*/_react.default.createElement("span", Object.assign({
|
|
316
260
|
className: (0, _classnames.default)('sdoc-image-wrapper', className)
|
|
317
261
|
}, attributes, {
|
|
318
262
|
style: {
|
|
@@ -320,12 +264,13 @@ const Image = _ref => {
|
|
|
320
264
|
},
|
|
321
265
|
onMouseOver: e => (0, _helpers.selectImageWhenSelectPartial)(e, editor, element, isSelected),
|
|
322
266
|
contentEditable: "false",
|
|
267
|
+
"data-src": data.src,
|
|
323
268
|
suppressContentEditableWarning: true
|
|
324
269
|
}), /*#__PURE__*/_react.default.createElement(_copyImageErrorSvg.default, {
|
|
325
270
|
t: t,
|
|
326
271
|
isSelected: isSelected,
|
|
327
272
|
imageRef: imageRef
|
|
328
|
-
}), children), !isShowImagePlaceholder && !
|
|
273
|
+
}), children), !isShowImagePlaceholder && !isCopyImageError && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("span", Object.assign({
|
|
329
274
|
"data-id": element.id,
|
|
330
275
|
className: (0, _classnames.default)('sdoc-image-wrapper', className)
|
|
331
276
|
}, attributes, {
|
|
@@ -342,16 +287,19 @@ const Image = _ref => {
|
|
|
342
287
|
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
343
288
|
style: imageStyle
|
|
344
289
|
}, /*#__PURE__*/_react.default.createElement("img", {
|
|
290
|
+
ref: imageRef,
|
|
345
291
|
className: (0, _classnames.default)({
|
|
346
292
|
'image-selected': isSelected
|
|
347
293
|
}),
|
|
348
294
|
onClick: onClickImage,
|
|
349
|
-
ref: imageRef,
|
|
350
295
|
src: (0, _helpers.getImageURL)(data, editor),
|
|
351
296
|
style: getImageStyle(),
|
|
352
297
|
draggable: false,
|
|
298
|
+
onLoad: onImageLoaded,
|
|
353
299
|
onError: onImageLoadError,
|
|
354
300
|
alt: ""
|
|
301
|
+
}), isCopyImageLoading && /*#__PURE__*/_react.default.createElement(_imageLoader.default, {
|
|
302
|
+
copyright: t('Image_is_uploading')
|
|
355
303
|
}), isSelected && /*#__PURE__*/_react.default.createElement("span", {
|
|
356
304
|
className: "image-resizer",
|
|
357
305
|
ref: resizerRef,
|
|
@@ -0,0 +1,80 @@
|
|
|
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 = require("react");
|
|
9
|
+
var _slate = require("@seafile/slate");
|
|
10
|
+
var _slateReact = require("@seafile/slate-react");
|
|
11
|
+
var _context = _interopRequireDefault(require("../../../../context"));
|
|
12
|
+
var _helpers = require("./helpers");
|
|
13
|
+
const updateImageNode = async function (editor, element, newUrl) {
|
|
14
|
+
let isError = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
15
|
+
const nodePath = _slateReact.ReactEditor.findPath(editor, element);
|
|
16
|
+
const newData = {
|
|
17
|
+
...element.data,
|
|
18
|
+
src: newUrl,
|
|
19
|
+
is_copy_error: isError
|
|
20
|
+
};
|
|
21
|
+
_slate.Transforms.setNodes(editor, {
|
|
22
|
+
data: newData
|
|
23
|
+
}, {
|
|
24
|
+
at: nodePath
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
const useImageUpload = _ref => {
|
|
28
|
+
let {
|
|
29
|
+
editor,
|
|
30
|
+
element
|
|
31
|
+
} = _ref;
|
|
32
|
+
const {
|
|
33
|
+
data
|
|
34
|
+
} = element;
|
|
35
|
+
const {
|
|
36
|
+
is_copy_error = false
|
|
37
|
+
} = data;
|
|
38
|
+
const [isLoading, setIsLoading] = (0, _react.useState)(false);
|
|
39
|
+
const [isCopyError, setIsCopyError] = (0, _react.useState)(is_copy_error);
|
|
40
|
+
(0, _react.useEffect)(() => {
|
|
41
|
+
const {
|
|
42
|
+
src: url
|
|
43
|
+
} = data;
|
|
44
|
+
if (isCopyError) return;
|
|
45
|
+
if (!(0, _helpers.isImagUrlIsFromCopy)(url)) return;
|
|
46
|
+
const downloadAndUploadImages = async url => {
|
|
47
|
+
try {
|
|
48
|
+
const response = await fetch(url);
|
|
49
|
+
if (response.ok) {
|
|
50
|
+
const blob = await response.blob();
|
|
51
|
+
const file = new File([blob], 'downloaded_image.png', {
|
|
52
|
+
type: blob.type
|
|
53
|
+
});
|
|
54
|
+
const imageUrl = await _context.default.uploadLocalImage([file]);
|
|
55
|
+
if (imageUrl && imageUrl[0]) {
|
|
56
|
+
updateImageNode(editor, element, imageUrl[0]);
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
throw new Error(`HTTP error status: ${response.status}`);
|
|
60
|
+
}
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error(error);
|
|
63
|
+
updateImageNode(editor, element, url, true);
|
|
64
|
+
setIsCopyError(true);
|
|
65
|
+
} finally {
|
|
66
|
+
setTimeout(() => {
|
|
67
|
+
setIsLoading(false);
|
|
68
|
+
}, 500);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
downloadAndUploadImages(url);
|
|
72
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
73
|
+
}, []);
|
|
74
|
+
return {
|
|
75
|
+
isCopyImageLoading: isLoading,
|
|
76
|
+
setCopyImageLoading: setIsLoading,
|
|
77
|
+
isCopyImageError: isCopyError
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
var _default = exports.default = useImageUpload;
|