@seafile/seafile-editor 1.0.61 → 1.0.63
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/editors/simple-slate-editor /index.js +16 -1
- package/dist/editors/slate-editor/style.css +1 -0
- package/dist/editors/slate-viewer/style.css +1 -0
- package/dist/extension/commons/select/menu/style.css +1 -1
- package/dist/extension/core/queries/index.js +10 -1
- package/dist/extension/plugins/blockquote/plugin.js +21 -4
- package/dist/extension/plugins/check-list/plugin.js +20 -1
- package/dist/extension/plugins/header/helper.js +5 -3
- package/dist/extension/plugins/header/menu/style.css +1 -0
- package/dist/extension/plugins/header/plugin.js +28 -14
- package/dist/extension/plugins/image/helper.js +1 -0
- package/dist/extension/plugins/image/render-element/index.js +8 -7
- package/dist/extension/plugins/list/plugin/insert-fragment-list.js +10 -2
- package/dist/extension/plugins/markdown/plugin.js +22 -6
- package/dist/extension/plugins/paragraph/plugin.js +26 -1
- package/dist/extension/plugins/table/helper.js +2 -1
- package/dist/extension/plugins/table/model.js +4 -1
- package/dist/extension/plugins/table/plugin.js +70 -6
- package/dist/extension/toolbar/user-help/style.css +1 -1
- package/dist/pages/longtext-editor-dialog/style.css +1 -0
- package/dist/pages/markdown-preview/style.css +1 -0
- package/dist/slate-convert/html-to-slate/rules/code-block.js +1 -1
- package/dist/utils/event-handler.js +2 -1
- package/package.json +1 -1
|
@@ -60,6 +60,21 @@ function SimpleSlateEditor(_ref) {
|
|
|
60
60
|
(0, _core.focusEditor)(editor, range);
|
|
61
61
|
}
|
|
62
62
|
}, []);
|
|
63
|
+
const focusEndNode = (0, _react.useCallback)(editor => {
|
|
64
|
+
const lastChildIndex = editor.children.length - 1;
|
|
65
|
+
if (lastChildIndex < 0) return;
|
|
66
|
+
const lastNode = editor.children[lastChildIndex];
|
|
67
|
+
if (!lastNode) return;
|
|
68
|
+
const [lastNodeFirstChild] = lastNode.children;
|
|
69
|
+
if (lastNodeFirstChild) {
|
|
70
|
+
const endOfFirstNode = _slate.Editor.end(editor, [lastChildIndex, 0]);
|
|
71
|
+
const range = {
|
|
72
|
+
anchor: endOfFirstNode,
|
|
73
|
+
focus: endOfFirstNode
|
|
74
|
+
};
|
|
75
|
+
(0, _core.focusEditor)(editor, range);
|
|
76
|
+
}
|
|
77
|
+
}, []);
|
|
63
78
|
|
|
64
79
|
// useMount: focus editor
|
|
65
80
|
(0, _react.useEffect)(() => {
|
|
@@ -69,7 +84,7 @@ function SimpleSlateEditor(_ref) {
|
|
|
69
84
|
});
|
|
70
85
|
const timer = setTimeout(() => {
|
|
71
86
|
editor.forceNormalize = false;
|
|
72
|
-
|
|
87
|
+
focusEndNode(editor);
|
|
73
88
|
}, 300);
|
|
74
89
|
return () => {
|
|
75
90
|
editor.forceNormalize = false;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isTextNode = exports.isStartPoint = exports.isSelectionAtBlockStart = exports.isSelectionAtBlockEnd = exports.isRangeAcrossBlocks = exports.isLastNode = exports.isLastChild = exports.isFirstNode = exports.isFirstChild = exports.isEndPoint = exports.isBlockTextEmptyAfterSelection = exports.isBlockAboveEmpty = exports.isAncestorEmpty = exports.getSelectedNodeEntryByType = exports.getSelectedNodeByTypes = exports.getSelectedNodeByType = exports.getSelectedElems = exports.getQueryOptions = exports.getPreviousPath = exports.getPrevNode = exports.getParentNode = exports.getNodes = exports.getNodeType = exports.getNodeEntries = exports.getNode = exports.getNextSiblingNodes = exports.getNextNode = exports.getLastChildPath = exports.getLastChild = exports.getEditorString = exports.getDeepInlineChildren = exports.getCommonNode = exports.getChildren = exports.getAboveNode = exports.getAboveBlockNode = exports.findPath = exports.findNode = exports.findDescendant = void 0;
|
|
6
|
+
exports.isTextNode = exports.isStartPoint = exports.isSelectionAtBlockStart = exports.isSelectionAtBlockEnd = exports.isRangeAcrossBlocks = exports.isLastNode = exports.isLastChild = exports.isFirstNode = exports.isFirstChild = exports.isEndPoint = exports.isBlockTextEmptyAfterSelection = exports.isBlockAboveEmpty = exports.isAncestorEmpty = exports.getSelectedNodeEntryByTypes = exports.getSelectedNodeEntryByType = exports.getSelectedNodeByTypes = exports.getSelectedNodeByType = exports.getSelectedElems = exports.getQueryOptions = exports.getPreviousPath = exports.getPrevNode = exports.getParentNode = exports.getNodes = exports.getNodeType = exports.getNodeEntries = exports.getNode = exports.getNextSiblingNodes = exports.getNextNode = exports.getLastChildPath = exports.getLastChild = exports.getEditorString = exports.getDeepInlineChildren = exports.getCommonNode = exports.getChildren = exports.getAboveNode = exports.getAboveBlockNode = exports.findPath = exports.findNode = exports.findDescendant = void 0;
|
|
7
7
|
var _slate = require("slate");
|
|
8
8
|
var _slateReact = require("slate-react");
|
|
9
9
|
var _utils = require("../utils");
|
|
@@ -101,6 +101,15 @@ const getSelectedNodeEntryByType = (editor, type) => {
|
|
|
101
101
|
return nodeEntry ? nodeEntry : null;
|
|
102
102
|
};
|
|
103
103
|
exports.getSelectedNodeEntryByType = getSelectedNodeEntryByType;
|
|
104
|
+
const getSelectedNodeEntryByTypes = (editor, types) => {
|
|
105
|
+
const match = n => types.includes(getNodeType(n));
|
|
106
|
+
const [nodeEntry] = _slate.Editor.nodes(editor, {
|
|
107
|
+
match,
|
|
108
|
+
universal: false
|
|
109
|
+
});
|
|
110
|
+
return nodeEntry ? nodeEntry : null;
|
|
111
|
+
};
|
|
112
|
+
exports.getSelectedNodeEntryByTypes = getSelectedNodeEntryByTypes;
|
|
104
113
|
const getNodeEntries = (editor, options) => {
|
|
105
114
|
return _slate.Editor.nodes(editor, getQueryOptions(editor, options));
|
|
106
115
|
};
|
|
@@ -119,17 +119,34 @@ const withBlockquote = editor => {
|
|
|
119
119
|
}
|
|
120
120
|
deleteBackward(unit);
|
|
121
121
|
};
|
|
122
|
-
newEditor.insertFragment =
|
|
122
|
+
newEditor.insertFragment = fragment => {
|
|
123
123
|
const {
|
|
124
124
|
selection
|
|
125
125
|
} = editor;
|
|
126
|
-
if (selection == null) return insertFragment(
|
|
126
|
+
if (selection == null) return insertFragment(fragment);
|
|
127
127
|
const [blockquoteEntry] = _slate.Editor.nodes(editor, {
|
|
128
128
|
match: n => _slate.Element.isElement(n) && n.type === _elementTypes.BLOCKQUOTE,
|
|
129
129
|
universal: true
|
|
130
130
|
});
|
|
131
|
-
if (!blockquoteEntry) return insertFragment(
|
|
132
|
-
const
|
|
131
|
+
if (!blockquoteEntry) return insertFragment(fragment);
|
|
132
|
+
const firstChild = fragment[0];
|
|
133
|
+
if (fragment.length === 1 && firstChild.type === _elementTypes.TABLE) {
|
|
134
|
+
// const nodeEntry = Editor.nodes(newEditor, { mode: 'highest' });
|
|
135
|
+
const nextPath = _slate.Path.next(blockquoteEntry[1]);
|
|
136
|
+
_slate.Transforms.insertNodes(newEditor, fragment, {
|
|
137
|
+
at: nextPath
|
|
138
|
+
});
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const insertData = fragment.map(node => {
|
|
142
|
+
if (node.type === _elementTypes.TABLE) {
|
|
143
|
+
const text = _slate.Node.string(node);
|
|
144
|
+
return (0, _core.generateElement)(_elementTypes.PARAGRAPH, {
|
|
145
|
+
childrenOrText: text
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return node;
|
|
149
|
+
});
|
|
133
150
|
return insertFragment(insertData);
|
|
134
151
|
};
|
|
135
152
|
return newEditor;
|
|
@@ -11,7 +11,8 @@ var _helper = require("../paragraph/helper");
|
|
|
11
11
|
const withCheckList = editor => {
|
|
12
12
|
const {
|
|
13
13
|
insertBreak,
|
|
14
|
-
deleteBackward
|
|
14
|
+
deleteBackward,
|
|
15
|
+
insertFragment
|
|
15
16
|
} = editor;
|
|
16
17
|
const newEditor = editor;
|
|
17
18
|
newEditor.insertBreak = () => {
|
|
@@ -49,6 +50,24 @@ const withCheckList = editor => {
|
|
|
49
50
|
}
|
|
50
51
|
deleteBackward(unit);
|
|
51
52
|
};
|
|
53
|
+
newEditor.insertFragment = fragment => {
|
|
54
|
+
const match = {
|
|
55
|
+
type: [_elementTypes.CHECK_LIST_ITEM]
|
|
56
|
+
};
|
|
57
|
+
const [checkListEntry] = (0, _core.getNodeEntries)(newEditor, {
|
|
58
|
+
match
|
|
59
|
+
});
|
|
60
|
+
if (!checkListEntry) return insertFragment(fragment);
|
|
61
|
+
const firstChild = fragment[0];
|
|
62
|
+
if (fragment.length === 1 && firstChild.type === _elementTypes.TABLE) {
|
|
63
|
+
const nextPath = _slate.Path.next(checkListEntry[1]);
|
|
64
|
+
_slate.Transforms.insertNodes(newEditor, fragment, {
|
|
65
|
+
at: nextPath
|
|
66
|
+
});
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
return insertFragment(fragment);
|
|
70
|
+
};
|
|
52
71
|
return newEditor;
|
|
53
72
|
};
|
|
54
73
|
var _default = exports.default = withCheckList;
|
|
@@ -20,7 +20,7 @@ const isMenuDisabled = function (editor) {
|
|
|
20
20
|
type = (0, _queries.getNodeType)(parentNode);
|
|
21
21
|
}
|
|
22
22
|
if (type === _constants.ELementTypes.PARAGRAPH) return true;
|
|
23
|
-
if (type.startsWith(_constants.ELementTypes.HEADER)) return true;
|
|
23
|
+
if (type && type.startsWith(_constants.ELementTypes.HEADER)) return true;
|
|
24
24
|
return false;
|
|
25
25
|
},
|
|
26
26
|
universal: true,
|
|
@@ -32,8 +32,10 @@ exports.isMenuDisabled = isMenuDisabled;
|
|
|
32
32
|
const getHeaderType = editor => {
|
|
33
33
|
const [match] = _slate.Editor.nodes(editor, {
|
|
34
34
|
match: node => {
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
if (_slate.Element.isElement(node) && _slate.Editor.isBlock(editor, node)) {
|
|
36
|
+
const type = (0, _queries.getNodeType)(node);
|
|
37
|
+
if (type && type.startsWith(_constants.ELementTypes.HEADER)) return true;
|
|
38
|
+
}
|
|
37
39
|
return false;
|
|
38
40
|
},
|
|
39
41
|
universal: true
|
|
@@ -12,6 +12,7 @@ var _helper = require("./helper");
|
|
|
12
12
|
var _keyboard = require("../../constants/keyboard");
|
|
13
13
|
var _common = require("../../../utils/common");
|
|
14
14
|
var _constants = require("../../constants");
|
|
15
|
+
var _elementTypes = require("../../constants/element-types");
|
|
15
16
|
const isSelectionAtLineEnd = (editor, path) => {
|
|
16
17
|
const {
|
|
17
18
|
selection
|
|
@@ -72,7 +73,7 @@ const withHeader = editor => {
|
|
|
72
73
|
const [headerEntry] = _slate.Editor.nodes(newEditor, {
|
|
73
74
|
match: n => {
|
|
74
75
|
if (!_slate.Element.isElement(n)) return false;
|
|
75
|
-
if (n.type.startsWith(_constants.ELementTypes.HEADER)) return true;
|
|
76
|
+
if (n.type && n.type.startsWith(_constants.ELementTypes.HEADER)) return true;
|
|
76
77
|
return false;
|
|
77
78
|
},
|
|
78
79
|
// Matches nodes whose node.type starts with header
|
|
@@ -89,20 +90,33 @@ const withHeader = editor => {
|
|
|
89
90
|
}
|
|
90
91
|
return deleteBackward(unit);
|
|
91
92
|
};
|
|
92
|
-
newEditor.insertFragment =
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
93
|
+
newEditor.insertFragment = fragment => {
|
|
94
|
+
const headerEntry = (0, _core.getSelectedNodeEntryByTypes)(editor, _constants.HEADERS);
|
|
95
|
+
if (!headerEntry) return insertFragment(fragment);
|
|
96
|
+
const firstChild = fragment[0];
|
|
97
|
+
if (fragment.length === 1) {
|
|
98
|
+
// is single list item
|
|
99
|
+
if (_constants.LIST_TYPE_ARRAY.includes(firstChild.type)) {
|
|
100
|
+
if (firstChild.children.length === 1) {
|
|
101
|
+
const text = _slate.Node.string(fragment[0]);
|
|
102
|
+
insertText(text);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const nextPath = _slate.Path.next(headerEntry[1]);
|
|
106
|
+
_slate.Transforms.insertNodes(newEditor, fragment, {
|
|
107
|
+
at: nextPath
|
|
108
|
+
});
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (firstChild.type === _elementTypes.TABLE) {
|
|
112
|
+
const nextPath = _slate.Path.next(headerEntry[1]);
|
|
113
|
+
_slate.Transforms.insertNodes(newEditor, fragment, {
|
|
114
|
+
at: nextPath
|
|
115
|
+
});
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
104
118
|
}
|
|
105
|
-
return insertFragment(
|
|
119
|
+
return insertFragment(fragment);
|
|
106
120
|
};
|
|
107
121
|
newEditor.onHotKeyDown = event => {
|
|
108
122
|
const HOT_KEYS = (0, _common.isMac)() ? _keyboard.MAC_HOTKEYS_EVENT_HEADER : _keyboard.WIN_HOTKEYS_EVENT_HEADER;
|
|
@@ -17,14 +17,14 @@ require("./style.css");
|
|
|
17
17
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
18
18
|
|
|
19
19
|
const renderImage = (_ref, editor) => {
|
|
20
|
-
var _element$data, _element$data2, _element$data3;
|
|
20
|
+
var _element$data, _element$data2, _element$data3, _element$data4;
|
|
21
21
|
let {
|
|
22
22
|
attributes,
|
|
23
23
|
children,
|
|
24
24
|
element
|
|
25
25
|
} = _ref;
|
|
26
|
-
const [isLoadingImage, setIsLoadingImage] = (0, _react.useState)(
|
|
27
|
-
const [isError, setIsError] = (0, _react.useState)(
|
|
26
|
+
const [isLoadingImage, setIsLoadingImage] = (0, _react.useState)(element === null || element === void 0 ? void 0 : (_element$data = element.data) === null || _element$data === void 0 ? void 0 : _element$data.init);
|
|
27
|
+
const [isError, setIsError] = (0, _react.useState)(false);
|
|
28
28
|
const [isResizing, setIsResizing] = (0, _react.useState)(false);
|
|
29
29
|
const [isFullScreening, setIsFullScreening] = (0, _react.useState)(false);
|
|
30
30
|
const [imgSizeInfo, setImgSizeInfo] = (0, _react.useState)({
|
|
@@ -41,6 +41,7 @@ const renderImage = (_ref, editor) => {
|
|
|
41
41
|
const {
|
|
42
42
|
data = {}
|
|
43
43
|
} = element;
|
|
44
|
+
if (!data.init) return;
|
|
44
45
|
const url = data.src;
|
|
45
46
|
(0, _helper.lazyLoadImage)(url, image => {
|
|
46
47
|
setIsLoadingImage(false);
|
|
@@ -110,11 +111,11 @@ const renderImage = (_ref, editor) => {
|
|
|
110
111
|
'selected': isSelected,
|
|
111
112
|
'error': isError
|
|
112
113
|
}),
|
|
113
|
-
alt: (element === null || element === void 0 ? void 0 : (_element$
|
|
114
|
-
src: element === null || element === void 0 ? void 0 : (_element$
|
|
114
|
+
alt: (element === null || element === void 0 ? void 0 : (_element$data2 = element.data) === null || _element$data2 === void 0 ? void 0 : _element$data2.alt) || '',
|
|
115
|
+
src: element === null || element === void 0 ? void 0 : (_element$data3 = element.data) === null || _element$data3 === void 0 ? void 0 : _element$data3.src,
|
|
115
116
|
width: element === null || element === void 0 ? void 0 : element.data.width,
|
|
116
117
|
height: element === null || element === void 0 ? void 0 : element.data.height
|
|
117
|
-
}), isSelected && !
|
|
118
|
+
}), isSelected && !isLoadingImage && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("span", {
|
|
118
119
|
ref: resizerRef,
|
|
119
120
|
className: "resizer",
|
|
120
121
|
onMouseDown: handleStartResize
|
|
@@ -128,7 +129,7 @@ const renderImage = (_ref, editor) => {
|
|
|
128
129
|
}))), isResizing && /*#__PURE__*/_react.default.createElement("span", {
|
|
129
130
|
className: "image-size-info-tooltip"
|
|
130
131
|
}, "".concat(t('Width'), ":").concat(imgSizeInfo.width, " ").concat(t('Height'), ":").concat(imgSizeInfo.height)), isFullScreening && /*#__PURE__*/_react.default.createElement(_imagePreviewer.default, {
|
|
131
|
-
imgUrl: element === null || element === void 0 ? void 0 : (_element$
|
|
132
|
+
imgUrl: element === null || element === void 0 ? void 0 : (_element$data4 = element.data) === null || _element$data4 === void 0 ? void 0 : _element$data4.src,
|
|
132
133
|
toggleImagePreviewer: toggleImagePreviewer
|
|
133
134
|
}), children);
|
|
134
135
|
};
|
|
@@ -50,10 +50,18 @@ const trimList = listRoot => {
|
|
|
50
50
|
return [...findListItemsWithContent(first), ...rest];
|
|
51
51
|
};
|
|
52
52
|
const wrapNodeIntoListItem = node => {
|
|
53
|
-
|
|
53
|
+
if (node.type === _elementTypes.LIST_ITEM) return node;
|
|
54
|
+
return {
|
|
54
55
|
id: _slugid.default.nice(),
|
|
55
56
|
type: _elementTypes.LIST_ITEM,
|
|
56
|
-
children: [
|
|
57
|
+
children: [{
|
|
58
|
+
id: _slugid.default.nice(),
|
|
59
|
+
type: _elementTypes.PARAGRAPH,
|
|
60
|
+
children: [{
|
|
61
|
+
id: _slugid.default.nice(),
|
|
62
|
+
text: _slate.Node.string(node)
|
|
63
|
+
}]
|
|
64
|
+
}]
|
|
57
65
|
};
|
|
58
66
|
};
|
|
59
67
|
const isSingleLic = fragment => {
|
|
@@ -31,6 +31,9 @@ const KEY_TO_INLINE_TYPE_FOR_SPACE = {
|
|
|
31
31
|
'**': _constants.TEXT_STYLE_MAP.BOLD,
|
|
32
32
|
'*': _constants.TEXT_STYLE_MAP.ITALIC,
|
|
33
33
|
'***': _constants.TEXT_STYLE_MAP.BOLD_ITALIC,
|
|
34
|
+
'__': _constants.TEXT_STYLE_MAP.BOLD,
|
|
35
|
+
'_': _constants.TEXT_STYLE_MAP.ITALIC,
|
|
36
|
+
'___': _constants.TEXT_STYLE_MAP.BOLD_ITALIC,
|
|
34
37
|
'`': _constants.TEXT_STYLE_MAP.CODE
|
|
35
38
|
};
|
|
36
39
|
const getBeforeText = editor => {
|
|
@@ -95,9 +98,10 @@ const withMarkDown = editor => {
|
|
|
95
98
|
const inlineCode = KEY_TO_INLINE_TYPE_FOR_SPACE[beforeText.slice(-1)];
|
|
96
99
|
if (!type && !boldType && !italicType && !italicAndBoldType) return insertText(text);
|
|
97
100
|
if (italicAndBoldType === _constants.TEXT_STYLE_MAP.BOLD_ITALIC) {
|
|
101
|
+
const SYMBOL = beforeText.slice(-3);
|
|
98
102
|
const restStr = beforeText === null || beforeText === void 0 ? void 0 : beforeText.slice(0, beforeText.length - 3);
|
|
99
|
-
const startOffset = restStr === null || restStr === void 0 ? void 0 : restStr.lastIndexOf(
|
|
100
|
-
const endOffset = (beforeText === null || beforeText === void 0 ? void 0 : beforeText.lastIndexOf(
|
|
103
|
+
const startOffset = restStr === null || restStr === void 0 ? void 0 : restStr.lastIndexOf(SYMBOL);
|
|
104
|
+
const endOffset = (beforeText === null || beforeText === void 0 ? void 0 : beforeText.lastIndexOf(SYMBOL)) + 3;
|
|
101
105
|
if (startOffset === -1) {
|
|
102
106
|
return insertText(text);
|
|
103
107
|
}
|
|
@@ -122,9 +126,10 @@ const withMarkDown = editor => {
|
|
|
122
126
|
return;
|
|
123
127
|
}
|
|
124
128
|
if (boldType === _constants.TEXT_STYLE_MAP.BOLD) {
|
|
129
|
+
const SYMBOL = beforeText.slice(-2);
|
|
125
130
|
const restStr = beforeText.slice(0, beforeText.length - 2);
|
|
126
|
-
const startOffset = restStr.lastIndexOf(
|
|
127
|
-
const endOffset = beforeText.lastIndexOf(
|
|
131
|
+
const startOffset = restStr.lastIndexOf(SYMBOL);
|
|
132
|
+
const endOffset = beforeText.lastIndexOf(SYMBOL) + 2;
|
|
128
133
|
if (startOffset === -1) {
|
|
129
134
|
return insertText(text);
|
|
130
135
|
}
|
|
@@ -150,9 +155,20 @@ const withMarkDown = editor => {
|
|
|
150
155
|
// 1 '*'
|
|
151
156
|
// 2 'acd * add *'
|
|
152
157
|
if (italicType === _constants.TEXT_STYLE_MAP.ITALIC) {
|
|
158
|
+
const SYMBOL = beforeText.slice(-1);
|
|
153
159
|
const restStr = beforeText === null || beforeText === void 0 ? void 0 : beforeText.slice(0, beforeText.length - 1);
|
|
154
|
-
const startOffset = restStr === null || restStr === void 0 ? void 0 : restStr.lastIndexOf(
|
|
155
|
-
const endOffset = (beforeText === null || beforeText === void 0 ? void 0 : beforeText.lastIndexOf(
|
|
160
|
+
const startOffset = restStr === null || restStr === void 0 ? void 0 : restStr.lastIndexOf(SYMBOL);
|
|
161
|
+
const endOffset = (beforeText === null || beforeText === void 0 ? void 0 : beforeText.lastIndexOf(SYMBOL)) + 1;
|
|
162
|
+
|
|
163
|
+
// start: restStr = '`' | ' `'
|
|
164
|
+
if (restStr === '' || restStr === '_') {
|
|
165
|
+
return insertText(text);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// end: restStr = ' _' | 'aaaaa_'
|
|
169
|
+
if (startOffset + 1 === restStr.length) {
|
|
170
|
+
return insertText(text);
|
|
171
|
+
}
|
|
156
172
|
if (startOffset === -1 && restStr.length > 0) {
|
|
157
173
|
return insertText(text);
|
|
158
174
|
}
|
|
@@ -26,7 +26,8 @@ const isSelectionAtLineStart = (editor, path) => {
|
|
|
26
26
|
const withParagraph = editor => {
|
|
27
27
|
const {
|
|
28
28
|
deleteBackward,
|
|
29
|
-
insertBreak
|
|
29
|
+
insertBreak,
|
|
30
|
+
insertFragment
|
|
30
31
|
} = editor;
|
|
31
32
|
const newEditor = editor;
|
|
32
33
|
newEditor.insertBreak = () => {
|
|
@@ -88,6 +89,30 @@ const withParagraph = editor => {
|
|
|
88
89
|
}
|
|
89
90
|
return deleteBackward(unit);
|
|
90
91
|
};
|
|
92
|
+
newEditor.insertFragment = fragment => {
|
|
93
|
+
const match = {
|
|
94
|
+
type: [_elementTypes.PARAGRAPH]
|
|
95
|
+
};
|
|
96
|
+
const [paragraphEntry] = (0, _core.getNodeEntries)(newEditor, {
|
|
97
|
+
match
|
|
98
|
+
});
|
|
99
|
+
if (!paragraphEntry) return insertFragment(fragment);
|
|
100
|
+
const firstChild = fragment[0];
|
|
101
|
+
if (fragment.length === 1 && firstChild.type === _elementTypes.TABLE) {
|
|
102
|
+
const hasVoidNode = paragraphEntry[0].children.some(item => _slate.Editor.isVoid(newEditor, item));
|
|
103
|
+
if (_slate.Node.string(paragraphEntry[0]).length === 0 && !hasVoidNode) {
|
|
104
|
+
_slate.Transforms.removeNodes(newEditor);
|
|
105
|
+
_slate.Transforms.insertNodes(newEditor, fragment);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const nextPath = _slate.Path.next(paragraphEntry[1]);
|
|
109
|
+
_slate.Transforms.insertNodes(newEditor, fragment, {
|
|
110
|
+
at: nextPath
|
|
111
|
+
});
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
return insertFragment(fragment);
|
|
115
|
+
};
|
|
91
116
|
return newEditor;
|
|
92
117
|
};
|
|
93
118
|
var _default = exports.default = withParagraph;
|
|
@@ -103,10 +103,11 @@ const selectCellByGrid = (editor, rowIndex, colIndex) => {
|
|
|
103
103
|
exports.selectCellByGrid = selectCellByGrid;
|
|
104
104
|
const getSelectedTableCells = editor => {
|
|
105
105
|
const [tableEntry] = getTableEntry(editor);
|
|
106
|
-
if (!tableEntry) return
|
|
106
|
+
if (!tableEntry) return null;
|
|
107
107
|
const [tableNode] = tableEntry;
|
|
108
108
|
const tableRows = tableNode.children;
|
|
109
109
|
const selectGrid = getSelectGrid(editor);
|
|
110
|
+
if (!selectGrid) return null;
|
|
110
111
|
const {
|
|
111
112
|
startRowIndex,
|
|
112
113
|
endRowIndex,
|
|
@@ -72,8 +72,9 @@ const generateTable = options => {
|
|
|
72
72
|
childrenOrText = ''
|
|
73
73
|
} = options;
|
|
74
74
|
let rows = [];
|
|
75
|
-
|
|
75
|
+
let align = [];
|
|
76
76
|
if (rowNum) {
|
|
77
|
+
align = new Array(columnNum).fill(null);
|
|
77
78
|
rows = Array.from({
|
|
78
79
|
length: rowNum
|
|
79
80
|
}, () => generateTableRow({
|
|
@@ -89,6 +90,8 @@ const generateTable = options => {
|
|
|
89
90
|
if (!Array.isArray(childrenOrText)) {
|
|
90
91
|
throw Error('childrenOrText must be a string or a Node array!');
|
|
91
92
|
}
|
|
93
|
+
const columns = childrenOrText[0].children.length;
|
|
94
|
+
align = new Array(columns).fill(null);
|
|
92
95
|
}
|
|
93
96
|
return (0, _core.generateElement)(_elementTypes.TABLE, {
|
|
94
97
|
childrenOrText: rowNum ? rows : childrenOrText,
|
|
@@ -66,21 +66,77 @@ const withTable = editor => {
|
|
|
66
66
|
}
|
|
67
67
|
return (0, _helper.pasteContentIntoTable)(newEditor, data);
|
|
68
68
|
};
|
|
69
|
-
newEditor.insertFragment =
|
|
69
|
+
newEditor.insertFragment = fragment => {
|
|
70
70
|
const isTableActive = (0, _helper.isInTable)(newEditor);
|
|
71
|
-
if (!isTableActive) return insertFragment && insertFragment(
|
|
72
|
-
if (!Array.isArray(
|
|
71
|
+
if (!isTableActive) return insertFragment && insertFragment(fragment);
|
|
72
|
+
if (!Array.isArray(fragment)) return;
|
|
73
|
+
const firstChild = fragment[0];
|
|
74
|
+
if (fragment.length === 1 && firstChild.type === _elementTypes.TABLE) {
|
|
75
|
+
const {
|
|
76
|
+
tableEntry,
|
|
77
|
+
rowEntry
|
|
78
|
+
} = (0, _helper.getTableFocusingInfos)(editor);
|
|
79
|
+
let selectedInfo = (0, _helper.getSelectGrid)(editor);
|
|
80
|
+
if (!selectedInfo) {
|
|
81
|
+
const tableCellEntry = (0, _core.getSelectedNodeEntryByType)(editor, _elementTypes.TABLE_CELL);
|
|
82
|
+
if (!tableCellEntry) return;
|
|
83
|
+
const [, path] = tableCellEntry;
|
|
84
|
+
const startColIndex = path.pop();
|
|
85
|
+
const startRowIndex = path.pop();
|
|
86
|
+
selectedInfo = {
|
|
87
|
+
startRowIndex,
|
|
88
|
+
startColIndex
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const {
|
|
92
|
+
startRowIndex,
|
|
93
|
+
startColIndex
|
|
94
|
+
} = selectedInfo;
|
|
95
|
+
const [tableNode, tablePath] = tableEntry;
|
|
96
|
+
const [rowNode] = rowEntry;
|
|
97
|
+
const tableWidth = rowNode.children.length;
|
|
98
|
+
const tableHeight = tableNode.children.length;
|
|
99
|
+
firstChild.children.forEach((clipRow, clipRowIndex) => {
|
|
100
|
+
// Out of table
|
|
101
|
+
if (startRowIndex + clipRowIndex >= tableHeight) return true;
|
|
102
|
+
|
|
103
|
+
// rowPath = [...tablePath, rowIndex + clipRowIndex];
|
|
104
|
+
const currentRowPath = [...tablePath, startRowIndex + clipRowIndex];
|
|
105
|
+
clipRow.children.forEach((clipCol, clipColIndex) => {
|
|
106
|
+
// Out of table
|
|
107
|
+
if (startColIndex + clipColIndex >= tableWidth) return true;
|
|
108
|
+
|
|
109
|
+
// cellPath = [...rowPath, columnIndex + clipColIndex];
|
|
110
|
+
const currentCellPath = [...currentRowPath, startColIndex + clipColIndex];
|
|
111
|
+
const currentCellChildPath = currentCellPath.concat(0);
|
|
112
|
+
_slate.Transforms.removeNodes(editor, {
|
|
113
|
+
at: currentCellChildPath
|
|
114
|
+
});
|
|
115
|
+
const otherBlockTypes = [..._constants.HEADERS, _elementTypes.CHECK_LIST_ITEM, _elementTypes.PARAGRAPH];
|
|
116
|
+
const newChildren = clipCol.children.map(item => {
|
|
117
|
+
if (otherBlockTypes.includes(item.type)) return item.children;
|
|
118
|
+
return item;
|
|
119
|
+
}).flat();
|
|
120
|
+
_slate.Transforms.insertNodes(editor, newChildren, {
|
|
121
|
+
at: currentCellChildPath
|
|
122
|
+
});
|
|
123
|
+
return false;
|
|
124
|
+
});
|
|
125
|
+
return false;
|
|
126
|
+
});
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
73
129
|
const notSupportTypes = [_elementTypes.TABLE, _elementTypes.BLOCKQUOTE, _elementTypes.UNORDERED_LIST, _elementTypes.ORDERED_LIST, _elementTypes.CODE_BLOCK];
|
|
74
|
-
const isDataValid =
|
|
130
|
+
const isDataValid = fragment.some(item => notSupportTypes.includes(item.type));
|
|
75
131
|
if (isDataValid) {
|
|
76
|
-
const strContent =
|
|
132
|
+
const strContent = fragment.reduce((ret, item) => {
|
|
77
133
|
return ret + _slate.Node.string(item);
|
|
78
134
|
}, '');
|
|
79
135
|
_slate.Editor.insertText(newEditor, strContent);
|
|
80
136
|
return;
|
|
81
137
|
}
|
|
82
138
|
const otherBlockTypes = [..._constants.HEADERS, _elementTypes.CHECK_LIST_ITEM, _elementTypes.PARAGRAPH];
|
|
83
|
-
const newChildren =
|
|
139
|
+
const newChildren = fragment.map(item => {
|
|
84
140
|
if (otherBlockTypes.includes(item.type)) return item.children;
|
|
85
141
|
return item;
|
|
86
142
|
}).flat();
|
|
@@ -219,11 +275,19 @@ const withTable = editor => {
|
|
|
219
275
|
}
|
|
220
276
|
event.preventDefault();
|
|
221
277
|
event.stopPropagation();
|
|
278
|
+
// selected multiple cells
|
|
222
279
|
const tableNode = (0, _helper.getSelectedTableCells)(newEditor);
|
|
223
280
|
if (tableNode) {
|
|
224
281
|
(0, _setEventTransfer.default)(event, 'fragment', tableNode);
|
|
225
282
|
return true;
|
|
226
283
|
}
|
|
284
|
+
// selected only one cell
|
|
285
|
+
const tableCell = (0, _core.getSelectedNodeByType)(newEditor, _elementTypes.TABLE_CELL);
|
|
286
|
+
if (tableCell) {
|
|
287
|
+
(0, _setEventTransfer.default)(event, 'fragment', tableCell.children);
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
return false;
|
|
227
291
|
};
|
|
228
292
|
newEditor.normalizeNode = _ref => {
|
|
229
293
|
let [node, path] = _ref;
|