@portabletext/editor 1.1.0 → 1.1.2

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 (79) hide show
  1. package/README.md +3 -0
  2. package/lib/index.d.mts +1680 -12
  3. package/lib/index.d.ts +1680 -12
  4. package/lib/index.esm.js +310 -162
  5. package/lib/index.esm.js.map +1 -1
  6. package/lib/index.js +310 -163
  7. package/lib/index.js.map +1 -1
  8. package/lib/index.mjs +310 -162
  9. package/lib/index.mjs.map +1 -1
  10. package/package.json +25 -38
  11. package/src/editor/Editable.tsx +51 -50
  12. package/src/editor/PortableTextEditor.tsx +42 -26
  13. package/src/editor/__tests__/PortableTextEditor.test.tsx +11 -12
  14. package/src/editor/__tests__/PortableTextEditorTester.tsx +2 -5
  15. package/src/editor/__tests__/RangeDecorations.test.tsx +6 -7
  16. package/src/editor/__tests__/handleClick.test.tsx +27 -7
  17. package/src/editor/__tests__/insert-block.test.tsx +6 -6
  18. package/src/editor/__tests__/pteWarningsSelfSolving.test.tsx +8 -8
  19. package/src/editor/__tests__/self-solving.test.tsx +176 -0
  20. package/src/editor/components/Element.tsx +15 -17
  21. package/src/editor/components/Leaf.tsx +40 -35
  22. package/src/editor/components/SlateContainer.tsx +2 -2
  23. package/src/editor/components/Synchronizer.tsx +62 -34
  24. package/src/editor/editor-machine.ts +195 -0
  25. package/src/editor/hooks/usePortableTextEditor.ts +1 -1
  26. package/src/editor/hooks/usePortableTextEditorSelection.tsx +12 -14
  27. package/src/editor/hooks/useSyncValue.test.tsx +9 -9
  28. package/src/editor/hooks/useSyncValue.ts +16 -19
  29. package/src/editor/nodes/DefaultAnnotation.tsx +1 -2
  30. package/src/editor/nodes/DefaultObject.tsx +1 -1
  31. package/src/editor/plugins/__tests__/createWithInsertData.test.tsx +2 -5
  32. package/src/editor/plugins/__tests__/withEditableAPIDelete.test.tsx +28 -28
  33. package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +17 -17
  34. package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +8 -8
  35. package/src/editor/plugins/__tests__/withEditableAPISelectionsOverlapping.test.tsx +6 -6
  36. package/src/editor/plugins/__tests__/withPortableTextLists.test.tsx +2 -2
  37. package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +47 -49
  38. package/src/editor/plugins/__tests__/withPortableTextSelections.test.tsx +22 -11
  39. package/src/editor/plugins/__tests__/withUndoRedo.test.tsx +9 -9
  40. package/src/editor/plugins/createWithEditableAPI.ts +8 -8
  41. package/src/editor/plugins/createWithHotKeys.ts +8 -12
  42. package/src/editor/plugins/createWithInsertBreak.ts +4 -4
  43. package/src/editor/plugins/createWithInsertData.ts +11 -16
  44. package/src/editor/plugins/createWithMaxBlocks.ts +1 -1
  45. package/src/editor/plugins/createWithObjectKeys.ts +10 -3
  46. package/src/editor/plugins/createWithPatches.ts +9 -12
  47. package/src/editor/plugins/createWithPlaceholderBlock.ts +2 -2
  48. package/src/editor/plugins/createWithPortableTextBlockStyle.ts +13 -5
  49. package/src/editor/plugins/createWithPortableTextLists.ts +3 -4
  50. package/src/editor/plugins/createWithPortableTextMarkModel.ts +24 -10
  51. package/src/editor/plugins/createWithPortableTextSelections.ts +9 -10
  52. package/src/editor/plugins/createWithSchemaTypes.ts +13 -4
  53. package/src/editor/plugins/createWithUndoRedo.ts +3 -7
  54. package/src/editor/plugins/createWithUtils.ts +6 -6
  55. package/src/editor/plugins/index.ts +21 -11
  56. package/src/index.ts +9 -3
  57. package/src/types/editor.ts +33 -33
  58. package/src/types/options.ts +3 -3
  59. package/src/types/slate.ts +4 -4
  60. package/src/utils/__tests__/dmpToOperations.test.ts +4 -4
  61. package/src/utils/__tests__/operationToPatches.test.ts +62 -62
  62. package/src/utils/__tests__/patchToOperations.test.ts +40 -40
  63. package/src/utils/__tests__/ranges.test.ts +2 -2
  64. package/src/utils/__tests__/valueNormalization.test.tsx +14 -2
  65. package/src/utils/__tests__/values.test.ts +17 -17
  66. package/src/utils/applyPatch.ts +10 -12
  67. package/src/utils/getPortableTextMemberSchemaTypes.ts +8 -8
  68. package/src/utils/operationToPatches.ts +5 -9
  69. package/src/utils/paths.ts +5 -5
  70. package/src/utils/ranges.ts +4 -5
  71. package/src/utils/selection.ts +2 -2
  72. package/src/utils/ucs2Indices.ts +2 -2
  73. package/src/utils/validateValue.ts +3 -25
  74. package/src/utils/values.ts +7 -8
  75. package/src/utils/weakMaps.ts +2 -2
  76. package/src/utils/withChanges.ts +1 -1
  77. package/src/utils/withUndoRedo.ts +1 -1
  78. package/src/utils/withoutPatching.ts +1 -1
  79. package/src/editor/__tests__/utils.ts +0 -45
