@seafile/sdoc-editor 0.1.83 → 0.1.85

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.
Files changed (32) hide show
  1. package/dist/basic-sdk/comment/color-menu/color-item.js +22 -0
  2. package/dist/basic-sdk/comment/color-menu/index.css +109 -0
  3. package/dist/basic-sdk/comment/color-menu/index.js +199 -0
  4. package/dist/basic-sdk/constants/index.js +1 -0
  5. package/dist/basic-sdk/editor.js +3 -1
  6. package/dist/basic-sdk/extension/constants/color.js +265 -0
  7. package/dist/basic-sdk/extension/constants/index.js +9 -2
  8. package/dist/basic-sdk/extension/plugins/header/plugin.js +2 -1
  9. package/dist/basic-sdk/extension/plugins/table/helpers.js +386 -49
  10. package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/common-menu.js +4 -0
  11. package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/index.js +40 -13
  12. package/dist/basic-sdk/extension/plugins/table/plugin.js +138 -214
  13. package/dist/basic-sdk/extension/plugins/table/render/index.js +38 -8
  14. package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +16 -7
  15. package/dist/basic-sdk/extension/plugins/table/render/table-header/rows-header/row-header.js +2 -2
  16. package/dist/basic-sdk/node-id/helpers.js +18 -0
  17. package/dist/basic-sdk/node-id/index.js +3 -3
  18. package/dist/basic-sdk/utils/event-handler.js +5 -1
  19. package/dist/basic-sdk/utils/object-utils.js +3 -0
  20. package/dist/components/doc-operations/revision-operations/more-revision-operations/index.js +1 -1
  21. package/dist/constants/index.js +2 -1
  22. package/dist/utils/index.js +2 -1
  23. package/dist/utils/local-storage-utils.js +49 -0
  24. package/package.json +2 -1
  25. package/public/locales/en/sdoc-editor.json +44 -1
  26. package/public/locales/zh-CN/sdoc-editor.json +44 -1
  27. package/public/media/sdoc-editor-font/iconfont.eot +0 -0
  28. package/public/media/sdoc-editor-font/iconfont.svg +4 -0
  29. package/public/media/sdoc-editor-font/iconfont.ttf +0 -0
  30. package/public/media/sdoc-editor-font/iconfont.woff +0 -0
  31. package/public/media/sdoc-editor-font/iconfont.woff2 +0 -0
  32. package/public/media/sdoc-editor-font.css +14 -6
@@ -1,174 +1,16 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
- import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
4
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
5
4
  import isHotkey from 'is-hotkey';
6
- import { Editor, Transforms, Point, Path, Node } from '@seafile/slate';
7
- import { ReactEditor } from '@seafile/slate-react';
8
- import { getNodeType, getParentNode, getSelectedNodeByType, isTextNode, isLastNode, replaceNodeChildren, focusEditor, getNode, generateEmptyElement } from '../../core';
5
+ import { Editor, Transforms, Path } from '@seafile/slate';
6
+ import { getNodeType, getParentNode, getSelectedNodeByType, isLastNode, generateEmptyElement } from '../../core';
9
7
  import { ELEMENT_TYPE, KEYBOARD, PARAGRAPH } from '../../constants';
10
8
  import { TABLE_MAX_ROWS, EMPTY_SELECTED_RANGE, TABLE_ELEMENT, TABLE_ELEMENT_POSITION } from './constants';
11
9
  import ObjectUtils from '../../../utils/object-utils';
