@seafile/sdoc-editor 0.1.135 → 0.1.137
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/default.css +1 -1
- package/dist/basic-sdk/editor.js +3 -1
- package/dist/basic-sdk/extension/index.js +10 -0
- package/dist/basic-sdk/extension/plugins/code-block/plugin.js +1 -2
- package/dist/basic-sdk/extension/plugins/header/helpers.js +3 -8
- package/dist/basic-sdk/extension/plugins/table/menu/table-menu/index.js +1 -1
- package/dist/basic-sdk/views/viewer.js +6 -4
- package/package.json +1 -1
package/dist/basic-sdk/editor.js
CHANGED
|
@@ -2,7 +2,7 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
|
2
2
|
import React, { useEffect, useMemo, useState, forwardRef, useImperativeHandle } from 'react';
|
|
3
3
|
import { Editor } from '@seafile/slate';
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
5
|
-
import
|
|
5
|
+
import { createDefaultEditor } from './extension';
|
|
6
6
|
import { focusEditor } from './extension/core';
|
|
7
7
|
import { withSocketIO } from './socket';
|
|
8
8
|
import withNodeId from './node-id';
|
|
@@ -18,6 +18,7 @@ var SDocEditor = forwardRef(function (_ref, ref) {
|
|
|
18
18
|
|
|
19
19
|
// init editor
|
|
20
20
|
var editor = useMemo(function () {
|
|
21
|
+
var defaultEditor = createDefaultEditor();
|
|
21
22
|
var newEditor = withNodeId(withSocketIO(defaultEditor, {
|
|
22
23
|
document: document,
|
|
23
24
|
config: config
|
|
@@ -25,6 +26,7 @@ var SDocEditor = forwardRef(function (_ref, ref) {
|
|
|
25
26
|
var cursors = document.cursors;
|
|
26
27
|
newEditor.cursors = cursors || {};
|
|
27
28
|
newEditor.width = PAGE_EDIT_AREA_WIDTH; // default width
|
|
29
|
+
newEditor.readonly = false;
|
|
28
30
|
return newEditor;
|
|
29
31
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
30
32
|
}, []);
|
|
@@ -13,5 +13,15 @@ var defaultEditor = Plugins === null || Plugins === void 0 ? void 0 : Plugins.re
|
|
|
13
13
|
}
|
|
14
14
|
return editor;
|
|
15
15
|
}, baseEditor);
|
|
16
|
+
export var createDefaultEditor = function createDefaultEditor() {
|
|
17
|
+
var defaultEditor = Plugins === null || Plugins === void 0 ? void 0 : Plugins.reduce(function (editor, pluginItem) {
|
|
18
|
+
var withPlugin = pluginItem.editorPlugin;
|
|
19
|
+
if (withPlugin) {
|
|
20
|
+
return withPlugin(editor);
|
|
21
|
+
}
|
|
22
|
+
return editor;
|
|
23
|
+
}, withHistory(withReact(createEditor())));
|
|
24
|
+
return defaultEditor;
|
|
25
|
+
};
|
|
16
26
|
export default defaultEditor;
|
|
17
27
|
export { renderLeaf, renderElement, Toolbar, ContextToolbar, SideToolbar };
|
|
@@ -25,7 +25,7 @@ var withCodeBlock = function withCodeBlock(editor) {
|
|
|
25
25
|
return insertText(data);
|
|
26
26
|
};
|
|
27
27
|
newEditor.insertData = function (data) {
|
|
28
|
-
if (!newEditor.insertFragmentData(data)) {
|
|
28
|
+
if (!newEditor.insertFragmentData(data) && !data.types.includes('text/code-block')) {
|
|
29
29
|
var plaintext = data.getData('text/plain') || '';
|
|
30
30
|
if (plaintext) {
|
|
31
31
|
var fragmentData = [];
|
|
@@ -48,7 +48,6 @@ var withCodeBlock = function withCodeBlock(editor) {
|
|
|
48
48
|
var codeBlockNode = JSON.parse(data.getData('text/code-block'));
|
|
49
49
|
return insertNode(codeBlockNode);
|
|
50
50
|
}
|
|
51
|
-
return insertData(data);
|
|
52
51
|
};
|
|
53
52
|
newEditor.insertFragment = function (data) {
|
|
54
53
|
// only selected code block content
|
|
@@ -48,12 +48,7 @@ export var getHeaderType = function getHeaderType(editor) {
|
|
|
48
48
|
};
|
|
49
49
|
export var setHeaderType = function setHeaderType(editor, type) {
|
|
50
50
|
if (!type) return;
|
|
51
|
-
|
|
52
|
-
type: type
|
|
53
|
-
|
|
54
|
-
};
|
|
55
|
-
if (type === TITLE || type === SUBTITLE) {
|
|
56
|
-
newProperties['align'] = 'center';
|
|
57
|
-
}
|
|
58
|
-
Transforms.setNodes(editor, newProperties);
|
|
51
|
+
Transforms.setNodes(editor, {
|
|
52
|
+
type: type
|
|
53
|
+
});
|
|
59
54
|
};
|
|
@@ -30,7 +30,7 @@ var TableMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
30
30
|
};
|
|
31
31
|
_this.createTable = function (size) {
|
|
32
32
|
var editor = _this.props.editor;
|
|
33
|
-
insertTable(editor, size,
|
|
33
|
+
insertTable(editor, size, editor.selection);
|
|
34
34
|
};
|
|
35
35
|
return _this;
|
|
36
36
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import React, { Fragment,
|
|
2
|
-
import classnames from 'classnames';
|
|
1
|
+
import React, { Fragment, useMemo } from 'react';
|
|
3
2
|
import { Editable, Slate } from '@seafile/slate-react';
|
|
4
|
-
import
|
|
3
|
+
import { renderLeaf as _renderLeaf, renderElement as _renderElement, createDefaultEditor } from '../extension';
|
|
5
4
|
import withNodeId from '../node-id';
|
|
6
5
|
import { generateDefaultDocContent } from '../../utils';
|
|
7
6
|
import { SetNodeToDecorations } from '../highlight-decorate/setNodeToDecorations';
|
|
@@ -14,7 +13,10 @@ var SDocViewer = function SDocViewer(_ref) {
|
|
|
14
13
|
customRenderElement = _ref.renderElement,
|
|
15
14
|
showToolbar = _ref.showToolbar,
|
|
16
15
|
showOutline = _ref.showOutline;
|
|
17
|
-
var editor =
|
|
16
|
+
var editor = useMemo(function () {
|
|
17
|
+
var defaultEditor = createDefaultEditor();
|
|
18
|
+
return withNodeId(defaultEditor);
|
|
19
|
+
}, []);
|
|
18
20
|
editor.readonly = true;
|
|
19
21
|
var slateValue = (document || generateDefaultDocContent()).children;
|
|
20
22
|
var decorate = usePipDecorate(editor);
|