@openremote/or-rules 1.8.0-snapshot.20250725120000 → 1.8.0-snapshot.20250725123024

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 (73) hide show
  1. package/README.md +30 -30
  2. package/custom-elements.json +13 -13
  3. package/dist/umd/index.bundle.js +4744 -4744
  4. package/dist/umd/index.bundle.js.map +1 -1
  5. package/lib/flow-viewer/components/confirmation-dialog.js +24 -61
  6. package/lib/flow-viewer/components/connection-container.js +1 -35
  7. package/lib/flow-viewer/components/connection-line.js +28 -117
  8. package/lib/flow-viewer/components/context-menu.js +45 -140
  9. package/lib/flow-viewer/components/editor-workspace.js +20 -282
  10. package/lib/flow-viewer/components/flow-editor.js +47 -160
  11. package/lib/flow-viewer/components/flow-node-socket.js +31 -146
  12. package/lib/flow-viewer/components/flow-node.js +29 -192
  13. package/lib/flow-viewer/components/internal-picker.js +54 -271
  14. package/lib/flow-viewer/components/node-menu-item.js +32 -132
  15. package/lib/flow-viewer/components/node-panel.js +60 -104
  16. package/lib/flow-viewer/components/notification-dialog.js +23 -55
  17. package/lib/flow-viewer/components/popup-modal.js +54 -113
  18. package/lib/flow-viewer/components/rule-browser.js +30 -119
  19. package/lib/flow-viewer/components/selectable-element.js +1 -71
  20. package/lib/flow-viewer/components/selection-box.js +15 -119
  21. package/lib/flow-viewer/components/top-bar.js +49 -116
  22. package/lib/flow-viewer/components/workspace-contextmenu-options.js +5 -128
  23. package/lib/flow-viewer/components/writable-dropdown.js +5 -51
  24. package/lib/flow-viewer/converters/node-converter.js +1 -10
  25. package/lib/flow-viewer/flow-viewer.js +1 -19
  26. package/lib/flow-viewer/models/camera.js +1 -2
  27. package/lib/flow-viewer/models/context-menu-button.js +1 -2
  28. package/lib/flow-viewer/models/light-node-collection.js +1 -2
  29. package/lib/flow-viewer/models/status.js +1 -8
  30. package/lib/flow-viewer/node-structure/copy.machine.js +1 -34
  31. package/lib/flow-viewer/node-structure/identity.assigner.js +1 -10
  32. package/lib/flow-viewer/node-structure/identity.dom.link.js +1 -4
  33. package/lib/flow-viewer/node-structure/index.js +1 -5
  34. package/lib/flow-viewer/node-structure/socket.type.matcher.js +1 -50
  35. package/lib/flow-viewer/node-structure/utils.js +1 -109
  36. package/lib/flow-viewer/services/copy-paste-manager.js +1 -59
  37. package/lib/flow-viewer/services/exporter.js +1 -67
  38. package/lib/flow-viewer/services/input.js +1 -80
  39. package/lib/flow-viewer/services/integration.js +1 -27
  40. package/lib/flow-viewer/services/modal.js +8 -29
  41. package/lib/flow-viewer/services/project.js +1 -222
  42. package/lib/flow-viewer/services/shortcuts.js +1 -63
  43. package/lib/flow-viewer/styles/editor-workspace-style.js +53 -55
  44. package/lib/flow-viewer/styles/flow-node-style.js +93 -95
  45. package/lib/flow-viewer/styles/picker-styles.js +29 -31
  46. package/lib/flow-viewer/utils.js +1 -49
  47. package/lib/index.js +56 -953
  48. package/lib/json-viewer/forms/or-rule-form-alarm.js +18 -91
  49. package/lib/json-viewer/forms/or-rule-form-email-message.js +12 -51
  50. package/lib/json-viewer/forms/or-rule-form-localized.js +43 -269
  51. package/lib/json-viewer/forms/or-rule-form-push-notification.js +63 -152
  52. package/lib/json-viewer/forms/or-rule-form-webhook.js +101 -296
  53. package/lib/json-viewer/modals/or-rule-alarm-modal.js +17 -173
  54. package/lib/json-viewer/modals/or-rule-notification-modal.js +11 -196
  55. package/lib/json-viewer/modals/or-rule-radial-modal.js +17 -142
  56. package/lib/json-viewer/modals/or-rule-webhook-modal.js +8 -78
  57. package/lib/json-viewer/or-rule-action-alarm.js +5 -97
  58. package/lib/json-viewer/or-rule-action-attribute.js +33 -235
  59. package/lib/json-viewer/or-rule-action-notification.js +56 -465
  60. package/lib/json-viewer/or-rule-action-webhook.js +18 -49
  61. package/lib/json-viewer/or-rule-asset-query.js +126 -849
  62. package/lib/json-viewer/or-rule-condition.js +29 -216
  63. package/lib/json-viewer/or-rule-json-viewer.js +34 -393
  64. package/lib/json-viewer/or-rule-then-otherwise.js +113 -609
  65. package/lib/json-viewer/or-rule-trigger-query.js +57 -227
  66. package/lib/json-viewer/or-rule-when.js +126 -343
  67. package/lib/or-rule-group-viewer.js +12 -106
  68. package/lib/or-rule-text-viewer.js +22 -133
  69. package/lib/or-rule-tree.js +57 -601
  70. package/lib/or-rule-validity.js +62 -373
  71. package/lib/or-rule-viewer.js +81 -361
  72. package/lib/style.js +64 -89
  73. package/package.json +11 -11
