@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.52.2",
3
+ "version": "1.52.3",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -15,7 +15,7 @@ import {
15
15
  type MutableRefObject,
16
16
  type TextareaHTMLAttributes,
17
17
  } from 'react'
18
- import {Editor, Transforms, type Text} from 'slate'
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
- const newSelection = PortableTextEditor.getSelection(portableTextEditor)
544
- // If the selection is the same, emit it explicitly here as there is no actual onChange event triggered.
545
- if (selection === newSelection) {
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, portableTextEditor, relayActor],
554
+ [editorActor, onFocus, slateEditor, relayActor],
554
555
  )
555
556
 
556
557
  const handleClick = useCallback(