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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (736) hide show
  1. package/blockly.min.js +830 -810
  2. package/blockly_compressed.js +821 -801
  3. package/blockly_compressed.js.map +1 -1
  4. package/blocks.d.ts +0 -5
  5. package/blocks_compressed.js +9 -9
  6. package/blocks_compressed.js.map +1 -1
  7. package/closure/goog/base.d.ts +1 -0
  8. package/closure/goog/base_minimal.d.ts +1 -0
  9. package/closure/goog/goog.d.ts +1 -0
  10. package/core/any_aliases.d.ts +1 -0
  11. package/core/block.d.ts +156 -53
  12. package/core/block_animations.d.ts +5 -0
  13. package/core/block_drag_surface.d.ts +18 -5
  14. package/core/block_dragger.d.ts +20 -5
  15. package/core/block_svg.d.ts +92 -24
  16. package/core/blockly.d.ts +31 -10
  17. package/core/blockly_options.d.ts +2 -0
  18. package/core/blocks.d.ts +2 -0
  19. package/core/browser_events.d.ts +16 -7
  20. package/core/bubble.d.ts +42 -12
  21. package/core/bubble_dragger.d.ts +9 -2
  22. package/core/bump_objects.d.ts +6 -2
  23. package/core/clipboard.d.ts +6 -2
  24. package/core/comment.d.ts +13 -3
  25. package/core/common.d.ts +35 -9
  26. package/core/component_manager.d.ts +16 -6
  27. package/core/config.d.ts +1 -0
  28. package/core/connection.d.ts +48 -18
  29. package/core/connection_checker.d.ts +16 -7
  30. package/core/connection_db.d.ts +17 -6
  31. package/core/connection_type.d.ts +2 -0
  32. package/core/constants.d.ts +3 -0
  33. package/core/contextmenu.d.ts +15 -5
  34. package/core/contextmenu_items.d.ts +15 -0
  35. package/core/contextmenu_registry.d.ts +12 -7
  36. package/core/css.d.ts +3 -0
  37. package/core/delete_area.d.ts +5 -1
  38. package/core/dialog.d.ts +14 -7
  39. package/core/drag_target.d.ts +10 -2
  40. package/core/dropdowndiv.d.ts +42 -10
  41. package/core/events/events.d.ts +51 -24
  42. package/core/events/events_abstract.d.ts +18 -7
  43. package/core/events/events_block_base.d.ts +13 -7
  44. package/core/events/events_block_change.d.ts +24 -11
  45. package/core/events/events_block_create.d.ts +18 -7
  46. package/core/events/events_block_delete.d.ts +20 -8
  47. package/core/events/events_block_drag.d.ts +14 -4
  48. package/core/events/events_block_move.d.ts +25 -12
  49. package/core/events/events_bubble_open.d.ts +21 -6
  50. package/core/events/events_click.d.ts +20 -6
  51. package/core/events/events_comment_base.d.ts +13 -6
  52. package/core/events/events_comment_change.d.ts +17 -7
  53. package/core/events/events_comment_create.d.ts +13 -5
  54. package/core/events/events_comment_delete.d.ts +4 -11
  55. package/core/events/events_comment_move.d.ts +19 -8
  56. package/core/events/events_marker_move.d.ts +16 -5
  57. package/core/events/events_selected.d.ts +14 -5
  58. package/core/events/events_theme_change.d.ts +11 -3
  59. package/core/events/events_toolbox_item_select.d.ts +14 -5
  60. package/core/events/events_trashcan_open.d.ts +11 -3
  61. package/core/events/events_ui.d.ts +5 -1
  62. package/core/events/events_ui_base.d.ts +2 -0
  63. package/core/events/events_var_base.d.ts +13 -7
  64. package/core/events/events_var_create.d.ts +15 -6
  65. package/core/events/events_var_delete.d.ts +15 -6
  66. package/core/events/events_var_rename.d.ts +15 -6
  67. package/core/events/events_viewport.d.ts +14 -3
  68. package/core/events/utils.d.ts +50 -7
  69. package/core/events/workspace_events.d.ts +11 -6
  70. package/core/extensions.d.ts +14 -4
  71. package/core/field.d.ts +93 -36
  72. package/core/field_angle.d.ts +14 -3
  73. package/core/field_checkbox.d.ts +20 -7
  74. package/core/field_colour.d.ts +22 -6
  75. package/core/field_dropdown.d.ts +28 -8
  76. package/core/field_image.d.ts +15 -4
  77. package/core/field_label.d.ts +8 -2
  78. package/core/field_label_serializable.d.ts +4 -1
  79. package/core/field_multilineinput.d.ts +21 -6
  80. package/core/field_number.d.ts +22 -6
  81. package/core/field_registry.d.ts +8 -2
  82. package/core/field_textinput.d.ts +28 -8
  83. package/core/field_variable.d.ts +36 -13
  84. package/core/flyout_base.d.ts +70 -24
  85. package/core/flyout_button.d.ts +12 -5
  86. package/core/flyout_horizontal.d.ts +14 -6
  87. package/core/flyout_metrics_manager.d.ts +6 -3
  88. package/core/flyout_vertical.d.ts +14 -6
  89. package/core/generator.d.ts +39 -20
  90. package/core/gesture.d.ts +56 -22
  91. package/core/grid.d.ts +20 -16
  92. package/core/icon.d.ts +18 -5
  93. package/core/inject.d.ts +3 -1
  94. package/core/input.d.ts +25 -10
  95. package/core/input_types.d.ts +2 -0
  96. package/core/insertion_marker_manager.d.ts +27 -9
  97. package/core/interfaces/i_ast_node_location.d.ts +2 -0
  98. package/core/interfaces/i_ast_node_location_svg.d.ts +4 -0
  99. package/core/interfaces/i_ast_node_location_with_block.d.ts +4 -1
  100. package/core/interfaces/i_autohideable.d.ts +3 -0
  101. package/core/interfaces/i_block_dragger.d.ts +7 -1
  102. package/core/interfaces/i_bounded_element.d.ts +5 -1
  103. package/core/interfaces/i_bubble.d.ts +11 -2
  104. package/core/interfaces/i_collapsible_toolbox_item.d.ts +6 -2
  105. package/core/interfaces/i_component.d.ts +3 -1
  106. package/core/interfaces/i_connection_checker.d.ts +14 -6
  107. package/core/interfaces/i_contextmenu.d.ts +2 -0
  108. package/core/interfaces/i_copyable.d.ts +3 -1
  109. package/core/interfaces/i_deletable.d.ts +4 -1
  110. package/core/interfaces/i_delete_area.d.ts +4 -1
  111. package/core/interfaces/i_drag_target.d.ts +10 -2
  112. package/core/interfaces/i_draggable.d.ts +2 -0
  113. package/core/interfaces/i_flyout.d.ts +27 -11
  114. package/core/interfaces/i_keyboard_accessible.d.ts +4 -1
  115. package/core/interfaces/i_metrics_manager.d.ts +24 -12
  116. package/core/interfaces/i_movable.d.ts +4 -1
  117. package/core/interfaces/i_positionable.d.ts +5 -1
  118. package/core/interfaces/i_registrable.d.ts +2 -0
  119. package/core/interfaces/i_registrable_field.d.ts +2 -0
  120. package/core/interfaces/i_selectable.d.ts +2 -0
  121. package/core/interfaces/i_selectable_toolbox_item.d.ts +10 -3
  122. package/core/interfaces/i_serializer.d.ts +6 -1
  123. package/core/interfaces/i_styleable.d.ts +4 -0
  124. package/core/interfaces/i_toolbox.d.ts +17 -6
  125. package/core/interfaces/i_toolbox_item.d.ts +17 -7
  126. package/core/internal_constants.d.ts +6 -0
  127. package/core/keyboard_nav/ast_node.d.ts +55 -28
  128. package/core/keyboard_nav/basic_cursor.d.ts +20 -9
  129. package/core/keyboard_nav/cursor.d.ts +11 -5
  130. package/core/keyboard_nav/marker.d.ts +9 -2
  131. package/core/keyboard_nav/tab_navigate_cursor.d.ts +4 -1
  132. package/core/main.d.ts +1 -0
  133. package/core/marker_manager.d.ts +13 -2
  134. package/core/menu.d.ts +25 -6
  135. package/core/menuitem.d.ts +22 -7
  136. package/core/metrics_manager.d.ts +30 -15
  137. package/core/msg.d.ts +15 -0
  138. package/core/mutator.d.ts +20 -8
  139. package/core/names.d.ts +20 -8
  140. package/core/options.d.ts +12 -6
  141. package/core/positionable_helpers.d.ts +11 -3
  142. package/core/procedures.d.ts +27 -10
  143. package/core/registry.d.ts +19 -8
  144. package/core/rendered_connection.d.ts +29 -7
  145. package/core/renderers/common/block_rendering.d.ts +9 -2
  146. package/core/renderers/common/constants.d.ts +57 -18
  147. package/core/renderers/common/debug.d.ts +5 -1
  148. package/core/renderers/common/debugger.d.ts +12 -1
  149. package/core/renderers/common/drawer.d.ts +16 -3
  150. package/core/renderers/common/i_path_object.d.ts +37 -16
  151. package/core/renderers/common/info.d.ts +28 -11
  152. package/core/renderers/common/marker_svg.d.ts +42 -11
  153. package/core/renderers/common/path_object.d.ts +23 -3
  154. package/core/renderers/common/renderer.d.ts +33 -12
  155. package/core/renderers/geras/constants.d.ts +6 -2
  156. package/core/renderers/geras/drawer.d.ts +4 -1
  157. package/core/renderers/geras/geras.d.ts +3 -2
  158. package/core/renderers/geras/highlight_constants.d.ts +9 -6
  159. package/core/renderers/geras/highlighter.d.ts +12 -1
  160. package/core/renderers/geras/info.d.ts +4 -1
  161. package/core/renderers/geras/measurables/inline_input.d.ts +2 -0
  162. package/core/renderers/geras/measurables/statement_input.d.ts +2 -0
  163. package/core/renderers/geras/path_object.d.ts +4 -1
  164. package/core/renderers/geras/renderer.d.ts +16 -6
  165. package/core/renderers/measurables/base.d.ts +2 -0
  166. package/core/renderers/measurables/bottom_row.d.ts +9 -3
  167. package/core/renderers/measurables/connection.d.ts +2 -0
  168. package/core/renderers/measurables/external_value_input.d.ts +2 -1
  169. package/core/renderers/measurables/field.d.ts +2 -1
  170. package/core/renderers/measurables/hat.d.ts +2 -1
  171. package/core/renderers/measurables/icon.d.ts +4 -1
  172. package/core/renderers/measurables/in_row_spacer.d.ts +2 -1
  173. package/core/renderers/measurables/inline_input.d.ts +2 -1
  174. package/core/renderers/measurables/input_connection.d.ts +2 -0
  175. package/core/renderers/measurables/input_row.d.ts +4 -1
  176. package/core/renderers/measurables/jagged_edge.d.ts +2 -1
  177. package/core/renderers/measurables/next_connection.d.ts +2 -1
  178. package/core/renderers/measurables/output_connection.d.ts +2 -1
  179. package/core/renderers/measurables/previous_connection.d.ts +2 -1
  180. package/core/renderers/measurables/round_corner.d.ts +2 -1
  181. package/core/renderers/measurables/row.d.ts +30 -8
  182. package/core/renderers/measurables/spacer_row.d.ts +2 -1
  183. package/core/renderers/measurables/square_corner.d.ts +2 -1
  184. package/core/renderers/measurables/statement_input.d.ts +2 -1
  185. package/core/renderers/measurables/top_row.d.ts +7 -4
  186. package/core/renderers/measurables/types.d.ts +54 -25
  187. package/core/renderers/minimalist/constants.d.ts +2 -0
  188. package/core/renderers/minimalist/drawer.d.ts +2 -0
  189. package/core/renderers/minimalist/info.d.ts +5 -1
  190. package/core/renderers/minimalist/minimalist.d.ts +2 -1
  191. package/core/renderers/minimalist/renderer.d.ts +8 -3
  192. package/core/renderers/thrasos/info.d.ts +5 -4
  193. package/core/renderers/thrasos/renderer.d.ts +4 -1
  194. package/core/renderers/thrasos/thrasos.d.ts +2 -1
  195. package/core/renderers/zelos/constants.d.ts +31 -44
  196. package/core/renderers/zelos/drawer.d.ts +3 -0
  197. package/core/renderers/zelos/info.d.ts +10 -5
  198. package/core/renderers/zelos/marker_svg.d.ts +5 -0
  199. package/core/renderers/zelos/measurables/bottom_row.d.ts +2 -0
  200. package/core/renderers/zelos/measurables/inputs.d.ts +2 -1
  201. package/core/renderers/zelos/measurables/row_elements.d.ts +2 -0
  202. package/core/renderers/zelos/measurables/top_row.d.ts +2 -0
  203. package/core/renderers/zelos/path_object.d.ts +9 -2
  204. package/core/renderers/zelos/renderer.d.ts +14 -6
  205. package/core/renderers/zelos/zelos.d.ts +3 -2
  206. package/core/scrollbar.d.ts +41 -9
  207. package/core/scrollbar_pair.d.ts +20 -6
  208. package/core/serialization/blocks.d.ts +10 -4
  209. package/core/serialization/exceptions.d.ts +5 -0
  210. package/core/serialization/priorities.d.ts +3 -0
  211. package/core/serialization/registry.d.ts +3 -0
  212. package/core/serialization/variables.d.ts +2 -0
  213. package/core/serialization/workspaces.d.ts +4 -1
  214. package/core/shortcut_items.d.ts +10 -0
  215. package/core/shortcut_registry.d.ts +25 -9
  216. package/core/sprites.d.ts +2 -4
  217. package/core/theme/classic.d.ts +2 -0
  218. package/core/theme/themes.d.ts +1 -0
  219. package/core/theme/zelos.d.ts +2 -0
  220. package/core/theme.d.ts +41 -30
  221. package/core/theme_manager.d.ts +10 -1
  222. package/core/toolbox/category.d.ts +60 -32
  223. package/core/toolbox/collapsible_category.d.ts +10 -3
  224. package/core/toolbox/separator.d.ts +4 -1
  225. package/core/toolbox/toolbox.d.ts +71 -23
  226. package/core/toolbox/toolbox_item.d.ts +17 -7
  227. package/core/tooltip.d.ts +22 -1
  228. package/core/touch.d.ts +18 -6
  229. package/core/touch_gesture.d.ts +19 -4
  230. package/core/trashcan.d.ts +27 -6
  231. package/core/utils/aria.d.ts +4 -0
  232. package/core/utils/array.d.ts +4 -2
  233. package/core/utils/colour.d.ts +24 -13
  234. package/core/utils/coordinate.d.ts +19 -9
  235. package/core/utils/deprecation.d.ts +6 -4
  236. package/core/utils/dom.d.ts +37 -18
  237. package/core/utils/idgenerator.d.ts +14 -4
  238. package/core/utils/keycodes.d.ts +1 -0
  239. package/core/utils/math.d.ts +7 -3
  240. package/core/utils/metrics.d.ts +1 -0
  241. package/core/utils/object.d.ts +7 -2
  242. package/core/utils/parsing.d.ts +9 -4
  243. package/core/utils/rect.d.ts +5 -3
  244. package/core/utils/sentinel.d.ts +2 -0
  245. package/core/utils/size.d.ts +4 -2
  246. package/core/utils/string.d.ts +13 -6
  247. package/core/utils/style.d.ts +14 -33
  248. package/core/utils/svg.d.ts +5 -2
  249. package/core/utils/svg_math.d.ts +15 -7
  250. package/core/utils/svg_paths.d.ts +20 -10
  251. package/core/utils/toolbox.d.ts +26 -5
  252. package/core/utils/useragent.d.ts +1 -12
  253. package/core/utils/xml.d.ts +13 -5
  254. package/core/utils.d.ts +43 -21
  255. package/core/variable_map.d.ts +26 -9
  256. package/core/variable_model.d.ts +5 -2
  257. package/core/variables.d.ts +33 -18
  258. package/core/variables_dynamic.d.ts +25 -5
  259. package/core/warning.d.ts +8 -3
  260. package/core/widgetdiv.d.ts +15 -6
  261. package/core/workspace.d.ts +80 -30
  262. package/core/workspace_audio.d.ts +6 -0
  263. package/core/workspace_comment.d.ts +33 -11
  264. package/core/workspace_comment_svg.d.ts +52 -9
  265. package/core/workspace_drag_surface_svg.d.ts +20 -14
  266. package/core/workspace_dragger.d.ts +6 -0
  267. package/core/workspace_svg.d.ts +174 -62
  268. package/core/xml.d.ts +26 -11
  269. package/core/zoom_controls.d.ts +17 -7
  270. package/core-browser.js +0 -6
  271. package/core.d.ts +0 -5
  272. package/core.js +0 -6
  273. package/dart.d.ts +1 -7
  274. package/dart_compressed.js.map +1 -1
  275. package/index.d.ts +2 -6
  276. package/javascript.d.ts +1 -7
  277. package/javascript_compressed.js.map +1 -1
  278. package/lua.d.ts +1 -7
  279. package/lua_compressed.js.map +1 -1
  280. package/msg/ab.d.ts +8 -0
  281. package/msg/ace.d.ts +8 -0
  282. package/msg/af.d.ts +8 -0
  283. package/msg/am.d.ts +8 -0
  284. package/msg/ar.d.ts +8 -0
  285. package/msg/ast.d.ts +8 -0
  286. package/msg/az.d.ts +8 -0
  287. package/msg/ba.d.ts +8 -0
  288. package/msg/bcc.d.ts +8 -0
  289. package/msg/be-tarask.d.ts +8 -0
  290. package/msg/be.d.ts +8 -0
  291. package/msg/bg.d.ts +8 -0
  292. package/msg/bn.d.ts +8 -0
  293. package/msg/br.d.ts +8 -0
  294. package/msg/bs.d.ts +8 -0
  295. package/msg/ca.d.ts +8 -0
  296. package/msg/cdo.d.ts +8 -0
  297. package/msg/constants.d.ts +16 -0
  298. package/msg/cs.d.ts +8 -0
  299. package/msg/da.d.ts +8 -0
  300. package/msg/de.d.ts +8 -0
  301. package/msg/diq.d.ts +8 -0
  302. package/msg/dty.d.ts +8 -0
  303. package/msg/ee.d.ts +8 -0
  304. package/msg/el.d.ts +8 -0
  305. package/msg/en-gb.d.ts +8 -0
  306. package/msg/en.d.ts +8 -0
  307. package/msg/eo.d.ts +8 -0
  308. package/msg/es.d.ts +8 -0
  309. package/msg/et.d.ts +8 -0
  310. package/msg/eu.d.ts +8 -0
  311. package/msg/fa.d.ts +8 -0
  312. package/msg/fi.d.ts +8 -0
  313. package/msg/fo.d.ts +8 -0
  314. package/msg/fr.d.ts +8 -0
  315. package/msg/frr.d.ts +8 -0
  316. package/msg/gl.d.ts +8 -0
  317. package/msg/gn.d.ts +8 -0
  318. package/msg/gor.d.ts +8 -0
  319. package/msg/ha.d.ts +8 -0
  320. package/msg/hak.d.ts +8 -0
  321. package/msg/he.d.ts +8 -0
  322. package/msg/hi.d.ts +8 -0
  323. package/msg/hr.d.ts +8 -0
  324. package/msg/hrx.d.ts +8 -0
  325. package/msg/hu.d.ts +8 -0
  326. package/msg/hy.d.ts +8 -0
  327. package/msg/ia.d.ts +8 -0
  328. package/msg/id.d.ts +8 -0
  329. package/msg/ig.d.ts +8 -0
  330. package/msg/inh.d.ts +8 -0
  331. package/msg/is.d.ts +8 -0
  332. package/msg/it.d.ts +8 -0
  333. package/msg/ja.d.ts +8 -0
  334. package/msg/ka.d.ts +8 -0
  335. package/msg/kab.d.ts +8 -0
  336. package/msg/kbd-cyrl.d.ts +8 -0
  337. package/msg/km.d.ts +8 -0
  338. package/msg/kn.d.ts +8 -0
  339. package/msg/ko.d.ts +8 -0
  340. package/msg/ksh.d.ts +8 -0
  341. package/msg/ku-latn.d.ts +8 -0
  342. package/msg/ky.d.ts +8 -0
  343. package/msg/la.d.ts +8 -0
  344. package/msg/lb.d.ts +8 -0
  345. package/msg/lki.d.ts +8 -0
  346. package/msg/lo.d.ts +8 -0
  347. package/msg/lrc.d.ts +8 -0
  348. package/msg/lt.d.ts +8 -0
  349. package/msg/lv.d.ts +8 -0
  350. package/msg/mg.d.ts +8 -0
  351. package/msg/mk.d.ts +8 -0
  352. package/msg/ml.d.ts +8 -0
  353. package/msg/mnw.d.ts +8 -0
  354. package/msg/ms.d.ts +8 -0
  355. package/msg/msg.d.ts +429 -432
  356. package/msg/my.d.ts +8 -0
  357. package/msg/mzn.d.ts +8 -0
  358. package/msg/nb.d.ts +8 -0
  359. package/msg/ne.d.ts +8 -0
  360. package/msg/nl.d.ts +8 -0
  361. package/msg/oc.d.ts +8 -0
  362. package/msg/olo.d.ts +8 -0
  363. package/msg/pa.d.ts +8 -0
  364. package/msg/pl.d.ts +8 -0
  365. package/msg/pms.d.ts +8 -0
  366. package/msg/ps.d.ts +8 -0
  367. package/msg/pt-br.d.ts +8 -0
  368. package/msg/pt.d.ts +8 -0
  369. package/msg/qqq.d.ts +16 -0
  370. package/msg/ro.d.ts +8 -0
  371. package/msg/ru.d.ts +8 -0
  372. package/msg/sc.d.ts +8 -0
  373. package/msg/sco.d.ts +8 -0
  374. package/msg/sd.d.ts +8 -0
  375. package/msg/shn.d.ts +8 -0
  376. package/msg/si.d.ts +8 -0
  377. package/msg/sk.d.ts +8 -0
  378. package/msg/skr-arab.d.ts +8 -0
  379. package/msg/sl.d.ts +8 -0
  380. package/msg/smn.d.ts +8 -0
  381. package/msg/sq.d.ts +8 -0
  382. package/msg/sr-latn.d.ts +8 -0
  383. package/msg/sr.d.ts +8 -0
  384. package/msg/sv.d.ts +8 -0
  385. package/msg/sw.d.ts +8 -0
  386. package/msg/synonyms.d.ts +16 -0
  387. package/msg/ta.d.ts +8 -0
  388. package/msg/tcy.d.ts +8 -0
  389. package/msg/te.d.ts +8 -0
  390. package/msg/th.d.ts +8 -0
  391. package/msg/ti.d.ts +8 -0
  392. package/msg/tl.d.ts +8 -0
  393. package/msg/tlh.d.ts +8 -0
  394. package/msg/tr.d.ts +8 -0
  395. package/msg/ug-arab.d.ts +8 -0
  396. package/msg/uk.d.ts +8 -0
  397. package/msg/ur.d.ts +8 -0
  398. package/msg/uz.d.ts +8 -0
  399. package/msg/vi.d.ts +8 -0
  400. package/msg/xmf.d.ts +8 -0
  401. package/msg/yo.d.ts +8 -0
  402. package/msg/yue.d.ts +8 -0
  403. package/msg/zgh.d.ts +8 -0
  404. package/msg/zh-hans.d.ts +8 -0
  405. package/msg/zh-hant.d.ts +8 -0
  406. package/package.json +6 -3
  407. package/php.d.ts +1 -7
  408. package/php_compressed.js.map +1 -1
  409. package/python.d.ts +1 -7
  410. package/python_compressed.js.map +1 -1
  411. package/blocks/blocks.js +0 -48
  412. package/blocks/colour.js +0 -121
  413. package/blocks/lists.js +0 -996
  414. package/blocks/logic.js +0 -665
  415. package/blocks/loops.js +0 -375
  416. package/blocks/math.js +0 -594
  417. package/blocks/procedures.js +0 -1196
  418. package/blocks/text.js +0 -1000
  419. package/blocks/variables.js +0 -176
  420. package/blocks/variables_dynamic.js +0 -192
  421. package/core/any_aliases.ts +0 -1
  422. package/core/block.ts +0 -2102
  423. package/core/block_animations.ts +0 -202
  424. package/core/block_drag_surface.ts +0 -237
  425. package/core/block_dragger.ts +0 -447
  426. package/core/block_svg.ts +0 -1758
  427. package/core/blockly.js +0 -890
  428. package/core/blockly.ts +0 -749
  429. package/core/blockly_options.ts +0 -81
  430. package/core/blocks.ts +0 -29
  431. package/core/browser_events.ts +0 -289
  432. package/core/bubble.ts +0 -892
  433. package/core/bubble_dragger.ts +0 -229
  434. package/core/bump_objects.ts +0 -182
  435. package/core/clipboard.ts +0 -91
  436. package/core/comment.ts +0 -398
  437. package/core/common.ts +0 -288
  438. package/core/component_manager.ts +0 -211
  439. package/core/config.ts +0 -80
  440. package/core/connection.ts +0 -692
  441. package/core/connection_checker.ts +0 -301
  442. package/core/connection_db.ts +0 -289
  443. package/core/connection_type.ts +0 -32
  444. package/core/constants.ts +0 -29
  445. package/core/contextmenu.ts +0 -363
  446. package/core/contextmenu_items.ts +0 -576
  447. package/core/contextmenu_registry.ts +0 -179
  448. package/core/css.ts +0 -560
  449. package/core/delete_area.ts +0 -82
  450. package/core/dialog.ts +0 -127
  451. package/core/drag_target.ts +0 -94
  452. package/core/dropdowndiv.ts +0 -683
  453. package/core/events/events.ts +0 -123
  454. package/core/events/events_abstract.ts +0 -112
  455. package/core/events/events_block_base.ts +0 -65
  456. package/core/events/events_block_change.ts +0 -176
  457. package/core/events/events_block_create.ts +0 -114
  458. package/core/events/events_block_delete.ts +0 -126
  459. package/core/events/events_block_drag.ts +0 -82
  460. package/core/events/events_block_move.ts +0 -206
  461. package/core/events/events_bubble_open.ts +0 -82
  462. package/core/events/events_click.ts +0 -84
  463. package/core/events/events_comment_base.ts +0 -107
  464. package/core/events/events_comment_change.ts +0 -108
  465. package/core/events/events_comment_create.ts +0 -82
  466. package/core/events/events_comment_delete.ts +0 -77
  467. package/core/events/events_comment_move.ts +0 -154
  468. package/core/events/events_marker_move.ts +0 -99
  469. package/core/events/events_selected.ts +0 -78
  470. package/core/events/events_theme_change.ts +0 -67
  471. package/core/events/events_toolbox_item_select.ts +0 -79
  472. package/core/events/events_trashcan_open.ts +0 -68
  473. package/core/events/events_ui.ts +0 -89
  474. package/core/events/events_ui_base.ts +0 -54
  475. package/core/events/events_var_base.ts +0 -65
  476. package/core/events/events_var_create.ts +0 -88
  477. package/core/events/events_var_delete.ts +0 -88
  478. package/core/events/events_var_rename.ts +0 -89
  479. package/core/events/events_viewport.ts +0 -100
  480. package/core/events/utils.ts +0 -529
  481. package/core/events/workspace_events.ts +0 -86
  482. package/core/extensions.ts +0 -504
  483. package/core/field.ts +0 -1206
  484. package/core/field_angle.ts +0 -563
  485. package/core/field_checkbox.ts +0 -243
  486. package/core/field_colour.ts +0 -632
  487. package/core/field_dropdown.ts +0 -773
  488. package/core/field_image.ts +0 -282
  489. package/core/field_label.ts +0 -152
  490. package/core/field_label_serializable.ts +0 -76
  491. package/core/field_multilineinput.ts +0 -466
  492. package/core/field_number.ts +0 -327
  493. package/core/field_registry.ts +0 -87
  494. package/core/field_textinput.ts +0 -591
  495. package/core/field_variable.ts +0 -545
  496. package/core/flyout_base.ts +0 -1165
  497. package/core/flyout_button.ts +0 -292
  498. package/core/flyout_horizontal.ts +0 -381
  499. package/core/flyout_metrics_manager.ts +0 -94
  500. package/core/flyout_vertical.ts +0 -384
  501. package/core/generator.ts +0 -539
  502. package/core/gesture.ts +0 -946
  503. package/core/grid.ts +0 -192
  504. package/core/icon.ts +0 -189
  505. package/core/inject.ts +0 -390
  506. package/core/input.ts +0 -309
  507. package/core/input_types.ts +0 -32
  508. package/core/insertion_marker_manager.ts +0 -788
  509. package/core/interfaces/i_ast_node_location.ts +0 -23
  510. package/core/interfaces/i_ast_node_location_svg.ts +0 -37
  511. package/core/interfaces/i_ast_node_location_with_block.ts +0 -38
  512. package/core/interfaces/i_autohideable.ts +0 -34
  513. package/core/interfaces/i_block_dragger.ts +0 -67
  514. package/core/interfaces/i_bounded_element.ts +0 -42
  515. package/core/interfaces/i_bubble.ts +0 -88
  516. package/core/interfaces/i_collapsible_toolbox_item.ts +0 -47
  517. package/core/interfaces/i_component.ts +0 -32
  518. package/core/interfaces/i_connection_checker.ts +0 -102
  519. package/core/interfaces/i_contextmenu.ts +0 -26
  520. package/core/interfaces/i_copyable.ts +0 -40
  521. package/core/interfaces/i_deletable.ts +0 -29
  522. package/core/interfaces/i_delete_area.ts +0 -46
  523. package/core/interfaces/i_drag_target.ts +0 -84
  524. package/core/interfaces/i_draggable.ts +0 -25
  525. package/core/interfaces/i_flyout.ts +0 -186
  526. package/core/interfaces/i_keyboard_accessible.ts +0 -35
  527. package/core/interfaces/i_metrics_manager.ts +0 -151
  528. package/core/interfaces/i_movable.ts +0 -29
  529. package/core/interfaces/i_positionable.ts +0 -50
  530. package/core/interfaces/i_registrable.ts +0 -25
  531. package/core/interfaces/i_registrable_field.ts +0 -31
  532. package/core/interfaces/i_selectable.ts +0 -34
  533. package/core/interfaces/i_selectable_toolbox_item.ts +0 -64
  534. package/core/interfaces/i_serializer.ts +0 -65
  535. package/core/interfaces/i_styleable.ts +0 -35
  536. package/core/interfaces/i_toolbox.ts +0 -127
  537. package/core/interfaces/i_toolbox_item.ts +0 -84
  538. package/core/internal_constants.ts +0 -67
  539. package/core/keyboard_nav/ast_node.ts +0 -717
  540. package/core/keyboard_nav/basic_cursor.ts +0 -214
  541. package/core/keyboard_nav/cursor.ts +0 -134
  542. package/core/keyboard_nav/marker.ts +0 -115
  543. package/core/keyboard_nav/tab_navigate_cursor.ts +0 -48
  544. package/core/main.js +0 -303
  545. package/core/marker_manager.ts +0 -181
  546. package/core/menu.ts +0 -449
  547. package/core/menuitem.ts +0 -240
  548. package/core/metrics_manager.ts +0 -456
  549. package/core/msg.ts +0 -20
  550. package/core/mutator.ts +0 -560
  551. package/core/names.ts +0 -267
  552. package/core/options.ts +0 -365
  553. package/core/positionable_helpers.ts +0 -181
  554. package/core/procedures.ts +0 -443
  555. package/core/registry.ts +0 -339
  556. package/core/rendered_connection.ts +0 -568
  557. package/core/renderers/common/block_rendering.ts +0 -164
  558. package/core/renderers/common/constants.ts +0 -1124
  559. package/core/renderers/common/debug.ts +0 -61
  560. package/core/renderers/common/debugger.ts +0 -433
  561. package/core/renderers/common/drawer.ts +0 -450
  562. package/core/renderers/common/i_path_object.ts +0 -161
  563. package/core/renderers/common/info.ts +0 -718
  564. package/core/renderers/common/marker_svg.ts +0 -680
  565. package/core/renderers/common/path_object.ts +0 -272
  566. package/core/renderers/common/renderer.ts +0 -271
  567. package/core/renderers/geras/constants.ts +0 -61
  568. package/core/renderers/geras/drawer.ts +0 -176
  569. package/core/renderers/geras/geras.ts +0 -37
  570. package/core/renderers/geras/highlight_constants.ts +0 -337
  571. package/core/renderers/geras/highlighter.ts +0 -306
  572. package/core/renderers/geras/info.ts +0 -450
  573. package/core/renderers/geras/measurables/inline_input.ts +0 -51
  574. package/core/renderers/geras/measurables/statement_input.ts +0 -50
  575. package/core/renderers/geras/path_object.ts +0 -138
  576. package/core/renderers/geras/renderer.ts +0 -126
  577. package/core/renderers/measurables/base.ts +0 -53
  578. package/core/renderers/measurables/bottom_row.ts +0 -120
  579. package/core/renderers/measurables/connection.ts +0 -52
  580. package/core/renderers/measurables/external_value_input.ts +0 -65
  581. package/core/renderers/measurables/field.ts +0 -63
  582. package/core/renderers/measurables/hat.ts +0 -48
  583. package/core/renderers/measurables/icon.ts +0 -54
  584. package/core/renderers/measurables/in_row_spacer.ts +0 -44
  585. package/core/renderers/measurables/inline_input.ts +0 -76
  586. package/core/renderers/measurables/input_connection.ts +0 -66
  587. package/core/renderers/measurables/input_row.ts +0 -82
  588. package/core/renderers/measurables/jagged_edge.ts +0 -43
  589. package/core/renderers/measurables/next_connection.ts +0 -47
  590. package/core/renderers/measurables/output_connection.ts +0 -56
  591. package/core/renderers/measurables/previous_connection.ts +0 -47
  592. package/core/renderers/measurables/round_corner.ts +0 -49
  593. package/core/renderers/measurables/row.ts +0 -225
  594. package/core/renderers/measurables/spacer_row.ts +0 -55
  595. package/core/renderers/measurables/square_corner.ts +0 -47
  596. package/core/renderers/measurables/statement_input.ts +0 -55
  597. package/core/renderers/measurables/top_row.ts +0 -122
  598. package/core/renderers/measurables/types.ts +0 -332
  599. package/core/renderers/minimalist/constants.ts +0 -32
  600. package/core/renderers/minimalist/drawer.ts +0 -38
  601. package/core/renderers/minimalist/info.ts +0 -52
  602. package/core/renderers/minimalist/minimalist.ts +0 -22
  603. package/core/renderers/minimalist/renderer.ts +0 -71
  604. package/core/renderers/thrasos/info.ts +0 -338
  605. package/core/renderers/thrasos/renderer.ts +0 -48
  606. package/core/renderers/thrasos/thrasos.ts +0 -20
  607. package/core/renderers/zelos/constants.ts +0 -858
  608. package/core/renderers/zelos/drawer.ts +0 -228
  609. package/core/renderers/zelos/info.ts +0 -593
  610. package/core/renderers/zelos/marker_svg.ts +0 -151
  611. package/core/renderers/zelos/measurables/bottom_row.ts +0 -53
  612. package/core/renderers/zelos/measurables/inputs.ts +0 -56
  613. package/core/renderers/zelos/measurables/row_elements.ts +0 -45
  614. package/core/renderers/zelos/measurables/top_row.ts +0 -58
  615. package/core/renderers/zelos/path_object.ts +0 -215
  616. package/core/renderers/zelos/renderer.ts +0 -142
  617. package/core/renderers/zelos/zelos.ts +0 -39
  618. package/core/scrollbar.ts +0 -870
  619. package/core/scrollbar_pair.ts +0 -321
  620. package/core/serialization/blocks.ts +0 -706
  621. package/core/serialization/exceptions.ts +0 -98
  622. package/core/serialization/priorities.ts +0 -32
  623. package/core/serialization/registry.ts +0 -43
  624. package/core/serialization/variables.ts +0 -96
  625. package/core/serialization/workspaces.ts +0 -106
  626. package/core/shortcut_items.ts +0 -266
  627. package/core/shortcut_registry.ts +0 -355
  628. package/core/sprites.ts +0 -29
  629. package/core/theme/classic.ts +0 -54
  630. package/core/theme/themes.ts +0 -22
  631. package/core/theme/zelos.ts +0 -91
  632. package/core/theme.ts +0 -221
  633. package/core/theme_manager.ts +0 -186
  634. package/core/toolbox/category.ts +0 -679
  635. package/core/toolbox/collapsible_category.ts +0 -273
  636. package/core/toolbox/separator.ts +0 -105
  637. package/core/toolbox/toolbox.ts +0 -1044
  638. package/core/toolbox/toolbox_item.ts +0 -147
  639. package/core/tooltip.ts +0 -463
  640. package/core/touch.ts +0 -306
  641. package/core/touch_gesture.ts +0 -295
  642. package/core/trashcan.ts +0 -671
  643. package/core/utils/aria.ts +0 -160
  644. package/core/utils/array.ts +0 -32
  645. package/core/utils/colour.ts +0 -276
  646. package/core/utils/coordinate.ts +0 -124
  647. package/core/utils/deprecation.ts +0 -41
  648. package/core/utils/dom.ts +0 -408
  649. package/core/utils/idgenerator.ts +0 -80
  650. package/core/utils/keycodes.ts +0 -169
  651. package/core/utils/math.ts +0 -61
  652. package/core/utils/metrics.ts +0 -97
  653. package/core/utils/object.ts +0 -95
  654. package/core/utils/parsing.ts +0 -261
  655. package/core/utils/rect.ts +0 -62
  656. package/core/utils/sentinel.ts +0 -23
  657. package/core/utils/size.ts +0 -51
  658. package/core/utils/string.ts +0 -308
  659. package/core/utils/style.ts +0 -306
  660. package/core/utils/svg.ts +0 -88
  661. package/core/utils/svg_math.ts +0 -269
  662. package/core/utils/svg_paths.ts +0 -140
  663. package/core/utils/toolbox.ts +0 -433
  664. package/core/utils/useragent.ts +0 -135
  665. package/core/utils/xml.ts +0 -97
  666. package/core/utils.ts +0 -428
  667. package/core/variable_map.ts +0 -392
  668. package/core/variable_model.ts +0 -82
  669. package/core/variables.ts +0 -596
  670. package/core/variables_dynamic.ts +0 -133
  671. package/core/warning.ts +0 -161
  672. package/core/widgetdiv.ts +0 -257
  673. package/core/workspace.ts +0 -801
  674. package/core/workspace_audio.ts +0 -156
  675. package/core/workspace_comment.ts +0 -398
  676. package/core/workspace_comment_svg.ts +0 -1127
  677. package/core/workspace_drag_surface_svg.ts +0 -187
  678. package/core/workspace_dragger.ts +0 -104
  679. package/core/workspace_svg.ts +0 -2655
  680. package/core/xml.ts +0 -1023
  681. package/core/zoom_controls.ts +0 -441
  682. package/generators/dart/all.js +0 -27
  683. package/generators/dart/colour.js +0 -105
  684. package/generators/dart/lists.js +0 -431
  685. package/generators/dart/logic.js +0 -123
  686. package/generators/dart/loops.js +0 -161
  687. package/generators/dart/math.js +0 -446
  688. package/generators/dart/procedures.js +0 -105
  689. package/generators/dart/text.js +0 -338
  690. package/generators/dart/variables.js +0 -32
  691. package/generators/dart/variables_dynamic.js +0 -21
  692. package/generators/dart.js +0 -303
  693. package/generators/javascript/all.js +0 -27
  694. package/generators/javascript/colour.js +0 -85
  695. package/generators/javascript/lists.js +0 -405
  696. package/generators/javascript/logic.js +0 -127
  697. package/generators/javascript/loops.js +0 -180
  698. package/generators/javascript/math.js +0 -401
  699. package/generators/javascript/procedures.js +0 -110
  700. package/generators/javascript/text.js +0 -371
  701. package/generators/javascript/variables.js +0 -32
  702. package/generators/javascript/variables_dynamic.js +0 -21
  703. package/generators/javascript.js +0 -322
  704. package/generators/lua/all.js +0 -27
  705. package/generators/lua/colour.js +0 -71
  706. package/generators/lua/lists.js +0 -348
  707. package/generators/lua/logic.js +0 -112
  708. package/generators/lua/loops.js +0 -168
  709. package/generators/lua/math.js +0 -406
  710. package/generators/lua/procedures.js +0 -106
  711. package/generators/lua/text.js +0 -327
  712. package/generators/lua/variables.js +0 -31
  713. package/generators/lua/variables_dynamic.js +0 -21
  714. package/generators/lua.js +0 -206
  715. package/generators/php/all.js +0 -27
  716. package/generators/php/colour.js +0 -81
  717. package/generators/php/lists.js +0 -481
  718. package/generators/php/logic.js +0 -119
  719. package/generators/php/loops.js +0 -161
  720. package/generators/php/math.js +0 -349
  721. package/generators/php/procedures.js +0 -125
  722. package/generators/php/text.js +0 -255
  723. package/generators/php/variables.js +0 -32
  724. package/generators/php/variables_dynamic.js +0 -21
  725. package/generators/php.js +0 -303
  726. package/generators/python/all.js +0 -27
  727. package/generators/python/colour.js +0 -67
  728. package/generators/python/lists.js +0 -346
  729. package/generators/python/logic.js +0 -120
  730. package/generators/python/loops.js +0 -206
  731. package/generators/python/math.js +0 -373
  732. package/generators/python/procedures.js +0 -129
  733. package/generators/python/text.js +0 -291
  734. package/generators/python/variables.js +0 -32
  735. package/generators/python/variables_dynamic.js +0 -21
  736. package/generators/python.js +0 -333
