@seafile/sdoc-editor 1.0.202-test-0.0.3 → 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({
@@ -143,7 +144,8 @@ const updateColumnWidthOnDeletion = (editor, selection, column, deletionDirectio
143
144
  const newMultiColumnNode = _slate.Node.get(editor, multiColumnPath);
144
145
  const targetColumnIndex = selection.anchor.path[1] + (deletionDirection === 'deleteForward' ? 1 : 0);
145
146
  const remainingColumn = column.filter((_, index) => index !== targetColumnIndex);
146
- const columnWidth = realTimePageWidth() ? Math.max(_constants2.COLUMN_MIN_WIDTH, parseInt(realTimePageWidth() / remainingColumn.length)) : _constants2.COLUMN_MIN_WIDTH;
147
+ const currentPageWidth = getCurrentPageWidth();
148
+ const columnWidth = Math.max(_constants2.COLUMN_MIN_WIDTH, parseInt(currentPageWidth / remainingColumn.length));
147
149
 
148
150
  // Recalculate width of every left column
149
151
  const newColumn = remainingColumn.map((column, index) => ({
@@ -154,9 +156,9 @@ const updateColumnWidthOnDeletion = (editor, selection, column, deletionDirectio
154
156
  updateColumnWidth(editor, newMultiColumnNode, newColumn, multiColumnPath);
155
157
  };
156
158
  exports.updateColumnWidthOnDeletion = updateColumnWidthOnDeletion;
157
- const realTimePageWidth = () => {
159
+ const getCurrentPageWidth = () => {
158
160
  const sdocEditorPage = document.getElementById('sdoc-editor');
159
- const pageWidth = sdocEditorPage === null || sdocEditorPage === void 0 ? void 0 : sdocEditorPage.getBoundingClientRect().width;
161
+ const pageWidth = sdocEditorPage.getBoundingClientRect().width;
160
162
  return pageWidth;
161
163
  };
162
- 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,13 +29,11 @@
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 {
38
35
  height: 100%;
39
36
  position: absolute;
40
- /* border: 1px solid red; */
41
37
  }
42
38
 
43
39
  .sdoc-multicolumn-container .column-resize-handler .column-width-just {
@@ -48,12 +44,10 @@
48
44
  margin-right: 1.5px;
49
45
  position: absolute;
50
46
  cursor: col-resize;
51
- border: 1px solid red;
52
47
  }
53
48
 
54
49
  .sdoc-multicolumn-container .column-resize-handler .column-width-just.active,
55
50
  .sdoc-multicolumn-container .column-resize-handler .column-width-just:hover {
56
51
  background-color: lightgray;
57
52
  cursor: col-resize;
58
- /* border: 1px solid red; */
59
53
  }
@@ -8,9 +8,12 @@ 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
18
  const MultiColumn = _ref => {
16
19
  let {
@@ -19,62 +22,82 @@ const MultiColumn = _ref => {
19
22
  children,
20
23
  element
21
24
  } = _ref;
25
+ const editor = (0, _slateReact.useSlateStatic)();
22
26
  const multiColumn = (0, _react.useRef)(null);
23
27
  const [column, setColumn] = (0, _react.useState)(element.column || []);
24
28
  const [style, setStyle] = (0, _react.useState)(element.style ? {
25
29
  ...element.style
26
30
  } : {});
27
31
  const multiColumnContainerClassName = (0, _classnames.default)('sdoc-multicolumn-container', className);
28
- 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
+
29
36
  const handleResizeColumn = newColumn => {
30
37
  setColumn(newColumn);
31
38
  };
32
- (0, _react.useEffect)(() => {
33
- console.log('real', column);
34
- let columnWidthList = column.map(item => `${item.width}px`);
35
- console.log(0, columnWidthList);
36
- const sdocEditorPage = document.getElementById('sdoc-editor');
37
- if (sdocEditorPage) {
38
- const resizeObserver = new ResizeObserver(entries => {
39
- const realTimeWidth = entries[0].contentRect.width;
40
- if (realTimeWidth !== pageWidth) {
41
- const scaleFactor = realTimeWidth / pageWidth;
42
- const updatedColumns = column.map(item => ({
43
- ...item,
44
- width: Math.round(item.width * scaleFactor)
45
- }));
46
- columnWidthList = updatedColumns.map(item => `${item.width}px`);
47
- console.log(22, columnWidthList);
48
- const newStyle = {
49
- ...element.style,
50
- gridTemplateColumns: columnWidthList.join(' ')
51
- };
52
- setStyle(newStyle);
53
- console.log(4, updatedColumns);
54
- setColumn(updatedColumns);
55
- setPageWidth(realTimeWidth);
56
- } else {
57
- const newStyle = {
58
- ...element.style,
59
- gridTemplateColumns: columnWidthList.join(' ')
60
- };
61
- console.log(100, newStyle);
62
- setStyle(newStyle);
63
- }
64
- });
65
- resizeObserver.observe(sdocEditorPage);
66
- return () => {
67
- resizeObserver.disconnect();
68
- };
69
- }
70
- }, [pageWidth, element.style, element.column, column]);
71
39
 
72
40
  // useEffect(() => {
73
- // const columnWidthList = element.column.map(item => `${item.width}px`);
74
- // const newStyle = { ...element.style, gridTemplateColumns: columnWidthList.join(' ') };
75
- // setStyle(newStyle);
76
- // }, [element.style, element.column, column]);
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
+ // };
77
53
 
54
+ // window.addEventListener('storage', handleStorageChange);
55
+
56
+ // return () => {
57
+ // window.removeEventListener('storage', handleStorageChange);
58
+ // };
59
+ // }, [fullPageWidthState]);
60
+
61
+ (0, _react.useEffect)(() => {
62
+ console.log(3, column, element.column);
63
+ const sdocEditorPage = document.getElementById('sdoc-editor');
64
+ if (!sdocEditorPage) return;
65
+ const resizeObserver = new ResizeObserver(entries => {
66
+ var _entries$;
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 => ({
73
+ ...item,
74
+ width: Math.round(item.width * scaleFactor)
75
+ }));
76
+ const columnWidthList = updatedColumns.map(item => `${item.width}px`);
77
+ const newStyle = {
78
+ ...element.style,
79
+ gridTemplateColumns: columnWidthList.join(' ')
80
+ };
81
+ setStyle(newStyle);
82
+ // setColumn(updatedColumns);
83
+ setPageWidth(newPageWidth);
84
+ (0, _helper.updateColumnWidth)(editor, element, updatedColumns);
85
+ } else {
86
+ console.log(0);
87
+ const columnWidthList = element.column.map(item => `${item.width}px`);
88
+ const newStyle = {
89
+ ...element.style,
90
+ gridTemplateColumns: columnWidthList.join(' ')
91
+ };
92
+ setStyle(newStyle);
93
+ // setColumn(element.column);
94
+ }
95
+ });
96
+ resizeObserver.observe(sdocEditorPage);
97
+ return () => {
98
+ resizeObserver.disconnect();
99
+ };
100
+ }, [pageWidth, element.style, element.column]);
78
101
  return /*#__PURE__*/_react.default.createElement(_multiColumnRoot.default, {
79
102
  attributes: attributes
80
103
  }, /*#__PURE__*/_react.default.createElement("div", {
@@ -85,7 +108,7 @@ const MultiColumn = _ref => {
85
108
  }, children, /*#__PURE__*/_react.default.createElement(_resizeHandlers.default, {
86
109
  element: element,
87
110
  handleResizeColumn: handleResizeColumn,
88
- columnWidthList: column
111
+ newColumnWidthList: element.column
89
112
  })));
90
113
  };
91
114
  function renderMultiColumn(props) {
@@ -7,20 +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
- console.log(33, (0, _helper.realTimePageWidth)());
19
15
  return /*#__PURE__*/_react.default.createElement("div", Object.assign({}, attributes, {
20
16
  className: (0, _classnames.default)('sdoc-multicolumn-wrapper position-relative', attributes.className),
21
17
  style: {
22
18
  ...attributes.style,
23
- maxWidth: (0, _helper.realTimePageWidth)() ? (0, _helper.realTimePageWidth)() : '100%'
19
+ maxWidth: '100%'
24
20
  }
25
21
  }), children);
26
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,
@@ -18,30 +17,10 @@ const Column = _ref => {
18
17
  children
19
18
  } = _ref;
20
19
  const editor = (0, _slateReact.useSlateStatic)();
21
- console.log(1, attributes, element, children);
22
20
  const [columnWidth, setColumnWidth] = (0, _react.useState)(element.width || 0);
23
- const [pageWidth, setPageWidth] = (0, _react.useState)((0, _helper.realTimePageWidth)());
24
21
  const path = _slateReact.ReactEditor.findPath(editor, element);
25
22
  const parentPath = _slate.Path.parent(path);
26
23
  const [parentNode] = _slate.Editor.node(editor, parentPath);
27
- (0, _react.useEffect)(() => {
28
- const sdocEditorPage = document.getElementById('sdoc-editor');
29
- if (sdocEditorPage) {
30
- const resizeObserver = new ResizeObserver(entries => {
31
- const realTimeWidth = entries[0].contentRect.width;
32
- if (realTimeWidth !== pageWidth) {
33
- console.log(55, realTimeWidth, pageWidth);
34
- const scaleFactor = realTimeWidth / pageWidth;
35
- setColumnWidth(preColumnwidth => preColumnwidth * scaleFactor);
36
- setPageWidth(realTimeWidth);
37
- }
38
- });
39
- resizeObserver.observe(sdocEditorPage);
40
- return () => {
41
- resizeObserver.disconnect();
42
- };
43
- }
44
- }, [editor, element, parentNode.column, pageWidth]);
45
24
  (0, _react.useEffect)(() => {
46
25
  const matchingColumn = parentNode.column.find(column => column.key === element.id);
47
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,8 +42,8 @@ const ResizeHandlers = _ref => {
42
42
 
43
43
  // Render when column element of multi_column node changes
44
44
  (0, _react.useEffect)(() => {
45
- setColumn(columnWidthList);
46
- }, [columnWidthList]);
45
+ setColumnWidthList(newColumnWidthList);
46
+ }, [newColumnWidthList]);
47
47
  (0, _react.useEffect)(() => {
48
48
  const path = _slateReact.ReactEditor.findPath(editor, element);
49
49
  const [node] = _slate.Editor.node(editor, path);
@@ -53,7 +53,7 @@ const ResizeHandlers = _ref => {
53
53
  const onMouseMove = event => {
54
54
  event.preventDefault();
55
55
  // Let resize handler show when mouse is close to right edge of column at range of 20 px
56
- const nearBorder = column.map((col, colIndex) => {
56
+ const nearBorder = columnWidthList.map((col, colIndex) => {
57
57
  const child = childNodes[colIndex];
58
58
  if (!child) return false;
59
59
  const childRect = child.getBoundingClientRect();
@@ -77,7 +77,7 @@ const ResizeHandlers = _ref => {
77
77
  const deltaX = Math.min(event.clientX - initialX, cellWidths[index + 1] - _constants.COLUMN_MIN_WIDTH);
78
78
  const newWidth = Math.max(cellWidths[index] + deltaX, _constants.COLUMN_MIN_WIDTH);
79
79
  if (cellWidths[index] === _constants.COLUMN_MIN_WIDTH && deltaX < 0) return;
80
- const updatedColumn = column.map((column, colIndex) => {
80
+ const updatedColumnWidthList = columnWidthList.map((column, colIndex) => {
81
81
  if (colIndex === index) {
82
82
  return {
83
83
  ...column,
@@ -91,16 +91,15 @@ const ResizeHandlers = _ref => {
91
91
  }
92
92
  return column;
93
93
  });
94
- setColumn(updatedColumn);
94
+ setColumnWidthList(updatedColumnWidthList);
95
95
  };
96
96
  const onMouseUp = event => {
97
97
  event.preventDefault();
98
98
  if (adjustingCell === null) return;
99
- const newColumn = column.map(column => ({
99
+ const newColumn = columnWidthList.map(column => ({
100
100
  ...column,
101
101
  left: column.width
102
102
  }));
103
- console.log(3333, newColumn);
104
103
  handleResizeColumn(newColumn);
105
104
  (0, _helper.updateColumnWidth)(editor, element, newColumn);
106
105
  setIsDraggingResizeHandler(false);
@@ -118,12 +117,12 @@ const ResizeHandlers = _ref => {
118
117
  'mouseleave': onMouseUp
119
118
  });
120
119
  };
121
- }, [handleResizeColumn, column, isDraggingResizeHandler, isMouseNearBorder]);
120
+ }, [handleResizeColumn, columnWidthList, isDraggingResizeHandler, isMouseNearBorder]);
122
121
  let leftAccumulator = 0;
123
122
  return /*#__PURE__*/_react.default.createElement("div", {
124
123
  className: "column-resize-handler",
125
124
  contentEditable: false
126
- }, column.map((column, index) => {
125
+ }, columnWidthList.map((column, index) => {
127
126
  leftAccumulator += column.width;
128
127
  const left = leftAccumulator;
129
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.3",
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",