@ant-design/agentic-ui 2.29.7 → 2.29.8

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.
Files changed (83) hide show
  1. package/dist/ChatLayout/components/FooterBackgroundLottie/index.js +1 -1
  2. package/dist/MarkdownEditor/BaseMarkdownEditor.js +1 -1
  3. package/dist/MarkdownEditor/editor/elements/Blockquote/ReadonlyBlockquote.d.ts +33 -0
  4. package/dist/MarkdownEditor/editor/elements/Blockquote/ReadonlyBlockquote.js +69 -0
  5. package/dist/MarkdownEditor/editor/elements/Break/ReadonlyBreak.d.ts +30 -0
  6. package/dist/MarkdownEditor/editor/elements/Break/ReadonlyBreak.js +88 -0
  7. package/dist/MarkdownEditor/editor/elements/Card/ReadonlyCard.d.ts +34 -0
  8. package/dist/MarkdownEditor/editor/elements/Card/ReadonlyCard.js +96 -0
  9. package/dist/MarkdownEditor/editor/elements/Code/ReadonlyCode.d.ts +33 -0
  10. package/dist/MarkdownEditor/editor/elements/Code/ReadonlyCode.js +145 -0
  11. package/dist/MarkdownEditor/editor/elements/FootnoteDefinition/ReadonlyFootnoteDefinition.d.ts +34 -0
  12. package/dist/MarkdownEditor/editor/elements/FootnoteDefinition/ReadonlyFootnoteDefinition.js +125 -0
  13. package/dist/MarkdownEditor/editor/elements/FootnoteReference/ReadonlyFootnoteReference.d.ts +34 -0
  14. package/dist/MarkdownEditor/editor/elements/FootnoteReference/ReadonlyFootnoteReference.js +101 -0
  15. package/dist/MarkdownEditor/editor/elements/Head/ReadonlyHead.d.ts +35 -0
  16. package/dist/MarkdownEditor/editor/elements/Head/ReadonlyHead.js +111 -0
  17. package/dist/MarkdownEditor/editor/elements/Head/index.d.ts +3 -0
  18. package/dist/MarkdownEditor/editor/elements/Head/index.js +3 -1
  19. package/dist/MarkdownEditor/editor/elements/Hr/ReadonlyHr.d.ts +30 -0
  20. package/dist/MarkdownEditor/editor/elements/Hr/ReadonlyHr.js +95 -0
  21. package/dist/MarkdownEditor/editor/elements/Image/ReadonlyEditorImage.d.ts +35 -0
  22. package/dist/MarkdownEditor/editor/elements/Image/ReadonlyEditorImage.js +426 -0
  23. package/dist/MarkdownEditor/editor/elements/Image/index.js +38 -50
  24. package/dist/MarkdownEditor/editor/elements/InlineKatex/ReadonlyInlineKatex.d.ts +32 -0
  25. package/dist/MarkdownEditor/editor/elements/InlineKatex/ReadonlyInlineKatex.js +100 -0
  26. package/dist/MarkdownEditor/editor/elements/Katex/ReadonlyKatex.d.ts +32 -0
  27. package/dist/MarkdownEditor/editor/elements/Katex/ReadonlyKatex.js +110 -0
  28. package/dist/MarkdownEditor/editor/elements/LinkCard/ReadonlyLinkCard.d.ts +40 -0
  29. package/dist/MarkdownEditor/editor/elements/LinkCard/ReadonlyLinkCard.js +215 -0
  30. package/dist/MarkdownEditor/editor/elements/List/List.js +27 -12
  31. package/dist/MarkdownEditor/editor/elements/List/ReadonlyList.d.ts +33 -0
  32. package/dist/MarkdownEditor/editor/elements/List/ReadonlyList.js +93 -0
  33. package/dist/MarkdownEditor/editor/elements/List/ReadonlyListItem.d.ts +35 -0
  34. package/dist/MarkdownEditor/editor/elements/List/ReadonlyListItem.js +138 -0
  35. package/dist/MarkdownEditor/editor/elements/Media/ReadonlyMedia.d.ts +36 -0
  36. package/dist/MarkdownEditor/editor/elements/Media/ReadonlyMedia.js +600 -0
  37. package/dist/MarkdownEditor/editor/elements/Mermaid/ReadonlyMermaid.d.ts +32 -0
  38. package/dist/MarkdownEditor/editor/elements/Mermaid/ReadonlyMermaid.js +101 -0
  39. package/dist/MarkdownEditor/editor/elements/Paragraph/ReadonlyParagraph.d.ts +35 -0
  40. package/dist/MarkdownEditor/editor/elements/Paragraph/ReadonlyParagraph.js +109 -0
  41. package/dist/MarkdownEditor/editor/elements/Paragraph/index.js +2 -1
  42. package/dist/MarkdownEditor/editor/elements/Schema/ReadonlySchema.d.ts +33 -0
  43. package/dist/MarkdownEditor/editor/elements/Schema/ReadonlySchema.js +163 -0
  44. package/dist/MarkdownEditor/editor/elements/index.d.ts +20 -1
  45. package/dist/MarkdownEditor/editor/elements/index.js +65 -29
  46. package/dist/MarkdownEditor/editor/parser/parse/parseBlockElements.js +18 -10
  47. package/dist/MarkdownEditor/editor/parser/parserSlateNodeToMarkdown.js +64 -21
  48. package/dist/MarkdownEditor/editor/plugins/elements.js +60 -6
  49. package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/backspace.js +97 -39
  50. package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/tab.d.ts +14 -0
  51. package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/tab.js +117 -90
  52. package/dist/MarkdownEditor/editor/plugins/index.d.ts +8 -0
  53. package/dist/MarkdownEditor/editor/plugins/index.js +8 -0
  54. package/dist/MarkdownEditor/editor/plugins/insertParsedHtmlNodes.d.ts +12 -6
  55. package/dist/MarkdownEditor/editor/plugins/insertParsedHtmlNodes.js +67 -42
  56. package/dist/MarkdownEditor/editor/plugins/utils.d.ts +31 -0
  57. package/dist/MarkdownEditor/editor/plugins/utils.js +75 -0
  58. package/dist/MarkdownEditor/editor/plugins/withCardPlugin.d.ts +15 -0
  59. package/dist/MarkdownEditor/editor/plugins/withCardPlugin.js +329 -0
  60. package/dist/MarkdownEditor/editor/plugins/withCodeTagPlugin.d.ts +11 -0
  61. package/dist/MarkdownEditor/editor/plugins/withCodeTagPlugin.js +299 -0
  62. package/dist/MarkdownEditor/editor/plugins/withInlineNodes.d.ts +12 -0
  63. package/dist/MarkdownEditor/editor/plugins/withInlineNodes.js +17 -0
  64. package/dist/MarkdownEditor/editor/plugins/withLinkAndMediaPlugin.d.ts +11 -0
  65. package/dist/MarkdownEditor/editor/plugins/withLinkAndMediaPlugin.js +70 -0
  66. package/dist/MarkdownEditor/editor/plugins/withListsPlugin.d.ts +23 -0
  67. package/dist/MarkdownEditor/editor/plugins/withListsPlugin.js +204 -0
  68. package/dist/MarkdownEditor/editor/plugins/withMarkdown.d.ts +9 -12
  69. package/dist/MarkdownEditor/editor/plugins/withMarkdown.js +17 -764
  70. package/dist/MarkdownEditor/editor/plugins/withSchemaPlugin.d.ts +11 -0
  71. package/dist/MarkdownEditor/editor/plugins/withSchemaPlugin.js +55 -0
  72. package/dist/MarkdownEditor/editor/plugins/withVoidNodes.d.ts +12 -0
  73. package/dist/MarkdownEditor/editor/plugins/withVoidNodes.js +17 -0
  74. package/dist/MarkdownEditor/editor/store.js +1 -1
  75. package/dist/MarkdownEditor/editor/utils/docx/module.js +41 -8
  76. package/dist/MarkdownEditor/editor/utils/editorCommands.d.ts +97 -0
  77. package/dist/MarkdownEditor/editor/utils/editorCommands.js +966 -0
  78. package/dist/MarkdownEditor/editor/utils/editorUtils.js +2 -2
  79. package/dist/MarkdownEditor/editor/utils/keyboard.js +15 -391
  80. package/dist/MarkdownEditor/el.d.ts +12 -5
  81. package/dist/MarkdownInputField/MarkdownInputField.js +10 -23
  82. package/dist/MarkdownInputField/style.js +9 -4
  83. package/package.json +8 -8
