@flowgram.ai/form-materials 0.1.0-alpha.11 → 0.1.0-alpha.13
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 +14 -22
- package/bin/materials.ts +41 -90
- package/bin/project.ts +4 -0
- package/bin/utils/import.ts +127 -0
- package/bin/utils/traverse-file.ts +60 -0
- package/dist/esm/index.js +2073 -1601
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +392 -131
- package/dist/index.d.ts +392 -131
- package/dist/index.js +2175 -1710
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/src/components/assign-row/components/blur-input.tsx +27 -0
- package/src/components/assign-row/index.tsx +84 -0
- package/src/components/assign-row/types.ts +25 -0
- package/src/components/assign-rows/index.tsx +59 -0
- package/src/components/batch-outputs/index.tsx +7 -14
- package/src/components/batch-outputs/types.ts +1 -1
- package/src/components/batch-variable-selector/index.tsx +2 -2
- package/src/components/code-editor/index.tsx +7 -0
- package/src/components/code-editor/language-features.ts +22 -1
- package/src/components/code-editor/theme/light.ts +1 -1
- package/src/components/code-editor-mini/index.tsx +31 -0
- package/src/components/condition-row/constants.ts +8 -10
- package/src/components/condition-row/hooks/useOp.tsx +15 -9
- package/src/components/condition-row/hooks/useRule.ts +9 -5
- package/src/components/condition-row/index.tsx +28 -10
- package/src/components/condition-row/types.ts +5 -5
- package/src/components/constant-input/index.tsx +20 -61
- package/src/components/constant-input/types.ts +6 -9
- package/src/components/display-flow-value/index.tsx +59 -0
- package/src/components/display-inputs-values/index.tsx +28 -0
- package/src/components/display-inputs-values/styles.ts +12 -0
- package/src/components/display-outputs/index.tsx +65 -0
- package/src/components/display-outputs/styles.ts +12 -0
- package/src/components/display-schema-tag/index.tsx +45 -0
- package/src/components/display-schema-tag/styles.ts +28 -0
- package/src/components/display-schema-tree/index.tsx +75 -0
- package/src/components/display-schema-tree/styles.tsx +90 -0
- package/src/components/dynamic-value-input/hooks.ts +53 -0
- package/src/components/dynamic-value-input/index.tsx +74 -19
- package/src/components/dynamic-value-input/styles.tsx +28 -2
- package/src/components/index.ts +9 -0
- package/src/components/inputs-values/components/blur-input.tsx +27 -0
- package/src/components/inputs-values/index.tsx +75 -0
- package/src/components/inputs-values/styles.tsx +19 -0
- package/src/components/inputs-values/types.ts +22 -0
- package/src/components/json-editor-with-variables/extensions/variable-tree.tsx +1 -1
- package/src/components/json-editor-with-variables/index.tsx +2 -1
- package/src/components/json-schema-editor/default-value.tsx +12 -106
- package/src/components/json-schema-editor/hooks.tsx +53 -94
- package/src/components/json-schema-editor/index.tsx +32 -13
- package/src/components/json-schema-editor/styles.tsx +0 -29
- package/src/components/json-schema-editor/types.ts +1 -1
- package/src/components/prompt-editor/types.tsx +1 -1
- package/src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx +2 -1
- package/src/components/prompt-editor-with-inputs/index.tsx +3 -2
- package/src/components/prompt-editor-with-inputs/inputs-picker.tsx +2 -2
- package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +6 -3
- package/src/components/prompt-editor-with-variables/extensions/variable-tree.tsx +1 -1
- package/src/components/prompt-editor-with-variables/index.tsx +2 -1
- package/src/components/type-selector/index.tsx +58 -13
- package/src/components/variable-selector/index.tsx +42 -17
- package/src/components/variable-selector/styles.tsx +18 -8
- package/src/components/variable-selector/use-variable-tree.tsx +19 -22
- package/src/effects/auto-rename-ref/index.ts +1 -1
- package/src/effects/index.ts +3 -1
- package/src/effects/listen-ref-schema-change/index.ts +56 -0
- package/src/effects/listen-ref-value-change/index.ts +53 -0
- package/src/effects/provide-batch-input/index.ts +1 -1
- package/src/effects/provide-json-schema-outputs/index.ts +1 -3
- package/src/effects/sync-variable-title/index.ts +1 -0
- package/src/effects/validate-when-variable-sync/index.ts +35 -0
- package/src/form-plugins/batch-outputs-plugin/index.ts +1 -1
- package/src/form-plugins/index.ts +3 -1
- package/src/form-plugins/infer-assign-plugin/index.ts +90 -0
- package/src/form-plugins/infer-inputs-plugin/index.ts +108 -0
- package/src/hooks/index.tsx +6 -0
- package/src/hooks/use-object-list/index.tsx +136 -0
- package/src/index.ts +3 -1
- package/src/{utils/format-legacy-refs → plugins/disable-declaration-plugin}/config.json +1 -1
- package/src/plugins/disable-declaration-plugin/create-disable-declaration-plugin.ts +31 -0
- package/src/plugins/disable-declaration-plugin/index.tsx +6 -0
- package/src/plugins/index.ts +7 -0
- package/src/plugins/json-schema-preset/config.json +9 -0
- package/src/plugins/json-schema-preset/create-type-preset-plugin.tsx +28 -0
- package/src/plugins/json-schema-preset/index.tsx +41 -0
- package/src/plugins/json-schema-preset/manager.ts +18 -0
- package/src/plugins/json-schema-preset/type-definition/array.tsx +26 -0
- package/src/plugins/json-schema-preset/type-definition/boolean.tsx +33 -0
- package/src/plugins/json-schema-preset/type-definition/index.tsx +24 -0
- package/src/plugins/json-schema-preset/type-definition/integer.tsx +25 -0
- package/src/plugins/json-schema-preset/type-definition/number.tsx +25 -0
- package/src/plugins/json-schema-preset/type-definition/object.tsx +26 -0
- package/src/plugins/json-schema-preset/type-definition/string.tsx +24 -0
- package/src/{utils → shared}/index.ts +1 -1
- 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/typings/flow-value/index.ts +11 -0
- package/src/typings/index.ts +0 -1
- package/src/validate/index.tsx +6 -0
- package/src/validate/validate-flow-value/index.tsx +73 -0
- package/src/components/batch-outputs/config.json +0 -12
- package/src/components/batch-outputs/use-list.ts +0 -86
- package/src/components/batch-variable-selector/config.json +0 -5
- package/src/components/code-editor/config.json +0 -10
- package/src/components/condition-row/config.json +0 -5
- package/src/components/constant-input/config.json +0 -6
- package/src/components/dynamic-value-input/config.json +0 -5
- package/src/components/json-editor-with-variables/config.json +0 -13
- 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 -5
- package/src/components/type-selector/constants.tsx +0 -364
- package/src/components/variable-selector/config.json +0 -5
- package/src/effects/auto-rename-ref/config.json +0 -5
- package/src/effects/provide-batch-input/config.json +0 -5
- package/src/effects/provide-batch-outputs/config.json +0 -5
- package/src/effects/provide-batch-outputs/index.ts +0 -38
- package/src/effects/provide-json-schema-outputs/config.json +0 -8
- package/src/effects/sync-variable-title/config.json +0 -5
- package/src/form-plugins/batch-outputs-plugin/config.json +0 -7
- package/src/typings/flow-value/config.json +0 -5
- package/src/typings/json-schema/config.json +0 -5
- package/src/typings/json-schema/index.ts +0 -36
- package/src/utils/json-schema/config.json +0 -5
- package/src/utils/json-schema/index.ts +0 -180
- /package/src/{utils → shared}/format-legacy-refs/index.ts +0 -0
- /package/src/{utils → shared}/format-legacy-refs/readme.md +0 -0
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { useEffect,
|
|
6
|
+
import { useEffect, useState } from 'react';
|
|
7
7
|
|
|
8
|
-
import { omit } from 'lodash';
|
|
8
|
+
import { difference, omit } from 'lodash';
|
|
9
|
+
import { produce } from 'immer';
|
|
10
|
+
import { IJsonSchema, type JsonSchemaTypeManager, useTypeManager } from '@flowgram.ai/json-schema';
|
|
9
11
|
|
|
10
|
-
import { IJsonSchema } from '../../typings';
|
|
11
12
|
import { PropertyValueType } from './types';
|
|
12
13
|
|
|
13
14
|
let _id = 0;
|
|
@@ -15,92 +16,46 @@ function genId() {
|
|
|
15
16
|
return _id++;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
function getDrilldownSchema(
|
|
19
|
-
value?: PropertyValueType,
|
|
20
|
-
path?: (keyof PropertyValueType)[]
|
|
21
|
-
): { schema?: PropertyValueType | null; path?: (keyof PropertyValueType)[] } {
|
|
22
|
-
if (!value) {
|
|
23
|
-
return {};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (value.type === 'array' && value.items) {
|
|
27
|
-
return getDrilldownSchema(value.items, [...(path || []), 'items']);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return { schema: value, path };
|
|
31
|
-
}
|
|
32
|
-
|
|
33
19
|
export function usePropertiesEdit(
|
|
34
20
|
value?: PropertyValueType,
|
|
35
21
|
onChange?: (value: PropertyValueType) => void
|
|
36
22
|
) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
() =>
|
|
45
|
-
isDrilldownObject
|
|
46
|
-
? Object.entries(drilldown.schema?.properties || {})
|
|
47
|
-
.sort(([, a], [, b]) => (a.extra?.index ?? 0) - (b.extra?.index ?? 0))
|
|
48
|
-
.map(
|
|
49
|
-
([name, _value], index) =>
|
|
50
|
-
({
|
|
51
|
-
key: genId(),
|
|
52
|
-
name,
|
|
53
|
-
isPropertyRequired: drilldown.schema?.required?.includes(name) || false,
|
|
54
|
-
..._value,
|
|
55
|
-
extra: {
|
|
56
|
-
...(_value.extra || {}),
|
|
57
|
-
index,
|
|
58
|
-
},
|
|
59
|
-
} as PropertyValueType)
|
|
60
|
-
)
|
|
61
|
-
: [],
|
|
62
|
-
[isDrilldownObject]
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
const [propertyList, setPropertyList] = useState<PropertyValueType[]>(initPropertyList);
|
|
66
|
-
|
|
67
|
-
const mountRef = useRef(false);
|
|
23
|
+
const typeManager = useTypeManager() as JsonSchemaTypeManager;
|
|
24
|
+
|
|
25
|
+
// Get drilldown properties (array.items.items.properties...)
|
|
26
|
+
const drilldownSchema = typeManager.getPropertiesParent(value || {});
|
|
27
|
+
const canAddField = typeManager.canAddField(value || {});
|
|
28
|
+
|
|
29
|
+
const [propertyList, setPropertyList] = useState<PropertyValueType[]>([]);
|
|
68
30
|
|
|
69
31
|
useEffect(() => {
|
|
70
|
-
// If
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
.
|
|
83
|
-
.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
..._value,
|
|
98
|
-
};
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
mountRef.current = true;
|
|
103
|
-
}, [drilldown.schema]);
|
|
32
|
+
// If the value is changed, update the property list
|
|
33
|
+
setPropertyList((_list) => {
|
|
34
|
+
const newNames = Object.entries(drilldownSchema?.properties || {})
|
|
35
|
+
.sort(([, a], [, b]) => (a.extra?.index ?? 0) - (b.extra?.index ?? 0))
|
|
36
|
+
.map(([key]) => key);
|
|
37
|
+
|
|
38
|
+
const oldNames = _list.map((item) => item.name).filter(Boolean) as string[];
|
|
39
|
+
const addNames = difference(newNames, oldNames);
|
|
40
|
+
|
|
41
|
+
return _list
|
|
42
|
+
.filter((item) => !item.name || newNames.includes(item.name))
|
|
43
|
+
.map((item) => ({
|
|
44
|
+
key: item.key,
|
|
45
|
+
name: item.name,
|
|
46
|
+
isPropertyRequired: drilldownSchema?.required?.includes(item.name || '') || false,
|
|
47
|
+
...item,
|
|
48
|
+
}))
|
|
49
|
+
.concat(
|
|
50
|
+
addNames.map((_name) => ({
|
|
51
|
+
key: genId(),
|
|
52
|
+
name: _name,
|
|
53
|
+
isPropertyRequired: drilldownSchema?.required?.includes(_name) || false,
|
|
54
|
+
...(drilldownSchema?.properties?.[_name] || {}),
|
|
55
|
+
}))
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
}, [drilldownSchema]);
|
|
104
59
|
|
|
105
60
|
const updatePropertyList = (updater: (list: PropertyValueType[]) => PropertyValueType[]) => {
|
|
106
61
|
setPropertyList((_list) => {
|
|
@@ -122,21 +77,25 @@ export function usePropertiesEdit(
|
|
|
122
77
|
}
|
|
123
78
|
}
|
|
124
79
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
drilldownSchema.properties = nextProperties;
|
|
130
|
-
drilldownSchema.required = nextRequired;
|
|
80
|
+
onChange?.(
|
|
81
|
+
produce(value || {}, (draft) => {
|
|
82
|
+
const propertiesParent = typeManager.getPropertiesParent(draft);
|
|
131
83
|
|
|
132
|
-
|
|
84
|
+
if (propertiesParent) {
|
|
85
|
+
propertiesParent.properties = nextProperties;
|
|
86
|
+
propertiesParent.required = nextRequired;
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
);
|
|
133
91
|
|
|
134
92
|
return next;
|
|
135
93
|
});
|
|
136
94
|
};
|
|
137
95
|
|
|
138
96
|
const onAddProperty = () => {
|
|
139
|
-
|
|
97
|
+
// set property list only, not trigger updatePropertyList
|
|
98
|
+
setPropertyList((_list) => [
|
|
140
99
|
..._list,
|
|
141
100
|
{ key: genId(), name: '', type: 'string', extra: { index: _list.length + 1 } },
|
|
142
101
|
]);
|
|
@@ -153,14 +112,14 @@ export function usePropertiesEdit(
|
|
|
153
112
|
};
|
|
154
113
|
|
|
155
114
|
useEffect(() => {
|
|
156
|
-
if (!
|
|
115
|
+
if (!canAddField) {
|
|
157
116
|
setPropertyList([]);
|
|
158
117
|
}
|
|
159
|
-
}, [
|
|
118
|
+
}, [canAddField]);
|
|
160
119
|
|
|
161
120
|
return {
|
|
162
121
|
propertyList,
|
|
163
|
-
|
|
122
|
+
canAddField,
|
|
164
123
|
onAddProperty,
|
|
165
124
|
onRemoveProperty,
|
|
166
125
|
onEditProperty,
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
import React, { useMemo, useState } from 'react';
|
|
7
7
|
|
|
8
|
+
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
9
|
+
import { I18n } from '@flowgram.ai/editor';
|
|
8
10
|
import { Button, Checkbox, IconButton } from '@douyinfe/semi-ui';
|
|
9
11
|
import {
|
|
10
12
|
IconExpand,
|
|
@@ -15,8 +17,8 @@ import {
|
|
|
15
17
|
IconMinus,
|
|
16
18
|
} from '@douyinfe/semi-icons';
|
|
17
19
|
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
+
import { InjectTypeSelector } from '@/components/type-selector';
|
|
21
|
+
|
|
20
22
|
import { ConfigType, PropertyValueType } from './types';
|
|
21
23
|
import {
|
|
22
24
|
IconAddChildren,
|
|
@@ -39,13 +41,16 @@ import { usePropertiesEdit } from './hooks';
|
|
|
39
41
|
import { DefaultValue } from './default-value';
|
|
40
42
|
import { BlurInput } from './components/blur-input';
|
|
41
43
|
|
|
44
|
+
const DEFAULT = { type: 'object' };
|
|
45
|
+
|
|
42
46
|
export function JsonSchemaEditor(props: {
|
|
43
47
|
value?: IJsonSchema;
|
|
44
48
|
onChange?: (value: IJsonSchema) => void;
|
|
45
49
|
config?: ConfigType;
|
|
46
50
|
className?: string;
|
|
51
|
+
readonly?: boolean;
|
|
47
52
|
}) {
|
|
48
|
-
const { value =
|
|
53
|
+
const { value = DEFAULT, config = {}, onChange: onChangeProps, readonly } = props;
|
|
49
54
|
const { propertyList, onAddProperty, onRemoveProperty, onEditProperty } = usePropertiesEdit(
|
|
50
55
|
value,
|
|
51
56
|
onChangeProps
|
|
@@ -56,6 +61,7 @@ export function JsonSchemaEditor(props: {
|
|
|
56
61
|
<UIProperties>
|
|
57
62
|
{propertyList.map((_property, index) => (
|
|
58
63
|
<PropertyEdit
|
|
64
|
+
readonly={readonly}
|
|
59
65
|
key={_property.key}
|
|
60
66
|
value={_property}
|
|
61
67
|
config={config}
|
|
@@ -70,12 +76,13 @@ export function JsonSchemaEditor(props: {
|
|
|
70
76
|
))}
|
|
71
77
|
</UIProperties>
|
|
72
78
|
<Button
|
|
79
|
+
disabled={readonly}
|
|
73
80
|
size="small"
|
|
74
81
|
style={{ marginTop: 10, marginLeft: 16 }}
|
|
75
82
|
icon={<IconPlus />}
|
|
76
83
|
onClick={onAddProperty}
|
|
77
84
|
>
|
|
78
|
-
{config?.addButtonText ?? 'Add'}
|
|
85
|
+
{config?.addButtonText ?? I18n.t('Add')}
|
|
79
86
|
</Button>
|
|
80
87
|
</UIContainer>
|
|
81
88
|
);
|
|
@@ -86,6 +93,7 @@ function PropertyEdit(props: {
|
|
|
86
93
|
config?: ConfigType;
|
|
87
94
|
onChange?: (value: PropertyValueType) => void;
|
|
88
95
|
onRemove?: () => void;
|
|
96
|
+
readonly?: boolean;
|
|
89
97
|
$isLast?: boolean;
|
|
90
98
|
$index?: number;
|
|
91
99
|
$isFirst?: boolean;
|
|
@@ -97,6 +105,7 @@ function PropertyEdit(props: {
|
|
|
97
105
|
const {
|
|
98
106
|
value,
|
|
99
107
|
config,
|
|
108
|
+
readonly,
|
|
100
109
|
$level = 0,
|
|
101
110
|
onChange: onChangeProps,
|
|
102
111
|
onRemove,
|
|
@@ -115,7 +124,7 @@ function PropertyEdit(props: {
|
|
|
115
124
|
|
|
116
125
|
const typeSelectorValue = useMemo(() => ({ type, items }), [type, items]);
|
|
117
126
|
|
|
118
|
-
const { propertyList,
|
|
127
|
+
const { propertyList, canAddField, onAddProperty, onRemoveProperty, onEditProperty } =
|
|
119
128
|
usePropertiesEdit(value, onChangeProps);
|
|
120
129
|
|
|
121
130
|
const onChange = (key: string, _value: any) => {
|
|
@@ -125,7 +134,7 @@ function PropertyEdit(props: {
|
|
|
125
134
|
});
|
|
126
135
|
};
|
|
127
136
|
|
|
128
|
-
const showCollapse =
|
|
137
|
+
const showCollapse = canAddField && propertyList.length > 0;
|
|
129
138
|
|
|
130
139
|
return (
|
|
131
140
|
<>
|
|
@@ -155,6 +164,7 @@ function PropertyEdit(props: {
|
|
|
155
164
|
<UIRow>
|
|
156
165
|
<UIName>
|
|
157
166
|
<BlurInput
|
|
167
|
+
disabled={readonly}
|
|
158
168
|
placeholder={config?.placeholder ?? 'Input Variable Name'}
|
|
159
169
|
size="small"
|
|
160
170
|
value={name}
|
|
@@ -162,8 +172,9 @@ function PropertyEdit(props: {
|
|
|
162
172
|
/>
|
|
163
173
|
</UIName>
|
|
164
174
|
<UIType>
|
|
165
|
-
<
|
|
175
|
+
<InjectTypeSelector
|
|
166
176
|
value={typeSelectorValue}
|
|
177
|
+
readonly={readonly}
|
|
167
178
|
onChange={(_value) => {
|
|
168
179
|
onChangeProps?.({
|
|
169
180
|
...(value || {}),
|
|
@@ -174,12 +185,14 @@ function PropertyEdit(props: {
|
|
|
174
185
|
</UIType>
|
|
175
186
|
<UIRequired>
|
|
176
187
|
<Checkbox
|
|
188
|
+
disabled={readonly}
|
|
177
189
|
checked={isPropertyRequired}
|
|
178
190
|
onChange={(e) => onChange('isPropertyRequired', e.target.checked)}
|
|
179
191
|
/>
|
|
180
192
|
</UIRequired>
|
|
181
193
|
<UIActions>
|
|
182
194
|
<IconButton
|
|
195
|
+
disabled={readonly}
|
|
183
196
|
size="small"
|
|
184
197
|
theme="borderless"
|
|
185
198
|
icon={expand ? <IconShrink size="small" /> : <IconExpand size="small" />}
|
|
@@ -187,8 +200,9 @@ function PropertyEdit(props: {
|
|
|
187
200
|
setExpand((_expand) => !_expand);
|
|
188
201
|
}}
|
|
189
202
|
/>
|
|
190
|
-
{
|
|
203
|
+
{canAddField && (
|
|
191
204
|
<IconButton
|
|
205
|
+
disabled={readonly}
|
|
192
206
|
size="small"
|
|
193
207
|
theme="borderless"
|
|
194
208
|
icon={<IconAddChildren />}
|
|
@@ -199,6 +213,7 @@ function PropertyEdit(props: {
|
|
|
199
213
|
/>
|
|
200
214
|
)}
|
|
201
215
|
<IconButton
|
|
216
|
+
disabled={readonly}
|
|
202
217
|
size="small"
|
|
203
218
|
theme="borderless"
|
|
204
219
|
icon={<IconMinus size="small" />}
|
|
@@ -208,24 +223,27 @@ function PropertyEdit(props: {
|
|
|
208
223
|
</UIRow>
|
|
209
224
|
{expand && (
|
|
210
225
|
<UIExpandDetail>
|
|
211
|
-
<UILabel>{config?.descTitle ?? 'Description'}</UILabel>
|
|
226
|
+
<UILabel>{config?.descTitle ?? I18n.t('Description')}</UILabel>
|
|
212
227
|
<BlurInput
|
|
228
|
+
disabled={readonly}
|
|
213
229
|
size="small"
|
|
214
230
|
value={description}
|
|
215
231
|
onChange={(value) => onChange('description', value)}
|
|
216
|
-
placeholder={
|
|
232
|
+
placeholder={
|
|
233
|
+
config?.descPlaceholder ?? I18n.t('Help LLM to understand the property')
|
|
234
|
+
}
|
|
217
235
|
/>
|
|
218
|
-
{$level === 0 &&
|
|
236
|
+
{$level === 0 && (
|
|
219
237
|
<>
|
|
220
238
|
<UILabel style={{ marginTop: 10 }}>
|
|
221
|
-
{config?.defaultValueTitle ?? 'Default Value'}
|
|
239
|
+
{config?.defaultValueTitle ?? I18n.t('Default Value')}
|
|
222
240
|
</UILabel>
|
|
223
241
|
<DefaultValueWrapper>
|
|
224
242
|
<DefaultValue
|
|
225
243
|
value={defaultValue}
|
|
226
244
|
schema={value}
|
|
227
245
|
type={type}
|
|
228
|
-
placeholder={config?.defaultValuePlaceholder}
|
|
246
|
+
placeholder={config?.defaultValuePlaceholder ?? I18n.t('Default Value')}
|
|
229
247
|
jsonFormatText={config?.jsonFormatText}
|
|
230
248
|
onChange={(value) => onChange('default', value)}
|
|
231
249
|
/>
|
|
@@ -240,6 +258,7 @@ function PropertyEdit(props: {
|
|
|
240
258
|
<UIProperties $shrink={true}>
|
|
241
259
|
{propertyList.map((_property, index) => (
|
|
242
260
|
<PropertyEdit
|
|
261
|
+
readonly={readonly}
|
|
243
262
|
key={_property.key}
|
|
244
263
|
value={_property}
|
|
245
264
|
config={config}
|
|
@@ -200,35 +200,6 @@ export const DefaultValueWrapper = styled.div`
|
|
|
200
200
|
margin: 0;
|
|
201
201
|
`;
|
|
202
202
|
|
|
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
203
|
export const ConstantInputWrapper = styled.div`
|
|
233
204
|
flex-grow: 1;
|
|
234
205
|
|
|
@@ -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('');
|
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
|
+
import { IFlowValue } from '@/typings';
|
|
9
|
+
import { PromptEditor, PromptEditorPropsType } from '@/components/prompt-editor';
|
|
10
|
+
|
|
8
11
|
import { InputsTree } from './extensions/inputs-tree';
|
|
9
|
-
import { PromptEditor, PromptEditorPropsType } from '../prompt-editor';
|
|
10
|
-
import { IFlowValue } from '../../typings';
|
|
11
12
|
|
|
12
13
|
interface PropsType extends PromptEditorPropsType {
|
|
13
14
|
inputsValues: Record<string, IFlowValue>;
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
|
|
17
17
|
import { Tree } from '@douyinfe/semi-ui';
|
|
18
18
|
|
|
19
|
-
import { IFlowValue } from '
|
|
19
|
+
import { IFlowValue } from '@/typings';
|
|
20
20
|
|
|
21
21
|
type VariableField = BaseVariableField<{ icon?: string | JSX.Element; title?: string }>;
|
|
22
22
|
|
|
@@ -79,7 +79,7 @@ export function InputsPicker({
|
|
|
79
79
|
const treeData: TreeNodeData[] = useMemo(
|
|
80
80
|
() =>
|
|
81
81
|
Object.entries(inputsValues).map(([key, value]) => {
|
|
82
|
-
if (value
|
|
82
|
+
if (value?.type === 'ref') {
|
|
83
83
|
const variable = available.getByKeyPath(value.content || []);
|
|
84
84
|
|
|
85
85
|
if (variable) {
|
|
@@ -67,10 +67,13 @@ class VariableTagWidget extends WidgetType {
|
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
const rootField = last(v.parentFields);
|
|
70
|
+
const rootField = last(v.parentFields) || v;
|
|
71
|
+
const isRoot = v.parentFields.length === 0;
|
|
71
72
|
|
|
72
73
|
const rootTitle = (
|
|
73
|
-
<UIRootTitle>
|
|
74
|
+
<UIRootTitle>
|
|
75
|
+
{rootField?.meta.title ? `${rootField.meta.title} ${isRoot ? '' : '-'} ` : ''}
|
|
76
|
+
</UIRootTitle>
|
|
74
77
|
);
|
|
75
78
|
const rootIcon = this.renderIcon(rootField?.meta.icon);
|
|
76
79
|
|
|
@@ -86,7 +89,7 @@ class VariableTagWidget extends WidgetType {
|
|
|
86
89
|
>
|
|
87
90
|
<UITag prefixIcon={rootIcon}>
|
|
88
91
|
{rootTitle}
|
|
89
|
-
<UIVarName>{v?.key}</UIVarName>
|
|
92
|
+
{!isRoot && <UIVarName>{v?.key}</UIVarName>}
|
|
90
93
|
</UITag>
|
|
91
94
|
</Popover>
|
|
92
95
|
);
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
} from '@coze-editor/editor/react';
|
|
16
16
|
import { EditorAPI } from '@coze-editor/editor/preset-prompt';
|
|
17
17
|
|
|
18
|
-
import { useVariableTree } from '
|
|
18
|
+
import { useVariableTree } from '@/components/variable-selector';
|
|
19
19
|
|
|
20
20
|
export function VariableTree() {
|
|
21
21
|
const [posKey, setPosKey] = useState('');
|
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
|
+
import { PromptEditor, PromptEditorPropsType } from '@/components/prompt-editor';
|
|
9
|
+
|
|
8
10
|
import { VariableTree } from './extensions/variable-tree';
|
|
9
11
|
import { VariableTagInject } from './extensions/variable-tag';
|
|
10
|
-
import { PromptEditor, PromptEditorPropsType } from '../prompt-editor';
|
|
11
12
|
|
|
12
13
|
export function PromptEditorWithVariables(props: PromptEditorPropsType) {
|
|
13
14
|
return (
|
|
@@ -5,18 +5,25 @@
|
|
|
5
5
|
|
|
6
6
|
import React, { useMemo } from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
9
|
+
import { Cascader, Icon, IconButton } from '@douyinfe/semi-ui';
|
|
9
10
|
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
11
|
+
import { createInjectMaterial } from '@/shared/inject-material';
|
|
12
|
+
import { useTypeManager } from '@/plugins';
|
|
12
13
|
|
|
13
|
-
interface
|
|
14
|
+
export interface TypeSelectorProps {
|
|
14
15
|
value?: Partial<IJsonSchema>;
|
|
15
|
-
onChange
|
|
16
|
+
onChange?: (value?: Partial<IJsonSchema>) => void;
|
|
17
|
+
readonly?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated use readonly instead
|
|
20
|
+
*/
|
|
16
21
|
disabled?: boolean;
|
|
17
22
|
style?: React.CSSProperties;
|
|
18
23
|
}
|
|
19
24
|
|
|
25
|
+
const labelStyle: React.CSSProperties = { display: 'flex', alignItems: 'center', gap: 5 };
|
|
26
|
+
|
|
20
27
|
export const getTypeSelectValue = (value?: Partial<IJsonSchema>): string[] | undefined => {
|
|
21
28
|
if (value?.type === 'array' && value?.items) {
|
|
22
29
|
return [value.type, ...(getTypeSelectValue(value.items) || [])];
|
|
@@ -35,28 +42,66 @@ export const parseTypeSelectValue = (value?: string[]): Partial<IJsonSchema> | u
|
|
|
35
42
|
return { type };
|
|
36
43
|
};
|
|
37
44
|
|
|
38
|
-
export function TypeSelector(props:
|
|
39
|
-
const { value, onChange, disabled, style } = props;
|
|
45
|
+
export function TypeSelector(props: TypeSelectorProps) {
|
|
46
|
+
const { value, onChange, readonly, disabled, style } = props;
|
|
40
47
|
|
|
41
48
|
const selectValue = useMemo(() => getTypeSelectValue(value), [value]);
|
|
42
49
|
|
|
50
|
+
const typeManager = useTypeManager();
|
|
51
|
+
|
|
52
|
+
const icon = typeManager.getDisplayIcon(value || {});
|
|
53
|
+
|
|
54
|
+
const options = useMemo(
|
|
55
|
+
() =>
|
|
56
|
+
typeManager.getTypeRegistriesWithParentType().map((_type) => {
|
|
57
|
+
const isArray = _type.type === 'array';
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
label: (
|
|
61
|
+
<div style={labelStyle}>
|
|
62
|
+
<Icon size="small" svg={_type.icon} />
|
|
63
|
+
{typeManager.getTypeBySchema(_type)?.label || _type.type}
|
|
64
|
+
</div>
|
|
65
|
+
),
|
|
66
|
+
value: _type.type,
|
|
67
|
+
children: isArray
|
|
68
|
+
? typeManager.getTypeRegistriesWithParentType('array').map((_type) => ({
|
|
69
|
+
label: (
|
|
70
|
+
<div style={labelStyle}>
|
|
71
|
+
<Icon
|
|
72
|
+
size="small"
|
|
73
|
+
svg={typeManager.getDisplayIcon({
|
|
74
|
+
type: 'array',
|
|
75
|
+
items: { type: _type.type },
|
|
76
|
+
})}
|
|
77
|
+
/>
|
|
78
|
+
{typeManager.getTypeBySchema(_type)?.label || _type.type}
|
|
79
|
+
</div>
|
|
80
|
+
),
|
|
81
|
+
value: _type.type,
|
|
82
|
+
}))
|
|
83
|
+
: [],
|
|
84
|
+
};
|
|
85
|
+
}),
|
|
86
|
+
[]
|
|
87
|
+
);
|
|
88
|
+
|
|
43
89
|
return (
|
|
44
90
|
<Cascader
|
|
45
|
-
disabled={disabled}
|
|
91
|
+
disabled={readonly || disabled}
|
|
46
92
|
size="small"
|
|
47
93
|
triggerRender={() => (
|
|
48
|
-
<
|
|
49
|
-
{getSchemaIcon(value)}
|
|
50
|
-
</Button>
|
|
94
|
+
<IconButton size="small" style={style} disabled={readonly || disabled} icon={icon} />
|
|
51
95
|
)}
|
|
52
96
|
treeData={options}
|
|
53
97
|
value={selectValue}
|
|
54
98
|
leafOnly={true}
|
|
55
99
|
onChange={(value) => {
|
|
56
|
-
onChange(parseTypeSelectValue(value as string[]));
|
|
100
|
+
onChange?.(parseTypeSelectValue(value as string[]));
|
|
57
101
|
}}
|
|
58
102
|
/>
|
|
59
103
|
);
|
|
60
104
|
}
|
|
61
105
|
|
|
62
|
-
|
|
106
|
+
TypeSelector.renderKey = 'type-selector-render-key';
|
|
107
|
+
export const InjectTypeSelector = createInjectMaterial(TypeSelector);
|