@portabletext/editor 1.45.4 → 1.47.0
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 +20 -0
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +25 -25
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +69 -4
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +20 -0
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +26 -26
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +69 -4
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +1 -1
- package/lib/behaviors/index.cjs +37 -53
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +546 -1
- package/lib/behaviors/index.d.ts +546 -1
- package/lib/behaviors/index.js +38 -54
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.d.cts +17 -1
- package/lib/index.d.ts +17 -1
- package/lib/plugins/index.cjs +23 -29
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +17 -1
- package/lib/plugins/index.d.ts +17 -1
- package/lib/plugins/index.js +24 -30
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.cts +17 -1
- package/lib/selectors/index.d.ts +17 -1
- package/lib/utils/index.d.cts +17 -1
- package/lib/utils/index.d.ts +17 -1
- package/package.json +3 -3
- package/src/behavior-actions/behavior.action.move.backward.ts +12 -0
- package/src/behavior-actions/behavior.action.move.forward.ts +11 -0
- package/src/behavior-actions/behavior.actions.ts +18 -0
- package/src/behaviors/behavior.decorator-pair.ts +16 -19
- package/src/behaviors/behavior.emoji-picker.ts +26 -45
- package/src/behaviors/behavior.links.ts +5 -4
- package/src/behaviors/behavior.markdown.ts +37 -34
- package/src/behaviors/behavior.perform-event.ts +53 -2
- package/src/behaviors/behavior.types.action.ts +38 -7
- package/src/behaviors/behavior.types.event.ts +10 -0
- package/src/behaviors/index.ts +3 -0
- package/src/editor/editor-machine.ts +2 -2
- package/src/plugins/plugin.decorator-shortcut.ts +6 -8
- package/src/plugins/plugin.one-line.tsx +4 -4
|
@@ -255,7 +255,13 @@ declare type Behavior<
|
|
|
255
255
|
* @beta
|
|
256
256
|
*/
|
|
257
257
|
declare type BehaviorAction =
|
|
258
|
-
|
|
|
258
|
+
| {
|
|
259
|
+
type: 'execute'
|
|
260
|
+
event:
|
|
261
|
+
| AbstractBehaviorEvent
|
|
262
|
+
| SyntheticBehaviorEvent
|
|
263
|
+
| CustomBehaviorEvent
|
|
264
|
+
}
|
|
259
265
|
| {
|
|
260
266
|
type: 'raise'
|
|
261
267
|
event:
|
|
@@ -5442,11 +5448,19 @@ declare type SyntheticBehaviorEvent =
|
|
|
5442
5448
|
type: StrictExtract<SyntheticBehaviorEventType, 'insert.text'>
|
|
5443
5449
|
text: string
|
|
5444
5450
|
}
|
|
5451
|
+
| {
|
|
5452
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'move.backward'>
|
|
5453
|
+
distance: number
|
|
5454
|
+
}
|
|
5445
5455
|
| {
|
|
5446
5456
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.block'>
|
|
5447
5457
|
at: [KeyedSegment]
|
|
5448
5458
|
to: [KeyedSegment]
|
|
5449
5459
|
}
|
|
5460
|
+
| {
|
|
5461
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'move.forward'>
|
|
5462
|
+
distance: number
|
|
5463
|
+
}
|
|
5450
5464
|
| {
|
|
5451
5465
|
type: StrictExtract<SyntheticBehaviorEventType, 'select'>
|
|
5452
5466
|
at: EditorSelection
|
|
@@ -5483,7 +5497,9 @@ declare const syntheticBehaviorEventTypes: readonly [
|
|
|
5483
5497
|
'insert.block',
|
|
5484
5498
|
'insert.span',
|
|
5485
5499
|
'insert.text',
|
|
5500
|
+
'move.backward',
|
|
5486
5501
|
'move.block',
|
|
5502
|
+
'move.forward',
|
|
5487
5503
|
'select',
|
|
5488
5504
|
'split.block',
|
|
5489
5505
|
]
|
package/lib/selectors/index.d.ts
CHANGED
|
@@ -255,7 +255,13 @@ declare type Behavior<
|
|
|
255
255
|
* @beta
|
|
256
256
|
*/
|
|
257
257
|
declare type BehaviorAction =
|
|
258
|
-
|
|
|
258
|
+
| {
|
|
259
|
+
type: 'execute'
|
|
260
|
+
event:
|
|
261
|
+
| AbstractBehaviorEvent
|
|
262
|
+
| SyntheticBehaviorEvent
|
|
263
|
+
| CustomBehaviorEvent
|
|
264
|
+
}
|
|
259
265
|
| {
|
|
260
266
|
type: 'raise'
|
|
261
267
|
event:
|
|
@@ -5442,11 +5448,19 @@ declare type SyntheticBehaviorEvent =
|
|
|
5442
5448
|
type: StrictExtract<SyntheticBehaviorEventType, 'insert.text'>
|
|
5443
5449
|
text: string
|
|
5444
5450
|
}
|
|
5451
|
+
| {
|
|
5452
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'move.backward'>
|
|
5453
|
+
distance: number
|
|
5454
|
+
}
|
|
5445
5455
|
| {
|
|
5446
5456
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.block'>
|
|
5447
5457
|
at: [KeyedSegment]
|
|
5448
5458
|
to: [KeyedSegment]
|
|
5449
5459
|
}
|
|
5460
|
+
| {
|
|
5461
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'move.forward'>
|
|
5462
|
+
distance: number
|
|
5463
|
+
}
|
|
5450
5464
|
| {
|
|
5451
5465
|
type: StrictExtract<SyntheticBehaviorEventType, 'select'>
|
|
5452
5466
|
at: EditorSelection
|
|
@@ -5483,7 +5497,9 @@ declare const syntheticBehaviorEventTypes: readonly [
|
|
|
5483
5497
|
'insert.block',
|
|
5484
5498
|
'insert.span',
|
|
5485
5499
|
'insert.text',
|
|
5500
|
+
'move.backward',
|
|
5486
5501
|
'move.block',
|
|
5502
|
+
'move.forward',
|
|
5487
5503
|
'select',
|
|
5488
5504
|
'split.block',
|
|
5489
5505
|
]
|
package/lib/utils/index.d.cts
CHANGED
|
@@ -255,7 +255,13 @@ declare type Behavior<
|
|
|
255
255
|
* @beta
|
|
256
256
|
*/
|
|
257
257
|
declare type BehaviorAction =
|
|
258
|
-
|
|
|
258
|
+
| {
|
|
259
|
+
type: 'execute'
|
|
260
|
+
event:
|
|
261
|
+
| AbstractBehaviorEvent
|
|
262
|
+
| SyntheticBehaviorEvent
|
|
263
|
+
| CustomBehaviorEvent
|
|
264
|
+
}
|
|
259
265
|
| {
|
|
260
266
|
type: 'raise'
|
|
261
267
|
event:
|
|
@@ -5276,11 +5282,19 @@ declare type SyntheticBehaviorEvent =
|
|
|
5276
5282
|
type: StrictExtract<SyntheticBehaviorEventType, 'insert.text'>
|
|
5277
5283
|
text: string
|
|
5278
5284
|
}
|
|
5285
|
+
| {
|
|
5286
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'move.backward'>
|
|
5287
|
+
distance: number
|
|
5288
|
+
}
|
|
5279
5289
|
| {
|
|
5280
5290
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.block'>
|
|
5281
5291
|
at: [KeyedSegment]
|
|
5282
5292
|
to: [KeyedSegment]
|
|
5283
5293
|
}
|
|
5294
|
+
| {
|
|
5295
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'move.forward'>
|
|
5296
|
+
distance: number
|
|
5297
|
+
}
|
|
5284
5298
|
| {
|
|
5285
5299
|
type: StrictExtract<SyntheticBehaviorEventType, 'select'>
|
|
5286
5300
|
at: EditorSelection
|
|
@@ -5317,7 +5331,9 @@ declare const syntheticBehaviorEventTypes: readonly [
|
|
|
5317
5331
|
'insert.block',
|
|
5318
5332
|
'insert.span',
|
|
5319
5333
|
'insert.text',
|
|
5334
|
+
'move.backward',
|
|
5320
5335
|
'move.block',
|
|
5336
|
+
'move.forward',
|
|
5321
5337
|
'select',
|
|
5322
5338
|
'split.block',
|
|
5323
5339
|
]
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -255,7 +255,13 @@ declare type Behavior<
|
|
|
255
255
|
* @beta
|
|
256
256
|
*/
|
|
257
257
|
declare type BehaviorAction =
|
|
258
|
-
|
|
|
258
|
+
| {
|
|
259
|
+
type: 'execute'
|
|
260
|
+
event:
|
|
261
|
+
| AbstractBehaviorEvent
|
|
262
|
+
| SyntheticBehaviorEvent
|
|
263
|
+
| CustomBehaviorEvent
|
|
264
|
+
}
|
|
259
265
|
| {
|
|
260
266
|
type: 'raise'
|
|
261
267
|
event:
|
|
@@ -5276,11 +5282,19 @@ declare type SyntheticBehaviorEvent =
|
|
|
5276
5282
|
type: StrictExtract<SyntheticBehaviorEventType, 'insert.text'>
|
|
5277
5283
|
text: string
|
|
5278
5284
|
}
|
|
5285
|
+
| {
|
|
5286
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'move.backward'>
|
|
5287
|
+
distance: number
|
|
5288
|
+
}
|
|
5279
5289
|
| {
|
|
5280
5290
|
type: StrictExtract<SyntheticBehaviorEventType, 'move.block'>
|
|
5281
5291
|
at: [KeyedSegment]
|
|
5282
5292
|
to: [KeyedSegment]
|
|
5283
5293
|
}
|
|
5294
|
+
| {
|
|
5295
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'move.forward'>
|
|
5296
|
+
distance: number
|
|
5297
|
+
}
|
|
5284
5298
|
| {
|
|
5285
5299
|
type: StrictExtract<SyntheticBehaviorEventType, 'select'>
|
|
5286
5300
|
at: EditorSelection
|
|
@@ -5317,7 +5331,9 @@ declare const syntheticBehaviorEventTypes: readonly [
|
|
|
5317
5331
|
'insert.block',
|
|
5318
5332
|
'insert.span',
|
|
5319
5333
|
'insert.text',
|
|
5334
|
+
'move.backward',
|
|
5320
5335
|
'move.block',
|
|
5336
|
+
'move.forward',
|
|
5321
5337
|
'select',
|
|
5322
5338
|
'split.block',
|
|
5323
5339
|
]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.47.0",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"slate-react": "0.112.1",
|
|
80
80
|
"use-effect-event": "^1.0.2",
|
|
81
81
|
"xstate": "^5.19.2",
|
|
82
|
-
"@portabletext/
|
|
83
|
-
"@portabletext/
|
|
82
|
+
"@portabletext/patches": "1.1.3",
|
|
83
|
+
"@portabletext/block-tools": "1.1.17"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@portabletext/toolkit": "^2.0.17",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {Transforms} from 'slate'
|
|
2
|
+
import type {BehaviorActionImplementation} from './behavior.actions'
|
|
3
|
+
|
|
4
|
+
export const moveBackwardActionImplementation: BehaviorActionImplementation<
|
|
5
|
+
'move.backward'
|
|
6
|
+
> = ({action}) => {
|
|
7
|
+
Transforms.move(action.editor, {
|
|
8
|
+
unit: 'character',
|
|
9
|
+
distance: action.distance,
|
|
10
|
+
reverse: true,
|
|
11
|
+
})
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {Transforms} from 'slate'
|
|
2
|
+
import type {BehaviorActionImplementation} from './behavior.actions'
|
|
3
|
+
|
|
4
|
+
export const moveForwardActionImplementation: BehaviorActionImplementation<
|
|
5
|
+
'move.forward'
|
|
6
|
+
> = ({action}) => {
|
|
7
|
+
Transforms.move(action.editor, {
|
|
8
|
+
unit: 'character',
|
|
9
|
+
distance: action.distance,
|
|
10
|
+
})
|
|
11
|
+
}
|
|
@@ -24,7 +24,9 @@ import {insertInlineObjectActionImplementation} from './behavior.action.insert-i
|
|
|
24
24
|
import {insertSpanActionImplementation} from './behavior.action.insert-span'
|
|
25
25
|
import {insertBlockActionImplementation} from './behavior.action.insert.block'
|
|
26
26
|
import {insertTextActionImplementation} from './behavior.action.insert.text'
|
|
27
|
+
import {moveBackwardActionImplementation} from './behavior.action.move.backward'
|
|
27
28
|
import {moveBlockActionImplementation} from './behavior.action.move.block'
|
|
29
|
+
import {moveForwardActionImplementation} from './behavior.action.move.forward'
|
|
28
30
|
import {noopActionImplementation} from './behavior.action.noop'
|
|
29
31
|
import {selectActionImplementation} from './behavior.action.select'
|
|
30
32
|
import {splitBlockActionImplementation} from './behavior.action.split.block'
|
|
@@ -71,7 +73,9 @@ const behaviorActionImplementations: BehaviorActionImplementations = {
|
|
|
71
73
|
'insert.span': insertSpanActionImplementation,
|
|
72
74
|
'insert.text': insertTextActionImplementation,
|
|
73
75
|
'effect': effectActionImplementation,
|
|
76
|
+
'move.backward': moveBackwardActionImplementation,
|
|
74
77
|
'move.block': moveBlockActionImplementation,
|
|
78
|
+
'move.forward': moveForwardActionImplementation,
|
|
75
79
|
'noop': noopActionImplementation,
|
|
76
80
|
'select': selectActionImplementation,
|
|
77
81
|
'split.block': splitBlockActionImplementation,
|
|
@@ -220,6 +224,13 @@ export function performAction({
|
|
|
220
224
|
})
|
|
221
225
|
break
|
|
222
226
|
}
|
|
227
|
+
case 'move.backward': {
|
|
228
|
+
behaviorActionImplementations['move.backward']({
|
|
229
|
+
context,
|
|
230
|
+
action,
|
|
231
|
+
})
|
|
232
|
+
break
|
|
233
|
+
}
|
|
223
234
|
case 'move.block': {
|
|
224
235
|
behaviorActionImplementations['move.block']({
|
|
225
236
|
context,
|
|
@@ -227,6 +238,13 @@ export function performAction({
|
|
|
227
238
|
})
|
|
228
239
|
break
|
|
229
240
|
}
|
|
241
|
+
case 'move.forward': {
|
|
242
|
+
behaviorActionImplementations['move.forward']({
|
|
243
|
+
context,
|
|
244
|
+
action,
|
|
245
|
+
})
|
|
246
|
+
break
|
|
247
|
+
}
|
|
230
248
|
case 'noop': {
|
|
231
249
|
behaviorActionImplementations.noop({
|
|
232
250
|
context,
|
|
@@ -3,7 +3,7 @@ import {createPairRegex} from '../internal-utils/get-text-to-emphasize'
|
|
|
3
3
|
import * as selectors from '../selectors'
|
|
4
4
|
import type {BlockOffset} from '../types/block-offset'
|
|
5
5
|
import * as utils from '../utils'
|
|
6
|
-
import {
|
|
6
|
+
import {effect, execute} from './behavior.types.action'
|
|
7
7
|
import {defineBehavior} from './behavior.types.behavior'
|
|
8
8
|
|
|
9
9
|
export function createDecoratorPairBehavior(config: {
|
|
@@ -160,43 +160,40 @@ export function createDecoratorPairBehavior(config: {
|
|
|
160
160
|
},
|
|
161
161
|
actions: [
|
|
162
162
|
// Insert the text as usual in its own undo step
|
|
163
|
-
({event}) => [event],
|
|
163
|
+
({event}) => [execute(event)],
|
|
164
164
|
(_, {prefixOffsets, suffixOffsets, decorator}) => [
|
|
165
165
|
// Decorate the text between the prefix and suffix
|
|
166
|
-
{
|
|
166
|
+
execute({
|
|
167
167
|
type: 'decorator.add',
|
|
168
168
|
decorator,
|
|
169
169
|
at: {
|
|
170
170
|
anchor: prefixOffsets.focus,
|
|
171
171
|
focus: suffixOffsets.anchor,
|
|
172
172
|
},
|
|
173
|
-
},
|
|
173
|
+
}),
|
|
174
174
|
// Delete the suffix
|
|
175
|
-
|
|
175
|
+
execute({
|
|
176
176
|
type: 'delete.text',
|
|
177
177
|
at: suffixOffsets,
|
|
178
178
|
}),
|
|
179
179
|
// Delete the prefix
|
|
180
|
-
|
|
180
|
+
execute({
|
|
181
181
|
type: 'delete.text',
|
|
182
182
|
at: prefixOffsets,
|
|
183
183
|
}),
|
|
184
184
|
// Toggle the decorator off so the next inserted text isn't emphasized
|
|
185
|
-
{
|
|
185
|
+
execute({
|
|
186
186
|
type: 'decorator.remove',
|
|
187
187
|
decorator,
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
offset
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
})
|
|
198
|
-
},
|
|
199
|
-
},
|
|
188
|
+
}),
|
|
189
|
+
effect(() => {
|
|
190
|
+
config.onDecorate({
|
|
191
|
+
...suffixOffsets.anchor,
|
|
192
|
+
offset:
|
|
193
|
+
suffixOffsets.anchor.offset -
|
|
194
|
+
(prefixOffsets.focus.offset - prefixOffsets.anchor.offset),
|
|
195
|
+
})
|
|
196
|
+
}),
|
|
200
197
|
],
|
|
201
198
|
],
|
|
202
199
|
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {assertEvent, assign, createActor, setup} from 'xstate'
|
|
2
2
|
import {isHotkey} from '../internal-utils/is-hotkey'
|
|
3
3
|
import * as selectors from '../selectors'
|
|
4
|
-
import {
|
|
4
|
+
import {effect, execute, noop} from './behavior.types.action'
|
|
5
5
|
import {defineBehavior} from './behavior.types.behavior'
|
|
6
6
|
|
|
7
7
|
const emojiCharRegEx = /^[a-zA-Z-_0-9]{1}$/
|
|
@@ -118,19 +118,16 @@ export function createEmojiPickerBehaviors<TEmojiMatch>(
|
|
|
118
118
|
},
|
|
119
119
|
actions: [
|
|
120
120
|
() => [
|
|
121
|
-
{
|
|
121
|
+
execute({
|
|
122
122
|
type: 'insert.text',
|
|
123
123
|
text: ':',
|
|
124
|
-
},
|
|
124
|
+
}),
|
|
125
125
|
],
|
|
126
126
|
(_, params) => [
|
|
127
|
-
{
|
|
128
|
-
type: '
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
raise({
|
|
127
|
+
effect(() => {
|
|
128
|
+
emojiPickerActor.send({type: 'select'})
|
|
129
|
+
}),
|
|
130
|
+
execute({
|
|
134
131
|
type: 'delete.text',
|
|
135
132
|
at: {
|
|
136
133
|
anchor: {
|
|
@@ -143,10 +140,10 @@ export function createEmojiPickerBehaviors<TEmojiMatch>(
|
|
|
143
140
|
},
|
|
144
141
|
},
|
|
145
142
|
}),
|
|
146
|
-
{
|
|
143
|
+
execute({
|
|
147
144
|
type: 'insert.text',
|
|
148
145
|
text: params.emoji,
|
|
149
|
-
},
|
|
146
|
+
}),
|
|
150
147
|
],
|
|
151
148
|
],
|
|
152
149
|
}),
|
|
@@ -220,13 +217,10 @@ export function createEmojiPickerBehaviors<TEmojiMatch>(
|
|
|
220
217
|
(_, params) => {
|
|
221
218
|
if (params.action === 'select') {
|
|
222
219
|
return [
|
|
223
|
-
{
|
|
224
|
-
type: '
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
},
|
|
228
|
-
},
|
|
229
|
-
raise({
|
|
220
|
+
effect(() => {
|
|
221
|
+
emojiPickerActor.send({type: 'select'})
|
|
222
|
+
}),
|
|
223
|
+
execute({
|
|
230
224
|
type: 'delete.text',
|
|
231
225
|
at: {
|
|
232
226
|
anchor: {
|
|
@@ -239,10 +233,10 @@ export function createEmojiPickerBehaviors<TEmojiMatch>(
|
|
|
239
233
|
},
|
|
240
234
|
},
|
|
241
235
|
}),
|
|
242
|
-
{
|
|
236
|
+
execute({
|
|
243
237
|
type: 'insert.text',
|
|
244
238
|
text: params.emoji,
|
|
245
|
-
},
|
|
239
|
+
}),
|
|
246
240
|
]
|
|
247
241
|
}
|
|
248
242
|
|
|
@@ -250,15 +244,10 @@ export function createEmojiPickerBehaviors<TEmojiMatch>(
|
|
|
250
244
|
return [
|
|
251
245
|
// If we are navigating then we want to hijack the key event and
|
|
252
246
|
// turn it into a noop.
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
type: 'effect',
|
|
258
|
-
effect: () => {
|
|
259
|
-
emojiPickerActor.send({type: 'navigate up'})
|
|
260
|
-
},
|
|
261
|
-
},
|
|
247
|
+
noop(),
|
|
248
|
+
effect(() => {
|
|
249
|
+
emojiPickerActor.send({type: 'navigate up'})
|
|
250
|
+
}),
|
|
262
251
|
]
|
|
263
252
|
}
|
|
264
253
|
|
|
@@ -266,25 +255,17 @@ export function createEmojiPickerBehaviors<TEmojiMatch>(
|
|
|
266
255
|
return [
|
|
267
256
|
// If we are navigating then we want to hijack the key event and
|
|
268
257
|
// turn it into a noop.
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
type: 'effect',
|
|
274
|
-
effect: () => {
|
|
275
|
-
emojiPickerActor.send({type: 'navigate down'})
|
|
276
|
-
},
|
|
277
|
-
},
|
|
258
|
+
noop(),
|
|
259
|
+
effect(() => {
|
|
260
|
+
emojiPickerActor.send({type: 'navigate down'})
|
|
261
|
+
}),
|
|
278
262
|
]
|
|
279
263
|
}
|
|
280
264
|
|
|
281
265
|
return [
|
|
282
|
-
{
|
|
283
|
-
type: '
|
|
284
|
-
|
|
285
|
-
emojiPickerActor.send({type: 'reset'})
|
|
286
|
-
},
|
|
287
|
-
},
|
|
266
|
+
effect(() => {
|
|
267
|
+
emojiPickerActor.send({type: 'reset'})
|
|
268
|
+
}),
|
|
288
269
|
]
|
|
289
270
|
},
|
|
290
271
|
],
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type {EditorSchema} from '../editor/define-schema'
|
|
2
2
|
import {looksLikeUrl} from '../internal-utils/looks-like-url'
|
|
3
3
|
import * as selectors from '../selectors'
|
|
4
|
+
import {execute} from './behavior.types.action'
|
|
4
5
|
import {defineBehavior} from './behavior.types.behavior'
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -36,10 +37,10 @@ export function createLinkBehaviors(config: LinkBehaviorsConfig) {
|
|
|
36
37
|
},
|
|
37
38
|
actions: [
|
|
38
39
|
(_, {annotation}) => [
|
|
39
|
-
{
|
|
40
|
+
execute({
|
|
40
41
|
type: 'annotation.add',
|
|
41
42
|
annotation,
|
|
42
|
-
},
|
|
43
|
+
}),
|
|
43
44
|
],
|
|
44
45
|
],
|
|
45
46
|
})
|
|
@@ -68,11 +69,11 @@ export function createLinkBehaviors(config: LinkBehaviorsConfig) {
|
|
|
68
69
|
},
|
|
69
70
|
actions: [
|
|
70
71
|
(_, {annotation, url}) => [
|
|
71
|
-
{
|
|
72
|
+
execute({
|
|
72
73
|
type: 'insert.span',
|
|
73
74
|
text: url,
|
|
74
75
|
annotations: [annotation],
|
|
75
|
-
},
|
|
76
|
+
}),
|
|
76
77
|
],
|
|
77
78
|
],
|
|
78
79
|
})
|
|
@@ -3,7 +3,7 @@ import type {EditorSchema} from '../editor/define-schema'
|
|
|
3
3
|
import * as selectors from '../selectors'
|
|
4
4
|
import {spanSelectionPointToBlockOffset} from '../utils/util.block-offset'
|
|
5
5
|
import {getTextBlockText} from '../utils/util.get-text-block-text'
|
|
6
|
-
import {
|
|
6
|
+
import {execute} from './behavior.types.action'
|
|
7
7
|
import {defineBehavior} from './behavior.types.behavior'
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -120,23 +120,23 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
120
120
|
},
|
|
121
121
|
actions: [
|
|
122
122
|
() => [
|
|
123
|
-
{
|
|
123
|
+
execute({
|
|
124
124
|
type: 'insert.text',
|
|
125
125
|
text: ' ',
|
|
126
|
-
},
|
|
126
|
+
}),
|
|
127
127
|
],
|
|
128
128
|
(_, {focusTextBlock, style}) => [
|
|
129
|
-
{
|
|
129
|
+
execute({
|
|
130
130
|
type: 'block.unset',
|
|
131
131
|
props: ['listItem', 'level'],
|
|
132
132
|
at: focusTextBlock.path,
|
|
133
|
-
},
|
|
134
|
-
{
|
|
133
|
+
}),
|
|
134
|
+
execute({
|
|
135
135
|
type: 'block.set',
|
|
136
136
|
props: {style},
|
|
137
137
|
at: focusTextBlock.path,
|
|
138
|
-
},
|
|
139
|
-
|
|
138
|
+
}),
|
|
139
|
+
execute({
|
|
140
140
|
type: 'delete.text',
|
|
141
141
|
at: {
|
|
142
142
|
anchor: {
|
|
@@ -200,21 +200,21 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
200
200
|
},
|
|
201
201
|
actions: [
|
|
202
202
|
(_, {hrCharacter}) => [
|
|
203
|
-
{
|
|
203
|
+
execute({
|
|
204
204
|
type: 'insert.text',
|
|
205
205
|
text: hrCharacter,
|
|
206
|
-
},
|
|
206
|
+
}),
|
|
207
207
|
],
|
|
208
208
|
(_, {hrObject, hrBlockOffsets}) => [
|
|
209
|
-
{
|
|
209
|
+
execute({
|
|
210
210
|
type: 'insert.block',
|
|
211
211
|
placement: 'before',
|
|
212
212
|
block: {
|
|
213
213
|
_type: hrObject.name,
|
|
214
214
|
...(hrObject.value ?? {}),
|
|
215
215
|
},
|
|
216
|
-
},
|
|
217
|
-
|
|
216
|
+
}),
|
|
217
|
+
execute({
|
|
218
218
|
type: 'delete.text',
|
|
219
219
|
at: hrBlockOffsets,
|
|
220
220
|
}),
|
|
@@ -238,41 +238,44 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
238
238
|
},
|
|
239
239
|
actions: [
|
|
240
240
|
(_, {hrCharacters}) => [
|
|
241
|
-
{
|
|
241
|
+
execute({
|
|
242
242
|
type: 'insert.text',
|
|
243
243
|
text: hrCharacters,
|
|
244
|
-
},
|
|
244
|
+
}),
|
|
245
245
|
],
|
|
246
246
|
({snapshot}, {hrObject, focusBlock}) =>
|
|
247
247
|
isPortableTextTextBlock(focusBlock.node)
|
|
248
248
|
? [
|
|
249
|
-
{
|
|
249
|
+
execute({
|
|
250
250
|
type: 'insert.block',
|
|
251
251
|
block: {
|
|
252
252
|
_type: snapshot.context.schema.block.name,
|
|
253
253
|
children: focusBlock.node.children,
|
|
254
254
|
},
|
|
255
255
|
placement: 'after',
|
|
256
|
-
},
|
|
257
|
-
{
|
|
256
|
+
}),
|
|
257
|
+
execute({
|
|
258
258
|
type: 'insert.block',
|
|
259
259
|
block: {
|
|
260
260
|
_type: hrObject.name,
|
|
261
261
|
...(hrObject.value ?? {}),
|
|
262
262
|
},
|
|
263
263
|
placement: 'after',
|
|
264
|
-
},
|
|
265
|
-
{
|
|
264
|
+
}),
|
|
265
|
+
execute({
|
|
266
|
+
type: 'delete.block',
|
|
267
|
+
at: focusBlock.path,
|
|
268
|
+
}),
|
|
266
269
|
]
|
|
267
270
|
: [
|
|
268
|
-
{
|
|
271
|
+
execute({
|
|
269
272
|
type: 'insert.block',
|
|
270
273
|
block: {
|
|
271
274
|
_type: hrObject.name,
|
|
272
275
|
...(hrObject.value ?? {}),
|
|
273
276
|
},
|
|
274
277
|
placement: 'after',
|
|
275
|
-
},
|
|
278
|
+
}),
|
|
276
279
|
],
|
|
277
280
|
],
|
|
278
281
|
})
|
|
@@ -337,19 +340,19 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
337
340
|
return false
|
|
338
341
|
},
|
|
339
342
|
actions: [
|
|
340
|
-
({event}) => [event],
|
|
343
|
+
({event}) => [execute(event)],
|
|
341
344
|
(_, {focusTextBlock, style, level}) => [
|
|
342
|
-
{
|
|
345
|
+
execute({
|
|
343
346
|
type: 'block.unset',
|
|
344
347
|
props: ['listItem', 'level'],
|
|
345
348
|
at: focusTextBlock.path,
|
|
346
|
-
},
|
|
347
|
-
{
|
|
349
|
+
}),
|
|
350
|
+
execute({
|
|
348
351
|
type: 'block.set',
|
|
349
352
|
props: {style},
|
|
350
353
|
at: focusTextBlock.path,
|
|
351
|
-
},
|
|
352
|
-
|
|
354
|
+
}),
|
|
355
|
+
execute({
|
|
353
356
|
type: 'delete.text',
|
|
354
357
|
at: {
|
|
355
358
|
anchor: {
|
|
@@ -394,11 +397,11 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
394
397
|
},
|
|
395
398
|
actions: [
|
|
396
399
|
(_, {defaultStyle, focusTextBlock}) => [
|
|
397
|
-
{
|
|
400
|
+
execute({
|
|
398
401
|
type: 'block.set',
|
|
399
402
|
props: {style: defaultStyle},
|
|
400
403
|
at: focusTextBlock.path,
|
|
401
|
-
},
|
|
404
|
+
}),
|
|
402
405
|
],
|
|
403
406
|
],
|
|
404
407
|
})
|
|
@@ -477,9 +480,9 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
477
480
|
return false
|
|
478
481
|
},
|
|
479
482
|
actions: [
|
|
480
|
-
({event}) => [event],
|
|
483
|
+
({event}) => [execute(event)],
|
|
481
484
|
(_, {focusTextBlock, style, listItem, listItemLength}) => [
|
|
482
|
-
{
|
|
485
|
+
execute({
|
|
483
486
|
type: 'block.set',
|
|
484
487
|
props: {
|
|
485
488
|
listItem,
|
|
@@ -487,8 +490,8 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
487
490
|
style,
|
|
488
491
|
},
|
|
489
492
|
at: focusTextBlock.path,
|
|
490
|
-
},
|
|
491
|
-
|
|
493
|
+
}),
|
|
494
|
+
execute({
|
|
492
495
|
type: 'delete.text',
|
|
493
496
|
at: {
|
|
494
497
|
anchor: {
|