@flowgram.ai/form-materials 0.3.3 → 0.3.5
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 +5 -19
- package/bin/materials.ts +31 -89
- 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 +431 -505
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +77 -23
- package/dist/index.d.ts +77 -23
- package/dist/index.js +657 -731
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- 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 +4 -3
- package/src/components/batch-outputs/types.ts +1 -1
- package/src/components/batch-variable-selector/index.tsx +1 -1
- package/src/components/code-editor-mini/index.tsx +1 -1
- package/src/components/condition-row/constants.ts +2 -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 +27 -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/display-flow-value/index.tsx +2 -2
- package/src/components/display-inputs-values/index.tsx +3 -2
- 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 +1 -1
- package/src/components/dynamic-value-input/index.tsx +13 -9
- package/src/components/inputs-values/index.tsx +7 -5
- package/src/components/inputs-values/types.ts +3 -3
- 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 +11 -105
- package/src/components/json-schema-editor/hooks.tsx +53 -94
- package/src/components/json-schema-editor/index.tsx +18 -12
- package/src/components/json-schema-editor/styles.tsx +0 -29
- 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 +1 -1
- 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 +9 -7
- package/src/components/variable-selector/index.tsx +9 -5
- package/src/components/variable-selector/use-variable-tree.tsx +1 -1
- package/src/effects/auto-rename-ref/index.ts +1 -1
- 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/form-plugins/batch-outputs-plugin/index.ts +1 -1
- package/src/form-plugins/infer-assign-plugin/index.ts +1 -1
- package/src/form-plugins/infer-inputs-plugin/index.ts +1 -1
- 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/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 +7 -1
- package/src/shared/index.ts +1 -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/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/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/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
|
@@ -3,26 +3,19 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import React
|
|
6
|
+
import React from 'react';
|
|
7
7
|
|
|
8
8
|
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
9
|
-
import {
|
|
10
|
-
import { IconBrackets } from '@douyinfe/semi-icons';
|
|
9
|
+
import { I18n } from '@flowgram.ai/editor';
|
|
11
10
|
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
JSONHeader,
|
|
16
|
-
JSONHeaderLeft,
|
|
17
|
-
JSONHeaderRight,
|
|
18
|
-
JSONViewerWrapper,
|
|
19
|
-
} from './styles';
|
|
20
|
-
import { ConstantInput } from '../constant-input';
|
|
11
|
+
import { ConstantInput } from '@/components/constant-input';
|
|
12
|
+
|
|
13
|
+
import { ConstantInputWrapper } from './styles';
|
|
21
14
|
|
|
22
15
|
/**
|
|
23
|
-
*
|
|
24
|
-
* @param props -
|
|
25
|
-
* @returns
|
|
16
|
+
* Renders the corresponding default value input component based on different data types.
|
|
17
|
+
* @param props - Component properties, including value, type, placeholder, onChange.
|
|
18
|
+
* @returns Returns the input component of the corresponding type or null.
|
|
26
19
|
*/
|
|
27
20
|
export function DefaultValue(props: {
|
|
28
21
|
value: any;
|
|
@@ -33,102 +26,15 @@ export function DefaultValue(props: {
|
|
|
33
26
|
jsonFormatText?: string;
|
|
34
27
|
onChange: (value: any) => void;
|
|
35
28
|
}) {
|
|
36
|
-
const { value, schema,
|
|
37
|
-
|
|
38
|
-
const wrapperRef = useRef<HTMLDivElement>(null);
|
|
39
|
-
const JsonViewerRef = useRef<JsonViewer>(null);
|
|
40
|
-
|
|
41
|
-
// 为 JsonViewer 添加状态管理
|
|
42
|
-
const [internalJsonValue, setInternalJsonValue] = useState<string>(
|
|
43
|
-
getValueType(value) === 'string' ? value : ''
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
// 使用 useCallback 创建稳定的回调函数
|
|
47
|
-
const handleJsonChange = useCallback((val: string) => {
|
|
48
|
-
// 只在值真正改变时才更新状态
|
|
49
|
-
if (val !== internalJsonValue) {
|
|
50
|
-
setInternalJsonValue(val);
|
|
51
|
-
}
|
|
52
|
-
}, []);
|
|
53
|
-
|
|
54
|
-
// 处理编辑完成事件
|
|
55
|
-
const handleEditComplete = useCallback(() => {
|
|
56
|
-
// 只有当存在key,编辑完成时才触发父组件的 onChange
|
|
57
|
-
onChange(internalJsonValue);
|
|
58
|
-
// 确保在更新后移除焦点
|
|
59
|
-
requestAnimationFrame(() => {
|
|
60
|
-
// JsonViewerRef.current?.format();
|
|
61
|
-
wrapperRef.current?.blur();
|
|
62
|
-
});
|
|
63
|
-
setJsonReadOnly(true);
|
|
64
|
-
}, [internalJsonValue, onChange]);
|
|
65
|
-
|
|
66
|
-
const [jsonReadOnly, setJsonReadOnly] = useState<boolean>(true);
|
|
67
|
-
|
|
68
|
-
const handleFormatJson = useCallback(() => {
|
|
69
|
-
try {
|
|
70
|
-
const parsed = JSON.parse(internalJsonValue);
|
|
71
|
-
const formatted = JSON.stringify(parsed, null, 4);
|
|
72
|
-
setInternalJsonValue(formatted);
|
|
73
|
-
onChange(formatted);
|
|
74
|
-
} catch (error) {
|
|
75
|
-
console.error('Invalid JSON:', error);
|
|
76
|
-
}
|
|
77
|
-
}, [internalJsonValue, onChange]);
|
|
78
|
-
|
|
79
|
-
return type === 'object' ? (
|
|
80
|
-
<>
|
|
81
|
-
<JSONHeader>
|
|
82
|
-
<JSONHeaderLeft>json</JSONHeaderLeft>
|
|
83
|
-
<JSONHeaderRight>
|
|
84
|
-
<Tooltip content={jsonFormatText ?? 'Format'}>
|
|
85
|
-
<IconButton
|
|
86
|
-
icon={<IconBrackets style={{ color: 'var(--semi-color-primary)' }} />}
|
|
87
|
-
size="small"
|
|
88
|
-
type="tertiary"
|
|
89
|
-
theme="borderless"
|
|
90
|
-
onClick={handleFormatJson}
|
|
91
|
-
/>
|
|
92
|
-
</Tooltip>
|
|
93
|
-
</JSONHeaderRight>
|
|
94
|
-
</JSONHeader>
|
|
29
|
+
const { value, schema, onChange, placeholder } = props;
|
|
95
30
|
|
|
96
|
-
|
|
97
|
-
ref={wrapperRef}
|
|
98
|
-
tabIndex={-1}
|
|
99
|
-
onBlur={(e) => {
|
|
100
|
-
if (wrapperRef.current && !wrapperRef.current?.contains(e.relatedTarget as Node)) {
|
|
101
|
-
handleEditComplete();
|
|
102
|
-
}
|
|
103
|
-
}}
|
|
104
|
-
onClick={(e: React.MouseEvent) => {
|
|
105
|
-
setJsonReadOnly(false);
|
|
106
|
-
}}
|
|
107
|
-
>
|
|
108
|
-
<JsonViewer
|
|
109
|
-
ref={JsonViewerRef}
|
|
110
|
-
value={getValueType(value) === 'string' ? value : ''}
|
|
111
|
-
height={120}
|
|
112
|
-
width="100%"
|
|
113
|
-
showSearch={false}
|
|
114
|
-
options={{
|
|
115
|
-
readOnly: jsonReadOnly,
|
|
116
|
-
formatOptions: { tabSize: 4, insertSpaces: true, eol: '\n' },
|
|
117
|
-
}}
|
|
118
|
-
style={{
|
|
119
|
-
padding: 0,
|
|
120
|
-
}}
|
|
121
|
-
onChange={handleJsonChange}
|
|
122
|
-
/>
|
|
123
|
-
</JSONViewerWrapper>
|
|
124
|
-
</>
|
|
125
|
-
) : (
|
|
31
|
+
return (
|
|
126
32
|
<ConstantInputWrapper>
|
|
127
33
|
<ConstantInput
|
|
128
34
|
value={value}
|
|
129
35
|
onChange={(_v) => onChange(_v)}
|
|
130
36
|
schema={schema || { type: 'string' }}
|
|
131
|
-
placeholder={placeholder ?? 'Default value if parameter is not provided'}
|
|
37
|
+
placeholder={placeholder ?? I18n.t('Default value if parameter is not provided')}
|
|
132
38
|
/>
|
|
133
39
|
</ConstantInputWrapper>
|
|
134
40
|
);
|
|
@@ -3,10 +3,11 @@
|
|
|
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';
|
|
9
|
-
import {
|
|
8
|
+
import { difference, omit } from 'lodash';
|
|
9
|
+
import { produce } from 'immer';
|
|
10
|
+
import { IJsonSchema, type JsonSchemaTypeManager, useTypeManager } from '@flowgram.ai/json-schema';
|
|
10
11
|
|
|
11
12
|
import { PropertyValueType } from './types';
|
|
12
13
|
|
|
@@ -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,
|
|
@@ -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,8 @@ import {
|
|
|
16
17
|
IconMinus,
|
|
17
18
|
} from '@douyinfe/semi-icons';
|
|
18
19
|
|
|
19
|
-
import {
|
|
20
|
+
import { InjectTypeSelector } from '@/components/type-selector';
|
|
21
|
+
|
|
20
22
|
import { ConfigType, PropertyValueType } from './types';
|
|
21
23
|
import {
|
|
22
24
|
IconAddChildren,
|
|
@@ -39,6 +41,8 @@ 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;
|
|
@@ -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
|
|
@@ -78,7 +82,7 @@ export function JsonSchemaEditor(props: {
|
|
|
78
82
|
icon={<IconPlus />}
|
|
79
83
|
onClick={onAddProperty}
|
|
80
84
|
>
|
|
81
|
-
{config?.addButtonText ?? 'Add'}
|
|
85
|
+
{config?.addButtonText ?? I18n.t('Add')}
|
|
82
86
|
</Button>
|
|
83
87
|
</UIContainer>
|
|
84
88
|
);
|
|
@@ -120,7 +124,7 @@ function PropertyEdit(props: {
|
|
|
120
124
|
|
|
121
125
|
const typeSelectorValue = useMemo(() => ({ type, items }), [type, items]);
|
|
122
126
|
|
|
123
|
-
const { propertyList,
|
|
127
|
+
const { propertyList, canAddField, onAddProperty, onRemoveProperty, onEditProperty } =
|
|
124
128
|
usePropertiesEdit(value, onChangeProps);
|
|
125
129
|
|
|
126
130
|
const onChange = (key: string, _value: any) => {
|
|
@@ -130,7 +134,7 @@ function PropertyEdit(props: {
|
|
|
130
134
|
});
|
|
131
135
|
};
|
|
132
136
|
|
|
133
|
-
const showCollapse =
|
|
137
|
+
const showCollapse = canAddField && propertyList.length > 0;
|
|
134
138
|
|
|
135
139
|
return (
|
|
136
140
|
<>
|
|
@@ -168,7 +172,7 @@ function PropertyEdit(props: {
|
|
|
168
172
|
/>
|
|
169
173
|
</UIName>
|
|
170
174
|
<UIType>
|
|
171
|
-
<
|
|
175
|
+
<InjectTypeSelector
|
|
172
176
|
value={typeSelectorValue}
|
|
173
177
|
readonly={readonly}
|
|
174
178
|
onChange={(_value) => {
|
|
@@ -196,7 +200,7 @@ function PropertyEdit(props: {
|
|
|
196
200
|
setExpand((_expand) => !_expand);
|
|
197
201
|
}}
|
|
198
202
|
/>
|
|
199
|
-
{
|
|
203
|
+
{canAddField && (
|
|
200
204
|
<IconButton
|
|
201
205
|
disabled={readonly}
|
|
202
206
|
size="small"
|
|
@@ -219,25 +223,27 @@ function PropertyEdit(props: {
|
|
|
219
223
|
</UIRow>
|
|
220
224
|
{expand && (
|
|
221
225
|
<UIExpandDetail>
|
|
222
|
-
<UILabel>{config?.descTitle ?? 'Description'}</UILabel>
|
|
226
|
+
<UILabel>{config?.descTitle ?? I18n.t('Description')}</UILabel>
|
|
223
227
|
<BlurInput
|
|
224
228
|
disabled={readonly}
|
|
225
229
|
size="small"
|
|
226
230
|
value={description}
|
|
227
231
|
onChange={(value) => onChange('description', value)}
|
|
228
|
-
placeholder={
|
|
232
|
+
placeholder={
|
|
233
|
+
config?.descPlaceholder ?? I18n.t('Help LLM to understand the property')
|
|
234
|
+
}
|
|
229
235
|
/>
|
|
230
|
-
{$level === 0 &&
|
|
236
|
+
{$level === 0 && (
|
|
231
237
|
<>
|
|
232
238
|
<UILabel style={{ marginTop: 10 }}>
|
|
233
|
-
{config?.defaultValueTitle ?? 'Default Value'}
|
|
239
|
+
{config?.defaultValueTitle ?? I18n.t('Default Value')}
|
|
234
240
|
</UILabel>
|
|
235
241
|
<DefaultValueWrapper>
|
|
236
242
|
<DefaultValue
|
|
237
243
|
value={defaultValue}
|
|
238
244
|
schema={value}
|
|
239
245
|
type={type}
|
|
240
|
-
placeholder={config?.defaultValuePlaceholder}
|
|
246
|
+
placeholder={config?.defaultValuePlaceholder ?? I18n.t('Default Value')}
|
|
241
247
|
jsonFormatText={config?.jsonFormatText}
|
|
242
248
|
onChange={(value) => onChange('default', value)}
|
|
243
249
|
/>
|
|
@@ -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
|
|
|
@@ -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 (
|
|
@@ -8,9 +8,10 @@ import React, { useMemo } from 'react';
|
|
|
8
8
|
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
9
9
|
import { Cascader, Icon, IconButton } from '@douyinfe/semi-ui';
|
|
10
10
|
|
|
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
16
|
onChange?: (value?: Partial<IJsonSchema>) => void;
|
|
16
17
|
readonly?: boolean;
|
|
@@ -23,8 +24,6 @@ interface PropTypes {
|
|
|
23
24
|
|
|
24
25
|
const labelStyle: React.CSSProperties = { display: 'flex', alignItems: 'center', gap: 5 };
|
|
25
26
|
|
|
26
|
-
const firstUppercase = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
27
|
-
|
|
28
27
|
export const getTypeSelectValue = (value?: Partial<IJsonSchema>): string[] | undefined => {
|
|
29
28
|
if (value?.type === 'array' && value?.items) {
|
|
30
29
|
return [value.type, ...(getTypeSelectValue(value.items) || [])];
|
|
@@ -43,7 +42,7 @@ export const parseTypeSelectValue = (value?: string[]): Partial<IJsonSchema> | u
|
|
|
43
42
|
return { type };
|
|
44
43
|
};
|
|
45
44
|
|
|
46
|
-
export function TypeSelector(props:
|
|
45
|
+
export function TypeSelector(props: TypeSelectorProps) {
|
|
47
46
|
const { value, onChange, readonly, disabled, style } = props;
|
|
48
47
|
|
|
49
48
|
const selectValue = useMemo(() => getTypeSelectValue(value), [value]);
|
|
@@ -61,7 +60,7 @@ export function TypeSelector(props: PropTypes) {
|
|
|
61
60
|
label: (
|
|
62
61
|
<div style={labelStyle}>
|
|
63
62
|
<Icon size="small" svg={_type.icon} />
|
|
64
|
-
{
|
|
63
|
+
{typeManager.getTypeBySchema(_type)?.label || _type.type}
|
|
65
64
|
</div>
|
|
66
65
|
),
|
|
67
66
|
value: _type.type,
|
|
@@ -76,7 +75,7 @@ export function TypeSelector(props: PropTypes) {
|
|
|
76
75
|
items: { type: _type.type },
|
|
77
76
|
})}
|
|
78
77
|
/>
|
|
79
|
-
{
|
|
78
|
+
{typeManager.getTypeBySchema(_type)?.label || _type.type}
|
|
80
79
|
</div>
|
|
81
80
|
),
|
|
82
81
|
value: _type.type,
|
|
@@ -103,3 +102,6 @@ export function TypeSelector(props: PropTypes) {
|
|
|
103
102
|
/>
|
|
104
103
|
);
|
|
105
104
|
}
|
|
105
|
+
|
|
106
|
+
TypeSelector.renderKey = 'type-selector-render-key';
|
|
107
|
+
export const InjectTypeSelector = createInjectMaterial(TypeSelector);
|
|
@@ -6,15 +6,18 @@
|
|
|
6
6
|
import React, { useMemo } from 'react';
|
|
7
7
|
|
|
8
8
|
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
9
|
+
import { I18n } from '@flowgram.ai/editor';
|
|
9
10
|
import { TriggerRenderProps } from '@douyinfe/semi-ui/lib/es/treeSelect';
|
|
10
11
|
import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
|
|
11
12
|
import { Popover } from '@douyinfe/semi-ui';
|
|
12
13
|
import { IconChevronDownStroked, IconIssueStroked } from '@douyinfe/semi-icons';
|
|
13
14
|
|
|
15
|
+
import { createInjectMaterial } from '@/shared';
|
|
16
|
+
|
|
14
17
|
import { useVariableTree } from './use-variable-tree';
|
|
15
18
|
import { UIPopoverContent, UIRootTitle, UITag, UITreeSelect, UIVarName } from './styles';
|
|
16
19
|
|
|
17
|
-
interface
|
|
20
|
+
export interface VariableSelectorProps {
|
|
18
21
|
value?: string[];
|
|
19
22
|
config?: {
|
|
20
23
|
placeholder?: string;
|
|
@@ -29,8 +32,6 @@ interface PropTypes {
|
|
|
29
32
|
triggerRender?: (props: TriggerRenderProps) => React.ReactNode;
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
export type VariableSelectorProps = PropTypes;
|
|
33
|
-
|
|
34
35
|
export { useVariableTree };
|
|
35
36
|
|
|
36
37
|
export const VariableSelector = ({
|
|
@@ -43,7 +44,7 @@ export const VariableSelector = ({
|
|
|
43
44
|
excludeSchema,
|
|
44
45
|
hasError,
|
|
45
46
|
triggerRender,
|
|
46
|
-
}:
|
|
47
|
+
}: VariableSelectorProps) => {
|
|
47
48
|
const treeData = useVariableTree({ includeSchema, excludeSchema });
|
|
48
49
|
|
|
49
50
|
const treeValue = useMemo(() => {
|
|
@@ -130,8 +131,11 @@ export const VariableSelector = ({
|
|
|
130
131
|
showClear={false}
|
|
131
132
|
arrowIcon={<IconChevronDownStroked size="small" />}
|
|
132
133
|
triggerRender={triggerRender}
|
|
133
|
-
placeholder={config?.placeholder ?? 'Select Variable'}
|
|
134
|
+
placeholder={config?.placeholder ?? I18n.t('Select Variable')}
|
|
134
135
|
/>
|
|
135
136
|
</>
|
|
136
137
|
);
|
|
137
138
|
};
|
|
139
|
+
|
|
140
|
+
VariableSelector.renderKey = 'variable-selector-render-key';
|
|
141
|
+
export const InjectVariableSelector = createInjectMaterial(VariableSelector);
|
|
@@ -10,7 +10,7 @@ import { ASTMatch, BaseVariableField, useAvailableVariables } from '@flowgram.ai
|
|
|
10
10
|
import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
|
|
11
11
|
import { Icon } from '@douyinfe/semi-ui';
|
|
12
12
|
|
|
13
|
-
import { useTypeManager } from '
|
|
13
|
+
import { useTypeManager } from '@/plugins';
|
|
14
14
|
|
|
15
15
|
type VariableField = BaseVariableField<{
|
|
16
16
|
icon?: string | JSX.Element;
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
VariableFieldKeyRenameService,
|
|
12
12
|
} from '@flowgram.ai/editor';
|
|
13
13
|
|
|
14
|
-
import { IFlowRefValue, IFlowTemplateValue } from '
|
|
14
|
+
import { IFlowRefValue, IFlowTemplateValue } from '@/typings';
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Auto rename ref when form item's key is renamed
|