@supernova-studio/client 0.15.0 → 0.17.0

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 (62) hide show
  1. package/dist/index.d.mts +35218 -4953
  2. package/dist/index.d.ts +35218 -4953
  3. package/dist/index.js +1167 -81
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +1195 -109
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +1 -1
  8. package/src/api/conversion/documentation/documentation-elements-to-hierarchy-v2-dto.ts +20 -0
  9. package/src/api/conversion/documentation/documentation-group-to-dto.ts +83 -0
  10. package/src/api/conversion/documentation/documentation-page-to-dto-utils.ts +54 -0
  11. package/src/api/conversion/documentation/documentation-page-v1-to-dto.ts +43 -0
  12. package/src/api/conversion/documentation/documentation-page-v2-to-dto.ts +57 -0
  13. package/src/api/conversion/documentation/index.ts +5 -0
  14. package/src/api/conversion/index.ts +1 -0
  15. package/src/api/dto/{design-system.ts → design-systems/design-system.ts} +6 -2
  16. package/src/api/dto/design-systems/index.ts +1 -0
  17. package/src/api/dto/documentation/index.ts +0 -0
  18. package/src/api/dto/elements/documentation/group-action.ts +66 -0
  19. package/src/api/dto/elements/documentation/group-bulk-action.ts +32 -0
  20. package/src/api/dto/elements/documentation/group.ts +85 -0
  21. package/src/api/dto/elements/documentation/index.ts +7 -0
  22. package/src/api/dto/elements/documentation/page-actions-v2.ts +66 -0
  23. package/src/api/dto/elements/documentation/page-bulk-action-v2.ts +33 -0
  24. package/src/api/dto/{documentation-v1.ts → elements/documentation/page-v1.ts} +4 -0
  25. package/src/api/dto/elements/documentation/page-v2.ts +87 -0
  26. package/src/api/dto/elements/elements-action-v2.ts +61 -0
  27. package/src/api/dto/elements/elements-bulk-action-v2.ts +25 -0
  28. package/src/api/dto/elements/index.ts +3 -0
  29. package/src/api/dto/index.ts +2 -3
  30. package/src/api/index.ts +2 -2
  31. package/src/api/payloads/documentation/block-definitions.ts +12 -0
  32. package/src/api/payloads/documentation/index.ts +1 -0
  33. package/src/api/payloads/index.ts +2 -0
  34. package/src/api/payloads/liveblocks/auth.ts +7 -0
  35. package/src/api/payloads/liveblocks/index.ts +1 -0
  36. package/src/index.ts +1 -2
  37. package/src/yjs/design-system-content/documentation-hierarchy.ts +100 -0
  38. package/src/yjs/index.ts +2 -0
  39. package/src/api/dto/documentation-v2.ts +0 -28
  40. package/src/api/dto/documentation.ts +0 -29
  41. package/src/api/requests/elements/elements-transaction-v2.ts +0 -53
  42. package/src/api/requests/elements/index.ts +0 -1
  43. package/src/api/requests/index.ts +0 -2
  44. package/src/api/requests/post-liveblocks-auth.ts +0 -4
  45. package/src/api/responses/elements/elements-transaction-v2.ts +0 -11
  46. package/src/api/responses/elements/index.ts +0 -1
  47. package/src/api/responses/get-block-definitions.ts +0 -8
  48. package/src/api/responses/index.ts +0 -2
  49. package/src/design-system-content/documentation-hierarchy.ts +0 -74
  50. /package/src/{design-system-content → yjs/design-system-content}/index.ts +0 -0
  51. /package/src/{design-system-content → yjs/design-system-content}/item-configuration.ts +0 -0
  52. /package/src/{docs-editor → yjs/docs-editor}/blocks-to-prosemirror.ts +0 -0
  53. /package/src/{docs-editor → yjs/docs-editor}/index.ts +0 -0
  54. /package/src/{docs-editor → yjs/docs-editor}/mock.ts +0 -0
  55. /package/src/{docs-editor → yjs/docs-editor}/model/block.ts +0 -0
  56. /package/src/{docs-editor → yjs/docs-editor}/model/index.ts +0 -0
  57. /package/src/{docs-editor → yjs/docs-editor}/model/page.ts +0 -0
  58. /package/src/{docs-editor → yjs/docs-editor}/prosemirror/index.ts +0 -0
  59. /package/src/{docs-editor → yjs/docs-editor}/prosemirror/schema.ts +0 -0
  60. /package/src/{docs-editor → yjs/docs-editor}/prosemirror/types.ts +0 -0
  61. /package/src/{docs-editor → yjs/docs-editor}/prosemirror-to-blocks.ts +0 -0
  62. /package/src/{docs-editor → yjs/docs-editor}/utils.ts +0 -0
