@seafile/sdoc-editor 0.3.13 → 0.3.14

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,4 +1,4 @@
1
- import { Editor, Path, Transforms } from '@seafile/slate';
1
+ import { Editor, Node, Path, Transforms } from '@seafile/slate';
2
2
  import { CALL_OUT } from '../../constants/element-type';
3
3
  import { findPath, focusEditor, generateEmptyElement, getSelectedElems, isRangeAcrossBlocks } from '../../core';
4
4
  import { CALLOUT_ALLOWED_INSIDE_TYPES, CALLOUT_COLOR_MAP } from './constant';
@@ -100,10 +100,10 @@ export const isFocusOnElement = (editor, element) => {
100
100
  const isSelectOnElement = Path.isAncestor(elementPath, editor === null || editor === void 0 ? void 0 : (_editor$selection = editor.selection) === null || _editor$selection === void 0 ? void 0 : (_editor$selection$anc = _editor$selection.anchor) === null || _editor$selection$anc === void 0 ? void 0 : _editor$selection$anc.path);
101
101
  return isSelectOnElement;
102
102
  };
103
- export const isCalloutContentEmpty = (editor, calloutEntry) => {
104
- const [, calloutPath] = calloutEntry;
105
- const contentString = Editor.string(editor, calloutPath);
106
- return contentString.length === 0;
103
+ export const isCalloutContentEmpty = calloutEntry => {
104
+ const [calloutNode] = calloutEntry;
105
+ const contentString = Node.string(calloutNode);
106
+ return calloutNode.children.length === 1 && contentString.length === 0;
107
107
  };
108
108
 
109
109
  // Insert a new element at new line in callout after current path
@@ -1,5 +1,5 @@
1
1
  import isHotkey from 'is-hotkey';
2
- import { PARAGRAPH, INSERT_POSITION } from '../../constants';
2
+ import { PARAGRAPH, INSERT_POSITION, CODE_BLOCK } from '../../constants';
3
3
  import { isSelectionAtBlockStart } from '../../core';
4
4
  import { getCalloutEntry, isCalloutContentEmpty, unwrapCallout } from './helper';
5
5
  import { insertElement } from '../../toolbar/side-toolbar/helpers';
@@ -15,23 +15,39 @@ const withCallout = editor => {
15
15
  const {
16
16
  insertFragment,
17
17
  deleteBackward,
18
- onHotKeyDown
18
+ onHotKeyDown,
19
+ insertData
19
20
  } = editor;
20
21
  const newEditor = editor;
21
22
  newEditor.deleteBackward = unit => {
22
23
  const calloutEntry = getCalloutEntry(editor);
23
24
  if (calloutEntry) {
24
- if (isSelectionAtBlockStart(editor) && isCalloutContentEmpty(editor, calloutEntry)) return;
25
+ if (isSelectionAtBlockStart(editor) && isCalloutContentEmpty(calloutEntry)) {
26
+ unwrapCallout(editor);
27
+ return;
28
+ }
25
29
  }
26
30
  return deleteBackward(unit);
27
31
  };
32
+ newEditor.insertData = data => {
33
+ if (getCalloutEntry(newEditor)) {
34
+ if (data.types.includes('text/code-block')) {
35
+ const eventBus = EventBus.getInstance();
36
+ eventBus.dispatch(INTERNAL_EVENT.DISPLAY_CALLOUT_UNSUPPORT_ALERT, CODE_BLOCK);
37
+ return;
38
+ }
39
+ }
40
+ return insertData(data);
41
+ };
28
42
  newEditor.insertFragment = data => {
29
- var _data$find;
30
- const eventBus = EventBus.getInstance();
31
- const unsupportType = (_data$find = data.find(node => !CALLOUT_ALLOWED_INSIDE_TYPES.includes(node.type))) === null || _data$find === void 0 ? void 0 : _data$find.type;
32
- if (unsupportType) {
33
- eventBus.dispatch(INTERNAL_EVENT.DISPLAY_CALLOUT_UNSUPPORT_ALERT, unsupportType);
34
- return;
43
+ if (getCalloutEntry(editor)) {
44
+ var _data$find;
45
+ const eventBus = EventBus.getInstance();
46
+ const unsupportType = (_data$find = data.find(node => !CALLOUT_ALLOWED_INSIDE_TYPES.includes(node.type))) === null || _data$find === void 0 ? void 0 : _data$find.type;
47
+ if (unsupportType) {
48
+ eventBus.dispatch(INTERNAL_EVENT.DISPLAY_CALLOUT_UNSUPPORT_ALERT, unsupportType);
49
+ return;
50
+ }
35
51
  }
36
52
  return insertFragment(data);
37
53
  };
@@ -40,16 +56,6 @@ const withCallout = editor => {
40
56
  insertElement(newEditor, PARAGRAPH, INSERT_POSITION.AFTER);
41
57
  return true;
42
58
  }
43
- if (isHotkey('enter', event)) {
44
- const calloutEntry = getCalloutEntry(editor);
45
- if (calloutEntry) {
46
- if (isCalloutContentEmpty(editor, calloutEntry)) {
47
- unwrapCallout(editor);
48
- event.preventDefault();
49
- return true;
50
- }
51
- }
52
- }
53
59
  return onHotKeyDown && onHotKeyDown(event);
54
60
  };
55
61
  return newEditor;
@@ -26,8 +26,10 @@ const ColorSelector = (_ref, ref) => {
26
26
  }, []);
27
27
  return /*#__PURE__*/React.createElement("div", {
28
28
  ref: selectorRef,
29
- className: "sdoc-callout-color-selector-container",
29
+ className: "sdoc-selector-gap-filler",
30
30
  contentEditable: false
31
+ }, /*#__PURE__*/React.createElement("div", {
32
+ className: "sdoc-callout-color-selector-container"
31
33
  }, /*#__PURE__*/React.createElement("ul", {
32
34
  className: "sdoc-color-selector-list"
33
35
  }, Object.values(CALLOUT_COLOR_MAP).map((_ref2, index) => {
@@ -46,6 +48,6 @@ const ColorSelector = (_ref, ref) => {
46
48
  }, isShowCheckedIcon(element, background_color) && /*#__PURE__*/React.createElement("i", {
47
49
  className: "sdoc-callout-color-checked-icon sdocfont sdoc-check-mark"
48
50
  }));
49
- })));
51
+ }))));
50
52
  };
