@seafile/sdoc-editor 1.0.59 → 1.0.60
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.
|
@@ -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.isTextNode = exports.isStartPoint = exports.isSelectionAtBlockStart = exports.isSelectionAtBlockEnd = exports.isRangeAcrossBlocks = exports.isMultiLevelList = exports.isLastNode = exports.isLastChild = exports.isHasImg = exports.isEndPoint = exports.isCurrentLineHasText = exports.isCurrentLineEmpty = exports.isBlockTextEmptyAfterSelection = exports.isBlockAboveEmpty = exports.isAncestorEmpty = exports.getTopLevelBlockNode = exports.getSelectedNodeEntryByType = exports.getSelectedNodeByTypes = exports.getSelectedNodeByType = exports.getSelectedElems = exports.getQueryOptions = exports.getPreviousPath = exports.getPrevNode = exports.getParentNode = exports.getNodes = exports.getNodeType = exports.getNodeEntries = exports.getNodeById = exports.getNode = exports.getNextSiblingNodes = exports.getNextNode = exports.getLastChildPath = exports.getLastChild = exports.getEditorString = exports.getDeepInlineChildren = exports.getCurrentNode = exports.getCommonNode = exports.getChildren = exports.getAboveNode = exports.getAboveBlockNode = exports.findPath = exports.findNode = exports.findDescendant = void 0;
|
|
7
|
+
exports.isTopLevelListItem = exports.isTextNode = exports.isStartPoint = exports.isSelectionAtBlockStart = exports.isSelectionAtBlockEnd = exports.isRangeAcrossBlocks = exports.isMultiLevelList = exports.isLastNode = exports.isLastChild = exports.isHasImg = exports.isEndPoint = exports.isCurrentLineHasText = exports.isCurrentLineEmpty = exports.isBlockTextEmptyAfterSelection = exports.isBlockAboveEmpty = exports.isAncestorEmpty = exports.getTopLevelBlockNode = exports.getSelectedNodeEntryByType = exports.getSelectedNodeByTypes = exports.getSelectedNodeByType = exports.getSelectedElems = exports.getQueryOptions = exports.getPreviousPath = exports.getPrevNode = exports.getParentNode = exports.getNodes = exports.getNodeType = exports.getNodeEntries = exports.getNodeById = exports.getNode = exports.getNextSiblingNodes = exports.getNextNode = exports.getLastChildPath = exports.getLastChild = 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");
|
|
@@ -508,4 +508,17 @@ const isMultiLevelList = listNode => {
|
|
|
508
508
|
let isMultiLevel = children !== null && children !== void 0 && children.find(item => (item === null || item === void 0 ? void 0 : item.children.length) > 1) ? true : false;
|
|
509
509
|
return isMultiLevel;
|
|
510
510
|
};
|
|
511
|
-
exports.isMultiLevelList = isMultiLevelList;
|
|
511
|
+
exports.isMultiLevelList = isMultiLevelList;
|
|
512
|
+
const isTopLevelListItem = editor => {
|
|
513
|
+
const {
|
|
514
|
+
selection
|
|
515
|
+
} = editor;
|
|
516
|
+
if (!selection) return false;
|
|
517
|
+
const [, paragraphPath] = _slate.Editor.parent(editor, selection) || [];
|
|
518
|
+
if (paragraphPath.length !== 0) {
|
|
519
|
+
const [listItemNode, listItemPath] = _slate.Editor.parent(editor, paragraphPath) || [];
|
|
520
|
+
return listItemNode && listItemPath && (listItemNode === null || listItemNode === void 0 ? void 0 : listItemNode.type) === _constants.LIST_ITEM && (listItemPath === null || listItemPath === void 0 ? void 0 : listItemPath.length) === 2;
|
|
521
|
+
}
|
|
522
|
+
return false;
|
|
523
|
+
};
|
|
524
|
+
exports.isTopLevelListItem = isTopLevelListItem;
|
|
@@ -27,6 +27,11 @@ const isMenuDisabled = (editor, readonly) => {
|
|
|
27
27
|
if (!selection) return true;
|
|
28
28
|
const selectedElements = (0, _core.getSelectedElems)(editor);
|
|
29
29
|
const isRangeAcrossBlock = (0, _core.isRangeAcrossBlocks)(editor);
|
|
30
|
+
// If it's not the top list item, disable callout menu
|
|
31
|
+
const [node] = (0, _core.getTopLevelBlockNode)(editor);
|
|
32
|
+
if (node && [_elementType.ORDERED_LIST, _elementType.UNORDERED_LIST].includes(node === null || node === void 0 ? void 0 : node.type)) {
|
|
33
|
+
if (!(0, _core.isTopLevelListItem)(editor)) return true;
|
|
34
|
+
}
|
|
30
35
|
// If selected multiple block element contains callout, disable callout menu
|
|
31
36
|
const isAllSelectedElementsInAllowTypes = selectedElements.length && selectedElements.every(element => {
|
|
32
37
|
if (element.type === _elementType.CALL_OUT && isRangeAcrossBlock) return false;
|
|
@@ -58,6 +63,107 @@ const wrapCallout = editor => {
|
|
|
58
63
|
} = editor;
|
|
59
64
|
if (!selection) return;
|
|
60
65
|
const callout = generateCallout();
|
|
66
|
+
const [node, path] = (0, _core.getTopLevelBlockNode)(editor);
|
|
67
|
+
if (node && [_elementType.ORDERED_LIST, _elementType.UNORDERED_LIST].includes(node === null || node === void 0 ? void 0 : node.type)) {
|
|
68
|
+
if (_slate.Range.isCollapsed(selection)) {
|
|
69
|
+
_slate.Transforms.collapse(editor);
|
|
70
|
+
}
|
|
71
|
+
const {
|
|
72
|
+
path: startPath
|
|
73
|
+
} = _slate.Editor.start(editor, path) || {};
|
|
74
|
+
const {
|
|
75
|
+
offset: endOffset,
|
|
76
|
+
path: endPath
|
|
77
|
+
} = _slate.Editor.end(editor, path) || {};
|
|
78
|
+
const [, paragraphPath] = _slate.Editor.parent(editor, selection) || [];
|
|
79
|
+
const [listItemNode, listItemPath] = _slate.Editor.parent(editor, paragraphPath) || [];
|
|
80
|
+
let focusPoint = null;
|
|
81
|
+
// Highlight only the top listItem
|
|
82
|
+
if ((listItemNode === null || listItemNode === void 0 ? void 0 : listItemNode.type) === _elementType.LIST_ITEM && listItemPath.length === 2) {
|
|
83
|
+
const listNode = (0, _core.generateEmptyElement)(node.type);
|
|
84
|
+
listNode.children = [listItemNode];
|
|
85
|
+
callout.children = [listNode];
|
|
86
|
+
const {
|
|
87
|
+
path: curPath
|
|
88
|
+
} = _slate.Editor.point(editor, listItemPath) || {};
|
|
89
|
+
if (_slate.Path.equals(startPath, curPath)) {
|
|
90
|
+
// start
|
|
91
|
+
_slate.Transforms.removeNodes(editor, {
|
|
92
|
+
at: listItemPath
|
|
93
|
+
});
|
|
94
|
+
_slate.Transforms.insertNodes(editor, callout, {
|
|
95
|
+
at: [path[0]]
|
|
96
|
+
});
|
|
97
|
+
focusPoint = _slate.Editor.end(editor, [path[0]]);
|
|
98
|
+
} else if (_slate.Path.equals(endPath, curPath)) {
|
|
99
|
+
// end
|
|
100
|
+
_slate.Transforms.removeNodes(editor, {
|
|
101
|
+
at: listItemPath
|
|
102
|
+
});
|
|
103
|
+
_slate.Transforms.insertNodes(editor, callout, {
|
|
104
|
+
at: _slate.Path.next(path)
|
|
105
|
+
});
|
|
106
|
+
focusPoint = _slate.Editor.end(editor, _slate.Path.next(path));
|
|
107
|
+
} else {
|
|
108
|
+
// center
|
|
109
|
+
// Get rest list node
|
|
110
|
+
const restItemNode = _slate.Editor.nodes(editor, {
|
|
111
|
+
at: {
|
|
112
|
+
anchor: {
|
|
113
|
+
offset: 0,
|
|
114
|
+
path: curPath
|
|
115
|
+
},
|
|
116
|
+
focus: {
|
|
117
|
+
offset: endOffset,
|
|
118
|
+
path: endPath
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
match: (node, path) => {
|
|
122
|
+
// Matches the list type is LIST_ITEM
|
|
123
|
+
// Matches the list after the current path
|
|
124
|
+
// Matches top-level list-item
|
|
125
|
+
return (node === null || node === void 0 ? void 0 : node.type) === _elementType.LIST_ITEM && _slate.Path.compare(path, curPath) === 1 && path.length === 2;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
const restListNode = (0, _core.generateEmptyElement)(node.type);
|
|
129
|
+
restListNode.children = [];
|
|
130
|
+
for (const [n] of restItemNode) {
|
|
131
|
+
restListNode.children.push(n);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Delete rest list node
|
|
135
|
+
_slate.Transforms.removeNodes(editor, {
|
|
136
|
+
at: {
|
|
137
|
+
anchor: {
|
|
138
|
+
offset: 0,
|
|
139
|
+
path: curPath
|
|
140
|
+
},
|
|
141
|
+
focus: {
|
|
142
|
+
offset: endOffset,
|
|
143
|
+
path: endPath
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
match: (node, path) => (node === null || node === void 0 ? void 0 : node.type) === _elementType.LIST_ITEM && _slate.Path.compare(path, curPath) === 1 && path.length === 2
|
|
147
|
+
});
|
|
148
|
+
const insertCalloutPath = _slate.Path.next(path);
|
|
149
|
+
const insertListPath = _slate.Path.next(insertCalloutPath);
|
|
150
|
+
// Delete current list node
|
|
151
|
+
_slate.Transforms.removeNodes(editor, {
|
|
152
|
+
at: listItemPath
|
|
153
|
+
});
|
|
154
|
+
// Insert callout node and list node
|
|
155
|
+
_slate.Transforms.insertNodes(editor, callout, {
|
|
156
|
+
at: insertCalloutPath
|
|
157
|
+
});
|
|
158
|
+
_slate.Transforms.insertNodes(editor, restListNode, {
|
|
159
|
+
at: insertListPath
|
|
160
|
+
});
|
|
161
|
+
focusPoint = _slate.Editor.end(editor, insertCalloutPath);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
(0, _core.focusEditor)(editor, focusPoint);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
61
167
|
_slate.Transforms.wrapNodes(editor, callout, {
|
|
62
168
|
mode: 'highest'
|
|
63
169
|
});
|
|
@@ -46,10 +46,15 @@ const TransformMenus = _ref => {
|
|
|
46
46
|
if (_constants.HEADERS.includes(highestNode.type)) {
|
|
47
47
|
newSideMenusConfig = SIDE_TRANSFORM_MENUS_CONFIG.filter(item => item.type !== _constants.BLOCKQUOTE);
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
if ([_constants.ORDERED_LIST, _constants.UNORDERED_LIST].includes(highestNode.type)) {
|
|
50
|
+
// If it's not the top list item, cannot be converted to checks
|
|
51
|
+
if (!(0, _core.isTopLevelListItem)(editor)) {
|
|
52
|
+
newSideMenusConfig = SIDE_TRANSFORM_MENUS_CONFIG.filter(item => item.type !== _constants.CALL_OUT);
|
|
53
|
+
}
|
|
54
|
+
// Multi-level list items cannot be converted to checks
|
|
55
|
+
if ((0, _core.isMultiLevelList)(highestNode)) {
|
|
56
|
+
newSideMenusConfig = newSideMenusConfig.filter(item => item.type !== _constants.CHECK_LIST_ITEM);
|
|
57
|
+
}
|
|
53
58
|
}
|
|
54
59
|
}
|
|
55
60
|
return newSideMenusConfig;
|