@seafile/sdoc-editor 0.1.41 → 0.1.43
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/editor.js +24 -3
- package/dist/basic-sdk/extension/core/utils/index.js +21 -1
- package/dist/basic-sdk/extension/plugins/blockquote/helpers.js +2 -1
- package/dist/basic-sdk/extension/plugins/header/plugin.js +12 -0
- package/dist/basic-sdk/extension/plugins/header/render-elem.js +14 -1
- package/dist/basic-sdk/extension/plugins/table/dialog/custom-table-size-dialog/index.js +2 -2
- package/dist/basic-sdk/extension/render/render-element.js +31 -3
- package/package.json +1 -1
- package/public/locales/en/sdoc-editor.json +3 -1
- package/public/locales/zh-CN/sdoc-editor.json +3 -1
package/dist/basic-sdk/editor.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
1
2
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
3
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
4
|
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
4
5
|
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
5
6
|
import React from 'react';
|
|
6
|
-
import { Editable, Slate } from '@seafile/slate-react';
|
|
7
|
+
import { Editable, Slate, ReactEditor } from '@seafile/slate-react';
|
|
8
|
+
import { Editor } from '@seafile/slate';
|
|
7
9
|
import editor, { renderLeaf as _renderLeaf, renderElement as _renderElement, Toolbar } from './extension';
|
|
8
10
|
import { SocketManager, withSocketIO } from './socket';
|
|
9
11
|
import withNodeId from './node-id';
|
|
10
12
|
import SDocOutline from './outline';
|
|
11
13
|
import EventProxy from './utils/event-handler';
|
|
14
|
+
import { focusEditor } from './extension/core';
|
|
12
15
|
import './assets/css/layout.css';
|
|
13
16
|
import './assets/css/sdoc-editor-plugins.css';
|
|
14
17
|
var SDocEditor = /*#__PURE__*/function (_React$Component) {
|
|
@@ -28,6 +31,22 @@ var SDocEditor = /*#__PURE__*/function (_React$Component) {
|
|
|
28
31
|
});
|
|
29
32
|
onValueChanged && onValueChanged(slateValue);
|
|
30
33
|
};
|
|
34
|
+
_this.onDOMBeforeInput = function (e) {
|
|
35
|
+
var slateValue = _this.state.slateValue;
|
|
36
|
+
if (e.data && e.data !== '') {
|
|
37
|
+
var _node$;
|
|
38
|
+
var node = Editor.parent(_this.editor, editor.selection);
|
|
39
|
+
_this.editor.onDOMBeforeInputId = (_node$ = node[0]) === null || _node$ === void 0 ? void 0 : _node$.id;
|
|
40
|
+
_this.setState({
|
|
41
|
+
slateValue: _toConsumableArray(slateValue)
|
|
42
|
+
});
|
|
43
|
+
} else {
|
|
44
|
+
_this.editor.onDOMBeforeInputId = null;
|
|
45
|
+
_this.setState({
|
|
46
|
+
slateValue: _toConsumableArray(slateValue)
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
31
50
|
var children = props.document.children;
|
|
32
51
|
_this.state = {
|
|
33
52
|
slateValue: children,
|
|
@@ -51,6 +70,8 @@ var SDocEditor = /*#__PURE__*/function (_React$Component) {
|
|
|
51
70
|
if (isOpenSocket) {
|
|
52
71
|
this.socketManager = SocketManager.getInstance(this.editor, document, config);
|
|
53
72
|
}
|
|
73
|
+
var firstNodepath = ReactEditor.findPath(editor, this.editor.children[0]);
|
|
74
|
+
focusEditor(this.editor, firstNodepath);
|
|
54
75
|
}
|
|
55
76
|
}, {
|
|
56
77
|
key: "componentWillUnmount",
|
|
@@ -83,14 +104,14 @@ var SDocEditor = /*#__PURE__*/function (_React$Component) {
|
|
|
83
104
|
}, /*#__PURE__*/React.createElement("div", {
|
|
84
105
|
className: "article"
|
|
85
106
|
}, /*#__PURE__*/React.createElement(Editable, {
|
|
86
|
-
placeholder: "Enter some text...",
|
|
87
107
|
renderElement: function renderElement(props) {
|
|
88
108
|
return _renderElement(props, _this2.editor);
|
|
89
109
|
},
|
|
90
110
|
renderLeaf: function renderLeaf(props) {
|
|
91
111
|
return _renderLeaf(props, _this2.editor);
|
|
92
112
|
},
|
|
93
|
-
onKeyDown: this.eventProxy.onKeyDown
|
|
113
|
+
onKeyDown: this.eventProxy.onKeyDown,
|
|
114
|
+
onDOMBeforeInput: this.onDOMBeforeInput
|
|
94
115
|
}))))));
|
|
95
116
|
}
|
|
96
117
|
}]);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import React from 'react';
|
|
2
3
|
import slugid from 'slugid';
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
3
5
|
export var match = function match(node, path, predicate) {
|
|
4
6
|
if (!predicate) return true;
|
|
5
7
|
if (typeof predicate === 'object') {
|
|
@@ -24,4 +26,22 @@ export var generateEmptyElement = function generateEmptyElement(type) {
|
|
|
24
26
|
text: ''
|
|
25
27
|
}]
|
|
26
28
|
};
|
|
27
|
-
};
|
|
29
|
+
};
|
|
30
|
+
export function Placeholder(props) {
|
|
31
|
+
var title = props.title;
|
|
32
|
+
var _useTranslation = useTranslation(),
|
|
33
|
+
t = _useTranslation.t;
|
|
34
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
35
|
+
style: {
|
|
36
|
+
position: 'absolute',
|
|
37
|
+
top: '0px',
|
|
38
|
+
color: 'rgba(191,191,191,1)',
|
|
39
|
+
pointerEvents: 'none',
|
|
40
|
+
width: '100%',
|
|
41
|
+
maxWidth: '100%',
|
|
42
|
+
display: 'block',
|
|
43
|
+
userSelect: 'none',
|
|
44
|
+
textDecoration: 'none'
|
|
45
|
+
}
|
|
46
|
+
}, t(title));
|
|
47
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
2
|
import { Editor, Transforms } from '@seafile/slate';
|
|
3
3
|
import { BLOCKQUOTE } from '../../constants';
|
|
4
|
-
import { getNodeType } from '../../core';
|
|
4
|
+
import { focusEditor, getNodeType } from '../../core';
|
|
5
5
|
export var isMenuDisabled = function isMenuDisabled(editor) {
|
|
6
6
|
if (editor.selection == null) return true;
|
|
7
7
|
var _Editor$nodes = Editor.nodes(editor, {
|
|
@@ -46,4 +46,5 @@ export var setBlockQuoteType = function setBlockQuoteType(editor, type) {
|
|
|
46
46
|
}, {
|
|
47
47
|
mode: 'highest'
|
|
48
48
|
});
|
|
49
|
+
focusEditor(editor);
|
|
49
50
|
};
|
|
@@ -29,6 +29,18 @@ var withHeader = function withHeader(editor) {
|
|
|
29
29
|
insertBreak();
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
|
+
var nextNode = Editor.next(editor, {
|
|
33
|
+
at: match[1]
|
|
34
|
+
});
|
|
35
|
+
if (nextNode) {
|
|
36
|
+
var _nextNode = _slicedToArray(nextNode, 2),
|
|
37
|
+
node = _nextNode[0],
|
|
38
|
+
path = _nextNode[1];
|
|
39
|
+
if (node && node.children[0].text === '') {
|
|
40
|
+
Transforms.select(editor, path);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
32
44
|
var isAtLineEnd = isSelectionAtLineEnd(editor, match[1]);
|
|
33
45
|
|
|
34
46
|
// 如果在行末插入一个空 p,否则正常换行
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { Node } from '@seafile/slate';
|
|
3
|
+
import { Placeholder } from '../../core';
|
|
2
4
|
var renderHeader = function renderHeader(props, editor) {
|
|
3
5
|
var element = props.element,
|
|
4
6
|
attributes = props.attributes,
|
|
@@ -6,9 +8,20 @@ var renderHeader = function renderHeader(props, editor) {
|
|
|
6
8
|
var type = element.type;
|
|
7
9
|
var level = type.split('header')[1];
|
|
8
10
|
var Tag = "h".concat(level);
|
|
11
|
+
var isShowPlaceHolder = false;
|
|
12
|
+
var firstChild = editor.children[0];
|
|
13
|
+
if (firstChild.id === element.id && Node.string(element) === '' && (editor === null || editor === void 0 ? void 0 : editor.onDOMBeforeInputId) !== (element === null || element === void 0 ? void 0 : element.id)) {
|
|
14
|
+
isShowPlaceHolder = true;
|
|
15
|
+
}
|
|
9
16
|
return /*#__PURE__*/React.createElement(Tag, Object.assign({
|
|
10
17
|
id: element.id,
|
|
11
18
|
"data-id": element.id
|
|
12
|
-
}, attributes
|
|
19
|
+
}, attributes, {
|
|
20
|
+
style: {
|
|
21
|
+
position: isShowPlaceHolder ? 'relative' : ''
|
|
22
|
+
}
|
|
23
|
+
}), isShowPlaceHolder && /*#__PURE__*/React.createElement(Placeholder, {
|
|
24
|
+
title: 'Please_enter_the_title'
|
|
25
|
+
}), children);
|
|
13
26
|
};
|
|
14
27
|
export default renderHeader;
|
|
@@ -79,10 +79,10 @@ var CustomTableSizeDialog = /*#__PURE__*/function (_Component) {
|
|
|
79
79
|
})))), /*#__PURE__*/React.createElement(ModalFooter, null, /*#__PURE__*/React.createElement(Button, {
|
|
80
80
|
color: "secondary",
|
|
81
81
|
onClick: this.toggle
|
|
82
|
-
}, t('
|
|
82
|
+
}, t('cancel')), /*#__PURE__*/React.createElement(Button, {
|
|
83
83
|
color: "primary",
|
|
84
84
|
onClick: this.handleSubmit
|
|
85
|
-
}, t('
|
|
85
|
+
}, t('submit'))));
|
|
86
86
|
}
|
|
87
87
|
}]);
|
|
88
88
|
return CustomTableSizeDialog;
|
|
@@ -1,16 +1,44 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
2
|
import React from 'react';
|
|
3
|
+
import { Node, Editor } from '@seafile/slate';
|
|
3
4
|
import { BLOCKQUOTE, LINK, CHECK_LIST_ITEM, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, LIST_ITEM, LIST_LIC, ORDERED_LIST, PARAGRAPH, UNORDERED_LIST, CODE_BLOCK, IMAGE, ELEMENT_TYPE } from '../constants';
|
|
4
5
|
import { BlockquotePlugin, LinkPlugin, CheckListPlugin, HeaderPlugin, ListPlugin, CodeBlockPlugin, ImagePlugin, TablePlugin } from '../plugins';
|
|
6
|
+
import { Placeholder, findNode } from '../core';
|
|
5
7
|
var renderElement = function renderElement(props, editor) {
|
|
6
8
|
var attributes = props.attributes,
|
|
7
9
|
children = props.children,
|
|
8
10
|
element = props.element;
|
|
9
11
|
switch (element.type) {
|
|
10
12
|
case PARAGRAPH:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
{
|
|
14
|
+
var isShowPlaceHolder = false;
|
|
15
|
+
if (editor.children.length < 3) {
|
|
16
|
+
var firstParagraphNode = findNode(editor, {
|
|
17
|
+
at: [],
|
|
18
|
+
match: function match(node) {
|
|
19
|
+
return node.type === 'paragraph';
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
if (firstParagraphNode) {
|
|
23
|
+
var _firstParagraphNode = _slicedToArray(firstParagraphNode, 2),
|
|
24
|
+
node = _firstParagraphNode[0],
|
|
25
|
+
path = _firstParagraphNode[1];
|
|
26
|
+
var nextNode = Editor.next(editor, {
|
|
27
|
+
at: path
|
|
28
|
+
});
|
|
29
|
+
isShowPlaceHolder = (node === null || node === void 0 ? void 0 : node.id) === (element === null || element === void 0 ? void 0 : element.id) && Node.string(element) === '' && !nextNode && (editor === null || editor === void 0 ? void 0 : editor.onDOMBeforeInputId) !== (element === null || element === void 0 ? void 0 : element.id);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return /*#__PURE__*/React.createElement("p", Object.assign({
|
|
33
|
+
"data-id": element.id
|
|
34
|
+
}, attributes, {
|
|
35
|
+
style: {
|
|
36
|
+
position: isShowPlaceHolder ? 'relative' : ''
|
|
37
|
+
}
|
|
38
|
+
}), children, isShowPlaceHolder && /*#__PURE__*/React.createElement(Placeholder, {
|
|
39
|
+
title: 'Please_enter_the_text'
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
14
42
|
case HEADER1:
|
|
15
43
|
case HEADER2:
|
|
16
44
|
case HEADER3:
|
package/package.json
CHANGED
|
@@ -242,5 +242,7 @@
|
|
|
242
242
|
"Open_link": "Open link",
|
|
243
243
|
"Customize_the_number_of_rows_and_columns": "Customize the number of rows and columns",
|
|
244
244
|
"Rows": "Rows",
|
|
245
|
-
"Columns": "Columns"
|
|
245
|
+
"Columns": "Columns",
|
|
246
|
+
"Please_enter_the_title": "Please enter the title",
|
|
247
|
+
"Please_enter_the_text": "Please enter the text"
|
|
246
248
|
}
|