blockly 7.20211209.4 → 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.
- package/blockly.d.ts +18963 -18432
- package/blockly.min.js +852 -844
- package/blockly_compressed.js +669 -664
- package/blockly_compressed.js.map +1 -1
- package/blocks/blocks.js +47 -0
- package/blocks/colour.js +13 -3
- package/blocks/lists.js +22 -13
- package/blocks/logic.js +13 -3
- package/blocks/loops.js +24 -11
- package/blocks/math.js +12 -3
- package/blocks/procedures.js +41 -27
- package/blocks/text.js +22 -13
- package/blocks/variables.js +14 -3
- package/blocks/variables_dynamic.js +13 -3
- package/blocks_compressed.js +146 -141
- package/blocks_compressed.js.map +1 -1
- package/core/block.js +1869 -1814
- package/core/block_drag_surface.js +201 -200
- package/core/block_dragger.js +377 -373
- package/core/block_svg.js +1593 -1479
- package/core/blockly.js +8 -22
- package/core/blocks.js +9 -2
- package/core/browser_events.js +22 -5
- package/core/bubble.js +841 -797
- package/core/bubble_dragger.js +213 -206
- package/core/bump_objects.js +2 -2
- package/core/clipboard.js +9 -9
- package/core/comment.js +353 -332
- package/core/common.js +46 -17
- package/core/component_manager.js +181 -174
- package/core/config.js +87 -0
- package/core/connection.js +595 -584
- package/core/connection_checker.js +242 -244
- package/core/connection_db.js +235 -230
- package/core/contextmenu.js +9 -6
- package/core/contextmenu_items.js +1 -2
- package/core/contextmenu_registry.js +93 -89
- package/core/css.js +474 -474
- package/core/delete_area.js +45 -42
- package/core/drag_target.js +57 -56
- package/core/dropdowndiv.js +153 -163
- package/core/events/events.js +2 -2
- package/core/events/events_abstract.js +89 -77
- package/core/events/events_block_base.js +37 -36
- package/core/events/events_block_change.js +130 -124
- package/core/events/events_block_create.js +73 -71
- package/core/events/events_block_delete.js +84 -82
- package/core/events/events_block_drag.js +50 -49
- package/core/events/events_block_move.js +147 -140
- package/core/events/events_bubble_open.js +51 -50
- package/core/events/events_click.js +48 -44
- package/core/events/events_comment_base.js +72 -69
- package/core/events/events_comment_change.js +63 -61
- package/core/events/events_comment_create.js +44 -42
- package/core/events/events_comment_delete.js +42 -40
- package/core/events/events_comment_move.js +106 -104
- package/core/events/events_marker_move.js +65 -64
- package/core/events/events_selected.js +46 -45
- package/core/events/events_theme_change.js +36 -35
- package/core/events/events_toolbox_item_select.js +46 -45
- package/core/events/events_trashcan_open.js +37 -36
- package/core/events/events_ui.js +47 -46
- package/core/events/events_ui_base.js +30 -29
- package/core/events/events_var_base.js +37 -36
- package/core/events/events_var_create.js +50 -48
- package/core/events/events_var_delete.js +50 -48
- package/core/events/events_var_rename.js +51 -49
- package/core/events/events_viewport.js +66 -65
- package/core/events/utils.js +29 -14
- package/core/events/workspace_events.js +49 -55
- package/core/extensions.js +4 -3
- package/core/field.js +1061 -997
- package/core/field_angle.js +462 -442
- package/core/field_checkbox.js +194 -182
- package/core/field_colour.js +519 -505
- package/core/field_dropdown.js +617 -598
- package/core/field_image.js +229 -220
- package/core/field_label.js +102 -91
- package/core/field_label_serializable.js +42 -41
- package/core/field_multilineinput.js +372 -358
- package/core/field_number.js +272 -253
- package/core/field_textinput.js +499 -467
- package/core/field_variable.js +458 -420
- package/core/flyout_base.js +1005 -952
- package/core/flyout_button.js +277 -260
- package/core/flyout_horizontal.js +304 -302
- package/core/flyout_metrics_manager.js +64 -64
- package/core/flyout_vertical.js +306 -300
- package/core/generator.js +459 -446
- package/core/gesture.js +829 -813
- package/core/grid.js +166 -163
- package/core/icon.js +168 -159
- package/core/inject.js +7 -5
- package/core/input.js +257 -248
- package/core/insertion_marker_manager.js +655 -624
- package/core/internal_constants.js +0 -129
- package/core/keyboard_nav/ast_node.js +605 -596
- package/core/keyboard_nav/basic_cursor.js +166 -165
- package/core/keyboard_nav/cursor.js +99 -97
- package/core/keyboard_nav/marker.js +83 -79
- package/core/keyboard_nav/tab_navigate_cursor.js +18 -23
- package/core/marker_manager.js +153 -141
- package/core/menu.js +377 -372
- package/core/menuitem.js +223 -217
- package/core/metrics_manager.js +403 -390
- package/core/mutator.js +468 -437
- package/core/names.js +229 -188
- package/core/options.js +290 -284
- package/core/procedures.js +29 -17
- package/core/registry.js +19 -16
- package/core/rendered_connection.js +482 -463
- package/core/renderers/common/block_rendering.js +9 -3
- package/core/renderers/common/constants.js +1119 -1112
- package/core/renderers/common/debug.js +14 -0
- package/core/renderers/common/debugger.js +338 -316
- package/core/renderers/common/drawer.js +380 -370
- package/core/renderers/common/i_path_object.js +2 -2
- package/core/renderers/common/info.js +626 -618
- package/core/renderers/common/marker_svg.js +579 -541
- package/core/renderers/common/path_object.js +203 -200
- package/core/renderers/common/renderer.js +220 -218
- package/core/renderers/geras/constants.js +36 -36
- package/core/renderers/geras/drawer.js +155 -147
- package/core/renderers/geras/highlight_constants.js +244 -238
- package/core/renderers/geras/highlighter.js +231 -179
- package/core/renderers/geras/info.js +392 -369
- package/core/renderers/geras/measurables/inline_input.js +25 -19
- package/core/renderers/geras/measurables/statement_input.js +23 -17
- package/core/renderers/geras/path_object.js +106 -121
- package/core/renderers/geras/renderer.js +96 -98
- package/core/renderers/measurables/base.js +30 -18
- package/core/renderers/measurables/bottom_row.js +83 -80
- package/core/renderers/measurables/connection.js +22 -15
- package/core/renderers/measurables/external_value_input.js +35 -22
- package/core/renderers/measurables/field.js +35 -20
- package/core/renderers/measurables/hat.js +18 -13
- package/core/renderers/measurables/icon.js +24 -17
- package/core/renderers/measurables/in_row_spacer.js +15 -13
- package/core/renderers/measurables/inline_input.js +43 -33
- package/core/renderers/measurables/input_connection.js +41 -28
- package/core/renderers/measurables/input_row.js +50 -44
- package/core/renderers/measurables/jagged_edge.js +14 -12
- package/core/renderers/measurables/next_connection.js +16 -14
- package/core/renderers/measurables/output_connection.js +26 -20
- package/core/renderers/measurables/previous_connection.js +16 -15
- package/core/renderers/measurables/round_corner.js +20 -18
- package/core/renderers/measurables/row.js +184 -168
- package/core/renderers/measurables/spacer_row.js +38 -23
- package/core/renderers/measurables/square_corner.js +18 -16
- package/core/renderers/measurables/statement_input.js +23 -20
- package/core/renderers/measurables/top_row.js +88 -85
- package/core/renderers/minimalist/constants.js +8 -7
- package/core/renderers/minimalist/drawer.js +11 -10
- package/core/renderers/minimalist/info.js +18 -18
- package/core/renderers/minimalist/renderer.js +40 -39
- package/core/renderers/thrasos/info.js +258 -248
- package/core/renderers/thrasos/renderer.js +20 -20
- package/core/renderers/zelos/constants.js +898 -873
- package/core/renderers/zelos/drawer.js +186 -169
- package/core/renderers/zelos/info.js +502 -479
- package/core/renderers/zelos/marker_svg.js +129 -115
- package/core/renderers/zelos/measurables/bottom_row.js +31 -30
- package/core/renderers/zelos/measurables/inputs.js +22 -21
- package/core/renderers/zelos/measurables/row_elements.js +14 -13
- package/core/renderers/zelos/measurables/top_row.js +34 -33
- package/core/renderers/zelos/path_object.js +181 -180
- package/core/renderers/zelos/renderer.js +91 -92
- package/core/scrollbar.js +759 -713
- package/core/scrollbar_pair.js +250 -245
- package/core/serialization/blocks.js +19 -9
- package/core/serialization/workspaces.js +3 -2
- package/core/shortcut_registry.js +286 -277
- package/core/sprites.js +31 -0
- package/core/theme.js +135 -141
- package/core/theme_manager.js +147 -143
- package/core/toolbox/category.js +602 -576
- package/core/toolbox/collapsible_category.js +226 -227
- package/core/toolbox/separator.js +70 -61
- package/core/toolbox/toolbox.js +934 -927
- package/core/toolbox/toolbox_item.js +115 -99
- package/core/tooltip.js +108 -35
- package/core/touch.js +8 -3
- package/core/touch_gesture.js +254 -251
- package/core/trashcan.js +606 -595
- package/core/utils/coordinate.js +97 -95
- package/core/utils/dom.js +2 -2
- package/core/utils/global.js +2 -0
- package/core/utils/rect.js +41 -37
- package/core/utils/sentinel.js +25 -0
- package/core/utils/size.js +30 -27
- package/core/utils/svg.js +18 -16
- package/core/variable_map.js +325 -341
- package/core/variable_model.js +55 -54
- package/core/variables.js +9 -2
- package/core/variables_dynamic.js +3 -1
- package/core/warning.js +126 -120
- package/core/widgetdiv.js +4 -4
- package/core/workspace.js +685 -664
- package/core/workspace_audio.js +124 -118
- package/core/workspace_comment.js +308 -298
- package/core/workspace_comment_svg.js +1029 -951
- package/core/workspace_drag_surface_svg.js +147 -140
- package/core/workspace_dragger.js +70 -71
- package/core/workspace_svg.js +2322 -2297
- package/core/xml.js +30 -20
- package/core/zoom_controls.js +431 -439
- package/dart_compressed.js +40 -43
- package/dart_compressed.js.map +1 -1
- package/generators/dart/colour.js +56 -64
- package/generators/dart/lists.js +61 -50
- package/generators/dart/math.js +160 -148
- package/generators/dart/text.js +83 -61
- package/generators/javascript/colour.js +37 -34
- package/generators/javascript/lists.js +50 -43
- package/generators/javascript/math.js +123 -139
- package/generators/javascript/text.js +67 -81
- package/generators/lua/colour.js +25 -23
- package/generators/lua/lists.js +97 -69
- package/generators/lua/logic.js +1 -2
- package/generators/lua/math.js +182 -144
- package/generators/lua/text.js +116 -99
- package/generators/php/colour.js +38 -32
- package/generators/php/lists.js +109 -89
- package/generators/php/math.js +90 -81
- package/generators/php/text.js +63 -61
- package/generators/python/colour.js +18 -18
- package/generators/python/lists.js +38 -30
- package/generators/python/loops.js +12 -8
- package/generators/python/math.js +104 -106
- package/generators/python/text.js +34 -30
- package/javascript_compressed.js +37 -39
- package/javascript_compressed.js.map +1 -1
- package/lua_compressed.js +39 -42
- package/lua_compressed.js.map +1 -1
- package/msg/az.js +2 -2
- package/msg/be.js +4 -4
- package/msg/cs.js +15 -15
- package/msg/de.js +1 -1
- package/msg/diq.js +1 -1
- package/msg/eo.js +1 -1
- package/msg/es.js +1 -1
- package/msg/fa.js +1 -1
- package/msg/fr.js +4 -4
- package/msg/he.js +1 -1
- package/msg/hr.js +2 -2
- package/msg/hy.js +2 -2
- package/msg/id.js +12 -12
- package/msg/inh.js +14 -14
- package/msg/ja.js +7 -7
- package/msg/lv.js +29 -29
- package/msg/pa.js +3 -3
- package/msg/smn.js +436 -0
- package/msg/te.js +1 -1
- package/msg/yue.js +1 -1
- package/msg/zh-hans.js +3 -3
- package/msg/zh-hant.js +3 -3
- package/package.json +7 -6
- package/php_compressed.js +38 -42
- package/php_compressed.js.map +1 -1
- package/python_compressed.js +26 -25
- package/python_compressed.js.map +1 -1
- 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
|
-
|
|
36
|
-
name, opt_blockStyles, opt_categoryStyles, opt_componentStyles) {
|
|
26
|
+
class Theme {
|
|
37
27
|
/**
|
|
38
|
-
*
|
|
39
|
-
* @
|
|
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
|
-
|
|
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
|
-
*
|
|
45
|
-
* @
|
|
85
|
+
* Gets the class name that identifies this theme.
|
|
86
|
+
* @return {string} The CSS class name.
|
|
46
87
|
* @package
|
|
47
88
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
89
|
+
getClassName() {
|
|
90
|
+
return this.name + '-theme';
|
|
91
|
+
}
|
|
50
92
|
/**
|
|
51
|
-
*
|
|
52
|
-
* @
|
|
53
|
-
* @
|
|
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
|
-
|
|
56
|
-
|
|
97
|
+
setBlockStyle(blockStyleName, blockStyle) {
|
|
98
|
+
this.blockStyles[blockStyleName] = blockStyle;
|
|
99
|
+
}
|
|
57
100
|
/**
|
|
58
|
-
*
|
|
59
|
-
* @
|
|
60
|
-
* @
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
105
|
+
setCategoryStyle(categoryStyleName, categoryStyle) {
|
|
106
|
+
this.categoryStyles[categoryStyleName] = categoryStyle;
|
|
107
|
+
}
|
|
65
108
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* @
|
|
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
|
-
|
|
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
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* @
|
|
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
|
-
|
|
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
|
-
|
|
81
|
-
|
|
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;
|
package/core/theme_manager.js
CHANGED
|
@@ -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
|
-
|
|
34
|
+
class ThemeManager {
|
|
39
35
|
/**
|
|
40
|
-
* The main workspace.
|
|
41
|
-
* @
|
|
42
|
-
* @
|
|
36
|
+
* @param {!WorkspaceSvg} workspace The main workspace.
|
|
37
|
+
* @param {!Theme} theme The workspace theme.
|
|
38
|
+
* @package
|
|
43
39
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
*
|
|
55
|
-
* @
|
|
56
|
-
* @
|
|
71
|
+
* Get the workspace theme.
|
|
72
|
+
* @return {!Theme} The workspace theme.
|
|
73
|
+
* @package
|
|
57
74
|
*/
|
|
58
|
-
|
|
75
|
+
getTheme() {
|
|
76
|
+
return this.theme_;
|
|
77
|
+
}
|
|
59
78
|
|
|
60
79
|
/**
|
|
61
|
-
*
|
|
62
|
-
* @
|
|
63
|
-
* @
|
|
80
|
+
* Set the workspace theme, and refresh the workspace and all components.
|
|
81
|
+
* @param {!Theme} theme The workspace theme.
|
|
82
|
+
* @package
|
|
64
83
|
*/
|
|
65
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
137
|
-
|
|
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
|
-
|
|
148
|
-
|
|
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
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
//
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
*
|
|
197
|
-
* @
|
|
198
|
-
*
|
|
203
|
+
* A Blockly UI component type.
|
|
204
|
+
* @typedef {{
|
|
205
|
+
* element:!Element,
|
|
206
|
+
* propertyName:string
|
|
207
|
+
* }}
|
|
199
208
|
*/
|
|
200
|
-
ThemeManager.
|
|
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;
|