@supernova-studio/client 0.36.2 → 0.38.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.
- package/dist/index.d.mts +2231 -997
- package/dist/index.d.ts +2231 -997
- package/dist/index.js +358 -175
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +531 -348
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/api/conversion/design-systems/elements/properties/property-value.ts +2 -2
- package/src/api/conversion/design-systems/index.ts +1 -1
- package/src/api/conversion/documentation/documentation-elements-to-hierarchy-v2-dto.ts +6 -5
- package/src/api/conversion/documentation/documentation-group-v1-to-dto.ts +85 -0
- package/src/api/conversion/documentation/{documentation-group-to-dto.ts → documentation-group-v2-to-dto.ts} +16 -12
- package/src/api/conversion/documentation/documentation-item-configuration-v1-to-dto.ts +46 -0
- package/src/api/conversion/documentation/documentation-page-to-dto-utils.ts +16 -5
- package/src/api/conversion/documentation/documentation-page-v1-to-dto.ts +12 -10
- package/src/api/conversion/documentation/documentation-page-v2-to-dto.ts +9 -7
- package/src/api/conversion/documentation/index.ts +3 -1
- package/src/api/conversion/index.ts +1 -1
- package/src/api/dto/design-systems/index.ts +2 -2
- package/src/api/dto/elements/documentation/group-action.ts +1 -1
- package/src/api/dto/elements/documentation/group-v1.ts +35 -0
- package/src/api/dto/elements/documentation/index.ts +3 -1
- package/src/api/dto/elements/documentation/item-configuration-v1.ts +22 -0
- package/src/api/dto/elements/documentation/page-v1.ts +8 -7
- package/src/api/dto/elements/documentation/page-v2.ts +2 -3
- package/src/yjs/design-system-content/documentation-hierarchy.ts +47 -2
- package/src/yjs/docs-editor/mock.ts +13 -13
- package/src/yjs/docs-editor/prosemirror-to-blocks.ts +1 -1
- /package/src/api/dto/elements/documentation/{group.ts → group-v2.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ElementPropertyValue
|
|
1
|
+
import { ElementPropertyValue } from "@supernova-studio/model";
|
|
2
2
|
import { DTOElementPropertyValue } from "packages/client/src/api/dto/elements/properties/property-values";
|
|
3
3
|
|
|
4
4
|
export function elementPropertyValueToDto(elementPropertyValue: ElementPropertyValue): DTOElementPropertyValue {
|
|
@@ -15,7 +15,7 @@ export function elementPropertyValueToDto(elementPropertyValue: ElementPropertyV
|
|
|
15
15
|
value = elementPropertyValue.referenceValue;
|
|
16
16
|
valuePreview = elementPropertyValue.referenceValuePreview;
|
|
17
17
|
} else {
|
|
18
|
-
|
|
18
|
+
value = undefined;
|
|
19
19
|
}
|
|
20
20
|
return {
|
|
21
21
|
id: elementPropertyValue.id,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { documentationPagesToStructureDTOV2 } from "./documentation-page-v2-to-dto";
|
|
2
|
-
import { elementGroupsToDocumentationGroupStructureDTO } from "./documentation-group-to-dto";
|
|
3
1
|
import { DocumentationPageV2, ElementGroup } from "@supernova-studio/model";
|
|
4
2
|
import { DTODocumentationHierarchyV2 } from "../../dto";
|
|
3
|
+
import { elementGroupsToDocumentationGroupStructureDTOV2 } from "./documentation-group-v2-to-dto";
|
|
4
|
+
import { documentationPagesToStructureDTOV2 } from "./documentation-page-v2-to-dto";
|
|
5
5
|
|
|
6
6
|
// The fact that DTO conversion is located here instead of main backend code is due to the fact
|
|
7
7
|
// that we store page and group data in YJS documents in the same way as they are stored in the database.
|
|
@@ -11,10 +11,11 @@ import { DTODocumentationHierarchyV2 } from "../../dto";
|
|
|
11
11
|
|
|
12
12
|
export function documentationElementsToHierarchyDto(
|
|
13
13
|
docPages: DocumentationPageV2[],
|
|
14
|
-
docGroups: ElementGroup[]
|
|
14
|
+
docGroups: ElementGroup[],
|
|
15
|
+
routingVersion: string
|
|
15
16
|
): DTODocumentationHierarchyV2 {
|
|
16
17
|
return {
|
|
17
|
-
pages: documentationPagesToStructureDTOV2(docPages, docGroups),
|
|
18
|
-
groups:
|
|
18
|
+
pages: documentationPagesToStructureDTOV2(docPages, docGroups, routingVersion),
|
|
19
|
+
groups: elementGroupsToDocumentationGroupStructureDTOV2(docGroups, docPages),
|
|
19
20
|
};
|
|
20
21
|
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { DocumentationGroupV1, DocumentationPageV1, DocumentationPageV2, groupBy } from "@supernova-studio/model";
|
|
2
|
+
import { DTODocumentationGroupStructureV1, DTODocumentationGroupV1 } from "../../dto/elements/documentation/group-v1";
|
|
3
|
+
import {
|
|
4
|
+
documentationItemConfigurationToDTOV1,
|
|
5
|
+
dtoDefaultItemConfigurationV1,
|
|
6
|
+
} from "./documentation-item-configuration-v1-to-dto";
|
|
7
|
+
|
|
8
|
+
// The fact that DTO conversion is located here instead of main backend code is due to the fact
|
|
9
|
+
// that we store page and group data in YJS documents in the same way as they are stored in the database.
|
|
10
|
+
// Therefore, we need to expose this conversion to the client so that it can consume data from YJS documents.
|
|
11
|
+
//
|
|
12
|
+
// Please do not put more DTO conversion here unless you know what you're doing.
|
|
13
|
+
|
|
14
|
+
export function elementGroupsToDocumentationGroupStructureDTOV1(
|
|
15
|
+
groups: DocumentationGroupV1[],
|
|
16
|
+
pages: (DocumentationPageV1 | DocumentationPageV2)[]
|
|
17
|
+
): DTODocumentationGroupStructureV1[] {
|
|
18
|
+
const childrenIdsMap = calculateChildrenIdsMapV1(pages, groups);
|
|
19
|
+
|
|
20
|
+
return groups.map(group => elementGroupToDocumentationGroupStructureDTOV1(group, childrenIdsMap));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function elementGroupsToDocumentationGroupDTOV1(
|
|
24
|
+
groups: DocumentationGroupV1[],
|
|
25
|
+
pages: (DocumentationPageV1 | DocumentationPageV2)[]
|
|
26
|
+
): DTODocumentationGroupV1[] {
|
|
27
|
+
const childrenIdsMap = calculateChildrenIdsMapV1(pages, groups);
|
|
28
|
+
|
|
29
|
+
return groups.map(group => {
|
|
30
|
+
return {
|
|
31
|
+
...elementGroupToDocumentationGroupStructureDTOV1(group, childrenIdsMap),
|
|
32
|
+
configuration: group.data?.configuration
|
|
33
|
+
? documentationItemConfigurationToDTOV1(group.data.configuration)
|
|
34
|
+
: dtoDefaultItemConfigurationV1,
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function elementGroupToDocumentationGroupStructureDTOV1(
|
|
40
|
+
group: DocumentationGroupV1,
|
|
41
|
+
childrenIdsMap: Map<string, string[]>
|
|
42
|
+
): DTODocumentationGroupStructureV1 {
|
|
43
|
+
const childrenIds = childrenIdsMap.get(group.persistentId) ?? [];
|
|
44
|
+
|
|
45
|
+
if (!group.shortPersistentId) {
|
|
46
|
+
throw new Error(`Short persistent id is required for docs groups, group id: ${group.id}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
id: group.id,
|
|
51
|
+
designSystemVersionId: group.designSystemVersionId,
|
|
52
|
+
persistentId: group.persistentId,
|
|
53
|
+
slug: group.slug,
|
|
54
|
+
userSlug: group.userSlug,
|
|
55
|
+
createdAt: group.createdAt,
|
|
56
|
+
updatedAt: group.updatedAt,
|
|
57
|
+
title: group.meta.name,
|
|
58
|
+
childrenIds: childrenIds,
|
|
59
|
+
isRoot: !group.parentPersistentId,
|
|
60
|
+
groupBehavior: group.data?.behavior ?? "Group",
|
|
61
|
+
shortPersistentId: group.shortPersistentId,
|
|
62
|
+
type: "Group",
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function calculateChildrenIdsMapV1(
|
|
67
|
+
elements: { persistentId: string; parentPersistentId: string; sortOrder: number }[],
|
|
68
|
+
groups: DocumentationGroupV1[]
|
|
69
|
+
): Map<string, string[]> {
|
|
70
|
+
const byParentId = groupBy([...elements, ...groups], e => e.parentPersistentId);
|
|
71
|
+
|
|
72
|
+
const childrenIdsMap = new Map<string, string[]>();
|
|
73
|
+
|
|
74
|
+
for (const [parentPersistentId, children] of byParentId) {
|
|
75
|
+
if (!parentPersistentId) continue;
|
|
76
|
+
children.sort((lhs, rhs) => lhs.sortOrder - rhs.sortOrder);
|
|
77
|
+
|
|
78
|
+
childrenIdsMap.set(
|
|
79
|
+
parentPersistentId,
|
|
80
|
+
children.map(c => c.persistentId)
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return childrenIdsMap;
|
|
85
|
+
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {
|
|
2
|
+
defaultDocumentationItemHeaderV2,
|
|
3
|
+
DocumentationPageV1,
|
|
4
|
+
DocumentationPageV2,
|
|
5
|
+
ElementGroup,
|
|
6
|
+
groupBy,
|
|
7
|
+
} from "@supernova-studio/model";
|
|
8
|
+
import { DTODocumentationGroupStructureV2, DTODocumentationGroupV2 } from "../../dto";
|
|
5
9
|
|
|
6
10
|
// The fact that DTO conversion is located here instead of main backend code is due to the fact
|
|
7
11
|
// that we store page and group data in YJS documents in the same way as they are stored in the database.
|
|
@@ -9,24 +13,24 @@ import { DTODocumentationGroupV2, DTODocumentationGroupStructureV2 } from "../..
|
|
|
9
13
|
//
|
|
10
14
|
// Please do not put more DTO conversion here unless you know what you're doing.
|
|
11
15
|
|
|
12
|
-
export function
|
|
16
|
+
export function elementGroupsToDocumentationGroupStructureDTOV2(
|
|
13
17
|
groups: ElementGroup[],
|
|
14
18
|
pages: (DocumentationPageV1 | DocumentationPageV2)[]
|
|
15
19
|
): DTODocumentationGroupStructureV2[] {
|
|
16
|
-
const childrenIdsMap =
|
|
20
|
+
const childrenIdsMap = calculateChildrenIdsMapV2(pages, groups);
|
|
17
21
|
|
|
18
|
-
return groups.map(group =>
|
|
22
|
+
return groups.map(group => elementGroupToDocumentationGroupStructureDTOV2(group, childrenIdsMap));
|
|
19
23
|
}
|
|
20
24
|
|
|
21
|
-
export function
|
|
25
|
+
export function elementGroupsToDocumentationGroupDTOV2(
|
|
22
26
|
groups: ElementGroup[],
|
|
23
27
|
pages: (DocumentationPageV1 | DocumentationPageV2)[]
|
|
24
28
|
): DTODocumentationGroupV2[] {
|
|
25
|
-
const childrenIdsMap =
|
|
29
|
+
const childrenIdsMap = calculateChildrenIdsMapV2(pages, groups);
|
|
26
30
|
|
|
27
31
|
return groups.map(group => {
|
|
28
32
|
return {
|
|
29
|
-
...
|
|
33
|
+
...elementGroupToDocumentationGroupStructureDTOV2(group, childrenIdsMap),
|
|
30
34
|
configuration: group.data?.configuration ?? {
|
|
31
35
|
showSidebar: true,
|
|
32
36
|
header: defaultDocumentationItemHeaderV2,
|
|
@@ -35,7 +39,7 @@ export function elementGroupsToDocumentationGroupDTO(
|
|
|
35
39
|
});
|
|
36
40
|
}
|
|
37
41
|
|
|
38
|
-
function
|
|
42
|
+
function elementGroupToDocumentationGroupStructureDTOV2(
|
|
39
43
|
group: ElementGroup,
|
|
40
44
|
childrenIdsMap: Map<string, string[]>
|
|
41
45
|
): DTODocumentationGroupStructureV2 {
|
|
@@ -62,7 +66,7 @@ function elementGroupToDocumentationGroupStructureDTO(
|
|
|
62
66
|
};
|
|
63
67
|
}
|
|
64
68
|
|
|
65
|
-
function
|
|
69
|
+
function calculateChildrenIdsMapV2(
|
|
66
70
|
elements: { persistentId: string; parentPersistentId: string; sortOrder: number }[],
|
|
67
71
|
groups: ElementGroup[]
|
|
68
72
|
): Map<string, string[]> {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ColorTokenData,
|
|
3
|
+
DocumentationItemConfigurationV1,
|
|
4
|
+
DocumentationItemHeaderAlignment,
|
|
5
|
+
DocumentationItemHeaderImageScaleType,
|
|
6
|
+
} from "@supernova-studio/model";
|
|
7
|
+
import { DTODocumentationItemConfigurationV1 } from "../../dto";
|
|
8
|
+
|
|
9
|
+
export const dtoDefaultItemConfigurationV1: DTODocumentationItemConfigurationV1 = {
|
|
10
|
+
showSidebar: true,
|
|
11
|
+
header: {
|
|
12
|
+
alignment: DocumentationItemHeaderAlignment.Left,
|
|
13
|
+
backgroundImageScaleType: DocumentationItemHeaderImageScaleType.AspectFill,
|
|
14
|
+
description: "",
|
|
15
|
+
showBackgroundOverlay: false,
|
|
16
|
+
showCoverText: true,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export function documentationItemConfigurationToDTOV1(
|
|
21
|
+
config: DocumentationItemConfigurationV1
|
|
22
|
+
): DTODocumentationItemConfigurationV1 {
|
|
23
|
+
const { header, showSidebar } = config;
|
|
24
|
+
|
|
25
|
+
const { backgroundColor, foregroundColor, ...headerRest } = header;
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
showSidebar,
|
|
29
|
+
header: {
|
|
30
|
+
...headerRest,
|
|
31
|
+
backgroundColor: colorToDTOV1(backgroundColor ?? undefined),
|
|
32
|
+
foregroundColor: colorToDTOV1(foregroundColor ?? undefined),
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function colorToDTOV1(color: ColorTokenData | undefined) {
|
|
38
|
+
if (!color) return undefined;
|
|
39
|
+
if (color.aliasTo) return { aliasTo: color.aliasTo };
|
|
40
|
+
if (!color.value) return undefined;
|
|
41
|
+
|
|
42
|
+
if (typeof color.value === "string") return { value: color.value };
|
|
43
|
+
if (typeof color.value.color === "string") return { value: color.value.color };
|
|
44
|
+
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
DocumentationGroupV1,
|
|
3
|
+
DocumentationPageV1,
|
|
4
|
+
DocumentationPageV2,
|
|
5
|
+
ElementGroup,
|
|
6
|
+
mapByUnique,
|
|
7
|
+
slugify,
|
|
8
|
+
} from "@supernova-studio/model";
|
|
3
9
|
|
|
4
10
|
type GroupLike = {
|
|
5
11
|
persistentId: string;
|
|
@@ -13,8 +19,9 @@ type GroupLike = {
|
|
|
13
19
|
// Please do not put more DTO conversion here unless you know what you're doing.
|
|
14
20
|
|
|
15
21
|
export function buildDocPagePublishPaths(
|
|
16
|
-
groups: ElementGroup[],
|
|
17
|
-
pages: (DocumentationPageV1 | DocumentationPageV2)[]
|
|
22
|
+
groups: (ElementGroup | DocumentationGroupV1)[],
|
|
23
|
+
pages: (DocumentationPageV1 | DocumentationPageV2)[],
|
|
24
|
+
routingVersion: string
|
|
18
25
|
): Map<string, string> {
|
|
19
26
|
const groupPersistentIdToGroupMap = mapByUnique(groups, group => group.persistentId);
|
|
20
27
|
const result = new Map<string, string>();
|
|
@@ -35,7 +42,11 @@ export function buildDocPagePublishPaths(
|
|
|
35
42
|
pathV1 = `/${pathV1}`;
|
|
36
43
|
pathV2 = `/${pathV2}`;
|
|
37
44
|
|
|
38
|
-
|
|
45
|
+
if (routingVersion === "2") {
|
|
46
|
+
result.set(page.persistentId, pathV2);
|
|
47
|
+
} else {
|
|
48
|
+
result.set(page.persistentId, pathV1);
|
|
49
|
+
}
|
|
39
50
|
}
|
|
40
51
|
|
|
41
52
|
return result;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { SupernovaException } from "@supernova-studio/model";
|
|
2
|
-
import { defaultDocumentationItemHeaderV1, DocumentationPageV1 } from "@supernova-studio/model";
|
|
3
|
-
import { ElementGroup } from "@supernova-studio/model";
|
|
4
|
-
import { buildDocPagePublishPaths } from "./documentation-page-to-dto-utils";
|
|
1
|
+
import { DocumentationGroupV1, DocumentationPageV1, SupernovaException } from "@supernova-studio/model";
|
|
5
2
|
import { DocumentationPageV1DTO } from "../../dto";
|
|
3
|
+
import {
|
|
4
|
+
documentationItemConfigurationToDTOV1,
|
|
5
|
+
dtoDefaultItemConfigurationV1,
|
|
6
|
+
} from "./documentation-item-configuration-v1-to-dto";
|
|
7
|
+
import { buildDocPagePublishPaths } from "./documentation-page-to-dto-utils";
|
|
6
8
|
|
|
7
9
|
// The fact that DTO conversion is located here instead of main backend code is due to the fact
|
|
8
10
|
// that we store page and group data in YJS documents in the same way as they are stored in the database.
|
|
@@ -12,9 +14,10 @@ import { DocumentationPageV1DTO } from "../../dto";
|
|
|
12
14
|
|
|
13
15
|
export function documentationPagesToDTOV1(
|
|
14
16
|
pages: DocumentationPageV1[],
|
|
15
|
-
groups:
|
|
17
|
+
groups: DocumentationGroupV1[],
|
|
18
|
+
routingVersion: string
|
|
16
19
|
): DocumentationPageV1DTO[] {
|
|
17
|
-
const pathsMap = buildDocPagePublishPaths(groups, pages);
|
|
20
|
+
const pathsMap = buildDocPagePublishPaths(groups, pages, routingVersion);
|
|
18
21
|
|
|
19
22
|
return pages.map(page => {
|
|
20
23
|
let path = pathsMap.get(page.persistentId);
|
|
@@ -31,10 +34,9 @@ export function documentationPagesToDTOV1(
|
|
|
31
34
|
blocks: page.data.blocks,
|
|
32
35
|
slug: page.slug,
|
|
33
36
|
userSlug: page.userSlug,
|
|
34
|
-
configuration: page.data.configuration
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
},
|
|
37
|
+
configuration: page.data.configuration
|
|
38
|
+
? documentationItemConfigurationToDTOV1(page.data.configuration)
|
|
39
|
+
: dtoDefaultItemConfigurationV1,
|
|
38
40
|
createdAt: page.createdAt,
|
|
39
41
|
updatedAt: page.updatedAt,
|
|
40
42
|
path: path,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { DocumentationPageV2, defaultDocumentationItemHeaderV2 } from "@supernova-studio/model";
|
|
2
|
-
import { ElementGroup } from "@supernova-studio/model";
|
|
3
|
-
import { buildDocPagePublishPaths } from "./documentation-page-to-dto-utils";
|
|
1
|
+
import { DocumentationPageV2, ElementGroup, defaultDocumentationItemHeaderV2 } from "@supernova-studio/model";
|
|
4
2
|
import { DTODocumentationPageStructureV2, DTODocumentationPageV2 } from "../../dto";
|
|
3
|
+
import { buildDocPagePublishPaths } from "./documentation-page-to-dto-utils";
|
|
5
4
|
|
|
6
5
|
// The fact that DTO conversion is located here instead of main backend code is due to the fact
|
|
7
6
|
// that we store page and group data in YJS documents in the same way as they are stored in the database.
|
|
@@ -11,17 +10,20 @@ import { DTODocumentationPageStructureV2, DTODocumentationPageV2 } from "../../d
|
|
|
11
10
|
|
|
12
11
|
export function documentationPagesToStructureDTOV2(
|
|
13
12
|
pages: DocumentationPageV2[],
|
|
14
|
-
groups: ElementGroup[]
|
|
13
|
+
groups: ElementGroup[],
|
|
14
|
+
routingVersion: string
|
|
15
15
|
): DTODocumentationPageStructureV2[] {
|
|
16
|
-
const pathsMap = buildDocPagePublishPaths(groups, pages);
|
|
16
|
+
const pathsMap = buildDocPagePublishPaths(groups, pages, routingVersion);
|
|
17
17
|
return pages.map(page => documentationPageToStructureDTOV2(page, pathsMap));
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export function documentationPagesToDTOV2(
|
|
21
21
|
pages: DocumentationPageV2[],
|
|
22
|
-
groups: ElementGroup[]
|
|
22
|
+
groups: ElementGroup[],
|
|
23
|
+
routingVersion: string
|
|
23
24
|
): DTODocumentationPageV2[] {
|
|
24
|
-
const pathsMap = buildDocPagePublishPaths(groups, pages);
|
|
25
|
+
const pathsMap = buildDocPagePublishPaths(groups, pages, routingVersion);
|
|
26
|
+
|
|
25
27
|
return pages.map(page => {
|
|
26
28
|
return {
|
|
27
29
|
...documentationPageToStructureDTOV2(page, pathsMap),
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from "./documentation-elements-to-hierarchy-v2-dto";
|
|
2
|
-
export * from "./documentation-group-to-dto";
|
|
2
|
+
export * from "./documentation-group-v1-to-dto";
|
|
3
|
+
export * from "./documentation-group-v2-to-dto";
|
|
4
|
+
export * from "./documentation-item-configuration-v1-to-dto";
|
|
3
5
|
export * from "./documentation-page-to-dto-utils";
|
|
4
6
|
export * from "./documentation-page-v1-to-dto";
|
|
5
7
|
export * from "./documentation-page-v2-to-dto";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { DocumentationGroupBehavior, ElementGroup } from "@supernova-studio/model";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { DTODocumentationItemConfigurationV1 } from "./item-configuration-v1";
|
|
4
|
+
|
|
5
|
+
//
|
|
6
|
+
// Read
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Structure DTO is element properties minus element data (in other words data required
|
|
11
|
+
* to display the element in the left panel)
|
|
12
|
+
*/
|
|
13
|
+
export const DTODocumentationGroupStructureV1 = ElementGroup.omit({
|
|
14
|
+
sortOrder: true,
|
|
15
|
+
parentPersistentId: true,
|
|
16
|
+
brandPersistentId: true,
|
|
17
|
+
meta: true,
|
|
18
|
+
childType: true,
|
|
19
|
+
data: true,
|
|
20
|
+
shortPersistentId: true,
|
|
21
|
+
}).extend({
|
|
22
|
+
title: z.string(),
|
|
23
|
+
isRoot: z.boolean(),
|
|
24
|
+
childrenIds: z.array(z.string()),
|
|
25
|
+
groupBehavior: DocumentationGroupBehavior,
|
|
26
|
+
shortPersistentId: z.string(),
|
|
27
|
+
type: z.literal("Group"),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const DTODocumentationGroupV1 = DTODocumentationGroupStructureV1.extend({
|
|
31
|
+
configuration: DTODocumentationItemConfigurationV1,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export type DTODocumentationGroupStructureV1 = z.infer<typeof DTODocumentationGroupStructureV1>;
|
|
35
|
+
export type DTODocumentationGroupV1 = z.infer<typeof DTODocumentationGroupV1>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DocumentationItemHeaderV1 } from "@supernova-studio/model";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
const DocumentationColorV1 = z.object({
|
|
5
|
+
aliasTo: z.string().optional(),
|
|
6
|
+
value: z.string().optional(),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const DTODocumentationItemHeaderV1 = DocumentationItemHeaderV1.omit({
|
|
10
|
+
foregroundColor: true,
|
|
11
|
+
backgroundColor: true,
|
|
12
|
+
}).extend({
|
|
13
|
+
foregroundColor: DocumentationColorV1.optional(),
|
|
14
|
+
backgroundColor: DocumentationColorV1.optional(),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export const DTODocumentationItemConfigurationV1 = z.object({
|
|
18
|
+
showSidebar: z.boolean(),
|
|
19
|
+
header: DTODocumentationItemHeaderV1,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export type DTODocumentationItemConfigurationV1 = z.infer<typeof DTODocumentationItemConfigurationV1>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { DocumentationPageV1, PageBlockV1 } from "@supernova-studio/model";
|
|
1
2
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
3
|
+
import { DTODocumentationItemConfigurationV1 } from "./item-configuration-v1";
|
|
3
4
|
|
|
4
5
|
//
|
|
5
6
|
// Read
|
|
@@ -10,11 +11,11 @@ export const DocumentationPageV1DTO = DocumentationPageV1.omit({
|
|
|
10
11
|
meta: true,
|
|
11
12
|
parentPersistentId: true,
|
|
12
13
|
sortOrder: true,
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
}).extend({
|
|
15
|
+
configuration: DTODocumentationItemConfigurationV1,
|
|
16
|
+
blocks: z.array(PageBlockV1),
|
|
17
|
+
title: z.string(),
|
|
18
|
+
path: z.string(),
|
|
19
|
+
});
|
|
19
20
|
|
|
20
21
|
export type DocumentationPageV1DTO = z.infer<typeof DocumentationPageV1DTO>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import { DocumentationItemConfigurationV2, DocumentationPageV2 } from "@supernova-studio/model";
|
|
1
2
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
import { DocumentationPageV2 } from "@supernova-studio/model";
|
|
4
|
-
import { DTODocumentationGroupStructureV2 } from "./group";
|
|
3
|
+
import { DTODocumentationGroupStructureV2 } from "./group-v2";
|
|
5
4
|
|
|
6
5
|
//
|
|
7
6
|
// Read
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { DocumentationPageV2, ElementGroup } from "@supernova-studio/model";
|
|
1
2
|
import * as Y from "yjs";
|
|
3
|
+
import { z } from "zod";
|
|
2
4
|
import { DTODocumentationHierarchyV2, documentationElementsToHierarchyDto } from "../../api";
|
|
3
|
-
import { DocumentationPageV2, ElementGroup } from "@supernova-studio/model";
|
|
4
5
|
|
|
5
6
|
// We store pages and groups in the same way they are stored in the database.
|
|
6
7
|
// This means that instead of groups having childrenIds array, all items have
|
|
@@ -22,8 +23,16 @@ type DocumentationHierarchyTransaction = {
|
|
|
22
23
|
groups: ElementGroup[];
|
|
23
24
|
pageIdsToDelete: string[];
|
|
24
25
|
groupIdsToDelete: string[];
|
|
26
|
+
|
|
27
|
+
internalSettings: DocumentationHierarchySettings | undefined;
|
|
25
28
|
};
|
|
26
29
|
|
|
30
|
+
export const DocumentationHierarchySettings = z.object({
|
|
31
|
+
routingVersion: z.string(),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export type DocumentationHierarchySettings = z.infer<typeof DocumentationHierarchySettings>;
|
|
35
|
+
|
|
27
36
|
//
|
|
28
37
|
// Init
|
|
29
38
|
//
|
|
@@ -65,30 +74,62 @@ export function documentationHierarchyToYjs(doc: Y.Doc, transaction: Documentati
|
|
|
65
74
|
|
|
66
75
|
groupsMap.set(group.id, JSON.parse(JSON.stringify(sanitizedGroup)));
|
|
67
76
|
});
|
|
77
|
+
|
|
78
|
+
// Internal settings
|
|
79
|
+
if (transaction.internalSettings) {
|
|
80
|
+
serializeDocumentationInternalSettings(trx.doc, transaction.internalSettings);
|
|
81
|
+
}
|
|
68
82
|
});
|
|
69
83
|
|
|
70
84
|
return doc;
|
|
71
85
|
}
|
|
72
86
|
|
|
87
|
+
function serializeDocumentationInternalSettings(doc: Y.Doc, settings: DocumentationHierarchySettings) {
|
|
88
|
+
const map = getInternalSettingsYMap(doc);
|
|
89
|
+
|
|
90
|
+
map.set("routingVersion", settings.routingVersion);
|
|
91
|
+
}
|
|
92
|
+
|
|
73
93
|
export function yjsToDocumentationHierarchy(doc: Y.Doc): DTODocumentationHierarchyV2 {
|
|
74
94
|
const pagesMap = getPagesYMap(doc);
|
|
75
95
|
const groupsMap = getGroupsYMap(doc);
|
|
76
96
|
|
|
97
|
+
// Read pages
|
|
77
98
|
const pages: DocumentationPageV2[] = [];
|
|
78
99
|
pagesMap.forEach(page => {
|
|
79
100
|
pages.push(DocumentationPageV2.parse(page));
|
|
80
101
|
});
|
|
81
102
|
|
|
103
|
+
// Read groups
|
|
82
104
|
const groups: ElementGroup[] = [];
|
|
83
105
|
groupsMap.forEach(group => {
|
|
84
106
|
groups.push(ElementGroup.parse(group));
|
|
85
107
|
});
|
|
86
108
|
|
|
87
|
-
|
|
109
|
+
// Parse internalSettings
|
|
110
|
+
const internalSettings = parseDocumentationInternalSettings(doc);
|
|
111
|
+
|
|
112
|
+
// Map model onto client DTO
|
|
113
|
+
const hierarchy = documentationElementsToHierarchyDto(pages, groups, internalSettings.routingVersion ?? "2");
|
|
88
114
|
|
|
89
115
|
return hierarchy;
|
|
90
116
|
}
|
|
91
117
|
|
|
118
|
+
function parseDocumentationInternalSettings(doc: Y.Doc): DocumentationHierarchySettings {
|
|
119
|
+
const map = getInternalSettingsYMap(doc);
|
|
120
|
+
|
|
121
|
+
const rawSettings: Record<keyof DocumentationHierarchySettings, any> = {
|
|
122
|
+
routingVersion: map.get("routingVersion"),
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const settingsParseResult = DocumentationHierarchySettings.safeParse(rawSettings);
|
|
126
|
+
if (!settingsParseResult.success) {
|
|
127
|
+
return { routingVersion: "2" };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return settingsParseResult.data;
|
|
131
|
+
}
|
|
132
|
+
|
|
92
133
|
//
|
|
93
134
|
// Internals
|
|
94
135
|
//
|
|
@@ -100,3 +141,7 @@ function getPagesYMap(doc: Y.Doc) {
|
|
|
100
141
|
function getGroupsYMap(doc: Y.Doc) {
|
|
101
142
|
return doc.getMap<ElementGroup>("documentationGroups");
|
|
102
143
|
}
|
|
144
|
+
|
|
145
|
+
function getInternalSettingsYMap(doc: Y.Doc) {
|
|
146
|
+
return doc.getMap<unknown>("documentationInternalSettings");
|
|
147
|
+
}
|