@portabletext/editor 1.40.0 → 1.40.1
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-cjs/editor-provider.cjs +9 -7
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +9 -7
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/index.cjs +2 -2
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/converters/converter.portable-text.ts +9 -0
- package/src/converters/converter.text-plain.test.ts +5 -5
- package/src/converters/converter.text-plain.ts +12 -19
- package/src/editor/components/Element.tsx +2 -7
- package/src/editor/plugins/create-with-event-listeners.ts +2 -5
package/package.json
CHANGED
|
@@ -22,6 +22,15 @@ export const converterPortableText = defineConverter({
|
|
|
22
22
|
selection,
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
+
if (blocks.length === 0) {
|
|
26
|
+
return {
|
|
27
|
+
type: 'serialization.failure',
|
|
28
|
+
mimeType: 'application/x-portable-text',
|
|
29
|
+
reason: 'No blocks serialized',
|
|
30
|
+
originEvent: event.originEvent,
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
25
34
|
return {
|
|
26
35
|
type: 'serialization.success',
|
|
27
36
|
data: JSON.stringify(blocks),
|
|
@@ -128,7 +128,7 @@ test(converterTextPlain.serialize.name, () => {
|
|
|
128
128
|
},
|
|
129
129
|
}),
|
|
130
130
|
).toMatchObject({
|
|
131
|
-
data: 'foobar\n\
|
|
131
|
+
data: 'foobar\n\nbaz',
|
|
132
132
|
})
|
|
133
133
|
|
|
134
134
|
expect(
|
|
@@ -152,7 +152,7 @@ test(converterTextPlain.serialize.name, () => {
|
|
|
152
152
|
},
|
|
153
153
|
}),
|
|
154
154
|
).toMatchObject({
|
|
155
|
-
data: '
|
|
155
|
+
data: '',
|
|
156
156
|
})
|
|
157
157
|
|
|
158
158
|
expect(
|
|
@@ -182,7 +182,7 @@ test(converterTextPlain.serialize.name, () => {
|
|
|
182
182
|
},
|
|
183
183
|
}),
|
|
184
184
|
).toMatchObject({
|
|
185
|
-
data: 'foobar\n\
|
|
185
|
+
data: 'foobar\n\nbaz',
|
|
186
186
|
})
|
|
187
187
|
|
|
188
188
|
expect(
|
|
@@ -206,7 +206,7 @@ test(converterTextPlain.serialize.name, () => {
|
|
|
206
206
|
},
|
|
207
207
|
}),
|
|
208
208
|
).toMatchObject({
|
|
209
|
-
data: '
|
|
209
|
+
data: 'fizzbuzz',
|
|
210
210
|
})
|
|
211
211
|
|
|
212
212
|
expect(
|
|
@@ -236,6 +236,6 @@ test(converterTextPlain.serialize.name, () => {
|
|
|
236
236
|
},
|
|
237
237
|
}),
|
|
238
238
|
).toMatchObject({
|
|
239
|
-
data: '
|
|
239
|
+
data: 'fizzbuzz',
|
|
240
240
|
})
|
|
241
241
|
})
|
|
@@ -25,28 +25,21 @@ export const converterTextPlain = defineConverter({
|
|
|
25
25
|
|
|
26
26
|
const data = blocks
|
|
27
27
|
.map((block) => {
|
|
28
|
-
if (isPortableTextTextBlock(block)) {
|
|
29
|
-
return
|
|
30
|
-
.map((child) => {
|
|
31
|
-
if (child._type === snapshot.context.schema.span.name) {
|
|
32
|
-
return child.text
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return `[${
|
|
36
|
-
snapshot.context.schema.inlineObjects.find(
|
|
37
|
-
(inlineObjectType) => inlineObjectType.name === child._type,
|
|
38
|
-
)?.title ?? 'Object'
|
|
39
|
-
}]`
|
|
40
|
-
})
|
|
41
|
-
.join('')
|
|
28
|
+
if (!isPortableTextTextBlock(block)) {
|
|
29
|
+
return ''
|
|
42
30
|
}
|
|
43
31
|
|
|
44
|
-
return
|
|
45
|
-
|
|
46
|
-
(
|
|
47
|
-
|
|
48
|
-
|
|
32
|
+
return block.children
|
|
33
|
+
.map((child) => {
|
|
34
|
+
if (child._type === snapshot.context.schema.span.name) {
|
|
35
|
+
return child.text
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return ''
|
|
39
|
+
})
|
|
40
|
+
.join('')
|
|
49
41
|
})
|
|
42
|
+
.filter((block) => block !== '')
|
|
50
43
|
.join('\n\n')
|
|
51
44
|
|
|
52
45
|
return {
|
|
@@ -419,15 +419,10 @@ export const Element: FunctionComponent<ElementProps> = ({
|
|
|
419
419
|
}
|
|
420
420
|
|
|
421
421
|
return (
|
|
422
|
-
<div
|
|
423
|
-
key={element._key}
|
|
424
|
-
{...attributes}
|
|
425
|
-
className={className}
|
|
426
|
-
draggable={!readOnly}
|
|
427
|
-
>
|
|
422
|
+
<div key={element._key} {...attributes} className={className}>
|
|
428
423
|
{dragPositionBlock === 'start' ? <DropIndicator /> : null}
|
|
429
424
|
{children}
|
|
430
|
-
<div ref={blockRef} contentEditable={false}>
|
|
425
|
+
<div ref={blockRef} contentEditable={false} draggable={!readOnly}>
|
|
431
426
|
{renderedBlockFromProps ? (
|
|
432
427
|
renderedBlockFromProps
|
|
433
428
|
) : (
|
|
@@ -122,12 +122,9 @@ export function createWithEventListeners(
|
|
|
122
122
|
editorActor.send({
|
|
123
123
|
type: 'behavior event',
|
|
124
124
|
behaviorEvent: {
|
|
125
|
-
type: '
|
|
125
|
+
type: 'input.*',
|
|
126
126
|
originEvent: {
|
|
127
|
-
|
|
128
|
-
originEvent: {
|
|
129
|
-
dataTransfer,
|
|
130
|
-
},
|
|
127
|
+
dataTransfer,
|
|
131
128
|
},
|
|
132
129
|
},
|
|
133
130
|
editor,
|