blockly 9.0.0-beta.0 → 9.0.0-beta.2

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 +830 -810
  2. package/blockly_compressed.js +821 -801
  3. package/blockly_compressed.js.map +1 -1
  4. package/blocks.d.ts +0 -5
  5. package/blocks_compressed.js +9 -9
  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 +156 -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 +92 -24
  16. package/core/blockly.d.ts +31 -10
  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 +51 -24
  42. package/core/events/events_abstract.d.ts +18 -7
  43. package/core/events/events_block_base.d.ts +13 -7
  44. package/core/events/events_block_change.d.ts +24 -11
  45. package/core/events/events_block_create.d.ts +18 -7
  46. package/core/events/events_block_delete.d.ts +20 -8
  47. package/core/events/events_block_drag.d.ts +14 -4
  48. package/core/events/events_block_move.d.ts +25 -12
  49. package/core/events/events_bubble_open.d.ts +21 -6
  50. package/core/events/events_click.d.ts +20 -6
  51. package/core/events/events_comment_base.d.ts +13 -6
  52. package/core/events/events_comment_change.d.ts +17 -7
  53. package/core/events/events_comment_create.d.ts +13 -5
  54. package/core/events/events_comment_delete.d.ts +4 -11
  55. package/core/events/events_comment_move.d.ts +19 -8
  56. package/core/events/events_marker_move.d.ts +16 -5
  57. package/core/events/events_selected.d.ts +14 -5
  58. package/core/events/events_theme_change.d.ts +11 -3
  59. package/core/events/events_toolbox_item_select.d.ts +14 -5
  60. package/core/events/events_trashcan_open.d.ts +11 -3
  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 +13 -7
  64. package/core/events/events_var_create.d.ts +15 -6
  65. package/core/events/events_var_delete.d.ts +15 -6
  66. package/core/events/events_var_rename.d.ts +15 -6
  67. package/core/events/events_viewport.d.ts +14 -3
  68. package/core/events/utils.d.ts +50 -7
  69. package/core/events/workspace_events.d.ts +11 -6
  70. package/core/extensions.d.ts +14 -4
  71. package/core/field.d.ts +93 -36
  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 +56 -22
  91. package/core/grid.d.ts +20 -16
  92. package/core/icon.d.ts +18 -5
  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 +3 -1
  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 +25 -6
  135. package/core/menuitem.d.ts +22 -7
  136. package/core/metrics_manager.d.ts +30 -15
  137. package/core/msg.d.ts +15 -0
  138. package/core/mutator.d.ts +20 -8
  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 +29 -7
  145. package/core/renderers/common/block_rendering.d.ts +9 -2
  146. package/core/renderers/common/constants.d.ts +57 -18
  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 +16 -3
  150. package/core/renderers/common/i_path_object.d.ts +37 -16
  151. package/core/renderers/common/info.d.ts +28 -11
  152. package/core/renderers/common/marker_svg.d.ts +42 -11
  153. package/core/renderers/common/path_object.d.ts +23 -3
  154. package/core/renderers/common/renderer.d.ts +33 -12
  155. package/core/renderers/geras/constants.d.ts +6 -2
  156. package/core/renderers/geras/drawer.d.ts +4 -1
  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 -1
  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 +4 -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 +30 -8
  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 -4
  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 +5 -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 +5 -4
  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 +31 -44
  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 -1
  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 +9 -2
  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 +41 -30
  221. package/core/theme_manager.d.ts +10 -1
  222. package/core/toolbox/category.d.ts +60 -32
  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 +71 -23
  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 +19 -4
  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 +19 -9
  235. package/core/utils/deprecation.d.ts +6 -4
  236. package/core/utils/dom.d.ts +37 -18
  237. package/core/utils/idgenerator.d.ts +14 -4
  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 +17 -7
  270. package/core-browser.js +0 -6
  271. package/core.d.ts +0 -5
  272. package/core.js +0 -6
  273. package/dart.d.ts +1 -7
  274. package/dart_compressed.js.map +1 -1
  275. package/index.d.ts +2 -6
  276. package/javascript.d.ts +1 -7
  277. package/javascript_compressed.js.map +1 -1
  278. package/lua.d.ts +1 -7
  279. package/lua_compressed.js.map +1 -1
  280. package/msg/ab.d.ts +8 -0
  281. package/msg/ace.d.ts +8 -0
  282. package/msg/af.d.ts +8 -0
  283. package/msg/am.d.ts +8 -0
  284. package/msg/ar.d.ts +8 -0
  285. package/msg/ast.d.ts +8 -0
  286. package/msg/az.d.ts +8 -0
  287. package/msg/ba.d.ts +8 -0
  288. package/msg/bcc.d.ts +8 -0
  289. package/msg/be-tarask.d.ts +8 -0
  290. package/msg/be.d.ts +8 -0
  291. package/msg/bg.d.ts +8 -0
  292. package/msg/bn.d.ts +8 -0
  293. package/msg/br.d.ts +8 -0
  294. package/msg/bs.d.ts +8 -0
  295. package/msg/ca.d.ts +8 -0
  296. package/msg/cdo.d.ts +8 -0
  297. package/msg/constants.d.ts +16 -0
  298. package/msg/cs.d.ts +8 -0
  299. package/msg/da.d.ts +8 -0
  300. package/msg/de.d.ts +8 -0
  301. package/msg/diq.d.ts +8 -0
  302. package/msg/dty.d.ts +8 -0
  303. package/msg/ee.d.ts +8 -0
  304. package/msg/el.d.ts +8 -0
  305. package/msg/en-gb.d.ts +8 -0
  306. package/msg/en.d.ts +8 -0
  307. package/msg/eo.d.ts +8 -0
  308. package/msg/es.d.ts +8 -0
  309. package/msg/et.d.ts +8 -0
  310. package/msg/eu.d.ts +8 -0
  311. package/msg/fa.d.ts +8 -0
  312. package/msg/fi.d.ts +8 -0
  313. package/msg/fo.d.ts +8 -0
  314. package/msg/fr.d.ts +8 -0
  315. package/msg/frr.d.ts +8 -0
  316. package/msg/gl.d.ts +8 -0
  317. package/msg/gn.d.ts +8 -0
  318. package/msg/gor.d.ts +8 -0
  319. package/msg/ha.d.ts +8 -0
  320. package/msg/hak.d.ts +8 -0
  321. package/msg/he.d.ts +8 -0
  322. package/msg/hi.d.ts +8 -0
  323. package/msg/hr.d.ts +8 -0
  324. package/msg/hrx.d.ts +8 -0
  325. package/msg/hu.d.ts +8 -0
  326. package/msg/hy.d.ts +8 -0
  327. package/msg/ia.d.ts +8 -0
  328. package/msg/id.d.ts +8 -0
  329. package/msg/ig.d.ts +8 -0
  330. package/msg/inh.d.ts +8 -0
  331. package/msg/is.d.ts +8 -0
  332. package/msg/it.d.ts +8 -0
  333. package/msg/ja.d.ts +8 -0
  334. package/msg/ka.d.ts +8 -0
  335. package/msg/kab.d.ts +8 -0
  336. package/msg/kbd-cyrl.d.ts +8 -0
  337. package/msg/km.d.ts +8 -0
  338. package/msg/kn.d.ts +8 -0
  339. package/msg/ko.d.ts +8 -0
  340. package/msg/ksh.d.ts +8 -0
  341. package/msg/ku-latn.d.ts +8 -0
  342. package/msg/ky.d.ts +8 -0
  343. package/msg/la.d.ts +8 -0
  344. package/msg/lb.d.ts +8 -0
  345. package/msg/lki.d.ts +8 -0
  346. package/msg/lo.d.ts +8 -0
  347. package/msg/lrc.d.ts +8 -0
  348. package/msg/lt.d.ts +8 -0
  349. package/msg/lv.d.ts +8 -0
  350. package/msg/mg.d.ts +8 -0
  351. package/msg/mk.d.ts +8 -0
  352. package/msg/ml.d.ts +8 -0
  353. package/msg/mnw.d.ts +8 -0
  354. package/msg/ms.d.ts +8 -0
  355. package/msg/msg.d.ts +429 -432
  356. package/msg/my.d.ts +8 -0
  357. package/msg/mzn.d.ts +8 -0
  358. package/msg/nb.d.ts +8 -0
  359. package/msg/ne.d.ts +8 -0
  360. package/msg/nl.d.ts +8 -0
  361. package/msg/oc.d.ts +8 -0
  362. package/msg/olo.d.ts +8 -0
  363. package/msg/pa.d.ts +8 -0
  364. package/msg/pl.d.ts +8 -0
  365. package/msg/pms.d.ts +8 -0
  366. package/msg/ps.d.ts +8 -0
  367. package/msg/pt-br.d.ts +8 -0
  368. package/msg/pt.d.ts +8 -0
  369. package/msg/qqq.d.ts +16 -0
  370. package/msg/ro.d.ts +8 -0
  371. package/msg/ru.d.ts +8 -0
  372. package/msg/sc.d.ts +8 -0
  373. package/msg/sco.d.ts +8 -0
  374. package/msg/sd.d.ts +8 -0
  375. package/msg/shn.d.ts +8 -0
  376. package/msg/si.d.ts +8 -0
  377. package/msg/sk.d.ts +8 -0
  378. package/msg/skr-arab.d.ts +8 -0
  379. package/msg/sl.d.ts +8 -0
  380. package/msg/smn.d.ts +8 -0
  381. package/msg/sq.d.ts +8 -0
  382. package/msg/sr-latn.d.ts +8 -0
  383. package/msg/sr.d.ts +8 -0
  384. package/msg/sv.d.ts +8 -0
  385. package/msg/sw.d.ts +8 -0
  386. package/msg/synonyms.d.ts +16 -0
  387. package/msg/ta.d.ts +8 -0
  388. package/msg/tcy.d.ts +8 -0
  389. package/msg/te.d.ts +8 -0
  390. package/msg/th.d.ts +8 -0
  391. package/msg/ti.d.ts +8 -0
  392. package/msg/tl.d.ts +8 -0
  393. package/msg/tlh.d.ts +8 -0
  394. package/msg/tr.d.ts +8 -0
  395. package/msg/ug-arab.d.ts +8 -0
  396. package/msg/uk.d.ts +8 -0
  397. package/msg/ur.d.ts +8 -0
  398. package/msg/uz.d.ts +8 -0
  399. package/msg/vi.d.ts +8 -0
  400. package/msg/xmf.d.ts +8 -0
  401. package/msg/yo.d.ts +8 -0
  402. package/msg/yue.d.ts +8 -0
  403. package/msg/zgh.d.ts +8 -0
  404. package/msg/zh-hans.d.ts +8 -0
  405. package/msg/zh-hant.d.ts +8 -0
  406. package/package.json +6 -3
  407. package/php.d.ts +1 -7
  408. package/php_compressed.js.map +1 -1
  409. package/python.d.ts +1 -7
  410. package/python_compressed.js.map +1 -1
  411. package/blocks/blocks.js +0 -48
  412. package/blocks/colour.js +0 -121
  413. package/blocks/lists.js +0 -996
  414. package/blocks/logic.js +0 -665
  415. package/blocks/loops.js +0 -375
  416. package/blocks/math.js +0 -594
  417. package/blocks/procedures.js +0 -1196
  418. package/blocks/text.js +0 -1000
  419. package/blocks/variables.js +0 -176
  420. package/blocks/variables_dynamic.js +0 -192
  421. package/core/any_aliases.ts +0 -1
  422. package/core/block.ts +0 -2102
  423. package/core/block_animations.ts +0 -202
  424. package/core/block_drag_surface.ts +0 -237
  425. package/core/block_dragger.ts +0 -447
  426. package/core/block_svg.ts +0 -1758
  427. package/core/blockly.js +0 -890
  428. package/core/blockly.ts +0 -749
  429. package/core/blockly_options.ts +0 -81
  430. package/core/blocks.ts +0 -29
  431. package/core/browser_events.ts +0 -289
  432. package/core/bubble.ts +0 -892
  433. package/core/bubble_dragger.ts +0 -229
  434. package/core/bump_objects.ts +0 -182
  435. package/core/clipboard.ts +0 -91
  436. package/core/comment.ts +0 -398
  437. package/core/common.ts +0 -288
  438. package/core/component_manager.ts +0 -211
  439. package/core/config.ts +0 -80
  440. package/core/connection.ts +0 -692
  441. package/core/connection_checker.ts +0 -301
  442. package/core/connection_db.ts +0 -289
  443. package/core/connection_type.ts +0 -32
  444. package/core/constants.ts +0 -29
  445. package/core/contextmenu.ts +0 -363
  446. package/core/contextmenu_items.ts +0 -576
  447. package/core/contextmenu_registry.ts +0 -179
  448. package/core/css.ts +0 -560
  449. package/core/delete_area.ts +0 -82
  450. package/core/dialog.ts +0 -127
  451. package/core/drag_target.ts +0 -94
  452. package/core/dropdowndiv.ts +0 -683
  453. package/core/events/events.ts +0 -123
  454. package/core/events/events_abstract.ts +0 -112
  455. package/core/events/events_block_base.ts +0 -65
  456. package/core/events/events_block_change.ts +0 -176
  457. package/core/events/events_block_create.ts +0 -114
  458. package/core/events/events_block_delete.ts +0 -126
  459. package/core/events/events_block_drag.ts +0 -82
  460. package/core/events/events_block_move.ts +0 -206
  461. package/core/events/events_bubble_open.ts +0 -82
  462. package/core/events/events_click.ts +0 -84
  463. package/core/events/events_comment_base.ts +0 -107
  464. package/core/events/events_comment_change.ts +0 -108
  465. package/core/events/events_comment_create.ts +0 -82
  466. package/core/events/events_comment_delete.ts +0 -77
  467. package/core/events/events_comment_move.ts +0 -154
  468. package/core/events/events_marker_move.ts +0 -99
  469. package/core/events/events_selected.ts +0 -78
  470. package/core/events/events_theme_change.ts +0 -67
  471. package/core/events/events_toolbox_item_select.ts +0 -79
  472. package/core/events/events_trashcan_open.ts +0 -68
  473. package/core/events/events_ui.ts +0 -89
  474. package/core/events/events_ui_base.ts +0 -54
  475. package/core/events/events_var_base.ts +0 -65
  476. package/core/events/events_var_create.ts +0 -88
  477. package/core/events/events_var_delete.ts +0 -88
  478. package/core/events/events_var_rename.ts +0 -89
  479. package/core/events/events_viewport.ts +0 -100
  480. package/core/events/utils.ts +0 -529
  481. package/core/events/workspace_events.ts +0 -86
  482. package/core/extensions.ts +0 -504
  483. package/core/field.ts +0 -1206
  484. package/core/field_angle.ts +0 -563
  485. package/core/field_checkbox.ts +0 -243
  486. package/core/field_colour.ts +0 -632
  487. package/core/field_dropdown.ts +0 -773
  488. package/core/field_image.ts +0 -282
  489. package/core/field_label.ts +0 -152
  490. package/core/field_label_serializable.ts +0 -76
  491. package/core/field_multilineinput.ts +0 -466
  492. package/core/field_number.ts +0 -327
  493. package/core/field_registry.ts +0 -87
  494. package/core/field_textinput.ts +0 -591
  495. package/core/field_variable.ts +0 -545
  496. package/core/flyout_base.ts +0 -1165
  497. package/core/flyout_button.ts +0 -292
  498. package/core/flyout_horizontal.ts +0 -381
  499. package/core/flyout_metrics_manager.ts +0 -94
  500. package/core/flyout_vertical.ts +0 -384
  501. package/core/generator.ts +0 -539
  502. package/core/gesture.ts +0 -946
  503. package/core/grid.ts +0 -192
  504. package/core/icon.ts +0 -189
  505. package/core/inject.ts +0 -390
  506. package/core/input.ts +0 -309
  507. package/core/input_types.ts +0 -32
  508. package/core/insertion_marker_manager.ts +0 -788
  509. package/core/interfaces/i_ast_node_location.ts +0 -23
  510. package/core/interfaces/i_ast_node_location_svg.ts +0 -37
  511. package/core/interfaces/i_ast_node_location_with_block.ts +0 -38
  512. package/core/interfaces/i_autohideable.ts +0 -34
  513. package/core/interfaces/i_block_dragger.ts +0 -67
  514. package/core/interfaces/i_bounded_element.ts +0 -42
  515. package/core/interfaces/i_bubble.ts +0 -88
  516. package/core/interfaces/i_collapsible_toolbox_item.ts +0 -47
  517. package/core/interfaces/i_component.ts +0 -32
  518. package/core/interfaces/i_connection_checker.ts +0 -102
  519. package/core/interfaces/i_contextmenu.ts +0 -26
  520. package/core/interfaces/i_copyable.ts +0 -40
  521. package/core/interfaces/i_deletable.ts +0 -29
  522. package/core/interfaces/i_delete_area.ts +0 -46
  523. package/core/interfaces/i_drag_target.ts +0 -84
  524. package/core/interfaces/i_draggable.ts +0 -25
  525. package/core/interfaces/i_flyout.ts +0 -186
  526. package/core/interfaces/i_keyboard_accessible.ts +0 -35
  527. package/core/interfaces/i_metrics_manager.ts +0 -151
  528. package/core/interfaces/i_movable.ts +0 -29
  529. package/core/interfaces/i_positionable.ts +0 -50
  530. package/core/interfaces/i_registrable.ts +0 -25
  531. package/core/interfaces/i_registrable_field.ts +0 -31
  532. package/core/interfaces/i_selectable.ts +0 -34
  533. package/core/interfaces/i_selectable_toolbox_item.ts +0 -64
  534. package/core/interfaces/i_serializer.ts +0 -65
  535. package/core/interfaces/i_styleable.ts +0 -35
  536. package/core/interfaces/i_toolbox.ts +0 -127
  537. package/core/interfaces/i_toolbox_item.ts +0 -84
  538. package/core/internal_constants.ts +0 -67
  539. package/core/keyboard_nav/ast_node.ts +0 -717
  540. package/core/keyboard_nav/basic_cursor.ts +0 -214
  541. package/core/keyboard_nav/cursor.ts +0 -134
  542. package/core/keyboard_nav/marker.ts +0 -115
  543. package/core/keyboard_nav/tab_navigate_cursor.ts +0 -48
  544. package/core/main.js +0 -303
  545. package/core/marker_manager.ts +0 -181
  546. package/core/menu.ts +0 -449
  547. package/core/menuitem.ts +0 -240
  548. package/core/metrics_manager.ts +0 -456
  549. package/core/msg.ts +0 -20
  550. package/core/mutator.ts +0 -560
  551. package/core/names.ts +0 -267
  552. package/core/options.ts +0 -365
  553. package/core/positionable_helpers.ts +0 -181
  554. package/core/procedures.ts +0 -443
  555. package/core/registry.ts +0 -339
  556. package/core/rendered_connection.ts +0 -568
  557. package/core/renderers/common/block_rendering.ts +0 -164
  558. package/core/renderers/common/constants.ts +0 -1124
  559. package/core/renderers/common/debug.ts +0 -61
  560. package/core/renderers/common/debugger.ts +0 -433
  561. package/core/renderers/common/drawer.ts +0 -450
  562. package/core/renderers/common/i_path_object.ts +0 -161
  563. package/core/renderers/common/info.ts +0 -718
  564. package/core/renderers/common/marker_svg.ts +0 -680
  565. package/core/renderers/common/path_object.ts +0 -272
  566. package/core/renderers/common/renderer.ts +0 -271
  567. package/core/renderers/geras/constants.ts +0 -61
  568. package/core/renderers/geras/drawer.ts +0 -176
  569. package/core/renderers/geras/geras.ts +0 -37
  570. package/core/renderers/geras/highlight_constants.ts +0 -337
  571. package/core/renderers/geras/highlighter.ts +0 -306
  572. package/core/renderers/geras/info.ts +0 -450
  573. package/core/renderers/geras/measurables/inline_input.ts +0 -51
  574. package/core/renderers/geras/measurables/statement_input.ts +0 -50
  575. package/core/renderers/geras/path_object.ts +0 -138
  576. package/core/renderers/geras/renderer.ts +0 -126
  577. package/core/renderers/measurables/base.ts +0 -53
  578. package/core/renderers/measurables/bottom_row.ts +0 -120
  579. package/core/renderers/measurables/connection.ts +0 -52
  580. package/core/renderers/measurables/external_value_input.ts +0 -65
  581. package/core/renderers/measurables/field.ts +0 -63
  582. package/core/renderers/measurables/hat.ts +0 -48
  583. package/core/renderers/measurables/icon.ts +0 -54
  584. package/core/renderers/measurables/in_row_spacer.ts +0 -44
  585. package/core/renderers/measurables/inline_input.ts +0 -76
  586. package/core/renderers/measurables/input_connection.ts +0 -66
  587. package/core/renderers/measurables/input_row.ts +0 -82
  588. package/core/renderers/measurables/jagged_edge.ts +0 -43
  589. package/core/renderers/measurables/next_connection.ts +0 -47
  590. package/core/renderers/measurables/output_connection.ts +0 -56
  591. package/core/renderers/measurables/previous_connection.ts +0 -47
  592. package/core/renderers/measurables/round_corner.ts +0 -49
  593. package/core/renderers/measurables/row.ts +0 -225
  594. package/core/renderers/measurables/spacer_row.ts +0 -55
  595. package/core/renderers/measurables/square_corner.ts +0 -47
  596. package/core/renderers/measurables/statement_input.ts +0 -55
  597. package/core/renderers/measurables/top_row.ts +0 -122
  598. package/core/renderers/measurables/types.ts +0 -332
  599. package/core/renderers/minimalist/constants.ts +0 -32
  600. package/core/renderers/minimalist/drawer.ts +0 -38
  601. package/core/renderers/minimalist/info.ts +0 -52
  602. package/core/renderers/minimalist/minimalist.ts +0 -22
  603. package/core/renderers/minimalist/renderer.ts +0 -71
  604. package/core/renderers/thrasos/info.ts +0 -338
  605. package/core/renderers/thrasos/renderer.ts +0 -48
  606. package/core/renderers/thrasos/thrasos.ts +0 -20
  607. package/core/renderers/zelos/constants.ts +0 -858
  608. package/core/renderers/zelos/drawer.ts +0 -228
  609. package/core/renderers/zelos/info.ts +0 -593
  610. package/core/renderers/zelos/marker_svg.ts +0 -151
  611. package/core/renderers/zelos/measurables/bottom_row.ts +0 -53
  612. package/core/renderers/zelos/measurables/inputs.ts +0 -56
  613. package/core/renderers/zelos/measurables/row_elements.ts +0 -45
  614. package/core/renderers/zelos/measurables/top_row.ts +0 -58
  615. package/core/renderers/zelos/path_object.ts +0 -215
  616. package/core/renderers/zelos/renderer.ts +0 -142
  617. package/core/renderers/zelos/zelos.ts +0 -39
  618. package/core/scrollbar.ts +0 -870
  619. package/core/scrollbar_pair.ts +0 -321
  620. package/core/serialization/blocks.ts +0 -706
  621. package/core/serialization/exceptions.ts +0 -98
  622. package/core/serialization/priorities.ts +0 -32
  623. package/core/serialization/registry.ts +0 -43
  624. package/core/serialization/variables.ts +0 -96
  625. package/core/serialization/workspaces.ts +0 -106
  626. package/core/shortcut_items.ts +0 -266
  627. package/core/shortcut_registry.ts +0 -355
  628. package/core/sprites.ts +0 -29
  629. package/core/theme/classic.ts +0 -54
  630. package/core/theme/themes.ts +0 -22
  631. package/core/theme/zelos.ts +0 -91
  632. package/core/theme.ts +0 -221
  633. package/core/theme_manager.ts +0 -186
  634. package/core/toolbox/category.ts +0 -679
  635. package/core/toolbox/collapsible_category.ts +0 -273
  636. package/core/toolbox/separator.ts +0 -105
  637. package/core/toolbox/toolbox.ts +0 -1044
  638. package/core/toolbox/toolbox_item.ts +0 -147
  639. package/core/tooltip.ts +0 -463
  640. package/core/touch.ts +0 -306
  641. package/core/touch_gesture.ts +0 -295
  642. package/core/trashcan.ts +0 -671
  643. package/core/utils/aria.ts +0 -160
  644. package/core/utils/array.ts +0 -32
  645. package/core/utils/colour.ts +0 -276
  646. package/core/utils/coordinate.ts +0 -124
  647. package/core/utils/deprecation.ts +0 -41
  648. package/core/utils/dom.ts +0 -408
  649. package/core/utils/idgenerator.ts +0 -80
  650. package/core/utils/keycodes.ts +0 -169
  651. package/core/utils/math.ts +0 -61
  652. package/core/utils/metrics.ts +0 -97
  653. package/core/utils/object.ts +0 -95
  654. package/core/utils/parsing.ts +0 -261
  655. package/core/utils/rect.ts +0 -62
  656. package/core/utils/sentinel.ts +0 -23
  657. package/core/utils/size.ts +0 -51
  658. package/core/utils/string.ts +0 -308
  659. package/core/utils/style.ts +0 -306
  660. package/core/utils/svg.ts +0 -88
  661. package/core/utils/svg_math.ts +0 -269
  662. package/core/utils/svg_paths.ts +0 -140
  663. package/core/utils/toolbox.ts +0 -433
  664. package/core/utils/useragent.ts +0 -135
  665. package/core/utils/xml.ts +0 -97
  666. package/core/utils.ts +0 -428
  667. package/core/variable_map.ts +0 -392
  668. package/core/variable_model.ts +0 -82
  669. package/core/variables.ts +0 -596
  670. package/core/variables_dynamic.ts +0 -133
  671. package/core/warning.ts +0 -161
  672. package/core/widgetdiv.ts +0 -257
  673. package/core/workspace.ts +0 -801
  674. package/core/workspace_audio.ts +0 -156
  675. package/core/workspace_comment.ts +0 -398
  676. package/core/workspace_comment_svg.ts +0 -1127
  677. package/core/workspace_drag_surface_svg.ts +0 -187
  678. package/core/workspace_dragger.ts +0 -104
  679. package/core/workspace_svg.ts +0 -2655
  680. package/core/xml.ts +0 -1023
  681. package/core/zoom_controls.ts +0 -441
  682. package/generators/dart/all.js +0 -27
  683. package/generators/dart/colour.js +0 -105
  684. package/generators/dart/lists.js +0 -431
  685. package/generators/dart/logic.js +0 -123
  686. package/generators/dart/loops.js +0 -161
  687. package/generators/dart/math.js +0 -446
  688. package/generators/dart/procedures.js +0 -105
  689. package/generators/dart/text.js +0 -338
  690. package/generators/dart/variables.js +0 -32
  691. package/generators/dart/variables_dynamic.js +0 -21
  692. package/generators/dart.js +0 -303
  693. package/generators/javascript/all.js +0 -27
  694. package/generators/javascript/colour.js +0 -85
  695. package/generators/javascript/lists.js +0 -405
  696. package/generators/javascript/logic.js +0 -127
  697. package/generators/javascript/loops.js +0 -180
  698. package/generators/javascript/math.js +0 -401
  699. package/generators/javascript/procedures.js +0 -110
  700. package/generators/javascript/text.js +0 -371
  701. package/generators/javascript/variables.js +0 -32
  702. package/generators/javascript/variables_dynamic.js +0 -21
  703. package/generators/javascript.js +0 -322
  704. package/generators/lua/all.js +0 -27
  705. package/generators/lua/colour.js +0 -71
  706. package/generators/lua/lists.js +0 -348
  707. package/generators/lua/logic.js +0 -112
  708. package/generators/lua/loops.js +0 -168
  709. package/generators/lua/math.js +0 -406
  710. package/generators/lua/procedures.js +0 -106
  711. package/generators/lua/text.js +0 -327
  712. package/generators/lua/variables.js +0 -31
  713. package/generators/lua/variables_dynamic.js +0 -21
  714. package/generators/lua.js +0 -206
  715. package/generators/php/all.js +0 -27
  716. package/generators/php/colour.js +0 -81
  717. package/generators/php/lists.js +0 -481
  718. package/generators/php/logic.js +0 -119
  719. package/generators/php/loops.js +0 -161
  720. package/generators/php/math.js +0 -349
  721. package/generators/php/procedures.js +0 -125
  722. package/generators/php/text.js +0 -255
  723. package/generators/php/variables.js +0 -32
  724. package/generators/php/variables_dynamic.js +0 -21
  725. package/generators/php.js +0 -303
  726. package/generators/python/all.js +0 -27
  727. package/generators/python/colour.js +0 -67
  728. package/generators/python/lists.js +0 -346
  729. package/generators/python/logic.js +0 -120
  730. package/generators/python/loops.js +0 -206
  731. package/generators/python/math.js +0 -373
  732. package/generators/python/procedures.js +0 -129
  733. package/generators/python/text.js +0 -291
  734. package/generators/python/variables.js +0 -32
  735. package/generators/python/variables_dynamic.js +0 -21
  736. 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
- }