@node-red/nodes 4.0.0-beta.3 → 4.0.0-beta.3-1
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/package.json +1 -1
- package/core/function/20-array.html +0 -362
- package/core/function/20-array.js +0 -59
package/package.json
CHANGED
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
<script type="text/html" data-template-name="array">
|
|
3
|
-
<div class="form-row">
|
|
4
|
-
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
|
5
|
-
<input type="text" id="node-input-name" style="width: calc(100% - 105px)" data-i18n="[placeholder]common.label.name">
|
|
6
|
-
</div>
|
|
7
|
-
<div class="form-row" style="margin-bottom:0;">
|
|
8
|
-
<label><i class="fa fa-list"></i> <span data-i18n="change.label.rules"></span></label>
|
|
9
|
-
</div>
|
|
10
|
-
<div class="form-row node-input-rule-container-row">
|
|
11
|
-
<ol id="node-input-rule-container"></ol>
|
|
12
|
-
</div>
|
|
13
|
-
</script>
|
|
14
|
-
|
|
15
|
-
<script type="text/javascript">
|
|
16
|
-
(function() {
|
|
17
|
-
RED.nodes.registerType('array', {
|
|
18
|
-
color: "#E2D96E",
|
|
19
|
-
category: 'function',
|
|
20
|
-
defaults: {
|
|
21
|
-
name: {value:""},
|
|
22
|
-
rules:{
|
|
23
|
-
value:[{t:"set",p:"payload",pt:"msg",to:"",tot:"str"}],
|
|
24
|
-
validate: function(rules, opt) {
|
|
25
|
-
let msg;
|
|
26
|
-
const errors = []
|
|
27
|
-
if (!rules || rules.length === 0) { return true }
|
|
28
|
-
for (var i=0;i<rules.length;i++) {
|
|
29
|
-
const opt = { label: RED._('node-red:change.label.rule')+' '+(i+1) }
|
|
30
|
-
const r = rules[i];
|
|
31
|
-
if (r.t === 'set' || r.t === 'change' || r.t === 'delete' || r.t === 'move') {
|
|
32
|
-
if ((msg = RED.utils.validateTypedProperty(r.p,r.pt,opt)) !== true) {
|
|
33
|
-
errors.push(msg)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
if (r.t === 'set' || r.t === 'change' || r.t === 'move') {
|
|
37
|
-
if ((msg = RED.utils.validateTypedProperty(r.to,r.tot,opt)) !== true) {
|
|
38
|
-
errors.push(msg)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (r.t === 'change') {
|
|
42
|
-
if ((msg = RED.utils.validateTypedProperty(r.from,r.fromt,opt)) !== true) {
|
|
43
|
-
errors.push(msg)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (errors.length) {
|
|
48
|
-
return errors
|
|
49
|
-
}
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
// legacy
|
|
54
|
-
action: {value:""},
|
|
55
|
-
property: {value:""},
|
|
56
|
-
from: {value:""},
|
|
57
|
-
to: {value:""},
|
|
58
|
-
reg: {value:false}
|
|
59
|
-
},
|
|
60
|
-
inputs: 1,
|
|
61
|
-
outputs: 1,
|
|
62
|
-
icon: "swap.svg",
|
|
63
|
-
label: function() {
|
|
64
|
-
function prop2name(type, key) {
|
|
65
|
-
var result = RED.utils.parseContextKey(key);
|
|
66
|
-
return type +"." +result.key;
|
|
67
|
-
}
|
|
68
|
-
if (this.name) {
|
|
69
|
-
return this.name;
|
|
70
|
-
}
|
|
71
|
-
if (!this.rules) {
|
|
72
|
-
if (this.action === "replace") {
|
|
73
|
-
return this._("change.label.set",{property:"msg."+this.property});
|
|
74
|
-
} else if (this.action === "change") {
|
|
75
|
-
return this._("change.label.change",{property:"msg."+this.property});
|
|
76
|
-
} else if (this.action === "move") {
|
|
77
|
-
return this._("change.label.move",{property:"msg."+this.property});
|
|
78
|
-
} else {
|
|
79
|
-
return this._("change.label.delete",{property:"msg."+this.property});
|
|
80
|
-
}
|
|
81
|
-
} else {
|
|
82
|
-
if (this.rules.length == 1) {
|
|
83
|
-
if (this.rules[0].t === "set") {
|
|
84
|
-
return this._("change.label.set",{property:prop2name((this.rules[0].pt||"msg"), this.rules[0].p)});
|
|
85
|
-
} else if (this.rules[0].t === "change") {
|
|
86
|
-
return this._("change.label.change",{property:prop2name((this.rules[0].pt||"msg"), this.rules[0].p)});
|
|
87
|
-
} else if (this.rules[0].t === "move") {
|
|
88
|
-
return this._("change.label.move",{property:prop2name((this.rules[0].pt||"msg"), this.rules[0].p)});
|
|
89
|
-
} else {
|
|
90
|
-
return this._("change.label.delete",{property:prop2name((this.rules[0].pt||"msg"), this.rules[0].p)});
|
|
91
|
-
}
|
|
92
|
-
} else {
|
|
93
|
-
return this._("change.label.changeCount",{count:this.rules.length});
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
labelStyle: function() {
|
|
98
|
-
return this.name ? "node_label_italic" : "";
|
|
99
|
-
},
|
|
100
|
-
oneditprepare: function() {
|
|
101
|
-
var set = this._("change.action.set");
|
|
102
|
-
var change = this._("change.action.change");
|
|
103
|
-
var del = this._("change.action.delete");
|
|
104
|
-
var move = this._("change.action.move");
|
|
105
|
-
var to = this._("change.action.to");
|
|
106
|
-
var toValueLabel = this._("change.action.toValue",to);
|
|
107
|
-
var search = this._("change.action.search");
|
|
108
|
-
var replace = this._("change.action.replace");
|
|
109
|
-
var regex = this._("change.label.regex");
|
|
110
|
-
var deepCopyLabel = this._("change.label.deepCopy");
|
|
111
|
-
|
|
112
|
-
function createPropertyValue(row2_1, row2_2, defaultType) {
|
|
113
|
-
var propValInput = $('<input/>',{class:"node-input-rule-property-value",type:"text"})
|
|
114
|
-
.appendTo(row2_1)
|
|
115
|
-
.typedInput({default:defaultType||'str',types:['msg','flow','global','str','num','bool','json','bin','date','jsonata','env']});
|
|
116
|
-
|
|
117
|
-
var dcLabel = $('<label style="padding-left: 130px;"></label>').appendTo(row2_2);
|
|
118
|
-
var deepCopy = $('<input type="checkbox" class="node-input-rule-property-deepCopy" style="width: auto; margin: 0 6px 0 0">').appendTo(dcLabel)
|
|
119
|
-
$('<span>').text(deepCopyLabel).appendTo(dcLabel)
|
|
120
|
-
|
|
121
|
-
propValInput.on("change", function(evt,type,val) {
|
|
122
|
-
row2_2.toggle(type === "msg" || type === "flow" || type === "global" || type === "env");
|
|
123
|
-
})
|
|
124
|
-
return [propValInput, deepCopy];
|
|
125
|
-
}
|
|
126
|
-
function createFromValue(row3_1, defaultType) {
|
|
127
|
-
return $('<input/>',{class:"node-input-rule-property-search-value",type:"text"})
|
|
128
|
-
.appendTo(row3_1)
|
|
129
|
-
.typedInput({default:defaultType||'str',types:['msg','flow','global','str','re','num','bool','env']});
|
|
130
|
-
}
|
|
131
|
-
function createToValue(row3_2, defaultType) {
|
|
132
|
-
return $('<input/>',{class:"node-input-rule-property-replace-value",type:"text"})
|
|
133
|
-
.appendTo(row3_2)
|
|
134
|
-
.typedInput({default:defaultType||'str',types:['msg','flow','global','str','num','bool','json','bin','env']});
|
|
135
|
-
}
|
|
136
|
-
function createMoveValue(row4, defaultType) {
|
|
137
|
-
return $('<input/>',{class:"node-input-rule-property-move-value",type:"text"})
|
|
138
|
-
.appendTo(row4)
|
|
139
|
-
.typedInput({default:defaultType||'msg',types:['msg','flow','global']});
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
$('#node-input-rule-container').css('min-height','150px').css('min-width','450px').editableList({
|
|
143
|
-
addItem: function(container,i,opt) {
|
|
144
|
-
var rule = opt;
|
|
145
|
-
if (!rule.hasOwnProperty('t')) {
|
|
146
|
-
rule = {t:"set",p:"payload",to:"",tot:"str"};
|
|
147
|
-
}
|
|
148
|
-
if (rule.t === "change" && rule.re) {
|
|
149
|
-
rule.fromt = 're';
|
|
150
|
-
delete rule.re;
|
|
151
|
-
}
|
|
152
|
-
if (rule.t === "set" && !rule.tot) {
|
|
153
|
-
if (rule.to.indexOf("msg.") === 0 && !rule.tot) {
|
|
154
|
-
rule.to = rule.to.substring(4);
|
|
155
|
-
rule.tot = "msg";
|
|
156
|
-
} else {
|
|
157
|
-
rule.tot = "str";
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
if (rule.t === "move" && !rule.tot) {
|
|
161
|
-
rule.tot = "msg";
|
|
162
|
-
}
|
|
163
|
-
container.css({
|
|
164
|
-
overflow: 'hidden',
|
|
165
|
-
whiteSpace: 'nowrap'
|
|
166
|
-
});
|
|
167
|
-
let fragment = document.createDocumentFragment();
|
|
168
|
-
var row1 = $('<div/>',{style:"display:flex; align-items: baseline"}).appendTo(fragment);
|
|
169
|
-
var row2 = $('<div/>',{style:"margin-top:8px;"}).appendTo(fragment);
|
|
170
|
-
var row3 = $('<div/>',{style:"margin-top:8px;"}).appendTo(fragment);
|
|
171
|
-
var row4 = $('<div/>',{style:"display:flex;margin-top:8px;align-items: baseline"}).appendTo(fragment);
|
|
172
|
-
|
|
173
|
-
var selectField = $('<select/>',{class:"node-input-rule-type",style:"width:110px; margin-right:10px;"}).appendTo(row1);
|
|
174
|
-
var selectOptions = [{v:"set",l:set},{v:"change",l:change},{v:"delete",l:del},{v:"move",l:move}];
|
|
175
|
-
for (var i=0; i<4; i++) {
|
|
176
|
-
selectField.append($("<option></option>").val(selectOptions[i].v).text(selectOptions[i].l));
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
var propertyName = $('<input/>',{class:"node-input-rule-property-name",type:"text"})
|
|
180
|
-
.appendTo(row1)
|
|
181
|
-
.typedInput({types:['msg','flow','global']});
|
|
182
|
-
|
|
183
|
-
var row2_1 = $('<div/>', {style:"display:flex;align-items: baseline"}).appendTo(row2);
|
|
184
|
-
$('<div/>',{style:"display:inline-block;text-align:right; width:120px; padding-right:10px; box-sizing:border-box;"})
|
|
185
|
-
.text(toValueLabel)
|
|
186
|
-
.appendTo(row2_1);
|
|
187
|
-
|
|
188
|
-
var row2_2 = $('<div/>', {style:"margin-top: 4px;"}).appendTo(row2);
|
|
189
|
-
|
|
190
|
-
var row3_1 = $('<div/>', {style:"display:flex;align-items: baseline"}).appendTo(row3);
|
|
191
|
-
$('<div/>',{style:"display:inline-block;text-align:right; width:120px; padding-right:10px; box-sizing:border-box;"})
|
|
192
|
-
.text(search)
|
|
193
|
-
.appendTo(row3_1);
|
|
194
|
-
|
|
195
|
-
var row3_2 = $('<div/>',{style:"display:flex;margin-top:8px;align-items: baseline"}).appendTo(row3);
|
|
196
|
-
$('<div/>',{style:"display:inline-block;text-align:right; width:120px; padding-right:10px; box-sizing:border-box;"})
|
|
197
|
-
.text(replace)
|
|
198
|
-
.appendTo(row3_2);
|
|
199
|
-
|
|
200
|
-
$('<div/>',{style:"display:inline-block;text-align:right; width:120px; padding-right:10px; box-sizing:border-box;"})
|
|
201
|
-
.text(to)
|
|
202
|
-
.appendTo(row4);
|
|
203
|
-
|
|
204
|
-
let propertyValue = null;
|
|
205
|
-
let fromValue = null;
|
|
206
|
-
let toValue = null;
|
|
207
|
-
let moveValue = null;
|
|
208
|
-
|
|
209
|
-
selectField.on("change", function() {
|
|
210
|
-
var type = $(this).val();
|
|
211
|
-
if (propertyValue) {
|
|
212
|
-
propertyValue.typedInput('hide');
|
|
213
|
-
}
|
|
214
|
-
if (fromValue) {
|
|
215
|
-
fromValue.typedInput('hide');
|
|
216
|
-
}
|
|
217
|
-
if (toValue) {
|
|
218
|
-
toValue.typedInput('hide');
|
|
219
|
-
}
|
|
220
|
-
if (moveValue) {
|
|
221
|
-
moveValue.typedInput('hide');
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
if (type == "set") {
|
|
225
|
-
if(!propertyValue) {
|
|
226
|
-
var parts = createPropertyValue(row2_1, row2_2);
|
|
227
|
-
propertyValue = parts[0];
|
|
228
|
-
deepCopy = parts[1];
|
|
229
|
-
}
|
|
230
|
-
propertyValue.typedInput('show');
|
|
231
|
-
row2.show();
|
|
232
|
-
row3.hide();
|
|
233
|
-
row4.hide();
|
|
234
|
-
} else if (type == "change") {
|
|
235
|
-
if(!fromValue) {
|
|
236
|
-
fromValue = createFromValue(row3_1);
|
|
237
|
-
}
|
|
238
|
-
fromValue.typedInput('show');
|
|
239
|
-
if(!toValue) {
|
|
240
|
-
toValue = createToValue(row3_2);
|
|
241
|
-
}
|
|
242
|
-
toValue.typedInput('show');
|
|
243
|
-
row2.hide();
|
|
244
|
-
row3.show();
|
|
245
|
-
row4.hide();
|
|
246
|
-
} else if (type == "delete") {
|
|
247
|
-
row2.hide();
|
|
248
|
-
row3.hide();
|
|
249
|
-
row4.hide();
|
|
250
|
-
} else if (type == "move") {
|
|
251
|
-
if(!moveValue) {
|
|
252
|
-
moveValue = createMoveValue(row4);
|
|
253
|
-
}
|
|
254
|
-
moveValue.typedInput('show');
|
|
255
|
-
row2.hide();
|
|
256
|
-
row3.hide();
|
|
257
|
-
row4.show();
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
selectField.val(rule.t);
|
|
262
|
-
propertyName.typedInput('value',rule.p);
|
|
263
|
-
propertyName.typedInput('type',rule.pt);
|
|
264
|
-
if (rule.t == "set") {
|
|
265
|
-
var parts = createPropertyValue(row2_1, row2_2, rule.tot);
|
|
266
|
-
propertyValue = parts[0];
|
|
267
|
-
deepCopy = parts[1];
|
|
268
|
-
propertyValue.typedInput('value',rule.to);
|
|
269
|
-
deepCopy.prop("checked", !!rule.dc);
|
|
270
|
-
}
|
|
271
|
-
if (rule.t == "move") {
|
|
272
|
-
moveValue = createMoveValue(row4,rule.tot);
|
|
273
|
-
moveValue.typedInput('value',rule.to);
|
|
274
|
-
}
|
|
275
|
-
if (rule.t == "change") {
|
|
276
|
-
fromValue = createFromValue(row3_1, rule.fromt);
|
|
277
|
-
fromValue.typedInput('value',rule.from);
|
|
278
|
-
|
|
279
|
-
toValue = createToValue(row3_2,rule.tot);
|
|
280
|
-
toValue.typedInput('value',rule.to);
|
|
281
|
-
}
|
|
282
|
-
selectField.change();
|
|
283
|
-
container[0].appendChild(fragment);
|
|
284
|
-
},
|
|
285
|
-
removable: true,
|
|
286
|
-
sortable: true
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
if (!this.rules) {
|
|
290
|
-
var rule = {
|
|
291
|
-
t:(this.action=="replace"?"set":this.action),
|
|
292
|
-
p:this.property,
|
|
293
|
-
pt:"msg"
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
if ((rule.t === "set")||(rule.t === "move")) {
|
|
297
|
-
rule.to = this.to;
|
|
298
|
-
} else if (rule.t === "change") {
|
|
299
|
-
rule.from = this.from;
|
|
300
|
-
rule.to = this.to;
|
|
301
|
-
rule.re = this.reg;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
delete this.to;
|
|
305
|
-
delete this.from;
|
|
306
|
-
delete this.reg;
|
|
307
|
-
delete this.action;
|
|
308
|
-
delete this.property;
|
|
309
|
-
|
|
310
|
-
this.rules = [rule];
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
for (var i=0; i<this.rules.length; i++) {
|
|
314
|
-
var rule = this.rules[i];
|
|
315
|
-
$("#node-input-rule-container").editableList('addItem',rule);
|
|
316
|
-
}
|
|
317
|
-
},
|
|
318
|
-
oneditsave: function() {
|
|
319
|
-
var rules = $("#node-input-rule-container").editableList('items');
|
|
320
|
-
var node = this;
|
|
321
|
-
node.rules= [];
|
|
322
|
-
rules.each(function(i) {
|
|
323
|
-
var rule = $(this);
|
|
324
|
-
var type = rule.find(".node-input-rule-type").val();
|
|
325
|
-
var r = {
|
|
326
|
-
t:type,
|
|
327
|
-
p:rule.find(".node-input-rule-property-name").typedInput('value'),
|
|
328
|
-
pt:rule.find(".node-input-rule-property-name").typedInput('type')
|
|
329
|
-
};
|
|
330
|
-
if (type === "set") {
|
|
331
|
-
r.to = rule.find(".node-input-rule-property-value").typedInput('value');
|
|
332
|
-
r.tot = rule.find(".node-input-rule-property-value").typedInput('type');
|
|
333
|
-
if (rule.find(".node-input-rule-property-deepCopy").prop("checked")) {
|
|
334
|
-
r.dc = true;
|
|
335
|
-
}
|
|
336
|
-
} else if (type === "move") {
|
|
337
|
-
r.to = rule.find(".node-input-rule-property-move-value").typedInput('value');
|
|
338
|
-
r.tot = rule.find(".node-input-rule-property-move-value").typedInput('type');
|
|
339
|
-
} else if (type === "change") {
|
|
340
|
-
r.from = rule.find(".node-input-rule-property-search-value").typedInput('value');
|
|
341
|
-
r.fromt = rule.find(".node-input-rule-property-search-value").typedInput('type');
|
|
342
|
-
r.to = rule.find(".node-input-rule-property-replace-value").typedInput('value');
|
|
343
|
-
r.tot = rule.find(".node-input-rule-property-replace-value").typedInput('type');
|
|
344
|
-
}
|
|
345
|
-
node.rules.push(r);
|
|
346
|
-
});
|
|
347
|
-
},
|
|
348
|
-
oneditresize: function(size) {
|
|
349
|
-
var rows = $("#dialog-form>div:not(.node-input-rule-container-row)");
|
|
350
|
-
var height = size.height;
|
|
351
|
-
for (var i=0; i<rows.length; i++) {
|
|
352
|
-
height -= $(rows[i]).outerHeight(true);
|
|
353
|
-
}
|
|
354
|
-
var editorRow = $("#dialog-form>div.node-input-rule-container-row");
|
|
355
|
-
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
|
|
356
|
-
height += 16;
|
|
357
|
-
$("#node-input-rule-container").editableList('height',height);
|
|
358
|
-
}
|
|
359
|
-
});
|
|
360
|
-
})();
|
|
361
|
-
</script>
|
|
362
|
-
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright JS Foundation and other contributors, http://js.foundation
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
**/
|
|
16
|
-
|
|
17
|
-
module.exports = function(RED) {
|
|
18
|
-
"use strict";
|
|
19
|
-
function RangeNode(n) {
|
|
20
|
-
RED.nodes.createNode(this, n);
|
|
21
|
-
this.action = n.action;
|
|
22
|
-
this.round = n.round || false;
|
|
23
|
-
this.minin = Number(n.minin);
|
|
24
|
-
this.maxin = Number(n.maxin);
|
|
25
|
-
this.minout = Number(n.minout);
|
|
26
|
-
this.maxout = Number(n.maxout);
|
|
27
|
-
this.property = n.property||"payload";
|
|
28
|
-
var node = this;
|
|
29
|
-
|
|
30
|
-
this.on('input', function (msg, send, done) {
|
|
31
|
-
var value = RED.util.getMessageProperty(msg,node.property);
|
|
32
|
-
if (value !== undefined) {
|
|
33
|
-
var n = Number(value);
|
|
34
|
-
if (!isNaN(n)) {
|
|
35
|
-
if (node.action === "drop") {
|
|
36
|
-
if (n < node.minin) { done(); return; }
|
|
37
|
-
if (n > node.maxin) { done(); return; }
|
|
38
|
-
}
|
|
39
|
-
if (node.action === "clamp") {
|
|
40
|
-
if (n < node.minin) { n = node.minin; }
|
|
41
|
-
if (n > node.maxin) { n = node.maxin; }
|
|
42
|
-
}
|
|
43
|
-
if (node.action === "roll") {
|
|
44
|
-
var divisor = node.maxin - node.minin;
|
|
45
|
-
n = ((n - node.minin) % divisor + divisor) % divisor + node.minin;
|
|
46
|
-
}
|
|
47
|
-
value = ((n - node.minin) / (node.maxin - node.minin) * (node.maxout - node.minout)) + node.minout;
|
|
48
|
-
if (node.round) { value = Math.round(value); }
|
|
49
|
-
RED.util.setMessageProperty(msg,node.property,value);
|
|
50
|
-
send(msg);
|
|
51
|
-
}
|
|
52
|
-
else { node.log(RED._("range.errors.notnumber")+": "+value); }
|
|
53
|
-
}
|
|
54
|
-
else { send(msg); } // If no payload - just pass it on.
|
|
55
|
-
done();
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
RED.nodes.registerType("range", RangeNode);
|
|
59
|
-
}
|