@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.js CHANGED
@@ -859,7 +859,9 @@ var PageBlockV1 = PageBlockBaseV1.extend({
859
859
 
860
860
  // ../model/src/dsm/elements/data/documentation-block-v2.ts
861
861
 
862
- var PageBlockLinkType = _zod.z.enum(["Page", "PageHeading", "Group", "Url"]);
862
+ var PageBlockLinkType = _zod.z.enum(["DocumentationItem", "PageHeading", "Url"]);
863
+ var PageBlockImageType = _zod.z.enum(["Upload", "Asset", "FigmaFrame"]);
864
+ var PageBlockImageAlignment = _zod.z.enum(["Left", "Center", "Stretch"]);
863
865
  var PageBlockAppearanceV2 = _zod.z.object({
864
866
  itemBackgroundColor: ColorValue
865
867
  });
@@ -870,6 +872,11 @@ var PageBlockItemRichTextPropertyValue = _zod.z.object({
870
872
  value: PageBlockText,
871
873
  calloutType: PageBlockCalloutType.optional()
872
874
  });
875
+ var PageBlockItemEmbedPropertyValue = _zod.z.object({
876
+ value: _zod.z.string().optional(),
877
+ caption: _zod.z.string().optional(),
878
+ height: _zod.z.number().optional()
879
+ });
873
880
  var PageBlockItemMultiRichTextPropertyValue = _zod.z.object({
874
881
  value: PageBlockText.array()
875
882
  });
@@ -877,11 +884,26 @@ var PageBlockItemTextPropertyValue = _zod.z.object({
877
884
  value: _zod.z.string(),
878
885
  calloutType: PageBlockCalloutType.optional()
879
886
  });
887
+ var PageBlockItemImageReference = _zod.z.object({
888
+ type: PageBlockImageType,
889
+ url: _zod.z.string(),
890
+ assetId: _zod.z.string().optional(),
891
+ size: Size.optional(),
892
+ figmaFile: _zod.z.object({
893
+ sourceId: _zod.z.string(),
894
+ frameId: _zod.z.string()
895
+ }).optional()
896
+ });
897
+ var PageBlockItemImageValue = _zod.z.object({
898
+ alt: _zod.z.string().optional(),
899
+ caption: _zod.z.string().optional(),
900
+ alignment: PageBlockImageAlignment.optional(),
901
+ value: PageBlockItemImageReference.optional()
902
+ });
880
903
  var PageBlockLinkV2 = _zod.z.object({
881
904
  type: PageBlockLinkType,
882
- pageId: _zod.z.string().optional(),
905
+ documentationItemId: _zod.z.string().optional(),
883
906
  pageHeadingId: _zod.z.string().optional(),
884
- groupId: _zod.z.string().optional(),
885
907
  url: _zod.z.string().optional(),
886
908
  openInNewTab: _zod.z.boolean().optional()
887
909
  });
@@ -1837,7 +1859,8 @@ var PageBlockDefinitionPropertyType = _zod.z.enum([
1837
1859
  "CodeSandbox",
1838
1860
  "Table",
1839
1861
  "Divider",
1840
- "Storybook"
1862
+ "Storybook",
1863
+ "Color"
1841
1864
  ]);
1842
1865
  var PageBlockDefinitionRichTextPropertyStyle = _zod.z.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) => serializeItem(i, block, definition));
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: "default",
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 = _nullishCoalesce(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: "RichText",
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: "RichText",
4876
+ type: "Text",
4813
4877
  description: void 0,
4814
4878
  options: { textStyle: "Default", color: "NeutralFaded" },
4815
4879
  variantOptions: void 0
@@ -5603,9 +5667,61 @@ 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) {
5684
+ const id = parseProsemirrorBlockAttribute(prosemirrorNode, "id");
5685
+ const variantId = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "variantId");
5686
+ const calloutType = parseCalloutType(parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "type"));
5687
+ return {
5688
+ // TODO Artem: indent
5689
+ id,
5690
+ ...variantId && { variantId },
5691
+ data: {
5692
+ packageId: definition.id,
5693
+ indentLevel: 0,
5694
+ items: [
5695
+ {
5696
+ id,
5697
+ props: {
5698
+ [property.id]: {
5699
+ // Required
5700
+ value: parseRichText(_nullishCoalesce(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) {
5609
5725
  const id = parseProsemirrorBlockAttribute(prosemirrorNode, "id");
5610
5726
  const variantId = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "variantId");
5611
5727
  return {
@@ -5614,13 +5730,23 @@ function parseAsRichText(prosemirrorNode, definition, property) {
5614
5730
  data: {
5615
5731
  packageId: definition.id,
5616
5732
  indentLevel: 0,
5617
- variantId,
5733
+ ...variantId && { variantId },
5618
5734
  items: [
5619
5735
  {
5620
5736
  id,
5621
5737
  props: {
5622
5738
  [property.id]: {
5623
- value: parseRichText(_nullishCoalesce(prosemirrorNode.content, () => ( [])))
5739
+ // Required
5740
+ value: (_nullishCoalesce(prosemirrorNode.content, () => ( []))).map((listItem) => {
5741
+ if (listItem.type !== "listitem")
5742
+ return null;
5743
+ if (!_optionalChain([listItem, 'access', _10 => _10.content, 'optionalAccess', _11 => _11.length]))
5744
+ return parseRichText([]);
5745
+ const paragraph = listItem.content[0];
5746
+ if (paragraph.type !== "paragraph")
5747
+ return parseRichText([]);
5748
+ return parseRichText(_nullishCoalesce(paragraph.content, () => ( [])));
5749
+ }).filter(nonNullFilter2)
5624
5750
  }
5625
5751
  }
5626
5752
  }
@@ -5653,19 +5779,108 @@ function parseRichTextAttribute(mark) {
5653
5779
  case "code":
5654
5780
  return { type: "Code" };
5655
5781
  case "link":
5656
- const itemId = _optionalChain([mark, 'access', _10 => _10.attrs, 'optionalAccess', _11 => _11.itemId]);
5657
- const href = _optionalChain([mark, 'access', _12 => _12.attrs, 'optionalAccess', _13 => _13.href]);
5782
+ const itemId = _optionalChain([mark, 'access', _12 => _12.attrs, 'optionalAccess', _13 => _13.itemId]);
5783
+ const href = _optionalChain([mark, 'access', _14 => _14.attrs, 'optionalAccess', _15 => _15.href]);
5658
5784
  return {
5659
5785
  type: "Link",
5660
- openInNewWindow: _optionalChain([mark, 'access', _14 => _14.attrs, 'optionalAccess', _15 => _15.target]) !== "_self",
5786
+ openInNewWindow: _optionalChain([mark, 'access', _16 => _16.attrs, 'optionalAccess', _17 => _17.target]) !== "_self",
5661
5787
  documentationItemId: itemId,
5662
5788
  link: href
5663
5789
  };
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
- return null;
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);
@@ -5675,7 +5890,7 @@ function parseProsemirrorBlockAttribute(prosemirrorNode, attributeName) {
5675
5890
  return attributeValue;
5676
5891
  }
5677
5892
  function parseProsemirrorOptionalBlockAttribute(prosemirrorNode, attributeName) {
5678
- return _nullishCoalesce(_optionalChain([prosemirrorNode, 'access', _16 => _16.attrs, 'optionalAccess', _17 => _17[attributeName]]), () => ( void 0));
5893
+ return _nullishCoalesce(_optionalChain([prosemirrorNode, 'access', _18 => _18.attrs, 'optionalAccess', _19 => _19[attributeName]]), () => ( void 0));
5679
5894
  }
5680
5895
  function nonNullFilter2(item) {
5681
5896
  return item !== null;
@@ -5703,7 +5918,5 @@ function mapByUnique(items, keyFn) {
5703
5918
 
5704
5919
 
5705
5920
 
5706
-
5707
-
5708
- exports.BlockDefinitionUtils = BlockDefinitionUtils; exports.BlockParsingUtils = BlockParsingUtils; exports.DocumentationPageEditorModel = DocumentationPageEditorModel; exports.GetBlockDefinitionsResponse = GetBlockDefinitionsResponse; exports.PageBlockEditorModel = PageBlockEditorModel; exports.blockDefinitionForBlock = blockDefinitionForBlock; exports.blockToProsemirrorNode = blockToProsemirrorNode; exports.getMockPageBlockDefinitions = getMockPageBlockDefinitions; exports.pageToProsemirrorDoc = pageToProsemirrorDoc; exports.pageToYXmlFragment = pageToYXmlFragment; exports.pmSchema = pmSchema; exports.prosemirrorDocToPage = prosemirrorDocToPage; exports.prosemirrorNodeToBlock = prosemirrorNodeToBlock; exports.serializeAsCustomBlock = serializeAsCustomBlock; exports.serializeAsMultiRichTextBlock = serializeAsMultiRichTextBlock; exports.serializeAsRichTextBlock = serializeAsRichTextBlock; exports.yXmlFragmetToPage = yXmlFragmetToPage;
5921
+ exports.BlockDefinitionUtils = BlockDefinitionUtils; exports.BlockParsingUtils = BlockParsingUtils; exports.DocumentationPageEditorModel = DocumentationPageEditorModel; exports.GetBlockDefinitionsResponse = GetBlockDefinitionsResponse; exports.PageBlockEditorModel = PageBlockEditorModel; exports.blockDefinitionForBlock = blockDefinitionForBlock; exports.blockToProsemirrorNode = blockToProsemirrorNode; exports.getMockPageBlockDefinitions = getMockPageBlockDefinitions; exports.pageToProsemirrorDoc = pageToProsemirrorDoc; exports.pageToYXmlFragment = pageToYXmlFragment; exports.pmSchema = pmSchema; exports.prosemirrorDocToPage = prosemirrorDocToPage; exports.prosemirrorNodeToBlock = prosemirrorNodeToBlock; exports.serializeAsCustomBlock = serializeAsCustomBlock; exports.yXmlFragmetToPage = yXmlFragmetToPage;
5709
5922
  //# sourceMappingURL=index.js.map