blockly 7.20211209.4 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/blockly.d.ts +18963 -18432
  2. package/blockly.min.js +5 -4
  3. package/blockly_compressed.js +4 -3
  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 +45 -32
  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 +1 -1
  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 +26 -10
  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/generators/dart/colour.js +56 -64
  208. package/generators/dart/lists.js +61 -50
  209. package/generators/dart/math.js +160 -148
  210. package/generators/dart/text.js +83 -61
  211. package/generators/javascript/colour.js +37 -34
  212. package/generators/javascript/lists.js +50 -43
  213. package/generators/javascript/math.js +123 -139
  214. package/generators/javascript/text.js +67 -81
  215. package/generators/lua/colour.js +25 -23
  216. package/generators/lua/lists.js +97 -69
  217. package/generators/lua/logic.js +1 -2
  218. package/generators/lua/math.js +182 -144
  219. package/generators/lua/text.js +116 -99
  220. package/generators/php/colour.js +38 -32
  221. package/generators/php/lists.js +109 -89
  222. package/generators/php/math.js +90 -81
  223. package/generators/php/text.js +63 -61
  224. package/generators/python/colour.js +18 -18
  225. package/generators/python/lists.js +38 -30
  226. package/generators/python/loops.js +12 -8
  227. package/generators/python/math.js +104 -106
  228. package/generators/python/text.js +34 -30
  229. package/msg/smn.js +436 -0
  230. package/package.json +7 -6
  231. package/blocks/all.js +0 -23
package/core/theme.js CHANGED
@@ -21,65 +21,157 @@ const registry = goog.require('Blockly.registry');
21
21
 
22
22
  /**
23
23
  * Class for a theme.
24
- * @param {string} name Theme name.
25
- * @param {!Object<string, Theme.BlockStyle>=} opt_blockStyles A map
26
- * from style names (strings) to objects with style attributes for blocks.
27
- * @param {!Object<string, Theme.CategoryStyle>=} opt_categoryStyles A
28
- * map from style names (strings) to objects with style attributes for
29
- * categories.
30
- * @param {!Theme.ComponentStyle=} opt_componentStyles A map of Blockly
31
- * component names to style value.
32
- * @constructor
33
24
  * @alias Blockly.Theme
34
25
  */