12
- import { getSelectedInfo, insertTableElement } from './helpers';
13
- var deleteHandler = function deleteHandler(editor) {
14
- var selection = editor.selection,
15
- tableSelectedRange = editor.tableSelectedRange;
16
- if (selection == null) return '';
17
- if (!ObjectUtils.isSameObject(tableSelectedRange, EMPTY_SELECTED_RANGE)) {
18
- return 'range';
19
- }
20
- var _Editor$nodes = Editor.nodes(editor, {
21
- match: function match(n) {
22
- var type = getNodeType(n);
23
- if (!type && isTextNode(n) && n.id) {
24
- var parentNode = getParentNode(editor.children, n.id);
25
- type = getNodeType(parentNode);
26
- }
27
- return type === ELEMENT_TYPE.TABLE_CELL;
28
- }
29
- }),
30
- _Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
31
- cellNodeEntry = _Editor$nodes2[0];
32
- if (cellNodeEntry) {
33
- var _cellNodeEntry = _slicedToArray(cellNodeEntry, 2),
34
- cellPath = _cellNodeEntry[1];
35
- var start = Editor.start(editor, cellPath);
36
- if (Point.equals(selection.anchor, start)) {
37
- return 'default';
38
- }
39
- }
40
- return '';
41
- };
42
- var isTableLocation = function isTableLocation(editor, location) {
43
- var tables = Editor.nodes(editor, {
44
- at: location,
45
- match: function match(n) {
46
- var type = getNodeType(n);
47
- if (!type && isTextNode(n) && n.id) {
48
- var parentNode = getParentNode(editor.children, n.id);
49
- type = getNodeType(parentNode);
50
- }
51
- return type === ELEMENT_TYPE.TABLE_CELL;
52
- }
53
- });
54
- var hasTable = false;
55
- // eslint-disable-next-line no-unused-vars
56
- var _iterator = _createForOfIteratorHelper(tables),
57
- _step;
58
- try {
59
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
60
- var table = _step.value;
61
- hasTable = true;
62
- }
63
- } catch (err) {
64
- _iterator.e(err);
65
- } finally {
66
- _iterator.f();
67
- }
68
- return hasTable;
69
- };
70
- var isCursorAtCellEnd = function isCursorAtCellEnd(cell) {
71
- var cursor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
72
- if (!cell) return false;
73
- var childrenCount = cell.children.length;
74
- var lastChildren = cell.children[childrenCount - 1];
75
- var textCount = lastChildren.text.length;
76
- return cursor === textCount;
77
- };
78
- var isCursorAtCellStart = function isCursorAtCellStart() {
79
- var cursor = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
80
- return cursor === 0;
81
- };
82
- var focusCell = function focusCell(editor, event) {
83
- var keyboardName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
84
- var _getSelectedInfo = getSelectedInfo(editor),
85
- tableSize = _getSelectedInfo.tableSize,
86
- tablePath = _getSelectedInfo.tablePath,
87
- rowIndex = _getSelectedInfo.rowIndex,
88
- cellIndex = _getSelectedInfo.cellIndex,
89
- cell = _getSelectedInfo.cell;
90
- var tableIndex = tablePath[0];
91
- var selection = editor.selection;
92
- var focus = selection.focus;
93
- if (keyboardName === KEYBOARD.UP) {
94
- if (!isCursorAtCellStart(focus.offset)) return;
95
- event.preventDefault();
96
- if (rowIndex === 0) {
97
- if (tableIndex !== 0) {
98
- focusEditor(editor, [tableIndex - 1]);
99
- }
100
- return;
101
- }
102
- focusEditor(editor, [tableIndex, rowIndex - 1, cellIndex]);
103
- var newFocus = editor.selection.focus;
104
- Transforms.select(editor, {
105
- focus: newFocus,
106
- anchor: newFocus
107
- });
108
- }
109
- if (keyboardName === KEYBOARD.RIGHT) {
110
- if (!isCursorAtCellEnd(cell, focus.offset)) return;
111
- event.preventDefault();
112
- if (rowIndex === tableSize[0] - 1 && cellIndex === tableSize[1] - 1) {
113
- focusEditor(editor, [tableIndex + 1]);
114
- return;
115
- }
116
- if (cellIndex === tableSize[1] - 1) {
117
- focusEditor(editor, [tableIndex, rowIndex + 1, 0]);
118
- } else {
119
- focusEditor(editor, [tableIndex, rowIndex, cellIndex + 1]);
120
- }
121
- var newAnchor = editor.selection.anchor;
122
- Transforms.select(editor, {
123
- focus: newAnchor,
124
- anchor: newAnchor
125
- });
126
- }
127
- if (keyboardName === KEYBOARD.DOWN) {
128
- if (!isCursorAtCellEnd(cell, focus.offset)) return;
129
- event.preventDefault();
130
- if (rowIndex === tableSize[0] - 1) {
131
- focusEditor(editor, [tableIndex + 1]);
132
- return;
133
- }
134
- focusEditor(editor, [tableIndex, rowIndex + 1, cellIndex]);
135
- var _newAnchor = editor.selection.anchor;
136
- Transforms.select(editor, {
137
- focus: _newAnchor,
138
- anchor: _newAnchor
139
- });
140
- }
141
- if (keyboardName === KEYBOARD.LEFT) {
142
- if (!isCursorAtCellStart(focus.offset)) return;
143
- event.preventDefault();
144
- if (rowIndex === 0 && cellIndex === 0) {
145
- if (tableIndex !== 0) {
146
- focusEditor(editor, [tableIndex - 1]);
147
- }
148
- return;
149
- }
150
- if (cellIndex === 0) {
151
- focusEditor(editor, [tableIndex, rowIndex - 1, tableSize[1] - 1]);
152
- } else {
153
- focusEditor(editor, [tableIndex, rowIndex, cellIndex - 1]);
154
- }
155
- var _newFocus = editor.selection.focus;
156
- Transforms.select(editor, {
157
- focus: _newFocus,
158
- anchor: _newFocus
159
- });
160
- }
161
- };
162
- var isLastTableCell = function isLastTableCell(editor, cellNode) {
163
- if (cellNode[0].type !== ELEMENT_TYPE.TABLE_CELL) return false;
164
- var _getSelectedInfo2 = getSelectedInfo(editor),
165
- tableSize = _getSelectedInfo2.tableSize;
166
- var lastRowIndex = tableSize[0] - 1;
167
- var lastColumnIndex = tableSize[1] - 1;
168
- var cellNodePath = cellNode[1];
169
- var cellNodePathDeep = cellNodePath.length;
170
- return cellNodePath[cellNodePathDeep - 1] === lastColumnIndex && cellNodePath[cellNodePathDeep - 2] === lastRowIndex;
171
- };
10
+ import { getSelectedInfo, insertTableElement, removeTable, insertMultipleRowsAndColumns, setTableFragmentData, deleteTableRangeData, focusCell, deleteHandler, isTableLocation, isLastTableCell } from './helpers';
11
+ import EventBus from '../../../utils/event-bus';
12
+ import { EXTERNAL_EVENT } from '../../../../constants';
13
+ import { CLIPBOARD_FORMAT_KEY } from '../../../constants';
172
14
  var withTable = function withTable(editor) {
173
15
  var insertBreak = editor.insertBreak,
174
16
  deleteBackward = editor.deleteBackward,
@@ -176,15 +18,29 @@ var withTable = function withTable(editor) {
176
18
  insertData = editor.insertData,
177
19
  selectAll = editor.selectAll,
178
20
  normalizeNode = editor.normalizeNode,
179
- handleTab = editor.handleTab;
21
+ handleTab = editor.handleTab,
22
+ getFragment = editor.getFragment,
23
+ setFragmentData = editor.setFragmentData,
24
+ insertFragment = editor.insertFragment;
180
25
  var newEditor = editor;
181
26
  newEditor.tableSelectedRange = EMPTY_SELECTED_RANGE;
27
+ var eventBus = EventBus.getInstance();
182
28
  newEditor.tableOnKeyDown = function (event) {
183
29
  // Handle special keyboard events
184
30
 
185
31
  if (isHotkey('mod+a', event)) {
186
32
  event.preventDefault();
187
- newEditor.selectAll();
33
+ var _getSelectedInfo = getSelectedInfo(newEditor),
34
+ table = _getSelectedInfo.table,
35
+ tableSize = _getSelectedInfo.tableSize;
36
+ var allTableRange = {
37
+ minRowIndex: 0,
38
+ maxRowIndex: tableSize[0] - 1,
39
+ minColIndex: 0,
40
+ maxColIndex: tableSize[1] - 1
41
+ };
42
+ newEditor.tableSelectedRange = allTableRange;
43
+ eventBus.dispatch(EXTERNAL_EVENT.SET_TABLE_SELECT_RANGE, table, allTableRange);
188
44
  }
189
45
  if (isHotkey(KEYBOARD.UP, event)) {
190
46
  event.preventDefault();
@@ -213,34 +69,16 @@ var withTable = function withTable(editor) {
213
69
  };
214
70
  newEditor.deleteBackward = function (unit) {
215
71
  var deleteType = deleteHandler(newEditor);
72
+ if (deleteType === 'table') {
73
+ var _getSelectedInfo2 = getSelectedInfo(editor),
74
+ tablePath = _getSelectedInfo2.tablePath;
75
+ removeTable(editor, tablePath);
76
+ return;
77
+ }
216
78
 
217
79
  // range selection delete
218
80
  if (deleteType === 'range') {
219
- var tableSelectedRange = newEditor.tableSelectedRange;
220
- var minRowIndex = tableSelectedRange.minRowIndex,
221
- maxRowIndex = tableSelectedRange.maxRowIndex,
222
- minColIndex = tableSelectedRange.minColIndex,
223
- maxColIndex = tableSelectedRange.maxColIndex;
224
- var _getSelectedInfo3 = getSelectedInfo(newEditor),
225
- tablePath = _getSelectedInfo3.tablePath;
226
- for (var i = minRowIndex; i <= maxRowIndex; i++) {
227
- for (var j = minColIndex; j <= maxColIndex; j++) {
228
- var path = [].concat(_toConsumableArray(tablePath), [i, j]);
229
- var node = getNode(newEditor, path);
230
- var firstNode = node.children[0];
231
- for (var m = 1; m < node.children.length; m++) {
232
- Transforms.removeNodes(editor, {
233
- at: [].concat(_toConsumableArray(path), [m])
234
- });
235
- }
236
- replaceNodeChildren(newEditor, {
237
- at: path,
238
- nodes: _objectSpread(_objectSpread({}, firstNode), {}, {
239
- text: ''
240
- })
241
- });
242
- }
243
- }
81
+ deleteTableRangeData(newEditor);
244
82
  return;
245
83
  }
246
84
  if (deleteType === 'default') return;
@@ -264,6 +102,78 @@ var withTable = function withTable(editor) {
264
102
  if (newNodeParent.type === ELEMENT_TYPE.TABLE_CELL) return;
265
103
  deleteForward(unit);
266
104
  };
105
+ newEditor.getFragment = function () {
106
+ var selectedNode = getSelectedNodeByType(newEditor, ELEMENT_TYPE.TABLE);
107
+ if (!selectedNode) {
108
+ return getFragment();
109
+ }
110
+ var tableSelectedRange = newEditor.tableSelectedRange;
111
+ if (ObjectUtils.isSameObject(tableSelectedRange, EMPTY_SELECTED_RANGE)) {
112
+ return getFragment();
113
+ }
114
+ var minColIndex = tableSelectedRange.minColIndex,
115
+ maxColIndex = tableSelectedRange.maxColIndex,
116
+ minRowIndex = tableSelectedRange.minRowIndex,
117
+ maxRowIndex = tableSelectedRange.maxRowIndex;
118
+ var rows = selectedNode.children;
119
+ var columns = selectedNode.columns;
120
+ var selectedRows = [];
121
+ var selectedColumns = [];
122
+ for (var i = minRowIndex; i <= maxRowIndex; i++) {
123
+ var row = rows[i];
124
+ var rowChildren = row.children;
125
+ var newRowChildren = [];
126
+ for (var j = minColIndex; j <= maxColIndex; j++) {
127
+ var column = rowChildren[j];
128
+ newRowChildren.push(column);
129
+ }
130
+ selectedRows.push(_objectSpread(_objectSpread({}, row), {}, {
131
+ children: newRowChildren
132
+ }));
133
+ }
134
+ for (var _j = minColIndex; _j <= maxColIndex; _j++) {
135
+ var _column = columns[_j];
136
+ selectedColumns.push(_column);
137
+ }
138
+ return _objectSpread(_objectSpread({}, selectedNode), {}, {
139
+ children: selectedRows,
140
+ columns: selectedColumns
141
+ });
142
+ };
143
+
144
+ // copy: mod + c
145
+ newEditor.setFragmentData = function (dataTransfer) {
146
+ var selectedNode = getSelectedNodeByType(newEditor, ELEMENT_TYPE.TABLE);
147
+ if (!selectedNode) {
148
+ return setFragmentData(dataTransfer);
149
+ }
150
+ var tableSelectedRange = newEditor.tableSelectedRange;
151
+ if (ObjectUtils.isSameObject(tableSelectedRange, EMPTY_SELECTED_RANGE)) {
152
+ return setFragmentData(dataTransfer);
153
+ }
154
+ return setTableFragmentData(newEditor, dataTransfer);
155
+ };
156
+ newEditor.cut = function (event) {
157
+ var selectedNode = getSelectedNodeByType(newEditor, ELEMENT_TYPE.TABLE);
158
+ var tableSelectedRange = newEditor.tableSelectedRange;
159
+ if (selectedNode && !ObjectUtils.isSameObject(tableSelectedRange, EMPTY_SELECTED_RANGE)) {
160
+ setTableFragmentData(newEditor, event.clipboardData);
161
+ var deleteType = deleteHandler(newEditor);
162
+ if (deleteType === 'table') {
163
+ var _getSelectedInfo3 = getSelectedInfo(editor),
164
+ tablePath = _getSelectedInfo3.tablePath;
165
+ removeTable(editor, tablePath);
166
+ return;
167
+ }
168
+
169
+ // range selection delete
170
+ if (deleteType === 'range') {
171
+ deleteTableRangeData(newEditor);
172
+ return;
173
+ }
174
+ return;
175
+ }
176
+ };
267
177
 
268
178
  // copy insert text
269
179
  newEditor.insertData = function (data) {
@@ -272,10 +182,26 @@ var withTable = function withTable(editor) {
272
182
  insertData(data);
273
183
  return;
274
184
  }
185
+ var fragment = data.getData("application/".concat(CLIPBOARD_FORMAT_KEY));
186
+ if (fragment) {
187
+ var decoded = decodeURIComponent(window.atob(fragment));
188
+ var parsedData = JSON.parse(decoded);
189
+ if (ObjectUtils.isObject(parsedData) && parsedData.type === ELEMENT_TYPE.TABLE) {
190
+ insertMultipleRowsAndColumns(newEditor, parsedData.children, parsedData.columns);
191
+ return;
192
+ }
193
+ }
275
194
  var text = data.getData('text/plain');
276
195
  if (!text) return;
277
196
  Editor.insertText(newEditor, text);
278
197
  };
198
+ newEditor.insertFragment = function (data) {
199
+ if (data.type === ELEMENT_TYPE.TABLE) {
200
+ Transforms.insertNodes(editor, data);
201
+ return;
202
+ }
203
+ return insertFragment(data);
204
+ };
279
205
  newEditor.selectAll = function () {
280
206
  var selection = newEditor.selection;
281
207
  if (!selection) {
@@ -293,20 +219,15 @@ var withTable = function withTable(editor) {
293
219
  selectAll();
294
220
  return;
295
221
  }
296
- var text = Node.string(selectedCell);
297
- var textLength = text.length;
298
- if (textLength === 0) {
299
- selectAll();
300
- return;
301
- }
302
- var path = ReactEditor.findPath(newEditor, selectedCell);
303
- var start = Editor.start(newEditor, path);
304
- var end = Editor.end(newEditor, path);
305
- var newSelection = {
306
- anchor: start,
307
- focus: end
308
- };
309
- Transforms.select(newEditor, newSelection);
222
+ var _getSelectedInfo4 = getSelectedInfo(newEditor),
223
+ table = _getSelectedInfo4.table,
224
+ tableSize = _getSelectedInfo4.tableSize;
225
+ eventBus.dispatch(EXTERNAL_EVENT.SET_TABLE_SELECT_RANGE, table, {
226
+ minRowIndex: 0,
227
+ maxRowIndex: tableSize[0] - 1,
228
+ minColIndex: 0,
229
+ maxColIndex: tableSize[1] - 1
230
+ });
310
231
  };
311
232
 
312
233
  // Rewrite normalizeNode
@@ -348,9 +269,9 @@ var withTable = function withTable(editor) {
348
269
 
349
270
  // Add row to the last cell
350
271
  if (isLastTableCell(newEditor, above)) {
351
- var _getSelectedInfo4 = getSelectedInfo(newEditor),
352
- tablePath = _getSelectedInfo4.tablePath,
353
- tableSize = _getSelectedInfo4.tableSize;
272
+ var _getSelectedInfo5 = getSelectedInfo(newEditor),
273
+ tablePath = _getSelectedInfo5.tablePath,
274
+ tableSize = _getSelectedInfo5.tableSize;
354
275
  if (tableSize[0] === TABLE_MAX_ROWS) return;
355
276
  insertTableElement(newEditor, TABLE_ELEMENT.ROW, TABLE_ELEMENT_POSITION.AFTER);
356
277
  Transforms.select(newEditor, [].concat(_toConsumableArray(tablePath), [tableSize[0], 0]));
@@ -361,11 +282,11 @@ var withTable = function withTable(editor) {
361
282
  // The default behavior, the cursor is in the middle of the text, and the current text content is selected
362
283
  // Change to jump to next cell
363
284
  if (selection.anchor.offset === selection.focus.offset) {
364
- var _getSelectedInfo5 = getSelectedInfo(newEditor),
365
- _tableSize = _getSelectedInfo5.tableSize,
366
- _tablePath = _getSelectedInfo5.tablePath,
367
- rowIndex = _getSelectedInfo5.rowIndex,
368
- cellIndex = _getSelectedInfo5.cellIndex;
285
+ var _getSelectedInfo6 = getSelectedInfo(newEditor),
286
+ _tableSize = _getSelectedInfo6.tableSize,
287
+ _tablePath = _getSelectedInfo6.tablePath,
288
+ rowIndex = _getSelectedInfo6.rowIndex,
289
+ cellIndex = _getSelectedInfo6.cellIndex;
369
290
  var lastColumnIndex = _tableSize[1] - 1;
370
291
  var nextCell = [rowIndex, cellIndex + 1];
371
292
  if (lastColumnIndex < nextCell[1]) {
@@ -377,6 +298,9 @@ var withTable = function withTable(editor) {
377
298
  var next = Editor.next(newEditor);
378
299
  Transforms.select(newEditor, next[1]);
379
300
  };
301
+ newEditor.reSetTableSelectedRange = function () {
302
+ newEditor.tableSelectedRange = EMPTY_SELECTED_RANGE;
303
+ };
380
304
  return newEditor;
381
305
  };
382
306
  export default withTable;
@@ -1,8 +1,10 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
1
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
3
  import React, { useRef, useState, useEffect, useCallback } from 'react';
3
4
  import classnames from 'classnames';
4
5
  import throttle from 'lodash.throttle';
5
6
  import { useSelected, useSlateStatic, useReadOnly } from '@seafile/slate-react';
7
+ import { Transforms, Editor } from '@seafile/slate';
6
8
  import { EMPTY_SELECTED_RANGE } from '../constants';
7
9
  import { ResizeHandlersContext, TableSelectedRangeContext, SettingSelectRangeContext } from './hooks';
8
10
  import EventBus from '../../../../utils/event-bus';
@@ -13,6 +15,7 @@ import ResizeHandlers from './resize-handlers';
13
15
  import { registerResizeEvents, unregisterResizeEvents } from '../../../../utils/mouse-event';
14
16
  import TableRoot from './table-root';
15
17
  import TableHeader from './table-header';
18
+ import { findPath } from '../../../core';
16
19
  import './index.css';
17
20
  var Table = function Table(_ref) {
18
21
  var className = _ref.className,
@@ -43,6 +46,7 @@ var Table = function Table(_ref) {
43
46
  _useState10 = _slicedToArray(_useState9, 2),
44
47
  columns = _useState10[0],
45
48
  setColumns = _useState10[1];
49
+ var path = findPath(editor, element);
46
50
  var onMouseDown = useCallback(function (event) {
47
51
  if (event.button !== 0) return; // right click not deal
48
52
  setIsSettingSelectRange(true);
@@ -61,10 +65,21 @@ var Table = function Table(_ref) {
61
65
 
62
66
  // eslint-disable-next-line react-hooks/exhaustive-deps
63
67
  }, []);
68
+ useEffect(function () {
69
+ if (isSelected) {
70
+ var eventBus = EventBus.getInstance();
71
+ var cancelTableSelectRangeSubscribe = eventBus.subscribe(EXTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE, clearRange);
72
+ var setTableSelectRangeSubscribe = eventBus.subscribe(EXTERNAL_EVENT.SET_TABLE_SELECT_RANGE, setRange);
73
+ return function () {
74
+ cancelTableSelectRangeSubscribe();
75
+ setTableSelectRangeSubscribe();
76
+ };
77
+ }
78
+
79
+ // eslint-disable-next-line react-hooks/exhaustive-deps
80
+ }, [isSelected]);
64
81
  useEffect(function () {
65
82
  setColumns(getTableColumns(editor, element));
66
- var eventBus = EventBus.getInstance();
67
- var cancelTableSelectRangeSubscribe = eventBus.subscribe(EXTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE, clearRange);
68
83
  if (isSettingSelectRange) {
69
84
  var onMouseMove = throttle(function (event) {
70
85
  // if event.target not in the table, clear the mouseMove event
@@ -79,7 +94,17 @@ var Table = function Table(_ref) {
79
94
  maxColIndex: Math.max(startColIndex, endColIndex)
80
95
  };
81
96
  if (!ObjectUtils.isSameObject(selectedRange, EMPTY_SELECTED_RANGE)) {
82
- window.getSelection().collapseToEnd();
97
+ event.preventDefault();
98
+ Editor.withoutNormalizing(editor, function () {
99
+ var selection = {
100
+ offset: 0,
101
+ path: [].concat(_toConsumableArray(path), [endRowIndex, endColIndex, 0])
102
+ };
103
+ Transforms.setSelection(editor, {
104
+ anchor: selection,
105
+ focus: selection
106
+ });
107
+ });
83
108
  }
84
109
 
85
110
  // same cell
@@ -100,20 +125,25 @@ var Table = function Table(_ref) {
100
125
  'mouseup': onMouseUp
101
126
  });
102
127
  return function () {
103
- cancelTableSelectRangeSubscribe();
104
128
  unregisterResizeEvents({
105
129
  'mousemove': onMouseMove,
106
130
  'mouseup': onMouseUp
107
131
  });
108
132
  };
109
133
  }
110
- return function () {
111
- cancelTableSelectRangeSubscribe();
112
- setTableSelectedRange(editor, selectedRange);
113
- };
114
134
 
115
135
  // eslint-disable-next-line react-hooks/exhaustive-deps
116
136
  }, [element, isSettingSelectRange, selectedRange, element]);
137
+ var setRange = useCallback(function (table, range) {
138
+ if (element.id !== table.id) {
139
+ setSelectedRange(EMPTY_SELECTED_RANGE);
140
+ } else {
141
+ setSelectedRange(range);
142
+ }
143
+ setTableSelectedRange(editor, range);
144
+
145
+ // eslint-disable-next-line react-hooks/exhaustive-deps
146
+ }, [element]);
117
147
  var clearRange = useCallback(function () {
118
148
  setSelectedRange(EMPTY_SELECTED_RANGE);
119
149
 
@@ -7,7 +7,7 @@ import { STYLE_KEY } from '../../../constants';
7
7
  import { findPath } from '../../../core';
8
8
  import { useResizeHandlersContext, useTableSelectedRangeContext } from './hooks';
9
9
  import { EMPTY_SELECTED_RANGE } from '../constants';
10
- import { getTableColumns, getCellColumn } from '../helpers';
10
+ import { getTableColumns, getCellColumn, colorBlend } from '../helpers';
11
11
  var TableCell = function TableCell(_ref) {
12
12
  var attributes = _ref.attributes,
13
13
  element = _ref.element,
@@ -21,10 +21,6 @@ var TableCell = function TableCell(_ref) {
21
21
  var cellIndex = cellPath[pathLength - 1];
22
22
  var column = columns ? columns[cellIndex] : {};
23
23
  var columnWidth = (column === null || column === void 0 ? void 0 : column.width) || 0;
24
- var style = attributes.style || {};
25
- if (ObjectUtils.hasProperty(element.style, STYLE_KEY.TEXT_ALIGN)) {
26
- style[STYLE_KEY.TEXT_ALIGN] = element.style[STYLE_KEY.TEXT_ALIGN];
27
- }
28
24
  var minColIndex = selectedRange.minColIndex,
29
25
  maxColIndex = selectedRange.maxColIndex,
30
26
  minRowIndex = selectedRange.minRowIndex,
@@ -35,8 +31,18 @@ var TableCell = function TableCell(_ref) {
35
31
  var isSelectedLastCell = isSelected && cellIndex === maxColIndex;
36
32
  var isSelectedFirstRow = isSelected && rowIndex === minRowIndex;
37
33
  var isSelectedLastRow = isSelected && rowIndex === maxRowIndex;
34
+ var style = attributes.style || {};
35
+ if (ObjectUtils.hasProperty(element.style, STYLE_KEY.TEXT_ALIGN)) {
36
+ style[STYLE_KEY.TEXT_ALIGN] = element.style[STYLE_KEY.TEXT_ALIGN];
37
+ }
38
+ if (ObjectUtils.hasProperty(element.style, STYLE_KEY.BG_COLOR)) {
39
+ var color = element.style[STYLE_KEY.BG_COLOR];
40
+ if (color && (color !== 'transparent' || color !== 'unset')) {
41
+ style['backgroundColor'] = isSelected ? colorBlend('#fff4e6', color, 0.9) : color;
42
+ }
43
+ }
38
44
  return /*#__PURE__*/React.createElement("div", Object.assign({}, attributes, {
39
- style: _objectSpread(_objectSpread(_objectSpread({}, style), element.style), {}, {
45
+ style: _objectSpread(_objectSpread(_objectSpread({}, element.style), style), {}, {
40
46
  minWidth: columnWidth,
41
47
  width: columnWidth
42
48
  }),
@@ -70,10 +76,13 @@ function renderTableCell(props) {
70
76
  if (ObjectUtils.hasProperty(element, STYLE_KEY.TEXT_ALIGN)) {
71
77
  style[STYLE_KEY.TEXT_ALIGN] = element[STYLE_KEY.TEXT_ALIGN];
72
78
  }
79
+ if (ObjectUtils.hasProperty(element.style, STYLE_KEY.BG_COLOR)) {
80
+ style['backgroundColor'] = element.style[STYLE_KEY.BG_COLOR];
81
+ }
73
82
  var column = getCellColumn(editor, element);
74
83
  var width = column.width;
75
84
  return /*#__PURE__*/React.createElement("div", Object.assign({}, attributes, {
76
- style: _objectSpread(_objectSpread(_objectSpread({}, style), element.style), {}, {
85
+ style: _objectSpread(_objectSpread(_objectSpread({}, element.style), style), {}, {
77
86
  minWidth: width,
78
87
  width: width
79
88
  }),
@@ -8,7 +8,7 @@ import { useResizeHandlersContext, useTableSelectedRangeContext } from '../../ho
8
8
  import { useScrollContext } from '../../../../../../hooks/use-scroll-context';
9
9
  import { ELEMENT_TYPE } from '../../../../../constants';
10
10
  import { findPath, getSelectedNodeByType } from '../../../../../core';
11
- import { rowElementHasImage } from '../../../helpers';
11
+ import { elementHasImage } from '../../../helpers';
12
12
  var RowHeader = function RowHeader(_ref) {
13
13
  var _row$style;
14
14
  var row = _ref.row,
@@ -31,7 +31,7 @@ var RowHeader = function RowHeader(_ref) {
31
31
  var currentCellPath = currentCell ? findPath(editor, currentCell, [-1, -1]) : [-1, -1];
32
32
  var pathLength = currentCellPath.length;
33
33
  useEffect(function () {
34
- if (rowElementHasImage(row)) {
34
+ if (elementHasImage(row)) {
35
35
  var time = setTimeout(function () {
36
36
  // There is a delay in image loading
37
37
  var rowDom = ReactEditor.toDOMNode(editor, row);
@@ -1,7 +1,9 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
1
2
  import { Node } from '@seafile/slate';
2
3
  import deepCopy from 'deep-copy';
3
4
  import slugid from 'slugid';
4
5
  import * as OPERATION from './constants';
6
+ import ObjectUtils from '../utils/object-utils';
5
7
  export var decorateOperation = function decorateOperation(editor, operation) {
6
8
  var newOperation = deepCopy(operation);
7
9
  var type = newOperation.type;
@@ -75,8 +77,24 @@ export var decorateOperation = function decorateOperation(editor, operation) {
75
77
  }
76
78
  return newOperation;
77
79
  };
80
+ export var replaceNodeId = function replaceNodeId(node) {
81
+ if (!ObjectUtils.isObject(node)) return node;
82
+ if (ObjectUtils.hasProperty(node, 'children')) {
83
+ return _objectSpread(_objectSpread({}, node), {}, {
84
+ id: slugid.nice(),
85
+ children: replacePastedDataId(node.children)
86
+ });
87
+ }
88
+ return _objectSpread(_objectSpread({}, node), {}, {
89
+ id: slugid.nice()
90
+ });
91
+ };
78
92
  export var replacePastedDataId = function replacePastedDataId(pastedData) {
79
93
  // If children is malformed, return a list of correct child nodes
94
+
95
+ if (ObjectUtils.isObject(pastedData)) {
96
+ return replaceNodeId(pastedData);
97
+ }
80
98
  if (!Array.isArray(pastedData)) return [{
81
99
  id: slugid.nice(),
82
100
  text: ''
@@ -1,6 +1,6 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import { decorateOperation, replacePastedDataId } from './helpers';
3
- var clipboardFormatKey = 'x-slate-fragment';
3
+ import { CLIPBOARD_FORMAT_KEY } from '../constants';
4
4
  var catchSlateFragment = /data-slate-fragment="(.+?)"/m;
5
5
  var getSlateFragmentAttribute = function getSlateFragmentAttribute(dataTransfer) {
6
6
  var htmlData = dataTransfer.getData('text/html');
@@ -19,13 +19,13 @@ var withNodeId = function withNodeId(editor) {
19
19
 
20
20
  // rewrite insert fragment data
21
21
  newEditor.insertFragmentData = function (data) {
22
- var fragment = data.getData("application/".concat(clipboardFormatKey)) || getSlateFragmentAttribute(data);
22
+ var fragment = data.getData("application/".concat(CLIPBOARD_FORMAT_KEY)) || getSlateFragmentAttribute(data);
23
23
  if (fragment) {
24
24
  var decoded = decodeURIComponent(window.atob(fragment));
25
25
  var parsed = JSON.parse(decoded);
26
26
  var newData = replacePastedDataId(parsed);
27
27
  newEditor.insertFragment(newData);
28
- return true;
28
+ return newEditor;
29
29
  }
30
30
  };
31
31
  return newEditor;
@@ -62,7 +62,11 @@ var EventProxy = /*#__PURE__*/_createClass(function EventProxy(_editor) {
62
62
  event.nativeEvent.stopImmediatePropagation();
63
63
  // 处理数据
64
64
  };
65
- this.onCut = function (event) {};
65
+ this.onCut = function (event) {
66
+ if (_this.editor.cut) {
67
+ _this.editor.cut(event);
68
+ }
69
+ };
66
70
  this.onPaste = function (event) {};
67
71
  this.editor = _editor;
68
72
  });
@@ -54,6 +54,9 @@ var ObjectUtils = /*#__PURE__*/function () {
54
54
  }]);
55
55
  return ObjectUtils;
56
56
  }();
57
+ ObjectUtils.isObject = function (data) {
58
+ return ObjectUtils.getDataType(data) === 'Object';
59
+ };
57
60
  ObjectUtils.hasProperty = function (obj, prop) {
58
61
  if (!obj) return false;
59
62
  return Object.prototype.hasOwnProperty.call(obj, prop);