Skip to content

Commit

Permalink
feat: new richtext composable and component
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosabu committed Aug 1, 2024
1 parent bdb8191 commit d5916c8
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 51 deletions.
4 changes: 3 additions & 1 deletion lib/components/SbRichText.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script setup lang="ts">
import type { VNode } from "vue";
import type { SbRichTextNode } from "@storyblok/vue";
import { useSbRichText } from "../composables/useRichText";
import type { SbRichTextProps } from "../types";
Expand All @@ -8,7 +10,7 @@ const { render } = useSbRichText({
resolvers: props.resolvers,
});
const root = () => render(props.doc);
const root = () => render(props.doc as SbRichTextNode<VNode>);
</script>

<template>
Expand Down
10 changes: 5 additions & 5 deletions lib/composables/useRichText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { createTextVNode, h } from "vue";
import type {
SbRichTextNode,
SbRichTextNodeResolver,
SbRichTextOptions,
} from "@storyblok/richtext";
import { BlockTypes, richTextResolver } from "@storyblok/richtext";
newSbRichTextOptions,
} from "@storyblok/js";
import { BlockTypes, richTextResolver } from "@storyblok/js";
import StoryblokComponent from "../StoryblokComponent.vue";

const componentResolver: SbRichTextNodeResolver<VNode> = (
Expand All @@ -21,8 +21,8 @@ const componentResolver: SbRichTextNodeResolver<VNode> = (
);
};

export function useSbRichText(options: SbRichTextOptions<VNode>) {
const mergedOptions: SbRichTextOptions<VNode> = {
export function useSbRichText(options: newSbRichTextOptions<VNode>) {
const mergedOptions: newSbRichTextOptions<VNode> = {
renderFn: h,
textFn: createTextVNode,
resolvers: {
Expand Down
14 changes: 6 additions & 8 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,22 @@ import type {
} from "./types";

export {
useStoryblokBridge,
apiPlugin,
renderRichText,
RichTextSchema,
RichTextResolver,
BlockTypes,
MarkTypes,
richTextResolver,
TextTypes,
type SbRichTextDocumentNode,
type SbRichTextNodeTypes,
type SbRichTextNode,
type SbRichTextOptions,
type SbRichTextResolvers,
type SbRichTextNodeResolver,
type SbRichTextImageOptimizationOptions,
} from "@storyblok/richtext";

export {
useStoryblokBridge,
apiPlugin,
renderRichText,
RichTextSchema,
RichTextResolver,
} from "@storyblok/js";

import StoryblokComponent from "./StoryblokComponent.vue";
Expand Down
3 changes: 1 addition & 2 deletions lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"prepublishOnly": "npm run build && cp ../README.md ./"
},
"dependencies": {
"@storyblok/js": "^3.0.8",
"@storyblok/richtext": "^0.3.0"
"@storyblok/js": "^3.1.0-next.2"
},
"devDependencies": {
"@babel/core": "^7.24.7",
Expand Down
7 changes: 5 additions & 2 deletions lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { SbBlokData, SbSDKOptions } from "@storyblok/js";
import type StoryblokComponent from "./StoryblokComponent.vue";
import type { SbRichTextNode, SbRichTextResolvers } from "@storyblok/richtext";
import type {
SbRichTextDocumentNode,
SbRichTextResolvers,
} from "@storyblok/richtext";
import type { VNode } from "vue";

declare module "@vue/runtime-core" {
Expand Down Expand Up @@ -55,6 +58,6 @@ export interface SbComponentProps {
}

export interface SbRichTextProps {
doc: SbRichTextNode<VNode>;
doc: SbRichTextDocumentNode;
resolvers?: SbRichTextResolvers<VNode>;
}
62 changes: 32 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions playground/pages/Home.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script setup lang="ts">
import { onMounted, ref, VNode } from "vue";
import { onMounted, ref } from "vue";
import {
useStoryblokBridge,
useStoryblokApi,
SbRichText,
SbRichTextNode,
SbRichTextDocumentNode,
BlockTypes,
} from "@storyblok/vue";
Expand All @@ -22,7 +22,7 @@ onMounted(() => {
useStoryblokBridge(story.value.id, (evStory) => (story.value = evStory));
});
const doc: SbRichTextNode<VNode> = {
const doc: SbRichTextDocumentNode = {
[BlockTypes.DOCUMENT]: "doc",
content: [
{
Expand Down

0 comments on commit d5916c8

Please sign in to comment.