@seafile/sdoc-editor 0.1.70 → 0.1.72

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.
@@ -1,8 +1,8 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
- import { Editable, Slate } from '@seafile/slate-react';
3
+ import { Editable, ReactEditor, Slate } from '@seafile/slate-react';
4
4
  import defaultEditor, { renderLeaf, renderElement, Toolbar, ContextMenu } from './extension';
5
- import { focusEditor } from './extension/core';
5
+ import { focusEditor, getNextNode, getPrevNode, isSelectionAtBlockEnd, isSelectionAtBlockStart } from './extension/core';
6
6
  import { withSocketIO } from './socket';
7
7
  import withNodeId from './node-id';
8
8
  import SDocOutline from './outline';
@@ -16,6 +16,7 @@ import { ScrollContext } from './hooks/use-scroll-context';
16
16
  import CommentContextProvider from './comment/comment-context-provider';
17
17
  import CommentWrapper from './comment';
18
18
  import { usePipDecorate } from './decorates';
19
+ import { getCursorPosition, getDomHeight } from './utils/dom-utils';
19
20
  import './assets/css/layout.css';
20
21
  import './assets/css/sdoc-editor-plugins.css';
21
22
  var SDocEditor = function SDocEditor(_ref) {
@@ -100,6 +101,44 @@ var SDocEditor = function SDocEditor(_ref) {
100
101
  }
101
102
  // eslint-disable-next-line react-hooks/exhaustive-deps
102
103
  }, []);
104
+ var onKeyDown = useCallback(function (event) {
105
+ var _scrollRef$current = scrollRef.current,
106
+ scrollTop = _scrollRef$current.scrollTop,
107
+ clientHeight = _scrollRef$current.clientHeight;
108
+ if (event.key === 'ArrowLeft') {
109
+ if (!isSelectionAtBlockStart(editor)) return;
110
+ }
111
+ if (event.key === 'ArrowUp' || event.key === 'ArrowLeft') {
112
+ if (scrollTop === 0) return;
113
+ var prevNode = getPrevNode(editor);
114
+ if (!prevNode) return;
115
+ var domNode = ReactEditor.toDOMNode(editor, prevNode[0]);
116
+ var domHeight = getDomHeight(domNode);
117
+ var isScrollUp = true;
118
+ var _getCursorPosition = getCursorPosition(isScrollUp),
119
+ y = _getCursorPosition.y;
120
+ if (y >= domHeight) return;
121
+ scrollRef.current.scroll(0, Math.max(0, scrollTop - domHeight));
122
+ return;
123
+ }
124
+ if (event.key === 'ArrowRight') {
125
+ if (!isSelectionAtBlockEnd(editor)) return;
126
+ }
127
+ if (event.key === 'ArrowDown' || event.key === 'ArrowRight') {
128
+ var nextNode = getNextNode(editor);
129
+ if (!nextNode) return;
130
+ var _domNode = ReactEditor.toDOMNode(editor, nextNode[0]);
131
+ var _domHeight = getDomHeight(_domNode);
132
+ var _isScrollUp = false;
133
+ var _getCursorPosition2 = getCursorPosition(_isScrollUp),
134
+ _y = _getCursorPosition2.y;
135
+ if (clientHeight - _y >= _domHeight) return;
136
+ scrollRef.current.scroll(0, Math.max(0, scrollTop + _domHeight));
137
+ return;
138
+ }
139
+ eventProxy.onKeyDown(event);
140
+ // eslint-disable-next-line react-hooks/exhaustive-deps
141
+ }, []);
103
142
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
104
143
  className: "sdoc-editor-container"
