@seafile/sdoc-editor 0.4.35 → 0.4.36

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.
Files changed (26) hide show
  1. package/dist/basic-sdk/comment/components/global-comment/index.js +1 -2
  2. package/dist/basic-sdk/comment/helper.js +2 -2
  3. package/dist/basic-sdk/comment/utils/index.js +3 -1
  4. package/dist/basic-sdk/editor/editable-article.js +1 -1
  5. package/dist/basic-sdk/editor/sdoc-editor.js +1 -2
  6. package/dist/basic-sdk/extension/commons/history-files/index.js +13 -1
  7. package/dist/basic-sdk/extension/constants/font.js +1 -0
  8. package/dist/basic-sdk/extension/constants/index.js +1 -0
  9. package/dist/basic-sdk/extension/plugins/callout/render-elem/index.js +2 -0
  10. package/dist/basic-sdk/extension/plugins/code-block/helpers.js +4 -2
  11. package/dist/basic-sdk/extension/plugins/code-block/render-elem.js +2 -0
  12. package/dist/basic-sdk/extension/plugins/file-link/helpers.js +1 -0
  13. package/dist/basic-sdk/extension/plugins/html/helper.js +1 -0
  14. package/dist/basic-sdk/extension/plugins/image/hover-menu/index.js +3 -3
  15. package/dist/basic-sdk/extension/plugins/link/helpers.js +1 -0
  16. package/dist/basic-sdk/extension/plugins/sdoc-link/helpers.js +1 -1
  17. package/dist/basic-sdk/extension/plugins/table/helpers.js +1 -0
  18. package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +6 -7
  19. package/dist/basic-sdk/extension/plugins/table/render/resize-handlers/column-resize-handler.js +1 -1
  20. package/dist/basic-sdk/extension/plugins/table/render/resize-handlers/row-resize-handler.js +2 -3
  21. package/dist/basic-sdk/extension/plugins/table/render/table-header/rows-header/row-header.js +1 -1
  22. package/dist/basic-sdk/extension/toolbar/side-toolbar/helpers.js +1 -0
  23. package/dist/basic-sdk/utils/dom-utils.js +2 -2
  24. package/dist/utils/get-event-transfer.js +3 -1
  25. package/dist/utils/index.js +6 -6
  26. package/package.json +1 -1
@@ -1,8 +1,7 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import React, { useCallback, useEffect, useRef, useState } from 'react';
3
3
  import dayjs from 'dayjs';
4
- import { useSlateStatic } from '@seafile/slate-react';
5
- import { ReactEditor } from '@seafile/slate-react';
4
+ import { useSlateStatic, ReactEditor } from '@seafile/slate-react';
6
5
  import { ElementPopover } from '../../../extension/commons';
7
6
  import EventBus from '../../../utils/event-bus';
8
7
  import useCommentList from '../../hooks/comment-hooks/use-comment-list';
@@ -13,8 +13,8 @@ export const getSelectionRange = () => {
13
13
  return null;
14
14
  };
15
15
  export const getCursorPosition = () => {
16
- let x = 0,
17
- y = 0;
16
+ let x = 0;
17
+ let y = 0;
18
18
  let range = getSelectionRange();
19
19
  if (range) {
20
20
  const rect = range.getBoundingClientRect();
@@ -100,7 +100,9 @@ class CommentUtilities {
100
100
  content,
101
101
  nodeType
102
102
  } = _ref2;
103
- let spanNode1, spanNode2, imageContainer;
103
+ let spanNode1;
104
+ let spanNode2;
105
+ let imageContainer;
104
106
  if (nodeType === 'image') {
105
107
  spanNode1 = document.createElement('div');
106
108
  spanNode1.className = 'image-container';
@@ -154,7 +154,7 @@ const EditableArticle = _ref => {
154
154
  block: 'nearest'
155
155
  });
156
156
  } catch (error) {
157
- //
157
+ //
158
158
  }
159
159
  }, []);
