iobroker.javascript 10.0.0 → 10.1.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/README.md +48 -12
- package/admin/assets/AiChatPanel-C_WbKMGX.js +242 -0
- package/admin/assets/AiDiffView-BtXbDWZ8.js +1 -0
- package/admin/assets/Debugger-DAdJnEhw.js +15 -0
- package/admin/assets/Error-DQ1pzKcf.js +1 -0
- package/admin/assets/Import-BjMtH6Gk.js +1 -0
- package/admin/assets/RulesEditor-dDRPHw4X.js +1 -0
- package/admin/assets/RulesEditor-k-DMHotH.css +1 -0
- package/admin/assets/{ScriptEditor-BGIuoNei.js → ScriptEditor-CZSc7rwE.js} +2 -2
- package/admin/assets/ScriptEditorVanillaMonaco-DEKg14_A.js +3 -0
- package/admin/assets/_virtual_mf-localSharedImportMap___mfe_internal__iobroker_javascript__mf_owner__1-DPmwd_G2.js +1 -0
- package/admin/assets/_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__1__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-C8inUeKt.js +1243 -0
- package/admin/assets/_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__1__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-VcQjt7_9.js +9 -0
- package/admin/assets/aiPromptBuilder-D5FDo74i.js +1 -0
- package/admin/assets/blockly-DBw-ytY1.js +1047 -0
- package/admin/assets/blocks_action-BqfWEwpf.js +1 -0
- package/admin/assets/blocks_convert-CX0i-JfS.js +3 -0
- package/admin/assets/blocks_logic-D-QSzw95.js +1 -0
- package/admin/assets/blocks_number-D7JuNYsw.js +1 -0
- package/admin/assets/blocks_object-C9DzAlc7.js +1 -0
- package/admin/assets/blocks_procedures-BJMz6HWW.js +3 -0
- package/admin/assets/blocks_sendto-DRh7lk9o.js +5 -0
- package/admin/assets/blocks_switch-BfmboMex.js +2 -0
- package/admin/assets/blocks_system-B-78JfAc.js +1 -0
- package/admin/assets/blocks_text-CGbR0Ozw.js +1 -0
- package/admin/assets/blocks_time-5vS2geJg.js +1 -0
- package/admin/assets/blocks_timeout-BdaTywfN.js +1 -0
- package/admin/assets/blocks_trigger-D8kgHKbg.js +2 -0
- package/admin/assets/blocks_words-BhHIf_1o.js +1 -0
- package/admin/assets/{cronHoverProvider-pKJkSevo.js → cronHoverProvider-DpgESCox.js} +1 -1
- package/admin/assets/dist-CaOsN0XW.js +4 -0
- package/admin/assets/field_cron-B40zwSfJ.js +1 -0
- package/admin/assets/field_oid-KfoBnEM9.js +1 -0
- package/admin/assets/field_script-yXhe1iCp.js +1 -0
- package/admin/assets/helpers-B0ByElPJ.js +1 -0
- package/admin/assets/hostInit-9REPDUe7.js +1 -0
- package/admin/assets/index-07o_WKsX.js +726 -0
- package/admin/assets/index-Z8Hkv58g.css +1 -0
- package/admin/assets/{inlineChatWidget-ZaisTOLh.js → inlineChatWidget-B9y_gQcH.js} +2 -2
- package/admin/assets/{inlineDiffController-hTwHHqcc.js → inlineDiffController-C07CdIFo.js} +2 -2
- package/admin/assets/{mf-entry-bootstrap-0-d6052b31.js → mf-entry-bootstrap-0-efcb49d3.js} +7 -2
- package/admin/assets/stateHoverProvider-CqeoOjXs.js +9 -0
- package/admin/assets/{virtualExposes-Ed0lGq7k.js → virtualExposes-DgGB-18P.js} +1 -1
- package/admin/assets/virtual_mf-REMOTE_ENTRY_ID___mfe_internal__iobroker_javascript__remoteEntry_js-BwSvIKEV.js +1 -0
- package/admin/assets/virtual_mf-exposes___mfe_internal__iobroker_javascript__remoteEntry_js-ChiJXsfH.js +1 -0
- package/admin/custom/assets/Components-BCQTjBgm.js +1 -0
- package/admin/custom/assets/_virtual_mf-localSharedImportMap___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1-BuAc8OyX.js +1 -0
- package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare___mf_0_emotion_mf_1_react__loadShare__.js-BGJv4zZP.js +1 -0
- package/admin/custom/assets/{_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare___mf_0_emotion_mf_1_styled__loadShare__.js-CGb5Cofy.js → _virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare___mf_0_emotion_mf_1_styled__loadShare__.js-B4E6MFJ4.js} +1 -1
- package/admin/custom/assets/{_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-BVCIAgbo.js → _virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-aRlxyEhq.js} +78 -78
- package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare___mf_0_iobroker_mf_1_json_mf_2_config__loadShare__.js-DQwzYx75.js +1494 -0
- package/admin/custom/assets/{_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare__leaflet__loadShare__.js-h-rCw3iz.js → _virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare__leaflet__loadShare__.js-n2zIPi0L.js} +1 -1
- package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-xxszBNje.js +9 -0
- package/admin/custom/assets/{_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__prebuild__date_mf_2_fns__prebuild__-Cb5TR7FB.js → _virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__prebuild__date_mf_2_fns__prebuild__-Tq7tesSS.js} +1 -1
- package/admin/custom/assets/{_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__prebuild__leaflet__prebuild__-DARUoA03.js → _virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__prebuild__leaflet__prebuild__-BeF0jEWM.js} +1 -1
- package/admin/custom/assets/hostInit-CHwrowP4.js +1 -0
- package/admin/custom/assets/{index-uEKAoVT7.js → index-Cm6xl9K4.js} +1 -1
- package/admin/custom/assets/{lib-Yj8cfN0A.js → lib-bhrFL6jR.js} +1 -1
- package/admin/custom/assets/{mf-entry-bootstrap-0-77793feb.js → mf-entry-bootstrap-0-f08941e2.js} +7 -2
- package/admin/custom/assets/{setYear-DJ9FbdkO.js → setYear-DzTZ2h9A.js} +1 -1
- package/admin/custom/assets/virtualExposes-B5LJmnfO.js +1 -0
- package/admin/custom/assets/virtual_mf-REMOTE_ENTRY_ID___mfe_internal__ConfigCustomJavascriptSet__customComponents_js-ML-chjs6.js +1 -0
- package/admin/custom/assets/virtual_mf-exposes___mfe_internal__ConfigCustomJavascriptSet__customComponents_js-C3ImybiM.js +2 -0
- package/admin/custom/customComponents.js +12 -1
- package/admin/custom/i18n/de.json +11 -1
- package/admin/custom/i18n/en.json +11 -1
- package/admin/custom/i18n/es.json +11 -1
- package/admin/custom/i18n/fr.json +11 -1
- package/admin/custom/i18n/it.json +11 -1
- package/admin/custom/i18n/nl.json +11 -1
- package/admin/custom/i18n/pl.json +11 -1
- package/admin/custom/i18n/pt.json +11 -1
- package/admin/custom/i18n/ru.json +11 -1
- package/admin/custom/i18n/uk.json +11 -1
- package/admin/custom/i18n/zh-cn.json +11 -1
- package/admin/google-blockly/VERSION +1 -0
- package/admin/google-blockly/media/drop.mp3 +0 -0
- package/admin/google-blockly/msg/js/de.js +332 -56
- package/admin/google-blockly/msg/js/en.js +319 -43
- package/admin/google-blockly/msg/js/es.js +319 -42
- package/admin/google-blockly/msg/js/fr.js +315 -39
- package/admin/google-blockly/msg/js/it.js +327 -51
- package/admin/google-blockly/msg/js/nl.js +376 -100
- package/admin/google-blockly/msg/js/pl.js +318 -42
- package/admin/google-blockly/msg/js/pt.js +318 -42
- package/admin/google-blockly/msg/js/ru.js +320 -44
- package/admin/google-blockly/msg/js/uk.js +326 -50
- package/admin/google-blockly/msg/js/zh-cn.js +322 -46
- package/admin/i18n/de.json +51 -26
- package/admin/i18n/en.json +50 -25
- package/admin/i18n/es.json +51 -18
- package/admin/i18n/fr.json +50 -17
- package/admin/i18n/it.json +50 -17
- package/admin/i18n/nl.json +50 -17
- package/admin/i18n/pl.json +51 -18
- package/admin/i18n/pt.json +50 -17
- package/admin/i18n/ru.json +50 -17
- package/admin/i18n/uk.json +50 -17
- package/admin/i18n/zh-cn.json +50 -17
- package/admin/jsonConfig.json +398 -0
- package/admin/mf-manifest.json +1 -1
- package/admin/mf-stats.json +1 -1
- package/admin/remoteEntry.js +12 -1
- package/admin/tab.html +6 -98
- package/build/lib/javascript.d.ts +48 -0
- package/build/lib/mirror.js +9 -0
- package/build/lib/mirror.js.map +1 -1
- package/build/lib/sandbox.js +37 -0
- package/build/lib/sandbox.js.map +1 -1
- package/build/lib/secrets.js +220 -0
- package/build/lib/secrets.js.map +1 -0
- package/build/lib/typescriptSettings.js +112 -2
- package/build/lib/typescriptSettings.js.map +1 -1
- package/build/lib/typescriptTools.js +168 -43
- package/build/lib/typescriptTools.js.map +1 -1
- package/build/main.js +61 -5
- package/build/main.js.map +1 -1
- package/build/types.d.ts +48 -0
- package/docs/en/blockly.md +29 -0
- package/docs/en/javascript.md +72 -0
- package/docs/en/upgrade-guide.md +3 -0
- package/io-package.json +59 -28
- package/package.json +8 -3
- package/admin/assets/AiChatPanel-p0KAg6Cs.js +0 -237
- package/admin/assets/AiDiffView-BPTLnNx1.js +0 -1
- package/admin/assets/AiScriptAnalyzer--BHML2rN.js +0 -9
- package/admin/assets/BlocklyEditor-CAjVMhYT.js +0 -81
- package/admin/assets/ContextWrapper-BVc8wTK_.css +0 -1
- package/admin/assets/ContextWrapper-D9CrnNKs.js +0 -127
- package/admin/assets/Debugger-SjROokFI.js +0 -15
- package/admin/assets/Error-DDfrxAt2.js +0 -1
- package/admin/assets/Import-DpTg1Jow.js +0 -1
- package/admin/assets/RulesEditor-BSRFWpEm.css +0 -1
- package/admin/assets/RulesEditor-D0hgrcBc.js +0 -1
- package/admin/assets/ScriptEditorVanillaMonaco-DyMQtoTQ.js +0 -3
- package/admin/assets/_virtual_mf-localSharedImportMap___mfe_internal__iobroker_javascript__mf_owner__1-DWJotR1B.js +0 -1
- package/admin/assets/_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__1__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-CxICLr5Z.js +0 -1243
- package/admin/assets/_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__1__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-BBAXJaqI.js +0 -9
- package/admin/assets/aiCodeLensProvider-hyAmut0e.js +0 -4
- package/admin/assets/aiPromptBuilder-Bs27qOHT.js +0 -7
- package/admin/assets/blocklyDarkTheme-DEiAX5DT.js +0 -1
- package/admin/assets/dist-uw5orDgd.js +0 -4
- package/admin/assets/hostInit-BFg5u9hY.js +0 -1
- package/admin/assets/index-B1gICjdq.js +0 -192
- package/admin/assets/index-BHhhebRG.css +0 -1
- package/admin/assets/mjs-DWqivHEk.js +0 -90
- package/admin/assets/stateHoverProvider-C7DawIs-.js +0 -9
- package/admin/assets/virtual_mf-REMOTE_ENTRY_ID___mfe_internal__iobroker_javascript__remoteEntry_js-BYs71IQF.js +0 -1
- package/admin/assets/virtual_mf-exposes___mfe_internal__iobroker_javascript__remoteEntry_js-DnnXQRkG.js +0 -1
- package/admin/custom/assets/Components-BrDyDHXh.js +0 -1
- package/admin/custom/assets/_virtual_mf-localSharedImportMap___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1-CyYJM2-v.js +0 -1
- package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare___mf_0_emotion_mf_1_react__loadShare__.js-BdzCssLn.js +0 -1
- package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare___mf_0_iobroker_mf_1_json_mf_2_config__loadShare__.js-BkB0anQX.js +0 -1494
- package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-BotqDuw-.js +0 -9
- package/admin/custom/assets/hostInit-DJx2uXXy.js +0 -1
- package/admin/custom/assets/virtualExposes-CxDjLoYu.js +0 -1
- package/admin/custom/assets/virtual_mf-REMOTE_ENTRY_ID___mfe_internal__ConfigCustomJavascriptSet__customComponents_js-BU-ugy_7.js +0 -1
- package/admin/custom/assets/virtual_mf-exposes-ssr___mfe_internal__ConfigCustomJavascriptSet__customComponents_js-BEfZbrf7.js +0 -2
- package/admin/custom/assets/virtual_mf-exposes___mfe_internal__ConfigCustomJavascriptSet__customComponents_js-CTeZ0Jpm.js +0 -2
- package/admin/google-blockly/blockly_compressed.js +0 -1679
- package/admin/google-blockly/blocks_compressed.js +0 -193
- package/admin/google-blockly/javascript_compressed.js +0 -264
- package/admin/google-blockly/msg/messages.js +0 -1630
- package/admin/google-blockly/own/blocks_action.js +0 -765
- package/admin/google-blockly/own/blocks_convert.js +0 -480
- package/admin/google-blockly/own/blocks_logic.js +0 -459
- package/admin/google-blockly/own/blocks_number.js +0 -30
- package/admin/google-blockly/own/blocks_object.js +0 -402
- package/admin/google-blockly/own/blocks_procedures.js +0 -688
- package/admin/google-blockly/own/blocks_sendto.js +0 -702
- package/admin/google-blockly/own/blocks_switch.js +0 -257
- package/admin/google-blockly/own/blocks_system.js +0 -1409
- package/admin/google-blockly/own/blocks_text.js +0 -104
- package/admin/google-blockly/own/blocks_time.js +0 -639
- package/admin/google-blockly/own/blocks_timeout.js +0 -551
- package/admin/google-blockly/own/blocks_trigger.js +0 -1791
- package/admin/google-blockly/own/blocks_words.js +0 -708
- package/admin/google-blockly/own/field_cron.js +0 -158
- package/admin/google-blockly/own/field_oid.js +0 -642
- package/admin/google-blockly/own/field_script.js +0 -159
|
@@ -1,765 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
if (typeof goog !== 'undefined') {
|
|
4
|
-
goog.provide('Blockly.JavaScript.Action');
|
|
5
|
-
goog.require('Blockly.JavaScript');
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
Blockly.CustomBlocks = Blockly.CustomBlocks || [];
|
|
9
|
-
Blockly.CustomBlocks.push('Action');
|
|
10
|
-
|
|
11
|
-
Blockly.Action = {
|
|
12
|
-
HUE: 330,
|
|
13
|
-
blocks: {},
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
// --- action exec --------------------------------------------------
|
|
17
|
-
|
|
18
|
-
Blockly.Action.blocks['exec'] =
|
|
19
|
-
'<block type="exec">' +
|
|
20
|
-
' <mutation with_statement="false"></mutation>' +
|
|
21
|
-
' <field name="WITH_STATEMENT">FALSE</field>' +
|
|
22
|
-
' <field name="LOG"></field>' +
|
|
23
|
-
' <value name="COMMAND">' +
|
|
24
|
-
' <shadow type="text">' +
|
|
25
|
-
' <field name="TEXT">pwd</field>' +
|
|
26
|
-
' </shadow>' +
|
|
27
|
-
' </value>' +
|
|
28
|
-
'</block>';
|
|
29
|
-
|
|
30
|
-
Blockly.Blocks['exec'] = {
|
|
31
|
-
init: function () {
|
|
32
|
-
this.appendDummyInput('TEXT')
|
|
33
|
-
.appendField('» ' + Blockly.Translate('exec'));
|
|
34
|
-
|
|
35
|
-
this.appendValueInput('COMMAND')
|
|
36
|
-
.appendField(Blockly.Translate('exec_command'));
|
|
37
|
-
|
|
38
|
-
this.appendDummyInput('WITH_STATEMENT')
|
|
39
|
-
.appendField(Blockly.Translate('with_results'))
|
|
40
|
-
.appendField(new Blockly.FieldCheckbox('FALSE', function (option) {
|
|
41
|
-
this.sourceBlock_.updateShape_(option === true || option === 'true' || option === 'TRUE');
|
|
42
|
-
}), 'WITH_STATEMENT');
|
|
43
|
-
|
|
44
|
-
this.appendDummyInput('LOG')
|
|
45
|
-
.appendField(Blockly.Translate('loglevel'))
|
|
46
|
-
.appendField(new Blockly.FieldDropdown([
|
|
47
|
-
[Blockly.Translate('loglevel_none'), ''],
|
|
48
|
-
[Blockly.Translate('loglevel_debug'), 'debug'],
|
|
49
|
-
[Blockly.Translate('loglevel_info'), 'info'],
|
|
50
|
-
[Blockly.Translate('loglevel_warn'), 'warn'],
|
|
51
|
-
[Blockly.Translate('loglevel_error'), 'error'],
|
|
52
|
-
]), 'LOG');
|
|
53
|
-
|
|
54
|
-
this.setInputsInline(false);
|
|
55
|
-
this.setPreviousStatement(true, null);
|
|
56
|
-
this.setNextStatement(true, null);
|
|
57
|
-
|
|
58
|
-
this.setColour(Blockly.Action.HUE);
|
|
59
|
-
|
|
60
|
-
this.setTooltip(Blockly.Translate('exec_tooltip'));
|
|
61
|
-
this.setHelpUrl(getHelp('exec_help'));
|
|
62
|
-
},
|
|
63
|
-
mutationToDom: function () {
|
|
64
|
-
const container = document.createElement('mutation');
|
|
65
|
-
const option = this.getFieldValue('WITH_STATEMENT');
|
|
66
|
-
|
|
67
|
-
container.setAttribute('with_statement', option === true || option === 'true' || option === 'TRUE');
|
|
68
|
-
|
|
69
|
-
return container;
|
|
70
|
-
},
|
|
71
|
-
domToMutation: function (xmlElement) {
|
|
72
|
-
const option = xmlElement.getAttribute('with_statement');
|
|
73
|
-
|
|
74
|
-
this.updateShape_(option === true || option === 'true' || option === 'TRUE');
|
|
75
|
-
},
|
|
76
|
-
updateShape_: function (withStatement) {
|
|
77
|
-
// Add or remove a statement Input.
|
|
78
|
-
let inputExists;
|
|
79
|
-
try {
|
|
80
|
-
inputExists = this.getInput('STATEMENT');
|
|
81
|
-
} catch (e) {
|
|
82
|
-
// Input does not exist
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (withStatement) {
|
|
86
|
-
if (!inputExists) {
|
|
87
|
-
this.appendStatementInput('STATEMENT');
|
|
88
|
-
}
|
|
89
|
-
} else if (inputExists) {
|
|
90
|
-
this.removeInput('STATEMENT');
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
Blockly.JavaScript.forBlock['exec'] = function (block) {
|
|
96
|
-
const vCommand = Blockly.JavaScript.valueToCode(block, 'COMMAND', Blockly.JavaScript.ORDER_ATOMIC);
|
|
97
|
-
const fLog = block.getFieldValue('LOG');
|
|
98
|
-
const fWithStatement = block.getFieldValue('WITH_STATEMENT');
|
|
99
|
-
|
|
100
|
-
let logText = '';
|
|
101
|
-
if (fLog) {
|
|
102
|
-
logText = `console.${fLog}('exec: ' + ${vCommand});\n`;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (fWithStatement === 'TRUE' || fWithStatement === 'true' || fWithStatement === true) {
|
|
106
|
-
const statement = Blockly.JavaScript.statementToCode(block, 'STATEMENT');
|
|
107
|
-
if (statement) {
|
|
108
|
-
return `exec(${vCommand}, async (error, result, stderr) => {\n${statement}});\n${logText}`;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return `exec(${vCommand});\n${logText}`;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return `exec(${vCommand});\n${logText}`;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
// --- exec_result -----------------------------------------------------------
|
|
118
|
-
Blockly.Action.blocks['exec_result'] =
|
|
119
|
-
'<sep gap="5"></sep>' +
|
|
120
|
-
'<block type="exec_result">' +
|
|
121
|
-
' <field name="ATTR">result</field>' +
|
|
122
|
-
'</block>';
|
|
123
|
-
|
|
124
|
-
Blockly.Blocks['exec_result'] = {
|
|
125
|
-
/**
|
|
126
|
-
* Block for conditionally returning a value from a procedure.
|
|
127
|
-
* @this Blockly.Block
|
|
128
|
-
*/
|
|
129
|
-
init: function () {
|
|
130
|
-
this.appendDummyInput()
|
|
131
|
-
.appendField('»');
|
|
132
|
-
|
|
133
|
-
this.appendDummyInput('ATTR')
|
|
134
|
-
.appendField(new Blockly.FieldDropdown([
|
|
135
|
-
[Blockly.Translate('exec_result_result'), 'result'],
|
|
136
|
-
[Blockly.Translate('exec_result_stderr'), 'stderr'],
|
|
137
|
-
[Blockly.Translate('exec_result_error'), 'error'],
|
|
138
|
-
]), 'ATTR');
|
|
139
|
-
|
|
140
|
-
this.setInputsInline(true);
|
|
141
|
-
this.setOutput(true);
|
|
142
|
-
|
|
143
|
-
this.setColour(Blockly.Action.HUE);
|
|
144
|
-
|
|
145
|
-
this.setTooltip(Blockly.Translate('exec_result_tooltip'));
|
|
146
|
-
this.setHelpUrl(getHelp('exec_help'));
|
|
147
|
-
},
|
|
148
|
-
/**
|
|
149
|
-
* Called whenever anything on the workspace changes.
|
|
150
|
-
* Add warning if this flow block is not nested inside a loop.
|
|
151
|
-
* @param {!Blockly.Events.Abstract} e Change event.
|
|
152
|
-
* @this Blockly.Block
|
|
153
|
-
*/
|
|
154
|
-
onchange: function (e) {
|
|
155
|
-
let legal = false;
|
|
156
|
-
// Is the block nested in an exec?
|
|
157
|
-
let block = this;
|
|
158
|
-
do {
|
|
159
|
-
if (this.FUNCTION_TYPES.includes(block.type)) {
|
|
160
|
-
legal = true;
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
block = block.getSurroundParent();
|
|
164
|
-
} while (block);
|
|
165
|
-
|
|
166
|
-
if (legal) {
|
|
167
|
-
this.setWarningText(null, this.id);
|
|
168
|
-
} else {
|
|
169
|
-
this.setWarningText(Blockly.Translate('exec_result_warning'), this.id);
|
|
170
|
-
}
|
|
171
|
-
},
|
|
172
|
-
/**
|
|
173
|
-
* List of block types that are functions and thus do not need warnings.
|
|
174
|
-
* To add a new function type add this to your code:
|
|
175
|
-
* Blockly.Blocks['procedures_ifreturn'].FUNCTION_TYPES.push('custom_func');
|
|
176
|
-
*/
|
|
177
|
-
FUNCTION_TYPES: ['exec'],
|
|
178
|
-
};
|
|
179
|
-
Blockly.JavaScript.forBlock['exec_result'] = function (block) {
|
|
180
|
-
const attr = block.getFieldValue('ATTR');
|
|
181
|
-
|
|
182
|
-
return [attr, Blockly.JavaScript.ORDER_ATOMIC];
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
// --- action http_get --------------------------------------------------
|
|
186
|
-
Blockly.Action.blocks['http_get'] =
|
|
187
|
-
'<block type="http_get">' +
|
|
188
|
-
' <field name="TIMEOUT">2000</field>' +
|
|
189
|
-
' <field name="UNIT">ms</field>' +
|
|
190
|
-
' <field name="TYPE">text</field>' +
|
|
191
|
-
' <value name="URL">' +
|
|
192
|
-
' <shadow type="text">' +
|
|
193
|
-
' <field name="TEXT">http://</field>' +
|
|
194
|
-
' </shadow>' +
|
|
195
|
-
' </value>' +
|
|
196
|
-
'</block>';
|
|
197
|
-
|
|
198
|
-
Blockly.Blocks['http_get'] = {
|
|
199
|
-
init: function () {
|
|
200
|
-
this.appendValueInput('URL')
|
|
201
|
-
.appendField('🌐 ' + Blockly.Translate('http_get'));
|
|
202
|
-
|
|
203
|
-
this.appendDummyInput()
|
|
204
|
-
.appendField(Blockly.Translate('http_timeout'))
|
|
205
|
-
.appendField(new Blockly.FieldTextInput(2000), 'TIMEOUT')
|
|
206
|
-
.appendField(new Blockly.FieldDropdown([
|
|
207
|
-
[Blockly.Translate('http_timeout_ms'), 'ms'],
|
|
208
|
-
[Blockly.Translate('http_timeout_sec'), 'sec'],
|
|
209
|
-
]), 'UNIT');
|
|
210
|
-
|
|
211
|
-
this.appendDummyInput('TYPE')
|
|
212
|
-
.appendField(Blockly.Translate('http_type'))
|
|
213
|
-
.appendField(new Blockly.FieldDropdown([
|
|
214
|
-
[Blockly.Translate('http_type_text'), 'text'],
|
|
215
|
-
[Blockly.Translate('http_type_arraybuffer'), 'arraybuffer'],
|
|
216
|
-
]), 'TYPE');
|
|
217
|
-
|
|
218
|
-
this.appendStatementInput('STATEMENT')
|
|
219
|
-
.setCheck(null);
|
|
220
|
-
|
|
221
|
-
this.setInputsInline(false);
|
|
222
|
-
this.setPreviousStatement(true, null);
|
|
223
|
-
this.setNextStatement(true, null);
|
|
224
|
-
|
|
225
|
-
this.setColour(Blockly.Action.HUE);
|
|
226
|
-
|
|
227
|
-
this.setTooltip(Blockly.Translate('http_get_tooltip'));
|
|
228
|
-
this.setHelpUrl(getHelp('http_get_help'));
|
|
229
|
-
},
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
Blockly.JavaScript.forBlock['http_get'] = function (block) {
|
|
233
|
-
const vUrl = Blockly.JavaScript.valueToCode(block, 'URL', Blockly.JavaScript.ORDER_ATOMIC);
|
|
234
|
-
const fUnit = block.getFieldValue('UNIT');
|
|
235
|
-
|
|
236
|
-
let fTimeout = block.getFieldValue('TIMEOUT');
|
|
237
|
-
if (Number.isNaN(fTimeout)) {
|
|
238
|
-
fTimeout = 2000;
|
|
239
|
-
}
|
|
240
|
-
if (fUnit === 'sec') {
|
|
241
|
-
fTimeout *= 1000;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
let responseType = block.getFieldValue('TYPE');
|
|
245
|
-
if (!responseType) {
|
|
246
|
-
responseType = 'text';
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
const statement = Blockly.JavaScript.statementToCode(block, 'STATEMENT');
|
|
250
|
-
|
|
251
|
-
return `httpGet(${vUrl}, { timeout: ${fTimeout}, responseType: '${responseType}' }, async (err, response) => {\n` +
|
|
252
|
-
statement +
|
|
253
|
-
'});\n';
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
// --- action http_post --------------------------------------------------
|
|
257
|
-
Blockly.Action.blocks['http_post'] =
|
|
258
|
-
'<sep gap="5"></sep>' +
|
|
259
|
-
'<block type="http_post">' +
|
|
260
|
-
' <field name="TIMEOUT">2000</field>' +
|
|
261
|
-
' <field name="UNIT">ms</field>' +
|
|
262
|
-
' <field name="TYPE">text</field>' +
|
|
263
|
-
' <value name="URL">' +
|
|
264
|
-
' <shadow type="text">' +
|
|
265
|
-
' <field name="TEXT">http://</field>' +
|
|
266
|
-
' </shadow>' +
|
|
267
|
-
' </value>' +
|
|
268
|
-
' <value name="DATA">' +
|
|
269
|
-
' <shadow type="logic_null"></shadow>' +
|
|
270
|
-
' </value>' +
|
|
271
|
-
'</block>';
|
|
272
|
-
|
|
273
|
-
Blockly.Blocks['http_post'] = {
|
|
274
|
-
init: function () {
|
|
275
|
-
this.appendValueInput('URL')
|
|
276
|
-
.appendField('🌐 ' + Blockly.Translate('http_post'));
|
|
277
|
-
|
|
278
|
-
this.appendDummyInput()
|
|
279
|
-
.appendField(Blockly.Translate('http_timeout'))
|
|
280
|
-
.appendField(new Blockly.FieldTextInput(2000), 'TIMEOUT')
|
|
281
|
-
.appendField(new Blockly.FieldDropdown([
|
|
282
|
-
[Blockly.Translate('http_timeout_ms'), 'ms'],
|
|
283
|
-
[Blockly.Translate('http_timeout_sec'), 'sec'],
|
|
284
|
-
]), 'UNIT');
|
|
285
|
-
|
|
286
|
-
this.appendDummyInput('TYPE')
|
|
287
|
-
.appendField(Blockly.Translate('http_type'))
|
|
288
|
-
.appendField(new Blockly.FieldDropdown([
|
|
289
|
-
[Blockly.Translate('http_type_text'), 'text'],
|
|
290
|
-
[Blockly.Translate('http_type_arraybuffer'), 'arraybuffer'],
|
|
291
|
-
]), 'TYPE');
|
|
292
|
-
|
|
293
|
-
this.appendValueInput('DATA')
|
|
294
|
-
.appendField(Blockly.Translate('http_post_data'));
|
|
295
|
-
|
|
296
|
-
this.appendStatementInput('STATEMENT')
|
|
297
|
-
.setCheck(null);
|
|
298
|
-
|
|
299
|
-
this.setInputsInline(false);
|
|
300
|
-
this.setPreviousStatement(true, null);
|
|
301
|
-
this.setNextStatement(true, null);
|
|
302
|
-
|
|
303
|
-
this.setColour(Blockly.Action.HUE);
|
|
304
|
-
|
|
305
|
-
this.setTooltip(Blockly.Translate('http_post_tooltip'));
|
|
306
|
-
this.setHelpUrl(getHelp('http_post_help'));
|
|
307
|
-
},
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
Blockly.JavaScript.forBlock['http_post'] = function (block) {
|
|
311
|
-
const vUrl = Blockly.JavaScript.valueToCode(block, 'URL', Blockly.JavaScript.ORDER_ATOMIC);
|
|
312
|
-
const fUnit = block.getFieldValue('UNIT');
|
|
313
|
-
|
|
314
|
-
let fTimeout = block.getFieldValue('TIMEOUT');
|
|
315
|
-
if (isNaN(fTimeout)) {
|
|
316
|
-
fTimeout = 2000;
|
|
317
|
-
}
|
|
318
|
-
if (fUnit === 'sec') {
|
|
319
|
-
fTimeout *= 1000;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
let fType = block.getFieldValue('TYPE');
|
|
323
|
-
if (!fType) {
|
|
324
|
-
fType = 'text';
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
let vData = Blockly.JavaScript.valueToCode(block, 'DATA', Blockly.JavaScript.ORDER_ATOMIC);
|
|
328
|
-
if (!vData) {
|
|
329
|
-
vData = 'null';
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
const statement = Blockly.JavaScript.statementToCode(block, 'STATEMENT');
|
|
333
|
-
|
|
334
|
-
return `httpPost(${vUrl}, ${vData}, { timeout: ${fTimeout}, responseType: '${fType}' }, async (err, response) => {\n` +
|
|
335
|
-
statement +
|
|
336
|
-
'});\n';
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
// --- http_response -----------------------------------------------------------
|
|
340
|
-
Blockly.Action.blocks['http_response'] =
|
|
341
|
-
'<sep gap="5"></sep>' +
|
|
342
|
-
'<block type="http_response">' +
|
|
343
|
-
' <field name="ATTR">response.data</field>' +
|
|
344
|
-
'</block>';
|
|
345
|
-
|
|
346
|
-
Blockly.Blocks['http_response'] = {
|
|
347
|
-
/**
|
|
348
|
-
* Block for conditionally returning a value from a procedure.
|
|
349
|
-
* @this Blockly.Block
|
|
350
|
-
*/
|
|
351
|
-
init: function () {
|
|
352
|
-
this.appendDummyInput()
|
|
353
|
-
.appendField('🌐');
|
|
354
|
-
|
|
355
|
-
this.appendDummyInput('ATTR')
|
|
356
|
-
.appendField(new Blockly.FieldDropdown([
|
|
357
|
-
[Blockly.Translate('http_response_data'), 'response.data'],
|
|
358
|
-
[Blockly.Translate('http_response_statuscode'), 'response.statusCode'],
|
|
359
|
-
[Blockly.Translate('http_response_responsetime'), 'response.responseTime'],
|
|
360
|
-
[Blockly.Translate('http_response_headers'), 'response.headers'],
|
|
361
|
-
[Blockly.Translate('http_response_error'), 'err'],
|
|
362
|
-
]), 'ATTR');
|
|
363
|
-
|
|
364
|
-
this.setInputsInline(true);
|
|
365
|
-
this.setOutput(true);
|
|
366
|
-
|
|
367
|
-
this.setColour(Blockly.Action.HUE);
|
|
368
|
-
|
|
369
|
-
this.setTooltip(Blockly.Translate('http_response_tooltip'));
|
|
370
|
-
this.setHelpUrl(getHelp('http_response_help'));
|
|
371
|
-
},
|
|
372
|
-
/**
|
|
373
|
-
* Called whenever anything on the workspace changes.
|
|
374
|
-
* Add warning if this flow block is not nested inside a loop.
|
|
375
|
-
* @param {!Blockly.Events.Abstract} e Change event.
|
|
376
|
-
* @this Blockly.Block
|
|
377
|
-
*/
|
|
378
|
-
onchange: function (e) {
|
|
379
|
-
let legal = false;
|
|
380
|
-
// Is the block nested in a trigger?
|
|
381
|
-
let block = this;
|
|
382
|
-
do {
|
|
383
|
-
if (this.FUNCTION_TYPES.includes(block.type)) {
|
|
384
|
-
legal = true;
|
|
385
|
-
break;
|
|
386
|
-
}
|
|
387
|
-
block = block.getSurroundParent();
|
|
388
|
-
} while (block);
|
|
389
|
-
|
|
390
|
-
if (legal) {
|
|
391
|
-
this.setWarningText(null, this.id);
|
|
392
|
-
} else {
|
|
393
|
-
this.setWarningText(Blockly.Translate('http_response_warning'), this.id);
|
|
394
|
-
}
|
|
395
|
-
},
|
|
396
|
-
/**
|
|
397
|
-
* List of block types that are functions and thus do not need warnings.
|
|
398
|
-
* To add a new function type add this to your code:
|
|
399
|
-
* Blockly.Blocks['procedures_ifreturn'].FUNCTION_TYPES.push('custom_func');
|
|
400
|
-
*/
|
|
401
|
-
FUNCTION_TYPES: ['http_get', 'http_post'],
|
|
402
|
-
};
|
|
403
|
-
Blockly.JavaScript.forBlock['http_response'] = function (block) {
|
|
404
|
-
const attr = block.getFieldValue('ATTR');
|
|
405
|
-
|
|
406
|
-
return [attr, Blockly.JavaScript.ORDER_ATOMIC];
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
// --- http_response_tofile -----------------------------------------------------------
|
|
410
|
-
Blockly.Action.blocks['http_response_tofile'] =
|
|
411
|
-
'<sep gap="5"></sep>' +
|
|
412
|
-
'<block type="http_response_tofile">' +
|
|
413
|
-
' <value name="FILENAME">' +
|
|
414
|
-
' <shadow type="text">' +
|
|
415
|
-
' <field name="TEXT">temp.jpg</field>' +
|
|
416
|
-
' </shadow>' +
|
|
417
|
-
' </value>' +
|
|
418
|
-
'</block>';
|
|
419
|
-
|
|
420
|
-
Blockly.Blocks['http_response_tofile'] = {
|
|
421
|
-
/**
|
|
422
|
-
* Block for conditionally returning a value from a procedure.
|
|
423
|
-
* @this Blockly.Block
|
|
424
|
-
*/
|
|
425
|
-
init: function () {
|
|
426
|
-
this.appendDummyInput()
|
|
427
|
-
.appendField('🌐 ' + Blockly.Translate('http_response_tofile'));
|
|
428
|
-
|
|
429
|
-
this.appendValueInput('FILENAME')
|
|
430
|
-
.appendField(Blockly.Translate('http_response_tofile_filename'))
|
|
431
|
-
.setCheck(null);
|
|
432
|
-
|
|
433
|
-
this.setInputsInline(false);
|
|
434
|
-
this.setOutput(true, 'String');
|
|
435
|
-
|
|
436
|
-
this.setColour(Blockly.Action.HUE);
|
|
437
|
-
|
|
438
|
-
this.setTooltip(Blockly.Translate('http_response_tofile_tooltip'));
|
|
439
|
-
this.setHelpUrl(getHelp('http_response_tofile_help'));
|
|
440
|
-
},
|
|
441
|
-
/**
|
|
442
|
-
* Called whenever anything on the workspace changes.
|
|
443
|
-
* Add warning if this flow block is not nested inside a loop.
|
|
444
|
-
* @param {!Blockly.Events.Abstract} e Change event.
|
|
445
|
-
* @this Blockly.Block
|
|
446
|
-
*/
|
|
447
|
-
onchange: function (e) {
|
|
448
|
-
let legal = false;
|
|
449
|
-
// Is the block nested in a trigger?
|
|
450
|
-
let block = this;
|
|
451
|
-
do {
|
|
452
|
-
if (this.FUNCTION_TYPES.includes(block.type)) {
|
|
453
|
-
legal = true;
|
|
454
|
-
break;
|
|
455
|
-
}
|
|
456
|
-
block = block.getSurroundParent();
|
|
457
|
-
} while (block);
|
|
458
|
-
|
|
459
|
-
if (legal) {
|
|
460
|
-
this.setWarningText(null, this.id);
|
|
461
|
-
} else {
|
|
462
|
-
this.setWarningText(Blockly.Translate('http_response_warning'), this.id);
|
|
463
|
-
}
|
|
464
|
-
},
|
|
465
|
-
/**
|
|
466
|
-
* List of block types that are functions and thus do not need warnings.
|
|
467
|
-
* To add a new function type add this to your code:
|
|
468
|
-
* Blockly.Blocks['procedures_ifreturn'].FUNCTION_TYPES.push('custom_func');
|
|
469
|
-
*/
|
|
470
|
-
FUNCTION_TYPES: ['http_get', 'http_post'],
|
|
471
|
-
};
|
|
472
|
-
Blockly.JavaScript.forBlock['http_response_tofile'] = function (block) {
|
|
473
|
-
const vFileName = Blockly.JavaScript.valueToCode(block, 'FILENAME', Blockly.JavaScript.ORDER_ATOMIC);
|
|
474
|
-
|
|
475
|
-
return [`createTempFile(${vFileName}, response.data)`, Blockly.JavaScript.ORDER_ATOMIC];
|
|
476
|
-
};
|
|
477
|
-
|
|
478
|
-
// --- action file_write --------------------------------------------------
|
|
479
|
-
Blockly.Action.blocks['file_write'] =
|
|
480
|
-
'<block type="file_write">' +
|
|
481
|
-
' <value name="OID">' +
|
|
482
|
-
' <shadow type="field_oid_meta">' +
|
|
483
|
-
' <field name="oid">0_userdata.0</field>' +
|
|
484
|
-
' </shadow>' +
|
|
485
|
-
' </value>' +
|
|
486
|
-
' <value name="FILE">' +
|
|
487
|
-
' <shadow type="text">' +
|
|
488
|
-
' <field name="TEXT">demo.json</field>' +
|
|
489
|
-
' </shadow>' +
|
|
490
|
-
' </value>' +
|
|
491
|
-
'</block>';
|
|
492
|
-
|
|
493
|
-
Blockly.Blocks['file_write'] = {
|
|
494
|
-
init: function () {
|
|
495
|
-
this.appendValueInput('OID')
|
|
496
|
-
.appendField('📁 ' + Blockly.Translate('file_write'));
|
|
497
|
-
|
|
498
|
-
this.appendValueInput('FILE')
|
|
499
|
-
.appendField(Blockly.Translate('file_write_filename'))
|
|
500
|
-
.setCheck(null);
|
|
501
|
-
|
|
502
|
-
this.appendValueInput('DATA')
|
|
503
|
-
.appendField(Blockly.Translate('file_write_data'));
|
|
504
|
-
|
|
505
|
-
this.setInputsInline(false);
|
|
506
|
-
this.setPreviousStatement(true, null);
|
|
507
|
-
this.setNextStatement(true, null);
|
|
508
|
-
|
|
509
|
-
this.setColour(Blockly.Action.HUE);
|
|
510
|
-
this.setTooltip(Blockly.Translate('file_write_tooltip'));
|
|
511
|
-
this.setHelpUrl(getHelp('file_write_help'));
|
|
512
|
-
},
|
|
513
|
-
};
|
|
514
|
-
|
|
515
|
-
Blockly.JavaScript.forBlock['file_write'] = function (block) {
|
|
516
|
-
const vObjId = Blockly.JavaScript.valueToCode(block, 'OID', Blockly.JavaScript.ORDER_ATOMIC);
|
|
517
|
-
const vFile = Blockly.JavaScript.valueToCode(block, 'FILE', Blockly.JavaScript.ORDER_ATOMIC);
|
|
518
|
-
const vData = Blockly.JavaScript.valueToCode(block, 'DATA', Blockly.JavaScript.ORDER_ATOMIC);
|
|
519
|
-
|
|
520
|
-
let objectName = '';
|
|
521
|
-
try {
|
|
522
|
-
const objId = eval(vObjId); // Code to string
|
|
523
|
-
objectName = main.objects[objId] && main.objects[objId].common && main.objects[objId].common.name ? main.objects[objId].common.name : '';
|
|
524
|
-
if (typeof objectName === 'object') {
|
|
525
|
-
objectName = objectName[systemLang] || objectName.en;
|
|
526
|
-
}
|
|
527
|
-
} catch (error) {
|
|
528
|
-
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
return `writeFile(${vObjId}${objectName ? ` /* ${objectName} */` : ''}, String(${vFile}), ${vData ? vData : 'null'}, (err) => {\n` +
|
|
532
|
-
Blockly.JavaScript.prefixLines(`if (err) {`, Blockly.JavaScript.INDENT) + '\n' +
|
|
533
|
-
Blockly.JavaScript.prefixLines(`console.error(err);`, Blockly.JavaScript.INDENT + Blockly.JavaScript.INDENT) + '\n' +
|
|
534
|
-
Blockly.JavaScript.prefixLines(`}`, Blockly.JavaScript.INDENT) + '\n' +
|
|
535
|
-
'});\n';
|
|
536
|
-
};
|
|
537
|
-
|
|
538
|
-
// --- action file_read --------------------------------------------------
|
|
539
|
-
Blockly.Action.blocks['file_read'] =
|
|
540
|
-
'<sep gap="5"></sep>' +
|
|
541
|
-
'<block type="file_read">' +
|
|
542
|
-
' <value name="OID">' +
|
|
543
|
-
' <shadow type="field_oid_meta">' +
|
|
544
|
-
' <field name="oid">0_userdata.0</field>' +
|
|
545
|
-
' </shadow>' +
|
|
546
|
-
' </value>' +
|
|
547
|
-
' <value name="FILE">' +
|
|
548
|
-
' <shadow type="text">' +
|
|
549
|
-
' <field name="TEXT">demo.json</field>' +
|
|
550
|
-
' </shadow>' +
|
|
551
|
-
' </value>' +
|
|
552
|
-
'</block>';
|
|
553
|
-
|
|
554
|
-
Blockly.Blocks['file_read'] = {
|
|
555
|
-
init: function () {
|
|
556
|
-
this.appendValueInput('OID')
|
|
557
|
-
.appendField('📁 ' + Blockly.Translate('file_read'));
|
|
558
|
-
|
|
559
|
-
this.appendValueInput('FILE')
|
|
560
|
-
.appendField(Blockly.Translate('file_read_filename'))
|
|
561
|
-
.setCheck(null);
|
|
562
|
-
|
|
563
|
-
this.appendStatementInput('STATEMENT')
|
|
564
|
-
.setCheck(null);
|
|
565
|
-
|
|
566
|
-
this.setInputsInline(false);
|
|
567
|
-
this.setPreviousStatement(true, null);
|
|
568
|
-
this.setNextStatement(true, null);
|
|
569
|
-
|
|
570
|
-
this.setColour(Blockly.Action.HUE);
|
|
571
|
-
|
|
572
|
-
this.setTooltip(Blockly.Translate('file_read_tooltip'));
|
|
573
|
-
this.setHelpUrl(getHelp('file_read_help'));
|
|
574
|
-
},
|
|
575
|
-
};
|
|
576
|
-
|
|
577
|
-
Blockly.JavaScript.forBlock['file_read'] = function (block) {
|
|
578
|
-
const vObjId = Blockly.JavaScript.valueToCode(block, 'OID', Blockly.JavaScript.ORDER_ATOMIC);
|
|
579
|
-
const vFile = Blockly.JavaScript.valueToCode(block, 'FILE', Blockly.JavaScript.ORDER_ATOMIC);
|
|
580
|
-
const statement = Blockly.JavaScript.statementToCode(block, 'STATEMENT');
|
|
581
|
-
|
|
582
|
-
let objectName = '';
|
|
583
|
-
try {
|
|
584
|
-
const objId = eval(vObjId); // Code to string
|
|
585
|
-
objectName = main.objects[objId] && main.objects[objId].common && main.objects[objId].common.name ? main.objects[objId].common.name : '';
|
|
586
|
-
if (typeof objectName === 'object') {
|
|
587
|
-
objectName = objectName[systemLang] || objectName.en;
|
|
588
|
-
}
|
|
589
|
-
} catch (error) {
|
|
590
|
-
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
return `readFile(${vObjId}${objectName ? ` /* ${objectName} */` : ''}, String(${vFile}), (err, data, mimeType) => {\n` +
|
|
594
|
-
Blockly.JavaScript.prefixLines(`if (err) {`, Blockly.JavaScript.INDENT) + '\n' +
|
|
595
|
-
Blockly.JavaScript.prefixLines(`console.error(err);`, Blockly.JavaScript.INDENT + Blockly.JavaScript.INDENT) + '\n' +
|
|
596
|
-
Blockly.JavaScript.prefixLines(`}`, Blockly.JavaScript.INDENT) + '\n' +
|
|
597
|
-
statement +
|
|
598
|
-
'});\n';
|
|
599
|
-
};
|
|
600
|
-
|
|
601
|
-
// --- file_data -----------------------------------------------------------
|
|
602
|
-
Blockly.Action.blocks['file_data'] =
|
|
603
|
-
'<sep gap="5"></sep>' +
|
|
604
|
-
'<block type="file_data">' +
|
|
605
|
-
' <field name="ATTR">data</field>' +
|
|
606
|
-
'</block>';
|
|
607
|
-
|
|
608
|
-
Blockly.Blocks['file_data'] = {
|
|
609
|
-
/**
|
|
610
|
-
* Block for conditionally returning a value from a procedure.
|
|
611
|
-
* @this Blockly.Block
|
|
612
|
-
*/
|
|
613
|
-
init: function () {
|
|
614
|
-
this.appendDummyInput()
|
|
615
|
-
.appendField('📁');
|
|
616
|
-
|
|
617
|
-
this.appendDummyInput('ATTR')
|
|
618
|
-
.appendField(new Blockly.FieldDropdown([
|
|
619
|
-
[Blockly.Translate('file_data_data'), 'data'],
|
|
620
|
-
[Blockly.Translate('file_data_mimeType'), 'mimeType'],
|
|
621
|
-
]), 'ATTR');
|
|
622
|
-
|
|
623
|
-
this.setInputsInline(true);
|
|
624
|
-
this.setOutput(true);
|
|
625
|
-
|
|
626
|
-
this.setColour(Blockly.Action.HUE);
|
|
627
|
-
|
|
628
|
-
this.setTooltip(Blockly.Translate('file_data_tooltip'));
|
|
629
|
-
//this.setHelpUrl(getHelp('file_data'));
|
|
630
|
-
},
|
|
631
|
-
/**
|
|
632
|
-
* Called whenever anything on the workspace changes.
|
|
633
|
-
* Add warning if this flow block is not nested inside a loop.
|
|
634
|
-
* @param {!Blockly.Events.Abstract} e Change event.
|
|
635
|
-
* @this Blockly.Block
|
|
636
|
-
*/
|
|
637
|
-
onchange: function (e) {
|
|
638
|
-
let legal = false;
|
|
639
|
-
// Is the block nested in a trigger?
|
|
640
|
-
let block = this;
|
|
641
|
-
do {
|
|
642
|
-
if (this.FUNCTION_TYPES.includes(block.type)) {
|
|
643
|
-
legal = true;
|
|
644
|
-
break;
|
|
645
|
-
}
|
|
646
|
-
block = block.getSurroundParent();
|
|
647
|
-
} while (block);
|
|
648
|
-
|
|
649
|
-
if (legal) {
|
|
650
|
-
this.setWarningText(null, this.id);
|
|
651
|
-
} else {
|
|
652
|
-
this.setWarningText(Blockly.Translate('file_data_warning'), this.id);
|
|
653
|
-
}
|
|
654
|
-
},
|
|
655
|
-
/**
|
|
656
|
-
* List of block types that are functions and thus do not need warnings.
|
|
657
|
-
* To add a new function type add this to your code:
|
|
658
|
-
* Blockly.Blocks['procedures_ifreturn'].FUNCTION_TYPES.push('custom_func');
|
|
659
|
-
*/
|
|
660
|
-
FUNCTION_TYPES: ['file_read'],
|
|
661
|
-
};
|
|
662
|
-
Blockly.JavaScript.forBlock['file_data'] = function (block) {
|
|
663
|
-
const vAttr = block.getFieldValue('ATTR');
|
|
664
|
-
|
|
665
|
-
return [vAttr, Blockly.JavaScript.ORDER_ATOMIC];
|
|
666
|
-
};
|
|
667
|
-
|
|
668
|
-
// --- action request --------------------------------------------------
|
|
669
|
-
Blockly.Action.blocks['request'] =
|
|
670
|
-
'<block type="request">' +
|
|
671
|
-
' <mutation with_statement="false"></mutation>' +
|
|
672
|
-
' <field name="WITH_STATEMENT">FALSE</field>' +
|
|
673
|
-
' <field name="LOG"></field>' +
|
|
674
|
-
' <value name="URL">' +
|
|
675
|
-
' <shadow type="text">' +
|
|
676
|
-
' <field name="TEXT">http://</field>' +
|
|
677
|
-
' </shadow>' +
|
|
678
|
-
' </value>' +
|
|
679
|
-
'</block>';
|
|
680
|
-
|
|
681
|
-
Blockly.Blocks['request'] = {
|
|
682
|
-
init: function () {
|
|
683
|
-
this.appendDummyInput('TEXT')
|
|
684
|
-
.appendField(Blockly.Translate('request'));
|
|
685
|
-
|
|
686
|
-
this.appendValueInput('URL')
|
|
687
|
-
.appendField(Blockly.Translate('request_url'));
|
|
688
|
-
|
|
689
|
-
this.appendDummyInput('WITH_STATEMENT')
|
|
690
|
-
.appendField(Blockly.Translate('with_results'))
|
|
691
|
-
.appendField(new Blockly.FieldCheckbox('FALSE', function (option) {
|
|
692
|
-
this.sourceBlock_.updateShape_(option === true || option === 'true' || option === 'TRUE');
|
|
693
|
-
}), 'WITH_STATEMENT');
|
|
694
|
-
|
|
695
|
-
this.appendDummyInput('LOG')
|
|
696
|
-
.appendField(Blockly.Translate('loglevel'))
|
|
697
|
-
.appendField(new Blockly.FieldDropdown([
|
|
698
|
-
[Blockly.Translate('loglevel_none'), ''],
|
|
699
|
-
[Blockly.Translate('loglevel_debug'), 'debug'],
|
|
700
|
-
[Blockly.Translate('loglevel_info'), 'info'],
|
|
701
|
-
[Blockly.Translate('loglevel_warn'), 'warn'],
|
|
702
|
-
[Blockly.Translate('loglevel_error'), 'error'],
|
|
703
|
-
]), 'LOG');
|
|
704
|
-
|
|
705
|
-
this.setInputsInline(false);
|
|
706
|
-
this.setPreviousStatement(true, null);
|
|
707
|
-
this.setNextStatement(true, null);
|
|
708
|
-
|
|
709
|
-
this.setColour(Blockly.Action.HUE);
|
|
710
|
-
|
|
711
|
-
this.setTooltip(Blockly.Translate('request_tooltip'));
|
|
712
|
-
this.setHelpUrl(Blockly.Translate('request_help'));
|
|
713
|
-
},
|
|
714
|
-
mutationToDom: function () {
|
|
715
|
-
const container = document.createElement('mutation');
|
|
716
|
-
const withStatement = this.getFieldValue('WITH_STATEMENT');
|
|
717
|
-
|
|
718
|
-
container.setAttribute('with_statement', withStatement === true || withStatement === 'true' || withStatement === 'TRUE');
|
|
719
|
-
|
|
720
|
-
return container;
|
|
721
|
-
},
|
|
722
|
-
domToMutation: function (xmlElement) {
|
|
723
|
-
const option = xmlElement.getAttribute('with_statement');
|
|
724
|
-
|
|
725
|
-
this.updateShape_(option === true || option === 'true' || option === 'TRUE');
|
|
726
|
-
},
|
|
727
|
-
updateShape_: function (withStatement) {
|
|
728
|
-
// Add or remove a statement Input.
|
|
729
|
-
let inputExists;
|
|
730
|
-
try {
|
|
731
|
-
inputExists = this.getInput('STATEMENT');
|
|
732
|
-
} catch (e) {
|
|
733
|
-
// Input does not exist
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
if (withStatement) {
|
|
737
|
-
if (!inputExists) {
|
|
738
|
-
this.appendStatementInput('STATEMENT');
|
|
739
|
-
}
|
|
740
|
-
} else if (inputExists) {
|
|
741
|
-
this.removeInput('STATEMENT');
|
|
742
|
-
}
|
|
743
|
-
},
|
|
744
|
-
};
|
|
745
|
-
|
|
746
|
-
Blockly.JavaScript.forBlock['request'] = function (block) {
|
|
747
|
-
const vUrl = Blockly.JavaScript.valueToCode(block, 'URL', Blockly.JavaScript.ORDER_ATOMIC);
|
|
748
|
-
const fWithStatement = block.getFieldValue('WITH_STATEMENT');
|
|
749
|
-
const fLog = block.getFieldValue('LOG');
|
|
750
|
-
|
|
751
|
-
let logText = '';
|
|
752
|
-
if (fLog) {
|
|
753
|
-
logText = `console.${fLog}('request: ' + ${vUrl});\n`;
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
if (fWithStatement === 'TRUE' || fWithStatement === 'true' || fWithStatement === true) {
|
|
757
|
-
const statement = Blockly.JavaScript.statementToCode(block, 'STATEMENT');
|
|
758
|
-
if (statement) {
|
|
759
|
-
return 'try {\n require("request")(' + vUrl + ', async (error, response, result) => {\n ' + statement + ' }).on("error", (e) => { console.error(e); });\n} catch (e) { console.error(e); }\n' + logText;
|
|
760
|
-
}
|
|
761
|
-
return 'try {\n require("request")(' + vUrl + ').on("error", (e) => { console.error(e); });\n} catch (e) { console.error(e); }\n' + logText;
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
return 'try {\n require("request")(' + vUrl + ').on("error", (e) => { console.error(e); });\n} catch (e) { console.error(e); }\n' + logText;
|
|
765
|
-
};
|