@flowgram.ai/form-materials 0.1.30 → 0.2.0
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/materials.js +21 -5
- package/dist/esm/index.js +463 -57
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +171 -28
- package/dist/index.d.ts +171 -28
- package/dist/index.js +472 -60
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/components/batch-variable-selector/config.json +5 -0
- package/src/components/batch-variable-selector/index.tsx +18 -0
- package/src/components/constant-input/config.json +6 -0
- package/src/components/constant-input/index.tsx +81 -0
- package/src/components/constant-input/types.ts +18 -0
- package/src/components/dynamic-value-input/config.json +5 -0
- package/src/components/dynamic-value-input/index.tsx +77 -0
- package/src/components/dynamic-value-input/styles.tsx +19 -0
- package/src/components/index.ts +6 -3
- package/src/components/json-schema-editor/hooks.tsx +33 -22
- package/src/components/json-schema-editor/index.tsx +11 -7
- package/src/components/json-schema-editor/types.ts +7 -0
- package/src/components/type-selector/index.tsx +5 -2
- package/src/components/type-selector/types.ts +4 -18
- package/src/components/variable-selector/config.json +1 -1
- package/src/components/variable-selector/index.tsx +80 -16
- package/src/components/variable-selector/styles.tsx +43 -0
- package/src/components/variable-selector/use-variable-tree.tsx +29 -7
- package/src/effects/index.ts +2 -0
- package/src/effects/provide-batch-input/config.json +5 -0
- package/src/effects/provide-batch-input/index.ts +38 -0
- package/src/effects/provide-batch-outputs/config.json +5 -0
- package/src/effects/provide-batch-outputs/index.ts +34 -0
- package/src/index.ts +3 -0
- package/src/typings/flow-value/config.json +5 -0
- package/src/typings/flow-value/index.ts +27 -0
- package/src/typings/index.ts +1 -0
- package/src/utils/format-legacy-refs/config.json +5 -0
- package/src/utils/format-legacy-refs/index.ts +153 -0
- package/src/utils/format-legacy-refs/readme.md +38 -0
- package/src/utils/index.ts +1 -0
package/src/components/index.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export * from './variable-selector';
|
|
2
|
+
export * from './type-selector';
|
|
3
|
+
export * from './json-schema-editor';
|
|
4
|
+
export * from './batch-variable-selector';
|
|
5
|
+
export * from './constant-input';
|
|
6
|
+
export * from './dynamic-value-input';
|
|
@@ -36,15 +36,21 @@ export function usePropertiesEdit(
|
|
|
36
36
|
const initPropertyList = useMemo(
|
|
37
37
|
() =>
|
|
38
38
|
isDrilldownObject
|
|
39
|
-
? Object.entries(drilldown.schema?.properties || {})
|
|
40
|
-
([
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
? Object.entries(drilldown.schema?.properties || {})
|
|
40
|
+
.sort(([, a], [, b]) => (a.extra?.index ?? 0) - (b.extra?.index ?? 0))
|
|
41
|
+
.map(
|
|
42
|
+
([name, _value], index) =>
|
|
43
|
+
({
|
|
44
|
+
key: genId(),
|
|
45
|
+
name,
|
|
46
|
+
isPropertyRequired: drilldown.schema?.required?.includes(name) || false,
|
|
47
|
+
..._value,
|
|
48
|
+
extra: {
|
|
49
|
+
...(_value.extra || {}),
|
|
50
|
+
index,
|
|
51
|
+
},
|
|
52
|
+
} as PropertyValueType)
|
|
53
|
+
)
|
|
48
54
|
: [],
|
|
49
55
|
[isDrilldownObject]
|
|
50
56
|
);
|
|
@@ -65,23 +71,25 @@ export function usePropertiesEdit(
|
|
|
65
71
|
nameMap.set(_property.name, _property);
|
|
66
72
|
}
|
|
67
73
|
}
|
|
68
|
-
return Object.entries(drilldown.schema?.properties || {})
|
|
69
|
-
|
|
70
|
-
|
|
74
|
+
return Object.entries(drilldown.schema?.properties || {})
|
|
75
|
+
.sort(([, a], [, b]) => (a.extra?.index ?? 0) - (b.extra?.index ?? 0))
|
|
76
|
+
.map(([name, _value]) => {
|
|
77
|
+
const _property = nameMap.get(name);
|
|
78
|
+
if (_property) {
|
|
79
|
+
return {
|
|
80
|
+
key: _property.key,
|
|
81
|
+
name,
|
|
82
|
+
isPropertyRequired: drilldown.schema?.required?.includes(name) || false,
|
|
83
|
+
..._value,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
71
86
|
return {
|
|
72
|
-
key:
|
|
87
|
+
key: genId(),
|
|
73
88
|
name,
|
|
74
89
|
isPropertyRequired: drilldown.schema?.required?.includes(name) || false,
|
|
75
90
|
..._value,
|
|
76
91
|
};
|
|
77
|
-
}
|
|
78
|
-
return {
|
|
79
|
-
key: genId(),
|
|
80
|
-
name,
|
|
81
|
-
isPropertyRequired: drilldown.schema?.required?.includes(name) || false,
|
|
82
|
-
..._value,
|
|
83
|
-
};
|
|
84
|
-
});
|
|
92
|
+
});
|
|
85
93
|
});
|
|
86
94
|
}
|
|
87
95
|
mountRef.current = true;
|
|
@@ -121,7 +129,10 @@ export function usePropertiesEdit(
|
|
|
121
129
|
};
|
|
122
130
|
|
|
123
131
|
const onAddProperty = () => {
|
|
124
|
-
updatePropertyList((_list) => [
|
|
132
|
+
updatePropertyList((_list) => [
|
|
133
|
+
..._list,
|
|
134
|
+
{ key: genId(), name: '', type: 'string', extra: { index: _list.length + 1 } },
|
|
135
|
+
]);
|
|
125
136
|
};
|
|
126
137
|
|
|
127
138
|
const onRemoveProperty = (key: number) => {
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
|
|
13
13
|
import { JsonSchema } from '../type-selector/types';
|
|
14
14
|
import { TypeSelector } from '../type-selector';
|
|
15
|
-
import { PropertyValueType } from './types';
|
|
15
|
+
import { ConfigType, PropertyValueType } from './types';
|
|
16
16
|
import {
|
|
17
17
|
IconAddChildren,
|
|
18
18
|
UIActions,
|
|
@@ -35,8 +35,9 @@ import { usePropertiesEdit } from './hooks';
|
|
|
35
35
|
export function JsonSchemaEditor(props: {
|
|
36
36
|
value?: JsonSchema;
|
|
37
37
|
onChange?: (value: JsonSchema) => void;
|
|
38
|
+
config?: ConfigType;
|
|
38
39
|
}) {
|
|
39
|
-
const { value = { type: 'object' }, onChange: onChangeProps } = props;
|
|
40
|
+
const { value = { type: 'object' }, config = {}, onChange: onChangeProps } = props;
|
|
40
41
|
const { propertyList, onAddProperty, onRemoveProperty, onEditProperty } = usePropertiesEdit(
|
|
41
42
|
value,
|
|
42
43
|
onChangeProps
|
|
@@ -49,6 +50,7 @@ export function JsonSchemaEditor(props: {
|
|
|
49
50
|
<PropertyEdit
|
|
50
51
|
key={_property.key}
|
|
51
52
|
value={_property}
|
|
53
|
+
config={config}
|
|
52
54
|
onChange={(_v) => {
|
|
53
55
|
onEditProperty(_property.key!, _v);
|
|
54
56
|
}}
|
|
@@ -59,7 +61,7 @@ export function JsonSchemaEditor(props: {
|
|
|
59
61
|
))}
|
|
60
62
|
</UIProperties>
|
|
61
63
|
<Button size="small" style={{ marginTop: 10 }} icon={<IconPlus />} onClick={onAddProperty}>
|
|
62
|
-
Add
|
|
64
|
+
{config?.addButtonText ?? 'Add'}
|
|
63
65
|
</Button>
|
|
64
66
|
</UIContainer>
|
|
65
67
|
);
|
|
@@ -67,12 +69,13 @@ export function JsonSchemaEditor(props: {
|
|
|
67
69
|
|
|
68
70
|
function PropertyEdit(props: {
|
|
69
71
|
value?: PropertyValueType;
|
|
72
|
+
config?: ConfigType;
|
|
70
73
|
onChange?: (value: PropertyValueType) => void;
|
|
71
74
|
onRemove?: () => void;
|
|
72
75
|
$isLast?: boolean;
|
|
73
76
|
$showLine?: boolean;
|
|
74
77
|
}) {
|
|
75
|
-
const { value, onChange: onChangeProps, onRemove, $isLast, $showLine } = props;
|
|
78
|
+
const { value, config, onChange: onChangeProps, onRemove, $isLast, $showLine } = props;
|
|
76
79
|
|
|
77
80
|
const [expand, setExpand] = useState(false);
|
|
78
81
|
const [collapse, setCollapse] = useState(false);
|
|
@@ -107,7 +110,7 @@ function PropertyEdit(props: {
|
|
|
107
110
|
<UIRow>
|
|
108
111
|
<UIName>
|
|
109
112
|
<Input
|
|
110
|
-
placeholder=
|
|
113
|
+
placeholder={config?.placeholder ?? 'Input Variable Name'}
|
|
111
114
|
size="small"
|
|
112
115
|
value={name}
|
|
113
116
|
onChange={(value) => onChange('name', value)}
|
|
@@ -158,12 +161,12 @@ function PropertyEdit(props: {
|
|
|
158
161
|
</UIRow>
|
|
159
162
|
{expand && (
|
|
160
163
|
<UIExpandDetail>
|
|
161
|
-
<UILabel>Description</UILabel>
|
|
164
|
+
<UILabel>{config?.descTitle ?? 'Description'}</UILabel>
|
|
162
165
|
<Input
|
|
163
166
|
size="small"
|
|
164
167
|
value={description}
|
|
165
168
|
onChange={(value) => onChange('description', value)}
|
|
166
|
-
placeholder=
|
|
169
|
+
placeholder={config?.descPlaceholder ?? 'Help LLM to understand the property'}
|
|
167
170
|
/>
|
|
168
171
|
</UIExpandDetail>
|
|
169
172
|
)}
|
|
@@ -175,6 +178,7 @@ function PropertyEdit(props: {
|
|
|
175
178
|
<PropertyEdit
|
|
176
179
|
key={_property.key}
|
|
177
180
|
value={_property}
|
|
181
|
+
config={config}
|
|
178
182
|
onChange={(_v) => {
|
|
179
183
|
onEditProperty(_property.key!, _v);
|
|
180
184
|
}}
|
|
@@ -9,3 +9,10 @@ export interface PropertyValueType extends JsonSchema {
|
|
|
9
9
|
export type PropertiesValueType = Pick<PropertyValueType, 'properties' | 'required'>;
|
|
10
10
|
|
|
11
11
|
export type JsonSchemaProperties = JsonSchema['properties'];
|
|
12
|
+
|
|
13
|
+
export interface ConfigType {
|
|
14
|
+
placeholder?: string;
|
|
15
|
+
descTitle?: string;
|
|
16
|
+
descPlaceholder?: string;
|
|
17
|
+
addButtonText?: string;
|
|
18
|
+
}
|
|
@@ -8,6 +8,8 @@ import { ArrayIcons, VariableTypeIcons, getSchemaIcon, options } from './constan
|
|
|
8
8
|
interface PropTypes {
|
|
9
9
|
value?: Partial<JsonSchema>;
|
|
10
10
|
onChange: (value?: Partial<JsonSchema>) => void;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
style?: React.CSSProperties;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
export const getTypeSelectValue = (value?: Partial<JsonSchema>): string[] | undefined => {
|
|
@@ -29,15 +31,16 @@ export const parseTypeSelectValue = (value?: string[]): Partial<JsonSchema> | un
|
|
|
29
31
|
};
|
|
30
32
|
|
|
31
33
|
export function TypeSelector(props: PropTypes) {
|
|
32
|
-
const { value, onChange } = props;
|
|
34
|
+
const { value, onChange, disabled, style } = props;
|
|
33
35
|
|
|
34
36
|
const selectValue = useMemo(() => getTypeSelectValue(value), [value]);
|
|
35
37
|
|
|
36
38
|
return (
|
|
37
39
|
<Cascader
|
|
40
|
+
disabled={disabled}
|
|
38
41
|
size="small"
|
|
39
42
|
triggerRender={() => (
|
|
40
|
-
<Button size="small" style={
|
|
43
|
+
<Button size="small" style={style}>
|
|
41
44
|
{getSchemaIcon(value)}
|
|
42
45
|
</Button>
|
|
43
46
|
)}
|
|
@@ -1,19 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { VarJSONSchema } from '@flowgram.ai/editor';
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
title?: string;
|
|
7
|
-
description?: string;
|
|
8
|
-
enum?: (string | number)[];
|
|
9
|
-
properties?: Record<string, JsonSchema>;
|
|
10
|
-
additionalProperties?: JsonSchema;
|
|
11
|
-
items?: JsonSchema;
|
|
12
|
-
required?: string[];
|
|
13
|
-
$ref?: string;
|
|
14
|
-
extra?: {
|
|
15
|
-
order?: number;
|
|
16
|
-
literal?: boolean; // is literal type
|
|
17
|
-
formComponent?: string; // Set the render component
|
|
18
|
-
};
|
|
19
|
-
}
|
|
3
|
+
export type BasicType = VarJSONSchema.BasicType;
|
|
4
|
+
|
|
5
|
+
export type JsonSchema = VarJSONSchema.ISchema;
|
|
@@ -1,44 +1,108 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { VarJSONSchema } from '@flowgram.ai/editor';
|
|
4
|
+
import { TriggerRenderProps } from '@douyinfe/semi-ui/lib/es/treeSelect';
|
|
5
|
+
import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
|
|
6
|
+
import { IconChevronDownStroked, IconIssueStroked } from '@douyinfe/semi-icons';
|
|
4
7
|
|
|
5
8
|
import { useVariableTree } from './use-variable-tree';
|
|
9
|
+
import { UIRootTitle, UITag, UITreeSelect } from './styles';
|
|
6
10
|
|
|
7
|
-
|
|
8
|
-
value?: string;
|
|
9
|
-
|
|
11
|
+
interface PropTypes {
|
|
12
|
+
value?: string[];
|
|
13
|
+
config?: {
|
|
14
|
+
placeholder?: string;
|
|
15
|
+
notFoundContent?: string;
|
|
16
|
+
};
|
|
17
|
+
onChange: (value?: string[]) => void;
|
|
18
|
+
includeSchema?: VarJSONSchema.ISchema | VarJSONSchema.ISchema[];
|
|
19
|
+
excludeSchema?: VarJSONSchema.ISchema | VarJSONSchema.ISchema[];
|
|
10
20
|
readonly?: boolean;
|
|
11
21
|
hasError?: boolean;
|
|
12
22
|
style?: React.CSSProperties;
|
|
23
|
+
triggerRender?: (props: TriggerRenderProps) => React.ReactNode;
|
|
13
24
|
}
|
|
14
25
|
|
|
26
|
+
export type VariableSelectorProps = PropTypes;
|
|
27
|
+
|
|
15
28
|
export const VariableSelector = ({
|
|
16
29
|
value,
|
|
30
|
+
config,
|
|
17
31
|
onChange,
|
|
18
32
|
style,
|
|
19
33
|
readonly = false,
|
|
34
|
+
includeSchema,
|
|
35
|
+
excludeSchema,
|
|
20
36
|
hasError,
|
|
37
|
+
triggerRender,
|
|
21
38
|
}: PropTypes) => {
|
|
22
|
-
const treeData = useVariableTree();
|
|
39
|
+
const treeData = useVariableTree({ includeSchema, excludeSchema });
|
|
40
|
+
|
|
41
|
+
const treeValue = useMemo(() => {
|
|
42
|
+
if (typeof value === 'string') {
|
|
43
|
+
console.warn(
|
|
44
|
+
'The Value of VariableSelector is a string, it should be an ARRAY. \n',
|
|
45
|
+
'Please check the value of VariableSelector \n'
|
|
46
|
+
);
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
return value?.join('.');
|
|
50
|
+
}, [value]);
|
|
51
|
+
|
|
52
|
+
const renderIcon = (icon: string | JSX.Element) => {
|
|
53
|
+
if (typeof icon === 'string') {
|
|
54
|
+
return <img style={{ marginRight: 8 }} width={12} height={12} src={icon} />;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return icon;
|
|
58
|
+
};
|
|
23
59
|
|
|
24
60
|
return (
|
|
25
61
|
<>
|
|
26
|
-
<
|
|
62
|
+
<UITreeSelect
|
|
27
63
|
dropdownMatchSelectWidth={false}
|
|
28
64
|
disabled={readonly}
|
|
29
65
|
treeData={treeData}
|
|
30
66
|
size="small"
|
|
31
|
-
value={
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}}
|
|
67
|
+
value={treeValue}
|
|
68
|
+
clearIcon={null}
|
|
69
|
+
$error={hasError}
|
|
70
|
+
style={style}
|
|
36
71
|
validateStatus={hasError ? 'error' : undefined}
|
|
37
|
-
onChange={(
|
|
38
|
-
onChange(
|
|
72
|
+
onChange={(_, _config) => {
|
|
73
|
+
onChange((_config as TreeNodeData).keyPath as string[]);
|
|
74
|
+
}}
|
|
75
|
+
renderSelectedItem={(_option: TreeNodeData) => {
|
|
76
|
+
if (!_option?.keyPath) {
|
|
77
|
+
return (
|
|
78
|
+
<UITag
|
|
79
|
+
prefixIcon={<IconIssueStroked />}
|
|
80
|
+
color="amber"
|
|
81
|
+
closable={!readonly}
|
|
82
|
+
onClose={() => onChange(undefined)}
|
|
83
|
+
>
|
|
84
|
+
{config?.notFoundContent ?? 'Undefined'}
|
|
85
|
+
</UITag>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<UITag
|
|
91
|
+
prefixIcon={renderIcon(_option.rootMeta?.icon || _option?.icon)}
|
|
92
|
+
closable={!readonly}
|
|
93
|
+
onClose={() => onChange(undefined)}
|
|
94
|
+
>
|
|
95
|
+
<UIRootTitle>
|
|
96
|
+
{_option.rootMeta?.title ? `${_option.rootMeta?.title} -` : null}
|
|
97
|
+
</UIRootTitle>
|
|
98
|
+
{_option.label}
|
|
99
|
+
</UITag>
|
|
100
|
+
);
|
|
39
101
|
}}
|
|
40
|
-
showClear
|
|
41
|
-
|
|
102
|
+
showClear={false}
|
|
103
|
+
arrowIcon={value ? null : <IconChevronDownStroked size="small" />}
|
|
104
|
+
triggerRender={triggerRender}
|
|
105
|
+
placeholder={config?.placeholder ?? 'Select Variable...'}
|
|
42
106
|
/>
|
|
43
107
|
</>
|
|
44
108
|
);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
import { Tag, TreeSelect } from '@douyinfe/semi-ui';
|
|
3
|
+
|
|
4
|
+
export const UIRootTitle = styled.span`
|
|
5
|
+
margin-right: 4px;
|
|
6
|
+
color: var(--semi-color-text-2);
|
|
7
|
+
`;
|
|
8
|
+
|
|
9
|
+
export const UITag = styled(Tag)`
|
|
10
|
+
width: 100%;
|
|
11
|
+
display: flex;
|
|
12
|
+
align-items: center;
|
|
13
|
+
justify-content: flex-start;
|
|
14
|
+
|
|
15
|
+
& .semi-tag-content-center {
|
|
16
|
+
justify-content: flex-start;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
&.semi-tag {
|
|
20
|
+
margin: 0;
|
|
21
|
+
}
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
export const UITreeSelect = styled(TreeSelect)<{ $error?: boolean }>`
|
|
25
|
+
outline: ${({ $error }) => ($error ? '1px solid red' : 'none')};
|
|
26
|
+
|
|
27
|
+
height: 22px;
|
|
28
|
+
min-height: 22px;
|
|
29
|
+
line-height: 22px;
|
|
30
|
+
|
|
31
|
+
& .semi-tree-select-selection {
|
|
32
|
+
padding: 0 2px;
|
|
33
|
+
height: 22px;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
& .semi-tree-select-selection-content {
|
|
37
|
+
width: 100%;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
& .semi-tree-select-selection-placeholder {
|
|
41
|
+
padding-left: 10px;
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
2
|
|
|
3
|
-
import { useScopeAvailable, ASTMatch, BaseVariableField } from '@flowgram.ai/editor';
|
|
3
|
+
import { useScopeAvailable, ASTMatch, BaseVariableField, VarJSONSchema } from '@flowgram.ai/editor';
|
|
4
4
|
import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
|
|
5
5
|
import { Icon } from '@douyinfe/semi-ui';
|
|
6
6
|
|
|
@@ -8,11 +8,16 @@ import { ArrayIcons, VariableTypeIcons } from '../type-selector/constants';
|
|
|
8
8
|
|
|
9
9
|
type VariableField = BaseVariableField<{ icon?: string | JSX.Element; title?: string }>;
|
|
10
10
|
|
|
11
|
-
export function useVariableTree(
|
|
11
|
+
export function useVariableTree(params: {
|
|
12
|
+
includeSchema?: VarJSONSchema.ISchema | VarJSONSchema.ISchema[];
|
|
13
|
+
excludeSchema?: VarJSONSchema.ISchema | VarJSONSchema.ISchema[];
|
|
14
|
+
}): TreeNodeData[] {
|
|
15
|
+
const { includeSchema, excludeSchema } = params;
|
|
16
|
+
|
|
12
17
|
const available = useScopeAvailable();
|
|
13
18
|
|
|
14
19
|
const getVariableTypeIcon = useCallback((variable: VariableField) => {
|
|
15
|
-
if (variable.meta
|
|
20
|
+
if (variable.meta?.icon) {
|
|
16
21
|
if (typeof variable.meta.icon === 'string') {
|
|
17
22
|
return <img style={{ marginRight: 8 }} width={12} height={12} src={variable.meta.icon} />;
|
|
18
23
|
}
|
|
@@ -44,6 +49,10 @@ export function useVariableTree(): TreeNodeData[] {
|
|
|
44
49
|
): TreeNodeData | null => {
|
|
45
50
|
let type = variable?.type;
|
|
46
51
|
|
|
52
|
+
if (!type) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
47
56
|
let children: TreeNodeData[] | undefined;
|
|
48
57
|
|
|
49
58
|
if (ASTMatch.isObject(type)) {
|
|
@@ -56,14 +65,27 @@ export function useVariableTree(): TreeNodeData[] {
|
|
|
56
65
|
}
|
|
57
66
|
}
|
|
58
67
|
|
|
59
|
-
const
|
|
68
|
+
const keyPath = [...parentFields.map((_field) => _field.key), variable.key];
|
|
69
|
+
const key = keyPath.join('.');
|
|
70
|
+
|
|
71
|
+
const isSchemaInclude = includeSchema ? type.isEqualWithJSONSchema(includeSchema) : true;
|
|
72
|
+
const isSchemaExclude = excludeSchema ? type.isEqualWithJSONSchema(excludeSchema) : false;
|
|
73
|
+
const isSchemaMatch = isSchemaInclude && !isSchemaExclude;
|
|
74
|
+
|
|
75
|
+
// If not match, and no children, return null
|
|
76
|
+
if (!isSchemaMatch && !children?.length) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
60
79
|
|
|
61
80
|
return {
|
|
62
|
-
key:
|
|
63
|
-
label: variable.meta
|
|
64
|
-
value:
|
|
81
|
+
key: key,
|
|
82
|
+
label: variable.meta?.title || variable.key,
|
|
83
|
+
value: key,
|
|
84
|
+
keyPath,
|
|
65
85
|
icon: getVariableTypeIcon(variable),
|
|
66
86
|
children,
|
|
87
|
+
disabled: !isSchemaMatch,
|
|
88
|
+
rootMeta: parentFields[0]?.meta,
|
|
67
89
|
};
|
|
68
90
|
};
|
|
69
91
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ASTFactory,
|
|
3
|
+
EffectOptions,
|
|
4
|
+
FlowNodeRegistry,
|
|
5
|
+
createEffectFromVariableProvider,
|
|
6
|
+
getNodeForm,
|
|
7
|
+
} from '@flowgram.ai/editor';
|
|
8
|
+
|
|
9
|
+
import { IFlowRefValue } from '../../typings';
|
|
10
|
+
|
|
11
|
+
export const provideBatchInputEffect: EffectOptions[] = createEffectFromVariableProvider({
|
|
12
|
+
private: true,
|
|
13
|
+
parse: (value: IFlowRefValue, ctx) => [
|
|
14
|
+
ASTFactory.createVariableDeclaration({
|
|
15
|
+
key: `${ctx.node.id}_locals`,
|
|
16
|
+
meta: {
|
|
17
|
+
title: getNodeForm(ctx.node)?.getValueIn('title'),
|
|
18
|
+
icon: ctx.node.getNodeRegistry<FlowNodeRegistry>().info?.icon,
|
|
19
|
+
},
|
|
20
|
+
type: ASTFactory.createObject({
|
|
21
|
+
properties: [
|
|
22
|
+
ASTFactory.createProperty({
|
|
23
|
+
key: 'item',
|
|
24
|
+
initializer: ASTFactory.createEnumerateExpression({
|
|
25
|
+
enumerateFor: ASTFactory.createKeyPathExpression({
|
|
26
|
+
keyPath: value.content || [],
|
|
27
|
+
}),
|
|
28
|
+
}),
|
|
29
|
+
}),
|
|
30
|
+
ASTFactory.createProperty({
|
|
31
|
+
key: 'index',
|
|
32
|
+
type: ASTFactory.createNumber(),
|
|
33
|
+
}),
|
|
34
|
+
],
|
|
35
|
+
}),
|
|
36
|
+
}),
|
|
37
|
+
],
|
|
38
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ASTFactory,
|
|
3
|
+
EffectOptions,
|
|
4
|
+
FlowNodeRegistry,
|
|
5
|
+
createEffectFromVariableProvider,
|
|
6
|
+
getNodeForm,
|
|
7
|
+
} from '@flowgram.ai/editor';
|
|
8
|
+
|
|
9
|
+
import { IFlowRefValue } from '../../typings';
|
|
10
|
+
|
|
11
|
+
export const provideBatchOutputsEffect: EffectOptions[] = createEffectFromVariableProvider({
|
|
12
|
+
private: true,
|
|
13
|
+
parse: (value: Record<string, IFlowRefValue>, ctx) => [
|
|
14
|
+
ASTFactory.createVariableDeclaration({
|
|
15
|
+
key: `${ctx.node.id}`,
|
|
16
|
+
meta: {
|
|
17
|
+
title: getNodeForm(ctx.node)?.getValueIn('title'),
|
|
18
|
+
icon: ctx.node.getNodeRegistry<FlowNodeRegistry>().info?.icon,
|
|
19
|
+
},
|
|
20
|
+
type: ASTFactory.createObject({
|
|
21
|
+
properties: Object.entries(value).map(([_key, value]) =>
|
|
22
|
+
ASTFactory.createProperty({
|
|
23
|
+
key: _key,
|
|
24
|
+
initializer: ASTFactory.createWrapArrayExpression({
|
|
25
|
+
wrapFor: ASTFactory.createKeyPathExpression({
|
|
26
|
+
keyPath: value.content || [],
|
|
27
|
+
}),
|
|
28
|
+
}),
|
|
29
|
+
})
|
|
30
|
+
),
|
|
31
|
+
}),
|
|
32
|
+
}),
|
|
33
|
+
],
|
|
34
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface IFlowConstantValue {
|
|
2
|
+
type: 'constant';
|
|
3
|
+
content?: string | number | boolean;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface IFlowRefValue {
|
|
7
|
+
type: 'ref';
|
|
8
|
+
content?: string[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface IFlowExpressionValue {
|
|
12
|
+
type: 'expression';
|
|
13
|
+
content?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface IFlowTemplateValue {
|
|
17
|
+
type: 'template';
|
|
18
|
+
content?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type IFlowValue =
|
|
22
|
+
| IFlowConstantValue
|
|
23
|
+
| IFlowRefValue
|
|
24
|
+
| IFlowExpressionValue
|
|
25
|
+
| IFlowTemplateValue;
|
|
26
|
+
|
|
27
|
+
export type IFlowConstantRefValue = IFlowConstantValue | IFlowRefValue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './flow-value';
|