@supernova-studio/client 0.58.19 → 1.0.0-alpha.3

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.
Files changed (196) hide show
  1. package/dist/index.d.mts +1363 -1321
  2. package/dist/index.d.ts +1363 -1321
  3. package/dist/index.js +536 -339
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +839 -642
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +4 -3
  8. package/src/api/client.ts +0 -31
  9. package/src/api/conversion/documentation/documentation-group-v1-to-dto.ts +0 -114
  10. package/src/api/conversion/documentation/documentation-group-v2-to-dto.ts +0 -92
  11. package/src/api/conversion/documentation/documentation-item-configuration-v1-to-dto.ts +0 -52
  12. package/src/api/conversion/documentation/documentation-item-configuration-v2-to-dto.ts +0 -34
  13. package/src/api/conversion/documentation/documentation-page-to-dto-utils.ts +0 -131
  14. package/src/api/conversion/documentation/documentation-page-v1-to-dto.ts +0 -69
  15. package/src/api/conversion/documentation/documentation-page-v2-to-dto.ts +0 -72
  16. package/src/api/conversion/documentation/index.ts +0 -7
  17. package/src/api/conversion/export/index.ts +0 -1
  18. package/src/api/conversion/export/pipeline.ts +0 -25
  19. package/src/api/conversion/index.ts +0 -3
  20. package/src/api/conversion/integrations/git.ts +0 -37
  21. package/src/api/conversion/integrations/index.ts +0 -2
  22. package/src/api/conversion/integrations/integration.ts +0 -37
  23. package/src/api/dto/aux/color.ts +0 -7
  24. package/src/api/dto/aux/index.ts +0 -3
  25. package/src/api/dto/aux/meta.ts +0 -8
  26. package/src/api/dto/aux/pagination.ts +0 -8
  27. package/src/api/dto/bff/app-bootstrap-data.ts +0 -20
  28. package/src/api/dto/bff/index.ts +0 -1
  29. package/src/api/dto/collections/index.ts +0 -1
  30. package/src/api/dto/collections/token-collection.ts +0 -24
  31. package/src/api/dto/design-systems/brand.ts +0 -44
  32. package/src/api/dto/design-systems/component.ts +0 -40
  33. package/src/api/dto/design-systems/contact.ts +0 -11
  34. package/src/api/dto/design-systems/data-source.ts +0 -141
  35. package/src/api/dto/design-systems/design-system.ts +0 -68
  36. package/src/api/dto/design-systems/elements-diff.ts +0 -14
  37. package/src/api/dto/design-systems/figma-variables.ts +0 -108
  38. package/src/api/dto/design-systems/import-job.ts +0 -61
  39. package/src/api/dto/design-systems/index.ts +0 -13
  40. package/src/api/dto/design-systems/members.ts +0 -50
  41. package/src/api/dto/design-systems/role.ts +0 -11
  42. package/src/api/dto/design-systems/stats.ts +0 -19
  43. package/src/api/dto/design-systems/version.ts +0 -56
  44. package/src/api/dto/design-systems/view.ts +0 -45
  45. package/src/api/dto/design-tokens/design-token.ts +0 -78
  46. package/src/api/dto/design-tokens/index.ts +0 -1
  47. package/src/api/dto/documentation/anchor.ts +0 -15
  48. package/src/api/dto/documentation/approvals.ts +0 -15
  49. package/src/api/dto/documentation/block-definition.ts +0 -28
  50. package/src/api/dto/documentation/block.ts +0 -6
  51. package/src/api/dto/documentation/documentation-page-snapshot.ts +0 -18
  52. package/src/api/dto/documentation/index.ts +0 -8
  53. package/src/api/dto/documentation/link-preview.ts +0 -23
  54. package/src/api/dto/documentation/publish.ts +0 -23
  55. package/src/api/dto/documentation/room.ts +0 -12
  56. package/src/api/dto/elements/components/figma-component-group.ts +0 -19
  57. package/src/api/dto/elements/components/figma-component.ts +0 -56
  58. package/src/api/dto/elements/components/index.ts +0 -2
  59. package/src/api/dto/elements/documentation/draft-state.ts +0 -37
  60. package/src/api/dto/elements/documentation/group-action.ts +0 -108
  61. package/src/api/dto/elements/documentation/group-v1.ts +0 -35
  62. package/src/api/dto/elements/documentation/group-v2.ts +0 -117
  63. package/src/api/dto/elements/documentation/hierarchy.ts +0 -22
  64. package/src/api/dto/elements/documentation/index.ts +0 -13
  65. package/src/api/dto/elements/documentation/item-configuration-v1.ts +0 -24
  66. package/src/api/dto/elements/documentation/item-configuration-v2.ts +0 -14
  67. package/src/api/dto/elements/documentation/metadata.ts +0 -8
  68. package/src/api/dto/elements/documentation/page-actions-v2.ts +0 -121
  69. package/src/api/dto/elements/documentation/page-content.ts +0 -15
  70. package/src/api/dto/elements/documentation/page-v1.ts +0 -21
  71. package/src/api/dto/elements/documentation/page-v2.ts +0 -120
  72. package/src/api/dto/elements/documentation/structure.ts +0 -37
  73. package/src/api/dto/elements/elements-action-v2.ts +0 -104
  74. package/src/api/dto/elements/figma-nodes/figma-node.ts +0 -106
  75. package/src/api/dto/elements/figma-nodes/index.ts +0 -2
  76. package/src/api/dto/elements/figma-nodes/node-actions-v2.ts +0 -24
  77. package/src/api/dto/elements/frame-node-structures/frame-node-structure.ts +0 -17
  78. package/src/api/dto/elements/frame-node-structures/index.ts +0 -1
  79. package/src/api/dto/elements/get-elements-v2.ts +0 -21
  80. package/src/api/dto/elements/index.ts +0 -7
  81. package/src/api/dto/elements/properties/index.ts +0 -2
  82. package/src/api/dto/elements/properties/property-definitions.ts +0 -75
  83. package/src/api/dto/elements/properties/property-values.ts +0 -38
  84. package/src/api/dto/export/exporter-property.ts +0 -95
  85. package/src/api/dto/export/exporter.ts +0 -87
  86. package/src/api/dto/export/filter.ts +0 -6
  87. package/src/api/dto/export/index.ts +0 -5
  88. package/src/api/dto/export/job.ts +0 -87
  89. package/src/api/dto/export/pipeline.ts +0 -43
  90. package/src/api/dto/figma-components/assets/download.ts +0 -30
  91. package/src/api/dto/figma-components/assets/index.ts +0 -1
  92. package/src/api/dto/figma-components/index.ts +0 -1
  93. package/src/api/dto/index.ts +0 -13
  94. package/src/api/dto/liveblocks/auth-response.ts +0 -7
  95. package/src/api/dto/liveblocks/index.ts +0 -1
  96. package/src/api/dto/themes/index.ts +0 -2
  97. package/src/api/dto/themes/override.ts +0 -27
  98. package/src/api/dto/themes/theme.ts +0 -45
  99. package/src/api/dto/users/authenticated-user.ts +0 -43
  100. package/src/api/dto/users/index.ts +0 -3
  101. package/src/api/dto/users/update.ts +0 -8
  102. package/src/api/dto/users/user.ts +0 -31
  103. package/src/api/dto/workspaces/git.ts +0 -32
  104. package/src/api/dto/workspaces/index.ts +0 -6
  105. package/src/api/dto/workspaces/integrations.ts +0 -34
  106. package/src/api/dto/workspaces/invitations.ts +0 -30
  107. package/src/api/dto/workspaces/membership.ts +0 -41
  108. package/src/api/dto/workspaces/npm-registry.ts +0 -35
  109. package/src/api/dto/workspaces/workspace.ts +0 -34
  110. package/src/api/endpoints/codegen/codegen.ts +0 -13
  111. package/src/api/endpoints/codegen/exporters.ts +0 -13
  112. package/src/api/endpoints/codegen/index.ts +0 -3
  113. package/src/api/endpoints/codegen/pipelines.ts +0 -37
  114. package/src/api/endpoints/design-system/bff.ts +0 -13
  115. package/src/api/endpoints/design-system/contact.ts +0 -12
  116. package/src/api/endpoints/design-system/design-systems.ts +0 -55
  117. package/src/api/endpoints/design-system/index.ts +0 -6
  118. package/src/api/endpoints/design-system/members.ts +0 -24
  119. package/src/api/endpoints/design-system/sources.ts +0 -35
  120. package/src/api/endpoints/design-system/versions/brands.ts +0 -45
  121. package/src/api/endpoints/design-system/versions/documentation.ts +0 -27
  122. package/src/api/endpoints/design-system/versions/ds-components.ts +0 -28
  123. package/src/api/endpoints/design-system/versions/elements-action.ts +0 -55
  124. package/src/api/endpoints/design-system/versions/elements.ts +0 -13
  125. package/src/api/endpoints/design-system/versions/figma-component-groups.ts +0 -13
  126. package/src/api/endpoints/design-system/versions/figma-components.ts +0 -13
  127. package/src/api/endpoints/design-system/versions/figma-frame-structures.ts +0 -13
  128. package/src/api/endpoints/design-system/versions/import-jobs.ts +0 -13
  129. package/src/api/endpoints/design-system/versions/index.ts +0 -18
  130. package/src/api/endpoints/design-system/versions/overrides.ts +0 -17
  131. package/src/api/endpoints/design-system/versions/property-definitions.ts +0 -43
  132. package/src/api/endpoints/design-system/versions/property-values.ts +0 -25
  133. package/src/api/endpoints/design-system/versions/stats.ts +0 -12
  134. package/src/api/endpoints/design-system/versions/themes.ts +0 -35
  135. package/src/api/endpoints/design-system/versions/token-collections.ts +0 -13
  136. package/src/api/endpoints/design-system/versions/token-groups.ts +0 -28
  137. package/src/api/endpoints/design-system/versions/tokens.ts +0 -27
  138. package/src/api/endpoints/design-system/versions/versions.ts +0 -79
  139. package/src/api/endpoints/index.ts +0 -5
  140. package/src/api/endpoints/liveblocks.ts +0 -14
  141. package/src/api/endpoints/users.ts +0 -26
  142. package/src/api/endpoints/workspaces/index.ts +0 -3
  143. package/src/api/endpoints/workspaces/workspace-invites.ts +0 -34
  144. package/src/api/endpoints/workspaces/workspace-members.ts +0 -31
  145. package/src/api/endpoints/workspaces/workspaces.ts +0 -47
  146. package/src/api/index.ts +0 -6
  147. package/src/api/payloads/design-systems/index.ts +0 -2
  148. package/src/api/payloads/design-systems/update-design-system.ts +0 -29
  149. package/src/api/payloads/design-systems/version.ts +0 -29
  150. package/src/api/payloads/documentation/block-definitions.ts +0 -12
  151. package/src/api/payloads/documentation/design-data-doc-diff.ts +0 -7
  152. package/src/api/payloads/documentation/index.ts +0 -2
  153. package/src/api/payloads/export/index.ts +0 -1
  154. package/src/api/payloads/export/pipeline.ts +0 -50
  155. package/src/api/payloads/index.ts +0 -6
  156. package/src/api/payloads/liveblocks/auth.ts +0 -7
  157. package/src/api/payloads/liveblocks/index.ts +0 -1
  158. package/src/api/payloads/users/index.ts +0 -2
  159. package/src/api/payloads/users/notifications/index.ts +0 -1
  160. package/src/api/payloads/users/notifications/notification-settings.ts +0 -17
  161. package/src/api/payloads/users/profile/index.ts +0 -1
  162. package/src/api/payloads/users/profile/update.ts +0 -4
  163. package/src/api/payloads/workspaces/index.ts +0 -3
  164. package/src/api/payloads/workspaces/transfer-ownership.ts +0 -7
  165. package/src/api/payloads/workspaces/workspace-configuration.ts +0 -50
  166. package/src/api/payloads/workspaces/workspace-integrations.ts +0 -26
  167. package/src/api/transport/index.ts +0 -2
  168. package/src/api/transport/request-executor-error.ts +0 -66
  169. package/src/api/transport/request-executor.ts +0 -87
  170. package/src/index.ts +0 -3
  171. package/src/utils/figma.ts +0 -53
  172. package/src/utils/hash.ts +0 -62
  173. package/src/utils/index.ts +0 -3
  174. package/src/utils/query.ts +0 -18
  175. package/src/yjs/design-system-content/documentation-hierarchy.ts +0 -35
  176. package/src/yjs/design-system-content/index.ts +0 -2
  177. package/src/yjs/design-system-content/item-configuration.ts +0 -93
  178. package/src/yjs/docs-editor/blocks-to-prosemirror.ts +0 -764
  179. package/src/yjs/docs-editor/index.ts +0 -7
  180. package/src/yjs/docs-editor/list-tree-builder.ts +0 -127
  181. package/src/yjs/docs-editor/mock.ts +0 -2104
  182. package/src/yjs/docs-editor/model/block.ts +0 -8
  183. package/src/yjs/docs-editor/model/index.ts +0 -2
  184. package/src/yjs/docs-editor/model/page.ts +0 -8
  185. package/src/yjs/docs-editor/prosemirror/index.ts +0 -3
  186. package/src/yjs/docs-editor/prosemirror/inner-editor-schema.ts +0 -145
  187. package/src/yjs/docs-editor/prosemirror/main-editor-schema.ts +0 -577
  188. package/src/yjs/docs-editor/prosemirror/types.ts +0 -19
  189. package/src/yjs/docs-editor/prosemirror-to-blocks.ts +0 -975
  190. package/src/yjs/docs-editor/utils.ts +0 -115
  191. package/src/yjs/index.ts +0 -3
  192. package/src/yjs/version-room/backend.ts +0 -78
  193. package/src/yjs/version-room/base.ts +0 -211
  194. package/src/yjs/version-room/frontend.ts +0 -461
  195. package/src/yjs/version-room/index.ts +0 -4
  196. package/src/yjs/version-room/utils.ts +0 -109
