@financial-times/cp-content-pipeline-ui 6.15.1 → 6.15.3

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.
@@ -47,6 +47,8 @@ import {
47
47
  import { ScrollyImage } from '../Scrollytelling/ScrollyImage'
48
48
  import YoutubeVideo from '../YoutubeVideo'
49
49
 
50
+ import RichTextContext from './context'
51
+
50
52
  export type RichTextComponentMapRecord = Partial<
51
53
  Record<
52
54
  ContentTreeWorkarounds.AnyNode['type'] | 'fallback',
@@ -63,7 +65,7 @@ export const ComponentsContext = createContext<
63
65
  type WithOptionalProperty<T, K extends keyof T> = Pick<Partial<T>, K> &
64
66
  Omit<T, K>
65
67
 
66
- type RichTextProps = {
68
+ export type RichTextProps = {
67
69
  // the component using RichText might not have queried for references, so make it optional
68
70
  structuredContent: WithOptionalProperty<
69
71
  StructuredContentFragment,
@@ -140,7 +142,13 @@ const RichTextChild: React.FC<RichTextChildProps> = ({
140
142
  return <>{node.value}</>
141
143
  }
142
144
 
143
- const Component = components[node.type] || components.fallback
145
+ let Component = components[node.type]
146
+ if (!Component) {
147
+ console.warn(
148
+ `couldn't find component for Content Tree node ${node.type}, using fallback component instead (by default will render the node's children)`
149
+ )
150
+ Component = components.fallback
151
+ }
144
152
 
145
153
  if (Component) {
146
154
  const children: ReactNode[] = isParentNode(node)
@@ -163,14 +171,16 @@ const RichTextChild: React.FC<RichTextChildProps> = ({
163
171
  : {}
164
172
 
165
173
  return (
166
- <Component
167
- {...node}
168
- {...reference}
169
- key={parentIndex}
170
- parentIndex={parentIndex}
171
- >
172
- {children}
173
- </Component>
174
+ <RichTextContext.Provider value={RichText}>
175
+ <Component
176
+ {...node}
177
+ {...reference}
178
+ key={parentIndex}
179
+ parentIndex={parentIndex}
180
+ >
181
+ {children}
182
+ </Component>
183
+ </RichTextContext.Provider>
174
184
  )
175
185
  }
176
186