From c29d741ad45c8b71c4196e54aa3946b9b0d2a760 Mon Sep 17 00:00:00 2001 From: Steven Le Date: Fri, 26 Jul 2024 12:14:33 -0700 Subject: [PATCH] fix: avoid marshalling rich text data --- .changeset/nine-donkeys-doubt.md | 5 +++++ packages/root-cms/core/client.ts | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 .changeset/nine-donkeys-doubt.md diff --git a/.changeset/nine-donkeys-doubt.md b/.changeset/nine-donkeys-doubt.md new file mode 100644 index 00000000..47293856 --- /dev/null +++ b/.changeset/nine-donkeys-doubt.md @@ -0,0 +1,5 @@ +--- +'@blinkk/root-cms': patch +--- + +fix: avoid marshalling rich text data diff --git a/packages/root-cms/core/client.ts b/packages/root-cms/core/client.ts index e9496738..9156ea94 100644 --- a/packages/root-cms/core/client.ts +++ b/packages/root-cms/core/client.ts @@ -940,6 +940,22 @@ export class RootCMSClient { } } +/** + * Returns true if the `data` is a rich text data object. + */ +export function isRichTextData(data: any) { + // The RichTextEditor uses editorjs under the hood, the data format is + // something like: + // { + // "time": 1721761211720, + // "version": "2.28.2", + // "blocks": [...] + // } + return Boolean( + isObject(data) && Array.isArray(data.blocks) && data.time && data.version + ); +} + export function getCmsPlugin(rootConfig: RootConfig): CMSPlugin { const plugins: Plugin[] = rootConfig.plugins || []; const plugin = plugins.find((plugin) => plugin.name === 'root-cms'); @@ -954,6 +970,11 @@ export function getCmsPlugin(rootConfig: RootConfig): CMSPlugin { * for storage in firestore. */ export function marshalData(data: any): any { + // Avoid changing the format of rich text data. + if (isRichTextData(data)) { + return data; + } + const result: any = {}; for (const key in data) { const val = data[key];