Skip to content

Commit 4cf5e71

Browse files
Fixing some blocks in blockly: cron, time (#1927)
* Fixing some blocks in blockly: cron, time * Fixed typo
1 parent 38bf597 commit 4cf5e71

File tree

10 files changed

+279
-76
lines changed

10 files changed

+279
-76
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Executes Javascript, Typescript Scripts.
2828
-->
2929
### **WORK IN PROGRESS**
3030
* (@klein0r) Added Blockly block to format a numeric value
31+
* (@GermanBluefox) Fixing some blocks in blockly: cron, time
3132

3233
### 9.0.7 (2025-06-29)
3334
* (@GermanBluefox) Fixing some blocks in blockly: time, function

src-editor/public/google-blockly/own/blocks_action.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ Blockly.Blocks['exec'] = {
7575
},
7676
updateShape_: function (withStatement) {
7777
// Add or remove a statement Input.
78-
const inputExists = this.getInput('STATEMENT');
78+
let inputExists;
79+
try {
80+
inputExists = this.getInput('STATEMENT');
81+
} catch (e) {
82+
// Input does not exist
83+
}
7984

8085
if (withStatement) {
8186
if (!inputExists) {
@@ -721,7 +726,12 @@ Blockly.Blocks['request'] = {
721726
},
722727
updateShape_: function (withStatement) {
723728
// Add or remove a statement Input.
724-
const inputExists = this.getInput('STATEMENT');
729+
let inputExists;
730+
try {
731+
inputExists = this.getInput('STATEMENT');
732+
} catch (e) {
733+
// Input does not exist
734+
}
725735

726736
if (withStatement) {
727737
if (!inputExists) {

src-editor/public/google-blockly/own/blocks_convert.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,12 @@ Blockly.Blocks.convert_from_date = {
217217
},
218218
updateShape_: function (isFormat, isLanguage) {
219219
// Add or remove a delay Input.
220-
let inputExists = this.getInput('FORMAT');
220+
let inputExists;
221+
try {
222+
inputExists = this.getInput('FORMAT');
223+
} catch (e) {
224+
inputExists = null;
225+
}
221226

222227
if (isFormat) {
223228
if (!inputExists) {
@@ -229,7 +234,11 @@ Blockly.Blocks.convert_from_date = {
229234
this.removeInput('FORMAT');
230235
}
231236

232-
inputExists = this.getInput('LANGUAGE');
237+
try {
238+
inputExists = this.getInput('LANGUAGE');
239+
} catch (e) {
240+
inputExists = null;
241+
}
233242

234243
if (isLanguage) {
235244
if (!inputExists) {
@@ -349,7 +358,12 @@ Blockly.Blocks.convert_time_difference = {
349358
this.updateShape_(format === true || format === 'true' || format === 'TRUE');
350359
},
351360
updateShape_: function (isFormat, isLanguage) {
352-
let inputExists = this.getInput('FORMAT');
361+
let inputExists;
362+
try {
363+
inputExists = this.getInput('FORMAT');
364+
} catch (e) {
365+
inputExists = null;
366+
}
353367

354368
if (isFormat) {
355369
if (!inputExists) {

src-editor/public/google-blockly/own/blocks_logic.js

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Blockly.Blocks['logic_multi_and'] = {
115115

116116
// Disconnect any children that don't belong.
117117
for (let k = 0; k < this.itemCount_; k++) {
118-
const connection = this.getInput('AND' + k).connection.targetConnection;
118+
const connection = this.getInput(`AND${k}`).connection.targetConnection;
119119
if (connection && !connections.includes(connection)) {
120120
connection.disconnect();
121121
}
@@ -142,11 +142,16 @@ Blockly.Blocks['logic_multi_and'] = {
142142
let i = 0;
143143

144144
while (itemBlock) {
145-
const input = this.getInput('AND' + i);
146-
itemBlock.valueConnection_ = input && input.connection.targetConnection;
145+
let input;
146+
try {
147+
input = this.getInput('AND' + i);
148+
} catch (e) {
149+
// If the input does not exist, it means that the block has been removed.
150+
input = null;
151+
}
152+
itemBlock.valueConnection_ = input?.connection.targetConnection;
147153
i++;
148-
itemBlock = itemBlock.nextConnection &&
149-
itemBlock.nextConnection.targetBlock();
154+
itemBlock = itemBlock.nextConnection?.targetBlock();
150155
}
151156
},
152157
/**
@@ -157,16 +162,28 @@ Blockly.Blocks['logic_multi_and'] = {
157162
updateShape_: function () {
158163
// Add new inputs.
159164
for (let i = 0; i < this.itemCount_; i++) {
160-
if (!this.getInput('AND' + i)) {
165+
let input;
166+
try {
167+
input = this.getInput('AND' + i);
168+
} catch (e) {
169+
// If the input does not exist, it means that the block has been removed.
170+
input = null;
171+
}
172+
if (!input) {
161173
const input = this.appendValueInput('AND' + i).setAlign(Blockly.ALIGN_RIGHT);
162174
if (i > 0) {
163175
input.appendField(Blockly.Translate('logic_multi_and_and'));
164176
}
165177
}
166178
}
167179
// Remove deleted inputs.
168-
for (let i = this.itemCount_; this.getInput('AND' + i); i++) {
169-
this.removeInput('AND' + i);
180+
try {
181+
for (let i = this.itemCount_; this.getInput('AND' + i); i++) {
182+
this.removeInput('AND' + i);
183+
}
184+
} catch (e) {
185+
// If the input does not exist, it means that the block has been removed.
186+
// Do nothing.
170187
}
171188
},
172189
};
@@ -321,11 +338,16 @@ Blockly.Blocks['logic_multi_or'] = {
321338
let i = 0;
322339

323340
while (itemBlock) {
324-
const input = this.getInput('OR' + i);
325-
itemBlock.valueConnection_ = input && input.connection.targetConnection;
341+
let input;
342+
try {
343+
input = this.getInput('OR' + i);
344+
} catch (e) {
345+
// If the input does not exist, it means that the block has been removed.
346+
input = null;
347+
}
348+
itemBlock.valueConnection_ = input?.connection.targetConnection;
326349
i++;
327-
itemBlock = itemBlock.nextConnection &&
328-
itemBlock.nextConnection.targetBlock();
350+
itemBlock = itemBlock.nextConnection?.targetBlock();
329351
}
330352
},
331353
/**
@@ -336,16 +358,27 @@ Blockly.Blocks['logic_multi_or'] = {
336358
updateShape_: function () {
337359
// Add new inputs.
338360
for (let i = 0; i < this.itemCount_; i++) {
339-
if (!this.getInput('OR' + i)) {
361+
let input;
362+
try {
363+
input = this.getInput('OR' + i);
364+
} catch (e) {
365+
input = null;
366+
}
367+
if (!input) {
340368
const input = this.appendValueInput('OR' + i).setAlign(Blockly.ALIGN_RIGHT);
341369
if (i > 0) {
342370
input.appendField(Blockly.Translate('logic_multi_or_or'));
343371
}
344372
}
345373
}
346374
// Remove deleted inputs.
347-
for (let i = this.itemCount_; this.getInput('OR' + i); i++) {
348-
this.removeInput('OR' + i);
375+
try {
376+
for (let i = this.itemCount_; this.getInput('OR' + i); i++) {
377+
this.removeInput('OR' + i);
378+
}
379+
} catch (e) {
380+
// If the input does not exist, it means that the block has been removed.
381+
// Do nothing.
349382
}
350383
},
351384
};

src-editor/public/google-blockly/own/blocks_object.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,15 @@ Blockly.Blocks['object_new'] = {
178178
let i = 0;
179179

180180
while (itemBlock) {
181-
const input = this.getInput('ATTR_' + i);
182-
itemBlock.valueConnection_ = input && input.connection.targetConnection;
181+
let input;
182+
try {
183+
input = this.getInput('ATTR_' + i);
184+
} catch (e) {
185+
input = null;
186+
}
187+
itemBlock.valueConnection_ = input?.connection.targetConnection;
183188
i++;
184-
itemBlock = itemBlock.nextConnection &&
185-
itemBlock.nextConnection.targetBlock();
189+
itemBlock = itemBlock.nextConnection?.targetBlock();
186190
}
187191
},
188192
/**
@@ -195,7 +199,12 @@ Blockly.Blocks['object_new'] = {
195199

196200
// Add new inputs.
197201
for (let i = 0; i < this.itemCount_; i++) {
198-
let input = this.getInput('ATTR_' + i);
202+
let input;
203+
try {
204+
input = this.getInput(`ATTR_${i}`);
205+
} catch (e) {
206+
input = null;
207+
}
199208

200209
if (!input) {
201210
input = this.appendValueInput('ATTR_' + i).setAlign(Blockly.ALIGN_RIGHT);
@@ -215,8 +224,12 @@ Blockly.Blocks['object_new'] = {
215224
}, 100, input);
216225
}
217226
// Remove deleted inputs.
218-
for (let i = this.itemCount_; this.getInput('ATTR_' + i); i++) {
219-
this.removeInput('ATTR_' + i);
227+
try {
228+
for (let i = this.itemCount_; this.getInput('ATTR_' + i); i++) {
229+
this.removeInput('ATTR_' + i);
230+
}
231+
} catch (e) {
232+
// Ignore error if input does not exist
220233
}
221234
},
222235
};

src-editor/public/google-blockly/own/blocks_sendto.js

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,14 @@ Blockly.Blocks['sendto_custom'] = {
228228
let itemBlock = containerBlock.getInputTargetBlock('STACK');
229229
let i = 0;
230230
while (itemBlock) {
231-
const input = this.getInput('ARG' + i);
232-
itemBlock.valueConnection_ = input && input.connection.targetConnection;
233-
itemBlock = itemBlock.nextConnection && itemBlock.nextConnection.targetBlock();
231+
let input;
232+
try {
233+
input = this.getInput('ARG' + i);
234+
} catch (e) {
235+
// if the input does not exist, it means that the block was deleted
236+
}
237+
itemBlock.valueConnection_ = input?.connection.targetConnection;
238+
itemBlock = itemBlock.nextConnection?.targetBlock();
234239
i++;
235240
}
236241
},
@@ -244,7 +249,12 @@ Blockly.Blocks['sendto_custom'] = {
244249

245250
// Add new inputs.
246251
for (let i = 0; i < this.itemCount_; i++) {
247-
let input = this.getInput('ARG' + i);
252+
let input;
253+
try {
254+
input = this.getInput('ARG' + i);
255+
} catch (e) {
256+
input = null;
257+
}
248258

249259
if (!input) {
250260
input = this.appendValueInput('ARG' + i).setAlign(Blockly.ALIGN_RIGHT);
@@ -264,16 +274,27 @@ Blockly.Blocks['sendto_custom'] = {
264274
}, 100, input);
265275
}
266276
// Remove deleted inputs.
267-
for (let i = this.itemCount_; this.getInput('ARG' + i); i++) {
268-
this.removeInput('ARG' + i);
277+
try {
278+
for (let i = this.itemCount_; this.getInput('ARG' + i); i++) {
279+
this.removeInput('ARG' + i);
280+
}
281+
} catch (e) {
282+
// if the input does not exist, it means that the block was deleted
269283
}
270284

285+
271286
if (withStatement === undefined) {
272287
withStatement = this.getFieldValue('WITH_STATEMENT');
273288
withStatement = withStatement === true || withStatement === 'true' || withStatement === 'TRUE';
274289
}
275290

276-
this.getInput('STATEMENT') && this.removeInput('STATEMENT');
291+
try {
292+
if (this.getInput('STATEMENT')) {
293+
this.removeInput('STATEMENT');
294+
}
295+
} catch (e) {
296+
// if the input does not exist, it means that the block was deleted
297+
}
277298

278299
// Add or remove a statement Input.
279300
if (withStatement) {
@@ -429,7 +450,12 @@ Blockly.Blocks['sendto_otherscript'] = {
429450

430451
// Add new inputs.
431452
for (let i = 0; i < this.itemCount_; i++) {
432-
let input = this.getInput('ARG' + i);
453+
let input;
454+
try {
455+
input = this.getInput('ARG' + i);
456+
} catch (e) {
457+
input = null;
458+
}
433459

434460
if (!input) {
435461
input = this.appendValueInput('ARG' + i).setAlign(Blockly.ALIGN_RIGHT);
@@ -449,16 +475,27 @@ Blockly.Blocks['sendto_otherscript'] = {
449475
}, 100, input);
450476
}
451477
// Remove deleted inputs.
452-
for (let i = this.itemCount_; this.getInput('ARG' + i); i++) {
453-
this.removeInput('ARG' + i);
478+
try {
479+
for (let i = this.itemCount_; this.getInput('ARG' + i); i++) {
480+
this.removeInput('ARG' + i);
481+
}
482+
} catch (e) {
483+
// if the input does not exist, it means that the block was deleted
454484
}
455485

486+
456487
if (withStatement === undefined) {
457488
withStatement = this.getFieldValue('WITH_STATEMENT');
458489
withStatement = withStatement === true || withStatement === 'true' || withStatement === 'TRUE';
459490
}
460491

461-
this.getInput('STATEMENT') && this.removeInput('STATEMENT');
492+
try {
493+
if (this.getInput('STATEMENT')) {
494+
this.removeInput('STATEMENT');
495+
}
496+
} catch (e) {
497+
// if the input does not exist, it means that the block was deleted
498+
}
462499

463500
// Add or remove a statement Input.
464501
if (withStatement) {

src-editor/public/google-blockly/own/blocks_switch.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,21 +142,31 @@ Blockly.Blocks['logic_switch_case'] = {
142142
while (caseBlock) {
143143
switch (caseBlock.type) {
144144
case'case_incaseof':
145-
const caseconditionInput = this.getInput('CASECONDITION' + x);
146-
const caseInput = this.getInput('CASE' + x);
147-
caseBlock.valueConnection_ = caseconditionInput && caseconditionInput.connection.targetConnection;
148-
caseBlock.statementConnection_ = caseInput && caseInput.connection.targetConnection;
145+
let caseconditionInput;
146+
let caseInput;
147+
try {
148+
caseconditionInput = this.getInput('CASECONDITION' + x);
149+
caseInput = this.getInput('CASE' + x);
150+
} catch (e) {
151+
// ignore
152+
}
153+
caseBlock.valueConnection_ = caseconditionInput?.connection.targetConnection;
154+
caseBlock.statementConnection_ = caseInput?.connection.targetConnection;
149155
x++;
150156
break;
151157
case'case_default':
152-
const defaultInput = this.getInput('ONDEFAULT');
153-
caseBlock.satementConnection_ = defaultInput && defaultInput.connection.targetConnection;
158+
let defaultInput;
159+
try {
160+
defaultInput = this.getInput('ONDEFAULT');
161+
} catch (e) {
162+
// ignore
163+
}
164+
caseBlock.statementConnection_ = defaultInput?.connection.targetConnection;
154165
break;
155166
default:
156167
throw 'Unknown block type';
157168
}
158-
caseBlock = caseBlock.nextConnection &&
159-
caseBlock.nextConnection.targetBlock();
169+
caseBlock = caseBlock.nextConnection?.targetBlock();
160170
}
161171
},
162172
};

0 commit comments

Comments
 (0)