@portabletext/editor 1.24.0 → 1.25.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 +186 -62
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/{selector.is-selection-collapsed.cjs → selector.is-active-style.cjs} +158 -3
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -0
- package/lib/_chunks-es/behavior.core.js +162 -38
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/{selector.is-selection-collapsed.js → selector.is-active-style.js} +159 -4
- package/lib/_chunks-es/selector.is-active-style.js.map +1 -0
- package/lib/behaviors/index.cjs +27 -27
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +1718 -94
- package/lib/behaviors/index.d.ts +1718 -94
- package/lib/behaviors/index.js +1 -1
- package/lib/index.cjs +178 -211
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +8792 -245
- package/lib/index.d.ts +8792 -245
- package/lib/index.js +174 -207
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.cjs +24 -171
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.js +3 -151
- package/lib/selectors/index.js.map +1 -1
- package/package.json +6 -6
- package/src/behavior-actions/behavior.actions.ts +99 -98
- package/src/behaviors/behavior.core.annotations.ts +29 -0
- package/src/behaviors/behavior.core.block-objects.ts +13 -13
- package/src/behaviors/behavior.core.decorators.ts +19 -0
- package/src/behaviors/behavior.core.lists.ts +57 -23
- package/src/behaviors/behavior.core.style.ts +19 -0
- package/src/behaviors/behavior.core.ts +12 -0
- package/src/behaviors/behavior.types.ts +87 -87
- package/src/editor/create-editor.ts +46 -6
- package/src/editor/editor-machine.ts +38 -1
- package/src/editor/plugins/create-with-event-listeners.ts +38 -106
- package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs.map +0 -1
- package/lib/_chunks-es/selector.is-selection-collapsed.js.map +0 -1
|
@@ -308,312 +308,313 @@ export function performAction({
|
|
|
308
308
|
action: BehaviorAction
|
|
309
309
|
}) {
|
|
310
310
|
switch (action.type) {
|
|
311
|
-
case '
|
|
312
|
-
behaviorActionImplementations
|
|
311
|
+
case 'noop': {
|
|
312
|
+
behaviorActionImplementations.noop({
|
|
313
313
|
context,
|
|
314
314
|
action,
|
|
315
315
|
})
|
|
316
316
|
break
|
|
317
317
|
}
|
|
318
|
-
case '
|
|
319
|
-
behaviorActionImplementations
|
|
318
|
+
case 'effect': {
|
|
319
|
+
behaviorActionImplementations.effect({
|
|
320
320
|
context,
|
|
321
321
|
action,
|
|
322
322
|
})
|
|
323
323
|
break
|
|
324
324
|
}
|
|
325
|
-
case '
|
|
326
|
-
behaviorActionImplementations
|
|
325
|
+
case 'select': {
|
|
326
|
+
behaviorActionImplementations.select({
|
|
327
327
|
context,
|
|
328
328
|
action,
|
|
329
329
|
})
|
|
330
330
|
break
|
|
331
331
|
}
|
|
332
|
-
|
|
333
|
-
|
|
332
|
+
default: {
|
|
333
|
+
performDefaultAction({context, action})
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function performDefaultAction({
|
|
339
|
+
context,
|
|
340
|
+
action,
|
|
341
|
+
}: {
|
|
342
|
+
context: BehaviorActionImplementationContext
|
|
343
|
+
action: PickFromUnion<BehaviorAction, 'type', SyntheticBehaviorEvent['type']>
|
|
344
|
+
}) {
|
|
345
|
+
switch (action.type) {
|
|
346
|
+
case 'annotation.add': {
|
|
347
|
+
behaviorActionImplementations['annotation.add']({
|
|
334
348
|
context,
|
|
335
349
|
action,
|
|
336
350
|
})
|
|
337
351
|
break
|
|
338
352
|
}
|
|
339
|
-
case '
|
|
340
|
-
behaviorActionImplementations['
|
|
353
|
+
case 'annotation.remove': {
|
|
354
|
+
behaviorActionImplementations['annotation.remove']({
|
|
341
355
|
context,
|
|
342
356
|
action,
|
|
343
357
|
})
|
|
344
358
|
break
|
|
345
359
|
}
|
|
346
|
-
case '
|
|
347
|
-
behaviorActionImplementations['
|
|
360
|
+
case 'annotation.toggle': {
|
|
361
|
+
behaviorActionImplementations['annotation.toggle']({
|
|
348
362
|
context,
|
|
349
363
|
action,
|
|
350
364
|
})
|
|
351
365
|
break
|
|
352
366
|
}
|
|
353
|
-
case '
|
|
354
|
-
behaviorActionImplementations
|
|
367
|
+
case 'blur': {
|
|
368
|
+
behaviorActionImplementations.blur({
|
|
355
369
|
context,
|
|
356
370
|
action,
|
|
357
371
|
})
|
|
358
372
|
break
|
|
359
373
|
}
|
|
360
|
-
case '
|
|
361
|
-
behaviorActionImplementations['
|
|
374
|
+
case 'data transfer.set': {
|
|
375
|
+
behaviorActionImplementations['data transfer.set']({
|
|
362
376
|
context,
|
|
363
377
|
action,
|
|
364
378
|
})
|
|
365
379
|
break
|
|
366
380
|
}
|
|
367
|
-
case '
|
|
368
|
-
behaviorActionImplementations['
|
|
381
|
+
case 'decorator.add': {
|
|
382
|
+
behaviorActionImplementations['decorator.add']({
|
|
369
383
|
context,
|
|
370
384
|
action,
|
|
371
385
|
})
|
|
372
386
|
break
|
|
373
387
|
}
|
|
374
|
-
case '
|
|
375
|
-
behaviorActionImplementations['
|
|
388
|
+
case 'decorator.remove': {
|
|
389
|
+
behaviorActionImplementations['decorator.remove']({
|
|
376
390
|
context,
|
|
377
391
|
action,
|
|
378
392
|
})
|
|
379
393
|
break
|
|
380
394
|
}
|
|
381
|
-
case '
|
|
382
|
-
behaviorActionImplementations['
|
|
395
|
+
case 'decorator.toggle': {
|
|
396
|
+
behaviorActionImplementations['decorator.toggle']({
|
|
383
397
|
context,
|
|
384
398
|
action,
|
|
385
399
|
})
|
|
386
400
|
break
|
|
387
401
|
}
|
|
388
|
-
case '
|
|
389
|
-
behaviorActionImplementations['
|
|
402
|
+
case 'delete.backward': {
|
|
403
|
+
behaviorActionImplementations['delete.backward']({
|
|
390
404
|
context,
|
|
391
405
|
action,
|
|
392
406
|
})
|
|
393
407
|
break
|
|
394
408
|
}
|
|
395
|
-
case '
|
|
396
|
-
behaviorActionImplementations.
|
|
409
|
+
case 'delete.block': {
|
|
410
|
+
behaviorActionImplementations['delete.block']({
|
|
397
411
|
context,
|
|
398
412
|
action,
|
|
399
413
|
})
|
|
400
414
|
break
|
|
401
415
|
}
|
|
402
|
-
case '
|
|
403
|
-
behaviorActionImplementations.
|
|
416
|
+
case 'delete.forward': {
|
|
417
|
+
behaviorActionImplementations['delete.forward']({
|
|
404
418
|
context,
|
|
405
419
|
action,
|
|
406
420
|
})
|
|
407
421
|
break
|
|
408
422
|
}
|
|
409
|
-
case '
|
|
410
|
-
behaviorActionImplementations.
|
|
423
|
+
case 'delete.text': {
|
|
424
|
+
behaviorActionImplementations['delete.text']({
|
|
411
425
|
context,
|
|
412
426
|
action,
|
|
413
427
|
})
|
|
414
428
|
break
|
|
415
429
|
}
|
|
416
|
-
case '
|
|
417
|
-
behaviorActionImplementations['
|
|
430
|
+
case 'deserialization.failure': {
|
|
431
|
+
behaviorActionImplementations['deserialization.failure']({
|
|
418
432
|
context,
|
|
419
433
|
action,
|
|
420
434
|
})
|
|
421
435
|
break
|
|
422
436
|
}
|
|
423
|
-
case '
|
|
424
|
-
behaviorActionImplementations['
|
|
437
|
+
case 'deserialization.success': {
|
|
438
|
+
behaviorActionImplementations['deserialization.success']({
|
|
425
439
|
context,
|
|
426
440
|
action,
|
|
427
441
|
})
|
|
428
442
|
break
|
|
429
443
|
}
|
|
430
|
-
case '
|
|
431
|
-
behaviorActionImplementations
|
|
444
|
+
case 'focus': {
|
|
445
|
+
behaviorActionImplementations.focus({
|
|
432
446
|
context,
|
|
433
447
|
action,
|
|
434
448
|
})
|
|
435
449
|
break
|
|
436
450
|
}
|
|
437
|
-
case '
|
|
438
|
-
behaviorActionImplementations['
|
|
451
|
+
case 'insert.blocks': {
|
|
452
|
+
behaviorActionImplementations['insert.blocks']({
|
|
439
453
|
context,
|
|
440
454
|
action,
|
|
441
455
|
})
|
|
442
456
|
break
|
|
443
457
|
}
|
|
444
|
-
case '
|
|
445
|
-
behaviorActionImplementations['
|
|
458
|
+
case 'insert.block object': {
|
|
459
|
+
behaviorActionImplementations['insert.block object']({
|
|
446
460
|
context,
|
|
447
461
|
action,
|
|
448
462
|
})
|
|
449
463
|
break
|
|
450
464
|
}
|
|
451
|
-
case '
|
|
452
|
-
behaviorActionImplementations['
|
|
465
|
+
case 'insert.inline object': {
|
|
466
|
+
behaviorActionImplementations['insert.inline object']({
|
|
453
467
|
context,
|
|
454
468
|
action,
|
|
455
469
|
})
|
|
456
470
|
break
|
|
457
471
|
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
function performDefaultAction({
|
|
465
|
-
context,
|
|
466
|
-
action,
|
|
467
|
-
}: {
|
|
468
|
-
context: BehaviorActionImplementationContext
|
|
469
|
-
action: PickFromUnion<BehaviorAction, 'type', SyntheticBehaviorEvent['type']>
|
|
470
|
-
}) {
|
|
471
|
-
switch (action.type) {
|
|
472
|
-
case 'annotation.add': {
|
|
473
|
-
behaviorActionImplementations['annotation.add']({
|
|
472
|
+
case 'insert.break': {
|
|
473
|
+
behaviorActionImplementations['insert.break']({
|
|
474
474
|
context,
|
|
475
475
|
action,
|
|
476
476
|
})
|
|
477
477
|
break
|
|
478
478
|
}
|
|
479
|
-
case '
|
|
480
|
-
behaviorActionImplementations['
|
|
479
|
+
case 'insert.soft break': {
|
|
480
|
+
behaviorActionImplementations['insert.soft break']({
|
|
481
481
|
context,
|
|
482
482
|
action,
|
|
483
483
|
})
|
|
484
484
|
break
|
|
485
485
|
}
|
|
486
|
-
case '
|
|
487
|
-
behaviorActionImplementations.
|
|
486
|
+
case 'insert.span': {
|
|
487
|
+
behaviorActionImplementations['insert.span']({
|
|
488
488
|
context,
|
|
489
489
|
action,
|
|
490
490
|
})
|
|
491
491
|
break
|
|
492
492
|
}
|
|
493
|
-
case '
|
|
494
|
-
behaviorActionImplementations['
|
|
493
|
+
case 'insert.text': {
|
|
494
|
+
behaviorActionImplementations['insert.text']({
|
|
495
495
|
context,
|
|
496
496
|
action,
|
|
497
497
|
})
|
|
498
498
|
break
|
|
499
499
|
}
|
|
500
|
-
case '
|
|
501
|
-
behaviorActionImplementations['
|
|
500
|
+
case 'insert.text block': {
|
|
501
|
+
behaviorActionImplementations['insert.text block']({
|
|
502
502
|
context,
|
|
503
503
|
action,
|
|
504
504
|
})
|
|
505
505
|
break
|
|
506
506
|
}
|
|
507
|
-
case '
|
|
508
|
-
behaviorActionImplementations['
|
|
507
|
+
case 'list item.add': {
|
|
508
|
+
behaviorActionImplementations['list item.add']({
|
|
509
509
|
context,
|
|
510
510
|
action,
|
|
511
511
|
})
|
|
512
512
|
break
|
|
513
513
|
}
|
|
514
|
-
case '
|
|
515
|
-
behaviorActionImplementations['
|
|
514
|
+
case 'list item.remove': {
|
|
515
|
+
behaviorActionImplementations['list item.remove']({
|
|
516
516
|
context,
|
|
517
517
|
action,
|
|
518
518
|
})
|
|
519
519
|
break
|
|
520
520
|
}
|
|
521
|
-
case '
|
|
522
|
-
behaviorActionImplementations['
|
|
521
|
+
case 'list item.toggle': {
|
|
522
|
+
behaviorActionImplementations['list item.toggle']({
|
|
523
523
|
context,
|
|
524
524
|
action,
|
|
525
525
|
})
|
|
526
526
|
break
|
|
527
527
|
}
|
|
528
|
-
case '
|
|
529
|
-
behaviorActionImplementations['
|
|
528
|
+
case 'move.block': {
|
|
529
|
+
behaviorActionImplementations['move.block']({
|
|
530
530
|
context,
|
|
531
531
|
action,
|
|
532
532
|
})
|
|
533
533
|
break
|
|
534
534
|
}
|
|
535
|
-
case '
|
|
536
|
-
behaviorActionImplementations.
|
|
535
|
+
case 'move.block down': {
|
|
536
|
+
behaviorActionImplementations['move.block down']({
|
|
537
537
|
context,
|
|
538
538
|
action,
|
|
539
539
|
})
|
|
540
540
|
break
|
|
541
541
|
}
|
|
542
|
-
case '
|
|
543
|
-
behaviorActionImplementations['
|
|
542
|
+
case 'move.block up': {
|
|
543
|
+
behaviorActionImplementations['move.block up']({
|
|
544
544
|
context,
|
|
545
545
|
action,
|
|
546
546
|
})
|
|
547
547
|
break
|
|
548
548
|
}
|
|
549
|
-
case '
|
|
550
|
-
behaviorActionImplementations
|
|
549
|
+
case 'select': {
|
|
550
|
+
behaviorActionImplementations.select({
|
|
551
551
|
context,
|
|
552
552
|
action,
|
|
553
553
|
})
|
|
554
554
|
break
|
|
555
555
|
}
|
|
556
|
-
case '
|
|
557
|
-
behaviorActionImplementations['
|
|
556
|
+
case 'select.previous block': {
|
|
557
|
+
behaviorActionImplementations['select.previous block']({
|
|
558
558
|
context,
|
|
559
559
|
action,
|
|
560
560
|
})
|
|
561
561
|
break
|
|
562
562
|
}
|
|
563
|
-
case '
|
|
564
|
-
behaviorActionImplementations['
|
|
563
|
+
case 'select.next block': {
|
|
564
|
+
behaviorActionImplementations['select.next block']({
|
|
565
565
|
context,
|
|
566
566
|
action,
|
|
567
567
|
})
|
|
568
568
|
break
|
|
569
569
|
}
|
|
570
|
-
case '
|
|
571
|
-
behaviorActionImplementations['
|
|
570
|
+
case 'serialization.failure': {
|
|
571
|
+
behaviorActionImplementations['serialization.failure']({
|
|
572
572
|
context,
|
|
573
573
|
action,
|
|
574
574
|
})
|
|
575
575
|
break
|
|
576
576
|
}
|
|
577
|
-
case '
|
|
578
|
-
behaviorActionImplementations['
|
|
577
|
+
case 'serialization.success': {
|
|
578
|
+
behaviorActionImplementations['serialization.success']({
|
|
579
579
|
context,
|
|
580
580
|
action,
|
|
581
581
|
})
|
|
582
582
|
break
|
|
583
583
|
}
|
|
584
|
-
case '
|
|
585
|
-
behaviorActionImplementations['
|
|
584
|
+
case 'style.add': {
|
|
585
|
+
behaviorActionImplementations['style.add']({
|
|
586
586
|
context,
|
|
587
587
|
action,
|
|
588
588
|
})
|
|
589
589
|
break
|
|
590
590
|
}
|
|
591
|
-
case '
|
|
592
|
-
behaviorActionImplementations.
|
|
591
|
+
case 'style.remove': {
|
|
592
|
+
behaviorActionImplementations['style.remove']({
|
|
593
593
|
context,
|
|
594
594
|
action,
|
|
595
595
|
})
|
|
596
596
|
break
|
|
597
597
|
}
|
|
598
|
-
case '
|
|
599
|
-
behaviorActionImplementations['
|
|
598
|
+
case 'style.toggle': {
|
|
599
|
+
behaviorActionImplementations['style.toggle']({
|
|
600
600
|
context,
|
|
601
601
|
action,
|
|
602
602
|
})
|
|
603
603
|
break
|
|
604
604
|
}
|
|
605
|
-
case '
|
|
606
|
-
behaviorActionImplementations['
|
|
605
|
+
case 'text block.set': {
|
|
606
|
+
behaviorActionImplementations['text block.set']({
|
|
607
607
|
context,
|
|
608
608
|
action,
|
|
609
609
|
})
|
|
610
610
|
break
|
|
611
611
|
}
|
|
612
|
-
|
|
613
|
-
behaviorActionImplementations['
|
|
612
|
+
case 'text block.unset': {
|
|
613
|
+
behaviorActionImplementations['text block.unset']({
|
|
614
614
|
context,
|
|
615
615
|
action,
|
|
616
616
|
})
|
|
617
|
+
break
|
|
617
618
|
}
|
|
618
619
|
}
|
|
619
620
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as selectors from '../selectors'
|
|
2
|
+
import {defineBehavior, raise} from './behavior.types'
|
|
3
|
+
|
|
4
|
+
const toggleAnnotationOff = defineBehavior({
|
|
5
|
+
on: 'annotation.toggle',
|
|
6
|
+
guard: ({context, event}) =>
|
|
7
|
+
selectors.isActiveAnnotation(event.annotation.name)({context}),
|
|
8
|
+
actions: [
|
|
9
|
+
({event}) => [
|
|
10
|
+
raise({type: 'annotation.remove', annotation: event.annotation}),
|
|
11
|
+
],
|
|
12
|
+
],
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const toggleAnnotationOn = defineBehavior({
|
|
16
|
+
on: 'annotation.toggle',
|
|
17
|
+
guard: ({context, event}) =>
|
|
18
|
+
!selectors.isActiveAnnotation(event.annotation.name)({context}),
|
|
19
|
+
actions: [
|
|
20
|
+
({event}) => [
|
|
21
|
+
raise({type: 'annotation.add', annotation: event.annotation}),
|
|
22
|
+
],
|
|
23
|
+
],
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
export const coreAnnotationBehaviors = {
|
|
27
|
+
toggleAnnotationOff,
|
|
28
|
+
toggleAnnotationOn,
|
|
29
|
+
}
|
|
@@ -2,7 +2,7 @@ import {isPortableTextTextBlock} from '@sanity/types'
|
|
|
2
2
|
import {isHotkey} from '../internal-utils/is-hotkey'
|
|
3
3
|
import * as selectors from '../selectors'
|
|
4
4
|
import {isEmptyTextBlock} from '../utils/util.is-empty-text-block'
|
|
5
|
-
import {defineBehavior} from './behavior.types'
|
|
5
|
+
import {defineBehavior, raise} from './behavior.types'
|
|
6
6
|
|
|
7
7
|
const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
8
8
|
on: 'key.down',
|
|
@@ -13,7 +13,7 @@ const arrowDownOnLonelyBlockObject = defineBehavior({
|
|
|
13
13
|
|
|
14
14
|
return isArrowDown && focusBlockObject && !nextBlock
|
|
15
15
|
},
|
|
16
|
-
actions: [() => [{type: 'insert.text block', placement: 'after'}]],
|
|
16
|
+
actions: [() => [raise({type: 'insert.text block', placement: 'after'})]],
|
|
17
17
|
})
|
|
18
18
|
|
|
19
19
|
const arrowUpOnLonelyBlockObject = defineBehavior({
|
|
@@ -27,8 +27,8 @@ const arrowUpOnLonelyBlockObject = defineBehavior({
|
|
|
27
27
|
},
|
|
28
28
|
actions: [
|
|
29
29
|
() => [
|
|
30
|
-
{type: 'insert.text block', placement: 'before'},
|
|
31
|
-
{type: 'select.previous block'},
|
|
30
|
+
raise({type: 'insert.text block', placement: 'before'}),
|
|
31
|
+
raise({type: 'select.previous block'}),
|
|
32
32
|
],
|
|
33
33
|
],
|
|
34
34
|
})
|
|
@@ -41,7 +41,7 @@ const breakingBlockObject = defineBehavior({
|
|
|
41
41
|
|
|
42
42
|
return collapsedSelection && focusBlockObject !== undefined
|
|
43
43
|
},
|
|
44
|
-
actions: [() => [{type: 'insert.text block', placement: 'after'}]],
|
|
44
|
+
actions: [() => [raise({type: 'insert.text block', placement: 'after'})]],
|
|
45
45
|
})
|
|
46
46
|
|
|
47
47
|
const deletingEmptyTextBlockAfterBlockObject = defineBehavior({
|
|
@@ -66,17 +66,17 @@ const deletingEmptyTextBlockAfterBlockObject = defineBehavior({
|
|
|
66
66
|
},
|
|
67
67
|
actions: [
|
|
68
68
|
(_, {focusTextBlock, previousBlock}) => [
|
|
69
|
-
{
|
|
69
|
+
raise({
|
|
70
70
|
type: 'delete.block',
|
|
71
71
|
blockPath: focusTextBlock.path,
|
|
72
|
-
},
|
|
73
|
-
{
|
|
72
|
+
}),
|
|
73
|
+
raise({
|
|
74
74
|
type: 'select',
|
|
75
75
|
selection: {
|
|
76
76
|
anchor: {path: previousBlock.path, offset: 0},
|
|
77
77
|
focus: {path: previousBlock.path, offset: 0},
|
|
78
78
|
},
|
|
79
|
-
},
|
|
79
|
+
}),
|
|
80
80
|
],
|
|
81
81
|
],
|
|
82
82
|
})
|
|
@@ -103,17 +103,17 @@ const deletingEmptyTextBlockBeforeBlockObject = defineBehavior({
|
|
|
103
103
|
},
|
|
104
104
|
actions: [
|
|
105
105
|
(_, {focusTextBlock, nextBlock}) => [
|
|
106
|
-
{
|
|
106
|
+
raise({
|
|
107
107
|
type: 'delete.block',
|
|
108
108
|
blockPath: focusTextBlock.path,
|
|
109
|
-
},
|
|
110
|
-
{
|
|
109
|
+
}),
|
|
110
|
+
raise({
|
|
111
111
|
type: 'select',
|
|
112
112
|
selection: {
|
|
113
113
|
anchor: {path: nextBlock.path, offset: 0},
|
|
114
114
|
focus: {path: nextBlock.path, offset: 0},
|
|
115
115
|
},
|
|
116
|
-
},
|
|
116
|
+
}),
|
|
117
117
|
],
|
|
118
118
|
],
|
|
119
119
|
})
|
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
import {isHotkey} from '../internal-utils/is-hotkey'
|
|
2
|
+
import * as selectors from '../selectors'
|
|
2
3
|
import {defineBehavior, raise} from './behavior.types'
|
|
3
4
|
|
|
4
5
|
export const coreDecoratorBehaviors = {
|
|
6
|
+
toggleDecoratorOff: defineBehavior({
|
|
7
|
+
on: 'decorator.toggle',
|
|
8
|
+
guard: ({context, event}) =>
|
|
9
|
+
selectors.isActiveDecorator(event.decorator)({context}),
|
|
10
|
+
actions: [
|
|
11
|
+
({event}) => [
|
|
12
|
+
raise({type: 'decorator.remove', decorator: event.decorator}),
|
|
13
|
+
],
|
|
14
|
+
],
|
|
15
|
+
}),
|
|
16
|
+
toggleDecoratorOn: defineBehavior({
|
|
17
|
+
on: 'decorator.toggle',
|
|
18
|
+
guard: ({context, event}) =>
|
|
19
|
+
!selectors.isActiveDecorator(event.decorator)({context}),
|
|
20
|
+
actions: [
|
|
21
|
+
({event}) => [raise({type: 'decorator.add', decorator: event.decorator})],
|
|
22
|
+
],
|
|
23
|
+
}),
|
|
5
24
|
strongShortcut: defineBehavior({
|
|
6
25
|
on: 'key.down',
|
|
7
26
|
guard: ({context, event}) =>
|
|
@@ -2,10 +2,38 @@ import {createGuards} from '../behavior-actions/behavior.guards'
|
|
|
2
2
|
import {isHotkey} from '../internal-utils/is-hotkey'
|
|
3
3
|
import * as selectors from '../selectors'
|
|
4
4
|
import {isEmptyTextBlock} from '../utils/util.is-empty-text-block'
|
|
5
|
-
import {defineBehavior} from './behavior.types'
|
|
5
|
+
import {defineBehavior, raise} from './behavior.types'
|
|
6
6
|
|
|
7
7
|
const MAX_LIST_LEVEL = 10
|
|
8
8
|
|
|
9
|
+
const toggleListItemOff = defineBehavior({
|
|
10
|
+
on: 'list item.toggle',
|
|
11
|
+
guard: ({context, event}) =>
|
|
12
|
+
selectors.isActiveListItem(event.listItem)({context}),
|
|
13
|
+
actions: [
|
|
14
|
+
({event}) => [
|
|
15
|
+
raise({
|
|
16
|
+
type: 'list item.remove',
|
|
17
|
+
listItem: event.listItem,
|
|
18
|
+
}),
|
|
19
|
+
],
|
|
20
|
+
],
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const toggleListItemOn = defineBehavior({
|
|
24
|
+
on: 'list item.toggle',
|
|
25
|
+
guard: ({context, event}) =>
|
|
26
|
+
!selectors.isActiveListItem(event.listItem)({context}),
|
|
27
|
+
actions: [
|
|
28
|
+
({event}) => [
|
|
29
|
+
raise({
|
|
30
|
+
type: 'list item.add',
|
|
31
|
+
listItem: event.listItem,
|
|
32
|
+
}),
|
|
33
|
+
],
|
|
34
|
+
],
|
|
35
|
+
})
|
|
36
|
+
|
|
9
37
|
const clearListOnBackspace = defineBehavior({
|
|
10
38
|
on: 'delete.backward',
|
|
11
39
|
guard: ({context}) => {
|
|
@@ -29,11 +57,11 @@ const clearListOnBackspace = defineBehavior({
|
|
|
29
57
|
},
|
|
30
58
|
actions: [
|
|
31
59
|
(_, {focusTextBlock}) => [
|
|
32
|
-
{
|
|
60
|
+
raise({
|
|
33
61
|
type: 'text block.unset',
|
|
34
62
|
props: ['listItem', 'level'],
|
|
35
63
|
at: focusTextBlock.path,
|
|
36
|
-
},
|
|
64
|
+
}),
|
|
37
65
|
],
|
|
38
66
|
],
|
|
39
67
|
})
|
|
@@ -65,11 +93,11 @@ const unindentListOnBackspace = defineBehavior({
|
|
|
65
93
|
},
|
|
66
94
|
actions: [
|
|
67
95
|
(_, {focusTextBlock, level}) => [
|
|
68
|
-
{
|
|
96
|
+
raise({
|
|
69
97
|
type: 'text block.set',
|
|
70
98
|
level,
|
|
71
99
|
at: focusTextBlock.path,
|
|
72
|
-
},
|
|
100
|
+
}),
|
|
73
101
|
],
|
|
74
102
|
],
|
|
75
103
|
})
|
|
@@ -92,11 +120,11 @@ const clearListOnEnter = defineBehavior({
|
|
|
92
120
|
},
|
|
93
121
|
actions: [
|
|
94
122
|
(_, {focusListBlock}) => [
|
|
95
|
-
{
|
|
123
|
+
raise({
|
|
96
124
|
type: 'text block.unset',
|
|
97
125
|
props: ['listItem', 'level'],
|
|
98
126
|
at: focusListBlock.path,
|
|
99
|
-
},
|
|
127
|
+
}),
|
|
100
128
|
],
|
|
101
129
|
],
|
|
102
130
|
})
|
|
@@ -131,14 +159,16 @@ const indentListOnTab = defineBehavior({
|
|
|
131
159
|
},
|
|
132
160
|
actions: [
|
|
133
161
|
(_, {selectedListBlocks}) =>
|
|
134
|
-
selectedListBlocks.map((selectedListBlock) =>
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
162
|
+
selectedListBlocks.map((selectedListBlock) =>
|
|
163
|
+
raise({
|
|
164
|
+
type: 'text block.set',
|
|
165
|
+
level: Math.min(
|
|
166
|
+
MAX_LIST_LEVEL,
|
|
167
|
+
Math.max(1, selectedListBlock.node.level + 1),
|
|
168
|
+
),
|
|
169
|
+
at: selectedListBlock.path,
|
|
170
|
+
}),
|
|
171
|
+
),
|
|
142
172
|
],
|
|
143
173
|
})
|
|
144
174
|
|
|
@@ -172,18 +202,22 @@ const unindentListOnShiftTab = defineBehavior({
|
|
|
172
202
|
},
|
|
173
203
|
actions: [
|
|
174
204
|
(_, {selectedListBlocks}) =>
|
|
175
|
-
selectedListBlocks.map((selectedListBlock) =>
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
205
|
+
selectedListBlocks.map((selectedListBlock) =>
|
|
206
|
+
raise({
|
|
207
|
+
type: 'text block.set',
|
|
208
|
+
level: Math.min(
|
|
209
|
+
MAX_LIST_LEVEL,
|
|
210
|
+
Math.max(1, selectedListBlock.node.level - 1),
|
|
211
|
+
),
|
|
212
|
+
at: selectedListBlock.path,
|
|
213
|
+
}),
|
|
214
|
+
),
|
|
183
215
|
],
|
|
184
216
|
})
|
|
185
217
|
|
|
186
218
|
export const coreListBehaviors = {
|
|
219
|
+
toggleListItemOff,
|
|
220
|
+
toggleListItemOn,
|
|
187
221
|
clearListOnBackspace,
|
|
188
222
|
unindentListOnBackspace,
|
|
189
223
|
clearListOnEnter,
|