@portabletext/editor 1.0.10 → 1.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -46,24 +46,25 @@
46
46
  "debug": "^4.3.4",
47
47
  "is-hotkey-esm": "^1.0.0",
48
48
  "lodash": "^4.17.21",
49
- "slate": "0.100.0",
50
- "slate-react": "0.101.0"
49
+ "slate": "0.103.0",
50
+ "slate-react": "0.107.1"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@jest/globals": "^29.7.0",
54
- "@playwright/test": "1.45.3",
54
+ "@playwright/test": "1.46.0",
55
55
  "@portabletext/toolkit": "^2.0.15",
56
- "@sanity/block-tools": "^3.52.2",
56
+ "@sanity/block-tools": "^3.53.0",
57
57
  "@sanity/diff-match-patch": "^3.1.1",
58
58
  "@sanity/eslint-config-i18n": "^1.1.0",
59
59
  "@sanity/eslint-config-studio": "^4.0.0",
60
- "@sanity/pkg-utils": "^6.10.6",
61
- "@sanity/schema": "^3.52.2",
60
+ "@sanity/pkg-utils": "^6.10.9",
61
+ "@sanity/schema": "^3.53.0",
62
62
  "@sanity/test": "0.0.1-alpha.1",
63
- "@sanity/types": "^3.52.2",
63
+ "@sanity/types": "^3.53.0",
64
64
  "@sanity/ui": "^2.8.8",
65
- "@sanity/util": "^3.52.2",
66
- "@testing-library/react": "^13.4.0",
65
+ "@sanity/util": "^3.53.0",
66
+ "@testing-library/dom": "^10.4.0",
67
+ "@testing-library/react": "^16.0.0",
67
68
  "@types/debug": "^4.1.5",
68
69
  "@types/express": "^4.17.21",
69
70
  "@types/express-ws": "^3.0.4",
@@ -72,9 +73,9 @@
72
73
  "@types/node-ipc": "^9.2.3",
73
74
  "@types/react": "^18.3.3",
74
75
  "@types/react-dom": "^18.3.0",
75
- "@types/ws": "~8.5.11",
76
- "@typescript-eslint/eslint-plugin": "^7.17.0",
77
- "@typescript-eslint/parser": "^7.17.0",
76
+ "@types/ws": "~8.5.12",
77
+ "@typescript-eslint/eslint-plugin": "^8.0.1",
78
+ "@typescript-eslint/parser": "^8.0.1",
78
79
  "@vitejs/plugin-react": "^4.3.1",
79
80
  "dotenv": "^16.4.5",
80
81
  "eslint": "^8.57.0",
@@ -85,12 +86,12 @@
85
86
  "eslint-plugin-prettier": "^5.2.1",
86
87
  "eslint-plugin-react-compiler": "0.0.0-experimental-9ed098e-20240725",
87
88
  "eslint-plugin-tsdoc": "^0.3.0",
88
- "eslint-plugin-unicorn": "^54.0.0",
89
+ "eslint-plugin-unicorn": "^55.0.0",
89
90
  "eslint-plugin-unused-imports": "^4.0.1",
90
91
  "express": "^4.19.2",
91
92
  "express-ws": "^5.0.2",
92
93
  "jest": "^29.7.0",
93
- "jest-dev-server": "^9.0.2",
94
+ "jest-dev-server": "^10.0.0",
94
95
  "jest-environment-jsdom": "^29.7.0",
95
96
  "jest-environment-node": "^29.7.0",
96
97
  "node-ipc": "npm:@node-ipc/compat@9.2.5",
@@ -98,9 +99,9 @@
98
99
  "react-dom": "^18.3.1",
99
100
  "rxjs": "^7.8.1",
100
101
  "styled-components": "^6.1.12",
101
- "tsx": "^4.16.2",
102
- "typescript": "^5.5.3",
103
- "vite": "^4.5.3"
102
+ "tsx": "^4.16.5",
103
+ "typescript": "5.5.4",
104
+ "vite": "^5.3.5"
104
105
  },
105
106
  "peerDependencies": {
106
107
  "@sanity/block-tools": "^3.47.1",
@@ -127,6 +128,7 @@
127
128
  "lint:fix": "eslint . --fix",
128
129
  "test": "jest",
129
130
  "test:e2e": "jest --config=e2e-tests/e2e.config.cjs",
131
+ "test:e2e:watch": "jest --config=e2e-tests/e2e.config.cjs --watch",
130
132
  "test:watch": "jest --watch"
131
133
  }
