@seafile/sdoc-editor 0.1.51 → 0.1.53
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
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
2
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
4
|
-
import { Node
|
|
3
|
+
import { Node } from '@seafile/slate';
|
|
5
4
|
import { Editable, Slate, ReactEditor } from '@seafile/slate-react';
|
|
6
5
|
import defaultEditor, { renderLeaf, renderElement, Toolbar, ContextMenu } from './extension';
|
|
7
6
|
import { focusEditor } from './extension/core';
|
|
@@ -26,6 +25,20 @@ var SDocEditor = function SDocEditor(_ref) {
|
|
|
26
25
|
return newEditor;
|
|
27
26
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
28
27
|
}, []);
|
|
28
|
+
var _useState = useState(document.children),
|
|
29
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
30
|
+
slateValue = _useState2[0],
|
|
31
|
+
setSlateValue = _useState2[1];
|
|
32
|
+
var _useState3 = useState(false),
|
|
33
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
34
|
+
isShowContextMenu = _useState4[0],
|
|
35
|
+
setContextMenu = _useState4[1];
|
|
36
|
+
var _useState5 = useState({}),
|
|
37
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
38
|
+
menuPosition = _useState6[0],
|
|
39
|
+
setMenuPosition = _useState6[1];
|
|
40
|
+
var _useCursors = useCursors(editor),
|
|
41
|
+
cursors = _useCursors.cursors;
|
|
29
42
|
|
|
30
43
|
// init eventHandler
|
|
31
44
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -50,28 +63,6 @@ var SDocEditor = function SDocEditor(_ref) {
|
|
|
50
63
|
}
|
|
51
64
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
52
65
|
}, []);
|
|
53
|
-
|
|
54
|
-
// handle placeholder
|
|
55
|
-
var onDOMBeforeInput = useCallback(function (e) {
|
|
56
|
-
if (e.data && e.data !== '') {
|
|
57
|
-
var _node$;
|
|
58
|
-
var node = Editor.parent(editor, editor.selection);
|
|
59
|
-
editor.onDOMBeforeInputId = (_node$ = node[0]) === null || _node$ === void 0 ? void 0 : _node$.id;
|
|
60
|
-
setSlateValue(_toConsumableArray(slateValue));
|
|
61
|
-
} else {
|
|
62
|
-
editor.onDOMBeforeInputId = null;
|
|
63
|
-
setSlateValue(_toConsumableArray(slateValue));
|
|
64
|
-
}
|
|
65
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
66
|
-
}, []);
|
|
67
|
-
var _useState = useState(false),
|
|
68
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
69
|
-
isShowContextMenu = _useState2[0],
|
|
70
|
-
setContextMenu = _useState2[1];
|
|
71
|
-
var _useState3 = useState({}),
|
|
72
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
73
|
-
menuPosition = _useState4[0],
|
|
74
|
-
setMenuPosition = _useState4[1];
|
|
75
66
|
var onContextMenu = useCallback(function (event) {
|
|
76
67
|
if (editor.isAllInTable()) {
|
|
77
68
|
event.preventDefault();
|
|
@@ -84,17 +75,11 @@ var SDocEditor = function SDocEditor(_ref) {
|
|
|
84
75
|
}
|
|
85
76
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
86
77
|
}, []);
|
|
87
|
-
var _useState5 = useState(document.children),
|
|
88
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
89
|
-
slateValue = _useState6[0],
|
|
90
|
-
setSlateValue = _useState6[1];
|
|
91
78
|
var onChange = useCallback(function (slateValue) {
|
|
92
79
|
setSlateValue(slateValue);
|
|
93
80
|
setContextMenu(false);
|
|
94
81
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
95
82
|
}, []);
|
|
96
|
-
var _useCursors = useCursors(editor),
|
|
97
|
-
cursors = _useCursors.cursors;
|
|
98
83
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
99
84
|
className: "sdoc-editor-container"
|
|
100
85
|
}, /*#__PURE__*/React.createElement(Toolbar, {
|
|
@@ -116,7 +101,6 @@ var SDocEditor = function SDocEditor(_ref) {
|
|
|
116
101
|
renderElement: renderElement,
|
|
117
102
|
renderLeaf: renderLeaf,
|
|
118
103
|
onKeyDown: eventProxy.onKeyDown,
|
|
119
|
-
onDOMBeforeInput: onDOMBeforeInput,
|
|
120
104
|
cursors: cursors,
|
|
121
105
|
onContextMenu: onContextMenu
|
|
122
106
|
})))))), isShowContextMenu && /*#__PURE__*/React.createElement(ContextMenu, {
|
|
@@ -4,13 +4,14 @@ import { Placeholder } from '../../core';
|
|
|
4
4
|
var renderHeader = function renderHeader(props, editor) {
|
|
5
5
|
var element = props.element,
|
|
6
6
|
attributes = props.attributes,
|
|
7
|
-
children = props.children
|
|
7
|
+
children = props.children,
|
|
8
|
+
isComposing = props.isComposing;
|
|
8
9
|
var type = element.type;
|
|
9
10
|
var level = type.split('header')[1];
|
|
10
11
|
var Tag = "h".concat(level);
|
|
11
12
|
var isShowPlaceHolder = false;
|
|
12
13
|
var firstChild = editor.children[0];
|
|
13
|
-
if (firstChild.id === element.id && Node.string(element) === '' &&
|
|
14
|
+
if (firstChild.id === element.id && Node.string(element) === '' && !isComposing) {
|
|
14
15
|
isShowPlaceHolder = true;
|
|
15
16
|
}
|
|
16
17
|
return /*#__PURE__*/React.createElement(Tag, Object.assign({
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { Node
|
|
3
|
+
import { Node } from '@seafile/slate';
|
|
4
4
|
import { useSlateStatic } from '@seafile/slate-react';
|
|
5
5
|
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';
|
|
6
6
|
import { BlockquotePlugin, LinkPlugin, CheckListPlugin, HeaderPlugin, ListPlugin, CodeBlockPlugin, ImagePlugin, TablePlugin } from '../plugins';
|
|
7
|
-
import { Placeholder
|
|
7
|
+
import { Placeholder } from '../core';
|
|
8
8
|
var CustomElement = function CustomElement(props) {
|
|
9
9
|
var editor = useSlateStatic();
|
|
10
10
|
var attributes = props.attributes,
|
|
@@ -14,22 +14,13 @@ var CustomElement = function CustomElement(props) {
|
|
|
14
14
|
case PARAGRAPH:
|
|
15
15
|
{
|
|
16
16
|
var isShowPlaceHolder = false;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (firstParagraphNode) {
|
|
25
|
-
var _firstParagraphNode = _slicedToArray(firstParagraphNode, 2),
|
|
26
|
-
node = _firstParagraphNode[0],
|
|
27
|
-
path = _firstParagraphNode[1];
|
|
28
|
-
var nextNode = Editor.next(editor, {
|
|
29
|
-
at: path
|
|
30
|
-
});
|
|
31
|
-
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);
|
|
32
|
-
}
|
|
17
|
+
var isComposing = props.isComposing;
|
|
18
|
+
if (editor.children.length === 1) {
|
|
19
|
+
isShowPlaceHolder = Node.string(element) === '' && !isComposing;
|
|
20
|
+
}
|
|
21
|
+
if (editor.children.length === 2 && editor.children[0].type.startsWith('header')) {
|
|
22
|
+
var node = editor.children[1];
|
|
23
|
+
isShowPlaceHolder = Node.string(element) === '' && (node === null || node === void 0 ? void 0 : node.id) === (element === null || element === void 0 ? void 0 : element.id) && !isComposing;
|
|
33
24
|
}
|
|
34
25
|
return /*#__PURE__*/React.createElement("p", Object.assign({
|
|
35
26
|
"data-id": element.id
|
|
@@ -54,20 +54,17 @@ export var decorateOperation = function decorateOperation(editor, operation) {
|
|
|
54
54
|
}
|
|
55
55
|
case OPERATION.SET_NODE:
|
|
56
56
|
{
|
|
57
|
-
var
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
// newProperties none has id attribute, keep the original id
|
|
61
|
-
newProperties.id = _properties.id;
|
|
62
|
-
newOperation['node_id'] = _properties.id; // the node which will be set to another type
|
|
57
|
+
var _path5 = newOperation.path;
|
|
58
|
+
var _node5 = Node.get(editor, _path5);
|
|
59
|
+
newOperation['node_id'] = _node5.id; // the node which will be set to another type
|
|
63
60
|
break;
|
|
64
61
|
}
|
|
65
62
|
case OPERATION.MOVE_NODE:
|
|
66
63
|
{
|
|
67
|
-
var
|
|
68
|
-
var
|
|
64
|
+
var _path6 = newOperation.path;
|
|
65
|
+
var _node6 = Node.get(editor, _path6);
|
|
69
66
|
// move operation not change the node's id
|
|
70
|
-
newOperation['node_id'] =
|
|
67
|
+
newOperation['node_id'] = _node6.id; // moved node's id
|
|
71
68
|
break;
|
|
72
69
|
}
|
|
73
70
|
default:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seafile/sdoc-editor",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.53",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "This is a sdoc editor",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"@seafile/slate": "0.91.8",
|
|
10
10
|
"@seafile/slate-history": "0.86.2",
|
|
11
11
|
"@seafile/slate-hyperscript": "0.81.7",
|
|
12
|
-
"@seafile/slate-react": "0.92.
|
|
12
|
+
"@seafile/slate-react": "0.92.6",
|
|
13
13
|
"ahooks": "3.7.7",
|
|
14
14
|
"classnames": "2.3.2",
|
|
15
15
|
"deep-copy": "1.4.2",
|