@flowgram.ai/form-materials 0.1.0-alpha.12 → 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.
Files changed (164) hide show
  1. package/bin/index.ts +4 -29
  2. package/bin/materials.ts +56 -87
  3. package/bin/project.ts +4 -0
  4. package/bin/utils/import.ts +127 -0
  5. package/bin/utils/traverse-file.ts +60 -0
  6. package/dist/esm/chunk-727SU246.js +13 -0
  7. package/dist/esm/chunk-727SU246.js.map +1 -0
  8. package/dist/esm/chunk-DEZUEMUM.js +284 -0
  9. package/dist/esm/chunk-DEZUEMUM.js.map +1 -0
  10. package/dist/esm/chunk-DUOXDOUE.js +477 -0
  11. package/dist/esm/chunk-DUOXDOUE.js.map +1 -0
  12. package/dist/esm/editor-6UMULJYB.js +180 -0
  13. package/dist/esm/editor-6UMULJYB.js.map +1 -0
  14. package/dist/esm/editor-EYOQTGMT.js +282 -0
  15. package/dist/esm/editor-EYOQTGMT.js.map +1 -0
  16. package/dist/esm/editor-OXPGKPF5.js +167 -0
  17. package/dist/esm/editor-OXPGKPF5.js.map +1 -0
  18. package/dist/esm/editor-VO6YAXRC.js +249 -0
  19. package/dist/esm/editor-VO6YAXRC.js.map +1 -0
  20. package/dist/esm/editor-XYLKTB6L.js +365 -0
  21. package/dist/esm/editor-XYLKTB6L.js.map +1 -0
  22. package/dist/esm/index.js +1186 -2456
  23. package/dist/esm/index.js.map +1 -1
  24. package/dist/index.d.mts +363 -70
  25. package/dist/index.d.ts +363 -70
  26. package/dist/index.js +4064 -2887
  27. package/dist/index.js.map +1 -1
  28. package/package.json +9 -8
  29. package/src/components/assign-row/index.tsx +4 -4
  30. package/src/components/assign-rows/index.tsx +1 -1
  31. package/src/components/batch-outputs/index.tsx +7 -5
  32. package/src/components/batch-outputs/types.ts +1 -1
  33. package/src/components/batch-variable-selector/index.tsx +1 -1
  34. package/src/components/code-editor/editor.tsx +89 -0
  35. package/src/components/code-editor/index.tsx +5 -89
  36. package/src/components/code-editor/language-features.ts +18 -18
  37. package/src/components/code-editor/theme/dark.ts +49 -30
  38. package/src/components/code-editor/theme/light.ts +56 -32
  39. package/src/components/code-editor-mini/index.tsx +2 -2
  40. package/src/components/condition-row/constants.ts +10 -2
  41. package/src/components/condition-row/hooks/useOp.tsx +13 -9
  42. package/src/components/condition-row/hooks/useRule.ts +8 -4
  43. package/src/components/condition-row/index.tsx +31 -10
  44. package/src/components/condition-row/types.ts +5 -7
  45. package/src/components/constant-input/index.tsx +5 -2
  46. package/src/components/constant-input/types.ts +1 -1
  47. package/src/components/db-condition-row/hooks/use-left.tsx +66 -0
  48. package/src/components/db-condition-row/hooks/use-op.tsx +59 -0
  49. package/src/components/db-condition-row/index.tsx +93 -0
  50. package/src/components/db-condition-row/styles.tsx +43 -0
  51. package/src/components/db-condition-row/types.ts +34 -0
  52. package/src/components/display-flow-value/index.tsx +4 -14
  53. package/src/components/display-inputs-values/index.tsx +46 -7
  54. package/src/components/display-outputs/index.tsx +2 -1
  55. package/src/components/display-schema-tag/index.tsx +3 -2
  56. package/src/components/display-schema-tree/index.tsx +2 -1
  57. package/src/components/dynamic-value-input/hooks.ts +25 -4
  58. package/src/components/dynamic-value-input/index.tsx +33 -20
  59. package/src/components/dynamic-value-input/styles.tsx +14 -4
  60. package/src/components/index.ts +3 -0
  61. package/src/components/inputs-values/index.tsx +21 -8
  62. package/src/components/inputs-values/styles.tsx +1 -1
  63. package/src/components/inputs-values/types.ts +3 -3
  64. package/src/components/inputs-values-tree/hooks/use-child-list.tsx +76 -0
  65. package/src/components/inputs-values-tree/index.tsx +62 -0
  66. package/src/components/inputs-values-tree/row.tsx +177 -0
  67. package/src/components/inputs-values-tree/styles.tsx +128 -0
  68. package/src/components/inputs-values-tree/types.ts +21 -0
  69. package/src/components/json-editor-with-variables/editor.tsx +69 -0
  70. package/src/components/json-editor-with-variables/extensions/variable-tag.tsx +6 -5
  71. package/src/components/json-editor-with-variables/extensions/variable-tree.tsx +1 -1
  72. package/src/components/json-editor-with-variables/index.tsx +5 -58
  73. package/src/components/json-schema-editor/default-value.tsx +12 -108
  74. package/src/components/json-schema-editor/hooks.tsx +63 -93
  75. package/src/components/json-schema-editor/index.tsx +36 -70
  76. package/src/components/json-schema-editor/styles.tsx +12 -84
  77. package/src/components/json-schema-editor/types.ts +0 -1
  78. package/src/components/prompt-editor/editor.tsx +81 -0
  79. package/src/components/prompt-editor/index.tsx +5 -62
  80. package/src/components/prompt-editor/types.tsx +1 -1
  81. package/src/components/prompt-editor-with-inputs/editor.tsx +25 -0
  82. package/src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx +13 -1
  83. package/src/components/prompt-editor-with-inputs/index.tsx +5 -15
  84. package/src/components/prompt-editor-with-inputs/inputs-picker.tsx +34 -17
  85. package/src/components/prompt-editor-with-variables/editor.tsx +22 -0
  86. package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +12 -20
  87. package/src/components/prompt-editor-with-variables/extensions/variable-tree.tsx +14 -2
  88. package/src/components/prompt-editor-with-variables/index.tsx +5 -12
  89. package/src/components/type-selector/index.tsx +21 -9
  90. package/src/components/variable-selector/context.tsx +28 -0
  91. package/src/components/variable-selector/index.tsx +19 -6
  92. package/src/components/variable-selector/use-variable-tree.tsx +4 -4
  93. package/src/effects/auto-rename-ref/index.ts +8 -55
  94. package/src/effects/listen-ref-schema-change/index.ts +1 -1
  95. package/src/effects/listen-ref-value-change/index.ts +1 -1
  96. package/src/effects/provide-batch-input/index.ts +1 -1
  97. package/src/effects/validate-when-variable-sync/index.ts +1 -1
  98. package/src/form-plugins/batch-outputs-plugin/index.ts +1 -1
  99. package/src/form-plugins/infer-assign-plugin/index.ts +2 -2
  100. package/src/form-plugins/infer-inputs-plugin/index.ts +4 -76
  101. package/src/hooks/use-object-list/index.tsx +35 -7
  102. package/src/index.ts +1 -0
  103. package/src/plugins/json-schema-preset/manager.ts +1 -0
  104. package/src/plugins/json-schema-preset/type-definition/array.tsx +3 -1
  105. package/src/plugins/json-schema-preset/type-definition/boolean.tsx +4 -3
  106. package/src/plugins/json-schema-preset/type-definition/date-time.tsx +25 -0
  107. package/src/plugins/json-schema-preset/type-definition/index.tsx +2 -0
  108. package/src/plugins/json-schema-preset/type-definition/integer.tsx +2 -1
  109. package/src/plugins/json-schema-preset/type-definition/number.tsx +2 -1
  110. package/src/plugins/json-schema-preset/type-definition/object.tsx +3 -1
  111. package/src/plugins/json-schema-preset/type-definition/string.tsx +19 -4
  112. package/src/shared/flow-value/index.ts +6 -0
  113. package/src/shared/flow-value/schema.ts +38 -0
  114. package/src/shared/flow-value/utils.ts +201 -0
  115. package/src/shared/format-legacy-refs/index.ts +1 -1
  116. package/src/shared/index.ts +4 -0
  117. package/src/shared/inject-material/README.md +170 -0
  118. package/src/shared/inject-material/README.zh.md +174 -0
  119. package/src/shared/inject-material/index.tsx +87 -0
  120. package/src/shared/lazy-suspense/index.tsx +28 -0
  121. package/src/shared/polyfill-create-root/index.tsx +33 -0
  122. package/src/typings/flow-value/index.ts +3 -1
  123. package/src/validate/validate-flow-value/index.tsx +4 -16
  124. package/src/components/assign-row/config.json +0 -11
  125. package/src/components/assign-rows/config.json +0 -11
  126. package/src/components/batch-outputs/config.json +0 -13
  127. package/src/components/batch-variable-selector/config.json +0 -9
  128. package/src/components/code-editor/config.json +0 -10
  129. package/src/components/code-editor-mini/config.json +0 -7
  130. package/src/components/condition-row/config.json +0 -13
  131. package/src/components/constant-input/config.json +0 -9
  132. package/src/components/display-flow-value/config.json +0 -8
  133. package/src/components/display-inputs-values/config.json +0 -9
  134. package/src/components/display-outputs/config.json +0 -10
  135. package/src/components/display-schema-tag/config.json +0 -10
  136. package/src/components/display-schema-tree/config.json +0 -11
  137. package/src/components/dynamic-value-input/config.json +0 -14
  138. package/src/components/inputs-values/config.json +0 -13
  139. package/src/components/json-editor-with-variables/config.json +0 -13
  140. package/src/components/json-schema-editor/components/blur-input.tsx +0 -27
  141. package/src/components/json-schema-editor/config.json +0 -13
  142. package/src/components/json-schema-editor/utils.ts +0 -29
  143. package/src/components/prompt-editor/config.json +0 -9
  144. package/src/components/prompt-editor-with-inputs/config.json +0 -13
  145. package/src/components/prompt-editor-with-variables/config.json +0 -13
  146. package/src/components/type-selector/config.json +0 -9
  147. package/src/components/variable-selector/config.json +0 -9
  148. package/src/effects/auto-rename-ref/config.json +0 -5
  149. package/src/effects/listen-ref-schema-change/config.json +0 -10
  150. package/src/effects/listen-ref-value-change/config.json +0 -9
  151. package/src/effects/provide-batch-input/config.json +0 -5
  152. package/src/effects/provide-json-schema-outputs/config.json +0 -7
  153. package/src/effects/sync-variable-title/config.json +0 -5
  154. package/src/effects/validate-when-variable-sync/config.json +0 -5
  155. package/src/form-plugins/batch-outputs-plugin/config.json +0 -7
  156. package/src/form-plugins/infer-assign-plugin/config.json +0 -7
  157. package/src/form-plugins/infer-inputs-plugin/config.json +0 -9
  158. package/src/hooks/use-object-list/config.json +0 -8
  159. package/src/plugins/disable-declaration-plugin/config.json +0 -5
  160. package/src/plugins/json-schema-preset/config.json +0 -9
  161. package/src/shared/format-legacy-refs/config.json +0 -5
  162. package/src/typings/flow-value/config.json +0 -7
  163. package/src/validate/validate-flow-value/config.json +0 -7
  164. /package/src/components/{inputs-values/components/blur-input.tsx → blur-input/index.tsx} +0 -0
