@seafile/sdoc-editor 1.0.47 → 1.0.48
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.
- package/dist/basic-sdk/extension/plugins/image/helpers.js +18 -2
- package/dist/basic-sdk/extension/plugins/image/plugin.js +27 -16
- package/dist/basic-sdk/extension/plugins/table/helpers.js +22 -2
- package/dist/basic-sdk/extension/plugins/table/menu/table-context-menu/index.js +2 -2
- package/package.json +1 -1
|
@@ -5,10 +5,10 @@ import { ReactEditor } from '@seafile/slate-react';
|
|
|
5
5
|
import slugId from 'slugid';
|
|
6
6
|
import context from '../../../../context';
|
|
7
7
|
import EventBus from '../../../utils/event-bus';
|
|
8
|
-
import { generateEmptyElement, getNodeType, isTextNode, getParentNode, focusEditor } from '../../core';
|
|
8
|
+
import { generateEmptyElement, getNodeType, isTextNode, getParentNode, focusEditor, getAboveBlockNode } from '../../core';
|
|
9
9
|
import { isList } from '../../toolbar/side-toolbar/helpers';
|
|
10
10
|
import { COMMENT_EDITOR, INTERNAL_EVENT } from '../../../constants';
|
|
11
|
-
import { CODE_BLOCK, ELEMENT_TYPE, IMAGE, IMAGE_BLOCK, INSERT_POSITION, SUBTITLE, TITLE } from '../../constants';
|
|
11
|
+
import { CODE_BLOCK, ELEMENT_TYPE, IMAGE, IMAGE_BLOCK, INSERT_POSITION, PARAGRAPH, SUBTITLE, TITLE } from '../../constants';
|
|
12
12
|
import base64ToUnit8Array from '../../../../utils/base64-to-unit8array';
|
|
13
13
|
export const isInsertImageMenuDisabled = (editor, readonly) => {
|
|
14
14
|
if (readonly) return true;
|
|
@@ -57,6 +57,22 @@ export const insertImage = function (editor, srcList, selection) {
|
|
|
57
57
|
});
|
|
58
58
|
const validSelection = selection || editor.selection;
|
|
59
59
|
let path = Editor.path(editor, validSelection);
|
|
60
|
+
const aboveNodeEntry = getAboveBlockNode(editor);
|
|
61
|
+
const isEmptyParagraph = aboveNodeEntry[0].type === PARAGRAPH && Node.string(aboveNodeEntry[0]).length === 0;
|
|
62
|
+
if (imageNodes.length === 1 && isEmptyParagraph) {
|
|
63
|
+
const imageNode = imageNodes[0];
|
|
64
|
+
Transforms.insertNodes(editor, imageNode, {
|
|
65
|
+
at: validSelection
|
|
66
|
+
});
|
|
67
|
+
Transforms.setNodes(editor, {
|
|
68
|
+
type: IMAGE_BLOCK
|
|
69
|
+
}, {
|
|
70
|
+
at: validSelection
|
|
71
|
+
});
|
|
72
|
+
const imageEndSelection = Path.next(Path.next(path));
|
|
73
|
+
focusEditor(editor, imageEndSelection);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
60
76
|
if (position === INSERT_POSITION.AFTER) {
|
|
61
77
|
if (isList(editor, path)) {
|
|
62
78
|
const targetPath = path.slice(0, -2);
|
|
@@ -3,7 +3,7 @@ import toaster from '../../../../components/toast';
|
|
|
3
3
|
import context from '../../../../context';
|
|
4
4
|
import EventBus from '../../../utils/event-bus';
|
|
5
5
|
import { insertImage, hasSdocImages, getImageData, queryCopyMoveProgressView, resetCursor, isInsertImageMenuDisabled, getSingleImageFromFragment } from './helpers';
|
|
6
|
-
import { focusEditor, generateEmptyElement, isBlockAboveEmpty } from '../../core';
|
|
6
|
+
import { focusEditor, generateEmptyElement, getLastChildPath, getSelectedNodeEntryByType, isBlockAboveEmpty, isSelectionAtBlockStart } from '../../core';
|
|
7
7
|
import { getErrorMsg } from '../../../../utils';
|
|
8
8
|
import { getSlateFragmentAttribute } from '../../../utils/document-utils';
|
|
9
9
|
import { INSERT_POSITION, CLIPBOARD_FORMAT_KEY, CLIPBOARD_ORIGIN_SDOC_KEY, IMAGE, IMAGE_BLOCK, PARAGRAPH, ELEMENT_TYPE } from '../../constants';
|
|
@@ -123,28 +123,39 @@ const withImage = editor => {
|
|
|
123
123
|
const {
|
|
124
124
|
selection
|
|
125
125
|
} = editor;
|
|
126
|
-
|
|
126
|
+
if (!selection) return deleteBackward(unit);
|
|
127
127
|
const point = Editor.before(editor, selection, {
|
|
128
128
|
distance: 1
|
|
129
129
|
});
|
|
130
130
|
if (!point) return deleteBackward(unit);
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (isPerviousNodeImage && Range.isCollapsed(selection) && isBlockAboveEmpty(editor) && !Path.isCommon(path, selection.anchor.path)) {
|
|
134
|
-
deleteBackward(unit);
|
|
135
|
-
focusEditor(newEditor, Editor.end(newEditor, focusPoint));
|
|
136
|
-
return;
|
|
131
|
+
if (!Range.isCollapsed(selection)) {
|
|
132
|
+
return deleteBackward(unit);
|
|
137
133
|
}
|
|
138
|
-
if (
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
});
|
|
134
|
+
if (isSelectionAtBlockStart(editor)) {
|
|
135
|
+
const path = selection.anchor.path;
|
|
136
|
+
const beforePath = [path[0] - 1];
|
|
137
|
+
const beforeBlock = Editor.node(editor, beforePath);
|
|
138
|
+
if (beforeBlock && beforeBlock[0].type === IMAGE_BLOCK) {
|
|
139
|
+
focusEditor(editor, [...beforePath, 1]);
|
|
145
140
|
return;
|
|
146
141
|
}
|
|
147
|
-
|
|
142
|
+
}
|
|
143
|
+
const imageBlock = getSelectedNodeEntryByType(editor, IMAGE_BLOCK);
|
|
144
|
+
if (imageBlock) {
|
|
145
|
+
const path = selection.anchor.path;
|
|
146
|
+
const deletePath = [path[0]];
|
|
147
|
+
Transforms.removeNodes(editor, {
|
|
148
|
+
at: deletePath
|
|
149
|
+
});
|
|
150
|
+
const beforeEntry = Editor.node(editor, Path.previous(deletePath));
|
|
151
|
+
const selectPath = getLastChildPath(beforeEntry);
|
|
152
|
+
const endOfFirstNode = Editor.end(editor, selectPath);
|
|
153
|
+
const range = {
|
|
154
|
+
anchor: endOfFirstNode,
|
|
155
|
+
focus: endOfFirstNode
|
|
156
|
+
};
|
|
157
|
+
focusEditor(editor, range);
|
|
158
|
+
return;
|
|
148
159
|
}
|
|
149
160
|
deleteBackward(unit);
|
|
150
161
|
};
|
|
@@ -577,8 +577,10 @@ export const removeTableElement = (editor, type) => {
|
|
|
577
577
|
return;
|
|
578
578
|
}
|
|
579
579
|
for (let i = minRowIndex; i <= maxRowIndex; i++) {
|
|
580
|
-
|
|
581
|
-
|
|
580
|
+
queueMicrotask(() => {
|
|
581
|
+
Transforms.removeNodes(editor, {
|
|
582
|
+
at: [...tablePath, minRowIndex]
|
|
583
|
+
});
|
|
582
584
|
});
|
|
583
585
|
}
|
|
584
586
|
const focusPath = [...tablePath, minRowIndex === 0 ? 0 : minRowIndex - 1, cellIndex];
|
|
@@ -1772,9 +1774,27 @@ export const isHideDragHandlerLine = (editor, displayType, table, cellPath, isDr
|
|
|
1772
1774
|
if (displayType === DRAG_HANDLER_COLUMN && cellIndex > 0) {
|
|
1773
1775
|
const prevCell = table.children[rowIndex].children[cellIndex - 1];
|
|
1774
1776
|
preCellDom = ReactEditor.toDOMNode(editor, prevCell);
|
|
1777
|
+
|
|
1778
|
+
// Check if there are merged cells in the columns before and after the drag line
|
|
1779
|
+
const beforeLineColumnHasCombined = table.children.find(item => {
|
|
1780
|
+
const cell = item.children[cellIndex - 1];
|
|
1781
|
+
return cell.children.length > 1;
|
|
1782
|
+
});
|
|
1783
|
+
const afterLineColumnHasCombined = table.children.find(item => {
|
|
1784
|
+
const cell = item.children[cellIndex];
|
|
1785
|
+
return (cell === null || cell === void 0 ? void 0 : cell.is_combined) === true;
|
|
1786
|
+
});
|
|
1787
|
+
if (beforeLineColumnHasCombined && afterLineColumnHasCombined) return true;
|
|
1775
1788
|
} else if (displayType === DRAG_HANDLER_ROW && rowIndex > 0) {
|
|
1776
1789
|
const prevCell = table.children[rowIndex - 1].children[cellIndex];
|
|
1777
1790
|
preCellDom = ReactEditor.toDOMNode(editor, prevCell);
|
|
1791
|
+
|
|
1792
|
+
// Check whether there are merged cells in the rows before and after the drag line
|
|
1793
|
+
const beforeLineRow = table.children[rowIndex - 1];
|
|
1794
|
+
const afterLineRow = table.children[rowIndex];
|
|
1795
|
+
const beforeLineRowHasCombined = beforeLineRow.children.find(item => item.children.length > 1);
|
|
1796
|
+
const afterLineRowHasCombined = afterLineRow.children.find(item => (item === null || item === void 0 ? void 0 : item.is_combined) === true);
|
|
1797
|
+
if (beforeLineRowHasCombined && afterLineRowHasCombined) return true;
|
|
1778
1798
|
}
|
|
1779
1799
|
|
|
1780
1800
|
// Check is above cell selected
|
|
@@ -46,7 +46,7 @@ class TableContextMenu extends React.Component {
|
|
|
46
46
|
} = this.props;
|
|
47
47
|
insertTableElement(editor, type, position, count);
|
|
48
48
|
});
|
|
49
|
-
_defineProperty(this, "
|
|
49
|
+
_defineProperty(this, "removeTableElements", type => {
|
|
50
50
|
const {
|
|
51
51
|
editor
|
|
52
52
|
} = this.props;
|
|
@@ -54,7 +54,7 @@ class TableContextMenu extends React.Component {
|
|
|
54
54
|
});
|
|
55
55
|
_defineProperty(this, "renderRemoveBtn", (type, title) => {
|
|
56
56
|
return /*#__PURE__*/React.createElement("button", {
|
|
57
|
-
onMouseDown: this.
|
|
57
|
+
onMouseDown: this.removeTableElements.bind(this, type),
|
|
58
58
|
className: "dropdown-item"
|
|
59
59
|
}, this.props.t(title));
|
|
60
60
|
});
|