@@ -1,7 +1,7 @@
1
- import {describe, expect, it, jest} from '@jest/globals'
2
1
  import {isPortableTextTextBlock} from '@sanity/types'
3
2
  import {render, waitFor} from '@testing-library/react'
4
3
  import {createRef, type RefObject} from 'react'
4
+ import {describe, expect, it, vi} from 'vitest'
5
5
  import {
6
6
  PortableTextEditorTester,
7
7
  schemaType,
@@ -52,7 +52,7 @@ const initialValue = [
52
52
  describe('plugin:withEditableAPI: .getFragment()', () => {
53
53
  it('can get a Portable Text fragment of the current selection in a single block', async () => {
54
54
  const editorRef: RefObject<PortableTextEditor> = createRef()
55
- const onChange = jest.fn()
55
+ const onChange = vi.fn()
56
56
 
57
57
  render(
58
58
  <PortableTextEditorTester
@@ -93,7 +93,7 @@ describe('plugin:withEditableAPI: .getFragment()', () => {
93
93
 
94
94
  it('can get a Portable Text fragment of the current selection in multiple blocks', async () => {
95
95
  const editorRef: RefObject<PortableTextEditor> = createRef()
96
- const onChange = jest.fn()
96
+ const onChange = vi.fn()
97
97
 
98
98
  render(
99
99
  <PortableTextEditorTester
@@ -124,43 +124,43 @@ describe('plugin:withEditableAPI: .getFragment()', () => {
124
124
  PortableTextEditor.select(editorRef.current, initialSelection)
125
125
  const fragment = PortableTextEditor.getFragment(editorRef.current)
126
126
  expect(fragment).toMatchInlineSnapshot(`
127
- Array [
128
- Object {
127
+ [
128
+ {
129
129
  "_key": "a",
130
130
  "_type": "myTestBlockType",
131
- "children": Array [
132
- Object {
131
+ "children": [
132
+ {
133
133
  "_key": "a1",
134
134
  "_type": "span",
135
- "marks": Array [],
135
+ "marks": [],
136
136
  "text": "A",
137
137
  },
138
138
  ],
139
- "markDefs": Array [],
139
+ "markDefs": [],
140
140
  "style": "normal",
141
141
  },
142
- Object {
142
+ {
143
143
  "_key": "b",
144
144
  "_type": "myTestBlockType",
145
- "children": Array [
146
- Object {
145
+ "children": [
146
+ {
147
147
  "_key": "b1",
148
148
  "_type": "span",
149
- "marks": Array [],
149
+ "marks": [],
150
150
  "text": "Block B ",
151
151
  },
152
- Object {
152
+ {
153
153
  "_key": "b2",
154
154
  "_type": "someObject",
155
155
  },
156
- Object {
156
+ {
157
157
  "_key": "b3",
158
158
  "_type": "span",
159
- "marks": Array [],
159
+ "marks": [],
160
160
  "text": " contains",
161
161
  },
162
162
  ],
163
- "markDefs": Array [],
163
+ "markDefs": [],
164
164
  "style": "normal",
165
165
  },
166
166
  ]
@@ -1,6 +1,6 @@
1
- import {describe, expect, it, jest} from '@jest/globals'
2
1
  import {render, waitFor} from '@testing-library/react'
3
2
  import {createRef, type RefObject} from 'react'
3
+ import {describe, expect, it, vi} from 'vitest'
4
4
  import {
5
5
  PortableTextEditorTester,
6
6
  schemaType,
@@ -58,7 +58,7 @@ const emptyBlockSelection = {
58
58
  describe('plugin:withEditableAPI: .insertChild()', () => {
59
59
  it('inserts child nodes correctly', async () => {
60
60
  const editorRef: RefObject<PortableTextEditor> = createRef()
61
- const onChange = jest.fn()
61
+ const onChange = vi.fn()
62
62
 
63
63
  render(
64
64
  <PortableTextEditorTester
@@ -200,7 +200,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
200
200
  style: 'normal',
201
201
  },
202
202
  ]
203
- const onChange = jest.fn()
203
+ const onChange = vi.fn()
204
204
 
205
205
  render(
206
206
  <PortableTextEditorTester
@@ -248,7 +248,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
248
248
 
249
249
  it('should not add empty blank blocks: non-empty block', async () => {
250
250
  const editorRef: RefObject<PortableTextEditor> = createRef()
251
- const onChange = jest.fn()
251
+ const onChange = vi.fn()
252
252
 
253
253
  render(
254
254
  <PortableTextEditorTester
@@ -300,7 +300,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
300
300
 
301
301
  it('should be inserted before if focus is on start of block', async () => {
302
302
  const editorRef: RefObject<PortableTextEditor> = createRef()
303
- const onChange = jest.fn()
303
+ const onChange = vi.fn()
304
304
 
305
305
  render(
306
306
  <PortableTextEditorTester
@@ -358,7 +358,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
358
358
  ...initialValue,
359
359
  {_key: 'b', _type: 'someObject', color: 'red'},
360
360
  ]
361
- const onChange = jest.fn()
361
+ const onChange = vi.fn()
362
362
 
363
363
  render(
364
364
  <PortableTextEditorTester
@@ -414,7 +414,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
414
414
  ...initialValue,
415
415
  {_key: 'b', _type: 'someObject', color: 'red'},
416
416
  ]
417
- const onChange = jest.fn()
417
+ const onChange = vi.fn()
418
418
 
419
419
  render(
420
420
  <PortableTextEditorTester
@@ -465,7 +465,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
465
465
  it('should not add empty blank blocks: in new empty text block', async () => {
466
466
  const editorRef: RefObject<PortableTextEditor> = createRef()
467
467
  const value = [...initialValue, ...emptyTextBlock]
468
- const onChange = jest.fn()
468
+ const onChange = vi.fn()
469
469
 
470
470
  render(
471
471
  <PortableTextEditorTester
@@ -1,7 +1,7 @@
1
- import {describe, expect, it, jest} from '@jest/globals'
2
- import {type PortableTextBlock} from '@sanity/types'
1
+ import type {PortableTextBlock} from '@sanity/types'
3
2
  import {render, waitFor} from '@testing-library/react'
4
3
  import {createRef, type RefObject} from 'react'
4
+ import {describe, expect, it, vi} from 'vitest'
5
5
  import {
6
6
  PortableTextEditorTester,
7
7
  schemaType,
@@ -28,7 +28,7 @@ const INITIAL_VALUE: PortableTextBlock[] = [
28
28
  describe('plugin:withEditableAPI: .isSelectionsOverlapping', () => {
29
29
  it('returns true if the selections are partially overlapping', async () => {
30
30
  const editorRef: RefObject<PortableTextEditor> = createRef()
31
- const onChange = jest.fn()
31
+ const onChange = vi.fn()
32
32
  render(
33
33
  <PortableTextEditorTester
34
34
  onChange={onChange}
@@ -62,7 +62,7 @@ describe('plugin:withEditableAPI: .isSelectionsOverlapping', () => {
62
62
 
63
63
  it('returns true if the selections are fully overlapping', async () => {
64
64
  const editorRef: RefObject<PortableTextEditor> = createRef()
65
- const onChange = jest.fn()
65
+ const onChange = vi.fn()
66
66
  render(
67
67
  <PortableTextEditorTester
68
68
  onChange={onChange}
@@ -96,7 +96,7 @@ describe('plugin:withEditableAPI: .isSelectionsOverlapping', () => {
96
96
 
97
97
  it('return true if selection is fully inside another selection', async () => {
98
98
  const editorRef: RefObject<PortableTextEditor> = createRef()
99
- const onChange = jest.fn()
99
+ const onChange = vi.fn()
100
100
  render(
101
101
  <PortableTextEditorTester
102
102
  onChange={onChange}
@@ -130,7 +130,7 @@ describe('plugin:withEditableAPI: .isSelectionsOverlapping', () => {
130
130
 
131
131
  it('returns false if the selections are not overlapping', async () => {
132
132
  const editorRef: RefObject<PortableTextEditor> = createRef()
133
- const onChange = jest.fn()
133
+ const onChange = vi.fn()
134
134
  render(
135
135
  <PortableTextEditorTester
136
136
  onChange={onChange}
@@ -1,6 +1,6 @@
1
- import {describe, expect, it, jest} from '@jest/globals'
2
1
  import {render, waitFor} from '@testing-library/react'
3
2
  import {createRef, type RefObject} from 'react'
3
+ import {describe, expect, it, vi} from 'vitest'
4
4
  import {
5
5
  PortableTextEditorTester,
6
6
  schemaType,
@@ -42,7 +42,7 @@ describe('plugin:withPortableTextLists', () => {
42
42
  style: 'normal',
43
43
  },
44
44
  ]
45
- const onChange = jest.fn()
45
+ const onChange = vi.fn()
46
46
  await waitFor(() => {
47
47
  render(
48
48
  <PortableTextEditorTester
@@ -1,13 +1,12 @@
1
- import {describe, expect, it, jest} from '@jest/globals'
2
- /* eslint-disable max-nested-callbacks */
3
1
  import {render, waitFor} from '@testing-library/react'
4
2
  import {createRef, type RefObject} from 'react'
3
+ import {describe, expect, it, vi} from 'vitest'
5
4
  import {
6
5
  PortableTextEditorTester,
7
6
  schemaType,
8
7
  schemaTypeWithColorAndLink,
9
8
  } from '../../__tests__/PortableTextEditorTester'
10
- import {type EditorSelection} from '../../../types/editor'
9
+ import type {EditorSelection} from '../../../types/editor'
11
10
  import {PortableTextEditor} from '../../PortableTextEditor'
12
11
 
13
12
  describe('plugin:withPortableTextMarksModel', () => {
@@ -30,7 +29,7 @@ describe('plugin:withPortableTextMarksModel', () => {
30
29
  style: 'normal',
31
30
  },
32
31
  ]
33
- const onChange = jest.fn()
32
+ const onChange = vi.fn()
34
33
  await waitFor(() => {
35
34
  render(
36
35
  <PortableTextEditorTester
@@ -51,21 +50,21 @@ describe('plugin:withPortableTextMarksModel', () => {
51
50
  })
52
51
  PortableTextEditor.toggleMark(editor, 'strong')
53
52
  expect(PortableTextEditor.getValue(editor)).toMatchInlineSnapshot(`
54
- Array [
55
- Object {
53
+ [
54
+ {
56
55
  "_key": "a",
57
56
  "_type": "myTestBlockType",
58
- "children": Array [
59
- Object {
57
+ "children": [
58
+ {
60
59
  "_key": "a1",
61
60
  "_type": "span",
62
- "marks": Array [
61
+ "marks": [
63
62
  "strong",
64
63
  ],
65
64
  "text": "1234",
66
65
  },
67
66
  ],
68
- "markDefs": Array [],
67
+ "markDefs": [],
69
68
  "style": "normal",
70
69
  },
71
70
  ]
@@ -80,35 +79,35 @@ describe('plugin:withPortableTextMarksModel', () => {
80
79
  PortableTextEditor.toggleMark(editorRef.current, 'strong')
81
80
  expect(PortableTextEditor.getValue(editorRef.current))
82
81
  .toMatchInlineSnapshot(`
83
- Array [
84
- Object {
82
+ [
83
+ {
85
84
  "_key": "a",
86
85
  "_type": "myTestBlockType",
87
- "children": Array [
88
- Object {
86
+ "children": [
87
+ {
89
88
  "_key": "a1",
90
89
  "_type": "span",
91
- "marks": Array [
90
+ "marks": [
92
91
  "strong",
93
92
  ],
94
93
  "text": "1",
95
94
  },
96
- Object {
95
+ {
97
96
  "_key": "2",
98
97
  "_type": "span",
99
- "marks": Array [],
98
+ "marks": [],
100
99
  "text": "23",
101
100
  },
102
- Object {
101
+ {
103
102
  "_key": "1",
104
103
  "_type": "span",
105
- "marks": Array [
104
+ "marks": [
106
105
  "strong",
107
106
  ],
108
107
  "text": "4",
109
108
  },
110
109
  ],
111
- "markDefs": Array [],
110
+ "markDefs": [],
112
111
  "style": "normal",
113
112
  },
114
113
  ]
@@ -123,21 +122,21 @@ describe('plugin:withPortableTextMarksModel', () => {
123
122
  })
124
123
  PortableTextEditor.toggleMark(editor, 'strong')
125
124
  expect(PortableTextEditor.getValue(editor)).toMatchInlineSnapshot(`
126
- Array [
127
- Object {
125
+ [
126
+ {
128
127
  "_key": "a",
129
128
  "_type": "myTestBlockType",
130
- "children": Array [
131
- Object {
129
+ "children": [
130
+ {
132
131
  "_key": "a1",
133
132
  "_type": "span",
134
- "marks": Array [
133
+ "marks": [
135
134
  "strong",
136
135
  ],
137
136
  "text": "1234",
138
137
  },
139
138
  ],
140
- "markDefs": Array [],
139
+ "markDefs": [],
141
140
  "style": "normal",
142
141
  },
143
142
  ]
@@ -176,7 +175,7 @@ Array [
176
175
  style: 'normal',
177
176
  },
178
177
  ]
179
- const onChange = jest.fn()
178
+ const onChange = vi.fn()
180
179
 
181
180
  render(
182
181
  <PortableTextEditorTester
@@ -308,7 +307,7 @@ Array [
308
307
  offset: 0,
309
308
  },
310
309
  }
311
- const onChange = jest.fn()
310
+ const onChange = vi.fn()
312
311
  await waitFor(() => {
313
312
  render(
314
313
  <PortableTextEditorTester
@@ -325,47 +324,47 @@ Array [
325
324
  PortableTextEditor.select(editor, sel)
326
325
  PortableTextEditor.delete(editor, sel)
327
326
  expect(PortableTextEditor.getValue(editor)).toMatchInlineSnapshot(`
328
- Array [
329
- Object {
327
+ [
328
+ {
330
329
  "_key": "5fc57af23597",
331
330
  "_type": "myTestBlockType",
332
- "children": Array [
333
- Object {
331
+ "children": [
332
+ {
334
333
  "_key": "be1c67c6971a",
335
334
  "_type": "span",
336
- "marks": Array [],
335
+ "marks": [],
337
336
  "text": "This is a ",
338
337
  },
339
- Object {
338
+ {
340
339
  "_key": "11c8c9f783a8",
341
340
  "_type": "span",
342
- "marks": Array [
341
+ "marks": [
343
342
  "fde1fd54b544",
344
343
  ],
345
344
  "text": "link",
346
345
  },
347
- Object {
346
+ {
348
347
  "_key": "576c748e0cd2",
349
348
  "_type": "span",
350
- "marks": Array [],
349
+ "marks": [],
351
350
  "text": "This is ",
352
351
  },
353
- Object {
352
+ {
354
353
  "_key": "f3d73d3833bf",
355
354
  "_type": "span",
356
- "marks": Array [
355
+ "marks": [
357
356
  "7b6d3d5de30c",
358
357
  ],
359
358
  "text": "another",
360
359
  },
361
360
  ],
362
- "markDefs": Array [
363
- Object {
361
+ "markDefs": [
362
+ {
364
363
  "_key": "fde1fd54b544",
365
364
  "_type": "link",
366
365
  "url": "1",
367
366
  },
368
- Object {
367
+ {
369
368
  "_key": "7b6d3d5de30c",
370
369
  "_type": "link",
371
370
  "url": "2",
@@ -420,7 +419,7 @@ Array [
420
419
  focus: {path: [{_key: 'bb'}, 'children', {_key: 'sb'}], offset: 0},
421
420
  anchor: {path: [{_key: 'bb'}, 'children', {_key: 'sb'}], offset: 0},
422
421
  }
423
- const onChange = jest.fn()
422
+ const onChange = vi.fn()
424
423
 
425
424
  render(
426
425
  <PortableTextEditorTester
@@ -523,7 +522,7 @@ Array [
523
522
  style: 'normal',
524
523
  },
525
524
  ]
526
- const onChange = jest.fn()
525
+ const onChange = vi.fn()
527
526
 
528
527
  render(
529
528
  <PortableTextEditorTester
@@ -593,7 +592,7 @@ Array [
593
592
  style: 'normal',
594
593
  },
595
594
  ]
596
- const onChange = jest.fn()
595
+ const onChange = vi.fn()
597
596
  await waitFor(() => {
598
597
  render(
599
598
  <PortableTextEditorTester
@@ -648,7 +647,7 @@ Array [
648
647
  style: 'normal',
649
648
  },
650
649
  ]
651
- const onChange = jest.fn()
650
+ const onChange = vi.fn()
652
651
  await waitFor(() => {
653
652
  render(
654
653
  <PortableTextEditorTester
@@ -704,7 +703,7 @@ Array [
704
703
  style: 'normal',
705
704
  },
706
705
  ]
707
- const onChange = jest.fn()
706
+ const onChange = vi.fn()
708
707
  await waitFor(() => {
709
708
  render(
710
709
  <PortableTextEditorTester
@@ -739,7 +738,6 @@ Array [
739
738
  },
740
739
  })
741
740
 
742
- // // eslint-disable-next-line max-nested-callbacks
743
741
  const linkType = editorRef.current.schemaTypes.annotations.find(
744
742
  (a) => a.name === 'link',
745
743
  )
@@ -861,7 +859,7 @@ Array [
861
859
  ],
862
860
  },
863
861
  ]
864
- const onChange = jest.fn()
862
+ const onChange = vi.fn()
865
863
  await waitFor(() => {
866
864
  render(
867
865
  <PortableTextEditorTester
@@ -1,6 +1,6 @@
1
- import {describe, expect, it, jest} from '@jest/globals'
2
1
  import {render, waitFor} from '@testing-library/react'
3
2
  import {createRef, type RefObject} from 'react'
3
+ import {describe, expect, it, vi} from 'vitest'
4
4
  import {
5
5
  PortableTextEditorTester,
6
6
  schemaType,
@@ -41,7 +41,7 @@ const initialValue = [
41
41
  describe('plugin:withPortableTextSelections', () => {
42
42
  it('will report that a selection is made backward', async () => {
43
43
  const editorRef: RefObject<PortableTextEditor> = createRef()
44
- const onChange = jest.fn()
44
+ const onChange = vi.fn()
45
45
  render(
46
46
  <PortableTextEditorTester
47
47
  onChange={onChange}
@@ -54,34 +54,45 @@ describe('plugin:withPortableTextSelections', () => {
54
54
  anchor: {path: [{_key: 'b'}, 'children', {_key: 'b1'}], offset: 9},
55
55
  focus: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 7},
56
56
  }
57
+
58
+ await waitFor(() => {
59
+ if (editorRef.current) {
60
+ expect(onChange).toHaveBeenCalledWith({
61
+ type: 'value',
62
+ value: initialValue,
63
+ })
64
+ expect(onChange).toHaveBeenCalledWith({type: 'ready'})
65
+ }
66
+ })
67
+
57
68
  await waitFor(() => {
58
69
  if (editorRef.current) {
59
70
  PortableTextEditor.focus(editorRef.current)
60
71
  PortableTextEditor.select(editorRef.current, initialSelection)
61
72
  expect(PortableTextEditor.getSelection(editorRef.current))
62
73
  .toMatchInlineSnapshot(`
63
- Object {
64
- "anchor": Object {
74
+ {
75
+ "anchor": {
65
76
  "offset": 9,
66
- "path": Array [
67
- Object {
77
+ "path": [
78
+ {
68
79
  "_key": "b",
69
80
  },
70
81
  "children",
71
- Object {
82
+ {
72
83
  "_key": "b1",
73
84
  },
74
85
  ],
75
86
  },
76
87
  "backward": true,
77
- "focus": Object {
88
+ "focus": {
78
89
  "offset": 7,
79
- "path": Array [
80
- Object {
90
+ "path": [
91
+ {
81
92
  "_key": "a",
82
93
  },
83
94
  "children",
84
- Object {
95
+ {
85
96
  "_key": "a1",
86
97
  },
87
98
  ],
@@ -1,6 +1,6 @@
1
- import {describe, expect, it, jest} from '@jest/globals'
2
1
  import {render, waitFor} from '@testing-library/react'
3
2
  import {createRef, type RefObject} from 'react'
3
+ import {describe, expect, it, vi} from 'vitest'
4
4
  import {
5
5
  PortableTextEditorTester,
6
6
  schemaType,
@@ -46,7 +46,7 @@ const initialSelection = {
46
46
  describe('plugin:withUndoRedo', () => {
47
47
  it('preserves the keys when undoing ', async () => {
48
48
  const editorRef: RefObject<PortableTextEditor> = createRef()
49
- const onChange = jest.fn()
49
+ const onChange = vi.fn()
50
50
  render(
51
51
  <PortableTextEditorTester
52
52
  onChange={onChange}
@@ -77,19 +77,19 @@ describe('plugin:withUndoRedo', () => {
77
77
  )
78
78
  expect(PortableTextEditor.getValue(editorRef.current))
79
79
  .toMatchInlineSnapshot(`
80
- Array [
81
- Object {
80
+ [
81
+ {
82
82
  "_key": "a",
83
83
  "_type": "myTestBlockType",
84
- "children": Array [
85
- Object {
84
+ "children": [
85
+ {
86
86
  "_key": "a1",
87
87
  "_type": "span",
88
- "marks": Array [],
88
+ "marks": [],
89
89
  "text": "Block A",
90
90
  },
91
91
  ],
92
- "markDefs": Array [],
92
+ "markDefs": [],
93
93
  "style": "normal",
94
94
  },
95
95
  ]
@@ -103,7 +103,7 @@ describe('plugin:withUndoRedo', () => {
103
103
  })
104
104
  it('preserves the keys when redoing ', async () => {
105
105
  const editorRef: RefObject<PortableTextEditor> = createRef()
106
- const onChange = jest.fn()
106
+ const onChange = vi.fn()
107
107
 
108
108
  render(
109
109
  <PortableTextEditorTester
@@ -19,13 +19,13 @@ import {
19
19
  Transforms,
20
20
  } from 'slate'
21
21
  import {ReactEditor} from 'slate-react'
22
- import {type DOMNode} from 'slate-react/dist/utils/dom'
23
- import {
24
- type EditableAPI,
25
- type EditableAPIDeleteOptions,
26
- type EditorSelection,
27
- type PortableTextMemberSchemaTypes,
28
- type PortableTextSlateEditor,
22
+ import type {DOMNode} from 'slate-react/dist/utils/dom'
23
+ import type {
24
+ EditableAPI,
25
+ EditableAPIDeleteOptions,
26
+ EditorSelection,
27
+ PortableTextMemberSchemaTypes,
28
+ PortableTextSlateEditor,
29
29
  } from '../../types/editor'
30
30
  import {debugWithName} from '../../utils/debug'
31
31
  import {toPortableTextRange, toSlateRange} from '../../utils/ranges'
@@ -38,7 +38,7 @@ import {
38
38
  KEY_TO_VALUE_ELEMENT,
39
39
  SLATE_TO_PORTABLE_TEXT_RANGE,
40
40
  } from '../../utils/weakMaps'
41
- import {type PortableTextEditor} from '../PortableTextEditor'
41
+ import type {PortableTextEditor} from '../PortableTextEditor'
42
42
 
43
43
  const debug = debugWithName('API:editable')
44
44
 
@@ -1,18 +1,16 @@
1
- /* eslint-disable max-statements */
2
- /* eslint-disable complexity */
3
1
  import {isPortableTextSpan, isPortableTextTextBlock} from '@sanity/types'
4
2
  import {isHotkey} from 'is-hotkey-esm'
5
- import {type KeyboardEvent} from 'react'
3
+ import type {KeyboardEvent} from 'react'
6
4
  import {Editor, Node, Path, Range, Transforms} from 'slate'
7
- import {type ReactEditor} from 'slate-react'
8
- import {
9
- type PortableTextMemberSchemaTypes,
10
- type PortableTextSlateEditor,
5
+ import type {ReactEditor} from 'slate-react'
6
+ import type {
7
+ PortableTextMemberSchemaTypes,
8
+ PortableTextSlateEditor,
11
9
  } from '../../types/editor'
12
- import {type HotkeyOptions} from '../../types/options'
13
- import {type SlateTextBlock, type VoidElement} from '../../types/slate'
10
+ import type {HotkeyOptions} from '../../types/options'
11
+ import type {SlateTextBlock, VoidElement} from '../../types/slate'
14
12
  import {debugWithName} from '../../utils/debug'
15
- import {type PortableTextEditor} from '../PortableTextEditor'
13
+ import type {PortableTextEditor} from '../PortableTextEditor'
16
14
 
17
15
  const debug = debugWithName('plugin:withHotKeys')
18
16
 
@@ -42,7 +40,6 @@ export function createWithHotkeys(
42
40
  // Wire up custom marks hotkeys
43
41
  Object.keys(activeHotkeys).forEach((cat) => {
44
42
  if (cat === 'marks') {
45
- // eslint-disable-next-line guard-for-in
46
43
  for (const hotkey in activeHotkeys[cat]) {
47
44
  if (reservedHotkeys.includes(hotkey)) {
48
45
  throw new Error(`The hotkey ${hotkey} is reserved!`)
@@ -59,7 +56,6 @@ export function createWithHotkeys(
59
56
  }
60
57
  }
61
58
  if (cat === 'custom') {
62
- // eslint-disable-next-line guard-for-in
63
59
  for (const hotkey in activeHotkeys[cat]) {
64
60
  if (reservedHotkeys.includes(hotkey)) {
65
61
  throw new Error(`The hotkey ${hotkey} is reserved!`)