@seafile/sdoc-editor 0.1.75 → 0.1.77

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.
@@ -2,7 +2,7 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
3
  import { Editable, ReactEditor, Slate } from '@seafile/slate-react';
4
4
  import defaultEditor, { renderLeaf, renderElement, Toolbar, ContextMenu } from './extension';
5
- import { focusEditor, getNextNode, getPrevNode, isSelectionAtBlockEnd, isSelectionAtBlockStart } from './extension/core';
5
+ import { focusEditor, getAboveBlockNode, 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,7 +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
+ import { getCursorPosition, getDomHeight, getDomMarginTop } from './utils/dom-utils';
20
20
  import './assets/css/layout.css';
21
21
  import './assets/css/sdoc-editor-plugins.css';
22
22
  var SDocEditor = function SDocEditor(_ref) {
@@ -148,7 +148,11 @@ var SDocEditor = function SDocEditor(_ref) {
148
148
  if (!_prevNode) return;
149
149
  var _domNode2 = ReactEditor.toDOMNode(editor, _prevNode[0]);
150
150
  var _domHeight2 = getDomHeight(_domNode2);
151
- scrollRef.current.scroll(0, Math.max(0, scrollTop - (newY + _domHeight2)));
151
+ var node = getAboveBlockNode(editor);
152
+ if (!node) return;
153
+ var currentDomNode = ReactEditor.toDOMNode(editor, node[0]);
154
+ var marginTop = getDomMarginTop(currentDomNode);
155
+ scrollRef.current.scroll(0, Math.max(0, scrollTop - (newY + _domHeight2 + marginTop)));
152
156
  } else {
153
157
  scrollRef.current.scroll(0, Math.max(0, scrollTop - newY));
154
158
  }
@@ -1,5 +1,6 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
3
+ import copy from 'copy-to-clipboard';
3
4
  import { Transforms, Editor, Node } from '@seafile/slate';
4
5
  import slugid from 'slugid';
5
6
  import { CODE_BLOCK, CODE_LINE, PARAGRAPH } from '../../constants';
@@ -106,4 +107,20 @@ export var changeToPlainText = function changeToPlainText(editor) {
106
107
  Transforms.insertNodes(editor, pList, {
107
108
  mode: 'highest'
108
109
  });
110
+ };
111
+ export var setClipboardData = function setClipboardData(value) {
112
+ // Insert text into the clipboard for use on other pages
113
+ var text = value.children.map(function (line) {
114
+ return Node.string(line);
115
+ }).join('\n');
116
+ copy(text, {
117
+ format: 'text/plain'
118
+ });
119
+
120
+ // Store the code block data
121
+ var clipboardData = {
122
+ text: text,
123
+ codeBlockNode: value
124
+ };
125
+ sessionStorage.setItem('clipboardData', JSON.stringify(clipboardData));
109
126
  };
@@ -9,7 +9,9 @@ var withCodeBlock = function withCodeBlock(editor) {
9
9
  var normalizeNode = editor.normalizeNode,
10
10
  insertFragment = editor.insertFragment,
11
11
  insertText = editor.insertText,
12
- insertBreak = editor.insertBreak;
12
+ insertBreak = editor.insertBreak,
13
+ insertData = editor.insertData,
14
+ insertNode = editor.insertNode;
13
15
  var newEditor = editor;
14
16
 
15
17
  // If you enter two Spaces in quick succession, a period and a space appear (Default Settings for mac)
@@ -19,6 +21,16 @@ var withCodeBlock = function withCodeBlock(editor) {
19
21
  }
20
22
  return insertText(data);
21
23
  };
24
+ newEditor.insertData = function (data) {
25
+ var text = data.getData('text/plain');
26
+ var _ref = JSON.parse(sessionStorage.getItem('clipboardData')) || {},
27
+ storageText = _ref.text,
28
+ codeBlockNode = _ref.codeBlockNode;
29
+ if (codeBlockNode && text === storageText && !getSelectedNodeByType(editor, CODE_BLOCK)) {
30
+ return insertNode(codeBlockNode);
31
+ }
32
+ return insertData(data);
33
+ };
22
34
  newEditor.insertFragment = function (data) {
23
35
  // only selected code block content
24
36
  if (data.length === 1 && data[0].type === CODE_BLOCK && !getSelectedNodeByType(editor, CODE_BLOCK)) {
@@ -83,10 +95,10 @@ var withCodeBlock = function withCodeBlock(editor) {
83
95
  };
84
96
 
85
97
  // Rewrite normalizeNode
86
- newEditor.normalizeNode = function (_ref) {
87
- var _ref2 = _slicedToArray(_ref, 2),
88
- node = _ref2[0],
89
- path = _ref2[1];
98
+ newEditor.normalizeNode = function (_ref2) {
99
+ var _ref3 = _slicedToArray(_ref2, 2),
100
+ node = _ref3[0],
101
+ path = _ref3[1];
90
102
  var type = getNodeType(node);
91
103
  if (type === CODE_BLOCK) {
92
104
  // code-block is the last node in the editor and needs to be followed by a p node
@@ -5,6 +5,7 @@ import { ReactEditor, useSlateStatic, useReadOnly } from '@seafile/slate-react';
5
5
  import { Transforms } from '@seafile/slate';
6
6
  import { useScrollContext } from '../../../hooks/use-scroll-context';
7
7
  import CodeBlockHoverMenu from '../../../../components/code-block-hover-menu';
8
+ import { setClipboardData } from './helpers';
8
9
  import '../../../assets/css/code-block.css';
9
10
  var CodeBlock = function CodeBlock(_ref) {
10
11
  var codeBlockProps = _ref.codeBlockProps;
@@ -53,6 +54,10 @@ var CodeBlock = function CodeBlock(_ref) {
53
54
  });
54
55
  // eslint-disable-next-line react-hooks/exhaustive-deps
55
56
  }, []);
57
+ var onCopyCodeBlock = useCallback(function () {
58
+ setClipboardData(element);
59
+ // eslint-disable-next-line react-hooks/exhaustive-deps
60
+ }, [element]);
56
61
  var onDeleteCodeBlock = useCallback(function () {
57
62
  var path = ReactEditor.findPath(editor, element);
58
63
  Transforms.removeNodes(editor, {
@@ -124,6 +129,7 @@ var CodeBlock = function CodeBlock(_ref) {
124
129
  white_space: 'nowrap'
125
130
  },
126
131
  onChangeAutoLineWrap: onChangeAutoLineWrap,
132
+ onCopyCodeBlock: onCopyCodeBlock,
127
133
  onDeleteCodeBlock: onDeleteCodeBlock
128
134
  }));
129
135
  };
@@ -7,6 +7,11 @@ export var getDomHeight = function getDomHeight(dom) {
7
7
  var height = rect.height;
8
8
  return height + parseInt(marginTop);
9
9
  };
10
+ export var getDomMarginTop = function getDomMarginTop(dom) {
11
+ var styles = window.getComputedStyle(dom);
12
+ var marginTop = styles['marginTop'];
13
+ return parseInt(marginTop);
14
+ };
10
15
  export var getSelectionRange = function getSelectionRange() {
11
16
  if (window.getSelection) {
12
17
  var sel = window.getSelection();
@@ -26,10 +26,14 @@
26
26
  .sdoc-code-block-hover-menu-container .hover-menu-container .op-item {
27
27
  font-size: 12px;
28
28
  color: #212529;
29
- padding: 0 3px;
29
+ padding: 0 5px;
30
30
  border-radius: 2px;
31
31
  }
32
32
 
33
+ .sdoc-code-block-hover-menu-container .hover-menu-container .op-item:not(:last-child) {
34
+ border-right: 1px solid #e5e5e5;
35
+ }
36
+
33
37
  .sdoc-code-block-hover-menu-container .hover-menu-container .op-item:hover {
34
38
  color: #212529;
35
39
  text-decoration: none;
@@ -10,6 +10,7 @@ var CodeBlockHoverMenu = function CodeBlockHoverMenu(_ref) {
10
10
  menuPosition = _ref.menuPosition,
11
11
  onChangeLanguage = _ref.onChangeLanguage,
12
12
  onChangeAutoLineWrap = _ref.onChangeAutoLineWrap,
13
+ onCopyCodeBlock = _ref.onCopyCodeBlock,
13
14
  onDeleteCodeBlock = _ref.onDeleteCodeBlock,
14
15
  t = _ref.t;
15
16
  var _style$white_space = style.white_space,
@@ -83,6 +84,10 @@ var CodeBlockHoverMenu = function CodeBlockHoverMenu(_ref) {
83
84
  className: "op-item ".concat(white_space === 'normal' ? 'active' : ''),
84
85
  onClick: onAutoLineWrap
85
86
  }, /*#__PURE__*/React.createElement("span", null, t('Auto_wrap'))), /*#__PURE__*/React.createElement("span", {
87
+ role: "button",
88
+ className: "op-item",
89
+ onClick: onCopyCodeBlock
90
+ }, /*#__PURE__*/React.createElement("span", null, t('Copy'))), /*#__PURE__*/React.createElement("span", {
86
91
  role: "button",
87
92
  className: 'op-item',
88
93
  onClick: onDelete
@@ -3,22 +3,21 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
3
  import _inherits from "@babel/runtime/helpers/esm/inherits";
4
4
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
5
  import React from 'react';
6
- import { withTranslation } from 'react-i18next';
7
6
  import './style.css';
8
- var TextAlignMenu = /*#__PURE__*/function (_React$Component) {
9
- _inherits(TextAlignMenu, _React$Component);
10
- var _super = _createSuper(TextAlignMenu);
11
- function TextAlignMenu(props) {
7
+ var MoreDropdownMenu = /*#__PURE__*/function (_React$Component) {
8
+ _inherits(MoreDropdownMenu, _React$Component);
9
+ var _super = _createSuper(MoreDropdownMenu);
10
+ function MoreDropdownMenu(props) {
12
11
  var _this;
13
- _classCallCheck(this, TextAlignMenu);
12
+ _classCallCheck(this, MoreDropdownMenu);
14
13
  _this = _super.call(this, props);
15
14
  _this.registerEventHandler = function () {
16
- document.addEventListener('click', _this.onHideTextAlignMenu);
15
+ document.addEventListener('click', _this.onHideMoreDropdownMenu);
17
16
  };
18
17
  _this.unregisterEventHandler = function () {
19
- document.removeEventListener('click', _this.onHideTextAlignMenu);
18
+ document.removeEventListener('click', _this.onHideMoreDropdownMenu);
20
19
  };
21
- _this.onHideTextAlignMenu = function () {
20
+ _this.onHideMoreDropdownMenu = function () {
22
21
  _this.setState({
23
22
  isDropdownMenuOpen: false
24
23
  }, function () {
@@ -48,7 +47,7 @@ var TextAlignMenu = /*#__PURE__*/function (_React$Component) {
48
47
  };
49
48
  return _this;
50
49
  }
51
- _createClass(TextAlignMenu, [{
50
+ _createClass(MoreDropdownMenu, [{
52
51
  key: "render",
53
52
  value: function render() {
54
53
  var isDropdownMenuOpen = this.state.isDropdownMenuOpen;
@@ -64,6 +63,6 @@ var TextAlignMenu = /*#__PURE__*/function (_React$Component) {
64
63
  }, this.props.children));
65
64
  }
66
65
  }]);
67
- return TextAlignMenu;
66
+ return MoreDropdownMenu;
68
67
  }(React.Component);
69
- export default withTranslation('sdoc-editor')(TextAlignMenu);
68
+ export default MoreDropdownMenu;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.75",
3
+ "version": "0.1.77",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -12,6 +12,7 @@
12
12
  "@seafile/slate-react": "0.92.6",
13
13
  "ahooks": "3.7.7",
14
14
  "classnames": "2.3.2",
15
+ "copy-to-clipboard": "^3.3.3",
15
16
  "deep-copy": "1.4.2",
16
17
  "is-hotkey": "0.2.0",
17
18
  "is-url": "^1.2.4",