blockly 7.20211209.2 → 8.0.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.
Files changed (262) hide show
  1. package/blockly.d.ts +18963 -18432
  2. package/blockly.min.js +852 -844
  3. package/blockly_compressed.js +669 -664
  4. package/blockly_compressed.js.map +1 -1
  5. package/blocks/blocks.js +47 -0
  6. package/blocks/colour.js +13 -3
  7. package/blocks/lists.js +22 -13
  8. package/blocks/logic.js +13 -3
  9. package/blocks/loops.js +24 -11
  10. package/blocks/math.js +12 -3
  11. package/blocks/procedures.js +41 -27
  12. package/blocks/text.js +22 -13
  13. package/blocks/variables.js +14 -3
  14. package/blocks/variables_dynamic.js +13 -3
  15. package/blocks_compressed.js +146 -141
  16. package/blocks_compressed.js.map +1 -1
  17. package/core/block.js +1869 -1814
  18. package/core/block_drag_surface.js +201 -200
  19. package/core/block_dragger.js +377 -373
  20. package/core/block_svg.js +1593 -1479
  21. package/core/blockly.js +8 -22
  22. package/core/blocks.js +9 -2
  23. package/core/browser_events.js +22 -5
  24. package/core/bubble.js +841 -797
  25. package/core/bubble_dragger.js +213 -206
  26. package/core/bump_objects.js +2 -2
  27. package/core/clipboard.js +9 -9
  28. package/core/comment.js +353 -332
  29. package/core/common.js +46 -17
  30. package/core/component_manager.js +181 -174
  31. package/core/config.js +87 -0
  32. package/core/connection.js +595 -584
  33. package/core/connection_checker.js +242 -244
  34. package/core/connection_db.js +235 -230
  35. package/core/contextmenu.js +9 -6
  36. package/core/contextmenu_items.js +1 -2
  37. package/core/contextmenu_registry.js +93 -89
  38. package/core/css.js +474 -474
  39. package/core/delete_area.js +45 -42
  40. package/core/drag_target.js +57 -56
  41. package/core/dropdowndiv.js +153 -163
  42. package/core/events/events.js +2 -2
  43. package/core/events/events_abstract.js +89 -77
  44. package/core/events/events_block_base.js +37 -36
  45. package/core/events/events_block_change.js +130 -124
  46. package/core/events/events_block_create.js +73 -71
  47. package/core/events/events_block_delete.js +84 -82
  48. package/core/events/events_block_drag.js +50 -49
  49. package/core/events/events_block_move.js +147 -140
  50. package/core/events/events_bubble_open.js +51 -50
  51. package/core/events/events_click.js +48 -44
  52. package/core/events/events_comment_base.js +72 -69
  53. package/core/events/events_comment_change.js +63 -61
  54. package/core/events/events_comment_create.js +44 -42
  55. package/core/events/events_comment_delete.js +42 -40
  56. package/core/events/events_comment_move.js +106 -104
  57. package/core/events/events_marker_move.js +65 -64
  58. package/core/events/events_selected.js +46 -45
  59. package/core/events/events_theme_change.js +36 -35
  60. package/core/events/events_toolbox_item_select.js +46 -45
  61. package/core/events/events_trashcan_open.js +37 -36
  62. package/core/events/events_ui.js +47 -46
  63. package/core/events/events_ui_base.js +30 -29
  64. package/core/events/events_var_base.js +37 -36
  65. package/core/events/events_var_create.js +50 -48
  66. package/core/events/events_var_delete.js +50 -48
  67. package/core/events/events_var_rename.js +51 -49
  68. package/core/events/events_viewport.js +66 -65
  69. package/core/events/utils.js +29 -14
  70. package/core/events/workspace_events.js +49 -55
  71. package/core/extensions.js +4 -3
  72. package/core/field.js +1061 -997
  73. package/core/field_angle.js +462 -442
  74. package/core/field_checkbox.js +194 -182
  75. package/core/field_colour.js +519 -505
  76. package/core/field_dropdown.js +617 -598
  77. package/core/field_image.js +229 -220
  78. package/core/field_label.js +102 -91
  79. package/core/field_label_serializable.js +42 -41
  80. package/core/field_multilineinput.js +372 -358
  81. package/core/field_number.js +272 -253
  82. package/core/field_textinput.js +499 -467
  83. package/core/field_variable.js +458 -420
  84. package/core/flyout_base.js +1005 -952
  85. package/core/flyout_button.js +277 -260
  86. package/core/flyout_horizontal.js +304 -302
  87. package/core/flyout_metrics_manager.js +64 -64
  88. package/core/flyout_vertical.js +306 -300
  89. package/core/generator.js +459 -446
  90. package/core/gesture.js +829 -813
  91. package/core/grid.js +166 -163
  92. package/core/icon.js +168 -159
  93. package/core/inject.js +7 -5
  94. package/core/input.js +257 -248
  95. package/core/insertion_marker_manager.js +655 -624
  96. package/core/internal_constants.js +0 -129
  97. package/core/keyboard_nav/ast_node.js +605 -596
  98. package/core/keyboard_nav/basic_cursor.js +166 -165
  99. package/core/keyboard_nav/cursor.js +99 -97
  100. package/core/keyboard_nav/marker.js +83 -79
  101. package/core/keyboard_nav/tab_navigate_cursor.js +18 -23
  102. package/core/marker_manager.js +153 -141
  103. package/core/menu.js +377 -372
  104. package/core/menuitem.js +223 -217
  105. package/core/metrics_manager.js +403 -390
  106. package/core/mutator.js +468 -437
  107. package/core/names.js +229 -188
  108. package/core/options.js +290 -284
  109. package/core/procedures.js +29 -17
  110. package/core/registry.js +19 -16
  111. package/core/rendered_connection.js +482 -463
  112. package/core/renderers/common/block_rendering.js +9 -3
  113. package/core/renderers/common/constants.js +1119 -1112
  114. package/core/renderers/common/debug.js +14 -0
  115. package/core/renderers/common/debugger.js +338 -316
  116. package/core/renderers/common/drawer.js +380 -370
  117. package/core/renderers/common/i_path_object.js +2 -2
  118. package/core/renderers/common/info.js +626 -618
  119. package/core/renderers/common/marker_svg.js +579 -541
  120. package/core/renderers/common/path_object.js +203 -200
  121. package/core/renderers/common/renderer.js +220 -218
  122. package/core/renderers/geras/constants.js +36 -36
  123. package/core/renderers/geras/drawer.js +155 -147
  124. package/core/renderers/geras/highlight_constants.js +244 -238
  125. package/core/renderers/geras/highlighter.js +231 -179
  126. package/core/renderers/geras/info.js +392 -369
  127. package/core/renderers/geras/measurables/inline_input.js +25 -19
  128. package/core/renderers/geras/measurables/statement_input.js +23 -17
  129. package/core/renderers/geras/path_object.js +106 -121
  130. package/core/renderers/geras/renderer.js +96 -98
  131. package/core/renderers/measurables/base.js +30 -18
  132. package/core/renderers/measurables/bottom_row.js +83 -80
  133. package/core/renderers/measurables/connection.js +22 -15
  134. package/core/renderers/measurables/external_value_input.js +35 -22
  135. package/core/renderers/measurables/field.js +35 -20
  136. package/core/renderers/measurables/hat.js +18 -13
  137. package/core/renderers/measurables/icon.js +24 -17
  138. package/core/renderers/measurables/in_row_spacer.js +15 -13
  139. package/core/renderers/measurables/inline_input.js +43 -33
  140. package/core/renderers/measurables/input_connection.js +41 -28
  141. package/core/renderers/measurables/input_row.js +50 -44
  142. package/core/renderers/measurables/jagged_edge.js +14 -12
  143. package/core/renderers/measurables/next_connection.js +16 -14
  144. package/core/renderers/measurables/output_connection.js +26 -20
  145. package/core/renderers/measurables/previous_connection.js +16 -15
  146. package/core/renderers/measurables/round_corner.js +20 -18
  147. package/core/renderers/measurables/row.js +184 -168
  148. package/core/renderers/measurables/spacer_row.js +38 -23
  149. package/core/renderers/measurables/square_corner.js +18 -16
  150. package/core/renderers/measurables/statement_input.js +23 -20
  151. package/core/renderers/measurables/top_row.js +88 -85
  152. package/core/renderers/minimalist/constants.js +8 -7
  153. package/core/renderers/minimalist/drawer.js +11 -10
  154. package/core/renderers/minimalist/info.js +18 -18
  155. package/core/renderers/minimalist/renderer.js +40 -39
  156. package/core/renderers/thrasos/info.js +258 -248
  157. package/core/renderers/thrasos/renderer.js +20 -20
  158. package/core/renderers/zelos/constants.js +898 -873
  159. package/core/renderers/zelos/drawer.js +186 -169
  160. package/core/renderers/zelos/info.js +502 -479
  161. package/core/renderers/zelos/marker_svg.js +129 -115
  162. package/core/renderers/zelos/measurables/bottom_row.js +31 -30
  163. package/core/renderers/zelos/measurables/inputs.js +22 -21
  164. package/core/renderers/zelos/measurables/row_elements.js +14 -13
  165. package/core/renderers/zelos/measurables/top_row.js +34 -33
  166. package/core/renderers/zelos/path_object.js +181 -180
  167. package/core/renderers/zelos/renderer.js +91 -92
  168. package/core/scrollbar.js +759 -713
  169. package/core/scrollbar_pair.js +250 -245
  170. package/core/serialization/blocks.js +19 -9
  171. package/core/serialization/workspaces.js +3 -2
  172. package/core/shortcut_registry.js +286 -277
  173. package/core/sprites.js +31 -0
  174. package/core/theme.js +135 -141
  175. package/core/theme_manager.js +147 -143
  176. package/core/toolbox/category.js +602 -576
  177. package/core/toolbox/collapsible_category.js +226 -227
  178. package/core/toolbox/separator.js +70 -61
  179. package/core/toolbox/toolbox.js +934 -927
  180. package/core/toolbox/toolbox_item.js +115 -99
  181. package/core/tooltip.js +108 -35
  182. package/core/touch.js +8 -3
  183. package/core/touch_gesture.js +254 -251
  184. package/core/trashcan.js +606 -595
  185. package/core/utils/coordinate.js +97 -95
  186. package/core/utils/dom.js +2 -2
  187. package/core/utils/global.js +2 -0
  188. package/core/utils/rect.js +41 -37
  189. package/core/utils/sentinel.js +25 -0
  190. package/core/utils/size.js +30 -27
  191. package/core/utils/svg.js +18 -16
  192. package/core/variable_map.js +325 -341
  193. package/core/variable_model.js +55 -54
  194. package/core/variables.js +9 -2
  195. package/core/variables_dynamic.js +3 -1
  196. package/core/warning.js +126 -120
  197. package/core/widgetdiv.js +4 -4
  198. package/core/workspace.js +685 -664
  199. package/core/workspace_audio.js +124 -118
  200. package/core/workspace_comment.js +308 -298
  201. package/core/workspace_comment_svg.js +1029 -951
  202. package/core/workspace_drag_surface_svg.js +147 -140
  203. package/core/workspace_dragger.js +70 -71
  204. package/core/workspace_svg.js +2322 -2297
  205. package/core/xml.js +30 -20
  206. package/core/zoom_controls.js +431 -439
  207. package/dart_compressed.js +40 -43
  208. package/dart_compressed.js.map +1 -1
  209. package/generators/dart/colour.js +56 -64
  210. package/generators/dart/lists.js +61 -50
  211. package/generators/dart/math.js +160 -148
  212. package/generators/dart/text.js +83 -61
  213. package/generators/javascript/colour.js +37 -34
  214. package/generators/javascript/lists.js +50 -43
  215. package/generators/javascript/math.js +123 -139
  216. package/generators/javascript/text.js +67 -81
  217. package/generators/lua/colour.js +25 -23
  218. package/generators/lua/lists.js +97 -69
  219. package/generators/lua/logic.js +1 -2
  220. package/generators/lua/math.js +182 -144
  221. package/generators/lua/text.js +116 -99
  222. package/generators/php/colour.js +38 -32
  223. package/generators/php/lists.js +109 -89
  224. package/generators/php/math.js +90 -81
  225. package/generators/php/text.js +63 -61
  226. package/generators/python/colour.js +18 -18
  227. package/generators/python/lists.js +38 -30
  228. package/generators/python/loops.js +12 -8
  229. package/generators/python/math.js +104 -106
  230. package/generators/python/text.js +34 -30
  231. package/javascript_compressed.js +37 -39
  232. package/javascript_compressed.js.map +1 -1
  233. package/lua_compressed.js +39 -42
  234. package/lua_compressed.js.map +1 -1
  235. package/msg/az.js +2 -2
  236. package/msg/be.js +4 -4
  237. package/msg/cs.js +15 -15
  238. package/msg/de.js +1 -1
  239. package/msg/diq.js +1 -1
  240. package/msg/eo.js +1 -1
  241. package/msg/es.js +1 -1
  242. package/msg/fa.js +1 -1
  243. package/msg/fr.js +4 -4
  244. package/msg/he.js +1 -1
  245. package/msg/hr.js +2 -2
  246. package/msg/hy.js +2 -2
  247. package/msg/id.js +12 -12
  248. package/msg/inh.js +14 -14
  249. package/msg/ja.js +7 -7
  250. package/msg/lv.js +29 -29
  251. package/msg/pa.js +3 -3
  252. package/msg/smn.js +436 -0
  253. package/msg/te.js +1 -1
  254. package/msg/yue.js +1 -1
  255. package/msg/zh-hans.js +3 -3
  256. package/msg/zh-hant.js +3 -3
  257. package/package.json +7 -6
  258. package/php_compressed.js +38 -42
  259. package/php_compressed.js.map +1 -1
  260. package/python_compressed.js +26 -25
  261. package/python_compressed.js.map +1 -1
  262. package/blocks/all.js +0 -23
