@portabletext/editor 1.43.0 → 1.44.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.markdown.cjs +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +445 -623
- 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 +434 -611
- 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 +1860 -5464
- package/lib/behaviors/index.d.ts +1860 -5464
- package/lib/index.cjs +4 -4
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +1529 -5062
- package/lib/index.d.ts +1529 -5062
- package/lib/index.js +3 -3
- package/lib/plugins/index.cjs +1 -1
- package/lib/plugins/index.d.cts +1529 -5062
- package/lib/plugins/index.d.ts +1529 -5062
- 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 +1508 -5064
- package/lib/selectors/index.d.ts +1508 -5064
- package/lib/selectors/index.js +2 -1
- package/lib/utils/index.d.cts +1491 -5057
- package/lib/utils/index.d.ts +1491 -5057
- package/package.json +1 -1
- package/src/behavior-actions/behavior.actions.ts +1 -131
- package/src/behaviors/behavior.default.ts +47 -50
- 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 +143 -100
- package/src/editor/create-editor.ts +2 -2
- package/src/editor/editor-machine.ts +3 -4
- package/src/editor/plugins/createWithEditableAPI.ts +1 -2
- package/src/editor/sync-machine.ts +1 -1
- 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
package/package.json
CHANGED
|
@@ -19,18 +19,14 @@ import type {PickFromUnion} from '../type-utils'
|
|
|
19
19
|
import {blockSetBehaviorActionImplementation} from './behavior.action.block.set'
|
|
20
20
|
import {blockUnsetBehaviorActionImplementation} from './behavior.action.block.unset'
|
|
21
21
|
import {blurActionImplementation} from './behavior.action.blur'
|
|
22
|
-
import {dataTransferSetActionImplementation} from './behavior.action.data-transfer-set'
|
|
23
22
|
import {decoratorAddActionImplementation} from './behavior.action.decorator.add'
|
|
24
23
|
import {deleteActionImplementation} from './behavior.action.delete'
|
|
25
24
|
import {deleteBackwardActionImplementation} from './behavior.action.delete.backward'
|
|
26
25
|
import {deleteBlockActionImplementation} from './behavior.action.delete.block'
|
|
27
26
|
import {deleteForwardActionImplementation} from './behavior.action.delete.forward'
|
|
28
27
|
import {deleteTextActionImplementation} from './behavior.action.delete.text'
|
|
29
|
-
import {deserializationFailureActionImplementation} from './behavior.action.deserialization.failure'
|
|
30
|
-
import {deserializationSuccessActionImplementation} from './behavior.action.deserialization.success'
|
|
31
28
|
import {effectActionImplementation} from './behavior.action.effect'
|
|
32
29
|
import {focusActionImplementation} from './behavior.action.focus'
|
|
33
|
-
import {insertBlocksActionImplementation} from './behavior.action.insert-blocks'
|
|
34
30
|
import {
|
|
35
31
|
insertBreakActionImplementation,
|
|
36
32
|
insertSoftBreakActionImplementation,
|
|
@@ -39,25 +35,11 @@ import {insertInlineObjectActionImplementation} from './behavior.action.insert-i
|
|
|
39
35
|
import {insertSpanActionImplementation} from './behavior.action.insert-span'
|
|
40
36
|
import {insertBlockActionImplementation} from './behavior.action.insert.block'
|
|
41
37
|
import {insertTextActionImplementation} from './behavior.action.insert.text'
|
|
42
|
-
import {
|
|
43
|
-
addListItemActionImplementation,
|
|
44
|
-
removeListItemActionImplementation,
|
|
45
|
-
toggleListItemActionImplementation,
|
|
46
|
-
} from './behavior.action.list-item'
|
|
47
38
|
import {moveBlockActionImplementation} from './behavior.action.move.block'
|
|
48
39
|
import {moveBlockDownActionImplementation} from './behavior.action.move.block-down'
|
|
49
40
|
import {moveBlockUpActionImplementation} from './behavior.action.move.block-up'
|
|
50
41
|
import {noopActionImplementation} from './behavior.action.noop'
|
|
51
42
|
import {selectActionImplementation} from './behavior.action.select'
|
|
52
|
-
import {selectNextBlockActionImplementation} from './behavior.action.select.next-block'
|
|
53
|
-
import {selectPreviousBlockActionImplementation} from './behavior.action.select.previous-block'
|
|
54
|
-
import {serializationFailureActionImplementation} from './behavior.action.serialization.failure'
|
|
55
|
-
import {serializationSuccessActionImplementation} from './behavior.action.serialization.success'
|
|
56
|
-
import {
|
|
57
|
-
addStyleActionImplementation,
|
|
58
|
-
removeStyleActionImplementation,
|
|
59
|
-
toggleStyleActionImplementation,
|
|
60
|
-
} from './behavior.action.style'
|
|
61
43
|
|
|
62
44
|
const debug = debugWithName('behaviors:action')
|
|
63
45
|
|
|
@@ -88,7 +70,6 @@ const behaviorActionImplementations: BehaviorActionImplementations = {
|
|
|
88
70
|
'block.set': blockSetBehaviorActionImplementation,
|
|
89
71
|
'block.unset': blockUnsetBehaviorActionImplementation,
|
|
90
72
|
'blur': blurActionImplementation,
|
|
91
|
-
'data transfer.set': dataTransferSetActionImplementation,
|
|
92
73
|
'decorator.add': decoratorAddActionImplementation,
|
|
93
74
|
'decorator.remove': removeDecoratorActionImplementation,
|
|
94
75
|
'decorator.toggle': toggleDecoratorActionImplementation,
|
|
@@ -98,33 +79,20 @@ const behaviorActionImplementations: BehaviorActionImplementations = {
|
|
|
98
79
|
'delete.forward': deleteForwardActionImplementation,
|
|
99
80
|
'delete.block': deleteBlockActionImplementation,
|
|
100
81
|
'delete.text': deleteTextActionImplementation,
|
|
101
|
-
'deserialization.failure': deserializationFailureActionImplementation,
|
|
102
|
-
'deserialization.success': deserializationSuccessActionImplementation,
|
|
103
82
|
'history.redo': historyRedoActionImplementation,
|
|
104
83
|
'history.undo': historyUndoActionImplementation,
|
|
105
84
|
'insert.block': insertBlockActionImplementation,
|
|
106
|
-
'insert.blocks': insertBlocksActionImplementation,
|
|
107
85
|
'insert.break': insertBreakActionImplementation,
|
|
108
86
|
'insert.inline object': insertInlineObjectActionImplementation,
|
|
109
87
|
'insert.soft break': insertSoftBreakActionImplementation,
|
|
110
88
|
'insert.span': insertSpanActionImplementation,
|
|
111
89
|
'insert.text': insertTextActionImplementation,
|
|
112
90
|
'effect': effectActionImplementation,
|
|
113
|
-
'list item.add': addListItemActionImplementation,
|
|
114
|
-
'list item.remove': removeListItemActionImplementation,
|
|
115
|
-
'list item.toggle': toggleListItemActionImplementation,
|
|
116
91
|
'move.block': moveBlockActionImplementation,
|
|
117
92
|
'move.block down': moveBlockDownActionImplementation,
|
|
118
93
|
'move.block up': moveBlockUpActionImplementation,
|
|
119
94
|
'noop': noopActionImplementation,
|
|
120
95
|
'select': selectActionImplementation,
|
|
121
|
-
'select.previous block': selectPreviousBlockActionImplementation,
|
|
122
|
-
'select.next block': selectNextBlockActionImplementation,
|
|
123
|
-
'serialization.failure': serializationFailureActionImplementation,
|
|
124
|
-
'serialization.success': serializationSuccessActionImplementation,
|
|
125
|
-
'style.toggle': toggleStyleActionImplementation,
|
|
126
|
-
'style.add': addStyleActionImplementation,
|
|
127
|
-
'style.remove': removeStyleActionImplementation,
|
|
128
96
|
}
|
|
129
97
|
|
|
130
98
|
export function performAction({
|
|
@@ -179,13 +147,6 @@ export function performAction({
|
|
|
179
147
|
})
|
|
180
148
|
break
|
|
181
149
|
}
|
|
182
|
-
case 'data transfer.set': {
|
|
183
|
-
behaviorActionImplementations['data transfer.set']({
|
|
184
|
-
context,
|
|
185
|
-
action,
|
|
186
|
-
})
|
|
187
|
-
break
|
|
188
|
-
}
|
|
189
150
|
case 'decorator.add': {
|
|
190
151
|
behaviorActionImplementations['decorator.add']({
|
|
191
152
|
context,
|
|
@@ -242,20 +203,6 @@ export function performAction({
|
|
|
242
203
|
})
|
|
243
204
|
break
|
|
244
205
|
}
|
|
245
|
-
case 'deserialization.failure': {
|
|
246
|
-
behaviorActionImplementations['deserialization.failure']({
|
|
247
|
-
context,
|
|
248
|
-
action,
|
|
249
|
-
})
|
|
250
|
-
break
|
|
251
|
-
}
|
|
252
|
-
case 'deserialization.success': {
|
|
253
|
-
behaviorActionImplementations['deserialization.success']({
|
|
254
|
-
context,
|
|
255
|
-
action,
|
|
256
|
-
})
|
|
257
|
-
break
|
|
258
|
-
}
|
|
259
206
|
case 'effect': {
|
|
260
207
|
behaviorActionImplementations.effect({
|
|
261
208
|
context,
|
|
@@ -291,13 +238,6 @@ export function performAction({
|
|
|
291
238
|
})
|
|
292
239
|
break
|
|
293
240
|
}
|
|
294
|
-
case 'insert.blocks': {
|
|
295
|
-
behaviorActionImplementations['insert.blocks']({
|
|
296
|
-
context,
|
|
297
|
-
action,
|
|
298
|
-
})
|
|
299
|
-
break
|
|
300
|
-
}
|
|
301
241
|
case 'insert.inline object': {
|
|
302
242
|
behaviorActionImplementations['insert.inline object']({
|
|
303
243
|
context,
|
|
@@ -333,27 +273,6 @@ export function performAction({
|
|
|
333
273
|
})
|
|
334
274
|
break
|
|
335
275
|
}
|
|
336
|
-
case 'list item.add': {
|
|
337
|
-
behaviorActionImplementations['list item.add']({
|
|
338
|
-
context,
|
|
339
|
-
action,
|
|
340
|
-
})
|
|
341
|
-
break
|
|
342
|
-
}
|
|
343
|
-
case 'list item.remove': {
|
|
344
|
-
behaviorActionImplementations['list item.remove']({
|
|
345
|
-
context,
|
|
346
|
-
action,
|
|
347
|
-
})
|
|
348
|
-
break
|
|
349
|
-
}
|
|
350
|
-
case 'list item.toggle': {
|
|
351
|
-
behaviorActionImplementations['list item.toggle']({
|
|
352
|
-
context,
|
|
353
|
-
action,
|
|
354
|
-
})
|
|
355
|
-
break
|
|
356
|
-
}
|
|
357
276
|
case 'move.block': {
|
|
358
277
|
behaviorActionImplementations['move.block']({
|
|
359
278
|
context,
|
|
@@ -382,57 +301,8 @@ export function performAction({
|
|
|
382
301
|
})
|
|
383
302
|
break
|
|
384
303
|
}
|
|
385
|
-
case 'select': {
|
|
386
|
-
behaviorActionImplementations.select({
|
|
387
|
-
context,
|
|
388
|
-
action,
|
|
389
|
-
})
|
|
390
|
-
break
|
|
391
|
-
}
|
|
392
|
-
case 'select.previous block': {
|
|
393
|
-
behaviorActionImplementations['select.previous block']({
|
|
394
|
-
context,
|
|
395
|
-
action,
|
|
396
|
-
})
|
|
397
|
-
break
|
|
398
|
-
}
|
|
399
|
-
case 'select.next block': {
|
|
400
|
-
behaviorActionImplementations['select.next block']({
|
|
401
|
-
context,
|
|
402
|
-
action,
|
|
403
|
-
})
|
|
404
|
-
break
|
|
405
|
-
}
|
|
406
|
-
case 'serialization.failure': {
|
|
407
|
-
behaviorActionImplementations['serialization.failure']({
|
|
408
|
-
context,
|
|
409
|
-
action,
|
|
410
|
-
})
|
|
411
|
-
break
|
|
412
|
-
}
|
|
413
|
-
case 'serialization.success': {
|
|
414
|
-
behaviorActionImplementations['serialization.success']({
|
|
415
|
-
context,
|
|
416
|
-
action,
|
|
417
|
-
})
|
|
418
|
-
break
|
|
419
|
-
}
|
|
420
|
-
case 'style.add': {
|
|
421
|
-
behaviorActionImplementations['style.add']({
|
|
422
|
-
context,
|
|
423
|
-
action,
|
|
424
|
-
})
|
|
425
|
-
break
|
|
426
|
-
}
|
|
427
|
-
case 'style.remove': {
|
|
428
|
-
behaviorActionImplementations['style.remove']({
|
|
429
|
-
context,
|
|
430
|
-
action,
|
|
431
|
-
})
|
|
432
|
-
break
|
|
433
|
-
}
|
|
434
304
|
default: {
|
|
435
|
-
behaviorActionImplementations
|
|
305
|
+
behaviorActionImplementations.select({
|
|
436
306
|
context,
|
|
437
307
|
action,
|
|
438
308
|
})
|
|
@@ -2,6 +2,10 @@ import {isTextBlock} from '../internal-utils/parse-blocks'
|
|
|
2
2
|
import * as selectors from '../selectors'
|
|
3
3
|
import {blockOffsetsToSelection, getTextBlockText} from '../utils'
|
|
4
4
|
import {raiseInsertSoftBreak} from './behavior.default.raise-soft-break'
|
|
5
|
+
import {internalInsertBehaviors} from './behavior.internal.insert'
|
|
6
|
+
import {internalListItemBehaviors} from './behavior.internal.list-item'
|
|
7
|
+
import {internalSelectBehaviors} from './behavior.internal.select'
|
|
8
|
+
import {internalStyleBehaviors} from './behavior.internal.style'
|
|
5
9
|
import {raise} from './behavior.types.action'
|
|
6
10
|
import {defineBehavior} from './behavior.types.behavior'
|
|
7
11
|
|
|
@@ -70,46 +74,6 @@ const toggleDecoratorOn = defineBehavior({
|
|
|
70
74
|
],
|
|
71
75
|
})
|
|
72
76
|
|
|
73
|
-
const toggleListItemOff = defineBehavior({
|
|
74
|
-
on: 'list item.toggle',
|
|
75
|
-
guard: ({snapshot, event}) =>
|
|
76
|
-
selectors.isActiveListItem(event.listItem)(snapshot),
|
|
77
|
-
actions: [
|
|
78
|
-
({event}) => [
|
|
79
|
-
raise({
|
|
80
|
-
type: 'list item.remove',
|
|
81
|
-
listItem: event.listItem,
|
|
82
|
-
}),
|
|
83
|
-
],
|
|
84
|
-
],
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
const toggleListItemOn = defineBehavior({
|
|
88
|
-
on: 'list item.toggle',
|
|
89
|
-
guard: ({snapshot, event}) =>
|
|
90
|
-
!selectors.isActiveListItem(event.listItem)(snapshot),
|
|
91
|
-
actions: [
|
|
92
|
-
({event}) => [
|
|
93
|
-
raise({
|
|
94
|
-
type: 'list item.add',
|
|
95
|
-
listItem: event.listItem,
|
|
96
|
-
}),
|
|
97
|
-
],
|
|
98
|
-
],
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
const toggleStyleOff = defineBehavior({
|
|
102
|
-
on: 'style.toggle',
|
|
103
|
-
guard: ({snapshot, event}) => selectors.isActiveStyle(event.style)(snapshot),
|
|
104
|
-
actions: [({event}) => [raise({type: 'style.remove', style: event.style})]],
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
const toggleStyleOn = defineBehavior({
|
|
108
|
-
on: 'style.toggle',
|
|
109
|
-
guard: ({snapshot, event}) => !selectors.isActiveStyle(event.style)(snapshot),
|
|
110
|
-
actions: [({event}) => [raise({type: 'style.add', style: event.style})]],
|
|
111
|
-
})
|
|
112
|
-
|
|
113
77
|
const raiseDeserializationSuccessOrFailure = defineBehavior({
|
|
114
78
|
on: 'deserialize',
|
|
115
79
|
guard: ({snapshot, event}) => {
|
|
@@ -265,12 +229,30 @@ export const defaultBehaviors = [
|
|
|
265
229
|
on: 'serialization.success',
|
|
266
230
|
actions: [
|
|
267
231
|
({event}) => [
|
|
268
|
-
|
|
269
|
-
type: '
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
232
|
+
{
|
|
233
|
+
type: 'effect',
|
|
234
|
+
effect: () => {
|
|
235
|
+
event.originEvent.originEvent.dataTransfer.setData(
|
|
236
|
+
event.mimeType,
|
|
237
|
+
event.data,
|
|
238
|
+
)
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
],
|
|
242
|
+
],
|
|
243
|
+
}),
|
|
244
|
+
defineBehavior({
|
|
245
|
+
on: 'serialization.failure',
|
|
246
|
+
actions: [
|
|
247
|
+
({event}) => [
|
|
248
|
+
{
|
|
249
|
+
type: 'effect',
|
|
250
|
+
effect: () => {
|
|
251
|
+
console.warn(
|
|
252
|
+
`Serialization of ${event.mimeType} failed with reason "${event.reason}"`,
|
|
253
|
+
)
|
|
254
|
+
},
|
|
255
|
+
},
|
|
274
256
|
],
|
|
275
257
|
],
|
|
276
258
|
}),
|
|
@@ -465,6 +447,21 @@ export const defaultBehaviors = [
|
|
|
465
447
|
],
|
|
466
448
|
],
|
|
467
449
|
}),
|
|
450
|
+
defineBehavior({
|
|
451
|
+
on: 'deserialization.failure',
|
|
452
|
+
actions: [
|
|
453
|
+
({event}) => [
|
|
454
|
+
{
|
|
455
|
+
type: 'effect',
|
|
456
|
+
effect: () => {
|
|
457
|
+
console.warn(
|
|
458
|
+
`Deserialization of ${event.mimeType} failed with reason "${event.reason}"`,
|
|
459
|
+
)
|
|
460
|
+
},
|
|
461
|
+
},
|
|
462
|
+
],
|
|
463
|
+
],
|
|
464
|
+
}),
|
|
468
465
|
defineBehavior({
|
|
469
466
|
on: 'clipboard.paste',
|
|
470
467
|
guard: ({snapshot}) => {
|
|
@@ -508,14 +505,14 @@ export const defaultBehaviors = [
|
|
|
508
505
|
],
|
|
509
506
|
],
|
|
510
507
|
}),
|
|
508
|
+
...internalInsertBehaviors,
|
|
509
|
+
...internalListItemBehaviors,
|
|
510
|
+
...internalStyleBehaviors,
|
|
511
|
+
...internalSelectBehaviors,
|
|
511
512
|
toggleAnnotationOff,
|
|
512
513
|
toggleAnnotationOn,
|
|
513
514
|
toggleDecoratorOff,
|
|
514
515
|
toggleDecoratorOn,
|
|
515
|
-
toggleListItemOff,
|
|
516
|
-
toggleListItemOn,
|
|
517
|
-
toggleStyleOff,
|
|
518
|
-
toggleStyleOn,
|
|
519
516
|
raiseDeserializationSuccessOrFailure,
|
|
520
517
|
raiseSerializationSuccessOrFailure,
|
|
521
518
|
raiseInsertSoftBreak,
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import {getFocusTextBlock} from '../selectors'
|
|
2
|
+
import {raise} from './behavior.types.action'
|
|
3
|
+
import {defineBehavior} from './behavior.types.behavior'
|
|
4
|
+
|
|
5
|
+
export const internalInsertBehaviors = [
|
|
6
|
+
defineBehavior({
|
|
7
|
+
on: 'insert.blocks',
|
|
8
|
+
guard: ({event}) => event.placement === 'before',
|
|
9
|
+
actions: [
|
|
10
|
+
({event}) =>
|
|
11
|
+
event.blocks.map((block, index) =>
|
|
12
|
+
raise({
|
|
13
|
+
type: 'insert.block',
|
|
14
|
+
block,
|
|
15
|
+
placement: index === 0 ? 'before' : 'after',
|
|
16
|
+
select: 'end',
|
|
17
|
+
}),
|
|
18
|
+
),
|
|
19
|
+
],
|
|
20
|
+
}),
|
|
21
|
+
defineBehavior({
|
|
22
|
+
on: 'insert.blocks',
|
|
23
|
+
guard: ({event}) => event.placement === 'after',
|
|
24
|
+
actions: [
|
|
25
|
+
({event}) =>
|
|
26
|
+
event.blocks.map((block) =>
|
|
27
|
+
raise({
|
|
28
|
+
type: 'insert.block',
|
|
29
|
+
block,
|
|
30
|
+
placement: 'after',
|
|
31
|
+
select: 'end',
|
|
32
|
+
}),
|
|
33
|
+
),
|
|
34
|
+
],
|
|
35
|
+
}),
|
|
36
|
+
defineBehavior({
|
|
37
|
+
on: 'insert.blocks',
|
|
38
|
+
guard: ({snapshot, event}) => {
|
|
39
|
+
if (event.placement !== 'auto') {
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const focusTextBlock = getFocusTextBlock(snapshot)
|
|
44
|
+
|
|
45
|
+
if (!focusTextBlock) {
|
|
46
|
+
return false
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return true
|
|
50
|
+
},
|
|
51
|
+
actions: [
|
|
52
|
+
({event}) =>
|
|
53
|
+
event.blocks.length === 1
|
|
54
|
+
? [
|
|
55
|
+
raise({
|
|
56
|
+
type: 'insert.block',
|
|
57
|
+
block: event.blocks[0],
|
|
58
|
+
placement: 'auto',
|
|
59
|
+
select: 'end',
|
|
60
|
+
}),
|
|
61
|
+
]
|
|
62
|
+
: event.blocks.flatMap((block, index) =>
|
|
63
|
+
index === 0
|
|
64
|
+
? [
|
|
65
|
+
raise({
|
|
66
|
+
type: 'insert.break',
|
|
67
|
+
}),
|
|
68
|
+
raise({
|
|
69
|
+
type: 'select.previous block',
|
|
70
|
+
select: 'end',
|
|
71
|
+
}),
|
|
72
|
+
raise({
|
|
73
|
+
type: 'insert.block',
|
|
74
|
+
block,
|
|
75
|
+
placement: 'auto',
|
|
76
|
+
select: 'end',
|
|
77
|
+
}),
|
|
78
|
+
]
|
|
79
|
+
: index === event.blocks.length - 1
|
|
80
|
+
? [
|
|
81
|
+
raise({
|
|
82
|
+
type: 'select.next block',
|
|
83
|
+
select: 'start',
|
|
84
|
+
}),
|
|
85
|
+
raise({
|
|
86
|
+
type: 'insert.block',
|
|
87
|
+
block,
|
|
88
|
+
placement: 'auto',
|
|
89
|
+
select: 'end',
|
|
90
|
+
}),
|
|
91
|
+
]
|
|
92
|
+
: [
|
|
93
|
+
raise({
|
|
94
|
+
type: 'insert.block',
|
|
95
|
+
block,
|
|
96
|
+
placement: 'after',
|
|
97
|
+
select: 'end',
|
|
98
|
+
}),
|
|
99
|
+
],
|
|
100
|
+
),
|
|
101
|
+
],
|
|
102
|
+
}),
|
|
103
|
+
defineBehavior({
|
|
104
|
+
on: 'insert.blocks',
|
|
105
|
+
guard: ({event}) => event.placement === 'auto',
|
|
106
|
+
actions: [
|
|
107
|
+
({event}) =>
|
|
108
|
+
event.blocks.map((block, index) =>
|
|
109
|
+
raise({
|
|
110
|
+
type: 'insert.block',
|
|
111
|
+
block,
|
|
112
|
+
placement: index === 0 ? 'auto' : 'after',
|
|
113
|
+
select: 'end',
|
|
114
|
+
}),
|
|
115
|
+
),
|
|
116
|
+
],
|
|
117
|
+
}),
|
|
118
|
+
]
|
|
@@ -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
|
+
]
|