blockly 8.0.5 → 9.0.0-beta.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 (736) hide show
  1. package/blockly.min.js +2002 -2269
  2. package/blockly_compressed.js +1499 -1994
  3. package/blockly_compressed.js.map +1 -1
  4. package/blocks/blocks.js +3 -2
  5. package/blocks/colour.js +3 -1
  6. package/blocks/lists.js +94 -22
  7. package/blocks/logic.js +14 -6
  8. package/blocks/loops.js +5 -3
  9. package/blocks/math.js +3 -1
  10. package/blocks/procedures.js +3 -1
  11. package/blocks/text.js +14 -6
  12. package/blocks/variables.js +3 -1
  13. package/blocks/variables_dynamic.js +3 -1
  14. package/blocks.d.ts +0 -2
  15. package/blocks_compressed.js +189 -171
  16. package/blocks_compressed.js.map +1 -1
  17. package/closure/goog/base.d.ts +1 -0
  18. package/closure/goog/base_minimal.d.ts +18 -0
  19. package/closure/goog/goog.d.ts +25 -0
  20. package/core/any_aliases.d.ts +1 -0
  21. package/core/any_aliases.ts +1 -0
  22. package/core/block.d.ts +779 -0
  23. package/core/{block.js → block.ts} +610 -719
  24. package/core/block_animations.d.ts +33 -0
  25. package/core/{block_animations.js → block_animations.ts} +75 -79
  26. package/core/block_drag_surface.d.ts +111 -0
  27. package/core/{block_drag_surface.js → block_drag_surface.ts} +85 -117
  28. package/core/block_dragger.d.ts +143 -0
  29. package/core/{block_dragger.js → block_dragger.ts} +139 -176
  30. package/core/block_svg.d.ts +588 -0
  31. package/core/{block_svg.js → block_svg.ts} +494 -630
  32. package/core/blockly.d.ts +562 -0
  33. package/core/blockly.js +1 -1
  34. package/core/blockly.ts +749 -0
  35. package/core/blockly_options.d.ts +69 -0
  36. package/core/blockly_options.ts +81 -0
  37. package/core/blocks.d.ts +17 -0
  38. package/core/{blocks.js → blocks.ts} +4 -8
  39. package/core/browser_events.d.ts +85 -0
  40. package/core/{browser_events.js → browser_events.ts} +98 -93
  41. package/core/bubble.d.ts +279 -0
  42. package/core/{bubble.js → bubble.ts} +277 -370
  43. package/core/bubble_dragger.d.ts +73 -0
  44. package/core/bubble_dragger.ts +229 -0
  45. package/core/bump_objects.d.ts +34 -0
  46. package/core/{bump_objects.js → bump_objects.ts} +54 -52
  47. package/core/clipboard.d.ts +42 -0
  48. package/core/clipboard.ts +91 -0
  49. package/core/comment.d.ts +113 -0
  50. package/core/{comment.js → comment.ts} +135 -185
  51. package/core/common.d.ts +129 -0
  52. package/core/{common.js → common.ts} +105 -82
  53. package/core/component_manager.d.ts +91 -0
  54. package/core/component_manager.ts +211 -0
  55. package/core/config.d.ts +23 -0
  56. package/core/{config.js → config.ts} +12 -19
  57. package/core/connection.d.ts +232 -0
  58. package/core/{connection.js → connection.ts} +187 -237
  59. package/core/connection_checker.d.ts +78 -0
  60. package/core/{connection_checker.js → connection_checker.ts} +66 -77
  61. package/core/connection_db.d.ts +91 -0
  62. package/core/{connection_db.js → connection_db.ts} +62 -87
  63. package/core/connection_type.d.ts +15 -0
  64. package/core/{connection_type.js → connection_type.ts} +8 -12
  65. package/core/constants.d.ts +15 -0
  66. package/core/{constants.js → constants.ts} +4 -8
  67. package/core/contextmenu.d.ts +80 -0
  68. package/core/{contextmenu.js → contextmenu.ts} +118 -153
  69. package/core/contextmenu_items.d.ts +77 -0
  70. package/core/contextmenu_items.ts +576 -0
  71. package/core/contextmenu_registry.d.ts +105 -0
  72. package/core/contextmenu_registry.ts +179 -0
  73. package/core/css.d.ts +24 -0
  74. package/core/{css.js → css.ts} +16 -24
  75. package/core/delete_area.d.ts +47 -0
  76. package/core/delete_area.ts +82 -0
  77. package/core/dialog.d.ts +61 -0
  78. package/core/dialog.ts +127 -0
  79. package/core/drag_target.d.ts +63 -0
  80. package/core/drag_target.ts +94 -0
  81. package/core/dropdowndiv.d.ts +155 -0
  82. package/core/{dropdowndiv.js → dropdowndiv.ts} +262 -333
  83. package/core/events/events.d.ts +102 -0
  84. package/core/events/events.ts +123 -0
  85. package/core/events/events_abstract.d.ts +51 -0
  86. package/core/events/events_abstract.ts +112 -0
  87. package/core/events/events_block_base.d.ts +31 -0
  88. package/core/events/events_block_base.ts +65 -0
  89. package/core/events/events_block_change.d.ts +55 -0
  90. package/core/events/{events_block_change.js → events_block_change.ts} +45 -48
  91. package/core/events/events_block_create.d.ts +35 -0
  92. package/core/events/{events_block_create.js → events_block_create.ts} +30 -35
  93. package/core/events/events_block_delete.d.ts +36 -0
  94. package/core/events/{events_block_delete.js → events_block_delete.ts} +34 -39
  95. package/core/events/events_block_drag.d.ts +36 -0
  96. package/core/events/events_block_drag.ts +82 -0
  97. package/core/events/events_block_move.d.ts +51 -0
  98. package/core/events/{events_block_move.js → events_block_move.ts} +54 -50
  99. package/core/events/events_bubble_open.d.ts +35 -0
  100. package/core/events/events_bubble_open.ts +82 -0
  101. package/core/events/events_click.d.ts +36 -0
  102. package/core/events/{events_click.js → events_click.ts} +27 -30
  103. package/core/events/events_comment_base.d.ts +39 -0
  104. package/core/events/events_comment_base.ts +107 -0
  105. package/core/events/events_comment_change.d.ts +43 -0
  106. package/core/events/{events_comment_change.js → events_comment_change.ts} +31 -28
  107. package/core/events/events_comment_create.d.ts +35 -0
  108. package/core/events/{events_comment_create.js → events_comment_create.ts} +24 -26
  109. package/core/events/events_comment_delete.d.ts +35 -0
  110. package/core/events/{events_comment_delete.js → events_comment_delete.ts} +20 -24
  111. package/core/events/events_comment_move.d.ts +55 -0
  112. package/core/events/{events_comment_move.js → events_comment_move.ts} +39 -42
  113. package/core/events/events_marker_move.d.ts +40 -0
  114. package/core/events/events_marker_move.ts +99 -0
  115. package/core/events/events_selected.d.ts +34 -0
  116. package/core/events/events_selected.ts +78 -0
  117. package/core/events/events_theme_change.d.ts +30 -0
  118. package/core/events/{events_theme_change.js → events_theme_change.ts} +19 -24
  119. package/core/events/events_toolbox_item_select.d.ts +34 -0
  120. package/core/events/events_toolbox_item_select.ts +79 -0
  121. package/core/events/events_trashcan_open.d.ts +31 -0
  122. package/core/events/events_trashcan_open.ts +68 -0
  123. package/core/events/events_ui.d.ts +37 -0
  124. package/core/events/{events_ui.js → events_ui.ts} +27 -26
  125. package/core/events/events_ui_base.d.ts +26 -0
  126. package/core/events/{events_ui_base.js → events_ui_base.ts} +17 -26
  127. package/core/events/events_var_base.d.ts +31 -0
  128. package/core/events/events_var_base.ts +65 -0
  129. package/core/events/events_var_create.d.ts +35 -0
  130. package/core/events/{events_var_create.js → events_var_create.ts} +24 -25
  131. package/core/events/events_var_delete.d.ts +35 -0
  132. package/core/events/{events_var_delete.js → events_var_delete.ts} +24 -25
  133. package/core/events/events_var_rename.d.ts +36 -0
  134. package/core/events/{events_var_rename.js → events_var_rename.ts} +25 -26
  135. package/core/events/events_viewport.d.ts +39 -0
  136. package/core/events/events_viewport.ts +100 -0
  137. package/core/events/utils.d.ts +272 -0
  138. package/core/events/{utils.js → utils.ts} +148 -219
  139. package/core/events/workspace_events.d.ts +36 -0
  140. package/core/events/workspace_events.ts +86 -0
  141. package/core/extensions.d.ts +107 -0
  142. package/core/{extensions.js → extensions.ts} +153 -172
  143. package/core/field.d.ts +534 -0
  144. package/core/{field.js → field.ts} +413 -489
  145. package/core/field_angle.d.ts +176 -0
  146. package/core/field_angle.ts +563 -0
  147. package/core/field_checkbox.d.ts +124 -0
  148. package/core/field_checkbox.ts +243 -0
  149. package/core/field_colour.d.ts +200 -0
  150. package/core/field_colour.ts +632 -0
  151. package/core/field_dropdown.d.ts +222 -0
  152. package/core/{field_dropdown.js → field_dropdown.ts} +277 -299
  153. package/core/field_image.d.ts +134 -0
  154. package/core/field_image.ts +282 -0
  155. package/core/field_label.d.ts +71 -0
  156. package/core/field_label.ts +152 -0
  157. package/core/field_label_serializable.d.ts +42 -0
  158. package/core/field_label_serializable.ts +76 -0
  159. package/core/field_multilineinput.d.ts +146 -0
  160. package/core/{field_multilineinput.js → field_multilineinput.ts} +166 -163
  161. package/core/field_number.d.ts +156 -0
  162. package/core/{field_number.js → field_number.ts} +110 -123
  163. package/core/field_registry.d.ts +45 -0
  164. package/core/{field_registry.js → field_registry.ts} +37 -30
  165. package/core/field_textinput.d.ts +219 -0
  166. package/core/field_textinput.ts +591 -0
  167. package/core/field_variable.d.ts +217 -0
  168. package/core/{field_variable.js → field_variable.ts} +174 -187
  169. package/core/flyout_base.d.ts +459 -0
  170. package/core/{flyout_base.js → flyout_base.ts} +429 -518
  171. package/core/flyout_button.d.ts +81 -0
  172. package/core/flyout_button.ts +292 -0
  173. package/core/flyout_horizontal.d.ts +82 -0
  174. package/core/{flyout_horizontal.js → flyout_horizontal.ts} +97 -107
  175. package/core/flyout_metrics_manager.d.ts +40 -0
  176. package/core/{flyout_metrics_manager.js → flyout_metrics_manager.ts} +22 -34
  177. package/core/flyout_vertical.d.ts +83 -0
  178. package/core/{flyout_vertical.js → flyout_vertical.ts} +106 -117
  179. package/core/generator.d.ts +205 -0
  180. package/core/{generator.js → generator.ts} +168 -193
  181. package/core/gesture.d.ts +357 -0
  182. package/core/{gesture.js → gesture.ts} +289 -369
  183. package/core/grid.d.ts +83 -0
  184. package/core/grid.ts +192 -0
  185. package/core/icon.d.ts +78 -0
  186. package/core/icon.ts +189 -0
  187. package/core/inject.d.ts +15 -0
  188. package/core/{inject.js → inject.ts} +101 -100
  189. package/core/input.d.ts +128 -0
  190. package/core/input.ts +309 -0
  191. package/core/input_types.d.ts +14 -0
  192. package/core/{input_types.js → input_types.ts} +8 -12
  193. package/core/insertion_marker_manager.d.ts +212 -0
  194. package/core/{insertion_marker_manager.js → insertion_marker_manager.ts} +234 -236
  195. package/core/interfaces/i_ast_node_location.d.ts +11 -0
  196. package/core/interfaces/{i_ast_node_location.js → i_ast_node_location.ts} +4 -7
  197. package/core/interfaces/i_ast_node_location_svg.d.ts +22 -0
  198. package/core/interfaces/i_ast_node_location_svg.ts +37 -0
  199. package/core/interfaces/i_ast_node_location_with_block.d.ts +18 -0
  200. package/core/interfaces/i_ast_node_location_with_block.ts +38 -0
  201. package/core/interfaces/i_autohideable.d.ts +18 -0
  202. package/core/interfaces/i_autohideable.ts +34 -0
  203. package/core/interfaces/i_block_dragger.d.ts +43 -0
  204. package/core/interfaces/i_block_dragger.ts +67 -0
  205. package/core/interfaces/i_bounded_element.d.ts +24 -0
  206. package/core/interfaces/i_bounded_element.ts +42 -0
  207. package/core/interfaces/i_bubble.d.ts +59 -0
  208. package/core/interfaces/i_bubble.ts +88 -0
  209. package/core/interfaces/i_collapsible_toolbox_item.d.ts +26 -0
  210. package/core/interfaces/i_collapsible_toolbox_item.ts +47 -0
  211. package/core/interfaces/i_component.d.ts +17 -0
  212. package/core/interfaces/{i_component.js → i_component.ts} +9 -14
  213. package/core/interfaces/i_connection_checker.d.ts +69 -0
  214. package/core/interfaces/i_connection_checker.ts +102 -0
  215. package/core/interfaces/i_contextmenu.d.ts +13 -0
  216. package/core/interfaces/i_contextmenu.ts +26 -0
  217. package/core/interfaces/i_copyable.d.ts +24 -0
  218. package/core/interfaces/i_copyable.ts +40 -0
  219. package/core/interfaces/i_deletable.d.ts +16 -0
  220. package/core/interfaces/{i_deletable.js → i_deletable.ts} +9 -13
  221. package/core/interfaces/i_delete_area.d.ts +25 -0
  222. package/core/interfaces/i_delete_area.ts +46 -0
  223. package/core/interfaces/i_drag_target.d.ts +53 -0
  224. package/core/interfaces/i_drag_target.ts +84 -0
  225. package/core/interfaces/i_draggable.d.ts +12 -0
  226. package/core/interfaces/{i_draggable.js → i_draggable.ts} +4 -10
  227. package/core/interfaces/i_flyout.d.ts +134 -0
  228. package/core/interfaces/i_flyout.ts +186 -0
  229. package/core/interfaces/i_keyboard_accessible.d.ts +18 -0
  230. package/core/interfaces/i_keyboard_accessible.ts +35 -0
  231. package/core/interfaces/i_metrics_manager.d.ts +117 -0
  232. package/core/interfaces/i_metrics_manager.ts +151 -0
  233. package/core/interfaces/i_movable.d.ts +16 -0
  234. package/core/interfaces/{i_movable.js → i_movable.ts} +9 -13
  235. package/core/interfaces/i_positionable.d.ts +27 -0
  236. package/core/interfaces/i_positionable.ts +50 -0
  237. package/core/interfaces/i_registrable.d.ts +11 -0
  238. package/core/interfaces/{i_registrable.js → i_registrable.ts} +3 -7
  239. package/core/interfaces/i_registrable_field.d.ts +17 -0
  240. package/core/interfaces/{i_registrable_field.js → i_registrable_field.ts} +8 -16
  241. package/core/interfaces/i_selectable.d.ts +18 -0
  242. package/core/interfaces/i_selectable.ts +34 -0
  243. package/core/interfaces/i_selectable_toolbox_item.d.ts +42 -0
  244. package/core/interfaces/i_selectable_toolbox_item.ts +64 -0
  245. package/core/interfaces/i_serializer.d.ts +42 -0
  246. package/core/interfaces/i_serializer.ts +65 -0
  247. package/core/interfaces/i_styleable.d.ts +21 -0
  248. package/core/interfaces/i_styleable.ts +35 -0
  249. package/core/interfaces/i_toolbox.d.ts +85 -0
  250. package/core/interfaces/i_toolbox.ts +127 -0
  251. package/core/interfaces/i_toolbox_item.d.ts +62 -0
  252. package/core/interfaces/i_toolbox_item.ts +84 -0
  253. package/core/internal_constants.d.ts +40 -0
  254. package/core/{internal_constants.js → internal_constants.ts} +13 -18
  255. package/core/keyboard_nav/ast_node.d.ts +239 -0
  256. package/core/keyboard_nav/{ast_node.js → ast_node.ts} +207 -231
  257. package/core/keyboard_nav/basic_cursor.d.ts +88 -0
  258. package/core/keyboard_nav/{basic_cursor.js → basic_cursor.ts} +55 -66
  259. package/core/keyboard_nav/cursor.d.ts +41 -0
  260. package/core/keyboard_nav/{cursor.js → cursor.ts} +25 -35
  261. package/core/keyboard_nav/marker.d.ts +58 -0
  262. package/core/keyboard_nav/{marker.js → marker.ts} +36 -55
  263. package/core/keyboard_nav/tab_navigate_cursor.d.ts +19 -0
  264. package/core/keyboard_nav/{tab_navigate_cursor.js → tab_navigate_cursor.ts} +11 -15
  265. package/core/main.d.ts +11 -0
  266. package/core/main.js +303 -0
  267. package/core/marker_manager.d.ts +85 -0
  268. package/core/marker_manager.ts +181 -0
  269. package/core/menu.d.ts +149 -0
  270. package/core/{menu.js → menu.ts} +141 -174
  271. package/core/menuitem.d.ts +118 -0
  272. package/core/menuitem.ts +240 -0
  273. package/core/metrics_manager.d.ts +201 -0
  274. package/core/{metrics_manager.js → metrics_manager.ts} +117 -156
  275. package/core/msg.d.ts +9 -0
  276. package/core/{msg.js → msg.ts} +4 -8
  277. package/core/mutator.d.ts +128 -0
  278. package/core/{mutator.js → mutator.ts} +196 -211
  279. package/core/names.d.ts +124 -0
  280. package/core/names.ts +267 -0
  281. package/core/options.d.ts +137 -0
  282. package/core/{options.js → options.ts} +147 -173
  283. package/core/positionable_helpers.d.ts +88 -0
  284. package/core/{positionable_helpers.js → positionable_helpers.ts} +63 -70
  285. package/core/procedures.d.ts +108 -0
  286. package/core/{procedures.js → procedures.ts} +143 -152
  287. package/core/registry.d.ts +137 -0
  288. package/core/registry.ts +339 -0
  289. package/core/rendered_connection.d.ts +191 -0
  290. package/core/{rendered_connection.js → rendered_connection.ts} +164 -184
  291. package/core/renderers/common/block_rendering.d.ts +114 -0
  292. package/core/renderers/common/block_rendering.ts +164 -0
  293. package/core/renderers/common/constants.d.ts +458 -0
  294. package/core/renderers/common/constants.ts +1124 -0
  295. package/core/renderers/common/debug.d.ts +28 -0
  296. package/core/renderers/common/{debug.js → debug.ts} +14 -20
  297. package/core/renderers/common/debugger.d.ts +120 -0
  298. package/core/renderers/common/{debugger.js → debugger.ts} +100 -124
  299. package/core/renderers/common/drawer.d.ts +132 -0
  300. package/core/renderers/common/{drawer.js → drawer.ts} +112 -137
  301. package/core/renderers/common/i_path_object.d.ts +117 -0
  302. package/core/renderers/common/i_path_object.ts +161 -0
  303. package/core/renderers/common/info.d.ts +194 -0
  304. package/core/renderers/common/{info.js → info.ts} +165 -222
  305. package/core/renderers/common/marker_svg.d.ts +220 -0
  306. package/core/renderers/common/marker_svg.ts +680 -0
  307. package/core/renderers/common/path_object.d.ts +146 -0
  308. package/core/renderers/common/path_object.ts +272 -0
  309. package/core/renderers/common/renderer.d.ts +157 -0
  310. package/core/renderers/common/renderer.ts +271 -0
  311. package/core/renderers/geras/constants.d.ts +23 -0
  312. package/core/renderers/geras/constants.ts +61 -0
  313. package/core/renderers/geras/drawer.d.ts +43 -0
  314. package/core/renderers/geras/{drawer.js → drawer.ts} +40 -84
  315. package/core/renderers/geras/geras.d.ts +11 -0
  316. package/core/renderers/geras/geras.ts +37 -0
  317. package/core/renderers/geras/highlight_constants.d.ts +108 -0
  318. package/core/renderers/geras/{highlight_constants.js → highlight_constants.ts} +107 -69
  319. package/core/renderers/geras/highlighter.d.ts +98 -0
  320. package/core/renderers/geras/{highlighter.js → highlighter.ts} +81 -86
  321. package/core/renderers/geras/info.d.ts +45 -0
  322. package/core/renderers/geras/{info.js → info.ts} +61 -99
  323. package/core/renderers/geras/measurables/inline_input.d.ts +23 -0
  324. package/core/renderers/geras/measurables/inline_input.ts +51 -0
  325. package/core/renderers/geras/measurables/statement_input.d.ts +23 -0
  326. package/core/renderers/geras/measurables/statement_input.ts +50 -0
  327. package/core/renderers/geras/path_object.d.ts +47 -0
  328. package/core/renderers/geras/{path_object.js → path_object.ts} +46 -74
  329. package/core/renderers/geras/renderer.d.ts +69 -0
  330. package/core/renderers/geras/renderer.ts +126 -0
  331. package/core/renderers/measurables/base.d.ts +27 -0
  332. package/core/renderers/measurables/base.ts +53 -0
  333. package/core/renderers/measurables/bottom_row.d.ts +61 -0
  334. package/core/renderers/measurables/bottom_row.ts +120 -0
  335. package/core/renderers/measurables/connection.d.ts +25 -0
  336. package/core/renderers/measurables/connection.ts +52 -0
  337. package/core/renderers/measurables/external_value_input.d.ts +27 -0
  338. package/core/renderers/measurables/external_value_input.ts +65 -0
  339. package/core/renderers/measurables/field.d.ts +30 -0
  340. package/core/renderers/measurables/field.ts +63 -0
  341. package/core/renderers/measurables/hat.d.ts +21 -0
  342. package/core/renderers/measurables/{hat.js → hat.ts} +12 -14
  343. package/core/renderers/measurables/icon.d.ts +26 -0
  344. package/core/renderers/measurables/{icon.js → icon.ts} +14 -18
  345. package/core/renderers/measurables/in_row_spacer.d.ts +21 -0
  346. package/core/renderers/measurables/in_row_spacer.ts +44 -0
  347. package/core/renderers/measurables/inline_input.d.ts +24 -0
  348. package/core/renderers/measurables/{inline_input.js → inline_input.ts} +22 -26
  349. package/core/renderers/measurables/input_connection.d.ts +29 -0
  350. package/core/renderers/measurables/input_connection.ts +66 -0
  351. package/core/renderers/measurables/input_row.d.ts +30 -0
  352. package/core/renderers/measurables/{input_row.js → input_row.ts} +24 -31
  353. package/core/renderers/measurables/jagged_edge.d.ts +20 -0
  354. package/core/renderers/measurables/{jagged_edge.js → jagged_edge.ts} +10 -13
  355. package/core/renderers/measurables/next_connection.d.ts +23 -0
  356. package/core/renderers/measurables/next_connection.ts +47 -0
  357. package/core/renderers/measurables/output_connection.d.ts +26 -0
  358. package/core/renderers/measurables/output_connection.ts +56 -0
  359. package/core/renderers/measurables/previous_connection.d.ts +23 -0
  360. package/core/renderers/measurables/previous_connection.ts +47 -0
  361. package/core/renderers/measurables/round_corner.d.ts +21 -0
  362. package/core/renderers/measurables/round_corner.ts +49 -0
  363. package/core/renderers/measurables/row.d.ts +141 -0
  364. package/core/renderers/measurables/row.ts +225 -0
  365. package/core/renderers/measurables/spacer_row.d.ts +29 -0
  366. package/core/renderers/measurables/spacer_row.ts +55 -0
  367. package/core/renderers/measurables/square_corner.d.ts +21 -0
  368. package/core/renderers/measurables/square_corner.ts +47 -0
  369. package/core/renderers/measurables/statement_input.d.ts +22 -0
  370. package/core/renderers/measurables/{statement_input.js → statement_input.ts} +14 -18
  371. package/core/renderers/measurables/top_row.d.ts +56 -0
  372. package/core/renderers/measurables/top_row.ts +122 -0
  373. package/core/renderers/measurables/types.d.ts +235 -0
  374. package/core/renderers/measurables/types.ts +332 -0
  375. package/core/renderers/minimalist/constants.d.ts +14 -0
  376. package/core/renderers/minimalist/{constants.js → constants.ts} +5 -10
  377. package/core/renderers/minimalist/drawer.d.ts +21 -0
  378. package/core/renderers/minimalist/drawer.ts +38 -0
  379. package/core/renderers/minimalist/info.d.ts +30 -0
  380. package/core/renderers/minimalist/info.ts +52 -0
  381. package/core/renderers/minimalist/minimalist.d.ts +6 -0
  382. package/core/renderers/minimalist/minimalist.ts +22 -0
  383. package/core/renderers/minimalist/renderer.d.ts +41 -0
  384. package/core/renderers/minimalist/renderer.ts +71 -0
  385. package/core/renderers/thrasos/info.d.ts +40 -0
  386. package/core/renderers/thrasos/{info.js → info.ts} +66 -67
  387. package/core/renderers/thrasos/renderer.d.ts +25 -0
  388. package/core/renderers/thrasos/renderer.ts +48 -0
  389. package/core/renderers/thrasos/thrasos.d.ts +4 -0
  390. package/core/renderers/thrasos/thrasos.ts +20 -0
  391. package/core/renderers/zelos/constants.d.ts +186 -0
  392. package/core/renderers/zelos/{constants.js → constants.ts} +294 -441
  393. package/core/renderers/zelos/drawer.d.ts +47 -0
  394. package/core/renderers/zelos/{drawer.js → drawer.ts} +73 -95
  395. package/core/renderers/zelos/info.d.ts +88 -0
  396. package/core/renderers/zelos/{info.js → info.ts} +111 -142
  397. package/core/renderers/zelos/marker_svg.d.ts +46 -0
  398. package/core/renderers/zelos/marker_svg.ts +151 -0
  399. package/core/renderers/zelos/measurables/bottom_row.d.ts +27 -0
  400. package/core/renderers/zelos/measurables/bottom_row.ts +53 -0
  401. package/core/renderers/zelos/measurables/inputs.d.ts +23 -0
  402. package/core/renderers/zelos/measurables/{inputs.js → inputs.ts} +14 -15
  403. package/core/renderers/zelos/measurables/row_elements.d.ts +21 -0
  404. package/core/renderers/zelos/measurables/row_elements.ts +45 -0
  405. package/core/renderers/zelos/measurables/top_row.d.ts +29 -0
  406. package/core/renderers/zelos/measurables/{top_row.js → top_row.ts} +14 -27
  407. package/core/renderers/zelos/path_object.d.ts +77 -0
  408. package/core/renderers/zelos/path_object.ts +215 -0
  409. package/core/renderers/zelos/renderer.d.ts +74 -0
  410. package/core/renderers/zelos/renderer.ts +142 -0
  411. package/core/renderers/zelos/zelos.d.ts +12 -0
  412. package/core/renderers/zelos/zelos.ts +39 -0
  413. package/core/scrollbar.d.ts +277 -0
  414. package/core/{scrollbar.js → scrollbar.ts} +307 -328
  415. package/core/scrollbar_pair.d.ts +105 -0
  416. package/core/{scrollbar_pair.js → scrollbar_pair.ts} +71 -79
  417. package/core/serialization/blocks.d.ts +98 -0
  418. package/core/serialization/{blocks.js → blocks.ts} +229 -228
  419. package/core/serialization/exceptions.d.ts +73 -0
  420. package/core/serialization/exceptions.ts +98 -0
  421. package/core/serialization/priorities.d.ts +15 -0
  422. package/core/serialization/{priorities.js → priorities.ts} +4 -10
  423. package/core/serialization/registry.d.ts +20 -0
  424. package/core/serialization/{registry.js → registry.ts} +11 -13
  425. package/core/serialization/variables.d.ts +14 -0
  426. package/core/serialization/{variables.js → variables.ts} +30 -32
  427. package/core/serialization/workspaces.d.ts +28 -0
  428. package/core/serialization/{workspaces.js → workspaces.ts} +30 -27
  429. package/core/shortcut_items.d.ts +61 -0
  430. package/core/{shortcut_items.js → shortcut_items.ts} +121 -157
  431. package/core/shortcut_registry.d.ts +151 -0
  432. package/core/shortcut_registry.ts +355 -0
  433. package/core/sprites.d.ts +19 -0
  434. package/core/{sprites.js → sprites.ts} +4 -6
  435. package/core/theme/classic.d.ts +12 -0
  436. package/core/theme/{classic.js → classic.ts} +5 -7
  437. package/core/theme/themes.d.ts +8 -0
  438. package/core/theme/themes.ts +22 -0
  439. package/core/theme/zelos.d.ts +11 -0
  440. package/core/theme/{zelos.js → zelos.ts} +4 -7
  441. package/core/theme.d.ts +142 -0
  442. package/core/theme.ts +221 -0
  443. package/core/theme_manager.d.ts +81 -0
  444. package/core/theme_manager.ts +186 -0
  445. package/core/toolbox/category.d.ts +239 -0
  446. package/core/toolbox/category.ts +679 -0
  447. package/core/toolbox/collapsible_category.d.ts +91 -0
  448. package/core/toolbox/collapsible_category.ts +273 -0
  449. package/core/toolbox/separator.d.ts +39 -0
  450. package/core/toolbox/separator.ts +105 -0
  451. package/core/toolbox/toolbox.d.ts +352 -0
  452. package/core/toolbox/{toolbox.js → toolbox.ts} +316 -432
  453. package/core/toolbox/toolbox_item.d.ts +85 -0
  454. package/core/toolbox/toolbox_item.ts +147 -0
  455. package/core/tooltip.d.ts +126 -0
  456. package/core/{tooltip.js → tooltip.ts} +136 -214
  457. package/core/touch.d.ts +121 -0
  458. package/core/touch.ts +306 -0
  459. package/core/touch_gesture.d.ts +115 -0
  460. package/core/{touch_gesture.js → touch_gesture.ts} +87 -125
  461. package/core/trashcan.d.ts +195 -0
  462. package/core/{trashcan.js → trashcan.ts} +226 -312
  463. package/core/utils/aria.d.ts +67 -0
  464. package/core/utils/{aria.js → aria.ts} +47 -61
  465. package/core/utils/array.d.ts +14 -0
  466. package/core/utils/{array.js → array.ts} +10 -12
  467. package/core/utils/colour.d.ts +103 -0
  468. package/core/utils/{colour.js → colour.ts} +60 -72
  469. package/core/utils/coordinate.d.ts +72 -0
  470. package/core/utils/coordinate.ts +124 -0
  471. package/core/utils/deprecation.d.ts +17 -0
  472. package/core/utils/{deprecation.js → deprecation.ts} +11 -11
  473. package/core/utils/dom.d.ts +165 -0
  474. package/core/utils/{dom.js → dom.ts} +125 -147
  475. package/core/utils/idgenerator.d.ts +25 -0
  476. package/core/utils/{idgenerator.js → idgenerator.ts} +15 -18
  477. package/core/utils/keycodes.d.ts +137 -0
  478. package/core/utils/keycodes.ts +169 -0
  479. package/core/utils/math.d.ts +30 -0
  480. package/core/utils/{math.js → math.ts} +17 -19
  481. package/core/utils/metrics.d.ts +64 -0
  482. package/core/utils/metrics.ts +97 -0
  483. package/core/utils/object.d.ts +35 -0
  484. package/core/utils/{object.js → object.ts} +30 -26
  485. package/core/utils/parsing.d.ts +50 -0
  486. package/core/utils/{parsing.js → parsing.ts} +50 -50
  487. package/core/utils/rect.d.ts +38 -0
  488. package/core/utils/{rect.js → rect.ts} +18 -31
  489. package/core/utils/sentinel.d.ts +11 -0
  490. package/core/utils/{sentinel.js → sentinel.ts} +3 -5
  491. package/core/utils/size.d.ts +27 -0
  492. package/core/utils/{size.js → size.ts} +12 -26
  493. package/core/utils/string.d.ts +55 -0
  494. package/core/utils/{string.js → string.ts} +64 -61
  495. package/core/utils/style.d.ts +127 -0
  496. package/core/utils/{style.js → style.ts} +102 -92
  497. package/core/utils/svg.d.ts +68 -0
  498. package/core/utils/svg.ts +88 -0
  499. package/core/utils/svg_math.d.ts +70 -0
  500. package/core/utils/{svg_math.js → svg_math.ts} +72 -71
  501. package/core/utils/svg_paths.d.ts +101 -0
  502. package/core/utils/{svg_paths.js → svg_paths.ts} +56 -65
  503. package/core/utils/toolbox.d.ts +193 -0
  504. package/core/utils/toolbox.ts +433 -0
  505. package/core/utils/useragent.d.ts +33 -0
  506. package/core/utils/useragent.ts +135 -0
  507. package/core/utils/xml.d.ts +52 -0
  508. package/core/utils/{xml.js → xml.ts} +26 -36
  509. package/core/utils.d.ts +217 -0
  510. package/core/utils.ts +428 -0
  511. package/core/variable_map.d.ts +141 -0
  512. package/core/{variable_map.js → variable_map.ts} +131 -149
  513. package/core/variable_model.d.ts +40 -0
  514. package/core/variable_model.ts +82 -0
  515. package/core/variables.d.ts +181 -0
  516. package/core/{variables.js → variables.ts} +206 -188
  517. package/core/variables_dynamic.d.ts +38 -0
  518. package/core/{variables_dynamic.js → variables_dynamic.ts} +47 -43
  519. package/core/warning.d.ts +50 -0
  520. package/core/{warning.js → warning.ts} +52 -66
  521. package/core/widgetdiv.d.ts +69 -0
  522. package/core/widgetdiv.ts +257 -0
  523. package/core/workspace.d.ts +386 -0
  524. package/core/workspace.ts +801 -0
  525. package/core/workspace_audio.d.ts +47 -0
  526. package/core/{workspace_audio.js → workspace_audio.ts} +47 -60
  527. package/core/workspace_comment.d.ts +170 -0
  528. package/core/workspace_comment.ts +398 -0
  529. package/core/workspace_comment_svg.d.ts +329 -0
  530. package/core/{workspace_comment_svg.js → workspace_comment_svg.ts} +347 -444
  531. package/core/workspace_drag_surface_svg.d.ts +68 -0
  532. package/core/{workspace_drag_surface_svg.js → workspace_drag_surface_svg.ts} +75 -82
  533. package/core/workspace_dragger.d.ts +48 -0
  534. package/core/workspace_dragger.ts +104 -0
  535. package/core/workspace_svg.d.ts +920 -0
  536. package/core/{workspace_svg.js → workspace_svg.ts} +855 -935
  537. package/core/xml.d.ts +117 -0
  538. package/core/{xml.js → xml.ts} +306 -326
  539. package/core/zoom_controls.d.ts +130 -0
  540. package/core/{zoom_controls.js → zoom_controls.ts} +185 -251
  541. package/core.d.ts +1 -3
  542. package/core.js +1 -2
  543. package/dart.d.ts +0 -3
  544. package/dart_compressed.js +387 -99
  545. package/dart_compressed.js.map +1 -1
  546. package/generators/dart/all.js +2 -0
  547. package/generators/dart/colour.js +1 -1
  548. package/generators/dart/lists.js +1 -1
  549. package/generators/dart/logic.js +1 -1
  550. package/generators/dart/loops.js +1 -1
  551. package/generators/dart/math.js +1 -1
  552. package/generators/dart/procedures.js +1 -1
  553. package/generators/dart/text.js +1 -1
  554. package/generators/dart/variables.js +1 -1
  555. package/generators/dart/variables_dynamic.js +1 -1
  556. package/generators/dart.js +1 -2
  557. package/generators/javascript/all.js +2 -0
  558. package/generators/javascript/colour.js +1 -1
  559. package/generators/javascript/lists.js +1 -1
  560. package/generators/javascript/logic.js +1 -1
  561. package/generators/javascript/loops.js +1 -1
  562. package/generators/javascript/math.js +4 -4
  563. package/generators/javascript/procedures.js +1 -1
  564. package/generators/javascript/text.js +2 -2
  565. package/generators/javascript/variables.js +1 -1
  566. package/generators/javascript/variables_dynamic.js +1 -1
  567. package/generators/javascript.js +1 -3
  568. package/generators/lua/all.js +2 -0
  569. package/generators/lua/colour.js +1 -1
  570. package/generators/lua/lists.js +1 -1
  571. package/generators/lua/logic.js +1 -1
  572. package/generators/lua/loops.js +1 -1
  573. package/generators/lua/math.js +1 -1
  574. package/generators/lua/procedures.js +1 -1
  575. package/generators/lua/text.js +1 -1
  576. package/generators/lua/variables.js +1 -1
  577. package/generators/lua/variables_dynamic.js +1 -1
  578. package/generators/lua.js +1 -2
  579. package/generators/php/all.js +2 -0
  580. package/generators/php/colour.js +1 -1
  581. package/generators/php/lists.js +1 -2
  582. package/generators/php/logic.js +1 -1
  583. package/generators/php/loops.js +1 -1
  584. package/generators/php/math.js +1 -1
  585. package/generators/php/procedures.js +1 -1
  586. package/generators/php/text.js +1 -1
  587. package/generators/php/variables.js +1 -1
  588. package/generators/php/variables_dynamic.js +1 -1
  589. package/generators/php.js +1 -2
  590. package/generators/python/all.js +2 -0
  591. package/generators/python/colour.js +3 -3
  592. package/generators/python/lists.js +1 -1
  593. package/generators/python/logic.js +1 -1
  594. package/generators/python/loops.js +4 -7
  595. package/generators/python/math.js +1 -1
  596. package/generators/python/procedures.js +1 -1
  597. package/generators/python/text.js +1 -1
  598. package/generators/python/variables.js +1 -1
  599. package/generators/python/variables_dynamic.js +1 -1
  600. package/generators/python.js +1 -2
  601. package/index.d.ts +2 -8
  602. package/javascript.d.ts +0 -3
  603. package/javascript_compressed.js +314 -104
  604. package/javascript_compressed.js.map +1 -1
  605. package/lua.d.ts +0 -3
  606. package/lua_compressed.js +399 -81
  607. package/lua_compressed.js.map +1 -1
  608. package/package.json +5 -5
  609. package/php.d.ts +0 -3
  610. package/php_compressed.js +322 -93
  611. package/php_compressed.js.map +1 -1
  612. package/python.d.ts +0 -3
  613. package/python_compressed.js +237 -90
  614. package/python_compressed.js.map +1 -1
  615. package/blockly.d.ts +0 -26127
  616. package/core/blockly_options.js +0 -28
  617. package/core/bubble_dragger.js +0 -298
  618. package/core/clipboard.js +0 -80
  619. package/core/component_manager.js +0 -263
  620. package/core/contextmenu_items.js +0 -651
  621. package/core/contextmenu_registry.js +0 -178
  622. package/core/delete_area.js +0 -87
  623. package/core/dialog.js +0 -107
  624. package/core/drag_target.js +0 -98
  625. package/core/events/events.js +0 -147
  626. package/core/events/events_abstract.js +0 -133
  627. package/core/events/events_block_base.js +0 -70
  628. package/core/events/events_block_drag.js +0 -89
  629. package/core/events/events_bubble_open.js +0 -90
  630. package/core/events/events_comment_base.js +0 -121
  631. package/core/events/events_marker_move.js +0 -110
  632. package/core/events/events_selected.js +0 -83
  633. package/core/events/events_toolbox_item_select.js +0 -84
  634. package/core/events/events_trashcan_open.js +0 -73
  635. package/core/events/events_var_base.js +0 -70
  636. package/core/events/events_viewport.js +0 -107
  637. package/core/events/workspace_events.js +0 -93
  638. package/core/field_angle.js +0 -591
  639. package/core/field_checkbox.js +0 -255
  640. package/core/field_colour.js +0 -717
  641. package/core/field_image.js +0 -304
  642. package/core/field_label.js +0 -149
  643. package/core/field_label_serializable.js +0 -80
  644. package/core/field_textinput.js +0 -619
  645. package/core/flyout_button.js +0 -356
  646. package/core/grid.js +0 -226
  647. package/core/icon.js +0 -225
  648. package/core/input.js +0 -335
  649. package/core/interfaces/i_ast_node_location_svg.js +0 -45
  650. package/core/interfaces/i_ast_node_location_with_block.js +0 -41
  651. package/core/interfaces/i_autohideable.js +0 -40
  652. package/core/interfaces/i_block_dragger.js +0 -66
  653. package/core/interfaces/i_bounded_element.js +0 -45
  654. package/core/interfaces/i_bubble.js +0 -95
  655. package/core/interfaces/i_collapsible_toolbox_item.js +0 -53
  656. package/core/interfaces/i_connection_checker.js +0 -104
  657. package/core/interfaces/i_contextmenu.js +0 -32
  658. package/core/interfaces/i_copyable.js +0 -49
  659. package/core/interfaces/i_delete_area.js +0 -50
  660. package/core/interfaces/i_drag_target.js +0 -88
  661. package/core/interfaces/i_flyout.js +0 -201
  662. package/core/interfaces/i_keyboard_accessible.js +0 -38
  663. package/core/interfaces/i_metrics_manager.js +0 -154
  664. package/core/interfaces/i_positionable.js +0 -51
  665. package/core/interfaces/i_selectable.js +0 -51
  666. package/core/interfaces/i_selectable_toolbox_item.js +0 -73
  667. package/core/interfaces/i_serializer.js +0 -77
  668. package/core/interfaces/i_styleable.js +0 -39
  669. package/core/interfaces/i_toolbox.js +0 -142
  670. package/core/interfaces/i_toolbox_item.js +0 -85
  671. package/core/marker_manager.js +0 -213
  672. package/core/menuitem.js +0 -292
  673. package/core/names.js +0 -293
  674. package/core/registry.js +0 -384
  675. package/core/renderers/common/block_rendering.js +0 -170
  676. package/core/renderers/common/constants.js +0 -1250
  677. package/core/renderers/common/i_path_object.js +0 -162
  678. package/core/renderers/common/marker_svg.js +0 -721
  679. package/core/renderers/common/path_object.js +0 -283
  680. package/core/renderers/common/renderer.js +0 -305
  681. package/core/renderers/geras/constants.js +0 -73
  682. package/core/renderers/geras/geras.js +0 -36
  683. package/core/renderers/geras/measurables/inline_input.js +0 -58
  684. package/core/renderers/geras/measurables/statement_input.js +0 -57
  685. package/core/renderers/geras/renderer.js +0 -149
  686. package/core/renderers/measurables/base.js +0 -64
  687. package/core/renderers/measurables/bottom_row.js +0 -138
  688. package/core/renderers/measurables/connection.js +0 -56
  689. package/core/renderers/measurables/external_value_input.js +0 -70
  690. package/core/renderers/measurables/field.js +0 -71
  691. package/core/renderers/measurables/in_row_spacer.js +0 -47
  692. package/core/renderers/measurables/input_connection.js +0 -75
  693. package/core/renderers/measurables/next_connection.js +0 -50
  694. package/core/renderers/measurables/output_connection.js +0 -61
  695. package/core/renderers/measurables/previous_connection.js +0 -50
  696. package/core/renderers/measurables/round_corner.js +0 -52
  697. package/core/renderers/measurables/row.js +0 -247
  698. package/core/renderers/measurables/spacer_row.js +0 -69
  699. package/core/renderers/measurables/square_corner.js +0 -50
  700. package/core/renderers/measurables/top_row.js +0 -143
  701. package/core/renderers/measurables/types.js +0 -353
  702. package/core/renderers/minimalist/drawer.js +0 -42
  703. package/core/renderers/minimalist/info.js +0 -54
  704. package/core/renderers/minimalist/minimalist.js +0 -26
  705. package/core/renderers/minimalist/renderer.js +0 -80
  706. package/core/renderers/thrasos/renderer.js +0 -53
  707. package/core/renderers/thrasos/thrasos.js +0 -22
  708. package/core/renderers/zelos/marker_svg.js +0 -179
  709. package/core/renderers/zelos/measurables/bottom_row.js +0 -66
  710. package/core/renderers/zelos/measurables/row_elements.js +0 -46
  711. package/core/renderers/zelos/path_object.js +0 -247
  712. package/core/renderers/zelos/renderer.js +0 -147
  713. package/core/renderers/zelos/zelos.js +0 -38
  714. package/core/serialization/exceptions.js +0 -144
  715. package/core/shortcut_registry.js +0 -366
  716. package/core/theme/themes.js +0 -23
  717. package/core/theme.js +0 -228
  718. package/core/theme_manager.js +0 -211
  719. package/core/toolbox/category.js +0 -751
  720. package/core/toolbox/collapsible_category.js +0 -311
  721. package/core/toolbox/separator.js +0 -133
  722. package/core/toolbox/toolbox_item.js +0 -173
  723. package/core/touch.js +0 -285
  724. package/core/utils/coordinate.js +0 -138
  725. package/core/utils/global.js +0 -41
  726. package/core/utils/keycodes.js +0 -172
  727. package/core/utils/metrics.js +0 -154
  728. package/core/utils/svg.js +0 -186
  729. package/core/utils/toolbox.js +0 -459
  730. package/core/utils/useragent.js +0 -197
  731. package/core/utils.js +0 -383
  732. package/core/variable_model.js +0 -96
  733. package/core/widgetdiv.js +0 -290
  734. package/core/workspace.js +0 -836
  735. package/core/workspace_comment.js +0 -400
  736. package/core/workspace_dragger.js +0 -115
