@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,697 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PageBlockCalloutType,
|
|
3
|
-
PageBlockDefinition,
|
|
4
|
-
PageBlockDefinitionProperty,
|
|
5
|
-
PageBlockDefinitionRichTextOptions,
|
|
6
|
-
PageBlockItemImageValue,
|
|
7
|
-
PageBlockItemRichTextValue,
|
|
8
|
-
PageBlockItemTableCell,
|
|
9
|
-
PageBlockItemTableNode,
|
|
10
|
-
PageBlockItemTableRow,
|
|
11
|
-
PageBlockItemTableValue,
|
|
12
|
-
PageBlockTableCellAlignment,
|
|
13
|
-
PageBlockText,
|
|
14
|
-
PageBlockTextSpan,
|
|
15
|
-
PageBlockTextSpanAttribute,
|
|
16
|
-
PageSectionColumnV2,
|
|
17
|
-
PageSectionItemV2,
|
|
18
|
-
SupernovaException,
|
|
19
|
-
mapByUnique,
|
|
20
|
-
} from "@supernova-studio/model";
|
|
21
|
-
import { prosemirrorJSONToYXmlFragment } from "y-prosemirror";
|
|
22
|
-
import * as Y from "yjs";
|
|
23
|
-
import { ListNode, ListTreeBuilder } from "./list-tree-builder";
|
|
24
|
-
import { DocumentationPageEditorModel } from "./model";
|
|
25
|
-
import { PageBlockEditorModel, PageSectionEditorModel } from "./model/block";
|
|
26
|
-
import { pmSchema } from "./prosemirror";
|
|
27
|
-
import { ProsemirrorMark, ProsemirrorNode } from "./prosemirror/types";
|
|
28
|
-
import { BlockDefinitionUtils, BlockParsingUtils } from "./utils";
|
|
29
|
-
|
|
30
|
-
//
|
|
31
|
-
// Types
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
type BaseInput = {
|
|
35
|
-
block: PageBlockEditorModel;
|
|
36
|
-
definition: PageBlockDefinition;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
type InputWithProperty = BaseInput & {
|
|
40
|
-
property: PageBlockDefinitionProperty;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
type RichTextInputWithValue = InputWithProperty & {
|
|
44
|
-
richTextPropertyValue: PageBlockItemRichTextValue;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
//
|
|
48
|
-
// Implementation
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
export function pageToYDoc(doc: Y.Doc, page: DocumentationPageEditorModel, definitions: PageBlockDefinition[]) {
|
|
52
|
-
pageToYXmlFragment(page, definitions, doc.getXmlFragment("default"));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function pageToYXmlFragment(
|
|
56
|
-
page: DocumentationPageEditorModel,
|
|
57
|
-
definitions: PageBlockDefinition[],
|
|
58
|
-
fragment: Y.XmlFragment
|
|
59
|
-
): Y.XmlFragment {
|
|
60
|
-
const doc = pageToProsemirrorDoc(page, definitions);
|
|
61
|
-
// console.log(JSON.stringify(doc, null, 2));
|
|
62
|
-
return prosemirrorJSONToYXmlFragment(pmSchema, doc, fragment);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function pageToProsemirrorDoc(
|
|
66
|
-
page: DocumentationPageEditorModel,
|
|
67
|
-
definitions: PageBlockDefinition[]
|
|
68
|
-
): ProsemirrorNode {
|
|
69
|
-
const definitionsMap = mapByUnique(definitions, d => d.id);
|
|
70
|
-
|
|
71
|
-
const children: ProsemirrorNode[] = [];
|
|
72
|
-
let blockBuffer: PageBlockEditorModel[] = [];
|
|
73
|
-
|
|
74
|
-
page.blocks.forEach(b => {
|
|
75
|
-
if (b.type === "Block") {
|
|
76
|
-
blockBuffer.push(b);
|
|
77
|
-
} else if (b.type === "Section") {
|
|
78
|
-
if (blockBuffer.length) {
|
|
79
|
-
children.push(...internalBlocksToProsemirrorNodes(blockBuffer, definitionsMap));
|
|
80
|
-
blockBuffer = [];
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
children.push(internalSectionToProsemirrorNode(b, definitionsMap));
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
if (blockBuffer.length) {
|
|
88
|
-
children.push(...internalBlocksToProsemirrorNodes(blockBuffer, definitionsMap));
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
type: "doc",
|
|
93
|
-
content: children,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function blockToProsemirrorNode(
|
|
98
|
-
block: PageBlockEditorModel,
|
|
99
|
-
definition: PageBlockDefinition
|
|
100
|
-
): ProsemirrorNode | null {
|
|
101
|
-
const definitionsMap = new Map<string, PageBlockDefinition>([[definition.id, definition]]);
|
|
102
|
-
const nodes = internalBlocksToProsemirrorNodes([block], definitionsMap);
|
|
103
|
-
return nodes[0] ?? null;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
//
|
|
107
|
-
// Sections
|
|
108
|
-
//
|
|
109
|
-
|
|
110
|
-
function internalSectionToProsemirrorNode(
|
|
111
|
-
section: PageSectionEditorModel,
|
|
112
|
-
definitionsMap: Map<string, PageBlockDefinition>
|
|
113
|
-
): ProsemirrorNode {
|
|
114
|
-
return {
|
|
115
|
-
type: "tabsSection",
|
|
116
|
-
attrs: {
|
|
117
|
-
id: section.id,
|
|
118
|
-
...(section.variantId && { variantId: section.variantId }),
|
|
119
|
-
},
|
|
120
|
-
content: section.items.map(item => sectionItemToProsemirrorNode(item, definitionsMap)),
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function sectionItemToProsemirrorNode(
|
|
125
|
-
sectionItem: PageSectionItemV2,
|
|
126
|
-
definitionsMap: Map<string, PageBlockDefinition>
|
|
127
|
-
): ProsemirrorNode {
|
|
128
|
-
return {
|
|
129
|
-
type: "sectionItem",
|
|
130
|
-
attrs: {
|
|
131
|
-
id: sectionItem.id,
|
|
132
|
-
title: sectionItem.title,
|
|
133
|
-
},
|
|
134
|
-
content: sectionItem.columns.map(column => sectionColumnToProsemirrorNode(column, definitionsMap)),
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function sectionColumnToProsemirrorNode(
|
|
139
|
-
sectionColumn: PageSectionColumnV2,
|
|
140
|
-
definitionsMap: Map<string, PageBlockDefinition>
|
|
141
|
-
): ProsemirrorNode {
|
|
142
|
-
const blocks = internalBlocksToProsemirrorNodes(sectionColumn.blocks, definitionsMap);
|
|
143
|
-
|
|
144
|
-
if (!blocks.length) {
|
|
145
|
-
blocks.push({
|
|
146
|
-
type: "paragraph",
|
|
147
|
-
attrs: {
|
|
148
|
-
id: "id",
|
|
149
|
-
definitionId: "io.supernova.block.rich-text",
|
|
150
|
-
},
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return {
|
|
155
|
-
type: "sectionItemColumn",
|
|
156
|
-
attrs: {
|
|
157
|
-
id: sectionColumn.id,
|
|
158
|
-
},
|
|
159
|
-
content: blocks,
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
//
|
|
164
|
-
// Blocks
|
|
165
|
-
//
|
|
166
|
-
|
|
167
|
-
function internalBlocksToProsemirrorNodes(
|
|
168
|
-
blocks: PageBlockEditorModel[],
|
|
169
|
-
definitionsMap: Map<string, PageBlockDefinition>
|
|
170
|
-
): ProsemirrorNode[] {
|
|
171
|
-
const result: ProsemirrorNode[] = [];
|
|
172
|
-
|
|
173
|
-
const listTreeBuilder = new ListTreeBuilder();
|
|
174
|
-
|
|
175
|
-
blocks.forEach(b => {
|
|
176
|
-
const definition = definitionsMap.get(b.data.packageId);
|
|
177
|
-
if (!definition) {
|
|
178
|
-
console.warn(`Could not find definition for ${b.id} (${b.data.packageId})`);
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const multiRichTextProp = BlockDefinitionUtils.firstMultiRichTextProperty(definition);
|
|
183
|
-
|
|
184
|
-
if (multiRichTextProp) {
|
|
185
|
-
// This is list
|
|
186
|
-
const node = listTreeBuilder.addWithProperty(b, multiRichTextProp);
|
|
187
|
-
if (node) {
|
|
188
|
-
result.push(serializeAsMultiRichTextBlock(node));
|
|
189
|
-
}
|
|
190
|
-
} else {
|
|
191
|
-
// This is not a list
|
|
192
|
-
// Flush the tree builder to inject a non-tree block after it
|
|
193
|
-
const tree = listTreeBuilder.flush();
|
|
194
|
-
if (tree) {
|
|
195
|
-
result.push(serializeAsMultiRichTextBlock(tree));
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const node = internalBlockToProsemirrorNode(b, definition);
|
|
199
|
-
node && result.push(node);
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
const tree = listTreeBuilder.flush();
|
|
204
|
-
if (tree) {
|
|
205
|
-
result.push(serializeAsMultiRichTextBlock(tree));
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return result;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
function internalBlockToProsemirrorNode(
|
|
212
|
-
block: PageBlockEditorModel,
|
|
213
|
-
definition: PageBlockDefinition
|
|
214
|
-
): ProsemirrorNode | null {
|
|
215
|
-
// Single rich text
|
|
216
|
-
const richTextProperty = BlockDefinitionUtils.firstRichTextProperty(definition);
|
|
217
|
-
if (richTextProperty) {
|
|
218
|
-
return serializeAsRichTextBlock({
|
|
219
|
-
block: block,
|
|
220
|
-
definition: definition,
|
|
221
|
-
property: richTextProperty,
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
const tableProperty = BlockDefinitionUtils.firstTableProperty(definition);
|
|
226
|
-
if (tableProperty) {
|
|
227
|
-
return serializeAsTable({
|
|
228
|
-
block: block,
|
|
229
|
-
definition: definition,
|
|
230
|
-
property: tableProperty,
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// Divider
|
|
235
|
-
if (block.data.packageId === "io.supernova.block.divider") {
|
|
236
|
-
return serializeAsDivider({
|
|
237
|
-
block: block,
|
|
238
|
-
definition: definition,
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return serializeAsCustomBlock(block, definition);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
//
|
|
246
|
-
// Single rich text blocks
|
|
247
|
-
//
|
|
248
|
-
|
|
249
|
-
function serializeAsRichTextBlock(input: InputWithProperty): ProsemirrorNode {
|
|
250
|
-
const { block, definition, property: richTextProperty } = input;
|
|
251
|
-
|
|
252
|
-
const blockItem = BlockParsingUtils.singleBlockItem(block);
|
|
253
|
-
const textPropertyValue = BlockParsingUtils.richTextPropertyValue(blockItem, richTextProperty.id);
|
|
254
|
-
|
|
255
|
-
const enrichedInput: RichTextInputWithValue = { ...input, richTextPropertyValue: textPropertyValue };
|
|
256
|
-
|
|
257
|
-
const parsedOptions = PageBlockDefinitionRichTextOptions.optional().parse(richTextProperty.options);
|
|
258
|
-
const style = parsedOptions?.richTextStyle ?? "Default";
|
|
259
|
-
|
|
260
|
-
switch (style) {
|
|
261
|
-
case "Callout":
|
|
262
|
-
return serializeAsCallout(enrichedInput);
|
|
263
|
-
case "Default":
|
|
264
|
-
return serializeAsParagraph(enrichedInput);
|
|
265
|
-
|
|
266
|
-
case "Quote":
|
|
267
|
-
return serializeAsBlockquote(enrichedInput);
|
|
268
|
-
|
|
269
|
-
case "Title1":
|
|
270
|
-
case "Title2":
|
|
271
|
-
case "Title3":
|
|
272
|
-
case "Title4":
|
|
273
|
-
case "Title5":
|
|
274
|
-
return serializeAsHeading(enrichedInput);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
function serializeAsParagraph(input: RichTextInputWithValue): ProsemirrorNode {
|
|
279
|
-
return {
|
|
280
|
-
type: "paragraph",
|
|
281
|
-
attrs: serializeBlockNodeAttributes(input.block),
|
|
282
|
-
...serializeRichTextNodePart(input.richTextPropertyValue.value),
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
function serializeAsHeading(input: RichTextInputWithValue): ProsemirrorNode {
|
|
287
|
-
return {
|
|
288
|
-
type: "heading",
|
|
289
|
-
attrs: {
|
|
290
|
-
...serializeBlockNodeAttributes(input.block),
|
|
291
|
-
level: richTextHeadingLevel(input.property),
|
|
292
|
-
},
|
|
293
|
-
...serializeRichTextNodePart(input.richTextPropertyValue.value),
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
function serializeAsBlockquote(input: RichTextInputWithValue): ProsemirrorNode {
|
|
298
|
-
return {
|
|
299
|
-
type: "blockquote",
|
|
300
|
-
attrs: serializeBlockNodeAttributes(input.block),
|
|
301
|
-
...serializeRichTextNodePart(input.richTextPropertyValue.value),
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
function serializeAsCallout(input: RichTextInputWithValue): ProsemirrorNode {
|
|
306
|
-
const calloutType = input.richTextPropertyValue.calloutType ?? "Info";
|
|
307
|
-
|
|
308
|
-
return {
|
|
309
|
-
type: "callout",
|
|
310
|
-
attrs: {
|
|
311
|
-
...serializeBlockNodeAttributes(input.block),
|
|
312
|
-
type: serializeCalloutType(calloutType),
|
|
313
|
-
},
|
|
314
|
-
...serializeRichTextNodePart(input.richTextPropertyValue.value),
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
//
|
|
319
|
-
// Multi rich text blocks
|
|
320
|
-
//
|
|
321
|
-
|
|
322
|
-
function serializeAsMultiRichTextBlock(node: ListNode): ProsemirrorNode {
|
|
323
|
-
switch (node.listType) {
|
|
324
|
-
case "Ordered":
|
|
325
|
-
return serializeAsOrderedList(node);
|
|
326
|
-
|
|
327
|
-
case "Unordered":
|
|
328
|
-
return serializeAsUnorderedList(node);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
function serializeAsOrderedList(tree: ListNode): ProsemirrorNode {
|
|
333
|
-
return {
|
|
334
|
-
type: "orderedList",
|
|
335
|
-
attrs: {
|
|
336
|
-
...serializeBlockNodeAttributes(tree.block),
|
|
337
|
-
start: "1",
|
|
338
|
-
},
|
|
339
|
-
content: serializeListContent(tree),
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
function serializeAsUnorderedList(tree: ListNode): ProsemirrorNode {
|
|
344
|
-
return {
|
|
345
|
-
type: "bulletList",
|
|
346
|
-
attrs: {
|
|
347
|
-
...serializeBlockNodeAttributes(tree.block),
|
|
348
|
-
},
|
|
349
|
-
content: serializeListContent(tree),
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
function serializeListContent(tree: ListNode): ProsemirrorNode[] {
|
|
354
|
-
const result: ProsemirrorNode[] = tree.leadingChildren.map(i => serializeAsTextListItem(i.text));
|
|
355
|
-
|
|
356
|
-
for (const child of tree.children) {
|
|
357
|
-
if (child.type === "ListItem") {
|
|
358
|
-
// Text list item
|
|
359
|
-
|
|
360
|
-
result.push(serializeAsTextListItem(child.text));
|
|
361
|
-
} else if (child.type === "List") {
|
|
362
|
-
// List list item
|
|
363
|
-
|
|
364
|
-
const previousNode = result[result.length - 1];
|
|
365
|
-
if (!previousNode) {
|
|
366
|
-
throw SupernovaException.shouldNotHappen("List node without previous node");
|
|
367
|
-
}
|
|
368
|
-
if (!previousNode.content) {
|
|
369
|
-
throw SupernovaException.shouldNotHappen("List item node has no content");
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
const serializedList = serializeAsMultiRichTextBlock(child);
|
|
373
|
-
previousNode.content.push(serializedList);
|
|
374
|
-
} else {
|
|
375
|
-
// Should noit happen
|
|
376
|
-
|
|
377
|
-
throw SupernovaException.shouldNotHappen(`Unknown list node type: ${child}`);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
return result;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
function serializeAsTextListItem(text: PageBlockText): ProsemirrorNode {
|
|
385
|
-
return {
|
|
386
|
-
type: "listItem",
|
|
387
|
-
content: [
|
|
388
|
-
{
|
|
389
|
-
type: "paragraph",
|
|
390
|
-
attrs: {
|
|
391
|
-
definitionId: "io.supernova.block.rich-text",
|
|
392
|
-
variantId: "default",
|
|
393
|
-
},
|
|
394
|
-
content: serializeRichText(text),
|
|
395
|
-
},
|
|
396
|
-
],
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
//
|
|
401
|
-
// Tables
|
|
402
|
-
//
|
|
403
|
-
|
|
404
|
-
function serializeAsTable(input: InputWithProperty): ProsemirrorNode {
|
|
405
|
-
const { block, definition, property: tableProperty } = input;
|
|
406
|
-
|
|
407
|
-
const blockItem = BlockParsingUtils.singleBlockItem(block);
|
|
408
|
-
const table = BlockParsingUtils.tablePropertyValue(blockItem, tableProperty.id);
|
|
409
|
-
|
|
410
|
-
return {
|
|
411
|
-
type: "tableContainer",
|
|
412
|
-
attrs: {
|
|
413
|
-
...serializeBlockNodeAttributes(input.block),
|
|
414
|
-
hasBorder: table.showBorder ?? true,
|
|
415
|
-
},
|
|
416
|
-
|
|
417
|
-
content: [
|
|
418
|
-
{
|
|
419
|
-
type: "table",
|
|
420
|
-
content: serializeTableRows(table),
|
|
421
|
-
},
|
|
422
|
-
],
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
function serializeTableRows(table: PageBlockItemTableValue): ProsemirrorNode[] {
|
|
427
|
-
// If no rows are present, we have to generate a least one empty row
|
|
428
|
-
const rows: PageBlockItemTableRow[] = table.value.length ? table.value : [{ cells: [] }];
|
|
429
|
-
|
|
430
|
-
return rows.map<ProsemirrorNode>((row, rowIndex) => {
|
|
431
|
-
const isHeaderRow = rowIndex === 0 && table.highlightHeaderRow === true;
|
|
432
|
-
|
|
433
|
-
// If no cells are present, we have to generate at least one cell
|
|
434
|
-
const cells: PageBlockItemTableCell[] = row.cells.length ? row.cells : [{ id: "", alignment: "Left", nodes: [] }];
|
|
435
|
-
|
|
436
|
-
return {
|
|
437
|
-
type: "tableRow",
|
|
438
|
-
content: cells.map<ProsemirrorNode>((cell, cellIndex) => {
|
|
439
|
-
const isHeaderColumn = cellIndex === 0 && table.highlightHeaderColumn === true;
|
|
440
|
-
|
|
441
|
-
return {
|
|
442
|
-
type: isHeaderRow || isHeaderColumn ? "tableHeader" : "tableCell",
|
|
443
|
-
attrs: {
|
|
444
|
-
...(cell.id && { id: cell.id }),
|
|
445
|
-
textAlign: serializeTableCellAlignment(cell.alignment),
|
|
446
|
-
colspan: 1,
|
|
447
|
-
rowspan: 1,
|
|
448
|
-
...(cell.columnWidth && { colwidth: [cell.columnWidth] }),
|
|
449
|
-
},
|
|
450
|
-
content: serializeTableCellNodes(cell),
|
|
451
|
-
};
|
|
452
|
-
}),
|
|
453
|
-
};
|
|
454
|
-
});
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
function serializeTableCellAlignment(alignment: PageBlockTableCellAlignment) {
|
|
458
|
-
switch (alignment) {
|
|
459
|
-
case "Left":
|
|
460
|
-
return "left";
|
|
461
|
-
case "Center":
|
|
462
|
-
return "center";
|
|
463
|
-
case "Right":
|
|
464
|
-
return "right";
|
|
465
|
-
|
|
466
|
-
default:
|
|
467
|
-
return "left";
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
function serializeTableCellNodes(cell: PageBlockItemTableCell): ProsemirrorNode[] {
|
|
472
|
-
const result = cell.nodes.map(serializeTableNode);
|
|
473
|
-
|
|
474
|
-
if (result.length) {
|
|
475
|
-
return result;
|
|
476
|
-
} else {
|
|
477
|
-
return [{ type: "paragraph" }];
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
function serializeTableNode(node: PageBlockItemTableNode): ProsemirrorNode {
|
|
482
|
-
switch (node.type) {
|
|
483
|
-
case "RichText":
|
|
484
|
-
return {
|
|
485
|
-
type: "paragraph",
|
|
486
|
-
attrs: {
|
|
487
|
-
id: node.id,
|
|
488
|
-
definitionId: "io.supernova.block.rich-text",
|
|
489
|
-
},
|
|
490
|
-
...serializeRichTextNodePart(node.value),
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
case "Image":
|
|
494
|
-
return {
|
|
495
|
-
type: "image",
|
|
496
|
-
attrs: {
|
|
497
|
-
id: node.id,
|
|
498
|
-
definitionId: "io.supernova.block.image",
|
|
499
|
-
items: JSON.stringify([
|
|
500
|
-
{
|
|
501
|
-
id: node.id,
|
|
502
|
-
props: {
|
|
503
|
-
image: {
|
|
504
|
-
caption: node.caption,
|
|
505
|
-
value: node.value,
|
|
506
|
-
} satisfies PageBlockItemImageValue,
|
|
507
|
-
},
|
|
508
|
-
},
|
|
509
|
-
]),
|
|
510
|
-
},
|
|
511
|
-
};
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
//
|
|
516
|
-
// Divider
|
|
517
|
-
//
|
|
518
|
-
|
|
519
|
-
function serializeAsDivider(input: BaseInput): ProsemirrorNode {
|
|
520
|
-
return {
|
|
521
|
-
type: "horizontalRule",
|
|
522
|
-
attrs: serializeBlockNodeAttributes(input.block),
|
|
523
|
-
};
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
//
|
|
527
|
-
// Attributes
|
|
528
|
-
//
|
|
529
|
-
|
|
530
|
-
function serializeBlockNodeAttributes(block: PageBlockEditorModel) {
|
|
531
|
-
return {
|
|
532
|
-
id: block.id,
|
|
533
|
-
definitionId: block.data.packageId,
|
|
534
|
-
...(block.data.variantId && { variantId: block.data.variantId }),
|
|
535
|
-
};
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
function richTextHeadingLevel(property: PageBlockDefinitionProperty): number | undefined {
|
|
539
|
-
const style = property.options?.richTextStyle;
|
|
540
|
-
if (!style) return undefined;
|
|
541
|
-
|
|
542
|
-
switch (style) {
|
|
543
|
-
case "Title1":
|
|
544
|
-
return 1;
|
|
545
|
-
case "Title2":
|
|
546
|
-
return 2;
|
|
547
|
-
case "Title3":
|
|
548
|
-
return 3;
|
|
549
|
-
case "Title4":
|
|
550
|
-
return 4;
|
|
551
|
-
case "Title5":
|
|
552
|
-
return 5;
|
|
553
|
-
case "Callout":
|
|
554
|
-
case "Default":
|
|
555
|
-
case "Quote":
|
|
556
|
-
return undefined;
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
function serializeCalloutType(calloutType: PageBlockCalloutType) {
|
|
561
|
-
switch (calloutType) {
|
|
562
|
-
case "Error":
|
|
563
|
-
return "critical";
|
|
564
|
-
case "Info":
|
|
565
|
-
return "neutral";
|
|
566
|
-
case "Success":
|
|
567
|
-
return "positive";
|
|
568
|
-
case "Warning":
|
|
569
|
-
return "warning";
|
|
570
|
-
case "Primary":
|
|
571
|
-
return "primary";
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
//
|
|
576
|
-
// Rich text
|
|
577
|
-
//
|
|
578
|
-
|
|
579
|
-
function serializeRichTextNodePart(richText: PageBlockText): Pick<ProsemirrorNode, "content"> {
|
|
580
|
-
const spans = serializeRichText(richText);
|
|
581
|
-
if (spans.length) return { content: spans };
|
|
582
|
-
return {};
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
function serializeRichText(richText: PageBlockText) {
|
|
586
|
-
return richText.spans.map(serializeTextSpan).flat();
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
function serializeTextSpan(span: PageBlockTextSpan): ProsemirrorNode[] {
|
|
590
|
-
const hardBreakType = "hardBreak";
|
|
591
|
-
|
|
592
|
-
const marks = span.attributes.map(serializeTextSpanAttribute);
|
|
593
|
-
|
|
594
|
-
const textParts = span.text.split("\n");
|
|
595
|
-
const interspersed: ProsemirrorNode[] = [
|
|
596
|
-
{
|
|
597
|
-
type: "text",
|
|
598
|
-
text: textParts[0],
|
|
599
|
-
|
|
600
|
-
...(marks.length && { marks: marks }),
|
|
601
|
-
},
|
|
602
|
-
];
|
|
603
|
-
|
|
604
|
-
for (let i = 1; i < textParts.length; i++) {
|
|
605
|
-
interspersed.push(
|
|
606
|
-
{
|
|
607
|
-
type: hardBreakType,
|
|
608
|
-
},
|
|
609
|
-
{
|
|
610
|
-
type: "text",
|
|
611
|
-
text: textParts[i],
|
|
612
|
-
|
|
613
|
-
...(marks.length && { marks: marks }),
|
|
614
|
-
}
|
|
615
|
-
);
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
return interspersed.filter(t => t.type === hardBreakType || !!t.text);
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
function serializeTextSpanAttribute(spanAttribute: PageBlockTextSpanAttribute): ProsemirrorMark {
|
|
622
|
-
switch (spanAttribute.type) {
|
|
623
|
-
case "Bold":
|
|
624
|
-
return { type: "bold", attrs: {} };
|
|
625
|
-
case "Italic":
|
|
626
|
-
return { type: "italic", attrs: {} };
|
|
627
|
-
case "Strikethrough":
|
|
628
|
-
return { type: "strike", attrs: {} };
|
|
629
|
-
case "Code":
|
|
630
|
-
return { type: "code", attrs: {} };
|
|
631
|
-
case "Link":
|
|
632
|
-
if (spanAttribute.link) {
|
|
633
|
-
return serializeLinkMark(
|
|
634
|
-
spanAttribute.link,
|
|
635
|
-
spanAttribute.openInNewTab ?? spanAttribute.openInNewWindow ?? false
|
|
636
|
-
);
|
|
637
|
-
} else if (spanAttribute.documentationItemId) {
|
|
638
|
-
return serializeLinkMark(
|
|
639
|
-
`@page:${spanAttribute.documentationItemId}`,
|
|
640
|
-
spanAttribute.openInNewTab ?? spanAttribute.openInNewWindow ?? false
|
|
641
|
-
);
|
|
642
|
-
} else {
|
|
643
|
-
return serializeLinkMark("about:blank", spanAttribute.openInNewTab ?? spanAttribute.openInNewWindow ?? false);
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
function serializeLinkMark(href: string, openInNewTab: boolean): ProsemirrorMark {
|
|
649
|
-
return {
|
|
650
|
-
type: "link",
|
|
651
|
-
attrs: {
|
|
652
|
-
href: href,
|
|
653
|
-
target: openInNewTab ? "_blank" : "_self",
|
|
654
|
-
rel: "noopener noreferrer nofollow",
|
|
655
|
-
class: "tiptap-link",
|
|
656
|
-
},
|
|
657
|
-
};
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
export function serializeAsCustomBlock(block: PageBlockEditorModel, definition: PageBlockDefinition): ProsemirrorNode {
|
|
661
|
-
const items = block.data.items.map(i => {
|
|
662
|
-
return {
|
|
663
|
-
id: i.id,
|
|
664
|
-
props: i.props,
|
|
665
|
-
linksTo: i.linksTo,
|
|
666
|
-
};
|
|
667
|
-
});
|
|
668
|
-
|
|
669
|
-
const columns = block.data.appearance?.numberOfColumns;
|
|
670
|
-
|
|
671
|
-
return {
|
|
672
|
-
type: serializeCustomBlockNodeType(block, definition),
|
|
673
|
-
attrs: {
|
|
674
|
-
id: block.id,
|
|
675
|
-
definitionId: block.data.packageId,
|
|
676
|
-
...(block.data.variantId && { variantId: block.data.variantId }),
|
|
677
|
-
items: JSON.stringify(items),
|
|
678
|
-
|
|
679
|
-
...(block.data.appearance && { appearance: JSON.stringify(block.data.appearance) }),
|
|
680
|
-
...(columns && { columns: columns }),
|
|
681
|
-
},
|
|
682
|
-
};
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
function serializeCustomBlockNodeType(block: PageBlockEditorModel, definition: PageBlockDefinition): string {
|
|
686
|
-
switch (block.data.packageId) {
|
|
687
|
-
case "io.supernova.block.image":
|
|
688
|
-
return "image";
|
|
689
|
-
|
|
690
|
-
default:
|
|
691
|
-
return "blockNode";
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
function nonNullFilter<T>(item: T | null): item is T {
|
|
696
|
-
return !!item;
|
|
697
|
-
}
|