51
53
  export default forwardRef(ColorSelector);
@@ -18,13 +18,21 @@
18
18
  pointer-events: none;
19
19
  }
20
20
 
21
- .sdoc-callout-color-selector-container {
21
+ .sdoc-selector-gap-filler {
22
+ position: absolute;
23
+ left: 0;
24
+ top: -40px;
25
+ width: 300px;
26
+ height: 100%;
27
+ z-index: 100;
28
+ }
29
+
30
+ .sdoc-selector-gap-filler .sdoc-callout-color-selector-container {
22
31
  position: absolute;
23
32
  padding: 10px;
24
- top: -39px;
33
+ top: -5px;
25
34
  left: 5px;
26
35
  background-color: #fff;
27
- box-shadow: -2px 0px 8px 2px #d0cfcf;
28
36
  border: 1px solid #eee;
29
37
  border-radius: 3px;
30
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.3.13",
3
+ "version": "0.3.14",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -414,5 +414,8 @@
414
414
  "New": "Nový",
415
415
  "Table_template": "Table template",
416
416
  "Jump_to_original_doc": "Jump to the original document",
417
- "Freezed": "Freezed"
417
+ "Freezed": "Freezed",
418
+ "Callout": "Callout",
419
+ "The_current_location_does_not_support_pasting": "The current location does not support pasting ",
420
+ "Please_enter...": "Please enter..."
418
421
  }
@@ -414,5 +414,8 @@
414
414
  "New": "Erstellen",
415
415
  "Table_template": "Table template",
416
416
  "Jump_to_original_doc": "Jump to the original document",
417
- "Freezed": "Freezed"
417
+ "Freezed": "Freezed",
418
+ "Callout": "Callout",
419
+ "The_current_location_does_not_support_pasting": "The current location does not support pasting ",
420
+ "Please_enter...": "Please enter..."
418
421
  }
@@ -414,5 +414,8 @@
414
414
  "New": "Nuevo",
415
415
  "Table_template": "Table template",
416
416
  "Jump_to_original_doc": "Jump to the original document",
417
- "Freezed": "Freezed"
417
+ "Freezed": "Freezed",
418
+ "Callout": "Callout",
419
+ "The_current_location_does_not_support_pasting": "The current location does not support pasting ",
420
+ "Please_enter...": "Please enter..."
418
421
  }
@@ -414,5 +414,8 @@
414
414
  "New": "Créer",
415
415
  "Table_template": "Table template",
416
416
  "Jump_to_original_doc": "Jump to the original document",
417
- "Freezed": "Freezed"
417
+ "Freezed": "Freezed",
418
+ "Callout": "Callout",
419
+ "The_current_location_does_not_support_pasting": "The current location does not support pasting ",
420
+ "Please_enter...": "Please enter..."
418
421
  }
@@ -414,5 +414,8 @@
414
414
  "New": "Nuovo",
415
415
  "Table_template": "Table template",
416
416
  "Jump_to_original_doc": "Jump to the original document",
417
- "Freezed": "Freezed"
417
+ "Freezed": "Freezed",
418
+ "Callout": "Callout",
419
+ "The_current_location_does_not_support_pasting": "The current location does not support pasting ",
420
+ "Please_enter...": "Please enter..."
418
421
  }
@@ -281,7 +281,7 @@
281
281
  "Revision": "Пересмотр",
282
282
  "Error": "Ошибка",
283
283
  "Start_revise": "Начать пересмотр",
284
- "Revise": "Revise",
284
+ "Revise": "Пересмотр",
285
285
  "Failed_to_execute_operation_on_server": "Не удалось выполнить операцию на сервере, текущая операция отменена.",
286
286
  "Start_revise_tip": "Создайте временный документ и внесите в него изменения, объедините его обратно после просмотра изменений",
287
287
  "Load_doc_content_error": "Ошибка загрузки содержимого документа",
@@ -414,5 +414,8 @@
414
414
  "New": "Новый",
415
415
  "Table_template": "Шаблон таблицы",
416
416
  "Jump_to_original_doc": "Перейти к исходному документу",
417
- "Freezed": "Freezed"
417
+ "Freezed": "Заморожено",
418
+ "Callout": "Callout",
419
+ "The_current_location_does_not_support_pasting": "The current location does not support pasting ",
420
+ "Please_enter...": "Please enter..."
418
421
  }