@seafile/sdoc-editor 0.2.5 → 0.2.6

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,9 +1,10 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
3
- import { Editor, Element } from '@seafile/slate';
4
- import { CHECK_LIST_ITEM, CODE_BLOCK, CODE_LINE, PARAGRAPH, TABLE } from '../../constants';
5
- import { getSelectedNodeByType } from '../../core';
3
+ import { Editor, Element, Node, Range, Text } from '@seafile/slate';
4
+ import { CHECK_LIST_ITEM, CODE_BLOCK, CODE_LINE, LIST_ITEM, PARAGRAPH, TABLE } from '../../constants';
5
+ import { isRangeAcrossBlocks } from '../../core';
6
6
  import { toggleList } from './transforms';
7
+ import { getListTypes } from './queries';
7
8
  export var isMenuDisabled = function isMenuDisabled(editor, readonly) {
8
9
  if (readonly) return true;
9
10
  if (editor.selection == null) return true;
@@ -35,9 +36,48 @@ export var isMenuDisabled = function isMenuDisabled(editor, readonly) {
35
36
  return false;
36
37
  };
37
38
  export var getListType = function getListType(editor, type) {
38
- var node = getSelectedNodeByType(editor, type);
39
- if (!node) return PARAGRAPH;
40
- return node.type;
39
+ var selection = editor.selection;
40
+ if (!selection) return;
41
+ var selectedListNodeEntry;
42
+ if (Range.isCollapsed(selection)) {
43
+ var _Editor$nodes = Editor.nodes(editor, {
44
+ match: function match(node) {
45
+ return getListTypes().includes(node.type);
46
+ },
47
+ mode: 'lowest'
48
+ }),
49
+ _Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
50
+ nodeEntry = _Editor$nodes2[0];
51
+ selectedListNodeEntry = nodeEntry;
52
+ } else {
53
+ var anchor = selection.anchor,
54
+ focus = selection.focus;
55
+ var commonNodeEntry = Node.common(editor, anchor.path, focus.path);
56
+ // Select condition:
57
+ // 1. Select in one list
58
+ // 2. Select in one list item
59
+ // 3. Select in one line
60
+ if (getListTypes().includes(commonNodeEntry[0].type)) {
61
+ // Select in one list
62
+ selectedListNodeEntry = commonNodeEntry;
63
+ } else if (commonNodeEntry[0].type === LIST_ITEM) {
64
+ // Select in one list item
65
+ selectedListNodeEntry = Editor.parent(editor, commonNodeEntry[1]);
66
+ } else if (Text.isText(commonNodeEntry[0])) {
67
+ // Select in one line
68
+ var _Editor$nodes3 = Editor.nodes(editor, {
69
+ at: commonNodeEntry[1],
70
+ match: function match(node) {
71
+ return getListTypes().includes(node.type);
72
+ },
73
+ mode: 'lowest'
74
+ }),
75
+ _Editor$nodes4 = _slicedToArray(_Editor$nodes3, 1),
76
+ _nodeEntry2 = _Editor$nodes4[0];
77
+ selectedListNodeEntry = _nodeEntry2;
78
+ }
79
+ }
80
+ return selectedListNodeEntry ? selectedListNodeEntry[0].type : PARAGRAPH;
41
81
  };
42
82
  export var setListType = function setListType(editor, type) {
43
83
  toggleList(editor, type);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",