@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
@@ -1,46 +1,62 @@
1
1
  import { createTheme, tags } from "@flowgram.ai/coze-editor/preset-code";
2
2
  const colors = {
3
- background: '#FFFFFF',
4
- comment: '#6B7280',
5
- key: '#2563EB',
6
- variable: '#DC2626',
7
- string: '#059669',
8
- number: '#EA580C',
9
- boolean: '#7C3AED',
10
- null: '#7C3AED',
11
- separator: '#374151'
3
+ background: '#f4f5f5',
4
+ foreground: '#444d56',
5
+ selection: '#0366d625',
6
+ cursor: '#044289',
7
+ dropdownBackground: '#fff',
8
+ dropdownBorder: '#e1e4e8',
9
+ activeLine: '#c6c6c622',
10
+ matchingBracket: '#34d05840',
11
+ keyword: '#d73a49',
12
+ storage: '#d73a49',
13
+ variable: '#e36209',
14
+ parameter: '#24292e',
15
+ function: '#005cc5',
16
+ string: '#032f62',
17
+ constant: '#005cc5',
18
+ type: '#005cc5',
19
+ class: '#6f42c1',
20
+ number: '#005cc5',
21
+ comment: '#6a737d',
22
+ heading: '#005cc5',
23
+ invalid: '#cb2431',
24
+ regexp: '#032f62'
12
25
  };
