@supernova-studio/client 0.9.0 → 0.9.2
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 +77 -62
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +77 -62
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/docs-editor/blocks-to-prosemirror.ts +3 -1
- package/src/docs-editor/prosemirror-to-blocks.ts +80 -64
package/dist/index.js
CHANGED
|
@@ -4076,8 +4076,9 @@ function pageToProsemirrorDoc(page, definitions) {
|
|
|
4076
4076
|
}
|
|
4077
4077
|
function blockDefinitionForBlock(block, definitions) {
|
|
4078
4078
|
const definition = definitions.find((d) => d.id === block.data.packageId);
|
|
4079
|
-
if (!definition)
|
|
4079
|
+
if (!definition) {
|
|
4080
4080
|
throw new Error(`Could not find definition for ${block.id} (${block.data.packageId})`);
|
|
4081
|
+
}
|
|
4081
4082
|
return definition;
|
|
4082
4083
|
}
|
|
4083
4084
|
function blockToProsemirrorNode(block, definition) {
|
|
@@ -6961,6 +6962,7 @@ var blocks = [
|
|
|
6961
6962
|
|
|
6962
6963
|
// src/docs-editor/prosemirror-to-blocks.ts
|
|
6963
6964
|
|
|
6965
|
+
|
|
6964
6966
|
function yDocToPage(yDoc, definitions) {
|
|
6965
6967
|
return yXmlFragmentToPage(yDoc.getXmlFragment("default"), definitions);
|
|
6966
6968
|
}
|
|
@@ -6972,14 +6974,21 @@ function prosemirrorDocToPage(prosemirrorDoc, definitions) {
|
|
|
6972
6974
|
const definitionsById = mapByUnique(definitions, (d) => d.id);
|
|
6973
6975
|
return {
|
|
6974
6976
|
blocks: (_nullishCoalesce(prosemirrorDoc.content, () => ( []))).map((prosemirrorNode) => {
|
|
6975
|
-
const definitionId =
|
|
6976
|
-
if (!definitionId)
|
|
6977
|
-
|
|
6978
|
-
|
|
6979
|
-
|
|
6977
|
+
const definitionId = getProsemirrorAttribute(prosemirrorNode, "definitionId", _zod.z.string());
|
|
6978
|
+
if (!definitionId) {
|
|
6979
|
+
console.warn(
|
|
6980
|
+
`definitionId on ${prosemirrorNode.type} is required to be interpreted as a block, skipping node`
|
|
6981
|
+
);
|
|
6982
|
+
return null;
|
|
6983
|
+
}
|
|
6980
6984
|
const definition = definitionsById.get(definitionId);
|
|
6981
|
-
if (!definition)
|
|
6982
|
-
|
|
6985
|
+
if (!definition) {
|
|
6986
|
+
console.warn(
|
|
6987
|
+
`Block definitionId "${definitionId}" (prosemirror node ${prosemirrorNode.type}) is not among available definitions`
|
|
6988
|
+
);
|
|
6989
|
+
console.warn(prosemirrorNode);
|
|
6990
|
+
return null;
|
|
6991
|
+
}
|
|
6983
6992
|
return prosemirrorNodeToBlock(prosemirrorNode, definition);
|
|
6984
6993
|
}).filter(nonNullFilter2)
|
|
6985
6994
|
};
|
|
@@ -7007,12 +7016,11 @@ function prosemirrorNodeToBlock(prosemirrorNode, definition) {
|
|
|
7007
7016
|
return parseAsCustomBlock(prosemirrorNode, definition);
|
|
7008
7017
|
}
|
|
7009
7018
|
function parseAsRichText(prosemirrorNode, definition, property) {
|
|
7010
|
-
const id =
|
|
7011
|
-
if (
|
|
7019
|
+
const id = getProsemirrorBlockId(prosemirrorNode);
|
|
7020
|
+
if (!id)
|
|
7012
7021
|
return null;
|
|
7013
|
-
const
|
|
7014
|
-
const
|
|
7015
|
-
const calloutType = parseCalloutType(parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "type"));
|
|
7022
|
+
const variantId = getProsemirrorBlockVariantId(prosemirrorNode);
|
|
7023
|
+
const calloutType = parseCalloutType(getProsemirrorAttribute(prosemirrorNode, "type", _zod.z.string()));
|
|
7016
7024
|
return {
|
|
7017
7025
|
// TODO Artem: indent
|
|
7018
7026
|
id,
|
|
@@ -7051,11 +7059,10 @@ function parseCalloutType(prosemirrorCalloutType) {
|
|
|
7051
7059
|
}
|
|
7052
7060
|
}
|
|
7053
7061
|
function parseAsMultiRichText(prosemirrorNode, definition, property) {
|
|
7054
|
-
const id =
|
|
7055
|
-
if (
|
|
7062
|
+
const id = getProsemirrorBlockId(prosemirrorNode);
|
|
7063
|
+
if (!id)
|
|
7056
7064
|
return null;
|
|
7057
|
-
const
|
|
7058
|
-
const variantId = typeof variantIdRaw === "string" ? variantIdRaw : void 0;
|
|
7065
|
+
const variantId = getProsemirrorBlockVariantId(prosemirrorNode);
|
|
7059
7066
|
return {
|
|
7060
7067
|
// TODO Artem: indent
|
|
7061
7068
|
id,
|
|
@@ -7111,10 +7118,8 @@ function parseRichTextAttribute(mark) {
|
|
|
7111
7118
|
case "code":
|
|
7112
7119
|
return { type: "Code" };
|
|
7113
7120
|
case "link":
|
|
7114
|
-
const
|
|
7115
|
-
const
|
|
7116
|
-
const hrefRaw = parseProsemirrorBlockAttribute(mark, "href");
|
|
7117
|
-
const href = typeof hrefRaw === "string" ? hrefRaw : void 0;
|
|
7121
|
+
const itemId = getProsemirrorAttribute(mark, "itemId", _zod.z.string());
|
|
7122
|
+
const href = getProsemirrorAttribute(mark, "href", _zod.z.string());
|
|
7118
7123
|
return {
|
|
7119
7124
|
type: "Link",
|
|
7120
7125
|
openInNewWindow: _optionalChain([mark, 'access', _15 => _15.attrs, 'optionalAccess', _16 => _16.target]) !== "_self",
|
|
@@ -7125,12 +7130,11 @@ function parseRichTextAttribute(mark) {
|
|
|
7125
7130
|
return null;
|
|
7126
7131
|
}
|
|
7127
7132
|
function parseAsTable(prosemirrorNode, definition, property) {
|
|
7128
|
-
const id =
|
|
7129
|
-
if (
|
|
7133
|
+
const id = getProsemirrorBlockId(prosemirrorNode);
|
|
7134
|
+
if (!id)
|
|
7130
7135
|
return null;
|
|
7131
|
-
const
|
|
7132
|
-
const
|
|
7133
|
-
const hasBorder = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "hasBorder") !== false;
|
|
7136
|
+
const variantId = getProsemirrorBlockVariantId(prosemirrorNode);
|
|
7137
|
+
const hasBorder = getProsemirrorAttribute(prosemirrorNode, "hasBorder", _zod.z.boolean()) !== false;
|
|
7134
7138
|
const tableChild = _optionalChain([prosemirrorNode, 'access', _17 => _17.content, 'optionalAccess', _18 => _18.find, 'call', _19 => _19((c) => c.type === "table")]);
|
|
7135
7139
|
if (!tableChild) {
|
|
7136
7140
|
return emptyTable(id, variantId, 0);
|
|
@@ -7172,13 +7176,13 @@ function parseAsTable(prosemirrorNode, definition, property) {
|
|
|
7172
7176
|
};
|
|
7173
7177
|
}
|
|
7174
7178
|
function parseAsTableCell(prosemirrorNode) {
|
|
7175
|
-
const id =
|
|
7176
|
-
if (
|
|
7179
|
+
const id = getProsemirrorBlockId(prosemirrorNode);
|
|
7180
|
+
if (!id)
|
|
7177
7181
|
return null;
|
|
7178
|
-
const textAlign =
|
|
7182
|
+
const textAlign = getProsemirrorAttribute(prosemirrorNode, "textAlign", _zod.z.string());
|
|
7179
7183
|
let columnWidth;
|
|
7180
|
-
const columnWidthArray =
|
|
7181
|
-
if (
|
|
7184
|
+
const columnWidthArray = getProsemirrorAttribute(prosemirrorNode, "colwidth", _zod.z.array(_zod.z.number()));
|
|
7185
|
+
if (columnWidthArray) {
|
|
7182
7186
|
columnWidth = columnWidthArray[0];
|
|
7183
7187
|
}
|
|
7184
7188
|
const tableNodes = (_nullishCoalesce(prosemirrorNode.content, () => ( []))).map(parseAsTableNode).filter(nonNullFilter2);
|
|
@@ -7211,8 +7215,8 @@ function parseAsTableNode(prosemirrorNode) {
|
|
|
7211
7215
|
value: parseRichText(_nullishCoalesce(prosemirrorNode.content, () => ( [])))
|
|
7212
7216
|
};
|
|
7213
7217
|
case "image":
|
|
7214
|
-
const url =
|
|
7215
|
-
if (!url
|
|
7218
|
+
const url = getProsemirrorAttribute(prosemirrorNode, "src", _zod.z.string());
|
|
7219
|
+
if (!url)
|
|
7216
7220
|
return null;
|
|
7217
7221
|
return {
|
|
7218
7222
|
type: "Image",
|
|
@@ -7270,14 +7274,13 @@ function emptyTableCellContent() {
|
|
|
7270
7274
|
];
|
|
7271
7275
|
}
|
|
7272
7276
|
function parseAsEmbed(prosemirrorNode, definition, property) {
|
|
7273
|
-
const id =
|
|
7274
|
-
if (
|
|
7277
|
+
const id = getProsemirrorBlockId(prosemirrorNode);
|
|
7278
|
+
if (!id)
|
|
7275
7279
|
return null;
|
|
7276
|
-
const
|
|
7277
|
-
const
|
|
7278
|
-
const
|
|
7279
|
-
const
|
|
7280
|
-
const height = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "height");
|
|
7280
|
+
const variantId = getProsemirrorBlockVariantId(prosemirrorNode);
|
|
7281
|
+
const url = getProsemirrorAttribute(prosemirrorNode, "url", _zod.z.string());
|
|
7282
|
+
const caption = getProsemirrorAttribute(prosemirrorNode, "caption", _zod.z.string());
|
|
7283
|
+
const height = getProsemirrorAttribute(prosemirrorNode, "height", _zod.z.number());
|
|
7281
7284
|
return {
|
|
7282
7285
|
id,
|
|
7283
7286
|
data: {
|
|
@@ -7300,11 +7303,10 @@ function parseAsEmbed(prosemirrorNode, definition, property) {
|
|
|
7300
7303
|
};
|
|
7301
7304
|
}
|
|
7302
7305
|
function parseAsDivider(prosemirrorNode, definition) {
|
|
7303
|
-
const id =
|
|
7304
|
-
if (
|
|
7306
|
+
const id = getProsemirrorBlockId(prosemirrorNode);
|
|
7307
|
+
if (!id)
|
|
7305
7308
|
return null;
|
|
7306
|
-
const
|
|
7307
|
-
const variantId = typeof variantIdRaw === "string" ? variantIdRaw : void 0;
|
|
7309
|
+
const variantId = getProsemirrorBlockVariantId(prosemirrorNode);
|
|
7308
7310
|
return {
|
|
7309
7311
|
id,
|
|
7310
7312
|
data: {
|
|
@@ -7316,11 +7318,10 @@ function parseAsDivider(prosemirrorNode, definition) {
|
|
|
7316
7318
|
};
|
|
7317
7319
|
}
|
|
7318
7320
|
function parseAsCustomBlock(prosemirrorNode, definition) {
|
|
7319
|
-
const id =
|
|
7320
|
-
if (
|
|
7321
|
+
const id = getProsemirrorBlockId(prosemirrorNode);
|
|
7322
|
+
if (!id)
|
|
7321
7323
|
return null;
|
|
7322
|
-
const
|
|
7323
|
-
const variantId = typeof variantIdRaw === "string" ? variantIdRaw : void 0;
|
|
7324
|
+
const variantId = getProsemirrorBlockVariantId(prosemirrorNode);
|
|
7324
7325
|
const appearance = parseAppearance(prosemirrorNode);
|
|
7325
7326
|
const parsedItems = parseBlockItems(prosemirrorNode, definition);
|
|
7326
7327
|
if (!parsedItems)
|
|
@@ -7337,8 +7338,8 @@ function parseAsCustomBlock(prosemirrorNode, definition) {
|
|
|
7337
7338
|
};
|
|
7338
7339
|
}
|
|
7339
7340
|
function parseBlockItems(prosemirrorNode, definition) {
|
|
7340
|
-
const itemsString =
|
|
7341
|
-
if (
|
|
7341
|
+
const itemsString = getProsemirrorAttribute(prosemirrorNode, "items", _zod.z.string());
|
|
7342
|
+
if (!itemsString)
|
|
7342
7343
|
return null;
|
|
7343
7344
|
const itemsJson = JSON.parse(itemsString);
|
|
7344
7345
|
if (!Array.isArray(itemsJson)) {
|
|
@@ -7349,12 +7350,12 @@ function parseBlockItems(prosemirrorNode, definition) {
|
|
|
7349
7350
|
}
|
|
7350
7351
|
function parseAppearance(prosemirrorNode) {
|
|
7351
7352
|
const appearance = {};
|
|
7352
|
-
const columns =
|
|
7353
|
-
if (
|
|
7353
|
+
const columns = getProsemirrorAttribute(prosemirrorNode, "columns", _zod.z.number());
|
|
7354
|
+
if (columns) {
|
|
7354
7355
|
appearance.numberOfColumns = columns;
|
|
7355
7356
|
}
|
|
7356
|
-
const backgroundColor =
|
|
7357
|
-
if (
|
|
7357
|
+
const backgroundColor = getProsemirrorAttribute(prosemirrorNode, "backgroundColor", _zod.z.string());
|
|
7358
|
+
if (backgroundColor) {
|
|
7358
7359
|
const parsedColor = ColorValue.safeParse(JSON.parse(backgroundColor));
|
|
7359
7360
|
if (parsedColor.success) {
|
|
7360
7361
|
appearance.itemBackgroundColor = parsedColor.data;
|
|
@@ -7441,15 +7442,29 @@ function valueSchemaForPropertyType(type) {
|
|
|
7441
7442
|
return PageBlockItemColorValue;
|
|
7442
7443
|
}
|
|
7443
7444
|
}
|
|
7444
|
-
function
|
|
7445
|
-
const
|
|
7446
|
-
if (!
|
|
7447
|
-
|
|
7448
|
-
|
|
7449
|
-
return attributeValue;
|
|
7445
|
+
function getProsemirrorBlockId(prosemirrorNode) {
|
|
7446
|
+
const id = getProsemirrorAttribute(prosemirrorNode, "id", _zod.z.string());
|
|
7447
|
+
if (!id)
|
|
7448
|
+
console.warn(`Prosemirror attribute "id" on ${prosemirrorNode.type} is required`);
|
|
7449
|
+
return id;
|
|
7450
7450
|
}
|
|
7451
|
-
function
|
|
7452
|
-
return
|
|
7451
|
+
function getProsemirrorBlockVariantId(prosemirrorNode) {
|
|
7452
|
+
return getProsemirrorAttribute(prosemirrorNode, "variantId", _zod.z.string());
|
|
7453
|
+
}
|
|
7454
|
+
function getProsemirrorAttribute(prosemirrorNode, attributeName, validationSchema) {
|
|
7455
|
+
const attr = _nullishCoalesce(_optionalChain([prosemirrorNode, 'access', _36 => _36.attrs, 'optionalAccess', _37 => _37[attributeName]]), () => ( void 0));
|
|
7456
|
+
if (!attr) {
|
|
7457
|
+
console.warn(`Prosemirror attribute ${attributeName} on ${prosemirrorNode.type} was not defined`);
|
|
7458
|
+
return void 0;
|
|
7459
|
+
}
|
|
7460
|
+
const parsedAttr = validationSchema.safeParse(attr);
|
|
7461
|
+
if (parsedAttr.success) {
|
|
7462
|
+
return parsedAttr.data;
|
|
7463
|
+
} else {
|
|
7464
|
+
console.warn(`Prosemirror attribute ${attributeName} on ${prosemirrorNode.type} is not valid and will be ignored`);
|
|
7465
|
+
console.warn(parsedAttr.error.flatten());
|
|
7466
|
+
return void 0;
|
|
7467
|
+
}
|
|
7453
7468
|
}
|
|
7454
7469
|
function nonNullFilter2(item) {
|
|
7455
7470
|
return item !== null;
|