35
- const Theme = function(
36
- name, opt_blockStyles, opt_categoryStyles, opt_componentStyles) {
26
+ class Theme {
37
27
  /**
38
- * The theme name. This can be used to reference a specific theme in CSS.
39
- * @type {string}
28
+ * @param {string} name Theme name.
29
+ * @param {!Object<string, Theme.BlockStyle>=} opt_blockStyles A map
30
+ * from style names (strings) to objects with style attributes for blocks.
31
+ * @param {!Object<string, Theme.CategoryStyle>=} opt_categoryStyles A
32
+ * map from style names (strings) to objects with style attributes for
33
+ * categories.
34
+ * @param {!Theme.ComponentStyle=} opt_componentStyles A map of Blockly
35
+ * component names to style value.
40
36
  */
41
- this.name = name;
42
-
37
+ constructor(name, opt_blockStyles, opt_categoryStyles, opt_componentStyles) {
38
+ /**
39
+ * The theme name. This can be used to reference a specific theme in CSS.
40
+ * @type {string}
41
+ */
42
+ this.name = name;
43
+
44
+ /**
45
+ * The block styles map.
46
+ * @type {!Object<string, !Theme.BlockStyle>}
47
+ * @package
48
+ */
49
+ this.blockStyles = opt_blockStyles || Object.create(null);
50
+
51
+ /**
52
+ * The category styles map.
53
+ * @type {!Object<string, Theme.CategoryStyle>}
54
+ * @package
55
+ */
56
+ this.categoryStyles = opt_categoryStyles || Object.create(null);
57
+
58
+ /**
59
+ * The UI components styles map.
60
+ * @type {!Theme.ComponentStyle}
61
+ * @package
62
+ */
63
+ this.componentStyles = opt_componentStyles ||
64
+ (/** @type {Theme.ComponentStyle} */ (Object.create(null)));
65
+
66
+ /**
67
+ * The font style.
68
+ * @type {!Theme.FontStyle}
69
+ * @package
70
+ */
71
+ this.fontStyle = /** @type {Theme.FontStyle} */ (Object.create(null));
72
+
73
+ /**
74
+ * Whether or not to add a 'hat' on top of all blocks with no previous or
75
+ * output connections.
76
+ * @type {?boolean}
77
+ * @package
78
+ */
79
+ this.startHats = null;
80
+
81
+ // Register the theme by name.
82
+ registry.register(registry.Type.THEME, name, this);
83
+ }
43
84
  /**
44
- * The block styles map.
45
- * @type {!Object<string, !Theme.BlockStyle>}
85
+ * Gets the class name that identifies this theme.
86
+ * @return {string} The CSS class name.
46
87
  * @package
47
88
  */
48
- this.blockStyles = opt_blockStyles || Object.create(null);
49
-
89
+ getClassName() {
90
+ return this.name + '-theme';
91
+ }
50
92
  /**
51
- * The category styles map.
52
- * @type {!Object<string, Theme.CategoryStyle>}
53
- * @package
93
+ * Overrides or adds a style to the blockStyles map.
94
+ * @param {string} blockStyleName The name of the block style.
95
+ * @param {Theme.BlockStyle} blockStyle The block style.
54
96
  */
55
- this.categoryStyles = opt_categoryStyles || Object.create(null);
56
-
97
+ setBlockStyle(blockStyleName, blockStyle) {
98
+ this.blockStyles[blockStyleName] = blockStyle;
99
+ }
57
100
  /**
58
- * The UI components styles map.
59
- * @type {!Theme.ComponentStyle}
60
- * @package
101
+ * Overrides or adds a style to the categoryStyles map.
102
+ * @param {string} categoryStyleName The name of the category style.
103
+ * @param {Theme.CategoryStyle} categoryStyle The category style.
61
104
  */
62
- this.componentStyles = opt_componentStyles ||
63
- (/** @type {Theme.ComponentStyle} */ (Object.create(null)));
64
-
105
+ setCategoryStyle(categoryStyleName, categoryStyle) {
106
+ this.categoryStyles[categoryStyleName] = categoryStyle;
107
+ }
65
108
  /**
66
- * The font style.
67
- * @type {!Theme.FontStyle}
68
- * @package
109
+ * Gets the style for a given Blockly UI component. If the style value is a
110
+ * string, we attempt to find the value of any named references.
111
+ * @param {string} componentName The name of the component.
112
+ * @return {?string} The style value.
69
113
  */
70
- this.fontStyle = /** @type {Theme.FontStyle} */ (Object.create(null));
71
-
114
+ getComponentStyle(componentName) {
115
+ const style = this.componentStyles[componentName];
116
+ if (style && typeof style === 'string' &&
117
+ this.getComponentStyle(/** @type {string} */ (style))) {
118
+ return this.getComponentStyle(/** @type {string} */ (style));
119
+ }
120
+ return style ? String(style) : null;
121
+ }
72
122
  /**
73
- * Whether or not to add a 'hat' on top of all blocks with no previous or
74
- * output connections.
75
- * @type {?boolean}
76
- * @package
123
+ * Configure a specific Blockly UI component with a style value.
124
+ * @param {string} componentName The name of the component.
125
+ * @param {*} styleValue The style value.
77
126
  */
78
- this.startHats = null;
127
+ setComponentStyle(componentName, styleValue) {
128
+ this.componentStyles[componentName] = styleValue;
129
+ }
130
+ /**
131
+ * Configure a theme's font style.
132
+ * @param {Theme.FontStyle} fontStyle The font style.
133
+ */
134
+ setFontStyle(fontStyle) {
135
+ this.fontStyle = fontStyle;
136
+ }
137
+ /**
138
+ * Configure a theme's start hats.
139
+ * @param {boolean} startHats True if the theme enables start hats, false
140
+ * otherwise.
141
+ */
142
+ setStartHats(startHats) {
143
+ this.startHats = startHats;
144
+ }
145
+ /**
146
+ * Define a new Blockly theme.
147
+ * @param {string} name The name of the theme.
148
+ * @param {!Object} themeObj An object containing theme properties.
149
+ * @return {!Theme} A new Blockly theme.
150
+ */
151
+ static defineTheme(name, themeObj) {
152
+ const theme = new Theme(name);
153
+ let base = themeObj['base'];
154
+ if (base) {
155
+ if (typeof base === 'string') {
156
+ base = registry.getObject(registry.Type.THEME, base);
157
+ }
158
+ if (base instanceof Theme) {
159
+ object.deepMerge(theme, base);
160
+ theme.name = name;
161
+ }
162
+ }
79
163
 
80
- // Register the theme by name.
81
- registry.register(registry.Type.THEME, name, this);
82
- };
164
+ object.deepMerge(theme.blockStyles, themeObj['blockStyles']);
165
+ object.deepMerge(theme.categoryStyles, themeObj['categoryStyles']);
166
+ object.deepMerge(theme.componentStyles, themeObj['componentStyles']);
167
+ object.deepMerge(theme.fontStyle, themeObj['fontStyle']);
168
+ if (themeObj['startHats'] !== null) {
169
+ theme.startHats = themeObj['startHats'];
170
+ }
171
+
172
+ return theme;
173
+ }
174
+ }
83
175
 
