@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.
Files changed (149) hide show
  1. package/dist/cjs/components/code-editor/editor.js +54 -77
  2. package/dist/cjs/components/code-editor/index.js +10 -2
  3. package/dist/cjs/components/code-editor/language-features.js +119 -16
  4. package/dist/cjs/components/code-editor/theme/dark.js +120 -50
  5. package/dist/cjs/components/code-editor/theme/light.js +110 -61
  6. package/dist/cjs/components/condition-context/context.js +59 -0
  7. package/dist/cjs/components/condition-context/hooks/use-condition.js +97 -0
  8. package/dist/cjs/components/condition-context/index.js +47 -0
  9. package/dist/cjs/components/condition-context/op.js +117 -0
  10. package/dist/cjs/components/condition-row/index.js +43 -26
  11. package/dist/cjs/components/condition-row/types.js +1 -35
  12. package/dist/cjs/components/coze-editor-extensions/extensions/variable-tag.js +4 -3
  13. package/dist/cjs/components/coze-editor-extensions/extensions/variable-tree.js +3 -0
  14. package/dist/cjs/components/db-condition-row/index.js +59 -34
  15. package/dist/cjs/components/variable-selector/index.js +0 -1
  16. package/dist/cjs/form-plugins/batch-outputs-plugin/index.js +8 -1
  17. package/dist/cjs/form-plugins/infer-inputs-plugin/index.js +30 -3
  18. package/dist/cjs/plugins/json-schema-preset/create-type-preset-plugin.js +1 -0
  19. package/dist/cjs/plugins/json-schema-preset/react.js +1 -0
  20. package/dist/cjs/plugins/json-schema-preset/type-definition/array.js +30 -1
  21. package/dist/cjs/plugins/json-schema-preset/type-definition/boolean.js +23 -0
  22. package/dist/cjs/plugins/json-schema-preset/type-definition/date-time.js +31 -2
  23. package/dist/cjs/plugins/json-schema-preset/type-definition/index.js +9 -1
  24. package/dist/cjs/plugins/json-schema-preset/type-definition/integer.js +34 -1
  25. package/dist/cjs/{components/code-editor/init-worker.js → plugins/json-schema-preset/type-definition/map.js} +21 -23
  26. package/dist/cjs/plugins/json-schema-preset/type-definition/number.js +34 -1
  27. package/dist/cjs/plugins/json-schema-preset/type-definition/object.js +6 -1
  28. package/dist/cjs/plugins/json-schema-preset/type-definition/string.js +30 -1
  29. package/dist/cjs/plugins/json-schema-preset/types.js +18 -0
  30. package/dist/cjs/shared/flow-value/utils.js +22 -8
  31. package/dist/esm/components/code-editor/editor.mjs +4 -9
  32. package/dist/esm/components/code-editor/index.mjs +5 -2
  33. package/dist/esm/components/code-editor/language-features.mjs +49 -13
  34. package/dist/esm/components/code-editor/theme/dark.mjs +117 -50
  35. package/dist/esm/components/code-editor/theme/light.mjs +108 -62
  36. package/dist/esm/components/condition-context/context.mjs +19 -0
  37. package/dist/esm/components/condition-context/hooks/use-condition.mjs +63 -0
  38. package/dist/esm/components/condition-context/index.mjs +4 -0
  39. package/dist/esm/components/condition-context/op.mjs +80 -0
  40. package/dist/esm/components/condition-row/index.mjs +45 -28
  41. package/dist/esm/components/condition-row/types.mjs +0 -18
  42. package/dist/esm/components/coze-editor-extensions/extensions/variable-tag.mjs +4 -3
  43. package/dist/esm/components/coze-editor-extensions/extensions/variable-tree.mjs +3 -0
  44. package/dist/esm/components/db-condition-row/index.mjs +59 -34
  45. package/dist/esm/components/variable-selector/index.mjs +0 -1
  46. package/dist/esm/form-plugins/batch-outputs-plugin/index.mjs +8 -1
  47. package/dist/esm/form-plugins/infer-inputs-plugin/index.mjs +31 -4
  48. package/dist/esm/plugins/json-schema-preset/create-type-preset-plugin.mjs +2 -1
  49. package/dist/esm/plugins/json-schema-preset/react.mjs +2 -1
  50. package/dist/esm/plugins/json-schema-preset/type-definition/array.mjs +30 -1
  51. package/dist/esm/plugins/json-schema-preset/type-definition/boolean.mjs +23 -0
  52. package/dist/esm/plugins/json-schema-preset/type-definition/date-time.mjs +31 -2
  53. package/dist/esm/plugins/json-schema-preset/type-definition/index.mjs +7 -2
  54. package/dist/esm/plugins/json-schema-preset/type-definition/integer.mjs +34 -1
  55. package/dist/esm/plugins/json-schema-preset/type-definition/map.mjs +20 -0
  56. package/dist/esm/plugins/json-schema-preset/type-definition/number.mjs +34 -1
  57. package/dist/esm/plugins/json-schema-preset/type-definition/object.mjs +6 -1
  58. package/dist/esm/plugins/json-schema-preset/type-definition/string.mjs +30 -1
  59. package/dist/esm/plugins/json-schema-preset/types.mjs +0 -0
  60. package/dist/esm/shared/flow-value/utils.mjs +22 -8
  61. package/dist/tsconfig.tsbuildinfo +1 -1
  62. package/dist/types/components/code-editor/editor.d.ts +0 -2
  63. package/dist/types/components/code-editor/language-features.d.ts +4 -1
  64. package/dist/types/components/code-editor/theme/dark.d.ts +29 -0
  65. package/dist/types/components/code-editor/theme/light.d.ts +24 -0
  66. package/dist/types/components/condition-context/context.d.ts +14 -0
  67. package/dist/types/components/condition-context/hooks/use-condition.d.ts +29 -0
  68. package/dist/types/components/condition-context/index.d.ts +8 -0
  69. package/dist/types/components/condition-context/op.d.ts +22 -0
  70. package/dist/types/components/condition-context/types.d.ts +14 -0
  71. package/dist/types/components/condition-row/index.d.ts +4 -7
  72. package/dist/types/components/condition-row/types.d.ts +0 -24
  73. package/dist/types/components/db-condition-row/index.d.ts +4 -3
  74. package/dist/types/components/db-condition-row/types.d.ts +0 -8
  75. package/dist/types/form-plugins/batch-outputs-plugin/index.d.ts +4 -0
  76. package/dist/types/form-plugins/infer-inputs-plugin/index.d.ts +4 -0
  77. package/dist/types/plugins/json-schema-preset/create-type-preset-plugin.d.ts +1 -1
  78. package/dist/types/plugins/json-schema-preset/index.d.ts +1 -1
  79. package/dist/types/plugins/json-schema-preset/react.d.ts +1 -1
  80. package/dist/types/plugins/json-schema-preset/type-definition/array.d.ts +1 -1
  81. package/dist/types/plugins/json-schema-preset/type-definition/boolean.d.ts +1 -1
  82. package/dist/types/plugins/json-schema-preset/type-definition/date-time.d.ts +1 -1
  83. package/dist/types/plugins/json-schema-preset/type-definition/index.d.ts +3 -1
  84. package/dist/types/plugins/json-schema-preset/type-definition/integer.d.ts +1 -1
  85. package/dist/types/plugins/json-schema-preset/type-definition/map.d.ts +6 -0
  86. package/dist/types/plugins/json-schema-preset/type-definition/number.d.ts +1 -1
  87. package/dist/types/plugins/json-schema-preset/type-definition/object.d.ts +1 -1
  88. package/dist/types/plugins/json-schema-preset/type-definition/string.d.ts +1 -1
  89. package/dist/types/plugins/json-schema-preset/{manager.d.ts → types.d.ts} +5 -0
  90. package/dist/types/shared/flow-value/utils.d.ts +3 -1
  91. package/package.json +9 -8
  92. package/src/components/code-editor/editor.tsx +7 -10
  93. package/src/components/code-editor/index.tsx +3 -1
  94. package/src/components/code-editor/language-features.ts +52 -14
  95. package/src/components/code-editor/theme/dark.ts +62 -77
  96. package/src/components/code-editor/theme/light.ts +60 -91
  97. package/src/components/condition-context/context.tsx +28 -0
  98. package/src/components/condition-context/hooks/use-condition.tsx +99 -0
  99. package/src/components/condition-context/index.tsx +14 -0
  100. package/src/components/condition-context/op.ts +86 -0
  101. package/src/components/condition-context/types.ts +22 -0
  102. package/src/components/condition-row/index.tsx +44 -22
  103. package/src/components/condition-row/types.ts +0 -30
  104. package/src/components/coze-editor-extensions/extensions/variable-tag.tsx +6 -3
  105. package/src/components/coze-editor-extensions/extensions/variable-tree.tsx +3 -0
  106. package/src/components/db-condition-row/index.tsx +76 -24
  107. package/src/components/db-condition-row/types.ts +0 -13
  108. package/src/components/variable-selector/index.tsx +0 -2
  109. package/src/form-plugins/batch-outputs-plugin/index.ts +63 -44
  110. package/src/form-plugins/infer-inputs-plugin/index.ts +62 -14
  111. package/src/plugins/json-schema-preset/create-type-preset-plugin.tsx +4 -2
  112. package/src/plugins/json-schema-preset/index.tsx +1 -1
  113. package/src/plugins/json-schema-preset/react.tsx +5 -2
  114. package/src/plugins/json-schema-preset/type-definition/array.tsx +10 -1
  115. package/src/plugins/json-schema-preset/type-definition/boolean.tsx +17 -1
  116. package/src/plugins/json-schema-preset/type-definition/date-time.tsx +21 -2
  117. package/src/plugins/json-schema-preset/type-definition/index.tsx +10 -1
  118. package/src/plugins/json-schema-preset/type-definition/integer.tsx +19 -1
  119. package/src/plugins/json-schema-preset/type-definition/map.tsx +31 -0
  120. package/src/plugins/json-schema-preset/type-definition/number.tsx +19 -1
  121. package/src/plugins/json-schema-preset/type-definition/object.tsx +6 -1
  122. package/src/plugins/json-schema-preset/type-definition/string.tsx +19 -1
  123. package/src/plugins/json-schema-preset/{manager.ts → types.ts} +7 -0
  124. package/src/shared/flow-value/utils.ts +22 -9
  125. package/dist/cjs/components/condition-row/constants.js +0 -165
  126. package/dist/cjs/components/condition-row/hooks/useOp.js +0 -78
  127. package/dist/cjs/components/condition-row/hooks/useRule.js +0 -68
  128. package/dist/cjs/components/db-condition-row/hooks/use-left.js +0 -86
  129. package/dist/cjs/components/db-condition-row/hooks/use-op.js +0 -79
  130. package/dist/esm/components/code-editor/init-worker.mjs +0 -19
  131. package/dist/esm/components/condition-row/constants.mjs +0 -128
  132. package/dist/esm/components/condition-row/hooks/useOp.mjs +0 -44
  133. package/dist/esm/components/condition-row/hooks/useRule.mjs +0 -34
  134. package/dist/esm/components/db-condition-row/hooks/use-left.mjs +0 -52
  135. package/dist/esm/components/db-condition-row/hooks/use-op.mjs +0 -45
  136. package/dist/types/components/code-editor/init-worker.d.ts +0 -5
  137. package/dist/types/components/condition-row/constants.d.ts +0 -7
  138. package/dist/types/components/condition-row/hooks/useOp.d.ts +0 -18
  139. package/dist/types/components/condition-row/hooks/useRule.d.ts +0 -9
  140. package/dist/types/components/db-condition-row/hooks/use-left.d.ts +0 -18
  141. package/dist/types/components/db-condition-row/hooks/use-op.d.ts +0 -18
  142. package/src/components/code-editor/init-worker.ts +0 -27
  143. package/src/components/condition-row/constants.ts +0 -134
  144. package/src/components/condition-row/hooks/useOp.tsx +0 -56
  145. package/src/components/condition-row/hooks/useRule.ts +0 -35
  146. package/src/components/db-condition-row/hooks/use-left.tsx +0 -66
  147. package/src/components/db-condition-row/hooks/use-op.tsx +0 -59
  148. /package/dist/cjs/{plugins/json-schema-preset/manager.js → components/condition-context/types.js} +0 -0
  149. /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 { I18n } from '@flowgram.ai/editor';
