@supernova-studio/client 0.6.0 → 0.7.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 +48 -32
- package/dist/index.d.ts +48 -32
- package/dist/index.js +85 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +77 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/docs-editor/blocks-to-prosemirror.ts +4 -0
- package/src/docs-editor/prosemirror-to-blocks.ts +88 -28
package/dist/index.js
CHANGED
|
@@ -876,7 +876,8 @@ var PageBlockImageType = _zod.z.enum(["Upload", "Asset", "FigmaFrame"]);
|
|
|
876
876
|
var PageBlockImageAlignment = _zod.z.enum(["Left", "Center", "Stretch"]);
|
|
877
877
|
var PageBlockTableCellAlignment = _zod.z.enum(["Left", "Center", "Right"]);
|
|
878
878
|
var PageBlockAppearanceV2 = _zod.z.object({
|
|
879
|
-
itemBackgroundColor: ColorValue
|
|
879
|
+
itemBackgroundColor: ColorValue.optional(),
|
|
880
|
+
numberOfColumns: _zod.z.number().optional()
|
|
880
881
|
});
|
|
881
882
|
var PageBlockItemUntypedValue = _zod.z.object({
|
|
882
883
|
value: _zod.z.any()
|
|
@@ -2068,6 +2069,14 @@ var WorkspaceMembership = _zod.z.object({
|
|
|
2068
2069
|
workspaceId: _zod.z.string(),
|
|
2069
2070
|
workspaceRole: _zod.z.nativeEnum(WorkspaceRole)
|
|
2070
2071
|
});
|
|
2072
|
+
var UpdateMembershipRolesInput = _zod.z.object({
|
|
2073
|
+
members: _zod.z.array(
|
|
2074
|
+
_zod.z.object({
|
|
2075
|
+
userId: _zod.z.string(),
|
|
2076
|
+
role: _zod.z.nativeEnum(WorkspaceRole)
|
|
2077
|
+
})
|
|
2078
|
+
)
|
|
2079
|
+
});
|
|
2071
2080
|
var WorkspaceIpWhitelistEntry = _zod.z.object({
|
|
2072
2081
|
isEnabled: _zod.z.boolean(),
|
|
2073
2082
|
name: _zod.z.string(),
|
|
@@ -4420,13 +4429,15 @@ function serializeAsCustomBlock(block, definition) {
|
|
|
4420
4429
|
linksTo: i.linksTo
|
|
4421
4430
|
};
|
|
4422
4431
|
});
|
|
4432
|
+
const columns = _optionalChain([block, 'access', _10 => _10.data, 'access', _11 => _11.appearance, 'optionalAccess', _12 => _12.numberOfColumns]);
|
|
4423
4433
|
return {
|
|
4424
4434
|
type: "blockNode",
|
|
4425
4435
|
attrs: {
|
|
4426
4436
|
id: block.id,
|
|
4427
4437
|
definitionId: block.data.packageId,
|
|
4428
4438
|
variantId: block.data.variantId,
|
|
4429
|
-
items: JSON.stringify(items)
|
|
4439
|
+
items: JSON.stringify(items),
|
|
4440
|
+
...columns && { columns }
|
|
4430
4441
|
}
|
|
4431
4442
|
};
|
|
4432
4443
|
}
|
|
@@ -5811,7 +5822,7 @@ function prosemirrorDocToPage(prosemirrorDoc, definitions) {
|
|
|
5811
5822
|
const definitionsById = mapByUnique(definitions, (d) => d.id);
|
|
5812
5823
|
return {
|
|
5813
5824
|
blocks: (_nullishCoalesce(prosemirrorDoc.content, () => ( []))).map((prosemirrorNode) => {
|
|
5814
|
-
const definitionId =
|
|
5825
|
+
const definitionId = parseProsemirrorBlockAttribute(prosemirrorNode, "definitionId");
|
|
5815
5826
|
if (!definitionId)
|
|
5816
5827
|
throw new Error(`Node is missing defintion id`);
|
|
5817
5828
|
if (typeof definitionId !== "string")
|
|
@@ -5847,7 +5858,10 @@ function prosemirrorNodeToBlock(prosemirrorNode, definition) {
|
|
|
5847
5858
|
}
|
|
5848
5859
|
function parseAsRichText(prosemirrorNode, definition, property) {
|
|
5849
5860
|
const id = parseProsemirrorBlockAttribute(prosemirrorNode, "id");
|
|
5850
|
-
|
|
5861
|
+
if (typeof id !== "string")
|
|
5862
|
+
return null;
|
|
5863
|
+
const variantIdRaw = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "variantId");
|
|
5864
|
+
const variantId = typeof variantIdRaw === "string" ? variantIdRaw : void 0;
|
|
5851
5865
|
const calloutType = parseCalloutType(parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "type"));
|
|
5852
5866
|
return {
|
|
5853
5867
|
// TODO Artem: indent
|
|
@@ -5888,7 +5902,10 @@ function parseCalloutType(prosemirrorCalloutType) {
|
|
|
5888
5902
|
}
|
|
5889
5903
|
function parseAsMultiRichText(prosemirrorNode, definition, property) {
|
|
5890
5904
|
const id = parseProsemirrorBlockAttribute(prosemirrorNode, "id");
|
|
5891
|
-
|
|
5905
|
+
if (typeof id !== "string")
|
|
5906
|
+
return null;
|
|
5907
|
+
const variantIdRaw = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "variantId");
|
|
5908
|
+
const variantId = typeof variantIdRaw === "string" ? variantIdRaw : void 0;
|
|
5892
5909
|
return {
|
|
5893
5910
|
// TODO Artem: indent
|
|
5894
5911
|
id,
|
|
@@ -5905,7 +5922,7 @@ function parseAsMultiRichText(prosemirrorNode, definition, property) {
|
|
|
5905
5922
|
value: (_nullishCoalesce(prosemirrorNode.content, () => ( []))).map((listItem) => {
|
|
5906
5923
|
if (listItem.type !== "listitem")
|
|
5907
5924
|
return null;
|
|
5908
|
-
if (!_optionalChain([listItem, 'access',
|
|
5925
|
+
if (!_optionalChain([listItem, 'access', _13 => _13.content, 'optionalAccess', _14 => _14.length]))
|
|
5909
5926
|
return parseRichText([]);
|
|
5910
5927
|
const paragraph = listItem.content[0];
|
|
5911
5928
|
if (paragraph.type !== "paragraph")
|
|
@@ -5944,11 +5961,13 @@ function parseRichTextAttribute(mark) {
|
|
|
5944
5961
|
case "code":
|
|
5945
5962
|
return { type: "Code" };
|
|
5946
5963
|
case "link":
|
|
5947
|
-
const
|
|
5948
|
-
const
|
|
5964
|
+
const itemIdRaw = parseProsemirrorBlockAttribute(mark, "itemId");
|
|
5965
|
+
const itemId = typeof itemIdRaw === "string" ? itemIdRaw : void 0;
|
|
5966
|
+
const hrefRaw = parseProsemirrorBlockAttribute(mark, "href");
|
|
5967
|
+
const href = typeof hrefRaw === "string" ? hrefRaw : void 0;
|
|
5949
5968
|
return {
|
|
5950
5969
|
type: "Link",
|
|
5951
|
-
openInNewWindow: _optionalChain([mark, 'access',
|
|
5970
|
+
openInNewWindow: _optionalChain([mark, 'access', _15 => _15.attrs, 'optionalAccess', _16 => _16.target]) !== "_self",
|
|
5952
5971
|
documentationItemId: itemId,
|
|
5953
5972
|
link: href
|
|
5954
5973
|
};
|
|
@@ -5957,19 +5976,22 @@ function parseRichTextAttribute(mark) {
|
|
|
5957
5976
|
}
|
|
5958
5977
|
function parseAsTable(prosemirrorNode, definition, property) {
|
|
5959
5978
|
const id = parseProsemirrorBlockAttribute(prosemirrorNode, "id");
|
|
5960
|
-
|
|
5979
|
+
if (typeof id !== "string")
|
|
5980
|
+
return null;
|
|
5981
|
+
const variantIdRaw = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "variantId");
|
|
5982
|
+
const variantId = typeof variantIdRaw === "string" ? variantIdRaw : void 0;
|
|
5961
5983
|
const hasBorder = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "hasBorder") !== false;
|
|
5962
|
-
const tableChild = _optionalChain([prosemirrorNode, 'access',
|
|
5984
|
+
const tableChild = _optionalChain([prosemirrorNode, 'access', _17 => _17.content, 'optionalAccess', _18 => _18.find, 'call', _19 => _19((c) => c.type === "table")]);
|
|
5963
5985
|
if (!tableChild) {
|
|
5964
5986
|
return emptyTable(id, variantId, 0);
|
|
5965
5987
|
}
|
|
5966
|
-
const rows = _nullishCoalesce(_optionalChain([tableChild, 'access',
|
|
5988
|
+
const rows = _nullishCoalesce(_optionalChain([tableChild, 'access', _20 => _20.content, 'optionalAccess', _21 => _21.filter, 'call', _22 => _22((c) => c.type === "tableRow" && !!_optionalChain([c, 'access', _23 => _23.content, 'optionalAccess', _24 => _24.length]))]), () => ( []));
|
|
5967
5989
|
if (!rows.length) {
|
|
5968
5990
|
return emptyTable(id, variantId, 0);
|
|
5969
5991
|
}
|
|
5970
|
-
const rowHeaderCells = _nullishCoalesce(_optionalChain([rows, 'access',
|
|
5971
|
-
const columnHeaderCells = rows.filter((r) => _optionalChain([r, 'access',
|
|
5972
|
-
const hasHeaderRow = _optionalChain([rows, 'access',
|
|
5992
|
+
const rowHeaderCells = _nullishCoalesce(_optionalChain([rows, 'access', _25 => _25[0], 'access', _26 => _26.content, 'optionalAccess', _27 => _27.filter, 'call', _28 => _28((c) => c.type === "tableHeader"), 'access', _29 => _29.length]), () => ( 0));
|
|
5993
|
+
const columnHeaderCells = rows.filter((r) => _optionalChain([r, 'access', _30 => _30.content, 'optionalAccess', _31 => _31[0], 'optionalAccess', _32 => _32.type]) === "tableHeader").length;
|
|
5994
|
+
const hasHeaderRow = _optionalChain([rows, 'access', _33 => _33[0], 'access', _34 => _34.content, 'optionalAccess', _35 => _35.length]) === rowHeaderCells;
|
|
5973
5995
|
const hasHeaderColumn = rows.length === columnHeaderCells;
|
|
5974
5996
|
const tableValue = {
|
|
5975
5997
|
showBorder: hasBorder,
|
|
@@ -5979,7 +6001,7 @@ function parseAsTable(prosemirrorNode, definition, property) {
|
|
|
5979
6001
|
};
|
|
5980
6002
|
tableValue.value = rows.map((row) => {
|
|
5981
6003
|
return {
|
|
5982
|
-
cells: (_nullishCoalesce(row.content, () => ( []))).map(parseAsTableCell)
|
|
6004
|
+
cells: (_nullishCoalesce(row.content, () => ( []))).map(parseAsTableCell).filter(nonNullFilter2)
|
|
5983
6005
|
};
|
|
5984
6006
|
});
|
|
5985
6007
|
return {
|
|
@@ -6001,6 +6023,8 @@ function parseAsTable(prosemirrorNode, definition, property) {
|
|
|
6001
6023
|
}
|
|
6002
6024
|
function parseAsTableCell(prosemirrorNode) {
|
|
6003
6025
|
const id = parseProsemirrorBlockAttribute(prosemirrorNode, "id");
|
|
6026
|
+
if (typeof id !== "string")
|
|
6027
|
+
return null;
|
|
6004
6028
|
const textAlign = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "textAlign");
|
|
6005
6029
|
let columnWidth;
|
|
6006
6030
|
const columnWidthArray = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "colwidth");
|
|
@@ -6097,7 +6121,10 @@ function emptyTableCellContent() {
|
|
|
6097
6121
|
}
|
|
6098
6122
|
function parseAsEmbed(prosemirrorNode, definition, property) {
|
|
6099
6123
|
const id = parseProsemirrorBlockAttribute(prosemirrorNode, "id");
|
|
6100
|
-
|
|
6124
|
+
if (typeof id !== "string")
|
|
6125
|
+
return null;
|
|
6126
|
+
const variantIdRaw = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "variantId");
|
|
6127
|
+
const variantId = typeof variantIdRaw === "string" ? variantIdRaw : void 0;
|
|
6101
6128
|
const url = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "url");
|
|
6102
6129
|
const caption = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "caption");
|
|
6103
6130
|
const height = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "height");
|
|
@@ -6124,7 +6151,10 @@ function parseAsEmbed(prosemirrorNode, definition, property) {
|
|
|
6124
6151
|
}
|
|
6125
6152
|
function parseAsDivider(prosemirrorNode, definition) {
|
|
6126
6153
|
const id = parseProsemirrorBlockAttribute(prosemirrorNode, "id");
|
|
6127
|
-
|
|
6154
|
+
if (typeof id !== "string")
|
|
6155
|
+
return null;
|
|
6156
|
+
const variantIdRaw = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "variantId");
|
|
6157
|
+
const variantId = typeof variantIdRaw === "string" ? variantIdRaw : void 0;
|
|
6128
6158
|
return {
|
|
6129
6159
|
id,
|
|
6130
6160
|
data: {
|
|
@@ -6137,24 +6167,53 @@ function parseAsDivider(prosemirrorNode, definition) {
|
|
|
6137
6167
|
}
|
|
6138
6168
|
function parseAsCustomBlock(prosemirrorNode, definition) {
|
|
6139
6169
|
const id = parseProsemirrorBlockAttribute(prosemirrorNode, "id");
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
const
|
|
6143
|
-
|
|
6144
|
-
|
|
6170
|
+
if (typeof id !== "string")
|
|
6171
|
+
return null;
|
|
6172
|
+
const variantIdRaw = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "variantId");
|
|
6173
|
+
const variantId = typeof variantIdRaw === "string" ? variantIdRaw : void 0;
|
|
6174
|
+
const appearance = parseAppearance(prosemirrorNode);
|
|
6175
|
+
const parsedItems = parseBlockItems(prosemirrorNode, definition);
|
|
6176
|
+
if (!parsedItems)
|
|
6145
6177
|
return null;
|
|
6146
|
-
}
|
|
6147
|
-
const parsedItems = itemsJson.map((i) => parseItem(i, definition)).filter(nonNullFilter2);
|
|
6148
6178
|
return {
|
|
6149
6179
|
id,
|
|
6150
6180
|
data: {
|
|
6151
6181
|
packageId: definition.id,
|
|
6152
6182
|
indentLevel: 0,
|
|
6153
6183
|
...variantId && { variantId },
|
|
6184
|
+
...appearance && { appearance },
|
|
6154
6185
|
items: parsedItems
|
|
6155
6186
|
}
|
|
6156
6187
|
};
|
|
6157
6188
|
}
|
|
6189
|
+
function parseBlockItems(prosemirrorNode, definition) {
|
|
6190
|
+
const itemsString = parseProsemirrorBlockAttribute(prosemirrorNode, "items");
|
|
6191
|
+
if (typeof itemsString !== "string")
|
|
6192
|
+
return null;
|
|
6193
|
+
const itemsJson = JSON.parse(itemsString);
|
|
6194
|
+
if (!Array.isArray(itemsJson)) {
|
|
6195
|
+
console.error("Block `items` property must be a json array");
|
|
6196
|
+
return null;
|
|
6197
|
+
}
|
|
6198
|
+
return itemsJson.map((i) => parseItem(i, definition)).filter(nonNullFilter2);
|
|
6199
|
+
}
|
|
6200
|
+
function parseAppearance(prosemirrorNode) {
|
|
6201
|
+
const appearance = {};
|
|
6202
|
+
const columns = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "columns");
|
|
6203
|
+
if (typeof columns === "number") {
|
|
6204
|
+
appearance.numberOfColumns = columns;
|
|
6205
|
+
}
|
|
6206
|
+
const backgroundColor = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "backgroundColor");
|
|
6207
|
+
if (typeof backgroundColor === "string") {
|
|
6208
|
+
const parsedColor = ColorValue.safeParse(JSON.parse(backgroundColor));
|
|
6209
|
+
if (parsedColor.success) {
|
|
6210
|
+
appearance.itemBackgroundColor = parsedColor.data;
|
|
6211
|
+
}
|
|
6212
|
+
}
|
|
6213
|
+
if (!Object.keys(appearance).length)
|
|
6214
|
+
return void 0;
|
|
6215
|
+
return appearance;
|
|
6216
|
+
}
|
|
6158
6217
|
function parseItem(rawItem, definition) {
|
|
6159
6218
|
const parsedItem = PageBlockItemV2.safeParse(rawItem);
|
|
6160
6219
|
if (!parsedItem.success) {
|
|
@@ -6240,7 +6299,7 @@ function parseProsemirrorBlockAttribute(prosemirrorNode, attributeName) {
|
|
|
6240
6299
|
return attributeValue;
|
|
6241
6300
|
}
|
|
6242
6301
|
function parseProsemirrorOptionalBlockAttribute(prosemirrorNode, attributeName) {
|
|
6243
|
-
return _nullishCoalesce(_optionalChain([prosemirrorNode, 'access',
|
|
6302
|
+
return _nullishCoalesce(_optionalChain([prosemirrorNode, 'access', _36 => _36.attrs, 'optionalAccess', _37 => _37[attributeName]]), () => ( void 0));
|
|
6244
6303
|
}
|
|
6245
6304
|
function nonNullFilter2(item) {
|
|
6246
6305
|
return item !== null;
|