84
176
  /**
85
177
  * A block style.
@@ -133,102 +225,4 @@ Theme.ComponentStyle;
133
225
  */
134
226
  Theme.FontStyle;
135
227
 
136
- /**
137
- * Gets the class name that identifies this theme.
138
- * @return {string} The CSS class name.
139
- * @package
140
- */
141
- Theme.prototype.getClassName = function() {
142
- return this.name + '-theme';
143
- };
144
-
145
- /**
146
- * Overrides or adds a style to the blockStyles map.
147
- * @param {string} blockStyleName The name of the block style.
148
- * @param {Theme.BlockStyle} blockStyle The block style.
149
- */
150
- Theme.prototype.setBlockStyle = function(blockStyleName, blockStyle) {
151
- this.blockStyles[blockStyleName] = blockStyle;
152
- };
153
-
154
- /**
155
- * Overrides or adds a style to the categoryStyles map.
156
- * @param {string} categoryStyleName The name of the category style.
157
- * @param {Theme.CategoryStyle} categoryStyle The category style.
158
- */
159
- Theme.prototype.setCategoryStyle = function(categoryStyleName, categoryStyle) {
160
- this.categoryStyles[categoryStyleName] = categoryStyle;
161
- };
162
-
163
- /**
164
- * Gets the style for a given Blockly UI component. If the style value is a
165
- * string, we attempt to find the value of any named references.
166
- * @param {string} componentName The name of the component.
167
- * @return {?string} The style value.
168
- */
169
- Theme.prototype.getComponentStyle = function(componentName) {
170
- const style = this.componentStyles[componentName];
171
- if (style && typeof style === 'string' &&
172
- this.getComponentStyle(/** @type {string} */ (style))) {
173
- return this.getComponentStyle(/** @type {string} */ (style));
174
- }
175
- return style ? String(style) : null;
176
- };
177
-
178
- /**
179
- * Configure a specific Blockly UI component with a style value.
180
- * @param {string} componentName The name of the component.
181
- * @param {*} styleValue The style value.
182
- */
183
- Theme.prototype.setComponentStyle = function(componentName, styleValue) {
184
- this.componentStyles[componentName] = styleValue;
185
- };
186
-
187
- /**
188
- * Configure a theme's font style.
189
- * @param {Theme.FontStyle} fontStyle The font style.
190
- */
191
- Theme.prototype.setFontStyle = function(fontStyle) {
192
- this.fontStyle = fontStyle;
193
- };
194
-
195
- /**
196
- * Configure a theme's start hats.
197
- * @param {boolean} startHats True if the theme enables start hats, false
198
- * otherwise.
199
- */
200
- Theme.prototype.setStartHats = function(startHats) {
201
- this.startHats = startHats;
202
- };
203
-
204
- /**
205
- * Define a new Blockly theme.
206
- * @param {string} name The name of the theme.
207
- * @param {!Object} themeObj An object containing theme properties.
208
- * @return {!Theme} A new Blockly theme.
209
- */
210
- Theme.defineTheme = function(name, themeObj) {
211
- const theme = new Theme(name);
212
- let base = themeObj['base'];
213
- if (base) {
214
- if (typeof base === 'string') {
215
- base = registry.getObject(registry.Type.THEME, base);
216
- }
217
- if (base instanceof Theme) {
218
- object.deepMerge(theme, base);
219
- theme.name = name;
220
- }
221
- }
222
-
223
- object.deepMerge(theme.blockStyles, themeObj['blockStyles']);
224
- object.deepMerge(theme.categoryStyles, themeObj['categoryStyles']);
225
- object.deepMerge(theme.componentStyles, themeObj['componentStyles']);
226
- object.deepMerge(theme.fontStyle, themeObj['fontStyle']);
227
- if (themeObj['startHats'] !== null) {
228
- theme.startHats = themeObj['startHats'];
229
- }
230
-
231
- return theme;
232
- };
233
-
234
228
  exports.Theme = Theme;