@@ -19,6 +19,8 @@ const eventUtils = goog.require('Blockly.Events.utils');
19
19
  const svgMath = goog.require('Blockly.utils.svgMath');
20
20
  /* eslint-disable-next-line no-unused-vars */
21
21
  const {BlockDragSurfaceSvg} = goog.requireType('Blockly.BlockDragSurfaceSvg');
22
+ /* eslint-disable-next-line no-unused-vars */
23
+ const {CommentMove} = goog.requireType('Blockly.Events.CommentMove');
22
24
  const {ComponentManager} = goog.require('Blockly.ComponentManager');
23
25
  const {Coordinate} = goog.require('Blockly.utils.Coordinate');
24
26
  /* eslint-disable-next-line no-unused-vars */
@@ -43,249 +45,254 @@ goog.require('Blockly.constants');
43
45
  * Class for a bubble dragger. It moves things on the bubble canvas around the
44
46
  * workspace when they are being dragged by a mouse or touch. These can be
45
47
  * block comments, mutators, warnings, or workspace comments.
46
- * @param {!IBubble} bubble The item on the bubble canvas to drag.
47
- * @param {!WorkspaceSvg} workspace The workspace to drag on.
48
- * @constructor
49
48
  * @alias Blockly.BubbleDragger
50
49
  */
