iobroker.javascript 7.0.7 → 7.0.10
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 +6 -12
- package/admin/asset-manifest.json +7 -7
- package/admin/google-blockly/blockly_compressed.js +1469 -1704
- package/admin/google-blockly/blocks_compressed.js +164 -218
- package/admin/google-blockly/javascript_compressed.js +100 -328
- package/admin/google-blockly/msg/js/de.js +64 -70
- package/admin/google-blockly/msg/js/en.js +14 -20
- package/admin/google-blockly/msg/js/es.js +39 -45
- package/admin/google-blockly/msg/js/fr.js +59 -65
- package/admin/google-blockly/msg/js/it.js +19 -25
- package/admin/google-blockly/msg/js/nl.js +55 -61
- package/admin/google-blockly/msg/js/pl.js +46 -52
- package/admin/google-blockly/msg/js/pt.js +30 -36
- package/admin/google-blockly/msg/js/ru.js +41 -47
- package/admin/google-blockly/msg/js/uk.js +13 -17
- package/admin/google-blockly/msg/js/zh-cn.js +86 -92
- package/admin/google-blockly/own/blocks_action.js +4 -4
- package/admin/google-blockly/own/blocks_logic.js +2 -2
- package/admin/google-blockly/own/blocks_procedures.js +63 -62
- package/admin/google-blockly/own/blocks_sendto.js +62 -60
- package/admin/google-blockly/own/blocks_switch.js +40 -29
- package/admin/google-blockly/own/blocks_system.js +109 -170
- package/admin/google-blockly/own/blocks_time.js +35 -35
- package/admin/google-blockly/own/blocks_timeout.js +42 -42
- package/admin/google-blockly/own/blocks_trigger.js +51 -68
- package/admin/google-blockly/own/blocks_words.js +12 -8
- package/admin/google-blockly/own/field_cron.js +189 -139
- package/admin/google-blockly/own/field_oid.js +250 -170
- package/admin/google-blockly/own/field_script.js +168 -122
- package/admin/static/js/{565.643198c0.chunk.js → 569.e2b427a7.chunk.js} +2 -2
- package/admin/static/js/569.e2b427a7.chunk.js.map +1 -0
- package/admin/static/js/759.7f25ba6c.chunk.js.map +1 -1
- package/admin/static/js/98.eee0c52f.chunk.js +2 -0
- package/admin/static/js/98.eee0c52f.chunk.js.map +1 -0
- package/admin/static/js/{main.d86fb9de.js → main.d5dc2784.js} +2 -2
- package/admin/static/js/{main.d86fb9de.js.map → main.d5dc2784.js.map} +1 -1
- package/admin/tab.html +1 -1
- package/io-package.json +27 -27
- package/package.json +1 -1
- package/admin/static/js/565.643198c0.chunk.js.map +0 -1
- package/admin/static/js/98.f78be4fc.chunk.js +0 -2
- package/admin/static/js/98.f78be4fc.chunk.js.map +0 -1
|
@@ -14,14 +14,14 @@ if (Blockly.Blocks['procedures_ifreturn'].FUNCTION_TYPES.indexOf('procedures_def
|
|
|
14
14
|
* list, and return value boolean.
|
|
15
15
|
*/
|
|
16
16
|
Blockly.Procedures.allProcedures = function(root) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
for (
|
|
17
|
+
const blocks = root.getAllBlocks();
|
|
18
|
+
const proceduresReturn = [];
|
|
19
|
+
const proceduresNoReturn = [];
|
|
20
|
+
const proceduresCustomReturn = [];
|
|
21
|
+
const proceduresCustomNoReturn = [];
|
|
22
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
23
23
|
if (blocks[i].getProcedureDef) {
|
|
24
|
-
|
|
24
|
+
const tuple = blocks[i].getProcedureDef();
|
|
25
25
|
if (tuple) {
|
|
26
26
|
if (tuple[3]) {
|
|
27
27
|
if (tuple[2]) {
|
|
@@ -50,16 +50,16 @@ Blockly.Procedures.allProcedures = function(root) {
|
|
|
50
50
|
* @return {!Array.<!Element>} Array of XML block elements.
|
|
51
51
|
*/
|
|
52
52
|
Blockly.Procedures.flyoutCategory = function(workspace) {
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
const xmlList = [];
|
|
54
|
+
const utils = (Blockly.Xml.utils ? Blockly.Xml.utils : Blockly.utils.xml);
|
|
55
55
|
if (Blockly.Blocks['procedures_defnoreturn']) {
|
|
56
56
|
// <block type="procedures_defnoreturn" gap="16">
|
|
57
57
|
// <field name="NAME">do something</field>
|
|
58
58
|
// </block>
|
|
59
|
-
|
|
59
|
+
const block = utils.createElement('block');
|
|
60
60
|
block.setAttribute('type', 'procedures_defnoreturn');
|
|
61
61
|
block.setAttribute('gap', 16);
|
|
62
|
-
|
|
62
|
+
const nameField = utils.createElement('field');
|
|
63
63
|
nameField.setAttribute('name', 'NAME');
|
|
64
64
|
nameField.appendChild((Blockly.Xml.utils ? Blockly.Xml.utils : Blockly.utils.xml).createTextNode(
|
|
65
65
|
Blockly.Msg['PROCEDURES_DEFNORETURN_PROCEDURE']));
|
|
@@ -70,10 +70,10 @@ Blockly.Procedures.flyoutCategory = function(workspace) {
|
|
|
70
70
|
// <block type="procedures_defreturn" gap="16">
|
|
71
71
|
// <field name="NAME">do something</field>
|
|
72
72
|
// </block>
|
|
73
|
-
|
|
73
|
+
const block = utils.createElement('block');
|
|
74
74
|
block.setAttribute('type', 'procedures_defreturn');
|
|
75
75
|
block.setAttribute('gap', 16);
|
|
76
|
-
|
|
76
|
+
const nameField = utils.createElement('field');
|
|
77
77
|
nameField.setAttribute('name', 'NAME');
|
|
78
78
|
nameField.appendChild((Blockly.Xml.utils ? Blockly.Xml.utils : Blockly.utils.xml).createTextNode(
|
|
79
79
|
Blockly.Msg['PROCEDURES_DEFRETURN_PROCEDURE']));
|
|
@@ -82,7 +82,7 @@ Blockly.Procedures.flyoutCategory = function(workspace) {
|
|
|
82
82
|
}
|
|
83
83
|
if (Blockly.Blocks['procedures_ifreturn']) {
|
|
84
84
|
// <block type="procedures_ifreturn" gap="16"></block>
|
|
85
|
-
|
|
85
|
+
const block = utils.createElement('block');
|
|
86
86
|
block.setAttribute('type', 'procedures_ifreturn');
|
|
87
87
|
block.setAttribute('gap', 16);
|
|
88
88
|
xmlList.push(block);
|
|
@@ -91,10 +91,10 @@ Blockly.Procedures.flyoutCategory = function(workspace) {
|
|
|
91
91
|
// <block type="procedures_defcustomnoreturn" gap="16">
|
|
92
92
|
// <field name="NAME">do something</field>
|
|
93
93
|
// </block>
|
|
94
|
-
|
|
94
|
+
const block = utils.createElement('block');
|
|
95
95
|
block.setAttribute('type', 'procedures_defcustomnoreturn');
|
|
96
96
|
block.setAttribute('gap', 16);
|
|
97
|
-
|
|
97
|
+
const nameField = utils.createElement('field');
|
|
98
98
|
nameField.setAttribute('name', 'NAME');
|
|
99
99
|
nameField.appendChild((Blockly.Xml.utils ? Blockly.Xml.utils : Blockly.utils.xml).createTextNode(
|
|
100
100
|
Blockly.Msg['PROCEDURES_DEFNORETURN_PROCEDURE']));
|
|
@@ -105,10 +105,10 @@ Blockly.Procedures.flyoutCategory = function(workspace) {
|
|
|
105
105
|
// <block type="procedures_defcustomreturn" gap="16">
|
|
106
106
|
// <field name="NAME">do something</field>
|
|
107
107
|
// </block>
|
|
108
|
-
|
|
108
|
+
const block = utils.createElement('block');
|
|
109
109
|
block.setAttribute('type', 'procedures_defcustomreturn');
|
|
110
110
|
block.setAttribute('gap', 16);
|
|
111
|
-
|
|
111
|
+
const nameField = utils.createElement('field');
|
|
112
112
|
nameField.setAttribute('name', 'NAME');
|
|
113
113
|
nameField.appendChild((Blockly.Xml.utils ? Blockly.Xml.utils : Blockly.utils.xml).createTextNode(
|
|
114
114
|
Blockly.Msg['PROCEDURES_DEFRETURN_PROCEDURE']));
|
|
@@ -121,23 +121,23 @@ Blockly.Procedures.flyoutCategory = function(workspace) {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
function populateProcedures(procedureList, templateName) {
|
|
124
|
-
|
|
125
|
-
for (
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
const utils = (Blockly.Xml.utils ? Blockly.Xml.utils : Blockly.utils.xml);
|
|
125
|
+
for (let i = 0; i < procedureList.length; i++) {
|
|
126
|
+
const name = procedureList[i][0];
|
|
127
|
+
const args = procedureList[i][1];
|
|
128
128
|
// <block type="procedures_callnoreturn" gap="16">
|
|
129
129
|
// <mutation name="do something">
|
|
130
130
|
// <arg name="x"></arg>
|
|
131
131
|
// </mutation>
|
|
132
132
|
// </block>
|
|
133
|
-
|
|
133
|
+
const block = utils.createElement('block');
|
|
134
134
|
block.setAttribute('type', templateName);
|
|
135
135
|
block.setAttribute('gap', 16);
|
|
136
|
-
|
|
136
|
+
const mutation = utils.createElement('mutation');
|
|
137
137
|
mutation.setAttribute('name', name);
|
|
138
138
|
block.appendChild(mutation);
|
|
139
|
-
for (
|
|
140
|
-
|
|
139
|
+
for (let j = 0; j < args.length; j++) {
|
|
140
|
+
const arg = utils.createElement('arg');
|
|
141
141
|
arg.setAttribute('name', args[j]);
|
|
142
142
|
mutation.appendChild(arg);
|
|
143
143
|
}
|
|
@@ -145,7 +145,7 @@ Blockly.Procedures.flyoutCategory = function(workspace) {
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
|
|
148
|
+
const tuple = Blockly.Procedures.allProcedures(workspace);
|
|
149
149
|
populateProcedures(tuple[0], 'procedures_callnoreturn');
|
|
150
150
|
populateProcedures(tuple[1], 'procedures_callreturn');
|
|
151
151
|
populateProcedures(tuple[2], 'procedures_callcustomnoreturn');
|
|
@@ -157,9 +157,9 @@ Blockly.Procedures.flyoutCategory = function(workspace) {
|
|
|
157
157
|
// taken from javascript/procedures.js
|
|
158
158
|
Blockly.JavaScript['procedures_defreturn'] = function(block) {
|
|
159
159
|
// Define a procedure with a return value.
|
|
160
|
-
|
|
160
|
+
const funcName = Blockly.JavaScript.variableDB_.getName(
|
|
161
161
|
block.getFieldValue('NAME'), Blockly.PROCEDURE_CATEGORY_NAME);
|
|
162
|
-
|
|
162
|
+
let xfix1 = '';
|
|
163
163
|
if (Blockly.JavaScript.STATEMENT_PREFIX) {
|
|
164
164
|
xfix1 += Blockly.JavaScript.injectId(Blockly.JavaScript.STATEMENT_PREFIX,
|
|
165
165
|
block);
|
|
@@ -171,16 +171,16 @@ Blockly.JavaScript['procedures_defreturn'] = function(block) {
|
|
|
171
171
|
if (xfix1) {
|
|
172
172
|
xfix1 = Blockly.JavaScript.prefixLines(xfix1, Blockly.JavaScript.INDENT);
|
|
173
173
|
}
|
|
174
|
-
|
|
174
|
+
let loopTrap = '';
|
|
175
175
|
if (Blockly.JavaScript.INFINITE_LOOP_TRAP) {
|
|
176
176
|
loopTrap = Blockly.JavaScript.prefixLines(
|
|
177
177
|
Blockly.JavaScript.injectId(Blockly.JavaScript.INFINITE_LOOP_TRAP,
|
|
178
178
|
block), Blockly.JavaScript.INDENT);
|
|
179
179
|
}
|
|
180
|
-
|
|
181
|
-
|
|
180
|
+
const branch = Blockly.JavaScript.statementToCode(block, 'STACK');
|
|
181
|
+
let returnValue = Blockly.JavaScript.valueToCode(block, 'RETURN',
|
|
182
182
|
Blockly.JavaScript.ORDER_NONE) || '';
|
|
183
|
-
|
|
183
|
+
let xfix2 = '';
|
|
184
184
|
if (branch && returnValue) {
|
|
185
185
|
// After executing the function body, revisit this block for the return.
|
|
186
186
|
xfix2 = xfix1;
|
|
@@ -188,13 +188,13 @@ Blockly.JavaScript['procedures_defreturn'] = function(block) {
|
|
|
188
188
|
if (returnValue) {
|
|
189
189
|
returnValue = Blockly.JavaScript.INDENT + 'return ' + returnValue + ';\n';
|
|
190
190
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
for (
|
|
191
|
+
const args = [];
|
|
192
|
+
const variables = block.getVars();
|
|
193
|
+
for (let i = 0; i < variables.length; i++) {
|
|
194
194
|
args[i] = Blockly.JavaScript.variableDB_.getName(variables[i],
|
|
195
195
|
Blockly.VARIABLE_CATEGORY_NAME);
|
|
196
196
|
}
|
|
197
|
-
|
|
197
|
+
let code = 'async function ' + funcName + '(' + args.join(', ') + ') {\n' +
|
|
198
198
|
xfix1 + loopTrap + branch + xfix2 + returnValue + '}';
|
|
199
199
|
code = Blockly.JavaScript.scrub_(block, code);
|
|
200
200
|
// Add % so as not to collide with helper functions in definitions list.
|
|
@@ -204,15 +204,15 @@ Blockly.JavaScript['procedures_defreturn'] = function(block) {
|
|
|
204
204
|
|
|
205
205
|
Blockly.JavaScript['procedures_callreturn'] = function(block) {
|
|
206
206
|
// Call a procedure with a return value.
|
|
207
|
-
|
|
207
|
+
const funcName = Blockly.JavaScript.variableDB_.getName(
|
|
208
208
|
block.getFieldValue('NAME'), Blockly.PROCEDURE_CATEGORY_NAME);
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
for (
|
|
209
|
+
const args = [];
|
|
210
|
+
const variables = block.arguments_;
|
|
211
|
+
for (let i = 0; i < variables.length; i++) {
|
|
212
212
|
args[i] = Blockly.JavaScript.valueToCode(block, 'ARG' + i,
|
|
213
213
|
Blockly.JavaScript.ORDER_COMMA) || 'null';
|
|
214
214
|
}
|
|
215
|
-
|
|
215
|
+
const code = 'await ' + funcName + '(' + args.join(', ') + ')';
|
|
216
216
|
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
|
|
217
217
|
};
|
|
218
218
|
|
|
@@ -226,7 +226,7 @@ Blockly.Blocks['procedures_defcustomreturn'] = {
|
|
|
226
226
|
* @this Blockly.Block
|
|
227
227
|
*/
|
|
228
228
|
init: function() {
|
|
229
|
-
|
|
229
|
+
const nameField = new Blockly.FieldTextInput('',
|
|
230
230
|
Blockly.Procedures.rename);
|
|
231
231
|
|
|
232
232
|
nameField.setSpellcheck(false);
|
|
@@ -269,7 +269,7 @@ Blockly.Blocks['procedures_defcustomreturn'] = {
|
|
|
269
269
|
* @this Blockly.Block
|
|
270
270
|
*/
|
|
271
271
|
decompose: function (workspace) {
|
|
272
|
-
|
|
272
|
+
const containerBlock = workspace.newBlock('procedures_mutatorcontainer');
|
|
273
273
|
containerBlock.initSvg();
|
|
274
274
|
|
|
275
275
|
// Check/uncheck the allow statement box.
|
|
@@ -284,9 +284,9 @@ Blockly.Blocks['procedures_defcustomreturn'] = {
|
|
|
284
284
|
containerBlock.getInput('STATEMENT_INPUT').setVisible(false);
|
|
285
285
|
|
|
286
286
|
// Parameter list.
|
|
287
|
-
|
|
288
|
-
for (
|
|
289
|
-
|
|
287
|
+
let connection = containerBlock.getInput('STACK').connection;
|
|
288
|
+
for (let i = 0; i < this.arguments_.length; i++) {
|
|
289
|
+
const paramBlock = workspace.newBlock('procedures_mutatorarg');
|
|
290
290
|
paramBlock.initSvg();
|
|
291
291
|
paramBlock.setFieldValue(this.arguments_[i], 'NAME');
|
|
292
292
|
// Store the old location.
|
|
@@ -308,11 +308,11 @@ Blockly.Blocks['procedures_defcustomreturn'] = {
|
|
|
308
308
|
this.arguments_ = [];
|
|
309
309
|
this.paramIds_ = [];
|
|
310
310
|
this.argumentVarModels_ = [];
|
|
311
|
-
|
|
311
|
+
let paramBlock = containerBlock.getInputTargetBlock('STACK');
|
|
312
312
|
while (paramBlock) {
|
|
313
|
-
|
|
313
|
+
const varName = paramBlock.getFieldValue('NAME');
|
|
314
314
|
this.arguments_.push(varName);
|
|
315
|
-
|
|
315
|
+
const variable = this.workspace.getVariable(varName, '');
|
|
316
316
|
if (variable != null) {
|
|
317
317
|
this.argumentVarModels_.push(variable);
|
|
318
318
|
} else {
|
|
@@ -327,7 +327,7 @@ Blockly.Blocks['procedures_defcustomreturn'] = {
|
|
|
327
327
|
Blockly.Procedures.mutateCallers(this);
|
|
328
328
|
/*
|
|
329
329
|
// Show/hide the statement input.
|
|
330
|
-
|
|
330
|
+
let hasStatements = containerBlock.getFieldValue('STATEMENTS');
|
|
331
331
|
if (hasStatements !== null) {
|
|
332
332
|
hasStatements = hasStatements == 'TRUE';
|
|
333
333
|
if (this.hasStatements_ != hasStatements) {
|
|
@@ -338,10 +338,10 @@ Blockly.Blocks['procedures_defcustomreturn'] = {
|
|
|
338
338
|
this.statementConnection_ = null;
|
|
339
339
|
} else {
|
|
340
340
|
// Save the stack, then disconnect it.
|
|
341
|
-
|
|
341
|
+
const stackConnection = this.getInput('STACK').connection;
|
|
342
342
|
this.statementConnection_ = stackConnection.targetConnection;
|
|
343
343
|
if (this.statementConnection_) {
|
|
344
|
-
|
|
344
|
+
const stackBlock = stackConnection.targetBlock();
|
|
345
345
|
stackBlock.unplug();
|
|
346
346
|
stackBlock.bumpNeighbours_();
|
|
347
347
|
}
|
|
@@ -373,22 +373,22 @@ Blockly.Blocks['procedures_defcustomreturn'] = {
|
|
|
373
373
|
|
|
374
374
|
Blockly.JavaScript['procedures_defcustomreturn'] = function(block) {
|
|
375
375
|
// Define a procedure with a return value.
|
|
376
|
-
|
|
376
|
+
const funcName = Blockly.JavaScript.variableDB_.getName(
|
|
377
377
|
block.getFieldValue('NAME'), Blockly.Procedures.NAME_TYPE);
|
|
378
378
|
|
|
379
|
-
|
|
380
|
-
for (
|
|
379
|
+
const args = [];
|
|
380
|
+
for (let i = 0; i < block.arguments_.length; i++) {
|
|
381
381
|
args[i] = Blockly.JavaScript.variableDB_.getName(block.arguments_[i],
|
|
382
382
|
Blockly.Variables.NAME_TYPE);
|
|
383
383
|
}
|
|
384
384
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
for (
|
|
385
|
+
const script = Blockly.b64DecodeUnicode(block.getFieldValue('SCRIPT') || '');
|
|
386
|
+
const lines = script.split('\n');
|
|
387
|
+
for (let l = 0; l < lines.length; l++) {
|
|
388
388
|
lines[l] = ' ' + lines[l];
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
-
|
|
391
|
+
let code = 'async function ' + funcName + '(' + args.join(', ') + ') {\n' +
|
|
392
392
|
lines.join('\n') + '\n}';
|
|
393
393
|
|
|
394
394
|
code = Blockly.JavaScript.scrub_(block, code);
|
|
@@ -418,9 +418,10 @@ Blockly.JavaScript['procedures_callcustomreturn'] = Blockly.JavaScript['procedur
|
|
|
418
418
|
|
|
419
419
|
Blockly.Blocks['procedures_defcustomnoreturn'] = {
|
|
420
420
|
init: function() {
|
|
421
|
-
|
|
421
|
+
const nameField = new Blockly.FieldTextInput('',
|
|
422
422
|
Blockly.Procedures.rename);
|
|
423
423
|
nameField.setSpellcheck(false);
|
|
424
|
+
|
|
424
425
|
this.appendDummyInput()
|
|
425
426
|
.appendField(Blockly.Translate('procedures_defcustomnoreturn_name'))
|
|
426
427
|
.appendField(nameField, 'NAME')
|
|
@@ -485,6 +486,6 @@ Blockly.JavaScript['procedures_callcustomnoreturn'] = function(block) {
|
|
|
485
486
|
// Call a procedure with no return value.
|
|
486
487
|
// Generated code is for a function call as a statement is the same as a
|
|
487
488
|
// function call as a value, with the addition of line ending.
|
|
488
|
-
|
|
489
|
+
const tuple = Blockly.JavaScript['procedures_callcustomreturn'](block);
|
|
489
490
|
return tuple[0] + ';\n';
|
|
490
491
|
};
|
|
@@ -69,18 +69,18 @@ Blockly.Blocks['sendto_custom'] = {
|
|
|
69
69
|
* @this Blockly.Block
|
|
70
70
|
*/
|
|
71
71
|
init: function () {
|
|
72
|
-
|
|
72
|
+
const options = [];
|
|
73
73
|
if (typeof main !== 'undefined' && main.instances) {
|
|
74
|
-
for (
|
|
74
|
+
for (let i = 0; i < main.instances.length; i++) {
|
|
75
75
|
if (main.objects[main.instances[i]].common.messagebox) {
|
|
76
|
-
|
|
76
|
+
const id = main.instances[i].substring('system.adapter.'.length);
|
|
77
77
|
options.push([id, id]);
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
if (!options.length) {
|
|
81
81
|
options.push([Blockly.Translate('sendto_no_instances'), '']);
|
|
82
82
|
}
|
|
83
|
-
/*for (
|
|
83
|
+
/*for (let h = 0; h < scripts.hosts.length; h++) {
|
|
84
84
|
options.push([scripts.hosts[h], scripts.hosts[h]]);
|
|
85
85
|
}*/
|
|
86
86
|
this.appendDummyInput('INSTANCE')
|
|
@@ -130,15 +130,15 @@ Blockly.Blocks['sendto_custom'] = {
|
|
|
130
130
|
* @this Blockly.Block
|
|
131
131
|
*/
|
|
132
132
|
mutationToDom: function () {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
for (
|
|
136
|
-
|
|
133
|
+
const container = document.createElement('mutation');
|
|
134
|
+
const names = [];
|
|
135
|
+
for (let i = 0; i < this.itemCount_; i++) {
|
|
136
|
+
const input = this.getInput('ARG' + i);
|
|
137
137
|
names[i] = input.fieldRow[0].getValue();
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
container.setAttribute('items', names.join(','));
|
|
141
|
-
|
|
141
|
+
const withStatement = this.getFieldValue('WITH_STATEMENT');
|
|
142
142
|
container.setAttribute('with_statement', withStatement === 'TRUE' || withStatement === 'true' || withStatement === true);
|
|
143
143
|
return container;
|
|
144
144
|
},
|
|
@@ -148,9 +148,9 @@ Blockly.Blocks['sendto_custom'] = {
|
|
|
148
148
|
* @this Blockly.Block
|
|
149
149
|
*/
|
|
150
150
|
domToMutation: function (xmlElement) {
|
|
151
|
-
|
|
151
|
+
const names = xmlElement.getAttribute('items').split(',');
|
|
152
152
|
this.itemCount_ = names.length;
|
|
153
|
-
|
|
153
|
+
const withStatement = xmlElement.getAttribute('with_statement');
|
|
154
154
|
this.updateShape_(names, withStatement === true || withStatement === 'true' || withStatement === 'TRUE');
|
|
155
155
|
},
|
|
156
156
|
/**
|
|
@@ -160,11 +160,11 @@ Blockly.Blocks['sendto_custom'] = {
|
|
|
160
160
|
* @this Blockly.Block
|
|
161
161
|
*/
|
|
162
162
|
decompose: function (workspace) {
|
|
163
|
-
|
|
163
|
+
const containerBlock = workspace.newBlock('sendto_custom_container');
|
|
164
164
|
containerBlock.initSvg();
|
|
165
|
-
|
|
166
|
-
for (
|
|
167
|
-
|
|
165
|
+
let connection = containerBlock.getInput('STACK').connection;
|
|
166
|
+
for (let i = 0; i < this.itemCount_; i++) {
|
|
167
|
+
const itemBlock = workspace.newBlock('sendto_custom_item');
|
|
168
168
|
itemBlock.initSvg();
|
|
169
169
|
connection.connect(itemBlock.previousConnection);
|
|
170
170
|
connection = itemBlock.nextConnection;
|
|
@@ -177,37 +177,39 @@ Blockly.Blocks['sendto_custom'] = {
|
|
|
177
177
|
* @this Blockly.Block
|
|
178
178
|
*/
|
|
179
179
|
compose: function (containerBlock) {
|
|
180
|
-
|
|
180
|
+
let itemBlock = containerBlock.getInputTargetBlock('STACK');
|
|
181
181
|
// Count number of inputs.
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
const connections = [];
|
|
183
|
+
const names = [];
|
|
184
184
|
while (itemBlock) {
|
|
185
185
|
connections.push(itemBlock.valueConnection_);
|
|
186
186
|
itemBlock = itemBlock.nextConnection &&
|
|
187
187
|
itemBlock.nextConnection.targetBlock();
|
|
188
188
|
}
|
|
189
189
|
// Disconnect any children that don't belong.
|
|
190
|
-
for (
|
|
191
|
-
|
|
192
|
-
|
|
190
|
+
for (let i = 0; i < this.itemCount_; i++) {
|
|
191
|
+
const input = this.getInput('ARG' + i);
|
|
192
|
+
const connection = input.connection.targetConnection;
|
|
193
193
|
names[i] = input.fieldRow[0].getValue();
|
|
194
|
-
if (connection && connections.
|
|
194
|
+
if (connection && !connections.includes(connection)) {
|
|
195
195
|
connection.disconnect();
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
this.itemCount_ = connections.length;
|
|
199
|
-
if (this.itemCount_ < 1)
|
|
199
|
+
if (this.itemCount_ < 1) {
|
|
200
|
+
this.itemCount_ = 1;
|
|
201
|
+
}
|
|
200
202
|
this.updateShape_(names);
|
|
201
203
|
// Reconnect any child blocks.
|
|
202
|
-
for (
|
|
204
|
+
for (let j = 0; j < this.itemCount_; j++) {
|
|
203
205
|
Blockly.Mutator.reconnect(connections[j], this, 'ARG' + j);
|
|
204
206
|
|
|
205
207
|
}
|
|
206
208
|
},
|
|
207
209
|
getArgNames_: function () {
|
|
208
|
-
|
|
209
|
-
for (
|
|
210
|
-
|
|
210
|
+
const names = [];
|
|
211
|
+
for (let n = 0; n < this.itemCount_; n++) {
|
|
212
|
+
const input = this.getInput('ARG' + n);
|
|
211
213
|
names.push(input.fieldRow[0].getValue());
|
|
212
214
|
}
|
|
213
215
|
return names;
|
|
@@ -218,10 +220,10 @@ Blockly.Blocks['sendto_custom'] = {
|
|
|
218
220
|
* @this Blockly.Block
|
|
219
221
|
*/
|
|
220
222
|
saveConnections: function (containerBlock) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
+
let itemBlock = containerBlock.getInputTargetBlock('STACK');
|
|
224
|
+
let i = 0;
|
|
223
225
|
while (itemBlock) {
|
|
224
|
-
|
|
226
|
+
const input = this.getInput('ARG' + i);
|
|
225
227
|
itemBlock.valueConnection_ = input && input.connection.targetConnection;
|
|
226
228
|
itemBlock = itemBlock.nextConnection && itemBlock.nextConnection.targetBlock();
|
|
227
229
|
i++;
|
|
@@ -234,8 +236,8 @@ Blockly.Blocks['sendto_custom'] = {
|
|
|
234
236
|
*/
|
|
235
237
|
updateShape_: function (names, withStatement) {
|
|
236
238
|
names = names || [];
|
|
237
|
-
|
|
238
|
-
|
|
239
|
+
let _input;
|
|
240
|
+
const wp = this.workspace;
|
|
239
241
|
if (withStatement === undefined) {
|
|
240
242
|
withStatement = this.getFieldValue('WITH_STATEMENT');
|
|
241
243
|
withStatement = withStatement === true || withStatement === 'true' || withStatement === 'TRUE';
|
|
@@ -244,7 +246,7 @@ Blockly.Blocks['sendto_custom'] = {
|
|
|
244
246
|
this.getInput('STATEMENT') && this.removeInput('STATEMENT');
|
|
245
247
|
|
|
246
248
|
// Add new inputs.
|
|
247
|
-
|
|
249
|
+
let i;
|
|
248
250
|
for (i = 0; i < this.itemCount_; i++) {
|
|
249
251
|
_input = this.getInput('ARG' + i);
|
|
250
252
|
|
|
@@ -256,7 +258,7 @@ Blockly.Blocks['sendto_custom'] = {
|
|
|
256
258
|
_input.appendField(new Blockly.FieldTextInput(names[i]));
|
|
257
259
|
setTimeout(function (_input) {
|
|
258
260
|
if (!_input.connection.isConnected()) {
|
|
259
|
-
|
|
261
|
+
const _shadow = wp.newBlock('text');
|
|
260
262
|
_shadow.setShadow(true);
|
|
261
263
|
_shadow.initSvg();
|
|
262
264
|
_shadow.render();
|
|
@@ -270,7 +272,7 @@ Blockly.Blocks['sendto_custom'] = {
|
|
|
270
272
|
setTimeout(function (_input, name) {
|
|
271
273
|
if (!_input.connection.isConnected()) {
|
|
272
274
|
console.log('Create ' + name);
|
|
273
|
-
|
|
275
|
+
const shadow = wp.newBlock('text');
|
|
274
276
|
shadow.setShadow(true);
|
|
275
277
|
shadow.initSvg();
|
|
276
278
|
shadow.render();
|
|
@@ -281,9 +283,9 @@ Blockly.Blocks['sendto_custom'] = {
|
|
|
281
283
|
}
|
|
282
284
|
|
|
283
285
|
// Remove deleted inputs.
|
|
284
|
-
|
|
286
|
+
const blocks = [];
|
|
285
287
|
while (_input = this.getInput('ARG' + i)) {
|
|
286
|
-
|
|
288
|
+
const b = _input.connection.targetBlock();
|
|
287
289
|
if (b && b.isShadow()) {
|
|
288
290
|
blocks.push(b);
|
|
289
291
|
}
|
|
@@ -292,9 +294,9 @@ Blockly.Blocks['sendto_custom'] = {
|
|
|
292
294
|
}
|
|
293
295
|
|
|
294
296
|
if (blocks.length) {
|
|
295
|
-
|
|
297
|
+
const ws = this.workspace;
|
|
296
298
|
setTimeout(function () {
|
|
297
|
-
for(
|
|
299
|
+
for(let b = 0; b < blocks.length; b++) {
|
|
298
300
|
ws.removeTopBlock(blocks[b]);
|
|
299
301
|
}
|
|
300
302
|
}, 100);
|
|
@@ -308,25 +310,25 @@ Blockly.Blocks['sendto_custom'] = {
|
|
|
308
310
|
};
|
|
309
311
|
|
|
310
312
|
Blockly.JavaScript['sendto_custom'] = function (block) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
313
|
+
const instance = block.getFieldValue('INSTANCE');
|
|
314
|
+
const logLevel = block.getFieldValue('LOG');
|
|
315
|
+
const command = block.getFieldValue('COMMAND');
|
|
316
|
+
const withStatement = block.getFieldValue('WITH_STATEMENT');
|
|
317
|
+
const args = [];
|
|
318
|
+
let logText;
|
|
317
319
|
if (logLevel) {
|
|
318
320
|
logText = 'console.' + logLevel + '("' + instance + ': " + "' + (args.length ? args.join(',') + '\n' : '') + '");\n'
|
|
319
321
|
} else {
|
|
320
322
|
logText = '';
|
|
321
323
|
}
|
|
322
|
-
|
|
324
|
+
let statement;
|
|
323
325
|
if (withStatement === true || withStatement === 'true' || withStatement === 'TRUE') {
|
|
324
326
|
statement = Blockly.JavaScript.statementToCode(block, 'STATEMENT');
|
|
325
327
|
}
|
|
326
328
|
|
|
327
|
-
for (
|
|
328
|
-
|
|
329
|
-
|
|
329
|
+
for (let n = 0; n < block.itemCount_; n++) {
|
|
330
|
+
const input = this.getInput('ARG' + n);
|
|
331
|
+
let val = Blockly.JavaScript.valueToCode(block, 'ARG' + n, Blockly.JavaScript.ORDER_COMMA);
|
|
330
332
|
// if JSON
|
|
331
333
|
if (val && val[0] === "'" && val[1] === '{') {
|
|
332
334
|
val = val.substring(1, val.length - 1);
|
|
@@ -372,19 +374,19 @@ Blockly.Sendto.blocks['sendto_otherscript'] =
|
|
|
372
374
|
|
|
373
375
|
Blockly.Blocks['sendto_otherscript'] = {
|
|
374
376
|
init: function() {
|
|
375
|
-
|
|
377
|
+
const options = [[Blockly.Translate('sendto_otherscript_anyInstance'), '']];
|
|
376
378
|
if (typeof main !== 'undefined' && main.instances) {
|
|
377
|
-
for (
|
|
378
|
-
|
|
379
|
+
for (let i = 0; i < main.instances.length; i++) {
|
|
380
|
+
const m = main.instances[i].match(/^system.adapter.javascript.(\d+)$/);
|
|
379
381
|
if (m) {
|
|
380
|
-
|
|
382
|
+
const n = parseInt(m[1], 10);
|
|
381
383
|
options.push(['javascript.' + n, '.' + n]);
|
|
382
384
|
}
|
|
383
385
|
}
|
|
384
386
|
}
|
|
385
387
|
|
|
386
388
|
if (!options.length) {
|
|
387
|
-
for (
|
|
389
|
+
for (let u = 0; u <= 4; u++) {
|
|
388
390
|
options.push(['javascript.' + u, '.' + u]);
|
|
389
391
|
}
|
|
390
392
|
}
|
|
@@ -418,18 +420,18 @@ Blockly.Blocks['sendto_otherscript'] = {
|
|
|
418
420
|
};
|
|
419
421
|
|
|
420
422
|
Blockly.JavaScript['sendto_otherscript'] = function(block) {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
423
|
+
const dropdown_instance = block.getFieldValue('INSTANCE');
|
|
424
|
+
const value_objectid = Blockly.JavaScript.valueToCode(block, 'OID', Blockly.JavaScript.ORDER_ATOMIC);
|
|
425
|
+
const message = block.getFieldValue('MESSAGE');
|
|
426
|
+
let data = Blockly.JavaScript.valueToCode(block, 'DATA', Blockly.JavaScript.ORDER_ATOMIC);
|
|
425
427
|
|
|
426
|
-
|
|
428
|
+
const objectname = main.objects[value_objectid] && main.objects[value_objectid].common && main.objects[value_objectid].common.name ? main.objects[value_objectid].common.name : '';
|
|
427
429
|
|
|
428
430
|
if (!data) {
|
|
429
431
|
data = 'true';
|
|
430
432
|
}
|
|
431
433
|
|
|
432
|
-
|
|
434
|
+
let text = '{\n';
|
|
433
435
|
text += ' script: ' + value_objectid + ',' + (objectname ? '/*' + objectname + '*/' : '') + '\n';
|
|
434
436
|
text += ' message: "' + message + '",\n';
|
|
435
437
|
text += ' data: ' + data + '\n';
|