@supernova-studio/client 0.1.0 → 0.2.0
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 +86 -100
- package/dist/index.d.ts +86 -100
- package/dist/index.js +257 -44
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +252 -39
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -3
- package/src/docs-editor/blocks-to-prosemirror.ts +88 -114
- package/src/docs-editor/mock.ts +2 -2
- package/src/docs-editor/prosemirror/types.ts +3 -7
- package/src/docs-editor/prosemirror-to-blocks.ts +226 -3
- package/src/docs-editor/utils.ts +14 -0
package/dist/index.mjs
CHANGED
|
@@ -859,7 +859,9 @@ var PageBlockV1 = PageBlockBaseV1.extend({
|
|
|
859
859
|
|
|
860
860
|
// ../model/src/dsm/elements/data/documentation-block-v2.ts
|
|
861
861
|
import { z as z33 } from "zod";
|
|
862
|
-
var PageBlockLinkType = z33.enum(["
|
|
862
|
+
var PageBlockLinkType = z33.enum(["DocumentationItem", "PageHeading", "Url"]);
|
|
863
|
+
var PageBlockImageType = z33.enum(["Upload", "Asset", "FigmaFrame"]);
|
|
864
|
+
var PageBlockImageAlignment = z33.enum(["Left", "Center", "Stretch"]);
|
|
863
865
|
var PageBlockAppearanceV2 = z33.object({
|
|
864
866
|
itemBackgroundColor: ColorValue
|
|
865
867
|
});
|
|
@@ -870,6 +872,11 @@ var PageBlockItemRichTextPropertyValue = z33.object({
|
|
|
870
872
|
value: PageBlockText,
|
|
871
873
|
calloutType: PageBlockCalloutType.optional()
|
|
872
874
|
});
|
|
875
|
+
var PageBlockItemEmbedPropertyValue = z33.object({
|
|
876
|
+
value: z33.string().optional(),
|
|
877
|
+
caption: z33.string().optional(),
|
|
878
|
+
height: z33.number().optional()
|
|
879
|
+
});
|
|
873
880
|
var PageBlockItemMultiRichTextPropertyValue = z33.object({
|
|
874
881
|
value: PageBlockText.array()
|
|
875
882
|
});
|
|
@@ -877,11 +884,26 @@ var PageBlockItemTextPropertyValue = z33.object({
|
|
|
877
884
|
value: z33.string(),
|
|
878
885
|
calloutType: PageBlockCalloutType.optional()
|
|
879
886
|
});
|
|
887
|
+
var PageBlockItemImageReference = z33.object({
|
|
888
|
+
type: PageBlockImageType,
|
|
889
|
+
url: z33.string(),
|
|
890
|
+
assetId: z33.string().optional(),
|
|
891
|
+
size: Size.optional(),
|
|
892
|
+
figmaFile: z33.object({
|
|
893
|
+
sourceId: z33.string(),
|
|
894
|
+
frameId: z33.string()
|
|
895
|
+
}).optional()
|
|
896
|
+
});
|
|
897
|
+
var PageBlockItemImageValue = z33.object({
|
|
898
|
+
alt: z33.string().optional(),
|
|
899
|
+
caption: z33.string().optional(),
|
|
900
|
+
alignment: PageBlockImageAlignment.optional(),
|
|
901
|
+
value: PageBlockItemImageReference.optional()
|
|
902
|
+
});
|
|
880
903
|
var PageBlockLinkV2 = z33.object({
|
|
881
904
|
type: PageBlockLinkType,
|
|
882
|
-
|
|
905
|
+
documentationItemId: z33.string().optional(),
|
|
883
906
|
pageHeadingId: z33.string().optional(),
|
|
884
|
-
groupId: z33.string().optional(),
|
|
885
907
|
url: z33.string().optional(),
|
|
886
908
|
openInNewTab: z33.boolean().optional()
|
|
887
909
|
});
|
|
@@ -1837,7 +1859,8 @@ var PageBlockDefinitionPropertyType = z82.enum([
|
|
|
1837
1859
|
"CodeSandbox",
|
|
1838
1860
|
"Table",
|
|
1839
1861
|
"Divider",
|
|
1840
|
-
"Storybook"
|
|
1862
|
+
"Storybook",
|
|
1863
|
+
"Color"
|
|
1841
1864
|
]);
|
|
1842
1865
|
var PageBlockDefinitionRichTextPropertyStyle = z82.enum([
|
|
1843
1866
|
"Title1",
|
|
@@ -3879,6 +3902,11 @@ var BlockParsingUtils = {
|
|
|
3879
3902
|
const richText = PageBlockItemMultiRichTextPropertyValue.parse(objectValue);
|
|
3880
3903
|
return richText;
|
|
3881
3904
|
},
|
|
3905
|
+
embedPropertyValue(item, propertyKey) {
|
|
3906
|
+
const objectValue = this.objectPropertyValue(item, propertyKey);
|
|
3907
|
+
const embed = PageBlockItemEmbedPropertyValue.parse(objectValue);
|
|
3908
|
+
return embed;
|
|
3909
|
+
},
|
|
3882
3910
|
objectPropertyValue(item, propertyKey) {
|
|
3883
3911
|
const value = this.propertyValueOrThrow(item, propertyKey);
|
|
3884
3912
|
if (typeof value !== "object") {
|
|
@@ -3912,6 +3940,12 @@ var BlockDefinitionUtils = {
|
|
|
3912
3940
|
return property;
|
|
3913
3941
|
return void 0;
|
|
3914
3942
|
},
|
|
3943
|
+
firstEmbedProperty(definition) {
|
|
3944
|
+
const property = definition.item.properties.find((p) => p.type === "EmbedURL");
|
|
3945
|
+
if (property)
|
|
3946
|
+
return property;
|
|
3947
|
+
return void 0;
|
|
3948
|
+
},
|
|
3915
3949
|
richTextProperty(definition, propertyKey) {
|
|
3916
3950
|
return this.property(definition, propertyKey, "RichText");
|
|
3917
3951
|
},
|
|
@@ -3967,6 +4001,24 @@ function blockToProsemirrorNode(block, definition) {
|
|
|
3967
4001
|
property: multiRichTextProperty
|
|
3968
4002
|
});
|
|
3969
4003
|
}
|
|
4004
|
+
const embedProperty = BlockDefinitionUtils.firstEmbedProperty(definition);
|
|
4005
|
+
const embedType = serializeEmbedType(block.data.packageId);
|
|
4006
|
+
if (embedProperty && embedType) {
|
|
4007
|
+
return serializeAsEmbed(
|
|
4008
|
+
{
|
|
4009
|
+
block,
|
|
4010
|
+
definition,
|
|
4011
|
+
property: embedProperty
|
|
4012
|
+
},
|
|
4013
|
+
embedType
|
|
4014
|
+
);
|
|
4015
|
+
}
|
|
4016
|
+
if (block.data.packageId === "io.supernova.block.divider") {
|
|
4017
|
+
return serializeAsDivider({
|
|
4018
|
+
block,
|
|
4019
|
+
definition
|
|
4020
|
+
});
|
|
4021
|
+
}
|
|
3970
4022
|
return serializeAsCustomBlock(block, definition);
|
|
3971
4023
|
}
|
|
3972
4024
|
function serializeAsRichTextBlock(input) {
|
|
@@ -4079,6 +4131,38 @@ function serializeAsListItem(text) {
|
|
|
4079
4131
|
]
|
|
4080
4132
|
};
|
|
4081
4133
|
}
|
|
4134
|
+
function serializeAsEmbed(input, embedType) {
|
|
4135
|
+
const { block, definition, property: embedProperty } = input;
|
|
4136
|
+
const blockItem = BlockParsingUtils.singleBlockItem(block);
|
|
4137
|
+
const embedValue = BlockParsingUtils.embedPropertyValue(blockItem, embedProperty.id);
|
|
4138
|
+
return {
|
|
4139
|
+
type: "embed",
|
|
4140
|
+
attrs: {
|
|
4141
|
+
...serializeBlockNodeAttributes(input),
|
|
4142
|
+
type: embedType,
|
|
4143
|
+
url: embedValue.value,
|
|
4144
|
+
height: embedValue.height,
|
|
4145
|
+
caption: embedValue.caption
|
|
4146
|
+
}
|
|
4147
|
+
};
|
|
4148
|
+
}
|
|
4149
|
+
function serializeEmbedType(blockDefinitionId) {
|
|
4150
|
+
switch (blockDefinitionId) {
|
|
4151
|
+
case "io.supernova.block.embed":
|
|
4152
|
+
return "generic";
|
|
4153
|
+
case "io.supernova.block.embed-youtube":
|
|
4154
|
+
return "youtube";
|
|
4155
|
+
case "io.supernova.block.embed-figma":
|
|
4156
|
+
return "figma";
|
|
4157
|
+
}
|
|
4158
|
+
return void 0;
|
|
4159
|
+
}
|
|
4160
|
+
function serializeAsDivider(input) {
|
|
4161
|
+
return {
|
|
4162
|
+
type: "horizontalrule",
|
|
4163
|
+
attrs: serializeBlockNodeAttributes(input)
|
|
4164
|
+
};
|
|
4165
|
+
}
|
|
4082
4166
|
function serializeBlockNodeAttributes(input) {
|
|
4083
4167
|
const { block } = input;
|
|
4084
4168
|
return {
|
|
@@ -4171,43 +4255,23 @@ function serializeTextSpanAttribute(spanAttribute) {
|
|
|
4171
4255
|
}
|
|
4172
4256
|
}
|
|
4173
4257
|
function serializeAsCustomBlock(block, definition) {
|
|
4174
|
-
const items = block.data.items.map((i) =>
|
|
4258
|
+
const items = block.data.items.map((i) => {
|
|
4259
|
+
return {
|
|
4260
|
+
id: i.id,
|
|
4261
|
+
props: i.props,
|
|
4262
|
+
linksTo: i.linksTo
|
|
4263
|
+
};
|
|
4264
|
+
});
|
|
4175
4265
|
return {
|
|
4176
4266
|
type: "blockNode",
|
|
4177
4267
|
attrs: {
|
|
4178
4268
|
id: block.id,
|
|
4179
4269
|
definitionId: block.data.packageId,
|
|
4180
|
-
variantId:
|
|
4181
|
-
columns: 1,
|
|
4270
|
+
variantId: block.data.variantId,
|
|
4182
4271
|
items: JSON.stringify(items)
|
|
4183
|
-
// TODO Docs: variant, columns
|
|
4184
4272
|
}
|
|
4185
4273
|
};
|
|
4186
4274
|
}
|
|
4187
|
-
function serializeItem(item, block, definition) {
|
|
4188
|
-
const result = {
|
|
4189
|
-
properties: []
|
|
4190
|
-
};
|
|
4191
|
-
for (const property of definition.item.properties) {
|
|
4192
|
-
const serializedValue = serializePropertyValue(item, property);
|
|
4193
|
-
serializedValue && result.properties.push(serializedValue);
|
|
4194
|
-
}
|
|
4195
|
-
return result;
|
|
4196
|
-
}
|
|
4197
|
-
function serializePropertyValue(item, property) {
|
|
4198
|
-
const value = item.props[property.id] ?? void 0;
|
|
4199
|
-
if (!value) {
|
|
4200
|
-
return void 0;
|
|
4201
|
-
}
|
|
4202
|
-
const result = {
|
|
4203
|
-
id: property.id,
|
|
4204
|
-
data: {}
|
|
4205
|
-
};
|
|
4206
|
-
if (typeof value === "string") {
|
|
4207
|
-
result.data.value = value;
|
|
4208
|
-
}
|
|
4209
|
-
return result;
|
|
4210
|
-
}
|
|
4211
4275
|
function nonNullFilter(item) {
|
|
4212
4276
|
return !!item;
|
|
4213
4277
|
}
|
|
@@ -4801,7 +4865,7 @@ var blocks = [
|
|
|
4801
4865
|
{
|
|
4802
4866
|
id: "block.links.property.title",
|
|
4803
4867
|
name: "Title",
|
|
4804
|
-
type: "
|
|
4868
|
+
type: "Text",
|
|
4805
4869
|
description: void 0,
|
|
4806
4870
|
options: { textStyle: "Title5" },
|
|
4807
4871
|
variantOptions: void 0
|
|
@@ -4809,7 +4873,7 @@ var blocks = [
|
|
|
4809
4873
|
{
|
|
4810
4874
|
id: "block.links.property.description",
|
|
4811
4875
|
name: "Short description",
|
|
4812
|
-
type: "
|
|
4876
|
+
type: "Text",
|
|
4813
4877
|
description: void 0,
|
|
4814
4878
|
options: { textStyle: "Default", color: "NeutralFaded" },
|
|
4815
4879
|
variantOptions: void 0
|
|
@@ -5603,24 +5667,86 @@ function prosemirrorNodeToBlock(prosemirrorNode, definition) {
|
|
|
5603
5667
|
if (richTextProperty) {
|
|
5604
5668
|
return parseAsRichText(prosemirrorNode, definition, richTextProperty);
|
|
5605
5669
|
}
|
|
5670
|
+
const multiRichTextProperty = BlockDefinitionUtils.firstMultiRichTextProperty(definition);
|
|
5671
|
+
if (multiRichTextProperty) {
|
|
5672
|
+
return parseAsMultiRichText(prosemirrorNode, definition, multiRichTextProperty);
|
|
5673
|
+
}
|
|
5674
|
+
const embedProperty = BlockDefinitionUtils.firstEmbedProperty(definition);
|
|
5675
|
+
if (prosemirrorNode.type === "embed" && embedProperty) {
|
|
5676
|
+
return parseAsEmbed(prosemirrorNode, definition, embedProperty);
|
|
5677
|
+
}
|
|
5678
|
+
if (definition.id === "io.supernova.block.divider") {
|
|
5679
|
+
return parseAsDivider(prosemirrorNode, definition);
|
|
5680
|
+
}
|
|
5606
5681
|
return parseAsCustomBlock(prosemirrorNode, definition);
|
|
5607
5682
|
}
|
|
5608
5683
|
function parseAsRichText(prosemirrorNode, definition, property) {
|
|
5609
5684
|
const id = parseProsemirrorBlockAttribute(prosemirrorNode, "id");
|
|
5610
5685
|
const variantId = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "variantId");
|
|
5686
|
+
const calloutType = parseCalloutType(parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "type"));
|
|
5611
5687
|
return {
|
|
5612
5688
|
// TODO Artem: indent
|
|
5613
5689
|
id,
|
|
5690
|
+
...variantId && { variantId },
|
|
5614
5691
|
data: {
|
|
5615
5692
|
packageId: definition.id,
|
|
5616
5693
|
indentLevel: 0,
|
|
5617
|
-
variantId,
|
|
5618
5694
|
items: [
|
|
5619
5695
|
{
|
|
5620
5696
|
id,
|
|
5621
5697
|
props: {
|
|
5622
5698
|
[property.id]: {
|
|
5623
|
-
|
|
5699
|
+
// Required
|
|
5700
|
+
value: parseRichText(prosemirrorNode.content ?? []),
|
|
5701
|
+
// Optional
|
|
5702
|
+
...calloutType && { calloutType }
|
|
5703
|
+
}
|
|
5704
|
+
}
|
|
5705
|
+
}
|
|
5706
|
+
]
|
|
5707
|
+
}
|
|
5708
|
+
};
|
|
5709
|
+
}
|
|
5710
|
+
function parseCalloutType(prosemirrorCalloutType) {
|
|
5711
|
+
if (!prosemirrorCalloutType)
|
|
5712
|
+
return void 0;
|
|
5713
|
+
switch (prosemirrorCalloutType) {
|
|
5714
|
+
case "error":
|
|
5715
|
+
return "Error";
|
|
5716
|
+
case "neutral":
|
|
5717
|
+
return "Info";
|
|
5718
|
+
case "success":
|
|
5719
|
+
return "Success";
|
|
5720
|
+
case "warning":
|
|
5721
|
+
return "Warning";
|
|
5722
|
+
}
|
|
5723
|
+
}
|
|
5724
|
+
function parseAsMultiRichText(prosemirrorNode, definition, property) {
|
|
5725
|
+
const id = parseProsemirrorBlockAttribute(prosemirrorNode, "id");
|
|
5726
|
+
const variantId = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "variantId");
|
|
5727
|
+
return {
|
|
5728
|
+
// TODO Artem: indent
|
|
5729
|
+
id,
|
|
5730
|
+
data: {
|
|
5731
|
+
packageId: definition.id,
|
|
5732
|
+
indentLevel: 0,
|
|
5733
|
+
...variantId && { variantId },
|
|
5734
|
+
items: [
|
|
5735
|
+
{
|
|
5736
|
+
id,
|
|
5737
|
+
props: {
|
|
5738
|
+
[property.id]: {
|
|
5739
|
+
// Required
|
|
5740
|
+
value: (prosemirrorNode.content ?? []).map((listItem) => {
|
|
5741
|
+
if (listItem.type !== "listitem")
|
|
5742
|
+
return null;
|
|
5743
|
+
if (!listItem.content?.length)
|
|
5744
|
+
return parseRichText([]);
|
|
5745
|
+
const paragraph = listItem.content[0];
|
|
5746
|
+
if (paragraph.type !== "paragraph")
|
|
5747
|
+
return parseRichText([]);
|
|
5748
|
+
return parseRichText(paragraph.content ?? []);
|
|
5749
|
+
}).filter(nonNullFilter2)
|
|
5624
5750
|
}
|
|
5625
5751
|
}
|
|
5626
5752
|
}
|
|
@@ -5664,8 +5790,97 @@ function parseRichTextAttribute(mark) {
|
|
|
5664
5790
|
}
|
|
5665
5791
|
return null;
|
|
5666
5792
|
}
|
|
5793
|
+
function parseAsEmbed(prosemirrorNode, definition, property) {
|
|
5794
|
+
const id = parseProsemirrorBlockAttribute(prosemirrorNode, "id");
|
|
5795
|
+
const variantId = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "variantId");
|
|
5796
|
+
const url = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "url");
|
|
5797
|
+
const caption = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "caption");
|
|
5798
|
+
const height = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "height");
|
|
5799
|
+
return {
|
|
5800
|
+
id,
|
|
5801
|
+
data: {
|
|
5802
|
+
packageId: definition.id,
|
|
5803
|
+
indentLevel: 0,
|
|
5804
|
+
...variantId && { variantId },
|
|
5805
|
+
items: [
|
|
5806
|
+
{
|
|
5807
|
+
id,
|
|
5808
|
+
props: {
|
|
5809
|
+
[property.id]: {
|
|
5810
|
+
value: url,
|
|
5811
|
+
caption,
|
|
5812
|
+
height
|
|
5813
|
+
}
|
|
5814
|
+
}
|
|
5815
|
+
}
|
|
5816
|
+
]
|
|
5817
|
+
}
|
|
5818
|
+
};
|
|
5819
|
+
}
|
|
5820
|
+
function parseAsDivider(prosemirrorNode, definition) {
|
|
5821
|
+
const id = parseProsemirrorBlockAttribute(prosemirrorNode, "id");
|
|
5822
|
+
const variantId = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "variantId");
|
|
5823
|
+
return {
|
|
5824
|
+
id,
|
|
5825
|
+
data: {
|
|
5826
|
+
packageId: definition.id,
|
|
5827
|
+
indentLevel: 0,
|
|
5828
|
+
...variantId && { variantId },
|
|
5829
|
+
items: [{ id, props: {} }]
|
|
5830
|
+
}
|
|
5831
|
+
};
|
|
5832
|
+
}
|
|
5667
5833
|
function parseAsCustomBlock(prosemirrorNode, definition) {
|
|
5668
|
-
|
|
5834
|
+
const id = parseProsemirrorBlockAttribute(prosemirrorNode, "id");
|
|
5835
|
+
const variantId = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "variantId");
|
|
5836
|
+
const itemsString = parseProsemirrorBlockAttribute(prosemirrorNode, "items");
|
|
5837
|
+
const itemsJson = JSON.parse(itemsString);
|
|
5838
|
+
if (!Array.isArray(itemsJson)) {
|
|
5839
|
+
console.error("Block `items` property must be a json array");
|
|
5840
|
+
return null;
|
|
5841
|
+
}
|
|
5842
|
+
const parsedItems = itemsJson.map((i) => parseItem(i, definition));
|
|
5843
|
+
return {
|
|
5844
|
+
id,
|
|
5845
|
+
data: {
|
|
5846
|
+
packageId: definition.id,
|
|
5847
|
+
indentLevel: 0,
|
|
5848
|
+
...variantId && { variantId },
|
|
5849
|
+
items: parsedItems
|
|
5850
|
+
}
|
|
5851
|
+
};
|
|
5852
|
+
}
|
|
5853
|
+
function parseItem(rawItem, definition) {
|
|
5854
|
+
const parsedItem = PageBlockItemV2.safeParse(rawItem);
|
|
5855
|
+
if (!parsedItem.success) {
|
|
5856
|
+
return null;
|
|
5857
|
+
}
|
|
5858
|
+
const sanitizedProps = {};
|
|
5859
|
+
for (const property of definition.item.properties) {
|
|
5860
|
+
const value = parsedItem.data.props[property.id];
|
|
5861
|
+
if (!value) {
|
|
5862
|
+
return null;
|
|
5863
|
+
}
|
|
5864
|
+
switch (property.type) {
|
|
5865
|
+
case "Text":
|
|
5866
|
+
PageBlockItemTextPropertyValue.parse(value);
|
|
5867
|
+
break;
|
|
5868
|
+
case "EmbedURL":
|
|
5869
|
+
PageBlockItemEmbedPropertyValue.parse(value);
|
|
5870
|
+
break;
|
|
5871
|
+
case "Image":
|
|
5872
|
+
PageBlockItemImageValue.parse(value);
|
|
5873
|
+
break;
|
|
5874
|
+
default:
|
|
5875
|
+
return null;
|
|
5876
|
+
}
|
|
5877
|
+
sanitizedProps[property.id] = value;
|
|
5878
|
+
}
|
|
5879
|
+
return {
|
|
5880
|
+
id: parsedItem.data.id,
|
|
5881
|
+
linksTo: parsedItem.data.linksTo,
|
|
5882
|
+
props: sanitizedProps
|
|
5883
|
+
};
|
|
5669
5884
|
}
|
|
5670
5885
|
function parseProsemirrorBlockAttribute(prosemirrorNode, attributeName) {
|
|
5671
5886
|
const attributeValue = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, attributeName);
|
|
@@ -5702,8 +5917,6 @@ export {
|
|
|
5702
5917
|
prosemirrorDocToPage,
|
|
5703
5918
|
prosemirrorNodeToBlock,
|
|
5704
5919
|
serializeAsCustomBlock,
|
|
5705
|
-
serializeAsMultiRichTextBlock,
|
|
5706
|
-
serializeAsRichTextBlock,
|
|
5707
5920
|
yXmlFragmetToPage
|
|
5708
5921
|
};
|
|
5709
5922
|
//# sourceMappingURL=index.mjs.map
|