@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.
- package/lib/_chunks-dts/behavior.types.action.d.cts +51 -51
- package/lib/_chunks-dts/behavior.types.action.d.ts +122 -122
- package/lib/index.cjs +40 -1
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +40 -1
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.ts +3 -3
- package/lib/utils/index.d.cts +2 -2
- package/lib/utils/index.d.ts +2 -2
- package/package.json +1 -1
- package/src/converters/converter.text-plain.test.ts +7 -5
- package/src/editor/__tests__/PortableTextEditor.test.tsx +5 -14
- package/src/editor/__tests__/PortableTextEditorTester.tsx +23 -77
- package/src/editor/__tests__/RangeDecorations.test.tsx +2 -9
- package/src/editor/__tests__/insert-block.test.tsx +7 -28
- package/src/editor/__tests__/self-solving.test.tsx +5 -17
- package/src/editor/create-editor.ts +4 -1
- package/src/editor/editor-schema.ts +36 -3
- package/src/editor/plugins/__tests__/withEditableAPIDelete.test.tsx +8 -15
- package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +7 -11
- package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +81 -63
- package/src/editor/plugins/__tests__/withEditableAPISelectionsOverlapping.test.tsx +2 -9
- package/src/editor/plugins/__tests__/withPortableTextLists.test.tsx +3 -7
- package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +17 -27
- package/src/editor/plugins/__tests__/withPortableTextSelections.test.tsx +3 -7
- package/src/editor/plugins/__tests__/withUndoRedo.test.tsx +4 -9
- package/src/internal-utils/__tests__/valueNormalization.test.tsx +3 -7
- package/src/internal-utils/__tests__/values.test.ts +5 -6
- package/src/internal-utils/operation-to-patches.test.ts +17 -12
- package/src/plugins/plugin.internal.portable-text-editor-ref.tsx +16 -0
- package/src/editor/__tests__/sync-value.test.tsx +0 -154
|
@@ -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: '
|
|
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: '
|
|
25
|
+
_type: 'block',
|
|
29
26
|
children: [
|
|
30
27
|
{
|
|
31
28
|
_key: 'b1',
|
|
@@ -52,7 +49,6 @@ describe('plugin:withEditableAPI: .delete()', () => {
|
|
|
52
49
|
<PortableTextEditorTester
|
|
53
50
|
onChange={onChange}
|
|
54
51
|
ref={editorRef}
|
|
55
|
-
schemaType={schemaType}
|
|
56
52
|
value={initialValue}
|
|
57
53
|
keyGenerator={createTestKeyGenerator()}
|
|
58
54
|
/>,
|
|
@@ -82,7 +78,7 @@ describe('plugin:withEditableAPI: .delete()', () => {
|
|
|
82
78
|
[
|
|
83
79
|
{
|
|
84
80
|
"_key": "a",
|
|
85
|
-
"_type": "
|
|
81
|
+
"_type": "block",
|
|
86
82
|
"children": [
|
|
87
83
|
{
|
|
88
84
|
"_key": "a1",
|
|
@@ -108,7 +104,6 @@ describe('plugin:withEditableAPI: .delete()', () => {
|
|
|
108
104
|
keyGenerator={createTestKeyGenerator()}
|
|
109
105
|
onChange={onChange}
|
|
110
106
|
ref={editorRef}
|
|
111
|
-
schemaType={schemaType}
|
|
112
107
|
value={initialValue}
|
|
113
108
|
/>,
|
|
114
109
|
)
|
|
@@ -139,7 +134,7 @@ describe('plugin:withEditableAPI: .delete()', () => {
|
|
|
139
134
|
expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
|
|
140
135
|
{
|
|
141
136
|
_key: 'k2',
|
|
142
|
-
_type: '
|
|
137
|
+
_type: 'block',
|
|
143
138
|
children: [
|
|
144
139
|
{
|
|
145
140
|
_key: 'k3',
|
|
@@ -165,7 +160,6 @@ describe('plugin:withEditableAPI: .delete()', () => {
|
|
|
165
160
|
keyGenerator={createTestKeyGenerator()}
|
|
166
161
|
onChange={onChange}
|
|
167
162
|
ref={editorRef}
|
|
168
|
-
schemaType={schemaType}
|
|
169
163
|
value={initialValue}
|
|
170
164
|
/>,
|
|
171
165
|
)
|
|
@@ -206,7 +200,7 @@ describe('plugin:withEditableAPI: .delete()', () => {
|
|
|
206
200
|
[
|
|
207
201
|
{
|
|
208
202
|
"_key": "a",
|
|
209
|
-
"_type": "
|
|
203
|
+
"_type": "block",
|
|
210
204
|
"children": [
|
|
211
205
|
{
|
|
212
206
|
"_key": "a1",
|
|
@@ -220,7 +214,7 @@ describe('plugin:withEditableAPI: .delete()', () => {
|
|
|
220
214
|
},
|
|
221
215
|
{
|
|
222
216
|
"_key": "b",
|
|
223
|
-
"_type": "
|
|
217
|
+
"_type": "block",
|
|
224
218
|
"children": [
|
|
225
219
|
{
|
|
226
220
|
"_key": "k2",
|
|
@@ -246,7 +240,6 @@ describe('plugin:withEditableAPI: .delete()', () => {
|
|
|
246
240
|
<PortableTextEditorTester
|
|
247
241
|
onChange={onChange}
|
|
248
242
|
ref={editorRef}
|
|
249
|
-
schemaType={schemaType}
|
|
250
243
|
value={initialValue}
|
|
251
244
|
keyGenerator={createTestKeyGenerator()}
|
|
252
245
|
/>,
|
|
@@ -286,7 +279,7 @@ describe('plugin:withEditableAPI: .delete()', () => {
|
|
|
286
279
|
expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
|
|
287
280
|
{
|
|
288
281
|
_key: 'b',
|
|
289
|
-
_type: '
|
|
282
|
+
_type: 'block',
|
|
290
283
|
children: [
|
|
291
284
|
{
|
|
292
285
|
_key: 'b1',
|
|
@@ -3,17 +3,17 @@ import {createRef, type RefObject} from 'react'
|
|
|
3
3
|
import {describe, expect, it, vi} from 'vitest'
|
|
4
4
|
import {
|
|
5
5
|
PortableTextEditorTester,
|
|
6
|
-
|
|
6
|
+
schemaDefinition,
|
|
7
7
|
} from '../../__tests__/PortableTextEditorTester'
|
|
8
8
|
import {isTextBlock} from '../../../internal-utils/parse-blocks'
|
|
9
9
|
import {createTestKeyGenerator} from '../../../internal-utils/test-key-generator'
|
|
10
|
-
import {
|
|
10
|
+
import {compileSchemaDefinition} from '../../editor-schema'
|
|
11
11
|
import {PortableTextEditor} from '../../PortableTextEditor'
|
|
12
12
|
|
|
13
13
|
const initialValue = [
|
|
14
14
|
{
|
|
15
15
|
_key: 'a',
|
|
16
|
-
_type: '
|
|
16
|
+
_type: 'block',
|
|
17
17
|
children: [
|
|
18
18
|
{
|
|
19
19
|
_key: 'a1',
|
|
@@ -27,7 +27,7 @@ const initialValue = [
|
|
|
27
27
|
},
|
|
28
28
|
{
|
|
29
29
|
_key: 'b',
|
|
30
|
-
_type: '
|
|
30
|
+
_type: 'block',
|
|
31
31
|
children: [
|
|
32
32
|
{
|
|
33
33
|
_key: 'b1',
|
|
@@ -61,7 +61,6 @@ describe('plugin:withEditableAPI: .getFragment()', () => {
|
|
|
61
61
|
keyGenerator={createTestKeyGenerator()}
|
|
62
62
|
onChange={onChange}
|
|
63
63
|
ref={editorRef}
|
|
64
|
-
schemaType={schemaType}
|
|
65
64
|
value={initialValue}
|
|
66
65
|
/>,
|
|
67
66
|
)
|
|
@@ -89,9 +88,7 @@ describe('plugin:withEditableAPI: .getFragment()', () => {
|
|
|
89
88
|
fragment &&
|
|
90
89
|
isTextBlock(
|
|
91
90
|
{
|
|
92
|
-
schema:
|
|
93
|
-
editorRef.current.schemaTypes,
|
|
94
|
-
),
|
|
91
|
+
schema: compileSchemaDefinition(schemaDefinition),
|
|
95
92
|
},
|
|
96
93
|
fragment[0],
|
|
97
94
|
) &&
|
|
@@ -110,7 +107,6 @@ describe('plugin:withEditableAPI: .getFragment()', () => {
|
|
|
110
107
|
keyGenerator={createTestKeyGenerator()}
|
|
111
108
|
onChange={onChange}
|
|
112
109
|
ref={editorRef}
|
|
113
|
-
schemaType={schemaType}
|
|
114
110
|
value={initialValue}
|
|
115
111
|
/>,
|
|
116
112
|
)
|
|
@@ -138,7 +134,7 @@ describe('plugin:withEditableAPI: .getFragment()', () => {
|
|
|
138
134
|
[
|
|
139
135
|
{
|
|
140
136
|
"_key": "a",
|
|
141
|
-
"_type": "
|
|
137
|
+
"_type": "block",
|
|
142
138
|
"children": [
|
|
143
139
|
{
|
|
144
140
|
"_key": "a1",
|
|
@@ -152,7 +148,7 @@ describe('plugin:withEditableAPI: .getFragment()', () => {
|
|
|
152
148
|
},
|
|
153
149
|
{
|
|
154
150
|
"_key": "b",
|
|
155
|
-
"_type": "
|
|
151
|
+
"_type": "block",
|
|
156
152
|
"children": [
|
|
157
153
|
{
|
|
158
154
|
"_key": "b1",
|
|
@@ -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: '
|
|
11
|
+
_type: 'block',
|
|
15
12
|
children: [
|
|
16
13
|
{
|
|
17
14
|
_key: 'a1',
|
|
@@ -32,7 +29,7 @@ const initialSelection = {
|
|
|
32
29
|
const emptyTextBlock = [
|
|
33
30
|
{
|
|
34
31
|
_key: 'emptyBlock',
|
|
35
|
-
_type: '
|
|
32
|
+
_type: 'block',
|
|
36
33
|
children: [
|
|
37
34
|
{
|
|
38
35
|
_key: 'emptySpan',
|
|
@@ -66,7 +63,6 @@ describe('plugin:withEditableAPI: .insertChild()', () => {
|
|
|
66
63
|
keyGenerator={createTestKeyGenerator()}
|
|
67
64
|
onChange={onChange}
|
|
68
65
|
ref={editorRef}
|
|
69
|
-
schemaType={schemaType}
|
|
70
66
|
value={initialValue}
|
|
71
67
|
/>,
|
|
72
68
|
)
|
|
@@ -104,7 +100,7 @@ describe('plugin:withEditableAPI: .insertChild()', () => {
|
|
|
104
100
|
expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
|
|
105
101
|
{
|
|
106
102
|
_key: 'a',
|
|
107
|
-
_type: '
|
|
103
|
+
_type: 'block',
|
|
108
104
|
children: [
|
|
109
105
|
{
|
|
110
106
|
_key: 'a1',
|
|
@@ -148,7 +144,7 @@ describe('plugin:withEditableAPI: .insertChild()', () => {
|
|
|
148
144
|
expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
|
|
149
145
|
{
|
|
150
146
|
_key: 'a',
|
|
151
|
-
_type: '
|
|
147
|
+
_type: 'block',
|
|
152
148
|
children: [
|
|
153
149
|
{
|
|
154
150
|
_key: 'a1',
|
|
@@ -189,7 +185,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
|
|
|
189
185
|
const value = [
|
|
190
186
|
{
|
|
191
187
|
_key: 'emptyBlock',
|
|
192
|
-
_type: '
|
|
188
|
+
_type: 'block',
|
|
193
189
|
children: [
|
|
194
190
|
{
|
|
195
191
|
_key: 'emptySpan',
|
|
@@ -207,7 +203,6 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
|
|
|
207
203
|
render(
|
|
208
204
|
<PortableTextEditorTester
|
|
209
205
|
ref={editorRef}
|
|
210
|
-
schemaType={schemaType}
|
|
211
206
|
value={emptyTextBlock}
|
|
212
207
|
onChange={onChange}
|
|
213
208
|
keyGenerator={createTestKeyGenerator()}
|
|
@@ -230,20 +225,24 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
|
|
|
230
225
|
|
|
231
226
|
await waitFor(() => {
|
|
232
227
|
if (editorRef.current) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
228
|
+
PortableTextEditor.insertBlock(
|
|
229
|
+
editorRef.current,
|
|
230
|
+
{name: 'custom image'},
|
|
231
|
+
{
|
|
232
|
+
src: 'https://example.com/image.jpg',
|
|
233
|
+
},
|
|
234
|
+
)
|
|
240
235
|
}
|
|
241
236
|
})
|
|
242
237
|
|
|
243
238
|
await waitFor(() => {
|
|
244
239
|
if (editorRef.current) {
|
|
245
240
|
expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
|
|
246
|
-
{
|
|
241
|
+
{
|
|
242
|
+
_key: 'k2',
|
|
243
|
+
_type: 'custom image',
|
|
244
|
+
src: 'https://example.com/image.jpg',
|
|
245
|
+
},
|
|
247
246
|
])
|
|
248
247
|
}
|
|
249
248
|
})
|
|
@@ -256,7 +255,6 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
|
|
|
256
255
|
render(
|
|
257
256
|
<PortableTextEditorTester
|
|
258
257
|
ref={editorRef}
|
|
259
|
-
schemaType={schemaType}
|
|
260
258
|
value={initialValue}
|
|
261
259
|
onChange={onChange}
|
|
262
260
|
keyGenerator={createTestKeyGenerator()}
|
|
@@ -282,13 +280,13 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
|
|
|
282
280
|
|
|
283
281
|
await waitFor(() => {
|
|
284
282
|
if (editorRef.current) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
283
|
+
PortableTextEditor.insertBlock(
|
|
284
|
+
editorRef.current,
|
|
285
|
+
{name: 'custom image'},
|
|
286
|
+
{
|
|
287
|
+
src: 'https://example.com/image.jpg',
|
|
288
|
+
},
|
|
289
|
+
)
|
|
292
290
|
}
|
|
293
291
|
})
|
|
294
292
|
|
|
@@ -296,7 +294,11 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
|
|
|
296
294
|
if (editorRef.current) {
|
|
297
295
|
expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
|
|
298
296
|
...initialValue,
|
|
299
|
-
{
|
|
297
|
+
{
|
|
298
|
+
_key: 'k2',
|
|
299
|
+
_type: 'custom image',
|
|
300
|
+
src: 'https://example.com/image.jpg',
|
|
301
|
+
},
|
|
300
302
|
])
|
|
301
303
|
}
|
|
302
304
|
})
|
|
@@ -310,7 +312,6 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
|
|
|
310
312
|
<PortableTextEditorTester
|
|
311
313
|
onChange={onChange}
|
|
312
314
|
ref={editorRef}
|
|
313
|
-
schemaType={schemaType}
|
|
314
315
|
value={initialValue}
|
|
315
316
|
keyGenerator={createTestKeyGenerator()}
|
|
316
317
|
/>,
|
|
@@ -338,19 +339,24 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
|
|
|
338
339
|
|
|
339
340
|
await waitFor(() => {
|
|
340
341
|
if (editorRef.current) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
342
|
+
PortableTextEditor.insertBlock(
|
|
343
|
+
editorRef.current,
|
|
344
|
+
{name: 'custom image'},
|
|
345
|
+
{
|
|
346
|
+
src: 'https://example.com/image.jpg',
|
|
347
|
+
},
|
|
348
|
+
)
|
|
347
349
|
}
|
|
348
350
|
})
|
|
349
351
|
|
|
350
352
|
await waitFor(() => {
|
|
351
353
|
if (editorRef.current) {
|
|
352
354
|
expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
|
|
353
|
-
{
|
|
355
|
+
{
|
|
356
|
+
_key: 'k2',
|
|
357
|
+
_type: 'custom image',
|
|
358
|
+
src: 'https://example.com/image.jpg',
|
|
359
|
+
},
|
|
354
360
|
...initialValue,
|
|
355
361
|
])
|
|
356
362
|
}
|
|
@@ -361,14 +367,13 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
|
|
|
361
367
|
const editorRef: RefObject<PortableTextEditor | null> = createRef()
|
|
362
368
|
const value = [
|
|
363
369
|
...initialValue,
|
|
364
|
-
{_key: 'b', _type: '
|
|
370
|
+
{_key: 'b', _type: 'custom image', src: 'https://example.com/image.jpg'},
|
|
365
371
|
]
|
|
366
372
|
const onChange = vi.fn()
|
|
367
373
|
|
|
368
374
|
render(
|
|
369
375
|
<PortableTextEditorTester
|
|
370
376
|
ref={editorRef}
|
|
371
|
-
schemaType={schemaType}
|
|
372
377
|
value={value}
|
|
373
378
|
onChange={onChange}
|
|
374
379
|
keyGenerator={createTestKeyGenerator()}
|
|
@@ -385,7 +390,7 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
|
|
|
385
390
|
await waitFor(() => {
|
|
386
391
|
if (editorRef.current) {
|
|
387
392
|
PortableTextEditor.focus(editorRef.current)
|
|
388
|
-
// Focus the `
|
|
393
|
+
// Focus the `custom image` block
|
|
389
394
|
PortableTextEditor.select(editorRef.current, {
|
|
390
395
|
focus: {path: [{_key: 'b'}], offset: 0},
|
|
391
396
|
anchor: {path: [{_key: 'b'}], offset: 0},
|
|
@@ -395,12 +400,13 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
|
|
|
395
400
|
|
|
396
401
|
await waitFor(() => {
|
|
397
402
|
if (editorRef.current) {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
403
|
+
PortableTextEditor.insertBlock(
|
|
404
|
+
editorRef.current,
|
|
405
|
+
{name: 'custom image'},
|
|
406
|
+
{
|
|
407
|
+
src: 'https://example.com/image2.jpg',
|
|
408
|
+
},
|
|
409
|
+
)
|
|
404
410
|
}
|
|
405
411
|
})
|
|
406
412
|
|
|
@@ -408,7 +414,11 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
|
|
|
408
414
|
if (editorRef.current) {
|
|
409
415
|
expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
|
|
410
416
|
...value,
|
|
411
|
-
{
|
|
417
|
+
{
|
|
418
|
+
_key: 'k2',
|
|
419
|
+
_type: 'custom image',
|
|
420
|
+
src: 'https://example.com/image2.jpg',
|
|
421
|
+
},
|
|
412
422
|
])
|
|
413
423
|
}
|
|
414
424
|
})
|
|
@@ -418,14 +428,13 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
|
|
|
418
428
|
const editorRef: RefObject<PortableTextEditor | null> = createRef()
|
|
419
429
|
const value = [
|
|
420
430
|
...initialValue,
|
|
421
|
-
{_key: 'b', _type: '
|
|
431
|
+
{_key: 'b', _type: 'custom image', src: 'https://example.com/image.jpg'},
|
|
422
432
|
]
|
|
423
433
|
const onChange = vi.fn()
|
|
424
434
|
|
|
425
435
|
render(
|
|
426
436
|
<PortableTextEditorTester
|
|
427
437
|
ref={editorRef}
|
|
428
|
-
schemaType={schemaType}
|
|
429
438
|
value={value}
|
|
430
439
|
onChange={onChange}
|
|
431
440
|
keyGenerator={createTestKeyGenerator()}
|
|
@@ -449,12 +458,13 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
|
|
|
449
458
|
|
|
450
459
|
await waitFor(() => {
|
|
451
460
|
if (editorRef.current) {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
461
|
+
PortableTextEditor.insertBlock(
|
|
462
|
+
editorRef.current,
|
|
463
|
+
{name: 'custom image'},
|
|
464
|
+
{
|
|
465
|
+
src: 'https://example.com/image2.jpg',
|
|
466
|
+
},
|
|
467
|
+
)
|
|
458
468
|
}
|
|
459
469
|
})
|
|
460
470
|
|
|
@@ -462,7 +472,11 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
|
|
|
462
472
|
if (editorRef.current) {
|
|
463
473
|
expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
|
|
464
474
|
value[0],
|
|
465
|
-
{
|
|
475
|
+
{
|
|
476
|
+
_key: 'k2',
|
|
477
|
+
_type: 'custom image',
|
|
478
|
+
src: 'https://example.com/image2.jpg',
|
|
479
|
+
},
|
|
466
480
|
value[1],
|
|
467
481
|
])
|
|
468
482
|
}
|
|
@@ -477,7 +491,6 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
|
|
|
477
491
|
render(
|
|
478
492
|
<PortableTextEditorTester
|
|
479
493
|
ref={editorRef}
|
|
480
|
-
schemaType={schemaType}
|
|
481
494
|
value={value}
|
|
482
495
|
onChange={onChange}
|
|
483
496
|
keyGenerator={createTestKeyGenerator()}
|
|
@@ -499,12 +512,13 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
|
|
|
499
512
|
|
|
500
513
|
await waitFor(() => {
|
|
501
514
|
if (editorRef.current) {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
515
|
+
PortableTextEditor.insertBlock(
|
|
516
|
+
editorRef.current,
|
|
517
|
+
{name: 'custom image'},
|
|
518
|
+
{
|
|
519
|
+
src: 'https://example.com/image.jpg',
|
|
520
|
+
},
|
|
521
|
+
)
|
|
508
522
|
}
|
|
509
523
|
})
|
|
510
524
|
|
|
@@ -512,7 +526,11 @@ describe('plugin:withEditableAPI: .insertBlock()', () => {
|
|
|
512
526
|
if (editorRef.current) {
|
|
513
527
|
expect(PortableTextEditor.getValue(editorRef.current)).toEqual([
|
|
514
528
|
value[0],
|
|
515
|
-
{
|
|
529
|
+
{
|
|
530
|
+
_key: 'k2',
|
|
531
|
+
_type: 'custom image',
|
|
532
|
+
src: 'https://example.com/image.jpg',
|
|
533
|
+
},
|
|
516
534
|
])
|
|
517
535
|
}
|
|
518
536
|
})
|
|
@@ -2,17 +2,14 @@ import type {PortableTextBlock} from '@sanity/types'
|
|
|
2
2
|
import {render, waitFor} from '@testing-library/react'
|
|
3
3
|
import {createRef, type RefObject} from 'react'
|
|
4
4
|
import {describe, expect, it, vi} from 'vitest'
|
|
5
|
-
import {
|
|
6
|
-
PortableTextEditorTester,
|
|
7
|
-
schemaType,
|
|
8
|
-
} from '../../__tests__/PortableTextEditorTester'
|
|
5
|
+
import {PortableTextEditorTester} from '../../__tests__/PortableTextEditorTester'
|
|
9
6
|
import {createTestKeyGenerator} from '../../../internal-utils/test-key-generator'
|
|
10
7
|
import {PortableTextEditor} from '../../PortableTextEditor'
|
|
11
8
|
|
|
12
9
|
const INITIAL_VALUE: PortableTextBlock[] = [
|
|
13
10
|
{
|
|
14
11
|
_key: 'a',
|
|
15
|
-
_type: '
|
|
12
|
+
_type: 'block',
|
|
16
13
|
children: [
|
|
17
14
|
{
|
|
18
15
|
_key: 'a1',
|
|
@@ -35,7 +32,6 @@ describe('plugin:withEditableAPI: .isSelectionsOverlapping', () => {
|
|
|
35
32
|
keyGenerator={createTestKeyGenerator()}
|
|
36
33
|
onChange={onChange}
|
|
37
34
|
ref={editorRef}
|
|
38
|
-
schemaType={schemaType}
|
|
39
35
|
value={INITIAL_VALUE}
|
|
40
36
|
/>,
|
|
41
37
|
)
|
|
@@ -70,7 +66,6 @@ describe('plugin:withEditableAPI: .isSelectionsOverlapping', () => {
|
|
|
70
66
|
keyGenerator={createTestKeyGenerator()}
|
|
71
67
|
onChange={onChange}
|
|
72
68
|
ref={editorRef}
|
|
73
|
-
schemaType={schemaType}
|
|
74
69
|
value={INITIAL_VALUE}
|
|
75
70
|
/>,
|
|
76
71
|
)
|
|
@@ -105,7 +100,6 @@ describe('plugin:withEditableAPI: .isSelectionsOverlapping', () => {
|
|
|
105
100
|
keyGenerator={createTestKeyGenerator()}
|
|
106
101
|
onChange={onChange}
|
|
107
102
|
ref={editorRef}
|
|
108
|
-
schemaType={schemaType}
|
|
109
103
|
value={INITIAL_VALUE}
|
|
110
104
|
/>,
|
|
111
105
|
)
|
|
@@ -140,7 +134,6 @@ describe('plugin:withEditableAPI: .isSelectionsOverlapping', () => {
|
|
|
140
134
|
keyGenerator={createTestKeyGenerator()}
|
|
141
135
|
onChange={onChange}
|
|
142
136
|
ref={editorRef}
|
|
143
|
-
schemaType={schemaType}
|
|
144
137
|
value={INITIAL_VALUE}
|
|
145
138
|
/>,
|
|
146
139
|
)
|
|
@@ -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 {PortableTextEditor} from '../../PortableTextEditor'
|
|
10
7
|
|
|
@@ -14,7 +11,7 @@ describe('plugin:withPortableTextLists', () => {
|
|
|
14
11
|
const initialValue = [
|
|
15
12
|
{
|
|
16
13
|
_key: 'a',
|
|
17
|
-
_type: '
|
|
14
|
+
_type: 'block',
|
|
18
15
|
children: [
|
|
19
16
|
{
|
|
20
17
|
_key: 'a1',
|
|
@@ -28,7 +25,7 @@ describe('plugin:withPortableTextLists', () => {
|
|
|
28
25
|
},
|
|
29
26
|
{
|
|
30
27
|
_key: 'b',
|
|
31
|
-
_type: '
|
|
28
|
+
_type: 'block',
|
|
32
29
|
children: [
|
|
33
30
|
{
|
|
34
31
|
_key: '2',
|
|
@@ -50,7 +47,6 @@ describe('plugin:withPortableTextLists', () => {
|
|
|
50
47
|
keyGenerator={createTestKeyGenerator()}
|
|
51
48
|
onChange={onChange}
|
|
52
49
|
ref={editorRef}
|
|
53
|
-
schemaType={schemaType}
|
|
54
50
|
value={initialValue}
|
|
55
51
|
/>,
|
|
56
52
|
)
|