@portabletext/editor 2.3.1 → 2.3.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 (31) hide show
  1. package/lib/_chunks-dts/behavior.types.action.d.cts +51 -51
  2. package/lib/_chunks-dts/behavior.types.action.d.ts +122 -122
  3. package/lib/index.cjs +40 -1
  4. package/lib/index.cjs.map +1 -1
  5. package/lib/index.js +40 -1
  6. package/lib/index.js.map +1 -1
  7. package/lib/plugins/index.d.ts +3 -3
  8. package/lib/utils/index.d.cts +2 -2
  9. package/lib/utils/index.d.ts +2 -2
  10. package/package.json +1 -1
  11. package/src/converters/converter.text-plain.test.ts +7 -5
  12. package/src/editor/__tests__/PortableTextEditor.test.tsx +5 -14
  13. package/src/editor/__tests__/PortableTextEditorTester.tsx +23 -77
  14. package/src/editor/__tests__/RangeDecorations.test.tsx +2 -9
  15. package/src/editor/__tests__/insert-block.test.tsx +7 -28
  16. package/src/editor/__tests__/self-solving.test.tsx +5 -17
  17. package/src/editor/create-editor.ts +4 -1
  18. package/src/editor/editor-schema.ts +36 -3
  19. package/src/editor/plugins/__tests__/withEditableAPIDelete.test.tsx +8 -15
  20. package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +7 -11
  21. package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +81 -63
  22. package/src/editor/plugins/__tests__/withEditableAPISelectionsOverlapping.test.tsx +2 -9
  23. package/src/editor/plugins/__tests__/withPortableTextLists.test.tsx +3 -7
  24. package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +17 -27
  25. package/src/editor/plugins/__tests__/withPortableTextSelections.test.tsx +3 -7
  26. package/src/editor/plugins/__tests__/withUndoRedo.test.tsx +4 -9
  27. package/src/internal-utils/__tests__/valueNormalization.test.tsx +3 -7
  28. package/src/internal-utils/__tests__/values.test.ts +5 -6
  29. package/src/internal-utils/operation-to-patches.test.ts +17 -12
  30. package/src/plugins/plugin.internal.portable-text-editor-ref.tsx +16 -0
  31. package/src/editor/__tests__/sync-value.test.tsx +0 -154
@@ -1,10 +1,7 @@
1
1
  import {render, waitFor} from '@testing-library/react'
2
2
  import {createRef, type RefObject} from 'react'
3
3
  import {describe, expect, it, vi} from 'vitest'
4
- import {
5
- PortableTextEditorTester,
6
- schemaType,
7
- } from '../../__tests__/PortableTextEditorTester'
4
+ import {PortableTextEditorTester} from '../../__tests__/PortableTextEditorTester'
8
5
  import {createTestKeyGenerator} from '../../../internal-utils/test-key-generator'
9
6
  import type {EditorSelection} from '../../../types/editor'
10
7
  import {PortableTextEditor} from '../../PortableTextEditor'
