@contentful/experiences-sdk-react 1.36.0 → 1.37.0-beta.2
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/blocks/preview/CompositionBlock.js +1 -1
- package/dist/blocks/preview/CompositionBlock.js.map +1 -1
- package/dist/hooks/useCustomFetch.js +24 -0
- package/dist/hooks/useCustomFetch.js.map +1 -0
- package/dist/hooks/useFetchByBase.js.map +1 -1
- package/dist/index.d.ts +22 -17
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/sdkVersion.js +1 -1
- package/dist/sdkVersion.js.map +1 -1
- package/dist/src/hooks/index.d.ts +1 -0
- package/dist/src/hooks/useCustomFetch.d.ts +22 -0
- package/dist/src/hooks/useCustomFetch.spec.d.ts +1 -0
- package/dist/src/hooks/useFetchByBase.d.ts +4 -7
- package/dist/src/hooks/useFetchById.d.ts +1 -9
- package/dist/src/hooks/useFetchBySlug.d.ts +1 -9
- package/dist/src/index.d.ts +2 -3
- package/dist/src/sdkVersion.d.ts +1 -1
- package/package.json +6 -6
- package/dist/vite.config.d.ts +0 -2
|
@@ -161,7 +161,7 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern
|
|
|
161
161
|
return undefined;
|
|
162
162
|
return resolveDesignValue(classesForNode.valuesByBreakpoint, 'cfSsrClassName');
|
|
163
163
|
}
|
|
164
|
-
return getPatternChildNodeClassName?.(childNodeId);
|
|
164
|
+
return getPatternChildNodeClassName?.(`${node.id}${childNodeId}`);
|
|
165
165
|
};
|
|
166
166
|
const children = componentRegistration.definition.children === true
|
|
167
167
|
? node.children.map((childNode, index) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CompositionBlock.js","sources":["../../../../src/blocks/preview/CompositionBlock.tsx"],"sourcesContent":["import React, { ReactNode, useMemo } from 'react';\nimport type { UnresolvedLink } from 'contentful';\nimport {\n EntityStore,\n resolveHyperlinkPattern,\n sanitizeNodeProps,\n} from '@contentful/experiences-core';\nimport {\n CONTENTFUL_COMPONENTS,\n HYPERLINK_DEFAULT_PATTERN,\n} from '@contentful/experiences-core/constants';\nimport type {\n ComponentTreeNode,\n DesignValue,\n PatternProperty,\n PrimitiveValue,\n ResolveDesignValueType,\n StyleProps,\n} from '@contentful/experiences-core/types';\nimport { createAssemblyRegistration, getComponentRegistration } from '../../core/componentRegistry';\nimport { checkIsAssemblyNode, transformBoundContentValue } from '@contentful/experiences-core';\nimport { useInjectStylesheet } from '../../hooks/useClassName';\nimport {\n Assembly,\n Columns,\n ContentfulContainer,\n SingleColumn,\n} from '@contentful/experiences-components-react';\nimport { resolveAssembly } from '../../core/preview/assemblyUtils';\nimport { Entry } from 'contentful';\nimport PreviewUnboundImage from './PreviewUnboundImage';\nimport { parseComponentProps } from '../../utils/parseComponentProps';\n\ntype CompositionBlockProps = {\n node: ComponentTreeNode;\n locale: string;\n entityStore: EntityStore;\n hyperlinkPattern?: string | undefined;\n resolveDesignValue: ResolveDesignValueType;\n getPatternChildNodeClassName?: (childNodeId: string) => string | undefined;\n wrappingPatternIds?: Set<string>;\n /**\n * Chained IDs to ensure uniqueness across multiple instances of the same pattern\n * when storing & accessing cfSsrClassName.\n */\n patternNodeIdsChain?: string;\n patternRootNodeIdsChain?: string;\n wrappingPatternProperties?: Record<string, PatternProperty>;\n};\n\nexport const CompositionBlock = ({\n node: rawNode,\n locale,\n entityStore,\n hyperlinkPattern,\n resolveDesignValue,\n getPatternChildNodeClassName,\n wrappingPatternIds: parentWrappingPatternIds = new Set(),\n wrappingPatternProperties: parentWrappingPatternProperties = {},\n patternNodeIdsChain = '',\n patternRootNodeIdsChain: parentPatternRootNodeIdsChain = '',\n}: CompositionBlockProps) => {\n patternNodeIdsChain = `${patternNodeIdsChain}${rawNode.id}`;\n\n const isAssembly = useMemo(\n () =>\n checkIsAssemblyNode({\n componentId: rawNode.definitionId,\n usedComponents: entityStore.usedComponents,\n }),\n [entityStore.usedComponents, rawNode.definitionId],\n );\n\n const patternRootNodeIdsChain = useMemo(() => {\n if (isAssembly) {\n return `${parentPatternRootNodeIdsChain}${rawNode.id}`;\n }\n return parentPatternRootNodeIdsChain;\n }, [isAssembly, parentPatternRootNodeIdsChain, rawNode.id]);\n\n const node = useMemo(() => {\n return isAssembly\n ? resolveAssembly({\n node: rawNode,\n entityStore,\n parentPatternProperties: parentWrappingPatternProperties,\n patternNodeIdsChain: patternRootNodeIdsChain,\n })\n : rawNode;\n }, [entityStore, isAssembly, rawNode, parentWrappingPatternProperties, patternRootNodeIdsChain]);\n\n const wrappingPatternIds = useMemo(() => {\n if (isAssembly) {\n return new Set([node.definitionId, ...parentWrappingPatternIds]);\n }\n return parentWrappingPatternIds;\n }, [isAssembly, node, parentWrappingPatternIds]);\n\n // Merge the pattern properties of the current node with the parent's pattern properties\n // to ensure nested patterns receive relevant pattern properties that were bubbled up\n // during assembly serialization.\n const wrappingPatternProperties = useMemo(() => {\n if (isAssembly) {\n return { ...parentWrappingPatternProperties, ...(rawNode.patternProperties || {}) };\n }\n return parentWrappingPatternProperties;\n }, [isAssembly, rawNode, parentWrappingPatternProperties]);\n\n const componentRegistration = useMemo(() => {\n const registration = getComponentRegistration(node.definitionId as string);\n\n if (isAssembly && !registration) {\n return createAssemblyRegistration({\n definitionId: node.definitionId as string,\n component: Assembly,\n });\n }\n return registration;\n }, [isAssembly, node.definitionId]);\n\n const { ssrProps, contentProps, props, mediaQuery } = useMemo(() => {\n // In SSR, we store the className under breakpoints[0] which is resolved here to the actual string\n const cfSsrClassNameValues = node.variables.cfSsrClassName as DesignValue | undefined;\n const mainBreakpoint = entityStore.breakpoints[0];\n const cfSsrClassName = cfSsrClassNameValues?.valuesByBreakpoint?.[mainBreakpoint.id] as\n | string\n | undefined;\n\n // Don't enrich the assembly wrapper node with props\n if (!componentRegistration || isAssembly) {\n const ssrProps = { cfSsrClassName };\n const props: Record<string, PrimitiveValue> = { className: cfSsrClassName };\n return {\n ssrProps,\n props,\n customDesignProps: {},\n };\n }\n\n const ssrProps: Record<string, string | undefined> = {\n cfSsrClassName:\n node.id && getPatternChildNodeClassName\n ? getPatternChildNodeClassName(node.id)\n : cfSsrClassName,\n };\n\n const {\n contentProps = {},\n styleProps = {},\n customDesignProps = {},\n mediaQuery,\n } = parseComponentProps({\n breakpoints: entityStore.breakpoints,\n mainBreakpoint,\n componentDefinition: componentRegistration.definition,\n node,\n resolveCustomDesignValue: ({ propertyName, valuesByBreakpoint }) => {\n return resolveDesignValue(valuesByBreakpoint, propertyName);\n },\n resolveBoundValue: ({ binding, propertyName, dataType }) => {\n const [, uuid] = binding.path.split('/');\n const boundEntityLink = entityStore.dataSource[uuid] as UnresolvedLink<'Entry' | 'Asset'>;\n const boundValue = transformBoundContentValue(\n node.variables,\n entityStore,\n boundEntityLink,\n resolveDesignValue,\n propertyName,\n dataType,\n binding.path,\n );\n\n return boundValue;\n },\n resolveHyperlinkValue: ({ linkTargetKey }) => {\n const boundEntity = entityStore.dataSource[linkTargetKey];\n const hyperlinkEntry = entityStore.getEntryOrAsset(boundEntity, linkTargetKey);\n\n const value = resolveHyperlinkPattern(\n componentRegistration.definition.hyperlinkPattern ||\n hyperlinkPattern ||\n HYPERLINK_DEFAULT_PATTERN,\n hyperlinkEntry as Entry,\n locale,\n );\n\n return value;\n },\n resolveUnboundValue: ({ mappingKey, defaultValue }) => {\n return entityStore.unboundValues[mappingKey]?.value ?? defaultValue;\n },\n });\n\n const slotsProps: Record<string, ReactNode> = {};\n\n if (componentRegistration.definition.slots) {\n for (const slotId in componentRegistration.definition.slots) {\n const slotNode = node.children.find((child) => child.slotId === slotId);\n if (slotNode) {\n slotsProps[slotId] = (\n <CompositionBlock\n node={slotNode}\n locale={locale}\n hyperlinkPattern={hyperlinkPattern}\n entityStore={entityStore}\n resolveDesignValue={resolveDesignValue}\n wrappingPatternIds={wrappingPatternIds}\n wrappingPatternProperties={wrappingPatternProperties}\n patternNodeIdsChain={patternNodeIdsChain}\n patternRootNodeIdsChain={patternRootNodeIdsChain}\n />\n );\n }\n }\n }\n\n const props: Record<string, PrimitiveValue> = {\n className: ssrProps.cfSsrClassName ?? mediaQuery?.className,\n ...styleProps,\n ...contentProps,\n ...customDesignProps,\n ...slotsProps,\n };\n\n return {\n ssrProps,\n contentProps,\n slotsProps,\n styleProps,\n customDesignProps,\n mediaQuery,\n props,\n };\n }, [\n node,\n entityStore,\n componentRegistration,\n isAssembly,\n getPatternChildNodeClassName,\n resolveDesignValue,\n hyperlinkPattern,\n locale,\n wrappingPatternIds,\n wrappingPatternProperties,\n patternNodeIdsChain,\n patternRootNodeIdsChain,\n ]);\n\n // do not inject the stylesheet into the dom because it's already been done on the server side\n useInjectStylesheet(ssrProps.cfSsrClassName ? undefined : mediaQuery);\n\n if (!componentRegistration) {\n return null;\n }\n\n // When detecting a circular dependency, we stop silently. The editor mode will render an actionable error.\n if (parentWrappingPatternIds.has(node.definitionId)) {\n return null;\n }\n\n const { component } = componentRegistration;\n\n // Retrieves the CSS class name for a given child node ID.\n const _getPatternChildNodeClassName = (childNodeId: string) => {\n if (isAssembly) {\n const nodeIdsChain = `${patternNodeIdsChain}${childNodeId}`;\n // @ts-expect-error -- property cfSsrClassName is a map (id to classNames) that is added during rendering in ssrStyles\n const classesForNode: DesignValue | undefined = node.variables.cfSsrClassName?.[nodeIdsChain];\n\n if (!classesForNode) return undefined;\n return resolveDesignValue(classesForNode.valuesByBreakpoint, 'cfSsrClassName') as string;\n }\n return getPatternChildNodeClassName?.(childNodeId);\n };\n\n const children =\n componentRegistration.definition.children === true\n ? node.children.map((childNode: ComponentTreeNode, index) => {\n return (\n <CompositionBlock\n getPatternChildNodeClassName={\n isAssembly || getPatternChildNodeClassName\n ? _getPatternChildNodeClassName\n : undefined\n }\n node={childNode}\n key={index}\n locale={locale}\n hyperlinkPattern={hyperlinkPattern}\n entityStore={entityStore}\n resolveDesignValue={resolveDesignValue}\n wrappingPatternIds={wrappingPatternIds}\n wrappingPatternProperties={wrappingPatternProperties}\n patternNodeIdsChain={patternNodeIdsChain}\n patternRootNodeIdsChain={patternRootNodeIdsChain}\n />\n );\n })\n : null;\n\n if (isContainerOrSection(node.definitionId)) {\n return (\n <ContentfulContainer\n editorMode={false}\n cfHyperlink={(contentProps as StyleProps).cfHyperlink}\n cfOpenInNewTab={(contentProps as StyleProps).cfOpenInNewTab}\n className={props.className as string | undefined}>\n {children}\n </ContentfulContainer>\n );\n }\n\n if (node.definitionId === CONTENTFUL_COMPONENTS.columns.id) {\n return (\n <Columns editorMode={false} className={props.className as string | undefined}>\n {children}\n </Columns>\n );\n }\n\n if (node.definitionId === CONTENTFUL_COMPONENTS.singleColumn.id) {\n return (\n <SingleColumn editorMode={false} className={props.className as string | undefined}>\n {children}\n </SingleColumn>\n );\n }\n\n if (\n node.definitionId === CONTENTFUL_COMPONENTS.image.id &&\n node.variables.cfImageAsset?.type === 'UnboundValue'\n ) {\n return (\n <PreviewUnboundImage\n node={node}\n nodeProps={props}\n component={component}\n breakpoints={entityStore.breakpoints}\n />\n );\n }\n\n return React.createElement(\n component,\n {\n ...sanitizeNodeProps(props),\n },\n children ?? (typeof props.children === 'string' ? props.children : null),\n );\n};\n\nconst isContainerOrSection = (\n nodeDefinitionId: string,\n): nodeDefinitionId is 'contentful-container' | 'contentful-section' =>\n [CONTENTFUL_COMPONENTS.container.id, CONTENTFUL_COMPONENTS.section.id].includes(\n nodeDefinitionId as 'contentful-container' | 'contentful-section',\n );\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;MAkDa,gBAAgB,GAAG,CAAC,EAC/B,IAAI,EAAE,OAAO,EACb,MAAM,EACN,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,4BAA4B,EAC5B,kBAAkB,EAAE,wBAAwB,GAAG,IAAI,GAAG,EAAE,EACxD,yBAAyB,EAAE,+BAA+B,GAAG,EAAE,EAC/D,mBAAmB,GAAG,EAAE,EACxB,uBAAuB,EAAE,6BAA6B,GAAG,EAAE,GACrC,KAAI;IAC1B,mBA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AE,KAAK,EAChB,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,WAAW,CAAC,WAAW,EACpC,CAAA,EACF;KACH;AAED,IAAA,OAAO,KAAK,CAAC,aAAa,CACxB,SAAS,EACT;QACE,GAAG,iBAAiB,CAAC,KAAK,CAAC;KAC5B,EACD,QAAQ,KAAK,OAAO,KAAK,CAAC,QAAQ,KAAK,QAAQ,GAAG,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,CACzE,CAAC;AACJ,EAAE;AAEF,MAAM,oBAAoB,GAAG,CAC3B,gBAAwB,KAExB,CAAC,qBAAqB,CAAC,SAAS,CAAC,EAAE,EAAE,qBAAqB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,QAAQ,CAC7E,gBAAiE,CAClE;;;;"}
|
|
1
|
+
{"version":3,"file":"CompositionBlock.js","sources":["../../../../src/blocks/preview/CompositionBlock.tsx"],"sourcesContent":["import React, { ReactNode, useMemo } from 'react';\nimport type { UnresolvedLink } from 'contentful';\nimport {\n EntityStore,\n resolveHyperlinkPattern,\n sanitizeNodeProps,\n} from '@contentful/experiences-core';\nimport {\n CONTENTFUL_COMPONENTS,\n HYPERLINK_DEFAULT_PATTERN,\n} from '@contentful/experiences-core/constants';\nimport type {\n ComponentTreeNode,\n DesignValue,\n PatternProperty,\n PrimitiveValue,\n ResolveDesignValueType,\n StyleProps,\n} from '@contentful/experiences-core/types';\nimport { createAssemblyRegistration, getComponentRegistration } from '../../core/componentRegistry';\nimport { checkIsAssemblyNode, transformBoundContentValue } from '@contentful/experiences-core';\nimport { useInjectStylesheet } from '../../hooks/useClassName';\nimport {\n Assembly,\n Columns,\n ContentfulContainer,\n SingleColumn,\n} from '@contentful/experiences-components-react';\nimport { resolveAssembly } from '../../core/preview/assemblyUtils';\nimport { Entry } from 'contentful';\nimport PreviewUnboundImage from './PreviewUnboundImage';\nimport { parseComponentProps } from '../../utils/parseComponentProps';\n\ntype CompositionBlockProps = {\n node: ComponentTreeNode;\n locale: string;\n entityStore: EntityStore;\n hyperlinkPattern?: string | undefined;\n resolveDesignValue: ResolveDesignValueType;\n getPatternChildNodeClassName?: (childNodeId: string) => string | undefined;\n wrappingPatternIds?: Set<string>;\n /**\n * Chained IDs to ensure uniqueness across multiple instances of the same pattern\n * when storing & accessing cfSsrClassName.\n */\n patternNodeIdsChain?: string;\n patternRootNodeIdsChain?: string;\n wrappingPatternProperties?: Record<string, PatternProperty>;\n};\n\nexport const CompositionBlock = ({\n node: rawNode,\n locale,\n entityStore,\n hyperlinkPattern,\n resolveDesignValue,\n getPatternChildNodeClassName,\n wrappingPatternIds: parentWrappingPatternIds = new Set(),\n wrappingPatternProperties: parentWrappingPatternProperties = {},\n patternNodeIdsChain = '',\n patternRootNodeIdsChain: parentPatternRootNodeIdsChain = '',\n}: CompositionBlockProps) => {\n patternNodeIdsChain = `${patternNodeIdsChain}${rawNode.id}`;\n\n const isAssembly = useMemo(\n () =>\n checkIsAssemblyNode({\n componentId: rawNode.definitionId,\n usedComponents: entityStore.usedComponents,\n }),\n [entityStore.usedComponents, rawNode.definitionId],\n );\n\n const patternRootNodeIdsChain = useMemo(() => {\n if (isAssembly) {\n return `${parentPatternRootNodeIdsChain}${rawNode.id}`;\n }\n return parentPatternRootNodeIdsChain;\n }, [isAssembly, parentPatternRootNodeIdsChain, rawNode.id]);\n\n const node = useMemo(() => {\n return isAssembly\n ? resolveAssembly({\n node: rawNode,\n entityStore,\n parentPatternProperties: parentWrappingPatternProperties,\n patternNodeIdsChain: patternRootNodeIdsChain,\n })\n : rawNode;\n }, [entityStore, isAssembly, rawNode, parentWrappingPatternProperties, patternRootNodeIdsChain]);\n\n const wrappingPatternIds = useMemo(() => {\n if (isAssembly) {\n return new Set([node.definitionId, ...parentWrappingPatternIds]);\n }\n return parentWrappingPatternIds;\n }, [isAssembly, node, parentWrappingPatternIds]);\n\n // Merge the pattern properties of the current node with the parent's pattern properties\n // to ensure nested patterns receive relevant pattern properties that were bubbled up\n // during assembly serialization.\n const wrappingPatternProperties = useMemo(() => {\n if (isAssembly) {\n return { ...parentWrappingPatternProperties, ...(rawNode.patternProperties || {}) };\n }\n return parentWrappingPatternProperties;\n }, [isAssembly, rawNode, parentWrappingPatternProperties]);\n\n const componentRegistration = useMemo(() => {\n const registration = getComponentRegistration(node.definitionId as string);\n\n if (isAssembly && !registration) {\n return createAssemblyRegistration({\n definitionId: node.definitionId as string,\n component: Assembly,\n });\n }\n return registration;\n }, [isAssembly, node.definitionId]);\n\n const { ssrProps, contentProps, props, mediaQuery } = useMemo(() => {\n // In SSR, we store the className under breakpoints[0] which is resolved here to the actual string\n const cfSsrClassNameValues = node.variables.cfSsrClassName as DesignValue | undefined;\n const mainBreakpoint = entityStore.breakpoints[0];\n const cfSsrClassName = cfSsrClassNameValues?.valuesByBreakpoint?.[mainBreakpoint.id] as\n | string\n | undefined;\n\n // Don't enrich the assembly wrapper node with props\n if (!componentRegistration || isAssembly) {\n const ssrProps = { cfSsrClassName };\n const props: Record<string, PrimitiveValue> = { className: cfSsrClassName };\n return {\n ssrProps,\n props,\n customDesignProps: {},\n };\n }\n\n const ssrProps: Record<string, string | undefined> = {\n cfSsrClassName:\n node.id && getPatternChildNodeClassName\n ? getPatternChildNodeClassName(node.id)\n : cfSsrClassName,\n };\n\n const {\n contentProps = {},\n styleProps = {},\n customDesignProps = {},\n mediaQuery,\n } = parseComponentProps({\n breakpoints: entityStore.breakpoints,\n mainBreakpoint,\n componentDefinition: componentRegistration.definition,\n node,\n resolveCustomDesignValue: ({ propertyName, valuesByBreakpoint }) => {\n return resolveDesignValue(valuesByBreakpoint, propertyName);\n },\n resolveBoundValue: ({ binding, propertyName, dataType }) => {\n const [, uuid] = binding.path.split('/');\n const boundEntityLink = entityStore.dataSource[uuid] as UnresolvedLink<'Entry' | 'Asset'>;\n const boundValue = transformBoundContentValue(\n node.variables,\n entityStore,\n boundEntityLink,\n resolveDesignValue,\n propertyName,\n dataType,\n binding.path,\n );\n\n return boundValue;\n },\n resolveHyperlinkValue: ({ linkTargetKey }) => {\n const boundEntity = entityStore.dataSource[linkTargetKey];\n const hyperlinkEntry = entityStore.getEntryOrAsset(boundEntity, linkTargetKey);\n\n const value = resolveHyperlinkPattern(\n componentRegistration.definition.hyperlinkPattern ||\n hyperlinkPattern ||\n HYPERLINK_DEFAULT_PATTERN,\n hyperlinkEntry as Entry,\n locale,\n );\n\n return value;\n },\n resolveUnboundValue: ({ mappingKey, defaultValue }) => {\n return entityStore.unboundValues[mappingKey]?.value ?? defaultValue;\n },\n });\n\n const slotsProps: Record<string, ReactNode> = {};\n\n if (componentRegistration.definition.slots) {\n for (const slotId in componentRegistration.definition.slots) {\n const slotNode = node.children.find((child) => child.slotId === slotId);\n if (slotNode) {\n slotsProps[slotId] = (\n <CompositionBlock\n node={slotNode}\n locale={locale}\n hyperlinkPattern={hyperlinkPattern}\n entityStore={entityStore}\n resolveDesignValue={resolveDesignValue}\n wrappingPatternIds={wrappingPatternIds}\n wrappingPatternProperties={wrappingPatternProperties}\n patternNodeIdsChain={patternNodeIdsChain}\n patternRootNodeIdsChain={patternRootNodeIdsChain}\n />\n );\n }\n }\n }\n\n const props: Record<string, PrimitiveValue> = {\n className: ssrProps.cfSsrClassName ?? mediaQuery?.className,\n ...styleProps,\n ...contentProps,\n ...customDesignProps,\n ...slotsProps,\n };\n\n return {\n ssrProps,\n contentProps,\n slotsProps,\n styleProps,\n customDesignProps,\n mediaQuery,\n props,\n };\n }, [\n node,\n entityStore,\n componentRegistration,\n isAssembly,\n getPatternChildNodeClassName,\n resolveDesignValue,\n hyperlinkPattern,\n locale,\n wrappingPatternIds,\n wrappingPatternProperties,\n patternNodeIdsChain,\n patternRootNodeIdsChain,\n ]);\n\n // do not inject the stylesheet into the dom because it's already been done on the server side\n useInjectStylesheet(ssrProps.cfSsrClassName ? undefined : mediaQuery);\n\n if (!componentRegistration) {\n return null;\n }\n\n // When detecting a circular dependency, we stop silently. The editor mode will render an actionable error.\n if (parentWrappingPatternIds.has(node.definitionId)) {\n return null;\n }\n\n const { component } = componentRegistration;\n\n // Retrieves the CSS class name for a given child node ID.\n const _getPatternChildNodeClassName = (childNodeId: string) => {\n if (isAssembly) {\n const nodeIdsChain = `${patternNodeIdsChain}${childNodeId}`;\n // @ts-expect-error -- property cfSsrClassName is a map (id to classNames) that is added during rendering in ssrStyles\n const classesForNode: DesignValue | undefined = node.variables.cfSsrClassName?.[nodeIdsChain];\n\n if (!classesForNode) return undefined;\n return resolveDesignValue(classesForNode.valuesByBreakpoint, 'cfSsrClassName') as string;\n }\n return getPatternChildNodeClassName?.(`${node.id}${childNodeId}`);\n };\n\n const children =\n componentRegistration.definition.children === true\n ? node.children.map((childNode: ComponentTreeNode, index) => {\n return (\n <CompositionBlock\n getPatternChildNodeClassName={\n isAssembly || getPatternChildNodeClassName\n ? _getPatternChildNodeClassName\n : undefined\n }\n node={childNode}\n key={index}\n locale={locale}\n hyperlinkPattern={hyperlinkPattern}\n entityStore={entityStore}\n resolveDesignValue={resolveDesignValue}\n wrappingPatternIds={wrappingPatternIds}\n wrappingPatternProperties={wrappingPatternProperties}\n patternNodeIdsChain={patternNodeIdsChain}\n patternRootNodeIdsChain={patternRootNodeIdsChain}\n />\n );\n })\n : null;\n\n if (isContainerOrSection(node.definitionId)) {\n return (\n <ContentfulContainer\n editorMode={false}\n cfHyperlink={(contentProps as StyleProps).cfHyperlink}\n cfOpenInNewTab={(contentProps as StyleProps).cfOpenInNewTab}\n className={props.className as string | undefined}>\n {children}\n </ContentfulContainer>\n );\n }\n\n if (node.definitionId === CONTENTFUL_COMPONENTS.columns.id) {\n return (\n <Columns editorMode={false} className={props.className as string | undefined}>\n {children}\n </Columns>\n );\n }\n\n if (node.definitionId === CONTENTFUL_COMPONENTS.singleColumn.id) {\n return (\n <SingleColumn editorMode={false} className={props.className as string | undefined}>\n {children}\n </SingleColumn>\n );\n }\n\n if (\n node.definitionId === CONTENTFUL_COMPONENTS.image.id &&\n node.variables.cfImageAsset?.type === 'UnboundValue'\n ) {\n return (\n <PreviewUnboundImage\n node={node}\n nodeProps={props}\n component={component}\n breakpoints={entityStore.breakpoints}\n />\n );\n }\n\n return React.createElement(\n component,\n {\n ...sanitizeNodeProps(props),\n },\n children ?? (typeof props.children === 'string' ? props.children : null),\n );\n};\n\nconst isContainerOrSection = (\n nodeDefinitionId: string,\n): nodeDefinitionId is 'contentful-container' | 'contentful-section' =>\n [CONTENTFUL_COMPONENTS.container.id, CONTENTFUL_COMPONENTS.section.id].includes(\n nodeDefinitionId as 'contentful-container' | 'contentful-section',\n );\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;MAkDa,gBAAgB,GAAG,CAAC,EAC/B,IAAI,EAAE,OAAO,EACb,MAAM,EACN,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,4BAA4B,EAC5B,kBAAkB,EAAE,wBAAwB,GAAG,IAAI,GAAG,EAAE,EACxD,yBAAyB,EAAE,+BAA+B,GAAG,EAAE,EAC/D,mBAAmB,GAAG,EAAE,EACxB,uBAAuB,EAAE,6BAA6B,GAAG,EAAE,GACrC,KAAI;IAC1B,mBAAmB,GAAG,GAAG,mBAAmB,CAAA,EAAG,OAAO,CAAC,EAAE,EAAE,CAAC;IAE5D,MAAM,UAAU,GAAG,OAAO,CACxB,MACE,mBAAmB,CAAC;QAClB,WAAW,EAAE,OAAO,CAAC,YAAY;QACjC,cAAc,EAAE,WAAW,CAAC,cAAc;KAC3C,CAAC,EACJ,CAAC,WAAW,CAAC,cAAc,EAAE,OAAO,CAAC,YAAY,CAAC,CACnD,CAAC;AAEF,IAAA,MAAM,uBAAuB,GAAG,OAAO,CAAC,MAAK;QAC3C,IAAI,UAAU,EAAE;AACd,YAAA,OAAO,GAAG,6BAA6B,CAAA,EAAG,OAAO,CAAC,EAAE,EAAE,CAAC;SACxD;AACD,QAAA,OAAO,6BAA6B,CAAC;KACtC,EAAE,CAAC,UAAU,EAAE,6BAA6B,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;AAE5D,IAAA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
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { useFetchByBase } from './useFetchByBase.js';
|
|
3
|
+
import { useDetectCanvasMode } from './useDetectCanvasMode.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A hook that allows specifying a custom fetch function to retrieve an experience with all its references.
|
|
7
|
+
* @param options.fetchFn - A function that returns a promise resolving to an experience instance created with `createExperience()`
|
|
8
|
+
* @param options.hyperlinkPattern - URL Pattern for generating links for hyperlink properties on nodes pointing to other experience pages
|
|
9
|
+
* @returns loading state, error message, and the experience instance that needs to be passed to `<ExperienceRoot>`
|
|
10
|
+
*/
|
|
11
|
+
const useCustomFetch = ({ fetchFn, hyperlinkPattern }) => {
|
|
12
|
+
const mode = useDetectCanvasMode({ isClientSide: typeof window !== 'undefined' });
|
|
13
|
+
const fetchMethod = useCallback(() => {
|
|
14
|
+
return fetchFn();
|
|
15
|
+
// we purposely don't want to include the client in the dependencies as it can cause infinite loops if the
|
|
16
|
+
// user creates the client in the component
|
|
17
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
18
|
+
}, []);
|
|
19
|
+
const fetchResult = useFetchByBase(fetchMethod, mode);
|
|
20
|
+
return { ...fetchResult, experience: { ...fetchResult.experience, hyperlinkPattern } };
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { useCustomFetch };
|
|
24
|
+
//# sourceMappingURL=useCustomFetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCustomFetch.js","sources":["../../../src/hooks/useCustomFetch.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { useFetchByBase } from './useFetchByBase';\nimport { useDetectCanvasMode } from './useDetectCanvasMode';\nimport { Experience } from '@contentful/experiences-core/types';\nimport { EntityStore } from '@contentful/experiences-core';\n\nexport type UseCustomFetchArgs = {\n fetchFn: () => Promise<Experience<EntityStore> | undefined>;\n /** The pattern being used to generate links for hyperlink properties **/\n hyperlinkPattern?: string;\n};\n\n/**\n * A hook that allows specifying a custom fetch function to retrieve an experience with all its references.\n * @param options.fetchFn - A function that returns a promise resolving to an experience instance created with `createExperience()`\n * @param options.hyperlinkPattern - URL Pattern for generating links for hyperlink properties on nodes pointing to other experience pages\n * @returns loading state, error message, and the experience instance that needs to be passed to `<ExperienceRoot>`\n */\nexport const useCustomFetch = ({ fetchFn, hyperlinkPattern }: UseCustomFetchArgs) => {\n const mode = useDetectCanvasMode({ isClientSide: typeof window !== 'undefined' });\n\n const fetchMethod = useCallback(() => {\n return fetchFn();\n // we purposely don't want to include the client in the dependencies as it can cause infinite loops if the\n // user creates the client in the component\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const fetchResult = useFetchByBase(fetchMethod, mode);\n\n return { ...fetchResult, experience: { ...fetchResult.experience, hyperlinkPattern } };\n};\n"],"names":[],"mappings":";;;;AAYA;;;;;AAKG;AACU,MAAA,cAAc,GAAG,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAsB,KAAI;AAClF,IAAA,MAAM,IAAI,GAAG,mBAAmB,CAAC,EAAE,YAAY,EAAE,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC,CAAC;AAElF,IAAA,MAAM,WAAW,GAAG,WAAW,CAAC,MAAK;QACnC,OAAO,OAAO,EAAE,CAAC;;;;KAIlB,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,WAAW,GAAG,cAAc,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;AAEtD,IAAA,OAAO,EAAE,GAAG,WAAW,EAAE,UAAU,EAAE,EAAE,GAAG,WAAW,CAAC,UAAU,EAAE,gBAAgB,EAAE,EAAE,CAAC;AACzF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFetchByBase.js","sources":["../../../src/hooks/useFetchByBase.ts"],"sourcesContent":["'use client';\nimport { useEffect, useState } from 'react';\nimport { EntityStore } from '@contentful/experiences-core';\nimport type { Experience } from '@contentful/experiences-core/types';\nimport { StudioCanvasMode } from '@contentful/experiences-core/constants';\n\nexport const useFetchByBase = (\n fetchMethod: () => Promise<Experience<EntityStore> | undefined>,\n mode: StudioCanvasMode,\n) => {\n const [experience, setExperience] = useState<Experience<EntityStore>>();\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<Error>();\n\n useEffect(() => {\n (async () => {\n // if we are in editor/read only mode, we don't want to fetch the experience here\n // it is passed via postMessage instead\n if (mode === StudioCanvasMode.EDITOR || mode === StudioCanvasMode.READ_ONLY) {\n return;\n }\n setIsLoading(true);\n setError(undefined);\n try {\n const exp = await fetchMethod();\n setExperience(exp);\n } catch (error) {\n setError(error as Error);\n } finally {\n setIsLoading(false);\n }\n })();\n }, [fetchMethod, mode]);\n\n // When a save event caused a canvas reload, the `receivedModeMessage` might time out and set the\n // mode temporarily to NONE. If it's set to a valid mode afterward, we ignore the fetch result.\n if (mode === StudioCanvasMode.EDITOR || mode === StudioCanvasMode.READ_ONLY) {\n return {\n error: undefined,\n experience: undefined,\n isLoading: false,\n mode,\n };\n }\n\n return {\n error,\n experience,\n isLoading,\n mode,\n };\n};\n"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useFetchByBase.js","sources":["../../../src/hooks/useFetchByBase.ts"],"sourcesContent":["'use client';\nimport { useEffect, useState } from 'react';\nimport { EntityStore } from '@contentful/experiences-core';\nimport type { Experience } from '@contentful/experiences-core/types';\nimport { StudioCanvasMode } from '@contentful/experiences-core/constants';\n\n// Typing the response explicitly ensures a stable interface for all fetchers\n// and creates more readable type definitions for the SDK consumers.\ntype UseFetchByBaseResponse = {\n error: Error | undefined;\n experience: Experience<EntityStore> | undefined;\n isLoading: boolean;\n mode: StudioCanvasMode;\n};\n\nexport const useFetchByBase = (\n fetchMethod: () => Promise<Experience<EntityStore> | undefined>,\n mode: StudioCanvasMode,\n): UseFetchByBaseResponse => {\n const [experience, setExperience] = useState<Experience<EntityStore>>();\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<Error>();\n\n useEffect(() => {\n (async () => {\n // if we are in editor/read only mode, we don't want to fetch the experience here\n // it is passed via postMessage instead\n if (mode === StudioCanvasMode.EDITOR || mode === StudioCanvasMode.READ_ONLY) {\n return;\n }\n setIsLoading(true);\n setError(undefined);\n try {\n const exp = await fetchMethod();\n setExperience(exp);\n } catch (error) {\n setError(error as Error);\n } finally {\n setIsLoading(false);\n }\n })();\n }, [fetchMethod, mode]);\n\n // When a save event caused a canvas reload, the `receivedModeMessage` might time out and set the\n // mode temporarily to NONE. If it's set to a valid mode afterward, we ignore the fetch result.\n if (mode === StudioCanvasMode.EDITOR || mode === StudioCanvasMode.READ_ONLY) {\n return {\n error: undefined,\n experience: undefined,\n isLoading: false,\n mode,\n };\n }\n\n return {\n error,\n experience,\n isLoading,\n mode,\n };\n};\n"],"names":[],"mappings":";;;;;;;;;;;;AA2BM;;;;;AAKA;AACE;;;;;;;;;;AAQN;;;AAIA;;AAEI;AACA;AACA;;;;;;;;;;AAWN;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as _contentful_experiences_core from '@contentful/experiences-core';
|
|
3
3
|
import { EntityStore, VisualEditorMode } from '@contentful/experiences-core';
|
|
4
|
-
export { VisualEditorMode, createExperience, defineBreakpoints, defineDesignTokens, detachExperienceStyles, fetchById, fetchBySlug } from '@contentful/experiences-core';
|
|
4
|
+
export { VisualEditorMode, createExperience, defineBreakpoints, defineDesignTokens, detachExperienceStyles, fetchById, fetchBySlug, fetchExperienceEntry, fetchReferencedEntities, localizeEntity } from '@contentful/experiences-core';
|
|
5
5
|
import { Experience, ComponentRegistration, ComponentRegistrationOptions } from '@contentful/experiences-core/types';
|
|
6
6
|
export { ComponentDefinition, ComponentRegistration, Experience } from '@contentful/experiences-core/types';
|
|
7
7
|
import * as _contentful_experiences_core_constants from '@contentful/experiences-core/constants';
|
|
8
8
|
export { CF_STYLE_ATTRIBUTES, CONTENTFUL_COMPONENTS, LATEST_SCHEMA_VERSION } from '@contentful/experiences-core/constants';
|
|
9
9
|
import { ContentfulClientApi } from 'contentful';
|
|
10
10
|
|
|
11
|
-
declare const SDK_VERSION = "1.
|
|
11
|
+
declare const SDK_VERSION = "1.37.0-beta.2";
|
|
12
12
|
|
|
13
13
|
type ExperienceRootProps = {
|
|
14
14
|
experience?: Experience<EntityStore> | string | null;
|
|
@@ -31,21 +31,13 @@ type UseFetchByIdArgs = {
|
|
|
31
31
|
hyperlinkPattern?: string;
|
|
32
32
|
};
|
|
33
33
|
declare const useFetchById: ({ id, localeCode, client, experienceTypeId, hyperlinkPattern, }: UseFetchByIdArgs) => {
|
|
34
|
-
experience: {
|
|
35
|
-
hyperlinkPattern: string | undefined;
|
|
36
|
-
entityStore?: _contentful_experiences_core.EntityStore | undefined;
|
|
37
|
-
};
|
|
38
|
-
error: undefined;
|
|
39
|
-
isLoading: boolean;
|
|
40
|
-
mode: _contentful_experiences_core_constants.StudioCanvasMode.READ_ONLY | _contentful_experiences_core_constants.StudioCanvasMode.EDITOR;
|
|
41
|
-
} | {
|
|
42
34
|
experience: {
|
|
43
35
|
hyperlinkPattern: string | undefined;
|
|
44
36
|
entityStore?: _contentful_experiences_core.EntityStore | undefined;
|
|
45
37
|
};
|
|
46
38
|
error: Error | undefined;
|
|
47
39
|
isLoading: boolean;
|
|
48
|
-
mode: _contentful_experiences_core_constants.StudioCanvasMode
|
|
40
|
+
mode: _contentful_experiences_core_constants.StudioCanvasMode;
|
|
49
41
|
};
|
|
50
42
|
|
|
51
43
|
type UseFetchBySlugArgs = {
|
|
@@ -61,17 +53,30 @@ declare const useFetchBySlug: ({ slug, localeCode, client, experienceTypeId, hyp
|
|
|
61
53
|
hyperlinkPattern: string | undefined;
|
|
62
54
|
entityStore?: _contentful_experiences_core.EntityStore | undefined;
|
|
63
55
|
};
|
|
64
|
-
error: undefined;
|
|
56
|
+
error: Error | undefined;
|
|
65
57
|
isLoading: boolean;
|
|
66
|
-
mode: _contentful_experiences_core_constants.StudioCanvasMode
|
|
67
|
-
}
|
|
58
|
+
mode: _contentful_experiences_core_constants.StudioCanvasMode;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
type UseCustomFetchArgs = {
|
|
62
|
+
fetchFn: () => Promise<Experience<EntityStore> | undefined>;
|
|
63
|
+
/** The pattern being used to generate links for hyperlink properties **/
|
|
64
|
+
hyperlinkPattern?: string;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* A hook that allows specifying a custom fetch function to retrieve an experience with all its references.
|
|
68
|
+
* @param options.fetchFn - A function that returns a promise resolving to an experience instance created with `createExperience()`
|
|
69
|
+
* @param options.hyperlinkPattern - URL Pattern for generating links for hyperlink properties on nodes pointing to other experience pages
|
|
70
|
+
* @returns loading state, error message, and the experience instance that needs to be passed to `<ExperienceRoot>`
|
|
71
|
+
*/
|
|
72
|
+
declare const useCustomFetch: ({ fetchFn, hyperlinkPattern }: UseCustomFetchArgs) => {
|
|
68
73
|
experience: {
|
|
69
74
|
hyperlinkPattern: string | undefined;
|
|
70
|
-
entityStore?:
|
|
75
|
+
entityStore?: EntityStore | undefined;
|
|
71
76
|
};
|
|
72
77
|
error: Error | undefined;
|
|
73
78
|
isLoading: boolean;
|
|
74
|
-
mode: _contentful_experiences_core_constants.StudioCanvasMode
|
|
79
|
+
mode: _contentful_experiences_core_constants.StudioCanvasMode;
|
|
75
80
|
};
|
|
76
81
|
|
|
77
82
|
/**
|
|
@@ -89,4 +94,4 @@ declare const defineComponents: (componentRegistrations: ComponentRegistration[]
|
|
|
89
94
|
*/
|
|
90
95
|
declare const maintainBasicComponentIdsWithoutPrefix: () => void;
|
|
91
96
|
|
|
92
|
-
export { ExperienceRoot, defineComponents, maintainBasicComponentIdsWithoutPrefix, useFetchById, useFetchBySlug, SDK_VERSION as version };
|
|
97
|
+
export { ExperienceRoot, defineComponents, maintainBasicComponentIdsWithoutPrefix, useCustomFetch, useFetchById, useFetchBySlug, SDK_VERSION as version };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { enableDebug, disableDebug } from '@contentful/experiences-core';
|
|
2
|
-
export { VisualEditorMode, createExperience, defineBreakpoints, defineDesignTokens, detachExperienceStyles, fetchById, fetchBySlug } from '@contentful/experiences-core';
|
|
2
|
+
export { VisualEditorMode, createExperience, defineBreakpoints, defineDesignTokens, detachExperienceStyles, fetchById, fetchBySlug, fetchExperienceEntry, fetchReferencedEntities, localizeEntity } from '@contentful/experiences-core';
|
|
3
3
|
import { SDK_VERSION } from './sdkVersion.js';
|
|
4
4
|
export { ExperienceRoot } from './ExperienceRoot.js';
|
|
5
5
|
import 'react';
|
|
6
6
|
export { useFetchById } from './hooks/useFetchById.js';
|
|
7
7
|
export { useFetchBySlug } from './hooks/useFetchBySlug.js';
|
|
8
|
+
export { useCustomFetch } from './hooks/useCustomFetch.js';
|
|
8
9
|
export { defineComponents, maintainBasicComponentIdsWithoutPrefix } from './core/componentRegistry.js';
|
|
9
10
|
export { CF_STYLE_ATTRIBUTES, CONTENTFUL_COMPONENTS, LATEST_SCHEMA_VERSION } from '@contentful/experiences-core/constants';
|
|
10
11
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { enableDebug, disableDebug } from '@contentful/experiences-core';\nimport { SDK_VERSION } from './sdkVersion';\nexport { SDK_VERSION as version };\n\nexport { ExperienceRoot } from './ExperienceRoot';\nexport { useFetchById, useFetchBySlug } from './hooks';\nexport { defineComponents, maintainBasicComponentIdsWithoutPrefix } from './core/componentRegistry';\nexport {\n defineDesignTokens,\n defineBreakpoints,\n VisualEditorMode,\n fetchById,\n fetchBySlug,\n createExperience,\n} from '@contentful/experiences-core';\nexport {\n CONTENTFUL_COMPONENTS,\n LATEST_SCHEMA_VERSION,\n CF_STYLE_ATTRIBUTES,\n} from '@contentful/experiences-core/constants';\n\n// Simple state store to store a few things that are needed across the SDK\nif (typeof window !== 'undefined') {\n if (!window.__EB__) {\n window.__EB__ = {};\n }\n window.__EB__.sdkVersion = SDK_VERSION;\n window.__EB__.enableDebug = enableDebug;\n window.__EB__.disableDebug = disableDebug;\n}\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { enableDebug, disableDebug } from '@contentful/experiences-core';\nimport { SDK_VERSION } from './sdkVersion';\nexport { SDK_VERSION as version };\n\nexport { ExperienceRoot } from './ExperienceRoot';\nexport { useFetchById, useFetchBySlug, useCustomFetch } from './hooks';\nexport { defineComponents, maintainBasicComponentIdsWithoutPrefix } from './core/componentRegistry';\nexport {\n defineDesignTokens,\n defineBreakpoints,\n VisualEditorMode,\n fetchById,\n fetchBySlug,\n createExperience,\n detachExperienceStyles,\n fetchReferencedEntities,\n fetchExperienceEntry,\n localizeEntity,\n} from '@contentful/experiences-core';\nexport {\n CONTENTFUL_COMPONENTS,\n LATEST_SCHEMA_VERSION,\n CF_STYLE_ATTRIBUTES,\n} from '@contentful/experiences-core/constants';\nexport type {\n Experience,\n ComponentDefinition,\n ComponentRegistration,\n} from '@contentful/experiences-core/types';\n\n// Simple state store to store a few things that are needed across the SDK\nif (typeof window !== 'undefined') {\n if (!window.__EB__) {\n window.__EB__ = {};\n }\n window.__EB__.sdkVersion = SDK_VERSION;\n window.__EB__.enableDebug = enableDebug;\n window.__EB__.disableDebug = disableDebug;\n}\n"],"names":[],"mappings":";;;;;;;;;;;AA8BA;AACA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;AACjC,IAAA,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;AAClB,QAAA,MAAM,CAAC,MAAM,GAAG,EAAE,CAAC;KACpB;AACD,IAAA,MAAM,CAAC,MAAM,CAAC,UAAU,GAAG,WAAW,CAAC;AACvC,IAAA,MAAM,CAAC,MAAM,CAAC,WAAW,GAAG,WAAW,CAAC;AACxC,IAAA,MAAM,CAAC,MAAM,CAAC,YAAY,GAAG,YAAY,CAAC;AAC5C;;;;"}
|
package/dist/sdkVersion.js
CHANGED
package/dist/sdkVersion.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdkVersion.js","sources":["../../src/sdkVersion.ts"],"sourcesContent":["export const SDK_VERSION = '1.
|
|
1
|
+
{"version":3,"file":"sdkVersion.js","sources":["../../src/sdkVersion.ts"],"sourcesContent":["export const SDK_VERSION = '1.37.0-beta.2';\n"],"names":[],"mappings":"AAAO,MAAM,WAAW,GAAG;;;;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Experience } from '@contentful/experiences-core/types';
|
|
2
|
+
import { EntityStore } from '@contentful/experiences-core';
|
|
3
|
+
export type UseCustomFetchArgs = {
|
|
4
|
+
fetchFn: () => Promise<Experience<EntityStore> | undefined>;
|
|
5
|
+
/** The pattern being used to generate links for hyperlink properties **/
|
|
6
|
+
hyperlinkPattern?: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* A hook that allows specifying a custom fetch function to retrieve an experience with all its references.
|
|
10
|
+
* @param options.fetchFn - A function that returns a promise resolving to an experience instance created with `createExperience()`
|
|
11
|
+
* @param options.hyperlinkPattern - URL Pattern for generating links for hyperlink properties on nodes pointing to other experience pages
|
|
12
|
+
* @returns loading state, error message, and the experience instance that needs to be passed to `<ExperienceRoot>`
|
|
13
|
+
*/
|
|
14
|
+
export declare const useCustomFetch: ({ fetchFn, hyperlinkPattern }: UseCustomFetchArgs) => {
|
|
15
|
+
experience: {
|
|
16
|
+
hyperlinkPattern: string | undefined;
|
|
17
|
+
entityStore?: EntityStore | undefined;
|
|
18
|
+
};
|
|
19
|
+
error: Error | undefined;
|
|
20
|
+
isLoading: boolean;
|
|
21
|
+
mode: import("@contentful/experiences-core/constants").StudioCanvasMode;
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { EntityStore } from '@contentful/experiences-core';
|
|
2
2
|
import type { Experience } from '@contentful/experiences-core/types';
|
|
3
3
|
import { StudioCanvasMode } from '@contentful/experiences-core/constants';
|
|
4
|
-
|
|
5
|
-
error: undefined;
|
|
6
|
-
experience: undefined;
|
|
7
|
-
isLoading: boolean;
|
|
8
|
-
mode: StudioCanvasMode.READ_ONLY | StudioCanvasMode.EDITOR;
|
|
9
|
-
} | {
|
|
4
|
+
type UseFetchByBaseResponse = {
|
|
10
5
|
error: Error | undefined;
|
|
11
6
|
experience: Experience<EntityStore> | undefined;
|
|
12
7
|
isLoading: boolean;
|
|
13
|
-
mode: StudioCanvasMode
|
|
8
|
+
mode: StudioCanvasMode;
|
|
14
9
|
};
|
|
10
|
+
export declare const useFetchByBase: (fetchMethod: () => Promise<Experience<EntityStore> | undefined>, mode: StudioCanvasMode) => UseFetchByBaseResponse;
|
|
11
|
+
export {};
|
|
@@ -7,19 +7,11 @@ export type UseFetchByIdArgs = {
|
|
|
7
7
|
hyperlinkPattern?: string;
|
|
8
8
|
};
|
|
9
9
|
export declare const useFetchById: ({ id, localeCode, client, experienceTypeId, hyperlinkPattern, }: UseFetchByIdArgs) => {
|
|
10
|
-
experience: {
|
|
11
|
-
hyperlinkPattern: string | undefined;
|
|
12
|
-
entityStore?: import("@contentful/experiences-core").EntityStore | undefined;
|
|
13
|
-
};
|
|
14
|
-
error: undefined;
|
|
15
|
-
isLoading: boolean;
|
|
16
|
-
mode: import("@contentful/experiences-core/constants").StudioCanvasMode.READ_ONLY | import("@contentful/experiences-core/constants").StudioCanvasMode.EDITOR;
|
|
17
|
-
} | {
|
|
18
10
|
experience: {
|
|
19
11
|
hyperlinkPattern: string | undefined;
|
|
20
12
|
entityStore?: import("@contentful/experiences-core").EntityStore | undefined;
|
|
21
13
|
};
|
|
22
14
|
error: Error | undefined;
|
|
23
15
|
isLoading: boolean;
|
|
24
|
-
mode: import("@contentful/experiences-core/constants").StudioCanvasMode
|
|
16
|
+
mode: import("@contentful/experiences-core/constants").StudioCanvasMode;
|
|
25
17
|
};
|
|
@@ -8,19 +8,11 @@ export type UseFetchBySlugArgs = {
|
|
|
8
8
|
hyperlinkPattern?: string;
|
|
9
9
|
};
|
|
10
10
|
export declare const useFetchBySlug: ({ slug, localeCode, client, experienceTypeId, hyperlinkPattern, }: UseFetchBySlugArgs) => {
|
|
11
|
-
experience: {
|
|
12
|
-
hyperlinkPattern: string | undefined;
|
|
13
|
-
entityStore?: import("@contentful/experiences-core").EntityStore | undefined;
|
|
14
|
-
};
|
|
15
|
-
error: undefined;
|
|
16
|
-
isLoading: boolean;
|
|
17
|
-
mode: import("@contentful/experiences-core/constants").StudioCanvasMode.READ_ONLY | import("@contentful/experiences-core/constants").StudioCanvasMode.EDITOR;
|
|
18
|
-
} | {
|
|
19
11
|
experience: {
|
|
20
12
|
hyperlinkPattern: string | undefined;
|
|
21
13
|
entityStore?: import("@contentful/experiences-core").EntityStore | undefined;
|
|
22
14
|
};
|
|
23
15
|
error: Error | undefined;
|
|
24
16
|
isLoading: boolean;
|
|
25
|
-
mode: import("@contentful/experiences-core/constants").StudioCanvasMode
|
|
17
|
+
mode: import("@contentful/experiences-core/constants").StudioCanvasMode;
|
|
26
18
|
};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { SDK_VERSION } from './sdkVersion';
|
|
2
2
|
export { SDK_VERSION as version };
|
|
3
3
|
export { ExperienceRoot } from './ExperienceRoot';
|
|
4
|
-
export { useFetchById, useFetchBySlug } from './hooks';
|
|
4
|
+
export { useFetchById, useFetchBySlug, useCustomFetch } from './hooks';
|
|
5
5
|
export { defineComponents, maintainBasicComponentIdsWithoutPrefix } from './core/componentRegistry';
|
|
6
|
-
export { defineDesignTokens, defineBreakpoints, VisualEditorMode, fetchById, fetchBySlug, createExperience, } from '@contentful/experiences-core';
|
|
6
|
+
export { defineDesignTokens, defineBreakpoints, VisualEditorMode, fetchById, fetchBySlug, createExperience, detachExperienceStyles, fetchReferencedEntities, fetchExperienceEntry, localizeEntity, } from '@contentful/experiences-core';
|
|
7
7
|
export { CONTENTFUL_COMPONENTS, LATEST_SCHEMA_VERSION, CF_STYLE_ATTRIBUTES, } from '@contentful/experiences-core/constants';
|
|
8
8
|
export type { Experience, ComponentDefinition, ComponentRegistration, } from '@contentful/experiences-core/types';
|
|
9
|
-
export { detachExperienceStyles } from '@contentful/experiences-core';
|
package/dist/src/sdkVersion.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.
|
|
1
|
+
export declare const SDK_VERSION = "1.37.0-beta.2";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/experiences-sdk-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.37.0-beta.2",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"typings": "./dist/src/index.d.ts",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"depcruise": "depcruise src"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@contentful/experiences-components-react": "1.
|
|
45
|
-
"@contentful/experiences-core": "1.
|
|
46
|
-
"@contentful/experiences-validators": "1.
|
|
47
|
-
"@contentful/experiences-visual-editor-react": "1.
|
|
44
|
+
"@contentful/experiences-components-react": "1.37.0-beta.2",
|
|
45
|
+
"@contentful/experiences-core": "1.37.0-beta.2",
|
|
46
|
+
"@contentful/experiences-validators": "1.37.0-beta.2",
|
|
47
|
+
"@contentful/experiences-visual-editor-react": "1.37.0-beta.2",
|
|
48
48
|
"@contentful/rich-text-types": "^17.0.0",
|
|
49
49
|
"classnames": "^2.3.2",
|
|
50
50
|
"csstype": "^3.1.2",
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"dist",
|
|
103
103
|
"package.json"
|
|
104
104
|
],
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "cbcd3d8173ba2b7ea845d18265c7e95bdb43181a"
|
|
106
106
|
}
|
package/dist/vite.config.d.ts
DELETED