Skip to content

Commit

Permalink
fix: render default inline object as a span
Browse files Browse the repository at this point in the history
  • Loading branch information
christianhg committed Jan 31, 2025
1 parent 52cda8d commit e3821e2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 11 additions & 1 deletion packages/editor/src/editor/components/DefaultObject.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {PortableTextBlock, PortableTextChild} from '@sanity/types'

export function DefaultObject(props: {
export function DefaultBlockObject(props: {
value: PortableTextBlock | PortableTextChild
}) {
return (
Expand All @@ -9,3 +9,13 @@ export function DefaultObject(props: {
</div>
)
}

export function DefaultInlineObject(props: {
value: PortableTextBlock | PortableTextChild
}) {
return (
<span style={{userSelect: 'none'}}>
[{props.value._type}: {props.value._key}]
</span>
)
}
10 changes: 5 additions & 5 deletions packages/editor/src/editor/components/Element.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type {
RenderListItemFunction,
RenderStyleFunction,
} from '../../types/editor'
import {DefaultObject} from './DefaultObject'
import {DefaultBlockObject, DefaultInlineObject} from './DefaultObject'
import {DraggableBlock} from './DraggableBlock'

const debug = debugWithName('components:Element')
Expand Down Expand Up @@ -137,7 +137,7 @@ export const Element: FunctionComponent<ElementProps> = ({
{renderChild &&
renderChild({

Check warning on line 138 in packages/editor/src/editor/components/Element.tsx

View workflow job for this annotation

GitHub Actions / check-lint

Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef)
annotations: EMPTY_ANNOTATIONS, // These inline objects currently doesn't support annotations. This is a limitation of the current PT spec/model.
children: <DefaultObject value={value} />,
children: <DefaultInlineObject value={value} />,
editorElementRef: inlineBlockObjectRef,
focused,
path: elmPath,
Expand All @@ -146,7 +146,7 @@ export const Element: FunctionComponent<ElementProps> = ({
type: schemaType,
value: value as PortableTextChild,
})}
{!renderChild && <DefaultObject value={value} />}
{!renderChild && <DefaultInlineObject value={value} />}
</span>
</span>
)
Expand Down Expand Up @@ -280,7 +280,7 @@ export const Element: FunctionComponent<ElementProps> = ({
if (renderBlock) {
const _props: Omit<BlockRenderProps, 'type'> = Object.defineProperty(
{
children: <DefaultObject value={value} />,
children: <DefaultBlockObject value={value} />,
editorElementRef: blockRef,
focused,
path: blockPath,
Expand Down Expand Up @@ -310,7 +310,7 @@ export const Element: FunctionComponent<ElementProps> = ({
{renderedBlockFromProps ? (
renderedBlockFromProps
) : (
<DefaultObject value={value} />
<DefaultBlockObject value={value} />
)}
</div>
</DraggableBlock>
Expand Down

0 comments on commit e3821e2

Please sign in to comment.