@ant-design/agentic-ui 2.30.0 → 2.30.1

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 (63) hide show
  1. package/dist/Bubble/List/index.d.ts +4 -0
  2. package/dist/Bubble/List/index.js +8 -5
  3. package/dist/Bubble/MessagesContent/EXCEPTION.js +11 -2
  4. package/dist/Bubble/MessagesContent/MarkdownPreview.js +13 -7
  5. package/dist/Bubble/MessagesContent/index.js +39 -10
  6. package/dist/Bubble/MessagesContent/style.js +55 -22
  7. package/dist/Bubble/type.d.ts +4 -0
  8. package/dist/I18n/locales.js +2 -2
  9. package/dist/MarkdownEditor/BaseMarkdownEditor.js +37 -5
  10. package/dist/MarkdownEditor/editor/elements/AgenticUiBlocks/AgenticUiTaskBlock.d.ts +4 -0
  11. package/dist/MarkdownEditor/editor/elements/AgenticUiBlocks/AgenticUiTaskBlock.js +74 -0
  12. package/dist/MarkdownEditor/editor/elements/AgenticUiBlocks/AgenticUiToolUseBarBlock.d.ts +4 -0
  13. package/dist/MarkdownEditor/editor/elements/AgenticUiBlocks/AgenticUiToolUseBarBlock.js +114 -0
  14. package/dist/MarkdownEditor/editor/elements/AgenticUiBlocks/agenticUiEmbedUtils.d.ts +20 -0
  15. package/dist/MarkdownEditor/editor/elements/AgenticUiBlocks/agenticUiEmbedUtils.js +169 -0
  16. package/dist/MarkdownEditor/editor/elements/Table/EditableTable.d.ts +11 -0
  17. package/dist/MarkdownEditor/editor/elements/Table/EditableTable.js +207 -0
  18. package/dist/MarkdownEditor/editor/elements/Table/Table.js +10 -276
  19. package/dist/MarkdownEditor/editor/elements/Table/TableCellIndex/index.js +7 -227
  20. package/dist/MarkdownEditor/editor/elements/Table/TableCellIndexSpacer/index.js +20 -229
  21. package/dist/MarkdownEditor/editor/elements/Table/commands/tableCommands.d.ts +9 -0
  22. package/dist/MarkdownEditor/editor/elements/Table/commands/tableCommands.js +242 -0
  23. package/dist/MarkdownEditor/editor/elements/Table/utils/editableTableWidth.d.ts +20 -0
  24. package/dist/MarkdownEditor/editor/elements/Table/utils/editableTableWidth.js +60 -0
  25. package/dist/MarkdownEditor/editor/elements/Table/utils/useEditableTableColWidths.d.ts +6 -0
  26. package/dist/MarkdownEditor/editor/elements/Table/utils/useEditableTableColWidths.js +20 -0
  27. package/dist/MarkdownEditor/editor/elements/Table/utils/useEditableTableContentWidth.d.ts +10 -0
  28. package/dist/MarkdownEditor/editor/elements/Table/utils/useEditableTableContentWidth.js +103 -0
  29. package/dist/MarkdownEditor/editor/elements/index.js +7 -0
  30. package/dist/MarkdownEditor/editor/parser/parse/parseCode.js +33 -2
  31. package/dist/MarkdownEditor/editor/parser/parserSlateNodeToMarkdown.js +3 -0
  32. package/dist/MarkdownEditor/editor/plugins/handlePaste.js +4 -1
  33. package/dist/MarkdownEditor/style.js +109 -7
  34. package/dist/MarkdownEditor/types.d.ts +5 -0
  35. package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/AttachmentFileIcon.js +2 -2
  36. package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/AttachmentFileListItem.js +11 -8
  37. package/dist/MarkdownInputField/AttachmentButton/index.js +7 -2
  38. package/dist/MarkdownInputField/AttachmentButton/types.d.ts +5 -1
  39. package/dist/MarkdownInputField/AttachmentButton/utils.d.ts +7 -0
  40. package/dist/MarkdownInputField/AttachmentButton/utils.js +9 -1
  41. package/dist/MarkdownInputField/FileMapView/FileMapViewItem.js +10 -5
  42. package/dist/MarkdownInputField/FileUploadManager/index.d.ts +9 -0
  43. package/dist/MarkdownInputField/FileUploadManager/index.js +20 -4
  44. package/dist/MarkdownInputField/MarkdownInputField.js +5 -3
  45. package/dist/MarkdownInputField/SendActions/index.d.ts +9 -0
  46. package/dist/MarkdownInputField/SendActions/index.js +3 -2
  47. package/dist/MarkdownInputField/utils/renderHelpers.d.ts +8 -1
  48. package/dist/MarkdownInputField/utils/renderHelpers.js +5 -1
  49. package/dist/MarkdownRenderer/AnimationText.d.ts +4 -7
  50. package/dist/MarkdownRenderer/AnimationText.js +117 -15
  51. package/dist/MarkdownRenderer/MarkdownRenderer.js +15 -1
  52. package/dist/MarkdownRenderer/index.d.ts +2 -2
  53. package/dist/MarkdownRenderer/index.js +1 -1
  54. package/dist/MarkdownRenderer/renderers/AgenticUiTaskBlockRenderer.d.ts +6 -0
  55. package/dist/MarkdownRenderer/renderers/AgenticUiTaskBlockRenderer.js +66 -0
  56. package/dist/MarkdownRenderer/renderers/AgenticUiToolUseBarBlockRenderer.d.ts +6 -0
  57. package/dist/MarkdownRenderer/renderers/AgenticUiToolUseBarBlockRenderer.js +134 -0
  58. package/dist/MarkdownRenderer/style.js +7 -6
  59. package/dist/MarkdownRenderer/useMarkdownToReact.js +5 -4
  60. package/dist/MarkdownRenderer/useStreaming.js +8 -1
  61. package/dist/Plugins/chart/ChartRender.js +1 -0
  62. package/dist/Plugins/chart/index.js +3 -1
  63. package/package.json +2 -1