package/core/xml.ts DELETED
@@ -1,1023 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2012 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- /**
8
- * @fileoverview XML reader and writer.
9
- */
10
-
11
- /**
12
- * XML reader and writer.
13
- * @namespace Blockly.Xml
14
- */
15
- import * as goog from '../closure/goog/goog.js';
16
- goog.declareModuleId('Blockly.Xml');
17
-
18
- // Unused import preserved for side-effects. Remove if unneeded.
19
- // import './comment.js';
20
- // Unused import preserved for side-effects. Remove if unneeded.
21
- // import './variables.js';
22
- // Unused import preserved for side-effects. Remove if unneeded.
23
- // import './workspace_comment.js';
24
- // Unused import preserved for side-effects. Remove if unneeded.
25
- // import './workspace_comment_svg.js';
26
-
27
- import type {Block} from './block.js';
28
- import type {BlockSvg} from './block_svg.js';
29
- import type {Connection} from './connection.js';
30
- import * as eventUtils from './events/utils.js';
31
- import type {Field} from './field.js';
32
- import {inputTypes} from './input_types.js';
33
- import * as dom from './utils/dom.js';
34
- import {Size} from './utils/size.js';
35
- import * as utilsXml from './utils/xml.js';
36
- import type {VariableModel} from './variable_model.js';
37
- import * as Variables from './variables.js';
38
- import type {Workspace} from './workspace.js';
39
- import {WorkspaceComment} from './workspace_comment.js';
40
- import {WorkspaceCommentSvg} from './workspace_comment_svg.js';
41
- import type {WorkspaceSvg} from './workspace_svg.js';
42
-
43
-
44
- /**
45
- * Encode a block tree as XML.
46
- * @param workspace The workspace containing blocks.
47
- * @param opt_noId True if the encoder should skip the block IDs.
48
- * @return XML DOM element.
49
- * @alias Blockly.Xml.workspaceToDom
50
- */
51
- export function workspaceToDom(
52
- workspace: Workspace, opt_noId?: boolean): Element {
53
- const treeXml = utilsXml.createElement('xml');
54
- const variablesElement =
55
- variablesToDom(Variables.allUsedVarModels(workspace));
56
- if (variablesElement.hasChildNodes()) {
57
- treeXml.appendChild(variablesElement);
58
- }
59
- const comments = workspace.getTopComments(true);
60
- for (let i = 0; i < comments.length; i++) {
61
- const comment = comments[i];
62
- treeXml.appendChild(comment.toXmlWithXY(opt_noId));
63
- }
64
- const blocks = workspace.getTopBlocks(true);
65
- for (let i = 0; i < blocks.length; i++) {
66
- const block = blocks[i];
67
- treeXml.appendChild(blockToDomWithXY(block, opt_noId));
68
- }
69
- return treeXml;
70
- }
71
-
72
- /**
73
- * Encode a list of variables as XML.
74
- * @param variableList List of all variable models.
75
- * @return Tree of XML elements.
76
- * @alias Blockly.Xml.variablesToDom
77
- */
78
- export function variablesToDom(variableList: VariableModel[]): Element {
79
- const variables = utilsXml.createElement('variables');
80
- for (let i = 0; i < variableList.length; i++) {
81
- const variable = variableList[i];
82
- const element = utilsXml.createElement('variable');
83
- element.appendChild(utilsXml.createTextNode(variable.name));
84
- if (variable.type) {
85
- element.setAttribute('type', variable.type);
86
- }
87
- element.id = variable.getId();
88
- variables.appendChild(element);
89
- }
90
- return variables;
91
- }
92
-
93
- /**
94
- * Encode a block subtree as XML with XY coordinates.
95
- * @param block The root block to encode.
96
- * @param opt_noId True if the encoder should skip the block ID.
97
- * @return Tree of XML elements or an empty document fragment if the block was
98
- * an insertion marker.
99
- * @alias Blockly.Xml.blockToDomWithXY
100
- */
101
- export function blockToDomWithXY(block: Block, opt_noId?: boolean): Element|
102
- DocumentFragment {
103
- if (block.isInsertionMarker()) { // Skip over insertion markers.
104
- block = block.getChildren(false)[0];
105
- if (!block) {
106
- // Disappears when appended.
107
- return new DocumentFragment();
108
- }
109
- }
110
-
111
- let width = 0; // Not used in LTR.
112
- if (block.workspace.RTL) {
113
- width = block.workspace.getWidth();
114
- }
115
-
116
- const element = blockToDom(block, opt_noId);
117
- const xy = block.getRelativeToSurfaceXY();
118
- // AnyDuringMigration because: Property 'setAttribute' does not exist on type
119
- // 'Element | DocumentFragment'.
120
- (element as AnyDuringMigration)
121
- .setAttribute('x', Math.round(block.workspace.RTL ? width - xy.x : xy.x));
122
- // AnyDuringMigration because: Property 'setAttribute' does not exist on type
123
- // 'Element | DocumentFragment'.
124
- (element as AnyDuringMigration).setAttribute('y', Math.round(xy.y));
125
- return element;
126
- }
127
-
128
- /**
129
- * Encode a field as XML.
130
- * @param field The field to encode.
131
- * @return XML element, or null if the field did not need to be serialized.
132
- */
133
- function fieldToDom(field: Field): Element|null {
134
- if (field.isSerializable()) {
135
- const container = utilsXml.createElement('field');
136
- container.setAttribute('name', field.name || '');
137
- return field.toXml(container);
138
- }
139
- return null;
140
- }
141
-
142
- /**
143
- * Encode all of a block's fields as XML and attach them to the given tree of
144
- * XML elements.
145
- * @param block A block with fields to be encoded.
146
- * @param element The XML element to which the field DOM should be attached.
147
- */
148
- function allFieldsToDom(block: Block, element: Element) {
149
- for (let i = 0; i < block.inputList.length; i++) {
150
- const input = block.inputList[i];
151
- for (let j = 0; j < input.fieldRow.length; j++) {
152
- const field = input.fieldRow[j];
153
- const fieldDom = fieldToDom(field);
154
- if (fieldDom) {
155
- element.appendChild(fieldDom);
156
- }
157
- }
158
- }
159
- }
160
-
161
- /**
162
- * Encode a block subtree as XML.
163
- * @param block The root block to encode.
164
- * @param opt_noId True if the encoder should skip the block ID.
165
- * @return Tree of XML elements or an empty document fragment if the block was
166
- * an insertion marker.
167
- * @alias Blockly.Xml.blockToDom
168
- */
169
- export function blockToDom(block: Block, opt_noId?: boolean): Element|
170
- DocumentFragment {
171
- // Skip over insertion markers.
172
- if (block.isInsertionMarker()) {
173
- const child = block.getChildren(false)[0];
174
- if (child) {
175
- return blockToDom(child);
176
- } else {
177
- // Disappears when appended.
178
- return new DocumentFragment();
179
- }
180
- }
181
-
182
- const element = utilsXml.createElement(block.isShadow() ? 'shadow' : 'block');
183
- element.setAttribute('type', block.type);
184
- if (!opt_noId) {
185
- // It's important to use setAttribute here otherwise IE11 won't serialize
186
- // the block's ID when domToText is called.
187
- element.setAttribute('id', block.id);
188
- }
189
- if (block.mutationToDom) {
190
- // Custom data for an advanced block.
191
- const mutation = block.mutationToDom();
192
- if (mutation && (mutation.hasChildNodes() || mutation.hasAttributes())) {
193
- element.appendChild(mutation);
194
- }
195
- }
196
-
197
- allFieldsToDom(block, element);
198
-
199
- const commentText = block.getCommentText();
200
- if (commentText) {
201
- const size = block.commentModel.size;
202
- const pinned = block.commentModel.pinned;
203
-
204
- const commentElement = utilsXml.createElement('comment');
205
- commentElement.appendChild(utilsXml.createTextNode(commentText));
206
- // AnyDuringMigration because: Argument of type 'boolean' is not assignable
207
- // to parameter of type 'string'.
208
- commentElement.setAttribute('pinned', pinned as AnyDuringMigration);
209
- // AnyDuringMigration because: Argument of type 'number' is not assignable
210
- // to parameter of type 'string'.
211
- commentElement.setAttribute('h', size.height as AnyDuringMigration);
212
- // AnyDuringMigration because: Argument of type 'number' is not assignable
213
- // to parameter of type 'string'.
214
- commentElement.setAttribute('w', size.width as AnyDuringMigration);
215
-
216
- element.appendChild(commentElement);
217
- }
218
-
219
- if (block.data) {
220
- const dataElement = utilsXml.createElement('data');
221
- dataElement.appendChild(utilsXml.createTextNode(block.data));
222
- element.appendChild(dataElement);
223
- }
224
-
225
- for (let i = 0; i < block.inputList.length; i++) {
226
- const input = block.inputList[i];
227
- let container: Element;
228
- let empty = true;
229
- if (input.type === inputTypes.DUMMY) {
230
- continue;
231
- } else {
232
- const childBlock = input.connection!.targetBlock();
233
- if (input.type === inputTypes.VALUE) {
234
- container = utilsXml.createElement('value');
235
- } else if (input.type === inputTypes.STATEMENT) {
236
- container = utilsXml.createElement('statement');
237
- }
238
- const childShadow = input.connection!.getShadowDom();
239
- if (childShadow && (!childBlock || !childBlock.isShadow())) {
240
- container!.appendChild(cloneShadow(childShadow, opt_noId));
241
- }
242
- if (childBlock) {
243
- const childElem = blockToDom(childBlock, opt_noId);
244
- if (childElem.nodeType === dom.NodeType.ELEMENT_NODE) {
245
- container!.appendChild(childElem);
246
- empty = false;
247
- }
248
- }
249
- }
250
- container!.setAttribute('name', input.name);
251
- if (!empty) {
252
- element.appendChild(container!);
253
- }
254
- }
255
- if (block.inputsInline !== undefined &&
256
- block.inputsInline !== block.inputsInlineDefault) {
257
- element.setAttribute('inline', block.inputsInline.toString());
258
- }
259
- if (block.isCollapsed()) {
260
- element.setAttribute('collapsed', 'true');
261
- }
262
- if (!block.isEnabled()) {
263
- element.setAttribute('disabled', 'true');
264
- }
265
- if (!block.isDeletable() && !block.isShadow()) {
266
- element.setAttribute('deletable', 'false');
267
- }
268
- if (!block.isMovable() && !block.isShadow()) {
269
- element.setAttribute('movable', 'false');
270
- }
271
- if (!block.isEditable()) {
272
- element.setAttribute('editable', 'false');
273
- }
274
-
275
- const nextBlock = block.getNextBlock();
276
- let container: Element;
277
- if (nextBlock) {
278
- const nextElem = blockToDom(nextBlock, opt_noId);
279
- if (nextElem.nodeType === dom.NodeType.ELEMENT_NODE) {
280
- container = utilsXml.createElement('next');
281
- container.appendChild(nextElem);
282
- element.appendChild(container);
283
- }
284
- }
285
- const nextShadow =
286
- block.nextConnection && block.nextConnection.getShadowDom();
287
- if (nextShadow && (!nextBlock || !nextBlock.isShadow())) {
288
- container!.appendChild(cloneShadow(nextShadow, opt_noId));
289
- }
290
-
291
- return element;
292
- }
293
-
294
- /**
295
- * Deeply clone the shadow's DOM so that changes don't back-wash to the block.
296
- * @param shadow A tree of XML elements.
297
- * @param opt_noId True if the encoder should skip the block ID.
298
- * @return A tree of XML elements.
299
- */
300
- function cloneShadow(shadow: Element, opt_noId?: boolean): Element {
301
- shadow = shadow.cloneNode(true) as Element;
302
- // Walk the tree looking for whitespace. Don't prune whitespace in a tag.
303
- let node: Node|null = shadow;
304
- let textNode;
305
- while (node) {
306
- if (opt_noId && node.nodeName === 'shadow') {
307
- // Strip off IDs from shadow blocks. There should never be a 'block' as
308
- // a child of a 'shadow', so no need to check that.
309
- (node as Element).removeAttribute('id');
310
- }
311
- if (node.firstChild) {
312
- node = node.firstChild;
313
- } else {
314
- while (node && !node.nextSibling) {
315
- textNode = node;
316
- node = node.parentNode;
317
- if (textNode.nodeType === dom.NodeType.TEXT_NODE &&
318
- (textNode as Text).data.trim() === '' &&
319
- node?.firstChild !== textNode) {
320
- // Prune whitespace after a tag.
321
- dom.removeNode(textNode);
322
- }
323
- }
324
- if (node) {
325
- textNode = node;
326
- node = node.nextSibling;
327
- if (textNode.nodeType === dom.NodeType.TEXT_NODE &&
328
- (textNode as Text).data.trim() === '') {
329
- // Prune whitespace before a tag.
330
- dom.removeNode(textNode);
331
- }
332
- }
333
- }
334
- }
335
- return shadow;
336
- }
337
-
338
- /**
339
- * Converts a DOM structure into plain text.
340
- * Currently the text format is fairly ugly: all one line with no whitespace,
341
- * unless the DOM itself has whitespace built-in.
342
- * @param dom A tree of XML nodes.
343
- * @return Text representation.
344
- * @alias Blockly.Xml.domToText
345
- */
346
- export function domToText(dom: Node): string {
347
- const text = utilsXml.domToText(dom);
348
- // Unpack self-closing tags. These tags fail when embedded in HTML.
349
- // <block name="foo"/> -> <block name="foo"></block>
350
- return text.replace(/<(\w+)([^<]*)\/>/g, '<$1$2></$1>');
351
- }
352
-
353
- /**
354
- * Converts a DOM structure into properly indented text.
355
- * @param dom A tree of XML elements.
356
- * @return Text representation.
357
- * @alias Blockly.Xml.domToPrettyText
358
- */
359
- export function domToPrettyText(dom: Node): string {
360
- // This function is not guaranteed to be correct for all XML.
361
- // But it handles the XML that Blockly generates.
362
- const blob = domToText(dom);
363
- // Place every open and close tag on its own line.
364
- const lines = blob.split('<');
365
- // Indent every line.
366
- let indent = '';
367
- for (let i = 1; i < lines.length; i++) {
368
- const line = lines[i];
369
- if (line[0] === '/') {
370
- indent = indent.substring(2);
371
- }
372
- lines[i] = indent + '<' + line;
373
- if (line[0] !== '/' && line.slice(-2) !== '/>') {
374
- indent += ' ';
375
- }
376
- }
377
- // Pull simple tags back together.
378
- // E.g. <foo></foo>
379
- let text = lines.join('\n');
380
- text = text.replace(/(<(\w+)\b[^>]*>[^\n]*)\n *<\/\2>/g, '$1</$2>');
381
- // Trim leading blank line.
382
- return text.replace(/^\n/, '');
383
- }
384
-
385
- /**
386
- * Converts an XML string into a DOM structure.
387
- * @param text An XML string.
388
- * @return A DOM object representing the singular child of the document element.
389
- * @throws if the text doesn't parse.
390
- * @alias Blockly.Xml.textToDom
391
- */
392
- export function textToDom(text: string): Element {
393
- const doc = utilsXml.textToDomDocument(text);
394
- if (!doc || !doc.documentElement ||
395
- doc.getElementsByTagName('parsererror').length) {
396
- throw Error('textToDom was unable to parse: ' + text);
397
- }
398
- return doc.documentElement;
399
- }
400
-
401
- /**
402
- * Clear the given workspace then decode an XML DOM and
403
- * create blocks on the workspace.
404
- * @param xml XML DOM.
405
- * @param workspace The workspace.
406
- * @return An array containing new block IDs.
407
- * @alias Blockly.Xml.clearWorkspaceAndLoadFromXml
408
- */
409
- export function clearWorkspaceAndLoadFromXml(
410
- xml: Element, workspace: WorkspaceSvg): string[] {
411
- workspace.setResizesEnabled(false);
412
- workspace.clear();
413
- // AnyDuringMigration because: Argument of type 'WorkspaceSvg' is not
414
- // assignable to parameter of type 'Workspace'.
415
- const blockIds = domToWorkspace(xml, workspace as AnyDuringMigration);
416
- workspace.setResizesEnabled(true);
417
- return blockIds;
418
- }
419
-
420
- /**
421
- * Decode an XML DOM and create blocks on the workspace.
422
- * @param xml XML DOM.
423
- * @param workspace The workspace.
424
- * @return An array containing new block IDs.
425
- * @suppress {strictModuleDepCheck} Suppress module check while workspace
426
- * comments are not bundled in.
427
- * @alias Blockly.Xml.domToWorkspace
428
- */
429
- export function domToWorkspace(xml: Element, workspace: Workspace): string[] {
430
- let width = 0; // Not used in LTR.
431
- if (workspace.RTL) {
432
- width = workspace.getWidth();
433
- }
434
- const newBlockIds = []; // A list of block IDs added by this call.
435
- dom.startTextWidthCache();
436
- const existingGroup = eventUtils.getGroup();
437
- if (!existingGroup) {
438
- eventUtils.setGroup(true);
439
- }
440
-
441
- // Disable workspace resizes as an optimization.
442
- // Assume it is rendered so we can check.
443
- if ((workspace as WorkspaceSvg).setResizesEnabled) {
444
- (workspace as WorkspaceSvg).setResizesEnabled(false);
445
- }
446
- let variablesFirst = true;
447
- try {
448
- for (let i = 0, xmlChild; xmlChild = xml.childNodes[i]; i++) {
449
- const name = xmlChild.nodeName.toLowerCase();
450
- const xmlChildElement = xmlChild as Element;
451
- if (name === 'block' ||
452
- name === 'shadow' && !eventUtils.getRecordUndo()) {
453
- // Allow top-level shadow blocks if recordUndo is disabled since
454
- // that means an undo is in progress. Such a block is expected
455
- // to be moved to a nested destination in the next operation.
456
- const block = domToBlock(xmlChildElement, workspace);
457
- newBlockIds.push(block.id);
458
- // AnyDuringMigration because: Argument of type 'string | null' is not
459
- // assignable to parameter of type 'string'.
460
- const blockX = xmlChildElement.hasAttribute('x') ?
461
- parseInt(
462
- xmlChildElement.getAttribute('x') as AnyDuringMigration, 10) :
463
- 10;
464
- // AnyDuringMigration because: Argument of type 'string | null' is not
465
- // assignable to parameter of type 'string'.
466
- const blockY = xmlChildElement.hasAttribute('y') ?
467
- parseInt(
468
- xmlChildElement.getAttribute('y') as AnyDuringMigration, 10) :
469
- 10;
470
- if (!isNaN(blockX) && !isNaN(blockY)) {
471
- block.moveBy(workspace.RTL ? width - blockX : blockX, blockY);
472
- }
473
- variablesFirst = false;
474
- } else if (name === 'shadow') {
475
- throw TypeError('Shadow block cannot be a top-level block.');
476
- } else if (name === 'comment') {
477
- if (workspace.rendered) {
478
- WorkspaceCommentSvg.fromXmlRendered(
479
- xmlChildElement, workspace as WorkspaceSvg, width);
480
- } else {
481
- WorkspaceComment.fromXml(xmlChildElement, workspace);
482
- }
483
- } else if (name === 'variables') {
484
- if (variablesFirst) {
485
- domToVariables(xmlChildElement, workspace);
486
- } else {
487
- throw Error(
488
- '\'variables\' tag must exist once before block and ' +
489
- 'shadow tag elements in the workspace XML, but it was found in ' +
490
- 'another location.');
491
- }
492
- variablesFirst = false;
493
- }
494
- }
495
- } finally {
496
- if (!existingGroup) {
497
- eventUtils.setGroup(false);
498
- }
499
- dom.stopTextWidthCache();
500
- }
501
- // Re-enable workspace resizing.
502
- if ((workspace as WorkspaceSvg).setResizesEnabled) {
503
- (workspace as WorkspaceSvg).setResizesEnabled(true);
504
- }
505
- eventUtils.fire(new (eventUtils.get(eventUtils.FINISHED_LOADING))!
506
- (workspace));
507
- return newBlockIds;
508
- }
509
-
510
- /**
511
- * Decode an XML DOM and create blocks on the workspace. Position the new
512
- * blocks immediately below prior blocks, aligned by their starting edge.
513
- * @param xml The XML DOM.
514
- * @param workspace The workspace to add to.
515
- * @return An array containing new block IDs.
516
- * @alias Blockly.Xml.appendDomToWorkspace
517
- */
518
- export function appendDomToWorkspace(
519
- xml: Element, workspace: WorkspaceSvg): string[] {
520
- // First check if we have a WorkspaceSvg, otherwise the blocks have no shape
521
- // and the position does not matter.
522
- // Assume it is rendered so we can check.
523
- if (!(workspace as WorkspaceSvg).getBlocksBoundingBox) {
524
- return domToWorkspace(xml, workspace);
525
- }
526
-
527
- const bbox = (workspace as WorkspaceSvg).getBlocksBoundingBox();
528
- // Load the new blocks into the workspace and get the IDs of the new blocks.
529
- const newBlockIds = domToWorkspace(xml, workspace);
530
- if (bbox && bbox.top !== bbox.bottom) { // Check if any previous block.
531
- let offsetY = 0; // Offset to add to y of the new block.
532
- let offsetX = 0;
533
- const farY = bbox.bottom; // Bottom position.
534
- const topX = workspace.RTL ? bbox.right : bbox.left; // X of bounding box.
535
- // Check position of the new blocks.
536
- let newLeftX = Infinity; // X of top left corner.
537
- let newRightX = -Infinity; // X of top right corner.
538
- let newY = Infinity; // Y of top corner.
539
- const ySeparation = 10;
540
- for (let i = 0; i < newBlockIds.length; i++) {
541
- const blockXY =
542
- workspace.getBlockById(newBlockIds[i])!.getRelativeToSurfaceXY();
543
- if (blockXY.y < newY) {
544
- newY = blockXY.y;
545
- }
546
- if (blockXY.x < newLeftX) { // if we left align also on x
547
- newLeftX = blockXY.x;
548
- }
549
- if (blockXY.x > newRightX) { // if we right align also on x
550
- newRightX = blockXY.x;
551
- }
552
- }
553
- offsetY = farY - newY + ySeparation;
554
- offsetX = workspace.RTL ? topX - newRightX : topX - newLeftX;
555
- for (let i = 0; i < newBlockIds.length; i++) {
556
- const block = workspace.getBlockById(newBlockIds[i]);
557
- block!.moveBy(offsetX, offsetY);
558
- }
559
- }
560
- return newBlockIds;
561
- }
562
-
563
- /**
564
- * Decode an XML block tag and create a block (and possibly sub blocks) on the
565
- * workspace.
566
- * @param xmlBlock XML block element.
567
- * @param workspace The workspace.
568
- * @return The root block created.
569
- * @alias Blockly.Xml.domToBlock
570
- */
571
- export function domToBlock(xmlBlock: Element, workspace: Workspace): Block {
572
- // Create top-level block.
573
- eventUtils.disable();
574
- const variablesBeforeCreation = workspace.getAllVariables();
575
- let topBlock;
576
- try {
577
- topBlock = domToBlockHeadless(xmlBlock, workspace);
578
- // Generate list of all blocks.
579
- if (workspace.rendered) {
580
- const topBlockSvg = topBlock as BlockSvg;
581
- const blocks = topBlock.getDescendants(false);
582
- topBlockSvg.setConnectionTracking(false);
583
- // Render each block.
584
- for (let i = blocks.length - 1; i >= 0; i--) {
585
- (blocks[i] as BlockSvg).initSvg();
586
- }
587
- for (let i = blocks.length - 1; i >= 0; i--) {
588
- (blocks[i] as BlockSvg).render(false);
589
- }
590
- // Populating the connection database may be deferred until after the
591
- // blocks have rendered.
592
- setTimeout(function() {
593
- if (!topBlockSvg.disposed) {
594
- topBlockSvg.setConnectionTracking(true);
595
- }
596
- }, 1);
597
- topBlockSvg.updateDisabled();
598
- // Allow the scrollbars to resize and move based on the new contents.
599
- // TODO(@picklesrus): #387. Remove when domToBlock avoids resizing.
600
- (workspace as WorkspaceSvg).resizeContents();
601
- } else {
602
- const blocks = topBlock.getDescendants(false);
603
- for (let i = blocks.length - 1; i >= 0; i--) {
604
- blocks[i].initModel();
605
- }
606
- }
607
- } finally {
608
- eventUtils.enable();
609
- }
610
- if (eventUtils.isEnabled()) {
611
- // AnyDuringMigration because: Property 'get' does not exist on type
612
- // '(name: string) => void'.
613
- const newVariables =
614
- Variables.getAddedVariables(workspace, variablesBeforeCreation);
615
- // Fire a VarCreate event for each (if any) new variable created.
616
- for (let i = 0; i < newVariables.length; i++) {
617
- const thisVariable = newVariables[i];
618
- eventUtils.fire(new (eventUtils.get(eventUtils.VAR_CREATE))!
619
- (thisVariable));
620
- }
621
- // Block events come after var events, in case they refer to newly created
622
- // variables.
623
- eventUtils.fire(new (eventUtils.get(eventUtils.CREATE))!(topBlock));
624
- }
625
- return topBlock;
626
- }
627
-
628
- /**
629
- * Decode an XML list of variables and add the variables to the workspace.
630
- * @param xmlVariables List of XML variable elements.
631
- * @param workspace The workspace to which the variable should be added.
632
- * @alias Blockly.Xml.domToVariables
633
- */
634
- export function domToVariables(xmlVariables: Element, workspace: Workspace) {
635
- for (let i = 0; i < xmlVariables.children.length; i++) {
636
- const xmlChild = xmlVariables.children[i];
637
- const type = xmlChild.getAttribute('type');
638
- const id = xmlChild.getAttribute('id');
639
- const name = xmlChild.textContent;
640
-
641
- // AnyDuringMigration because: Argument of type 'string | null' is not
642
- // assignable to parameter of type 'string'.
643
- workspace.createVariable(name as AnyDuringMigration, type, id);
644
- }
645
- }
646
-
647
- /** A mapping of nodeName to node for child nodes of xmlBlock. */
648
- interface childNodeTagMap {
649
- mutation: Element[];
650
- comment: Element[];
651
- data: Element[];
652
- field: Element[];
653
- input: Element[];
654
- next: Element[];
655
- }
656
-
657
- /**
658
- * Creates a mapping of childNodes for each supported XML tag for the provided
659
- * xmlBlock. Logs a warning for any encountered unsupported tags.
660
- * @param xmlBlock XML block element.
661
- * @return The childNode map from nodeName to node.
662
- */
663
- function mapSupportedXmlTags(xmlBlock: Element): childNodeTagMap {
664
- const childNodeMap = {
665
- mutation: new Array<Element>(),
666
- comment: new Array<Element>(),
667
- data: new Array<Element>(),
668
- field: new Array<Element>(),
669
- input: new Array<Element>(),
670
- next: new Array<Element>()
671
- };
672
- for (let i = 0; i < xmlBlock.children.length; i++) {
673
- const xmlChild = xmlBlock.children[i];
674
- if (xmlChild.nodeType === dom.NodeType.TEXT_NODE) {
675
- // Ignore any text at the <block> level. It's all whitespace anyway.
676
- continue;
677
- }
678
- switch (xmlChild.nodeName.toLowerCase()) {
679
- case 'mutation':
680
- childNodeMap.mutation.push(xmlChild);
681
- break;
682
- case 'comment':
683
- childNodeMap.comment.push(xmlChild);
684
- break;
685
- case 'data':
686
- childNodeMap.data.push(xmlChild);
687
- break;
688
- case 'title':
689
- // Titles were renamed to field in December 2013.
690
- // Fall through.
691
- case 'field':
692
- childNodeMap.field.push(xmlChild);
693
- break;
694
- case 'value':
695
- case 'statement':
696
- childNodeMap.input.push(xmlChild);
697
- break;
698
- case 'next':
699
- childNodeMap.next.push(xmlChild);
700
- break;
701
- default:
702
- // Unknown tag; ignore. Same principle as HTML parsers.
703
- console.warn('Ignoring unknown tag: ' + xmlChild.nodeName);
704
- }
705
- }
706
- return childNodeMap;
707
- }
708
-
709
- /**
710
- * Applies mutation tag child nodes to the given block.
711
- * @param xmlChildren Child nodes.
712
- * @param block The block to apply the child nodes on.
713
- * @return True if mutation may have added some elements that need
714
- * initialization (requiring initSvg call).
715
- */
716
- function applyMutationTagNodes(xmlChildren: Element[], block: Block): boolean {
717
- let shouldCallInitSvg = false;
718
- for (let i = 0; i < xmlChildren.length; i++) {
719
- const xmlChild = xmlChildren[i];
720
- // Custom data for an advanced block.
721
- if (block.domToMutation) {
722
- block.domToMutation(xmlChild);
723
- if ((block as BlockSvg).initSvg) {
724
- // Mutation may have added some elements that need initializing.
725
- shouldCallInitSvg = true;
726
- }
727
- }
728
- }
729
- return shouldCallInitSvg;
730
- }
731
-
732
- /**
733
- * Applies comment tag child nodes to the given block.
734
- * @param xmlChildren Child nodes.
735
- * @param block The block to apply the child nodes on.
736
- */
737
- function applyCommentTagNodes(xmlChildren: Element[], block: Block) {
738
- for (let i = 0; i < xmlChildren.length; i++) {
739
- const xmlChild = xmlChildren[i];
740
- const text = xmlChild.textContent;
741
- const pinned = xmlChild.getAttribute('pinned') === 'true';
742
- // AnyDuringMigration because: Argument of type 'string | null' is not
743
- // assignable to parameter of type 'string'.
744
- const width =
745
- parseInt(xmlChild.getAttribute('w') as AnyDuringMigration, 10);
746
- // AnyDuringMigration because: Argument of type 'string | null' is not
747
- // assignable to parameter of type 'string'.
748
- const height =
749
- parseInt(xmlChild.getAttribute('h') as AnyDuringMigration, 10);
750
-
751
- block.setCommentText(text);
752
- block.commentModel.pinned = pinned;
753
- if (!isNaN(width) && !isNaN(height)) {
754
- block.commentModel.size = new Size(width, height);
755
- }
756
-
757
- if (pinned && (block as BlockSvg).getCommentIcon && !block.isInFlyout) {
758
- const blockSvg = block as BlockSvg;
759
- setTimeout(function() {
760
- blockSvg.getCommentIcon()!.setVisible(true);
761
- }, 1);
762
- }
763
- }
764
- }
765
-
766
- /**
767
- * Applies data tag child nodes to the given block.
768
- * @param xmlChildren Child nodes.
769
- * @param block The block to apply the child nodes on.
770
- */
771
- function applyDataTagNodes(xmlChildren: Element[], block: Block) {
772
- for (let i = 0; i < xmlChildren.length; i++) {
773
- const xmlChild = xmlChildren[i];
774
- block.data = xmlChild.textContent;
775
- }
776
- }
777
-
778
- /**
779
- * Applies field tag child nodes to the given block.
780
- * @param xmlChildren Child nodes.
781
- * @param block The block to apply the child nodes on.
782
- */
783
- function applyFieldTagNodes(xmlChildren: Element[], block: Block) {
784
- for (let i = 0; i < xmlChildren.length; i++) {
785
- const xmlChild = xmlChildren[i];
786
- const nodeName = xmlChild.getAttribute('name');
787
- // AnyDuringMigration because: Argument of type 'string | null' is not
788
- // assignable to parameter of type 'string'.
789
- domToField(block, nodeName as AnyDuringMigration, xmlChild);
790
- }
791
- }
792
-
793
- /**
794
- * Finds any enclosed blocks or shadows within this XML node.
795
- * @param xmlNode The XML node to extract child block info from.
796
- * @return Any found child block.
797
- */
798
- function findChildBlocks(xmlNode: Element):
799
- {childBlockElement: Element|null, childShadowElement: Element|null} {
800
- const childBlockInfo = {childBlockElement: null, childShadowElement: null};
801
- for (let i = 0; i < xmlNode.childNodes.length; i++) {
802
- const xmlChild = xmlNode.childNodes[i];
803
- if (xmlChild.nodeType === dom.NodeType.ELEMENT_NODE) {
804
- if (xmlChild.nodeName.toLowerCase() === 'block') {
805
- // AnyDuringMigration because: Type 'Element' is not assignable to type
806
- // 'null'.
807
- childBlockInfo.childBlockElement =
808
- xmlChild as Element as AnyDuringMigration;
809
- } else if (xmlChild.nodeName.toLowerCase() === 'shadow') {
810
- // AnyDuringMigration because: Type 'Element' is not assignable to type
811
- // 'null'.
812
- childBlockInfo.childShadowElement =
813
- xmlChild as Element as AnyDuringMigration;
814
- }
815
- }
816
- }
817
- return childBlockInfo;
818
- }
819
- /**
820
- * Applies input child nodes (value or statement) to the given block.
821
- * @param xmlChildren Child nodes.
822
- * @param workspace The workspace containing the given block.
823
- * @param block The block to apply the child nodes on.
824
- * @param prototypeName The prototype name of the block.
825
- */
826
- function applyInputTagNodes(
827
- xmlChildren: Element[], workspace: Workspace, block: Block,
828
- prototypeName: string) {
829
- for (let i = 0; i < xmlChildren.length; i++) {
830
- const xmlChild = xmlChildren[i];
831
- const nodeName = xmlChild.getAttribute('name');
832
- // AnyDuringMigration because: Argument of type 'string | null' is not
833
- // assignable to parameter of type 'string'.
834
- const input = block.getInput(nodeName as AnyDuringMigration);
835
- if (!input) {
836
- console.warn(
837
- 'Ignoring non-existent input ' + nodeName + ' in block ' +
838
- prototypeName);
839
- break;
840
- }
841
- const childBlockInfo = findChildBlocks(xmlChild);
842
- if (childBlockInfo.childBlockElement) {
843
- if (!input.connection) {
844
- throw TypeError('Input connection does not exist.');
845
- }
846
- domToBlockHeadless(
847
- childBlockInfo.childBlockElement, workspace, input.connection, false);
848
- }
849
- // Set shadow after so we don't create a shadow we delete immediately.
850
- if (childBlockInfo.childShadowElement) {
851
- input.connection?.setShadowDom(childBlockInfo.childShadowElement);
852
- }
853
- }
854
- }
855
-
856
- /**
857
- * Applies next child nodes to the given block.
858
- * @param xmlChildren Child nodes.
859
- * @param workspace The workspace containing the given block.
860
- * @param block The block to apply the child nodes on.
861
- */
862
- function applyNextTagNodes(
863
- xmlChildren: Element[], workspace: Workspace, block: Block) {
864
- for (let i = 0; i < xmlChildren.length; i++) {
865
- const xmlChild = xmlChildren[i];
866
- const childBlockInfo = findChildBlocks(xmlChild);
867
- if (childBlockInfo.childBlockElement) {
868
- if (!block.nextConnection) {
869
- throw TypeError('Next statement does not exist.');
870
- }
871
- // If there is more than one XML 'next' tag.
872
- if (block.nextConnection.isConnected()) {
873
- throw TypeError('Next statement is already connected.');
874
- }
875
- // Create child block.
876
- domToBlockHeadless(
877
- childBlockInfo.childBlockElement, workspace, block.nextConnection,
878
- true);
879
- }
880
- // Set shadow after so we don't create a shadow we delete immediately.
881
- if (childBlockInfo.childShadowElement && block.nextConnection) {
882
- block.nextConnection.setShadowDom(childBlockInfo.childShadowElement);
883
- }
884
- }
885
- }
886
-
887
- /**
888
- * Decode an XML block tag and create a block (and possibly sub blocks) on the
889
- * workspace.
890
- * @param xmlBlock XML block element.
891
- * @param workspace The workspace.
892
- * @param parentConnection The parent connection to to connect this block to
893
- * after instantiating.
894
- * @param connectedToParentNext Whether the provided parent connection is a next
895
- * connection, rather than output or statement.
896
- * @return The root block created.
897
- */
898
- function domToBlockHeadless(
899
- xmlBlock: Element, workspace: Workspace, parentConnection?: Connection,
900
- connectedToParentNext?: boolean): Block {
901
- let block = null;
902
- const prototypeName = xmlBlock.getAttribute('type');
903
- if (!prototypeName) {
904
- throw TypeError('Block type unspecified: ' + xmlBlock.outerHTML);
905
- }
906
- const id = xmlBlock.getAttribute('id');
907
- // AnyDuringMigration because: Argument of type 'string | null' is not
908
- // assignable to parameter of type 'string | undefined'.
909
- block = workspace.newBlock(prototypeName, id as AnyDuringMigration);
910
-
911
- // Preprocess childNodes so tags can be processed in a consistent order.
912
- const xmlChildNameMap = mapSupportedXmlTags(xmlBlock);
913
-
914
- const shouldCallInitSvg =
915
- applyMutationTagNodes(xmlChildNameMap.mutation, block);
916
- applyCommentTagNodes(xmlChildNameMap.comment, block);
917
- applyDataTagNodes(xmlChildNameMap.data, block);
918
-
919
- // Connect parent after processing mutation and before setting fields.
920
- if (parentConnection) {
921
- if (connectedToParentNext) {
922
- if (block.previousConnection) {
923
- parentConnection.connect(block.previousConnection);
924
- } else {
925
- throw TypeError('Next block does not have previous statement.');
926
- }
927
- } else {
928
- if (block.outputConnection) {
929
- parentConnection.connect(block.outputConnection);
930
- } else if (block.previousConnection) {
931
- parentConnection.connect(block.previousConnection);
932
- } else {
933
- throw TypeError(
934
- 'Child block does not have output or previous statement.');
935
- }
936
- }
937
- }
938
-
939
- applyFieldTagNodes(xmlChildNameMap.field, block);
940
- applyInputTagNodes(xmlChildNameMap.input, workspace, block, prototypeName);
941
- applyNextTagNodes(xmlChildNameMap.next, workspace, block);
942
-
943
- if (shouldCallInitSvg) {
944
- // This shouldn't even be called here
945
- // (ref: https://github.com/google/blockly/pull/4296#issuecomment-884226021
946
- // But the XML serializer/deserializer is iceboxed so I'm not going to fix
947
- // it.
948
- (block as BlockSvg).initSvg();
949
- }
950
-
951
- const inline = xmlBlock.getAttribute('inline');
952
- if (inline) {
953
- block.setInputsInline(inline === 'true');
954
- }
955
- const disabled = xmlBlock.getAttribute('disabled');
956
- if (disabled) {
957
- block.setEnabled(disabled !== 'true' && disabled !== 'disabled');
958
- }
959
- const deletable = xmlBlock.getAttribute('deletable');
960
- if (deletable) {
961
- block.setDeletable(deletable === 'true');
962
- }
963
- const movable = xmlBlock.getAttribute('movable');
964
- if (movable) {
965
- block.setMovable(movable === 'true');
966
- }
967
- const editable = xmlBlock.getAttribute('editable');
968
- if (editable) {
969
- block.setEditable(editable === 'true');
970
- }
971
- const collapsed = xmlBlock.getAttribute('collapsed');
972
- if (collapsed) {
973
- block.setCollapsed(collapsed === 'true');
974
- }
975
- if (xmlBlock.nodeName.toLowerCase() === 'shadow') {
976
- // Ensure all children are also shadows.
977
- const children = block.getChildren(false);
978
- for (let i = 0; i < children.length; i++) {
979
- const child = children[i];
980
- if (!child.isShadow()) {
981
- throw TypeError('Shadow block not allowed non-shadow child.');
982
- }
983
- }
984
- // Ensure this block doesn't have any variable inputs.
985
- if (block.getVarModels().length) {
986
- throw TypeError('Shadow blocks cannot have variable references.');
987
- }
988
- block.setShadow(true);
989
- }
990
- return block;
991
- }
992
-
993
- /**
994
- * Decode an XML field tag and set the value of that field on the given block.
995
- * @param block The block that is currently being deserialized.
996
- * @param fieldName The name of the field on the block.
997
- * @param xml The field tag to decode.
998
- */
999
- function domToField(block: Block, fieldName: string, xml: Element) {
1000
- const field = block.getField(fieldName);
1001
- if (!field) {
1002
- console.warn(
1003
- 'Ignoring non-existent field ' + fieldName + ' in block ' + block.type);
1004
- return;
1005
- }
1006
- field.fromXml(xml);
1007
- }
1008
-
1009
- /**
1010
- * Remove any 'next' block (statements in a stack).
1011
- * @param xmlBlock XML block element or an empty DocumentFragment if the block
1012
- * was an insertion marker.
1013
- * @alias Blockly.Xml.deleteNext
1014
- */
1015
- export function deleteNext(xmlBlock: Element|DocumentFragment) {
1016
- for (let i = 0; i < xmlBlock.childNodes.length; i++) {
1017
- const child = xmlBlock.childNodes[i];
1018
- if (child.nodeName.toLowerCase() === 'next') {
1019
- xmlBlock.removeChild(child);
1020
- break;
1021
- }
1022
- }
1023
- }