@portabletext/editor 1.0.19 → 1.1.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.
Files changed (72) hide show
  1. package/lib/index.d.mts +140 -66
  2. package/lib/index.d.ts +140 -66
  3. package/lib/index.esm.js +1125 -362
  4. package/lib/index.esm.js.map +1 -1
  5. package/lib/index.js +1125 -362
  6. package/lib/index.js.map +1 -1
  7. package/lib/index.mjs +1125 -362
  8. package/lib/index.mjs.map +1 -1
  9. package/package.json +2 -2
  10. package/src/editor/Editable.tsx +107 -36
  11. package/src/editor/PortableTextEditor.tsx +47 -12
  12. package/src/editor/__tests__/PortableTextEditor.test.tsx +42 -15
  13. package/src/editor/__tests__/PortableTextEditorTester.tsx +50 -38
  14. package/src/editor/__tests__/RangeDecorations.test.tsx +0 -1
  15. package/src/editor/__tests__/handleClick.test.tsx +28 -9
  16. package/src/editor/__tests__/insert-block.test.tsx +22 -6
  17. package/src/editor/__tests__/pteWarningsSelfSolving.test.tsx +30 -62
  18. package/src/editor/__tests__/utils.ts +10 -3
  19. package/src/editor/components/DraggableBlock.tsx +36 -13
  20. package/src/editor/components/Element.tsx +59 -17
  21. package/src/editor/components/Leaf.tsx +106 -68
  22. package/src/editor/components/SlateContainer.tsx +12 -5
  23. package/src/editor/components/Synchronizer.tsx +5 -2
  24. package/src/editor/hooks/usePortableTextEditor.ts +2 -2
  25. package/src/editor/hooks/usePortableTextEditorSelection.tsx +9 -3
  26. package/src/editor/hooks/useSyncValue.test.tsx +9 -4
  27. package/src/editor/hooks/useSyncValue.ts +199 -130
  28. package/src/editor/nodes/DefaultAnnotation.tsx +6 -3
  29. package/src/editor/plugins/__tests__/createWithInsertData.test.tsx +25 -7
  30. package/src/editor/plugins/__tests__/withEditableAPIDelete.test.tsx +26 -9
  31. package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +15 -5
  32. package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +60 -19
  33. package/src/editor/plugins/__tests__/withEditableAPISelectionsOverlapping.test.tsx +4 -2
  34. package/src/editor/plugins/__tests__/withPortableTextLists.test.tsx +4 -2
  35. package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +61 -17
  36. package/src/editor/plugins/__tests__/withPortableTextSelections.test.tsx +6 -3
  37. package/src/editor/plugins/__tests__/withUndoRedo.test.tsx +30 -13
  38. package/src/editor/plugins/createWithEditableAPI.ts +354 -124
  39. package/src/editor/plugins/createWithHotKeys.ts +41 -121
  40. package/src/editor/plugins/createWithInsertBreak.ts +166 -27
  41. package/src/editor/plugins/createWithInsertData.ts +60 -23
  42. package/src/editor/plugins/createWithMaxBlocks.ts +5 -2
  43. package/src/editor/plugins/createWithObjectKeys.ts +7 -3
  44. package/src/editor/plugins/createWithPatches.ts +60 -16
  45. package/src/editor/plugins/createWithPlaceholderBlock.ts +7 -3
  46. package/src/editor/plugins/createWithPortableTextBlockStyle.ts +17 -7
  47. package/src/editor/plugins/createWithPortableTextLists.ts +21 -8
  48. package/src/editor/plugins/createWithPortableTextMarkModel.ts +213 -46
  49. package/src/editor/plugins/createWithPortableTextSelections.ts +4 -2
  50. package/src/editor/plugins/createWithSchemaTypes.ts +25 -9
  51. package/src/editor/plugins/createWithUndoRedo.ts +107 -24
  52. package/src/editor/plugins/createWithUtils.ts +32 -10
  53. package/src/editor/plugins/index.ts +31 -10
  54. package/src/types/editor.ts +44 -15
  55. package/src/types/options.ts +4 -2
  56. package/src/types/slate.ts +2 -2
  57. package/src/utils/__tests__/dmpToOperations.test.ts +38 -13
  58. package/src/utils/__tests__/operationToPatches.test.ts +3 -2
  59. package/src/utils/__tests__/patchToOperations.test.ts +15 -4
  60. package/src/utils/__tests__/ranges.test.ts +8 -3
  61. package/src/utils/__tests__/valueNormalization.test.tsx +12 -4
  62. package/src/utils/__tests__/values.test.ts +0 -1
  63. package/src/utils/applyPatch.ts +71 -20
  64. package/src/utils/getPortableTextMemberSchemaTypes.ts +30 -15
  65. package/src/utils/operationToPatches.ts +126 -43
  66. package/src/utils/paths.ts +24 -7
  67. package/src/utils/ranges.ts +12 -5
  68. package/src/utils/selection.ts +19 -7
  69. package/src/utils/validateValue.ts +118 -45
  70. package/src/utils/values.ts +31 -9
  71. package/src/utils/weakMaps.ts +18 -8
  72. package/src/utils/withChanges.ts +4 -2
