@seafile/sdoc-editor 0.4.8 → 0.4.9

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.
@@ -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;
@@ -1,6 +1,8 @@
1
+ import withParagraph from './plugin';
1
2
  import { PARAGRAPH } from '../../constants';
2
3
  import { renderParagraph } from './render-elem';
3
4
  const ParagraphPlugin = {
5
+ editorPlugin: withParagraph,
4
6
  type: PARAGRAPH,
5
7
  renderElements: [renderParagraph]
6
8
  };
@@ -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'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.4.8",
3
+ "version": "0.4.9",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",