@supernova-studio/client 0.47.37 → 0.47.39

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.47.37",
3
+ "version": "0.47.39",
4
4
  "description": "Supernova Data Models",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -1,4 +1,4 @@
1
- import { DocumentationPageV2, ElementGroup } from "@supernova-studio/model";
1
+ import { DesignElementSnapshot, DocumentationPageV2, ElementGroup } from "@supernova-studio/model";
2
2
  import { DTODocumentationHierarchyV2 } from "../../dto";
3
3
  import { elementGroupsToDocumentationGroupStructureDTOV2 } from "./documentation-group-v2-to-dto";
4
4
  import { documentationPagesToStructureDTOV2 } from "./documentation-page-v2-to-dto";
@@ -12,10 +12,12 @@ import { documentationPagesToStructureDTOV2 } from "./documentation-page-v2-to-d
12
12
  export function documentationElementsToHierarchyDto(
13
13
  docPages: DocumentationPageV2[],
14
14
  docGroups: ElementGroup[],
15
+ publishedPagesSnapshots: DesignElementSnapshot[],
15
16
  routingVersion: string
16
17
  ): DTODocumentationHierarchyV2 {
17
18
  return {
18
19
  pages: documentationPagesToStructureDTOV2(docPages, docGroups, routingVersion),
19
20
  groups: elementGroupsToDocumentationGroupStructureDTOV2(docGroups, docPages),
21
+ publishedPagesSnapshots,
20
22
  };
21
23
  }
@@ -1,7 +1,7 @@
1
- import { DocumentationPageV2 } from "@supernova-studio/model";
1
+ import { DesignElementSnapshot, DocumentationPageV2 } from "@supernova-studio/model";
2
2
  import { z } from "zod";
3
- import { DTODocumentationItemConfigurationV2 } from "./item-configuration-v2";
4
3
  import { DTODocumentationGroupStructureV2 } from "./group-v2";
4
+ import { DTODocumentationItemConfigurationV2 } from "./item-configuration-v2";
5
5
  //
6
6
  // Read
7
7
  //
@@ -29,6 +29,7 @@ export type DTODocumentationPageStructureV2 = DTODocumentationPageV2;
29
29
  export const DTODocumentationHierarchyV2 = z.object({
30
30
  pages: z.array(DTODocumentationPageStructureV2),
31
31
  groups: z.array(DTODocumentationGroupStructureV2),
32
+ publishedPagesSnapshots: DesignElementSnapshot.array(),
32
33
  });
33
34
 
34
35
  export type DTODocumentationHierarchyV2 = z.infer<typeof DTODocumentationHierarchyV2>;
@@ -1,4 +1,4 @@
1
- import { DocumentationPageV2, ElementGroup } from "@supernova-studio/model";
1
+ import { DesignElementSnapshot, DocumentationPageV2, ElementGroup } from "@supernova-studio/model";
2
2
  import * as Y from "yjs";
3
3
  import { z } from "zod";
4
4
  import { DTODocumentationHierarchyV2, documentationElementsToHierarchyDto } from "../../api";
@@ -23,12 +23,14 @@ type DocumentationHierarchyTransaction = {
23
23
  groups: ElementGroup[];
24
24
  pageIdsToDelete: string[];
25
25
  groupIdsToDelete: string[];
26
+ publishedPageSnapshots: DesignElementSnapshot[];
26
27
 
27
28
  internalSettings: DocumentationHierarchySettings | undefined;
28
29
  };
29
30
 
30
31
  export const DocumentationHierarchySettings = z.object({
31
32
  routingVersion: z.string(),
33
+ isDraftFeatureAdopted: z.boolean(),
32
34
  });
33
35
 
34
36
  export type DocumentationHierarchySettings = z.infer<typeof DocumentationHierarchySettings>;
@@ -69,6 +71,13 @@ export function documentationHierarchyToYjs(doc: Y.Doc, transaction: Documentati
69
71
  groupsMap.set(group.id, JSON.parse(JSON.stringify(group)));
70
72
  });
71
73
 
74
+ // Published state
75
+ const publishedSnapshotsMap = getPublishedSnapshotsYMap(trx.doc);
76
+
77
+ transaction.publishedPageSnapshots.forEach(state => {
78
+ publishedSnapshotsMap.set(state.id, JSON.parse(JSON.stringify(state)));
79
+ });
80
+
72
81
  // Internal settings
