@seafile/seafile-editor 1.0.2 → 1.0.4
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/constants/event-types.js +2 -8
- package/dist/constants/hot-keys.js +1 -7
- package/dist/containers/article-info/index.js +24 -34
- package/dist/containers/custom/get-event-transfer.js +10 -16
- package/dist/containers/custom/set-event-transfer.js +10 -16
- package/dist/containers/hotkeys-helper/classify-hotkeys.js +20 -25
- package/dist/containers/hotkeys-helper/index.js +32 -35
- package/dist/containers/loading/index.js +11 -32
- package/dist/containers/outline/index.js +41 -51
- package/dist/containers/outline/outline-item.js +15 -21
- package/dist/editors/plain-markdown-editor/code-mirror.js +51 -75
- package/dist/editors/plain-markdown-editor/index.js +90 -107
- package/dist/editors/simple-slate-editor /index.js +43 -57
- package/dist/editors/simple-slate-editor /with-props-editor.js +4 -10
- package/dist/editors/slate-editor/editor-help/index.js +24 -37
- package/dist/editors/slate-editor/index.js +50 -64
- package/dist/editors/slate-editor/with-props-editor.js +4 -10
- package/dist/editors/slate-viewer/index.js +25 -31
- package/dist/extension/commons/element-popover/index.js +30 -55
- package/dist/extension/commons/index.js +3 -26
- package/dist/extension/commons/menu/index.js +4 -21
- package/dist/extension/commons/menu/menu-drop-down.js +50 -63
- package/dist/extension/commons/menu/menu-group.js +4 -11
- package/dist/extension/commons/menu/menu-item.js +25 -30
- package/dist/extension/commons/tooltip/index.js +14 -19
- package/dist/extension/constants/element-types.js +22 -28
- package/dist/extension/constants/index.js +15 -37
- package/dist/extension/constants/keyboard.js +3 -9
- package/dist/extension/constants/menus-config.js +118 -105
- package/dist/extension/core/index.js +3 -38
- package/dist/extension/core/queries/index.js +209 -304
- package/dist/extension/core/transforms/focus-editor.js +7 -13
- package/dist/extension/core/transforms/index.js +4 -49
- package/dist/extension/core/transforms/move-children.js +18 -25
- package/dist/extension/core/transforms/remove-node-children.js +8 -27
- package/dist/extension/core/transforms/replace-node-children.js +14 -19
- package/dist/extension/core/utils/index.js +36 -44
- package/dist/extension/editor.js +8 -15
- package/dist/extension/index.js +7 -48
- package/dist/extension/plugins/blockquote/helpers.js +38 -57
- package/dist/extension/plugins/blockquote/index.js +8 -15
- package/dist/extension/plugins/blockquote/menu/index.js +20 -25
- package/dist/extension/plugins/blockquote/plugin.js +35 -41
- package/dist/extension/plugins/blockquote/render-elem.js +9 -14
- package/dist/extension/plugins/check-list/helper.js +14 -24
- package/dist/extension/plugins/check-list/index.js +10 -17
- package/dist/extension/plugins/check-list/menu/index.js +21 -29
- package/dist/extension/plugins/check-list/plugin.js +24 -26
- package/dist/extension/plugins/check-list/render-elem.js +22 -28
- package/dist/extension/plugins/clear-format/helpers.js +25 -47
- package/dist/extension/plugins/clear-format/menu/index.js +22 -29
- package/dist/extension/plugins/code-block/helpers.js +74 -126
- package/dist/extension/plugins/code-block/index.js +10 -18
- package/dist/extension/plugins/code-block/menu/index.js +20 -27
- package/dist/extension/plugins/code-block/plugin.js +123 -144
- package/dist/extension/plugins/code-block/render-elem/constant.js +15 -11
- package/dist/extension/plugins/code-block/render-elem/index.js +30 -39
- package/dist/extension/plugins/code-block/render-elem/language-selector.js +19 -27
- package/dist/extension/plugins/formula/helper.js +39 -45
- package/dist/extension/plugins/formula/index.js +10 -17
- package/dist/extension/plugins/formula/menu/formula-modal.js +37 -52
- package/dist/extension/plugins/formula/menu/index.js +34 -50
- package/dist/extension/plugins/formula/plugin.js +12 -14
- package/dist/extension/plugins/formula/render-elem.js +27 -33
- package/dist/extension/plugins/header/helper.js +35 -48
- package/dist/extension/plugins/header/index.js +10 -17
- package/dist/extension/plugins/header/menu/index.js +52 -66
- package/dist/extension/plugins/header/plugin.js +72 -83
- package/dist/extension/plugins/header/render-elem.js +15 -20
- package/dist/extension/plugins/image/helper.js +28 -37
- package/dist/extension/plugins/image/index.js +10 -17
- package/dist/extension/plugins/image/menu/image-menu-dialog.js +31 -42
- package/dist/extension/plugins/image/menu/image-menu-popover.js +35 -67
- package/dist/extension/plugins/image/menu/index.js +24 -34
- package/dist/extension/plugins/image/plugin.js +18 -18
- package/dist/extension/plugins/image/render-element/image-previewer.js +32 -42
- package/dist/extension/plugins/image/render-element/index.js +58 -74
- package/dist/extension/plugins/index.js +18 -94
- package/dist/extension/plugins/link/helper.js +102 -139
- package/dist/extension/plugins/link/index.js +10 -17
- package/dist/extension/plugins/link/menu/index.js +46 -62
- package/dist/extension/plugins/link/menu/link-modal.js +67 -87
- package/dist/extension/plugins/link/plugin.js +52 -56
- package/dist/extension/plugins/link/render-elem/index.js +39 -54
- package/dist/extension/plugins/link/render-elem/link-popover.js +38 -42
- package/dist/extension/plugins/list/constant.js +2 -8
- package/dist/extension/plugins/list/helpers.js +40 -54
- package/dist/extension/plugins/list/index.js +10 -17
- package/dist/extension/plugins/list/menu/index.js +23 -33
- package/dist/extension/plugins/list/plugin/index.js +28 -31
- package/dist/extension/plugins/list/plugin/insert-break-list.js +9 -15
- package/dist/extension/plugins/list/plugin/insert-fragment-list.js +86 -109
- package/dist/extension/plugins/list/plugin/normalize-list.js +31 -42
- package/dist/extension/plugins/list/plugin/on-tab-handle.js +35 -34
- package/dist/extension/plugins/list/queries/index.js +22 -30
- package/dist/extension/plugins/list/render-elem/index.js +27 -27
- package/dist/extension/plugins/list/transforms/index.js +11 -75
- package/dist/extension/plugins/list/transforms/insert-list-item.js +38 -47
- package/dist/extension/plugins/list/transforms/move-list-item-down.js +22 -32
- package/dist/extension/plugins/list/transforms/move-list-item-up.js +45 -56
- package/dist/extension/plugins/list/transforms/move-list-items-to-list.js +25 -31
- package/dist/extension/plugins/list/transforms/move-list-items.js +37 -44
- package/dist/extension/plugins/list/transforms/normalize-list-item.js +57 -81
- package/dist/extension/plugins/list/transforms/normalize-nested-list.js +17 -26
- package/dist/extension/plugins/list/transforms/remove-first-list-item.js +12 -19
- package/dist/extension/plugins/list/transforms/transforms-to-list.js +60 -84
- package/dist/extension/plugins/list/transforms/unwrap-list.js +20 -29
- package/dist/extension/plugins/node-id/constants.js +9 -15
- package/dist/extension/plugins/node-id/helpers.js +33 -35
- package/dist/extension/plugins/node-id/index.js +4 -11
- package/dist/extension/plugins/node-id/with-node-id.js +18 -26
- package/dist/extension/plugins/paragraph/helper.js +7 -13
- package/dist/extension/plugins/paragraph/index.js +8 -15
- package/dist/extension/plugins/paragraph/plugin.js +25 -27
- package/dist/extension/plugins/paragraph/render-elem.js +9 -14
- package/dist/extension/plugins/table/constant.js +3 -9
- package/dist/extension/plugins/table/helper.js +133 -154
- package/dist/extension/plugins/table/index.js +11 -19
- package/dist/extension/plugins/table/menu/index.js +26 -38
- package/dist/extension/plugins/table/menu/table-operator.js +62 -77
- package/dist/extension/plugins/table/menu/table-size-selector.js +41 -62
- package/dist/extension/plugins/table/model.js +39 -41
- package/dist/extension/plugins/table/plugin.js +95 -102
- package/dist/extension/plugins/table/render-elem/context-menu.js +42 -65
- package/dist/extension/plugins/table/render-elem/index.js +85 -93
- package/dist/extension/plugins/table/table-operations.js +101 -118
- package/dist/extension/plugins/text-style/helpers.js +18 -28
- package/dist/extension/plugins/text-style/index.js +8 -15
- package/dist/extension/plugins/text-style/menu/index.js +19 -25
- package/dist/extension/plugins/text-style/plugin.js +16 -21
- package/dist/extension/plugins/text-style/render-elem.js +28 -33
- package/dist/extension/render/render-element.js +26 -47
- package/dist/extension/render/render-leaf.js +9 -18
- package/dist/extension/toolbar/header-toolbar/index.js +66 -84
- package/dist/extension/toolbar/index.js +2 -13
- package/dist/extension/toolbar/user-help/shortcut-dialog.js +108 -131
- package/dist/hooks/use-mathjax.js +9 -20
- package/dist/hooks/use-scroll-context.js +7 -12
- package/dist/hooks/use-selection-update.js +9 -21
- package/dist/index.js +9 -80
- package/dist/pages/markdown-editor.js +30 -43
- package/dist/pages/markdown-view.js +25 -37
- package/dist/pages/rich-markdown-editor.js +54 -67
- package/dist/pages/simple-editor.js +29 -42
- package/dist/slate-convert/html-to-slate/constants.js +26 -32
- package/dist/slate-convert/html-to-slate/helper.js +1 -7
- package/dist/slate-convert/html-to-slate/index.js +44 -51
- package/dist/slate-convert/html-to-slate/rules/blockquote.js +10 -15
- package/dist/slate-convert/html-to-slate/rules/check-list.js +10 -15
- package/dist/slate-convert/html-to-slate/rules/code-block.js +40 -51
- package/dist/slate-convert/html-to-slate/rules/header.js +11 -16
- package/dist/slate-convert/html-to-slate/rules/image.js +10 -15
- package/dist/slate-convert/html-to-slate/rules/index.js +11 -18
- package/dist/slate-convert/html-to-slate/rules/link.js +11 -16
- package/dist/slate-convert/html-to-slate/rules/list.js +21 -26
- package/dist/slate-convert/html-to-slate/rules/paragraph.js +10 -15
- package/dist/slate-convert/html-to-slate/rules/table.js +14 -19
- package/dist/slate-convert/html-to-slate/rules/text.js +14 -19
- package/dist/slate-convert/index.js +8 -34
- package/dist/slate-convert/md-to-html/index.js +26 -31
- package/dist/slate-convert/md-to-html/sanitize-schema.js +5 -12
- package/dist/slate-convert/md-to-slate/index.js +17 -23
- package/dist/slate-convert/md-to-slate/transform.js +183 -175
- package/dist/slate-convert/slate-to-md/index.js +14 -20
- package/dist/slate-convert/slate-to-md/transform.js +76 -87
- package/dist/utils/common.js +8 -15
- package/dist/utils/deserialize-html.js +118 -166
- package/dist/utils/dom-utils.js +18 -22
- package/dist/utils/event-bus.js +27 -47
- package/dist/utils/event-handler.js +29 -38
- package/dist/utils/object-utils.js +39 -62
- package/package.json +5 -4
|
@@ -1,52 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
require("./style.css");
|
|
16
|
-
var RenderTableContainer = function RenderTableContainer(_ref, editor) {
|
|
17
|
-
var attributes = _ref.attributes,
|
|
18
|
-
children = _ref.children,
|
|
19
|
-
element = _ref.element;
|
|
20
|
-
var tableRef = (0, _react.useRef)(null);
|
|
21
|
-
var startGridRef = (0, _react.useRef)({
|
|
1
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { useReadOnly } from 'slate-react';
|
|
3
|
+
import { TEXT_ALIGN } from '../../../constants';
|
|
4
|
+
import { TABLE_BODY_NODE_NAME, TABLE_CELL_NODE_NAME, TABLE_ROW_NODE_NAME } from '../constant';
|
|
5
|
+
import ContextMenu from './context-menu';
|
|
6
|
+
import './style.css';
|
|
7
|
+
const RenderTableContainer = (_ref, editor) => {
|
|
8
|
+
let {
|
|
9
|
+
attributes,
|
|
10
|
+
children,
|
|
11
|
+
element
|
|
12
|
+
} = _ref;
|
|
13
|
+
const tableRef = useRef(null);
|
|
14
|
+
const startGridRef = useRef({
|
|
22
15
|
rowIndex: -1,
|
|
23
16
|
colIndex: -1
|
|
24
17
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
top: 0,
|
|
39
|
-
left: 0
|
|
40
|
-
}),
|
|
41
|
-
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
|
42
|
-
contextMenuPosition = _useState6[0],
|
|
43
|
-
setContextMenuPosition = _useState6[1];
|
|
44
|
-
var isReadonly = (0, _slateReact.useReadOnly)();
|
|
45
|
-
(0, _react.useEffect)(function () {
|
|
18
|
+
const [, setSelectGridRange] = useState({
|
|
19
|
+
startRowIndex: -1,
|
|
20
|
+
startColIndex: -1,
|
|
21
|
+
endRowIndex: -1,
|
|
22
|
+
endColIndex: -1
|
|
23
|
+
});
|
|
24
|
+
const [isShowContextMenu, setIsShowContextMenu] = useState(false);
|
|
25
|
+
const [contextMenuPosition, setContextMenuPosition] = useState({
|
|
26
|
+
top: 0,
|
|
27
|
+
left: 0
|
|
28
|
+
});
|
|
29
|
+
const isReadonly = useReadOnly();
|
|
30
|
+
useEffect(() => {
|
|
46
31
|
if (isReadonly) return null;
|
|
47
32
|
clearSelectedCells();
|
|
48
33
|
document.addEventListener('contextmenu', handleContextMenu);
|
|
49
|
-
return
|
|
34
|
+
return () => {
|
|
50
35
|
document.removeEventListener('contextmenu', handleContextMenu);
|
|
51
36
|
document.removeEventListener('mousedown', unregisterEventHandler);
|
|
52
37
|
document.removeEventListener('keyup', unregisterEventHandler);
|
|
@@ -55,29 +40,29 @@ var RenderTableContainer = function RenderTableContainer(_ref, editor) {
|
|
|
55
40
|
};
|
|
56
41
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
57
42
|
}, []);
|
|
58
|
-
|
|
59
|
-
|
|
43
|
+
const getTableElement = useCallback((node, type) => {
|
|
44
|
+
let target = node;
|
|
60
45
|
if (target.nodeName.toLowerCase() === type) return target;
|
|
61
46
|
while (target.nodeName.toLowerCase() !== type) {
|
|
62
47
|
target = target.parentNode;
|
|
63
48
|
}
|
|
64
49
|
return target;
|
|
65
50
|
}, []);
|
|
66
|
-
|
|
51
|
+
const clearSelectedCells = useCallback(e => {
|
|
67
52
|
isShowContextMenu && handleCloseContextMenu();
|
|
68
|
-
tableRef.current.querySelectorAll('.selected-cell').forEach(
|
|
53
|
+
tableRef.current.querySelectorAll('.selected-cell').forEach(selectedCell => {
|
|
69
54
|
selectedCell.classList.remove('selected-cell', 'selected-cell-left', 'selected-cell-bottom', 'selected-cell-top', 'selected-cell-right');
|
|
70
55
|
});
|
|
71
56
|
document.removeEventListener('keyup', clearSelectedCells);
|
|
72
57
|
document.removeEventListener('click', clearSelectedCells);
|
|
73
58
|
}, [isShowContextMenu]);
|
|
74
|
-
|
|
59
|
+
const updateSelectedCellStyles = useCallback((startRowIndex, endRowIndex, startColIndex, endColIndex) => {
|
|
75
60
|
clearSelectedCells();
|
|
76
61
|
if (startColIndex < 0 || startRowIndex < 0) return;
|
|
77
|
-
for (
|
|
78
|
-
|
|
79
|
-
for (
|
|
80
|
-
|
|
62
|
+
for (let rowIndex = startRowIndex; rowIndex <= endRowIndex; rowIndex++) {
|
|
63
|
+
let currentRow = tableRef.current.querySelectorAll(TABLE_ROW_NODE_NAME)[rowIndex];
|
|
64
|
+
for (let colIndex = startColIndex; colIndex <= endColIndex; colIndex++) {
|
|
65
|
+
const selectedCell = currentRow.querySelectorAll(TABLE_CELL_NODE_NAME)[colIndex];
|
|
81
66
|
selectedCell.classList.add('selected-cell');
|
|
82
67
|
// Set selected cell border
|
|
83
68
|
rowIndex === startRowIndex && selectedCell.classList.add('selected-cell-top');
|
|
@@ -87,43 +72,44 @@ var RenderTableContainer = function RenderTableContainer(_ref, editor) {
|
|
|
87
72
|
}
|
|
88
73
|
}
|
|
89
74
|
setSelectGridRange({
|
|
90
|
-
startRowIndex
|
|
91
|
-
endRowIndex
|
|
92
|
-
startColIndex
|
|
93
|
-
endColIndex
|
|
75
|
+
startRowIndex,
|
|
76
|
+
endRowIndex,
|
|
77
|
+
startColIndex,
|
|
78
|
+
endColIndex
|
|
94
79
|
});
|
|
95
80
|
}, [clearSelectedCells]);
|
|
96
|
-
|
|
81
|
+
const selectCellsInTable = useCallback(e => {
|
|
97
82
|
// Check if the target is in the table
|
|
98
|
-
if (e.target.nodeName.toLowerCase() ===
|
|
83
|
+
if (e.target.nodeName.toLowerCase() === TABLE_BODY_NODE_NAME || !tableRef.current.contains(e.target)) return;
|
|
99
84
|
// Figure out select range
|
|
100
|
-
|
|
101
|
-
startRowIndex
|
|
102
|
-
startColIndex
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
85
|
+
const {
|
|
86
|
+
startRowIndex,
|
|
87
|
+
startColIndex
|
|
88
|
+
} = startGridRef.current;
|
|
89
|
+
const endRowIndex = getTableElement(e.target, TABLE_ROW_NODE_NAME).rowIndex;
|
|
90
|
+
const endColIndex = getTableElement(e.target, TABLE_CELL_NODE_NAME).cellIndex;
|
|
91
|
+
const minRowIndex = Math.min(startRowIndex, endRowIndex);
|
|
92
|
+
const maxRowIndex = Math.max(startRowIndex, endRowIndex);
|
|
93
|
+
const minColIndex = Math.min(startColIndex, endColIndex);
|
|
94
|
+
const maxColIndex = Math.max(startColIndex, endColIndex);
|
|
109
95
|
// Select one cell
|
|
110
96
|
if (minRowIndex === maxRowIndex && minColIndex === maxColIndex) return;
|
|
111
97
|
// collapse selection
|
|
112
98
|
window.getSelection().collapseToEnd();
|
|
113
99
|
updateSelectedCellStyles(minRowIndex, maxRowIndex, minColIndex, maxColIndex);
|
|
114
100
|
}, [getTableElement, updateSelectedCellStyles]);
|
|
115
|
-
|
|
101
|
+
const handleMouseUp = useCallback(e => {
|
|
116
102
|
document.removeEventListener('mousemove', selectCellsInTable);
|
|
117
103
|
document.removeEventListener('mouseup', handleMouseUp);
|
|
118
104
|
document.addEventListener('keyup', clearSelectedCells);
|
|
119
105
|
document.addEventListener('mousedown', clearSelectedCells);
|
|
120
106
|
}, [clearSelectedCells, selectCellsInTable]);
|
|
121
|
-
|
|
107
|
+
const handleMouseDown = useCallback(e => {
|
|
122
108
|
// Clear last rendered styles
|
|
123
109
|
clearSelectedCells();
|
|
124
110
|
// Set new select range
|
|
125
|
-
|
|
126
|
-
|
|
111
|
+
const startRowIndex = getTableElement(e.target, TABLE_ROW_NODE_NAME).rowIndex;
|
|
112
|
+
const startColIndex = getTableElement(e.target, TABLE_CELL_NODE_NAME).cellIndex;
|
|
127
113
|
startGridRef.current = {
|
|
128
114
|
startRowIndex: startRowIndex,
|
|
129
115
|
startColIndex: startColIndex
|
|
@@ -131,13 +117,14 @@ var RenderTableContainer = function RenderTableContainer(_ref, editor) {
|
|
|
131
117
|
document.addEventListener('mousemove', selectCellsInTable);
|
|
132
118
|
document.addEventListener('mouseup', handleMouseUp);
|
|
133
119
|
}, [clearSelectedCells, getTableElement, handleMouseUp, selectCellsInTable]);
|
|
134
|
-
|
|
120
|
+
const handleContextMenu = useCallback(e => {
|
|
135
121
|
if (!tableRef.current.contains(e.target)) return;
|
|
136
122
|
e.preventDefault();
|
|
137
123
|
e.stopPropagation();
|
|
138
|
-
|
|
139
|
-
x
|
|
140
|
-
y
|
|
124
|
+
const {
|
|
125
|
+
x,
|
|
126
|
+
y
|
|
127
|
+
} = tableRef.current.getBoundingClientRect();
|
|
141
128
|
setContextMenuPosition({
|
|
142
129
|
top: e.clientY - y,
|
|
143
130
|
left: e.clientX - x
|
|
@@ -147,40 +134,45 @@ var RenderTableContainer = function RenderTableContainer(_ref, editor) {
|
|
|
147
134
|
document.addEventListener('keyup', unregisterEventHandler);
|
|
148
135
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
149
136
|
}, []);
|
|
150
|
-
|
|
137
|
+
const unregisterEventHandler = useCallback(() => {
|
|
151
138
|
document.removeEventListener('mousedown', handleContextMenu);
|
|
152
139
|
}, [handleContextMenu]);
|
|
153
|
-
|
|
140
|
+
const handleCloseContextMenu = () => {
|
|
154
141
|
setIsShowContextMenu(false);
|
|
155
142
|
};
|
|
156
|
-
return /*#__PURE__*/
|
|
143
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
157
144
|
style: {
|
|
158
145
|
position: 'relative'
|
|
159
146
|
}
|
|
160
|
-
}, /*#__PURE__*/
|
|
147
|
+
}, /*#__PURE__*/React.createElement("table", {
|
|
161
148
|
ref: tableRef,
|
|
162
149
|
onMouseDown: handleMouseDown,
|
|
163
150
|
className: "sf-table-container"
|
|
164
|
-
}, /*#__PURE__*/
|
|
151
|
+
}, /*#__PURE__*/React.createElement("tbody", attributes, children)), isShowContextMenu && /*#__PURE__*/React.createElement(ContextMenu, {
|
|
165
152
|
handleCloseContextMenu: handleCloseContextMenu,
|
|
166
153
|
position: contextMenuPosition,
|
|
167
154
|
editor: editor
|
|
168
155
|
}));
|
|
169
156
|
};
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
157
|
+
export default RenderTableContainer;
|
|
158
|
+
export const RenderTableRow = _ref2 => {
|
|
159
|
+
let {
|
|
160
|
+
attributes,
|
|
161
|
+
children,
|
|
162
|
+
element
|
|
163
|
+
} = _ref2;
|
|
164
|
+
return /*#__PURE__*/React.createElement("tr", attributes, children);
|
|
176
165
|
};
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
166
|
+
export const RenderTableCell = _ref3 => {
|
|
167
|
+
let {
|
|
168
|
+
attributes,
|
|
169
|
+
children,
|
|
170
|
+
element
|
|
171
|
+
} = _ref3;
|
|
172
|
+
const {
|
|
173
|
+
align = TEXT_ALIGN.LEFT
|
|
174
|
+
} = element;
|
|
175
|
+
return /*#__PURE__*/React.createElement("td", Object.assign({
|
|
184
176
|
"data-root": "true",
|
|
185
177
|
style: {
|
|
186
178
|
textAlign: align
|
|
@@ -1,147 +1,127 @@
|
|
|
1
|
-
|
|
1
|
+
import { Editor, Transforms } from 'slate';
|
|
2
|
+
import { INSERT_POSITION } from '../../constants';
|
|
3
|
+
import { getSelectGrid, getTableEntry, getTableFocusingInfos } from './helper';
|
|
4
|
+
import { generateTableCell, generateTableRow } from './model';
|
|
5
|
+
import { focusEditor } from '../../core';
|
|
2
6
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.removeTable = exports.removeRow = exports.removeColumn = exports.insertRow = exports.insertColumn = exports.changeCellAlign = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/defineProperty"));
|
|
9
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
|
|
10
|
-
var _slate = require("slate");
|
|
11
|
-
var _constants = require("../../constants");
|
|
12
|
-
var _helper = require("./helper");
|
|
13
|
-
var _model = require("./model");
|
|
14
|
-
var _core = require("../../core");
|
|
15
7
|
/**
|
|
16
8
|
* @param {Object} editor
|
|
17
9
|
* @param {INSERT_POSITION.AFTER | INSERT_POSITION.BEFORE} insertPosition by default is INSERT_POSITION.AFTER
|
|
18
10
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}), (0, _defineProperty2.default)(_handlePosition, _constants.INSERT_POSITION.AFTER, function (rowIndex) {
|
|
32
|
-
return tablePath.concat(rowIndex + 1);
|
|
33
|
-
}), _handlePosition);
|
|
11
|
+
const insertRow = function (editor) {
|
|
12
|
+
let position = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : INSERT_POSITION.AFTER;
|
|
13
|
+
const {
|
|
14
|
+
tableEntry: [, tablePath],
|
|
15
|
+
rowEntry: [rowNode],
|
|
16
|
+
rowIndex
|
|
17
|
+
} = getTableFocusingInfos(editor);
|
|
18
|
+
const getInsertPath = rowIndex => {
|
|
19
|
+
const handlePosition = {
|
|
20
|
+
[INSERT_POSITION.BEFORE]: rowIndex => tablePath.concat(rowIndex),
|
|
21
|
+
[INSERT_POSITION.AFTER]: rowIndex => tablePath.concat(rowIndex + 1)
|
|
22
|
+
};
|
|
34
23
|
return handlePosition[position](rowIndex);
|
|
35
24
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
25
|
+
const insertPath = getInsertPath(rowIndex);
|
|
26
|
+
const insertRowChildren = rowNode.children.map(_ref => {
|
|
27
|
+
let {
|
|
28
|
+
align
|
|
29
|
+
} = _ref;
|
|
30
|
+
return generateTableCell({
|
|
31
|
+
align
|
|
41
32
|
});
|
|
42
33
|
});
|
|
43
|
-
|
|
34
|
+
const insertRow = generateTableRow({
|
|
44
35
|
childrenOrText: insertRowChildren
|
|
45
36
|
});
|
|
46
|
-
|
|
37
|
+
Transforms.insertNodes(editor, insertRow, {
|
|
47
38
|
at: insertPath
|
|
48
39
|
});
|
|
49
40
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
var focusPoint = null;
|
|
59
|
-
var tableHeight = tableNode.children.length;
|
|
41
|
+
const removeRow = editor => {
|
|
42
|
+
const {
|
|
43
|
+
tableEntry: [tableNode, tablePath],
|
|
44
|
+
rowEntry: [, rowPath],
|
|
45
|
+
rowIndex
|
|
46
|
+
} = getTableFocusingInfos(editor);
|
|
47
|
+
let focusPoint = null;
|
|
48
|
+
const tableHeight = tableNode.children.length;
|
|
60
49
|
// If table has one more row, remove row, else remove table
|
|
61
50
|
if (tableHeight > 1) {
|
|
62
51
|
// If removing row is the last row, focus on the previous row
|
|
63
|
-
|
|
64
|
-
focusPoint = isRemovingLastRow ?
|
|
65
|
-
|
|
52
|
+
const isRemovingLastRow = rowIndex === tableHeight - 1;
|
|
53
|
+
focusPoint = isRemovingLastRow ? Editor.start(editor, tablePath.concat(rowIndex - 1)) : Editor.start(editor, rowPath);
|
|
54
|
+
Transforms.removeNodes(editor, {
|
|
66
55
|
at: rowPath
|
|
67
56
|
});
|
|
68
|
-
|
|
57
|
+
focusEditor(editor, focusPoint);
|
|
69
58
|
} else {
|
|
70
59
|
removeTable(editor);
|
|
71
60
|
}
|
|
72
61
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
_getTableEntry2 = (0, _slicedToArray2.default)(_getTableEntry, 1),
|
|
76
|
-
tableNodeEntry = _getTableEntry2[0];
|
|
62
|
+
const removeTable = editor => {
|
|
63
|
+
const [tableNodeEntry] = getTableEntry(editor);
|
|
77
64
|
if (!tableNodeEntry) return;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
var previousNodeEntry = _slate.Editor.previous(editor, {
|
|
65
|
+
const [, tablePath] = tableNodeEntry;
|
|
66
|
+
const previousNodeEntry = Editor.previous(editor, {
|
|
81
67
|
at: tablePath
|
|
82
68
|
});
|
|
83
|
-
|
|
84
|
-
|
|
69
|
+
const focusPoint = Editor.end(editor, previousNodeEntry[1]);
|
|
70
|
+
Transforms.removeNodes(editor, {
|
|
85
71
|
at: tablePath
|
|
86
72
|
});
|
|
87
|
-
|
|
73
|
+
focusEditor(editor, focusPoint);
|
|
88
74
|
};
|
|
89
75
|
|
|
90
76
|
/**
|
|
91
77
|
* @param {Object} editor
|
|
92
78
|
* @param {INSERT_POSITION.AFTER | INSERT_POSITION.BEFORE} insertPosition by default is INSERT_POSITION.AFTER
|
|
93
79
|
*/
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}), (0, _defineProperty2.default)(_newCellPath, _constants.INSERT_POSITION.AFTER, function (rowIndex, columnIndex) {
|
|
107
|
-
return tablePath.concat(rowIndex, columnIndex + 1);
|
|
108
|
-
}), _newCellPath);
|
|
80
|
+
const insertColumn = function (editor) {
|
|
81
|
+
let insertPosition = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : INSERT_POSITION.AFTER;
|
|
82
|
+
const {
|
|
83
|
+
tableEntry: [tableNode, tablePath],
|
|
84
|
+
rowIndex,
|
|
85
|
+
columnIndex
|
|
86
|
+
} = getTableFocusingInfos(editor);
|
|
87
|
+
const getInsertPath = (rowIndex, columnIndex) => {
|
|
88
|
+
const newCellPath = {
|
|
89
|
+
[INSERT_POSITION.BEFORE]: (rowIndex, columnIndex) => tablePath.concat(rowIndex, columnIndex),
|
|
90
|
+
[INSERT_POSITION.AFTER]: (rowIndex, columnIndex) => tablePath.concat(rowIndex, columnIndex + 1)
|
|
91
|
+
};
|
|
109
92
|
return newCellPath[insertPosition](rowIndex, columnIndex);
|
|
110
93
|
};
|
|
111
|
-
tableNode.children.forEach(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
94
|
+
tableNode.children.forEach((row, rowIndex) => {
|
|
95
|
+
const insertPath = getInsertPath(rowIndex, columnIndex);
|
|
96
|
+
const newCell = generateTableCell(rowIndex, columnIndex);
|
|
97
|
+
Transforms.insertNodes(editor, newCell, {
|
|
115
98
|
at: insertPath
|
|
116
99
|
});
|
|
117
100
|
});
|
|
118
|
-
|
|
119
|
-
|
|
101
|
+
const focusPoint = Editor.start(editor, getInsertPath(rowIndex, columnIndex));
|
|
102
|
+
focusEditor(editor, focusPoint);
|
|
120
103
|
};
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
columnIndex = _getTableFocusingInfo9.columnIndex;
|
|
130
|
-
var tableWidth = rowNode.children.length;
|
|
131
|
-
var focusPoint = null;
|
|
104
|
+
const removeColumn = editor => {
|
|
105
|
+
const {
|
|
106
|
+
tableEntry: [tableNode, tablePath],
|
|
107
|
+
rowEntry: [rowNode, rowPath],
|
|
108
|
+
columnIndex
|
|
109
|
+
} = getTableFocusingInfos(editor);
|
|
110
|
+
const tableWidth = rowNode.children.length;
|
|
111
|
+
let focusPoint = null;
|
|
132
112
|
|
|
133
113
|
// If table has one more column, remove column, else remove table
|
|
134
114
|
if (tableWidth > 1) {
|
|
135
115
|
// If removing column is the last column, focus on the previous column
|
|
136
|
-
|
|
137
|
-
tableNode.children.forEach(
|
|
138
|
-
|
|
139
|
-
|
|
116
|
+
const isRemovingLastColumn = columnIndex === tableWidth - 1;
|
|
117
|
+
tableNode.children.forEach((row, rowIndex) => {
|
|
118
|
+
const removePath = tablePath.concat(rowIndex, columnIndex);
|
|
119
|
+
Transforms.removeNodes(editor, {
|
|
140
120
|
at: removePath
|
|
141
121
|
});
|
|
142
122
|
});
|
|
143
|
-
focusPoint = isRemovingLastColumn ?
|
|
144
|
-
|
|
123
|
+
focusPoint = isRemovingLastColumn ? Editor.start(editor, rowPath.concat(columnIndex - 1)) : Editor.start(editor, rowPath.concat(columnIndex));
|
|
124
|
+
focusEditor(editor, focusPoint);
|
|
145
125
|
} else {
|
|
146
126
|
removeTable(editor);
|
|
147
127
|
}
|
|
@@ -151,25 +131,27 @@ var removeColumn = exports.removeColumn = function removeColumn(editor) {
|
|
|
151
131
|
* @param {Object} editor
|
|
152
132
|
* @param {keyof TEXT_ALIGN} align Text align
|
|
153
133
|
*/
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
134
|
+
const changeCellAlign = (editor, align) => {
|
|
135
|
+
const {
|
|
136
|
+
tableEntry: [, tablePath],
|
|
137
|
+
columnIndex,
|
|
138
|
+
rowIndex
|
|
139
|
+
} = getTableFocusingInfos(editor);
|
|
140
|
+
const selectGrid = getSelectGrid(editor);
|
|
161
141
|
|
|
162
142
|
// If select a range in table
|
|
163
143
|
if (selectGrid) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
144
|
+
const {
|
|
145
|
+
startRowIndex,
|
|
146
|
+
endRowIndex,
|
|
147
|
+
startColIndex,
|
|
148
|
+
endColIndex
|
|
149
|
+
} = selectGrid;
|
|
150
|
+
for (let rowIndex = startRowIndex; rowIndex <= endRowIndex; rowIndex++) {
|
|
151
|
+
for (let columnIndex = startColIndex; columnIndex <= endColIndex; columnIndex++) {
|
|
152
|
+
const cellPath = tablePath.concat(rowIndex, columnIndex);
|
|
153
|
+
Transforms.setNodes(editor, {
|
|
154
|
+
align
|
|
173
155
|
}, {
|
|
174
156
|
at: cellPath
|
|
175
157
|
});
|
|
@@ -177,11 +159,12 @@ var changeCellAlign = exports.changeCellAlign = function changeCellAlign(editor,
|
|
|
177
159
|
}
|
|
178
160
|
} else {
|
|
179
161
|
// If select a cell in table
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
align
|
|
162
|
+
const cellPath = tablePath.concat(rowIndex, columnIndex);
|
|
163
|
+
Transforms.setNodes(editor, {
|
|
164
|
+
align
|
|
183
165
|
}, {
|
|
184
|
-
at:
|
|
166
|
+
at: cellPath
|
|
185
167
|
});
|
|
186
168
|
}
|
|
187
|
-
};
|
|
169
|
+
};
|
|
170
|
+
export { insertRow, removeRow, removeTable, insertColumn, removeColumn, changeCellAlign };
|
|
@@ -1,44 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.toggleTextStyle = exports.removeMark = exports.isMenuDisabled = exports.isMarkActive = exports.addMark = void 0;
|
|
8
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
|
|
9
|
-
var _slate = require("slate");
|
|
10
|
-
var _helpers = require("../code-block/helpers");
|
|
11
|
-
var isMenuDisabled = exports.isMenuDisabled = function isMenuDisabled(editor, isReadonly) {
|
|
1
|
+
import { Editor } from 'slate';
|
|
2
|
+
import { isInCodeBlock } from '../code-block/helpers';
|
|
3
|
+
export const isMenuDisabled = (editor, isReadonly) => {
|
|
12
4
|
if (isReadonly) return true;
|
|
13
|
-
|
|
5
|
+
const {
|
|
6
|
+
selection
|
|
7
|
+
} = editor;
|
|
14
8
|
if (!selection) return true;
|
|
15
|
-
if (
|
|
9
|
+
if (isInCodeBlock(editor)) return true;
|
|
16
10
|
return false;
|
|
17
11
|
};
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
export const isMarkActive = (editor, mark) => {
|
|
13
|
+
const marks = Editor.marks(editor);
|
|
20
14
|
|
|
21
15
|
// If curMarks exists, you need to set this parameter manually. curMarks prevails
|
|
22
16
|
if (marks && Object.keys(marks).length > 0) {
|
|
23
17
|
return !!marks[mark];
|
|
24
18
|
} else {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
}),
|
|
30
|
-
_Editor$nodes2 = (0, _slicedToArray2.default)(_Editor$nodes, 1),
|
|
31
|
-
match = _Editor$nodes2[0];
|
|
19
|
+
const [match] = Editor.nodes(editor, {
|
|
20
|
+
match: n => n[mark] === true
|
|
21
|
+
});
|
|
32
22
|
return !!match;
|
|
33
23
|
}
|
|
34
24
|
};
|
|
35
|
-
|
|
36
|
-
|
|
25
|
+
export const addMark = (editor, type) => {
|
|
26
|
+
Editor.addMark(editor, type, true);
|
|
37
27
|
};
|
|
38
|
-
|
|
39
|
-
|
|
28
|
+
export const removeMark = (editor, type) => {
|
|
29
|
+
Editor.removeMark(editor, type);
|
|
40
30
|
};
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
export const toggleTextStyle = (editor, type) => {
|
|
32
|
+
const isActive = isMarkActive(editor, type);
|
|
43
33
|
isActive ? removeMark(editor, type) : addMark(editor, type);
|
|
44
34
|
};
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _menu = _interopRequireDefault(require("./menu"));
|
|
9
|
-
var _plugin = _interopRequireDefault(require("./plugin"));
|
|
10
|
-
var _renderElem = _interopRequireDefault(require("./render-elem"));
|
|
11
|
-
var TextPlugin = {
|
|
1
|
+
import TextStyleMenu from './menu';
|
|
2
|
+
import withTextStyle from './plugin';
|
|
3
|
+
import renderText from './render-elem';
|
|
4
|
+
const TextPlugin = {
|
|
12
5
|
type: 'text',
|
|
13
|
-
editorMenus: [
|
|
14
|
-
editorPlugin:
|
|
15
|
-
renderElements: [
|
|
6
|
+
editorMenus: [TextStyleMenu],
|
|
7
|
+
editorPlugin: withTextStyle,
|
|
8
|
+
renderElements: [renderText]
|
|
16
9
|
};
|
|
17
|
-
|
|
10
|
+
export default TextPlugin;
|