@flowgram.ai/form-materials 0.4.13 → 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 (142) 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/form-plugins/infer-inputs-plugin/index.js +30 -3
  16. package/dist/cjs/plugins/json-schema-preset/create-type-preset-plugin.js +1 -0
  17. package/dist/cjs/plugins/json-schema-preset/react.js +1 -0
  18. package/dist/cjs/plugins/json-schema-preset/type-definition/array.js +30 -1
  19. package/dist/cjs/plugins/json-schema-preset/type-definition/boolean.js +23 -0
  20. package/dist/cjs/plugins/json-schema-preset/type-definition/date-time.js +31 -2
  21. package/dist/cjs/plugins/json-schema-preset/type-definition/index.js +9 -1
  22. package/dist/cjs/plugins/json-schema-preset/type-definition/integer.js +34 -1
  23. package/dist/cjs/{components/code-editor/init-worker.js → plugins/json-schema-preset/type-definition/map.js} +21 -23
  24. package/dist/cjs/plugins/json-schema-preset/type-definition/number.js +34 -1
  25. package/dist/cjs/plugins/json-schema-preset/type-definition/object.js +6 -1
  26. package/dist/cjs/plugins/json-schema-preset/type-definition/string.js +30 -1
  27. package/dist/cjs/plugins/json-schema-preset/types.js +18 -0
  28. package/dist/cjs/shared/flow-value/utils.js +22 -8
  29. package/dist/esm/components/code-editor/editor.mjs +4 -9
  30. package/dist/esm/components/code-editor/index.mjs +5 -2
  31. package/dist/esm/components/code-editor/language-features.mjs +49 -13
  32. package/dist/esm/components/code-editor/theme/dark.mjs +117 -50
  33. package/dist/esm/components/code-editor/theme/light.mjs +108 -62
  34. package/dist/esm/components/condition-context/context.mjs +19 -0
  35. package/dist/esm/components/condition-context/hooks/use-condition.mjs +63 -0
  36. package/dist/esm/components/condition-context/index.mjs +4 -0
  37. package/dist/esm/components/condition-context/op.mjs +80 -0
  38. package/dist/esm/components/condition-row/index.mjs +45 -28
  39. package/dist/esm/components/condition-row/types.mjs +0 -18
  40. package/dist/esm/components/coze-editor-extensions/extensions/variable-tag.mjs +4 -3
  41. package/dist/esm/components/coze-editor-extensions/extensions/variable-tree.mjs +3 -0
  42. package/dist/esm/components/db-condition-row/index.mjs +59 -34
  43. package/dist/esm/form-plugins/infer-inputs-plugin/index.mjs +31 -4
  44. package/dist/esm/plugins/json-schema-preset/create-type-preset-plugin.mjs +2 -1
  45. package/dist/esm/plugins/json-schema-preset/react.mjs +2 -1
  46. package/dist/esm/plugins/json-schema-preset/type-definition/array.mjs +30 -1
  47. package/dist/esm/plugins/json-schema-preset/type-definition/boolean.mjs +23 -0
  48. package/dist/esm/plugins/json-schema-preset/type-definition/date-time.mjs +31 -2
  49. package/dist/esm/plugins/json-schema-preset/type-definition/index.mjs +7 -2
  50. package/dist/esm/plugins/json-schema-preset/type-definition/integer.mjs +34 -1
  51. package/dist/esm/plugins/json-schema-preset/type-definition/map.mjs +20 -0
  52. package/dist/esm/plugins/json-schema-preset/type-definition/number.mjs +34 -1
  53. package/dist/esm/plugins/json-schema-preset/type-definition/object.mjs +6 -1
  54. package/dist/esm/plugins/json-schema-preset/type-definition/string.mjs +30 -1
  55. package/dist/esm/plugins/json-schema-preset/types.mjs +0 -0
  56. package/dist/esm/shared/flow-value/utils.mjs +22 -8
  57. package/dist/tsconfig.tsbuildinfo +1 -1
  58. package/dist/types/components/code-editor/editor.d.ts +0 -2
  59. package/dist/types/components/code-editor/language-features.d.ts +4 -1
  60. package/dist/types/components/code-editor/theme/dark.d.ts +29 -0
  61. package/dist/types/components/code-editor/theme/light.d.ts +24 -0
  62. package/dist/types/components/condition-context/context.d.ts +14 -0
  63. package/dist/types/components/condition-context/hooks/use-condition.d.ts +29 -0
  64. package/dist/types/components/condition-context/index.d.ts +8 -0
  65. package/dist/types/components/condition-context/op.d.ts +22 -0
  66. package/dist/types/components/condition-context/types.d.ts +14 -0
  67. package/dist/types/components/condition-row/index.d.ts +4 -7
  68. package/dist/types/components/condition-row/types.d.ts +0 -24
  69. package/dist/types/components/db-condition-row/index.d.ts +4 -3
  70. package/dist/types/components/db-condition-row/types.d.ts +0 -8
  71. package/dist/types/form-plugins/infer-inputs-plugin/index.d.ts +4 -0
  72. package/dist/types/plugins/json-schema-preset/create-type-preset-plugin.d.ts +1 -1
  73. package/dist/types/plugins/json-schema-preset/index.d.ts +1 -1
  74. package/dist/types/plugins/json-schema-preset/react.d.ts +1 -1
  75. package/dist/types/plugins/json-schema-preset/type-definition/array.d.ts +1 -1
  76. package/dist/types/plugins/json-schema-preset/type-definition/boolean.d.ts +1 -1
  77. package/dist/types/plugins/json-schema-preset/type-definition/date-time.d.ts +1 -1
  78. package/dist/types/plugins/json-schema-preset/type-definition/index.d.ts +3 -1
  79. package/dist/types/plugins/json-schema-preset/type-definition/integer.d.ts +1 -1
  80. package/dist/types/plugins/json-schema-preset/type-definition/map.d.ts +6 -0
  81. package/dist/types/plugins/json-schema-preset/type-definition/number.d.ts +1 -1
  82. package/dist/types/plugins/json-schema-preset/type-definition/object.d.ts +1 -1
  83. package/dist/types/plugins/json-schema-preset/type-definition/string.d.ts +1 -1
  84. package/dist/types/plugins/json-schema-preset/{manager.d.ts → types.d.ts} +5 -0
  85. package/dist/types/shared/flow-value/utils.d.ts +3 -1
  86. package/package.json +7 -6
  87. package/src/components/code-editor/editor.tsx +7 -10
  88. package/src/components/code-editor/index.tsx +3 -1
  89. package/src/components/code-editor/language-features.ts +52 -14
  90. package/src/components/code-editor/theme/dark.ts +62 -77
  91. package/src/components/code-editor/theme/light.ts +60 -91
  92. package/src/components/condition-context/context.tsx +28 -0
  93. package/src/components/condition-context/hooks/use-condition.tsx +99 -0
  94. package/src/components/condition-context/index.tsx +14 -0
  95. package/src/components/condition-context/op.ts +86 -0
  96. package/src/components/condition-context/types.ts +22 -0
  97. package/src/components/condition-row/index.tsx +44 -22
  98. package/src/components/condition-row/types.ts +0 -30
  99. package/src/components/coze-editor-extensions/extensions/variable-tag.tsx +6 -3
  100. package/src/components/coze-editor-extensions/extensions/variable-tree.tsx +3 -0
  101. package/src/components/db-condition-row/index.tsx +76 -24
  102. package/src/components/db-condition-row/types.ts +0 -13
  103. package/src/form-plugins/infer-inputs-plugin/index.ts +62 -14
  104. package/src/plugins/json-schema-preset/create-type-preset-plugin.tsx +4 -2
  105. package/src/plugins/json-schema-preset/index.tsx +1 -1
  106. package/src/plugins/json-schema-preset/react.tsx +5 -2
  107. package/src/plugins/json-schema-preset/type-definition/array.tsx +10 -1
  108. package/src/plugins/json-schema-preset/type-definition/boolean.tsx +17 -1
  109. package/src/plugins/json-schema-preset/type-definition/date-time.tsx +21 -2
  110. package/src/plugins/json-schema-preset/type-definition/index.tsx +10 -1
  111. package/src/plugins/json-schema-preset/type-definition/integer.tsx +19 -1
  112. package/src/plugins/json-schema-preset/type-definition/map.tsx +31 -0
  113. package/src/plugins/json-schema-preset/type-definition/number.tsx +19 -1
  114. package/src/plugins/json-schema-preset/type-definition/object.tsx +6 -1
  115. package/src/plugins/json-schema-preset/type-definition/string.tsx +19 -1
  116. package/src/plugins/json-schema-preset/{manager.ts → types.ts} +7 -0
  117. package/src/shared/flow-value/utils.ts +22 -9
  118. package/dist/cjs/components/condition-row/constants.js +0 -165
  119. package/dist/cjs/components/condition-row/hooks/useOp.js +0 -78
  120. package/dist/cjs/components/condition-row/hooks/useRule.js +0 -68
  121. package/dist/cjs/components/db-condition-row/hooks/use-left.js +0 -86
  122. package/dist/cjs/components/db-condition-row/hooks/use-op.js +0 -79
  123. package/dist/esm/components/code-editor/init-worker.mjs +0 -19
  124. package/dist/esm/components/condition-row/constants.mjs +0 -128
  125. package/dist/esm/components/condition-row/hooks/useOp.mjs +0 -44
  126. package/dist/esm/components/condition-row/hooks/useRule.mjs +0 -34
  127. package/dist/esm/components/db-condition-row/hooks/use-left.mjs +0 -52
  128. package/dist/esm/components/db-condition-row/hooks/use-op.mjs +0 -45
  129. package/dist/types/components/code-editor/init-worker.d.ts +0 -5
  130. package/dist/types/components/condition-row/constants.d.ts +0 -7
  131. package/dist/types/components/condition-row/hooks/useOp.d.ts +0 -18
  132. package/dist/types/components/condition-row/hooks/useRule.d.ts +0 -9
  133. package/dist/types/components/db-condition-row/hooks/use-left.d.ts +0 -18
  134. package/dist/types/components/db-condition-row/hooks/use-op.d.ts +0 -18
  135. package/src/components/code-editor/init-worker.ts +0 -27
  136. package/src/components/condition-row/constants.ts +0 -134
  137. package/src/components/condition-row/hooks/useOp.tsx +0 -56
  138. package/src/components/condition-row/hooks/useRule.ts +0 -35
  139. package/src/components/db-condition-row/hooks/use-left.tsx +0 -66
  140. package/src/components/db-condition-row/hooks/use-op.tsx +0 -59
  141. /package/dist/cjs/{plugins/json-schema-preset/manager.js → components/condition-context/types.js} +0 -0
  142. /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;
