@portabletext/editor 1.43.1 → 1.44.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/behavior.markdown.cjs +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +555 -794
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/parse-blocks.cjs +151 -0
- package/lib/_chunks-cjs/parse-blocks.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +2 -1
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
- package/lib/_chunks-cjs/{selector.is-active-style.cjs → selector.is-selecting-entire-blocks.cjs} +47 -11
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -0
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs +3 -3
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +0 -149
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +1 -1
- package/lib/_chunks-es/editor-provider.js +539 -777
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/parse-blocks.js +152 -0
- package/lib/_chunks-es/parse-blocks.js.map +1 -0
- package/lib/_chunks-es/selector.is-overlapping-selection.js +2 -1
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
- package/lib/_chunks-es/{selector.is-active-style.js → selector.is-selecting-entire-blocks.js} +49 -12
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -0
- package/lib/_chunks-es/util.merge-text-blocks.js +1 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js +0 -149
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
- package/lib/behaviors/index.d.cts +2819 -6421
- package/lib/behaviors/index.d.ts +2819 -6421
- package/lib/index.cjs +4 -4
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +2496 -6025
- package/lib/index.d.ts +2496 -6025
- package/lib/index.js +3 -3
- package/lib/plugins/index.cjs +1 -1
- package/lib/plugins/index.d.cts +2496 -6025
- package/lib/plugins/index.d.ts +2496 -6025
- package/lib/plugins/index.js +1 -1
- package/lib/selectors/index.cjs +12 -11
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +2464 -6018
- package/lib/selectors/index.d.ts +2464 -6018
- package/lib/selectors/index.js +2 -1
- package/lib/utils/index.d.cts +2458 -6022
- package/lib/utils/index.d.ts +2458 -6022
- package/package.json +2 -2
- package/src/behavior-actions/behavior.actions.ts +2 -152
- package/src/behaviors/behavior.default.ts +52 -120
- package/src/behaviors/behavior.internal.annotation.ts +26 -0
- package/src/behaviors/behavior.internal.decorator.ts +47 -0
- package/src/behaviors/behavior.internal.insert.ts +118 -0
- package/src/behaviors/behavior.internal.list-item.ts +61 -0
- package/src/behaviors/behavior.internal.select.ts +62 -0
- package/src/behaviors/behavior.internal.style.ts +54 -0
- package/src/behaviors/behavior.perform-event.ts +15 -13
- package/src/behaviors/behavior.types.event.ts +155 -108
- package/src/editor/create-editor.ts +2 -2
- package/src/editor/editor-machine.ts +3 -4
- package/src/editor/plugins/createWithEditableAPI.ts +1 -32
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +0 -29
- package/src/internal-utils/slate-utils.ts +52 -0
- package/src/plugins/plugin.internal.editor-actor-ref.tsx +15 -0
- package/src/plugins/plugin.internal.slate-editor-ref.tsx +15 -0
- package/src/selectors/index.ts +2 -1
- package/src/selectors/selector.get-selected-text-blocks.ts +67 -0
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +0 -1
- package/lib/_chunks-es/selector.is-active-style.js.map +0 -1
- package/src/behavior-actions/behavior.action.data-transfer-set.ts +0 -7
- package/src/behavior-actions/behavior.action.deserialization.failure.ts +0 -9
- package/src/behavior-actions/behavior.action.deserialization.success.ts +0 -16
- package/src/behavior-actions/behavior.action.insert-blocks.ts +0 -140
- package/src/behavior-actions/behavior.action.list-item.ts +0 -100
- package/src/behavior-actions/behavior.action.select.next-block.ts +0 -44
- package/src/behavior-actions/behavior.action.select.previous-block.ts +0 -48
- package/src/behavior-actions/behavior.action.serialization.failure.ts +0 -9
- package/src/behavior-actions/behavior.action.serialization.success.ts +0 -17
- package/src/behavior-actions/behavior.action.style.ts +0 -108
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {getSelectedTextBlocks, isActiveListItem} from '../selectors'
|
|
2
|
+
import {raise} from './behavior.types.action'
|
|
3
|
+
import {defineBehavior} from './behavior.types.behavior'
|
|
4
|
+
|
|
5
|
+
export const internalListItemBehaviors = [
|
|
6
|
+
defineBehavior({
|
|
7
|
+
on: 'list item.add',
|
|
8
|
+
guard: ({snapshot}) => {
|
|
9
|
+
const selectedTextBlocks = getSelectedTextBlocks(snapshot)
|
|
10
|
+
|
|
11
|
+
return {selectedTextBlocks}
|
|
12
|
+
},
|
|
13
|
+
actions: [
|
|
14
|
+
({event}, {selectedTextBlocks}) =>
|
|
15
|
+
selectedTextBlocks.map((block) =>
|
|
16
|
+
raise({
|
|
17
|
+
type: 'block.set',
|
|
18
|
+
at: block.path,
|
|
19
|
+
props: {
|
|
20
|
+
level: 1,
|
|
21
|
+
listItem: event.listItem,
|
|
22
|
+
},
|
|
23
|
+
}),
|
|
24
|
+
),
|
|
25
|
+
],
|
|
26
|
+
}),
|
|
27
|
+
defineBehavior({
|
|
28
|
+
on: 'list item.remove',
|
|
29
|
+
guard: ({snapshot}) => {
|
|
30
|
+
const selectedTextBlocks = getSelectedTextBlocks(snapshot)
|
|
31
|
+
|
|
32
|
+
return {selectedTextBlocks}
|
|
33
|
+
},
|
|
34
|
+
actions: [
|
|
35
|
+
(_, {selectedTextBlocks}) =>
|
|
36
|
+
selectedTextBlocks.map((block) =>
|
|
37
|
+
raise({
|
|
38
|
+
type: 'block.unset',
|
|
39
|
+
at: block.path,
|
|
40
|
+
props: ['level', 'listItem'],
|
|
41
|
+
}),
|
|
42
|
+
),
|
|
43
|
+
],
|
|
44
|
+
}),
|
|
45
|
+
defineBehavior({
|
|
46
|
+
on: 'list item.toggle',
|
|
47
|
+
guard: ({snapshot, event}) => isActiveListItem(event.listItem)(snapshot),
|
|
48
|
+
actions: [
|
|
49
|
+
({event}) => [
|
|
50
|
+
raise({type: 'list item.remove', listItem: event.listItem}),
|
|
51
|
+
],
|
|
52
|
+
],
|
|
53
|
+
}),
|
|
54
|
+
defineBehavior({
|
|
55
|
+
on: 'list item.toggle',
|
|
56
|
+
guard: ({snapshot, event}) => !isActiveListItem(event.listItem)(snapshot),
|
|
57
|
+
actions: [
|
|
58
|
+
({event}) => [raise({type: 'list item.add', listItem: event.listItem})],
|
|
59
|
+
],
|
|
60
|
+
}),
|
|
61
|
+
]
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {getNextBlock, getPreviousBlock} from '../selectors'
|
|
2
|
+
import {getBlockEndPoint, getBlockStartPoint} from '../utils'
|
|
3
|
+
import {raise} from './behavior.types.action'
|
|
4
|
+
import {defineBehavior} from './behavior.types.behavior'
|
|
5
|
+
|
|
6
|
+
export const internalSelectBehaviors = [
|
|
7
|
+
defineBehavior({
|
|
8
|
+
on: 'select.previous block',
|
|
9
|
+
guard: ({snapshot, event}) => {
|
|
10
|
+
const previousBlock = getPreviousBlock(snapshot)
|
|
11
|
+
|
|
12
|
+
if (!previousBlock) {
|
|
13
|
+
return false
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const point =
|
|
17
|
+
event.select === 'end'
|
|
18
|
+
? getBlockEndPoint(previousBlock)
|
|
19
|
+
: getBlockStartPoint(previousBlock)
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
selection: {
|
|
23
|
+
anchor: point,
|
|
24
|
+
focus: point,
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
actions: [
|
|
29
|
+
(_, {selection}) => [
|
|
30
|
+
raise({
|
|
31
|
+
type: 'select',
|
|
32
|
+
selection,
|
|
33
|
+
}),
|
|
34
|
+
],
|
|
35
|
+
],
|
|
36
|
+
}),
|
|
37
|
+
defineBehavior({
|
|
38
|
+
on: 'select.next block',
|
|
39
|
+
guard: ({snapshot, event}) => {
|
|
40
|
+
const nextBlock = getNextBlock(snapshot)
|
|
41
|
+
|
|
42
|
+
if (!nextBlock) {
|
|
43
|
+
return false
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const point =
|
|
47
|
+
event.select === 'end'
|
|
48
|
+
? getBlockEndPoint(nextBlock)
|
|
49
|
+
: getBlockStartPoint(nextBlock)
|
|
50
|
+
|
|
51
|
+
return {selection: {anchor: point, focus: point}}
|
|
52
|
+
},
|
|
53
|
+
actions: [
|
|
54
|
+
(_, {selection}) => [
|
|
55
|
+
raise({
|
|
56
|
+
type: 'select',
|
|
57
|
+
selection,
|
|
58
|
+
}),
|
|
59
|
+
],
|
|
60
|
+
],
|
|
61
|
+
}),
|
|
62
|
+
]
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {getSelectedTextBlocks, isActiveStyle} from '../selectors'
|
|
2
|
+
import {raise} from './behavior.types.action'
|
|
3
|
+
import {defineBehavior} from './behavior.types.behavior'
|
|
4
|
+
|
|
5
|
+
export const internalStyleBehaviors = [
|
|
6
|
+
defineBehavior({
|
|
7
|
+
on: 'style.add',
|
|
8
|
+
guard: ({snapshot}) => {
|
|
9
|
+
const selectedTextBlocks = getSelectedTextBlocks(snapshot)
|
|
10
|
+
|
|
11
|
+
return {selectedTextBlocks}
|
|
12
|
+
},
|
|
13
|
+
actions: [
|
|
14
|
+
({event}, {selectedTextBlocks}) =>
|
|
15
|
+
selectedTextBlocks.map((block) =>
|
|
16
|
+
raise({
|
|
17
|
+
type: 'block.set',
|
|
18
|
+
at: block.path,
|
|
19
|
+
props: {
|
|
20
|
+
style: event.style,
|
|
21
|
+
},
|
|
22
|
+
}),
|
|
23
|
+
),
|
|
24
|
+
],
|
|
25
|
+
}),
|
|
26
|
+
defineBehavior({
|
|
27
|
+
on: 'style.remove',
|
|
28
|
+
guard: ({snapshot}) => {
|
|
29
|
+
const selectedTextBlocks = getSelectedTextBlocks(snapshot)
|
|
30
|
+
|
|
31
|
+
return {selectedTextBlocks}
|
|
32
|
+
},
|
|
33
|
+
actions: [
|
|
34
|
+
(_, {selectedTextBlocks}) =>
|
|
35
|
+
selectedTextBlocks.map((block) =>
|
|
36
|
+
raise({
|
|
37
|
+
type: 'block.unset',
|
|
38
|
+
at: block.path,
|
|
39
|
+
props: ['style'],
|
|
40
|
+
}),
|
|
41
|
+
),
|
|
42
|
+
],
|
|
43
|
+
}),
|
|
44
|
+
defineBehavior({
|
|
45
|
+
on: 'style.toggle',
|
|
46
|
+
guard: ({snapshot, event}) => isActiveStyle(event.style)(snapshot),
|
|
47
|
+
actions: [({event}) => [raise({type: 'style.remove', style: event.style})]],
|
|
48
|
+
}),
|
|
49
|
+
defineBehavior({
|
|
50
|
+
on: 'style.toggle',
|
|
51
|
+
guard: ({snapshot, event}) => !isActiveStyle(event.style)(snapshot),
|
|
52
|
+
actions: [({event}) => [raise({type: 'style.add', style: event.style})]],
|
|
53
|
+
}),
|
|
54
|
+
]
|
|
@@ -10,16 +10,23 @@ import {debugWithName} from '../internal-utils/debug'
|
|
|
10
10
|
import type {PortableTextSlateEditor} from '../types/editor'
|
|
11
11
|
import type {InternalBehaviorAction} from './behavior.types.action'
|
|
12
12
|
import {
|
|
13
|
-
isClipboardBehaviorEvent,
|
|
14
13
|
isCustomBehaviorEvent,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
isKeyboardBehaviorEvent,
|
|
18
|
-
isMouseBehaviorEvent,
|
|
14
|
+
isInternalBehaviorEvent,
|
|
15
|
+
isNativeBehaviorEvent,
|
|
19
16
|
} from './behavior.types.event'
|
|
20
17
|
|
|
21
18
|
const debug = debugWithName('behaviors:event')
|
|
22
19
|
|
|
20
|
+
function eventCategory(event: BehaviorEvent) {
|
|
21
|
+
return isNativeBehaviorEvent(event)
|
|
22
|
+
? 'native'
|
|
23
|
+
: isInternalBehaviorEvent(event)
|
|
24
|
+
? 'internal'
|
|
25
|
+
: isCustomBehaviorEvent(event)
|
|
26
|
+
? 'custom'
|
|
27
|
+
: 'synthetic'
|
|
28
|
+
}
|
|
29
|
+
|
|
23
30
|
export function performEvent({
|
|
24
31
|
behaviors,
|
|
25
32
|
event,
|
|
@@ -43,17 +50,12 @@ export function performEvent({
|
|
|
43
50
|
}
|
|
44
51
|
| undefined
|
|
45
52
|
}) {
|
|
46
|
-
debug(JSON.stringify(event, null, 2))
|
|
53
|
+
debug(`(${eventCategory(event)})`, JSON.stringify(event, null, 2))
|
|
47
54
|
|
|
48
55
|
const defaultAction =
|
|
49
56
|
isCustomBehaviorEvent(event) ||
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
isInputBehaviorEvent(event) ||
|
|
53
|
-
isKeyboardBehaviorEvent(event) ||
|
|
54
|
-
isMouseBehaviorEvent(event) ||
|
|
55
|
-
event.type === 'deserialize' ||
|
|
56
|
-
event.type === 'serialize'
|
|
57
|
+
isNativeBehaviorEvent(event) ||
|
|
58
|
+
isInternalBehaviorEvent(event)
|
|
57
59
|
? undefined
|
|
58
60
|
: ({
|
|
59
61
|
...event,
|
|
@@ -28,17 +28,39 @@ type NamespacedBehaviorEventType<
|
|
|
28
28
|
? BehaviorEvent['type']
|
|
29
29
|
: Extract<BehaviorEvent['type'], TNamespace | `${TNamespace}.${string}`>
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
*
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
31
|
+
/**************************************
|
|
32
|
+
* External events
|
|
33
|
+
**************************************/
|
|
34
|
+
|
|
35
|
+
type ExternalBehaviorEventNamespace = 'insert'
|
|
36
|
+
|
|
37
|
+
type ExternalBehaviorEventType<
|
|
38
|
+
TNamespace extends ExternalBehaviorEventNamespace,
|
|
39
|
+
TType extends string = '',
|
|
40
|
+
> = TType extends '' ? `${TNamespace}` : `${TNamespace}.${TType}`
|
|
41
|
+
|
|
42
|
+
export type ExternalBehaviorEvent =
|
|
43
|
+
| {
|
|
44
|
+
type: ExternalBehaviorEventType<'insert', 'block object'>
|
|
45
|
+
placement: InsertPlacement
|
|
46
|
+
blockObject: {
|
|
47
|
+
name: string
|
|
48
|
+
value?: {[prop: string]: unknown}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
| PickFromUnion<
|
|
52
|
+
InternalBehaviorEvent,
|
|
53
|
+
'type',
|
|
54
|
+
| 'annotation.toggle'
|
|
55
|
+
| 'decorator.toggle'
|
|
56
|
+
| 'insert.blocks'
|
|
57
|
+
| 'list item.add'
|
|
58
|
+
| 'list item.remove'
|
|
59
|
+
| 'list item.toggle'
|
|
60
|
+
| 'style.add'
|
|
61
|
+
| 'style.remove'
|
|
62
|
+
| 'style.toggle'
|
|
63
|
+
>
|
|
42
64
|
|
|
43
65
|
/**************************************
|
|
44
66
|
* Synthetic events
|
|
@@ -53,18 +75,13 @@ type SyntheticBehaviorEventNamespace =
|
|
|
53
75
|
| 'annotation'
|
|
54
76
|
| 'block'
|
|
55
77
|
| 'blur'
|
|
56
|
-
| 'data transfer'
|
|
57
78
|
| 'decorator'
|
|
58
79
|
| 'delete'
|
|
59
|
-
| 'deserialization'
|
|
60
80
|
| 'focus'
|
|
61
81
|
| 'history'
|
|
62
82
|
| 'insert'
|
|
63
|
-
| 'list item'
|
|
64
83
|
| 'move'
|
|
65
84
|
| 'select'
|
|
66
|
-
| 'serialization'
|
|
67
|
-
| 'style'
|
|
68
85
|
|
|
69
86
|
/**
|
|
70
87
|
* @beta
|
|
@@ -83,13 +100,6 @@ export type SyntheticBehaviorEvent =
|
|
|
83
100
|
name: string
|
|
84
101
|
}
|
|
85
102
|
}
|
|
86
|
-
| {
|
|
87
|
-
type: SyntheticBehaviorEventType<'annotation', 'toggle'>
|
|
88
|
-
annotation: {
|
|
89
|
-
name: string
|
|
90
|
-
value: {[prop: string]: unknown}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
103
|
| {
|
|
94
104
|
type: SyntheticBehaviorEventType<'block', 'set'>
|
|
95
105
|
at: [KeyedSegment]
|
|
@@ -103,12 +113,6 @@ export type SyntheticBehaviorEvent =
|
|
|
103
113
|
| {
|
|
104
114
|
type: SyntheticBehaviorEventType<'blur'>
|
|
105
115
|
}
|
|
106
|
-
| {
|
|
107
|
-
type: SyntheticBehaviorEventType<'data transfer', 'set'>
|
|
108
|
-
data: string
|
|
109
|
-
dataTransfer: DataTransfer
|
|
110
|
-
mimeType: MIMEType
|
|
111
|
-
}
|
|
112
116
|
| {
|
|
113
117
|
type: SyntheticBehaviorEventType<'decorator', 'add'>
|
|
114
118
|
decorator: string
|
|
@@ -118,11 +122,6 @@ export type SyntheticBehaviorEvent =
|
|
|
118
122
|
type: SyntheticBehaviorEventType<'decorator', 'remove'>
|
|
119
123
|
decorator: string
|
|
120
124
|
}
|
|
121
|
-
| {
|
|
122
|
-
type: SyntheticBehaviorEventType<'decorator', 'toggle'>
|
|
123
|
-
decorator: string
|
|
124
|
-
offsets?: {anchor: BlockOffset; focus: BlockOffset}
|
|
125
|
-
}
|
|
126
125
|
| {
|
|
127
126
|
type: SyntheticBehaviorEventType<'delete'>
|
|
128
127
|
selection: NonNullable<EditorSelection>
|
|
@@ -153,11 +152,6 @@ export type SyntheticBehaviorEvent =
|
|
|
153
152
|
| {
|
|
154
153
|
type: SyntheticBehaviorEventType<'history', 'undo'>
|
|
155
154
|
}
|
|
156
|
-
| {
|
|
157
|
-
type: SyntheticBehaviorEventType<'insert', 'blocks'>
|
|
158
|
-
blocks: Array<PortableTextBlock>
|
|
159
|
-
placement: InsertPlacement
|
|
160
|
-
}
|
|
161
155
|
| {
|
|
162
156
|
type: SyntheticBehaviorEventType<'insert', 'inline object'>
|
|
163
157
|
inlineObject: {
|
|
@@ -190,18 +184,6 @@ export type SyntheticBehaviorEvent =
|
|
|
190
184
|
type: SyntheticBehaviorEventType<'insert', 'text'>
|
|
191
185
|
text: string
|
|
192
186
|
}
|
|
193
|
-
| {
|
|
194
|
-
type: SyntheticBehaviorEventType<'list item', 'add'>
|
|
195
|
-
listItem: string
|
|
196
|
-
}
|
|
197
|
-
| {
|
|
198
|
-
type: SyntheticBehaviorEventType<'list item', 'remove'>
|
|
199
|
-
listItem: string
|
|
200
|
-
}
|
|
201
|
-
| {
|
|
202
|
-
type: SyntheticBehaviorEventType<'list item', 'toggle'>
|
|
203
|
-
listItem: string
|
|
204
|
-
}
|
|
205
187
|
| {
|
|
206
188
|
type: SyntheticBehaviorEventType<'move', 'block'>
|
|
207
189
|
at: [KeyedSegment]
|
|
@@ -219,28 +201,69 @@ export type SyntheticBehaviorEvent =
|
|
|
219
201
|
type: SyntheticBehaviorEventType<'select'>
|
|
220
202
|
selection: EditorSelection
|
|
221
203
|
}
|
|
204
|
+
|
|
205
|
+
export type InsertPlacement = 'auto' | 'after' | 'before'
|
|
206
|
+
|
|
207
|
+
export function isKeyboardBehaviorEvent(
|
|
208
|
+
event: BehaviorEvent,
|
|
209
|
+
): event is KeyboardBehaviorEvent {
|
|
210
|
+
return event.type.startsWith('keyboard.')
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**************************************
|
|
214
|
+
* Internal events
|
|
215
|
+
**************************************/
|
|
216
|
+
|
|
217
|
+
type InternalBehaviorEventNamespace =
|
|
218
|
+
| 'annotation'
|
|
219
|
+
| 'decorator'
|
|
220
|
+
| 'deserialize'
|
|
221
|
+
| 'deserialization'
|
|
222
|
+
| 'list item'
|
|
223
|
+
| 'insert'
|
|
224
|
+
| 'select'
|
|
225
|
+
| 'serialize'
|
|
226
|
+
| 'serialization'
|
|
227
|
+
| 'style'
|
|
228
|
+
|
|
229
|
+
type InternalBehaviorEventType<
|
|
230
|
+
TNamespace extends InternalBehaviorEventNamespace,
|
|
231
|
+
TType extends string = '',
|
|
232
|
+
> = TType extends '' ? `${TNamespace}` : `${TNamespace}.${TType}`
|
|
233
|
+
|
|
234
|
+
export type InternalBehaviorEvent =
|
|
222
235
|
| {
|
|
223
|
-
type:
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
select?: 'start' | 'end'
|
|
236
|
+
type: InternalBehaviorEventType<'annotation', 'toggle'>
|
|
237
|
+
annotation: {
|
|
238
|
+
name: string
|
|
239
|
+
value: {[prop: string]: unknown}
|
|
240
|
+
}
|
|
229
241
|
}
|
|
230
242
|
| {
|
|
231
|
-
type:
|
|
232
|
-
|
|
243
|
+
type: InternalBehaviorEventType<'decorator', 'toggle'>
|
|
244
|
+
decorator: string
|
|
245
|
+
offsets?: {anchor: BlockOffset; focus: BlockOffset}
|
|
233
246
|
}
|
|
234
247
|
| {
|
|
235
|
-
type:
|
|
236
|
-
|
|
248
|
+
type: InternalBehaviorEventType<'deserialize'>
|
|
249
|
+
originEvent:
|
|
250
|
+
| PickFromUnion<
|
|
251
|
+
NativeBehaviorEvent,
|
|
252
|
+
'type',
|
|
253
|
+
'drag.drop' | 'clipboard.paste'
|
|
254
|
+
>
|
|
255
|
+
| InputBehaviorEvent
|
|
237
256
|
}
|
|
238
257
|
| {
|
|
239
|
-
type:
|
|
240
|
-
|
|
258
|
+
type: InternalBehaviorEventType<'serialize'>
|
|
259
|
+
originEvent: PickFromUnion<
|
|
260
|
+
NativeBehaviorEvent,
|
|
261
|
+
'type',
|
|
262
|
+
'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart'
|
|
263
|
+
>
|
|
241
264
|
}
|
|
242
265
|
| {
|
|
243
|
-
type:
|
|
266
|
+
type: InternalBehaviorEventType<'deserialization', 'success'>
|
|
244
267
|
mimeType: MIMEType
|
|
245
268
|
data: Array<PortableTextBlock>
|
|
246
269
|
originEvent:
|
|
@@ -252,7 +275,7 @@ export type SyntheticBehaviorEvent =
|
|
|
252
275
|
| InputBehaviorEvent
|
|
253
276
|
}
|
|
254
277
|
| {
|
|
255
|
-
type:
|
|
278
|
+
type: InternalBehaviorEventType<'deserialization', 'failure'>
|
|
256
279
|
mimeType: MIMEType
|
|
257
280
|
reason: string
|
|
258
281
|
originEvent:
|
|
@@ -264,7 +287,7 @@ export type SyntheticBehaviorEvent =
|
|
|
264
287
|
| InputBehaviorEvent
|
|
265
288
|
}
|
|
266
289
|
| {
|
|
267
|
-
type:
|
|
290
|
+
type: InternalBehaviorEventType<'serialization', 'success'>
|
|
268
291
|
mimeType: MIMEType
|
|
269
292
|
data: string
|
|
270
293
|
originEvent: PickFromUnion<
|
|
@@ -274,7 +297,7 @@ export type SyntheticBehaviorEvent =
|
|
|
274
297
|
>
|
|
275
298
|
}
|
|
276
299
|
| {
|
|
277
|
-
type:
|
|
300
|
+
type: InternalBehaviorEventType<'serialization', 'failure'>
|
|
278
301
|
mimeType: MIMEType
|
|
279
302
|
reason: string
|
|
280
303
|
originEvent: PickFromUnion<
|
|
@@ -283,45 +306,59 @@ export type SyntheticBehaviorEvent =
|
|
|
283
306
|
'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart'
|
|
284
307
|
>
|
|
285
308
|
}
|
|
286
|
-
|
|
287
|
-
export type InsertPlacement = 'auto' | 'after' | 'before'
|
|
288
|
-
|
|
289
|
-
export function isKeyboardBehaviorEvent(
|
|
290
|
-
event: BehaviorEvent,
|
|
291
|
-
): event is KeyboardBehaviorEvent {
|
|
292
|
-
return event.type.startsWith('keyboard.')
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**************************************
|
|
296
|
-
* Internal events
|
|
297
|
-
**************************************/
|
|
298
|
-
|
|
299
|
-
type InternalBehaviorEventNamespace = 'deserialize' | 'serialize'
|
|
300
|
-
|
|
301
|
-
type InternalBehaviorEventType<
|
|
302
|
-
TNamespace extends InternalBehaviorEventNamespace,
|
|
303
|
-
TType extends string = '',
|
|
304
|
-
> = TType extends '' ? `${TNamespace}` : `${TNamespace}.${TType}`
|
|
305
|
-
|
|
306
|
-
export type InternalBehaviorEvent =
|
|
307
309
|
| {
|
|
308
|
-
type: InternalBehaviorEventType<'
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
NativeBehaviorEvent,
|
|
312
|
-
'type',
|
|
313
|
-
'drag.drop' | 'clipboard.paste'
|
|
314
|
-
>
|
|
315
|
-
| InputBehaviorEvent
|
|
310
|
+
type: InternalBehaviorEventType<'insert', 'blocks'>
|
|
311
|
+
blocks: Array<PortableTextBlock>
|
|
312
|
+
placement: InsertPlacement
|
|
316
313
|
}
|
|
317
314
|
| {
|
|
318
|
-
type: InternalBehaviorEventType<'
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
315
|
+
type: InternalBehaviorEventType<'list item', 'add'>
|
|
316
|
+
listItem: string
|
|
317
|
+
}
|
|
318
|
+
| {
|
|
319
|
+
type: InternalBehaviorEventType<'list item', 'remove'>
|
|
320
|
+
listItem: string
|
|
321
|
+
}
|
|
322
|
+
| {
|
|
323
|
+
type: InternalBehaviorEventType<'list item', 'toggle'>
|
|
324
|
+
listItem: string
|
|
325
|
+
}
|
|
326
|
+
| {
|
|
327
|
+
type: InternalBehaviorEventType<'select', 'previous block'>
|
|
328
|
+
select?: 'start' | 'end'
|
|
329
|
+
}
|
|
330
|
+
| {
|
|
331
|
+
type: InternalBehaviorEventType<'select', 'next block'>
|
|
332
|
+
select?: 'start' | 'end'
|
|
333
|
+
}
|
|
334
|
+
| {
|
|
335
|
+
type: InternalBehaviorEventType<'style', 'add'>
|
|
336
|
+
style: string
|
|
337
|
+
}
|
|
338
|
+
| {
|
|
339
|
+
type: InternalBehaviorEventType<'style', 'remove'>
|
|
340
|
+
style: string
|
|
324
341
|
}
|
|
342
|
+
| {
|
|
343
|
+
type: InternalBehaviorEventType<'style', 'toggle'>
|
|
344
|
+
style: string
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export function isInternalBehaviorEvent(
|
|
348
|
+
event: BehaviorEvent,
|
|
349
|
+
): event is InternalBehaviorEvent {
|
|
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
|
+
)
|
|
361
|
+
}
|
|
325
362
|
|
|
326
363
|
/**************************************
|
|
327
364
|
* Native events
|
|
@@ -339,6 +376,18 @@ type NativeBehaviorEventType<
|
|
|
339
376
|
TType extends string = '',
|
|
340
377
|
> = TType extends '' ? `${TNamespace}` : `${TNamespace}.${TType}`
|
|
341
378
|
|
|
379
|
+
export function isNativeBehaviorEvent(
|
|
380
|
+
event: BehaviorEvent,
|
|
381
|
+
): event is NativeBehaviorEvent {
|
|
382
|
+
return (
|
|
383
|
+
isClipboardBehaviorEvent(event) ||
|
|
384
|
+
isDragBehaviorEvent(event) ||
|
|
385
|
+
isInputBehaviorEvent(event) ||
|
|
386
|
+
isKeyboardBehaviorEvent(event) ||
|
|
387
|
+
isMouseBehaviorEvent(event)
|
|
388
|
+
)
|
|
389
|
+
}
|
|
390
|
+
|
|
342
391
|
/**
|
|
343
392
|
* @beta
|
|
344
393
|
*/
|
|
@@ -372,7 +421,7 @@ type ClipboardBehaviorEvent =
|
|
|
372
421
|
position: Pick<EventPosition, 'selection'>
|
|
373
422
|
}
|
|
374
423
|
|
|
375
|
-
|
|
424
|
+
function isClipboardBehaviorEvent(
|
|
376
425
|
event: BehaviorEvent,
|
|
377
426
|
): event is ClipboardBehaviorEvent {
|
|
378
427
|
return event.type.startsWith('clipboard.')
|
|
@@ -426,9 +475,7 @@ type DragBehaviorEvent =
|
|
|
426
475
|
}
|
|
427
476
|
}
|
|
428
477
|
|
|
429
|
-
|
|
430
|
-
event: BehaviorEvent,
|
|
431
|
-
): event is DragBehaviorEvent {
|
|
478
|
+
function isDragBehaviorEvent(event: BehaviorEvent): event is DragBehaviorEvent {
|
|
432
479
|
return event.type.startsWith('drag.')
|
|
433
480
|
}
|
|
434
481
|
|
|
@@ -450,7 +497,7 @@ export type InputBehaviorEvent = {
|
|
|
450
497
|
}
|
|
451
498
|
}
|
|
452
499
|
|
|
453
|
-
|
|
500
|
+
function isInputBehaviorEvent(
|
|
454
501
|
event: BehaviorEvent,
|
|
455
502
|
): event is InputBehaviorEvent {
|
|
456
503
|
return event.type.startsWith('input.')
|
|
@@ -477,7 +524,7 @@ export type MouseBehaviorEvent = {
|
|
|
477
524
|
position: EventPosition
|
|
478
525
|
}
|
|
479
526
|
|
|
480
|
-
|
|
527
|
+
function isMouseBehaviorEvent(
|
|
481
528
|
event: BehaviorEvent,
|
|
482
529
|
): event is MouseBehaviorEvent {
|
|
483
530
|
return event.type.startsWith('mouse.')
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
import type {Behavior} from '../behaviors/behavior.types.behavior'
|
|
15
15
|
import type {
|
|
16
16
|
CustomBehaviorEvent,
|
|
17
|
-
|
|
17
|
+
ExternalBehaviorEvent,
|
|
18
18
|
SyntheticBehaviorEvent,
|
|
19
19
|
} from '../behaviors/behavior.types.event'
|
|
20
20
|
import {coreConverters} from '../converters/converters.core'
|
|
@@ -65,7 +65,7 @@ export type EditorConfig = {
|
|
|
65
65
|
*/
|
|
66
66
|
export type EditorEvent =
|
|
67
67
|
| ExternalEditorEvent
|
|
68
|
-
|
|
|
68
|
+
| ExternalBehaviorEvent
|
|
69
69
|
| SyntheticBehaviorEvent
|
|
70
70
|
| CustomBehaviorEvent
|
|
71
71
|
|
|
@@ -15,7 +15,7 @@ import {performEvent} from '../behaviors/behavior.perform-event'
|
|
|
15
15
|
import type {Behavior} from '../behaviors/behavior.types.behavior'
|
|
16
16
|
import type {
|
|
17
17
|
CustomBehaviorEvent,
|
|
18
|
-
|
|
18
|
+
ExternalBehaviorEvent,
|
|
19
19
|
InternalBehaviorEvent,
|
|
20
20
|
NativeBehaviorEvent,
|
|
21
21
|
SyntheticBehaviorEvent,
|
|
@@ -193,7 +193,7 @@ export type InternalEditorEvent =
|
|
|
193
193
|
nativeEvent?: {preventDefault: () => void}
|
|
194
194
|
}
|
|
195
195
|
| CustomBehaviorEvent
|
|
196
|
-
|
|
|
196
|
+
| ExternalBehaviorEvent
|
|
197
197
|
| ExternalEditorEvent
|
|
198
198
|
| MutationEvent
|
|
199
199
|
| InternalPatchEvent
|
|
@@ -213,7 +213,7 @@ export type InternalEditorEvent =
|
|
|
213
213
|
*/
|
|
214
214
|
export type InternalEditorEmittedEvent =
|
|
215
215
|
| EditorEmittedEvent
|
|
216
|
-
|
|
|
216
|
+
| ExternalBehaviorEvent
|
|
217
217
|
| InternalPatchEvent
|
|
218
218
|
| PatchesEvent
|
|
219
219
|
| UnsetEvent
|
|
@@ -406,7 +406,6 @@ export const editorMachine = setup({
|
|
|
406
406
|
actions: 'handle behavior event',
|
|
407
407
|
guard: ({event}) =>
|
|
408
408
|
event.behaviorEvent.type === 'clipboard.copy' ||
|
|
409
|
-
event.behaviorEvent.type === 'data transfer.set' ||
|
|
410
409
|
event.behaviorEvent.type === 'serialize' ||
|
|
411
410
|
event.behaviorEvent.type === 'serialization.failure' ||
|
|
412
411
|
event.behaviorEvent.type === 'serialization.success' ||
|