@flowgram.ai/form-materials 0.2.32 → 0.3.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/index.ts +11 -5
- package/bin/materials.ts +1 -1
- package/dist/esm/index.js +1252 -1361
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +232 -202
- package/dist/index.d.ts +232 -202
- package/dist/index.js +1396 -1506
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/src/components/batch-variable-selector/config.json +6 -2
- package/src/components/batch-variable-selector/index.tsx +1 -1
- package/src/components/code-editor/theme/light.ts +1 -1
- package/src/components/code-editor-mini/config.json +7 -0
- package/src/components/code-editor-mini/index.tsx +31 -0
- package/src/components/condition-row/config.json +10 -2
- package/src/components/condition-row/hooks/useRule.ts +2 -2
- package/src/components/condition-row/index.tsx +1 -1
- package/src/components/condition-row/types.ts +3 -1
- package/src/components/constant-input/config.json +6 -3
- package/src/components/constant-input/index.tsx +10 -71
- package/src/components/constant-input/types.ts +6 -10
- package/src/components/display-flow-value/config.json +8 -0
- package/src/components/display-flow-value/index.tsx +59 -0
- package/src/components/display-inputs-values/config.json +9 -0
- package/src/components/display-inputs-values/index.tsx +27 -0
- package/src/components/display-inputs-values/styles.ts +12 -0
- package/src/components/display-outputs/config.json +10 -0
- package/src/components/display-outputs/index.tsx +58 -0
- package/src/components/display-outputs/styles.ts +12 -0
- package/src/components/display-schema-tag/config.json +10 -0
- package/src/components/display-schema-tag/index.tsx +44 -0
- package/src/components/display-schema-tag/styles.ts +28 -0
- package/src/components/display-schema-tree/config.json +11 -0
- package/src/components/display-schema-tree/index.tsx +74 -0
- package/src/components/display-schema-tree/styles.tsx +90 -0
- package/src/components/dynamic-value-input/config.json +11 -2
- package/src/components/dynamic-value-input/hooks.ts +53 -0
- package/src/components/dynamic-value-input/index.tsx +30 -28
- package/src/components/index.ts +6 -0
- package/src/components/inputs-values/config.json +2 -1
- package/src/components/inputs-values/types.ts +3 -1
- package/src/components/json-schema-editor/config.json +3 -3
- package/src/components/json-schema-editor/default-value.tsx +1 -1
- package/src/components/json-schema-editor/hooks.tsx +1 -1
- package/src/components/json-schema-editor/index.tsx +1 -1
- package/src/components/json-schema-editor/types.ts +1 -1
- package/src/components/type-selector/config.json +6 -2
- package/src/components/type-selector/index.tsx +47 -11
- package/src/components/variable-selector/config.json +6 -2
- package/src/components/variable-selector/index.tsx +1 -1
- package/src/components/variable-selector/use-variable-tree.tsx +14 -20
- package/src/effects/provide-json-schema-outputs/config.json +4 -5
- package/src/effects/provide-json-schema-outputs/index.ts +1 -3
- package/src/effects/sync-variable-title/index.ts +1 -0
- package/src/form-plugins/infer-inputs-plugin/config.json +3 -1
- package/src/form-plugins/infer-inputs-plugin/index.ts +2 -2
- package/src/index.ts +1 -1
- package/src/{utils → shared}/index.ts +1 -1
- package/src/shared/json-schema-preset/config.json +9 -0
- package/src/shared/json-schema-preset/create-type-preset-plugin.tsx +26 -0
- package/src/shared/json-schema-preset/index.tsx +39 -0
- package/src/shared/json-schema-preset/manager.ts +18 -0
- package/src/shared/json-schema-preset/type-definition/array.tsx +23 -0
- package/src/shared/json-schema-preset/type-definition/boolean.tsx +32 -0
- package/src/shared/json-schema-preset/type-definition/index.tsx +24 -0
- package/src/shared/json-schema-preset/type-definition/integer.tsx +24 -0
- package/src/shared/json-schema-preset/type-definition/number.tsx +24 -0
- package/src/shared/json-schema-preset/type-definition/object.tsx +23 -0
- package/src/shared/json-schema-preset/type-definition/string.tsx +18 -0
- package/src/typings/flow-value/config.json +4 -4
- package/src/typings/flow-value/index.ts +1 -1
- package/src/typings/index.ts +0 -1
- package/src/components/type-selector/constants.tsx +0 -364
- package/src/typings/json-schema/config.json +0 -5
- package/src/typings/json-schema/index.ts +0 -36
- package/src/utils/json-schema/config.json +0 -5
- package/src/utils/json-schema/index.ts +0 -180
- /package/src/{utils → shared}/format-legacy-refs/config.json +0 -0
- /package/src/{utils → shared}/format-legacy-refs/index.ts +0 -0
- /package/src/{utils → shared}/format-legacy-refs/readme.md +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
8
|
+
import { IJsonSchema, JsonSchemaTypeManager } from '@flowgram.ai/json-schema';
|
|
9
|
+
|
|
10
|
+
import { useTypeManager } from '../../shared';
|
|
11
|
+
import { HorizontalLine, TreeItem, TreeLevel, TreeRow, TreeTitle } from './styles';
|
|
12
|
+
|
|
13
|
+
interface PropsType {
|
|
14
|
+
value?: IJsonSchema;
|
|
15
|
+
parentKey?: string;
|
|
16
|
+
depth?: number;
|
|
17
|
+
drilldown?: boolean;
|
|
18
|
+
showIcon?: boolean;
|
|
19
|
+
typeManager?: JsonSchemaTypeManager;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function DisplaySchemaTree(props: Omit<PropsType, 'parentKey' | 'depth'>) {
|
|
23
|
+
return <SchemaTree {...props} />;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function SchemaTree(props: PropsType) {
|
|
27
|
+
const {
|
|
28
|
+
value: schema = {},
|
|
29
|
+
drilldown = true,
|
|
30
|
+
depth = 0,
|
|
31
|
+
showIcon = true,
|
|
32
|
+
parentKey = '',
|
|
33
|
+
} = props || {};
|
|
34
|
+
|
|
35
|
+
const typeManager = useTypeManager();
|
|
36
|
+
|
|
37
|
+
const config = typeManager.getTypeBySchema(schema);
|
|
38
|
+
const title = typeManager.getComplexText(schema);
|
|
39
|
+
const icon = typeManager?.getDisplayIcon(schema);
|
|
40
|
+
let properties: IJsonSchema['properties'] =
|
|
41
|
+
drilldown && config ? config.getTypeSchemaProperties(schema) : {};
|
|
42
|
+
const childEntries = Object.entries(properties || {});
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<TreeItem depth={depth} key={parentKey || 'root'}>
|
|
46
|
+
<TreeRow>
|
|
47
|
+
{depth !== 0 && <HorizontalLine />}
|
|
48
|
+
{showIcon &&
|
|
49
|
+
icon &&
|
|
50
|
+
React.cloneElement(icon, {
|
|
51
|
+
className: 'tree-icon',
|
|
52
|
+
})}
|
|
53
|
+
<TreeTitle>
|
|
54
|
+
{parentKey ? (
|
|
55
|
+
<>
|
|
56
|
+
{`${parentKey} (`}
|
|
57
|
+
{title}
|
|
58
|
+
{')'}
|
|
59
|
+
</>
|
|
60
|
+
) : (
|
|
61
|
+
title
|
|
62
|
+
)}
|
|
63
|
+
</TreeTitle>
|
|
64
|
+
</TreeRow>
|
|
65
|
+
{childEntries?.length ? (
|
|
66
|
+
<TreeLevel>
|
|
67
|
+
{childEntries.map(([key, value]) => (
|
|
68
|
+
<SchemaTree key={key} {...props} parentKey={key} value={value} depth={depth + 1} />
|
|
69
|
+
))}
|
|
70
|
+
</TreeLevel>
|
|
71
|
+
) : null}
|
|
72
|
+
</TreeItem>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import styled, { css } from 'styled-components';
|
|
7
|
+
|
|
8
|
+
export const TreeRow = styled.div`
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
|
|
12
|
+
.tree-icon {
|
|
13
|
+
margin-right: 8px;
|
|
14
|
+
width: 14px;
|
|
15
|
+
height: 14px;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
height: 27px;
|
|
19
|
+
white-space: nowrap;
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
export const HorizontalLine = styled.div`
|
|
23
|
+
position: relative;
|
|
24
|
+
|
|
25
|
+
&::before,
|
|
26
|
+
&::after {
|
|
27
|
+
content: '';
|
|
28
|
+
position: absolute;
|
|
29
|
+
background-color: var(--semi-color-text-3);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
&::after {
|
|
33
|
+
top: 0px;
|
|
34
|
+
right: 6px;
|
|
35
|
+
width: 15px;
|
|
36
|
+
height: 1px;
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
export const TreeTitle = styled.div`
|
|
41
|
+
// overflow: hidden;
|
|
42
|
+
// text-overflow: ellipsis;
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
export const TreeLevel = styled.div`
|
|
46
|
+
padding-left: 30px;
|
|
47
|
+
position: relative;
|
|
48
|
+
|
|
49
|
+
/* &::before {
|
|
50
|
+
content: '';
|
|
51
|
+
position: absolute;
|
|
52
|
+
background-color: var(--semi-color-text-3);
|
|
53
|
+
top: 0px;
|
|
54
|
+
bottom: 0px;
|
|
55
|
+
left: -22px;
|
|
56
|
+
width: 1px;
|
|
57
|
+
} */
|
|
58
|
+
`;
|
|
59
|
+
|
|
60
|
+
export const TreeItem = styled.div<{ depth: number }>`
|
|
61
|
+
position: relative;
|
|
62
|
+
|
|
63
|
+
&::before {
|
|
64
|
+
content: '';
|
|
65
|
+
position: absolute;
|
|
66
|
+
background-color: var(--semi-color-text-3);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
&:not(:last-child)::before {
|
|
70
|
+
width: 1px;
|
|
71
|
+
top: 0;
|
|
72
|
+
bottom: 0;
|
|
73
|
+
left: -22px;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
&:last-child::before {
|
|
77
|
+
width: 1px;
|
|
78
|
+
top: 0;
|
|
79
|
+
height: 14px;
|
|
80
|
+
left: -22px;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
${(props) =>
|
|
84
|
+
props.depth === 0 &&
|
|
85
|
+
css`
|
|
86
|
+
&::before {
|
|
87
|
+
width: 0px !important;
|
|
88
|
+
}
|
|
89
|
+
`}
|
|
90
|
+
`;
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dynamic-value-input",
|
|
3
|
-
"depMaterials": [
|
|
4
|
-
|
|
3
|
+
"depMaterials": [
|
|
4
|
+
"flow-value",
|
|
5
|
+
"constant-input",
|
|
6
|
+
"variable-selector"
|
|
7
|
+
],
|
|
8
|
+
"depPackages": [
|
|
9
|
+
"@douyinfe/semi-ui",
|
|
10
|
+
"@douyinfe/semi-icons",
|
|
11
|
+
"styled-components",
|
|
12
|
+
"@flowgram.ai/json-schema"
|
|
13
|
+
]
|
|
5
14
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useMemo, useState } from 'react';
|
|
7
|
+
|
|
8
|
+
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
9
|
+
import { useScopeAvailable } from '@flowgram.ai/editor';
|
|
10
|
+
|
|
11
|
+
import { IFlowConstantRefValue } from '../../typings/flow-value';
|
|
12
|
+
|
|
13
|
+
export function useRefVariable(value?: IFlowConstantRefValue) {
|
|
14
|
+
const available = useScopeAvailable();
|
|
15
|
+
const refVariable = useMemo(() => {
|
|
16
|
+
if (value?.type === 'ref') {
|
|
17
|
+
return available.getByKeyPath(value.content);
|
|
18
|
+
}
|
|
19
|
+
}, [value, available]);
|
|
20
|
+
|
|
21
|
+
return refVariable;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function useSelectSchema(
|
|
25
|
+
schemaFromProps?: IJsonSchema,
|
|
26
|
+
constantProps?: {
|
|
27
|
+
schema?: IJsonSchema;
|
|
28
|
+
},
|
|
29
|
+
value?: IFlowConstantRefValue
|
|
30
|
+
) {
|
|
31
|
+
let defaultSelectSchema = schemaFromProps || constantProps?.schema || { type: 'string' };
|
|
32
|
+
if (value?.type === 'constant') {
|
|
33
|
+
defaultSelectSchema = value?.schema || defaultSelectSchema;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const [selectSchema, setSelectSchema] = useState(defaultSelectSchema);
|
|
37
|
+
|
|
38
|
+
return [selectSchema, setSelectSchema] as const;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function useIncludeSchema(schemaFromProps?: IJsonSchema) {
|
|
42
|
+
const includeSchema = useMemo(() => {
|
|
43
|
+
if (!schemaFromProps) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (schemaFromProps?.type === 'number') {
|
|
47
|
+
return [schemaFromProps, { type: 'integer' }];
|
|
48
|
+
}
|
|
49
|
+
return { ...schemaFromProps, extra: { ...schemaFromProps?.extra, weak: true } };
|
|
50
|
+
}, [schemaFromProps]);
|
|
51
|
+
|
|
52
|
+
return includeSchema;
|
|
53
|
+
}
|
|
@@ -3,20 +3,19 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import React
|
|
6
|
+
import React from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { JsonSchemaUtils, IJsonSchema } from '@flowgram.ai/json-schema';
|
|
9
9
|
import { IconButton } from '@douyinfe/semi-ui';
|
|
10
10
|
import { IconSetting } from '@douyinfe/semi-icons';
|
|
11
11
|
|
|
12
|
+
import { VariableSelector } from '../variable-selector';
|
|
13
|
+
import { TypeSelector } from '../type-selector';
|
|
12
14
|
import { Strategy } from '../constant-input/types';
|
|
13
15
|
import { ConstantInput } from '../constant-input';
|
|
14
|
-
import { JsonSchemaUtils } from '../../utils';
|
|
15
16
|
import { IFlowConstantRefValue } from '../../typings/flow-value';
|
|
16
17
|
import { UIContainer, UIMain, UITrigger, UIType } from './styles';
|
|
17
|
-
import {
|
|
18
|
-
import { TypeSelector } from '../type-selector';
|
|
19
|
-
import { IJsonSchema } from '../../typings';
|
|
18
|
+
import { useIncludeSchema, useRefVariable, useSelectSchema } from './hooks';
|
|
20
19
|
|
|
21
20
|
interface PropsType {
|
|
22
21
|
value?: IFlowConstantRefValue;
|
|
@@ -40,16 +39,9 @@ export function DynamicValueInput({
|
|
|
40
39
|
schema: schemaFromProps,
|
|
41
40
|
constantProps,
|
|
42
41
|
}: PropsType) {
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
return available.getByKeyPath(value.content);
|
|
47
|
-
}
|
|
48
|
-
}, [value, available]);
|
|
49
|
-
|
|
50
|
-
const [selectSchema, setSelectSchema] = useState(
|
|
51
|
-
schemaFromProps || constantProps?.schema || { type: 'string' }
|
|
52
|
-
);
|
|
42
|
+
const refVariable = useRefVariable(value);
|
|
43
|
+
const [selectSchema, setSelectSchema] = useSelectSchema(schemaFromProps, constantProps, value);
|
|
44
|
+
const includeSchema = useIncludeSchema(schemaFromProps);
|
|
53
45
|
|
|
54
46
|
const renderTypeSelector = () => {
|
|
55
47
|
if (schemaFromProps) {
|
|
@@ -65,23 +57,33 @@ export function DynamicValueInput({
|
|
|
65
57
|
return (
|
|
66
58
|
<TypeSelector
|
|
67
59
|
value={selectSchema}
|
|
68
|
-
onChange={(_v) =>
|
|
60
|
+
onChange={(_v) => {
|
|
61
|
+
setSelectSchema(_v || { type: 'string' });
|
|
62
|
+
let content;
|
|
63
|
+
|
|
64
|
+
if (_v?.type === 'object') {
|
|
65
|
+
content = '{}';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (_v?.type === 'array') {
|
|
69
|
+
content = '[]';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (_v?.type === 'boolean') {
|
|
73
|
+
content = false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
onChange({
|
|
77
|
+
type: 'constant',
|
|
78
|
+
content,
|
|
79
|
+
schema: _v || { type: 'string' },
|
|
80
|
+
});
|
|
81
|
+
}}
|
|
69
82
|
readonly={readonly}
|
|
70
83
|
/>
|
|
71
84
|
);
|
|
72
85
|
};
|
|
73
86
|
|
|
74
|
-
// When is number type, include integer as well
|
|
75
|
-
const includeSchema = useMemo(() => {
|
|
76
|
-
if (!schemaFromProps) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
if (schemaFromProps?.type === 'number') {
|
|
80
|
-
return [schemaFromProps, { type: 'integer' }];
|
|
81
|
-
}
|
|
82
|
-
return { ...schemaFromProps, extra: { ...schemaFromProps?.extra, weak: true } };
|
|
83
|
-
}, [schemaFromProps]);
|
|
84
|
-
|
|
85
87
|
const renderMain = () => {
|
|
86
88
|
if (value?.type === 'ref') {
|
|
87
89
|
// Display Variable Or Delete
|
package/src/components/index.ts
CHANGED
|
@@ -15,5 +15,11 @@ export * from './prompt-editor';
|
|
|
15
15
|
export * from './prompt-editor-with-variables';
|
|
16
16
|
export * from './prompt-editor-with-inputs';
|
|
17
17
|
export * from './code-editor';
|
|
18
|
+
export * from './code-editor-mini';
|
|
18
19
|
export * from './json-editor-with-variables';
|
|
19
20
|
export * from './inputs-values';
|
|
21
|
+
export * from './display-schema-tree';
|
|
22
|
+
export * from './display-outputs';
|
|
23
|
+
export * from './display-schema-tag';
|
|
24
|
+
export * from './display-flow-value';
|
|
25
|
+
export * from './display-inputs-values';
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
7
|
+
|
|
6
8
|
import { Strategy } from '../constant-input/types';
|
|
7
|
-
import { IFlowValue
|
|
9
|
+
import { IFlowValue } from '../../typings';
|
|
8
10
|
|
|
9
11
|
export interface PropsType {
|
|
10
12
|
value?: Record<string, IFlowValue | undefined>;
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
"name": "json-schema-editor",
|
|
3
3
|
"depMaterials": [
|
|
4
4
|
"type-selector",
|
|
5
|
-
"
|
|
6
|
-
"constant-inputs"
|
|
5
|
+
"constant-inputs",
|
|
7
6
|
],
|
|
8
7
|
"depPackages": [
|
|
9
8
|
"@douyinfe/semi-ui",
|
|
10
9
|
"@douyinfe/semi-icons",
|
|
11
|
-
"styled-components"
|
|
10
|
+
"styled-components",
|
|
11
|
+
"@flowgram.ai/json-schema"
|
|
12
12
|
]
|
|
13
13
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import React, { useRef, useState, useCallback } from 'react';
|
|
7
7
|
|
|
8
|
+
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
8
9
|
import { IconButton, JsonViewer, Tooltip } from '@douyinfe/semi-ui';
|
|
9
10
|
import { IconBrackets } from '@douyinfe/semi-icons';
|
|
10
11
|
|
|
@@ -17,7 +18,6 @@ import {
|
|
|
17
18
|
JSONViewerWrapper,
|
|
18
19
|
} from './styles';
|
|
19
20
|
import { ConstantInput } from '../constant-input';
|
|
20
|
-
import { IJsonSchema } from '../../typings';
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* 根据不同的数据类型渲染对应的默认值输入组件。
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import { omit } from 'lodash';
|
|
9
|
+
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
9
10
|
|
|
10
|
-
import { IJsonSchema } from '../../typings';
|
|
11
11
|
import { PropertyValueType } from './types';
|
|
12
12
|
|
|
13
13
|
let _id = 0;
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import React, { useMemo, useState } from 'react';
|
|
7
7
|
|
|
8
|
+
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
8
9
|
import { Button, Checkbox, IconButton } from '@douyinfe/semi-ui';
|
|
9
10
|
import {
|
|
10
11
|
IconExpand,
|
|
@@ -16,7 +17,6 @@ import {
|
|
|
16
17
|
} from '@douyinfe/semi-icons';
|
|
17
18
|
|
|
18
19
|
import { TypeSelector } from '../type-selector';
|
|
19
|
-
import { IJsonSchema } from '../../typings';
|
|
20
20
|
import { ConfigType, PropertyValueType } from './types';
|
|
21
21
|
import {
|
|
22
22
|
IconAddChildren,
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "type-selector",
|
|
3
|
-
"depMaterials": [
|
|
4
|
-
"depPackages": [
|
|
3
|
+
"depMaterials": [],
|
|
4
|
+
"depPackages": [
|
|
5
|
+
"@douyinfe/semi-ui",
|
|
6
|
+
"@douyinfe/semi-icons",
|
|
7
|
+
"@flowgram.ai/json-schema"
|
|
8
|
+
]
|
|
5
9
|
}
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
import React, { useMemo } from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
9
|
+
import { Cascader, Icon, IconButton } from '@douyinfe/semi-ui';
|
|
9
10
|
|
|
10
|
-
import {
|
|
11
|
-
import { ArrayIcons, VariableTypeIcons, getSchemaIcon, options } from './constants';
|
|
11
|
+
import { useTypeManager } from '../../shared';
|
|
12
12
|
|
|
13
13
|
interface PropTypes {
|
|
14
14
|
value?: Partial<IJsonSchema>;
|
|
@@ -21,6 +21,10 @@ interface PropTypes {
|
|
|
21
21
|
style?: React.CSSProperties;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
const labelStyle: React.CSSProperties = { display: 'flex', alignItems: 'center', gap: 5 };
|
|
25
|
+
|
|
26
|
+
const firstUppercase = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
27
|
+
|
|
24
28
|
export const getTypeSelectValue = (value?: Partial<IJsonSchema>): string[] | undefined => {
|
|
25
29
|
if (value?.type === 'array' && value?.items) {
|
|
26
30
|
return [value.type, ...(getTypeSelectValue(value.items) || [])];
|
|
@@ -44,17 +48,51 @@ export function TypeSelector(props: PropTypes) {
|
|
|
44
48
|
|
|
45
49
|
const selectValue = useMemo(() => getTypeSelectValue(value), [value]);
|
|
46
50
|
|
|
51
|
+
const typeManager = useTypeManager();
|
|
52
|
+
|
|
53
|
+
const icon = typeManager.getDisplayIcon(value || {});
|
|
54
|
+
|
|
55
|
+
const options = useMemo(
|
|
56
|
+
() =>
|
|
57
|
+
typeManager.getTypeRegistriesWithParentType().map((_type) => {
|
|
58
|
+
const isArray = _type.type === 'array';
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
label: (
|
|
62
|
+
<div style={labelStyle}>
|
|
63
|
+
<Icon size="small" svg={_type.icon} />
|
|
64
|
+
{firstUppercase(_type.type)}
|
|
65
|
+
</div>
|
|
66
|
+
),
|
|
67
|
+
value: _type.type,
|
|
68
|
+
children: isArray
|
|
69
|
+
? typeManager.getTypeRegistriesWithParentType('array').map((_type) => ({
|
|
70
|
+
label: (
|
|
71
|
+
<div style={labelStyle}>
|
|
72
|
+
<Icon
|
|
73
|
+
size="small"
|
|
74
|
+
svg={typeManager.getDisplayIcon({
|
|
75
|
+
type: 'array',
|
|
76
|
+
items: { type: _type.type },
|
|
77
|
+
})}
|
|
78
|
+
/>
|
|
79
|
+
{firstUppercase(_type.type)}
|
|
80
|
+
</div>
|
|
81
|
+
),
|
|
82
|
+
value: _type.type,
|
|
83
|
+
}))
|
|
84
|
+
: [],
|
|
85
|
+
};
|
|
86
|
+
}),
|
|
87
|
+
[]
|
|
88
|
+
);
|
|
89
|
+
|
|
47
90
|
return (
|
|
48
91
|
<Cascader
|
|
49
92
|
disabled={readonly || disabled}
|
|
50
93
|
size="small"
|
|
51
94
|
triggerRender={() => (
|
|
52
|
-
<IconButton
|
|
53
|
-
size="small"
|
|
54
|
-
style={style}
|
|
55
|
-
disabled={readonly || disabled}
|
|
56
|
-
icon={getSchemaIcon(value)}
|
|
57
|
-
/>
|
|
95
|
+
<IconButton size="small" style={style} disabled={readonly || disabled} icon={icon} />
|
|
58
96
|
)}
|
|
59
97
|
treeData={options}
|
|
60
98
|
value={selectValue}
|
|
@@ -65,5 +103,3 @@ export function TypeSelector(props: PropTypes) {
|
|
|
65
103
|
/>
|
|
66
104
|
);
|
|
67
105
|
}
|
|
68
|
-
|
|
69
|
-
export { VariableTypeIcons, ArrayIcons, getSchemaIcon };
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "variable-selector",
|
|
3
|
-
"depMaterials": [
|
|
4
|
-
"depPackages": [
|
|
3
|
+
"depMaterials": [],
|
|
4
|
+
"depPackages": [
|
|
5
|
+
"@douyinfe/semi-ui",
|
|
6
|
+
"styled-components",
|
|
7
|
+
"@flowgram.ai/json-schema"
|
|
8
|
+
]
|
|
5
9
|
}
|
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
|
|
6
6
|
import React, { useMemo } from 'react';
|
|
7
7
|
|
|
8
|
+
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
8
9
|
import { TriggerRenderProps } from '@douyinfe/semi-ui/lib/es/treeSelect';
|
|
9
10
|
import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
|
|
10
11
|
import { Popover } from '@douyinfe/semi-ui';
|
|
11
12
|
import { IconChevronDownStroked, IconIssueStroked } from '@douyinfe/semi-icons';
|
|
12
13
|
|
|
13
|
-
import { IJsonSchema } from '../../typings/json-schema';
|
|
14
14
|
import { useVariableTree } from './use-variable-tree';
|
|
15
15
|
import { UIPopoverContent, UIRootTitle, UITag, UITreeSelect, UIVarName } from './styles';
|
|
16
16
|
|
|
@@ -5,15 +5,18 @@
|
|
|
5
5
|
|
|
6
6
|
import React, { useCallback } from 'react';
|
|
7
7
|
|
|
8
|
+
import { IJsonSchema, JsonSchemaUtils } from '@flowgram.ai/json-schema';
|
|
8
9
|
import { ASTMatch, BaseVariableField, useAvailableVariables } from '@flowgram.ai/editor';
|
|
9
10
|
import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
|
|
10
11
|
import { Icon } from '@douyinfe/semi-ui';
|
|
11
12
|
|
|
12
|
-
import {
|
|
13
|
-
import { JsonSchemaUtils } from '../../utils/json-schema';
|
|
14
|
-
import { IJsonSchema } from '../../typings/json-schema';
|
|
13
|
+
import { useTypeManager } from '../../shared';
|
|
15
14
|
|
|
16
|
-
type VariableField = BaseVariableField<{
|
|
15
|
+
type VariableField = BaseVariableField<{
|
|
16
|
+
icon?: string | JSX.Element;
|
|
17
|
+
title?: string;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
}>;
|
|
17
20
|
|
|
18
21
|
export function useVariableTree(params: {
|
|
19
22
|
includeSchema?: IJsonSchema | IJsonSchema[];
|
|
@@ -22,6 +25,7 @@ export function useVariableTree(params: {
|
|
|
22
25
|
}): TreeNodeData[] {
|
|
23
26
|
const { includeSchema, excludeSchema, customSkip } = params;
|
|
24
27
|
|
|
28
|
+
const typeManager = useTypeManager();
|
|
25
29
|
const variables = useAvailableVariables();
|
|
26
30
|
|
|
27
31
|
const getVariableTypeIcon = useCallback((variable: VariableField) => {
|
|
@@ -33,22 +37,9 @@ export function useVariableTree(params: {
|
|
|
33
37
|
return variable.meta.icon;
|
|
34
38
|
}
|
|
35
39
|
|
|
36
|
-
const
|
|
40
|
+
const schema = JsonSchemaUtils.astToSchema(variable.type, { drilldownObject: false });
|
|
37
41
|
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<Icon
|
|
41
|
-
size="small"
|
|
42
|
-
svg={ArrayIcons[_type.items?.kind.toLowerCase()] || VariableTypeIcons.array}
|
|
43
|
-
/>
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (ASTMatch.isCustomType(_type)) {
|
|
48
|
-
return <Icon size="small" svg={VariableTypeIcons[_type.typeName.toLowerCase()]} />;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return <Icon size="small" svg={VariableTypeIcons[variable.type?.kind.toLowerCase()]} />;
|
|
42
|
+
return <Icon size="small" svg={typeManager.getDisplayIcon(schema || {})} />;
|
|
52
43
|
}, []);
|
|
53
44
|
|
|
54
45
|
const renderVariable = (
|
|
@@ -80,7 +71,10 @@ export function useVariableTree(params: {
|
|
|
80
71
|
: false;
|
|
81
72
|
const isCustomSkip = customSkip ? customSkip(variable) : false;
|
|
82
73
|
|
|
83
|
-
|
|
74
|
+
// disabled in meta when created
|
|
75
|
+
const isMetaDisabled = variable.meta?.disabled;
|
|
76
|
+
|
|
77
|
+
const isSchemaMatch = isSchemaInclude && !isSchemaExclude && !isCustomSkip && !isMetaDisabled;
|
|
84
78
|
|
|
85
79
|
// If not match, and no children, return null
|
|
86
80
|
if (!isSchemaMatch && !children?.length) {
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { JsonSchemaUtils, IJsonSchema } from '@flowgram.ai/json-schema';
|
|
6
7
|
import {
|
|
7
8
|
ASTFactory,
|
|
8
9
|
EffectOptions,
|
|
@@ -11,9 +12,6 @@ import {
|
|
|
11
12
|
getNodeForm,
|
|
12
13
|
} from '@flowgram.ai/editor';
|
|
13
14
|
|
|
14
|
-
import { JsonSchemaUtils } from '../../utils';
|
|
15
|
-
import { IJsonSchema } from '../../typings';
|
|
16
|
-
|
|
17
15
|
export const provideJsonSchemaOutputs: EffectOptions[] = createEffectFromVariableProvider({
|
|
18
16
|
parse: (value: IJsonSchema, ctx) => [
|
|
19
17
|
ASTFactory.createVariableDeclaration({
|
|
@@ -18,6 +18,7 @@ export const syncVariableTitle: EffectOptions[] = [
|
|
|
18
18
|
context.node.getData(FlowNodeVariableData).allScopes.forEach((_scope) => {
|
|
19
19
|
_scope.output.variables.forEach((_var) => {
|
|
20
20
|
_var.updateMeta({
|
|
21
|
+
...(_var.meta || {}),
|
|
21
22
|
title: value || context.node.id,
|
|
22
23
|
icon: context.node.getNodeRegistry<FlowNodeRegistry>().info?.icon,
|
|
23
24
|
});
|