@@ -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
  };
@@ -6,20 +6,39 @@
6
6
  /* eslint-disable react/prop-types */
7
7
  import React from 'react';
8
8
 
9
+ import { format } from 'date-fns';
10
+ import { type DatePickerProps } from '@douyinfe/semi-ui/lib/es/datePicker';
9
11
  import { DatePicker } from '@douyinfe/semi-ui';
10
12
 
11
- import { type JsonSchemaTypeRegistry } from '../manager';
13
+ import { ConditionPresetOp } from '@/components/condition-context/op';
14
+
15
+ import { type JsonSchemaTypeRegistry } from '../types';
12
16
 
13
17
  export const dateTimeRegistry: Partial<JsonSchemaTypeRegistry> = {
14
18
  type: 'date-time',
15
- ConstantRenderer: (props) => (
19
+ ConstantRenderer: (props: DatePickerProps & { readonly?: boolean }) => (
16
20
  <DatePicker
17
21
  size="small"
18
22
  type="dateTime"
19
23
  density="compact"
24
+ defaultValue={Date.now()}
20
25
  style={{ width: '100%', ...(props.style || {}) }}
21
26
  disabled={props.readonly}
22
27
  {...props}
28
+ onChange={(date) => {
29
+ props.onChange?.(format(date as Date, "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"));
30
+ }}
31
+ value={props.value}
23
32
  />
24
33
  ),
34
+ conditionRule: {
35
+ [ConditionPresetOp.EQ]: { type: 'date-time' },
36
+ [ConditionPresetOp.NEQ]: { type: 'date-time' },
37
+ [ConditionPresetOp.GT]: { type: 'date-time' },
38
+ [ConditionPresetOp.GTE]: { type: 'date-time' },
39
+ [ConditionPresetOp.LT]: { type: 'date-time' },
40
+ [ConditionPresetOp.LTE]: { type: 'date-time' },
41
+ [ConditionPresetOp.IS_EMPTY]: null,
42
+ [ConditionPresetOp.IS_NOT_EMPTY]: null,
43
+ },
25
44
  };
@@ -8,10 +8,12 @@ import { jsonSchemaTypeManager } from '@flowgram.ai/json-schema';
8
8
  import { stringRegistry } from './string';
9
9
  import { objectRegistry } from './object';
10
10
  import { numberRegistry } from './number';
11
+ import { mapRegistry } from './map';
11
12
  import { integerRegistry } from './integer';
12
13
  import { dateTimeRegistry } from './date-time';
13
14
  import { booleanRegistry } from './boolean';
14
15
  import { arrayRegistry } from './array';
16
+ import { type JsonSchemaTypeRegistry } from '../types';
15
17
 
16
18
  export const jsonSchemaTypePreset = [
17
19
  stringRegistry,
@@ -20,7 +22,14 @@ export const jsonSchemaTypePreset = [
20
22
  integerRegistry,
21
23
  booleanRegistry,
22
24
  arrayRegistry,
25
+ mapRegistry,
23
26
  dateTimeRegistry,
24
27
  ];
25
28
 
26
- jsonSchemaTypePreset.forEach((_type) => jsonSchemaTypeManager.register(_type));
29
+ export const initRegistries = () => {
30
+ if ((jsonSchemaTypeManager.getTypeByName('string') as JsonSchemaTypeRegistry)?.ConstantRenderer) {
31
+ return;
32
+ }
33
+
34
+ jsonSchemaTypePreset.forEach((_type) => jsonSchemaTypeManager.register(_type));
35
+ };
@@ -9,7 +9,9 @@ import React from 'react';
9
9
  import { I18n } from '@flowgram.ai/editor';
10
10
  import { InputNumber } 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 integerRegistry: Partial<JsonSchemaTypeRegistry> = {
15
17
  type: 'integer',
@@ -22,4 +24,20 @@ export const integerRegistry: Partial<JsonSchemaTypeRegistry> = {
22
24
  {...props}
23
25
  />
24
26
  ),
27
+ conditionRule: {
28
+ [ConditionPresetOp.EQ]: { type: 'number' },
29
+ [ConditionPresetOp.NEQ]: { type: 'number' },
30
+ [ConditionPresetOp.GT]: { type: 'number' },
31
+ [ConditionPresetOp.GTE]: { type: 'number' },
32
+ [ConditionPresetOp.LT]: { type: 'number' },
33
+ [ConditionPresetOp.LTE]: { type: 'number' },
34
+ [ConditionPresetOp.IN]: {
35
+ type: 'array',
36
+ extra: { weak: true },
37
+ },
38
+ [ConditionPresetOp.NIN]: {
39
+ type: 'array',
40
+ extra: { weak: true },
41
+ },
42
+ },
25
43
  };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /* eslint-disable react/prop-types */
7
+ import React from 'react';
8
+
9
+ import { I18n } from '@flowgram.ai/editor';
10
+
11
+ import { ConditionPresetOp } from '@/components/condition-context/op';
12
+ import { CodeEditorMini } from '@/components/code-editor-mini';
13
+
14
+ import { type JsonSchemaTypeRegistry } from '../types';
15
+
16
+ export const mapRegistry: Partial<JsonSchemaTypeRegistry> = {
17
+ type: 'map',
18
+ ConstantRenderer: (props) => (
19
+ <CodeEditorMini
20
+ value={props.value}
21
+ onChange={(v) => props.onChange?.(v)}
22
+ languageId="json"
23
+ placeholder={I18n.t('Please Input Map')}
24
+ readonly={props.readonly}
25
+ />
26
+ ),
27
+ conditionRule: {
28
+ [ConditionPresetOp.IS_EMPTY]: null,
29
+ [ConditionPresetOp.IS_NOT_EMPTY]: null,
30
+ },
31
+ };