Skip to content

Commit

Permalink
[field] PT: Update PortableText component according to changes
Browse files Browse the repository at this point in the history
  • Loading branch information
skogsmaskin authored and rexxars committed Oct 6, 2020
1 parent a112bc5 commit 6451ebf
Showing 1 changed file with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import {startCase, uniq, xor} from 'lodash'
import {ArrayDiff, DiffCard, ObjectDiff, StringDiff} from '../../../../diff'

import {ObjectSchemaType, SchemaType} from '../../../../types'
import {PortableTextBlock, PortableTextChild, PortableTextDiff, StringSegment} from '../types'
import {
PortableTextBlock,
PortableTextChild,
PortableTextDiff,
SpanTypeSchema,
StringSegment
} from '../types'

import * as TextSymbols from '../symbols'

Expand All @@ -18,7 +24,7 @@ import {
} from '../helpers'

import Block from './Block'
import Annotation from './Annotation'
import {Annotation} from './Annotation'
import Decorator from './Decorator'
import {InlineObject} from './InlineObject'

Expand Down Expand Up @@ -102,9 +108,6 @@ export default function PortableText(props: Props): JSX.Element {
if (key) {
const objectSchemaType = getChildSchemaType(schemaType.fields, originChild)
const objectDiff = findChildDiff(diff.origin, originChild)
if (!objectSchemaType) {
throw new Error('Schema type required')
}
returnedChildren.push(
<InlineObject
key={`inline-object-${originChild._key}`}
Expand Down Expand Up @@ -152,7 +155,7 @@ function renderTextSegment({
child: PortableTextChild
decoratorTypes: {title: string; value: string}[]
seg: StringSegment
spanSchemaType: SchemaType
spanSchemaType: SpanTypeSchema
}): JSX.Element {
// Newlines
if (seg.text === '\n') {
Expand Down Expand Up @@ -217,7 +220,25 @@ function renderTextSegment({
if (isDecorator(mark, spanSchemaType)) {
children = <Decorator mark={mark}>{children}</Decorator>
} else {
children = <Annotation diff={findAnnotationDiff(diff.origin, mark)}>{children}</Annotation>
const annotationDiff = findAnnotationDiff(diff.origin, mark)
const annotationObject =
annotationDiff &&
((annotationDiff.toValue || annotationDiff.fromValue) as PortableTextChild)
const objectSchemaType =
annotationObject &&
spanSchemaType.annotations &&
spanSchemaType.annotations.find(type => type.name === annotationObject._type)
if (annotationObject) {
children = (
<Annotation
object={annotationObject}
diff={annotationDiff}
schemaType={objectSchemaType}
>
{children}
</Annotation>
)
}
}
})
}
Expand Down

0 comments on commit 6451ebf

Please sign in to comment.