@molecule/app-rule-builder-angular 0.0.0-stage → 0.0.1-stage
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/LICENSE +202 -0
- package/README.md +10 -2
- package/dist/index.d.ts +66 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/dist/operators.d.ts +61 -0
- package/dist/operators.d.ts.map +1 -0
- package/dist/operators.js +98 -0
- package/dist/operators.js.map +1 -0
- package/dist/rule-builder.component.d.ts +388 -0
- package/dist/rule-builder.component.d.ts.map +1 -0
- package/dist/rule-builder.component.js +991 -0
- package/dist/rule-builder.component.js.map +1 -0
- package/dist/types.d.ts +138 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +16 -0
- package/dist/types.js.map +1 -0
- package/dist/utilities.d.ts +67 -0
- package/dist/utilities.d.ts.map +1 -0
- package/dist/utilities.js +108 -0
- package/dist/utilities.js.map +1 -0
- package/package.json +74 -4
|
@@ -0,0 +1,991 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<RuleBuilder>` component (React parity).
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { NgTemplateOutlet } from '@angular/common';
|
|
7
|
+
import { Component } from '@angular/core';
|
|
8
|
+
import { useTranslation } from '@molecule/app-angular';
|
|
9
|
+
import { getClassMap } from '@molecule/app-ui';
|
|
10
|
+
import { Button, Input, Select, styleText } from '@molecule/app-ui-angular';
|
|
11
|
+
import { operatorById, operatorsFor } from './operators.js';
|
|
12
|
+
import { appendToGroup, emptyGroup, emptyLeaf, removeById, replaceById, toggleGroupOp, } from './utilities.js';
|
|
13
|
+
import * as i0 from "@angular/core";
|
|
14
|
+
const _c0 = () => [];
|
|
15
|
+
const _forTrack0 = ($index, $item) => $item.id;
|
|
16
|
+
function RuleBuilder_ng_template_1_Conditional_6_Template(rf, ctx) { if (rf & 1) {
|
|
17
|
+
const _r6 = i0.ɵɵgetCurrentView();
|
|
18
|
+
i0.ɵɵelementStart(0, "button", 4);
|
|
19
|
+
i0.ɵɵlistener("click", function RuleBuilder_ng_template_1_Conditional_6_Template_button_click_0_listener() { i0.ɵɵrestoreView(_r6); const onRemove_r7 = i0.ɵɵnextContext().onRemove; return i0.ɵɵresetView(onRemove_r7()); });
|
|
20
|
+
i0.ɵɵtext(1);
|
|
21
|
+
i0.ɵɵelementEnd();
|
|
22
|
+
} if (rf & 2) {
|
|
23
|
+
const group_r3 = i0.ɵɵnextContext().$implicit;
|
|
24
|
+
const ctx_r4 = i0.ɵɵnextContext();
|
|
25
|
+
i0.ɵɵproperty("variant", "ghost")("size", "sm");
|
|
26
|
+
i0.ɵɵattribute("aria-label", ctx_r4.removeGroupLabel())("data-mol-id", "rule-builder-group-" + group_r3.id + "-remove");
|
|
27
|
+
i0.ɵɵadvance();
|
|
28
|
+
i0.ɵɵtextInterpolate1(" ", ctx_r4.removeGroupText(), " ");
|
|
29
|
+
} }
|
|
30
|
+
function RuleBuilder_ng_template_1_For_9_Conditional_0_Template(rf, ctx) { if (rf & 1) {
|
|
31
|
+
i0.ɵɵelementContainer(0, 3);
|
|
32
|
+
} if (rf & 2) {
|
|
33
|
+
const child_r8 = i0.ɵɵnextContext().$implicit;
|
|
34
|
+
const ctx_r8 = i0.ɵɵnextContext();
|
|
35
|
+
const group_r3 = ctx_r8.$implicit;
|
|
36
|
+
const onReplace_r4 = ctx_r8.onReplace;
|
|
37
|
+
const ctx_r4 = i0.ɵɵnextContext();
|
|
38
|
+
const groupTpl_r10 = i0.ɵɵreference(2);
|
|
39
|
+
i0.ɵɵproperty("ngTemplateOutlet", groupTpl_r10)("ngTemplateOutletContext", ctx_r4.groupContextOf(group_r3, child_r8, onReplace_r4));
|
|
40
|
+
} }
|
|
41
|
+
function RuleBuilder_ng_template_1_For_9_Conditional_1_Template(rf, ctx) { if (rf & 1) {
|
|
42
|
+
i0.ɵɵelementContainer(0, 3);
|
|
43
|
+
} if (rf & 2) {
|
|
44
|
+
const child_r8 = i0.ɵɵnextContext().$implicit;
|
|
45
|
+
const ctx_r8 = i0.ɵɵnextContext();
|
|
46
|
+
const group_r3 = ctx_r8.$implicit;
|
|
47
|
+
const onReplace_r4 = ctx_r8.onReplace;
|
|
48
|
+
const ctx_r4 = i0.ɵɵnextContext();
|
|
49
|
+
const leafTpl_r11 = i0.ɵɵreference(4);
|
|
50
|
+
i0.ɵɵproperty("ngTemplateOutlet", leafTpl_r11)("ngTemplateOutletContext", ctx_r4.leafContextOf(group_r3, child_r8, onReplace_r4));
|
|
51
|
+
} }
|
|
52
|
+
function RuleBuilder_ng_template_1_For_9_Template(rf, ctx) { if (rf & 1) {
|
|
53
|
+
i0.ɵɵconditionalCreate(0, RuleBuilder_ng_template_1_For_9_Conditional_0_Template, 1, 2, "ng-container", 3)(1, RuleBuilder_ng_template_1_For_9_Conditional_1_Template, 1, 2, "ng-container", 3);
|
|
54
|
+
} if (rf & 2) {
|
|
55
|
+
const child_r8 = ctx.$implicit;
|
|
56
|
+
const ctx_r4 = i0.ɵɵnextContext(2);
|
|
57
|
+
i0.ɵɵconditional(ctx_r4.isGroup(child_r8) ? 0 : 1);
|
|
58
|
+
} }
|
|
59
|
+
function RuleBuilder_ng_template_1_Template(rf, ctx) { if (rf & 1) {
|
|
60
|
+
const _r1 = i0.ɵɵgetCurrentView();
|
|
61
|
+
i0.ɵɵelementStart(0, "div")(1, "div")(2, "button", 4);
|
|
62
|
+
i0.ɵɵlistener("click", function RuleBuilder_ng_template_1_Template_button_click_2_listener() { const ctx_r1 = i0.ɵɵrestoreView(_r1); const group_r3 = ctx_r1.$implicit; const onReplace_r4 = ctx_r1.onReplace; const ctx_r4 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r4.toggle(group_r3, onReplace_r4)); });
|
|
63
|
+
i0.ɵɵtext(3);
|
|
64
|
+
i0.ɵɵelementEnd();
|
|
65
|
+
i0.ɵɵelementStart(4, "span");
|
|
66
|
+
i0.ɵɵtext(5);
|
|
67
|
+
i0.ɵɵelementEnd();
|
|
68
|
+
i0.ɵɵconditionalCreate(6, RuleBuilder_ng_template_1_Conditional_6_Template, 2, 5, "button", 5);
|
|
69
|
+
i0.ɵɵelementEnd();
|
|
70
|
+
i0.ɵɵelementStart(7, "div");
|
|
71
|
+
i0.ɵɵrepeaterCreate(8, RuleBuilder_ng_template_1_For_9_Template, 2, 1, null, null, _forTrack0);
|
|
72
|
+
i0.ɵɵelementEnd();
|
|
73
|
+
i0.ɵɵelementStart(10, "div")(11, "button", 4);
|
|
74
|
+
i0.ɵɵlistener("click", function RuleBuilder_ng_template_1_Template_button_click_11_listener() { const ctx_r11 = i0.ɵɵrestoreView(_r1); const group_r3 = ctx_r11.$implicit; const onReplace_r4 = ctx_r11.onReplace; const ctx_r4 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r4.addCondition(group_r3, onReplace_r4)); });
|
|
75
|
+
i0.ɵɵtext(12);
|
|
76
|
+
i0.ɵɵelementEnd();
|
|
77
|
+
i0.ɵɵelementStart(13, "button", 4);
|
|
78
|
+
i0.ɵɵlistener("click", function RuleBuilder_ng_template_1_Template_button_click_13_listener() { const ctx_r12 = i0.ɵɵrestoreView(_r1); const group_r3 = ctx_r12.$implicit; const onReplace_r4 = ctx_r12.onReplace; const ctx_r4 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r4.addGroup(group_r3, onReplace_r4)); });
|
|
79
|
+
i0.ɵɵtext(14);
|
|
80
|
+
i0.ɵɵelementEnd()()();
|
|
81
|
+
} if (rf & 2) {
|
|
82
|
+
const group_r3 = ctx.$implicit;
|
|
83
|
+
const isRoot_r14 = ctx.isRoot;
|
|
84
|
+
const ctx_r4 = i0.ɵɵnextContext();
|
|
85
|
+
i0.ɵɵstyleMap(ctx_r4.groupStyle());
|
|
86
|
+
i0.ɵɵclassMap(ctx_r4.groupClasses());
|
|
87
|
+
i0.ɵɵattribute("data-mol-id", "rule-builder-group-" + group_r3.id)("data-group-op", group_r3.op);
|
|
88
|
+
i0.ɵɵadvance();
|
|
89
|
+
i0.ɵɵclassMap(ctx_r4.rowClasses());
|
|
90
|
+
i0.ɵɵadvance();
|
|
91
|
+
i0.ɵɵproperty("variant", "outline")("size", "sm");
|
|
92
|
+
i0.ɵɵattribute("aria-label", ctx_r4.toggleLabel())("data-mol-id", "rule-builder-group-" + group_r3.id + "-toggle");
|
|
93
|
+
i0.ɵɵadvance();
|
|
94
|
+
i0.ɵɵtextInterpolate1(" ", ctx_r4.opLabel(group_r3), " ");
|
|
95
|
+
i0.ɵɵadvance();
|
|
96
|
+
i0.ɵɵclassMap(ctx_r4.helpClasses());
|
|
97
|
+
i0.ɵɵadvance();
|
|
98
|
+
i0.ɵɵtextInterpolate(ctx_r4.helpText(group_r3));
|
|
99
|
+
i0.ɵɵadvance();
|
|
100
|
+
i0.ɵɵconditional(!isRoot_r14 ? 6 : -1);
|
|
101
|
+
i0.ɵɵadvance();
|
|
102
|
+
i0.ɵɵstyleMap(ctx_r4.childrenStyle());
|
|
103
|
+
i0.ɵɵclassMap(ctx_r4.childrenClasses());
|
|
104
|
+
i0.ɵɵadvance();
|
|
105
|
+
i0.ɵɵrepeater(group_r3.children);
|
|
106
|
+
i0.ɵɵadvance(2);
|
|
107
|
+
i0.ɵɵclassMap(ctx_r4.rowClasses());
|
|
108
|
+
i0.ɵɵadvance();
|
|
109
|
+
i0.ɵɵproperty("variant", "outline")("size", "sm");
|
|
110
|
+
i0.ɵɵattribute("data-mol-id", "rule-builder-group-" + group_r3.id + "-add-condition");
|
|
111
|
+
i0.ɵɵadvance();
|
|
112
|
+
i0.ɵɵtextInterpolate1(" ", ctx_r4.addConditionText(), " ");
|
|
113
|
+
i0.ɵɵadvance();
|
|
114
|
+
i0.ɵɵproperty("variant", "ghost")("size", "sm");
|
|
115
|
+
i0.ɵɵattribute("data-mol-id", "rule-builder-group-" + group_r3.id + "-add-group");
|
|
116
|
+
i0.ɵɵadvance();
|
|
117
|
+
i0.ɵɵtextInterpolate1(" ", ctx_r4.addGroupText(), " ");
|
|
118
|
+
} }
|
|
119
|
+
function RuleBuilder_ng_template_3_Conditional_2_Conditional_1_Conditional_0_Template(rf, ctx) { if (rf & 1) {
|
|
120
|
+
i0.ɵɵelementContainer(0, 3);
|
|
121
|
+
} if (rf & 2) {
|
|
122
|
+
const field_r21 = i0.ɵɵnextContext(2);
|
|
123
|
+
const ctx_r19 = i0.ɵɵnextContext();
|
|
124
|
+
const leaf_r17 = ctx_r19.$implicit;
|
|
125
|
+
const onReplace_r18 = ctx_r19.onReplace;
|
|
126
|
+
const ctx_r4 = i0.ɵɵnextContext();
|
|
127
|
+
const valueTpl_r22 = i0.ɵɵreference(6);
|
|
128
|
+
i0.ɵɵproperty("ngTemplateOutlet", valueTpl_r22)("ngTemplateOutletContext", ctx_r4.valueContextOf(leaf_r17, field_r21, "between", onReplace_r18));
|
|
129
|
+
} }
|
|
130
|
+
function RuleBuilder_ng_template_3_Conditional_2_Conditional_1_Conditional_1_Template(rf, ctx) { if (rf & 1) {
|
|
131
|
+
i0.ɵɵelementContainer(0, 3);
|
|
132
|
+
} if (rf & 2) {
|
|
133
|
+
const field_r21 = i0.ɵɵnextContext(2);
|
|
134
|
+
const ctx_r19 = i0.ɵɵnextContext();
|
|
135
|
+
const leaf_r17 = ctx_r19.$implicit;
|
|
136
|
+
const onReplace_r18 = ctx_r19.onReplace;
|
|
137
|
+
const ctx_r4 = i0.ɵɵnextContext();
|
|
138
|
+
const valueTpl_r22 = i0.ɵɵreference(6);
|
|
139
|
+
i0.ɵɵproperty("ngTemplateOutlet", valueTpl_r22)("ngTemplateOutletContext", ctx_r4.valueContextOf(leaf_r17, field_r21, "binary", onReplace_r18));
|
|
140
|
+
} }
|
|
141
|
+
function RuleBuilder_ng_template_3_Conditional_2_Conditional_1_Template(rf, ctx) { if (rf & 1) {
|
|
142
|
+
i0.ɵɵconditionalCreate(0, RuleBuilder_ng_template_3_Conditional_2_Conditional_1_Conditional_0_Template, 1, 2, "ng-container", 3)(1, RuleBuilder_ng_template_3_Conditional_2_Conditional_1_Conditional_1_Template, 1, 2, "ng-container", 3);
|
|
143
|
+
} if (rf & 2) {
|
|
144
|
+
const op_r23 = ctx;
|
|
145
|
+
const ctx_r4 = i0.ɵɵnextContext(3);
|
|
146
|
+
i0.ɵɵconditional(ctx_r4.arityOf(op_r23) === "between" ? 0 : ctx_r4.arityOf(op_r23) === "binary" ? 1 : -1);
|
|
147
|
+
} }
|
|
148
|
+
function RuleBuilder_ng_template_3_Conditional_2_Template(rf, ctx) { if (rf & 1) {
|
|
149
|
+
const _r19 = i0.ɵɵgetCurrentView();
|
|
150
|
+
i0.ɵɵelementStart(0, "div", 6);
|
|
151
|
+
i0.ɵɵlistener("valueChange", function RuleBuilder_ng_template_3_Conditional_2_Template_div_valueChange_0_listener($event) { i0.ɵɵrestoreView(_r19); const ctx_r19 = i0.ɵɵnextContext(); const leaf_r17 = ctx_r19.$implicit; const onReplace_r18 = ctx_r19.onReplace; const ctx_r4 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r4.setOp(leaf_r17, onReplace_r18, $event)); });
|
|
152
|
+
i0.ɵɵelementEnd();
|
|
153
|
+
i0.ɵɵconditionalCreate(1, RuleBuilder_ng_template_3_Conditional_2_Conditional_1_Template, 2, 1);
|
|
154
|
+
} if (rf & 2) {
|
|
155
|
+
let tmp_13_0;
|
|
156
|
+
const field_r21 = ctx;
|
|
157
|
+
const leaf_r17 = i0.ɵɵnextContext().$implicit;
|
|
158
|
+
const ctx_r4 = i0.ɵɵnextContext();
|
|
159
|
+
i0.ɵɵproperty("id", leaf_r17.id + "-op")("value", leaf_r17.op)("options", ctx_r4.operatorOptions(field_r21));
|
|
160
|
+
i0.ɵɵattribute("aria-label", ctx_r4.operatorLabel());
|
|
161
|
+
i0.ɵɵadvance();
|
|
162
|
+
i0.ɵɵconditional((tmp_13_0 = ctx_r4.opOf(field_r21, leaf_r17)) ? 1 : -1, tmp_13_0);
|
|
163
|
+
} }
|
|
164
|
+
function RuleBuilder_ng_template_3_Template(rf, ctx) { if (rf & 1) {
|
|
165
|
+
const _r15 = i0.ɵɵgetCurrentView();
|
|
166
|
+
i0.ɵɵelementStart(0, "div")(1, "div", 6);
|
|
167
|
+
i0.ɵɵlistener("valueChange", function RuleBuilder_ng_template_3_Template_div_valueChange_1_listener($event) { const ctx_r15 = i0.ɵɵrestoreView(_r15); const leaf_r17 = ctx_r15.$implicit; const onReplace_r18 = ctx_r15.onReplace; const ctx_r4 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r4.setField(leaf_r17, onReplace_r18, $event)); });
|
|
168
|
+
i0.ɵɵelementEnd();
|
|
169
|
+
i0.ɵɵconditionalCreate(2, RuleBuilder_ng_template_3_Conditional_2_Template, 2, 5);
|
|
170
|
+
i0.ɵɵelementStart(3, "button", 4);
|
|
171
|
+
i0.ɵɵlistener("click", function RuleBuilder_ng_template_3_Template_button_click_3_listener() { const onRemove_r24 = i0.ɵɵrestoreView(_r15).onRemove; return i0.ɵɵresetView(onRemove_r24()); });
|
|
172
|
+
i0.ɵɵtext(4);
|
|
173
|
+
i0.ɵɵelementEnd()();
|
|
174
|
+
} if (rf & 2) {
|
|
175
|
+
let tmp_13_0;
|
|
176
|
+
const leaf_r17 = ctx.$implicit;
|
|
177
|
+
const ctx_r4 = i0.ɵɵnextContext();
|
|
178
|
+
i0.ɵɵclassMap(ctx_r4.leafClasses());
|
|
179
|
+
i0.ɵɵattribute("data-mol-id", "rule-builder-leaf-" + leaf_r17.id);
|
|
180
|
+
i0.ɵɵadvance();
|
|
181
|
+
i0.ɵɵproperty("id", leaf_r17.id + "-field")("value", leaf_r17.field)("options", ctx_r4.fieldOptions());
|
|
182
|
+
i0.ɵɵattribute("aria-label", ctx_r4.fieldLabel());
|
|
183
|
+
i0.ɵɵadvance();
|
|
184
|
+
i0.ɵɵconditional((tmp_13_0 = ctx_r4.fieldOf(leaf_r17)) ? 2 : -1, tmp_13_0);
|
|
185
|
+
i0.ɵɵadvance();
|
|
186
|
+
i0.ɵɵproperty("variant", "ghost")("size", "sm");
|
|
187
|
+
i0.ɵɵattribute("aria-label", ctx_r4.removeConditionLabel())("data-mol-id", "rule-builder-leaf-" + leaf_r17.id + "-remove");
|
|
188
|
+
i0.ɵɵadvance();
|
|
189
|
+
i0.ɵɵtextInterpolate1(" ", ctx_r4.removeConditionText(), " ");
|
|
190
|
+
} }
|
|
191
|
+
function RuleBuilder_ng_template_5_Conditional_0_Template(rf, ctx) { if (rf & 1) {
|
|
192
|
+
const _r25 = i0.ɵɵgetCurrentView();
|
|
193
|
+
i0.ɵɵelementStart(0, "span")(1, "div", 10);
|
|
194
|
+
i0.ɵɵlistener("change", function RuleBuilder_ng_template_5_Conditional_0_Template_div_change_1_listener($event) { i0.ɵɵrestoreView(_r25); const ctx_r25 = i0.ɵɵnextContext(); const field_r27 = ctx_r25.field; const value_r28 = ctx_r25.value; const onChange_r29 = ctx_r25.onChange; const ctx_r4 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r4.setFrom(field_r27, value_r28, onChange_r29, $event)); });
|
|
195
|
+
i0.ɵɵelementEnd();
|
|
196
|
+
i0.ɵɵelementStart(2, "span");
|
|
197
|
+
i0.ɵɵtext(3);
|
|
198
|
+
i0.ɵɵelementEnd();
|
|
199
|
+
i0.ɵɵelementStart(4, "div", 10);
|
|
200
|
+
i0.ɵɵlistener("change", function RuleBuilder_ng_template_5_Conditional_0_Template_div_change_4_listener($event) { i0.ɵɵrestoreView(_r25); const ctx_r25 = i0.ɵɵnextContext(); const field_r27 = ctx_r25.field; const value_r28 = ctx_r25.value; const onChange_r29 = ctx_r25.onChange; const ctx_r4 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r4.setTo(field_r27, value_r28, onChange_r29, $event)); });
|
|
201
|
+
i0.ɵɵelementEnd()();
|
|
202
|
+
} if (rf & 2) {
|
|
203
|
+
const ctx_r25 = i0.ɵɵnextContext();
|
|
204
|
+
const id_r30 = ctx_r25.id;
|
|
205
|
+
const field_r27 = ctx_r25.field;
|
|
206
|
+
const value_r28 = ctx_r25.value;
|
|
207
|
+
const ctx_r4 = i0.ɵɵnextContext();
|
|
208
|
+
i0.ɵɵclassMap(ctx_r4.rowClasses());
|
|
209
|
+
i0.ɵɵadvance();
|
|
210
|
+
i0.ɵɵproperty("id", id_r30 + "-from")("type", ctx_r4.inputType(field_r27))("value", ctx_r4.fromText(field_r27, value_r28));
|
|
211
|
+
i0.ɵɵattribute("aria-label", ctx_r4.fromLabel());
|
|
212
|
+
i0.ɵɵadvance(2);
|
|
213
|
+
i0.ɵɵtextInterpolate(ctx_r4.separatorText());
|
|
214
|
+
i0.ɵɵadvance();
|
|
215
|
+
i0.ɵɵproperty("id", id_r30 + "-to")("type", ctx_r4.inputType(field_r27))("value", ctx_r4.toText(field_r27, value_r28));
|
|
216
|
+
i0.ɵɵattribute("aria-label", ctx_r4.toLabel());
|
|
217
|
+
} }
|
|
218
|
+
function RuleBuilder_ng_template_5_Conditional_1_Template(rf, ctx) { if (rf & 1) {
|
|
219
|
+
const _r31 = i0.ɵɵgetCurrentView();
|
|
220
|
+
i0.ɵɵelementStart(0, "div", 6);
|
|
221
|
+
i0.ɵɵlistener("valueChange", function RuleBuilder_ng_template_5_Conditional_1_Template_div_valueChange_0_listener($event) { i0.ɵɵrestoreView(_r31); const onChange_r29 = i0.ɵɵnextContext().onChange; return i0.ɵɵresetView(onChange_r29($event)); });
|
|
222
|
+
i0.ɵɵelementEnd();
|
|
223
|
+
} if (rf & 2) {
|
|
224
|
+
const ctx_r25 = i0.ɵɵnextContext();
|
|
225
|
+
const id_r30 = ctx_r25.id;
|
|
226
|
+
const field_r27 = ctx_r25.field;
|
|
227
|
+
const value_r28 = ctx_r25.value;
|
|
228
|
+
const ctx_r4 = i0.ɵɵnextContext();
|
|
229
|
+
i0.ɵɵproperty("id", id_r30 + "-value")("value", ctx_r4.selectValue(value_r28))("options", field_r27.options ?? i0.ɵɵpureFunction0(4, _c0));
|
|
230
|
+
i0.ɵɵattribute("aria-label", ctx_r4.valueLabel());
|
|
231
|
+
} }
|
|
232
|
+
function RuleBuilder_ng_template_5_Conditional_2_Template(rf, ctx) { if (rf & 1) {
|
|
233
|
+
const _r32 = i0.ɵɵgetCurrentView();
|
|
234
|
+
i0.ɵɵelementStart(0, "div", 6);
|
|
235
|
+
i0.ɵɵlistener("valueChange", function RuleBuilder_ng_template_5_Conditional_2_Template_div_valueChange_0_listener($event) { i0.ɵɵrestoreView(_r32); const onChange_r29 = i0.ɵɵnextContext().onChange; const ctx_r4 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r4.setBoolean(onChange_r29, $event)); });
|
|
236
|
+
i0.ɵɵelementEnd();
|
|
237
|
+
} if (rf & 2) {
|
|
238
|
+
const ctx_r25 = i0.ɵɵnextContext();
|
|
239
|
+
const id_r30 = ctx_r25.id;
|
|
240
|
+
const value_r28 = ctx_r25.value;
|
|
241
|
+
const ctx_r4 = i0.ɵɵnextContext();
|
|
242
|
+
i0.ɵɵproperty("id", id_r30 + "-value")("value", ctx_r4.booleanValue(value_r28))("options", ctx_r4.booleanOptions());
|
|
243
|
+
i0.ɵɵattribute("aria-label", ctx_r4.valueLabel());
|
|
244
|
+
} }
|
|
245
|
+
function RuleBuilder_ng_template_5_Conditional_3_Template(rf, ctx) { if (rf & 1) {
|
|
246
|
+
const _r33 = i0.ɵɵgetCurrentView();
|
|
247
|
+
i0.ɵɵelementStart(0, "div", 11);
|
|
248
|
+
i0.ɵɵlistener("change", function RuleBuilder_ng_template_5_Conditional_3_Template_div_change_0_listener($event) { i0.ɵɵrestoreView(_r33); const ctx_r25 = i0.ɵɵnextContext(); const field_r27 = ctx_r25.field; const onChange_r29 = ctx_r25.onChange; const ctx_r4 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r4.setRawValue(field_r27, onChange_r29, $event)); });
|
|
249
|
+
i0.ɵɵelementEnd();
|
|
250
|
+
} if (rf & 2) {
|
|
251
|
+
const ctx_r25 = i0.ɵɵnextContext();
|
|
252
|
+
const id_r30 = ctx_r25.id;
|
|
253
|
+
const field_r27 = ctx_r25.field;
|
|
254
|
+
const value_r28 = ctx_r25.value;
|
|
255
|
+
const ctx_r4 = i0.ɵɵnextContext();
|
|
256
|
+
i0.ɵɵproperty("id", id_r30 + "-value")("type", ctx_r4.inputType(field_r27))("value", ctx_r4.valueText(value_r28))("placeholder", field_r27.placeholder);
|
|
257
|
+
i0.ɵɵattribute("aria-label", ctx_r4.valueLabel());
|
|
258
|
+
} }
|
|
259
|
+
function RuleBuilder_ng_template_5_Template(rf, ctx) { if (rf & 1) {
|
|
260
|
+
i0.ɵɵconditionalCreate(0, RuleBuilder_ng_template_5_Conditional_0_Template, 5, 11, "span", 7)(1, RuleBuilder_ng_template_5_Conditional_1_Template, 1, 5, "div", 8)(2, RuleBuilder_ng_template_5_Conditional_2_Template, 1, 4, "div", 8)(3, RuleBuilder_ng_template_5_Conditional_3_Template, 1, 5, "div", 9);
|
|
261
|
+
} if (rf & 2) {
|
|
262
|
+
const field_r27 = ctx.field;
|
|
263
|
+
const arity_r34 = ctx.arity;
|
|
264
|
+
i0.ɵɵconditional(arity_r34 === "between" ? 0 : field_r27.type === "select" ? 1 : field_r27.type === "boolean" ? 2 : 3);
|
|
265
|
+
} }
|
|
266
|
+
/**
|
|
267
|
+
* Visual rule / predicate builder.
|
|
268
|
+
*
|
|
269
|
+
* The host IS the outer `<div>` React renders (`div[mol-rule-builder]`),
|
|
270
|
+
* matching React exactly. The page frame uses ClassMap tokens so the styling
|
|
271
|
+
* library can be swapped without touching consumers; a recursive
|
|
272
|
+
* `<ng-template>` renders each AND / OR group, so the tree nests to any depth.
|
|
273
|
+
*
|
|
274
|
+
* The component is fully controlled — every interaction emits a new root rule
|
|
275
|
+
* through the `onChange` input.
|
|
276
|
+
*/
|
|
277
|
+
export class RuleBuilder {
|
|
278
|
+
/** Field catalog the user picks from. */
|
|
279
|
+
schema = { fields: [] };
|
|
280
|
+
/** Current rule tree (controlled). */
|
|
281
|
+
rules = { kind: 'leaf', id: '', field: '', op: '' };
|
|
282
|
+
/** Called whenever the user mutates the tree, with the full new root rule. */
|
|
283
|
+
onChange;
|
|
284
|
+
/** Optional extra root-level class. */
|
|
285
|
+
className;
|
|
286
|
+
/**
|
|
287
|
+
* Reactive translation, read in the injection context so the view re-renders
|
|
288
|
+
* its text (and its aria labels) on a locale switch.
|
|
289
|
+
*/
|
|
290
|
+
i18n = useTranslation();
|
|
291
|
+
/**
|
|
292
|
+
* The bonded ClassMap (styling tokens resolve at render time).
|
|
293
|
+
* @returns The UIClassMap.
|
|
294
|
+
*/
|
|
295
|
+
cm() {
|
|
296
|
+
return getClassMap();
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* The rendered root group: the given tree itself when it is a group,
|
|
300
|
+
* otherwise an implicit AND group wrapping the bare leaf (React's
|
|
301
|
+
* `rules.kind === 'group' ? rules : {...}`).
|
|
302
|
+
* @returns The root group.
|
|
303
|
+
*/
|
|
304
|
+
rootGroup() {
|
|
305
|
+
return this.rules.kind === 'group'
|
|
306
|
+
? this.rules
|
|
307
|
+
: { kind: 'group', id: 'root', op: 'AND', children: [this.rules] };
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* The root group's template context.
|
|
311
|
+
* @returns The group context.
|
|
312
|
+
*/
|
|
313
|
+
rootContext() {
|
|
314
|
+
return {
|
|
315
|
+
$implicit: this.rootGroup(),
|
|
316
|
+
isRoot: true,
|
|
317
|
+
onReplace: (next) => this.onChange?.(next),
|
|
318
|
+
onRemove: () => this.onChange?.(emptyGroup()),
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Narrows a rule to a group.
|
|
323
|
+
* @param rule - The rule.
|
|
324
|
+
* @returns Whether it is a group.
|
|
325
|
+
*/
|
|
326
|
+
isGroup(rule) {
|
|
327
|
+
return rule.kind === 'group';
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* The next tree after `child` is replaced inside `parent` (React's
|
|
331
|
+
* `replaceChild` closure).
|
|
332
|
+
* @param parent - The parent group.
|
|
333
|
+
* @param child - The child being replaced.
|
|
334
|
+
* @param onReplace - The parent's own replacement callback.
|
|
335
|
+
* @returns The child replacement callback.
|
|
336
|
+
*/
|
|
337
|
+
childReplace(parent, child, onReplace) {
|
|
338
|
+
return (next) => onReplace(replaceById(parent, child.id, next));
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* The next tree after `child` is removed from `parent` (React's
|
|
342
|
+
* `removeChild` closure).
|
|
343
|
+
* @param parent - The parent group.
|
|
344
|
+
* @param child - The child being removed.
|
|
345
|
+
* @param onReplace - The parent's own replacement callback.
|
|
346
|
+
* @returns The child removal callback.
|
|
347
|
+
*/
|
|
348
|
+
childRemove(parent, child, onReplace) {
|
|
349
|
+
return () => onReplace(removeById(parent, child.id));
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* The template context of a nested group.
|
|
353
|
+
* @param parent - The enclosing group.
|
|
354
|
+
* @param child - The nested group.
|
|
355
|
+
* @param onReplace - The enclosing group's replacement callback.
|
|
356
|
+
* @returns The group context.
|
|
357
|
+
*/
|
|
358
|
+
groupContextOf(parent, child, onReplace) {
|
|
359
|
+
return {
|
|
360
|
+
$implicit: child,
|
|
361
|
+
isRoot: false,
|
|
362
|
+
onReplace: this.childReplace(parent, child, onReplace),
|
|
363
|
+
onRemove: this.childRemove(parent, child, onReplace),
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* The template context of a leaf.
|
|
368
|
+
* @param parent - The enclosing group.
|
|
369
|
+
* @param child - The leaf.
|
|
370
|
+
* @param onReplace - The enclosing group's replacement callback.
|
|
371
|
+
* @returns The leaf context.
|
|
372
|
+
*/
|
|
373
|
+
leafContextOf(parent, child, onReplace) {
|
|
374
|
+
return {
|
|
375
|
+
$implicit: child,
|
|
376
|
+
onReplace: this.childReplace(parent, child, onReplace),
|
|
377
|
+
onRemove: this.childRemove(parent, child, onReplace),
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* The template context of a leaf's value editor.
|
|
382
|
+
* @param leaf - The leaf that owns the value.
|
|
383
|
+
* @param field - The leaf's field descriptor.
|
|
384
|
+
* @param arity - The operator's arity.
|
|
385
|
+
* @param onReplace - The leaf's replacement callback.
|
|
386
|
+
* @returns The value-editor context.
|
|
387
|
+
*/
|
|
388
|
+
valueContextOf(leaf, field, arity, onReplace) {
|
|
389
|
+
return {
|
|
390
|
+
id: leaf.id,
|
|
391
|
+
field,
|
|
392
|
+
arity,
|
|
393
|
+
value: leaf.value,
|
|
394
|
+
onChange: (value) => onReplace({ ...leaf, value }),
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Flips a group's operator between AND and OR.
|
|
399
|
+
* @param group - The group.
|
|
400
|
+
* @param onReplace - The group's replacement callback.
|
|
401
|
+
*/
|
|
402
|
+
toggle(group, onReplace) {
|
|
403
|
+
onReplace(toggleGroupOp(group, group.id));
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Appends an empty leaf to a group.
|
|
407
|
+
* @param group - The group.
|
|
408
|
+
* @param onReplace - The group's replacement callback.
|
|
409
|
+
*/
|
|
410
|
+
addCondition(group, onReplace) {
|
|
411
|
+
onReplace(appendToGroup(group, group.id, emptyLeaf()));
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Appends an empty nested group to a group.
|
|
415
|
+
* @param group - The group.
|
|
416
|
+
* @param onReplace - The group's replacement callback.
|
|
417
|
+
*/
|
|
418
|
+
addGroup(group, onReplace) {
|
|
419
|
+
onReplace(appendToGroup(group, group.id, emptyGroup()));
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* The field descriptor a leaf names, if the schema has it.
|
|
423
|
+
* @param leaf - The leaf.
|
|
424
|
+
* @returns The field, or undefined.
|
|
425
|
+
*/
|
|
426
|
+
fieldOf(leaf) {
|
|
427
|
+
return this.schema.fields.find((f) => f.name === leaf.field);
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* The operator descriptor a leaf names within its field's catalog.
|
|
431
|
+
* @param field - The leaf's field.
|
|
432
|
+
* @param leaf - The leaf.
|
|
433
|
+
* @returns The operator, or undefined.
|
|
434
|
+
*/
|
|
435
|
+
opOf(field, leaf) {
|
|
436
|
+
return operatorById(field, leaf.op);
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* An operator's value arity (React's `op?.arity ?? 'binary'`).
|
|
440
|
+
* @param op - The operator.
|
|
441
|
+
* @returns The arity.
|
|
442
|
+
*/
|
|
443
|
+
arityOf(op) {
|
|
444
|
+
return op?.arity ?? 'binary';
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Sets a leaf's field and auto-picks the field's first operator.
|
|
448
|
+
* @param leaf - The leaf.
|
|
449
|
+
* @param onReplace - The leaf's replacement callback.
|
|
450
|
+
* @param name - The field name.
|
|
451
|
+
*/
|
|
452
|
+
setField(leaf, onReplace, name) {
|
|
453
|
+
const field = this.schema.fields.find((f) => f.name === name);
|
|
454
|
+
const firstOp = field ? operatorsFor(field)[0] : undefined;
|
|
455
|
+
onReplace({ ...leaf, field: name, op: firstOp?.id ?? '', value: undefined });
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Sets a leaf's operator, resetting its value.
|
|
459
|
+
* @param leaf - The leaf.
|
|
460
|
+
* @param onReplace - The leaf's replacement callback.
|
|
461
|
+
* @param opId - The operator id.
|
|
462
|
+
*/
|
|
463
|
+
setOp(leaf, onReplace, opId) {
|
|
464
|
+
onReplace({ ...leaf, op: opId, value: undefined });
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* The value inputs' type for a field (React's `inputType`).
|
|
468
|
+
* @param field - The field.
|
|
469
|
+
* @returns The native input type.
|
|
470
|
+
*/
|
|
471
|
+
inputType(field) {
|
|
472
|
+
return field.type === 'date' ? 'date' : field.type === 'number' ? 'number' : 'text';
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* The `[from, to]` tuple of a between-valued leaf, with React's fallbacks.
|
|
476
|
+
* @param field - The field.
|
|
477
|
+
* @param value - The leaf's value.
|
|
478
|
+
* @returns The tuple.
|
|
479
|
+
*/
|
|
480
|
+
tupleOf(field, value) {
|
|
481
|
+
if (Array.isArray(value) && value.length === 2)
|
|
482
|
+
return value;
|
|
483
|
+
return field.type === 'number' ? [0, 0] : ['', ''];
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* The "from" input's text.
|
|
487
|
+
* @param field - The field.
|
|
488
|
+
* @param value - The leaf's value.
|
|
489
|
+
* @returns The text.
|
|
490
|
+
*/
|
|
491
|
+
fromText(field, value) {
|
|
492
|
+
return String(this.tupleOf(field, value)[0] ?? '');
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* The "to" input's text.
|
|
496
|
+
* @param field - The field.
|
|
497
|
+
* @param value - The leaf's value.
|
|
498
|
+
* @returns The text.
|
|
499
|
+
*/
|
|
500
|
+
toText(field, value) {
|
|
501
|
+
return String(this.tupleOf(field, value)[1] ?? '');
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Writes the "from" half of a between value.
|
|
505
|
+
* @param field - The field.
|
|
506
|
+
* @param value - The leaf's current value.
|
|
507
|
+
* @param onChange - Receives the next value.
|
|
508
|
+
* @param event - The native input event.
|
|
509
|
+
*/
|
|
510
|
+
setFrom(field, value, onChange, event) {
|
|
511
|
+
const raw = event.target.value;
|
|
512
|
+
const tuple = this.tupleOf(field, value);
|
|
513
|
+
onChange((field.type === 'number'
|
|
514
|
+
? [Number(raw), tuple[1]]
|
|
515
|
+
: [raw, tuple[1]]));
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Writes the "to" half of a between value.
|
|
519
|
+
* @param field - The field.
|
|
520
|
+
* @param value - The leaf's current value.
|
|
521
|
+
* @param onChange - Receives the next value.
|
|
522
|
+
* @param event - The native input event.
|
|
523
|
+
*/
|
|
524
|
+
setTo(field, value, onChange, event) {
|
|
525
|
+
const raw = event.target.value;
|
|
526
|
+
const tuple = this.tupleOf(field, value);
|
|
527
|
+
onChange((field.type === 'number'
|
|
528
|
+
? [tuple[0], Number(raw)]
|
|
529
|
+
: [tuple[0], raw]));
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Writes a select field's value.
|
|
533
|
+
* @param value - The leaf's current value.
|
|
534
|
+
* @returns The select's value.
|
|
535
|
+
*/
|
|
536
|
+
selectValue(value) {
|
|
537
|
+
return typeof value === 'string' ? value : '';
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Writes a boolean field's select value.
|
|
541
|
+
* @param value - The leaf's current value.
|
|
542
|
+
* @returns The select's value.
|
|
543
|
+
*/
|
|
544
|
+
booleanValue(value) {
|
|
545
|
+
return value === true ? 'true' : value === false ? 'false' : '';
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Writes a boolean value from the select's chosen text.
|
|
549
|
+
* @param onChange - Receives the next value.
|
|
550
|
+
* @param chosen - The chosen option value.
|
|
551
|
+
*/
|
|
552
|
+
setBoolean(onChange, chosen) {
|
|
553
|
+
onChange(chosen === 'true');
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* A binary text / number / date value as input text.
|
|
557
|
+
* @param value - The leaf's value.
|
|
558
|
+
* @returns The input text.
|
|
559
|
+
*/
|
|
560
|
+
valueText(value) {
|
|
561
|
+
return value === undefined ? '' : String(value);
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Writes a binary text / number / date value from the input.
|
|
565
|
+
* @param field - The field.
|
|
566
|
+
* @param onChange - Receives the next value.
|
|
567
|
+
* @param event - The native input event.
|
|
568
|
+
*/
|
|
569
|
+
setRawValue(field, onChange, event) {
|
|
570
|
+
const raw = event.target.value;
|
|
571
|
+
onChange(field.type === 'number' ? Number(raw) : raw);
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* The field dropdown's options, with the placeholder first.
|
|
575
|
+
* @returns The options.
|
|
576
|
+
*/
|
|
577
|
+
fieldOptions() {
|
|
578
|
+
return [
|
|
579
|
+
{
|
|
580
|
+
value: '',
|
|
581
|
+
label: this.i18n.t('ruleBuilder.field.placeholder', {}, { defaultValue: 'Select field…' }),
|
|
582
|
+
},
|
|
583
|
+
...this.schema.fields.map((f) => ({ value: f.name, label: f.label })),
|
|
584
|
+
];
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* The operator dropdown's options for a field.
|
|
588
|
+
* @param field - The field.
|
|
589
|
+
* @returns The options.
|
|
590
|
+
*/
|
|
591
|
+
operatorOptions(field) {
|
|
592
|
+
return operatorsFor(field).map((o) => ({ value: o.id, label: o.label }));
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* The boolean value dropdown's options.
|
|
596
|
+
* @returns The options.
|
|
597
|
+
*/
|
|
598
|
+
booleanOptions() {
|
|
599
|
+
return [
|
|
600
|
+
{
|
|
601
|
+
value: 'true',
|
|
602
|
+
label: this.i18n.t('ruleBuilder.boolean.true', {}, { defaultValue: 'true' }),
|
|
603
|
+
},
|
|
604
|
+
{
|
|
605
|
+
value: 'false',
|
|
606
|
+
label: this.i18n.t('ruleBuilder.boolean.false', {}, { defaultValue: 'false' }),
|
|
607
|
+
},
|
|
608
|
+
];
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* The outer class list.
|
|
612
|
+
* @returns The class string.
|
|
613
|
+
*/
|
|
614
|
+
classes() {
|
|
615
|
+
return this.cm().cn(this.cm().flex({ direction: 'col', gap: 'sm' }), this.className);
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* One group's class list.
|
|
619
|
+
* @returns The class string.
|
|
620
|
+
*/
|
|
621
|
+
groupClasses() {
|
|
622
|
+
return this.cm().cn(this.cm().flex({ direction: 'col', gap: 'xs' }), this.cm().borderAll, this.cm().surface);
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* One group's inline style (React's `style={cm.sp({ p: 3 })}`).
|
|
626
|
+
* @returns The style attribute text.
|
|
627
|
+
*/
|
|
628
|
+
groupStyle() {
|
|
629
|
+
return styleText(this.cm().sp({ p: 3 }));
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* A group's children wrapper class list.
|
|
633
|
+
* @returns The class string.
|
|
634
|
+
*/
|
|
635
|
+
childrenClasses() {
|
|
636
|
+
return this.cm().flex({ direction: 'col', gap: 'xs' });
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* A group's children wrapper inline style (React's `cm.sp({ p: 2 })`).
|
|
640
|
+
* @returns The style attribute text.
|
|
641
|
+
*/
|
|
642
|
+
childrenStyle() {
|
|
643
|
+
return styleText(this.cm().sp({ p: 2 }));
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* A row of controls' class list.
|
|
647
|
+
* @returns The class string.
|
|
648
|
+
*/
|
|
649
|
+
rowClasses() {
|
|
650
|
+
return this.cm().flex({ align: 'center', gap: 'xs' });
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* The help text's class list.
|
|
654
|
+
* @returns The class string.
|
|
655
|
+
*/
|
|
656
|
+
helpClasses() {
|
|
657
|
+
return this.cm().cn(this.cm().textSize('xs'), this.cm().textMuted);
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* A leaf row's class list.
|
|
661
|
+
* @returns The class string.
|
|
662
|
+
*/
|
|
663
|
+
leafClasses() {
|
|
664
|
+
return this.cm().flex({ align: 'center', gap: 'xs', wrap: 'wrap' });
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* A group's operator label.
|
|
668
|
+
* @param group - The group.
|
|
669
|
+
* @returns The translated label.
|
|
670
|
+
*/
|
|
671
|
+
opLabel(group) {
|
|
672
|
+
return group.op === 'AND'
|
|
673
|
+
? this.i18n.t('ruleBuilder.op.and', {}, { defaultValue: 'AND' })
|
|
674
|
+
: this.i18n.t('ruleBuilder.op.or', {}, { defaultValue: 'OR' });
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* A group's help text.
|
|
678
|
+
* @param group - The group.
|
|
679
|
+
* @returns The translated help text.
|
|
680
|
+
*/
|
|
681
|
+
helpText(group) {
|
|
682
|
+
const op = group.op;
|
|
683
|
+
return op === 'AND'
|
|
684
|
+
? this.i18n.t('ruleBuilder.help.allMustMatch', {}, {
|
|
685
|
+
defaultValue: 'All conditions must match',
|
|
686
|
+
})
|
|
687
|
+
: this.i18n.t('ruleBuilder.help.anyMustMatch', {}, {
|
|
688
|
+
defaultValue: 'Any condition may match',
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* The toggle button's accessible label.
|
|
693
|
+
* @returns The translated label.
|
|
694
|
+
*/
|
|
695
|
+
toggleLabel() {
|
|
696
|
+
return this.i18n.t('ruleBuilder.aria.toggleOp', {}, { defaultValue: 'Toggle AND / OR' });
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* The nested group's remove button accessible label.
|
|
700
|
+
* @returns The translated label.
|
|
701
|
+
*/
|
|
702
|
+
removeGroupLabel() {
|
|
703
|
+
return this.i18n.t('ruleBuilder.aria.removeGroup', {}, { defaultValue: 'Remove group' });
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* The nested group's remove button text.
|
|
707
|
+
* @returns The translated text.
|
|
708
|
+
*/
|
|
709
|
+
removeGroupText() {
|
|
710
|
+
return this.i18n.t('ruleBuilder.action.removeGroup', {}, { defaultValue: 'Remove group' });
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* The "Add condition" button text.
|
|
714
|
+
* @returns The translated text.
|
|
715
|
+
*/
|
|
716
|
+
addConditionText() {
|
|
717
|
+
return this.i18n.t('ruleBuilder.action.addCondition', {}, { defaultValue: '+ Add condition' });
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* The "Add group" button text.
|
|
721
|
+
* @returns The translated text.
|
|
722
|
+
*/
|
|
723
|
+
addGroupText() {
|
|
724
|
+
return this.i18n.t('ruleBuilder.action.addGroup', {}, { defaultValue: '+ Add group' });
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* The field dropdown's accessible label.
|
|
728
|
+
* @returns The translated label.
|
|
729
|
+
*/
|
|
730
|
+
fieldLabel() {
|
|
731
|
+
return this.i18n.t('ruleBuilder.aria.field', {}, { defaultValue: 'Field' });
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* The operator dropdown's accessible label.
|
|
735
|
+
* @returns The translated label.
|
|
736
|
+
*/
|
|
737
|
+
operatorLabel() {
|
|
738
|
+
return this.i18n.t('ruleBuilder.aria.operator', {}, { defaultValue: 'Operator' });
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* The value editor's accessible label.
|
|
742
|
+
* @returns The translated label.
|
|
743
|
+
*/
|
|
744
|
+
valueLabel() {
|
|
745
|
+
return this.i18n.t('ruleBuilder.aria.value', {}, { defaultValue: 'Value' });
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* The "from" input's accessible label.
|
|
749
|
+
* @returns The translated label.
|
|
750
|
+
*/
|
|
751
|
+
fromLabel() {
|
|
752
|
+
return this.i18n.t('ruleBuilder.aria.valueFrom', {}, { defaultValue: 'From' });
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* The "to" input's accessible label.
|
|
756
|
+
* @returns The translated label.
|
|
757
|
+
*/
|
|
758
|
+
toLabel() {
|
|
759
|
+
return this.i18n.t('ruleBuilder.aria.valueTo', {}, { defaultValue: 'To' });
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* The between separator text.
|
|
763
|
+
* @returns The translated separator.
|
|
764
|
+
*/
|
|
765
|
+
separatorText() {
|
|
766
|
+
return this.i18n.t('ruleBuilder.between.separator', {}, { defaultValue: '–' });
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* The remove-condition button's accessible label.
|
|
770
|
+
* @returns The translated label.
|
|
771
|
+
*/
|
|
772
|
+
removeConditionLabel() {
|
|
773
|
+
return this.i18n.t('ruleBuilder.aria.removeCondition', {}, {
|
|
774
|
+
defaultValue: 'Remove condition',
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* The remove-condition button's text.
|
|
779
|
+
* @returns The translated text.
|
|
780
|
+
*/
|
|
781
|
+
removeConditionText() {
|
|
782
|
+
return this.i18n.t('ruleBuilder.action.removeCondition', {}, { defaultValue: 'Remove' });
|
|
783
|
+
}
|
|
784
|
+
static ɵfac = function RuleBuilder_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || RuleBuilder)(); };
|
|
785
|
+
static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: RuleBuilder, selectors: [["div", "mol-rule-builder", ""]], hostAttrs: ["data-mol-id", "rule-builder"], hostVars: 2, hostBindings: function RuleBuilder_HostBindings(rf, ctx) { if (rf & 2) {
|
|
786
|
+
i0.ɵɵclassMap(ctx.classes());
|
|
787
|
+
} }, inputs: { schema: "schema", rules: "rules", onChange: "onChange", className: "className" }, decls: 7, vars: 2, consts: [["groupTpl", ""], ["leafTpl", ""], ["valueTpl", ""], [3, "ngTemplateOutlet", "ngTemplateOutletContext"], ["mol-button", "", 3, "click", "variant", "size"], ["mol-button", "", 3, "variant", "size"], ["mol-select", "", 3, "valueChange", "id", "value", "options"], [3, "class"], ["mol-select", "", 3, "id", "value", "options"], ["mol-input", "", 3, "id", "type", "value", "placeholder"], ["mol-input", "", 3, "change", "id", "type", "value"], ["mol-input", "", 3, "change", "id", "type", "value", "placeholder"]], template: function RuleBuilder_Template(rf, ctx) { if (rf & 1) {
|
|
788
|
+
i0.ɵɵelementContainer(0, 3);
|
|
789
|
+
i0.ɵɵtemplate(1, RuleBuilder_ng_template_1_Template, 15, 31, "ng-template", null, 0, i0.ɵɵtemplateRefExtractor)(3, RuleBuilder_ng_template_3_Template, 5, 13, "ng-template", null, 1, i0.ɵɵtemplateRefExtractor)(5, RuleBuilder_ng_template_5_Template, 4, 1, "ng-template", null, 2, i0.ɵɵtemplateRefExtractor);
|
|
790
|
+
} if (rf & 2) {
|
|
791
|
+
const groupTpl_r10 = i0.ɵɵreference(2);
|
|
792
|
+
i0.ɵɵproperty("ngTemplateOutlet", groupTpl_r10)("ngTemplateOutletContext", ctx.rootContext());
|
|
793
|
+
} }, dependencies: [Button, Input, Select, NgTemplateOutlet], encapsulation: 2 });
|
|
794
|
+
}
|
|
795
|
+
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(RuleBuilder, [{
|
|
796
|
+
type: Component,
|
|
797
|
+
args: [{
|
|
798
|
+
selector: 'div[mol-rule-builder]',
|
|
799
|
+
standalone: true,
|
|
800
|
+
imports: [Button, Input, Select, NgTemplateOutlet],
|
|
801
|
+
inputs: ['schema', 'rules', 'onChange', 'className'],
|
|
802
|
+
host: {
|
|
803
|
+
'[class]': 'classes()',
|
|
804
|
+
'data-mol-id': 'rule-builder',
|
|
805
|
+
},
|
|
806
|
+
template: `<ng-container
|
|
807
|
+
[ngTemplateOutlet]="groupTpl"
|
|
808
|
+
[ngTemplateOutletContext]="rootContext()"
|
|
809
|
+
></ng-container>
|
|
810
|
+
<ng-template
|
|
811
|
+
#groupTpl
|
|
812
|
+
let-group
|
|
813
|
+
let-isRoot="isRoot"
|
|
814
|
+
let-onReplace="onReplace"
|
|
815
|
+
let-onRemove="onRemove"
|
|
816
|
+
>
|
|
817
|
+
<div
|
|
818
|
+
[class]="groupClasses()"
|
|
819
|
+
[style]="groupStyle()"
|
|
820
|
+
[attr.data-mol-id]="'rule-builder-group-' + group.id"
|
|
821
|
+
[attr.data-group-op]="group.op"
|
|
822
|
+
>
|
|
823
|
+
<div [class]="rowClasses()">
|
|
824
|
+
<button
|
|
825
|
+
mol-button
|
|
826
|
+
[variant]="'outline'"
|
|
827
|
+
[size]="'sm'"
|
|
828
|
+
(click)="toggle(group, onReplace)"
|
|
829
|
+
[attr.aria-label]="toggleLabel()"
|
|
830
|
+
[attr.data-mol-id]="'rule-builder-group-' + group.id + '-toggle'"
|
|
831
|
+
>
|
|
832
|
+
{{ opLabel(group) }}
|
|
833
|
+
</button>
|
|
834
|
+
<span [class]="helpClasses()">{{ helpText(group) }}</span>
|
|
835
|
+
@if (!isRoot) {
|
|
836
|
+
<button
|
|
837
|
+
mol-button
|
|
838
|
+
[variant]="'ghost'"
|
|
839
|
+
[size]="'sm'"
|
|
840
|
+
(click)="onRemove()"
|
|
841
|
+
[attr.aria-label]="removeGroupLabel()"
|
|
842
|
+
[attr.data-mol-id]="'rule-builder-group-' + group.id + '-remove'"
|
|
843
|
+
>
|
|
844
|
+
{{ removeGroupText() }}
|
|
845
|
+
</button>
|
|
846
|
+
}
|
|
847
|
+
</div>
|
|
848
|
+
<div [class]="childrenClasses()" [style]="childrenStyle()">
|
|
849
|
+
@for (child of group.children; track child.id) {
|
|
850
|
+
@if (isGroup(child)) {
|
|
851
|
+
<ng-container
|
|
852
|
+
[ngTemplateOutlet]="groupTpl"
|
|
853
|
+
[ngTemplateOutletContext]="groupContextOf(group, child, onReplace)"
|
|
854
|
+
></ng-container>
|
|
855
|
+
} @else {
|
|
856
|
+
<ng-container
|
|
857
|
+
[ngTemplateOutlet]="leafTpl"
|
|
858
|
+
[ngTemplateOutletContext]="leafContextOf(group, child, onReplace)"
|
|
859
|
+
></ng-container>
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
</div>
|
|
863
|
+
<div [class]="rowClasses()">
|
|
864
|
+
<button
|
|
865
|
+
mol-button
|
|
866
|
+
[variant]="'outline'"
|
|
867
|
+
[size]="'sm'"
|
|
868
|
+
(click)="addCondition(group, onReplace)"
|
|
869
|
+
[attr.data-mol-id]="'rule-builder-group-' + group.id + '-add-condition'"
|
|
870
|
+
>
|
|
871
|
+
{{ addConditionText() }}
|
|
872
|
+
</button>
|
|
873
|
+
<button
|
|
874
|
+
mol-button
|
|
875
|
+
[variant]="'ghost'"
|
|
876
|
+
[size]="'sm'"
|
|
877
|
+
(click)="addGroup(group, onReplace)"
|
|
878
|
+
[attr.data-mol-id]="'rule-builder-group-' + group.id + '-add-group'"
|
|
879
|
+
>
|
|
880
|
+
{{ addGroupText() }}
|
|
881
|
+
</button>
|
|
882
|
+
</div>
|
|
883
|
+
</div>
|
|
884
|
+
</ng-template>
|
|
885
|
+
<ng-template #leafTpl let-leaf let-onReplace="onReplace" let-onRemove="onRemove">
|
|
886
|
+
<div [class]="leafClasses()" [attr.data-mol-id]="'rule-builder-leaf-' + leaf.id">
|
|
887
|
+
<div
|
|
888
|
+
mol-select
|
|
889
|
+
[id]="leaf.id + '-field'"
|
|
890
|
+
[value]="leaf.field"
|
|
891
|
+
[options]="fieldOptions()"
|
|
892
|
+
(valueChange)="setField(leaf, onReplace, $event)"
|
|
893
|
+
[attr.aria-label]="fieldLabel()"
|
|
894
|
+
></div>
|
|
895
|
+
@if (fieldOf(leaf); as field) {
|
|
896
|
+
<div
|
|
897
|
+
mol-select
|
|
898
|
+
[id]="leaf.id + '-op'"
|
|
899
|
+
[value]="leaf.op"
|
|
900
|
+
[options]="operatorOptions(field)"
|
|
901
|
+
(valueChange)="setOp(leaf, onReplace, $event)"
|
|
902
|
+
[attr.aria-label]="operatorLabel()"
|
|
903
|
+
></div>
|
|
904
|
+
@if (opOf(field, leaf); as op) {
|
|
905
|
+
@if (arityOf(op) === 'between') {
|
|
906
|
+
<ng-container
|
|
907
|
+
[ngTemplateOutlet]="valueTpl"
|
|
908
|
+
[ngTemplateOutletContext]="valueContextOf(leaf, field, 'between', onReplace)"
|
|
909
|
+
></ng-container>
|
|
910
|
+
} @else if (arityOf(op) === 'binary') {
|
|
911
|
+
<ng-container
|
|
912
|
+
[ngTemplateOutlet]="valueTpl"
|
|
913
|
+
[ngTemplateOutletContext]="valueContextOf(leaf, field, 'binary', onReplace)"
|
|
914
|
+
></ng-container>
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
<button
|
|
919
|
+
mol-button
|
|
920
|
+
[variant]="'ghost'"
|
|
921
|
+
[size]="'sm'"
|
|
922
|
+
(click)="onRemove()"
|
|
923
|
+
[attr.aria-label]="removeConditionLabel()"
|
|
924
|
+
[attr.data-mol-id]="'rule-builder-leaf-' + leaf.id + '-remove'"
|
|
925
|
+
>
|
|
926
|
+
{{ removeConditionText() }}
|
|
927
|
+
</button>
|
|
928
|
+
</div>
|
|
929
|
+
</ng-template>
|
|
930
|
+
<ng-template
|
|
931
|
+
#valueTpl
|
|
932
|
+
let-id="id"
|
|
933
|
+
let-field="field"
|
|
934
|
+
let-arity="arity"
|
|
935
|
+
let-value="value"
|
|
936
|
+
let-onChange="onChange"
|
|
937
|
+
>
|
|
938
|
+
@if (arity === 'between') {
|
|
939
|
+
<span [class]="rowClasses()">
|
|
940
|
+
<div
|
|
941
|
+
mol-input
|
|
942
|
+
[id]="id + '-from'"
|
|
943
|
+
[type]="inputType(field)"
|
|
944
|
+
[value]="fromText(field, value)"
|
|
945
|
+
(change)="setFrom(field, value, onChange, $event)"
|
|
946
|
+
[attr.aria-label]="fromLabel()"
|
|
947
|
+
></div>
|
|
948
|
+
<span>{{ separatorText() }}</span>
|
|
949
|
+
<div
|
|
950
|
+
mol-input
|
|
951
|
+
[id]="id + '-to'"
|
|
952
|
+
[type]="inputType(field)"
|
|
953
|
+
[value]="toText(field, value)"
|
|
954
|
+
(change)="setTo(field, value, onChange, $event)"
|
|
955
|
+
[attr.aria-label]="toLabel()"
|
|
956
|
+
></div>
|
|
957
|
+
</span>
|
|
958
|
+
} @else if (field.type === 'select') {
|
|
959
|
+
<div
|
|
960
|
+
mol-select
|
|
961
|
+
[id]="id + '-value'"
|
|
962
|
+
[value]="selectValue(value)"
|
|
963
|
+
[options]="field.options ?? []"
|
|
964
|
+
(valueChange)="onChange($event)"
|
|
965
|
+
[attr.aria-label]="valueLabel()"
|
|
966
|
+
></div>
|
|
967
|
+
} @else if (field.type === 'boolean') {
|
|
968
|
+
<div
|
|
969
|
+
mol-select
|
|
970
|
+
[id]="id + '-value'"
|
|
971
|
+
[value]="booleanValue(value)"
|
|
972
|
+
[options]="booleanOptions()"
|
|
973
|
+
(valueChange)="setBoolean(onChange, $event)"
|
|
974
|
+
[attr.aria-label]="valueLabel()"
|
|
975
|
+
></div>
|
|
976
|
+
} @else {
|
|
977
|
+
<div
|
|
978
|
+
mol-input
|
|
979
|
+
[id]="id + '-value'"
|
|
980
|
+
[type]="inputType(field)"
|
|
981
|
+
[value]="valueText(value)"
|
|
982
|
+
[placeholder]="field.placeholder"
|
|
983
|
+
(change)="setRawValue(field, onChange, $event)"
|
|
984
|
+
[attr.aria-label]="valueLabel()"
|
|
985
|
+
></div>
|
|
986
|
+
}
|
|
987
|
+
</ng-template>`,
|
|
988
|
+
}]
|
|
989
|
+
}], null, null); })();
|
|
990
|
+
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(RuleBuilder, { className: "RuleBuilder", filePath: "rule-builder.component.ts", lineNumber: 261 }); })();
|
|
991
|
+
//# sourceMappingURL=rule-builder.component.js.map
|