11import type { InlineObjectSchemaType } from '@portabletext/schema'
22import { isTextBlock } from '@portabletext/schema'
33import { useSelector } from '@xstate/react'
4- import { useContext , useMemo , useRef , type ReactElement } from 'react'
4+ import { useContext , useRef , type ReactElement } from 'react'
55import { serializePath } from '../paths/serialize-path'
66import type { RenderLeafProps } from '../slate/react/components/editable'
77import { useSlateStatic } from '../slate/react/hooks/use-slate-static'
@@ -40,22 +40,10 @@ export function RenderSpan(props: RenderSpanProps) {
4040 ? parent
4141 : undefined
4242
43- const path = useMemo (
44- ( ) =>
45- block
46- ? [ { _key : block . _key } , 'children' , { _key : props . leaf . _key } ]
47- : undefined ,
48- [ block , props . leaf . _key ] ,
49- )
50-
5143 const selectionState = useContext ( SelectionStateContext )
52- const serializedPath = path ? serializePath ( path ) : undefined
53- const focused = serializedPath
54- ? selectionState . focusedChildPath === serializedPath
55- : false
56- const selected = serializedPath
57- ? selectionState . selectedChildPaths . has ( serializedPath )
58- : false
44+ const serializedPath = serializePath ( props . path )
45+ const focused = selectionState . focusedChildPath === serializedPath
46+ const selected = selectionState . selectedChildPaths . has ( serializedPath )
5947
6048 const decoratorSchemaTypes = editorActor
6149 . getSnapshot ( )
@@ -95,13 +83,13 @@ export function RenderSpan(props: RenderSpanProps) {
9583 ( dec ) => dec . name === mark ,
9684 )
9785
98- if ( path && decoratorSchemaType && props . renderDecorator ) {
86+ if ( decoratorSchemaType && props . renderDecorator ) {
9987 children = (
10088 < RenderDecorator
10189 renderDecorator = { props . renderDecorator }
10290 editorElementRef = { spanRef }
10391 focused = { focused }
104- path = { path }
92+ path = { props . path }
10593 selected = { selected }
10694 schemaType = { decoratorSchemaType }
10795 value = { mark }
@@ -120,15 +108,15 @@ export function RenderSpan(props: RenderSpanProps) {
120108 ( t ) => t . name === annotationMarkDef . _type ,
121109 )
122110 if ( annotationSchemaType ) {
123- if ( block && path && props . renderAnnotation ) {
111+ if ( block && props . renderAnnotation ) {
124112 children = (
125113 < span ref = { spanRef } >
126114 < RenderAnnotation
127115 renderAnnotation = { props . renderAnnotation }
128116 block = { block }
129117 editorElementRef = { spanRef }
130118 focused = { focused }
131- path = { path }
119+ path = { props . path }
132120 selected = { selected }
133121 schemaType = { annotationSchemaType }
134122 value = { annotationMarkDef }
@@ -146,7 +134,7 @@ export function RenderSpan(props: RenderSpanProps) {
146134 /**
147135 * Support `renderChild` render function for the Span itself
148136 */
149- if ( block && path && props . renderChild ) {
137+ if ( block && props . renderChild ) {
150138 const child = block . children . find (
151139 ( _child ) => _child . _key === props . leaf . _key ,
152140 ) // Ensure object equality
@@ -158,7 +146,7 @@ export function RenderSpan(props: RenderSpanProps) {
158146 annotations = { annotationMarkDefs }
159147 editorElementRef = { spanRef }
160148 focused = { focused }
161- path = { path }
149+ path = { props . path }
162150 schemaType = { schemaType }
163151 selected = { selected }
164152 value = { child }
0 commit comments