@portabletext/editor 1.36.6 → 1.37.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.markdown.cjs +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +63 -4
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +1 -1
- package/lib/_chunks-es/editor-provider.js +67 -8
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/behaviors/index.d.cts +1 -0
- package/lib/behaviors/index.d.ts +1 -0
- package/lib/index.d.cts +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/plugins/index.cjs +1 -1
- package/lib/plugins/index.d.cts +1 -0
- package/lib/plugins/index.d.ts +1 -0
- package/lib/plugins/index.js +1 -1
- package/lib/selectors/index.cjs +69 -14
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +17 -0
- package/lib/selectors/index.d.ts +17 -0
- package/lib/selectors/index.js +63 -8
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.d.cts +1 -0
- package/lib/utils/index.d.ts +1 -0
- package/package.json +7 -7
- package/src/behavior-actions/behavior.action.decorator.add.ts +1 -0
- package/src/behavior-actions/behavior.action.delete.text.ts +1 -0
- package/src/behavior-actions/behavior.action.delete.ts +1 -3
- package/src/behavior-actions/behavior.action.insert-blocks.ts +66 -1
- package/src/editor/editor-machine.ts +16 -3
- package/src/editor/editor-selector.ts +1 -0
- package/src/editor/editor-snapshot.ts +4 -0
- package/src/internal-utils/create-test-snapshot.ts +1 -0
- package/src/selectors/index.ts +2 -0
- package/src/selectors/selector.get-focus-inline-object.ts +21 -0
- package/src/selectors/selector.is-overlapping-selection.test.ts +171 -0
- package/src/selectors/selector.is-overlapping-selection.ts +108 -4
- package/src/selectors/selector.is-point-after-selection.ts +3 -1
- package/src/selectors/selector.is-point-before-selection.ts +3 -1
- package/src/selectors/selector.is-selecting-entire-blocks.ts +34 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type {EditorSelection} from '../types/editor'
|
|
2
|
+
import {isEqualSelectionPoints} from '../utils'
|
|
2
3
|
import type {EditorSelector} from './../editor/editor-selector'
|
|
3
4
|
import {getSelectionEndPoint} from './selector.get-selection-end-point'
|
|
4
5
|
import {getSelectionStartPoint} from './selector.get-selection-start-point'
|
|
@@ -31,18 +32,121 @@ export function isOverlappingSelection(
|
|
|
31
32
|
},
|
|
32
33
|
})
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
const originalSelectionStartPoint = getSelectionStartPoint(snapshot)
|
|
36
|
+
const originalSelectionEndPoint = getSelectionEndPoint(snapshot)
|
|
37
|
+
|
|
38
|
+
if (
|
|
39
|
+
!selectionStartPoint ||
|
|
40
|
+
!selectionEndPoint ||
|
|
41
|
+
!originalSelectionStartPoint ||
|
|
42
|
+
!originalSelectionEndPoint
|
|
43
|
+
) {
|
|
35
44
|
return false
|
|
36
45
|
}
|
|
37
46
|
|
|
38
|
-
|
|
47
|
+
const startPointBeforeSelection =
|
|
48
|
+
isPointBeforeSelection(selectionStartPoint)(snapshot)
|
|
49
|
+
const startPointAfterSelection =
|
|
50
|
+
isPointAfterSelection(selectionStartPoint)(snapshot)
|
|
51
|
+
const endPointBeforeSelection =
|
|
52
|
+
isPointBeforeSelection(selectionEndPoint)(snapshot)
|
|
53
|
+
const endPointAfterSelection =
|
|
54
|
+
isPointAfterSelection(selectionEndPoint)(snapshot)
|
|
55
|
+
|
|
56
|
+
const originalStartPointBeforeStartPoint = isPointBeforeSelection(
|
|
57
|
+
originalSelectionStartPoint,
|
|
58
|
+
)({
|
|
59
|
+
...snapshot,
|
|
60
|
+
context: {
|
|
61
|
+
...snapshot.context,
|
|
62
|
+
selection: {
|
|
63
|
+
anchor: selectionStartPoint,
|
|
64
|
+
focus: selectionStartPoint,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
})
|
|
68
|
+
const originalStartPointAfterStartPoint = isPointAfterSelection(
|
|
69
|
+
originalSelectionStartPoint,
|
|
70
|
+
)({
|
|
71
|
+
...snapshot,
|
|
72
|
+
context: {
|
|
73
|
+
...snapshot.context,
|
|
74
|
+
selection: {
|
|
75
|
+
anchor: selectionStartPoint,
|
|
76
|
+
focus: selectionStartPoint,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
const originalEndPointBeforeEndPoint = isPointBeforeSelection(
|
|
82
|
+
originalSelectionEndPoint,
|
|
83
|
+
)({
|
|
84
|
+
...snapshot,
|
|
85
|
+
context: {
|
|
86
|
+
...snapshot.context,
|
|
87
|
+
selection: {
|
|
88
|
+
anchor: selectionEndPoint,
|
|
89
|
+
focus: selectionEndPoint,
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
})
|
|
93
|
+
const originalEndPointAfterEndPoint = isPointAfterSelection(
|
|
94
|
+
originalSelectionEndPoint,
|
|
95
|
+
)({
|
|
96
|
+
...snapshot,
|
|
97
|
+
context: {
|
|
98
|
+
...snapshot.context,
|
|
99
|
+
selection: {
|
|
100
|
+
anchor: selectionEndPoint,
|
|
101
|
+
focus: selectionEndPoint,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
const endPointEqualToOriginalStartPoint = isEqualSelectionPoints(
|
|
107
|
+
selectionEndPoint,
|
|
108
|
+
originalSelectionStartPoint,
|
|
109
|
+
)
|
|
110
|
+
const startPointEqualToOriginalEndPoint = isEqualSelectionPoints(
|
|
111
|
+
selectionStartPoint,
|
|
112
|
+
originalSelectionEndPoint,
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
if (endPointBeforeSelection && !endPointEqualToOriginalStartPoint) {
|
|
39
116
|
return false
|
|
40
117
|
}
|
|
41
118
|
|
|
42
|
-
if (!
|
|
119
|
+
if (startPointAfterSelection && !startPointEqualToOriginalEndPoint) {
|
|
43
120
|
return false
|
|
44
121
|
}
|
|
45
122
|
|
|
46
|
-
|
|
123
|
+
if (
|
|
124
|
+
!originalStartPointBeforeStartPoint &&
|
|
125
|
+
originalStartPointAfterStartPoint &&
|
|
126
|
+
!originalEndPointBeforeEndPoint &&
|
|
127
|
+
originalEndPointAfterEndPoint
|
|
128
|
+
) {
|
|
129
|
+
return !endPointEqualToOriginalStartPoint
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (
|
|
133
|
+
originalStartPointBeforeStartPoint &&
|
|
134
|
+
!originalStartPointAfterStartPoint &&
|
|
135
|
+
originalEndPointBeforeEndPoint &&
|
|
136
|
+
!originalEndPointAfterEndPoint
|
|
137
|
+
) {
|
|
138
|
+
return !startPointEqualToOriginalEndPoint
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (
|
|
142
|
+
!startPointAfterSelection ||
|
|
143
|
+
!startPointBeforeSelection ||
|
|
144
|
+
!endPointAfterSelection ||
|
|
145
|
+
!endPointBeforeSelection
|
|
146
|
+
) {
|
|
147
|
+
return true
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return false
|
|
47
151
|
}
|
|
48
152
|
}
|
|
@@ -14,7 +14,9 @@ export function isPointAfterSelection(
|
|
|
14
14
|
return false
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
const selection =
|
|
17
|
+
const selection = snapshot.context.selection.backward
|
|
18
|
+
? reverseSelection(snapshot.context.selection)
|
|
19
|
+
: snapshot.context.selection
|
|
18
20
|
|
|
19
21
|
const pointBlockKey = isKeySegment(point.path[0])
|
|
20
22
|
? point.path[0]._key
|
|
@@ -14,7 +14,9 @@ export function isPointBeforeSelection(
|
|
|
14
14
|
return false
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
const selection =
|
|
17
|
+
const selection = snapshot.context.selection.backward
|
|
18
|
+
? reverseSelection(snapshot.context.selection)
|
|
19
|
+
: snapshot.context.selection
|
|
18
20
|
|
|
19
21
|
const pointBlockKey = isKeySegment(point.path[0])
|
|
20
22
|
? point.path[0]._key
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type {EditorSelector} from '../editor/editor-selector'
|
|
2
|
+
import * as utils from '../utils'
|
|
3
|
+
import {getSelectionEndBlock, getSelectionStartBlock} from './selectors'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export const isSelectingEntireBlocks: EditorSelector<boolean> = (snapshot) => {
|
|
9
|
+
if (!snapshot.context.selection) {
|
|
10
|
+
return false
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const startPoint = snapshot.context.selection.backward
|
|
14
|
+
? snapshot.context.selection.focus
|
|
15
|
+
: snapshot.context.selection.anchor
|
|
16
|
+
const endPoint = snapshot.context.selection.backward
|
|
17
|
+
? snapshot.context.selection.anchor
|
|
18
|
+
: snapshot.context.selection.focus
|
|
19
|
+
|
|
20
|
+
const startBlock = getSelectionStartBlock(snapshot)
|
|
21
|
+
const endBlock = getSelectionEndBlock(snapshot)
|
|
22
|
+
|
|
23
|
+
if (!startBlock || !endBlock) {
|
|
24
|
+
return false
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const startBlockStartPoint = utils.getBlockStartPoint(startBlock)
|
|
28
|
+
const endBlockEndPoint = utils.getBlockEndPoint(endBlock)
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
utils.isEqualSelectionPoints(startBlockStartPoint, startPoint) &&
|
|
32
|
+
utils.isEqualSelectionPoints(endBlockEndPoint, endPoint)
|
|
33
|
+
)
|
|
34
|
+
}
|