@@ -1,99 +1,3 @@
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 ownKeys(object, enumerableOnly) {
74
- var keys = Object.keys(object);
75
- if (Object.getOwnPropertySymbols) {
76
- var symbols = Object.getOwnPropertySymbols(object);
77
- if (enumerableOnly) {
78
- symbols = symbols.filter(function(sym) {
79
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
80
- });
81
- }
82
- keys.push.apply(keys, symbols);
83
- }
84
- return keys;
85
- }
86
- function _object_spread_props(target, source) {
87
- source = source != null ? source : {};
88
- if (Object.getOwnPropertyDescriptors) {
89
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
90
- } else {
91
- ownKeys(Object(source)).forEach(function(key) {
92
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
93
- });
94
- }
95
- return target;
96
- }
97
1
  function _object_without_properties(source, excluded) {
98
2
  if (source == null) return {};
99
3
  var target = {}, sourceKeys, key, i;
@@ -130,32 +34,12 @@ function _object_without_properties_loose(source, excluded) {
130
34
  }
131
35
  return target;
132
36
  }
133
- function _sliced_to_array(arr, i) {
134
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
135
- }
136
- function _to_consumable_array(arr) {
137
- return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
138
- }
139
- function _unsupported_iterable_to_array(o, minLen) {
140
- if (!o) return;
141
- if (typeof o === "string") return _array_like_to_array(o, minLen);
142
- var n = Object.prototype.toString.call(o).slice(8, -1);
143
- if (n === "Object" && o.constructor) n = o.constructor.name;
144
- if (n === "Map" || n === "Set") return Array.from(n);
145
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
146
- }
147
37
  import { ConfigProvider } from "antd";
