@supernova-studio/client 0.48.7 → 1.0.1
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 +1166 -44514
- package/dist/index.mjs +4583 -9906
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -30
- package/dist/index.d.ts +0 -44757
- package/dist/index.js +0 -11011
- package/dist/index.js.map +0 -1
- package/src/api/conversion/documentation/documentation-group-v1-to-dto.ts +0 -114
- package/src/api/conversion/documentation/documentation-group-v2-to-dto.ts +0 -92
- package/src/api/conversion/documentation/documentation-item-configuration-v1-to-dto.ts +0 -52
- package/src/api/conversion/documentation/documentation-item-configuration-v2-to-dto.ts +0 -34
- package/src/api/conversion/documentation/documentation-page-to-dto-utils.ts +0 -132
- package/src/api/conversion/documentation/documentation-page-v1-to-dto.ts +0 -69
- package/src/api/conversion/documentation/documentation-page-v2-to-dto.ts +0 -72
- package/src/api/conversion/documentation/index.ts +0 -7
- package/src/api/conversion/export/index.ts +0 -1
- package/src/api/conversion/export/pipeline.ts +0 -24
- package/src/api/conversion/index.ts +0 -3
- package/src/api/conversion/integrations/git.ts +0 -37
- package/src/api/conversion/integrations/index.ts +0 -2
- package/src/api/conversion/integrations/integration.ts +0 -37
- package/src/api/dto/design-systems/brand.ts +0 -22
- package/src/api/dto/design-systems/data-source.ts +0 -122
- package/src/api/dto/design-systems/design-system.ts +0 -18
- package/src/api/dto/design-systems/elements-diff.ts +0 -14
- package/src/api/dto/design-systems/exporter-property.ts +0 -8
- package/src/api/dto/design-systems/index.ts +0 -7
- package/src/api/dto/design-systems/version.ts +0 -57
- package/src/api/dto/design-systems/view.ts +0 -45
- package/src/api/dto/documentation/anchor.ts +0 -15
- package/src/api/dto/documentation/block-definition.ts +0 -28
- package/src/api/dto/documentation/block.ts +0 -6
- package/src/api/dto/documentation/documentation-page-snapshot.ts +0 -18
- package/src/api/dto/documentation/index.ts +0 -6
- package/src/api/dto/documentation/link-preview.ts +0 -23
- package/src/api/dto/documentation/publish.ts +0 -23
- package/src/api/dto/elements/documentation/draft-state.ts +0 -35
- package/src/api/dto/elements/documentation/group-action.ts +0 -108
- package/src/api/dto/elements/documentation/group-v1.ts +0 -35
- package/src/api/dto/elements/documentation/group-v2.ts +0 -109
- package/src/api/dto/elements/documentation/hierarchy.ts +0 -36
- package/src/api/dto/elements/documentation/index.ts +0 -11
- package/src/api/dto/elements/documentation/item-configuration-v1.ts +0 -24
- package/src/api/dto/elements/documentation/item-configuration-v2.ts +0 -14
- package/src/api/dto/elements/documentation/page-actions-v2.ts +0 -108
- package/src/api/dto/elements/documentation/page-content.ts +0 -15
- package/src/api/dto/elements/documentation/page-v1.ts +0 -21
- package/src/api/dto/elements/documentation/page-v2.ts +0 -105
- package/src/api/dto/elements/elements-action-v2.ts +0 -114
- package/src/api/dto/elements/figma-nodes/figma-node.ts +0 -55
- package/src/api/dto/elements/figma-nodes/index.ts +0 -2
- package/src/api/dto/elements/figma-nodes/node-actions-v2.ts +0 -24
- package/src/api/dto/elements/get-elements-v2.ts +0 -21
- package/src/api/dto/elements/index.ts +0 -5
- package/src/api/dto/elements/properties/index.ts +0 -3
- package/src/api/dto/elements/properties/property-definitions-actions-v2.ts +0 -53
- package/src/api/dto/elements/properties/property-definitions.ts +0 -62
- package/src/api/dto/elements/properties/property-values.ts +0 -17
- package/src/api/dto/export/exporter.ts +0 -73
- package/src/api/dto/export/index.ts +0 -3
- package/src/api/dto/export/job.ts +0 -75
- package/src/api/dto/export/pipeline.ts +0 -20
- package/src/api/dto/figma-components/assets/download.ts +0 -30
- package/src/api/dto/figma-components/assets/index.ts +0 -1
- package/src/api/dto/figma-components/index.ts +0 -1
- package/src/api/dto/index.ts +0 -8
- package/src/api/dto/liveblocks/auth-response.ts +0 -7
- package/src/api/dto/liveblocks/index.ts +0 -1
- package/src/api/dto/users/index.ts +0 -1
- package/src/api/dto/users/profile/index.ts +0 -1
- package/src/api/dto/users/profile/update.ts +0 -7
- package/src/api/dto/workspaces/git.ts +0 -32
- package/src/api/dto/workspaces/index.ts +0 -5
- package/src/api/dto/workspaces/integrations.ts +0 -34
- package/src/api/dto/workspaces/membership.ts +0 -29
- package/src/api/dto/workspaces/npm-registry.ts +0 -35
- package/src/api/dto/workspaces/workspace.ts +0 -16
- package/src/api/index.ts +0 -3
- package/src/api/payloads/design-systems/brand.ts +0 -11
- package/src/api/payloads/design-systems/index.ts +0 -2
- package/src/api/payloads/design-systems/version.ts +0 -29
- package/src/api/payloads/documentation/block-definitions.ts +0 -12
- package/src/api/payloads/documentation/design-data-doc-diff.ts +0 -7
- package/src/api/payloads/documentation/index.ts +0 -2
- package/src/api/payloads/export/index.ts +0 -1
- package/src/api/payloads/export/pipeline.ts +0 -46
- package/src/api/payloads/index.ts +0 -6
- package/src/api/payloads/liveblocks/auth.ts +0 -7
- package/src/api/payloads/liveblocks/index.ts +0 -1
- package/src/api/payloads/users/index.ts +0 -2
- package/src/api/payloads/users/notifications/index.ts +0 -1
- package/src/api/payloads/users/notifications/notification-settings.ts +0 -17
- package/src/api/payloads/users/profile/index.ts +0 -1
- package/src/api/payloads/users/profile/update.ts +0 -4
- package/src/api/payloads/workspaces/index.ts +0 -2
- package/src/api/payloads/workspaces/workspace-configuration.ts +0 -50
- package/src/api/payloads/workspaces/workspace-integrations.ts +0 -26
- package/src/index.ts +0 -3
- package/src/utils/hash.ts +0 -62
- package/src/utils/index.ts +0 -1
- package/src/yjs/design-system-content/documentation-hierarchy.ts +0 -33
- package/src/yjs/design-system-content/index.ts +0 -2
- package/src/yjs/design-system-content/item-configuration.ts +0 -93
- package/src/yjs/docs-editor/blocks-to-prosemirror.ts +0 -697
- package/src/yjs/docs-editor/index.ts +0 -7
- package/src/yjs/docs-editor/list-tree-builder.ts +0 -135
- package/src/yjs/docs-editor/mock.ts +0 -2447
- package/src/yjs/docs-editor/model/block.ts +0 -8
- package/src/yjs/docs-editor/model/index.ts +0 -2
- package/src/yjs/docs-editor/model/page.ts +0 -8
- package/src/yjs/docs-editor/prosemirror/index.ts +0 -2
- package/src/yjs/docs-editor/prosemirror/schema.ts +0 -657
- package/src/yjs/docs-editor/prosemirror/types.ts +0 -19
- package/src/yjs/docs-editor/prosemirror-to-blocks.ts +0 -900
- package/src/yjs/docs-editor/utils.ts +0 -115
- package/src/yjs/index.ts +0 -3
- package/src/yjs/version-room/backend.ts +0 -60
- package/src/yjs/version-room/base.ts +0 -185
- package/src/yjs/version-room/frontend.ts +0 -298
- package/src/yjs/version-room/index.ts +0 -4
- package/src/yjs/version-room/utils.ts +0 -6
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { PageBlockEditorModel } from "./model/block";
|
|
2
|
-
import {
|
|
3
|
-
PageBlockDefinition,
|
|
4
|
-
PageBlockDefinitionPropertyType,
|
|
5
|
-
PageBlockItemEmbedValue,
|
|
6
|
-
PageBlockItemMultiRichTextValue,
|
|
7
|
-
PageBlockItemRichTextValue,
|
|
8
|
-
PageBlockItemTableValue,
|
|
9
|
-
PageBlockItemUntypedValue,
|
|
10
|
-
PageBlockItemV2,
|
|
11
|
-
PageBlockText,
|
|
12
|
-
} from "@supernova-studio/model";
|
|
13
|
-
|
|
14
|
-
export const BlockParsingUtils = {
|
|
15
|
-
singleBlockItem(block: PageBlockEditorModel) {
|
|
16
|
-
if (!block.data.items.length) throw new Error(`Block ${block.id} has no items`);
|
|
17
|
-
if (block.data.items.length > 1) throw new Error(`Block ${block.id} has more than 1 item`);
|
|
18
|
-
|
|
19
|
-
return block.data.items[0]!;
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
richTextPropertyValue(item: PageBlockItemV2, propertyKey: string): PageBlockItemRichTextValue {
|
|
23
|
-
const objectValue = this.objectPropertyValue(item, propertyKey);
|
|
24
|
-
const richText = PageBlockItemRichTextValue.parse(objectValue);
|
|
25
|
-
|
|
26
|
-
return richText;
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
multiRichTextPropertyValue(item: PageBlockItemV2, propertyKey: string): PageBlockItemMultiRichTextValue {
|
|
30
|
-
const objectValue = this.objectPropertyValue(item, propertyKey);
|
|
31
|
-
const richText = PageBlockItemMultiRichTextValue.parse(objectValue);
|
|
32
|
-
|
|
33
|
-
return richText;
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
tablePropertyValue(item: PageBlockItemV2, propertyKey: string): PageBlockItemTableValue {
|
|
37
|
-
const objectValue = this.objectPropertyValue(item, propertyKey);
|
|
38
|
-
const table = PageBlockItemTableValue.parse(objectValue);
|
|
39
|
-
|
|
40
|
-
return table;
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
embedPropertyValue(item: PageBlockItemV2, propertyKey: string): PageBlockItemEmbedValue {
|
|
44
|
-
const objectValue = this.objectPropertyValue(item, propertyKey);
|
|
45
|
-
const embed = PageBlockItemEmbedValue.parse(objectValue);
|
|
46
|
-
|
|
47
|
-
return embed;
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
objectPropertyValue(item: PageBlockItemV2, propertyKey: string) {
|
|
51
|
-
const value = this.propertyValueOrThrow(item, propertyKey);
|
|
52
|
-
|
|
53
|
-
if (typeof value !== "object") {
|
|
54
|
-
throw new Error(`Value for property ${propertyKey} is expected to be an object, but instead is ${typeof value}`);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return value;
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
propertyValueOrThrow(item: PageBlockItemV2, propertyKey: string): PageBlockItemUntypedValue {
|
|
61
|
-
const value = item.props[propertyKey];
|
|
62
|
-
if (!value) throw new Error(`Property ${propertyKey} is not defined on block item`);
|
|
63
|
-
|
|
64
|
-
return value;
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export const BlockDefinitionUtils = {
|
|
69
|
-
firstRichTextProperty(definition: PageBlockDefinition) {
|
|
70
|
-
const property = definition.item.properties.find(p => p.type === "RichText");
|
|
71
|
-
if (property) return property;
|
|
72
|
-
return undefined;
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
firstMultiRichTextProperty(definition: PageBlockDefinition) {
|
|
76
|
-
const property = definition.item.properties.find(p => p.type === "MultiRichText");
|
|
77
|
-
if (property) return property;
|
|
78
|
-
return undefined;
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
firstTableProperty(definition: PageBlockDefinition) {
|
|
82
|
-
const property = definition.item.properties.find(p => p.type === "Table");
|
|
83
|
-
if (property) return property;
|
|
84
|
-
return undefined;
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
firstEmbedProperty(definition: PageBlockDefinition) {
|
|
88
|
-
const property = definition.item.properties.find(p => p.type === "EmbedURL");
|
|
89
|
-
if (property) return property;
|
|
90
|
-
return undefined;
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
richTextProperty(definition: PageBlockDefinition, propertyKey: string) {
|
|
94
|
-
return this.property(definition, propertyKey, "RichText");
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
property(
|
|
98
|
-
definition: PageBlockDefinition,
|
|
99
|
-
propertyKey: string,
|
|
100
|
-
expectedPropertyType?: PageBlockDefinitionPropertyType
|
|
101
|
-
) {
|
|
102
|
-
const property = definition.item.properties.find(p => p.id === propertyKey);
|
|
103
|
-
if (!property) {
|
|
104
|
-
throw new Error(`Definition ${definition.id} doesn't contain property ${propertyKey}`);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (expectedPropertyType && property.type !== expectedPropertyType) {
|
|
108
|
-
throw new Error(
|
|
109
|
-
`Property ${propertyKey} of definition ${definition.id} expected to be ${expectedPropertyType} but was ${property.type}`
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return property;
|
|
114
|
-
},
|
|
115
|
-
};
|
package/src/yjs/index.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DocumentationPageSnapshot,
|
|
3
|
-
DocumentationPageV2,
|
|
4
|
-
ElementGroup,
|
|
5
|
-
ElementGroupSnapshot,
|
|
6
|
-
} from "@supernova-studio/model";
|
|
7
|
-
import * as Y from "yjs";
|
|
8
|
-
import { DocumentationHierarchySettings } from "../design-system-content";
|
|
9
|
-
import { VersionRoomBaseYDoc } from "./base";
|
|
10
|
-
|
|
11
|
-
type DocumentationHierarchyTransaction = {
|
|
12
|
-
pages?: DocumentationPageV2[];
|
|
13
|
-
pageIdsToDelete?: string[];
|
|
14
|
-
|
|
15
|
-
groups?: ElementGroup[];
|
|
16
|
-
groupIdsToDelete?: string[];
|
|
17
|
-
|
|
18
|
-
pageSnapshots?: DocumentationPageSnapshot[];
|
|
19
|
-
pageSnapshotIdsToDelete?: string[];
|
|
20
|
-
|
|
21
|
-
groupSnapshots?: ElementGroupSnapshot[];
|
|
22
|
-
groupSnapshotIdsToDelete?: string[];
|
|
23
|
-
|
|
24
|
-
internalSettings?: DocumentationHierarchySettings;
|
|
25
|
-
pageHashesToUpdate?: Record<string, string>;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export class BackendVersionRoomYDoc {
|
|
29
|
-
private readonly yDoc: Y.Doc;
|
|
30
|
-
|
|
31
|
-
constructor(yDoc: Y.Doc) {
|
|
32
|
-
this.yDoc = yDoc;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
updateDocumentationHierarchy(transaction: DocumentationHierarchyTransaction) {
|
|
36
|
-
this.yDoc.transact(trx => {
|
|
37
|
-
const yDoc = new VersionRoomBaseYDoc(trx.doc);
|
|
38
|
-
|
|
39
|
-
// Pages
|
|
40
|
-
transaction.pageIdsToDelete && yDoc.deletePages(transaction.pageIdsToDelete);
|
|
41
|
-
transaction.pages && yDoc.updatePages(transaction.pages);
|
|
42
|
-
|
|
43
|
-
// Groups
|
|
44
|
-
transaction.groupIdsToDelete && yDoc.deleteGroups(transaction.groupIdsToDelete);
|
|
45
|
-
transaction.groups && yDoc.updateGroups(transaction.groups);
|
|
46
|
-
|
|
47
|
-
// Page snapshots
|
|
48
|
-
transaction.pageSnapshotIdsToDelete && yDoc.deletePageSnapshots(transaction.pageSnapshotIdsToDelete);
|
|
49
|
-
transaction.pageSnapshots && yDoc.updatePageSnapshots(transaction.pageSnapshots);
|
|
50
|
-
|
|
51
|
-
// Snapshots - published groups
|
|
52
|
-
transaction.groupSnapshotIdsToDelete && yDoc.deleteGroupSnapshots(transaction.groupSnapshotIdsToDelete);
|
|
53
|
-
transaction.groupSnapshots && yDoc.updateGroupSnapshots(transaction.groupSnapshots);
|
|
54
|
-
|
|
55
|
-
// Settings
|
|
56
|
-
transaction.internalSettings && yDoc.updateDocumentationInternalSettings(transaction.internalSettings);
|
|
57
|
-
transaction.pageHashesToUpdate && yDoc.updateDocumentationPageContentHashes(transaction.pageHashesToUpdate);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DocumentationPageSnapshot,
|
|
3
|
-
DocumentationPageV2,
|
|
4
|
-
ElementGroup,
|
|
5
|
-
ElementGroupSnapshot,
|
|
6
|
-
} from "@supernova-studio/model";
|
|
7
|
-
import * as Y from "yjs";
|
|
8
|
-
import { ZodSchema, ZodTypeDef } from "zod";
|
|
9
|
-
import { DocumentationHierarchySettings } from "../design-system-content";
|
|
10
|
-
|
|
11
|
-
type YJSSerializable = { id: string };
|
|
12
|
-
|
|
13
|
-
export class VersionRoomBaseYDoc {
|
|
14
|
-
private readonly yDoc: Y.Doc;
|
|
15
|
-
|
|
16
|
-
constructor(yDoc: Y.Doc) {
|
|
17
|
-
this.yDoc = yDoc;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
//
|
|
21
|
-
// Pages
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
getPages(): DocumentationPageV2[] {
|
|
25
|
-
return this.getObjects(this.pagesYMap, DocumentationPageV2);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
updatePages(pages: DocumentationPageV2[]) {
|
|
29
|
-
pages = pages.map(page => {
|
|
30
|
-
// We remove blocks from the payload here because it will not get parsed anyway
|
|
31
|
-
return {
|
|
32
|
-
...page,
|
|
33
|
-
data: {
|
|
34
|
-
configuration: page.data.configuration,
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
this.setObjects(this.pagesYMap, pages);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
deletePages(ids: string[]) {
|
|
43
|
-
this.deleteObjects(this.pagesYMap, ids);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
private get pagesYMap() {
|
|
47
|
-
return this.yDoc.getMap<object>("documentationPages");
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
//
|
|
51
|
-
// Groups
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
getGroups(): ElementGroup[] {
|
|
55
|
-
return this.getObjects(this.groupsYMap, ElementGroup);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
updateGroups(groups: ElementGroup[]) {
|
|
59
|
-
this.setObjects(this.groupsYMap, groups);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
deleteGroups(ids: string[]) {
|
|
63
|
-
this.deleteObjects(this.groupsYMap, ids);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
private get groupsYMap() {
|
|
67
|
-
return this.yDoc.getMap<object>("documentationGroups");
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
//
|
|
71
|
-
// Documentation internal settings
|
|
72
|
-
//
|
|
73
|
-
|
|
74
|
-
getDocumentationInternalSettings(): DocumentationHierarchySettings {
|
|
75
|
-
const map = this.internalSettingsYMap;
|
|
76
|
-
|
|
77
|
-
const rawSettings: Record<keyof DocumentationHierarchySettings, any> = {
|
|
78
|
-
routingVersion: map.get("routingVersion"),
|
|
79
|
-
isDraftFeatureAdopted: map.get("isDraftFeatureAdopted") ?? false,
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const settingsParseResult = DocumentationHierarchySettings.safeParse(rawSettings);
|
|
83
|
-
if (!settingsParseResult.success) {
|
|
84
|
-
return {
|
|
85
|
-
routingVersion: "2",
|
|
86
|
-
isDraftFeatureAdopted: false,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return settingsParseResult.data;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
updateDocumentationInternalSettings(settings: DocumentationHierarchySettings) {
|
|
94
|
-
const map = this.internalSettingsYMap;
|
|
95
|
-
|
|
96
|
-
map.set("routingVersion", settings.routingVersion);
|
|
97
|
-
map.set("isDraftFeatureAdopted", settings.isDraftFeatureAdopted);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
private get internalSettingsYMap() {
|
|
101
|
-
return this.yDoc.getMap<unknown>("documentationInternalSettings");
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
//
|
|
105
|
-
// Documentation page snapshot
|
|
106
|
-
//
|
|
107
|
-
|
|
108
|
-
getPageSnapshots(): DocumentationPageSnapshot[] {
|
|
109
|
-
return this.getObjects(this.documentationPagePublishedStatesYMap, DocumentationPageSnapshot);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
updatePageSnapshots(snapshots: DocumentationPageSnapshot[]) {
|
|
113
|
-
this.setObjects(this.documentationPagePublishedStatesYMap, snapshots);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
deletePageSnapshots(ids: string[]) {
|
|
117
|
-
this.deleteObjects(this.documentationPagePublishedStatesYMap, ids);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
private get documentationPagePublishedStatesYMap() {
|
|
121
|
-
return this.yDoc.getMap<object>("documentationPageSnapshots");
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
//
|
|
125
|
-
// Documentation group snapshots
|
|
126
|
-
//
|
|
127
|
-
|
|
128
|
-
getGroupSnapshots(): ElementGroupSnapshot[] {
|
|
129
|
-
return this.getObjects(this.documentationGroupPublishedStatesYMap, ElementGroupSnapshot);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
updateGroupSnapshots(snapshots: ElementGroupSnapshot[]) {
|
|
133
|
-
this.setObjects(this.documentationGroupPublishedStatesYMap, snapshots);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
deleteGroupSnapshots(ids: string[]) {
|
|
137
|
-
this.deleteObjects(this.documentationGroupPublishedStatesYMap, ids);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
private get documentationGroupPublishedStatesYMap() {
|
|
141
|
-
return this.yDoc.getMap<object>("documentationGroupSnapshots");
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
//
|
|
145
|
-
// Utils
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
private getObjects<T extends YJSSerializable, I>(map: Y.Map<object>, schema: ZodSchema<T, ZodTypeDef, I>): T[] {
|
|
149
|
-
const results: T[] = [];
|
|
150
|
-
map.forEach(object => results.push(schema.parse(object)));
|
|
151
|
-
return results;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
private setObjects<T extends YJSSerializable>(map: Y.Map<object>, objects: T[]) {
|
|
155
|
-
objects.forEach(o => map.set(o.id, JSON.parse(JSON.stringify(o))));
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
private deleteObjects(map: Y.Map<object>, ids: string[]) {
|
|
159
|
-
ids.forEach(id => map.delete(id));
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
//
|
|
163
|
-
// Documentation page content hashes
|
|
164
|
-
//
|
|
165
|
-
|
|
166
|
-
getDocumentationPageContentHashes(): Record<string, string> {
|
|
167
|
-
const map = this.documentationPageContentHashesYMap;
|
|
168
|
-
|
|
169
|
-
const result: Record<string, string> = {};
|
|
170
|
-
map.forEach((hash, key) => {
|
|
171
|
-
result[key] = hash;
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
return result;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
updateDocumentationPageContentHashes(hashes: Record<string, string>) {
|
|
178
|
-
const map = this.documentationPageContentHashesYMap;
|
|
179
|
-
Object.entries(hashes).forEach(([key, hash]) => map.set(key, hash));
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
private get documentationPageContentHashesYMap() {
|
|
183
|
-
return this.yDoc.getMap<string>("documentationPageHashes");
|
|
184
|
-
}
|
|
185
|
-
}
|
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DocumentationItemConfigurationV2,
|
|
3
|
-
DocumentationPageSnapshot,
|
|
4
|
-
DocumentationPageV2,
|
|
5
|
-
ElementGroup,
|
|
6
|
-
ElementGroupSnapshot,
|
|
7
|
-
defaultDocumentationItemConfigurationV2,
|
|
8
|
-
mapByUnique,
|
|
9
|
-
} from "@supernova-studio/model";
|
|
10
|
-
import * as Y from "yjs";
|
|
11
|
-
import {
|
|
12
|
-
DTODocumentationDraftState,
|
|
13
|
-
DTODocumentationDraftStateUpdated,
|
|
14
|
-
DTODocumentationHierarchyV2,
|
|
15
|
-
documentationItemConfigurationToDTOV2,
|
|
16
|
-
documentationPagesToDTOV2,
|
|
17
|
-
elementGroupsToDocumentationGroupDTOV2,
|
|
18
|
-
} from "../../api";
|
|
19
|
-
import { generateHash } from "../../utils";
|
|
20
|
-
import { DocumentationPageEditorModel } from "../docs-editor";
|
|
21
|
-
import { VersionRoomBaseYDoc } from "./base";
|
|
22
|
-
import { generatePageContentHash } from "./utils";
|
|
23
|
-
|
|
24
|
-
type ItemState = {
|
|
25
|
-
title: string;
|
|
26
|
-
configuration: DocumentationItemConfigurationV2;
|
|
27
|
-
contentHash: string;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export class FrontendVersionRoomYDoc {
|
|
31
|
-
private readonly yDoc: Y.Doc;
|
|
32
|
-
|
|
33
|
-
constructor(yDoc: Y.Doc, private readonly debug = false) {
|
|
34
|
-
this.yDoc = yDoc;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
//
|
|
38
|
-
// Hierarchy
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
getDocumentationHierarchy(): DTODocumentationHierarchyV2 {
|
|
42
|
-
const doc = new VersionRoomBaseYDoc(this.yDoc);
|
|
43
|
-
|
|
44
|
-
// Read current room data
|
|
45
|
-
const pages = doc.getPages();
|
|
46
|
-
const groups = doc.getGroups();
|
|
47
|
-
const pageSnapshots = doc.getPageSnapshots();
|
|
48
|
-
const groupSnapshots = doc.getGroupSnapshots();
|
|
49
|
-
|
|
50
|
-
const settings = doc.getDocumentationInternalSettings();
|
|
51
|
-
|
|
52
|
-
// Convert pages to DTOs
|
|
53
|
-
const pageDTOs = documentationPagesToDTOV2(pages, groups, settings.routingVersion);
|
|
54
|
-
const groupDTOs = elementGroupsToDocumentationGroupDTOV2(groups, pages);
|
|
55
|
-
|
|
56
|
-
// If draft feature is not yet adopted, no snapshot-based features should not be provided
|
|
57
|
-
if (!settings.isDraftFeatureAdopted) {
|
|
58
|
-
return {
|
|
59
|
-
pages: pageDTOs,
|
|
60
|
-
groups: groupDTOs,
|
|
61
|
-
deletedGroups: [],
|
|
62
|
-
deletedPages: [],
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const pageDraftStates = this.buildPageDraftStates(pages, pageSnapshots);
|
|
67
|
-
pageDTOs.forEach(p => {
|
|
68
|
-
const draftState = pageDraftStates.get(p.id);
|
|
69
|
-
draftState && (p.draftState = draftState);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
const groupDraftStates = this.buildGroupDraftStates(groups, groupSnapshots);
|
|
73
|
-
groupDTOs.forEach(g => {
|
|
74
|
-
const draftState = groupDraftStates.get(g.id);
|
|
75
|
-
draftState && (g.draftState = draftState);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
// Read deleted pages
|
|
79
|
-
const pageIds = new Set(pages.map(p => p.id));
|
|
80
|
-
const deletedPagesMap = mapByUnique(
|
|
81
|
-
pageSnapshots.filter(s => !pageIds.has(s.page.id)).map(s => s.page),
|
|
82
|
-
p => p.id
|
|
83
|
-
);
|
|
84
|
-
const deletedPages = Array.from(deletedPagesMap.values());
|
|
85
|
-
|
|
86
|
-
// Read deleted groups
|
|
87
|
-
const groupIds = new Set(groups.map(p => p.id));
|
|
88
|
-
const deletedGroupsMap = mapByUnique(
|
|
89
|
-
groupSnapshots.filter(s => !groupIds.has(s.group.id)).map(s => s.group),
|
|
90
|
-
g => g.id
|
|
91
|
-
);
|
|
92
|
-
const deletedGroups = Array.from(deletedGroupsMap.values());
|
|
93
|
-
|
|
94
|
-
// Convert deleted pages to DTOs with draft states
|
|
95
|
-
const deletedPageDTOs = documentationPagesToDTOV2(
|
|
96
|
-
deletedPages,
|
|
97
|
-
[...groups, ...deletedGroups],
|
|
98
|
-
settings.routingVersion
|
|
99
|
-
).map(p => {
|
|
100
|
-
return { ...p, draftState: { changeType: "Deleted" } } as const;
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
// Convert deleted groups to DTOs with draft states
|
|
104
|
-
const deletedGroupDTOs = elementGroupsToDocumentationGroupDTOV2(deletedGroups, deletedPages).map(g => {
|
|
105
|
-
return { ...g, draftState: { changeType: "Deleted" } } as const;
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
return {
|
|
109
|
-
pages: pageDTOs,
|
|
110
|
-
groups: groupDTOs,
|
|
111
|
-
|
|
112
|
-
deletedPages: deletedPageDTOs,
|
|
113
|
-
deletedGroups: deletedGroupDTOs,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
//
|
|
118
|
-
// Drafts - Pages
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
private buildPageDraftStates(
|
|
122
|
-
pages: DocumentationPageV2[],
|
|
123
|
-
pageSnapshots: DocumentationPageSnapshot[]
|
|
124
|
-
): Map<string, DTODocumentationDraftState> {
|
|
125
|
-
const doc = new VersionRoomBaseYDoc(this.yDoc);
|
|
126
|
-
|
|
127
|
-
// Read room data
|
|
128
|
-
const pageHashes = doc.getDocumentationPageContentHashes();
|
|
129
|
-
const publishedSnapshots = pageSnapshots.filter(s => s.reason === "Publish");
|
|
130
|
-
|
|
131
|
-
const publishedSnapshotsByPageId = mapByUnique(publishedSnapshots, s => s.page.id);
|
|
132
|
-
const publishedPagesById = mapByUnique(
|
|
133
|
-
publishedSnapshots.map(s => s.page),
|
|
134
|
-
p => p.id
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
const result = new Map<string, DTODocumentationDraftState>();
|
|
138
|
-
|
|
139
|
-
pages.forEach(page => {
|
|
140
|
-
// Published state
|
|
141
|
-
const snapshot = publishedSnapshotsByPageId.get(page.id);
|
|
142
|
-
let publishedState: ItemState | undefined;
|
|
143
|
-
if (snapshot) {
|
|
144
|
-
const publishedPage = publishedPagesById.get(snapshot.page.id)!;
|
|
145
|
-
publishedState = this.itemStateFromPage(publishedPage, snapshot.pageContentHash);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Current state - if content hash is undefined, it means that the page hasn't changed
|
|
149
|
-
const currentPageContentHash = pageHashes[page.persistentId] ?? snapshot?.pageContentHash ?? "";
|
|
150
|
-
const currentState: ItemState = this.itemStateFromPage(page, currentPageContentHash);
|
|
151
|
-
|
|
152
|
-
// Calculate draft
|
|
153
|
-
const draftState = this.createDraftState(page.persistentId, currentState, publishedState);
|
|
154
|
-
if (draftState) result.set(page.id, draftState);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
return result;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
private itemStateFromPage(page: DocumentationPageV2, pageContentHash: string): ItemState {
|
|
161
|
-
return {
|
|
162
|
-
title: page.meta.name,
|
|
163
|
-
configuration: page.data.configuration ?? defaultDocumentationItemConfigurationV2,
|
|
164
|
-
contentHash: pageContentHash,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
//
|
|
169
|
-
// Drafts - Groups
|
|
170
|
-
//
|
|
171
|
-
|
|
172
|
-
private buildGroupDraftStates(
|
|
173
|
-
groups: ElementGroup[],
|
|
174
|
-
groupSnapshots: ElementGroupSnapshot[]
|
|
175
|
-
): Map<string, DTODocumentationDraftState> {
|
|
176
|
-
const doc = new VersionRoomBaseYDoc(this.yDoc);
|
|
177
|
-
|
|
178
|
-
// Read room data
|
|
179
|
-
const publishedSnapshots = groupSnapshots.filter(s => s.reason === "Publish");
|
|
180
|
-
|
|
181
|
-
const publishedSnapshotsByGroupId = mapByUnique(publishedSnapshots, s => s.group.id);
|
|
182
|
-
const publishedGroupsById = mapByUnique(
|
|
183
|
-
publishedSnapshots.map(s => s.group),
|
|
184
|
-
g => g.id
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
const result = new Map<string, DTODocumentationDraftState>();
|
|
188
|
-
|
|
189
|
-
groups.forEach(group => {
|
|
190
|
-
// Current state
|
|
191
|
-
const currentState: ItemState = this.itemStateFromGroup(group);
|
|
192
|
-
|
|
193
|
-
// Published state
|
|
194
|
-
const snapshot = publishedSnapshotsByGroupId.get(group.id);
|
|
195
|
-
let publishedState: ItemState | undefined;
|
|
196
|
-
if (snapshot) {
|
|
197
|
-
const publishedGroup = publishedGroupsById.get(snapshot.group.id)!;
|
|
198
|
-
publishedState = this.itemStateFromGroup(publishedGroup);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// Calculate draft
|
|
202
|
-
const draftState = this.createDraftState(group.persistentId, currentState, publishedState);
|
|
203
|
-
if (draftState) result.set(group.id, draftState);
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
return result;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
private itemStateFromGroup(group: ElementGroup): ItemState {
|
|
210
|
-
return {
|
|
211
|
-
title: group.meta.name,
|
|
212
|
-
configuration: group.data?.configuration ?? defaultDocumentationItemConfigurationV2,
|
|
213
|
-
contentHash: "-",
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
//
|
|
218
|
-
// Drafts - Shared
|
|
219
|
-
//
|
|
220
|
-
|
|
221
|
-
private createDraftState(
|
|
222
|
-
itemPersistentId: string,
|
|
223
|
-
currentState: ItemState,
|
|
224
|
-
publishedState: ItemState | undefined
|
|
225
|
-
): DTODocumentationDraftState | undefined {
|
|
226
|
-
if (!publishedState) {
|
|
227
|
-
// New item (hasn't been published yet)
|
|
228
|
-
return { changeType: "Created" };
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// Compare current item state to the published state
|
|
232
|
-
const updatedDraftState: DTODocumentationDraftStateUpdated = {
|
|
233
|
-
changeType: "Updated",
|
|
234
|
-
changes: {},
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
if (currentState.title !== publishedState.title) {
|
|
238
|
-
if (this.debug) {
|
|
239
|
-
console.log(`Item ${itemPersistentId} (${currentState.title}): updated title`);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
updatedDraftState.changes.previousTitle = publishedState.title;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const currentConfigHash = generateHash(currentState.configuration, this.debug);
|
|
246
|
-
const publishedConfigHash = generateHash(publishedState.configuration, this.debug);
|
|
247
|
-
|
|
248
|
-
if (currentConfigHash !== publishedConfigHash) {
|
|
249
|
-
if (this.debug) {
|
|
250
|
-
console.log(`Item ${itemPersistentId} (${currentState.title}): updated configuration`);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const configurationDto = documentationItemConfigurationToDTOV2(publishedState.configuration);
|
|
254
|
-
updatedDraftState.changes.previousConfiguration = configurationDto;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
if (currentState.contentHash !== publishedState.contentHash) {
|
|
258
|
-
if (this.debug) {
|
|
259
|
-
console.log(`Item ${itemPersistentId} (${currentState.title}): updated content hash`);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
updatedDraftState.changes.previousContentHash = publishedState.contentHash;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
if (Object.keys(updatedDraftState.changes).length) {
|
|
266
|
-
// Item has at least one of the draft changes
|
|
267
|
-
return updatedDraftState;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// Item has no draft changes compared to the published item
|
|
271
|
-
return undefined;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
//
|
|
275
|
-
// Update page content hash
|
|
276
|
-
//
|
|
277
|
-
|
|
278
|
-
notifyDocumentationPageContentUpdated(pageId: string, content: DocumentationPageEditorModel) {
|
|
279
|
-
const pageContentHash = generatePageContentHash(content, this.debug);
|
|
280
|
-
if (this.debug) {
|
|
281
|
-
console.log(`Will set page content hash: '${pageId}' : '${pageContentHash}'`);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
new VersionRoomBaseYDoc(this.yDoc).updateDocumentationPageContentHashes({
|
|
285
|
-
[pageId]: pageContentHash,
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
//
|
|
290
|
-
// Misc
|
|
291
|
-
//
|
|
292
|
-
|
|
293
|
-
isDraftFeatureAdopted() {
|
|
294
|
-
const doc = new VersionRoomBaseYDoc(this.yDoc);
|
|
295
|
-
const settings = doc.getDocumentationInternalSettings();
|
|
296
|
-
return settings.isDraftFeatureAdopted;
|
|
297
|
-
}
|
|
298
|
-
}
|