@seafile/seafile-editor 0.3.78 → 0.3.82

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.
@@ -0,0 +1,58 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
+ import React from 'react';
6
+
7
+ var ClickOutside = /*#__PURE__*/function (_React$Component) {
8
+ _inherits(ClickOutside, _React$Component);
9
+
10
+ var _super = _createSuper(ClickOutside);
11
+
12
+ function ClickOutside(props) {
13
+ var _this;
14
+
15
+ _classCallCheck(this, ClickOutside);
16
+
17
+ _this = _super.call(this, props);
18
+
19
+ _this.handleDocumentMouseDown = function () {
20
+ if (_this.isClickedInside) {
21
+ _this.isClickedInside = false;
22
+ return;
23
+ }
24
+
25
+ _this.props.clickOutside();
26
+ };
27
+
28
+ _this.handleMouseDown = function (e) {
29
+ _this.isClickedInside = true;
30
+ };
31
+
32
+ _this.isClickedInside = false;
33
+ return _this;
34
+ }
35
+
36
+ _createClass(ClickOutside, [{
37
+ key: "componentDidMount",
38
+ value: function componentDidMount() {
39
+ document.addEventListener('mousedown', this.handleDocumentMouseDown);
40
+ }
41
+ }, {
42
+ key: "componentWillUnmount",
43
+ value: function componentWillUnmount() {
44
+ document.removeEventListener('mousedown', this.handleDocumentMouseDown);
45
+ }
46
+ }, {
47
+ key: "render",
48
+ value: function render() {
49
+ return React.cloneElement(React.Children.only(this.props.children), {
50
+ onMouseDownCapture: this.handleMouseDown
51
+ });
52
+ }
53
+ }]);
54
+
55
+ return ClickOutside;
56
+ }(React.Component);
57
+
58
+ export default ClickOutside;
@@ -0,0 +1,155 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
+ import React, { Component } from 'react';
6
+ import ClickOutside from './click-outside';
7
+ import IconButton from './topbar-component/icon-button';
8
+
9
+ var TableButton = /*#__PURE__*/function (_Component) {
10
+ _inherits(TableButton, _Component);
11
+
12
+ var _super = _createSuper(TableButton);
13
+
14
+ function TableButton(props) {
15
+ var _this;
16
+
17
+ _classCallCheck(this, TableButton);
18
+
19
+ _this = _super.call(this, props);
20
+
21
+ _this.toggleCard = function () {
22
+ _this.setState({
23
+ showCard: !_this.state.showCard,
24
+ columnCount: -1,
25
+ rowCount: -1
26
+ });
27
+ };
28
+
29
+ _this.createTableCells = function () {
30
+ var rows = [];
31
+ var _this$state = _this.state,
32
+ columnCount = _this$state.columnCount,
33
+ rowCount = _this$state.rowCount,
34
+ currentMaxColumnCount = _this$state.currentMaxColumnCount,
35
+ currentMaxRowCount = _this$state.currentMaxRowCount;
36
+
37
+ var _loop = function _loop(rowIndex) {
38
+ var cells = [];
39
+
40
+ var _loop2 = function _loop2(columnIndex) {
41
+ var isActive = columnIndex <= columnCount - 1 && rowIndex <= rowCount - 1;
42
+ var vDom = /*#__PURE__*/React.createElement("div", {
43
+ onMouseEnter: function onMouseEnter() {
44
+ return _this.onTableCellMouseEnter(rowIndex, columnIndex);
45
+ },
46
+ key: "table-row-".concat(rowIndex, "-").concat(columnIndex),
47
+ className: "sf-editor-table-card-cell ".concat(isActive ? 'sf-editor-table-card-active-cell' : '')
48
+ });
49
+ cells.push(vDom);
50
+ };
51
+
52
+ for (var columnIndex = 0; columnIndex < currentMaxColumnCount; columnIndex++) {
53
+ _loop2(columnIndex);
54
+ }
55
+
56
+ var row = /*#__PURE__*/React.createElement("div", {
57
+ key: "table-row-".concat(rowIndex),
58
+ className: "sf-editor-table-card-row"
59
+ }, cells);
60
+ rows.push(row);
61
+ };
62
+
63
+ for (var rowIndex = 0; rowIndex < currentMaxRowCount; rowIndex++) {
64
+ _loop(rowIndex);
65
+ }
66
+
67
+ return /*#__PURE__*/React.createElement("div", {
68
+ onClick: function onClick(event) {
69
+ return _this.onAddTable(event, rowCount, columnCount);
70
+ },
71
+ className: "sf-editor-table-card"
72
+ }, rows);
73
+ };
74
+
75
+ _this.onAddTable = function (event, rowCount, columnCount) {
76
+ _this.props.onAddTable(event, rowCount, columnCount);
77
+
78
+ _this.toggleCard();
79
+ };
80
+
81
+ _this.onTableCellMouseEnter = function (rowIndex, columnIndex) {
82
+ var columnCount = columnIndex + 1,
83
+ rowCount = rowIndex + 1;
84
+ var currentMaxRowCount = rowCount + 1,
85
+ currentMaxColumnCount = columnCount + 1;
86
+
87
+ if (currentMaxColumnCount > 10) {
88
+ currentMaxColumnCount = 10;
89
+ } else if (currentMaxColumnCount < 4) {
90
+ currentMaxColumnCount = 4;
91
+ }
92
+
93
+ if (currentMaxRowCount > 10) {
94
+ currentMaxRowCount = 10;
95
+ } else if (currentMaxRowCount < 4) {
96
+ currentMaxRowCount = 4;
97
+ }
98
+
99
+ _this.setState({
100
+ columnCount: columnCount,
101
+ rowCount: rowCount,
102
+ currentMaxColumnCount: currentMaxColumnCount,
103
+ currentMaxRowCount: currentMaxRowCount
104
+ });
105
+ };
106
+
107
+ _this.state = {
108
+ showCard: false,
109
+ currentMaxColumnCount: 4,
110
+ currentMaxRowCount: 4,
111
+ columnCount: -1,
112
+ rowCount: -1
113
+ };
114
+ return _this;
115
+ }
116
+
117
+ _createClass(TableButton, [{
118
+ key: "createTableScaleCard",
119
+ value: function createTableScaleCard(props) {
120
+ var _this$state2 = this.state,
121
+ columnCount = _this$state2.columnCount,
122
+ rowCount = _this$state2.rowCount;
123
+ return /*#__PURE__*/React.createElement("div", {
124
+ className: "sf-editor-table-count-card"
125
+ }, /*#__PURE__*/React.createElement("div", {
126
+ className: "sf-editor-table-cells-header"
127
+ }, "".concat(columnCount < 0 ? 0 : columnCount, " x ").concat(rowCount < 0 ? 0 : rowCount)), this.createTableCells());
128
+ }
129
+ }, {
130
+ key: "render",
131
+ value: function render() {
132
+ var _this$props = this.props,
133
+ disabled = _this$props.disabled,
134
+ isRichEditor = _this$props.isRichEditor,
135
+ text = _this$props.text;
136
+ var showCard = this.state.showCard;
137
+ return /*#__PURE__*/React.createElement("div", {
138
+ className: "sf-editor-table-btn-wrapper"
139
+ }, /*#__PURE__*/React.createElement(IconButton, {
140
+ disabled: disabled,
141
+ isRichEditor: isRichEditor,
142
+ text: text,
143
+ id: 'tableButton',
144
+ icon: 'iconfont icon-table',
145
+ onMouseDown: this.toggleCard
146
+ }), showCard && /*#__PURE__*/React.createElement(ClickOutside, {
147
+ clickOutside: this.toggleCard
148
+ }, this.createTableScaleCard()));
149
+ }
150
+ }]);
151
+
152
+ return TableButton;
153
+ }(Component);
154
+
155
+ export default TableButton;
@@ -6,6 +6,7 @@ import React from 'react';
6
6
  import HeaderList from '../components/topbar-component/header-list';
