iobroker.javascript 7.10.2 → 7.11.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/README.md +9 -5
- package/admin/asset-manifest.json +5 -5
- package/admin/google-blockly/own/blocks_action.js +231 -13
- package/admin/google-blockly/own/blocks_system.js +10 -13
- package/admin/google-blockly/own/blocks_trigger.js +74 -6
- package/admin/google-blockly/own/blocks_words.js +46 -12
- package/admin/google-blockly/own/field_oid.js +7 -1
- package/admin/static/js/184.689231d0.chunk.js +2 -0
- package/admin/static/js/184.689231d0.chunk.js.map +1 -0
- package/admin/static/js/{main.4caef13e.js → main.da00e584.js} +2 -2
- package/admin/static/js/{main.4caef13e.js.map → main.da00e584.js.map} +1 -1
- package/admin/tab.html +1 -1
- package/docs/en/javascript.md +16 -0
- package/io-package.json +14 -14
- package/lib/javascript.d.ts +1 -3
- package/lib/sandbox.js +52 -125
- package/lib/tools.js +48 -3
- package/package.json +2 -2
- package/admin/static/js/184.23703866.chunk.js +0 -2
- package/admin/static/js/184.23703866.chunk.js.map +0 -1
package/README.md
CHANGED
|
@@ -42,6 +42,15 @@ Since v5.5.0 of the JavaScript adapter the following locations (relative to the
|
|
|
42
42
|
<!--
|
|
43
43
|
### **WORK IN PROGRESS**
|
|
44
44
|
-->
|
|
45
|
+
### 7.11.0 (2024-03-26)
|
|
46
|
+
|
|
47
|
+
* (klein0r) Added blockly block for read and write file
|
|
48
|
+
* (klein0r) Allow to select other object types than state in some blocks
|
|
49
|
+
* (klein0r) Improved translations
|
|
50
|
+
* (klein0r) Removed 'type' from dropdown (is always 'state')
|
|
51
|
+
* (klein0r) Use highlight in search (instead of select)
|
|
52
|
+
* (klein0r) Added option for httpGet to receive arraybuffer (download files)
|
|
53
|
+
|
|
45
54
|
### 7.10.2 (2024-03-25)
|
|
46
55
|
|
|
47
56
|
* (klein0r) Fixed httpGet/httpPost issue when using without options
|
|
@@ -63,11 +72,6 @@ Since v5.5.0 of the JavaScript adapter the following locations (relative to the
|
|
|
63
72
|
* (klein0r) Fixed urlencoding for basic auth in url (user:pass)
|
|
64
73
|
* (klein0r) Added warning icon if trigger is positioned inside of another trigger or loop
|
|
65
74
|
|
|
66
|
-
### 7.9.3 (2024-03-19)
|
|
67
|
-
|
|
68
|
-
* (klein0r) Added timeout option for http blocks
|
|
69
|
-
* (klein0r) Added option for basic auth in url (user:pass)
|
|
70
|
-
|
|
71
75
|
## License
|
|
72
76
|
The MIT License (MIT)
|
|
73
77
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"files": {
|
|
3
|
-
"main.js": "/static/js/main.
|
|
3
|
+
"main.js": "/static/js/main.da00e584.js",
|
|
4
4
|
"static/css/184.7463f8b6.chunk.css": "/static/css/184.7463f8b6.chunk.css",
|
|
5
|
-
"static/js/184.
|
|
5
|
+
"static/js/184.689231d0.chunk.js": "/static/js/184.689231d0.chunk.js",
|
|
6
6
|
"static/js/966.088c1225.chunk.js": "/static/js/966.088c1225.chunk.js",
|
|
7
7
|
"static/js/30.8bf17a3b.chunk.js": "/static/js/30.8bf17a3b.chunk.js",
|
|
8
8
|
"static/js/704.4ede9892.chunk.js": "/static/js/704.4ede9892.chunk.js",
|
|
@@ -160,9 +160,9 @@
|
|
|
160
160
|
"static/media/Garage Doors.svg": "/static/media/Garage Doors.0c2a1cfca7ad1ea59625.svg",
|
|
161
161
|
"static/media/Outdoor Blinds.svg": "/static/media/Outdoor Blinds.37b85a9c060a4af48da9.svg",
|
|
162
162
|
"static/media/Upstairs.svg": "/static/media/Upstairs.441813e54e0daca0882d.svg",
|
|
163
|
-
"main.
|
|
163
|
+
"main.da00e584.js.map": "/static/js/main.da00e584.js.map",
|
|
164
164
|
"184.7463f8b6.chunk.css.map": "/static/css/184.7463f8b6.chunk.css.map",
|
|
165
|
-
"184.
|
|
165
|
+
"184.689231d0.chunk.js.map": "/static/js/184.689231d0.chunk.js.map",
|
|
166
166
|
"966.088c1225.chunk.js.map": "/static/js/966.088c1225.chunk.js.map",
|
|
167
167
|
"30.8bf17a3b.chunk.js.map": "/static/js/30.8bf17a3b.chunk.js.map",
|
|
168
168
|
"704.4ede9892.chunk.js.map": "/static/js/704.4ede9892.chunk.js.map",
|
|
@@ -195,6 +195,6 @@
|
|
|
195
195
|
"77.f4bb7c45.chunk.js.map": "/static/js/77.f4bb7c45.chunk.js.map"
|
|
196
196
|
},
|
|
197
197
|
"entrypoints": [
|
|
198
|
-
"static/js/main.
|
|
198
|
+
"static/js/main.da00e584.js"
|
|
199
199
|
]
|
|
200
200
|
}
|
|
@@ -128,6 +128,8 @@ Blockly.Action.blocks['http_get'] =
|
|
|
128
128
|
+ ' </value>'
|
|
129
129
|
+ ' <value name="UNIT">'
|
|
130
130
|
+ ' </value>'
|
|
131
|
+
+ ' <value name="TYPE">'
|
|
132
|
+
+ ' </value>'
|
|
131
133
|
+ ' <value name="STATEMENT">'
|
|
132
134
|
+ ' </value>'
|
|
133
135
|
+ '</block>';
|
|
@@ -135,16 +137,23 @@ Blockly.Action.blocks['http_get'] =
|
|
|
135
137
|
Blockly.Blocks['http_get'] = {
|
|
136
138
|
init: function() {
|
|
137
139
|
this.appendValueInput('URL')
|
|
138
|
-
.appendField(Blockly.Translate('http_get'));
|
|
140
|
+
.appendField('🌐 ' + Blockly.Translate('http_get'));
|
|
139
141
|
|
|
140
142
|
this.appendDummyInput()
|
|
141
|
-
.appendField(Blockly.Translate('
|
|
143
|
+
.appendField(Blockly.Translate('http_timeout'))
|
|
142
144
|
.appendField(new Blockly.FieldTextInput(2000), 'TIMEOUT')
|
|
143
145
|
.appendField(new Blockly.FieldDropdown([
|
|
144
|
-
[Blockly.Translate('
|
|
145
|
-
[Blockly.Translate('
|
|
146
|
+
[Blockly.Translate('http_timeout_ms'), 'ms'],
|
|
147
|
+
[Blockly.Translate('http_timeout_sec'), 'sec']
|
|
146
148
|
]), 'UNIT');
|
|
147
149
|
|
|
150
|
+
this.appendDummyInput('TYPE')
|
|
151
|
+
.appendField(Blockly.Translate('http_type'))
|
|
152
|
+
.appendField(new Blockly.FieldDropdown([
|
|
153
|
+
[Blockly.Translate('http_type_text'), 'text'],
|
|
154
|
+
[Blockly.Translate('http_type_arraybuffer'), 'arraybuffer'],
|
|
155
|
+
]), 'TYPE');
|
|
156
|
+
|
|
148
157
|
this.appendStatementInput('STATEMENT')
|
|
149
158
|
.setCheck(null);
|
|
150
159
|
|
|
@@ -170,7 +179,12 @@ Blockly.JavaScript['http_get'] = function(block) {
|
|
|
170
179
|
timeout *= 1000;
|
|
171
180
|
}
|
|
172
181
|
|
|
173
|
-
|
|
182
|
+
let responseType = block.getFieldValue('TYPE');
|
|
183
|
+
if (!responseType) {
|
|
184
|
+
responseType = 'text';
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return `httpGet(${URL}, { timeout: ${timeout}, responseType: '${responseType}' }, async (err, response) => {\n` +
|
|
174
188
|
Blockly.JavaScript.prefixLines(`if (err) {`, Blockly.JavaScript.INDENT) + '\n' +
|
|
175
189
|
Blockly.JavaScript.prefixLines(`console.error(err);`, Blockly.JavaScript.INDENT + Blockly.JavaScript.INDENT) + '\n' +
|
|
176
190
|
Blockly.JavaScript.prefixLines(`}`, Blockly.JavaScript.INDENT) + '\n' +
|
|
@@ -190,6 +204,8 @@ Blockly.Action.blocks['http_post'] =
|
|
|
190
204
|
+ ' </value>'
|
|
191
205
|
+ ' <value name="UNIT">'
|
|
192
206
|
+ ' </value>'
|
|
207
|
+
+ ' <value name="TYPE">'
|
|
208
|
+
+ ' </value>'
|
|
193
209
|
+ ' <value name="DATA">'
|
|
194
210
|
+ ' <shadow type="object_new">'
|
|
195
211
|
+ ' </shadow>'
|
|
@@ -201,16 +217,23 @@ Blockly.Action.blocks['http_post'] =
|
|
|
201
217
|
Blockly.Blocks['http_post'] = {
|
|
202
218
|
init: function() {
|
|
203
219
|
this.appendValueInput('URL')
|
|
204
|
-
.appendField(Blockly.Translate('http_post'));
|
|
220
|
+
.appendField('🌐 ' + Blockly.Translate('http_post'));
|
|
205
221
|
|
|
206
222
|
this.appendDummyInput()
|
|
207
|
-
.appendField(Blockly.Translate('
|
|
223
|
+
.appendField(Blockly.Translate('http_timeout'))
|
|
208
224
|
.appendField(new Blockly.FieldTextInput(2000), 'TIMEOUT')
|
|
209
225
|
.appendField(new Blockly.FieldDropdown([
|
|
210
|
-
[Blockly.Translate('
|
|
211
|
-
[Blockly.Translate('
|
|
226
|
+
[Blockly.Translate('http_timeout_ms'), 'ms'],
|
|
227
|
+
[Blockly.Translate('http_timeout_sec'), 'sec']
|
|
212
228
|
]), 'UNIT');
|
|
213
229
|
|
|
230
|
+
this.appendDummyInput('TYPE')
|
|
231
|
+
.appendField(Blockly.Translate('http_type'))
|
|
232
|
+
.appendField(new Blockly.FieldDropdown([
|
|
233
|
+
[Blockly.Translate('http_type_text'), 'text'],
|
|
234
|
+
[Blockly.Translate('http_type_arraybuffer'), 'arraybuffer'],
|
|
235
|
+
]), 'TYPE');
|
|
236
|
+
|
|
214
237
|
this.appendValueInput('DATA')
|
|
215
238
|
.appendField(Blockly.Translate('http_post_data'));
|
|
216
239
|
|
|
@@ -240,11 +263,16 @@ Blockly.JavaScript['http_post'] = function(block) {
|
|
|
240
263
|
timeout *= 1000;
|
|
241
264
|
}
|
|
242
265
|
|
|
266
|
+
let responseType = block.getFieldValue('TYPE');
|
|
267
|
+
if (!responseType) {
|
|
268
|
+
responseType = 'text';
|
|
269
|
+
}
|
|
270
|
+
|
|
243
271
|
if (!data) {
|
|
244
272
|
data = 'null';
|
|
245
273
|
}
|
|
246
274
|
|
|
247
|
-
return `httpPost(${URL}, ${data}, { timeout: ${timeout} }, async (err, response) => {\n` +
|
|
275
|
+
return `httpPost(${URL}, ${data}, { timeout: ${timeout}, responseType: '${responseType}' }, async (err, response) => {\n` +
|
|
248
276
|
Blockly.JavaScript.prefixLines(`if (err) {`, Blockly.JavaScript.INDENT) + '\n' +
|
|
249
277
|
Blockly.JavaScript.prefixLines(`console.error(err);`, Blockly.JavaScript.INDENT + Blockly.JavaScript.INDENT) + '\n' +
|
|
250
278
|
Blockly.JavaScript.prefixLines(`}`, Blockly.JavaScript.INDENT) + '\n' +
|
|
@@ -252,7 +280,7 @@ Blockly.JavaScript['http_post'] = function(block) {
|
|
|
252
280
|
'});\n';
|
|
253
281
|
};
|
|
254
282
|
|
|
255
|
-
// ---
|
|
283
|
+
// --- http_response -----------------------------------------------------------
|
|
256
284
|
Blockly.Action.blocks['http_response'] =
|
|
257
285
|
'<block type="http_response">'
|
|
258
286
|
+ ' <value name="ATTR">'
|
|
@@ -276,7 +304,7 @@ Blockly.Blocks['http_response'] = {
|
|
|
276
304
|
|
|
277
305
|
this.setInputsInline(true);
|
|
278
306
|
this.setOutput(true);
|
|
279
|
-
this.setColour(Blockly.
|
|
307
|
+
this.setColour(Blockly.Action.HUE);
|
|
280
308
|
this.setTooltip(Blockly.Translate('http_response_tooltip'));
|
|
281
309
|
//this.setHelpUrl(getHelp('http_response'));
|
|
282
310
|
},
|
|
@@ -317,6 +345,196 @@ Blockly.JavaScript['http_response'] = function(block) {
|
|
|
317
345
|
return [attr, Blockly.JavaScript.ORDER_ATOMIC];
|
|
318
346
|
};
|
|
319
347
|
|
|
348
|
+
// --- action file_write --------------------------------------------------
|
|
349
|
+
Blockly.Action.blocks['file_write'] =
|
|
350
|
+
'<block type="file_write">'
|
|
351
|
+
+ ' <value name="OID">'
|
|
352
|
+
+ ' <shadow type="field_oid_meta">'
|
|
353
|
+
+ ' <field name="oid">0_userdata.0</field>'
|
|
354
|
+
+ ' </shadow>'
|
|
355
|
+
+ ' </value>'
|
|
356
|
+
+ ' <value name="FILE">'
|
|
357
|
+
+ ' <shadow type="text">'
|
|
358
|
+
+ ' <field name="TEXT">demo.json</field>'
|
|
359
|
+
+ ' </shadow>'
|
|
360
|
+
+ ' </value>'
|
|
361
|
+
+ ' <value name="DATA">'
|
|
362
|
+
+ ' </value>'
|
|
363
|
+
+ '</block>';
|
|
364
|
+
|
|
365
|
+
Blockly.Blocks['file_write'] = {
|
|
366
|
+
init: function() {
|
|
367
|
+
this.appendValueInput('OID')
|
|
368
|
+
.appendField('📁 ' + Blockly.Translate('file_write'));
|
|
369
|
+
|
|
370
|
+
this.appendValueInput('FILE')
|
|
371
|
+
.appendField(Blockly.Translate('file_write_filename'))
|
|
372
|
+
.setCheck(null);
|
|
373
|
+
|
|
374
|
+
this.appendValueInput('DATA')
|
|
375
|
+
.appendField(Blockly.Translate('file_write_data'));
|
|
376
|
+
|
|
377
|
+
this.setInputsInline(false);
|
|
378
|
+
this.setPreviousStatement(true, null);
|
|
379
|
+
this.setNextStatement(true, null);
|
|
380
|
+
|
|
381
|
+
this.setColour(Blockly.Action.HUE);
|
|
382
|
+
this.setTooltip(Blockly.Translate('file_write_tooltip'));
|
|
383
|
+
this.setHelpUrl(getHelp('file_write_help'));
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
Blockly.JavaScript['file_write'] = function(block) {
|
|
388
|
+
const value_objectid = Blockly.JavaScript.valueToCode(block, 'OID', Blockly.JavaScript.ORDER_ATOMIC);
|
|
389
|
+
const file = Blockly.JavaScript.valueToCode(block, 'FILE', Blockly.JavaScript.ORDER_ATOMIC);
|
|
390
|
+
const data = Blockly.JavaScript.valueToCode(block, 'DATA', Blockly.JavaScript.ORDER_ATOMIC);
|
|
391
|
+
|
|
392
|
+
let objectName = '';
|
|
393
|
+
try {
|
|
394
|
+
const objId = eval(value_objectid); // Code to string
|
|
395
|
+
objectName = main.objects[objId] && main.objects[objId].common && main.objects[objId].common.name ? main.objects[objId].common.name : '';
|
|
396
|
+
if (typeof objectName === 'object') {
|
|
397
|
+
objectName = objectName[systemLang] || objectName.en;
|
|
398
|
+
}
|
|
399
|
+
} catch (error) {
|
|
400
|
+
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return `writeFile(${value_objectid}${objectName ? ` /* ${objectName} */` : ''}, String(${file}), ${data ? data : 'null'}, (err) => {\n` +
|
|
404
|
+
Blockly.JavaScript.prefixLines(`if (err) {`, Blockly.JavaScript.INDENT) + '\n' +
|
|
405
|
+
Blockly.JavaScript.prefixLines(`console.error(err);`, Blockly.JavaScript.INDENT + Blockly.JavaScript.INDENT) + '\n' +
|
|
406
|
+
Blockly.JavaScript.prefixLines(`}`, Blockly.JavaScript.INDENT) + '\n' +
|
|
407
|
+
'});\n';
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
// --- action file_read --------------------------------------------------
|
|
411
|
+
Blockly.Action.blocks['file_read'] =
|
|
412
|
+
'<block type="file_read">'
|
|
413
|
+
+ ' <value name="OID">'
|
|
414
|
+
+ ' <shadow type="field_oid_meta">'
|
|
415
|
+
+ ' <field name="oid">0_userdata.0</field>'
|
|
416
|
+
+ ' </shadow>'
|
|
417
|
+
+ ' </value>'
|
|
418
|
+
+ ' <value name="FILE">'
|
|
419
|
+
+ ' <shadow type="text">'
|
|
420
|
+
+ ' <field name="TEXT">demo.json</field>'
|
|
421
|
+
+ ' </shadow>'
|
|
422
|
+
+ ' </value>'
|
|
423
|
+
+ ' <value name="STATEMENT">'
|
|
424
|
+
+ ' </value>'
|
|
425
|
+
+ '</block>';
|
|
426
|
+
|
|
427
|
+
Blockly.Blocks['file_read'] = {
|
|
428
|
+
init: function() {
|
|
429
|
+
this.appendValueInput('OID')
|
|
430
|
+
.appendField('📁 ' + Blockly.Translate('file_read'));
|
|
431
|
+
|
|
432
|
+
this.appendValueInput('FILE')
|
|
433
|
+
.appendField(Blockly.Translate('file_read_filename'))
|
|
434
|
+
.setCheck(null);
|
|
435
|
+
|
|
436
|
+
this.appendStatementInput('STATEMENT')
|
|
437
|
+
.setCheck(null);
|
|
438
|
+
|
|
439
|
+
this.setInputsInline(false);
|
|
440
|
+
this.setPreviousStatement(true, null);
|
|
441
|
+
this.setNextStatement(true, null);
|
|
442
|
+
|
|
443
|
+
this.setColour(Blockly.Action.HUE);
|
|
444
|
+
this.setTooltip(Blockly.Translate('file_read_tooltip'));
|
|
445
|
+
this.setHelpUrl(getHelp('file_read_help'));
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
Blockly.JavaScript['file_read'] = function(block) {
|
|
450
|
+
const value_objectid = Blockly.JavaScript.valueToCode(block, 'OID', Blockly.JavaScript.ORDER_ATOMIC);
|
|
451
|
+
const file = Blockly.JavaScript.valueToCode(block, 'FILE', Blockly.JavaScript.ORDER_ATOMIC);
|
|
452
|
+
const statement = Blockly.JavaScript.statementToCode(block, 'STATEMENT');
|
|
453
|
+
|
|
454
|
+
let objectName = '';
|
|
455
|
+
try {
|
|
456
|
+
const objId = eval(value_objectid); // Code to string
|
|
457
|
+
objectName = main.objects[objId] && main.objects[objId].common && main.objects[objId].common.name ? main.objects[objId].common.name : '';
|
|
458
|
+
if (typeof objectName === 'object') {
|
|
459
|
+
objectName = objectName[systemLang] || objectName.en;
|
|
460
|
+
}
|
|
461
|
+
} catch (error) {
|
|
462
|
+
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
return `readFile(${value_objectid}${objectName ? ` /* ${objectName} */` : ''}, String(${file}), (err, data, mimeType) => {\n` +
|
|
466
|
+
Blockly.JavaScript.prefixLines(`if (err) {`, Blockly.JavaScript.INDENT) + '\n' +
|
|
467
|
+
Blockly.JavaScript.prefixLines(`console.error(err);`, Blockly.JavaScript.INDENT + Blockly.JavaScript.INDENT) + '\n' +
|
|
468
|
+
Blockly.JavaScript.prefixLines(`}`, Blockly.JavaScript.INDENT) + '\n' +
|
|
469
|
+
statement +
|
|
470
|
+
'});\n';
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
// --- file_data -----------------------------------------------------------
|
|
474
|
+
Blockly.Action.blocks['file_data'] =
|
|
475
|
+
'<block type="file_data">'
|
|
476
|
+
+ ' <value name="ATTR">'
|
|
477
|
+
+ ' </value>'
|
|
478
|
+
+ '</block>';
|
|
479
|
+
|
|
480
|
+
Blockly.Blocks['file_data'] = {
|
|
481
|
+
/**
|
|
482
|
+
* Block for conditionally returning a value from a procedure.
|
|
483
|
+
* @this Blockly.Block
|
|
484
|
+
*/
|
|
485
|
+
init: function() {
|
|
486
|
+
this.appendDummyInput()
|
|
487
|
+
.appendField('📁');
|
|
488
|
+
|
|
489
|
+
this.appendDummyInput('ATTR')
|
|
490
|
+
.appendField(new Blockly.FieldDropdown([
|
|
491
|
+
[Blockly.Translate('file_data_data'), 'data'],
|
|
492
|
+
[Blockly.Translate('file_data_mimeType'), 'mimeType'],
|
|
493
|
+
]), 'ATTR');
|
|
494
|
+
|
|
495
|
+
this.setInputsInline(true);
|
|
496
|
+
this.setOutput(true);
|
|
497
|
+
this.setColour(Blockly.Action.HUE);
|
|
498
|
+
this.setTooltip(Blockly.Translate('file_data_tooltip'));
|
|
499
|
+
//this.setHelpUrl(getHelp('file_data'));
|
|
500
|
+
},
|
|
501
|
+
/**
|
|
502
|
+
* Called whenever anything on the workspace changes.
|
|
503
|
+
* Add warning if this flow block is not nested inside a loop.
|
|
504
|
+
* @param {!Blockly.Events.Abstract} e Change event.
|
|
505
|
+
* @this Blockly.Block
|
|
506
|
+
*/
|
|
507
|
+
onchange: function(e) {
|
|
508
|
+
let legal = false;
|
|
509
|
+
// Is the block nested in a trigger?
|
|
510
|
+
let block = this;
|
|
511
|
+
do {
|
|
512
|
+
if (this.FUNCTION_TYPES.includes(block.type)) {
|
|
513
|
+
legal = true;
|
|
514
|
+
break;
|
|
515
|
+
}
|
|
516
|
+
block = block.getSurroundParent();
|
|
517
|
+
} while (block);
|
|
518
|
+
|
|
519
|
+
if (legal) {
|
|
520
|
+
this.setWarningText(null, this.id);
|
|
521
|
+
} else {
|
|
522
|
+
this.setWarningText(Blockly.Translate('file_data_warning'), this.id);
|
|
523
|
+
}
|
|
524
|
+
},
|
|
525
|
+
/**
|
|
526
|
+
* List of block types that are functions and thus do not need warnings.
|
|
527
|
+
* To add a new function type add this to your code:
|
|
528
|
+
* Blockly.Blocks['procedures_ifreturn'].FUNCTION_TYPES.push('custom_func');
|
|
529
|
+
*/
|
|
530
|
+
FUNCTION_TYPES: ['file_read'],
|
|
531
|
+
};
|
|
532
|
+
Blockly.JavaScript['file_data'] = function(block) {
|
|
533
|
+
const attr = block.getFieldValue('ATTR');
|
|
534
|
+
|
|
535
|
+
return [attr, Blockly.JavaScript.ORDER_ATOMIC];
|
|
536
|
+
};
|
|
537
|
+
|
|
320
538
|
// --- action request --------------------------------------------------
|
|
321
539
|
Blockly.Action.blocks['request'] =
|
|
322
540
|
'<block type="request">'
|
|
@@ -403,7 +621,7 @@ Blockly.JavaScript['request'] = function(block) {
|
|
|
403
621
|
logText = '';
|
|
404
622
|
}
|
|
405
623
|
|
|
406
|
-
logText += `console.warn('request blockly block is deprecated - please use "http
|
|
624
|
+
logText += `console.warn('request blockly block is deprecated - please use "http (GET)" instead');\n`;
|
|
407
625
|
|
|
408
626
|
if (withStatement === 'TRUE' || withStatement === 'true' || withStatement === true) {
|
|
409
627
|
const statement = Blockly.JavaScript.statementToCode(block, 'STATEMENT');
|
|
@@ -102,7 +102,7 @@ Blockly.Blocks['control'] = {
|
|
|
102
102
|
.appendField(Blockly.Translate('control'));
|
|
103
103
|
|
|
104
104
|
this.appendDummyInput('OID')
|
|
105
|
-
.appendField(new Blockly.FieldOID('
|
|
105
|
+
.appendField(new Blockly.FieldOID(Blockly.Translate('select_id'), 'state'), 'OID');
|
|
106
106
|
|
|
107
107
|
this.appendValueInput('VALUE')
|
|
108
108
|
.setCheck(null)
|
|
@@ -222,7 +222,7 @@ Blockly.Blocks['toggle'] = {
|
|
|
222
222
|
.appendField(Blockly.Translate('toggle'));
|
|
223
223
|
|
|
224
224
|
this.appendDummyInput('OID')
|
|
225
|
-
.appendField(new Blockly.FieldOID('
|
|
225
|
+
.appendField(new Blockly.FieldOID(Blockly.Translate('select_id'), 'state'), 'OID');
|
|
226
226
|
|
|
227
227
|
this.appendDummyInput('WITH_DELAY')
|
|
228
228
|
.appendField(Blockly.Translate('toggle_delay'))
|
|
@@ -362,7 +362,7 @@ Blockly.Blocks['update'] = {
|
|
|
362
362
|
.appendField(Blockly.Translate('update'));
|
|
363
363
|
|
|
364
364
|
this.appendDummyInput('OID')
|
|
365
|
-
.appendField(new Blockly.FieldOID('
|
|
365
|
+
.appendField(new Blockly.FieldOID(Blockly.Translate('select_id'), 'state'), 'OID');
|
|
366
366
|
|
|
367
367
|
this.appendValueInput('VALUE')
|
|
368
368
|
.setCheck(null)
|
|
@@ -775,7 +775,6 @@ Blockly.Blocks['get_value'] = {
|
|
|
775
775
|
[Blockly.Translate('get_common_unit'), 'common.unit'],
|
|
776
776
|
[Blockly.Translate('get_common_role'), 'common.role'],
|
|
777
777
|
[Blockly.Translate('get_common_state_type'), 'common.type'],
|
|
778
|
-
[Blockly.Translate('get_common_object_type'), 'type'],
|
|
779
778
|
[Blockly.Translate('get_common_read'), 'common.read'],
|
|
780
779
|
[Blockly.Translate('get_common_write'), 'common.write'],
|
|
781
780
|
]), 'ATTR');
|
|
@@ -784,7 +783,7 @@ Blockly.Blocks['get_value'] = {
|
|
|
784
783
|
.appendField(Blockly.Translate('get_value_OID'));
|
|
785
784
|
|
|
786
785
|
this.appendDummyInput()
|
|
787
|
-
.appendField(new Blockly.FieldOID(Blockly.Translate('
|
|
786
|
+
.appendField(new Blockly.FieldOID(Blockly.Translate('select_id'), 'state'), 'OID');
|
|
788
787
|
|
|
789
788
|
this.setInputsInline(true);
|
|
790
789
|
this.setOutput(true);
|
|
@@ -849,7 +848,6 @@ Blockly.Blocks['get_value_var'] = {
|
|
|
849
848
|
[Blockly.Translate('get_common_unit'), 'common.unit'],
|
|
850
849
|
[Blockly.Translate('get_common_role'), 'common.role'],
|
|
851
850
|
[Blockly.Translate('get_common_state_type'), 'common.type'],
|
|
852
|
-
[Blockly.Translate('get_common_object_type'), 'type'],
|
|
853
851
|
[Blockly.Translate('get_common_read'), 'common.read'],
|
|
854
852
|
[Blockly.Translate('get_common_write'), 'common.write'],
|
|
855
853
|
]), 'ATTR');
|
|
@@ -922,7 +920,6 @@ Blockly.Blocks['get_value_async'] = {
|
|
|
922
920
|
[Blockly.Translate('get_common_unit'), 'common.unit'],
|
|
923
921
|
[Blockly.Translate('get_common_role'), 'common.role'],
|
|
924
922
|
[Blockly.Translate('get_common_state_type'), 'common.type'],
|
|
925
|
-
[Blockly.Translate('get_common_object_type'), 'type'],
|
|
926
923
|
[Blockly.Translate('get_common_read'), 'common.read'],
|
|
927
924
|
[Blockly.Translate('get_common_write'), 'common.write'],
|
|
928
925
|
]), 'ATTR');
|
|
@@ -931,7 +928,7 @@ Blockly.Blocks['get_value_async'] = {
|
|
|
931
928
|
.appendField(Blockly.Translate('get_value_OID'));
|
|
932
929
|
|
|
933
930
|
this.appendDummyInput()
|
|
934
|
-
.appendField(new Blockly.FieldOID(Blockly.Translate('
|
|
931
|
+
.appendField(new Blockly.FieldOID(Blockly.Translate('select_id'), 'state'), 'OID');
|
|
935
932
|
|
|
936
933
|
this.appendStatementInput('STATEMENT')
|
|
937
934
|
.setCheck(null);
|
|
@@ -978,7 +975,7 @@ Blockly.Blocks['get_object'] = {
|
|
|
978
975
|
.appendField(Blockly.Translate('get_object'));
|
|
979
976
|
|
|
980
977
|
this.appendDummyInput()
|
|
981
|
-
.appendField(new Blockly.FieldOID(Blockly.Translate('
|
|
978
|
+
.appendField(new Blockly.FieldOID(Blockly.Translate('select_id'), 'all'), 'OID');
|
|
982
979
|
|
|
983
980
|
this.setInputsInline(true);
|
|
984
981
|
this.setOutput(true);
|
|
@@ -1024,7 +1021,7 @@ Blockly.Blocks['get_object_async'] = {
|
|
|
1024
1021
|
.appendField(Blockly.Translate('get_object'));
|
|
1025
1022
|
|
|
1026
1023
|
this.appendDummyInput()
|
|
1027
|
-
.appendField(new Blockly.FieldOID(Blockly.Translate('
|
|
1024
|
+
.appendField(new Blockly.FieldOID(Blockly.Translate('select_id'), 'all'), 'OID');
|
|
1028
1025
|
|
|
1029
1026
|
this.appendStatementInput('STATEMENT')
|
|
1030
1027
|
.setCheck(null);
|
|
@@ -1061,7 +1058,7 @@ Blockly.Blocks['field_oid'] = {
|
|
|
1061
1058
|
.appendField(Blockly.Translate('field_oid_OID'));
|
|
1062
1059
|
|
|
1063
1060
|
this.appendDummyInput()
|
|
1064
|
-
.appendField(new Blockly.FieldOID('
|
|
1061
|
+
.appendField(new Blockly.FieldOID(Blockly.Translate('select_id'), 'state'), 'oid');
|
|
1065
1062
|
|
|
1066
1063
|
this.setInputsInline(true);
|
|
1067
1064
|
this.setColour("%{BKY_TEXTS_HUE}");
|
|
@@ -1089,7 +1086,7 @@ Blockly.Blocks['field_oid_meta'] = {
|
|
|
1089
1086
|
.appendField(Blockly.Translate('field_oid_OID_meta'));
|
|
1090
1087
|
|
|
1091
1088
|
this.appendDummyInput()
|
|
1092
|
-
.appendField(new Blockly.FieldOID('
|
|
1089
|
+
.appendField(new Blockly.FieldOID(Blockly.Translate('select_id'), 'meta'), 'oid');
|
|
1093
1090
|
|
|
1094
1091
|
this.setInputsInline(true);
|
|
1095
1092
|
this.setColour("%{BKY_TEXTS_HUE}");
|
|
@@ -1117,7 +1114,7 @@ Blockly.Blocks['field_oid_script'] = {
|
|
|
1117
1114
|
.appendField(Blockly.Translate('field_oid_OID_script'));
|
|
1118
1115
|
|
|
1119
1116
|
this.appendDummyInput()
|
|
1120
|
-
.appendField(new Blockly.FieldOID('
|
|
1117
|
+
.appendField(new Blockly.FieldOID(Blockly.Translate('select_id'), 'script'), 'oid');
|
|
1121
1118
|
|
|
1122
1119
|
this.setInputsInline(true);
|
|
1123
1120
|
this.setColour("%{BKY_TEXTS_HUE}");
|
|
@@ -350,7 +350,7 @@ Blockly.Blocks['on'] = {
|
|
|
350
350
|
.appendField(Blockly.Translate('on'));
|
|
351
351
|
|
|
352
352
|
this.appendDummyInput('OID')
|
|
353
|
-
.appendField(new Blockly.FieldOID('
|
|
353
|
+
.appendField(new Blockly.FieldOID(Blockly.Translate('select_id'), 'state'), 'OID');
|
|
354
354
|
|
|
355
355
|
this.appendDummyInput('CONDITION')
|
|
356
356
|
.appendField(new Blockly.FieldDropdown([
|
|
@@ -610,7 +610,7 @@ Blockly.Blocks['schedule_by_id'] = {
|
|
|
610
610
|
.appendField(Blockly.Translate('schedule_by_id'));
|
|
611
611
|
|
|
612
612
|
this.appendDummyInput('OID')
|
|
613
|
-
.appendField(new Blockly.FieldOID('
|
|
613
|
+
.appendField(new Blockly.FieldOID(Blockly.Translate('select_id'), 'state'), 'OID');
|
|
614
614
|
|
|
615
615
|
this.appendDummyInput('ACK_CONDITION')
|
|
616
616
|
.appendField(Blockly.Translate('on_ack'))
|
|
@@ -1192,7 +1192,7 @@ Blockly.Trigger.blocks['onFile'] =
|
|
|
1192
1192
|
+ ' </value>'
|
|
1193
1193
|
+ ' <value name="FILE">'
|
|
1194
1194
|
+ ' <shadow type="text">'
|
|
1195
|
-
+ ' <field name="
|
|
1195
|
+
+ ' <field name="TEXT">*</field>'
|
|
1196
1196
|
+ ' </shadow>'
|
|
1197
1197
|
+ ' </value>'
|
|
1198
1198
|
+ ' <value name="WITH_FILE">'
|
|
@@ -1204,7 +1204,7 @@ Blockly.Trigger.blocks['onFile'] =
|
|
|
1204
1204
|
Blockly.Blocks['onFile'] = {
|
|
1205
1205
|
init: function() {
|
|
1206
1206
|
this.appendValueInput('OID')
|
|
1207
|
-
.appendField(Blockly.Translate('onFile'))
|
|
1207
|
+
.appendField('📁 ' + Blockly.Translate('onFile'))
|
|
1208
1208
|
.setCheck(null);
|
|
1209
1209
|
|
|
1210
1210
|
this.appendValueInput('FILE')
|
|
@@ -1274,6 +1274,74 @@ Blockly.JavaScript['onFile'] = function (block) {
|
|
|
1274
1274
|
'});\n';
|
|
1275
1275
|
};
|
|
1276
1276
|
|
|
1277
|
+
// --- onFile_data -----------------------------------------------------------
|
|
1278
|
+
Blockly.Trigger.blocks['onFile_data'] =
|
|
1279
|
+
'<block type="onFile_data">'
|
|
1280
|
+
+ ' <value name="ATTR">'
|
|
1281
|
+
+ ' </value>'
|
|
1282
|
+
+ '</block>';
|
|
1283
|
+
|
|
1284
|
+
Blockly.Blocks['onFile_data'] = {
|
|
1285
|
+
/**
|
|
1286
|
+
* Block for conditionally returning a value from a procedure.
|
|
1287
|
+
* @this Blockly.Block
|
|
1288
|
+
*/
|
|
1289
|
+
init: function() {
|
|
1290
|
+
this.appendDummyInput()
|
|
1291
|
+
.appendField('📁');
|
|
1292
|
+
|
|
1293
|
+
this.appendDummyInput('ATTR')
|
|
1294
|
+
.appendField(new Blockly.FieldDropdown([
|
|
1295
|
+
[Blockly.Translate('onFile_data_data'), 'data'],
|
|
1296
|
+
[Blockly.Translate('onFile_data_filename'), 'fileName'],
|
|
1297
|
+
[Blockly.Translate('onFile_data_size'), 'size'],
|
|
1298
|
+
[Blockly.Translate('onFile_data_mimeType'), 'mimeType'],
|
|
1299
|
+
[Blockly.Translate('onFile_data_id'), 'id'],
|
|
1300
|
+
]), 'ATTR');
|
|
1301
|
+
|
|
1302
|
+
this.setInputsInline(true);
|
|
1303
|
+
this.setOutput(true);
|
|
1304
|
+
this.setColour(Blockly.Trigger.HUE);
|
|
1305
|
+
this.setTooltip(Blockly.Translate('onFile_datatooltip'));
|
|
1306
|
+
//this.setHelpUrl(getHelp('onFile_data'));
|
|
1307
|
+
},
|
|
1308
|
+
/**
|
|
1309
|
+
* Called whenever anything on the workspace changes.
|
|
1310
|
+
* Add warning if this flow block is not nested inside a loop.
|
|
1311
|
+
* @param {!Blockly.Events.Abstract} e Change event.
|
|
1312
|
+
* @this Blockly.Block
|
|
1313
|
+
*/
|
|
1314
|
+
onchange: function(e) {
|
|
1315
|
+
let legal = false;
|
|
1316
|
+
// Is the block nested in a trigger?
|
|
1317
|
+
let block = this;
|
|
1318
|
+
do {
|
|
1319
|
+
if (this.FUNCTION_TYPES.includes(block.type)) {
|
|
1320
|
+
legal = true;
|
|
1321
|
+
break;
|
|
1322
|
+
}
|
|
1323
|
+
block = block.getSurroundParent();
|
|
1324
|
+
} while (block);
|
|
1325
|
+
|
|
1326
|
+
if (legal) {
|
|
1327
|
+
this.setWarningText(null, this.id);
|
|
1328
|
+
} else {
|
|
1329
|
+
this.setWarningText(Blockly.Translate('onFile_data_warning'), this.id);
|
|
1330
|
+
}
|
|
1331
|
+
},
|
|
1332
|
+
/**
|
|
1333
|
+
* List of block types that are functions and thus do not need warnings.
|
|
1334
|
+
* To add a new function type add this to your code:
|
|
1335
|
+
* Blockly.Blocks['procedures_ifreturn'].FUNCTION_TYPES.push('custom_func');
|
|
1336
|
+
*/
|
|
1337
|
+
FUNCTION_TYPES: ['onFile'],
|
|
1338
|
+
};
|
|
1339
|
+
Blockly.JavaScript['onFile_data'] = function(block) {
|
|
1340
|
+
const attr = block.getFieldValue('ATTR');
|
|
1341
|
+
|
|
1342
|
+
return [attr, Blockly.JavaScript.ORDER_ATOMIC];
|
|
1343
|
+
};
|
|
1344
|
+
|
|
1277
1345
|
// --- onFile -----------------------------------------------------------
|
|
1278
1346
|
Blockly.Trigger.blocks['offFile'] =
|
|
1279
1347
|
'<block type="offFile">'
|
|
@@ -1284,7 +1352,7 @@ Blockly.Trigger.blocks['offFile'] =
|
|
|
1284
1352
|
+ ' </value>'
|
|
1285
1353
|
+ ' <value name="FILE">'
|
|
1286
1354
|
+ ' <shadow type="text">'
|
|
1287
|
-
+ ' <field name="
|
|
1355
|
+
+ ' <field name="TEXT">*</field>'
|
|
1288
1356
|
+ ' </shadow>'
|
|
1289
1357
|
+ ' </value>'
|
|
1290
1358
|
+ '</block>';
|
|
@@ -1292,7 +1360,7 @@ Blockly.Trigger.blocks['offFile'] =
|
|
|
1292
1360
|
Blockly.Blocks['offFile'] = {
|
|
1293
1361
|
init: function() {
|
|
1294
1362
|
this.appendValueInput('OID')
|
|
1295
|
-
.appendField(Blockly.Translate('offFile'))
|
|
1363
|
+
.appendField('📁 ' + Blockly.Translate('offFile'))
|
|
1296
1364
|
.setCheck(null);
|
|
1297
1365
|
|
|
1298
1366
|
this.appendValueInput('FILE')
|