@@ -16,7 +13,7 @@ describe('plugin:withPortableTextMarksModel', () => {
16
13
  const initialValue = [
17
14
  {
18
15
  _key: 'a',
19
- _type: 'myTestBlockType',
16
+ _type: 'block',
20
17
  children: [
21
18
  {
22
19
  _key: 'a1',
@@ -47,7 +44,6 @@ describe('plugin:withPortableTextMarksModel', () => {
47
44
  <PortableTextEditorTester
48
45
  onChange={onChange}
49
46
  ref={editorRef}
50
- schemaType={schemaType}
51
47
  value={initialValue}
52
48
  keyGenerator={createTestKeyGenerator()}
53
49
  />,
@@ -79,7 +75,7 @@ describe('plugin:withPortableTextMarksModel', () => {
79
75
  expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
80
76
  {
81
77
  _key: 'a',
82
- _type: 'myTestBlockType',
78
+ _type: 'block',
83
79
  children: [
84
80
  {
85
81
  _key: 'a1',
@@ -113,7 +109,7 @@ describe('plugin:withPortableTextMarksModel', () => {
113
109
  const initialValue = [
114
110
  {
115
111
  _key: '5fc57af23597',
116
- _type: 'myTestBlockType',
112
+ _type: 'block',
117
113
  children: [
118
114
  {
119
115
  _key: 'be1c67c6971a',
@@ -139,7 +135,7 @@ describe('plugin:withPortableTextMarksModel', () => {
139
135
  },
140
136
  {
141
137
  _key: '7cd53af36712',
142
- _type: 'myTestBlockType',
138
+ _type: 'block',
143
139
  children: [
144
140
  {
145
141
  _key: '576c748e0cd2',
@@ -181,7 +177,6 @@ describe('plugin:withPortableTextMarksModel', () => {
181
177
  keyGenerator={createTestKeyGenerator()}
182
178
  onChange={onChange}
183
179
  ref={editorRef}
184
- schemaType={schemaType}
185
180
  value={initialValue}
186
181
  />,
187
182
  )
@@ -194,7 +189,7 @@ describe('plugin:withPortableTextMarksModel', () => {
194
189
  expect(PortableTextEditor.getValue(editor)).toEqual([
195
190
  {
196
191
  _key: '5fc57af23597',
197
- _type: 'myTestBlockType',
192
+ _type: 'block',
198
193
  children: [
199
194
  {
200
195
  _key: 'be1c67c6971a',
@@ -244,7 +239,7 @@ describe('plugin:withPortableTextMarksModel', () => {
244
239
  const initialValue = [
245
240
  {
246
241
  _key: 'ba',
247
- _type: 'myTestBlockType',
242
+ _type: 'block',
248
243
  children: [
249
244
  {
250
245
  _key: 'sa',
@@ -258,7 +253,7 @@ describe('plugin:withPortableTextMarksModel', () => {
258
253
  },
259
254
  {
260
255
  _key: 'bb',
261
- _type: 'myTestBlockType',
256
+ _type: 'block',
262
257
  children: [
263
258
  {
264
259
  _key: 'sb',
@@ -287,7 +282,6 @@ describe('plugin:withPortableTextMarksModel', () => {
287
282
  <PortableTextEditorTester
288
283
  onChange={onChange}
289
284
  ref={editorRef}
290
- schemaType={schemaType}
291
285
  value={initialValue}
292
286
  keyGenerator={createTestKeyGenerator()}
293
287
  />,
@@ -315,7 +309,7 @@ describe('plugin:withPortableTextMarksModel', () => {
315
309
  expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
316
310
  {
317
311
  _key: 'ba',
318
- _type: 'myTestBlockType',
312
+ _type: 'block',
319
313
  children: [
320
314
  {
321
315
  _key: 'sa',
@@ -329,7 +323,7 @@ describe('plugin:withPortableTextMarksModel', () => {
329
323
  },
330
324
  {
331
325
  _key: 'k2',
332
- _type: 'myTestBlockType',
326
+ _type: 'block',
333
327
  children: [
334
328
  {
335
329
  _key: 'k3',
@@ -343,7 +337,7 @@ describe('plugin:withPortableTextMarksModel', () => {
343
337
  },
344
338
  {
345
339
  _key: 'bb',
346
- _type: 'myTestBlockType',
340
+ _type: 'block',
347
341
  children: [
348
342
  {
349
343
  _key: 'sb',
@@ -372,7 +366,7 @@ describe('plugin:withPortableTextMarksModel', () => {
372
366
  const initialValue = [
373
367
  {
374
368
  _key: 'ba',
375
- _type: 'myTestBlockType',
369
+ _type: 'block',
376
370
  children: [
377
371
  {
378
372
  _key: 'sa',
@@ -391,7 +385,6 @@ describe('plugin:withPortableTextMarksModel', () => {
391
385
  <PortableTextEditorTester
392
386
  onChange={onChange}
393
387
  ref={editorRef}
394
- schemaType={schemaType}
395
388
  value={initialValue}
396
389
  keyGenerator={createTestKeyGenerator()}
397
390
  />,
@@ -437,7 +430,7 @@ describe('plugin:withPortableTextMarksModel', () => {
437
430
  const initialValue = [
438
431
  {
439
432
  _key: 'a',
440
- _type: 'myTestBlockType',
433
+ _type: 'block',
441
434
  children: [
442
435
  {
443
436
  _key: 'a1',
@@ -462,7 +455,6 @@ describe('plugin:withPortableTextMarksModel', () => {
462
455
  <PortableTextEditorTester
463
456
  onChange={onChange}
464
457
  ref={editorRef}
465
- schemaType={schemaType}
466
458
  value={initialValue}
467
459
  keyGenerator={createTestKeyGenerator()}
468
460
  />,
@@ -487,7 +479,7 @@ describe('plugin:withPortableTextMarksModel', () => {
487
479
  const initialValue = [
488
480
  {
489
481
  _key: 'a',
490
- _type: 'myTestBlockType',
482
+ _type: 'block',
491
483
  children: [
492
484
  {
493
485
  _key: 'a1',
@@ -518,7 +510,6 @@ describe('plugin:withPortableTextMarksModel', () => {
518
510
  <PortableTextEditorTester
519
511
  onChange={onChange}
520
512
  ref={editorRef}
521
- schemaType={schemaType}
522
513
  value={initialValue}
523
514
  keyGenerator={createTestKeyGenerator()}
524
515
  />,
@@ -545,10 +536,10 @@ describe('plugin:withPortableTextMarksModel', () => {
545
536
  const initialValue = [
546
537
  {
547
538
  _key: '5fc57af23597',
548
- _type: 'someObject',
539
+ _type: 'custom image',
549
540
  },
550
541
  {
551
- _type: 'myTestBlockType',
542
+ _type: 'block',
552
543
  _key: 'existingBlock',
553
544
  style: 'normal',
554
545
  markDefs: [],
@@ -569,7 +560,6 @@ describe('plugin:withPortableTextMarksModel', () => {
569
560
  keyGenerator={createTestKeyGenerator()}
570
561
  onChange={onChange}
571
562
  ref={editorRef}
572
- schemaType={schemaType}
573
563
  value={initialValue}
574
564
  />,
575
565
  )
@@ -601,7 +591,7 @@ describe('plugin:withPortableTextMarksModel', () => {
601
591
  const value = PortableTextEditor.getValue(editorRef.current)
602
592
  expect(value).toEqual([
603
593
  {
604
- _type: 'myTestBlockType',
594
+ _type: 'block',
605
595
  _key: 'existingBlock',
606
596
  style: 'normal',
607
597
  markDefs: [],
@@ -1,17 +1,14 @@
1
1
  import {render, waitFor} from '@testing-library/react'
2
2
  import {createRef, type RefObject} from 'react'
3
3
  import {describe, expect, it, vi} from 'vitest'
4
- import {
5
- PortableTextEditorTester,
6
- schemaType,
7
- } from '../../__tests__/PortableTextEditorTester'
4
+ import {PortableTextEditorTester} from '../../__tests__/PortableTextEditorTester'
8
5
  import {createTestKeyGenerator} from '../../../internal-utils/test-key-generator'
9
6
  import {PortableTextEditor} from '../../PortableTextEditor'
10
7
 
11
8
  const initialValue = [
12
9
  {
13
10
  _key: 'a',
14
- _type: 'myTestBlockType',
11
+ _type: 'block',
15
12
  children: [
16
13
  {
17
14
  _key: 'a1',
@@ -25,7 +22,7 @@ const initialValue = [
25
22
  },
26
23
  {
27
24
  _key: 'b',
28
- _type: 'myTestBlockType',
25
+ _type: 'block',
29
26
  children: [
30
27
  {
31
28
  _key: 'b1',
@@ -48,7 +45,6 @@ describe('plugin:withPortableTextSelections', () => {
48
45
  keyGenerator={createTestKeyGenerator()}
49
46
  onChange={onChange}
50
47
  ref={editorRef}
51
- schemaType={schemaType}
52
48
  value={initialValue}
53
49
  />,
54
50
  )
@@ -1,17 +1,14 @@
1
1
  import {render, waitFor} from '@testing-library/react'
2
2
  import {createRef, type RefObject} from 'react'
3
3
  import {describe, expect, it, vi} from 'vitest'
4
- import {
5
- PortableTextEditorTester,
6
- schemaType,
7
- } from '../../__tests__/PortableTextEditorTester'
4
+ import {PortableTextEditorTester} from '../../__tests__/PortableTextEditorTester'
8
5
  import {createTestKeyGenerator} from '../../../internal-utils/test-key-generator'
9
6
  import {PortableTextEditor} from '../../PortableTextEditor'
10
7
 
11
8
  const initialValue = [
12
9
  {
13
10
  _key: 'a',
14
- _type: 'myTestBlockType',
11
+ _type: 'block',
15
12
  children: [
16
13
  {
17
14
  _key: 'a1',
@@ -25,7 +22,7 @@ const initialValue = [
25
22
  },
26
23
  {
27
24
  _key: 'b',
28
- _type: 'myTestBlockType',
25
+ _type: 'block',
29
26
  children: [
30
27
  {
31
28
  _key: 'b1',
@@ -53,7 +50,6 @@ describe('plugin:withUndoRedo', () => {
53
50
  keyGenerator={createTestKeyGenerator()}
54
51
  onChange={onChange}
55
52
  ref={editorRef}
56
- schemaType={schemaType}
57
53
  value={initialValue}
58
54
  />,
59
55
  )
@@ -82,7 +78,7 @@ describe('plugin:withUndoRedo', () => {
82
78
  [
83
79
  {
84
80
  "_key": "a",
85
- "_type": "myTestBlockType",
81
+ "_type": "block",
86
82
  "children": [
87
83
  {
88
84
  "_key": "a1",
@@ -112,7 +108,6 @@ describe('plugin:withUndoRedo', () => {
112
108
  keyGenerator={createTestKeyGenerator()}
113
109
  onChange={onChange}
114
110
  ref={editorRef}
115
- schemaType={schemaType}
116
111
  value={initialValue}
117
112
  />,
118
113
  )
@@ -1,10 +1,7 @@
1
1
  import {render, waitFor} from '@testing-library/react'
2
2
  import {createRef, type RefObject} from 'react'
3
3
  import {describe, expect, it, vi} from 'vitest'
4
- import {
5
- PortableTextEditorTester,
6
- schemaType,
7
- } from '../../editor/__tests__/PortableTextEditorTester'
4
+ import {PortableTextEditorTester} from '../../editor/__tests__/PortableTextEditorTester'
8
5
  import {PortableTextEditor} from '../../editor/PortableTextEditor'
9
6
  import {createTestKeyGenerator} from '../test-key-generator'
10
7
 
@@ -14,7 +11,7 @@ describe('values: normalization', () => {
14
11
  const initialValue = [
15
12
  {
16
13
  _key: '5fc57af23597',
17
- _type: 'myTestBlockType',
14
+ _type: 'block',
18
15
  children: [
19
16
  {
20
17
  _key: 'be1c67c6971a',
@@ -32,7 +29,6 @@ describe('values: normalization', () => {
32
29
  keyGenerator={createTestKeyGenerator()}
33
30
  onChange={onChange}
34
31
  ref={editorRef}
35
- schemaType={schemaType}
36
32
  value={initialValue}
37
33
  />,
38
34
  )
@@ -64,7 +60,7 @@ describe('values: normalization', () => {
64
60
  expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
65
61
  {
66
62
  _key: '5fc57af23597',
67
- _type: 'myTestBlockType',
63
+ _type: 'block',
68
64
  children: [
69
65
  {
70
66
  _key: 'be1c67c6971a',
@@ -1,10 +1,9 @@
1
1
  import {describe, expect, it} from 'vitest'
2
- import {schemaType} from '../../editor/__tests__/PortableTextEditorTester'
3
- import {legacySchemaToEditorSchema} from '../../editor/editor-schema'
4
- import {createLegacySchema} from '../../editor/legacy-schema'
2
+ import {compileSchemaDefinition} from '../../editor/editor-schema'
3
+ import {defineSchema} from '../../editor/editor-schema-definition'
5
4
  import {fromSlateValue, toSlateValue} from '../values'
6
5
 
7
- const schemaTypes = legacySchemaToEditorSchema(createLegacySchema(schemaType))
6
+ const schemaTypes = compileSchemaDefinition(defineSchema({}))
8
7
 
9
8
  describe('toSlateValue', () => {
10
9
  it('checks undefined', () => {
@@ -63,7 +62,7 @@ describe('toSlateValue', () => {
63
62
  [
64
63
  {
65
64
  "_key": "123",
66
- "_type": "myTestBlockType",
65
+ "_type": "block",
67
66
  "children": [
68
67
  {
69
68
  "_key": "1231",
@@ -106,7 +105,7 @@ describe('toSlateValue', () => {
106
105
  [
107
106
  {
108
107
  "_key": "123",
109
- "_type": "myTestBlockType",
108
+ "_type": "block",
110
109
  "children": [
111
110
  {
112
111
  "_key": "1231",
@@ -2,11 +2,13 @@ import type {PortableTextTextBlock} from '@sanity/types'
2
2
  import {createEditor, type Descendant} from 'slate'
3
3
  import {beforeEach, describe, expect, it} from 'vitest'
4
4
  import {createActor} from 'xstate'
5
- import {schemaType} from '../editor/__tests__/PortableTextEditorTester'
6
5
  import {editorMachine} from '../editor/editor-machine'
7
- import {legacySchemaToEditorSchema} from '../editor/editor-schema'
6
+ import {
7
+ compileSchemaDefinition,
8
+ compileSchemaDefinitionToLegacySchema,
9
+ } from '../editor/editor-schema'
10
+ import {defineSchema} from '../editor/editor-schema-definition'
8
11
  import {defaultKeyGenerator} from '../editor/key-generator'
9
- import {createLegacySchema} from '../editor/legacy-schema'
10
12
  import {withPlugins} from '../editor/plugins/with-plugins'
11
13
  import {relayMachine} from '../editor/relay-machine'
12
14
  import {
@@ -18,11 +20,14 @@ import {
18
20
  splitNodePatch,
19
21
  } from './operation-to-patches'
20
22
 
21
- const legacySchema = createLegacySchema(schemaType)
22
- const schemaTypes = legacySchemaToEditorSchema(legacySchema)
23
+ const schemaDefinition = defineSchema({
24
+ inlineObjects: [{name: 'someObject'}],
25
+ })
26
+ const schema = compileSchemaDefinition(schemaDefinition)
27
+ const legacySchema = compileSchemaDefinitionToLegacySchema(schemaDefinition)
23
28
  const editorActor = createActor(editorMachine, {
24
29
  input: {
25
- schema: schemaTypes,
30
+ schema,
26
31
  keyGenerator: defaultKeyGenerator,
27
32
  getLegacySchema: () => legacySchema,
28
33
  },
@@ -38,7 +43,7 @@ const editor = withPlugins(createEditor(), {
38
43
  const createDefaultValue = () =>
39
44
  [
40
45
  {
41
- _type: 'myTestBlockType',
46
+ _type: 'block',
42
47
  _key: '1f2e64b47787',
43
48
  style: 'normal',
44
49
  markDefs: [],
@@ -65,7 +70,7 @@ describe('operationToPatches', () => {
65
70
  it('translates void items correctly when splitting spans', () => {
66
71
  expect(
67
72
  splitNodePatch(
68
- schemaTypes,
73
+ schema,
69
74
  editor.children,
70
75
  {
71
76
  type: 'split_node',
@@ -119,7 +124,7 @@ describe('operationToPatches', () => {
119
124
  it('produce correct insert block patch', () => {
120
125
  expect(
121
126
  insertNodePatch(
122
- schemaTypes,
127
+ schema,
123
128
  editor.children,
124
129
  {
125
130
  type: 'insert_node',
@@ -161,7 +166,7 @@ describe('operationToPatches', () => {
161
166
  editor.onChange()
162
167
  expect(
163
168
  insertNodePatch(
164
- schemaTypes,
169
+ schema,
165
170
  editor.children,
166
171
  {
167
172
  type: 'insert_node',
@@ -204,7 +209,7 @@ describe('operationToPatches', () => {
204
209
  it('produce correct insert child patch', () => {
205
210
  expect(
206
211
  insertNodePatch(
207
- schemaTypes,
212
+ schema,
208
213
  editor.children,
209
214
  {
210
215
  type: 'insert_node',
@@ -392,7 +397,7 @@ describe('operationToPatches', () => {
392
397
  editor.onChange()
393
398
  expect(
394
399
  mergeNodePatch(
395
- schemaTypes,
400
+ schema,
396
401
  editor.children,
397
402
  {
398
403
  type: 'merge_node',
@@ -0,0 +1,16 @@
1
+ import React from 'react'
2
+ import {usePortableTextEditor} from '../editor/hooks/usePortableTextEditor'
3
+ import type {PortableTextEditor} from '../editor/PortableTextEditor'
4
+
5
+ export const InternalPortableTextEditorRefPlugin =
6
+ React.forwardRef<PortableTextEditor | null>((_, ref) => {
7
+ const portableTextEditor = usePortableTextEditor()
8
+
9
+ const portableTextEditorRef = React.useRef(portableTextEditor)
10
+
11
+ React.useImperativeHandle(ref, () => portableTextEditorRef.current, [])
12
+
13
+ return null
14
+ })
15
+ InternalPortableTextEditorRefPlugin.displayName =
16
+ 'InternalPortableTextEditorRefPlugin'
@@ -1,154 +0,0 @@
1
- import {render, waitFor} from '@testing-library/react'
2
- import {createRef, type RefObject} from 'react'
3
- import {describe, expect, it, vi} from 'vitest'
4
- import {createTestKeyGenerator} from '../../internal-utils/test-key-generator'
5
- import {PortableTextEditor} from '../PortableTextEditor'
6
- import {PortableTextEditorTester, schemaType} from './PortableTextEditorTester'
7
-
8
- const initialValue = [
9
- {
10
- _key: '77071c3af231',
11
- _type: 'myTestBlockType',
12
- children: [
13
- {
14
- _key: 'c001f0e92c1f0',
15
- _type: 'span',
16
- marks: [],
17
- text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ',
18
- },
19
- ],
20
- markDefs: [],
21
- style: 'normal',
22
- },
23
- ]
24
-
25
- describe('useSyncValue', () => {
26
- it('updates span text', async () => {
27
- const editorRef: RefObject<PortableTextEditor | null> = createRef()
28
- const onChange = vi.fn()
29
- const syncedValue = [
30
- {
31
- _key: '77071c3af231',
32
- _type: 'myTestBlockType',
33
- children: [
34
- {
35
- _key: 'c001f0e92c1f0',
36
- _type: 'span',
37
- marks: [],
38
- text: 'Lorem my ipsum!',
39
- },
40
- ],
41
- markDefs: [],
42
- style: 'normal',
43
- },
44
- ]
45
- const {rerender} = render(
46
- <PortableTextEditorTester
47
- keyGenerator={createTestKeyGenerator()}
48
- onChange={onChange}
49
- ref={editorRef}
50
- schemaType={schemaType}
51
- value={initialValue}
52
- />,
53
- )
54
-
55
- await waitFor(() => {
56
- if (editorRef.current) {
57
- expect(onChange).toHaveBeenCalledWith({
58
- type: 'value',
59
- value: initialValue,
60
- })
61
- expect(onChange).toHaveBeenCalledWith({type: 'ready'})
62
- }
63
- })
64
-
65
- rerender(
66
- <PortableTextEditorTester
67
- keyGenerator={createTestKeyGenerator()}
68
- onChange={onChange}
69
- ref={editorRef}
70
- schemaType={schemaType}
71
- value={syncedValue}
72
- />,
73
- )
74
-
75
- await waitFor(() => {
76
- if (editorRef.current) {
77
- expect(PortableTextEditor.getValue(editorRef.current)).toEqual(
78
- syncedValue,
79
- )
80
- }
81
- })
82
- })
83
-
84
- it('replaces span nodes with different keys inside the same children array', async () => {
85
- const editorRef: RefObject<PortableTextEditor | null> = createRef()
86
- const onChange = vi.fn()
87
- const syncedValue = [
88
- {
89
- _key: '77071c3af231',
90
- _type: 'myTestBlockType',
91
- children: [
92
- {
93
- _key: 'c001f0e92c1f0__NEW_KEY_YA!',
94
- _type: 'span',
95
- marks: [],
96
- text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ',
97
- },
98
- ],
99
- markDefs: [],
100
- style: 'normal',
101
- },
102
- ]
103
- const {rerender} = render(
104
- <PortableTextEditorTester
105
- keyGenerator={createTestKeyGenerator()}
106
- onChange={onChange}
107
- ref={editorRef}
108
- schemaType={schemaType}
109
- value={initialValue}
110
- />,
111
- )
112
-
113
- await waitFor(() => {
114
- if (editorRef.current) {
115
- expect(onChange).toHaveBeenCalledWith({
116
- type: 'value',
117
- value: initialValue,
118
- })
119
- expect(onChange).toHaveBeenCalledWith({type: 'ready'})
120
- }
121
- })
122
-
123
- rerender(
124
- <PortableTextEditorTester
125
- keyGenerator={createTestKeyGenerator()}
126
- onChange={onChange}
127
- ref={editorRef}
128
- schemaType={schemaType}
129
- value={syncedValue}
130
- />,
131
- )
132
-
133
- await waitFor(() => {
134
- if (editorRef.current) {
135
- expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
136
- {
137
- _key: '77071c3af231',
138
- _type: 'myTestBlockType',
139
- children: [
140
- {
141
- _key: 'c001f0e92c1f0__NEW_KEY_YA!',
142
- _type: 'span',
143
- marks: [],
144
- text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ',
145
- },
146
- ],
147
- markDefs: [],
148
- style: 'normal',
149
- },
150
- ])
151
- }
152
- })
153
- })
154
- })