microsoft / pxt-microbit

A Blocks / JavaScript code editor for the micro:bit built on Microsoft MakeCode
https://makecode.microbit.org
Other
721 stars 594 forks source link

Combine "Blocks embed" with extensions #5303

Closed jxns closed 1 year ago

jxns commented 1 year ago

I implemented the blocks embed method in a software I am developing. The rendering works great but the renderer can not translate blocks of my extension (the extension is already released and added to the makecode repository). Is there any way I can use extensions in combination with blocks embed or does this only work with internal blocks?

abchatra commented 1 year ago

@jxns can you share your extension?

jxns commented 1 year ago

@abchatra of course, my extension is this one: pxt-RB-JoyPi-Advanced

jwunderl commented 1 year ago

It's not documented well on that page, but there's a package field in the render message where you can pass in packages you want to include; the string should use the same format as the package snippet in 'normal' docs: https://makecode.com/writing-docs/snippets#package; e.g. in this case the render message would look something like:

    f.contentWindow.postMessage({
        type: "renderblocks",
        id: pre.id,
        code: pre.innerText,
        options: {
            package: "pxt-rb-joypi-advanced=github:joy-it/pxt-RB-JoyPi-Advanced"
        }
    }, "https://makecode.microbit.org/");

I have to double check on our editor interface whether package can handle multiple dependencies (if they're e.g. split by new lines, another delimitter, or pass an array or something) but should work fine for this scenario?

e.g. https://replit.com/@jwunderl/ImaginativeHopefulUsers

jxns commented 1 year ago

Adding the package in the options tag worked perfectly. Thank you very much!

abchatra commented 1 year ago

@ganicke can we document this?