@seafile/sdoc-editor 3.0.160 → 3.0.161

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.
@@ -87,6 +87,11 @@ var withCallout = function withCallout(editor) {
87
87
  // Close color picker
88
88
  var eventBus = _eventBus["default"].getInstance();
89
89
  eventBus.dispatch(_constants.INTERNAL_EVENT.CLOSE_CALLOUT_COLOR_PICKER);
90
+ if ((0, _isHotkey["default"])('tab', event) || (0, _isHotkey["default"])('shift+tab', event)) {
91
+ event.preventDefault();
92
+ newEditor.handleTab && newEditor.handleTab(event);
93
+ return true;
94
+ }
90
95
  if ((0, _isHotkey["default"])('mod+enter', event)) {
91
96
  (0, _helpers.insertElement)(newEditor, _constants2.PARAGRAPH, _constants2.INSERT_POSITION.AFTER);
92
97
  return true;
@@ -20,18 +20,30 @@ var withParagraph = function withParagraph(editor) {
20
20
  insertBreak = editor.insertBreak;
21
21
  var newEditor = editor;
22
22
  newEditor.handleTab = function (event) {
23
- var _selectedNode$;
24
23
  var selection = newEditor.selection;
25
- if (!selection) return;
26
- if (!_slate.Range.isCollapsed(selection)) return;
27
- var selectedNode = _slate.Editor.node(newEditor, selection, {
28
- depth: 1
29
- });
30
- if ((selectedNode === null || selectedNode === void 0 ? void 0 : (_selectedNode$ = selectedNode[0]) === null || _selectedNode$ === void 0 ? void 0 : _selectedNode$.type) === _constants.PARAGRAPH) {
24
+ if (!selection) {
25
+ handleTab && handleTab(event);
26
+ return;
27
+ }
28
+ if (!_slate.Range.isCollapsed(selection)) {
29
+ handleTab && handleTab(event);
30
+ return;
31
+ }
32
+ var _Editor$nodes = _slate.Editor.nodes(newEditor, {
33
+ at: selection,
34
+ match: function match(n) {
35
+ return n.type === _constants.PARAGRAPH;
36
+ },
37
+ mode: 'lowest'
38
+ }),
39
+ _Editor$nodes2 = (0, _slicedToArray2["default"])(_Editor$nodes, 1),
40
+ selectedParagraphEntry = _Editor$nodes2[0];
41
+ if (selectedParagraphEntry) {
31
42
  event.preventDefault();
32
- var path = _slate.Editor.path(newEditor, selection);
43
+ var _selectedParagraphEnt = (0, _slicedToArray2["default"])(selectedParagraphEntry, 2),
44
+ path = _selectedParagraphEnt[1];
33
45
  var point = _slate.Editor.point(newEditor, selection);
34
- var isStart = _slate.Editor.isStart(newEditor, point, [path[0]]);
46
+ var isStart = _slate.Editor.isStart(newEditor, point, path);
35
47
  if (isStart) {
36
48
  var indent;
37
49
  if ((0, _isHotkey["default"])('shift+tab', event)) {
@@ -43,35 +55,42 @@ var withParagraph = function withParagraph(editor) {
43
55
  _slate.Transforms.setNodes(newEditor, {
44
56
  indent: indent
45
57
  }, {
46
- at: [path[0]]
58
+ at: path
47
59
  });
48
60
  } else {
49
61
  if ((0, _isHotkey["default"])('tab', event)) insertText(' ');
50
62
  }
51
63
  return;
52
64
  }
53
- return handleTab(event);
65
+ return handleTab && handleTab(event);
54
66
  };
55
67
  newEditor.deleteBackward = function (unit) {
56
68
  var selection = newEditor.selection;
57
69
  if (!selection) return;
58
- var _Editor$node = _slate.Editor.node(newEditor, selection, {
59
- depth: 1
70
+ var _Editor$nodes3 = _slate.Editor.nodes(newEditor, {
71
+ at: selection,
72
+ match: function match(n) {
73
+ return n.type === _constants.PARAGRAPH;
74
+ },
75
+ mode: 'lowest'
60
76
  }),
61
- _Editor$node2 = (0, _slicedToArray2["default"])(_Editor$node, 1),
62
- _Editor$node2$ = _Editor$node2[0],
63
- selectedNode = _Editor$node2$ === void 0 ? {} : _Editor$node2$;
64
- var type = selectedNode.type,
65
- indent = selectedNode.indent;
66
- if (_slate.Range.isCollapsed(selection) && type === _constants.PARAGRAPH && indent) {
67
- var path = _slate.Editor.path(newEditor, selection);
77
+ _Editor$nodes4 = (0, _slicedToArray2["default"])(_Editor$nodes3, 1),
78
+ selectedParagraphEntry = _Editor$nodes4[0];
79
+ var _ref = selectedParagraphEntry || [],
80
+ _ref2 = (0, _slicedToArray2["default"])(_ref, 2),
81
+ _ref2$ = _ref2[0],
82
+ selectedNode = _ref2$ === void 0 ? {} : _ref2$,
83
+ _ref2$2 = _ref2[1],
84
+ path = _ref2$2 === void 0 ? [] : _ref2$2;
85
+ var indent = selectedNode.indent;
86
+ if (_slate.Range.isCollapsed(selection) && indent && path.length) {
68
87
  var point = _slate.Editor.point(newEditor, selection);
69
- var isStart = _slate.Editor.isStart(newEditor, point, [path[0]]);
88
+ var isStart = _slate.Editor.isStart(newEditor, point, path);
70
89
  if (isStart) {
71
90
  _slate.Transforms.setNodes(newEditor, {
72
91
  indent: false
73
92
  }, {
74
- at: [path[0]]
93
+ at: path
75
94
  });
76
95
  return;
77
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "3.0.160",
3
+ "version": "3.0.161",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -72,5 +72,5 @@
72
72
  "publishConfig": {
73
73
  "access": "public"
74
74
  },
75
- "gitHead": "2d77cce0e646af89cc4212bfeb5e621601f3e0f1"
75
+ "gitHead": "81c488be2476a672597399e9093e1c5e112586f2"
76
76
  }