@@ -1,8 +1,10 @@
1
1
  import {describe, expect, it, jest} from '@jest/globals'
2
2
  import {render, waitFor} from '@testing-library/react'
3
3
  import {createRef, type RefObject} from 'react'
4
-
5
- import {PortableTextEditorTester, schemaType} from '../../__tests__/PortableTextEditorTester'
4
+ import {
5
+ PortableTextEditorTester,
6
+ schemaType,
7
+ } from '../../__tests__/PortableTextEditorTester'
6
8
  import {PortableTextEditor} from '../../PortableTextEditor'
7
9
 
8
10
  const initialValue = [
@@ -43,8 +45,14 @@ const emptyTextBlock = [
43
45
  },
44
46
  ]
45
47
  const emptyBlockSelection = {
46
- focus: {path: [{_key: 'emptyBlock'}, 'children', {_key: 'emptySpan'}], offset: 0},
47
- anchor: {path: [{_key: 'emptyBlock'}, 'children', {_key: 'emptySpan'}], offset: 0},
48
+ focus: {
49
+ path: [{_key: 'emptyBlock'}, 'children', {_key: 'emptySpan'}],
50
+ offset: 0,
51
+ },
52
+ anchor: {
53
+ path: [{_key: 'emptyBlock'}, 'children', {_key: 'emptySpan'}],
54
+ offset: 0,
55
+ },
48
56
  }
49
57
 
