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
|
@@ -19,13 +19,13 @@ const common = goog.require('Blockly.common');
|
|
|
19
19
|
const dom = goog.require('Blockly.utils.dom');
|
|
20
20
|
const eventUtils = goog.require('Blockly.Events.utils');
|
|
21
21
|
const internalConstants = goog.require('Blockly.internalConstants');
|
|
22
|
-
const object = goog.require('Blockly.utils.object');
|
|
23
22
|
const svgPaths = goog.require('Blockly.utils.svgPaths');
|
|
24
23
|
const svgMath = goog.require('Blockly.utils.svgMath');
|
|
25
24
|
/* eslint-disable-next-line no-unused-vars */
|
|
26
25
|
const {BlockSvg} = goog.requireType('Blockly.BlockSvg');
|
|
27
26
|
/* eslint-disable-next-line no-unused-vars */
|
|
28
27
|
const {Block} = goog.requireType('Blockly.Block');
|
|
28
|
+
const {config} = goog.require('Blockly.config');
|
|
29
29
|
/* eslint-disable-next-line no-unused-vars */
|
|
30
30
|
const {ConnectionDB} = goog.requireType('Blockly.ConnectionDB');
|
|
31
31
|
const {ConnectionType} = goog.require('Blockly.ConnectionType');
|
|
@@ -34,536 +34,555 @@ const {Coordinate} = goog.require('Blockly.utils.Coordinate');
|
|
|
34
34
|
const {Svg} = goog.require('Blockly.utils.Svg');
|
|
35
35
|
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Maximum randomness in workspace units for bumping a block.
|
|
39
|
+
* @const
|
|
40
|
+
*/
|
|
41
|
+
const BUMP_RANDOMNESS = 10;
|
|
42
|
+
|
|
37
43
|
/**
|
|
38
44
|
* Class for a connection between blocks that may be rendered on screen.
|
|
39
|
-
* @param {!BlockSvg} source The block establishing this connection.
|
|
40
|
-
* @param {number} type The type of the connection.
|
|
41
45
|
* @extends {Connection}
|
|
42
|
-
* @constructor
|
|
43
46
|
* @alias Blockly.RenderedConnection
|
|
44
47
|
*/
|
|
45
|
-
|
|
46
|
-
RenderedConnection.superClass_.constructor.call(this, source, type);
|
|
47
|
-
|
|
48
|
+
class RenderedConnection extends Connection {
|
|
48
49
|
/**
|
|
49
|
-
*
|
|
50
|
-
* @
|
|
51
|
-
* @private
|
|
50
|
+
* @param {!BlockSvg} source The block establishing this connection.
|
|
51
|
+
* @param {number} type The type of the connection.
|
|
52
52
|
*/
|
|
53
|
-
|
|
53
|
+
constructor(source, type) {
|
|
54
|
+
super(source, type);
|
|
55
|
+
|
|
56
|
+
/** @type {!BlockSvg} */
|
|
57
|
+
this.sourceBlock_;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Connection database for connections of this type on the current
|
|
61
|
+
* workspace.
|
|
62
|
+
* @const {!ConnectionDB}
|
|
63
|
+
* @private
|
|
64
|
+
*/
|
|
65
|
+
this.db_ = source.workspace.connectionDBList[type];
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Connection database for connections compatible with this type on the
|
|
69
|
+
* current workspace.
|
|
70
|
+
* @const {!ConnectionDB}
|
|
71
|
+
* @private
|
|
72
|
+
*/
|
|
73
|
+
this.dbOpposite_ =
|
|
74
|
+
source.workspace
|
|
75
|
+
.connectionDBList[internalConstants.OPPOSITE_TYPE[type]];
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Workspace units, (0, 0) is top left of block.
|
|
79
|
+
* @type {!Coordinate}
|
|
80
|
+
* @private
|
|
81
|
+
*/
|
|
82
|
+
this.offsetInBlock_ = new Coordinate(0, 0);
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Describes the state of this connection's tracked-ness.
|
|
86
|
+
* @type {RenderedConnection.TrackedState}
|
|
87
|
+
* @private
|
|
88
|
+
*/
|
|
89
|
+
this.trackedState_ = RenderedConnection.TrackedState.WILL_TRACK;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Connection this connection connects to. Null if not connected.
|
|
93
|
+
* @type {RenderedConnection}
|
|
94
|
+
*/
|
|
95
|
+
this.targetConnection = null;
|
|
96
|
+
}
|
|
54
97
|
|
|
55
98
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* @
|
|
59
|
-
* @
|
|
99
|
+
* Dispose of this connection. Remove it from the database (if it is
|
|
100
|
+
* tracked) and call the super-function to deal with connected blocks.
|
|
101
|
+
* @override
|
|
102
|
+
* @package
|
|
60
103
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
104
|
+
dispose() {
|
|
105
|
+
super.dispose();
|
|
106
|
+
if (this.trackedState_ === RenderedConnection.TrackedState.TRACKED) {
|
|
107
|
+
this.db_.removeConnection(this, this.y);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
63
110
|
|
|
64
111
|
/**
|
|
65
|
-
*
|
|
66
|
-
* @
|
|
67
|
-
* @
|
|
112
|
+
* Get the source block for this connection.
|
|
113
|
+
* @return {!BlockSvg} The source block.
|
|
114
|
+
* @override
|
|
68
115
|
*/
|
|
69
|
-
|
|
116
|
+
getSourceBlock() {
|
|
117
|
+
return /** @type {!BlockSvg} */ (super.getSourceBlock());
|
|
118
|
+
}
|
|
70
119
|
|
|
71
120
|
/**
|
|
72
|
-
*
|
|
73
|
-
* @
|
|
74
|
-
* @
|
|
121
|
+
* Returns the block that this connection connects to.
|
|
122
|
+
* @return {?BlockSvg} The connected block or null if none is connected.
|
|
123
|
+
* @override
|
|
75
124
|
*/
|
|
76
|
-
|
|
125
|
+
targetBlock() {
|
|
126
|
+
return /** @type {BlockSvg} */ (super.targetBlock());
|
|
127
|
+
}
|
|
77
128
|
|
|
78
129
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
130
|
+
* Returns the distance between this connection and another connection in
|
|
131
|
+
* workspace units.
|
|
132
|
+
* @param {!Connection} otherConnection The other connection to measure
|
|
133
|
+
* the distance to.
|
|
134
|
+
* @return {number} The distance between connections, in workspace units.
|
|
81
135
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Enum for different kinds of tracked states.
|
|
88
|
-
*
|
|
89
|
-
* WILL_TRACK means that this connection will add itself to
|
|
90
|
-
* the db on the next moveTo call it receives.
|
|
91
|
-
*
|
|
92
|
-
* UNTRACKED means that this connection will not add
|
|
93
|
-
* itself to the database until setTracking(true) is explicitly called.
|
|
94
|
-
*
|
|
95
|
-
* TRACKED means that this connection is currently being tracked.
|
|
96
|
-
* @enum {number}
|
|
97
|
-
*/
|
|
98
|
-
RenderedConnection.TrackedState = {
|
|
99
|
-
WILL_TRACK: -1,
|
|
100
|
-
UNTRACKED: 0,
|
|
101
|
-
TRACKED: 1,
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Dispose of this connection. Remove it from the database (if it is
|
|
106
|
-
* tracked) and call the super-function to deal with connected blocks.
|
|
107
|
-
* @override
|
|
108
|
-
* @package
|
|
109
|
-
*/
|
|
110
|
-
RenderedConnection.prototype.dispose = function() {
|
|
111
|
-
RenderedConnection.superClass_.dispose.call(this);
|
|
112
|
-
if (this.trackedState_ === RenderedConnection.TrackedState.TRACKED) {
|
|
113
|
-
this.db_.removeConnection(this, this.y);
|
|
136
|
+
distanceFrom(otherConnection) {
|
|
137
|
+
const xDiff = this.x - otherConnection.x;
|
|
138
|
+
const yDiff = this.y - otherConnection.y;
|
|
139
|
+
return Math.sqrt(xDiff * xDiff + yDiff * yDiff);
|
|
114
140
|
}
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Get the source block for this connection.
|
|
119
|
-
* @return {!BlockSvg} The source block.
|
|
120
|
-
* @override
|
|
121
|
-
*/
|
|
122
|
-
RenderedConnection.prototype.getSourceBlock = function() {
|
|
123
|
-
return /** @type {!BlockSvg} */ (
|
|
124
|
-
RenderedConnection.superClass_.getSourceBlock.call(this));
|
|
125
|
-
};
|
|
126
141
|
|
|
127
|
-
/**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Returns the distance between this connection and another connection in
|
|
139
|
-
* workspace units.
|
|
140
|
-
* @param {!Connection} otherConnection The other connection to measure
|
|
141
|
-
* the distance to.
|
|
142
|
-
* @return {number} The distance between connections, in workspace units.
|
|
143
|
-
*/
|
|
144
|
-
RenderedConnection.prototype.distanceFrom = function(otherConnection) {
|
|
145
|
-
const xDiff = this.x - otherConnection.x;
|
|
146
|
-
const yDiff = this.y - otherConnection.y;
|
|
147
|
-
return Math.sqrt(xDiff * xDiff + yDiff * yDiff);
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Move the block(s) belonging to the connection to a point where they don't
|
|
152
|
-
* visually interfere with the specified connection.
|
|
153
|
-
* @param {!Connection} staticConnection The connection to move away
|
|
154
|
-
* from.
|
|
155
|
-
* @package
|
|
156
|
-
*/
|
|
157
|
-
RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) {
|
|
158
|
-
if (this.sourceBlock_.workspace.isDragging()) {
|
|
159
|
-
// Don't move blocks around while the user is doing the same.
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
// Move the root block.
|
|
163
|
-
let rootBlock = this.sourceBlock_.getRootBlock();
|
|
164
|
-
if (rootBlock.isInFlyout) {
|
|
165
|
-
// Don't move blocks around in a flyout.
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
let reverse = false;
|
|
169
|
-
if (!rootBlock.isMovable()) {
|
|
170
|
-
// Can't bump an uneditable block away.
|
|
171
|
-
// Check to see if the other block is movable.
|
|
172
|
-
rootBlock = staticConnection.getSourceBlock().getRootBlock();
|
|
173
|
-
if (!rootBlock.isMovable()) {
|
|
142
|
+
/**
|
|
143
|
+
* Move the block(s) belonging to the connection to a point where they don't
|
|
144
|
+
* visually interfere with the specified connection.
|
|
145
|
+
* @param {!RenderedConnection} staticConnection The connection to move away
|
|
146
|
+
* from.
|
|
147
|
+
* @package
|
|
148
|
+
*/
|
|
149
|
+
bumpAwayFrom(staticConnection) {
|
|
150
|
+
if (this.sourceBlock_.workspace.isDragging()) {
|
|
151
|
+
// Don't move blocks around while the user is doing the same.
|
|
174
152
|
return;
|
|
175
153
|
}
|
|
176
|
-
//
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
154
|
+
// Move the root block.
|
|
155
|
+
let rootBlock = this.sourceBlock_.getRootBlock();
|
|
156
|
+
if (rootBlock.isInFlyout) {
|
|
157
|
+
// Don't move blocks around in a flyout.
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
let reverse = false;
|
|
161
|
+
if (!rootBlock.isMovable()) {
|
|
162
|
+
// Can't bump an uneditable block away.
|
|
163
|
+
// Check to see if the other block is movable.
|
|
164
|
+
rootBlock = staticConnection.getSourceBlock().getRootBlock();
|
|
165
|
+
if (!rootBlock.isMovable()) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
// Swap the connections and move the 'static' connection instead.
|
|
169
|
+
staticConnection = this;
|
|
170
|
+
reverse = true;
|
|
171
|
+
}
|
|
172
|
+
// Raise it to the top for extra visibility.
|
|
173
|
+
const selected = common.getSelected() == rootBlock;
|
|
174
|
+
selected || rootBlock.addSelect();
|
|
175
|
+
let dx = (staticConnection.x + config.snapRadius +
|
|
176
|
+
Math.floor(Math.random() * BUMP_RANDOMNESS)) -
|
|
196
177
|
this.x;
|
|
178
|
+
let dy = (staticConnection.y + config.snapRadius +
|
|
179
|
+
Math.floor(Math.random() * BUMP_RANDOMNESS)) -
|
|
180
|
+
this.y;
|
|
181
|
+
if (reverse) {
|
|
182
|
+
// When reversing a bump due to an uneditable block, bump up.
|
|
183
|
+
dy = -dy;
|
|
184
|
+
}
|
|
185
|
+
if (rootBlock.RTL) {
|
|
186
|
+
dx = (staticConnection.x - config.snapRadius -
|
|
187
|
+
Math.floor(Math.random() * BUMP_RANDOMNESS)) -
|
|
188
|
+
this.x;
|
|
189
|
+
}
|
|
190
|
+
rootBlock.moveBy(dx, dy);
|
|
191
|
+
selected || rootBlock.removeSelect();
|
|
197
192
|
}
|
|
198
|
-
rootBlock.moveBy(dx, dy);
|
|
199
|
-
selected || rootBlock.removeSelect();
|
|
200
|
-
};
|
|
201
193
|
|
|
202
|
-
/**
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
194
|
+
/**
|
|
195
|
+
* Change the connection's coordinates.
|
|
196
|
+
* @param {number} x New absolute x coordinate, in workspace coordinates.
|
|
197
|
+
* @param {number} y New absolute y coordinate, in workspace coordinates.
|
|
198
|
+
*/
|
|
199
|
+
moveTo(x, y) {
|
|
200
|
+
if (this.trackedState_ === RenderedConnection.TrackedState.WILL_TRACK) {
|
|
201
|
+
this.db_.addConnection(this, y);
|
|
202
|
+
this.trackedState_ = RenderedConnection.TrackedState.TRACKED;
|
|
203
|
+
} else if (this.trackedState_ === RenderedConnection.TrackedState.TRACKED) {
|
|
204
|
+
this.db_.removeConnection(this, this.y);
|
|
205
|
+
this.db_.addConnection(this, y);
|
|
206
|
+
}
|
|
207
|
+
this.x = x;
|
|
208
|
+
this.y = y;
|
|
214
209
|
}
|
|
215
|
-
this.x = x;
|
|
216
|
-
this.y = y;
|
|
217
|
-
};
|
|
218
210
|
|
|
219
|
-
/**
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
211
|
+
/**
|
|
212
|
+
* Change the connection's coordinates.
|
|
213
|
+
* @param {number} dx Change to x coordinate, in workspace units.
|
|
214
|
+
* @param {number} dy Change to y coordinate, in workspace units.
|
|
215
|
+
*/
|
|
216
|
+
moveBy(dx, dy) {
|
|
217
|
+
this.moveTo(this.x + dx, this.y + dy);
|
|
218
|
+
}
|
|
227
219
|
|
|
228
|
-
/**
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
220
|
+
/**
|
|
221
|
+
* Move this connection to the location given by its offset within the block
|
|
222
|
+
* and the location of the block's top left corner.
|
|
223
|
+
* @param {!Coordinate} blockTL The location of the top left
|
|
224
|
+
* corner of the block, in workspace coordinates.
|
|
225
|
+
*/
|
|
226
|
+
moveToOffset(blockTL) {
|
|
227
|
+
this.moveTo(
|
|
228
|
+
blockTL.x + this.offsetInBlock_.x, blockTL.y + this.offsetInBlock_.y);
|
|
229
|
+
}
|
|
238
230
|
|
|
239
|
-
/**
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
}
|
|
231
|
+
/**
|
|
232
|
+
* Set the offset of this connection relative to the top left of its block.
|
|
233
|
+
* @param {number} x The new relative x, in workspace units.
|
|
234
|
+
* @param {number} y The new relative y, in workspace units.
|
|
235
|
+
*/
|
|
236
|
+
setOffsetInBlock(x, y) {
|
|
237
|
+
this.offsetInBlock_.x = x;
|
|
238
|
+
this.offsetInBlock_.y = y;
|
|
239
|
+
}
|
|
248
240
|
|
|
249
|
-
/**
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
241
|
+
/**
|
|
242
|
+
* Get the offset of this connection relative to the top left of its block.
|
|
243
|
+
* @return {!Coordinate} The offset of the connection.
|
|
244
|
+
* @package
|
|
245
|
+
*/
|
|
246
|
+
getOffsetInBlock() {
|
|
247
|
+
return this.offsetInBlock_;
|
|
248
|
+
}
|
|
257
249
|
|
|
258
|
-
/**
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
250
|
+
/**
|
|
251
|
+
* Move the blocks on either side of this connection right next to each other.
|
|
252
|
+
* @package
|
|
253
|
+
*/
|
|
254
|
+
tighten() {
|
|
255
|
+
const dx = this.targetConnection.x - this.x;
|
|
256
|
+
const dy = this.targetConnection.y - this.y;
|
|
257
|
+
if (dx !== 0 || dy !== 0) {
|
|
258
|
+
const block = this.targetBlock();
|
|
259
|
+
const svgRoot = block.getSvgRoot();
|
|
260
|
+
if (!svgRoot) {
|
|
261
|
+
throw Error('block is not rendered.');
|
|
262
|
+
}
|
|
263
|
+
// Workspace coordinates.
|
|
264
|
+
const xy = svgMath.getRelativeXY(svgRoot);
|
|
265
|
+
block.getSvgRoot().setAttribute(
|
|
266
|
+
'transform', 'translate(' + (xy.x - dx) + ',' + (xy.y - dy) + ')');
|
|
267
|
+
block.moveConnections(-dx, -dy);
|
|
270
268
|
}
|
|
271
|
-
// Workspace coordinates.
|
|
272
|
-
const xy = svgMath.getRelativeXY(svgRoot);
|
|
273
|
-
block.getSvgRoot().setAttribute(
|
|
274
|
-
'transform', 'translate(' + (xy.x - dx) + ',' + (xy.y - dy) + ')');
|
|
275
|
-
block.moveConnections(-dx, -dy);
|
|
276
269
|
}
|
|
277
|
-
};
|
|
278
270
|
|
|
279
|
-
/**
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* Add highlighting around this connection.
|
|
295
|
-
*/
|
|
296
|
-
RenderedConnection.prototype.highlight = function() {
|
|
297
|
-
let steps;
|
|
298
|
-
const sourceBlockSvg = /** @type {!BlockSvg} */ (this.sourceBlock_);
|
|
299
|
-
const renderConstants = sourceBlockSvg.workspace.getRenderer().getConstants();
|
|
300
|
-
const shape = renderConstants.shapeFor(this);
|
|
301
|
-
if (this.type === ConnectionType.INPUT_VALUE ||
|
|
302
|
-
this.type === ConnectionType.OUTPUT_VALUE) {
|
|
303
|
-
// Vertical line, puzzle tab, vertical line.
|
|
304
|
-
const yLen = renderConstants.TAB_OFFSET_FROM_TOP;
|
|
305
|
-
steps = svgPaths.moveBy(0, -yLen) + svgPaths.lineOnAxis('v', yLen) +
|
|
306
|
-
shape.pathDown + svgPaths.lineOnAxis('v', yLen);
|
|
307
|
-
} else {
|
|
308
|
-
const xLen =
|
|
309
|
-
renderConstants.NOTCH_OFFSET_LEFT - renderConstants.CORNER_RADIUS;
|
|
310
|
-
// Horizontal line, notch, horizontal line.
|
|
311
|
-
steps = svgPaths.moveBy(-xLen, 0) + svgPaths.lineOnAxis('h', xLen) +
|
|
312
|
-
shape.pathLeft + svgPaths.lineOnAxis('h', xLen);
|
|
271
|
+
/**
|
|
272
|
+
* Find the closest compatible connection to this connection.
|
|
273
|
+
* All parameters are in workspace units.
|
|
274
|
+
* @param {number} maxLimit The maximum radius to another connection.
|
|
275
|
+
* @param {!Coordinate} dxy Offset between this connection's location
|
|
276
|
+
* in the database and the current location (as a result of dragging).
|
|
277
|
+
* @return {!{connection: ?Connection, radius: number}} Contains two
|
|
278
|
+
* properties: 'connection' which is either another connection or null,
|
|
279
|
+
* and 'radius' which is the distance.
|
|
280
|
+
*/
|
|
281
|
+
closest(maxLimit, dxy) {
|
|
282
|
+
return this.dbOpposite_.searchForClosest(this, maxLimit, dxy);
|
|
313
283
|
}
|
|
314
|
-
const xy = this.sourceBlock_.getRelativeToSurfaceXY();
|
|
315
|
-
const x = this.x - xy.x;
|
|
316
|
-
const y = this.y - xy.y;
|
|
317
|
-
Connection.highlightedPath_ = dom.createSvgElement(
|
|
318
|
-
Svg.PATH, {
|
|
319
|
-
'class': 'blocklyHighlightedConnectionPath',
|
|
320
|
-
'd': steps,
|
|
321
|
-
'transform': 'translate(' + x + ',' + y + ')' +
|
|
322
|
-
(this.sourceBlock_.RTL ? ' scale(-1 1)' : ''),
|
|
323
|
-
},
|
|
324
|
-
this.sourceBlock_.getSvgRoot());
|
|
325
|
-
};
|
|
326
284
|
|
|
327
|
-
/**
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
285
|
+
/**
|
|
286
|
+
* Add highlighting around this connection.
|
|
287
|
+
*/
|
|
288
|
+
highlight() {
|
|
289
|
+
let steps;
|
|
290
|
+
const sourceBlockSvg = /** @type {!BlockSvg} */ (this.sourceBlock_);
|
|
291
|
+
const renderConstants =
|
|
292
|
+
sourceBlockSvg.workspace.getRenderer().getConstants();
|
|
293
|
+
const shape = renderConstants.shapeFor(this);
|
|
294
|
+
if (this.type === ConnectionType.INPUT_VALUE ||
|
|
295
|
+
this.type === ConnectionType.OUTPUT_VALUE) {
|
|
296
|
+
// Vertical line, puzzle tab, vertical line.
|
|
297
|
+
const yLen = renderConstants.TAB_OFFSET_FROM_TOP;
|
|
298
|
+
steps = svgPaths.moveBy(0, -yLen) + svgPaths.lineOnAxis('v', yLen) +
|
|
299
|
+
shape.pathDown + svgPaths.lineOnAxis('v', yLen);
|
|
300
|
+
} else {
|
|
301
|
+
const xLen =
|
|
302
|
+
renderConstants.NOTCH_OFFSET_LEFT - renderConstants.CORNER_RADIUS;
|
|
303
|
+
// Horizontal line, notch, horizontal line.
|
|
304
|
+
steps = svgPaths.moveBy(-xLen, 0) + svgPaths.lineOnAxis('h', xLen) +
|
|
305
|
+
shape.pathLeft + svgPaths.lineOnAxis('h', xLen);
|
|
306
|
+
}
|
|
307
|
+
const xy = this.sourceBlock_.getRelativeToSurfaceXY();
|
|
308
|
+
const x = this.x - xy.x;
|
|
309
|
+
const y = this.y - xy.y;
|
|
310
|
+
Connection.highlightedPath_ = dom.createSvgElement(
|
|
311
|
+
Svg.PATH, {
|
|
312
|
+
'class': 'blocklyHighlightedConnectionPath',
|
|
313
|
+
'd': steps,
|
|
314
|
+
'transform': 'translate(' + x + ',' + y + ')' +
|
|
315
|
+
(this.sourceBlock_.RTL ? ' scale(-1 1)' : ''),
|
|
316
|
+
},
|
|
317
|
+
this.sourceBlock_.getSvgRoot());
|
|
350
318
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Remove the highlighting around this connection.
|
|
322
|
+
*/
|
|
323
|
+
unhighlight() {
|
|
324
|
+
dom.removeNode(Connection.highlightedPath_);
|
|
325
|
+
delete Connection.highlightedPath_;
|
|
355
326
|
}
|
|
356
|
-
|
|
357
|
-
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Set whether this connections is tracked in the database or not.
|
|
330
|
+
* @param {boolean} doTracking If true, start tracking. If false, stop
|
|
331
|
+
* tracking.
|
|
332
|
+
* @package
|
|
333
|
+
*/
|
|
334
|
+
setTracking(doTracking) {
|
|
335
|
+
if ((doTracking &&
|
|
336
|
+
this.trackedState_ === RenderedConnection.TrackedState.TRACKED) ||
|
|
337
|
+
(!doTracking &&
|
|
338
|
+
this.trackedState_ === RenderedConnection.TrackedState.UNTRACKED)) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (this.sourceBlock_.isInFlyout) {
|
|
342
|
+
// Don't bother maintaining a database of connections in a flyout.
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (doTracking) {
|
|
346
|
+
this.db_.addConnection(this, this.y);
|
|
347
|
+
this.trackedState_ = RenderedConnection.TrackedState.TRACKED;
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
if (this.trackedState_ === RenderedConnection.TrackedState.TRACKED) {
|
|
351
|
+
this.db_.removeConnection(this, this.y);
|
|
352
|
+
}
|
|
353
|
+
this.trackedState_ = RenderedConnection.TrackedState.UNTRACKED;
|
|
358
354
|
}
|
|
359
|
-
this.trackedState_ = RenderedConnection.TrackedState.UNTRACKED;
|
|
360
|
-
};
|
|
361
355
|
|
|
362
|
-
/**
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
icons
|
|
356
|
+
/**
|
|
357
|
+
* Stop tracking this connection, as well as all down-stream connections on
|
|
358
|
+
* any block attached to this connection. This happens when a block is
|
|
359
|
+
* collapsed.
|
|
360
|
+
*
|
|
361
|
+
* Also closes down-stream icons/bubbles.
|
|
362
|
+
* @package
|
|
363
|
+
*/
|
|
364
|
+
stopTrackingAll() {
|
|
365
|
+
this.setTracking(false);
|
|
366
|
+
if (this.targetConnection) {
|
|
367
|
+
const blocks = this.targetBlock().getDescendants(false);
|
|
368
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
369
|
+
const block = blocks[i];
|
|
370
|
+
// Stop tracking connections of all children.
|
|
371
|
+
const connections = block.getConnections_(true);
|
|
372
|
+
for (let j = 0; j < connections.length; j++) {
|
|
373
|
+
/** @type {!RenderedConnection} */ (connections[j])
|
|
374
|
+
.setTracking(false);
|
|
375
|
+
}
|
|
376
|
+
// Close all bubbles of all children.
|
|
377
|
+
const icons = block.getIcons();
|
|
378
|
+
for (let j = 0; j < icons.length; j++) {
|
|
379
|
+
icons[j].setVisible(false);
|
|
380
|
+
}
|
|
385
381
|
}
|
|
386
382
|
}
|
|
387
383
|
}
|
|
388
|
-
};
|
|
389
384
|
|
|
390
|
-
/**
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
const block = this.targetBlock();
|
|
408
|
-
if (block) {
|
|
409
|
-
let connections;
|
|
410
|
-
if (block.isCollapsed()) {
|
|
411
|
-
// This block should only be partially revealed since it is collapsed.
|
|
412
|
-
connections = [];
|
|
413
|
-
block.outputConnection && connections.push(block.outputConnection);
|
|
414
|
-
block.nextConnection && connections.push(block.nextConnection);
|
|
415
|
-
block.previousConnection && connections.push(block.previousConnection);
|
|
416
|
-
} else {
|
|
417
|
-
// Show all connections of this block.
|
|
418
|
-
connections = block.getConnections_(true);
|
|
385
|
+
/**
|
|
386
|
+
* Start tracking this connection, as well as all down-stream connections on
|
|
387
|
+
* any block attached to this connection. This happens when a block is
|
|
388
|
+
* expanded.
|
|
389
|
+
* @return {!Array<!Block>} List of blocks to render.
|
|
390
|
+
*/
|
|
391
|
+
startTrackingAll() {
|
|
392
|
+
this.setTracking(true);
|
|
393
|
+
// All blocks that are not tracked must start tracking before any
|
|
394
|
+
// rendering takes place, since rendering requires knowing the dimensions
|
|
395
|
+
// of lower blocks. Also, since rendering a block renders all its parents,
|
|
396
|
+
// we only need to render the leaf nodes.
|
|
397
|
+
let renderList = [];
|
|
398
|
+
if (this.type !== ConnectionType.INPUT_VALUE &&
|
|
399
|
+
this.type !== ConnectionType.NEXT_STATEMENT) {
|
|
400
|
+
// Only spider down.
|
|
401
|
+
return renderList;
|
|
419
402
|
}
|
|
420
|
-
|
|
421
|
-
|
|
403
|
+
const block = this.targetBlock();
|
|
404
|
+
if (block) {
|
|
405
|
+
let connections;
|
|
406
|
+
if (block.isCollapsed()) {
|
|
407
|
+
// This block should only be partially revealed since it is collapsed.
|
|
408
|
+
connections = [];
|
|
409
|
+
block.outputConnection && connections.push(block.outputConnection);
|
|
410
|
+
block.nextConnection && connections.push(block.nextConnection);
|
|
411
|
+
block.previousConnection && connections.push(block.previousConnection);
|
|
412
|
+
} else {
|
|
413
|
+
// Show all connections of this block.
|
|
414
|
+
connections = block.getConnections_(true);
|
|
415
|
+
}
|
|
416
|
+
for (let i = 0; i < connections.length; i++) {
|
|
417
|
+
renderList.push.apply(renderList, connections[i].startTrackingAll());
|
|
418
|
+
}
|
|
419
|
+
if (!renderList.length) {
|
|
420
|
+
// Leaf block.
|
|
421
|
+
renderList = [block];
|
|
422
|
+
}
|
|
422
423
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
424
|
+
return renderList;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Behavior after a connection attempt fails.
|
|
429
|
+
* Bumps this connection away from the other connection. Called when an
|
|
430
|
+
* attempted connection fails.
|
|
431
|
+
* @param {!Connection} otherConnection Connection that this connection
|
|
432
|
+
* failed to connect to.
|
|
433
|
+
* @package
|
|
434
|
+
*/
|
|
435
|
+
onFailedConnect(otherConnection) {
|
|
436
|
+
const block = this.getSourceBlock();
|
|
437
|
+
if (eventUtils.getRecordUndo()) {
|
|
438
|
+
const group = eventUtils.getGroup();
|
|
439
|
+
setTimeout(function() {
|
|
440
|
+
if (!block.isDisposed() && !block.getParent()) {
|
|
441
|
+
eventUtils.setGroup(group);
|
|
442
|
+
this.bumpAwayFrom(
|
|
443
|
+
/** @type {!RenderedConnection} */ (otherConnection));
|
|
444
|
+
eventUtils.setGroup(false);
|
|
445
|
+
}
|
|
446
|
+
}.bind(this), config.bumpDelay);
|
|
426
447
|
}
|
|
427
448
|
}
|
|
428
|
-
return renderList;
|
|
429
|
-
};
|
|
430
449
|
|
|
431
|
-
/**
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
+
/**
|
|
451
|
+
* Disconnect two blocks that are connected by this connection.
|
|
452
|
+
* @param {!Block} parentBlock The superior block.
|
|
453
|
+
* @param {!Block} childBlock The inferior block.
|
|
454
|
+
* @protected
|
|
455
|
+
* @override
|
|
456
|
+
*/
|
|
457
|
+
disconnectInternal_(parentBlock, childBlock) {
|
|
458
|
+
super.disconnectInternal_(parentBlock, childBlock);
|
|
459
|
+
const renderedParent = /** @type {!BlockSvg} */ (parentBlock);
|
|
460
|
+
const renderedChild = /** @type {!BlockSvg} */ (childBlock);
|
|
461
|
+
|
|
462
|
+
// Rerender the parent so that it may reflow.
|
|
463
|
+
if (renderedParent.rendered) {
|
|
464
|
+
renderedParent.render();
|
|
465
|
+
}
|
|
466
|
+
if (renderedChild.rendered) {
|
|
467
|
+
renderedChild.updateDisabled();
|
|
468
|
+
renderedChild.render();
|
|
469
|
+
// Reset visibility, since the child is now a top block.
|
|
470
|
+
renderedChild.getSvgRoot().style.display = 'block';
|
|
471
|
+
}
|
|
450
472
|
}
|
|
451
|
-
};
|
|
452
473
|
|
|
474
|
+
/**
|
|
475
|
+
* Respawn the shadow block if there was one connected to the this connection.
|
|
476
|
+
* Render/rerender blocks as needed.
|
|
477
|
+
* @protected
|
|
478
|
+
* @override
|
|
479
|
+
*/
|
|
480
|
+
respawnShadow_() {
|
|
481
|
+
super.respawnShadow_();
|
|
482
|
+
const blockShadow = this.targetBlock();
|
|
483
|
+
if (!blockShadow) {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
blockShadow.initSvg();
|
|
487
|
+
blockShadow.render(false);
|
|
453
488
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
* @protected
|
|
459
|
-
* @override
|
|
460
|
-
*/
|
|
461
|
-
RenderedConnection.prototype.disconnectInternal_ = function(
|
|
462
|
-
parentBlock, childBlock) {
|
|
463
|
-
RenderedConnection.superClass_.disconnectInternal_.call(
|
|
464
|
-
this, parentBlock, childBlock);
|
|
465
|
-
// Rerender the parent so that it may reflow.
|
|
466
|
-
if (parentBlock.rendered) {
|
|
467
|
-
parentBlock.render();
|
|
468
|
-
}
|
|
469
|
-
if (childBlock.rendered) {
|
|
470
|
-
childBlock.updateDisabled();
|
|
471
|
-
childBlock.render();
|
|
472
|
-
// Reset visibility, since the child is now a top block.
|
|
473
|
-
childBlock.getSvgRoot().style.display = 'block';
|
|
489
|
+
const parentBlock = this.getSourceBlock();
|
|
490
|
+
if (parentBlock.rendered) {
|
|
491
|
+
parentBlock.render();
|
|
492
|
+
}
|
|
474
493
|
}
|
|
475
|
-
};
|
|
476
494
|
|
|
477
|
-
/**
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
return;
|
|
495
|
+
/**
|
|
496
|
+
* Find all nearby compatible connections to this connection.
|
|
497
|
+
* Type checking does not apply, since this function is used for bumping.
|
|
498
|
+
* @param {number} maxLimit The maximum radius to another connection, in
|
|
499
|
+
* workspace units.
|
|
500
|
+
* @return {!Array<!Connection>} List of connections.
|
|
501
|
+
* @package
|
|
502
|
+
*/
|
|
503
|
+
neighbours(maxLimit) {
|
|
504
|
+
return this.dbOpposite_.getNeighbours(this, maxLimit);
|
|
488
505
|
}
|
|
489
|
-
blockShadow.initSvg();
|
|
490
|
-
blockShadow.render(false);
|
|
491
506
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
507
|
+
/**
|
|
508
|
+
* Connect two connections together. This is the connection on the superior
|
|
509
|
+
* block. Rerender blocks as needed.
|
|
510
|
+
* @param {!Connection} childConnection Connection on inferior block.
|
|
511
|
+
* @protected
|
|
512
|
+
*/
|
|
513
|
+
connect_(childConnection) {
|
|
514
|
+
super.connect_(childConnection);
|
|
497
515
|
|
|
498
|
-
/**
|
|
499
|
-
|
|
500
|
-
* Type checking does not apply, since this function is used for bumping.
|
|
501
|
-
* @param {number} maxLimit The maximum radius to another connection, in
|
|
502
|
-
* workspace units.
|
|
503
|
-
* @return {!Array<!Connection>} List of connections.
|
|
504
|
-
* @package
|
|
505
|
-
*/
|
|
506
|
-
RenderedConnection.prototype.neighbours = function(maxLimit) {
|
|
507
|
-
return this.dbOpposite_.getNeighbours(this, maxLimit);
|
|
508
|
-
};
|
|
516
|
+
const renderedChildConnection = /** @type {!RenderedConnection} */
|
|
517
|
+
(childConnection);
|
|
509
518
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
*/
|
|
516
|
-
RenderedConnection.prototype.connect_ = function(childConnection) {
|
|
517
|
-
RenderedConnection.superClass_.connect_.call(this, childConnection);
|
|
519
|
+
const parentConnection = this;
|
|
520
|
+
const parentBlock = parentConnection.getSourceBlock();
|
|
521
|
+
const childBlock = renderedChildConnection.getSourceBlock();
|
|
522
|
+
const parentRendered = parentBlock.rendered;
|
|
523
|
+
const childRendered = childBlock.rendered;
|
|
518
524
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
525
|
+
if (parentRendered) {
|
|
526
|
+
parentBlock.updateDisabled();
|
|
527
|
+
}
|
|
528
|
+
if (childRendered) {
|
|
529
|
+
childBlock.updateDisabled();
|
|
530
|
+
}
|
|
531
|
+
if (parentRendered && childRendered) {
|
|
532
|
+
if (parentConnection.type === ConnectionType.NEXT_STATEMENT ||
|
|
533
|
+
parentConnection.type === ConnectionType.PREVIOUS_STATEMENT) {
|
|
534
|
+
// Child block may need to square off its corners if it is in a stack.
|
|
535
|
+
// Rendering a child will render its parent.
|
|
536
|
+
childBlock.render();
|
|
537
|
+
} else {
|
|
538
|
+
// Child block does not change shape. Rendering the parent node will
|
|
539
|
+
// move its connected children into position.
|
|
540
|
+
parentBlock.render();
|
|
541
|
+
}
|
|
542
|
+
}
|
|
524
543
|
|
|
525
|
-
|
|
526
|
-
parentBlock.
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
}
|
|
531
|
-
if (parentRendered && childRendered) {
|
|
532
|
-
if (parentConnection.type === ConnectionType.NEXT_STATEMENT ||
|
|
533
|
-
parentConnection.type === ConnectionType.PREVIOUS_STATEMENT) {
|
|
534
|
-
// Child block may need to square off its corners if it is in a stack.
|
|
535
|
-
// Rendering a child will render its parent.
|
|
536
|
-
childBlock.render();
|
|
537
|
-
} else {
|
|
538
|
-
// Child block does not change shape. Rendering the parent node will
|
|
539
|
-
// move its connected children into position.
|
|
540
|
-
parentBlock.render();
|
|
544
|
+
// The input the child block is connected to (if any).
|
|
545
|
+
const parentInput = parentBlock.getInputWithBlock(childBlock);
|
|
546
|
+
if (parentInput) {
|
|
547
|
+
const visible = parentInput.isVisible();
|
|
548
|
+
childBlock.getSvgRoot().style.display = visible ? 'block' : 'none';
|
|
541
549
|
}
|
|
542
550
|
}
|
|
543
551
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
552
|
+
/**
|
|
553
|
+
* Function to be called when this connection's compatible types have changed.
|
|
554
|
+
* @protected
|
|
555
|
+
*/
|
|
556
|
+
onCheckChanged_() {
|
|
557
|
+
// The new value type may not be compatible with the existing connection.
|
|
558
|
+
if (this.isConnected() &&
|
|
559
|
+
(!this.targetConnection ||
|
|
560
|
+
!this.getConnectionChecker().canConnect(
|
|
561
|
+
this, this.targetConnection, false))) {
|
|
562
|
+
const child = this.isSuperior() ? this.targetBlock() : this.sourceBlock_;
|
|
563
|
+
child.unplug();
|
|
564
|
+
// Bump away.
|
|
565
|
+
this.sourceBlock_.bumpNeighbours();
|
|
566
|
+
}
|
|
549
567
|
}
|
|
550
|
-
}
|
|
568
|
+
}
|
|
551
569
|
|
|
552
570
|
/**
|
|
553
|
-
*
|
|
554
|
-
*
|
|
571
|
+
* Enum for different kinds of tracked states.
|
|
572
|
+
*
|
|
573
|
+
* WILL_TRACK means that this connection will add itself to
|
|
574
|
+
* the db on the next moveTo call it receives.
|
|
575
|
+
*
|
|
576
|
+
* UNTRACKED means that this connection will not add
|
|
577
|
+
* itself to the database until setTracking(true) is explicitly called.
|
|
578
|
+
*
|
|
579
|
+
* TRACKED means that this connection is currently being tracked.
|
|
580
|
+
* @enum {number}
|
|
555
581
|
*/
|
|
556
|
-
RenderedConnection.
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
!this.getConnectionChecker().canConnect(
|
|
561
|
-
this, this.targetConnection, false))) {
|
|
562
|
-
const child = this.isSuperior() ? this.targetBlock() : this.sourceBlock_;
|
|
563
|
-
child.unplug();
|
|
564
|
-
// Bump away.
|
|
565
|
-
this.sourceBlock_.bumpNeighbours();
|
|
566
|
-
}
|
|
582
|
+
RenderedConnection.TrackedState = {
|
|
583
|
+
WILL_TRACK: -1,
|
|
584
|
+
UNTRACKED: 0,
|
|
585
|
+
TRACKED: 1,
|
|
567
586
|
};
|
|
568
587
|
|
|
569
588
|
exports.RenderedConnection = RenderedConnection;
|