@@ -7,422 +7,393 @@
7
7
  /**
8
8
  * @fileoverview Object representing a workspace rendered as SVG.
9
9
  */
10
- 'use strict';
11
10
 
12
11
  /**
13
12
  * Object representing a workspace rendered as SVG.
14
13
  * @class
15
14
  */
16
- goog.module('Blockly.WorkspaceSvg');
15
+ import * as goog from '../closure/goog/goog.js';
16
+ goog.declareModuleId('Blockly.WorkspaceSvg');
17
17
 
18
- const ContextMenu = goog.require('Blockly.ContextMenu');
19
18
  /* eslint-disable-next-line no-unused-vars */
20
- const Procedures = goog.requireType('Blockly.Procedures');
21
- const Tooltip = goog.require('Blockly.Tooltip');
19
+ // Unused import preserved for side-effects. Remove if unneeded.
20
+ // import './procedures.js';
22
21
  /* eslint-disable-next-line no-unused-vars */
23
- const Variables = goog.requireType('Blockly.Variables');
22
+ // Unused import preserved for side-effects. Remove if unneeded.
23
+ // import './variables.js';
24
24
  /* eslint-disable-next-line no-unused-vars */
25
- const VariablesDynamic = goog.requireType('Blockly.VariablesDynamic');
26
- const WidgetDiv = goog.require('Blockly.WidgetDiv');
27
- const Xml = goog.require('Blockly.Xml');
28
- const arrayUtils = goog.require('Blockly.utils.array');
29
- const blockRendering = goog.require('Blockly.blockRendering');
30
- const blocks = goog.require('Blockly.serialization.blocks');
31
- const browserEvents = goog.require('Blockly.browserEvents');
32
- const common = goog.require('Blockly.common');
33
- const dom = goog.require('Blockly.utils.dom');
34
- const dropDownDiv = goog.require('Blockly.dropDownDiv');
35
- const eventUtils = goog.require('Blockly.Events.utils');
36
- const registry = goog.require('Blockly.registry');
37
- const svgMath = goog.require('Blockly.utils.svgMath');
38
- const toolbox = goog.require('Blockly.utils.toolbox');
39
- const userAgent = goog.require('Blockly.utils.userAgent');
40
- const utils = goog.require('Blockly.utils');
25
+ // Unused import preserved for side-effects. Remove if unneeded.
26
+ // import './variables_dynamic.js';
41
27
  /* eslint-disable-next-line no-unused-vars */