@@ -1,461 +0,0 @@
1
- import {
2
- DocumentationItemConfigurationV2,
3
- DocumentationPageSnapshot,
4
- DocumentationPageV2,
5
- ElementGroup,
6
- ElementGroupSnapshot,
7
- PageBlockDefinition,
8
- defaultDocumentationItemConfigurationV2,
9
- mapByUnique,
10
- pickLatestGroupSnapshots,
11
- pickLatestPageSnapshots,
12
- } from "@supernova-studio/model";
13
- import * as Y from "yjs";
14
- import {
15
- DTODocumentationDraftState,
16
- DTODocumentationDraftStateUpdated,
17
- DTODocumentationGroupApprovalState,
18
- DTODocumentationHierarchyV2,
19
- DTODocumentationPageApprovalState,
20
- documentationItemConfigurationToDTOV2,
21
- documentationPagesToDTOV2,
22
- elementGroupsToDocumentationGroupDTOV2,
23
- } from "../../api";
24
- import { DTODocumentationPublishMetadata } from "../../api/dto/elements/documentation/metadata";
25
- import { generateHash } from "../../utils";
26
- import { DocumentationPageEditorModel } from "../docs-editor";
27
- import { VersionRoomBaseYDoc } from "./base";
28
- import { generatePageContentHash } from "./utils";
29
-
30
- type ItemState = {
31
- title: string;
32
- configuration: DocumentationItemConfigurationV2;
33
- contentHash: string;
34
- };
35
-
36
- export class FrontendVersionRoomYDoc {
37
- private readonly yDoc: Y.Doc;
38
-
39
- constructor(yDoc: Y.Doc, private readonly debug = false) {
40
- this.yDoc = yDoc;
41
- }
42
-
43
- //
44
- // Hierarchy
45
- //
46
-
47
- getDocumentationHierarchy(options: { includeDeletedContent?: boolean } = {}): DTODocumentationHierarchyV2 {
48
- const includeDeletedContent = options.includeDeletedContent ?? false;
49
-
50
- const doc = new VersionRoomBaseYDoc(this.yDoc);
51
-
52
- // Read current room data
53
- const pages = doc.getPages();
54
- const groups = doc.getGroups();
55
- const pageSnapshots = doc.getPageSnapshots();
56
- const groupSnapshots = doc.getGroupSnapshots();
57
-
58
- if (includeDeletedContent) {
59
- pages.push(...this.getDeletedPages(pages, pageSnapshots));
60
- groups.push(...this.getDeletedGroups(groups, groupSnapshots));
61
- }
62
-
63
- const settings = doc.getDocumentationInternalSettings();
64
-
65
- // Convert pages to DTOs
66
- const pageDTOs = documentationPagesToDTOV2(pages, groups, settings.routingVersion);
67
- const groupDTOs = elementGroupsToDocumentationGroupDTOV2(groups, pages);
68
-
69
- // If draft feature is not yet adopted, no snapshot-based features should not be provided
70
- if (!settings.isDraftFeatureAdopted) {
71
- return {
72
- pages: pageDTOs,
73
- groups: groupDTOs,
74
- };
75
- }
76
-
77
- const pageDraftStates = this.buildPageDraftCreatedAndUpdatedStates(pages, pageSnapshots);
78
- const pageDraftDeletedStates = this.buildPageDraftDeletedStates(pages, pageSnapshots);
79
- const pagePublishedMetadata = this.buildPagePublishedMetadata(pages, pageSnapshots);
80
- const pageApprovalStates = this.buildPageApprovalStates(pages);
81
-
82
- pageDTOs.forEach(p => {
83
- // Assign draft state
84
- const draftState = pageDraftDeletedStates.get(p.id) ?? pageDraftStates.get(p.id);
85
- draftState && (p.draftState = draftState);
86
-
87
- // Assign publish metadata
88
- const publishMetadata = pagePublishedMetadata.get(p.id);
89
- publishMetadata && (p.publishMetadata = publishMetadata);
90
-
91
- // Assign approval state
92
- const approvalState = pageApprovalStates.get(p.id);
93
- approvalState && (p.approvalState = approvalState);
94
- });
95
-
96
- const groupDraftStates = this.buildGroupDraftCreatedAndUpdatedStates(groups, groupSnapshots);
97
- const groupDraftDeletedStates = this.buildGroupDraftDeletedStates(groups, groupSnapshots);
98
- const groupPublishedMetadata = this.buildGroupPublishedMetadata(groups, groupSnapshots);
99
- const groupApprovalStates = this.buildGroupApprovalStates(groups, groupSnapshots);
100
- groupDTOs.forEach(g => {
101
- // Assign draft state
102
- const draftState = groupDraftDeletedStates.get(g.id) ?? groupDraftStates.get(g.id);
103
- draftState && (g.draftState = draftState);
104
-
105
- // Assign publish metadata
106
- const publishMetadata = groupPublishedMetadata.get(g.id);
107
- publishMetadata && (g.publishMetadata = publishMetadata);
108
-
109
- const approvalState = groupApprovalStates.get(g.id);
110
- approvalState && (g.approvalState = approvalState);
111
- });
112
-
113
- return {
114
- pages: pageDTOs,
115
- groups: groupDTOs,
116
- };
117
- }
118
-
119
- //
120
- // Drafts - Pages
121
- //
122
-
123
- private buildPageDraftDeletedStates(
124
- pages: DocumentationPageV2[],
125
- pageSnapshots: DocumentationPageSnapshot[]
126
- ): Map<string, DTODocumentationDraftState> {
127
- const deletedSnapshotsByPageId = mapByUnique(
128
- pickLatestPageSnapshots(pageSnapshots.filter(s => s.reason === "Deletion")),
129
- s => s.page.id
130
- );
131
-
132
- const result = new Map<string, DTODocumentationDraftState>();
133
-
134
- pages.forEach(page => {
135
- const deletedSnapshot = deletedSnapshotsByPageId.get(page.id);
136
- if (!deletedSnapshot) return;
137
-
138
- result.set(page.id, {
139
- changeType: "Deleted",
140
- deletedAt: deletedSnapshot.createdAt,
141
- deletedByUserId: deletedSnapshot.createdByUserId,
142
- });
143
- });
144
-
145
- return result;
146
- }
147
-
148
- private buildPageDraftCreatedAndUpdatedStates(
149
- pages: DocumentationPageV2[],
150
- pageSnapshots: DocumentationPageSnapshot[]
151
- ): Map<string, DTODocumentationDraftState> {
152
- const doc = new VersionRoomBaseYDoc(this.yDoc);
153
-
154
- // Read room data
155
- const pageHashes = doc.getDocumentationPageContentHashes();
156
- const publishedSnapshots = pickLatestPageSnapshots(pageSnapshots.filter(s => s.reason === "Publish"));
157
-
158
- const publishedSnapshotsByPageId = mapByUnique(publishedSnapshots, s => s.page.id);
159
-
160
- const result = new Map<string, DTODocumentationDraftState>();
161
-
162
- pages.forEach(page => {
163
- // Published state
164
- const snapshot = publishedSnapshotsByPageId.get(page.id);
165
- let publishedState: ItemState | undefined;
166
- if (snapshot) {
167
- publishedState = this.itemStateFromPage(snapshot.page, snapshot.pageContentHash);
168
- }
169
-
170
- // Current state - if content hash is undefined, it means that the page hasn't changed
171
- const currentPageContentHash = pageHashes[page.persistentId] ?? snapshot?.pageContentHash ?? "";
172
- const currentState: ItemState = this.itemStateFromPage(page, currentPageContentHash);
173
-
174
- // Calculate draft
175
- const draftState = this.createDraftState(page.persistentId, currentState, publishedState);
176
- if (draftState) result.set(page.id, draftState);
177
- });
178
-
179
- return result;
180
- }
181
-
182
- private itemStateFromPage(page: DocumentationPageV2, pageContentHash: string): ItemState {
183
- return {
184
- title: page.meta.name,
185
- configuration: page.data.configuration ?? defaultDocumentationItemConfigurationV2,
186
- contentHash: pageContentHash,
187
- };
188
- }
189
-
190
- private getDeletedPages(
191
- pages: DocumentationPageV2[],
192
- pageSnapshots: DocumentationPageSnapshot[]
193
- ): DocumentationPageV2[] {
194
- const existingPageIds = new Set(pages.map(p => p.id));
195
- const latestSnapshots = pickLatestPageSnapshots(pageSnapshots);
196
- return latestSnapshots.filter(s => !existingPageIds.has(s.page.id)).map(s => s.page);
197
- }
198
-
199
- private buildPagePublishedMetadata(
200
- pages: DocumentationPageV2[],
201
- pageSnapshots: DocumentationPageSnapshot[]
202
- ): Map<string, DTODocumentationPublishMetadata> {
203
- const publishedPageSnapshotsById = mapByUnique(
204
- pickLatestPageSnapshots(pageSnapshots.filter(s => s.reason === "Publish")),
205
- s => s.page.id
206
- );
207
-
208
- const result = new Map<string, DTODocumentationPublishMetadata>();
209
-
210
- pages.forEach(p => {
211
- const publishedSnapshot = publishedPageSnapshotsById.get(p.id);
212
- if (!publishedSnapshot) return;
213
-
214
- result.set(p.id, {
215
- lastPublishedAt: publishedSnapshot.createdAt,
216
- lastPublishedByUserId: publishedSnapshot.createdByUserId,
217
- });
218
- });
219
-
220
- return result;
221
- }
222
-
223
- //
224
- // Drafts - Groups
225
- //
226
-
227
- private buildGroupDraftDeletedStates(
228
- groups: ElementGroup[],
229
- groupSnapshots: ElementGroupSnapshot[]
230
- ): Map<string, DTODocumentationDraftState> {
231
- const deletedSnapshotsByGroupId = mapByUnique(
232
- pickLatestGroupSnapshots(groupSnapshots.filter(s => s.reason === "Deletion")),
233
- s => s.group.id
234
- );
235
-
236
- const result = new Map<string, DTODocumentationDraftState>();
237
-
238
- groups.forEach(group => {
239
- if (!group.parentPersistentId) return;
240
-
241
- const deletedSnapshot = deletedSnapshotsByGroupId.get(group.id);
242
- if (!deletedSnapshot) return;
243
-
244
- result.set(group.id, {
245
- changeType: "Deleted",
246
- deletedAt: deletedSnapshot.createdAt,
247
- deletedByUserId: deletedSnapshot.createdByUserId,
248
- });
249
- });
250
-
251
- return result;
252
- }
253
-
254
- private buildGroupDraftCreatedAndUpdatedStates(
255
- groups: ElementGroup[],
256
- groupSnapshots: ElementGroupSnapshot[]
257
- ): Map<string, DTODocumentationDraftState> {
258
- // Read room data
259
- const publishedSnapshots = pickLatestGroupSnapshots(groupSnapshots.filter(s => s.reason === "Publish"));
260
-
261
- const publishedSnapshotsByGroupId = mapByUnique(publishedSnapshots, s => s.group.id);
262
-
263
- const result = new Map<string, DTODocumentationDraftState>();
264
-
265
- groups.forEach(group => {
266
- if (!group.parentPersistentId) return;
267
-
268
- // Current state
269
- const currentState: ItemState = this.itemStateFromGroup(group);
270
-
271
- // Published state
272
- const snapshot = publishedSnapshotsByGroupId.get(group.id);
273
- let publishedState: ItemState | undefined;
274
- if (snapshot) {
275
- publishedState = this.itemStateFromGroup(snapshot.group);
276
- }
277
-
278
- // Calculate draft
279
- const draftState = this.createDraftState(group.persistentId, currentState, publishedState);
280
- if (draftState) result.set(group.id, draftState);
281
- });
282
-
283
- return result;
284
- }
285
-
286
- private itemStateFromGroup(group: ElementGroup): ItemState {
287
- return {
288
- title: group.meta.name,
289
- configuration: group.data?.configuration ?? defaultDocumentationItemConfigurationV2,
290
- contentHash: "-",
291
- };
292
- }
293
-
294
- private getDeletedGroups(groups: ElementGroup[], groupSnapshots: ElementGroupSnapshot[]): ElementGroup[] {
295
- const existingGroupIds = new Set(groups.map(p => p.id));
296
- const latestSnapshots = pickLatestGroupSnapshots(groupSnapshots);
297
- return latestSnapshots.filter(s => !existingGroupIds.has(s.group.id)).map(s => s.group);
298
- }
299
-
300
- private buildGroupPublishedMetadata(
301
- groups: ElementGroup[],
302
- groupSnapshots: ElementGroupSnapshot[]
303
- ): Map<string, DTODocumentationPublishMetadata> {
304
- const publishedGroupSnapshotsById = mapByUnique(
305
- pickLatestGroupSnapshots(groupSnapshots.filter(s => s.reason === "Publish")),
306
- s => s.group.id
307
- );
308
-
309
- const result = new Map<string, DTODocumentationPublishMetadata>();
310
-
311
- groups.forEach(g => {
312
- if (!g.parentPersistentId) return;
313
-
314
- const publishedSnapshot = publishedGroupSnapshotsById.get(g.id);
315
- if (!publishedSnapshot) return;
316
-
317
- result.set(g.id, {
318
- lastPublishedAt: publishedSnapshot.createdAt,
319
- lastPublishedByUserId: publishedSnapshot.createdByUserId,
320
- });
321
- });
322
-
323
- return result;
324
- }
325
-
326
- //
327
- // Drafts - Shared
328
- //
329
-
330
- private createDraftState(
331
- itemPersistentId: string,
332
- currentState: ItemState,
333
- publishedState: ItemState | undefined
334
- ): DTODocumentationDraftState | undefined {
335
- if (!publishedState) {
336
- // New item (hasn't been published yet)
337
- return { changeType: "Created" };
338
- }
339
-
340
- // Compare current item state to the published state
341
- const updatedDraftState: DTODocumentationDraftStateUpdated = {
342
- changeType: "Updated",
343
- changes: {},
344
- };
345
-
346
- if (currentState.title !== publishedState.title) {
347
- if (this.debug) {
348
- console.log(`Item ${itemPersistentId} (${currentState.title}): updated title`);
349
- }
350
-
351
- updatedDraftState.changes.previousTitle = publishedState.title;
352
- }
353
-
354
- const currentConfigHash = generateHash(currentState.configuration, this.debug);
355
- const publishedConfigHash = generateHash(publishedState.configuration, this.debug);
356
-
357
- if (currentConfigHash !== publishedConfigHash) {
358
- if (this.debug) {
359
- console.log(`Item ${itemPersistentId} (${currentState.title}): updated configuration`);
360
- }
361
-
362
- const configurationDto = documentationItemConfigurationToDTOV2(publishedState.configuration);
363
- updatedDraftState.changes.previousConfiguration = configurationDto;
364
- }
365
-
366
- if (currentState.contentHash !== publishedState.contentHash) {
367
- if (this.debug) {
368
- console.log(`Item ${itemPersistentId} (${currentState.title}): updated content hash`);
369
- }
370
-
371
- updatedDraftState.changes.previousContentHash = publishedState.contentHash;
372
- }
373
-
374
- if (Object.keys(updatedDraftState.changes).length) {
375
- // Item has at least one of the draft changes
376
- return updatedDraftState;
377
- }
378
-
379
- // Item has no draft changes compared to the published item
380
- return undefined;
381
- }
382
-
383
- private buildGroupApprovalStates(groups: ElementGroup[], groupSnapshots: ElementGroupSnapshot[]) {
384
- const result = new Map<string, DTODocumentationGroupApprovalState>();
385
- const allGroups = [...groups, ...groupSnapshots];
386
- for (const g of allGroups) {
387
- const approvalState: DTODocumentationGroupApprovalState = {
388
- approvalState: "Approved",
389
- designSystemVersionId: g.designSystemVersionId,
390
- persistentId: g.persistentId,
391
- groupId: g.id,
392
- };
393
- result.set(g.id, approvalState);
394
- }
395
- return result;
396
- }
397
-
398
- //
399
- // Update page content hash
400
- //
401
-
402
- notifyDocumentationPageContentUpdated(
403
- pageId: string,
404
- content: DocumentationPageEditorModel,
405
- definitions: PageBlockDefinition[]
406
- ) {
407
- const pageContentHash = generatePageContentHash(content, definitions, this.debug);
408
- if (this.debug) {
409
- console.log(`Will set page content hash: '${pageId}' : '${pageContentHash}'`);
410
- }
411
-
412
- new VersionRoomBaseYDoc(this.yDoc).updateDocumentationPageContentHashes({
413
- [pageId]: pageContentHash,
414
- });
415
- }
416
-
417
- //
418
- // Misc
419
- //
420
-
421
- isDraftFeatureAdopted() {
422
- const doc = new VersionRoomBaseYDoc(this.yDoc);
423
- const settings = doc.getDocumentationInternalSettings();
424
- return settings.isDraftFeatureAdopted;
425
- }
426
-
427
- hasPublishedDocumentationContent() {
428
- const doc = new VersionRoomBaseYDoc(this.yDoc);
429
-
430
- return (
431
- doc.getPageSnapshots().filter(s => s.reason === "Publish").length > 0 ||
432
- doc.getGroupSnapshots().filter(s => s.reason === "Publish").length > 0
433
- );
434
- }
435
-
436
- isApprovalsFeatureEnabled() {
437
- const doc = new VersionRoomBaseYDoc(this.yDoc);
438
- const settings = doc.getDocumentationInternalSettings();
439
- return settings.isApprovalFeatureEnabled;
440
- }
441
-
442
- isApprovalRequiredForPublishing() {
443
- const doc = new VersionRoomBaseYDoc(this.yDoc);
444
- const settings = doc.getDocumentationInternalSettings();
445
- return settings.approvalRequiredForPublishing;
446
- }
447
-
448
- private buildPageApprovalStates(pages: DocumentationPageV2[]) {
449
- const doc = new VersionRoomBaseYDoc(this.yDoc);
450
- const pageIds = pages.map(p => p.id);
451
- const result = new Map<string, DTODocumentationPageApprovalState>();
452
- const approvals = doc.getApprovals();
453
- for (const pId of pageIds) {
454
- const approval = approvals.find(approval => approval.pageId === pId);
455
- if (approval) {
456
- result.set(pId, approval);
457
- }
458
- }
459
- return result;
460
- }
461
- }
@@ -1,4 +0,0 @@
1
- export * from "./backend";
2
- export * from "./base";
3
- export * from "./frontend";
4
- export * from "./utils";
@@ -1,109 +0,0 @@
1
- import {
2
- PageBlockDefinition,
3
- PageBlockDefinitionsMap,
4
- PageBlockItemMultiRichTextValue,
5
- PageBlockItemRichTextValue,
6
- PageBlockItemTableValue,
7
- PageBlockText,
8
- mapPageBlockItemValuesV2,
9
- removeCommentSpans,
10
- } from "@supernova-studio/model";
11
- import { generateHash } from "../../utils";
12
- import { DocumentationPageEditorModel } from "../docs-editor";
13
-
14
- export function generatePageContentHash(
15
- content: DocumentationPageEditorModel,
16
- definitions: PageBlockDefinition[],
17
- debug = false
18
- ) {
19
- let sanitizedContent = structuredClone(content);
20
-
21
- // Remove comment spans
22
- sanitizedContent = sanitizePageContents(sanitizedContent, definitions);
23
-
24
- // Make sure hashes of empty pages always match
25
- if (isPageContentEmpty(sanitizedContent)) {
26
- sanitizedContent = { blocks: [] };
27
- }
28
-
29
- return generateHash(sanitizedContent, debug);
30
- }
31
-
32
- /**
33
- * Empty page content can be one of the following:
34
- * - page without any blocks
35
- * - page with a single block, the block is a paragraph whithout any text
36
- */
37
- function isPageContentEmpty(content: DocumentationPageEditorModel): boolean {
38
- if (content.blocks.length > 1) return false;
39
- if (content.blocks.length < 1) return true;
40
-
41
- const singleBlock = content.blocks[0];
42
- if (singleBlock.type !== "Block" || singleBlock.data.packageId !== "io.supernova.block.rich-text") {
43
- return false;
44
- }
45
-
46
- const singleItem = singleBlock.data.items[0];
47
-
48
- // Block has no value, effectively the same as empty value
49
- if (!singleItem || !singleItem.props["text"]) return true;
50
-
51
- const textValue = singleItem.props["text"] as PageBlockItemRichTextValue;
52
- return !textValue.value.spans.length;
53
- }
54
-
55
- function sanitizePageContents(
56
- content: DocumentationPageEditorModel,
57
- definitions: PageBlockDefinition[]
58
- ): DocumentationPageEditorModel {
59
- const defMap = new PageBlockDefinitionsMap(definitions);
60
-
61
- mapPageBlockItemValuesV2(content.blocks, defMap, (block, item, prop, value) => {
62
- if (prop.type === "RichText") {
63
- const richTextValue = value as PageBlockItemRichTextValue;
64
- return {
65
- ...richTextValue,
66
- value: sanitizeRichText(richTextValue.value),
67
- };
68
- }
69
-
70
- if (prop.type === "MultiRichText") {
71
- const multiRichTextValue = value as PageBlockItemMultiRichTextValue;
72
- return {
73
- ...multiRichTextValue,
74
- value: multiRichTextValue.value.map(sanitizeRichText),
75
- };
76
- }
77
-
78
- if (prop.type === "Table") {
79
- const tableValue = value as PageBlockItemTableValue;
80
- tableValue.value.forEach(r => {
81
- r.cells.forEach(c => {
82
- c.nodes.forEach(n => {
83
- if (n.type === "RichText") {
84
- n.value = sanitizeRichText(n.value);
85
- }
86
- });
87
- });
88
- });
89
-
90
- return tableValue;
91
- }
92
-
93
- return value;
94
- });
95
-
96
- return content;
97
- }
98
-
99
- function sanitizeRichText(richText: PageBlockText): PageBlockText {
100
- return sortSpanAttributes(removeCommentSpans(richText));
101
- }
102
-
103
- function sortSpanAttributes(richText: PageBlockText) {
104
- richText.spans.forEach(s => {
105
- s.attributes.sort((lhs, rhs) => lhs.type.localeCompare(rhs.type));
106
- });
107
-
108
- return richText;
109
- }