@flowgram.ai/form-materials 0.1.0-alpha.11 → 0.1.0-alpha.13
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 +14 -22
- package/bin/materials.ts +41 -90
- package/bin/project.ts +4 -0
- package/bin/utils/import.ts +127 -0
- package/bin/utils/traverse-file.ts +60 -0
- package/dist/esm/index.js +2073 -1601
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +392 -131
- package/dist/index.d.ts +392 -131
- package/dist/index.js +2175 -1710
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/src/components/assign-row/components/blur-input.tsx +27 -0
- package/src/components/assign-row/index.tsx +84 -0
- package/src/components/assign-row/types.ts +25 -0
- package/src/components/assign-rows/index.tsx +59 -0
- package/src/components/batch-outputs/index.tsx +7 -14
- package/src/components/batch-outputs/types.ts +1 -1
- package/src/components/batch-variable-selector/index.tsx +2 -2
- package/src/components/code-editor/index.tsx +7 -0
- package/src/components/code-editor/language-features.ts +22 -1
- package/src/components/code-editor/theme/light.ts +1 -1
- package/src/components/code-editor-mini/index.tsx +31 -0
- package/src/components/condition-row/constants.ts +8 -10
- package/src/components/condition-row/hooks/useOp.tsx +15 -9
- package/src/components/condition-row/hooks/useRule.ts +9 -5
- package/src/components/condition-row/index.tsx +28 -10
- package/src/components/condition-row/types.ts +5 -5
- package/src/components/constant-input/index.tsx +20 -61
- package/src/components/constant-input/types.ts +6 -9
- package/src/components/display-flow-value/index.tsx +59 -0
- package/src/components/display-inputs-values/index.tsx +28 -0
- package/src/components/display-inputs-values/styles.ts +12 -0
- package/src/components/display-outputs/index.tsx +65 -0
- package/src/components/display-outputs/styles.ts +12 -0
- package/src/components/display-schema-tag/index.tsx +45 -0
- package/src/components/display-schema-tag/styles.ts +28 -0
- package/src/components/display-schema-tree/index.tsx +75 -0
- package/src/components/display-schema-tree/styles.tsx +90 -0
- package/src/components/dynamic-value-input/hooks.ts +53 -0
- package/src/components/dynamic-value-input/index.tsx +74 -19
- package/src/components/dynamic-value-input/styles.tsx +28 -2
- package/src/components/index.ts +9 -0
- package/src/components/inputs-values/components/blur-input.tsx +27 -0
- package/src/components/inputs-values/index.tsx +75 -0
- package/src/components/inputs-values/styles.tsx +19 -0
- package/src/components/inputs-values/types.ts +22 -0
- package/src/components/json-editor-with-variables/extensions/variable-tree.tsx +1 -1
- package/src/components/json-editor-with-variables/index.tsx +2 -1
- package/src/components/json-schema-editor/default-value.tsx +12 -106
- package/src/components/json-schema-editor/hooks.tsx +53 -94
- package/src/components/json-schema-editor/index.tsx +32 -13
- package/src/components/json-schema-editor/styles.tsx +0 -29
- package/src/components/json-schema-editor/types.ts +1 -1
- package/src/components/prompt-editor/types.tsx +1 -1
- package/src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx +2 -1
- package/src/components/prompt-editor-with-inputs/index.tsx +3 -2
- package/src/components/prompt-editor-with-inputs/inputs-picker.tsx +2 -2
- package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +6 -3
- package/src/components/prompt-editor-with-variables/extensions/variable-tree.tsx +1 -1
- package/src/components/prompt-editor-with-variables/index.tsx +2 -1
- package/src/components/type-selector/index.tsx +58 -13
- package/src/components/variable-selector/index.tsx +42 -17
- package/src/components/variable-selector/styles.tsx +18 -8
- package/src/components/variable-selector/use-variable-tree.tsx +19 -22
- package/src/effects/auto-rename-ref/index.ts +1 -1
- package/src/effects/index.ts +3 -1
- package/src/effects/listen-ref-schema-change/index.ts +56 -0
- package/src/effects/listen-ref-value-change/index.ts +53 -0
- package/src/effects/provide-batch-input/index.ts +1 -1
- package/src/effects/provide-json-schema-outputs/index.ts +1 -3
- package/src/effects/sync-variable-title/index.ts +1 -0
- package/src/effects/validate-when-variable-sync/index.ts +35 -0
- package/src/form-plugins/batch-outputs-plugin/index.ts +1 -1
- package/src/form-plugins/index.ts +3 -1
- package/src/form-plugins/infer-assign-plugin/index.ts +90 -0
- package/src/form-plugins/infer-inputs-plugin/index.ts +108 -0
- package/src/hooks/index.tsx +6 -0
- package/src/hooks/use-object-list/index.tsx +136 -0
- package/src/index.ts +3 -1
- package/src/{utils/format-legacy-refs → plugins/disable-declaration-plugin}/config.json +1 -1
- package/src/plugins/disable-declaration-plugin/create-disable-declaration-plugin.ts +31 -0
- package/src/plugins/disable-declaration-plugin/index.tsx +6 -0
- package/src/plugins/index.ts +7 -0
- package/src/plugins/json-schema-preset/config.json +9 -0
- package/src/plugins/json-schema-preset/create-type-preset-plugin.tsx +28 -0
- package/src/plugins/json-schema-preset/index.tsx +41 -0
- package/src/plugins/json-schema-preset/manager.ts +18 -0
- package/src/plugins/json-schema-preset/type-definition/array.tsx +26 -0
- package/src/plugins/json-schema-preset/type-definition/boolean.tsx +33 -0
- package/src/plugins/json-schema-preset/type-definition/index.tsx +24 -0
- package/src/plugins/json-schema-preset/type-definition/integer.tsx +25 -0
- package/src/plugins/json-schema-preset/type-definition/number.tsx +25 -0
- package/src/plugins/json-schema-preset/type-definition/object.tsx +26 -0
- package/src/plugins/json-schema-preset/type-definition/string.tsx +24 -0
- package/src/{utils → shared}/index.ts +1 -1
- package/src/shared/inject-material/README.md +170 -0
- package/src/shared/inject-material/README.zh.md +174 -0
- package/src/shared/inject-material/index.tsx +87 -0
- package/src/typings/flow-value/index.ts +11 -0
- package/src/typings/index.ts +0 -1
- package/src/validate/index.tsx +6 -0
- package/src/validate/validate-flow-value/index.tsx +73 -0
- package/src/components/batch-outputs/config.json +0 -12
- package/src/components/batch-outputs/use-list.ts +0 -86
- package/src/components/batch-variable-selector/config.json +0 -5
- package/src/components/code-editor/config.json +0 -10
- package/src/components/condition-row/config.json +0 -5
- package/src/components/constant-input/config.json +0 -6
- package/src/components/dynamic-value-input/config.json +0 -5
- package/src/components/json-editor-with-variables/config.json +0 -13
- package/src/components/json-schema-editor/config.json +0 -13
- package/src/components/json-schema-editor/utils.ts +0 -29
- package/src/components/prompt-editor/config.json +0 -9
- package/src/components/prompt-editor-with-inputs/config.json +0 -13
- package/src/components/prompt-editor-with-variables/config.json +0 -13
- package/src/components/type-selector/config.json +0 -5
- package/src/components/type-selector/constants.tsx +0 -364
- package/src/components/variable-selector/config.json +0 -5
- package/src/effects/auto-rename-ref/config.json +0 -5
- package/src/effects/provide-batch-input/config.json +0 -5
- package/src/effects/provide-batch-outputs/config.json +0 -5
- package/src/effects/provide-batch-outputs/index.ts +0 -38
- package/src/effects/provide-json-schema-outputs/config.json +0 -8
- package/src/effects/sync-variable-title/config.json +0 -5
- package/src/form-plugins/batch-outputs-plugin/config.json +0 -7
- package/src/typings/flow-value/config.json +0 -5
- 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/index.ts +0 -0
- /package/src/{utils → shared}/format-legacy-refs/readme.md +0 -0
|
@@ -6,79 +6,38 @@
|
|
|
6
6
|
/* eslint-disable react/prop-types */
|
|
7
7
|
import React, { useMemo } from 'react';
|
|
8
8
|
|
|
9
|
-
import { Input
|
|
9
|
+
import { Input } from '@douyinfe/semi-ui';
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import { useTypeManager } from '@/plugins';
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
Renderer: (props) => (
|
|
17
|
-
<Input placeholder="Please Input String" size="small" disabled={props.readonly} {...props} />
|
|
18
|
-
),
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
hit: (schema) => schema?.type === 'number',
|
|
22
|
-
Renderer: (props) => (
|
|
23
|
-
<InputNumber
|
|
24
|
-
placeholder="Please Input Number"
|
|
25
|
-
size="small"
|
|
26
|
-
disabled={props.readonly}
|
|
27
|
-
hideButtons
|
|
28
|
-
{...props}
|
|
29
|
-
/>
|
|
30
|
-
),
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
hit: (schema) => schema?.type === 'integer',
|
|
34
|
-
Renderer: (props) => (
|
|
35
|
-
<InputNumber
|
|
36
|
-
placeholder="Please Input Integer"
|
|
37
|
-
size="small"
|
|
38
|
-
disabled={props.readonly}
|
|
39
|
-
hideButtons
|
|
40
|
-
precision={0}
|
|
41
|
-
{...props}
|
|
42
|
-
/>
|
|
43
|
-
),
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
hit: (schema) => schema?.type === 'boolean',
|
|
47
|
-
Renderer: (props) => {
|
|
48
|
-
const { value, onChange, ...rest } = props;
|
|
49
|
-
return (
|
|
50
|
-
<Select
|
|
51
|
-
placeholder="Please Select Boolean"
|
|
52
|
-
size="small"
|
|
53
|
-
disabled={props.readonly}
|
|
54
|
-
optionList={[
|
|
55
|
-
{ label: 'True', value: 1 },
|
|
56
|
-
{ label: 'False', value: 0 },
|
|
57
|
-
]}
|
|
58
|
-
value={value ? 1 : 0}
|
|
59
|
-
onChange={(value) => onChange?.(!!value)}
|
|
60
|
-
{...rest}
|
|
61
|
-
/>
|
|
62
|
-
);
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
];
|
|
13
|
+
import { PropsType, Strategy as ConstantInputStrategy } from './types';
|
|
14
|
+
|
|
15
|
+
export { ConstantInputStrategy };
|
|
66
16
|
|
|
67
17
|
export function ConstantInput(props: PropsType) {
|
|
68
|
-
const { value, onChange, schema, strategies
|
|
18
|
+
const { value, onChange, schema, strategies, fallbackRenderer, readonly, ...rest } = props;
|
|
69
19
|
|
|
70
|
-
const
|
|
71
|
-
() => [...defaultStrategies, ...(extraStrategies || [])],
|
|
72
|
-
[extraStrategies]
|
|
73
|
-
);
|
|
20
|
+
const typeManager = useTypeManager();
|
|
74
21
|
|
|
75
22
|
const Renderer = useMemo(() => {
|
|
76
|
-
const strategy = strategies.find((_strategy) => _strategy.hit(schema));
|
|
23
|
+
const strategy = (strategies || []).find((_strategy) => _strategy.hit(schema));
|
|
24
|
+
|
|
25
|
+
if (!strategy) {
|
|
26
|
+
return typeManager.getTypeBySchema(schema)?.ConstantRenderer;
|
|
27
|
+
}
|
|
77
28
|
|
|
78
29
|
return strategy?.Renderer;
|
|
79
30
|
}, [strategies, schema]);
|
|
80
31
|
|
|
81
32
|
if (!Renderer) {
|
|
33
|
+
if (fallbackRenderer) {
|
|
34
|
+
return React.createElement(fallbackRenderer, {
|
|
35
|
+
value,
|
|
36
|
+
onChange,
|
|
37
|
+
readonly,
|
|
38
|
+
...rest,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
82
41
|
return <Input size="small" disabled placeholder="Unsupported type" />;
|
|
83
42
|
}
|
|
84
43
|
|
|
@@ -3,21 +3,18 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { IJsonSchema } from '
|
|
6
|
+
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
7
|
+
|
|
8
|
+
import { ConstantRendererProps } from '@/plugins';
|
|
7
9
|
|
|
8
10
|
export interface Strategy<Value = any> {
|
|
9
11
|
hit: (schema: IJsonSchema) => boolean;
|
|
10
|
-
Renderer: React.FC<
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface RendererProps<Value = any> {
|
|
14
|
-
value?: Value;
|
|
15
|
-
onChange?: (value: Value) => void;
|
|
16
|
-
readonly?: boolean;
|
|
12
|
+
Renderer: React.FC<ConstantRendererProps<Value>>;
|
|
17
13
|
}
|
|
18
14
|
|
|
19
|
-
export interface PropsType extends
|
|
15
|
+
export interface PropsType extends ConstantRendererProps {
|
|
20
16
|
schema: IJsonSchema;
|
|
21
17
|
strategies?: Strategy[];
|
|
18
|
+
fallbackRenderer?: React.FC<ConstantRendererProps>;
|
|
22
19
|
[key: string]: any;
|
|
23
20
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React, { useMemo } from 'react';
|
|
7
|
+
|
|
8
|
+
import { JsonSchemaTypeManager, JsonSchemaUtils } from '@flowgram.ai/json-schema';
|
|
9
|
+
import { useScopeAvailable } from '@flowgram.ai/editor';
|
|
10
|
+
|
|
11
|
+
import { IFlowValue } from '@/typings';
|
|
12
|
+
import { DisplaySchemaTag } from '@/components/display-schema-tag';
|
|
13
|
+
|
|
14
|
+
interface PropsType {
|
|
15
|
+
value?: IFlowValue;
|
|
16
|
+
title?: JSX.Element | string;
|
|
17
|
+
showIconInTree?: boolean;
|
|
18
|
+
typeManager?: JsonSchemaTypeManager;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function DisplayFlowValue({ value, title, showIconInTree }: PropsType) {
|
|
22
|
+
const available = useScopeAvailable();
|
|
23
|
+
|
|
24
|
+
const variable = value?.type === 'ref' ? available.getByKeyPath(value?.content) : undefined;
|
|
25
|
+
|
|
26
|
+
const schema = useMemo(() => {
|
|
27
|
+
if (value?.type === 'ref') {
|
|
28
|
+
return JsonSchemaUtils.astToSchema(variable?.type);
|
|
29
|
+
}
|
|
30
|
+
if (value?.type === 'template') {
|
|
31
|
+
return { type: 'string' };
|
|
32
|
+
}
|
|
33
|
+
if (value?.type === 'constant') {
|
|
34
|
+
if (value?.schema) {
|
|
35
|
+
return value?.schema;
|
|
36
|
+
}
|
|
37
|
+
if (typeof value?.content === 'string') {
|
|
38
|
+
return { type: 'string' };
|
|
39
|
+
}
|
|
40
|
+
if (typeof value?.content === 'number') {
|
|
41
|
+
return { type: 'number' };
|
|
42
|
+
}
|
|
43
|
+
if (typeof value?.content === 'boolean') {
|
|
44
|
+
return { type: 'boolean' };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return { type: 'unknown' };
|
|
49
|
+
}, [value, variable?.hash]);
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<DisplaySchemaTag
|
|
53
|
+
title={title}
|
|
54
|
+
value={schema}
|
|
55
|
+
showIconInTree={showIconInTree}
|
|
56
|
+
warning={value?.type === 'ref' && !variable}
|
|
57
|
+
/>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 { IFlowValue } from '@/typings';
|
|
9
|
+
import { DisplayFlowValue } from '@/components/display-flow-value';
|
|
10
|
+
|
|
11
|
+
import { DisplayInputsWrapper } from './styles';
|
|
12
|
+
|
|
13
|
+
interface PropsType {
|
|
14
|
+
value?: Record<string, IFlowValue | undefined>;
|
|
15
|
+
showIconInTree?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function DisplayInputsValues({ value, showIconInTree }: PropsType) {
|
|
19
|
+
const childEntries = Object.entries(value || {});
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<DisplayInputsWrapper>
|
|
23
|
+
{childEntries.map(([key, value]) => (
|
|
24
|
+
<DisplayFlowValue key={key} title={key} value={value} showIconInTree={showIconInTree} />
|
|
25
|
+
))}
|
|
26
|
+
</DisplayInputsWrapper>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React, { useEffect } from 'react';
|
|
7
|
+
|
|
8
|
+
import { IJsonSchema, JsonSchemaTypeManager, JsonSchemaUtils } from '@flowgram.ai/json-schema';
|
|
9
|
+
import { useCurrentScope, useRefresh } from '@flowgram.ai/editor';
|
|
10
|
+
|
|
11
|
+
import { DisplaySchemaTag } from '@/components/display-schema-tag';
|
|
12
|
+
|
|
13
|
+
import { DisplayOutputsWrapper } from './styles';
|
|
14
|
+
|
|
15
|
+
interface PropsType {
|
|
16
|
+
value?: IJsonSchema;
|
|
17
|
+
showIconInTree?: boolean;
|
|
18
|
+
displayFromScope?: boolean;
|
|
19
|
+
typeManager?: JsonSchemaTypeManager;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function DisplayOutputs({ value, showIconInTree, displayFromScope }: PropsType) {
|
|
23
|
+
const scope = useCurrentScope();
|
|
24
|
+
const refresh = useRefresh();
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!displayFromScope) {
|
|
28
|
+
return () => null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const disposable = scope.output.onListOrAnyVarChange(() => {
|
|
32
|
+
refresh();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return () => {
|
|
36
|
+
disposable.dispose();
|
|
37
|
+
};
|
|
38
|
+
}, [displayFromScope]);
|
|
39
|
+
|
|
40
|
+
const properties: IJsonSchema['properties'] = displayFromScope
|
|
41
|
+
? scope.output.variables?.reduce((acm, curr) => {
|
|
42
|
+
acm = {
|
|
43
|
+
...acm,
|
|
44
|
+
...(JsonSchemaUtils.astToSchema(curr.type)?.properties || {}),
|
|
45
|
+
};
|
|
46
|
+
return acm;
|
|
47
|
+
}, {})
|
|
48
|
+
: value?.properties || {};
|
|
49
|
+
|
|
50
|
+
const childEntries = Object.entries(properties || {});
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<DisplayOutputsWrapper>
|
|
54
|
+
{childEntries.map(([key, schema]) => (
|
|
55
|
+
<DisplaySchemaTag
|
|
56
|
+
key={key}
|
|
57
|
+
title={key}
|
|
58
|
+
value={schema}
|
|
59
|
+
showIconInTree={showIconInTree}
|
|
60
|
+
warning={!schema}
|
|
61
|
+
/>
|
|
62
|
+
))}
|
|
63
|
+
</DisplayOutputsWrapper>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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 } from '@flowgram.ai/json-schema';
|
|
9
|
+
import { Popover } from '@douyinfe/semi-ui';
|
|
10
|
+
|
|
11
|
+
import { useTypeManager } from '@/plugins';
|
|
12
|
+
import { DisplaySchemaTree } from '@/components/display-schema-tree';
|
|
13
|
+
|
|
14
|
+
import { PopoverContent, StyledTag, TitleSpan } from './styles';
|
|
15
|
+
|
|
16
|
+
interface PropsType {
|
|
17
|
+
title?: JSX.Element | string;
|
|
18
|
+
value?: IJsonSchema;
|
|
19
|
+
showIconInTree?: boolean;
|
|
20
|
+
warning?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function DisplaySchemaTag({ value = {}, showIconInTree, title, warning }: PropsType) {
|
|
24
|
+
const typeManager = useTypeManager();
|
|
25
|
+
const icon =
|
|
26
|
+
typeManager?.getDisplayIcon(value) || typeManager.getDisplayIcon({ type: 'unknown' });
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<Popover
|
|
30
|
+
content={
|
|
31
|
+
<PopoverContent>
|
|
32
|
+
<DisplaySchemaTree value={value} typeManager={typeManager} showIcon={showIconInTree} />
|
|
33
|
+
</PopoverContent>
|
|
34
|
+
}
|
|
35
|
+
>
|
|
36
|
+
<StyledTag color={warning ? 'amber' : 'white'}>
|
|
37
|
+
{icon &&
|
|
38
|
+
React.cloneElement(icon, {
|
|
39
|
+
className: 'tag-icon',
|
|
40
|
+
})}
|
|
41
|
+
{title && <TitleSpan>{title}</TitleSpan>}
|
|
42
|
+
</StyledTag>
|
|
43
|
+
</Popover>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import styled from 'styled-components';
|
|
7
|
+
import { Tag } from '@douyinfe/semi-ui';
|
|
8
|
+
|
|
9
|
+
export const PopoverContent = styled.div`
|
|
10
|
+
padding: 10px;
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
export const StyledTag = styled(Tag)`
|
|
14
|
+
padding: 4px;
|
|
15
|
+
|
|
16
|
+
.tag-icon {
|
|
17
|
+
width: 12px;
|
|
18
|
+
height: 12px;
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
export const TitleSpan = styled.span`
|
|
23
|
+
display: inline-block;
|
|
24
|
+
margin-left: 4px;
|
|
25
|
+
margin-top: -1px;
|
|
26
|
+
overflow: hidden;
|
|
27
|
+
text-overflow: ellipsis;
|
|
28
|
+
`;
|
|
@@ -0,0 +1,75 @@
|
|
|
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 '@/plugins';
|
|
11
|
+
|
|
12
|
+
import { HorizontalLine, TreeItem, TreeLevel, TreeRow, TreeTitle } from './styles';
|
|
13
|
+
|
|
14
|
+
interface PropsType {
|
|
15
|
+
value?: IJsonSchema;
|
|
16
|
+
parentKey?: string;
|
|
17
|
+
depth?: number;
|
|
18
|
+
drilldown?: boolean;
|
|
19
|
+
showIcon?: boolean;
|
|
20
|
+
typeManager?: JsonSchemaTypeManager;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function DisplaySchemaTree(props: Omit<PropsType, 'parentKey' | 'depth'>) {
|
|
24
|
+
return <SchemaTree {...props} />;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function SchemaTree(props: PropsType) {
|
|
28
|
+
const {
|
|
29
|
+
value: schema = {},
|
|
30
|
+
drilldown = true,
|
|
31
|
+
depth = 0,
|
|
32
|
+
showIcon = true,
|
|
33
|
+
parentKey = '',
|
|
34
|
+
} = props || {};
|
|
35
|
+
|
|
36
|
+
const typeManager = useTypeManager();
|
|
37
|
+
|
|
38
|
+
const config = typeManager.getTypeBySchema(schema);
|
|
39
|
+
const title = typeManager.getComplexText(schema);
|
|
40
|
+
const icon = typeManager?.getDisplayIcon(schema);
|
|
41
|
+
let properties: IJsonSchema['properties'] =
|
|
42
|
+
drilldown && config ? config.getTypeSchemaProperties(schema) : {};
|
|
43
|
+
const childEntries = Object.entries(properties || {});
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<TreeItem depth={depth} key={parentKey || 'root'}>
|
|
47
|
+
<TreeRow>
|
|
48
|
+
{depth !== 0 && <HorizontalLine />}
|
|
49
|
+
{showIcon &&
|
|
50
|
+
icon &&
|
|
51
|
+
React.cloneElement(icon, {
|
|
52
|
+
className: 'tree-icon',
|
|
53
|
+
})}
|
|
54
|
+
<TreeTitle>
|
|
55
|
+
{parentKey ? (
|
|
56
|
+
<>
|
|
57
|
+
{`${parentKey} (`}
|
|
58
|
+
{title}
|
|
59
|
+
{')'}
|
|
60
|
+
</>
|
|
61
|
+
) : (
|
|
62
|
+
title
|
|
63
|
+
)}
|
|
64
|
+
</TreeTitle>
|
|
65
|
+
</TreeRow>
|
|
66
|
+
{childEntries?.length ? (
|
|
67
|
+
<TreeLevel>
|
|
68
|
+
{childEntries.map(([key, value]) => (
|
|
69
|
+
<SchemaTree key={key} {...props} parentKey={key} value={value} depth={depth + 1} />
|
|
70
|
+
))}
|
|
71
|
+
</TreeLevel>
|
|
72
|
+
) : null}
|
|
73
|
+
</TreeItem>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
@@ -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
|
+
`;
|
|
@@ -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
|
+
}
|