@@ -0,0 +1,87 @@
1
+ import { z } from "zod";
2
+ import { DocumentationItemConfiguration as DocumentationItemConfigurationV2 } from "@supernova-studio/model";
3
+ import { DocumentationPageV2 } from "@supernova-studio/model";
4
+ import { DTODocumentationGroupStructure } from "./group";
5
+
6
+ //
7
+ // Read
8
+ //
9
+
10
+ /**
11
+ * Structure DTO is element properties minus element data (in other words data required
12
+ * to display the element in the left panel)
13
+ */
14
+ export const DTODocumentationPageStructureV2 = DocumentationPageV2.omit({
15
+ data: true,
16
+ meta: true,
17
+ parentPersistentId: true,
18
+ sortOrder: true,
19
+ }).extend({
20
+ title: z.string(),
21
+ path: z.string(),
22
+ });
23
+
24
+ export const DTODocumentationPageV2 = DTODocumentationPageStructureV2.extend({
25
+ configuration: DocumentationItemConfigurationV2,
26
+ });
27
+
28
+ export const DTODocumentationHierarchyV2 = z.object({
29
+ pages: z.array(DTODocumentationPageStructureV2),
30
+ groups: z.array(DTODocumentationGroupStructure),
31
+ });
32
+
33
+ export type DTODocumentationPageV2 = z.infer<typeof DTODocumentationPageV2>;
34
+ export type DTODocumentationPageStructureV2 = z.infer<typeof DTODocumentationPageStructureV2>;
35
+ export type DTODocumentationHierarchyV2 = z.infer<typeof DTODocumentationHierarchyV2>;
36
+
37
+ //
38
+ // Write
39
+ //
40
+
41
+ export const DTOCreateDocumentationPageInputV2 = z.object({
42
+ // Identifier
43
+ persistentId: z.string().uuid(),
44
+
45
+ // Page properties
46
+ title: z.string(),
47
+ configuration: DocumentationItemConfigurationV2.optional(),
48
+
49
+ // Page placement properties
50
+ parentPersistentId: z.string().uuid(),
51
+ afterPersistentId: z.string().uuid().optional(),
52
+ });
53
+
54
+ export const DTOUpdateDocumentationPageInputV2 = z.object({
55
+ // Identifier of the group to update
56
+ id: z.string(),
57
+
58
+ // Page properties
59
+ title: z.string().optional(),
60
+ configuration: DocumentationItemConfigurationV2.optional(),
61
+
62
+ // Page placement properties
63
+ parentPersistentId: z.string().optional(),
64
+ afterPersistentId: z.string().optional(),
65
+ });
66
+
67
+ export const DTODuplicateDocumentationPageInputV2 = z.object({
68
+ // Identifier of the page to duplicate from
69
+ id: z.string(),
70
+
71
+ // New page persistent id
72
+ persistentId: z.string().uuid(),
73
+
74
+ // Page placement properties
75
+ parentPersistentId: z.string().uuid(),
76
+ afterPersistentId: z.string().uuid().optional(),
77
+ });
78
+
79
+ export const DTODeleteDocumentationPageInputV2 = z.object({
80
+ // Identifier
81
+ id: z.string(),
82
+ });
83
+
84
+ export type DTOCreateDocumentationPageInputV2 = z.infer<typeof DTOCreateDocumentationPageInputV2>;
85
+ export type DTOUpdateDocumentationPageInputV2 = z.infer<typeof DTOUpdateDocumentationPageInputV2>;
86
+ export type DTODuplicateDocumentationPageInputV2 = z.infer<typeof DTODuplicateDocumentationPageInputV2>;
87
+ export type DTODeleteDocumentationPageInputV2 = z.infer<typeof DTODeleteDocumentationPageInputV2>;
@@ -0,0 +1,61 @@
1
+ import { z } from "zod";
2
+ import {
3
+ DTODocumentationPageCreateActionInputV2,
4
+ DTODocumentationPageCreateActionOutputV2,
5
+ DTODocumentationPageDeleteActionInputV2,
6
+ DTODocumentationPageDeleteActionOutputV2,
7
+ DTODocumentationPageDuplicateActionInputV2,
8
+ DTODocumentationPageDuplicateActionOutputV2,
9
+ DTODocumentationPageUpdateActionInputV2,
10
+ DTODocumentationPageUpdateActionOutputV2,
11
+ } from "./documentation/page-actions-v2";
12
+ import {
13
+ DTODocumentationGroupCreateActionInputV2,
14
+ DTODocumentationGroupCreateActionOutputV2,
15
+ DTODocumentationGroupDeleteActionInputV2,
16
+ DTODocumentationGroupDeleteActionOutputV2,
17
+ DTODocumentationGroupDuplicateActionInputV2,
18
+ DTODocumentationGroupDuplicateActionOutputV2,
19
+ DTODocumentationGroupUpdateActionInputV2,
20
+ DTODocumentationGroupUpdateActionOutputV2,
21
+ } from "./documentation/group-action";
22
+
23
+ //
24
+ // Read
25
+ //
26
+
27
+ export const DTOElementActionOutput = z.discriminatedUnion("type", [
28
+ // Documentation pages
29
+ DTODocumentationPageCreateActionOutputV2,
30
+ DTODocumentationPageUpdateActionOutputV2,
31
+ DTODocumentationPageDuplicateActionOutputV2,
32
+ DTODocumentationPageDeleteActionOutputV2,
33
+
34
+ // Documentation groups
35
+ DTODocumentationGroupCreateActionOutputV2,
36
+ DTODocumentationGroupUpdateActionOutputV2,
37
+ DTODocumentationGroupDuplicateActionOutputV2,
38
+ DTODocumentationGroupDeleteActionOutputV2,
39
+ ]);
40
+
41
+ export type DTOElementActionOutput = z.infer<typeof DTOElementActionOutput>;
42
+
43
+ //
44
+ // Write
45
+ //
46
+
47
+ export const DTOElementActionInput = z.discriminatedUnion("type", [
48
+ // Documentation pages
49
+ DTODocumentationPageCreateActionInputV2,
50
+ DTODocumentationPageUpdateActionInputV2,
51
+ DTODocumentationPageDuplicateActionInputV2,
52
+ DTODocumentationPageDeleteActionInputV2,
53
+
54
+ // Documentation groups
55
+ DTODocumentationGroupCreateActionInputV2,
56
+ DTODocumentationGroupUpdateActionInputV2,
57
+ DTODocumentationGroupDuplicateActionInputV2,
58
+ DTODocumentationGroupDeleteActionInputV2,
59
+ ]);
60
+
61
+ export type DTOElementActionInput = z.infer<typeof DTOElementActionInput>;
@@ -0,0 +1,25 @@
1
+ import { z } from "zod";
2
+ import {
3
+ DTODocumentationPageBulkActionInputV2,
4
+ DTODocumentationPageBulkActionOutputV2,
5
+ } from "./documentation/page-bulk-action-v2";
6
+
7
+ //
8
+ // Read
9
+ //
10
+
11
+ export const DTOElementsBulkActionOutputV2 = z.object({
12
+ documentationPages: DTODocumentationPageBulkActionOutputV2,
13
+ });
14
+
15
+ export type DTOElementsBulkActionOutputV2 = z.infer<typeof DTOElementsBulkActionOutputV2>;
16
+
17
+ //
18
+ // Write
19
+ //
20
+
21
+ export const DTOElementsBulkActionInputV2 = z.object({
22
+ documentationPages: DTODocumentationPageBulkActionInputV2,
23
+ });
24
+
25
+ export type DTOElementsBulkActionInputV2 = z.infer<typeof DTOElementsBulkActionInputV2>;
@@ -0,0 +1,3 @@
1
+ export * from "./documentation";
2
+ export * from "./elements-action-v2";
3
+ export * from "./elements-bulk-action-v2";
@@ -1,4 +1,3 @@
1
- export * from "./design-system";
2
- export * from "./documentation-v1";
3
- export * from "./documentation-v2";
1
+ export * from "./design-systems";
4
2
  export * from "./documentation";
