@seafile/seafile-editor 1.0.62 → 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/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/menu/style.css +1 -0
- package/dist/extension/plugins/header/plugin.js +27 -13
- package/dist/extension/plugins/list/plugin/insert-fragment-list.js +10 -2
- 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
|
@@ -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;
|
|
@@ -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
|
|
@@ -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;
|
|
@@ -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 => {
|
|
@@ -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;
|