@supernova-studio/client 0.4.6 → 0.6.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 +2537 -177
- package/dist/index.d.ts +2537 -177
- package/dist/index.js +159 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +194 -74
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -2
- package/src/api/dto/documentation-v1.ts +16 -0
- package/src/api/dto/documentation-v2.ts +28 -0
- package/src/api/dto/documentation.ts +29 -0
- package/src/api/dto/index.ts +3 -0
- package/src/api/index.ts +1 -0
- package/src/design-system-content/documentation-hierarchy.ts +41 -0
- package/src/design-system-content/index.ts +2 -0
- package/src/design-system-content/item-configuration.ts +57 -0
- package/src/docs-editor/prosemirror-to-blocks.ts +6 -1
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supernova-studio/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Supernova Data Models",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
"author": "",
|
|
33
33
|
"license": "ISC",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@supernova-studio/model": "*",
|
|
36
35
|
"prosemirror-model": "^1.19.4",
|
|
37
36
|
"typescript": "^5.0.4",
|
|
38
37
|
"y-prosemirror": "^1.2.2",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { DocumentationPageV1 } from "@supernova-studio/model";
|
|
3
|
+
|
|
4
|
+
export const DocumentationPageV1DTO = DocumentationPageV1.omit({
|
|
5
|
+
data: true,
|
|
6
|
+
meta: true,
|
|
7
|
+
parentPersistentId: true,
|
|
8
|
+
sortOrder: true,
|
|
9
|
+
})
|
|
10
|
+
.extend(DocumentationPageV1.shape.data.shape)
|
|
11
|
+
.extend({
|
|
12
|
+
title: z.string(),
|
|
13
|
+
path: z.string(),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export type DocumentationPageV1DTO = z.infer<typeof DocumentationPageV1DTO>;
|
|
@@ -0,0 +1,28 @@
|
|
|
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 DocumentationPageStructureV2DTO = 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 DocumentationPageV2DTO = DocumentationPageStructureV2DTO.extend(DocumentationPageV2.shape.data.shape);
|
|
20
|
+
|
|
21
|
+
export const DocumentationHierarchyV2DTO = z.object({
|
|
22
|
+
pages: z.array(DocumentationPageStructureV2DTO),
|
|
23
|
+
groups: z.array(DocumentationGroupStructureDTO),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export type DocumentationPageV2DTO = z.infer<typeof DocumentationPageV2DTO>;
|
|
27
|
+
export type DocumentationPageStructureV2DTO = z.infer<typeof DocumentationPageStructureV2DTO>;
|
|
28
|
+
export type DocumentationHierarchyV2DTO = z.infer<typeof DocumentationHierarchyV2DTO>;
|
|
@@ -0,0 +1,29 @@
|
|
|
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>;
|
package/src/api/index.ts
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as Y from "yjs";
|
|
2
|
+
import { DocumentationHierarchyV2DTO, DocumentationPageStructureV2DTO } from "../api/dto/documentation-v2";
|
|
3
|
+
import { DocumentationGroupStructureDTO } from "../api";
|
|
4
|
+
|
|
5
|
+
export function documentationHierarchyToYjs(documentationHierarchy: DocumentationHierarchyV2DTO, doc: Y.Doc) {
|
|
6
|
+
doc.transact(trx => {
|
|
7
|
+
const pagesMap = trx.doc.getMap("documentationPages");
|
|
8
|
+
documentationHierarchy.pages.forEach(page => {
|
|
9
|
+
pagesMap.set(page.persistentId, page);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const groupsMap = trx.doc.getMap("documentationGroups");
|
|
13
|
+
documentationHierarchy.groups.forEach(group => {
|
|
14
|
+
groupsMap.set(group.persistentId, group);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return doc;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function yjsToDocumentationHierarchy(doc: Y.Doc): DocumentationHierarchyV2DTO {
|
|
22
|
+
const pagesMap = doc.getMap("documentationPages");
|
|
23
|
+
const groupsMap = doc.getMap("documentationGroups");
|
|
24
|
+
|
|
25
|
+
const pages: DocumentationPageStructureV2DTO[] = [];
|
|
26
|
+
pagesMap.forEach(page => {
|
|
27
|
+
pages.push(DocumentationPageStructureV2DTO.parse(page));
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const groups: DocumentationGroupStructureDTO[] = [];
|
|
31
|
+
groupsMap.forEach(group => {
|
|
32
|
+
groups.push(DocumentationGroupStructureDTO.parse(group));
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
pages,
|
|
37
|
+
groups,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// TODO Update page and update group
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { DocumentationItemConfiguration, DocumentationItemHeader } from "@supernova-studio/model";
|
|
2
|
+
import * as Y from "yjs";
|
|
3
|
+
|
|
4
|
+
type UpdateDocumentationItemConfiguration = Partial<DocumentationItemConfiguration> & {
|
|
5
|
+
header?: Partial<DocumentationItemHeader>;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export function itemConfigurationToYjs(item: UpdateDocumentationItemConfiguration, yDoc: Y.Doc) {
|
|
9
|
+
yDoc.transact(trx => {
|
|
10
|
+
const header = item.header;
|
|
11
|
+
|
|
12
|
+
if (header) {
|
|
13
|
+
const headerYMap = trx.doc.getMap("itemHeader");
|
|
14
|
+
|
|
15
|
+
header.description !== undefined && headerYMap.set("description", header.description);
|
|
16
|
+
header.alignment !== undefined && headerYMap.set("alignment", header.alignment);
|
|
17
|
+
header.foregroundColor !== undefined && headerYMap.set("foregroundColor", header.foregroundColor);
|
|
18
|
+
header.backgroundColor !== undefined && headerYMap.set("backgroundColor", header.backgroundColor);
|
|
19
|
+
header.backgroundImageAsset !== undefined && headerYMap.set("backgroundImageAsset", header.backgroundImageAsset);
|
|
20
|
+
header.backgroundImageScaleType !== undefined &&
|
|
21
|
+
headerYMap.set("backgroundImageScaleType", header.backgroundImageScaleType);
|
|
22
|
+
header.showBackgroundOverlay !== undefined &&
|
|
23
|
+
headerYMap.set("showBackgroundOverlay", header.showBackgroundOverlay);
|
|
24
|
+
header.showCoverText !== undefined && headerYMap.set("showCoverText", header.showCoverText);
|
|
25
|
+
header.minHeight !== undefined && headerYMap.set("minHeight", header.minHeight);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (item.showSidebar !== undefined) {
|
|
29
|
+
const configYMap = trx.doc.getMap("itemConfiguration");
|
|
30
|
+
|
|
31
|
+
configYMap.set("showSidebar", item.showSidebar);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function yjsToItemConfiguration(yDoc: Y.Doc): DocumentationItemConfiguration {
|
|
37
|
+
const headerYMap = yDoc.getMap("itemHeader");
|
|
38
|
+
const rawHeader = {
|
|
39
|
+
description: headerYMap.get("description"),
|
|
40
|
+
alignment: headerYMap.get("alignment"),
|
|
41
|
+
foregroundColor: headerYMap.get("foregroundColor"),
|
|
42
|
+
backgroundColor: headerYMap.get("backgroundColor"),
|
|
43
|
+
backgroundImageAsset: headerYMap.get("backgroundImageAsset"),
|
|
44
|
+
backgroundImageScaleType: headerYMap.get("backgroundImageScaleType"),
|
|
45
|
+
showBackgroundOverlay: headerYMap.get("showBackgroundOverlay"),
|
|
46
|
+
showCoverText: headerYMap.get("showCoverText"),
|
|
47
|
+
minHeight: headerYMap.get("minHeight"),
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const configYMap = yDoc.getMap("itemConfiguration");
|
|
51
|
+
const rawConfig = {
|
|
52
|
+
showSidebar: configYMap.get("showSidebar"),
|
|
53
|
+
header: rawHeader,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return DocumentationItemConfiguration.parse(rawConfig);
|
|
57
|
+
}
|
|
@@ -37,13 +37,18 @@ import {
|
|
|
37
37
|
PageBlockItemTableNode,
|
|
38
38
|
PageBlockItemTableCell,
|
|
39
39
|
PageBlockTableCellAlignment,
|
|
40
|
+
DocumentationItemConfiguration,
|
|
40
41
|
} from "@supernova-studio/model";
|
|
41
42
|
import { PageBlockEditorModel } from "./model/block";
|
|
42
43
|
import { DocumentationPageEditorModel } from "./model/page";
|
|
43
44
|
import { BlockDefinitionUtils } from "./utils";
|
|
44
45
|
import { yXmlFragmentToProsemirrorJSON } from "y-prosemirror";
|
|
45
46
|
|
|
46
|
-
export function
|
|
47
|
+
export function yDocToPage(yDoc: Y.Doc, definitions: PageBlockDefinition[]): DocumentationPageEditorModel {
|
|
48
|
+
return yXmlFragmentToPage(yDoc.getXmlFragment("default"), definitions);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function yXmlFragmentToPage(
|
|
47
52
|
fragment: Y.XmlFragment,
|
|
48
53
|
definitions: PageBlockDefinition[]
|
|
49
54
|
): DocumentationPageEditorModel {
|
package/src/index.ts
CHANGED