blockly 9.0.0-beta.0 → 9.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (608) hide show
  1. package/blockly.min.js +401 -405
  2. package/blockly_compressed.js +398 -402
  3. package/blockly_compressed.js.map +1 -1
  4. package/blocks.d.ts +0 -5
  5. package/blocks_compressed.js +3 -3
  6. package/blocks_compressed.js.map +1 -1
  7. package/closure/goog/base.d.ts +1 -0
  8. package/closure/goog/base_minimal.d.ts +1 -0
  9. package/closure/goog/goog.d.ts +1 -0
  10. package/core/any_aliases.d.ts +1 -0
  11. package/core/block.d.ts +145 -53
  12. package/core/block_animations.d.ts +5 -0
  13. package/core/block_drag_surface.d.ts +18 -5
  14. package/core/block_dragger.d.ts +20 -5
  15. package/core/block_svg.d.ts +89 -21
  16. package/core/blockly.d.ts +29 -8
  17. package/core/blockly_options.d.ts +2 -0
  18. package/core/blocks.d.ts +2 -0
  19. package/core/browser_events.d.ts +16 -7
  20. package/core/bubble.d.ts +42 -12
  21. package/core/bubble_dragger.d.ts +9 -2
  22. package/core/bump_objects.d.ts +6 -2
  23. package/core/clipboard.d.ts +6 -2
  24. package/core/comment.d.ts +13 -3
  25. package/core/common.d.ts +35 -9
  26. package/core/component_manager.d.ts +16 -6
  27. package/core/config.d.ts +1 -0
  28. package/core/connection.d.ts +48 -18
  29. package/core/connection_checker.d.ts +16 -7
  30. package/core/connection_db.d.ts +17 -6
  31. package/core/connection_type.d.ts +2 -0
  32. package/core/constants.d.ts +3 -0
  33. package/core/contextmenu.d.ts +15 -5
  34. package/core/contextmenu_items.d.ts +15 -0
  35. package/core/contextmenu_registry.d.ts +12 -7
  36. package/core/css.d.ts +3 -0
  37. package/core/delete_area.d.ts +5 -1
  38. package/core/dialog.d.ts +14 -7
  39. package/core/drag_target.d.ts +10 -2
  40. package/core/dropdowndiv.d.ts +42 -10
  41. package/core/events/events.d.ts +1 -0
  42. package/core/events/events_abstract.d.ts +10 -3
  43. package/core/events/events_block_base.d.ts +5 -1
  44. package/core/events/events_block_change.d.ts +10 -3
  45. package/core/events/events_block_create.d.ts +6 -1
  46. package/core/events/events_block_delete.d.ts +6 -1
  47. package/core/events/events_block_drag.d.ts +5 -1
  48. package/core/events/events_block_move.d.ts +10 -3
  49. package/core/events/events_bubble_open.d.ts +6 -2
  50. package/core/events/events_click.d.ts +5 -1
  51. package/core/events/events_comment_base.d.ts +6 -1
  52. package/core/events/events_comment_change.d.ts +8 -2
  53. package/core/events/events_comment_create.d.ts +6 -1
  54. package/core/events/events_comment_delete.d.ts +6 -1
  55. package/core/events/events_comment_move.d.ts +9 -2
  56. package/core/events/events_marker_move.d.ts +5 -1
  57. package/core/events/events_selected.d.ts +5 -1
  58. package/core/events/events_theme_change.d.ts +5 -1
  59. package/core/events/events_toolbox_item_select.d.ts +5 -1
  60. package/core/events/events_trashcan_open.d.ts +5 -1
  61. package/core/events/events_ui.d.ts +5 -1
  62. package/core/events/events_ui_base.d.ts +2 -0
  63. package/core/events/events_var_base.d.ts +5 -1
  64. package/core/events/events_var_create.d.ts +6 -1
  65. package/core/events/events_var_delete.d.ts +6 -1
  66. package/core/events/events_var_rename.d.ts +6 -1
  67. package/core/events/events_viewport.d.ts +5 -1
  68. package/core/events/utils.d.ts +50 -7
  69. package/core/events/workspace_events.d.ts +5 -1
  70. package/core/extensions.d.ts +14 -4
  71. package/core/field.d.ts +93 -34
  72. package/core/field_angle.d.ts +14 -3
  73. package/core/field_checkbox.d.ts +20 -7
  74. package/core/field_colour.d.ts +22 -6
  75. package/core/field_dropdown.d.ts +28 -8
  76. package/core/field_image.d.ts +15 -4
  77. package/core/field_label.d.ts +8 -2
  78. package/core/field_label_serializable.d.ts +4 -1
  79. package/core/field_multilineinput.d.ts +21 -6
  80. package/core/field_number.d.ts +22 -6
  81. package/core/field_registry.d.ts +8 -2
  82. package/core/field_textinput.d.ts +28 -8
  83. package/core/field_variable.d.ts +36 -13
  84. package/core/flyout_base.d.ts +70 -24
  85. package/core/flyout_button.d.ts +12 -5
  86. package/core/flyout_horizontal.d.ts +14 -6
  87. package/core/flyout_metrics_manager.d.ts +6 -3
  88. package/core/flyout_vertical.d.ts +14 -6
  89. package/core/generator.d.ts +39 -20
  90. package/core/gesture.d.ts +48 -13
  91. package/core/grid.d.ts +19 -15
  92. package/core/icon.d.ts +12 -3
  93. package/core/inject.d.ts +3 -1
  94. package/core/input.d.ts +25 -10
  95. package/core/input_types.d.ts +2 -0
  96. package/core/insertion_marker_manager.d.ts +27 -9
  97. package/core/interfaces/i_ast_node_location.d.ts +2 -0
  98. package/core/interfaces/i_ast_node_location_svg.d.ts +4 -0
  99. package/core/interfaces/i_ast_node_location_with_block.d.ts +4 -1
  100. package/core/interfaces/i_autohideable.d.ts +3 -0
  101. package/core/interfaces/i_block_dragger.d.ts +7 -1
  102. package/core/interfaces/i_bounded_element.d.ts +5 -1
  103. package/core/interfaces/i_bubble.d.ts +11 -2
  104. package/core/interfaces/i_collapsible_toolbox_item.d.ts +6 -2
  105. package/core/interfaces/i_component.d.ts +2 -0
  106. package/core/interfaces/i_connection_checker.d.ts +14 -6
  107. package/core/interfaces/i_contextmenu.d.ts +2 -0
  108. package/core/interfaces/i_copyable.d.ts +3 -1
  109. package/core/interfaces/i_deletable.d.ts +4 -1
  110. package/core/interfaces/i_delete_area.d.ts +4 -1
  111. package/core/interfaces/i_drag_target.d.ts +10 -2
  112. package/core/interfaces/i_draggable.d.ts +2 -0
  113. package/core/interfaces/i_flyout.d.ts +27 -11
  114. package/core/interfaces/i_keyboard_accessible.d.ts +4 -1
  115. package/core/interfaces/i_metrics_manager.d.ts +24 -12
  116. package/core/interfaces/i_movable.d.ts +4 -1
  117. package/core/interfaces/i_positionable.d.ts +5 -1
  118. package/core/interfaces/i_registrable.d.ts +2 -0
  119. package/core/interfaces/i_registrable_field.d.ts +2 -0
  120. package/core/interfaces/i_selectable.d.ts +2 -0
  121. package/core/interfaces/i_selectable_toolbox_item.d.ts +10 -3
  122. package/core/interfaces/i_serializer.d.ts +6 -1
  123. package/core/interfaces/i_styleable.d.ts +4 -0
  124. package/core/interfaces/i_toolbox.d.ts +17 -6
  125. package/core/interfaces/i_toolbox_item.d.ts +17 -7
  126. package/core/internal_constants.d.ts +6 -0
  127. package/core/keyboard_nav/ast_node.d.ts +55 -28
  128. package/core/keyboard_nav/basic_cursor.d.ts +20 -9
  129. package/core/keyboard_nav/cursor.d.ts +11 -5
  130. package/core/keyboard_nav/marker.d.ts +9 -2
  131. package/core/keyboard_nav/tab_navigate_cursor.d.ts +4 -1
  132. package/core/main.d.ts +1 -0
  133. package/core/marker_manager.d.ts +13 -2
  134. package/core/menu.d.ts +23 -5
  135. package/core/menuitem.d.ts +22 -7
  136. package/core/metrics_manager.d.ts +30 -15
  137. package/core/msg.d.ts +1 -0
  138. package/core/mutator.d.ts +19 -7
  139. package/core/names.d.ts +20 -8
  140. package/core/options.d.ts +12 -6
  141. package/core/positionable_helpers.d.ts +11 -3
  142. package/core/procedures.d.ts +27 -10
  143. package/core/registry.d.ts +19 -8
  144. package/core/rendered_connection.d.ts +28 -7
  145. package/core/renderers/common/block_rendering.d.ts +9 -2
  146. package/core/renderers/common/constants.d.ts +49 -17
  147. package/core/renderers/common/debug.d.ts +5 -1
  148. package/core/renderers/common/debugger.d.ts +12 -1
  149. package/core/renderers/common/drawer.d.ts +12 -0
  150. package/core/renderers/common/i_path_object.d.ts +15 -0
  151. package/core/renderers/common/info.d.ts +25 -8
  152. package/core/renderers/common/marker_svg.d.ts +35 -6
  153. package/core/renderers/common/path_object.d.ts +20 -0
  154. package/core/renderers/common/renderer.d.ts +33 -12
  155. package/core/renderers/geras/constants.d.ts +2 -0
  156. package/core/renderers/geras/drawer.d.ts +2 -0
  157. package/core/renderers/geras/geras.d.ts +3 -2
  158. package/core/renderers/geras/highlight_constants.d.ts +9 -6
  159. package/core/renderers/geras/highlighter.d.ts +12 -1
  160. package/core/renderers/geras/info.d.ts +4 -1
  161. package/core/renderers/geras/measurables/inline_input.d.ts +2 -0
  162. package/core/renderers/geras/measurables/statement_input.d.ts +2 -0
  163. package/core/renderers/geras/path_object.d.ts +4 -0
  164. package/core/renderers/geras/renderer.d.ts +16 -6
  165. package/core/renderers/measurables/base.d.ts +2 -0
  166. package/core/renderers/measurables/bottom_row.d.ts +9 -3
  167. package/core/renderers/measurables/connection.d.ts +2 -0
  168. package/core/renderers/measurables/external_value_input.d.ts +2 -1
  169. package/core/renderers/measurables/field.d.ts +2 -1
  170. package/core/renderers/measurables/hat.d.ts +2 -1
  171. package/core/renderers/measurables/icon.d.ts +3 -1
  172. package/core/renderers/measurables/in_row_spacer.d.ts +2 -1
  173. package/core/renderers/measurables/inline_input.d.ts +2 -1
  174. package/core/renderers/measurables/input_connection.d.ts +2 -0
  175. package/core/renderers/measurables/input_row.d.ts +4 -1
  176. package/core/renderers/measurables/jagged_edge.d.ts +2 -1
  177. package/core/renderers/measurables/next_connection.d.ts +2 -1
  178. package/core/renderers/measurables/output_connection.d.ts +2 -1
  179. package/core/renderers/measurables/previous_connection.d.ts +2 -1
  180. package/core/renderers/measurables/round_corner.d.ts +2 -1
  181. package/core/renderers/measurables/row.d.ts +27 -5
  182. package/core/renderers/measurables/spacer_row.d.ts +2 -1
  183. package/core/renderers/measurables/square_corner.d.ts +2 -1
  184. package/core/renderers/measurables/statement_input.d.ts +2 -1
  185. package/core/renderers/measurables/top_row.d.ts +7 -3
  186. package/core/renderers/measurables/types.d.ts +54 -25
  187. package/core/renderers/minimalist/constants.d.ts +2 -0
  188. package/core/renderers/minimalist/drawer.d.ts +2 -0
  189. package/core/renderers/minimalist/info.d.ts +4 -1
  190. package/core/renderers/minimalist/minimalist.d.ts +2 -1
  191. package/core/renderers/minimalist/renderer.d.ts +8 -3
  192. package/core/renderers/thrasos/info.d.ts +4 -1
  193. package/core/renderers/thrasos/renderer.d.ts +4 -1
  194. package/core/renderers/thrasos/thrasos.d.ts +2 -1
  195. package/core/renderers/zelos/constants.d.ts +11 -3
  196. package/core/renderers/zelos/drawer.d.ts +3 -0
  197. package/core/renderers/zelos/info.d.ts +10 -5
  198. package/core/renderers/zelos/marker_svg.d.ts +5 -0
  199. package/core/renderers/zelos/measurables/bottom_row.d.ts +2 -0
  200. package/core/renderers/zelos/measurables/inputs.d.ts +2 -0
  201. package/core/renderers/zelos/measurables/row_elements.d.ts +2 -0
  202. package/core/renderers/zelos/measurables/top_row.d.ts +2 -0
  203. package/core/renderers/zelos/path_object.d.ts +8 -1
  204. package/core/renderers/zelos/renderer.d.ts +14 -6
  205. package/core/renderers/zelos/zelos.d.ts +3 -2
  206. package/core/scrollbar.d.ts +41 -9
  207. package/core/scrollbar_pair.d.ts +20 -6
  208. package/core/serialization/blocks.d.ts +10 -4
  209. package/core/serialization/exceptions.d.ts +5 -0
  210. package/core/serialization/priorities.d.ts +3 -0
  211. package/core/serialization/registry.d.ts +3 -0
  212. package/core/serialization/variables.d.ts +2 -0
  213. package/core/serialization/workspaces.d.ts +4 -1
  214. package/core/shortcut_items.d.ts +10 -0
  215. package/core/shortcut_registry.d.ts +25 -9
  216. package/core/sprites.d.ts +2 -4
  217. package/core/theme/classic.d.ts +2 -0
  218. package/core/theme/themes.d.ts +1 -0
  219. package/core/theme/zelos.d.ts +2 -0
  220. package/core/theme.d.ts +14 -3
  221. package/core/theme_manager.d.ts +10 -1
  222. package/core/toolbox/category.d.ts +42 -15
  223. package/core/toolbox/collapsible_category.d.ts +10 -3
  224. package/core/toolbox/separator.d.ts +4 -1
  225. package/core/toolbox/toolbox.d.ts +70 -22
  226. package/core/toolbox/toolbox_item.d.ts +17 -7
  227. package/core/tooltip.d.ts +22 -1
  228. package/core/touch.d.ts +18 -6
  229. package/core/touch_gesture.d.ts +16 -2
  230. package/core/trashcan.d.ts +27 -6
  231. package/core/utils/aria.d.ts +4 -0
  232. package/core/utils/array.d.ts +4 -2
  233. package/core/utils/colour.d.ts +24 -13
  234. package/core/utils/coordinate.d.ts +18 -8
  235. package/core/utils/deprecation.d.ts +6 -4
  236. package/core/utils/dom.d.ts +32 -12
  237. package/core/utils/idgenerator.d.ts +13 -3
  238. package/core/utils/keycodes.d.ts +1 -0
  239. package/core/utils/math.d.ts +7 -3
  240. package/core/utils/metrics.d.ts +1 -0
  241. package/core/utils/object.d.ts +7 -2
  242. package/core/utils/parsing.d.ts +9 -4
  243. package/core/utils/rect.d.ts +5 -3
  244. package/core/utils/sentinel.d.ts +2 -0
  245. package/core/utils/size.d.ts +4 -2
  246. package/core/utils/string.d.ts +13 -6
  247. package/core/utils/style.d.ts +14 -33
  248. package/core/utils/svg.d.ts +5 -2
  249. package/core/utils/svg_math.d.ts +15 -7
  250. package/core/utils/svg_paths.d.ts +20 -10
  251. package/core/utils/toolbox.d.ts +26 -5
  252. package/core/utils/useragent.d.ts +1 -12
  253. package/core/utils/xml.d.ts +13 -5
  254. package/core/utils.d.ts +43 -21
  255. package/core/variable_map.d.ts +26 -9
  256. package/core/variable_model.d.ts +5 -2
  257. package/core/variables.d.ts +33 -18
  258. package/core/variables_dynamic.d.ts +25 -5
  259. package/core/warning.d.ts +8 -3
  260. package/core/widgetdiv.d.ts +15 -6
  261. package/core/workspace.d.ts +80 -30
  262. package/core/workspace_audio.d.ts +6 -0
  263. package/core/workspace_comment.d.ts +33 -11
  264. package/core/workspace_comment_svg.d.ts +52 -9
  265. package/core/workspace_drag_surface_svg.d.ts +20 -14
  266. package/core/workspace_dragger.d.ts +6 -0
  267. package/core/workspace_svg.d.ts +174 -62
  268. package/core/xml.d.ts +26 -11
  269. package/core/zoom_controls.d.ts +16 -6
  270. package/core.d.ts +0 -5
  271. package/dart.d.ts +0 -5
  272. package/dart_compressed.js.map +1 -1
  273. package/index.d.ts +2 -6
  274. package/javascript.d.ts +0 -5
  275. package/javascript_compressed.js.map +1 -1
  276. package/lua.d.ts +0 -5
  277. package/lua_compressed.js.map +1 -1
  278. package/package.json +6 -3
  279. package/php.d.ts +0 -5
  280. package/php_compressed.js.map +1 -1
  281. package/python.d.ts +0 -5
  282. package/python_compressed.js.map +1 -1
  283. package/blocks/blocks.js +0 -48
  284. package/blocks/colour.js +0 -121
  285. package/blocks/lists.js +0 -996
  286. package/blocks/logic.js +0 -665
  287. package/blocks/loops.js +0 -375
  288. package/blocks/math.js +0 -594
  289. package/blocks/procedures.js +0 -1196
  290. package/blocks/text.js +0 -1000
  291. package/blocks/variables.js +0 -176
  292. package/blocks/variables_dynamic.js +0 -192
  293. package/core/any_aliases.ts +0 -1
  294. package/core/block.ts +0 -2102
  295. package/core/block_animations.ts +0 -202
  296. package/core/block_drag_surface.ts +0 -237
  297. package/core/block_dragger.ts +0 -447
  298. package/core/block_svg.ts +0 -1758
  299. package/core/blockly.js +0 -890
  300. package/core/blockly.ts +0 -749
  301. package/core/blockly_options.ts +0 -81
  302. package/core/blocks.ts +0 -29
  303. package/core/browser_events.ts +0 -289
  304. package/core/bubble.ts +0 -892
  305. package/core/bubble_dragger.ts +0 -229
  306. package/core/bump_objects.ts +0 -182
  307. package/core/clipboard.ts +0 -91
  308. package/core/comment.ts +0 -398
  309. package/core/common.ts +0 -288
  310. package/core/component_manager.ts +0 -211
  311. package/core/config.ts +0 -80
  312. package/core/connection.ts +0 -692
  313. package/core/connection_checker.ts +0 -301
  314. package/core/connection_db.ts +0 -289
  315. package/core/connection_type.ts +0 -32
  316. package/core/constants.ts +0 -29
  317. package/core/contextmenu.ts +0 -363
  318. package/core/contextmenu_items.ts +0 -576
  319. package/core/contextmenu_registry.ts +0 -179
  320. package/core/css.ts +0 -560
  321. package/core/delete_area.ts +0 -82
  322. package/core/dialog.ts +0 -127
  323. package/core/drag_target.ts +0 -94
  324. package/core/dropdowndiv.ts +0 -683
  325. package/core/events/events.ts +0 -123
  326. package/core/events/events_abstract.ts +0 -112
  327. package/core/events/events_block_base.ts +0 -65
  328. package/core/events/events_block_change.ts +0 -176
  329. package/core/events/events_block_create.ts +0 -114
  330. package/core/events/events_block_delete.ts +0 -126
  331. package/core/events/events_block_drag.ts +0 -82
  332. package/core/events/events_block_move.ts +0 -206
  333. package/core/events/events_bubble_open.ts +0 -82
  334. package/core/events/events_click.ts +0 -84
  335. package/core/events/events_comment_base.ts +0 -107
  336. package/core/events/events_comment_change.ts +0 -108
  337. package/core/events/events_comment_create.ts +0 -82
  338. package/core/events/events_comment_delete.ts +0 -77
  339. package/core/events/events_comment_move.ts +0 -154
  340. package/core/events/events_marker_move.ts +0 -99
  341. package/core/events/events_selected.ts +0 -78
  342. package/core/events/events_theme_change.ts +0 -67
  343. package/core/events/events_toolbox_item_select.ts +0 -79
  344. package/core/events/events_trashcan_open.ts +0 -68
  345. package/core/events/events_ui.ts +0 -89
  346. package/core/events/events_ui_base.ts +0 -54
  347. package/core/events/events_var_base.ts +0 -65
  348. package/core/events/events_var_create.ts +0 -88
  349. package/core/events/events_var_delete.ts +0 -88
  350. package/core/events/events_var_rename.ts +0 -89
  351. package/core/events/events_viewport.ts +0 -100
  352. package/core/events/utils.ts +0 -529
  353. package/core/events/workspace_events.ts +0 -86
  354. package/core/extensions.ts +0 -504
  355. package/core/field.ts +0 -1206
  356. package/core/field_angle.ts +0 -563
  357. package/core/field_checkbox.ts +0 -243
  358. package/core/field_colour.ts +0 -632
  359. package/core/field_dropdown.ts +0 -773
  360. package/core/field_image.ts +0 -282
  361. package/core/field_label.ts +0 -152
  362. package/core/field_label_serializable.ts +0 -76
  363. package/core/field_multilineinput.ts +0 -466
  364. package/core/field_number.ts +0 -327
  365. package/core/field_registry.ts +0 -87
  366. package/core/field_textinput.ts +0 -591
  367. package/core/field_variable.ts +0 -545
  368. package/core/flyout_base.ts +0 -1165
  369. package/core/flyout_button.ts +0 -292
  370. package/core/flyout_horizontal.ts +0 -381
  371. package/core/flyout_metrics_manager.ts +0 -94
  372. package/core/flyout_vertical.ts +0 -384
  373. package/core/generator.ts +0 -539
  374. package/core/gesture.ts +0 -946
  375. package/core/grid.ts +0 -192
  376. package/core/icon.ts +0 -189
  377. package/core/inject.ts +0 -390
  378. package/core/input.ts +0 -309
  379. package/core/input_types.ts +0 -32
  380. package/core/insertion_marker_manager.ts +0 -788
  381. package/core/interfaces/i_ast_node_location.ts +0 -23
  382. package/core/interfaces/i_ast_node_location_svg.ts +0 -37
  383. package/core/interfaces/i_ast_node_location_with_block.ts +0 -38
  384. package/core/interfaces/i_autohideable.ts +0 -34
  385. package/core/interfaces/i_block_dragger.ts +0 -67
  386. package/core/interfaces/i_bounded_element.ts +0 -42
  387. package/core/interfaces/i_bubble.ts +0 -88
  388. package/core/interfaces/i_collapsible_toolbox_item.ts +0 -47
  389. package/core/interfaces/i_component.ts +0 -32
  390. package/core/interfaces/i_connection_checker.ts +0 -102
  391. package/core/interfaces/i_contextmenu.ts +0 -26
  392. package/core/interfaces/i_copyable.ts +0 -40
  393. package/core/interfaces/i_deletable.ts +0 -29
  394. package/core/interfaces/i_delete_area.ts +0 -46
  395. package/core/interfaces/i_drag_target.ts +0 -84
  396. package/core/interfaces/i_draggable.ts +0 -25
  397. package/core/interfaces/i_flyout.ts +0 -186
  398. package/core/interfaces/i_keyboard_accessible.ts +0 -35
  399. package/core/interfaces/i_metrics_manager.ts +0 -151
  400. package/core/interfaces/i_movable.ts +0 -29
  401. package/core/interfaces/i_positionable.ts +0 -50
  402. package/core/interfaces/i_registrable.ts +0 -25
  403. package/core/interfaces/i_registrable_field.ts +0 -31
  404. package/core/interfaces/i_selectable.ts +0 -34
  405. package/core/interfaces/i_selectable_toolbox_item.ts +0 -64
  406. package/core/interfaces/i_serializer.ts +0 -65
  407. package/core/interfaces/i_styleable.ts +0 -35
  408. package/core/interfaces/i_toolbox.ts +0 -127
  409. package/core/interfaces/i_toolbox_item.ts +0 -84
  410. package/core/internal_constants.ts +0 -67
  411. package/core/keyboard_nav/ast_node.ts +0 -717
  412. package/core/keyboard_nav/basic_cursor.ts +0 -214
  413. package/core/keyboard_nav/cursor.ts +0 -134
  414. package/core/keyboard_nav/marker.ts +0 -115
  415. package/core/keyboard_nav/tab_navigate_cursor.ts +0 -48
  416. package/core/main.js +0 -303
  417. package/core/marker_manager.ts +0 -181
  418. package/core/menu.ts +0 -449
  419. package/core/menuitem.ts +0 -240
  420. package/core/metrics_manager.ts +0 -456
  421. package/core/msg.ts +0 -20
  422. package/core/mutator.ts +0 -560
  423. package/core/names.ts +0 -267
  424. package/core/options.ts +0 -365
  425. package/core/positionable_helpers.ts +0 -181
  426. package/core/procedures.ts +0 -443
  427. package/core/registry.ts +0 -339
  428. package/core/rendered_connection.ts +0 -568
  429. package/core/renderers/common/block_rendering.ts +0 -164
  430. package/core/renderers/common/constants.ts +0 -1124
  431. package/core/renderers/common/debug.ts +0 -61
  432. package/core/renderers/common/debugger.ts +0 -433
  433. package/core/renderers/common/drawer.ts +0 -450
  434. package/core/renderers/common/i_path_object.ts +0 -161
  435. package/core/renderers/common/info.ts +0 -718
  436. package/core/renderers/common/marker_svg.ts +0 -680
  437. package/core/renderers/common/path_object.ts +0 -272
  438. package/core/renderers/common/renderer.ts +0 -271
  439. package/core/renderers/geras/constants.ts +0 -61
  440. package/core/renderers/geras/drawer.ts +0 -176
  441. package/core/renderers/geras/geras.ts +0 -37
  442. package/core/renderers/geras/highlight_constants.ts +0 -337
  443. package/core/renderers/geras/highlighter.ts +0 -306
  444. package/core/renderers/geras/info.ts +0 -450
  445. package/core/renderers/geras/measurables/inline_input.ts +0 -51
  446. package/core/renderers/geras/measurables/statement_input.ts +0 -50
  447. package/core/renderers/geras/path_object.ts +0 -138
  448. package/core/renderers/geras/renderer.ts +0 -126
  449. package/core/renderers/measurables/base.ts +0 -53
  450. package/core/renderers/measurables/bottom_row.ts +0 -120
  451. package/core/renderers/measurables/connection.ts +0 -52
  452. package/core/renderers/measurables/external_value_input.ts +0 -65
  453. package/core/renderers/measurables/field.ts +0 -63
  454. package/core/renderers/measurables/hat.ts +0 -48
  455. package/core/renderers/measurables/icon.ts +0 -54
  456. package/core/renderers/measurables/in_row_spacer.ts +0 -44
  457. package/core/renderers/measurables/inline_input.ts +0 -76
  458. package/core/renderers/measurables/input_connection.ts +0 -66
  459. package/core/renderers/measurables/input_row.ts +0 -82
  460. package/core/renderers/measurables/jagged_edge.ts +0 -43
  461. package/core/renderers/measurables/next_connection.ts +0 -47
  462. package/core/renderers/measurables/output_connection.ts +0 -56
  463. package/core/renderers/measurables/previous_connection.ts +0 -47
  464. package/core/renderers/measurables/round_corner.ts +0 -49
  465. package/core/renderers/measurables/row.ts +0 -225
  466. package/core/renderers/measurables/spacer_row.ts +0 -55
  467. package/core/renderers/measurables/square_corner.ts +0 -47
  468. package/core/renderers/measurables/statement_input.ts +0 -55
  469. package/core/renderers/measurables/top_row.ts +0 -122
  470. package/core/renderers/measurables/types.ts +0 -332
  471. package/core/renderers/minimalist/constants.ts +0 -32
  472. package/core/renderers/minimalist/drawer.ts +0 -38
  473. package/core/renderers/minimalist/info.ts +0 -52
  474. package/core/renderers/minimalist/minimalist.ts +0 -22
  475. package/core/renderers/minimalist/renderer.ts +0 -71
  476. package/core/renderers/thrasos/info.ts +0 -338
  477. package/core/renderers/thrasos/renderer.ts +0 -48
  478. package/core/renderers/thrasos/thrasos.ts +0 -20
  479. package/core/renderers/zelos/constants.ts +0 -858
  480. package/core/renderers/zelos/drawer.ts +0 -228
  481. package/core/renderers/zelos/info.ts +0 -593
  482. package/core/renderers/zelos/marker_svg.ts +0 -151
  483. package/core/renderers/zelos/measurables/bottom_row.ts +0 -53
  484. package/core/renderers/zelos/measurables/inputs.ts +0 -56
  485. package/core/renderers/zelos/measurables/row_elements.ts +0 -45
  486. package/core/renderers/zelos/measurables/top_row.ts +0 -58
  487. package/core/renderers/zelos/path_object.ts +0 -215
  488. package/core/renderers/zelos/renderer.ts +0 -142
  489. package/core/renderers/zelos/zelos.ts +0 -39
  490. package/core/scrollbar.ts +0 -870
  491. package/core/scrollbar_pair.ts +0 -321
  492. package/core/serialization/blocks.ts +0 -706
  493. package/core/serialization/exceptions.ts +0 -98
  494. package/core/serialization/priorities.ts +0 -32
  495. package/core/serialization/registry.ts +0 -43
  496. package/core/serialization/variables.ts +0 -96
  497. package/core/serialization/workspaces.ts +0 -106
  498. package/core/shortcut_items.ts +0 -266
  499. package/core/shortcut_registry.ts +0 -355
  500. package/core/sprites.ts +0 -29
  501. package/core/theme/classic.ts +0 -54
  502. package/core/theme/themes.ts +0 -22
  503. package/core/theme/zelos.ts +0 -91
  504. package/core/theme.ts +0 -221
  505. package/core/theme_manager.ts +0 -186
  506. package/core/toolbox/category.ts +0 -679
  507. package/core/toolbox/collapsible_category.ts +0 -273
  508. package/core/toolbox/separator.ts +0 -105
  509. package/core/toolbox/toolbox.ts +0 -1044
  510. package/core/toolbox/toolbox_item.ts +0 -147
  511. package/core/tooltip.ts +0 -463
  512. package/core/touch.ts +0 -306
  513. package/core/touch_gesture.ts +0 -295
  514. package/core/trashcan.ts +0 -671
  515. package/core/utils/aria.ts +0 -160
  516. package/core/utils/array.ts +0 -32
  517. package/core/utils/colour.ts +0 -276
  518. package/core/utils/coordinate.ts +0 -124
  519. package/core/utils/deprecation.ts +0 -41
  520. package/core/utils/dom.ts +0 -408
  521. package/core/utils/idgenerator.ts +0 -80
  522. package/core/utils/keycodes.ts +0 -169
  523. package/core/utils/math.ts +0 -61
  524. package/core/utils/metrics.ts +0 -97
  525. package/core/utils/object.ts +0 -95
  526. package/core/utils/parsing.ts +0 -261
  527. package/core/utils/rect.ts +0 -62
  528. package/core/utils/sentinel.ts +0 -23
  529. package/core/utils/size.ts +0 -51
  530. package/core/utils/string.ts +0 -308
  531. package/core/utils/style.ts +0 -306
  532. package/core/utils/svg.ts +0 -88
  533. package/core/utils/svg_math.ts +0 -269
  534. package/core/utils/svg_paths.ts +0 -140
  535. package/core/utils/toolbox.ts +0 -433
  536. package/core/utils/useragent.ts +0 -135
  537. package/core/utils/xml.ts +0 -97
  538. package/core/utils.ts +0 -428
  539. package/core/variable_map.ts +0 -392
  540. package/core/variable_model.ts +0 -82
  541. package/core/variables.ts +0 -596
  542. package/core/variables_dynamic.ts +0 -133
  543. package/core/warning.ts +0 -161
  544. package/core/widgetdiv.ts +0 -257
  545. package/core/workspace.ts +0 -801
  546. package/core/workspace_audio.ts +0 -156
  547. package/core/workspace_comment.ts +0 -398
  548. package/core/workspace_comment_svg.ts +0 -1127
  549. package/core/workspace_drag_surface_svg.ts +0 -187
  550. package/core/workspace_dragger.ts +0 -104
  551. package/core/workspace_svg.ts +0 -2655
  552. package/core/xml.ts +0 -1023
  553. package/core/zoom_controls.ts +0 -441
  554. package/generators/dart/all.js +0 -27
  555. package/generators/dart/colour.js +0 -105
  556. package/generators/dart/lists.js +0 -431
  557. package/generators/dart/logic.js +0 -123
  558. package/generators/dart/loops.js +0 -161
  559. package/generators/dart/math.js +0 -446
  560. package/generators/dart/procedures.js +0 -105
  561. package/generators/dart/text.js +0 -338
  562. package/generators/dart/variables.js +0 -32
  563. package/generators/dart/variables_dynamic.js +0 -21
  564. package/generators/dart.js +0 -303
  565. package/generators/javascript/all.js +0 -27
  566. package/generators/javascript/colour.js +0 -85
  567. package/generators/javascript/lists.js +0 -405
  568. package/generators/javascript/logic.js +0 -127
  569. package/generators/javascript/loops.js +0 -180
  570. package/generators/javascript/math.js +0 -401
  571. package/generators/javascript/procedures.js +0 -110
  572. package/generators/javascript/text.js +0 -371
  573. package/generators/javascript/variables.js +0 -32
  574. package/generators/javascript/variables_dynamic.js +0 -21
  575. package/generators/javascript.js +0 -322
  576. package/generators/lua/all.js +0 -27
  577. package/generators/lua/colour.js +0 -71
  578. package/generators/lua/lists.js +0 -348
  579. package/generators/lua/logic.js +0 -112
  580. package/generators/lua/loops.js +0 -168
  581. package/generators/lua/math.js +0 -406
  582. package/generators/lua/procedures.js +0 -106
  583. package/generators/lua/text.js +0 -327
  584. package/generators/lua/variables.js +0 -31
  585. package/generators/lua/variables_dynamic.js +0 -21
  586. package/generators/lua.js +0 -206
  587. package/generators/php/all.js +0 -27
  588. package/generators/php/colour.js +0 -81
  589. package/generators/php/lists.js +0 -481
  590. package/generators/php/logic.js +0 -119
  591. package/generators/php/loops.js +0 -161
  592. package/generators/php/math.js +0 -349
  593. package/generators/php/procedures.js +0 -125
  594. package/generators/php/text.js +0 -255
  595. package/generators/php/variables.js +0 -32
  596. package/generators/php/variables_dynamic.js +0 -21
  597. package/generators/php.js +0 -303
  598. package/generators/python/all.js +0 -27
  599. package/generators/python/colour.js +0 -67
  600. package/generators/python/lists.js +0 -346
  601. package/generators/python/logic.js +0 -120
  602. package/generators/python/loops.js +0 -206
  603. package/generators/python/math.js +0 -373
  604. package/generators/python/procedures.js +0 -129
  605. package/generators/python/text.js +0 -291
  606. package/generators/python/variables.js +0 -32
  607. package/generators/python/variables_dynamic.js +0 -21
  608. package/generators/python.js +0 -333
