@ant-design/agentic-ui 2.29.43 → 2.29.46
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/AgentRunBar/index.js +27 -19
- package/dist/Hooks/useLanguage.d.ts +1 -0
- package/dist/I18n/locales.d.ts +1 -0
- package/dist/I18n/locales.js +2 -0
- package/dist/MarkdownEditor/editor/elements/Table/Table.js +2 -1
- package/dist/MarkdownEditor/editor/elements/index.js +21 -0
- package/dist/MarkdownEditor/editor/plugins/hotKeyCommands/enter.js +15 -0
- package/dist/MarkdownEditor/editor/plugins/useHighlight.js +173 -14
- package/dist/MarkdownEditor/editor/plugins/useKeyboard.js +3 -1
- package/dist/MarkdownEditor/editor/style.js +343 -363
- package/dist/MarkdownEditor/editor/tools/JinjaTemplatePanel/index.js +45 -17
- package/dist/MarkdownEditor/editor/tools/JinjaTemplatePanel/style.js +23 -1
- package/dist/MarkdownEditor/el.d.ts +7 -0
- package/dist/Plugins/chart/components/ChartContainer/ChartErrorBoundary.d.ts +2 -0
- package/dist/TaskList/TaskList.d.ts +3 -0
- package/dist/TaskList/TaskList.js +210 -0
- package/dist/TaskList/components/StatusIcon.d.ts +9 -0
- package/dist/TaskList/components/StatusIcon.js +23 -0
- package/dist/TaskList/components/TaskListItem.d.ts +12 -0
- package/dist/TaskList/components/TaskListItem.js +68 -0
- package/dist/TaskList/constants.d.ts +24 -0
- package/dist/TaskList/constants.js +38 -0
- package/dist/TaskList/index.d.ts +2 -50
- package/dist/TaskList/index.js +1 -260
- package/dist/TaskList/style.js +66 -9
- package/dist/TaskList/types.d.ts +29 -0
- package/dist/TaskList/types.js +3 -0
- package/dist/ToolUseBar/style.js +6 -5
- package/package.json +1 -1
|
@@ -61,6 +61,7 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
61
61
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
62
62
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
63
63
|
}
|
|
64
|
+
import { CloseOutlined } from "@ant-design/icons";
|
|
64
65
|
import { Info } from "@sofa-design/icons";
|
|
65
66
|
import { ConfigProvider } from "antd";
|
|
66
67
|
import classNames from "clsx";
|
|
@@ -71,32 +72,37 @@ import { Editor, Transforms } from "slate";
|
|
|
71
72
|
import { ReactEditor } from "slate-react";
|
|
72
73
|
import { useLocale } from "../../../../I18n";
|
|
73
74
|
import { useEditorStore } from "../../store";
|
|
74
|
-
import { getOffsetLeft } from "../../utils/dom";
|
|
75
75
|
import { EditorUtils } from "../../utils/editorUtils";
|
|
76
76
|
import { JINJA_PANEL_PREFIX_CLS, useJinjaTemplatePanelStyle } from "./style";
|
|
77
77
|
import { getJinjaTemplateData, JINJA_DOC_LINK } from "./templates";
|
|
78
78
|
var PANEL_MAX_HEIGHT = 320;
|
|
79
|
+
var PANEL_MIN_WIDTH = 240;
|
|
79
80
|
function getPosition(nodeEl) {
|
|
80
81
|
var rect = nodeEl.getBoundingClientRect();
|
|
81
|
-
var
|
|
82
|
-
var top = rect.bottom + window.scrollY;
|
|
82
|
+
var viewportWidth = document.documentElement.clientWidth;
|
|
83
83
|
var viewportHeight = document.documentElement.clientHeight;
|
|
84
84
|
var spaceBelow = viewportHeight - rect.bottom;
|
|
85
|
-
|
|
85
|
+
var spaceAbove = rect.top;
|
|
86
|
+
var left = rect.left;
|
|
87
|
+
left = Math.max(0, Math.min(left, viewportWidth - PANEL_MIN_WIDTH));
|
|
88
|
+
if (spaceBelow < PANEL_MAX_HEIGHT && spaceAbove > PANEL_MAX_HEIGHT) {
|
|
86
89
|
return {
|
|
87
90
|
left: left,
|
|
88
|
-
bottom: viewportHeight - rect.top
|
|
91
|
+
bottom: Math.min(viewportHeight - rect.top, viewportHeight - PANEL_MAX_HEIGHT),
|
|
92
|
+
position: 'fixed'
|
|
89
93
|
};
|
|
90
94
|
}
|
|
95
|
+
var top = Math.min(rect.bottom, viewportHeight - PANEL_MAX_HEIGHT);
|
|
91
96
|
return {
|
|
92
97
|
left: left,
|
|
93
|
-
top: top
|
|
98
|
+
top: top,
|
|
99
|
+
position: 'fixed'
|
|
94
100
|
};
|
|
95
101
|
}
|
|
96
102
|
export var JinjaTemplatePanel = function JinjaTemplatePanel() {
|
|
97
103
|
var _ref, _ref1, _ref2, _ref3;
|
|
98
104
|
var _context_getPrefixCls;
|
|
99
|
-
var _useEditorStore = useEditorStore(), markdownEditorRef = _useEditorStore.markdownEditorRef,
|
|
105
|
+
var _useEditorStore = useEditorStore(), markdownEditorRef = _useEditorStore.markdownEditorRef, openJinjaTemplate = _useEditorStore.openJinjaTemplate, setOpenJinjaTemplate = _useEditorStore.setOpenJinjaTemplate, jinjaAnchorPath = _useEditorStore.jinjaAnchorPath, setJinjaAnchorPath = _useEditorStore.setJinjaAnchorPath, editorProps = _useEditorStore.editorProps;
|
|
100
106
|
var jinjaConfig = editorProps === null || editorProps === void 0 ? void 0 : editorProps.jinja;
|
|
101
107
|
var templatePanelConfig = (jinjaConfig === null || jinjaConfig === void 0 ? void 0 : jinjaConfig.templatePanel) && _type_of(jinjaConfig.templatePanel) === 'object' ? jinjaConfig.templatePanel : undefined;
|
|
102
108
|
var trigger = (_ref = templatePanelConfig === null || templatePanelConfig === void 0 ? void 0 : templatePanelConfig.trigger) !== null && _ref !== void 0 ? _ref : '{}';
|
|
@@ -113,9 +119,11 @@ export var JinjaTemplatePanel = function JinjaTemplatePanel() {
|
|
|
113
119
|
var _useState1 = _sliced_to_array(useState(false), 2), loading = _useState1[0], setLoading = _useState1[1];
|
|
114
120
|
var _useState2 = _sliced_to_array(useState(0), 2), activeIndex = _useState2[0], setActiveIndex = _useState2[1];
|
|
115
121
|
var _useState3 = _sliced_to_array(useState({
|
|
116
|
-
left: 0
|
|
122
|
+
left: 0,
|
|
123
|
+
position: 'fixed'
|
|
117
124
|
}), 2), position = _useState3[0], setPosition = _useState3[1];
|
|
118
125
|
var domRef = useRef(null);
|
|
126
|
+
var openTimeRef = useRef(0);
|
|
119
127
|
var context = React.useContext(ConfigProvider.ConfigContext);
|
|
120
128
|
var prefixCls = (_ref3 = context === null || context === void 0 ? void 0 : (_context_getPrefixCls = context.getPrefixCls) === null || _context_getPrefixCls === void 0 ? void 0 : _context_getPrefixCls.call(context, 'agentic-md-editor-jinja-panel')) !== null && _ref3 !== void 0 ? _ref3 : JINJA_PANEL_PREFIX_CLS;
|
|
121
129
|
var _useJinjaTemplatePanelStyle = useJinjaTemplatePanelStyle(prefixCls), wrapSSR = _useJinjaTemplatePanelStyle.wrapSSR, hashId = _useJinjaTemplatePanelStyle.hashId;
|
|
@@ -130,6 +138,10 @@ export var JinjaTemplatePanel = function JinjaTemplatePanel() {
|
|
|
130
138
|
var handleClickOutside = useCallback(function(e) {
|
|
131
139
|
var target = e.target;
|
|
132
140
|
if (domRef.current && !domRef.current.contains(target)) {
|
|
141
|
+
// 忽略弹窗打开后短时间内的点击,避免「点击聚焦编辑器后快速输入 {}」
|
|
142
|
+
// 触发的陈旧 click 事件立即关闭弹窗
|
|
143
|
+
var elapsed = Date.now() - openTimeRef.current;
|
|
144
|
+
if (elapsed < 150) return;
|
|
133
145
|
close();
|
|
134
146
|
}
|
|
135
147
|
}, [
|
|
@@ -177,7 +189,8 @@ export var JinjaTemplatePanel = function JinjaTemplatePanel() {
|
|
|
177
189
|
}
|
|
178
190
|
} catch (unused) {
|
|
179
191
|
setPosition({
|
|
180
|
-
left: 0
|
|
192
|
+
left: 0,
|
|
193
|
+
position: 'fixed'
|
|
181
194
|
});
|
|
182
195
|
}
|
|
183
196
|
}, [
|
|
@@ -188,6 +201,7 @@ export var JinjaTemplatePanel = function JinjaTemplatePanel() {
|
|
|
188
201
|
useEffect(function() {
|
|
189
202
|
if (!openJinjaTemplate) return;
|
|
190
203
|
if (typeof window === 'undefined') return;
|
|
204
|
+
openTimeRef.current = Date.now();
|
|
191
205
|
window.addEventListener('click', handleClickOutside);
|
|
192
206
|
return function() {
|
|
193
207
|
return window.removeEventListener('click', handleClickOutside);
|
|
@@ -261,14 +275,16 @@ export var JinjaTemplatePanel = function JinjaTemplatePanel() {
|
|
|
261
275
|
insertTemplate
|
|
262
276
|
]);
|
|
263
277
|
useEffect(function() {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
278
|
+
if (!openJinjaTemplate) return;
|
|
279
|
+
var handleKeydown = function handleKeydown(e) {
|
|
280
|
+
return keydown(e);
|
|
281
|
+
};
|
|
282
|
+
document.addEventListener('keydown', handleKeydown);
|
|
267
283
|
return function() {
|
|
268
|
-
return
|
|
284
|
+
return document.removeEventListener('keydown', handleKeydown);
|
|
269
285
|
};
|
|
270
286
|
}, [
|
|
271
|
-
|
|
287
|
+
openJinjaTemplate,
|
|
272
288
|
keydown
|
|
273
289
|
]);
|
|
274
290
|
useEffect(function() {
|
|
@@ -283,7 +299,7 @@ export var JinjaTemplatePanel = function JinjaTemplatePanel() {
|
|
|
283
299
|
"aria-label": "Jinja template list",
|
|
284
300
|
className: classNames(prefixCls, hashId),
|
|
285
301
|
style: {
|
|
286
|
-
position:
|
|
302
|
+
position: position.position,
|
|
287
303
|
zIndex: 9999,
|
|
288
304
|
left: position.left,
|
|
289
305
|
top: position.top,
|
|
@@ -298,13 +314,25 @@ export var JinjaTemplatePanel = function JinjaTemplatePanel() {
|
|
|
298
314
|
className: "".concat(prefixCls, "-header")
|
|
299
315
|
}, /*#__PURE__*/ React.createElement("div", {
|
|
300
316
|
className: "".concat(prefixCls, "-title")
|
|
301
|
-
}, locale['jinja.panel.title']),
|
|
317
|
+
}, locale['jinja.panel.title']), /*#__PURE__*/ React.createElement("div", {
|
|
318
|
+
className: "".concat(prefixCls, "-header-actions")
|
|
319
|
+
}, docLink ? /*#__PURE__*/ React.createElement("div", {
|
|
302
320
|
className: "".concat(prefixCls, "-doc-link"),
|
|
303
321
|
onClick: function onClick(e) {
|
|
304
322
|
e.preventDefault();
|
|
305
323
|
window.open(docLink, '_blank');
|
|
306
324
|
}
|
|
307
|
-
}, /*#__PURE__*/ React.createElement(Info, null), locale['jinja.panel.docLink']) : null
|
|
325
|
+
}, /*#__PURE__*/ React.createElement(Info, null), locale['jinja.panel.docLink']) : null, /*#__PURE__*/ React.createElement("button", {
|
|
326
|
+
type: "button",
|
|
327
|
+
className: "".concat(prefixCls, "-close"),
|
|
328
|
+
onClick: function onClick(e) {
|
|
329
|
+
e.preventDefault();
|
|
330
|
+
e.stopPropagation();
|
|
331
|
+
close();
|
|
332
|
+
},
|
|
333
|
+
"aria-label": locale['jinja.panel.close'],
|
|
334
|
+
title: locale['jinja.panel.close']
|
|
335
|
+
}, /*#__PURE__*/ React.createElement(CloseOutlined, null)))), /*#__PURE__*/ React.createElement("div", {
|
|
308
336
|
className: "".concat(prefixCls, "-list-box")
|
|
309
337
|
}, loading ? /*#__PURE__*/ React.createElement("div", {
|
|
310
338
|
style: {
|
|
@@ -76,7 +76,29 @@ var genJinjaPanelStyle = function genJinjaPanelStyle(token) {
|
|
|
76
76
|
padding: '6px 12px',
|
|
77
77
|
display: 'flex',
|
|
78
78
|
alignItems: 'center',
|
|
79
|
-
justifyContent: 'space-between'
|
|
79
|
+
justifyContent: 'space-between',
|
|
80
|
+
flexShrink: 0
|
|
81
|
+
},
|
|
82
|
+
'&-header-actions': {
|
|
83
|
+
display: 'flex',
|
|
84
|
+
alignItems: 'center',
|
|
85
|
+
gap: 8
|
|
86
|
+
},
|
|
87
|
+
'&-close': {
|
|
88
|
+
display: 'flex',
|
|
89
|
+
alignItems: 'center',
|
|
90
|
+
justifyContent: 'center',
|
|
91
|
+
padding: 4,
|
|
92
|
+
margin: -4,
|
|
93
|
+
border: 'none',
|
|
94
|
+
background: 'transparent',
|
|
95
|
+
cursor: 'pointer',
|
|
96
|
+
color: 'var(--color-gray-text-light, var(--ant-color-text-secondary))',
|
|
97
|
+
borderRadius: token.borderRadiusSM,
|
|
98
|
+
'&:hover': {
|
|
99
|
+
color: 'var(--color-gray-text-default, var(--ant-color-text))',
|
|
100
|
+
backgroundColor: token.colorFillTertiary
|
|
101
|
+
}
|
|
80
102
|
},
|
|
81
103
|
'&-title': {
|
|
82
104
|
font: 'var(--font-text-body-emphasized-sm)',
|
|
@@ -231,6 +231,13 @@ export type CustomLeaf<T = Record<string, any>> = {
|
|
|
231
231
|
jinjaVariable?: boolean;
|
|
232
232
|
jinjaTag?: boolean;
|
|
233
233
|
jinjaComment?: boolean;
|
|
234
|
+
jinjaKeyword?: boolean;
|
|
235
|
+
jinjaString?: boolean;
|
|
236
|
+
jinjaNumber?: boolean;
|
|
237
|
+
jinjaFilter?: boolean;
|
|
238
|
+
jinjaVariableName?: boolean;
|
|
239
|
+
jinjaPlaceholder?: boolean;
|
|
240
|
+
jinjaDelimiter?: boolean;
|
|
234
241
|
selection?: BaseRange;
|
|
235
242
|
id?: string;
|
|
236
243
|
data?: Record<string, any>;
|
|
@@ -415,6 +415,7 @@ declare class ChartErrorBoundary extends React.Component<ChartErrorBoundaryProps
|
|
|
415
415
|
'refine.optimizePrompt': string;
|
|
416
416
|
'jinja.panel.title': string;
|
|
417
417
|
'jinja.panel.docLink': string;
|
|
418
|
+
'jinja.panel.close': string;
|
|
418
419
|
'jinja.panel.noTemplates': string;
|
|
419
420
|
'jinja.template.variableInterpolation.title': string;
|
|
420
421
|
'jinja.template.variableInterpolation.description': string;
|
|
@@ -803,6 +804,7 @@ declare class ChartErrorBoundary extends React.Component<ChartErrorBoundaryProps
|
|
|
803
804
|
'refine.optimizePrompt': string;
|
|
804
805
|
'jinja.panel.title': string;
|
|
805
806
|
'jinja.panel.docLink': string;
|
|
807
|
+
'jinja.panel.close': string;
|
|
806
808
|
'jinja.panel.noTemplates': string;
|
|
807
809
|
'jinja.template.variableInterpolation.title': string;
|
|
808
810
|
'jinja.template.variableInterpolation.description': string;
|
|
@@ -0,0 +1,210 @@
|
|
|
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 { ChevronUp } from "@sofa-design/icons";
|
|
60
|
+
import { ConfigProvider } from "antd";
|
|
61
|
+
import classNames from "clsx";
|
|
62
|
+
import { AnimatePresence, motion } from "framer-motion";
|
|
63
|
+
import { useMergedState } from "rc-util";
|
|
64
|
+
import React, { memo, useContext, useMemo } from "react";
|
|
65
|
+
import { ActionIconBox } from "../Components/ActionIconBox";
|
|
66
|
+
import { useRefFunction } from "../Hooks/useRefFunction";
|
|
67
|
+
import { I18nContext } from "../I18n";
|
|
68
|
+
import { StatusIcon } from "./components/StatusIcon";
|
|
69
|
+
import { TaskListItem } from "./components/TaskListItem";
|
|
70
|
+
import { COLLAPSE_TRANSITION, COLLAPSE_VARIANTS, getArrowRotation } from "./constants";
|
|
71
|
+
import { useStyle } from "./style";
|
|
72
|
+
var getDefaultExpandedKeys = function getDefaultExpandedKeys(items, isControlled) {
|
|
73
|
+
return isControlled ? [] : items.map(function(item) {
|
|
74
|
+
return item.key;
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
export var TaskList = /*#__PURE__*/ memo(function(param) {
|
|
78
|
+
var items = param.items, className = param.className, expandedKeys = param.expandedKeys, onExpandedKeysChange = param.onExpandedKeysChange, _param_variant = param.variant, variant = _param_variant === void 0 ? 'default' : _param_variant, open = param.open, onOpenChange = param.onOpenChange;
|
|
79
|
+
var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
|
|
80
|
+
var prefixCls = getPrefixCls('task-list');
|
|
81
|
+
var _useStyle = useStyle(prefixCls), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
|
|
82
|
+
var locale = useContext(I18nContext).locale;
|
|
83
|
+
var isControlled = expandedKeys !== undefined;
|
|
84
|
+
var _useMergedState = _sliced_to_array(useMergedState(getDefaultExpandedKeys(items, isControlled), {
|
|
85
|
+
value: expandedKeys,
|
|
86
|
+
onChange: onExpandedKeysChange
|
|
87
|
+
}), 2), internalExpandedKeys = _useMergedState[0], setInternalExpandedKeys = _useMergedState[1];
|
|
88
|
+
var handleToggle = useRefFunction(function(key) {
|
|
89
|
+
var currentExpanded = isControlled ? expandedKeys : internalExpandedKeys;
|
|
90
|
+
var newExpandedKeys = currentExpanded.includes(key) ? currentExpanded.filter(function(k) {
|
|
91
|
+
return k !== key;
|
|
92
|
+
}) : _to_consumable_array(currentExpanded).concat([
|
|
93
|
+
key
|
|
94
|
+
]);
|
|
95
|
+
setInternalExpandedKeys(newExpandedKeys);
|
|
96
|
+
});
|
|
97
|
+
var _useMergedState1 = _sliced_to_array(useMergedState(false, {
|
|
98
|
+
value: open,
|
|
99
|
+
onChange: function onChange(val) {
|
|
100
|
+
return onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(val);
|
|
101
|
+
}
|
|
102
|
+
}), 2), simpleExpanded = _useMergedState1[0], setSimpleExpanded = _useMergedState1[1];
|
|
103
|
+
var handleSimpleToggle = useRefFunction(function() {
|
|
104
|
+
setSimpleExpanded(function(prev) {
|
|
105
|
+
return !prev;
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
var _useMemo = useMemo(function() {
|
|
109
|
+
var completedCount = items.filter(function(i) {
|
|
110
|
+
return i.status === 'success';
|
|
111
|
+
}).length;
|
|
112
|
+
var loadingItem = items.find(function(i) {
|
|
113
|
+
return i.status === 'loading';
|
|
114
|
+
});
|
|
115
|
+
var hasError = items.some(function(i) {
|
|
116
|
+
return i.status === 'error';
|
|
117
|
+
});
|
|
118
|
+
var allDone = completedCount === items.length && items.length > 0;
|
|
119
|
+
var status = 'pending';
|
|
120
|
+
var text = (locale === null || locale === void 0 ? void 0 : locale['taskList.taskList']) || '任务列表';
|
|
121
|
+
if (allDone) {
|
|
122
|
+
status = 'success';
|
|
123
|
+
text = (locale === null || locale === void 0 ? void 0 : locale['taskList.taskComplete']) || '任务完成';
|
|
124
|
+
} else if (loadingItem === null || loadingItem === void 0 ? void 0 : loadingItem.title) {
|
|
125
|
+
status = 'loading';
|
|
126
|
+
var tpl = (locale === null || locale === void 0 ? void 0 : locale['taskList.taskInProgress']) || '正在进行${taskName}任务';
|
|
127
|
+
var title = loadingItem.title;
|
|
128
|
+
var taskName = typeof title === 'string' || typeof title === 'number' ? String(title) : '';
|
|
129
|
+
text = tpl.replace('${taskName}', taskName);
|
|
130
|
+
} else if (hasError) {
|
|
131
|
+
status = 'error';
|
|
132
|
+
text = (locale === null || locale === void 0 ? void 0 : locale['taskList.taskAborted']) || '任务已取消';
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
summaryStatus: status,
|
|
136
|
+
summaryText: text,
|
|
137
|
+
progressText: "".concat(completedCount, "/").concat(items.length)
|
|
138
|
+
};
|
|
139
|
+
}, [
|
|
140
|
+
items,
|
|
141
|
+
locale
|
|
142
|
+
]), summaryStatus = _useMemo.summaryStatus, summaryText = _useMemo.summaryText, progressText = _useMemo.progressText;
|
|
143
|
+
var renderItems = function renderItems() {
|
|
144
|
+
return items.map(function(item, index) {
|
|
145
|
+
return /*#__PURE__*/ React.createElement(TaskListItem, {
|
|
146
|
+
key: item.key,
|
|
147
|
+
item: item,
|
|
148
|
+
isLast: index === items.length - 1,
|
|
149
|
+
prefixCls: prefixCls,
|
|
150
|
+
hashId: hashId,
|
|
151
|
+
expandedKeys: internalExpandedKeys,
|
|
152
|
+
onToggle: handleToggle
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
if (variant !== 'simple') {
|
|
157
|
+
return wrapSSR(/*#__PURE__*/ React.createElement("div", {
|
|
158
|
+
className: className
|
|
159
|
+
}, renderItems()));
|
|
160
|
+
}
|
|
161
|
+
var simpleCls = "".concat(prefixCls, "-simple");
|
|
162
|
+
var simpleArrowTitle = simpleExpanded ? (locale === null || locale === void 0 ? void 0 : locale['taskList.collapse']) || '收起' : (locale === null || locale === void 0 ? void 0 : locale['taskList.expand']) || '展开';
|
|
163
|
+
return wrapSSR(/*#__PURE__*/ React.createElement("div", {
|
|
164
|
+
className: classNames("".concat(simpleCls, "-wrapper"), hashId, className),
|
|
165
|
+
"data-testid": "task-list-simple-wrapper"
|
|
166
|
+
}, /*#__PURE__*/ React.createElement("div", {
|
|
167
|
+
className: classNames(simpleCls, hashId),
|
|
168
|
+
onClick: handleSimpleToggle,
|
|
169
|
+
role: "button",
|
|
170
|
+
tabIndex: 0,
|
|
171
|
+
"aria-expanded": simpleExpanded,
|
|
172
|
+
"aria-label": simpleArrowTitle,
|
|
173
|
+
"data-testid": "task-list-simple-bar"
|
|
174
|
+
}, /*#__PURE__*/ React.createElement("div", {
|
|
175
|
+
className: classNames("".concat(simpleCls, "-status"), hashId)
|
|
176
|
+
}, /*#__PURE__*/ React.createElement(StatusIcon, {
|
|
177
|
+
status: summaryStatus,
|
|
178
|
+
prefixCls: prefixCls,
|
|
179
|
+
hashId: hashId
|
|
180
|
+
})), /*#__PURE__*/ React.createElement("div", {
|
|
181
|
+
className: classNames("".concat(simpleCls, "-text"), hashId)
|
|
182
|
+
}, summaryText), /*#__PURE__*/ React.createElement("div", {
|
|
183
|
+
className: classNames("".concat(simpleCls, "-progress"), hashId)
|
|
184
|
+
}, progressText), /*#__PURE__*/ React.createElement("div", {
|
|
185
|
+
className: classNames("".concat(simpleCls, "-arrow"), hashId)
|
|
186
|
+
}, /*#__PURE__*/ React.createElement(ActionIconBox, {
|
|
187
|
+
title: simpleArrowTitle,
|
|
188
|
+
iconStyle: getArrowRotation(!simpleExpanded),
|
|
189
|
+
loading: false,
|
|
190
|
+
onClick: function onClick(e) {
|
|
191
|
+
e.stopPropagation();
|
|
192
|
+
handleSimpleToggle();
|
|
193
|
+
}
|
|
194
|
+
}, /*#__PURE__*/ React.createElement(ChevronUp, {
|
|
195
|
+
"data-testid": "task-list-simple-arrow"
|
|
196
|
+
})))), /*#__PURE__*/ React.createElement(AnimatePresence, {
|
|
197
|
+
initial: false
|
|
198
|
+
}, simpleExpanded && /*#__PURE__*/ React.createElement(motion.div, {
|
|
199
|
+
key: "simple-task-list-content",
|
|
200
|
+
variants: COLLAPSE_VARIANTS,
|
|
201
|
+
initial: "collapsed",
|
|
202
|
+
animate: "expanded",
|
|
203
|
+
exit: "collapsed",
|
|
204
|
+
transition: COLLAPSE_TRANSITION,
|
|
205
|
+
className: classNames("".concat(simpleCls, "-content"), hashId)
|
|
206
|
+
}, /*#__PURE__*/ React.createElement("div", {
|
|
207
|
+
className: classNames("".concat(simpleCls, "-list"), hashId)
|
|
208
|
+
}, renderItems())))));
|
|
209
|
+
});
|
|
210
|
+
TaskList.displayName = 'TaskList';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CircleDashed, SuccessFill, X } from "@sofa-design/icons";
|
|
2
|
+
import classNames from "clsx";
|
|
3
|
+
import React, { memo } from "react";
|
|
4
|
+
import { Loading } from "../../Components/Loading";
|
|
5
|
+
import { LOADING_SIZE } from "../constants";
|
|
6
|
+
export var StatusIcon = /*#__PURE__*/ memo(function(param) {
|
|
7
|
+
var status = param.status, prefixCls = param.prefixCls, hashId = param.hashId;
|
|
8
|
+
var statusMap = {
|
|
9
|
+
success: /*#__PURE__*/ React.createElement(SuccessFill, null),
|
|
10
|
+
loading: /*#__PURE__*/ React.createElement(Loading, {
|
|
11
|
+
size: LOADING_SIZE
|
|
12
|
+
}),
|
|
13
|
+
pending: /*#__PURE__*/ React.createElement("div", {
|
|
14
|
+
className: classNames("".concat(prefixCls, "-status-idle"), hashId)
|
|
15
|
+
}, /*#__PURE__*/ React.createElement(CircleDashed, null)),
|
|
16
|
+
error: /*#__PURE__*/ React.createElement(X, null)
|
|
17
|
+
};
|
|
18
|
+
return /*#__PURE__*/ React.createElement("div", {
|
|
19
|
+
className: classNames("".concat(prefixCls, "-status"), "".concat(prefixCls, "-status-").concat(status), hashId),
|
|
20
|
+
"data-testid": "task-list-status-".concat(status)
|
|
21
|
+
}, statusMap[status]);
|
|
22
|
+
});
|
|
23
|
+
StatusIcon.displayName = 'StatusIcon';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { TaskItem } from '../types';
|
|
3
|
+
interface TaskListItemProps {
|
|
4
|
+
item: TaskItem;
|
|
5
|
+
isLast: boolean;
|
|
6
|
+
prefixCls: string;
|
|
7
|
+
hashId: string;
|
|
8
|
+
expandedKeys: string[];
|
|
9
|
+
onToggle: (key: string) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare const TaskListItem: React.FC<TaskListItemProps>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ChevronUp } from "@sofa-design/icons";
|
|
2
|
+
import classNames from "clsx";
|
|
3
|
+
import { AnimatePresence, motion } from "framer-motion";
|
|
4
|
+
import React, { memo, useCallback, useContext } from "react";
|
|
5
|
+
import { ActionIconBox } from "../../Components/ActionIconBox";
|
|
6
|
+
import { I18nContext } from "../../I18n";
|
|
7
|
+
import { COLLAPSE_TRANSITION, COLLAPSE_VARIANTS, getArrowRotation, hasTaskContent } from "../constants";
|
|
8
|
+
import { StatusIcon } from "./StatusIcon";
|
|
9
|
+
export var TaskListItem = /*#__PURE__*/ memo(function(param) {
|
|
10
|
+
var item = param.item, isLast = param.isLast, prefixCls = param.prefixCls, hashId = param.hashId, expandedKeys = param.expandedKeys, onToggle = param.onToggle;
|
|
11
|
+
var locale = useContext(I18nContext).locale;
|
|
12
|
+
var isCollapsed = !expandedKeys.includes(item.key);
|
|
13
|
+
var hasContent = hasTaskContent(item.content);
|
|
14
|
+
var handleToggle = useCallback(function() {
|
|
15
|
+
onToggle(item.key);
|
|
16
|
+
}, [
|
|
17
|
+
item.key,
|
|
18
|
+
onToggle
|
|
19
|
+
]);
|
|
20
|
+
var arrowTitle = isCollapsed ? (locale === null || locale === void 0 ? void 0 : locale['taskList.expand']) || '展开' : (locale === null || locale === void 0 ? void 0 : locale['taskList.collapse']) || '收起';
|
|
21
|
+
return /*#__PURE__*/ React.createElement("div", {
|
|
22
|
+
key: item.key,
|
|
23
|
+
className: classNames("".concat(prefixCls, "-thoughtChainItem"), hashId),
|
|
24
|
+
"data-testid": "task-list-thoughtChainItem"
|
|
25
|
+
}, /*#__PURE__*/ React.createElement("div", {
|
|
26
|
+
className: classNames("".concat(prefixCls, "-left"), hashId),
|
|
27
|
+
onClick: handleToggle,
|
|
28
|
+
"data-testid": "task-list-left"
|
|
29
|
+
}, /*#__PURE__*/ React.createElement(StatusIcon, {
|
|
30
|
+
status: item.status,
|
|
31
|
+
prefixCls: prefixCls,
|
|
32
|
+
hashId: hashId
|
|
33
|
+
}), /*#__PURE__*/ React.createElement("div", {
|
|
34
|
+
className: classNames("".concat(prefixCls, "-content-left"), hashId)
|
|
35
|
+
}, !isLast && /*#__PURE__*/ React.createElement("div", {
|
|
36
|
+
className: classNames("".concat(prefixCls, "-dash-line"), hashId),
|
|
37
|
+
"data-testid": "task-list-dash-line"
|
|
38
|
+
}))), /*#__PURE__*/ React.createElement("div", {
|
|
39
|
+
className: classNames("".concat(prefixCls, "-right"), hashId)
|
|
40
|
+
}, /*#__PURE__*/ React.createElement("div", {
|
|
41
|
+
className: classNames("".concat(prefixCls, "-top"), hashId),
|
|
42
|
+
onClick: handleToggle
|
|
43
|
+
}, /*#__PURE__*/ React.createElement("div", {
|
|
44
|
+
className: classNames("".concat(prefixCls, "-title"), hashId)
|
|
45
|
+
}, item.title), hasContent && /*#__PURE__*/ React.createElement("div", {
|
|
46
|
+
className: classNames("".concat(prefixCls, "-arrowContainer"), hashId),
|
|
47
|
+
"data-testid": "task-list-arrowContainer"
|
|
48
|
+
}, /*#__PURE__*/ React.createElement(ActionIconBox, {
|
|
49
|
+
title: arrowTitle,
|
|
50
|
+
iconStyle: getArrowRotation(isCollapsed),
|
|
51
|
+
loading: false
|
|
52
|
+
}, /*#__PURE__*/ React.createElement(ChevronUp, {
|
|
53
|
+
"data-testid": "task-list-arrow"
|
|
54
|
+
})))), /*#__PURE__*/ React.createElement(AnimatePresence, {
|
|
55
|
+
initial: false
|
|
56
|
+
}, !isCollapsed && /*#__PURE__*/ React.createElement(motion.div, {
|
|
57
|
+
key: "task-content",
|
|
58
|
+
variants: COLLAPSE_VARIANTS,
|
|
59
|
+
initial: "collapsed",
|
|
60
|
+
animate: "expanded",
|
|
61
|
+
exit: "collapsed",
|
|
62
|
+
transition: COLLAPSE_TRANSITION,
|
|
63
|
+
className: classNames("".concat(prefixCls, "-body"), hashId)
|
|
64
|
+
}, /*#__PURE__*/ React.createElement("div", {
|
|
65
|
+
className: classNames("".concat(prefixCls, "-content"), hashId)
|
|
66
|
+
}, item.content)))));
|
|
67
|
+
});
|
|
68
|
+
TaskListItem.displayName = 'TaskListItem';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare const LOADING_SIZE = 16;
|
|
3
|
+
export declare const COLLAPSE_VARIANTS: {
|
|
4
|
+
expanded: {
|
|
5
|
+
height: string;
|
|
6
|
+
opacity: number;
|
|
7
|
+
};
|
|
8
|
+
collapsed: {
|
|
9
|
+
height: number;
|
|
10
|
+
opacity: number;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export declare const COLLAPSE_TRANSITION: {
|
|
14
|
+
height: {
|
|
15
|
+
duration: number;
|
|
16
|
+
ease: number[];
|
|
17
|
+
};
|
|
18
|
+
opacity: {
|
|
19
|
+
duration: number;
|
|
20
|
+
ease: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export declare const getArrowRotation: (collapsed: boolean) => React.CSSProperties;
|
|
24
|
+
export declare const hasTaskContent: (content: React.ReactNode | React.ReactNode[]) => boolean;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export var LOADING_SIZE = 16;
|
|
2
|
+
export var COLLAPSE_VARIANTS = {
|
|
3
|
+
expanded: {
|
|
4
|
+
height: 'auto',
|
|
5
|
+
opacity: 1
|
|
6
|
+
},
|
|
7
|
+
collapsed: {
|
|
8
|
+
height: 0,
|
|
9
|
+
opacity: 0
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
export var COLLAPSE_TRANSITION = {
|
|
13
|
+
height: {
|
|
14
|
+
duration: 0.26,
|
|
15
|
+
ease: [
|
|
16
|
+
0.4,
|
|
17
|
+
0,
|
|
18
|
+
0.2,
|
|
19
|
+
1
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
opacity: {
|
|
23
|
+
duration: 0.2,
|
|
24
|
+
ease: 'linear'
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
export var getArrowRotation = function getArrowRotation(collapsed) {
|
|
28
|
+
return {
|
|
29
|
+
transform: collapsed ? 'rotate(0deg)' : 'rotate(180deg)',
|
|
30
|
+
transition: 'transform 0.3s ease'
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export var hasTaskContent = function hasTaskContent(content) {
|
|
34
|
+
if (Array.isArray(content)) {
|
|
35
|
+
return content.length > 0;
|
|
36
|
+
}
|
|
37
|
+
return !!content;
|
|
38
|
+
};
|
package/dist/TaskList/index.d.ts
CHANGED
|
@@ -1,50 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
type
|
|
3
|
-
type TaskItem = {
|
|
4
|
-
key: string;
|
|
5
|
-
title?: React.ReactNode;
|
|
6
|
-
content: React.ReactNode | React.ReactNode[];
|
|
7
|
-
status: TaskStatus;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* TaskList 组件属性
|
|
11
|
-
*/
|
|
12
|
-
export type TaskListProps = {
|
|
13
|
-
/** 任务列表数据 */
|
|
14
|
-
items: TaskItem[];
|
|
15
|
-
/** 自定义类名 */
|
|
16
|
-
className?: string;
|
|
17
|
-
/** 受控模式:指定当前展开的任务项 key 数组 */
|
|
18
|
-
expandedKeys?: string[];
|
|
19
|
-
/** 受控模式:展开状态变化时的回调函数 */
|
|
20
|
-
onExpandedKeysChange?: (expandedKeys: string[]) => void;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* @deprecated @since 2.30.0 请使用 TaskListProps 替代
|
|
24
|
-
*/
|
|
25
|
-
export type ThoughtChainProps = TaskListProps;
|
|
26
|
-
/**
|
|
27
|
-
* TaskList 组件
|
|
28
|
-
*
|
|
29
|
-
* 显示任务列表,支持展开/折叠、状态管理等功能
|
|
30
|
-
* 支持受控和非受控两种模式
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```tsx
|
|
34
|
-
* // 非受控模式
|
|
35
|
-
* <TaskList
|
|
36
|
-
* items={[
|
|
37
|
-
* { key: 'task1', title: '任务1', content: '内容', status: 'success' }
|
|
38
|
-
* ]}
|
|
39
|
-
* />
|
|
40
|
-
*
|
|
41
|
-
* // 受控模式
|
|
42
|
-
* <TaskList
|
|
43
|
-
* items={tasks}
|
|
44
|
-
* expandedKeys={expandedKeys}
|
|
45
|
-
* onExpandedKeysChange={setExpandedKeys}
|
|
46
|
-
* />
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
export declare const TaskList: React.MemoExoticComponent<({ items, className, expandedKeys, onExpandedKeysChange }: TaskListProps) => any>;
|
|
50
|
-
export {};
|
|
1
|
+
export { TaskList } from './TaskList';
|
|
2
|
+
export type { TaskItem, TaskListProps, TaskListVariant, TaskStatus, ThoughtChainProps, } from './types';
|