@seafile/sdoc-editor 0.1.78 → 0.1.80-beta

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.
@@ -17,6 +17,7 @@ import CommentContextProvider from './comment/comment-context-provider';
17
17
  import CommentWrapper from './comment';
18
18
  import { usePipDecorate } from './decorates';
19
19
  import { getCursorPosition, getDomHeight, getDomMarginTop } from './utils/dom-utils';
20
+ import { ArticleContext } from './hooks/use-article-width';
20
21
  import './assets/css/layout.css';
21
22
  import './assets/css/sdoc-editor-plugins.css';
22
23
  var SDocEditor = function SDocEditor(_ref) {
@@ -114,13 +114,10 @@ export var setClipboardData = function setClipboardData(value) {
114
114
  return Node.string(line);
115
115
  }).join('\n');
116
116
  copy(text, {
117
- format: 'text/plain'
117
+ format: 'text/plain',
118
+ onCopy: function onCopy(data) {
119
+ // Set the sdoc editor to format the data
120
+ data.setData('text/code-block', JSON.stringify(value));
121
+ }
118
122
  });
119
-
120
- // Store the code block data
121
- var clipboardData = {
122
- text: text,
123
- codeBlockNode: value
124
- };
125
- sessionStorage.setItem('clipboardData', JSON.stringify(clipboardData));
126
123
  };
@@ -22,11 +22,8 @@ var withCodeBlock = function withCodeBlock(editor) {
22
22
  return insertText(data);
23
23
  };
24
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)) {
25
+ if (data.types.includes('text/code-block') && !getSelectedNodeByType(editor, CODE_BLOCK)) {
26
+ var codeBlockNode = JSON.parse(data.getData('text/code-block'));
30
27
  return insertNode(codeBlockNode);
31
28
  }
32
29
  return insertData(data);
@@ -95,10 +92,10 @@ var withCodeBlock = function withCodeBlock(editor) {
95
92
  };
96
93
 
97
94
  // Rewrite normalizeNode
98
- newEditor.normalizeNode = function (_ref2) {
99
- var _ref3 = _slicedToArray(_ref2, 2),
100
- node = _ref3[0],
101
- path = _ref3[1];
95
+ newEditor.normalizeNode = function (_ref) {
96
+ var _ref2 = _slicedToArray(_ref, 2),
97
+ node = _ref2[0],
98
+ path = _ref2[1];
102
99
  var type = getNodeType(node);
103
100
  if (type === CODE_BLOCK) {
104
101
  // code-block is the last node in the editor and needs to be followed by a p node
@@ -1,60 +1,37 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/esm/createClass";
4
- import _inherits from "@babel/runtime/helpers/esm/inherits";
5
- import _createSuper from "@babel/runtime/helpers/esm/createSuper";
6
- import React from 'react';
2
+ import React, { useCallback } from 'react';
7
3
  import { withTranslation } from 'react-i18next';
8
4
  import { insertTable, isTableMenuDisabled } from '../../helpers';
9
5
  import { TABLE, MENUS_CONFIG_MAP } from '../../../../constants';
10
6
  import { MenuItem } from '../../../../menu';
11
7
  import TableSizePopover from '../../popover/table-size-popover';
12
- var TableMenu = /*#__PURE__*/function (_React$Component) {
13
- _inherits(TableMenu, _React$Component);
14
- var _super = _createSuper(TableMenu);
15
- function TableMenu() {
16
- var _this;
17
- _classCallCheck(this, TableMenu);
18
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
19
- args[_key] = arguments[_key];
20
- }
21
- _this = _super.call.apply(_super, [this].concat(args));
22
- _this.isActive = function () {
23
- return false;
24
- };
25
- _this.isDisabled = function () {
26
- var editor = _this.props.editor;
27
- return isTableMenuDisabled(editor);
28
- };
29
- _this.createTable = function (size) {
30
- var editor = _this.props.editor;
31
- insertTable(editor, size, _this.selection);
32
- };
33
- return _this;
34
- }
35
- _createClass(TableMenu, [{
36
- key: "render",
37
- value: function render() {
38
- var _this$props = this.props,
39
- isRichEditor = _this$props.isRichEditor,
40
- className = _this$props.className;
41
- var menuConfig = MENUS_CONFIG_MAP[TABLE];
42
- var props = _objectSpread(_objectSpread({
43
- isRichEditor: isRichEditor,
44
- className: className
45
- }, menuConfig), {}, {
46
- disabled: this.isDisabled(),
47
- isActive: this.isActive(),
48
- onMouseDown: function onMouseDown() {}
49
- });
50
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
51
- className: "table-menu"
52
- }, /*#__PURE__*/React.createElement(MenuItem, props)), /*#__PURE__*/React.createElement(TableSizePopover, {
53
- target: menuConfig.id,
54
- createTable: this.createTable
55
- }));
56
- }
57
- }]);
58
- return TableMenu;
59
- }(React.Component);
8
+ var TableMenu = function TableMenu(_ref) {
9
+ var editor = _ref.editor,
10
+ isRichEditor = _ref.isRichEditor,
11
+ className = _ref.className;
12
+ var isActive = useCallback(function () {
13
+ return false;
14
+ }, []);
15
+ var isDisabled = useCallback(function () {
16
+ return isTableMenuDisabled(editor);
17
+ }, [editor]);
18
+ var createTable = useCallback(function (size) {
19
+ insertTable(editor, size);
20
+ }, [editor]);
21
+ var menuConfig = MENUS_CONFIG_MAP[TABLE];
22
+ var props = _objectSpread(_objectSpread({
23
+ isRichEditor: isRichEditor,
24
+ className: className
25
+ }, menuConfig), {}, {
26
+ disabled: isDisabled(),
27
+ isActive: isActive(),
28
+ onMouseDown: function onMouseDown() {}
29
+ });
30
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
31
+ className: "table-menu"
32
+ }, /*#__PURE__*/React.createElement(MenuItem, props)), /*#__PURE__*/React.createElement(TableSizePopover, {
33
+ target: menuConfig.id,
34
+ createTable: createTable
35
+ }));
36
+ };
60
37
  export default withTranslation('sdoc-editor')(TableMenu);
@@ -0,0 +1,11 @@
1
+ import React, { useContext } from 'react';
2
+ export var ArticleContext = React.createContext(null);
3
+ export var useArticleWidth = function useArticleWidth() {
4
+ var context = useContext(ArticleContext);
5
+ if (!context) {
6
+ throw new Error('The \`useArticleWidth\` hook must be used inside the <ArticleContext> component\'s context.');
7
+ }
8
+ var articleRef = context.articleRef;
9
+ if (!articleRef.current) return 0;
10
+ return articleRef.current.firstChild.clientWidth;
11
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.78",
3
+ "version": "0.1.80beta",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",