@seafile/sdoc-editor 0.1.66 → 0.1.67

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.
@@ -13,6 +13,10 @@ export var useSelectionPosition = function useSelectionPosition() {
13
13
  return Element.isElement(n) && Editor.isBlock(editor, n);
14
14
  }
15
15
  });
16
+ if (!node) return {
17
+ x: 0,
18
+ y: 0
19
+ };
16
20
  var domNode = ReactEditor.toDOMNode(editor, node[0]);
17
21
  var rect = domNode.getBoundingClientRect();
18
22
  return rect;
@@ -74,4 +74,18 @@ export var decorateOperation = function decorateOperation(editor, operation) {
74
74
  }
75
75
  }
76
76
  return newOperation;
77
+ };
78
+ export var replacePastedDataId = function replacePastedDataId(pastedData) {
79
+ // If children is malformed, return a list of correct child nodes
80
+ if (!Array.isArray(pastedData)) return [{
81
+ id: slugid.nice(),
82
+ text: ''
83
+ }];
84
+ return pastedData.map(function (item) {
85
+ item.id = slugid.nice();
86
+ if (item.children) {
87
+ item.children = replacePastedDataId(item.children);
88
+ }
89
+ return item;
90
+ });
77
91
  };
@@ -1,4 +1,14 @@
1
- import { decorateOperation } from './helpers';
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import { decorateOperation, replacePastedDataId } from './helpers';
3
+ var clipboardFormatKey = 'x-slate-fragment';
4
+ var catchSlateFragment = /data-slate-fragment="(.+?)"/m;
5
+ var getSlateFragmentAttribute = function getSlateFragmentAttribute(dataTransfer) {
6
+ var htmlData = dataTransfer.getData('text/html');
7
+ var _ref = htmlData.match(catchSlateFragment) || [],
8
+ _ref2 = _slicedToArray(_ref, 2),
9
+ fragment = _ref2[1];
10
+ return fragment;
11
+ };
2
12
  var withNodeId = function withNodeId(editor) {
3
13
  var apply = editor.apply;
4
14
  var newEditor = editor;
@@ -6,6 +16,18 @@ var withNodeId = function withNodeId(editor) {
6
16
  var newOp = decorateOperation(newEditor, op);
7
17
  apply(newOp);
8
18
  };
19
+
20
+ // rewrite insert fragment data
21
+ newEditor.insertFragmentData = function (data) {
22
+ var fragment = data.getData("application/".concat(clipboardFormatKey)) || getSlateFragmentAttribute(data);
23
+ if (fragment) {
24
+ var decoded = decodeURIComponent(window.atob(fragment));
25
+ var parsed = JSON.parse(decoded);
26
+ var newData = replacePastedDataId(parsed);
27
+ newEditor.insertFragment(newData);
28
+ return true;
29
+ }
30
+ };
9
31
  return newEditor;
10
32
  };
11
33
  export default withNodeId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.66",
3
+ "version": "0.1.67",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",