-
-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested custom components in MDX/Mdsvex #297
Comments
I’ll figure out how to do this, but there is no plan to support Svelte components because it‘s too costly to run the Svelte compiler on the fly. |
Ok, thanks a lot.
What do you mean exactly? I mainly want the markdown to contain e.g. |
Svelte is very different from other frameworks. Components must be complied in advance at the build time. Sveltia CMS being built with Svelte doesn’t make it easy to support Svelte components at all. To support Svelte components in the CMS, it has to download the latest version of the compiler, initialize it, compile a component, and inject the produced vanilla JavaScript code to the CMS UI, all on the fly, like what Svelte Playground does. It takes time to finish it. And it doesn’t work or is very slow on mobile/tablet apparently because the compiler is too big. So I don’t think it’s feasible to support Svelte components. React support is a must for Netlify CMS compatibility. I also have a plan to support Preact+HTM because it’s lightweight and easy to write components with the combo. Vue support may also be possible, but not sure. |
Ok, I think we have a different model in mind: I think you imagine the setting where you just have a bare html page + load sveltia via a CDN in the html, and read in the github the source code of the svelte element itself. I agree, this would not be efficient (but this is not what I had in mind). I have in mind a setting where I pre-compile svelte components (for instance via a npm project that compiles both sveltia & the users custom components). This way the browser already loads pre-compiled svelte components, and does not need to do any compilation. A similar solution (but maybe more generic) could also be to only support custom elements (framework agnostic as defined in https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements), and then for instance use svelte custom elements support, or lit, or react (that can also be rendered into custom elements)… This solution could also work with a simple CDN for instance that would load sveltia + a browser that just loads the JS containing the compiled custom element. For instance, this page explains how to create a file
and this would work on any platforms supporting bare JS, including mobile… |
For the fun I tried a minimal solution that I described in https://stackoverflow.com/a/79346499/4987648 a minimalist method (no bundler…) to compile this:
into a resulting file
Just load it via:
Enjoy svelte components without heavy compilation on the browser! |
Yeah, web components would work, no matter how it’s created. Svelte support is not involved there. If you see the document, |
One important issue of what you link is that
|
I know that custom components are yet to be implemented (can't wait for this), but I was thinking that it might be worse mentioning that it would be great to have support for nested custom components. For instance, I'd love to use in my website nested the collapsible container from https://playground.lexical.dev/, and save them in markdown (via custom components in MDX/Mdsvex files) like:
Note that regexp "cannot count", so cannot know how to properly match closing tags, hence a proper MDX/Mdsvex parser must be implemented for this feature.
See also #32
The text was updated successfully, but these errors were encountered: