@portabletext/editor 1.47.4 → 1.47.5
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 +5 -8
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +5 -8
- package/lib/index.js.map +1 -1
- package/package.json +3 -3
- package/src/editor/Editable.tsx +12 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "1.47.
|
|
3
|
+
"version": "1.47.5",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"slate-react": "0.112.1",
|
|
80
80
|
"use-effect-event": "^1.0.2",
|
|
81
81
|
"xstate": "^5.19.2",
|
|
82
|
-
"@portabletext/
|
|
83
|
-
"@portabletext/
|
|
82
|
+
"@portabletext/patches": "1.1.3",
|
|
83
|
+
"@portabletext/block-tools": "1.1.18"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@portabletext/toolkit": "^2.0.17",
|
package/src/editor/Editable.tsx
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
type MutableRefObject,
|
|
17
17
|
type TextareaHTMLAttributes,
|
|
18
18
|
} from 'react'
|
|
19
|
-
import {Transforms, type Text} from 'slate'
|
|
19
|
+
import {Editor, Transforms, type Text} from 'slate'
|
|
20
20
|
import {
|
|
21
21
|
ReactEditor,
|
|
22
22
|
Editable as SlateEditable,
|
|
@@ -59,6 +59,7 @@ import {EditorActorContext} from './editor-actor-context'
|
|
|
59
59
|
import {getEditorSnapshot} from './editor-selector'
|
|
60
60
|
import {usePortableTextEditor} from './hooks/usePortableTextEditor'
|
|
61
61
|
import {createWithHotkeys} from './plugins/createWithHotKeys'
|
|
62
|
+
import {PortableTextEditor} from './PortableTextEditor'
|
|
62
63
|
import {
|
|
63
64
|
createDecorate,
|
|
64
65
|
rangeDecorationsMachine,
|
|
@@ -570,17 +571,16 @@ export const PortableTextEditable = forwardRef<
|
|
|
570
571
|
onFocus(event)
|
|
571
572
|
}
|
|
572
573
|
if (!event.isDefaultPrevented()) {
|
|
574
|
+
const selection = PortableTextEditor.getSelection(portableTextEditor)
|
|
575
|
+
// Create an editor selection if it does'nt exist
|
|
576
|
+
if (selection === null) {
|
|
577
|
+
Transforms.select(slateEditor, Editor.start(slateEditor, []))
|
|
578
|
+
slateEditor.onChange()
|
|
579
|
+
}
|
|
573
580
|
editorActor.send({type: 'notify.focused', event})
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
schema: editorActor.getSnapshot().context.schema,
|
|
578
|
-
editor: slateEditor,
|
|
579
|
-
range: slateEditor.selection,
|
|
580
|
-
})
|
|
581
|
-
: null
|
|
582
|
-
|
|
583
|
-
if (selection) {
|
|
581
|
+
const newSelection = PortableTextEditor.getSelection(portableTextEditor)
|
|
582
|
+
// If the selection is the same, emit it explicitly here as there is no actual onChange event triggered.
|
|
583
|
+
if (selection === newSelection) {
|
|
584
584
|
editorActor.send({
|
|
585
585
|
type: 'notify.selection',
|
|
586
586
|
selection,
|
|
@@ -588,7 +588,7 @@ export const PortableTextEditable = forwardRef<
|
|
|
588
588
|
}
|
|
589
589
|
}
|
|
590
590
|
},
|
|
591
|
-
[editorActor, onFocus, slateEditor],
|
|
591
|
+
[editorActor, onFocus, slateEditor, portableTextEditor],
|
|
592
592
|
)
|
|
593
593
|
|
|
594
594
|
const handleClick = useCallback(
|