@seafile/sdoc-editor 1.0.202-test-0.0.4 → 1.0.202-test-0.0.6

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.
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.updateColumnWidthOnDeletion = exports.updateColumnWidth = exports.realTimePageWidth = exports.insertMultiColumn = exports.handleInsertMultiColumn = exports.generateEmptyMultiColumn = void 0;
7
+ exports.updateColumnWidthOnDeletion = exports.updateColumnWidth = exports.insertMultiColumn = exports.handleInsertMultiColumn = exports.getCurrentPageWidth = exports.generateEmptyMultiColumn = void 0;
8
8
  var _slugid = _interopRequireDefault(require("slugid"));
9
9
  var _slate = require("@seafile/slate");
10
10
  var _slateReact = require("@seafile/slate-react");
@@ -40,7 +40,8 @@ const generateEmptyMultiColumn = (editor, MultiColumnType) => {
40
40
  default:
41
41
  break;
42
42
  }
43
- const initialColumnWidth = realTimePageWidth() ? Math.max(_constants2.COLUMN_MIN_WIDTH, parseInt(realTimePageWidth() / multiColumnNumber)) : _constants2.COLUMN_MIN_WIDTH;
43
+ const currentPageWidth = getCurrentPageWidth();
44
+ const initialColumnWidth = Math.max(_constants2.COLUMN_MIN_WIDTH, parseInt(currentPageWidth / multiColumnNumber));
44
45
  for (let i = 0; i < multiColumnNumber; i++) {
45
46
  const columnWidthKey = _slugid.default.nice();
46
47
  column.push({
@@ -76,7 +77,6 @@ exports.generateEmptyMultiColumn = generateEmptyMultiColumn;
76
77
  const updateColumnWidth = (editor, element, column, newPath) => {
77
78
  const path = (0, _core.findPath)(editor, element, newPath);
78
79
  const gridTemplateColumns = column.map(column => `${column.width}px`).join(' ');
79
- console.log(4, gridTemplateColumns);
80
80
  _slate.Transforms.setNodes(editor, {
81
81
  column: column,
82
82
  style: {
@@ -144,21 +144,21 @@ const updateColumnWidthOnDeletion = (editor, selection, column, deletionDirectio
144
144
  const newMultiColumnNode = _slate.Node.get(editor, multiColumnPath);
145
145
  const targetColumnIndex = selection.anchor.path[1] + (deletionDirection === 'deleteForward' ? 1 : 0);
146
146
  const remainingColumn = column.filter((_, index) => index !== targetColumnIndex);
147
- const columnWidth = realTimePageWidth() ? Math.max(_constants2.COLUMN_MIN_WIDTH, parseInt(realTimePageWidth() / remainingColumn.length)) : _constants2.COLUMN_MIN_WIDTH;
148
- console.log(1, remainingColumn);
147
+ const currentPageWidth = getCurrentPageWidth();
148
+ const columnWidth = Math.max(_constants2.COLUMN_MIN_WIDTH, parseInt(currentPageWidth / remainingColumn.length));
149
+
149
150
  // Recalculate width of every left column
150
151
  const newColumn = remainingColumn.map((column, index) => ({
151
152
  ...column,
152
153
  left: index * columnWidth,
153
154
  width: columnWidth
154
155
  }));
155
- console.log(2, newColumn);
156
156
  updateColumnWidth(editor, newMultiColumnNode, newColumn, multiColumnPath);
157
157
  };
158
158
  exports.updateColumnWidthOnDeletion = updateColumnWidthOnDeletion;
159
- const realTimePageWidth = () => {
159
+ const getCurrentPageWidth = () => {
160
160
  const sdocEditorPage = document.getElementById('sdoc-editor');
161
161
  const pageWidth = sdocEditorPage === null || sdocEditorPage === void 0 ? void 0 : sdocEditorPage.getBoundingClientRect().width;
162
162
  return pageWidth;
163
163
  };
164
- exports.realTimePageWidth = realTimePageWidth;
164
+ exports.getCurrentPageWidth = getCurrentPageWidth;
@@ -11,7 +11,6 @@
11
11
  position: relative;
12
12
  display: grid;
13
13
  cursor: text;
14
- /* border: 1px solid red; */
15
14
  }
16
15
 
17
16
  .sdoc-multicolumn-wrapper .column {
@@ -19,7 +18,6 @@
19
18
  left: 3px;
20
19
  line-height: 1.5;
21
20
  align-items: flex-start;
22
- /* border: 1px solid red; */
23
21
  }
24
22
 
25
23
  .sdoc-column-container {
@@ -31,7 +29,6 @@
31
29
  box-sizing: border-box;
32
30
  word-wrap: break-word;
33
31
  white-space: pre-wrap;
34
-
35
32
  }
36
33
 
37
34
  .sdoc-multicolumn-container .column-resize-handler {
@@ -47,12 +44,10 @@
47
44
  margin-right: 1.5px;
48
45
  position: absolute;
49
46
  cursor: col-resize;
50
- border: 1px solid red;
51
47
  }
52
48
 
53
49
  .sdoc-multicolumn-container .column-resize-handler .column-width-just.active,
54
50
  .sdoc-multicolumn-container .column-resize-handler .column-width-just:hover {
55
51
  background-color: lightgray;
56
52
  cursor: col-resize;
57
- /* border: 1px solid red; */
58
53
  }
@@ -8,11 +8,11 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.default = void 0;
9
9
  var _react = _interopRequireWildcard(require("react"));
10
10
  var _classnames = _interopRequireDefault(require("classnames"));
11
+ var _slateReact = require("@seafile/slate-react");
11
12
  var _multiColumnRoot = _interopRequireDefault(require("./multi-column-root"));
12
13
  var _resizeHandlers = _interopRequireDefault(require("../resize-handlers"));
13
14
  var _helper = require("../helper");
14
15
  require("./index.css");
15
- var _slateReact = require("@seafile/slate-react");
16
16
  const MultiColumn = _ref => {
17
17
  let {
18
18
  className,
@@ -22,57 +22,41 @@ const MultiColumn = _ref => {
22
22
  } = _ref;
23
23
  const editor = (0, _slateReact.useSlateStatic)();
24
24
  const multiColumn = (0, _react.useRef)(null);
25
- const [column, setColumn] = (0, _react.useState)(element.column || []);
26
25
  const [style, setStyle] = (0, _react.useState)(element.style ? {
27
26
  ...element.style
28
27
  } : {});
29
28
  const multiColumnContainerClassName = (0, _classnames.default)('sdoc-multicolumn-container', className);
30
- const [pageWidth, setPageWidth] = (0, _react.useState)((0, _helper.realTimePageWidth)());
29
+ const [pageWidth, setPageWidth] = (0, _react.useState)((0, _helper.getCurrentPageWidth)());
31
30
  const handleResizeColumn = newColumn => {
32
- setColumn(newColumn);
31
+ (0, _helper.updateColumnWidth)(editor, element, newColumn);
33
32
  };
34
-
35
- // useEffect(() => {
36
- // const columnWidthList = element.column.map(item => `${item.width}px`);
37
- // console.log(54, element.column);
38
- // setColumn(columnWidthList);
39
- // }, [element.style]);
40
-
41
33
  (0, _react.useEffect)(() => {
42
- let columnWidthList = element.column.map(item => `${item.width}px`);
43
34
  const sdocEditorPage = document.getElementById('sdoc-editor');
44
35
  if (!sdocEditorPage) return;
45
36
  const resizeObserver = new ResizeObserver(entries => {
46
37
  var _entries$;
47
- const realTimeWidth = ((_entries$ = entries[0]) === null || _entries$ === void 0 ? void 0 : _entries$.contentRect.width) || (0, _helper.realTimePageWidth)();
48
- // Check if pageWidth changes
49
- if (realTimeWidth !== pageWidth) {
50
- console.log(4444);
51
- const scaleFactor = realTimeWidth / pageWidth;
52
- console.log(5553, column);
53
- const updatedColumns = column.map(item => ({
38
+ const newPageWidth = (_entries$ = entries[0]) === null || _entries$ === void 0 ? void 0 : _entries$.contentRect.width;
39
+ // Check if sdocPageWidth changes
40
+ if (newPageWidth !== pageWidth) {
41
+ const scaleFactor = newPageWidth / pageWidth;
42
+ const updatedColumns = element.column.map(item => ({
54
43
  ...item,
55
44
  width: Math.round(item.width * scaleFactor)
56
45
  }));
57
- columnWidthList = updatedColumns.map(item => `${item.width}px`);
46
+ const columnWidthList = updatedColumns.map(item => `${item.width}px`);
58
47
  const newStyle = {
59
48
  ...element.style,
60
49
  gridTemplateColumns: columnWidthList.join(' ')
61
50
  };
62
51
  setStyle(newStyle);
63
- console.log(5554, updatedColumns);
64
- setColumn(updatedColumns);
65
- setPageWidth(realTimeWidth);
52
+ setPageWidth(newPageWidth);
66
53
  (0, _helper.updateColumnWidth)(editor, element, updatedColumns);
67
54
  } else {
68
- console.log(55555, columnWidthList);
55
+ const columnWidthList = element.column.map(item => `${item.width}px`);
69
56
  const newStyle = {
70
57
  ...element.style,
71
58
  gridTemplateColumns: columnWidthList.join(' ')
72
59
  };
73
- // setColumn(columnWidthList);
74
- console.log(5556, newStyle, element.column);
75
- setColumn(element.column);
76
60
  setStyle(newStyle);
77
61
  }
78
62
  });
@@ -80,16 +64,9 @@ const MultiColumn = _ref => {
80
64
  return () => {
81
65
  resizeObserver.disconnect();
82
66
  };
83
- }, [pageWidth, element.style, element.column, column]);
84
-
85
- // useEffect(() => {
86
- // const columnWidthList = element.column.map(item => `${item.width}px`);
87
- // console.log(55555, columnWidthList);
88
- // const newStyle = { ...element.style, gridTemplateColumns: columnWidthList.join(' ') };
89
- // setColumn(element.column);
90
- // setStyle(newStyle);
91
- // }, [element.style, element.column, column]);
92
67
 
68
+ // eslint-disable-next-line react-hooks/exhaustive-deps
69
+ }, [pageWidth, element.style, element.column]);
93
70
  return /*#__PURE__*/_react.default.createElement(_multiColumnRoot.default, {
94
71
  attributes: attributes
95
72
  }, /*#__PURE__*/_react.default.createElement("div", {
@@ -99,8 +76,7 @@ const MultiColumn = _ref => {
99
76
  "data-id": element.id
100
77
  }, children, /*#__PURE__*/_react.default.createElement(_resizeHandlers.default, {
101
78
  element: element,
102
- handleResizeColumn: handleResizeColumn,
103
- columnWidthList: column
79
+ handleResizeColumn: handleResizeColumn
104
80
  })));
105
81
  };
106
82
  function renderMultiColumn(props) {
@@ -7,19 +7,16 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _classnames = _interopRequireDefault(require("classnames"));
10
- var _slateReact = require("@seafile/slate-react");
11
- var _helper = require("../helper");
12
10
  const MultiColumnRoot = _ref => {
13
11
  let {
14
12
  attributes,
15
13
  children
16
14
  } = _ref;
17
- const editor = (0, _slateReact.useSlateStatic)();
18
15
  return /*#__PURE__*/_react.default.createElement("div", Object.assign({}, attributes, {
19
16
  className: (0, _classnames.default)('sdoc-multicolumn-wrapper position-relative', attributes.className),
20
17
  style: {
21
18
  ...attributes.style,
22
- maxWidth: (0, _helper.realTimePageWidth)() ? (0, _helper.realTimePageWidth)() : '100%'
19
+ maxWidth: '100%'
23
20
  }
24
21
  }), children);
25
22
  };
@@ -10,7 +10,6 @@ var _react = _interopRequireWildcard(require("react"));
10
10
  var _classnames = _interopRequireDefault(require("classnames"));
11
11
  var _slate = require("@seafile/slate");
12
12
  var _slateReact = require("@seafile/slate-react");
13
- var _helper = require("../helper");
14
13
  const Column = _ref => {
15
14
  let {
16
15
  attributes,
@@ -19,28 +18,9 @@ const Column = _ref => {
19
18
  } = _ref;
20
19
  const editor = (0, _slateReact.useSlateStatic)();
21
20
  const [columnWidth, setColumnWidth] = (0, _react.useState)(element.width || 0);
22
- const [pageWidth, setPageWidth] = (0, _react.useState)((0, _helper.realTimePageWidth)());
23
21
  const path = _slateReact.ReactEditor.findPath(editor, element);
24
22
  const parentPath = _slate.Path.parent(path);
25
23
  const [parentNode] = _slate.Editor.node(editor, parentPath);
26
- (0, _react.useEffect)(() => {
27
- const sdocEditorPage = document.getElementById('sdoc-editor');
28
- if (sdocEditorPage) {
29
- const resizeObserver = new ResizeObserver(entries => {
30
- const realTimeWidth = entries[0].contentRect.width;
31
- if (realTimeWidth !== pageWidth) {
32
- console.log(55, realTimeWidth, pageWidth);
33
- // const scaleFactor = realTimeWidth / pageWidth;
34
- // setColumnWidth(preColumnwidth => preColumnwidth * scaleFactor);
35
- // setPageWidth(realTimeWidth);
36
- }
37
- });
38
- resizeObserver.observe(sdocEditorPage);
39
- return () => {
40
- resizeObserver.disconnect();
41
- };
42
- }
43
- }, [editor, element, parentNode.column, pageWidth]);
44
24
  (0, _react.useEffect)(() => {
45
25
  const matchingColumn = parentNode.column.find(column => column.key === element.id);
46
26
  if (matchingColumn) {
@@ -16,11 +16,10 @@ var _mouseEvent = require("../../../../utils/mouse-event");
16
16
  const ResizeHandlers = _ref => {
17
17
  let {
18
18
  element,
19
- handleResizeColumn,
20
- columnWidthList
19
+ handleResizeColumn
21
20
  } = _ref;
22
21
  const editor = (0, _slateReact.useSlateStatic)();
23
- const [column, setColumn] = (0, _react.useState)(columnWidthList);
22
+ const [column, setColumn] = (0, _react.useState)(element.column);
24
23
  const [isDraggingResizeHandler, setIsDraggingResizeHandler] = (0, _react.useState)(false);
25
24
  const [adjustingCell, setAdjustingCell] = (0, _react.useState)(null);
26
25
  const [resizeInfo, setResizeInfo] = (0, _react.useState)({
@@ -42,15 +41,8 @@ const ResizeHandlers = _ref => {
42
41
 
43
42
  // Render when column element of multi_column node changes
44
43
  (0, _react.useEffect)(() => {
45
- console.log(3, columnWidthList);
46
- setColumn(columnWidthList);
47
- }, [columnWidthList]);
48
-
49
- // useEffect(() => {
50
- // console.log(44, element.column)
51
- // setColumn(element.column);
52
- // }, [element.column]);
53
-
44
+ setColumn(element.column);
45
+ }, [element.column]);
54
46
  (0, _react.useEffect)(() => {
55
47
  const path = _slateReact.ReactEditor.findPath(editor, element);
56
48
  const [node] = _slate.Editor.node(editor, path);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "1.0.202-test-0.0.4",
3
+ "version": "1.0.202-test-0.0.6",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",