Skip to content

Commit

Permalink
feat: add new @storyblok/richtext exports with retro-compatibilty w…
Browse files Browse the repository at this point in the history
…ith legacy `RichTextResolver`
  • Loading branch information
alvarosabu committed Jul 31, 2024
1 parent 9cb44bc commit 666e83f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
26 changes: 25 additions & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@ import {

import { RichtextResolver } from "storyblok-js-client";

import { type SbRichTextOptions as stdSbRichTextOptions} from "@storyblok/richtext";

/**
* This is a temporaly class to avoid type collision with the legacy richtext resolver.
* It will become ~~`newSbRichTextOptions`~~ -> `SbRichTextOptions` on v4.x
*/
export type newSbRichTextOptions = stdSbRichTextOptions;

// New Richtext Resolver
export {
BlockTypes,
MarkTypes,
richTextResolver,
TextTypes,
type SbRichTextDocumentNode,
type SbRichTextNodeTypes,
type SbRichTextNode,
type SbRichTextResolvers,
type SbRichTextNodeResolver,
type SbRichTextImageOptimizationOptions,
} from "@storyblok/richtext"

let richTextResolver;

let bridgeLatest = "https://app.storyblok.com/f/storyblok-v2-latest.js";
Expand Down Expand Up @@ -90,6 +112,7 @@ export const storyblokInit = (pluginOptions: SbSDKOptions = {}) => {
}

// Rich Text resolver
// TODO: replace with @storyblok/richtext package on v4.x
richTextResolver = new RichtextResolver(richText.schema);
if (richText.resolver) {
setComponentResolver(richTextResolver, richText.resolver);
Expand Down Expand Up @@ -134,12 +157,13 @@ export const renderRichText = (
}

if (options) {
// TODO: replace with @storyblok/richtext package on v4.x
localResolver = new RichtextResolver(options.schema);
if (options.resolver) {
setComponentResolver(localResolver, options.resolver);
}
}

// NOTE: This will warn the user about deprecation of legacy Richtext when https://github.com/storyblok/storyblok-js-client/pull/845 is merged
return localResolver.render(data);
};

Expand Down
1 change: 1 addition & 0 deletions lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"prepublishOnly": "npm run build && cp ../README.md ./"
},
"dependencies": {
"@storyblok/richtext": "^1.0.0",
"storyblok-js-client": "^6.7.2"
},
"devDependencies": {
Expand Down
31 changes: 31 additions & 0 deletions package-lock.json

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

0 comments on commit 666e83f

Please sign in to comment.