7
7
  import ButtonGroup from '../components/topbar-component/button-group';
8
8
  import IconButton from '../components/topbar-component/icon-button';
9
+ import TableButton from '../components/table-button';
9
10
  import { withTranslation } from 'react-i18next';
10
11
  import AddLinkDialog from './add-link-dialog';
11
12
  import AddImageDialog from './add-image-dialog';
@@ -168,13 +169,13 @@ var ToolBar = /*#__PURE__*/function (_React$Component) {
168
169
  return _this2.editorUtils.onClickBlock(event, 'code_block');
169
170
  },
170
171
  isActive: isCodeActive && !readOnly
171
- }), /*#__PURE__*/React.createElement(IconButton, {
172
+ }), /*#__PURE__*/React.createElement(TableButton, {
172
173
  disabled: isFormulaActive || isCodeActive || isTableActive || isHeadActive,
173
174
  isRichEditor: true,
174
175
  text: t('insert_table'),
175
176
  id: 'tableButton',
176
177
  icon: 'iconfont icon-table',
177
- onMouseDown: this.editorUtils.onAddTable
178
+ onAddTable: this.editorUtils.onAddTable
178
179
  }), window.canInsertFormula && /*#__PURE__*/React.createElement(IconButton, {
179
180
  disabled: isFormulaActive || isCodeActive || isTableActive || isHeadActive || isListActive,
180
181
  isRichEditor: true,
@@ -102,6 +102,58 @@
102
102
  margin-left:10px;
103
103
  }
104
104
 
105
+ .sf-editor-table-btn-wrapper {
106
+ position: relative;
107
+ }
108
+
109
+ .sf-editor-table-count-card {
110
+ background-color: #ffffff;
111
+ min-width: 100px;
112
+ min-height: 100px;
113
+ position: absolute;
114
+ top: 101%;
115
+ left: 0;
116
+ box-shadow: 0 1px 2px 0 rgb(0 0 0 / 5%);
117
+ border: 1px solid rgba(0, 40, 100, 0.12);
118
+ z-index: 100;
119
+ padding: 5px 10px 10px 10px;
120
+ border-radius: 2px;
121
+ }
122
+
123
+ .sf-editor-table-cells-header {
124
+ text-align: center;
125
+ height: 20px;
126
+ font-size: 14px;
127
+ }
128
+
129
+ .sf-editor-table-card {
130
+ margin-top: 5px;
131
+ }
132
+
133
+ .sf-editor-table-card-row {
134
+ display: flex;
135
+ flex-direction: row;
136
+ border-bottom: 1px solid #cccccc;
137
+ }
138
+
139
+ .sf-editor-table-card-row:first-child {
140
+ border-top: 1px solid #cccccc;
141
+ }
142
+
143
+ .sf-editor-table-card-cell {
144
+ border-right: 1px solid #cccccc;
145
+ width: 20px;
146
+ height: 15px;
147
+ }
148
+
149
+ .sf-editor-table-card-row .sf-editor-table-card-cell:first-child {
150
+ border-left: 1px solid #cccccc;
151
+ }
152
+
153
+ .sf-editor-table-card-active-cell {
154
+ background-color: #ffa94d;
155
+ }
156
+
105
157
  /*topbar style*/
106
158
 
107
159
  .menu {
@@ -1,5 +1,5 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
1
  import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
4
  import { Editor } from 'slate';
5
5
  import ListUtils from '../editor-utils/block-element-utils/list-utils';
@@ -146,6 +146,27 @@ var withBlock = function withBlock(editor) {
146
146
 
147
147
  if (firstFragmentNode.type === 'paragraph') {
148
148
  Editor.insertFragment(editor, fragment);
149
+ return;
150
+ }
151
+ /**
152
+ * if the first fragment element is a list, get normalized list items with function getNormalizedListItems and insert
153
+ */
154
+
155
+
156
+ if (firstFragmentNode.type.includes('_list')) {
157
+ var listItems = listUtils.getNormalizedListItems(firstFragmentNode);
158
+ var newFragment = fragment.slice(1);
159
+ Editor.insertNodes(editor, [{
160
+ type: firstFragmentNode.type,
161
+ children: listItems
162
+ }].concat(_toConsumableArray(newFragment)));
163
+
164
+ if (SfEditor.isEmptyParagraph(currentBlock)) {
165
+ Editor.delete(editor, {
166
+ at: path
167
+ });
168
+ }
169
+
149
170
  return;
150
171
  } // if current node is an empty paragraph, insert the fragment and
151
172
  // delete the empty paragraph
@@ -247,15 +268,16 @@ var withBlock = function withBlock(editor) {
247
268
  }
248
269
  });
249
270
  } else {
250
- var listItems = Editor.nodes(editor, {
271
+ var _listItems = Editor.nodes(editor, {
251
272
  at: editor.selection,
252
273
  match: {
253
274
  type: 'list_item'
254
275
  }
255
276
  });
277
+
256
278
  var nearestItem;
257
279
 
258
- var _iterator = _createForOfIteratorHelper(listItems),
280
+ var _iterator = _createForOfIteratorHelper(_listItems),
259
281
  _step;
260
282
 
261
283
  try {
@@ -325,7 +347,7 @@ var withBlock = function withBlock(editor) {
325
347
  break;
326
348
 
327
349
  case 'insert_table':
328
- tableUtils.insertTable();
350
+ tableUtils.insertTable(data);
329
351
  break;
330
352
 
331
353
  case 'remove_table':
@@ -356,6 +378,14 @@ var withBlock = function withBlock(editor) {
356
378
  tableUtils.exitTable();
357
379
  break;
358
380
 
381
+ case 'focus_next_table_cell':
382
+ tableUtils.focusNextTableCell();
383
+ break;
384
+
385
+ case 'focus_previous_table_cell':
386
+ tableUtils.focusPreviousTableCell();
387
+ break;
388
+
359
389
  case 'insert_formula':
360
390
  formulaUtils.insertFormula(command.data);
361
391
  break;
@@ -327,34 +327,54 @@ var withMarkdownShortcut = function withMarkdownShortcut(editor) {
327
327
  if (listUtils.isInlist()) {
328
328
  var _Editor$nodes9 = Editor.nodes(editor, {
329
329
  match: [{
330
- type: 'ordered_list'
331
- }, {
332
- type: 'unordered_list'
330
+ type: 'list_item'
333
331
  }]
334
332
  }),
335
333
  _Editor$nodes10 = _slicedToArray(_Editor$nodes9, 1),
336
334
  _node3 = _Editor$nodes10[0];
337
335
 
338
- var listNode = _node3[0];
336
+ var listItemPath = _node3[1];
337
+ var listNode = Node.parent(editor, listItemPath); // Unwrap the list item when the selection is at the first list item of the first node of document
339
338
 
340
- if (listNode.children.length === 1 && Node.text(listNode).length === 0) {
339
+ if (anchor.path[0] === 0 && anchor.path[1] === 0) {
341
340
  listUtils.unwrapList();
342
341
  return;
343
- } // Unwrap the list item when the selection is at the first list item of the first node of document
342
+ } // unwrap an empty list
344
343
 
345
344
 
346
- if (anchor.path[0] === 0 && anchor.path[1] === 0) {
345
+ if (listNode.children.length === 1 && Node.text(listNode).length === 0) {
347
346
  listUtils.unwrapList();
348
347
  return;
348
+ } // list items with mutiple chidren
349
+
350
+
351
+ var currentChildBlockIndex = anchor.path[anchor.path.length - 2];
352
+ var currentListItem;
353
+
354
+ for (var i = anchor.path.length - 1; i > 0; i--) {
355
+ var _node4 = Node.get(editor, anchor.path.slice(0, i));
356
+
357
+ if (_node4.type === 'list_item') {
358
+ currentListItem = _node4;
359
+ break;
360
+ }
361
+ }
362
+
363
+ if (currentChildBlockIndex === 0 && currentListItem.children.length > 1) {
364
+ Editor.withoutNormalizing(editor, function (editor) {
365
+ listUtils.unwrapList();
366
+ exec(command);
367
+ });
368
+ return;
349
369
  }
350
370
  }
351
371
 
352
372
  if (codeUtils.isInCodeBlock()) {
353
- var _node4 = Editor.match(editor, editor.selection, {
373
+ var _node5 = Editor.match(editor, editor.selection, {
354
374
  type: 'code_block'
355
375
  });
356
376
 
357
- var codeBlock = _node4[0];
377
+ var codeBlock = _node5[0];
358
378
  var children = codeBlock.children;
359
379
  var text = Node.text(codeBlock);
360
380
 
@@ -65,6 +65,12 @@ var Plugin = function Plugin(_editor) {
65
65
  type: "unwrap_".concat(type)
66
66
  });
67
67
  }
68
+
69
+ if (_this.tableUtils.isInTable()) {
70
+ _this.editor.exec({
71
+ type: 'focus_previous_table_cell'
72
+ });
73
+ }
68
74
  }
69
75
 
70
76
  if (isHotKey('mod+s', event)) {
@@ -86,6 +92,12 @@ var Plugin = function Plugin(_editor) {
86
92
  type: 'increase_list_item_depth'
87
93
  });
88
94
  }
95
+
96
+ if (_this.tableUtils.isInTable()) {
97
+ _this.editor.exec({
98
+ type: 'focus_next_table_cell'
99
+ });
100
+ }
89
101
  }
90
102
 
91
103
  if (isHotKey('mod+b', event)) {
@@ -2,7 +2,7 @@ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIt
2
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
3
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
4
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
5
- import { Node, Range, Path } from 'slate';
5
+ import { Node, Range, Path, Editor } from 'slate';
6
6
  import { SfEditor } from '../../custom/custom';
7
7
  import getEventTransfer from '../../custom/get-event-transfer';
8
8
  import { htmlDeserializer } from '../../../utils/deserialize-html';
@@ -14,117 +14,153 @@ var LitsUtils = function LitsUtils(editor) {
14
14
  _classCallCheck(this, LitsUtils);
15
15
 
16
16
  this.unwrapList = function () {
17
- normailizeSelection(_this.editor); // selected list item
17
+ // defer normalization util the unwrap operartions completed
18
+ SfEditor.withoutNormalizing(_this.editor, function () {
19
+ normailizeSelection(_this.editor); // selected list item
18
20
 
19
- var selectedListItem = _this.getCurrentListItem(); // first selected item path and node
21
+ var selectedListItem = _this.getCurrentListItem(); // first selected item path and node
20
22
 
21
23
 
22
- var firstSelectedItem = selectedListItem[0];
23
- var firstSelectedItemPath = firstSelectedItem[1]; // get selected list and the path of the list
24
+ var firstSelectedItem = selectedListItem[0];
25
+ var firstSelectedItemPath = firstSelectedItem[1]; // get selected list and the path of the list
24
26
 
25
- var selectedListPath = firstSelectedItemPath.slice(0, firstSelectedItemPath.length - 1);
26
- var selectedList = Node.get(_this.editor, selectedListPath); // get the node and path of parent of selected list
27
+ var selectedListPath = firstSelectedItemPath.slice(0, firstSelectedItemPath.length - 1);
28
+ var selectedList = Node.get(_this.editor, selectedListPath); // get the node and path of parent of selected list
27
29
 
28
- var listParent = Node.parent(_this.editor, selectedListPath);
29
- var listParentPath = selectedListPath.slice(0, selectedListPath.length - 1); // unwrap list of selected list item
30
- // if the type of parent of selected list is a list and it should be a list item
30
+ var listParent = Node.parent(_this.editor, selectedListPath);
31
+ var listParentPath = selectedListPath.slice(0, selectedListPath.length - 1); // unwrap list of selected list item
32
+ // if the type of parent of selected list is a list and it should be a list item
31
33
 
32
- if (listParent.type && listParent.type.includes('list')) {
33
- // get the path of parent of listParent
34
- var ancesstorPath = listParentPath.slice(0, listParentPath.length - 1);
35
- var lastSelectedListItem = selectedListItem.slice(-1)[0];
36
- var lastSelectedListItemPath = lastSelectedListItem[1];
37
- var lastSelectedListItemIndex = lastSelectedListItemPath.slice(-1)[0];
38
- var unSelectedListItem = selectedList.children.slice(selectedListItem.slice(-1)[0][1].slice(-1)[0] + 1); // insert a new list to the last selected list item
34
+ if (listParent.type && listParent.type.includes('list')) {
35
+ // get the path of parent of listParent
36
+ var ancesstorPath = listParentPath.slice(0, listParentPath.length - 1);
37
+ var lastSelectedListItem = selectedListItem.slice(-1)[0];
38
+ var lastSelectedListItemPath = lastSelectedListItem[1];
39
+ var lastSelectedListItemIndex = lastSelectedListItemPath.slice(-1)[0];
40
+ var unSelectedListItem = selectedList.children.slice(selectedListItem.slice(-1)[0][1].slice(-1)[0] + 1); // insert a new list to the last selected list item
39
41
 
40
- if (!(lastSelectedListItemIndex === selectedList.children.length - 1)) {
41
- SfEditor.insertNodes(_this.editor, {
42
- type: selectedList.type,
43
- children: []
44
- }, {
45
- at: [].concat(_toConsumableArray(lastSelectedListItemPath), [lastSelectedListItem[0].children.length])
46
- });
47
- } // move the unselected list item to the new created list
42
+ if (!(lastSelectedListItemIndex === selectedList.children.length - 1)) {
43
+ SfEditor.insertNodes(_this.editor, {
44
+ type: selectedList.type,
45
+ children: []
46
+ }, {
47
+ at: [].concat(_toConsumableArray(lastSelectedListItemPath), [lastSelectedListItem[0].children.length])
48
+ });
49
+ } // move the unselected list item to the new created list
48
50
 
49
51
 
50
- unSelectedListItem.forEach(function (item, index) {
51
- SfEditor.moveNodes(_this.editor, {
52
- at: [].concat(_toConsumableArray(lastSelectedListItemPath.slice(0, -1)), [lastSelectedListItemIndex + 1]),
53
- to: [].concat(_toConsumableArray(lastSelectedListItemPath), [lastSelectedListItem[0].children.length, index])
52
+ unSelectedListItem.forEach(function (item, index) {
53
+ SfEditor.moveNodes(_this.editor, {
54
+ at: [].concat(_toConsumableArray(lastSelectedListItemPath.slice(0, -1)), [lastSelectedListItemIndex + 1]),
55
+ to: [].concat(_toConsumableArray(lastSelectedListItemPath), [lastSelectedListItem[0].children.length, index])
56
+ });
54
57
  });
55
- });
56
- var currentItemPath = firstSelectedItemPath;
57
- var startIndexOfItemInNewList = listParentPath[listParentPath.length - 1] + 1; // move item to outer list by path
58
-
59
- selectedListItem.forEach(function (item, index) {
60
- var itemTargetPath = [].concat(_toConsumableArray(ancesstorPath), [index + startIndexOfItemInNewList]);
61
- SfEditor.moveNodes(_this.editor, {
62
- at: currentItemPath,
63
- to: itemTargetPath
58
+ var currentItemPath = firstSelectedItemPath;
59
+ var startIndexOfItemInNewList = listParentPath[listParentPath.length - 1] + 1; // move item to outer list by path
60
+
61
+ selectedListItem.forEach(function (item, index) {
62
+ var itemTargetPath = [].concat(_toConsumableArray(ancesstorPath), [index + startIndexOfItemInNewList]);
63
+ SfEditor.moveNodes(_this.editor, {
64
+ at: currentItemPath,
65
+ to: itemTargetPath
66
+ });
64
67
  });
65
- });
66
- var currentList = Node.get(_this.editor, selectedListPath); // delete empty list
68
+ var currentList = Node.get(_this.editor, selectedListPath); // delete empty list
67
69
 
68
- if (!currentList.children[0] || currentList.children[0].type !== 'list_item') {
69
- SfEditor.removeNodes(_this.editor, {
70
- at: selectedListPath
70
+ if (!currentList.children[0] || currentList.children[0].type !== 'list_item') {
71
+ SfEditor.removeNodes(_this.editor, {
72
+ at: selectedListPath
73
+ });
74
+ }
75
+ } else {
76
+ // unwrap list item if the selected list is the outest of the root
77
+ var firstListItemIndex = firstSelectedItem[1].slice(-1)[0];
78
+ var restCount = 0;
79
+ selectedListItem.forEach(function (item) {
80
+ SfEditor.unwrapNodesByTypeAtRange(_this.editor, {
81
+ match: {
82
+ type: 'list_item'
83
+ },
84
+ mode: 'highest',
85
+ at: [].concat(_toConsumableArray(selectedListPath), [firstListItemIndex + restCount])
86
+ });
87
+ restCount += item[0].children.length;
71
88
  });
72
- }
73
- } else {
74
- // unwrap list item if the selected list is the outest of the root
75
- SfEditor.unwrapNodesByTypeAtRange(_this.editor, {
76
- match: [{
77
- type: selectedList.type
78
- }],
79
- split: true,
80
- mode: 'highest'
81
- });
82
- var firstListItemIndex = firstSelectedItem[1].slice(-1)[0];
83
-
84
- var _listParentPath = Path.parent(selectedListPath);
85
-
86
- var selectedListIndex = selectedListPath.slice(-1)[0];
87
- var startIndex = firstListItemIndex === 0 ? selectedListIndex : selectedListIndex + 1;
88
- selectedListItem.forEach(function (item, index) {
89
+ var startItemRange = Editor.range(_this.editor, [].concat(_toConsumableArray(selectedListPath), [firstListItemIndex]));
90
+ var endItemRange = Editor.range(_this.editor, [].concat(_toConsumableArray(selectedListPath), [firstListItemIndex + restCount - 1]));
89
91
  SfEditor.unwrapNodesByTypeAtRange(_this.editor, {
90
- match: {
91
- type: 'list_item'
92
- },
92
+ match: [{
93
+ type: selectedList.type
94
+ }],
95
+ split: true,
93
96
  mode: 'highest',
94
- at: [].concat(_toConsumableArray(_listParentPath), [startIndex + index])
97
+ at: {
98
+ anchor: startItemRange.anchor,
99
+ focus: endItemRange.focus
100
+ }
95
101
  });
96
- });
97
- }
102
+ }
103
+ });
98
104
  };
99
105
 
100
106
  this.wrapList = function (type) {
101
107
  normailizeSelection(_this.editor);
102
- var nodes = SfEditor.nodes(_this.editor, {
103
- match: 'block'
104
- });
105
- SfEditor.wrapNodes(_this.editor, {
106
- type: type,
107
- children: []
108
- }, {
109
- split: false
110
- }); // Get selected block node from an iterator.
111
- // Modified according to the function *nodes from slate/src/interface/node.ts
112
-
113
- var items = Array.from(nodes); // wrap selected nodes into list_item
114
-
115
- for (var _i = 0, _items = items; _i < _items.length; _i++) {
116
- var _items$_i = _slicedToArray(_items[_i], 2),
117
- node = _items$_i[0],
118
- path = _items$_i[1];
119
-
120
- SfEditor.wrapNodes(_this.editor, {
121
- type: 'list_item',
122
- children: [node],
123
- data: {}
124
- }, {
125
- at: path
108
+ var selection = _this.editor.selection;
109
+ var focusPath = selection.focus.path;
110
+ var anchorPath = selection.anchor.path;
111
+
112
+ if (Path.equals(focusPath, anchorPath)) {
113
+ var _SfEditor$match = SfEditor.match(_this.editor, _this.editor.selection, 'block'),
114
+ _SfEditor$match2 = _slicedToArray(_SfEditor$match, 2),
115
+ block = _SfEditor$match2[0],
116
+ path = _SfEditor$match2[1];
117
+
118
+ Editor.withoutNormalizing(_this.editor, function (editor) {
119
+ SfEditor.wrapNodes(_this.editor, {
120
+ type: 'list_item',
121
+ children: [block],
122
+ data: {}
123
+ }, {
124
+ at: path
125
+ });
126
+ SfEditor.wrapNodes(_this.editor, {
127
+ type: type,
128
+ children: []
129
+ }, {
130
+ split: false,
131
+ at: path
132
+ });
126
133
  });
134
+ return;
127
135
  }
136
+
137
+ var commonPath = Path.common(focusPath, anchorPath);
138
+ var commonAncestor = Node.get(_this.editor, commonPath);
139
+ var startIndex = anchorPath[commonPath.length];
140
+ var endIndex = focusPath[commonPath.length]; // get hightest selected commonAncestor block items
141
+
142
+ var selectedBlock = commonAncestor.children.slice(startIndex, endIndex + 1);
143
+ Editor.withoutNormalizing(_this.editor, function (editor) {
144
+ selectedBlock.forEach(function (blockItem, index) {
145
+ // wrap block into list
146
+ if (!blockItem.type.includes('list')) {
147
+ SfEditor.wrapNodes(_this.editor, {
148
+ type: 'list_item',
149
+ children: [blockItem],
150
+ data: {}
151
+ }, {
152
+ at: [].concat(_toConsumableArray(commonPath), [startIndex + index])
153
+ });
154
+ SfEditor.wrapNodes(_this.editor, {
155
+ type: type,
156
+ children: []
157
+ }, {
158
+ split: false,
159
+ at: [].concat(_toConsumableArray(commonPath), [startIndex + index])
160
+ });
161
+ }
162
+ });
163
+ });
128
164
  };
129
165
 
130
166
  this.getCurrentListItem = function () {
@@ -224,34 +260,6 @@ var LitsUtils = function LitsUtils(editor) {
224
260
  return [[commonAncestor, commonPath]];
225
261
  }
226
262
 
227
- if (commonPath.length === 0) {
228
- var listNodes = SfEditor.nodes(_this.editor, {
229
- match: [{
230
- type: 'list_item'
231
- }, {
232
- type: 'list_item'
233
- }],
234
- mode: 'highest'
235
- });
236
- var list = [];
237
-
238
- var _iterator2 = _createForOfIteratorHelper(listNodes),
239
- _step2;
240
-
241
- try {
242
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
243
- var iterator = _step2.value;
244
- list.push(iterator);
245
- }
246
- } catch (err) {
247
- _iterator2.e(err);
248
- } finally {
249
- _iterator2.f();
250
- }
251
-
252
- return list;
253
- }
254
-
255
263
  return [];
256
264
  };
257
265
 
@@ -263,19 +271,19 @@ var LitsUtils = function LitsUtils(editor) {
263
271
  });
264
272
  var node; //get the nearest list_item of current selection
265
273
 
266
- var _iterator3 = _createForOfIteratorHelper(listNodes),
267
- _step3;
274
+ var _iterator2 = _createForOfIteratorHelper(listNodes),
275
+ _step2;
268
276
 
269
277
  try {
270
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
271
- var item = _step3.value;
278
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
279
+ var item = _step2.value;
272
280
  node = item;
273
281
  } // if current list item is the first child of the list return
274
282
 
275
283
  } catch (err) {
276
- _iterator3.e(err);
284
+ _iterator2.e(err);
277
285
  } finally {
278
- _iterator3.f();
286
+ _iterator2.f();
279
287
  }
280
288
 
281
289
  var listItemPath = _toConsumableArray(node[1]);
@@ -287,18 +295,21 @@ var LitsUtils = function LitsUtils(editor) {
287
295
  var previousListItem = listNode.children[listItemIndex - 1];
288
296
  var previousListItemPath = [].concat(_toConsumableArray(listNodePath), [listItemIndex - 1]);
289
297
  var lastIndex = previousListItem.children.length;
290
- var newListPath = [].concat(_toConsumableArray(previousListItemPath), [lastIndex]);
291
- SfEditor.insertNodes(_this.editor, {
292
- type: listNode.type,
293
- children: []
294
- }, {
295
- at: newListPath,
296
- split: true
297
- });
298
- var newListItemPath = [].concat(_toConsumableArray(newListPath), [0]);
299
- SfEditor.moveNodes(_this.editor, {
300
- at: node[1],
301
- to: newListItemPath
298
+ var newListPath = [].concat(_toConsumableArray(previousListItemPath), [lastIndex]); // Deferring normalization list untils after operations completes.
299
+
300
+ SfEditor.withoutNormalizing(_this.editor, function () {
301
+ SfEditor.insertNodes(_this.editor, {
302
+ type: listNode.type,
303
+ children: []
304
+ }, {
305
+ at: newListPath,
306
+ split: true
307
+ });
308
+ var newListItemPath = [].concat(_toConsumableArray(newListPath), [0]);
309
+ SfEditor.moveNodes(_this.editor, {
310
+ at: node[1],
311
+ to: newListItemPath
312
+ });
302
313
  });
303
314
  };
304
315
 
@@ -333,8 +344,6 @@ var LitsUtils = function LitsUtils(editor) {
333
344
  type = _getEventTransfer.type,
334
345
  html = _getEventTransfer.html;
335
346
 
336
- console.log(fragment);
337
-
338
347
  if (type === 'text' && !fragment) {
339
348
  var newText = text.replace(/\r\n|\n/g, ' ');
340
349
  SfEditor.insertText(_this.editor, newText);
@@ -2,7 +2,7 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
3
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
4
4
  import { SfEditor } from '../../custom/custom';
5
- import { Node } from 'slate';
5
+ import { Node, Editor } from 'slate';
6
6
  import { generateTable, generateTableRow, generateTableCell } from '../../element-model/table';
7
7
  import getEventTransfer from '../../custom/get-event-transfer';
8
8
  import { htmlDeserializer } from '../../../utils/deserialize-html';
@@ -28,8 +28,67 @@ var TableUtils = function TableUtils(_editor) {
28
28
  return false;
29
29
  };
30
30
 
31
- this.insertTable = function () {
32
- var tableElement = generateTable();
31
+ this.focusNextTableCell = function () {
32
+ var position = _this.getTablePosition();
33
+
34
+ var rowIndex = position.rowIndex,
35
+ cellIndex = position.cellIndex,
36
+ row = position.row,
37
+ table = position.table;
38
+ var nextCellIndex, nextRowIndex;
39
+
40
+ if (cellIndex < row.children.length - 1) {
41
+ nextCellIndex = cellIndex + 1;
42
+ nextRowIndex = rowIndex;
43
+ } else {
44
+ if (rowIndex < table.children.length - 1) {
45
+ nextCellIndex = 0;
46
+ nextRowIndex = rowIndex + 1;
47
+ } else {
48
+ _this.insertRow();
49
+
50
+ nextCellIndex = 0;
51
+ nextRowIndex = rowIndex + 1;
52
+ }
53
+ }
54
+
55
+ _this.selectCellByPosition(nextRowIndex, nextCellIndex);
56
+ };
57
+
58
+ this.focusPreviousTableCell = function () {
59
+ var position = _this.getTablePosition();
60
+
61
+ var rowIndex = position.rowIndex,
62
+ cellIndex = position.cellIndex,
63
+ row = position.row;
64
+ var nextCellIndex, nextRowIndex;
65
+
66
+ if (cellIndex > 0) {
67
+ nextCellIndex = cellIndex - 1;
68
+ nextRowIndex = rowIndex;
69
+ } else {
70
+ if (rowIndex > 0) {
71
+ nextRowIndex = rowIndex - 1;
72
+ nextCellIndex = row.children.length - 1;
73
+ } else {
74
+ nextCellIndex = 0;
75
+ nextRowIndex = 0;
76
+ }
77
+ }
78
+
79
+ _this.selectCellByPosition(nextRowIndex, nextCellIndex);
80
+ };
81
+
82
+ this.selectCellByPosition = function (rowIndex, cellIndex) {
83
+ var _this$getTablePositio = _this.getTablePosition(),
84
+ tablePath = _this$getTablePositio.tablePath;
85
+
86
+ var cellRange = Editor.range(_this.editor, [].concat(_toConsumableArray(tablePath), [rowIndex, cellIndex]));
87
+ Editor.select(_this.editor, cellRange.focus);
88
+ };
89
+
90
+ this.insertTable = function (data) {
91
+ var tableElement = generateTable(data);
33
92
  SfEditor.insertNodes(_this.editor, tableElement); // get the first cell path of the table and move selection to it;
34
93
 
35
94
  var table = SfEditor.match(_this.editor, _this.editor.selection, {
@@ -417,11 +417,15 @@ var EditorUtils = /*#__PURE__*/function () {
417
417
  });
418
418
  };
419
419
 
420
- this.onAddTable = function (event) {
420
+ this.onAddTable = function (event, rowCount, columnCount) {
421
421
  event.preventDefault();
422
422
 
423
423
  _this.editor.exec({
424
- type: 'insert_table'
424
+ type: 'insert_table',
425
+ data: {
426
+ rowCount: rowCount,
427
+ columnCount: columnCount
428
+ }
425
429
  });
426
430
  };
427
431
 
@@ -6,7 +6,20 @@ var Table = function Table() {
6
6
  _classCallCheck(this, Table);
7
7
 
8
8
  this.type = options.type || 'table';
9
- this.children = options.children || [generateTableRow(), generateTableRow()];
9
+ var rowCount = options.rowCount,
10
+ columnCount = options.columnCount;
11
+ var children = options.children;
12
+
13
+ if (rowCount) {
14
+ var list = new Array(rowCount).fill('');
15
+ children = list.map(function () {
16
+ return generateTableRow({
17
+ columnCount: columnCount
18
+ });
19
+ });
20
+ }
21
+
22
+ this.children = children;
10
23
  };
11
24
 
12
25
  var TableRow = function TableRow() {
@@ -15,7 +28,17 @@ var TableRow = function TableRow() {
15
28
  _classCallCheck(this, TableRow);
16
29
 
17
30
  this.type = options.type || 'table_row';
18
- this.children = options.children || [generateTableCell(), generateTableCell()];
31
+ var columnCount = options.columnCount;
32
+ var children = options.children;
33
+
34
+ if (columnCount) {
35
+ var list = new Array(columnCount).fill('');
36
+ children = list.map(function () {
37
+ return generateTableCell();
38
+ });
39
+ }
40
+
41
+ this.children = children;
19
42
  };
20
43
 
21
44
  var TableCell = function TableCell() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/seafile-editor",
3
- "version": "0.3.78",
3
+ "version": "0.3.82",
4
4
  "private": false,
5
5
  "dependencies": {
6
6
  "@seafile/slate-react": "^0.54.13",