@supernova-studio/client 0.25.1 → 0.27.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 +1394 -89
- package/dist/index.d.ts +1394 -89
- package/dist/index.js +249 -87
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1237 -1075
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/api/dto/elements/documentation/group-action.ts +8 -8
- package/src/api/dto/elements/documentation/group.ts +3 -3
- package/src/api/dto/elements/elements-action-v2.ts +4 -4
- package/src/yjs/docs-editor/blocks-to-prosemirror.ts +96 -3
- package/src/yjs/docs-editor/model/block.ts +5 -2
- package/src/yjs/docs-editor/model/page.ts +2 -2
- package/src/yjs/docs-editor/prosemirror-to-blocks.ts +142 -27
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import {
|
|
3
3
|
DTOCreateDocumentationGroupInput,
|
|
4
|
-
|
|
4
|
+
DTOCreateDocumentationTabInput,
|
|
5
5
|
DTODeleteDocumentationGroupInput,
|
|
6
6
|
DTODeleteDocumentationTabGroupInput,
|
|
7
7
|
DTODuplicateDocumentationGroupInput,
|
|
@@ -22,8 +22,8 @@ export const DTODocumentationGroupCreateActionOutputV2 = z.object({
|
|
|
22
22
|
output: SuccessPayload,
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
export const
|
|
26
|
-
type: z.literal("
|
|
25
|
+
export const DTODocumentationTabCreateActionOutputV2 = z.object({
|
|
26
|
+
type: z.literal("DocumentationTabCreate"),
|
|
27
27
|
output: SuccessPayload,
|
|
28
28
|
});
|
|
29
29
|
|
|
@@ -53,7 +53,7 @@ export const DTODocumentationTabGroupDeleteActionOutputV2 = z.object({
|
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
export type DTODocumentationGroupCreateActionOutputV2 = z.infer<typeof DTODocumentationGroupCreateActionOutputV2>;
|
|
56
|
-
export type
|
|
56
|
+
export type DTODocumentationTabCreateActionOutputV2 = z.infer<typeof DTODocumentationTabCreateActionOutputV2>;
|
|
57
57
|
export type DTODocumentationGroupUpdateActionOutputV2 = z.infer<typeof DTODocumentationGroupUpdateActionOutputV2>;
|
|
58
58
|
export type DTODocumentationGroupMoveActionOutputV2 = z.infer<typeof DTODocumentationGroupMoveActionOutputV2>;
|
|
59
59
|
export type DTODocumentationGroupDuplicateActionOutputV2 = z.infer<typeof DTODocumentationGroupDuplicateActionOutputV2>;
|
|
@@ -69,9 +69,9 @@ export const DTODocumentationGroupCreateActionInputV2 = z.object({
|
|
|
69
69
|
input: DTOCreateDocumentationGroupInput,
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
export const
|
|
73
|
-
type: z.literal("
|
|
74
|
-
input:
|
|
72
|
+
export const DTODocumentationTabCreateActionInputV2 = z.object({
|
|
73
|
+
type: z.literal("DocumentationTabCreate"),
|
|
74
|
+
input: DTOCreateDocumentationTabInput,
|
|
75
75
|
});
|
|
76
76
|
|
|
77
77
|
export const DTODocumentationGroupUpdateActionInputV2 = z.object({
|
|
@@ -100,7 +100,7 @@ export const DTODocumentationTabGroupDeleteActionInputV2 = z.object({
|
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
export type DTODocumentationGroupCreateActionInputV2 = z.infer<typeof DTODocumentationGroupCreateActionInputV2>;
|
|
103
|
-
export type DTODocumentationTabGroupCreateActionInputV2 = z.infer<typeof
|
|
103
|
+
export type DTODocumentationTabGroupCreateActionInputV2 = z.infer<typeof DTODocumentationTabCreateActionInputV2>;
|
|
104
104
|
export type DTODocumentationGroupUpdateActionInputV2 = z.infer<typeof DTODocumentationGroupUpdateActionInputV2>;
|
|
105
105
|
export type DTODocumentationGroupMoveActionInputV2 = z.infer<typeof DTODocumentationGroupMoveActionInputV2>;
|
|
106
106
|
export type DTODocumentationGroupDuplicateActionInputV2 = z.infer<typeof DTODocumentationGroupDuplicateActionInputV2>;
|
|
@@ -80,12 +80,12 @@ export const DTODuplicateDocumentationGroupInput = z.object({
|
|
|
80
80
|
parentPersistentId: z.string().uuid(),
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
-
export const
|
|
83
|
+
export const DTOCreateDocumentationTabInput = z.object({
|
|
84
84
|
// New group persistent id
|
|
85
85
|
persistentId: z.string().uuid(),
|
|
86
86
|
|
|
87
87
|
// Page that will become first tab of the tab group
|
|
88
|
-
|
|
88
|
+
fromPagePersistentId: z.string(),
|
|
89
89
|
tabName: z.string(),
|
|
90
90
|
});
|
|
91
91
|
|
|
@@ -106,6 +106,6 @@ export type DTOCreateDocumentationGroupInput = z.infer<typeof DTOCreateDocumenta
|
|
|
106
106
|
export type DTOUpdateDocumentationGroupInput = z.infer<typeof DTOUpdateDocumentationGroupInput>;
|
|
107
107
|
export type DTOMoveDocumentationGroupInput = z.infer<typeof DTOMoveDocumentationGroupInput>;
|
|
108
108
|
export type DTODuplicateDocumentationGroupInput = z.infer<typeof DTODuplicateDocumentationGroupInput>;
|
|
109
|
-
export type
|
|
109
|
+
export type DTOCreateDocumentationTabInput = z.infer<typeof DTOCreateDocumentationTabInput>;
|
|
110
110
|
export type DTODeleteDocumentationTabGroupInput = z.infer<typeof DTODeleteDocumentationTabGroupInput>;
|
|
111
111
|
export type DTODeleteDocumentationGroupInput = z.infer<typeof DTODeleteDocumentationGroupInput>;
|
|
@@ -22,8 +22,8 @@ import {
|
|
|
22
22
|
DTODocumentationGroupMoveActionOutputV2,
|
|
23
23
|
DTODocumentationGroupUpdateActionInputV2,
|
|
24
24
|
DTODocumentationGroupUpdateActionOutputV2,
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
DTODocumentationTabCreateActionInputV2,
|
|
26
|
+
DTODocumentationTabCreateActionOutputV2,
|
|
27
27
|
DTODocumentationTabGroupDeleteActionInputV2,
|
|
28
28
|
DTODocumentationTabGroupDeleteActionOutputV2,
|
|
29
29
|
} from "./documentation/group-action";
|
|
@@ -43,7 +43,7 @@ export const DTOElementActionOutput = z.discriminatedUnion("type", [
|
|
|
43
43
|
|
|
44
44
|
// Documentation groups
|
|
45
45
|
DTODocumentationGroupCreateActionOutputV2,
|
|
46
|
-
|
|
46
|
+
DTODocumentationTabCreateActionOutputV2,
|
|
47
47
|
DTODocumentationGroupUpdateActionOutputV2,
|
|
48
48
|
DTODocumentationGroupMoveActionOutputV2,
|
|
49
49
|
DTODocumentationGroupDuplicateActionOutputV2,
|
|
@@ -70,7 +70,7 @@ export const DTOElementActionInput = z.discriminatedUnion("type", [
|
|
|
70
70
|
|
|
71
71
|
// Documentation groups
|
|
72
72
|
DTODocumentationGroupCreateActionInputV2,
|
|
73
|
-
|
|
73
|
+
DTODocumentationTabCreateActionInputV2,
|
|
74
74
|
DTODocumentationGroupUpdateActionInputV2,
|
|
75
75
|
DTODocumentationGroupMoveActionInputV2,
|
|
76
76
|
DTODocumentationGroupDuplicateActionInputV2,
|
|
@@ -16,8 +16,12 @@ import {
|
|
|
16
16
|
PageBlockDefinitionRichTextOptions,
|
|
17
17
|
PageBlockDefinitionMutiRichTextOptions,
|
|
18
18
|
PageBlockItemImageValue,
|
|
19
|
+
SupernovaException,
|
|
20
|
+
PageSectionItemV2,
|
|
21
|
+
PageSectionColumnV2,
|
|
22
|
+
mapByUnique,
|
|
19
23
|
} from "@supernova-studio/model";
|
|
20
|
-
import { PageBlockEditorModel } from "./model/block";
|
|
24
|
+
import { PageBlockEditorModel, PageSectionEditorModel } from "./model/block";
|
|
21
25
|
import { ProsemirrorNode, ProsemirrorMark } from "./prosemirror/types";
|
|
22
26
|
import { BlockDefinitionUtils, BlockParsingUtils } from "./utils";
|
|
23
27
|
import { DocumentationPageEditorModel } from "./model";
|
|
@@ -62,12 +66,18 @@ export function pageToProsemirrorDoc(
|
|
|
62
66
|
page: DocumentationPageEditorModel,
|
|
63
67
|
definitions: PageBlockDefinition[]
|
|
64
68
|
): ProsemirrorNode {
|
|
69
|
+
const definitionsMap = mapByUnique(definitions, d => d.id);
|
|
70
|
+
|
|
65
71
|
return {
|
|
66
72
|
type: "doc",
|
|
67
73
|
content: page.blocks
|
|
68
74
|
.map(b => {
|
|
69
|
-
|
|
70
|
-
|
|
75
|
+
switch (b.type) {
|
|
76
|
+
case "Block":
|
|
77
|
+
return blockToProsemirrorNode(b, blockDefinitionForBlock(b, definitions));
|
|
78
|
+
case "Section":
|
|
79
|
+
return internalSectionToProsemirrorNode(b, definitionsMap);
|
|
80
|
+
}
|
|
71
81
|
})
|
|
72
82
|
.filter(nonNullFilter),
|
|
73
83
|
};
|
|
@@ -82,6 +92,88 @@ export function blockDefinitionForBlock(block: PageBlockEditorModel, definitions
|
|
|
82
92
|
return definition;
|
|
83
93
|
}
|
|
84
94
|
|
|
95
|
+
//
|
|
96
|
+
// Sections
|
|
97
|
+
//
|
|
98
|
+
|
|
99
|
+
export function sectionToProsemirrorNode(
|
|
100
|
+
section: PageSectionEditorModel,
|
|
101
|
+
definitions: PageBlockDefinition[]
|
|
102
|
+
): ProsemirrorNode {
|
|
103
|
+
const definitionsMap = mapByUnique(definitions, d => d.id);
|
|
104
|
+
return internalSectionToProsemirrorNode(section, definitionsMap);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function internalSectionToProsemirrorNode(
|
|
108
|
+
section: PageSectionEditorModel,
|
|
109
|
+
definitionsMap: Map<string, PageBlockDefinition>
|
|
110
|
+
): ProsemirrorNode {
|
|
111
|
+
return {
|
|
112
|
+
type: "tabsSection",
|
|
113
|
+
attrs: {
|
|
114
|
+
id: section.id,
|
|
115
|
+
...(section.variantId && { variantId: section.variantId }),
|
|
116
|
+
},
|
|
117
|
+
content: section.items.map(item => sectionItemToProsemirrorNode(item, definitionsMap)),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function sectionItemToProsemirrorNode(
|
|
122
|
+
sectionItem: PageSectionItemV2,
|
|
123
|
+
definitionsMap: Map<string, PageBlockDefinition>
|
|
124
|
+
): ProsemirrorNode {
|
|
125
|
+
return {
|
|
126
|
+
type: "sectionItem",
|
|
127
|
+
attrs: {
|
|
128
|
+
id: sectionItem.id,
|
|
129
|
+
title: sectionItem.title,
|
|
130
|
+
},
|
|
131
|
+
content: sectionItem.columns.map(column => sectionColumnToProsemirrorNode(column, definitionsMap)),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function sectionColumnToProsemirrorNode(
|
|
136
|
+
sectionColumn: PageSectionColumnV2,
|
|
137
|
+
definitionsMap: Map<string, PageBlockDefinition>
|
|
138
|
+
): ProsemirrorNode {
|
|
139
|
+
const blocks = sectionColumn.blocks
|
|
140
|
+
.map(block => {
|
|
141
|
+
return internalBlockToProsemirrorNode(block, definitionsMap);
|
|
142
|
+
})
|
|
143
|
+
.filter(nonNullFilter);
|
|
144
|
+
|
|
145
|
+
if (!blocks.length) {
|
|
146
|
+
blocks.push({
|
|
147
|
+
type: "paragraph",
|
|
148
|
+
attrs: {
|
|
149
|
+
id: "id",
|
|
150
|
+
definitionId: "io.supernova.block.rich-text",
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
type: "sectionItemColumn",
|
|
157
|
+
attrs: {
|
|
158
|
+
id: sectionColumn.id,
|
|
159
|
+
},
|
|
160
|
+
content: blocks,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
//
|
|
165
|
+
// Blocks
|
|
166
|
+
//
|
|
167
|
+
|
|
168
|
+
function internalBlockToProsemirrorNode(block: PageBlockEditorModel, definitionsMap: Map<string, PageBlockDefinition>) {
|
|
169
|
+
const definition = definitionsMap.get(block.data.packageId);
|
|
170
|
+
if (!definition) {
|
|
171
|
+
throw SupernovaException.shouldNotHappen(`Could not find definition for ${block.id} (${block.data.packageId})`);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return blockToProsemirrorNode(block, definition);
|
|
175
|
+
}
|
|
176
|
+
|
|
85
177
|
export function blockToProsemirrorNode(
|
|
86
178
|
block: PageBlockEditorModel,
|
|
87
179
|
definition: PageBlockDefinition
|
|
@@ -532,6 +624,7 @@ export function serializeAsCustomBlock(block: PageBlockEditorModel, definition:
|
|
|
532
624
|
...(block.data.variantId && { variantId: block.data.variantId }),
|
|
533
625
|
items: JSON.stringify(items),
|
|
534
626
|
|
|
627
|
+
...(block.data.appearance && { appearance: JSON.stringify(block.data.appearance) }),
|
|
535
628
|
...(columns && { columns: columns }),
|
|
536
629
|
},
|
|
537
630
|
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PageBlockEditorModelV2, PageSectionEditorModelV2 } from "@supernova-studio/model";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
|
|
4
|
-
export const PageBlockEditorModel =
|
|
4
|
+
export const PageBlockEditorModel = PageBlockEditorModelV2;
|
|
5
5
|
export type PageBlockEditorModel = z.infer<typeof PageBlockEditorModel>;
|
|
6
|
+
|
|
7
|
+
export const PageSectionEditorModel = PageSectionEditorModelV2;
|
|
8
|
+
export type PageSectionEditorModel = z.infer<typeof PageSectionEditorModel>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { PageBlockEditorModel } from "./block";
|
|
2
|
+
import { PageBlockEditorModel, PageSectionEditorModel } from "./block";
|
|
3
3
|
|
|
4
4
|
export const DocumentationPageEditorModel = z.object({
|
|
5
|
-
blocks: z.array(PageBlockEditorModel),
|
|
5
|
+
blocks: z.array(PageBlockEditorModel.or(PageSectionEditorModel)),
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
export type DocumentationPageEditorModel = z.infer<typeof DocumentationPageEditorModel>;
|
|
@@ -38,17 +38,17 @@ import {
|
|
|
38
38
|
PageBlockItemTableCell,
|
|
39
39
|
PageBlockTableCellAlignment,
|
|
40
40
|
PageBlockAppearanceV2,
|
|
41
|
-
ColorValue,
|
|
42
41
|
nullishToOptional,
|
|
43
42
|
PageBlockItemFigmaNodeValue,
|
|
44
43
|
PageBlockColorV2,
|
|
44
|
+
PageSectionItemV2,
|
|
45
|
+
PageSectionColumnV2,
|
|
45
46
|
} from "@supernova-studio/model";
|
|
46
|
-
import { PageBlockEditorModel } from "./model/block";
|
|
47
|
+
import { PageBlockEditorModel, PageSectionEditorModel } from "./model/block";
|
|
47
48
|
import { DocumentationPageEditorModel } from "./model/page";
|
|
48
49
|
import { BlockDefinitionUtils } from "./utils";
|
|
49
50
|
import { yXmlFragmentToProsemirrorJSON } from "y-prosemirror";
|
|
50
|
-
import {
|
|
51
|
-
import { o } from "vitest/dist/types-198fd1d9";
|
|
51
|
+
import { ZodSchema, ZodTypeDef, z } from "zod";
|
|
52
52
|
|
|
53
53
|
export function yDocToPage(yDoc: Y.Doc, definitions: PageBlockDefinition[]): DocumentationPageEditorModel {
|
|
54
54
|
return yXmlFragmentToPage(yDoc.getXmlFragment("default"), definitions);
|
|
@@ -69,32 +69,133 @@ export function prosemirrorDocToPage(
|
|
|
69
69
|
const definitionsById = mapByUnique(definitions, d => d.id);
|
|
70
70
|
|
|
71
71
|
return {
|
|
72
|
-
blocks: (prosemirrorDoc.content ?? [])
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
72
|
+
blocks: internalProsemirrorNodesToPageItems(prosemirrorDoc.content ?? [], definitionsById),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//
|
|
77
|
+
// Sections
|
|
78
|
+
//
|
|
79
|
+
|
|
80
|
+
export function prosemirrorNodeToSection(
|
|
81
|
+
prosemirrorNode: ProsemirrorNode,
|
|
82
|
+
definitions: PageBlockDefinition[]
|
|
83
|
+
): PageSectionEditorModel | null {
|
|
84
|
+
const definitionsById = mapByUnique(definitions, d => d.id);
|
|
85
|
+
return internalProsemirrorNodeToSection(prosemirrorNode, definitionsById);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function internalProsemirrorNodeToSection(
|
|
89
|
+
prosemirrorNode: ProsemirrorNode,
|
|
90
|
+
definitionsMap: Map<string, PageBlockDefinition>
|
|
91
|
+
): PageSectionEditorModel | null {
|
|
92
|
+
const id = getProsemirrorBlockId(prosemirrorNode);
|
|
93
|
+
if (!id) return null;
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
id: id,
|
|
97
|
+
type: "Section",
|
|
98
|
+
variantId: getProsemirrorBlockVariantId(prosemirrorNode),
|
|
99
|
+
sectionType: "Tabs",
|
|
100
|
+
appearance: {
|
|
101
|
+
contentExpandToEdges: true,
|
|
102
|
+
expandToEdges: true,
|
|
103
|
+
},
|
|
104
|
+
items: (prosemirrorNode.content ?? [])
|
|
105
|
+
.filter(c => c.type === "sectionItem")
|
|
106
|
+
.map(c => prosemirrorNodeToSectionItem(c, definitionsMap))
|
|
94
107
|
.filter(nonNullFilter),
|
|
95
108
|
};
|
|
96
109
|
}
|
|
97
110
|
|
|
111
|
+
function prosemirrorNodeToSectionItem(
|
|
112
|
+
prosemirrorNode: ProsemirrorNode,
|
|
113
|
+
definitionsMap: Map<string, PageBlockDefinition>
|
|
114
|
+
): PageSectionItemV2 | null {
|
|
115
|
+
const id = getProsemirrorBlockId(prosemirrorNode);
|
|
116
|
+
if (!id) return null;
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
id: id,
|
|
120
|
+
title: getProsemirrorAttribute(prosemirrorNode, "title", z.string()) ?? "",
|
|
121
|
+
columns: (prosemirrorNode.content ?? [])
|
|
122
|
+
.filter(c => c.type === "sectionItemColumn")
|
|
123
|
+
.map(c => prosemirrorNodeToSectionColumns(c, definitionsMap))
|
|
124
|
+
.filter(nonNullFilter),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function prosemirrorNodeToSectionColumns(
|
|
129
|
+
prosemirrorNode: ProsemirrorNode,
|
|
130
|
+
definitionsMap: Map<string, PageBlockDefinition>
|
|
131
|
+
): PageSectionColumnV2 | null {
|
|
132
|
+
const id = getProsemirrorBlockId(prosemirrorNode);
|
|
133
|
+
if (!id) return null;
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
id: id,
|
|
137
|
+
blocks: internalProsemirrorNodesToBlocks(prosemirrorNode.content ?? [], definitionsMap),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
//
|
|
142
|
+
// Blocks
|
|
143
|
+
//
|
|
144
|
+
|
|
145
|
+
export function prosemirrorNodesToBlocks(prosemirrorNodes: ProsemirrorNode[], definitions: PageBlockDefinition[]) {
|
|
146
|
+
const definitionsById = mapByUnique(definitions, d => d.id);
|
|
147
|
+
return internalProsemirrorNodesToBlocks(prosemirrorNodes, definitionsById);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function internalProsemirrorNodesToPageItems(
|
|
151
|
+
prosemirrorNodes: ProsemirrorNode[],
|
|
152
|
+
definitionsMap: Map<string, PageBlockDefinition>
|
|
153
|
+
): (PageBlockEditorModel | PageSectionEditorModel)[] {
|
|
154
|
+
return prosemirrorNodes
|
|
155
|
+
.map(prosemirrorNode => {
|
|
156
|
+
if (prosemirrorNode.type === "tabsSection") {
|
|
157
|
+
return prosemirrorNodeToSection(prosemirrorNode, Array.from(definitionsMap.values()));
|
|
158
|
+
} else {
|
|
159
|
+
return internalProsemirrorNodeToBlock(prosemirrorNode, definitionsMap);
|
|
160
|
+
}
|
|
161
|
+
})
|
|
162
|
+
.filter(nonNullFilter);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function internalProsemirrorNodesToBlocks(
|
|
166
|
+
prosemirrorNodes: ProsemirrorNode[],
|
|
167
|
+
definitionsMap: Map<string, PageBlockDefinition>
|
|
168
|
+
): PageBlockEditorModel[] {
|
|
169
|
+
return prosemirrorNodes
|
|
170
|
+
.map(prosemirrorNode => {
|
|
171
|
+
return internalProsemirrorNodeToBlock(prosemirrorNode, definitionsMap);
|
|
172
|
+
})
|
|
173
|
+
.filter(nonNullFilter);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function internalProsemirrorNodeToBlock(
|
|
177
|
+
prosemirrorNode: ProsemirrorNode,
|
|
178
|
+
definitionsMap: Map<string, PageBlockDefinition>
|
|
179
|
+
) {
|
|
180
|
+
const definitionId = getProsemirrorAttribute(prosemirrorNode, "definitionId", z.string());
|
|
181
|
+
if (!definitionId) {
|
|
182
|
+
console.warn(`definitionId on ${prosemirrorNode.type} is required to be interpreted as a block, skipping node`);
|
|
183
|
+
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const definition = definitionsMap.get(definitionId);
|
|
188
|
+
if (!definition) {
|
|
189
|
+
console.warn(
|
|
190
|
+
`Block definitionId "${definitionId}" (prosemirror node ${prosemirrorNode.type}) is not among available definitions`
|
|
191
|
+
);
|
|
192
|
+
console.warn(prosemirrorNode);
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return prosemirrorNodeToBlock(prosemirrorNode, definition);
|
|
197
|
+
}
|
|
198
|
+
|
|
98
199
|
export function prosemirrorNodeToBlock(
|
|
99
200
|
prosemirrorNode: ProsemirrorNode,
|
|
100
201
|
definition: PageBlockDefinition
|
|
@@ -139,6 +240,7 @@ function parseAsRichText(
|
|
|
139
240
|
return {
|
|
140
241
|
// TODO Artem: indent
|
|
141
242
|
id: id,
|
|
243
|
+
type: "Block",
|
|
142
244
|
|
|
143
245
|
...(variantId && { variantId: variantId }),
|
|
144
246
|
|
|
@@ -197,6 +299,7 @@ function parseAsMultiRichText(
|
|
|
197
299
|
return {
|
|
198
300
|
// TODO Artem: indent
|
|
199
301
|
id: id,
|
|
302
|
+
type: "Block",
|
|
200
303
|
data: {
|
|
201
304
|
packageId: definition.id,
|
|
202
305
|
indentLevel: 0,
|
|
@@ -321,6 +424,7 @@ function parseAsTable(
|
|
|
321
424
|
|
|
322
425
|
return {
|
|
323
426
|
id: id,
|
|
427
|
+
type: "Block",
|
|
324
428
|
data: {
|
|
325
429
|
packageId: "io.supernova.block.table",
|
|
326
430
|
indentLevel: 0,
|
|
@@ -438,6 +542,7 @@ function emptyTable(id: string, variantId?: string, indentLevel?: number): PageB
|
|
|
438
542
|
|
|
439
543
|
return {
|
|
440
544
|
id: id,
|
|
545
|
+
type: "Block",
|
|
441
546
|
data: {
|
|
442
547
|
packageId: "io.supernova.block.table",
|
|
443
548
|
indentLevel: indentLevel ?? 0,
|
|
@@ -479,6 +584,7 @@ function parseAsDivider(
|
|
|
479
584
|
|
|
480
585
|
return {
|
|
481
586
|
id: id,
|
|
587
|
+
type: "Block",
|
|
482
588
|
data: {
|
|
483
589
|
packageId: definition.id,
|
|
484
590
|
indentLevel: 0,
|
|
@@ -509,6 +615,7 @@ function parseAsCustomBlock(
|
|
|
509
615
|
|
|
510
616
|
return {
|
|
511
617
|
id: id,
|
|
618
|
+
type: "Block",
|
|
512
619
|
data: {
|
|
513
620
|
packageId: definition.id,
|
|
514
621
|
indentLevel: 0,
|
|
@@ -535,7 +642,15 @@ function parseBlockItems(prosemirrorNode: ProsemirrorNode, definition: PageBlock
|
|
|
535
642
|
}
|
|
536
643
|
|
|
537
644
|
function parseAppearance(prosemirrorNode: ProsemirrorNode): PageBlockAppearanceV2 | undefined {
|
|
538
|
-
|
|
645
|
+
let appearance: PageBlockAppearanceV2 = {};
|
|
646
|
+
|
|
647
|
+
const rawAppearanceString = getProsemirrorAttribute(prosemirrorNode, "appearance", z.string().optional());
|
|
648
|
+
if (rawAppearanceString) {
|
|
649
|
+
const parsedAppearance = PageBlockAppearanceV2.safeParse(JSON.parse(rawAppearanceString));
|
|
650
|
+
if (parsedAppearance.success) {
|
|
651
|
+
appearance = parsedAppearance.data;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
539
654
|
|
|
540
655
|
const columns = getProsemirrorAttribute(prosemirrorNode, "columns", z.number().optional());
|
|
541
656
|
if (columns) {
|