blockly 7.20211209.4 → 8.0.0

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.
Files changed (262) hide show
  1. package/blockly.d.ts +18963 -18432
  2. package/blockly.min.js +852 -844
  3. package/blockly_compressed.js +669 -664
  4. package/blockly_compressed.js.map +1 -1
  5. package/blocks/blocks.js +47 -0
  6. package/blocks/colour.js +13 -3
  7. package/blocks/lists.js +22 -13
  8. package/blocks/logic.js +13 -3
  9. package/blocks/loops.js +24 -11
  10. package/blocks/math.js +12 -3
  11. package/blocks/procedures.js +41 -27
  12. package/blocks/text.js +22 -13
  13. package/blocks/variables.js +14 -3
  14. package/blocks/variables_dynamic.js +13 -3
  15. package/blocks_compressed.js +146 -141
  16. package/blocks_compressed.js.map +1 -1
  17. package/core/block.js +1869 -1814
  18. package/core/block_drag_surface.js +201 -200
  19. package/core/block_dragger.js +377 -373
  20. package/core/block_svg.js +1593 -1479
  21. package/core/blockly.js +8 -22
  22. package/core/blocks.js +9 -2
  23. package/core/browser_events.js +22 -5
  24. package/core/bubble.js +841 -797
  25. package/core/bubble_dragger.js +213 -206
  26. package/core/bump_objects.js +2 -2
  27. package/core/clipboard.js +9 -9
  28. package/core/comment.js +353 -332
  29. package/core/common.js +46 -17
  30. package/core/component_manager.js +181 -174
  31. package/core/config.js +87 -0
  32. package/core/connection.js +595 -584
  33. package/core/connection_checker.js +242 -244
  34. package/core/connection_db.js +235 -230
  35. package/core/contextmenu.js +9 -6
  36. package/core/contextmenu_items.js +1 -2
  37. package/core/contextmenu_registry.js +93 -89
  38. package/core/css.js +474 -474
  39. package/core/delete_area.js +45 -42
  40. package/core/drag_target.js +57 -56
  41. package/core/dropdowndiv.js +153 -163
  42. package/core/events/events.js +2 -2
  43. package/core/events/events_abstract.js +89 -77
  44. package/core/events/events_block_base.js +37 -36
  45. package/core/events/events_block_change.js +130 -124
  46. package/core/events/events_block_create.js +73 -71
  47. package/core/events/events_block_delete.js +84 -82
  48. package/core/events/events_block_drag.js +50 -49
  49. package/core/events/events_block_move.js +147 -140
  50. package/core/events/events_bubble_open.js +51 -50
  51. package/core/events/events_click.js +48 -44
  52. package/core/events/events_comment_base.js +72 -69
  53. package/core/events/events_comment_change.js +63 -61
  54. package/core/events/events_comment_create.js +44 -42
  55. package/core/events/events_comment_delete.js +42 -40
  56. package/core/events/events_comment_move.js +106 -104
  57. package/core/events/events_marker_move.js +65 -64
  58. package/core/events/events_selected.js +46 -45
  59. package/core/events/events_theme_change.js +36 -35
  60. package/core/events/events_toolbox_item_select.js +46 -45
  61. package/core/events/events_trashcan_open.js +37 -36
  62. package/core/events/events_ui.js +47 -46
  63. package/core/events/events_ui_base.js +30 -29
  64. package/core/events/events_var_base.js +37 -36
  65. package/core/events/events_var_create.js +50 -48
  66. package/core/events/events_var_delete.js +50 -48
  67. package/core/events/events_var_rename.js +51 -49
  68. package/core/events/events_viewport.js +66 -65
  69. package/core/events/utils.js +29 -14
  70. package/core/events/workspace_events.js +49 -55
  71. package/core/extensions.js +4 -3
  72. package/core/field.js +1061 -997
  73. package/core/field_angle.js +462 -442
  74. package/core/field_checkbox.js +194 -182
  75. package/core/field_colour.js +519 -505
  76. package/core/field_dropdown.js +617 -598
  77. package/core/field_image.js +229 -220
  78. package/core/field_label.js +102 -91
  79. package/core/field_label_serializable.js +42 -41
  80. package/core/field_multilineinput.js +372 -358
  81. package/core/field_number.js +272 -253
  82. package/core/field_textinput.js +499 -467
  83. package/core/field_variable.js +458 -420
  84. package/core/flyout_base.js +1005 -952
  85. package/core/flyout_button.js +277 -260
  86. package/core/flyout_horizontal.js +304 -302
  87. package/core/flyout_metrics_manager.js +64 -64
  88. package/core/flyout_vertical.js +306 -300
  89. package/core/generator.js +459 -446
  90. package/core/gesture.js +829 -813
  91. package/core/grid.js +166 -163
  92. package/core/icon.js +168 -159
  93. package/core/inject.js +7 -5
  94. package/core/input.js +257 -248
  95. package/core/insertion_marker_manager.js +655 -624
  96. package/core/internal_constants.js +0 -129
  97. package/core/keyboard_nav/ast_node.js +605 -596
  98. package/core/keyboard_nav/basic_cursor.js +166 -165
  99. package/core/keyboard_nav/cursor.js +99 -97
  100. package/core/keyboard_nav/marker.js +83 -79
  101. package/core/keyboard_nav/tab_navigate_cursor.js +18 -23
  102. package/core/marker_manager.js +153 -141
  103. package/core/menu.js +377 -372
  104. package/core/menuitem.js +223 -217
  105. package/core/metrics_manager.js +403 -390
  106. package/core/mutator.js +468 -437
  107. package/core/names.js +229 -188
  108. package/core/options.js +290 -284
  109. package/core/procedures.js +29 -17
  110. package/core/registry.js +19 -16
  111. package/core/rendered_connection.js +482 -463
  112. package/core/renderers/common/block_rendering.js +9 -3
  113. package/core/renderers/common/constants.js +1119 -1112
  114. package/core/renderers/common/debug.js +14 -0
  115. package/core/renderers/common/debugger.js +338 -316
  116. package/core/renderers/common/drawer.js +380 -370
  117. package/core/renderers/common/i_path_object.js +2 -2
  118. package/core/renderers/common/info.js +626 -618
  119. package/core/renderers/common/marker_svg.js +579 -541
  120. package/core/renderers/common/path_object.js +203 -200
  121. package/core/renderers/common/renderer.js +220 -218
  122. package/core/renderers/geras/constants.js +36 -36
  123. package/core/renderers/geras/drawer.js +155 -147
  124. package/core/renderers/geras/highlight_constants.js +244 -238
  125. package/core/renderers/geras/highlighter.js +231 -179
  126. package/core/renderers/geras/info.js +392 -369
  127. package/core/renderers/geras/measurables/inline_input.js +25 -19
  128. package/core/renderers/geras/measurables/statement_input.js +23 -17
  129. package/core/renderers/geras/path_object.js +106 -121
  130. package/core/renderers/geras/renderer.js +96 -98
  131. package/core/renderers/measurables/base.js +30 -18
  132. package/core/renderers/measurables/bottom_row.js +83 -80
  133. package/core/renderers/measurables/connection.js +22 -15
  134. package/core/renderers/measurables/external_value_input.js +35 -22
  135. package/core/renderers/measurables/field.js +35 -20
  136. package/core/renderers/measurables/hat.js +18 -13
  137. package/core/renderers/measurables/icon.js +24 -17
  138. package/core/renderers/measurables/in_row_spacer.js +15 -13
  139. package/core/renderers/measurables/inline_input.js +43 -33
  140. package/core/renderers/measurables/input_connection.js +41 -28
  141. package/core/renderers/measurables/input_row.js +50 -44
  142. package/core/renderers/measurables/jagged_edge.js +14 -12
  143. package/core/renderers/measurables/next_connection.js +16 -14
  144. package/core/renderers/measurables/output_connection.js +26 -20
  145. package/core/renderers/measurables/previous_connection.js +16 -15
  146. package/core/renderers/measurables/round_corner.js +20 -18
  147. package/core/renderers/measurables/row.js +184 -168
  148. package/core/renderers/measurables/spacer_row.js +38 -23
  149. package/core/renderers/measurables/square_corner.js +18 -16
  150. package/core/renderers/measurables/statement_input.js +23 -20
  151. package/core/renderers/measurables/top_row.js +88 -85
  152. package/core/renderers/minimalist/constants.js +8 -7
  153. package/core/renderers/minimalist/drawer.js +11 -10
  154. package/core/renderers/minimalist/info.js +18 -18
  155. package/core/renderers/minimalist/renderer.js +40 -39
  156. package/core/renderers/thrasos/info.js +258 -248
  157. package/core/renderers/thrasos/renderer.js +20 -20
  158. package/core/renderers/zelos/constants.js +898 -873
  159. package/core/renderers/zelos/drawer.js +186 -169
  160. package/core/renderers/zelos/info.js +502 -479
  161. package/core/renderers/zelos/marker_svg.js +129 -115
  162. package/core/renderers/zelos/measurables/bottom_row.js +31 -30
  163. package/core/renderers/zelos/measurables/inputs.js +22 -21
  164. package/core/renderers/zelos/measurables/row_elements.js +14 -13
  165. package/core/renderers/zelos/measurables/top_row.js +34 -33
  166. package/core/renderers/zelos/path_object.js +181 -180
  167. package/core/renderers/zelos/renderer.js +91 -92
  168. package/core/scrollbar.js +759 -713
  169. package/core/scrollbar_pair.js +250 -245
  170. package/core/serialization/blocks.js +19 -9
  171. package/core/serialization/workspaces.js +3 -2
  172. package/core/shortcut_registry.js +286 -277
  173. package/core/sprites.js +31 -0
  174. package/core/theme.js +135 -141
  175. package/core/theme_manager.js +147 -143
  176. package/core/toolbox/category.js +602 -576
  177. package/core/toolbox/collapsible_category.js +226 -227
  178. package/core/toolbox/separator.js +70 -61
  179. package/core/toolbox/toolbox.js +934 -927
  180. package/core/toolbox/toolbox_item.js +115 -99
  181. package/core/tooltip.js +108 -35
  182. package/core/touch.js +8 -3
  183. package/core/touch_gesture.js +254 -251
  184. package/core/trashcan.js +606 -595
  185. package/core/utils/coordinate.js +97 -95
  186. package/core/utils/dom.js +2 -2
  187. package/core/utils/global.js +2 -0
  188. package/core/utils/rect.js +41 -37
  189. package/core/utils/sentinel.js +25 -0
  190. package/core/utils/size.js +30 -27
  191. package/core/utils/svg.js +18 -16
  192. package/core/variable_map.js +325 -341
  193. package/core/variable_model.js +55 -54
  194. package/core/variables.js +9 -2
  195. package/core/variables_dynamic.js +3 -1
  196. package/core/warning.js +126 -120
  197. package/core/widgetdiv.js +4 -4
  198. package/core/workspace.js +685 -664
  199. package/core/workspace_audio.js +124 -118
  200. package/core/workspace_comment.js +308 -298
  201. package/core/workspace_comment_svg.js +1029 -951
  202. package/core/workspace_drag_surface_svg.js +147 -140
  203. package/core/workspace_dragger.js +70 -71
  204. package/core/workspace_svg.js +2322 -2297
  205. package/core/xml.js +30 -20
  206. package/core/zoom_controls.js +431 -439
  207. package/dart_compressed.js +40 -43
  208. package/dart_compressed.js.map +1 -1
  209. package/generators/dart/colour.js +56 -64
  210. package/generators/dart/lists.js +61 -50
  211. package/generators/dart/math.js +160 -148
  212. package/generators/dart/text.js +83 -61
  213. package/generators/javascript/colour.js +37 -34
  214. package/generators/javascript/lists.js +50 -43
  215. package/generators/javascript/math.js +123 -139
  216. package/generators/javascript/text.js +67 -81
  217. package/generators/lua/colour.js +25 -23
  218. package/generators/lua/lists.js +97 -69
  219. package/generators/lua/logic.js +1 -2
  220. package/generators/lua/math.js +182 -144
  221. package/generators/lua/text.js +116 -99
  222. package/generators/php/colour.js +38 -32
  223. package/generators/php/lists.js +109 -89
  224. package/generators/php/math.js +90 -81
  225. package/generators/php/text.js +63 -61
  226. package/generators/python/colour.js +18 -18
  227. package/generators/python/lists.js +38 -30
  228. package/generators/python/loops.js +12 -8
  229. package/generators/python/math.js +104 -106
  230. package/generators/python/text.js +34 -30
  231. package/javascript_compressed.js +37 -39
  232. package/javascript_compressed.js.map +1 -1
  233. package/lua_compressed.js +39 -42
  234. package/lua_compressed.js.map +1 -1
  235. package/msg/az.js +2 -2
  236. package/msg/be.js +4 -4
  237. package/msg/cs.js +15 -15
  238. package/msg/de.js +1 -1
  239. package/msg/diq.js +1 -1
  240. package/msg/eo.js +1 -1
  241. package/msg/es.js +1 -1
  242. package/msg/fa.js +1 -1
  243. package/msg/fr.js +4 -4
  244. package/msg/he.js +1 -1
  245. package/msg/hr.js +2 -2
  246. package/msg/hy.js +2 -2
  247. package/msg/id.js +12 -12
  248. package/msg/inh.js +14 -14
  249. package/msg/ja.js +7 -7
  250. package/msg/lv.js +29 -29
  251. package/msg/pa.js +3 -3
  252. package/msg/smn.js +436 -0
  253. package/msg/te.js +1 -1
  254. package/msg/yue.js +1 -1
  255. package/msg/zh-hans.js +3 -3
  256. package/msg/zh-hant.js +3 -3
  257. package/package.json +7 -6
  258. package/php_compressed.js +38 -42
  259. package/php_compressed.js.map +1 -1
  260. package/python_compressed.js +26 -25
  261. package/python_compressed.js.map +1 -1
  262. 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
