Skip to content

Commit

Permalink
Merge pull request #630 from contember/pr/allow-richtext-renderer-rea…
Browse files Browse the repository at this point in the history
…donly-props

Allow richtext renderer readonly props
  • Loading branch information
matej21 authored Oct 19, 2023
2 parents f37bdf6 + cf2eadd commit 903c5d7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions build/api/react-client.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export interface RichTextAnchorElement<CustomElements extends RichTextElement =
}

// @public (undocumented)
export type RichTextBlock = Record<string, unknown>;
export type RichTextBlock = Readonly<Record<string, unknown>>;

// @public (undocumented)
export interface RichTextBoldLeaf extends RichTextLeaf {
Expand Down Expand Up @@ -312,7 +312,7 @@ export const RichTextRenderer: <CustomElements extends RichTextElement<never, ne
// @public (undocumented)
export interface RichTextRendererBlockProps<CustomElements extends RichTextElement = never, CustomLeaves extends RichTextLeaf = never> {
// (undocumented)
blocks: RichTextBlock[];
blocks: readonly RichTextBlock[];
// (undocumented)
referenceDiscriminationField?: string;
// (undocumented)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type RichTextBlock = Record<string, unknown>
export type RichTextBlock = Readonly<Record<string, unknown>>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface RichTextRendererBlockProps<
CustomElements extends RichTextElement = never,
CustomLeaves extends RichTextLeaf = never,
> {
blocks: RichTextBlock[]
blocks: readonly RichTextBlock[]
referenceRenderers?: Record<string, ReferenceRenderer<any, CustomElements, CustomLeaves>>
sourceField?: string
referencesField?: string
Expand Down Expand Up @@ -60,9 +60,9 @@ export const RichTextRenderer = memo(function RichTextRenderer<
content: sourceProps.source
? deserialize(sourceProps.source)
: {
formatVersion: 0,
children: [],
},
formatVersion: 0,
children: [],
},
id: undefined,
referencesField: undefined,
referenceDiscriminationField: undefined,
Expand All @@ -80,10 +80,10 @@ export const RichTextRenderer = memo(function RichTextRenderer<
if (!(sourceField in block)) {
throw new RichTextRendererError(
`Found a block without a '${sourceField}' field. ` +
(sourceProps.sourceField === undefined
? `The 'sourceField' prop has not been supplied, and so '${sourceField}' was used as a default.`
: `That is what the 'sourceField' prop has been set to, and so either this is a typo, ` +
`or the data supplied is invalid.`),
(sourceProps.sourceField === undefined
? `The 'sourceField' prop has not been supplied, and so '${sourceField}' was used as a default.`
: `That is what the 'sourceField' prop has been set to, and so either this is a typo, ` +
`or the data supplied is invalid.`),
)
}
const source = block[sourceField]
Expand All @@ -94,8 +94,8 @@ export const RichTextRenderer = memo(function RichTextRenderer<
if (sourceProps.referencesField !== undefined && !(referencesField in block)) {
throw new RichTextRendererError(
`The 'referencesField' prop is set to '${referencesField}' but a block without such field ` +
`has been encountered. Unless this is just a typo, ` +
`if you do not wish to use references, avoid supplying the 'referencesField' prop.`,
`has been encountered. Unless this is just a typo, ` +
`if you do not wish to use references, avoid supplying the 'referencesField' prop.`,
)
}
const references = block[referencesField]
Expand All @@ -114,11 +114,11 @@ export const RichTextRenderer = memo(function RichTextRenderer<
if (!(referenceDiscriminationField in reference)) {
throw new RichTextRendererError(
`Found a reference without a '${referenceDiscriminationField}' field. ` +
(sourceProps.referenceDiscriminationField === undefined
? `The 'referenceDiscriminationField' prop has not been supplied, ` +
`and so '${referenceDiscriminationField}' was used as a default.`
: `That is what the 'referenceDiscriminationField' prop has been set to, ` +
`and so either this is a typo, or the data supplied is invalid.`),
(sourceProps.referenceDiscriminationField === undefined
? `The 'referenceDiscriminationField' prop has not been supplied, ` +
`and so '${referenceDiscriminationField}' was used as a default.`
: `That is what the 'referenceDiscriminationField' prop has been set to, ` +
`and so either this is a typo, or the data supplied is invalid.`),
)
}
normalizedReferences.set(reference.id, reference)
Expand Down Expand Up @@ -152,12 +152,12 @@ export const RichTextRenderer = memo(function RichTextRenderer<
>
{createElement(
renderBlock, {
block,
}, renderChildren(block.content.children, {
renderLeaf,
renderElement,
attributeNamePrefix,
}),
block,
}, renderChildren(block.content.children, {
renderLeaf,
renderElement,
attributeNamePrefix,
}),
)}
</RichTextRenderMetadataContext.Provider>
))}
Expand Down

0 comments on commit 903c5d7

Please sign in to comment.