@@ -5,7 +5,7 @@
5
5
 
6
6
  import { IRules, Op, OpConfigs } from './types';
7
7
 
8
- export const rules: IRules = {
8
+ export const defaultRules: IRules = {
9
9
  string: {
10
10
  [Op.EQ]: 'string',
11
11
  [Op.NEQ]: 'string',
@@ -60,9 +60,17 @@ export const rules: IRules = {
60
60
  [Op.IS_EMPTY]: null,
61
61
  [Op.IS_NOT_EMPTY]: null,
62
62
  },
63
+ ['date-time']: {
64
+ [Op.EQ]: 'date-time',
65
+ [Op.NEQ]: 'date-time',
66
+ [Op.GT]: 'date-time',
67
+ [Op.GTE]: 'date-time',
68
+ [Op.LT]: 'date-time',
69
+ [Op.LTE]: 'date-time',
70
+ },
63
71
  };
64
72
 
65
- export const opConfigs: OpConfigs = {
73
+ export const defaultOpConfigs: OpConfigs = {
66
74
  [Op.EQ]: {
67
75
  label: 'Equal',
68
76
  abbreviation: '=',
@@ -5,30 +5,34 @@
5
5
 
6
6
  import React, { useMemo } from 'react';
7
7
 
8
+ import { I18n } from '@flowgram.ai/editor';
8
9
  import { Button, Select } from '@douyinfe/semi-ui';
9
10
  import { IconChevronDownStroked } from '@douyinfe/semi-icons';
10
11
 
11
- import { IRule, Op } from '../types';
12
- import { opConfigs } from '../constants';
12
+ import { IRule, OpConfigs } from '../types';
13
+ import { defaultOpConfigs } from '../constants';
13
14
 
14
15
  interface HookParams {
15
16
  rule?: IRule;
16
- op?: Op;
17
- onChange: (op: Op) => void;
17
+ op?: string;
18
+ onChange: (op: string) => void;
18
19
  readonly?: boolean;
20
+ userOps?: OpConfigs;
19
21
  }
20
22
 
21
- export function useOp({ rule, op, onChange, readonly }: HookParams) {
23
+ export function useOp({ rule, op, onChange, readonly, userOps }: HookParams) {
22
24
  const options = useMemo(
23
25
  () =>
24
26
  Object.keys(rule || {}).map((_op) => ({
25
- ...(opConfigs[_op as Op] || {}),
27
+ ...(defaultOpConfigs[_op] || {}),
28
+ ...(userOps?.[_op] || {}),
26
29
  value: _op,
30
+ label: I18n.t(userOps?.[_op]?.label || defaultOpConfigs[_op]?.label),
27
31
  })),
28
- [rule]
32
+ [rule, userOps]
29
33
  );
30
34
 
31
- const opConfig = useMemo(() => opConfigs[op as Op], [op]);
35
+ const opConfig = useMemo(() => defaultOpConfigs[op as string], [op]);
32
36
 
33
37
  const renderOpSelect = () => (
34
38
  <Select
@@ -38,7 +42,7 @@ export function useOp({ rule, op, onChange, readonly }: HookParams) {
38
42
  value={op}
39
43
  optionList={options}
40
44
  onChange={(v) => {
41
- onChange(v as Op);
45
+ onChange(v as string);
42
46
  }}
43
47
  triggerRender={({ value }) => (
44
48
  <Button size="small" disabled={!rule}>
@@ -8,12 +8,16 @@ import { useMemo } from 'react';
8
8
  import { JsonSchemaUtils, JsonSchemaBasicType } from '@flowgram.ai/json-schema';
9
9
  import { useScopeAvailable } from '@flowgram.ai/editor';
10
10
 
11
- import { rules } from '../constants';
12
- import { IFlowRefValue } from '../../../typings';
11
+ import { IFlowRefValue } from '@/typings';
13
12
 
14
- export function useRule(left?: IFlowRefValue) {
13
+ import { IRules } from '../types';
14
+ import { defaultRules } from '../constants';
15
+
16
+ export function useRule(left?: IFlowRefValue, userRules?: IRules) {
15
17
  const available = useScopeAvailable();
16
18
 
19
+ const rules = useMemo(() => ({ ...defaultRules, ...(userRules || {}) }), [userRules]);
20
+
17
21
  const variable = useMemo(() => {
18
22
  if (!left) return undefined;
19
23
  return available.getByKeyPath(left.content);
@@ -25,7 +29,7 @@ export function useRule(left?: IFlowRefValue) {
25
29
  const schema = JsonSchemaUtils.astToSchema(variable.type, { drilldown: false });
26
30
 
27
31
  return rules[schema?.type as JsonSchemaBasicType];
28
- }, [variable?.type]);
32
+ }, [variable?.type, rules]);
29
33
 
30
34
  return { rule };
31
35
  }
@@ -5,35 +5,53 @@
5
5
 
6
6
  import React, { useMemo } from 'react';
7
7
 
8
- import { JsonSchemaBasicType } from '@flowgram.ai/json-schema';
8
+ import { I18n } from '@flowgram.ai/editor';
9
9
  import { Input } from '@douyinfe/semi-ui';
10
10
 
11
- import { ConditionRowValueType, Op } from './types';
11
+ import { InjectVariableSelector } from '@/components/variable-selector';
12
+ import { InjectDynamicValueInput } from '@/components/dynamic-value-input';
13
+
14
+ import { ConditionRowValueType, IRules, OpConfigs } from './types';
12
15
  import { UIContainer, UILeft, UIOperator, UIRight, UIValues } from './styles';
13
16
  import { useRule } from './hooks/useRule';
14
17
  import { useOp } from './hooks/useOp';
15
- import { VariableSelector } from '../variable-selector';
16
- import { DynamicValueInput } from '../dynamic-value-input';
18
+ import { defaultOpConfigs, defaultRules } from './constants';
17
19
 
18
20
  interface PropTypes {
19
21
  value?: ConditionRowValueType;
20
22
  onChange: (value?: ConditionRowValueType) => void;
21
23
  style?: React.CSSProperties;
22
24
  readonly?: boolean;
25
+ ruleConfig?: {
26
+ ops?: OpConfigs;
27
+ rules?: IRules;
28
+ };
23
29
  }
24
30
 
25
- export function ConditionRow({ style, value, onChange, readonly }: PropTypes) {
31
+ const defaultRuleConfig = {
32
+ ops: {},
33
+ rules: {},
34
+ };
35
+
36
+ export function ConditionRow({
37
+ style,
38
+ value,
39
+ onChange,
40
+ readonly,
41
+ ruleConfig = defaultRuleConfig,
42
+ }: PropTypes) {
26
43
  const { left, operator, right } = value || {};
27
- const { rule } = useRule(left);
44
+ const { rule } = useRule(left, ruleConfig.rules);
28
45
  const { renderOpSelect, opConfig } = useOp({
29
46
  rule,
30
47
  op: operator,
31
48
  onChange: (v) => onChange({ ...value, operator: v }),
32
49
  readonly,
50
+ userOps: ruleConfig.ops,
33
51
  });
34
52
 
35
53
  const targetSchema = useMemo(() => {
36
- const targetType: JsonSchemaBasicType | null = rule?.[operator as Op] || null;
54
+ const targetType: string | null = rule?.[operator || ''] || null;
37
55
  return targetType ? { type: targetType, extra: { weak: true } } : null;
38
56
  }, [rule, opConfig]);
39
57
 
@@ -42,7 +60,7 @@ export function ConditionRow({ style, value, onChange, readonly }: PropTypes) {
42
60
  <UIOperator>{renderOpSelect()}</UIOperator>
43
61
  <UIValues>
44
62
  <UILeft>
45
- <VariableSelector
63
+ <InjectVariableSelector
46
64
  readonly={readonly}
47
65
  style={{ width: '100%' }}
48
66
  value={left?.content}
@@ -59,7 +77,7 @@ export function ConditionRow({ style, value, onChange, readonly }: PropTypes) {
59
77
  </UILeft>
60
78
  <UIRight>
61
79
  {targetSchema ? (
62
- <DynamicValueInput
80
+ <InjectDynamicValueInput
63
81
  readonly={readonly || !rule}
64
82
  value={right}
65
83
  schema={targetSchema}
@@ -70,7 +88,7 @@ export function ConditionRow({ style, value, onChange, readonly }: PropTypes) {
70
88
  size="small"
71
89
  disabled
72
90
  style={{ pointerEvents: 'none' }}
73
- value={opConfig?.rightDisplay || 'Empty'}
91
+ value={opConfig?.rightDisplay || I18n.t('Empty')}
74
92
  />
75
93
  )}
76
94
  </UIRight>
@@ -79,4 +97,7 @@ export function ConditionRow({ style, value, onChange, readonly }: PropTypes) {
79
97
  );
80
98
  }
81
99
 
100
+ ConditionRow.defaultRules = defaultRules;
101
+ ConditionRow.defaultOpConfigs = defaultOpConfigs;
102
+
82
103
  export { type ConditionRowValueType };
@@ -3,9 +3,7 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import { JsonSchemaBasicType } from '@flowgram.ai/json-schema';
7
-
8
- import { IFlowConstantRefValue, IFlowRefValue } from '../../typings';
6
+ import { IFlowConstantRefValue, IFlowRefValue } from '@/typings';
9
7
 
10
8
  export enum Op {
11
9
  EQ = 'eq',
@@ -31,14 +29,14 @@ export interface OpConfig {
31
29
  rightDisplay?: string;
32
30
  }
33
31
 
34
- export type OpConfigs = Record<Op, OpConfig>;
32
+ export type OpConfigs = Record<string, OpConfig>;
35
33
 
36
- export type IRule = Partial<Record<Op, JsonSchemaBasicType | null>>;
34
+ export type IRule = Partial<Record<string, string | null>>;
37
35
 
38
- export type IRules = Record<JsonSchemaBasicType, IRule>;
36
+ export type IRules = Record<string, IRule>;
39
37
 
40
38
  export interface ConditionRowValueType {
41
39
  left?: IFlowRefValue;
42
- operator?: Op;
40
+ operator?: string;
43
41
  right?: IFlowConstantRefValue;
44
42
  }
@@ -8,8 +8,11 @@ import React, { useMemo } from 'react';
8
8
 
9
9
  import { Input } from '@douyinfe/semi-ui';
10
10
 
11
- import { useTypeManager } from '../../plugins';
12
- import { PropsType } from './types';
11
+ import { useTypeManager } from '@/plugins';
12
+
13
+ import { PropsType, Strategy as ConstantInputStrategy } from './types';
14
+
15
+ export { ConstantInputStrategy };
13
16
 
14
17
  export function ConstantInput(props: PropsType) {
15
18
  const { value, onChange, schema, strategies, fallbackRenderer, readonly, ...rest } = props;
@@ -5,7 +5,7 @@
5
5
 
6
6
  import { IJsonSchema } from '@flowgram.ai/json-schema';
7
7
 
8
- import { ConstantRendererProps } from '../../plugins';
8
+ import { ConstantRendererProps } from '@/plugins';
9
9
 
10
10
  export interface Strategy<Value = any> {
11
11
  hit: (schema: IJsonSchema) => boolean;
@@ -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
+ }
@@ -8,8 +8,9 @@ import React, { useMemo } from 'react';
8
8
  import { JsonSchemaTypeManager, JsonSchemaUtils } from '@flowgram.ai/json-schema';
9
9
  import { useScopeAvailable } from '@flowgram.ai/editor';
10
10
 
11
- import { DisplaySchemaTag } from '../display-schema-tag';
12
- import { IFlowValue } from '../../typings';
11
+ import { IFlowValue } from '@/typings';
12
+ import { FlowValueUtils } from '@/shared';
13
+ import { DisplaySchemaTag } from '@/components/display-schema-tag';
13
14
 
14
15
  interface PropsType {
15
16
  value?: IFlowValue;
@@ -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
- 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
- }
35
+ return FlowValueUtils.inferConstantJsonSchema(value);
46
36
  }
47
37
 
48
38
  return { type: 'unknown' };
@@ -3,14 +3,19 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import React from 'react';
6
+ import React, { useMemo } from 'react';
7
+
8
+ import { isPlainObject } from 'lodash-es';
9
+ import { useScopeAvailable } from '@flowgram.ai/editor';
10
+
11
+ import { FlowValueUtils } from '@/shared';
12
+ import { DisplayFlowValue } from '@/components/display-flow-value';
7
13
 
8
- import { DisplayFlowValue } from '../display-flow-value';
9
- import { IFlowValue } from '../../typings';
10
14
  import { DisplayInputsWrapper } from './styles';
15
+ import { DisplaySchemaTag } from '../display-schema-tag';
11
16
 
12
17
  interface PropsType {
13
- value?: Record<string, IFlowValue | undefined>;
18
+ value?: any;
14
19
  showIconInTree?: boolean;
15
20
  }
16
21
 
@@ -19,9 +24,43 @@ export function DisplayInputsValues({ value, showIconInTree }: PropsType) {
19
24
 
20
25
  return (
21
26
  <DisplayInputsWrapper>
22
- {childEntries.map(([key, value]) => (
23
- <DisplayFlowValue key={key} title={key} value={value} showIconInTree={showIconInTree} />
24
- ))}
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
+ })}
25
47
  </DisplayInputsWrapper>
26
48
  );
27
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
+ }
@@ -8,7 +8,8 @@ import React, { useEffect } from 'react';
8
8
  import { IJsonSchema, JsonSchemaTypeManager, JsonSchemaUtils } from '@flowgram.ai/json-schema';
9
9
  import { useCurrentScope, useRefresh } from '@flowgram.ai/editor';
10
10
 
11
- import { DisplaySchemaTag } from '../display-schema-tag';
11
+ import { DisplaySchemaTag } from '@/components/display-schema-tag';
12
+
12
13
  import { DisplayOutputsWrapper } from './styles';
13
14
 
14
15
  interface PropsType {
@@ -8,8 +8,9 @@ import React from 'react';
8
8
  import { IJsonSchema } from '@flowgram.ai/json-schema';
9
9
  import { Popover } from '@douyinfe/semi-ui';
10
10
 
11
- import { DisplaySchemaTree } from '../display-schema-tree';
12
- import { useTypeManager } from '../../plugins';
11
+ import { useTypeManager } from '@/plugins';
12
+ import { DisplaySchemaTree } from '@/components/display-schema-tree';
13
+
13
14
  import { PopoverContent, StyledTag, TitleSpan } from './styles';
14
15
 
15
16
  interface PropsType {