@portabletext/editor 1.36.2 → 1.36.4
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.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +36 -36
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +36 -36
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/behaviors/index.d.cts +5 -5
- package/lib/behaviors/index.d.ts +5 -5
- package/lib/index.d.cts +4 -4
- package/lib/index.d.ts +4 -4
- package/lib/plugins/index.d.cts +4 -4
- package/lib/plugins/index.d.ts +4 -4
- package/lib/selectors/index.d.cts +4 -4
- package/lib/selectors/index.d.ts +4 -4
- package/lib/utils/index.d.cts +4 -4
- package/lib/utils/index.d.ts +4 -4
- package/package.json +1 -1
- package/src/behavior-actions/behavior.actions.ts +10 -6
- package/src/behaviors/{behavior.foundational.ts → behavior.default.raise-soft-break.ts} +1 -3
- package/src/behaviors/behavior.default.ts +2 -0
- package/src/behaviors/behavior.types.ts +7 -10
- package/src/behaviors/index.ts +2 -2
- package/src/editor/editor-machine.ts +18 -22
- package/src/editor/plugins/createWithUndoRedo.ts +10 -13
- package/src/editor/with-applying-behavior-actions.ts +6 -9
|
@@ -77,13 +77,13 @@ export declare type Behavior<
|
|
|
77
77
|
/**
|
|
78
78
|
* Array of behavior action sets.
|
|
79
79
|
*/
|
|
80
|
-
actions: Array<
|
|
80
|
+
actions: Array<BehaviorActionSet<TBehaviorEvent, TGuardResponse>>
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
84
|
* @beta
|
|
85
85
|
*/
|
|
86
|
-
export declare type
|
|
86
|
+
export declare type BehaviorAction =
|
|
87
87
|
| SyntheticBehaviorEvent
|
|
88
88
|
| {
|
|
89
89
|
type: 'raise'
|
|
@@ -100,7 +100,7 @@ export declare type BehaviorActionIntend =
|
|
|
100
100
|
/**
|
|
101
101
|
* @beta
|
|
102
102
|
*/
|
|
103
|
-
export declare type
|
|
103
|
+
export declare type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (
|
|
104
104
|
payload: {
|
|
105
105
|
/**
|
|
106
106
|
* @deprecated
|
|
@@ -111,7 +111,7 @@ export declare type BehaviorActionIntendSet<TBehaviorEvent, TGuardResponse> = (
|
|
|
111
111
|
event: TBehaviorEvent
|
|
112
112
|
},
|
|
113
113
|
guardResponse: TGuardResponse,
|
|
114
|
-
) => Array<
|
|
114
|
+
) => Array<BehaviorAction>
|
|
115
115
|
|
|
116
116
|
/**
|
|
117
117
|
* @beta
|
|
@@ -19925,7 +19925,7 @@ declare interface PortableTextSlateEditor extends ReactEditor {
|
|
|
19925
19925
|
*/
|
|
19926
19926
|
export declare function raise(
|
|
19927
19927
|
event: SyntheticBehaviorEvent | CustomBehaviorEvent,
|
|
19928
|
-
): PickFromUnion<
|
|
19928
|
+
): PickFromUnion<BehaviorAction, 'type', 'raise'>
|
|
19929
19929
|
|
|
19930
19930
|
declare type Serializer<TMIMEType extends MIMEType> = ({
|
|
19931
19931
|
snapshot,
|
package/lib/behaviors/index.d.ts
CHANGED
|
@@ -77,13 +77,13 @@ export declare type Behavior<
|
|
|
77
77
|
/**
|
|
78
78
|
* Array of behavior action sets.
|
|
79
79
|
*/
|
|
80
|
-
actions: Array<
|
|
80
|
+
actions: Array<BehaviorActionSet<TBehaviorEvent, TGuardResponse>>
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
84
|
* @beta
|
|
85
85
|
*/
|
|
86
|
-
export declare type
|
|
86
|
+
export declare type BehaviorAction =
|
|
87
87
|
| SyntheticBehaviorEvent
|
|
88
88
|
| {
|
|
89
89
|
type: 'raise'
|
|
@@ -100,7 +100,7 @@ export declare type BehaviorActionIntend =
|
|
|
100
100
|
/**
|
|
101
101
|
* @beta
|
|
102
102
|
*/
|
|
103
|
-
export declare type
|
|
103
|
+
export declare type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (
|
|
104
104
|
payload: {
|
|
105
105
|
/**
|
|
106
106
|
* @deprecated
|
|
@@ -111,7 +111,7 @@ export declare type BehaviorActionIntendSet<TBehaviorEvent, TGuardResponse> = (
|
|
|
111
111
|
event: TBehaviorEvent
|
|
112
112
|
},
|
|
113
113
|
guardResponse: TGuardResponse,
|
|
114
|
-
) => Array<
|
|
114
|
+
) => Array<BehaviorAction>
|
|
115
115
|
|
|
116
116
|
/**
|
|
117
117
|
* @beta
|
|
@@ -19925,7 +19925,7 @@ declare interface PortableTextSlateEditor extends ReactEditor {
|
|
|
19925
19925
|
*/
|
|
19926
19926
|
export declare function raise(
|
|
19927
19927
|
event: SyntheticBehaviorEvent | CustomBehaviorEvent,
|
|
19928
|
-
): PickFromUnion<
|
|
19928
|
+
): PickFromUnion<BehaviorAction, 'type', 'raise'>
|
|
19929
19929
|
|
|
19930
19930
|
declare type Serializer<TMIMEType extends MIMEType> = ({
|
|
19931
19931
|
snapshot,
|
package/lib/index.d.cts
CHANGED
|
@@ -120,13 +120,13 @@ declare type Behavior<
|
|
|
120
120
|
/**
|
|
121
121
|
* Array of behavior action sets.
|
|
122
122
|
*/
|
|
123
|
-
actions: Array<
|
|
123
|
+
actions: Array<BehaviorActionSet<TBehaviorEvent, TGuardResponse>>
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
/**
|
|
127
127
|
* @beta
|
|
128
128
|
*/
|
|
129
|
-
declare type
|
|
129
|
+
declare type BehaviorAction =
|
|
130
130
|
| SyntheticBehaviorEvent
|
|
131
131
|
| {
|
|
132
132
|
type: 'raise'
|
|
@@ -143,7 +143,7 @@ declare type BehaviorActionIntend =
|
|
|
143
143
|
/**
|
|
144
144
|
* @beta
|
|
145
145
|
*/
|
|
146
|
-
declare type
|
|
146
|
+
declare type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (
|
|
147
147
|
payload: {
|
|
148
148
|
/**
|
|
149
149
|
* @deprecated
|
|
@@ -154,7 +154,7 @@ declare type BehaviorActionIntendSet<TBehaviorEvent, TGuardResponse> = (
|
|
|
154
154
|
event: TBehaviorEvent
|
|
155
155
|
},
|
|
156
156
|
guardResponse: TGuardResponse,
|
|
157
|
-
) => Array<
|
|
157
|
+
) => Array<BehaviorAction>
|
|
158
158
|
|
|
159
159
|
/**
|
|
160
160
|
* @beta
|
package/lib/index.d.ts
CHANGED
|
@@ -120,13 +120,13 @@ declare type Behavior<
|
|
|
120
120
|
/**
|
|
121
121
|
* Array of behavior action sets.
|
|
122
122
|
*/
|
|
123
|
-
actions: Array<
|
|
123
|
+
actions: Array<BehaviorActionSet<TBehaviorEvent, TGuardResponse>>
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
/**
|
|
127
127
|
* @beta
|
|
128
128
|
*/
|
|
129
|
-
declare type
|
|
129
|
+
declare type BehaviorAction =
|
|
130
130
|
| SyntheticBehaviorEvent
|
|
131
131
|
| {
|
|
132
132
|
type: 'raise'
|
|
@@ -143,7 +143,7 @@ declare type BehaviorActionIntend =
|
|
|
143
143
|
/**
|
|
144
144
|
* @beta
|
|
145
145
|
*/
|
|
146
|
-
declare type
|
|
146
|
+
declare type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (
|
|
147
147
|
payload: {
|
|
148
148
|
/**
|
|
149
149
|
* @deprecated
|
|
@@ -154,7 +154,7 @@ declare type BehaviorActionIntendSet<TBehaviorEvent, TGuardResponse> = (
|
|
|
154
154
|
event: TBehaviorEvent
|
|
155
155
|
},
|
|
156
156
|
guardResponse: TGuardResponse,
|
|
157
|
-
) => Array<
|
|
157
|
+
) => Array<BehaviorAction>
|
|
158
158
|
|
|
159
159
|
/**
|
|
160
160
|
* @beta
|
package/lib/plugins/index.d.cts
CHANGED
|
@@ -75,13 +75,13 @@ declare type Behavior<
|
|
|
75
75
|
/**
|
|
76
76
|
* Array of behavior action sets.
|
|
77
77
|
*/
|
|
78
|
-
actions: Array<
|
|
78
|
+
actions: Array<BehaviorActionSet<TBehaviorEvent, TGuardResponse>>
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
82
|
* @beta
|
|
83
83
|
*/
|
|
84
|
-
declare type
|
|
84
|
+
declare type BehaviorAction =
|
|
85
85
|
| SyntheticBehaviorEvent
|
|
86
86
|
| {
|
|
87
87
|
type: 'raise'
|
|
@@ -98,7 +98,7 @@ declare type BehaviorActionIntend =
|
|
|
98
98
|
/**
|
|
99
99
|
* @beta
|
|
100
100
|
*/
|
|
101
|
-
declare type
|
|
101
|
+
declare type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (
|
|
102
102
|
payload: {
|
|
103
103
|
/**
|
|
104
104
|
* @deprecated
|
|
@@ -109,7 +109,7 @@ declare type BehaviorActionIntendSet<TBehaviorEvent, TGuardResponse> = (
|
|
|
109
109
|
event: TBehaviorEvent
|
|
110
110
|
},
|
|
111
111
|
guardResponse: TGuardResponse,
|
|
112
|
-
) => Array<
|
|
112
|
+
) => Array<BehaviorAction>
|
|
113
113
|
|
|
114
114
|
/**
|
|
115
115
|
* @beta
|
package/lib/plugins/index.d.ts
CHANGED
|
@@ -75,13 +75,13 @@ declare type Behavior<
|
|
|
75
75
|
/**
|
|
76
76
|
* Array of behavior action sets.
|
|
77
77
|
*/
|
|
78
|
-
actions: Array<
|
|
78
|
+
actions: Array<BehaviorActionSet<TBehaviorEvent, TGuardResponse>>
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
82
|
* @beta
|
|
83
83
|
*/
|
|
84
|
-
declare type
|
|
84
|
+
declare type BehaviorAction =
|
|
85
85
|
| SyntheticBehaviorEvent
|
|
86
86
|
| {
|
|
87
87
|
type: 'raise'
|
|
@@ -98,7 +98,7 @@ declare type BehaviorActionIntend =
|
|
|
98
98
|
/**
|
|
99
99
|
* @beta
|
|
100
100
|
*/
|
|
101
|
-
declare type
|
|
101
|
+
declare type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (
|
|
102
102
|
payload: {
|
|
103
103
|
/**
|
|
104
104
|
* @deprecated
|
|
@@ -109,7 +109,7 @@ declare type BehaviorActionIntendSet<TBehaviorEvent, TGuardResponse> = (
|
|
|
109
109
|
event: TBehaviorEvent
|
|
110
110
|
},
|
|
111
111
|
guardResponse: TGuardResponse,
|
|
112
|
-
) => Array<
|
|
112
|
+
) => Array<BehaviorAction>
|
|
113
113
|
|
|
114
114
|
/**
|
|
115
115
|
* @beta
|
|
@@ -76,13 +76,13 @@ declare type Behavior<
|
|
|
76
76
|
/**
|
|
77
77
|
* Array of behavior action sets.
|
|
78
78
|
*/
|
|
79
|
-
actions: Array<
|
|
79
|
+
actions: Array<BehaviorActionSet<TBehaviorEvent, TGuardResponse>>
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
83
|
* @beta
|
|
84
84
|
*/
|
|
85
|
-
declare type
|
|
85
|
+
declare type BehaviorAction =
|
|
86
86
|
| SyntheticBehaviorEvent
|
|
87
87
|
| {
|
|
88
88
|
type: 'raise'
|
|
@@ -99,7 +99,7 @@ declare type BehaviorActionIntend =
|
|
|
99
99
|
/**
|
|
100
100
|
* @beta
|
|
101
101
|
*/
|
|
102
|
-
declare type
|
|
102
|
+
declare type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (
|
|
103
103
|
payload: {
|
|
104
104
|
/**
|
|
105
105
|
* @deprecated
|
|
@@ -110,7 +110,7 @@ declare type BehaviorActionIntendSet<TBehaviorEvent, TGuardResponse> = (
|
|
|
110
110
|
event: TBehaviorEvent
|
|
111
111
|
},
|
|
112
112
|
guardResponse: TGuardResponse,
|
|
113
|
-
) => Array<
|
|
113
|
+
) => Array<BehaviorAction>
|
|
114
114
|
|
|
115
115
|
/**
|
|
116
116
|
* @beta
|
package/lib/selectors/index.d.ts
CHANGED
|
@@ -76,13 +76,13 @@ declare type Behavior<
|
|
|
76
76
|
/**
|
|
77
77
|
* Array of behavior action sets.
|
|
78
78
|
*/
|
|
79
|
-
actions: Array<
|
|
79
|
+
actions: Array<BehaviorActionSet<TBehaviorEvent, TGuardResponse>>
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
83
|
* @beta
|
|
84
84
|
*/
|
|
85
|
-
declare type
|
|
85
|
+
declare type BehaviorAction =
|
|
86
86
|
| SyntheticBehaviorEvent
|
|
87
87
|
| {
|
|
88
88
|
type: 'raise'
|
|
@@ -99,7 +99,7 @@ declare type BehaviorActionIntend =
|
|
|
99
99
|
/**
|
|
100
100
|
* @beta
|
|
101
101
|
*/
|
|
102
|
-
declare type
|
|
102
|
+
declare type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (
|
|
103
103
|
payload: {
|
|
104
104
|
/**
|
|
105
105
|
* @deprecated
|
|
@@ -110,7 +110,7 @@ declare type BehaviorActionIntendSet<TBehaviorEvent, TGuardResponse> = (
|
|
|
110
110
|
event: TBehaviorEvent
|
|
111
111
|
},
|
|
112
112
|
guardResponse: TGuardResponse,
|
|
113
|
-
) => Array<
|
|
113
|
+
) => Array<BehaviorAction>
|
|
114
114
|
|
|
115
115
|
/**
|
|
116
116
|
* @beta
|
package/lib/utils/index.d.cts
CHANGED
|
@@ -77,13 +77,13 @@ declare type Behavior<
|
|
|
77
77
|
/**
|
|
78
78
|
* Array of behavior action sets.
|
|
79
79
|
*/
|
|
80
|
-
actions: Array<
|
|
80
|
+
actions: Array<BehaviorActionSet<TBehaviorEvent, TGuardResponse>>
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
84
|
* @beta
|
|
85
85
|
*/
|
|
86
|
-
declare type
|
|
86
|
+
declare type BehaviorAction =
|
|
87
87
|
| SyntheticBehaviorEvent
|
|
88
88
|
| {
|
|
89
89
|
type: 'raise'
|
|
@@ -100,7 +100,7 @@ declare type BehaviorActionIntend =
|
|
|
100
100
|
/**
|
|
101
101
|
* @beta
|
|
102
102
|
*/
|
|
103
|
-
declare type
|
|
103
|
+
declare type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (
|
|
104
104
|
payload: {
|
|
105
105
|
/**
|
|
106
106
|
* @deprecated
|
|
@@ -111,7 +111,7 @@ declare type BehaviorActionIntendSet<TBehaviorEvent, TGuardResponse> = (
|
|
|
111
111
|
event: TBehaviorEvent
|
|
112
112
|
},
|
|
113
113
|
guardResponse: TGuardResponse,
|
|
114
|
-
) => Array<
|
|
114
|
+
) => Array<BehaviorAction>
|
|
115
115
|
|
|
116
116
|
/**
|
|
117
117
|
* @beta
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -77,13 +77,13 @@ declare type Behavior<
|
|
|
77
77
|
/**
|
|
78
78
|
* Array of behavior action sets.
|
|
79
79
|
*/
|
|
80
|
-
actions: Array<
|
|
80
|
+
actions: Array<BehaviorActionSet<TBehaviorEvent, TGuardResponse>>
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
84
|
* @beta
|
|
85
85
|
*/
|
|
86
|
-
declare type
|
|
86
|
+
declare type BehaviorAction =
|
|
87
87
|
| SyntheticBehaviorEvent
|
|
88
88
|
| {
|
|
89
89
|
type: 'raise'
|
|
@@ -100,7 +100,7 @@ declare type BehaviorActionIntend =
|
|
|
100
100
|
/**
|
|
101
101
|
* @beta
|
|
102
102
|
*/
|
|
103
|
-
declare type
|
|
103
|
+
declare type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (
|
|
104
104
|
payload: {
|
|
105
105
|
/**
|
|
106
106
|
* @deprecated
|
|
@@ -111,7 +111,7 @@ declare type BehaviorActionIntendSet<TBehaviorEvent, TGuardResponse> = (
|
|
|
111
111
|
event: TBehaviorEvent
|
|
112
112
|
},
|
|
113
113
|
guardResponse: TGuardResponse,
|
|
114
|
-
) => Array<
|
|
114
|
+
) => Array<BehaviorAction>
|
|
115
115
|
|
|
116
116
|
/**
|
|
117
117
|
* @beta
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {deleteForward, insertText, Path, Transforms} from 'slate'
|
|
2
2
|
import {ReactEditor} from 'slate-react'
|
|
3
3
|
import type {
|
|
4
|
-
|
|
4
|
+
InternalBehaviorAction,
|
|
5
5
|
SyntheticBehaviorEvent,
|
|
6
6
|
} from '../behaviors/behavior.types'
|
|
7
7
|
import type {EditorContext} from '../editor/editor-snapshot'
|
|
@@ -55,18 +55,18 @@ export type BehaviorActionImplementationContext = Pick<
|
|
|
55
55
|
>
|
|
56
56
|
|
|
57
57
|
export type BehaviorActionImplementation<
|
|
58
|
-
TBehaviorActionType extends
|
|
58
|
+
TBehaviorActionType extends InternalBehaviorAction['type'],
|
|
59
59
|
TReturnType = void,
|
|
60
60
|
> = ({
|
|
61
61
|
context,
|
|
62
62
|
action,
|
|
63
63
|
}: {
|
|
64
64
|
context: BehaviorActionImplementationContext
|
|
65
|
-
action: PickFromUnion<
|
|
65
|
+
action: PickFromUnion<InternalBehaviorAction, 'type', TBehaviorActionType>
|
|
66
66
|
}) => TReturnType
|
|
67
67
|
|
|
68
68
|
type BehaviorActionImplementations = {
|
|
69
|
-
[TBehaviorActionType in
|
|
69
|
+
[TBehaviorActionType in InternalBehaviorAction['type']]: BehaviorActionImplementation<TBehaviorActionType>
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
const behaviorActionImplementations: BehaviorActionImplementations = {
|
|
@@ -271,7 +271,7 @@ export function performAction({
|
|
|
271
271
|
action,
|
|
272
272
|
}: {
|
|
273
273
|
context: BehaviorActionImplementationContext
|
|
274
|
-
action:
|
|
274
|
+
action: InternalBehaviorAction
|
|
275
275
|
}) {
|
|
276
276
|
switch (action.type) {
|
|
277
277
|
case 'noop': {
|
|
@@ -299,7 +299,11 @@ function performDefaultAction({
|
|
|
299
299
|
action,
|
|
300
300
|
}: {
|
|
301
301
|
context: BehaviorActionImplementationContext
|
|
302
|
-
action: PickFromUnion<
|
|
302
|
+
action: PickFromUnion<
|
|
303
|
+
InternalBehaviorAction,
|
|
304
|
+
'type',
|
|
305
|
+
SyntheticBehaviorEvent['type']
|
|
306
|
+
>
|
|
303
307
|
}) {
|
|
304
308
|
switch (action.type) {
|
|
305
309
|
case 'annotation.add': {
|
|
@@ -6,10 +6,8 @@ import {defineBehavior, raise} from './behavior.types'
|
|
|
6
6
|
* than an `insertLineBreak` input event. This Behavior makes sure we catch
|
|
7
7
|
* that `key.down` event beforehand and raise an `insert.soft break` manually.
|
|
8
8
|
*/
|
|
9
|
-
const
|
|
9
|
+
export const raiseInsertSoftBreak = defineBehavior({
|
|
10
10
|
on: 'key.down',
|
|
11
11
|
guard: ({event}) => keyIs.lineBreak(event.keyboardEvent),
|
|
12
12
|
actions: [() => [raise({type: 'insert.soft break'})]],
|
|
13
13
|
})
|
|
14
|
-
|
|
15
|
-
export const foundationalBehaviors = [raiseSoftBreak]
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as selectors from '../selectors'
|
|
2
|
+
import {raiseInsertSoftBreak} from './behavior.default.raise-soft-break'
|
|
2
3
|
import {defineBehavior, raise} from './behavior.types'
|
|
3
4
|
|
|
4
5
|
const toggleAnnotationOff = defineBehavior({
|
|
@@ -200,4 +201,5 @@ export const defaultBehaviors = [
|
|
|
200
201
|
raiseInsertBlocks,
|
|
201
202
|
raiseSerializationSuccessOrFailure,
|
|
202
203
|
raiseDataTransferSet,
|
|
204
|
+
raiseInsertSoftBreak,
|
|
203
205
|
]
|
|
@@ -261,7 +261,7 @@ export function isCustomBehaviorEvent(
|
|
|
261
261
|
/**
|
|
262
262
|
* @beta
|
|
263
263
|
*/
|
|
264
|
-
export type
|
|
264
|
+
export type BehaviorAction =
|
|
265
265
|
| SyntheticBehaviorEvent
|
|
266
266
|
| {
|
|
267
267
|
type: 'raise'
|
|
@@ -275,11 +275,8 @@ export type BehaviorActionIntend =
|
|
|
275
275
|
effect: () => void
|
|
276
276
|
}
|
|
277
277
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
*/
|
|
281
|
-
export type BehaviorAction = OmitFromUnion<
|
|
282
|
-
BehaviorActionIntend,
|
|
278
|
+
export type InternalBehaviorAction = OmitFromUnion<
|
|
279
|
+
BehaviorAction,
|
|
283
280
|
'type',
|
|
284
281
|
'raise'
|
|
285
282
|
> & {
|
|
@@ -291,7 +288,7 @@ export type BehaviorAction = OmitFromUnion<
|
|
|
291
288
|
*/
|
|
292
289
|
export function raise(
|
|
293
290
|
event: SyntheticBehaviorEvent | CustomBehaviorEvent,
|
|
294
|
-
): PickFromUnion<
|
|
291
|
+
): PickFromUnion<BehaviorAction, 'type', 'raise'> {
|
|
295
292
|
return {type: 'raise', event}
|
|
296
293
|
}
|
|
297
294
|
|
|
@@ -327,7 +324,7 @@ export type Behavior<
|
|
|
327
324
|
/**
|
|
328
325
|
* Array of behavior action sets.
|
|
329
326
|
*/
|
|
330
|
-
actions: Array<
|
|
327
|
+
actions: Array<BehaviorActionSet<TBehaviorEvent, TGuardResponse>>
|
|
331
328
|
}
|
|
332
329
|
|
|
333
330
|
/**
|
|
@@ -346,7 +343,7 @@ export type BehaviorGuard<TBehaviorEvent, TGuardResponse> = (payload: {
|
|
|
346
343
|
/**
|
|
347
344
|
* @beta
|
|
348
345
|
*/
|
|
349
|
-
export type
|
|
346
|
+
export type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (
|
|
350
347
|
payload: {
|
|
351
348
|
/**
|
|
352
349
|
* @deprecated
|
|
@@ -357,7 +354,7 @@ export type BehaviorActionIntendSet<TBehaviorEvent, TGuardResponse> = (
|
|
|
357
354
|
event: TBehaviorEvent
|
|
358
355
|
},
|
|
359
356
|
guardResponse: TGuardResponse,
|
|
360
|
-
) => Array<
|
|
357
|
+
) => Array<BehaviorAction>
|
|
361
358
|
|
|
362
359
|
/**
|
|
363
360
|
* @beta
|
package/src/behaviors/index.ts
CHANGED
|
@@ -12,12 +12,11 @@ import {
|
|
|
12
12
|
import {performAction} from '../behavior-actions/behavior.actions'
|
|
13
13
|
import {coreBehaviors} from '../behaviors/behavior.core'
|
|
14
14
|
import {defaultBehaviors} from '../behaviors/behavior.default'
|
|
15
|
-
import {foundationalBehaviors} from '../behaviors/behavior.foundational'
|
|
16
15
|
import {
|
|
17
16
|
isCustomBehaviorEvent,
|
|
18
17
|
type Behavior,
|
|
19
|
-
type BehaviorAction,
|
|
20
18
|
type CustomBehaviorEvent,
|
|
19
|
+
type InternalBehaviorAction,
|
|
21
20
|
type NativeBehaviorEvent,
|
|
22
21
|
type SyntheticBehaviorEvent,
|
|
23
22
|
} from '../behaviors/behavior.types'
|
|
@@ -31,8 +30,8 @@ import type {
|
|
|
31
30
|
import type {EditorSchema} from './define-schema'
|
|
32
31
|
import {createEditorSnapshot} from './editor-snapshot'
|
|
33
32
|
import {
|
|
34
|
-
withApplyingBehaviorActionIntendSet,
|
|
35
33
|
withApplyingBehaviorActions,
|
|
34
|
+
withApplyingBehaviorActionSet,
|
|
36
35
|
} from './with-applying-behavior-actions'
|
|
37
36
|
|
|
38
37
|
export * from 'xstate/guards'
|
|
@@ -324,14 +323,13 @@ export const editorMachine = setup({
|
|
|
324
323
|
: ({
|
|
325
324
|
...event.behaviorEvent,
|
|
326
325
|
editor: event.editor,
|
|
327
|
-
} satisfies
|
|
326
|
+
} satisfies InternalBehaviorAction)
|
|
328
327
|
const defaultActionCallback =
|
|
329
328
|
event.type === 'behavior event'
|
|
330
329
|
? event.defaultActionCallback
|
|
331
330
|
: undefined
|
|
332
331
|
|
|
333
332
|
const eventBehaviors = [
|
|
334
|
-
...foundationalBehaviors,
|
|
335
333
|
...context.behaviors.values(),
|
|
336
334
|
...defaultBehaviors,
|
|
337
335
|
].filter(
|
|
@@ -400,7 +398,7 @@ export const editorMachine = setup({
|
|
|
400
398
|
continue
|
|
401
399
|
}
|
|
402
400
|
|
|
403
|
-
const
|
|
401
|
+
const actionSets = eventBehavior.actions.map((actionSet) =>
|
|
404
402
|
actionSet(
|
|
405
403
|
{
|
|
406
404
|
context: editorSnapshot.context,
|
|
@@ -411,44 +409,42 @@ export const editorMachine = setup({
|
|
|
411
409
|
),
|
|
412
410
|
)
|
|
413
411
|
|
|
414
|
-
for (const
|
|
412
|
+
for (const actionSet of actionSets) {
|
|
415
413
|
behaviorOverwritten =
|
|
416
414
|
behaviorOverwritten ||
|
|
417
|
-
(
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
if (actionIntend.type === 'raise') {
|
|
425
|
-
if (isCustomBehaviorEvent(actionIntend.event)) {
|
|
415
|
+
(actionSet.length > 0 &&
|
|
416
|
+
actionSet.some((action) => action.type !== 'effect'))
|
|
417
|
+
|
|
418
|
+
withApplyingBehaviorActionSet(event.editor, () => {
|
|
419
|
+
for (const action of actionSet) {
|
|
420
|
+
if (action.type === 'raise') {
|
|
421
|
+
if (isCustomBehaviorEvent(action.event)) {
|
|
426
422
|
enqueue.raise({
|
|
427
423
|
type: 'custom behavior event',
|
|
428
|
-
behaviorEvent:
|
|
424
|
+
behaviorEvent: action.event as CustomBehaviorEvent,
|
|
429
425
|
editor: event.editor,
|
|
430
426
|
})
|
|
431
427
|
} else {
|
|
432
428
|
enqueue.raise({
|
|
433
429
|
type: 'behavior event',
|
|
434
|
-
behaviorEvent:
|
|
430
|
+
behaviorEvent: action.event,
|
|
435
431
|
editor: event.editor,
|
|
436
432
|
})
|
|
437
433
|
}
|
|
438
434
|
continue
|
|
439
435
|
}
|
|
440
436
|
|
|
441
|
-
const
|
|
442
|
-
...
|
|
437
|
+
const internalAction = {
|
|
438
|
+
...action,
|
|
443
439
|
editor: event.editor,
|
|
444
440
|
}
|
|
445
441
|
|
|
446
442
|
try {
|
|
447
|
-
performAction({context, action})
|
|
443
|
+
performAction({context, action: internalAction})
|
|
448
444
|
} catch (error) {
|
|
449
445
|
console.error(
|
|
450
446
|
new Error(
|
|
451
|
-
`Performing action "${
|
|
447
|
+
`Performing action "${internalAction.type}" as a result of "${event.behaviorEvent.type}" failed due to: ${error.message}`,
|
|
452
448
|
),
|
|
453
449
|
)
|
|
454
450
|
break
|
|
@@ -80,8 +80,7 @@ export function createWithUndoRedo(
|
|
|
80
80
|
blockSchemaType.name,
|
|
81
81
|
)
|
|
82
82
|
const remotePatches = getRemotePatches(editor)
|
|
83
|
-
let
|
|
84
|
-
getCurrentBehaviorActionSetId(editor)
|
|
83
|
+
let previousBehaviorActionSetId = getCurrentBehaviorActionSetId(editor)
|
|
85
84
|
|
|
86
85
|
options.subscriptions.push(() => {
|
|
87
86
|
debug('Subscribing to patches')
|
|
@@ -151,17 +150,15 @@ export function createWithUndoRedo(
|
|
|
151
150
|
const overwrite = shouldOverwrite(op, lastOp)
|
|
152
151
|
const save = isSaving(editor)
|
|
153
152
|
|
|
154
|
-
const
|
|
155
|
-
getCurrentBehaviorActionSetId(editor)
|
|
153
|
+
const currentBehaviorActionSetId = getCurrentBehaviorActionSetId(editor)
|
|
156
154
|
|
|
157
155
|
let merge =
|
|
158
|
-
|
|
159
|
-
|
|
156
|
+
currentBehaviorActionSetId !== undefined &&
|
|
157
|
+
previousBehaviorActionSetId === undefined
|
|
160
158
|
? false
|
|
161
|
-
:
|
|
162
|
-
|
|
163
|
-
?
|
|
164
|
-
previousBehaviorActionIntendSetId
|
|
159
|
+
: currentBehaviorActionSetId !== undefined &&
|
|
160
|
+
previousBehaviorActionSetId !== undefined
|
|
161
|
+
? currentBehaviorActionSetId === previousBehaviorActionSetId
|
|
165
162
|
: true
|
|
166
163
|
|
|
167
164
|
if (save) {
|
|
@@ -169,8 +166,8 @@ export function createWithUndoRedo(
|
|
|
169
166
|
merge = false
|
|
170
167
|
} else if (operations.length === 0) {
|
|
171
168
|
merge =
|
|
172
|
-
|
|
173
|
-
|
|
169
|
+
currentBehaviorActionSetId === undefined &&
|
|
170
|
+
previousBehaviorActionSetId === undefined
|
|
174
171
|
? shouldMerge(op, lastOp) || overwrite
|
|
175
172
|
: merge
|
|
176
173
|
}
|
|
@@ -200,7 +197,7 @@ export function createWithUndoRedo(
|
|
|
200
197
|
}
|
|
201
198
|
}
|
|
202
199
|
|
|
203
|
-
|
|
200
|
+
previousBehaviorActionSetId = currentBehaviorActionSetId
|
|
204
201
|
|
|
205
202
|
apply(op)
|
|
206
203
|
}
|