132
134
  }
@@ -127,6 +127,14 @@ describe('initialization', () => {
127
127
  value={initialValue}
128
128
  />,
129
129
  )
130
+
131
+ await waitFor(() => {
132
+ if (editorRef.current) {
133
+ expect(onChange).toHaveBeenCalledWith({type: 'value', value: initialValue})
134
+ expect(onChange).toHaveBeenCalledWith({type: 'ready'})
135
+ }
136
+ })
137
+
130
138
  await waitFor(() => {
131
139
  if (editorRef.current) {
132
140
  PortableTextEditor.focus(editorRef.current)
@@ -158,10 +166,16 @@ describe('initialization', () => {
158
166
  value={initialValue}
159
167
  />,
160
168
  )
169
+
161
170
  await waitFor(() => {
162
171
  if (editorRef.current) {
163
- expect(onChange).toHaveBeenCalledWith({type: 'ready'})
164
172
  expect(onChange).toHaveBeenCalledWith({type: 'value', value: initialValue})
173
+ expect(onChange).toHaveBeenCalledWith({type: 'ready'})
174
+ }
175
+ })
176
+
177
+ await waitFor(() => {
178
+ if (editorRef.current) {
165
179
  const sel = PortableTextEditor.getSelection(editorRef.current)
166
180
  PortableTextEditor.focus(editorRef.current)
167
181
 
@@ -44,16 +44,22 @@ describe('adds empty text block if its needed', () => {
44
44
  value={initialValue}
45
45
  />,
46
46
  )
47
+
48
+ await waitFor(() => {
49
+ if (editorRef.current) {
50
+ expect(onChange).toHaveBeenCalledWith({type: 'value', value: initialValue})
51
+ expect(onChange).toHaveBeenCalledWith({type: 'ready'})
52
+ }
53
+ })
54
+
47
55
  const element = await getEditableElement(component)
48
56
 
49
- const editor = editorRef.current
50
- const inlineType = editor?.schemaTypes.inlineObjects.find((t) => t.name === 'someObject')
51
57
  await waitFor(async () => {
52
- if (editor && inlineType && element) {
53
- PortableTextEditor.focus(editor)
54
- PortableTextEditor.select(editor, initialSelection)
58
+ if (editorRef.current && element) {
59
+ PortableTextEditor.focus(editorRef.current)
60
+ PortableTextEditor.select(editorRef.current, initialSelection)
55
61
  fireEvent.click(element)
56
- expect(PortableTextEditor.getValue(editor)).toEqual([initialValue[0], newBlock])
62
+ expect(PortableTextEditor.getValue(editorRef.current)).toEqual([initialValue[0], newBlock])
57
63
  }
58
64
  })
59
65
  })
@@ -96,17 +102,16 @@ describe('adds empty text block if its needed', () => {
96
102
  )
97
103
  const element = await getEditableElement(component)
98
104
 
99
- const editor = editorRef.current
100
- const inlineType = editor?.schemaTypes.inlineObjects.find((t) => t.name === 'someObject')
101
105
  await waitFor(async () => {
102
- if (editor && inlineType && element) {
103
- PortableTextEditor.focus(editor)
104
- PortableTextEditor.select(editor, initialSelection)
106
+ if (editorRef.current && element) {
107
+ PortableTextEditor.focus(editorRef.current)
108
+ PortableTextEditor.select(editorRef.current, initialSelection)
105
109
  fireEvent.click(element)
106
- expect(PortableTextEditor.getValue(editor)).toEqual(initialValue)
110
+ expect(PortableTextEditor.getValue(editorRef.current)).toEqual(initialValue)
107
111
  }
108
112
  })
109
113
  })
114
+
110
115
  it('should not add blocks if the last element is void, but its not focused on that one', async () => {
111
116
  const initialValue = [
112
117
  {
@@ -134,8 +139,8 @@ describe('adds empty text block if its needed', () => {
134
139
  ]
135
140
 
136
141
  const initialSelection = {
137
- focus: {path: [{_key: 'b'}, 'children', {_key: 'b1'}], offset: 2},
138
- anchor: {path: [{_key: 'b'}, 'children', {_key: 'b1'}], offset: 2},
142
+ focus: {path: [{_key: 'b'}, 'children', {_key: 'b1'}], offset: 0},
143
+ anchor: {path: [{_key: 'b'}, 'children', {_key: 'b1'}], offset: 0},
139
144
  }
140
145
 
141
146
  const editorRef: RefObject<PortableTextEditor> = createRef()
@@ -148,19 +153,26 @@ describe('adds empty text block if its needed', () => {
148
153
  value={initialValue}
149
154
  />,
150
155
  )
156
+
157
+ await waitFor(() => {
158
+ if (editorRef.current) {
159
+ expect(onChange).toHaveBeenCalledWith({type: 'value', value: initialValue})
160
+ expect(onChange).toHaveBeenCalledWith({type: 'ready'})
161
+ }
162
+ })
163
+
151
164
  const element = await getEditableElement(component)
152
165
 
153
- const editor = editorRef.current
154
- const inlineType = editor?.schemaTypes.inlineObjects.find((t) => t.name === 'someObject')
155
166
  await waitFor(async () => {
156
- if (editor && inlineType && element) {
157
- PortableTextEditor.focus(editor)
158
- PortableTextEditor.select(editor, initialSelection)
167
+ if (editorRef.current && element) {
168
+ PortableTextEditor.focus(editorRef.current)
169
+ PortableTextEditor.select(editorRef.current, initialSelection)
159
170
  fireEvent.click(element)
160
- expect(PortableTextEditor.getValue(editor)).toEqual(initialValue)
171
+ expect(PortableTextEditor.getValue(editorRef.current)).toEqual(initialValue)
161
172
  }
162
173
  })
163
174
  })
175
+
164
176
  it('should not add blocks if the last element is void, and its focused on that one when clicking', async () => {
165
177
  const initialValue = [
166
178
  {
@@ -202,6 +214,14 @@ describe('adds empty text block if its needed', () => {
202
214
  value={initialValue}
203
215
  />,
204
216
  )
217
+
218
+ await waitFor(() => {
219
+ if (editorRef.current) {
220
+ expect(onChange).toHaveBeenCalledWith({type: 'value', value: initialValue})
221
+ expect(onChange).toHaveBeenCalledWith({type: 'ready'})
222
+ }
223
+ })
224
+
205
225
  const element = await getEditableElement(component)
206
226
 
207
227
  const editor = editorRef.current
@@ -0,0 +1,229 @@
1
+ import {describe, expect, jest, test} from '@jest/globals'
2
+ import {Schema} from '@sanity/schema'
3
+ import {type PortableTextBlock} from '@sanity/types'
4
+ import {render, waitFor} from '@testing-library/react'
5
+ import {createRef, type RefObject} from 'react'
6
+
7
+ import {type EditorChange, type EditorSelection} from '../../types/editor'
8
+ import {PortableTextEditable} from '../Editable'
9
+ import {PortableTextEditor} from '../PortableTextEditor'
10
+
11
+ const schema = Schema.compile({
12
+ types: [
13
+ {name: 'portable-text', type: 'array', of: [{type: 'block'}, {type: 'image'}]},
14
+ {name: 'image', type: 'object'},
15
+ ],
16
+ }).get('portable-text')
17
+
18
+ describe(PortableTextEditor.insertBlock.name, () => {
19
+ test('Scenario: Inserting a custom block without a selection #1', async () => {
20
+ const editorRef: RefObject<PortableTextEditor> = createRef()
21
+ const emptyTextBlock: PortableTextBlock = {
22
+ _key: 'ba',
23
+ _type: 'block',
24
+ children: [
25
+ {
26
+ _type: 'span',
27
+ _key: 'sa',
28
+ text: '',
29
+ marks: [],
30
+ },
31
+ ],
32
+ style: 'normal',
33
+ }
34
+ const initialValue: Array<PortableTextBlock> = [emptyTextBlock]
35
+ const onChange: (change: EditorChange) => void = jest.fn()
36
+
37
+ render(
38
+ <PortableTextEditor
39
+ ref={editorRef}
40
+ schemaType={schema}
41
+ value={initialValue}
42
+ keyGenerator={() => 'bb'}
43
+ onChange={onChange}
44
+ >
45
+ <PortableTextEditable />
46
+ </PortableTextEditor>,
47
+ )
48
+
49
+ // Given an empty text block
50
+ await waitFor(() => {
51
+ if (editorRef.current) {
52
+ expect(onChange).toHaveBeenCalledWith({type: 'value', value: initialValue})
53
+ expect(onChange).toHaveBeenCalledWith({type: 'ready'})
54
+ }
55
+ })
56
+
57
+ // And no selection
58
+ await waitFor(() => {
59
+ if (editorRef.current) {
60
+ expect(PortableTextEditor.getSelection(editorRef.current)).toBeNull()
61
+ }
62
+ })
63
+
64
+ // When a new image is inserted
65
+ await waitFor(() => {
66
+ if (editorRef.current) {
67
+ const imageBlockType = editorRef.current.schemaTypes.blockObjects.find(
68
+ (object) => object.name === 'image',
69
+ )!
70
+ PortableTextEditor.insertBlock(editorRef.current, imageBlockType)
71
+ }
72
+ })
73
+
74
+ // Then the empty text block is replaced with the new image
75
+ await waitFor(() => {
76
+ if (editorRef.current) {
77
+ expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
78
+ {_key: 'bb', _type: 'image'},
79
+ ])
80
+ }
81
+ })
82
+ })
83
+
84
+ test('Scenario: Inserting a custom block without a selection #2', async () => {
85
+ const editorRef: RefObject<PortableTextEditor> = createRef()
86
+ const nonEmptyTextBlock: PortableTextBlock = {
87
+ _key: 'ba',
88
+ _type: 'block',
89
+ children: [
90
+ {
91
+ _type: 'span',
92
+ _key: 'xs',
93
+ text: 'foo',
94
+ marks: [],
95
+ },
96
+ ],
97
+ style: 'normal',
98
+ }
99
+ const initialValue: Array<PortableTextBlock> = [nonEmptyTextBlock]
100
+ const onChange: (change: EditorChange) => void = jest.fn()
101
+
102
+ render(
103
+ <PortableTextEditor
104
+ ref={editorRef}
105
+ schemaType={schema}
106
+ value={initialValue}
107
+ keyGenerator={() => 'bb'}
108
+ onChange={onChange}
109
+ >
110
+ <PortableTextEditable />
111
+ </PortableTextEditor>,
112
+ )
113
+
114
+ // Given an non-empty text block
115
+ await waitFor(() => {
116
+ if (editorRef.current) {
117
+ expect(onChange).toHaveBeenCalledWith({type: 'value', value: initialValue})
118
+ expect(onChange).toHaveBeenCalledWith({type: 'ready'})
119
+ }
120
+ })
121
+
122
+ // And no selection
123
+ await waitFor(() => {
124
+ if (editorRef.current) {
125
+ expect(PortableTextEditor.getSelection(editorRef.current)).toBeNull()
126
+ }
127
+ })
128
+
129
+ // When a new image is inserted
130
+ await waitFor(() => {
131
+ if (editorRef.current) {
132
+ const imageBlockType = editorRef.current.schemaTypes.blockObjects.find(
133
+ (object) => object.name === 'image',
134
+ )!
135
+ PortableTextEditor.insertBlock(editorRef.current, imageBlockType)
136
+ }
137
+ })
138
+
139
+ // Then the empty text block is replaced with the new image
140
+ await waitFor(() => {
141
+ if (editorRef.current) {
142
+ expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
143
+ nonEmptyTextBlock,
144
+ {_key: 'bb', _type: 'image'},
145
+ ])
146
+ }
147
+ })
148
+ })
149
+
150
+ test('Scenario: Replacing an empty text block with a custom block', async () => {
151
+ const editorRef: RefObject<PortableTextEditor> = createRef()
152
+ const emptyTextBlock: PortableTextBlock = {
153
+ _key: 'ba',
154
+ _type: 'block',
155
+ children: [
156
+ {
157
+ _type: 'span',
158
+ _key: 'sa',
159
+ text: '',
160
+ marks: [],
161
+ },
162
+ ],
163
+ style: 'normal',
164
+ }
165
+ const imageBlock: PortableTextBlock = {
166
+ _key: 'bb',
167
+ _type: 'image',
168
+ }
169
+ const initialValue: Array<PortableTextBlock> = [emptyTextBlock, imageBlock]
170
+ const onChange: (change: EditorChange) => void = jest.fn()
171
+
172
+ render(
173
+ <PortableTextEditor
174
+ ref={editorRef}
175
+ schemaType={schema}
176
+ value={initialValue}
177
+ keyGenerator={() => 'bc'}
178
+ onChange={onChange}
179
+ >
180
+ <PortableTextEditable />
181
+ </PortableTextEditor>,
182
+ )
183
+
184
+ // Given an empty text block followed by an image
185
+ await waitFor(() => {
186
+ if (editorRef.current) {
187
+ expect(onChange).toHaveBeenCalledWith({type: 'value', value: initialValue})
188
+ expect(onChange).toHaveBeenCalledWith({type: 'ready'})
189
+ }
190
+ })
191
+
192
+ // And a selection in the empty text block
193
+ const initialSelection: EditorSelection = {
194
+ anchor: {path: [{_key: 'ba'}, 'children', {_key: 'sa'}], offset: 0},
195
+ focus: {path: [{_key: 'ba'}, 'children', {_key: 'sa'}], offset: 0},
196
+ backward: false,
197
+ }
198
+ await waitFor(() => {
199
+ if (editorRef.current) {
200
+ PortableTextEditor.select(editorRef.current, initialSelection)
201
+ }
202
+ })
203
+ await waitFor(() => {
204
+ if (editorRef.current) {
205
+ expect(onChange).toHaveBeenCalledWith({type: 'selection', selection: initialSelection})
206
+ }
207
+ })
208
+
209
+ // When a new image is inserted
210
+ await waitFor(() => {
211
+ if (editorRef.current) {
212
+ const imageBlockType = editorRef.current.schemaTypes.blockObjects.find(
213
+ (object) => object.name === 'image',
214
+ )!
215
+ PortableTextEditor.insertBlock(editorRef.current, imageBlockType)
216
+ }
217
+ })
218
+
219
+ // Then the empty text block is replaced with the new image
220
+ await waitFor(() => {
221
+ if (editorRef.current) {
222
+ expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
223
+ {_key: 'bc', _type: 'image'},
224
+ {_key: 'bb', _type: 'image'},
225
+ ])
226
+ }
227
+ })
228
+ })
229
+ })
@@ -1,23 +1,22 @@
1
1
  // This utils are inspired from https://github.dev/mwood23/slate-test-utils/blob/master/src/buildTestHarness.tsx
2
- import {act, fireEvent, type render} from '@testing-library/react'
2
+ import {fireEvent, type render} from '@testing-library/react'
3
3
  import {parseHotkey} from 'is-hotkey-esm'
4
+ import {act} from 'react'
4
5
 
5
6
  export async function triggerKeyboardEvent(hotkey: string, element: Element): Promise<void> {
6
- return act(async () => {
7
- const eventProps = parseHotkey(hotkey)
8
- const values = hotkey.split('+')
7
+ const eventProps = parseHotkey(hotkey)
8
+ const values = hotkey.split('+')
9
9
 
10
- fireEvent(
11
- element,
12
- new window.KeyboardEvent('keydown', {
13
- key: values[values.length - 1],
14
- code: `${eventProps.which}`,
15
- keyCode: eventProps.which,
16
- bubbles: true,
17
- ...eventProps,
18
- }),
19
- )
20
- })
10
+ fireEvent(
11
+ element,
12
+ new window.KeyboardEvent('keydown', {
13
+ key: values[values.length - 1],
14
+ code: `${eventProps.which}`,
15
+ keyCode: eventProps.which,
16
+ bubbles: true,
17
+ ...eventProps,
18
+ }),
19
+ )
21
20
  }
22
21
 
23
22
  export async function getEditableElement(component: ReturnType<typeof render>): Promise<Element> {
@@ -53,6 +53,14 @@ describe('plugin:withEditableAPI: .delete()', () => {
53
53
  value={initialValue}
54
54
  />,
55
55
  )
56
+
57
+ await waitFor(() => {
58
+ if (editorRef.current) {
59
+ expect(onChange).toHaveBeenCalledWith({type: 'value', value: initialValue})
60
+ expect(onChange).toHaveBeenCalledWith({type: 'ready'})
61
+ }
62
+ })
63
+
56
64
  await waitFor(() => {
57
65
  if (editorRef.current) {
58
66
  PortableTextEditor.focus(editorRef.current)
@@ -95,6 +103,7 @@ describe('plugin:withEditableAPI: .delete()', () => {
95
103
  value={initialValue}
96
104
  />,
97
105
  )
106
+
98
107
  await waitFor(() => {
99
108
  expect(onChange).toHaveBeenCalledWith({type: 'value', value: initialValue})
100
109
  expect(onChange).toHaveBeenCalledWith({type: 'ready'})
@@ -140,6 +149,7 @@ describe('plugin:withEditableAPI: .delete()', () => {
140
149
  it('deletes children', async () => {
141
150
  const editorRef: RefObject<PortableTextEditor> = createRef()
142
151
  const onChange = jest.fn()
152
+
143
153
  render(
144
154
  <PortableTextEditorTester
145
155
  onChange={onChange}
@@ -149,18 +159,34 @@ describe('plugin:withEditableAPI: .delete()', () => {
149
159
  />,
150
160
  )
151
161
 
162
+ await waitFor(() => {
163
+ if (editorRef.current) {
164
+ expect(onChange).toHaveBeenCalledWith({type: 'value', value: initialValue})
165
+ expect(onChange).toHaveBeenCalledWith({type: 'ready'})
166
+ }
167
+ })
168
+
152
169
  await waitFor(() => {
153
170
  if (editorRef.current) {
154
171
  PortableTextEditor.select(editorRef.current, {
155
172
  focus: {path: [{_key: 'b'}, 'children', {_key: 'b1'}], offset: 5},
156
173
  anchor: {path: [{_key: 'b'}, 'children', {_key: 'b1'}], offset: 7},
157
174
  })
158
- PortableTextEditor.focus(editorRef.current)
175
+ }
176
+ })
177
+
178
+ await waitFor(() => {
179
+ if (editorRef.current) {
159
180
  PortableTextEditor.delete(
160
181
  editorRef.current,
161
182
  PortableTextEditor.getSelection(editorRef.current),
162
183
  {mode: 'children'},
163
184
  )
185
+ }
186
+ })
187
+
188
+ await waitFor(() => {
189
+ if (editorRef.current) {
164
190
  expect(PortableTextEditor.getValue(editorRef.current)).toMatchInlineSnapshot(`
165
191
  Array [
166
192
  Object {
@@ -196,9 +222,11 @@ describe('plugin:withEditableAPI: .delete()', () => {
196
222
  }
197
223
  })
198
224
  })
225
+
199
226
  it('deletes selected', async () => {
200
227
  const editorRef: RefObject<PortableTextEditor> = createRef()
201
228
  const onChange = jest.fn()
229
+
202
230
  render(
203
231
  <PortableTextEditorTester
204
232
  onChange={onChange}
@@ -208,36 +236,50 @@ describe('plugin:withEditableAPI: .delete()', () => {
208
236
  />,
209
237
  )
210
238
 
239
+ await waitFor(() => {
240
+ if (editorRef.current) {
241
+ expect(onChange).toHaveBeenCalledWith({type: 'value', value: initialValue})
242
+ expect(onChange).toHaveBeenCalledWith({type: 'ready'})
243
+ }
244
+ })
245
+
211
246
  await waitFor(() => {
212
247
  if (editorRef.current) {
213
248
  PortableTextEditor.select(editorRef.current, {
214
249
  focus: {path: [{_key: 'b'}, 'children', {_key: 'b1'}], offset: 5},
215
250
  anchor: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 0},
216
251
  })
217
- PortableTextEditor.focus(editorRef.current)
252
+ }
253
+ })
254
+
255
+ await waitFor(() => {
256
+ if (editorRef.current) {
218
257
  PortableTextEditor.delete(
219
258
  editorRef.current,
220
259
  PortableTextEditor.getSelection(editorRef.current),
221
260
  {mode: 'selected'},
222
261
  )
223
- expect(PortableTextEditor.getValue(editorRef.current)).toMatchInlineSnapshot(`
224
- Array [
225
- Object {
226
- "_key": "b",
227
- "_type": "myTestBlockType",
228
- "children": Array [
229
- Object {
230
- "_key": "b1",
231
- "_type": "span",
232
- "marks": Array [],
233
- "text": " B",
234
- },
235
- ],
236
- "markDefs": Array [],
237
- "style": "normal",
238
- },
239
- ]
240
- `)
262
+ }
263
+ })
264
+
265
+ await waitFor(() => {
266
+ if (editorRef.current) {
267
+ expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
268
+ {
269
+ _key: 'b',
270
+ _type: 'myTestBlockType',
271
+ children: [
272
+ {
273
+ _key: 'b1',
274
+ _type: 'span',
275
+ marks: [],
276
+ text: ' B',
277
+ },
278
+ ],
279
+ markDefs: [],
280
+ style: 'normal',
281
+ },
282
+ ])
241
283
  }
242
284
  })
243
285
  })