@seafile/sdoc-editor 1.0.209 → 1.0.211
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/extension/core/queries/index.js +22 -1
- package/dist/basic-sdk/extension/plugins/blockquote/plugin.js +0 -18
- package/dist/basic-sdk/extension/plugins/check-list/plugin.js +13 -10
- package/dist/basic-sdk/extension/plugins/code-block/plugin.js +48 -37
- package/dist/basic-sdk/extension/plugins/header/plugin.js +8 -0
- package/dist/basic-sdk/extension/plugins/link/helpers.js +18 -19
- package/dist/basic-sdk/extension/plugins/link/plugin.js +1 -1
- package/dist/basic-sdk/extension/plugins/paragraph/plugin.js +17 -1
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.someNode = exports.isTopLevelListItem = exports.isTextNode = exports.isStartPoint = exports.isSelectionAtBlockStart = exports.isSelectionAtBlockEnd = exports.isRangeInSameBlock = exports.isRangeAcrossBlocks = exports.isMultiLevelList = exports.isMiddlePoint = exports.isLastNode = exports.isLastChild = exports.isHasImg = exports.isFirstChild = exports.isEndPoint = exports.isEmptyArticle = exports.isCurrentLineHasText = exports.isCurrentLineEmpty = exports.isContainsVoidElement = exports.isBlockTextEmptyAfterSelection = exports.isBlockAboveEmpty = exports.isAncestorEmpty = exports.getTopLevelBlockNode = exports.getStartPoint = exports.getSelectedNodeEntryByType = exports.getSelectedNodeByTypes = exports.getSelectedNodeByType = exports.getSelectedElems = exports.getQueryOptions = exports.getPreviousPath = exports.getPrevNode = exports.getPointBefore = exports.getParentNode = exports.getNodes = exports.getNodeType = exports.getNodeEntries = exports.getNodeById = exports.getNode = exports.getNextSiblingNodes = exports.getNextNode = exports.getLastChildPath = exports.getLastChild = exports.getEndPoint = exports.getEditorString = exports.getDeepInlineChildren = exports.getCurrentNode = exports.getCommonNode = exports.getChildren = exports.getAboveNode = exports.getAboveBlockNode = exports.findPath = exports.findNode = exports.findDescendant = void 0;
|
|
7
|
+
exports.someNode = exports.isTopLevelListItem = exports.isTextNode = exports.isStartPoint = exports.isSelectionAtBlockStart = exports.isSelectionAtBlockEnd = exports.isRangeInSameBlock = exports.isRangeAcrossBlocks = exports.isMultiLevelList = exports.isMiddlePoint = exports.isLastNode = exports.isLastChild = exports.isHasImg = exports.isFirstChild = exports.isEndPoint = exports.isEmptyArticle = exports.isCursorAtBlockStart = exports.isCurrentLineHasText = exports.isCurrentLineEmpty = exports.isContainsVoidElement = exports.isBlockTextEmptyAfterSelection = exports.isBlockAboveEmpty = exports.isAncestorEmpty = exports.getTopLevelBlockNode = exports.getStartPoint = exports.getSelectedNodeEntryByType = exports.getSelectedNodeByTypes = exports.getSelectedNodeByType = exports.getSelectedElems = exports.getQueryOptions = exports.getPreviousPath = exports.getPrevNode = exports.getPointBefore = exports.getParentNode = exports.getNodes = exports.getNodeType = exports.getNodeEntries = exports.getNodeById = exports.getNode = exports.getNextSiblingNodes = exports.getNextNode = exports.getLastChildPath = exports.getLastChild = exports.getEndPoint = exports.getEditorString = exports.getDeepInlineChildren = exports.getCurrentNode = exports.getCommonNode = exports.getChildren = exports.getAboveNode = exports.getAboveBlockNode = exports.findPath = exports.findNode = exports.findDescendant = void 0;
|
|
8
8
|
var _slate = require("@seafile/slate");
|
|
9
9
|
var _slateReact = require("@seafile/slate-react");
|
|
10
10
|
var _utils = require("../utils");
|
|
@@ -455,6 +455,27 @@ const isBlockAboveEmpty = editor => {
|
|
|
455
455
|
return isAncestorEmpty(editor, block);
|
|
456
456
|
};
|
|
457
457
|
exports.isBlockAboveEmpty = isBlockAboveEmpty;
|
|
458
|
+
const isCursorAtBlockStart = (editor, options) => {
|
|
459
|
+
const {
|
|
460
|
+
selection
|
|
461
|
+
} = editor;
|
|
462
|
+
if (!selection) return false;
|
|
463
|
+
const nodeEntry = getAboveBlockNode(editor, options);
|
|
464
|
+
let [node, path] = nodeEntry || [];
|
|
465
|
+
if (!path) return false;
|
|
466
|
+
|
|
467
|
+
// Special handling of placeholders, such as link, inline image
|
|
468
|
+
if (_slate.Node.string(node.children[0]).length === 0) {
|
|
469
|
+
const {
|
|
470
|
+
offset,
|
|
471
|
+
path: point
|
|
472
|
+
} = selection.focus;
|
|
473
|
+
if (offset !== 0) return false;
|
|
474
|
+
return _slate.Path.equals(point, [path[0], 1, 0]);
|
|
475
|
+
}
|
|
476
|
+
return isStartPoint(editor, selection.focus, path);
|
|
477
|
+
};
|
|
478
|
+
exports.isCursorAtBlockStart = isCursorAtBlockStart;
|
|
458
479
|
const isSelectionAtBlockStart = (editor, options) => {
|
|
459
480
|
const {
|
|
460
481
|
selection
|
|
@@ -88,24 +88,6 @@ const withBlockquote = editor => {
|
|
|
88
88
|
});
|
|
89
89
|
return;
|
|
90
90
|
}
|
|
91
|
-
|
|
92
|
-
// Merge with previous line when Select at the beginning of the line
|
|
93
|
-
if (currentLineIndex !== 0 && (0, _core.isSelectionAtBlockStart)(editor)) {
|
|
94
|
-
const lineText = _slate.Node.string(currentLineEntry[0]);
|
|
95
|
-
const previousNodeEntry = _slate.Editor.previous(editor, {
|
|
96
|
-
at: currentLineEntry[1]
|
|
97
|
-
});
|
|
98
|
-
if (!previousNodeEntry) return;
|
|
99
|
-
const focusPoint = _slate.Editor.end(newEditor, previousNodeEntry[1]);
|
|
100
|
-
_slate.Transforms.insertText(newEditor, lineText, {
|
|
101
|
-
at: _slate.Editor.end(newEditor, previousNodeEntry[1])
|
|
102
|
-
});
|
|
103
|
-
_slate.Transforms.removeNodes(editor, {
|
|
104
|
-
at: currentLineEntry[1]
|
|
105
|
-
});
|
|
106
|
-
(0, _core.focusEditor)(newEditor, focusPoint);
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
91
|
}
|
|
110
92
|
deleteBackward(unit);
|
|
111
93
|
};
|
|
@@ -40,19 +40,22 @@ const withCheckList = editor => {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
// If it is check-list-item, handle your own business logic
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
checked: false
|
|
49
|
-
}, {
|
|
50
|
-
at: node[1]
|
|
43
|
+
if ((0, _core.isCursorAtBlockStart)(editor)) {
|
|
44
|
+
const path = (0, _core.findPath)(editor, node);
|
|
45
|
+
const newNode = (0, _core.generateEmptyElement)(_constants.CHECK_LIST_ITEM);
|
|
46
|
+
_slate.Transforms.insertNodes(editor, newNode, {
|
|
47
|
+
at: path
|
|
51
48
|
});
|
|
52
49
|
return;
|
|
53
50
|
}
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
_slate.Transforms.splitNodes(editor, {
|
|
52
|
+
always: true
|
|
53
|
+
});
|
|
54
|
+
_slate.Transforms.setNodes(editor, {
|
|
55
|
+
checked: false
|
|
56
|
+
}, {
|
|
57
|
+
at: node[1]
|
|
58
|
+
});
|
|
56
59
|
};
|
|
57
60
|
newEditor.deleteBackward = unit => {
|
|
58
61
|
const {
|
|
@@ -68,47 +68,47 @@ const withCodeBlock = editor => {
|
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
70
|
return insertFragment(data);
|
|
71
|
-
}
|
|
72
|
-
// Paste into code block
|
|
73
|
-
if ((0, _core.getSelectedNodeByType)(editor, _constants.CODE_BLOCK)) {
|
|
74
|
-
// Pasted data is code block split with code-line
|
|
75
|
-
data.forEach((node, index) => {
|
|
76
|
-
if (node.type === _constants.CODE_BLOCK) {
|
|
77
|
-
const codeLineArr = node.children.map(line => line);
|
|
78
|
-
data.splice(index, 1, ...codeLineArr);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
const newData = data.map(node => {
|
|
82
|
-
const text = _slate.Node.string(node);
|
|
83
|
-
const codeLine = {
|
|
84
|
-
id: _slugid.default.nice(),
|
|
85
|
-
type: _constants.CODE_LINE,
|
|
86
|
-
children: [{
|
|
87
|
-
text: text,
|
|
88
|
-
id: _slugid.default.nice()
|
|
89
|
-
}]
|
|
90
|
-
};
|
|
91
|
-
return codeLine;
|
|
92
|
-
});
|
|
71
|
+
}
|
|
93
72
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
insertBreak();
|
|
102
|
-
insertFragment(restNode);
|
|
103
|
-
}
|
|
104
|
-
return;
|
|
73
|
+
// Paste into code block
|
|
74
|
+
if ((0, _core.getSelectedNodeByType)(editor, _constants.CODE_BLOCK)) {
|
|
75
|
+
// Pasted data is code block split with code-line
|
|
76
|
+
data.forEach((node, index) => {
|
|
77
|
+
if (node.type === _constants.CODE_BLOCK) {
|
|
78
|
+
const codeLineArr = node.children.map(line => line);
|
|
79
|
+
data.splice(index, 1, ...codeLineArr);
|
|
105
80
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
81
|
+
});
|
|
82
|
+
const newData = data.map(node => {
|
|
83
|
+
const text = _slate.Node.string(node);
|
|
84
|
+
const codeLine = {
|
|
85
|
+
id: _slugid.default.nice(),
|
|
86
|
+
type: _constants.CODE_LINE,
|
|
87
|
+
children: [{
|
|
88
|
+
text: text,
|
|
89
|
+
id: _slugid.default.nice()
|
|
90
|
+
}]
|
|
91
|
+
};
|
|
92
|
+
return codeLine;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// current focus code-line string not empty
|
|
96
|
+
const string = _slate.Editor.string(newEditor, newEditor.selection.focus.path);
|
|
97
|
+
if (string.length !== 0 && _slate.Range.isCollapsed(newEditor.selection)) {
|
|
98
|
+
const [node, ...restNode] = newData;
|
|
99
|
+
const text = _slate.Node.string(node);
|
|
100
|
+
insertText(text);
|
|
101
|
+
if (restNode.length !== 0) {
|
|
102
|
+
insertBreak();
|
|
103
|
+
insertFragment(restNode);
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
110
106
|
}
|
|
107
|
+
return insertFragment(newData);
|
|
111
108
|
}
|
|
109
|
+
|
|
110
|
+
// Paste into not a code block
|
|
111
|
+
return insertFragment(data);
|
|
112
112
|
};
|
|
113
113
|
|
|
114
114
|
// Rewrite normalizeNode
|
|
@@ -213,6 +213,17 @@ const withCodeBlock = editor => {
|
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
};
|
|
216
|
+
newEditor.insertBreak = () => {
|
|
217
|
+
const selectedNode = (0, _core.getSelectedNodeByType)(newEditor, _constants.CODE_LINE);
|
|
218
|
+
if (selectedNode != null && (0, _core.isCursorAtBlockStart)(newEditor)) {
|
|
219
|
+
const line = (0, _core.generateEmptyElement)(_constants.CODE_LINE);
|
|
220
|
+
_slate.Transforms.insertNodes(editor, line, {
|
|
221
|
+
at: selectedNode[1]
|
|
222
|
+
});
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
insertBreak();
|
|
226
|
+
};
|
|
216
227
|
return newEditor;
|
|
217
228
|
};
|
|
218
229
|
var _default = exports.default = withCodeBlock;
|
|
@@ -55,6 +55,14 @@ const withHeader = editor => {
|
|
|
55
55
|
insertBreak();
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
|
+
if ((0, _core.isCursorAtBlockStart)(newEditor)) {
|
|
59
|
+
const [currentNode, path] = match;
|
|
60
|
+
const newNode = (0, _core.generateEmptyElement)(currentNode.type);
|
|
61
|
+
_slate.Transforms.insertNodes(editor, newNode, {
|
|
62
|
+
at: path
|
|
63
|
+
});
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
58
66
|
const isAtLineEnd = isSelectionAtLineEnd(editor, match[1]);
|
|
59
67
|
const nextNode = _slate.Editor.next(editor, {
|
|
60
68
|
at: match[1]
|
|
@@ -62,8 +62,8 @@ const insertLink = function (editor, title, url) {
|
|
|
62
62
|
let slateNode = arguments.length > 4 ? arguments[4] : undefined;
|
|
63
63
|
if (position === _constants.INSERT_POSITION.CURRENT && isMenuDisabled(editor)) return;
|
|
64
64
|
if (!title || !url) return;
|
|
65
|
+
const linkNode = genLinkNode(url, title);
|
|
65
66
|
if (position === _constants.INSERT_POSITION.AFTER) {
|
|
66
|
-
const linkNode = genLinkNode(url, title);
|
|
67
67
|
let path = _slate.Editor.path(editor, editor.selection);
|
|
68
68
|
if (slateNode && (slateNode === null || slateNode === void 0 ? void 0 : slateNode.type) === _constants.LIST_ITEM) {
|
|
69
69
|
path = _slateReact.ReactEditor.findPath(editor, slateNode);
|
|
@@ -88,26 +88,25 @@ const insertLink = function (editor, title, url) {
|
|
|
88
88
|
if (selection == null) return;
|
|
89
89
|
const isCollapsed = _slate.Range.isCollapsed(selection);
|
|
90
90
|
if (isCollapsed) {
|
|
91
|
-
const linkNode = genLinkNode(url, title);
|
|
92
91
|
_slate.Transforms.insertNodes(editor, linkNode);
|
|
93
|
-
|
|
94
|
-
const selectedText = _slate.Editor.string(editor, selection); // Selected text
|
|
95
|
-
if (selectedText !== title) {
|
|
96
|
-
// If the selected text is different from the typed text, delete the text and insert the link
|
|
97
|
-
editor.deleteFragment();
|
|
98
|
-
const linkNode = genLinkNode(url, title);
|
|
99
|
-
_slate.Transforms.insertNodes(editor, linkNode);
|
|
100
|
-
} else {
|
|
101
|
-
// If the selected text is the same as the entered text, only the link can be wrapped
|
|
102
|
-
const linkNode = genLinkNode(url, title);
|
|
103
|
-
_slate.Transforms.wrapNodes(editor, linkNode, {
|
|
104
|
-
split: true
|
|
105
|
-
});
|
|
106
|
-
_slate.Transforms.collapse(editor, {
|
|
107
|
-
edge: 'end'
|
|
108
|
-
});
|
|
109
|
-
}
|
|
92
|
+
return;
|
|
110
93
|
}
|
|
94
|
+
const selectedText = _slate.Editor.string(editor, selection); // Selected text
|
|
95
|
+
|
|
96
|
+
// If the selected text is different from the typed text, delete the text and insert the link
|
|
97
|
+
if (selectedText !== title) {
|
|
98
|
+
editor.deleteFragment();
|
|
99
|
+
_slate.Transforms.insertNodes(editor, linkNode);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// If the selected text is the same as the entered text, only the link can be wrapped
|
|
104
|
+
_slate.Transforms.wrapNodes(editor, linkNode, {
|
|
105
|
+
split: true
|
|
106
|
+
});
|
|
107
|
+
_slate.Transforms.collapse(editor, {
|
|
108
|
+
edge: 'end'
|
|
109
|
+
});
|
|
111
110
|
};
|
|
112
111
|
exports.insertLink = insertLink;
|
|
113
112
|
const updateLink = (editor, newText, newUrl) => {
|
|
@@ -16,7 +16,8 @@ const withParagraph = editor => {
|
|
|
16
16
|
insertText,
|
|
17
17
|
deleteBackward,
|
|
18
18
|
onHotKeyDown,
|
|
19
|
-
insertFragment
|
|
19
|
+
insertFragment,
|
|
20
|
+
insertBreak
|
|
20
21
|
} = editor;
|
|
21
22
|
const newEditor = editor;
|
|
22
23
|
newEditor.handleTab = event => {
|
|
@@ -135,6 +136,21 @@ const withParagraph = editor => {
|
|
|
135
136
|
}
|
|
136
137
|
return onHotKeyDown && onHotKeyDown(event);
|
|
137
138
|
};
|
|
139
|
+
newEditor.insertBreak = () => {
|
|
140
|
+
const selectedNode = (0, _core.getSelectedNodeByType)(newEditor, _constants.PARAGRAPH);
|
|
141
|
+
if (selectedNode != null && (0, _core.isCursorAtBlockStart)(newEditor)) {
|
|
142
|
+
const paragraph = (0, _core.generateDefaultParagraph)();
|
|
143
|
+
const targetPath = (0, _core.findPath)(editor, selectedNode);
|
|
144
|
+
const parentNode = (0, _core.getParentNode)(newEditor.children, selectedNode.id);
|
|
145
|
+
if ((parentNode === null || parentNode === void 0 ? void 0 : parentNode.type) !== _constants.LIST_ITEM) {
|
|
146
|
+
_slate.Transforms.insertNodes(editor, paragraph, {
|
|
147
|
+
at: targetPath
|
|
148
|
+
});
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
insertBreak();
|
|
153
|
+
};
|
|
138
154
|
newEditor.insertFragment = data => {
|
|
139
155
|
const paragraphBlock = (0, _core.getSelectedNodeByType)(editor, _constants.PARAGRAPH);
|
|
140
156
|
const onlyOneListItem = data.length === 1 && (0, _helpers.isSingleListItem)(data[0]);
|