42
- const {BlockDragSurfaceSvg} = goog.requireType('Blockly.BlockDragSurfaceSvg');
43
- const {BlockSvg} = goog.require('Blockly.BlockSvg');
28
+ // Unused import preserved for side-effects. Remove if unneeded.
29
+ // import './rendered_connection.js';
44
30
  /* eslint-disable-next-line no-unused-vars */
45
- const {BlocklyOptions} = goog.requireType('Blockly.BlocklyOptions');
46
- /* eslint-disable-next-line no-unused-vars */
47
- const {Block} = goog.requireType('Blockly.Block');
48
- const {Classic} = goog.require('Blockly.Themes.Classic');
49
- const {ComponentManager} = goog.require('Blockly.ComponentManager');
50
- const {config} = goog.require('Blockly.config');
51
- const {ConnectionDB} = goog.require('Blockly.ConnectionDB');
52
- const {ContextMenuRegistry} = goog.require('Blockly.ContextMenuRegistry');
53
- const {Coordinate} = goog.require('Blockly.utils.Coordinate');
54
- /* eslint-disable-next-line no-unused-vars */
55
- const {Cursor} = goog.requireType('Blockly.Cursor');
56
- /* eslint-disable-next-line no-unused-vars */
57
- const {FlyoutButton} = goog.requireType('Blockly.FlyoutButton');
58
- const {Gesture} = goog.require('Blockly.Gesture');
59
- const {Grid} = goog.require('Blockly.Grid');
60
- /* eslint-disable-next-line no-unused-vars */
61
- const {IASTNodeLocationSvg} = goog.require('Blockly.IASTNodeLocationSvg');
62
- /* eslint-disable-next-line no-unused-vars */
63
- const {IBoundedElement} = goog.requireType('Blockly.IBoundedElement');
64
- /* eslint-disable-next-line no-unused-vars */
65
- const {ICopyable} = goog.requireType('Blockly.ICopyable');
66
- /* eslint-disable-next-line no-unused-vars */
67
- const {IDragTarget} = goog.requireType('Blockly.IDragTarget');
68
- /* eslint-disable-next-line no-unused-vars */
69
- const {IFlyout} = goog.requireType('Blockly.IFlyout');
70
- /* eslint-disable-next-line no-unused-vars */
71
- const {IMetricsManager} = goog.requireType('Blockly.IMetricsManager');
72
- /* eslint-disable-next-line no-unused-vars */
73
- const {IToolbox} = goog.requireType('Blockly.IToolbox');
74
- const {MarkerManager} = goog.require('Blockly.MarkerManager');
75
- /* eslint-disable-next-line no-unused-vars */
76
- const {Marker} = goog.requireType('Blockly.Marker');
77
- /* eslint-disable-next-line no-unused-vars */
78
- const {Metrics} = goog.requireType('Blockly.utils.Metrics');
79
- const {Options} = goog.require('Blockly.Options');
80
- const {Rect} = goog.require('Blockly.utils.Rect');
81
- /* eslint-disable-next-line no-unused-vars */
82
- const {RenderedConnection} = goog.requireType('Blockly.RenderedConnection');
83
- /* eslint-disable-next-line no-unused-vars */
84
- const {Renderer} = goog.requireType('Blockly.blockRendering.Renderer');
85
- /* eslint-disable-next-line no-unused-vars */
86
- const {ScrollbarPair} = goog.requireType('Blockly.ScrollbarPair');
87
- const {Size} = goog.require('Blockly.utils.Size');
88
- const {Svg} = goog.require('Blockly.utils.Svg');
89
- const {ThemeManager} = goog.require('Blockly.ThemeManager');
90
- /* eslint-disable-next-line no-unused-vars */
91
- const {Theme} = goog.requireType('Blockly.Theme');
92
- const {TouchGesture} = goog.require('Blockly.TouchGesture');
93
- /* eslint-disable-next-line no-unused-vars */
94
- const {Trashcan} = goog.requireType('Blockly.Trashcan');
95
- /* eslint-disable-next-line no-unused-vars */
96
- const {VariableModel} = goog.requireType('Blockly.VariableModel');
97
- const {WorkspaceAudio} = goog.require('Blockly.WorkspaceAudio');
98
- /* eslint-disable-next-line no-unused-vars */
99
- const {WorkspaceCommentSvg} = goog.requireType('Blockly.WorkspaceCommentSvg');
100
- /* eslint-disable-next-line no-unused-vars */
101
- const {WorkspaceComment} = goog.requireType('Blockly.WorkspaceComment');
102
- /* eslint-disable-next-line no-unused-vars */
103
- const {WorkspaceDragSurfaceSvg} = goog.requireType('Blockly.WorkspaceDragSurfaceSvg');
104
- const {Workspace} = goog.require('Blockly.Workspace');
105
- /* eslint-disable-next-line no-unused-vars */
106
- const {ZoomControls} = goog.requireType('Blockly.ZoomControls');
107
- /** @suppress {extraRequire} */
108
- goog.require('Blockly.Events.BlockCreate');
109
- /** @suppress {extraRequire} */
110
- goog.require('Blockly.Events.ThemeChange');
111
- /** @suppress {extraRequire} */
112
- goog.require('Blockly.Events.ViewportChange');
113
- /** @suppress {extraRequire} */
114
- goog.require('Blockly.MetricsManager');
115
- /** @suppress {extraRequire} */
116
- goog.require('Blockly.Msg');
117
-
31
+ // Unused import preserved for side-effects. Remove if unneeded.
32
+ // import './zoom_controls.js';
33
+ // Unused import preserved for side-effects. Remove if unneeded.
34
+ import './events/events_block_create.js';
35
+ // Unused import preserved for side-effects. Remove if unneeded.
36
+ import './events/events_theme_change.js';
37
+ // Unused import preserved for side-effects. Remove if unneeded.
38
+ import './events/events_viewport.js';
39
+ // Unused import preserved for side-effects. Remove if unneeded.
40
+ // import './metrics_manager.js';
41
+ // Unused import preserved for side-effects. Remove if unneeded.
42
+ // import './msg.js';
43
+
44
+ import type {Block} from './block.js';
45
+ import type {BlockDragSurfaceSvg} from './block_drag_surface.js';
46
+ import type {BlockSvg} from './block_svg.js';
47
+ import type {BlocklyOptions} from './blockly_options.js';
48
+ import * as browserEvents from './browser_events.js';
49
+ import * as common from './common.js';
50
+ import {ComponentManager} from './component_manager.js';
51
+ import {config} from './config.js';
52
+ import {ConnectionDB} from './connection_db.js';
53
+ import * as ContextMenu from './contextmenu.js';
54
+ import {ContextMenuRegistry} from './contextmenu_registry.js';
55
+ import * as dropDownDiv from './dropdowndiv.js';
56
+ import * as eventUtils from './events/utils.js';
57
+ import type {FlyoutButton} from './flyout_button.js';
58
+ import {Gesture} from './gesture.js';
59
+ import {Grid} from './grid.js';
60
+ import type {IASTNodeLocationSvg} from './interfaces/i_ast_node_location_svg.js';
61
+ import type {IBoundedElement} from './interfaces/i_bounded_element.js';
62
+ import type {ICopyable} from './interfaces/i_copyable.js';
63
+ import type {IDragTarget} from './interfaces/i_drag_target.js';
64
+ import type {IFlyout} from './interfaces/i_flyout.js';
65
+ import type {IMetricsManager} from './interfaces/i_metrics_manager.js';
66
+ import type {IToolbox} from './interfaces/i_toolbox.js';
67
+ import type {Cursor} from './keyboard_nav/cursor.js';
68
+ import type {Marker} from './keyboard_nav/marker.js';
69
+ import {MarkerManager} from './marker_manager.js';
70
+ import {Options} from './options.js';
71
+ import * as Procedures from './procedures.js';
72
+ import * as registry from './registry.js';
73
+ import * as blockRendering from './renderers/common/block_rendering.js';
74
+ import type {Renderer} from './renderers/common/renderer.js';
75
+ import type {ScrollbarPair} from './scrollbar_pair.js';
76
+ import * as blocks from './serialization/blocks.js';
77
+ import type {Theme} from './theme.js';
78
+ import {Classic} from './theme/classic.js';
79
+ import {ThemeManager} from './theme_manager.js';
80
+ import * as Tooltip from './tooltip.js';
81
+ import {TouchGesture} from './touch_gesture.js';
82
+ import type {Trashcan} from './trashcan.js';
83
+ import * as utils from './utils.js';
84
+ import * as arrayUtils from './utils/array.js';
85
+ import {Coordinate} from './utils/coordinate.js';
86
+ import * as dom from './utils/dom.js';
87
+ import type {Metrics} from './utils/metrics.js';
88
+ import {Rect} from './utils/rect.js';
89
+ import {Size} from './utils/size.js';
90
+ import {Svg} from './utils/svg.js';
91
+ import * as svgMath from './utils/svg_math.js';
92
+ import * as toolbox from './utils/toolbox.js';
93
+ import * as userAgent from './utils/useragent.js';
94
+ import type {VariableModel} from './variable_model.js';
95
+ import * as Variables from './variables.js';
96
+ import * as VariablesDynamic from './variables_dynamic.js';
97
+ import * as WidgetDiv from './widgetdiv.js';
98
+ import {Workspace} from './workspace.js';
99
+ import {WorkspaceAudio} from './workspace_audio.js';
100
+ import {WorkspaceComment} from './workspace_comment.js';
101
+ import {WorkspaceCommentSvg} from './workspace_comment_svg.js';
102
+ import type {WorkspaceDragSurfaceSvg} from './workspace_drag_surface_svg.js';
103
+ import * as Xml from './xml.js';
104
+ import {ZoomControls} from './zoom_controls.js';
105
+
106
+
107
+ /** Margin around the top/bottom/left/right after a zoomToFit call. */
108
+ const ZOOM_TO_FIT_MARGIN = 20;
118
109
 
119
110
  /**
120
111
  * Class for a workspace. This is an onscreen area with optional trashcan,
121
112
  * scrollbars, bubbles, and dragging.
122
- * @extends {Workspace}
123
- * @implements {IASTNodeLocationSvg}
124
113
  * @alias Blockly.WorkspaceSvg
125
114
  */
