@seafile/sdoc-editor 1.0.90 → 1.0.91

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.
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  var _slugid = _interopRequireDefault(require("slugid"));
9
+ var _slate = require("@seafile/slate");
9
10
  var _helper = require("./helper");
10
11
  var _core = require("../../core");
11
12
  var _constants = require("../../constants");
@@ -42,6 +43,41 @@ const withHtml = editor => {
42
43
  editor.insertFragment(content);
43
44
  return;
44
45
  }
46
+
47
+ // Paste AI code as code blcok type
48
+ if (data.types[0].includes('text/plain') && data.types.length === 1) {
49
+ const pastedCode = data.getData('text/plain') || '';
50
+ if (pastedCode && pastedCode.trim() !== '') {
51
+ const fragmentData = {
52
+ id: _slugid.default.nice(),
53
+ language: 'plaintext',
54
+ type: _constants.CODE_BLOCK,
55
+ children: pastedCode.split('\n').map(text => ({
56
+ id: _slugid.default.nice(),
57
+ type: _constants.CODE_LINE,
58
+ children: [{
59
+ id: _slugid.default.nice(),
60
+ text: text
61
+ }]
62
+ }))
63
+ };
64
+ const string = _slate.Editor.string(newEditor, newEditor.selection.focus.path);
65
+ if (string.length === 0) {
66
+ _slate.Transforms.insertNodes(newEditor, fragmentData, {
67
+ at: newEditor.selection.focus.path
68
+ });
69
+ const paragraph = (0, _core.generateEmptyElement)(_constants.PARAGRAPH);
70
+ _slate.Transforms.insertNodes(newEditor, paragraph, {
71
+ at: [newEditor.selection.focus.path[0] + 1]
72
+ });
73
+ } else {
74
+ _slate.Transforms.insertNodes(newEditor, fragmentData, {
75
+ at: newEditor.selection
76
+ });
77
+ }
78
+ return;
79
+ }
80
+ }
45
81
  insertData(data);
46
82
  }
47
83
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "1.0.90",
3
+ "version": "1.0.91",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",