- const RenderedConnection = function(source, type) {
46
- RenderedConnection.superClass_.constructor.call(this, source, type);
47
-
48
+ class RenderedConnection extends Connection {
48
49
  /**
49
- * Connection database for connections of this type on the current workspace.
50
- * @const {!ConnectionDB}
51
- * @private
50
+ * @param {!BlockSvg} source The block establishing this connection.
51
+ * @param {number} type The type of the connection.
52
52
  */
53
- this.db_ = source.workspace.connectionDBList[type];
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
- * Connection database for connections compatible with this type on the
57
- * current workspace.
58
- * @const {!ConnectionDB}
59
- * @private
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
- this.dbOpposite_ =
62
- source.workspace.connectionDBList[internalConstants.OPPOSITE_TYPE[type]];
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
- * Workspace units, (0, 0) is top left of block.
66
- * @type {!Coordinate}
67
- * @private
112
+ * Get the source block for this connection.
113
+ * @return {!BlockSvg} The source block.
114
+ * @override
68
115
  */
69
- this.offsetInBlock_ = new Coordinate(0, 0);
116
+ getSourceBlock() {
117
+ return /** @type {!BlockSvg} */ (super.getSourceBlock());
118
+ }
70
119
 
71
120
  /**
72
- * Describes the state of this connection's tracked-ness.
73
- * @type {RenderedConnection.TrackedState}
74
- * @private
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
- this.trackedState_ = RenderedConnection.TrackedState.WILL_TRACK;
125
+ targetBlock() {
126
+ return /** @type {BlockSvg} */ (super.targetBlock());
127
+ }
77
128
 
78
129
  /**
79
- * Connection this connection connects to. Null if not connected.
80
- * @type {RenderedConnection}
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
- this.targetConnection = null;
83
- };
84
- object.inherits(RenderedConnection, Connection);
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
- * Returns the block that this connection connects to.
129
- * @return {?BlockSvg} The connected block or null if none is connected.
130
- * @override
131
- */
132
- RenderedConnection.prototype.targetBlock = function() {
133
- return /** @type {BlockSvg} */ (
134
- RenderedConnection.superClass_.targetBlock.call(this));
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
- // Swap the connections and move the 'static' connection instead.
177
- staticConnection = this;
178
- reverse = true;
179
- }
180
- // Raise it to the top for extra visibility.
181
- const selected = common.getSelected() == rootBlock;
182
- selected || rootBlock.addSelect();
183
- let dx = (staticConnection.x + internalConstants.SNAP_RADIUS +
184
- Math.floor(Math.random() * internalConstants.BUMP_RANDOMNESS)) -
185
- this.x;
186
- let dy = (staticConnection.y + internalConstants.SNAP_RADIUS +
187
- Math.floor(Math.random() * internalConstants.BUMP_RANDOMNESS)) -
188
- this.y;
189
- if (reverse) {
190
- // When reversing a bump due to an uneditable block, bump up.
191
- dy = -dy;
192
- }
193
- if (rootBlock.RTL) {
194
- dx = (staticConnection.x - internalConstants.SNAP_RADIUS -
195
- Math.floor(Math.random() * internalConstants.BUMP_RANDOMNESS)) -
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
- * Change the connection's coordinates.
204
- * @param {number} x New absolute x coordinate, in workspace coordinates.
205
- * @param {number} y New absolute y coordinate, in workspace coordinates.
206
- */
207
- RenderedConnection.prototype.moveTo = function(x, y) {
208
- if (this.trackedState_ === RenderedConnection.TrackedState.WILL_TRACK) {
209
- this.db_.addConnection(this, y);
210
- this.trackedState_ = RenderedConnection.TrackedState.TRACKED;
211
- } else if (this.trackedState_ === RenderedConnection.TrackedState.TRACKED) {
212
- this.db_.removeConnection(this, this.y);
213
- this.db_.addConnection(this, y);
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
- * Change the connection's coordinates.
221
- * @param {number} dx Change to x coordinate, in workspace units.
222
- * @param {number} dy Change to y coordinate, in workspace units.
223
- */
224
- RenderedConnection.prototype.moveBy = function(dx, dy) {
225
- this.moveTo(this.x + dx, this.y + dy);
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
- * Move this connection to the location given by its offset within the block and
230
- * the location of the block's top left corner.
231
- * @param {!Coordinate} blockTL The location of the top left
232
- * corner of the block, in workspace coordinates.
233
- */
234
- RenderedConnection.prototype.moveToOffset = function(blockTL) {
235
- this.moveTo(
236
- blockTL.x + this.offsetInBlock_.x, blockTL.y + this.offsetInBlock_.y);
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
- * Set the offset of this connection relative to the top left of its block.
241
- * @param {number} x The new relative x, in workspace units.
242
- * @param {number} y The new relative y, in workspace units.
243
- */
244
- RenderedConnection.prototype.setOffsetInBlock = function(x, y) {
245
- this.offsetInBlock_.x = x;
246
- this.offsetInBlock_.y = y;
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
- * Get the offset of this connection relative to the top left of its block.
251
- * @return {!Coordinate} The offset of the connection.
252
- * @package
253
- */
254
- RenderedConnection.prototype.getOffsetInBlock = function() {
255
- return this.offsetInBlock_;
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
- * Move the blocks on either side of this connection right next to each other.
260
- * @package
261
- */
262
- RenderedConnection.prototype.tighten = function() {
263
- const dx = this.targetConnection.x - this.x;
264
- const dy = this.targetConnection.y - this.y;
265
- if (dx !== 0 || dy !== 0) {
266
- const block = this.targetBlock();
267
- const svgRoot = block.getSvgRoot();
268
- if (!svgRoot) {
269
- throw Error('block is not rendered.');
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
- * Find the closest compatible connection to this connection.
281
- * All parameters are in workspace units.
282
- * @param {number} maxLimit The maximum radius to another connection.
283
- * @param {!Coordinate} dxy Offset between this connection's location
284
- * in the database and the current location (as a result of dragging).
285
- * @return {!{connection: ?Connection, radius: number}} Contains two
286
- * properties: 'connection' which is either another connection or null,
287
- * and 'radius' which is the distance.
288
- */
289
- RenderedConnection.prototype.closest = function(maxLimit, dxy) {
290
- return this.dbOpposite_.searchForClosest(this, maxLimit, dxy);
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
- * Remove the highlighting around this connection.
329
- */
330
- RenderedConnection.prototype.unhighlight = function() {
331
- dom.removeNode(Connection.highlightedPath_);
332
- delete Connection.highlightedPath_;
333
- };
334
-
335
- /**
336
- * Set whether this connections is tracked in the database or not.
337
- * @param {boolean} doTracking If true, start tracking. If false, stop tracking.
338
- * @package
339
- */
340
- RenderedConnection.prototype.setTracking = function(doTracking) {
341
- if ((doTracking &&
342
- this.trackedState_ === RenderedConnection.TrackedState.TRACKED) ||
343
- (!doTracking &&
344
- this.trackedState_ === RenderedConnection.TrackedState.UNTRACKED)) {
345
- return;
346
- }
347
- if (this.sourceBlock_.isInFlyout) {
348
- // Don't bother maintaining a database of connections in a flyout.
349
- return;
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
- if (doTracking) {
352
- this.db_.addConnection(this, this.y);
353
- this.trackedState_ = RenderedConnection.TrackedState.TRACKED;
354
- return;
319
+
320
+ /**
321
+ * Remove the highlighting around this connection.
322
+ */
323
+ unhighlight() {
324
+ dom.removeNode(Connection.highlightedPath_);
325
+ delete Connection.highlightedPath_;
355
326
  }
356
- if (this.trackedState_ === RenderedConnection.TrackedState.TRACKED) {
357
- this.db_.removeConnection(this, this.y);
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
- * Stop tracking this connection, as well as all down-stream connections on
364
- * any block attached to this connection. This happens when a block is
365
- * collapsed.
366
- *
367
- * Also closes down-stream icons/bubbles.
368
- * @package
369
- */
370
- RenderedConnection.prototype.stopTrackingAll = function() {
371
- this.setTracking(false);
372
- if (this.targetConnection) {
373
- const blocks = this.targetBlock().getDescendants(false);
374
- for (let i = 0; i < blocks.length; i++) {
375
- const block = blocks[i];
376
- // Stop tracking connections of all children.
377
- const connections = block.getConnections_(true);
378
- for (let j = 0; j < connections.length; j++) {
379
- connections[j].setTracking(false);
380
- }
381
- // Close all bubbles of all children.
382
- const icons = block.getIcons();
383
- for (let j = 0; j < icons.length; j++) {
384
- icons[j].setVisible(false);
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
- * Start tracking this connection, as well as all down-stream connections on
392
- * any block attached to this connection. This happens when a block is expanded.
393
- * @return {!Array<!Block>} List of blocks to render.
394
- */
395
- RenderedConnection.prototype.startTrackingAll = function() {
396
- this.setTracking(true);
397
- // All blocks that are not tracked must start tracking before any
398
- // rendering takes place, since rendering requires knowing the dimensions
399
- // of lower blocks. Also, since rendering a block renders all its parents,
400
- // we only need to render the leaf nodes.
401
- let renderList = [];
402
- if (this.type !== ConnectionType.INPUT_VALUE &&
403
- this.type !== ConnectionType.NEXT_STATEMENT) {
404
- // Only spider down.
405
- return renderList;
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
- for (let i = 0; i < connections.length; i++) {
421
- renderList.push.apply(renderList, connections[i].startTrackingAll());
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
- if (!renderList.length) {
424
- // Leaf block.
425
- renderList = [block];
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
- * Behavior after a connection attempt fails.
433
- * Bumps this connection away from the other connection. Called when an
434
- * attempted connection fails.
435
- * @param {!Connection} otherConnection Connection that this connection
436
- * failed to connect to.
437
- * @package
438
- */
439
- RenderedConnection.prototype.onFailedConnect = function(otherConnection) {
440
- const block = this.getSourceBlock();
441
- if (eventUtils.getRecordUndo()) {
442
- const group = eventUtils.getGroup();
443
- setTimeout(function() {
444
- if (!block.isDisposed() && !block.getParent()) {
445
- eventUtils.setGroup(group);
446
- this.bumpAwayFrom(otherConnection);
447
- eventUtils.setGroup(false);
448
- }
449
- }.bind(this), internalConstants.BUMP_DELAY);
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
- * Disconnect two blocks that are connected by this connection.
456
- * @param {!Block} parentBlock The superior block.
457
- * @param {!Block} childBlock The inferior block.
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
- * Respawn the shadow block if there was one connected to the this connection.
479
- * Render/rerender blocks as needed.
480
- * @protected
481
- * @override
482
- */
483
- RenderedConnection.prototype.respawnShadow_ = function() {
484
- RenderedConnection.superClass_.respawnShadow_.call(this);
485
- const blockShadow = this.targetBlock();
486
- if (!blockShadow) {
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
- const parentBlock = this.getSourceBlock();
493
- if (parentBlock.rendered) {
494
- parentBlock.render();
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
- * Find all nearby compatible connections to this connection.
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
- * Connect two connections together. This is the connection on the superior
512
- * block. Rerender blocks as needed.
513
- * @param {!Connection} childConnection Connection on inferior block.
514
- * @protected
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
- const parentConnection = this;
520
- const parentBlock = parentConnection.getSourceBlock();
521
- const childBlock = childConnection.getSourceBlock();
522
- const parentRendered = parentBlock.rendered;
523
- const childRendered = childBlock.rendered;
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
- 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();
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
- // 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';
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
- * Function to be called when this connection's compatible types have changed.
554
- * @protected
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.prototype.onCheckChanged_ = function() {
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
- }
582
+ RenderedConnection.TrackedState = {
583
+ WILL_TRACK: -1,
584
+ UNTRACKED: 0,
585
+ TRACKED: 1,
567
586
  };
568
587
 
569
588
  exports.RenderedConnection = RenderedConnection;