148
- import classNames from "clsx";
149
- import React, { useContext, useEffect, useMemo, useRef } from "react";
150
- import { Node } from "slate";
151
- import stringWidth from "string-width";
152
- import { MOBILE_BREAKPOINT, MOBILE_TABLE_MIN_COLUMN_WIDTH, TABLE_EDIT_COL_WIDTH_MIN_COLUMNS } from "../../../../Constants/mobile";
38
+ import React, { useContext } from "react";
153
39
  import { useEditorStore } from "../../store";
40
+ import { EditableTable } from "./EditableTable";
154
41
  import { ReadonlyTableComponent } from "./ReadonlyTableComponent";
155
- import { TABLE_ROW_INDEX_COL_WIDTH, TableColgroup } from "./TableColgroup";
156
42
  import { TablePropsContext } from "./TableContext";
157
- import { TableRowIndex } from "./TableRowIndex";
158
- import useScrollShadow from "./useScrollShadow";
159
43
  /**
160
44
  * 表格组
161
45
  *
@@ -185,173 +69,23 @@ import useScrollShadow from "./useScrollShadow";
185
69
  var children = _0.children, props = _object_without_properties(_0, [
186
70
  "children"
187
71
  ]);
188
- var _editorProps_tableConfig, _props_element_children__children, _props_element_children_, _props_element_children, _props_element, _props_element_otherProps, _props_element1, _props_element_children1, _props_element2;
72
+ var _editorProps_tableConfig;
189
73
  var _useEditorStore = useEditorStore(), readonly = _useEditorStore.readonly, markdownContainerRef = _useEditorStore.markdownContainerRef, editorProps = _useEditorStore.editorProps;
190
74
  var tableCssVariables = editorProps === null || editorProps === void 0 ? void 0 : (_editorProps_tableConfig = editorProps.tableConfig) === null || _editorProps_tableConfig === void 0 ? void 0 : _editorProps_tableConfig.cssVariables;
191
75
  var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
192
76
  var tablePath = useContext(TablePropsContext).tablePath;
193
77
  var baseCls = getPrefixCls('agentic-md-editor-content-table');
194
- var tableTargetRef = useRef(null);
195
- var columnCount = ((_props_element = props.element) === null || _props_element === void 0 ? void 0 : (_props_element_children = _props_element.children) === null || _props_element_children === void 0 ? void 0 : (_props_element_children_ = _props_element_children[0]) === null || _props_element_children_ === void 0 ? void 0 : (_props_element_children__children = _props_element_children_.children) === null || _props_element_children__children === void 0 ? void 0 : _props_element_children__children.length) || 0;
196
- var mobileBreakpointValue = parseInt(MOBILE_BREAKPOINT, 10) || 768;
197
- // 总是调用 hooks,避免条件调用
198
- var _useScrollShadow = _sliced_to_array(useScrollShadow(), 2), tableRef = _useScrollShadow[0], scrollState = _useScrollShadow[1];
199
- // 编辑模式下列宽计算(readonly 时走 ReadonlyTableComponent,跳过计算)
200
- var colWidths = useMemo(function() {
201
- var _props_element_otherProps_colWidths, _props_element_otherProps, _props_element, _props_element_children, _props_element1, _tableRows__children, _tableRows_, _markdownContainerRef_current_querySelector, _markdownContainerRef_current;
202
- if (readonly) return [];
203
- // 少于 TABLE_EDIT_COL_WIDTH_MIN_COLUMNS 列不设置 data col,仅行号列(显式 colWidths 也忽略)
204
- if (columnCount < TABLE_EDIT_COL_WIDTH_MIN_COLUMNS) return [];
205
- // 显式传入 colWidths 时优先使用
206
- if ((_props_element = props.element) === null || _props_element === void 0 ? void 0 : (_props_element_otherProps = _props_element.otherProps) === null || _props_element_otherProps === void 0 ? void 0 : (_props_element_otherProps_colWidths = _props_element_otherProps.colWidths) === null || _props_element_otherProps_colWidths === void 0 ? void 0 : _props_element_otherProps_colWidths.length) {
207
- return props.element.otherProps.colWidths;
208
- }
209
- if (typeof window === 'undefined' || !((_props_element1 = props.element) === null || _props_element1 === void 0 ? void 0 : (_props_element_children = _props_element1.children) === null || _props_element_children === void 0 ? void 0 : _props_element_children.length)) return [];
210
- var tableRows = props.element.children;
211
- if (!(tableRows === null || tableRows === void 0 ? void 0 : (_tableRows_ = tableRows[0]) === null || _tableRows_ === void 0 ? void 0 : (_tableRows__children = _tableRows_.children) === null || _tableRows__children === void 0 ? void 0 : _tableRows__children.length)) return [];
212
- // 只获取一次容器宽度
213
- var containerWidth = ((markdownContainerRef === null || markdownContainerRef === void 0 ? void 0 : (_markdownContainerRef_current = markdownContainerRef.current) === null || _markdownContainerRef_current === void 0 ? void 0 : (_markdownContainerRef_current_querySelector = _markdownContainerRef_current.querySelector('.ant-agentic-md-editor-content')) === null || _markdownContainerRef_current_querySelector === void 0 ? void 0 : _markdownContainerRef_current_querySelector.clientWidth) || 400) - 32 - 12;
214
- var isMobileLayout = containerWidth <= mobileBreakpointValue;
215
- var minColumnWidth = isMobileLayout ? MOBILE_TABLE_MIN_COLUMN_WIDTH : 60;
216
- var maxColumnWidth = isMobileLayout ? containerWidth : containerWidth / 4;
217
- // 至少采样 3 行用于列宽计算(若有 3 行以上),不足 3 行时自动使用全部可用行
218
- var rowsToSample = tableRows.length >= 3 ? Math.min(5, tableRows.length) : tableRows.length;
219
- // 一次性计算宽度
220
- var calculatedWidths = Array.from({
221
- length: columnCount
222
- }, function(_, colIndex) {
223
- var _Math;
224
- var cellWidths = [];
225
- for(var rowIndex = 0; rowIndex < rowsToSample; rowIndex++){
226
- var _tableRows_rowIndex_children, _tableRows_rowIndex;
227
- var cell = (_tableRows_rowIndex = tableRows[rowIndex]) === null || _tableRows_rowIndex === void 0 ? void 0 : (_tableRows_rowIndex_children = _tableRows_rowIndex.children) === null || _tableRows_rowIndex_children === void 0 ? void 0 : _tableRows_rowIndex_children[colIndex];
228
- if (cell) {
229
- var textWidth = stringWidth(Node.string(cell)) * 12;
230
- cellWidths.push(textWidth);
231
- }
232
- }
233
- return Math.min((_Math = Math).max.apply(_Math, [
234
- minColumnWidth
235
- ].concat(_to_consumable_array(cellWidths))), maxColumnWidth);
236
- });
237
- // 如果表格少于5行且总宽度超过容器宽度,则均匀分配宽度
238
- if (tableRows.length < 5 && columnCount > 0) {
239
- var totalWidth = calculatedWidths.reduce(function(sum, width) {
240
- return sum + width;
241
- }, 0);
242
- if (totalWidth > containerWidth) {
243
- var evenWidth = Math.max(minColumnWidth, Math.floor(containerWidth / columnCount));
244
- return Array(columnCount).fill(evenWidth);
245
- }
246
- }
247
- return calculatedWidths;
248
- }, [
249
- readonly,
250
- (_props_element1 = props.element) === null || _props_element1 === void 0 ? void 0 : (_props_element_otherProps = _props_element1.otherProps) === null || _props_element_otherProps === void 0 ? void 0 : _props_element_otherProps.colWidths,
251
- (_props_element2 = props.element) === null || _props_element2 === void 0 ? void 0 : (_props_element_children1 = _props_element2.children) === null || _props_element_children1 === void 0 ? void 0 : _props_element_children1.length,
252
- columnCount,
253
- markdownContainerRef
254
- ]);
255
- // 只在编辑模式下添加resize事件监听
256
- useEffect(function() {
257
- if (readonly || typeof window === 'undefined') return;
258
- var resize = function resize() {
259
- var _markdownContainerRef_current_querySelector, _markdownContainerRef_current;
260
- if (process.env.NODE_ENV === 'test') return;
261
- var maxWidth = colWidths ? (colWidths === null || colWidths === void 0 ? void 0 : colWidths.reduce(function(a, b) {
262
- return a + b;
263
- }, 0)) + 8 : 0;
264
- var minWidth = markdownContainerRef === null || markdownContainerRef === void 0 ? void 0 : (_markdownContainerRef_current = markdownContainerRef.current) === null || _markdownContainerRef_current === void 0 ? void 0 : (_markdownContainerRef_current_querySelector = _markdownContainerRef_current.querySelector('.ant-agentic-md-editor-content')) === null || _markdownContainerRef_current_querySelector === void 0 ? void 0 : _markdownContainerRef_current_querySelector.clientWidth;
265
- var dom = tableRef.current;
266
- if (dom) {
267
- setTimeout(function() {
268
- var _markdownContainerRef_current_querySelector, _markdownContainerRef_current;
269
- var containerWidthForBreakpoint = ((markdownContainerRef === null || markdownContainerRef === void 0 ? void 0 : (_markdownContainerRef_current = markdownContainerRef.current) === null || _markdownContainerRef_current === void 0 ? void 0 : (_markdownContainerRef_current_querySelector = _markdownContainerRef_current.querySelector('.ant-agentic-md-editor-content')) === null || _markdownContainerRef_current_querySelector === void 0 ? void 0 : _markdownContainerRef_current_querySelector.clientWidth) || 400) - 32 - 12;
270
- var isMobileLayout = containerWidthForBreakpoint <= mobileBreakpointValue;
271
- var computedMinColumnWidth = isMobileLayout ? MOBILE_TABLE_MIN_COLUMN_WIDTH : 60;
272
- var fallbackMinWidth = Number(((minWidth || 200) * 0.95).toFixed(0));
273
- var requiredMinWidth = Math.max(columnCount * computedMinColumnWidth, maxWidth, fallbackMinWidth, 200);
274
- dom.style.minWidth = "".concat(requiredMinWidth, "px");
275
- }, 200);
276
- }
277
- };
278
- document.addEventListener('md-resize', resize);
279
- window.addEventListener('resize', resize);
280
- resize();
281
- return function() {
282
- document.removeEventListener('md-resize', resize);
283
- window.removeEventListener('resize', resize);
284
- };
285
- }, [
286
- colWidths,
287
- readonly,
288
- markdownContainerRef,
289
- tableRef
290
- ]);
291
- useEffect(function() {
292
- if (readonly) return;
293
- document.dispatchEvent(new CustomEvent('md-resize', {
294
- detail: {}
295
- }));
296
- }, [
297
- readonly
298
- ]);
299
- // 缓存表格DOM,减少重复渲染
300
- var tableDom = useMemo(function() {
301
- return /*#__PURE__*/ React.createElement("table", {
302
- ref: tableTargetRef,
303
- className: classNames("".concat(baseCls, "-editor-table")),
304
- onDragStart: function onDragStart(e) {
305
- // 阻止拖拽开始事件
306
- e.preventDefault();
307
- return false;
308
- }
309
- }, /*#__PURE__*/ React.createElement(TableColgroup, {
310
- colWidths: colWidths !== null && colWidths !== void 0 ? colWidths : [],
311
- prefixColWidth: TABLE_ROW_INDEX_COL_WIDTH
312
- }), /*#__PURE__*/ React.createElement("tbody", null, readonly ? null : /*#__PURE__*/ React.createElement(TableRowIndex, {
313
- colWidths: colWidths,
314
- columnCount: columnCount,
315
- tablePath: tablePath
316
- }), children));
317
- }, [
318
- colWidths,
319
- columnCount,
320
- children,
321
- baseCls
322
- ]);
323
- // 缓存boxShadow样式,只在scrollState变化时重新计算
324
- var boxShadowStyle = useMemo(function() {
325
- return {
326
- flex: 1,
327
- minWidth: 0,
328
- boxShadow: readonly ? undefined : "\n ".concat(scrollState.vertical.hasScroll && !scrollState.vertical.isAtStart ? 'inset 0 8px 8px -8px rgba(0,0,0,0.1)' : '', "\n ").concat(scrollState.vertical.hasScroll && !scrollState.vertical.isAtEnd ? 'inset 0 -8px 8px -8px rgba(0,0,0,0.1)' : '', "\n ").concat(scrollState.horizontal.hasScroll && !scrollState.horizontal.isAtStart ? 'inset 8px 0 8px -8px rgba(0,0,0,0.1)' : '', "\n ").concat(scrollState.horizontal.hasScroll && !scrollState.horizontal.isAtEnd ? 'inset -8px 0 8px -8px rgba(0,0,0,0.1)' : '', "\n ")
329
- };
330
- }, [
331
- scrollState,
332
- readonly
333
- ]);
334
- // readonly 模式渲染 - 使用优化的组件(早期返回)
335
78
  if (readonly) {
336
79
  return /*#__PURE__*/ React.createElement(ReadonlyTableComponent, {
337
80
  element: props.element,
338
81
  baseCls: baseCls
339
82
  }, children);
340
83
  }
