@supernova-studio/client 0.48.10 → 0.48.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supernova-studio/client",
3
- "version": "0.48.10",
3
+ "version": "0.48.11",
4
4
  "description": "Supernova Data Models",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -1,6 +1,37 @@
1
+ import { PageBlockItemRichTextValue } from "@supernova-studio/model";
1
2
  import { generateHash } from "../../utils";
2
3
  import { DocumentationPageEditorModel } from "../docs-editor";
3
4
 
4
5
  export function generatePageContentHash(content: DocumentationPageEditorModel, debug = false) {
5
- return generateHash(content, debug);
6
+ let sanitizedContent = content;
7
+
8
+ // Make sure hashes of empty pages always match
9
+ if (isPageContentEmpty(content)) {
10
+ sanitizedContent = { blocks: [] };
11
+ }
12
+
13
+ return generateHash(sanitizedContent, debug);
14
+ }
15
+
16
+ /**
17
+ * Empty page content can be one of the following:
18
+ * - page without any blocks
19
+ * - page with a single block, the block is a paragraph whithout any text
20
+ */
21
+ function isPageContentEmpty(content: DocumentationPageEditorModel): boolean {
22
+ if (content.blocks.length > 1) return false;
23
+ if (content.blocks.length < 1) return true;
24
+
25
+ const singleBlock = content.blocks[0];
26
+ if (singleBlock.type !== "Block" || singleBlock.data.packageId !== "io.supernova.block.rich-text") {
27
+ return false;
28
+ }
29
+
30
+ const singleItem = singleBlock.data.items[0];
31
+
32
+ // Block has no value, effectively the same as empty value
33
+ if (!singleItem || !singleItem.props["text"]) return true;
34
+
35
+ const textValue = singleItem.props["text"] as PageBlockItemRichTextValue;
36
+ return !textValue.value.spans.length;
6
37
  }