@supernova-studio/client 0.48.28 → 0.48.30

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.28",
3
+ "version": "0.48.30",
4
4
  "description": "Supernova Data Models",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -4,6 +4,7 @@ import {
4
4
  DocumentationPageV2,
5
5
  ElementGroup,
6
6
  ElementGroupSnapshot,
7
+ PageBlockDefinition,
7
8
  defaultDocumentationItemConfigurationV2,
8
9
  mapByUnique,
9
10
  pickLatestGroupSnapshots,
@@ -373,8 +374,12 @@ export class FrontendVersionRoomYDoc {
373
374
  // Update page content hash
374
375
  //
375
376
 
376
- notifyDocumentationPageContentUpdated(pageId: string, content: DocumentationPageEditorModel) {
377
- const pageContentHash = generatePageContentHash(content, this.debug);
377
+ notifyDocumentationPageContentUpdated(
378
+ pageId: string,
379
+ content: DocumentationPageEditorModel,
380
+ definitions: PageBlockDefinition[]
381
+ ) {
382
+ const pageContentHash = generatePageContentHash(content, definitions, this.debug);
378
383
  if (this.debug) {
379
384
  console.log(`Will set page content hash: '${pageId}' : '${pageContentHash}'`);
380
385
  }
@@ -1,12 +1,26 @@
1
- import { PageBlockItemRichTextValue } from "@supernova-studio/model";
1
+ import {
2
+ PageBlockDefinition,
3
+ PageBlockDefinitionsMap,
4
+ PageBlockItemMultiRichTextValue,
5
+ PageBlockItemRichTextValue,
6
+ mapPageBlockItemValuesV2,
7
+ removeCommentSpans,
8
+ } from "@supernova-studio/model";
2
9
  import { generateHash } from "../../utils";
3
10
  import { DocumentationPageEditorModel } from "../docs-editor";
4
11
 
5
- export function generatePageContentHash(content: DocumentationPageEditorModel, debug = false) {
12
+ export function generatePageContentHash(
13
+ content: DocumentationPageEditorModel,
14
+ definitions: PageBlockDefinition[],
15
+ debug = false
16
+ ) {
6
17
  let sanitizedContent = content;
7
18
 
19
+ // Remove comment spans
20
+ sanitizedContent = removeCommentSpansFromPage(content, definitions);
21
+
8
22
  // Make sure hashes of empty pages always match
9
- if (isPageContentEmpty(content)) {
23
+ if (isPageContentEmpty(sanitizedContent)) {
10
24
  sanitizedContent = { blocks: [] };
11
25
  }
12
26
 
@@ -35,3 +49,32 @@ function isPageContentEmpty(content: DocumentationPageEditorModel): boolean {
35
49
  const textValue = singleItem.props["text"] as PageBlockItemRichTextValue;
36
50
  return !textValue.value.spans.length;
37
51
  }
52
+
53
+ function removeCommentSpansFromPage(
54
+ content: DocumentationPageEditorModel,
55
+ definitions: PageBlockDefinition[]
56
+ ): DocumentationPageEditorModel {
57
+ const defMap = new PageBlockDefinitionsMap(definitions);
58
+
59
+ mapPageBlockItemValuesV2(content.blocks, defMap, (block, item, prop, value) => {
60
+ if (prop.type === "RichText") {
61
+ const richTextValue = value as PageBlockItemRichTextValue;
62
+ return {
63
+ ...richTextValue,
64
+ value: removeCommentSpans(richTextValue.value),
65
+ };
66
+ }
67
+
68
+ if (prop.type === "MultiRichText") {
69
+ const multiRichTextValue = value as PageBlockItemMultiRichTextValue;
70
+ return {
71
+ ...multiRichTextValue,
72
+ value: multiRichTextValue.value.map(removeCommentSpans),
73
+ };
74
+ }
75
+
76
+ return value;
77
+ });
78
+
79
+ return content;
80
+ }