From 666e83f947efd6fbd5b9401401361daa45fd25e4 Mon Sep 17 00:00:00 2001 From: alvarosabu Date: Wed, 31 Jul 2024 10:41:05 +0200 Subject: [PATCH] feat: add new `@storyblok/richtext` exports with retro-compatibilty with legacy `RichTextResolver` --- lib/index.ts | 26 +++++++++++++++++++++++++- lib/package.json | 1 + package-lock.json | 31 +++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/lib/index.ts b/lib/index.ts index b1c0422..578e532 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -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"; @@ -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); @@ -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); }; diff --git a/lib/package.json b/lib/package.json index 9aad7b0..6089b8e 100644 --- a/lib/package.json +++ b/lib/package.json @@ -28,6 +28,7 @@ "prepublishOnly": "npm run build && cp ../README.md ./" }, "dependencies": { + "@storyblok/richtext": "^1.0.0", "storyblok-js-client": "^6.7.2" }, "devDependencies": { diff --git a/package-lock.json b/package-lock.json index e755ced..51f9f4d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,6 +27,7 @@ "name": "@storyblok/js", "version": "2.0.6", "dependencies": { + "@storyblok/richtext": "^1.0.0", "storyblok-js-client": "^6.7.2" }, "devDependencies": { @@ -1775,6 +1776,14 @@ "resolved": "playground", "link": true }, + "node_modules/@storyblok/richtext": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@storyblok/richtext/-/richtext-1.0.0.tgz", + "integrity": "sha512-zzdgyJuoOTw9jldtj1/0+S1952NnherH7M5iXQRq7ehg7RDz01RGZEBSwcwrDmkXjfa6i7yaZrBdqD3BLUb34A==", + "dependencies": { + "consola": "^3.2.3" + } + }, "node_modules/@storyblok/vue-playground": { "resolved": "playground-vue", "link": true @@ -2751,6 +2760,14 @@ "dev": true, "license": "MIT" }, + "node_modules/consola": { + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/consola/-/consola-3.2.3.tgz", + "integrity": "sha512-I5qxpzLv+sJhTVEoLYNcTW+bThDCPsit0vLNKShZx6rLtpilNpmmeTPaeqJb9ZE9dV3DGaeby6Vuhrw38WjeyQ==", + "engines": { + "node": "^14.18.0 || >=16.10.0" + } + }, "node_modules/conventional-changelog-angular": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/conventional-changelog-angular/-/conventional-changelog-angular-7.0.0.tgz", @@ -8000,6 +8017,7 @@ "@storyblok/js": { "version": "file:lib", "requires": { + "@storyblok/richtext": "^1.0.0", "@tsconfig/recommended": "^1.0.6", "cypress": "^13.7.3", "eslint-plugin-cypress": "^2.15.1", @@ -8019,6 +8037,14 @@ "vite": "^5.2.8" } }, + "@storyblok/richtext": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@storyblok/richtext/-/richtext-1.0.0.tgz", + "integrity": "sha512-zzdgyJuoOTw9jldtj1/0+S1952NnherH7M5iXQRq7ehg7RDz01RGZEBSwcwrDmkXjfa6i7yaZrBdqD3BLUb34A==", + "requires": { + "consola": "^3.2.3" + } + }, "@storyblok/vue-playground": { "version": "file:playground-vue", "requires": { @@ -8724,6 +8750,11 @@ "version": "0.0.1", "dev": true }, + "consola": { + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/consola/-/consola-3.2.3.tgz", + "integrity": "sha512-I5qxpzLv+sJhTVEoLYNcTW+bThDCPsit0vLNKShZx6rLtpilNpmmeTPaeqJb9ZE9dV3DGaeby6Vuhrw38WjeyQ==" + }, "conventional-changelog-angular": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/conventional-changelog-angular/-/conventional-changelog-angular-7.0.0.tgz",