@portabletext/editor 1.36.3 → 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 +23 -23
- 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 +23 -23
- 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.types.ts +7 -10
- package/src/behaviors/index.ts +2 -2
- package/src/editor/editor-machine.ts +18 -20
- 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': {
|
|
@@ -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
|
@@ -15,8 +15,8 @@ import {defaultBehaviors} from '../behaviors/behavior.default'
|
|
|
15
15
|
import {
|
|
16
16
|
isCustomBehaviorEvent,
|
|
17
17
|
type Behavior,
|
|
18
|
-
type BehaviorAction,
|
|
19
18
|
type CustomBehaviorEvent,
|
|
19
|
+
type InternalBehaviorAction,
|
|
20
20
|
type NativeBehaviorEvent,
|
|
21
21
|
type SyntheticBehaviorEvent,
|
|
22
22
|
} from '../behaviors/behavior.types'
|
|
@@ -30,8 +30,8 @@ import type {
|
|
|
30
30
|
import type {EditorSchema} from './define-schema'
|
|
31
31
|
import {createEditorSnapshot} from './editor-snapshot'
|
|
32
32
|
import {
|
|
33
|
-
withApplyingBehaviorActionIntendSet,
|
|
34
33
|
withApplyingBehaviorActions,
|
|
34
|
+
withApplyingBehaviorActionSet,
|
|
35
35
|
} from './with-applying-behavior-actions'
|
|
36
36
|
|
|
37
37
|
export * from 'xstate/guards'
|
|
@@ -323,7 +323,7 @@ export const editorMachine = setup({
|
|
|
323
323
|
: ({
|
|
324
324
|
...event.behaviorEvent,
|
|
325
325
|
editor: event.editor,
|
|
326
|
-
} satisfies
|
|
326
|
+
} satisfies InternalBehaviorAction)
|
|
327
327
|
const defaultActionCallback =
|
|
328
328
|
event.type === 'behavior event'
|
|
329
329
|
? event.defaultActionCallback
|
|
@@ -398,7 +398,7 @@ export const editorMachine = setup({
|
|
|
398
398
|
continue
|
|
399
399
|
}
|
|
400
400
|
|
|
401
|
-
const
|
|
401
|
+
const actionSets = eventBehavior.actions.map((actionSet) =>
|
|
402
402
|
actionSet(
|
|
403
403
|
{
|
|
404
404
|
context: editorSnapshot.context,
|
|
@@ -409,44 +409,42 @@ export const editorMachine = setup({
|
|
|
409
409
|
),
|
|
410
410
|
)
|
|
411
411
|
|
|
412
|
-
for (const
|
|
412
|
+
for (const actionSet of actionSets) {
|
|
413
413
|
behaviorOverwritten =
|
|
414
414
|
behaviorOverwritten ||
|
|
415
|
-
(
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
if (actionIntend.type === 'raise') {
|
|
423
|
-
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)) {
|
|
424
422
|
enqueue.raise({
|
|
425
423
|
type: 'custom behavior event',
|
|
426
|
-
behaviorEvent:
|
|
424
|
+
behaviorEvent: action.event as CustomBehaviorEvent,
|
|
427
425
|
editor: event.editor,
|
|
428
426
|
})
|
|
429
427
|
} else {
|
|
430
428
|
enqueue.raise({
|
|
431
429
|
type: 'behavior event',
|
|
432
|
-
behaviorEvent:
|
|
430
|
+
behaviorEvent: action.event,
|
|
433
431
|
editor: event.editor,
|
|
434
432
|
})
|
|
435
433
|
}
|
|
436
434
|
continue
|
|
437
435
|
}
|
|
438
436
|
|
|
439
|
-
const
|
|
440
|
-
...
|
|
437
|
+
const internalAction = {
|
|
438
|
+
...action,
|
|
441
439
|
editor: event.editor,
|
|
442
440
|
}
|
|
443
441
|
|
|
444
442
|
try {
|
|
445
|
-
performAction({context, action})
|
|
443
|
+
performAction({context, action: internalAction})
|
|
446
444
|
} catch (error) {
|
|
447
445
|
console.error(
|
|
448
446
|
new Error(
|
|
449
|
-
`Performing action "${
|
|
447
|
+
`Performing action "${internalAction.type}" as a result of "${event.behaviorEvent.type}" failed due to: ${error.message}`,
|
|
450
448
|
),
|
|
451
449
|
)
|
|
452
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
|
}
|
|
@@ -19,23 +19,20 @@ export function isApplyingBehaviorActions(editor: Editor) {
|
|
|
19
19
|
|
|
20
20
|
////////
|
|
21
21
|
|
|
22
|
-
const
|
|
22
|
+
const CURRENT_BEHAVIOR_ACTION_SET: WeakMap<
|
|
23
23
|
Editor,
|
|
24
24
|
{actionSetId: string} | undefined
|
|
25
25
|
> = new WeakMap()
|
|
26
26
|
|
|
27
|
-
export function
|
|
28
|
-
editor
|
|
29
|
-
|
|
30
|
-
) {
|
|
31
|
-
const current = CURRENT_BEHAVIOR_ACTION_INTEND_SET.get(editor)
|
|
32
|
-
CURRENT_BEHAVIOR_ACTION_INTEND_SET.set(editor, {
|
|
27
|
+
export function withApplyingBehaviorActionSet(editor: Editor, fn: () => void) {
|
|
28
|
+
const current = CURRENT_BEHAVIOR_ACTION_SET.get(editor)
|
|
29
|
+
CURRENT_BEHAVIOR_ACTION_SET.set(editor, {
|
|
33
30
|
actionSetId: defaultKeyGenerator(),
|
|
34
31
|
})
|
|
35
32
|
withApplyingBehaviorActions(editor, fn)
|
|
36
|
-
|
|
33
|
+
CURRENT_BEHAVIOR_ACTION_SET.set(editor, current)
|
|
37
34
|
}
|
|
38
35
|
|
|
39
36
|
export function getCurrentBehaviorActionSetId(editor: Editor) {
|
|
40
|
-
return
|
|
37
|
+
return CURRENT_BEHAVIOR_ACTION_SET.get(editor)?.actionSetId
|
|
41
38
|
}
|