51
- const BubbleDragger = function(bubble, workspace) {
50
+ const BubbleDragger = class {
52
51
  /**
53
- * The item on the bubble canvas that is being dragged.
54
- * @type {!IBubble}
55
- * @private
52
+ * @param {!IBubble} bubble The item on the bubble canvas to drag.
53
+ * @param {!WorkspaceSvg} workspace The workspace to drag on.
56
54
  */
57
- this.draggingBubble_ = bubble;
55
+ constructor(bubble, workspace) {
56
+ /**
57
+ * The item on the bubble canvas that is being dragged.
58
+ * @type {!IBubble}
59
+ * @private
60
+ */
61
+ this.draggingBubble_ = bubble;
58
62
 
59
- /**
60
- * The workspace on which the bubble is being dragged.
61
- * @type {!WorkspaceSvg}
62
- * @private
63
- */
64
- this.workspace_ = workspace;
63
+ /**
64
+ * The workspace on which the bubble is being dragged.
65
+ * @type {!WorkspaceSvg}
66
+ * @private
67
+ */
68
+ this.workspace_ = workspace;
65
69
 
66
- /**
67
- * Which drag target the mouse pointer is over, if any.
68
- * @type {?IDragTarget}
69
- * @private
70
- */
71
- this.dragTarget_ = null;
70
+ /**
71
+ * Which drag target the mouse pointer is over, if any.
72
+ * @type {?IDragTarget}
73
+ * @private
74
+ */
75
+ this.dragTarget_ = null;
72
76
 
73
- /**
74
- * Whether the bubble would be deleted if dropped immediately.
75
- * @type {boolean}
76
- * @private
77
- */
78
- this.wouldDeleteBubble_ = false;
77
+ /**
78
+ * Whether the bubble would be deleted if dropped immediately.
79
+ * @type {boolean}
80
+ * @private
81
+ */
82
+ this.wouldDeleteBubble_ = false;
83
+
84
+ /**
85
+ * The location of the top left corner of the dragging bubble's body at the
86
+ * beginning of the drag, in workspace coordinates.
87
+ * @type {!Coordinate}
88
+ * @private
89
+ */
90
+ this.startXY_ = this.draggingBubble_.getRelativeToSurfaceXY();
91
+
92
+ /**
93
+ * The drag surface to move bubbles to during a drag, or null if none should
94
+ * be used. Block dragging and bubble dragging use the same surface.
95
+ * @type {BlockDragSurfaceSvg}
96
+ * @private
97
+ */
98
+ this.dragSurface_ =
99
+ svgMath.is3dSupported() && !!workspace.getBlockDragSurface() ?
100
+ workspace.getBlockDragSurface() :
101
+ null;
102
+ }
79
103
 
80
104
  /**
81
- * The location of the top left corner of the dragging bubble's body at the
82
- * beginning of the drag, in workspace coordinates.
83
- * @type {!Coordinate}
84
- * @private
105
+ * Sever all links from this object.
106
+ * @package
107
+ * @suppress {checkTypes}
85
108
  */
86
- this.startXY_ = this.draggingBubble_.getRelativeToSurfaceXY();
109
+ dispose() {
110
+ this.draggingBubble_ = null;
111
+ this.workspace_ = null;
112
+ this.dragSurface_ = null;
113
+ }
87
114
 
88
115
  /**
89
- * The drag surface to move bubbles to during a drag, or null if none should
90
- * be used. Block dragging and bubble dragging use the same surface.
91
- * @type {BlockDragSurfaceSvg}
92
- * @private
116
+ * Start dragging a bubble. This includes moving it to the drag surface.
117
+ * @package
93
118
  */
94
- this.dragSurface_ =
95
- svgMath.is3dSupported() && !!workspace.getBlockDragSurface() ?
96
- workspace.getBlockDragSurface() :
97
- null;
98
- };
99
-
100
- /**
101
- * Sever all links from this object.
102
- * @package
103
- * @suppress {checkTypes}
104
- */
105
- BubbleDragger.prototype.dispose = function() {
106
- this.draggingBubble_ = null;
107
- this.workspace_ = null;
108
- this.dragSurface_ = null;
109
- };
119
+ startBubbleDrag() {
120
+ if (!eventUtils.getGroup()) {
121
+ eventUtils.setGroup(true);
122
+ }
110
123
 
111
- /**
112
- * Start dragging a bubble. This includes moving it to the drag surface.
113
- * @package
114
- */
115
- BubbleDragger.prototype.startBubbleDrag = function() {
116
- if (!eventUtils.getGroup()) {
117
- eventUtils.setGroup(true);
118
- }
124
+ this.workspace_.setResizesEnabled(false);
125
+ this.draggingBubble_.setAutoLayout(false);
126
+ if (this.dragSurface_) {
127
+ this.moveToDragSurface_();
128
+ }
119
129
 
120
- this.workspace_.setResizesEnabled(false);
121
- this.draggingBubble_.setAutoLayout(false);
122
- if (this.dragSurface_) {
123
- this.moveToDragSurface_();
130
+ this.draggingBubble_.setDragging && this.draggingBubble_.setDragging(true);
124
131
  }
125
132
 
126
- this.draggingBubble_.setDragging && this.draggingBubble_.setDragging(true);
127
- };
133
+ /**
134
+ * Execute a step of bubble dragging, based on the given event. Update the
135
+ * display accordingly.
136
+ * @param {!Event} e The most recent move event.
137
+ * @param {!Coordinate} currentDragDeltaXY How far the pointer has
138
+ * moved from the position at the start of the drag, in pixel units.
139
+ * @package
140
+ */
141
+ dragBubble(e, currentDragDeltaXY) {
142
+ const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY);
143
+ const newLoc = Coordinate.sum(this.startXY_, delta);
144
+ this.draggingBubble_.moveDuringDrag(this.dragSurface_, newLoc);
128
145
 
129
- /**
130
- * Execute a step of bubble dragging, based on the given event. Update the
131
- * display accordingly.
132
- * @param {!Event} e The most recent move event.
133
- * @param {!Coordinate} currentDragDeltaXY How far the pointer has
134
- * moved from the position at the start of the drag, in pixel units.
135
- * @package
136
- */
137
- BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) {
138
- const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY);
139
- const newLoc = Coordinate.sum(this.startXY_, delta);
140
- this.draggingBubble_.moveDuringDrag(this.dragSurface_, newLoc);
146
+ const oldDragTarget = this.dragTarget_;
147
+ this.dragTarget_ = this.workspace_.getDragTarget(e);
141
148
 
142
- const oldDragTarget = this.dragTarget_;
143
- this.dragTarget_ = this.workspace_.getDragTarget(e);
149
+ const oldWouldDeleteBubble = this.wouldDeleteBubble_;
150
+ this.wouldDeleteBubble_ = this.shouldDelete_(this.dragTarget_);
151
+ if (oldWouldDeleteBubble !== this.wouldDeleteBubble_) {
152
+ // Prevent unnecessary add/remove class calls.
153
+ this.updateCursorDuringBubbleDrag_();
154
+ }
144
155
 
145
- const oldWouldDeleteBubble = this.wouldDeleteBubble_;
146
- this.wouldDeleteBubble_ = this.shouldDelete_(this.dragTarget_);
147
- if (oldWouldDeleteBubble !== this.wouldDeleteBubble_) {
148
- // Prevent unnecessary add/remove class calls.
149
- this.updateCursorDuringBubbleDrag_();
156
+ // Call drag enter/exit/over after wouldDeleteBlock is called in
157
+ // shouldDelete_
158
+ if (this.dragTarget_ !== oldDragTarget) {
159
+ oldDragTarget && oldDragTarget.onDragExit(this.draggingBubble_);
160
+ this.dragTarget_ && this.dragTarget_.onDragEnter(this.draggingBubble_);
161
+ }
162
+ this.dragTarget_ && this.dragTarget_.onDragOver(this.draggingBubble_);
150
163
  }
151
164
 
152
- // Call drag enter/exit/over after wouldDeleteBlock is called in shouldDelete_
153
- if (this.dragTarget_ !== oldDragTarget) {
154
- oldDragTarget && oldDragTarget.onDragExit(this.draggingBubble_);
155
- this.dragTarget_ && this.dragTarget_.onDragEnter(this.draggingBubble_);
165
+ /**
166
+ * Whether ending the drag would delete the bubble.
167
+ * @param {?IDragTarget} dragTarget The drag target that the bubblee is
168
+ * currently over.
169
+ * @return {boolean} Whether dropping the bubble immediately would delete the
170
+ * block.
171
+ * @private
172
+ */
173
+ shouldDelete_(dragTarget) {
174
+ if (dragTarget) {
175
+ const componentManager = this.workspace_.getComponentManager();
176
+ const isDeleteArea = componentManager.hasCapability(
177
+ dragTarget.id, ComponentManager.Capability.DELETE_AREA);
178
+ if (isDeleteArea) {
179
+ return (/** @type {!IDeleteArea} */ (dragTarget))
180
+ .wouldDelete(this.draggingBubble_, false);
181
+ }
182
+ }
183
+ return false;
156
184
  }
157
- this.dragTarget_ && this.dragTarget_.onDragOver(this.draggingBubble_);
158
- };
159
185
 
160
- /**
161
- * Whether ending the drag would delete the bubble.
162
- * @param {?IDragTarget} dragTarget The drag target that the bubblee is
163
- * currently over.
164
- * @return {boolean} Whether dropping the bubble immediately would delete the
165
- * block.
166
- * @private
167
- */
168
- BubbleDragger.prototype.shouldDelete_ = function(dragTarget) {
169
- if (dragTarget) {
170
- const componentManager = this.workspace_.getComponentManager();
171
- const isDeleteArea = componentManager.hasCapability(
172
- dragTarget.id, ComponentManager.Capability.DELETE_AREA);
173
- if (isDeleteArea) {
174
- return (/** @type {!IDeleteArea} */ (dragTarget))
175
- .wouldDelete(this.draggingBubble_, false);
176
- }
186
+ /**
187
+ * Update the cursor (and possibly the trash can lid) to reflect whether the
188
+ * dragging bubble would be deleted if released immediately.
189
+ * @private
190
+ */
191
+ updateCursorDuringBubbleDrag_() {
192
+ this.draggingBubble_.setDeleteStyle(this.wouldDeleteBubble_);
177
193
  }
178
- return false;
179
- };
180
194
 
181
- /**
182
- * Update the cursor (and possibly the trash can lid) to reflect whether the
183
- * dragging bubble would be deleted if released immediately.
184
- * @private
185
- */
186
- BubbleDragger.prototype.updateCursorDuringBubbleDrag_ = function() {
187
- this.draggingBubble_.setDeleteStyle(this.wouldDeleteBubble_);
188
- };
195
+ /**
196
+ * Finish a bubble drag and put the bubble back on the workspace.
197
+ * @param {!Event} e The mouseup/touchend event.
198
+ * @param {!Coordinate} currentDragDeltaXY How far the pointer has
199
+ * moved from the position at the start of the drag, in pixel units.
200
+ * @package
201
+ */
202
+ endBubbleDrag(e, currentDragDeltaXY) {
203
+ // Make sure internal state is fresh.
204
+ this.dragBubble(e, currentDragDeltaXY);
189
205
 
190
- /**
191
- * Finish a bubble drag and put the bubble back on the workspace.
192
- * @param {!Event} e The mouseup/touchend event.
193
- * @param {!Coordinate} currentDragDeltaXY How far the pointer has
194
- * moved from the position at the start of the drag, in pixel units.
195
- * @package
196
- */
197
- BubbleDragger.prototype.endBubbleDrag = function(e, currentDragDeltaXY) {
198
- // Make sure internal state is fresh.
199
- this.dragBubble(e, currentDragDeltaXY);
206
+ const preventMove = this.dragTarget_ &&
207
+ this.dragTarget_.shouldPreventMove(this.draggingBubble_);
208
+ let newLoc;
209
+ if (preventMove) {
210
+ newLoc = this.startXY_;
211
+ } else {
212
+ const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY);
213
+ newLoc = Coordinate.sum(this.startXY_, delta);
214
+ }
215
+ // Move the bubble to its final location.
216
+ this.draggingBubble_.moveTo(newLoc.x, newLoc.y);
200
217
 
201
- const preventMove = this.dragTarget_ &&
202
- this.dragTarget_.shouldPreventMove(this.draggingBubble_);
203
- let newLoc;
204
- if (preventMove) {
205
- newLoc = this.startXY_;
206
- } else {
207
- const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY);
208
- newLoc = Coordinate.sum(this.startXY_, delta);
209
- }
210
- // Move the bubble to its final location.
211
- this.draggingBubble_.moveTo(newLoc.x, newLoc.y);
218
+ if (this.dragTarget_) {
219
+ this.dragTarget_.onDrop(this.draggingBubble_);
220
+ }
221
+
222
+ if (this.wouldDeleteBubble_) {
223
+ // Fire a move event, so we know where to go back to for an undo.
224
+ this.fireMoveEvent_();
225
+ this.draggingBubble_.dispose(false, true);
226
+ } else {
227
+ // Put everything back onto the bubble canvas.
228
+ if (this.dragSurface_) {
229
+ this.dragSurface_.clearAndHide(this.workspace_.getBubbleCanvas());
230
+ }
231
+ if (this.draggingBubble_.setDragging) {
232
+ this.draggingBubble_.setDragging(false);
233
+ }
234
+ this.fireMoveEvent_();
235
+ }
236
+ this.workspace_.setResizesEnabled(true);
212
237
 
213
- if (this.dragTarget_) {
214
- this.dragTarget_.onDrop(this.draggingBubble_);
238
+ eventUtils.setGroup(false);
215
239
  }
216
240
 
217
- if (this.wouldDeleteBubble_) {
218
- // Fire a move event, so we know where to go back to for an undo.
219
- this.fireMoveEvent_();
220
- this.draggingBubble_.dispose(false, true);
221
- } else {
222
- // Put everything back onto the bubble canvas.
223
- if (this.dragSurface_) {
224
- this.dragSurface_.clearAndHide(this.workspace_.getBubbleCanvas());
225
- }
226
- if (this.draggingBubble_.setDragging) {
227
- this.draggingBubble_.setDragging(false);
241
+ /**
242
+ * Fire a move event at the end of a bubble drag.
243
+ * @private
244
+ */
245
+ fireMoveEvent_() {
246
+ if (this.draggingBubble_.isComment) {
247
+ // TODO (adodson): Resolve build errors when requiring
248
+ // WorkspaceCommentSvg.
249
+ const event = /** @type {!CommentMove} */
250
+ (new (eventUtils.get(eventUtils.COMMENT_MOVE))(
251
+ /** @type {!WorkspaceCommentSvg} */ (this.draggingBubble_)));
252
+ event.setOldCoordinate(this.startXY_);
253
+ event.recordNew();
254
+ eventUtils.fire(event);
228
255
  }
229
- this.fireMoveEvent_();
256
+ // TODO (fenichel): move events for comments.
257
+ return;
230
258
  }
231
- this.workspace_.setResizesEnabled(true);
232
259
 
233
- eventUtils.setGroup(false);
234
- };
235
-
236
- /**
237
- * Fire a move event at the end of a bubble drag.
238
- * @private
239
- */
240
- BubbleDragger.prototype.fireMoveEvent_ = function() {
241
- if (this.draggingBubble_.isComment) {
242
- // TODO (adodson): Resolve build errors when requiring WorkspaceCommentSvg.
243
- const event = new (eventUtils.get(eventUtils.COMMENT_MOVE))(
244
- /** @type {!WorkspaceCommentSvg} */ (this.draggingBubble_));
245
- event.setOldCoordinate(this.startXY_);
246
- event.recordNew();
247
- eventUtils.fire(event);
260
+ /**
261
+ * Convert a coordinate object from pixels to workspace units, including a
262
+ * correction for mutator workspaces.
263
+ * This function does not consider differing origins. It simply scales the
264
+ * input's x and y values.
265
+ * @param {!Coordinate} pixelCoord A coordinate with x and y
266
+ * values in CSS pixel units.
267
+ * @return {!Coordinate} The input coordinate divided by the
268
+ * workspace scale.
269
+ * @private
270
+ */
271
+ pixelsToWorkspaceUnits_(pixelCoord) {
272
+ const result = new Coordinate(
273
+ pixelCoord.x / this.workspace_.scale,
274
+ pixelCoord.y / this.workspace_.scale);
275
+ if (this.workspace_.isMutator) {
276
+ // If we're in a mutator, its scale is always 1, purely because of some
277
+ // oddities in our rendering optimizations. The actual scale is the same
278
+ // as the scale on the parent workspace. Fix that for dragging.
279
+ const mainScale = this.workspace_.options.parentWorkspace.scale;
280
+ result.scale(1 / mainScale);
281
+ }
282
+ return result;
248
283
  }
249
- // TODO (fenichel): move events for comments.
250
- return;
251
- };
252
284
 
253
- /**
254
- * Convert a coordinate object from pixels to workspace units, including a
255
- * correction for mutator workspaces.
256
- * This function does not consider differing origins. It simply scales the
257
- * input's x and y values.
258
- * @param {!Coordinate} pixelCoord A coordinate with x and y
259
- * values in CSS pixel units.
260
- * @return {!Coordinate} The input coordinate divided by the
261
- * workspace scale.
262
- * @private
263
- */
264
- BubbleDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) {
265
- const result = new Coordinate(
266
- pixelCoord.x / this.workspace_.scale,
267
- pixelCoord.y / this.workspace_.scale);
268
- if (this.workspace_.isMutator) {
269
- // If we're in a mutator, its scale is always 1, purely because of some
270
- // oddities in our rendering optimizations. The actual scale is the same as
271
- // the scale on the parent workspace.
272
- // Fix that for dragging.
273
- const mainScale = this.workspace_.options.parentWorkspace.scale;
274
- result.scale(1 / mainScale);
285
+ /**
286
+ * Move the bubble onto the drag surface at the beginning of a drag. Move the
287
+ * drag surface to preserve the apparent location of the bubble.
288
+ * @private
289
+ */
290
+ moveToDragSurface_() {
291
+ this.draggingBubble_.moveTo(0, 0);
292
+ this.dragSurface_.translateSurface(this.startXY_.x, this.startXY_.y);
293
+ // Execute the move on the top-level SVG component.
294
+ this.dragSurface_.setBlocksAndShow(this.draggingBubble_.getSvgRoot());
275
295
  }
276
- return result;
277
- };
278
-
279
- /**
280
- * Move the bubble onto the drag surface at the beginning of a drag. Move the
281
- * drag surface to preserve the apparent location of the bubble.
282
- * @private
283
- */
284
- BubbleDragger.prototype.moveToDragSurface_ = function() {
285
- this.draggingBubble_.moveTo(0, 0);
286
- this.dragSurface_.translateSurface(this.startXY_.x, this.startXY_.y);
287
- // Execute the move on the top-level SVG component.
288
- this.dragSurface_.setBlocksAndShow(this.draggingBubble_.getSvgRoot());
289
296
  };
290
297
 
291
298
  exports.BubbleDragger = BubbleDragger;
@@ -15,11 +15,11 @@
15
15
  */
16
16
  goog.module('Blockly.bumpObjects');
17
17
 
18
- /* eslint-disable-next-line no-unused-vars */
19
- const Abstract = goog.requireType('Blockly.Events.Abstract');
20
18
  const eventUtils = goog.require('Blockly.Events.utils');
21
19
  const mathUtils = goog.require('Blockly.utils.math');
22
20
  /* eslint-disable-next-line no-unused-vars */
21
+ const {Abstract} = goog.requireType('Blockly.Events.Abstract');
22
+ /* eslint-disable-next-line no-unused-vars */
23
23
  const {BlockSvg} = goog.requireType('Blockly.BlockSvg');
24
24
  /* eslint-disable-next-line no-unused-vars */
25
25
  const {IBoundedElement} = goog.requireType('Blockly.IBoundedElement');
package/core/clipboard.js CHANGED
@@ -15,7 +15,6 @@
15
15
  */
16
16
  goog.module('Blockly.clipboard');
17
17
 
18
- const eventUtils = goog.require('Blockly.Events.utils');
19
18
  /* eslint-disable-next-line no-unused-vars */
20
19
  const {ICopyable} = goog.requireType('Blockly.ICopyable');
21
20
 
@@ -39,13 +38,14 @@ exports.copy = copy;
39
38
 
40
39
  /**
41
40
  * Paste a block or workspace comment on to the main workspace.
42
- * @return {boolean} True if the paste was successful, false otherwise.
41
+ * @return {!ICopyable|null} The pasted thing if the paste
42
+ * was successful, null otherwise.
43
43
  * @alias Blockly.clipboard.paste
44
44
  * @package
45
45
  */
46
46
  const paste = function() {
47
47
  if (!copyData) {
48
- return false;
48
+ return null;
49
49
  }
50
50
  // Pasting always pastes to the main workspace, even if the copy
51
51
  // started in a flyout workspace.
@@ -55,12 +55,9 @@ const paste = function() {
55
55
  }
56
56
  if (copyData.typeCounts &&
57
57
  workspace.isCapacityAvailable(copyData.typeCounts)) {
58
- eventUtils.setGroup(true);
59
- workspace.paste(copyData.saveInfo);
60
- eventUtils.setGroup(false);
61
- return true;
58
+ return workspace.paste(copyData.saveInfo);
62
59
  }
63
- return false;
60
+ return null;
64
61
  };
65
62
  exports.paste = paste;
66
63
 
@@ -68,13 +65,16 @@ exports.paste = paste;
68
65
  * Duplicate this block and its children, or a workspace comment.
69
66
  * @param {!ICopyable} toDuplicate Block or Workspace Comment to be
70
67
  * duplicated.
68
+ * @return {!ICopyable|null} The block or workspace comment that was duplicated,
69
+ * or null if the duplication failed.
71
70
  * @alias Blockly.clipboard.duplicate
72
71
  * @package
73
72
  */
74
73
  const duplicate = function(toDuplicate) {
75
74
  const oldCopyData = copyData;
76
75
  copy(toDuplicate);
77
- toDuplicate.workspace.paste(copyData.saveInfo);
76
+ const pastedThing = toDuplicate.workspace.paste(copyData.saveInfo);
78
77
  copyData = oldCopyData;
78
+ return pastedThing;
79
79
  };
80
80
  exports.duplicate = duplicate;