160
160
  return /*#__PURE__*/React.createElement(Slate, {
@@ -5,7 +5,7 @@ import deepCopy from 'deep-copy';
5
5
  import context from '../../context';
6
6
  import CommonLoading from '../../components/common-loading';
7
7
  import { INTERNAL_EVENT, PAGE_EDIT_AREA_WIDTH } from '../constants';
8
- import { createDefaultEditor } from '../extension';
8
+ import { createDefaultEditor, HeaderToolbar } from '../extension';
9
9
  import withNodeId from '../node-id';
10
10
  import { withSocketIO } from '../socket';
11
11
  import { focusEditor } from '../extension/core';
@@ -13,7 +13,6 @@ import InsertElementDialog from '../extension/commons/insert-element-dialog';
13
13
  import { EditorContainer, EditorContent } from '../layout';
14
14
  import EditableArticle from './editable-article';
15
15
  import { ColorProvider } from '../hooks/use-color-context';
16
- import { HeaderToolbar } from '../extension';
17
16
  import ReadOnlyArticle from '../views/readonly-article';
18
17
  import { isMobile } from '../../utils';
19
18
  import { CollaboratorsProvider } from '../../hooks';
@@ -8,6 +8,7 @@ import debounce from 'lodash.debounce';
8
8
  import toaster from '../../../../components/toast';
9
9
  import EventBus from '../../../utils/event-bus';
10
10
  import context from '../../../../context';
11
+ import { focusEditor } from '../../core';
11
12
  import { insertSdocFileLink } from '../../plugins/sdoc-link/helpers';
12
13
  import { LocalStorage, isEnglish } from '../../../../utils';
13
14
  import { INTERNAL_EVENT } from '../../../constants';
@@ -83,6 +84,16 @@ const HistoryFiles = _ref => {
83
84
  };
84
85
  // eslint-disable-next-line react-hooks/exhaustive-deps
85
86
  }, []);
87
+ const onKeydown = useCallback(e => {
88
+ const {
89
+ key,
90
+ target
91
+ } = e;
92
+ if (key === 'Backspace' && !target.selectionStart && !target.selectionEnd && !target.value) {
93
+ focusEditor(editor);
94
+ closeDialog();
95
+ }
96
+ }, [closeDialog, editor]);
86
97
  const onCompositionStart = e => {
87
98
  e.stopPropagation();
88
99
  historyFilesInputRef.current.typing = true;
@@ -167,7 +178,8 @@ const HistoryFiles = _ref => {
167
178
  autoComplete: "off",
168
179
  onChange: debounce(onSearch, 200),
169
180
  onCompositionStart: onCompositionStart,
170
- onCompositionEnd: onCompositionEnd
181
+ onCompositionEnd: onCompositionEnd,
182
+ onKeyDown: onKeydown
171
183
  }), /*#__PURE__*/React.createElement("div", {
172
184
  className: "sdoc-history-files-content"
173
185
  }, header.length !== 0 && /*#__PURE__*/React.createElement("div", {
@@ -517,6 +517,7 @@ export const FONT = [
517
517
  }
518
518
  } // 楷体
519
519
  ];
520
+
520
521
  export const SDOC_FONT_SIZE = {
521
522
  DEFAULT: 11,
522
523
  [ELEMENT_TYPE.TITLE]: 26,
@@ -1,5 +1,6 @@
1
1
  // extension plugin
2
2
  import * as ELEMENT_TYPE from './element-type';
3
+ // eslint-disable-next-line no-duplicate-imports
3
4
  import { BLOCKQUOTE, TITLE, SUBTITLE, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, PARAGRAPH, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, CHECK_LIST_ITEM, CODE_BLOCK, CODE_LINE, TABLE, TABLE_CELL, TABLE_ROW, LINK, SDOC_LINK, FILE_LINK, IMAGE, IMAGE_BLOCK, TOP_LEVEL_TYPES, INLINE_LEVEL_TYPES, CALL_OUT } from './element-type';
4
5
  export { DEFAULT_COLORS, STANDARD_COLORS, DEFAULT_RECENT_USED_LIST, DEFAULT_FONT_COLOR, RECENT_USED_HIGHLIGHT_COLORS_KEY, RECENT_USED_FONT_COLORS_KEY, RECENT_USED_TABLE_CELL_BACKGROUND_COLORS_KEY, DEFAULT_LAST_USED_FONT_COLOR, DEFAULT_LAST_USED_HIGHLIGHT_COLOR, DEFAULT_LAST_USED_TABLE_CELL_BACKGROUND_COLOR } from './color';
5
6
  export { FONT_SIZE, DEFAULT_FONT, FONT, GOOGLE_FONT_CLASS, RECENT_USED_FONTS_KEY, SDOC_FONT_SIZE } from './font';
@@ -72,6 +72,7 @@ const renderCallout = (_ref, editor) => {
72
72
  top: menuTop,
73
73
  left: left // left = code-block left distance
74
74
  };
75
+
75
76
  setPopoverPosition(newMenuPosition);
76
77
  }
77
78
  }, [isShowColorSelector, readOnly]);
