@seafile/seafile-editor 0.3.80 → 0.3.81

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,156 @@
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 _this$state2 = _this.state,
83
+ currentMaxColumnCount = _this$state2.currentMaxColumnCount,
84
+ currentMaxRowCount = _this$state2.currentMaxRowCount;
85
+
86
+ if (columnIndex >= currentMaxColumnCount - 2 && currentMaxColumnCount < _this.maxColumnCount) {
87
+ currentMaxColumnCount += 1;
88
+ } else if (columnIndex < currentMaxColumnCount - 1 && currentMaxColumnCount > 4) {
89
+ currentMaxColumnCount -= 1;
90
+ }
91
+
92
+ if (rowIndex >= currentMaxRowCount - 2 && currentMaxRowCount < _this.maxRowCount) {
93
+ currentMaxRowCount += 1;
94
+ } else if (rowIndex < currentMaxRowCount - 1 && currentMaxRowCount > 4) {
95
+ currentMaxRowCount -= 1;
96
+ }
97
+
98
+ _this.setState({
99
+ columnCount: columnIndex + 1,
100
+ rowCount: rowIndex + 1,
101
+ currentMaxColumnCount: currentMaxColumnCount,
102
+ currentMaxRowCount: currentMaxRowCount
103
+ });
104
+ };
105
+
106
+ _this.state = {
107
+ showCard: false,
108
+ currentMaxColumnCount: 4,
109
+ currentMaxRowCount: 4,
110
+ columnCount: -1,
111
+ rowCount: -1
112
+ };
113
+ _this.maxColumnCount = 10;
114
+ _this.maxRowCount = 10;
115
+ return _this;
116
+ }
117
+
118
+ _createClass(TableButton, [{
119
+ key: "createTableScaleCard",
120
+ value: function createTableScaleCard(props) {
121
+ var _this$state3 = this.state,
122
+ columnCount = _this$state3.columnCount,
123
+ rowCount = _this$state3.rowCount;
124
+ return /*#__PURE__*/React.createElement("div", {
125
+ className: "sf-editor-table-count-card"
126
+ }, /*#__PURE__*/React.createElement("div", {
127
+ className: "sf-editor-table-cells-header"
128
+ }, "".concat(columnCount < 0 ? 0 : columnCount, " x ").concat(rowCount < 0 ? 0 : rowCount)), this.createTableCells());
129
+ }
130
+ }, {
131
+ key: "render",
132
+ value: function render() {
133
+ var _this$props = this.props,
134
+ disabled = _this$props.disabled,
135
+ isRichEditor = _this$props.isRichEditor,
136
+ text = _this$props.text;
137
+ var showCard = this.state.showCard;
138
+ return /*#__PURE__*/React.createElement("div", {
139
+ className: "sf-editor-table-btn-wrapper"
140
+ }, /*#__PURE__*/React.createElement(IconButton, {
141
+ disabled: disabled,
142
+ isRichEditor: isRichEditor,
143
+ text: text,
144
+ id: 'tableButton',
145
+ icon: 'iconfont icon-table',
146
+ onMouseDown: this.toggleCard
147
+ }), showCard && /*#__PURE__*/React.createElement(ClickOutside, {
148
+ clickOutside: this.toggleCard
149
+ }, this.createTableScaleCard()));
150
+ }
151
+ }]);
152
+
153
+ return TableButton;
154
+ }(Component);
155
+
156
+ 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 {
@@ -347,7 +347,7 @@ var withBlock = function withBlock(editor) {
347
347
  break;
348
348
 
349
349
  case 'insert_table':
350
- tableUtils.insertTable();
350
+ tableUtils.insertTable(data);
351
351
  break;
352
352
 
353
353
  case 'remove_table':
@@ -378,6 +378,14 @@ var withBlock = function withBlock(editor) {
378
378
  tableUtils.exitTable();
379
379
  break;
380
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
+
381
389
  case 'insert_formula':
382
390
  formulaUtils.insertFormula(command.data);
383
391
  break;
@@ -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 _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.80",
3
+ "version": "0.3.81",
4
4
  "private": false,
5
5
  "dependencies": {
6
6
  "@seafile/slate-react": "^0.54.13",