@seafile/sdoc-editor 0.5.2 → 0.5.3

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.
@@ -1,5 +1,5 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import { Editor, Transforms, Element } from '@seafile/slate';
2
+ import { Editor, Transforms, Element, Node } from '@seafile/slate';
3
3
  import slugid from 'slugid';
4
4
  import { BLOCKQUOTE, CHECK_LIST_ITEM, IMAGE, ORDERED_LIST, PARAGRAPH, UNORDERED_LIST, CODE_BLOCK, TABLE, CALL_OUT } from '../../constants';
5
5
  import { getNodeType } from '../../core';
@@ -97,13 +97,15 @@ export const getFormattedElements = data => {
97
97
  };
98
98
  export const getFormattedRestElements = data => {
99
99
  const restElements = data.slice(0);
100
- // Contains quote block type elements
101
- if (data.find(item => (item === null || item === void 0 ? void 0 : item.type) === BLOCKQUOTE)) {
102
- data.forEach((item, index) => {
103
- if ((item === null || item === void 0 ? void 0 : item.type) === BLOCKQUOTE) {
104
- restElements.splice(index, 1, ...item.children);
105
- }
106
- });
107
- }
100
+ data.forEach((item, index) => {
101
+ if (Node.string(item).length === 0) {
102
+ restElements.splice(index, 1);
103
+ }
104
+
105
+ // Split quote block
106
+ if ((item === null || item === void 0 ? void 0 : item.type) === BLOCKQUOTE) {
107
+ restElements.splice(index, 1, ...item.children);
108
+ }
109
+ });
108
110
  return restElements;
109
111
  };
@@ -112,7 +112,7 @@ const withBlockquote = editor => {
112
112
  Editor.insertText(newEditor, string);
113
113
  } else {
114
114
  Transforms.insertNodes(newEditor, restElements, {
115
- at: [path[0], path[1]]
115
+ at: [path[0], path[1] + 1]
116
116
  });
117
117
  }
118
118
  }
@@ -17,7 +17,8 @@ const withCallout = editor => {
17
17
  insertFragment,
18
18
  deleteBackward,
19
19
  onHotKeyDown,
20
- insertData
20
+ insertData,
21
+ onCopy
21
22
  } = editor;
22
23
  const newEditor = editor;
23
24
  newEditor.deleteBackward = unit => {
@@ -87,6 +88,7 @@ const withCallout = editor => {
87
88
  if (getCalloutEntry(editor)) {
88
89
  event.stopPropagation();
89
90
  }
91
+ return onCopy(event);
90
92
  };
91
93
  return newEditor;
92
94
  };
@@ -6,13 +6,14 @@ import { insertSdocFileLink } from '../sdoc-link/helpers';
6
6
  import { genLinkNode, isSdocFile } from './helpers';
7
7
  import { getNodeType, getSelectedNodeByType } from '../../core';
8
8
  import { isImage, isSameDomain } from '../../utils';
9
- import { LINK } from '../../constants';
9
+ import { LINK, ORDERED_LIST, UNORDERED_LIST } from '../../constants';
10
10
  const withLink = editor => {
11
11
  const {
12
12
  normalizeNode,
13
13
  isInline,
14
14
  insertData,
15
- insertText
15
+ insertText,
16
+ insertFragment
16
17
  } = editor;
17
18
  const newEditor = editor;
18
19
 
@@ -64,6 +65,17 @@ const withLink = editor => {
64
65
  }
65
66
  insertData(data);
66
67
  };
68
+ newEditor.insertFragment = data => {
69
+ // Paste into link
70
+ if (getSelectedNodeByType(newEditor, LINK)) {
71
+ const fragments = data.slice(0).filter(item => Node.string(item).length !== 0);
72
+ // Prevent list into link
73
+ if (fragments.some(item => [ORDERED_LIST, UNORDERED_LIST].includes(item.type))) {
74
+ return;
75
+ }
76
+ }
77
+ return insertFragment(data);
78
+ };
67
79
 
68
80
  // Rewrite normalizeNode
69
81
  newEditor.normalizeNode = _ref => {
@@ -1,11 +1,12 @@
1
+ import { Editor, Transforms } from '@seafile/slate';
1
2
  import { insertBreakList } from './insert-break-list';
2
3
  import { onTabHandle } from './on-tab-handle';
3
4
  import { normalizeList } from './normalize-list';
4
5
  import { insertFragmentList } from './insert-fragment-list';
5
6
  import { handleShortcut } from './shortcut';
6
- import { getAboveBlockNode, getSelectedNodeEntryByType } from '../../../core';
7
+ import { getSelectedNodeEntryByType } from '../../../core';
7
8
  import { BLOCKQUOTE, LIST_ITEM } from '../../../constants';
8
- import { Editor, Transforms } from '@seafile/slate';
9
+ import { isList } from '../../../toolbar/side-toolbar/helpers';
9
10
  const withList = editor => {
10
11
  const {
11
12
  insertBreak,
@@ -61,6 +62,22 @@ const withList = editor => {
61
62
  if (isPreventInsert) return;
62
63
  return insertText(text);
63
64
  };
65
+ newEditor.onCopy = event => {
66
+ const path = Editor.path(newEditor, newEditor.selection, {
67
+ edge: 'start'
68
+ });
69
+ if (isList(newEditor, path)) {
70
+ event.stopPropagation();
71
+ }
72
+ };
73
+ newEditor.cut = event => {
74
+ const path = Editor.path(newEditor, newEditor.selection, {
75
+ edge: 'start'
76
+ });
77
+ if (isList(newEditor, path)) {
78
+ event.stopPropagation();
79
+ }
80
+ };
64
81
  return newEditor;
65
82
  };
66
83
  export default withList;
@@ -20,7 +20,8 @@ const withTable = editor => {
20
20
  handleTab,
21
21
  getFragment,
22
22
  setFragmentData,
23
- insertFragment
23
+ insertFragment,
24
+ cut
24
25
  } = editor;
25
26
  const newEditor = editor;
26
27
  newEditor.tableSelectedRange = EMPTY_SELECTED_RANGE;
@@ -237,6 +238,7 @@ const withTable = editor => {
237
238
  }
238
239
  return;
239
240
  }
241
+ return cut(event);
240
242
  };
241
243
 
242
244
  // copy insert text
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",