@portabletext/editor 1.52.2 → 1.52.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.cjs +8 -5
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +8 -5
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/editor/Editable.tsx +13 -12
package/package.json
CHANGED
package/src/editor/Editable.tsx
CHANGED
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
type MutableRefObject,
|
|
16
16
|
type TextareaHTMLAttributes,
|
|
17
17
|
} from 'react'
|
|
18
|
-
import {
|
|
18
|
+
import {Transforms, type Text} from 'slate'
|
|
19
19
|
import {
|
|
20
20
|
ReactEditor,
|
|
21
21
|
Editable as SlateEditable,
|
|
@@ -52,7 +52,6 @@ import {RenderText, type RenderTextProps} from './components/render-text'
|
|
|
52
52
|
import {EditorActorContext} from './editor-actor-context'
|
|
53
53
|
import {usePortableTextEditor} from './hooks/usePortableTextEditor'
|
|
54
54
|
import {createWithHotkeys} from './plugins/createWithHotKeys'
|
|
55
|
-
import {PortableTextEditor} from './PortableTextEditor'
|
|
56
55
|
import {
|
|
57
56
|
createDecorate,
|
|
58
57
|
rangeDecorationsMachine,
|
|
@@ -532,17 +531,19 @@ export const PortableTextEditable = forwardRef<
|
|
|
532
531
|
if (onFocus) {
|
|
533
532
|
onFocus(event)
|
|
534
533
|
}
|
|
534
|
+
|
|
535
535
|
if (!event.isDefaultPrevented()) {
|
|
536
|
-
const selection = PortableTextEditor.getSelection(portableTextEditor)
|
|
537
|
-
// Create an editor selection if it does'nt exist
|
|
538
|
-
if (selection === null) {
|
|
539
|
-
Transforms.select(slateEditor, Editor.start(slateEditor, []))
|
|
540
|
-
slateEditor.onChange()
|
|
541
|
-
}
|
|
542
536
|
relayActor.send({type: 'focused', event})
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
537
|
+
|
|
538
|
+
const selection = slateEditor.selection
|
|
539
|
+
? slateRangeToSelection({
|
|
540
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
541
|
+
editor: slateEditor,
|
|
542
|
+
range: slateEditor.selection,
|
|
543
|
+
})
|
|
544
|
+
: null
|
|
545
|
+
|
|
546
|
+
if (selection) {
|
|
546
547
|
editorActor.send({
|
|
547
548
|
type: 'update selection',
|
|
548
549
|
selection,
|
|
@@ -550,7 +551,7 @@ export const PortableTextEditable = forwardRef<
|
|
|
550
551
|
}
|
|
551
552
|
}
|
|
552
553
|
},
|
|
553
|
-
[editorActor, onFocus, slateEditor,
|
|
554
|
+
[editorActor, onFocus, slateEditor, relayActor],
|
|
554
555
|
)
|
|
555
556
|
|
|
556
557
|
const handleClick = useCallback(
|