bartbutenaers / node-red-contrib-blockly

A Node Red node for visual programming a function using Blockly
Apache License 2.0
88 stars 22 forks source link

Support for Blockly Themes selection #107

Closed ralphwetzel closed 10 months ago

ralphwetzel commented 10 months ago

Initially Bart tried to import the Blockly Theme modules the conventional way:

node.themeModule = await import("/blockly-contrib/npm/@blockly___SEPARATOR___theme-" + theme + "/dist/index.js");

This yet runs into Cannot read properties of undefined (reading 'Blockly'). Looks like there's an issue with the webpackUniversalModuleDefinition implementation. I found no way to compensate for this. Bad. As [...]/src/index.js is the pure code file (not being wrapped into the webpackUniversalModuleDefinition stuff), I tried to import from there. Fails as well, as import Blockly from 'blockly/core' cannot be resolved. The good thing: We don't need this import at all! Blockly is guaranteed to be already defined! Fortunately, the Blockly Theme plugins follow a very simple & identical pattern - supporting the following hack:

Works like a charm!

Closes #106

bartbutenaers commented 10 months ago

@ralphwetzel,

This is VERY kind of you!! Thanks a lot for this. Your way to load this is very creative. I wouldn't have thought about that myself...

@cymplecy: I had installed the blockly-themes branch from Ralph's fork, and then e.g. the Black theme looks like this:

image

So I have merged his changes in our master branch.