@seafile/seafile-editor 3.0.41 → 3.0.42
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/extension/constants/menus-config.js +4 -4
- package/dist/extension/plugins/divider/helper.js +44 -0
- package/dist/extension/plugins/divider/menu/index.js +1 -1
- package/dist/extension/plugins/table/context-menu/horizontal-align-popover/index.js +41 -3
- package/dist/extension/plugins/table/context-menu/horizontal-align-popover/style.css +7 -0
- package/dist/extension/plugins/table/context-menu/index.js +2 -1
- package/dist/extension/plugins/table/helper.js +26 -43
- package/package.json +1 -1
- package/public/locales/en/seafile-editor.json +2 -3
|
@@ -67,12 +67,12 @@ const MENUS_CONFIG_MAP = exports.MENUS_CONFIG_MAP = {
|
|
|
67
67
|
[_elementTypes.IMAGE]: {
|
|
68
68
|
id: "seafile_".concat(_elementTypes.IMAGE),
|
|
69
69
|
iconClass: 'mdfont md-image',
|
|
70
|
-
text: '
|
|
70
|
+
text: 'Image'
|
|
71
71
|
},
|
|
72
72
|
[_elementTypes.TABLE]: {
|
|
73
73
|
id: "seafile_".concat(_elementTypes.TABLE),
|
|
74
74
|
iconClass: 'mdfont md-table',
|
|
75
|
-
text: '
|
|
75
|
+
text: 'Table'
|
|
76
76
|
},
|
|
77
77
|
[ITALIC]: {
|
|
78
78
|
id: "seafile_".concat(ITALIC),
|
|
@@ -116,7 +116,7 @@ const MENUS_CONFIG_MAP = exports.MENUS_CONFIG_MAP = {
|
|
|
116
116
|
[_elementTypes.FORMULA]: {
|
|
117
117
|
id: "seafile_".concat(_elementTypes.FORMULA),
|
|
118
118
|
iconClass: 'mdfont md-formula',
|
|
119
|
-
text: '
|
|
119
|
+
text: 'Formula'
|
|
120
120
|
},
|
|
121
121
|
[CLEAR_FORMAT]: {
|
|
122
122
|
id: "seafile_".concat(CLEAR_FORMAT),
|
|
@@ -126,7 +126,7 @@ const MENUS_CONFIG_MAP = exports.MENUS_CONFIG_MAP = {
|
|
|
126
126
|
[_elementTypes.COLUMN]: {
|
|
127
127
|
id: "seafile_".concat(_elementTypes.COLUMN),
|
|
128
128
|
iconClass: 'mdfont md-choose-column',
|
|
129
|
-
text: '
|
|
129
|
+
text: 'Column'
|
|
130
130
|
},
|
|
131
131
|
[MORE_OPERATION]: {
|
|
132
132
|
id: "seafile_".concat(MORE_OPERATION),
|
|
@@ -17,7 +17,51 @@ const transformToDivider = editor => {
|
|
|
17
17
|
exports.transformToDivider = transformToDivider;
|
|
18
18
|
const insertDivider = editor => {
|
|
19
19
|
if (!editor.selection) return;
|
|
20
|
+
const blockEntry = _slate.Editor.above(editor, {
|
|
21
|
+
at: editor.selection,
|
|
22
|
+
match: n => _slate.Element.isElement(n) && _slate.Editor.isBlock(editor, n),
|
|
23
|
+
mode: 'highest'
|
|
24
|
+
});
|
|
20
25
|
const dividerNode = (0, _core.generateElement)(_elementTypes.DIVIDER);
|
|
26
|
+
const paragraphNode = (0, _core.generateDefaultParagraph)();
|
|
27
|
+
const focusInsertedParagraph = () => {
|
|
28
|
+
const [paragraphEntry] = _slate.Editor.nodes(editor, {
|
|
29
|
+
at: [],
|
|
30
|
+
match: node => node.id === paragraphNode.id,
|
|
31
|
+
mode: 'highest'
|
|
32
|
+
});
|
|
33
|
+
if (paragraphEntry) {
|
|
34
|
+
(0, _core.focusEditor)(editor, _slate.Editor.start(editor, paragraphEntry[1]));
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
(0, _core.focusEditor)(editor);
|
|
38
|
+
};
|
|
39
|
+
if (!blockEntry) {
|
|
40
|
+
_slate.Editor.withoutNormalizing(editor, () => {
|
|
41
|
+
_slate.Transforms.insertNodes(editor, [dividerNode, paragraphNode]);
|
|
42
|
+
focusInsertedParagraph();
|
|
43
|
+
});
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const [blockNode, blockPath] = blockEntry;
|
|
47
|
+
const isEmptyParagraph = blockNode.type === _elementTypes.PARAGRAPH && _slate.Node.string(blockNode) === '';
|
|
48
|
+
const insertPath = isEmptyParagraph ? blockPath : (0, _core.isSelectionAtBlockEnd)(editor, {
|
|
49
|
+
at: editor.selection
|
|
50
|
+
}) ? _slate.Path.next(blockPath) : null;
|
|
51
|
+
if (insertPath) {
|
|
52
|
+
_slate.Editor.withoutNormalizing(editor, () => {
|
|
53
|
+
if (isEmptyParagraph) {
|
|
54
|
+
_slate.Transforms.removeNodes(editor, {
|
|
55
|
+
at: blockPath
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
_slate.Transforms.insertNodes(editor, [dividerNode, paragraphNode], {
|
|
59
|
+
at: insertPath
|
|
60
|
+
});
|
|
61
|
+
focusInsertedParagraph();
|
|
62
|
+
});
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
21
65
|
_slate.Transforms.insertNodes(editor, dividerNode);
|
|
22
66
|
(0, _core.focusEditor)(editor);
|
|
23
67
|
};
|
|
@@ -13,17 +13,21 @@ var _classnames = _interopRequireDefault(require("classnames"));
|
|
|
13
13
|
var _core = require("../../../../core");
|
|
14
14
|
var _constants = require("../../../../../constants");
|
|
15
15
|
var _tableOperations = require("../../table-operations");
|
|
16
|
+
var _helper = require("../../helper");
|
|
16
17
|
require("./style.css");
|
|
17
18
|
const HorizontalAlignPopover = _ref => {
|
|
18
19
|
let {
|
|
19
20
|
target,
|
|
20
21
|
editor,
|
|
21
22
|
readonly,
|
|
22
|
-
horizontalAlign
|
|
23
|
+
horizontalAlign,
|
|
24
|
+
handleCloseContextMenu
|
|
23
25
|
} = _ref;
|
|
24
26
|
const {
|
|
25
27
|
t
|
|
26
28
|
} = (0, _reactI18next.useTranslation)(_constants.TRANSLATE_NAMESPACE);
|
|
29
|
+
const popoverRef = (0, _react.useRef)(null);
|
|
30
|
+
const [popoverClassName, setPopoverClassName] = (0, _react.useState)('sf-table-alignment-popover');
|
|
27
31
|
const setTextAlignStyle = (0, _react.useCallback)(textAlign => {
|
|
28
32
|
if (readonly) return;
|
|
29
33
|
(0, _tableOperations.changeColumnAlign)(editor, textAlign);
|
|
@@ -34,7 +38,40 @@ const HorizontalAlignPopover = _ref => {
|
|
|
34
38
|
setTimeout(() => {
|
|
35
39
|
(0, _core.focusEditor)(editor, focusPoint);
|
|
36
40
|
}, 0);
|
|
37
|
-
|
|
41
|
+
handleCloseContextMenu();
|
|
42
|
+
}, [editor, handleCloseContextMenu, readonly]);
|
|
43
|
+
(0, _react.useEffect)(() => {
|
|
44
|
+
var _target$current;
|
|
45
|
+
const updatePlacement = () => {
|
|
46
|
+
var _popoverRef$current;
|
|
47
|
+
const popoverNode = (_popoverRef$current = popoverRef.current) === null || _popoverRef$current === void 0 ? void 0 : _popoverRef$current._element;
|
|
48
|
+
const targetNode = target === null || target === void 0 ? void 0 : target.current;
|
|
49
|
+
if (!popoverNode || !targetNode) return;
|
|
50
|
+
const boundaryRect = (0, _helper.getTableMenuBoundaryRect)(targetNode);
|
|
51
|
+
const targetRect = targetNode.getBoundingClientRect();
|
|
52
|
+
const popoverWidth = popoverNode.offsetWidth || 0;
|
|
53
|
+
const gap = 8;
|
|
54
|
+
const boundaryGap = 10;
|
|
55
|
+
const canShowRight = targetRect.right + gap + popoverWidth <= boundaryRect.right - boundaryGap;
|
|
56
|
+
const canShowLeft = targetRect.left - gap - popoverWidth >= boundaryRect.left + boundaryGap;
|
|
57
|
+
if (!canShowRight && canShowLeft) {
|
|
58
|
+
setPopoverClassName('sf-table-alignment-popover sf-table-alignment-popover-left');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
setPopoverClassName('sf-table-alignment-popover');
|
|
62
|
+
};
|
|
63
|
+
const handleMouseEnter = () => {
|
|
64
|
+
setTimeout(updatePlacement, 0);
|
|
65
|
+
};
|
|
66
|
+
updatePlacement();
|
|
67
|
+
target === null || target === void 0 ? void 0 : (_target$current = target.current) === null || _target$current === void 0 ? void 0 : _target$current.addEventListener('mouseenter', handleMouseEnter);
|
|
68
|
+
window.addEventListener('resize', updatePlacement);
|
|
69
|
+
return () => {
|
|
70
|
+
var _target$current2;
|
|
71
|
+
target === null || target === void 0 ? void 0 : (_target$current2 = target.current) === null || _target$current2 === void 0 ? void 0 : _target$current2.removeEventListener('mouseenter', handleMouseEnter);
|
|
72
|
+
window.removeEventListener('resize', updatePlacement);
|
|
73
|
+
};
|
|
74
|
+
}, [target]);
|
|
38
75
|
return /*#__PURE__*/_react.default.createElement(_reactstrap.UncontrolledPopover, {
|
|
39
76
|
target: target.current,
|
|
40
77
|
trigger: "hover",
|
|
@@ -42,7 +79,8 @@ const HorizontalAlignPopover = _ref => {
|
|
|
42
79
|
hideArrow: true,
|
|
43
80
|
fade: false,
|
|
44
81
|
offset: [0, 8],
|
|
45
|
-
popperClassName: "
|
|
82
|
+
popperClassName: "".concat(popoverClassName, " sf-popover-box-shadow"),
|
|
83
|
+
innerRef: popoverRef
|
|
46
84
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
47
85
|
className: "sf-dropdown-menu sf-table-alignment-menu"
|
|
48
86
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -5,7 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
.sf-table-alignment-popover {
|
|
7
7
|
z-index: 2000;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.sf-table-alignment-popover .popover {
|
|
11
|
+
left: 0 !important;
|
|
12
|
+
}
|
|
8
13
|
|
|
14
|
+
.sf-table-alignment-popover-left .popover {
|
|
15
|
+
transform: translateX(calc(-100% - 16px));
|
|
9
16
|
}
|
|
10
17
|
|
|
11
18
|
.sf-table-alignment-menu {
|
|
@@ -118,7 +118,8 @@ const ContextMenu = _ref => {
|
|
|
118
118
|
})), horizontalAlignRef.current && /*#__PURE__*/_react.default.createElement(_horizontalAlignPopover.default, {
|
|
119
119
|
target: horizontalAlignRef,
|
|
120
120
|
editor: editor,
|
|
121
|
-
horizontalAlign: horizontalAlign
|
|
121
|
+
horizontalAlign: horizontalAlign,
|
|
122
|
+
handleCloseContextMenu: handleCloseContextMenu
|
|
122
123
|
})));
|
|
123
124
|
};
|
|
124
125
|
var _default = exports.default = ContextMenu;
|
|
@@ -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.selectCellByGrid = exports.pasteContentIntoTable = exports.jumpOutTableInEditor = exports.isSelectingMultipleTables = exports.isInTable = exports.isDisabled = exports.insertTable = exports.getTableFocusingInfos = exports.getTableEntry = exports.getSelectedTableCells = exports.getSelectGrid = exports.getContextMenuPosition = void 0;
|
|
7
|
+
exports.selectCellByGrid = exports.pasteContentIntoTable = exports.jumpOutTableInEditor = exports.isSelectingMultipleTables = exports.isInTable = exports.isDisabled = exports.insertTable = exports.getTableMenuBoundaryRect = exports.getTableFocusingInfos = exports.getTableEntry = exports.getSelectedTableCells = exports.getSelectGrid = exports.getContextMenuPosition = void 0;
|
|
8
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
|
|
9
9
|
var _slate = require("slate");
|
|
10
10
|
var _slateReact = require("slate-react");
|
|
@@ -17,6 +17,8 @@ var _deserializeHtml = require("../../../utils/deserialize-html");
|
|
|
17
17
|
var _common = require("../../../utils/common");
|
|
18
18
|
var _helper = require("../link/helper");
|
|
19
19
|
var _helper2 = require("../image/helper");
|
|
20
|
+
const TABLE_MENU_BOUNDARY_SELECTOR = '.longtext-dialog-container, .sf-long-text-inline-editor-container';
|
|
21
|
+
const TABLE_MENU_BOUNDARY_GAP = 10;
|
|
20
22
|
const isDisabled = (editor, readonly) => {
|
|
21
23
|
const {
|
|
22
24
|
selection
|
|
@@ -275,57 +277,38 @@ const isSelectingMultipleTables = editor => {
|
|
|
275
277
|
return isSelectedMultiple;
|
|
276
278
|
};
|
|
277
279
|
exports.isSelectingMultipleTables = isSelectingMultipleTables;
|
|
280
|
+
const getTableMenuBoundaryRect = targetNode => {
|
|
281
|
+
const boundaryContainer = targetNode === null || targetNode === void 0 ? void 0 : targetNode.closest(TABLE_MENU_BOUNDARY_SELECTOR);
|
|
282
|
+
if (boundaryContainer) {
|
|
283
|
+
return boundaryContainer.getBoundingClientRect();
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
top: 0,
|
|
287
|
+
left: 0,
|
|
288
|
+
right: window.innerWidth,
|
|
289
|
+
bottom: window.innerHeight
|
|
290
|
+
};
|
|
291
|
+
};
|
|
292
|
+
exports.getTableMenuBoundaryRect = getTableMenuBoundaryRect;
|
|
278
293
|
const getContextMenuPosition = (event, tableRef) => {
|
|
279
294
|
const menuHeight = 240;
|
|
280
295
|
const menuWidth = 350;
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
clientWidth
|
|
284
|
-
} = document.body; // page
|
|
285
|
-
const {
|
|
286
|
-
x,
|
|
287
|
-
y
|
|
288
|
-
} = tableRef.current.getBoundingClientRect(); // table
|
|
296
|
+
const boundaryRect = getTableMenuBoundaryRect(tableRef.current);
|
|
297
|
+
const tableRect = tableRef.current.getBoundingClientRect();
|
|
289
298
|
const {
|
|
290
299
|
clientY,
|
|
291
300
|
clientX
|
|
292
301
|
} = event; // cursor
|
|
293
302
|
|
|
294
|
-
const
|
|
295
|
-
const
|
|
296
|
-
const
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
if (isBeyondBottom) {
|
|
301
|
-
const hiddenHeight = menuHeight - (clientHeight - clientY);
|
|
302
|
-
top = defaultTop - hiddenHeight;
|
|
303
|
-
}
|
|
304
|
-
if (isBeyondRight) {
|
|
305
|
-
const hiddenWidth = menuWidth - (clientWidth - clientX);
|
|
306
|
-
left = defaultLeft - hiddenWidth;
|
|
307
|
-
}
|
|
308
|
-
if (!isBeyondBottom && !isBeyondRight) {
|
|
309
|
-
return {
|
|
310
|
-
top: defaultTop,
|
|
311
|
-
left: defaultLeft
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
if (isBeyondBottom && isBeyondRight) {
|
|
315
|
-
return {
|
|
316
|
-
top,
|
|
317
|
-
left
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
if (isBeyondBottom) {
|
|
321
|
-
return {
|
|
322
|
-
top,
|
|
323
|
-
left: defaultLeft
|
|
324
|
-
};
|
|
325
|
-
}
|
|
303
|
+
const minTop = Math.max(boundaryRect.top - tableRect.top, 0);
|
|
304
|
+
const minLeft = Math.max(boundaryRect.left - tableRect.left, 0);
|
|
305
|
+
const maxTop = Math.max(boundaryRect.bottom - tableRect.top - menuHeight, minTop);
|
|
306
|
+
const maxLeft = Math.max(boundaryRect.right - tableRect.left - menuWidth - TABLE_MENU_BOUNDARY_GAP, minLeft);
|
|
307
|
+
const defaultTop = clientY - tableRect.top;
|
|
308
|
+
const defaultLeft = clientX - tableRect.left;
|
|
326
309
|
return {
|
|
327
|
-
top: defaultTop,
|
|
328
|
-
left
|
|
310
|
+
top: Math.min(Math.max(defaultTop, minTop), maxTop),
|
|
311
|
+
left: Math.min(Math.max(defaultLeft, minLeft), maxLeft)
|
|
329
312
|
};
|
|
330
313
|
};
|
|
331
314
|
exports.getContextMenuPosition = getContextMenuPosition;
|
package/package.json
CHANGED
|
@@ -13,14 +13,13 @@
|
|
|
13
13
|
"Ordered_list": "Ordered list",
|
|
14
14
|
"Unordered_list": "Unordered list",
|
|
15
15
|
"Check_list_item": "Check list item",
|
|
16
|
-
"
|
|
17
|
-
"Insert_formula": "Insert formula",
|
|
16
|
+
"Image": "Image",
|
|
18
17
|
"Formula": "Formula",
|
|
19
18
|
"Insert_file": "Insert file",
|
|
20
19
|
"Code": "Inline code",
|
|
21
20
|
"Code_block": "Code block",
|
|
22
21
|
"Insert_link": "Insert link",
|
|
23
|
-
"
|
|
22
|
+
"Table": "Table",
|
|
24
23
|
"Save": "Save",
|
|
25
24
|
"More": "More",
|
|
26
25
|
"Invalid_url": "Invalid URL",
|