@portabletext/editor 2.7.2 → 2.8.1

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.
Files changed (72) hide show
  1. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +3 -1
  2. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
  3. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs +10 -4
  4. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -1
  5. package/lib/_chunks-cjs/util.merge-text-blocks.cjs +0 -1
  6. package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
  7. package/lib/_chunks-cjs/util.slice-blocks.cjs +60 -9
  8. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
  9. package/lib/_chunks-dts/behavior.types.action.d.cts +149 -149
  10. package/lib/_chunks-dts/behavior.types.action.d.ts +86 -86
  11. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +4 -2
  12. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
  13. package/lib/_chunks-es/selector.is-selection-expanded.js +10 -4
  14. package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -1
  15. package/lib/_chunks-es/util.merge-text-blocks.js +0 -1
  16. package/lib/_chunks-es/util.merge-text-blocks.js.map +1 -1
  17. package/lib/_chunks-es/util.slice-blocks.js +56 -8
  18. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  19. package/lib/index.cjs +94 -131
  20. package/lib/index.cjs.map +1 -1
  21. package/lib/index.js +90 -128
  22. package/lib/index.js.map +1 -1
  23. package/lib/plugins/index.d.cts +3 -3
  24. package/lib/selectors/index.d.cts +13 -3
  25. package/lib/selectors/index.d.ts +13 -3
  26. package/package.json +13 -14
  27. package/src/behaviors/behavior.abstract.insert.ts +58 -1
  28. package/src/behaviors/behavior.abstract.split.ts +0 -1
  29. package/src/behaviors/behavior.core.annotations.ts +24 -2
  30. package/src/behaviors/behavior.core.ts +1 -1
  31. package/src/behaviors/behavior.types.event.ts +18 -18
  32. package/src/converters/converter.portable-text.ts +0 -1
  33. package/src/converters/converter.text-html.serialize.test.ts +27 -17
  34. package/src/converters/converter.text-html.ts +0 -1
  35. package/src/converters/converter.text-plain.test.ts +1 -1
  36. package/src/converters/converter.text-plain.ts +0 -1
  37. package/src/editor/Editable.tsx +0 -1
  38. package/src/editor/plugins/createWithEditableAPI.ts +16 -0
  39. package/src/internal-utils/parse-blocks.test.ts +23 -23
  40. package/src/internal-utils/parse-blocks.ts +13 -24
  41. package/src/internal-utils/test-editor.tsx +15 -21
  42. package/src/operations/behavior.operation.annotation.add.ts +2 -13
  43. package/src/operations/behavior.operation.block.set.ts +1 -1
  44. package/src/operations/behavior.operation.block.unset.ts +2 -2
  45. package/src/operations/behavior.operation.insert.block.ts +1 -1
  46. package/src/operations/behavior.operations.ts +0 -18
  47. package/src/plugins/plugin.internal.auto-close-brackets.test.tsx +25 -71
  48. package/src/plugins/plugin.markdown.test.tsx +12 -30
  49. package/src/selectors/selector.get-selected-value.test.ts +748 -0
  50. package/src/selectors/selector.get-selected-value.ts +28 -7
  51. package/src/selectors/selector.get-trimmed-selection.test.ts +0 -1
  52. package/src/selectors/selector.is-active-annotation.test.ts +320 -0
  53. package/src/selectors/selector.is-active-annotation.ts +24 -0
  54. package/src/utils/util.merge-text-blocks.ts +1 -1
  55. package/src/utils/util.slice-blocks.ts +36 -3
  56. package/src/editor/__tests__/PortableTextEditor.test.tsx +0 -430
  57. package/src/editor/__tests__/PortableTextEditorTester.tsx +0 -58
  58. package/src/editor/__tests__/RangeDecorations.test.tsx +0 -213
  59. package/src/editor/__tests__/insert-block.test.tsx +0 -224
  60. package/src/editor/__tests__/self-solving.test.tsx +0 -183
  61. package/src/editor/plugins/__tests__/withEditableAPIDelete.test.tsx +0 -298
  62. package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +0 -177
  63. package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +0 -538
  64. package/src/editor/plugins/__tests__/withEditableAPISelectionsOverlapping.test.tsx +0 -162
  65. package/src/editor/plugins/__tests__/withPortableTextLists.test.tsx +0 -65
  66. package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +0 -612
  67. package/src/editor/plugins/__tests__/withPortableTextSelections.test.tsx +0 -103
  68. package/src/editor/plugins/__tests__/withUndoRedo.test.tsx +0 -147
  69. package/src/internal-utils/__tests__/valueNormalization.test.tsx +0 -79
  70. package/src/operations/behavior.operation.insert-inline-object.ts +0 -59
  71. package/src/operations/behavior.operation.insert-span.ts +0 -48
  72. package/src/utils/util.slice-blocks.test.ts +0 -465
