@flowgram.ai/form-materials 0.1.0-alpha.10
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 +99 -0
- package/bin/materials.ts +156 -0
- package/bin/project.ts +91 -0
- package/dist/esm/index.js +3303 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +495 -0
- package/dist/index.d.ts +495 -0
- package/dist/index.js +3299 -0
- package/dist/index.js.map +1 -0
- package/package.json +75 -0
- package/src/components/batch-outputs/config.json +12 -0
- package/src/components/batch-outputs/index.tsx +61 -0
- package/src/components/batch-outputs/styles.tsx +19 -0
- package/src/components/batch-outputs/types.ts +22 -0
- package/src/components/batch-outputs/use-list.ts +86 -0
- package/src/components/batch-variable-selector/config.json +5 -0
- package/src/components/batch-variable-selector/index.tsx +24 -0
- package/src/components/code-editor/config.json +9 -0
- package/src/components/code-editor/index.tsx +74 -0
- package/src/components/code-editor/language-features.ts +24 -0
- package/src/components/code-editor/theme/dark.ts +119 -0
- package/src/components/code-editor/theme/index.ts +12 -0
- package/src/components/code-editor/theme/light.ts +119 -0
- package/src/components/code-editor/utils.ts +20 -0
- package/src/components/condition-row/config.json +5 -0
- package/src/components/condition-row/constants.ts +128 -0
- package/src/components/condition-row/hooks/useOp.tsx +50 -0
- package/src/components/condition-row/hooks/useRule.ts +31 -0
- package/src/components/condition-row/index.tsx +81 -0
- package/src/components/condition-row/styles.tsx +30 -0
- package/src/components/condition-row/types.ts +42 -0
- package/src/components/constant-input/config.json +6 -0
- package/src/components/constant-input/index.tsx +86 -0
- package/src/components/constant-input/types.ts +23 -0
- package/src/components/dynamic-value-input/config.json +5 -0
- package/src/components/dynamic-value-input/index.tsx +92 -0
- package/src/components/dynamic-value-input/styles.tsx +26 -0
- package/src/components/index.ts +18 -0
- package/src/components/json-editor-with-variables/config.json +13 -0
- package/src/components/json-editor-with-variables/extensions/variable-tag.tsx +173 -0
- package/src/components/json-editor-with-variables/extensions/variable-tree.tsx +83 -0
- package/src/components/json-editor-with-variables/index.tsx +19 -0
- package/src/components/json-editor-with-variables/styles.tsx +44 -0
- package/src/components/json-schema-editor/components/blur-input.tsx +27 -0
- package/src/components/json-schema-editor/config.json +13 -0
- package/src/components/json-schema-editor/default-value.tsx +135 -0
- package/src/components/json-schema-editor/hooks.tsx +166 -0
- package/src/components/json-schema-editor/index.tsx +267 -0
- package/src/components/json-schema-editor/styles.tsx +240 -0
- package/src/components/json-schema-editor/types.ts +26 -0
- package/src/components/json-schema-editor/utils.ts +29 -0
- package/src/components/prompt-editor/config.json +9 -0
- package/src/components/prompt-editor/extensions/jinja.tsx +58 -0
- package/src/components/prompt-editor/extensions/language-support.tsx +19 -0
- package/src/components/prompt-editor/extensions/markdown.tsx +75 -0
- package/src/components/prompt-editor/index.tsx +68 -0
- package/src/components/prompt-editor/styles.tsx +18 -0
- package/src/components/prompt-editor/types.tsx +18 -0
- package/src/components/prompt-editor-with-inputs/config.json +13 -0
- package/src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx +82 -0
- package/src/components/prompt-editor-with-inputs/index.tsx +22 -0
- package/src/components/prompt-editor-with-inputs/inputs-picker.tsx +100 -0
- package/src/components/prompt-editor-with-variables/config.json +13 -0
- package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +179 -0
- package/src/components/prompt-editor-with-variables/extensions/variable-tree.tsx +83 -0
- package/src/components/prompt-editor-with-variables/index.tsx +19 -0
- package/src/components/prompt-editor-with-variables/styles.tsx +44 -0
- package/src/components/type-selector/config.json +5 -0
- package/src/components/type-selector/constants.tsx +364 -0
- package/src/components/type-selector/index.tsx +62 -0
- package/src/components/variable-selector/config.json +5 -0
- package/src/components/variable-selector/index.tsx +116 -0
- package/src/components/variable-selector/styles.tsx +59 -0
- package/src/components/variable-selector/use-variable-tree.tsx +103 -0
- package/src/effects/auto-rename-ref/config.json +5 -0
- package/src/effects/auto-rename-ref/index.ts +109 -0
- package/src/effects/index.ts +10 -0
- package/src/effects/provide-batch-input/config.json +5 -0
- package/src/effects/provide-batch-input/index.ts +43 -0
- package/src/effects/provide-batch-outputs/config.json +5 -0
- package/src/effects/provide-batch-outputs/index.ts +38 -0
- package/src/effects/provide-json-schema-outputs/config.json +8 -0
- package/src/effects/provide-json-schema-outputs/index.ts +28 -0
- package/src/effects/sync-variable-title/config.json +5 -0
- package/src/effects/sync-variable-title/index.ts +28 -0
- package/src/form-plugins/batch-outputs-plugin/config.json +7 -0
- package/src/form-plugins/batch-outputs-plugin/index.ts +104 -0
- package/src/form-plugins/index.ts +6 -0
- package/src/index.ts +10 -0
- package/src/typings/flow-value/config.json +5 -0
- package/src/typings/flow-value/index.ts +32 -0
- package/src/typings/index.ts +7 -0
- package/src/typings/json-schema/config.json +5 -0
- package/src/typings/json-schema/index.ts +36 -0
- package/src/utils/format-legacy-refs/config.json +5 -0
- package/src/utils/format-legacy-refs/index.ts +158 -0
- package/src/utils/format-legacy-refs/readme.md +38 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/json-schema/config.json +5 -0
- package/src/utils/json-schema/index.ts +180 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { IRules, Op, OpConfigs } from './types';
|
|
7
|
+
|
|
8
|
+
export const rules: IRules = {
|
|
9
|
+
string: {
|
|
10
|
+
[Op.EQ]: 'string',
|
|
11
|
+
[Op.NEQ]: 'string',
|
|
12
|
+
[Op.CONTAINS]: 'string',
|
|
13
|
+
[Op.NOT_CONTAINS]: 'string',
|
|
14
|
+
[Op.IN]: 'array',
|
|
15
|
+
[Op.NIN]: 'array',
|
|
16
|
+
[Op.IS_EMPTY]: 'string',
|
|
17
|
+
[Op.IS_NOT_EMPTY]: 'string',
|
|
18
|
+
},
|
|
19
|
+
number: {
|
|
20
|
+
[Op.EQ]: 'number',
|
|
21
|
+
[Op.NEQ]: 'number',
|
|
22
|
+
[Op.GT]: 'number',
|
|
23
|
+
[Op.GTE]: 'number',
|
|
24
|
+
[Op.LT]: 'number',
|
|
25
|
+
[Op.LTE]: 'number',
|
|
26
|
+
[Op.IN]: 'array',
|
|
27
|
+
[Op.NIN]: 'array',
|
|
28
|
+
[Op.IS_EMPTY]: null,
|
|
29
|
+
[Op.IS_NOT_EMPTY]: null,
|
|
30
|
+
},
|
|
31
|
+
integer: {
|
|
32
|
+
[Op.EQ]: 'number',
|
|
33
|
+
[Op.NEQ]: 'number',
|
|
34
|
+
[Op.GT]: 'number',
|
|
35
|
+
[Op.GTE]: 'number',
|
|
36
|
+
[Op.LT]: 'number',
|
|
37
|
+
[Op.LTE]: 'number',
|
|
38
|
+
[Op.IN]: 'array',
|
|
39
|
+
[Op.NIN]: 'array',
|
|
40
|
+
[Op.IS_EMPTY]: null,
|
|
41
|
+
[Op.IS_NOT_EMPTY]: null,
|
|
42
|
+
},
|
|
43
|
+
boolean: {
|
|
44
|
+
[Op.EQ]: 'boolean',
|
|
45
|
+
[Op.NEQ]: 'boolean',
|
|
46
|
+
[Op.IS_TRUE]: null,
|
|
47
|
+
[Op.IS_FALSE]: null,
|
|
48
|
+
[Op.IN]: 'array',
|
|
49
|
+
[Op.NIN]: 'array',
|
|
50
|
+
[Op.IS_EMPTY]: null,
|
|
51
|
+
[Op.IS_NOT_EMPTY]: null,
|
|
52
|
+
},
|
|
53
|
+
object: {
|
|
54
|
+
[Op.IS_EMPTY]: null,
|
|
55
|
+
[Op.IS_NOT_EMPTY]: null,
|
|
56
|
+
},
|
|
57
|
+
array: {
|
|
58
|
+
[Op.IS_EMPTY]: null,
|
|
59
|
+
[Op.IS_NOT_EMPTY]: null,
|
|
60
|
+
},
|
|
61
|
+
map: {
|
|
62
|
+
[Op.IS_EMPTY]: null,
|
|
63
|
+
[Op.IS_NOT_EMPTY]: null,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const opConfigs: OpConfigs = {
|
|
68
|
+
[Op.EQ]: {
|
|
69
|
+
label: 'Equal',
|
|
70
|
+
abbreviation: '=',
|
|
71
|
+
},
|
|
72
|
+
[Op.NEQ]: {
|
|
73
|
+
label: 'Not Equal',
|
|
74
|
+
abbreviation: '≠',
|
|
75
|
+
},
|
|
76
|
+
[Op.GT]: {
|
|
77
|
+
label: 'Greater Than',
|
|
78
|
+
abbreviation: '>',
|
|
79
|
+
},
|
|
80
|
+
[Op.GTE]: {
|
|
81
|
+
label: 'Greater Than or Equal',
|
|
82
|
+
abbreviation: '>=',
|
|
83
|
+
},
|
|
84
|
+
[Op.LT]: {
|
|
85
|
+
label: 'Less Than',
|
|
86
|
+
abbreviation: '<',
|
|
87
|
+
},
|
|
88
|
+
[Op.LTE]: {
|
|
89
|
+
label: 'Less Than or Equal',
|
|
90
|
+
abbreviation: '<=',
|
|
91
|
+
},
|
|
92
|
+
[Op.IN]: {
|
|
93
|
+
label: 'In',
|
|
94
|
+
abbreviation: '∈',
|
|
95
|
+
},
|
|
96
|
+
[Op.NIN]: {
|
|
97
|
+
label: 'Not In',
|
|
98
|
+
abbreviation: '∉',
|
|
99
|
+
},
|
|
100
|
+
[Op.CONTAINS]: {
|
|
101
|
+
label: 'Contains',
|
|
102
|
+
abbreviation: '⊇',
|
|
103
|
+
},
|
|
104
|
+
[Op.NOT_CONTAINS]: {
|
|
105
|
+
label: 'Not Contains',
|
|
106
|
+
abbreviation: '⊉',
|
|
107
|
+
},
|
|
108
|
+
[Op.IS_EMPTY]: {
|
|
109
|
+
label: 'Is Empty',
|
|
110
|
+
abbreviation: '=',
|
|
111
|
+
rightDisplay: 'Empty',
|
|
112
|
+
},
|
|
113
|
+
[Op.IS_NOT_EMPTY]: {
|
|
114
|
+
label: 'Is Not Empty',
|
|
115
|
+
abbreviation: '≠',
|
|
116
|
+
rightDisplay: 'Empty',
|
|
117
|
+
},
|
|
118
|
+
[Op.IS_TRUE]: {
|
|
119
|
+
label: 'Is True',
|
|
120
|
+
abbreviation: '=',
|
|
121
|
+
rightDisplay: 'True',
|
|
122
|
+
},
|
|
123
|
+
[Op.IS_FALSE]: {
|
|
124
|
+
label: 'Is False',
|
|
125
|
+
abbreviation: '=',
|
|
126
|
+
rightDisplay: 'False',
|
|
127
|
+
},
|
|
128
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
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 { Button, Select } from '@douyinfe/semi-ui';
|
|
9
|
+
import { IconChevronDownStroked } from '@douyinfe/semi-icons';
|
|
10
|
+
|
|
11
|
+
import { IRule, Op } from '../types';
|
|
12
|
+
import { opConfigs } from '../constants';
|
|
13
|
+
|
|
14
|
+
interface HookParams {
|
|
15
|
+
rule?: IRule;
|
|
16
|
+
op?: Op;
|
|
17
|
+
onChange: (op: Op) => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function useOp({ rule, op, onChange }: HookParams) {
|
|
21
|
+
const options = useMemo(
|
|
22
|
+
() =>
|
|
23
|
+
Object.keys(rule || {}).map((_op) => ({
|
|
24
|
+
...(opConfigs[_op as Op] || {}),
|
|
25
|
+
value: _op,
|
|
26
|
+
})),
|
|
27
|
+
[rule]
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const opConfig = useMemo(() => opConfigs[op as Op], [op]);
|
|
31
|
+
|
|
32
|
+
const renderOpSelect = () => (
|
|
33
|
+
<Select
|
|
34
|
+
style={{ height: 22 }}
|
|
35
|
+
size="small"
|
|
36
|
+
value={op}
|
|
37
|
+
optionList={options}
|
|
38
|
+
onChange={(v) => {
|
|
39
|
+
onChange(v as Op);
|
|
40
|
+
}}
|
|
41
|
+
triggerRender={({ value }) => (
|
|
42
|
+
<Button size="small" disabled={!rule}>
|
|
43
|
+
{opConfig?.abbreviation || <IconChevronDownStroked size="small" />}
|
|
44
|
+
</Button>
|
|
45
|
+
)}
|
|
46
|
+
/>
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
return { renderOpSelect, opConfig };
|
|
50
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useMemo } from 'react';
|
|
7
|
+
|
|
8
|
+
import { useScopeAvailable } from '@flowgram.ai/editor';
|
|
9
|
+
|
|
10
|
+
import { rules } from '../constants';
|
|
11
|
+
import { JsonSchemaUtils } from '../../../utils';
|
|
12
|
+
import { IFlowRefValue, JsonSchemaBasicType } from '../../../typings';
|
|
13
|
+
|
|
14
|
+
export function useRule(left?: IFlowRefValue) {
|
|
15
|
+
const available = useScopeAvailable();
|
|
16
|
+
|
|
17
|
+
const variable = useMemo(() => {
|
|
18
|
+
if (!left) return undefined;
|
|
19
|
+
return available.getByKeyPath(left.content);
|
|
20
|
+
}, [available, left]);
|
|
21
|
+
|
|
22
|
+
const rule = useMemo(() => {
|
|
23
|
+
if (!variable) return undefined;
|
|
24
|
+
|
|
25
|
+
const schema = JsonSchemaUtils.astToSchema(variable.type, { drilldown: false });
|
|
26
|
+
|
|
27
|
+
return rules[schema?.type as JsonSchemaBasicType];
|
|
28
|
+
}, [variable?.type]);
|
|
29
|
+
|
|
30
|
+
return { rule };
|
|
31
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
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 { Input } from '@douyinfe/semi-ui';
|
|
9
|
+
|
|
10
|
+
import { ConditionRowValueType, Op } from './types';
|
|
11
|
+
import { UIContainer, UILeft, UIOperator, UIRight, UIValues } from './styles';
|
|
12
|
+
import { useRule } from './hooks/useRule';
|
|
13
|
+
import { useOp } from './hooks/useOp';
|
|
14
|
+
import { VariableSelector } from '../variable-selector';
|
|
15
|
+
import { DynamicValueInput } from '../dynamic-value-input';
|
|
16
|
+
import { JsonSchemaBasicType } from '../../typings';
|
|
17
|
+
|
|
18
|
+
interface PropTypes {
|
|
19
|
+
value?: ConditionRowValueType;
|
|
20
|
+
onChange: (value?: ConditionRowValueType) => void;
|
|
21
|
+
style?: React.CSSProperties;
|
|
22
|
+
readonly?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function ConditionRow({ style, value, onChange, readonly }: PropTypes) {
|
|
26
|
+
const { left, operator, right } = value || {};
|
|
27
|
+
const { rule } = useRule(left);
|
|
28
|
+
const { renderOpSelect, opConfig } = useOp({
|
|
29
|
+
rule,
|
|
30
|
+
op: operator,
|
|
31
|
+
onChange: (v) => onChange({ ...value, operator: v }),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const targetSchema = useMemo(() => {
|
|
35
|
+
const targetType: JsonSchemaBasicType | null = rule?.[operator as Op] || null;
|
|
36
|
+
return targetType ? { type: targetType, extra: { weak: true } } : null;
|
|
37
|
+
}, [rule, opConfig]);
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<UIContainer style={style}>
|
|
41
|
+
<UIOperator>{renderOpSelect()}</UIOperator>
|
|
42
|
+
<UIValues>
|
|
43
|
+
<UILeft>
|
|
44
|
+
<VariableSelector
|
|
45
|
+
readonly={readonly}
|
|
46
|
+
style={{ width: '100%' }}
|
|
47
|
+
value={left?.content}
|
|
48
|
+
onChange={(v) =>
|
|
49
|
+
onChange({
|
|
50
|
+
...value,
|
|
51
|
+
left: {
|
|
52
|
+
type: 'ref',
|
|
53
|
+
content: v,
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
/>
|
|
58
|
+
</UILeft>
|
|
59
|
+
<UIRight>
|
|
60
|
+
{targetSchema ? (
|
|
61
|
+
<DynamicValueInput
|
|
62
|
+
readonly={readonly || !rule}
|
|
63
|
+
value={right}
|
|
64
|
+
schema={targetSchema}
|
|
65
|
+
onChange={(v) => onChange({ ...value, right: v })}
|
|
66
|
+
/>
|
|
67
|
+
) : (
|
|
68
|
+
<Input
|
|
69
|
+
size="small"
|
|
70
|
+
disabled
|
|
71
|
+
style={{ pointerEvents: 'none' }}
|
|
72
|
+
value={opConfig?.rightDisplay || 'Empty'}
|
|
73
|
+
/>
|
|
74
|
+
)}
|
|
75
|
+
</UIRight>
|
|
76
|
+
</UIValues>
|
|
77
|
+
</UIContainer>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { type ConditionRowValueType };
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
|
|
8
|
+
export const UIContainer = styled.div`
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
gap: 4px;
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
export const UIOperator = styled.div``;
|
|
15
|
+
|
|
16
|
+
export const UILeft = styled.div`
|
|
17
|
+
width: 100%;
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
export const UIRight = styled.div`
|
|
21
|
+
width: 100%;
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
export const UIValues = styled.div`
|
|
25
|
+
flex-grow: 1;
|
|
26
|
+
display: flex;
|
|
27
|
+
flex-direction: column;
|
|
28
|
+
align-items: center;
|
|
29
|
+
gap: 4px;
|
|
30
|
+
`;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { IFlowConstantRefValue, IFlowRefValue, JsonSchemaBasicType } from '../../typings';
|
|
7
|
+
|
|
8
|
+
export enum Op {
|
|
9
|
+
EQ = 'eq',
|
|
10
|
+
NEQ = 'neq',
|
|
11
|
+
GT = 'gt',
|
|
12
|
+
GTE = 'gte',
|
|
13
|
+
LT = 'lt',
|
|
14
|
+
LTE = 'lte',
|
|
15
|
+
IN = 'in',
|
|
16
|
+
NIN = 'nin',
|
|
17
|
+
CONTAINS = 'contains',
|
|
18
|
+
NOT_CONTAINS = 'not_contains',
|
|
19
|
+
IS_EMPTY = 'is_empty',
|
|
20
|
+
IS_NOT_EMPTY = 'is_not_empty',
|
|
21
|
+
IS_TRUE = 'is_true',
|
|
22
|
+
IS_FALSE = 'is_false',
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface OpConfig {
|
|
26
|
+
label: string;
|
|
27
|
+
abbreviation: string;
|
|
28
|
+
// When right is not a value, display this text
|
|
29
|
+
rightDisplay?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type OpConfigs = Record<Op, OpConfig>;
|
|
33
|
+
|
|
34
|
+
export type IRule = Partial<Record<Op, JsonSchemaBasicType | null>>;
|
|
35
|
+
|
|
36
|
+
export type IRules = Record<JsonSchemaBasicType, IRule>;
|
|
37
|
+
|
|
38
|
+
export interface ConditionRowValueType {
|
|
39
|
+
left?: IFlowRefValue;
|
|
40
|
+
operator?: Op;
|
|
41
|
+
right?: IFlowConstantRefValue;
|
|
42
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/* eslint-disable react/prop-types */
|
|
7
|
+
import React, { useMemo } from 'react';
|
|
8
|
+
|
|
9
|
+
import { Input, InputNumber, Select } from '@douyinfe/semi-ui';
|
|
10
|
+
|
|
11
|
+
import { PropsType, Strategy } from './types';
|
|
12
|
+
|
|
13
|
+
const defaultStrategies: Strategy[] = [
|
|
14
|
+
{
|
|
15
|
+
hit: (schema) => schema?.type === 'string',
|
|
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
|
+
];
|
|
66
|
+
|
|
67
|
+
export function ConstantInput(props: PropsType) {
|
|
68
|
+
const { value, onChange, schema, strategies: extraStrategies, readonly, ...rest } = props;
|
|
69
|
+
|
|
70
|
+
const strategies = useMemo(
|
|
71
|
+
() => [...defaultStrategies, ...(extraStrategies || [])],
|
|
72
|
+
[extraStrategies]
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const Renderer = useMemo(() => {
|
|
76
|
+
const strategy = strategies.find((_strategy) => _strategy.hit(schema));
|
|
77
|
+
|
|
78
|
+
return strategy?.Renderer;
|
|
79
|
+
}, [strategies, schema]);
|
|
80
|
+
|
|
81
|
+
if (!Renderer) {
|
|
82
|
+
return <Input size="small" disabled placeholder="Unsupported type" />;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return <Renderer value={value} onChange={onChange} readonly={readonly} {...rest} />;
|
|
86
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { IJsonSchema } from '../../typings';
|
|
7
|
+
|
|
8
|
+
export interface Strategy<Value = any> {
|
|
9
|
+
hit: (schema: IJsonSchema) => boolean;
|
|
10
|
+
Renderer: React.FC<RendererProps<Value>>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface RendererProps<Value = any> {
|
|
14
|
+
value?: Value;
|
|
15
|
+
onChange?: (value: Value) => void;
|
|
16
|
+
readonly?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface PropsType extends RendererProps {
|
|
20
|
+
schema: IJsonSchema;
|
|
21
|
+
strategies?: Strategy[];
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
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 { IconButton } from '@douyinfe/semi-ui';
|
|
9
|
+
import { IconSetting } from '@douyinfe/semi-icons';
|
|
10
|
+
|
|
11
|
+
import { Strategy } from '../constant-input/types';
|
|
12
|
+
import { ConstantInput } from '../constant-input';
|
|
13
|
+
import { IFlowConstantRefValue } from '../../typings/flow-value';
|
|
14
|
+
import { UIContainer, UIMain, UITrigger } from './styles';
|
|
15
|
+
import { VariableSelector } from '../variable-selector';
|
|
16
|
+
import { IJsonSchema } from '../../typings';
|
|
17
|
+
|
|
18
|
+
interface PropsType {
|
|
19
|
+
value?: IFlowConstantRefValue;
|
|
20
|
+
onChange: (value?: IFlowConstantRefValue) => void;
|
|
21
|
+
readonly?: boolean;
|
|
22
|
+
hasError?: boolean;
|
|
23
|
+
style?: React.CSSProperties;
|
|
24
|
+
schema?: IJsonSchema;
|
|
25
|
+
constantProps?: {
|
|
26
|
+
strategies?: Strategy[];
|
|
27
|
+
schema?: IJsonSchema; // set schema of constant input only
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function DynamicValueInput({
|
|
33
|
+
value,
|
|
34
|
+
onChange,
|
|
35
|
+
readonly,
|
|
36
|
+
style,
|
|
37
|
+
schema,
|
|
38
|
+
constantProps,
|
|
39
|
+
}: PropsType) {
|
|
40
|
+
// When is number type, include integer as well
|
|
41
|
+
const includeSchema = useMemo(() => {
|
|
42
|
+
if (schema?.type === 'number') {
|
|
43
|
+
return [schema, { type: 'integer' }];
|
|
44
|
+
}
|
|
45
|
+
return schema;
|
|
46
|
+
}, [schema]);
|
|
47
|
+
|
|
48
|
+
const renderMain = () => {
|
|
49
|
+
if (value?.type === 'ref') {
|
|
50
|
+
// Display Variable Or Delete
|
|
51
|
+
return (
|
|
52
|
+
<VariableSelector
|
|
53
|
+
style={{ width: '100%' }}
|
|
54
|
+
value={value?.content}
|
|
55
|
+
onChange={(_v) => onChange(_v ? { type: 'ref', content: _v } : undefined)}
|
|
56
|
+
includeSchema={includeSchema}
|
|
57
|
+
readonly={readonly}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<ConstantInput
|
|
64
|
+
value={value?.content}
|
|
65
|
+
onChange={(_v) => onChange({ type: 'constant', content: _v })}
|
|
66
|
+
schema={schema || { type: 'string' }}
|
|
67
|
+
readonly={readonly}
|
|
68
|
+
{...constantProps}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const renderTrigger = () => (
|
|
74
|
+
<VariableSelector
|
|
75
|
+
style={{ width: '100%' }}
|
|
76
|
+
value={value?.type === 'ref' ? value?.content : undefined}
|
|
77
|
+
onChange={(_v) => onChange({ type: 'ref', content: _v })}
|
|
78
|
+
includeSchema={includeSchema}
|
|
79
|
+
readonly={readonly}
|
|
80
|
+
triggerRender={() => (
|
|
81
|
+
<IconButton disabled={readonly} size="small" icon={<IconSetting size="small" />} />
|
|
82
|
+
)}
|
|
83
|
+
/>
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<UIContainer style={style}>
|
|
88
|
+
<UIMain>{renderMain()}</UIMain>
|
|
89
|
+
<UITrigger>{renderTrigger()}</UITrigger>
|
|
90
|
+
</UIContainer>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
|
|
8
|
+
export const UIContainer = styled.div`
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
gap: 5px;
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
export const UIMain = styled.div`
|
|
15
|
+
flex-grow: 1;
|
|
16
|
+
overflow: hidden;
|
|
17
|
+
min-width: 0;
|
|
18
|
+
|
|
19
|
+
& .semi-tree-select,
|
|
20
|
+
& .semi-input-number,
|
|
21
|
+
& .semi-select {
|
|
22
|
+
width: 100%;
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
export const UITrigger = styled.div``;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export * from './variable-selector';
|
|
7
|
+
export * from './type-selector';
|
|
8
|
+
export * from './json-schema-editor';
|
|
9
|
+
export * from './batch-variable-selector';
|
|
10
|
+
export * from './constant-input';
|
|
11
|
+
export * from './dynamic-value-input';
|
|
12
|
+
export * from './condition-row';
|
|
13
|
+
export * from './batch-outputs';
|
|
14
|
+
export * from './prompt-editor';
|
|
15
|
+
export * from './prompt-editor-with-variables';
|
|
16
|
+
export * from './prompt-editor-with-inputs';
|
|
17
|
+
export * from './code-editor';
|
|
18
|
+
export * from './json-editor-with-variables';
|