@flowgram.ai/form-materials 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/inputs-values-tree/index.js +1 -1
- package/dist/cjs/components/json-schema-editor/hooks.js +55 -48
- package/dist/esm/components/inputs-values-tree/index.mjs +1 -1
- package/dist/esm/components/json-schema-editor/hooks.mjs +55 -48
- package/dist/types/components/coze-editor-extensions/extensions/inputs-tree.d.ts +3 -3
- package/dist/types/components/coze-editor-extensions/index.d.ts +1 -1
- package/dist/types/components/display-inputs-values/index.d.ts +2 -1
- package/dist/types/components/inputs-values-tree/types.d.ts +3 -2
- package/dist/types/components/prompt-editor-with-inputs/editor.d.ts +2 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/shared/flow-value/index.d.ts +1 -1
- package/dist/types/shared/flow-value/types.d.ts +3 -0
- package/dist/types/shared/index.d.ts +1 -1
- package/package.json +6 -6
- package/src/components/coze-editor-extensions/extensions/inputs-tree.tsx +4 -3
- package/src/components/display-inputs-values/index.tsx +2 -1
- package/src/components/inputs-values-tree/index.tsx +5 -3
- package/src/components/inputs-values-tree/types.ts +3 -2
- package/src/components/json-schema-editor/hooks.tsx +60 -53
- package/src/components/prompt-editor-with-inputs/editor.tsx +2 -1
- package/src/index.ts +1 -0
- package/src/shared/flow-value/index.ts +1 -0
- package/src/shared/flow-value/types.ts +4 -0
- package/src/shared/index.ts +1 -0
|
@@ -39,7 +39,7 @@ function InputsValuesTree(props) {
|
|
|
39
39
|
const { value, onChange, readonly, hasError, constantProps } = props;
|
|
40
40
|
const { list, updateKey, updateValue, remove, add } = (0, external_hooks_index_js_namespaceObject.useObjectList)({
|
|
41
41
|
value,
|
|
42
|
-
onChange,
|
|
42
|
+
onChange: (v)=>onChange?.(v),
|
|
43
43
|
sortIndexKey: (value)=>index_js_namespaceObject.FlowValueUtils.isFlowValue(value) ? 'extra.index' : ''
|
|
44
44
|
});
|
|
45
45
|
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
|
|
@@ -39,68 +39,72 @@ function usePropertiesEdit(value, onChange) {
|
|
|
39
39
|
const drilldownSchema = typeManager.getPropertiesParent(value || {});
|
|
40
40
|
const canAddField = typeManager.canAddField(value || {});
|
|
41
41
|
const [propertyList, setPropertyList] = (0, external_react_namespaceObject.useState)([]);
|
|
42
|
+
const latestPropertyListRef = (0, external_react_namespaceObject.useRef)(propertyList);
|
|
42
43
|
const effectVersion = (0, external_react_namespaceObject.useRef)(0);
|
|
43
44
|
const changeVersion = (0, external_react_namespaceObject.useRef)(0);
|
|
44
45
|
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
45
46
|
effectVersion.current = effectVersion.current + 1;
|
|
46
47
|
if (effectVersion.current === changeVersion.current) return;
|
|
47
48
|
effectVersion.current = changeVersion.current;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
49
|
+
const _list = latestPropertyListRef.current;
|
|
50
|
+
const newNames = Object.entries(drilldownSchema?.properties || {}).sort(([, a], [, b])=>(a.extra?.index ?? 0) - (b.extra?.index ?? 0)).map(([key])=>key);
|
|
51
|
+
const oldNames = _list.map((item)=>item.name).filter(Boolean);
|
|
52
|
+
const addNames = (0, external_lodash_es_namespaceObject.difference)(newNames, oldNames);
|
|
53
|
+
const next = _list.filter((item)=>!item.name || newNames.includes(item.name)).map((item)=>({
|
|
54
|
+
key: item.key,
|
|
55
|
+
name: item.name,
|
|
56
|
+
isPropertyRequired: drilldownSchema?.required?.includes(item.name || '') || false,
|
|
57
|
+
...drilldownSchema?.properties?.[item.name || ''] || item || {}
|
|
58
|
+
})).concat(addNames.map((_name)=>({
|
|
59
|
+
key: genId(),
|
|
60
|
+
name: _name,
|
|
61
|
+
isPropertyRequired: drilldownSchema?.required?.includes(_name) || false,
|
|
62
|
+
...drilldownSchema?.properties?.[_name] || {}
|
|
63
|
+
})));
|
|
64
|
+
latestPropertyListRef.current = next;
|
|
65
|
+
setPropertyList(next);
|
|
64
66
|
}, [
|
|
65
67
|
drilldownSchema
|
|
66
68
|
]);
|
|
67
69
|
const updatePropertyList = (updater)=>{
|
|
68
70
|
changeVersion.current = changeVersion.current + 1;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
71
|
+
const next = updater(latestPropertyListRef.current);
|
|
72
|
+
latestPropertyListRef.current = next;
|
|
73
|
+
setPropertyList(next);
|
|
74
|
+
const nextProperties = {};
|
|
75
|
+
const nextRequired = [];
|
|
76
|
+
for (const _property of next)if (_property.name) {
|
|
77
|
+
nextProperties[_property.name] = (0, external_lodash_es_namespaceObject.omit)(_property, [
|
|
78
|
+
'key',
|
|
79
|
+
'name',
|
|
80
|
+
'isPropertyRequired'
|
|
81
|
+
]);
|
|
82
|
+
if (_property.isPropertyRequired) nextRequired.push(_property.name);
|
|
83
|
+
}
|
|
84
|
+
onChange?.((0, external_immer_namespaceObject.produce)(value || {}, (draft)=>{
|
|
85
|
+
const propertiesParent = typeManager.getPropertiesParent(draft);
|
|
86
|
+
if (propertiesParent) {
|
|
87
|
+
propertiesParent.properties = nextProperties;
|
|
88
|
+
propertiesParent.required = nextRequired;
|
|
89
|
+
return;
|
|
80
90
|
}
|
|
81
|
-
|
|
82
|
-
const propertiesParent = typeManager.getPropertiesParent(draft);
|
|
83
|
-
if (propertiesParent) {
|
|
84
|
-
propertiesParent.properties = nextProperties;
|
|
85
|
-
propertiesParent.required = nextRequired;
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
}));
|
|
89
|
-
return next;
|
|
90
|
-
});
|
|
91
|
+
}));
|
|
91
92
|
};
|
|
92
93
|
const onAddProperty = ()=>{
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
const _list = latestPropertyListRef.current;
|
|
95
|
+
const next = [
|
|
96
|
+
..._list,
|
|
97
|
+
{
|
|
98
|
+
key: genId(),
|
|
99
|
+
name: '',
|
|
100
|
+
type: 'string',
|
|
101
|
+
extra: {
|
|
102
|
+
index: _list.length + 1
|
|
102
103
|
}
|
|
103
|
-
|
|
104
|
+
}
|
|
105
|
+
];
|
|
106
|
+
latestPropertyListRef.current = next;
|
|
107
|
+
setPropertyList(next);
|
|
104
108
|
};
|
|
105
109
|
const onRemoveProperty = (key)=>{
|
|
106
110
|
updatePropertyList((_list)=>_list.filter((_property)=>_property.key !== key));
|
|
@@ -109,7 +113,10 @@ function usePropertiesEdit(value, onChange) {
|
|
|
109
113
|
updatePropertyList((_list)=>_list.map((_property)=>_property.key === key ? nextValue : _property));
|
|
110
114
|
};
|
|
111
115
|
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
112
|
-
if (!canAddField)
|
|
116
|
+
if (!canAddField) {
|
|
117
|
+
latestPropertyListRef.current = [];
|
|
118
|
+
setPropertyList([]);
|
|
119
|
+
}
|
|
113
120
|
}, [
|
|
114
121
|
canAddField
|
|
115
122
|
]);
|
|
@@ -11,7 +11,7 @@ function InputsValuesTree(props) {
|
|
|
11
11
|
const { value, onChange, readonly, hasError, constantProps } = props;
|
|
12
12
|
const { list, updateKey, updateValue, remove, add } = useObjectList({
|
|
13
13
|
value,
|
|
14
|
-
onChange,
|
|
14
|
+
onChange: (v)=>onChange?.(v),
|
|
15
15
|
sortIndexKey: (value)=>FlowValueUtils.isFlowValue(value) ? 'extra.index' : ''
|
|
16
16
|
});
|
|
17
17
|
return /*#__PURE__*/ jsxs("div", {
|
|
@@ -11,68 +11,72 @@ function usePropertiesEdit(value, onChange) {
|
|
|
11
11
|
const drilldownSchema = typeManager.getPropertiesParent(value || {});
|
|
12
12
|
const canAddField = typeManager.canAddField(value || {});
|
|
13
13
|
const [propertyList, setPropertyList] = useState([]);
|
|
14
|
+
const latestPropertyListRef = useRef(propertyList);
|
|
14
15
|
const effectVersion = useRef(0);
|
|
15
16
|
const changeVersion = useRef(0);
|
|
16
17
|
useEffect(()=>{
|
|
17
18
|
effectVersion.current = effectVersion.current + 1;
|
|
18
19
|
if (effectVersion.current === changeVersion.current) return;
|
|
19
20
|
effectVersion.current = changeVersion.current;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
21
|
+
const _list = latestPropertyListRef.current;
|
|
22
|
+
const newNames = Object.entries(drilldownSchema?.properties || {}).sort(([, a], [, b])=>(a.extra?.index ?? 0) - (b.extra?.index ?? 0)).map(([key])=>key);
|
|
23
|
+
const oldNames = _list.map((item)=>item.name).filter(Boolean);
|
|
24
|
+
const addNames = difference(newNames, oldNames);
|
|
25
|
+
const next = _list.filter((item)=>!item.name || newNames.includes(item.name)).map((item)=>({
|
|
26
|
+
key: item.key,
|
|
27
|
+
name: item.name,
|
|
28
|
+
isPropertyRequired: drilldownSchema?.required?.includes(item.name || '') || false,
|
|
29
|
+
...drilldownSchema?.properties?.[item.name || ''] || item || {}
|
|
30
|
+
})).concat(addNames.map((_name)=>({
|
|
31
|
+
key: genId(),
|
|
32
|
+
name: _name,
|
|
33
|
+
isPropertyRequired: drilldownSchema?.required?.includes(_name) || false,
|
|
34
|
+
...drilldownSchema?.properties?.[_name] || {}
|
|
35
|
+
})));
|
|
36
|
+
latestPropertyListRef.current = next;
|
|
37
|
+
setPropertyList(next);
|
|
36
38
|
}, [
|
|
37
39
|
drilldownSchema
|
|
38
40
|
]);
|
|
39
41
|
const updatePropertyList = (updater)=>{
|
|
40
42
|
changeVersion.current = changeVersion.current + 1;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
const next = updater(latestPropertyListRef.current);
|
|
44
|
+
latestPropertyListRef.current = next;
|
|
45
|
+
setPropertyList(next);
|
|
46
|
+
const nextProperties = {};
|
|
47
|
+
const nextRequired = [];
|
|
48
|
+
for (const _property of next)if (_property.name) {
|
|
49
|
+
nextProperties[_property.name] = omit(_property, [
|
|
50
|
+
'key',
|
|
51
|
+
'name',
|
|
52
|
+
'isPropertyRequired'
|
|
53
|
+
]);
|
|
54
|
+
if (_property.isPropertyRequired) nextRequired.push(_property.name);
|
|
55
|
+
}
|
|
56
|
+
onChange?.(produce(value || {}, (draft)=>{
|
|
57
|
+
const propertiesParent = typeManager.getPropertiesParent(draft);
|
|
58
|
+
if (propertiesParent) {
|
|
59
|
+
propertiesParent.properties = nextProperties;
|
|
60
|
+
propertiesParent.required = nextRequired;
|
|
61
|
+
return;
|
|
52
62
|
}
|
|
53
|
-
|
|
54
|
-
const propertiesParent = typeManager.getPropertiesParent(draft);
|
|
55
|
-
if (propertiesParent) {
|
|
56
|
-
propertiesParent.properties = nextProperties;
|
|
57
|
-
propertiesParent.required = nextRequired;
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
}));
|
|
61
|
-
return next;
|
|
62
|
-
});
|
|
63
|
+
}));
|
|
63
64
|
};
|
|
64
65
|
const onAddProperty = ()=>{
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
66
|
+
const _list = latestPropertyListRef.current;
|
|
67
|
+
const next = [
|
|
68
|
+
..._list,
|
|
69
|
+
{
|
|
70
|
+
key: genId(),
|
|
71
|
+
name: '',
|
|
72
|
+
type: 'string',
|
|
73
|
+
extra: {
|
|
74
|
+
index: _list.length + 1
|
|
74
75
|
}
|
|
75
|
-
|
|
76
|
+
}
|
|
77
|
+
];
|
|
78
|
+
latestPropertyListRef.current = next;
|
|
79
|
+
setPropertyList(next);
|
|
76
80
|
};
|
|
77
81
|
const onRemoveProperty = (key)=>{
|
|
78
82
|
updatePropertyList((_list)=>_list.filter((_property)=>_property.key !== key));
|
|
@@ -81,7 +85,10 @@ function usePropertiesEdit(value, onChange) {
|
|
|
81
85
|
updatePropertyList((_list)=>_list.map((_property)=>_property.key === key ? nextValue : _property));
|
|
82
86
|
};
|
|
83
87
|
useEffect(()=>{
|
|
84
|
-
if (!canAddField)
|
|
88
|
+
if (!canAddField) {
|
|
89
|
+
latestPropertyListRef.current = [];
|
|
90
|
+
setPropertyList([]);
|
|
91
|
+
}
|
|
85
92
|
}, [
|
|
86
93
|
canAddField
|
|
87
94
|
]);
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
import React from 'react';
|
|
6
|
-
import {
|
|
6
|
+
import { IInputsValues } from '../../../shared/flow-value/types';
|
|
7
7
|
export declare function InputsPicker({ inputsValues, onSelect, }: {
|
|
8
|
-
inputsValues:
|
|
8
|
+
inputsValues: IInputsValues;
|
|
9
9
|
onSelect: (v: string) => void;
|
|
10
10
|
}): React.JSX.Element;
|
|
11
11
|
export declare function InputsTree({ inputsValues, triggerCharacters, }: {
|
|
12
|
-
inputsValues:
|
|
12
|
+
inputsValues: IInputsValues;
|
|
13
13
|
triggerCharacters?: string[];
|
|
14
14
|
}): React.JSX.Element;
|
|
@@ -11,7 +11,7 @@ export declare const EditorVariableTagInject: import("react").FC<unknown> & {
|
|
|
11
11
|
renderKey?: string;
|
|
12
12
|
};
|
|
13
13
|
export declare const EditorInputsTree: import("react").FC<{
|
|
14
|
-
inputsValues:
|
|
14
|
+
inputsValues: import("../../shared").IInputsValues;
|
|
15
15
|
triggerCharacters?: string[];
|
|
16
16
|
}> & {
|
|
17
17
|
renderKey?: string;
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
import React from 'react';
|
|
6
|
+
import { IInputsValues } from '../../shared/flow-value';
|
|
6
7
|
interface PropsType {
|
|
7
|
-
value?:
|
|
8
|
+
value?: IInputsValues;
|
|
8
9
|
showIconInTree?: boolean;
|
|
9
10
|
}
|
|
10
11
|
export declare function DisplayInputsValues({ value, showIconInTree }: PropsType): React.JSX.Element;
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
6
|
+
import { IInputsValues } from '../../shared';
|
|
6
7
|
import { ConstantInputStrategy } from '../constant-input';
|
|
7
8
|
export interface PropsType {
|
|
8
|
-
value?:
|
|
9
|
-
onChange: (value?:
|
|
9
|
+
value?: IInputsValues;
|
|
10
|
+
onChange: (value?: IInputsValues) => void;
|
|
10
11
|
readonly?: boolean;
|
|
11
12
|
hasError?: boolean;
|
|
12
13
|
schema?: IJsonSchema;
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
import React from 'react';
|
|
6
|
+
import type { IInputsValues } from '../../shared/flow-value';
|
|
6
7
|
import { PromptEditorPropsType } from '../prompt-editor';
|
|
7
8
|
export interface PromptEditorWithInputsProps extends PromptEditorPropsType {
|
|
8
|
-
inputsValues:
|
|
9
|
+
inputsValues: IInputsValues;
|
|
9
10
|
}
|
|
10
11
|
export declare function PromptEditorWithInputs({ inputsValues, ...restProps }: PromptEditorWithInputsProps): React.JSX.Element;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -7,5 +7,5 @@ export { autoRenameRefEffect, listenRefSchemaChange, listenRefValueChange, provi
|
|
|
7
7
|
export { createBatchOutputsFormPlugin, createInferAssignPlugin, createInferInputsPlugin, provideBatchOutputsEffect, } from './form-plugins';
|
|
8
8
|
export { useObjectList } from './hooks';
|
|
9
9
|
export { JsonSchemaTypePresetProvider, JsonSchemaUtils, createDisableDeclarationPlugin, createTypePresetPlugin, type ConstantRendererProps, type IJsonSchema, type JsonSchemaBasicType, type JsonSchemaTypeRegistry, useTypeManager, } from './plugins';
|
|
10
|
-
export { FlowValueUtils, createInjectMaterial, formatLegacyRefOnInit, formatLegacyRefOnSubmit, formatLegacyRefToNewRef, formatNewRefToLegacyRef, isLegacyFlowRefValueSchema, isNewFlowRefValueSchema, lazySuspense, polyfillCreateRoot, type FlowValueType, type IFlowConstantRefValue, type IFlowConstantValue, type IFlowExpressionValue, type IFlowRefValue, type IFlowTemplateValue, type IFlowValue, type IFlowValueExtra, type IPolyfillRoot, unstableSetCreateRoot, withSuspense, } from './shared';
|
|
10
|
+
export { FlowValueUtils, createInjectMaterial, formatLegacyRefOnInit, formatLegacyRefOnSubmit, formatLegacyRefToNewRef, formatNewRefToLegacyRef, isLegacyFlowRefValueSchema, isNewFlowRefValueSchema, lazySuspense, polyfillCreateRoot, type FlowValueType, type IFlowConstantRefValue, type IFlowConstantValue, type IFlowExpressionValue, type IFlowRefValue, type IFlowTemplateValue, type IFlowValue, type IFlowValueExtra, type IInputsValues, type IPolyfillRoot, unstableSetCreateRoot, withSuspense, } from './shared';
|
|
11
11
|
export { validateFlowValue } from './validate';
|
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
export { FlowValueUtils } from './utils';
|
|
6
|
-
export { type IFlowValueExtra, type FlowValueType, type IFlowValue, type IFlowConstantValue, type IFlowRefValue, type IFlowExpressionValue, type IFlowTemplateValue, type IFlowConstantRefValue, } from './types';
|
|
6
|
+
export { type IFlowValueExtra, type FlowValueType, type IFlowValue, type IFlowConstantValue, type IFlowRefValue, type IFlowExpressionValue, type IFlowTemplateValue, type IFlowConstantRefValue, type IInputsValues, } from './types';
|
|
@@ -30,3 +30,6 @@ export interface IFlowTemplateValue {
|
|
|
30
30
|
}
|
|
31
31
|
export type IFlowValue = IFlowConstantValue | IFlowRefValue | IFlowExpressionValue | IFlowTemplateValue;
|
|
32
32
|
export type IFlowConstantRefValue = IFlowConstantValue | IFlowRefValue;
|
|
33
|
+
export interface IInputsValues {
|
|
34
|
+
[key: string]: IInputsValues | IFlowValue | undefined;
|
|
35
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
|
-
export { FlowValueUtils, type FlowValueType, type IFlowConstantRefValue, type IFlowConstantValue, type IFlowExpressionValue, type IFlowRefValue, type IFlowTemplateValue, type IFlowValue, type IFlowValueExtra, } from './flow-value';
|
|
5
|
+
export { FlowValueUtils, type FlowValueType, type IFlowConstantRefValue, type IFlowConstantValue, type IFlowExpressionValue, type IFlowRefValue, type IFlowTemplateValue, type IFlowValue, type IFlowValueExtra, type IInputsValues, } from './flow-value';
|
|
6
6
|
export { formatLegacyRefOnInit, formatLegacyRefOnSubmit, formatLegacyRefToNewRef, formatNewRefToLegacyRef, isLegacyFlowRefValueSchema, isNewFlowRefValueSchema, } from './format-legacy-refs';
|
|
7
7
|
export { createInjectMaterial } from './inject-material';
|
|
8
8
|
export { lazySuspense, withSuspense } from './lazy-suspense';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowgram.ai/form-materials",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"homepage": "https://flowgram.ai/",
|
|
5
5
|
"repository": "https://github.com/bytedance/flowgram.ai",
|
|
6
6
|
"license": "MIT",
|
|
@@ -67,9 +67,9 @@
|
|
|
67
67
|
"@codemirror/view": "~6.38.0",
|
|
68
68
|
"@codemirror/state": "~6.5.2",
|
|
69
69
|
"zod": "^3.24.4",
|
|
70
|
-
"@flowgram.ai/editor": "0.5.
|
|
71
|
-
"@flowgram.ai/json-schema": "0.5.
|
|
72
|
-
"@flowgram.ai/coze-editor": "0.5.
|
|
70
|
+
"@flowgram.ai/editor": "0.5.3",
|
|
71
|
+
"@flowgram.ai/json-schema": "0.5.3",
|
|
72
|
+
"@flowgram.ai/coze-editor": "0.5.3"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@types/lodash-es": "^4.17.12",
|
|
@@ -88,8 +88,8 @@
|
|
|
88
88
|
"cross-env": "~7.0.3",
|
|
89
89
|
"@rsbuild/plugin-react": "^1.1.1",
|
|
90
90
|
"date-fns": "~4.1.0",
|
|
91
|
-
"@flowgram.ai/
|
|
92
|
-
"@flowgram.ai/
|
|
91
|
+
"@flowgram.ai/eslint-config": "0.5.3",
|
|
92
|
+
"@flowgram.ai/ts-config": "0.5.3"
|
|
93
93
|
},
|
|
94
94
|
"peerDependencies": {
|
|
95
95
|
"react": ">=16.8",
|
|
@@ -24,7 +24,8 @@ import { EditorAPI } from '@flowgram.ai/coze-editor/preset-prompt';
|
|
|
24
24
|
import { type TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
|
|
25
25
|
import { Tree, Popover } from '@douyinfe/semi-ui';
|
|
26
26
|
|
|
27
|
-
import {
|
|
27
|
+
import { IInputsValues } from '@/shared/flow-value/types';
|
|
28
|
+
import { FlowValueUtils } from '@/shared';
|
|
28
29
|
|
|
29
30
|
type VariableField = BaseVariableField<{ icon?: string | JSX.Element; title?: string }>;
|
|
30
31
|
|
|
@@ -32,7 +33,7 @@ export function InputsPicker({
|
|
|
32
33
|
inputsValues,
|
|
33
34
|
onSelect,
|
|
34
35
|
}: {
|
|
35
|
-
inputsValues:
|
|
36
|
+
inputsValues: IInputsValues;
|
|
36
37
|
onSelect: (v: string) => void;
|
|
37
38
|
}) {
|
|
38
39
|
const available = useScopeAvailable();
|
|
@@ -130,7 +131,7 @@ export function InputsTree({
|
|
|
130
131
|
inputsValues,
|
|
131
132
|
triggerCharacters = DEFAULT_TRIGGER_CHARACTERS,
|
|
132
133
|
}: {
|
|
133
|
-
inputsValues:
|
|
134
|
+
inputsValues: IInputsValues;
|
|
134
135
|
triggerCharacters?: string[];
|
|
135
136
|
}) {
|
|
136
137
|
const [posKey, setPosKey] = useState('');
|
|
@@ -8,6 +8,7 @@ import React, { useMemo } from 'react';
|
|
|
8
8
|
import { isPlainObject } from 'lodash-es';
|
|
9
9
|
import { useScopeAvailable } from '@flowgram.ai/editor';
|
|
10
10
|
|
|
11
|
+
import { IInputsValues } from '@/shared/flow-value';
|
|
11
12
|
import { FlowValueUtils } from '@/shared';
|
|
12
13
|
import { DisplayFlowValue } from '@/components/display-flow-value';
|
|
13
14
|
|
|
@@ -15,7 +16,7 @@ import { DisplayInputsWrapper } from './styles';
|
|
|
15
16
|
import { DisplaySchemaTag } from '../display-schema-tag';
|
|
16
17
|
|
|
17
18
|
interface PropsType {
|
|
18
|
-
value?:
|
|
19
|
+
value?: IInputsValues;
|
|
19
20
|
showIconInTree?: boolean;
|
|
20
21
|
}
|
|
21
22
|
|
|
@@ -9,7 +9,7 @@ import { I18n } from '@flowgram.ai/editor';
|
|
|
9
9
|
import { Button } from '@douyinfe/semi-ui';
|
|
10
10
|
import { IconPlus } from '@douyinfe/semi-icons';
|
|
11
11
|
|
|
12
|
-
import { FlowValueUtils } from '@/shared';
|
|
12
|
+
import { FlowValueUtils, IFlowValue, IInputsValues } from '@/shared';
|
|
13
13
|
import { useObjectList } from '@/hooks';
|
|
14
14
|
|
|
15
15
|
import { PropsType } from './types';
|
|
@@ -19,9 +19,11 @@ import { InputValueRow } from './row';
|
|
|
19
19
|
export function InputsValuesTree(props: PropsType) {
|
|
20
20
|
const { value, onChange, readonly, hasError, constantProps } = props;
|
|
21
21
|
|
|
22
|
-
const { list, updateKey, updateValue, remove, add } = useObjectList
|
|
22
|
+
const { list, updateKey, updateValue, remove, add } = useObjectList<
|
|
23
|
+
IInputsValues | IFlowValue | undefined
|
|
24
|
+
>({
|
|
23
25
|
value,
|
|
24
|
-
onChange,
|
|
26
|
+
onChange: (v) => onChange?.(v as IInputsValues),
|
|
25
27
|
sortIndexKey: (value) => (FlowValueUtils.isFlowValue(value) ? 'extra.index' : ''),
|
|
26
28
|
});
|
|
27
29
|
|
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
|
|
6
6
|
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
7
7
|
|
|
8
|
+
import { IInputsValues } from '@/shared';
|
|
8
9
|
import { ConstantInputStrategy } from '@/components/constant-input';
|
|
9
10
|
|
|
10
11
|
export interface PropsType {
|
|
11
|
-
value?:
|
|
12
|
-
onChange: (value?:
|
|
12
|
+
value?: IInputsValues;
|
|
13
|
+
onChange: (value?: IInputsValues) => void;
|
|
13
14
|
readonly?: boolean;
|
|
14
15
|
hasError?: boolean;
|
|
15
16
|
schema?: IJsonSchema;
|
|
@@ -27,6 +27,7 @@ export function usePropertiesEdit(
|
|
|
27
27
|
const canAddField = typeManager.canAddField(value || {});
|
|
28
28
|
|
|
29
29
|
const [propertyList, setPropertyList] = useState<PropertyValueType[]>([]);
|
|
30
|
+
const latestPropertyListRef = useRef(propertyList);
|
|
30
31
|
|
|
31
32
|
const effectVersion = useRef(0);
|
|
32
33
|
const changeVersion = useRef(0);
|
|
@@ -39,77 +40,82 @@ export function usePropertiesEdit(
|
|
|
39
40
|
effectVersion.current = changeVersion.current;
|
|
40
41
|
|
|
41
42
|
// If the value is changed, update the property list
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
43
|
+
const _list = latestPropertyListRef.current;
|
|
44
|
+
|
|
45
|
+
const newNames = Object.entries(drilldownSchema?.properties || {})
|
|
46
|
+
.sort(([, a], [, b]) => (a.extra?.index ?? 0) - (b.extra?.index ?? 0))
|
|
47
|
+
.map(([key]) => key);
|
|
48
|
+
|
|
49
|
+
const oldNames = _list.map((item) => item.name).filter(Boolean) as string[];
|
|
50
|
+
const addNames = difference(newNames, oldNames);
|
|
51
|
+
|
|
52
|
+
const next = _list
|
|
53
|
+
.filter((item) => !item.name || newNames.includes(item.name))
|
|
54
|
+
.map((item) => ({
|
|
55
|
+
key: item.key,
|
|
56
|
+
name: item.name,
|
|
57
|
+
isPropertyRequired: drilldownSchema?.required?.includes(item.name || '') || false,
|
|
58
|
+
...(drilldownSchema?.properties?.[item.name || ''] || item || {}),
|
|
59
|
+
}))
|
|
60
|
+
.concat(
|
|
61
|
+
addNames.map((_name) => ({
|
|
62
|
+
key: genId(),
|
|
63
|
+
name: _name,
|
|
64
|
+
isPropertyRequired: drilldownSchema?.required?.includes(_name) || false,
|
|
65
|
+
...(drilldownSchema?.properties?.[_name] || {}),
|
|
57
66
|
}))
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
...(drilldownSchema?.properties?.[_name] || {}),
|
|
64
|
-
}))
|
|
65
|
-
);
|
|
66
|
-
});
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
latestPropertyListRef.current = next;
|
|
70
|
+
|
|
71
|
+
setPropertyList(next);
|
|
67
72
|
}, [drilldownSchema]);
|
|
68
73
|
|
|
69
74
|
const updatePropertyList = (updater: (list: PropertyValueType[]) => PropertyValueType[]) => {
|
|
70
75
|
changeVersion.current = changeVersion.current + 1;
|
|
71
76
|
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
const next = updater(latestPropertyListRef.current);
|
|
78
|
+
latestPropertyListRef.current = next;
|
|
79
|
+
setPropertyList(next);
|
|
74
80
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
81
|
+
// onChange to parent
|
|
82
|
+
const nextProperties: Record<string, IJsonSchema> = {};
|
|
83
|
+
const nextRequired: string[] = [];
|
|
78
84
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
for (const _property of next) {
|
|
86
|
+
if (!_property.name) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
83
89
|
|
|
84
|
-
|
|
90
|
+
nextProperties[_property.name] = omit(_property, ['key', 'name', 'isPropertyRequired']);
|
|
85
91
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
92
|
+
if (_property.isPropertyRequired) {
|
|
93
|
+
nextRequired.push(_property.name);
|
|
89
94
|
}
|
|
95
|
+
}
|
|
90
96
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (propertiesParent) {
|
|
96
|
-
propertiesParent.properties = nextProperties;
|
|
97
|
-
propertiesParent.required = nextRequired;
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
})
|
|
101
|
-
);
|
|
97
|
+
onChange?.(
|
|
98
|
+
produce(value || {}, (draft) => {
|
|
99
|
+
const propertiesParent = typeManager.getPropertiesParent(draft);
|
|
102
100
|
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
if (propertiesParent) {
|
|
102
|
+
propertiesParent.properties = nextProperties;
|
|
103
|
+
propertiesParent.required = nextRequired;
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
);
|
|
105
108
|
};
|
|
106
109
|
|
|
107
110
|
const onAddProperty = () => {
|
|
108
|
-
|
|
109
|
-
|
|
111
|
+
const _list = latestPropertyListRef.current;
|
|
112
|
+
const next = [
|
|
110
113
|
..._list,
|
|
111
114
|
{ key: genId(), name: '', type: 'string', extra: { index: _list.length + 1 } },
|
|
112
|
-
]
|
|
115
|
+
];
|
|
116
|
+
|
|
117
|
+
latestPropertyListRef.current = next;
|
|
118
|
+
setPropertyList(next);
|
|
113
119
|
};
|
|
114
120
|
|
|
115
121
|
const onRemoveProperty = (key: number) => {
|
|
@@ -124,6 +130,7 @@ export function usePropertiesEdit(
|
|
|
124
130
|
|
|
125
131
|
useEffect(() => {
|
|
126
132
|
if (!canAddField) {
|
|
133
|
+
latestPropertyListRef.current = [];
|
|
127
134
|
setPropertyList([]);
|
|
128
135
|
}
|
|
129
136
|
}, [canAddField]);
|
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
|
+
import type { IInputsValues } from '@/shared/flow-value';
|
|
8
9
|
import { PromptEditor, PromptEditorPropsType } from '@/components/prompt-editor';
|
|
9
10
|
import { EditorInputsTree } from '@/components/coze-editor-extensions';
|
|
10
11
|
|
|
11
12
|
export interface PromptEditorWithInputsProps extends PromptEditorPropsType {
|
|
12
|
-
inputsValues:
|
|
13
|
+
inputsValues: IInputsValues;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export function PromptEditorWithInputs({
|
package/src/index.ts
CHANGED