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