@portabletext/editor 1.44.3 → 1.44.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.
@@ -12,12 +12,16 @@ export function getFocusBlock({
12
12
  return [undefined, undefined]
13
13
  }
14
14
 
15
- return (
16
- Editor.node(editor, editor.selection.focus.path.slice(0, 1)) ?? [
17
- undefined,
18
- undefined,
19
- ]
20
- )
15
+ try {
16
+ return (
17
+ Editor.node(editor, editor.selection.focus.path.slice(0, 1)) ?? [
18
+ undefined,
19
+ undefined,
20
+ ]
21
+ )
22
+ } catch {
23
+ return [undefined, undefined]
24
+ }
21
25
  }
22
26
 
23
27
  function getPointBlock({
@@ -27,11 +31,15 @@ function getPointBlock({
27
31
  editor: PortableTextSlateEditor
28
32
  point: Point
29
33
  }): [node: Node, path: Path] | [undefined, undefined] {
30
- const [block] = Editor.node(editor, point.path.slice(0, 1)) ?? [
31
- undefined,
32
- undefined,
33
- ]
34
- return block ? [block, point.path] : [undefined, undefined]
34
+ try {
35
+ const [block] = Editor.node(editor, point.path.slice(0, 1)) ?? [
36
+ undefined,
37
+ undefined,
38
+ ]
39
+ return block ? [block, point.path] : [undefined, undefined]
40
+ } catch {
41
+ return [undefined, undefined]
42
+ }
35
43
  }
36
44
 
37
45
  export function getFocusChild({
@@ -46,11 +54,15 @@ export function getFocusChild({
46
54
  return [undefined, undefined]
47
55
  }
48
56
 
49
- const focusChild = Node.child(focusBlock, childIndex)
57
+ try {
58
+ const focusChild = Node.child(focusBlock, childIndex)
50
59
 
51
- return focusChild
52
- ? [focusChild, [...focusBlockPath, childIndex]]
53
- : [undefined, undefined]
60
+ return focusChild
61
+ ? [focusChild, [...focusBlockPath, childIndex]]
62
+ : [undefined, undefined]
63
+ } catch {
64
+ return [undefined, undefined]
65
+ }
54
66
  }
55
67
 
56
68
  function getPointChild({
@@ -86,9 +98,13 @@ export function getFirstBlock({
86
98
  const firstPoint = Editor.start(editor, [])
87
99
  const firstBlockPath = firstPoint.path.at(0)
88
100
 
89
- return firstBlockPath !== undefined
90
- ? (Editor.node(editor, [firstBlockPath]) ?? [undefined, undefined])
91
- : [undefined, undefined]
101
+ try {
102
+ return firstBlockPath !== undefined
103
+ ? (Editor.node(editor, [firstBlockPath]) ?? [undefined, undefined])
104
+ : [undefined, undefined]
105
+ } catch {
106
+ return [undefined, undefined]
107
+ }
92
108
  }
93
109
 
94
110
  export function getLastBlock({
@@ -98,9 +114,14 @@ export function getLastBlock({
98
114
  }): [node: Node, path: Path] | [undefined, undefined] {
99
115
  const lastPoint = Editor.end(editor, [])
100
116
  const lastBlockPath = lastPoint.path.at(0)
101
- return lastBlockPath !== undefined
102
- ? (Editor.node(editor, [lastBlockPath]) ?? [undefined, undefined])
103
- : [undefined, undefined]
117
+
118
+ try {
119
+ return lastBlockPath !== undefined
120
+ ? (Editor.node(editor, [lastBlockPath]) ?? [undefined, undefined])
121
+ : [undefined, undefined]
122
+ } catch {
123
+ return [undefined, undefined]
124
+ }
104
125
  }
105
126
 
106
127
  export function getNodeBlock({
@@ -1,32 +0,0 @@
1
- import type {BaseEditor, Operation} from 'slate'
2
- import type {ReactEditor} from 'slate-react'
3
- import type {PortableTextSlateEditor} from '../types/editor'
4
- import type {EditorActor} from './editor-machine'
5
-
6
- // React Compiler considers `slateEditor` as immutable, and opts-out if we do this inline in a useEffect, doing it in a function moves it out of the scope, and opts-in again for the rest of the component.
7
- export function withSyncRangeDecorations({
8
- editorActor,
9
- slateEditor,
10
- syncRangeDecorations,
11
- }: {
12
- editorActor: EditorActor
13
- slateEditor: BaseEditor & ReactEditor & PortableTextSlateEditor
14
- syncRangeDecorations: (operation?: Operation) => void
15
- }) {
16
- const originalApply = slateEditor.apply
17
-
18
- slateEditor.apply = (op: Operation) => {
19
- originalApply(op)
20
-
21
- if (
22
- !editorActor.getSnapshot().matches({'edit mode': 'read only'}) &&
23
- op.type !== 'set_selection'
24
- ) {
25
- syncRangeDecorations(op)
26
- }
27
- }
28
-
29
- return () => {
30
- slateEditor.apply = originalApply
31
- }
32
- }