126
- class WorkspaceSvg extends Workspace {
115
+ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
127
116
  /**
128
- * @param {!Options} options Dictionary of options.
129
- * @param {BlockDragSurfaceSvg=} opt_blockDragSurface Drag surface for
130
- * blocks.
131
- * @param {WorkspaceDragSurfaceSvg=} opt_wsDragSurface Drag surface for
132
- * the workspace.
117
+ * A wrapper function called when a resize event occurs.
118
+ * You can pass the result to `eventHandling.unbind`.
133
119
  */
134
- constructor(options, opt_blockDragSurface, opt_wsDragSurface) {
135
- super(options);
120
+ private resizeHandlerWrapper_: browserEvents.Data|null = null;
136
121
 
137
- /**
138
- * A wrapper function called when a resize event occurs.
139
- * You can pass the result to `eventHandling.unbind`.
140
- * @type {?browserEvents.Data}
141
- * @private
142
- */
143
- this.resizeHandlerWrapper_ = null;
122
+ /**
123
+ * The render status of an SVG workspace.
124
+ * Returns `false` for headless workspaces and true for instances of
125
+ * `WorkspaceSvg`.
126
+ */
127
+ override rendered = true;
144
128
 
145
- /**
146
- * The render status of an SVG workspace.
147
- * Returns `false` for headless workspaces and true for instances of
148
- * `WorkspaceSvg`.
149
- * @type {boolean}
150
- */
151
- this.rendered = true;
129
+ /**
130
+ * Whether the workspace is visible. False if the workspace has been hidden
131
+ * by calling `setVisible(false)`.
132
+ */
133
+ private isVisible_ = true;
152
134
 
153
- /**
154
- * Whether the workspace is visible. False if the workspace has been hidden
155
- * by calling `setVisible(false)`.
156
- * @type {boolean}
157
- * @private
158
- */
159
- this.isVisible_ = true;
135
+ /**
136
+ * Whether this workspace has resizes enabled.
137
+ * Disable during batch operations for a performance improvement.
138
+ */
139
+ private resizesEnabled_ = true;
160
140
 
161
- /**
162
- * Whether this workspace has resizes enabled.
163
- * Disable during batch operations for a performance improvement.
164
- * @type {boolean}
165
- * @private
166
- */
167
- this.resizesEnabled_ = true;
141
+ /**
142
+ * Current horizontal scrolling offset in pixel units, relative to the
143
+ * workspace origin.
144
+ *
145
+ * It is useful to think about a view, and a canvas moving beneath that
146
+ * view. As the canvas moves right, this value becomes more positive, and
147
+ * the view is now "seeing" the left side of the canvas. As the canvas moves
148
+ * left, this value becomes more negative, and the view is now "seeing" the
149
+ * right side of the canvas.
150
+ *
151
+ * The confusing thing about this value is that it does not, and must not
152
+ * include the absoluteLeft offset. This is because it is used to calculate
153
+ * the viewLeft value.
154
+ *
155
+ * The viewLeft is relative to the workspace origin (although in pixel
156
+ * units). The workspace origin is the top-left corner of the workspace (at
157
+ * least when it is enabled). It is shifted from the top-left of the
158
+ * blocklyDiv so as not to be beneath the toolbox.
159
+ *
160
+ * When the workspace is enabled the viewLeft and workspace origin are at
161
+ * the same X location. As the canvas slides towards the right beneath the
162
+ * view this value (scrollX) becomes more positive, and the viewLeft becomes
163
+ * more negative relative to the workspace origin (imagine the workspace
164
+ * origin as a dot on the canvas sliding to the right as the canvas moves).
165
+ *
166
+ * So if the scrollX were to include the absoluteLeft this would in a way
167
+ * "unshift" the workspace origin. This means that the viewLeft would be
168
+ * representing the left edge of the blocklyDiv, rather than the left edge
169
+ * of the workspace.
170
+ */
171
+ scrollX = 0;
168
172
 
169
- /**
170
- * Current horizontal scrolling offset in pixel units, relative to the
171
- * workspace origin.
172
- *
173
- * It is useful to think about a view, and a canvas moving beneath that
174
- * view. As the canvas moves right, this value becomes more positive, and
175
- * the view is now "seeing" the left side of the canvas. As the canvas moves
176
- * left, this value becomes more negative, and the view is now "seeing" the
177
- * right side of the canvas.
178
- *
179
- * The confusing thing about this value is that it does not, and must not
180
- * include the absoluteLeft offset. This is because it is used to calculate
181
- * the viewLeft value.
182
- *
183
- * The viewLeft is relative to the workspace origin (although in pixel
184
- * units). The workspace origin is the top-left corner of the workspace (at
185
- * least when it is enabled). It is shifted from the top-left of the
186
- * blocklyDiv so as not to be beneath the toolbox.
187
- *
188
- * When the workspace is enabled the viewLeft and workspace origin are at
189
- * the same X location. As the canvas slides towards the right beneath the
190
- * view this value (scrollX) becomes more positive, and the viewLeft becomes
191
- * more negative relative to the workspace origin (imagine the workspace
192
- * origin as a dot on the canvas sliding to the right as the canvas moves).
193
- *
194
- * So if the scrollX were to include the absoluteLeft this would in a way
195
- * "unshift" the workspace origin. This means that the viewLeft would be
196
- * representing the left edge of the blocklyDiv, rather than the left edge
197
- * of the workspace.
198
- *
199
- * @type {number}
200
- */
201
- this.scrollX = 0;
173
+ /**
174
+ * Current vertical scrolling offset in pixel units, relative to the
175
+ * workspace origin.
176
+ *
177
+ * It is useful to think about a view, and a canvas moving beneath that
178
+ * view. As the canvas moves down, this value becomes more positive, and the
179
+ * view is now "seeing" the upper part of the canvas. As the canvas moves
180
+ * up, this value becomes more negative, and the view is "seeing" the lower
181
+ * part of the canvas.
182
+ *
183
+ * This confusing thing about this value is that it does not, and must not
184
+ * include the absoluteTop offset. This is because it is used to calculate
185
+ * the viewTop value.
186
+ *
187
+ * The viewTop is relative to the workspace origin (although in pixel
188
+ * units). The workspace origin is the top-left corner of the workspace (at
189
+ * least when it is enabled). It is shifted from the top-left of the
190
+ * blocklyDiv so as not to be beneath the toolbox.
191
+ *
192
+ * When the workspace is enabled the viewTop and workspace origin are at the
193
+ * same Y location. As the canvas slides towards the bottom this value
194
+ * (scrollY) becomes more positive, and the viewTop becomes more negative
195
+ * relative to the workspace origin (image in the workspace origin as a dot
196
+ * on the canvas sliding downwards as the canvas moves).
197
+ *
198
+ * So if the scrollY were to include the absoluteTop this would in a way
199
+ * "unshift" the workspace origin. This means that the viewTop would be
200
+ * representing the top edge of the blocklyDiv, rather than the top edge of
201
+ * the workspace.
202
+ */
203
+ scrollY = 0;
202
204
 
203
- /**
204
- * Current vertical scrolling offset in pixel units, relative to the
205
- * workspace origin.
206
- *
207
- * It is useful to think about a view, and a canvas moving beneath that
208
- * view. As the canvas moves down, this value becomes more positive, and the
209
- * view is now "seeing" the upper part of the canvas. As the canvas moves
210
- * up, this value becomes more negative, and the view is "seeing" the lower
211
- * part of the canvas.
212
- *
213
- * This confusing thing about this value is that it does not, and must not
214
- * include the absoluteTop offset. This is because it is used to calculate
215
- * the viewTop value.
216
- *
217
- * The viewTop is relative to the workspace origin (although in pixel
218
- * units). The workspace origin is the top-left corner of the workspace (at
219
- * least when it is enabled). It is shifted from the top-left of the
220
- * blocklyDiv so as not to be beneath the toolbox.
221
- *
222
- * When the workspace is enabled the viewTop and workspace origin are at the
223
- * same Y location. As the canvas slides towards the bottom this value
224
- * (scrollY) becomes more positive, and the viewTop becomes more negative
225
- * relative to the workspace origin (image in the workspace origin as a dot
226
- * on the canvas sliding downwards as the canvas moves).
227
- *
228
- * So if the scrollY were to include the absoluteTop this would in a way
229
- * "unshift" the workspace origin. This means that the viewTop would be
230
- * representing the top edge of the blocklyDiv, rather than the top edge of
231
- * the workspace.
232
- *
233
- * @type {number}
234
- */
235
- this.scrollY = 0;
205
+ /** Horizontal scroll value when scrolling started in pixel units. */
206
+ startScrollX = 0;
236
207
 
237
- /**
238
- * Horizontal scroll value when scrolling started in pixel units.
239
- * @type {number}
240
- */
241
- this.startScrollX = 0;
208
+ /** Vertical scroll value when scrolling started in pixel units. */
209
+ startScrollY = 0;
242
210
 
243
- /**
244
- * Vertical scroll value when scrolling started in pixel units.
245
- * @type {number}
246
- */
247
- this.startScrollY = 0;
211
+ /** Distance from mouse to object being dragged. */
212
+ // AnyDuringMigration because: Type 'null' is not assignable to type
213
+ // 'Coordinate'.
214
+ private dragDeltaXY_: Coordinate = null as AnyDuringMigration;
248
215
 
249
- /**
250
- * Distance from mouse to object being dragged.
251
- * @type {Coordinate}
252
- * @private
253
- */
254
- this.dragDeltaXY_ = null;
216
+ /** Current scale. */
217
+ scale = 1;
255
218
 
256
- /**
257
- * Current scale.
258
- * @type {number}
259
- */
260
- this.scale = 1;
219
+ /** Cached scale value. Used to detect changes in viewport. */
220
+ private oldScale_ = 1;
261
221
 
262
- /**
263
- * Cached scale value. Used to detect changes in viewport.
264
- * @type {number}
265
- * @private
266
- */
267
- this.oldScale_ = 1;
222
+ /** Cached viewport top value. Used to detect changes in viewport. */
223
+ private oldTop_ = 0;
268
224
 
269
- /**
270
- * Cached viewport top value. Used to detect changes in viewport.
271
- * @type {number}
272
- * @private
273
- */
274
- this.oldTop_ = 0;
225
+ /** Cached viewport left value. Used to detect changes in viewport. */
226
+ private oldLeft_ = 0;
275
227
 
276
- /**
277
- * Cached viewport left value. Used to detect changes in viewport.
278
- * @type {number}
279
- * @private
280
- */
281
- this.oldLeft_ = 0;
228
+ /** The workspace's trashcan (if any). */
229
+ // AnyDuringMigration because: Type 'null' is not assignable to type
230
+ // 'Trashcan'.
231
+ trashcan: Trashcan = null as AnyDuringMigration;
282
232
 
283
- /**
284
- * The workspace's trashcan (if any).
285
- * @type {Trashcan}
286
- */
287
- this.trashcan = null;
233
+ /** This workspace's scrollbars, if they exist. */
234
+ // AnyDuringMigration because: Type 'null' is not assignable to type
235
+ // 'ScrollbarPair'.
236
+ scrollbar: ScrollbarPair = null as AnyDuringMigration;
288
237
 
289
- /**
290
- * This workspace's scrollbars, if they exist.
291
- * @type {ScrollbarPair}
292
- */
293
- this.scrollbar = null;
238
+ /**
239
+ * Fixed flyout providing blocks which may be dragged into this workspace.
240
+ */
241
+ // AnyDuringMigration because: Type 'null' is not assignable to type
242
+ // 'IFlyout'.
243
+ private flyout_: IFlyout = null as AnyDuringMigration;
294
244
 
295
- /**
296
- * Fixed flyout providing blocks which may be dragged into this workspace.
297
- * @type {IFlyout}
298
- * @private
299
- */
300
- this.flyout_ = null;
245
+ /**
246
+ * Category-based toolbox providing blocks which may be dragged into this
247
+ * workspace.
248
+ */
249
+ // AnyDuringMigration because: Type 'null' is not assignable to type
250
+ // 'IToolbox'.
251
+ private toolbox_: IToolbox = null as AnyDuringMigration;
301
252
 
302
- /**
303
- * Category-based toolbox providing blocks which may be dragged into this
304
- * workspace.
305
- * @type {IToolbox}
306
- * @private
307
- */
308
- this.toolbox_ = null;
253
+ /**
254
+ * The current gesture in progress on this workspace, if any.
255
+ * @internal
256
+ */
257
+ // AnyDuringMigration because: Type 'null' is not assignable to type
258
+ // 'TouchGesture'.
259
+ currentGesture_: TouchGesture = null as AnyDuringMigration;
309
260
 
310
- /**
311
- * The current gesture in progress on this workspace, if any.
312
- * @type {TouchGesture}
313
- * @package
314
- */
315
- this.currentGesture_ = null;
261
+ /** This workspace's surface for dragging blocks, if it exists. */
262
+ // AnyDuringMigration because: Type 'null' is not assignable to type
263
+ // 'BlockDragSurfaceSvg'.
264
+ private readonly blockDragSurface_: BlockDragSurfaceSvg =
265
+ null as AnyDuringMigration;
316
266
 
317
- /**
318
- * This workspace's surface for dragging blocks, if it exists.
319
- * @type {BlockDragSurfaceSvg}
320
- * @private
321
- */
322
- this.blockDragSurface_ = null;
267
+ /** This workspace's drag surface, if it exists. */
268
+ // AnyDuringMigration because: Type 'null' is not assignable to type
269
+ // 'WorkspaceDragSurfaceSvg'.
270
+ private readonly workspaceDragSurface_: WorkspaceDragSurfaceSvg =
271
+ null as AnyDuringMigration;
323
272
 
324
- /**
325
- * This workspace's drag surface, if it exists.
326
- * @type {WorkspaceDragSurfaceSvg}
327
- * @private
328
- */
329
- this.workspaceDragSurface_ = null;
273
+ /**
274
+ * Whether to move workspace to the drag surface when it is dragged.
275
+ * True if it should move, false if it should be translated directly.
276
+ */
277
+ private readonly useWorkspaceDragSurface_;
330
278
 
331
- /**
332
- * Whether to move workspace to the drag surface when it is dragged.
333
- * True if it should move, false if it should be translated directly.
334
- * @type {boolean}
335
- * @private
336
- */
337
- this.useWorkspaceDragSurface_ = false;
279
+ /**
280
+ * Whether the drag surface is actively in use. When true, calls to
281
+ * translate will translate the drag surface instead of the translating the
282
+ * workspace directly.
283
+ * This is set to true in setupDragSurface and to false in resetDragSurface.
284
+ */
285
+ private isDragSurfaceActive_ = false;
338
286
 
339
- /**
340
- * Whether the drag surface is actively in use. When true, calls to
341
- * translate will translate the drag surface instead of the translating the
342
- * workspace directly.
343
- * This is set to true in setupDragSurface and to false in resetDragSurface.
344
- * @type {boolean}
345
- * @private
346
- */
347
- this.isDragSurfaceActive_ = false;
287
+ /**
288
+ * The first parent div with 'injectionDiv' in the name, or null if not set.
289
+ * Access this with getInjectionDiv.
290
+ */
291
+ // AnyDuringMigration because: Type 'null' is not assignable to type
292
+ // 'Element'.
293
+ private injectionDiv_: Element = null as AnyDuringMigration;
348
294
 
349
- /**
350
- * The first parent div with 'injectionDiv' in the name, or null if not set.
351
- * Access this with getInjectionDiv.
352
- * @type {Element}
353
- * @private
354
- */
355
- this.injectionDiv_ = null;
295
+ /**
296
+ * Last known position of the page scroll.
297
+ * This is used to determine whether we have recalculated screen coordinate
298
+ * stuff since the page scrolled.
299
+ */
300
+ // AnyDuringMigration because: Type 'null' is not assignable to type
301
+ // 'Coordinate'.
302
+ private lastRecordedPageScroll_: Coordinate = null as AnyDuringMigration;
356
303
 
357
- /**
358
- * Last known position of the page scroll.
359
- * This is used to determine whether we have recalculated screen coordinate
360
- * stuff since the page scrolled.
361
- * @type {Coordinate}
362
- * @private
363
- */
364
- this.lastRecordedPageScroll_ = null;
304
+ /**
305
+ * Developers may define this function to add custom menu options to the
306
+ * workspace's context menu or edit the workspace-created set of menu
307
+ * options.
308
+ * @param options List of menu options to add to.
309
+ * @param e The right-click event that triggered the context menu.
310
+ */
311
+ configureContextMenu: AnyDuringMigration;
365
312
 
366
- /**
367
- * Developers may define this function to add custom menu options to the
368
- * workspace's context menu or edit the workspace-created set of menu
369
- * options.
370
- * @param {!Array<!Object>} options List of menu options to add to.
371
- * @param {!Event} e The right-click event that triggered the context menu.
372
- */
373
- this.configureContextMenu;
313
+ /**
314
+ * In a flyout, the target workspace where blocks should be placed after a
315
+ * drag. Otherwise null.
316
+ * @internal
317
+ */
318
+ // AnyDuringMigration because: Type 'null' is not assignable to type
319
+ // 'WorkspaceSvg'.
320
+ targetWorkspace: WorkspaceSvg = null as AnyDuringMigration;
374
321
 
375
- /**
376
- * In a flyout, the target workspace where blocks should be placed after a
377
- * drag. Otherwise null.
378
- * @type {WorkspaceSvg}
379
- * @package
380
- */
381
- this.targetWorkspace = null;
322
+ /** Inverted screen CTM, for use in mouseToSvg. */
323
+ private inverseScreenCTM_: SVGMatrix|null = null;
382
324
 
383
- /**
384
- * Inverted screen CTM, for use in mouseToSvg.
385
- * @type {?SVGMatrix}
386
- * @private
387
- */
388
- this.inverseScreenCTM_ = null;
325
+ /** Inverted screen CTM is dirty, recalculate it. */
326
+ private inverseScreenCTMDirty_ = true;
327
+ private metricsManager_: IMetricsManager;
328
+ /** @internal */
329
+ getMetrics: () => Metrics;
330
+ /** @internal */
331
+ setMetrics: (p1: {x: number, y: number}) => void;
332
+ private readonly componentManager_: ComponentManager;
389
333
 
390
- /**
391
- * Inverted screen CTM is dirty, recalculate it.
392
- * @type {boolean}
393
- * @private
394
- */
395
- this.inverseScreenCTMDirty_ = true;
334
+ /**
335
+ * List of currently highlighted blocks. Block highlighting is often used
336
+ * to visually mark blocks currently being executed.
337
+ */
338
+ private readonly highlightedBlocks_: BlockSvg[] = [];
339
+ private audioManager_: WorkspaceAudio;
340
+ private grid_: Grid;
341
+ private markerManager_: MarkerManager;
342
+ private toolboxCategoryCallbacks_:
343
+ {[key: string]: ((p1: WorkspaceSvg) => toolbox.FlyoutDefinition)|null};
344
+ private flyoutButtonCallbacks_:
345
+ {[key: string]: ((p1: FlyoutButton) => AnyDuringMigration)|null};
346
+ protected themeManager_: ThemeManager;
347
+ private readonly renderer_: Renderer;
348
+
349
+ /** Cached parent SVG. */
350
+ // AnyDuringMigration because: Type 'null' is not assignable to type
351
+ // 'SVGElement'.
352
+ private cachedParentSvg_: SVGElement = null as AnyDuringMigration;
353
+
354
+ /** True if keyboard accessibility mode is on, false otherwise. */
355
+ keyboardAccessibilityMode = false;
356
+
357
+ /** The list of top-level bounded elements on the workspace. */
358
+ private topBoundedElements_: IBoundedElement[] = [];
359
+
360
+ /** The recorded drag targets. */
361
+ private dragTargetAreas_: Array<{component: IDragTarget, clientRect: Rect}> =
362
+ [];
363
+ private readonly cachedParentSvgSize_: Size;
364
+ // TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
365
+ svgGroup_!: SVGElement;
366
+ // TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
367
+ svgBackground_!: SVGElement;
368
+ // TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
369
+ svgBlockCanvas_!: SVGElement;
370
+ // TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
371
+ svgBubbleCanvas_!: SVGElement;
372
+ zoomControls_: AnyDuringMigration;
373
+
374
+ /**
375
+ * @param options Dictionary of options.
376
+ * @param opt_blockDragSurface Drag surface for blocks.
377
+ * @param opt_wsDragSurface Drag surface for the workspace.
378
+ */
379
+ constructor(
380
+ options: Options, opt_blockDragSurface?: BlockDragSurfaceSvg,
381
+ opt_wsDragSurface?: WorkspaceDragSurfaceSvg) {
382
+ super(options);
396
383
 
397
384
  const MetricsManagerClass = registry.getClassFromOptions(
398
385
  registry.Type.METRICS_MANAGER, options, true);
399
- /**
400
- * Object in charge of calculating metrics for the workspace.
401
- * @type {!IMetricsManager}
402
- * @private
403
- */
404
- this.metricsManager_ = new MetricsManagerClass(this);
386
+ /** Object in charge of calculating metrics for the workspace. */
387
+ this.metricsManager_ = new MetricsManagerClass!(this);
405
388
 
406
- /**
407
- * Method to get all the metrics that have to do with a workspace.
408
- * @type {function():!Metrics}
409
- * @package
410
- */
389
+ /** Method to get all the metrics that have to do with a workspace. */
411
390
  this.getMetrics = options.getMetrics ||
412
391
  this.metricsManager_.getMetrics.bind(this.metricsManager_);
413
392
 
414
- /**
415
- * Translates the workspace.
416
- * @type {function(!{x:number, y:number}):void}
417
- * @package
418
- */
393
+ /** Translates the workspace. */
419
394
  this.setMetrics =
420
395
  options.setMetrics || WorkspaceSvg.setTopLevelWorkspaceMetrics_;
421
396
 
422
- /**
423
- * @type {!ComponentManager}
424
- * @private
425
- */
426
397
  this.componentManager_ = new ComponentManager();
427
398
 
428
399
  this.connectionDBList = ConnectionDB.init(this.connectionChecker);
@@ -438,156 +409,92 @@ class WorkspaceSvg extends Workspace {
438
409
  this.useWorkspaceDragSurface_ =
439
410
  !!this.workspaceDragSurface_ && svgMath.is3dSupported();
440
411
 
441
- /**
442
- * List of currently highlighted blocks. Block highlighting is often used
443
- * to visually mark blocks currently being executed.
444
- * @type {!Array<!BlockSvg>}
445
- * @private
446
- */
447
- this.highlightedBlocks_ = [];
448
-
449
412
  /**
450
413
  * Object in charge of loading, storing, and playing audio for a workspace.
451
- * @type {!WorkspaceAudio}
452
- * @private
453
414
  */
454
- this.audioManager_ = new WorkspaceAudio(
455
- /** @type {WorkspaceSvg} */ (options.parentWorkspace));
415
+ this.audioManager_ =
416
+ new WorkspaceAudio((options.parentWorkspace as WorkspaceSvg));
456
417
 
457
- /**
458
- * This workspace's grid object or null.
459
- * @type {Grid}
460
- * @private
461
- */
462
- this.grid_ = this.options.gridPattern ?
463
- new Grid(this.options.gridPattern, options.gridOptions) :
464
- null;
418
+ /** This workspace's grid object or null. */
419
+ // AnyDuringMigration because: Type 'Grid | null' is not assignable to type
420
+ // 'Grid'.
421
+ this.grid_ = (this.options.gridPattern ?
422
+ new Grid(this.options.gridPattern, options.gridOptions) :
423
+ null) as AnyDuringMigration;
465
424
 
466
- /**
467
- * Manager in charge of markers and cursors.
468
- * @type {!MarkerManager}
469
- * @private
470
- */
425
+ /** Manager in charge of markers and cursors. */
471
426
  this.markerManager_ = new MarkerManager(this);
472
427
 
473
428
  /**
474
429
  * Map from function names to callbacks, for deciding what to do when a
475
430
  * custom toolbox category is opened.
476
- * @type {!Object<string, ?function(!WorkspaceSvg):
477
- * !toolbox.FlyoutDefinition>}
478
- * @private
479
431
  */
480
432
  this.toolboxCategoryCallbacks_ = Object.create(null);
481
433
 
482
434
  /**
483
435
  * Map from function names to callbacks, for deciding what to do when a
484
436
  * button is clicked.
485
- * @type {!Object<string, ?function(!FlyoutButton)>}
486
- * @private
487
437
  */
488
438
  this.flyoutButtonCallbacks_ = Object.create(null);
489
439
 
490
- const Variables = goog.module.get('Blockly.Variables');
491
440
  if (Variables && Variables.flyoutCategory) {
492
441
  this.registerToolboxCategoryCallback(
493
442
  Variables.CATEGORY_NAME, Variables.flyoutCategory);
494
443
  }
495
444
 
496
- const VariablesDynamic = goog.module.get('Blockly.VariablesDynamic');
497
445
  if (VariablesDynamic && VariablesDynamic.flyoutCategory) {
498
446
  this.registerToolboxCategoryCallback(
499
447
  VariablesDynamic.CATEGORY_NAME, VariablesDynamic.flyoutCategory);
500
448
  }
501
449
 
502
- const Procedures = goog.module.get('Blockly.Procedures');
503
450
  if (Procedures && Procedures.flyoutCategory) {
504
451
  this.registerToolboxCategoryCallback(
505
452
  Procedures.CATEGORY_NAME, Procedures.flyoutCategory);
506
453
  this.addChangeListener(Procedures.mutatorOpenListener);
507
454
  }
508
455
 
509
- /**
510
- * Object in charge of storing and updating the workspace theme.
511
- * @type {!ThemeManager}
512
- * @protected
513
- */
456
+ /** Object in charge of storing and updating the workspace theme. */
514
457
  this.themeManager_ = this.options.parentWorkspace ?
515
458
  this.options.parentWorkspace.getThemeManager() :
516
459
  new ThemeManager(this, this.options.theme || Classic);
517
- this.themeManager_.subscribeWorkspace(this);
460
+ // AnyDuringMigration because: Argument of type 'this' is not assignable to
461
+ // parameter of type 'Workspace'.
462
+ this.themeManager_.subscribeWorkspace(this as AnyDuringMigration);
518
463
 
519
- /**
520
- * The block renderer used for rendering blocks on this workspace.
521
- * @type {!Renderer}
522
- * @private
523
- */
464
+ /** The block renderer used for rendering blocks on this workspace. */
524
465
  this.renderer_ = blockRendering.init(
525
466
  this.options.renderer || 'geras', this.getTheme(),
526
- this.options.rendererOverrides);
527
-
528
- /**
529
- * Cached parent SVG.
530
- * @type {SVGElement}
531
- * @private
532
- */
533
- this.cachedParentSvg_ = null;
534
-
535
- /**
536
- * True if keyboard accessibility mode is on, false otherwise.
537
- * @type {boolean}
538
- */
539
- this.keyboardAccessibilityMode = false;
540
-
541
- /**
542
- * The list of top-level bounded elements on the workspace.
543
- * @type {!Array<!IBoundedElement>}
544
- * @private
545
- */
546
- this.topBoundedElements_ = [];
547
-
548
- /**
549
- * The recorded drag targets.
550
- * @type {!Array<
551
- * {
552
- * component: !IDragTarget,
553
- * clientRect: !Rect
554
- * }>}
555
- * @private
556
- */
557
- this.dragTargetAreas_ = [];
467
+ this.options.rendererOverrides ?? undefined);
558
468
 
559
469
  /**
560
470
  * The cached size of the parent svg element.
561
471
  * Used to compute svg metrics.
562
- * @type {!Size}
563
- * @private
564
472
  */
565
473
  this.cachedParentSvgSize_ = new Size(0, 0);
566
474
  }
567
475
 
568
476
  /**
569
477
  * Get the marker manager for this workspace.
570
- * @return {!MarkerManager} The marker manager.
478
+ * @return The marker manager.
571
479
  */
572
- getMarkerManager() {
480
+ getMarkerManager(): MarkerManager {
573
481
  return this.markerManager_;
574
482
  }
575
483
 
576
484
  /**
577
485
  * Gets the metrics manager for this workspace.
578
- * @return {!IMetricsManager} The metrics manager.
579
- * @public
486
+ * @return The metrics manager.
580
487
  */
581
- getMetricsManager() {
488
+ getMetricsManager(): IMetricsManager {
582
489
  return this.metricsManager_;
583
490
  }
584
491
 
585
492
  /**
586
493
  * Sets the metrics manager for the workspace.
587
- * @param {!IMetricsManager} metricsManager The metrics manager.
588
- * @package
494
+ * @param metricsManager The metrics manager.
495
+ * @internal
589
496
  */
590
- setMetricsManager(metricsManager) {
497
+ setMetricsManager(metricsManager: IMetricsManager) {
591
498
  this.metricsManager_ = metricsManager;
592
499
  this.getMetrics =
593
500
  this.metricsManager_.getMetrics.bind(this.metricsManager_);
@@ -595,41 +502,40 @@ class WorkspaceSvg extends Workspace {
595
502
 
596
503
  /**
597
504
  * Gets the component manager for this workspace.
598
- * @return {!ComponentManager} The component manager.
599
- * @public
505
+ * @return The component manager.
600
506
  */
601
- getComponentManager() {
507
+ getComponentManager(): ComponentManager {
602
508
  return this.componentManager_;
603
509
  }
604
510
 
605
511
  /**
606
512
  * Add the cursor SVG to this workspaces SVG group.
607
- * @param {SVGElement} cursorSvg The SVG root of the cursor to be added to the
608
- * workspace SVG group.
609
- * @package
513
+ * @param cursorSvg The SVG root of the cursor to be added to the workspace
514
+ * SVG group.
515
+ * @internal
610
516
  */
611
- setCursorSvg(cursorSvg) {
517
+ setCursorSvg(cursorSvg: SVGElement) {
612
518
  this.markerManager_.setCursorSvg(cursorSvg);
613
519
  }
614
520
 
615
521
  /**
616
522
  * Add the marker SVG to this workspaces SVG group.
617
- * @param {SVGElement} markerSvg The SVG root of the marker to be added to the
618
- * workspace SVG group.
619
- * @package
523
+ * @param markerSvg The SVG root of the marker to be added to the workspace
524
+ * SVG group.
525
+ * @internal
620
526
  */
621
- setMarkerSvg(markerSvg) {
527
+ setMarkerSvg(markerSvg: SVGElement) {
622
528
  this.markerManager_.setMarkerSvg(markerSvg);
623
529
  }
624
530
 
625
531
  /**
626
532
  * Get the marker with the given ID.
627
- * @param {string} id The ID of the marker.
628
- * @return {?Marker} The marker with the given ID or null if no marker
629
- * with the given ID exists.
630
- * @package
533
+ * @param id The ID of the marker.
534
+ * @return The marker with the given ID or null if no marker with the given ID
535
+ * exists.
536
+ * @internal
631
537
  */
632
- getMarker(id) {
538
+ getMarker(id: string): Marker|null {
633
539
  if (this.markerManager_) {
634
540
  return this.markerManager_.getMarker(id);
635
541
  }
@@ -638,9 +544,9 @@ class WorkspaceSvg extends Workspace {
638
544
 
639
545
  /**
640
546
  * The cursor for this workspace.
641
- * @return {?Cursor} The cursor for the workspace.
547
+ * @return The cursor for the workspace.
642
548
  */
643
- getCursor() {
549
+ getCursor(): Cursor|null {
644
550
  if (this.markerManager_) {
645
551
  return this.markerManager_.getCursor();
646
552
  }
@@ -649,45 +555,43 @@ class WorkspaceSvg extends Workspace {
649
555
 
650
556
  /**
651
557
  * Get the block renderer attached to this workspace.
652
- * @return {!Renderer} The renderer attached to this
653
- * workspace.
558
+ * @return The renderer attached to this workspace.
654
559
  */
655
- getRenderer() {
560
+ getRenderer(): Renderer {
656
561
  return this.renderer_;
657
562
  }
658
563
 
659
564
  /**
660
565
  * Get the theme manager for this workspace.
661
- * @return {!ThemeManager} The theme manager for this workspace.
662
- * @package
566
+ * @return The theme manager for this workspace.
567
+ * @internal
663
568
  */
664
- getThemeManager() {
569
+ getThemeManager(): ThemeManager {
665
570
  return this.themeManager_;
666
571
  }
667
572
 
668
573
  /**
669
574
  * Get the workspace theme object.
670
- * @return {!Theme} The workspace theme object.
575
+ * @return The workspace theme object.
671
576
  */
672
- getTheme() {
577
+ getTheme(): Theme {
673
578
  return this.themeManager_.getTheme();
674
579
  }
675
580
 
676
581
  /**
677
582
  * Set the workspace theme object.
678
583
  * If no theme is passed, default to the `Classic` theme.
679
- * @param {Theme} theme The workspace theme object.
584
+ * @param theme The workspace theme object.
680
585
  */
681
- setTheme(theme) {
586
+ setTheme(theme: Theme) {
682
587
  if (!theme) {
683
- theme = /** @type {!Theme} */ (Classic);
588
+ theme = Classic as Theme;
684
589
  }
685
590
  this.themeManager_.setTheme(theme);
686
591
  }
687
592
 
688
593
  /**
689
594
  * Refresh all blocks on the workspace after a theme update.
690
- * @package
691
595
  */
692
596
  refreshTheme() {
693
597
  if (this.svgGroup_) {
@@ -695,9 +599,11 @@ class WorkspaceSvg extends Workspace {
695
599
  }
696
600
 
697
601
  // Update all blocks in workspace that have a style name.
602
+ // AnyDuringMigration because: Argument of type 'BlockSvg[]' is not
603
+ // assignable to parameter of type 'Block[]'.
698
604
  this.updateBlockStyles_(this.getAllBlocks(false).filter(function(block) {
699
605
  return !!block.getStyleName();
700
- }));
606
+ }) as AnyDuringMigration);
701
607
 
702
608
  // Update current toolbox selection.
703
609
  this.refreshToolboxSelection();
@@ -710,24 +616,23 @@ class WorkspaceSvg extends Workspace {
710
616
  this.setVisible(true);
711
617
  }
712
618
 
713
- const event = new (eventUtils.get(eventUtils.THEME_CHANGE))(
714
- this.getTheme().name, this.id);
619
+ const event = new (eventUtils.get(eventUtils.THEME_CHANGE))!
620
+ (this.getTheme().name, this.id);
715
621
  eventUtils.fire(event);
716
622
  }
717
623
 
718
624
  /**
719
625
  * Updates all the blocks with new style.
720
- * @param {!Array<!Block>} blocks List of blocks to update the style
721
- * on.
722
- * @private
626
+ * @param blocks List of blocks to update the style on.
723
627
  */
724
- updateBlockStyles_(blocks) {
725
- for (let i = 0, block; (block = blocks[i]); i++) {
628
+ private updateBlockStyles_(blocks: Block[]) {
629
+ for (let i = 0, block; block = blocks[i]; i++) {
726
630
  const blockStyleName = block.getStyleName();
727
631
  if (blockStyleName) {
728
- block.setStyle(blockStyleName);
729
- if (block.mutator) {
730
- block.mutator.updateBlockStyle();
632
+ const blockSvg = block as BlockSvg;
633
+ blockSvg.setStyle(blockStyleName);
634
+ if (blockSvg.mutator) {
635
+ blockSvg.mutator.updateBlockStyle();
731
636
  }
732
637
  }
733
638
  }
@@ -735,15 +640,15 @@ class WorkspaceSvg extends Workspace {
735
640
 
736
641
  /**
737
642
  * Getter for the inverted screen CTM.
738
- * @return {?SVGMatrix} The matrix to use in mouseToSvg
643
+ * @return The matrix to use in mouseToSvg
739
644
  */
740
- getInverseScreenCTM() {
645
+ getInverseScreenCTM(): SVGMatrix|null {
741
646
  // Defer getting the screen CTM until we actually need it, this should
742
647
  // avoid forced reflows from any calls to updateInverseScreenCTM.
743
648
  if (this.inverseScreenCTMDirty_) {
744
649
  const ctm = this.getParentSvg().getScreenCTM();
745
650
  if (ctm) {
746
- this.inverseScreenCTM_ = ctm.inverse();
651
+ this.inverseScreenCTM_ = (ctm).inverse();
747
652
  this.inverseScreenCTMDirty_ = false;
748
653
  }
749
654
  }
@@ -751,19 +656,17 @@ class WorkspaceSvg extends Workspace {
751
656
  return this.inverseScreenCTM_;
752
657
  }
753
658
 
754
- /**
755
- * Mark the inverse screen CTM as dirty.
756
- */
659
+ /** Mark the inverse screen CTM as dirty. */
757
660
  updateInverseScreenCTM() {
758
661
  this.inverseScreenCTMDirty_ = true;
759
662
  }
760
663
 
761
664
  /**
762
665
  * Getter for isVisible
763
- * @return {boolean} Whether the workspace is visible.
666
+ * @return Whether the workspace is visible.
764
667
  * False if the workspace has been hidden by calling `setVisible(false)`.
765
668
  */
766
- isVisible() {
669
+ isVisible(): boolean {
767
670
  return this.isVisible_;
768
671
  }
769
672
 
@@ -771,11 +674,11 @@ class WorkspaceSvg extends Workspace {
771
674
  * Return the absolute coordinates of the top-left corner of this element,
772
675
  * scales that after canvas SVG element, if it's a descendant.
773
676
  * The origin (0,0) is the top-left corner of the Blockly SVG.
774
- * @param {!SVGElement} element SVG element to find the coordinates of.
775
- * @return {!Coordinate} Object with .x and .y properties.
776
- * @package
677
+ * @param element SVG element to find the coordinates of.
678
+ * @return Object with .x and .y properties.
679
+ * @internal
777
680
  */
778
- getSvgXY(element) {
681
+ getSvgXY(element: SVGElement): Coordinate {
779
682
  let x = 0;
780
683
  let y = 0;
781
684
  let scale = 1;
@@ -793,18 +696,17 @@ class WorkspaceSvg extends Workspace {
793
696
  }
794
697
  x += xy.x * scale;
795
698
  y += xy.y * scale;
796
- element = /** @type {!SVGElement} */ (element.parentNode);
699
+ element = element.parentNode as SVGElement;
797
700
  } while (element && element !== this.getParentSvg());
798
701
  return new Coordinate(x, y);
799
702
  }
800
703
 
801
704
  /**
802
705
  * Gets the size of the workspace's parent SVG element.
803
- * @return {!Size} The cached width and height of the workspace's
804
- * parent SVG element.
805
- * @package
706
+ * @return The cached width and height of the workspace's parent SVG element.
707
+ * @internal
806
708
  */
807
- getCachedParentSvgSize() {
709
+ getCachedParentSvgSize(): Size {
808
710
  const size = this.cachedParentSvgSize_;
809
711
  return new Size(size.width, size.height);
810
712
  }
@@ -814,10 +716,10 @@ class WorkspaceSvg extends Workspace {
814
716
  * origin in pixels.
815
717
  * The workspace origin is where a block would render at position (0, 0).
816
718
  * It is not the upper left corner of the workspace SVG.
817
- * @return {!Coordinate} Offset in pixels.
818
- * @package
719
+ * @return Offset in pixels.
720
+ * @internal
819
721
  */
820
- getOriginOffsetInPixels() {
722
+ getOriginOffsetInPixels(): Coordinate {
821
723
  return svgMath.getInjectionDivXY(this.getCanvas());
822
724
  }
823
725
 
@@ -826,51 +728,50 @@ class WorkspaceSvg extends Workspace {
826
728
  * Walks the DOM the first time it's called, then returns a cached value.
827
729
  * Note: We assume this is only called after the workspace has been injected
828
730
  * into the DOM.
829
- * @return {!Element} The first parent div with 'injectionDiv' in the name.
830
- * @package
731
+ * @return The first parent div with 'injectionDiv' in the name.
732
+ * @internal
831
733
  */
832
- getInjectionDiv() {
734
+ getInjectionDiv(): Element {
833
735
  // NB: it would be better to pass this in at createDom, but is more likely
834
736
  // to break existing uses of Blockly.
835
737
  if (!this.injectionDiv_) {
836
- let element = this.svgGroup_;
738
+ let element: Element = this.svgGroup_;
837
739
  while (element) {
838
740
  const classes = element.getAttribute('class') || '';
839
741
  if ((' ' + classes + ' ').indexOf(' injectionDiv ') !== -1) {
840
742
  this.injectionDiv_ = element;
841
743
  break;
842
744
  }
843
- element = /** @type {!Element} */ (element.parentNode);
745
+ element = element.parentNode as Element;
844
746
  }
845
747
  }
846
- return /** @type {!Element} */ (this.injectionDiv_);
748
+ return this.injectionDiv_;
847
749
  }
848
750
 
849
751
  /**
850
752
  * Get the SVG block canvas for the workspace.
851
- * @return {?SVGElement} The SVG group for the workspace.
852
- * @package
753
+ * @return The SVG group for the workspace.
754
+ * @internal
853
755
  */
854
- getBlockCanvas() {
756
+ getBlockCanvas(): SVGElement|null {
855
757
  return this.svgBlockCanvas_;
856
758
  }
857
759
 
858
760
  /**
859
761
  * Save resize handler data so we can delete it later in dispose.
860
- * @param {!browserEvents.Data} handler Data that can be passed to
861
- * eventHandling.unbind.
762
+ * @param handler Data that can be passed to eventHandling.unbind.
862
763
  */
863
- setResizeHandlerWrapper(handler) {
764
+ setResizeHandlerWrapper(handler: browserEvents.Data) {
864
765
  this.resizeHandlerWrapper_ = handler;
865
766
  }
866
767
 
867
768
  /**
868
769
  * Create the workspace DOM elements.
869
- * @param {string=} opt_backgroundClass Either 'blocklyMainBackground' or
770
+ * @param opt_backgroundClass Either 'blocklyMainBackground' or
870
771
  * 'blocklyMutatorBackground'.
871
- * @return {!Element} The workspace's SVG group.
772
+ * @return The workspace's SVG group.
872
773
  */
873
- createDom(opt_backgroundClass) {
774
+ createDom(opt_backgroundClass?: string): Element {
874
775
  /**
875
776
  * <g class="blocklyWorkspace">
876
777
  * <rect class="blocklyMainBackground" height="100%" width="100%"></rect>
@@ -878,16 +779,13 @@ class WorkspaceSvg extends Workspace {
878
779
  * <g class="blocklyBlockCanvas"></g>
879
780
  * <g class="blocklyBubbleCanvas"></g>
880
781
  * </g>
881
- * @type {SVGElement}
882
782
  */
883
- this.svgGroup_ =
884
- dom.createSvgElement(Svg.G, {'class': 'blocklyWorkspace'}, null);
783
+ this.svgGroup_ = dom.createSvgElement(Svg.G, {'class': 'blocklyWorkspace'});
885
784
 
886
785
  // Note that a <g> alone does not receive mouse events--it must have a
887
786
  // valid target inside it. If no background class is specified, as in the
888
787
  // flyout, the workspace will not receive mouse events.
889
788
  if (opt_backgroundClass) {
890
- /** @type {SVGElement} */
891
789
  this.svgBackground_ = dom.createSvgElement(
892
790
  Svg.RECT,
893
791
  {'height': '100%', 'width': '100%', 'class': opt_backgroundClass},
@@ -901,10 +799,8 @@ class WorkspaceSvg extends Workspace {
901
799
  this.svgBackground_, 'workspaceBackgroundColour', 'fill');
902
800
  }
903
801
  }
904
- /** @type {SVGElement} */
905
802
  this.svgBlockCanvas_ = dom.createSvgElement(
906
803
  Svg.G, {'class': 'blocklyBlockCanvas'}, this.svgGroup_);
907
- /** @type {SVGElement} */
908
804
  this.svgBubbleCanvas_ = dom.createSvgElement(
909
805
  Svg.G, {'class': 'blocklyBubbleCanvas'}, this.svgGroup_);
910
806
 
@@ -924,7 +820,7 @@ class WorkspaceSvg extends Workspace {
924
820
  if (this.options.hasCategories) {
925
821
  const ToolboxClass = registry.getClassFromOptions(
926
822
  registry.Type.TOOLBOX, this.options, true);
927
- this.toolbox_ = new ToolboxClass(this);
823
+ this.toolbox_ = new ToolboxClass!(this);
928
824
  }
929
825
  if (this.grid_) {
930
826
  this.grid_.update(this.scale);
@@ -944,7 +840,7 @@ class WorkspaceSvg extends Workspace {
944
840
  * Unlink from all DOM elements to prevent memory leaks.
945
841
  * @suppress {checkTypes}
946
842
  */
947
- dispose() {
843
+ override dispose() {
948
844
  // Stop rerendering.
949
845
  this.rendered = false;
950
846
  if (this.currentGesture_) {
@@ -952,25 +848,39 @@ class WorkspaceSvg extends Workspace {
952
848
  }
953
849
  if (this.svgGroup_) {
954
850
  dom.removeNode(this.svgGroup_);
955
- this.svgGroup_ = null;
956
- }
957
- this.svgBlockCanvas_ = null;
958
- this.svgBubbleCanvas_ = null;
851
+ // AnyDuringMigration because: Type 'null' is not assignable to type
852
+ // 'SVGElement'.
853
+ this.svgGroup_ = null as AnyDuringMigration;
854
+ }
855
+ // AnyDuringMigration because: Type 'null' is not assignable to type
856
+ // 'SVGElement'.
857
+ this.svgBlockCanvas_ = null as AnyDuringMigration;
858
+ // AnyDuringMigration because: Type 'null' is not assignable to type
859
+ // 'SVGElement'.
860
+ this.svgBubbleCanvas_ = null as AnyDuringMigration;
959
861
  if (this.toolbox_) {
960
862
  this.toolbox_.dispose();
961
- this.toolbox_ = null;
863
+ // AnyDuringMigration because: Type 'null' is not assignable to type
864
+ // 'IToolbox'.
865
+ this.toolbox_ = null as AnyDuringMigration;
962
866
  }
963
867
  if (this.flyout_) {
964
868
  this.flyout_.dispose();
965
- this.flyout_ = null;
869
+ // AnyDuringMigration because: Type 'null' is not assignable to type
870
+ // 'IFlyout'.
871
+ this.flyout_ = null as AnyDuringMigration;
966
872
  }
967
873
  if (this.trashcan) {
968
874
  this.trashcan.dispose();
969
- this.trashcan = null;
875
+ // AnyDuringMigration because: Type 'null' is not assignable to type
876
+ // 'Trashcan'.
877
+ this.trashcan = null as AnyDuringMigration;
970
878
  }
971
879
  if (this.scrollbar) {
972
880
  this.scrollbar.dispose();
973
- this.scrollbar = null;
881
+ // AnyDuringMigration because: Type 'null' is not assignable to type
882
+ // 'ScrollbarPair'.
883
+ this.scrollbar = null as AnyDuringMigration;
974
884
  }
975
885
  if (this.zoomControls_) {
976
886
  this.zoomControls_.dispose();
@@ -979,37 +889,50 @@ class WorkspaceSvg extends Workspace {
979
889
 
980
890
  if (this.audioManager_) {
981
891
  this.audioManager_.dispose();
982
- this.audioManager_ = null;
892
+ // AnyDuringMigration because: Type 'null' is not assignable to type
893
+ // 'WorkspaceAudio'.
894
+ this.audioManager_ = null as AnyDuringMigration;
983
895
  }
984
896
 
985
897
  if (this.grid_) {
986
- this.grid_.dispose();
987
- this.grid_ = null;
898
+ // AnyDuringMigration because: Type 'null' is not assignable to type
899
+ // 'Grid'.
900
+ this.grid_ = null as AnyDuringMigration;
988
901
  }
989
902
 
990
903
  this.renderer_.dispose();
991
904
 
992
905
  if (this.markerManager_) {
993
906
  this.markerManager_.dispose();
994
- this.markerManager_ = null;
907
+ // AnyDuringMigration because: Type 'null' is not assignable to type
908
+ // 'MarkerManager'.
909
+ this.markerManager_ = null as AnyDuringMigration;
995
910
  }
996
911
 
997
912
  super.dispose();
998
913
 
999
914
  // Dispose of theme manager after all blocks and mutators are disposed of.
1000
915
  if (this.themeManager_) {
1001
- this.themeManager_.unsubscribeWorkspace(this);
916
+ // AnyDuringMigration because: Argument of type 'this' is not assignable
917
+ // to parameter of type 'Workspace'.
918
+ this.themeManager_.unsubscribeWorkspace(this as AnyDuringMigration);
1002
919
  this.themeManager_.unsubscribe(this.svgBackground_);
1003
920
  if (!this.options.parentWorkspace) {
1004
921
  this.themeManager_.dispose();
1005
- this.themeManager_ = null;
922
+ // AnyDuringMigration because: Type 'null' is not assignable to type
923
+ // 'ThemeManager'.
924
+ this.themeManager_ = null as AnyDuringMigration;
1006
925
  }
1007
926
  }
1008
927
 
1009
- this.connectionDBList = null;
928
+ this.connectionDBList.length = 0;
1010
929
 
1011
- this.toolboxCategoryCallbacks_ = null;
1012
- this.flyoutButtonCallbacks_ = null;
930
+ // AnyDuringMigration because: Type 'null' is not assignable to type '{
931
+ // [key: string]: ((p1: WorkspaceSvg) => FlyoutDefinition) | null; }'.
932
+ this.toolboxCategoryCallbacks_ = null as AnyDuringMigration;
933
+ // AnyDuringMigration because: Type 'null' is not assignable to type '{
934
+ // [key: string]: ((p1: FlyoutButton) => any) | null; }'.
935
+ this.flyoutButtonCallbacks_ = null as AnyDuringMigration;
1013
936
 
1014
937
  if (!this.options.parentWorkspace) {
1015
938
  // Top-most workspace. Dispose of the div that the
@@ -1025,48 +948,30 @@ class WorkspaceSvg extends Workspace {
1025
948
  }
1026
949
  }
1027
950
 
1028
- /**
1029
- * Obtain a newly created block.
1030
- *
1031
- * This block's SVG must still be initialized
1032
- * ([initSvg]{@link BlockSvg#initSvg}) and it must be rendered
1033
- * ([render]{@link BlockSvg#render}) before the block will be visible.
1034
- * @param {!string} prototypeName Name of the language object containing
1035
- * type-specific functions for this block.
1036
- * @param {string=} opt_id Optional ID. Use this ID if provided, otherwise
1037
- * create a new ID.
1038
- * @return {!BlockSvg} The created block.
1039
- * @override
1040
- */
1041
- newBlock(prototypeName, opt_id) {
1042
- return new BlockSvg(this, prototypeName, opt_id);
1043
- }
1044
-
1045
951
  /**
1046
952
  * Add a trashcan.
1047
- * @package
953
+ * @internal
1048
954
  */
1049
955
  addTrashcan() {
1050
- const {Trashcan} = goog.module.get('Blockly.Trashcan');
1051
- if (!Trashcan) {
1052
- throw Error('Missing require for Blockly.Trashcan');
1053
- }
1054
- /** @type {Trashcan} */
1055
- this.trashcan = new Trashcan(this);
956
+ this.trashcan = WorkspaceSvg.newTrashcan(this);
1056
957
  const svgTrashcan = this.trashcan.createDom();
1057
958
  this.svgGroup_.insertBefore(svgTrashcan, this.svgBlockCanvas_);
1058
959
  }
1059
960
 
961
+ /**
962
+ * @internal
963
+ */
964
+ static newTrashcan(workspace: WorkspaceSvg): Trashcan {
965
+ throw new Error(
966
+ 'The implementation of newTrashcan should be ' +
967
+ 'monkey-patched in by blockly.ts');
968
+ }
969
+
1060
970
  /**
1061
971
  * Add zoom controls.
1062
- * @package
972
+ * @internal
1063
973
  */
1064
974
  addZoomControls() {
1065
- const {ZoomControls} = goog.module.get('Blockly.ZoomControls');
1066
- if (!ZoomControls) {
1067
- throw Error('Missing require for Blockly.ZoomControls');
1068
- }
1069
- /** @type {ZoomControls} */
1070
975
  this.zoomControls_ = new ZoomControls(this);
1071
976
  const svgZoomControls = this.zoomControls_.createDom();
1072
977
  this.svgGroup_.appendChild(svgZoomControls);
@@ -1074,36 +979,31 @@ class WorkspaceSvg extends Workspace {
1074
979
 
1075
980
  /**
1076
981
  * Add a flyout element in an element with the given tag name.
1077
- * @param {string|
1078
- * !Svg<!SVGSVGElement>|
1079
- * !Svg<!SVGGElement>} tagName What type of tag the
1080
- * flyout belongs in.
1081
- * @return {!Element} The element containing the flyout DOM.
1082
- * @package
1083
- */
1084
- addFlyout(tagName) {
1085
- const workspaceOptions = new Options(
1086
- /** @type {!BlocklyOptions} */
1087
- ({
1088
- 'parentWorkspace': this,
1089
- 'rtl': this.RTL,
1090
- 'oneBasedIndex': this.options.oneBasedIndex,
1091
- 'horizontalLayout': this.horizontalLayout,
1092
- 'renderer': this.options.renderer,
1093
- 'rendererOverrides': this.options.rendererOverrides,
1094
- 'move': {
1095
- 'scrollbars': true,
1096
- },
1097
- }));
982
+ * @param tagName What type of tag the flyout belongs in.
983
+ * @return The element containing the flyout DOM.
984
+ * @internal
985
+ */
986
+ addFlyout(tagName: string|Svg<SVGSVGElement>|Svg<SVGGElement>): Element {
987
+ const workspaceOptions = new Options(({
988
+ 'parentWorkspace': this,
989
+ 'rtl': this.RTL,
990
+ 'oneBasedIndex': this.options.oneBasedIndex,
991
+ 'horizontalLayout': this.horizontalLayout,
992
+ 'renderer': this.options.renderer,
993
+ 'rendererOverrides': this.options.rendererOverrides,
994
+ 'move': {
995
+ 'scrollbars': true,
996
+ },
997
+ } as BlocklyOptions));
1098
998
  workspaceOptions.toolboxPosition = this.options.toolboxPosition;
1099
999
  if (this.horizontalLayout) {
1100
1000
  const HorizontalFlyout = registry.getClassFromOptions(
1101
1001
  registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, this.options, true);
1102
- this.flyout_ = new HorizontalFlyout(workspaceOptions);
1002
+ this.flyout_ = new HorizontalFlyout!(workspaceOptions);
1103
1003
  } else {
1104
1004
  const VerticalFlyout = registry.getClassFromOptions(
1105
1005
  registry.Type.FLYOUTS_VERTICAL_TOOLBOX, this.options, true);
1106
- this.flyout_ = new VerticalFlyout(workspaceOptions);
1006
+ this.flyout_ = new VerticalFlyout!(workspaceOptions);
1107
1007
  }
1108
1008
  this.flyout_.autoClose = false;
1109
1009
  this.flyout_.getWorkspace().setVisible(true);
@@ -1118,12 +1018,11 @@ class WorkspaceSvg extends Workspace {
1118
1018
  * Getter for the flyout associated with this workspace. This flyout may be
1119
1019
  * owned by either the toolbox or the workspace, depending on toolbox
1120
1020
  * configuration. It will be null if there is no flyout.
1121
- * @param {boolean=} opt_own Whether to only return the workspace's own
1122
- * flyout.
1123
- * @return {?IFlyout} The flyout on this workspace.
1124
- * @package
1021
+ * @param opt_own Whether to only return the workspace's own flyout.
1022
+ * @return The flyout on this workspace.
1023
+ * @internal
1125
1024
  */
1126
- getFlyout(opt_own) {
1025
+ getFlyout(opt_own?: boolean): IFlyout|null {
1127
1026
  if (this.flyout_ || opt_own) {
1128
1027
  return this.flyout_;
1129
1028
  }
@@ -1135,19 +1034,18 @@ class WorkspaceSvg extends Workspace {
1135
1034
 
1136
1035
  /**
1137
1036
  * Getter for the toolbox associated with this workspace, if one exists.
1138
- * @return {?IToolbox} The toolbox on this workspace.
1139
- * @package
1037
+ * @return The toolbox on this workspace.
1038
+ * @internal
1140
1039
  */
1141
- getToolbox() {
1040
+ getToolbox(): IToolbox|null {
1142
1041
  return this.toolbox_;
1143
1042
  }
1144
1043
 
1145
1044
  /**
1146
1045
  * Update items that use screen coordinate calculations
1147
1046
  * because something has changed (e.g. scroll position, window size).
1148
- * @private
1149
1047
  */
1150
- updateScreenCalculations_() {
1048
+ private updateScreenCalculations_() {
1151
1049
  this.updateInverseScreenCTM();
1152
1050
  this.recordDragTargets();
1153
1051
  }
@@ -1156,7 +1054,7 @@ class WorkspaceSvg extends Workspace {
1156
1054
  * If enabled, resize the parts of the workspace that change when the
1157
1055
  * workspace contents (e.g. block positions) change. This will also scroll
1158
1056
  * the workspace contents if needed.
1159
- * @package
1057
+ * @internal
1160
1058
  */
1161
1059
  resizeContents() {
1162
1060
  if (!this.resizesEnabled_ || !this.rendered) {
@@ -1187,7 +1085,7 @@ class WorkspaceSvg extends Workspace {
1187
1085
  ComponentManager.Capability.POSITIONABLE, true);
1188
1086
  const metrics = this.getMetricsManager().getUiMetrics();
1189
1087
  const savedPositions = [];
1190
- for (let i = 0, positionable; (positionable = positionables[i]); i++) {
1088
+ for (let i = 0, positionable; positionable = positionables[i]; i++) {
1191
1089
  positionable.position(metrics, savedPositions);
1192
1090
  const boundingRect = positionable.getBoundingRectangle();
1193
1091
  if (boundingRect) {
@@ -1204,7 +1102,7 @@ class WorkspaceSvg extends Workspace {
1204
1102
  /**
1205
1103
  * Resizes and repositions workspace chrome if the page has a new
1206
1104
  * scroll position.
1207
- * @package
1105
+ * @internal
1208
1106
  */
1209
1107
  updateScreenCalculationsIfScrolled() {
1210
1108
  /* eslint-disable indent */
@@ -1218,50 +1116,54 @@ class WorkspaceSvg extends Workspace {
1218
1116
 
1219
1117
  /**
1220
1118
  * Get the SVG element that forms the drawing surface.
1221
- * @return {!SVGGElement} SVG group element.
1119
+ * @return SVG group element.
1222
1120
  */
1223
- getCanvas() {
1224
- return /** @type {!SVGGElement} */ (this.svgBlockCanvas_);
1121
+ getCanvas(): SVGGElement {
1122
+ return this.svgBlockCanvas_ as SVGGElement;
1225
1123
  }
1226
1124
 
1227
1125
  /**
1228
1126
  * Caches the width and height of the workspace's parent SVG element for use
1229
1127
  * with getSvgMetrics.
1230
- * @param {?number} width The width of the parent SVG element.
1231
- * @param {?number} height The height of the parent SVG element
1232
- * @package
1128
+ * @param width The width of the parent SVG element.
1129
+ * @param height The height of the parent SVG element
1130
+ * @internal
1233
1131
  */
1234
- setCachedParentSvgSize(width, height) {
1132
+ setCachedParentSvgSize(width: number|null, height: number|null) {
1235
1133
  const svg = this.getParentSvg();
1236
1134
  if (width != null) {
1237
1135
  this.cachedParentSvgSize_.width = width;
1238
1136
  // This is set to support the public (but deprecated) Blockly.svgSize
1239
1137
  // method.
1240
- svg.cachedWidth_ = width;
1138
+ // AnyDuringMigration because: Argument of type 'number' is not
1139
+ // assignable to parameter of type 'string'.
1140
+ svg.setAttribute('data-cached-width', width as AnyDuringMigration);
1241
1141
  }
1242
1142
  if (height != null) {
1243
1143
  this.cachedParentSvgSize_.height = height;
1244
1144
  // This is set to support the public (but deprecated) Blockly.svgSize
1245
1145
  // method.
1246
- svg.cachedHeight_ = height;
1146
+ // AnyDuringMigration because: Argument of type 'number' is not
1147
+ // assignable to parameter of type 'string'.
1148
+ svg.setAttribute('data-cached-height', height as AnyDuringMigration);
1247
1149
  }
1248
1150
  }
1249
1151
 
1250
1152
  /**
1251
1153
  * Get the SVG element that forms the bubble surface.
1252
- * @return {!SVGGElement} SVG group element.
1154
+ * @return SVG group element.
1253
1155
  */
1254
- getBubbleCanvas() {
1255
- return /** @type {!SVGGElement} */ (this.svgBubbleCanvas_);
1156
+ getBubbleCanvas(): SVGGElement {
1157
+ return this.svgBubbleCanvas_ as SVGGElement;
1256
1158
  }
1257
1159
 
1258
1160
  /**
1259
1161
  * Get the SVG element that contains this workspace.
1260
1162
  * Note: We assume this is only called after the workspace has been injected
1261
1163
  * into the DOM.
1262
- * @return {!SVGElement} SVG element.
1164
+ * @return SVG element.
1263
1165
  */
1264
- getParentSvg() {
1166
+ getParentSvg(): SVGSVGElement {
1265
1167
  if (!this.cachedParentSvg_) {
1266
1168
  let element = this.svgGroup_;
1267
1169
  while (element) {
@@ -1269,16 +1171,16 @@ class WorkspaceSvg extends Workspace {
1269
1171
  this.cachedParentSvg_ = element;
1270
1172
  break;
1271
1173
  }
1272
- element = /** @type {!SVGElement} */ (element.parentNode);
1174
+ element = element.parentNode as SVGSVGElement;
1273
1175
  }
1274
1176
  }
1275
- return /** @type {!SVGElement} */ (this.cachedParentSvg_);
1177
+ return this.cachedParentSvg_ as SVGSVGElement;
1276
1178
  }
1277
1179
 
1278
1180
  /**
1279
1181
  * Fires a viewport event if events are enabled and there is a change in
1280
1182
  * viewport values.
1281
- * @package
1183
+ * @internal
1282
1184
  */
1283
1185
  maybeFireViewportChangeEvent() {
1284
1186
  if (!eventUtils.isEnabled()) {
@@ -1293,8 +1195,8 @@ class WorkspaceSvg extends Workspace {
1293
1195
  // of negligible changes in viewport top/left.
1294
1196
  return;
1295
1197
  }
1296
- const event = new (eventUtils.get(eventUtils.VIEWPORT_CHANGE))(
1297
- top, left, scale, this.id, this.oldScale_);
1198
+ const event = new (eventUtils.get(eventUtils.VIEWPORT_CHANGE))!
1199
+ (top, left, scale, this.id, this.oldScale_);
1298
1200
  this.oldScale_ = scale;
1299
1201
  this.oldTop_ = top;
1300
1202
  this.oldLeft_ = left;
@@ -1303,12 +1205,12 @@ class WorkspaceSvg extends Workspace {
1303
1205
 
1304
1206
  /**
1305
1207
  * Translate this workspace to new coordinates.
1306
- * @param {number} x Horizontal translation, in pixel units relative to the
1307
- * top left of the Blockly div.
1308
- * @param {number} y Vertical translation, in pixel units relative to the
1309
- * top left of the Blockly div.
1208
+ * @param x Horizontal translation, in pixel units relative to the top left of
1209
+ * the Blockly div.
1210
+ * @param y Vertical translation, in pixel units relative to the top left of
1211
+ * the Blockly div.
1310
1212
  */
1311
- translate(x, y) {
1213
+ translate(x: number, y: number) {
1312
1214
  if (this.useWorkspaceDragSurface_ && this.isDragSurfaceActive_) {
1313
1215
  this.workspaceDragSurface_.translateSurface(x, y);
1314
1216
  } else {
@@ -1333,7 +1235,7 @@ class WorkspaceSvg extends Workspace {
1333
1235
  * Called at the end of a workspace drag to take the contents
1334
1236
  * out of the drag surface and put them back into the workspace SVG.
1335
1237
  * Does nothing if the workspace drag surface is not enabled.
1336
- * @package
1238
+ * @internal
1337
1239
  */
1338
1240
  resetDragSurface() {
1339
1241
  // Don't do anything if we aren't using a drag surface.
@@ -1355,7 +1257,7 @@ class WorkspaceSvg extends Workspace {
1355
1257
  * Called at the beginning of a workspace drag to move contents of
1356
1258
  * the workspace to the drag surface.
1357
1259
  * Does nothing if the drag surface is not enabled.
1358
- * @package
1260
+ * @internal
1359
1261
  */
1360
1262
  setupDragSurface() {
1361
1263
  // Don't do anything if we aren't using a drag surface.
@@ -1376,10 +1278,15 @@ class WorkspaceSvg extends Workspace {
1376
1278
 
1377
1279
  // Figure out where we want to put the canvas back. The order
1378
1280
  // in the is important because things are layered.
1379
- const previousElement =
1380
- /** @type {Element} */ (this.svgBlockCanvas_.previousSibling);
1381
- const width = parseInt(this.getParentSvg().getAttribute('width'), 10);
1382
- const height = parseInt(this.getParentSvg().getAttribute('height'), 10);
1281
+ const previousElement = this.svgBlockCanvas_.previousSibling as Element;
1282
+ // AnyDuringMigration because: Argument of type 'string | null' is not
1283
+ // assignable to parameter of type 'string'.
1284
+ const width = parseInt(
1285
+ this.getParentSvg().getAttribute('width') as AnyDuringMigration, 10);
1286
+ // AnyDuringMigration because: Argument of type 'string | null' is not
1287
+ // assignable to parameter of type 'string'.
1288
+ const height = parseInt(
1289
+ this.getParentSvg().getAttribute('height') as AnyDuringMigration, 10);
1383
1290
  const coord = svgMath.getRelativeXY(this.getCanvas());
1384
1291
  this.workspaceDragSurface_.setContentsAndShow(
1385
1292
  this.getCanvas(), this.getBubbleCanvas(), previousElement, width,
@@ -1389,20 +1296,19 @@ class WorkspaceSvg extends Workspace {
1389
1296
 
1390
1297
  /**
1391
1298
  * Gets the drag surface blocks are moved to when a drag is started.
1392
- * @return {?BlockDragSurfaceSvg} This workspace's block drag surface,
1393
- * if one is in use.
1394
- * @package
1299
+ * @return This workspace's block drag surface, if one is in use.
1300
+ * @internal
1395
1301
  */
1396
- getBlockDragSurface() {
1302
+ getBlockDragSurface(): BlockDragSurfaceSvg|null {
1397
1303
  return this.blockDragSurface_;
1398
1304
  }
1399
1305
 
1400
1306
  /**
1401
1307
  * Returns the horizontal offset of the workspace.
1402
1308
  * Intended for LTR/RTL compatibility in XML.
1403
- * @return {number} Width.
1309
+ * @return Width.
1404
1310
  */
1405
- getWidth() {
1311
+ override getWidth(): number {
1406
1312
  const metrics = this.getMetrics();
1407
1313
  return metrics ? metrics.viewWidth / this.scale : 0;
1408
1314
  }
@@ -1410,9 +1316,9 @@ class WorkspaceSvg extends Workspace {
1410
1316
  /**
1411
1317
  * Toggles the visibility of the workspace.
1412
1318
  * Currently only intended for main workspace.
1413
- * @param {boolean} isVisible True if workspace should be visible.
1319
+ * @param isVisible True if workspace should be visible.
1414
1320
  */
1415
- setVisible(isVisible) {
1321
+ setVisible(isVisible: boolean) {
1416
1322
  this.isVisible_ = isVisible;
1417
1323
  if (!this.svgGroup_) {
1418
1324
  return;
@@ -1427,7 +1333,7 @@ class WorkspaceSvg extends Workspace {
1427
1333
  // Tell the flyout whether its container is visible so it can
1428
1334
  // tell when to hide itself.
1429
1335
  if (this.getFlyout()) {
1430
- this.getFlyout().setContainerVisible(isVisible);
1336
+ this.getFlyout()!.setContainerVisible(isVisible);
1431
1337
  }
1432
1338
 
1433
1339
  this.getParentSvg().style.display = isVisible ? 'block' : 'none';
@@ -1451,9 +1357,7 @@ class WorkspaceSvg extends Workspace {
1451
1357
  }
1452
1358
  }
1453
1359
 
1454
- /**
1455
- * Render all blocks in workspace.
1456
- */
1360
+ /** Render all blocks in workspace. */
1457
1361
  render() {
1458
1362
  // Generate list of all blocks.
1459
1363
  const blocks = this.getAllBlocks(false);
@@ -1475,16 +1379,16 @@ class WorkspaceSvg extends Workspace {
1475
1379
  /**
1476
1380
  * Highlight or unhighlight a block in the workspace. Block highlighting is
1477
1381
  * often used to visually mark blocks currently being executed.
1478
- * @param {?string} id ID of block to highlight/unhighlight,
1479
- * or null for no block (used to unhighlight all blocks).
1480
- * @param {boolean=} opt_state If undefined, highlight specified block and
1481
- * automatically unhighlight all others. If true or false, manually
1482
- * highlight/unhighlight the specified block.
1382
+ * @param id ID of block to highlight/unhighlight, or null for no block (used
1383
+ * to unhighlight all blocks).
1384
+ * @param opt_state If undefined, highlight specified block and automatically
1385
+ * unhighlight all others. If true or false, manually
1386
+ * highlight/unhighlight the specified block.
1483
1387
  */
1484
- highlightBlock(id, opt_state) {
1388
+ highlightBlock(id: string|null, opt_state?: boolean) {
1485
1389
  if (opt_state === undefined) {
1486
1390
  // Unhighlight all blocks.
1487
- for (let i = 0, block; (block = this.highlightedBlocks_[i]); i++) {
1391
+ for (let i = 0, block; block = this.highlightedBlocks_[i]; i++) {
1488
1392
  block.setHighlighted(false);
1489
1393
  }
1490
1394
  this.highlightedBlocks_.length = 0;
@@ -1492,7 +1396,7 @@ class WorkspaceSvg extends Workspace {
1492
1396
  // Highlight/unhighlight the specified block.
1493
1397
  const block = id ? this.getBlockById(id) : null;
1494
1398
  if (block) {
1495
- const state = (opt_state === undefined) || opt_state;
1399
+ const state = opt_state === undefined || opt_state;
1496
1400
  // Using Set here would be great, but at the cost of IE10 support.
1497
1401
  if (!state) {
1498
1402
  arrayUtils.removeElem(this.highlightedBlocks_, block);
@@ -1507,17 +1411,15 @@ class WorkspaceSvg extends Workspace {
1507
1411
  * Pastes the provided block or workspace comment onto the workspace.
1508
1412
  * Does not check whether there is remaining capacity for the object, that
1509
1413
  * should be done before calling this method.
1510
- * @param {!Object|!Element|!DocumentFragment} state The representation of the
1511
- * thing to paste.
1512
- * @return {!ICopyable|null} The pasted thing, or null if
1513
- * the paste was not successful.
1414
+ * @param state The representation of the thing to paste.
1415
+ * @return The pasted thing, or null if the paste was not successful.
1514
1416
  */
1515
- paste(state) {
1516
- if (!this.rendered || !state['type'] && !state.tagName) {
1417
+ paste(state: AnyDuringMigration|Element|DocumentFragment): ICopyable|null {
1418
+ if (!this.rendered || !state['type'] && !state['tagName']) {
1517
1419
  return null;
1518
1420
  }
1519
- if (this.currentGesture_) {
1520
- this.currentGesture_.cancel(); // Dragging while pasting? No.
1421
+ if (this.currentGesture_) { // Dragging while pasting? No.
1422
+ this.currentGesture_.cancel();
1521
1423
  }
1522
1424
 
1523
1425
  const existingGroup = eventUtils.getGroup();
@@ -1528,10 +1430,9 @@ class WorkspaceSvg extends Workspace {
1528
1430
  let pastedThing;
1529
1431
  // Checks if this is JSON. JSON has a type property, while elements don't.
1530
1432
  if (state['type']) {
1531
- pastedThing =
1532
- this.pasteBlock_(null, /** @type {!blocks.State} */ (state));
1433
+ pastedThing = this.pasteBlock_(null, state as blocks.State);
1533
1434
  } else {
1534
- const xmlBlock = /** @type {!Element} */ (state);
1435
+ const xmlBlock = state as Element;
1535
1436
  if (xmlBlock.tagName.toLowerCase() === 'comment') {
1536
1437
  pastedThing = this.pasteWorkspaceComment_(xmlBlock);
1537
1438
  } else {
@@ -1545,27 +1446,36 @@ class WorkspaceSvg extends Workspace {
1545
1446
 
1546
1447
  /**
1547
1448
  * Paste the provided block onto the workspace.
1548
- * @param {?Element} xmlBlock XML block element.
1549
- * @param {?blocks.State} jsonBlock JSON block
1550
- * representation.
1551
- * @return {!BlockSvg} The pasted block.
1552
- * @private
1449
+ * @param xmlBlock XML block element.
1450
+ * @param jsonBlock JSON block representation.
1451
+ * @return The pasted block.
1553
1452
  */
1554
- pasteBlock_(xmlBlock, jsonBlock) {
1453
+ private pasteBlock_(xmlBlock: Element|null, jsonBlock: blocks.State|null):
1454
+ BlockSvg {
1555
1455
  eventUtils.disable();
1556
- let block;
1456
+ let block: BlockSvg;
1557
1457
  try {
1558
1458
  let blockX = 0;
1559
1459
  let blockY = 0;
1560
1460
  if (xmlBlock) {
1561
- block = /** @type {!BlockSvg} */ (Xml.domToBlock(xmlBlock, this));
1562
- blockX = parseInt(xmlBlock.getAttribute('x'), 10);
1461
+ // AnyDuringMigration because: Argument of type 'this' is not
1462
+ // assignable to parameter of type 'Workspace'.
1463
+ block =
1464
+ Xml.domToBlock(xmlBlock, this as AnyDuringMigration) as BlockSvg;
1465
+ // AnyDuringMigration because: Argument of type 'string | null' is not
1466
+ // assignable to parameter of type 'string'.
1467
+ blockX = parseInt(xmlBlock.getAttribute('x') as AnyDuringMigration, 10);
1563
1468
  if (this.RTL) {
1564
1469
  blockX = -blockX;
1565
1470
  }
1566
- blockY = parseInt(xmlBlock.getAttribute('y'), 10);
1471
+ // AnyDuringMigration because: Argument of type 'string | null' is not
1472
+ // assignable to parameter of type 'string'.
1473
+ blockY = parseInt(xmlBlock.getAttribute('y') as AnyDuringMigration, 10);
1567
1474
  } else if (jsonBlock) {
1568
- block = /** @type {!BlockSvg} */ (blocks.append(jsonBlock, this));
1475
+ // AnyDuringMigration because: Argument of type 'this' is not
1476
+ // assignable to parameter of type 'Workspace'.
1477
+ block =
1478
+ blocks.append(jsonBlock, this as AnyDuringMigration) as BlockSvg;
1569
1479
  blockX = jsonBlock['x'] || 10;
1570
1480
  if (this.RTL) {
1571
1481
  blockX = this.getWidth() - blockX;
@@ -1581,7 +1491,7 @@ class WorkspaceSvg extends Workspace {
1581
1491
  do {
1582
1492
  collide = false;
1583
1493
  const allBlocks = this.getAllBlocks(false);
1584
- for (let i = 0, otherBlock; (otherBlock = allBlocks[i]); i++) {
1494
+ for (let i = 0, otherBlock; otherBlock = allBlocks[i]; i++) {
1585
1495
  const otherXY = otherBlock.getRelativeToSurfaceXY();
1586
1496
  if (Math.abs(blockX - otherXY.x) <= 1 &&
1587
1497
  Math.abs(blockY - otherXY.y) <= 1) {
@@ -1591,10 +1501,10 @@ class WorkspaceSvg extends Workspace {
1591
1501
  }
1592
1502
  if (!collide) {
1593
1503
  // Check for blocks in snap range to any of its connections.
1594
- const connections = block.getConnections_(false);
1595
- for (let i = 0, connection; (connection = connections[i]); i++) {
1504
+ const connections = block!.getConnections_(false);
1505
+ for (let i = 0, connection; connection = connections[i]; i++) {
1596
1506
  const neighbour =
1597
- /** @type {!RenderedConnection} */ (connection)
1507
+ (connection)
1598
1508
  .closest(
1599
1509
  config.snapRadius, new Coordinate(blockX, blockY));
1600
1510
  if (neighbour.connection) {
@@ -1612,35 +1522,42 @@ class WorkspaceSvg extends Workspace {
1612
1522
  blockY += config.snapRadius * 2;
1613
1523
  }
1614
1524
  } while (collide);
1615
- block.moveTo(new Coordinate(blockX, blockY));
1525
+ block!.moveTo(new Coordinate(blockX, blockY));
1616
1526
  }
1617
1527
  } finally {
1618
1528
  eventUtils.enable();
1619
1529
  }
1620
- if (eventUtils.isEnabled() && !block.isShadow()) {
1621
- eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CREATE))(block));
1530
+ if (eventUtils.isEnabled() && !block!.isShadow()) {
1531
+ eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CREATE))!(block!));
1622
1532
  }
1623
- block.select();
1624
- return block;
1533
+ block!.select();
1534
+ return block!;
1625
1535
  }
1626
1536
 
1627
1537
  /**
1628
1538
  * Paste the provided comment onto the workspace.
1629
- * @param {!Element} xmlComment XML workspace comment element.
1630
- * @return {!WorkspaceCommentSvg} The pasted workspace comment.
1631
- * @private
1539
+ * @param xmlComment XML workspace comment element.
1540
+ * @return The pasted workspace comment.
1632
1541
  * @suppress {checkTypes} Suppress checks while workspace comments are not
1633
- * bundled in.
1542
+ * bundled in.
1634
1543
  */
1635
- pasteWorkspaceComment_(xmlComment) {
1544
+ private pasteWorkspaceComment_(xmlComment: Element): WorkspaceCommentSvg {
1636
1545
  eventUtils.disable();
1637
- let comment;
1546
+ let comment: WorkspaceCommentSvg;
1638
1547
  try {
1639
- comment = goog.module.get('Blockly.WorkspaceCommentSvg')
1640
- .fromXml(xmlComment, this);
1548
+ // AnyDuringMigration because: Property 'get' does not exist on type
1549
+ // '(name: string) => void'.
1550
+ comment =
1551
+ WorkspaceCommentSvg.fromXml(xmlComment, this) as AnyDuringMigration;
1641
1552
  // Move the duplicate to original position.
1642
- let commentX = parseInt(xmlComment.getAttribute('x'), 10);
1643
- let commentY = parseInt(xmlComment.getAttribute('y'), 10);
1553
+ // AnyDuringMigration because: Argument of type 'string | null' is not
1554
+ // assignable to parameter of type 'string'.
1555
+ let commentX =
1556
+ parseInt(xmlComment.getAttribute('x') as AnyDuringMigration, 10);
1557
+ // AnyDuringMigration because: Argument of type 'string | null' is not
1558
+ // assignable to parameter of type 'string'.
1559
+ let commentY =
1560
+ parseInt(xmlComment.getAttribute('y') as AnyDuringMigration, 10);
1644
1561
  if (!isNaN(commentX) && !isNaN(commentY)) {
1645
1562
  if (this.RTL) {
1646
1563
  commentX = -commentX;
@@ -1656,7 +1573,9 @@ class WorkspaceSvg extends Workspace {
1656
1573
  eventUtils.enable();
1657
1574
  }
1658
1575
  if (eventUtils.isEnabled()) {
1659
- goog.module.get('Blockly.WorkspaceComment').fireCreateEvent(comment);
1576
+ // AnyDuringMigration because: Property 'get' does not exist on type
1577
+ // '(name: string) => void'.
1578
+ WorkspaceComment.fireCreateEvent(comment);
1660
1579
  }
1661
1580
  comment.select();
1662
1581
  return comment;
@@ -1664,7 +1583,7 @@ class WorkspaceSvg extends Workspace {
1664
1583
 
1665
1584
  /**
1666
1585
  * Refresh the toolbox unless there's a drag in progress.
1667
- * @package
1586
+ * @internal
1668
1587
  */
1669
1588
  refreshToolboxSelection() {
1670
1589
  const ws = this.isFlyout ? this.targetWorkspace : this;
@@ -1676,10 +1595,10 @@ class WorkspaceSvg extends Workspace {
1676
1595
  /**
1677
1596
  * Rename a variable by updating its name in the variable map. Update the
1678
1597
  * flyout to show the renamed variable immediately.
1679
- * @param {string} id ID of the variable to rename.
1680
- * @param {string} newName New variable name.
1598
+ * @param id ID of the variable to rename.
1599
+ * @param newName New variable name.
1681
1600
  */
1682
- renameVariableById(id, newName) {
1601
+ override renameVariableById(id: string, newName: string) {
1683
1602
  super.renameVariableById(id, newName);
1684
1603
  this.refreshToolboxSelection();
1685
1604
  }
@@ -1687,9 +1606,9 @@ class WorkspaceSvg extends Workspace {
1687
1606
  /**
1688
1607
  * Delete a variable by the passed in ID. Update the flyout to show
1689
1608
  * immediately that the variable is deleted.
1690
- * @param {string} id ID of variable to delete.
1609
+ * @param id ID of variable to delete.
1691
1610
  */
1692
- deleteVariableById(id) {
1611
+ override deleteVariableById(id: string) {
1693
1612
  super.deleteVariableById(id);
1694
1613
  this.refreshToolboxSelection();
1695
1614
  }
@@ -1697,15 +1616,16 @@ class WorkspaceSvg extends Workspace {
1697
1616
  /**
1698
1617
  * Create a new variable with the given name. Update the flyout to show the
1699
1618
  * new variable immediately.
1700
- * @param {string} name The new variable's name.
1701
- * @param {?string=} opt_type The type of the variable like 'int' or 'string'.
1619
+ * @param name The new variable's name.
1620
+ * @param opt_type The type of the variable like 'int' or 'string'.
1702
1621
  * Does not need to be unique. Field_variable can filter variables based
1703
1622
  * on their type. This will default to '' which is a specific type.
1704
- * @param {?string=} opt_id The unique ID of the variable. This will default
1705
- * to a UUID.
1706
- * @return {!VariableModel} The newly created variable.
1623
+ * @param opt_id The unique ID of the variable. This will default to a UUID.
1624
+ * @return The newly created variable.
1707
1625
  */
1708
- createVariable(name, opt_type, opt_id) {
1626
+ override createVariable(
1627
+ name: string, opt_type?: string|null,
1628
+ opt_id?: string|null): VariableModel {
1709
1629
  const newVar = super.createVariable(name, opt_type, opt_id);
1710
1630
  this.refreshToolboxSelection();
1711
1631
  return newVar;
@@ -1716,21 +1636,22 @@ class WorkspaceSvg extends Workspace {
1716
1636
  * @deprecated Use workspace.recordDragTargets. (2021 June)
1717
1637
  */
1718
1638
  recordDeleteAreas() {
1719
- utils.deprecation.warn(
1720
- 'WorkspaceSvg.prototype.recordDeleteAreas', 'June 2021', 'June 2022',
1721
- 'WorkspaceSvg.prototype.recordDragTargets');
1639
+ // AnyDuringMigration because: Property 'warn' does not exist on type
1640
+ // 'void'.
1641
+ (utils.deprecation as AnyDuringMigration)
1642
+ .warn(
1643
+ 'WorkspaceSvg.prototype.recordDeleteAreas', 'June 2021',
1644
+ 'June 2022', 'WorkspaceSvg.prototype.recordDragTargets');
1722
1645
  this.recordDragTargets();
1723
1646
  }
1724
1647
 
1725
- /**
1726
- * Make a list of all the delete areas for this workspace.
1727
- */
1648
+ /** Make a list of all the delete areas for this workspace. */
1728
1649
  recordDragTargets() {
1729
1650
  const dragTargets = this.componentManager_.getComponents(
1730
1651
  ComponentManager.Capability.DRAG_TARGET, true);
1731
1652
 
1732
1653
  this.dragTargetAreas_ = [];
1733
- for (let i = 0, targetArea; (targetArea = dragTargets[i]); i++) {
1654
+ for (let i = 0, targetArea; targetArea = dragTargets[i]; i++) {
1734
1655
  const rect = targetArea.getClientRect();
1735
1656
  if (rect) {
1736
1657
  this.dragTargetAreas_.push({
@@ -1742,14 +1663,33 @@ class WorkspaceSvg extends Workspace {
1742
1663
  }
1743
1664
 
1744
1665
  /**
1745
- * Returns the drag target the mouse event is over.
1746
- * @param {!Event} e Mouse move event.
1747
- * @return {?IDragTarget} Null if not over a drag target, or the drag
1748
- * target the event is over.
1666
+ * Obtain a newly created block.
1667
+ * @param prototypeName Name of the language object containing type-specific
1668
+ * functions for this block.
1669
+ * @param opt_id Optional ID. Use this ID if provided, otherwise create a new
1670
+ * ID.
1671
+ * @return The created block.
1749
1672
  */
1750
- getDragTarget(e) {
1751
- for (let i = 0, targetArea; (targetArea = this.dragTargetAreas_[i]); i++) {
1752
- if (targetArea.clientRect.contains(e.clientX, e.clientY)) {
1673
+ override newBlock(prototypeName: string, opt_id?: string): BlockSvg {
1674
+ throw new Error(
1675
+ 'The implementation of newBlock should be ' +
1676
+ 'monkey-patched in by blockly.ts');
1677
+ }
1678
+
1679
+ /**
1680
+ * Returns the drag target the mouse event is over.
1681
+ * @param e Mouse move event.
1682
+ * @return Null if not over a drag target, or the drag target the event is
1683
+ * over.
1684
+ */
1685
+ getDragTarget(e: Event): IDragTarget|null {
1686
+ for (let i = 0, targetArea; targetArea = this.dragTargetAreas_[i]; i++) {
1687
+ // AnyDuringMigration because: Property 'clientY' does not exist on
1688
+ // type 'Event'. AnyDuringMigration because: Property 'clientX' does
1689
+ // not exist on type 'Event'.
1690
+ if (targetArea.clientRect.contains(
1691
+ (e as AnyDuringMigration).clientX,
1692
+ (e as AnyDuringMigration).clientY)) {
1753
1693
  return targetArea.component;
1754
1694
  }
1755
1695
  }
@@ -1758,10 +1698,9 @@ class WorkspaceSvg extends Workspace {
1758
1698
 
1759
1699
  /**
1760
1700
  * Handle a mouse-down on SVG drawing surface.
1761
- * @param {!Event} e Mouse down event.
1762
- * @private
1701
+ * @param e Mouse down event.
1763
1702
  */
1764
- onMouseDown_(e) {
1703
+ private onMouseDown_(e: MouseEvent) {
1765
1704
  const gesture = this.getGesture(e);
1766
1705
  if (gesture) {
1767
1706
  gesture.handleWsStart(e, this);
@@ -1770,10 +1709,10 @@ class WorkspaceSvg extends Workspace {
1770
1709
 
1771
1710
  /**
1772
1711
  * Start tracking a drag of an object on this workspace.
1773
- * @param {!Event} e Mouse down event.
1774
- * @param {!Coordinate} xy Starting location of object.
1712
+ * @param e Mouse down event.
1713
+ * @param xy Starting location of object.
1775
1714
  */
1776
- startDrag(e, xy) {
1715
+ startDrag(e: MouseEvent, xy: Coordinate) {
1777
1716
  // Record the starting offset between the bubble's location and the mouse.
1778
1717
  const point = browserEvents.mouseToSvg(
1779
1718
  e, this.getParentSvg(), this.getInverseScreenCTM());
@@ -1785,32 +1724,31 @@ class WorkspaceSvg extends Workspace {
1785
1724
 
1786
1725
  /**
1787
1726
  * Track a drag of an object on this workspace.
1788
- * @param {!Event} e Mouse move event.
1789
- * @return {!Coordinate} New location of object.
1727
+ * @param e Mouse move event.
1728
+ * @return New location of object.
1790
1729
  */
1791
- moveDrag(e) {
1730
+ moveDrag(e: MouseEvent): Coordinate {
1792
1731
  const point = browserEvents.mouseToSvg(
1793
1732
  e, this.getParentSvg(), this.getInverseScreenCTM());
1794
1733
  // Fix scale of mouse event.
1795
1734
  point.x /= this.scale;
1796
1735
  point.y /= this.scale;
1797
- return Coordinate.sum(
1798
- /** @type {!Coordinate} */ (this.dragDeltaXY_), point);
1736
+ return Coordinate.sum((this.dragDeltaXY_), point);
1799
1737
  }
1800
1738
 
1801
1739
  /**
1802
1740
  * Is the user currently dragging a block or scrolling the flyout/workspace?
1803
- * @return {boolean} True if currently dragging or scrolling.
1741
+ * @return True if currently dragging or scrolling.
1804
1742
  */
1805
- isDragging() {
1743
+ isDragging(): boolean {
1806
1744
  return this.currentGesture_ !== null && this.currentGesture_.isDragging();
1807
1745
  }
1808
1746
 
1809
1747
  /**
1810
1748
  * Is this workspace draggable?
1811
- * @return {boolean} True if this workspace may be dragged.
1749
+ * @return True if this workspace may be dragged.
1812
1750
  */
1813
- isDraggable() {
1751
+ isDraggable(): boolean {
1814
1752
  return this.options.moveOptions && this.options.moveOptions.drag;
1815
1753
  }
1816
1754
 
@@ -1822,47 +1760,43 @@ class WorkspaceSvg extends Workspace {
1822
1760
  * through zooming with the scroll wheel or pinch (since the zoom is centered
1823
1761
  * on the mouse position). This does not include zooming with the zoom
1824
1762
  * controls since the X Y coordinates are decided programmatically.
1825
- * @return {boolean} True if the workspace is movable, false otherwise.
1763
+ * @return True if the workspace is movable, false otherwise.
1826
1764
  */
1827
- isMovable() {
1828
- return (this.options.moveOptions &&
1829
- !!this.options.moveOptions.scrollbars) ||
1830
- (this.options.moveOptions && this.options.moveOptions.wheel) ||
1831
- (this.options.moveOptions && this.options.moveOptions.drag) ||
1832
- (this.options.zoomOptions && this.options.zoomOptions.wheel) ||
1833
- (this.options.zoomOptions && this.options.zoomOptions.pinch);
1765
+ isMovable(): boolean {
1766
+ return this.options.moveOptions && !!this.options.moveOptions.scrollbars ||
1767
+ this.options.moveOptions && this.options.moveOptions.wheel ||
1768
+ this.options.moveOptions && this.options.moveOptions.drag ||
1769
+ this.options.zoomOptions && this.options.zoomOptions.wheel ||
1770
+ this.options.zoomOptions && this.options.zoomOptions.pinch;
1834
1771
  }
1835
1772
 
1836
1773
  /**
1837
1774
  * Is this workspace movable horizontally?
1838
- * @return {boolean} True if the workspace is movable horizontally, false
1839
- * otherwise.
1775
+ * @return True if the workspace is movable horizontally, false otherwise.
1840
1776
  */
1841
- isMovableHorizontally() {
1777
+ isMovableHorizontally(): boolean {
1842
1778
  const hasScrollbars = !!this.scrollbar;
1843
1779
  return this.isMovable() &&
1844
1780
  (!hasScrollbars ||
1845
- (hasScrollbars && this.scrollbar.canScrollHorizontally()));
1781
+ hasScrollbars && this.scrollbar.canScrollHorizontally());
1846
1782
  }
1847
1783
 
1848
1784
  /**
1849
1785
  * Is this workspace movable vertically?
1850
- * @return {boolean} True if the workspace is movable vertically, false
1851
- * otherwise.
1786
+ * @return True if the workspace is movable vertically, false otherwise.
1852
1787
  */
1853
- isMovableVertically() {
1788
+ isMovableVertically(): boolean {
1854
1789
  const hasScrollbars = !!this.scrollbar;
1855
1790
  return this.isMovable() &&
1856
1791
  (!hasScrollbars ||
1857
- (hasScrollbars && this.scrollbar.canScrollVertically()));
1792
+ hasScrollbars && this.scrollbar.canScrollVertically());
1858
1793
  }
1859
1794
 
1860
1795
  /**
1861
1796
  * Handle a mouse-wheel on SVG drawing surface.
1862
- * @param {!Event} e Mouse wheel event.
1863
- * @private
1797
+ * @param e Mouse wheel event.
1864
1798
  */
1865
- onMouseWheel_(e) {
1799
+ private onMouseWheel_(e: WheelEvent) {
1866
1800
  // Don't scroll or zoom anything if drag is in progress.
1867
1801
  if (Gesture.inProgress()) {
1868
1802
  e.preventDefault();
@@ -1916,10 +1850,10 @@ class WorkspaceSvg extends Workspace {
1916
1850
  * Calculate the bounding box for the blocks on the workspace.
1917
1851
  * Coordinate system: workspace coordinates.
1918
1852
  *
1919
- * @return {!Rect} Contains the position and size of the
1920
- * bounding box containing the blocks on the workspace.
1853
+ * @return Contains the position and size of the bounding box containing the
1854
+ * blocks on the workspace.
1921
1855
  */
1922
- getBlocksBoundingBox() {
1856
+ getBlocksBoundingBox(): Rect {
1923
1857
  const topElements = this.getTopBoundedElements();
1924
1858
  // There are no blocks, return empty rectangle.
1925
1859
  if (!topElements.length) {
@@ -1932,7 +1866,8 @@ class WorkspaceSvg extends Workspace {
1932
1866
  // Start at 1 since the 0th block was used for initialization.
1933
1867
  for (let i = 1; i < topElements.length; i++) {
1934
1868
  const topElement = topElements[i];
1935
- if (topElement.isInsertionMarker && topElement.isInsertionMarker()) {
1869
+ if ((topElement as AnyDuringMigration).isInsertionmarker &&
1870
+ (topElement as AnyDuringMigration).isInsertionMarker()) {
1936
1871
  continue;
1937
1872
  }
1938
1873
  const blockBoundary = topElement.getBoundingRectangle();
@@ -1952,15 +1887,13 @@ class WorkspaceSvg extends Workspace {
1952
1887
  return boundary;
1953
1888
  }
1954
1889
 
1955
- /**
1956
- * Clean up the workspace by ordering all the blocks in a column.
1957
- */
1890
+ /** Clean up the workspace by ordering all the blocks in a column. */
1958
1891
  cleanUp() {
1959
1892
  this.setResizesEnabled(false);
1960
1893
  eventUtils.setGroup(true);
1961
1894
  const topBlocks = this.getTopBlocks(true);
1962
1895
  let cursorY = 0;
1963
- for (let i = 0, block; (block = topBlocks[i]); i++) {
1896
+ for (let i = 0, block; block = topBlocks[i]; i++) {
1964
1897
  if (!block.isMovable()) {
1965
1898
  continue;
1966
1899
  }
@@ -1977,15 +1910,18 @@ class WorkspaceSvg extends Workspace {
1977
1910
 
1978
1911
  /**
1979
1912
  * Show the context menu for the workspace.
1980
- * @param {!Event} e Mouse event.
1981
- * @package
1913
+ * @param e Mouse event.
1914
+ * @internal
1982
1915
  */
1983
- showContextMenu(e) {
1916
+ showContextMenu(e: Event) {
1984
1917
  if (this.options.readOnly || this.isFlyout) {
1985
1918
  return;
1986
1919
  }
1920
+ // AnyDuringMigration because: Argument of type '{ workspace: this; }' is
1921
+ // not assignable to parameter of type 'Scope'.
1987
1922
  const menuOptions = ContextMenuRegistry.registry.getContextMenuOptions(
1988
- ContextMenuRegistry.ScopeType.WORKSPACE, {workspace: this});
1923
+ ContextMenuRegistry.ScopeType.WORKSPACE,
1924
+ {workspace: this} as AnyDuringMigration);
1989
1925
 
1990
1926
  // Allow the developer to add or modify menuOptions.
1991
1927
  if (this.configureContextMenu) {
@@ -1997,11 +1933,10 @@ class WorkspaceSvg extends Workspace {
1997
1933
 
1998
1934
  /**
1999
1935
  * Modify the block tree on the existing toolbox.
2000
- * @param {?toolbox.ToolboxDefinition} toolboxDef
2001
- * DOM tree of toolbox contents, string of toolbox contents, or JSON
2002
- * representing toolbox definition.
1936
+ * @param toolboxDef DOM tree of toolbox contents, string of toolbox contents,
1937
+ * or JSON representing toolbox definition.
2003
1938
  */
2004
- updateToolbox(toolboxDef) {
1939
+ updateToolbox(toolboxDef: toolbox.ToolboxDefinition|null) {
2005
1940
  const parsedToolboxDef = toolbox.convertToolboxDefToJson(toolboxDef);
2006
1941
 
2007
1942
  if (!parsedToolboxDef) {
@@ -2029,14 +1964,14 @@ class WorkspaceSvg extends Workspace {
2029
1964
  }
2030
1965
  }
2031
1966
 
2032
- /**
2033
- * Mark this workspace as the currently focused main workspace.
2034
- */
1967
+ /** Mark this workspace as the currently focused main workspace. */
2035
1968
  markFocused() {
2036
1969
  if (this.options.parentWorkspace) {
2037
1970
  this.options.parentWorkspace.markFocused();
2038
1971
  } else {
2039
- common.setMainWorkspace(this);
1972
+ // AnyDuringMigration because: Argument of type 'this' is not assignable
1973
+ // to parameter of type 'Workspace'.
1974
+ common.setMainWorkspace(this as AnyDuringMigration);
2040
1975
  // We call e.preventDefault in many event handlers which means we
2041
1976
  // need to explicitly grab focus (e.g from a textarea) because
2042
1977
  // the browser will not do it for us. How to do this is browser
@@ -2045,18 +1980,20 @@ class WorkspaceSvg extends Workspace {
2045
1980
  }
2046
1981
  }
2047
1982
 
2048
- /**
2049
- * Set the workspace to have focus in the browser.
2050
- * @private
2051
- */
2052
- setBrowserFocus() {
1983
+ /** Set the workspace to have focus in the browser. */
1984
+ private setBrowserFocus() {
2053
1985
  // Blur whatever was focused since explicitly grabbing focus below does not
2054
1986
  // work in Edge.
2055
1987
  // In IE, SVGs can't be blurred or focused. Check to make sure the current
2056
1988
  // focus can be blurred before doing so.
2057
1989
  // See https://github.com/google/blockly/issues/4440
2058
- if (document.activeElement && document.activeElement.blur) {
2059
- document.activeElement.blur();
1990
+ // AnyDuringMigration because: Property 'blur' does not exist on type
1991
+ // 'Element'.
1992
+ if (document.activeElement &&
1993
+ (document.activeElement as AnyDuringMigration).blur) {
1994
+ // AnyDuringMigration because: Property 'blur' does not exist on type
1995
+ // 'Element'.
1996
+ (document.activeElement as AnyDuringMigration).blur();
2060
1997
  }
2061
1998
  try {
2062
1999
  // Focus the workspace SVG - this is for Chrome and Firefox.
@@ -2068,11 +2005,11 @@ class WorkspaceSvg extends Workspace {
2068
2005
  try {
2069
2006
  // In IE11, use setActive (which is IE only) so the page doesn't scroll
2070
2007
  // to the workspace gaining focus.
2071
- this.getParentSvg().parentNode.setActive();
2008
+ (this.getParentSvg().parentElement as AnyDuringMigration).setActive();
2072
2009
  } catch (e) {
2073
2010
  // setActive support was discontinued in Edge so when that fails, call
2074
2011
  // focus instead.
2075
- this.getParentSvg().parentNode.focus({preventScroll: true});
2012
+ this.getParentSvg().parentElement!.focus({preventScroll: true});
2076
2013
  }
2077
2014
  }
2078
2015
  }
@@ -2080,16 +2017,16 @@ class WorkspaceSvg extends Workspace {
2080
2017
  /**
2081
2018
  * Zooms the workspace in or out relative to/centered on the given (x, y)
2082
2019
  * coordinate.
2083
- * @param {number} x X coordinate of center, in pixel units relative to the
2084
- * top-left corner of the parentSVG.
2085
- * @param {number} y Y coordinate of center, in pixel units relative to the
2086
- * top-left corner of the parentSVG.
2087
- * @param {number} amount Amount of zooming. The formula for the new scale
2088
- * is newScale = currentScale * (scaleSpeed^amount). scaleSpeed is set in
2089
- * the workspace options. Negative amount values zoom out, and positive
2090
- * amount values zoom in.
2091
- */
2092
- zoom(x, y, amount) {
2020
+ * @param x X coordinate of center, in pixel units relative to the top-left
2021
+ * corner of the parentSVG.
2022
+ * @param y Y coordinate of center, in pixel units relative to the top-left
2023
+ * corner of the parentSVG.
2024
+ * @param amount Amount of zooming. The formula for the new scale is newScale
2025
+ * = currentScale * (scaleSpeed^amount). scaleSpeed is set in the
2026
+ * workspace options. Negative amount values zoom out, and positive amount
2027
+ * values zoom in.
2028
+ */
2029
+ zoom(x: number, y: number, amount: number) {
2093
2030
  // Scale factor.
2094
2031
  const speed = this.options.zoomOptions.scaleSpeed;
2095
2032
  let scaleChange = Math.pow(speed, amount);
@@ -2109,17 +2046,17 @@ class WorkspaceSvg extends Workspace {
2109
2046
  // canvas' space, so that they are in workspace units relative to the top
2110
2047
  // left of the visible portion of the workspace.
2111
2048
  let matrix = this.getCanvas().getCTM();
2112
- let center = this.getParentSvg().createSVGPoint();
2049
+ let center = (this.getParentSvg()).createSVGPoint();
2113
2050
  center.x = x;
2114
2051
  center.y = y;
2115
- center = center.matrixTransform(matrix.inverse());
2052
+ center = center.matrixTransform(matrix!.inverse());
2116
2053
  x = center.x;
2117
2054
  y = center.y;
2118
2055
 
2119
2056
  // Find the new scrollX/scrollY so that the center remains in the same
2120
2057
  // position (relative to the center) after we zoom.
2121
2058
  // newScale and matrix.a should be identical (within a rounding error).
2122
- matrix = matrix.translate(x * (1 - scaleChange), y * (1 - scaleChange))
2059
+ matrix = matrix!.translate(x * (1 - scaleChange), y * (1 - scaleChange))
2123
2060
  .scale(scaleChange);
2124
2061
  // scrollX and scrollY are in pixels.
2125
2062
  // The scrollX and scrollY still need to have absoluteLeft and absoluteTop
@@ -2132,9 +2069,9 @@ class WorkspaceSvg extends Workspace {
2132
2069
 
2133
2070
  /**
2134
2071
  * Zooming the blocks centered in the center of view with zooming in or out.
2135
- * @param {number} type Type of zooming (-1 zooming out and 1 zooming in).
2072
+ * @param type Type of zooming (-1 zooming out and 1 zooming in).
2136
2073
  */
2137
- zoomCenter(type) {
2074
+ zoomCenter(type: number) {
2138
2075
  const metrics = this.getMetrics();
2139
2076
  let x;
2140
2077
  let y;
@@ -2147,15 +2084,13 @@ class WorkspaceSvg extends Workspace {
2147
2084
  x = metrics.svgWidth ? metrics.svgWidth / 2 : 0;
2148
2085
  y = metrics.svgHeight ? metrics.svgHeight / 2 : 0;
2149
2086
  } else {
2150
- x = (metrics.viewWidth / 2) + metrics.absoluteLeft;
2151
- y = (metrics.viewHeight / 2) + metrics.absoluteTop;
2087
+ x = metrics.viewWidth / 2 + metrics.absoluteLeft;
2088
+ y = metrics.viewHeight / 2 + metrics.absoluteTop;
2152
2089
  }
2153
2090
  this.zoom(x, y, type);
2154
2091
  }
2155
2092
 
2156
- /**
2157
- * Zoom the blocks to fit in the workspace if possible.
2158
- */
2093
+ /** Zoom the blocks to fit in the workspace if possible. */
2159
2094
  zoomToFit() {
2160
2095
  if (!this.isMovable()) {
2161
2096
  console.warn(
@@ -2168,8 +2103,9 @@ class WorkspaceSvg extends Workspace {
2168
2103
  let workspaceWidth = metrics.viewWidth;
2169
2104
  let workspaceHeight = metrics.viewHeight;
2170
2105
  const blocksBox = this.getBlocksBoundingBox();
2171
- let blocksWidth = blocksBox.right - blocksBox.left;
2172
- let blocksHeight = blocksBox.bottom - blocksBox.top;
2106
+ const doubleMargin = ZOOM_TO_FIT_MARGIN * 2;
2107
+ let blocksWidth = blocksBox.right - blocksBox.left + doubleMargin;
2108
+ let blocksHeight = blocksBox.bottom - blocksBox.top + doubleMargin;
2173
2109
  if (!blocksWidth) {
2174
2110
  return; // Prevents zooming to infinity.
2175
2111
  }
@@ -2205,33 +2141,23 @@ class WorkspaceSvg extends Workspace {
2205
2141
  /**
2206
2142
  * Add a transition class to the block and bubble canvas, to animate any
2207
2143
  * transform changes.
2208
- * @package
2144
+ * @internal
2209
2145
  */
2210
2146
  beginCanvasTransition() {
2211
- dom.addClass(
2212
- /** @type {!SVGElement} */ (this.svgBlockCanvas_),
2213
- 'blocklyCanvasTransitioning');
2214
- dom.addClass(
2215
- /** @type {!SVGElement} */ (this.svgBubbleCanvas_),
2216
- 'blocklyCanvasTransitioning');
2147
+ dom.addClass((this.svgBlockCanvas_), 'blocklyCanvasTransitioning');
2148
+ dom.addClass((this.svgBubbleCanvas_), 'blocklyCanvasTransitioning');
2217
2149
  }
2218
2150
 
2219
2151
  /**
2220
2152
  * Remove transition class from the block and bubble canvas.
2221
- * @package
2153
+ * @internal
2222
2154
  */
2223
2155
  endCanvasTransition() {
2224
- dom.removeClass(
2225
- /** @type {!SVGElement} */ (this.svgBlockCanvas_),
2226
- 'blocklyCanvasTransitioning');
2227
- dom.removeClass(
2228
- /** @type {!SVGElement} */ (this.svgBubbleCanvas_),
2229
- 'blocklyCanvasTransitioning');
2156
+ dom.removeClass((this.svgBlockCanvas_), 'blocklyCanvasTransitioning');
2157
+ dom.removeClass((this.svgBubbleCanvas_), 'blocklyCanvasTransitioning');
2230
2158
  }
2231
2159
 
2232
- /**
2233
- * Center the workspace.
2234
- */
2160
+ /** Center the workspace. */
2235
2161
  scrollCenter() {
2236
2162
  if (!this.isMovable()) {
2237
2163
  console.warn(
@@ -2253,10 +2179,9 @@ class WorkspaceSvg extends Workspace {
2253
2179
  /**
2254
2180
  * Scroll the workspace to center on the given block. If the block has other
2255
2181
  * blocks stacked below it, the workspace will be centered on the stack.
2256
- * @param {?string} id ID of block center on.
2257
- * @public
2182
+ * @param id ID of block center on.
2258
2183
  */
2259
- centerOnBlock(id) {
2184
+ centerOnBlock(id: string|null) {
2260
2185
  if (!this.isMovable()) {
2261
2186
  console.warn(
2262
2187
  'Tried to move a non-movable workspace. This could result' +
@@ -2279,7 +2204,7 @@ class WorkspaceSvg extends Workspace {
2279
2204
 
2280
2205
  // In RTL the block's position is the top right of the block, not top left.
2281
2206
  const multiplier = this.RTL ? -1 : 1;
2282
- const blockCenterX = xy.x + (multiplier * heightWidth.width / 2);
2207
+ const blockCenterX = xy.x + multiplier * heightWidth.width / 2;
2283
2208
 
2284
2209
  // Workspace scale, used to convert from workspace coordinates to pixels.
2285
2210
  const scale = this.scale;
@@ -2309,9 +2234,9 @@ class WorkspaceSvg extends Workspace {
2309
2234
 
2310
2235
  /**
2311
2236
  * Set the workspace's zoom factor.
2312
- * @param {number} newScale Zoom factor. Units: (pixels / workspaceUnit).
2237
+ * @param newScale Zoom factor. Units: (pixels / workspaceUnit).
2313
2238
  */
2314
- setScale(newScale) {
2239
+ setScale(newScale: number) {
2315
2240
  if (this.options.zoomOptions.maxScale &&
2316
2241
  newScale > this.options.zoomOptions.maxScale) {
2317
2242
  newScale = this.options.zoomOptions.maxScale;
@@ -2358,10 +2283,9 @@ class WorkspaceSvg extends Workspace {
2358
2283
  /**
2359
2284
  * Get the workspace's zoom factor. If the workspace has a parent, we call
2360
2285
  * into the parent to get the workspace scale.
2361
- * @return {number} The workspace zoom factor. Units: (pixels /
2362
- * workspaceUnit).
2286
+ * @return The workspace zoom factor. Units: (pixels / workspaceUnit).
2363
2287
  */
2364
- getScale() {
2288
+ getScale(): number {
2365
2289
  if (this.options.parentWorkspace) {
2366
2290
  return this.options.parentWorkspace.getScale();
2367
2291
  }
@@ -2372,12 +2296,13 @@ class WorkspaceSvg extends Workspace {
2372
2296
  * Scroll the workspace to a specified offset (in pixels), keeping in the
2373
2297
  * workspace bounds. See comment on workspaceSvg.scrollX for more detail on
2374
2298
  * the meaning of these values.
2375
- * @param {number} x Target X to scroll to.
2376
- * @param {number} y Target Y to scroll to.
2377
- * @package
2299
+ * @param x Target X to scroll to.
2300
+ * @param y Target Y to scroll to.
2301
+ * @internal
2378
2302
  */
2379
- scroll(x, y) {
2380
- this.hideChaff(/* opt_onlyClosePopups= */ true);
2303
+ scroll(x: number, y: number) {
2304
+ this.hideChaff(/* opt_onlyClosePopups= */
2305
+ true);
2381
2306
 
2382
2307
  // Keep scrolling within the bounds of the content.
2383
2308
  const metrics = this.getMetrics();
@@ -2415,95 +2340,91 @@ class WorkspaceSvg extends Workspace {
2415
2340
 
2416
2341
  /**
2417
2342
  * Find the block on this workspace with the specified ID.
2418
- * @param {string} id ID of block to find.
2419
- * @return {?BlockSvg} The sought after block, or null if not found.
2420
- * @override
2343
+ * @param id ID of block to find.
2344
+ * @return The sought after block, or null if not found.
2421
2345
  */
2422
- getBlockById(id) {
2423
- return /** @type {BlockSvg} */ (super.getBlockById(id));
2346
+ override getBlockById(id: string): BlockSvg|null {
2347
+ return super.getBlockById(id) as BlockSvg;
2424
2348
  }
2425
2349
 
2426
2350
  /**
2427
2351
  * Find all blocks in workspace. Blocks are optionally sorted
2428
2352
  * by position; top to bottom (with slight LTR or RTL bias).
2429
- * @param {boolean} ordered Sort the list if true.
2430
- * @return {!Array<!BlockSvg>} Array of blocks.
2353
+ * @param ordered Sort the list if true.
2354
+ * @return Array of blocks.
2431
2355
  */
2432
- getAllBlocks(ordered) {
2433
- return /** @type {!Array<!BlockSvg>} */ (super.getAllBlocks(ordered));
2356
+ override getAllBlocks(ordered: boolean): BlockSvg[] {
2357
+ return super.getAllBlocks(ordered) as BlockSvg[];
2434
2358
  }
2435
2359
 
2436
2360
  /**
2437
2361
  * Finds the top-level blocks and returns them. Blocks are optionally sorted
2438
2362
  * by position; top to bottom (with slight LTR or RTL bias).
2439
- * @param {boolean} ordered Sort the list if true.
2440
- * @return {!Array<!BlockSvg>} The top-level block objects.
2441
- * @override
2363
+ * @param ordered Sort the list if true.
2364
+ * @return The top-level block objects.
2442
2365
  */
2443
- getTopBlocks(ordered) {
2444
- return super.getTopBlocks(ordered);
2366
+ override getTopBlocks(ordered: boolean): BlockSvg[] {
2367
+ return super.getTopBlocks(ordered) as BlockSvg[];
2445
2368
  }
2446
2369
 
2447
2370
  /**
2448
2371
  * Adds a block to the list of top blocks.
2449
- * @param {!Block} block Block to add.
2372
+ * @param block Block to add.
2450
2373
  */
2451
- addTopBlock(block) {
2452
- this.addTopBoundedElement(/** @type {!BlockSvg} */ (block));
2374
+ override addTopBlock(block: Block) {
2375
+ this.addTopBoundedElement(block as BlockSvg);
2453
2376
  super.addTopBlock(block);
2454
2377
  }
2455
2378
 
2456
2379
  /**
2457
2380
  * Removes a block from the list of top blocks.
2458
- * @param {!Block} block Block to remove.
2381
+ * @param block Block to remove.
2459
2382
  */
2460
- removeTopBlock(block) {
2461
- this.removeTopBoundedElement(/** @type {!BlockSvg} */ (block));
2383
+ override removeTopBlock(block: Block) {
2384
+ this.removeTopBoundedElement(block as BlockSvg);
2462
2385
  super.removeTopBlock(block);
2463
2386
  }
2464
2387
 
2465
2388
  /**
2466
2389
  * Adds a comment to the list of top comments.
2467
- * @param {!WorkspaceComment} comment comment to add.
2390
+ * @param comment comment to add.
2468
2391
  */
2469
- addTopComment(comment) {
2470
- this.addTopBoundedElement(
2471
- /** @type {!WorkspaceCommentSvg} */ (comment));
2392
+ override addTopComment(comment: WorkspaceComment) {
2393
+ this.addTopBoundedElement(comment as WorkspaceCommentSvg);
2472
2394
  super.addTopComment(comment);
2473
2395
  }
2474
2396
 
2475
2397
  /**
2476
2398
  * Removes a comment from the list of top comments.
2477
- * @param {!WorkspaceComment} comment comment to remove.
2399
+ * @param comment comment to remove.
2478
2400
  */
2479
- removeTopComment(comment) {
2480
- this.removeTopBoundedElement(
2481
- /** @type {!WorkspaceCommentSvg} */ (comment));
2401
+ override removeTopComment(comment: WorkspaceComment) {
2402
+ this.removeTopBoundedElement(comment as WorkspaceCommentSvg);
2482
2403
  super.removeTopComment(comment);
2483
2404
  }
2484
2405
 
2485
2406
  /**
2486
2407
  * Adds a bounded element to the list of top bounded elements.
2487
- * @param {!IBoundedElement} element Bounded element to add.
2408
+ * @param element Bounded element to add.
2488
2409
  */
2489
- addTopBoundedElement(element) {
2410
+ addTopBoundedElement(element: IBoundedElement) {
2490
2411
  this.topBoundedElements_.push(element);
2491
2412
  }
2492
2413
 
2493
2414
  /**
2494
2415
  * Removes a bounded element from the list of top bounded elements.
2495
- * @param {!IBoundedElement} element Bounded element to remove.
2416
+ * @param element Bounded element to remove.
2496
2417
  */
2497
- removeTopBoundedElement(element) {
2418
+ removeTopBoundedElement(element: IBoundedElement) {
2498
2419
  arrayUtils.removeElem(this.topBoundedElements_, element);
2499
2420
  }
2500
2421
 
2501
2422
  /**
2502
2423
  * Finds the top-level bounded elements and returns them.
2503
- * @return {!Array<!IBoundedElement>} The top-level bounded elements.
2424
+ * @return The top-level bounded elements.
2504
2425
  */
2505
- getTopBoundedElements() {
2506
- return [].concat(this.topBoundedElements_);
2426
+ getTopBoundedElements(): IBoundedElement[] {
2427
+ return (new Array<IBoundedElement>()).concat(this.topBoundedElements_);
2507
2428
  }
2508
2429
 
2509
2430
  /**
@@ -2511,10 +2432,10 @@ class WorkspaceSvg extends Workspace {
2511
2432
  * If enabled, workspace will resize when appropriate.
2512
2433
  * If disabled, workspace will not resize until re-enabled.
2513
2434
  * Use to avoid resizing during a batch operation, for performance.
2514
- * @param {boolean} enabled Whether resizes should be enabled.
2435
+ * @param enabled Whether resizes should be enabled.
2515
2436
  */
2516
- setResizesEnabled(enabled) {
2517
- const reenabled = (!this.resizesEnabled_ && enabled);
2437
+ setResizesEnabled(enabled: boolean) {
2438
+ const reenabled = !this.resizesEnabled_ && enabled;
2518
2439
  this.resizesEnabled_ = enabled;
2519
2440
  if (reenabled) {
2520
2441
  // Newly enabled. Trigger a resize.
@@ -2526,7 +2447,7 @@ class WorkspaceSvg extends Workspace {
2526
2447
  * Dispose of all blocks in workspace, with an optimization to prevent
2527
2448
  * resizes.
2528
2449
  */
2529
- clear() {
2450
+ override clear() {
2530
2451
  this.setResizesEnabled(false);
2531
2452
  super.clear();
2532
2453
  this.topBoundedElements_ = [];
@@ -2540,11 +2461,11 @@ class WorkspaceSvg extends Workspace {
2540
2461
  * <button text="create variable" callbackKey="CREATE_VARIABLE"></button>
2541
2462
  * should be matched by a call to
2542
2463
  * registerButtonCallback("CREATE_VARIABLE", yourCallbackFunction).
2543
- * @param {string} key The name to use to look up this function.
2544
- * @param {function(!FlyoutButton)} func The function to call when the
2545
- * given button is clicked.
2464
+ * @param key The name to use to look up this function.
2465
+ * @param func The function to call when the given button is clicked.
2546
2466
  */
2547
- registerButtonCallback(key, func) {
2467
+ registerButtonCallback(
2468
+ key: string, func: (p1: FlyoutButton) => AnyDuringMigration) {
2548
2469
  if (typeof func !== 'function') {
2549
2470
  throw TypeError('Button callbacks must be functions.');
2550
2471
  }
@@ -2554,20 +2475,21 @@ class WorkspaceSvg extends Workspace {
2554
2475
  /**
2555
2476
  * Get the callback function associated with a given key, for clicks on
2556
2477
  * buttons and labels in the flyout.
2557
- * @param {string} key The name to use to look up the function.
2558
- * @return {?function(!FlyoutButton)} The function corresponding to the
2559
- * given key for this workspace; null if no callback is registered.
2478
+ * @param key The name to use to look up the function.
2479
+ * @return The function corresponding to the given key for this workspace;
2480
+ * null if no callback is registered.
2560
2481
  */
2561
- getButtonCallback(key) {
2482
+ getButtonCallback(key: string):
2483
+ ((p1: FlyoutButton) => AnyDuringMigration)|null {
2562
2484
  const result = this.flyoutButtonCallbacks_[key];
2563
2485
  return result ? result : null;
2564
2486
  }
2565
2487
 
2566
2488
  /**
2567
2489
  * Remove a callback for a click on a button in the flyout.
2568
- * @param {string} key The name associated with the callback function.
2490
+ * @param key The name associated with the callback function.
2569
2491
  */
2570
- removeButtonCallback(key) {
2492
+ removeButtonCallback(key: string) {
2571
2493
  this.flyoutButtonCallbacks_[key] = null;
2572
2494
  }
2573
2495
 
@@ -2575,11 +2497,11 @@ class WorkspaceSvg extends Workspace {
2575
2497
  * Register a callback function associated with a given key, for populating
2576
2498
  * custom toolbox categories in this workspace. See the variable and
2577
2499
  * procedure categories as an example.
2578
- * @param {string} key The name to use to look up this function.
2579
- * @param {function(!WorkspaceSvg): !toolbox.FlyoutDefinition} func The
2580
- * function to call when the given toolbox category is opened.
2500
+ * @param key The name to use to look up this function.
2501
+ * @param func The function to call when the given toolbox category is opened.
2581
2502
  */
2582
- registerToolboxCategoryCallback(key, func) {
2503
+ registerToolboxCategoryCallback(
2504
+ key: string, func: (p1: WorkspaceSvg) => toolbox.FlyoutDefinition) {
2583
2505
  if (typeof func !== 'function') {
2584
2506
  throw TypeError('Toolbox category callbacks must be functions.');
2585
2507
  }
@@ -2589,35 +2511,34 @@ class WorkspaceSvg extends Workspace {
2589
2511
  /**
2590
2512
  * Get the callback function associated with a given key, for populating
2591
2513
  * custom toolbox categories in this workspace.
2592
- * @param {string} key The name to use to look up the function.
2593
- * @return {?function(!WorkspaceSvg): !toolbox.FlyoutDefinition} The function
2594
- * corresponding to the given key for this workspace, or null if no
2595
- * function is registered.
2514
+ * @param key The name to use to look up the function.
2515
+ * @return The function corresponding to the given key for this workspace, or
2516
+ * null if no function is registered.
2596
2517
  */
2597
- getToolboxCategoryCallback(key) {
2518
+ getToolboxCategoryCallback(key: string):
2519
+ ((p1: WorkspaceSvg) => toolbox.FlyoutDefinition)|null {
2598
2520
  return this.toolboxCategoryCallbacks_[key] || null;
2599
2521
  }
2600
2522
 
2601
2523
  /**
2602
2524
  * Remove a callback for a click on a custom category's name in the toolbox.
2603
- * @param {string} key The name associated with the callback function.
2525
+ * @param key The name associated with the callback function.
2604
2526
  */
2605
- removeToolboxCategoryCallback(key) {
2527
+ removeToolboxCategoryCallback(key: string) {
2606
2528
  this.toolboxCategoryCallbacks_[key] = null;
2607
2529
  }
2608
2530
 
2609
2531
  /**
2610
2532
  * Look up the gesture that is tracking this touch stream on this workspace.
2611
2533
  * May create a new gesture.
2612
- * @param {!Event} e Mouse event or touch event.
2613
- * @return {?TouchGesture} The gesture that is tracking this touch
2614
- * stream, or null if no valid gesture exists.
2615
- * @package
2534
+ * @param e Mouse event or touch event.
2535
+ * @return The gesture that is tracking this touch stream, or null if no valid
2536
+ * gesture exists.
2537
+ * @internal
2616
2538
  */
2617
- getGesture(e) {
2618
- const isStart =
2619
- (e.type === 'mousedown' || e.type === 'touchstart' ||
2620
- e.type === 'pointerdown');
2539
+ getGesture(e: Event): TouchGesture|null {
2540
+ const isStart = e.type === 'mousedown' || e.type === 'touchstart' ||
2541
+ e.type === 'pointerdown';
2621
2542
 
2622
2543
  const gesture = this.currentGesture_;
2623
2544
  if (gesture) {
@@ -2643,15 +2564,17 @@ class WorkspaceSvg extends Workspace {
2643
2564
 
2644
2565
  /**
2645
2566
  * Clear the reference to the current gesture.
2646
- * @package
2567
+ * @internal
2647
2568
  */
2648
2569
  clearGesture() {
2649
- this.currentGesture_ = null;
2570
+ // AnyDuringMigration because: Type 'null' is not assignable to type
2571
+ // 'TouchGesture'.
2572
+ this.currentGesture_ = null as AnyDuringMigration;
2650
2573
  }
2651
2574
 
2652
2575
  /**
2653
2576
  * Cancel the current gesture, if one exists.
2654
- * @package
2577
+ * @internal
2655
2578
  */
2656
2579
  cancelCurrentGesture() {
2657
2580
  if (this.currentGesture_) {
@@ -2661,26 +2584,26 @@ class WorkspaceSvg extends Workspace {
2661
2584
 
2662
2585
  /**
2663
2586
  * Get the audio manager for this workspace.
2664
- * @return {!WorkspaceAudio} The audio manager for this workspace.
2587
+ * @return The audio manager for this workspace.
2665
2588
  */
2666
- getAudioManager() {
2589
+ getAudioManager(): WorkspaceAudio {
2667
2590
  return this.audioManager_;
2668
2591
  }
2669
2592
 
2670
2593
  /**
2671
2594
  * Get the grid object for this workspace, or null if there is none.
2672
- * @return {?Grid} The grid object for this workspace.
2673
- * @package
2595
+ * @return The grid object for this workspace.
2596
+ * @internal
2674
2597
  */
2675
- getGrid() {
2598
+ getGrid(): Grid|null {
2676
2599
  return this.grid_;
2677
2600
  }
2678
2601
 
2679
2602
  /**
2680
2603
  * Close tooltips, context menus, dropdown selections, etc.
2681
- * @param {boolean=} opt_onlyClosePopups Whether only popups should be closed.
2604
+ * @param opt_onlyClosePopups Whether only popups should be closed.
2682
2605
  */
2683
- hideChaff(opt_onlyClosePopups) {
2606
+ hideChaff(opt_onlyClosePopups?: boolean) {
2684
2607
  Tooltip.hide();
2685
2608
  WidgetDiv.hide();
2686
2609
  dropDownDiv.hideWithoutAnimation();
@@ -2694,12 +2617,11 @@ class WorkspaceSvg extends Workspace {
2694
2617
 
2695
2618
  /**
2696
2619
  * Sets the X/Y translations of a top level workspace.
2697
- * @param {!Object} xyRatio Contains an x and/or y property which is a float
2698
- * between 0 and 1 specifying the degree of scrolling.
2699
- * @private
2700
- * @this {WorkspaceSvg}
2620
+ * @param xyRatio Contains an x and/or y property which is a float between 0
2621
+ * and 1 specifying the degree of scrolling.
2701
2622
  */
2702
- static setTopLevelWorkspaceMetrics_(xyRatio) {
2623
+ private static setTopLevelWorkspaceMetrics_(
2624
+ this: WorkspaceSvg, xyRatio: AnyDuringMigration) {
2703
2625
  const metrics = this.getMetrics();
2704
2626
 
2705
2627
  if (typeof xyRatio.x === 'number') {
@@ -2724,12 +2646,10 @@ class WorkspaceSvg extends Workspace {
2724
2646
  /**
2725
2647
  * Size the workspace when the contents change. This also updates
2726
2648
  * scrollbars accordingly.
2727
- * @param {!WorkspaceSvg} workspace The workspace to resize.
2649
+ * @param workspace The workspace to resize.
2728
2650
  * @alias Blockly.WorkspaceSvg.resizeSvgContents
2651
+ * @internal
2729
2652
  */
2730
- const resizeSvgContents = function(workspace) {
2653
+ export function resizeSvgContents(workspace: WorkspaceSvg) {
2731
2654
  workspace.resizeContents();
2732
- };
2733
- exports.resizeSvgContents = resizeSvgContents;
2734
-
2735
- exports.WorkspaceSvg = WorkspaceSvg;
2655
+ }