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
@@ -9,6 +9,7 @@
9
9
  */
10
10
  'use strict';
11
11
 
12
+
12
13
  /**
13
14
  * Methods for rendering debug graphics.
14
15
  * @class
@@ -21,7 +22,9 @@ const {BlockSvg} = goog.requireType('Blockly.BlockSvg');
21
22
  const {ConnectionType} = goog.require('Blockly.ConnectionType');
22
23
  /* eslint-disable-next-line no-unused-vars */
23
24
  const {ConstantProvider} = goog.requireType('Blockly.blockRendering.ConstantProvider');
25
+ const {Field} = goog.require('Blockly.blockRendering.Field');
24
26
  const {FieldLabel} = goog.require('Blockly.FieldLabel');
27
+ const {InputConnection} = goog.require('Blockly.blockRendering.InputConnection');
25
28
  /* eslint-disable-next-line no-unused-vars */
26
29
  const {InRowSpacer} = goog.requireType('Blockly.blockRendering.InRowSpacer');
27
30
  /* eslint-disable-next-line no-unused-vars */
@@ -29,6 +32,8 @@ const {Measurable} = goog.requireType('Blockly.blockRendering.Measurable');
29
32
  /* eslint-disable-next-line no-unused-vars */
30
33
  const {RenderInfo} = goog.requireType('Blockly.blockRendering.RenderInfo');
31
34
  /* eslint-disable-next-line no-unused-vars */
35
+ const {RenderInfo: ZelosInfo} = goog.requireType('Blockly.zelos.RenderInfo');
36
+ /* eslint-disable-next-line no-unused-vars */
32
37
  const {RenderedConnection} = goog.requireType('Blockly.RenderedConnection');
33
38
  /* eslint-disable-next-line no-unused-vars */
34
39
  const {Row} = goog.requireType('Blockly.blockRendering.Row');
@@ -38,398 +43,415 @@ const {Types} = goog.require('Blockly.blockRendering.Types');
38
43
 
39
44
  /**
40
45
  * An object that renders rectangles and dots for debugging rendering code.
41
- * @param {!ConstantProvider} constants The renderer's
42
- * constants.
43
- * @package
44
- * @constructor
45
46
  * @alias Blockly.blockRendering.Debug
46
47
  */
