@supernova-studio/client 0.0.15 → 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,26 +859,58 @@ 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
  });
866
- var PageBlockItemPropertyValue = _zod.z.object({
867
- value: _zod.z.any(),
868
+ var PageBlockItemUntypedPropertyValue = _zod.z.object({
869
+ value: _zod.z.any()
870
+ }).and(_zod.z.record(_zod.z.any()));
871
+ var PageBlockItemRichTextPropertyValue = _zod.z.object({
872
+ value: PageBlockText,
868
873
  calloutType: PageBlockCalloutType.optional()
869
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
+ });
880
+ var PageBlockItemMultiRichTextPropertyValue = _zod.z.object({
881
+ value: PageBlockText.array()
882
+ });
883
+ var PageBlockItemTextPropertyValue = _zod.z.object({
884
+ value: _zod.z.string(),
885
+ calloutType: PageBlockCalloutType.optional()
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
+ });
870
903
  var PageBlockLinkV2 = _zod.z.object({
871
904
  type: PageBlockLinkType,
872
- pageId: _zod.z.string().optional(),
905
+ documentationItemId: _zod.z.string().optional(),
873
906
  pageHeadingId: _zod.z.string().optional(),
874
- groupId: _zod.z.string().optional(),
875
907
  url: _zod.z.string().optional(),
876
908
  openInNewTab: _zod.z.boolean().optional()
877
909
  });
878
910
  var PageBlockItemV2 = _zod.z.object({
879
911
  id: _zod.z.string(),
880
912
  linksTo: PageBlockLinkV2.optional(),
881
- props: _zod.z.record(PageBlockItemPropertyValue)
913
+ props: _zod.z.record(PageBlockItemUntypedPropertyValue)
882
914
  });
883
915
  var PageBlockDataV2 = _zod.z.object({
884
916
  packageId: _zod.z.string(),
@@ -1806,6 +1838,7 @@ var PageBlockDefinitionVariant = _zod.z.object({
1806
1838
  // ../model/src/dsm/documentation/block-definitions/item.ts
1807
1839
  var PageBlockDefinitionPropertyType = _zod.z.enum([
1808
1840
  "RichText",
1841
+ "MultiRichText",
1809
1842
  "Text",
1810
1843
  "Boolean",
1811
1844
  "Number",
@@ -1826,7 +1859,8 @@ var PageBlockDefinitionPropertyType = _zod.z.enum([
1826
1859
  "CodeSandbox",
1827
1860
  "Table",
1828
1861
  "Divider",
1829
- "Storybook"
1862
+ "Storybook",
1863
+ "Color"
1830
1864
  ]);
1831
1865
  var PageBlockDefinitionRichTextPropertyStyle = _zod.z.enum([
1832
1866
  "Title1",
@@ -1836,10 +1870,9 @@ var PageBlockDefinitionRichTextPropertyStyle = _zod.z.enum([
1836
1870
  "Title5",
1837
1871
  "Quote",
1838
1872
  "Callout",
1839
- "OL",
1840
- "UL",
1841
1873
  "Default"
1842
1874
  ]);
1875
+ var PageBlockDefinitionMultiRichTextPropertyStyle = _zod.z.enum(["OL", "UL", "Default"]);
1843
1876
  var PageBlockDefinitionTextPropertyStyle = _zod.z.enum([
1844
1877
  "Title1",
1845
1878
  "Title2",
@@ -1863,6 +1896,7 @@ var PageBlockDefinitionSingleSelectPropertyStyle = _zod.z.enum([
1863
1896
  var PageBlockDefinitionMultiSelectPropertyStyle = _zod.z.enum(["SegmentedControl", "Select", "Checkbox"]);
1864
1897
  var PageBlockDefinitionPropertyOptions = _zod.z.object({
1865
1898
  richTextStyle: PageBlockDefinitionRichTextPropertyStyle.optional(),
1899
+ multiRichTextStyle: PageBlockDefinitionMultiRichTextPropertyStyle.optional(),
1866
1900
  textStyle: PageBlockDefinitionTextPropertyStyle.optional(),
1867
1901
  placeholder: _zod.z.string().optional()
1868
1902
  }).and(_zod.z.record(_zod.z.any()));
@@ -3860,24 +3894,31 @@ var BlockParsingUtils = {
3860
3894
  },
3861
3895
  richTextPropertyValue(item, propertyKey) {
3862
3896
  const objectValue = this.objectPropertyValue(item, propertyKey);
3863
- const richText = PageBlockText.parse(objectValue.value);
3897
+ const richText = PageBlockItemRichTextPropertyValue.parse(objectValue);
3898
+ return richText;
3899
+ },
3900
+ multiRichTextPropertyValue(item, propertyKey) {
3901
+ const objectValue = this.objectPropertyValue(item, propertyKey);
3902
+ const richText = PageBlockItemMultiRichTextPropertyValue.parse(objectValue);
3864
3903
  return richText;
3865
3904
  },
3905
+ embedPropertyValue(item, propertyKey) {
3906
+ const objectValue = this.objectPropertyValue(item, propertyKey);
3907
+ const embed = PageBlockItemEmbedPropertyValue.parse(objectValue);
3908
+ return embed;
3909
+ },
3866
3910
  objectPropertyValue(item, propertyKey) {
3867
- const value = this.propertyValue(item, propertyKey);
3911
+ const value = this.propertyValueOrThrow(item, propertyKey);
3868
3912
  if (typeof value !== "object") {
3869
3913
  throw new Error(`Value for property ${propertyKey} is expected to be an object, but instead is ${typeof value}`);
3870
3914
  }
3871
3915
  return value;
3872
3916
  },
3873
- propertyValue(item, propertyKey) {
3874
- const value = this.safePropertyValue(item, propertyKey);
3917
+ propertyValueOrThrow(item, propertyKey) {
3918
+ const value = item.props[propertyKey];
3875
3919
  if (!value)
3876
3920
  throw new Error(`Property ${propertyKey} is not defined on block item`);
3877
3921
  return value;
3878
- },
3879
- safePropertyValue(item, propertyKey) {
3880
- return _nullishCoalesce(item.props[propertyKey], () => ( void 0));
3881
3922
  }
3882
3923
  };
3883
3924
  var BlockDefinitionUtils = {
@@ -3887,12 +3928,24 @@ var BlockDefinitionUtils = {
3887
3928
  return property;
3888
3929
  return void 0;
3889
3930
  },
3931
+ firstMultiRichTextProperty(definition) {
3932
+ const property = definition.item.properties.find((p) => p.type === "MultiRichText");
3933
+ if (property)
3934
+ return property;
3935
+ return void 0;
3936
+ },
3890
3937
  firstTableProperty(definition) {
3891
3938
  const property = definition.item.properties.find((p) => p.type === "RichText");
3892
3939
  if (property)
3893
3940
  return property;
3894
3941
  return void 0;
3895
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
+ },
3896
3949
  richTextProperty(definition, propertyKey) {
3897
3950
  return this.property(definition, propertyKey, "RichText");
3898
3951
  },
@@ -3937,13 +3990,39 @@ function blockToProsemirrorNode(block, definition) {
3937
3990
  return serializeAsRichTextBlock({
3938
3991
  block,
3939
3992
  definition,
3940
- richTextProperty
3993
+ property: richTextProperty
3994
+ });
3995
+ }
3996
+ const multiRichTextProperty = BlockDefinitionUtils.firstMultiRichTextProperty(definition);
3997
+ if (multiRichTextProperty) {
3998
+ return serializeAsMultiRichTextBlock({
3999
+ block,
4000
+ definition,
4001
+ property: multiRichTextProperty
4002
+ });
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
3941
4020
  });
3942
4021
  }
3943
4022
  return serializeAsCustomBlock(block, definition);
3944
4023
  }
3945
4024
  function serializeAsRichTextBlock(input) {
3946
- const { block, definition, richTextProperty } = input;
4025
+ const { block, definition, property: richTextProperty } = input;
3947
4026
  const blockItem = BlockParsingUtils.singleBlockItem(block);
3948
4027
  const textPropertyValue = BlockParsingUtils.richTextPropertyValue(blockItem, richTextProperty.id);
3949
4028
  const enrichedInput = { ...input, richTextPropertyValue: textPropertyValue };
@@ -3961,16 +4040,13 @@ function serializeAsRichTextBlock(input) {
3961
4040
  case "Title4":
3962
4041
  case "Title5":
3963
4042
  return serializeAsHeading(enrichedInput);
3964
- case "OL":
3965
- case "UL":
3966
- throw new Error(`Not allowed!`);
3967
4043
  }
3968
4044
  }
3969
4045
  function serializeAsParagraph(input) {
3970
4046
  return {
3971
4047
  type: "paragraph",
3972
4048
  attrs: serializeBlockNodeAttributes(input),
3973
- content: serializeRichText(input.richTextPropertyValue)
4049
+ content: serializeRichText(input.richTextPropertyValue.value)
3974
4050
  };
3975
4051
  }
3976
4052
  function serializeAsHeading(input) {
@@ -3978,27 +4054,113 @@ function serializeAsHeading(input) {
3978
4054
  type: "heading",
3979
4055
  attrs: {
3980
4056
  ...serializeBlockNodeAttributes(input),
3981
- level: richTextHeadingLevel(input.richTextProperty)
4057
+ level: richTextHeadingLevel(input.property)
3982
4058
  },
3983
- content: serializeRichText(input.richTextPropertyValue)
4059
+ content: serializeRichText(input.richTextPropertyValue.value)
3984
4060
  };
3985
4061
  }
3986
4062
  function serializeAsBlockquote(input) {
3987
4063
  return {
3988
4064
  type: "blockquote",
3989
4065
  attrs: serializeBlockNodeAttributes(input),
3990
- content: serializeRichText(input.richTextPropertyValue)
4066
+ content: serializeRichText(input.richTextPropertyValue.value)
3991
4067
  };
3992
4068
  }
3993
4069
  function serializeAsCallout(input) {
4070
+ const calloutType = _nullishCoalesce(input.richTextPropertyValue.calloutType, () => ( "Info"));
3994
4071
  return {
3995
4072
  type: "callout",
3996
4073
  attrs: {
3997
4074
  ...serializeBlockNodeAttributes(input),
3998
- // TODO Docs: type
3999
- type: "neutral"
4075
+ type: serializeCalloutType(calloutType)
4076
+ },
4077
+ content: serializeRichText(input.richTextPropertyValue.value)
4078
+ };
4079
+ }
4080
+ function serializeAsMultiRichTextBlock(input) {
4081
+ const { block, definition, property: richTextProperty } = input;
4082
+ const blockItem = BlockParsingUtils.singleBlockItem(block);
4083
+ const textPropertyValue = BlockParsingUtils.multiRichTextPropertyValue(blockItem, richTextProperty.id);
4084
+ const enrichedInput = { ...input, multiRichTextPropertyValue: textPropertyValue };
4085
+ const style = _nullishCoalesce(_optionalChain([richTextProperty, 'access', _4 => _4.options, 'optionalAccess', _5 => _5.multiRichTextStyle]), () => ( "Default"));
4086
+ switch (style) {
4087
+ case "Default":
4088
+ return serializeAsMultiParagraph(enrichedInput);
4089
+ case "OL":
4090
+ return serializeAsOrderedList(enrichedInput);
4091
+ case "UL":
4092
+ return serializeAsUnorderedList(enrichedInput);
4093
+ }
4094
+ }
4095
+ function serializeAsMultiParagraph(input) {
4096
+ return {
4097
+ type: "bulletlist",
4098
+ attrs: {
4099
+ ...serializeBlockNodeAttributes(input)
4100
+ },
4101
+ content: input.multiRichTextPropertyValue.value.map(serializeAsListItem)
4102
+ };
4103
+ }
4104
+ function serializeAsOrderedList(input) {
4105
+ return {
4106
+ type: "orderedlist",
4107
+ attrs: {
4108
+ ...serializeBlockNodeAttributes(input),
4109
+ start: "1"
4000
4110
  },
4001
- content: serializeRichText(input.richTextPropertyValue)
4111
+ content: input.multiRichTextPropertyValue.value.map(serializeAsListItem)
4112
+ };
4113
+ }
4114
+ function serializeAsUnorderedList(input) {
4115
+ return {
4116
+ type: "bulletlist",
4117
+ attrs: {
4118
+ ...serializeBlockNodeAttributes(input)
4119
+ },
4120
+ content: input.multiRichTextPropertyValue.value.map(serializeAsListItem)
4121
+ };
4122
+ }
4123
+ function serializeAsListItem(text) {
4124
+ return {
4125
+ type: "listitem",
4126
+ content: [
4127
+ {
4128
+ type: "paragraph",
4129
+ content: serializeRichText(text)
4130
+ }
4131
+ ]
4132
+ };
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)
4002
4164
  };
4003
4165
  }
4004
4166
  function serializeBlockNodeAttributes(input) {
@@ -4006,11 +4168,11 @@ function serializeBlockNodeAttributes(input) {
4006
4168
  return {
4007
4169
  id: block.id,
4008
4170
  definitionId: block.data.packageId,
4009
- ...input.block.data.variantId && { variantId: input.block.data.variantId }
4171
+ ...block.data.variantId && { variantId: block.data.variantId }
4010
4172
  };
4011
4173
  }
4012
4174
  function richTextHeadingLevel(property) {
4013
- const style = _optionalChain([property, 'access', _4 => _4.options, 'optionalAccess', _5 => _5.style]);
4175
+ const style = _optionalChain([property, 'access', _6 => _6.options, 'optionalAccess', _7 => _7.richTextStyle]);
4014
4176
  if (!style)
4015
4177
  return void 0;
4016
4178
  switch (style) {
@@ -4024,14 +4186,24 @@ function richTextHeadingLevel(property) {
4024
4186
  return 4;
4025
4187
  case "Title5":
4026
4188
  return 5;
4027
- case "OL":
4028
- case "UL":
4029
4189
  case "Callout":
4030
4190
  case "Default":
4031
4191
  case "Quote":
4032
4192
  return void 0;
4033
4193
  }
4034
4194
  }
4195
+ function serializeCalloutType(calloutType) {
4196
+ switch (calloutType) {
4197
+ case "Error":
4198
+ return "error";
4199
+ case "Info":
4200
+ return "neutral";
4201
+ case "Success":
4202
+ return "success";
4203
+ case "Warning":
4204
+ return "warning";
4205
+ }
4206
+ }
4035
4207
  function serializeRichText(richText) {
4036
4208
  return richText.spans.map(serializeTextSpan).flat();
4037
4209
  }
@@ -4083,43 +4255,23 @@ function serializeTextSpanAttribute(spanAttribute) {
4083
4255
  }
4084
4256
  }
4085
4257
  function serializeAsCustomBlock(block, definition) {
4086
- 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
+ });
4087
4265
  return {
4088
4266
  type: "blockNode",
4089
4267
  attrs: {
4090
4268
  id: block.id,
4091
4269
  definitionId: block.data.packageId,
4092
- variantId: "default",
4093
- columns: 1,
4270
+ variantId: block.data.variantId,
4094
4271
  items: JSON.stringify(items)
4095
- // TODO Docs: variant, columns
4096
4272
  }
4097
4273
  };
4098
4274
  }
4099
- function serializeItem(item, block, definition) {
4100
- const result = {
4101
- properties: []
4102
- };
4103
- for (const property of definition.item.properties) {
4104
- const serializedValue = serializePropertyValue(item, property);
4105
- serializedValue && result.properties.push(serializedValue);
4106
- }
4107
- return result;
4108
- }
4109
- function serializePropertyValue(item, property) {
4110
- const value = _nullishCoalesce(item.props[property.id], () => ( void 0));
4111
- if (!value) {
4112
- return void 0;
4113
- }
4114
- const result = {
4115
- id: property.id,
4116
- data: {}
4117
- };
4118
- if (typeof value === "string") {
4119
- result.data.value = value;
4120
- }
4121
- return result;
4122
- }
4123
4275
  function nonNullFilter(item) {
4124
4276
  return !!item;
4125
4277
  }
@@ -4144,7 +4296,7 @@ var blocks = [
4144
4296
  description: void 0,
4145
4297
  options: {
4146
4298
  placeholder: "Start writing with plain text",
4147
- style: "Default"
4299
+ richTextStyle: "Default"
4148
4300
  },
4149
4301
  variantOptions: void 0
4150
4302
  }
@@ -4190,7 +4342,7 @@ var blocks = [
4190
4342
  id: "text",
4191
4343
  name: "Text",
4192
4344
  type: "RichText",
4193
- options: { placeholder: "Title 1", style: "Title1" }
4345
+ options: { placeholder: "Title 1", richTextStyle: "Title1" }
4194
4346
  }
4195
4347
  ],
4196
4348
  appearance: { isBordered: false, hasBackground: false },
@@ -4235,7 +4387,7 @@ var blocks = [
4235
4387
  name: "Text",
4236
4388
  type: "RichText",
4237
4389
  description: void 0,
4238
- options: { placeholder: "Title 2", style: "Title2" },
4390
+ options: { placeholder: "Title 2", richTextStyle: "Title2" },
4239
4391
  variantOptions: void 0
4240
4392
  }
4241
4393
  ],
@@ -4283,7 +4435,7 @@ var blocks = [
4283
4435
  name: "Text",
4284
4436
  type: "RichText",
4285
4437
  description: void 0,
4286
- options: { placeholder: "Title 3", style: "Title3" },
4438
+ options: { placeholder: "Title 3", richTextStyle: "Title3" },
4287
4439
  variantOptions: void 0
4288
4440
  }
4289
4441
  ],
@@ -4331,7 +4483,7 @@ var blocks = [
4331
4483
  name: "Text",
4332
4484
  type: "RichText",
4333
4485
  description: void 0,
4334
- options: { placeholder: "Title 4", style: "Title4" },
4486
+ options: { placeholder: "Title 4", richTextStyle: "Title4" },
4335
4487
  variantOptions: void 0
4336
4488
  }
4337
4489
  ],
@@ -4379,7 +4531,7 @@ var blocks = [
4379
4531
  name: "Text",
4380
4532
  type: "RichText",
4381
4533
  description: void 0,
4382
- options: { placeholder: "Title 5", style: "Title5" },
4534
+ options: { placeholder: "Title 5", richTextStyle: "Title5" },
4383
4535
  variantOptions: void 0
4384
4536
  }
4385
4537
  ],
@@ -4425,9 +4577,9 @@ var blocks = [
4425
4577
  {
4426
4578
  id: "text",
4427
4579
  name: "Text",
4428
- type: "RichText",
4580
+ type: "MultiRichText",
4429
4581
  description: void 0,
4430
- options: { style: "OL" },
4582
+ options: { multiRichTextStyle: "OL" },
4431
4583
  variantOptions: void 0
4432
4584
  }
4433
4585
  ],
@@ -4473,9 +4625,9 @@ var blocks = [
4473
4625
  {
4474
4626
  id: "text",
4475
4627
  name: "Text",
4476
- type: "RichText",
4628
+ type: "MultiRichText",
4477
4629
  description: void 0,
4478
- options: { style: "UL" },
4630
+ options: { multiRichTextStyle: "UL" },
4479
4631
  variantOptions: void 0
4480
4632
  }
4481
4633
  ],
@@ -4571,7 +4723,7 @@ var blocks = [
4571
4723
  name: "Text",
4572
4724
  type: "RichText",
4573
4725
  description: void 0,
4574
- options: { placeholder: "Empty quote", style: "Quote" },
4726
+ options: { placeholder: "Empty quote", richTextStyle: "Quote" },
4575
4727
  variantOptions: void 0
4576
4728
  }
4577
4729
  ],
@@ -4619,7 +4771,7 @@ var blocks = [
4619
4771
  name: "Text",
4620
4772
  type: "RichText",
4621
4773
  description: void 0,
4622
- options: { style: "Callout" },
4774
+ options: { richTextStyle: "Callout" },
4623
4775
  variantOptions: void 0
4624
4776
  }
4625
4777
  ],
@@ -4713,17 +4865,17 @@ var blocks = [
4713
4865
  {
4714
4866
  id: "block.links.property.title",
4715
4867
  name: "Title",
4716
- type: "RichText",
4868
+ type: "Text",
4717
4869
  description: void 0,
4718
- options: { style: "Title5" },
4870
+ options: { textStyle: "Title5" },
4719
4871
  variantOptions: void 0
4720
4872
  },
4721
4873
  {
4722
4874
  id: "block.links.property.description",
4723
4875
  name: "Short description",
4724
- type: "RichText",
4876
+ type: "Text",
4725
4877
  description: void 0,
4726
- options: { style: "Default", color: "NeutralFaded" },
4878
+ options: { textStyle: "Default", color: "NeutralFaded" },
4727
4879
  variantOptions: void 0
4728
4880
  },
4729
4881
  {
@@ -5498,7 +5650,7 @@ function prosemirrorDocToPage(prosemirrorDoc, definitions) {
5498
5650
  const definitionsById = mapByUnique(definitions, (d) => d.id);
5499
5651
  return {
5500
5652
  blocks: (_nullishCoalesce(prosemirrorDoc.content, () => ( []))).map((prosemirrorNode) => {
5501
- const definitionId = _optionalChain([prosemirrorNode, 'access', _6 => _6.attrs, 'optionalAccess', _7 => _7.definitionId]);
5653
+ const definitionId = _optionalChain([prosemirrorNode, 'access', _8 => _8.attrs, 'optionalAccess', _9 => _9.definitionId]);
5502
5654
  if (!definitionId)
5503
5655
  throw new Error(`Node is missing defintion id`);
5504
5656
  if (typeof definitionId !== "string")
@@ -5515,9 +5667,61 @@ function prosemirrorNodeToBlock(prosemirrorNode, definition) {
5515
5667
  if (richTextProperty) {
5516
5668
  return parseAsRichText(prosemirrorNode, definition, richTextProperty);
5517
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
+ }
5518
5681
  return parseAsCustomBlock(prosemirrorNode, definition);
5519
5682
  }
5520
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) {
5521
5725
  const id = parseProsemirrorBlockAttribute(prosemirrorNode, "id");
5522
5726
  const variantId = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, "variantId");
5523
5727
  return {
@@ -5526,13 +5730,23 @@ function parseAsRichText(prosemirrorNode, definition, property) {
5526
5730
  data: {
5527
5731
  packageId: definition.id,
5528
5732
  indentLevel: 0,
5529
- variantId,
5733
+ ...variantId && { variantId },
5530
5734
  items: [
5531
5735
  {
5532
5736
  id,
5533
5737
  props: {
5534
5738
  [property.id]: {
5535
- 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)
5536
5750
  }
5537
5751
  }
5538
5752
  }
@@ -5565,19 +5779,108 @@ function parseRichTextAttribute(mark) {
5565
5779
  case "code":
5566
5780
  return { type: "Code" };
5567
5781
  case "link":
5568
- const itemId = _optionalChain([mark, 'access', _8 => _8.attrs, 'optionalAccess', _9 => _9.itemId]);
5569
- const href = _optionalChain([mark, 'access', _10 => _10.attrs, 'optionalAccess', _11 => _11.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]);
5570
5784
  return {
5571
5785
  type: "Link",
5572
- openInNewWindow: _optionalChain([mark, 'access', _12 => _12.attrs, 'optionalAccess', _13 => _13.target]) !== "_self",
5786
+ openInNewWindow: _optionalChain([mark, 'access', _16 => _16.attrs, 'optionalAccess', _17 => _17.target]) !== "_self",
5573
5787
  documentationItemId: itemId,
5574
5788
  link: href
5575
5789
  };
5576
5790
  }
5577
5791
  return null;
5578
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
+ }
5579
5833
  function parseAsCustomBlock(prosemirrorNode, definition) {
5580
- 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
+ };
5581
5884
  }
5582
5885
  function parseProsemirrorBlockAttribute(prosemirrorNode, attributeName) {
5583
5886
  const attributeValue = parseProsemirrorOptionalBlockAttribute(prosemirrorNode, attributeName);
@@ -5587,7 +5890,7 @@ function parseProsemirrorBlockAttribute(prosemirrorNode, attributeName) {
5587
5890
  return attributeValue;
5588
5891
  }
5589
5892
  function parseProsemirrorOptionalBlockAttribute(prosemirrorNode, attributeName) {
5590
- return _nullishCoalesce(_optionalChain([prosemirrorNode, 'access', _14 => _14.attrs, 'optionalAccess', _15 => _15[attributeName]]), () => ( void 0));
5893
+ return _nullishCoalesce(_optionalChain([prosemirrorNode, 'access', _18 => _18.attrs, 'optionalAccess', _19 => _19[attributeName]]), () => ( void 0));
5591
5894
  }
5592
5895
  function nonNullFilter2(item) {
5593
5896
  return item !== null;
@@ -5615,6 +5918,5 @@ function mapByUnique(items, keyFn) {
5615
5918
 
5616
5919
 
5617
5920
 
5618
-
5619
- 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.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;
5620
5922
  //# sourceMappingURL=index.js.map