@flowgram.ai/form-materials 0.1.0-alpha.13 → 0.1.0-alpha.14
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 +0 -11
- package/bin/materials.ts +29 -2
- package/dist/esm/chunk-727SU246.js +13 -0
- package/dist/esm/chunk-727SU246.js.map +1 -0
- package/dist/esm/chunk-DEZUEMUM.js +284 -0
- package/dist/esm/chunk-DEZUEMUM.js.map +1 -0
- package/dist/esm/chunk-DUOXDOUE.js +477 -0
- package/dist/esm/chunk-DUOXDOUE.js.map +1 -0
- package/dist/esm/editor-6UMULJYB.js +180 -0
- package/dist/esm/editor-6UMULJYB.js.map +1 -0
- package/dist/esm/editor-EYOQTGMT.js +282 -0
- package/dist/esm/editor-EYOQTGMT.js.map +1 -0
- package/dist/esm/editor-OXPGKPF5.js +167 -0
- package/dist/esm/editor-OXPGKPF5.js.map +1 -0
- package/dist/esm/editor-VO6YAXRC.js +249 -0
- package/dist/esm/editor-VO6YAXRC.js.map +1 -0
- package/dist/esm/editor-XYLKTB6L.js +365 -0
- package/dist/esm/editor-XYLKTB6L.js.map +1 -0
- package/dist/esm/index.js +1110 -2306
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +298 -59
- package/dist/index.d.ts +298 -59
- package/dist/index.js +3932 -2681
- package/dist/index.js.map +1 -1
- package/package.json +9 -8
- package/src/components/batch-outputs/index.tsx +3 -2
- package/src/components/code-editor/editor.tsx +89 -0
- package/src/components/code-editor/index.tsx +5 -89
- package/src/components/code-editor/language-features.ts +18 -18
- package/src/components/code-editor/theme/dark.ts +49 -30
- package/src/components/code-editor/theme/light.ts +56 -32
- package/src/components/code-editor-mini/index.tsx +2 -2
- package/src/components/condition-row/constants.ts +8 -0
- package/src/components/condition-row/index.tsx +4 -0
- package/src/components/db-condition-row/hooks/use-left.tsx +66 -0
- package/src/components/db-condition-row/hooks/use-op.tsx +59 -0
- package/src/components/db-condition-row/index.tsx +93 -0
- package/src/components/db-condition-row/styles.tsx +43 -0
- package/src/components/db-condition-row/types.ts +34 -0
- package/src/components/display-flow-value/index.tsx +2 -12
- package/src/components/display-inputs-values/index.tsx +44 -6
- package/src/components/dynamic-value-input/hooks.ts +25 -4
- package/src/components/dynamic-value-input/index.tsx +21 -12
- package/src/components/dynamic-value-input/styles.tsx +14 -4
- package/src/components/index.ts +3 -0
- package/src/components/inputs-values/index.tsx +14 -3
- package/src/components/inputs-values/styles.tsx +1 -1
- package/src/components/inputs-values-tree/hooks/use-child-list.tsx +76 -0
- package/src/components/inputs-values-tree/index.tsx +62 -0
- package/src/components/inputs-values-tree/row.tsx +177 -0
- package/src/components/inputs-values-tree/styles.tsx +128 -0
- package/src/components/inputs-values-tree/types.ts +21 -0
- package/src/components/json-editor-with-variables/editor.tsx +69 -0
- package/src/components/json-editor-with-variables/extensions/variable-tag.tsx +6 -5
- package/src/components/json-editor-with-variables/index.tsx +5 -59
- package/src/components/json-schema-editor/default-value.tsx +1 -3
- package/src/components/json-schema-editor/hooks.tsx +14 -3
- package/src/components/json-schema-editor/index.tsx +18 -58
- package/src/components/json-schema-editor/styles.tsx +12 -55
- package/src/components/json-schema-editor/types.ts +0 -1
- package/src/components/prompt-editor/editor.tsx +81 -0
- package/src/components/prompt-editor/index.tsx +5 -62
- package/src/components/prompt-editor-with-inputs/editor.tsx +25 -0
- package/src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx +11 -0
- package/src/components/prompt-editor-with-inputs/index.tsx +5 -16
- package/src/components/prompt-editor-with-inputs/inputs-picker.tsx +34 -17
- package/src/components/prompt-editor-with-variables/editor.tsx +22 -0
- package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +12 -20
- package/src/components/prompt-editor-with-variables/extensions/variable-tree.tsx +13 -1
- package/src/components/prompt-editor-with-variables/index.tsx +5 -13
- package/src/components/type-selector/index.tsx +12 -2
- package/src/components/variable-selector/context.tsx +28 -0
- package/src/components/variable-selector/index.tsx +10 -1
- package/src/components/variable-selector/use-variable-tree.tsx +3 -3
- package/src/effects/auto-rename-ref/index.ts +7 -54
- package/src/effects/validate-when-variable-sync/index.ts +1 -1
- package/src/form-plugins/infer-assign-plugin/index.ts +1 -1
- package/src/form-plugins/infer-inputs-plugin/index.ts +4 -76
- package/src/hooks/use-object-list/index.tsx +35 -7
- package/src/index.ts +1 -0
- package/src/plugins/json-schema-preset/manager.ts +1 -0
- package/src/plugins/json-schema-preset/type-definition/date-time.tsx +25 -0
- package/src/plugins/json-schema-preset/type-definition/index.tsx +2 -0
- package/src/plugins/json-schema-preset/type-definition/string.tsx +18 -9
- package/src/shared/flow-value/index.ts +6 -0
- package/src/shared/flow-value/schema.ts +38 -0
- package/src/shared/flow-value/utils.ts +201 -0
- package/src/shared/format-legacy-refs/index.ts +1 -1
- package/src/shared/index.ts +3 -0
- package/src/shared/lazy-suspense/index.tsx +28 -0
- package/src/shared/polyfill-create-root/index.tsx +33 -0
- package/src/typings/flow-value/index.ts +3 -1
- package/src/validate/validate-flow-value/index.tsx +4 -16
- package/src/components/json-schema-editor/components/blur-input.tsx +0 -27
- package/src/plugins/disable-declaration-plugin/config.json +0 -5
- package/src/plugins/json-schema-preset/config.json +0 -9
- /package/src/components/{inputs-values/components/blur-input.tsx → blur-input/index.tsx} +0 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useMemo } from 'react';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
|
|
9
|
+
import { JsonSchemaTypeManager, useTypeManager } from '@flowgram.ai/json-schema';
|
|
10
|
+
import { Icon } from '@douyinfe/semi-ui';
|
|
11
|
+
|
|
12
|
+
import { ConditionRow } from '@/components';
|
|
13
|
+
|
|
14
|
+
import { DBConditionOptionType, IRules } from '../types';
|
|
15
|
+
import { UIOptionLabel, UISelect } from '../styles';
|
|
16
|
+
|
|
17
|
+
const defaultRules = ConditionRow.defaultRules;
|
|
18
|
+
|
|
19
|
+
interface HookParams {
|
|
20
|
+
left?: string;
|
|
21
|
+
options?: DBConditionOptionType[];
|
|
22
|
+
userRules?: IRules;
|
|
23
|
+
readonly?: boolean;
|
|
24
|
+
onChange: (leftKey: string) => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function useLeft({ left, options, userRules, readonly, onChange }: HookParams) {
|
|
28
|
+
const rules = useMemo(() => ({ ...defaultRules, ...(userRules || {}) }), [userRules]);
|
|
29
|
+
|
|
30
|
+
const typeManager = useTypeManager() as JsonSchemaTypeManager;
|
|
31
|
+
|
|
32
|
+
const rule = useMemo(() => {
|
|
33
|
+
if (!left) return undefined;
|
|
34
|
+
|
|
35
|
+
const option = options?.find((item) => item.value === left);
|
|
36
|
+
|
|
37
|
+
if (!option?.schema?.type) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return rules[option.schema.type];
|
|
42
|
+
}, [left, options, rules]);
|
|
43
|
+
|
|
44
|
+
const renderDBOptionSelect = () => (
|
|
45
|
+
<UISelect
|
|
46
|
+
disabled={readonly}
|
|
47
|
+
size="small"
|
|
48
|
+
style={{ width: '100%' }}
|
|
49
|
+
value={left}
|
|
50
|
+
onChange={(v) => onChange(v as string)}
|
|
51
|
+
optionList={
|
|
52
|
+
options?.map((item) => ({
|
|
53
|
+
label: (
|
|
54
|
+
<UIOptionLabel>
|
|
55
|
+
<Icon size="small" svg={typeManager.getDisplayIcon(item.schema)} />
|
|
56
|
+
{item.label}
|
|
57
|
+
</UIOptionLabel>
|
|
58
|
+
),
|
|
59
|
+
value: item.value,
|
|
60
|
+
})) || []
|
|
61
|
+
}
|
|
62
|
+
/>
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
return { rule, renderDBOptionSelect };
|
|
66
|
+
}
|
|
@@ -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 { I18n } from '@flowgram.ai/editor';
|
|
9
|
+
import { Button, Select } from '@douyinfe/semi-ui';
|
|
10
|
+
import { IconChevronDownStroked } from '@douyinfe/semi-icons';
|
|
11
|
+
|
|
12
|
+
import { ConditionRow } from '@/components';
|
|
13
|
+
|
|
14
|
+
import { IRule, OpConfigs } from '../types';
|
|
15
|
+
|
|
16
|
+
const defaultOpConfigs = ConditionRow.defaultOpConfigs;
|
|
17
|
+
|
|
18
|
+
interface HookParams {
|
|
19
|
+
rule?: IRule;
|
|
20
|
+
op?: string;
|
|
21
|
+
onChange: (op: string) => void;
|
|
22
|
+
readonly?: boolean;
|
|
23
|
+
userOps?: OpConfigs;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function useOp({ rule, op, onChange, readonly, userOps }: HookParams) {
|
|
27
|
+
const options = useMemo(
|
|
28
|
+
() =>
|
|
29
|
+
Object.keys(rule || {}).map((_op) => ({
|
|
30
|
+
...(defaultOpConfigs[_op] || {}),
|
|
31
|
+
...(userOps?.[_op] || {}),
|
|
32
|
+
value: _op,
|
|
33
|
+
label: I18n.t(userOps?.[_op]?.label || defaultOpConfigs[_op]?.label),
|
|
34
|
+
})),
|
|
35
|
+
[rule, userOps]
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const opConfig = useMemo(() => defaultOpConfigs[op as string], [op]);
|
|
39
|
+
|
|
40
|
+
const renderOpSelect = () => (
|
|
41
|
+
<Select
|
|
42
|
+
style={{ height: 22 }}
|
|
43
|
+
disabled={readonly}
|
|
44
|
+
size="small"
|
|
45
|
+
value={op}
|
|
46
|
+
optionList={options}
|
|
47
|
+
onChange={(v) => {
|
|
48
|
+
onChange(v as string);
|
|
49
|
+
}}
|
|
50
|
+
triggerRender={({ value }) => (
|
|
51
|
+
<Button size="small" disabled={!rule}>
|
|
52
|
+
{opConfig?.abbreviation || <IconChevronDownStroked size="small" />}
|
|
53
|
+
</Button>
|
|
54
|
+
)}
|
|
55
|
+
/>
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
return { renderOpSelect, opConfig };
|
|
59
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
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 { I18n } from '@flowgram.ai/editor';
|
|
9
|
+
import { Input } from '@douyinfe/semi-ui';
|
|
10
|
+
|
|
11
|
+
import { InjectDynamicValueInput } from '@/components/dynamic-value-input';
|
|
12
|
+
|
|
13
|
+
import { DBConditionOptionType, DBConditionRowValueType, IRules, OpConfigs } from './types';
|
|
14
|
+
import { UIContainer, UILeft, UIOperator, UIRight, UIValues } from './styles';
|
|
15
|
+
import { useOp } from './hooks/use-op';
|
|
16
|
+
import { useLeft } from './hooks/use-left';
|
|
17
|
+
|
|
18
|
+
interface PropTypes {
|
|
19
|
+
value?: DBConditionRowValueType;
|
|
20
|
+
onChange: (value?: DBConditionRowValueType) => void;
|
|
21
|
+
style?: React.CSSProperties;
|
|
22
|
+
options?: DBConditionOptionType[];
|
|
23
|
+
readonly?: boolean;
|
|
24
|
+
ruleConfig?: {
|
|
25
|
+
ops?: OpConfigs;
|
|
26
|
+
rules?: IRules;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const defaultRuleConfig = {
|
|
31
|
+
ops: {},
|
|
32
|
+
rules: {},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export function DBConditionRow({
|
|
36
|
+
style,
|
|
37
|
+
value,
|
|
38
|
+
onChange,
|
|
39
|
+
readonly,
|
|
40
|
+
options,
|
|
41
|
+
ruleConfig = defaultRuleConfig,
|
|
42
|
+
}: PropTypes) {
|
|
43
|
+
const { left, operator, right } = value || {};
|
|
44
|
+
|
|
45
|
+
const { rule, renderDBOptionSelect } = useLeft({
|
|
46
|
+
left,
|
|
47
|
+
options,
|
|
48
|
+
onChange: (leftKey) => onChange({ ...value, left: leftKey }),
|
|
49
|
+
readonly,
|
|
50
|
+
userRules: ruleConfig.rules,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const { renderOpSelect, opConfig } = useOp({
|
|
54
|
+
rule,
|
|
55
|
+
op: operator,
|
|
56
|
+
onChange: (v) => onChange({ ...value, operator: v }),
|
|
57
|
+
readonly,
|
|
58
|
+
userOps: ruleConfig.ops,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const targetSchema = useMemo(() => {
|
|
62
|
+
const targetType: string | null = rule?.[operator || ''] || null;
|
|
63
|
+
return targetType ? { type: targetType, extra: { weak: true } } : null;
|
|
64
|
+
}, [rule, opConfig]);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<UIContainer style={style}>
|
|
68
|
+
<UIOperator>{renderOpSelect()}</UIOperator>
|
|
69
|
+
<UIValues>
|
|
70
|
+
<UILeft>{renderDBOptionSelect()}</UILeft>
|
|
71
|
+
<UIRight>
|
|
72
|
+
{targetSchema ? (
|
|
73
|
+
<InjectDynamicValueInput
|
|
74
|
+
readonly={readonly || !rule}
|
|
75
|
+
value={right}
|
|
76
|
+
schema={targetSchema}
|
|
77
|
+
onChange={(v) => onChange({ ...value, right: v })}
|
|
78
|
+
/>
|
|
79
|
+
) : (
|
|
80
|
+
<Input
|
|
81
|
+
size="small"
|
|
82
|
+
disabled
|
|
83
|
+
style={{ pointerEvents: 'none' }}
|
|
84
|
+
value={opConfig?.rightDisplay || I18n.t('Empty')}
|
|
85
|
+
/>
|
|
86
|
+
)}
|
|
87
|
+
</UIRight>
|
|
88
|
+
</UIValues>
|
|
89
|
+
</UIContainer>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { type DBConditionRowValueType, type DBConditionOptionType };
|
|
@@ -0,0 +1,43 @@
|
|
|
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 { Select } from '@douyinfe/semi-ui';
|
|
8
|
+
|
|
9
|
+
export const UIContainer = styled.div`
|
|
10
|
+
display: flex;
|
|
11
|
+
align-items: center;
|
|
12
|
+
gap: 4px;
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
export const UIOperator = styled.div``;
|
|
16
|
+
|
|
17
|
+
export const UILeft = styled.div`
|
|
18
|
+
width: 100%;
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
export const UIRight = styled.div`
|
|
22
|
+
width: 100%;
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
export const UIValues = styled.div`
|
|
26
|
+
flex-grow: 1;
|
|
27
|
+
display: flex;
|
|
28
|
+
flex-direction: column;
|
|
29
|
+
align-items: center;
|
|
30
|
+
gap: 4px;
|
|
31
|
+
`;
|
|
32
|
+
|
|
33
|
+
export const UIOptionLabel = styled.div`
|
|
34
|
+
display: flex;
|
|
35
|
+
align-items: center;
|
|
36
|
+
gap: 10px;
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
export const UISelect = styled(Select)`
|
|
40
|
+
& .semi-select-selection {
|
|
41
|
+
margin-left: 5px;
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
7
|
+
|
|
8
|
+
import { IFlowConstantRefValue } from '@/typings';
|
|
9
|
+
|
|
10
|
+
export interface OpConfig {
|
|
11
|
+
label: string;
|
|
12
|
+
abbreviation: string;
|
|
13
|
+
// When right is not a value, display this text
|
|
14
|
+
rightDisplay?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type OpConfigs = Record<string, OpConfig>;
|
|
18
|
+
|
|
19
|
+
export type IRule = Partial<Record<string, string | null>>;
|
|
20
|
+
|
|
21
|
+
export type IRules = Record<string, IRule>;
|
|
22
|
+
|
|
23
|
+
export interface DBConditionRowValueType {
|
|
24
|
+
left?: string;
|
|
25
|
+
schema?: IJsonSchema;
|
|
26
|
+
operator?: string;
|
|
27
|
+
right?: IFlowConstantRefValue;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface DBConditionOptionType {
|
|
31
|
+
label: string | JSX.Element;
|
|
32
|
+
value: string;
|
|
33
|
+
schema: IJsonSchema;
|
|
34
|
+
}
|
|
@@ -9,6 +9,7 @@ import { JsonSchemaTypeManager, JsonSchemaUtils } from '@flowgram.ai/json-schema
|
|
|
9
9
|
import { useScopeAvailable } from '@flowgram.ai/editor';
|
|
10
10
|
|
|
11
11
|
import { IFlowValue } from '@/typings';
|
|
12
|
+
import { FlowValueUtils } from '@/shared';
|
|
12
13
|
import { DisplaySchemaTag } from '@/components/display-schema-tag';
|
|
13
14
|
|
|
14
15
|
interface PropsType {
|
|
@@ -31,18 +32,7 @@ export function DisplayFlowValue({ value, title, showIconInTree }: PropsType) {
|
|
|
31
32
|
return { type: 'string' };
|
|
32
33
|
}
|
|
33
34
|
if (value?.type === 'constant') {
|
|
34
|
-
|
|
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
|
-
}
|
|
35
|
+
return FlowValueUtils.inferConstantJsonSchema(value);
|
|
46
36
|
}
|
|
47
37
|
|
|
48
38
|
return { type: 'unknown' };
|
|
@@ -3,15 +3,19 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import React from 'react';
|
|
6
|
+
import React, { useMemo } from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { isPlainObject } from 'lodash-es';
|
|
9
|
+
import { useScopeAvailable } from '@flowgram.ai/editor';
|
|
10
|
+
|
|
11
|
+
import { FlowValueUtils } from '@/shared';
|
|
9
12
|
import { DisplayFlowValue } from '@/components/display-flow-value';
|
|
10
13
|
|
|
11
14
|
import { DisplayInputsWrapper } from './styles';
|
|
15
|
+
import { DisplaySchemaTag } from '../display-schema-tag';
|
|
12
16
|
|
|
13
17
|
interface PropsType {
|
|
14
|
-
value?:
|
|
18
|
+
value?: any;
|
|
15
19
|
showIconInTree?: boolean;
|
|
16
20
|
}
|
|
17
21
|
|
|
@@ -20,9 +24,43 @@ export function DisplayInputsValues({ value, showIconInTree }: PropsType) {
|
|
|
20
24
|
|
|
21
25
|
return (
|
|
22
26
|
<DisplayInputsWrapper>
|
|
23
|
-
{childEntries.map(([key, value]) =>
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
{childEntries.map(([key, value]) => {
|
|
28
|
+
if (FlowValueUtils.isFlowValue(value)) {
|
|
29
|
+
return (
|
|
30
|
+
<DisplayFlowValue key={key} title={key} value={value} showIconInTree={showIconInTree} />
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (isPlainObject(value)) {
|
|
35
|
+
return (
|
|
36
|
+
<DisplayInputsValueAllInTag
|
|
37
|
+
key={key}
|
|
38
|
+
title={key}
|
|
39
|
+
value={value}
|
|
40
|
+
showIconInTree={showIconInTree}
|
|
41
|
+
/>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return null;
|
|
46
|
+
})}
|
|
26
47
|
</DisplayInputsWrapper>
|
|
27
48
|
);
|
|
28
49
|
}
|
|
50
|
+
|
|
51
|
+
export function DisplayInputsValueAllInTag({
|
|
52
|
+
value,
|
|
53
|
+
title,
|
|
54
|
+
showIconInTree,
|
|
55
|
+
}: PropsType & {
|
|
56
|
+
title: string;
|
|
57
|
+
}) {
|
|
58
|
+
const available = useScopeAvailable();
|
|
59
|
+
|
|
60
|
+
const schema = useMemo(
|
|
61
|
+
() => FlowValueUtils.inferJsonSchema(value, available.scope),
|
|
62
|
+
[available.version, value]
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
return <DisplaySchemaTag title={title} value={schema} showIconInTree={showIconInTree} />;
|
|
66
|
+
}
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { useMemo, useState } from 'react';
|
|
6
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
9
9
|
import { useScopeAvailable } from '@flowgram.ai/editor';
|
|
10
10
|
|
|
11
|
-
import { IFlowConstantRefValue } from '@/typings
|
|
11
|
+
import { IFlowConstantRefValue } from '@/typings';
|
|
12
12
|
|
|
13
13
|
export function useRefVariable(value?: IFlowConstantRefValue) {
|
|
14
14
|
const available = useScopeAvailable();
|
|
@@ -33,9 +33,30 @@ export function useSelectSchema(
|
|
|
33
33
|
defaultSelectSchema = value?.schema || defaultSelectSchema;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
const changeVersion = useRef(0);
|
|
37
|
+
const effectVersion = useRef(0);
|
|
38
|
+
|
|
36
39
|
const [selectSchema, setSelectSchema] = useState(defaultSelectSchema);
|
|
37
40
|
|
|
38
|
-
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
effectVersion.current += 1;
|
|
43
|
+
if (changeVersion.current === effectVersion.current) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
effectVersion.current = changeVersion.current;
|
|
47
|
+
|
|
48
|
+
if (value?.type === 'constant' && value?.schema) {
|
|
49
|
+
setSelectSchema(value?.schema);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
}, [value]);
|
|
53
|
+
|
|
54
|
+
const setSelectSchemaWithVersionUpdate = (schema: IJsonSchema) => {
|
|
55
|
+
setSelectSchema(schema);
|
|
56
|
+
changeVersion.current += 1;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return [selectSchema, setSelectSchemaWithVersionUpdate] as const;
|
|
39
60
|
}
|
|
40
61
|
|
|
41
62
|
export function useIncludeSchema(schemaFromProps?: IJsonSchema) {
|
|
@@ -46,7 +67,7 @@ export function useIncludeSchema(schemaFromProps?: IJsonSchema) {
|
|
|
46
67
|
if (schemaFromProps?.type === 'number') {
|
|
47
68
|
return [schemaFromProps, { type: 'integer' }];
|
|
48
69
|
}
|
|
49
|
-
return { ...schemaFromProps, extra: { ...schemaFromProps?.extra
|
|
70
|
+
return { ...schemaFromProps, extra: { weak: true, ...schemaFromProps?.extra } };
|
|
50
71
|
}, [schemaFromProps]);
|
|
51
72
|
|
|
52
73
|
return includeSchema;
|
|
@@ -5,11 +5,16 @@
|
|
|
5
5
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
JsonSchemaUtils,
|
|
10
|
+
IJsonSchema,
|
|
11
|
+
useTypeManager,
|
|
12
|
+
type JsonSchemaTypeManager,
|
|
13
|
+
} from '@flowgram.ai/json-schema';
|
|
9
14
|
import { IconButton } from '@douyinfe/semi-ui';
|
|
10
15
|
import { IconSetting } from '@douyinfe/semi-icons';
|
|
11
16
|
|
|
12
|
-
import { IFlowConstantRefValue } from '@/typings
|
|
17
|
+
import { IFlowConstantRefValue, IFlowConstantValue } from '@/typings';
|
|
13
18
|
import { createInjectMaterial } from '@/shared';
|
|
14
19
|
import { InjectVariableSelector } from '@/components/variable-selector';
|
|
15
20
|
import { TypeSelector } from '@/components/type-selector';
|
|
@@ -32,6 +37,12 @@ interface PropsType {
|
|
|
32
37
|
};
|
|
33
38
|
}
|
|
34
39
|
|
|
40
|
+
const DEFAULT_VALUE: IFlowConstantValue = {
|
|
41
|
+
type: 'constant',
|
|
42
|
+
content: '',
|
|
43
|
+
schema: { type: 'string' },
|
|
44
|
+
};
|
|
45
|
+
|
|
35
46
|
export function DynamicValueInput({
|
|
36
47
|
value,
|
|
37
48
|
onChange,
|
|
@@ -44,6 +55,8 @@ export function DynamicValueInput({
|
|
|
44
55
|
const [selectSchema, setSelectSchema] = useSelectSchema(schemaFromProps, constantProps, value);
|
|
45
56
|
const includeSchema = useIncludeSchema(schemaFromProps);
|
|
46
57
|
|
|
58
|
+
const typeManager = useTypeManager() as JsonSchemaTypeManager;
|
|
59
|
+
|
|
47
60
|
const renderTypeSelector = () => {
|
|
48
61
|
if (schemaFromProps) {
|
|
49
62
|
return <TypeSelector value={schemaFromProps} readonly={true} />;
|
|
@@ -60,24 +73,20 @@ export function DynamicValueInput({
|
|
|
60
73
|
value={selectSchema}
|
|
61
74
|
onChange={(_v) => {
|
|
62
75
|
setSelectSchema(_v || { type: 'string' });
|
|
63
|
-
let content;
|
|
64
76
|
|
|
77
|
+
const schema = _v || { type: 'string' };
|
|
78
|
+
let content = typeManager.getDefaultValue(schema);
|
|
65
79
|
if (_v?.type === 'object') {
|
|
66
80
|
content = '{}';
|
|
67
81
|
}
|
|
68
|
-
|
|
69
82
|
if (_v?.type === 'array') {
|
|
70
83
|
content = '[]';
|
|
71
84
|
}
|
|
72
85
|
|
|
73
|
-
if (_v?.type === 'boolean') {
|
|
74
|
-
content = false;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
86
|
onChange({
|
|
78
87
|
type: 'constant',
|
|
79
88
|
content,
|
|
80
|
-
schema
|
|
89
|
+
schema,
|
|
81
90
|
});
|
|
82
91
|
}}
|
|
83
92
|
readonly={readonly}
|
|
@@ -92,7 +101,7 @@ export function DynamicValueInput({
|
|
|
92
101
|
<InjectVariableSelector
|
|
93
102
|
style={{ width: '100%' }}
|
|
94
103
|
value={value?.content}
|
|
95
|
-
onChange={(_v) => onChange(_v ? { type: 'ref', content: _v } :
|
|
104
|
+
onChange={(_v) => onChange(_v ? { type: 'ref', content: _v } : DEFAULT_VALUE)}
|
|
96
105
|
includeSchema={includeSchema}
|
|
97
106
|
readonly={readonly}
|
|
98
107
|
/>
|
|
@@ -107,16 +116,16 @@ export function DynamicValueInput({
|
|
|
107
116
|
onChange={(_v) => onChange({ type: 'constant', content: _v, schema: constantSchema })}
|
|
108
117
|
schema={constantSchema || { type: 'string' }}
|
|
109
118
|
readonly={readonly}
|
|
110
|
-
strategies={[...(constantProps?.strategies || [])]}
|
|
111
119
|
fallbackRenderer={() => (
|
|
112
120
|
<InjectVariableSelector
|
|
113
121
|
style={{ width: '100%' }}
|
|
114
|
-
onChange={(_v) => onChange(_v ? { type: 'ref', content: _v } :
|
|
122
|
+
onChange={(_v) => onChange(_v ? { type: 'ref', content: _v } : DEFAULT_VALUE)}
|
|
115
123
|
includeSchema={includeSchema}
|
|
116
124
|
readonly={readonly}
|
|
117
125
|
/>
|
|
118
126
|
)}
|
|
119
127
|
{...constantProps}
|
|
128
|
+
strategies={[...(constantProps?.strategies || [])]}
|
|
120
129
|
/>
|
|
121
130
|
);
|
|
122
131
|
};
|
|
@@ -20,6 +20,8 @@ export const UIMain = styled.div`
|
|
|
20
20
|
flex-grow: 1;
|
|
21
21
|
overflow: hidden;
|
|
22
22
|
min-width: 0;
|
|
23
|
+
border-left: 1px solid var(--semi-color-border);
|
|
24
|
+
border-right: 1px solid var(--semi-color-border);
|
|
23
25
|
|
|
24
26
|
& .semi-tree-select,
|
|
25
27
|
& .semi-input-number,
|
|
@@ -33,19 +35,27 @@ export const UIMain = styled.div`
|
|
|
33
35
|
border: none;
|
|
34
36
|
border-radius: 0;
|
|
35
37
|
}
|
|
38
|
+
|
|
39
|
+
& .semi-input-textarea-wrapper {
|
|
40
|
+
border: none;
|
|
41
|
+
border-radius: 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
& .semi-input-textarea {
|
|
45
|
+
padding: 2px 6px;
|
|
46
|
+
border: none;
|
|
47
|
+
border-radius: 0;
|
|
48
|
+
word-break: break-all;
|
|
49
|
+
}
|
|
36
50
|
`;
|
|
37
51
|
|
|
38
52
|
export const UIType = styled.div`
|
|
39
|
-
border-right: 1px solid #e5e5e5;
|
|
40
|
-
|
|
41
53
|
& .semi-button {
|
|
42
54
|
border-radius: 0;
|
|
43
55
|
}
|
|
44
56
|
`;
|
|
45
57
|
|
|
46
58
|
export const UITrigger = styled.div`
|
|
47
|
-
border-left: 1px solid #e5e5e5;
|
|
48
|
-
|
|
49
59
|
& .semi-button {
|
|
50
60
|
border-radius: 0;
|
|
51
61
|
}
|
package/src/components/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './batch-variable-selector';
|
|
|
10
10
|
export * from './constant-input';
|
|
11
11
|
export * from './dynamic-value-input';
|
|
12
12
|
export * from './condition-row';
|
|
13
|
+
export * from './db-condition-row';
|
|
13
14
|
export * from './batch-outputs';
|
|
14
15
|
export * from './prompt-editor';
|
|
15
16
|
export * from './prompt-editor-with-variables';
|
|
@@ -25,3 +26,5 @@ export * from './display-flow-value';
|
|
|
25
26
|
export * from './display-inputs-values';
|
|
26
27
|
export * from './assign-rows';
|
|
27
28
|
export * from './assign-row';
|
|
29
|
+
export * from './blur-input';
|
|
30
|
+
export * from './inputs-values-tree';
|
|
@@ -12,10 +12,10 @@ import { IconDelete, IconPlus } from '@douyinfe/semi-icons';
|
|
|
12
12
|
import { IFlowConstantRefValue, IFlowValue } from '@/typings';
|
|
13
13
|
import { useObjectList } from '@/hooks';
|
|
14
14
|
import { InjectDynamicValueInput } from '@/components/dynamic-value-input';
|
|
15
|
+
import { BlurInput } from '@/components/blur-input';
|
|
15
16
|
|
|
16
17
|
import { PropsType } from './types';
|
|
17
18
|
import { UIRow, UIRows } from './styles';
|
|
18
|
-
import { BlurInput } from './components/blur-input';
|
|
19
19
|
|
|
20
20
|
export function InputsValues({
|
|
21
21
|
value,
|
|
@@ -67,8 +67,19 @@ export function InputsValues({
|
|
|
67
67
|
</UIRow>
|
|
68
68
|
))}
|
|
69
69
|
</UIRows>
|
|
70
|
-
<Button
|
|
71
|
-
|
|
70
|
+
<Button
|
|
71
|
+
disabled={readonly}
|
|
72
|
+
icon={<IconPlus />}
|
|
73
|
+
size="small"
|
|
74
|
+
onClick={() =>
|
|
75
|
+
add({
|
|
76
|
+
type: 'constant',
|
|
77
|
+
content: '',
|
|
78
|
+
schema: { type: 'string' },
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
>
|
|
82
|
+
{I18n.t('Add')}
|
|
72
83
|
</Button>
|
|
73
84
|
</div>
|
|
74
85
|
);
|