@supernova-studio/client 0.4.5 → 0.5.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 +163 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +198 -71
- 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/schema.ts +13 -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.5.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
|
+
}
|
|
@@ -169,6 +169,9 @@ const newSchema = {
|
|
|
169
169
|
markSet: [],
|
|
170
170
|
groups: [],
|
|
171
171
|
attrs: {
|
|
172
|
+
id: {
|
|
173
|
+
default: null,
|
|
174
|
+
},
|
|
172
175
|
textAlign: {
|
|
173
176
|
hasDefault: true,
|
|
174
177
|
default: "left",
|
|
@@ -187,6 +190,7 @@ const newSchema = {
|
|
|
187
190
|
},
|
|
188
191
|
},
|
|
189
192
|
defaultAttrs: {
|
|
193
|
+
id: null,
|
|
190
194
|
textAlign: "left",
|
|
191
195
|
colspan: 1,
|
|
192
196
|
rowspan: 1,
|
|
@@ -232,6 +236,9 @@ const newSchema = {
|
|
|
232
236
|
markSet: [],
|
|
233
237
|
groups: [],
|
|
234
238
|
attrs: {
|
|
239
|
+
id: {
|
|
240
|
+
default: null,
|
|
241
|
+
},
|
|
235
242
|
textAlign: {
|
|
236
243
|
hasDefault: true,
|
|
237
244
|
default: "left",
|
|
@@ -250,6 +257,7 @@ const newSchema = {
|
|
|
250
257
|
},
|
|
251
258
|
},
|
|
252
259
|
defaultAttrs: {
|
|
260
|
+
id: null,
|
|
253
261
|
textAlign: "left",
|
|
254
262
|
colspan: 1,
|
|
255
263
|
rowspan: 1,
|
|
@@ -760,6 +768,7 @@ const newSchema = {
|
|
|
760
768
|
defining: true,
|
|
761
769
|
attrs: {
|
|
762
770
|
id: {
|
|
771
|
+
hasDefault: true,
|
|
763
772
|
default: null,
|
|
764
773
|
},
|
|
765
774
|
definitionId: {
|
|
@@ -778,6 +787,9 @@ const newSchema = {
|
|
|
778
787
|
markSet: [],
|
|
779
788
|
groups: ["block"],
|
|
780
789
|
attrs: {
|
|
790
|
+
id: {
|
|
791
|
+
default: null,
|
|
792
|
+
},
|
|
781
793
|
definitionId: {
|
|
782
794
|
hasDefault: true,
|
|
783
795
|
default: "io.supernova.block.blockquote",
|
|
@@ -788,6 +800,7 @@ const newSchema = {
|
|
|
788
800
|
},
|
|
789
801
|
},
|
|
790
802
|
defaultAttrs: {
|
|
803
|
+
id: null,
|
|
791
804
|
definitionId: "io.supernova.block.blockquote",
|
|
792
805
|
variantId: "default",
|
|
793
806
|
},
|
|
@@ -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