Skip to content

Commit

Permalink
fix: avoid marshalling rich text data
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenle committed Jul 26, 2024
1 parent 843090b commit c29d741
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-donkeys-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@blinkk/root-cms': patch
---

fix: avoid marshalling rich text data
21 changes: 21 additions & 0 deletions packages/root-cms/core/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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];
Expand Down

0 comments on commit c29d741

Please sign in to comment.