@genesislcap/expression-builder 14.248.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.
Files changed (114) hide show
  1. package/FUTURE.md +164 -0
  2. package/README.md +3 -0
  3. package/custom-elements-manifest.config.js +14 -0
  4. package/dist/custom-elements.json +1971 -0
  5. package/dist/dts/config/combinators.d.ts +6 -0
  6. package/dist/dts/config/combinators.d.ts.map +1 -0
  7. package/dist/dts/config/index.d.ts +3 -0
  8. package/dist/dts/config/index.d.ts.map +1 -0
  9. package/dist/dts/config/operators.d.ts +4 -0
  10. package/dist/dts/config/operators.d.ts.map +1 -0
  11. package/dist/dts/index.d.ts +6 -0
  12. package/dist/dts/index.d.ts.map +1 -0
  13. package/dist/dts/main/events.d.ts +50 -0
  14. package/dist/dts/main/events.d.ts.map +1 -0
  15. package/dist/dts/main/expression-builder.d.ts +44 -0
  16. package/dist/dts/main/expression-builder.d.ts.map +1 -0
  17. package/dist/dts/main/expression-builder.helpers.d.ts +19 -0
  18. package/dist/dts/main/expression-builder.helpers.d.ts.map +1 -0
  19. package/dist/dts/main/expression-builder.styles.d.ts +3 -0
  20. package/dist/dts/main/expression-builder.styles.d.ts.map +1 -0
  21. package/dist/dts/main/expression-builder.template.d.ts +4 -0
  22. package/dist/dts/main/expression-builder.template.d.ts.map +1 -0
  23. package/dist/dts/main/expression-group/expression-group.d.ts +18 -0
  24. package/dist/dts/main/expression-group/expression-group.d.ts.map +1 -0
  25. package/dist/dts/main/expression-group/expression-group.styles.d.ts +2 -0
  26. package/dist/dts/main/expression-group/expression-group.styles.d.ts.map +1 -0
  27. package/dist/dts/main/expression-group/expression-group.template.d.ts +3 -0
  28. package/dist/dts/main/expression-group/expression-group.template.d.ts.map +1 -0
  29. package/dist/dts/main/expression-rule/expression-rule.d.ts +27 -0
  30. package/dist/dts/main/expression-rule/expression-rule.d.ts.map +1 -0
  31. package/dist/dts/main/expression-rule/expression-rule.helpers.d.ts +4 -0
  32. package/dist/dts/main/expression-rule/expression-rule.helpers.d.ts.map +1 -0
  33. package/dist/dts/main/expression-rule/expression-rule.styles.d.ts +2 -0
  34. package/dist/dts/main/expression-rule/expression-rule.styles.d.ts.map +1 -0
  35. package/dist/dts/main/expression-rule/expression-rule.template.d.ts +3 -0
  36. package/dist/dts/main/expression-rule/expression-rule.template.d.ts.map +1 -0
  37. package/dist/dts/main/index.d.ts +4 -0
  38. package/dist/dts/main/index.d.ts.map +1 -0
  39. package/dist/dts/main/rule-field/rule-field.d.ts +15 -0
  40. package/dist/dts/main/rule-field/rule-field.d.ts.map +1 -0
  41. package/dist/dts/main/rule-field/rule-field.template.d.ts +3 -0
  42. package/dist/dts/main/rule-field/rule-field.template.d.ts.map +1 -0
  43. package/dist/dts/main/rule-operator/rule-operator.d.ts +17 -0
  44. package/dist/dts/main/rule-operator/rule-operator.d.ts.map +1 -0
  45. package/dist/dts/main/rule-operator/rule-operator.template.d.ts +3 -0
  46. package/dist/dts/main/rule-operator/rule-operator.template.d.ts.map +1 -0
  47. package/dist/dts/main/rule-value/rule-value.d.ts +17 -0
  48. package/dist/dts/main/rule-value/rule-value.d.ts.map +1 -0
  49. package/dist/dts/main/rule-value/rule-value.helpers.d.ts +6 -0
  50. package/dist/dts/main/rule-value/rule-value.helpers.d.ts.map +1 -0
  51. package/dist/dts/main/rule-value/rule-value.styles.d.ts +2 -0
  52. package/dist/dts/main/rule-value/rule-value.styles.d.ts.map +1 -0
  53. package/dist/dts/main/rule-value/rule-value.template.d.ts +3 -0
  54. package/dist/dts/main/rule-value/rule-value.template.d.ts.map +1 -0
  55. package/dist/dts/types/index.d.ts +3 -0
  56. package/dist/dts/types/index.d.ts.map +1 -0
  57. package/dist/dts/types/private.types.d.ts +21 -0
  58. package/dist/dts/types/private.types.d.ts.map +1 -0
  59. package/dist/dts/types/public.types.d.ts +160 -0
  60. package/dist/dts/types/public.types.d.ts.map +1 -0
  61. package/dist/dts/utils/data-model.d.ts +27 -0
  62. package/dist/dts/utils/data-model.d.ts.map +1 -0
  63. package/dist/dts/utils/formatting.d.ts +13 -0
  64. package/dist/dts/utils/formatting.d.ts.map +1 -0
  65. package/dist/dts/utils/index.d.ts +4 -0
  66. package/dist/dts/utils/index.d.ts.map +1 -0
  67. package/dist/dts/utils/misc.d.ts +14 -0
  68. package/dist/dts/utils/misc.d.ts.map +1 -0
  69. package/dist/esm/config/combinators.js +31 -0
  70. package/dist/esm/config/index.js +2 -0
  71. package/dist/esm/config/operators.js +91 -0
  72. package/dist/esm/index.js +5 -0
  73. package/dist/esm/main/events.js +13 -0
  74. package/dist/esm/main/expression-builder.helpers.js +129 -0
  75. package/dist/esm/main/expression-builder.js +157 -0
  76. package/dist/esm/main/expression-builder.styles.js +177 -0
  77. package/dist/esm/main/expression-builder.template.js +13 -0
  78. package/dist/esm/main/expression-group/expression-group.js +121 -0
  79. package/dist/esm/main/expression-group/expression-group.styles.js +45 -0
  80. package/dist/esm/main/expression-group/expression-group.template.js +102 -0
  81. package/dist/esm/main/expression-rule/expression-rule.helpers.js +25 -0
  82. package/dist/esm/main/expression-rule/expression-rule.js +203 -0
  83. package/dist/esm/main/expression-rule/expression-rule.styles.js +57 -0
  84. package/dist/esm/main/expression-rule/expression-rule.template.js +65 -0
  85. package/dist/esm/main/index.js +3 -0
  86. package/dist/esm/main/rule-field/rule-field.js +48 -0
  87. package/dist/esm/main/rule-field/rule-field.template.js +46 -0
  88. package/dist/esm/main/rule-operator/rule-operator.js +60 -0
  89. package/dist/esm/main/rule-operator/rule-operator.template.js +46 -0
  90. package/dist/esm/main/rule-value/rule-value.helpers.js +17 -0
  91. package/dist/esm/main/rule-value/rule-value.js +115 -0
  92. package/dist/esm/main/rule-value/rule-value.styles.js +11 -0
  93. package/dist/esm/main/rule-value/rule-value.template.js +106 -0
  94. package/dist/esm/types/index.js +2 -0
  95. package/dist/esm/types/private.types.js +1 -0
  96. package/dist/esm/types/public.types.js +1 -0
  97. package/dist/esm/utils/data-model.js +51 -0
  98. package/dist/esm/utils/formatting.js +23 -0
  99. package/dist/esm/utils/index.js +3 -0
  100. package/dist/esm/utils/misc.js +62 -0
  101. package/dist/expression-builder.api.json +212 -0
  102. package/dist/expression-builder.d.ts +322 -0
  103. package/dist/tsdoc-metadata.json +11 -0
  104. package/docs/.gitattributes +2 -0
  105. package/docs/api/expression-builder.config.md +6 -0
  106. package/docs/api/expression-builder.md +13 -0
  107. package/docs/api/expression-builder.types.md +6 -0
  108. package/docs/api/index.md +12 -0
  109. package/docs/api-report.md +260 -0
  110. package/license.txt +46 -0
  111. package/package.json +66 -0
  112. package/playwright.config.ts +5 -0
  113. package/test/unit/test.ts +1 -0
  114. package/tsdoc.json +4 -0