50
58
  describe('plugin:withEditableAPI: .insertChild()', () => {
@@ -63,7 +71,10 @@ describe('plugin:withEditableAPI: .insertChild()', () => {
63
71
 
64
72
  await waitFor(() => {
65
73
  if (editorRef.current) {
66
- expect(onChange).toHaveBeenCalledWith({type: 'value', value: initialValue})
74
+ expect(onChange).toHaveBeenCalledWith({
75
+ type: 'value',
76
+ value: initialValue,
77
+ })
67
78
  expect(onChange).toHaveBeenCalledWith({type: 'ready'})
68
79
  }
69
80
  })
@@ -80,7 +91,9 @@ describe('plugin:withEditableAPI: .insertChild()', () => {
80
91
  const inlineType = editorRef.current.schemaTypes.inlineObjects.find(
81
92
  (t) => t.name === 'someObject',
82
93
  )!
83
- PortableTextEditor.insertChild(editorRef.current, inlineType, {color: 'red'})
94
+ PortableTextEditor.insertChild(editorRef.current, inlineType, {
95
+ color: 'red',
96
+ })
84
97
  }
85
98
  })
86
99
 
@@ -118,9 +131,13 @@ describe('plugin:withEditableAPI: .insertChild()', () => {
118
131
 
119
132
  await waitFor(() => {
120
133
  if (editorRef.current) {
121
- PortableTextEditor.insertChild(editorRef.current, editorRef.current.schemaTypes.span, {
122
- text: ' ',
123
- })
134
+ PortableTextEditor.insertChild(
135
+ editorRef.current,
136
+ editorRef.current.schemaTypes.span,
137
+ {
138
+ text: ' ',
139
+ },
140
+ )
124
141
  }
125
142
  })
126
143
 
@@ -214,7 +231,9 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
214
231
  (t) => t.name === 'someObject',
215
232
  )!
216
233
 
217
- PortableTextEditor.insertBlock(editorRef.current, someObject, {color: 'red'})
234
+ PortableTextEditor.insertBlock(editorRef.current, someObject, {
235
+ color: 'red',
236
+ })
218
237
  }
219
238
  })
220
239
 
@@ -242,7 +261,10 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
242
261
 
243
262
  await waitFor(() => {
244
263
  if (editorRef.current) {
245
- expect(onChange).toHaveBeenCalledWith({type: 'value', value: initialValue})
264
+ expect(onChange).toHaveBeenCalledWith({
265
+ type: 'value',
266
+ value: initialValue,
267
+ })
246
268
  expect(onChange).toHaveBeenCalledWith({type: 'ready'})
247
269
  }
248
270
  })
@@ -260,7 +282,9 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
260
282
  (t) => t.name === 'someObject',
261
283
  )!
262
284
 
263
- PortableTextEditor.insertBlock(editorRef.current, someObject, {color: 'red'})
285
+ PortableTextEditor.insertBlock(editorRef.current, someObject, {
286
+ color: 'red',
287
+ })
264
288
  }
265
289
  })
266
290
 
@@ -289,7 +313,10 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
289
313
 
290
314
  await waitFor(() => {
291
315
  if (editorRef.current) {
292
- expect(onChange).toHaveBeenCalledWith({type: 'value', value: initialValue})
316
+ expect(onChange).toHaveBeenCalledWith({
317
+ type: 'value',
318
+ value: initialValue,
319
+ })
293
320
  expect(onChange).toHaveBeenCalledWith({type: 'ready'})
294
321
  }
295
322
  })
@@ -309,7 +336,9 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
309
336
  const someObject = editorRef.current.schemaTypes.inlineObjects.find(
310
337
  (t) => t.name === 'someObject',
311
338
  )!
312
- PortableTextEditor.insertBlock(editorRef.current, someObject, {color: 'red'})
339
+ PortableTextEditor.insertBlock(editorRef.current, someObject, {
340
+ color: 'red',
341
+ })
313
342
  }
314
343
  })
315
344
 
@@ -325,7 +354,10 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
325
354
 
326
355
  it('should not add empty blank blocks: non text block', async () => {
327
356
  const editorRef: RefObject<PortableTextEditor> = createRef()
328
- const value = [...initialValue, {_key: 'b', _type: 'someObject', color: 'red'}]
357
+ const value = [
358
+ ...initialValue,
359
+ {_key: 'b', _type: 'someObject', color: 'red'},
360
+ ]
329
361
  const onChange = jest.fn()
330
362
 
331
363
  render(
@@ -360,7 +392,9 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
360
392
  const someObject = editorRef.current.schemaTypes.inlineObjects.find(
361
393
  (t) => t.name === 'someObject',
362
394
  )!
363
- PortableTextEditor.insertBlock(editorRef.current, someObject, {color: 'yellow'})
395
+ PortableTextEditor.insertBlock(editorRef.current, someObject, {
396
+ color: 'yellow',
397
+ })
364
398
  }
365
399
  })
366
400
 
@@ -376,7 +410,10 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
376
410
 
