@seafile/sdoc-editor 0.5.47 → 0.5.48
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/sdoc-editor-plugins.css +2 -1
- package/dist/basic-sdk/extension/plugins/file-link/helpers.js +0 -8
- package/dist/basic-sdk/extension/plugins/html/rules/text.js +4 -1
- package/dist/basic-sdk/extension/plugins/image/helpers.js +24 -1
- package/dist/basic-sdk/extension/plugins/image/render-elem.js +5 -1
- package/dist/basic-sdk/extension/plugins/sdoc-link/helpers.js +0 -7
- package/dist/utils/base64-to-unit8array.js +15 -0
- package/package.json +1 -1
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
.sdoc-editor-container .article .sdoc-checkbox-container .sdoc-checkbox-input-wrapper .sdoc-checkbox-content-container {
|
|
51
|
-
word-break:normal;
|
|
51
|
+
word-break: normal;
|
|
52
52
|
width: calc(100% - 1em);
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
position: relative;
|
|
58
58
|
display: inline-block;
|
|
59
59
|
padding: 6px 6px 6px 0;
|
|
60
|
+
margin: 0 0.15em;
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
.sdoc-editor-container .article .sdoc-image-inner {
|
|
@@ -53,16 +53,8 @@ export const insertFileLink = (editor, text, uuid) => {
|
|
|
53
53
|
if (selection == null) return;
|
|
54
54
|
const isCollapsed = Range.isCollapsed(selection);
|
|
55
55
|
if (isCollapsed) {
|
|
56
|
-
// Insert Spaces before and after filelinks for easy operation
|
|
57
|
-
editor.insertText(' ');
|
|
58
56
|
const fileNode = generateFileNode(uuid, text);
|
|
59
57
|
Transforms.insertNodes(editor, fileNode);
|
|
60
|
-
|
|
61
|
-
// Not being able to use insertText directly causes the added Spaces to be added to the linked text, as in the issue above, replaced by insertFragment
|
|
62
|
-
editor.insertFragment([{
|
|
63
|
-
id: slugid.nice(),
|
|
64
|
-
text: ' '
|
|
65
|
-
}]);
|
|
66
58
|
} else {
|
|
67
59
|
const selectedText = Editor.string(editor, selection); // Selected text
|
|
68
60
|
if (selectedText !== text) {
|
|
@@ -2,8 +2,11 @@ import slugid from 'slugid';
|
|
|
2
2
|
const textRule = (element, parseChild) => {
|
|
3
3
|
const {
|
|
4
4
|
nodeName,
|
|
5
|
-
nodeType
|
|
5
|
+
nodeType,
|
|
6
|
+
childNodes
|
|
6
7
|
} = element;
|
|
8
|
+
// If the child node is not a text node, it is processed by the child node
|
|
9
|
+
if (childNodes.length && !((childNodes === null || childNodes === void 0 ? void 0 : childNodes[0]) instanceof Text)) return parseChild(childNodes);
|
|
7
10
|
if (nodeName === 'SPAN') {
|
|
8
11
|
return {
|
|
9
12
|
id: slugid.nice(),
|
|
@@ -2,12 +2,14 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
2
2
|
import urlJoin from 'url-join';
|
|
3
3
|
import { Editor, Range, Transforms, Path, Node } from '@seafile/slate';
|
|
4
4
|
import { ReactEditor } from '@seafile/slate-react';
|
|
5
|
+
import slugId from 'slugid';
|
|
5
6
|
import context from '../../../../context';
|
|
6
7
|
import EventBus from '../../../utils/event-bus';
|
|
7
|
-
import { generateEmptyElement, getNodeType, isTextNode, getParentNode, focusEditor
|
|
8
|
+
import { generateEmptyElement, getNodeType, isTextNode, getParentNode, focusEditor } from '../../core';
|
|
8
9
|
import { isList } from '../../toolbar/side-toolbar/helpers';
|
|
9
10
|
import { COMMENT_EDITOR, INTERNAL_EVENT } from '../../../constants';
|
|
10
11
|
import { CODE_BLOCK, ELEMENT_TYPE, IMAGE, IMAGE_BLOCK, INSERT_POSITION } from '../../constants';
|
|
12
|
+
import base64ToUnit8Array from '../../../../utils/base64-to-unit8array';
|
|
11
13
|
export const isInsertImageMenuDisabled = (editor, readonly) => {
|
|
12
14
|
if (readonly) return true;
|
|
13
15
|
const {
|
|
@@ -178,4 +180,25 @@ export const selectImageWhenSelectPartial = (event, editor, imageNode, isImageSe
|
|
|
178
180
|
}
|
|
179
181
|
});
|
|
180
182
|
focusEditor(editor, focusRange);
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// Upload image when the image is pasted from the clipboard in base64
|
|
186
|
+
export const handleBase64Image = (editor, path, imgData) => {
|
|
187
|
+
const unit8Array = base64ToUnit8Array(imgData.src);
|
|
188
|
+
const blob = new Blob([unit8Array.u8arr], {
|
|
189
|
+
type: unit8Array.mime
|
|
190
|
+
});
|
|
191
|
+
const file = new File([blob], "".concat(slugId.nice(), ".jpg"), {
|
|
192
|
+
type: unit8Array.mime
|
|
193
|
+
});
|
|
194
|
+
context.uploadLocalImage([file]).then(res => {
|
|
195
|
+
const _data = _objectSpread(_objectSpread({}, imgData), {}, {
|
|
196
|
+
src: res[0]
|
|
197
|
+
});
|
|
198
|
+
Transforms.setNodes(editor, {
|
|
199
|
+
data: _data
|
|
200
|
+
}, {
|
|
201
|
+
at: path
|
|
202
|
+
});
|
|
203
|
+
});
|
|
181
204
|
};
|
|
@@ -4,7 +4,7 @@ import { ReactEditor, useSelected, useReadOnly } from '@seafile/slate-react';
|
|
|
4
4
|
import { Transforms, Editor } from '@seafile/slate';
|
|
5
5
|
import classNames from 'classnames';
|
|
6
6
|
import { withTranslation } from 'react-i18next';
|
|
7
|
-
import { getImageURL, selectImageWhenSelectPartial, updateImage } from './helpers';
|
|
7
|
+
import { getImageURL, handleBase64Image, selectImageWhenSelectPartial, updateImage } from './helpers';
|
|
8
8
|
import EventBus from '../../../utils/event-bus';
|
|
9
9
|
import { INTERNAL_EVENT } from '../../../constants';
|
|
10
10
|
import ImageHoverMenu from './hover-menu';
|
|
@@ -171,6 +171,10 @@ const Image = _ref => {
|
|
|
171
171
|
}
|
|
172
172
|
}, [data.src]);
|
|
173
173
|
const onImageLoadError = useCallback(() => {
|
|
174
|
+
// Check is due to the image is pasted from the clipboard in base64
|
|
175
|
+
if (data.src.startsWith('data:image/jpeg;base64')) {
|
|
176
|
+
return handleBase64Image(editor, path, data);
|
|
177
|
+
}
|
|
174
178
|
setIsShowImagePlaceholder(true);
|
|
175
179
|
// External network images do not reload after failure to load
|
|
176
180
|
if (!data.src.startsWith('http')) {
|
|
@@ -60,14 +60,7 @@ export const insertSdocFileLink = (editor, text, uuid) => {
|
|
|
60
60
|
removeShortCutSymbol(editor);
|
|
61
61
|
const sdocFileNode = generateSdocFileNode(uuid, text);
|
|
62
62
|
if (isCollapsed) {
|
|
63
|
-
// Insert Spaces before and after sdoclinks for easy operation
|
|
64
|
-
editor.insertText(' ');
|
|
65
63
|
Transforms.insertNodes(editor, sdocFileNode);
|
|
66
|
-
// Not being able to use insertText directly causes the added Spaces to be added to the linked text, as in the issue above, replaced by insertFragment
|
|
67
|
-
editor.insertFragment([{
|
|
68
|
-
id: slugid.nice(),
|
|
69
|
-
text: ' '
|
|
70
|
-
}]);
|
|
71
64
|
} else {
|
|
72
65
|
const selectedText = Editor.string(editor, selection); // Selected text
|
|
73
66
|
if (selectedText !== text) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const base64ToUnit8Array = base64 => {
|
|
2
|
+
const arr = base64.split(',');
|
|
3
|
+
const mime = arr[0].match(/:(.*?);/)[1];
|
|
4
|
+
const bstr = atob(arr[1]);
|
|
5
|
+
let n = bstr.length;
|
|
6
|
+
const u8arr = new Uint8Array(n);
|
|
7
|
+
while (n--) {
|
|
8
|
+
u8arr[n] = bstr.charCodeAt(n);
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
u8arr,
|
|
12
|
+
mime
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export default base64ToUnit8Array;
|