13
26
  const lightTheme = createTheme({
14
27
  variant: 'light',
15
28
  settings: {
16
- background: '#FFFFFF',
17
- foreground: '#1F2937',
18
- caret: '#2563EB',
19
- selection: '#E5E7EB',
20
- gutterBackground: '#F9FAFB',
21
- gutterForeground: '#6B7280',
29
+ background: colors.background,
30
+ foreground: colors.foreground,
31
+ caret: colors.cursor,
32
+ selection: colors.selection,
33
+ gutterBackground: colors.background,
34
+ gutterForeground: colors.foreground,
22
35
  gutterBorderColor: 'transparent',
23
36
  gutterBorderWidth: 0,
24
- lineHighlight: '#F3F4F680',
37
+ lineHighlight: colors.background,
25
38
  bracketColors: [
26
39
  '#F59E0B',
27
40
  '#8B5CF6',
28
41
  '#06B6D4'
29
42
  ],
30
43
  tooltip: {
31
- backgroundColor: '#FFFFFF',
32
- color: '#1F2937',
33
- border: '1px solid #E5E7EB',
34
- boxShadow: '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)'
44
+ backgroundColor: colors.dropdownBackground,
45
+ color: colors.foreground,
46
+ border: 'none',
47
+ boxShadow: '0 0 1px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .1)!important',
48
+ maxWidth: '400px'
35
49
  },
36
50
  link: {
37
- color: '#2563EB'
51
+ color: '#2563EB',
52
+ caret: colors.cursor
38
53
  },
39
54
  completionItemHover: {
40
55
  backgroundColor: '#F3F4F6'
41
56
  },
42
57
  completionItemSelected: {
43
- backgroundColor: '#E5E7EB'
58
+ backgroundColor: colors.selection,
59
+ color: colors.foreground
44
60
  },
45
61
  completionItemIcon: {
46
62
  color: '#4B5563'
@@ -57,105 +73,135 @@ const lightTheme = createTheme({
57
73
  },
58
74
  styles: [
59
75
  {
60
- tag: tags.comment,
61
- color: colors.comment
76
+ tag: tags.keyword,
77
+ color: colors.keyword
62
78
  },
63
79
  {
64
80
  tag: [
65
- tags.propertyName
81
+ tags.name,
82
+ tags.deleted,
83
+ tags.character,
84
+ tags.macroName
66
85
  ],
67
- color: colors.key
86
+ color: colors.variable
68
87
  },
69
88
  {
70
89
  tag: [
71
- tags.variableName
90
+ tags.propertyName
72
91
  ],
73
- color: colors.variable
92
+ color: colors.function
74
93
  },
75
94
  {
76
95
  tag: [
77
- tags.string
96
+ tags.processingInstruction,
97
+ tags.string,
98
+ tags.inserted,
99
+ tags.special(tags.string)
78
100
  ],
79
101
  color: colors.string
80
102
  },
81
103
  {
82
104
  tag: [
83
- tags.number
105
+ tags["function"](tags.variableName),
106
+ tags.labelName
84
107
  ],
85
- color: colors.number
108
+ color: colors.function
86
109
  },
87
110
  {
88
111
  tag: [
89
- tags.bool
112
+ tags.color,
113
+ tags.constant(tags.name),
114
+ tags.standard(tags.name)
90
115
  ],
91
- color: colors.boolean
116
+ color: colors.constant
92
117
  },
93
118
  {
94
119
  tag: [
95
- tags["null"]
120
+ tags.definition(tags.name),
121
+ tags.separator
96
122
  ],
97
- color: colors.null
123
+ color: colors.variable
98
124
  },
99
125
  {
100
126
  tag: [
101
- tags.separator
127
+ tags.className
102
128
  ],
103
- color: colors.separator
129
+ color: colors.class
104
130
  },
105
131
  {
106
132
  tag: [
107
- tags.heading
133
+ tags.number,
134
+ tags.changed,
135
+ tags.annotation,
136
+ tags.modifier,
137
+ tags.self,
138
+ tags.namespace
108
139
  ],
109
- color: '#2563EB'
140
+ color: colors.number
110
141
  },
111
142
  {
112
143
  tag: [
113
- tags.processingInstruction
144
+ tags.typeName
114
145
  ],
115
- color: '#2563EB'
146
+ color: colors.type,
147
+ fontStyle: colors.type
116
148
  },
117
149
  {
118
150
  tag: [
119
- tags.definitionKeyword
151
+ tags.operator,
152
+ tags.operatorKeyword
120
153
  ],
121
- color: '#9333EA'
154
+ color: colors.keyword
122
155
  },
123
156
  {
124
157
  tag: [
125
- tags.modifier
158
+ tags.url,
159
+ tags.escape,
160
+ tags.regexp,
161
+ tags.link
126
162
  ],
127
- color: '#9333EA'
163
+ color: colors.regexp
128
164
  },
129
165
  {
130
166
  tag: [
131
- tags.controlKeyword
167
+ tags.meta,
168
+ tags.comment
132
169
  ],
133
- color: '#9333EA'
170
+ color: colors.comment
134
171
  },
135
172
  {
136
- tag: [
137
- tags.operatorKeyword
138
- ],
139
- color: '#9333EA'
173
+ tag: tags.strong,
174
+ fontWeight: 'bold'
140
175
  },
141
176
  {
142
- tag: [
143
- tags.standard(tags.variableName)
144
- ],
145
- color: '#059669'
177
+ tag: tags.emphasis,
178
+ fontStyle: 'italic'
146
179
  },
147
180
  {
148
- tag: [
149
- tags.attributeName
150
- ],
151
- color: '#EA580C'
181
+ tag: tags.link,
182
+ textDecoration: 'underline'
183
+ },
184
+ {
185
+ tag: tags.heading,
186
+ fontWeight: 'bold',
187
+ color: colors.heading
152
188
  },
153
189
  {
154
190
  tag: [
155
- tags.special(tags.string)
191
+ tags.atom,
192
+ tags.bool,
193
+ tags.special(tags.variableName)
156
194
  ],
157
- color: '#2563EB'
195
+ color: colors.variable
196
+ },
197
+ {
198
+ tag: tags.invalid,
199
+ color: colors.invalid
200
+ },
201
+ {
202
+ tag: tags.strikethrough,
203
+ textDecoration: 'line-through'
158
204
  }
159
205
  ]
160
206
  });
161
- export { lightTheme };
207
+ export { colors, lightTheme };
@@ -0,0 +1,19 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext } from "react";
3
+ import { defaultConditionOpConfigs } from "./op.mjs";
4
+ const ConditionContext = /*#__PURE__*/ createContext({
5
+ rules: {},
6
+ ops: defaultConditionOpConfigs
7
+ });
8
+ const ConditionProvider = (props)=>{
9
+ const { rules, ops } = props;
10
+ return /*#__PURE__*/ jsx(ConditionContext.Provider, {
11
+ value: {
12
+ rules,
13
+ ops
14
+ },
15
+ children: props.children
16
+ });
17
+ };
18
+ const useConditionContext = ()=>useContext(ConditionContext);
19
+ export { ConditionContext, ConditionProvider, useConditionContext };
@@ -0,0 +1,63 @@
1
+ import { useMemo } from "react";
2
+ import { I18n } from "@flowgram.ai/editor";
3
+ import { useTypeManager } from "../../../plugins/index.mjs";
4
+ import { useConditionContext } from "../context.mjs";
5
+ function useCondition({ leftSchema, operator, ruleConfig }) {
6
+ const typeManager = useTypeManager();
7
+ const { rules: contextRules, ops: contextOps } = useConditionContext();
8
+ const userRules = useMemo(()=>ruleConfig?.rules || contextRules || {}, [
9
+ contextRules,
10
+ ruleConfig?.rules
11
+ ]);
12
+ const allOps = useMemo(()=>ruleConfig?.ops || contextOps || {}, [
13
+ contextOps,
14
+ ruleConfig?.ops
15
+ ]);
16
+ const config = useMemo(()=>leftSchema ? typeManager.getTypeBySchema(leftSchema) : void 0, [
17
+ leftSchema,
18
+ typeManager
19
+ ]);
20
+ const rule = useMemo(()=>{
21
+ if (!config) return;
22
+ if (userRules[config.type]) return userRules[config.type];
23
+ if ('function' == typeof config.conditionRule) return config.conditionRule(leftSchema);
24
+ return config.conditionRule;
25
+ }, [
26
+ userRules,
27
+ leftSchema,
28
+ config
29
+ ]);
30
+ const opOptionList = useMemo(()=>Object.keys(rule || {}).filter((_op)=>allOps[_op]).map((_op)=>({
31
+ ...allOps?.[_op] || {},
32
+ value: _op,
33
+ label: I18n.t(allOps?.[_op]?.label || _op)
34
+ })), [
35
+ rule,
36
+ allOps
37
+ ]);
38
+ const targetSchema = useMemo(()=>{
39
+ const targetType = rule?.[operator || ''] || null;
40
+ if (!targetType) return;
41
+ if ('string' == typeof targetType) return {
42
+ type: targetType,
43
+ extra: {
44
+ weak: true
45
+ }
46
+ };
47
+ return targetType;
48
+ }, [
49
+ rule,
50
+ operator
51
+ ]);
52
+ const opConfig = useMemo(()=>allOps[operator || ''], [
53
+ operator,
54
+ allOps
55
+ ]);
56
+ return {
57
+ rule,
58
+ opConfig,
59
+ opOptionList,
60
+ targetSchema
61
+ };
62
+ }
63
+ export { useCondition };
@@ -0,0 +1,4 @@
1
+ import { ConditionPresetOp } from "./op.mjs";
2
+ import { ConditionProvider, useConditionContext } from "./context.mjs";
3
+ import { useCondition } from "./hooks/use-condition.mjs";
4
+ export { ConditionPresetOp, ConditionProvider, useCondition, useConditionContext };
@@ -0,0 +1,80 @@
1
+ var op_ConditionPresetOp = /*#__PURE__*/ function(ConditionPresetOp) {
2
+ ConditionPresetOp["EQ"] = "eq";
3
+ ConditionPresetOp["NEQ"] = "neq";
4
+ ConditionPresetOp["GT"] = "gt";
5
+ ConditionPresetOp["GTE"] = "gte";
6
+ ConditionPresetOp["LT"] = "lt";
7
+ ConditionPresetOp["LTE"] = "lte";
8
+ ConditionPresetOp["IN"] = "in";
9
+ ConditionPresetOp["NIN"] = "nin";
10
+ ConditionPresetOp["CONTAINS"] = "contains";
11
+ ConditionPresetOp["NOT_CONTAINS"] = "not_contains";
12
+ ConditionPresetOp["IS_EMPTY"] = "is_empty";
13
+ ConditionPresetOp["IS_NOT_EMPTY"] = "is_not_empty";
14
+ ConditionPresetOp["IS_TRUE"] = "is_true";
15
+ ConditionPresetOp["IS_FALSE"] = "is_false";
16
+ return ConditionPresetOp;
17
+ }({});
18
+ const defaultConditionOpConfigs = {
19
+ ["eq"]: {
20
+ label: 'Equal',
21
+ abbreviation: '='
22
+ },
23
+ ["neq"]: {
24
+ label: 'Not Equal',
25
+ abbreviation: "\u2260"
26
+ },
27
+ ["gt"]: {
28
+ label: 'Greater Than',
29
+ abbreviation: '>'
30
+ },
31
+ ["gte"]: {
32
+ label: 'Greater Than or Equal',
33
+ abbreviation: '>='
34
+ },
35
+ ["lt"]: {
36
+ label: 'Less Than',
37
+ abbreviation: '<'
38
+ },
39
+ ["lte"]: {
40
+ label: 'Less Than or Equal',
41
+ abbreviation: '<='
42
+ },
43
+ ["in"]: {
44
+ label: 'In',
45
+ abbreviation: "\u2208"
46
+ },
47
+ ["nin"]: {
48
+ label: 'Not In',
49
+ abbreviation: "\u2209"
50
+ },
51
+ ["contains"]: {
52
+ label: 'Contains',
53
+ abbreviation: "\u2287"
54
+ },
55
+ ["not_contains"]: {
56
+ label: 'Not Contains',
57
+ abbreviation: "\u2289"
58
+ },
59
+ ["is_empty"]: {
60
+ label: 'Is Empty',
61
+ abbreviation: '=',
62
+ rightDisplay: 'Empty'
63
+ },
64
+ ["is_not_empty"]: {
65
+ label: 'Is Not Empty',
66
+ abbreviation: "\u2260",
67
+ rightDisplay: 'Empty'
68
+ },
69
+ ["is_true"]: {
70
+ label: 'Is True',
71
+ abbreviation: '=',
72
+ rightDisplay: 'True'
73
+ },
74
+ ["is_false"]: {
75
+ label: 'Is False',
76
+ abbreviation: '=',
77
+ rightDisplay: 'False'
78
+ }
79
+ };
80
+ export { op_ConditionPresetOp as ConditionPresetOp, defaultConditionOpConfigs };
@@ -1,42 +1,61 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useMemo } from "react";
3
- import { I18n } from "@flowgram.ai/editor";
4
- import { Input } from "@douyinfe/semi-ui";
3
+ import { JsonSchemaUtils } from "@flowgram.ai/json-schema";
4
+ import { I18n, useScopeAvailable } from "@flowgram.ai/editor";
5
+ import { Button, Input, Select } from "@douyinfe/semi-ui";
6
+ import { IconChevronDownStroked } from "@douyinfe/semi-icons";
5
7
  import { InjectVariableSelector } from "../variable-selector/index.mjs";
6
8
  import { InjectDynamicValueInput } from "../dynamic-value-input/index.mjs";
9
+ import { useCondition } from "../condition-context/index.mjs";
7
10
  import { UIContainer, UILeft, UIOperator, UIRight, UIValues } from "./styles.mjs";
8
- import { useRule } from "./hooks/useRule.mjs";
9
- import { useOp } from "./hooks/useOp.mjs";
10
- import { defaultOpConfigs, defaultRules } from "./constants.mjs";
11
11
  const defaultRuleConfig = {
12
12
  ops: {},
13
13
  rules: {}
14
14
  };
15
15
  function ConditionRow({ style, value, onChange, readonly, ruleConfig = defaultRuleConfig }) {
16
16
  const { left, operator, right } = value || {};
17
- const { rule } = useRule(left, ruleConfig.rules);
18
- const { renderOpSelect, opConfig } = useOp({
19
- rule,
20
- op: operator,
21
- onChange: (v)=>onChange({
22
- ...value,
23
- operator: v
24
- }),
25
- readonly,
26
- userOps: ruleConfig.ops
27
- });
28
- const targetSchema = useMemo(()=>{
29
- const targetType = rule?.[operator || ''] || null;
30
- return targetType ? {
31
- type: targetType,
32
- extra: {
33
- weak: true
34
- }
35
- } : null;
17
+ const available = useScopeAvailable();
18
+ const variable = useMemo(()=>{
19
+ if (!left) return;
20
+ return available.getByKeyPath(left.content);
21
+ }, [
22
+ available,
23
+ left
24
+ ]);
25
+ const leftSchema = useMemo(()=>{
26
+ if (!variable) return;
27
+ return JsonSchemaUtils.astToSchema(variable.type, {
28
+ drilldown: false
29
+ });
36
30
  }, [
37
- rule,
38
- opConfig
31
+ variable?.type?.hash
39
32
  ]);
33
+ const { rule, opConfig, opOptionList, targetSchema } = useCondition({
34
+ leftSchema,
35
+ operator
36
+ });
37
+ const renderOpSelect = ()=>/*#__PURE__*/ jsx(Select, {
38
+ style: {
39
+ height: 22
40
+ },
41
+ disabled: readonly,
42
+ size: "small",
43
+ value: operator,
44
+ optionList: opOptionList,
45
+ onChange: (v)=>{
46
+ onChange({
47
+ ...value,
48
+ operator: v
49
+ });
50
+ },
51
+ triggerRender: ({ value })=>/*#__PURE__*/ jsx(Button, {
52
+ size: "small",
53
+ disabled: !rule,
54
+ children: opConfig?.abbreviation || /*#__PURE__*/ jsx(IconChevronDownStroked, {
55
+ size: "small"
56
+ })
57
+ })
58
+ });
40
59
  return /*#__PURE__*/ jsxs(UIContainer, {
41
60
  style: style,
42
61
  children: [
@@ -84,6 +103,4 @@ function ConditionRow({ style, value, onChange, readonly, ruleConfig = defaultRu
84
103
  ]
85
104
  });
86
105
  }
87
- ConditionRow.defaultRules = defaultRules;
88
- ConditionRow.defaultOpConfigs = defaultOpConfigs;
89
106
  export { ConditionRow };
@@ -1,18 +0,0 @@
1
- var types_Op = /*#__PURE__*/ function(Op) {
2
- Op["EQ"] = "eq";
3
- Op["NEQ"] = "neq";
4
- Op["GT"] = "gt";
5
- Op["GTE"] = "gte";
6
- Op["LT"] = "lt";
7
- Op["LTE"] = "lte";
8
- Op["IN"] = "in";
9
- Op["NIN"] = "nin";
10
- Op["CONTAINS"] = "contains";
11
- Op["NOT_CONTAINS"] = "not_contains";
12
- Op["IS_EMPTY"] = "is_empty";
13
- Op["IS_NOT_EMPTY"] = "is_not_empty";
14
- Op["IS_TRUE"] = "is_true";
15
- Op["IS_FALSE"] = "is_false";
16
- return Op;
17
- }({});
18
- export { types_Op as Op };
@@ -30,9 +30,10 @@ class VariableTagWidget extends WidgetType {
30
30
  color: "amber",
31
31
  children: "Unknown"
32
32
  }));
33
- const rootField = last(v.parentFields);
33
+ const rootField = last(v.parentFields) || v;
34
+ const isRoot = v === rootField;
34
35
  const rootTitle = /*#__PURE__*/ jsx(UIRootTitle, {
35
- children: rootField?.meta.title ? `${rootField.meta.title} -` : ''
36
+ children: rootField.meta?.title ? `${rootField.meta.title} ${isRoot ? '' : '-'} ` : ''
36
37
  });
37
38
  const rootIcon = this.renderIcon(rootField?.meta.icon);
38
39
  this.root.render(/*#__PURE__*/ jsx(Popover, {
@@ -49,7 +50,7 @@ class VariableTagWidget extends WidgetType {
49
50
  prefixIcon: rootIcon,
50
51
  children: [
51
52
  rootTitle,
52
- /*#__PURE__*/ jsx(UIVarName, {
53
+ !isRoot && /*#__PURE__*/ jsx(UIVarName, {
53
54
  children: v?.key
54
55
  })
55
56
  ]
@@ -56,6 +56,9 @@ function VariableTree({ triggerCharacters = DEFAULT_TRIGGER_CHARACTER }) {
56
56
  },
57
57
  children: /*#__PURE__*/ jsx(Tree, {
58
58
  treeData: treeData,
59
+ onExpand: (v)=>{
60
+ setPosKey(String(Math.random()));
61
+ },
59
62
  onSelect: (v)=>{
60
63
  insert(v);
61
64
  }