Skip to content
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

Get code from a slot. #50

Open
Decipher opened this issue Oct 2, 2020 · 5 comments
Open

Get code from a slot. #50

Decipher opened this issue Oct 2, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@Decipher
Copy link

Decipher commented Oct 2, 2020

As a user I want the ability to wrap my code with a the vue-live component so it's code readable but still works.

Currently I have to set my code to a prop, which results in this:

<vue-live :code="`<un-readable nested-props='{ tooMuch: true }' />`" />

When it would be much nicer to write it like this:

<vue-live>
  <read-able
    :clean="true"
  />
</vue-live>
@elevatebart
Copy link
Member

Hello @Decipher,

This is a great idea. It looks much cleaner indeed.
It was my initial idea too but I abandoned it.
It is almost impossible to ask VueJs NOT to render a template.

In styleguidist & in vuepress I preferred a markdown approach. I rarely use vue-live as is, but mostly as part of a bigger plugin. This way I almost never have to use the syntax described above.

I say almost impossible, because, in-theory, we could write an intermediary webpack loader.
It would detect and transform vue-live instances from read-able to un-readable but working before the vue-loader picks it up ad transforms it.

Would you be interested in creating such a loader?

@elevatebart elevatebart added the enhancement New feature or request label Oct 2, 2020
@Decipher
Copy link
Author

Decipher commented Oct 6, 2020

Hi @elevatebart,

I will look more into this as soon as I have a free opportunity.

I plan to investigate writing my own webpack loaders anyway, so this would be a good way to learn.

@jannikbuscha
Copy link

You can get Slot Content in Vue 3 with:

<template>
<VueLive :code="slots.default()[0].children[0]" />
</template>

<script setup>
import { VueLive } from 'vue-live';
import 'vue-live/lib/vue-live.esm.css';

import { useSlots } from 'vue';
const slots = useSlots();
</script>

@elevatebart
Copy link
Member

Agreed, the content of this slots is not the code as far as I know.
What vue-live needs is the code. I am wondering if it can be extracted though.

@elevatebart
Copy link
Member

elevatebart commented Dec 3, 2022

I think we could probably do it using the same method as histoire
If you have a minute for a PR that would be incredibly awesome.

example:
https://github.com/histoire-dev/histoire/blob/8ae9b9235c97af0eba17a765ee7a4f14af853267/packages/histoire-plugin-vue/src/client/app/RenderStory.ts#L88-L107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

3 participants