@seafile/sdoc-editor 1.0.46 → 1.0.47
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/extension/plugins/image/helpers.js +10 -6
- package/dist/basic-sdk/extension/plugins/image/plugin.js +17 -4
- package/dist/basic-sdk/extension/plugins/image/render-elem.js +6 -6
- package/dist/basic-sdk/extension/plugins/seatable-tables/helpers.js +2 -0
- package/dist/basic-sdk/extension/plugins/table/helpers.js +2 -0
- package/dist/pages/sdoc-wiki-editor.js +0 -1
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@ import EventBus from '../../../utils/event-bus';
|
|
|
8
8
|
import { generateEmptyElement, getNodeType, isTextNode, getParentNode, focusEditor } from '../../core';
|
|
9
9
|
import { isList } from '../../toolbar/side-toolbar/helpers';
|
|
10
10
|
import { COMMENT_EDITOR, INTERNAL_EVENT } from '../../../constants';
|
|
11
|
-
import { CODE_BLOCK, ELEMENT_TYPE, IMAGE, IMAGE_BLOCK, INSERT_POSITION } from '../../constants';
|
|
11
|
+
import { CODE_BLOCK, ELEMENT_TYPE, IMAGE, IMAGE_BLOCK, INSERT_POSITION, SUBTITLE, TITLE } from '../../constants';
|
|
12
12
|
import base64ToUnit8Array from '../../../../utils/base64-to-unit8array';
|
|
13
13
|
export const isInsertImageMenuDisabled = (editor, readonly) => {
|
|
14
14
|
if (readonly) return true;
|
|
@@ -26,6 +26,8 @@ export const isInsertImageMenuDisabled = (editor, readonly) => {
|
|
|
26
26
|
}
|
|
27
27
|
if (type === CODE_BLOCK) return true;
|
|
28
28
|
if (type.startsWith('header')) return true;
|
|
29
|
+
if (type === TITLE) return true;
|
|
30
|
+
if (type === SUBTITLE) return true;
|
|
29
31
|
if (Editor.isVoid(editor, n)) return true;
|
|
30
32
|
return false;
|
|
31
33
|
},
|
|
@@ -147,11 +149,13 @@ export const resetCursor = editor => {
|
|
|
147
149
|
Transforms.select(editor, targetPath);
|
|
148
150
|
});
|
|
149
151
|
};
|
|
150
|
-
export const
|
|
151
|
-
if (data.length !== 1) return
|
|
152
|
-
if (Node.string(data[0]).length !== 0) return
|
|
153
|
-
|
|
154
|
-
|
|
152
|
+
export const getSingleImageFromFragment = data => {
|
|
153
|
+
if (data.length !== 1) return null;
|
|
154
|
+
if (Node.string(data[0]).length !== 0) return null;
|
|
155
|
+
const children = data[0].children;
|
|
156
|
+
const images = children.filter(item => (item === null || item === void 0 ? void 0 : item.type) === IMAGE);
|
|
157
|
+
if (images.length !== 1) return null;
|
|
158
|
+
return images[0];
|
|
155
159
|
};
|
|
156
160
|
export const insertImageFiles = (files, editor, targetPath) => {
|
|
157
161
|
context.uploadLocalImage(files).then(fileUrl => {
|
|
@@ -2,11 +2,11 @@ import { Transforms, Path, Editor, Element, Range } from '@seafile/slate';
|
|
|
2
2
|
import toaster from '../../../../components/toast';
|
|
3
3
|
import context from '../../../../context';
|
|
4
4
|
import EventBus from '../../../utils/event-bus';
|
|
5
|
-
import { insertImage, hasSdocImages, getImageData, queryCopyMoveProgressView, resetCursor,
|
|
5
|
+
import { insertImage, hasSdocImages, getImageData, queryCopyMoveProgressView, resetCursor, isInsertImageMenuDisabled, getSingleImageFromFragment } from './helpers';
|
|
6
6
|
import { focusEditor, generateEmptyElement, isBlockAboveEmpty } from '../../core';
|
|
7
7
|
import { getErrorMsg } from '../../../../utils';
|
|
8
8
|
import { getSlateFragmentAttribute } from '../../../utils/document-utils';
|
|
9
|
-
import { INSERT_POSITION, CLIPBOARD_FORMAT_KEY, CLIPBOARD_ORIGIN_SDOC_KEY, IMAGE, IMAGE_BLOCK, PARAGRAPH } from '../../constants';
|
|
9
|
+
import { INSERT_POSITION, CLIPBOARD_FORMAT_KEY, CLIPBOARD_ORIGIN_SDOC_KEY, IMAGE, IMAGE_BLOCK, PARAGRAPH, ELEMENT_TYPE } from '../../constants';
|
|
10
10
|
import { INTERNAL_EVENT } from '../../../constants';
|
|
11
11
|
const withImage = editor => {
|
|
12
12
|
const {
|
|
@@ -70,14 +70,27 @@ const withImage = editor => {
|
|
|
70
70
|
if (data.types && data.types.includes('Files') && data.files[0].type.includes(IMAGE)) {
|
|
71
71
|
context.uploadLocalImage(data.files).then(fileUrl => {
|
|
72
72
|
insertImage(newEditor, fileUrl, editor.selection, INSERT_POSITION.CURRENT);
|
|
73
|
-
resetCursor(newEditor);
|
|
74
73
|
});
|
|
75
74
|
return;
|
|
76
75
|
}
|
|
77
76
|
insertData(data);
|
|
78
77
|
};
|
|
79
78
|
newEditor.insertFragment = data => {
|
|
80
|
-
|
|
79
|
+
const singleImage = getSingleImageFromFragment(data);
|
|
80
|
+
if (singleImage && isInsertImageMenuDisabled(editor)) {
|
|
81
|
+
const path = Editor.path(editor, editor.selection);
|
|
82
|
+
const nextPath = Path.next([path[0]]);
|
|
83
|
+
const p = generateEmptyElement(ELEMENT_TYPE.PARAGRAPH);
|
|
84
|
+
p.children = [singleImage];
|
|
85
|
+
Transforms.insertNodes(editor, p, {
|
|
86
|
+
at: nextPath
|
|
87
|
+
});
|
|
88
|
+
// There will be a space before and after the image
|
|
89
|
+
const imagePath = [...nextPath, 1];
|
|
90
|
+
focusEditor(editor, Path.next(imagePath));
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (singleImage) {
|
|
81
94
|
resetCursor(newEditor);
|
|
82
95
|
}
|
|
83
96
|
return insertFragment(data);
|
|
@@ -201,7 +201,8 @@ const Image = _ref => {
|
|
|
201
201
|
}, attributes, {
|
|
202
202
|
style: _objectSpread({}, style),
|
|
203
203
|
onMouseOver: e => selectImageWhenSelectPartial(e, editor, element, isSelected),
|
|
204
|
-
contentEditable: "true"
|
|
204
|
+
contentEditable: "true",
|
|
205
|
+
suppressContentEditableWarning: true
|
|
205
206
|
}), /*#__PURE__*/React.createElement("img", {
|
|
206
207
|
ref: imageRef,
|
|
207
208
|
src: imagePlaceholder,
|
|
@@ -214,10 +215,10 @@ const Image = _ref => {
|
|
|
214
215
|
}, attributes, {
|
|
215
216
|
style: _objectSpread({}, style),
|
|
216
217
|
onMouseOver: e => selectImageWhenSelectPartial(e, editor, element, isSelected),
|
|
217
|
-
contentEditable: "true"
|
|
218
|
+
contentEditable: "true",
|
|
219
|
+
suppressContentEditableWarning: true
|
|
218
220
|
}), /*#__PURE__*/React.createElement("span", {
|
|
219
|
-
className: "sdoc-image-inner"
|
|
220
|
-
contentEditable: "false"
|
|
221
|
+
className: "sdoc-image-inner"
|
|
221
222
|
}, /*#__PURE__*/React.createElement("span", {
|
|
222
223
|
className: "sdoc-image-content"
|
|
223
224
|
}, /*#__PURE__*/React.createElement("span", {
|
|
@@ -238,8 +239,7 @@ const Image = _ref => {
|
|
|
238
239
|
ref: resizerRef,
|
|
239
240
|
onMouseDown: onResizeStart
|
|
240
241
|
}), isResizing && /*#__PURE__*/React.createElement("span", {
|
|
241
|
-
className: "image-size"
|
|
242
|
-
contentEditable: false
|
|
242
|
+
className: "image-size"
|
|
243
243
|
}, /*#__PURE__*/React.createElement("span", null, t('Width'), ':', parseInt(movingWidth || ((_imageRef$current = imageRef.current) === null || _imageRef$current === void 0 ? void 0 : _imageRef$current.clientWidth))), /*#__PURE__*/React.createElement("span", null, "\xA0\xA0"), /*#__PURE__*/React.createElement("span", null, t('Height'), ':', imageRef.current.clientHeight))), nodeEntry[0].type === IMAGE_BLOCK && show_caption && /*#__PURE__*/React.createElement("input", {
|
|
244
244
|
id: "sdoc-image-caption-input",
|
|
245
245
|
ref: imageCaptionInputRef,
|
|
@@ -18,6 +18,8 @@ export const isInsertSeaTableTableDisabled = (editor, readonly) => {
|
|
|
18
18
|
type = getNodeType(parentNode);
|
|
19
19
|
}
|
|
20
20
|
if (type.startsWith('header')) return true;
|
|
21
|
+
if (type === ELEMENT_TYPE.TITLE) return true;
|
|
22
|
+
if (type === ELEMENT_TYPE.SUBTITLE) return true;
|
|
21
23
|
if (type === ELEMENT_TYPE.CODE_BLOCK) return true;
|
|
22
24
|
if (type === ELEMENT_TYPE.ORDERED_LIST) return true;
|
|
23
25
|
if (type === ELEMENT_TYPE.UNORDERED_LIST) return true;
|
|
@@ -25,6 +25,8 @@ export const isTableMenuDisabled = (editor, readonly) => {
|
|
|
25
25
|
type = getNodeType(parentNode);
|
|
26
26
|
}
|
|
27
27
|
if (type.startsWith('header')) return true;
|
|
28
|
+
if (type === ELEMENT_TYPE.TITLE) return true;
|
|
29
|
+
if (type === ELEMENT_TYPE.SUBTITLE) return true;
|
|
28
30
|
if (type === ELEMENT_TYPE.CODE_BLOCK) return true;
|
|
29
31
|
if (type === ELEMENT_TYPE.ORDERED_LIST) return true;
|
|
30
32
|
if (type === ELEMENT_TYPE.UNORDERED_LIST) return true;
|
|
@@ -6,7 +6,6 @@ import { PAGE_EDIT_AREA_WIDTH, WIKI_EDITOR } from '../basic-sdk/constants';
|
|
|
6
6
|
import { createWikiEditor } from '../basic-sdk/extension';
|
|
7
7
|
import withNodeId from '../basic-sdk/node-id';
|
|
8
8
|
import { withSocketIO } from '../basic-sdk/socket';
|
|
9
|
-
import { TITLE } from '../basic-sdk/extension/constants';
|
|
10
9
|
import WikiEditor from '../basic-sdk/editor/wiki-editor';
|
|
11
10
|
import '../assets/css/simple-viewer.css';
|
|
12
11
|
const SdocWikiEditor = _ref => {
|