@portabletext/editor 1.14.2 → 1.15.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 (30) hide show
  1. package/lib/index.cjs +30 -21
  2. package/lib/index.cjs.map +1 -1
  3. package/lib/index.d.cts +15 -15
  4. package/lib/index.d.ts +15 -15
  5. package/lib/index.js +30 -21
  6. package/lib/index.js.map +1 -1
  7. package/package.json +7 -7
  8. package/src/editor/__tests__/PortableTextEditor.test.tsx +6 -6
  9. package/src/editor/__tests__/RangeDecorations.test.tsx +1 -1
  10. package/src/editor/__tests__/handleClick.test.tsx +4 -4
  11. package/src/editor/__tests__/insert-block.test.tsx +3 -3
  12. package/src/editor/__tests__/pteWarningsSelfSolving.test.tsx +6 -6
  13. package/src/editor/__tests__/self-solving.test.tsx +1 -1
  14. package/src/editor/components/DraggableBlock.tsx +1 -1
  15. package/src/editor/components/Element.tsx +8 -2
  16. package/src/editor/components/Leaf.tsx +1 -1
  17. package/src/editor/create-editor.ts +18 -29
  18. package/src/editor/hooks/useSyncValue.test.tsx +2 -2
  19. package/src/editor/hooks/useSyncValue.ts +2 -2
  20. package/src/editor/nodes/DefaultObject.tsx +1 -0
  21. package/src/editor/plugins/__tests__/withEditableAPIDelete.test.tsx +4 -4
  22. package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +2 -2
  23. package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +7 -7
  24. package/src/editor/plugins/__tests__/withEditableAPISelectionsOverlapping.test.tsx +4 -4
  25. package/src/editor/plugins/__tests__/withPortableTextLists.test.tsx +1 -1
  26. package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +9 -9
  27. package/src/editor/plugins/__tests__/withPortableTextSelections.test.tsx +1 -1
  28. package/src/editor/plugins/__tests__/withUndoRedo.test.tsx +2 -2
  29. package/src/types/editor.ts +14 -13
  30. package/src/utils/__tests__/valueNormalization.test.tsx +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.14.2",
3
+ "version": "1.15.0",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -74,8 +74,8 @@
74
74
  "@types/debug": "^4.1.5",
75
75
  "@types/lodash": "^4.17.13",
76
76
  "@types/lodash.startcase": "^4.4.9",
77
- "@types/react": "^18.3.14",
78
- "@types/react-dom": "^18.3.2",
77
+ "@types/react": "^19.0.0",
78
+ "@types/react-dom": "^19.0.1",
79
79
  "@typescript-eslint/eslint-plugin": "^8.17.0",
80
80
  "@typescript-eslint/parser": "^8.17.0",
81
81
  "@vitejs/plugin-react": "^4.3.4",
@@ -86,12 +86,12 @@
86
86
  "eslint-plugin-react-compiler": "19.0.0-beta-df7b47d-20241124",
87
87
  "eslint-plugin-react-hooks": "^5.1.0",
88
88
  "jsdom": "^25.0.1",
89
- "react": "^18.3.1",
90
- "react-dom": "^18.3.1",
89
+ "react": "^19.0.0",
90
+ "react-dom": "^19.0.0",
91
91
  "rxjs": "^7.8.1",
92
92
  "styled-components": "^6.1.13",
93
93
  "typescript": "5.7.2",
94
- "vite": "^5.4.11",
94
+ "vite": "^6.0.3",
95
95
  "vitest": "^2.1.8",
96
96
  "vitest-browser-react": "^0.0.4",
97
97
  "racejar": "1.1.0"
@@ -100,7 +100,7 @@
100
100
  "@sanity/block-tools": "^3.66.1",
101
101
  "@sanity/schema": "^3.66.1",
102
102
  "@sanity/types": "^3.66.1",
103
- "react": "^16.9 || ^17 || ^18",
103
+ "react": "^16.9 || ^17 || ^18 || ^19",
104
104
  "rxjs": "^7.8.1",
105
105
  "styled-components": "^6.1.13"
106
106
  },
@@ -17,7 +17,7 @@ const renderPlaceholder = () => 'Jot something down here'
17
17
 
