@seafile/sdoc-editor 3.0.160 → 3.0.162

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.
@@ -7,14 +7,31 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports["default"] = void 0;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
9
9
  var _slate = require("@seafile/slate");
10
+ var _isHotkey = _interopRequireDefault(require("is-hotkey"));
10
11
  var _constants = require("../../constants");
11
12
  var _core = require("../../core");
12
13
  var _helpers = require("./helpers");
13
14
  var withBlockquote = function withBlockquote(editor) {
14
15
  var insertBreak = editor.insertBreak,
15
16
  deleteBackward = editor.deleteBackward,
16
- insertFragment = editor.insertFragment;
17
+ insertFragment = editor.insertFragment,
18
+ handleTab = editor.handleTab;
17
19
  var newEditor = editor;
20
+ newEditor.handleTab = function (event) {
21
+ var quoteBlockEntry = (0, _core.getSelectedNodeEntryByType)(newEditor, _constants.BLOCKQUOTE);
22
+ if (!quoteBlockEntry) {
23
+ return handleTab && handleTab(event);
24
+ }
25
+ var listItemEntry = (0, _core.getSelectedNodeEntryByType)(newEditor, _constants.LIST_ITEM);
26
+ if (listItemEntry) {
27
+ return handleTab && handleTab(event);
28
+ }
29
+ if ((0, _isHotkey["default"])('tab', event) || (0, _isHotkey["default"])('shift+tab', event)) {
30
+ event.preventDefault();
31
+ return true;
32
+ }
33
+ return handleTab && handleTab(event);
34
+ };
18
35
  newEditor.insertBreak = function () {
19
36
  var selection = editor.selection;
20
37
  if (selection == null) return insertBreak();
@@ -87,6 +87,21 @@ 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
+ var listItemEntry = _slate.Editor.above(newEditor, {
92
+ at: newEditor.selection,
93
+ match: function match(n) {
94
+ return n.type === _constants2.LIST_ITEM;
95
+ },
96
+ mode: 'lowest'
97
+ });
98
+ if (!listItemEntry) {
99
+ event.preventDefault();
100
+ return true;
101
+ }
102
+ newEditor.handleTab && newEditor.handleTab(event);
103
+ return true;
104
+ }
90
105
  if ((0, _isHotkey["default"])('mod+enter', event)) {
91
106
  (0, _helpers.insertElement)(newEditor, _constants2.PARAGRAPH, _constants2.INSERT_POSITION.AFTER);
92
107
  return true;
@@ -122,11 +122,11 @@ var withList = function withList(editor) {
122
122
  };
123
123
  newEditor.handleTab = function (event) {
124
124
  if (!newEditor.selection) {
125
- handleTab && handleTab();
125
+ handleTab && handleTab(event);
126
126
  return;
127
127
  }
128
128
  if ((0, _onTabHandle.onTabHandle)(newEditor, event)) return;
129
- handleTab && handleTab();
129
+ handleTab && handleTab(event);
130
130
  };
131
131
  newEditor.insertFragment = (0, _insertFragmentList.insertFragmentList)(newEditor);
132
132
  newEditor.normalizeNode = (0, _normalizeList.normalizeList)(editor);
@@ -20,18 +20,40 @@ 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
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 excludedParent = _slate.Editor.above(newEditor, {
33
+ at: selection,
34
+ match: function match(n) {
35
+ return [_constants.LIST_ITEM, _constants.BLOCKQUOTE].includes(n.type);
36
+ },
37
+ mode: 'lowest'
29
38
  });
30
- if ((selectedNode === null || selectedNode === void 0 ? void 0 : (_selectedNode$ = selectedNode[0]) === null || _selectedNode$ === void 0 ? void 0 : _selectedNode$.type) === _constants.PARAGRAPH) {
39
+ if (excludedParent) {
40
+ return handleTab && handleTab(event);
41
+ }
42
+ var _Editor$nodes = _slate.Editor.nodes(newEditor, {
43
+ at: selection,
44
+ match: function match(n) {
45
+ return n.type === _constants.PARAGRAPH;
46
+ },
47
+ mode: 'lowest'
48
+ }),
49
+ _Editor$nodes2 = (0, _slicedToArray2["default"])(_Editor$nodes, 1),
50
+ selectedParagraphEntry = _Editor$nodes2[0];
51
+ if (selectedParagraphEntry) {
31
52
  event.preventDefault();
32
- var path = _slate.Editor.path(newEditor, selection);
53
+ var _selectedParagraphEnt = (0, _slicedToArray2["default"])(selectedParagraphEntry, 2),
54
+ path = _selectedParagraphEnt[1];
33
55
  var point = _slate.Editor.point(newEditor, selection);
34
- var isStart = _slate.Editor.isStart(newEditor, point, [path[0]]);
56
+ var isStart = _slate.Editor.isStart(newEditor, point, path);
35
57
  if (isStart) {
36
58
  var indent;
37
59
  if ((0, _isHotkey["default"])('shift+tab', event)) {
@@ -43,35 +65,42 @@ var withParagraph = function withParagraph(editor) {
43
65
  _slate.Transforms.setNodes(newEditor, {
44
66
  indent: indent
45
67
  }, {
46
- at: [path[0]]
68
+ at: path
47
69
  });
48
70
  } else {
49
71
  if ((0, _isHotkey["default"])('tab', event)) insertText(' ');
50
72
  }
51
73
  return;
52
74
  }
53
- return handleTab(event);
75
+ return handleTab && handleTab(event);
54
76
  };
55
77
  newEditor.deleteBackward = function (unit) {
56
78
  var selection = newEditor.selection;
57
79
  if (!selection) return;
58
- var _Editor$node = _slate.Editor.node(newEditor, selection, {
59
- depth: 1
80
+ var _Editor$nodes3 = _slate.Editor.nodes(newEditor, {
81
+ at: selection,
82
+ match: function match(n) {
83
+ return n.type === _constants.PARAGRAPH;
84
+ },
85
+ mode: 'lowest'
60
86
  }),
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);
87
+ _Editor$nodes4 = (0, _slicedToArray2["default"])(_Editor$nodes3, 1),
88
+ selectedParagraphEntry = _Editor$nodes4[0];
89
+ var _ref = selectedParagraphEntry || [],
90
+ _ref2 = (0, _slicedToArray2["default"])(_ref, 2),
91
+ _ref2$ = _ref2[0],
92
+ selectedNode = _ref2$ === void 0 ? {} : _ref2$,
93
+ _ref2$2 = _ref2[1],
94
+ path = _ref2$2 === void 0 ? [] : _ref2$2;
95
+ var indent = selectedNode.indent;
96
+ if (_slate.Range.isCollapsed(selection) && indent && path.length) {
68
97
  var point = _slate.Editor.point(newEditor, selection);
69
- var isStart = _slate.Editor.isStart(newEditor, point, [path[0]]);
98
+ var isStart = _slate.Editor.isStart(newEditor, point, path);
70
99
  if (isStart) {
71
100
  _slate.Transforms.setNodes(newEditor, {
72
101
  indent: false
73
102
  }, {
74
- at: [path[0]]
103
+ at: path
75
104
  });
76
105
  return;
77
106
  }
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.162",
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": "e799288b08d797747a7c810596964b8619de28a0"
76
76
  }