@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.
- package/dist/cjs/components/code-editor/editor.js +54 -77
- package/dist/cjs/components/code-editor/index.js +10 -2
- package/dist/cjs/components/code-editor/language-features.js +119 -16
- package/dist/cjs/components/code-editor/theme/dark.js +120 -50
- package/dist/cjs/components/code-editor/theme/light.js +110 -61
- package/dist/cjs/components/condition-context/context.js +59 -0
- package/dist/cjs/components/condition-context/hooks/use-condition.js +97 -0
- package/dist/cjs/components/condition-context/index.js +47 -0
- package/dist/cjs/components/condition-context/op.js +117 -0
- package/dist/cjs/components/condition-row/index.js +43 -26
- package/dist/cjs/components/condition-row/types.js +1 -35
- package/dist/cjs/components/coze-editor-extensions/extensions/variable-tag.js +4 -3
- package/dist/cjs/components/coze-editor-extensions/extensions/variable-tree.js +3 -0
- package/dist/cjs/components/db-condition-row/index.js +59 -34
- package/dist/cjs/form-plugins/infer-inputs-plugin/index.js +30 -3
- package/dist/cjs/plugins/json-schema-preset/create-type-preset-plugin.js +1 -0
- package/dist/cjs/plugins/json-schema-preset/react.js +1 -0
- package/dist/cjs/plugins/json-schema-preset/type-definition/array.js +30 -1
- package/dist/cjs/plugins/json-schema-preset/type-definition/boolean.js +23 -0
- package/dist/cjs/plugins/json-schema-preset/type-definition/date-time.js +31 -2
- package/dist/cjs/plugins/json-schema-preset/type-definition/index.js +9 -1
- package/dist/cjs/plugins/json-schema-preset/type-definition/integer.js +34 -1
- package/dist/cjs/{components/code-editor/init-worker.js → plugins/json-schema-preset/type-definition/map.js} +21 -23
- package/dist/cjs/plugins/json-schema-preset/type-definition/number.js +34 -1
- package/dist/cjs/plugins/json-schema-preset/type-definition/object.js +6 -1
- package/dist/cjs/plugins/json-schema-preset/type-definition/string.js +30 -1
- package/dist/cjs/plugins/json-schema-preset/types.js +18 -0
- package/dist/cjs/shared/flow-value/utils.js +22 -8
- package/dist/esm/components/code-editor/editor.mjs +4 -9
- package/dist/esm/components/code-editor/index.mjs +5 -2
- package/dist/esm/components/code-editor/language-features.mjs +49 -13
- package/dist/esm/components/code-editor/theme/dark.mjs +117 -50
- package/dist/esm/components/code-editor/theme/light.mjs +108 -62
- package/dist/esm/components/condition-context/context.mjs +19 -0
- package/dist/esm/components/condition-context/hooks/use-condition.mjs +63 -0
- package/dist/esm/components/condition-context/index.mjs +4 -0
- package/dist/esm/components/condition-context/op.mjs +80 -0
- package/dist/esm/components/condition-row/index.mjs +45 -28
- package/dist/esm/components/condition-row/types.mjs +0 -18
- package/dist/esm/components/coze-editor-extensions/extensions/variable-tag.mjs +4 -3
- package/dist/esm/components/coze-editor-extensions/extensions/variable-tree.mjs +3 -0
- package/dist/esm/components/db-condition-row/index.mjs +59 -34
- package/dist/esm/form-plugins/infer-inputs-plugin/index.mjs +31 -4
- package/dist/esm/plugins/json-schema-preset/create-type-preset-plugin.mjs +2 -1
- package/dist/esm/plugins/json-schema-preset/react.mjs +2 -1
- package/dist/esm/plugins/json-schema-preset/type-definition/array.mjs +30 -1
- package/dist/esm/plugins/json-schema-preset/type-definition/boolean.mjs +23 -0
- package/dist/esm/plugins/json-schema-preset/type-definition/date-time.mjs +31 -2
- package/dist/esm/plugins/json-schema-preset/type-definition/index.mjs +7 -2
- package/dist/esm/plugins/json-schema-preset/type-definition/integer.mjs +34 -1
- package/dist/esm/plugins/json-schema-preset/type-definition/map.mjs +20 -0
- package/dist/esm/plugins/json-schema-preset/type-definition/number.mjs +34 -1
- package/dist/esm/plugins/json-schema-preset/type-definition/object.mjs +6 -1
- package/dist/esm/plugins/json-schema-preset/type-definition/string.mjs +30 -1
- package/dist/esm/plugins/json-schema-preset/types.mjs +0 -0
- package/dist/esm/shared/flow-value/utils.mjs +22 -8
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/components/code-editor/editor.d.ts +0 -2
- package/dist/types/components/code-editor/language-features.d.ts +4 -1
- package/dist/types/components/code-editor/theme/dark.d.ts +29 -0
- package/dist/types/components/code-editor/theme/light.d.ts +24 -0
- package/dist/types/components/condition-context/context.d.ts +14 -0
- package/dist/types/components/condition-context/hooks/use-condition.d.ts +29 -0
- package/dist/types/components/condition-context/index.d.ts +8 -0
- package/dist/types/components/condition-context/op.d.ts +22 -0
- package/dist/types/components/condition-context/types.d.ts +14 -0
- package/dist/types/components/condition-row/index.d.ts +4 -7
- package/dist/types/components/condition-row/types.d.ts +0 -24
- package/dist/types/components/db-condition-row/index.d.ts +4 -3
- package/dist/types/components/db-condition-row/types.d.ts +0 -8
- package/dist/types/form-plugins/infer-inputs-plugin/index.d.ts +4 -0
- package/dist/types/plugins/json-schema-preset/create-type-preset-plugin.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/index.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/react.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/type-definition/array.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/type-definition/boolean.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/type-definition/date-time.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/type-definition/index.d.ts +3 -1
- package/dist/types/plugins/json-schema-preset/type-definition/integer.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/type-definition/map.d.ts +6 -0
- package/dist/types/plugins/json-schema-preset/type-definition/number.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/type-definition/object.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/type-definition/string.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/{manager.d.ts → types.d.ts} +5 -0
- package/dist/types/shared/flow-value/utils.d.ts +3 -1
- package/package.json +7 -6
- package/src/components/code-editor/editor.tsx +7 -10
- package/src/components/code-editor/index.tsx +3 -1
- package/src/components/code-editor/language-features.ts +52 -14
- package/src/components/code-editor/theme/dark.ts +62 -77
- package/src/components/code-editor/theme/light.ts +60 -91
- package/src/components/condition-context/context.tsx +28 -0
- package/src/components/condition-context/hooks/use-condition.tsx +99 -0
- package/src/components/condition-context/index.tsx +14 -0
- package/src/components/condition-context/op.ts +86 -0
- package/src/components/condition-context/types.ts +22 -0
- package/src/components/condition-row/index.tsx +44 -22
- package/src/components/condition-row/types.ts +0 -30
- package/src/components/coze-editor-extensions/extensions/variable-tag.tsx +6 -3
- package/src/components/coze-editor-extensions/extensions/variable-tree.tsx +3 -0
- package/src/components/db-condition-row/index.tsx +76 -24
- package/src/components/db-condition-row/types.ts +0 -13
- package/src/form-plugins/infer-inputs-plugin/index.ts +62 -14
- package/src/plugins/json-schema-preset/create-type-preset-plugin.tsx +4 -2
- package/src/plugins/json-schema-preset/index.tsx +1 -1
- package/src/plugins/json-schema-preset/react.tsx +5 -2
- package/src/plugins/json-schema-preset/type-definition/array.tsx +10 -1
- package/src/plugins/json-schema-preset/type-definition/boolean.tsx +17 -1
- package/src/plugins/json-schema-preset/type-definition/date-time.tsx +21 -2
- package/src/plugins/json-schema-preset/type-definition/index.tsx +10 -1
- package/src/plugins/json-schema-preset/type-definition/integer.tsx +19 -1
- package/src/plugins/json-schema-preset/type-definition/map.tsx +31 -0
- package/src/plugins/json-schema-preset/type-definition/number.tsx +19 -1
- package/src/plugins/json-schema-preset/type-definition/object.tsx +6 -1
- package/src/plugins/json-schema-preset/type-definition/string.tsx +19 -1
- package/src/plugins/json-schema-preset/{manager.ts → types.ts} +7 -0
- package/src/shared/flow-value/utils.ts +22 -9
- package/dist/cjs/components/condition-row/constants.js +0 -165
- package/dist/cjs/components/condition-row/hooks/useOp.js +0 -78
- package/dist/cjs/components/condition-row/hooks/useRule.js +0 -68
- package/dist/cjs/components/db-condition-row/hooks/use-left.js +0 -86
- package/dist/cjs/components/db-condition-row/hooks/use-op.js +0 -79
- package/dist/esm/components/code-editor/init-worker.mjs +0 -19
- package/dist/esm/components/condition-row/constants.mjs +0 -128
- package/dist/esm/components/condition-row/hooks/useOp.mjs +0 -44
- package/dist/esm/components/condition-row/hooks/useRule.mjs +0 -34
- package/dist/esm/components/db-condition-row/hooks/use-left.mjs +0 -52
- package/dist/esm/components/db-condition-row/hooks/use-op.mjs +0 -45
- package/dist/types/components/code-editor/init-worker.d.ts +0 -5
- package/dist/types/components/condition-row/constants.d.ts +0 -7
- package/dist/types/components/condition-row/hooks/useOp.d.ts +0 -18
- package/dist/types/components/condition-row/hooks/useRule.d.ts +0 -9
- package/dist/types/components/db-condition-row/hooks/use-left.d.ts +0 -18
- package/dist/types/components/db-condition-row/hooks/use-op.d.ts +0 -18
- package/src/components/code-editor/init-worker.ts +0 -27
- package/src/components/condition-row/constants.ts +0 -134
- package/src/components/condition-row/hooks/useOp.tsx +0 -56
- package/src/components/condition-row/hooks/useRule.ts +0 -35
- package/src/components/db-condition-row/hooks/use-left.tsx +0 -66
- package/src/components/db-condition-row/hooks/use-op.tsx +0 -59
- /package/dist/cjs/{plugins/json-schema-preset/manager.js → components/condition-context/types.js} +0 -0
- /package/dist/esm/{plugins/json-schema-preset/manager.mjs → components/condition-context/types.mjs} +0 -0
|
@@ -1,46 +1,62 @@
|
|
|
1
1
|
import { createTheme, tags } from "@flowgram.ai/coze-editor/preset-code";
|
|
2
2
|
const colors = {
|
|
3
|
-
background: '#
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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:
|
|
17
|
-
foreground:
|
|
18
|
-
caret:
|
|
19
|
-
selection:
|
|
20
|
-
gutterBackground:
|
|
21
|
-
gutterForeground:
|
|
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:
|
|
37
|
+
lineHighlight: colors.background,
|
|
25
38
|
bracketColors: [
|
|
26
39
|
'#F59E0B',
|
|
27
40
|
'#8B5CF6',
|
|
28
41
|
'#06B6D4'
|
|
29
42
|
],
|
|
30
43
|
tooltip: {
|
|
31
|
-
backgroundColor:
|
|
32
|
-
color:
|
|
33
|
-
border: '
|
|
34
|
-
boxShadow: '0
|
|
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:
|
|
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.
|
|
61
|
-
color: colors.
|
|
76
|
+
tag: tags.keyword,
|
|
77
|
+
color: colors.keyword
|
|
62
78
|
},
|
|
63
79
|
{
|
|
64
80
|
tag: [
|
|
65
|
-
tags.
|
|
81
|
+
tags.name,
|
|
82
|
+
tags.deleted,
|
|
83
|
+
tags.character,
|
|
84
|
+
tags.macroName
|
|
66
85
|
],
|
|
67
|
-
color: colors.
|
|
86
|
+
color: colors.variable
|
|
68
87
|
},
|
|
69
88
|
{
|
|
70
89
|
tag: [
|
|
71
|
-
tags.
|
|
90
|
+
tags.propertyName
|
|
72
91
|
],
|
|
73
|
-
color: colors.
|
|
92
|
+
color: colors.function
|
|
74
93
|
},
|
|
75
94
|
{
|
|
76
95
|
tag: [
|
|
77
|
-
tags.
|
|
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.
|
|
105
|
+
tags["function"](tags.variableName),
|
|
106
|
+
tags.labelName
|
|
84
107
|
],
|
|
85
|
-
color: colors.
|
|
108
|
+
color: colors.function
|
|
86
109
|
},
|
|
87
110
|
{
|
|
88
111
|
tag: [
|
|
89
|
-
tags.
|
|
112
|
+
tags.color,
|
|
113
|
+
tags.constant(tags.name),
|
|
114
|
+
tags.standard(tags.name)
|
|
90
115
|
],
|
|
91
|
-
color: colors.
|
|
116
|
+
color: colors.constant
|
|
92
117
|
},
|
|
93
118
|
{
|
|
94
119
|
tag: [
|
|
95
|
-
tags
|
|
120
|
+
tags.definition(tags.name),
|
|
121
|
+
tags.separator
|
|
96
122
|
],
|
|
97
|
-
color: colors.
|
|
123
|
+
color: colors.variable
|
|
98
124
|
},
|
|
99
125
|
{
|
|
100
126
|
tag: [
|
|
101
|
-
tags.
|
|
127
|
+
tags.className
|
|
102
128
|
],
|
|
103
|
-
color: colors.
|
|
129
|
+
color: colors.class
|
|
104
130
|
},
|
|
105
131
|
{
|
|
106
132
|
tag: [
|
|
107
|
-
tags.
|
|
133
|
+
tags.number,
|
|
134
|
+
tags.changed,
|
|
135
|
+
tags.annotation,
|
|
136
|
+
tags.modifier,
|
|
137
|
+
tags.self,
|
|
138
|
+
tags.namespace
|
|
108
139
|
],
|
|
109
|
-
color:
|
|
140
|
+
color: colors.number
|
|
110
141
|
},
|
|
111
142
|
{
|
|
112
143
|
tag: [
|
|
113
|
-
tags.
|
|
144
|
+
tags.typeName
|
|
114
145
|
],
|
|
115
|
-
color:
|
|
146
|
+
color: colors.type,
|
|
147
|
+
fontStyle: colors.type
|
|
116
148
|
},
|
|
117
149
|
{
|
|
118
150
|
tag: [
|
|
119
|
-
tags.
|
|
151
|
+
tags.operator,
|
|
152
|
+
tags.operatorKeyword
|
|
120
153
|
],
|
|
121
|
-
color:
|
|
154
|
+
color: colors.keyword
|
|
122
155
|
},
|
|
123
156
|
{
|
|
124
157
|
tag: [
|
|
125
|
-
tags.
|
|
158
|
+
tags.url,
|
|
159
|
+
tags.escape,
|
|
160
|
+
tags.regexp,
|
|
161
|
+
tags.link
|
|
126
162
|
],
|
|
127
|
-
color:
|
|
163
|
+
color: colors.regexp
|
|
128
164
|
},
|
|
129
165
|
{
|
|
130
166
|
tag: [
|
|
131
|
-
tags.
|
|
167
|
+
tags.meta,
|
|
168
|
+
tags.comment
|
|
132
169
|
],
|
|
133
|
-
color:
|
|
170
|
+
color: colors.comment
|
|
134
171
|
},
|
|
135
172
|
{
|
|
136
|
-
tag:
|
|
137
|
-
|
|
138
|
-
],
|
|
139
|
-
color: '#9333EA'
|
|
173
|
+
tag: tags.strong,
|
|
174
|
+
fontWeight: 'bold'
|
|
140
175
|
},
|
|
141
176
|
{
|
|
142
|
-
tag:
|
|
143
|
-
|
|
144
|
-
],
|
|
145
|
-
color: '#059669'
|
|
177
|
+
tag: tags.emphasis,
|
|
178
|
+
fontStyle: 'italic'
|
|
146
179
|
},
|
|
147
180
|
{
|
|
148
|
-
tag:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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.
|
|
191
|
+
tags.atom,
|
|
192
|
+
tags.bool,
|
|
193
|
+
tags.special(tags.variableName)
|
|
156
194
|
],
|
|
157
|
-
color:
|
|
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,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 {
|
|
4
|
-
import {
|
|
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
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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?.
|
|
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
|
]
|