@genesislcap/foundation-ui 14.247.2 → 14.249.0
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/custom-elements.json +3729 -3001
- package/dist/dts/expression-builder/expression-builder.d.ts +11 -0
- package/dist/dts/expression-builder/expression-builder.d.ts.map +1 -0
- package/dist/dts/expression-builder/index.d.ts +4 -0
- package/dist/dts/expression-builder/index.d.ts.map +1 -0
- package/dist/dts/expression-builder/rule-expression-builder.d.ts +181 -0
- package/dist/dts/expression-builder/rule-expression-builder.d.ts.map +1 -0
- package/dist/dts/expression-builder/types.d.ts +104 -0
- package/dist/dts/expression-builder/types.d.ts.map +1 -0
- package/dist/dts/index.d.ts +5 -4
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/esm/expression-builder/expression-builder.js +20 -0
- package/dist/esm/expression-builder/index.js +3 -0
- package/dist/esm/expression-builder/rule-expression-builder.js +540 -0
- package/dist/esm/expression-builder/types.js +21 -0
- package/dist/esm/index.js +5 -4
- package/package.json +18 -17
|
@@ -0,0 +1,540 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { ExpressionBuilder, template, styles, formatDateString, formatDateTimeString, } from '@genesislcap/expression-builder';
|
|
3
|
+
import { customElement, observable } from '@microsoft/fast-element';
|
|
4
|
+
import { RuleExpression } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* CONFIG
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Combinators for the server expression
|
|
10
|
+
* @internal
|
|
11
|
+
**/
|
|
12
|
+
const logicalCombinators = [
|
|
13
|
+
{
|
|
14
|
+
type: RuleExpression.logicalOperations.AND,
|
|
15
|
+
maxRules: 'many',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
type: RuleExpression.logicalOperations.OR,
|
|
19
|
+
maxRules: 'many',
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* Operator names for the server expression
|
|
24
|
+
* Mapped to the RuleExpression names where possible
|
|
25
|
+
* @internal
|
|
26
|
+
**/
|
|
27
|
+
export const clientOperators = {
|
|
28
|
+
EQUALS: RuleExpression.operations.EQUALS,
|
|
29
|
+
NOT_EQUALS: RuleExpression.operations.NOT_EQUALS,
|
|
30
|
+
IS_NULL: 'IS_NULL',
|
|
31
|
+
NOT_NULL: 'NOT_NULL',
|
|
32
|
+
IS_BLANK: 'IS_BLANK',
|
|
33
|
+
NOT_BLANK: 'NOT_BLANK',
|
|
34
|
+
CONTAINS_IGNORE_CASE: 'CONTAINS_IGNORE_CASE',
|
|
35
|
+
CONTAINS_WORDS_STARTING_WITH_IGNORE_CASE: 'CONTAINS_WORDS_STARTING_WITH_IGNORE_CASE',
|
|
36
|
+
CONTAINS_WORDS_STARTING_WITH_IGNORE_CASE_WITH_DELIMITER: 'CONTAINS_WORDS_STARTING_WITH_IGNORE_CASE_WITH_DELIMITER',
|
|
37
|
+
GREATER_THAN: RuleExpression.operations.GREATER_THAN,
|
|
38
|
+
GREATER_THAN_OR_EQUAL: RuleExpression.operations.GREATER_THAN_OR_EQUAL,
|
|
39
|
+
LESS_THAN: RuleExpression.operations.LESS_THAN,
|
|
40
|
+
LESS_THAN_OR_EQUAL: RuleExpression.operations.LESS_THAN_OR_EQUAL,
|
|
41
|
+
IS_BEFORE: 'IS_BEFORE',
|
|
42
|
+
IS_AFTER: 'IS_AFTER',
|
|
43
|
+
ON_OR_BEFORE: 'ON_OR_BEFORE',
|
|
44
|
+
ON_OR_AFTER: 'ON_OR_AFTER',
|
|
45
|
+
};
|
|
46
|
+
const intTypes = ['int', 'short', 'long'];
|
|
47
|
+
const floatTypes = ['double', 'bigdecimal'];
|
|
48
|
+
const numberTypes = [...intTypes, ...floatTypes];
|
|
49
|
+
const dateTypes = ['date', 'date-time'];
|
|
50
|
+
const stringTypes = ['string', 'enum'];
|
|
51
|
+
const booleanTypes = ['boolean'];
|
|
52
|
+
/**
|
|
53
|
+
* Operators for the server expression
|
|
54
|
+
* @internal
|
|
55
|
+
**/
|
|
56
|
+
const logicalOperators = [
|
|
57
|
+
{
|
|
58
|
+
type: clientOperators.EQUALS,
|
|
59
|
+
nbInputs: 1,
|
|
60
|
+
applyTo: [...stringTypes, ...booleanTypes, ...numberTypes, ...dateTypes],
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
type: clientOperators.NOT_EQUALS,
|
|
64
|
+
nbInputs: 1,
|
|
65
|
+
applyTo: [...stringTypes, ...booleanTypes, ...numberTypes, ...dateTypes],
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
type: clientOperators.IS_NULL,
|
|
69
|
+
nbInputs: 0,
|
|
70
|
+
applyTo: [...stringTypes, ...booleanTypes, ...numberTypes, ...dateTypes],
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
type: clientOperators.NOT_NULL,
|
|
74
|
+
nbInputs: 0,
|
|
75
|
+
applyTo: [...stringTypes, ...booleanTypes, ...numberTypes, ...dateTypes],
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
type: clientOperators.IS_BLANK,
|
|
79
|
+
nbInputs: 0,
|
|
80
|
+
applyTo: ['string'],
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
type: clientOperators.NOT_BLANK,
|
|
84
|
+
nbInputs: 0,
|
|
85
|
+
applyTo: ['string'],
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
type: clientOperators.CONTAINS_IGNORE_CASE,
|
|
89
|
+
nbInputs: 1,
|
|
90
|
+
applyTo: ['string'],
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
type: clientOperators.CONTAINS_WORDS_STARTING_WITH_IGNORE_CASE,
|
|
94
|
+
nbInputs: 1,
|
|
95
|
+
applyTo: ['string'],
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
type: clientOperators.CONTAINS_WORDS_STARTING_WITH_IGNORE_CASE_WITH_DELIMITER,
|
|
99
|
+
nbInputs: 1,
|
|
100
|
+
applyTo: ['string'],
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
type: clientOperators.GREATER_THAN,
|
|
104
|
+
nbInputs: 1,
|
|
105
|
+
applyTo: [...numberTypes],
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
type: clientOperators.GREATER_THAN_OR_EQUAL,
|
|
109
|
+
nbInputs: 1,
|
|
110
|
+
applyTo: [...numberTypes],
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
type: clientOperators.LESS_THAN,
|
|
114
|
+
nbInputs: 1,
|
|
115
|
+
applyTo: [...numberTypes],
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
type: clientOperators.LESS_THAN_OR_EQUAL,
|
|
119
|
+
nbInputs: 1,
|
|
120
|
+
applyTo: [...numberTypes],
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
type: clientOperators.IS_BEFORE,
|
|
124
|
+
nbInputs: 1,
|
|
125
|
+
applyTo: [...dateTypes],
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
type: clientOperators.IS_AFTER,
|
|
129
|
+
nbInputs: 1,
|
|
130
|
+
applyTo: [...dateTypes],
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
type: clientOperators.ON_OR_BEFORE,
|
|
134
|
+
nbInputs: 1,
|
|
135
|
+
applyTo: [...dateTypes],
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
type: clientOperators.ON_OR_AFTER,
|
|
139
|
+
nbInputs: 1,
|
|
140
|
+
applyTo: [...dateTypes],
|
|
141
|
+
},
|
|
142
|
+
];
|
|
143
|
+
/**
|
|
144
|
+
* Convert from Expression builder to Genesis
|
|
145
|
+
*/
|
|
146
|
+
/**
|
|
147
|
+
* Converts a client BinaryOperator to a server BinaryExpression
|
|
148
|
+
*
|
|
149
|
+
* The opposite of `fromBinaryExpression`
|
|
150
|
+
* @internal
|
|
151
|
+
**/
|
|
152
|
+
export function toBinaryExpression(rule, OPERATION, TYPE) {
|
|
153
|
+
if (!('value' in rule))
|
|
154
|
+
return null;
|
|
155
|
+
return {
|
|
156
|
+
TYPE: 'BINARY_EXPRESSION',
|
|
157
|
+
LEFT: {
|
|
158
|
+
TYPE: 'FIELD',
|
|
159
|
+
NAME: rule.field.fieldId,
|
|
160
|
+
},
|
|
161
|
+
OPERATION,
|
|
162
|
+
RIGHT: {
|
|
163
|
+
TYPE,
|
|
164
|
+
VALUE: rule.value,
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Converts a client BinaryOperator to a server BinaryExpression
|
|
170
|
+
*
|
|
171
|
+
* The opposite of `fromBinaryExpression`
|
|
172
|
+
*
|
|
173
|
+
* @privateRemarks
|
|
174
|
+
* Used in specific cases where a server operation doesn't map nicely to a client one,
|
|
175
|
+
* such as IS_NULL being a client UniraryOperation but a server BinaryExpression
|
|
176
|
+
* @internal
|
|
177
|
+
**/
|
|
178
|
+
export function toSetValueBinaryExpression(rule, OPERATION, RIGHT) {
|
|
179
|
+
return {
|
|
180
|
+
TYPE: 'BINARY_EXPRESSION',
|
|
181
|
+
LEFT: {
|
|
182
|
+
TYPE: 'FIELD',
|
|
183
|
+
NAME: rule.field.fieldId,
|
|
184
|
+
},
|
|
185
|
+
OPERATION,
|
|
186
|
+
RIGHT,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Converts a client BinaryOperator to a server MethodExpression
|
|
191
|
+
*
|
|
192
|
+
* The opposite of `fromMethodExpression`
|
|
193
|
+
*
|
|
194
|
+
* @internal
|
|
195
|
+
**/
|
|
196
|
+
export function toMethodExpression(rule, METHOD, extraParams = []) {
|
|
197
|
+
if (!('value' in rule))
|
|
198
|
+
return null;
|
|
199
|
+
return {
|
|
200
|
+
TYPE: 'METHOD_EXPRESSION',
|
|
201
|
+
PARAMETERS: [
|
|
202
|
+
{
|
|
203
|
+
TYPE: 'FIELD',
|
|
204
|
+
NAME: rule.field.fieldId,
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
TYPE: 'STRING',
|
|
208
|
+
VALUE: rule.value,
|
|
209
|
+
},
|
|
210
|
+
...extraParams,
|
|
211
|
+
],
|
|
212
|
+
METHOD,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Converts a client field type to a server expression type
|
|
217
|
+
*
|
|
218
|
+
* @internal
|
|
219
|
+
**/
|
|
220
|
+
export function mapFieldTypeToRuleExpressionType(rule) {
|
|
221
|
+
switch (rule.field.type) {
|
|
222
|
+
case 'int':
|
|
223
|
+
case 'long':
|
|
224
|
+
case 'double':
|
|
225
|
+
case 'bigdecimal':
|
|
226
|
+
case 'date':
|
|
227
|
+
case 'date-time':
|
|
228
|
+
case 'short':
|
|
229
|
+
return 'NUMBER';
|
|
230
|
+
case 'string':
|
|
231
|
+
case 'enum':
|
|
232
|
+
return 'STRING';
|
|
233
|
+
case 'boolean':
|
|
234
|
+
return 'BOOLEAN';
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
export const MILLIS_TO_SECONDS = 1000;
|
|
238
|
+
/**
|
|
239
|
+
* Converts a client field value to a server field value
|
|
240
|
+
*
|
|
241
|
+
* The opposite to `rebuildRuleValue`
|
|
242
|
+
*
|
|
243
|
+
* @privateRemarks
|
|
244
|
+
* `string` (+`enum`) and `boolean` types are left as they are
|
|
245
|
+
* `number` types are converted to string due to the limitation of BigDecimal values from the server
|
|
246
|
+
* `date` and `datetime-local` converted to epoch time as the server works with numbers
|
|
247
|
+
*
|
|
248
|
+
* @internal
|
|
249
|
+
**/
|
|
250
|
+
export function transformRuleValue(rule) {
|
|
251
|
+
const transform = (value) => {
|
|
252
|
+
if (stringTypes.includes(rule.field.type))
|
|
253
|
+
return value;
|
|
254
|
+
if (numberTypes.includes(rule.field.type))
|
|
255
|
+
return value.toString(); // Handle as bigdecimal
|
|
256
|
+
if (booleanTypes.includes(rule.field.type))
|
|
257
|
+
return value;
|
|
258
|
+
if (Array.isArray(value))
|
|
259
|
+
throw new Error(`Not implemented TernararyOperator or VariadicOperator args in rule value transformer`);
|
|
260
|
+
if (dateTypes.includes(rule.field.type)) {
|
|
261
|
+
return (new Date(value).getTime() / MILLIS_TO_SECONDS).toString(); // Handle as bigdecimal
|
|
262
|
+
}
|
|
263
|
+
throw new Error('Unhandled transformRuleValue case');
|
|
264
|
+
};
|
|
265
|
+
const validRule = !(!('value' in rule) ||
|
|
266
|
+
typeof rule.value === 'undefined' ||
|
|
267
|
+
rule.value === null);
|
|
268
|
+
return Object.assign(Object.assign({}, rule), (validRule ? { value: transform(rule.value) } : {}));
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Converts a client operator name to a server operator name
|
|
272
|
+
*
|
|
273
|
+
* The opposite to `transformServerNameToOperatorName`
|
|
274
|
+
*
|
|
275
|
+
* @privateRemarks
|
|
276
|
+
* Most names are the same, but this handles cases where date comparison operator names are different
|
|
277
|
+
* on the display to their server name
|
|
278
|
+
*
|
|
279
|
+
* TODO: We could clean this up if we support labels/aliases on the client component
|
|
280
|
+
*
|
|
281
|
+
* @internal
|
|
282
|
+
**/
|
|
283
|
+
export function transformOperatorNameToServerName(op) {
|
|
284
|
+
switch (op) {
|
|
285
|
+
case 'IS_BEFORE':
|
|
286
|
+
return 'LESS_THAN';
|
|
287
|
+
case 'IS_AFTER':
|
|
288
|
+
return 'GREATER_THAN';
|
|
289
|
+
case 'ON_OR_BEFORE':
|
|
290
|
+
return 'LESS_THAN_OR_EQUAL';
|
|
291
|
+
case 'ON_OR_AFTER':
|
|
292
|
+
return 'GREATER_THAN_OR_EQUAL';
|
|
293
|
+
default:
|
|
294
|
+
return op;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Converts a client `Rule` into the correct server `Expression`
|
|
299
|
+
*
|
|
300
|
+
* @privateRemarks
|
|
301
|
+
* The server doesn't have a concept for a partial expression so if the user doesn't fill out all values
|
|
302
|
+
* (e.g. chooses a field but not an operator) that would be lost via this process
|
|
303
|
+
*
|
|
304
|
+
* @internal
|
|
305
|
+
**/
|
|
306
|
+
export function ruleToRuleExpression(ruleInput) {
|
|
307
|
+
var _a, _b;
|
|
308
|
+
// If the user hasn't fully filled out the rule then we just ignore it for the condition
|
|
309
|
+
if (!(((_a = ruleInput.operator) === null || _a === void 0 ? void 0 : _a.type) && ((_b = ruleInput.field) === null || _b === void 0 ? void 0 : _b.fieldId)))
|
|
310
|
+
return null;
|
|
311
|
+
const rule = transformRuleValue(ruleInput);
|
|
312
|
+
const rhsType = mapFieldTypeToRuleExpressionType(rule);
|
|
313
|
+
const operatorName = transformOperatorNameToServerName(rule.operator.type);
|
|
314
|
+
switch (operatorName) {
|
|
315
|
+
case clientOperators.EQUALS:
|
|
316
|
+
case clientOperators.NOT_EQUALS:
|
|
317
|
+
case clientOperators.GREATER_THAN:
|
|
318
|
+
case clientOperators.GREATER_THAN_OR_EQUAL:
|
|
319
|
+
case clientOperators.LESS_THAN:
|
|
320
|
+
case clientOperators.LESS_THAN_OR_EQUAL:
|
|
321
|
+
return toBinaryExpression(rule, operatorName, rhsType);
|
|
322
|
+
case clientOperators.IS_NULL:
|
|
323
|
+
return toSetValueBinaryExpression(rule, RuleExpression.operations.EQUALS, { TYPE: 'NULL' });
|
|
324
|
+
case clientOperators.NOT_NULL:
|
|
325
|
+
return toSetValueBinaryExpression(rule, RuleExpression.operations.NOT_EQUALS, {
|
|
326
|
+
TYPE: 'NULL',
|
|
327
|
+
});
|
|
328
|
+
case clientOperators.IS_BLANK:
|
|
329
|
+
return toSetValueBinaryExpression(rule, RuleExpression.operations.EQUALS, {
|
|
330
|
+
TYPE: 'STRING',
|
|
331
|
+
VALUE: '',
|
|
332
|
+
});
|
|
333
|
+
case clientOperators.NOT_BLANK:
|
|
334
|
+
return toSetValueBinaryExpression(rule, RuleExpression.operations.NOT_EQUALS, {
|
|
335
|
+
TYPE: 'STRING',
|
|
336
|
+
VALUE: '',
|
|
337
|
+
});
|
|
338
|
+
case clientOperators.CONTAINS_IGNORE_CASE:
|
|
339
|
+
return toMethodExpression(rule, RuleExpression.methodCall.CONTAINS_IGNORE_CASE);
|
|
340
|
+
case clientOperators.CONTAINS_WORDS_STARTING_WITH_IGNORE_CASE:
|
|
341
|
+
return toMethodExpression(rule, RuleExpression.methodCall.CONTAINS_WORDS_STARTING_WITH_IGNORE_CASE);
|
|
342
|
+
case clientOperators.CONTAINS_WORDS_STARTING_WITH_IGNORE_CASE_WITH_DELIMITER:
|
|
343
|
+
return toMethodExpression(rule, RuleExpression.methodCall.CONTAINS_WORDS_STARTING_WITH_IGNORE_CASE, [{ TYPE: 'STRING', VALUE: ';' }]);
|
|
344
|
+
default:
|
|
345
|
+
throw new Error(`Unmatched case for operator name: ${operatorName}`);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Converts a client `Group` into the correct server `Expression`
|
|
350
|
+
*
|
|
351
|
+
* @internal
|
|
352
|
+
**/
|
|
353
|
+
export function groupToRuleExpression(group) {
|
|
354
|
+
return {
|
|
355
|
+
TYPE: 'PREDICATE_EXPRESSION',
|
|
356
|
+
OPERATION: group.combinator.type,
|
|
357
|
+
CONDITIONS: group.children
|
|
358
|
+
.map((c) => 'children' in c ? groupToRuleExpression(c) : ruleToRuleExpression(c))
|
|
359
|
+
.filter(Boolean),
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Convert from Genesis to Expression builder
|
|
364
|
+
*/
|
|
365
|
+
/**
|
|
366
|
+
* Converts a server operator name to a client operator name
|
|
367
|
+
*
|
|
368
|
+
* The opposite to `transformOperatorNameToServerName`
|
|
369
|
+
*
|
|
370
|
+
* @privateRemarks
|
|
371
|
+
* Most names are the same, but this handles cases where date comparison operator names are different
|
|
372
|
+
* on the display to their server name
|
|
373
|
+
*
|
|
374
|
+
* TODO: We could clean this up if we support labels/aliases on the client component
|
|
375
|
+
*
|
|
376
|
+
* @internal
|
|
377
|
+
**/
|
|
378
|
+
export function transformServerNameToOperatorName(op) {
|
|
379
|
+
switch (op) {
|
|
380
|
+
case 'LESS_THAN':
|
|
381
|
+
return 'IS_BEFORE';
|
|
382
|
+
case 'GREATER_THAN':
|
|
383
|
+
return 'IS_AFTER';
|
|
384
|
+
case 'LESS_THAN_OR_EQUAL':
|
|
385
|
+
return 'ON_OR_BEFORE';
|
|
386
|
+
case 'GREATER_THAN_OR_EQUAL':
|
|
387
|
+
return 'ON_OR_AFTER';
|
|
388
|
+
default:
|
|
389
|
+
return op;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Converts a server field value to a client field value
|
|
394
|
+
*
|
|
395
|
+
* The opposite to `transformRuleValue`
|
|
396
|
+
*
|
|
397
|
+
* @privateRemarks
|
|
398
|
+
* `string` (+`enum`) and `boolean` types are left as they are
|
|
399
|
+
* `date` and `datetime-local` are converted to the string format required for input type=[date|datetime-local]
|
|
400
|
+
* `number` types are parsed as ints or floats as required
|
|
401
|
+
*
|
|
402
|
+
* @internal
|
|
403
|
+
**/
|
|
404
|
+
export function rebuildRuleValue(rule, rhs) {
|
|
405
|
+
const transform = (value) => {
|
|
406
|
+
if (stringTypes.includes(rule.field.type))
|
|
407
|
+
return value;
|
|
408
|
+
if (intTypes.includes(rule.field.type))
|
|
409
|
+
return parseInt(value);
|
|
410
|
+
if (floatTypes.includes(rule.field.type))
|
|
411
|
+
return parseFloat(value);
|
|
412
|
+
if (booleanTypes.includes(rule.field.type))
|
|
413
|
+
return value;
|
|
414
|
+
if (dateTypes.includes(rule.field.type)) {
|
|
415
|
+
const dateObj = new Date(parseInt(value) * MILLIS_TO_SECONDS);
|
|
416
|
+
return rule.field.type === 'date' ? formatDateString(dateObj) : formatDateTimeString(dateObj);
|
|
417
|
+
}
|
|
418
|
+
throw new Error('Unhandled rebuildRuleValue case');
|
|
419
|
+
};
|
|
420
|
+
const operatorNbInputs = rule.operator.nbInputs;
|
|
421
|
+
if (operatorNbInputs === 'many' || operatorNbInputs === 2)
|
|
422
|
+
throw new Error(`Not implemented TernararyOperator or VariadicOperator args in rebuildRuleValue`);
|
|
423
|
+
return Object.assign(Object.assign({}, rule), (operatorNbInputs === 0 ? {} : { value: transform(rhs.VALUE) }));
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Handles operator names which have a special client name, but serialised to a normal operator on the server
|
|
427
|
+
*
|
|
428
|
+
* @privateRemarks
|
|
429
|
+
* e.g. `NOT_NULL` is a standard NOT_EQUAL BinaryExpression on the server, but a special UniraryOperation on the client
|
|
430
|
+
*
|
|
431
|
+
* @internal
|
|
432
|
+
**/
|
|
433
|
+
export function rebuildOperator(binExpr) {
|
|
434
|
+
if (binExpr.RIGHT.TYPE === 'NULL') {
|
|
435
|
+
const op = binExpr.OPERATION === 'EQUALS'
|
|
436
|
+
? clientOperators[clientOperators.IS_NULL]
|
|
437
|
+
: clientOperators[clientOperators.NOT_NULL];
|
|
438
|
+
return logicalOperators.find((o) => o.type === op);
|
|
439
|
+
}
|
|
440
|
+
if (binExpr.RIGHT.TYPE === 'STRING' && binExpr.RIGHT.VALUE === '') {
|
|
441
|
+
const op = binExpr.OPERATION === 'EQUALS'
|
|
442
|
+
? clientOperators[clientOperators.IS_BLANK]
|
|
443
|
+
: clientOperators[clientOperators.NOT_BLANK];
|
|
444
|
+
return logicalOperators.find((o) => o.type === op);
|
|
445
|
+
}
|
|
446
|
+
const clientOperatorName = transformServerNameToOperatorName(binExpr.OPERATION);
|
|
447
|
+
return logicalOperators.find((o) => o.type === clientOperatorName);
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Converts a server BinaryExpression to a client BinaryOperator
|
|
451
|
+
*
|
|
452
|
+
* The opposite of `toBinaryExpression`
|
|
453
|
+
* @internal
|
|
454
|
+
**/
|
|
455
|
+
export function fromBinaryExpression(fields, binExpr) {
|
|
456
|
+
if (binExpr.LEFT.TYPE !== 'FIELD')
|
|
457
|
+
throw new Error('BinaryExpression LHS must be TYPE === FIELD');
|
|
458
|
+
if (!['STRING', 'NUMBER', 'BOOLEAN', 'NULL'].includes(binExpr.RIGHT.TYPE))
|
|
459
|
+
throw new Error('BinaryExpression RHS must be TYPE === NUMBER | STRING | BOOLEAN | NULL');
|
|
460
|
+
return rebuildRuleValue({
|
|
461
|
+
field: fields.find((f) => f.fieldId === binExpr.LEFT.NAME),
|
|
462
|
+
operator: rebuildOperator(binExpr),
|
|
463
|
+
}, binExpr.RIGHT);
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Converts a server MethodExpression to a client BinaryOperator
|
|
467
|
+
*
|
|
468
|
+
* The opposite of `toMethodExpression`
|
|
469
|
+
*
|
|
470
|
+
* @internal
|
|
471
|
+
**/
|
|
472
|
+
export function fromMethodExpression(fields, methodExpr) {
|
|
473
|
+
const clientOperatorName = methodExpr.METHOD === 'CONTAINS_IGNORE_CASE'
|
|
474
|
+
? clientOperators[clientOperators.CONTAINS_IGNORE_CASE]
|
|
475
|
+
: methodExpr.PARAMETERS.length === 2
|
|
476
|
+
? clientOperators[clientOperators.CONTAINS_WORDS_STARTING_WITH_IGNORE_CASE]
|
|
477
|
+
: clientOperators[clientOperators.CONTAINS_WORDS_STARTING_WITH_IGNORE_CASE_WITH_DELIMITER];
|
|
478
|
+
return {
|
|
479
|
+
field: fields.find((f) => f.fieldId === methodExpr.PARAMETERS[0].NAME),
|
|
480
|
+
operator: logicalOperators.find((o) => o.type === clientOperatorName),
|
|
481
|
+
value: methodExpr.PARAMETERS[1].VALUE, // TODO currently the only methods defined are BinaryExpression Strings
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Converts recursively from a PREDICATE_EXPRESSION to client Groups and Rules
|
|
486
|
+
*
|
|
487
|
+
* @internal
|
|
488
|
+
**/
|
|
489
|
+
export function ruleExpressionToGroup(fields, expr) {
|
|
490
|
+
return {
|
|
491
|
+
combinator: logicalCombinators.find((combinator) => combinator.type === expr.OPERATION),
|
|
492
|
+
children: expr.CONDITIONS.map((condition) => {
|
|
493
|
+
if (!('TYPE' in condition))
|
|
494
|
+
throw new Error('RuleExpression format not yet supported - no TYPE');
|
|
495
|
+
if (condition.TYPE === 'PREDICATE_EXPRESSION')
|
|
496
|
+
return ruleExpressionToGroup(fields, condition);
|
|
497
|
+
if (condition.TYPE === 'BINARY_EXPRESSION')
|
|
498
|
+
return fromBinaryExpression(fields, condition);
|
|
499
|
+
if (condition.TYPE === 'METHOD_EXPRESSION')
|
|
500
|
+
return fromMethodExpression(fields, condition);
|
|
501
|
+
throw new Error('RuleExpression format not yet supported - unsupported TYPE');
|
|
502
|
+
}),
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* We don't create the foundation version of the component in the same way as the other components,
|
|
507
|
+
* they're composed from a base FAST component.
|
|
508
|
+
* The reason for this is that we want to have ExpressionBuilder as an independent and open source
|
|
509
|
+
* component, and due to this we don't want to release it as base components that someone needs to use
|
|
510
|
+
* FAST to compose.
|
|
511
|
+
*/
|
|
512
|
+
let FoundationRuleExpressionBuilder = class FoundationRuleExpressionBuilder extends ExpressionBuilder {
|
|
513
|
+
ruleConfigChanged(_, newConfig) {
|
|
514
|
+
this.config = Object.assign({ combinators: logicalCombinators, operators: logicalOperators, fields: newConfig.fields, maxNesting: newConfig.maxNesting }, ((newConfig === null || newConfig === void 0 ? void 0 : newConfig.model)
|
|
515
|
+
? {
|
|
516
|
+
model: ruleExpressionToGroup(newConfig.fields, newConfig.model),
|
|
517
|
+
}
|
|
518
|
+
: {}));
|
|
519
|
+
}
|
|
520
|
+
dispatchChangeEvent(group) {
|
|
521
|
+
const ruleExpr = groupToRuleExpression(group);
|
|
522
|
+
this.dispatchEvent(new CustomEvent('change', {
|
|
523
|
+
detail: ruleExpr,
|
|
524
|
+
bubbles: true,
|
|
525
|
+
cancelable: true,
|
|
526
|
+
composed: true,
|
|
527
|
+
}));
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
__decorate([
|
|
531
|
+
observable
|
|
532
|
+
], FoundationRuleExpressionBuilder.prototype, "ruleConfig", void 0);
|
|
533
|
+
FoundationRuleExpressionBuilder = __decorate([
|
|
534
|
+
customElement({
|
|
535
|
+
name: 'foundation-rule-expression-builder',
|
|
536
|
+
styles: styles,
|
|
537
|
+
template,
|
|
538
|
+
})
|
|
539
|
+
], FoundationRuleExpressionBuilder);
|
|
540
|
+
export { FoundationRuleExpressionBuilder };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Config, template, styles } from '@genesislcap/expression-builder';
|
|
2
|
+
export { Config as ExpressionBuilderConfig };
|
|
3
|
+
export const ExpressionBuilderCore = {
|
|
4
|
+
template,
|
|
5
|
+
styles,
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Based on the RuleExpression config in Kotlin
|
|
9
|
+
*/
|
|
10
|
+
export var RuleExpression;
|
|
11
|
+
(function (RuleExpression) {
|
|
12
|
+
RuleExpression.methodCall = {
|
|
13
|
+
CONTAINS_IGNORE_CASE: 'CONTAINS_IGNORE_CASE',
|
|
14
|
+
CONTAINS_WORDS_STARTING_WITH_IGNORE_CASE: 'CONTAINS_WORDS_STARTING_WITH_IGNORE_CASE',
|
|
15
|
+
};
|
|
16
|
+
RuleExpression.logicalOperations = {
|
|
17
|
+
AND: 'AND',
|
|
18
|
+
OR: 'OR',
|
|
19
|
+
};
|
|
20
|
+
RuleExpression.operations = Object.assign(Object.assign({}, RuleExpression.logicalOperations), { GREATER_THAN: 'GREATER_THAN', LESS_THAN: 'LESS_THAN', GREATER_THAN_OR_EQUAL: 'GREATER_THAN_OR_EQUAL', LESS_THAN_OR_EQUAL: 'LESS_THAN_OR_EQUAL', EQUALS: 'EQUALS', NOT_EQUALS: 'NOT_EQUALS', PLUS: 'PLUS', MINUS: 'MINUS', MULTIPLY: 'MULTIPLY', DIVIDE: 'DIVIDE', BITWISE_AND: 'BITWISE_AND', BITWISE_OR: 'BITWISE_OR', ASSIGNMENT: 'ASSIGNMENT' });
|
|
21
|
+
})(RuleExpression || (RuleExpression = {}));
|
package/dist/esm/index.js
CHANGED
|
@@ -12,16 +12,16 @@ export * from './anchored-region';
|
|
|
12
12
|
export * from './avatar';
|
|
13
13
|
export * from './badge';
|
|
14
14
|
export * from './banner';
|
|
15
|
-
export * from './breadcrumb-item';
|
|
16
15
|
export * from './breadcrumb';
|
|
16
|
+
export * from './breadcrumb-item';
|
|
17
17
|
export * from './button';
|
|
18
|
-
export * from './context';
|
|
19
18
|
export * from './calendar';
|
|
20
19
|
export * from './card';
|
|
21
20
|
export * from './categorized-multiselect';
|
|
22
21
|
export * from './checkbox';
|
|
23
22
|
export * from './combobox';
|
|
24
23
|
export * from './connection-indicator';
|
|
24
|
+
export * from './context';
|
|
25
25
|
export * from './data-grid';
|
|
26
26
|
export * from './data-grid-cell';
|
|
27
27
|
export * from './data-grid-datasource';
|
|
@@ -32,9 +32,10 @@ export * from './dialog';
|
|
|
32
32
|
export * from './disclosure';
|
|
33
33
|
export * from './divider';
|
|
34
34
|
export * from './dropdown-menu';
|
|
35
|
-
export * from './error-boundary';
|
|
36
35
|
export * from './error-banner';
|
|
36
|
+
export * from './error-boundary';
|
|
37
37
|
export * from './error-dialog';
|
|
38
|
+
export * from './expression-builder';
|
|
38
39
|
export * from './file-upload';
|
|
39
40
|
export * from './filter';
|
|
40
41
|
export * from './filter-bar';
|
|
@@ -70,8 +71,8 @@ export * from './select';
|
|
|
70
71
|
export * from './skeleton';
|
|
71
72
|
export * from './slider';
|
|
72
73
|
export * from './slider-label';
|
|
73
|
-
export * from './stacking-icons';
|
|
74
74
|
export * from './snackbar';
|
|
75
|
+
export * from './stacking-icons';
|
|
75
76
|
export * from './stepper';
|
|
76
77
|
export * from './stepper-tab';
|
|
77
78
|
export * from './stepper-tab-panel';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@genesislcap/foundation-ui",
|
|
3
3
|
"description": "Genesis Foundation UI",
|
|
4
|
-
"version": "14.
|
|
4
|
+
"version": "14.249.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"license": "SEE LICENSE IN license.txt",
|
|
7
7
|
"main": "dist/esm/index.js",
|
|
@@ -83,13 +83,13 @@
|
|
|
83
83
|
}
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"@genesislcap/foundation-testing": "14.
|
|
87
|
-
"@genesislcap/genx": "14.
|
|
88
|
-
"@genesislcap/rollup-builder": "14.
|
|
89
|
-
"@genesislcap/ts-builder": "14.
|
|
90
|
-
"@genesislcap/uvu-playwright-builder": "14.
|
|
91
|
-
"@genesislcap/vite-builder": "14.
|
|
92
|
-
"@genesislcap/webpack-builder": "14.
|
|
86
|
+
"@genesislcap/foundation-testing": "14.249.0",
|
|
87
|
+
"@genesislcap/genx": "14.249.0",
|
|
88
|
+
"@genesislcap/rollup-builder": "14.249.0",
|
|
89
|
+
"@genesislcap/ts-builder": "14.249.0",
|
|
90
|
+
"@genesislcap/uvu-playwright-builder": "14.249.0",
|
|
91
|
+
"@genesislcap/vite-builder": "14.249.0",
|
|
92
|
+
"@genesislcap/webpack-builder": "14.249.0",
|
|
93
93
|
"copyfiles": "^2.4.1",
|
|
94
94
|
"rimraf": "^5.0.0",
|
|
95
95
|
"rxjs": "^7.5.4"
|
|
@@ -100,14 +100,15 @@
|
|
|
100
100
|
"@fortawesome/free-regular-svg-icons": "^6.2.1",
|
|
101
101
|
"@fortawesome/free-solid-svg-icons": "^6.2.1",
|
|
102
102
|
"@genesiscommunitysuccess/analyzer-import-alias-plugin": "^5.0.3",
|
|
103
|
-
"@genesislcap/
|
|
104
|
-
"@genesislcap/foundation-
|
|
105
|
-
"@genesislcap/foundation-
|
|
106
|
-
"@genesislcap/foundation-
|
|
107
|
-
"@genesislcap/foundation-
|
|
108
|
-
"@genesislcap/foundation-
|
|
109
|
-
"@genesislcap/foundation-
|
|
110
|
-
"@genesislcap/foundation-
|
|
103
|
+
"@genesislcap/expression-builder": "14.249.0",
|
|
104
|
+
"@genesislcap/foundation-comms": "14.249.0",
|
|
105
|
+
"@genesislcap/foundation-criteria": "14.249.0",
|
|
106
|
+
"@genesislcap/foundation-errors": "14.249.0",
|
|
107
|
+
"@genesislcap/foundation-events": "14.249.0",
|
|
108
|
+
"@genesislcap/foundation-logger": "14.249.0",
|
|
109
|
+
"@genesislcap/foundation-notifications": "14.249.0",
|
|
110
|
+
"@genesislcap/foundation-user": "14.249.0",
|
|
111
|
+
"@genesislcap/foundation-utils": "14.249.0",
|
|
111
112
|
"@microsoft/fast-colors": "5.3.1",
|
|
112
113
|
"@microsoft/fast-components": "2.30.6",
|
|
113
114
|
"@microsoft/fast-element": "1.14.0",
|
|
@@ -129,5 +130,5 @@
|
|
|
129
130
|
"access": "public"
|
|
130
131
|
},
|
|
131
132
|
"customElements": "dist/custom-elements.json",
|
|
132
|
-
"gitHead": "
|
|
133
|
+
"gitHead": "0827469e373358a4dbc50de154868998adf62bd9"
|
|
133
134
|
}
|