@contentful/experiences-visual-editor-react 1.27.1 → 1.28.0-beta.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
@@ -933,9 +933,12 @@ const BreakpointSchema$1 = z
933
933
  const UnboundValuesSchema$1 = z.record(uuidKeySchema$1, z.object({
934
934
  value: PrimitiveValueSchema$1,
935
935
  }));
936
+ const ComponentTreeNodeIdSchema$1 = z
937
+ .string()
938
+ .regex(/^[a-zA-Z0-9]{1,8}$/, { message: 'Does not match /^[a-zA-Z0-9]{1,8}$/' });
936
939
  // Use helper schema to define a recursive schema with its type correctly below
937
940
  const BaseComponentTreeNodeSchema$1 = z.object({
938
- id: uuidKeySchema$1.optional(),
941
+ id: ComponentTreeNodeIdSchema$1.optional(),
939
942
  definitionId: DefinitionPropertyKeySchema$1,
940
943
  displayName: z.string().optional(),
941
944
  slotId: z.string().optional(),
@@ -1193,21 +1196,31 @@ const transformRichText = (entryOrAsset, entityStore, path) => {
1193
1196
  };
1194
1197
  }
1195
1198
  if (typeof value === 'object' && value.nodeType === BLOCKS.DOCUMENT) {
1196
- //resolve any embedded links - we currently only support resolving embedded in the first entry
1199
+ // resolve any links to assets/entries/hyperlinks
1197
1200
  const richTextDocument = value;
1198
- richTextDocument.content.forEach((node) => {
1199
- if ((node.nodeType === BLOCKS.EMBEDDED_ENTRY || node.nodeType === BLOCKS.EMBEDDED_ASSET) &&
1200
- node.data.target.sys.type === 'Link') {
1201
- const entity = entityStore.getEntityFromLink(node.data.target);
1202
- if (entity) {
1203
- node.data.target = entity;
1204
- }
1205
- }
1206
- });
1207
- return value;
1201
+ resolveLinks(richTextDocument, entityStore);
1202
+ return richTextDocument;
1208
1203
  }
1209
1204
  return undefined;
1210
1205
  };
1206
+ const isLinkTarget = (node) => {
1207
+ return node?.data?.target?.sys?.type === 'Link';
1208
+ };
1209
+ const resolveLinks = (node, entityStore) => {
1210
+ if (!node)
1211
+ return;
1212
+ // Resolve link if current node has one
1213
+ if (isLinkTarget(node)) {
1214
+ const entity = entityStore.getEntityFromLink(node.data.target);
1215
+ if (entity) {
1216
+ node.data.target = entity;
1217
+ }
1218
+ }
1219
+ // Process content array if it exists
1220
+ if ('content' in node && Array.isArray(node.content)) {
1221
+ node.content.forEach((childNode) => resolveLinks(childNode, entityStore));
1222
+ }
1223
+ };
1211
1224
 
