@flowgram.ai/form-materials 0.1.31 → 0.2.1
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 +570 -54
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +206 -28
- package/dist/index.d.ts +206 -28
- package/dist/index.js +582 -59
- 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 +19 -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/config.json +1 -1
- package/src/components/json-schema-editor/hooks.tsx +35 -24
- package/src/components/json-schema-editor/index.tsx +3 -3
- package/src/components/json-schema-editor/types.ts +3 -3
- package/src/components/type-selector/config.json +1 -1
- package/src/components/type-selector/constants.tsx +2 -2
- package/src/components/type-selector/index.tsx +11 -8
- package/src/components/variable-selector/config.json +2 -2
- package/src/components/variable-selector/index.tsx +76 -16
- package/src/components/variable-selector/styles.tsx +43 -0
- package/src/components/variable-selector/use-variable-tree.tsx +34 -6
- 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 +2 -0
- package/src/typings/json-schema/config.json +5 -0
- package/src/typings/json-schema/index.ts +31 -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 +2 -0
- package/src/utils/json-schema/config.json +5 -0
- package/src/utils/json-schema/index.ts +154 -0
- package/src/components/type-selector/types.ts +0 -19
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
|
|
3
|
+
export const UIContainer = styled.div`
|
|
4
|
+
display: flex;
|
|
5
|
+
align-items: center;
|
|
6
|
+
gap: 5px;
|
|
7
|
+
`;
|
|
8
|
+
|
|
9
|
+
export const UIMain = styled.div`
|
|
10
|
+
flex-grow: 1;
|
|
11
|
+
|
|
12
|
+
& .semi-tree-select,
|
|
13
|
+
& .semi-input-number,
|
|
14
|
+
& .semi-select {
|
|
15
|
+
width: 100%;
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
export const UITrigger = styled.div``;
|
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';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
2
|
|
|
3
|
+
import { IJsonSchema } from '../../typings';
|
|
3
4
|
import { PropertyValueType } from './types';
|
|
4
|
-
import { JsonSchema } from '../type-selector';
|
|
5
5
|
|
|
6
6
|
let _id = 0;
|
|
7
7
|
function genId() {
|
|
@@ -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;
|
|
@@ -92,7 +100,7 @@ export function usePropertiesEdit(
|
|
|
92
100
|
const next = updater(_list);
|
|
93
101
|
|
|
94
102
|
// onChange to parent
|
|
95
|
-
const nextProperties: Record<string,
|
|
103
|
+
const nextProperties: Record<string, IJsonSchema> = {};
|
|
96
104
|
const nextRequired: string[] = [];
|
|
97
105
|
|
|
98
106
|
for (const _property of next) {
|
|
@@ -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) => {
|
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
IconMinus,
|
|
11
11
|
} from '@douyinfe/semi-icons';
|
|
12
12
|
|
|
13
|
-
import { JsonSchema } from '../type-selector/types';
|
|
14
13
|
import { TypeSelector } from '../type-selector';
|
|
14
|
+
import { IJsonSchema } from '../../typings';
|
|
15
15
|
import { ConfigType, PropertyValueType } from './types';
|
|
16
16
|
import {
|
|
17
17
|
IconAddChildren,
|
|
@@ -33,8 +33,8 @@ import { UIRow } from './styles';
|
|
|
33
33
|
import { usePropertiesEdit } from './hooks';
|
|
34
34
|
|
|
35
35
|
export function JsonSchemaEditor(props: {
|
|
36
|
-
value?:
|
|
37
|
-
onChange?: (value:
|
|
36
|
+
value?: IJsonSchema;
|
|
37
|
+
onChange?: (value: IJsonSchema) => void;
|
|
38
38
|
config?: ConfigType;
|
|
39
39
|
}) {
|
|
40
40
|
const { value = { type: 'object' }, config = {}, onChange: onChangeProps } = props;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IJsonSchema } from '../../typings';
|
|
2
2
|
|
|
3
|
-
export interface PropertyValueType extends
|
|
3
|
+
export interface PropertyValueType extends IJsonSchema {
|
|
4
4
|
name?: string;
|
|
5
5
|
key?: number;
|
|
6
6
|
isPropertyRequired?: boolean;
|
|
@@ -8,7 +8,7 @@ export interface PropertyValueType extends JsonSchema {
|
|
|
8
8
|
|
|
9
9
|
export type PropertiesValueType = Pick<PropertyValueType, 'properties' | 'required'>;
|
|
10
10
|
|
|
11
|
-
export type JsonSchemaProperties =
|
|
11
|
+
export type JsonSchemaProperties = IJsonSchema['properties'];
|
|
12
12
|
|
|
13
13
|
export interface ConfigType {
|
|
14
14
|
placeholder?: string;
|
|
@@ -3,7 +3,7 @@ import React from 'react';
|
|
|
3
3
|
import { CascaderData } from '@douyinfe/semi-ui/lib/es/cascader';
|
|
4
4
|
import Icon from '@douyinfe/semi-icons';
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { IJsonSchema } from '../../typings';
|
|
7
7
|
|
|
8
8
|
export const VariableTypeIcons: { [key: string]: React.ReactNode } = {
|
|
9
9
|
custom: (
|
|
@@ -271,7 +271,7 @@ export const ArrayIcons: { [key: string]: React.ReactNode } = {
|
|
|
271
271
|
),
|
|
272
272
|
};
|
|
273
273
|
|
|
274
|
-
export const getSchemaIcon = (value?: Partial<
|
|
274
|
+
export const getSchemaIcon = (value?: Partial<IJsonSchema>) => {
|
|
275
275
|
if (value?.type === 'array') {
|
|
276
276
|
return ArrayIcons[value.items?.type || 'object'];
|
|
277
277
|
}
|
|
@@ -2,15 +2,17 @@ import React, { useMemo } from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { Button, Cascader } from '@douyinfe/semi-ui';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { IJsonSchema } from '../../typings';
|
|
6
6
|
import { ArrayIcons, VariableTypeIcons, getSchemaIcon, options } from './constants';
|
|
7
7
|
|
|
8
8
|
interface PropTypes {
|
|
9
|
-
value?: Partial<
|
|
10
|
-
onChange: (value?: Partial<
|
|
9
|
+
value?: Partial<IJsonSchema>;
|
|
10
|
+
onChange: (value?: Partial<IJsonSchema>) => void;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
style?: React.CSSProperties;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
export const getTypeSelectValue = (value?: Partial<
|
|
15
|
+
export const getTypeSelectValue = (value?: Partial<IJsonSchema>): string[] | undefined => {
|
|
14
16
|
if (value?.type === 'array' && value?.items) {
|
|
15
17
|
return [value.type, ...(getTypeSelectValue(value.items) || [])];
|
|
16
18
|
}
|
|
@@ -18,7 +20,7 @@ export const getTypeSelectValue = (value?: Partial<JsonSchema>): string[] | unde
|
|
|
18
20
|
return value?.type ? [value.type] : undefined;
|
|
19
21
|
};
|
|
20
22
|
|
|
21
|
-
export const parseTypeSelectValue = (value?: string[]): Partial<
|
|
23
|
+
export const parseTypeSelectValue = (value?: string[]): Partial<IJsonSchema> | undefined => {
|
|
22
24
|
const [type, ...subTypes] = value || [];
|
|
23
25
|
|
|
24
26
|
if (type === 'array') {
|
|
@@ -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
|
)}
|
|
@@ -51,4 +54,4 @@ export function TypeSelector(props: PropTypes) {
|
|
|
51
54
|
);
|
|
52
55
|
}
|
|
53
56
|
|
|
54
|
-
export {
|
|
57
|
+
export { VariableTypeIcons, ArrayIcons, getSchemaIcon };
|
|
@@ -1,47 +1,107 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { TriggerRenderProps } from '@douyinfe/semi-ui/lib/es/treeSelect';
|
|
4
|
+
import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
|
|
5
|
+
import { IconChevronDownStroked, IconIssueStroked } from '@douyinfe/semi-icons';
|
|
4
6
|
|
|
7
|
+
import { IJsonSchema } from '../../typings/json-schema';
|
|
5
8
|
import { useVariableTree } from './use-variable-tree';
|
|
9
|
+
import { UIRootTitle, UITag, UITreeSelect } from './styles';
|
|
6
10
|
|
|
7
|
-
|
|
8
|
-
value?: string;
|
|
9
|
-
config
|
|
11
|
+
interface PropTypes {
|
|
12
|
+
value?: string[];
|
|
13
|
+
config?: {
|
|
10
14
|
placeholder?: string;
|
|
15
|
+
notFoundContent?: string;
|
|
11
16
|
};
|
|
12
|
-
onChange: (value?: string) => void;
|
|
17
|
+
onChange: (value?: string[]) => void;
|
|
18
|
+
includeSchema?: IJsonSchema | IJsonSchema[];
|
|
19
|
+
excludeSchema?: IJsonSchema | IJsonSchema[];
|
|
13
20
|
readonly?: boolean;
|
|
14
21
|
hasError?: boolean;
|
|
15
22
|
style?: React.CSSProperties;
|
|
23
|
+
triggerRender?: (props: TriggerRenderProps) => React.ReactNode;
|
|
16
24
|
}
|
|
17
25
|
|
|
26
|
+
export type VariableSelectorProps = PropTypes;
|
|
27
|
+
|
|
18
28
|
export const VariableSelector = ({
|
|
19
29
|
value,
|
|
20
30
|
config,
|
|
21
31
|
onChange,
|
|
22
32
|
style,
|
|
23
33
|
readonly = false,
|
|
34
|
+
includeSchema,
|
|
35
|
+
excludeSchema,
|
|
24
36
|
hasError,
|
|
37
|
+
triggerRender,
|
|
25
38
|
}: PropTypes) => {
|
|
26
|
-
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
|
+
};
|
|
27
59
|
|
|
28
60
|
return (
|
|
29
61
|
<>
|
|
30
|
-
<
|
|
62
|
+
<UITreeSelect
|
|
31
63
|
dropdownMatchSelectWidth={false}
|
|
32
64
|
disabled={readonly}
|
|
33
65
|
treeData={treeData}
|
|
34
66
|
size="small"
|
|
35
|
-
value={
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}}
|
|
67
|
+
value={treeValue}
|
|
68
|
+
clearIcon={null}
|
|
69
|
+
$error={hasError}
|
|
70
|
+
style={style}
|
|
40
71
|
validateStatus={hasError ? 'error' : undefined}
|
|
41
|
-
onChange={(
|
|
42
|
-
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
|
+
);
|
|
43
101
|
}}
|
|
44
|
-
showClear
|
|
102
|
+
showClear={false}
|
|
103
|
+
arrowIcon={value ? null : <IconChevronDownStroked size="small" />}
|
|
104
|
+
triggerRender={triggerRender}
|
|
45
105
|
placeholder={config?.placeholder ?? 'Select Variable...'}
|
|
46
106
|
/>
|
|
47
107
|
</>
|
|
@@ -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
|
+
`;
|
|
@@ -5,14 +5,21 @@ import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
|
|
|
5
5
|
import { Icon } from '@douyinfe/semi-ui';
|
|
6
6
|
|
|
7
7
|
import { ArrayIcons, VariableTypeIcons } from '../type-selector/constants';
|
|
8
|
+
import { JsonSchemaUtils } from '../../utils/json-schema';
|
|
9
|
+
import { IJsonSchema } from '../../typings/json-schema';
|
|
8
10
|
|
|
9
11
|
type VariableField = BaseVariableField<{ icon?: string | JSX.Element; title?: string }>;
|
|
10
12
|
|
|
11
|
-
export function useVariableTree(
|
|
13
|
+
export function useVariableTree(params: {
|
|
14
|
+
includeSchema?: IJsonSchema | IJsonSchema[];
|
|
15
|
+
excludeSchema?: IJsonSchema | IJsonSchema[];
|
|
16
|
+
}): TreeNodeData[] {
|
|
17
|
+
const { includeSchema, excludeSchema } = params;
|
|
18
|
+
|
|
12
19
|
const available = useScopeAvailable();
|
|
13
20
|
|
|
14
21
|
const getVariableTypeIcon = useCallback((variable: VariableField) => {
|
|
15
|
-
if (variable.meta
|
|
22
|
+
if (variable.meta?.icon) {
|
|
16
23
|
if (typeof variable.meta.icon === 'string') {
|
|
17
24
|
return <img style={{ marginRight: 8 }} width={12} height={12} src={variable.meta.icon} />;
|
|
18
25
|
}
|
|
@@ -44,6 +51,10 @@ export function useVariableTree(): TreeNodeData[] {
|
|
|
44
51
|
): TreeNodeData | null => {
|
|
45
52
|
let type = variable?.type;
|
|
46
53
|
|
|
54
|
+
if (!type) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
47
58
|
let children: TreeNodeData[] | undefined;
|
|
48
59
|
|
|
49
60
|
if (ASTMatch.isObject(type)) {
|
|
@@ -56,14 +67,31 @@ export function useVariableTree(): TreeNodeData[] {
|
|
|
56
67
|
}
|
|
57
68
|
}
|
|
58
69
|
|
|
59
|
-
const
|
|
70
|
+
const keyPath = [...parentFields.map((_field) => _field.key), variable.key];
|
|
71
|
+
const key = keyPath.join('.');
|
|
72
|
+
|
|
73
|
+
const isSchemaInclude = includeSchema
|
|
74
|
+
? JsonSchemaUtils.isASTMatchSchema(type, includeSchema)
|
|
75
|
+
: true;
|
|
76
|
+
const isSchemaExclude = excludeSchema
|
|
77
|
+
? JsonSchemaUtils.isASTMatchSchema(type, excludeSchema)
|
|
78
|
+
: false;
|
|
79
|
+
const isSchemaMatch = isSchemaInclude && !isSchemaExclude;
|
|
80
|
+
|
|
81
|
+
// If not match, and no children, return null
|
|
82
|
+
if (!isSchemaMatch && !children?.length) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
60
85
|
|
|
61
86
|
return {
|
|
62
|
-
key:
|
|
63
|
-
label: variable.meta
|
|
64
|
-
value:
|
|
87
|
+
key: key,
|
|
88
|
+
label: variable.meta?.title || variable.key,
|
|
89
|
+
value: key,
|
|
90
|
+
keyPath,
|
|
65
91
|
icon: getVariableTypeIcon(variable),
|
|
66
92
|
children,
|
|
93
|
+
disabled: !isSchemaMatch,
|
|
94
|
+
rootMeta: parentFields[0]?.meta,
|
|
67
95
|
};
|
|
68
96
|
};
|
|
69
97
|
|
|
@@ -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;
|