package/core/block_svg.ts DELETED
@@ -1,1758 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2012 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- /**
8
- * @fileoverview Methods for graphically rendering a block as SVG.
9
- */
10
-
11
- /**
12
- * Methods for graphically rendering a block as SVG.
13
- * @class
14
- */
15
- import * as goog from '../closure/goog/goog.js';
16
- goog.declareModuleId('Blockly.BlockSvg');
17
-
18
- /* eslint-disable-next-line no-unused-vars */
19
- // Unused import preserved for side-effects. Remove if unneeded.
20
- // import './theme.js';
21
- // Unused import preserved for side-effects. Remove if unneeded.
22
- import './events/events_selected.js';
23
- // Unused import preserved for side-effects. Remove if unneeded.
24
- // import './touch.js';
25
-
26
- import {Block} from './block.js';
27
- import * as blockAnimations from './block_animations.js';
28
- import * as browserEvents from './browser_events.js';
29
- import {Comment} from './comment.js';
30
- import * as common from './common.js';
31
- import {config} from './config.js';
32
- import type {Connection} from './connection.js';
33
- import {ConnectionType} from './connection_type.js';
34
- import * as constants from './constants.js';
35
- import * as ContextMenu from './contextmenu.js';
36
- import {ContextMenuOption, ContextMenuRegistry, LegacyContextMenuOption} from './contextmenu_registry.js';
37
- import type {BlockMove} from './events/events_block_move.js';
38
- import * as eventUtils from './events/utils.js';
39
- import type {Field} from './field.js';
40
- import {FieldLabel} from './field_label.js';
41
- import type {Icon} from './icon.js';
42
- import type {Input} from './input.js';
43
- import type {IASTNodeLocationSvg} from './interfaces/i_ast_node_location_svg.js';
44
- import type {IBoundedElement} from './interfaces/i_bounded_element.js';
45
- import type {CopyData, ICopyable} from './interfaces/i_copyable.js';
46
- import type {IDraggable} from './interfaces/i_draggable.js';
47
- import * as internalConstants from './internal_constants.js';
48
- import {ASTNode} from './keyboard_nav/ast_node.js';
49
- import {TabNavigateCursor} from './keyboard_nav/tab_navigate_cursor.js';
50
- import {MarkerManager} from './marker_manager.js';
51
- import {Msg} from './msg.js';
52
- import type {Mutator} from './mutator.js';
53
- import {RenderedConnection} from './rendered_connection.js';
54
- import type {Debug as BlockRenderingDebug} from './renderers/common/debugger.js';
55
- import type {IPathObject} from './renderers/common/i_path_object.js';
56
- import * as blocks from './serialization/blocks.js';
57
- import type {BlockStyle} from './theme.js';
58
- import * as Tooltip from './tooltip.js';
59
- import {Coordinate} from './utils/coordinate.js';
60
- import * as dom from './utils/dom.js';
61
- import {Rect} from './utils/rect.js';
62
- import {Svg} from './utils/svg.js';
63
- import * as svgMath from './utils/svg_math.js';
64
- import {Warning} from './warning.js';
65
- import type {Workspace} from './workspace.js';
66
- import type {WorkspaceSvg} from './workspace_svg.js';
67
-
68
-
69
- /**
70
- * Class for a block's SVG representation.
71
- * Not normally called directly, workspace.newBlock() is preferred.
72
- * @alias Blockly.BlockSvg
73
- */
74
- export class BlockSvg extends Block implements IASTNodeLocationSvg,
75
- IBoundedElement, ICopyable,
76
- IDraggable {
77
- /**
78
- * Constant for identifying rows that are to be rendered inline.
79
- * Don't collide with Blockly.inputTypes.
80
- */
81
- static readonly INLINE = -1;
82
-
83
- /**
84
- * ID to give the "collapsed warnings" warning. Allows us to remove the
85
- * "collapsed warnings" warning without removing any warnings that belong to
86
- * the block.
87
- */
88
- static readonly COLLAPSED_WARNING_ID = 'TEMP_COLLAPSED_WARNING_';
89
- override decompose?: ((p1: Workspace) => BlockSvg);
90
- // override compose?: ((p1: BlockSvg) => void)|null;
91
- saveConnections?: ((p1: BlockSvg) => AnyDuringMigration);
92
- customContextMenu?:
93
- ((p1: Array<ContextMenuOption|LegacyContextMenuOption>) =>
94
- AnyDuringMigration)|null;
95
-
96
- /**
97
- * An property used internally to reference the block's rendering debugger.
98
- * @internal
99
- */
100
- renderingDebugger: BlockRenderingDebug|null = null;
101
-
102
- /**
103
- * Height of this block, not including any statement blocks above or below.
104
- * Height is in workspace units.
105
- */
106
- height = 0;
107
-
108
- /**
109
- * Width of this block, including any connected value blocks.
110
- * Width is in workspace units.
111
- */
112
- width = 0;
113
-
114
- /**
115
- * Map from IDs for warnings text to PIDs of functions to apply them.
116
- * Used to be able to maintain multiple warnings.
117
- */
118
- private warningTextDb = new Map<string, ReturnType<typeof setTimeout>>();
119
-
120
- /** Block's mutator icon (if any). */
121
- mutator: Mutator|null = null;
122
-
123
- /** Block's comment icon (if any). */
124
- private commentIcon_: Comment|null = null;
125
-
126
- /** Block's warning icon (if any). */
127
- warning: Warning|null = null;
128
-
129
- private svgGroup_: SVGGElement;
130
- style: BlockStyle;
131
- /** @internal */
132
- pathObject: IPathObject;
133
- override rendered = false;
134
-
135
- /**
136
- * Is this block currently rendering? Used to stop recursive render calls
137
- * from actually triggering a re-render.
138
- */
139
- private renderIsInProgress_ = false;
140
-
141
- /** Whether mousedown events have been bound yet. */
142
- private eventsInit_ = false;
143
-
144
- override workspace: WorkspaceSvg;
145
- // TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
146
- override outputConnection!: RenderedConnection;
147
- // TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
148
- override nextConnection!: RenderedConnection;
149
- // TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
150
- override previousConnection!: RenderedConnection;
151
- private readonly useDragSurface_: boolean;
152
-
153
- /**
154
- * @param workspace The block's workspace.
155
- * @param prototypeName Name of the language object containing type-specific
156
- * functions for this block.
157
- * @param opt_id Optional ID. Use this ID if provided, otherwise create a new
158
- * ID.
159
- */
160
- constructor(workspace: WorkspaceSvg, prototypeName: string, opt_id?: string) {
161
- super(workspace, prototypeName, opt_id);
162
- this.workspace = workspace;
163
-
164
- /**
165
- * An optional method called when a mutator dialog is first opened.
166
- * This function must create and initialize a top-level block for the
167
- * mutator dialog, and return it. This function should also populate this
168
- * top-level block with any sub-blocks which are appropriate. This method
169
- * must also be coupled with defining a `compose` method for the default
170
- * mutation dialog button and UI to appear.
171
- */
172
- this.decompose = this.decompose;
173
-
174
- /**
175
- * An optional method called when a mutator dialog saves its content.
176
- * This function is called to modify the original block according to new
177
- * settings. This method must also be coupled with defining a `decompose`
178
- * method for the default mutation dialog button and UI to appear.
179
- */
180
- this.compose = this.compose;
181
-
182
- /**
183
- * An optional method called by the default mutator UI which gives the block
184
- * a chance to save information about what child blocks are connected to
185
- * what mutated connections.
186
- */
187
- this.saveConnections = this.saveConnections;
188
-
189
- /** An optional method for defining custom block context menu items. */
190
- this.customContextMenu = this.customContextMenu;
191
- this.svgGroup_ = dom.createSvgElement(Svg.G, {});
192
- (this.svgGroup_ as AnyDuringMigration).translate_ = '';
193
-
194
- /** A block style object. */
195
- this.style = workspace.getRenderer().getConstants().getBlockStyle(null);
196
-
197
- /** The renderer's path object. */
198
- this.pathObject =
199
- workspace.getRenderer().makePathObject(this.svgGroup_, this.style);
200
-
201
- /**
202
- * Whether to move the block to the drag surface when it is dragged.
203
- * True if it should move, false if it should be translated directly.
204
- */
205
- this.useDragSurface_ =
206
- svgMath.is3dSupported() && !!workspace.getBlockDragSurface();
207
-
208
- const svgPath = this.pathObject.svgPath;
209
- (svgPath as AnyDuringMigration).tooltip = this;
210
- Tooltip.bindMouseEvents(svgPath);
211
-
212
- // Expose this block's ID on its top-level SVG group.
213
- this.svgGroup_.setAttribute('data-id', this.id);
214
-
215
- this.doInit_();
216
- }
217
-
218
- /**
219
- * Create and initialize the SVG representation of the block.
220
- * May be called more than once.
221
- */
222
- initSvg() {
223
- if (!this.workspace.rendered) {
224
- throw TypeError('Workspace is headless.');
225
- }
226
- for (let i = 0, input; input = this.inputList[i]; i++) {
227
- input.init();
228
- }
229
- const icons = this.getIcons();
230
- for (let i = 0; i < icons.length; i++) {
231
- icons[i].createIcon();
232
- }
233
- this.applyColour();
234
- this.pathObject.updateMovable(this.isMovable());
235
- const svg = this.getSvgRoot();
236
- if (!this.workspace.options.readOnly && !this.eventsInit_ && svg) {
237
- browserEvents.conditionalBind(svg, 'mousedown', this, this.onMouseDown_);
238
- }
239
- this.eventsInit_ = true;
240
-
241
- if (!svg.parentNode) {
242
- this.workspace.getCanvas().appendChild(svg);
243
- }
244
- }
245
-
246
- /**
247
- * Get the secondary colour of a block.
248
- * @return #RRGGBB string.
249
- */
250
- getColourSecondary(): string|null {
251
- return this.style.colourSecondary;
252
- }
253
-
254
- /**
255
- * Get the tertiary colour of a block.
256
- * @return #RRGGBB string.
257
- */
258
- getColourTertiary(): string|null {
259
- return this.style.colourTertiary;
260
- }
261
-
262
- /**
263
- * Selects this block. Highlights the block visually and fires a select event
264
- * if the block is not already selected.
265
- */
266
- select() {
267
- if (this.isShadow() && this.getParent()) {
268
- // Shadow blocks should not be selected.
269
- this.getParent()!.select();
270
- return;
271
- }
272
- if (common.getSelected() === this) {
273
- return;
274
- }
275
- let oldId = null;
276
- if (common.getSelected()) {
277
- oldId = common.getSelected()!.id;
278
- // Unselect any previously selected block.
279
- eventUtils.disable();
280
- try {
281
- common.getSelected()!.unselect();
282
- } finally {
283
- eventUtils.enable();
284
- }
285
- }
286
- const event = new (eventUtils.get(eventUtils.SELECTED))!
287
- (oldId, this.id, this.workspace.id);
288
- eventUtils.fire(event);
289
- common.setSelected(this);
290
- this.addSelect();
291
- }
292
-
293
- /**
294
- * Unselects this block. Unhighlights the block and fires a select (false)
295
- * event if the block is currently selected.
296
- */
297
- unselect() {
298
- if (common.getSelected() !== this) {
299
- return;
300
- }
301
- const event = new (eventUtils.get(eventUtils.SELECTED))!
302
- (this.id, null, this.workspace.id);
303
- event.workspaceId = this.workspace.id;
304
- eventUtils.fire(event);
305
- common.setSelected(null);
306
- this.removeSelect();
307
- }
308
-
309
- /**
310
- * Returns a list of mutator, comment, and warning icons.
311
- * @return List of icons.
312
- */
313
- getIcons(): Icon[] {
314
- const icons = [];
315
- if (this.mutator) {
316
- icons.push(this.mutator);
317
- }
318
- if (this.commentIcon_) {
319
- icons.push(this.commentIcon_);
320
- }
321
- if (this.warning) {
322
- icons.push(this.warning);
323
- }
324
- return icons;
325
- }
326
-
327
- /**
328
- * Sets the parent of this block to be a new block or null.
329
- * @param newParent New parent block.
330
- * @internal
331
- */
332
- override setParent(newParent: this|null) {
333
- const oldParent = this.parentBlock_;
334
- if (newParent === oldParent) {
335
- return;
336
- }
337
-
338
- dom.startTextWidthCache();
339
- // AnyDuringMigration because: Argument of type 'Block | null' is not
340
- // assignable to parameter of type 'Block'.
341
- super.setParent(newParent as AnyDuringMigration);
342
- dom.stopTextWidthCache();
343
-
344
- const svgRoot = this.getSvgRoot();
345
-
346
- // Bail early if workspace is clearing, or we aren't rendered.
347
- // We won't need to reattach ourselves anywhere.
348
- if (this.workspace.isClearing || !svgRoot) {
349
- return;
350
- }
351
-
352
- const oldXY = this.getRelativeToSurfaceXY();
353
- if (newParent) {
354
- (newParent as BlockSvg).getSvgRoot().appendChild(svgRoot);
355
- const newXY = this.getRelativeToSurfaceXY();
356
- // Move the connections to match the child's new position.
357
- this.moveConnections(newXY.x - oldXY.x, newXY.y - oldXY.y);
358
- } else if (oldParent) {
359
- // If we are losing a parent, we want to move our DOM element to the
360
- // root of the workspace.
361
- this.workspace.getCanvas().appendChild(svgRoot);
362
- this.translate(oldXY.x, oldXY.y);
363
- }
364
-
365
- this.applyColour();
366
- }
367
-
368
- /**
369
- * Return the coordinates of the top-left corner of this block relative to the
370
- * drawing surface's origin (0,0), in workspace units.
371
- * If the block is on the workspace, (0, 0) is the origin of the workspace
372
- * coordinate system.
373
- * This does not change with workspace scale.
374
- * @return Object with .x and .y properties in workspace coordinates.
375
- */
376
- override getRelativeToSurfaceXY(): Coordinate {
377
- let x = 0;
378
- let y = 0;
379
-
380
- const dragSurfaceGroup = this.useDragSurface_ ?
381
- this.workspace.getBlockDragSurface()!.getGroup() :
382
- null;
383
-
384
- let element: SVGElement = this.getSvgRoot();
385
- if (element) {
386
- do {
387
- // Loop through this block and every parent.
388
- const xy = svgMath.getRelativeXY(element);
389
- x += xy.x;
390
- y += xy.y;
391
- // If this element is the current element on the drag surface, include
392
- // the translation of the drag surface itself.
393
- if (this.useDragSurface_ &&
394
- this.workspace.getBlockDragSurface()!.getCurrentBlock() ===
395
- element) {
396
- const surfaceTranslation =
397
- this.workspace.getBlockDragSurface()!.getSurfaceTranslation();
398
- x += surfaceTranslation.x;
399
- y += surfaceTranslation.y;
400
- }
401
- element = element.parentNode as SVGElement;
402
- } while (element && element !== this.workspace.getCanvas() &&
403
- element !== dragSurfaceGroup);
404
- }
405
- return new Coordinate(x, y);
406
- }
407
-
408
- /**
409
- * Move a block by a relative offset.
410
- * @param dx Horizontal offset in workspace units.
411
- * @param dy Vertical offset in workspace units.
412
- */
413
- override moveBy(dx: number, dy: number) {
414
- if (this.parentBlock_) {
415
- throw Error('Block has parent.');
416
- }
417
- const eventsEnabled = eventUtils.isEnabled();
418
- let event: BlockMove|null = null;
419
- if (eventsEnabled) {
420
- event = new (eventUtils.get(eventUtils.BLOCK_MOVE))!(this) as BlockMove;
421
- }
422
- const xy = this.getRelativeToSurfaceXY();
423
- this.translate(xy.x + dx, xy.y + dy);
424
- this.moveConnections(dx, dy);
425
- if (eventsEnabled && event) {
426
- event!.recordNew();
427
- eventUtils.fire(event);
428
- }
429
- this.workspace.resizeContents();
430
- }
431
-
432
- /**
433
- * Transforms a block by setting the translation on the transform attribute
434
- * of the block's SVG.
435
- * @param x The x coordinate of the translation in workspace units.
436
- * @param y The y coordinate of the translation in workspace units.
437
- */
438
- translate(x: number, y: number) {
439
- this.getSvgRoot().setAttribute(
440
- 'transform', 'translate(' + x + ',' + y + ')');
441
- }
442
-
443
- /**
444
- * Move this block to its workspace's drag surface, accounting for
445
- * positioning. Generally should be called at the same time as
446
- * setDragging_(true). Does nothing if useDragSurface_ is false.
447
- * @internal
448
- */
449
- moveToDragSurface() {
450
- if (!this.useDragSurface_) {
451
- return;
452
- }
453
- // The translation for drag surface blocks,
454
- // is equal to the current relative-to-surface position,
455
- // to keep the position in sync as it move on/off the surface.
456
- // This is in workspace coordinates.
457
- const xy = this.getRelativeToSurfaceXY();
458
- this.clearTransformAttributes_();
459
- this.workspace.getBlockDragSurface()!.translateSurface(xy.x, xy.y);
460
- // Execute the move on the top-level SVG component
461
- const svg = this.getSvgRoot();
462
- if (svg) {
463
- this.workspace.getBlockDragSurface()!.setBlocksAndShow(svg);
464
- }
465
- }
466
-
467
- /**
468
- * Move a block to a position.
469
- * @param xy The position to move to in workspace units.
470
- */
471
- moveTo(xy: Coordinate) {
472
- const curXY = this.getRelativeToSurfaceXY();
473
- this.moveBy(xy.x - curXY.x, xy.y - curXY.y);
474
- }
475
-
476
- /**
477
- * Move this block back to the workspace block canvas.
478
- * Generally should be called at the same time as setDragging_(false).
479
- * Does nothing if useDragSurface_ is false.
480
- * @param newXY The position the block should take on on the workspace canvas,
481
- * in workspace coordinates.
482
- * @internal
483
- */
484
- moveOffDragSurface(newXY: Coordinate) {
485
- if (!this.useDragSurface_) {
486
- return;
487
- }
488
- // Translate to current position, turning off 3d.
489
- this.translate(newXY.x, newXY.y);
490
- this.workspace.getBlockDragSurface()!.clearAndHide(
491
- this.workspace.getCanvas());
492
- }
493
-
494
- /**
495
- * Move this block during a drag, taking into account whether we are using a
496
- * drag surface to translate blocks.
497
- * This block must be a top-level block.
498
- * @param newLoc The location to translate to, in workspace coordinates.
499
- * @internal
500
- */
501
- moveDuringDrag(newLoc: Coordinate) {
502
- if (this.useDragSurface_) {
503
- this.workspace.getBlockDragSurface()!.translateSurface(
504
- newLoc.x, newLoc.y);
505
- } else {
506
- (this.svgGroup_ as AnyDuringMigration).translate_ =
507
- 'translate(' + newLoc.x + ',' + newLoc.y + ')';
508
- (this.svgGroup_ as AnyDuringMigration)
509
- .setAttribute(
510
- 'transform',
511
- (this.svgGroup_ as AnyDuringMigration).translate_ +
512
- (this.svgGroup_ as AnyDuringMigration).skew_);
513
- }
514
- }
515
-
516
- /**
517
- * Clear the block of transform="..." attributes.
518
- * Used when the block is switching from 3d to 2d transform or vice versa.
519
- */
520
- private clearTransformAttributes_() {
521
- this.getSvgRoot().removeAttribute('transform');
522
- }
523
-
524
- /** Snap this block to the nearest grid point. */
525
- snapToGrid() {
526
- if (this.disposed) {
527
- return; // Deleted block.
528
- }
529
- if (this.workspace.isDragging()) {
530
- return // Don't bump blocks during a drag.;
531
- }
532
-
533
- if (this.getParent()) {
534
- return; // Only snap top-level blocks.
535
- }
536
- if (this.isInFlyout) {
537
- return; // Don't move blocks around in a flyout.
538
- }
539
- const grid = this.workspace.getGrid();
540
- if (!grid || !grid.shouldSnap()) {
541
- return; // Config says no snapping.
542
- }
543
- const spacing = grid.getSpacing();
544
- const half = spacing / 2;
545
- const xy = this.getRelativeToSurfaceXY();
546
- const dx =
547
- Math.round(Math.round((xy.x - half) / spacing) * spacing + half - xy.x);
548
- const dy =
549
- Math.round(Math.round((xy.y - half) / spacing) * spacing + half - xy.y);
550
- if (dx || dy) {
551
- this.moveBy(dx, dy);
552
- }
553
- }
554
-
555
- /**
556
- * Returns the coordinates of a bounding box describing the dimensions of this
557
- * block and any blocks stacked below it.
558
- * Coordinate system: workspace coordinates.
559
- * @return Object with coordinates of the bounding box.
560
- */
561
- getBoundingRectangle(): Rect {
562
- const blockXY = this.getRelativeToSurfaceXY();
563
- const blockBounds = this.getHeightWidth();
564
- let left;
565
- let right;
566
- if (this.RTL) {
567
- left = blockXY.x - blockBounds.width;
568
- right = blockXY.x;
569
- } else {
570
- left = blockXY.x;
571
- right = blockXY.x + blockBounds.width;
572
- }
573
- return new Rect(blockXY.y, blockXY.y + blockBounds.height, left, right);
574
- }
575
-
576
- /**
577
- * Notify every input on this block to mark its fields as dirty.
578
- * A dirty field is a field that needs to be re-rendered.
579
- */
580
- markDirty() {
581
- this.pathObject.constants = this.workspace.getRenderer().getConstants();
582
- for (let i = 0, input; input = this.inputList[i]; i++) {
583
- input.markDirty();
584
- }
585
- }
586
-
587
- /**
588
- * Set whether the block is collapsed or not.
589
- * @param collapsed True if collapsed.
590
- */
591
- override setCollapsed(collapsed: boolean) {
592
- if (this.collapsed_ === collapsed) {
593
- return;
594
- }
595
- super.setCollapsed(collapsed);
596
- if (!collapsed) {
597
- this.updateCollapsed_();
598
- } else if (this.rendered) {
599
- this.render();
600
- // Don't bump neighbours. Users like to store collapsed functions together
601
- // and bumping makes them go out of alignment.
602
- }
603
- }
604
-
605
- /**
606
- * Makes sure that when the block is collapsed, it is rendered correctly
607
- * for that state.
608
- */
609
- private updateCollapsed_() {
610
- const collapsed = this.isCollapsed();
611
- const collapsedInputName = constants.COLLAPSED_INPUT_NAME;
612
- const collapsedFieldName = constants.COLLAPSED_FIELD_NAME;
613
-
614
- for (let i = 0, input; input = this.inputList[i]; i++) {
615
- if (input.name !== collapsedInputName) {
616
- input.setVisible(!collapsed);
617
- }
618
- }
619
-
620
- if (!collapsed) {
621
- this.updateDisabled();
622
- this.removeInput(collapsedInputName);
623
- return;
624
- }
625
-
626
- const icons = this.getIcons();
627
- for (let i = 0, icon; icon = icons[i]; i++) {
628
- icon.setVisible(false);
629
- }
630
-
631
- const text = this.toString(internalConstants.COLLAPSE_CHARS);
632
- const field = this.getField(collapsedFieldName);
633
- if (field) {
634
- field.setValue(text);
635
- return;
636
- }
637
- const input = this.getInput(collapsedInputName) ||
638
- this.appendDummyInput(collapsedInputName);
639
- // AnyDuringMigration because: Argument of type 'FieldLabel' is not
640
- // assignable to parameter of type 'string | Field'.
641
- input.appendField(
642
- new FieldLabel(text) as AnyDuringMigration, collapsedFieldName);
643
- }
644
-
645
- /**
646
- * Open the next (or previous) FieldTextInput.
647
- * @param start Current field.
648
- * @param forward If true go forward, otherwise backward.
649
- */
650
- tab(start: Field, forward: boolean) {
651
- const tabCursor = new TabNavigateCursor();
652
- tabCursor.setCurNode(ASTNode.createFieldNode(start)!);
653
- const currentNode = tabCursor.getCurNode();
654
-
655
- if (forward) {
656
- tabCursor.next();
657
- } else {
658
- tabCursor.prev();
659
- }
660
-
661
- const nextNode = tabCursor.getCurNode();
662
- if (nextNode && nextNode !== currentNode) {
663
- const nextField = nextNode.getLocation() as Field;
664
- nextField.showEditor();
665
-
666
- // Also move the cursor if we're in keyboard nav mode.
667
- if (this.workspace.keyboardAccessibilityMode) {
668
- this.workspace.getCursor()!.setCurNode(nextNode);
669
- }
670
- }
671
- }
672
-
673
- /**
674
- * Handle a mouse-down on an SVG block.
675
- * @param e Mouse down event or touch start event.
676
- */
677
- private onMouseDown_(e: Event) {
678
- const gesture = this.workspace.getGesture(e);
679
- if (gesture) {
680
- gesture.handleBlockStart(e, this);
681
- }
682
- }
683
-
684
- /**
685
- * Load the block's help page in a new window.
686
- * @internal
687
- */
688
- showHelp() {
689
- const url =
690
- typeof this.helpUrl === 'function' ? this.helpUrl() : this.helpUrl;
691
- if (url) {
692
- window.open(url);
693
- }
694
- }
695
-
696
- /**
697
- * Generate the context menu for this block.
698
- * @return Context menu options or null if no menu.
699
- */
700
- protected generateContextMenu():
701
- Array<ContextMenuOption|LegacyContextMenuOption>|null {
702
- if (this.workspace.options.readOnly || !this.contextMenu) {
703
- return null;
704
- }
705
- // AnyDuringMigration because: Argument of type '{ block: this; }' is not
706
- // assignable to parameter of type 'Scope'.
707
- const menuOptions = ContextMenuRegistry.registry.getContextMenuOptions(
708
- ContextMenuRegistry.ScopeType.BLOCK,
709
- {block: this} as AnyDuringMigration);
710
-
711
- // Allow the block to add or modify menuOptions.
712
- if (this.customContextMenu) {
713
- this.customContextMenu(menuOptions);
714
- }
715
-
716
- return menuOptions;
717
- }
718
-
719
- /**
720
- * Show the context menu for this block.
721
- * @param e Mouse event.
722
- * @internal
723
- */
724
- showContextMenu(e: Event) {
725
- const menuOptions = this.generateContextMenu();
726
-
727
- if (menuOptions && menuOptions.length) {
728
- ContextMenu.show(e, menuOptions, this.RTL);
729
- // AnyDuringMigration because: Argument of type 'this' is not assignable
730
- // to parameter of type 'Block | null'.
731
- ContextMenu.setCurrentBlock(this as AnyDuringMigration);
732
- }
733
- }
734
-
735
- /**
736
- * Move the connections for this block and all blocks attached under it.
737
- * Also update any attached bubbles.
738
- * @param dx Horizontal offset from current location, in workspace units.
739
- * @param dy Vertical offset from current location, in workspace units.
740
- * @internal
741
- */
742
- moveConnections(dx: number, dy: number) {
743
- if (!this.rendered) {
744
- // Rendering is required to lay out the blocks.
745
- // This is probably an invisible block attached to a collapsed block.
746
- return;
747
- }
748
- const myConnections = this.getConnections_(false);
749
- for (let i = 0; i < myConnections.length; i++) {
750
- myConnections[i].moveBy(dx, dy);
751
- }
752
- const icons = this.getIcons();
753
- for (let i = 0; i < icons.length; i++) {
754
- icons[i].computeIconLocation();
755
- }
756
-
757
- // Recurse through all blocks attached under this one.
758
- for (let i = 0; i < this.childBlocks_.length; i++) {
759
- (this.childBlocks_[i] as BlockSvg).moveConnections(dx, dy);
760
- }
761
- }
762
-
763
- /**
764
- * Recursively adds or removes the dragging class to this node and its
765
- * children.
766
- * @param adding True if adding, false if removing.
767
- * @internal
768
- */
769
- setDragging(adding: boolean) {
770
- if (adding) {
771
- const group = this.getSvgRoot();
772
- (group as AnyDuringMigration).translate_ = '';
773
- (group as AnyDuringMigration).skew_ = '';
774
- common.draggingConnections.push(...this.getConnections_(true));
775
- dom.addClass(this.svgGroup_ as Element, 'blocklyDragging');
776
- } else {
777
- common.draggingConnections.length = 0;
778
- dom.removeClass(this.svgGroup_ as Element, 'blocklyDragging');
779
- }
780
- // Recurse through all blocks attached under this one.
781
- for (let i = 0; i < this.childBlocks_.length; i++) {
782
- (this.childBlocks_[i] as BlockSvg).setDragging(adding);
783
- }
784
- }
785
-
786
- /**
787
- * Set whether this block is movable or not.
788
- * @param movable True if movable.
789
- */
790
- override setMovable(movable: boolean) {
791
- super.setMovable(movable);
792
- this.pathObject.updateMovable(movable);
793
- }
794
-
795
- /**
796
- * Set whether this block is editable or not.
797
- * @param editable True if editable.
798
- */
799
- override setEditable(editable: boolean) {
800
- super.setEditable(editable);
801
- const icons = this.getIcons();
802
- for (let i = 0; i < icons.length; i++) {
803
- icons[i].updateEditable();
804
- }
805
- }
806
-
807
- /**
808
- * Sets whether this block is a shadow block or not.
809
- * @param shadow True if a shadow.
810
- * @internal
811
- */
812
- override setShadow(shadow: boolean) {
813
- super.setShadow(shadow);
814
- this.applyColour();
815
- }
816
-
817
- /**
818
- * Set whether this block is an insertion marker block or not.
819
- * Once set this cannot be unset.
820
- * @param insertionMarker True if an insertion marker.
821
- * @internal
822
- */
823
- override setInsertionMarker(insertionMarker: boolean) {
824
- if (this.isInsertionMarker_ === insertionMarker) {
825
- return; // No change.
826
- }
827
- this.isInsertionMarker_ = insertionMarker;
828
- if (this.isInsertionMarker_) {
829
- this.setColour(
830
- this.workspace.getRenderer().getConstants().INSERTION_MARKER_COLOUR);
831
- this.pathObject.updateInsertionMarker(true);
832
- }
833
- }
834
-
835
- /**
836
- * Return the root node of the SVG or null if none exists.
837
- * @return The root SVG node (probably a group).
838
- */
839
- getSvgRoot(): SVGGElement {
840
- return this.svgGroup_;
841
- }
842
-
843
- /**
844
- * Dispose of this block.
845
- * @param healStack If true, then try to heal any gap by connecting the next
846
- * statement with the previous statement. Otherwise, dispose of all
847
- * children of this block.
848
- * @param animate If true, show a disposal animation and sound.
849
- * @suppress {checkTypes}
850
- */
851
- override dispose(healStack?: boolean, animate?: boolean) {
852
- if (this.disposed) {
853
- // The block has already been deleted.
854
- return;
855
- }
856
- Tooltip.dispose();
857
- Tooltip.unbindMouseEvents(this.pathObject.svgPath);
858
- dom.startTextWidthCache();
859
- // Save the block's workspace temporarily so we can resize the
860
- // contents once the block is disposed.
861
- const blockWorkspace = this.workspace;
862
- // If this block is being dragged, unlink the mouse events.
863
- if (common.getSelected() === this) {
864
- this.unselect();
865
- this.workspace.cancelCurrentGesture();
866
- }
867
- // If this block has a context menu open, close it.
868
- if (ContextMenu.getCurrentBlock() === this) {
869
- ContextMenu.hide();
870
- }
871
-
872
- if (animate && this.rendered) {
873
- this.unplug(healStack);
874
- blockAnimations.disposeUiEffect(this);
875
- }
876
- // Stop rerendering.
877
- this.rendered = false;
878
-
879
- // Clear pending warnings.
880
- for (const n of this.warningTextDb.values()) {
881
- clearTimeout(n);
882
- }
883
- this.warningTextDb.clear();
884
-
885
- const icons = this.getIcons();
886
- for (let i = 0; i < icons.length; i++) {
887
- icons[i].dispose();
888
- }
889
-
890
- // Just deleting this block from the DOM would result in a memory leak as
891
- // well as corruption of the connection database. Therefore we must
892
- // methodically step through the blocks and carefully disassemble them.
893
- if (common.getSelected() === this) {
894
- common.setSelected(null);
895
- }
896
-
897
- super.dispose(!!healStack);
898
-
899
- dom.removeNode(this.svgGroup_);
900
- blockWorkspace.resizeContents();
901
- // Sever JavaScript to DOM connections.
902
- // AnyDuringMigration because: Type 'null' is not assignable to type
903
- // 'SVGGElement'.
904
- this.svgGroup_ = null as AnyDuringMigration;
905
- dom.stopTextWidthCache();
906
- }
907
-
908
- /**
909
- * Delete a block and hide chaff when doing so. The block will not be deleted
910
- * if it's in a flyout. This is called from the context menu and keyboard
911
- * shortcuts as the full delete action. If you are disposing of a block from
912
- * the workspace and don't need to perform flyout checks, handle event
913
- * grouping, or hide chaff, then use `block.dispose()` directly.
914
- */
915
- checkAndDelete() {
916
- if (this.workspace.isFlyout) {
917
- return;
918
- }
919
- eventUtils.setGroup(true);
920
- this.workspace.hideChaff();
921
- if (this.outputConnection) {
922
- // Do not attempt to heal rows
923
- // (https://github.com/google/blockly/issues/4832)
924
- this.dispose(false, true);
925
- } else {
926
- this.dispose(/* heal */
927
- true, true);
928
- }
929
- eventUtils.setGroup(false);
930
- }
931
-
932
- /**
933
- * Encode a block for copying.
934
- * @return Copy metadata, or null if the block is an insertion marker.
935
- * @internal
936
- */
937
- toCopyData(): CopyData|null {
938
- if (this.isInsertionMarker_) {
939
- return null;
940
- }
941
- // AnyDuringMigration because: Argument of type 'this' is not assignable to
942
- // parameter of type 'Block'. AnyDuringMigration because: Argument of type
943
- // 'this' is not assignable to parameter of type 'Block'.
944
- return {
945
- saveInfo: blocks.save(
946
- this as AnyDuringMigration,
947
- {addCoordinates: true, addNextBlocks: false}) as
948
- blocks.State,
949
- source: this.workspace,
950
- typeCounts: common.getBlockTypeCounts(this as AnyDuringMigration, true),
951
- };
952
- }
953
-
954
- /**
955
- * Updates the colour of the block to match the block's state.
956
- * @internal
957
- */
958
- applyColour() {
959
- this.pathObject.applyColour(this);
960
-
961
- const icons = this.getIcons();
962
- for (let i = 0; i < icons.length; i++) {
963
- icons[i].applyColour();
964
- }
965
-
966
- for (let x = 0, input; input = this.inputList[x]; x++) {
967
- for (let y = 0, field; field = input.fieldRow[y]; y++) {
968
- field.applyColour();
969
- }
970
- }
971
- }
972
-
973
- /**
974
- * Updates the color of the block (and children) to match the current disabled
975
- * state.
976
- * @internal
977
- */
978
- updateDisabled() {
979
- const children = (this.getChildren(false));
980
- this.applyColour();
981
- if (this.isCollapsed()) {
982
- return;
983
- }
984
- for (let i = 0, child; child = children[i]; i++) {
985
- if (child.rendered) {
986
- child.updateDisabled();
987
- }
988
- }
989
- }
990
-
991
- /**
992
- * Get the comment icon attached to this block, or null if the block has no
993
- * comment.
994
- * @return The comment icon attached to this block, or null.
995
- */
996
- getCommentIcon(): Comment|null {
997
- return this.commentIcon_;
998
- }
999
-
1000
- /**
1001
- * Set this block's comment text.
1002
- * @param text The text, or null to delete.
1003
- */
1004
- override setCommentText(text: string|null) {
1005
- // AnyDuringMigration because: Property 'get' does not exist on type
1006
- // '(name: string) => void'.
1007
- if (this.commentModel.text === text) {
1008
- return;
1009
- }
1010
- super.setCommentText(text);
1011
-
1012
- const shouldHaveComment = text !== null;
1013
- if (!!this.commentIcon_ === shouldHaveComment) {
1014
- // If the comment's state of existence is correct, but the text is new
1015
- // that means we're just updating a comment.
1016
- this.commentIcon_!.updateText();
1017
- return;
1018
- }
1019
- if (shouldHaveComment) {
1020
- this.commentIcon_ = new Comment(this);
1021
- this.comment = this.commentIcon_; // For backwards compatibility.
1022
- } else {
1023
- this.commentIcon_!.dispose();
1024
- this.commentIcon_ = null;
1025
- this.comment = null; // For backwards compatibility.
1026
- }
1027
- if (this.rendered) {
1028
- this.render();
1029
- // Adding or removing a comment icon will cause the block to change shape.
1030
- this.bumpNeighbours();
1031
- }
1032
- }
1033
-
1034
- /**
1035
- * Set this block's warning text.
1036
- * @param text The text, or null to delete.
1037
- * @param opt_id An optional ID for the warning text to be able to maintain
1038
- * multiple warnings.
1039
- */
1040
- override setWarningText(text: string|null, opt_id?: string) {
1041
- const id = opt_id || '';
1042
- if (!id) {
1043
- // Kill all previous pending processes, this edit supersedes them all.
1044
- for (const timeout of this.warningTextDb.values()) {
1045
- clearTimeout(timeout);
1046
- }
1047
- this.warningTextDb.clear();
1048
- } else if (this.warningTextDb.has(id)) {
1049
- // Only queue up the latest change. Kill any earlier pending process.
1050
- clearTimeout(this.warningTextDb.get(id)!);
1051
- this.warningTextDb.delete(id);
1052
- }
1053
- if (this.workspace.isDragging()) {
1054
- // Don't change the warning text during a drag.
1055
- // Wait until the drag finishes.
1056
- const thisBlock = this;
1057
- this.warningTextDb.set(
1058
- id, setTimeout(() => {
1059
- if (!this.disposed) { // Check block wasn't deleted.
1060
- this.warningTextDb.delete(id);
1061
- this.setWarningText(text, id);
1062
- }
1063
- }, 100));
1064
- return;
1065
- }
1066
- if (this.isInFlyout) {
1067
- text = null;
1068
- }
1069
-
1070
- let changedState = false;
1071
- if (typeof text === 'string') {
1072
- // Bubble up to add a warning on top-most collapsed block.
1073
- let parent = this.getSurroundParent();
1074
- let collapsedParent = null;
1075
- while (parent) {
1076
- if (parent.isCollapsed()) {
1077
- collapsedParent = parent;
1078
- }
1079
- parent = parent.getSurroundParent();
1080
- }
1081
- if (collapsedParent) {
1082
- collapsedParent.setWarningText(
1083
- Msg['COLLAPSED_WARNINGS_WARNING'], BlockSvg.COLLAPSED_WARNING_ID);
1084
- }
1085
-
1086
- if (!this.warning) {
1087
- this.warning = new Warning(this);
1088
- changedState = true;
1089
- }
1090
- this.warning!.setText((text), id);
1091
- } else {
1092
- // Dispose all warnings if no ID is given.
1093
- if (this.warning && !id) {
1094
- this.warning.dispose();
1095
- changedState = true;
1096
- } else if (this.warning) {
1097
- const oldText = this.warning.getText();
1098
- this.warning.setText('', id);
1099
- const newText = this.warning.getText();
1100
- if (!newText) {
1101
- this.warning.dispose();
1102
- }
1103
- changedState = oldText !== newText;
1104
- }
1105
- }
1106
- if (changedState && this.rendered) {
1107
- this.render();
1108
- // Adding or removing a warning icon will cause the block to change shape.
1109
- this.bumpNeighbours();
1110
- }
1111
- }
1112
-
1113
- /**
1114
- * Give this block a mutator dialog.
1115
- * @param mutator A mutator dialog instance or null to remove.
1116
- */
1117
- override setMutator(mutator: Mutator|null) {
1118
- if (this.mutator && this.mutator !== mutator) {
1119
- this.mutator.dispose();
1120
- }
1121
- if (mutator) {
1122
- mutator.setBlock(this);
1123
- this.mutator = mutator;
1124
- mutator.createIcon();
1125
- }
1126
- if (this.rendered) {
1127
- this.render();
1128
- // Adding or removing a mutator icon will cause the block to change shape.
1129
- this.bumpNeighbours();
1130
- }
1131
- }
1132
-
1133
- /**
1134
- * Set whether the block is enabled or not.
1135
- * @param enabled True if enabled.
1136
- */
1137
- override setEnabled(enabled: boolean) {
1138
- if (this.isEnabled() !== enabled) {
1139
- super.setEnabled(enabled);
1140
- if (this.rendered && !this.getInheritedDisabled()) {
1141
- this.updateDisabled();
1142
- }
1143
- }
1144
- }
1145
-
1146
- /**
1147
- * Set whether the block is highlighted or not. Block highlighting is
1148
- * often used to visually mark blocks currently being executed.
1149
- * @param highlighted True if highlighted.
1150
- */
1151
- setHighlighted(highlighted: boolean) {
1152
- if (!this.rendered) {
1153
- return;
1154
- }
1155
- this.pathObject.updateHighlighted(highlighted);
1156
- }
1157
-
1158
- /**
1159
- * Adds the visual "select" effect to the block, but does not actually select
1160
- * it or fire an event.
1161
- * @see BlockSvg#select
1162
- */
1163
- addSelect() {
1164
- this.pathObject.updateSelected(true);
1165
- }
1166
-
1167
- /**
1168
- * Removes the visual "select" effect from the block, but does not actually
1169
- * unselect it or fire an event.
1170
- * @see BlockSvg#unselect
1171
- */
1172
- removeSelect() {
1173
- this.pathObject.updateSelected(false);
1174
- }
1175
-
1176
- /**
1177
- * Update the cursor over this block by adding or removing a class.
1178
- * @param enable True if the delete cursor should be shown, false otherwise.
1179
- * @internal
1180
- */
1181
- setDeleteStyle(enable: boolean) {
1182
- this.pathObject.updateDraggingDelete(enable);
1183
- }
1184
-
1185
- // Overrides of functions on Blockly.Block that take into account whether the
1186
-
1187
- // block has been rendered.
1188
-
1189
- /**
1190
- * Get the colour of a block.
1191
- * @return #RRGGBB string.
1192
- */
1193
- override getColour(): string {
1194
- return this.style.colourPrimary;
1195
- }
1196
-
1197
- /**
1198
- * Change the colour of a block.
1199
- * @param colour HSV hue value, or #RRGGBB string.
1200
- */
1201
- override setColour(colour: number|string) {
1202
- super.setColour(colour);
1203
- const styleObj =
1204
- this.workspace.getRenderer().getConstants().getBlockStyleForColour(
1205
- this.colour_);
1206
-
1207
- this.pathObject.setStyle(styleObj.style);
1208
- this.style = styleObj.style;
1209
- this.styleName_ = styleObj.name;
1210
-
1211
- this.applyColour();
1212
- }
1213
-
1214
- /**
1215
- * Set the style and colour values of a block.
1216
- * @param blockStyleName Name of the block style.
1217
- * @throws {Error} if the block style does not exist.
1218
- */
1219
- override setStyle(blockStyleName: string) {
1220
- const blockStyle =
1221
- this.workspace.getRenderer().getConstants().getBlockStyle(
1222
- blockStyleName);
1223
- this.styleName_ = blockStyleName;
1224
-
1225
- if (blockStyle) {
1226
- this.hat = blockStyle.hat;
1227
- this.pathObject.setStyle(blockStyle);
1228
- // Set colour to match Block.
1229
- this.colour_ = blockStyle.colourPrimary;
1230
- this.style = blockStyle;
1231
-
1232
- this.applyColour();
1233
- } else {
1234
- throw Error('Invalid style name: ' + blockStyleName);
1235
- }
1236
- }
1237
-
1238
- /**
1239
- * Move this block to the front of the visible workspace.
1240
- * <g> tags do not respect z-index so SVG renders them in the
1241
- * order that they are in the DOM. By placing this block first within the
1242
- * block group's <g>, it will render on top of any other blocks.
1243
- * @internal
1244
- */
1245
- bringToFront() {
1246
- let block = this;
1247
- do {
1248
- const root = block.getSvgRoot();
1249
- const parent = root.parentNode;
1250
- const childNodes = parent!.childNodes;
1251
- // Avoid moving the block if it's already at the bottom.
1252
- if (childNodes[childNodes.length - 1] !== root) {
1253
- parent!.appendChild(root);
1254
- }
1255
- // AnyDuringMigration because: Type 'BlockSvg | null' is not assignable
1256
- // to type 'this'.
1257
- block = block.getParent() as AnyDuringMigration;
1258
- } while (block);
1259
- }
1260
-
1261
- /**
1262
- * Set whether this block can chain onto the bottom of another block.
1263
- * @param newBoolean True if there can be a previous statement.
1264
- * @param opt_check Statement type or list of statement types. Null/undefined
1265
- * if any type could be connected.
1266
- */
1267
- override setPreviousStatement(
1268
- newBoolean: boolean, opt_check?: string|string[]|null) {
1269
- super.setPreviousStatement(newBoolean, opt_check);
1270
-
1271
- if (this.rendered) {
1272
- this.render();
1273
- this.bumpNeighbours();
1274
- }
1275
- }
1276
-
1277
- /**
1278
- * Set whether another block can chain onto the bottom of this block.
1279
- * @param newBoolean True if there can be a next statement.
1280
- * @param opt_check Statement type or list of statement types. Null/undefined
1281
- * if any type could be connected.
1282
- */
1283
- override setNextStatement(
1284
- newBoolean: boolean, opt_check?: string|string[]|null) {
1285
- super.setNextStatement(newBoolean, opt_check);
1286
-
1287
- if (this.rendered) {
1288
- this.render();
1289
- this.bumpNeighbours();
1290
- }
1291
- }
1292
-
1293
- /**
1294
- * Set whether this block returns a value.
1295
- * @param newBoolean True if there is an output.
1296
- * @param opt_check Returned type or list of returned types. Null or
1297
- * undefined if any type could be returned (e.g. variable get).
1298
- */
1299
- override setOutput(newBoolean: boolean, opt_check?: string|string[]|null) {
1300
- super.setOutput(newBoolean, opt_check);
1301
-
1302
- if (this.rendered) {
1303
- this.render();
1304
- this.bumpNeighbours();
1305
- }
1306
- }
1307
-
1308
- /**
1309
- * Set whether value inputs are arranged horizontally or vertically.
1310
- * @param newBoolean True if inputs are horizontal.
1311
- */
1312
- override setInputsInline(newBoolean: boolean) {
1313
- super.setInputsInline(newBoolean);
1314
-
1315
- if (this.rendered) {
1316
- this.render();
1317
- this.bumpNeighbours();
1318
- }
1319
- }
1320
-
1321
- /**
1322
- * Remove an input from this block.
1323
- * @param name The name of the input.
1324
- * @param opt_quiet True to prevent error if input is not present.
1325
- * @return True if operation succeeds, false if input is not present and
1326
- * opt_quiet is true
1327
- * @throws {Error} if the input is not present and opt_quiet is not true.
1328
- */
1329
- override removeInput(name: string, opt_quiet?: boolean): boolean {
1330
- const removed = super.removeInput(name, opt_quiet);
1331
-
1332
- if (this.rendered) {
1333
- this.render();
1334
- // Removing an input will cause the block to change shape.
1335
- this.bumpNeighbours();
1336
- }
1337
-
1338
- return removed;
1339
- }
1340
-
1341
- /**
1342
- * Move a numbered input to a different location on this block.
1343
- * @param inputIndex Index of the input to move.
1344
- * @param refIndex Index of input that should be after the moved input.
1345
- */
1346
- override moveNumberedInputBefore(inputIndex: number, refIndex: number) {
1347
- super.moveNumberedInputBefore(inputIndex, refIndex);
1348
-
1349
- if (this.rendered) {
1350
- this.render();
1351
- // Moving an input will cause the block to change shape.
1352
- this.bumpNeighbours();
1353
- }
1354
- }
1355
-
1356
- /**
1357
- * Add a value input, statement input or local variable to this block.
1358
- * @param type One of Blockly.inputTypes.
1359
- * @param name Language-neutral identifier which may used to find this input
1360
- * again. Should be unique to this block.
1361
- * @return The input object created.
1362
- */
1363
- protected override appendInput_(type: number, name: string): Input {
1364
- const input = super.appendInput_(type, name);
1365
-
1366
- if (this.rendered) {
1367
- this.render();
1368
- // Adding an input will cause the block to change shape.
1369
- this.bumpNeighbours();
1370
- }
1371
- return input;
1372
- }
1373
-
1374
- /**
1375
- * Sets whether this block's connections are tracked in the database or not.
1376
- *
1377
- * Used by the deserializer to be more efficient. Setting a connection's
1378
- * tracked_ value to false keeps it from adding itself to the db when it
1379
- * gets its first moveTo call, saving expensive ops for later.
1380
- * @param track If true, start tracking. If false, stop tracking.
1381
- * @internal
1382
- */
1383
- setConnectionTracking(track: boolean) {
1384
- if (this.previousConnection) {
1385
- (this.previousConnection).setTracking(track);
1386
- }
1387
- if (this.outputConnection) {
1388
- (this.outputConnection).setTracking(track);
1389
- }
1390
- if (this.nextConnection) {
1391
- (this.nextConnection).setTracking(track);
1392
- const child = (this.nextConnection).targetBlock();
1393
- if (child) {
1394
- child.setConnectionTracking(track);
1395
- }
1396
- }
1397
-
1398
- if (this.collapsed_) {
1399
- // When track is true, we don't want to start tracking collapsed
1400
- // connections. When track is false, we're already not tracking
1401
- // collapsed connections, so no need to update.
1402
- return;
1403
- }
1404
-
1405
- for (let i = 0; i < this.inputList.length; i++) {
1406
- const conn = this.inputList[i].connection as RenderedConnection;
1407
- if (conn) {
1408
- conn.setTracking(track);
1409
-
1410
- // Pass tracking on down the chain.
1411
- const block = conn.targetBlock();
1412
- if (block) {
1413
- block.setConnectionTracking(track);
1414
- }
1415
- }
1416
- }
1417
- }
1418
-
1419
- /**
1420
- * Returns connections originating from this block.
1421
- * @param all If true, return all connections even hidden ones.
1422
- * Otherwise, for a non-rendered block return an empty list, and for a
1423
- * collapsed block don't return inputs connections.
1424
- * @return Array of connections.
1425
- * @internal
1426
- */
1427
- override getConnections_(all: boolean): RenderedConnection[] {
1428
- const myConnections = [];
1429
- if (all || this.rendered) {
1430
- if (this.outputConnection) {
1431
- myConnections.push(this.outputConnection);
1432
- }
1433
- if (this.previousConnection) {
1434
- myConnections.push(this.previousConnection);
1435
- }
1436
- if (this.nextConnection) {
1437
- myConnections.push(this.nextConnection);
1438
- }
1439
- if (all || !this.collapsed_) {
1440
- for (let i = 0, input; input = this.inputList[i]; i++) {
1441
- if (input.connection) {
1442
- myConnections.push(input.connection as RenderedConnection);
1443
- }
1444
- }
1445
- }
1446
- }
1447
- return myConnections;
1448
- }
1449
-
1450
- /**
1451
- * Walks down a stack of blocks and finds the last next connection on the
1452
- * stack.
1453
- * @param ignoreShadows If true,the last connection on a non-shadow block will
1454
- * be returned. If false, this will follow shadows to find the last
1455
- * connection.
1456
- * @return The last next connection on the stack, or null.
1457
- * @internal
1458
- */
1459
- override lastConnectionInStack(ignoreShadows: boolean): RenderedConnection
1460
- |null {
1461
- return super.lastConnectionInStack(ignoreShadows) as RenderedConnection;
1462
- }
1463
-
1464
- /**
1465
- * Find the connection on this block that corresponds to the given connection
1466
- * on the other block.
1467
- * Used to match connections between a block and its insertion marker.
1468
- * @param otherBlock The other block to match against.
1469
- * @param conn The other connection to match.
1470
- * @return The matching connection on this block, or null.
1471
- * @internal
1472
- */
1473
- override getMatchingConnection(otherBlock: Block, conn: Connection):
1474
- RenderedConnection|null {
1475
- return super.getMatchingConnection(otherBlock, conn) as RenderedConnection;
1476
- }
1477
-
1478
- /**
1479
- * Create a connection of the specified type.
1480
- * @param type The type of the connection to create.
1481
- * @return A new connection of the specified type.
1482
- */
1483
- protected override makeConnection_(type: number): RenderedConnection {
1484
- return new RenderedConnection(this, type);
1485
- }
1486
-
1487
- /**
1488
- * Return the next statement block directly connected to this block.
1489
- * @return The next statement block or null.
1490
- */
1491
- override getNextBlock(): BlockSvg|null {
1492
- return super.getNextBlock() as BlockSvg;
1493
- }
1494
-
1495
- /**
1496
- * Returns the block connected to the previous connection.
1497
- * @return The previous statement block or null.
1498
- */
1499
- override getPreviousBlock(): BlockSvg|null {
1500
- return super.getPreviousBlock() as BlockSvg;
1501
- }
1502
-
1503
- /**
1504
- * Bump unconnected blocks out of alignment. Two blocks which aren't actually
1505
- * connected should not coincidentally line up on screen.
1506
- */
1507
- override bumpNeighbours() {
1508
- if (this.disposed) {
1509
- return; // Deleted block.
1510
- }
1511
- if (this.workspace.isDragging()) {
1512
- return; // Don't bump blocks during a drag.
1513
- }
1514
- const rootBlock = this.getRootBlock();
1515
- if (rootBlock.isInFlyout) {
1516
- return;
1517
- }
1518
- // Don't move blocks around in a flyout.
1519
- // Loop through every connection on this block.
1520
- const myConnections = this.getConnections_(false);
1521
- for (let i = 0, connection; connection = myConnections[i]; i++) {
1522
- const renderedConn = (connection);
1523
- // Spider down from this block bumping all sub-blocks.
1524
- if (renderedConn.isConnected() && renderedConn.isSuperior()) {
1525
- renderedConn.targetBlock()!.bumpNeighbours();
1526
- }
1527
-
1528
- const neighbours = connection.neighbours(config.snapRadius);
1529
- for (let j = 0, otherConnection; otherConnection = neighbours[j]; j++) {
1530
- const renderedOther = otherConnection as RenderedConnection;
1531
- // If both connections are connected, that's probably fine. But if
1532
- // either one of them is unconnected, then there could be confusion.
1533
- if (!renderedConn.isConnected() || !renderedOther.isConnected()) {
1534
- // Only bump blocks if they are from different tree structures.
1535
- if (renderedOther.getSourceBlock().getRootBlock() !== rootBlock) {
1536
- // Always bump the inferior block.
1537
- if (renderedConn.isSuperior()) {
1538
- renderedOther.bumpAwayFrom(renderedConn);
1539
- } else {
1540
- renderedConn.bumpAwayFrom(renderedOther);
1541
- }
1542
- }
1543
- }
1544
- }
1545
- }
1546
- }
1547
-
1548
- /**
1549
- * Schedule snapping to grid and bumping neighbours to occur after a brief
1550
- * delay.
1551
- * @internal
1552
- */
1553
- scheduleSnapAndBump() {
1554
- const block = this;
1555
- // Ensure that any snap and bump are part of this move's event group.
1556
- const group = eventUtils.getGroup();
1557
-
1558
- setTimeout(function() {
1559
- eventUtils.setGroup(group);
1560
- block.snapToGrid();
1561
- eventUtils.setGroup(false);
1562
- }, config.bumpDelay / 2);
1563
-
1564
- setTimeout(function() {
1565
- eventUtils.setGroup(group);
1566
- block.bumpNeighbours();
1567
- eventUtils.setGroup(false);
1568
- }, config.bumpDelay);
1569
- }
1570
-
1571
- /**
1572
- * Position a block so that it doesn't move the target block when connected.
1573
- * The block to position is usually either the first block in a dragged stack
1574
- * or an insertion marker.
1575
- * @param sourceConnection The connection on the moving block's stack.
1576
- * @param targetConnection The connection that should stay stationary as this
1577
- * block is positioned.
1578
- * @internal
1579
- */
1580
- positionNearConnection(
1581
- sourceConnection: RenderedConnection,
1582
- targetConnection: RenderedConnection) {
1583
- // We only need to position the new block if it's before the existing one,
1584
- // otherwise its position is set by the previous block.
1585
- if (sourceConnection.type === ConnectionType.NEXT_STATEMENT ||
1586
- sourceConnection.type === ConnectionType.INPUT_VALUE) {
1587
- const dx = targetConnection.x - sourceConnection.x;
1588
- const dy = targetConnection.y - sourceConnection.y;
1589
-
1590
- this.moveBy(dx, dy);
1591
- }
1592
- }
1593
-
1594
- /**
1595
- * @return The first statement connection or null.
1596
- * @internal
1597
- */
1598
- override getFirstStatementConnection(): RenderedConnection|null {
1599
- return super.getFirstStatementConnection() as RenderedConnection | null;
1600
- }
1601
-
1602
- /**
1603
- * Find all the blocks that are directly nested inside this one.
1604
- * Includes value and statement inputs, as well as any following statement.
1605
- * Excludes any connection on an output tab or any preceding statement.
1606
- * Blocks are optionally sorted by position; top to bottom.
1607
- * @param ordered Sort the list if true.
1608
- * @return Array of blocks.
1609
- */
1610
- override getChildren(ordered: boolean): BlockSvg[] {
1611
- return super.getChildren(ordered) as BlockSvg[];
1612
- }
1613
-
1614
- /**
1615
- * Lays out and reflows a block based on its contents and settings.
1616
- * @param opt_bubble If false, just render this block.
1617
- * If true, also render block's parent, grandparent, etc. Defaults to true.
1618
- */
1619
- render(opt_bubble?: boolean) {
1620
- if (this.renderIsInProgress_) {
1621
- return; // Don't allow recursive renders.
1622
- }
1623
- this.renderIsInProgress_ = true;
1624
- try {
1625
- this.rendered = true;
1626
- dom.startTextWidthCache();
1627
-
1628
- if (this.isCollapsed()) {
1629
- this.updateCollapsed_();
1630
- }
1631
- this.workspace.getRenderer().render(this);
1632
- this.updateConnectionLocations_();
1633
-
1634
- if (opt_bubble !== false) {
1635
- const parentBlock = this.getParent();
1636
- if (parentBlock) {
1637
- parentBlock.render(true);
1638
- } else {
1639
- // Top-most block. Fire an event to allow scrollbars to resize.
1640
- this.workspace.resizeContents();
1641
- }
1642
- }
1643
-
1644
- dom.stopTextWidthCache();
1645
- this.updateMarkers_();
1646
- } finally {
1647
- this.renderIsInProgress_ = false;
1648
- }
1649
- }
1650
-
1651
- /** Redraw any attached marker or cursor svgs if needed. */
1652
- protected updateMarkers_() {
1653
- if (this.workspace.keyboardAccessibilityMode && this.pathObject.cursorSvg) {
1654
- this.workspace.getCursor()!.draw();
1655
- }
1656
- if (this.workspace.keyboardAccessibilityMode && this.pathObject.markerSvg) {
1657
- // TODO(#4592): Update all markers on the block.
1658
- this.workspace.getMarker(MarkerManager.LOCAL_MARKER)!.draw();
1659
- }
1660
- }
1661
-
1662
- /**
1663
- * Update all of the connections on this block with the new locations
1664
- * calculated during rendering. Also move all of the connected blocks based
1665
- * on the new connection locations.
1666
- */
1667
- private updateConnectionLocations_() {
1668
- const blockTL = this.getRelativeToSurfaceXY();
1669
- // Don't tighten previous or output connections because they are inferior
1670
- // connections.
1671
- if (this.previousConnection) {
1672
- this.previousConnection.moveToOffset(blockTL);
1673
- }
1674
- if (this.outputConnection) {
1675
- this.outputConnection.moveToOffset(blockTL);
1676
- }
1677
-
1678
- for (let i = 0; i < this.inputList.length; i++) {
1679
- const conn = this.inputList[i].connection as RenderedConnection;
1680
- if (conn) {
1681
- conn.moveToOffset(blockTL);
1682
- if (conn.isConnected()) {
1683
- conn.tighten();
1684
- }
1685
- }
1686
- }
1687
-
1688
- if (this.nextConnection) {
1689
- this.nextConnection.moveToOffset(blockTL);
1690
- if (this.nextConnection.isConnected()) {
1691
- this.nextConnection.tighten();
1692
- }
1693
- }
1694
- }
1695
-
1696
- /**
1697
- * Add the cursor SVG to this block's SVG group.
1698
- * @param cursorSvg The SVG root of the cursor to be added to the block SVG
1699
- * group.
1700
- * @internal
1701
- */
1702
- setCursorSvg(cursorSvg: SVGElement) {
1703
- this.pathObject.setCursorSvg(cursorSvg);
1704
- }
1705
-
1706
- /**
1707
- * Add the marker SVG to this block's SVG group.
1708
- * @param markerSvg The SVG root of the marker to be added to the block SVG
1709
- * group.
1710
- * @internal
1711
- */
1712
- setMarkerSvg(markerSvg: SVGElement) {
1713
- this.pathObject.setMarkerSvg(markerSvg);
1714
- }
1715
-
1716
- /**
1717
- * Returns a bounding box describing the dimensions of this block
1718
- * and any blocks stacked below it.
1719
- * @return Object with height and width properties in workspace units.
1720
- * @internal
1721
- */
1722
- getHeightWidth(): {height: number, width: number} {
1723
- let height = this.height;
1724
- let width = this.width;
1725
- // Recursively add size of subsequent blocks.
1726
- const nextBlock = this.getNextBlock();
1727
- if (nextBlock) {
1728
- const nextHeightWidth = nextBlock.getHeightWidth();
1729
- const tabHeight =
1730
- this.workspace.getRenderer().getConstants().NOTCH_HEIGHT;
1731
- height += nextHeightWidth.height - tabHeight;
1732
- width = Math.max(width, nextHeightWidth.width);
1733
- }
1734
- return {height, width};
1735
- }
1736
-
1737
- /**
1738
- * Visual effect to show that if the dragging block is dropped, this block
1739
- * will be replaced. If a shadow block, it will disappear. Otherwise it will
1740
- * bump.
1741
- * @param add True if highlighting should be added.
1742
- * @internal
1743
- */
1744
- fadeForReplacement(add: boolean) {
1745
- this.pathObject.updateReplacementFade(add);
1746
- }
1747
-
1748
- /**
1749
- * Visual effect to show that if the dragging block is dropped it will connect
1750
- * to this input.
1751
- * @param conn The connection on the input to highlight.
1752
- * @param add True if highlighting should be added.
1753
- * @internal
1754
- */
1755
- highlightShapeForInput(conn: Connection, add: boolean) {
1756
- this.pathObject.updateShapeForInputHighlight(conn, add);
1757
- }
1758
- }