@seafile/sdoc-editor 0.3.28 → 0.4.0
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/api/seafile-api.js +7 -5
- package/dist/basic-sdk/extension/plugins/image/helpers.js +5 -0
- package/dist/basic-sdk/extension/plugins/sdoc-link/helpers.js +9 -3
- package/dist/basic-sdk/extension/plugins/sdoc-link/plugin.js +2 -2
- package/dist/basic-sdk/extension/toolbar/side-toolbar/index.js +8 -0
- package/dist/components/doc-operations/revision-operations/index.js +7 -1
- package/package.json +1 -1
package/dist/api/seafile-api.js
CHANGED
|
@@ -33,11 +33,13 @@ class SeafileAPI {
|
|
|
33
33
|
const url = '/api/v2.1/seadoc/upload-image/' + docUuid + '/';
|
|
34
34
|
const form = new FormData();
|
|
35
35
|
for (const fileItem of imageFiles) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
if (fileItem.type.startsWith('image/')) {
|
|
37
|
+
const fileName = this.getImageFileNameWithTimestamp(fileItem);
|
|
38
|
+
const file = new File([fileItem], fileName, {
|
|
39
|
+
type: fileItem.type
|
|
40
|
+
});
|
|
41
|
+
form.append('file', file);
|
|
42
|
+
}
|
|
41
43
|
}
|
|
42
44
|
return this.req.post(url, form);
|
|
43
45
|
}
|
|
@@ -141,4 +141,9 @@ export const isSingleImage = data => {
|
|
|
141
141
|
if (Node.string(data[0]).length !== 0) return false;
|
|
142
142
|
if (data[0].children.filter(item => (item === null || item === void 0 ? void 0 : item.type) === IMAGE).length !== 1) return false;
|
|
143
143
|
return true;
|
|
144
|
+
};
|
|
145
|
+
export const insertImageFiles = (files, editor, targetPath) => {
|
|
146
|
+
context.uploadLocalImage(files).then(fileUrl => {
|
|
147
|
+
insertImage(editor, fileUrl, targetPath, INSERT_POSITION.AFTER);
|
|
148
|
+
});
|
|
144
149
|
};
|
|
@@ -151,10 +151,16 @@ export const getBeforeText = editor => {
|
|
|
151
151
|
};
|
|
152
152
|
};
|
|
153
153
|
export const isTriggeredByShortCut = editor => {
|
|
154
|
+
const {
|
|
155
|
+
selection
|
|
156
|
+
} = editor;
|
|
157
|
+
const {
|
|
158
|
+
anchor
|
|
159
|
+
} = selection;
|
|
154
160
|
const {
|
|
155
161
|
beforeText
|
|
156
162
|
} = getBeforeText(editor);
|
|
157
|
-
return beforeText.slice(-
|
|
163
|
+
return beforeText.slice(-1) === '[' && Editor.isEnd(editor, anchor, anchor.path);
|
|
158
164
|
};
|
|
159
165
|
|
|
160
166
|
// If insert operation is triggered by shortcut, remove the '[[' symbol
|
|
@@ -167,12 +173,12 @@ export const removeShortCutSymbol = editor => {
|
|
|
167
173
|
beforeText,
|
|
168
174
|
range: beforeRange
|
|
169
175
|
} = getBeforeText(editor);
|
|
170
|
-
const isTrrigeredByShortCut = beforeText.slice(-
|
|
176
|
+
const isTrrigeredByShortCut = beforeText.slice(-2) === '[[';
|
|
171
177
|
isTrrigeredByShortCut && Transforms.delete(editor, {
|
|
172
178
|
at: {
|
|
173
179
|
anchor: {
|
|
174
180
|
path: beforeRange.focus.path,
|
|
175
|
-
offset: beforeText.length -
|
|
181
|
+
offset: beforeText.length - 2
|
|
176
182
|
},
|
|
177
183
|
focus: _objectSpread({}, selection.focus)
|
|
178
184
|
},
|
|
@@ -49,8 +49,8 @@ const withSdocLink = editor => {
|
|
|
49
49
|
const {
|
|
50
50
|
key
|
|
51
51
|
} = event;
|
|
52
|
-
if (key !== '
|
|
53
|
-
// If user press
|
|
52
|
+
if (key !== '[') return onHotKeyDown && onHotKeyDown(event);
|
|
53
|
+
// If user press '[[', open file modal
|
|
54
54
|
const eventBus = EventBus.getInstance();
|
|
55
55
|
if (isTriggeredByShortCut(newEditor)) {
|
|
56
56
|
eventBus.dispatch(INTERNAL_EVENT.INSERT_ELEMENT, {
|
|
@@ -7,6 +7,7 @@ import EventBus from '../../../utils/event-bus';
|
|
|
7
7
|
import { useScrollContext } from '../../../hooks/use-scroll-context';
|
|
8
8
|
import { focusEditor } from '../../core';
|
|
9
9
|
import { getDomTopHeight, setSelection, isVoidNode, getNodeEntry, isBlockquote, isList, onWrapListItem } from './helpers';
|
|
10
|
+
import { insertImageFiles } from '../../plugins/image/helpers';
|
|
10
11
|
import { INTERNAL_EVENT } from '../../../constants';
|
|
11
12
|
import { CODE_BLOCK, TABLE, BLOCKQUOTE, CHECK_LIST_ITEM, CALL_OUT } from '../../constants';
|
|
12
13
|
import { getCalloutEntry } from '../../plugins/callout/helper';
|
|
@@ -106,6 +107,13 @@ const SideToolbar = () => {
|
|
|
106
107
|
const drop = useCallback(event => {
|
|
107
108
|
targetElement = event.currentTarget;
|
|
108
109
|
targetElement.classList.remove('sdoc-draging');
|
|
110
|
+
|
|
111
|
+
// Drag local image files to sdoc
|
|
112
|
+
if (event.dataTransfer.files.length > 0) {
|
|
113
|
+
const [, targetPath] = getNodeEntry(editor, targetElement);
|
|
114
|
+
insertImageFiles(event.dataTransfer.files, editor, targetPath);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
109
117
|
const [sourceNode, sourcePath] = getNodeEntry(editor, sourceElement);
|
|
110
118
|
const [, targetPath] = getNodeEntry(editor, targetElement);
|
|
111
119
|
|
|
@@ -28,6 +28,7 @@ const RevisionOperations = _ref => {
|
|
|
28
28
|
const [isShowTip, setShowTip] = useState(false);
|
|
29
29
|
const [tipType, setTipType] = useState('');
|
|
30
30
|
const [mergeValue, setMergeValue] = useState(null);
|
|
31
|
+
const [isLoading, setLoading] = useState(false);
|
|
31
32
|
const {
|
|
32
33
|
loadDocument
|
|
33
34
|
} = useDocument();
|
|
@@ -72,6 +73,8 @@ const RevisionOperations = _ref => {
|
|
|
72
73
|
|
|
73
74
|
// solve show change view in revision editor
|
|
74
75
|
const onViewChangesToggle = useCallback(isShowChanges => {
|
|
76
|
+
if (isLoading) return;
|
|
77
|
+
setLoading(true);
|
|
75
78
|
if (!isPublished && isShowChanges) {
|
|
76
79
|
// The trick here is to send one more api request in order to use the same information box.
|
|
77
80
|
loadDocument().then(revisionContent => {
|
|
@@ -82,13 +85,16 @@ const RevisionOperations = _ref => {
|
|
|
82
85
|
} else {
|
|
83
86
|
handleViewChangesToggle(isShowChanges);
|
|
84
87
|
}
|
|
88
|
+
setLoading(false);
|
|
85
89
|
}).catch(errorMessage => {
|
|
86
90
|
toaster.danger(t(errorMessage));
|
|
91
|
+
setLoading(false);
|
|
87
92
|
});
|
|
88
93
|
return;
|
|
89
94
|
}
|
|
90
95
|
handleViewChangesToggle(isShowChanges);
|
|
91
|
-
|
|
96
|
+
setLoading(false);
|
|
97
|
+
}, [handleViewChangesToggle, loadDocument, t, isPublished, isLoading]);
|
|
92
98
|
|
|
93
99
|
// publish revision
|
|
94
100
|
const publishRevision = useCallback(() => {
|