blockly 7.20211209.4 → 8.0.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/blockly.d.ts +18963 -18432
- package/blockly.min.js +5 -4
- package/blockly_compressed.js +4 -3
- package/blockly_compressed.js.map +1 -1
- package/blocks/blocks.js +47 -0
- package/blocks/colour.js +13 -3
- package/blocks/lists.js +22 -13
- package/blocks/logic.js +13 -3
- package/blocks/loops.js +24 -11
- package/blocks/math.js +12 -3
- package/blocks/procedures.js +45 -32
- package/blocks/text.js +22 -13
- package/blocks/variables.js +14 -3
- package/blocks/variables_dynamic.js +13 -3
- package/blocks_compressed.js +1 -1
- package/blocks_compressed.js.map +1 -1
- package/core/block.js +1869 -1814
- package/core/block_drag_surface.js +201 -200
- package/core/block_dragger.js +377 -373
- package/core/block_svg.js +1593 -1479
- package/core/blockly.js +8 -22
- package/core/blocks.js +9 -2
- package/core/browser_events.js +22 -5
- package/core/bubble.js +841 -797
- package/core/bubble_dragger.js +213 -206
- package/core/bump_objects.js +2 -2
- package/core/clipboard.js +9 -9
- package/core/comment.js +353 -332
- package/core/common.js +46 -17
- package/core/component_manager.js +181 -174
- package/core/config.js +87 -0
- package/core/connection.js +595 -584
- package/core/connection_checker.js +242 -244
- package/core/connection_db.js +235 -230
- package/core/contextmenu.js +9 -6
- package/core/contextmenu_items.js +1 -2
- package/core/contextmenu_registry.js +93 -89
- package/core/css.js +474 -474
- package/core/delete_area.js +45 -42
- package/core/drag_target.js +57 -56
- package/core/dropdowndiv.js +153 -163
- package/core/events/events.js +2 -2
- package/core/events/events_abstract.js +89 -77
- package/core/events/events_block_base.js +37 -36
- package/core/events/events_block_change.js +130 -124
- package/core/events/events_block_create.js +73 -71
- package/core/events/events_block_delete.js +84 -82
- package/core/events/events_block_drag.js +50 -49
- package/core/events/events_block_move.js +147 -140
- package/core/events/events_bubble_open.js +51 -50
- package/core/events/events_click.js +48 -44
- package/core/events/events_comment_base.js +72 -69
- package/core/events/events_comment_change.js +63 -61
- package/core/events/events_comment_create.js +44 -42
- package/core/events/events_comment_delete.js +42 -40
- package/core/events/events_comment_move.js +106 -104
- package/core/events/events_marker_move.js +65 -64
- package/core/events/events_selected.js +46 -45
- package/core/events/events_theme_change.js +36 -35
- package/core/events/events_toolbox_item_select.js +46 -45
- package/core/events/events_trashcan_open.js +37 -36
- package/core/events/events_ui.js +47 -46
- package/core/events/events_ui_base.js +30 -29
- package/core/events/events_var_base.js +37 -36
- package/core/events/events_var_create.js +50 -48
- package/core/events/events_var_delete.js +50 -48
- package/core/events/events_var_rename.js +51 -49
- package/core/events/events_viewport.js +66 -65
- package/core/events/utils.js +29 -14
- package/core/events/workspace_events.js +49 -55
- package/core/extensions.js +4 -3
- package/core/field.js +1061 -997
- package/core/field_angle.js +462 -442
- package/core/field_checkbox.js +194 -182
- package/core/field_colour.js +519 -505
- package/core/field_dropdown.js +617 -598
- package/core/field_image.js +229 -220
- package/core/field_label.js +102 -91
- package/core/field_label_serializable.js +42 -41
- package/core/field_multilineinput.js +372 -358
- package/core/field_number.js +272 -253
- package/core/field_textinput.js +499 -467
- package/core/field_variable.js +458 -420
- package/core/flyout_base.js +1005 -952
- package/core/flyout_button.js +277 -260
- package/core/flyout_horizontal.js +304 -302
- package/core/flyout_metrics_manager.js +64 -64
- package/core/flyout_vertical.js +306 -300
- package/core/generator.js +459 -446
- package/core/gesture.js +829 -813
- package/core/grid.js +166 -163
- package/core/icon.js +168 -159
- package/core/inject.js +7 -5
- package/core/input.js +257 -248
- package/core/insertion_marker_manager.js +655 -624
- package/core/internal_constants.js +0 -129
- package/core/keyboard_nav/ast_node.js +605 -596
- package/core/keyboard_nav/basic_cursor.js +166 -165
- package/core/keyboard_nav/cursor.js +99 -97
- package/core/keyboard_nav/marker.js +83 -79
- package/core/keyboard_nav/tab_navigate_cursor.js +18 -23
- package/core/marker_manager.js +153 -141
- package/core/menu.js +377 -372
- package/core/menuitem.js +223 -217
- package/core/metrics_manager.js +403 -390
- package/core/mutator.js +468 -437
- package/core/names.js +229 -188
- package/core/options.js +290 -284
- package/core/procedures.js +29 -17
- package/core/registry.js +19 -16
- package/core/rendered_connection.js +482 -463
- package/core/renderers/common/block_rendering.js +9 -3
- package/core/renderers/common/constants.js +1119 -1112
- package/core/renderers/common/debug.js +14 -0
- package/core/renderers/common/debugger.js +338 -316
- package/core/renderers/common/drawer.js +380 -370
- package/core/renderers/common/i_path_object.js +2 -2
- package/core/renderers/common/info.js +626 -618
- package/core/renderers/common/marker_svg.js +579 -541
- package/core/renderers/common/path_object.js +203 -200
- package/core/renderers/common/renderer.js +220 -218
- package/core/renderers/geras/constants.js +36 -36
- package/core/renderers/geras/drawer.js +155 -147
- package/core/renderers/geras/highlight_constants.js +244 -238
- package/core/renderers/geras/highlighter.js +231 -179
- package/core/renderers/geras/info.js +392 -369
- package/core/renderers/geras/measurables/inline_input.js +25 -19
- package/core/renderers/geras/measurables/statement_input.js +23 -17
- package/core/renderers/geras/path_object.js +106 -121
- package/core/renderers/geras/renderer.js +96 -98
- package/core/renderers/measurables/base.js +30 -18
- package/core/renderers/measurables/bottom_row.js +83 -80
- package/core/renderers/measurables/connection.js +22 -15
- package/core/renderers/measurables/external_value_input.js +35 -22
- package/core/renderers/measurables/field.js +35 -20
- package/core/renderers/measurables/hat.js +18 -13
- package/core/renderers/measurables/icon.js +24 -17
- package/core/renderers/measurables/in_row_spacer.js +15 -13
- package/core/renderers/measurables/inline_input.js +43 -33
- package/core/renderers/measurables/input_connection.js +41 -28
- package/core/renderers/measurables/input_row.js +50 -44
- package/core/renderers/measurables/jagged_edge.js +14 -12
- package/core/renderers/measurables/next_connection.js +16 -14
- package/core/renderers/measurables/output_connection.js +26 -20
- package/core/renderers/measurables/previous_connection.js +16 -15
- package/core/renderers/measurables/round_corner.js +20 -18
- package/core/renderers/measurables/row.js +184 -168
- package/core/renderers/measurables/spacer_row.js +38 -23
- package/core/renderers/measurables/square_corner.js +18 -16
- package/core/renderers/measurables/statement_input.js +23 -20
- package/core/renderers/measurables/top_row.js +88 -85
- package/core/renderers/minimalist/constants.js +8 -7
- package/core/renderers/minimalist/drawer.js +11 -10
- package/core/renderers/minimalist/info.js +18 -18
- package/core/renderers/minimalist/renderer.js +40 -39
- package/core/renderers/thrasos/info.js +258 -248
- package/core/renderers/thrasos/renderer.js +20 -20
- package/core/renderers/zelos/constants.js +898 -873
- package/core/renderers/zelos/drawer.js +186 -169
- package/core/renderers/zelos/info.js +502 -479
- package/core/renderers/zelos/marker_svg.js +129 -115
- package/core/renderers/zelos/measurables/bottom_row.js +31 -30
- package/core/renderers/zelos/measurables/inputs.js +22 -21
- package/core/renderers/zelos/measurables/row_elements.js +14 -13
- package/core/renderers/zelos/measurables/top_row.js +34 -33
- package/core/renderers/zelos/path_object.js +181 -180
- package/core/renderers/zelos/renderer.js +91 -92
- package/core/scrollbar.js +759 -713
- package/core/scrollbar_pair.js +250 -245
- package/core/serialization/blocks.js +26 -10
- package/core/serialization/workspaces.js +3 -2
- package/core/shortcut_registry.js +286 -277
- package/core/sprites.js +31 -0
- package/core/theme.js +135 -141
- package/core/theme_manager.js +147 -143
- package/core/toolbox/category.js +602 -576
- package/core/toolbox/collapsible_category.js +226 -227
- package/core/toolbox/separator.js +70 -61
- package/core/toolbox/toolbox.js +934 -927
- package/core/toolbox/toolbox_item.js +115 -99
- package/core/tooltip.js +108 -35
- package/core/touch.js +8 -3
- package/core/touch_gesture.js +254 -251
- package/core/trashcan.js +606 -595
- package/core/utils/coordinate.js +97 -95
- package/core/utils/dom.js +2 -2
- package/core/utils/global.js +2 -0
- package/core/utils/rect.js +41 -37
- package/core/utils/sentinel.js +25 -0
- package/core/utils/size.js +30 -27
- package/core/utils/svg.js +18 -16
- package/core/variable_map.js +325 -341
- package/core/variable_model.js +55 -54
- package/core/variables.js +9 -2
- package/core/variables_dynamic.js +3 -1
- package/core/warning.js +126 -120
- package/core/widgetdiv.js +4 -4
- package/core/workspace.js +685 -664
- package/core/workspace_audio.js +124 -118
- package/core/workspace_comment.js +308 -298
- package/core/workspace_comment_svg.js +1029 -951
- package/core/workspace_drag_surface_svg.js +147 -140
- package/core/workspace_dragger.js +70 -71
- package/core/workspace_svg.js +2322 -2297
- package/core/xml.js +30 -20
- package/core/zoom_controls.js +431 -439
- package/generators/dart/colour.js +56 -64
- package/generators/dart/lists.js +61 -50
- package/generators/dart/math.js +160 -148
- package/generators/dart/text.js +83 -61
- package/generators/javascript/colour.js +37 -34
- package/generators/javascript/lists.js +50 -43
- package/generators/javascript/math.js +123 -139
- package/generators/javascript/text.js +67 -81
- package/generators/lua/colour.js +25 -23
- package/generators/lua/lists.js +97 -69
- package/generators/lua/logic.js +1 -2
- package/generators/lua/math.js +182 -144
- package/generators/lua/text.js +116 -99
- package/generators/php/colour.js +38 -32
- package/generators/php/lists.js +109 -89
- package/generators/php/math.js +90 -81
- package/generators/php/text.js +63 -61
- package/generators/python/colour.js +18 -18
- package/generators/python/lists.js +38 -30
- package/generators/python/loops.js +12 -8
- package/generators/python/math.js +104 -106
- package/generators/python/text.js +34 -30
- package/msg/smn.js +436 -0
- package/package.json +7 -6
- package/blocks/all.js +0 -23
|
@@ -24,17 +24,16 @@ Dart['colour_picker'] = function(block) {
|
|
|
24
24
|
|
|
25
25
|
Dart['colour_random'] = function(block) {
|
|
26
26
|
// Generate a random colour.
|
|
27
|
-
Dart.definitions_['import_dart_math'] =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
'}']);
|
|
27
|
+
Dart.definitions_['import_dart_math'] = "import 'dart:math' as Math;";
|
|
28
|
+
const functionName = Dart.provideFunction_('colour_random', `
|
|
29
|
+
String ${Dart.FUNCTION_NAME_PLACEHOLDER_}() {
|
|
30
|
+
String hex = '0123456789abcdef';
|
|
31
|
+
var rnd = new Math.Random();
|
|
32
|
+
return '#\${hex[rnd.nextInt(16)]}\${hex[rnd.nextInt(16)]}'
|
|
33
|
+
'\${hex[rnd.nextInt(16)]}\${hex[rnd.nextInt(16)]}'
|
|
34
|
+
'\${hex[rnd.nextInt(16)]}\${hex[rnd.nextInt(16)]}';
|
|
35
|
+
}
|
|
36
|
+
`);
|
|
38
37
|
const code = functionName + '()';
|
|
39
38
|
return [code, Dart.ORDER_UNARY_POSTFIX];
|
|
40
39
|
};
|
|
@@ -48,66 +47,59 @@ Dart['colour_rgb'] = function(block) {
|
|
|
48
47
|
const blue = Dart.valueToCode(block, 'BLUE',
|
|
49
48
|
Dart.ORDER_NONE) || 0;
|
|
50
49
|
|
|
51
|
-
Dart.definitions_['import_dart_math'] =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
' return \'#$rs$gs$bs\';',
|
|
70
|
-
'}']);
|
|
50
|
+
Dart.definitions_['import_dart_math'] = "import 'dart:math' as Math;";
|
|
51
|
+
const functionName = Dart.provideFunction_('colour_rgb', `
|
|
52
|
+
String ${Dart.FUNCTION_NAME_PLACEHOLDER_}(num r, num g, num b) {
|
|
53
|
+
num rn = (Math.max(Math.min(r, 100), 0) * 2.55).round();
|
|
54
|
+
String rs = rn.toInt().toRadixString(16);
|
|
55
|
+
rs = '0$rs';
|
|
56
|
+
rs = rs.substring(rs.length - 2);
|
|
57
|
+
num gn = (Math.max(Math.min(g, 100), 0) * 2.55).round();
|
|
58
|
+
String gs = gn.toInt().toRadixString(16);
|
|
59
|
+
gs = '0$gs';
|
|
60
|
+
gs = gs.substring(gs.length - 2);
|
|
61
|
+
num bn = (Math.max(Math.min(b, 100), 0) * 2.55).round();
|
|
62
|
+
String bs = bn.toInt().toRadixString(16);
|
|
63
|
+
bs = '0$bs';
|
|
64
|
+
bs = bs.substring(bs.length - 2);
|
|
65
|
+
return '#$rs$gs$bs';
|
|
66
|
+
}
|
|
67
|
+
`);
|
|
71
68
|
const code = functionName + '(' + red + ', ' + green + ', ' + blue + ')';
|
|
72
69
|
return [code, Dart.ORDER_UNARY_POSTFIX];
|
|
73
70
|
};
|
|
74
71
|
|
|
75
72
|
Dart['colour_blend'] = function(block) {
|
|
76
73
|
// Blend two colours together.
|
|
77
|
-
const c1 = Dart.valueToCode(block, 'COLOUR1',
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
Dart.ORDER_NONE) || '\'#000000\'';
|
|
81
|
-
const ratio = Dart.valueToCode(block, 'RATIO',
|
|
82
|
-
Dart.ORDER_NONE) || 0.5;
|
|
74
|
+
const c1 = Dart.valueToCode(block, 'COLOUR1', Dart.ORDER_NONE) || "'#000000'";
|
|
75
|
+
const c2 = Dart.valueToCode(block, 'COLOUR2', Dart.ORDER_NONE) || "'#000000'";
|
|
76
|
+
const ratio = Dart.valueToCode(block, 'RATIO', Dart.ORDER_NONE) || 0.5;
|
|
83
77
|
|
|
84
|
-
Dart.definitions_['import_dart_math'] =
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
' return \'#$rs$gs$bs\';',
|
|
110
|
-
'}']);
|
|
78
|
+
Dart.definitions_['import_dart_math'] = "import 'dart:math' as Math;";
|
|
79
|
+
const functionName = Dart.provideFunction_('colour_blend', `
|
|
80
|
+
String ${Dart.FUNCTION_NAME_PLACEHOLDER_}(String c1, String c2, num ratio) {
|
|
81
|
+
ratio = Math.max(Math.min(ratio, 1), 0);
|
|
82
|
+
int r1 = int.parse('0x\${c1.substring(1, 3)}');
|
|
83
|
+
int g1 = int.parse('0x\${c1.substring(3, 5)}');
|
|
84
|
+
int b1 = int.parse('0x\${c1.substring(5, 7)}');
|
|
85
|
+
int r2 = int.parse('0x\${c2.substring(1, 3)}');
|
|
86
|
+
int g2 = int.parse('0x\${c2.substring(3, 5)}');
|
|
87
|
+
int b2 = int.parse('0x\${c2.substring(5, 7)}');
|
|
88
|
+
num rn = (r1 * (1 - ratio) + r2 * ratio).round();
|
|
89
|
+
String rs = rn.toInt().toRadixString(16);
|
|
90
|
+
num gn = (g1 * (1 - ratio) + g2 * ratio).round();
|
|
91
|
+
String gs = gn.toInt().toRadixString(16);
|
|
92
|
+
num bn = (b1 * (1 - ratio) + b2 * ratio).round();
|
|
93
|
+
String bs = bn.toInt().toRadixString(16);
|
|
94
|
+
rs = '0$rs';
|
|
95
|
+
rs = rs.substring(rs.length - 2);
|
|
96
|
+
gs = '0$gs';
|
|
97
|
+
gs = gs.substring(gs.length - 2);
|
|
98
|
+
bs = '0$bs';
|
|
99
|
+
bs = bs.substring(bs.length - 2);
|
|
100
|
+
return '#$rs$gs$bs';
|
|
101
|
+
}
|
|
102
|
+
`);
|
|
111
103
|
const code = functionName + '(' + c1 + ', ' + c2 + ', ' + ratio + ')';
|
|
112
104
|
return [code, Dart.ORDER_UNARY_POSTFIX];
|
|
113
105
|
};
|
package/generators/dart/lists.js
CHANGED
|
@@ -58,7 +58,7 @@ Dart['lists_indexOf'] = function(block) {
|
|
|
58
58
|
// Find an item in the list.
|
|
59
59
|
const operator =
|
|
60
60
|
block.getFieldValue('END') === 'FIRST' ? 'indexOf' : 'lastIndexOf';
|
|
61
|
-
const item = Dart.valueToCode(block, 'FIND', Dart.ORDER_NONE) || '
|
|
61
|
+
const item = Dart.valueToCode(block, 'FIND', Dart.ORDER_NONE) || "''";
|
|
62
62
|
const list =
|
|
63
63
|
Dart.valueToCode(block, 'VALUE', Dart.ORDER_UNARY_POSTFIX) || '[]';
|
|
64
64
|
const code = list + '.' + operator + '(' + item + ')';
|
|
@@ -112,21 +112,23 @@ Dart['lists_getIndex'] = function(block) {
|
|
|
112
112
|
} else if (mode === 'GET') {
|
|
113
113
|
const at = Dart.getAdjusted(block, 'AT', 1);
|
|
114
114
|
// We need to create a procedure to avoid reevaluating values.
|
|
115
|
-
const functionName = Dart.provideFunction_('lists_get_from_end',
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
115
|
+
const functionName = Dart.provideFunction_('lists_get_from_end', `
|
|
116
|
+
dynamic ${Dart.FUNCTION_NAME_PLACEHOLDER_}(List my_list, num x) {
|
|
117
|
+
x = my_list.length - x;
|
|
118
|
+
return my_list[x];
|
|
119
|
+
}
|
|
120
|
+
`);
|
|
120
121
|
const code = functionName + '(' + list + ', ' + at + ')';
|
|
121
122
|
return [code, Dart.ORDER_UNARY_POSTFIX];
|
|
122
123
|
} else if (mode === 'GET_REMOVE') {
|
|
123
124
|
const at = Dart.getAdjusted(block, 'AT', 1);
|
|
124
125
|
// We need to create a procedure to avoid reevaluating values.
|
|
125
|
-
const functionName = Dart.provideFunction_('lists_remove_from_end',
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
const functionName = Dart.provideFunction_('lists_remove_from_end', `
|
|
127
|
+
dynamic ${Dart.FUNCTION_NAME_PLACEHOLDER_}(List my_list, num x) {
|
|
128
|
+
x = my_list.length - x;
|
|
129
|
+
return my_list.removeAt(x);
|
|
130
|
+
}
|
|
131
|
+
`);
|
|
130
132
|
const code = functionName + '(' + list + ', ' + at + ')';
|
|
131
133
|
return [code, Dart.ORDER_UNARY_POSTFIX];
|
|
132
134
|
}
|
|
@@ -195,21 +197,22 @@ Dart['lists_getIndex'] = function(block) {
|
|
|
195
197
|
code += list + '.removeAt(' + xVar + ');\n';
|
|
196
198
|
return code;
|
|
197
199
|
} else if (mode === 'GET') {
|
|
198
|
-
const functionName = Dart.provideFunction_('lists_get_random_item',
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
200
|
+
const functionName = Dart.provideFunction_('lists_get_random_item', `
|
|
201
|
+
dynamic ${Dart.FUNCTION_NAME_PLACEHOLDER_}(List my_list) {
|
|
202
|
+
int x = new Math.Random().nextInt(my_list.length);
|
|
203
|
+
return my_list[x];
|
|
204
|
+
}
|
|
205
|
+
`);
|
|
203
206
|
const code = functionName + '(' + list + ')';
|
|
204
207
|
return [code, Dart.ORDER_UNARY_POSTFIX];
|
|
205
208
|
} else if (mode === 'GET_REMOVE') {
|
|
206
209
|
const functionName =
|
|
207
|
-
Dart.provideFunction_('lists_remove_random_item',
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
210
|
+
Dart.provideFunction_('lists_remove_random_item', `
|
|
211
|
+
dynamic ${Dart.FUNCTION_NAME_PLACEHOLDER_}(List my_list) {
|
|
212
|
+
int x = new Math.Random().nextInt(my_list.length);
|
|
213
|
+
return my_list.removeAt(x);
|
|
214
|
+
}
|
|
215
|
+
`);
|
|
213
216
|
const code = functionName + '(' + list + ')';
|
|
214
217
|
return [code, Dart.ORDER_UNARY_POSTFIX];
|
|
215
218
|
}
|
|
@@ -344,18 +347,25 @@ Dart['lists_getSublist'] = function(block) {
|
|
|
344
347
|
} else {
|
|
345
348
|
const at1 = Dart.getAdjusted(block, 'AT1');
|
|
346
349
|
const at2 = Dart.getAdjusted(block, 'AT2');
|
|
347
|
-
const functionName = Dart.provideFunction_('lists_get_sublist',
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
'
|
|
358
|
-
|
|
350
|
+
const functionName = Dart.provideFunction_('lists_get_sublist', `
|
|
351
|
+
List ${Dart.FUNCTION_NAME_PLACEHOLDER_}(List list, String where1, num at1, String where2, num at2) {
|
|
352
|
+
int getAt(String where, num at) {
|
|
353
|
+
if (where == 'FROM_END') {
|
|
354
|
+
at = list.length - 1 - at;
|
|
355
|
+
} else if (where == 'FIRST') {
|
|
356
|
+
at = 0;
|
|
357
|
+
} else if (where == 'LAST') {
|
|
358
|
+
at = list.length - 1;
|
|
359
|
+
} else if (where != 'FROM_START') {
|
|
360
|
+
throw 'Unhandled option (lists_getSublist).';
|
|
361
|
+
}
|
|
362
|
+
return at;
|
|
363
|
+
}
|
|
364
|
+
at1 = getAt(where1, at1);
|
|
365
|
+
at2 = getAt(where2, at2) + 1;
|
|
366
|
+
return list.sublist(at1, at2);
|
|
367
|
+
}
|
|
368
|
+
`);
|
|
359
369
|
code = functionName + '(' + list + ', \'' + where1 + '\', ' + at1 + ', \'' +
|
|
360
370
|
where2 + '\', ' + at2 + ')';
|
|
361
371
|
}
|
|
@@ -367,20 +377,21 @@ Dart['lists_sort'] = function(block) {
|
|
|
367
377
|
const list = Dart.valueToCode(block, 'LIST', Dart.ORDER_NONE) || '[]';
|
|
368
378
|
const direction = block.getFieldValue('DIRECTION') === '1' ? 1 : -1;
|
|
369
379
|
const type = block.getFieldValue('TYPE');
|
|
370
|
-
const sortFunctionName = Dart.provideFunction_('lists_sort',
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
'
|
|
374
|
-
'
|
|
375
|
-
'
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
380
|
+
const sortFunctionName = Dart.provideFunction_('lists_sort', `
|
|
381
|
+
List ${Dart.FUNCTION_NAME_PLACEHOLDER_}(List list, String type, int direction) {
|
|
382
|
+
var compareFuncs = {
|
|
383
|
+
'NUMERIC': (a, b) => (direction * a.compareTo(b)).toInt(),
|
|
384
|
+
'TEXT': (a, b) => direction * a.toString().compareTo(b.toString()),
|
|
385
|
+
'IGNORE_CASE':
|
|
386
|
+
(a, b) => direction *
|
|
387
|
+
a.toString().toLowerCase().compareTo(b.toString().toLowerCase())
|
|
388
|
+
};
|
|
389
|
+
list = new List.from(list);
|
|
390
|
+
var compare = compareFuncs[type];
|
|
391
|
+
list.sort(compare);
|
|
392
|
+
return list;
|
|
393
|
+
}
|
|
394
|
+
`);
|
|
384
395
|
return [
|
|
385
396
|
sortFunctionName + '(' + list + ', ' +
|
|
386
397
|
'"' + type + '", ' + direction + ')',
|
|
@@ -391,12 +402,12 @@ Dart['lists_sort'] = function(block) {
|
|
|
391
402
|
Dart['lists_split'] = function(block) {
|
|
392
403
|
// Block for splitting text into a list, or joining a list into text.
|
|
393
404
|
let input = Dart.valueToCode(block, 'INPUT', Dart.ORDER_UNARY_POSTFIX);
|
|
394
|
-
const delimiter = Dart.valueToCode(block, 'DELIM', Dart.ORDER_NONE) || '
|
|
405
|
+
const delimiter = Dart.valueToCode(block, 'DELIM', Dart.ORDER_NONE) || "''";
|
|
395
406
|
const mode = block.getFieldValue('MODE');
|
|
396
407
|
let functionName;
|
|
397
408
|
if (mode === 'SPLIT') {
|
|
398
409
|
if (!input) {
|
|
399
|
-
input = '
|
|
410
|
+
input = "''";
|
|
400
411
|
}
|
|
401
412
|
functionName = 'split';
|
|
402
413
|
} else if (mode === 'JOIN') {
|