@portabletext/editor 1.44.14 → 1.44.16
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 +107 -97
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +113 -103
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/behaviors/index.d.cts +814 -600
- package/lib/behaviors/index.d.ts +814 -600
- package/lib/index.d.cts +12 -8
- package/lib/index.d.ts +12 -8
- package/lib/plugins/index.cjs +9 -0
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +12 -8
- package/lib/plugins/index.d.ts +12 -8
- package/lib/plugins/index.js +9 -0
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.cts +12 -8
- package/lib/selectors/index.d.ts +12 -8
- package/lib/utils/index.d.cts +12 -8
- package/lib/utils/index.d.ts +12 -8
- package/package.json +5 -5
- package/src/behavior-actions/{behavior.action.insert-break.ts → behavior.action.split.block.ts} +3 -9
- package/src/behavior-actions/behavior.actions.ts +9 -20
- package/src/behaviors/behavior.abstract.insert.ts +9 -1
- package/src/behaviors/behavior.default.ts +30 -28
- package/src/behaviors/behavior.types.event.ts +12 -8
- package/src/editor/plugins/create-with-event-listeners.ts +3 -3
- package/src/plugins/plugin.one-line.tsx +7 -0
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type {ConverterEvent} from '../converters/converter.types'
|
|
1
2
|
import {isTextBlock} from '../internal-utils/parse-blocks'
|
|
2
3
|
import * as selectors from '../selectors'
|
|
4
|
+
import type {PickFromUnion} from '../type-utils'
|
|
3
5
|
import {getTextBlockText} from '../utils'
|
|
4
6
|
import {abstractAnnotationBehaviors} from './behavior.abstract.annotation'
|
|
5
7
|
import {abstractDecoratorBehaviors} from './behavior.abstract.decorator'
|
|
@@ -15,44 +17,44 @@ import {defineBehavior} from './behavior.types.behavior'
|
|
|
15
17
|
const raiseDeserializationSuccessOrFailure = defineBehavior({
|
|
16
18
|
on: 'deserialize',
|
|
17
19
|
guard: ({snapshot, event}) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
let success:
|
|
21
|
+
| PickFromUnion<ConverterEvent, 'type', 'deserialization.success'>
|
|
22
|
+
| undefined
|
|
23
|
+
const failures: Array<
|
|
24
|
+
PickFromUnion<ConverterEvent, 'type', 'deserialization.failure'>
|
|
25
|
+
> = []
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
for (const converter of snapshot.context.converters) {
|
|
28
|
+
const data = event.originEvent.originEvent.dataTransfer.getData(
|
|
29
|
+
converter.mimeType,
|
|
30
|
+
)
|
|
27
31
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
event: {type: 'deserialize', data},
|
|
32
|
-
}),
|
|
33
|
-
]
|
|
34
|
-
},
|
|
35
|
-
)
|
|
32
|
+
if (!data) {
|
|
33
|
+
continue
|
|
34
|
+
}
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
const deserializeEvent = converter.deserialize({
|
|
37
|
+
snapshot,
|
|
38
|
+
event: {type: 'deserialize', data},
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
if (deserializeEvent.type === 'deserialization.success') {
|
|
42
|
+
success = deserializeEvent
|
|
43
|
+
break
|
|
44
|
+
} else {
|
|
45
|
+
failures.push(deserializeEvent)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
40
48
|
|
|
41
|
-
if (!
|
|
49
|
+
if (!success) {
|
|
42
50
|
return {
|
|
43
51
|
type: 'deserialization.failure',
|
|
44
52
|
mimeType: '*/*',
|
|
45
|
-
reason:
|
|
46
|
-
.map((deserializeEvent) =>
|
|
47
|
-
deserializeEvent.type === 'deserialization.failure'
|
|
48
|
-
? deserializeEvent.reason
|
|
49
|
-
: '',
|
|
50
|
-
)
|
|
51
|
-
.join(', '),
|
|
53
|
+
reason: failures.map((failure) => failure.reason).join(', '),
|
|
52
54
|
} as const
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
return
|
|
57
|
+
return success
|
|
56
58
|
},
|
|
57
59
|
actions: [
|
|
58
60
|
({event}, deserializeEvent) => [
|
|
@@ -73,13 +73,12 @@ const syntheticBehaviorEventTypes = [
|
|
|
73
73
|
'history.redo',
|
|
74
74
|
'history.undo',
|
|
75
75
|
'insert.inline object',
|
|
76
|
-
'insert.break',
|
|
77
|
-
'insert.soft break',
|
|
78
76
|
'insert.block',
|
|
79
77
|
'insert.span',
|
|
80
78
|
'insert.text',
|
|
81
79
|
'move.block',
|
|
82
80
|
'select',
|
|
81
|
+
'split.block',
|
|
83
82
|
] as const
|
|
84
83
|
|
|
85
84
|
type SyntheticBehaviorEventType = (typeof syntheticBehaviorEventTypes)[number]
|
|
@@ -163,12 +162,6 @@ export type SyntheticBehaviorEvent =
|
|
|
163
162
|
value?: {[prop: string]: unknown}
|
|
164
163
|
}
|
|
165
164
|
}
|
|
166
|
-
| {
|
|
167
|
-
type: StrictExtract<SyntheticBehaviorEventType, 'insert.break'>
|
|
168
|
-
}
|
|
169
|
-
| {
|
|
170
|
-
type: StrictExtract<SyntheticBehaviorEventType, 'insert.soft break'>
|
|
171
|
-
}
|
|
172
165
|
| {
|
|
173
166
|
type: StrictExtract<SyntheticBehaviorEventType, 'insert.block'>
|
|
174
167
|
block: BlockWithOptionalKey
|
|
@@ -197,6 +190,9 @@ export type SyntheticBehaviorEvent =
|
|
|
197
190
|
type: StrictExtract<SyntheticBehaviorEventType, 'select'>
|
|
198
191
|
selection: EditorSelection
|
|
199
192
|
}
|
|
193
|
+
| {
|
|
194
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'split.block'>
|
|
195
|
+
}
|
|
200
196
|
|
|
201
197
|
export type InsertPlacement = 'auto' | 'after' | 'before'
|
|
202
198
|
|
|
@@ -217,6 +213,8 @@ const abstractBehaviorEventTypes = [
|
|
|
217
213
|
'deserialization.success',
|
|
218
214
|
'deserialization.failure',
|
|
219
215
|
'insert.blocks',
|
|
216
|
+
'insert.break',
|
|
217
|
+
'insert.soft break',
|
|
220
218
|
'list item.add',
|
|
221
219
|
'list item.remove',
|
|
222
220
|
'list item.toggle',
|
|
@@ -317,6 +315,12 @@ export type AbstractBehaviorEvent =
|
|
|
317
315
|
blocks: Array<PortableTextBlock>
|
|
318
316
|
placement: InsertPlacement
|
|
319
317
|
}
|
|
318
|
+
| {
|
|
319
|
+
type: StrictExtract<AbstractBehaviorEventType, 'insert.break'>
|
|
320
|
+
}
|
|
321
|
+
| {
|
|
322
|
+
type: StrictExtract<AbstractBehaviorEventType, 'insert.soft break'>
|
|
323
|
+
}
|
|
320
324
|
| {
|
|
321
325
|
type: StrictExtract<AbstractBehaviorEventType, 'list item.add'>
|
|
322
326
|
listItem: string
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {Editor} from 'slate'
|
|
2
|
-
import {
|
|
2
|
+
import {insertTextActionImplementation} from '../../behavior-actions/behavior.action.insert.text'
|
|
3
3
|
import {performAction} from '../../behavior-actions/behavior.actions'
|
|
4
4
|
import {slateRangeToSelection} from '../../internal-utils/slate-utils'
|
|
5
5
|
import type {EditorActor} from '../editor-machine'
|
|
@@ -83,12 +83,12 @@ export function createWithEventListeners(editorActor: EditorActor) {
|
|
|
83
83
|
|
|
84
84
|
editor.insertSoftBreak = () => {
|
|
85
85
|
if (isApplyingBehaviorActions(editor)) {
|
|
86
|
-
|
|
86
|
+
insertTextActionImplementation({
|
|
87
87
|
context: {
|
|
88
88
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
89
89
|
schema: editorActor.getSnapshot().context.schema,
|
|
90
90
|
},
|
|
91
|
-
action: {type: 'insert.
|
|
91
|
+
action: {type: 'insert.text', text: '\n', editor},
|
|
92
92
|
})
|
|
93
93
|
return
|
|
94
94
|
}
|
|
@@ -23,6 +23,13 @@ const oneLineBehaviors = [
|
|
|
23
23
|
on: 'insert.break',
|
|
24
24
|
actions: [() => [{type: 'noop'}]],
|
|
25
25
|
}),
|
|
26
|
+
/**
|
|
27
|
+
* `split.block`s as well.
|
|
28
|
+
*/
|
|
29
|
+
defineBehavior({
|
|
30
|
+
on: 'split.block',
|
|
31
|
+
actions: [() => [{type: 'noop'}]],
|
|
32
|
+
}),
|
|
26
33
|
/**
|
|
27
34
|
* `insert.block` `before` or `after` is not allowed in a one-line editor.
|
|
28
35
|
*/
|