377
411
  it('should not add empty blank blocks: in between blocks', async () => {
378
412
  const editorRef: RefObject<PortableTextEditor> = createRef()
379
- const value = [...initialValue, {_key: 'b', _type: 'someObject', color: 'red'}]
413
+ const value = [
414
+ ...initialValue,
415
+ {_key: 'b', _type: 'someObject', color: 'red'},
416
+ ]
380
417
  const onChange = jest.fn()
381
418
 
382
419
  render(
@@ -408,7 +445,9 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
408
445
  const someObject = editorRef.current.schemaTypes.inlineObjects.find(
409
446
  (t) => t.name === 'someObject',
410
447
  )!
411
- PortableTextEditor.insertBlock(editorRef.current, someObject, {color: 'yellow'})
448
+ PortableTextEditor.insertBlock(editorRef.current, someObject, {
449
+ color: 'yellow',
450
+ })
412
451
  }
413
452
  })
414
453
 
@@ -455,7 +494,9 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
455
494
  const someObject = editorRef.current.schemaTypes.inlineObjects.find(
456
495
  (t) => t.name === 'someObject',
457
496
  )!
458
- PortableTextEditor.insertBlock(editorRef.current, someObject, {color: 'yellow'})
497
+ PortableTextEditor.insertBlock(editorRef.current, someObject, {
498
+ color: 'yellow',
499
+ })
459
500
  }
460
501
  })
461
502
 
@@ -2,8 +2,10 @@ import {describe, expect, it, jest} from '@jest/globals'
2
2
  import {type PortableTextBlock} from '@sanity/types'
3
3
  import {render, waitFor} from '@testing-library/react'
4
4
  import {createRef, type RefObject} from 'react'
5
-
6
- import {PortableTextEditorTester, schemaType} from '../../__tests__/PortableTextEditorTester'
5
+ import {
6
+ PortableTextEditorTester,
7
+ schemaType,
8
+ } from '../../__tests__/PortableTextEditorTester'
7
9
  import {PortableTextEditor} from '../../PortableTextEditor'
8
10
 
