Headless workspaces require a theme to be defined, even though they are not rendered.
I can create themed blocks on a headless workspace.
I recieve an error.
changeTheme function of the playground.start function and replace it with the below: var altWorkspace = new Blockly.Workspace();
// JSON block def.
var block = new Blockly.Block(altWorkspace, 'controls_if');
// JS block def.
var block = new Blockly.Block(altWorkspace, 'text_getSubstring');
block.js:1520 Block "controls_if": Style does not exist: logic_blocks
Blockly.Block.jsonInitStyle_ @ block.js:1520
Blockly.Block.jsonInit @ block.js:1426
(anonymous) @ blockly.js:414
Blockly.Block @ block.js:181
start @ playground.html:146
onload @ playground.html:429
block.js:975 Uncaught Error: Trying to set block style to text_blocks before theme was defined via Blockly.setTheme().
at Blockly.Block.setStyle (block.js:975)
at Blockly.Block.init (text.js:224)
at new Blockly.Block (block.js:181)
at start (playground.html:147)
at onload (playground.html:429)
Just noticed this when I was writing some unit tests, and thought I should send it in.
Oh I also noticed that colour functions (some of them my own additions) are defined on the block rather than the rendered block, not sure if this is intensional.
I think this and #2540 are related
I have the same problem. Is there a workaround?
code:
var Blockly = require('node-blockly/browser');
var xml = Blockly.Xml.textToDom(xml_text);
var workspace = new Blockly.Workspace();
Blockly.Xml.domToWorkspace(xml, workspace);
var code = Blockly.JavaScript.workspaceToCode(workspace);
error:
Error: Trying to set block style to procedure_blocks before theme was defined via Blockly.setTheme().
at module.exports.Blockly.Block.setStyle (blockly_compressed_browser.js:1460)
at module.exports.Blockly.Block.init (blocks_compressed_browser.js:106)
at new module.exports.Blockly.Block (blockly_compressed_browser.js:1440)
at module.exports.Blockly.Workspace.newBlock (blockly_compressed_browser.js:1029)
at Object.module.exports.Blockly.Xml.domToBlockHeadless_ (blockly_compressed_browser.js:993)
at Object.module.exports.Blockly.Xml.domToBlock (blockly_compressed_browser.js:990)
at Object.module.exports.Blockly.Xml.domToWorkspace (blockly_compressed_browser.js:986)
The following seems to work:
var Blockly = require('node-blockly/browser');
Blockly.setTheme(Blockly.Themes.Classic);
Most helpful comment
The following seems to work: