@portabletext/editor 1.44.10 → 1.44.12

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 (32) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +38 -8
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/editor-provider.cjs +2 -2
  4. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  5. package/lib/_chunks-es/behavior.core.js +38 -8
  6. package/lib/_chunks-es/behavior.core.js.map +1 -1
  7. package/lib/_chunks-es/editor-provider.js +2 -2
  8. package/lib/_chunks-es/editor-provider.js.map +1 -1
  9. package/lib/index.cjs +20 -16
  10. package/lib/index.cjs.map +1 -1
  11. package/lib/index.js +20 -16
  12. package/lib/index.js.map +1 -1
  13. package/package.json +2 -2
  14. package/src/behaviors/behavior.core.block-objects.ts +56 -8
  15. package/src/editor/Editable.tsx +24 -21
  16. package/src/editor/__tests__/PortableTextEditor.test.tsx +10 -0
  17. package/src/editor/__tests__/PortableTextEditorTester.tsx +3 -17
  18. package/src/editor/__tests__/RangeDecorations.test.tsx +6 -0
  19. package/src/editor/__tests__/pteWarningsSelfSolving.test.tsx +12 -5
  20. package/src/editor/__tests__/sync-value.test.tsx +5 -0
  21. package/src/editor/editor-machine.ts +1 -0
  22. package/src/editor/plugins/__tests__/withEditableAPIDelete.test.tsx +8 -3
  23. package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +3 -0
  24. package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +20 -12
  25. package/src/editor/plugins/__tests__/withEditableAPISelectionsOverlapping.test.tsx +5 -0
  26. package/src/editor/plugins/__tests__/withPortableTextLists.test.tsx +2 -0
  27. package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +10 -289
  28. package/src/editor/plugins/__tests__/withPortableTextSelections.test.tsx +2 -0
  29. package/src/editor/plugins/__tests__/withUndoRedo.test.tsx +3 -0
  30. package/src/editor/sync-machine.ts +8 -6
  31. package/src/internal-utils/__tests__/valueNormalization.test.tsx +2 -0
  32. package/src/internal-utils/event-position.ts +9 -4
@@ -5,6 +5,7 @@ import {
5
5
  PortableTextEditorTester,
6
6
  schemaType,
7
7
  } from '../../__tests__/PortableTextEditorTester'
8
+ import {createTestKeyGenerator} from '../../../internal-utils/test-key-generator'
8
9
  import {PortableTextEditor} from '../../PortableTextEditor'
9
10
 
10
11
  const initialValue = [
@@ -62,6 +63,7 @@ describe('plugin:withEditableAPI: .insertChild()', () => {
62
63
 
63
64
  render(
64
65
  <PortableTextEditorTester
66
+ keyGenerator={createTestKeyGenerator()}
65
67
  onChange={onChange}
66
68
  ref={editorRef}
67
69
  schemaType={schemaType}
@@ -111,12 +113,12 @@ describe('plugin:withEditableAPI: .insertChild()', () => {
111
113
  text: 'Block A',
112
114
  },
113
115
  {
114
- _key: '2',
116
+ _key: 'k3',
115
117
  _type: 'someObject',
116
118
  color: 'red',
117
119
  },
118
120
  {
119
- _key: '3',
121
+ _key: 'k4',
120
122
  _type: 'span',
121
123
  marks: [],
122
124
  text: '',
@@ -155,12 +157,12 @@ describe('plugin:withEditableAPI: .insertChild()', () => {
155
157
  text: 'Block A',
156
158
  },
157
159
  {
158
- _key: '2',
160
+ _key: 'k3',
159
161
  _type: 'someObject',
160
162
  color: 'red',
161
163
  },
162
164
  {
163
- _key: '5',
165
+ _key: 'k6',
164
166
  _type: 'span',
165
167
  marks: [],
166
168
  text: ' ',
@@ -172,8 +174,8 @@ describe('plugin:withEditableAPI: .insertChild()', () => {
172
174
  ])
173
175
 
174
176
  expect(PortableTextEditor.getSelection(editorRef.current)).toEqual({
175
- anchor: {path: [{_key: 'a'}, 'children', {_key: '5'}], offset: 1},
176
- focus: {path: [{_key: 'a'}, 'children', {_key: '5'}], offset: 1},
177
+ anchor: {path: [{_key: 'a'}, 'children', {_key: 'k6'}], offset: 1},
178
+ focus: {path: [{_key: 'a'}, 'children', {_key: 'k6'}], offset: 1},
177
179
  backward: false,
178
180
  })
179
181
  }
@@ -208,6 +210,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
208
210
  schemaType={schemaType}
209
211
  value={emptyTextBlock}
210
212
  onChange={onChange}
213
+ keyGenerator={createTestKeyGenerator()}
211
214
  />,
212
215
  )
213
216
 
@@ -240,7 +243,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
240
243
  await waitFor(() => {
241
244
  if (editorRef.current) {
242
245
  expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
243
- {_key: '1', _type: 'someObject', color: 'red'},
246
+ {_key: 'k2', _type: 'someObject', color: 'red'},
244
247
  ])
245
248
  }
246
249
  })
@@ -256,6 +259,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
256
259
  schemaType={schemaType}
257
260
  value={initialValue}
258
261
  onChange={onChange}
262
+ keyGenerator={createTestKeyGenerator()}
259
263
  />,
260
264
  )
261
265
 
@@ -292,7 +296,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
292
296
  if (editorRef.current) {
293
297
  expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
294
298
  ...initialValue,
295
- {_key: '1', _type: 'someObject', color: 'red'},
299
+ {_key: 'k2', _type: 'someObject', color: 'red'},
296
300
  ])
297
301
  }
298
302
  })
@@ -308,6 +312,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
308
312
  ref={editorRef}
309
313
  schemaType={schemaType}
310
314
  value={initialValue}
315
+ keyGenerator={createTestKeyGenerator()}
311
316
  />,
312
317
  )
313
318
 
@@ -345,7 +350,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
345
350
  await waitFor(() => {
346
351
  if (editorRef.current) {
347
352
  expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
348
- {_key: '1', _type: 'someObject', color: 'red'},
353
+ {_key: 'k2', _type: 'someObject', color: 'red'},
349
354
  ...initialValue,
350
355
  ])
351
356
  }
@@ -366,6 +371,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
366
371
  schemaType={schemaType}
367
372
  value={value}
368
373
  onChange={onChange}
374
+ keyGenerator={createTestKeyGenerator()}
369
375
  />,
370
376
  )
371
377
 
@@ -402,7 +408,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
402
408
  if (editorRef.current) {
403
409
  expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
404
410
  ...value,
405
- {_key: '1', _type: 'someObject', color: 'yellow'},
411
+ {_key: 'k2', _type: 'someObject', color: 'yellow'},
406
412
  ])
407
413
  }
408
414
  })
@@ -422,6 +428,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
422
428
  schemaType={schemaType}
423
429
  value={value}
424
430
  onChange={onChange}
431
+ keyGenerator={createTestKeyGenerator()}
425
432
  />,
426
433
  )
427
434
 
@@ -455,7 +462,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
455
462
  if (editorRef.current) {
456
463
  expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
457
464
  value[0],
458
- {_key: '1', _type: 'someObject', color: 'yellow'},
465
+ {_key: 'k2', _type: 'someObject', color: 'yellow'},
459
466
  value[1],
460
467
  ])
461
468
  }
@@ -473,6 +480,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
473
480
  schemaType={schemaType}
474
481
  value={value}
475
482
  onChange={onChange}
483
+ keyGenerator={createTestKeyGenerator()}
476
484
  />,
477
485
  )
478
486
 
@@ -504,7 +512,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
504
512
  if (editorRef.current) {
505
513
  expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
506
514
  value[0],
507
- {_key: '1', _type: 'someObject', color: 'yellow'},
515
+ {_key: 'k2', _type: 'someObject', color: 'yellow'},
508
516
  ])
509
517
  }
510
518
  })
@@ -6,6 +6,7 @@ import {
6
6
  PortableTextEditorTester,
7
7
  schemaType,
8
8
  } from '../../__tests__/PortableTextEditorTester'
9
+ import {createTestKeyGenerator} from '../../../internal-utils/test-key-generator'
9
10
  import {PortableTextEditor} from '../../PortableTextEditor'
10
11
 
11
12
  const INITIAL_VALUE: PortableTextBlock[] = [
@@ -31,6 +32,7 @@ describe('plugin:withEditableAPI: .isSelectionsOverlapping', () => {
31
32
  const onChange = vi.fn()
32
33
  render(
33
34
  <PortableTextEditorTester
35
+ keyGenerator={createTestKeyGenerator()}
34
36
  onChange={onChange}
35
37
  ref={editorRef}
36
38
  schemaType={schemaType}
@@ -65,6 +67,7 @@ describe('plugin:withEditableAPI: .isSelectionsOverlapping', () => {
65
67
  const onChange = vi.fn()
66
68
  render(
67
69
  <PortableTextEditorTester
70
+ keyGenerator={createTestKeyGenerator()}
68
71
  onChange={onChange}
69
72
  ref={editorRef}
70
73
  schemaType={schemaType}
@@ -99,6 +102,7 @@ describe('plugin:withEditableAPI: .isSelectionsOverlapping', () => {
99
102
  const onChange = vi.fn()
100
103
  render(
101
104
  <PortableTextEditorTester
105
+ keyGenerator={createTestKeyGenerator()}
102
106
  onChange={onChange}
103
107
  ref={editorRef}
104
108
  schemaType={schemaType}
@@ -133,6 +137,7 @@ describe('plugin:withEditableAPI: .isSelectionsOverlapping', () => {
133
137
  const onChange = vi.fn()
134
138
  render(
135
139
  <PortableTextEditorTester
140
+ keyGenerator={createTestKeyGenerator()}
136
141
  onChange={onChange}
137
142
  ref={editorRef}
138
143
  schemaType={schemaType}
@@ -5,6 +5,7 @@ import {
5
5
  PortableTextEditorTester,
6
6
  schemaType,
7
7
  } from '../../__tests__/PortableTextEditorTester'
8
+ import {createTestKeyGenerator} from '../../../internal-utils/test-key-generator'
8
9
  import {PortableTextEditor} from '../../PortableTextEditor'
9
10
 
10
11
  describe('plugin:withPortableTextLists', () => {
@@ -46,6 +47,7 @@ describe('plugin:withPortableTextLists', () => {
46
47
  await waitFor(() => {
47
48
  render(
48
49
  <PortableTextEditorTester
50
+ keyGenerator={createTestKeyGenerator()}
49
51
  onChange={onChange}
50
52
  ref={editorRef}
51
53
  schemaType={schemaType}
@@ -4,136 +4,13 @@ import {describe, expect, it, vi} from 'vitest'
4
4
  import {
5
5
  PortableTextEditorTester,
6
6
  schemaType,
7
- schemaTypeWithColorAndLink,
8
7
  } from '../../__tests__/PortableTextEditorTester'
8
+ import {createTestKeyGenerator} from '../../../internal-utils/test-key-generator'
9
9
  import type {EditorSelection} from '../../../types/editor'
10
10
  import {PortableTextEditor} from '../../PortableTextEditor'
11
11
 
12
12
  describe('plugin:withPortableTextMarksModel', () => {
13
13
  describe('normalization', () => {
14
- it('merges children correctly when toggling marks in various ranges', async () => {
15
- const editorRef: RefObject<PortableTextEditor | null> = createRef()
16
- const initialValue = [
17
- {
18
- _key: 'a',
19
- _type: 'myTestBlockType',
20
- children: [
21
- {
22
- _key: 'a1',
23
- _type: 'span',
24
- marks: [],
25
- text: '1234',
26
- },
27
- ],
28
- markDefs: [],
29
- style: 'normal',
30
- },
31
- ]
32
- const onChange = vi.fn()
33
- await waitFor(() => {
34
- render(
35
- <PortableTextEditorTester
36
- onChange={onChange}
37
- ref={editorRef}
38
- schemaType={schemaType}
39
- value={initialValue}
40
- />,
41
- )
42
- })
43
- const editor = editorRef.current!
44
- expect(editor).toBeDefined()
45
- await waitFor(() => {
46
- PortableTextEditor.focus(editor)
47
- PortableTextEditor.select(editor, {
48
- focus: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 0},
49
- anchor: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 4},
50
- })
51
- PortableTextEditor.toggleMark(editor, 'strong')
52
- expect(PortableTextEditor.getValue(editor)).toEqual([
53
- {
54
- _key: 'a',
55
- _type: 'myTestBlockType',
56
- children: [
57
- {
58
- _key: 'a1',
59
- _type: 'span',
60
- marks: ['strong'],
61
- text: '1234',
62
- },
63
- ],
64
- markDefs: [],
65
- style: 'normal',
66
- },
67
- ])
68
- })
69
- await waitFor(() => {
70
- if (editorRef.current) {
71
- PortableTextEditor.select(editorRef.current, {
72
- focus: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 1},
73
- anchor: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 3},
74
- })
75
- PortableTextEditor.toggleMark(editorRef.current, 'strong')
76
- expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
77
- {
78
- _key: 'a',
79
- _type: 'myTestBlockType',
80
- children: [
81
- {
82
- _key: 'a1',
83
- _type: 'span',
84
- marks: ['strong'],
85
- text: '1',
86
- },
87
- {
88
- _key: '2',
89
- _type: 'span',
90
- marks: [],
91
- text: '23',
92
- },
93
- {
94
- _key: '1',
95
- _type: 'span',
96
- marks: ['strong'],
97
- text: '4',
98
- },
99
- ],
100
- markDefs: [],
101
- style: 'normal',
102
- },
103
- ])
104
- }
105
- })
106
- await waitFor(() => {
107
- if (editor) {
108
- PortableTextEditor.select(editor, {
109
- focus: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 0},
110
- anchor: {path: [{_key: 'a'}, 'children', {_key: '1'}], offset: 1},
111
- })
112
- PortableTextEditor.toggleMark(editor, 'strong')
113
- expect(PortableTextEditor.getValue(editor)).toMatchInlineSnapshot(`
114
- [
115
- {
116
- "_key": "a",
117
- "_type": "myTestBlockType",
118
- "children": [
119
- {
120
- "_key": "a1",
121
- "_type": "span",
122
- "marks": [
123
- "strong",
124
- ],
125
- "text": "1234",
126
- },
127
- ],
128
- "markDefs": [],
129
- "style": "normal",
130
- },
131
- ]
132
- `)
133
- }
134
- })
135
- })
136
-
137
14
  it('toggles marks on children with annotation marks correctly', async () => {
138
15
  const editorRef: RefObject<PortableTextEditor | null> = createRef()
139
16
  const initialValue = [
@@ -172,6 +49,7 @@ describe('plugin:withPortableTextMarksModel', () => {
172
49
  ref={editorRef}
173
50
  schemaType={schemaType}
174
51
  value={initialValue}
52
+ keyGenerator={createTestKeyGenerator()}
175
53
  />,
176
54
  )
177
55
 
@@ -300,6 +178,7 @@ describe('plugin:withPortableTextMarksModel', () => {
300
178
  await waitFor(() => {
301
179
  render(
302
180
  <PortableTextEditorTester
181
+ keyGenerator={createTestKeyGenerator()}
303
182
  onChange={onChange}
304
183
  ref={editorRef}
305
184
  schemaType={schemaType}
@@ -416,6 +295,7 @@ describe('plugin:withPortableTextMarksModel', () => {
416
295
  ref={editorRef}
417
296
  schemaType={schemaType}
418
297
  value={initialValue}
298
+ keyGenerator={createTestKeyGenerator()}
419
299
  />,
420
300
  )
421
301
 
@@ -454,11 +334,11 @@ describe('plugin:withPortableTextMarksModel', () => {
454
334
  style: 'normal',
455
335
  },
456
336
  {
457
- _key: '1',
337
+ _key: 'k2',
458
338
  _type: 'myTestBlockType',
459
339
  children: [
460
340
  {
461
- _key: '2',
341
+ _key: 'k3',
462
342
  _type: 'span',
463
343
  marks: [],
464
344
  text: '',
@@ -519,6 +399,7 @@ describe('plugin:withPortableTextMarksModel', () => {
519
399
  ref={editorRef}
520
400
  schemaType={schemaType}
521
401
  value={initialValue}
402
+ keyGenerator={createTestKeyGenerator()}
522
403
  />,
523
404
  )
524
405
 
@@ -589,6 +470,7 @@ describe('plugin:withPortableTextMarksModel', () => {
589
470
  ref={editorRef}
590
471
  schemaType={schemaType}
591
472
  value={initialValue}
473
+ keyGenerator={createTestKeyGenerator()}
592
474
  />,
593
475
  )
594
476
  })
@@ -644,6 +526,7 @@ describe('plugin:withPortableTextMarksModel', () => {
644
526
  ref={editorRef}
645
527
  schemaType={schemaType}
646
528
  value={initialValue}
529
+ keyGenerator={createTestKeyGenerator()}
647
530
  />,
648
531
  )
649
532
  })
@@ -662,169 +545,6 @@ describe('plugin:withPortableTextMarksModel', () => {
662
545
  })
663
546
  })
664
547
 
665
- describe('removing annotations', () => {
666
- it('preserves other marks that apply to the spans', async () => {
667
- const editorRef: RefObject<PortableTextEditor | null> = createRef()
668
- const initialValue = [
669
- {
670
- _key: '5fc57af23597',
671
- _type: 'myTestBlockType',
672
- children: [
673
- {
674
- _key: 'be1c67c6971a',
675
- _type: 'span',
676
- marks: ['fde1fd54b544', '7b6d3d5de30c'],
677
- text: 'This is a link',
678
- },
679
- ],
680
- markDefs: [
681
- {
682
- _key: 'fde1fd54b544',
683
- _type: 'link',
684
- url: '1',
685
- },
686
- {
687
- _key: '7b6d3d5de30c',
688
- _type: 'color',
689
- color: 'blue',
690
- },
691
- ],
692
- style: 'normal',
693
- },
694
- ]
695
- const onChange = vi.fn()
696
- await waitFor(() => {
697
- render(
698
- <PortableTextEditorTester
699
- onChange={onChange}
700
- ref={editorRef}
701
- schemaType={schemaTypeWithColorAndLink}
702
- value={initialValue}
703
- />,
704
- )
705
- })
706
-
707
- await waitFor(() => {
708
- if (editorRef.current) {
709
- PortableTextEditor.focus(editorRef.current)
710
- // Selects `a link` from `This is a link`, so the mark should be kept in the first span, color mark in both.
711
- PortableTextEditor.select(editorRef.current, {
712
- focus: {
713
- path: [
714
- {_key: '5fc57af23597'},
715
- 'children',
716
- {_key: 'be1c67c6971a'},
717
- ],
718
- offset: 14,
719
- },
720
- anchor: {
721
- path: [
722
- {_key: '5fc57af23597'},
723
- 'children',
724
- {_key: 'be1c67c6971a'},
725
- ],
726
- offset: 8,
727
- },
728
- })
729
-
730
- const linkType = editorRef.current.schemaTypes.annotations.find(
731
- (a) => a.name === 'link',
732
- )
733
- if (!linkType) {
734
- throw new Error('No link type found')
735
- }
736
- PortableTextEditor.removeAnnotation(editorRef.current, linkType)
737
- expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
738
- {
739
- _key: '5fc57af23597',
740
- _type: 'myTestBlockType',
741
- children: [
742
- {
743
- _key: 'be1c67c6971a',
744
- _type: 'span',
745
- marks: ['fde1fd54b544', '7b6d3d5de30c'], // It has both marks, the link was only removed from the second span
746
- text: 'This is ',
747
- },
748
- {
749
- _key: '1',
750
- _type: 'span',
751
- marks: ['7b6d3d5de30c'],
752
- text: 'a link',
753
- },
754
- ],
755
- markDefs: [
756
- {
757
- _key: 'fde1fd54b544',
758
- _type: 'link',
759
- url: '1',
760
- },
761
- {
762
- _key: '7b6d3d5de30c',
763
- _type: 'color',
764
- color: 'blue',
765
- },
766
- ],
767
- style: 'normal',
768
- },
769
- ])
770
-
771
- // removes the color from both
772
- PortableTextEditor.select(editorRef.current, {
773
- focus: {
774
- path: [{_key: '5fc57af23597'}, 'children', {_key: '1'}],
775
- offset: 6,
776
- },
777
- anchor: {
778
- path: [
779
- {_key: '5fc57af23597'},
780
- 'children',
781
- {_key: 'be1c67c6971a'},
782
- ],
783
- offset: 0,
784
- },
785
- })
786
- const colorType = editorRef.current.schemaTypes.annotations.find(
787
- (a) => a.name === 'color',
788
- )
789
- if (!colorType) {
790
- throw new Error('No color type found')
791
- }
792
-
793
- PortableTextEditor.removeAnnotation(editorRef.current, colorType)
794
-
795
- expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
796
- {
797
- _key: '5fc57af23597',
798
- _type: 'myTestBlockType',
799
- children: [
800
- {
801
- _key: 'be1c67c6971a',
802
- _type: 'span',
803
- marks: ['fde1fd54b544'], // The color was removed from both
804
- text: 'This is ',
805
- },
806
- {
807
- _key: '1',
808
- _type: 'span',
809
- marks: [], // The color was removed from both
810
- text: 'a link',
811
- },
812
- ],
813
- markDefs: [
814
- {
815
- _key: 'fde1fd54b544',
816
- _type: 'link',
817
- url: '1',
818
- },
819
- ],
820
- style: 'normal',
821
- },
822
- ])
823
- }
824
- })
825
- })
826
- })
827
-
828
548
  describe('removing nodes', () => {
829
549
  it('should not insert a new block if we have more blocks available', async () => {
830
550
  const editorRef: RefObject<PortableTextEditor | null> = createRef()
@@ -852,6 +572,7 @@ describe('plugin:withPortableTextMarksModel', () => {
852
572
  await waitFor(() => {
853
573
  render(
854
574
  <PortableTextEditorTester
575
+ keyGenerator={createTestKeyGenerator()}
855
576
  onChange={onChange}
856
577
  ref={editorRef}
857
578
  schemaType={schemaType}
@@ -5,6 +5,7 @@ import {
5
5
  PortableTextEditorTester,
6
6
  schemaType,
7
7
  } from '../../__tests__/PortableTextEditorTester'
8
+ import {createTestKeyGenerator} from '../../../internal-utils/test-key-generator'
8
9
  import {PortableTextEditor} from '../../PortableTextEditor'
9
10
 
10
11
  const initialValue = [
@@ -44,6 +45,7 @@ describe('plugin:withPortableTextSelections', () => {
44
45
  const onChange = vi.fn()
45
46
  render(
46
47
  <PortableTextEditorTester
48
+ keyGenerator={createTestKeyGenerator()}
47
49
  onChange={onChange}
48
50
  ref={editorRef}
49
51
  schemaType={schemaType}
@@ -5,6 +5,7 @@ import {
5
5
  PortableTextEditorTester,
6
6
  schemaType,
7
7
  } from '../../__tests__/PortableTextEditorTester'
8
+ import {createTestKeyGenerator} from '../../../internal-utils/test-key-generator'
8
9
  import {PortableTextEditor} from '../../PortableTextEditor'
9
10
 
10
11
  const initialValue = [
@@ -49,6 +50,7 @@ describe('plugin:withUndoRedo', () => {
49
50
  const onChange = vi.fn()
50
51
  render(
51
52
  <PortableTextEditorTester
53
+ keyGenerator={createTestKeyGenerator()}
52
54
  onChange={onChange}
53
55
  ref={editorRef}
54
56
  schemaType={schemaType}
@@ -107,6 +109,7 @@ describe('plugin:withUndoRedo', () => {
107
109
 
108
110
  render(
109
111
  <PortableTextEditorTester
112
+ keyGenerator={createTestKeyGenerator()}
110
113
  onChange={onChange}
111
114
  ref={editorRef}
112
115
  schemaType={schemaType}
@@ -735,12 +735,14 @@ function _updateBlock(
735
735
  Text.isText(oldBlockChild) &&
736
736
  oldBlockChild._type === 'span'
737
737
  if (isSpanNode && isTextChanged) {
738
- Transforms.delete(slateEditor, {
739
- at: {
740
- focus: {path, offset: 0},
741
- anchor: {path, offset: oldBlockChild.text.length},
742
- },
743
- })
738
+ if (oldBlockChild.text.length > 0) {
739
+ Transforms.delete(slateEditor, {
740
+ at: {
741
+ focus: {path, offset: 0},
742
+ anchor: {path, offset: oldBlockChild.text.length},
743
+ },
744
+ })
745
+ }
744
746
  Transforms.insertText(slateEditor, currentBlockChild.text, {
745
747
  at: path,
746
748
  })
@@ -6,6 +6,7 @@ import {
6
6
  schemaType,
7
7
  } from '../../editor/__tests__/PortableTextEditorTester'
8
8
  import {PortableTextEditor} from '../../editor/PortableTextEditor'
9
+ import {createTestKeyGenerator} from '../test-key-generator'
9
10
 
10
11
  describe('values: normalization', () => {
11
12
  it("accepts incoming value with blocks without a style or markDefs prop, but doesn't leave them without them when editing them", async () => {
@@ -28,6 +29,7 @@ describe('values: normalization', () => {
28
29
  const onChange = vi.fn()
29
30
  render(
30
31
  <PortableTextEditorTester
32
+ keyGenerator={createTestKeyGenerator()}
31
33
  onChange={onChange}
32
34
  ref={editorRef}
33
35
  schemaType={schemaType}