9
11
  const INITIAL_VALUE: PortableTextBlock[] = [
@@ -1,8 +1,10 @@
1
1
  import {describe, expect, it, jest} from '@jest/globals'
2
2
  import {render, waitFor} from '@testing-library/react'
3
3
  import {createRef, type RefObject} from 'react'
4
-
5
- import {PortableTextEditorTester, schemaType} from '../../__tests__/PortableTextEditorTester'
4
+ import {
5
+ PortableTextEditorTester,
6
+ schemaType,
7
+ } from '../../__tests__/PortableTextEditorTester'
6
8
  import {PortableTextEditor} from '../../PortableTextEditor'
7
9
 
8
10
  describe('plugin:withPortableTextLists', () => {
@@ -2,13 +2,12 @@ import {describe, expect, it, jest} from '@jest/globals'
2
2
  /* eslint-disable max-nested-callbacks */
3
3
  import {render, waitFor} from '@testing-library/react'
4
4
  import {createRef, type RefObject} from 'react'
5
-
6
- import {type EditorSelection} from '../../../types/editor'
7
5
  import {
8
6
  PortableTextEditorTester,
9
7
  schemaType,
10
8
  schemaTypeWithColorAndLink,
11
9
  } from '../../__tests__/PortableTextEditorTester'
10
+ import {type EditorSelection} from '../../../types/editor'
12
11
  import {PortableTextEditor} from '../../PortableTextEditor'
13
12
 
14
13
  describe('plugin:withPortableTextMarksModel', () => {
@@ -79,7 +78,8 @@ describe('plugin:withPortableTextMarksModel', () => {
79
78
  anchor: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 3},
80
79
  })
81
80
  PortableTextEditor.toggleMark(editorRef.current, 'strong')
82
- expect(PortableTextEditor.getValue(editorRef.current)).toMatchInlineSnapshot(`
81
+ expect(PortableTextEditor.getValue(editorRef.current))
82
+ .toMatchInlineSnapshot(`
83
83
  Array [
84
84
  Object {
85
85
  "_key": "a",
@@ -189,7 +189,10 @@ Array [
189
189
 
190
190
  await waitFor(() => {
191
191
  if (editorRef.current) {
192
- expect(onChange).toHaveBeenCalledWith({type: 'value', value: initialValue})
192
+ expect(onChange).toHaveBeenCalledWith({
193
+ type: 'value',
194
+ value: initialValue,
195
+ })
193
196
  expect(onChange).toHaveBeenCalledWith({type: 'ready'})
194
197
  }
195
198
  })
@@ -296,8 +299,14 @@ Array [
296
299
  },
297
300
  ]
298
301
  const sel: EditorSelection = {
299
- focus: {path: [{_key: '5fc57af23597'}, 'children', {_key: '11c8c9f783a8'}], offset: 4},
300
- anchor: {path: [{_key: '7cd53af36712'}, 'children', {_key: '576c748e0cd2'}], offset: 0},
302
+ focus: {
303
+ path: [{_key: '5fc57af23597'}, 'children', {_key: '11c8c9f783a8'}],
304
+ offset: 4,
305
+ },
306
+ anchor: {
307
+ path: [{_key: '7cd53af36712'}, 'children', {_key: '576c748e0cd2'}],
308
+ offset: 0,
309
+ },
301
310
  }
302
311
  const onChange = jest.fn()
303
312
  await waitFor(() => {
@@ -424,7 +433,10 @@ Array [
424
433
 
425
434
  await waitFor(() => {
426
435
  if (editorRef.current) {
427
- expect(onChange).toHaveBeenCalledWith({type: 'value', value: initialValue})
436
+ expect(onChange).toHaveBeenCalledWith({
437
+ type: 'value',
438
+ value: initialValue,
439
+ })
428
440
  expect(onChange).toHaveBeenCalledWith({type: 'ready'})
429
441
  }
430
442
  })
@@ -524,7 +536,10 @@ Array [
524
536
 
525
537
  await waitFor(() => {
526
538
  if (editorRef.current) {
527
- expect(onChange).toHaveBeenCalledWith({type: 'value', value: initialValue})
539
+ expect(onChange).toHaveBeenCalledWith({
540
+ type: 'value',
541
+ value: initialValue,
542
+ })
528
543
  expect(onChange).toHaveBeenCalledWith({type: 'ready'})
529
544
  }
530
545
  })
@@ -537,12 +552,19 @@ Array [
537
552
 
538
553
  await waitFor(() => {
539
554
  if (editorRef.current) {
540
- const currentSelectionObject = PortableTextEditor.getSelection(editorRef.current)
555
+ const currentSelectionObject = PortableTextEditor.getSelection(
556
+ editorRef.current,
557
+ )
541
558
  PortableTextEditor.toggleMark(editorRef.current, 'strong')
542
- const nextSelectionObject = PortableTextEditor.getSelection(editorRef.current)
559
+ const nextSelectionObject = PortableTextEditor.getSelection(
560
+ editorRef.current,
561
+ )
543
562
  expect(currentSelectionObject).toEqual(nextSelectionObject)
544
563
  expect(currentSelectionObject === nextSelectionObject).toBe(false)
545
- expect(onChange).toHaveBeenCalledWith({type: 'selection', selection: nextSelectionObject})
564
+ expect(onChange).toHaveBeenCalledWith({
565
+ type: 'selection',
566
+ selection: nextSelectionObject,
567
+ })
546
568
  }
547
569
  })
548
570
  })
@@ -645,7 +667,9 @@ Array [
645
667
  focus: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 0},
646
668
  anchor: {path: [{_key: 'a'}, 'children', {_key: '2'}], offset: 2},
647
669
  })
648
- expect(PortableTextEditor.isAnnotationActive(editor, 'link')).toBe(false)
670
+ expect(PortableTextEditor.isAnnotationActive(editor, 'link')).toBe(
671
+ false,
672
+ )
649
673
  })
650
674
  })
651
675
  })
@@ -697,15 +721,28 @@ Array [
697
721
  PortableTextEditor.focus(editorRef.current)
698
722
  // Selects `a link` from `This is a link`, so the mark should be kept in the first span, color mark in both.
699
723
  PortableTextEditor.select(editorRef.current, {
700
- focus: {path: [{_key: '5fc57af23597'}, 'children', {_key: 'be1c67c6971a'}], offset: 14},
724
+ focus: {
725
+ path: [
726
+ {_key: '5fc57af23597'},
727
+ 'children',
728
+ {_key: 'be1c67c6971a'},
729
+ ],
730
+ offset: 14,
731
+ },
701
732
  anchor: {
702
- path: [{_key: '5fc57af23597'}, 'children', {_key: 'be1c67c6971a'}],
733
+ path: [
734
+ {_key: '5fc57af23597'},
735
+ 'children',
736
+ {_key: 'be1c67c6971a'},
737
+ ],
703
738
  offset: 8,
704
739
  },
705
740
  })
706
741
 
707
742
  // // eslint-disable-next-line max-nested-callbacks
708
- const linkType = editorRef.current.schemaTypes.annotations.find((a) => a.name === 'link')
743
+ const linkType = editorRef.current.schemaTypes.annotations.find(
744
+ (a) => a.name === 'link',
745
+ )
709
746
  if (!linkType) {
710
747
  throw new Error('No link type found')
711
748
  }
@@ -746,9 +783,16 @@ Array [
746
783
 
747
784
  // removes the color from both
748
785
  PortableTextEditor.select(editorRef.current, {
749
- focus: {path: [{_key: '5fc57af23597'}, 'children', {_key: '1'}], offset: 6},
786
+ focus: {
787
+ path: [{_key: '5fc57af23597'}, 'children', {_key: '1'}],
788
+ offset: 6,
789
+ },
750
790
  anchor: {
751
- path: [{_key: '5fc57af23597'}, 'children', {_key: 'be1c67c6971a'}],
791
+ path: [
792
+ {_key: '5fc57af23597'},
793
+ 'children',
794
+ {_key: 'be1c67c6971a'},
795
+ ],
752
796
  offset: 0,
753
797
  },
754
798
  })
@@ -1,8 +1,10 @@
1
1
  import {describe, expect, it, jest} from '@jest/globals'
2
2
  import {render, waitFor} from '@testing-library/react'
3
3
  import {createRef, type RefObject} from 'react'
4
-
5
- import {PortableTextEditorTester, schemaType} from '../../__tests__/PortableTextEditorTester'
4
+ import {
5
+ PortableTextEditorTester,
6
+ schemaType,
7
+ } from '../../__tests__/PortableTextEditorTester'
6
8
  import {PortableTextEditor} from '../../PortableTextEditor'
7
9
 
8
10
  const initialValue = [
@@ -56,7 +58,8 @@ describe('plugin:withPortableTextSelections', () => {
56
58
  if (editorRef.current) {
57
59
  PortableTextEditor.focus(editorRef.current)
58
60
  PortableTextEditor.select(editorRef.current, initialSelection)
59
- expect(PortableTextEditor.getSelection(editorRef.current)).toMatchInlineSnapshot(`
61
+ expect(PortableTextEditor.getSelection(editorRef.current))
62
+ .toMatchInlineSnapshot(`
60
63
  Object {
61
64
  "anchor": Object {
62
65
  "offset": 9,
@@ -1,8 +1,10 @@
1
1
  import {describe, expect, it, jest} from '@jest/globals'
2
2
  import {render, waitFor} from '@testing-library/react'
3
3
  import {createRef, type RefObject} from 'react'
4
-
5
- import {PortableTextEditorTester, schemaType} from '../../__tests__/PortableTextEditorTester'
4
+ import {
5
+ PortableTextEditorTester,
6
+ schemaType,
7
+ } from '../../__tests__/PortableTextEditorTester'
6
8
  import {PortableTextEditor} from '../../PortableTextEditor'
7
9
 
8
10
  const initialValue = [
@@ -56,7 +58,10 @@ describe('plugin:withUndoRedo', () => {
56
58
 
57
59
  await waitFor(() => {
58
60
  if (editorRef.current) {
59
- expect(onChange).toHaveBeenCalledWith({type: 'value', value: initialValue})
61
+ expect(onChange).toHaveBeenCalledWith({
62
+ type: 'value',
63
+ value: initialValue,
64
+ })
60
65
  expect(onChange).toHaveBeenCalledWith({type: 'ready'})
61
66
  }
62
67
  })
@@ -70,7 +75,8 @@ describe('plugin:withUndoRedo', () => {
70
75
  PortableTextEditor.getSelection(editorRef.current),
71
76
  {mode: 'blocks'},
72
77
  )
73
- expect(PortableTextEditor.getValue(editorRef.current)).toMatchInlineSnapshot(`
78
+ expect(PortableTextEditor.getValue(editorRef.current))
79
+ .toMatchInlineSnapshot(`
74
80
  Array [
75
81
  Object {
76
82
  "_key": "a",
@@ -89,7 +95,9 @@ describe('plugin:withUndoRedo', () => {
89
95
  ]
90
96
  `)
91
97
  PortableTextEditor.undo(editorRef.current)
92
- expect(PortableTextEditor.getValue(editorRef.current)).toEqual(initialValue)
98
+ expect(PortableTextEditor.getValue(editorRef.current)).toEqual(
99
+ initialValue,
100
+ )
93
101
  }
94
102
  })
95
103
  })
@@ -108,7 +116,10 @@ describe('plugin:withUndoRedo', () => {
108
116
 
109
117
  await waitFor(() => {
110
118
  if (editorRef.current) {
111
- expect(onChange).toHaveBeenCalledWith({type: 'value', value: initialValue})
119
+ expect(onChange).toHaveBeenCalledWith({
120
+ type: 'value',
121
+ value: initialValue,
122
+ })
112
123
  expect(onChange).toHaveBeenCalledWith({type: 'ready'})
113
124
  }
114
125
  })
@@ -117,15 +128,21 @@ describe('plugin:withUndoRedo', () => {
117
128
  if (editorRef.current) {
118
129
  PortableTextEditor.focus(editorRef.current)
119
130
  PortableTextEditor.select(editorRef.current, initialSelection)
120
- PortableTextEditor.insertBlock(editorRef.current, editorRef.current.schemaTypes.block, {
121
- children: [{_key: 'c1', _type: 'span', marks: [], text: 'Block C'}],
122
- })
123
- const producedKey = PortableTextEditor.getValue(editorRef.current)?.slice(-1)[0]?._key
131
+ PortableTextEditor.insertBlock(
132
+ editorRef.current,
133
+ editorRef.current.schemaTypes.block,
134
+ {
135
+ children: [{_key: 'c1', _type: 'span', marks: [], text: 'Block C'}],
136
+ },
137
+ )
138
+ const producedKey = PortableTextEditor.getValue(
139
+ editorRef.current,
140
+ )?.slice(-1)[0]?._key
124
141
  PortableTextEditor.undo(editorRef.current)
125
142
  PortableTextEditor.redo(editorRef.current)
126
- expect(PortableTextEditor.getValue(editorRef.current)?.slice(-1)[0]?._key).toEqual(
127
- producedKey,
128
- )
143
+ expect(
144
+ PortableTextEditor.getValue(editorRef.current)?.slice(-1)[0]?._key,
145
+ ).toEqual(producedKey)
129
146
  }
130
147
  })
131
148
  })