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

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
- const pageWidth = sdocEditorPage === null || sdocEditorPage === void 0 ? void 0 : sdocEditorPage.getBoundingClientRect().width;
161
+ const pageWidth = 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,13 @@ 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");
15
+ var _localStorageUtils = _interopRequireDefault(require("../../../../../utils/local-storage-utils"));
16
+ var _constants = require("../../../../constants");
14
17
  require("./index.css");
15
- var _slateReact = require("@seafile/slate-react");
16
18
  const MultiColumn = _ref => {
17
19
  let {
18
20
  className,
@@ -27,69 +29,75 @@ const MultiColumn = _ref => {
27
29
  ...element.style
28
30
  } : {});
29
31
  const multiColumnContainerClassName = (0, _classnames.default)('sdoc-multicolumn-container', className);
30
- const [pageWidth, setPageWidth] = (0, _react.useState)((0, _helper.realTimePageWidth)());
32
+ const [pageWidth, setPageWidth] = (0, _react.useState)((0, _helper.getCurrentPageWidth)());
33
+ // const [isChangedPageWidth, setIsChangedPageWidth] = useState(false);
34
+ // const [fullPageWidthState, setFullPageWidthState] = useState(null);
35
+
31
36
  const handleResizeColumn = newColumn => {
32
37
  setColumn(newColumn);
33
38
  };
34
39
 
35
40
  // useEffect(() => {
36
- // const columnWidthList = element.column.map(item => `${item.width}px`);
37
- // console.log(54, element.column);
38
- // setColumn(columnWidthList);
39
- // }, [element.style]);
41
+ // const fullPageWidthStorage = LocalStorage.getItem(FULL_WIDTH_MODE);
42
+ // setFullPageWidthState(fullPageWidthStorage);
43
+ // console.log(666)
44
+ // }, []);
45
+
46
+ // useEffect(() => {
47
+ // const handleStorageChange = (event) => {
48
+ // if (event.key === FULL_WIDTH_MODE && LocalStorage.getItem(FULL_WIDTH_MODE) !== fullPageWidthState) {
49
+ // setIsChangedPageWidth(true);
50
+ // console.log(555)
51
+ // }
52
+ // };
53
+
54
+ // window.addEventListener('storage', handleStorageChange);
55
+
56
+ // return () => {
57
+ // window.removeEventListener('storage', handleStorageChange);
58
+ // };
59
+ // }, [fullPageWidthState]);
40
60
 
41
61
  (0, _react.useEffect)(() => {
42
- let columnWidthList = element.column.map(item => `${item.width}px`);
62
+ console.log(3, column, element.column);
43
63
  const sdocEditorPage = document.getElementById('sdoc-editor');
44
64
  if (!sdocEditorPage) return;
45
65
  const resizeObserver = new ResizeObserver(entries => {
46
66
  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 => ({
67
+ const newPageWidth = (_entries$ = entries[0]) === null || _entries$ === void 0 ? void 0 : _entries$.contentRect.width;
68
+ // Check if sdocPageWidth changes
69
+ if (newPageWidth !== pageWidth) {
70
+ console.log('change');
71
+ const scaleFactor = newPageWidth / pageWidth;
72
+ const updatedColumns = element.column.map(item => ({
54
73
  ...item,
55
74
  width: Math.round(item.width * scaleFactor)
56
75
  }));
57
- columnWidthList = updatedColumns.map(item => `${item.width}px`);
76
+ const columnWidthList = updatedColumns.map(item => `${item.width}px`);
58
77
  const newStyle = {
59
78
  ...element.style,
60
79
  gridTemplateColumns: columnWidthList.join(' ')
61
80
  };
62
81
  setStyle(newStyle);
63
- console.log(5554, updatedColumns);
64
- setColumn(updatedColumns);
65
- setPageWidth(realTimeWidth);
82
+ // setColumn(updatedColumns);
83
+ setPageWidth(newPageWidth);
66
84
  (0, _helper.updateColumnWidth)(editor, element, updatedColumns);
67
85
  } else {
68
- console.log(55555, columnWidthList);
86
+ console.log(0);
87
+ const columnWidthList = element.column.map(item => `${item.width}px`);
69
88
  const newStyle = {
70
89
  ...element.style,
71
90
  gridTemplateColumns: columnWidthList.join(' ')
72
91
  };
73
- // setColumn(columnWidthList);
74
- console.log(5556, newStyle, element.column);
75
- setColumn(element.column);
76
92
  setStyle(newStyle);
93
+ // setColumn(element.column);
77
94
  }
78
95
  });
79
96
  resizeObserver.observe(sdocEditorPage);
80
97
  return () => {
81
98
  resizeObserver.disconnect();
82
99
  };
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
-
100
+ }, [pageWidth, element.style, element.column]);
93
101
  return /*#__PURE__*/_react.default.createElement(_multiColumnRoot.default, {
94
102
  attributes: attributes
95
103
  }, /*#__PURE__*/_react.default.createElement("div", {
@@ -100,7 +108,7 @@ const MultiColumn = _ref => {
100
108
  }, children, /*#__PURE__*/_react.default.createElement(_resizeHandlers.default, {
101
109
  element: element,
102
110
  handleResizeColumn: handleResizeColumn,
103
- columnWidthList: column
111
+ newColumnWidthList: element.column
104
112
  })));
105
113
  };
106
114
  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) {
@@ -17,20 +17,20 @@ const ResizeHandlers = _ref => {
17
17
  let {
18
18
  element,
19
19
  handleResizeColumn,
20
- columnWidthList
20
+ newColumnWidthList
21
21
  } = _ref;
22
22
  const editor = (0, _slateReact.useSlateStatic)();
23
- const [column, setColumn] = (0, _react.useState)(columnWidthList);
23
+ const [columnWidthList, setColumnWidthList] = (0, _react.useState)(newColumnWidthList);
24
24
  const [isDraggingResizeHandler, setIsDraggingResizeHandler] = (0, _react.useState)(false);
25
25
  const [adjustingCell, setAdjustingCell] = (0, _react.useState)(null);
26
26
  const [resizeInfo, setResizeInfo] = (0, _react.useState)({
27
27
  initialX: 0,
28
28
  cellWidths: []
29
29
  });
30
- const [isMouseNearBorder, setIsMouseNearBorder] = (0, _react.useState)(column.map(() => false));
30
+ const [isMouseNearBorder, setIsMouseNearBorder] = (0, _react.useState)(columnWidthList.map(() => false));
31
31
  const handleMouseDown = (index, event) => {
32
32
  event.preventDefault();
33
- const cellWidths = column.map(col => col.width);
33
+ const cellWidths = columnWidthList.map(col => col.width);
34
34
  setResizeInfo({
35
35
  initialX: event.clientX,
36
36
  cellWidths,
@@ -42,15 +42,8 @@ const ResizeHandlers = _ref => {
42
42
 
43
43
  // Render when column element of multi_column node changes
44
44
  (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
-
45
+ setColumnWidthList(newColumnWidthList);
46
+ }, [newColumnWidthList]);
54
47
  (0, _react.useEffect)(() => {
55
48
  const path = _slateReact.ReactEditor.findPath(editor, element);
56
49
  const [node] = _slate.Editor.node(editor, path);
@@ -60,7 +53,7 @@ const ResizeHandlers = _ref => {
60
53
  const onMouseMove = event => {
61
54
  event.preventDefault();
62
55
  // Let resize handler show when mouse is close to right edge of column at range of 20 px
63
- const nearBorder = column.map((col, colIndex) => {
56
+ const nearBorder = columnWidthList.map((col, colIndex) => {
64
57
  const child = childNodes[colIndex];
65
58
  if (!child) return false;
66
59
  const childRect = child.getBoundingClientRect();
@@ -84,7 +77,7 @@ const ResizeHandlers = _ref => {
84
77
  const deltaX = Math.min(event.clientX - initialX, cellWidths[index + 1] - _constants.COLUMN_MIN_WIDTH);
85
78
  const newWidth = Math.max(cellWidths[index] + deltaX, _constants.COLUMN_MIN_WIDTH);
86
79
  if (cellWidths[index] === _constants.COLUMN_MIN_WIDTH && deltaX < 0) return;
87
- const updatedColumn = column.map((column, colIndex) => {
80
+ const updatedColumnWidthList = columnWidthList.map((column, colIndex) => {
88
81
  if (colIndex === index) {
89
82
  return {
90
83
  ...column,
@@ -98,12 +91,12 @@ const ResizeHandlers = _ref => {
98
91
  }
99
92
  return column;
100
93
  });
101
- setColumn(updatedColumn);
94
+ setColumnWidthList(updatedColumnWidthList);
102
95
  };
103
96
  const onMouseUp = event => {
104
97
  event.preventDefault();
105
98
  if (adjustingCell === null) return;
106
- const newColumn = column.map(column => ({
99
+ const newColumn = columnWidthList.map(column => ({
107
100
  ...column,
108
101
  left: column.width
109
102
  }));
@@ -124,12 +117,12 @@ const ResizeHandlers = _ref => {
124
117
  'mouseleave': onMouseUp
125
118
  });
126
119
  };
127
- }, [handleResizeColumn, column, isDraggingResizeHandler, isMouseNearBorder]);
120
+ }, [handleResizeColumn, columnWidthList, isDraggingResizeHandler, isMouseNearBorder]);
128
121
  let leftAccumulator = 0;
129
122
  return /*#__PURE__*/_react.default.createElement("div", {
130
123
  className: "column-resize-handler",
131
124
  contentEditable: false
132
- }, column.map((column, index) => {
125
+ }, columnWidthList.map((column, index) => {
133
126
  leftAccumulator += column.width;
134
127
  const left = leftAccumulator;
135
128
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, {
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.5",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",