Cool!
Started following the link you shared.
Added the category as followed:
<category name="Projects"
colour={UTILS.getColorPalette().EXAMPLES}>
<category name="Colours" custom="COLOUR_PALLET">
</category>
</category>
It appears as a menu item in the category as seen in attached screenshot.
Pasted the following log with some debugging logging:
var coloursFlyoutCallback = function (workspace: any) {
console.log("JJJ CALLBACK CALLED")
var colourList = ['#4286f4', '#ef0447'];
var blockList = [];
for (var i = 0; i < colourList.length; i++) {
blockList.push({
'kind': 'block',
'type': 'colour_picker', // Type is optional if you provide blockxml
'blockxml': '<block type="colour_picker">' +
'<field name="COLOUR">' + colourList[i] + '</field>' +
'</block>'
});
}
return blockList;
};
console.log("JJJ Before");
workspace.registerToolboxCategoryCallback(
'COLOUR_PALETTE', coloursFlyoutCallback);
console.log("JJJ After");
console.log(workspace.getToolbox());
this.props.setWorkAreaLoadingState(LoadingState.INITIALIZED,
0);
With the following console.log output:
JJJ Before
JJJ After
Blockly.Toolbox {workspace_: B…y.WorkspaceSvg, toolboxDef_: {…}, horizontalLayout_: false, HtmlDiv: div.blocklyToolboxDiv.blocklyNonSelectable, contentsDiv_: div.blocklyToolboxContents, …}
Yet clicking the menu item does not trigger the
console.log("JJJ CALLBACK CALLED")
command
Instead an error is triggered with the following trace:
blockly_compressed.js:875 Uncaught TypeError: Couldn't find a callback function when opening a toolbox category.
at Blockly.VerticalFlyout.Blockly.Flyout.getDynamicCategoryContents_ (blockly_compressed.js:875:1)
at Blockly.VerticalFlyout.Blockly.Flyout.show (blockly_compressed.js:871:1)
at Blockly.Toolbox.updateFlyout_ (blockly_compressed.js:980:1)
at Blockly.Toolbox.setSelectedItem (blockly_compressed.js:978:1)
at Blockly.Toolbox.onClick_ (blockly_compressed.js:965:1)
at HTMLDivElement.h (blockly_compressed.js:829:1)
What am I doing wrong?