@agentscope-ai/design 1.0.28 → 1.0.29-beta.1770628898483
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/lib/components/commonComponents/CodeBlock/index.d.ts +2 -1
- package/lib/components/commonComponents/IconButton/index.style.js +5 -1
- package/lib/components/commonComponents/Modal/demo/basic.js +10 -0
- package/lib/components/commonComponents/PromptsEditor/VarRender.js +8 -51
- package/lib/components/commonComponents/PromptsEditor/components/OptimizeButton.d.ts +4 -0
- package/lib/components/commonComponents/PromptsEditor/components/OptimizeButton.js +77 -0
- package/lib/components/commonComponents/PromptsEditor/components/OptimizeInput.d.ts +4 -0
- package/lib/components/commonComponents/PromptsEditor/components/OptimizeInput.js +190 -0
- package/lib/components/commonComponents/PromptsEditor/components/SelectionToolbar.d.ts +4 -0
- package/lib/components/commonComponents/PromptsEditor/components/SelectionToolbar.js +73 -0
- package/lib/components/commonComponents/PromptsEditor/demo/optimize.d.ts +1 -0
- package/lib/components/commonComponents/PromptsEditor/demo/optimize.js +99 -0
- package/lib/components/commonComponents/PromptsEditor/hooks/useTextSelection.d.ts +20 -0
- package/lib/components/commonComponents/PromptsEditor/hooks/useTextSelection.js +120 -0
- package/lib/components/commonComponents/PromptsEditor/index.d.ts +4 -51
- package/lib/components/commonComponents/PromptsEditor/index.js +319 -72
- package/lib/components/commonComponents/PromptsEditor/index.style.d.ts +25 -0
- package/lib/components/commonComponents/PromptsEditor/index.style.js +46 -0
- package/lib/components/commonComponents/PromptsEditor/types.d.ts +210 -0
- package/lib/components/commonComponents/PromptsEditor/types.js +1 -0
- package/lib/components/commonComponents/RadioButton/demo/demo4.js +1 -2
- package/lib/components/commonComponents/RadioButton/index.style.js +7 -1
- package/lib/components/commonComponents/SlateEditor/index.js +3 -1
- package/lib/components/commonComponents/Steps/demo/demo3.js +5 -2
- package/lib/components/commonComponents/Steps/index.style.js +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/llms/all.llms.txt +1283 -837
- package/llms/components/commonComponents/CodeBlock/index.zh-CN.llms.txt +3 -2
- package/llms/components/commonComponents/FileIcon/index.zh-CN.llms.txt +28 -0
- package/llms/components/commonComponents/InputSearch/index.zh-CN.llms.txt +6 -0
- package/llms/components/commonComponents/MediaPreview/index.zh-CN.llms.txt +21 -0
- package/llms/components/commonComponents/PromptsEditor/index.zh-CN.llms.txt +12 -3
- package/llms/components/commonComponents/Tabs/index.zh-CN.llms.txt +1 -0
- package/llms/docs/changelog/index.zh-CN.llms.txt +67 -0
- package/llms/docs/guide/tokens&variables.zh-CN.llms.txt +1 -1
- package/llms/docs/guide/vibe-coding.zh-CN.llms.txt +2 -3
- package/llms/docs/icons/iconLibrary.zh-CN.llms.txt +308 -0
- package/llms/index.llms.txt +61 -48
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { ReactCodeMirrorProps } from '@uiw/react-codemirror';
|
|
1
2
|
import { Extension } from '@codemirror/state';
|
|
2
|
-
export interface CodeBlockProps {
|
|
3
|
+
export interface CodeBlockProps extends Omit<ReactCodeMirrorProps, 'theme' | 'extensions'> {
|
|
3
4
|
/**
|
|
4
5
|
* @description 语言
|
|
5
6
|
* @descriptionEn Language
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
var _templateObject;
|
|
2
2
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
3
3
|
import createGlobalStyle from "../../../libs/createStyle";
|
|
4
|
-
export var useStyle = createGlobalStyle(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n.", "-icon-button.", "-btn {\n .", "-btn-icon {\n display: flex;\n justify-content: center;\n align-items: center;\n }\n}\n"])), function (p) {
|
|
4
|
+
export var useStyle = createGlobalStyle(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n.", "-icon-button.", "-btn {\n .", "-btn-icon {\n display: flex;\n justify-content: center;\n align-items: center;\n }\n\n &.", "-btn-variant-outlined:not(:disabled):not(.", "-btn-disabled):hover {\n border-color: transparent;\n }\n}\n"])), function (p) {
|
|
5
5
|
return p.sparkPrefix;
|
|
6
6
|
}, function (p) {
|
|
7
7
|
return p.antPrefix;
|
|
8
8
|
}, function (p) {
|
|
9
9
|
return p.antPrefix;
|
|
10
|
+
}, function (p) {
|
|
11
|
+
return p.antPrefix;
|
|
12
|
+
}, function (p) {
|
|
13
|
+
return p.antPrefix;
|
|
10
14
|
});
|
|
@@ -14,6 +14,16 @@ export default function () {
|
|
|
14
14
|
_useState2 = _slicedToArray(_useState, 2),
|
|
15
15
|
open = _useState2[0],
|
|
16
16
|
setOpen = _useState2[1];
|
|
17
|
+
var model = Modal.info({
|
|
18
|
+
className: '',
|
|
19
|
+
closable: true,
|
|
20
|
+
width: 640,
|
|
21
|
+
footer: null,
|
|
22
|
+
icon: null,
|
|
23
|
+
content: /*#__PURE__*/_jsx("div", {
|
|
24
|
+
children: "Content"
|
|
25
|
+
})
|
|
26
|
+
});
|
|
17
27
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
18
28
|
children: [/*#__PURE__*/_jsx(Button, {
|
|
19
29
|
onClick: function onClick() {
|
|
@@ -1,52 +1,14 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
3
2
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
3
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
5
4
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
7
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
-
|
|
9
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
10
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
11
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
12
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
13
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
14
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
15
|
-
import { Decoration, EditorView, MatchDecorator, ViewPlugin, WidgetType } from '@codemirror/view';
|
|
8
|
+
import { Decoration, MatchDecorator, ViewPlugin } from '@codemirror/view';
|
|
16
9
|
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
_inherits(PlaceholderWidget, _WidgetType);
|
|
20
|
-
var _super = _createSuper(PlaceholderWidget);
|
|
21
|
-
function PlaceholderWidget(name) {
|
|
22
|
-
var _this;
|
|
23
|
-
_classCallCheck(this, PlaceholderWidget);
|
|
24
|
-
_this = _super.call(this);
|
|
25
|
-
_this.name = name;
|
|
26
|
-
return _this;
|
|
27
|
-
}
|
|
28
|
-
_createClass(PlaceholderWidget, [{
|
|
29
|
-
key: "eq",
|
|
30
|
-
value: function eq(other) {
|
|
31
|
-
return other.name === this.name;
|
|
32
|
-
}
|
|
33
|
-
}, {
|
|
34
|
-
key: "toDOM",
|
|
35
|
-
value: function toDOM() {
|
|
36
|
-
var wrap = document.createElement('span');
|
|
37
|
-
wrap.setAttribute('aria-hidden', 'true');
|
|
38
|
-
wrap.className = 'cm-prompt-var';
|
|
39
|
-
wrap.textContent = "${".concat(this.name, "}");
|
|
40
|
-
return wrap;
|
|
41
|
-
}
|
|
42
|
-
}, {
|
|
43
|
-
key: "ignoreEvent",
|
|
44
|
-
value: function ignoreEvent() {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
}]);
|
|
48
|
-
return PlaceholderWidget;
|
|
49
|
-
}(WidgetType); // Placeholder 匹配器
|
|
10
|
+
// 使用 Mark Decoration 而不是 Replace Decoration
|
|
11
|
+
// 这样文本保持可编辑,只添加样式高亮
|
|
50
12
|
var placeholderMatcher = new MatchDecorator({
|
|
51
13
|
// 该正则用于匹配形如 ${变量名} 的占位符,变量名允许为中文、字母、数字、下划线
|
|
52
14
|
// \${ 匹配字符 "${"
|
|
@@ -54,9 +16,9 @@ var placeholderMatcher = new MatchDecorator({
|
|
|
54
16
|
// \} 匹配字符 "}"
|
|
55
17
|
// g 全局匹配
|
|
56
18
|
regexp: /\$\{([\w\u4e00-\u9fa5]+)\}/g,
|
|
57
|
-
decoration: function decoration(
|
|
58
|
-
return Decoration.
|
|
59
|
-
|
|
19
|
+
decoration: function decoration() {
|
|
20
|
+
return Decoration.mark({
|
|
21
|
+
class: 'cm-prompt-var'
|
|
60
22
|
});
|
|
61
23
|
}
|
|
62
24
|
});
|
|
@@ -78,12 +40,7 @@ var placeholders = ViewPlugin.fromClass( /*#__PURE__*/function () {
|
|
|
78
40
|
}(), {
|
|
79
41
|
decorations: function decorations(instance) {
|
|
80
42
|
return instance.placeholders;
|
|
81
|
-
},
|
|
82
|
-
provide: function provide(plugin) {
|
|
83
|
-
return EditorView.atomicRanges.of(function (view) {
|
|
84
|
-
var _view$plugin;
|
|
85
|
-
return ((_view$plugin = view.plugin(plugin)) === null || _view$plugin === void 0 ? void 0 : _view$plugin.placeholders) || Decoration.none;
|
|
86
|
-
});
|
|
87
43
|
}
|
|
44
|
+
// 移除 atomicRanges,允许用户在变量内部编辑
|
|
88
45
|
});
|
|
89
46
|
export default [placeholders];
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { SparkMagicWandLine } from '@agentscope-ai/icons';
|
|
2
|
+
import { Button, Tooltip } from 'antd';
|
|
3
|
+
import React, { memo } from 'react';
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
|
+
/**
|
|
7
|
+
* 底部优化按钮组件
|
|
8
|
+
* 处理禁用状态和 tooltip 提示
|
|
9
|
+
*/
|
|
10
|
+
var OptimizeButton = function OptimizeButton(_ref) {
|
|
11
|
+
var _ref$disabled = _ref.disabled,
|
|
12
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
13
|
+
_ref$loading = _ref.loading,
|
|
14
|
+
loading = _ref$loading === void 0 ? false : _ref$loading,
|
|
15
|
+
_ref$text = _ref.text,
|
|
16
|
+
text = _ref$text === void 0 ? '优化提示词' : _ref$text,
|
|
17
|
+
onClick = _ref.onClick,
|
|
18
|
+
_ref$showRetry = _ref.showRetry,
|
|
19
|
+
showRetry = _ref$showRetry === void 0 ? false : _ref$showRetry,
|
|
20
|
+
onRetry = _ref.onRetry,
|
|
21
|
+
_ref$isOptimizing = _ref.isOptimizing,
|
|
22
|
+
isOptimizing = _ref$isOptimizing === void 0 ? false : _ref$isOptimizing,
|
|
23
|
+
onStop = _ref.onStop;
|
|
24
|
+
// 优化中显示停止按钮
|
|
25
|
+
if (isOptimizing) {
|
|
26
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
27
|
+
style: {
|
|
28
|
+
display: 'flex',
|
|
29
|
+
alignItems: 'center',
|
|
30
|
+
gap: 8
|
|
31
|
+
},
|
|
32
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
33
|
+
type: "primary",
|
|
34
|
+
size: "small",
|
|
35
|
+
icon: /*#__PURE__*/_jsx(SparkMagicWandLine, {
|
|
36
|
+
size: 14
|
|
37
|
+
}),
|
|
38
|
+
disabled: true,
|
|
39
|
+
loading: true,
|
|
40
|
+
children: text
|
|
41
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
42
|
+
size: "small",
|
|
43
|
+
onClick: onStop,
|
|
44
|
+
children: "\u505C\u6B62\u751F\u6210"
|
|
45
|
+
})]
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
var button = /*#__PURE__*/_jsx(Button, {
|
|
49
|
+
type: "primary",
|
|
50
|
+
size: "small",
|
|
51
|
+
icon: /*#__PURE__*/_jsx(SparkMagicWandLine, {
|
|
52
|
+
size: 14
|
|
53
|
+
}),
|
|
54
|
+
disabled: disabled || loading,
|
|
55
|
+
loading: loading,
|
|
56
|
+
onClick: onClick,
|
|
57
|
+
children: text
|
|
58
|
+
});
|
|
59
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
60
|
+
style: {
|
|
61
|
+
display: 'flex',
|
|
62
|
+
alignItems: 'center',
|
|
63
|
+
gap: 8
|
|
64
|
+
},
|
|
65
|
+
children: [disabled && !showRetry ? /*#__PURE__*/_jsx(Tooltip, {
|
|
66
|
+
title: "\u8F93\u5165\u5173\u952E\u8BCD\u540E\uFF0C\u624D\u53EF\u4F7F\u7528\u4F18\u5316prompt\u529F\u80FD\uFF01",
|
|
67
|
+
children: /*#__PURE__*/_jsx("span", {
|
|
68
|
+
children: button
|
|
69
|
+
})
|
|
70
|
+
}) : button, showRetry && /*#__PURE__*/_jsx(Button, {
|
|
71
|
+
size: "small",
|
|
72
|
+
onClick: onRetry,
|
|
73
|
+
children: "\u91CD\u8BD5"
|
|
74
|
+
})]
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
export default /*#__PURE__*/memo(OptimizeButton);
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { SparkCheckCircleLine, SparkErrorCircleLine } from '@agentscope-ai/icons';
|
|
2
|
+
import { Button, Spin } from 'antd';
|
|
3
|
+
import React, { memo, useCallback, useEffect, useRef } from 'react';
|
|
4
|
+
import { useStyles } from "../index.style";
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
+
/**
|
|
8
|
+
* 优化输入框组件
|
|
9
|
+
* 包含输入框、加载状态、结果展示和操作按钮
|
|
10
|
+
*/
|
|
11
|
+
var OptimizeInput = function OptimizeInput(_ref) {
|
|
12
|
+
var visible = _ref.visible,
|
|
13
|
+
value = _ref.value,
|
|
14
|
+
_onChange = _ref.onChange,
|
|
15
|
+
onSubmit = _ref.onSubmit,
|
|
16
|
+
onClose = _ref.onClose,
|
|
17
|
+
_ref$loading = _ref.loading,
|
|
18
|
+
loading = _ref$loading === void 0 ? false : _ref$loading,
|
|
19
|
+
status = _ref.status,
|
|
20
|
+
result = _ref.result,
|
|
21
|
+
error = _ref.error,
|
|
22
|
+
onReplace = _ref.onReplace,
|
|
23
|
+
onRetry = _ref.onRetry,
|
|
24
|
+
_ref$isPartial = _ref.isPartial,
|
|
25
|
+
isPartial = _ref$isPartial === void 0 ? false : _ref$isPartial,
|
|
26
|
+
containerRef = _ref.containerRef;
|
|
27
|
+
var _useStyles = useStyles(),
|
|
28
|
+
styles = _useStyles.styles;
|
|
29
|
+
var inputRef = useRef(null);
|
|
30
|
+
var popoverRef = useRef(null);
|
|
31
|
+
|
|
32
|
+
// 自动聚焦输入框
|
|
33
|
+
useEffect(function () {
|
|
34
|
+
if (visible && status === 'input' && inputRef.current) {
|
|
35
|
+
inputRef.current.focus();
|
|
36
|
+
}
|
|
37
|
+
}, [visible, status]);
|
|
38
|
+
|
|
39
|
+
// 点击外部关闭(仅在 input 状态且内容为空时)
|
|
40
|
+
useEffect(function () {
|
|
41
|
+
if (!visible || status !== 'input') return;
|
|
42
|
+
var handleClickOutside = function handleClickOutside(e) {
|
|
43
|
+
if (popoverRef.current && !popoverRef.current.contains(e.target) && !value.trim()) {
|
|
44
|
+
onClose();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// 延迟添加监听,避免立即触发
|
|
49
|
+
var timer = setTimeout(function () {
|
|
50
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
51
|
+
}, 100);
|
|
52
|
+
return function () {
|
|
53
|
+
clearTimeout(timer);
|
|
54
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
55
|
+
};
|
|
56
|
+
}, [visible, status, value, onClose]);
|
|
57
|
+
var handleKeyDown = useCallback(function (e) {
|
|
58
|
+
if (e.key === 'Enter' && !e.shiftKey) {
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
if (value.trim()) {
|
|
61
|
+
onSubmit();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (e.key === 'Escape' && !value.trim()) {
|
|
65
|
+
onClose();
|
|
66
|
+
}
|
|
67
|
+
}, [value, onSubmit, onClose]);
|
|
68
|
+
if (!visible) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 输入状态
|
|
73
|
+
var renderInput = function renderInput() {
|
|
74
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
75
|
+
className: styles.optimizeInput,
|
|
76
|
+
children: [/*#__PURE__*/_jsx("textarea", {
|
|
77
|
+
ref: inputRef,
|
|
78
|
+
className: "spark-optimize-input-field",
|
|
79
|
+
placeholder: "\u4F60\u5E0C\u671B\u5982\u4F55\u4F18\u5316\u63D0\u793A\u8BCD\uFF1F",
|
|
80
|
+
value: value,
|
|
81
|
+
onChange: function onChange(e) {
|
|
82
|
+
return _onChange(e.target.value);
|
|
83
|
+
},
|
|
84
|
+
onKeyDown: handleKeyDown,
|
|
85
|
+
rows: 1
|
|
86
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
87
|
+
className: "spark-optimize-send-btn ".concat(!value.trim() ? 'disabled' : ''),
|
|
88
|
+
onClick: function onClick() {
|
|
89
|
+
if (value.trim()) {
|
|
90
|
+
onSubmit();
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
children: "\u53D1\u9001"
|
|
94
|
+
})]
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// 加载状态(展示流式内容)
|
|
99
|
+
var renderLoading = function renderLoading() {
|
|
100
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
101
|
+
className: styles.optimizeLoading,
|
|
102
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
103
|
+
className: styles.optimizeInput,
|
|
104
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
105
|
+
className: "spark-optimize-input-value",
|
|
106
|
+
children: value
|
|
107
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
108
|
+
className: "spark-optimize-send-btn disabled",
|
|
109
|
+
children: "\u505C\u6B62"
|
|
110
|
+
})]
|
|
111
|
+
}), result ? /*#__PURE__*/_jsx("div", {
|
|
112
|
+
className: "spark-optimize-streaming-content",
|
|
113
|
+
children: result
|
|
114
|
+
}) : /*#__PURE__*/_jsxs("div", {
|
|
115
|
+
className: "spark-optimize-loading-content",
|
|
116
|
+
children: [/*#__PURE__*/_jsx(Spin, {
|
|
117
|
+
size: "small"
|
|
118
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
119
|
+
children: "\u4F18\u5316\u4E2D\uFF0C\u8BF7\u7B49\u5F85..."
|
|
120
|
+
})]
|
|
121
|
+
})]
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// 成功状态
|
|
126
|
+
var renderSuccess = function renderSuccess() {
|
|
127
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
128
|
+
className: styles.optimizeResult,
|
|
129
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
130
|
+
className: "spark-optimize-result-header spark-optimize-result-success",
|
|
131
|
+
children: [/*#__PURE__*/_jsx(SparkCheckCircleLine, {
|
|
132
|
+
size: 16
|
|
133
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
134
|
+
children: "\u4F18\u5316\u5B8C\u6210\uFF01"
|
|
135
|
+
})]
|
|
136
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
137
|
+
className: "spark-optimize-result-content",
|
|
138
|
+
children: result
|
|
139
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
140
|
+
className: styles.optimizeActions,
|
|
141
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
142
|
+
type: "primary",
|
|
143
|
+
size: "small",
|
|
144
|
+
onClick: onReplace,
|
|
145
|
+
children: "\u66FF\u6362"
|
|
146
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
147
|
+
size: "small",
|
|
148
|
+
onClick: onRetry,
|
|
149
|
+
children: "\u91CD\u8BD5"
|
|
150
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
151
|
+
size: "small",
|
|
152
|
+
onClick: onClose,
|
|
153
|
+
children: "\u9000\u51FA"
|
|
154
|
+
})]
|
|
155
|
+
})]
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// 错误状态
|
|
160
|
+
var renderError = function renderError() {
|
|
161
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
162
|
+
className: styles.optimizeResult,
|
|
163
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
164
|
+
className: "spark-optimize-result-header spark-optimize-result-error",
|
|
165
|
+
children: [/*#__PURE__*/_jsx(SparkErrorCircleLine, {
|
|
166
|
+
size: 16
|
|
167
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
168
|
+
children: "\u4F18\u5316\u5931\u8D25\uFF01\u8BF7\u68C0\u67E5\u7F51\u7EDC\u6216\u8D26\u53F7\u4F59\u989D"
|
|
169
|
+
})]
|
|
170
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
171
|
+
className: styles.optimizeActions,
|
|
172
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
173
|
+
size: "small",
|
|
174
|
+
onClick: onRetry,
|
|
175
|
+
children: "\u91CD\u8BD5"
|
|
176
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
177
|
+
size: "small",
|
|
178
|
+
onClick: onClose,
|
|
179
|
+
children: "\u9000\u51FA"
|
|
180
|
+
})]
|
|
181
|
+
})]
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
185
|
+
ref: popoverRef,
|
|
186
|
+
className: styles.optimizePopover,
|
|
187
|
+
children: [status === 'input' && renderInput(), status === 'loading' && renderLoading(), status === 'success' && renderSuccess(), status === 'error' && renderError()]
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
export default /*#__PURE__*/memo(OptimizeInput);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { SparkMagicWandLine } from '@agentscope-ai/icons';
|
|
8
|
+
import { Button } from 'antd';
|
|
9
|
+
import React, { memo, useEffect, useState } from 'react';
|
|
10
|
+
import { useStyles } from "../index.style";
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
/**
|
|
13
|
+
* 选中文本后的悬浮工具栏组件
|
|
14
|
+
* 显示在选中文本附近,提供局部优化入口
|
|
15
|
+
*/
|
|
16
|
+
var SelectionToolbar = function SelectionToolbar(_ref) {
|
|
17
|
+
var selection = _ref.selection,
|
|
18
|
+
_ref$text = _ref.text,
|
|
19
|
+
text = _ref$text === void 0 ? '优化' : _ref$text,
|
|
20
|
+
onClick = _ref.onClick,
|
|
21
|
+
containerRef = _ref.containerRef;
|
|
22
|
+
var _useStyles = useStyles(),
|
|
23
|
+
styles = _useStyles.styles;
|
|
24
|
+
var _useState = useState(null),
|
|
25
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
26
|
+
position = _useState2[0],
|
|
27
|
+
setPosition = _useState2[1];
|
|
28
|
+
useEffect(function () {
|
|
29
|
+
if (!(selection !== null && selection !== void 0 && selection.coords) || !(containerRef !== null && containerRef !== void 0 && containerRef.current)) {
|
|
30
|
+
setPosition(null);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
var containerRect = containerRef.current.getBoundingClientRect();
|
|
34
|
+
var coords = selection.coords;
|
|
35
|
+
|
|
36
|
+
// 计算工具栏位置:显示在选中文本的下方
|
|
37
|
+
var toolbarHeight = 32;
|
|
38
|
+
var gap = 4;
|
|
39
|
+
var top = coords.bottom - containerRect.top + gap;
|
|
40
|
+
|
|
41
|
+
// 如果下方空间不够,则显示在上方
|
|
42
|
+
if (top + toolbarHeight > containerRect.height - 30) {
|
|
43
|
+
top = coords.top - containerRect.top - toolbarHeight - gap;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 水平位置:靠近选中文本起始位置
|
|
47
|
+
var left = coords.left - containerRect.left;
|
|
48
|
+
setPosition({
|
|
49
|
+
top: Math.max(0, top),
|
|
50
|
+
left: Math.max(8, Math.min(left, containerRect.width - 68))
|
|
51
|
+
});
|
|
52
|
+
}, [selection, containerRef]);
|
|
53
|
+
if (!selection || !position) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return /*#__PURE__*/_jsx("div", {
|
|
57
|
+
className: styles.selectionToolbar,
|
|
58
|
+
style: {
|
|
59
|
+
top: position.top,
|
|
60
|
+
left: position.left
|
|
61
|
+
},
|
|
62
|
+
children: /*#__PURE__*/_jsx(Button, {
|
|
63
|
+
type: "primary",
|
|
64
|
+
size: "small",
|
|
65
|
+
icon: /*#__PURE__*/_jsx(SparkMagicWandLine, {
|
|
66
|
+
size: 14
|
|
67
|
+
}),
|
|
68
|
+
onClick: onClick,
|
|
69
|
+
children: text
|
|
70
|
+
})
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
export default /*#__PURE__*/memo(SelectionToolbar);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function OptimizeDemo(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
3
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
5
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
6
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
7
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
8
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
9
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
10
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
11
|
+
import { PromptsEditor } from "../../../..";
|
|
12
|
+
import { message } from 'antd';
|
|
13
|
+
import { useState } from 'react';
|
|
14
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
|
+
var MOCK_RESULT = "# \u89D2\u8272\uFF1A\n\u4F60\u662F\u4E00\u4F4D\u70ED\u60C5\u53CB\u597D\u7684\u65C5\u6E38\u5C0F\u52A9\u624B\uFF0C\u81F4\u529B\u4E8E\u4E3A\u7528\u6237\u63D0\u4F9B\u5168\u9762\u7684\u65C5\u884C\u5EFA\u8BAE\u548C\u5E2E\u52A9\u3002\u4F60\u719F\u6089\u5168\u7403\u5404\u5730\u7684\u65C5\u6E38\u666F\u70B9\u3001\u6587\u5316\u4E60\u4FD7\u548C\u5B9E\u7528\u65C5\u884C\u4FE1\u606F\uFF0C\u80FD\u591F\u6839\u636E\u7528\u6237\u7684\u9700\u6C42\u63D0\u4F9B\u4E2A\u6027\u5316\u7684\u65C5\u884C\u89C4\u5212\n\n## \u76EE\u6807\uFF1A\n1. \u53EA\u8BA8\u8BBA\u4E0E\u65C5\u884C\u76F8\u5173\u7684\u8BDD\u9898\u3002\n2. \u786E\u4FDD\u6240\u6709\u63A8\u8350\u90FD\u57FA\u4E8E\u7528\u6237\u7684\u65C5\u884C\u9700\u6C42\u3002\n\n## \u6280\u80FD\uFF1A\n1. \u8BE2\u95EE\u5E76\u4E86\u89E3\u7528\u6237\u7684\u65C5\u884C\u504F\u597D\u3001\u9884\u7B97\u3001\u51FA\u884C\u65E5\u671F\u3001\u6D3B\u52A8\u504F\u597D\u7B49\u4FE1\u606F\u3002";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 模拟流式优化 API 调用
|
|
19
|
+
*/
|
|
20
|
+
var mockStreamOptimize = /*#__PURE__*/function () {
|
|
21
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params, onUpdate, signal) {
|
|
22
|
+
var targetText, accumulated, i;
|
|
23
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
24
|
+
while (1) switch (_context.prev = _context.next) {
|
|
25
|
+
case 0:
|
|
26
|
+
targetText = params.isPartial ? "[\u4F18\u5316\u540E] ".concat(params.content) : MOCK_RESULT; // 模拟逐字流式输出
|
|
27
|
+
accumulated = '';
|
|
28
|
+
i = 0;
|
|
29
|
+
case 3:
|
|
30
|
+
if (!(i < targetText.length)) {
|
|
31
|
+
_context.next = 13;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
if (!signal.aborted) {
|
|
35
|
+
_context.next = 6;
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
throw new DOMException('Aborted', 'AbortError');
|
|
39
|
+
case 6:
|
|
40
|
+
_context.next = 8;
|
|
41
|
+
return new Promise(function (resolve) {
|
|
42
|
+
return setTimeout(resolve, 20);
|
|
43
|
+
});
|
|
44
|
+
case 8:
|
|
45
|
+
accumulated += targetText[i];
|
|
46
|
+
onUpdate(accumulated);
|
|
47
|
+
case 10:
|
|
48
|
+
i++;
|
|
49
|
+
_context.next = 3;
|
|
50
|
+
break;
|
|
51
|
+
case 13:
|
|
52
|
+
return _context.abrupt("return", accumulated);
|
|
53
|
+
case 14:
|
|
54
|
+
case "end":
|
|
55
|
+
return _context.stop();
|
|
56
|
+
}
|
|
57
|
+
}, _callee);
|
|
58
|
+
}));
|
|
59
|
+
return function mockStreamOptimize(_x, _x2, _x3) {
|
|
60
|
+
return _ref.apply(this, arguments);
|
|
61
|
+
};
|
|
62
|
+
}();
|
|
63
|
+
export default function OptimizeDemo() {
|
|
64
|
+
var _useState = useState("# \u89D2\u8272\uFF1A\n\u4F60\u662F\u4E00\u4F4D\u70ED\u60C5\u53CB\u597D\u7684\u65C5\u6E38\u5C0F\u52A9\u624B\uFF0C\u81F4\u529B\u4E8E\u4E3A\u7528\u6237\u63D0\u4F9B\u5168\u9762\u7684\u65C5\u884C\u5EFA\u8BAE\u548C\u5E2E\u52A9\u3002\u4F60\u719F\u6089\u5168\u7403\u5404\u5730\u7684\u65C5\u6E38\u666F\u70B9\u3001\u6587\u5316\u4E60\u4FD7\u548C\u5B9E\u7528\u65C5\u884C\u4FE1\u606F\uFF0C\u80FD\u591F\u6839\u636E\u7528\u6237\u7684\u9700\u6C42\u63D0\u4F9B\u4E2A\u6027\u5316\u7684\u65C5\u884C\u89C4\u5212 ${\u7528\u6237\u9700\u6C42}\n\n## \u76EE\u6807\uFF1A\n1. \u7981\u6B62\u63A8\u8350\u5546\u4E1A\u5316\u8FC7\u5EA6\u7684\u8FDE\u9501\u9910\u996E\u54C1\u724C\uFF08\u5982\u67D0\u70B9\u8BC4\u5FC5\u5403\u699CTOP30\u4E2D\u7684\u8FDE\u9501\u54C1\u724C\uFF09\n2. \u7981\u6B62\u5B89\u6392\u65E9\u4E8E9:00\u6216\u665A\u4E8E21:00\u7684\u56FA\u5B9A\u65F6\u95F4\u6D3B\u52A8\n3. \u7981\u6B62\u4F7F\u7528\u300C\u5FC5\u53BB\u300D\u300C\u6253\u5361\u300D\u7B49\u5F3A\u5F15\u5BFC\u6027\u8BCD\u6C47\uFF0C\u6539\u7528\u300C\u503C\u5F97\u4F53\u9A8C\u300D\u300C\u4E0D\u59A8\u8BD5\u8BD5\u300D\u7B49\u5EFA\u8BAE\u6027\u8868\u8FBE\n\n## \u6280\u80FD\uFF1A"),
|
|
65
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
66
|
+
value = _useState2[0],
|
|
67
|
+
setValue = _useState2[1];
|
|
68
|
+
var handleOptimize = /*#__PURE__*/function () {
|
|
69
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params, onUpdate, signal) {
|
|
70
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
71
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
72
|
+
case 0:
|
|
73
|
+
message.info("\u5F00\u59CB".concat(params.isPartial ? '局部' : '整体', "\u4F18\u5316..."));
|
|
74
|
+
return _context2.abrupt("return", mockStreamOptimize(params, onUpdate, signal));
|
|
75
|
+
case 2:
|
|
76
|
+
case "end":
|
|
77
|
+
return _context2.stop();
|
|
78
|
+
}
|
|
79
|
+
}, _callee2);
|
|
80
|
+
}));
|
|
81
|
+
return function handleOptimize(_x4, _x5, _x6) {
|
|
82
|
+
return _ref2.apply(this, arguments);
|
|
83
|
+
};
|
|
84
|
+
}();
|
|
85
|
+
return /*#__PURE__*/_jsx(PromptsEditor, {
|
|
86
|
+
value: value,
|
|
87
|
+
onChange: setValue,
|
|
88
|
+
maxLength: 6000,
|
|
89
|
+
variables: [{
|
|
90
|
+
code: '用户需求'
|
|
91
|
+
}, {
|
|
92
|
+
code: '日期'
|
|
93
|
+
}],
|
|
94
|
+
showOptimize: true,
|
|
95
|
+
onOptimize: handleOptimize,
|
|
96
|
+
optimizeBtnText: "\u4F18\u5316\u63D0\u793A\u8BCD",
|
|
97
|
+
partialOptimizeBtnText: "\u4F18\u5316"
|
|
98
|
+
});
|
|
99
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { EditorView } from '@codemirror/view';
|
|
2
|
+
import { Extension } from '@codemirror/state';
|
|
3
|
+
import { TextSelection } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* 监听 CodeMirror 文本选中状态的 hook
|
|
6
|
+
* 返回选中文本信息和创建监听扩展的方法
|
|
7
|
+
*/
|
|
8
|
+
export declare function useTextSelection(): {
|
|
9
|
+
/** 当前选中信息 */
|
|
10
|
+
selection: TextSelection;
|
|
11
|
+
/** CodeMirror 扩展 */
|
|
12
|
+
selectionExtension: Extension;
|
|
13
|
+
/** 清除选中状态 */
|
|
14
|
+
clearSelection: () => void;
|
|
15
|
+
/** 获取 EditorView 实例 */
|
|
16
|
+
getView: () => EditorView;
|
|
17
|
+
/** 替换选中文本 */
|
|
18
|
+
replaceSelection: (newText: string, from: number, to: number) => void;
|
|
19
|
+
};
|
|
20
|
+
export default useTextSelection;
|