@seafile/sdoc-editor 0.4.8 → 0.4.10
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/blockquote/helpers.js +1 -2
- package/dist/basic-sdk/extension/plugins/blockquote/menu/index.js +2 -0
- package/dist/basic-sdk/extension/plugins/blockquote/plugin.js +3 -4
- package/dist/basic-sdk/extension/plugins/index.js +1 -1
- package/dist/basic-sdk/extension/plugins/list/transforms/move-list-items.js +1 -1
- package/dist/basic-sdk/extension/plugins/markdown/plugin.js +2 -5
- package/dist/basic-sdk/extension/plugins/paragraph/index.js +2 -0
- package/dist/basic-sdk/extension/plugins/paragraph/plugin/index.js +75 -0
- package/dist/basic-sdk/extension/plugins/paragraph/render-elem.js +5 -1
- package/dist/basic-sdk/extension/plugins/search-replace/popover/index.js +1 -0
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
2
2
|
import { Editor, Transforms, Element } 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
|
-
import {
|
|
5
|
+
import { getNodeType } from '../../core';
|
|
6
6
|
export const isMenuDisabled = (editor, readonly) => {
|
|
7
7
|
if (readonly) return true;
|
|
8
8
|
if (editor.selection == null) return true;
|
|
@@ -64,7 +64,6 @@ export const setBlockQuoteType = (editor, active) => {
|
|
|
64
64
|
}
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
|
-
focusEditor(editor);
|
|
68
67
|
};
|
|
69
68
|
export const getFormattedElements = data => {
|
|
70
69
|
const elements = [];
|
|
@@ -3,6 +3,7 @@ import React from 'react';
|
|
|
3
3
|
import { BLOCKQUOTE, MENUS_CONFIG_MAP } from '../../../constants';
|
|
4
4
|
import { MenuItem } from '../../../commons';
|
|
5
5
|
import { getBlockQuoteType, isMenuDisabled, setBlockQuoteType } from '../helpers';
|
|
6
|
+
import { focusEditor } from '../../../core';
|
|
6
7
|
class QuoteMenu extends React.Component {
|
|
7
8
|
constructor() {
|
|
8
9
|
super(...arguments);
|
|
@@ -25,6 +26,7 @@ class QuoteMenu extends React.Component {
|
|
|
25
26
|
} = this.props;
|
|
26
27
|
const active = this.isActive(editor);
|
|
27
28
|
setBlockQuoteType(editor, active);
|
|
29
|
+
focusEditor(editor);
|
|
28
30
|
};
|
|
29
31
|
}
|
|
30
32
|
render() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Editor, Element, Transforms, Node } from '@seafile/slate';
|
|
1
|
+
import { Editor, Element, Transforms, Node, Path } from '@seafile/slate';
|
|
2
2
|
import { focusEditor, generateDefaultText, getSelectedNodeByType, isSelectionAtBlockStart } from '../../core';
|
|
3
3
|
import { BLOCKQUOTE, PARAGRAPH, CODE_BLOCK, TABLE } from '../../constants';
|
|
4
4
|
import { setBlockQuoteType, getFormattedElements, getFormattedRestElements } from './helpers';
|
|
@@ -27,12 +27,11 @@ const withBlockquote = editor => {
|
|
|
27
27
|
const isAtEnd = currentLineEntry[1].slice(-1)[0] === quoteBlockEntry[0].children.length - 1;
|
|
28
28
|
if (isAtEnd) {
|
|
29
29
|
const isEmptyLine = !(currentLineEntry && Editor.string(newEditor, currentLineEntry[1]).length);
|
|
30
|
-
const movePath = quoteBlockEntry[1];
|
|
31
|
-
movePath.push(movePath.pop() + 1);
|
|
32
30
|
if (isEmptyLine) {
|
|
31
|
+
const nextPath = Path.next(quoteBlockEntry[1]);
|
|
33
32
|
Transforms.moveNodes(newEditor, {
|
|
34
33
|
at: currentLineEntry[1],
|
|
35
|
-
to:
|
|
34
|
+
to: nextPath
|
|
36
35
|
});
|
|
37
36
|
return;
|
|
38
37
|
}
|
|
@@ -16,6 +16,6 @@ import FileLinkPlugin from './file-link';
|
|
|
16
16
|
import ParagraphPlugin from './paragraph';
|
|
17
17
|
import CalloutPlugin from './callout';
|
|
18
18
|
import SearchReplacePlugin from './search-replace';
|
|
19
|
-
const Plugins = [MarkDownPlugin, HtmlPlugin, HeaderPlugin, LinkPlugin, BlockquotePlugin, ListPlugin, CheckListPlugin, CodeBlockPlugin, ImagePlugin, TablePlugin, TextPlugin, TextAlignPlugin, FontPlugin, SdocLinkPlugin, FileLinkPlugin, CalloutPlugin, SearchReplacePlugin];
|
|
19
|
+
const Plugins = [MarkDownPlugin, HtmlPlugin, HeaderPlugin, LinkPlugin, BlockquotePlugin, ListPlugin, CheckListPlugin, CodeBlockPlugin, ImagePlugin, TablePlugin, TextPlugin, TextAlignPlugin, FontPlugin, SdocLinkPlugin, ParagraphPlugin, FileLinkPlugin, CalloutPlugin, SearchReplacePlugin];
|
|
20
20
|
export default Plugins;
|
|
21
21
|
export { MarkDownPlugin, HeaderPlugin, LinkPlugin, BlockquotePlugin, ListPlugin, CheckListPlugin, CodeBlockPlugin, ImagePlugin, TablePlugin, TextPlugin, HtmlPlugin, TextAlignPlugin, FontPlugin, SdocLinkPlugin, ParagraphPlugin, FileLinkPlugin, CalloutPlugin, SearchReplacePlugin };
|
|
@@ -39,7 +39,7 @@ export const moveListItems = function (editor) {
|
|
|
39
39
|
const licPath = licPathRef.unref();
|
|
40
40
|
if (!licPath) return;
|
|
41
41
|
const listItem = Editor.parent(editor, licPath);
|
|
42
|
-
if (!listItem) return;
|
|
42
|
+
if (!listItem || listItem[1].length === 0) return;
|
|
43
43
|
const parentList = Editor.parent(editor, listItem[1]);
|
|
44
44
|
if (!parentList) return;
|
|
45
45
|
let _moved = false;
|
|
@@ -3,6 +3,7 @@ import { Editor, Transforms, Range } from '@seafile/slate';
|
|
|
3
3
|
import { toggleList } from '../list/transforms';
|
|
4
4
|
import { getSelectedNodeByType } from '../../core';
|
|
5
5
|
import { HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, UNORDERED_LIST, BLOCKQUOTE, TEXT_STYLE_MAP, PARAGRAPH } from '../../constants';
|
|
6
|
+
import { setBlockQuoteType } from '../blockquote/helpers';
|
|
6
7
|
const KEY_TO_TYPE_FOR_SPACE = {
|
|
7
8
|
// Title shortcut
|
|
8
9
|
'#': HEADER1,
|
|
@@ -163,11 +164,7 @@ const withMarkDown = editor => {
|
|
|
163
164
|
return;
|
|
164
165
|
}
|
|
165
166
|
if (type === BLOCKQUOTE) {
|
|
166
|
-
|
|
167
|
-
type
|
|
168
|
-
}, {
|
|
169
|
-
mode: 'highest'
|
|
170
|
-
});
|
|
167
|
+
setBlockQuoteType(editor, false);
|
|
171
168
|
return;
|
|
172
169
|
}
|
|
173
170
|
Transforms.setNodes(editor, {
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import isHotkey from 'is-hotkey';
|
|
2
|
+
import { Editor, Range, Transforms } from '@seafile/slate';
|
|
3
|
+
import { PARAGRAPH } from '../../../constants';
|
|
4
|
+
const withParagraph = editor => {
|
|
5
|
+
const {
|
|
6
|
+
handleTab,
|
|
7
|
+
insertText,
|
|
8
|
+
deleteBackward
|
|
9
|
+
} = editor;
|
|
10
|
+
const newEditor = editor;
|
|
11
|
+
newEditor.handleTab = event => {
|
|
12
|
+
var _selectedNode$;
|
|
13
|
+
const {
|
|
14
|
+
selection
|
|
15
|
+
} = newEditor;
|
|
16
|
+
if (!selection) return;
|
|
17
|
+
if (!Range.isCollapsed(selection)) return;
|
|
18
|
+
const selectedNode = Editor.node(newEditor, selection, {
|
|
19
|
+
depth: 1
|
|
20
|
+
});
|
|
21
|
+
if ((selectedNode === null || selectedNode === void 0 ? void 0 : (_selectedNode$ = selectedNode[0]) === null || _selectedNode$ === void 0 ? void 0 : _selectedNode$.type) === PARAGRAPH) {
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
const path = Editor.path(newEditor, selection);
|
|
24
|
+
const point = Editor.point(newEditor, selection);
|
|
25
|
+
const isStart = Editor.isStart(newEditor, point, [path[0]]);
|
|
26
|
+
if (isStart) {
|
|
27
|
+
let indent;
|
|
28
|
+
if (isHotkey('shift+tab', event)) {
|
|
29
|
+
indent = false;
|
|
30
|
+
}
|
|
31
|
+
if (isHotkey('tab', event)) {
|
|
32
|
+
indent = true;
|
|
33
|
+
}
|
|
34
|
+
Transforms.setNodes(newEditor, {
|
|
35
|
+
indent: indent
|
|
36
|
+
}, {
|
|
37
|
+
at: [path[0]]
|
|
38
|
+
});
|
|
39
|
+
} else {
|
|
40
|
+
if (isHotkey('tab', event)) insertText(' ');
|
|
41
|
+
}
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
return handleTab(event);
|
|
45
|
+
};
|
|
46
|
+
newEditor.deleteBackward = unit => {
|
|
47
|
+
const {
|
|
48
|
+
selection
|
|
49
|
+
} = newEditor;
|
|
50
|
+
if (!selection) return;
|
|
51
|
+
const [selectedNode = {}] = Editor.node(newEditor, selection, {
|
|
52
|
+
depth: 1
|
|
53
|
+
});
|
|
54
|
+
const {
|
|
55
|
+
type,
|
|
56
|
+
indent
|
|
57
|
+
} = selectedNode;
|
|
58
|
+
if (Range.isCollapsed(selection) && type === PARAGRAPH && indent) {
|
|
59
|
+
const path = Editor.path(newEditor, selection);
|
|
60
|
+
const point = Editor.point(newEditor, selection);
|
|
61
|
+
const isStart = Editor.isStart(newEditor, point, [path[0]]);
|
|
62
|
+
if (isStart) {
|
|
63
|
+
Transforms.setNodes(newEditor, {
|
|
64
|
+
indent: false
|
|
65
|
+
}, {
|
|
66
|
+
at: [path[0]]
|
|
67
|
+
});
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return deleteBackward(unit);
|
|
72
|
+
};
|
|
73
|
+
return newEditor;
|
|
74
|
+
};
|
|
75
|
+
export default withParagraph;
|
|
@@ -10,6 +10,9 @@ const Paragraph = _ref => {
|
|
|
10
10
|
attributes,
|
|
11
11
|
children
|
|
12
12
|
} = _ref;
|
|
13
|
+
const {
|
|
14
|
+
indent
|
|
15
|
+
} = element;
|
|
13
16
|
const editor = useSlateStatic();
|
|
14
17
|
let isShowPlaceHolder = false;
|
|
15
18
|
if (editor.children.length === 1) {
|
|
@@ -20,7 +23,8 @@ const Paragraph = _ref => {
|
|
|
20
23
|
isShowPlaceHolder = Node.string(element) === '' && (node === null || node === void 0 ? void 0 : node.id) === (element === null || element === void 0 ? void 0 : element.id) && !isComposing;
|
|
21
24
|
}
|
|
22
25
|
const style = {
|
|
23
|
-
textAlign: element.align
|
|
26
|
+
textAlign: element.align,
|
|
27
|
+
paddingLeft: indent ? '28px' : ''
|
|
24
28
|
};
|
|
25
29
|
const newAttributes = _objectSpread(_objectSpread({}, attributes), typeof attributes.onMouseEnter === 'function' && {
|
|
26
30
|
'data-root': 'true'
|
|
@@ -80,6 +80,7 @@ const SearchReplacePopover = _ref => {
|
|
|
80
80
|
}, [editor, handleDrawHighlight, handleDrawHighlightLister, highlightInfos.length, searchContent]);
|
|
81
81
|
const handleSearchInputChange = useCallback(e => {
|
|
82
82
|
const keyword = e.target.value;
|
|
83
|
+
shouldScrollIntoView.current = true;
|
|
83
84
|
setSearchContent(keyword);
|
|
84
85
|
handleDrawHighlight(editor, keyword);
|
|
85
86
|
setCurrentSelectIndex(0);
|