1212
1225
  function getOptimizedImageUrl(url, width, quality, format) {
1213
1226
  if (url.startsWith('//')) {
@@ -3278,9 +3291,12 @@ const BreakpointSchema = z
3278
3291
  const UnboundValuesSchema = z.record(uuidKeySchema, z.object({
3279
3292
  value: PrimitiveValueSchema,
3280
3293
  }));
3294
+ const ComponentTreeNodeIdSchema = z
3295
+ .string()
3296
+ .regex(/^[a-zA-Z0-9]{1,8}$/, { message: 'Does not match /^[a-zA-Z0-9]{1,8}$/' });
3281
3297
  // Use helper schema to define a recursive schema with its type correctly below
3282
3298
  const BaseComponentTreeNodeSchema = z.object({
3283
- id: uuidKeySchema.optional(),
3299
+ id: ComponentTreeNodeIdSchema.optional(),
3284
3300
  definitionId: DefinitionPropertyKeySchema,
3285
3301
  displayName: z.string().optional(),
3286
3302
  slotId: z.string().optional(),
@@ -4438,6 +4454,7 @@ const useComponentProps = ({ node, areEntitiesFetched, resolveDesignValue, rende
4438
4454
  const isAssemblyBlock = node.type === ASSEMBLY_BLOCK_NODE_TYPE;
4439
4455
  const isSingleColumn = node?.data.blockId === CONTENTFUL_COMPONENTS$1.columns.id;
4440
4456
  const isStructureComponent = isContentfulStructureComponent(node?.data.blockId);
4457
+ const isPatternNode = node.type === ASSEMBLY_NODE_TYPE;
4441
4458
  const { overrideStyles, wrapperStyles } = useMemo(() => {
4442
4459
  // Move size styles to the wrapping div and override the component styles
4443
4460
  const overrideStyles = {};
@@ -4514,18 +4531,31 @@ const useComponentProps = ({ node, areEntitiesFetched, resolveDesignValue, rende
4514
4531
  styles: componentStyles,
4515
4532
  nodeId: node.data.id,
4516
4533
  });
4517
- const componentProps = {
4534
+ const sharedProps = {
4518
4535
  'data-cf-node-id': node.data.id,
4519
4536
  'data-cf-node-block-id': node.data.blockId,
4520
4537
  'data-cf-node-block-type': node.type,
4521
4538
  className: props.cfSsrClassName ?? componentClass,
4539
+ ...(definition?.children ? { children: renderDropzone(node) } : {}),
4540
+ };
4541
+ const customComponentProps = {
4542
+ ...sharedProps,
4543
+ isInExpEditorMode: true,
4544
+ ...sanitizeNodeProps(props),
4545
+ };
4546
+ const structuralOrPatternComponentProps = {
4547
+ ...sharedProps,
4522
4548
  editorMode: true,
4523
4549
  node,
4524
4550
  renderDropzone,
4525
- ...sanitizeNodeProps(props),
4526
- ...(definition?.children ? { children: renderDropzone(node) } : {}),
4527
4551
  };
4528
- return { componentProps, componentStyles, wrapperStyles };
4552
+ return {
4553
+ componentProps: isStructureComponent || isPatternNode
4554
+ ? structuralOrPatternComponentProps
4555
+ : customComponentProps,
4556
+ componentStyles,
4557
+ wrapperStyles,
4558
+ };
4529
4559
  };
4530
4560
  const addExtraDropzonePadding = (padding) => padding
4531
4561
  .split(' ')
@@ -4566,7 +4596,7 @@ class ImportedComponentErrorBoundary extends React.Component {
4566
4596
  }
4567
4597
  }
4568
4598
 
4569
- const MissingComponentPlacehoder = ({ blockId }) => {
4599
+ const MissingComponentPlaceholder = ({ blockId }) => {
4570
4600
  return (React.createElement("div", { style: {
4571
4601
  border: '1px solid red',
4572
4602
  width: '100%',
@@ -4614,24 +4644,22 @@ const useComponent = ({ node, resolveDesignValue, renderDropzone, userIsDragging
4614
4644
  });
4615
4645
  const elementToRender = (props) => {
4616
4646
  if (!componentRegistration) {
4617
- return React.createElement(MissingComponentPlacehoder, { blockId: node.data.blockId });
4647
+ return React.createElement(MissingComponentPlaceholder, { blockId: node.data.blockId });
4618
4648
  }
4619
4649
  const { dragProps = {} } = props || {};
4620
- const { editorMode: isInExpEditorMode, renderDropzone: _renderDropzone, node: _node, ...customComponentProps } = componentProps;
4621
- const modifiedProps = isStructureComponent || isPatternNode ? componentProps : customComponentProps;
4622
4650
  const element = React.createElement(ImportedComponentErrorBoundary, { componentId: node.data.blockId }, React.createElement(componentRegistration.component, {
4623
- ...modifiedProps,
4651
+ ...componentProps,
4624
4652
  dragProps,
4625
- isInExpEditorMode,
4626
4653
  }));
4627
4654
  if (!requiresDragWrapper) {
4628
4655
  return element;
4629
4656
  }
4630
4657
  const { children, innerRef, Tag = 'div', ToolTipAndPlaceholder, style, ...rest } = dragProps;
4658
+ const { 'data-cf-node-block-id': dataCfNodeBlockId, 'data-cf-node-block-type': dataCfNodeBlockType, 'data-cf-node-id': dataCfNodeId, } = componentProps;
4631
4659
  return (React.createElement(Tag, { ...rest, style: { ...style, ...wrapperStyles }, ref: (refNode) => {
4632
4660
  if (innerRef && refNode)
4633
4661
  innerRef(refNode);
4634
- } },
4662
+ }, "data-cf-node-id": dataCfNodeId, "data-cf-node-block-id": dataCfNodeBlockId, "data-cf-node-block-type": dataCfNodeBlockType },
4635
4663
  ToolTipAndPlaceholder,
4636
4664
  element));
4637
4665
  };