-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #685 from storyblok/feature/add-storyblok-richtext
feat: added new storyblok rich text API
- Loading branch information
Showing
21 changed files
with
1,709 additions
and
10,371 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<script setup lang="ts"> | ||
import type { VNode } from "vue"; | ||
import type { StoryblokRichTextNode } from "@storyblok/js"; | ||
import { useStoryblokRichText } from "../composables/useStoryblokRichText"; | ||
import type { StoryblokRichTextProps } from "../types"; | ||
const props = defineProps<StoryblokRichTextProps>(); | ||
const { render } = useStoryblokRichText({ | ||
resolvers: props.resolvers ?? {}, | ||
}); | ||
const root = () => render(props.doc as StoryblokRichTextNode<VNode>); | ||
</script> | ||
|
||
<template> | ||
<root /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { VNode } from "vue"; | ||
import { createTextVNode, h } from "vue"; | ||
import type { | ||
StoryblokRichTextNode, | ||
StoryblokRichTextNodeResolver, | ||
StoryblokRichTextOptions, | ||
} from "@storyblok/js"; | ||
import { BlockTypes, richTextResolver } from "@storyblok/js"; | ||
import StoryblokComponent from "../StoryblokComponent.vue"; | ||
|
||
const componentResolver: StoryblokRichTextNodeResolver<VNode> = ( | ||
node: StoryblokRichTextNode<VNode> | ||
): VNode => { | ||
return h( | ||
StoryblokComponent, | ||
{ | ||
blok: node?.attrs?.body[0], | ||
id: node.attrs?.id, | ||
}, | ||
node.children | ||
); | ||
}; | ||
|
||
export function useStoryblokRichText(options: StoryblokRichTextOptions<VNode>) { | ||
const mergedOptions: StoryblokRichTextOptions<VNode> = { | ||
renderFn: h, | ||
textFn: createTextVNode, | ||
resolvers: { | ||
[BlockTypes.COMPONENT]: componentResolver, | ||
...options.resolvers, | ||
}, | ||
}; | ||
return richTextResolver<VNode>(mergedOptions); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<script setup lang="ts"> | ||
defineProps({ | ||
blok: { | ||
type: Object, | ||
required: true, | ||
}, | ||
}); | ||
</script> | ||
<template> | ||
<iframe | ||
:src="blok.url.url" | ||
class="w-full aspect-video" | ||
frameborder="0" | ||
></iframe> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<script setup lang="ts"> | ||
import RichTextChild from "./RichTextChild.vue"; | ||
</script> | ||
<template> | ||
<div data-test="root"> | ||
<Suspense> | ||
<RichTextChild /> | ||
</Suspense> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<script setup lang="ts"> | ||
import { | ||
useStoryblok, | ||
StoryblokRichText, | ||
type StoryblokRichTextNode, | ||
MarkTypes, | ||
} from "@storyblok/vue"; | ||
import { type VNode, h } from "vue"; | ||
import { RouterLink } from "vue-router"; | ||
const story = await useStoryblok("vue/test-richtext", { version: "draft" }); | ||
const resolvers = { | ||
[MarkTypes.LINK]: (node: StoryblokRichTextNode<VNode>) => { | ||
return node.attrs?.linktype === "STORY" | ||
? h( | ||
RouterLink, | ||
{ | ||
to: node.attrs?.href, | ||
target: node.attrs?.target, | ||
}, | ||
node.text | ||
) | ||
: h( | ||
"a", | ||
{ | ||
href: node.attrs?.href, | ||
target: node.attrs?.target, | ||
}, | ||
node.text | ||
); | ||
}, | ||
}; | ||
</script> | ||
|
||
<template> | ||
<h2>RichText</h2> | ||
<!-- <pre>{{ story.content.richText }}</pre> --> | ||
<StoryblokRichText | ||
v-if="story.content" | ||
:doc="story.content.richText" | ||
:resolvers="resolvers" | ||
/> | ||
</template> |
Oops, something went wrong.