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