@flowgram.ai/form-materials 0.1.0-alpha.12 → 0.1.0-alpha.14
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/bin/index.ts +4 -29
- package/bin/materials.ts +56 -87
- package/bin/project.ts +4 -0
- package/bin/utils/import.ts +127 -0
- package/bin/utils/traverse-file.ts +60 -0
- package/dist/esm/chunk-727SU246.js +13 -0
- package/dist/esm/chunk-727SU246.js.map +1 -0
- package/dist/esm/chunk-DEZUEMUM.js +284 -0
- package/dist/esm/chunk-DEZUEMUM.js.map +1 -0
- package/dist/esm/chunk-DUOXDOUE.js +477 -0
- package/dist/esm/chunk-DUOXDOUE.js.map +1 -0
- package/dist/esm/editor-6UMULJYB.js +180 -0
- package/dist/esm/editor-6UMULJYB.js.map +1 -0
- package/dist/esm/editor-EYOQTGMT.js +282 -0
- package/dist/esm/editor-EYOQTGMT.js.map +1 -0
- package/dist/esm/editor-OXPGKPF5.js +167 -0
- package/dist/esm/editor-OXPGKPF5.js.map +1 -0
- package/dist/esm/editor-VO6YAXRC.js +249 -0
- package/dist/esm/editor-VO6YAXRC.js.map +1 -0
- package/dist/esm/editor-XYLKTB6L.js +365 -0
- package/dist/esm/editor-XYLKTB6L.js.map +1 -0
- package/dist/esm/index.js +1186 -2456
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +363 -70
- package/dist/index.d.ts +363 -70
- package/dist/index.js +4064 -2887
- package/dist/index.js.map +1 -1
- package/package.json +9 -8
- package/src/components/assign-row/index.tsx +4 -4
- package/src/components/assign-rows/index.tsx +1 -1
- package/src/components/batch-outputs/index.tsx +7 -5
- package/src/components/batch-outputs/types.ts +1 -1
- package/src/components/batch-variable-selector/index.tsx +1 -1
- package/src/components/code-editor/editor.tsx +89 -0
- package/src/components/code-editor/index.tsx +5 -89
- package/src/components/code-editor/language-features.ts +18 -18
- package/src/components/code-editor/theme/dark.ts +49 -30
- package/src/components/code-editor/theme/light.ts +56 -32
- package/src/components/code-editor-mini/index.tsx +2 -2
- package/src/components/condition-row/constants.ts +10 -2
- package/src/components/condition-row/hooks/useOp.tsx +13 -9
- package/src/components/condition-row/hooks/useRule.ts +8 -4
- package/src/components/condition-row/index.tsx +31 -10
- package/src/components/condition-row/types.ts +5 -7
- package/src/components/constant-input/index.tsx +5 -2
- package/src/components/constant-input/types.ts +1 -1
- package/src/components/db-condition-row/hooks/use-left.tsx +66 -0
- package/src/components/db-condition-row/hooks/use-op.tsx +59 -0
- package/src/components/db-condition-row/index.tsx +93 -0
- package/src/components/db-condition-row/styles.tsx +43 -0
- package/src/components/db-condition-row/types.ts +34 -0
- package/src/components/display-flow-value/index.tsx +4 -14
- package/src/components/display-inputs-values/index.tsx +46 -7
- package/src/components/display-outputs/index.tsx +2 -1
- package/src/components/display-schema-tag/index.tsx +3 -2
- package/src/components/display-schema-tree/index.tsx +2 -1
- package/src/components/dynamic-value-input/hooks.ts +25 -4
- package/src/components/dynamic-value-input/index.tsx +33 -20
- package/src/components/dynamic-value-input/styles.tsx +14 -4
- package/src/components/index.ts +3 -0
- package/src/components/inputs-values/index.tsx +21 -8
- package/src/components/inputs-values/styles.tsx +1 -1
- package/src/components/inputs-values/types.ts +3 -3
- package/src/components/inputs-values-tree/hooks/use-child-list.tsx +76 -0
- package/src/components/inputs-values-tree/index.tsx +62 -0
- package/src/components/inputs-values-tree/row.tsx +177 -0
- package/src/components/inputs-values-tree/styles.tsx +128 -0
- package/src/components/inputs-values-tree/types.ts +21 -0
- package/src/components/json-editor-with-variables/editor.tsx +69 -0
- package/src/components/json-editor-with-variables/extensions/variable-tag.tsx +6 -5
- package/src/components/json-editor-with-variables/extensions/variable-tree.tsx +1 -1
- package/src/components/json-editor-with-variables/index.tsx +5 -58
- package/src/components/json-schema-editor/default-value.tsx +12 -108
- package/src/components/json-schema-editor/hooks.tsx +63 -93
- package/src/components/json-schema-editor/index.tsx +36 -70
- package/src/components/json-schema-editor/styles.tsx +12 -84
- package/src/components/json-schema-editor/types.ts +0 -1
- package/src/components/prompt-editor/editor.tsx +81 -0
- package/src/components/prompt-editor/index.tsx +5 -62
- package/src/components/prompt-editor/types.tsx +1 -1
- package/src/components/prompt-editor-with-inputs/editor.tsx +25 -0
- package/src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx +13 -1
- package/src/components/prompt-editor-with-inputs/index.tsx +5 -15
- package/src/components/prompt-editor-with-inputs/inputs-picker.tsx +34 -17
- package/src/components/prompt-editor-with-variables/editor.tsx +22 -0
- package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +12 -20
- package/src/components/prompt-editor-with-variables/extensions/variable-tree.tsx +14 -2
- package/src/components/prompt-editor-with-variables/index.tsx +5 -12
- package/src/components/type-selector/index.tsx +21 -9
- package/src/components/variable-selector/context.tsx +28 -0
- package/src/components/variable-selector/index.tsx +19 -6
- package/src/components/variable-selector/use-variable-tree.tsx +4 -4
- package/src/effects/auto-rename-ref/index.ts +8 -55
- package/src/effects/listen-ref-schema-change/index.ts +1 -1
- package/src/effects/listen-ref-value-change/index.ts +1 -1
- package/src/effects/provide-batch-input/index.ts +1 -1
- package/src/effects/validate-when-variable-sync/index.ts +1 -1
- package/src/form-plugins/batch-outputs-plugin/index.ts +1 -1
- package/src/form-plugins/infer-assign-plugin/index.ts +2 -2
- package/src/form-plugins/infer-inputs-plugin/index.ts +4 -76
- package/src/hooks/use-object-list/index.tsx +35 -7
- package/src/index.ts +1 -0
- package/src/plugins/json-schema-preset/manager.ts +1 -0
- package/src/plugins/json-schema-preset/type-definition/array.tsx +3 -1
- package/src/plugins/json-schema-preset/type-definition/boolean.tsx +4 -3
- package/src/plugins/json-schema-preset/type-definition/date-time.tsx +25 -0
- package/src/plugins/json-schema-preset/type-definition/index.tsx +2 -0
- package/src/plugins/json-schema-preset/type-definition/integer.tsx +2 -1
- package/src/plugins/json-schema-preset/type-definition/number.tsx +2 -1
- package/src/plugins/json-schema-preset/type-definition/object.tsx +3 -1
- package/src/plugins/json-schema-preset/type-definition/string.tsx +19 -4
- package/src/shared/flow-value/index.ts +6 -0
- package/src/shared/flow-value/schema.ts +38 -0
- package/src/shared/flow-value/utils.ts +201 -0
- package/src/shared/format-legacy-refs/index.ts +1 -1
- package/src/shared/index.ts +4 -0
- package/src/shared/inject-material/README.md +170 -0
- package/src/shared/inject-material/README.zh.md +174 -0
- package/src/shared/inject-material/index.tsx +87 -0
- package/src/shared/lazy-suspense/index.tsx +28 -0
- package/src/shared/polyfill-create-root/index.tsx +33 -0
- package/src/typings/flow-value/index.ts +3 -1
- package/src/validate/validate-flow-value/index.tsx +4 -16
- package/src/components/assign-row/config.json +0 -11
- package/src/components/assign-rows/config.json +0 -11
- package/src/components/batch-outputs/config.json +0 -13
- package/src/components/batch-variable-selector/config.json +0 -9
- package/src/components/code-editor/config.json +0 -10
- package/src/components/code-editor-mini/config.json +0 -7
- package/src/components/condition-row/config.json +0 -13
- package/src/components/constant-input/config.json +0 -9
- package/src/components/display-flow-value/config.json +0 -8
- package/src/components/display-inputs-values/config.json +0 -9
- package/src/components/display-outputs/config.json +0 -10
- package/src/components/display-schema-tag/config.json +0 -10
- package/src/components/display-schema-tree/config.json +0 -11
- package/src/components/dynamic-value-input/config.json +0 -14
- package/src/components/inputs-values/config.json +0 -13
- package/src/components/json-editor-with-variables/config.json +0 -13
- package/src/components/json-schema-editor/components/blur-input.tsx +0 -27
- package/src/components/json-schema-editor/config.json +0 -13
- package/src/components/json-schema-editor/utils.ts +0 -29
- package/src/components/prompt-editor/config.json +0 -9
- package/src/components/prompt-editor-with-inputs/config.json +0 -13
- package/src/components/prompt-editor-with-variables/config.json +0 -13
- package/src/components/type-selector/config.json +0 -9
- package/src/components/variable-selector/config.json +0 -9
- package/src/effects/auto-rename-ref/config.json +0 -5
- package/src/effects/listen-ref-schema-change/config.json +0 -10
- package/src/effects/listen-ref-value-change/config.json +0 -9
- package/src/effects/provide-batch-input/config.json +0 -5
- package/src/effects/provide-json-schema-outputs/config.json +0 -7
- package/src/effects/sync-variable-title/config.json +0 -5
- package/src/effects/validate-when-variable-sync/config.json +0 -5
- package/src/form-plugins/batch-outputs-plugin/config.json +0 -7
- package/src/form-plugins/infer-assign-plugin/config.json +0 -7
- package/src/form-plugins/infer-inputs-plugin/config.json +0 -9
- package/src/hooks/use-object-list/config.json +0 -8
- package/src/plugins/disable-declaration-plugin/config.json +0 -5
- package/src/plugins/json-schema-preset/config.json +0 -9
- package/src/shared/format-legacy-refs/config.json +0 -5
- package/src/typings/flow-value/config.json +0 -7
- package/src/validate/validate-flow-value/config.json +0 -7
- /package/src/components/{inputs-values/components/blur-input.tsx → blur-input/index.tsx} +0 -0
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import React, { useMemo, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
9
|
+
import { I18n } from '@flowgram.ai/editor';
|
|
9
10
|
import { Button, Checkbox, IconButton } from '@douyinfe/semi-ui';
|
|
10
11
|
import {
|
|
11
12
|
IconExpand,
|
|
@@ -16,7 +17,9 @@ import {
|
|
|
16
17
|
IconMinus,
|
|
17
18
|
} from '@douyinfe/semi-icons';
|
|
18
19
|
|
|
19
|
-
import {
|
|
20
|
+
import { InjectTypeSelector } from '@/components/type-selector';
|
|
21
|
+
import { BlurInput } from '@/components/blur-input';
|
|
22
|
+
|
|
20
23
|
import { ConfigType, PropertyValueType } from './types';
|
|
21
24
|
import {
|
|
22
25
|
IconAddChildren,
|
|
@@ -26,10 +29,10 @@ import {
|
|
|
26
29
|
UIContainer,
|
|
27
30
|
UIExpandDetail,
|
|
28
31
|
UILabel,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
UITreeItems,
|
|
33
|
+
UITreeItemLeft,
|
|
34
|
+
UITreeItemMain,
|
|
35
|
+
UITreeItemRight,
|
|
33
36
|
UIRequired,
|
|
34
37
|
UIType,
|
|
35
38
|
} from './styles';
|
|
@@ -37,7 +40,8 @@ import { UIName } from './styles';
|
|
|
37
40
|
import { DefaultValueWrapper, UIRow } from './styles';
|
|
38
41
|
import { usePropertiesEdit } from './hooks';
|
|
39
42
|
import { DefaultValue } from './default-value';
|
|
40
|
-
|
|
43
|
+
|
|
44
|
+
const DEFAULT = { type: 'object' };
|
|
41
45
|
|
|
42
46
|
export function JsonSchemaEditor(props: {
|
|
43
47
|
value?: IJsonSchema;
|
|
@@ -46,7 +50,7 @@ export function JsonSchemaEditor(props: {
|
|
|
46
50
|
className?: string;
|
|
47
51
|
readonly?: boolean;
|
|
48
52
|
}) {
|
|
49
|
-
const { value =
|
|
53
|
+
const { value = DEFAULT, config = {}, onChange: onChangeProps, readonly } = props;
|
|
50
54
|
const { propertyList, onAddProperty, onRemoveProperty, onEditProperty } = usePropertiesEdit(
|
|
51
55
|
value,
|
|
52
56
|
onChangeProps
|
|
@@ -54,14 +58,13 @@ export function JsonSchemaEditor(props: {
|
|
|
54
58
|
|
|
55
59
|
return (
|
|
56
60
|
<UIContainer className={props.className}>
|
|
57
|
-
<
|
|
58
|
-
{propertyList.map((_property
|
|
61
|
+
<UITreeItems>
|
|
62
|
+
{propertyList.map((_property) => (
|
|
59
63
|
<PropertyEdit
|
|
60
64
|
readonly={readonly}
|
|
61
65
|
key={_property.key}
|
|
62
66
|
value={_property}
|
|
63
67
|
config={config}
|
|
64
|
-
$index={index}
|
|
65
68
|
onChange={(_v) => {
|
|
66
69
|
onEditProperty(_property.key!, _v);
|
|
67
70
|
}}
|
|
@@ -70,7 +73,7 @@ export function JsonSchemaEditor(props: {
|
|
|
70
73
|
}}
|
|
71
74
|
/>
|
|
72
75
|
))}
|
|
73
|
-
</
|
|
76
|
+
</UITreeItems>
|
|
74
77
|
<Button
|
|
75
78
|
disabled={readonly}
|
|
76
79
|
size="small"
|
|
@@ -78,7 +81,7 @@ export function JsonSchemaEditor(props: {
|
|
|
78
81
|
icon={<IconPlus />}
|
|
79
82
|
onClick={onAddProperty}
|
|
80
83
|
>
|
|
81
|
-
{config?.addButtonText ?? 'Add'}
|
|
84
|
+
{config?.addButtonText ?? I18n.t('Add')}
|
|
82
85
|
</Button>
|
|
83
86
|
</UIContainer>
|
|
84
87
|
);
|
|
@@ -91,27 +94,9 @@ function PropertyEdit(props: {
|
|
|
91
94
|
onRemove?: () => void;
|
|
92
95
|
readonly?: boolean;
|
|
93
96
|
$isLast?: boolean;
|
|
94
|
-
$index?: number;
|
|
95
|
-
$isFirst?: boolean;
|
|
96
|
-
$parentExpand?: boolean;
|
|
97
|
-
$parentType?: string;
|
|
98
|
-
$showLine?: boolean;
|
|
99
97
|
$level?: number; // 添加层级属性
|
|
100
98
|
}) {
|
|
101
|
-
const {
|
|
102
|
-
value,
|
|
103
|
-
config,
|
|
104
|
-
readonly,
|
|
105
|
-
$level = 0,
|
|
106
|
-
onChange: onChangeProps,
|
|
107
|
-
onRemove,
|
|
108
|
-
$index,
|
|
109
|
-
$isFirst,
|
|
110
|
-
$isLast,
|
|
111
|
-
$parentExpand = false,
|
|
112
|
-
$parentType = '',
|
|
113
|
-
$showLine,
|
|
114
|
-
} = props;
|
|
99
|
+
const { value, config, readonly, $level = 0, onChange: onChangeProps, onRemove, $isLast } = props;
|
|
115
100
|
|
|
116
101
|
const [expand, setExpand] = useState(false);
|
|
117
102
|
const [collapse, setCollapse] = useState(false);
|
|
@@ -120,7 +105,7 @@ function PropertyEdit(props: {
|
|
|
120
105
|
|
|
121
106
|
const typeSelectorValue = useMemo(() => ({ type, items }), [type, items]);
|
|
122
107
|
|
|
123
|
-
const { propertyList,
|
|
108
|
+
const { propertyList, canAddField, onAddProperty, onRemoveProperty, onEditProperty } =
|
|
124
109
|
usePropertiesEdit(value, onChangeProps);
|
|
125
110
|
|
|
126
111
|
const onChange = (key: string, _value: any) => {
|
|
@@ -130,45 +115,31 @@ function PropertyEdit(props: {
|
|
|
130
115
|
});
|
|
131
116
|
};
|
|
132
117
|
|
|
133
|
-
const showCollapse =
|
|
118
|
+
const showCollapse = canAddField && propertyList.length > 0;
|
|
134
119
|
|
|
135
120
|
return (
|
|
136
121
|
<>
|
|
137
|
-
<
|
|
138
|
-
type={type}
|
|
139
|
-
$index={$index}
|
|
140
|
-
$isFirst={$isFirst}
|
|
141
|
-
$isLast={$isLast}
|
|
142
|
-
$showLine={$showLine}
|
|
143
|
-
$isExpand={expand}
|
|
144
|
-
$parentExpand={$parentExpand}
|
|
145
|
-
$parentType={$parentType}
|
|
146
|
-
>
|
|
122
|
+
<UITreeItemLeft $isLast={$isLast} $showLine={$level > 0} $showCollapse={showCollapse}>
|
|
147
123
|
{showCollapse && (
|
|
148
124
|
<UICollapseTrigger onClick={() => setCollapse((_collapse) => !_collapse)}>
|
|
149
125
|
{collapse ? <IconChevronDown size="small" /> : <IconChevronRight size="small" />}
|
|
150
126
|
</UICollapseTrigger>
|
|
151
127
|
)}
|
|
152
|
-
</
|
|
153
|
-
<
|
|
154
|
-
<
|
|
155
|
-
$showCollapse={showCollapse}
|
|
156
|
-
$collapse={collapse}
|
|
157
|
-
$expand={expand}
|
|
158
|
-
type={type}
|
|
159
|
-
>
|
|
128
|
+
</UITreeItemLeft>
|
|
129
|
+
<UITreeItemRight>
|
|
130
|
+
<UITreeItemMain>
|
|
160
131
|
<UIRow>
|
|
161
132
|
<UIName>
|
|
162
133
|
<BlurInput
|
|
163
134
|
disabled={readonly}
|
|
164
|
-
placeholder={config?.placeholder ?? 'Input Variable Name'}
|
|
135
|
+
placeholder={config?.placeholder ?? I18n.t('Input Variable Name')}
|
|
165
136
|
size="small"
|
|
166
137
|
value={name}
|
|
167
138
|
onChange={(value) => onChange('name', value)}
|
|
168
139
|
/>
|
|
169
140
|
</UIName>
|
|
170
141
|
<UIType>
|
|
171
|
-
<
|
|
142
|
+
<InjectTypeSelector
|
|
172
143
|
value={typeSelectorValue}
|
|
173
144
|
readonly={readonly}
|
|
174
145
|
onChange={(_value) => {
|
|
@@ -196,7 +167,7 @@ function PropertyEdit(props: {
|
|
|
196
167
|
setExpand((_expand) => !_expand);
|
|
197
168
|
}}
|
|
198
169
|
/>
|
|
199
|
-
{
|
|
170
|
+
{canAddField && (
|
|
200
171
|
<IconButton
|
|
201
172
|
disabled={readonly}
|
|
202
173
|
size="small"
|
|
@@ -219,26 +190,26 @@ function PropertyEdit(props: {
|
|
|
219
190
|
</UIRow>
|
|
220
191
|
{expand && (
|
|
221
192
|
<UIExpandDetail>
|
|
222
|
-
<UILabel>{config?.descTitle ?? 'Description'}</UILabel>
|
|
193
|
+
<UILabel>{config?.descTitle ?? I18n.t('Description')}</UILabel>
|
|
223
194
|
<BlurInput
|
|
224
195
|
disabled={readonly}
|
|
225
196
|
size="small"
|
|
226
197
|
value={description}
|
|
227
198
|
onChange={(value) => onChange('description', value)}
|
|
228
|
-
placeholder={
|
|
199
|
+
placeholder={
|
|
200
|
+
config?.descPlaceholder ?? I18n.t('Help LLM to understand the property')
|
|
201
|
+
}
|
|
229
202
|
/>
|
|
230
|
-
{$level === 0 &&
|
|
203
|
+
{$level === 0 && (
|
|
231
204
|
<>
|
|
232
205
|
<UILabel style={{ marginTop: 10 }}>
|
|
233
|
-
{config?.defaultValueTitle ?? 'Default Value'}
|
|
206
|
+
{config?.defaultValueTitle ?? I18n.t('Default Value')}
|
|
234
207
|
</UILabel>
|
|
235
208
|
<DefaultValueWrapper>
|
|
236
209
|
<DefaultValue
|
|
237
210
|
value={defaultValue}
|
|
238
211
|
schema={value}
|
|
239
|
-
|
|
240
|
-
placeholder={config?.defaultValuePlaceholder}
|
|
241
|
-
jsonFormatText={config?.jsonFormatText}
|
|
212
|
+
placeholder={config?.defaultValuePlaceholder ?? I18n.t('Default Value')}
|
|
242
213
|
onChange={(value) => onChange('default', value)}
|
|
243
214
|
/>
|
|
244
215
|
</DefaultValueWrapper>
|
|
@@ -246,10 +217,10 @@ function PropertyEdit(props: {
|
|
|
246
217
|
)}
|
|
247
218
|
</UIExpandDetail>
|
|
248
219
|
)}
|
|
249
|
-
</
|
|
220
|
+
</UITreeItemMain>
|
|
250
221
|
{showCollapse && (
|
|
251
222
|
<UICollapsible $collapse={collapse}>
|
|
252
|
-
<
|
|
223
|
+
<UITreeItems $shrink={true}>
|
|
253
224
|
{propertyList.map((_property, index) => (
|
|
254
225
|
<PropertyEdit
|
|
255
226
|
readonly={readonly}
|
|
@@ -257,8 +228,6 @@ function PropertyEdit(props: {
|
|
|
257
228
|
value={_property}
|
|
258
229
|
config={config}
|
|
259
230
|
$level={$level + 1} // 传递递增的层级
|
|
260
|
-
$parentExpand={expand}
|
|
261
|
-
$parentType={type}
|
|
262
231
|
onChange={(_v) => {
|
|
263
232
|
onEditProperty(_property.key!, _v);
|
|
264
233
|
}}
|
|
@@ -266,15 +235,12 @@ function PropertyEdit(props: {
|
|
|
266
235
|
onRemoveProperty(_property.key!);
|
|
267
236
|
}}
|
|
268
237
|
$isLast={index === propertyList.length - 1}
|
|
269
|
-
$isFirst={index === 0}
|
|
270
|
-
$index={index}
|
|
271
|
-
$showLine={true}
|
|
272
238
|
/>
|
|
273
239
|
))}
|
|
274
|
-
</
|
|
240
|
+
</UITreeItems>
|
|
275
241
|
</UICollapsible>
|
|
276
242
|
)}
|
|
277
|
-
</
|
|
243
|
+
</UITreeItemRight>
|
|
278
244
|
</>
|
|
279
245
|
);
|
|
280
246
|
}
|
|
@@ -39,37 +39,30 @@ export const UILabel = styled.div`
|
|
|
39
39
|
margin-bottom: 2px;
|
|
40
40
|
`;
|
|
41
41
|
|
|
42
|
-
export const
|
|
42
|
+
export const UITreeItems = styled.div<{ $shrink?: boolean }>`
|
|
43
43
|
display: grid;
|
|
44
44
|
grid-template-columns: auto 1fr;
|
|
45
45
|
|
|
46
46
|
${({ $shrink }) =>
|
|
47
47
|
$shrink &&
|
|
48
48
|
css`
|
|
49
|
-
padding-left:
|
|
49
|
+
padding-left: 3px;
|
|
50
50
|
margin-top: 10px;
|
|
51
51
|
`}
|
|
52
52
|
`;
|
|
53
53
|
|
|
54
|
-
export const
|
|
54
|
+
export const UITreeItemLeft = styled.div<{
|
|
55
55
|
$isLast?: boolean;
|
|
56
56
|
$showLine?: boolean;
|
|
57
|
-
$
|
|
58
|
-
type?: string;
|
|
59
|
-
$isFirst?: boolean;
|
|
60
|
-
$index?: number;
|
|
61
|
-
$parentExpand?: boolean;
|
|
62
|
-
$parentType?: string;
|
|
57
|
+
$showCollapse?: boolean;
|
|
63
58
|
}>`
|
|
64
59
|
grid-column: 1;
|
|
65
60
|
position: relative;
|
|
66
61
|
width: 16px;
|
|
67
62
|
|
|
68
|
-
${({ $showLine, $isLast, $
|
|
69
|
-
let height = '100%';
|
|
70
|
-
|
|
71
|
-
height = '24px';
|
|
72
|
-
}
|
|
63
|
+
${({ $showLine, $isLast, $showCollapse }) => {
|
|
64
|
+
let height = $isLast ? '24px' : '100%';
|
|
65
|
+
let width = $showCollapse ? '12px' : '30px';
|
|
73
66
|
|
|
74
67
|
return (
|
|
75
68
|
$showLine &&
|
|
@@ -79,7 +72,7 @@ export const UIPropertyLeft = styled.div<{
|
|
|
79
72
|
content: '';
|
|
80
73
|
height: ${height};
|
|
81
74
|
position: absolute;
|
|
82
|
-
left: -
|
|
75
|
+
left: -14px;
|
|
83
76
|
top: -16px;
|
|
84
77
|
width: 1px;
|
|
85
78
|
background: #d9d9d9;
|
|
@@ -90,9 +83,9 @@ export const UIPropertyLeft = styled.div<{
|
|
|
90
83
|
/* 横线 */
|
|
91
84
|
content: '';
|
|
92
85
|
position: absolute;
|
|
93
|
-
left: -
|
|
86
|
+
left: -14px; // 横线起点和竖线对齐
|
|
94
87
|
top: 8px; // 跟随你的行高调整
|
|
95
|
-
width:
|
|
88
|
+
width: ${width}; // 横线长度
|
|
96
89
|
height: 1px;
|
|
97
90
|
background: #d9d9d9;
|
|
98
91
|
display: block;
|
|
@@ -102,7 +95,7 @@ export const UIPropertyLeft = styled.div<{
|
|
|
102
95
|
}}
|
|
103
96
|
`;
|
|
104
97
|
|
|
105
|
-
export const
|
|
98
|
+
export const UITreeItemRight = styled.div`
|
|
106
99
|
grid-column: 2;
|
|
107
100
|
margin-bottom: 10px;
|
|
108
101
|
|
|
@@ -111,47 +104,11 @@ export const UIPropertyRight = styled.div`
|
|
|
111
104
|
}
|
|
112
105
|
`;
|
|
113
106
|
|
|
114
|
-
export const
|
|
115
|
-
$expand?: boolean;
|
|
116
|
-
type?: string;
|
|
117
|
-
$collapse?: boolean;
|
|
118
|
-
$showCollapse?: boolean;
|
|
119
|
-
}>`
|
|
107
|
+
export const UITreeItemMain = styled.div<{}>`
|
|
120
108
|
display: flex;
|
|
121
109
|
flex-direction: column;
|
|
122
110
|
gap: 10px;
|
|
123
111
|
position: relative;
|
|
124
|
-
|
|
125
|
-
${({ $expand, type, $collapse, $showCollapse }) => {
|
|
126
|
-
const beforeElement = `
|
|
127
|
-
&::before {
|
|
128
|
-
/* 竖线 */
|
|
129
|
-
content: '';
|
|
130
|
-
height: 100%;
|
|
131
|
-
position: absolute;
|
|
132
|
-
left: -12px;
|
|
133
|
-
top: 18px;
|
|
134
|
-
width: 1px;
|
|
135
|
-
background: #d9d9d9;
|
|
136
|
-
display: block;
|
|
137
|
-
}`;
|
|
138
|
-
|
|
139
|
-
return (
|
|
140
|
-
$expand &&
|
|
141
|
-
css`
|
|
142
|
-
background-color: #f5f5f5;
|
|
143
|
-
padding: 10px;
|
|
144
|
-
border-radius: 4px;
|
|
145
|
-
|
|
146
|
-
${$showCollapse &&
|
|
147
|
-
$collapse &&
|
|
148
|
-
(type === 'array' || type === 'object') &&
|
|
149
|
-
css`
|
|
150
|
-
${beforeElement}
|
|
151
|
-
`}
|
|
152
|
-
`
|
|
153
|
-
);
|
|
154
|
-
}}
|
|
155
112
|
`;
|
|
156
113
|
|
|
157
114
|
export const UICollapsible = styled.div<{ $collapse?: boolean }>`
|
|
@@ -200,35 +157,6 @@ export const DefaultValueWrapper = styled.div`
|
|
|
200
157
|
margin: 0;
|
|
201
158
|
`;
|
|
202
159
|
|
|
203
|
-
export const JSONViewerWrapper = styled.div`
|
|
204
|
-
padding: 0 0 24px;
|
|
205
|
-
&:first-child {
|
|
206
|
-
margin-top: 0px;
|
|
207
|
-
}
|
|
208
|
-
`;
|
|
209
|
-
|
|
210
|
-
export const JSONHeader = styled.div`
|
|
211
|
-
display: flex;
|
|
212
|
-
justify-content: space-between;
|
|
213
|
-
align-items: center;
|
|
214
|
-
background-color: var(--semi-color-fill-0);
|
|
215
|
-
border-radius: 6px 6px 0 0;
|
|
216
|
-
height: 36px;
|
|
217
|
-
padding: 0 8px 0 12px;
|
|
218
|
-
`;
|
|
219
|
-
|
|
220
|
-
export const JSONHeaderLeft = styled.div`
|
|
221
|
-
display: flex;
|
|
222
|
-
align-items: center;
|
|
223
|
-
gap: 10px;
|
|
224
|
-
`;
|
|
225
|
-
|
|
226
|
-
export const JSONHeaderRight = styled.div`
|
|
227
|
-
display: flex;
|
|
228
|
-
align-items: center;
|
|
229
|
-
gap: 10px;
|
|
230
|
-
`;
|
|
231
|
-
|
|
232
160
|
export const ConstantInputWrapper = styled.div`
|
|
233
161
|
flex-grow: 1;
|
|
234
162
|
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React, { useEffect, useRef } from 'react';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
Renderer,
|
|
10
|
+
EditorProvider,
|
|
11
|
+
ActiveLinePlaceholder,
|
|
12
|
+
InferValues,
|
|
13
|
+
} from '@coze-editor/editor/react';
|
|
14
|
+
import preset, { EditorAPI } from '@coze-editor/editor/preset-prompt';
|
|
15
|
+
|
|
16
|
+
import { PropsType } from './types';
|
|
17
|
+
import { UIContainer } from './styles';
|
|
18
|
+
import MarkdownHighlight from './extensions/markdown';
|
|
19
|
+
import LanguageSupport from './extensions/language-support';
|
|
20
|
+
import JinjaHighlight from './extensions/jinja';
|
|
21
|
+
|
|
22
|
+
type Preset = typeof preset;
|
|
23
|
+
type Options = Partial<InferValues<Preset[number]>>;
|
|
24
|
+
|
|
25
|
+
export interface PromptEditorPropsType extends PropsType {
|
|
26
|
+
options?: Options;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function PromptEditor(props: PromptEditorPropsType) {
|
|
30
|
+
const {
|
|
31
|
+
value,
|
|
32
|
+
onChange,
|
|
33
|
+
readonly,
|
|
34
|
+
placeholder,
|
|
35
|
+
activeLinePlaceholder,
|
|
36
|
+
style,
|
|
37
|
+
hasError,
|
|
38
|
+
children,
|
|
39
|
+
disableMarkdownHighlight,
|
|
40
|
+
options,
|
|
41
|
+
} = props || {};
|
|
42
|
+
|
|
43
|
+
const editorRef = useRef<EditorAPI | null>(null);
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
// listen to value change
|
|
47
|
+
if (editorRef.current?.getValue() !== value?.content) {
|
|
48
|
+
editorRef.current?.setValue(String(value?.content || ''));
|
|
49
|
+
}
|
|
50
|
+
}, [value]);
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<UIContainer $hasError={hasError} style={style}>
|
|
54
|
+
<EditorProvider>
|
|
55
|
+
<Renderer
|
|
56
|
+
didMount={(editor: EditorAPI) => {
|
|
57
|
+
editorRef.current = editor;
|
|
58
|
+
}}
|
|
59
|
+
plugins={preset}
|
|
60
|
+
defaultValue={String(value?.content)}
|
|
61
|
+
options={{
|
|
62
|
+
readOnly: readonly,
|
|
63
|
+
editable: !readonly,
|
|
64
|
+
placeholder,
|
|
65
|
+
...options,
|
|
66
|
+
}}
|
|
67
|
+
onChange={(e) => {
|
|
68
|
+
onChange({ type: 'template', content: e.value });
|
|
69
|
+
}}
|
|
70
|
+
/>
|
|
71
|
+
{activeLinePlaceholder && (
|
|
72
|
+
<ActiveLinePlaceholder>{activeLinePlaceholder}</ActiveLinePlaceholder>
|
|
73
|
+
)}
|
|
74
|
+
{!disableMarkdownHighlight && <MarkdownHighlight />}
|
|
75
|
+
<LanguageSupport />
|
|
76
|
+
<JinjaHighlight />
|
|
77
|
+
{children}
|
|
78
|
+
</EditorProvider>
|
|
79
|
+
</UIContainer>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
@@ -3,67 +3,10 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import { lazySuspense } from '@/shared';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
import
|
|
8
|
+
export const PromptEditor = lazySuspense(() =>
|
|
9
|
+
import('./editor').then((module) => ({ default: module.PromptEditor }))
|
|
10
|
+
);
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
import { UIContainer } from './styles';
|
|
13
|
-
import MarkdownHighlight from './extensions/markdown';
|
|
14
|
-
import LanguageSupport from './extensions/language-support';
|
|
15
|
-
import JinjaHighlight from './extensions/jinja';
|
|
16
|
-
|
|
17
|
-
export type PromptEditorPropsType = PropsType;
|
|
18
|
-
|
|
19
|
-
export function PromptEditor(props: PropsType) {
|
|
20
|
-
const {
|
|
21
|
-
value,
|
|
22
|
-
onChange,
|
|
23
|
-
readonly,
|
|
24
|
-
placeholder,
|
|
25
|
-
activeLinePlaceholder,
|
|
26
|
-
style,
|
|
27
|
-
hasError,
|
|
28
|
-
children,
|
|
29
|
-
disableMarkdownHighlight,
|
|
30
|
-
} = props || {};
|
|
31
|
-
|
|
32
|
-
const editorRef = useRef<EditorAPI | null>(null);
|
|
33
|
-
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
// listen to value change
|
|
36
|
-
if (editorRef.current?.getValue() !== value?.content) {
|
|
37
|
-
editorRef.current?.setValue(String(value?.content || ''));
|
|
38
|
-
}
|
|
39
|
-
}, [value]);
|
|
40
|
-
|
|
41
|
-
return (
|
|
42
|
-
<UIContainer $hasError={hasError} style={style}>
|
|
43
|
-
<EditorProvider>
|
|
44
|
-
<Renderer
|
|
45
|
-
didMount={(editor: EditorAPI) => {
|
|
46
|
-
editorRef.current = editor;
|
|
47
|
-
}}
|
|
48
|
-
plugins={preset}
|
|
49
|
-
defaultValue={String(value?.content)}
|
|
50
|
-
options={{
|
|
51
|
-
readOnly: readonly,
|
|
52
|
-
editable: !readonly,
|
|
53
|
-
placeholder,
|
|
54
|
-
}}
|
|
55
|
-
onChange={(e) => {
|
|
56
|
-
onChange({ type: 'template', content: e.value });
|
|
57
|
-
}}
|
|
58
|
-
/>
|
|
59
|
-
{activeLinePlaceholder && (
|
|
60
|
-
<ActiveLinePlaceholder>{activeLinePlaceholder}</ActiveLinePlaceholder>
|
|
61
|
-
)}
|
|
62
|
-
{!disableMarkdownHighlight && <MarkdownHighlight />}
|
|
63
|
-
<LanguageSupport />
|
|
64
|
-
<JinjaHighlight />
|
|
65
|
-
{children}
|
|
66
|
-
</EditorProvider>
|
|
67
|
-
</UIContainer>
|
|
68
|
-
);
|
|
69
|
-
}
|
|
12
|
+
export type { PromptEditorPropsType } from './editor';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
8
|
+
import { PromptEditor, PromptEditorPropsType } from '@/components/prompt-editor';
|
|
9
|
+
|
|
10
|
+
import { InputsTree } from './extensions/inputs-tree';
|
|
11
|
+
|
|
12
|
+
export interface PromptEditorWithInputsProps extends PromptEditorPropsType {
|
|
13
|
+
inputsValues: any;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function PromptEditorWithInputs({
|
|
17
|
+
inputsValues,
|
|
18
|
+
...restProps
|
|
19
|
+
}: PromptEditorWithInputsProps) {
|
|
20
|
+
return (
|
|
21
|
+
<PromptEditor {...restProps}>
|
|
22
|
+
<InputsTree inputsValues={inputsValues} />
|
|
23
|
+
</PromptEditor>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -15,8 +15,9 @@ import {
|
|
|
15
15
|
} from '@coze-editor/editor/react';
|
|
16
16
|
import { EditorAPI } from '@coze-editor/editor/preset-prompt';
|
|
17
17
|
|
|
18
|
+
import { IFlowValue } from '@/typings';
|
|
19
|
+
|
|
18
20
|
import { InputsPicker } from '../inputs-picker';
|
|
19
|
-
import { IFlowValue } from '../../../typings';
|
|
20
21
|
|
|
21
22
|
export function InputsTree({ inputsValues }: { inputsValues: Record<string, IFlowValue> }) {
|
|
22
23
|
const [posKey, setPosKey] = useState('');
|
|
@@ -31,6 +32,17 @@ export function InputsTree({ inputsValues }: { inputsValues: Record<string, IFlo
|
|
|
31
32
|
return;
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
/**
|
|
36
|
+
* When user input {{xxxx}}, {{{xxx}}}(more brackets if possible), replace all brackets with {{xxxx}}
|
|
37
|
+
*/
|
|
38
|
+
let { from, to } = range;
|
|
39
|
+
while (editor.$view.state.doc.sliceString(from - 1, from) === '{') {
|
|
40
|
+
from--;
|
|
41
|
+
}
|
|
42
|
+
while (editor.$view.state.doc.sliceString(to, to + 1) === '}') {
|
|
43
|
+
to++;
|
|
44
|
+
}
|
|
45
|
+
|
|
34
46
|
editor.replaceText({
|
|
35
47
|
...range,
|
|
36
48
|
text: '{{' + variablePath + '}}',
|
|
@@ -3,20 +3,10 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import { lazySuspense } from '@/shared';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
|
|
8
|
+
export const PromptEditorWithInputs = lazySuspense(() =>
|
|
9
|
+
import('./editor').then((module) => ({ default: module.PromptEditorWithInputs }))
|
|
10
|
+
);
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
inputsValues: Record<string, IFlowValue>;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function PromptEditorWithInputs({ inputsValues, ...restProps }: PropsType) {
|
|
17
|
-
return (
|
|
18
|
-
<PromptEditor {...restProps}>
|
|
19
|
-
<InputsTree inputsValues={inputsValues} />
|
|
20
|
-
</PromptEditor>
|
|
21
|
-
);
|
|
22
|
-
}
|
|
12
|
+
export type { PromptEditorWithInputsProps } from './editor';
|