@portabletext/editor 1.44.0 → 1.44.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-cjs/behavior.core.cjs +3 -3
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +323 -490
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +3 -3
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +325 -492
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/behaviors/index.cjs +2 -2
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +8390 -16283
- package/lib/behaviors/index.d.ts +8390 -16283
- package/lib/behaviors/index.js +4 -4
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +2 -2
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +2237 -15969
- package/lib/index.d.ts +2237 -15969
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +2088 -15821
- package/lib/plugins/index.d.ts +2088 -15821
- package/lib/selectors/index.d.cts +1738 -15472
- package/lib/selectors/index.d.ts +1738 -15472
- package/lib/utils/index.d.cts +1738 -15472
- package/lib/utils/index.d.ts +1738 -15472
- package/package.json +2 -2
- package/src/behavior-actions/behavior.actions.ts +1 -39
- package/src/behaviors/behavior.abstract.annotation.ts +26 -0
- package/src/behaviors/behavior.abstract.decorator.ts +47 -0
- package/src/behaviors/{behavior.internal.insert.ts → behavior.abstract.insert.ts} +1 -1
- package/src/behaviors/{behavior.internal.list-item.ts → behavior.abstract.list-item.ts} +1 -1
- package/src/behaviors/behavior.abstract.move.ts +78 -0
- package/src/behaviors/{behavior.internal.select.ts → behavior.abstract.select.ts} +1 -1
- package/src/behaviors/{behavior.internal.style.ts → behavior.abstract.style.ts} +1 -1
- package/src/behaviors/behavior.code-editor.ts +13 -8
- package/src/behaviors/behavior.default.ts +15 -78
- package/src/behaviors/behavior.perform-event.ts +4 -4
- package/src/behaviors/behavior.types.action.ts +3 -3
- package/src/behaviors/behavior.types.behavior.ts +4 -3
- package/src/behaviors/behavior.types.event.ts +164 -160
- package/src/editor/components/Leaf.tsx +2 -2
- package/src/editor/create-editor.ts +37 -11
- package/src/editor/editor-machine.ts +4 -76
- package/src/editor/editor-selector.ts +5 -2
- package/src/editor/editor-snapshot.ts +2 -7
- package/src/editor/plugins/create-with-event-listeners.ts +1 -64
- package/src/editor/plugins/createWithEditableAPI.ts +0 -30
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +0 -29
- package/src/editor/plugins/with-plugins.ts +1 -4
- package/src/internal-utils/slate-children-to-blocks.ts +49 -0
- package/src/internal-utils/slate-utils.ts +6 -8
- package/src/type-utils.ts +2 -0
- package/src/behavior-actions/behavior.action.move.block-down.ts +0 -48
- package/src/behavior-actions/behavior.action.move.block-up.ts +0 -53
|
@@ -2,7 +2,7 @@ import type {KeyedSegment, PortableTextBlock} from '@sanity/types'
|
|
|
2
2
|
import type {TextUnit} from 'slate'
|
|
3
3
|
import type {EventPosition} from '../internal-utils/event-position'
|
|
4
4
|
import type {MIMEType} from '../internal-utils/mime-type'
|
|
5
|
-
import type {PickFromUnion} from '../type-utils'
|
|
5
|
+
import type {PickFromUnion, StrictExtract} from '../type-utils'
|
|
6
6
|
import type {BlockOffset} from '../types/block-offset'
|
|
7
7
|
import type {BlockWithOptionalKey} from '../types/block-with-optional-key'
|
|
8
8
|
import type {EditorSelection} from '../types/editor'
|
|
@@ -12,13 +12,13 @@ import type {EditorSelection} from '../types/editor'
|
|
|
12
12
|
*/
|
|
13
13
|
export type BehaviorEvent =
|
|
14
14
|
| SyntheticBehaviorEvent
|
|
15
|
-
|
|
|
15
|
+
| AbstractBehaviorEvent
|
|
16
16
|
| NativeBehaviorEvent
|
|
17
17
|
| CustomBehaviorEvent
|
|
18
18
|
|
|
19
19
|
export type BehaviorEventTypeNamespace =
|
|
20
20
|
| SyntheticBehaviorEventNamespace
|
|
21
|
-
|
|
|
21
|
+
| AbstractBehaviorEventNamespace
|
|
22
22
|
| NativeBehaviorEventNamespace
|
|
23
23
|
| CustomBehaviorEventNamespace
|
|
24
24
|
|
|
@@ -49,8 +49,10 @@ export type ExternalBehaviorEvent =
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
| PickFromUnion<
|
|
52
|
-
|
|
52
|
+
AbstractBehaviorEvent,
|
|
53
53
|
'type',
|
|
54
|
+
| 'annotation.toggle'
|
|
55
|
+
| 'decorator.toggle'
|
|
54
56
|
| 'insert.blocks'
|
|
55
57
|
| 'list item.add'
|
|
56
58
|
| 'list item.remove'
|
|
@@ -59,130 +61,134 @@ export type ExternalBehaviorEvent =
|
|
|
59
61
|
| 'style.remove'
|
|
60
62
|
| 'style.toggle'
|
|
61
63
|
>
|
|
64
|
+
| SyntheticBehaviorEvent
|
|
65
|
+
| CustomBehaviorEvent
|
|
62
66
|
|
|
63
67
|
/**************************************
|
|
64
68
|
* Synthetic events
|
|
65
69
|
**************************************/
|
|
66
70
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
const syntheticBehaviorEventTypes = [
|
|
72
|
+
'annotation.add',
|
|
73
|
+
'annotation.remove',
|
|
74
|
+
'block.set',
|
|
75
|
+
'block.unset',
|
|
76
|
+
'blur',
|
|
77
|
+
'decorator.add',
|
|
78
|
+
'decorator.remove',
|
|
79
|
+
'delete',
|
|
80
|
+
'delete.backward',
|
|
81
|
+
'delete.block',
|
|
82
|
+
'delete.forward',
|
|
83
|
+
'delete.text',
|
|
84
|
+
'focus',
|
|
85
|
+
'history.redo',
|
|
86
|
+
'history.undo',
|
|
87
|
+
'insert.inline object',
|
|
88
|
+
'insert.break',
|
|
89
|
+
'insert.soft break',
|
|
90
|
+
'insert.block',
|
|
91
|
+
'insert.span',
|
|
92
|
+
'insert.text',
|
|
93
|
+
'move.block',
|
|
94
|
+
'select',
|
|
95
|
+
] as const
|
|
96
|
+
|
|
97
|
+
type SyntheticBehaviorEventType = (typeof syntheticBehaviorEventTypes)[number]
|
|
71
98
|
|
|
72
99
|
type SyntheticBehaviorEventNamespace =
|
|
73
|
-
|
|
74
|
-
| 'block'
|
|
75
|
-
| 'blur'
|
|
76
|
-
| 'decorator'
|
|
77
|
-
| 'delete'
|
|
78
|
-
| 'focus'
|
|
79
|
-
| 'history'
|
|
80
|
-
| 'insert'
|
|
81
|
-
| 'move'
|
|
82
|
-
| 'select'
|
|
100
|
+
ExtractNamespace<SyntheticBehaviorEventType>
|
|
83
101
|
|
|
84
102
|
/**
|
|
85
103
|
* @beta
|
|
86
104
|
*/
|
|
87
105
|
export type SyntheticBehaviorEvent =
|
|
88
106
|
| {
|
|
89
|
-
type: SyntheticBehaviorEventType
|
|
107
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'annotation.add'>
|
|
90
108
|
annotation: {
|
|
91
109
|
name: string
|
|
92
110
|
value: {[prop: string]: unknown}
|
|
93
111
|
}
|
|
94
112
|
}
|
|
95
113
|
| {
|
|
96
|
-
type: SyntheticBehaviorEventType
|
|
97
|
-
annotation: {
|
|
98
|
-
name: string
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
| {
|
|
102
|
-
type: SyntheticBehaviorEventType<'annotation', 'toggle'>
|
|
114
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'annotation.remove'>
|
|
103
115
|
annotation: {
|
|
104
116
|
name: string
|
|
105
|
-
value: {[prop: string]: unknown}
|
|
106
117
|
}
|
|
107
118
|
}
|
|
108
119
|
| {
|
|
109
|
-
type: SyntheticBehaviorEventType
|
|
120
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'block.set'>
|
|
110
121
|
at: [KeyedSegment]
|
|
111
122
|
props: Record<string, unknown>
|
|
112
123
|
}
|
|
113
124
|
| {
|
|
114
|
-
type: SyntheticBehaviorEventType
|
|
125
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'block.unset'>
|
|
115
126
|
at: [KeyedSegment]
|
|
116
127
|
props: Array<string>
|
|
117
128
|
}
|
|
118
129
|
| {
|
|
119
|
-
type: SyntheticBehaviorEventType
|
|
130
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'blur'>
|
|
120
131
|
}
|
|
121
132
|
| {
|
|
122
|
-
type: SyntheticBehaviorEventType
|
|
133
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'decorator.add'>
|
|
123
134
|
decorator: string
|
|
124
135
|
offsets?: {anchor: BlockOffset; focus: BlockOffset}
|
|
125
136
|
}
|
|
126
137
|
| {
|
|
127
|
-
type: SyntheticBehaviorEventType
|
|
138
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'decorator.remove'>
|
|
128
139
|
decorator: string
|
|
129
140
|
}
|
|
130
141
|
| {
|
|
131
|
-
type: SyntheticBehaviorEventType
|
|
132
|
-
decorator: string
|
|
133
|
-
offsets?: {anchor: BlockOffset; focus: BlockOffset}
|
|
134
|
-
}
|
|
135
|
-
| {
|
|
136
|
-
type: SyntheticBehaviorEventType<'delete'>
|
|
142
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'delete'>
|
|
137
143
|
selection: NonNullable<EditorSelection>
|
|
138
144
|
}
|
|
139
145
|
| {
|
|
140
|
-
type: SyntheticBehaviorEventType
|
|
146
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'delete.backward'>
|
|
141
147
|
unit: TextUnit
|
|
142
148
|
}
|
|
143
149
|
| {
|
|
144
|
-
type: SyntheticBehaviorEventType
|
|
150
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'delete.block'>
|
|
145
151
|
at: [KeyedSegment]
|
|
146
152
|
}
|
|
147
153
|
| {
|
|
148
|
-
type: SyntheticBehaviorEventType
|
|
154
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'delete.forward'>
|
|
149
155
|
unit: TextUnit
|
|
150
156
|
}
|
|
151
157
|
| {
|
|
152
|
-
type: SyntheticBehaviorEventType
|
|
158
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'delete.text'>
|
|
153
159
|
anchor: BlockOffset
|
|
154
160
|
focus: BlockOffset
|
|
155
161
|
}
|
|
156
162
|
| {
|
|
157
|
-
type: SyntheticBehaviorEventType
|
|
163
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'focus'>
|
|
158
164
|
}
|
|
159
165
|
| {
|
|
160
|
-
type: SyntheticBehaviorEventType
|
|
166
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'history.redo'>
|
|
161
167
|
}
|
|
162
168
|
| {
|
|
163
|
-
type: SyntheticBehaviorEventType
|
|
169
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'history.undo'>
|
|
164
170
|
}
|
|
165
171
|
| {
|
|
166
|
-
type: SyntheticBehaviorEventType
|
|
172
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'insert.inline object'>
|
|
167
173
|
inlineObject: {
|
|
168
174
|
name: string
|
|
169
175
|
value?: {[prop: string]: unknown}
|
|
170
176
|
}
|
|
171
177
|
}
|
|
172
178
|
| {
|
|
173
|
-
type: SyntheticBehaviorEventType
|
|
179
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'insert.break'>
|
|
174
180
|
}
|
|
175
181
|
| {
|
|
176
|
-
type: SyntheticBehaviorEventType
|
|
182
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'insert.soft break'>
|
|
177
183
|
}
|
|
178
184
|
| {
|
|
179
|
-
type: SyntheticBehaviorEventType
|
|
185
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'insert.block'>
|
|
180
186
|
block: BlockWithOptionalKey
|
|
181
187
|
placement: InsertPlacement
|
|
182
188
|
select?: 'start' | 'end' | 'none'
|
|
183
189
|
}
|
|
184
190
|
| {
|
|
185
|
-
type: SyntheticBehaviorEventType
|
|
191
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'insert.span'>
|
|
186
192
|
text: string
|
|
187
193
|
annotations?: Array<{
|
|
188
194
|
name: string
|
|
@@ -191,24 +197,16 @@ export type SyntheticBehaviorEvent =
|
|
|
191
197
|
decorators?: Array<string>
|
|
192
198
|
}
|
|
193
199
|
| {
|
|
194
|
-
type: SyntheticBehaviorEventType
|
|
200
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'insert.text'>
|
|
195
201
|
text: string
|
|
196
202
|
}
|
|
197
203
|
| {
|
|
198
|
-
type: SyntheticBehaviorEventType
|
|
204
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'move.block'>
|
|
199
205
|
at: [KeyedSegment]
|
|
200
206
|
to: [KeyedSegment]
|
|
201
207
|
}
|
|
202
208
|
| {
|
|
203
|
-
type: SyntheticBehaviorEventType
|
|
204
|
-
at: [KeyedSegment]
|
|
205
|
-
}
|
|
206
|
-
| {
|
|
207
|
-
type: SyntheticBehaviorEventType<'move', 'block up'>
|
|
208
|
-
at: [KeyedSegment]
|
|
209
|
-
}
|
|
210
|
-
| {
|
|
211
|
-
type: SyntheticBehaviorEventType<'select'>
|
|
209
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'select'>
|
|
212
210
|
selection: EditorSelection
|
|
213
211
|
}
|
|
214
212
|
|
|
@@ -221,27 +219,51 @@ export function isKeyboardBehaviorEvent(
|
|
|
221
219
|
}
|
|
222
220
|
|
|
223
221
|
/**************************************
|
|
224
|
-
*
|
|
222
|
+
* Abstract events
|
|
225
223
|
**************************************/
|
|
226
224
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
225
|
+
const abstractBehaviorEventTypes = [
|
|
226
|
+
'annotation.toggle',
|
|
227
|
+
'decorator.toggle',
|
|
228
|
+
'deserialize',
|
|
229
|
+
'deserialization.success',
|
|
230
|
+
'deserialization.failure',
|
|
231
|
+
'insert.blocks',
|
|
232
|
+
'list item.add',
|
|
233
|
+
'list item.remove',
|
|
234
|
+
'list item.toggle',
|
|
235
|
+
'move.block down',
|
|
236
|
+
'move.block up',
|
|
237
|
+
'select.previous block',
|
|
238
|
+
'select.next block',
|
|
239
|
+
'serialize',
|
|
240
|
+
'serialization.success',
|
|
241
|
+
'serialization.failure',
|
|
242
|
+
'style.add',
|
|
243
|
+
'style.remove',
|
|
244
|
+
'style.toggle',
|
|
245
|
+
] as const
|
|
246
|
+
|
|
247
|
+
type AbstractBehaviorEventType = (typeof abstractBehaviorEventTypes)[number]
|
|
248
|
+
|
|
249
|
+
type AbstractBehaviorEventNamespace =
|
|
250
|
+
ExtractNamespace<AbstractBehaviorEventType>
|
|
251
|
+
|
|
252
|
+
export type AbstractBehaviorEvent =
|
|
253
|
+
| {
|
|
254
|
+
type: StrictExtract<AbstractBehaviorEventType, 'annotation.toggle'>
|
|
255
|
+
annotation: {
|
|
256
|
+
name: string
|
|
257
|
+
value: {[prop: string]: unknown}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
243
260
|
| {
|
|
244
|
-
type:
|
|
261
|
+
type: StrictExtract<AbstractBehaviorEventType, 'decorator.toggle'>
|
|
262
|
+
decorator: string
|
|
263
|
+
offsets?: {anchor: BlockOffset; focus: BlockOffset}
|
|
264
|
+
}
|
|
265
|
+
| {
|
|
266
|
+
type: StrictExtract<AbstractBehaviorEventType, 'deserialize'>
|
|
245
267
|
originEvent:
|
|
246
268
|
| PickFromUnion<
|
|
247
269
|
NativeBehaviorEvent,
|
|
@@ -251,7 +273,7 @@ export type InternalBehaviorEvent =
|
|
|
251
273
|
| InputBehaviorEvent
|
|
252
274
|
}
|
|
253
275
|
| {
|
|
254
|
-
type:
|
|
276
|
+
type: StrictExtract<AbstractBehaviorEventType, 'serialize'>
|
|
255
277
|
originEvent: PickFromUnion<
|
|
256
278
|
NativeBehaviorEvent,
|
|
257
279
|
'type',
|
|
@@ -259,7 +281,7 @@ export type InternalBehaviorEvent =
|
|
|
259
281
|
>
|
|
260
282
|
}
|
|
261
283
|
| {
|
|
262
|
-
type:
|
|
284
|
+
type: StrictExtract<AbstractBehaviorEventType, 'deserialization.success'>
|
|
263
285
|
mimeType: MIMEType
|
|
264
286
|
data: Array<PortableTextBlock>
|
|
265
287
|
originEvent:
|
|
@@ -271,7 +293,7 @@ export type InternalBehaviorEvent =
|
|
|
271
293
|
| InputBehaviorEvent
|
|
272
294
|
}
|
|
273
295
|
| {
|
|
274
|
-
type:
|
|
296
|
+
type: StrictExtract<AbstractBehaviorEventType, 'deserialization.failure'>
|
|
275
297
|
mimeType: MIMEType
|
|
276
298
|
reason: string
|
|
277
299
|
originEvent:
|
|
@@ -283,7 +305,7 @@ export type InternalBehaviorEvent =
|
|
|
283
305
|
| InputBehaviorEvent
|
|
284
306
|
}
|
|
285
307
|
| {
|
|
286
|
-
type:
|
|
308
|
+
type: StrictExtract<AbstractBehaviorEventType, 'serialization.success'>
|
|
287
309
|
mimeType: MIMEType
|
|
288
310
|
data: string
|
|
289
311
|
originEvent: PickFromUnion<
|
|
@@ -293,7 +315,7 @@ export type InternalBehaviorEvent =
|
|
|
293
315
|
>
|
|
294
316
|
}
|
|
295
317
|
| {
|
|
296
|
-
type:
|
|
318
|
+
type: StrictExtract<AbstractBehaviorEventType, 'serialization.failure'>
|
|
297
319
|
mimeType: MIMEType
|
|
298
320
|
reason: string
|
|
299
321
|
originEvent: PickFromUnion<
|
|
@@ -303,85 +325,86 @@ export type InternalBehaviorEvent =
|
|
|
303
325
|
>
|
|
304
326
|
}
|
|
305
327
|
| {
|
|
306
|
-
type:
|
|
328
|
+
type: StrictExtract<AbstractBehaviorEventType, 'insert.blocks'>
|
|
307
329
|
blocks: Array<PortableTextBlock>
|
|
308
330
|
placement: InsertPlacement
|
|
309
331
|
}
|
|
310
332
|
| {
|
|
311
|
-
type:
|
|
333
|
+
type: StrictExtract<AbstractBehaviorEventType, 'list item.add'>
|
|
312
334
|
listItem: string
|
|
313
335
|
}
|
|
314
336
|
| {
|
|
315
|
-
type:
|
|
337
|
+
type: StrictExtract<AbstractBehaviorEventType, 'list item.remove'>
|
|
316
338
|
listItem: string
|
|
317
339
|
}
|
|
318
340
|
| {
|
|
319
|
-
type:
|
|
341
|
+
type: StrictExtract<AbstractBehaviorEventType, 'list item.toggle'>
|
|
320
342
|
listItem: string
|
|
321
343
|
}
|
|
322
344
|
| {
|
|
323
|
-
type:
|
|
345
|
+
type: StrictExtract<AbstractBehaviorEventType, 'move.block down'>
|
|
346
|
+
at: [KeyedSegment]
|
|
347
|
+
}
|
|
348
|
+
| {
|
|
349
|
+
type: StrictExtract<AbstractBehaviorEventType, 'move.block up'>
|
|
350
|
+
at: [KeyedSegment]
|
|
351
|
+
}
|
|
352
|
+
| {
|
|
353
|
+
type: StrictExtract<AbstractBehaviorEventType, 'select.previous block'>
|
|
324
354
|
select?: 'start' | 'end'
|
|
325
355
|
}
|
|
326
356
|
| {
|
|
327
|
-
type:
|
|
357
|
+
type: StrictExtract<AbstractBehaviorEventType, 'select.next block'>
|
|
328
358
|
select?: 'start' | 'end'
|
|
329
359
|
}
|
|
330
360
|
| {
|
|
331
|
-
type:
|
|
361
|
+
type: StrictExtract<AbstractBehaviorEventType, 'style.add'>
|
|
332
362
|
style: string
|
|
333
363
|
}
|
|
334
364
|
| {
|
|
335
|
-
type:
|
|
365
|
+
type: StrictExtract<AbstractBehaviorEventType, 'style.remove'>
|
|
336
366
|
style: string
|
|
337
367
|
}
|
|
338
368
|
| {
|
|
339
|
-
type:
|
|
369
|
+
type: StrictExtract<AbstractBehaviorEventType, 'style.toggle'>
|
|
340
370
|
style: string
|
|
341
371
|
}
|
|
342
372
|
|
|
343
|
-
export function
|
|
373
|
+
export function isAbstractBehaviorEvent(
|
|
344
374
|
event: BehaviorEvent,
|
|
345
|
-
): event is
|
|
346
|
-
return (
|
|
347
|
-
event.type === 'deserialize' ||
|
|
348
|
-
event.type.startsWith('deserialization.') ||
|
|
349
|
-
event.type === 'insert.blocks' ||
|
|
350
|
-
event.type.startsWith('list item.') ||
|
|
351
|
-
event.type === 'serialize' ||
|
|
352
|
-
event.type.startsWith('serialization.') ||
|
|
353
|
-
event.type === 'select.next block' ||
|
|
354
|
-
event.type === 'select.previous block' ||
|
|
355
|
-
event.type.startsWith('style.')
|
|
356
|
-
)
|
|
375
|
+
): event is AbstractBehaviorEvent {
|
|
376
|
+
return (abstractBehaviorEventTypes as readonly string[]).includes(event.type)
|
|
357
377
|
}
|
|
358
378
|
|
|
359
379
|
/**************************************
|
|
360
380
|
* Native events
|
|
361
381
|
**************************************/
|
|
362
382
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
383
|
+
const nativeBehaviorEventTypes = [
|
|
384
|
+
'clipboard.copy',
|
|
385
|
+
'clipboard.cut',
|
|
386
|
+
'clipboard.paste',
|
|
387
|
+
'drag.dragstart',
|
|
388
|
+
'drag.drag',
|
|
389
|
+
'drag.dragend',
|
|
390
|
+
'drag.dragenter',
|
|
391
|
+
'drag.dragover',
|
|
392
|
+
'drag.dragleave',
|
|
393
|
+
'drag.drop',
|
|
394
|
+
'input.*',
|
|
395
|
+
'keyboard.keydown',
|
|
396
|
+
'keyboard.keyup',
|
|
397
|
+
'mouse.click',
|
|
398
|
+
] as const
|
|
399
|
+
|
|
400
|
+
type NativeBehaviorEventType = (typeof nativeBehaviorEventTypes)[number]
|
|
401
|
+
|
|
402
|
+
type NativeBehaviorEventNamespace = ExtractNamespace<NativeBehaviorEventType>
|
|
374
403
|
|
|
375
404
|
export function isNativeBehaviorEvent(
|
|
376
405
|
event: BehaviorEvent,
|
|
377
406
|
): event is NativeBehaviorEvent {
|
|
378
|
-
return (
|
|
379
|
-
isClipboardBehaviorEvent(event) ||
|
|
380
|
-
isDragBehaviorEvent(event) ||
|
|
381
|
-
isInputBehaviorEvent(event) ||
|
|
382
|
-
isKeyboardBehaviorEvent(event) ||
|
|
383
|
-
isMouseBehaviorEvent(event)
|
|
384
|
-
)
|
|
407
|
+
return (nativeBehaviorEventTypes as readonly string[]).includes(event.type)
|
|
385
408
|
}
|
|
386
409
|
|
|
387
410
|
/**
|
|
@@ -396,85 +419,75 @@ export type NativeBehaviorEvent =
|
|
|
396
419
|
|
|
397
420
|
type ClipboardBehaviorEvent =
|
|
398
421
|
| {
|
|
399
|
-
type: NativeBehaviorEventType
|
|
422
|
+
type: StrictExtract<NativeBehaviorEventType, 'clipboard.copy'>
|
|
400
423
|
originEvent: {
|
|
401
424
|
dataTransfer: DataTransfer
|
|
402
425
|
}
|
|
403
426
|
position: Pick<EventPosition, 'selection'>
|
|
404
427
|
}
|
|
405
428
|
| {
|
|
406
|
-
type: NativeBehaviorEventType
|
|
429
|
+
type: StrictExtract<NativeBehaviorEventType, 'clipboard.cut'>
|
|
407
430
|
originEvent: {
|
|
408
431
|
dataTransfer: DataTransfer
|
|
409
432
|
}
|
|
410
433
|
position: Pick<EventPosition, 'selection'>
|
|
411
434
|
}
|
|
412
435
|
| {
|
|
413
|
-
type: NativeBehaviorEventType
|
|
436
|
+
type: StrictExtract<NativeBehaviorEventType, 'clipboard.paste'>
|
|
414
437
|
originEvent: {
|
|
415
438
|
dataTransfer: DataTransfer
|
|
416
439
|
}
|
|
417
440
|
position: Pick<EventPosition, 'selection'>
|
|
418
441
|
}
|
|
419
442
|
|
|
420
|
-
function isClipboardBehaviorEvent(
|
|
421
|
-
event: BehaviorEvent,
|
|
422
|
-
): event is ClipboardBehaviorEvent {
|
|
423
|
-
return event.type.startsWith('clipboard.')
|
|
424
|
-
}
|
|
425
|
-
|
|
426
443
|
type DragBehaviorEvent =
|
|
427
444
|
| {
|
|
428
|
-
type: NativeBehaviorEventType
|
|
445
|
+
type: StrictExtract<NativeBehaviorEventType, 'drag.dragstart'>
|
|
429
446
|
originEvent: {
|
|
430
447
|
dataTransfer: DataTransfer
|
|
431
448
|
}
|
|
432
449
|
position: Pick<EventPosition, 'selection'>
|
|
433
450
|
}
|
|
434
451
|
| {
|
|
435
|
-
type: NativeBehaviorEventType
|
|
452
|
+
type: StrictExtract<NativeBehaviorEventType, 'drag.drag'>
|
|
436
453
|
originEvent: {
|
|
437
454
|
dataTransfer: DataTransfer
|
|
438
455
|
}
|
|
439
456
|
}
|
|
440
457
|
| {
|
|
441
|
-
type: NativeBehaviorEventType
|
|
458
|
+
type: StrictExtract<NativeBehaviorEventType, 'drag.dragend'>
|
|
442
459
|
originEvent: {
|
|
443
460
|
dataTransfer: DataTransfer
|
|
444
461
|
}
|
|
445
462
|
}
|
|
446
463
|
| {
|
|
447
|
-
type: NativeBehaviorEventType
|
|
464
|
+
type: StrictExtract<NativeBehaviorEventType, 'drag.dragenter'>
|
|
448
465
|
originEvent: {
|
|
449
466
|
dataTransfer: DataTransfer
|
|
450
467
|
}
|
|
451
468
|
position: EventPosition
|
|
452
469
|
}
|
|
453
470
|
| {
|
|
454
|
-
type: NativeBehaviorEventType
|
|
471
|
+
type: StrictExtract<NativeBehaviorEventType, 'drag.dragover'>
|
|
455
472
|
originEvent: {
|
|
456
473
|
dataTransfer: DataTransfer
|
|
457
474
|
}
|
|
458
475
|
position: EventPosition
|
|
459
476
|
}
|
|
460
477
|
| {
|
|
461
|
-
type: NativeBehaviorEventType
|
|
478
|
+
type: StrictExtract<NativeBehaviorEventType, 'drag.drop'>
|
|
462
479
|
originEvent: {
|
|
463
480
|
dataTransfer: DataTransfer
|
|
464
481
|
}
|
|
465
482
|
position: EventPosition
|
|
466
483
|
}
|
|
467
484
|
| {
|
|
468
|
-
type: NativeBehaviorEventType
|
|
485
|
+
type: StrictExtract<NativeBehaviorEventType, 'drag.dragleave'>
|
|
469
486
|
originEvent: {
|
|
470
487
|
dataTransfer: DataTransfer
|
|
471
488
|
}
|
|
472
489
|
}
|
|
473
490
|
|
|
474
|
-
function isDragBehaviorEvent(event: BehaviorEvent): event is DragBehaviorEvent {
|
|
475
|
-
return event.type.startsWith('drag.')
|
|
476
|
-
}
|
|
477
|
-
|
|
478
491
|
/**
|
|
479
492
|
* Used to represent native InputEvents that hold a DataTransfer object.
|
|
480
493
|
*
|
|
@@ -487,28 +500,22 @@ function isDragBehaviorEvent(event: BehaviorEvent): event is DragBehaviorEvent {
|
|
|
487
500
|
* - insertFromYank
|
|
488
501
|
*/
|
|
489
502
|
export type InputBehaviorEvent = {
|
|
490
|
-
type: NativeBehaviorEventType
|
|
503
|
+
type: StrictExtract<NativeBehaviorEventType, 'input.*'>
|
|
491
504
|
originEvent: {
|
|
492
505
|
dataTransfer: DataTransfer
|
|
493
506
|
}
|
|
494
507
|
}
|
|
495
508
|
|
|
496
|
-
function isInputBehaviorEvent(
|
|
497
|
-
event: BehaviorEvent,
|
|
498
|
-
): event is InputBehaviorEvent {
|
|
499
|
-
return event.type.startsWith('input.')
|
|
500
|
-
}
|
|
501
|
-
|
|
502
509
|
export type KeyboardBehaviorEvent =
|
|
503
510
|
| {
|
|
504
|
-
type: NativeBehaviorEventType
|
|
511
|
+
type: StrictExtract<NativeBehaviorEventType, 'keyboard.keydown'>
|
|
505
512
|
originEvent: Pick<
|
|
506
513
|
KeyboardEvent,
|
|
507
514
|
'key' | 'code' | 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'
|
|
508
515
|
>
|
|
509
516
|
}
|
|
510
517
|
| {
|
|
511
|
-
type: NativeBehaviorEventType
|
|
518
|
+
type: StrictExtract<NativeBehaviorEventType, 'keyboard.keyup'>
|
|
512
519
|
originEvent: Pick<
|
|
513
520
|
KeyboardEvent,
|
|
514
521
|
'key' | 'code' | 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'
|
|
@@ -516,16 +523,10 @@ export type KeyboardBehaviorEvent =
|
|
|
516
523
|
}
|
|
517
524
|
|
|
518
525
|
export type MouseBehaviorEvent = {
|
|
519
|
-
type: NativeBehaviorEventType
|
|
526
|
+
type: StrictExtract<NativeBehaviorEventType, 'mouse.click'>
|
|
520
527
|
position: EventPosition
|
|
521
528
|
}
|
|
522
529
|
|
|
523
|
-
function isMouseBehaviorEvent(
|
|
524
|
-
event: BehaviorEvent,
|
|
525
|
-
): event is MouseBehaviorEvent {
|
|
526
|
-
return event.type.startsWith('mouse.')
|
|
527
|
-
}
|
|
528
|
-
|
|
529
530
|
/**************************************
|
|
530
531
|
* Custom events
|
|
531
532
|
**************************************/
|
|
@@ -582,3 +583,6 @@ export type ResolveBehaviorEvent<
|
|
|
582
583
|
: TBehaviorEventType extends BehaviorEvent['type']
|
|
583
584
|
? PickFromUnion<BehaviorEvent, 'type', TBehaviorEventType>
|
|
584
585
|
: never
|
|
586
|
+
|
|
587
|
+
type ExtractNamespace<TType extends string> =
|
|
588
|
+
TType extends `${infer Namespace}.${string}` ? Namespace : TType
|
|
@@ -144,12 +144,12 @@ export const Leaf = (props: LeafProps) => {
|
|
|
144
144
|
return undefined
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
const onBlur = editorActor.on('
|
|
147
|
+
const onBlur = editorActor.on('blurred', () => {
|
|
148
148
|
setFocused(false)
|
|
149
149
|
setSelected(false)
|
|
150
150
|
})
|
|
151
151
|
|
|
152
|
-
const onFocus = editorActor.on('
|
|
152
|
+
const onFocus = editorActor.on('focused', () => {
|
|
153
153
|
const sel = PortableTextEditor.getSelection(portableTextEditor)
|
|
154
154
|
if (
|
|
155
155
|
sel &&
|