@@ -29,179 +29,183 @@ const {Workspace} = goog.requireType('Blockly.Workspace');
29
29
 
30
30
  /**
31
31
  * Class for storing and updating a workspace's theme and UI components.
32
- * @param {!WorkspaceSvg} workspace The main workspace.
33
- * @param {!Theme} theme The workspace theme.
34
- * @constructor
35
- * @package
36
32
  * @alias Blockly.ThemeManager
37
33
  */
38
- const ThemeManager = function(workspace, theme) {
34
+ class ThemeManager {
39
35
  /**
40
- * The main workspace.
41
- * @type {!WorkspaceSvg}
42
- * @private
36
+ * @param {!WorkspaceSvg} workspace The main workspace.
37
+ * @param {!Theme} theme The workspace theme.
38
+ * @package
43
39
  */
44
- this.workspace_ = workspace;
45
-
46
- /**
47
- * The Blockly theme to use.
48
- * @type {!Theme}
49
- * @private
50
- */
51
- this.theme_ = theme;
40
+ constructor(workspace, theme) {
41
+ /**
42
+ * The main workspace.
43
+ * @type {!WorkspaceSvg}
44
+ * @private
45
+ */
46
+ this.workspace_ = workspace;
47
+
48
+ /**
49
+ * The Blockly theme to use.
50
+ * @type {!Theme}
51
+ * @private
52
+ */
53
+ this.theme_ = theme;
54
+
55
+ /**
56
+ * A list of workspaces that are subscribed to this theme.
57
+ * @type {!Array<Workspace>}
58
+ * @private
59
+ */
60
+ this.subscribedWorkspaces_ = [];
61
+
62
+ /**
63
+ * A map of subscribed UI components, keyed by component name.
64
+ * @type {!Object<string, !Array<!ThemeManager.Component>>}
65
+ * @private
66
+ */
67
+ this.componentDB_ = Object.create(null);
68
+ }
52
69
 
53
70
  /**
54
- * A list of workspaces that are subscribed to this theme.
55
- * @type {!Array<Workspace>}
56
- * @private
71
+ * Get the workspace theme.
72
+ * @return {!Theme} The workspace theme.
73
+ * @package
57
74
  */
58
- this.subscribedWorkspaces_ = [];
75
+ getTheme() {
76
+ return this.theme_;
77
+ }
59
78
 
60
79
  /**
61
- * A map of subscribed UI components, keyed by component name.
62
- * @type {!Object<string, !Array<!ThemeManager.Component>>}
63
- * @private
80
+ * Set the workspace theme, and refresh the workspace and all components.
81
+ * @param {!Theme} theme The workspace theme.
82
+ * @package
64
83
  */
65
- this.componentDB_ = Object.create(null);
66
- };
84
+ setTheme(theme) {
85
+ const prevTheme = this.theme_;
86
+ this.theme_ = theme;
87
+
88
+ // Set the theme name onto the injection div.
89
+ const injectionDiv = this.workspace_.getInjectionDiv();
90
+ if (injectionDiv) {
91
+ if (prevTheme) {
92
+ dom.removeClass(injectionDiv, prevTheme.getClassName());
93
+ }
94
+ dom.addClass(injectionDiv, this.theme_.getClassName());
95
+ }
67
96
 
68
- /**
69
- * A Blockly UI component type.
70
- * @typedef {{
71
- * element:!Element,
72
- * propertyName:string
73
- * }}
74
- */
75
- ThemeManager.Component;
97
+ // Refresh all subscribed workspaces.
98
+ for (let i = 0, workspace; (workspace = this.subscribedWorkspaces_[i]);
99
+ i++) {
100
+ /** @type {!WorkspaceSvg} */ (workspace).refreshTheme();
101
+ }
76
102
 
77
- /**
78
- * Get the workspace theme.
79
- * @return {!Theme} The workspace theme.
80
- * @package
81
- */
82
- ThemeManager.prototype.getTheme = function() {
83
- return this.theme_;
84
- };
103
+ // Refresh all registered Blockly UI components.
104
+ for (let i = 0, keys = Object.keys(this.componentDB_), key; (key = keys[i]);
105
+ i++) {
106
+ for (let j = 0, component; (component = this.componentDB_[key][j]); j++) {
107
+ const element = component.element;
108
+ const propertyName = component.propertyName;
109
+ const style = this.theme_ && this.theme_.getComponentStyle(key);
110
+ element.style[propertyName] = style || '';
111
+ }
112
+ }
85
113
 
86
- /**
87
- * Set the workspace theme, and refresh the workspace and all components.
88
- * @param {!Theme} theme The workspace theme.
89
- * @package
90
- */
91
- ThemeManager.prototype.setTheme = function(theme) {
92
- const prevTheme = this.theme_;
93
- this.theme_ = theme;
94
-
95
- // Set the theme name onto the injection div.
96
- const injectionDiv = this.workspace_.getInjectionDiv();
97
- if (injectionDiv) {
98
- if (prevTheme) {
99
- dom.removeClass(injectionDiv, prevTheme.getClassName());
114
+ for (const workspace of this.subscribedWorkspaces_) {
115
+ /** @type {!WorkspaceSvg} */ (workspace).hideChaff();
100
116
  }
101
- dom.addClass(injectionDiv, this.theme_.getClassName());
102
117
  }
103
118
 
104
- // Refresh all subscribed workspaces.
105
- for (let i = 0, workspace; (workspace = this.subscribedWorkspaces_[i]); i++) {
106
- workspace.refreshTheme();
119
+ /**
120
+ * Subscribe a workspace to changes to the selected theme. If a new theme is
121
+ * set, the workspace is called to refresh its blocks.
122
+ * @param {!Workspace} workspace The workspace to subscribe.
123
+ * @package
124
+ */
125
+ subscribeWorkspace(workspace) {
126
+ this.subscribedWorkspaces_.push(workspace);
107
127
  }
108
128
 
109
- // Refresh all registered Blockly UI components.
110
- for (let i = 0, keys = Object.keys(this.componentDB_), key; (key = keys[i]);
111
- i++) {
112
- for (let j = 0, component; (component = this.componentDB_[key][j]); j++) {
113
- const element = component.element;
114
- const propertyName = component.propertyName;
115
- const style = this.theme_ && this.theme_.getComponentStyle(key);
116
- element.style[propertyName] = style || '';
129
+ /**
130
+ * Unsubscribe a workspace to changes to the selected theme.
131
+ * @param {!Workspace} workspace The workspace to unsubscribe.
132
+ * @package
133
+ */
134
+ unsubscribeWorkspace(workspace) {
135
+ if (!arrayUtils.removeElem(this.subscribedWorkspaces_, workspace)) {
136
+ throw Error(
137
+ 'Cannot unsubscribe a workspace that hasn\'t been subscribed.');
117
138
  }
118
139
  }
119
140
 
120
- for (const workspace of this.subscribedWorkspaces_) {
121
- workspace.hideChaff();
122
- }
123
- };
124
-
125
- /**
126
- * Subscribe a workspace to changes to the selected theme. If a new theme is
127
- * set, the workspace is called to refresh its blocks.
128
- * @param {!Workspace} workspace The workspace to subscribe.
129
- * @package
130
- */
131
- ThemeManager.prototype.subscribeWorkspace = function(workspace) {
132
- this.subscribedWorkspaces_.push(workspace);
133
- };
141
+ /**
142
+ * Subscribe an element to changes to the selected theme. If a new theme is
143
+ * selected, the element's style is refreshed with the new theme's style.
144
+ * @param {!Element} element The element to subscribe.
145
+ * @param {string} componentName The name used to identify the component. This
146
+ * must be the same name used to configure the style in the Theme object.
147
+ * @param {string} propertyName The inline style property name to update.
148
+ * @package
149
+ */
150
+ subscribe(element, componentName, propertyName) {
151
+ if (!this.componentDB_[componentName]) {
152
+ this.componentDB_[componentName] = [];
153
+ }
134
154
 
135
- /**
136
- * Unsubscribe a workspace to changes to the selected theme.
137
- * @param {!Workspace} workspace The workspace to unsubscribe.
138
- * @package
139
- */
140
- ThemeManager.prototype.unsubscribeWorkspace = function(workspace) {
141
- if (!arrayUtils.removeElem(this.subscribedWorkspaces_, workspace)) {
142
- throw Error('Cannot unsubscribe a workspace that hasn\'t been subscribed.');
143
- }
144
- };
155
+ // Add the element to our component map.
156
+ this.componentDB_[componentName].push(
157
+ {element: element, propertyName: propertyName});
145
158
 
146
- /**
147
- * Subscribe an element to changes to the selected theme. If a new theme is
148
- * selected, the element's style is refreshed with the new theme's style.
149
- * @param {!Element} element The element to subscribe.
150
- * @param {string} componentName The name used to identify the component. This
151
- * must be the same name used to configure the style in the Theme object.
152
- * @param {string} propertyName The inline style property name to update.
153
- * @package
154
- */
155
- ThemeManager.prototype.subscribe = function(
156
- element, componentName, propertyName) {
157
- if (!this.componentDB_[componentName]) {
158
- this.componentDB_[componentName] = [];
159
+ // Initialize the element with its corresponding theme style.
160
+ const style = this.theme_ && this.theme_.getComponentStyle(componentName);
161
+ element.style[propertyName] = style || '';
159
162
  }
160
163
 
161
- // Add the element to our component map.
162
- this.componentDB_[componentName].push(
163
- {element: element, propertyName: propertyName});
164
-
165
- // Initialize the element with its corresponding theme style.
166
- const style = this.theme_ && this.theme_.getComponentStyle(componentName);
167
- element.style[propertyName] = style || '';
168
- };
169
-
170
- /**
171
- * Unsubscribe an element to changes to the selected theme.
172
- * @param {Element} element The element to unsubscribe.
173
- * @package
174
- */
175
- ThemeManager.prototype.unsubscribe = function(element) {
176
- if (!element) {
177
- return;
178
- }
179
- // Go through all component, and remove any references to this element.
180
- const componentNames = Object.keys(this.componentDB_);
181
- for (let c = 0, componentName; (componentName = componentNames[c]); c++) {
182
- const elements = this.componentDB_[componentName];
183
- for (let i = elements.length - 1; i >= 0; i--) {
184
- if (elements[i].element === element) {
185
- elements.splice(i, 1);
186
- }
164
+ /**
165
+ * Unsubscribe an element to changes to the selected theme.
166
+ * @param {Element} element The element to unsubscribe.
167
+ * @package
168
+ */
169
+ unsubscribe(element) {
170
+ if (!element) {
171
+ return;
187
172
  }
188
- // Clean up the component map entry if the list is empty.
189
- if (!this.componentDB_[componentName].length) {
190
- delete this.componentDB_[componentName];
173
+ // Go through all component, and remove any references to this element.
174
+ const componentNames = Object.keys(this.componentDB_);
175
+ for (let c = 0, componentName; (componentName = componentNames[c]); c++) {
176
+ const elements = this.componentDB_[componentName];
177
+ for (let i = elements.length - 1; i >= 0; i--) {
178
+ if (elements[i].element === element) {
179
+ elements.splice(i, 1);
180
+ }
181
+ }
182
+ // Clean up the component map entry if the list is empty.
183
+ if (!this.componentDB_[componentName].length) {
184
+ delete this.componentDB_[componentName];
185
+ }
191
186
  }
192
187
  }
193
- };
188
+
189
+ /**
190
+ * Dispose of this theme manager.
191
+ * @package
192
+ * @suppress {checkTypes}
193
+ */
194
+ dispose() {
195
+ this.owner_ = null;
196
+ this.theme_ = null;
197
+ this.subscribedWorkspaces_ = null;
198
+ this.componentDB_ = null;
199
+ }
200
+ }
194
201
 
195
202
  /**
196
- * Dispose of this theme manager.
197
- * @package
198
- * @suppress {checkTypes}
203
+ * A Blockly UI component type.
204
+ * @typedef {{
205
+ * element:!Element,
206
+ * propertyName:string
207
+ * }}
199
208
  */
200
- ThemeManager.prototype.dispose = function() {
201
- this.owner_ = null;
202
- this.theme_ = null;
203
- this.subscribedWorkspaces_ = null;
204
- this.componentDB_ = null;
205
- };
209
+ ThemeManager.Component;
206
210
 
207
211
  exports.ThemeManager = ThemeManager;