@seafile/sdoc-editor 0.5.1 → 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
  };
@@ -13,12 +13,12 @@
13
13
 
14
14
  .sdoc-callout-container .callout-content {
15
15
  flex: 1;
16
+ position: relative;
16
17
  }
17
18
 
18
19
  .sdoc-callout-container .sdoc-callout-placeholder {
19
20
  position: absolute;
20
- top: 15px;
21
- left: 26px;
21
+ top: 5px;
22
22
  color: #b8b6b6;
23
23
  pointer-events: none;
24
24
  }
@@ -123,16 +123,16 @@ const renderCallout = (_ref, editor) => {
123
123
  ref: calloutRef,
124
124
  className: "".concat(attributes.className, " sdoc-callout-container"),
125
125
  style: containerStyle
126
- }, /*#__PURE__*/React.createElement("div", {
126
+ }, element.callout_icon && /*#__PURE__*/React.createElement("div", {
127
127
  className: "callout-icon"
128
- }, element.callout_icon && /*#__PURE__*/React.createElement("span", {
128
+ }, /*#__PURE__*/React.createElement("span", {
129
129
  className: 'sdoc-emoji ' + element.callout_icon
130
130
  }, calloutIcon)), /*#__PURE__*/React.createElement("div", {
131
131
  className: "callout-content"
132
132
  }, children, isShowPlaceholder() && /*#__PURE__*/React.createElement("div", {
133
133
  contentEditable: false,
134
134
  className: "sdoc-callout-placeholder"
135
- }, t('Please_enter...'))), isShowColorSelector && /*#__PURE__*/React.createElement(CalloutHoverMenu, {
135
+ }, t('Please_enter'), "...")), isShowColorSelector && /*#__PURE__*/React.createElement(CalloutHoverMenu, {
136
136
  editor: editor,
137
137
  element: element,
138
138
  popoverPosition: popoverPosition
@@ -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.1",
3
+ "version": "0.5.3",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -418,7 +418,7 @@
418
418
  "Freezed": "Freezed",
419
419
  "Callout": "Callout",
420
420
  "The_current_location_does_not_support_pasting": "The current location does not support pasting ",
421
- "Please_enter...": "Please enter...",
421
+ "Please_enter": "Please enter",
422
422
  "Combine_cell": "Combine cells",
423
423
  "Split_cell": "Split cell",
424
424
  "Row_number": "Row number",
@@ -418,7 +418,7 @@
418
418
  "Freezed": "Freezed",
419
419
  "Callout": "Callout",
420
420
  "The_current_location_does_not_support_pasting": "The current location does not support pasting ",
421
- "Please_enter...": "Please enter...",
421
+ "Please_enter": "Please enter",
422
422
  "Combine_cell": "Combine cells",
423
423
  "Split_cell": "Split cell",
424
424
  "Row_number": "Row number",
@@ -418,7 +418,7 @@
418
418
  "Freezed": "Freezed",
419
419
  "Callout": "Callout",
420
420
  "The_current_location_does_not_support_pasting": "The current location does not support pasting ",
421
- "Please_enter...": "Please enter...",
421
+ "Please_enter": "Please enter",
422
422
  "Combine_cell": "Combine cells",
423
423
  "Split_cell": "Split cell",
424
424
  "Row_number": "Row number",
@@ -418,7 +418,7 @@
418
418
  "Freezed": "Freezed",
419
419
  "Callout": "Callout",
420
420
  "The_current_location_does_not_support_pasting": "The current location does not support pasting ",
421
- "Please_enter...": "Please enter...",
421
+ "Please_enter": "Please enter",
422
422
  "Combine_cell": "Combine cells",
423
423
  "Split_cell": "Split cell",
424
424
  "Row_number": "Row number",
@@ -418,7 +418,7 @@
418
418
  "Freezed": "Freezed",
419
419
  "Callout": "Callout",
420
420
  "The_current_location_does_not_support_pasting": "The current location does not support pasting ",
421
- "Please_enter...": "Please enter...",
421
+ "Please_enter": "Please enter",
422
422
  "Combine_cell": "Combine cells",
423
423
  "Split_cell": "Split cell",
424
424
  "Row_number": "Row number",
@@ -418,7 +418,7 @@
418
418
  "Freezed": "Freezed",
419
419
  "Callout": "Callout",
420
420
  "The_current_location_does_not_support_pasting": "The current location does not support pasting ",
421
- "Please_enter...": "Please enter...",
421
+ "Please_enter": "Please enter",
422
422
  "Combine_cell": "Combine cells",
423
423
  "Split_cell": "Split cell",
424
424
  "Row_number": "Row number",
@@ -418,7 +418,7 @@
418
418
  "Freezed": "Заморожено",
419
419
  "Callout": "Выноска",
420
420
  "The_current_location_does_not_support_pasting": "Текущее местоположение не поддерживает вставку ",
421
- "Please_enter...": "Пожалуйста, введите...",
421
+ "Please_enter": "Please enter",
422
422
  "Combine_cell": "Объединить ячейки",
423
423
  "Split_cell": "Разделить ячейку",
424
424
  "Row_number": "Номер строки",
@@ -442,7 +442,7 @@
442
442
  "Are_you_sure_to_replace_all_number_xxx_in_this_document_with_yyy": "Вы уверены, что хотите заменить все {{number}} '{{originalWord}}' в этом документе на '{{replacedWord}}'?",
443
443
  "Are_you_sure_to_clear_all_number_xxx_in_this_document": "Вы уверены, что хотите очистить все {{number}} '{{originalWord}}' в этом документе?",
444
444
  "Search_not_found": "Не найдено",
445
- "Recent_visited": "Recent visited",
445
+ "Recent_visited": "Недавно посещенные",
446
446
  "The_document_does_not_exist": "Документ не существует",
447
447
  "Create_a_new_sdoc_file": "Создать новый файл sdoc",
448
448
  "Create": "Создать"
@@ -418,7 +418,7 @@
418
418
  "Freezed": "已冻结",
419
419
  "Callout": "高亮块",
420
420
  "The_current_location_does_not_support_pasting": "当前位置不支持粘贴",
421
- "Please_enter...": "请输入...",
421
+ "Please_enter": "请输入",
422
422
  "Combine_cell": "合并单元格",
423
423
  "Split_cell": "拆分单元格",
424
424
  "Row_number": "行数",