@flowgram.ai/form-materials 0.4.12 → 0.4.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/dist/cjs/components/code-editor/editor.js +54 -77
- package/dist/cjs/components/code-editor/index.js +10 -2
- package/dist/cjs/components/code-editor/language-features.js +119 -16
- package/dist/cjs/components/code-editor/theme/dark.js +120 -50
- package/dist/cjs/components/code-editor/theme/light.js +110 -61
- package/dist/cjs/components/condition-context/context.js +59 -0
- package/dist/cjs/components/condition-context/hooks/use-condition.js +97 -0
- package/dist/cjs/components/condition-context/index.js +47 -0
- package/dist/cjs/components/condition-context/op.js +117 -0
- package/dist/cjs/components/condition-row/index.js +43 -26
- package/dist/cjs/components/condition-row/types.js +1 -35
- package/dist/cjs/components/coze-editor-extensions/extensions/variable-tag.js +4 -3
- package/dist/cjs/components/coze-editor-extensions/extensions/variable-tree.js +3 -0
- package/dist/cjs/components/db-condition-row/index.js +59 -34
- package/dist/cjs/components/variable-selector/index.js +0 -1
- package/dist/cjs/form-plugins/batch-outputs-plugin/index.js +8 -1
- package/dist/cjs/form-plugins/infer-inputs-plugin/index.js +30 -3
- package/dist/cjs/plugins/json-schema-preset/create-type-preset-plugin.js +1 -0
- package/dist/cjs/plugins/json-schema-preset/react.js +1 -0
- package/dist/cjs/plugins/json-schema-preset/type-definition/array.js +30 -1
- package/dist/cjs/plugins/json-schema-preset/type-definition/boolean.js +23 -0
- package/dist/cjs/plugins/json-schema-preset/type-definition/date-time.js +31 -2
- package/dist/cjs/plugins/json-schema-preset/type-definition/index.js +9 -1
- package/dist/cjs/plugins/json-schema-preset/type-definition/integer.js +34 -1
- package/dist/cjs/{components/code-editor/init-worker.js → plugins/json-schema-preset/type-definition/map.js} +21 -23
- package/dist/cjs/plugins/json-schema-preset/type-definition/number.js +34 -1
- package/dist/cjs/plugins/json-schema-preset/type-definition/object.js +6 -1
- package/dist/cjs/plugins/json-schema-preset/type-definition/string.js +30 -1
- package/dist/cjs/plugins/json-schema-preset/types.js +18 -0
- package/dist/cjs/shared/flow-value/utils.js +22 -8
- package/dist/esm/components/code-editor/editor.mjs +4 -9
- package/dist/esm/components/code-editor/index.mjs +5 -2
- package/dist/esm/components/code-editor/language-features.mjs +49 -13
- package/dist/esm/components/code-editor/theme/dark.mjs +117 -50
- package/dist/esm/components/code-editor/theme/light.mjs +108 -62
- package/dist/esm/components/condition-context/context.mjs +19 -0
- package/dist/esm/components/condition-context/hooks/use-condition.mjs +63 -0
- package/dist/esm/components/condition-context/index.mjs +4 -0
- package/dist/esm/components/condition-context/op.mjs +80 -0
- package/dist/esm/components/condition-row/index.mjs +45 -28
- package/dist/esm/components/condition-row/types.mjs +0 -18
- package/dist/esm/components/coze-editor-extensions/extensions/variable-tag.mjs +4 -3
- package/dist/esm/components/coze-editor-extensions/extensions/variable-tree.mjs +3 -0
- package/dist/esm/components/db-condition-row/index.mjs +59 -34
- package/dist/esm/components/variable-selector/index.mjs +0 -1
- package/dist/esm/form-plugins/batch-outputs-plugin/index.mjs +8 -1
- package/dist/esm/form-plugins/infer-inputs-plugin/index.mjs +31 -4
- package/dist/esm/plugins/json-schema-preset/create-type-preset-plugin.mjs +2 -1
- package/dist/esm/plugins/json-schema-preset/react.mjs +2 -1
- package/dist/esm/plugins/json-schema-preset/type-definition/array.mjs +30 -1
- package/dist/esm/plugins/json-schema-preset/type-definition/boolean.mjs +23 -0
- package/dist/esm/plugins/json-schema-preset/type-definition/date-time.mjs +31 -2
- package/dist/esm/plugins/json-schema-preset/type-definition/index.mjs +7 -2
- package/dist/esm/plugins/json-schema-preset/type-definition/integer.mjs +34 -1
- package/dist/esm/plugins/json-schema-preset/type-definition/map.mjs +20 -0
- package/dist/esm/plugins/json-schema-preset/type-definition/number.mjs +34 -1
- package/dist/esm/plugins/json-schema-preset/type-definition/object.mjs +6 -1
- package/dist/esm/plugins/json-schema-preset/type-definition/string.mjs +30 -1
- package/dist/esm/plugins/json-schema-preset/types.mjs +0 -0
- package/dist/esm/shared/flow-value/utils.mjs +22 -8
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/components/code-editor/editor.d.ts +0 -2
- package/dist/types/components/code-editor/language-features.d.ts +4 -1
- package/dist/types/components/code-editor/theme/dark.d.ts +29 -0
- package/dist/types/components/code-editor/theme/light.d.ts +24 -0
- package/dist/types/components/condition-context/context.d.ts +14 -0
- package/dist/types/components/condition-context/hooks/use-condition.d.ts +29 -0
- package/dist/types/components/condition-context/index.d.ts +8 -0
- package/dist/types/components/condition-context/op.d.ts +22 -0
- package/dist/types/components/condition-context/types.d.ts +14 -0
- package/dist/types/components/condition-row/index.d.ts +4 -7
- package/dist/types/components/condition-row/types.d.ts +0 -24
- package/dist/types/components/db-condition-row/index.d.ts +4 -3
- package/dist/types/components/db-condition-row/types.d.ts +0 -8
- package/dist/types/form-plugins/batch-outputs-plugin/index.d.ts +4 -0
- package/dist/types/form-plugins/infer-inputs-plugin/index.d.ts +4 -0
- package/dist/types/plugins/json-schema-preset/create-type-preset-plugin.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/index.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/react.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/type-definition/array.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/type-definition/boolean.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/type-definition/date-time.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/type-definition/index.d.ts +3 -1
- package/dist/types/plugins/json-schema-preset/type-definition/integer.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/type-definition/map.d.ts +6 -0
- package/dist/types/plugins/json-schema-preset/type-definition/number.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/type-definition/object.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/type-definition/string.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/{manager.d.ts → types.d.ts} +5 -0
- package/dist/types/shared/flow-value/utils.d.ts +3 -1
- package/package.json +9 -8
- package/src/components/code-editor/editor.tsx +7 -10
- package/src/components/code-editor/index.tsx +3 -1
- package/src/components/code-editor/language-features.ts +52 -14
- package/src/components/code-editor/theme/dark.ts +62 -77
- package/src/components/code-editor/theme/light.ts +60 -91
- package/src/components/condition-context/context.tsx +28 -0
- package/src/components/condition-context/hooks/use-condition.tsx +99 -0
- package/src/components/condition-context/index.tsx +14 -0
- package/src/components/condition-context/op.ts +86 -0
- package/src/components/condition-context/types.ts +22 -0
- package/src/components/condition-row/index.tsx +44 -22
- package/src/components/condition-row/types.ts +0 -30
- package/src/components/coze-editor-extensions/extensions/variable-tag.tsx +6 -3
- package/src/components/coze-editor-extensions/extensions/variable-tree.tsx +3 -0
- package/src/components/db-condition-row/index.tsx +76 -24
- package/src/components/db-condition-row/types.ts +0 -13
- package/src/components/variable-selector/index.tsx +0 -2
- package/src/form-plugins/batch-outputs-plugin/index.ts +63 -44
- package/src/form-plugins/infer-inputs-plugin/index.ts +62 -14
- package/src/plugins/json-schema-preset/create-type-preset-plugin.tsx +4 -2
- package/src/plugins/json-schema-preset/index.tsx +1 -1
- package/src/plugins/json-schema-preset/react.tsx +5 -2
- package/src/plugins/json-schema-preset/type-definition/array.tsx +10 -1
- package/src/plugins/json-schema-preset/type-definition/boolean.tsx +17 -1
- package/src/plugins/json-schema-preset/type-definition/date-time.tsx +21 -2
- package/src/plugins/json-schema-preset/type-definition/index.tsx +10 -1
- package/src/plugins/json-schema-preset/type-definition/integer.tsx +19 -1
- package/src/plugins/json-schema-preset/type-definition/map.tsx +31 -0
- package/src/plugins/json-schema-preset/type-definition/number.tsx +19 -1
- package/src/plugins/json-schema-preset/type-definition/object.tsx +6 -1
- package/src/plugins/json-schema-preset/type-definition/string.tsx +19 -1
- package/src/plugins/json-schema-preset/{manager.ts → types.ts} +7 -0
- package/src/shared/flow-value/utils.ts +22 -9
- package/dist/cjs/components/condition-row/constants.js +0 -165
- package/dist/cjs/components/condition-row/hooks/useOp.js +0 -78
- package/dist/cjs/components/condition-row/hooks/useRule.js +0 -68
- package/dist/cjs/components/db-condition-row/hooks/use-left.js +0 -86
- package/dist/cjs/components/db-condition-row/hooks/use-op.js +0 -79
- package/dist/esm/components/code-editor/init-worker.mjs +0 -19
- package/dist/esm/components/condition-row/constants.mjs +0 -128
- package/dist/esm/components/condition-row/hooks/useOp.mjs +0 -44
- package/dist/esm/components/condition-row/hooks/useRule.mjs +0 -34
- package/dist/esm/components/db-condition-row/hooks/use-left.mjs +0 -52
- package/dist/esm/components/db-condition-row/hooks/use-op.mjs +0 -45
- package/dist/types/components/code-editor/init-worker.d.ts +0 -5
- package/dist/types/components/condition-row/constants.d.ts +0 -7
- package/dist/types/components/condition-row/hooks/useOp.d.ts +0 -18
- package/dist/types/components/condition-row/hooks/useRule.d.ts +0 -9
- package/dist/types/components/db-condition-row/hooks/use-left.d.ts +0 -18
- package/dist/types/components/db-condition-row/hooks/use-op.d.ts +0 -18
- package/src/components/code-editor/init-worker.ts +0 -27
- package/src/components/condition-row/constants.ts +0 -134
- package/src/components/condition-row/hooks/useOp.tsx +0 -56
- package/src/components/condition-row/hooks/useRule.ts +0 -35
- package/src/components/db-condition-row/hooks/use-left.tsx +0 -66
- package/src/components/db-condition-row/hooks/use-op.tsx +0 -59
- /package/dist/cjs/{plugins/json-schema-preset/manager.js → components/condition-context/types.js} +0 -0
- /package/dist/esm/{plugins/json-schema-preset/manager.mjs → components/condition-context/types.mjs} +0 -0
|
@@ -5,17 +5,17 @@
|
|
|
5
5
|
|
|
6
6
|
import React, { useMemo } from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { JsonSchemaUtils } from '@flowgram.ai/json-schema';
|
|
9
|
+
import { I18n, useScopeAvailable } from '@flowgram.ai/editor';
|
|
10
|
+
import { Button, Input, Select } from '@douyinfe/semi-ui';
|
|
11
|
+
import { IconChevronDownStroked } from '@douyinfe/semi-icons';
|
|
10
12
|
|
|
11
13
|
import { InjectVariableSelector } from '@/components/variable-selector';
|
|
12
14
|
import { InjectDynamicValueInput } from '@/components/dynamic-value-input';
|
|
15
|
+
import { IConditionRule, ConditionOpConfigs, useCondition } from '@/components/condition-context';
|
|
13
16
|
|
|
14
|
-
import { ConditionRowValueType
|
|
17
|
+
import { ConditionRowValueType } from './types';
|
|
15
18
|
import { UIContainer, UILeft, UIOperator, UIRight, UIValues } from './styles';
|
|
16
|
-
import { useRule } from './hooks/useRule';
|
|
17
|
-
import { useOp } from './hooks/useOp';
|
|
18
|
-
import { defaultOpConfigs, defaultRules } from './constants';
|
|
19
19
|
|
|
20
20
|
interface PropTypes {
|
|
21
21
|
value?: ConditionRowValueType;
|
|
@@ -23,8 +23,8 @@ interface PropTypes {
|
|
|
23
23
|
style?: React.CSSProperties;
|
|
24
24
|
readonly?: boolean;
|
|
25
25
|
ruleConfig?: {
|
|
26
|
-
ops?:
|
|
27
|
-
rules?:
|
|
26
|
+
ops?: ConditionOpConfigs;
|
|
27
|
+
rules?: Record<string, IConditionRule>;
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -41,19 +41,44 @@ export function ConditionRow({
|
|
|
41
41
|
ruleConfig = defaultRuleConfig,
|
|
42
42
|
}: PropTypes) {
|
|
43
43
|
const { left, operator, right } = value || {};
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
|
|
45
|
+
const available = useScopeAvailable();
|
|
46
|
+
|
|
47
|
+
const variable = useMemo(() => {
|
|
48
|
+
if (!left) return undefined;
|
|
49
|
+
return available.getByKeyPath(left.content);
|
|
50
|
+
}, [available, left]);
|
|
51
|
+
|
|
52
|
+
const leftSchema = useMemo(() => {
|
|
53
|
+
if (!variable) return undefined;
|
|
54
|
+
return JsonSchemaUtils.astToSchema(variable.type, { drilldown: false });
|
|
55
|
+
}, [variable?.type?.hash]);
|
|
56
|
+
|
|
57
|
+
const { rule, opConfig, opOptionList, targetSchema } = useCondition({
|
|
58
|
+
leftSchema,
|
|
59
|
+
operator,
|
|
51
60
|
});
|
|
52
61
|
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
const renderOpSelect = () => (
|
|
63
|
+
<Select
|
|
64
|
+
style={{ height: 22 }}
|
|
65
|
+
disabled={readonly}
|
|
66
|
+
size="small"
|
|
67
|
+
value={operator}
|
|
68
|
+
optionList={opOptionList}
|
|
69
|
+
onChange={(v) => {
|
|
70
|
+
onChange({
|
|
71
|
+
...value,
|
|
72
|
+
operator: v as string,
|
|
73
|
+
});
|
|
74
|
+
}}
|
|
75
|
+
triggerRender={({ value }) => (
|
|
76
|
+
<Button size="small" disabled={!rule}>
|
|
77
|
+
{opConfig?.abbreviation || <IconChevronDownStroked size="small" />}
|
|
78
|
+
</Button>
|
|
79
|
+
)}
|
|
80
|
+
/>
|
|
81
|
+
);
|
|
57
82
|
|
|
58
83
|
return (
|
|
59
84
|
<UIContainer style={style}>
|
|
@@ -97,7 +122,4 @@ export function ConditionRow({
|
|
|
97
122
|
);
|
|
98
123
|
}
|
|
99
124
|
|
|
100
|
-
ConditionRow.defaultRules = defaultRules;
|
|
101
|
-
ConditionRow.defaultOpConfigs = defaultOpConfigs;
|
|
102
|
-
|
|
103
125
|
export { type ConditionRowValueType };
|
|
@@ -5,36 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
import { IFlowConstantRefValue, IFlowRefValue } from '@/shared';
|
|
7
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<string, OpConfig>;
|
|
33
|
-
|
|
34
|
-
export type IRule = Partial<Record<string, string | null>>;
|
|
35
|
-
|
|
36
|
-
export type IRules = Record<string, IRule>;
|
|
37
|
-
|
|
38
8
|
export interface ConditionRowValueType {
|
|
39
9
|
left?: IFlowRefValue;
|
|
40
10
|
operator?: string;
|
|
@@ -63,10 +63,13 @@ class VariableTagWidget extends WidgetType {
|
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
const rootField = last(v.parentFields);
|
|
66
|
+
const rootField = last(v.parentFields) || v;
|
|
67
|
+
const isRoot = v === rootField;
|
|
67
68
|
|
|
68
69
|
const rootTitle = (
|
|
69
|
-
<UIRootTitle>
|
|
70
|
+
<UIRootTitle>
|
|
71
|
+
{rootField.meta?.title ? `${rootField.meta.title} ${isRoot ? '' : '-'} ` : ''}
|
|
72
|
+
</UIRootTitle>
|
|
70
73
|
);
|
|
71
74
|
const rootIcon = this.renderIcon(rootField?.meta.icon);
|
|
72
75
|
|
|
@@ -82,7 +85,7 @@ class VariableTagWidget extends WidgetType {
|
|
|
82
85
|
>
|
|
83
86
|
<UITag prefixIcon={rootIcon}>
|
|
84
87
|
{rootTitle}
|
|
85
|
-
<UIVarName>{v?.key}</UIVarName>
|
|
88
|
+
{!isRoot && <UIVarName>{v?.key}</UIVarName>}
|
|
86
89
|
</UITag>
|
|
87
90
|
</Popover>
|
|
88
91
|
);
|
|
@@ -6,14 +6,27 @@
|
|
|
6
6
|
import React, { useMemo } from 'react';
|
|
7
7
|
|
|
8
8
|
import { I18n } from '@flowgram.ai/editor';
|
|
9
|
-
import { Input } from '@douyinfe/semi-ui';
|
|
9
|
+
import { Button, Icon, Input, Select } from '@douyinfe/semi-ui';
|
|
10
|
+
import { IconChevronDownStroked } from '@douyinfe/semi-icons';
|
|
10
11
|
|
|
12
|
+
import { useTypeManager } from '@/plugins';
|
|
11
13
|
import { InjectDynamicValueInput } from '@/components/dynamic-value-input';
|
|
14
|
+
import {
|
|
15
|
+
useCondition,
|
|
16
|
+
type ConditionOpConfigs,
|
|
17
|
+
type IConditionRule,
|
|
18
|
+
} from '@/components/condition-context';
|
|
12
19
|
|
|
13
|
-
import { DBConditionOptionType, DBConditionRowValueType
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
import { DBConditionOptionType, DBConditionRowValueType } from './types';
|
|
21
|
+
import {
|
|
22
|
+
UIContainer,
|
|
23
|
+
UILeft,
|
|
24
|
+
UIOperator,
|
|
25
|
+
UIOptionLabel,
|
|
26
|
+
UIRight,
|
|
27
|
+
UISelect,
|
|
28
|
+
UIValues,
|
|
29
|
+
} from './styles';
|
|
17
30
|
|
|
18
31
|
interface PropTypes {
|
|
19
32
|
value?: DBConditionRowValueType;
|
|
@@ -22,8 +35,8 @@ interface PropTypes {
|
|
|
22
35
|
options?: DBConditionOptionType[];
|
|
23
36
|
readonly?: boolean;
|
|
24
37
|
ruleConfig?: {
|
|
25
|
-
ops?:
|
|
26
|
-
rules?:
|
|
38
|
+
ops?: ConditionOpConfigs;
|
|
39
|
+
rules?: Record<string, IConditionRule>;
|
|
27
40
|
};
|
|
28
41
|
}
|
|
29
42
|
|
|
@@ -42,26 +55,65 @@ export function DBConditionRow({
|
|
|
42
55
|
}: PropTypes) {
|
|
43
56
|
const { left, operator, right } = value || {};
|
|
44
57
|
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
58
|
+
const typeManager = useTypeManager();
|
|
59
|
+
|
|
60
|
+
const leftSchema = useMemo(
|
|
61
|
+
() => options?.find((item) => item.value === left)?.schema,
|
|
62
|
+
[left, options]
|
|
63
|
+
);
|
|
52
64
|
|
|
53
|
-
const {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
readonly,
|
|
58
|
-
userOps: ruleConfig.ops,
|
|
65
|
+
const { opConfig, rule, opOptionList, targetSchema } = useCondition({
|
|
66
|
+
leftSchema,
|
|
67
|
+
operator,
|
|
68
|
+
ruleConfig,
|
|
59
69
|
});
|
|
60
70
|
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
71
|
+
const renderDBOptionSelect = () => (
|
|
72
|
+
<UISelect
|
|
73
|
+
disabled={readonly}
|
|
74
|
+
size="small"
|
|
75
|
+
style={{ width: '100%' }}
|
|
76
|
+
value={left}
|
|
77
|
+
onChange={(v) =>
|
|
78
|
+
onChange({
|
|
79
|
+
...value,
|
|
80
|
+
left: v as string,
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
optionList={
|
|
84
|
+
options?.map((item) => ({
|
|
85
|
+
label: (
|
|
86
|
+
<UIOptionLabel>
|
|
87
|
+
<Icon size="small" svg={typeManager.getDisplayIcon(item.schema)} />
|
|
88
|
+
{item.label}
|
|
89
|
+
</UIOptionLabel>
|
|
90
|
+
),
|
|
91
|
+
value: item.value,
|
|
92
|
+
})) || []
|
|
93
|
+
}
|
|
94
|
+
/>
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const renderOpSelect = () => (
|
|
98
|
+
<Select
|
|
99
|
+
style={{ height: 22 }}
|
|
100
|
+
disabled={readonly}
|
|
101
|
+
size="small"
|
|
102
|
+
value={operator}
|
|
103
|
+
optionList={opOptionList}
|
|
104
|
+
onChange={(v) => {
|
|
105
|
+
onChange({
|
|
106
|
+
...value,
|
|
107
|
+
operator: v as string,
|
|
108
|
+
});
|
|
109
|
+
}}
|
|
110
|
+
triggerRender={({ value }) => (
|
|
111
|
+
<Button size="small" disabled={!rule}>
|
|
112
|
+
{opConfig?.abbreviation || <IconChevronDownStroked size="small" />}
|
|
113
|
+
</Button>
|
|
114
|
+
)}
|
|
115
|
+
/>
|
|
116
|
+
);
|
|
65
117
|
|
|
66
118
|
return (
|
|
67
119
|
<UIContainer style={style}>
|
|
@@ -7,19 +7,6 @@ import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
|
7
7
|
|
|
8
8
|
import { IFlowConstantRefValue } from '@/shared';
|
|
9
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
10
|
export interface DBConditionRowValueType {
|
|
24
11
|
left?: string;
|
|
25
12
|
schema?: IJsonSchema;
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { set } from 'lodash-es';
|
|
7
|
+
import { JsonSchemaUtils } from '@flowgram.ai/json-schema';
|
|
6
8
|
import {
|
|
7
9
|
ASTFactory,
|
|
8
10
|
createEffectFromVariableProvider,
|
|
@@ -46,59 +48,76 @@ export const provideBatchOutputsEffect: EffectOptions[] = createEffectFromVariab
|
|
|
46
48
|
/**
|
|
47
49
|
* Free Layout only right now
|
|
48
50
|
*/
|
|
49
|
-
export const createBatchOutputsFormPlugin: FormPluginCreator<{
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
export const createBatchOutputsFormPlugin: FormPluginCreator<{
|
|
52
|
+
outputKey: string;
|
|
53
|
+
/**
|
|
54
|
+
* if set, infer json schema to inferTargetKey when submit
|
|
55
|
+
*/
|
|
56
|
+
inferTargetKey?: string;
|
|
57
|
+
}> = defineFormPluginCreator({
|
|
58
|
+
name: 'batch-outputs-plugin',
|
|
59
|
+
onSetupFormMeta({ mergeEffect, addFormatOnSubmit }, { outputKey, inferTargetKey }) {
|
|
60
|
+
mergeEffect({
|
|
61
|
+
[outputKey]: provideBatchOutputsEffect,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (inferTargetKey) {
|
|
65
|
+
addFormatOnSubmit((formData, ctx) => {
|
|
66
|
+
const outputVariable = getNodeScope(ctx.node).output.variables?.[0];
|
|
67
|
+
|
|
68
|
+
if (outputVariable?.type) {
|
|
69
|
+
set(formData, inferTargetKey, JsonSchemaUtils.astToSchema(outputVariable?.type));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return formData;
|
|
55
73
|
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
onInit(ctx, { outputKey }) {
|
|
77
|
+
const chainTransformService = ctx.node.getService(ScopeChainTransformService);
|
|
59
78
|
|
|
60
|
-
|
|
79
|
+
const batchNodeType = ctx.node.flowNodeType;
|
|
61
80
|
|
|
62
|
-
|
|
81
|
+
const transformerId = `${batchNodeType}-outputs`;
|
|
63
82
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
83
|
+
if (chainTransformService.hasTransformer(transformerId)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
67
86
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
87
|
+
chainTransformService.registerTransformer(transformerId, {
|
|
88
|
+
transformCovers: (covers, ctx) => {
|
|
89
|
+
const node = ctx.scope.meta?.node;
|
|
71
90
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
91
|
+
// Child Node's variable can cover parent
|
|
92
|
+
if (node?.parent?.flowNodeType === batchNodeType) {
|
|
93
|
+
return [...covers, getNodeScope(node.parent)];
|
|
94
|
+
}
|
|
76
95
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
96
|
+
return covers;
|
|
97
|
+
},
|
|
98
|
+
transformDeps(scopes, ctx) {
|
|
99
|
+
const scopeMeta = ctx.scope.meta;
|
|
81
100
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
101
|
+
if (scopeMeta?.type === FlowNodeScopeType.private) {
|
|
102
|
+
return scopes;
|
|
103
|
+
}
|
|
85
104
|
|
|
86
|
-
|
|
105
|
+
const node = scopeMeta?.node;
|
|
87
106
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
107
|
+
// Public of Loop Node depends on child Node
|
|
108
|
+
if (node?.flowNodeType === batchNodeType) {
|
|
109
|
+
// Get all child blocks
|
|
110
|
+
const childBlocks = node.blocks;
|
|
92
111
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
112
|
+
// public scope of all child blocks
|
|
113
|
+
return [
|
|
114
|
+
getNodePrivateScope(node),
|
|
115
|
+
...childBlocks.map((_childBlock) => getNodeScope(_childBlock)),
|
|
116
|
+
];
|
|
117
|
+
}
|
|
99
118
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
119
|
+
return scopes;
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
});
|
|
@@ -3,34 +3,82 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { get, set } from 'lodash-es';
|
|
6
|
+
import { get, omit, set } from 'lodash-es';
|
|
7
|
+
import { Immer } from 'immer';
|
|
7
8
|
import { defineFormPluginCreator, getNodePrivateScope, getNodeScope } from '@flowgram.ai/editor';
|
|
8
9
|
|
|
9
10
|
import { FlowValueUtils } from '@/shared';
|
|
10
11
|
|
|
12
|
+
const { produce } = new Immer({ autoFreeze: false });
|
|
13
|
+
|
|
11
14
|
interface InputConfig {
|
|
12
15
|
sourceKey: string;
|
|
13
16
|
targetKey: string;
|
|
14
17
|
scope?: 'private' | 'public';
|
|
18
|
+
/**
|
|
19
|
+
* For backend runtime, constant schema is redundant, so we can choose to ignore it
|
|
20
|
+
*/
|
|
21
|
+
ignoreConstantSchema?: boolean;
|
|
15
22
|
}
|
|
16
23
|
|
|
17
24
|
export const createInferInputsPlugin = defineFormPluginCreator<InputConfig>({
|
|
18
|
-
onSetupFormMeta(
|
|
25
|
+
onSetupFormMeta(
|
|
26
|
+
{ addFormatOnSubmit, addFormatOnInit },
|
|
27
|
+
{ sourceKey, targetKey, scope, ignoreConstantSchema }
|
|
28
|
+
) {
|
|
19
29
|
if (!sourceKey || !targetKey) {
|
|
20
30
|
return;
|
|
21
31
|
}
|
|
22
32
|
|
|
23
|
-
addFormatOnSubmit((formData, ctx) =>
|
|
24
|
-
|
|
25
|
-
formData,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
addFormatOnSubmit((formData, ctx) =>
|
|
34
|
+
produce(formData, (draft: any) => {
|
|
35
|
+
const sourceData = get(formData, sourceKey);
|
|
36
|
+
|
|
37
|
+
set(
|
|
38
|
+
draft,
|
|
39
|
+
targetKey,
|
|
40
|
+
FlowValueUtils.inferJsonSchema(
|
|
41
|
+
sourceData,
|
|
42
|
+
scope === 'private' ? getNodePrivateScope(ctx.node) : getNodeScope(ctx.node)
|
|
43
|
+
)
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
if (ignoreConstantSchema) {
|
|
47
|
+
for (const { value, path } of FlowValueUtils.traverse(sourceData, {
|
|
48
|
+
includeTypes: ['constant'],
|
|
49
|
+
})) {
|
|
50
|
+
if (FlowValueUtils.isConstant(value) && value?.schema) {
|
|
51
|
+
set(formData, `${sourceKey}.${path}`, omit(value, ['schema']));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
if (ignoreConstantSchema) {
|
|
59
|
+
// Revert Schema in frontend
|
|
60
|
+
addFormatOnInit((formData, ctx) => {
|
|
61
|
+
const targetSchema = get(formData, targetKey);
|
|
62
|
+
|
|
63
|
+
if (!targetSchema) {
|
|
64
|
+
return formData;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// For backend data, it's not necessary to use immer
|
|
68
|
+
for (const { value, pathArr } of FlowValueUtils.traverse(get(formData, sourceKey), {
|
|
69
|
+
includeTypes: ['constant'],
|
|
70
|
+
})) {
|
|
71
|
+
if (FlowValueUtils.isConstant(value) && !value?.schema) {
|
|
72
|
+
const schemaPath = pathArr.map((_item) => `properties.${_item}`).join('.');
|
|
73
|
+
const schema = get(targetSchema, schemaPath);
|
|
74
|
+
if (schema) {
|
|
75
|
+
set(value, 'schema', schema);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return formData;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
35
83
|
},
|
|
36
84
|
});
|
|
@@ -10,8 +10,10 @@ import {
|
|
|
10
10
|
} from '@flowgram.ai/json-schema';
|
|
11
11
|
import { definePluginCreator } from '@flowgram.ai/editor';
|
|
12
12
|
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
13
|
+
import { JsonSchemaTypeRegistry } from './types';
|
|
14
|
+
import { initRegistries, jsonSchemaTypePreset } from './type-definition';
|
|
15
|
+
|
|
16
|
+
initRegistries();
|
|
15
17
|
|
|
16
18
|
export const createTypePresetPlugin = definePluginCreator<{
|
|
17
19
|
types?: Partial<JsonSchemaTypeRegistry> & Pick<JsonSchemaTypeRegistry, 'type'>[];
|
|
@@ -9,8 +9,8 @@ import {
|
|
|
9
9
|
type IJsonSchema,
|
|
10
10
|
} from '@flowgram.ai/json-schema';
|
|
11
11
|
|
|
12
|
+
import { type ConstantRendererProps, type JsonSchemaTypeRegistry } from './types';
|
|
12
13
|
import { useTypeManager, JsonSchemaTypePresetProvider } from './react';
|
|
13
|
-
import { ConstantRendererProps, type JsonSchemaTypeRegistry } from './manager';
|
|
14
14
|
import { createTypePresetPlugin } from './create-type-preset-plugin';
|
|
15
15
|
|
|
16
16
|
export {
|
|
@@ -12,8 +12,11 @@ import {
|
|
|
12
12
|
JsonSchemaTypeManager,
|
|
13
13
|
} from '@flowgram.ai/json-schema';
|
|
14
14
|
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
15
|
+
import { type JsonSchemaTypeRegistry } from './types';
|
|
16
|
+
import { initRegistries, jsonSchemaTypePreset } from './type-definition';
|
|
17
|
+
|
|
18
|
+
// If you want to use new type Manager, init registries
|
|
19
|
+
initRegistries();
|
|
17
20
|
|
|
18
21
|
export const useTypeManager = () =>
|
|
19
22
|
useOriginTypeManager() as JsonSchemaTypeManager<IJsonSchema, JsonSchemaTypeRegistry>;
|
|
@@ -8,9 +8,10 @@ import React from 'react';
|
|
|
8
8
|
|
|
9
9
|
import { I18n } from '@flowgram.ai/editor';
|
|
10
10
|
|
|
11
|
+
import { ConditionPresetOp } from '@/components/condition-context/op';
|
|
11
12
|
import { CodeEditorMini } from '@/components/code-editor-mini';
|
|
12
13
|
|
|
13
|
-
import { type JsonSchemaTypeRegistry } from '../
|
|
14
|
+
import { type JsonSchemaTypeRegistry } from '../types';
|
|
14
15
|
|
|
15
16
|
export const arrayRegistry: Partial<JsonSchemaTypeRegistry> = {
|
|
16
17
|
type: 'array',
|
|
@@ -23,4 +24,12 @@ export const arrayRegistry: Partial<JsonSchemaTypeRegistry> = {
|
|
|
23
24
|
readonly={props.readonly}
|
|
24
25
|
/>
|
|
25
26
|
),
|
|
27
|
+
conditionRule: {
|
|
28
|
+
[ConditionPresetOp.IS_EMPTY]: null,
|
|
29
|
+
[ConditionPresetOp.IS_NOT_EMPTY]: null,
|
|
30
|
+
[ConditionPresetOp.CONTAINS]: { type: 'array', extra: { weak: true } },
|
|
31
|
+
[ConditionPresetOp.NOT_CONTAINS]: { type: 'array', extra: { weak: true } },
|
|
32
|
+
[ConditionPresetOp.EQ]: { type: 'array', extra: { weak: true } },
|
|
33
|
+
[ConditionPresetOp.NEQ]: { type: 'array', extra: { weak: true } },
|
|
34
|
+
},
|
|
26
35
|
};
|
|
@@ -9,7 +9,9 @@ import React from 'react';
|
|
|
9
9
|
import { I18n } from '@flowgram.ai/editor';
|
|
10
10
|
import { Select } from '@douyinfe/semi-ui';
|
|
11
11
|
|
|
12
|
-
import {
|
|
12
|
+
import { ConditionPresetOp } from '@/components/condition-context/op';
|
|
13
|
+
|
|
14
|
+
import { type JsonSchemaTypeRegistry } from '../types';
|
|
13
15
|
|
|
14
16
|
export const booleanRegistry: Partial<JsonSchemaTypeRegistry> = {
|
|
15
17
|
type: 'boolean',
|
|
@@ -30,4 +32,18 @@ export const booleanRegistry: Partial<JsonSchemaTypeRegistry> = {
|
|
|
30
32
|
/>
|
|
31
33
|
);
|
|
32
34
|
},
|
|
35
|
+
conditionRule: {
|
|
36
|
+
[ConditionPresetOp.EQ]: { type: 'boolean' },
|
|
37
|
+
[ConditionPresetOp.NEQ]: { type: 'boolean' },
|
|
38
|
+
[ConditionPresetOp.IS_TRUE]: null,
|
|
39
|
+
[ConditionPresetOp.IS_FALSE]: null,
|
|
40
|
+
[ConditionPresetOp.IN]: {
|
|
41
|
+
type: 'array',
|
|
42
|
+
items: { type: 'boolean' },
|
|
43
|
+
},
|
|
44
|
+
[ConditionPresetOp.NIN]: {
|
|
45
|
+
type: 'array',
|
|
46
|
+
items: { type: 'boolean' },
|
|
47
|
+
},
|
|
48
|
+
},
|
|
33
49
|
};
|