@@ -0,0 +1,966 @@
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_with_holes(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function _array_without_holes(arr) {
10
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
11
+ }
12
+ function _define_property(obj, key, value) {
13
+ if (key in obj) {
14
+ Object.defineProperty(obj, key, {
15
+ value: value,
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true
19
+ });
20
+ } else {
21
+ obj[key] = value;
22
+ }
23
+ return obj;
24
+ }
25
+ function _iterable_to_array(iter) {
26
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
27
+ }
28
+ function _iterable_to_array_limit(arr, i) {
29
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
30
+ if (_i == null) return;
31
+ var _arr = [];
32
+ var _n = true;
33
+ var _d = false;
34
+ var _s, _e;
35
+ try {
36
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
37
+ _arr.push(_s.value);
38
+ if (i && _arr.length === i) break;
39
+ }
40
+ } catch (err) {
41
+ _d = true;
42
+ _e = err;
43
+ } finally{
44
+ try {
45
+ if (!_n && _i["return"] != null) _i["return"]();
46
+ } finally{
47
+ if (_d) throw _e;
48
+ }
49
+ }
50
+ return _arr;
51
+ }
52
+ function _non_iterable_rest() {
53
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
54
+ }
55
+ function _non_iterable_spread() {
56
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
57
+ }
58
+ function _object_spread(target) {
59
+ for(var i = 1; i < arguments.length; i++){
60
+ var source = arguments[i] != null ? arguments[i] : {};
61
+ var ownKeys = Object.keys(source);
62
+ if (typeof Object.getOwnPropertySymbols === "function") {
63
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
64
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
65
+ }));
66
+ }
67
+ ownKeys.forEach(function(key) {
68
+ _define_property(target, key, source[key]);
69
+ });
70
+ }
71
+ return target;
72
+ }
73
+ function _sliced_to_array(arr, i) {
74
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
75
+ }
76
+ function _to_consumable_array(arr) {
77
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
78
+ }
79
+ function _unsupported_iterable_to_array(o, minLen) {
80
+ if (!o) return;
81
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
82
+ var n = Object.prototype.toString.call(o).slice(8, -1);
83
+ if (n === "Object" && o.constructor) n = o.constructor.name;
84
+ if (n === "Map" || n === "Set") return Array.from(n);
85
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
86
+ }
87
+ import { Editor, Element, Node, Path, Range, Transforms } from "slate";
88
+ import { NativeTableEditor } from "../../utils/native-table";
89
+ import { getListType, isListType } from "../plugins/withListsPlugin";
90
+ import { EditorUtils } from "./editorUtils";
91
+ /**
92
+ * 获取当前编辑器中的最低层级元素节点
93
+ */ export function getCurrentNodes(editor) {
94
+ return Editor.nodes(editor, {
95
+ mode: 'lowest',
96
+ match: function(m) {
97
+ return Element.isElement(m);
98
+ }
99
+ });
100
+ }
101
+ /**
102
+ * 插入表格
103
+ *
104
+ * 在当前位置插入一个3x3的表格(包含表头行)。
105
+ * 根据当前节点类型(段落、标题或列单元格)
106
+ * 决定在何处插入表格及如何处理现有内容。
107
+ *
108
+ * @param editor Slate 编辑器实例
109
+ * @param node 可选的节点,如果不提供则从编辑器获取
110
+ */ export function insertTable(editor, node) {
111
+ var _currentNode_, _currentNode_1;
112
+ var currentNode = node || Array.from(getCurrentNodes(editor))[0];
113
+ if (currentNode && [
114
+ 'paragraph',
115
+ 'head'
116
+ ].includes(currentNode === null || currentNode === void 0 ? void 0 : (_currentNode_ = currentNode[0]) === null || _currentNode_ === void 0 ? void 0 : _currentNode_.type)) {
117
+ var _currentNode_2, _currentNode_3;
118
+ var path = (currentNode === null || currentNode === void 0 ? void 0 : (_currentNode_2 = currentNode[0]) === null || _currentNode_2 === void 0 ? void 0 : _currentNode_2.type) === 'paragraph' && !Node.string(currentNode[0]) ? currentNode[1] : Path.next(currentNode[1]);
119
+ // 使用原生表格编辑器插入表格
120
+ NativeTableEditor.insertTable(editor, {
121
+ rows: 3,
122
+ cols: 3,
123
+ at: path
124
+ });
125
+ if ((currentNode === null || currentNode === void 0 ? void 0 : (_currentNode_3 = currentNode[0]) === null || _currentNode_3 === void 0 ? void 0 : _currentNode_3.type) === 'paragraph' && !Node.string(currentNode[0])) {
126
+ Transforms.delete(editor, {
127
+ at: Path.next(path)
128
+ });
129
+ }
130
+ Transforms.select(editor, Editor.start(editor, path));
131
+ }
132
+ if (currentNode && [
133
+ 'column-cell'
134
+ ].includes(currentNode === null || currentNode === void 0 ? void 0 : (_currentNode_1 = currentNode[0]) === null || _currentNode_1 === void 0 ? void 0 : _currentNode_1.type)) {
135
+ NativeTableEditor.insertTable(editor, {
136
+ rows: 3,
137
+ cols: 3,
138
+ at: _to_consumable_array(currentNode[1]).concat([
139
+ 0
140
+ ])
141
+ });
142
+ }
143
+ }
144
+ /**
145
+ * 插入代码块
146
+ *
147
+ * 在当前位置插入代码块,并根据传入的类型设置语言和渲染模式。
148
+ * 支持在列单元格内或普通段落/标题后插入代码块。
149
+ *
150
+ * @param editor Slate 编辑器实例
151
+ * @param type 可选的代码块类型,'mermaid'表示流程图,'html'表示HTML渲染
152
+ * @param node 可选的节点,如果不提供则从编辑器获取
153
+ */ export function insertCodeBlock(editor, type, node) {
154
+ var currentNode = node || Array.from(getCurrentNodes(editor))[0];
155
+ if (currentNode && currentNode[0] && [
156
+ 'paragraph',
157
+ 'head'
158
+ ].includes(currentNode[0].type)) {
159
+ var path = currentNode[0].type === 'paragraph' && !Node.string(currentNode[0]) ? currentNode[1] : Path.next(currentNode[1]);
160
+ var lang = '';
161
+ if (type === 'mermaid') {
162
+ lang = 'mermaid';
163
+ }
164
+ Transforms.insertNodes(editor, {
165
+ type: 'code',
166
+ language: lang ? lang : undefined,
167
+ children: [
168
+ {
169
+ text: "flowchart TD\n Start --> Stop"
170
+ }
171
+ ],
172
+ render: type === 'html' ? true : undefined
173
+ }, {
174
+ at: path
175
+ });
176
+ Transforms.select(editor, Editor.end(editor, path));
177
+ }
178
+ }
179
+ /**
180
+ * 插入或移除引用块
181
+ *
182
+ * 如果当前节点已在引用块中,则移除引用块;
183
+ * 否则,将当前节点转换为引用块。
184
+ * 如果当前节点是标题,先将其转换为普通段落。
185
+ *
186
+ * @param editor Slate 编辑器实例
187
+ * @param node 可选的节点,如果不提供则从编辑器获取
188
+ */ export function toggleQuote(editor, node) {
189
+ var _currentNode_, _currentNode_1;
190
+ var currentNode = node || Array.from(getCurrentNodes(editor))[0];
191
+ if (!currentNode || ![
192
+ 'paragraph',
193
+ 'head'
194
+ ].includes(currentNode === null || currentNode === void 0 ? void 0 : (_currentNode_ = currentNode[0]) === null || _currentNode_ === void 0 ? void 0 : _currentNode_.type)) return;
195
+ if (Node.parent(editor, currentNode[1]).type === 'blockquote') {
196
+ Transforms.unwrapNodes(editor, {
197
+ at: Path.parent(currentNode[1])
198
+ });
199
+ return;
200
+ }
201
+ if ((currentNode === null || currentNode === void 0 ? void 0 : (_currentNode_1 = currentNode[0]) === null || _currentNode_1 === void 0 ? void 0 : _currentNode_1.type) === 'head') {
202
+ Transforms.setNodes(editor, {
203
+ type: 'paragraph'
204
+ }, {
205
+ at: currentNode[1]
206
+ });
207
+ }
208
+ Transforms.wrapNodes(editor, {
209
+ type: 'blockquote',
210
+ children: []
211
+ });
212
+ }
213
+ /**
214
+ * 插入水平分割线
215
+ *
216
+ * 在当前位置插入水平分割线,并将光标定位到分割线后的位置。
217
+ * 如果分割线后没有内容,则自动插入一个空段落并将光标定位到该段落。
218
+ *
219
+ * @param editor Slate 编辑器实例
220
+ * @param node 可选的节点,如果不提供则从编辑器获取
221
+ */ export function insertHorizontalLine(editor, node) {
222
+ var _currentNode_;
223
+ var currentNode = node || Array.from(getCurrentNodes(editor))[0];
224
+ if (currentNode && [
225
+ 'paragraph',
226
+ 'head'
227
+ ].includes(currentNode === null || currentNode === void 0 ? void 0 : (_currentNode_ = currentNode[0]) === null || _currentNode_ === void 0 ? void 0 : _currentNode_.type)) {
228
+ var _currentNode_1;
229
+ var path = (currentNode === null || currentNode === void 0 ? void 0 : (_currentNode_1 = currentNode[0]) === null || _currentNode_1 === void 0 ? void 0 : _currentNode_1.type) === 'paragraph' && !Node.string(currentNode[0]) ? currentNode[1] : Path.next(currentNode[1]);
230
+ Transforms.insertNodes(editor, {
231
+ type: 'hr',
232
+ children: [
233
+ {
234
+ text: ''
235
+ }
236
+ ]
237
+ }, {
238
+ at: path
239
+ });
240
+ if (Editor.hasPath(editor, Path.next(path))) {
241
+ Transforms.select(editor, Editor.start(editor, Path.next(path)));
242
+ } else {
243
+ Transforms.insertNodes(editor, {
244
+ type: 'paragraph',
245
+ children: [
246
+ {
247
+ text: ''
248
+ }
249
+ ]
250
+ }, {
251
+ at: Path.next(path),
252
+ select: true
253
+ });
254
+ }
255
+ }
256
+ }
257
+ /**
258
+ * 将标题转换为普通段落
259
+ *
260
+ * 如果当前节点是标题类型,将其转换为普通段落
261
+ *
262
+ * @param editor Slate 编辑器实例
263
+ */ function convertToParagraph(editor) {
264
+ var _node_;
265
+ var _getCurrentNodes = _sliced_to_array(getCurrentNodes(editor), 1), node = _getCurrentNodes[0];
266
+ if (node && [
267
+ 'head'
268
+ ].includes(node === null || node === void 0 ? void 0 : (_node_ = node[0]) === null || _node_ === void 0 ? void 0 : _node_.type)) {
269
+ Transforms.setNodes(editor, {
270
+ type: 'paragraph'
271
+ }, {
272
+ at: node[1]
273
+ });
274
+ }
275
+ }
276
+ /**
277
+ * 设置标题级别
278
+ *
279
+ * 将当前段落或标题节点转换为指定级别的标题。
280
+ * 如果级别为4,则转换为普通段落。
281
+ *
282
+ * @param editor Slate 编辑器实例
283
+ * @param level 标题级别(1-3)或4(表示普通段落)
284
+ */ export function setHeading(editor, level) {
285
+ var _node_;
286
+ var _getCurrentNodes = _sliced_to_array(getCurrentNodes(editor), 1), node = _getCurrentNodes[0];
287
+ if (level === 4) {
288
+ convertToParagraph(editor);
289
+ return;
290
+ }
291
+ if (node && [
292
+ 'paragraph',
293
+ 'head'
294
+ ].includes(node === null || node === void 0 ? void 0 : (_node_ = node[0]) === null || _node_ === void 0 ? void 0 : _node_.type) && EditorUtils.isTop(editor, node[1])) {
295
+ Transforms.setNodes(editor, {
296
+ type: 'head',
297
+ level: level
298
+ }, {
299
+ at: node[1]
300
+ });
301
+ }
302
+ }
303
+ export { convertToParagraph };
304
+ /**
305
+ * 查找选区内的块级节点
306
+ *
307
+ * @param editor - 编辑器实例
308
+ * @param selection - 当前选区
309
+ * @returns 找到的块级节点数组,每个元素包含 [node, path]
310
+ */ function findBlockNodesInSelection(editor, selection) {
311
+ if (!selection) {
312
+ return [];
313
+ }
314
+ var blockNodes = Array.from(Editor.nodes(editor, {
315
+ at: selection,
316
+ match: function(n) {
317
+ return Element.isElement(n) && !Editor.isInline(editor, n) && [
318
+ 'paragraph',
319
+ 'head'
320
+ ].includes(n.type);
321
+ }
322
+ }));
323
+ return blockNodes;
324
+ }
325
+ /**
326
+ * 将标题节点转换为段落节点
327
+ *
328
+ * @param editor - 编辑器实例
329
+ * @param path - 标题节点的路径
330
+ */ function convertHeadingToParagraph(editor, path) {
331
+ Transforms.setNodes(editor, {
332
+ type: 'paragraph'
333
+ }, {
334
+ at: path
335
+ });
336
+ // 移除 level 属性
337
+ Transforms.unsetNodes(editor, 'level', {
338
+ at: path
339
+ });
340
+ }
341
+ /**
342
+ * 检查路径是否有后一个兄弟节点
343
+ * 注意:Path.hasNext 在 Slate 中不存在,所以需要自定义实现
344
+ */ function hasNext(editor, path) {
345
+ if (path.length === 0) {
346
+ return false;
347
+ }
348
+ try {
349
+ var parentPath = Path.parent(path);
350
+ if (!Editor.hasPath(editor, parentPath)) {
351
+ return false;
352
+ }
353
+ var parentNode = Node.get(editor, parentPath);
354
+ if (!Element.isElement(parentNode)) {
355
+ return false;
356
+ }
357
+ var index = path[path.length - 1];
358
+ return index < parentNode.children.length - 1;
359
+ } catch (unused) {
360
+ return false;
361
+ }
362
+ }
363
+ /**
364
+ * 查找相邻的列表节点
365
+ *
366
+ * @param editor - 编辑器实例
367
+ * @param path - 当前路径
368
+ * @param listType - 目标列表类型
369
+ * @returns 相邻列表的路径,如果不存在则返回 null
370
+ */ function findAdjacentList(editor, path, listType) {
371
+ // 如果是根路径,无法查找相邻节点
372
+ if (path.length === 0) {
373
+ return null;
374
+ }
375
+ // 检查前一个兄弟节点(使用 Slate 的 Path.hasPrevious)
376
+ if (Path.hasPrevious(path)) {
377
+ var prevPath = Path.previous(path);
378
+ if (Editor.hasPath(editor, prevPath)) {
379
+ var prevNode = Node.get(editor, prevPath);
380
+ if (isListType(prevNode) && prevNode.type === listType) {
381
+ return prevPath;
382
+ }
383
+ }
384
+ }
385
+ // 检查后一个兄弟节点(使用自定义 hasNext)
386
+ if (hasNext(editor, path)) {
387
+ var nextPath = Path.next(path);
388
+ if (Editor.hasPath(editor, nextPath)) {
389
+ var nextNode = Node.get(editor, nextPath);
390
+ if (isListType(nextNode) && nextNode.type === listType) {
391
+ return nextPath;
392
+ }
393
+ }
394
+ }
395
+ return null;
396
+ }
397
+ /**
398
+ * 合并列表项到相邻列表
399
+ *
400
+ * @param editor - 编辑器实例
401
+ * @param listItemPaths - 要合并的列表项路径数组
402
+ * @param targetListPath - 目标列表路径
403
+ */ function mergeIntoAdjacentList(editor, listItemPaths, targetListPath) {
404
+ var targetList = Node.get(editor, targetListPath);
405
+ if (!isListType(targetList)) {
406
+ return;
407
+ }
408
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
409
+ try {
410
+ // 按路径倒序处理,避免路径变化影响
411
+ for(var _iterator = listItemPaths.reverse()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
412
+ var listItemPath = _step.value;
413
+ if (Editor.hasPath(editor, listItemPath)) {
414
+ var targetIndex = targetList.children.length;
415
+ Transforms.moveNodes(editor, {
416
+ at: listItemPath,
417
+ to: _to_consumable_array(targetListPath).concat([
418
+ targetIndex
419
+ ])
420
+ });
421
+ }
422
+ }
423
+ } catch (err) {
424
+ _didIteratorError = true;
425
+ _iteratorError = err;
426
+ } finally{
427
+ try {
428
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
429
+ _iterator.return();
430
+ }
431
+ } finally{
432
+ if (_didIteratorError) {
433
+ throw _iteratorError;
434
+ }
435
+ }
436
+ }
437
+ }
438
+ /**
439
+ * 解包列表为段落
440
+ *
441
+ * @param editor - 编辑器实例
442
+ * @param listItemPath - 列表项路径
443
+ * @param listPath - 列表路径
444
+ */ function unwrapListToParagraph(editor, listItemPath, listPath) {
445
+ // 先解包 list-item,保留其内容
446
+ Transforms.unwrapNodes(editor, {
447
+ at: listItemPath
448
+ });
449
+ // 如果列表为空,删除列表容器
450
+ var list = Node.get(editor, listPath);
451
+ if (isListType(list) && list.children.length === 0) {
452
+ Transforms.removeNodes(editor, {
453
+ at: listPath
454
+ });
455
+ }
456
+ }
457
+ /**
458
+ * 更新列表类型
459
+ *
460
+ * @param editor - 编辑器实例
461
+ * @param listPath - 列表路径
462
+ * @param mode - 列表类型模式
463
+ */ function updateListType(editor, listPath, mode) {
464
+ var listType = getListType(mode === 'ordered');
465
+ // 更新列表类型
466
+ Transforms.setNodes(editor, _object_spread({
467
+ type: listType
468
+ }, mode === 'ordered' && {
469
+ start: 1
470
+ }, mode === 'task' && {
471
+ task: true
472
+ }), {
473
+ at: listPath
474
+ });
475
+ // 移除旧的 order 属性(如果存在)
476
+ var listNode = Node.get(editor, listPath);
477
+ if (listNode.order !== undefined) {
478
+ Transforms.unsetNodes(editor, 'order', {
479
+ at: listPath
480
+ });
481
+ }
482
+ // 如果是任务列表,更新所有列表项的 checked 状态
483
+ if (mode === 'task') {
484
+ var listItems = Array.from(Editor.nodes(editor, {
485
+ match: function(n) {
486
+ return n.type === 'list-item';
487
+ },
488
+ at: listPath,
489
+ reverse: true,
490
+ mode: 'lowest'
491
+ }));
492
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
493
+ try {
494
+ for(var _iterator = listItems[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
495
+ var _step_value = _sliced_to_array(_step.value, 2), item = _step_value[0], itemPath = _step_value[1];
496
+ Transforms.setNodes(editor, {
497
+ checked: item.checked || false
498
+ }, {
499
+ at: itemPath
500
+ });
501
+ }
502
+ } catch (err) {
503
+ _didIteratorError = true;
504
+ _iteratorError = err;
505
+ } finally{
506
+ try {
507
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
508
+ _iterator.return();
509
+ }
510
+ } finally{
511
+ if (_didIteratorError) {
512
+ throw _iteratorError;
513
+ }
514
+ }
515
+ }
516
+ }
517
+ }
518
+ /**
519
+ * 创建或转换列表
520
+ *
521
+ * 将当前段落或标题转换为指定类型的列表。
522
+ * 如果已经是列表项,则根据情况切换类型或解包。
523
+ *
524
+ * @param editor Slate 编辑器实例
525
+ * @param mode 列表类型 'ordered'(有序列表), 'unordered'(无序列表), 'task'(任务列表)
526
+ */ export function createList(editor, mode) {
527
+ var selection = editor.selection;
528
+ if (!selection) {
529
+ return;
530
+ }
531
+ var _getCurrentNodes = _sliced_to_array(getCurrentNodes(editor), 1), curNode = _getCurrentNodes[0];
532
+ if (!curNode) {
533
+ return;
534
+ }
535
+ var targetListType = getListType(mode === 'ordered');
536
+ // 情况1: 当前节点已经是 list-item,处理反向转换或类型切换
537
+ if (curNode[0].type === 'list-item') {
538
+ var listItemPath = curNode[1];
539
+ var listPath = Path.parent(listItemPath);
540
+ var listNode = Node.get(editor, listPath);
541
+ if (isListType(listNode)) {
542
+ // 如果列表类型与目标类型相同,执行解包
543
+ if (listNode.type === targetListType && mode !== 'task') {
544
+ Editor.withoutNormalizing(editor, function() {
545
+ unwrapListToParagraph(editor, listItemPath, listPath);
546
+ });
547
+ return;
548
+ }
549
+ // 否则更新列表类型
550
+ Editor.withoutNormalizing(editor, function() {
551
+ updateListType(editor, listPath, mode);
552
+ });
553
+ return;
554
+ }
555
+ }
556
+ // 情况2: 当前节点在 list-item 中(paragraph 在 list-item 内)
557
+ if ([
558
+ 'paragraph',
559
+ 'head'
560
+ ].includes(curNode[0].type)) {
561
+ var parent = Editor.parent(editor, curNode[1]);
562
+ if (parent && Element.isElement(parent[0]) && parent[0].type === 'list-item' && !Path.hasPrevious(curNode[1])) {
563
+ var listParent = Editor.parent(editor, parent[1]);
564
+ if (listParent && Element.isElement(listParent[0]) && isListType(listParent[0])) {
565
+ // 如果列表类型与目标类型相同,且不是任务列表,执行解包
566
+ var isTaskList = listParent[0].type === 'bulleted-list' && listParent[0].task === true;
567
+ if (listParent[0].type === targetListType && mode !== 'task' && !isTaskList) {
568
+ Editor.withoutNormalizing(editor, function() {
569
+ unwrapListToParagraph(editor, parent[1], listParent[1]);
570
+ });
571
+ return;
572
+ }
573
+ // 否则更新列表类型
574
+ Editor.withoutNormalizing(editor, function() {
575
+ updateListType(editor, listParent[1], mode);
576
+ });
577
+ return;
578
+ }
579
+ }
580
+ }
581
+ // 情况3: 将节点转换为列表
582
+ if (![
583
+ 'paragraph',
584
+ 'head'
585
+ ].includes(curNode[0].type)) {
586
+ return;
587
+ }
588
+ // 查找需要转换的块级节点
589
+ var blockNodes = findBlockNodesInSelection(editor, selection);
590
+ // 如果没有找到节点,且选区已折叠,使用当前节点
591
+ if (blockNodes.length === 0 && Range.isCollapsed(selection)) {
592
+ if ([
593
+ 'paragraph',
594
+ 'head'
595
+ ].includes(curNode[0].type)) {
596
+ blockNodes.push(curNode);
597
+ } else {
598
+ return;
599
+ }
600
+ }
601
+ // 处理部分选中:如果选区只选中了节点的一部分文本,转换整个节点
602
+ if (blockNodes.length === 0 && selection && !Range.isCollapsed(selection)) {
603
+ // 尝试获取选区覆盖的所有块级节点
604
+ var _Range_edges = _sliced_to_array(Range.edges(selection), 2), start = _Range_edges[0], end = _Range_edges[1];
605
+ var startPath = start.path;
606
+ var endPath = end.path;
607
+ // 如果起始和结束在同一路径,说明是单个节点的部分选中
608
+ if (Path.equals(startPath.slice(0, -1), endPath.slice(0, -1))) {
609
+ var parentPath = Path.parent(startPath);
610
+ var parentNode = Node.get(editor, parentPath);
611
+ if (Element.isElement(parentNode) && [
612
+ 'paragraph',
613
+ 'head'
614
+ ].includes(parentNode.type)) {
615
+ blockNodes.push([
616
+ parentNode,
617
+ parentPath
618
+ ]);
619
+ }
620
+ } else {
621
+ // 跨节点选中,查找所有涉及的块级节点
622
+ var allBlockNodes = Array.from(Editor.nodes(editor, {
623
+ at: selection,
624
+ match: function(n) {
625
+ return Element.isElement(n) && !Editor.isInline(editor, n) && [
626
+ 'paragraph',
627
+ 'head'
628
+ ].includes(n.type);
629
+ }
630
+ }));
631
+ blockNodes = allBlockNodes;
632
+ }
633
+ }
634
+ if (blockNodes.length === 0) {
635
+ return;
636
+ }
637
+ // 过滤掉已经在列表中的节点(避免重复包装)
638
+ blockNodes = blockNodes.filter(function(param) {
639
+ var _param = _sliced_to_array(param, 2), path = _param[1];
640
+ var parent = Editor.parent(editor, path);
641
+ return !Element.isElement(parent[0]) || parent[0].type !== 'list-item';
642
+ });
643
+ if (blockNodes.length === 0) {
644
+ return;
645
+ }
646
+ // 使用 withoutNormalizing 确保原子性
647
+ Editor.withoutNormalizing(editor, function() {
648
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
649
+ try {
650
+ // 步骤1: 处理标题降级和空节点
651
+ for(var _iterator = blockNodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
652
+ var _step_value = _sliced_to_array(_step.value, 2), node = _step_value[0], path = _step_value[1];
653
+ if (!node || !Element.isElement(node)) {
654
+ continue;
655
+ }
656
+ if (node.type === 'head') {
657
+ convertHeadingToParagraph(editor, path);
658
+ }
659
+ // 处理空节点:确保节点有内容
660
+ // 注意:convertHeadingToParagraph 可能改变了节点,需要重新获取
661
+ if (!Editor.hasPath(editor, path)) {
662
+ continue;
663
+ }
664
+ var currentNode = Node.get(editor, path);
665
+ if (currentNode && Element.isElement(currentNode) && currentNode.type === 'paragraph' && Node.string(currentNode).trim() === '') {
666
+ // 空节点保持原样,后续会正常包装
667
+ }
668
+ }
669
+ } catch (err) {
670
+ _didIteratorError = true;
671
+ _iteratorError = err;
672
+ } finally{
673
+ try {
674
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
675
+ _iterator.return();
676
+ }
677
+ } finally{
678
+ if (_didIteratorError) {
679
+ throw _iteratorError;
680
+ }
681
+ }
682
+ }
683
+ // 步骤2: 包装节点为 list-item
684
+ var listItemPaths = [];
685
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
686
+ try {
687
+ for(var _iterator1 = blockNodes[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
688
+ var _step_value1 = _sliced_to_array(_step1.value, 2), path1 = _step_value1[1];
689
+ // 检查节点是否已经是 list-item(可能在转换过程中变化)
690
+ var currentNode1 = Node.get(editor, path1);
691
+ if (Element.isElement(currentNode1) && currentNode1.type === 'list-item') {
692
+ listItemPaths.push(path1);
693
+ continue;
694
+ }
695
+ // 检查路径是否有效且不是根路径
696
+ if (!Editor.hasPath(editor, path1) || path1.length === 0) {
697
+ continue;
698
+ }
699
+ // 包装为 list-item
700
+ var listItemProps = _object_spread({
701
+ type: 'list-item',
702
+ mentions: [],
703
+ id: ''
704
+ }, mode === 'task' && {
705
+ checked: false
706
+ });
707
+ Transforms.wrapNodes(editor, listItemProps, {
708
+ at: path1
709
+ });
710
+ // 更新路径(因为包装后路径会变化)
711
+ // wrapNodes 后,list-item 的路径就是原来的 path
712
+ // 原节点现在在 [path, 0] 位置
713
+ // 所以 list-item 的路径就是 path
714
+ if (Editor.hasPath(editor, path1)) {
715
+ var listItemNode = Node.get(editor, path1);
716
+ if (Element.isElement(listItemNode) && listItemNode.type === 'list-item') {
717
+ listItemPaths.push(path1);
718
+ }
719
+ }
720
+ }
721
+ } catch (err) {
722
+ _didIteratorError1 = true;
723
+ _iteratorError1 = err;
724
+ } finally{
725
+ try {
726
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
727
+ _iterator1.return();
728
+ }
729
+ } finally{
730
+ if (_didIteratorError1) {
731
+ throw _iteratorError1;
732
+ }
733
+ }
734
+ }
735
+ // 步骤3: 包装 list-item 为列表
736
+ if (listItemPaths.length === 0) {
737
+ return;
738
+ }
739
+ // 检查第一个节点前后是否有相同类型的列表
740
+ var firstPath = listItemPaths[0];
741
+ // 验证路径有效性
742
+ if (!Editor.hasPath(editor, firstPath)) {
743
+ return;
744
+ }
745
+ // 获取第一个 list-item 的父路径(可能是容器)
746
+ var firstListItemParentPath;
747
+ try {
748
+ // 检查路径是否有效且不是根路径
749
+ if (firstPath.length === 0) {
750
+ // 如果是根路径,无法创建列表,直接返回
751
+ return;
752
+ }
753
+ var firstListItemParent = Editor.parent(editor, firstPath);
754
+ if (firstListItemParent && firstListItemParent[1]) {
755
+ firstListItemParentPath = firstListItemParent[1];
756
+ } else {
757
+ // 如果无法获取父路径,使用 Path.parent
758
+ firstListItemParentPath = Path.parent(firstPath);
759
+ }
760
+ } catch (error) {
761
+ // 如果无法获取父路径,使用 Path.parent
762
+ if (firstPath.length > 0) {
763
+ firstListItemParentPath = Path.parent(firstPath);
764
+ } else {
765
+ // 根路径无法创建列表
766
+ return;
767
+ }
768
+ }
769
+ // 检查相邻列表(在同一个父容器层级)
770
+ var adjacentListPath = findAdjacentList(editor, firstListItemParentPath, targetListType);
771
+ if (adjacentListPath) {
772
+ // 合并到相邻列表
773
+ mergeIntoAdjacentList(editor, listItemPaths, adjacentListPath);
774
+ // 删除空的列表容器(如果有)
775
+ var processedListPaths = new Set();
776
+ var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
777
+ try {
778
+ for(var _iterator2 = listItemPaths[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
779
+ var listItemPath = _step2.value;
780
+ if (Editor.hasPath(editor, listItemPath)) {
781
+ var listItemParent = Editor.parent(editor, listItemPath);
782
+ if (Element.isElement(listItemParent[0]) && isListType(listItemParent[0])) {
783
+ var listPath = listItemParent[1];
784
+ if (!processedListPaths.has(listPath)) {
785
+ processedListPaths.add(listPath);
786
+ var list = listItemParent[0];
787
+ if (list.children.length === 0) {
788
+ Transforms.removeNodes(editor, {
789
+ at: listPath
790
+ });
791
+ }
792
+ }
793
+ }
794
+ }
795
+ }
796
+ } catch (err) {
797
+ _didIteratorError2 = true;
798
+ _iteratorError2 = err;
799
+ } finally{
800
+ try {
801
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
802
+ _iterator2.return();
803
+ }
804
+ } finally{
805
+ if (_didIteratorError2) {
806
+ throw _iteratorError2;
807
+ }
808
+ }
809
+ }
810
+ } else {
811
+ // 创建新列表
812
+ var listProps = _object_spread({
813
+ type: targetListType
814
+ }, mode === 'ordered' && {
815
+ start: 1
816
+ }, mode === 'task' && {
817
+ task: true
818
+ });
819
+ // 包装第一个 list-item
820
+ Transforms.wrapNodes(editor, listProps, {
821
+ at: firstPath
822
+ });
823
+ // 将其他 list-item 移动到同一个列表中
824
+ // 包装后,list 的路径是 firstPath 的父路径
825
+ if (firstPath.length === 0) {
826
+ return; // 根路径无法创建列表
827
+ }
828
+ var listPath1 = Path.parent(firstPath);
829
+ // 验证列表路径有效
830
+ if (!Editor.hasPath(editor, listPath1)) {
831
+ return;
832
+ }
833
+ for(var i = 1; i < listItemPaths.length; i++){
834
+ var listItemPath1 = listItemPaths[i];
835
+ if (Editor.hasPath(editor, listItemPath1)) {
836
+ // 检查是否已经在列表中
837
+ var listItemParent1 = Editor.parent(editor, listItemPath1);
838
+ if (Element.isElement(listItemParent1[0]) && isListType(listItemParent1[0])) {
839
+ // 已经在列表中,移动到目标列表
840
+ var targetList = Node.get(editor, listPath1);
841
+ if (isListType(targetList)) {
842
+ var targetIndex = targetList.children.length;
843
+ Transforms.moveNodes(editor, {
844
+ at: listItemPath1,
845
+ to: _to_consumable_array(listPath1).concat([
846
+ targetIndex
847
+ ])
848
+ });
849
+ }
850
+ } else {
851
+ // 包装为列表,然后移动到目标列表
852
+ Transforms.wrapNodes(editor, listProps, {
853
+ at: listItemPath1
854
+ });
855
+ if (listItemPath1.length === 0) {
856
+ continue; // 跳过根路径
857
+ }
858
+ var newListPath = Path.parent(listItemPath1);
859
+ var targetList1 = Node.get(editor, listPath1);
860
+ if (isListType(targetList1)) {
861
+ var targetIndex1 = targetList1.children.length;
862
+ Transforms.moveNodes(editor, {
863
+ at: listItemPath1,
864
+ to: _to_consumable_array(listPath1).concat([
865
+ targetIndex1
866
+ ])
867
+ });
868
+ // 删除空的列表容器
869
+ if (Editor.hasPath(editor, newListPath)) {
870
+ var emptyList = Node.get(editor, newListPath);
871
+ if (isListType(emptyList) && emptyList.children.length === 0) {
872
+ Transforms.removeNodes(editor, {
873
+ at: newListPath
874
+ });
875
+ }
876
+ }
877
+ }
878
+ }
879
+ }
880
+ }
881
+ }
882
+ // 步骤4: 更新光标位置
883
+ if (listItemPaths.length > 0) {
884
+ var firstListItemPath = listItemPaths[0];
885
+ if (Editor.hasPath(editor, firstListItemPath)) {
886
+ Transforms.select(editor, Editor.start(editor, firstListItemPath));
887
+ }
888
+ }
889
+ });
890
+ }
891
+ /**
892
+ * 增加标题级别(使标题变小)
893
+ *
894
+ * 将段落转换为4级标题,
895
+ * 或将标题级别从1级改为普通段落,
896
+ * 或将其他级别标题升级一级(数字变小)
897
+ *
898
+ * @param editor Slate 编辑器实例
899
+ */ export function increaseHeadingLevel(editor) {
900
+ var _node_;
901
+ var _getCurrentNodes = _sliced_to_array(getCurrentNodes(editor), 1), node = _getCurrentNodes[0];
902
+ if (node && [
903
+ 'paragraph',
904
+ 'head'
905
+ ].includes(node === null || node === void 0 ? void 0 : (_node_ = node[0]) === null || _node_ === void 0 ? void 0 : _node_.type) && EditorUtils.isTop(editor, node[1])) {
906
+ var _node_1;
907
+ if ((node === null || node === void 0 ? void 0 : (_node_1 = node[0]) === null || _node_1 === void 0 ? void 0 : _node_1.type) === 'paragraph') {
908
+ Transforms.setNodes(editor, {
909
+ type: 'head',
910
+ level: 4
911
+ }, {
912
+ at: node[1]
913
+ });
914
+ } else if (node[0].level === 1) {
915
+ Transforms.setNodes(editor, {
916
+ type: 'paragraph'
917
+ }, {
918
+ at: node[1]
919
+ });
920
+ } else {
921
+ Transforms.setNodes(editor, {
922
+ level: node[0].level - 1
923
+ }, {
924
+ at: node[1]
925
+ });
926
+ }
927
+ }
928
+ }
929
+ /**
930
+ * 降低标题级别(使标题变大)
931
+ *
932
+ * 将段落转换为1级标题,
933
+ * 或将4级标题改为普通段落,
934
+ * 或将其他级别标题降级一级(数字变大)
935
+ *
936
+ * @param editor Slate 编辑器实例
937
+ */ export function decreaseHeadingLevel(editor) {
938
+ var _node_;
939
+ var _getCurrentNodes = _sliced_to_array(getCurrentNodes(editor), 1), node = _getCurrentNodes[0];
940
+ if (node && [
941
+ 'paragraph',
942
+ 'head'
943
+ ].includes(node === null || node === void 0 ? void 0 : (_node_ = node[0]) === null || _node_ === void 0 ? void 0 : _node_.type) && EditorUtils.isTop(editor, node[1])) {
944
+ var _node_1;
945
+ if ((node === null || node === void 0 ? void 0 : (_node_1 = node[0]) === null || _node_1 === void 0 ? void 0 : _node_1.type) === 'paragraph') {
946
+ Transforms.setNodes(editor, {
947
+ type: 'head',
948
+ level: 1
949
+ }, {
950
+ at: node[1]
951
+ });
952
+ } else if (node[0].level === 4) {
953
+ Transforms.setNodes(editor, {
954
+ type: 'paragraph'
955
+ }, {
956
+ at: node[1]
957
+ });
958
+ } else {
959
+ Transforms.setNodes(editor, {
960
+ level: node[0].level + 1
961
+ }, {
962
+ at: node[1]
963
+ });
964
+ }
965
+ }
966
+ }