73
82
  if (transaction.internalSettings) {
74
83
  serializeDocumentationInternalSettings(trx.doc, transaction.internalSettings);
@@ -82,11 +91,13 @@ function serializeDocumentationInternalSettings(doc: Y.Doc, settings: Documentat
82
91
  const map = getInternalSettingsYMap(doc);
83
92
 
84
93
  map.set("routingVersion", settings.routingVersion);
94
+ settings.isDraftFeatureAdopted !== undefined && map.set("isDraftFeatureAdapted", settings.isDraftFeatureAdopted);
85
95
  }
86
96
 
87
97
  export function yjsToDocumentationHierarchy(doc: Y.Doc): DTODocumentationHierarchyV2 {
88
98
  const pagesMap = getPagesYMap(doc);
89
99
  const groupsMap = getGroupsYMap(doc);
100
+ const publishedSnapshotsMap = getPublishedSnapshotsYMap(doc);
90
101
 
91
102
  // Read pages
92
103
  const pages: DocumentationPageV2[] = [];
@@ -100,11 +111,22 @@ export function yjsToDocumentationHierarchy(doc: Y.Doc): DTODocumentationHierarc
100
111
  groups.push(ElementGroup.parse(group));
101
112
  });
102
113
 
114
+ // Read states
115
+ const publishedSnapshots: DesignElementSnapshot[] = [];
116
+ publishedSnapshotsMap.forEach(state => {
117
+ publishedSnapshots.push(DesignElementSnapshot.parse(state));
118
+ });
119
+
103
120
  // Parse internalSettings
104
121
  const internalSettings = parseDocumentationInternalSettings(doc);
105
122
 
106
123
  // Map model onto client DTO
107
- const hierarchy = documentationElementsToHierarchyDto(pages, groups, internalSettings.routingVersion ?? "2");
124
+ const hierarchy = documentationElementsToHierarchyDto(
125
+ pages,
126
+ groups,
127
+ publishedSnapshots,
128
+ internalSettings.routingVersion ?? "2"
129
+ );
108
130
 
109
131
  return hierarchy;
110
132
  }
@@ -114,11 +136,15 @@ function parseDocumentationInternalSettings(doc: Y.Doc): DocumentationHierarchyS
114
136
 
115
137
  const rawSettings: Record<keyof DocumentationHierarchySettings, any> = {
116
138
  routingVersion: map.get("routingVersion"),
139
+ isDraftFeatureAdopted: map.get("isDraftFeatureAdapted") ?? false,
117
140
  };
118
141
 
119
142
  const settingsParseResult = DocumentationHierarchySettings.safeParse(rawSettings);
120
143
  if (!settingsParseResult.success) {
121
- return { routingVersion: "2" };
144
+ return {
145
+ routingVersion: "2",
146
+ isDraftFeatureAdopted: false,
147
+ };
122
148
  }
123
149
 
124
150
  return settingsParseResult.data;
@@ -139,3 +165,7 @@ function getGroupsYMap(doc: Y.Doc) {
139
165
  function getInternalSettingsYMap(doc: Y.Doc) {
140
166
  return doc.getMap<unknown>("documentationInternalSettings");
141
167
  }
168
+
169
+ function getPublishedSnapshotsYMap(doc: Y.Doc) {
170
+ return doc.getMap<DesignElementSnapshot>("documentationPagePublishedSnapshots");
171
+ }
@@ -686,7 +686,10 @@ function parseAsCustomBlock(
686
686
  const appearance = parseAppearance(prosemirrorNode);
687
687
 
688
688
  const parsedItems = parseBlockItems(prosemirrorNode, definition) ?? [];
689
- if (!parsedItems.length && definition.behavior.items?.numberOfItems === 1) {
689
+
690
+ // Some blocks can expect at least one item to be always present. In such case we fallback to an item
691
+ // without any properties defined which should be a valid item for any combination of block settings.
692
+ if (!parsedItems.length && definitionExpectsPlaceholderItem(definition)) {
690
693
  parsedItems.push({
691
694
  id: id,
692
695
  props: {},
@@ -708,6 +711,15 @@ function parseAsCustomBlock(
708
711
  };
709
712
  }
710
713
 
714
+ function definitionExpectsPlaceholderItem(definition: PageBlockDefinition): boolean {
715
+ return (
716
+ // Block needs an item when it's a data block (tokens, components, etc)
717
+ !definition.behavior.items ||
718
+ // Block needs an item when number of items is expected to be 1
719
+ definition.behavior.items.numberOfItems === 1
720
+ );
721
+ }
722
+
711
723
  function parseBlockItems(prosemirrorNode: ProsemirrorNode, definition: PageBlockDefinition): PageBlockItemV2[] | null {
712
724
  const itemsString = getProsemirrorAttribute(prosemirrorNode, "items", z.string());
713
725
  if (!itemsString) return null;