341
- // 编辑模式渲染
342
- return /*#__PURE__*/ React.createElement("div", {
343
- className: classNames(baseCls),
344
- ref: tableRef,
345
- style: _object_spread(_object_spread_props(_object_spread({}, boxShadowStyle), {
346
- position: 'relative'
347
- }), tableCssVariables),
348
- onDragStart: function onDragStart(e) {
349
- // 阻止拖拽开始时的文字选择
350
- e.preventDefault();
351
- },
352
- onDoubleClick: function onDoubleClick(e) {
353
- // 阻止双击选择文字
354
- e.preventDefault();
355
- }
356
- }, tableDom);
84
+ return /*#__PURE__*/ React.createElement(EditableTable, {
85
+ baseCls: baseCls,
86
+ tablePath: tablePath,
87
+ tableNode: props.element,
88
+ markdownContainerRef: markdownContainerRef,
89
+ tableCssVariables: tableCssVariables
90
+ }, children);
357
91
  };
@@ -1,14 +1,3 @@
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
1
  function _define_property(obj, key, value) {
13
2
  if (key in obj) {
14
3
  Object.defineProperty(obj, key, {
@@ -22,39 +11,6 @@ function _define_property(obj, key, value) {
22
11
  }
23
12
  return obj;
24
13
  }
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
14
  function _object_spread(target) {
59
15
  for(var i = 1; i < arguments.length; i++){
60
16
  var source = arguments[i] != null ? arguments[i] : {};
@@ -70,30 +26,15 @@ function _object_spread(target) {
70
26
  }
71
27
  return target;
72
28
  }
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
29
  import { DeleteOutlined, InsertRowAboveOutlined, InsertRowBelowOutlined } from "@ant-design/icons";
88
30
  import { ConfigProvider } from "antd";
89
31
  import classNames from "clsx";
90
32
  import React, { useContext, useRef } from "react";
91
- import { Editor, Transforms } from "slate";
92
- import { ReactEditor, useSlate } from "slate-react";
33
+ import { useSlate } from "slate-react";
93
34
  import { useClickAway } from "../../../../../Hooks/useClickAway";
94
35
  import { useRefFunction } from "../../../../../Hooks/useRefFunction";
95
36
  import { I18nContext } from "../../../../../I18n";
96
- import { NativeTableEditor } from "../../../../utils/native-table";
37
+ import { clearTableSelection, insertTableRow, removeTableRow, selectTableRow } from "../commands/tableCommands";
97
38
  import { TablePropsContext } from "../TableContext";
98
39
  /**
99
40
  * TableCellIndex 组件 - 表格行索引单元格组件
@@ -148,39 +89,7 @@ import { TablePropsContext } from "../TableContext";
148
89
  return;
149
90
  }
150
91
  try {
151
- var _tableElement_children;
152
- // 获取表格元素
153
- var tableElement = Editor.node(editor, tablePath)[0];
154
- if (!tableElement || tableElement.type !== 'table') {
155
- return;
156
- }
157
- // 获取表格的行数
158
- var rowCount = ((_tableElement_children = tableElement.children) === null || _tableElement_children === void 0 ? void 0 : _tableElement_children.length) || 0;
159
- if (rowCount === 0) {
160
- return;
161
- }
162
- // 清除所有行的选中状态 - 通过 DOM 操作移除 data-select 属性
163
- for(var rowIdx = 0; rowIdx < rowCount; rowIdx++){
164
- var rowElement = tableElement.children[rowIdx];
165
- if (rowElement && rowElement.children) {
166
- for(var colIdx = 0; colIdx < rowElement.children.length; colIdx++){
167
- var cellPath = _to_consumable_array(tablePath).concat([
168
- rowIdx,
169
- colIdx
170
- ]);
171
- if (Editor.hasPath(editor, cellPath)) {
172
- var _Editor_node = _sliced_to_array(Editor.node(editor, cellPath), 1), cellNode = _Editor_node[0];
173
- if (cellNode && cellNode.type === 'table-cell') {
174
- // 通过 DOM 操作移除 data-select 属性
175
- var domNode = ReactEditor.toDOMNode(editor, cellNode);
176
- if (domNode) {
177
- domNode.removeAttribute('data-select');
178
- }
179
- }
180
- }
181
- }
182
- }
183
- }
92
+ clearTableSelection(editor, tablePath);
184
93
  } catch (error) {
185
94
  console.warn('Failed to clear table selection:', error);
186
95
  }
@@ -201,38 +110,8 @@ import { TablePropsContext } from "../TableContext";
201
110
  return;
202
111
  }
203
112
  try {
204
- var _tableElement_children;
205
- // 获取表格元素
206
- var tableElement = Editor.node(editor, tablePath)[0];
207
- if (!tableElement || tableElement.type !== 'table') {
208
- return;
209
- }
210
- // 获取表格的行数和列数
211
- var rowCount = ((_tableElement_children = tableElement.children) === null || _tableElement_children === void 0 ? void 0 : _tableElement_children.length) || 0;
212
- if (rowCount === 0) {
213
- return;
214
- }
215
113
  clearSelect(false);
216
- // 选中指定行的所有单元格 - 通过 DOM 操作设置 data-select 属性
217
- var rowElement = tableElement.children[rowIndex];
218
- if (rowElement && rowElement.children) {
219
- for(var colIdx = 0; colIdx < rowElement.children.length; colIdx++){
220
- var cellPath = _to_consumable_array(tablePath).concat([
221
- rowIndex,
222
- colIdx
223
- ]);
224
- if (Editor.hasPath(editor, cellPath)) {
225
- var _Editor_node = _sliced_to_array(Editor.node(editor, cellPath), 1), cellNode = _Editor_node[0];
226
- if (cellNode && cellNode.type === 'table-cell') {
227
- // 通过 DOM 操作设置 data-select 属性
228
- var domNode = ReactEditor.toDOMNode(editor, cellNode);
229
- if (domNode) {
230
- domNode.setAttribute('data-select', 'true');
231
- }
232
- }
233
- }
234
- }
235
- }
114
+ selectTableRow(editor, tablePath, rowIndex);
236
115
  } catch (error) {
237
116
  console.warn('Failed to select table row:', error);
238
117
  }
@@ -246,35 +125,7 @@ import { TablePropsContext } from "../TableContext";
246
125
  if (!tablePath || rowIndex === undefined) {
247
126
  return;
248
127
  }
249
- // 获取表格元素
250
- var tableElement = Editor.node(editor, tablePath)[0];
251
- if (!tableElement || tableElement.type !== 'table') {
252
- return;
253
- }
254
- var rowCount = tableElement.children.length;
255
- var firstRow = tableElement.children[0];
256
- var colCount = firstRow.children.length;
257
- // 检查是否只有一行一列
258
- if (rowCount <= 1 && colCount <= 1) {
259
- // 如果只有一行一列,删除整个表格
260
- NativeTableEditor.removeTable(editor, tablePath);
261
- return;
262
- }
263
- // 检查是否只有一行
264
- if (rowCount <= 1) {
265
- // 如果只有一行,删除整个表格
266
- NativeTableEditor.removeTable(editor, tablePath);
267
- return;
268
- }
269
- // 删除指定行
270
- var rowPath = _to_consumable_array(tablePath).concat([
271
- rowIndex
272
- ]);
273
- if (Editor.hasPath(editor, rowPath)) {
274
- Transforms.removeNodes(editor, {
275
- at: rowPath
276
- });
277
- }
128
+ removeTableRow(editor, tablePath, rowIndex);
278
129
  clearSelect();
279
130
  } catch (error) {
280
131
  console.warn('Failed to delete table row:', error);
@@ -289,41 +140,7 @@ import { TablePropsContext } from "../TableContext";
289
140
  if (!tablePath || rowIndex === undefined) {
290
141
  return;
291
142
  }
292
- // 获取表格元素
293
- var tableElement = Editor.node(editor, tablePath)[0];
294
- if (!tableElement || tableElement.type !== 'table') {
295
- return;
296
- }
297
- var firstRow = tableElement.children[0];
298
- var colCount = firstRow.children.length;
299
- // 创建新行
300
- var newRow = {
301
- type: 'table-row',
302
- children: Array.from({
303
- length: colCount
304
- }).map(function() {
305
- return {
306
- type: 'table-cell',
307
- children: [
308
- {
309
- type: 'paragraph',
310
- children: [
311
- {
312
- text: ''
313
- }
314
- ]
315
- }
316
- ]
317
- };
318
- })
319
- };
320
- // 在当前行之前插入新行
321
- var rowPath = _to_consumable_array(tablePath).concat([
322
- rowIndex
323
- ]);
324
- Transforms.insertNodes(editor, newRow, {
325
- at: rowPath
326
- });
143
+ insertTableRow(editor, tablePath, rowIndex, 'before');
327
144
  clearSelect();
328
145
  } catch (error) {
329
146
  console.warn('Failed to insert row before:', error);
@@ -338,44 +155,7 @@ import { TablePropsContext } from "../TableContext";
338
155
  if (!tablePath || rowIndex === undefined) {
339
156
  return;
340
157
  }
341
- // 获取表格元素
342
- var tableElement = Editor.node(editor, tablePath)[0];
343
- if (!tableElement || tableElement.type !== 'table') {
344
- return;
345
- }
346
- var firstRow = tableElement.children[0];
347
- var colCount = firstRow.children.length;
348
- // 创建新行
349
- var newRow = {
350
- type: 'table-row',
351
- children: Array.from({
352
- length: colCount
353
- }).map(function() {
354
- return {
355
- type: 'table-cell',
356
- children: [
357
- {
358
- type: 'paragraph',
359
- children: [
360
- {
361
- text: ''
362
- }
363
- ]
364
- }
365
- ]
366
- };
367
- })
368
- };
369
- // 在当前行之后插入新行
370
- // 获取表格的行数来检查边界
371
- var rowCount = tableElement.children.length;
372
- var insertRowIndex = Math.min(rowIndex + 1, rowCount);
373
- var rowPath = _to_consumable_array(tablePath).concat([
374
- insertRowIndex
375
- ]);
376
- Transforms.insertNodes(editor, newRow, {
377
- at: rowPath
378
- });
158
+ insertTableRow(editor, tablePath, rowIndex, 'after');
379
159
  clearSelect();
380
160
  } catch (error) {
381
161
  console.warn('Failed to insert row after:', error);