Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow richtext renderer readonly props #630

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading