@portabletext/editor 1.30.6 → 1.31.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.
- package/lib/_chunks-cjs/behavior.core.cjs +35 -2
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +4 -4
- package/lib/_chunks-cjs/plugin.event-listener.cjs +143 -170
- package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +5 -41
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +174 -6
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
- package/lib/_chunks-cjs/util.is-empty-text-block.cjs +1 -58
- package/lib/_chunks-cjs/util.is-empty-text-block.cjs.map +1 -1
- package/lib/_chunks-cjs/util.reverse-selection.cjs +105 -0
- package/lib/_chunks-cjs/util.reverse-selection.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +36 -3
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +2 -1
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/plugin.event-listener.js +143 -170
- package/lib/_chunks-es/plugin.event-listener.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +4 -41
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +170 -2
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/_chunks-es/util.is-empty-text-block.js +1 -59
- package/lib/_chunks-es/util.is-empty-text-block.js.map +1 -1
- package/lib/_chunks-es/util.reverse-selection.js +106 -1
- package/lib/_chunks-es/util.reverse-selection.js.map +1 -1
- package/lib/index.d.cts +0 -4
- package/lib/index.d.ts +0 -4
- package/lib/plugins/index.cjs +8 -8
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +0 -4
- package/lib/plugins/index.d.ts +0 -4
- package/lib/plugins/index.js +2 -3
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs +33 -6
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +209 -0
- package/lib/selectors/index.d.ts +209 -0
- package/lib/selectors/index.js +31 -5
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +10 -13
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.js +3 -6
- package/lib/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/src/behaviors/behavior.core.annotations.ts +32 -0
- package/src/behaviors/behavior.core.ts +1 -0
- package/src/editor/plugins/createWithEditableAPI.ts +1 -2
- package/src/editor/plugins/createWithUtils.ts +1 -52
- package/src/selectors/index.ts +4 -0
- package/src/selectors/selector.get-block-offsets.ts +33 -0
- package/src/selectors/selector.get-caret-word-selection.test.ts +288 -0
- package/src/selectors/selector.get-caret-word-selection.ts +116 -0
- package/src/selectors/selector.get-next-inline-object.ts +56 -0
- package/src/selectors/selector.get-previous-inline-object.ts +53 -0
- package/src/types/editor.ts +0 -5
- package/lib/_chunks-cjs/selector.get-selection-start-point.cjs +0 -15
- package/lib/_chunks-cjs/selector.get-selection-start-point.cjs.map +0 -1
- package/lib/_chunks-cjs/util.is-equal-selection-points.cjs +0 -46
- package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +0 -1
- package/lib/_chunks-es/selector.get-selection-start-point.js +0 -16
- package/lib/_chunks-es/selector.get-selection-start-point.js.map +0 -1
- package/lib/_chunks-es/util.is-equal-selection-points.js +0 -47
- package/lib/_chunks-es/util.is-equal-selection-points.js.map +0 -1
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type {EditorSelector} from '../editor/editor-selector'
|
|
2
|
+
import type {EditorSelection} from '../types/editor'
|
|
3
|
+
import {
|
|
4
|
+
blockOffsetToSpanSelectionPoint,
|
|
5
|
+
getBlockEndPoint,
|
|
6
|
+
getBlockStartPoint,
|
|
7
|
+
spanSelectionPointToBlockOffset,
|
|
8
|
+
type BlockOffset,
|
|
9
|
+
} from '../utils'
|
|
10
|
+
import {getNextInlineObject} from './selector.get-next-inline-object'
|
|
11
|
+
import {getPreviousInlineObject} from './selector.get-previous-inline-object'
|
|
12
|
+
import {getSelectionStartPoint} from './selector.get-selection-start-point'
|
|
13
|
+
import {getSelectionText} from './selector.get-selection-text'
|
|
14
|
+
import {isSelectionCollapsed} from './selector.is-selection-collapsed'
|
|
15
|
+
import {isSelectionExpanded} from './selector.is-selection-expanded'
|
|
16
|
+
import {getFocusTextBlock} from './selectors'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @public
|
|
20
|
+
* Returns the selection of the of the word the caret is placed in.
|
|
21
|
+
* Note: Only returns a word selection if the current selection is collapsed
|
|
22
|
+
*/
|
|
23
|
+
export const getCaretWordSelection: EditorSelector<EditorSelection> = ({
|
|
24
|
+
context,
|
|
25
|
+
}) => {
|
|
26
|
+
if (!context.selection) {
|
|
27
|
+
return null
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!isSelectionCollapsed({context})) {
|
|
31
|
+
return null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const focusTextBlock = getFocusTextBlock({context})
|
|
35
|
+
const selectionStartPoint = getSelectionStartPoint({context})
|
|
36
|
+
const selectionStartOffset = selectionStartPoint
|
|
37
|
+
? spanSelectionPointToBlockOffset({
|
|
38
|
+
value: context.value,
|
|
39
|
+
selectionPoint: selectionStartPoint,
|
|
40
|
+
})
|
|
41
|
+
: undefined
|
|
42
|
+
|
|
43
|
+
if (!focusTextBlock || !selectionStartPoint || !selectionStartOffset) {
|
|
44
|
+
return null
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const previousInlineObject = getPreviousInlineObject({context})
|
|
48
|
+
const blockStartPoint = getBlockStartPoint(focusTextBlock)
|
|
49
|
+
const textBefore = getSelectionText({
|
|
50
|
+
context: {
|
|
51
|
+
...context,
|
|
52
|
+
selection: {
|
|
53
|
+
anchor: previousInlineObject
|
|
54
|
+
? {path: previousInlineObject.path, offset: 0}
|
|
55
|
+
: blockStartPoint,
|
|
56
|
+
focus: selectionStartPoint,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
const textDirectlyBefore = textBefore.split(/\s+/).at(-1)
|
|
61
|
+
|
|
62
|
+
const nextInlineObject = getNextInlineObject({context})
|
|
63
|
+
const blockEndPoint = getBlockEndPoint(focusTextBlock)
|
|
64
|
+
const textAfter = getSelectionText({
|
|
65
|
+
context: {
|
|
66
|
+
...context,
|
|
67
|
+
selection: {
|
|
68
|
+
anchor: selectionStartPoint,
|
|
69
|
+
focus: nextInlineObject
|
|
70
|
+
? {path: nextInlineObject.path, offset: 0}
|
|
71
|
+
: blockEndPoint,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
})
|
|
75
|
+
const textDirectlyAfter = textAfter.split(/\s+/).at(0)
|
|
76
|
+
|
|
77
|
+
const caretWordStartOffset: BlockOffset = textDirectlyBefore
|
|
78
|
+
? {
|
|
79
|
+
...selectionStartOffset,
|
|
80
|
+
offset: selectionStartOffset.offset - textDirectlyBefore.length,
|
|
81
|
+
}
|
|
82
|
+
: selectionStartOffset
|
|
83
|
+
const caretWordEndOffset: BlockOffset = textDirectlyAfter
|
|
84
|
+
? {
|
|
85
|
+
...selectionStartOffset,
|
|
86
|
+
offset: selectionStartOffset.offset + textDirectlyAfter.length,
|
|
87
|
+
}
|
|
88
|
+
: selectionStartOffset
|
|
89
|
+
|
|
90
|
+
const caretWordStartSelectionPoint = blockOffsetToSpanSelectionPoint({
|
|
91
|
+
value: context.value,
|
|
92
|
+
blockOffset: caretWordStartOffset,
|
|
93
|
+
})
|
|
94
|
+
const caretWordEndSelectionPoint = blockOffsetToSpanSelectionPoint({
|
|
95
|
+
value: context.value,
|
|
96
|
+
blockOffset: caretWordEndOffset,
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
if (!caretWordStartSelectionPoint || !caretWordEndSelectionPoint) {
|
|
100
|
+
return null
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const caretWordSelection = {
|
|
104
|
+
anchor: caretWordStartSelectionPoint,
|
|
105
|
+
focus: caretWordEndSelectionPoint,
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return isSelectionExpanded({
|
|
109
|
+
context: {
|
|
110
|
+
...context,
|
|
111
|
+
selection: caretWordSelection,
|
|
112
|
+
},
|
|
113
|
+
})
|
|
114
|
+
? caretWordSelection
|
|
115
|
+
: null
|
|
116
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isKeySegment,
|
|
3
|
+
type KeyedSegment,
|
|
4
|
+
type PortableTextObject,
|
|
5
|
+
} from '@sanity/types'
|
|
6
|
+
import type {EditorSelector} from '../editor/editor-selector'
|
|
7
|
+
import {isSpan} from '../utils'
|
|
8
|
+
import {getSelectionEndPoint} from './selector.get-selection-end-point'
|
|
9
|
+
import {getFocusTextBlock} from './selectors'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export const getNextInlineObject: EditorSelector<
|
|
15
|
+
| {
|
|
16
|
+
node: PortableTextObject
|
|
17
|
+
path: [KeyedSegment, 'children', KeyedSegment]
|
|
18
|
+
}
|
|
19
|
+
| undefined
|
|
20
|
+
> = ({context}) => {
|
|
21
|
+
const focusTextBlock = getFocusTextBlock({context})
|
|
22
|
+
const selectionEndPoint = getSelectionEndPoint({context})
|
|
23
|
+
const selectionEndPointChildKey =
|
|
24
|
+
selectionEndPoint && isKeySegment(selectionEndPoint.path[2])
|
|
25
|
+
? selectionEndPoint.path[2]._key
|
|
26
|
+
: undefined
|
|
27
|
+
|
|
28
|
+
if (!focusTextBlock || !selectionEndPointChildKey) {
|
|
29
|
+
return undefined
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let endPointChildFound = false
|
|
33
|
+
let inlineObject:
|
|
34
|
+
| {
|
|
35
|
+
node: PortableTextObject
|
|
36
|
+
path: [KeyedSegment, 'children', KeyedSegment]
|
|
37
|
+
}
|
|
38
|
+
| undefined
|
|
39
|
+
|
|
40
|
+
for (const child of focusTextBlock.node.children) {
|
|
41
|
+
if (child._key === selectionEndPointChildKey) {
|
|
42
|
+
endPointChildFound = true
|
|
43
|
+
continue
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!isSpan(context, child) && endPointChildFound) {
|
|
47
|
+
inlineObject = {
|
|
48
|
+
node: child,
|
|
49
|
+
path: [...focusTextBlock.path, 'children', {_key: child._key}],
|
|
50
|
+
}
|
|
51
|
+
break
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return inlineObject
|
|
56
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isKeySegment,
|
|
3
|
+
type KeyedSegment,
|
|
4
|
+
type PortableTextObject,
|
|
5
|
+
} from '@sanity/types'
|
|
6
|
+
import type {EditorSelector} from '../editor/editor-selector'
|
|
7
|
+
import {isSpan} from '../utils'
|
|
8
|
+
import {getSelectionStartPoint} from './selector.get-selection-start-point'
|
|
9
|
+
import {getFocusTextBlock} from './selectors'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export const getPreviousInlineObject: EditorSelector<
|
|
15
|
+
| {
|
|
16
|
+
node: PortableTextObject
|
|
17
|
+
path: [KeyedSegment, 'children', KeyedSegment]
|
|
18
|
+
}
|
|
19
|
+
| undefined
|
|
20
|
+
> = ({context}) => {
|
|
21
|
+
const focusTextBlock = getFocusTextBlock({context})
|
|
22
|
+
const selectionStartPoint = getSelectionStartPoint({context})
|
|
23
|
+
const selectionStartPointChildKey =
|
|
24
|
+
selectionStartPoint && isKeySegment(selectionStartPoint.path[2])
|
|
25
|
+
? selectionStartPoint.path[2]._key
|
|
26
|
+
: undefined
|
|
27
|
+
|
|
28
|
+
if (!focusTextBlock || !selectionStartPointChildKey) {
|
|
29
|
+
return undefined
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let inlineObject:
|
|
33
|
+
| {
|
|
34
|
+
node: PortableTextObject
|
|
35
|
+
path: [KeyedSegment, 'children', KeyedSegment]
|
|
36
|
+
}
|
|
37
|
+
| undefined
|
|
38
|
+
|
|
39
|
+
for (const child of focusTextBlock.node.children) {
|
|
40
|
+
if (child._key === selectionStartPointChildKey) {
|
|
41
|
+
break
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!isSpan(context, child)) {
|
|
45
|
+
inlineObject = {
|
|
46
|
+
node: child,
|
|
47
|
+
path: [...focusTextBlock.path, 'children', {_key: child._key}],
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return inlineObject
|
|
53
|
+
}
|
package/src/types/editor.ts
CHANGED
|
@@ -134,11 +134,6 @@ export interface PortableTextSlateEditor extends ReactEditor {
|
|
|
134
134
|
isTextSpan: (value: unknown) => value is PortableTextSpan
|
|
135
135
|
isListBlock: (value: unknown) => value is PortableTextListBlock
|
|
136
136
|
|
|
137
|
-
/**
|
|
138
|
-
* Try to expand the current selection to a word
|
|
139
|
-
*/
|
|
140
|
-
pteExpandToWord: () => void
|
|
141
|
-
|
|
142
137
|
/**
|
|
143
138
|
* Use hotkeys
|
|
144
139
|
*/
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const getSelectionEndPoint = ({
|
|
3
|
-
context
|
|
4
|
-
}) => {
|
|
5
|
-
if (context.selection)
|
|
6
|
-
return context.selection.backward ? context.selection.anchor : context.selection.focus;
|
|
7
|
-
}, getSelectionStartPoint = ({
|
|
8
|
-
context
|
|
9
|
-
}) => {
|
|
10
|
-
if (context.selection)
|
|
11
|
-
return context.selection.backward ? context.selection.focus : context.selection.anchor;
|
|
12
|
-
};
|
|
13
|
-
exports.getSelectionEndPoint = getSelectionEndPoint;
|
|
14
|
-
exports.getSelectionStartPoint = getSelectionStartPoint;
|
|
15
|
-
//# sourceMappingURL=selector.get-selection-start-point.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selector.get-selection-start-point.cjs","sources":["../../src/selectors/selector.get-selection-end-point.ts","../../src/selectors/selector.get-selection-start-point.ts"],"sourcesContent":["import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectionEndPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n return context.selection.backward\n ? context.selection.anchor\n : context.selection.focus\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectionStartPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n return context.selection.backward\n ? context.selection.focus\n : context.selection.anchor\n}\n"],"names":["getSelectionEndPoint","context","selection","backward","anchor","focus","getSelectionStartPoint"],"mappings":";AAMO,MAAMA,uBAETA,CAAC;AAAA,EAACC;AAAO,MAAM;AACjB,MAAKA,QAAQC;AAIb,WAAOD,QAAQC,UAAUC,WACrBF,QAAQC,UAAUE,SAClBH,QAAQC,UAAUG;AACxB,GCVaC,yBAETA,CAAC;AAAA,EAACL;AAAO,MAAM;AACjB,MAAKA,QAAQC;AAIb,WAAOD,QAAQC,UAAUC,WACrBF,QAAQC,UAAUG,QAClBJ,QAAQC,UAAUE;AACxB;;;"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var types = require("@sanity/types");
|
|
3
|
-
function isKeyedSegment(segment) {
|
|
4
|
-
return typeof segment == "object" && segment !== null && "_key" in segment;
|
|
5
|
-
}
|
|
6
|
-
function getBlockEndPoint({
|
|
7
|
-
node,
|
|
8
|
-
path
|
|
9
|
-
}) {
|
|
10
|
-
if (types.isPortableTextTextBlock(node)) {
|
|
11
|
-
const lastChild = node.children[node.children.length - 1];
|
|
12
|
-
if (lastChild)
|
|
13
|
-
return {
|
|
14
|
-
path: [...path, "children", {
|
|
15
|
-
_key: lastChild._key
|
|
16
|
-
}],
|
|
17
|
-
offset: types.isPortableTextSpan(lastChild) ? lastChild.text.length : 0
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
return {
|
|
21
|
-
path,
|
|
22
|
-
offset: 0
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
function getBlockStartPoint({
|
|
26
|
-
node,
|
|
27
|
-
path
|
|
28
|
-
}) {
|
|
29
|
-
return types.isPortableTextTextBlock(node) ? {
|
|
30
|
-
path: [...path, "children", {
|
|
31
|
-
_key: node.children[0]._key
|
|
32
|
-
}],
|
|
33
|
-
offset: 0
|
|
34
|
-
} : {
|
|
35
|
-
path,
|
|
36
|
-
offset: 0
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
function isEqualSelectionPoints(a, b) {
|
|
40
|
-
return a.offset === b.offset && JSON.stringify(a.path) === JSON.stringify(b.path);
|
|
41
|
-
}
|
|
42
|
-
exports.getBlockEndPoint = getBlockEndPoint;
|
|
43
|
-
exports.getBlockStartPoint = getBlockStartPoint;
|
|
44
|
-
exports.isEqualSelectionPoints = isEqualSelectionPoints;
|
|
45
|
-
exports.isKeyedSegment = isKeyedSegment;
|
|
46
|
-
//# sourceMappingURL=util.is-equal-selection-points.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.is-equal-selection-points.cjs","sources":["../../src/utils/util.is-keyed-segment.ts","../../src/utils/util.get-block-end-point.ts","../../src/utils/util.get-block-start-point.ts","../../src/utils/util.is-equal-selection-points.ts"],"sourcesContent":["import type {KeyedSegment, PathSegment} from '@sanity/types'\n\n/**\n * @public\n */\nexport function isKeyedSegment(segment: PathSegment): segment is KeyedSegment {\n return typeof segment === 'object' && segment !== null && '_key' in segment\n}\n","import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getBlockEndPoint({\n node,\n path,\n}: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelectionPoint {\n if (isPortableTextTextBlock(node)) {\n const lastChild = node.children[node.children.length - 1]\n\n if (lastChild) {\n return {\n path: [...path, 'children', {_key: lastChild._key}],\n offset: isPortableTextSpan(lastChild) ? lastChild.text.length : 0,\n }\n }\n }\n\n return {\n path,\n offset: 0,\n }\n}\n","import {\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getBlockStartPoint({\n node,\n path,\n}: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelectionPoint {\n if (isPortableTextTextBlock(node)) {\n return {\n path: [...path, 'children', {_key: node.children[0]._key}],\n offset: 0,\n }\n }\n\n return {\n path,\n offset: 0,\n }\n}\n","import type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function isEqualSelectionPoints(\n a: EditorSelectionPoint,\n b: EditorSelectionPoint,\n) {\n return (\n a.offset === b.offset && JSON.stringify(a.path) === JSON.stringify(b.path)\n )\n}\n"],"names":["isKeyedSegment","segment","getBlockEndPoint","node","path","isPortableTextTextBlock","lastChild","children","length","_key","offset","isPortableTextSpan","text","getBlockStartPoint","isEqualSelectionPoints","a","b","JSON","stringify"],"mappings":";;AAKO,SAASA,eAAeC,SAA+C;AAC5E,SAAO,OAAOA,WAAY,YAAYA,YAAY,QAAQ,UAAUA;AACtE;ACIO,SAASC,iBAAiB;AAAA,EAC/BC;AAAAA,EACAC;AAIF,GAAyB;AACnBC,MAAAA,MAAAA,wBAAwBF,IAAI,GAAG;AACjC,UAAMG,YAAYH,KAAKI,SAASJ,KAAKI,SAASC,SAAS,CAAC;AAEpDF,QAAAA;AACK,aAAA;AAAA,QACLF,MAAM,CAAC,GAAGA,MAAM,YAAY;AAAA,UAACK,MAAMH,UAAUG;AAAAA,QAAAA,CAAK;AAAA,QAClDC,QAAQC,MAAmBL,mBAAAA,SAAS,IAAIA,UAAUM,KAAKJ,SAAS;AAAA,MAClE;AAAA,EAAA;AAIG,SAAA;AAAA,IACLJ;AAAAA,IACAM,QAAQ;AAAA,EACV;AACF;ACvBO,SAASG,mBAAmB;AAAA,EACjCV;AAAAA,EACAC;AAIF,GAAyB;AACnBC,SAAAA,MAAAA,wBAAwBF,IAAI,IACvB;AAAA,IACLC,MAAM,CAAC,GAAGA,MAAM,YAAY;AAAA,MAACK,MAAMN,KAAKI,SAAS,CAAC,EAAEE;AAAAA,IAAAA,CAAK;AAAA,IACzDC,QAAQ;AAAA,EAAA,IAIL;AAAA,IACLN;AAAAA,IACAM,QAAQ;AAAA,EACV;AACF;ACvBgBI,SAAAA,uBACdC,GACAC,GACA;AACA,SACED,EAAEL,WAAWM,EAAEN,UAAUO,KAAKC,UAAUH,EAAEX,IAAI,MAAMa,KAAKC,UAAUF,EAAEZ,IAAI;AAE7E;;;;;"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
const getSelectionEndPoint = ({
|
|
2
|
-
context
|
|
3
|
-
}) => {
|
|
4
|
-
if (context.selection)
|
|
5
|
-
return context.selection.backward ? context.selection.anchor : context.selection.focus;
|
|
6
|
-
}, getSelectionStartPoint = ({
|
|
7
|
-
context
|
|
8
|
-
}) => {
|
|
9
|
-
if (context.selection)
|
|
10
|
-
return context.selection.backward ? context.selection.focus : context.selection.anchor;
|
|
11
|
-
};
|
|
12
|
-
export {
|
|
13
|
-
getSelectionEndPoint,
|
|
14
|
-
getSelectionStartPoint
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=selector.get-selection-start-point.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selector.get-selection-start-point.js","sources":["../../src/selectors/selector.get-selection-end-point.ts","../../src/selectors/selector.get-selection-start-point.ts"],"sourcesContent":["import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectionEndPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n return context.selection.backward\n ? context.selection.anchor\n : context.selection.focus\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectionStartPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n return context.selection.backward\n ? context.selection.focus\n : context.selection.anchor\n}\n"],"names":["getSelectionEndPoint","context","selection","backward","anchor","focus","getSelectionStartPoint"],"mappings":"AAMO,MAAMA,uBAETA,CAAC;AAAA,EAACC;AAAO,MAAM;AACjB,MAAKA,QAAQC;AAIb,WAAOD,QAAQC,UAAUC,WACrBF,QAAQC,UAAUE,SAClBH,QAAQC,UAAUG;AACxB,GCVaC,yBAETA,CAAC;AAAA,EAACL;AAAO,MAAM;AACjB,MAAKA,QAAQC;AAIb,WAAOD,QAAQC,UAAUC,WACrBF,QAAQC,UAAUG,QAClBJ,QAAQC,UAAUE;AACxB;"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { isPortableTextTextBlock, isPortableTextSpan } from "@sanity/types";
|
|
2
|
-
function isKeyedSegment(segment) {
|
|
3
|
-
return typeof segment == "object" && segment !== null && "_key" in segment;
|
|
4
|
-
}
|
|
5
|
-
function getBlockEndPoint({
|
|
6
|
-
node,
|
|
7
|
-
path
|
|
8
|
-
}) {
|
|
9
|
-
if (isPortableTextTextBlock(node)) {
|
|
10
|
-
const lastChild = node.children[node.children.length - 1];
|
|
11
|
-
if (lastChild)
|
|
12
|
-
return {
|
|
13
|
-
path: [...path, "children", {
|
|
14
|
-
_key: lastChild._key
|
|
15
|
-
}],
|
|
16
|
-
offset: isPortableTextSpan(lastChild) ? lastChild.text.length : 0
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
return {
|
|
20
|
-
path,
|
|
21
|
-
offset: 0
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
function getBlockStartPoint({
|
|
25
|
-
node,
|
|
26
|
-
path
|
|
27
|
-
}) {
|
|
28
|
-
return isPortableTextTextBlock(node) ? {
|
|
29
|
-
path: [...path, "children", {
|
|
30
|
-
_key: node.children[0]._key
|
|
31
|
-
}],
|
|
32
|
-
offset: 0
|
|
33
|
-
} : {
|
|
34
|
-
path,
|
|
35
|
-
offset: 0
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function isEqualSelectionPoints(a, b) {
|
|
39
|
-
return a.offset === b.offset && JSON.stringify(a.path) === JSON.stringify(b.path);
|
|
40
|
-
}
|
|
41
|
-
export {
|
|
42
|
-
getBlockEndPoint,
|
|
43
|
-
getBlockStartPoint,
|
|
44
|
-
isEqualSelectionPoints,
|
|
45
|
-
isKeyedSegment
|
|
46
|
-
};
|
|
47
|
-
//# sourceMappingURL=util.is-equal-selection-points.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.is-equal-selection-points.js","sources":["../../src/utils/util.is-keyed-segment.ts","../../src/utils/util.get-block-end-point.ts","../../src/utils/util.get-block-start-point.ts","../../src/utils/util.is-equal-selection-points.ts"],"sourcesContent":["import type {KeyedSegment, PathSegment} from '@sanity/types'\n\n/**\n * @public\n */\nexport function isKeyedSegment(segment: PathSegment): segment is KeyedSegment {\n return typeof segment === 'object' && segment !== null && '_key' in segment\n}\n","import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getBlockEndPoint({\n node,\n path,\n}: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelectionPoint {\n if (isPortableTextTextBlock(node)) {\n const lastChild = node.children[node.children.length - 1]\n\n if (lastChild) {\n return {\n path: [...path, 'children', {_key: lastChild._key}],\n offset: isPortableTextSpan(lastChild) ? lastChild.text.length : 0,\n }\n }\n }\n\n return {\n path,\n offset: 0,\n }\n}\n","import {\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getBlockStartPoint({\n node,\n path,\n}: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelectionPoint {\n if (isPortableTextTextBlock(node)) {\n return {\n path: [...path, 'children', {_key: node.children[0]._key}],\n offset: 0,\n }\n }\n\n return {\n path,\n offset: 0,\n }\n}\n","import type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function isEqualSelectionPoints(\n a: EditorSelectionPoint,\n b: EditorSelectionPoint,\n) {\n return (\n a.offset === b.offset && JSON.stringify(a.path) === JSON.stringify(b.path)\n )\n}\n"],"names":["isKeyedSegment","segment","getBlockEndPoint","node","path","isPortableTextTextBlock","lastChild","children","length","_key","offset","isPortableTextSpan","text","getBlockStartPoint","isEqualSelectionPoints","a","b","JSON","stringify"],"mappings":";AAKO,SAASA,eAAeC,SAA+C;AAC5E,SAAO,OAAOA,WAAY,YAAYA,YAAY,QAAQ,UAAUA;AACtE;ACIO,SAASC,iBAAiB;AAAA,EAC/BC;AAAAA,EACAC;AAIF,GAAyB;AACnBC,MAAAA,wBAAwBF,IAAI,GAAG;AACjC,UAAMG,YAAYH,KAAKI,SAASJ,KAAKI,SAASC,SAAS,CAAC;AAEpDF,QAAAA;AACK,aAAA;AAAA,QACLF,MAAM,CAAC,GAAGA,MAAM,YAAY;AAAA,UAACK,MAAMH,UAAUG;AAAAA,QAAAA,CAAK;AAAA,QAClDC,QAAQC,mBAAmBL,SAAS,IAAIA,UAAUM,KAAKJ,SAAS;AAAA,MAClE;AAAA,EAAA;AAIG,SAAA;AAAA,IACLJ;AAAAA,IACAM,QAAQ;AAAA,EACV;AACF;ACvBO,SAASG,mBAAmB;AAAA,EACjCV;AAAAA,EACAC;AAIF,GAAyB;AACnBC,SAAAA,wBAAwBF,IAAI,IACvB;AAAA,IACLC,MAAM,CAAC,GAAGA,MAAM,YAAY;AAAA,MAACK,MAAMN,KAAKI,SAAS,CAAC,EAAEE;AAAAA,IAAAA,CAAK;AAAA,IACzDC,QAAQ;AAAA,EAAA,IAIL;AAAA,IACLN;AAAAA,IACAM,QAAQ;AAAA,EACV;AACF;ACvBgBI,SAAAA,uBACdC,GACAC,GACA;AACA,SACED,EAAEL,WAAWM,EAAEN,UAAUO,KAAKC,UAAUH,EAAEX,IAAI,MAAMa,KAAKC,UAAUF,EAAEZ,IAAI;AAE7E;"}
|