@seafile/sdoc-editor 1.0.217 → 1.0.218

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.
@@ -104,9 +104,12 @@ const getCommonNode = (root, path, ancestor) => {
104
104
  exports.getCommonNode = getCommonNode;
105
105
  const getSelectedNodeByType = (editor, type) => {
106
106
  const match = n => getNodeType(n) === type;
107
+ if (!editor.selection) return;
108
+ const at = _slate.Range.isCollapsed(editor.selection) ? editor.selection : _slate.Editor.start(editor, editor.selection);
107
109
  const [nodeEntry] = _slate.Editor.nodes(editor, {
108
110
  match,
109
- universal: true
111
+ universal: true,
112
+ at
110
113
  });
111
114
  return nodeEntry ? nodeEntry[0] : null;
112
115
  };
@@ -72,16 +72,42 @@ const setCheckListItemType = (editor, newType, insertPosition) => {
72
72
  });
73
73
  _slate.Transforms.select(editor, [path[0] + 1]);
74
74
  }
75
- const path = _slate.Editor.path(editor, editor.selection);
76
- if (path) {
77
- const [targetNode, targetPath] = _slate.Editor.node(editor, [path[0]]);
78
- if (targetNode && [_constants.ORDERED_LIST, _constants.UNORDERED_LIST].includes(targetNode === null || targetNode === void 0 ? void 0 : targetNode.type)) {
79
- convertToCheck(editor, targetNode, targetPath);
80
- return;
75
+ if (!(0, _core.isRangeAcrossBlocks)(editor)) {
76
+ const path = _slate.Editor.path(editor, editor.selection);
77
+ if (path) {
78
+ const [targetNode, targetPath] = _slate.Editor.node(editor, [path[0]]);
79
+ if (targetNode && [_constants.ORDERED_LIST, _constants.UNORDERED_LIST].includes(targetNode === null || targetNode === void 0 ? void 0 : targetNode.type)) {
80
+ convertToCheck(editor, targetNode, targetPath);
81
+ return;
82
+ }
81
83
  }
84
+ _slate.Transforms.setNodes(editor, {
85
+ type: newType
86
+ });
87
+ } else {
88
+ const nodes = _slate.Editor.nodes(editor, {
89
+ match: n => {
90
+ const type = (0, _core.getNodeType)(n);
91
+ if (!type) return;
92
+ if (type === _constants.PARAGRAPH) return true;
93
+ if (type === _constants.CHECK_LIST_ITEM) return true;
94
+ if (type.startsWith(_constants.HEADER)) return true;
95
+ if (type === _constants.TITLE) return true;
96
+ if (type === _constants.SUBTITLE) return true;
97
+ return false;
98
+ },
99
+ universal: false,
100
+ mode: 'highest' // Match top level
101
+ });
102
+ const nodesEntry = Array.from(nodes);
103
+ if (nodesEntry.length === 0) return;
104
+ nodesEntry.forEach(nodeEntry => {
105
+ _slate.Transforms.setNodes(editor, {
106
+ type: newType
107
+ }, {
108
+ at: nodeEntry[1]
109
+ });
110
+ });
82
111
  }
83
- _slate.Transforms.setNodes(editor, {
84
- type: newType
85
- });
86
112
  };
87
113
  exports.setCheckListItemType = setCheckListItemType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "1.0.217",
3
+ "version": "1.0.218",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",