9
- import { Input } from '@douyinfe/semi-ui';
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, IRules, OpConfigs } from './types';
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?: OpConfigs;
27
- rules?: IRules;
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
- const { rule } = useRule(left, ruleConfig.rules);
45
- const { renderOpSelect, opConfig } = useOp({
46
- rule,
47
- op: operator,
48
- onChange: (v) => onChange({ ...value, operator: v }),
49
- readonly,
50
- userOps: ruleConfig.ops,
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 targetSchema = useMemo(() => {
54
- const targetType: string | null = rule?.[operator || ''] || null;
55
- return targetType ? { type: targetType, extra: { weak: true } } : null;
56
- }, [rule, opConfig]);
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>{rootField?.meta.title ? `${rootField.meta.title} -` : ''}</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
  );
@@ -82,6 +82,9 @@ export function VariableTree({
82
82
  <div style={{ width: 300, maxHeight: 300, overflowY: 'auto' }}>
83
83
  <Tree
84
84
  treeData={treeData}
85
+ onExpand={(v) => {
86
+ setPosKey(String(Math.random()));
87
+ }}
85
88
  onSelect={(v) => {
86
89
  insert(v);
87
90
  }}
@@ -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, 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';
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?: OpConfigs;
26
- rules?: IRules;
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 { rule, renderDBOptionSelect } = useLeft({
46
- left,
47
- options,
48
- onChange: (leftKey) => onChange({ ...value, left: leftKey }),
49
- readonly,
50
- userRules: ruleConfig.rules,
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 { renderOpSelect, opConfig } = useOp({
54
- rule,
55
- op: operator,
56
- onChange: (v) => onChange({ ...value, operator: v }),
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 targetSchema = useMemo(() => {
62
- const targetType: string | null = rule?.[operator || ''] || null;
63
- return targetType ? { type: targetType, extra: { weak: true } } : null;
64
- }, [rule, opConfig]);
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;
@@ -73,8 +73,6 @@ export const VariableSelector = ({
73
73
  return icon;
74
74
  };
75
75
 
76
- console.log('debugger treeValue', treeValue);
77
-
78
76
  return (
79
77
  <>
80
78
  <UITreeSelect
@@ -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<{ outputKey: string }> =
50
- defineFormPluginCreator({
51
- name: 'batch-outputs-plugin',
52
- onSetupFormMeta({ mergeEffect }, { outputKey }) {
53
- mergeEffect({
54
- [outputKey]: provideBatchOutputsEffect,
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
- onInit(ctx, { outputKey }) {
58
- const chainTransformService = ctx.node.getService(ScopeChainTransformService);
74
+ }
75
+ },
76
+ onInit(ctx, { outputKey }) {
77
+ const chainTransformService = ctx.node.getService(ScopeChainTransformService);
59
78
 
60
- const batchNodeType = ctx.node.flowNodeType;
79
+ const batchNodeType = ctx.node.flowNodeType;
61
80
 
62
- const transformerId = `${batchNodeType}-outputs`;
81
+ const transformerId = `${batchNodeType}-outputs`;
63
82
 
64
- if (chainTransformService.hasTransformer(transformerId)) {
65
- return;
66
- }
83
+ if (chainTransformService.hasTransformer(transformerId)) {
84
+ return;
85
+ }
67
86
 
68
- chainTransformService.registerTransformer(transformerId, {
69
- transformCovers: (covers, ctx) => {
70
- const node = ctx.scope.meta?.node;
87
+ chainTransformService.registerTransformer(transformerId, {
88
+ transformCovers: (covers, ctx) => {
89
+ const node = ctx.scope.meta?.node;
71
90
 
72
- // Child Node's variable can cover parent
73
- if (node?.parent?.flowNodeType === batchNodeType) {
74
- return [...covers, getNodeScope(node.parent)];
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
- return covers;
78
- },
79
- transformDeps(scopes, ctx) {
80
- const scopeMeta = ctx.scope.meta;
96
+ return covers;
97
+ },
98
+ transformDeps(scopes, ctx) {
99
+ const scopeMeta = ctx.scope.meta;
81
100
 
82
- if (scopeMeta?.type === FlowNodeScopeType.private) {
83
- return scopes;
84
- }
101
+ if (scopeMeta?.type === FlowNodeScopeType.private) {
102
+ return scopes;
103
+ }
85
104
 
86
- const node = scopeMeta?.node;
105
+ const node = scopeMeta?.node;
87
106
 
88
- // Public of Loop Node depends on child Node
89
- if (node?.flowNodeType === batchNodeType) {
90
- // Get all child blocks
91
- const childBlocks = node.blocks;
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
- // public scope of all child blocks
94
- return [
95
- getNodePrivateScope(node),
96
- ...childBlocks.map((_childBlock) => getNodeScope(_childBlock)),
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
- return scopes;
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({ addFormatOnSubmit }, { sourceKey, targetKey, scope }) {
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
- set(
25
- formData,
26
- targetKey,
27
- FlowValueUtils.inferJsonSchema(
28
- get(formData, sourceKey),
29
- scope === 'private' ? getNodePrivateScope(ctx.node) : getNodeScope(ctx.node)
30
- )
31
- );
32
-
33
- return formData;
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 { jsonSchemaTypePreset } from './type-definition';
14
- import { JsonSchemaTypeRegistry } from './manager';
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 { jsonSchemaTypePreset } from './type-definition';
16
- import { type JsonSchemaTypeRegistry } from './manager';
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 '../manager';
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 { type JsonSchemaTypeRegistry } from '../manager';
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
  };