@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.
- package/dist/Bubble/List/index.d.ts +4 -0
- package/dist/Bubble/List/index.js +8 -5
- package/dist/Bubble/MessagesContent/EXCEPTION.js +11 -2
- package/dist/Bubble/MessagesContent/MarkdownPreview.js +13 -7
- package/dist/Bubble/MessagesContent/index.js +39 -10
- package/dist/Bubble/MessagesContent/style.js +55 -22
- package/dist/Bubble/type.d.ts +4 -0
- package/dist/I18n/locales.js +2 -2
- package/dist/MarkdownEditor/BaseMarkdownEditor.js +37 -5
- package/dist/MarkdownEditor/editor/elements/AgenticUiBlocks/AgenticUiTaskBlock.d.ts +4 -0
- package/dist/MarkdownEditor/editor/elements/AgenticUiBlocks/AgenticUiTaskBlock.js +74 -0
- package/dist/MarkdownEditor/editor/elements/AgenticUiBlocks/AgenticUiToolUseBarBlock.d.ts +4 -0
- package/dist/MarkdownEditor/editor/elements/AgenticUiBlocks/AgenticUiToolUseBarBlock.js +114 -0
- package/dist/MarkdownEditor/editor/elements/AgenticUiBlocks/agenticUiEmbedUtils.d.ts +20 -0
- package/dist/MarkdownEditor/editor/elements/AgenticUiBlocks/agenticUiEmbedUtils.js +169 -0
- package/dist/MarkdownEditor/editor/elements/Table/EditableTable.d.ts +11 -0
- package/dist/MarkdownEditor/editor/elements/Table/EditableTable.js +207 -0
- package/dist/MarkdownEditor/editor/elements/Table/Table.js +10 -276
- package/dist/MarkdownEditor/editor/elements/Table/TableCellIndex/index.js +7 -227
- package/dist/MarkdownEditor/editor/elements/Table/TableCellIndexSpacer/index.js +20 -229
- package/dist/MarkdownEditor/editor/elements/Table/commands/tableCommands.d.ts +9 -0
- package/dist/MarkdownEditor/editor/elements/Table/commands/tableCommands.js +242 -0
- package/dist/MarkdownEditor/editor/elements/Table/utils/editableTableWidth.d.ts +20 -0
- package/dist/MarkdownEditor/editor/elements/Table/utils/editableTableWidth.js +60 -0
- package/dist/MarkdownEditor/editor/elements/Table/utils/useEditableTableColWidths.d.ts +6 -0
- package/dist/MarkdownEditor/editor/elements/Table/utils/useEditableTableColWidths.js +20 -0
- package/dist/MarkdownEditor/editor/elements/Table/utils/useEditableTableContentWidth.d.ts +10 -0
- package/dist/MarkdownEditor/editor/elements/Table/utils/useEditableTableContentWidth.js +103 -0
- package/dist/MarkdownEditor/editor/elements/index.js +7 -0
- package/dist/MarkdownEditor/editor/parser/parse/parseCode.js +33 -2
- package/dist/MarkdownEditor/editor/parser/parserSlateNodeToMarkdown.js +3 -0
- package/dist/MarkdownEditor/editor/plugins/handlePaste.js +4 -1
- package/dist/MarkdownEditor/style.js +109 -7
- package/dist/MarkdownEditor/types.d.ts +5 -0
- package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/AttachmentFileIcon.js +2 -2
- package/dist/MarkdownInputField/AttachmentButton/AttachmentFileList/AttachmentFileListItem.js +11 -8
- package/dist/MarkdownInputField/AttachmentButton/index.js +7 -2
- package/dist/MarkdownInputField/AttachmentButton/types.d.ts +5 -1
- package/dist/MarkdownInputField/AttachmentButton/utils.d.ts +7 -0
- package/dist/MarkdownInputField/AttachmentButton/utils.js +9 -1
- package/dist/MarkdownInputField/FileMapView/FileMapViewItem.js +10 -5
- package/dist/MarkdownInputField/FileUploadManager/index.d.ts +9 -0
- package/dist/MarkdownInputField/FileUploadManager/index.js +20 -4
- package/dist/MarkdownInputField/MarkdownInputField.js +5 -3
- package/dist/MarkdownInputField/SendActions/index.d.ts +9 -0
- package/dist/MarkdownInputField/SendActions/index.js +3 -2
- package/dist/MarkdownInputField/utils/renderHelpers.d.ts +8 -1
- package/dist/MarkdownInputField/utils/renderHelpers.js +5 -1
- package/dist/MarkdownRenderer/AnimationText.d.ts +4 -7
- package/dist/MarkdownRenderer/AnimationText.js +117 -15
- package/dist/MarkdownRenderer/MarkdownRenderer.js +15 -1
- package/dist/MarkdownRenderer/index.d.ts +2 -2
- package/dist/MarkdownRenderer/index.js +1 -1
- package/dist/MarkdownRenderer/renderers/AgenticUiTaskBlockRenderer.d.ts +6 -0
- package/dist/MarkdownRenderer/renderers/AgenticUiTaskBlockRenderer.js +66 -0
- package/dist/MarkdownRenderer/renderers/AgenticUiToolUseBarBlockRenderer.d.ts +6 -0
- package/dist/MarkdownRenderer/renderers/AgenticUiToolUseBarBlockRenderer.js +134 -0
- package/dist/MarkdownRenderer/style.js +7 -6
- package/dist/MarkdownRenderer/useMarkdownToReact.js +5 -4
- package/dist/MarkdownRenderer/useStreaming.js +8 -1
- package/dist/Plugins/chart/ChartRender.js +1 -0
- package/dist/Plugins/chart/index.js +3 -1
- package/package.json +2 -1
|
@@ -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, InsertRowLeftOutlined, InsertRowRightOutlined } 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 {
|
|
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 {
|
|
37
|
+
import { clearTableSelection, insertTableColumn, removeTableColumn, selectTableColumn, selectWholeTable } from "../commands/tableCommands";
|
|
97
38
|
import { TablePropsContext } from "../TableContext";
|
|
98
39
|
/**
|
|
99
40
|
* TableCellIndexSpacer 组件 - 表格索引间隔单元格组件
|
|
@@ -137,37 +78,15 @@ import { TablePropsContext } from "../TableContext";
|
|
|
137
78
|
var editor = useSlate();
|
|
138
79
|
var tableContext = useContext(TablePropsContext);
|
|
139
80
|
var deleteIconPosition = tableContext.deleteIconPosition, setDeleteIconPosition = tableContext.setDeleteIconPosition;
|
|
81
|
+
var isSelectWholeTable = columnIndex === -1;
|
|
82
|
+
var actionColumnIndex = isSelectWholeTable ? 0 : columnIndex;
|
|
140
83
|
var clearSelect = useRefFunction(function() {
|
|
141
84
|
var clearIcon = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
|
|
142
|
-
var _tableElement_children;
|
|
143
85
|
if (clearIcon) {
|
|
144
86
|
setDeleteIconPosition === null || setDeleteIconPosition === void 0 ? void 0 : setDeleteIconPosition(null);
|
|
145
87
|
}
|
|
146
88
|
if (!tablePath) return;
|
|
147
|
-
|
|
148
|
-
if (!tableElement || tableElement.type !== 'table') return;
|
|
149
|
-
var rowCount = ((_tableElement_children = tableElement.children) === null || _tableElement_children === void 0 ? void 0 : _tableElement_children.length) || 0;
|
|
150
|
-
if (rowCount === 0) return;
|
|
151
|
-
for(var rowIndex = 0; rowIndex < rowCount; rowIndex++){
|
|
152
|
-
var rowElement = tableElement.children[rowIndex];
|
|
153
|
-
if (rowElement && rowElement.children) {
|
|
154
|
-
for(var colIndex = 0; colIndex < rowElement.children.length; colIndex++){
|
|
155
|
-
var cellPath = _to_consumable_array(tablePath).concat([
|
|
156
|
-
rowIndex,
|
|
157
|
-
colIndex
|
|
158
|
-
]);
|
|
159
|
-
if (Editor.hasPath(editor, cellPath)) {
|
|
160
|
-
var _Editor_node = _sliced_to_array(Editor.node(editor, cellPath), 1), cellNode = _Editor_node[0];
|
|
161
|
-
if (cellNode && cellNode.type === 'table-cell') {
|
|
162
|
-
var domNode = ReactEditor.toDOMNode(editor, cellNode);
|
|
163
|
-
if (domNode) {
|
|
164
|
-
domNode.removeAttribute('data-select');
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
89
|
+
clearTableSelection(editor, tablePath);
|
|
171
90
|
});
|
|
172
91
|
/**
|
|
173
92
|
* 处理点击事件,选中整列或显示删除图标
|
|
@@ -175,68 +94,21 @@ import { TablePropsContext } from "../TableContext";
|
|
|
175
94
|
e.preventDefault();
|
|
176
95
|
e.stopPropagation();
|
|
177
96
|
// 如果提供了列索引,显示删除图标
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
97
|
+
if (columnIndex !== undefined) {
|
|
98
|
+
setDeleteIconPosition === null || setDeleteIconPosition === void 0 ? void 0 : setDeleteIconPosition({
|
|
99
|
+
columnIndex: columnIndex
|
|
100
|
+
});
|
|
101
|
+
}
|
|
181
102
|
if (columnIndex === undefined || !tablePath) {
|
|
182
103
|
return;
|
|
183
104
|
}
|
|
184
105
|
try {
|
|
185
|
-
var _tableElement_children;
|
|
186
|
-
// 获取表格元素
|
|
187
|
-
var tableElement = Editor.node(editor, tablePath)[0];
|
|
188
|
-
if (!tableElement || tableElement.type !== 'table') {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
// 获取表格的行数
|
|
192
|
-
var rowCount = ((_tableElement_children = tableElement.children) === null || _tableElement_children === void 0 ? void 0 : _tableElement_children.length) || 0;
|
|
193
|
-
if (rowCount === 0) {
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
// 根据 columnIndex 的值决定选中逻辑
|
|
197
|
-
if (columnIndex === -1) {
|
|
198
|
-
// 选中所有单元格 - 只使用 DOM 操作
|
|
199
|
-
for(var rowIndex = 0; rowIndex < rowCount; rowIndex++){
|
|
200
|
-
var rowElement = tableElement.children[rowIndex];
|
|
201
|
-
if (rowElement && rowElement.children) {
|
|
202
|
-
for(var colIndex = 0; colIndex < rowElement.children.length; colIndex++){
|
|
203
|
-
var cellPath = _to_consumable_array(tablePath).concat([
|
|
204
|
-
rowIndex,
|
|
205
|
-
colIndex
|
|
206
|
-
]);
|
|
207
|
-
if (Editor.hasPath(editor, cellPath)) {
|
|
208
|
-
var _Editor_node = _sliced_to_array(Editor.node(editor, cellPath), 1), cellNode = _Editor_node[0];
|
|
209
|
-
if (cellNode && cellNode.type === 'table-cell') {
|
|
210
|
-
// 只使用 DOM 操作设置 data-select 属性
|
|
211
|
-
var domNode = ReactEditor.toDOMNode(editor, cellNode);
|
|
212
|
-
if (domNode) {
|
|
213
|
-
domNode.setAttribute('data-select', 'true');
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
106
|
clearSelect(false);
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
rowIndex1,
|
|
227
|
-
columnIndex
|
|
228
|
-
]);
|
|
229
|
-
if (Editor.hasPath(editor, cellPath1)) {
|
|
230
|
-
var _Editor_node1 = _sliced_to_array(Editor.node(editor, cellPath1), 1), cellNode1 = _Editor_node1[0];
|
|
231
|
-
if (cellNode1 && cellNode1.type === 'table-cell') {
|
|
232
|
-
// 只使用 DOM 操作设置 data-select 属性
|
|
233
|
-
var domNode1 = ReactEditor.toDOMNode(editor, cellNode1);
|
|
234
|
-
if (domNode1) {
|
|
235
|
-
domNode1.setAttribute('data-select', 'true');
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
107
|
+
if (isSelectWholeTable) {
|
|
108
|
+
selectWholeTable(editor, tablePath);
|
|
109
|
+
return;
|
|
239
110
|
}
|
|
111
|
+
selectTableColumn(editor, tablePath, columnIndex);
|
|
240
112
|
} catch (error) {
|
|
241
113
|
console.warn('Failed to select table column:', error);
|
|
242
114
|
}
|
|
@@ -247,35 +119,10 @@ import { TablePropsContext } from "../TableContext";
|
|
|
247
119
|
e.preventDefault();
|
|
248
120
|
e.stopPropagation();
|
|
249
121
|
try {
|
|
250
|
-
if (!tablePath ||
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
// 获取表格元素
|
|
254
|
-
var tableElement = Editor.node(editor, tablePath)[0];
|
|
255
|
-
if (!tableElement || tableElement.type !== 'table') {
|
|
122
|
+
if (!tablePath || actionColumnIndex === undefined) {
|
|
256
123
|
return;
|
|
257
124
|
}
|
|
258
|
-
|
|
259
|
-
var firstRow = tableElement.children[0];
|
|
260
|
-
var colCount = firstRow.children.length;
|
|
261
|
-
// 检查是否只有一列
|
|
262
|
-
if (colCount <= 1) {
|
|
263
|
-
// 如果只有一列,删除整个表格
|
|
264
|
-
NativeTableEditor.removeTable(editor, tablePath);
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
// 删除每一行的指定列
|
|
268
|
-
for(var rowIndex = 0; rowIndex < rowCount; rowIndex++){
|
|
269
|
-
var cellPath = _to_consumable_array(tablePath).concat([
|
|
270
|
-
rowIndex,
|
|
271
|
-
columnIndex
|
|
272
|
-
]);
|
|
273
|
-
if (Editor.hasPath(editor, cellPath)) {
|
|
274
|
-
Transforms.removeNodes(editor, {
|
|
275
|
-
at: cellPath
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
}
|
|
125
|
+
removeTableColumn(editor, tablePath, actionColumnIndex);
|
|
279
126
|
clearSelect();
|
|
280
127
|
} catch (error) {
|
|
281
128
|
console.warn('Failed to delete table column:', error);
|
|
@@ -287,38 +134,10 @@ import { TablePropsContext } from "../TableContext";
|
|
|
287
134
|
e.preventDefault();
|
|
288
135
|
e.stopPropagation();
|
|
289
136
|
try {
|
|
290
|
-
if (!tablePath ||
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
// 获取表格元素
|
|
294
|
-
var tableElement = Editor.node(editor, tablePath)[0];
|
|
295
|
-
if (!tableElement || tableElement.type !== 'table') {
|
|
137
|
+
if (!tablePath || actionColumnIndex === undefined) {
|
|
296
138
|
return;
|
|
297
139
|
}
|
|
298
|
-
|
|
299
|
-
// 为每一行在当前列之前插入新单元格
|
|
300
|
-
for(var rowIndex = 0; rowIndex < rowCount; rowIndex++){
|
|
301
|
-
var cellPath = _to_consumable_array(tablePath).concat([
|
|
302
|
-
rowIndex,
|
|
303
|
-
columnIndex
|
|
304
|
-
]);
|
|
305
|
-
var newCell = {
|
|
306
|
-
type: 'table-cell',
|
|
307
|
-
children: [
|
|
308
|
-
{
|
|
309
|
-
type: 'paragraph',
|
|
310
|
-
children: [
|
|
311
|
-
{
|
|
312
|
-
text: ''
|
|
313
|
-
}
|
|
314
|
-
]
|
|
315
|
-
}
|
|
316
|
-
]
|
|
317
|
-
};
|
|
318
|
-
Transforms.insertNodes(editor, newCell, {
|
|
319
|
-
at: cellPath
|
|
320
|
-
});
|
|
321
|
-
}
|
|
140
|
+
insertTableColumn(editor, tablePath, actionColumnIndex, 'before');
|
|
322
141
|
clearSelect();
|
|
323
142
|
} catch (error) {
|
|
324
143
|
console.warn('Failed to insert column before:', error);
|
|
@@ -330,38 +149,10 @@ import { TablePropsContext } from "../TableContext";
|
|
|
330
149
|
e.preventDefault();
|
|
331
150
|
e.stopPropagation();
|
|
332
151
|
try {
|
|
333
|
-
if (!tablePath ||
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
// 获取表格元素
|
|
337
|
-
var tableElement = Editor.node(editor, tablePath)[0];
|
|
338
|
-
if (!tableElement || tableElement.type !== 'table') {
|
|
152
|
+
if (!tablePath || actionColumnIndex === undefined) {
|
|
339
153
|
return;
|
|
340
154
|
}
|
|
341
|
-
|
|
342
|
-
// 为每一行在当前列之后插入新单元格
|
|
343
|
-
for(var rowIndex = 0; rowIndex < rowCount; rowIndex++){
|
|
344
|
-
var cellPath = _to_consumable_array(tablePath).concat([
|
|
345
|
-
rowIndex,
|
|
346
|
-
columnIndex + 1
|
|
347
|
-
]);
|
|
348
|
-
var newCell = {
|
|
349
|
-
type: 'table-cell',
|
|
350
|
-
children: [
|
|
351
|
-
{
|
|
352
|
-
type: 'paragraph',
|
|
353
|
-
children: [
|
|
354
|
-
{
|
|
355
|
-
text: ''
|
|
356
|
-
}
|
|
357
|
-
]
|
|
358
|
-
}
|
|
359
|
-
]
|
|
360
|
-
};
|
|
361
|
-
Transforms.insertNodes(editor, newCell, {
|
|
362
|
-
at: cellPath
|
|
363
|
-
});
|
|
364
|
-
}
|
|
155
|
+
insertTableColumn(editor, tablePath, actionColumnIndex, 'after');
|
|
365
156
|
clearSelect();
|
|
366
157
|
} catch (error) {
|
|
367
158
|
console.warn('Failed to insert column after:', error);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Editor } from 'slate';
|
|
2
|
+
export declare function clearTableSelection(editor: Editor, tablePath: number[]): void;
|
|
3
|
+
export declare function selectTableRow(editor: Editor, tablePath: number[], rowIndex: number): void;
|
|
4
|
+
export declare function selectTableColumn(editor: Editor, tablePath: number[], columnIndex: number): void;
|
|
5
|
+
export declare function selectWholeTable(editor: Editor, tablePath: number[]): void;
|
|
6
|
+
export declare function removeTableRow(editor: Editor, tablePath: number[], rowIndex: number): void;
|
|
7
|
+
export declare function insertTableRow(editor: Editor, tablePath: number[], rowIndex: number, position: 'before' | 'after'): void;
|
|
8
|
+
export declare function removeTableColumn(editor: Editor, tablePath: number[], columnIndex: number): void;
|
|
9
|
+
export declare function insertTableColumn(editor: Editor, tablePath: number[], columnIndex: number, position: 'before' | 'after'): void;
|
|
@@ -0,0 +1,242 @@
|
|
|
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 _iterable_to_array(iter) {
|
|
13
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
14
|
+
}
|
|
15
|
+
function _iterable_to_array_limit(arr, i) {
|
|
16
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
17
|
+
if (_i == null) return;
|
|
18
|
+
var _arr = [];
|
|
19
|
+
var _n = true;
|
|
20
|
+
var _d = false;
|
|
21
|
+
var _s, _e;
|
|
22
|
+
try {
|
|
23
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
24
|
+
_arr.push(_s.value);
|
|
25
|
+
if (i && _arr.length === i) break;
|
|
26
|
+
}
|
|
27
|
+
} catch (err) {
|
|
28
|
+
_d = true;
|
|
29
|
+
_e = err;
|
|
30
|
+
} finally{
|
|
31
|
+
try {
|
|
32
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
33
|
+
} finally{
|
|
34
|
+
if (_d) throw _e;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return _arr;
|
|
38
|
+
}
|
|
39
|
+
function _non_iterable_rest() {
|
|
40
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
41
|
+
}
|
|
42
|
+
function _non_iterable_spread() {
|
|
43
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
44
|
+
}
|
|
45
|
+
function _sliced_to_array(arr, i) {
|
|
46
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
47
|
+
}
|
|
48
|
+
function _to_consumable_array(arr) {
|
|
49
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
50
|
+
}
|
|
51
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
52
|
+
if (!o) return;
|
|
53
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
54
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
55
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
56
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
57
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
58
|
+
}
|
|
59
|
+
import { Editor, Transforms } from "slate";
|
|
60
|
+
import { ReactEditor } from "slate-react";
|
|
61
|
+
import { NativeTableEditor } from "../../../../utils/native-table";
|
|
62
|
+
var EMPTY_TABLE_CELL = {
|
|
63
|
+
type: 'table-cell',
|
|
64
|
+
children: [
|
|
65
|
+
{
|
|
66
|
+
type: 'paragraph',
|
|
67
|
+
children: [
|
|
68
|
+
{
|
|
69
|
+
text: ''
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
};
|
|
75
|
+
function getTableNode(editor, tablePath) {
|
|
76
|
+
var _Editor_node = _sliced_to_array(Editor.node(editor, tablePath), 1), tableNode = _Editor_node[0];
|
|
77
|
+
if (!tableNode || tableNode.type !== 'table') {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
return tableNode;
|
|
81
|
+
}
|
|
82
|
+
function getTableRowCount(tableNode) {
|
|
83
|
+
var _tableNode_children;
|
|
84
|
+
return ((_tableNode_children = tableNode.children) === null || _tableNode_children === void 0 ? void 0 : _tableNode_children.length) || 0;
|
|
85
|
+
}
|
|
86
|
+
function getTableColumnCount(tableNode) {
|
|
87
|
+
var _tableNode_children__children, _tableNode_children_, _tableNode_children;
|
|
88
|
+
return ((_tableNode_children = tableNode.children) === null || _tableNode_children === void 0 ? void 0 : (_tableNode_children_ = _tableNode_children[0]) === null || _tableNode_children_ === void 0 ? void 0 : (_tableNode_children__children = _tableNode_children_.children) === null || _tableNode_children__children === void 0 ? void 0 : _tableNode_children__children.length) || 0;
|
|
89
|
+
}
|
|
90
|
+
function forEachCellPath(editor, tablePath, callback) {
|
|
91
|
+
var tableNode = getTableNode(editor, tablePath);
|
|
92
|
+
if (!tableNode) return;
|
|
93
|
+
var rowCount = getTableRowCount(tableNode);
|
|
94
|
+
for(var rowIndex = 0; rowIndex < rowCount; rowIndex += 1){
|
|
95
|
+
var _tableNode_children, _rowNode_children;
|
|
96
|
+
var rowNode = (_tableNode_children = tableNode.children) === null || _tableNode_children === void 0 ? void 0 : _tableNode_children[rowIndex];
|
|
97
|
+
var columnCount = (rowNode === null || rowNode === void 0 ? void 0 : (_rowNode_children = rowNode.children) === null || _rowNode_children === void 0 ? void 0 : _rowNode_children.length) || 0;
|
|
98
|
+
for(var columnIndex = 0; columnIndex < columnCount; columnIndex += 1){
|
|
99
|
+
var cellPath = _to_consumable_array(tablePath).concat([
|
|
100
|
+
rowIndex,
|
|
101
|
+
columnIndex
|
|
102
|
+
]);
|
|
103
|
+
if (!Editor.hasPath(editor, cellPath)) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
var _Editor_node = _sliced_to_array(Editor.node(editor, cellPath), 1), cellNode = _Editor_node[0];
|
|
107
|
+
var tableCellNode = cellNode;
|
|
108
|
+
if (tableCellNode.type !== 'table-cell') {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
callback(cellPath, tableCellNode);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
export function clearTableSelection(editor, tablePath) {
|
|
116
|
+
forEachCellPath(editor, tablePath, function(_, cellNode) {
|
|
117
|
+
var domNode = ReactEditor.toDOMNode(editor, cellNode);
|
|
118
|
+
domNode === null || domNode === void 0 ? void 0 : domNode.removeAttribute('data-select');
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
export function selectTableRow(editor, tablePath, rowIndex) {
|
|
122
|
+
var _tableNode_children, _rowNode_children;
|
|
123
|
+
var tableNode = getTableNode(editor, tablePath);
|
|
124
|
+
if (!tableNode) return;
|
|
125
|
+
var rowNode = (_tableNode_children = tableNode.children) === null || _tableNode_children === void 0 ? void 0 : _tableNode_children[rowIndex];
|
|
126
|
+
if (!(rowNode === null || rowNode === void 0 ? void 0 : (_rowNode_children = rowNode.children) === null || _rowNode_children === void 0 ? void 0 : _rowNode_children.length)) return;
|
|
127
|
+
for(var columnIndex = 0; columnIndex < rowNode.children.length; columnIndex += 1){
|
|
128
|
+
var cellPath = _to_consumable_array(tablePath).concat([
|
|
129
|
+
rowIndex,
|
|
130
|
+
columnIndex
|
|
131
|
+
]);
|
|
132
|
+
if (!Editor.hasPath(editor, cellPath)) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
var _Editor_node = _sliced_to_array(Editor.node(editor, cellPath), 1), cellNode = _Editor_node[0];
|
|
136
|
+
var tableCellNode = cellNode;
|
|
137
|
+
if (tableCellNode.type !== 'table-cell') {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
var domNode = ReactEditor.toDOMNode(editor, tableCellNode);
|
|
141
|
+
domNode === null || domNode === void 0 ? void 0 : domNode.setAttribute('data-select', 'true');
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
export function selectTableColumn(editor, tablePath, columnIndex) {
|
|
145
|
+
var tableNode = getTableNode(editor, tablePath);
|
|
146
|
+
if (!tableNode) return;
|
|
147
|
+
var rowCount = getTableRowCount(tableNode);
|
|
148
|
+
for(var rowIndex = 0; rowIndex < rowCount; rowIndex += 1){
|
|
149
|
+
var cellPath = _to_consumable_array(tablePath).concat([
|
|
150
|
+
rowIndex,
|
|
151
|
+
columnIndex
|
|
152
|
+
]);
|
|
153
|
+
if (!Editor.hasPath(editor, cellPath)) {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
var _Editor_node = _sliced_to_array(Editor.node(editor, cellPath), 1), cellNode = _Editor_node[0];
|
|
157
|
+
var tableCellNode = cellNode;
|
|
158
|
+
if (tableCellNode.type !== 'table-cell') {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
var domNode = ReactEditor.toDOMNode(editor, tableCellNode);
|
|
162
|
+
domNode === null || domNode === void 0 ? void 0 : domNode.setAttribute('data-select', 'true');
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
export function selectWholeTable(editor, tablePath) {
|
|
166
|
+
forEachCellPath(editor, tablePath, function(_, cellNode) {
|
|
167
|
+
var domNode = ReactEditor.toDOMNode(editor, cellNode);
|
|
168
|
+
domNode === null || domNode === void 0 ? void 0 : domNode.setAttribute('data-select', 'true');
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
export function removeTableRow(editor, tablePath, rowIndex) {
|
|
172
|
+
var tableNode = getTableNode(editor, tablePath);
|
|
173
|
+
if (!tableNode) return;
|
|
174
|
+
if (getTableRowCount(tableNode) <= 1) {
|
|
175
|
+
NativeTableEditor.removeTable(editor, tablePath);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
var rowPath = _to_consumable_array(tablePath).concat([
|
|
179
|
+
rowIndex
|
|
180
|
+
]);
|
|
181
|
+
if (Editor.hasPath(editor, rowPath)) {
|
|
182
|
+
Transforms.removeNodes(editor, {
|
|
183
|
+
at: rowPath
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
export function insertTableRow(editor, tablePath, rowIndex, position) {
|
|
188
|
+
var tableNode = getTableNode(editor, tablePath);
|
|
189
|
+
if (!tableNode) return;
|
|
190
|
+
var rowCount = getTableRowCount(tableNode);
|
|
191
|
+
var columnCount = getTableColumnCount(tableNode);
|
|
192
|
+
if (columnCount <= 0) return;
|
|
193
|
+
var rowNode = {
|
|
194
|
+
type: 'table-row',
|
|
195
|
+
children: Array.from({
|
|
196
|
+
length: columnCount
|
|
197
|
+
}, function() {
|
|
198
|
+
return EMPTY_TABLE_CELL;
|
|
199
|
+
})
|
|
200
|
+
};
|
|
201
|
+
var insertIndex = position === 'before' ? rowIndex : Math.min(rowIndex + 1, rowCount);
|
|
202
|
+
Transforms.insertNodes(editor, rowNode, {
|
|
203
|
+
at: _to_consumable_array(tablePath).concat([
|
|
204
|
+
insertIndex
|
|
205
|
+
])
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
export function removeTableColumn(editor, tablePath, columnIndex) {
|
|
209
|
+
var tableNode = getTableNode(editor, tablePath);
|
|
210
|
+
if (!tableNode) return;
|
|
211
|
+
if (getTableColumnCount(tableNode) <= 1) {
|
|
212
|
+
NativeTableEditor.removeTable(editor, tablePath);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
var rowCount = getTableRowCount(tableNode);
|
|
216
|
+
for(var rowIndex = 0; rowIndex < rowCount; rowIndex += 1){
|
|
217
|
+
var cellPath = _to_consumable_array(tablePath).concat([
|
|
218
|
+
rowIndex,
|
|
219
|
+
columnIndex
|
|
220
|
+
]);
|
|
221
|
+
if (Editor.hasPath(editor, cellPath)) {
|
|
222
|
+
Transforms.removeNodes(editor, {
|
|
223
|
+
at: cellPath
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
export function insertTableColumn(editor, tablePath, columnIndex, position) {
|
|
229
|
+
var tableNode = getTableNode(editor, tablePath);
|
|
230
|
+
if (!tableNode) return;
|
|
231
|
+
var rowCount = getTableRowCount(tableNode);
|
|
232
|
+
var insertOffset = position === 'before' ? 0 : 1;
|
|
233
|
+
for(var rowIndex = 0; rowIndex < rowCount; rowIndex += 1){
|
|
234
|
+
var insertPath = _to_consumable_array(tablePath).concat([
|
|
235
|
+
rowIndex,
|
|
236
|
+
columnIndex + insertOffset
|
|
237
|
+
]);
|
|
238
|
+
Transforms.insertNodes(editor, EMPTY_TABLE_CELL, {
|
|
239
|
+
at: insertPath
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { TableNode } from '../../../types/Table';
|
|
2
|
+
export interface GetEditableTableColWidthsParams {
|
|
3
|
+
readonly: boolean;
|
|
4
|
+
columnCount: number;
|
|
5
|
+
availableTableWidth: number;
|
|
6
|
+
mobileBreakpointValue: number;
|
|
7
|
+
element?: TableNode;
|
|
8
|
+
}
|
|
9
|
+
/** 统一编辑态列宽策略:显式列宽优先,其他场景复用只读算法并归一化为像素值 */
|
|
10
|
+
export declare const getEditableTableColWidths: ({ readonly, columnCount, availableTableWidth, mobileBreakpointValue, element, }: GetEditableTableColWidthsParams) => number[];
|
|
11
|
+
export interface GetEditableTableMinWidthParams {
|
|
12
|
+
columnCount: number;
|
|
13
|
+
colWidths: number[];
|
|
14
|
+
availableTableWidth: number;
|
|
15
|
+
mobileBreakpointValue: number;
|
|
16
|
+
resolvedContentWidth: number;
|
|
17
|
+
minContainerWidth: number;
|
|
18
|
+
rowIndexColWidth: number;
|
|
19
|
+
}
|
|
20
|
+
export declare const getEditableTableMinWidth: ({ columnCount, colWidths, availableTableWidth, mobileBreakpointValue, resolvedContentWidth, minContainerWidth, rowIndexColWidth, }: GetEditableTableMinWidthParams) => number;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { MOBILE_TABLE_MIN_COLUMN_WIDTH, TABLE_EDIT_COL_WIDTH_MIN_COLUMNS } from "../../../../../Constants/mobile";
|
|
2
|
+
import { getReadonlyTableColWidths } from "./getTableColWidths";
|
|
3
|
+
var TABLE_EDIT_DESKTOP_MIN_COLUMN_WIDTH = 60;
|
|
4
|
+
var clamp = function clamp(value, min, max) {
|
|
5
|
+
return Math.min(Math.max(value, min), max);
|
|
6
|
+
};
|
|
7
|
+
var toPixelWidth = function toPixelWidth(width, containerWidth, fallbackWidth) {
|
|
8
|
+
if (typeof width === 'number') return width;
|
|
9
|
+
if (!width) return fallbackWidth;
|
|
10
|
+
if (width.endsWith('%')) {
|
|
11
|
+
var ratio = Number.parseFloat(width);
|
|
12
|
+
if (Number.isFinite(ratio)) return containerWidth * ratio / 100;
|
|
13
|
+
}
|
|
14
|
+
var parsed = Number.parseFloat(width);
|
|
15
|
+
return Number.isFinite(parsed) ? parsed : fallbackWidth;
|
|
16
|
+
};
|
|
17
|
+
/** 统一编辑态列宽策略:显式列宽优先,其他场景复用只读算法并归一化为像素值 */ export var getEditableTableColWidths = function getEditableTableColWidths(param) {
|
|
18
|
+
var readonly = param.readonly, columnCount = param.columnCount, availableTableWidth = param.availableTableWidth, mobileBreakpointValue = param.mobileBreakpointValue, element = param.element;
|
|
19
|
+
var _element_children, _element_otherProps;
|
|
20
|
+
if (readonly) return [];
|
|
21
|
+
if (!(element === null || element === void 0 ? void 0 : (_element_children = element.children) === null || _element_children === void 0 ? void 0 : _element_children.length)) return [];
|
|
22
|
+
if (columnCount < TABLE_EDIT_COL_WIDTH_MIN_COLUMNS) return [];
|
|
23
|
+
var explicitColWidths = (_element_otherProps = element.otherProps) === null || _element_otherProps === void 0 ? void 0 : _element_otherProps.colWidths;
|
|
24
|
+
if (explicitColWidths === null || explicitColWidths === void 0 ? void 0 : explicitColWidths.length) {
|
|
25
|
+
return explicitColWidths.slice(0, columnCount).map(function(width) {
|
|
26
|
+
return Math.max(1, Math.round(toPixelWidth(width, availableTableWidth, TABLE_EDIT_DESKTOP_MIN_COLUMN_WIDTH)));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
var isMobileLayout = availableTableWidth <= mobileBreakpointValue;
|
|
30
|
+
var minColumnWidth = isMobileLayout ? MOBILE_TABLE_MIN_COLUMN_WIDTH : TABLE_EDIT_DESKTOP_MIN_COLUMN_WIDTH;
|
|
31
|
+
var maxColumnWidth = isMobileLayout ? availableTableWidth : Math.max(TABLE_EDIT_DESKTOP_MIN_COLUMN_WIDTH, availableTableWidth / 4);
|
|
32
|
+
var fallbackWidth = Math.max(minColumnWidth, Math.floor(availableTableWidth / Math.max(columnCount, 1)));
|
|
33
|
+
var sourceColWidths = getReadonlyTableColWidths({
|
|
34
|
+
columnCount: columnCount,
|
|
35
|
+
element: element,
|
|
36
|
+
containerWidth: availableTableWidth
|
|
37
|
+
});
|
|
38
|
+
var normalizedWidths = Array.from({
|
|
39
|
+
length: columnCount
|
|
40
|
+
}, function(_, index) {
|
|
41
|
+
return clamp(toPixelWidth(sourceColWidths[index], availableTableWidth, fallbackWidth), minColumnWidth, maxColumnWidth);
|
|
42
|
+
});
|
|
43
|
+
var totalWidth = normalizedWidths.reduce(function(sum, width) {
|
|
44
|
+
return sum + width;
|
|
45
|
+
}, 0);
|
|
46
|
+
if (totalWidth > availableTableWidth) {
|
|
47
|
+
return Array(columnCount).fill(fallbackWidth);
|
|
48
|
+
}
|
|
49
|
+
return normalizedWidths;
|
|
50
|
+
};
|
|
51
|
+
export var getEditableTableMinWidth = function getEditableTableMinWidth(param) {
|
|
52
|
+
var columnCount = param.columnCount, colWidths = param.colWidths, availableTableWidth = param.availableTableWidth, mobileBreakpointValue = param.mobileBreakpointValue, resolvedContentWidth = param.resolvedContentWidth, minContainerWidth = param.minContainerWidth, rowIndexColWidth = param.rowIndexColWidth;
|
|
53
|
+
var isMobileLayout = availableTableWidth <= mobileBreakpointValue;
|
|
54
|
+
var minColumnWidth = isMobileLayout ? MOBILE_TABLE_MIN_COLUMN_WIDTH : TABLE_EDIT_DESKTOP_MIN_COLUMN_WIDTH;
|
|
55
|
+
var colWidthsTotal = colWidths.reduce(function(total, width) {
|
|
56
|
+
return total + width;
|
|
57
|
+
}, 0);
|
|
58
|
+
var fallbackMinWidth = Number((Math.max(resolvedContentWidth, minContainerWidth) * 0.95).toFixed(0));
|
|
59
|
+
return Math.max(columnCount * minColumnWidth, colWidthsTotal + rowIndexColWidth, fallbackMinWidth, minContainerWidth);
|
|
60
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TableNode } from '../../../types/Table';
|
|
2
|
+
import { type GetEditableTableColWidthsParams } from './editableTableWidth';
|
|
3
|
+
export interface UseEditableTableColWidthsParams extends Omit<GetEditableTableColWidthsParams, 'element'> {
|
|
4
|
+
element?: TableNode;
|
|
5
|
+
}
|
|
6
|
+
export declare function useEditableTableColWidths({ readonly, columnCount, availableTableWidth, mobileBreakpointValue, element, }: UseEditableTableColWidthsParams): number[];
|