@openremote/or-rules 1.8.0-snapshot.20250725074716 → 1.8.0-snapshot.20250725120000
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/README.md +30 -30
- package/custom-elements.json +13 -13
- package/dist/umd/index.bundle.js +4744 -4744
- package/dist/umd/index.bundle.js.map +1 -1
- package/lib/flow-viewer/components/confirmation-dialog.js +61 -24
- package/lib/flow-viewer/components/connection-container.js +35 -1
- package/lib/flow-viewer/components/connection-line.js +117 -28
- package/lib/flow-viewer/components/context-menu.js +140 -45
- package/lib/flow-viewer/components/editor-workspace.js +282 -20
- package/lib/flow-viewer/components/flow-editor.js +160 -47
- package/lib/flow-viewer/components/flow-node-socket.js +146 -31
- package/lib/flow-viewer/components/flow-node.js +192 -29
- package/lib/flow-viewer/components/internal-picker.js +271 -54
- package/lib/flow-viewer/components/node-menu-item.js +132 -32
- package/lib/flow-viewer/components/node-panel.js +104 -60
- package/lib/flow-viewer/components/notification-dialog.js +55 -23
- package/lib/flow-viewer/components/popup-modal.js +113 -54
- package/lib/flow-viewer/components/rule-browser.js +119 -30
- package/lib/flow-viewer/components/selectable-element.js +71 -1
- package/lib/flow-viewer/components/selection-box.js +119 -15
- package/lib/flow-viewer/components/top-bar.js +116 -49
- package/lib/flow-viewer/components/workspace-contextmenu-options.js +128 -5
- package/lib/flow-viewer/components/writable-dropdown.js +51 -5
- package/lib/flow-viewer/converters/node-converter.js +10 -1
- package/lib/flow-viewer/flow-viewer.js +19 -1
- package/lib/flow-viewer/models/camera.js +2 -1
- package/lib/flow-viewer/models/context-menu-button.js +2 -1
- package/lib/flow-viewer/models/light-node-collection.js +2 -1
- package/lib/flow-viewer/models/status.js +8 -1
- package/lib/flow-viewer/node-structure/copy.machine.js +34 -1
- package/lib/flow-viewer/node-structure/identity.assigner.js +10 -1
- package/lib/flow-viewer/node-structure/identity.dom.link.js +4 -1
- package/lib/flow-viewer/node-structure/index.js +5 -1
- package/lib/flow-viewer/node-structure/socket.type.matcher.js +50 -1
- package/lib/flow-viewer/node-structure/utils.js +109 -1
- package/lib/flow-viewer/services/copy-paste-manager.js +59 -1
- package/lib/flow-viewer/services/exporter.js +67 -1
- package/lib/flow-viewer/services/input.js +80 -1
- package/lib/flow-viewer/services/integration.js +27 -1
- package/lib/flow-viewer/services/modal.js +29 -8
- package/lib/flow-viewer/services/project.js +222 -1
- package/lib/flow-viewer/services/shortcuts.js +63 -1
- package/lib/flow-viewer/styles/editor-workspace-style.js +55 -53
- package/lib/flow-viewer/styles/flow-node-style.js +95 -93
- package/lib/flow-viewer/styles/picker-styles.js +31 -29
- package/lib/flow-viewer/utils.js +49 -1
- package/lib/index.js +953 -56
- package/lib/json-viewer/forms/or-rule-form-alarm.js +91 -18
- package/lib/json-viewer/forms/or-rule-form-email-message.js +51 -12
- package/lib/json-viewer/forms/or-rule-form-localized.js +269 -43
- package/lib/json-viewer/forms/or-rule-form-push-notification.js +152 -63
- package/lib/json-viewer/forms/or-rule-form-webhook.js +296 -101
- package/lib/json-viewer/modals/or-rule-alarm-modal.js +173 -17
- package/lib/json-viewer/modals/or-rule-notification-modal.js +196 -11
- package/lib/json-viewer/modals/or-rule-radial-modal.js +142 -17
- package/lib/json-viewer/modals/or-rule-webhook-modal.js +78 -8
- package/lib/json-viewer/or-rule-action-alarm.js +97 -5
- package/lib/json-viewer/or-rule-action-attribute.js +235 -33
- package/lib/json-viewer/or-rule-action-notification.js +465 -56
- package/lib/json-viewer/or-rule-action-webhook.js +49 -18
- package/lib/json-viewer/or-rule-asset-query.js +849 -126
- package/lib/json-viewer/or-rule-condition.js +216 -29
- package/lib/json-viewer/or-rule-json-viewer.js +393 -34
- package/lib/json-viewer/or-rule-then-otherwise.js +609 -113
- package/lib/json-viewer/or-rule-trigger-query.js +227 -57
- package/lib/json-viewer/or-rule-when.js +343 -126
- package/lib/or-rule-group-viewer.js +106 -12
- package/lib/or-rule-text-viewer.js +133 -22
- package/lib/or-rule-tree.js +601 -57
- package/lib/or-rule-validity.js +373 -62
- package/lib/or-rule-viewer.js +361 -81
- package/lib/style.js +89 -64
- package/package.json +11 -11
|
@@ -1,54 +1,271 @@
|
|
|
1
|
-
var __decorate
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
import { LitElement, html, css } from "lit";
|
|
17
|
+
import { customElement, property } from "lit/decorators.js";
|
|
18
|
+
import { AssetModelUtil } from "@openremote/model";
|
|
19
|
+
import { nodeConverter } from "../converters/node-converter";
|
|
20
|
+
import { InputType } from "@openremote/or-mwc-components/or-mwc-input";
|
|
21
|
+
import rest from "@openremote/rest";
|
|
22
|
+
import "@openremote/or-asset-tree";
|
|
23
|
+
import { ResizeObserver } from "resize-observer";
|
|
24
|
+
import { project } from "./flow-editor";
|
|
25
|
+
import { NodeUtilities } from "../node-structure";
|
|
26
|
+
import { translate, i18next } from "@openremote/or-translate";
|
|
27
|
+
import { PickerStyle } from "../styles/picker-styles";
|
|
28
|
+
import { Util } from "@openremote/core";
|
|
29
|
+
import { OrAssetAttributePicker, OrAssetAttributePickerPickedEvent } from "@openremote/or-attribute-picker";
|
|
30
|
+
import { showDialog } from "@openremote/or-mwc-components/or-mwc-dialog";
|
|
31
|
+
import { getAssetDescriptorIconTemplate } from "@openremote/or-icon";
|
|
32
|
+
import { ifDefined } from "lit/directives/if-defined.js";
|
|
33
|
+
let InternalPicker = class InternalPicker extends translate(i18next)(LitElement) {
|
|
34
|
+
constructor() {
|
|
35
|
+
super();
|
|
36
|
+
}
|
|
37
|
+
get internal() {
|
|
38
|
+
return this.node.internals[this.internalIndex];
|
|
39
|
+
}
|
|
40
|
+
static get styles() {
|
|
41
|
+
return [css `
|
|
42
|
+
:host{
|
|
43
|
+
padding: 0;
|
|
44
|
+
margin: 0;
|
|
45
|
+
display: flex;
|
|
46
|
+
flex-direction: column;
|
|
47
|
+
--or-app-color4: var(--or-mwc-input-color);
|
|
48
|
+
}`,
|
|
49
|
+
PickerStyle,
|
|
50
|
+
css `.attribute-label-white {
|
|
51
|
+
background: #ffffff;
|
|
52
|
+
}
|
|
53
|
+
.selected-asset-container {
|
|
54
|
+
display: flex;
|
|
55
|
+
align-items: center;
|
|
56
|
+
}
|
|
57
|
+
.selected-asset-container:hover {
|
|
58
|
+
cursor: pointer;
|
|
59
|
+
background-color: #F9F9F9;
|
|
60
|
+
}
|
|
61
|
+
.selected-asset-label {
|
|
62
|
+
padding: 5px;
|
|
63
|
+
display: flex;
|
|
64
|
+
flex-direction: column;
|
|
65
|
+
line-height: 16px;
|
|
66
|
+
justify-content: flex-start;
|
|
67
|
+
font-size: 14px;
|
|
68
|
+
text-align: left;
|
|
69
|
+
}
|
|
70
|
+
.selected-asset-label .asset {
|
|
71
|
+
color: rgb(76, 76, 76);
|
|
72
|
+
}
|
|
73
|
+
.selected-asset-label .asset-attribute {
|
|
74
|
+
color: grey;
|
|
75
|
+
}
|
|
76
|
+
.selected-asset-icon {
|
|
77
|
+
display: flex;
|
|
78
|
+
justify-content: center;
|
|
79
|
+
padding: 0px 5px 0px 5px;
|
|
80
|
+
--or-icon-width: 20px;
|
|
81
|
+
}`];
|
|
82
|
+
}
|
|
83
|
+
firstUpdated() {
|
|
84
|
+
this.addEventListener("contextmenu", (e) => e.stopPropagation());
|
|
85
|
+
this.addEventListener("mousedown", (e) => {
|
|
86
|
+
project.createUndoSnapshot();
|
|
87
|
+
return project.notifyChange();
|
|
88
|
+
});
|
|
89
|
+
this.resizeObserver = new ResizeObserver((a, b) => {
|
|
90
|
+
const rect = a[0].contentRect;
|
|
91
|
+
this.node.size = { x: rect.width - 20, y: rect.height - 20 };
|
|
92
|
+
});
|
|
93
|
+
this.resizeObserver.observe(this);
|
|
94
|
+
}
|
|
95
|
+
render() {
|
|
96
|
+
switch (this.internal.picker.type) {
|
|
97
|
+
case "ASSET_ATTRIBUTE" /* PickerType.ASSET_ATTRIBUTE */:
|
|
98
|
+
if (this.internal.value && !this.selectedAsset) {
|
|
99
|
+
this.setSelectedAssetFromInternalValue();
|
|
100
|
+
}
|
|
101
|
+
return this.assetAttributeInput;
|
|
102
|
+
case "COLOR" /* PickerType.COLOR */:
|
|
103
|
+
return this.colorInput;
|
|
104
|
+
case "DOUBLE_DROPDOWN" /* PickerType.DOUBLE_DROPDOWN */:
|
|
105
|
+
return this.doubleDropdownInput;
|
|
106
|
+
case "CHECKBOX" /* PickerType.CHECKBOX */:
|
|
107
|
+
return this.checkBoxInput;
|
|
108
|
+
case "DROPDOWN" /* PickerType.DROPDOWN */:
|
|
109
|
+
return this.dropdownInput;
|
|
110
|
+
case "MULTILINE" /* PickerType.MULTILINE */:
|
|
111
|
+
return this.multilineInput;
|
|
112
|
+
case "DATE" /* PickerType.DATE */:
|
|
113
|
+
return this.getNumberInput(0, undefined, 50);
|
|
114
|
+
case "NUMBER" /* PickerType.NUMBER */:
|
|
115
|
+
return this.getNumberInput(undefined, undefined, undefined);
|
|
116
|
+
case "TEXT" /* PickerType.TEXT */:
|
|
117
|
+
return this.textInput;
|
|
118
|
+
default:
|
|
119
|
+
return html `unimplemented picker`;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
setSocketTypeDynamically(value) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
const results = (yield rest.api.AssetResource.queryAssets({
|
|
125
|
+
ids: [value.assetId],
|
|
126
|
+
select: {
|
|
127
|
+
attributes: [
|
|
128
|
+
value.attributeName
|
|
129
|
+
]
|
|
130
|
+
}
|
|
131
|
+
})).data;
|
|
132
|
+
const socket = this.node.outputs[0] || this.node.inputs[0];
|
|
133
|
+
socket.type = "ANY" /* NodeDataType.ANY */;
|
|
134
|
+
if (results == null) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (results[0] == null) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (results[0].attributes == null) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
try {
|
|
144
|
+
const relevantAttribute = results[0].attributes[value.attributeName];
|
|
145
|
+
const descriptors = AssetModelUtil.getValueDescriptors();
|
|
146
|
+
const relevantDescriptor = descriptors.find((c) => c.name === relevantAttribute.type);
|
|
147
|
+
socket.type = NodeUtilities.convertValueTypeToSocketType(relevantDescriptor);
|
|
148
|
+
}
|
|
149
|
+
catch (e) {
|
|
150
|
+
console.error(e);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
setSelectedAssetFromInternalValue() {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
156
|
+
const response = yield rest.api.AssetResource.queryAssets({
|
|
157
|
+
ids: [this.internal.value.assetId]
|
|
158
|
+
});
|
|
159
|
+
if (response.data.length === 0) {
|
|
160
|
+
console.warn(`Asset with id ${this.internal.value.assetId} is missing`);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
this.selectedAsset = response.data[0];
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
get assetAttributeInput() {
|
|
167
|
+
var _a, _b, _c, _d;
|
|
168
|
+
const openDialog = () => {
|
|
169
|
+
const dialog = showDialog(new OrAssetAttributePicker()
|
|
170
|
+
.setShowOnlyRuleStateAttrs(true)
|
|
171
|
+
.setShowOnlyDatapointAttrs(false)
|
|
172
|
+
.setMultiSelect(false));
|
|
173
|
+
dialog.addEventListener(OrAssetAttributePickerPickedEvent.NAME, (ev) => __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
const value = {
|
|
175
|
+
assetId: ev.detail[0].id,
|
|
176
|
+
attributeName: ev.detail[0].name
|
|
177
|
+
};
|
|
178
|
+
yield this.setSocketTypeDynamically(value);
|
|
179
|
+
this.setValue(value);
|
|
180
|
+
yield this.setSelectedAssetFromInternalValue();
|
|
181
|
+
}));
|
|
182
|
+
};
|
|
183
|
+
let selectedAttrLabel = '?';
|
|
184
|
+
if (this.selectedAsset && this.selectedAsset.attributes && ((_b = (_a = this.internal) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.attributeName)) {
|
|
185
|
+
const attrName = (_d = (_c = this.internal) === null || _c === void 0 ? void 0 : _c.value) === null || _d === void 0 ? void 0 : _d.attributeName;
|
|
186
|
+
const attributeDescriptor = AssetModelUtil.getAttributeDescriptor(attrName, this.selectedAsset.type);
|
|
187
|
+
let attr = this.selectedAsset.attributes[attrName];
|
|
188
|
+
if (attr) {
|
|
189
|
+
selectedAttrLabel = Util.getAttributeLabel(attr, attributeDescriptor, this.selectedAsset.type, true);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const descriptor = this.selectedAsset ? AssetModelUtil.getAssetDescriptor(this.selectedAsset.type) : undefined;
|
|
193
|
+
const myIcon = getAssetDescriptorIconTemplate(descriptor);
|
|
194
|
+
return html `<div>
|
|
195
|
+
${(this.selectedAsset ?
|
|
196
|
+
html `<div class="attribute-label attribute-label-white selected-asset-container" @click="${() => openDialog()}">
|
|
197
|
+
<div class="selected-asset-icon">${myIcon}</div>
|
|
198
|
+
<div class="selected-asset-label">
|
|
199
|
+
<div class="asset">${this.selectedAsset.name}</div>
|
|
200
|
+
<div class="asset-attribute">${selectedAttrLabel}</div>
|
|
201
|
+
</div>
|
|
202
|
+
</div>` :
|
|
203
|
+
html `<or-mwc-input class="attribute-label-white" .type="${InputType.BUTTON}" label="attribute" icon="plus" @or-mwc-input-changed="${() => openDialog()}"></or-mwc-input>`)}
|
|
204
|
+
</div>`;
|
|
205
|
+
}
|
|
206
|
+
get colorInput() {
|
|
207
|
+
return html `<or-mwc-input type="color"></or-mwc-input>`; // looks strange
|
|
208
|
+
}
|
|
209
|
+
get doubleDropdownInput() {
|
|
210
|
+
return html `unimplemented`;
|
|
211
|
+
}
|
|
212
|
+
get dropdownInput() {
|
|
213
|
+
return html `<writable-dropdown @input="${(e) => this.setValue(e.target.value)}" .value="${this.internal.value}" .options="${this.internal.picker.options}">
|
|
214
|
+
</writable-dropdown>`;
|
|
215
|
+
}
|
|
216
|
+
get checkBoxInput() {
|
|
217
|
+
return html `<input type="checkbox" ?checked="${this.internal.value || false}" @input="${(e) => this.setValue(e.target.checked)}"/>`;
|
|
218
|
+
return html `<or-mwc-input type="checkbox"
|
|
219
|
+
@or-mwc-input-changed="${(e) => {
|
|
220
|
+
this.setValue(e.detail.value);
|
|
221
|
+
}}"></or-mwc-input>`;
|
|
222
|
+
}
|
|
223
|
+
get multilineInput() {
|
|
224
|
+
const sizeString = this.node.size ? `width:${this.node.size.x}px; height:${this.node.size.y}px` : ``;
|
|
225
|
+
return html `<textarea @wheel="${(e) => {
|
|
226
|
+
if (e.target.clientHeight < e.target.scrollHeight) {
|
|
227
|
+
return e.stopPropagation();
|
|
228
|
+
}
|
|
229
|
+
}}" style="${sizeString}" @input="${(e) => this.setValue(e.target.value)}" placeholder="${this.internal.name}">${this.internal.value || ""}</textarea>`;
|
|
230
|
+
}
|
|
231
|
+
getNumberInput(min, max, width) {
|
|
232
|
+
return html `<input
|
|
233
|
+
@wheel="${(e) => {
|
|
234
|
+
if (e.target === this.shadowRoot.activeElement) {
|
|
235
|
+
return e.stopPropagation();
|
|
236
|
+
}
|
|
237
|
+
}}"
|
|
238
|
+
@input="${(e) => this.setValue(parseFloat(e.target.value))}"
|
|
239
|
+
value="${this.internal.value || 0}" type="number" placeholder="${this.internal.name}"
|
|
240
|
+
style="max-width: ${ifDefined(width)}px"
|
|
241
|
+
min="${ifDefined(min)}" max="${ifDefined(max)}"
|
|
242
|
+
/>`;
|
|
243
|
+
}
|
|
244
|
+
get textInput() {
|
|
245
|
+
return html `<input @input="${(e) => this.setValue(e.target.value)}" value="${this.internal.value || ""}" type="text" placeholder="${this.internal.name}"/>`;
|
|
246
|
+
}
|
|
247
|
+
setValue(value) {
|
|
248
|
+
this.node.internals[this.internalIndex].value = value;
|
|
249
|
+
this.onPicked();
|
|
250
|
+
}
|
|
251
|
+
onPicked() {
|
|
252
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
253
|
+
yield this.updateComplete;
|
|
254
|
+
this.dispatchEvent(new CustomEvent("picked"));
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
__decorate([
|
|
259
|
+
property({ converter: nodeConverter, reflect: true })
|
|
260
|
+
], InternalPicker.prototype, "node", void 0);
|
|
261
|
+
__decorate([
|
|
262
|
+
property({ type: Number, reflect: true })
|
|
263
|
+
], InternalPicker.prototype, "internalIndex", void 0);
|
|
264
|
+
__decorate([
|
|
265
|
+
property({ type: Object })
|
|
266
|
+
], InternalPicker.prototype, "selectedAsset", void 0);
|
|
267
|
+
InternalPicker = __decorate([
|
|
268
|
+
customElement("internal-picker")
|
|
269
|
+
], InternalPicker);
|
|
270
|
+
export { InternalPicker };
|
|
271
|
+
//# sourceMappingURL=internal-picker.js.map
|
|
@@ -1,34 +1,134 @@
|
|
|
1
|
-
var __decorate=this&&this.__decorate
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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 { LitElement, html, css } from "lit";
|
|
8
|
+
import { customElement, property } from "lit/decorators.js";
|
|
9
|
+
import { Utilities } from "../utils";
|
|
10
|
+
import { i18next, translate } from "@openremote/or-translate";
|
|
11
|
+
import { newIds, project } from "./flow-editor";
|
|
12
|
+
import { CopyMachine } from "../node-structure";
|
|
13
|
+
let NodeMenuItem = class NodeMenuItem extends translate(i18next)(LitElement) {
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
this.isDragging = false;
|
|
17
|
+
this.x = 0;
|
|
18
|
+
this.y = 0;
|
|
19
|
+
this.xOffset = 0;
|
|
20
|
+
this.yOffset = 0;
|
|
21
|
+
this.startDrag = (e) => {
|
|
22
|
+
this.xOffset = e.offsetX;
|
|
23
|
+
this.yOffset = e.offsetY;
|
|
24
|
+
this.x = e.clientX;
|
|
25
|
+
this.y = e.clientY;
|
|
26
|
+
this.isDragging = true;
|
|
27
|
+
window.addEventListener("mouseup", this.stopDrag);
|
|
28
|
+
window.addEventListener("mousemove", this.onMove);
|
|
29
|
+
};
|
|
30
|
+
this.onMove = (e) => {
|
|
31
|
+
this.x = e.clientX;
|
|
32
|
+
this.y = e.clientY;
|
|
33
|
+
};
|
|
34
|
+
this.stopDrag = (e) => {
|
|
35
|
+
window.removeEventListener("mouseup", this.stopDrag);
|
|
36
|
+
window.removeEventListener("mousemove", this.onMove);
|
|
37
|
+
this.isDragging = false;
|
|
38
|
+
if (Utilities.isPointInsideBox(e.offsetX, e.offsetY, {
|
|
39
|
+
x: this.workspace.clientRect.left,
|
|
40
|
+
y: this.workspace.clientRect.top,
|
|
41
|
+
width: this.workspace.clientRect.width,
|
|
42
|
+
height: this.workspace.clientRect.height,
|
|
43
|
+
})) {
|
|
44
|
+
const copy = CopyMachine.copy(this.node);
|
|
45
|
+
newIds.add(copy.id);
|
|
46
|
+
copy.position = this.workspace.offsetToWorld({ x: e.offsetX - this.workspace.clientRect.left, y: e.offsetY - this.workspace.clientRect.top });
|
|
47
|
+
project.createUndoSnapshot();
|
|
48
|
+
project.addNode(copy);
|
|
49
|
+
project.notifyChange();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
this.addEventListener("mousedown", this.startDrag);
|
|
53
|
+
}
|
|
54
|
+
static get styles() {
|
|
55
|
+
return css `
|
|
56
|
+
:host, .node-drag-item{
|
|
57
|
+
padding: 4px;
|
|
58
|
+
margin: 0 0 15px 0;
|
|
59
|
+
display: inline-block;
|
|
60
|
+
text-align: center;
|
|
61
|
+
color: white;
|
|
62
|
+
border-radius: var(--roundness);
|
|
63
|
+
box-shadow: rgba(0, 0, 0, 0.2) 0px 5px 5px -5px;
|
|
64
|
+
|
|
65
|
+
width: calc(var(--nodepanel-width) - 4px * 2);
|
|
66
|
+
height: 22px;
|
|
67
|
+
line-height: 22px;
|
|
68
|
+
cursor:grab;
|
|
69
|
+
transition: box-shadow 150ms;
|
|
70
|
+
}
|
|
71
|
+
:host(.small), .small{
|
|
72
|
+
width: 26px;
|
|
73
|
+
height: 26px;
|
|
74
|
+
line-height: 26px;
|
|
75
|
+
margin: 0;
|
|
76
|
+
}
|
|
77
|
+
.node-drag-item{
|
|
78
|
+
z-index: 5000;
|
|
79
|
+
position: fixed;
|
|
80
|
+
background: inherit;
|
|
81
|
+
box-shadow: rgba(0, 0, 0, 0.2) 0 2px 15px;
|
|
82
|
+
filter: opacity(90%);
|
|
83
|
+
pointer-events: none;
|
|
84
|
+
}
|
|
85
|
+
`;
|
|
86
|
+
}
|
|
87
|
+
render() {
|
|
88
|
+
switch (this.node.type) {
|
|
89
|
+
case "INPUT" /* NodeType.INPUT */:
|
|
90
|
+
this.classList.add("input-node");
|
|
91
|
+
break;
|
|
92
|
+
case "PROCESSOR" /* NodeType.PROCESSOR */:
|
|
93
|
+
this.classList.add("processor-node");
|
|
94
|
+
break;
|
|
95
|
+
case "OUTPUT" /* NodeType.OUTPUT */:
|
|
96
|
+
this.classList.add("output-node");
|
|
97
|
+
break;
|
|
16
98
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
height: 26px;
|
|
20
|
-
line-height: 26px;
|
|
21
|
-
margin: 0;
|
|
99
|
+
if (this.node.displayCharacter) {
|
|
100
|
+
this.classList.add("small");
|
|
22
101
|
}
|
|
23
|
-
.node
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
102
|
+
this.title = i18next.t(this.node.name, Utilities.humanLike(this.node.name.toLowerCase()));
|
|
103
|
+
return html `
|
|
104
|
+
<div class="label">${this.flowNodeName}</div>
|
|
105
|
+
${this.isDragging ? this.dragNodeTemplate : null}
|
|
106
|
+
`;
|
|
107
|
+
}
|
|
108
|
+
get dragNodeTemplate() {
|
|
109
|
+
return html `<div class="node-drag-item ${(this.node.displayCharacter ? "small" : null)}" style="top: ${this.y - this.yOffset}px; left: ${this.x - this.xOffset}px"><div class="label">${this.flowNodeName}</div></div>`;
|
|
110
|
+
}
|
|
111
|
+
get flowNodeName() {
|
|
112
|
+
return i18next.t(this.node.displayCharacter ? "flow." + this.node.displayCharacter : "flow." + this.node.name, this.node.displayCharacter || this.node.name || "invalid node name");
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
__decorate([
|
|
116
|
+
property({ attribute: false })
|
|
117
|
+
], NodeMenuItem.prototype, "node", void 0);
|
|
118
|
+
__decorate([
|
|
119
|
+
property({ attribute: false })
|
|
120
|
+
], NodeMenuItem.prototype, "isDragging", void 0);
|
|
121
|
+
__decorate([
|
|
122
|
+
property({ attribute: false })
|
|
123
|
+
], NodeMenuItem.prototype, "x", void 0);
|
|
124
|
+
__decorate([
|
|
125
|
+
property({ attribute: false })
|
|
126
|
+
], NodeMenuItem.prototype, "y", void 0);
|
|
127
|
+
__decorate([
|
|
128
|
+
property({ attribute: false })
|
|
129
|
+
], NodeMenuItem.prototype, "workspace", void 0);
|
|
130
|
+
NodeMenuItem = __decorate([
|
|
131
|
+
customElement("node-menu-item")
|
|
132
|
+
], NodeMenuItem);
|
|
133
|
+
export { NodeMenuItem };
|
|
134
|
+
//# sourceMappingURL=node-menu-item.js.map
|