Skip to content

Commit

Permalink
Merge pull request #663 from contember/fix/richtext
Browse files Browse the repository at this point in the history
richtext fixes
  • Loading branch information
matej21 authored Jan 16, 2024
2 parents 7ddf4dd + e735501 commit 2c07cd9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createElement, ReactElement } from 'react'
import { createElement, isValidElement, ReactElement } from 'react'
import {
createEditor,
Descendant,
Expand Down Expand Up @@ -134,7 +134,7 @@ export const createEditorWithEssentials = (defaultElementType: string): Editor =
if (props.leaf[mark.type] === true) {
const markerEl = mark.render({ ...props, children: el })
if (markerEl !== null) {
if (!React.isValidElement(markerEl)) {
if (!isValidElement(markerEl)) {
throw new Error(`Mark plugin ${mark.type} returned a non-React element`)
}
el = markerEl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import { RichTextRendererError } from '../RichTextRendererError'
export const useRichTextBlocksSource = <CustomElements extends RichTextElement, CustomLeaves extends RichTextLeaf>({
deserialize = defaultDeserialize,
blocks,
referencesField = 'references',
sourceField = 'source',
referenceDiscriminationField = 'type',
referencesField,
sourceField,
referenceDiscriminationField,
}: RichTextBlockSource<CustomElements, CustomLeaves>) => {
return useMemo((): RichTextBlock<CustomElements, CustomLeaves>[] => {
const sourceFieldResolved = sourceField ?? 'source'
const referencesFieldResolved = referencesField ?? 'references'
const referenceDiscriminationFieldResolved = referenceDiscriminationField ?? 'type'

return blocks.map(block => {
if (!(sourceField in block)) {
if (!(sourceFieldResolved in block)) {
throw new RichTextRendererError(
`Found a block without a '${sourceFieldResolved}' field. ` +
(sourceField === undefined
Expand Down

0 comments on commit 2c07cd9

Please sign in to comment.