@portabletext/editor 2.13.6 → 2.14.0

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.
@@ -0,0 +1,50 @@
1
+ import {isSpan} from '@portabletext/schema'
2
+ import {isKeySegment, type PortableTextObject} from '@sanity/types'
3
+ import type {EditorSelector} from '../editor/editor-selector'
4
+ import type {ChildPath} from '../types/paths'
5
+ import {getFocusTextBlock} from './selector.get-focus-text-block'
6
+ import {getSelectionEndPoint} from './selector.get-selection-end-point'
7
+
8
+ /**
9
+ * @public
10
+ */
11
+ export const getNextInlineObjects: EditorSelector<
12
+ Array<{
13
+ node: PortableTextObject
14
+ path: ChildPath
15
+ }>
16
+ > = (snapshot) => {
17
+ const focusTextBlock = getFocusTextBlock(snapshot)
18
+ const selectionEndPoint = getSelectionEndPoint(snapshot)
19
+ const selectionEndPointChildKey =
20
+ selectionEndPoint && isKeySegment(selectionEndPoint.path[2])
21
+ ? selectionEndPoint.path[2]._key
22
+ : undefined
23
+
24
+ if (!focusTextBlock || !selectionEndPointChildKey) {
25
+ return []
26
+ }
27
+
28
+ let endPointChildFound = false
29
+ const inlineObjects: Array<{
30
+ node: PortableTextObject
31
+ path: ChildPath
32
+ }> = []
33
+
34
+ for (const child of focusTextBlock.node.children) {
35
+ if (child._key === selectionEndPointChildKey) {
36
+ endPointChildFound = true
37
+ continue
38
+ }
39
+
40
+ if (!isSpan(snapshot.context, child) && endPointChildFound) {
41
+ inlineObjects.push({
42
+ node: child,
43
+ path: [...focusTextBlock.path, 'children', {_key: child._key}],
44
+ })
45
+ break
46
+ }
47
+ }
48
+
49
+ return inlineObjects
50
+ }
@@ -0,0 +1,47 @@
1
+ import {isSpan} from '@portabletext/schema'
2
+ import {isKeySegment, type PortableTextObject} from '@sanity/types'
3
+ import type {EditorSelector} from '../editor/editor-selector'
4
+ import type {ChildPath} from '../types/paths'
5
+ import {getFocusTextBlock} from './selector.get-focus-text-block'
6
+ import {getSelectionStartPoint} from './selector.get-selection-start-point'
7
+
8
+ /**
9
+ * @public
10
+ */
11
+ export const getPreviousInlineObjects: EditorSelector<
12
+ Array<{
13
+ node: PortableTextObject
14
+ path: ChildPath
15
+ }>
16
+ > = (snapshot) => {
17
+ const focusTextBlock = getFocusTextBlock(snapshot)
18
+ const selectionStartPoint = getSelectionStartPoint(snapshot)
19
+ const selectionStartPointChildKey =
20
+ selectionStartPoint && isKeySegment(selectionStartPoint.path[2])
21
+ ? selectionStartPoint.path[2]._key
22
+ : undefined
23
+
24
+ if (!focusTextBlock || !selectionStartPointChildKey) {
25
+ return []
26
+ }
27
+
28
+ const inlineObjects: Array<{
29
+ node: PortableTextObject
30
+ path: ChildPath
31
+ }> = []
32
+
33
+ for (const child of focusTextBlock.node.children) {
34
+ if (child._key === selectionStartPointChildKey) {
35
+ break
36
+ }
37
+
38
+ if (!isSpan(snapshot.context, child)) {
39
+ inlineObjects.push({
40
+ node: child,
41
+ path: [...focusTextBlock.path, 'children', {_key: child._key}],
42
+ })
43
+ }
44
+ }
45
+
46
+ return inlineObjects
47
+ }