105
144
  }, /*#__PURE__*/React.createElement(Toolbar, {
@@ -111,8 +150,7 @@ var SDocEditor = function SDocEditor(_ref) {
111
150
  docUuid: config.docUuid
112
151
  }), /*#__PURE__*/React.createElement("div", {
113
152
  ref: scrollRef,
114
- className: "sdoc-editor-article-container",
115
- id: "sdoc-editor-article-container"
153
+ className: "sdoc-editor-article-container"
116
154
  }, /*#__PURE__*/React.createElement(ScrollContext.Provider, {
117
155
  value: {
118
156
  scrollRef: scrollRef
@@ -125,10 +163,10 @@ var SDocEditor = function SDocEditor(_ref) {
125
163
  className: "article",
126
164
  ref: articleRef
127
165
  }, /*#__PURE__*/React.createElement(SetNodeToDecorations, null), /*#__PURE__*/React.createElement(Editable, {
166
+ cursors: cursors,
128
167
  renderElement: renderElement,
129
168
  renderLeaf: renderLeaf,
130
- onKeyDown: eventProxy.onKeyDown,
131
- cursors: cursors,
169
+ onKeyDown: onKeyDown,
132
170
  onContextMenu: onContextMenu,
133
171
  onMouseDown: onMouseDown,
134
172
  decorate: decorate
@@ -216,6 +216,94 @@ export var getAboveBlockNode = function getAboveBlockNode(editor, options) {
216
216
  block: true
217
217
  }));
218
218
  };
219
+ export var getPrevNode = function getPrevNode(editor) {
220
+ var _getAboveNode = getAboveNode(editor, {
221
+ mode: 'lowest',
222
+ match: function match(n) {
223
+ return Element.isElement(n) && Editor.isBlock(editor, n);
224
+ }
225
+ }),
226
+ _getAboveNode2 = _slicedToArray(_getAboveNode, 2),
227
+ lowerNode = _getAboveNode2[0],
228
+ lowerPath = _getAboveNode2[1];
229
+ var _getAboveNode3 = getAboveNode(editor, {
230
+ mode: 'highest',
231
+ match: function match(n) {
232
+ return Element.isElement(n) && Editor.isBlock(editor, n);
233
+ }
234
+ }),
235
+ _getAboveNode4 = _slicedToArray(_getAboveNode3, 2),
236
+ heightNode = _getAboveNode4[0],
237
+ heightPath = _getAboveNode4[1];
238
+ var prevNode = null;
239
+ try {
240
+ prevNode = Editor.previous(editor, {
241
+ at: lowerPath,
242
+ match: function match(n) {
243
+ return Element.isElement(n) && Editor.isBlock(editor, n);
244
+ }
245
+ });
246
+ } catch (error) {
247
+ prevNode = null;
248
+ }
249
+ if (lowerNode.id !== heightNode.id && !prevNode) {
250
+ try {
251
+ prevNode = Editor.previous(editor, {
252
+ at: heightPath,
253
+ match: function match(n) {
254
+ return Element.isElement(n) && Editor.isBlock(editor, n);
255
+ }
256
+ });
257
+ } catch (error) {
258
+ prevNode = null;
259
+ }
260
+ }
261
+ return prevNode;
262
+ };
263
+ export var getNextNode = function getNextNode(editor) {
264
+ var _getAboveNode5 = getAboveNode(editor, {
265
+ mode: 'lowest',
266
+ match: function match(n) {
267
+ return Element.isElement(n) && Editor.isBlock(editor, n);
268
+ }
269
+ }),
270
+ _getAboveNode6 = _slicedToArray(_getAboveNode5, 2),
271
+ lowerNode = _getAboveNode6[0],
272
+ lowerPath = _getAboveNode6[1];
273
+ var _getAboveNode7 = getAboveNode(editor, {
274
+ mode: 'highest',
275
+ match: function match(n) {
276
+ return Element.isElement(n) && Editor.isBlock(editor, n);
277
+ }
278
+ }),
279
+ _getAboveNode8 = _slicedToArray(_getAboveNode7, 2),
280
+ heightNode = _getAboveNode8[0],
281
+ heightPath = _getAboveNode8[1];
282
+ var nextNode = null;
283
+ try {
284
+ nextNode = Editor.next(editor, {
285
+ at: lowerPath,
286
+ match: function match(n) {
287
+ return Element.isElement(n) && Editor.isBlock(editor, n);
288
+ }
289
+ });
290
+ } catch (error) {
291
+ nextNode = null;
292
+ }
293
+ if (lowerNode.id !== heightNode.id && !nextNode) {
294
+ try {
295
+ nextNode = Editor.next(editor, {
296
+ at: heightPath,
297
+ match: function match(n) {
298
+ return Element.isElement(n) && Editor.isBlock(editor, n);
299
+ }
300
+ });
301
+ } catch (error) {
302
+ nextNode = null;
303
+ }
304
+ }
305
+ return nextNode;
306
+ };
219
307
 
220
308
  // find node
221
309
  export var findNode = function findNode(editor, options) {
@@ -362,6 +450,11 @@ export var isSelectionAtBlockStart = function isSelectionAtBlockStart(editor, op
362
450
  if (!path) return false;
363
451
  return isStartPoint(editor, selection.focus, path) || Range.isExpanded(editor.selection) && isStartPoint(editor, selection.anchor, path);
364
452
  };
453
+ export var isSelectionAtBlockEnd = function isSelectionAtBlockEnd(editor, options) {
454
+ var _getAboveBlockNode3, _editor$selection;
455
+ var path = (_getAboveBlockNode3 = getAboveBlockNode(editor, options)) === null || _getAboveBlockNode3 === void 0 ? void 0 : _getAboveBlockNode3[1];
456
+ return !!path && isEndPoint(editor, (_editor$selection = editor.selection) === null || _editor$selection === void 0 ? void 0 : _editor$selection.focus, path);
457
+ };
365
458
  export var isLastNode = function isLastNode(editor, node) {
366
459
  var editorChildren = editor.children || [];
367
460
  var editorChildrenLength = editorChildren.length;
@@ -3,12 +3,15 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
3
  import React, { useCallback, useEffect, useState, useRef } from 'react';
4
4
  import { ReactEditor, useSlateStatic, useReadOnly } from '@seafile/slate-react';
5
5
  import { Transforms } from '@seafile/slate';
6
+ import { useScrollContext } from '../../../hooks/use-scroll-context';
6
7
  import CodeBlockHoverMenu from '../../../../components/code-block-hover-menu';
7
8
  import '../../../assets/css/code-block.css';
8
9
  var CodeBlock = function CodeBlock(_ref) {
9
10
  var codeBlockProps = _ref.codeBlockProps;
10
11
  var readOnly = useReadOnly();
12
+ var editor = useSlateStatic();
11
13
  var codeBlockRef = useRef();
14
+ var scrollRef = useScrollContext();
12
15
  var attributes = codeBlockProps.attributes,
13
16
  children = codeBlockProps.children,
14
17
  element = codeBlockProps.element;
@@ -17,7 +20,6 @@ var CodeBlock = function CodeBlock(_ref) {
17
20
  white_space: 'nowrap'
18
21
  } : _element$style;
19
22
  var white_space = style.white_space;
20
- var editor = useSlateStatic();
21
23
  var _useState = useState({
22
24
  top: '',
23
25
  left: ''
@@ -97,15 +99,12 @@ var CodeBlock = function CodeBlock(_ref) {
97
99
  // eslint-disable-next-line react-hooks/exhaustive-deps
98
100
  }, []);
99
101
  useEffect(function () {
102
+ if (readOnly) return;
100
103
  if (showHoverMenu) {
101
- document.getElementById('sdoc-editor-article-container').addEventListener('scroll', onScroll);
104
+ scrollRef.current && scrollRef.current.addEventListener('scroll', onScroll);
102
105
  } else {
103
- document.getElementById('sdoc-editor-article-container').removeEventListener('scroll', onScroll);
106
+ scrollRef.current && scrollRef.current.removeEventListener('scroll', onScroll);
104
107
  }
105
- return function () {
106
- var articleContainer = document.getElementById('sdoc-editor-article-container');
107
- articleContainer && articleContainer.removeEventListener('scroll', onScroll);
108
- };
109
108
  // eslint-disable-next-line react-hooks/exhaustive-deps
110
109
  }, [showHoverMenu]);
111
110
  return /*#__PURE__*/React.createElement("div", {
@@ -1,27 +1,54 @@
1
1
  import slugid from 'slugid';
2
2
  import { CODE_BLOCK, CODE_LINE } from '../../../constants';
3
+ import { genCodeLangs } from '../../../../utils/prismjs';
3
4
  var codeBlockRule = function codeBlockRule(element, parseChild) {
4
5
  var nodeName = element.nodeName,
5
6
  childNodes = element.childNodes;
6
7
  if (nodeName === 'PRE') {
8
+ var children = Array.from(childNodes).filter(function (item) {
9
+ return item.nodeName === 'CODE';
10
+ });
11
+ var codeChild = children[0];
12
+ var lang = codeChild.getAttribute('lang');
13
+ lang = genCodeLangs().find(function (item) {
14
+ return item.value === lang;
15
+ }) || 'plaintext';
7
16
  return {
8
17
  level: 'level1',
9
18
  id: slugid.nice(),
19
+ language: lang,
10
20
  type: CODE_BLOCK,
11
- children: parseChild(childNodes)
21
+ children: parseChild(children)
12
22
  };
13
23
  }
14
24
  if (nodeName === 'CODE' && element.parentElement.nodeName === 'PRE') {
15
- return {
16
- level: 'level2',
17
- id: slugid.nice(),
18
- type: CODE_LINE,
19
- children: [{
20
- level: 'level3',
25
+ var content = element.textContent;
26
+ var hasNewLine = content.indexOf('\n') > -1;
27
+ if (!hasNewLine) {
28
+ return {
29
+ level: 'level2',
21
30
  id: slugid.nice(),
22
- text: element.textContent
23
- }]
24
- };
31
+ type: CODE_LINE,
32
+ children: [{
33
+ level: 'level3',
34
+ id: slugid.nice(),
35
+ text: element.textContent
36
+ }]
37
+ };
38
+ }
39
+ var codes = content.split('\n');
40
+ return codes.map(function (item) {
41
+ return {
42
+ level: 'level2',
43
+ id: slugid.nice(),
44
+ type: CODE_LINE,
45
+ children: [{
46
+ level: 'level3',
47
+ id: slugid.nice(),
48
+ text: item
49
+ }]
50
+ };
51
+ });
25
52
  }
26
53
  return;
27
54
  };
@@ -34,6 +34,7 @@ var listRule = function listRule(element, parseChild) {
34
34
  id: slugid.nice(),
35
35
  type: LIST_ITEM,
36
36
  children: [{
37
+ id: slugid.nice(),
37
38
  level: 'level3',
38
39
  type: LIST_LIC,
39
40
  children: parseChild(childNodes)
@@ -0,0 +1,116 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import React, { useRef, useState, useEffect, useCallback } from 'react';
4
+ import { Transforms } from '@seafile/slate';
5
+ import { useSlateStatic } from '@seafile/slate-react';
6
+ import classnames from 'classnames';
7
+ import { useTableRootContext } from '../hooks';
8
+ import { TABLE_CELL_MIN_WIDTH } from '../../constants';
9
+ import { getTableColumns, updateColumnWidth } from '../../helpers';
10
+ import { eventStopPropagation, getMouseDownInfo, getMouseMoveInfo, registerResizeEvents, unregisterResizeEvents } from '../../../../../utils/mouse-event';
11
+ var FirstColumnResizeHandler = function FirstColumnResizeHandler(_ref) {
12
+ var column = _ref.column,
13
+ initLeft = _ref.left,
14
+ element = _ref.element,
15
+ index = _ref.index;
16
+ var editor = useSlateStatic();
17
+ var resizeHandler = useRef(null);
18
+ var _useState = useState(initLeft),
19
+ _useState2 = _slicedToArray(_useState, 2),
20
+ left = _useState2[0],
21
+ setLeft = _useState2[1];
22
+ var _useState3 = useState(false),
23
+ _useState4 = _slicedToArray(_useState3, 2),
24
+ isResizing = _useState4[0],
25
+ setIsResizing = _useState4[1];
26
+ var _useState5 = useState({}),
27
+ _useState6 = _slicedToArray(_useState5, 2),
28
+ mouseDownInfo = _useState6[0],
29
+ setMouseDownInfo = _useState6[1];
30
+ var _useState7 = useState({}),
31
+ _useState8 = _slicedToArray(_useState7, 2),
32
+ style = _useState8[0],
33
+ setStyle = _useState8[1];
34
+ var width = column.width;
35
+ var tableRootScrollContainer = useTableRootContext();
36
+ var onMouseDown = useCallback(function (event) {
37
+ eventStopPropagation(event);
38
+ Transforms.deselect(editor);
39
+ var mouseDownInfo = getMouseDownInfo(event, tableRootScrollContainer);
40
+ var _tableRootScrollConta = tableRootScrollContainer.getBoundingClientRect(),
41
+ top = _tableRootScrollConta.top;
42
+ setStyle({
43
+ left: mouseDownInfo.positionX - 2,
44
+ height: tableRootScrollContainer.clientHeight,
45
+ top: top
46
+ });
47
+ setMouseDownInfo(mouseDownInfo);
48
+ setIsResizing(true);
49
+
50
+ // eslint-disable-next-line react-hooks/exhaustive-deps
51
+ }, [tableRootScrollContainer]);
52
+ useEffect(function () {
53
+ if (!isResizing) {
54
+ if (initLeft !== left) {
55
+ setLeft(initLeft);
56
+ }
57
+ return;
58
+ }
59
+ var onMouseMove = function onMouseMove(event) {
60
+ eventStopPropagation(event);
61
+ var mouseMoveInfo = getMouseMoveInfo(event, mouseDownInfo, tableRootScrollContainer);
62
+ var newWidth = width - mouseMoveInfo.displacementX;
63
+ if (newWidth < TABLE_CELL_MIN_WIDTH) return;
64
+ var left = initLeft - mouseMoveInfo.displacementX;
65
+ var _tableRootScrollConta2 = tableRootScrollContainer.getBoundingClientRect(),
66
+ top = _tableRootScrollConta2.top;
67
+ setStyle({
68
+ left: event.clientX - 2,
69
+ height: tableRootScrollContainer.clientHeight,
70
+ top: top
71
+ });
72
+ setLeft(left);
73
+ };
74
+ var onMouseUp = function onMouseUp(event) {
75
+ eventStopPropagation(event);
76
+ setIsResizing(false);
77
+ setStyle({});
78
+ var columns = getTableColumns(editor, element);
79
+ var newColumns = columns.slice(0);
80
+ var column = newColumns[index];
81
+ var newWidth = width + left - initLeft;
82
+ newColumns[index] = _objectSpread(_objectSpread({}, column), {}, {
83
+ width: newWidth
84
+ });
85
+ updateColumnWidth(editor, element, newColumns);
86
+ };
87
+ registerResizeEvents({
88
+ 'mousemove': onMouseMove,
89
+ 'mouseup': onMouseUp
90
+ });
91
+ return function () {
92
+ unregisterResizeEvents({
93
+ 'mousemove': onMouseMove,
94
+ 'mouseup': onMouseUp
95
+ });
96
+ };
97
+
98
+ // eslint-disable-next-line react-hooks/exhaustive-deps
99
+ }, [isResizing, mouseDownInfo, left, width, column, editor, element, index, initLeft]);
100
+ return /*#__PURE__*/React.createElement("div", {
101
+ className: classnames('table-cell-width-just ', {
102
+ 'resizing position-fixed': isResizing,
103
+ 'position-absolute': !isResizing
104
+ }),
105
+ contentEditable: false,
106
+ style: isResizing ? style : {
107
+ left: -3.5,
108
+ top: 0
109
+ },
110
+ onMouseDown: onMouseDown,
111
+ ref: resizeHandler
112
+ }, /*#__PURE__*/React.createElement("div", {
113
+ className: "table-cell-width-just-color-tip"
114
+ }));
115
+ };
116
+ export default FirstColumnResizeHandler;
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
2
  import { useSlateStatic } from '@seafile/slate-react';
3
+ import FirstColumnResizeHandler from './first-column-left-resize-handler';
3
4
  import ResizeHandler from './resize-handler';
4
- import { getNode, findPath } from '../../../core';
5
- import { useResizeHandlersContext } from './hooks';
6
- import { getTableColumns } from '../helpers';
5
+ import { getNode, findPath } from '../../../../core';
6
+ import { useResizeHandlersContext } from '../hooks';
7
+ import { getTableColumns } from '../../helpers';
7
8
  var ResizeHandlers = function ResizeHandlers(props) {
8
9
  var element = props.element;
9
10
  var editor = useSlateStatic();
@@ -13,7 +14,13 @@ var ResizeHandlers = function ResizeHandlers(props) {
13
14
  var table = getNode(editor, tablePath);
14
15
  if (!table) return null;
15
16
  var columnLeft = 0;
16
- return /*#__PURE__*/React.createElement(React.Fragment, null, columns.map(function (column, columnIndex) {
17
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FirstColumnResizeHandler, {
18
+ key: "column-0-left",
19
+ column: columns[0],
20
+ left: 0,
21
+ index: 0,
22
+ element: element
23
+ }), columns.map(function (column, columnIndex) {
17
24
  columnLeft = columnLeft + column.width;
18
25
  return /*#__PURE__*/React.createElement(ResizeHandler, {
19
26
  key: columnIndex,
@@ -4,10 +4,10 @@ import React, { useRef, useState, useEffect, useCallback } from 'react';
4
4
  import { Transforms } from '@seafile/slate';
5
5
  import { useSlateStatic } from '@seafile/slate-react';
6
6
  import classnames from 'classnames';
7
- import { useTableRootContext } from './hooks';
8
- import { TABLE_CELL_MIN_WIDTH } from '../constants';
9
- import { getTableColumns, updateColumnWidth } from '../helpers';
10
- import { eventStopPropagation, getMouseDownInfo, getMouseMoveInfo, registerResizeEvents, unregisterResizeEvents } from '../../../../utils/mouse-event';
7
+ import { useTableRootContext } from '../hooks';
8
+ import { TABLE_CELL_MIN_WIDTH } from '../../constants';
9
+ import { getTableColumns, updateColumnWidth } from '../../helpers';
10
+ import { eventStopPropagation, getMouseDownInfo, getMouseMoveInfo, registerResizeEvents, unregisterResizeEvents } from '../../../../../utils/mouse-event';
11
11
  var ResizeHandler = function ResizeHandler(_ref) {
12
12
  var column = _ref.column,
13
13
  initLeft = _ref.left,
@@ -27,17 +27,28 @@ var ResizeHandler = function ResizeHandler(_ref) {
27
27
  _useState6 = _slicedToArray(_useState5, 2),
28
28
  mouseDownInfo = _useState6[0],
29
29
  setMouseDownInfo = _useState6[1];
30
+ var _useState7 = useState({}),
31
+ _useState8 = _slicedToArray(_useState7, 2),
32
+ style = _useState8[0],
33
+ setStyle = _useState8[1];
30
34
  var width = column.width;
31
35
  var tableRootScrollContainer = useTableRootContext();
32
36
  var onMouseDown = useCallback(function (event) {
33
37
  eventStopPropagation(event);
34
38
  Transforms.deselect(editor);
35
39
  var mouseDownInfo = getMouseDownInfo(event, tableRootScrollContainer);
40
+ var _tableRootScrollConta = tableRootScrollContainer.getBoundingClientRect(),
41
+ top = _tableRootScrollConta.top;
42
+ setStyle({
43
+ left: mouseDownInfo.positionX - 2,
44
+ height: tableRootScrollContainer.clientHeight,
45
+ top: top
46
+ });
36
47
  setMouseDownInfo(mouseDownInfo);
37
48
  setIsResizing(true);
38
49
 
39
50
  // eslint-disable-next-line react-hooks/exhaustive-deps
40
- }, []);
51
+ }, [tableRootScrollContainer]);
41
52
  useEffect(function () {
42
53
  if (!isResizing) {
43
54
  if (initLeft !== left) {
@@ -49,19 +60,27 @@ var ResizeHandler = function ResizeHandler(_ref) {
49
60
  eventStopPropagation(event);
50
61
  var mouseMoveInfo = getMouseMoveInfo(event, mouseDownInfo, tableRootScrollContainer);
51
62
  var newWidth = width + mouseMoveInfo.displacementX;
52
- if (newWidth < TABLE_CELL_MIN_WIDTH) return;
53
63
  var columns = getTableColumns(editor, element);
64
+ if (newWidth < TABLE_CELL_MIN_WIDTH) return;
54
65
  var nextColumn = columns[index + 1];
55
66
  if (nextColumn) {
56
67
  var nextColumnWidth = nextColumn.width - mouseMoveInfo.displacementX;
57
68
  if (nextColumnWidth < TABLE_CELL_MIN_WIDTH) return;
58
69
  }
59
70
  var left = initLeft + mouseMoveInfo.displacementX;
71
+ var _tableRootScrollConta2 = tableRootScrollContainer.getBoundingClientRect(),
72
+ top = _tableRootScrollConta2.top;
73
+ setStyle({
74
+ left: event.clientX - 2,
75
+ height: tableRootScrollContainer.clientHeight,
76
+ top: top
77
+ });
60
78
  setLeft(left);
61
79
  };
62
80
  var onMouseUp = function onMouseUp(event) {
63
81
  eventStopPropagation(event);
64
82
  setIsResizing(false);
83
+ setStyle({});
65
84
  var columns = getTableColumns(editor, element);
66
85
  var newColumns = columns.slice(0);
67
86
  var column = newColumns[index];
@@ -92,11 +111,12 @@ var ResizeHandler = function ResizeHandler(_ref) {
92
111
  // eslint-disable-next-line react-hooks/exhaustive-deps
93
112
  }, [isResizing, mouseDownInfo, left, width, column, editor, element, index, initLeft]);
94
113
  return /*#__PURE__*/React.createElement("div", {
95
- className: classnames('table-cell-width-just position-absolute', {
96
- 'resizing': isResizing
114
+ className: classnames('table-cell-width-just ', {
115
+ 'resizing position-fixed': isResizing,
116
+ 'position-absolute': !isResizing
97
117
  }),
98
118
  contentEditable: false,
99
- style: {
119
+ style: isResizing ? style : {
100
120
  left: left - 3.5,
101
121
  top: 0
102
122
  },
@@ -0,0 +1,40 @@
1
+ export var getDomHeight = function getDomHeight(dom) {
2
+ var styles = window.getComputedStyle(dom);
3
+ var rect = dom.getBoundingClientRect();
4
+ var marginTop = styles['marginTop'];
5
+ // margin-bottom overlaps margin-top
6
+ // const marginBottom = styles['marginBottom'];
7
+ var height = rect.height;
8
+ return height + parseInt(marginTop);
9
+ };
10
+ export var getSelectionRange = function getSelectionRange() {
11
+ if (window.getSelection) {
12
+ var sel = window.getSelection();
13
+ if (sel.getRangeAt && sel.rangeCount) {
14
+ return sel.getRangeAt(0);
15
+ }
16
+ } else if (document.selection && document.selection.createRange) {
17
+ return document.selection.createRange();
18
+ }
19
+ return null;
20
+ };
21
+ export var getCursorPosition = function getCursorPosition() {
22
+ var isScrollUp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
23
+ var x = 0,
24
+ y = 0;
25
+ var range = getSelectionRange();
26
+ if (range) {
27
+ var rect = range.getBoundingClientRect();
28
+ var headerHeight = 100;
29
+ x = rect.x || 0;
30
+ if (isScrollUp) {
31
+ y = rect.y - headerHeight;
32
+ } else {
33
+ y = rect.y - headerHeight + rect.height;
34
+ }
35
+ }
36
+ return {
37
+ x: x,
38
+ y: y
39
+ };
40
+ };
@@ -47,8 +47,8 @@ export var getMouseMoveInfo = function getMouseMoveInfo(event, mouseDownInfo, sc
47
47
  var scrollLeft = 0;
48
48
  var scrollTop = 0;
49
49
  if (scrollContainer) {
50
- scrollLeft = scrollContainer.scrollLeft;
51
- scrollTop = scrollContainer.scrollTop;
50
+ scrollLeft = scrollContainer.scrollLeft || 0;
51
+ scrollTop = scrollContainer.scrollTop || 0;
52
52
  }
53
53
  displacementX = currPositionX - mouseDownInfo.positionX + scrollLeft - (mouseDownInfo.scrollLeft || 0);
54
54
  displacementY = currPositionY - mouseDownInfo.positionY + scrollTop - (mouseDownInfo.scrollTop || 0);
@@ -1,30 +1,21 @@
1
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
- import React, { useRef, useEffect, useState } from 'react';
1
+ import React, { useRef, useEffect } from 'react';
3
2
  import { Editable, Slate } from '@seafile/slate-react';
4
3
  import defaultEditor, { renderLeaf as _renderLeaf, renderElement as _renderElement } from '../extension';
5
- import { withSocketIO } from '../socket';
6
4
  import withNodeId from '../node-id';
5
+ import { ScrollContext } from '../hooks/use-scroll-context';
6
+ import { generateDefaultDocContent } from '../../utils';
7
7
  import '../assets/css/layout.css';
8
8
  import '../assets/css/sdoc-editor-plugins.css';
9
- import { generateDefaultDocContent } from '../../utils';
10
9
  var SDocViewer = function SDocViewer(_ref) {
11
- var isOpenSocket = _ref.isOpenSocket,
12
- document = _ref.document,
13
- config = _ref.config,
10
+ var document = _ref.document,
14
11
  customRenderLeaf = _ref.renderLeaf,
15
12
  customRenderElement = _ref.renderElement;
16
- var editor = !isOpenSocket ? withNodeId(defaultEditor) : withSocketIO(withNodeId(defaultEditor, {
17
- document: document,
18
- config: config
19
- }));
13
+ var editor = withNodeId(defaultEditor);
20
14
  var slateValue = (document || generateDefaultDocContent()).children;
21
15
  var articleRef = useRef(null);
22
- var _useState = useState(false),
23
- _useState2 = _slicedToArray(_useState, 2),
24
- setUpdate = _useState2[1];
16
+ var scrollRef = useRef(null);
25
17
  useEffect(function () {
26
18
  editor.width = articleRef.current.children[0].clientWidth;
27
- setUpdate(true);
28
19
  // eslint-disable-next-line react-hooks/exhaustive-deps
29
20
  }, []);
30
21
  return /*#__PURE__*/React.createElement("div", {
@@ -32,12 +23,15 @@ var SDocViewer = function SDocViewer(_ref) {
32
23
  }, /*#__PURE__*/React.createElement("div", {
33
24
  className: "sdoc-editor-content"
34
25
  }, /*#__PURE__*/React.createElement("div", {
35
- className: "flex-fill o-auto sdoc-editor-article-container",
36
- id: "sdoc-editor-article-container"
26
+ ref: scrollRef,
27
+ className: "sdoc-editor-article-container"
28
+ }, /*#__PURE__*/React.createElement(ScrollContext.Provider, {
29
+ value: {
30
+ scrollRef: scrollRef
31
+ }
37
32
  }, /*#__PURE__*/React.createElement(Slate, {
38
33
  editor: editor,
39
- value: slateValue,
40
- onChange: function onChange() {}
34
+ value: slateValue
41
35
  }, /*#__PURE__*/React.createElement("div", {
42
36
  className: "article mx-auto",
43
37
  ref: articleRef
@@ -51,6 +45,6 @@ var SDocViewer = function SDocViewer(_ref) {
51
45
  return (customRenderLeaf || _renderLeaf)(props, editor);
52
46
  },
53
47
  onDOMBeforeInput: function onDOMBeforeInput(event) {}
54
- }))))));
48
+ })))))));
55
49
  };
56
50
  export default SDocViewer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.70",
3
+ "version": "0.1.72",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",