JeremyRH / storybook-addon-code-editor

A Storybook add-on for live editing stories.
https://jeremyrh.github.io/storybook-addon-code-editor
MIT License
22 stars 8 forks source link

Provide onBeforeCreate callback #5

Closed wintercounter closed 1 year ago

wintercounter commented 1 year ago

I'm trying to make the editor work with https://github.com/remcohaszing/monaco-tailwindcss so we can provide auto-complete for our Tailwind classes. To make this work, I'd need to configure monaco before creating the editor instance, which is currently not possible as I see. I guess a callback before creating the instance would be sufficient enough to make this work, but not sure. Any ideas how can I make this work?

JeremyRH commented 1 year ago

In version 1.2.0 I added a setupEditor callback that has 2 parameters: monaco and createEditor. The return value can be an editor instance or void. setupEditor is called before the editor instance is created, right after monaco loads. You can create and return an editor instance in your setupEditor callback or it will be created immediately afterwards for you if you return void.

Check out the README or example story and let me know if you have questions.

JeremyRH commented 1 year ago

With the latest version (2.0.1), I removed setupEditor and added a more global way to configure things: setupMonaco. I figured out a hacky way to get https://github.com/remcohaszing/monaco-tailwindcss 's worker file loaded. Not sure if it's working completely but at least there are no errors.