@supernova-studio/client 0.9.2 → 0.9.3
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.js +16 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/docs-editor/prosemirror-to-blocks.ts +20 -25
package/package.json
CHANGED
|
@@ -39,12 +39,13 @@ import {
|
|
|
39
39
|
PageBlockTableCellAlignment,
|
|
40
40
|
PageBlockAppearanceV2,
|
|
41
41
|
ColorValue,
|
|
42
|
+
nullishToOptional,
|
|
42
43
|
} from "@supernova-studio/model";
|
|
43
44
|
import { PageBlockEditorModel } from "./model/block";
|
|
44
45
|
import { DocumentationPageEditorModel } from "./model/page";
|
|
45
46
|
import { BlockDefinitionUtils } from "./utils";
|
|
46
47
|
import { yXmlFragmentToProsemirrorJSON } from "y-prosemirror";
|
|
47
|
-
import { ZodSchema, z } from "zod";
|
|
48
|
+
import { ZodAnyDef, ZodSchema, ZodTypeDef, z } from "zod";
|
|
48
49
|
|
|
49
50
|
export function yDocToPage(yDoc: Y.Doc, definitions: PageBlockDefinition[]): DocumentationPageEditorModel {
|
|
50
51
|
return yXmlFragmentToPage(yDoc.getXmlFragment("default"), definitions);
|
|
@@ -135,7 +136,7 @@ function parseAsRichText(
|
|
|
135
136
|
if (!id) return null;
|
|
136
137
|
|
|
137
138
|
const variantId = getProsemirrorBlockVariantId(prosemirrorNode);
|
|
138
|
-
const calloutType = parseCalloutType(getProsemirrorAttribute(prosemirrorNode, "type", z.string()));
|
|
139
|
+
const calloutType = parseCalloutType(getProsemirrorAttribute(prosemirrorNode, "type", z.string().optional()));
|
|
139
140
|
|
|
140
141
|
return {
|
|
141
142
|
// TODO Artem: indent
|
|
@@ -259,8 +260,8 @@ function parseRichTextAttribute(mark: ProsemirrorMark): PageBlockTextSpanAttribu
|
|
|
259
260
|
case "code":
|
|
260
261
|
return { type: "Code" };
|
|
261
262
|
case "link":
|
|
262
|
-
const itemId = getProsemirrorAttribute(mark, "itemId", z.string());
|
|
263
|
-
const href = getProsemirrorAttribute(mark, "href", z.string());
|
|
263
|
+
const itemId = getProsemirrorAttribute(mark, "itemId", z.string().optional());
|
|
264
|
+
const href = getProsemirrorAttribute(mark, "href", z.string().optional());
|
|
264
265
|
|
|
265
266
|
return {
|
|
266
267
|
type: "Link",
|
|
@@ -286,7 +287,7 @@ function parseAsTable(
|
|
|
286
287
|
if (!id) return null;
|
|
287
288
|
|
|
288
289
|
const variantId = getProsemirrorBlockVariantId(prosemirrorNode);
|
|
289
|
-
const hasBorder = getProsemirrorAttribute(prosemirrorNode, "hasBorder", z.boolean()) !== false;
|
|
290
|
+
const hasBorder = getProsemirrorAttribute(prosemirrorNode, "hasBorder", z.boolean().optional()) !== false;
|
|
290
291
|
|
|
291
292
|
const tableChild = prosemirrorNode.content?.find(c => c.type === "table");
|
|
292
293
|
if (!tableChild) {
|
|
@@ -342,10 +343,10 @@ function parseAsTableCell(prosemirrorNode: ProsemirrorNode): PageBlockItemTableC
|
|
|
342
343
|
const id = getProsemirrorBlockId(prosemirrorNode);
|
|
343
344
|
if (!id) return null;
|
|
344
345
|
|
|
345
|
-
const textAlign = getProsemirrorAttribute(prosemirrorNode, "textAlign", z.string());
|
|
346
|
+
const textAlign = getProsemirrorAttribute(prosemirrorNode, "textAlign", z.string().optional());
|
|
346
347
|
|
|
347
348
|
let columnWidth: number | undefined;
|
|
348
|
-
const columnWidthArray = getProsemirrorAttribute(prosemirrorNode, "colwidth", z.array(z.number()));
|
|
349
|
+
const columnWidthArray = getProsemirrorAttribute(prosemirrorNode, "colwidth", z.array(z.number()).optional());
|
|
349
350
|
if (columnWidthArray) {
|
|
350
351
|
columnWidth = columnWidthArray[0];
|
|
351
352
|
}
|
|
@@ -385,7 +386,7 @@ function parseAsTableNode(prosemirrorNode: ProsemirrorNode): PageBlockItemTableN
|
|
|
385
386
|
};
|
|
386
387
|
|
|
387
388
|
case "image":
|
|
388
|
-
const url = getProsemirrorAttribute(prosemirrorNode, "src", z.string());
|
|
389
|
+
const url = getProsemirrorAttribute(prosemirrorNode, "src", z.string().optional());
|
|
389
390
|
if (!url) return null;
|
|
390
391
|
|
|
391
392
|
return {
|
|
@@ -464,9 +465,9 @@ function parseAsEmbed(
|
|
|
464
465
|
|
|
465
466
|
const variantId = getProsemirrorBlockVariantId(prosemirrorNode);
|
|
466
467
|
|
|
467
|
-
const url = getProsemirrorAttribute(prosemirrorNode, "url", z.string());
|
|
468
|
-
const caption = getProsemirrorAttribute(prosemirrorNode, "caption", z.string());
|
|
469
|
-
const height = getProsemirrorAttribute(prosemirrorNode, "height", z.number());
|
|
468
|
+
const url = getProsemirrorAttribute(prosemirrorNode, "url", z.string().optional());
|
|
469
|
+
const caption = getProsemirrorAttribute(prosemirrorNode, "caption", z.string().optional());
|
|
470
|
+
const height = getProsemirrorAttribute(prosemirrorNode, "height", z.number().optional());
|
|
470
471
|
|
|
471
472
|
return {
|
|
472
473
|
id: id,
|
|
@@ -483,7 +484,7 @@ function parseAsEmbed(
|
|
|
483
484
|
[property.id]: {
|
|
484
485
|
value: url,
|
|
485
486
|
caption: caption,
|
|
486
|
-
height: height,
|
|
487
|
+
height: height ?? 200,
|
|
487
488
|
} as PageBlockItemEmbedValue,
|
|
488
489
|
},
|
|
489
490
|
},
|
|
@@ -565,12 +566,12 @@ function parseBlockItems(prosemirrorNode: ProsemirrorNode, definition: PageBlock
|
|
|
565
566
|
function parseAppearance(prosemirrorNode: ProsemirrorNode): PageBlockAppearanceV2 | undefined {
|
|
566
567
|
const appearance: PageBlockAppearanceV2 = {};
|
|
567
568
|
|
|
568
|
-
const columns = getProsemirrorAttribute(prosemirrorNode, "columns", z.number());
|
|
569
|
+
const columns = getProsemirrorAttribute(prosemirrorNode, "columns", z.number().optional());
|
|
569
570
|
if (columns) {
|
|
570
571
|
appearance.numberOfColumns = columns;
|
|
571
572
|
}
|
|
572
573
|
|
|
573
|
-
const backgroundColor = getProsemirrorAttribute(prosemirrorNode, "backgroundColor", z.string());
|
|
574
|
+
const backgroundColor = getProsemirrorAttribute(prosemirrorNode, "backgroundColor", z.string().optional());
|
|
574
575
|
if (backgroundColor) {
|
|
575
576
|
const parsedColor = ColorValue.safeParse(JSON.parse(backgroundColor));
|
|
576
577
|
if (parsedColor.success) {
|
|
@@ -678,25 +679,19 @@ function getProsemirrorBlockId(prosemirrorNode: ProsemirrorNode): string | undef
|
|
|
678
679
|
}
|
|
679
680
|
|
|
680
681
|
function getProsemirrorBlockVariantId(prosemirrorNode: ProsemirrorNode): string | undefined {
|
|
681
|
-
return getProsemirrorAttribute(prosemirrorNode, "variantId", z.string());
|
|
682
|
+
return getProsemirrorAttribute(prosemirrorNode, "variantId", nullishToOptional(z.string()));
|
|
682
683
|
}
|
|
683
684
|
|
|
684
|
-
function getProsemirrorAttribute<O>(
|
|
685
|
+
function getProsemirrorAttribute<I, O>(
|
|
685
686
|
prosemirrorNode: ProsemirrorNode,
|
|
686
687
|
attributeName: string,
|
|
687
|
-
validationSchema: ZodSchema<O>
|
|
688
|
+
validationSchema: ZodSchema<O, ZodTypeDef, I>
|
|
688
689
|
): O | undefined {
|
|
689
|
-
const
|
|
690
|
-
if (!attr) {
|
|
691
|
-
console.warn(`Prosemirror attribute ${attributeName} on ${prosemirrorNode.type} was not defined`);
|
|
692
|
-
return undefined;
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
const parsedAttr = validationSchema.safeParse(attr);
|
|
690
|
+
const parsedAttr = validationSchema.safeParse(prosemirrorNode.attrs?.[attributeName]);
|
|
696
691
|
if (parsedAttr.success) {
|
|
697
692
|
return parsedAttr.data;
|
|
698
693
|
} else {
|
|
699
|
-
console.warn(`Prosemirror attribute ${attributeName} on ${prosemirrorNode.type} is
|
|
694
|
+
console.warn(`Prosemirror attribute ${attributeName} on ${prosemirrorNode.type} is invalid`);
|
|
700
695
|
console.warn(parsedAttr.error.flatten());
|
|
701
696
|
return undefined;
|
|
702
697
|
}
|