@pb33f/cowboy-components 0.1.15 → 0.2.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/assets/rule-documentation.worker-D39NS8Lx.js +1 -0
- package/dist/components/editor/editor.d.ts +2 -0
- package/dist/components/editor/editor.js +6 -4
- package/dist/components/error-banner/error-banner.css.js +1 -1
- package/dist/components/manage-ruleset/function-option.css.d.ts +2 -0
- package/dist/components/manage-ruleset/function-option.css.js +38 -0
- package/dist/components/manage-ruleset/function-option.d.ts +19 -0
- package/dist/components/manage-ruleset/function-option.js +117 -0
- package/dist/components/manage-ruleset/manage-ruleset.css.d.ts +2 -0
- package/dist/components/manage-ruleset/manage-ruleset.css.js +75 -0
- package/dist/components/manage-ruleset/manage-ruleset.d.ts +62 -0
- package/dist/components/manage-ruleset/manage-ruleset.js +575 -0
- package/dist/components/manage-ruleset/rule-action.css.d.ts +2 -0
- package/dist/components/manage-ruleset/rule-action.css.js +56 -0
- package/dist/components/manage-ruleset/rule-action.d.ts +37 -0
- package/dist/components/manage-ruleset/rule-action.js +351 -0
- package/dist/components/manage-ruleset/rule-input.d.ts +38 -0
- package/dist/components/manage-ruleset/rule-input.js +296 -0
- package/dist/components/manage-ruleset/rule.css.d.ts +2 -0
- package/dist/components/manage-ruleset/rule.css.js +117 -0
- package/dist/components/manage-ruleset/rule.d.ts +31 -0
- package/dist/components/manage-ruleset/rule.js +153 -0
- package/dist/components/problem-list/details-drawer.d.ts +2 -1
- package/dist/components/problem-list/details-drawer.js +7 -0
- package/dist/components/problem-list/filter.css.js +2 -3
- package/dist/components/problem-list/problem-item.css.js +1 -3
- package/dist/components/problem-list/problem-item.js +1 -1
- package/dist/components/problem-list/problem-list.css.js +0 -10
- package/dist/components/problem-list/problem-list.d.ts +1 -1
- package/dist/components/problem-list/problem-list.js +1 -2
- package/dist/components/problems-overview/document-statistic.css.js +0 -1
- package/dist/components/problems-overview/problem-overview-group.css.js +1 -3
- package/dist/components/problems-overview/problem-overview-group.js +2 -2
- package/dist/components/problems-overview/problem-statistics.css.js +0 -5
- package/dist/components/problems-overview/problems-overview.css.js +0 -4
- package/dist/components/the-doctor/feedback.js +3 -3
- package/dist/components/the-doctor/status-bar.js +1 -1
- package/dist/components/the-doctor/the-doctor.css.js +99 -27
- package/dist/components/the-doctor/the-doctor.d.ts +65 -8
- package/dist/components/the-doctor/the-doctor.js +663 -63
- package/dist/components/toast/toast-component.css.d.ts +2 -0
- package/dist/components/toast/toast-component.css.js +151 -0
- package/dist/components/toast/toast-component.d.ts +19 -0
- package/dist/components/toast/toast-component.js +116 -0
- package/dist/components/toast/toast-manager.d.ts +13 -0
- package/dist/components/toast/toast-manager.js +54 -0
- package/dist/cowboy-components.umd.cjs +1375 -372
- package/dist/css/button.css.js +46 -0
- package/dist/css/dialog.css.d.ts +2 -0
- package/dist/css/dialog.css.js +11 -0
- package/dist/css/forms.css.d.ts +2 -0
- package/dist/css/forms.css.js +123 -0
- package/dist/css/modal.css.d.ts +2 -0
- package/dist/css/modal.css.js +15 -0
- package/dist/css/pb33f-theme.css +1 -0
- package/dist/css/radiogroups.css.d.ts +2 -0
- package/dist/css/radiogroups.css.js +26 -0
- package/dist/css/spinner.css.d.ts +2 -0
- package/dist/css/spinner.css.js +42 -0
- package/dist/events/doctor.d.ts +57 -3
- package/dist/events/doctor.js +13 -1
- package/dist/model/errors.d.ts +10 -0
- package/dist/model/rule_documentation.d.ts +8 -2
- package/dist/model/rule_documentation.js +5 -1
- package/dist/model/toast.d.ts +15 -0
- package/dist/model/toast.js +9 -0
- package/dist/model/vacuum_rule.d.ts +58 -0
- package/dist/model/vacuum_rule.js +1 -0
- package/dist/services/linting-service.d.ts +1 -1
- package/dist/services/linting-service.js +2 -6
- package/dist/services/ruleset-service.d.ts +17 -0
- package/dist/services/ruleset-service.js +316 -0
- package/dist/style.css +1 -1
- package/dist/workers/rule-documentation.worker.d.ts +9 -1
- package/dist/workers/rule-documentation.worker.js +97 -7
- package/dist/workers/search-problems.worker.d.ts +2 -1
- package/dist/workers/search-problems.worker.js +1 -2
- package/package.json +1 -1
- package/dist/assets/rule-documentation.worker-BFIxMBU8.js +0 -1
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { customElement, property, query } from "lit/decorators.js";
|
|
8
|
+
import { html, LitElement } from "lit";
|
|
9
|
+
import formsCss from "../../css/forms.css.js";
|
|
10
|
+
import ruleActionCss from "./rule-action.css.js";
|
|
11
|
+
import "./function-option.js";
|
|
12
|
+
import buttonCss from "../../css/button.css.js";
|
|
13
|
+
import { CreateBagManager } from "@pb33f/saddlebag";
|
|
14
|
+
import { FunctionsBag, FunctionsSchemaBag } from "../the-doctor/the-doctor.js";
|
|
15
|
+
import { FunctionOption } from "./function-option.js";
|
|
16
|
+
import { OpenProblemDrawer, RemoveFunctionOption, RulesetDirty, RuleActionDirty, } from "../../events/doctor.js";
|
|
17
|
+
import linksCss from "../../css/links.css.js";
|
|
18
|
+
import { ProblemDrawerEventType } from "../problem-list/details-drawer.js";
|
|
19
|
+
import sharedCss from "../../css/shared.css.js";
|
|
20
|
+
import listsCss from "../../css/lists.css.js";
|
|
21
|
+
import dialogCss from "../../css/dialog.css.js";
|
|
22
|
+
let RuleActionComponent = class RuleActionComponent extends LitElement {
|
|
23
|
+
constructor(action, rule) {
|
|
24
|
+
super();
|
|
25
|
+
this.ruleAction = action;
|
|
26
|
+
this.ruleComponent = rule;
|
|
27
|
+
this.bagManager = CreateBagManager(true);
|
|
28
|
+
this.FunctionsBag = this.bagManager.getBag(FunctionsBag);
|
|
29
|
+
this.FunctionsSchemaBag = this.bagManager.getBag(FunctionsSchemaBag);
|
|
30
|
+
this.functions = this.FunctionsBag?.get(FunctionsBag) || [];
|
|
31
|
+
this.functionSchemas = this.FunctionsSchemaBag?.get(FunctionsSchemaBag) || new Map();
|
|
32
|
+
this.buildFunctionOptions();
|
|
33
|
+
}
|
|
34
|
+
buildFunctionOptions() {
|
|
35
|
+
this.functionOptions = [];
|
|
36
|
+
this.ruleFunctionSchema = this.functionSchemas.get(this.ruleAction?.function);
|
|
37
|
+
//no rule action, fill it in.
|
|
38
|
+
if (!this.ruleAction) {
|
|
39
|
+
this.ruleAction = {
|
|
40
|
+
field: "",
|
|
41
|
+
function: "",
|
|
42
|
+
functionOptions: {}
|
|
43
|
+
};
|
|
44
|
+
this.ruleComponent.rule.then = this.ruleAction;
|
|
45
|
+
}
|
|
46
|
+
if (this.ruleAction?.functionOptions && this.ruleAction?.functionOptions.size > 0) {
|
|
47
|
+
let i = 0;
|
|
48
|
+
this.ruleAction.functionOptions.forEach((value, key) => {
|
|
49
|
+
// extract description from schema if its available
|
|
50
|
+
let desc = "";
|
|
51
|
+
let containsKey = false;
|
|
52
|
+
if (this.ruleFunctionSchema?.properties) {
|
|
53
|
+
this.ruleFunctionSchema.properties.forEach(prop => {
|
|
54
|
+
if (prop.name == key) {
|
|
55
|
+
desc = prop.description || "";
|
|
56
|
+
containsKey = true;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
let removeable = true;
|
|
61
|
+
// check if property is required and if so, force it to be non-removable
|
|
62
|
+
if (this.ruleFunctionSchema?.required && this.ruleFunctionSchema?.required.includes(key)) {
|
|
63
|
+
removeable = false;
|
|
64
|
+
}
|
|
65
|
+
if (containsKey) {
|
|
66
|
+
i++;
|
|
67
|
+
this.addFunctionOption(key, value, desc, removeable, false);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
if (i <= 0) {
|
|
71
|
+
if (this.ruleFunctionSchema?.properties) {
|
|
72
|
+
this.ruleFunctionSchema.properties.forEach(property => {
|
|
73
|
+
// check if property is required and if so, force it to be non-removable
|
|
74
|
+
if (this.ruleFunctionSchema?.required && this.ruleFunctionSchema.required.includes(property.name)) {
|
|
75
|
+
this.addFunctionOption(property.name, "", property.description, false, false);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
this.functionOptions = [];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
if (this.ruleAction?.functionOptions) {
|
|
86
|
+
let i = 0;
|
|
87
|
+
for (const property in this.ruleAction.functionOptions) {
|
|
88
|
+
// extract description from schema if its available
|
|
89
|
+
i++;
|
|
90
|
+
let desc = "";
|
|
91
|
+
if (this.ruleFunctionSchema?.properties) {
|
|
92
|
+
this.ruleFunctionSchema.properties.forEach(prop => {
|
|
93
|
+
if (prop.name == property) {
|
|
94
|
+
desc = prop.description || "";
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
// check schema allows it
|
|
99
|
+
if (this.ruleFunctionSchema?.properties) {
|
|
100
|
+
const prop = this.ruleFunctionSchema.properties.filter(prop => prop.name == property)[0];
|
|
101
|
+
if (prop) {
|
|
102
|
+
let removeable = true;
|
|
103
|
+
// check if property is required and if so, force it to be non-removable
|
|
104
|
+
if (this.ruleFunctionSchema.required && this.ruleFunctionSchema.required.includes(property)) {
|
|
105
|
+
removeable = false;
|
|
106
|
+
}
|
|
107
|
+
this.addFunctionOption(property, this.ruleAction.functionOptions[property], desc, removeable, false);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (i <= 0) {
|
|
112
|
+
if (this.ruleFunctionSchema?.properties) {
|
|
113
|
+
this.ruleFunctionSchema.properties.forEach(property => {
|
|
114
|
+
// check if property is required and if so, force it to be non-removable
|
|
115
|
+
if (this.ruleFunctionSchema?.required && this.ruleFunctionSchema.required.includes(property.name)) {
|
|
116
|
+
this.addFunctionOption(property.name, "", property.description, false, false);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
this.functionOptions = [];
|
|
122
|
+
this.requestUpdate();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
if (this.ruleAction)
|
|
128
|
+
this.ruleAction.functionOptions = {};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (this.ruleFunctionSchema?.minProperties && this.functionOptions.length <= this.ruleFunctionSchema?.minProperties) {
|
|
132
|
+
this.functionOptions.forEach(option => {
|
|
133
|
+
option.removeable = false;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
this.requestUpdate();
|
|
137
|
+
}
|
|
138
|
+
changeField() {
|
|
139
|
+
if (this.fieldInput) {
|
|
140
|
+
this.ruleAction.field = this.fieldInput.value;
|
|
141
|
+
}
|
|
142
|
+
this.dirty();
|
|
143
|
+
}
|
|
144
|
+
changeFunction() {
|
|
145
|
+
if (this.fieldInput) {
|
|
146
|
+
this.ruleAction.function = this.fieldFunction.value;
|
|
147
|
+
}
|
|
148
|
+
// wipe out function options, creates too much mess.
|
|
149
|
+
this.buildFunctionOptions();
|
|
150
|
+
this.dirty();
|
|
151
|
+
}
|
|
152
|
+
dirty() {
|
|
153
|
+
this.dispatchEvent(new CustomEvent(RulesetDirty, {
|
|
154
|
+
bubbles: true,
|
|
155
|
+
composed: true,
|
|
156
|
+
detail: {
|
|
157
|
+
rule: this.ruleComponent
|
|
158
|
+
}
|
|
159
|
+
}));
|
|
160
|
+
}
|
|
161
|
+
functionOptionRemoved(evt) {
|
|
162
|
+
if (Array.isArray(this.ruleComponent.rule.then)) {
|
|
163
|
+
const action = this.ruleComponent.rule.then.filter(action => action == this.ruleAction)[0];
|
|
164
|
+
if (action.functionOptions && action.functionOptions instanceof Map) {
|
|
165
|
+
action.functionOptions.delete(evt.detail.key);
|
|
166
|
+
this.functionOptions = this.functionOptions.filter(option => option.key != evt.detail.key);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
if (action.functionOptions) {
|
|
170
|
+
delete action.functionOptions[evt.detail.key];
|
|
171
|
+
this.functionOptions = this.functionOptions.filter(option => option.key != evt.detail.key);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
for (const property in this.ruleComponent.rule.then) {
|
|
177
|
+
if (property === "functionOptions") {
|
|
178
|
+
if (this.ruleComponent.rule.then.functionOptions && this.ruleComponent.rule.then.functionOptions instanceof Map) {
|
|
179
|
+
this.ruleComponent.rule.then.functionOptions.delete(evt.detail.key);
|
|
180
|
+
this.functionOptions = this.functionOptions.filter(option => option.key != evt.detail.key);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
if (this.ruleComponent.rule.then.functionOptions) {
|
|
184
|
+
delete this.ruleComponent.rule.then.functionOptions[evt.detail.key];
|
|
185
|
+
this.functionOptions = this.functionOptions.filter(option => option.key != evt.detail.key);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// check if this action can add any more properties
|
|
192
|
+
if (this.ruleFunctionSchema?.minProperties && this.functionOptions.length - 1 < this.ruleFunctionSchema.minProperties) {
|
|
193
|
+
this.functionOptions.forEach(option => {
|
|
194
|
+
option.removeable = false;
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
this.dirty();
|
|
198
|
+
this.requestUpdate();
|
|
199
|
+
}
|
|
200
|
+
viewFunctionDocs() {
|
|
201
|
+
this.dispatchEvent(new CustomEvent(OpenProblemDrawer, {
|
|
202
|
+
bubbles: true,
|
|
203
|
+
composed: true,
|
|
204
|
+
detail: {
|
|
205
|
+
type: ProblemDrawerEventType.FUNCTION_DOCS,
|
|
206
|
+
rule: this.ruleAction.function = this.fieldFunction.value
|
|
207
|
+
}
|
|
208
|
+
}));
|
|
209
|
+
}
|
|
210
|
+
addFunctionOption(key = "", value = "", desc = "", removeable = true, dirty = true) {
|
|
211
|
+
const funcOption = new FunctionOption(key, value, desc, this.ruleComponent, this.ruleAction, removeable);
|
|
212
|
+
// @ts-ignore
|
|
213
|
+
funcOption.addEventListener(RemoveFunctionOption, this.functionOptionRemoved.bind(this));
|
|
214
|
+
funcOption.addEventListener(RuleActionDirty, this.dirty);
|
|
215
|
+
this.functionOptions.push(funcOption);
|
|
216
|
+
if (dirty)
|
|
217
|
+
this.dirty();
|
|
218
|
+
this.requestUpdate();
|
|
219
|
+
}
|
|
220
|
+
removeSelf() {
|
|
221
|
+
if (this.ruleComponent.rule && this.ruleComponent.rule.then) {
|
|
222
|
+
if (Array.isArray(this.ruleComponent.rule.then)) {
|
|
223
|
+
this.ruleComponent.rule.then = this.ruleComponent.rule.then.filter(action => action.function !== this.ruleAction.function);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
delete this.ruleComponent.rule.then;
|
|
227
|
+
}
|
|
228
|
+
this.remove();
|
|
229
|
+
}
|
|
230
|
+
this.dirty();
|
|
231
|
+
}
|
|
232
|
+
closeFunctionOption() {
|
|
233
|
+
this.addFunctionOptionDialog.hide();
|
|
234
|
+
}
|
|
235
|
+
openFunctionOptionDialog() {
|
|
236
|
+
this.addFunctionOptionDialog.show();
|
|
237
|
+
}
|
|
238
|
+
addFunctionOptionProperty(prop, desc = "") {
|
|
239
|
+
// check if this has a schema and we have reached minimum props
|
|
240
|
+
if (this.ruleFunctionSchema?.minProperties && this.functionOptions.length + 1 >= this.ruleFunctionSchema.minProperties) {
|
|
241
|
+
this.functionOptions.forEach(option => {
|
|
242
|
+
option.removeable = true;
|
|
243
|
+
});
|
|
244
|
+
this.addFunctionOption(prop, "", desc, true);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
this.addFunctionOption(prop, "", desc, false);
|
|
248
|
+
}
|
|
249
|
+
this.addFunctionOptionDialog.hide();
|
|
250
|
+
this.dirty();
|
|
251
|
+
this.requestUpdate();
|
|
252
|
+
}
|
|
253
|
+
render() {
|
|
254
|
+
let addFunctionOptionButton = html ``;
|
|
255
|
+
if (this.ruleFunctionSchema && this.ruleFunctionSchema.properties && this.ruleFunctionSchema.properties.length > 0) {
|
|
256
|
+
if (this.functionOptions.length < this.ruleFunctionSchema.properties.length) {
|
|
257
|
+
addFunctionOptionButton = html `
|
|
258
|
+
<sl-button @click=${this.openFunctionOptionDialog} variant="primary" size="small"
|
|
259
|
+
class="add-function-option">
|
|
260
|
+
<sl-icon slot="prefix" name="plus-square"></sl-icon>
|
|
261
|
+
Add Function Option
|
|
262
|
+
</sl-button>
|
|
263
|
+
`;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return html `
|
|
267
|
+
<sl-dialog id="add-function-option" label="Add Function Option" class="dialog-overview"
|
|
268
|
+
style="--width: 50vw">
|
|
269
|
+
<h3>${this.ruleComponent.rule.id}</h3>
|
|
270
|
+
<p>This function <em>(${this.ruleAction?.function})</em> accepts the following properties</p>
|
|
271
|
+
<hr/>
|
|
272
|
+
<ul>
|
|
273
|
+
${this.ruleFunctionSchema?.properties?.map(prop => {
|
|
274
|
+
let propUsed = false;
|
|
275
|
+
this.functionOptions.forEach(option => {
|
|
276
|
+
if (option.key == prop.name) {
|
|
277
|
+
propUsed = true;
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
if (!propUsed) {
|
|
281
|
+
return html `
|
|
282
|
+
<li>
|
|
283
|
+
<sl-button @click=${() => {
|
|
284
|
+
this.addFunctionOptionProperty(prop.name, prop.description);
|
|
285
|
+
}} variant="primary" size="small"
|
|
286
|
+
class="add-function-option">
|
|
287
|
+
Add
|
|
288
|
+
</sl-button>
|
|
289
|
+
<strong>${prop.name}</strong> <span class="description">(${prop.description ? html `${prop.description})` : ''}</span>
|
|
290
|
+
</li>`;
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
return html `
|
|
294
|
+
<li><span style="color: var(--font-color-sub1)">${prop.name}</span> (already used)</li>`;
|
|
295
|
+
}
|
|
296
|
+
})}
|
|
297
|
+
</ul>
|
|
298
|
+
<sl-button @click=${this.closeFunctionOption} slot="footer" variant="primary" style="float: left">Close
|
|
299
|
+
</sl-button>
|
|
300
|
+
</sl-dialog>
|
|
301
|
+
|
|
302
|
+
<sl-input size="small" label="Field" id="field"
|
|
303
|
+
help-text="The field value of the nodes located by the JSON Path (can be blank if the JSON path is absolute)"
|
|
304
|
+
value="${this.ruleAction?.field}" @sl-change="${this.changeField}"></sl-input>
|
|
305
|
+
|
|
306
|
+
<div class="function-input">
|
|
307
|
+
<sl-select class="${this.error ? 'error' : ''}" label="Function" size="small" id="function"
|
|
308
|
+
help-text="The function to run on the field" value="${this.ruleAction?.function}"
|
|
309
|
+
@sl-change="${this.changeFunction}">
|
|
310
|
+
${this.functions.map(func => html `
|
|
311
|
+
<sl-option value="${func}">${func}</sl-option>`)}
|
|
312
|
+
</sl-select>
|
|
313
|
+
<a href="#" @click="${this.viewFunctionDocs}" class="function-docs">view docs</a>
|
|
314
|
+
</div>
|
|
315
|
+
|
|
316
|
+
<div class="function-options">
|
|
317
|
+
${addFunctionOptionButton}
|
|
318
|
+
${this.functionOptions}
|
|
319
|
+
<sl-button variant="default" size="small" class="danger"
|
|
320
|
+
@click=${this.removeSelf}>
|
|
321
|
+
<sl-icon slot="prefix" name="x-square"></sl-icon>
|
|
322
|
+
Delete Action
|
|
323
|
+
</sl-button>
|
|
324
|
+
</div>
|
|
325
|
+
<hr/>
|
|
326
|
+
`;
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
RuleActionComponent.styles = [dialogCss, sharedCss, listsCss, linksCss, buttonCss, ruleActionCss, formsCss];
|
|
330
|
+
__decorate([
|
|
331
|
+
query('sl-input#field')
|
|
332
|
+
], RuleActionComponent.prototype, "fieldInput", void 0);
|
|
333
|
+
__decorate([
|
|
334
|
+
query('sl-select#function')
|
|
335
|
+
], RuleActionComponent.prototype, "fieldFunction", void 0);
|
|
336
|
+
__decorate([
|
|
337
|
+
query('sl-dialog#add-function-option')
|
|
338
|
+
], RuleActionComponent.prototype, "addFunctionOptionDialog", void 0);
|
|
339
|
+
__decorate([
|
|
340
|
+
property({ type: Boolean })
|
|
341
|
+
], RuleActionComponent.prototype, "error", void 0);
|
|
342
|
+
__decorate([
|
|
343
|
+
property()
|
|
344
|
+
], RuleActionComponent.prototype, "ruleErrorFunction", void 0);
|
|
345
|
+
__decorate([
|
|
346
|
+
property()
|
|
347
|
+
], RuleActionComponent.prototype, "ruleErrorFunctionOption", void 0);
|
|
348
|
+
RuleActionComponent = __decorate([
|
|
349
|
+
customElement('pb33f-rule-action')
|
|
350
|
+
], RuleActionComponent);
|
|
351
|
+
export { RuleActionComponent };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { LitElement } from "lit";
|
|
2
|
+
import { Rule } from "../../model/vacuum_rule.js";
|
|
3
|
+
import { SlCheckbox, SlInput, SlSelect, SlTextarea } from "@shoelace-style/shoelace";
|
|
4
|
+
import { RuleComponent } from "./rule.js";
|
|
5
|
+
export declare class RuleInputComponent extends LitElement {
|
|
6
|
+
static styles: import("lit").CSSResult[];
|
|
7
|
+
rule: Rule;
|
|
8
|
+
description: SlTextarea;
|
|
9
|
+
message: SlTextarea;
|
|
10
|
+
jsonPath: SlInput;
|
|
11
|
+
name: SlInput;
|
|
12
|
+
oas2Check: SlCheckbox;
|
|
13
|
+
oas3Check: SlCheckbox;
|
|
14
|
+
oas31Check: SlCheckbox;
|
|
15
|
+
resolved: SlCheckbox;
|
|
16
|
+
severity: SlSelect;
|
|
17
|
+
category: SlSelect;
|
|
18
|
+
custom: boolean;
|
|
19
|
+
error: boolean;
|
|
20
|
+
ruleErrorFunction: string[];
|
|
21
|
+
ruleErrorFunctionOption: string[];
|
|
22
|
+
private readonly actions;
|
|
23
|
+
private readonly parent;
|
|
24
|
+
constructor(rule: Rule, parent: RuleComponent, custom: boolean);
|
|
25
|
+
showRuleDocs(source: string | undefined): void;
|
|
26
|
+
updateName(): void;
|
|
27
|
+
updateDescription(): void;
|
|
28
|
+
updateMessage(): void;
|
|
29
|
+
updateJsonPath(): void;
|
|
30
|
+
updateResolved(): void;
|
|
31
|
+
checkFormat(format: string): boolean;
|
|
32
|
+
addRuleAction(): void;
|
|
33
|
+
dirty(): void;
|
|
34
|
+
updateSeverity(): void;
|
|
35
|
+
updateCategory(): void;
|
|
36
|
+
updateFormats(): void;
|
|
37
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { customElement, property, query, state } from "lit/decorators.js";
|
|
8
|
+
import { html, LitElement } from "lit";
|
|
9
|
+
import { ProblemDrawerEventType } from "../problem-list/details-drawer.js";
|
|
10
|
+
import { OpenProblemDrawer, RuleNameUpdated, RulesetDirty } from "../../events/doctor";
|
|
11
|
+
import { RuleActionComponent } from "./rule-action.js";
|
|
12
|
+
import ruleCss from "./rule.css.js";
|
|
13
|
+
import formsCss from "../../css/forms.css.js";
|
|
14
|
+
import buttonCss from "../../css/button.css.js";
|
|
15
|
+
import linksCss from "../../css/links.css.js";
|
|
16
|
+
let RuleInputComponent = class RuleInputComponent extends LitElement {
|
|
17
|
+
constructor(rule, parent, custom) {
|
|
18
|
+
super();
|
|
19
|
+
this.rule = rule;
|
|
20
|
+
this.parent = parent;
|
|
21
|
+
this.custom = custom;
|
|
22
|
+
this.ruleErrorFunction = [];
|
|
23
|
+
this.ruleErrorFunctionOption = [];
|
|
24
|
+
let actions = [];
|
|
25
|
+
if (this.rule && Array.isArray(this.rule.then)) {
|
|
26
|
+
this.rule.then.forEach(action => {
|
|
27
|
+
const ruleAction = new RuleActionComponent(action, this.parent);
|
|
28
|
+
ruleAction.addEventListener(RulesetDirty, () => { this.dirty(); });
|
|
29
|
+
actions.push(ruleAction);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const ruleAction = new RuleActionComponent(this.rule.then, this.parent);
|
|
34
|
+
actions.push(ruleAction);
|
|
35
|
+
ruleAction.addEventListener(RulesetDirty, () => { this.dirty(); });
|
|
36
|
+
}
|
|
37
|
+
this.actions = actions;
|
|
38
|
+
}
|
|
39
|
+
showRuleDocs(source) {
|
|
40
|
+
this.dispatchEvent(new CustomEvent(OpenProblemDrawer, {
|
|
41
|
+
bubbles: true,
|
|
42
|
+
composed: true,
|
|
43
|
+
detail: {
|
|
44
|
+
type: ProblemDrawerEventType.RULE_DOCS,
|
|
45
|
+
rule: source
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
updateName() {
|
|
50
|
+
this.rule.id = this.name.value;
|
|
51
|
+
this.dispatchEvent(new CustomEvent(RuleNameUpdated, {
|
|
52
|
+
bubbles: true,
|
|
53
|
+
composed: true,
|
|
54
|
+
detail: {
|
|
55
|
+
name: this.rule.id
|
|
56
|
+
}
|
|
57
|
+
}));
|
|
58
|
+
this.dirty();
|
|
59
|
+
}
|
|
60
|
+
updateDescription() {
|
|
61
|
+
this.rule.description = this.description.value;
|
|
62
|
+
this.dirty();
|
|
63
|
+
}
|
|
64
|
+
updateMessage() {
|
|
65
|
+
this.rule.message = this.message.value;
|
|
66
|
+
this.dirty();
|
|
67
|
+
}
|
|
68
|
+
updateJsonPath() {
|
|
69
|
+
this.rule.given = this.jsonPath.value;
|
|
70
|
+
this.dirty();
|
|
71
|
+
}
|
|
72
|
+
updateResolved() {
|
|
73
|
+
this.rule.resolved = this.resolved.checked;
|
|
74
|
+
this.dirty();
|
|
75
|
+
}
|
|
76
|
+
checkFormat(format) {
|
|
77
|
+
if (this.rule.formats) {
|
|
78
|
+
return this.rule.formats.includes(format);
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
addRuleAction() {
|
|
83
|
+
const ruleAction = {
|
|
84
|
+
field: "",
|
|
85
|
+
function: "",
|
|
86
|
+
functionOptions: new Map()
|
|
87
|
+
};
|
|
88
|
+
const action = new RuleActionComponent(ruleAction, this.parent);
|
|
89
|
+
this.actions.push(action);
|
|
90
|
+
if (this.rule && this.rule.then) {
|
|
91
|
+
if (Array.isArray(this.rule.then)) {
|
|
92
|
+
this.rule.then.push(ruleAction);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
this.rule.then = [this.rule.then, ruleAction];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
this.rule.then = [ruleAction];
|
|
100
|
+
}
|
|
101
|
+
this.dirty();
|
|
102
|
+
this.requestUpdate();
|
|
103
|
+
}
|
|
104
|
+
dirty() {
|
|
105
|
+
this.dispatchEvent(new CustomEvent(RulesetDirty, {
|
|
106
|
+
bubbles: true,
|
|
107
|
+
composed: true,
|
|
108
|
+
detail: {
|
|
109
|
+
rule: this.parent
|
|
110
|
+
}
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
updateSeverity() {
|
|
114
|
+
this.rule.severity = this.severity.value;
|
|
115
|
+
this.dirty();
|
|
116
|
+
}
|
|
117
|
+
updateCategory() {
|
|
118
|
+
this.rule.category = { id: this.category.value, name: this.category.value };
|
|
119
|
+
this.dirty();
|
|
120
|
+
}
|
|
121
|
+
updateFormats() {
|
|
122
|
+
let formats = [];
|
|
123
|
+
if (this.oas2Check.checked) {
|
|
124
|
+
formats.push('oas2');
|
|
125
|
+
}
|
|
126
|
+
if (this.oas3Check.checked) {
|
|
127
|
+
formats.push('oas3');
|
|
128
|
+
}
|
|
129
|
+
if (this.oas31Check.checked) {
|
|
130
|
+
formats.push('oas3_1');
|
|
131
|
+
}
|
|
132
|
+
this.rule.formats = formats;
|
|
133
|
+
this.dirty();
|
|
134
|
+
}
|
|
135
|
+
render() {
|
|
136
|
+
let message = this.rule.message;
|
|
137
|
+
if (message == null) {
|
|
138
|
+
message = this.rule.description;
|
|
139
|
+
}
|
|
140
|
+
if (!this.rule) {
|
|
141
|
+
return html ``;
|
|
142
|
+
}
|
|
143
|
+
if (this.error) {
|
|
144
|
+
let i = 0;
|
|
145
|
+
this.actions.forEach(action => {
|
|
146
|
+
if (this.ruleErrorFunction && action.ruleAction?.function === this.ruleErrorFunction[i]) {
|
|
147
|
+
action.error = true;
|
|
148
|
+
action.ruleErrorFunction = this.ruleErrorFunctionOption[i];
|
|
149
|
+
if (this.ruleErrorFunctionOption) {
|
|
150
|
+
action.ruleErrorFunctionOption = this.ruleErrorFunctionOption[i];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
action.error = false;
|
|
155
|
+
action.ruleErrorFunction = '';
|
|
156
|
+
action.ruleErrorFunctionOption = '';
|
|
157
|
+
}
|
|
158
|
+
i++;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
this.actions.forEach(action => {
|
|
163
|
+
action.error = false;
|
|
164
|
+
action.ruleErrorFunction = '';
|
|
165
|
+
action.ruleErrorFunctionOption = '';
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
return html `
|
|
169
|
+
<a href="#" class="rule-docs" @click="${() => {
|
|
170
|
+
this.showRuleDocs(this.rule.id);
|
|
171
|
+
}}">view docs</a>
|
|
172
|
+
<sl-input @sl-change=${this.updateName} id="name" ?disabled="${!this.custom}" size="small"
|
|
173
|
+
class="label-on-left" label="ID"
|
|
174
|
+
value="${this.rule.id}"></sl-input>
|
|
175
|
+
<sl-textarea id="description" @sl-change="${this.updateDescription}" size="small" class="label-on-left"
|
|
176
|
+
label="Description" help-text="What does this rule do"
|
|
177
|
+
value="${this.rule.description}"></sl-textarea>
|
|
178
|
+
<sl-textarea id="message" @sl-change="${this.updateMessage}" size="small" class="label-on-left"
|
|
179
|
+
label="Message"
|
|
180
|
+
help-text="What should the doctor say when this rule is violated?"
|
|
181
|
+
value="${message}"></sl-textarea>
|
|
182
|
+
<sl-input id="json-path" @sl-change="${this.updateJsonPath}" size="small" class="label-on-left"
|
|
183
|
+
label="JSON Path"
|
|
184
|
+
help-text="JSON Path expression to locate items" value="${this.rule.given}"></sl-input>
|
|
185
|
+
|
|
186
|
+
<section class="checkbox">
|
|
187
|
+
<label class="checkbox-label">Version</label>
|
|
188
|
+
<sl-checkbox id="oas2" size="small" ?checked=${this.checkFormat('oas2')}
|
|
189
|
+
@sl-change="${this.updateFormats}">Swagger (2.0)
|
|
190
|
+
</sl-checkbox>
|
|
191
|
+
<sl-checkbox id="oas3" size="small" ?checked=${this.checkFormat('oas3')}
|
|
192
|
+
@sl-change="${this.updateFormats}">OpenAPI 3.0
|
|
193
|
+
</sl-checkbox>
|
|
194
|
+
<sl-checkbox id="oas3_1" size="small" ?checked=${this.checkFormat('oas3_1')}
|
|
195
|
+
@sl-change="${this.updateFormats}">OpenAPI 3.1
|
|
196
|
+
</sl-checkbox>
|
|
197
|
+
</section>
|
|
198
|
+
|
|
199
|
+
<section class="checkbox">
|
|
200
|
+
<label class="checkbox-label"></label>
|
|
201
|
+
<sl-checkbox id="resolved" @sl-change="${this.updateResolved}" size="small"
|
|
202
|
+
?checked=${this.rule.resolved}>Resolve References?
|
|
203
|
+
</sl-checkbox>
|
|
204
|
+
</section>
|
|
205
|
+
|
|
206
|
+
<sl-select id="severity" @sl-change="${this.updateSeverity}" class="label-on-left" label="Severity"
|
|
207
|
+
size="small"
|
|
208
|
+
value=${this.rule.severity}>
|
|
209
|
+
<sl-option value="error">
|
|
210
|
+
<sl-icon name="x-square" class="error"></sl-icon>
|
|
211
|
+
Error
|
|
212
|
+
</sl-option>
|
|
213
|
+
<sl-option value="warn">
|
|
214
|
+
<sl-icon name="exclamation-triangle" class="warning"></sl-icon>
|
|
215
|
+
Warning
|
|
216
|
+
</sl-option>
|
|
217
|
+
<sl-option value="info">
|
|
218
|
+
<sl-icon name="info-square" class="info"></sl-icon>
|
|
219
|
+
Info
|
|
220
|
+
</sl-option>
|
|
221
|
+
</sl-select>
|
|
222
|
+
|
|
223
|
+
<sl-select id="category" @sl-change="${this.updateCategory}" class="label-on-left" label="Category"
|
|
224
|
+
size="small"
|
|
225
|
+
value="${this.rule.category?.id}">
|
|
226
|
+
<sl-option value="schemas">Schemas</sl-option>
|
|
227
|
+
<sl-option value="examples">Examples</sl-option>
|
|
228
|
+
<sl-option value="operations">Operations</sl-option>
|
|
229
|
+
<sl-option value="information">Information</sl-option>
|
|
230
|
+
<sl-option value="descriptions">Descriptions</sl-option>
|
|
231
|
+
<sl-option value="security">Security</sl-option>
|
|
232
|
+
<sl-option value="tags">Tags</sl-option>
|
|
233
|
+
<sl-option value="validation">Validation</sl-option>
|
|
234
|
+
<sl-option value="OWASP">OWASP</sl-option>
|
|
235
|
+
</sl-select>
|
|
236
|
+
|
|
237
|
+
<section class="rule-actions">
|
|
238
|
+
<label class="rule-actions-label">Actions
|
|
239
|
+
<sl-button variant="default" size="small" class="button-primary" @click=${this.addRuleAction}>
|
|
240
|
+
<sl-icon slot="prefix" name="plus-square"></sl-icon>
|
|
241
|
+
Add
|
|
242
|
+
</sl-button>
|
|
243
|
+
</label>
|
|
244
|
+
<div class="actions">
|
|
245
|
+
${this.actions}
|
|
246
|
+
</section>
|
|
247
|
+
`;
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
RuleInputComponent.styles = [linksCss, buttonCss, ruleCss, formsCss];
|
|
251
|
+
__decorate([
|
|
252
|
+
state()
|
|
253
|
+
], RuleInputComponent.prototype, "rule", void 0);
|
|
254
|
+
__decorate([
|
|
255
|
+
query('sl-textarea#description')
|
|
256
|
+
], RuleInputComponent.prototype, "description", void 0);
|
|
257
|
+
__decorate([
|
|
258
|
+
query('sl-textarea#message')
|
|
259
|
+
], RuleInputComponent.prototype, "message", void 0);
|
|
260
|
+
__decorate([
|
|
261
|
+
query('sl-input#json-path')
|
|
262
|
+
], RuleInputComponent.prototype, "jsonPath", void 0);
|
|
263
|
+
__decorate([
|
|
264
|
+
query('sl-input#name')
|
|
265
|
+
], RuleInputComponent.prototype, "name", void 0);
|
|
266
|
+
__decorate([
|
|
267
|
+
query('sl-checkbox#oas2')
|
|
268
|
+
], RuleInputComponent.prototype, "oas2Check", void 0);
|
|
269
|
+
__decorate([
|
|
270
|
+
query('sl-checkbox#oas3')
|
|
271
|
+
], RuleInputComponent.prototype, "oas3Check", void 0);
|
|
272
|
+
__decorate([
|
|
273
|
+
query('sl-checkbox#oas3_1')
|
|
274
|
+
], RuleInputComponent.prototype, "oas31Check", void 0);
|
|
275
|
+
__decorate([
|
|
276
|
+
query('sl-checkbox#resolved')
|
|
277
|
+
], RuleInputComponent.prototype, "resolved", void 0);
|
|
278
|
+
__decorate([
|
|
279
|
+
query('sl-select#severity')
|
|
280
|
+
], RuleInputComponent.prototype, "severity", void 0);
|
|
281
|
+
__decorate([
|
|
282
|
+
query('sl-select#category')
|
|
283
|
+
], RuleInputComponent.prototype, "category", void 0);
|
|
284
|
+
__decorate([
|
|
285
|
+
property({ type: Boolean })
|
|
286
|
+
], RuleInputComponent.prototype, "custom", void 0);
|
|
287
|
+
__decorate([
|
|
288
|
+
property({ type: Boolean })
|
|
289
|
+
], RuleInputComponent.prototype, "error", void 0);
|
|
290
|
+
__decorate([
|
|
291
|
+
property()
|
|
292
|
+
], RuleInputComponent.prototype, "ruleErrorFunction", void 0);
|
|
293
|
+
RuleInputComponent = __decorate([
|
|
294
|
+
customElement('pb33f-rule-input')
|
|
295
|
+
], RuleInputComponent);
|
|
296
|
+
export { RuleInputComponent };
|