@portabletext/editor 1.48.7 → 1.48.8
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 +20 -8
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +5 -5
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +121 -90
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs +2 -2
- package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +7 -4
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +63 -47
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +29 -23
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs +3 -3
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +15 -15
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs +258 -38
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +21 -10
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +5 -6
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +75 -46
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/selector.get-focus-inline-object.js +1 -2
- package/lib/_chunks-es/selector.get-focus-inline-object.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +7 -4
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-overlapping-selection.js +61 -46
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +30 -26
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/util.merge-text-blocks.js +1 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js +15 -16
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js +258 -38
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/behaviors/index.d.cts +2552 -251
- package/lib/behaviors/index.d.ts +2552 -251
- package/lib/index.cjs +45 -21
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +2350 -51
- package/lib/index.d.ts +2350 -51
- package/lib/index.js +44 -21
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +16 -7
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +2324 -24
- package/lib/plugins/index.d.ts +2324 -24
- package/lib/plugins/index.js +16 -7
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs +5 -5
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +2321 -28
- package/lib/selectors/index.d.ts +2321 -28
- package/lib/selectors/index.js +5 -6
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +30 -24
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +2350 -44
- package/lib/utils/index.d.ts +2350 -44
- package/lib/utils/index.js +30 -24
- package/lib/utils/index.js.map +1 -1
- package/package.json +1 -2
- package/src/behavior-actions/behavior.action.block.unset.ts +1 -1
- package/src/behavior-actions/behavior.action.decorator.add.ts +20 -5
- package/src/behaviors/behavior.abstract.decorator.ts +1 -1
- package/src/behaviors/behavior.abstract.delete.ts +1 -1
- package/src/behaviors/behavior.abstract.insert.ts +2 -2
- package/src/behaviors/behavior.abstract.select.ts +16 -4
- package/src/behaviors/behavior.abstract.split.ts +9 -6
- package/src/behaviors/behavior.core.block-objects.ts +5 -5
- package/src/behaviors/behavior.core.insert-break.ts +16 -4
- package/src/behaviors/behavior.core.lists.ts +4 -6
- package/src/behaviors/behavior.decorator-pair.ts +13 -4
- package/src/behaviors/behavior.default.ts +1 -1
- package/src/behaviors/behavior.markdown.ts +5 -5
- package/src/converters/converter.portable-text.ts +1 -1
- package/src/converters/converter.text-html.ts +1 -1
- package/src/converters/converter.text-plain.ts +4 -4
- package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +10 -2
- package/src/editor/plugins/createWithSchemaTypes.ts +12 -19
- package/src/internal-utils/__tests__/dmpToOperations.test.ts +13 -12
- package/src/internal-utils/drag-selection.ts +16 -4
- package/src/internal-utils/event-position.ts +20 -8
- package/src/internal-utils/parse-blocks.ts +17 -5
- package/src/internal-utils/validateValue.ts +6 -6
- package/src/plugins/plugin.decorator-shortcut.ts +2 -2
- package/src/selectors/selector.get-active-annotations.ts +5 -2
- package/src/selectors/selector.get-active-list-item.ts +4 -3
- package/src/selectors/selector.get-active-style.ts +4 -3
- package/src/selectors/selector.get-anchor-text-block.ts +3 -6
- package/src/selectors/selector.get-block-offsets.ts +2 -2
- package/src/selectors/selector.get-caret-word-selection.ts +11 -5
- package/src/selectors/selector.get-selected-slice.ts +1 -1
- package/src/selectors/selector.get-selected-spans.ts +11 -15
- package/src/selectors/selector.get-selected-text-blocks.ts +3 -3
- package/src/selectors/selector.get-selection-text.ts +3 -3
- package/src/selectors/selector.get-text-before.ts +5 -2
- package/src/selectors/selector.get-trimmed-selection.ts +20 -14
- package/src/selectors/selector.is-active-annotation.ts +4 -2
- package/src/selectors/selector.is-active-decorator.test.ts +3 -3
- package/src/selectors/selector.is-at-the-end-of-block.ts +4 -1
- package/src/selectors/selector.is-at-the-start-of-block.ts +4 -1
- package/src/selectors/selector.is-point-after-selection.ts +7 -6
- package/src/selectors/selector.is-point-before-selection.ts +7 -6
- package/src/selectors/selector.is-selecting-entire-blocks.ts +8 -2
- package/src/selectors/selectors.ts +25 -28
- package/src/utils/util.block-offset-to-block-selection-point.ts +4 -4
- package/src/utils/util.block-offset-to-selection-point.ts +5 -5
- package/src/utils/util.block-offset.test.ts +219 -156
- package/src/utils/util.block-offset.ts +14 -17
- package/src/utils/util.block-offsets-to-selection.ts +5 -5
- package/src/utils/util.child-selection-point-to-block-offset.ts +7 -10
- package/src/utils/util.get-block-end-point.ts +15 -15
- package/src/utils/util.get-block-start-point.ts +13 -12
- package/src/utils/util.is-empty-text-block.ts +9 -8
- package/src/utils/util.selection-point-to-block-offset.ts +4 -4
- package/src/utils/util.slice-blocks.test.ts +178 -121
- package/src/utils/util.slice-blocks.ts +25 -24
- package/src/utils/util.split-text-block.ts +18 -12
- package/lib/_chunks-cjs/parse-blocks.cjs +0 -205
- package/lib/_chunks-cjs/parse-blocks.cjs.map +0 -1
- package/lib/_chunks-es/parse-blocks.js +0 -206
- package/lib/_chunks-es/parse-blocks.js.map +0 -1
- package/src/behavior-actions/behavior.guards.ts +0 -24
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type {PortableTextBlock} from '@sanity/types'
|
|
2
2
|
import {expect, test} from 'vitest'
|
|
3
|
+
import {compileSchemaDefinition, defineSchema} from '../editor/editor-schema'
|
|
3
4
|
import {blockOffsetToSpanSelectionPoint} from './util.block-offset'
|
|
4
5
|
|
|
6
|
+
const schema = compileSchemaDefinition(defineSchema({}))
|
|
7
|
+
|
|
5
8
|
test(blockOffsetToSpanSelectionPoint.name, () => {
|
|
6
9
|
const value: Array<PortableTextBlock> = [
|
|
7
10
|
{
|
|
@@ -67,17 +70,20 @@ test(blockOffsetToSpanSelectionPoint.name, () => {
|
|
|
67
70
|
|
|
68
71
|
expect(
|
|
69
72
|
blockOffsetToSpanSelectionPoint({
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
73
|
+
context: {
|
|
74
|
+
schema,
|
|
75
|
+
value: [
|
|
76
|
+
{
|
|
77
|
+
_key: 'b0',
|
|
78
|
+
_type: 'block',
|
|
79
|
+
children: [
|
|
80
|
+
{_key: 's0', _type: 'span', text: 'b'},
|
|
81
|
+
{_key: 's1', _type: 'span', text: 'a'},
|
|
82
|
+
{_key: 's2', _type: 'span', text: 'r'},
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
},
|
|
81
87
|
blockOffset: {
|
|
82
88
|
path: [{_key: 'b0'}],
|
|
83
89
|
offset: 3,
|
|
@@ -90,17 +96,20 @@ test(blockOffsetToSpanSelectionPoint.name, () => {
|
|
|
90
96
|
})
|
|
91
97
|
expect(
|
|
92
98
|
blockOffsetToSpanSelectionPoint({
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
context: {
|
|
100
|
+
schema,
|
|
101
|
+
value: [
|
|
102
|
+
{
|
|
103
|
+
_key: 'b0',
|
|
104
|
+
_type: 'block',
|
|
105
|
+
children: [
|
|
106
|
+
{_key: 's0', _type: 'span', text: 'b'},
|
|
107
|
+
{_key: 's1', _type: 'span', text: 'a'},
|
|
108
|
+
{_key: 's2', _type: 'span', text: 'r'},
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
},
|
|
104
113
|
blockOffset: {
|
|
105
114
|
path: [{_key: 'b0'}],
|
|
106
115
|
offset: 0,
|
|
@@ -113,17 +122,20 @@ test(blockOffsetToSpanSelectionPoint.name, () => {
|
|
|
113
122
|
})
|
|
114
123
|
expect(
|
|
115
124
|
blockOffsetToSpanSelectionPoint({
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
context: {
|
|
126
|
+
schema,
|
|
127
|
+
value: [
|
|
128
|
+
{
|
|
129
|
+
_key: 'b0',
|
|
130
|
+
_type: 'block',
|
|
131
|
+
children: [
|
|
132
|
+
{_key: 's0', _type: 'span', text: 'b'},
|
|
133
|
+
{_key: 's1', _type: 'span', text: 'a'},
|
|
134
|
+
{_key: 's2', _type: 'span', text: 'r'},
|
|
135
|
+
],
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
},
|
|
127
139
|
blockOffset: {
|
|
128
140
|
path: [{_key: 'b0'}],
|
|
129
141
|
offset: 0,
|
|
@@ -136,17 +148,20 @@ test(blockOffsetToSpanSelectionPoint.name, () => {
|
|
|
136
148
|
})
|
|
137
149
|
expect(
|
|
138
150
|
blockOffsetToSpanSelectionPoint({
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
151
|
+
context: {
|
|
152
|
+
schema,
|
|
153
|
+
value: [
|
|
154
|
+
{
|
|
155
|
+
_key: 'b0',
|
|
156
|
+
_type: 'block',
|
|
157
|
+
children: [
|
|
158
|
+
{_key: 's0', _type: 'span', text: 'b'},
|
|
159
|
+
{_key: 's1', _type: 'span', text: 'a'},
|
|
160
|
+
{_key: 's2', _type: 'span', text: 'r'},
|
|
161
|
+
],
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
},
|
|
150
165
|
blockOffset: {
|
|
151
166
|
path: [{_key: 'b0'}],
|
|
152
167
|
offset: 3,
|
|
@@ -159,7 +174,10 @@ test(blockOffsetToSpanSelectionPoint.name, () => {
|
|
|
159
174
|
})
|
|
160
175
|
expect(
|
|
161
176
|
blockOffsetToSpanSelectionPoint({
|
|
162
|
-
|
|
177
|
+
context: {
|
|
178
|
+
schema,
|
|
179
|
+
value,
|
|
180
|
+
},
|
|
163
181
|
blockOffset: {
|
|
164
182
|
path: [{_key: 'b1'}],
|
|
165
183
|
offset: 0,
|
|
@@ -169,7 +187,10 @@ test(blockOffsetToSpanSelectionPoint.name, () => {
|
|
|
169
187
|
).toBeUndefined()
|
|
170
188
|
expect(
|
|
171
189
|
blockOffsetToSpanSelectionPoint({
|
|
172
|
-
|
|
190
|
+
context: {
|
|
191
|
+
schema,
|
|
192
|
+
value,
|
|
193
|
+
},
|
|
173
194
|
blockOffset: {
|
|
174
195
|
path: [{_key: 'b2'}],
|
|
175
196
|
offset: 9,
|
|
@@ -182,7 +203,10 @@ test(blockOffsetToSpanSelectionPoint.name, () => {
|
|
|
182
203
|
})
|
|
183
204
|
expect(
|
|
184
205
|
blockOffsetToSpanSelectionPoint({
|
|
185
|
-
|
|
206
|
+
context: {
|
|
207
|
+
schema,
|
|
208
|
+
value,
|
|
209
|
+
},
|
|
186
210
|
blockOffset: {
|
|
187
211
|
path: [{_key: 'b3'}],
|
|
188
212
|
offset: 9,
|
|
@@ -195,7 +219,10 @@ test(blockOffsetToSpanSelectionPoint.name, () => {
|
|
|
195
219
|
})
|
|
196
220
|
expect(
|
|
197
221
|
blockOffsetToSpanSelectionPoint({
|
|
198
|
-
|
|
222
|
+
context: {
|
|
223
|
+
schema,
|
|
224
|
+
value,
|
|
225
|
+
},
|
|
199
226
|
blockOffset: {
|
|
200
227
|
path: [{_key: 'b3'}],
|
|
201
228
|
offset: 10,
|
|
@@ -208,19 +235,22 @@ test(blockOffsetToSpanSelectionPoint.name, () => {
|
|
|
208
235
|
})
|
|
209
236
|
expect(
|
|
210
237
|
blockOffsetToSpanSelectionPoint({
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
238
|
+
context: {
|
|
239
|
+
schema,
|
|
240
|
+
value: [
|
|
241
|
+
{
|
|
242
|
+
_key: 'b0',
|
|
243
|
+
_type: 'block',
|
|
244
|
+
children: [
|
|
245
|
+
{_key: 's0', _type: 'span', text: ''},
|
|
246
|
+
{_key: 's1', _type: 'stock-ticker'},
|
|
247
|
+
{_key: 's2', _type: 'span', text: 'foo'},
|
|
248
|
+
{_key: 's3', _type: 'stock-ticker'},
|
|
249
|
+
{_key: 's4', _type: 'span', text: ''},
|
|
250
|
+
],
|
|
251
|
+
},
|
|
252
|
+
],
|
|
253
|
+
},
|
|
224
254
|
blockOffset: {
|
|
225
255
|
path: [{_key: 'b0'}],
|
|
226
256
|
offset: 0,
|
|
@@ -233,19 +263,22 @@ test(blockOffsetToSpanSelectionPoint.name, () => {
|
|
|
233
263
|
})
|
|
234
264
|
expect(
|
|
235
265
|
blockOffsetToSpanSelectionPoint({
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
266
|
+
context: {
|
|
267
|
+
schema,
|
|
268
|
+
value: [
|
|
269
|
+
{
|
|
270
|
+
_key: 'b0',
|
|
271
|
+
_type: 'block',
|
|
272
|
+
children: [
|
|
273
|
+
{_key: 's0', _type: 'span', text: ''},
|
|
274
|
+
{_key: 's1', _type: 'stock-ticker'},
|
|
275
|
+
{_key: 's2', _type: 'span', text: 'foo'},
|
|
276
|
+
{_key: 's3', _type: 'stock-ticker'},
|
|
277
|
+
{_key: 's4', _type: 'span', text: ''},
|
|
278
|
+
],
|
|
279
|
+
},
|
|
280
|
+
],
|
|
281
|
+
},
|
|
249
282
|
blockOffset: {
|
|
250
283
|
path: [{_key: 'b0'}],
|
|
251
284
|
offset: 1,
|
|
@@ -258,19 +291,22 @@ test(blockOffsetToSpanSelectionPoint.name, () => {
|
|
|
258
291
|
})
|
|
259
292
|
expect(
|
|
260
293
|
blockOffsetToSpanSelectionPoint({
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
294
|
+
context: {
|
|
295
|
+
schema,
|
|
296
|
+
value: [
|
|
297
|
+
{
|
|
298
|
+
_key: 'b0',
|
|
299
|
+
_type: 'block',
|
|
300
|
+
children: [
|
|
301
|
+
{_key: 's0', _type: 'span', text: ''},
|
|
302
|
+
{_key: 's1', _type: 'stock-ticker'},
|
|
303
|
+
{_key: 's2', _type: 'span', text: 'foo'},
|
|
304
|
+
{_key: 's3', _type: 'stock-ticker'},
|
|
305
|
+
{_key: 's4', _type: 'span', text: ''},
|
|
306
|
+
],
|
|
307
|
+
},
|
|
308
|
+
],
|
|
309
|
+
},
|
|
274
310
|
blockOffset: {
|
|
275
311
|
path: [{_key: 'b0'}],
|
|
276
312
|
offset: 0,
|
|
@@ -283,19 +319,22 @@ test(blockOffsetToSpanSelectionPoint.name, () => {
|
|
|
283
319
|
})
|
|
284
320
|
expect(
|
|
285
321
|
blockOffsetToSpanSelectionPoint({
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
322
|
+
context: {
|
|
323
|
+
schema,
|
|
324
|
+
value: [
|
|
325
|
+
{
|
|
326
|
+
_key: 'b0',
|
|
327
|
+
_type: 'block',
|
|
328
|
+
children: [
|
|
329
|
+
{_key: 's0', _type: 'span', text: ''},
|
|
330
|
+
{_key: 's1', _type: 'stock-ticker'},
|
|
331
|
+
{_key: 's2', _type: 'span', text: 'foo'},
|
|
332
|
+
{_key: 's3', _type: 'stock-ticker'},
|
|
333
|
+
{_key: 's4', _type: 'span', text: ''},
|
|
334
|
+
],
|
|
335
|
+
},
|
|
336
|
+
],
|
|
337
|
+
},
|
|
299
338
|
blockOffset: {
|
|
300
339
|
path: [{_key: 'b0'}],
|
|
301
340
|
offset: 1,
|
|
@@ -308,19 +347,22 @@ test(blockOffsetToSpanSelectionPoint.name, () => {
|
|
|
308
347
|
})
|
|
309
348
|
expect(
|
|
310
349
|
blockOffsetToSpanSelectionPoint({
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
350
|
+
context: {
|
|
351
|
+
schema,
|
|
352
|
+
value: [
|
|
353
|
+
{
|
|
354
|
+
_key: 'b0',
|
|
355
|
+
_type: 'block',
|
|
356
|
+
children: [
|
|
357
|
+
{_key: 's0', _type: 'span', text: ''},
|
|
358
|
+
{_key: 's1', _type: 'stock-ticker'},
|
|
359
|
+
{_key: 's2', _type: 'span', text: 'foo'},
|
|
360
|
+
{_key: 's3', _type: 'stock-ticker'},
|
|
361
|
+
{_key: 's4', _type: 'span', text: ''},
|
|
362
|
+
],
|
|
363
|
+
},
|
|
364
|
+
],
|
|
365
|
+
},
|
|
324
366
|
blockOffset: {
|
|
325
367
|
path: [{_key: 'b0'}],
|
|
326
368
|
offset: 3,
|
|
@@ -333,19 +375,22 @@ test(blockOffsetToSpanSelectionPoint.name, () => {
|
|
|
333
375
|
})
|
|
334
376
|
expect(
|
|
335
377
|
blockOffsetToSpanSelectionPoint({
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
378
|
+
context: {
|
|
379
|
+
schema,
|
|
380
|
+
value: [
|
|
381
|
+
{
|
|
382
|
+
_key: 'b0',
|
|
383
|
+
_type: 'block',
|
|
384
|
+
children: [
|
|
385
|
+
{_key: 's0', _type: 'span', text: ''},
|
|
386
|
+
{_key: 's1', _type: 'stock-ticker'},
|
|
387
|
+
{_key: 's2', _type: 'span', text: 'foo'},
|
|
388
|
+
{_key: 's3', _type: 'stock-ticker'},
|
|
389
|
+
{_key: 's4', _type: 'span', text: ''},
|
|
390
|
+
],
|
|
391
|
+
},
|
|
392
|
+
],
|
|
393
|
+
},
|
|
349
394
|
blockOffset: {
|
|
350
395
|
path: [{_key: 'b0'}],
|
|
351
396
|
offset: 2,
|
|
@@ -358,19 +403,22 @@ test(blockOffsetToSpanSelectionPoint.name, () => {
|
|
|
358
403
|
})
|
|
359
404
|
expect(
|
|
360
405
|
blockOffsetToSpanSelectionPoint({
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
406
|
+
context: {
|
|
407
|
+
schema,
|
|
408
|
+
value: [
|
|
409
|
+
{
|
|
410
|
+
_key: 'b0',
|
|
411
|
+
_type: 'block',
|
|
412
|
+
children: [
|
|
413
|
+
{_key: 's0', _type: 'span', text: ''},
|
|
414
|
+
{_key: 's1', _type: 'stock-ticker'},
|
|
415
|
+
{_key: 's2', _type: 'span', text: 'foo'},
|
|
416
|
+
{_key: 's3', _type: 'stock-ticker'},
|
|
417
|
+
{_key: 's4', _type: 'span', text: ''},
|
|
418
|
+
],
|
|
419
|
+
},
|
|
420
|
+
],
|
|
421
|
+
},
|
|
374
422
|
blockOffset: {
|
|
375
423
|
path: [{_key: 'b0'}],
|
|
376
424
|
offset: 3,
|
|
@@ -383,19 +431,22 @@ test(blockOffsetToSpanSelectionPoint.name, () => {
|
|
|
383
431
|
})
|
|
384
432
|
expect(
|
|
385
433
|
blockOffsetToSpanSelectionPoint({
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
434
|
+
context: {
|
|
435
|
+
schema,
|
|
436
|
+
value: [
|
|
437
|
+
{
|
|
438
|
+
_key: 'b0',
|
|
439
|
+
_type: 'block',
|
|
440
|
+
children: [
|
|
441
|
+
{_key: 's0', _type: 'span', text: ''},
|
|
442
|
+
{_key: 's1', _type: 'stock-ticker'},
|
|
443
|
+
{_key: 's2', _type: 'span', text: 'foo'},
|
|
444
|
+
{_key: 's3', _type: 'stock-ticker'},
|
|
445
|
+
{_key: 's4', _type: 'span', text: ''},
|
|
446
|
+
],
|
|
447
|
+
},
|
|
448
|
+
],
|
|
449
|
+
},
|
|
399
450
|
blockOffset: {
|
|
400
451
|
path: [{_key: 'b0'}],
|
|
401
452
|
offset: 2,
|
|
@@ -408,7 +459,10 @@ test(blockOffsetToSpanSelectionPoint.name, () => {
|
|
|
408
459
|
})
|
|
409
460
|
expect(
|
|
410
461
|
blockOffsetToSpanSelectionPoint({
|
|
411
|
-
|
|
462
|
+
context: {
|
|
463
|
+
schema,
|
|
464
|
+
value,
|
|
465
|
+
},
|
|
412
466
|
blockOffset: {
|
|
413
467
|
path: [{_key: 'b3'}],
|
|
414
468
|
offset: 10,
|
|
@@ -421,7 +475,10 @@ test(blockOffsetToSpanSelectionPoint.name, () => {
|
|
|
421
475
|
})
|
|
422
476
|
expect(
|
|
423
477
|
blockOffsetToSpanSelectionPoint({
|
|
424
|
-
|
|
478
|
+
context: {
|
|
479
|
+
schema,
|
|
480
|
+
value,
|
|
481
|
+
},
|
|
425
482
|
blockOffset: {
|
|
426
483
|
path: [{_key: 'b3'}],
|
|
427
484
|
offset: 11,
|
|
@@ -434,7 +491,10 @@ test(blockOffsetToSpanSelectionPoint.name, () => {
|
|
|
434
491
|
})
|
|
435
492
|
expect(
|
|
436
493
|
blockOffsetToSpanSelectionPoint({
|
|
437
|
-
|
|
494
|
+
context: {
|
|
495
|
+
schema,
|
|
496
|
+
value,
|
|
497
|
+
},
|
|
438
498
|
blockOffset: {
|
|
439
499
|
path: [{_key: 'b4'}],
|
|
440
500
|
offset: 0,
|
|
@@ -444,7 +504,10 @@ test(blockOffsetToSpanSelectionPoint.name, () => {
|
|
|
444
504
|
).toBeUndefined()
|
|
445
505
|
expect(
|
|
446
506
|
blockOffsetToSpanSelectionPoint({
|
|
447
|
-
|
|
507
|
+
context: {
|
|
508
|
+
schema,
|
|
509
|
+
value,
|
|
510
|
+
},
|
|
448
511
|
blockOffset: {
|
|
449
512
|
path: [{_key: 'b4'}],
|
|
450
513
|
offset: 1,
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type KeyedSegment,
|
|
5
|
-
type PortableTextBlock,
|
|
6
|
-
} from '@sanity/types'
|
|
1
|
+
import type {KeyedSegment} from '@sanity/types'
|
|
2
|
+
import type {EditorContext} from '../editor/editor-snapshot'
|
|
3
|
+
import {isSpan, isTextBlock} from '../internal-utils/parse-blocks'
|
|
7
4
|
import type {BlockOffset} from '../types/block-offset'
|
|
8
5
|
import type {EditorSelectionPoint} from '../types/editor'
|
|
9
6
|
import {isKeyedSegment} from './util.is-keyed-segment'
|
|
@@ -12,11 +9,11 @@ import {isKeyedSegment} from './util.is-keyed-segment'
|
|
|
12
9
|
* @public
|
|
13
10
|
*/
|
|
14
11
|
export function blockOffsetToSpanSelectionPoint({
|
|
15
|
-
|
|
12
|
+
context,
|
|
16
13
|
blockOffset,
|
|
17
14
|
direction,
|
|
18
15
|
}: {
|
|
19
|
-
|
|
16
|
+
context: Pick<EditorContext, 'schema' | 'value'>
|
|
20
17
|
blockOffset: BlockOffset
|
|
21
18
|
direction: 'forward' | 'backward'
|
|
22
19
|
}) {
|
|
@@ -26,18 +23,18 @@ export function blockOffsetToSpanSelectionPoint({
|
|
|
26
23
|
| undefined
|
|
27
24
|
let skippedInlineObject = false
|
|
28
25
|
|
|
29
|
-
for (const block of value) {
|
|
26
|
+
for (const block of context.value) {
|
|
30
27
|
if (block._key !== blockOffset.path[0]._key) {
|
|
31
28
|
continue
|
|
32
29
|
}
|
|
33
30
|
|
|
34
|
-
if (!
|
|
31
|
+
if (!isTextBlock(context, block)) {
|
|
35
32
|
continue
|
|
36
33
|
}
|
|
37
34
|
|
|
38
35
|
for (const child of block.children) {
|
|
39
36
|
if (direction === 'forward') {
|
|
40
|
-
if (!
|
|
37
|
+
if (!isSpan(context, child)) {
|
|
41
38
|
continue
|
|
42
39
|
}
|
|
43
40
|
|
|
@@ -54,7 +51,7 @@ export function blockOffsetToSpanSelectionPoint({
|
|
|
54
51
|
continue
|
|
55
52
|
}
|
|
56
53
|
|
|
57
|
-
if (!
|
|
54
|
+
if (!isSpan(context, child)) {
|
|
58
55
|
skippedInlineObject = true
|
|
59
56
|
continue
|
|
60
57
|
}
|
|
@@ -96,10 +93,10 @@ export function blockOffsetToSpanSelectionPoint({
|
|
|
96
93
|
* @public
|
|
97
94
|
*/
|
|
98
95
|
export function spanSelectionPointToBlockOffset({
|
|
99
|
-
|
|
96
|
+
context,
|
|
100
97
|
selectionPoint,
|
|
101
98
|
}: {
|
|
102
|
-
|
|
99
|
+
context: Pick<EditorContext, 'schema' | 'value'>
|
|
103
100
|
selectionPoint: EditorSelectionPoint
|
|
104
101
|
}): BlockOffset | undefined {
|
|
105
102
|
let offset = 0
|
|
@@ -115,17 +112,17 @@ export function spanSelectionPointToBlockOffset({
|
|
|
115
112
|
return undefined
|
|
116
113
|
}
|
|
117
114
|
|
|
118
|
-
for (const block of value) {
|
|
115
|
+
for (const block of context.value) {
|
|
119
116
|
if (block._key !== blockKey) {
|
|
120
117
|
continue
|
|
121
118
|
}
|
|
122
119
|
|
|
123
|
-
if (!
|
|
120
|
+
if (!isTextBlock(context, block)) {
|
|
124
121
|
continue
|
|
125
122
|
}
|
|
126
123
|
|
|
127
124
|
for (const child of block.children) {
|
|
128
|
-
if (!
|
|
125
|
+
if (!isSpan(context, child)) {
|
|
129
126
|
continue
|
|
130
127
|
}
|
|
131
128
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {PortableTextBlock} from '@sanity/types'
|
|
2
1
|
import type {EditorSelection} from '..'
|
|
2
|
+
import type {EditorContext} from '../editor/editor-snapshot'
|
|
3
3
|
import type {BlockOffset} from '../types/block-offset'
|
|
4
4
|
import {blockOffsetToSelectionPoint} from './util.block-offset-to-selection-point'
|
|
5
5
|
|
|
@@ -7,21 +7,21 @@ import {blockOffsetToSelectionPoint} from './util.block-offset-to-selection-poin
|
|
|
7
7
|
* @public
|
|
8
8
|
*/
|
|
9
9
|
export function blockOffsetsToSelection({
|
|
10
|
-
|
|
10
|
+
context,
|
|
11
11
|
offsets,
|
|
12
12
|
backward,
|
|
13
13
|
}: {
|
|
14
|
-
|
|
14
|
+
context: Pick<EditorContext, 'schema' | 'value'>
|
|
15
15
|
offsets: {anchor: BlockOffset; focus: BlockOffset}
|
|
16
16
|
backward?: boolean
|
|
17
17
|
}): EditorSelection {
|
|
18
18
|
const anchor = blockOffsetToSelectionPoint({
|
|
19
|
-
|
|
19
|
+
context,
|
|
20
20
|
blockOffset: offsets.anchor,
|
|
21
21
|
direction: backward ? 'backward' : 'forward',
|
|
22
22
|
})
|
|
23
23
|
const focus = blockOffsetToSelectionPoint({
|
|
24
|
-
|
|
24
|
+
context,
|
|
25
25
|
blockOffset: offsets.focus,
|
|
26
26
|
direction: backward ? 'forward' : 'backward',
|
|
27
27
|
})
|