@@ -0,0 +1,46 @@
1
+ import { html, repeat } from '@genesislcap/web-core';
2
+ export const template = html `
3
+ ${(context) => {
4
+ var _a, _b, _c, _d;
5
+ const selectTag = ((_b = (_a = context.styles) === null || _a === void 0 ? void 0 : _a.customElements) === null || _b === void 0 ? void 0 : _b.select) || 'select';
6
+ const optionTag = ((_d = (_c = context.styles) === null || _c === void 0 ? void 0 : _c.customElements) === null || _d === void 0 ? void 0 : _d.option) || 'option';
7
+ const optgroupTag = 'optgroup'; // Not supporting custom optgroup for now
8
+ return html `
9
+ <${selectTag}
10
+ class="form-select"
11
+ @change=${(x, c) => x.dispatchFieldsChanged(c.event)}
12
+ value=${(x) => { var _a; return (_a = x.field) === null || _a === void 0 ? void 0 : _a.fieldId; }}
13
+ >
14
+ <${optionTag} value="">Select a field</${optionTag}>
15
+ ${repeat((x) => x.groupedFieldss, html `
16
+ ${(groupOrFields) => {
17
+ if ('xs' in groupOrFields) {
18
+ return html `
19
+ <${optgroupTag} label="${(x) => x.optgroup}">
20
+ ${repeat((x) => x.xs, html `
21
+ <${optionTag}
22
+ value="${(x) => x.fieldId}"
23
+ ?selected=${(x, c) => { var _a, _b; return x.fieldId === ((_b = (_a = c.parentContext.parent) === null || _a === void 0 ? void 0 : _a.field) === null || _b === void 0 ? void 0 : _b.fieldId); }}
24
+ >
25
+ ${(x) => x.label}
26
+ </${optionTag}>
27
+ `)}
28
+ </${optgroupTag}>
29
+ `;
30
+ }
31
+ else {
32
+ return html `
33
+ <${optionTag}
34
+ value="${(x) => x.fieldId}"
35
+ ?selected=${(x, c) => { var _a, _b; return x.fieldId === ((_b = (_a = c.parent) === null || _a === void 0 ? void 0 : _a.field) === null || _b === void 0 ? void 0 : _b.fieldId); }}
36
+ >
37
+ ${(x) => x.label}
38
+ </${optionTag}>
39
+ `;
40
+ }
41
+ }}
42
+ `)}
43
+ </${selectTag}>
44
+ `;
45
+ }}
46
+ `;
@@ -0,0 +1,60 @@
1
+ import { __decorate } from "tslib";
2
+ import { customElement, GenesisElement, observable, volatile } from '@genesislcap/web-core';
3
+ import { applyCustomStyles, processOptGroups } from '../../utils';
4
+ import { Events } from '../events';
5
+ import { template } from './rule-operator.template';
6
+ let RuleOperator = class RuleOperator extends GenesisElement {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.operators = [];
10
+ this.field = null;
11
+ }
12
+ connectedCallback() {
13
+ super.connectedCallback();
14
+ applyCustomStyles(this, this.styles, 'operator');
15
+ }
16
+ get allowedOperators() {
17
+ const fieldAllows = (operator) => { var _a, _b, _c; return (_c = (_b = (_a = this.field) === null || _a === void 0 ? void 0 : _a.operators) === null || _b === void 0 ? void 0 : _b.includes(operator.type)) !== null && _c !== void 0 ? _c : true; };
18
+ const operatorAllows = (operator) => { var _a, _b, _c, _d; return (_d = (_b = (_a = operator === null || operator === void 0 ? void 0 : operator.applyTo) === null || _a === void 0 ? void 0 : _a.includes) === null || _b === void 0 ? void 0 : _b.call(_a, (_c = this.field) === null || _c === void 0 ? void 0 : _c.type)) !== null && _d !== void 0 ? _d : true; };
19
+ return this.operators.filter((operator) => fieldAllows(operator) && operatorAllows(operator));
20
+ }
21
+ get groupedOperators() {
22
+ return processOptGroups(this.allowedOperators);
23
+ }
24
+ handleOperatorChange(event) {
25
+ event.stopPropagation();
26
+ const operatorType = event.target.value;
27
+ const detail = {
28
+ operatorId: operatorType,
29
+ };
30
+ this.dispatchEvent(new CustomEvent(Events.OperatorSelected, { detail, bubbles: true, composed: true }));
31
+ }
32
+ };
33
+ __decorate([
34
+ observable
35
+ ], RuleOperator.prototype, "operators", void 0);
36
+ __decorate([
37
+ observable
38
+ ], RuleOperator.prototype, "operator", void 0);
39
+ __decorate([
40
+ observable
41
+ ], RuleOperator.prototype, "field", void 0);
42
+ __decorate([
43
+ observable
44
+ ], RuleOperator.prototype, "config", void 0);
45
+ __decorate([
46
+ observable
47
+ ], RuleOperator.prototype, "styles", void 0);
48
+ __decorate([
49
+ volatile
50
+ ], RuleOperator.prototype, "allowedOperators", null);
51
+ __decorate([
52
+ volatile
53
+ ], RuleOperator.prototype, "groupedOperators", null);
54
+ RuleOperator = __decorate([
55
+ customElement({
56
+ name: 'expression-rule-operator',
57
+ template: template,
58
+ })
59
+ ], RuleOperator);
60
+ export { RuleOperator };
@@ -0,0 +1,46 @@
1
+ import { html, repeat } from '@genesislcap/web-core';
2
+ export const template = html `
3
+ ${(context) => {
4
+ var _a, _b, _c, _d;
5
+ const selectTag = ((_b = (_a = context.styles) === null || _a === void 0 ? void 0 : _a.customElements) === null || _b === void 0 ? void 0 : _b.select) || 'select';
6
+ const optionTag = ((_d = (_c = context.styles) === null || _c === void 0 ? void 0 : _c.customElements) === null || _d === void 0 ? void 0 : _d.option) || 'option';
7
+ const optgroupTag = 'optgroup'; // Not supporting custom optgroup for now
8
+ return html `
9
+ <${selectTag}
10
+ class="form-select"
11
+ @change=${(x, c) => x.handleOperatorChange(c.event)}
12
+ value=${(x) => { var _a; return (_a = x.operator) === null || _a === void 0 ? void 0 : _a.type; }}
13
+ >
14
+ <${optionTag} value="">Select an operator</${optionTag}>
15
+ ${repeat((x) => x.groupedOperators, html `
16
+ ${(groupOrOperator) => {
17
+ if ('xs' in groupOrOperator) {
18
+ return html `
19
+ <${optgroupTag} label="${groupOrOperator.optgroup}">
20
+ ${repeat((x) => x.xs, html `
21
+ <${optionTag}
22
+ value="${(x) => x.type}"
23
+ ?selected=${(x, c) => { var _a; return x.type === ((_a = c.parentContext.parent.operator) === null || _a === void 0 ? void 0 : _a.type); }}
24
+ >
25
+ ${(x) => x.type}
26
+ </${optionTag}>
27
+ `)}
28
+ </${optgroupTag}>
29
+ `;
30
+ }
31
+ else {
32
+ return html `
33
+ <${optionTag}
34
+ value="${(x) => x.type}"
35
+ ?selected=${(x, c) => { var _a; return ((_a = c.parent.operator) === null || _a === void 0 ? void 0 : _a.type) === x.type; }}
36
+ >
37
+ ${(x) => x.type}
38
+ </${optionTag}>
39
+ `;
40
+ }
41
+ }}
42
+ `)}
43
+ </${selectTag}>
44
+ `;
45
+ }}
46
+ `;
@@ -0,0 +1,17 @@
1
+ export const isIntType = (type) => ['short', 'int', 'long'].includes(type);
2
+ export const isFloatType = (type) => ['double', 'bigdecimal'].includes(type);
3
+ export const pattern = (type) => {
4
+ if (isIntType(type)) {
5
+ return /^[+-]?[0-9]+$/; // Integer pattern: optional leading minus sign, followed by digits
6
+ }
7
+ else if (isFloatType(type)) {
8
+ return /[+-]?([0-9]*[.])?[0-9]+/; // Float pattern: optional leading minus, digits, optional decimal and more digits
9
+ }
10
+ else {
11
+ return null;
12
+ }
13
+ };
14
+ export const numberPatternValidator = (type, value) => {
15
+ var _a, _b;
16
+ return !((_b = (_a = pattern(type)) === null || _a === void 0 ? void 0 : _a.test(value)) !== null && _b !== void 0 ? _b : true) ? 'Invalid number format' : null;
17
+ };
@@ -0,0 +1,115 @@
1
+ import { __decorate } from "tslib";
2
+ import { attr, customElement, GenesisElement, observable } from '@genesislcap/web-core';
3
+ import { applyCustomStyles } from '../../utils/misc';
4
+ import { Events } from '../events';
5
+ import { isFloatType, isIntType, numberPatternValidator } from './rule-value.helpers';
6
+ import { styles } from './rule-value.styles';
7
+ import { ruleValueTemplate } from './rule-value.template';
8
+ let RuleValue = class RuleValue extends GenesisElement {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.variadic = false;
12
+ this.validationError = false;
13
+ this.field = null;
14
+ }
15
+ connectedCallback() {
16
+ super.connectedCallback();
17
+ applyCustomStyles(this, this.styles, 'value');
18
+ }
19
+ // Validate the input value
20
+ validateInput(value) {
21
+ if (!this.field)
22
+ return null;
23
+ const errorMsg = [
24
+ 'validation' in this.field ? this.field.validation(value) : null,
25
+ numberPatternValidator(this.field.type, value),
26
+ ]
27
+ .filter((v) => !!v)
28
+ .join(', ');
29
+ return errorMsg || null;
30
+ }
31
+ // Handle input change/blur events
32
+ handleInputChange(event) {
33
+ event.stopPropagation();
34
+ const target = event.target;
35
+ // For text-like inputs, validate on blur
36
+ if (target.type !== 'checkbox' && target.type !== 'select-one') {
37
+ const errorMsg = this.validateInput(target.value);
38
+ if (errorMsg) {
39
+ this.validationError = true;
40
+ this.validationMsg = errorMsg;
41
+ return; // Don't proceed if validation fails
42
+ }
43
+ else {
44
+ this.validationError = false;
45
+ this.validationMsg = null;
46
+ }
47
+ }
48
+ // Process the value change
49
+ let newValue;
50
+ if (target.getAttribute('role') === 'checkbox') {
51
+ newValue = target.checked;
52
+ }
53
+ else if (target.type === 'select-one') {
54
+ newValue = event.target.value;
55
+ }
56
+ else if (this.field && isIntType(this.field.type)) {
57
+ newValue = parseInt(target.value);
58
+ }
59
+ else if (this.field && isFloatType(this.field.type)) {
60
+ newValue = parseFloat(target.value);
61
+ }
62
+ else {
63
+ newValue = target.value;
64
+ }
65
+ this.value = newValue;
66
+ const detail = {
67
+ value: newValue,
68
+ index: parseInt(this.valueIndex),
69
+ };
70
+ this.dispatchEvent(new CustomEvent(Events.ValueUpdated, { detail, bubbles: true, composed: true }));
71
+ }
72
+ handleRemoveVariadicOperand() {
73
+ if (!this.variadic)
74
+ throw new Error('Cannot remove inputs for non-variadic operator');
75
+ const detail = {
76
+ index: parseInt(this.valueIndex),
77
+ };
78
+ this.dispatchEvent(new CustomEvent(Events.RemoveVarArg, { detail, bubbles: true, composed: true }));
79
+ }
80
+ };
81
+ __decorate([
82
+ attr({ attribute: 'value-index' })
83
+ ], RuleValue.prototype, "valueIndex", void 0);
84
+ __decorate([
85
+ attr({ mode: 'boolean' })
86
+ ], RuleValue.prototype, "variadic", void 0);
87
+ __decorate([
88
+ attr({ mode: 'boolean', attribute: 'validation-error' })
89
+ ], RuleValue.prototype, "validationError", void 0);
90
+ __decorate([
91
+ attr({ attribute: 'validation-msg' })
92
+ ], RuleValue.prototype, "validationMsg", void 0);
93
+ __decorate([
94
+ observable
95
+ ], RuleValue.prototype, "field", void 0);
96
+ __decorate([
97
+ observable
98
+ ], RuleValue.prototype, "value", void 0);
99
+ __decorate([
100
+ observable
101
+ ], RuleValue.prototype, "config", void 0);
102
+ __decorate([
103
+ observable
104
+ ], RuleValue.prototype, "styles", void 0);
105
+ RuleValue = __decorate([
106
+ customElement({
107
+ name: 'expression-rule-value',
108
+ template: ruleValueTemplate,
109
+ styles: styles,
110
+ shadowOptions: {
111
+ delegatesFocus: true,
112
+ },
113
+ })
114
+ ], RuleValue);
115
+ export { RuleValue };
@@ -0,0 +1,11 @@
1
+ import { css } from '@genesislcap/web-core';
2
+ export const styles = css `
3
+ .text-input.error {
4
+ color: red;
5
+ }
6
+
7
+ div.value-and-validation {
8
+ display: inline-grid;
9
+ align-items: center;
10
+ }
11
+ `;
@@ -0,0 +1,106 @@
1
+ import { classNames, html, repeat, when, whenElse } from '@genesislcap/web-core';
2
+ // Simple input template with custom element tags support
3
+ const simpleTemplate = html `
4
+ ${(context) => {
5
+ var _a, _b;
6
+ const inputType = context.field.input;
7
+ // Convert datetime-local to datetimeLocal for the config property name
8
+ const configKey = inputType === 'datetime-local' ? 'datetimeLocal' : inputType;
9
+ // Get custom tag if available
10
+ const customTag = (_b = (_a = context.styles) === null || _a === void 0 ? void 0 : _a.customElements) === null || _b === void 0 ? void 0 : _b[configKey];
11
+ // Use custom tag if available, otherwise use standard input
12
+ const tagName = customTag || 'input';
13
+ return html `
14
+ <${tagName}
15
+ ${customTag ? '' : `type="${inputType}"`}
16
+ class="text-input ${(x) => classNames(['error', x.validationError])}"
17
+ value=${(x) => x.value}
18
+ @blur=${(x, c) => x.handleInputChange(c.event)}
19
+ />
20
+ `;
21
+ }}
22
+ `;
23
+ // Select template with custom element tags support
24
+ const selectTemplate = html `
25
+ ${(context) => {
26
+ var _a, _b, _c, _d;
27
+ const selectTag = ((_b = (_a = context.styles) === null || _a === void 0 ? void 0 : _a.customElements) === null || _b === void 0 ? void 0 : _b.select) || 'select';
28
+ const optionTag = ((_d = (_c = context.styles) === null || _c === void 0 ? void 0 : _c.customElements) === null || _d === void 0 ? void 0 : _d.option) || 'option';
29
+ return html `
30
+ <${selectTag}
31
+ class="form-select"
32
+ @change=${(x, c) => x.handleInputChange(c.event)}
33
+ value=${(x) => x.value}
34
+ >
35
+ ${repeat((x) => {
36
+ var _a, _b;
37
+ // Ensure values is defined and an object before calling Object.entries
38
+ const values = ((_a = x.field) === null || _a === void 0 ? void 0 : _a.type) === 'enum' && ((_b = x.field) === null || _b === void 0 ? void 0 : _b.values) ? x.field.values : {};
39
+ return Object.entries(values);
40
+ }, () => html `
41
+ <${optionTag} value="${(x) => x[0]}" ?selected=${(x, c) => x[0] === c.parent.value}>
42
+ ${(x) => x[1]}
43
+ </${optionTag}>
44
+ `)}
45
+ </${selectTag}>
46
+ `;
47
+ }}
48
+ `;
49
+ // Checkbox template with custom element tags support
50
+ const checkboxTemplate = html `
51
+ ${(context) => {
52
+ var _a, _b;
53
+ // Get custom checkbox tag if available
54
+ const customTag = (_b = (_a = context.styles) === null || _a === void 0 ? void 0 : _a.customElements) === null || _b === void 0 ? void 0 : _b.checkbox;
55
+ // Use custom tag if available, otherwise use standard input
56
+ const tagName = customTag || 'input';
57
+ return html `
58
+ <label>
59
+ <${tagName}
60
+ ${customTag ? '' : 'type="checkbox"'}
61
+ ?checked=${(x) => !!x.value}
62
+ @change=${(x, c) => x.handleInputChange(c.event)}
63
+ role="checkbox"
64
+ />
65
+ True
66
+ </label>
67
+ `;
68
+ }}
69
+ `;
70
+ // Unsupported input template
71
+ const unsupportedTemplate = html `
72
+ <div>Input type "${(x) => x.field.input}" not yet supported.</div>
73
+ `;
74
+ // Template switcher
75
+ const templateSwitcher = html `
76
+ <div class="value-and-validation">
77
+ ${when((x) => ['text', 'number', 'date', 'datetime-local'].includes(x.field.input), simpleTemplate)}
78
+ ${when((x) => x.field.input === 'select', selectTemplate)}
79
+ ${when((x) => x.field.input === 'checkbox', checkboxTemplate)}
80
+ ${when((x) => !['text', 'number', 'select', 'checkbox', 'date', 'datetime-local'].includes(x.field.input), unsupportedTemplate)}
81
+ ${when((x) => x.validationMsg, html `
82
+ <p>${(x) => x.validationMsg}</p>
83
+ `)}
84
+ </div>
85
+ ${when((x) => x.variadic && x.valueIndex !== '0', html `
86
+ ${(context) => {
87
+ var _a, _b;
88
+ const buttonTag = ((_b = (_a = context.styles) === null || _a === void 0 ? void 0 : _a.customElements) === null || _b === void 0 ? void 0 : _b.button) || 'button';
89
+ return html `
90
+ <${buttonTag}
91
+ type="button"
92
+ class="btn btn-sm btn-remove"
93
+ @click="${(x) => x.handleRemoveVariadicOperand()}"
94
+ >
95
+ -
96
+ </${buttonTag}>
97
+ `;
98
+ }}
99
+ `)}
100
+ `;
101
+ // Main template
102
+ export const ruleValueTemplate = html `
103
+ ${whenElse((x) => x.field, templateSwitcher, html `
104
+ <div>Select a field to set value</div>
105
+ `)}
106
+ `;
@@ -0,0 +1,2 @@
1
+ export * from './public.types';
2
+ export * from './private.types';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,51 @@
1
+ import { ROOT_GROUP } from '../main/expression-builder.helpers';
2
+ /**
3
+ * Converts a Group to a ModelGroup (adds required metadata)
4
+ */
5
+ export function groupToModelGroup(group, provider) {
6
+ const mapper = (child, level) => 'children' in child ? _groupToModelGroup(child, level) : _ruleToModelRule(child);
7
+ function _groupToModelGroup(_group, level) {
8
+ return Object.assign(Object.assign({}, _group), { level, config: provider.getConfig(), groupId: provider.getGroupId(), children: _group.children.map((child) => mapper(child, level + 1)) });
9
+ }
10
+ function _ruleToModelRule(rule) {
11
+ return Object.assign(Object.assign({}, rule), { ruleId: provider.getRuleId(), config: provider.getConfig() });
12
+ }
13
+ return Object.assign(Object.assign({}, group), { config: provider.getConfig(), level: 1, groupId: ROOT_GROUP, children: group.children.map((child) => mapper(child, 2)) });
14
+ }
15
+ /**
16
+ * Converts a ModelGroup (internal data structure) to a public Group structure.
17
+ * This function recursively processes the rules within the group.
18
+ *
19
+ * @param modelGroup The internal ModelGroup to convert.
20
+ * @returns A public Group object.
21
+ */
22
+ export function modelGroupToGroup(modelGroup) {
23
+ const children = modelGroup.children.map((child) => {
24
+ if ('children' in child) {
25
+ // It's a nested group, recursively convert it
26
+ return modelGroupToGroup(child);
27
+ }
28
+ else {
29
+ // It's a rule, convert it
30
+ return modelRuleToRule(child);
31
+ }
32
+ });
33
+ return {
34
+ combinator: modelGroup.combinator,
35
+ children: children,
36
+ };
37
+ }
38
+ /**
39
+ * Converts a ModelRule (internal data structure) to a public Rule structure.
40
+ *
41
+ * @param modelRule The internal ModelRule to convert.
42
+ * @returns A public Rule object.
43
+ */
44
+ export function modelRuleToRule(modelRule) {
45
+ const { operator, field, value } = modelRule;
46
+ return {
47
+ operator,
48
+ field,
49
+ value,
50
+ };
51
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Gets the string representation from a `Date` which is the format a `date` input uses.
3
+ * `yyyy-mm-dd`
4
+ * @alpha
5
+ */
6
+ export const formatDateString = (date) => {
7
+ const year = date.getFullYear();
8
+ const month = String(date.getMonth() + 1).padStart(2, '0'); // Months are 0-indexed
9
+ const day = String(date.getDate()).padStart(2, '0');
10
+ return `${year}-${month}-${day}`;
11
+ };
12
+ /**
13
+ * Gets the string representation from a `Date` which is the format a `datetime-local` input uses.
14
+ * `yyyy-mm-ddThh:mm:ss`
15
+ * @alpha
16
+ */
17
+ export const formatDateTimeString = (date) => {
18
+ const datePart = formatDateString(date);
19
+ const hours = String(date.getHours()).padStart(2, '0');
20
+ const minutes = String(date.getMinutes()).padStart(2, '0');
21
+ const seconds = String(date.getSeconds()).padStart(2, '0');
22
+ return `${datePart}T${hours}:${minutes}:${seconds}`;
23
+ };
@@ -0,0 +1,3 @@
1
+ export * from './data-model';
2
+ export * from './formatting';
3
+ export * from './misc';
@@ -0,0 +1,62 @@
1
+ export const processOptGroups = (xs) => {
2
+ const grouped = {};
3
+ const ungrouped = [];
4
+ // Helper function to sort items consistently
5
+ const sortItems = (items) => {
6
+ return [...items].sort((a, b) => {
7
+ if ('fieldId' in a && 'fieldId' in b) {
8
+ return a.fieldId.localeCompare(b.fieldId);
9
+ }
10
+ else if ('type' in a && 'type' in b) {
11
+ return a.type.localeCompare(b.type);
12
+ }
13
+ return 0;
14
+ });
15
+ };
16
+ xs.forEach((op) => {
17
+ if (op.optgroup) {
18
+ const groupName = op.optgroup;
19
+ if (!grouped[groupName]) {
20
+ grouped[groupName] = [];
21
+ }
22
+ grouped[groupName].push(op);
23
+ }
24
+ else {
25
+ ungrouped.push(op);
26
+ }
27
+ });
28
+ const result = [];
29
+ // Sort group names and each group's contents
30
+ Object.keys(grouped)
31
+ .sort()
32
+ .forEach((groupName) => {
33
+ result.push({
34
+ optgroup: groupName,
35
+ xs: sortItems(grouped[groupName]),
36
+ });
37
+ });
38
+ return [...result, ...sortItems(ungrouped)];
39
+ };
40
+ /**
41
+ * Utility function to add custom styles to a web component's shadow root
42
+ *
43
+ * @param component The web component instance
44
+ * @param styles The styles configuration object
45
+ * @param styleKey The key in styles.customStyles to use for custom styles
46
+ */
47
+ export function applyCustomStyles(component, styles, styleKey) {
48
+ if (!component.shadowRoot || !(styles === null || styles === void 0 ? void 0 : styles.customStyles))
49
+ return;
50
+ const customStyles = styles.customStyles[styleKey];
51
+ if (customStyles) {
52
+ const styleElement = document.createElement('style');
53
+ styleElement.textContent = customStyles;
54
+ // Insert the style element at the beginning of the shadow DOM
55
+ if (component.shadowRoot.firstChild) {
56
+ component.shadowRoot.insertBefore(styleElement, component.shadowRoot.firstChild);
57
+ }
58
+ else {
59
+ component.shadowRoot.appendChild(styleElement);
60
+ }
61
+ }
62
+ }