47
- const Debug = function(constants) {
48
- /**
49
- * An array of SVG elements that have been created by this object.
50
- * @type {Array<!SVGElement>}
51
- * @private
52
- */
53
- this.debugElements_ = [];
54
-
48
+ class Debug {
55
49
  /**
56
- * The SVG root of the block that is being rendered. Debug elements will
57
- * be attached to this root.
58
- * @type {SVGElement}
59
- * @private
50
+ * @param {!ConstantProvider} constants The renderer's
51
+ * constants.
52
+ * @package
60
53
  */
61
- this.svgRoot_ = null;
54
+ constructor(constants) {
55
+ /**
56
+ * An array of SVG elements that have been created by this object.
57
+ * @type {Array<!SVGElement>}
58
+ * @private
59
+ */
60
+ this.debugElements_ = [];
61
+
62
+ /**
63
+ * The SVG root of the block that is being rendered. Debug elements will
64
+ * be attached to this root.
65
+ * @type {SVGElement}
66
+ * @private
67
+ */
68
+ this.svgRoot_ = null;
69
+
70
+ /**
71
+ * The renderer's constant provider.
72
+ * @type {!ConstantProvider}
73
+ * @private
74
+ */
75
+ this.constants_ = constants;
76
+
77
+ /**
78
+ * @type {string}
79
+ * @private
80
+ */
81
+ this.randomColour_ = '';
82
+ }
62
83
 
63
84
  /**
64
- * The renderer's constant provider.
65
- * @type {!ConstantProvider}
66
- * @private
85
+ * Remove all elements the this object created on the last pass.
86
+ * @package
67
87
  */
68
- this.constants_ = constants;
69
- };
70
-
71
- /**
72
- * Configuration object containing booleans to enable and disable debug
73
- * rendering of specific rendering components.
74
- * @type {!Object<string, boolean>}
75
- */
76
- Debug.config = {
77
- rowSpacers: true,
78
- elemSpacers: true,
79
- rows: true,
80
- elems: true,
81
- connections: true,
82
- blockBounds: true,
83
- connectedBlockBounds: true,
84
- render: true,
85
- };
86
-
87
- /**
88
- * Remove all elements the this object created on the last pass.
89
- * @package
90
- */
91
- Debug.prototype.clearElems = function() {
92
- for (let i = 0; i < this.debugElements_.length; i++) {
93
- const elem = this.debugElements_[i];
94
- dom.removeNode(elem);
95
- }
96
-
97
- this.debugElements_ = [];
98
- };
88
+ clearElems() {
89
+ for (let i = 0; i < this.debugElements_.length; i++) {
90
+ const elem = this.debugElements_[i];
91
+ dom.removeNode(elem);
92
+ }
99
93
 
100
- /**
101
- * Draw a debug rectangle for a spacer (empty) row.
102
- * @param {!Row} row The row to render.
103
- * @param {number} cursorY The y position of the top of the row.
104
- * @param {boolean} isRtl Whether the block is rendered RTL.
105
- * @package
106
- */
107
- Debug.prototype.drawSpacerRow = function(row, cursorY, isRtl) {
108
- if (!Debug.config.rowSpacers) {
109
- return;
94
+ this.debugElements_ = [];
110
95
  }
111
96
 
112
- const height = Math.abs(row.height);
113
- const isNegativeSpacing = row.height < 0;
114
- if (isNegativeSpacing) {
115
- cursorY -= height;
116
- }
97
+ /**
98
+ * Draw a debug rectangle for a spacer (empty) row.
99
+ * @param {!Row} row The row to render.
100
+ * @param {number} cursorY The y position of the top of the row.
101
+ * @param {boolean} isRtl Whether the block is rendered RTL.
102
+ * @package
103
+ */
104
+ drawSpacerRow(row, cursorY, isRtl) {
105
+ if (!Debug.config.rowSpacers) {
106
+ return;
107
+ }
117
108
 
118
- this.debugElements_.push(dom.createSvgElement(
119
- Svg.RECT, {
120
- 'class': 'rowSpacerRect blockRenderDebug',
121
- 'x': isRtl ? -(row.xPos + row.width) : row.xPos,
122
- 'y': cursorY,
123
- 'width': row.width,
124
- 'height': height,
125
- 'stroke': isNegativeSpacing ? 'black' : 'blue',
126
- 'fill': 'blue',
127
- 'fill-opacity': '0.5',
128
- 'stroke-width': '1px',
129
- },
130
- this.svgRoot_));
131
- };
109
+ const height = Math.abs(row.height);
110
+ const isNegativeSpacing = row.height < 0;
111
+ if (isNegativeSpacing) {
112
+ cursorY -= height;
113
+ }
132
114
 
133
- /**
134
- * Draw a debug rectangle for a horizontal spacer.
135
- * @param {!InRowSpacer} elem The spacer to render.
136
- * @param {number} rowHeight The height of the container row.
137
- * @param {boolean} isRtl Whether the block is rendered RTL.
138
- * @package
139
- */
140
- Debug.prototype.drawSpacerElem = function(elem, rowHeight, isRtl) {
141
- if (!Debug.config.elemSpacers) {
142
- return;
115
+ this.debugElements_.push(dom.createSvgElement(
116
+ Svg.RECT, {
117
+ 'class': 'rowSpacerRect blockRenderDebug',
118
+ 'x': isRtl ? -(row.xPos + row.width) : row.xPos,
119
+ 'y': cursorY,
120
+ 'width': row.width,
121
+ 'height': height,
122
+ 'stroke': isNegativeSpacing ? 'black' : 'blue',
123
+ 'fill': 'blue',
124
+ 'fill-opacity': '0.5',
125
+ 'stroke-width': '1px',
126
+ },
127
+ this.svgRoot_));
143
128
  }
144
129
 
145
- const width = Math.abs(elem.width);
146
- const isNegativeSpacing = elem.width < 0;
147
- let xPos = isNegativeSpacing ? elem.xPos - width : elem.xPos;
148
- if (isRtl) {
149
- xPos = -(xPos + width);
150
- }
151
- const yPos = elem.centerline - elem.height / 2;
152
- this.debugElements_.push(dom.createSvgElement(
153
- Svg.RECT, {
154
- 'class': 'elemSpacerRect blockRenderDebug',
155
- 'x': xPos,
156
- 'y': yPos,
157
- 'width': width,
158
- 'height': elem.height,
159
- 'stroke': 'pink',
160
- 'fill': isNegativeSpacing ? 'black' : 'pink',
161
- 'fill-opacity': '0.5',
162
- 'stroke-width': '1px',
163
- },
164
- this.svgRoot_));
165
- };
130
+ /**
131
+ * Draw a debug rectangle for a horizontal spacer.
132
+ * @param {!InRowSpacer} elem The spacer to render.
133
+ * @param {number} rowHeight The height of the container row.
134
+ * @param {boolean} isRtl Whether the block is rendered RTL.
135
+ * @package
136
+ */
137
+ drawSpacerElem(elem, rowHeight, isRtl) {
138
+ if (!Debug.config.elemSpacers) {
139
+ return;
140
+ }
166
141
 
167
- /**
168
- * Draw a debug rectangle for an in-row element.
169
- * @param {!Measurable} elem The element to render.
170
- * @param {boolean} isRtl Whether the block is rendered RTL.
171
- * @package
172
- */
173
- Debug.prototype.drawRenderedElem = function(elem, isRtl) {
174
- if (Debug.config.elems) {
175
- let xPos = elem.xPos;
142
+ const width = Math.abs(elem.width);
143
+ const isNegativeSpacing = elem.width < 0;
144
+ let xPos = isNegativeSpacing ? elem.xPos - width : elem.xPos;
176
145
  if (isRtl) {
177
- xPos = -(xPos + elem.width);
146
+ xPos = -(xPos + width);
178
147
  }
179
148
  const yPos = elem.centerline - elem.height / 2;
180
149
  this.debugElements_.push(dom.createSvgElement(
181
150
  Svg.RECT, {
182
- 'class': 'rowRenderingRect blockRenderDebug',
151
+ 'class': 'elemSpacerRect blockRenderDebug',
183
152
  'x': xPos,
184
153
  'y': yPos,
185
- 'width': elem.width,
154
+ 'width': width,
186
155
  'height': elem.height,
187
- 'stroke': 'black',
188
- 'fill': 'none',
156
+ 'stroke': 'pink',
157
+ 'fill': isNegativeSpacing ? 'black' : 'pink',
158
+ 'fill-opacity': '0.5',
189
159
  'stroke-width': '1px',
190
160
  },
191
161
  this.svgRoot_));
162
+ }
192
163
 
193
- if (Types.isField(elem) && elem.field instanceof FieldLabel) {
194
- const baseline = this.constants_.FIELD_TEXT_BASELINE;
164
+ /**
165
+ * Draw a debug rectangle for an in-row element.
166
+ * @param {!Measurable} elem The element to render.
167
+ * @param {boolean} isRtl Whether the block is rendered RTL.
168
+ * @package
169
+ */
170
+ drawRenderedElem(elem, isRtl) {
171
+ if (Debug.config.elems) {
172
+ let xPos = elem.xPos;
173
+ if (isRtl) {
174
+ xPos = -(xPos + elem.width);
175
+ }
176
+ const yPos = elem.centerline - elem.height / 2;
195
177
  this.debugElements_.push(dom.createSvgElement(
196
178
  Svg.RECT, {
197
179
  'class': 'rowRenderingRect blockRenderDebug',
198
180
  'x': xPos,
199
- 'y': yPos + baseline,
181
+ 'y': yPos,
200
182
  'width': elem.width,
201
- 'height': '0.1px',
202
- 'stroke': 'red',
183
+ 'height': elem.height,
184
+ 'stroke': 'black',
203
185
  'fill': 'none',
204
- 'stroke-width': '0.5px',
186
+ 'stroke-width': '1px',
205
187
  },
206
188
  this.svgRoot_));
207
- }
208
- }
209
189
 
190
+ if (Types.isField(elem) && elem instanceof Field &&
191
+ elem.field instanceof FieldLabel) {
192
+ const baseline = this.constants_.FIELD_TEXT_BASELINE;
193
+ this.debugElements_.push(dom.createSvgElement(
194
+ Svg.RECT, {
195
+ 'class': 'rowRenderingRect blockRenderDebug',
196
+ 'x': xPos,
197
+ 'y': yPos + baseline,
198
+ 'width': elem.width,
199
+ 'height': '0.1px',
200
+ 'stroke': 'red',
201
+ 'fill': 'none',
202
+ 'stroke-width': '0.5px',
203
+ },
204
+ this.svgRoot_));
205
+ }
206
+ }
210
207
 
211
- if (Types.isInput(elem) && Debug.config.connections) {
212
- this.drawConnection(elem.connectionModel);
213
- }
214
- };
215
208
 
216
- /**
217
- * Draw a circle at the location of the given connection. Inputs and outputs
218
- * share the same colours, as do previous and next. When positioned correctly
219
- * a connected pair will look like a bullseye.
220
- * @param {RenderedConnection} conn The connection to circle.
221
- * @suppress {visibility} Suppress visibility of conn.offsetInBlock_ since this
222
- * is a debug module.
223
- * @package
224
- */
225
- Debug.prototype.drawConnection = function(conn) {
226
- if (!Debug.config.connections) {
227
- return;
209
+ if (Types.isInput(elem) && elem instanceof InputConnection &&
210
+ Debug.config.connections) {
211
+ this.drawConnection(elem.connectionModel);
212
+ }
228
213
  }
229
214
 
230
- let colour;
231
- let size;
232
- let fill;
233
- if (conn.type === ConnectionType.INPUT_VALUE) {
234
- size = 4;
235
- colour = 'magenta';
236
- fill = 'none';
237
- } else if (conn.type === ConnectionType.OUTPUT_VALUE) {
238
- size = 2;
239
- colour = 'magenta';
240
- fill = colour;
241
- } else if (conn.type === ConnectionType.NEXT_STATEMENT) {
242
- size = 4;
243
- colour = 'goldenrod';
244
- fill = 'none';
245
- } else if (conn.type === ConnectionType.PREVIOUS_STATEMENT) {
246
- size = 2;
247
- colour = 'goldenrod';
248
- fill = colour;
249
- }
250
- this.debugElements_.push(dom.createSvgElement(
251
- Svg.CIRCLE, {
252
- 'class': 'blockRenderDebug',
253
- 'cx': conn.offsetInBlock_.x,
254
- 'cy': conn.offsetInBlock_.y,
255
- 'r': size,
256
- 'fill': fill,
257
- 'stroke': colour,
258
- },
259
- this.svgRoot_));
260
- };
215
+ /**
216
+ * Draw a circle at the location of the given connection. Inputs and outputs
217
+ * share the same colours, as do previous and next. When positioned correctly
218
+ * a connected pair will look like a bullseye.
219
+ * @param {RenderedConnection} conn The connection to circle.
220
+ * @suppress {visibility} Suppress visibility of conn.offsetInBlock_ since
221
+ * this is a debug module.
222
+ * @package
223
+ */
224
+ drawConnection(conn) {
225
+ if (!Debug.config.connections) {
226
+ return;
227
+ }
261
228
 
262
- /**
263
- * Draw a debug rectangle for a non-empty row.
264
- * @param {!Row} row The non-empty row to render.
265
- * @param {number} cursorY The y position of the top of the row.
266
- * @param {boolean} isRtl Whether the block is rendered RTL.
267
- * @package
268
- */
269
- Debug.prototype.drawRenderedRow = function(row, cursorY, isRtl) {
270
- if (!Debug.config.rows) {
271
- return;
272
- }
273
- this.debugElements_.push(dom.createSvgElement(
274
- Svg.RECT, {
275
- 'class': 'elemRenderingRect blockRenderDebug',
276
- 'x': isRtl ? -(row.xPos + row.width) : row.xPos,
277
- 'y': row.yPos,
278
- 'width': row.width,
279
- 'height': row.height,
280
- 'stroke': 'red',
281
- 'fill': 'none',
282
- 'stroke-width': '1px',
283
- },
284
- this.svgRoot_));
285
-
286
- if (Types.isTopOrBottomRow(row)) {
287
- return;
229
+ let colour;
230
+ let size;
231
+ let fill;
232
+ if (conn.type === ConnectionType.INPUT_VALUE) {
233
+ size = 4;
234
+ colour = 'magenta';
235
+ fill = 'none';
236
+ } else if (conn.type === ConnectionType.OUTPUT_VALUE) {
237
+ size = 2;
238
+ colour = 'magenta';
239
+ fill = colour;
240
+ } else if (conn.type === ConnectionType.NEXT_STATEMENT) {
241
+ size = 4;
242
+ colour = 'goldenrod';
243
+ fill = 'none';
244
+ } else if (conn.type === ConnectionType.PREVIOUS_STATEMENT) {
245
+ size = 2;
246
+ colour = 'goldenrod';
247
+ fill = colour;
248
+ }
249
+ this.debugElements_.push(dom.createSvgElement(
250
+ Svg.CIRCLE, {
251
+ 'class': 'blockRenderDebug',
252
+ 'cx': conn.offsetInBlock_.x,
253
+ 'cy': conn.offsetInBlock_.y,
254
+ 'r': size,
255
+ 'fill': fill,
256
+ 'stroke': colour,
257
+ },
258
+ this.svgRoot_));
288
259
  }
289
260
 
290
- if (Debug.config.connectedBlockBounds) {
261
+ /**
262
+ * Draw a debug rectangle for a non-empty row.
263
+ * @param {!Row} row The non-empty row to render.
264
+ * @param {number} cursorY The y position of the top of the row.
265
+ * @param {boolean} isRtl Whether the block is rendered RTL.
266
+ * @package
267
+ */
268
+ drawRenderedRow(row, cursorY, isRtl) {
269
+ if (!Debug.config.rows) {
270
+ return;
271
+ }
291
272
  this.debugElements_.push(dom.createSvgElement(
292
273
  Svg.RECT, {
293
- 'class': 'connectedBlockWidth blockRenderDebug',
294
- 'x': isRtl ? -(row.xPos + row.widthWithConnectedBlocks) : row.xPos,
274
+ 'class': 'elemRenderingRect blockRenderDebug',
275
+ 'x': isRtl ? -(row.xPos + row.width) : row.xPos,
295
276
  'y': row.yPos,
296
- 'width': row.widthWithConnectedBlocks,
277
+ 'width': row.width,
297
278
  'height': row.height,
298
- 'stroke': this.randomColour_,
279
+ 'stroke': 'red',
299
280
  'fill': 'none',
300
281
  'stroke-width': '1px',
301
- 'stroke-dasharray': '3,3',
302
282
  },
303
283
  this.svgRoot_));
304
- }
305
- };
306
284
 
307
- /**
308
- * Draw debug rectangles for a non-empty row and all of its subcomponents.
309
- * @param {!Row} row The non-empty row to render.
310
- * @param {number} cursorY The y position of the top of the row.
311
- * @param {boolean} isRtl Whether the block is rendered RTL.
312
- * @package
313
- */
314
- Debug.prototype.drawRowWithElements = function(row, cursorY, isRtl) {
315
- for (let i = 0; i < row.elements.length; i++) {
316
- const elem = row.elements[i];
317
- if (!elem) {
318
- console.warn('A row has an undefined or null element.', row, elem);
319
- continue;
285
+ if (Types.isTopOrBottomRow(row)) {
286
+ return;
320
287
  }
321
- if (Types.isSpacer(elem)) {
322
- this.drawSpacerElem(
323
- /** @type {!InRowSpacer} */ (elem), row.height, isRtl);
324
- } else {
325
- this.drawRenderedElem(elem, isRtl);
288
+
289
+ if (Debug.config.connectedBlockBounds) {
290
+ this.debugElements_.push(dom.createSvgElement(
291
+ Svg.RECT, {
292
+ 'class': 'connectedBlockWidth blockRenderDebug',
293
+ 'x': isRtl ? -(row.xPos + row.widthWithConnectedBlocks) : row.xPos,
294
+ 'y': row.yPos,
295
+ 'width': row.widthWithConnectedBlocks,
296
+ 'height': row.height,
297
+ 'stroke': this.randomColour_,
298
+ 'fill': 'none',
299
+ 'stroke-width': '1px',
300
+ 'stroke-dasharray': '3,3',
301
+ },
302
+ this.svgRoot_));
326
303
  }
327
304
  }
328
- this.drawRenderedRow(row, cursorY, isRtl);
329
- };
330
305
 
331
- /**
332
- * Draw a debug rectangle around the entire block.
333
- * @param {!RenderInfo} info Rendering information about
334
- * the block to debug.
335
- * @package
336
- */
337
- Debug.prototype.drawBoundingBox = function(info) {
338
- if (!Debug.config.blockBounds) {
339
- return;
306
+ /**
307
+ * Draw debug rectangles for a non-empty row and all of its subcomponents.
308
+ * @param {!Row} row The non-empty row to render.
309
+ * @param {number} cursorY The y position of the top of the row.
310
+ * @param {boolean} isRtl Whether the block is rendered RTL.
311
+ * @package
312
+ */
313
+ drawRowWithElements(row, cursorY, isRtl) {
314
+ for (let i = 0; i < row.elements.length; i++) {
315
+ const elem = row.elements[i];
316
+ if (!elem) {
317
+ console.warn('A row has an undefined or null element.', row, elem);
318
+ continue;
319
+ }
320
+ if (Types.isSpacer(elem)) {
321
+ this.drawSpacerElem(
322
+ /** @type {!InRowSpacer} */ (elem), row.height, isRtl);
323
+ } else {
324
+ this.drawRenderedElem(elem, isRtl);
325
+ }
326
+ }
327
+ this.drawRenderedRow(row, cursorY, isRtl);
340
328
  }
341
- // Bounding box without children.
342
- let xPos = info.RTL ? -info.width : 0;
343
- const yPos = 0;
344
- this.debugElements_.push(dom.createSvgElement(
345
- Svg.RECT, {
346
- 'class': 'blockBoundingBox blockRenderDebug',
347
- 'x': xPos,
348
- 'y': yPos,
349
- 'width': info.width,
350
- 'height': info.height,
351
- 'stroke': 'black',
352
- 'fill': 'none',
353
- 'stroke-width': '1px',
354
- 'stroke-dasharray': '5,5',
355
- },
356
- this.svgRoot_));
357
-
358
- if (Debug.config.connectedBlockBounds) {
359
- // Bounding box with children.
360
- xPos = info.RTL ? -info.widthWithChildren : 0;
329
+
330
+ /**
331
+ * Draw a debug rectangle around the entire block.
332
+ * @param {!RenderInfo} info Rendering information about
333
+ * the block to debug.
334
+ * @package
335
+ */
336
+ drawBoundingBox(info) {
337
+ if (!Debug.config.blockBounds) {
338
+ return;
339
+ }
340
+ // Bounding box without children.
341
+ let xPos = info.RTL ? -info.width : 0;
342
+ const yPos = 0;
361
343
  this.debugElements_.push(dom.createSvgElement(
362
344
  Svg.RECT, {
363
- 'class': 'blockRenderDebug',
345
+ 'class': 'blockBoundingBox blockRenderDebug',
364
346
  'x': xPos,
365
347
  'y': yPos,
366
- 'width': info.widthWithChildren,
348
+ 'width': info.width,
367
349
  'height': info.height,
368
- 'stroke': '#DF57BC',
350
+ 'stroke': 'black',
369
351
  'fill': 'none',
370
352
  'stroke-width': '1px',
371
- 'stroke-dasharray': '3,3',
353
+ 'stroke-dasharray': '5,5',
372
354
  },
373
355
  this.svgRoot_));
374
- }
375
- };
376
356
 
377
- /**
378
- * Do all of the work to draw debug information for the whole block.
379
- * @param {!BlockSvg} block The block to draw debug information for.
380
- * @param {!RenderInfo} info Rendering information about
381
- * the block to debug.
382
- * @package
383
- */
384
- Debug.prototype.drawDebug = function(block, info) {
385
- this.clearElems();
386
- this.svgRoot_ = block.getSvgRoot();
387
-
388
- this.randomColour_ = '#' + Math.floor(Math.random() * 16777215).toString(16);
389
-
390
- let cursorY = 0;
391
- for (let i = 0; i < info.rows.length; i++) {
392
- const row = info.rows[i];
393
- if (Types.isBetweenRowSpacer(row)) {
394
- this.drawSpacerRow(row, cursorY, info.RTL);
395
- } else {
396
- this.drawRowWithElements(row, cursorY, info.RTL);
357
+ if (Debug.config.connectedBlockBounds) {
358
+ // Bounding box with children.
359
+ xPos = info.RTL ? -info.widthWithChildren : 0;
360
+ this.debugElements_.push(dom.createSvgElement(
361
+ Svg.RECT, {
362
+ 'class': 'blockRenderDebug',
363
+ 'x': xPos,
364
+ 'y': yPos,
365
+ 'width': info.widthWithChildren,
366
+ 'height': info.height,
367
+ 'stroke': '#DF57BC',
368
+ 'fill': 'none',
369
+ 'stroke-width': '1px',
370
+ 'stroke-dasharray': '3,3',
371
+ },
372
+ this.svgRoot_));
397
373
  }
398
- cursorY += row.height;
399
374
  }
400
375
 
401
- if (block.previousConnection) {
402
- this.drawConnection(block.previousConnection);
403
- }
404
- if (block.nextConnection) {
405
- this.drawConnection(block.nextConnection);
406
- }
407
- if (block.outputConnection) {
408
- this.drawConnection(block.outputConnection);
409
- }
410
- if (info.rightSide) {
411
- this.drawRenderedElem(info.rightSide, info.RTL);
412
- }
376
+ /**
377
+ * Do all of the work to draw debug information for the whole block.
378
+ * @param {!BlockSvg} block The block to draw debug information for.
379
+ * @param {!RenderInfo} info Rendering information about
380
+ * the block to debug.
381
+ * @package
382
+ */
383
+ drawDebug(block, info) {
384
+ this.clearElems();
385
+ this.svgRoot_ = block.getSvgRoot();
386
+
387
+ this.randomColour_ =
388
+ '#' + Math.floor(Math.random() * 16777215).toString(16);
389
+
390
+ let cursorY = 0;
391
+ for (let i = 0; i < info.rows.length; i++) {
392
+ const row = info.rows[i];
393
+ if (Types.isBetweenRowSpacer(row)) {
394
+ this.drawSpacerRow(row, cursorY, info.RTL);
395
+ } else {
396
+ this.drawRowWithElements(row, cursorY, info.RTL);
397
+ }
398
+ cursorY += row.height;
399
+ }
413
400
 
414
- this.drawBoundingBox(info);
401
+ if (block.previousConnection) {
402
+ this.drawConnection(block.previousConnection);
403
+ }
404
+ if (block.nextConnection) {
405
+ this.drawConnection(block.nextConnection);
406
+ }
407
+ if (block.outputConnection) {
408
+ this.drawConnection(block.outputConnection);
409
+ }
410
+ /**
411
+ * TODO: Find a better way to do this check without pulling in all of
412
+ * zelos, or just delete this line or the whole debug renderer.
413
+ */
414
+ const maybeZelosInfo = /** @type {!ZelosInfo} */ (info);
415
+ if (maybeZelosInfo.rightSide) {
416
+ this.drawRenderedElem(maybeZelosInfo.rightSide, info.RTL);
417
+ }
415
418
 
416
- this.drawRender(block.pathObject.svgPath);
417
- };
419
+ this.drawBoundingBox(info);
420
+
421
+ this.drawRender(block.pathObject.svgPath);
422
+ }
418
423
 
424
+ /**
425
+ * Show a debug filter to highlight that a block has been rendered.
426
+ * @param {!SVGElement} svgPath The block's SVG path.
427
+ * @package
428
+ */
429
+ drawRender(svgPath) {
430
+ if (!Debug.config.render) {
431
+ return;
432
+ }
433
+ svgPath.setAttribute(
434
+ 'filter', 'url(#' + this.constants_.debugFilterId + ')');
435
+ setTimeout(function() {
436
+ svgPath.setAttribute('filter', '');
437
+ }, 100);
438
+ }
439
+ }
419
440
 
420
441
  /**
421
- * Show a debug filter to highlight that a block has been rendered.
422
- * @param {!SVGElement} svgPath The block's SVG path.
423
- * @package
442
+ * Configuration object containing booleans to enable and disable debug
443
+ * rendering of specific rendering components.
444
+ * @type {!Object<string, boolean>}
424
445
  */
425
- Debug.prototype.drawRender = function(svgPath) {
426
- if (!Debug.config.render) {
427
- return;
428
- }
429
- svgPath.setAttribute('filter', 'url(#' + this.constants_.debugFilterId + ')');
430
- setTimeout(function() {
431
- svgPath.setAttribute('filter', '');
432
- }, 100);
446
+ Debug.config = {
447
+ rowSpacers: true,
448
+ elemSpacers: true,
449
+ rows: true,
450
+ elems: true,
451
+ connections: true,
452
+ blockBounds: true,
453
+ connectedBlockBounds: true,
454
+ render: true,
433
455
  };
434
456
 
435
457
  exports.Debug = Debug;