3
+ export * from "./elements";
package/src/api/index.ts CHANGED
@@ -1,3 +1,3 @@
1
+ export * from "./conversion";
1
2
  export * from "./dto";
2
- export * from "./requests";
3
- export * from "./responses";
3
+ export * from "./payloads";
@@ -0,0 +1,12 @@
1
+ import { PageBlockDefinition } from "@supernova-studio/model";
2
+ import { z } from "zod";
3
+
4
+ //
5
+ // Read
6
+ //
7
+
8
+ export const DTOGetBlockDefinitionsOutput = z.object({
9
+ definitions: z.array(PageBlockDefinition),
10
+ });
11
+
12
+ export type DTOGetBlockDefinitionsOutput = z.infer<typeof DTOGetBlockDefinitionsOutput>;
@@ -0,0 +1 @@
1
+ export * from "./block-definitions";
@@ -0,0 +1,2 @@
1
+ export * from "./documentation";
2
+ export * from "./liveblocks";
@@ -0,0 +1,7 @@
1
+ import { z } from "zod";
2
+
3
+ export const DTOLiveblocksAuthRequest = z.object({
4
+ room: z.string(),
5
+ });
6
+
7
+ export type DTOLiveblocksAuthRequest = z.infer<typeof DTOLiveblocksAuthRequest>;
@@ -0,0 +1 @@
1
+ export * from "./auth";
package/src/index.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from "./api";
2
- export * from "./design-system-content";
3
- export * from "./docs-editor";
2
+ export * from "./yjs";
@@ -0,0 +1,100 @@
1
+ import * as Y from "yjs";
2
+ import { DTODocumentationHierarchyV2, documentationElementsToHierarchyDto } from "../../api";
3
+ import { DocumentationPageV2, ElementGroup } from "@supernova-studio/model";
4
+
5
+ // We store pages and groups in the same way they are stored in the database.
6
+ // This means that instead of groups having childrenIds array, all items have
7
+ // parentPersistentId property that points to the parent item in the tree.
8
+ // Upon read this gets converted to the format that client expects, which is
9
+ // ordered childrenIds array on all groups.
10
+ //
11
+ // The decision behind it is that we potentially want to get rid of childrenIds
12
+ // array entirely because it makes group updates more complicated. For now
13
+ // resolving it on fly is a tradeoff for not rewriting client to stop relying
14
+ // on children ids array.
15
+
16
+ //
17
+ // Types
18
+ //
19
+
20
+ type DocumentationHierarchyTransaction = {
21
+ pages: DocumentationPageV2[];
22
+ groups: ElementGroup[];
23
+ pageIdsToDelete: string[];
24
+ groupIdsToDelete: string[];
25
+ };
26
+
27
+ //
28
+ // Init
29
+ //
30
+
31
+ export function documentationHierarchyToYjs(doc: Y.Doc, transaction: DocumentationHierarchyTransaction) {
32
+ doc.transact(trx => {
33
+ // Pages
34
+ const pagesMap = getPagesYMap(trx.doc);
35
+
36
+ transaction.pageIdsToDelete.forEach(pageId => {
37
+ pagesMap.delete(pageId);
38
+ });
39
+
40
+ transaction.pages.forEach(page => {
41
+ // We remove header from the payload here because it will not get parsed anyway
42
+ const sanitizedPage: DocumentationPageV2 = {
43
+ ...page,
44
+ data: {},
45
+ };
46
+
47
+ pagesMap.set(page.id, sanitizedPage);
48
+ });
49
+
50
+ // Groups
51
+ const groupsMap = getGroupsYMap(trx.doc);
52
+
53
+ transaction.groupIdsToDelete.forEach(id => {
54
+ groupsMap.delete(id);
55
+ });
56
+
57
+ transaction.groups.forEach(group => {
58
+ // We remove header from the payload here because it will not get parsed anyway
59
+ const sanitizedGroup: ElementGroup = {
60
+ ...group,
61
+ data: {},
62
+ };
63
+
64
+ groupsMap.set(group.id, group);
65
+ });
66
+ });
67
+
68
+ return doc;
69
+ }
70
+
71
+ export function yjsToDocumentationHierarchy(doc: Y.Doc): DTODocumentationHierarchyV2 {
72
+ const pagesMap = getPagesYMap(doc);
73
+ const groupsMap = getGroupsYMap(doc);
74
+
75
+ const pages: DocumentationPageV2[] = [];
76
+ pagesMap.forEach(page => {
77
+ pages.push(DocumentationPageV2.parse(page));
78
+ });
79
+
80
+ const groups: ElementGroup[] = [];
81
+ groupsMap.forEach(group => {
82
+ groups.push(ElementGroup.parse(group));
83
+ });
84
+
85
+ const hierarchy = documentationElementsToHierarchyDto(pages, groups);
86
+
87
+ return hierarchy;
88
+ }
89
+
90
+ //
91
+ // Internals
92
+ //
93
+
94
+ function getPagesYMap(doc: Y.Doc) {
95
+ return doc.getMap<DocumentationPageV2>("documentationPages");
96
+ }
97
+
98
+ function getGroupsYMap(doc: Y.Doc) {
99
+ return doc.getMap<ElementGroup>("documentationGroups");
100
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./design-system-content";
2
+ export * from "./docs-editor";
@@ -1,28 +0,0 @@
1
- import { z } from "zod";
2
- import { DocumentationPageV2 } from "@supernova-studio/model";
3
- import { DocumentationGroupStructureDTO } from "./documentation";
4
-
5
- /**
6
- * Structure DTO is element properties minus element data (in other words data required
7
- * to display the element in the left panel)
8
- */
9
- export const DTODocumentationPageStructureV2 = DocumentationPageV2.omit({
10
- data: true,
11
- meta: true,
12
- parentPersistentId: true,
13
- sortOrder: true,
14
- }).extend({
15
- title: z.string(),
16
- path: z.string(),
17
- });
18
-
19
- export const DTODocumentationPageV2 = DTODocumentationPageStructureV2.extend(DocumentationPageV2.shape.data.shape);
20
-
21
- export const DTODocumentationHierarchyV2 = z.object({
22
- pages: z.array(DTODocumentationPageStructureV2),
23
- groups: z.array(DocumentationGroupStructureDTO),
24
- });
25
-
26
- export type DTODocumentationPageV2 = z.infer<typeof DTODocumentationPageV2>;
27
- export type DTODocumentationPageStructureV2 = z.infer<typeof DTODocumentationPageStructureV2>;
28
- export type DTODocumentationHierarchyV2 = z.infer<typeof DTODocumentationHierarchyV2>;
@@ -1,29 +0,0 @@
1
- import { z } from "zod";
2
- import { DocumentationGroupBehavior, DocumentationItemConfiguration, ElementGroup } from "@supernova-studio/model";
3
-
4
- /**
5
- * Structure DTO is element properties minus element data (in other words data required
6
- * to display the element in the left panel)
7
- */
8
- export const DocumentationGroupStructureDTO = ElementGroup.omit({
9
- sortOrder: true,
10
- parentPersistentId: true,
11
- brandPersistentId: true,
12
- meta: true,
13
- childType: true,
14
- data: true,
15
- shortPersistentId: true,
16
- }).extend({
17
- title: z.string(),
18
- isRoot: z.boolean(),
19
- childrenIds: z.array(z.string()),
20
- groupBehavior: DocumentationGroupBehavior,
21
- shortPersistentId: z.string(),
22
- });
23
-
24
- export const DocumentationGroupDTO = DocumentationGroupStructureDTO.extend({
25
- configuration: DocumentationItemConfiguration,
26
- });
27
-
28
- export type DocumentationGroupStructureDTO = z.infer<typeof DocumentationGroupStructureDTO>;
29
- export type DocumentationGroupDTO = z.infer<typeof DocumentationGroupDTO>;
@@ -1,53 +0,0 @@
1
- import { z } from "zod";
2
-
3
- import { DocumentationItemConfiguration } from "@supernova-studio/model";
4
-
5
- //
6
- // Documentation Pages
7
- //
8
-
9
- export const DTOCreateDocumentationPageInput = z.object({
10
- parentPersistentId: z.string().uuid(),
11
- persistentId: z.string().uuid(),
12
- title: z.string(),
13
- configuration: DocumentationItemConfiguration.optional(),
14
- afterPersistentId: z.string().uuid().optional(),
15
- });
16
-
17
- export const DTOUpdateDocumentationPageInput = z.object({
18
- id: z.string(),
19
- title: z.string().optional(),
20
- configuration: DocumentationItemConfiguration.optional(),
21
- parentPersistentId: z.string().optional(),
22
- afterPersistentId: z.string().optional(),
23
- });
24
-
25
- export const DTODuplicateDocumentationPageInput = z.object({
26
- id: z.string(),
27
- persistentId: z.string().uuid(),
28
- parentPersistentId: z.string().uuid(),
29
- afterPersistentId: z.string().uuid().optional(),
30
- });
31
-
32
- export const DTODocumentationTransactionInput = z.object({
33
- create: z.array(DTOCreateDocumentationPageInput).optional(),
34
- update: z.array(DTOUpdateDocumentationPageInput).optional(),
35
- duplicate: z.array(DTODuplicateDocumentationPageInput).optional(),
36
- delete: z.array(z.string()).optional(),
37
- });
38
-
39
- export type DTOCreateDocumentationPageInput = z.infer<typeof DTOCreateDocumentationPageInput>;
40
- export type DTOUpdateDocumentationPageInput = z.infer<typeof DTOUpdateDocumentationPageInput>;
41
- export type DTODuplicateDocumentationPageInput = z.infer<typeof DTODuplicateDocumentationPageInput>;
42
-
43
- export type DTODocumentationTransactionInput = z.infer<typeof DTODocumentationTransactionInput>;
44
-
45
- //
46
- // Transaction
47
- //
48
-
49
- export const DTOElementsTransactionInput = z.object({
50
- documentationPages: DTODocumentationTransactionInput,
51
- });
52
-
53
- export type DTOElementsTransactionInput = z.infer<typeof DTOElementsTransactionInput>;
@@ -1 +0,0 @@
1
- export * from "./elements-transaction-v2";
@@ -1,2 +0,0 @@
1
- export * from "./elements";
2
- export * from "./post-liveblocks-auth";
@@ -1,4 +0,0 @@
1
- import { z } from "zod";
2
- export const PostLiveblocksAuth = z.object({
3
- room: z.string(),
4
- });
@@ -1,11 +0,0 @@
1
- import { DTODocumentationPageV2 } from "../../dto";
2
-
3
- export type DTODocumentationElementsTransactionOutput = {
4
- created: DTODocumentationPageV2[];
5
- updated: DTODocumentationPageV2[];
6
- deleted: string[];
7
- };
8
-
9
- export type DTOElementsTransactionOutput = {
10
- documentationPages: DTODocumentationElementsTransactionOutput;
11
- };
@@ -1 +0,0 @@
1
- export * from "./elements-transaction-v2";
@@ -1,8 +0,0 @@
1
- import { PageBlockDefinition } from "@supernova-studio/model";
2
- import { z } from "zod";
3
-
4
- export const GetBlockDefinitionsResponse = z.object({
5
- definitions: z.array(PageBlockDefinition),
6
- });
7
-
8
- export type GetBlockDefinitionsResponse = z.infer<typeof GetBlockDefinitionsResponse>;
@@ -1,2 +0,0 @@
1
- export * from "./elements";
2
- export * from "./get-block-definitions";
@@ -1,74 +0,0 @@
1
- import * as Y from "yjs";
2
- import { DTODocumentationHierarchyV2, DTODocumentationPageStructureV2 } from "../api/dto/documentation-v2";
3
- import { DocumentationGroupStructureDTO } from "../api";
4
-
5
- //
6
- // Types
7
- //
8
-
9
- type ItemsToDelete = {
10
- pagePersistentIdsToDelete: string[];
11
- groupPersistentIdsToDelete: string[];
12
- };
13
-
14
- //
15
- // Init
16
- //
17
-
18
- export function documentationHierarchyToYjs(
19
- doc: Y.Doc,
20
- documentationHierarchy: DTODocumentationHierarchyV2,
21
- itemsToDelete: ItemsToDelete
22
- ) {
23
- doc.transact(trx => {
24
- const pagesMap = getPagesYMap(trx.doc);
25
- itemsToDelete.pagePersistentIdsToDelete.forEach(persistentId => {
26
- pagesMap.delete(persistentId);
27
- });
28
- documentationHierarchy.pages.forEach(page => {
29
- pagesMap.set(page.persistentId, page);
30
- });
31
-
32
- const groupsMap = getGroupsYMap(trx.doc);
33
- itemsToDelete.groupPersistentIdsToDelete.forEach(persistentId => {
34
- groupsMap.delete(persistentId);
35
- });
36
- documentationHierarchy.groups.forEach(group => {
37
- groupsMap.set(group.persistentId, group);
38
- });
39
- });
40
-
41
- return doc;
42
- }
43
-
44
- export function yjsToDocumentationHierarchy(doc: Y.Doc): DTODocumentationHierarchyV2 {
45
- const pagesMap = getPagesYMap(doc);
46
- const groupsMap = getGroupsYMap(doc);
47
-
48
- const pages: DTODocumentationPageStructureV2[] = [];
49
- pagesMap.forEach(page => {
50
- pages.push(DTODocumentationPageStructureV2.parse(page));
51
- });
52
-
53
- const groups: DocumentationGroupStructureDTO[] = [];
54
- groupsMap.forEach(group => {
55
- groups.push(DocumentationGroupStructureDTO.parse(group));
56
- });
57
-
58
- return {
59
- pages,
60
- groups,
61
- };
62
- }
63
-
64
- //
65
- // Internals
66
- //
67
-
68
- function getPagesYMap(doc: Y.Doc) {
69
- return doc.getMap<DTODocumentationPageStructureV2>("documentationPages");
70
- }
71
-
72
- function getGroupsYMap(doc: Y.Doc) {
73
- return doc.getMap<DocumentationGroupStructureDTO>("documentationGroups");
74
- }
File without changes
File without changes
File without changes