@@ -1,612 +0,0 @@
1
- import {createTestKeyGenerator} from '@portabletext/test'
2
- import {render, waitFor} from '@testing-library/react'
3
- import {createRef, type RefObject} from 'react'
4
- import {describe, expect, it, vi} from 'vitest'
5
- import {PortableTextEditorTester} from '../../__tests__/PortableTextEditorTester'
6
- import type {EditorSelection} from '../../../types/editor'
7
- import {PortableTextEditor} from '../../PortableTextEditor'
8
-
9
- describe('plugin:withPortableTextMarksModel', () => {
10
- describe('normalization', () => {
11
- it('toggles marks on children with annotation marks correctly', async () => {
12
- const editorRef: RefObject<PortableTextEditor | null> = createRef()
13
- const initialValue = [
14
- {
15
- _key: 'a',
16
- _type: 'block',
17
- children: [
18
- {
19
- _key: 'a1',
20
- _type: 'span',
21
- marks: ['abc'],
22
- text: 'A link',
23
- },
24
- {
25
- _key: 'a2',
26
- _type: 'span',
27
- marks: [],
28
- text: ', not a link',
29
- },
30
- ],
31
- markDefs: [
32
- {
33
- _type: 'link',
34
- _key: 'abc',
35
- href: 'http://www.link.com',
36
- },
37
- ],
38
- style: 'normal',
39
- },
40
- ]
41
- const onChange = vi.fn()
42
-
43
- render(
44
- <PortableTextEditorTester
45
- onChange={onChange}
46
- ref={editorRef}
47
- value={initialValue}
48
- keyGenerator={createTestKeyGenerator()}
49
- />,
50
- )
51
-
52
- await waitFor(() => {
53
- if (editorRef.current) {
54
- expect(onChange).toHaveBeenCalledWith({
55
- type: 'value',
56
- value: initialValue,
57
- })
58
- expect(onChange).toHaveBeenCalledWith({type: 'ready'})
59
- }
60
- })
61
-
62
- await waitFor(() => {
63
- if (editorRef.current) {
64
- PortableTextEditor.focus(editorRef.current)
65
- PortableTextEditor.select(editorRef.current, {
66
- focus: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 0},
67
- anchor: {path: [{_key: 'a'}, 'children', {_key: 'a2'}], offset: 12},
68
- })
69
- PortableTextEditor.toggleMark(editorRef.current, 'strong')
70
- }
71
- })
72
-
73
- await waitFor(() => {
74
- if (editorRef.current) {
75
- expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
76
- {
77
- _key: 'a',
78
- _type: 'block',
79
- children: [
80
- {
81
- _key: 'a1',
82
- _type: 'span',
83
- marks: ['abc', 'strong'],
84
- text: 'A link',
85
- },
86
- {
87
- _key: 'a2',
88
- _type: 'span',
89
- marks: ['strong'],
90
- text: ', not a link',
91
- },
92
- ],
93
- markDefs: [
94
- {
95
- _type: 'link',
96
- _key: 'abc',
97
- href: 'http://www.link.com',
98
- },
99
- ],
100
- style: 'normal',
101
- },
102
- ])
103
- }
104
- })
105
- })
106
-
107
- it('merges blocks correctly when containing links', async () => {
108
- const editorRef: RefObject<PortableTextEditor | null> = createRef()
109
- const initialValue = [
110
- {
111
- _key: '5fc57af23597',
112
- _type: 'block',
113
- children: [
114
- {
115
- _key: 'be1c67c6971a',
116
- _type: 'span',
117
- marks: [],
118
- text: 'This is a ',
119
- },
120
- {
121
- _key: '11c8c9f783a8',
122
- _type: 'span',
123
- marks: ['fde1fd54b544'],
124
- text: 'link',
125
- },
126
- ],
127
- markDefs: [
128
- {
129
- _key: 'fde1fd54b544',
130
- _type: 'link',
131
- url: '1',
132
- },
133
- ],
134
- style: 'normal',
135
- },
136
- {
137
- _key: '7cd53af36712',
138
- _type: 'block',
139
- children: [
140
- {
141
- _key: '576c748e0cd2',
142
- _type: 'span',
143
- marks: [],
144
- text: 'This is ',
145
- },
146
- {
147
- _key: 'f3d73d3833bf',
148
- _type: 'span',
149
- marks: ['7b6d3d5de30c'],
150
- text: 'another',
151
- },
152
- ],
153
- markDefs: [
154
- {
155
- _key: '7b6d3d5de30c',
156
- _type: 'link',
157
- url: '2',
158
- },
159
- ],
160
- style: 'normal',
161
- },
162
- ]
163
- const sel: EditorSelection = {
164
- focus: {
165
- path: [{_key: '5fc57af23597'}, 'children', {_key: '11c8c9f783a8'}],
166
- offset: 4,
167
- },
168
- anchor: {
169
- path: [{_key: '7cd53af36712'}, 'children', {_key: '576c748e0cd2'}],
170
- offset: 0,
171
- },
172
- }
173
- const onChange = vi.fn()
174
- await waitFor(() => {
175
- render(
176
- <PortableTextEditorTester
177
- keyGenerator={createTestKeyGenerator()}
178
- onChange={onChange}
179
- ref={editorRef}
180
- value={initialValue}
181
- />,
182
- )
183
- })
184
- const editor = editorRef.current!
185
- expect(editor).toBeDefined()
186
- await waitFor(() => {
187
- PortableTextEditor.select(editor, sel)
188
- PortableTextEditor.delete(editor, sel)
189
- expect(PortableTextEditor.getValue(editor)).toEqual([
190
- {
191
- _key: '5fc57af23597',
192
- _type: 'block',
193
- children: [
194
- {
195
- _key: 'be1c67c6971a',
196
- _type: 'span',
197
- marks: [],
198
- text: 'This is a ',
199
- },
200
- {
201
- _key: '11c8c9f783a8',
202
- _type: 'span',
203
- marks: ['fde1fd54b544'],
204
- text: 'link',
205
- },
206
- {
207
- _key: '576c748e0cd2',
208
- _type: 'span',
209
- marks: [],
210
- text: 'This is ',
211
- },
212
- {
213
- _key: 'f3d73d3833bf',
214
- _type: 'span',
215
- marks: ['7b6d3d5de30c'],
216
- text: 'another',
217
- },
218
- ],
219
- markDefs: [
220
- {
221
- _key: 'fde1fd54b544',
222
- _type: 'link',
223
- url: '1',
224
- },
225
- {
226
- _key: '7b6d3d5de30c',
227
- _type: 'link',
228
- url: '2',
229
- },
230
- ],
231
- style: 'normal',
232
- },
233
- ])
234
- })
235
- })
236
-
237
- it('resets markDefs when splitting a block in the beginning', async () => {
238
- const editorRef: RefObject<PortableTextEditor | null> = createRef()
239
- const initialValue = [
240
- {
241
- _key: 'ba',
242
- _type: 'block',
243
- children: [
244
- {
245
- _key: 'sa',
246
- _type: 'span',
247
- marks: [],
248
- text: '1',
249
- },
250
- ],
251
- markDefs: [],
252
- style: 'normal',
253
- },
254
- {
255
- _key: 'bb',
256
- _type: 'block',
257
- children: [
258
- {
259
- _key: 'sb',
260
- _type: 'span',
261
- marks: ['aa'],
262
- text: '2',
263
- },
264
- ],
265
- markDefs: [
266
- {
267
- _key: 'aa',
268
- _type: 'link',
269
- href: 'http://www.123.com',
270
- },
271
- ],
272
- style: 'normal',
273
- },
274
- ]
275
- const sel: EditorSelection = {
276
- focus: {path: [{_key: 'bb'}, 'children', {_key: 'sb'}], offset: 0},
277
- anchor: {path: [{_key: 'bb'}, 'children', {_key: 'sb'}], offset: 0},
278
- }
279
- const onChange = vi.fn()
280
-
281
- render(
282
- <PortableTextEditorTester
283
- onChange={onChange}
284
- ref={editorRef}
285
- value={initialValue}
286
- keyGenerator={createTestKeyGenerator()}
287
- />,
288
- )
289
-
290
- await waitFor(() => {
291
- if (editorRef.current) {
292
- expect(onChange).toHaveBeenCalledWith({
293
- type: 'value',
294
- value: initialValue,
295
- })
296
- expect(onChange).toHaveBeenCalledWith({type: 'ready'})
297
- }
298
- })
299
-
300
- await waitFor(() => {
301
- if (editorRef.current) {
302
- PortableTextEditor.select(editorRef.current, sel)
303
- PortableTextEditor.insertBreak(editorRef.current)
304
- }
305
- })
306
-
307
- await waitFor(() => {
308
- if (editorRef.current) {
309
- expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
310
- {
311
- _key: 'ba',
312
- _type: 'block',
313
- children: [
314
- {
315
- _key: 'sa',
316
- _type: 'span',
317
- marks: [],
318
- text: '1',
319
- },
320
- ],
321
- markDefs: [],
322
- style: 'normal',
323
- },
324
- {
325
- _key: 'k2',
326
- _type: 'block',
327
- children: [
328
- {
329
- _key: 'k3',
330
- _type: 'span',
331
- marks: [],
332
- text: '',
333
- },
334
- ],
335
- markDefs: [],
336
- style: 'normal',
337
- },
338
- {
339
- _key: 'bb',
340
- _type: 'block',
341
- children: [
342
- {
343
- _key: 'sb',
344
- _type: 'span',
345
- marks: ['aa'],
346
- text: '2',
347
- },
348
- ],
349
- markDefs: [
350
- {
351
- _key: 'aa',
352
- _type: 'link',
353
- href: 'http://www.123.com',
354
- },
355
- ],
356
- style: 'normal',
357
- },
358
- ])
359
- }
360
- })
361
- })
362
- })
363
- describe('selection', () => {
364
- it('should emit a new selection object when toggling marks, even though the value is the same', async () => {
365
- const editorRef: RefObject<PortableTextEditor | null> = createRef()
366
- const initialValue = [
367
- {
368
- _key: 'ba',
369
- _type: 'block',
370
- children: [
371
- {
372
- _key: 'sa',
373
- _type: 'span',
374
- marks: [],
375
- text: '',
376
- },
377
- ],
378
- markDefs: [],
379
- style: 'normal',
380
- },
381
- ]
382
- const onChange = vi.fn()
383
-
384
- render(
385
- <PortableTextEditorTester
386
- onChange={onChange}
387
- ref={editorRef}
388
- value={initialValue}
389
- keyGenerator={createTestKeyGenerator()}
390
- />,
391
- )
392
-
393
- await waitFor(() => {
394
- if (editorRef.current) {
395
- expect(onChange).toHaveBeenCalledWith({
396
- type: 'value',
397
- value: initialValue,
398
- })
399
- expect(onChange).toHaveBeenCalledWith({type: 'ready'})
400
- }
401
- })
402
-
403
- await waitFor(() => {
404
- if (editorRef.current) {
405
- PortableTextEditor.focus(editorRef.current)
406
- }
407
- })
408
-
409
- await waitFor(() => {
410
- if (editorRef.current) {
411
- const currentSelectionObject = PortableTextEditor.getSelection(
412
- editorRef.current,
413
- )
414
- PortableTextEditor.toggleMark(editorRef.current, 'strong')
415
- const nextSelectionObject = PortableTextEditor.getSelection(
416
- editorRef.current,
417
- )
418
- expect(currentSelectionObject).toEqual(nextSelectionObject)
419
- expect(currentSelectionObject === nextSelectionObject).toBe(false)
420
- expect(onChange).toHaveBeenCalledWith({
421
- type: 'selection',
422
- selection: nextSelectionObject,
423
- })
424
- }
425
- })
426
- })
427
-
428
- it('should return active marks that cover the whole selection', async () => {
429
- const editorRef: RefObject<PortableTextEditor | null> = createRef()
430
- const initialValue = [
431
- {
432
- _key: 'a',
433
- _type: 'block',
434
- children: [
435
- {
436
- _key: 'a1',
437
- _type: 'span',
438
- marks: ['strong'],
439
- text: '12',
440
- },
441
- {
442
- _key: '2',
443
- _type: 'span',
444
- marks: [],
445
- text: '34',
446
- },
447
- ],
448
- markDefs: [{_key: 'strong', _type: 'strong'}],
449
- style: 'normal',
450
- },
451
- ]
452
- const onChange = vi.fn()
453
- await waitFor(() => {
454
- render(
455
- <PortableTextEditorTester
456
- onChange={onChange}
457
- ref={editorRef}
458
- value={initialValue}
459
- keyGenerator={createTestKeyGenerator()}
460
- />,
461
- )
462
- })
463
- const editor = editorRef.current!
464
- expect(editor).toBeDefined()
465
- await waitFor(() => {
466
- PortableTextEditor.focus(editor)
467
- PortableTextEditor.select(editor, {
468
- focus: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 0},
469
- anchor: {path: [{_key: 'a'}, 'children', {_key: '2'}], offset: 2},
470
- })
471
- expect(PortableTextEditor.isMarkActive(editor, 'strong')).toBe(false)
472
- PortableTextEditor.toggleMark(editor, 'strong')
473
- expect(PortableTextEditor.isMarkActive(editor, 'strong')).toBe(true)
474
- })
475
- })
476
-
477
- it('should return active annotation types that cover the whole selection', async () => {
478
- const editorRef: RefObject<PortableTextEditor | null> = createRef()
479
- const initialValue = [
480
- {
481
- _key: 'a',
482
- _type: 'block',
483
- children: [
484
- {
485
- _key: 'a1',
486
- _type: 'span',
487
- marks: ['bab319ad3a9d'],
488
- text: '12',
489
- },
490
- {
491
- _key: '2',
492
- _type: 'span',
493
- marks: [],
494
- text: '34',
495
- },
496
- ],
497
- markDefs: [
498
- {
499
- _key: 'bab319ad3a9d',
500
- _type: 'link',
501
- href: 'http://www.123.com',
502
- },
503
- ],
504
- style: 'normal',
505
- },
506
- ]
507
- const onChange = vi.fn()
508
- await waitFor(() => {
509
- render(
510
- <PortableTextEditorTester
511
- onChange={onChange}
512
- ref={editorRef}
513
- value={initialValue}
514
- keyGenerator={createTestKeyGenerator()}
515
- />,
516
- )
517
- })
518
- const editor = editorRef.current!
519
- expect(editor).toBeDefined()
520
- await waitFor(() => {
521
- PortableTextEditor.focus(editor)
522
- PortableTextEditor.select(editor, {
523
- focus: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 0},
524
- anchor: {path: [{_key: 'a'}, 'children', {_key: '2'}], offset: 2},
525
- })
526
- expect(PortableTextEditor.isAnnotationActive(editor, 'link')).toBe(
527
- false,
528
- )
529
- })
530
- })
531
- })
532
-
533
- describe('removing nodes', () => {
534
- it('should not insert a new block if we have more blocks available', async () => {
535
- const editorRef: RefObject<PortableTextEditor | null> = createRef()
536
- const initialValue = [
537
- {
538
- _key: '5fc57af23597',
539
- _type: 'custom image',
540
- },
541
- {
542
- _type: 'block',
543
- _key: 'existingBlock',
544
- style: 'normal',
545
- markDefs: [],
546
- children: [
547
- {
548
- _type: 'span',
549
- _key: '2',
550
- text: '',
551
- marks: [],
552
- },
553
- ],
554
- },
555
- ]
556
- const onChange = vi.fn()
557
- await waitFor(() => {
558
- render(
559
- <PortableTextEditorTester
560
- keyGenerator={createTestKeyGenerator()}
561
- onChange={onChange}
562
- ref={editorRef}
563
- value={initialValue}
564
- />,
565
- )
566
- })
567
-
568
- await waitFor(() => {
569
- if (editorRef.current) {
570
- expect(onChange).toHaveBeenCalledWith({
571
- type: 'value',
572
- value: initialValue,
573
- })
574
- expect(onChange).toHaveBeenCalledWith({type: 'ready'})
575
- }
576
- })
577
-
578
- await waitFor(() => {
579
- if (editorRef.current) {
580
- PortableTextEditor.focus(editorRef.current)
581
-
582
- PortableTextEditor.delete(
583
- editorRef.current,
584
- {
585
- focus: {path: [{_key: '5fc57af23597'}], offset: 0},
586
- anchor: {path: [{_key: '5fc57af23597'}], offset: 0},
587
- },
588
- {mode: 'blocks'},
589
- )
590
-
591
- const value = PortableTextEditor.getValue(editorRef.current)
592
- expect(value).toEqual([
593
- {
594
- _type: 'block',
595
- _key: 'existingBlock',
596
- style: 'normal',
597
- markDefs: [],
598
- children: [
599
- {
600
- _type: 'span',
601
- _key: '2',
602
- text: '',
603
- marks: [],
604
- },
605
- ],
606
- },
607
- ])
608
- }
609
- })
610
- })
611
- })
612
- })
@@ -1,103 +0,0 @@
1
- import {createTestKeyGenerator} from '@portabletext/test'
2
- import {render, waitFor} from '@testing-library/react'
3
- import {createRef, type RefObject} from 'react'
4
- import {describe, expect, it, vi} from 'vitest'
5
- import {PortableTextEditorTester} from '../../__tests__/PortableTextEditorTester'
6
- import {PortableTextEditor} from '../../PortableTextEditor'
7
-
8
- const initialValue = [
9
- {
10
- _key: 'a',
11
- _type: 'block',
12
- children: [
13
- {
14
- _key: 'a1',
15
- _type: 'span',
16
- marks: [],
17
- text: "It's a beautiful day on planet earth",
18
- },
19
- ],
20
- markDefs: [],
21
- style: 'normal',
22
- },
23
- {
24
- _key: 'b',
25
- _type: 'block',
26
- children: [
27
- {
28
- _key: 'b1',
29
- _type: 'span',
30
- marks: [],
31
- text: 'The birds are singing',
32
- },
33
- ],
34
- markDefs: [],
35
- style: 'normal',
36
- },
37
- ]
38
-
39
- describe('plugin:withPortableTextSelections', () => {
40
- it('will report that a selection is made backward', async () => {
41
- const editorRef: RefObject<PortableTextEditor | null> = createRef()
42
- const onChange = vi.fn()
43
- render(
44
- <PortableTextEditorTester
45
- keyGenerator={createTestKeyGenerator()}
46
- onChange={onChange}
47
- ref={editorRef}
48
- value={initialValue}
49
- />,
50
- )
51
- const initialSelection = {
52
- anchor: {path: [{_key: 'b'}, 'children', {_key: 'b1'}], offset: 9},
53
- focus: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 7},
54
- }
55
-
56
- await waitFor(() => {
57
- if (editorRef.current) {
58
- expect(onChange).toHaveBeenCalledWith({
59
- type: 'value',
60
- value: initialValue,
61
- })
62
- expect(onChange).toHaveBeenCalledWith({type: 'ready'})
63
- }
64
- })
65
-
66
- await waitFor(() => {
67
- if (editorRef.current) {
68
- PortableTextEditor.focus(editorRef.current)
69
- PortableTextEditor.select(editorRef.current, initialSelection)
70
- expect(PortableTextEditor.getSelection(editorRef.current))
71
- .toMatchInlineSnapshot(`
72
- {
73
- "anchor": {
74
- "offset": 9,
75
- "path": [
76
- {
77
- "_key": "b",
78
- },
79
- "children",
80
- {
81
- "_key": "b1",
82
- },
83
- ],
84
- },
85
- "backward": true,
86
- "focus": {
87
- "offset": 7,
88
- "path": [
89
- {
90
- "_key": "a",
91
- },
92
- "children",
93
- {
94
- "_key": "a1",
95
- },
96
- ],
97
- },
98
- }
99
- `)
100
- }
101
- })
102
- })
103
- })