@seafile/sdoc-editor 1.0.89 → 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.
@@ -23,6 +23,7 @@ require("prismjs/components/prism-swift");
23
23
  require("prismjs/components/prism-bash");
24
24
  require("prismjs/components/prism-lua");
25
25
  require("prismjs/components/prism-json.js");
26
+ require("prismjs/components/prism-yaml");
26
27
  // languages
27
28
 
28
29
  const newlineRe = /\r\n|\r|\n/;
@@ -81,6 +82,9 @@ const genCodeLangs = () => {
81
82
  }, {
82
83
  text: 'XML',
83
84
  value: 'xml'
85
+ }, {
86
+ text: 'YAML',
87
+ value: 'yaml'
84
88
  }];
85
89
  };
86
90
  exports.genCodeLangs = genCodeLangs;
@@ -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
  };
@@ -27,8 +27,11 @@ const getChildNodeToDecorations = _ref => {
27
27
  const nodeToDecorations = new Map();
28
28
  const text = block.children.map(line => _slate.Node.string(line)).join('\n');
29
29
  const language = (0, _helpers.getValidLang)(block.language);
30
+ console.log(language);
31
+ console.log(_prismjs.default.languages);
30
32
  let tokens = _prismjs.default.tokenize(text, _prismjs.default.languages[language]);
31
33
  if (Object.keys(_prismjs.normalizeTokensByLanguageType).includes(language)) {
34
+ console.log(language);
32
35
  tokens = _prismjs.normalizeTokensByLanguageType[language](tokens);
33
36
  }
34
37
  const normalizedTokens = (0, _prismjs.normalizeTokens)(tokens); // make tokens flat and grouped by line
@@ -56,6 +56,9 @@ const genCodeLangs = () => {
56
56
  }, {
57
57
  text: 'XML',
58
58
  value: 'xml'
59
+ }, {
60
+ text: 'YAML',
61
+ value: 'yaml'
59
62
  }];
60
63
  };
61
64
  exports.genCodeLangs = genCodeLangs;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "1.0.89",
3
+ "version": "1.0.91",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",