@seafile/sdoc-editor 0.5.23 → 0.5.24

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, Element, Transforms, Node, Path } from '@seafile/slate';
1
+ import { Editor, Element, Transforms, Node, Path, Range } from '@seafile/slate';
2
2
  import { focusEditor, generateDefaultText, generateEmptyElement, getSelectedNodeByType, getSelectedNodeEntryByType, isBlockAboveEmpty, isSelectionAtBlockStart } from '../../core';
3
3
  import { BLOCKQUOTE, PARAGRAPH, CODE_BLOCK, TABLE } from '../../constants';
4
4
  import { getFormattedElements, getFormattedRestElements } from './helpers';
@@ -106,6 +106,20 @@ const withBlockquote = editor => {
106
106
 
107
107
  // Insert elements of quote block
108
108
  if (restElements.length !== 0) {
109
+ if (Range.isCollapsed(editor.selection)) {
110
+ const paragraphEntry = getSelectedNodeEntryByType(newEditor, PARAGRAPH);
111
+ if (paragraphEntry) {
112
+ const parentNodeEntry = Editor.parent(editor, paragraphEntry[1]);
113
+ if (parentNodeEntry && parentNodeEntry[0].type === BLOCKQUOTE) {
114
+ if (!Node.string(paragraphEntry[0]).length) {
115
+ insertFragment(data);
116
+ return Transforms.removeNodes(newEditor, {
117
+ at: paragraphEntry[1]
118
+ });
119
+ }
120
+ }
121
+ }
122
+ }
109
123
  // Insert text when inserting a single line paragraph
110
124
  if (restElements.length === 1 && restElements[0].type === PARAGRAPH) {
111
125
  const string = Node.string(restElements[0]);
@@ -1,7 +1,7 @@
1
1
  import isHotkey from 'is-hotkey';
2
- import { Editor, Transforms } from '@seafile/slate';
3
- import { PARAGRAPH, INSERT_POSITION, CODE_BLOCK } from '../../constants';
4
- import { isSelectionAtBlockStart } from '../../core';
2
+ import { Editor, Node, Range, Transforms } from '@seafile/slate';
3
+ import { PARAGRAPH, INSERT_POSITION, CODE_BLOCK, CALL_OUT } from '../../constants';
4
+ import { getSelectedNodeEntryByType, isSelectionAtBlockStart } from '../../core';
5
5
  import { deleteCalloutIcon, getCalloutEntry, isCalloutContentEmpty, unwrapCallout } from './helper';
6
6
  import { insertElement } from '../../toolbar/side-toolbar/helpers';
7
7
  import EventBus from '../../../utils/event-bus';
@@ -49,6 +49,21 @@ const withCallout = editor => {
49
49
  newEditor.insertFragment = data => {
50
50
  if (getCalloutEntry(editor)) {
51
51
  var _data$find;
52
+ // Prvent insert new line when insert fragment
53
+ if (Range.isCollapsed(editor.selection)) {
54
+ const paragraphEntry = getSelectedNodeEntryByType(newEditor, PARAGRAPH);
55
+ if (paragraphEntry) {
56
+ const parentNodeEntry = Editor.parent(editor, paragraphEntry[1]);
57
+ if (parentNodeEntry && parentNodeEntry[0].type === CALL_OUT) {
58
+ if (!Node.string(paragraphEntry[0]).length) {
59
+ insertFragment(data);
60
+ return Transforms.removeNodes(newEditor, {
61
+ at: paragraphEntry[1]
62
+ });
63
+ }
64
+ }
65
+ }
66
+ }
52
67
  const eventBus = EventBus.getInstance();
53
68
  const unsupportType = (_data$find = data.find(node => !CALLOUT_ALLOWED_INSIDE_TYPES.includes(node.type))) === null || _data$find === void 0 ? void 0 : _data$find.type;
54
69
  if (unsupportType) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.5.23",
3
+ "version": "0.5.24",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",