@seafile/sdoc-editor 0.1.79 → 0.1.80-beta1

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.
@@ -9,7 +9,7 @@ import SDocOutline from './outline';
9
9
  import EventProxy from './utils/event-handler';
10
10
  import { useCursors } from './cursor/use-cursors';
11
11
  import EventBus from './utils/event-bus';
12
- import { EXTERNAL_EVENT } from '../constants';
12
+ import { EXTERNAL_EVENT, PAGE_EDIT_AREA_WIDTH } from '../constants';
13
13
  import { isAllInTable } from './extension/plugins/table/helpers';
14
14
  import { SetNodeToDecorations } from './highlight-decorate/setNodeToDecorations';
15
15
  import { ScrollContext } from './hooks/use-scroll-context';
@@ -30,6 +30,7 @@ var SDocEditor = function SDocEditor(_ref) {
30
30
  }));
31
31
  var cursors = document.cursors;
32
32
  newEditor.cursors = cursors || {};
33
+ newEditor.width = PAGE_EDIT_AREA_WIDTH; // default width
33
34
  return newEditor;
34
35
  // eslint-disable-next-line react-hooks/exhaustive-deps
35
36
  }, []);
@@ -61,7 +62,6 @@ var SDocEditor = function SDocEditor(_ref) {
61
62
  // useMount: init socket connection
62
63
  useEffect(function () {
63
64
  editor.openConnection();
64
- editor.width = articleRef.current.children[0].clientWidth;
65
65
  return function () {
66
66
  editor.closeConnection();
67
67
  };
@@ -71,6 +71,8 @@ var SDocEditor = function SDocEditor(_ref) {
71
71
  // useMount: focus editor
72
72
  useEffect(function () {
73
73
  var timer = setTimeout(function () {
74
+ // real width
75
+ editor.width = articleRef.current.children[0].clientWidth;
74
76
  focusEditor(editor);
75
77
  }, 300);
76
78
  return function () {
@@ -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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.79",
3
+ "version": "0.1.80beta1",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",