@@ -107,6 +108,7 @@ const renderCallout = (_ref, editor) => {
107
108
  top: menuTop,
108
109
  left: left // left = callout left distance
109
110
  };
111
+
110
112
  setPopoverPosition(newMenuPosition);
111
113
  setIsShowColorSelector(true);
112
114
  }, [readOnly]);
@@ -23,6 +23,7 @@ export const isMenuDisabled = (editor, readonly) => {
23
23
  if (isMatch) return false; // enable
24
24
  return true; // disable
25
25
  };
26
+
26
27
  export const getSelectCodeElem = editor => {
27
28
  const codeNode = getSelectedNodeByType(editor, CODE_BLOCK);
28
29
  if (codeNode == null) return null;
@@ -32,8 +33,8 @@ export const changeToCodeBlock = function (editor) {
32
33
  let language = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
33
34
  let position = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : INSERT_POSITION.CURRENT;
34
35
  // Summarizes the strings for the selected highest-level node
35
- let strArr = [],
36
- path = Editor.path(editor, editor.selection);
36
+ let strArr = [];
37
+ let path = Editor.path(editor, editor.selection);
37
38
  if (position === INSERT_POSITION.AFTER) {
38
39
  strArr = [''];
39
40
  } else {
@@ -62,6 +63,7 @@ export const changeToCodeBlock = function (editor) {
62
63
  style: {
63
64
  white_space: 'nowrap' // default nowrap
64
65
  },
66
+
65
67
  children: [{
66
68
  id: slugid.nice(),
67
69
  type: CODE_LINE,
@@ -81,6 +81,7 @@ const CodeBlock = _ref => {
81
81
  top: menuTop,
82
82
  left: left // left = code-block left distance
83
83
  };
84
+
84
85
  setMenuPosition(newMenuPosition);
85
86
  }
86
87
  setShowHoverMenu(true);
@@ -104,6 +105,7 @@ const CodeBlock = _ref => {
104
105
  top: menuTop,
105
106
  left: left // left = code-block left distance
106
107
  };
108
+
107
109
  setMenuPosition(newMenuPosition);
108
110
  }
109
111
  }, [readOnly, showHoverMenu]);
@@ -20,6 +20,7 @@ export const isMenuDisabled = (editor, readonly) => {
20
20
  if (notMatch) return true; // disabled
21
21
  return false; // enable
22
22
  };
23
+
23
24
  export const generateFileNode = (uuid, text) => {
24
25
  const fileNode = {
25
26
  id: slugid.nice(),
@@ -68,6 +68,7 @@ const deserializeElements = function () {
68
68
  // nothing todo
69
69
  }
70
70
  });
71
+
71
72
  return nodes;
72
73
  };
73
74
  const formatElementNodes = nodes => {
@@ -71,9 +71,9 @@ const ImageHoverMenu = _ref => {
71
71
  const beforeLeaf = newNodeEntry[0].children.slice(0, index);
72
72
  const imageLeaf = newNodeEntry[0].children.slice(index, index + 1);
73
73
  const afterLeaf = newNodeEntry[0].children.slice(index + 1);
74
- let beforeNode = null,
75
- centerNode = null,
76
- afterNode = null;
74
+ let beforeNode = null;
75
+ let centerNode = null;
76
+ let afterNode = null;
77
77
  let p = path[0];
78
78
  if (!beforeLeaf.every(item => {
79
79
  var _item$text;
@@ -19,6 +19,7 @@ export const isMenuDisabled = (editor, readonly) => {
19
19
  if (notMatch) return true; // disabled
20
20
  return false; // enable
21
21
  };
22
+
22
23
  export const checkLink = url => {
23
24
  if (url.indexOf('http') !== 0) {
24
25
  return true;
@@ -5,7 +5,6 @@ import slugid from 'slugid';
5
5
  import copy from 'copy-to-clipboard';
6
6
  import context from '../../../../context';
7
7
  import { focusEditor, getNodeType, getSelectedElems } from '../../core';
8
- import { LocalStorage } from '../../../../utils';
9
8
  import { SDOC_LINK, LINK, INSERT_FILE_DISPLAY_TYPE, CODE_BLOCK, CODE_LINE, PARAGRAPH } from '../../constants';
10
9
  export const isMenuDisabled = (editor, readonly) => {
11
10
  if (readonly) return true;
@@ -22,6 +21,7 @@ export const isMenuDisabled = (editor, readonly) => {
22
21
  if (notMatch) return true; // disabled
23
22
  return false; // enable
24
23
  };
24
+
25
25
  export const generateSdocFileNode = (uuid, text) => {
26
26
  const sdocFileNode = {
27
27
  id: slugid.nice(),
@@ -175,6 +175,7 @@ export const isAllInTable = editor => {
175
175
  if (firstSelectedNode.type !== ELEMENT_TYPE.TABLE) return false;
176
176
  return selectedNodes.slice(1).every(node => [ELEMENT_TYPE.TABLE_ROW, ELEMENT_TYPE.TABLE_CELL].includes(node.type)); // same table element
177
177
  };
178
+
178
179
  export const setCellStyle = (editor, style) => {
179
180
  // Select single cell
180
181
  if (ObjectUtils.isSameObject(editor.tableSelectedRange, EMPTY_SELECTED_RANGE)) {
@@ -5,9 +5,9 @@ import { useSlateStatic, useReadOnly } from '@seafile/slate-react';
5
5
  import { Editor, Transforms } from '@seafile/slate';
6
6
  import ObjectUtils from '../../../../utils/object-utils';
7
7
  import { findPath, focusEditor } from '../../../core';
8
- import { useResizeHandlersContext, useTableSelectedRangeContext } from './hooks';
8
+ import { useTableSelectedRangeContext } from './hooks';
9
9
  import { EMPTY_SELECTED_RANGE, SELECTED_TABLE_CELL_BACKGROUND_COLOR, TABLE_CELL_STYLE } from '../constants';
10
- import { getTableColumns, colorBlend, getHighlightClass } from '../helpers';
10
+ import { colorBlend, getHighlightClass } from '../helpers';
11
11
  import EventBus from '../../../../utils/event-bus';
12
12
  import { INTERNAL_EVENT } from '../../../../constants';
13
13
  const TableCell = _ref => {
@@ -19,7 +19,6 @@ const TableCell = _ref => {
19
19
  const editor = useSlateStatic();
20
20
  const selectedRange = useTableSelectedRangeContext() || EMPTY_SELECTED_RANGE;
21
21
  const cellPath = findPath(editor, element, [0, 0]);
22
- const columns = useResizeHandlersContext() || getTableColumns(editor, element);
23
22
  const pathLength = cellPath.length;
24
23
  const rowIndex = cellPath[pathLength - 2];
25
24
  const cellIndex = cellPath[pathLength - 1];
@@ -60,10 +59,10 @@ const TableCell = _ref => {
60
59
  if (element.is_combined) {
61
60
  style.display = 'none';
62
61
  }
63
- if (rowIndex == 0) {
62
+ if (rowIndex === 0) {
64
63
  style.borderTop = '1px solid #ddd';
65
64
  }
66
- if (cellIndex == 0) {
65
+ if (cellIndex === 0) {
67
66
  style.borderLeft = '1px solid #ddd';
68
67
  }
69
68
  const {
@@ -134,10 +133,10 @@ function renderTableCell(props) {
134
133
  if (element.is_combined) {
135
134
  style.display = 'none';
136
135
  }
137
- if (rowIndex == 0) {
136
+ if (rowIndex === 0) {
138
137
  style.borderTop = '1px solid #ddd';
139
138
  }
140
- if (cellIndex == 0) {
139
+ if (cellIndex === 0) {
141
140
  style.borderLeft = '1px solid #ddd';
142
141
  }
143
142
  const {
@@ -1,5 +1,5 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import React, { useRef, useState, useEffect, useCallback, useLayoutEffect } from 'react';
2
+ import React, { useRef, useState, useEffect, useLayoutEffect } from 'react';
3
3
  import { useSlateStatic } from '@seafile/slate-react';
4
4
  import { useTableRootContext } from '../hooks';
5
5
  import { TABLE_CELL_MIN_WIDTH } from '../../constants';
@@ -1,6 +1,5 @@
1
1
  import React, { useEffect, useState, useRef, useLayoutEffect } from 'react';
2
- import { useSlateStatic } from '@seafile/slate-react';
3
- import { ReactEditor } from '@seafile/slate-react';
2
+ import { useSlateStatic, ReactEditor } from '@seafile/slate-react';
4
3
  import { TABLE_ROW_MIN_HEIGHT } from '../../constants';
5
4
  import { focusClosestCellWhenJustifyCellSize, getRowHeight, updateTableRowHeight } from '../../helpers';
6
5
  import { eventStopPropagation, getMouseDownInfo, getMouseMoveInfo, registerResizeEvents, unregisterResizeEvents } from '../../../../../utils/mouse-event';
@@ -65,7 +64,7 @@ const RowResizeHandler = _ref => {
65
64
  // eslint-disable-next-line react-hooks/exhaustive-deps
66
65
  }, [isDraggingResizeHandler, mouseDownInfo, rowBottom, table, height]);
67
66
  useEffect(() => {
68
- const cell = row.children.filter(cell => !cell.is_combined && (!cell.rowspan || cell.rowspan == 1))[0];
67
+ const cell = row.children.filter(cell => !cell.is_combined && (!cell.rowspan || cell.rowspan === 1))[0];
69
68
  if (!cell) return;
70
69
  const rowDom = ReactEditor.toDOMNode(editor, cell);
71
70
  if (!rowDom) return;
@@ -1,4 +1,4 @@
1
- import React, { useRef, useCallback, useState, useEffect, useLayoutEffect } from 'react';
1
+ import React, { useRef, useCallback, useState, useEffect } from 'react';
2
2
  import { useSlateStatic } from '@seafile/slate-react';
3
3
  import classnames from 'classnames';
4
4
  import ObjectUtils from '../../../../../../utils/object-utils';
@@ -92,6 +92,7 @@ export const getDomTopHeight = (dom, slateNode) => {
92
92
  if (ADD_POSITION_OFFSET_TYPE.includes(slateNode.type)) {
93
93
  offsetY = lightHight / 2 + paddingTop - 12; // side toolbar icon is 12 px
94
94
  }
95
+
95
96
  const HEADER_HEIGHT = 56 + 44;
96
97
  return rect.y - HEADER_HEIGHT + offsetY;
97
98
  };
@@ -27,8 +27,8 @@ export const getSelectionRange = () => {
27
27
  };
28
28
  export const getCursorPosition = function () {
29
29
  let isScrollUp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
30
- let x = 0,
31
- y = 0;
30
+ let x = 0;
31
+ let y = 0;
32
32
  let range = getSelectionRange();
33
33
  if (range) {
34
34
  const rect = range.getBoundingClientRect();
@@ -4,7 +4,9 @@ const {
4
4
  TEXT
5
5
  } = TransferTypes;
6
6
  function getEventTransfer(event) {
7
- let html, text, files;
7
+ let html;
8
+ let text;
9
+ let files;
8
10
  if (window.isMobile) {
9
11
  if (window.dtableTransfer) {
10
12
  text = window.dtableTransfer['TEXT'];
@@ -56,12 +56,12 @@ export const resetWebTitle = t => {
56
56
  };
57
57
  export const getSelectionCoords = () => {
58
58
  let doc = window.document;
59
- let sel = doc.selection,
60
- range,
61
- rects,
62
- rect;
63
- let x = 0,
64
- y = 0;
59
+ let sel = doc.selection;
60
+ let range;
61
+ let rects;
62
+ let rect;
63
+ let x = 0;
64
+ let y = 0;
65
65
  if (sel) {
66
66
  if (sel.type !== 'Control') {
67
67
  range = sel.createRange();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.4.35",
3
+ "version": "0.4.36",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",