18
18
  describe('initialization', () => {
19
19
  it('receives initial onChange events and has custom placeholder', async () => {
20
- const editorRef: RefObject<PortableTextEditor> = createRef()
20
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
21
21
  const onChange = vi.fn()
22
22
  const {container} = render(
23
23
  <PortableTextEditorTester
@@ -113,7 +113,7 @@ describe('initialization', () => {
113
113
  })
114
114
 
115
115
  it('takes initial selection from props', async () => {
116
- const editorRef: RefObject<PortableTextEditor> = createRef()
116
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
117
117
  const initialValue = [helloBlock]
118
118
  const initialSelection: EditorSelection = {
119
119
  anchor: {path: [{_key: '123'}, 'children', {_key: '567'}], offset: 2},
@@ -152,7 +152,7 @@ describe('initialization', () => {
152
152
  })
153
153
 
154
154
  it('updates editor selection from new prop and keeps object equality in editor.getSelection()', async () => {
155
- const editorRef: RefObject<PortableTextEditor> = createRef()
155
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
156
156
  const initialValue = [helloBlock]
157
157
  const initialSelection: EditorSelection = {
158
158
  anchor: {path: [{_key: '123'}, 'children', {_key: '567'}], offset: 0},
@@ -217,7 +217,7 @@ describe('initialization', () => {
217
217
  })
218
218
 
219
219
  it('handles empty array value', async () => {
220
- const editorRef: RefObject<PortableTextEditor> = createRef()
220
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
221
221
  const initialValue: PortableTextBlock[] = []
222
222
  const initialSelection: EditorSelection = {
223
223
  anchor: {path: [{_key: '123'}, 'children', {_key: '567'}], offset: 2},
@@ -260,7 +260,7 @@ describe('initialization', () => {
260
260
  })
261
261
  })
262
262
  it('validates a non-initial value', async () => {
263
- const editorRef: RefObject<PortableTextEditor> = createRef()
263
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
264
264
  let value: PortableTextBlock[] = [helloBlock]
265
265
  const initialSelection: EditorSelection = {
266
266
  anchor: {path: [{_key: '123'}, 'children', {_key: '567'}], offset: 2},
@@ -338,7 +338,7 @@ describe('initialization', () => {
338
338
  })
339
339
  })
340
340
  it("doesn't crash when containing a invalid block somewhere inside the content", async () => {
341
- const editorRef: RefObject<PortableTextEditor> = createRef()
341
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
342
342
  const initialValue: PortableTextBlock[] = [
343
343
  helloBlock,
344
344
  {
@@ -22,7 +22,7 @@ const RangeDecorationTestComponent = ({children}: {children?: ReactNode}) => {
22
22
 
23
23
  describe('RangeDecorations', () => {
24
24
  it('only render range decorations as necessary', async () => {
25
- const editorRef: RefObject<PortableTextEditor> = createRef()
25
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
26
26
  const onChange = vi.fn()
27
27
  const value = [helloBlock]
28
28
  let rangeDecorations: RangeDecoration[] = [
@@ -53,7 +53,7 @@ describe('adds empty text block if its needed', () => {
53
53
  anchor: {path: [{_key: 'b'}], offset: 0},
54
54
  }
55
55
 
56
- const editorRef: RefObject<PortableTextEditor> = createRef()
56
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
57
57
  const onChange = vi.fn()
58
58
  const component = render(
59
59
  <PortableTextEditorTester
@@ -115,7 +115,7 @@ describe('adds empty text block if its needed', () => {
115
115
  anchor: {path: [{_key: 'b'}], offset: 0},
116
116
  }
117
117
 
118
- const editorRef: RefObject<PortableTextEditor> = createRef()
118
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
119
119
  const onChange = vi.fn()
120
120
  const component = render(
121
121
  <PortableTextEditorTester
@@ -170,7 +170,7 @@ describe('adds empty text block if its needed', () => {
170
170
  anchor: {path: [{_key: 'b'}, 'children', {_key: 'b1'}], offset: 0},
171
171
  }
172
172
 
173
- const editorRef: RefObject<PortableTextEditor> = createRef()
173
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
174
174
  const onChange = vi.fn()
175
175
  const component = render(
176
176
  <PortableTextEditorTester
@@ -236,7 +236,7 @@ describe('adds empty text block if its needed', () => {
236
236
  anchor: {path: [{_key: 'c'}], offset: 0},
237
237
  }
238
238
 
239
- const editorRef: RefObject<PortableTextEditor> = createRef()
239
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
240
240
  const onChange = vi.fn()
241
241
  const component = render(
242
242
  <PortableTextEditorTester
@@ -20,7 +20,7 @@ const schema = Schema.compile({
20
20
 
21
21
  describe(PortableTextEditor.insertBlock.name, () => {
22
22
  test('Scenario: Inserting a custom block without a selection #1', async () => {
23
- const editorRef: RefObject<PortableTextEditor> = createRef()
23
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
24
24
  const emptyTextBlock: PortableTextBlock = {
25
25
  _key: 'ba',
26
26
  _type: 'block',
@@ -88,7 +88,7 @@ describe(PortableTextEditor.insertBlock.name, () => {
88
88
  })
89
89
 
90
90
  test('Scenario: Inserting a custom block without a selection #2', async () => {
91
- const editorRef: RefObject<PortableTextEditor> = createRef()
91
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
92
92
  const nonEmptyTextBlock: PortableTextBlock = {
93
93
  _key: 'ba',
94
94
  _type: 'block',
@@ -158,7 +158,7 @@ describe(PortableTextEditor.insertBlock.name, () => {
158
158
  })
159
159
 
160
160
  test('Scenario: Replacing an empty text block with a custom block', async () => {
161
- const editorRef: RefObject<PortableTextEditor> = createRef()
161
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
162
162
  const emptyTextBlock: PortableTextBlock = {
163
163
  _key: 'ba',
164
164
  _type: 'block',
@@ -7,7 +7,7 @@ import {PortableTextEditorTester, schemaType} from './PortableTextEditorTester'
7
7
 
8
8
  describe('when PTE would display warnings, instead it self solves', () => {
9
9
  it('when child at index is missing required _key in block with _key', async () => {
10
- const editorRef: RefObject<PortableTextEditor> = createRef()
10
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
11
11
  const initialValue = [
12
12
  {
13
13
  _key: 'abc',
@@ -63,7 +63,7 @@ describe('when PTE would display warnings, instead it self solves', () => {
63
63
  })
64
64
 
65
65
  it('self-solves missing .markDefs', async () => {
66
- const editorRef: RefObject<PortableTextEditor> = createRef()
66
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
67
67
  const initialValue = [
68
68
  {
69
69
  _key: 'abc',
@@ -120,7 +120,7 @@ describe('when PTE would display warnings, instead it self solves', () => {
120
120
  })
121
121
 
122
122
  it('adds missing .children', async () => {
123
- const editorRef: RefObject<PortableTextEditor> = createRef()
123
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
124
124
  const initialValue = [
125
125
  {
126
126
  _key: 'abc',
@@ -191,7 +191,7 @@ describe('when PTE would display warnings, instead it self solves', () => {
191
191
  })
192
192
 
193
193
  it('removes orphaned marks', async () => {
194
- const editorRef: RefObject<PortableTextEditor> = createRef()
194
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
195
195
  const initialValue = [
196
196
  {
197
197
  _key: 'abc',
@@ -249,7 +249,7 @@ describe('when PTE would display warnings, instead it self solves', () => {
249
249
  })
250
250
 
251
251
  it('removes orphaned marksDefs', async () => {
252
- const editorRef: RefObject<PortableTextEditor> = createRef()
252
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
253
253
  const initialValue = [
254
254
  {
255
255
  _key: 'abc',
@@ -313,7 +313,7 @@ describe('when PTE would display warnings, instead it self solves', () => {
313
313
  })
314
314
 
315
315
  it('allows empty array of blocks', async () => {
316
- const editorRef: RefObject<PortableTextEditor> = createRef()
316
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
317
317
  const initialValue = [] as PortableTextBlock[]
318
318
 
319
319
  const onChange = vi.fn()
@@ -40,7 +40,7 @@ function span(
40
40
 
41
41
  describe('Feature: Self-solving', () => {
42
42
  it('Scenario: Missing .markDefs and .marks are added after the editor is made dirty', async () => {
43
- const editorRef: RefObject<PortableTextEditor> = createRef()
43
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
44
44
  const onChange = vi.fn<OnChange>()
45
45
  const initialValue = [
46
46
  block({
@@ -42,7 +42,7 @@ export const DraggableBlock = ({
42
42
  blockRef,
43
43
  }: DraggableBlockProps) => {
44
44
  const editor = useSlateStatic()
45
- const dragGhostRef: MutableRefObject<undefined | HTMLElement> = useRef()
45
+ const dragGhostRef = useRef<HTMLElement>(undefined)
46
46
  const [isDragOver, setIsDragOver] = useState(false)
47
47
  const isVoid = useMemo(
48
48
  () => Editor.isVoid(editor, element),
@@ -4,7 +4,13 @@ import type {
4
4
  PortableTextObject,
5
5
  PortableTextTextBlock,
6
6
  } from '@sanity/types'
7
- import {useMemo, useRef, type FunctionComponent, type ReactElement} from 'react'
7
+ import {
8
+ useMemo,
9
+ useRef,
10
+ type FunctionComponent,
11
+ type JSX,
12
+ type ReactElement,
13
+ } from 'react'
8
14
  import {Editor, Range, Element as SlateElement} from 'slate'
9
15
  import {
10
16
  ReactEditor,
@@ -40,7 +46,7 @@ const EMPTY_ANNOTATIONS: PortableTextObject[] = []
40
46
  */
41
47
  export interface ElementProps {
42
48
  attributes: RenderElementProps['attributes']
43
- children: ReactElement
49
+ children: ReactElement<any>
44
50
  element: SlateElement
45
51
  schemaTypes: PortableTextMemberSchemaTypes
46
52
  readOnly: boolean
@@ -39,7 +39,7 @@ const EMPTY_MARKS: string[] = []
39
39
  */
40
40
  export interface LeafProps extends RenderLeafProps {
41
41
  editorActor: EditorActor
42
- children: ReactElement
42
+ children: ReactElement<any>
43
43
  schemaTypes: PortableTextMemberSchemaTypes
44
44
  renderAnnotation?: RenderAnnotationFunction
45
45
  renderChild?: RenderChildFunction
@@ -4,7 +4,7 @@ import type {
4
4
  PortableTextBlock,
5
5
  } from '@sanity/types'
6
6
  import {useActorRef} from '@xstate/react'
7
- import {useCallback, useMemo} from 'react'
7
+ import {useMemo} from 'react'
8
8
  import {
9
9
  createActor,
10
10
  type ActorRef,
@@ -101,7 +101,7 @@ export function createEditor(config: EditorConfig): Editor {
101
101
  on: (event, listener) =>
102
102
  editorActor.on(
103
103
  event,
104
- // @ts-ignore
104
+ // @ts-expect-error
105
105
  listener,
106
106
  ),
107
107
  _internal: {
@@ -116,38 +116,27 @@ export function useCreateEditor(config: EditorConfig): Editor {
116
116
  const editorActor = useActorRef(editorMachine, {
117
117
  input: editorConfigToMachineInput(config),
118
118
  })
119
- const slateEditor = createSlateEditor({editorActor})
120
- const editable = useMemo(
121
- () => createEditableAPI(slateEditor.instance, editorActor),
122
- [slateEditor.instance, editorActor],
123
- )
124
- const send = useCallback(
125
- (event: EditorEvent) => {
126
- editorActor.send(event)
127
- },
128
- [editorActor],
129
- )
130
- const on = useCallback<Editor['on']>(
131
- (event, listener) =>
132
- editorActor.on(
133
- event,
134
- // @ts-ignore
135
- listener,
136
- ),
137
- [editorActor],
138
- )
139
- const editor: Editor = useMemo(
140
- () => ({
141
- send,
142
- on,
119
+ const editor: Editor = useMemo(() => {
120
+ const slateEditor = createSlateEditor({editorActor})
121
+ const editable = createEditableAPI(slateEditor.instance, editorActor)
122
+
123
+ return {
124
+ send: (event: EditorEvent) => {
125
+ editorActor.send(event)
126
+ },
127
+ on: (event, listener) =>
128
+ editorActor.on(
129
+ event,
130
+ // @ts-expect-error
131
+ listener,
132
+ ),
143
133
  _internal: {
144
134
  editable,
145
135
  editorActor,
146
136
  slateEditor,
147
137
  },
148
- }),
149
- [send, on, editable, editorActor, slateEditor],
150
- )
138
+ }
139
+ }, [editorActor])
151
140
 
152
141
  return editor
153
142
  }
@@ -26,7 +26,7 @@ const initialValue = [
26
26
 
27
27
  describe('useSyncValue', () => {
28
28
  it('updates span text', async () => {
29
- const editorRef: RefObject<PortableTextEditor> = createRef()
29
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
30
30
  const onChange = vi.fn()
31
31
  const syncedValue = [
32
32
  {
@@ -69,7 +69,7 @@ describe('useSyncValue', () => {
69
69
  })
70
70
  })
71
71
  it('replaces span nodes with different keys inside the same children array', async () => {
72
- const editorRef: RefObject<PortableTextEditor> = createRef()
72
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
73
73
  const onChange = vi.fn()
74
74
  const syncedValue = [
75
75
  {
@@ -53,9 +53,9 @@ export function useSyncValue(
53
53
  ) => void {
54
54
  const {editorActor, portableTextEditor, readOnly, slateEditor} = props
55
55
  const schemaTypes = editorActor.getSnapshot().context.schema
56
- const previousValue = useRef<PortableTextBlock[] | undefined>()
56
+ const previousValue = useRef<PortableTextBlock[]>(undefined)
57
57
  const updateValueFunctionRef =
58
- useRef<(value: PortableTextBlock[] | undefined) => void>()
58
+ useRef<(value: PortableTextBlock[] | undefined) => void>(undefined)
59
59
 
60
60
  const updateFromCurrentValue = useCallback(() => {
61
61
  const currentValue = CURRENT_VALUE.get(portableTextEditor)
@@ -1,4 +1,5 @@
1
1
  import type {PortableTextBlock, PortableTextChild} from '@sanity/types'
2
+ import type {JSX} from 'react'
2
3
 
3
4
  type Props = {
4
5
  value: PortableTextBlock | PortableTextChild
@@ -45,7 +45,7 @@ const initialSelection = {
45
45
 
46
46
  describe('plugin:withEditableAPI: .delete()', () => {
47
47
  it('deletes block', async () => {
48
- const editorRef: RefObject<PortableTextEditor> = createRef()
48
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
49
49
  const onChange = vi.fn()
50
50
  render(
51
51
  <PortableTextEditorTester
@@ -99,7 +99,7 @@ describe('plugin:withEditableAPI: .delete()', () => {
99
99
  })
100
100
 
101
101
  it('deletes all the blocks, but leaves a placeholder block', async () => {
102
- const editorRef: RefObject<PortableTextEditor> = createRef()
102
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
103
103
  const onChange = vi.fn()
104
104
  render(
105
105
  <PortableTextEditorTester
@@ -157,7 +157,7 @@ describe('plugin:withEditableAPI: .delete()', () => {
157
157
  })
158
158
 
159
159
  it('deletes children', async () => {
160
- const editorRef: RefObject<PortableTextEditor> = createRef()
160
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
161
161
  const onChange = vi.fn()
162
162
 
163
163
  render(
@@ -238,7 +238,7 @@ describe('plugin:withEditableAPI: .delete()', () => {
238
238
  })
239
239
 
240
240
  it('deletes selected', async () => {
241
- const editorRef: RefObject<PortableTextEditor> = createRef()
241
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
242
242
  const onChange = vi.fn()
243
243
 
244
244
  render(
@@ -51,7 +51,7 @@ const initialValue = [
51
51
 
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
- const editorRef: RefObject<PortableTextEditor> = createRef()
54
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
55
55
  const onChange = vi.fn()
56
56
 
57
57
  render(
@@ -92,7 +92,7 @@ describe('plugin:withEditableAPI: .getFragment()', () => {
92
92
  })
93
93
 
94
94
  it('can get a Portable Text fragment of the current selection in multiple blocks', async () => {
95
- const editorRef: RefObject<PortableTextEditor> = createRef()
95
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
96
96
  const onChange = vi.fn()
97
97
 
98
98
  render(
@@ -57,7 +57,7 @@ const emptyBlockSelection = {
57
57
 
58
58
  describe('plugin:withEditableAPI: .insertChild()', () => {
59
59
  it('inserts child nodes correctly', async () => {
60
- const editorRef: RefObject<PortableTextEditor> = createRef()
60
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
61
61
  const onChange = vi.fn()
62
62
 
63
63
  render(
@@ -183,7 +183,7 @@ describe('plugin:withEditableAPI: .insertChild()', () => {
183
183
 
184
184
  describe('plugin:withEditableAPI: .insertBlock()', () => {
185
185
  it('should not add empty blank blocks: empty block', async () => {
186
- const editorRef: RefObject<PortableTextEditor> = createRef()
186
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
187
187
  const value = [
188
188
  {
189
189
  _key: 'emptyBlock',
@@ -247,7 +247,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
247
247
  })
248
248
 
249
249
  it('should not add empty blank blocks: non-empty block', async () => {
250
- const editorRef: RefObject<PortableTextEditor> = createRef()
250
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
251
251
  const onChange = vi.fn()
252
252
 
253
253
  render(
@@ -299,7 +299,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
299
299
  })
300
300
 
301
301
  it('should be inserted before if focus is on start of block', async () => {
302
- const editorRef: RefObject<PortableTextEditor> = createRef()
302
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
303
303
  const onChange = vi.fn()
304
304
 
305
305
  render(
@@ -353,7 +353,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
353
353
  })
354
354
 
355
355
  it('should not add empty blank blocks: non text block', async () => {
356
- const editorRef: RefObject<PortableTextEditor> = createRef()
356
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
357
357
  const value = [
358
358
  ...initialValue,
359
359
  {_key: 'b', _type: 'someObject', color: 'red'},
@@ -409,7 +409,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
409
409
  })
410
410
 
411
411
  it('should not add empty blank blocks: in between blocks', async () => {
412
- const editorRef: RefObject<PortableTextEditor> = createRef()
412
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
413
413
  const value = [
414
414
  ...initialValue,
415
415
  {_key: 'b', _type: 'someObject', color: 'red'},
@@ -463,7 +463,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
463
463
  })
464
464
 
465
465
  it('should not add empty blank blocks: in new empty text block', async () => {
466
- const editorRef: RefObject<PortableTextEditor> = createRef()
466
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
467
467
  const value = [...initialValue, ...emptyTextBlock]
468
468
  const onChange = vi.fn()
469
469
 
@@ -27,7 +27,7 @@ const INITIAL_VALUE: PortableTextBlock[] = [
27
27
 
28
28
  describe('plugin:withEditableAPI: .isSelectionsOverlapping', () => {
29
29
  it('returns true if the selections are partially overlapping', async () => {
30
- const editorRef: RefObject<PortableTextEditor> = createRef()
30
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
31
31
  const onChange = vi.fn()
32
32
  render(
33
33
  <PortableTextEditorTester
@@ -61,7 +61,7 @@ describe('plugin:withEditableAPI: .isSelectionsOverlapping', () => {
61
61
  })
62
62
 
63
63
  it('returns true if the selections are fully overlapping', async () => {
64
- const editorRef: RefObject<PortableTextEditor> = createRef()
64
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
65
65
  const onChange = vi.fn()
66
66
  render(
67
67
  <PortableTextEditorTester
@@ -95,7 +95,7 @@ describe('plugin:withEditableAPI: .isSelectionsOverlapping', () => {
95
95
  })
96
96
 
97
97
  it('return true if selection is fully inside another selection', async () => {
98
- const editorRef: RefObject<PortableTextEditor> = createRef()
98
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
99
99
  const onChange = vi.fn()
100
100
  render(
101
101
  <PortableTextEditorTester
@@ -129,7 +129,7 @@ describe('plugin:withEditableAPI: .isSelectionsOverlapping', () => {
129
129
  })
130
130
 
131
131
  it('returns false if the selections are not overlapping', async () => {
132
- const editorRef: RefObject<PortableTextEditor> = createRef()
132
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
133
133
  const onChange = vi.fn()
134
134
  render(
135
135
  <PortableTextEditorTester
@@ -9,7 +9,7 @@ import {PortableTextEditor} from '../../PortableTextEditor'
9
9
 
10
10
  describe('plugin:withPortableTextLists', () => {
11
11
  it('should return active list styles that cover the whole selection', async () => {
12
- const editorRef: RefObject<PortableTextEditor> = createRef()
12
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
13
13
  const initialValue = [
14
14
  {
15
15
  _key: 'a',
@@ -12,7 +12,7 @@ import {PortableTextEditor} from '../../PortableTextEditor'
12
12
  describe('plugin:withPortableTextMarksModel', () => {
13
13
  describe('normalization', () => {
14
14
  it('merges children correctly when toggling marks in various ranges', async () => {
15
- const editorRef: RefObject<PortableTextEditor> = createRef()
15
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
16
16
  const initialValue = [
17
17
  {
18
18
  _key: 'a',
@@ -146,7 +146,7 @@ describe('plugin:withPortableTextMarksModel', () => {
146
146
  })
147
147
 
148
148
  it('toggles marks on children with annotation marks correctly', async () => {
149
- const editorRef: RefObject<PortableTextEditor> = createRef()
149
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
150
150
  const initialValue = [
151
151
  {
152
152
  _key: 'a',
@@ -242,7 +242,7 @@ describe('plugin:withPortableTextMarksModel', () => {
242
242
  })
243
243
 
244
244
  it('merges blocks correctly when containing links', async () => {
245
- const editorRef: RefObject<PortableTextEditor> = createRef()
245
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
246
246
  const initialValue = [
247
247
  {
248
248
  _key: '5fc57af23597',
@@ -378,7 +378,7 @@ describe('plugin:withPortableTextMarksModel', () => {
378
378
  })
379
379
 
380
380
  it('resets markDefs when splitting a block in the beginning', async () => {
381
- const editorRef: RefObject<PortableTextEditor> = createRef()
381
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
382
382
  const initialValue = [
383
383
  {
384
384
  _key: 'ba',
@@ -505,7 +505,7 @@ describe('plugin:withPortableTextMarksModel', () => {
505
505
  })
506
506
  describe('selection', () => {
507
507
  it('should emit a new selection object when toggling marks, even though the value is the same', async () => {
508
- const editorRef: RefObject<PortableTextEditor> = createRef()
508
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
509
509
  const initialValue = [
510
510
  {
511
511
  _key: 'ba',
@@ -569,7 +569,7 @@ describe('plugin:withPortableTextMarksModel', () => {
569
569
  })
570
570
 
571
571
  it('should return active marks that cover the whole selection', async () => {
572
- const editorRef: RefObject<PortableTextEditor> = createRef()
572
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
573
573
  const initialValue = [
574
574
  {
575
575
  _key: 'a',
@@ -618,7 +618,7 @@ describe('plugin:withPortableTextMarksModel', () => {
618
618
  })
619
619
 
620
620
  it('should return active annotation types that cover the whole selection', async () => {
621
- const editorRef: RefObject<PortableTextEditor> = createRef()
621
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
622
622
  const initialValue = [
623
623
  {
624
624
  _key: 'a',
@@ -675,7 +675,7 @@ describe('plugin:withPortableTextMarksModel', () => {
675
675
 
676
676
  describe('removing annotations', () => {
677
677
  it('preserves other marks that apply to the spans', async () => {
678
- const editorRef: RefObject<PortableTextEditor> = createRef()
678
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
679
679
  const initialValue = [
680
680
  {
681
681
  _key: '5fc57af23597',
@@ -838,7 +838,7 @@ describe('plugin:withPortableTextMarksModel', () => {
838
838
 
839
839
  describe('removing nodes', () => {
840
840
  it('should not insert a new block if we have more blocks available', async () => {
841
- const editorRef: RefObject<PortableTextEditor> = createRef()
841
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
842
842
  const initialValue = [
843
843
  {
844
844
  _key: '5fc57af23597',
@@ -40,7 +40,7 @@ const initialValue = [
40
40
 
41
41
  describe('plugin:withPortableTextSelections', () => {
42
42
  it('will report that a selection is made backward', async () => {
43
- const editorRef: RefObject<PortableTextEditor> = createRef()
43
+ const editorRef: RefObject<PortableTextEditor | null> = createRef()
44
44
  const onChange = vi.fn()
45
45
  render(
46
46
  <PortableTextEditorTester