@seafile/sdoc-editor 2.0.54 → 2.0.56

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.
@@ -17,6 +17,7 @@ var _chartEditDialog = _interopRequireDefault(require("./chart-edit-dialog"));
17
17
  var _context = _interopRequireDefault(require("../../../../context"));
18
18
  var _useScrollContext = require("../../../hooks/use-scroll-context");
19
19
  var _helpers = require("./helpers");
20
+ var _utils = require("../../utils");
20
21
  var _constants = require("../../constants");
21
22
  require("./render-elem.css");
22
23
  const Chart = _ref => {
@@ -50,11 +51,15 @@ const Chart = _ref => {
50
51
  top,
51
52
  left
52
53
  } = chartRef.current.getBoundingClientRect();
53
- setMenuPosition({
54
- top: top - 42,
55
- left: left - 3
54
+ const curTop = top - 42; // top = top distance - menu height
55
+ const curLeft = left - 3;
56
+ const newMenuPosition = (0, _utils.checkOverflow)(editor, {
57
+ top: curTop,
58
+ left: curLeft
56
59
  });
60
+ setMenuPosition(newMenuPosition);
57
61
  }
62
+ // eslint-disable-next-line react-hooks/exhaustive-deps
58
63
  }, []);
59
64
  const onScroll = (0, _react.useCallback)(e => {
60
65
  setPosition();
@@ -2,6 +2,15 @@
2
2
  outline: none;
3
3
  }
4
4
 
5
+ .seatable-rows-record-wrapper.no-row {
6
+ display: flex;
7
+ align-items: center;
8
+ justify-content: center;
9
+ border: 1px solid #ddd;
10
+ padding: 20px;
11
+ border-radius: 5px;
12
+ }
13
+
5
14
  .seatable-rows-record-container {
6
15
  margin: 5px 0;
7
16
  border: 1.5px solid #ddd;
@@ -37,7 +46,7 @@
37
46
  font-weight: 400;
38
47
  }
39
48
 
40
- .seatable-rows-record-wrapper .seatable-rows-record-container table td {
49
+ .seatable-rows-record-wrapper .seatable-rows-record-container table td {
41
50
  font-size: 14px;
42
51
  font-weight: 400;
43
52
  color: #212529
@@ -33,6 +33,7 @@ const RowRecord = _ref => {
33
33
  const [columnWidthMap, setColumnWidthMap] = (0, _react.useState)(column_width);
34
34
  const [isShowColumnWidth, setIsShowColumnWidth] = (0, _react.useState)(false);
35
35
  const [isCanModifyColumnWidth, setIsCanModifyColumnWidth] = (0, _react.useState)(false);
36
+ const [activeRow, setActiveRow] = (0, _react.useState)(null);
36
37
  const isSelected = (0, _slateReact.useSelected)();
37
38
  const {
38
39
  t
@@ -42,6 +43,7 @@ const RowRecord = _ref => {
42
43
  (0, _react.useEffect)(() => {
43
44
  async function initTableData() {
44
45
  const table = await editor.getTableById(table_id);
46
+ if (!table) return;
45
47
  if (!tableInfoRef.current) {
46
48
  tableInfoRef.current = {};
47
49
  }
@@ -55,6 +57,10 @@ const RowRecord = _ref => {
55
57
  };
56
58
  }
57
59
  const shownRecord = table.rows.filter(item => row_id === item._id);
60
+ setActiveRow(shownRecord);
61
+ if (!shownRecord) {
62
+ return;
63
+ }
58
64
  setShownRecord(shownRecord);
59
65
  setRowRecordName(shownRecord[0]['0000']);
60
66
  const updatedColumnWidthMap = Object.fromEntries(Object.entries(columnWidthMap).map(_ref2 => {
@@ -97,13 +103,14 @@ const RowRecord = _ref => {
97
103
  // eslint-disable-next-line react-hooks/exhaustive-deps
98
104
  }, [table_id]);
99
105
  (0, _react.useEffect)(() => {
106
+ if (!activeRow) return;
100
107
  if (!isSelected) {
101
108
  queueMicrotask(() => {
102
109
  setIsShowColumnWidth(false);
103
110
  setIsCanModifyColumnWidth(false);
104
111
  });
105
112
  }
106
- }, [editor, element, isSelected]);
113
+ }, [activeRow, editor, element, isSelected]);
107
114
  const onTableClick = (0, _react.useCallback)(event => {
108
115
  if (readOnly) return;
109
116
  setIsShowColumnWidth(true);
@@ -114,6 +121,13 @@ const RowRecord = _ref => {
114
121
  setIsCanModifyColumnWidth(true);
115
122
  }, [readOnly]);
116
123
  const formulaRows = (tableInfoRef === null || tableInfoRef === void 0 ? void 0 : (_tableInfoRef$current = tableInfoRef.current) === null || _tableInfoRef$current === void 0 ? void 0 : (_tableInfoRef$current2 = _tableInfoRef$current[table_id]) === null || _tableInfoRef$current2 === void 0 ? void 0 : _tableInfoRef$current2.formulaRows) || {};
124
+ if (!activeRow) {
125
+ return /*#__PURE__*/_react.default.createElement("div", Object.assign({}, attributes, {
126
+ className: "seatable-rows-record-wrapper no-row",
127
+ contentEditable: false,
128
+ suppressContentEditableWarning: true
129
+ }), t('Row_not_exist'), children);
130
+ }
117
131
  return /*#__PURE__*/_react.default.createElement("div", Object.assign({}, attributes, {
118
132
  className: "seatable-rows-record-wrapper"
119
133
  }), /*#__PURE__*/_react.default.createElement("div", {
@@ -2,6 +2,15 @@
2
2
  outline: none;
3
3
  }
4
4
 
5
+ .seatable-table-wrapper.no-table {
6
+ display: flex;
7
+ align-items: center;
8
+ justify-content: center;
9
+ border: 1px solid #ddd;
10
+ padding: 20px;
11
+ border-radius: 5px;
12
+ }
13
+
5
14
  .seatable-view-container {
6
15
  width: 100%;
7
16
  overflow: auto;
@@ -18,6 +18,7 @@ var _recordList = _interopRequireDefault(require("./record-list"));
18
18
  var _opMenu = _interopRequireDefault(require("../op-menu"));
19
19
  var _useScrollContext = require("../../../../hooks/use-scroll-context");
20
20
  var _helpers = require("../../seatable-column/helpers");
21
+ var _utils = require("../../../utils");
21
22
  var _helpers2 = require("../helpers");
22
23
  require("./index.css");
23
24
  function SeaTableTable(_ref) {
@@ -44,6 +45,7 @@ function SeaTableTable(_ref) {
44
45
  const [isShowColumnWidth, setIsShowColumnWidth] = (0, _react.useState)(false);
45
46
  const [isCanModifyColumnWidth, setIsCanModifyColumnWidth] = (0, _react.useState)(false);
46
47
  const tableInfoRef = (0, _react.useRef)(null);
48
+ const [activeTale, setActiveTable] = (0, _react.useState)(null);
47
49
  const {
48
50
  t
49
51
  } = (0, _reactI18next.useTranslation)('sdoc-editor');
@@ -59,6 +61,8 @@ function SeaTableTable(_ref) {
59
61
  // Compatible with old element data structures
60
62
  if (!column_width) {
61
63
  const table = editor.getTableById(table_id);
64
+ setActiveTable(table);
65
+ if (!table) return;
62
66
  const columnWidth = {};
63
67
  table.columns.forEach(item => {
64
68
  columnWidth[item.key] = (0, _helpers.getColumnWidth)(item);
@@ -78,6 +82,11 @@ function SeaTableTable(_ref) {
78
82
  table_id
79
83
  } = element;
80
84
  const table = await editor.getTableById(table_id);
85
+ setActiveTable(table);
86
+ if (!table) {
87
+ setIsLoading(false);
88
+ return;
89
+ }
81
90
  if (!tableInfoRef.current) {
82
91
  tableInfoRef.current = {};
83
92
  }
@@ -197,17 +206,13 @@ function SeaTableTable(_ref) {
197
206
  left
198
207
  } = seaTableRef.current.getBoundingClientRect();
199
208
  const menuTop = top - 42; // top = top distance - menu height
200
- const newMenuPosition = {
209
+ const newMenuPosition = (0, _utils.checkOverflow)(editor, {
201
210
  top: menuTop,
202
- left: left // left = code-block left distance
203
- };
204
- // 201 is distance with browser top
205
- if (menuTop < 201) {
206
- newMenuPosition['display'] = 'none';
207
- }
211
+ left
212
+ });
208
213
  setMenuPosition(newMenuPosition);
209
214
  }
210
- }, [isShowMenu, readOnly]);
215
+ }, [editor, isShowMenu, readOnly]);
211
216
  (0, _react.useEffect)(() => {
212
217
  if (readOnly) return;
213
218
  let observerRefValue = null;
@@ -258,7 +263,7 @@ function SeaTableTable(_ref) {
258
263
  }
259
264
  }, [editor, element]);
260
265
  (0, _react.useEffect)(() => {
261
- if (!isSelected) {
266
+ if (!isSelected && activeTale) {
262
267
  handleSaveData();
263
268
  queueMicrotask(() => {
264
269
  setIsShowMenu(false);
@@ -266,7 +271,7 @@ function SeaTableTable(_ref) {
266
271
  setIsCanModifyColumnWidth(false);
267
272
  });
268
273
  }
269
- }, [editor, element, handleSaveData, isSelected]);
274
+ }, [activeTale, editor, element, handleSaveData, isSelected]);
270
275
  const onTableClick = (0, _react.useCallback)(event => {
271
276
  if (readOnly) return;
272
277
  const {
@@ -294,6 +299,13 @@ function SeaTableTable(_ref) {
294
299
  const containerClass = (0, _classnames.default)('seatable-view-container', {
295
300
  selected: isSelected
296
301
  });
302
+ if (!activeTale) {
303
+ return /*#__PURE__*/_react.default.createElement("div", Object.assign({}, attributes, {
304
+ className: "seatable-table-wrapper no-table",
305
+ contentEditable: false,
306
+ suppressContentEditableWarning: true
307
+ }), t('Table_not_exist'), children);
308
+ }
297
309
  return /*#__PURE__*/_react.default.createElement("div", Object.assign({}, attributes, {
298
310
  className: "seatable-table-wrapper",
299
311
  contentEditable: true,
@@ -4,8 +4,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.onHandleOverflowScroll = exports.isSameDomain = exports.isOverflowPortByDirection = exports.isImage = exports.IMAGE_TYPES = void 0;
7
+ exports.onHandleOverflowScroll = exports.isSameDomain = exports.isOverflowPortByDirection = exports.isImage = exports.checkOverflow = exports.IMAGE_TYPES = void 0;
8
8
  var _isUrl = _interopRequireDefault(require("is-url"));
9
+ var _constants = require("../../constants");
9
10
  const IMAGE_TYPES = exports.IMAGE_TYPES = ['png', 'jpg', 'gif'];
10
11
  const isImage = url => {
11
12
  if (!url) return false;
@@ -68,4 +69,13 @@ const onHandleOverflowScroll = (currentSelectItem, downDownWrapperRef) => {
68
69
  });
69
70
  }
70
71
  };
71
- exports.onHandleOverflowScroll = onHandleOverflowScroll;
72
+ exports.onHandleOverflowScroll = onHandleOverflowScroll;
73
+ const checkOverflow = (editor, position) => {
74
+ if (editor.editorType === _constants.DOCUMENT_PLUGIN_EDITOR) {
75
+ if (position.top < 201 || position.top + 42 > window.innerHeight) {
76
+ position['display'] = 'none';
77
+ }
78
+ }
79
+ return position;
80
+ };
81
+ exports.checkOverflow = checkOverflow;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "2.0.54",
3
+ "version": "2.0.56",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -39,7 +39,7 @@
39
39
  "remark-parse": "11.0.0",
40
40
  "remark-rehype": "11.0.0",
41
41
  "remark-stringify": "11.0.0",
42
- "sea-chart": "2.0.10",
42
+ "sea-chart": "2.0.11",
43
43
  "slugid": "3.2.0",
44
44
  "socket.io-client": "4.8.1",
45
45
  "type-of": "2.0.1",
@@ -627,5 +627,7 @@
627
627
  "Edit_chart": "Edit chart",
628
628
  "Please_complete_the_chart_configuration_first": "Please complete the chart configuration first",
629
629
  "chart": "chart",
630
- "Image_is_upload_error": "Image upload failed, please delete it and try again"
630
+ "Image_is_upload_error": "Image upload failed, please delete it and try again",
631
+ "Table_not_exist": "The table does not exist, please delete the current table element",
632
+ "Row_not_exist": "The row data does not exist, please delete the current row element"
631
633
  }
@@ -627,5 +627,7 @@
627
627
  "Edit_chart": "编辑图表",
628
628
  "Please_complete_the_chart_configuration_first": "请先完成图表配置",
629
629
  "chart": "图表",
630
- "Image_is_upload_error": "图片上传失败,请删除后重新尝试"
630
+ "Image_is_upload_error": "图片上传失败,请删除后重新尝试",
631
+ "Table_not_exist": "表格不存在,请删除当前表格元素",
632
+ "Row_not_exist": "表格不存在,请删除当前行元素"
631
633
  }