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

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