@@ -1,353 +1,136 @@
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
- var OrRuleWhen_1;
8
- import { css, html, LitElement } from "lit";
9
- import { customElement, property } from "lit/decorators.js";
10
- import { OrRulesRuleUnsupportedEvent } from "../index";
11
- import { buttonStyle } from "../style";
12
- import "./or-rule-condition";
13
- import i18next from "i18next";
14
- import { InputType } from "@openremote/or-mwc-components/or-mwc-input";
15
- import { OrRulesJsonRuleChangedEvent } from "./or-rule-json-viewer";
16
- import { getWhenTypesMenu, updateRuleConditionType } from "./or-rule-condition";
17
- import { getContentWithMenuTemplate } from "@openremote/or-mwc-components/or-mwc-menu";
18
- import { translate } from "@openremote/or-translate";
19
- var ResetOption;
20
- (function (ResetOption) {
21
- ResetOption["NO_LONGER_MATCHES"] = "noLongerMatches";
22
- ResetOption["VALUE_CHANGES"] = "valueChanges";
23
- })(ResetOption || (ResetOption = {}));
24
- // language=CSS
25
- const style = css `
26
-
27
- :host {
28
- display: block;
29
- }
30
-
31
- ${buttonStyle}
32
-
33
- .rule-group-items {
34
- display: flex;
35
- flex-direction: column;
36
- }
37
-
38
- .rule-group .rule-group-items > div {
39
- margin: 10px 0;
40
- }
41
-
42
- .rule-condition {
43
- display: flex;
44
- padding-right: 5px;
45
- }
46
-
47
- .rule-condition > * {
48
- flex-grow: 0;
49
- }
50
-
51
- .rule-condition > or-rule-condition {
52
- flex-grow: 1;
53
- }
54
-
55
- or-rule-condition {
56
- margin-bottom: 10px;
57
- }
58
-
59
- .rule-group-item > or-icon {
60
- padding-left: 17px;
61
- }
62
-
63
- or-icon.small {
64
- --or-icon-width: 14px;
65
- --or-icon-height: 14px;
66
- }
67
-
68
- or-panel {
69
- margin: 10px 10px 20px 10px;
70
- position: relative;
71
- }
72
-
73
- or-panel > .remove-button {
74
- position: absolute;
75
- right: 0;
76
- top: 0;
77
- width: 24px;
78
- height: 24px;
79
- transform: translate(50%, -50%);
80
- }
81
-
82
- .rule-condition:hover .button-clear {
83
- visibility: visible;
84
- }
85
-
86
- or-panel:hover .remove-button.button-clear {
87
- visibility: visible;
88
- }
89
-
90
- .add-button-wrapper {
91
- display: flex;
92
- align-items: center;
93
- white-space: nowrap;
94
- }
95
-
96
- .add-button-wrapper > * {
97
- margin-right: 6px;
98
- }
99
-
100
- .add-button-wrapper or-mwc-menu {
101
- text-transform: capitalize;
102
- }
103
-
104
- strong {
105
- margin: var(--internal-or-panel-heading-margin);
106
- font-size: var(--internal-or-panel-heading-font-size);
107
- }
108
- `;
109
- let OrRuleWhen = OrRuleWhen_1 = class OrRuleWhen extends translate(i18next)(LitElement) {
110
- static get styles() {
111
- return style;
1
+ var OrRuleWhen_1,ResetOption,__decorate=this&&this.__decorate||function(e,t,o,r){var i,n=arguments.length,s=n<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,o,r);else for(var l=e.length-1;l>=0;l--)(i=e[l])&&(s=(n<3?i(s):n>3?i(t,o,s):i(t,o))||s);return n>3&&s&&Object.defineProperty(t,o,s),s};import{css as e,html as t,LitElement as o}from"lit";import{customElement as r,property as i}from"lit/decorators.js";import{OrRulesRuleUnsupportedEvent as n}from"../index";import{buttonStyle as s}from"../style";import"./or-rule-condition";import l from"i18next";import{InputType as p}from"@openremote/or-mwc-components/or-mwc-input";import{OrRulesJsonRuleChangedEvent as a}from"./or-rule-json-viewer";import{getWhenTypesMenu as u,updateRuleConditionType as h}from"./or-rule-condition";import{getContentWithMenuTemplate as c}from"@openremote/or-mwc-components/or-mwc-menu";import{translate as d}from"@openremote/or-translate";!function(e){e.NO_LONGER_MATCHES="noLongerMatches",e.VALUE_CHANGES="valueChanges"}(ResetOption||(ResetOption={}));let style=e`
2
+
3
+ :host {
4
+ display: block;
112
5
  }
113
- ruleGroupTemplate(group, parentGroup) {
114
- if (!group) {
115
- return html ``;
116
- }
117
- const isTopLevel = !parentGroup;
118
- const showAddCondition = !this.readonly && (!this.config || !this.config.controls || this.config.controls.hideWhenAddCondition !== true);
119
- const showRemoveCondition = !this.readonly;
120
- const showRemoveGroup = !this.readonly;
121
- let wrapper;
122
- if (isTopLevel) {
123
- wrapper = (content, item, parent, isGroup, isFirst) => {
124
- return html `
125
- <or-panel .heading="${i18next.t(isFirst ? "when" : "orWhen")}...">
126
- ${showRemoveGroup ? html `
127
- <button class="button-clear remove-button" @click="${() => this.removeItem(item, parent, isGroup)}">
128
- <or-icon icon="close-circle"></or-icon>
129
- </button>
130
- ` : ``}
131
- ${content}
132
- </or-panel>`;
133
- };
134
- }
135
- else {
136
- wrapper = (content, item, parent, isGroup, isFirst) => {
137
- return html `
138
- ${!isFirst ? html `
139
- <or-icon class="small" icon="ampersand"></or-icon>
140
- ` : ``}
141
- ${content}
142
- `;
143
- return content;
144
- };
145
- }
146
- let groupsTemplate = ``;
147
- let itemsTemplate = ``;
148
- let addTemplate = ``;
149
- let isFirst = true;
150
- if (group.groups && group.groups.length > 0) {
151
- groupsTemplate = html `
152
- ${group.groups.map((childGroup, index) => {
153
- const content = html `
154
- <div class="rule-group-item">
155
- ${this.ruleGroupTemplate(childGroup, group)}
156
- </div>
157
- `;
158
- return wrapper(content, childGroup, group, true, index == 0);
159
- })}
160
- `;
161
- isFirst = false;
162
- }
163
- if (group.items && group.items.length > 0) {
164
- itemsTemplate = html `
165
- ${group.items.map((condition, index) => {
166
- const content = html `
167
- <div class="rule-group-item">
168
- <div class="rule-condition">
169
- <or-rule-condition .config="${this.config}" .assetInfos="${this.assetInfos}" .ruleCondition="${condition}" .readonly="${this.readonly}" .assetProvider="${this.assetProvider}"></or-rule-condition>
170
- ${showRemoveGroup ? html `
171
- <button class="button-clear ${showRemoveCondition ? "" : "hidden"}" @click="${() => this.removeItem(condition, group, false)}"><or-icon icon="close-circle"></or-icon></input>
172
- ` : ``}
173
- </div>
174
- </div>
175
- `;
176
- return wrapper(content, condition, group, true, isFirst && index === 0);
177
- })}
178
- `;
179
- isFirst = false;
180
- }
181
- if (!isTopLevel && showAddCondition) {
182
- addTemplate = html `
183
- <span class="add-button-wrapper">
184
- ${getContentWithMenuTemplate(html `<or-mwc-input class="plus-button" type="${InputType.BUTTON}" icon="plus"
185
- .label="${i18next.t("rulesEditorAddCondition")}"></or-mwc-input>`, getWhenTypesMenu(this.config, this.assetInfos), undefined, (value) => this.addCondition(group, value))}
186
- </span>
187
- `;
188
- }
189
- return html `
190
- ${groupsTemplate}
191
- ${itemsTemplate}
192
- ${addTemplate}
193
- `;
6
+
7
+ ${s}
8
+
9
+ .rule-group-items {
10
+ display: flex;
11
+ flex-direction: column;
194
12
  }
195
- dateTimePredicateTemplate() {
196
- return html `<span>DATE TIME PREDICATE NOT IMPLEMENTED</span>`;
13
+
14
+ .rule-group .rule-group-items > div {
15
+ margin: 10px 0;
197
16
  }
198
- shouldUpdate(_changedProperties) {
199
- if (_changedProperties.has("rule")) {
200
- if (this.rule) {
201
- if (!this.rule.when) {
202
- this.rule.when = {
203
- operator: "OR" /* LogicGroupOperator.OR */
204
- };
205
- }
206
- else {
207
- // Check this is a rule compatible with this editor
208
- if (!OrRuleWhen_1._isRuleWhenCompatible(this.rule.when)) {
209
- this.rule = undefined;
210
- this.dispatchEvent(new OrRulesRuleUnsupportedEvent());
211
- }
212
- }
213
- }
214
- }
215
- return super.shouldUpdate(_changedProperties);
17
+
18
+ .rule-condition {
19
+ display: flex;
20
+ padding-right: 5px;
216
21
  }
217
- render() {
218
- if (!this.rule || !this.rule.when) {
219
- return html ``;
220
- }
221
- const showAddGroup = !this.readonly && (!this.config || !this.config.controls || this.config.controls.hideWhenAddGroup !== true);
222
- return html `
223
- <div>
224
- ${this.ruleGroupTemplate(this.rule.when)}
225
- </div>
226
-
227
- ${!showAddGroup ? `` : html `
228
- <or-panel>
229
- <strong>${i18next.t(!this.rule.when.groups || this.rule.when.groups.length === 0 ? "when" : "orWhen")}...</strong>
230
- <span class="add-button-wrapper">
231
- ${getContentWithMenuTemplate(html `<or-mwc-input class="plus-button" type="${InputType.BUTTON}" icon="plus"></or-mwc-input>`, getWhenTypesMenu(this.config, this.assetInfos), undefined, (value) => this.addGroup(this.rule.when, value))}
232
- </span>
233
- </or-panel>
234
- `}
235
- `;
22
+
23
+ .rule-condition > * {
24
+ flex-grow: 0;
236
25
  }
237
- /**
238
- * Currently only support a top level OR group and then N child AND groups with no more descendants
239
- */
240
- static _isRuleWhenCompatible(when) {
241
- if (when.operator !== "OR" /* LogicGroupOperator.OR */) {
242
- console.warn("Incompatible rule: when operator not set to 'OR'");
243
- return false;
244
- }
245
- if (when.items && when.items.length > 0) {
246
- console.warn("Incompatible rule: when items not supported");
247
- return false;
248
- }
249
- if (when.groups && when.groups.find((g) => !this._isWhenGroupCompatible(g))) {
250
- console.warn("Incompatible rule: when groups incompatible");
251
- return false;
252
- }
253
- return true;
26
+
27
+ .rule-condition > or-rule-condition {
28
+ flex-grow: 1;
254
29
  }
255
- static _isWhenGroupCompatible(group) {
256
- if (group.operator === "OR" /* LogicGroupOperator.OR */) {
257
- console.warn("Incompatible rule: when group operator not set to 'AND'");
258
- return false;
259
- }
260
- if (group.groups && group.groups.length > 0) {
261
- console.warn("Incompatible rule: when group nested groups not supported");
262
- return false;
263
- }
264
- return true;
30
+
31
+ or-rule-condition {
32
+ margin-bottom: 10px;
265
33
  }
266
- addGroup(parent, type) {
267
- if (!this.rule || !this.rule.when || parent !== this.rule.when) {
268
- return;
269
- }
270
- let newGroup = {
271
- operator: "AND" /* LogicGroupOperator.AND */
272
- };
273
- if (this.config && this.config.json && this.config.json.whenGroup) {
274
- newGroup = JSON.parse(JSON.stringify(this.config.json.whenGroup));
275
- }
276
- if (newGroup.operator !== "AND" /* LogicGroupOperator.AND */) {
277
- console.warn("JSON rules editor doesn't support top level logic group with type OR");
278
- this.dispatchEvent(new OrRulesRuleUnsupportedEvent());
279
- return;
280
- }
281
- if (newGroup.groups && newGroup.groups.length > 0) {
282
- console.warn("JSON rules editor doesn't support multiple top level logic groups");
283
- this.dispatchEvent(new OrRulesRuleUnsupportedEvent());
284
- return;
285
- }
286
- newGroup.groups = undefined;
287
- // Add an item if none exist
288
- if (!newGroup.items || newGroup.items.length === 0) {
289
- this.addCondition(newGroup, type, true);
290
- }
291
- if (!parent.groups) {
292
- parent.groups = [];
293
- }
294
- parent.groups.push(newGroup);
295
- this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
296
- this.requestUpdate();
34
+
35
+ .rule-group-item > or-icon {
36
+ padding-left: 17px;
297
37
  }
298
- removeItem(item, parent, isGroup) {
299
- let removed = false;
300
- if (parent) {
301
- if (isGroup) {
302
- const index = parent.groups.indexOf(item);
303
- parent.groups.splice(index, 1);
304
- removed = index >= 0;
305
- }
306
- else {
307
- const index = parent.items.indexOf(item);
308
- parent.items.splice(index, 1);
309
- removed = index >= 0;
310
- }
311
- if (removed) {
312
- this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
313
- this.requestUpdate();
314
- }
315
- }
38
+
39
+ or-icon.small {
40
+ --or-icon-width: 14px;
41
+ --or-icon-height: 14px;
316
42
  }
317
- addCondition(parent, type, silent) {
318
- if (!parent) {
319
- return;
320
- }
321
- if (!parent.items) {
322
- parent.items = [];
323
- }
324
- let newCondition = {};
325
- if (this.config && this.config.json && this.config.json.whenCondition) {
326
- newCondition = JSON.parse(JSON.stringify(this.config.json.whenCondition));
327
- }
328
- else {
329
- updateRuleConditionType(newCondition, type || "ThingAsset" /* WellknownAssets.THINGASSET */, this.config);
330
- }
331
- parent.items.push(newCondition);
332
- if (!silent) {
333
- this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
334
- this.requestUpdate();
335
- }
43
+
44
+ or-panel {
45
+ margin: 10px 10px 20px 10px;
46
+ position: relative;
336
47
  }
337
- };
338
- __decorate([
339
- property({ type: Object })
340
- ], OrRuleWhen.prototype, "rule", void 0);
341
- __decorate([
342
- property({ type: Boolean })
343
- ], OrRuleWhen.prototype, "readonly", void 0);
344
- __decorate([
345
- property({ type: Object })
346
- ], OrRuleWhen.prototype, "assetProvider", void 0);
347
- __decorate([
348
- property({ type: Object, attribute: false })
349
- ], OrRuleWhen.prototype, "assetInfos", void 0);
350
- OrRuleWhen = OrRuleWhen_1 = __decorate([
351
- customElement("or-rule-when")
352
- ], OrRuleWhen);
353
- //# sourceMappingURL=or-rule-when.js.map
48
+
49
+ or-panel > .remove-button {
50
+ position: absolute;
51
+ right: 0;
52
+ top: 0;
53
+ width: 24px;
54
+ height: 24px;
55
+ transform: translate(50%, -50%);
56
+ }
57
+
58
+ .rule-condition:hover .button-clear {
59
+ visibility: visible;
60
+ }
61
+
62
+ or-panel:hover .remove-button.button-clear {
63
+ visibility: visible;
64
+ }
65
+
66
+ .add-button-wrapper {
67
+ display: flex;
68
+ align-items: center;
69
+ white-space: nowrap;
70
+ }
71
+
72
+ .add-button-wrapper > * {
73
+ margin-right: 6px;
74
+ }
75
+
76
+ .add-button-wrapper or-mwc-menu {
77
+ text-transform: capitalize;
78
+ }
79
+
80
+ strong {
81
+ margin: var(--internal-or-panel-heading-margin);
82
+ font-size: var(--internal-or-panel-heading-font-size);
83
+ }
84
+ `,OrRuleWhen=OrRuleWhen_1=class extends d(l)(o){static get styles(){return style}ruleGroupTemplate(e,o){let r;if(!e)return t``;let i=!o,n=!this.readonly&&(!this.config||!this.config.controls||!0!==this.config.controls.hideWhenAddCondition),s=!this.readonly,a=!this.readonly;r=i?(e,o,r,i,n)=>t`
85
+ <or-panel .heading="${l.t(n?"when":"orWhen")}...">
86
+ ${a?t`
87
+ <button class="button-clear remove-button" @click="${()=>this.removeItem(o,r,i)}">
88
+ <or-icon icon="close-circle"></or-icon>
89
+ </button>
90
+ `:""}
91
+ ${e}
92
+ </or-panel>`:(e,o,r,i,n)=>t`
93
+ ${!n?t`
94
+ <or-icon class="small" icon="ampersand"></or-icon>
95
+ `:""}
96
+ ${e}
97
+ `;let h="",d="",m="",g=!0;return e.groups&&e.groups.length>0&&(h=t`
98
+ ${e.groups.map((o,i)=>r(t`
99
+ <div class="rule-group-item">
100
+ ${this.ruleGroupTemplate(o,e)}
101
+ </div>
102
+ `,o,e,!0,0==i))}
103
+ `,g=!1),e.items&&e.items.length>0&&(d=t`
104
+ ${e.items.map((o,i)=>r(t`
105
+ <div class="rule-group-item">
106
+ <div class="rule-condition">
107
+ <or-rule-condition .config="${this.config}" .assetInfos="${this.assetInfos}" .ruleCondition="${o}" .readonly="${this.readonly}" .assetProvider="${this.assetProvider}"></or-rule-condition>
108
+ ${a?t`
109
+ <button class="button-clear ${s?"":"hidden"}" @click="${()=>this.removeItem(o,e,!1)}"><or-icon icon="close-circle"></or-icon></input>
110
+ `:""}
111
+ </div>
112
+ </div>
113
+ `,o,e,!0,g&&0===i))}
114
+ `,g=!1),!i&&n&&(m=t`
115
+ <span class="add-button-wrapper">
116
+ ${c(t`<or-mwc-input class="plus-button" type="${p.BUTTON}" icon="plus"
117
+ .label="${l.t("rulesEditorAddCondition")}"></or-mwc-input>`,u(this.config,this.assetInfos),void 0,t=>this.addCondition(e,t))}
118
+ </span>
119
+ `),t`
120
+ ${h}
121
+ ${d}
122
+ ${m}
123
+ `}dateTimePredicateTemplate(){return t`<span>DATE TIME PREDICATE NOT IMPLEMENTED</span>`}shouldUpdate(e){return e.has("rule")&&this.rule&&(this.rule.when?OrRuleWhen_1._isRuleWhenCompatible(this.rule.when)||(this.rule=void 0,this.dispatchEvent(new n)):this.rule.when={operator:"OR"}),super.shouldUpdate(e)}render(){if(!this.rule||!this.rule.when)return t``;let e=!this.readonly&&(!this.config||!this.config.controls||!0!==this.config.controls.hideWhenAddGroup);return t`
124
+ <div>
125
+ ${this.ruleGroupTemplate(this.rule.when)}
126
+ </div>
127
+
128
+ ${!e?"":t`
129
+ <or-panel>
130
+ <strong>${l.t(!this.rule.when.groups||0===this.rule.when.groups.length?"when":"orWhen")}...</strong>
131
+ <span class="add-button-wrapper">
132
+ ${c(t`<or-mwc-input class="plus-button" type="${p.BUTTON}" icon="plus"></or-mwc-input>`,u(this.config,this.assetInfos),void 0,e=>this.addGroup(this.rule.when,e))}
133
+ </span>
134
+ </or-panel>
135
+ `}
136
+ `}static _isRuleWhenCompatible(e){return"OR"!==e.operator?(console.warn("Incompatible rule: when operator not set to 'OR'"),!1):e.items&&e.items.length>0?(console.warn("Incompatible rule: when items not supported"),!1):!(e.groups&&e.groups.find(e=>!this._isWhenGroupCompatible(e)))||(console.warn("Incompatible rule: when groups incompatible"),!1)}static _isWhenGroupCompatible(e){return"OR"===e.operator?(console.warn("Incompatible rule: when group operator not set to 'AND'"),!1):!e.groups||!(e.groups.length>0)||(console.warn("Incompatible rule: when group nested groups not supported"),!1)}addGroup(e,t){if(!this.rule||!this.rule.when||e!==this.rule.when)return;let o={operator:"AND"};if(this.config&&this.config.json&&this.config.json.whenGroup&&(o=JSON.parse(JSON.stringify(this.config.json.whenGroup))),"AND"!==o.operator){console.warn("JSON rules editor doesn't support top level logic group with type OR"),this.dispatchEvent(new n);return}if(o.groups&&o.groups.length>0){console.warn("JSON rules editor doesn't support multiple top level logic groups"),this.dispatchEvent(new n);return}o.groups=void 0,o.items&&0!==o.items.length||this.addCondition(o,t,!0),e.groups||(e.groups=[]),e.groups.push(o),this.dispatchEvent(new a),this.requestUpdate()}removeItem(e,t,o){let r=!1;if(t){if(o){let o=t.groups.indexOf(e);t.groups.splice(o,1),r=o>=0}else{let o=t.items.indexOf(e);t.items.splice(o,1),r=o>=0}r&&(this.dispatchEvent(new a),this.requestUpdate())}}addCondition(e,t,o){if(!e)return;e.items||(e.items=[]);let r={};this.config&&this.config.json&&this.config.json.whenCondition?r=JSON.parse(JSON.stringify(this.config.json.whenCondition)):h(r,t||"ThingAsset",this.config),e.items.push(r),o||(this.dispatchEvent(new a),this.requestUpdate())}};__decorate([i({type:Object})],OrRuleWhen.prototype,"rule",void 0),__decorate([i({type:Boolean})],OrRuleWhen.prototype,"readonly",void 0),__decorate([i({type:Object})],OrRuleWhen.prototype,"assetProvider",void 0),__decorate([i({type:Object,attribute:!1})],OrRuleWhen.prototype,"assetInfos",void 0),OrRuleWhen=OrRuleWhen_1=__decorate([r("or-rule-when")],OrRuleWhen);
@@ -1,106 +1,12 @@
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
- /*
8
- * Copyright 2025, OpenRemote Inc.
9
- *
10
- * See the CONTRIBUTORS.txt file in the distribution for a
11
- * full listing of individual contributors.
12
- *
13
- * This program is free software: you can redistribute it and/or modify
14
- * it under the terms of the GNU Affero General Public License as
15
- * published by the Free Software Foundation, either version 3 of the
16
- * License, or (at your option) any later version.
17
- *
18
- * This program is distributed in the hope that it will be useful,
19
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- * GNU Affero General Public License for more details.
22
- *
23
- * You should have received a copy of the GNU Affero General Public License
24
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
25
- */
26
- import { i18next, translate } from "@openremote/or-translate";
27
- import { html, LitElement } from "lit";
28
- import { customElement, property, query, state } from "lit/decorators.js";
29
- import { style } from "./or-rule-viewer";
30
- import { InputType } from "@openremote/or-mwc-components/or-mwc-input";
31
- import { OrRulesGroupNameChangeEvent } from "./index";
32
- import { showSnackbar } from "@openremote/or-mwc-components/or-mwc-snackbar";
33
- let OrRuleGroupViewer = class OrRuleGroupViewer extends translate(i18next)(LitElement) {
34
- constructor() {
35
- super(...arguments);
36
- this.readonly = false;
37
- }
38
- static get styles() {
39
- return [style];
40
- }
41
- willUpdate(changedProps) {
42
- var _a;
43
- if (changedProps.has("group")) {
44
- (_a = this._groupNameInput) === null || _a === void 0 ? void 0 : _a.focus(); // regain focus on the input (if lost)
45
- }
46
- return super.willUpdate(changedProps);
47
- }
48
- render() {
49
- return html `
50
- <div id="main-wrapper" class="wrapper">
51
- <div id="rule-header">
52
- <or-mwc-input id="rule-name" outlined .type="${InputType.TEXT}" .label="${i18next.t("ruleGroupName")}" focused
53
- .value="${this.group}" ?disabled="${this.readonly}" required minlength="1" maxlength="255" @input="${this._onGroupNameInput}"
54
- ></or-mwc-input>
55
- <div id="rule-header-controls">
56
- <or-mwc-input .type="${InputType.BUTTON}" id="save-btn" label="save" raised ?disabled="${this._cannotSave()}" @or-mwc-input-changed="${this._onSaveClicked}"></or-mwc-input>
57
- </div>
58
- </div>
59
- </div>
60
- `;
61
- }
62
- _onGroupNameInput(ev) {
63
- var _a;
64
- const value = (_a = this._groupNameInput) === null || _a === void 0 ? void 0 : _a.nativeValue;
65
- if (value)
66
- this._changeName(value);
67
- this.requestUpdate();
68
- }
69
- _changeName(name) {
70
- if (name.length >= 3 && name.length <= 255) {
71
- this.group = name;
72
- }
73
- }
74
- _cannotSave() {
75
- var _a, _b, _c;
76
- return this.readonly || !((_a = this._groupNameInput) === null || _a === void 0 ? void 0 : _a.nativeValue) || !((_b = this._groupNameInput) === null || _b === void 0 ? void 0 : _b.valid) || (((_c = this._groupNameInput) === null || _c === void 0 ? void 0 : _c.nativeValue) || "") === this._lastSaved;
77
- }
78
- _onSaveClicked() {
79
- if (this.group && !this._cannotSave()) {
80
- const success = this.dispatchEvent(new OrRulesGroupNameChangeEvent(this.group));
81
- if (success) {
82
- this._lastSaved = this.group;
83
- }
84
- else {
85
- showSnackbar(undefined, 'ruleGroupExistsError');
86
- }
87
- }
88
- }
89
- };
90
- __decorate([
91
- property({ type: String })
92
- ], OrRuleGroupViewer.prototype, "group", void 0);
93
- __decorate([
94
- property({ type: Boolean })
95
- ], OrRuleGroupViewer.prototype, "readonly", void 0);
96
- __decorate([
97
- state()
98
- ], OrRuleGroupViewer.prototype, "_lastSaved", void 0);
99
- __decorate([
100
- query("#rule-name")
101
- ], OrRuleGroupViewer.prototype, "_groupNameInput", void 0);
102
- OrRuleGroupViewer = __decorate([
103
- customElement("or-rule-group-viewer")
104
- ], OrRuleGroupViewer);
105
- export { OrRuleGroupViewer };
106
- //# sourceMappingURL=or-rule-group-viewer.js.map
1
+ var __decorate=this&&this.__decorate||function(e,r,t,o){var i,a=arguments.length,n=a<3?r:null===o?o=Object.getOwnPropertyDescriptor(r,t):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,r,t,o);else for(var u=e.length-1;u>=0;u--)(i=e[u])&&(n=(a<3?i(n):a>3?i(r,t,n):i(r,t))||n);return a>3&&n&&Object.defineProperty(r,t,n),n};import{i18next as e,translate as r}from"@openremote/or-translate";import{html as t,LitElement as o}from"lit";import{customElement as i,property as a,query as n,state as u}from"lit/decorators.js";import{style as p}from"./or-rule-viewer";import{InputType as l}from"@openremote/or-mwc-components/or-mwc-input";import{OrRulesGroupNameChangeEvent as d}from"./index";import{showSnackbar as s}from"@openremote/or-mwc-components/or-mwc-snackbar";let OrRuleGroupViewer=class extends r(e)(o){constructor(){super(...arguments),this.readonly=!1}static get styles(){return[p]}willUpdate(e){var r;return e.has("group")&&(null==(r=this._groupNameInput)||r.focus()),super.willUpdate(e)}render(){return t`
2
+ <div id="main-wrapper" class="wrapper">
3
+ <div id="rule-header">
4
+ <or-mwc-input id="rule-name" outlined .type="${l.TEXT}" .label="${e.t("ruleGroupName")}" focused
5
+ .value="${this.group}" ?disabled="${this.readonly}" required minlength="1" maxlength="255" @input="${this._onGroupNameInput}"
6
+ ></or-mwc-input>
7
+ <div id="rule-header-controls">
8
+ <or-mwc-input .type="${l.BUTTON}" id="save-btn" label="save" raised ?disabled="${this._cannotSave()}" @or-mwc-input-changed="${this._onSaveClicked}"></or-mwc-input>
9
+ </div>
10
+ </div>
11
+ </div>
12
+ `}_onGroupNameInput(e){var r;let t=null==(r=this._groupNameInput)?void 0:r.nativeValue;t&&this._changeName(t),this.requestUpdate()}_changeName(e){e.length>=3&&e.length<=255&&(this.group=e)}_cannotSave(){var e,r,t;return this.readonly||!(null==(e=this._groupNameInput)?void 0:e.nativeValue)||!(null==(r=this._groupNameInput)?void 0:r.valid)||((null==(t=this._groupNameInput)?void 0:t.nativeValue)||"")===this._lastSaved}_onSaveClicked(){this.group&&!this._cannotSave()&&(this.dispatchEvent(new d(this.group))?this._lastSaved=this.group:s(void 0,"ruleGroupExistsError"))}};__decorate([a({type:String})],OrRuleGroupViewer.prototype,"group",void 0),__decorate([a({type:Boolean})],OrRuleGroupViewer.prototype,"readonly",void 0),__decorate([u()],OrRuleGroupViewer.prototype,"_lastSaved",void 0),__decorate([n("#rule-name")],OrRuleGroupViewer.prototype,"_groupNameInput",void 0),OrRuleGroupViewer=__decorate([i("or-rule-group-viewer")],OrRuleGroupViewer);export{OrRuleGroupViewer};