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
package/core/menuitem.js CHANGED
@@ -22,265 +22,271 @@ const idGenerator = goog.require('Blockly.utils.idGenerator');
22
22
 
23
23
  /**
24
24
  * Class representing an item in a menu.
25
- *
26
- * @param {string|!HTMLElement} content Text caption to display as the content
27
- * of the item, or a HTML element to display.
28
- * @param {string=} opt_value Data/model associated with the menu item.
29
- * @constructor
30
25
  * @alias Blockly.MenuItem
31
26
  */
32
- const MenuItem = function(content, opt_value) {
27
+ const MenuItem = class {
33
28
  /**
34
- * Human-readable text of this menu item, or the HTML element to display.
35
- * @type {string|!HTMLElement}
36
- * @private
29
+ * @param {string|!HTMLElement} content Text caption to display as the content
30
+ * of the item, or a HTML element to display.
31
+ * @param {string=} opt_value Data/model associated with the menu item.
37
32
  */
38
- this.content_ = content;
33
+ constructor(content, opt_value) {
34
+ /**
35
+ * Human-readable text of this menu item, or the HTML element to display.
36
+ * @type {string|!HTMLElement}
37
+ * @private
38
+ */
39
+ this.content_ = content;
40
+
41
+ /**
42
+ * Machine-readable value of this menu item.
43
+ * @type {string|undefined}
44
+ * @private
45
+ */
46
+ this.value_ = opt_value;
47
+
48
+ /**
49
+ * Is the menu item clickable, as opposed to greyed-out.
50
+ * @type {boolean}
51
+ * @private
52
+ */
53
+ this.enabled_ = true;
54
+
55
+ /**
56
+ * The DOM element for the menu item.
57
+ * @type {?HTMLDivElement}
58
+ * @private
59
+ */
60
+ this.element_ = null;
61
+
62
+ /**
63
+ * Whether the menu item is rendered right-to-left.
64
+ * @type {boolean}
65
+ * @private
66
+ */
67
+ this.rightToLeft_ = false;
68
+
69
+ /**
70
+ * ARIA name for this menu.
71
+ * @type {?aria.Role}
72
+ * @private
73
+ */
74
+ this.roleName_ = null;
75
+
76
+ /**
77
+ * Is this menu item checkable.
78
+ * @type {boolean}
79
+ * @private
80
+ */
81
+ this.checkable_ = false;
82
+
83
+ /**
84
+ * Is this menu item currently checked.
85
+ * @type {boolean}
86
+ * @private
87
+ */
88
+ this.checked_ = false;
89
+
90
+ /**
91
+ * Is this menu item currently highlighted.
92
+ * @type {boolean}
93
+ * @private
94
+ */
95
+ this.highlight_ = false;
96
+
97
+ /**
98
+ * Bound function to call when this menu item is clicked.
99
+ * @type {?Function}
100
+ * @private
101
+ */
102
+ this.actionHandler_ = null;
103
+ }
39
104
 
40
105
  /**
41
- * Machine-readable value of this menu item.
42
- * @type {string|undefined}
43
- * @private
106
+ * Creates the menuitem's DOM.
107
+ * @return {!Element} Completed DOM.
44
108
  */
45
- this.value_ = opt_value;
109
+ createDom() {
110
+ const element =
111
+ /** @type {!HTMLDivElement} */ (document.createElement('div'));
112
+ element.id = idGenerator.getNextUniqueId();
113
+ this.element_ = element;
114
+
115
+ // Set class and style
116
+ // goog-menuitem* is deprecated, use blocklyMenuItem*. May 2020.
117
+ element.className = 'blocklyMenuItem goog-menuitem ' +
118
+ (this.enabled_ ? '' :
119
+ 'blocklyMenuItemDisabled goog-menuitem-disabled ') +
120
+ (this.checked_ ? 'blocklyMenuItemSelected goog-option-selected ' : '') +
121
+ (this.highlight_ ? 'blocklyMenuItemHighlight goog-menuitem-highlight ' :
122
+ '') +
123
+ (this.rightToLeft_ ? 'blocklyMenuItemRtl goog-menuitem-rtl ' : '');
124
+
125
+ const content =
126
+ /** @type {!HTMLDivElement} */ (document.createElement('div'));
127
+ content.className = 'blocklyMenuItemContent goog-menuitem-content';
128
+ // Add a checkbox for checkable menu items.
129
+ if (this.checkable_) {
130
+ const checkbox =
131
+ /** @type {!HTMLDivElement} */ (document.createElement('div'));
132
+ checkbox.className = 'blocklyMenuItemCheckbox goog-menuitem-checkbox';
133
+ content.appendChild(checkbox);
134
+ }
135
+
136
+ let contentDom = /** @type {!HTMLElement} */ (this.content_);
137
+ if (typeof this.content_ === 'string') {
138
+ contentDom = document.createTextNode(this.content_);
139
+ }
140
+ content.appendChild(contentDom);
141
+ element.appendChild(content);
142
+
143
+ // Initialize ARIA role and state.
144
+ if (this.roleName_) {
145
+ aria.setRole(element, this.roleName_);
146
+ }
147
+ aria.setState(
148
+ element, aria.State.SELECTED,
149
+ (this.checkable_ && this.checked_) || false);
150
+ aria.setState(element, aria.State.DISABLED, !this.enabled_);
151
+
152
+ return element;
153
+ }
46
154
 
47
155
  /**
48
- * Is the menu item clickable, as opposed to greyed-out.
49
- * @type {boolean}
50
- * @private
156
+ * Dispose of this menu item.
51
157
  */
52
- this.enabled_ = true;
158
+ dispose() {
159
+ this.element_ = null;
160
+ }
53
161
 
54
162
  /**
55
- * The DOM element for the menu item.
56
- * @type {?Element}
57
- * @private
163
+ * Gets the menu item's element.
164
+ * @return {?Element} The DOM element.
165
+ * @package
58
166
  */
59
- this.element_ = null;
167
+ getElement() {
168
+ return this.element_;
169
+ }
60
170
 
61
171
  /**
62
- * Whether the menu item is rendered right-to-left.
63
- * @type {boolean}
64
- * @private
172
+ * Gets the unique ID for this menu item.
173
+ * @return {string} Unique component ID.
174
+ * @package
65
175
  */
66
- this.rightToLeft_ = false;
176
+ getId() {
177
+ return this.element_.id;
178
+ }
67
179
 
68
180
  /**
69
- * ARIA name for this menu.
70
- * @type {?aria.Role}
71
- * @private
181
+ * Gets the value associated with the menu item.
182
+ * @return {*} value Value associated with the menu item.
183
+ * @package
72
184
  */
73
- this.roleName_ = null;
185
+ getValue() {
186
+ return this.value_;
187
+ }
74
188
 
75
189
  /**
76
- * Is this menu item checkable.
77
- * @type {boolean}
78
- * @private
190
+ * Set menu item's rendering direction.
191
+ * @param {boolean} rtl True if RTL, false if LTR.
192
+ * @package
79
193
  */
80
- this.checkable_ = false;
194
+ setRightToLeft(rtl) {
195
+ this.rightToLeft_ = rtl;
196
+ }
81
197
 
82
198
  /**
83
- * Is this menu item currently checked.
84
- * @type {boolean}
85
- * @private
199
+ * Set the menu item's accessibility role.
200
+ * @param {!aria.Role} roleName Role name.
201
+ * @package
86
202
  */
87
- this.checked_ = false;
203
+ setRole(roleName) {
204
+ this.roleName_ = roleName;
205
+ }
88
206
 
89
207
  /**
90
- * Is this menu item currently highlighted.
91
- * @type {boolean}
92
- * @private
208
+ * Sets the menu item to be checkable or not. Set to true for menu items
209
+ * that represent checkable options.
210
+ * @param {boolean} checkable Whether the menu item is checkable.
211
+ * @package
93
212
  */
94
- this.highlight_ = false;
213
+ setCheckable(checkable) {
214
+ this.checkable_ = checkable;
215
+ }
95
216
 
96
217
  /**
97
- * Bound function to call when this menu item is clicked.
98
- * @type {?Function}
99
- * @private
218
+ * Checks or unchecks the component.
219
+ * @param {boolean} checked Whether to check or uncheck the component.
220
+ * @package
100
221
  */
101
- this.actionHandler_ = null;
102
- };
103
-
104
-
105
- /**
106
- * Creates the menuitem's DOM.
107
- * @return {!Element} Completed DOM.
108
- */
109
- MenuItem.prototype.createDom = function() {
110
- const element = document.createElement('div');
111
- element.id = idGenerator.getNextUniqueId();
112
- this.element_ = element;
113
-
114
- // Set class and style
115
- // goog-menuitem* is deprecated, use blocklyMenuItem*. May 2020.
116
- element.className = 'blocklyMenuItem goog-menuitem ' +
117
- (this.enabled_ ? '' : 'blocklyMenuItemDisabled goog-menuitem-disabled ') +
118
- (this.checked_ ? 'blocklyMenuItemSelected goog-option-selected ' : '') +
119
- (this.highlight_ ? 'blocklyMenuItemHighlight goog-menuitem-highlight ' :
120
- '') +
121
- (this.rightToLeft_ ? 'blocklyMenuItemRtl goog-menuitem-rtl ' : '');
122
-
123
- const content = document.createElement('div');
124
- content.className = 'blocklyMenuItemContent goog-menuitem-content';
125
- // Add a checkbox for checkable menu items.
126
- if (this.checkable_) {
127
- const checkbox = document.createElement('div');
128
- checkbox.className = 'blocklyMenuItemCheckbox goog-menuitem-checkbox';
129
- content.appendChild(checkbox);
222
+ setChecked(checked) {
223
+ this.checked_ = checked;
130
224
  }
131
225
 
132
- let contentDom = /** @type {!HTMLElement} */ (this.content_);
133
- if (typeof this.content_ === 'string') {
134
- contentDom = document.createTextNode(this.content_);
226
+ /**
227
+ * Highlights or unhighlights the component.
228
+ * @param {boolean} highlight Whether to highlight or unhighlight the
229
+ * component.
230
+ * @package
231
+ */
232
+ setHighlighted(highlight) {
233
+ this.highlight_ = highlight;
234
+
235
+ const el = this.getElement();
236
+ if (el && this.isEnabled()) {
237
+ // goog-menuitem-highlight is deprecated, use blocklyMenuItemHighlight.
238
+ // May 2020.
239
+ const name = 'blocklyMenuItemHighlight';
240
+ const nameDep = 'goog-menuitem-highlight';
241
+ if (highlight) {
242
+ dom.addClass(el, name);
243
+ dom.addClass(el, nameDep);
244
+ } else {
245
+ dom.removeClass(el, name);
246
+ dom.removeClass(el, nameDep);
247
+ }
248
+ }
135
249
  }
136
- content.appendChild(contentDom);
137
- element.appendChild(content);
138
250
 
139
- // Initialize ARIA role and state.
140
- if (this.roleName_) {
141
- aria.setRole(element, this.roleName_);
251
+ /**
252
+ * Returns true if the menu item is enabled, false otherwise.
253
+ * @return {boolean} Whether the menu item is enabled.
254
+ * @package
255
+ */
256
+ isEnabled() {
257
+ return this.enabled_;
142
258
  }
143
- aria.setState(
144
- element, aria.State.SELECTED,
145
- (this.checkable_ && this.checked_) || false);
146
- aria.setState(element, aria.State.DISABLED, !this.enabled_);
147
-
148
- return element;
149
- };
150
-
151
- /**
152
- * Dispose of this menu item.
153
- */
154
- MenuItem.prototype.dispose = function() {
155
- this.element_ = null;
156
- };
157
-
158
- /**
159
- * Gets the menu item's element.
160
- * @return {?Element} The DOM element.
161
- * @package
162
- */
163
- MenuItem.prototype.getElement = function() {
164
- return this.element_;
165
- };
166
-
167
- /**
168
- * Gets the unique ID for this menu item.
169
- * @return {string} Unique component ID.
170
- * @package
171
- */
172
- MenuItem.prototype.getId = function() {
173
- return this.element_.id;
174
- };
175
-
176
- /**
177
- * Gets the value associated with the menu item.
178
- * @return {*} value Value associated with the menu item.
179
- * @package
180
- */
181
- MenuItem.prototype.getValue = function() {
182
- return this.value_;
183
- };
184
-
185
- /**
186
- * Set menu item's rendering direction.
187
- * @param {boolean} rtl True if RTL, false if LTR.
188
- * @package
189
- */
190
- MenuItem.prototype.setRightToLeft = function(rtl) {
191
- this.rightToLeft_ = rtl;
192
- };
193
259
 
194
- /**
195
- * Set the menu item's accessibility role.
196
- * @param {!aria.Role} roleName Role name.
197
- * @package
198
- */
199
- MenuItem.prototype.setRole = function(roleName) {
200
- this.roleName_ = roleName;
201
- };
202
-
203
- /**
204
- * Sets the menu item to be checkable or not. Set to true for menu items
205
- * that represent checkable options.
206
- * @param {boolean} checkable Whether the menu item is checkable.
207
- * @package
208
- */
209
- MenuItem.prototype.setCheckable = function(checkable) {
210
- this.checkable_ = checkable;
211
- };
212
-
213
- /**
214
- * Checks or unchecks the component.
215
- * @param {boolean} checked Whether to check or uncheck the component.
216
- * @package
217
- */
218
- MenuItem.prototype.setChecked = function(checked) {
219
- this.checked_ = checked;
220
- };
260
+ /**
261
+ * Enables or disables the menu item.
262
+ * @param {boolean} enabled Whether to enable or disable the menu item.
263
+ * @package
264
+ */
265
+ setEnabled(enabled) {
266
+ this.enabled_ = enabled;
267
+ }
221
268
 
222
- /**
223
- * Highlights or unhighlights the component.
224
- * @param {boolean} highlight Whether to highlight or unhighlight the component.
225
- * @package
226
- */
227
- MenuItem.prototype.setHighlighted = function(highlight) {
228
- this.highlight_ = highlight;
229
-
230
- const el = this.getElement();
231
- if (el && this.isEnabled()) {
232
- // goog-menuitem-highlight is deprecated, use blocklyMenuItemHighlight.
233
- // May 2020.
234
- const name = 'blocklyMenuItemHighlight';
235
- const nameDep = 'goog-menuitem-highlight';
236
- if (highlight) {
237
- dom.addClass(el, name);
238
- dom.addClass(el, nameDep);
239
- } else {
240
- dom.removeClass(el, name);
241
- dom.removeClass(el, nameDep);
269
+ /**
270
+ * Performs the appropriate action when the menu item is activated
271
+ * by the user.
272
+ * @package
273
+ */
274
+ performAction() {
275
+ if (this.isEnabled() && this.actionHandler_) {
276
+ this.actionHandler_(this);
242
277
  }
243
278
  }
244
- };
245
-
246
- /**
247
- * Returns true if the menu item is enabled, false otherwise.
248
- * @return {boolean} Whether the menu item is enabled.
249
- * @package
250
- */
251
- MenuItem.prototype.isEnabled = function() {
252
- return this.enabled_;
253
- };
254
-
255
- /**
256
- * Enables or disables the menu item.
257
- * @param {boolean} enabled Whether to enable or disable the menu item.
258
- * @package
259
- */
260
- MenuItem.prototype.setEnabled = function(enabled) {
261
- this.enabled_ = enabled;
262
- };
263
279
 
264
- /**
265
- * Performs the appropriate action when the menu item is activated
266
- * by the user.
267
- * @package
268
- */
269
- MenuItem.prototype.performAction = function() {
270
- if (this.isEnabled() && this.actionHandler_) {
271
- this.actionHandler_(this);
280
+ /**
281
+ * Set the handler that's called when the menu item is activated by the user.
282
+ * `obj` will be used as the 'this' object in the function when called.
283
+ * @param {function(!MenuItem)} fn The handler.
284
+ * @param {!Object} obj Used as the 'this' object in fn when called.
285
+ * @package
286
+ */
287
+ onAction(fn, obj) {
288
+ this.actionHandler_ = fn.bind(obj);
272
289
  }
273
290
  };
274
291
 
275
- /**
276
- * Set the handler that's called when the menu item is activated by the user.
277
- * `obj` will be used as the 'this' object in the function when called.
278
- * @param {function(!MenuItem)} fn The handler.
279
- * @param {!Object} obj Used as the 'this' object in fn when called.
280
- * @package
281
- */
282
- MenuItem.prototype.onAction = function(fn, obj) {
283
- this.actionHandler_ = fn.bind(obj);
284
- };
285
-
286
292
  exports.MenuItem = MenuItem;