@supernova-studio/client 0.9.1 → 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 +75 -61
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +75 -61
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/docs-editor/prosemirror-to-blocks.ts +80 -64
package/dist/index.js
CHANGED
|
@@ -6962,6 +6962,7 @@ var blocks = [
|
|
|
6962
6962
|
|
|
6963
6963
|
// src/docs-editor/prosemirror-to-blocks.ts
|
|
6964
6964
|
|
|
6965
|
+
|
|
6965
6966
|
function yDocToPage(yDoc, definitions) {
|
|
6966
6967
|
return yXmlFragmentToPage(yDoc.getXmlFragment("default"), definitions);
|
|
6967
6968
|
}
|
|
@@ -6973,14 +6974,21 @@ function prosemirrorDocToPage(prosemirrorDoc, definitions) {
|
|
|
6973
6974
|
const definitionsById = mapByUnique(definitions, (d) => d.id);
|
|
6974
6975
|
return {
|
|
6975
6976
|
blocks: (_nullishCoalesce(prosemirrorDoc.content, () => ( []))).map((prosemirrorNode) => {
|
|
6976
|
-
const definitionId =
|
|
6977
|
-
if (!definitionId)
|
|
6978
|
-
|
|
6979
|
-
|
|
6980
|
-
|
|
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
|
+
}
|
|
6981
6984
|
const definition = definitionsById.get(definitionId);
|
|
6982
|
-
if (!definition)
|
|
6983
|
-
|
|
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
|
+
}
|
|
6984
6992
|
return prosemirrorNodeToBlock(prosemirrorNode, definition);
|
|
6985
6993
|
}).filter(nonNullFilter2)
|
|
6986
6994
|
};
|
|
@@ -7008,12 +7016,11 @@ function prosemirrorNodeToBlock(prosemirrorNode, definition) {
|
|
|
7008
7016
|
return parseAsCustomBlock(prosemirrorNode, definition);
|
|
7009
7017
|
}
|
|
7010
7018
|
function parseAsRichText(prosemirrorNode, definition, property) {
|
|
7011
|
-
const id =
|
|
7012
|
-
if (
|
|
7019
|
+
const id = getProsemirrorBlockId(prosemirrorNode);
|
|
7020
|
+
if (!id)
|
|
7013
7021
|
return null;
|
|
7014
|
-
const
|
|
7015
|
-
const
|
|
7016
|
-
const calloutType = parseCalloutType(parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "type"));
|
|
7022
|
+
const variantId = getProsemirrorBlockVariantId(prosemirrorNode);
|
|
7023
|
+
const calloutType = parseCalloutType(getProsemirrorAttribute(prosemirrorNode, "type", _zod.z.string()));
|
|
7017
7024
|
return {
|
|
7018
7025
|
// TODO Artem: indent
|
|
7019
7026
|
id,
|
|
@@ -7052,11 +7059,10 @@ function parseCalloutType(prosemirrorCalloutType) {
|
|
|
7052
7059
|
}
|
|
7053
7060
|
}
|
|
7054
7061
|
function parseAsMultiRichText(prosemirrorNode, definition, property) {
|
|
7055
|
-
const id =
|
|
7056
|
-
if (
|
|
7062
|
+
const id = getProsemirrorBlockId(prosemirrorNode);
|
|
7063
|
+
if (!id)
|
|
7057
7064
|
return null;
|
|
7058
|
-
const
|
|
7059
|
-
const variantId = typeof variantIdRaw === "string" ? variantIdRaw : void 0;
|
|
7065
|
+
const variantId = getProsemirrorBlockVariantId(prosemirrorNode);
|
|
7060
7066
|
return {
|
|
7061
7067
|
// TODO Artem: indent
|
|
7062
7068
|
id,
|
|
@@ -7112,10 +7118,8 @@ function parseRichTextAttribute(mark) {
|
|
|
7112
7118
|
case "code":
|
|
7113
7119
|
return { type: "Code" };
|
|
7114
7120
|
case "link":
|
|
7115
|
-
const
|
|
7116
|
-
const
|
|
7117
|
-
const hrefRaw = parseProsemirrorOptionalBlockAttribute(mark, "href");
|
|
7118
|
-
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());
|
|
7119
7123
|
return {
|
|
7120
7124
|
type: "Link",
|
|
7121
7125
|
openInNewWindow: _optionalChain([mark, 'access', _15 => _15.attrs, 'optionalAccess', _16 => _16.target]) !== "_self",
|
|
@@ -7126,12 +7130,11 @@ function parseRichTextAttribute(mark) {
|
|
|
7126
7130
|
return null;
|
|
7127
7131
|
}
|
|
7128
7132
|
function parseAsTable(prosemirrorNode, definition, property) {
|
|
7129
|
-
const id =
|
|
7130
|
-
if (
|
|
7133
|
+
const id = getProsemirrorBlockId(prosemirrorNode);
|
|
7134
|
+
if (!id)
|
|
7131
7135
|
return null;
|
|
7132
|
-
const
|
|
7133
|
-
const
|
|
7134
|
-
const hasBorder = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "hasBorder") !== false;
|
|
7136
|
+
const variantId = getProsemirrorBlockVariantId(prosemirrorNode);
|
|
7137
|
+
const hasBorder = getProsemirrorAttribute(prosemirrorNode, "hasBorder", _zod.z.boolean()) !== false;
|
|
7135
7138
|
const tableChild = _optionalChain([prosemirrorNode, 'access', _17 => _17.content, 'optionalAccess', _18 => _18.find, 'call', _19 => _19((c) => c.type === "table")]);
|
|
7136
7139
|
if (!tableChild) {
|
|
7137
7140
|
return emptyTable(id, variantId, 0);
|
|
@@ -7173,13 +7176,13 @@ function parseAsTable(prosemirrorNode, definition, property) {
|
|
|
7173
7176
|
};
|
|
7174
7177
|
}
|
|
7175
7178
|
function parseAsTableCell(prosemirrorNode) {
|
|
7176
|
-
const id =
|
|
7177
|
-
if (
|
|
7179
|
+
const id = getProsemirrorBlockId(prosemirrorNode);
|
|
7180
|
+
if (!id)
|
|
7178
7181
|
return null;
|
|
7179
|
-
const textAlign =
|
|
7182
|
+
const textAlign = getProsemirrorAttribute(prosemirrorNode, "textAlign", _zod.z.string());
|
|
7180
7183
|
let columnWidth;
|
|
7181
|
-
const columnWidthArray =
|
|
7182
|
-
if (
|
|
7184
|
+
const columnWidthArray = getProsemirrorAttribute(prosemirrorNode, "colwidth", _zod.z.array(_zod.z.number()));
|
|
7185
|
+
if (columnWidthArray) {
|
|
7183
7186
|
columnWidth = columnWidthArray[0];
|
|
7184
7187
|
}
|
|
7185
7188
|
const tableNodes = (_nullishCoalesce(prosemirrorNode.content, () => ( []))).map(parseAsTableNode).filter(nonNullFilter2);
|
|
@@ -7212,8 +7215,8 @@ function parseAsTableNode(prosemirrorNode) {
|
|
|
7212
7215
|
value: parseRichText(_nullishCoalesce(prosemirrorNode.content, () => ( [])))
|
|
7213
7216
|
};
|
|
7214
7217
|
case "image":
|
|
7215
|
-
const url =
|
|
7216
|
-
if (!url
|
|
7218
|
+
const url = getProsemirrorAttribute(prosemirrorNode, "src", _zod.z.string());
|
|
7219
|
+
if (!url)
|
|
7217
7220
|
return null;
|
|
7218
7221
|
return {
|
|
7219
7222
|
type: "Image",
|
|
@@ -7271,14 +7274,13 @@ function emptyTableCellContent() {
|
|
|
7271
7274
|
];
|
|
7272
7275
|
}
|
|
7273
7276
|
function parseAsEmbed(prosemirrorNode, definition, property) {
|
|
7274
|
-
const id =
|
|
7275
|
-
if (
|
|
7277
|
+
const id = getProsemirrorBlockId(prosemirrorNode);
|
|
7278
|
+
if (!id)
|
|
7276
7279
|
return null;
|
|
7277
|
-
const
|
|
7278
|
-
const
|
|
7279
|
-
const
|
|
7280
|
-
const
|
|
7281
|
-
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());
|
|
7282
7284
|
return {
|
|
7283
7285
|
id,
|
|
7284
7286
|
data: {
|
|
@@ -7301,11 +7303,10 @@ function parseAsEmbed(prosemirrorNode, definition, property) {
|
|
|
7301
7303
|
};
|
|
7302
7304
|
}
|
|
7303
7305
|
function parseAsDivider(prosemirrorNode, definition) {
|
|
7304
|
-
const id =
|
|
7305
|
-
if (
|
|
7306
|
+
const id = getProsemirrorBlockId(prosemirrorNode);
|
|
7307
|
+
if (!id)
|
|
7306
7308
|
return null;
|
|
7307
|
-
const
|
|
7308
|
-
const variantId = typeof variantIdRaw === "string" ? variantIdRaw : void 0;
|
|
7309
|
+
const variantId = getProsemirrorBlockVariantId(prosemirrorNode);
|
|
7309
7310
|
return {
|
|
7310
7311
|
id,
|
|
7311
7312
|
data: {
|
|
@@ -7317,11 +7318,10 @@ function parseAsDivider(prosemirrorNode, definition) {
|
|
|
7317
7318
|
};
|
|
7318
7319
|
}
|
|
7319
7320
|
function parseAsCustomBlock(prosemirrorNode, definition) {
|
|
7320
|
-
const id =
|
|
7321
|
-
if (
|
|
7321
|
+
const id = getProsemirrorBlockId(prosemirrorNode);
|
|
7322
|
+
if (!id)
|
|
7322
7323
|
return null;
|
|
7323
|
-
const
|
|
7324
|
-
const variantId = typeof variantIdRaw === "string" ? variantIdRaw : void 0;
|
|
7324
|
+
const variantId = getProsemirrorBlockVariantId(prosemirrorNode);
|
|
7325
7325
|
const appearance = parseAppearance(prosemirrorNode);
|
|
7326
7326
|
const parsedItems = parseBlockItems(prosemirrorNode, definition);
|
|
7327
7327
|
if (!parsedItems)
|
|
@@ -7338,8 +7338,8 @@ function parseAsCustomBlock(prosemirrorNode, definition) {
|
|
|
7338
7338
|
};
|
|
7339
7339
|
}
|
|
7340
7340
|
function parseBlockItems(prosemirrorNode, definition) {
|
|
7341
|
-
const itemsString =
|
|
7342
|
-
if (
|
|
7341
|
+
const itemsString = getProsemirrorAttribute(prosemirrorNode, "items", _zod.z.string());
|
|
7342
|
+
if (!itemsString)
|
|
7343
7343
|
return null;
|
|
7344
7344
|
const itemsJson = JSON.parse(itemsString);
|
|
7345
7345
|
if (!Array.isArray(itemsJson)) {
|
|
@@ -7350,12 +7350,12 @@ function parseBlockItems(prosemirrorNode, definition) {
|
|
|
7350
7350
|
}
|
|
7351
7351
|
function parseAppearance(prosemirrorNode) {
|
|
7352
7352
|
const appearance = {};
|
|
7353
|
-
const columns =
|
|
7354
|
-
if (
|
|
7353
|
+
const columns = getProsemirrorAttribute(prosemirrorNode, "columns", _zod.z.number());
|
|
7354
|
+
if (columns) {
|
|
7355
7355
|
appearance.numberOfColumns = columns;
|
|
7356
7356
|
}
|
|
7357
|
-
const backgroundColor =
|
|
7358
|
-
if (
|
|
7357
|
+
const backgroundColor = getProsemirrorAttribute(prosemirrorNode, "backgroundColor", _zod.z.string());
|
|
7358
|
+
if (backgroundColor) {
|
|
7359
7359
|
const parsedColor = ColorValue.safeParse(JSON.parse(backgroundColor));
|
|
7360
7360
|
if (parsedColor.success) {
|
|
7361
7361
|
appearance.itemBackgroundColor = parsedColor.data;
|
|
@@ -7442,15 +7442,29 @@ function valueSchemaForPropertyType(type) {
|
|
|
7442
7442
|
return PageBlockItemColorValue;
|
|
7443
7443
|
}
|
|
7444
7444
|
}
|
|
7445
|
-
function
|
|
7446
|
-
const
|
|
7447
|
-
if (!
|
|
7448
|
-
|
|
7449
|
-
|
|
7450
|
-
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;
|
|
7451
7450
|
}
|
|
7452
|
-
function
|
|
7453
|
-
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
|
+
}
|
|
7454
7468
|
}
|
|
7455
7469
|
function nonNullFilter2(item) {
|
|
7456
7470
|
return item !== null;
|