@portabletext/editor 3.3.2 → 3.3.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-dts/index.d.ts +7 -1
- package/package.json +16 -19
- package/src/behaviors/_exports/index.ts +0 -1
- package/src/behaviors/behavior.abstract.annotation.ts +0 -77
- package/src/behaviors/behavior.abstract.decorator.ts +0 -39
- package/src/behaviors/behavior.abstract.delete.ts +0 -273
- package/src/behaviors/behavior.abstract.deserialize.ts +0 -232
- package/src/behaviors/behavior.abstract.insert.ts +0 -525
- package/src/behaviors/behavior.abstract.keyboard.ts +0 -189
- package/src/behaviors/behavior.abstract.list-item.ts +0 -70
- package/src/behaviors/behavior.abstract.move.ts +0 -79
- package/src/behaviors/behavior.abstract.select.ts +0 -118
- package/src/behaviors/behavior.abstract.serialize.ts +0 -96
- package/src/behaviors/behavior.abstract.split.ts +0 -170
- package/src/behaviors/behavior.abstract.style.ts +0 -55
- package/src/behaviors/behavior.abstract.ts +0 -139
- package/src/behaviors/behavior.config.ts +0 -7
- package/src/behaviors/behavior.core.annotations.ts +0 -62
- package/src/behaviors/behavior.core.block-element.ts +0 -116
- package/src/behaviors/behavior.core.block-objects.ts +0 -285
- package/src/behaviors/behavior.core.decorators.ts +0 -44
- package/src/behaviors/behavior.core.dnd.ts +0 -356
- package/src/behaviors/behavior.core.insert-break.ts +0 -266
- package/src/behaviors/behavior.core.insert.ts +0 -52
- package/src/behaviors/behavior.core.lists.ts +0 -691
- package/src/behaviors/behavior.core.ts +0 -44
- package/src/behaviors/behavior.perform-event.ts +0 -354
- package/src/behaviors/behavior.types.action.ts +0 -102
- package/src/behaviors/behavior.types.behavior.ts +0 -83
- package/src/behaviors/behavior.types.event.ts +0 -667
- package/src/behaviors/behavior.types.guard.ts +0 -11
- package/src/behaviors/index.ts +0 -17
- package/src/converters/converter.json.ts +0 -53
- package/src/converters/converter.portable-text.deserialize.test.ts +0 -680
- package/src/converters/converter.portable-text.ts +0 -75
- package/src/converters/converter.text-html.deserialize.test.ts +0 -406
- package/src/converters/converter.text-html.serialize.test.ts +0 -246
- package/src/converters/converter.text-html.ts +0 -87
- package/src/converters/converter.text-markdown.ts +0 -67
- package/src/converters/converter.text-plain.test.ts +0 -245
- package/src/converters/converter.text-plain.ts +0 -126
- package/src/converters/converter.types.ts +0 -72
- package/src/converters/converters.core.ts +0 -18
- package/src/editor/Editable.tsx +0 -1012
- package/src/editor/PortableTextEditor.tsx +0 -791
- package/src/editor/components/drop-indicator.tsx +0 -17
- package/src/editor/components/render-block-object.tsx +0 -121
- package/src/editor/components/render-default-object.tsx +0 -21
- package/src/editor/components/render-element.tsx +0 -88
- package/src/editor/components/render-inline-object.tsx +0 -129
- package/src/editor/components/render-leaf.tsx +0 -64
- package/src/editor/components/render-span.tsx +0 -303
- package/src/editor/components/render-text-block.tsx +0 -265
- package/src/editor/components/render-text.tsx +0 -18
- package/src/editor/components/use-core-block-element-behaviors.ts +0 -39
- package/src/editor/create-editor.ts +0 -323
- package/src/editor/create-slate-editor.tsx +0 -64
- package/src/editor/editor-actor-context.ts +0 -4
- package/src/editor/editor-context.tsx +0 -7
- package/src/editor/editor-dom.ts +0 -220
- package/src/editor/editor-machine.ts +0 -751
- package/src/editor/editor-provider.tsx +0 -111
- package/src/editor/editor-schema.ts +0 -6
- package/src/editor/editor-selector.ts +0 -89
- package/src/editor/editor-snapshot.ts +0 -68
- package/src/editor/event-to-change.tsx +0 -49
- package/src/editor/hooks/usePortableTextEditor.ts +0 -25
- package/src/editor/hooks/usePortableTextEditorSelection.tsx +0 -28
- package/src/editor/mutation-machine.ts +0 -322
- package/src/editor/plugins/create-with-event-listeners.ts +0 -271
- package/src/editor/plugins/createWithEditableAPI.ts +0 -529
- package/src/editor/plugins/createWithHotKeys.ts +0 -68
- package/src/editor/plugins/createWithObjectKeys.ts +0 -289
- package/src/editor/plugins/createWithPatches.ts +0 -272
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +0 -559
- package/src/editor/plugins/createWithSchemaTypes.ts +0 -121
- package/src/editor/plugins/slate-plugin.update-selection.ts +0 -51
- package/src/editor/plugins/slate-plugin.update-value.ts +0 -46
- package/src/editor/plugins/with-plugins.ts +0 -69
- package/src/editor/range-decorations-machine.ts +0 -421
- package/src/editor/relay-actor-context.ts +0 -4
- package/src/editor/relay-machine.ts +0 -152
- package/src/editor/sync-machine.ts +0 -961
- package/src/editor/use-editor.ts +0 -27
- package/src/editor/validate-selection-machine.test.ts +0 -47
- package/src/editor/validate-selection-machine.ts +0 -149
- package/src/editor/weakMaps.ts +0 -15
- package/src/editor/with-normalizing-node.ts +0 -14
- package/src/editor/with-performing-behavior-operation.ts +0 -21
- package/src/editor/withChanges.ts +0 -13
- package/src/editor/without-normalizing-conditional.ts +0 -13
- package/src/editor/withoutPatching.ts +0 -14
- package/src/editor.ts +0 -59
- package/src/history/behavior.operation.history.redo.ts +0 -67
- package/src/history/behavior.operation.history.undo.ts +0 -71
- package/src/history/event.history.undo.test.tsx +0 -672
- package/src/history/history.preserving-keys.test.tsx +0 -112
- package/src/history/remote-patches.ts +0 -20
- package/src/history/slate-plugin.history.ts +0 -142
- package/src/history/slate-plugin.redoing.ts +0 -21
- package/src/history/slate-plugin.undoing.ts +0 -21
- package/src/history/slate-plugin.without-history.ts +0 -23
- package/src/history/transform-operation.ts +0 -245
- package/src/history/undo-redo-collaboration.test.tsx +0 -541
- package/src/history/undo-redo.feature +0 -125
- package/src/history/undo-redo.test.tsx +0 -195
- package/src/history/undo-step.ts +0 -148
- package/src/index.ts +0 -98
- package/src/internal-utils/__tests__/ranges.test.ts +0 -23
- package/src/internal-utils/__tests__/values.test.ts +0 -110
- package/src/internal-utils/apply-operation-to-portable-text.test.ts +0 -1861
- package/src/internal-utils/apply-operation-to-portable-text.ts +0 -615
- package/src/internal-utils/applyPatch.ts +0 -644
- package/src/internal-utils/block-keys.ts +0 -9
- package/src/internal-utils/build-index-maps.test.ts +0 -464
- package/src/internal-utils/build-index-maps.ts +0 -131
- package/src/internal-utils/collapse-selection.ts +0 -36
- package/src/internal-utils/compound-client-rect.ts +0 -28
- package/src/internal-utils/create-placeholder-block.ts +0 -21
- package/src/internal-utils/create-test-snapshot.ts +0 -28
- package/src/internal-utils/debug.ts +0 -12
- package/src/internal-utils/editor-selection.test.ts +0 -44
- package/src/internal-utils/editor-selection.ts +0 -56
- package/src/internal-utils/event-position.ts +0 -318
- package/src/internal-utils/global-scope.ts +0 -27
- package/src/internal-utils/globally-scoped-context.ts +0 -39
- package/src/internal-utils/is-hotkey.test.ts +0 -114
- package/src/internal-utils/is-hotkey.ts +0 -209
- package/src/internal-utils/mime-type.ts +0 -1
- package/src/internal-utils/move-range-by-operation.ts +0 -19
- package/src/internal-utils/operation-to-patches.test.ts +0 -522
- package/src/internal-utils/operation-to-patches.ts +0 -571
- package/src/internal-utils/portable-text-node.ts +0 -209
- package/src/internal-utils/schema.ts +0 -8
- package/src/internal-utils/selection-block-keys.ts +0 -20
- package/src/internal-utils/selection-focus-text.ts +0 -40
- package/src/internal-utils/selection-text.test.ts +0 -32
- package/src/internal-utils/selection-text.ts +0 -21
- package/src/internal-utils/selection.ts +0 -77
- package/src/internal-utils/sibling-utils.ts +0 -55
- package/src/internal-utils/slate-utils.test.tsx +0 -121
- package/src/internal-utils/slate-utils.ts +0 -417
- package/src/internal-utils/split-string.ts +0 -12
- package/src/internal-utils/stop-actor.ts +0 -43
- package/src/internal-utils/string-overlap.test.ts +0 -14
- package/src/internal-utils/string-overlap.ts +0 -28
- package/src/internal-utils/string-utils.ts +0 -7
- package/src/internal-utils/text-block-key.test.ts +0 -41
- package/src/internal-utils/text-block-key.ts +0 -26
- package/src/internal-utils/text-marks.test.ts +0 -41
- package/src/internal-utils/text-marks.ts +0 -22
- package/src/internal-utils/text-selection.test.ts +0 -211
- package/src/internal-utils/text-selection.ts +0 -121
- package/src/internal-utils/to-slate-range.test.ts +0 -278
- package/src/internal-utils/to-slate-range.ts +0 -171
- package/src/internal-utils/validateValue.ts +0 -443
- package/src/internal-utils/value-annotations.ts +0 -33
- package/src/internal-utils/values.test.ts +0 -282
- package/src/internal-utils/values.ts +0 -266
- package/src/keyboard-shortcuts/default-keyboard-shortcuts.ts +0 -146
- package/src/operations/behavior.operation.annotation.add.ts +0 -99
- package/src/operations/behavior.operation.annotation.remove.ts +0 -150
- package/src/operations/behavior.operation.block.set.ts +0 -104
- package/src/operations/behavior.operation.block.unset.ts +0 -54
- package/src/operations/behavior.operation.child.set.ts +0 -107
- package/src/operations/behavior.operation.child.unset.ts +0 -116
- package/src/operations/behavior.operation.decorator.add.ts +0 -131
- package/src/operations/behavior.operation.delete.ts +0 -294
- package/src/operations/behavior.operation.insert.block.ts +0 -495
- package/src/operations/behavior.operation.insert.child.ts +0 -129
- package/src/operations/behavior.operation.insert.text.ts +0 -8
- package/src/operations/behavior.operation.move.backward.ts +0 -12
- package/src/operations/behavior.operation.move.block.ts +0 -44
- package/src/operations/behavior.operation.move.forward.ts +0 -11
- package/src/operations/behavior.operation.select.ts +0 -27
- package/src/operations/behavior.operations.ts +0 -221
- package/src/plugins/_exports/index.ts +0 -1
- package/src/plugins/index.ts +0 -3
- package/src/plugins/plugin.behavior.tsx +0 -24
- package/src/plugins/plugin.editor-ref.tsx +0 -17
- package/src/plugins/plugin.event-listener.tsx +0 -68
- package/src/plugins/plugin.internal.auto-close-brackets.test.tsx +0 -71
- package/src/plugins/plugin.internal.auto-close-brackets.ts +0 -62
- package/src/plugins/plugin.internal.change-ref.tsx +0 -19
- package/src/plugins/plugin.internal.portable-text-editor-ref.tsx +0 -16
- package/src/plugins/plugin.internal.slate-editor-ref.tsx +0 -15
- package/src/priority/priority.core.ts +0 -3
- package/src/priority/priority.sort.test.ts +0 -319
- package/src/priority/priority.sort.ts +0 -123
- package/src/priority/priority.types.ts +0 -24
- package/src/selectors/_exports/index.ts +0 -1
- package/src/selectors/drag-selection.test.ts +0 -578
- package/src/selectors/drag-selection.ts +0 -118
- package/src/selectors/index.ts +0 -54
- package/src/selectors/selector.get-active-annotation-marks.ts +0 -12
- package/src/selectors/selector.get-active-annotations.ts +0 -36
- package/src/selectors/selector.get-active-decorators.ts +0 -29
- package/src/selectors/selector.get-active-list-item.ts +0 -38
- package/src/selectors/selector.get-active-style.ts +0 -38
- package/src/selectors/selector.get-anchor-block.ts +0 -22
- package/src/selectors/selector.get-anchor-child.ts +0 -36
- package/src/selectors/selector.get-anchor-span.ts +0 -17
- package/src/selectors/selector.get-anchor-text-block.ts +0 -18
- package/src/selectors/selector.get-block-offsets.ts +0 -34
- package/src/selectors/selector.get-caret-word-selection.test.ts +0 -284
- package/src/selectors/selector.get-caret-word-selection.ts +0 -134
- package/src/selectors/selector.get-first-block.ts +0 -14
- package/src/selectors/selector.get-focus-block-object.ts +0 -18
- package/src/selectors/selector.get-focus-block.ts +0 -23
- package/src/selectors/selector.get-focus-child.ts +0 -36
- package/src/selectors/selector.get-focus-inline-object.ts +0 -17
- package/src/selectors/selector.get-focus-list-block.ts +0 -18
- package/src/selectors/selector.get-focus-span.ts +0 -18
- package/src/selectors/selector.get-focus-text-block.ts +0 -18
- package/src/selectors/selector.get-last-block.ts +0 -16
- package/src/selectors/selector.get-mark-state.test.ts +0 -325
- package/src/selectors/selector.get-mark-state.ts +0 -263
- package/src/selectors/selector.get-next-block.ts +0 -29
- package/src/selectors/selector.get-next-inline-object.ts +0 -53
- package/src/selectors/selector.get-next-inline-objects.ts +0 -50
- package/src/selectors/selector.get-next-span.ts +0 -56
- package/src/selectors/selector.get-previous-block.ts +0 -29
- package/src/selectors/selector.get-previous-inline-object.ts +0 -50
- package/src/selectors/selector.get-previous-inline-objects.ts +0 -47
- package/src/selectors/selector.get-previous-span.ts +0 -53
- package/src/selectors/selector.get-selected-blocks.ts +0 -61
- package/src/selectors/selector.get-selected-spans.test.ts +0 -347
- package/src/selectors/selector.get-selected-spans.ts +0 -155
- package/src/selectors/selector.get-selected-text-blocks.ts +0 -73
- package/src/selectors/selector.get-selected-value.test.ts +0 -834
- package/src/selectors/selector.get-selected-value.ts +0 -66
- package/src/selectors/selector.get-selection-end-block.ts +0 -33
- package/src/selectors/selector.get-selection-end-child.ts +0 -33
- package/src/selectors/selector.get-selection-end-point.ts +0 -17
- package/src/selectors/selector.get-selection-start-block.ts +0 -33
- package/src/selectors/selector.get-selection-start-child.ts +0 -33
- package/src/selectors/selector.get-selection-start-point.ts +0 -17
- package/src/selectors/selector.get-selection-text.test.ts +0 -421
- package/src/selectors/selector.get-selection-text.ts +0 -27
- package/src/selectors/selector.get-selection.ts +0 -9
- package/src/selectors/selector.get-text-after.ts +0 -46
- package/src/selectors/selector.get-text-before.ts +0 -46
- package/src/selectors/selector.get-value.ts +0 -11
- package/src/selectors/selector.is-active-annotation.test.ts +0 -320
- package/src/selectors/selector.is-active-annotation.ts +0 -52
- package/src/selectors/selector.is-active-decorator.test.ts +0 -136
- package/src/selectors/selector.is-active-decorator.ts +0 -24
- package/src/selectors/selector.is-active-list-item.ts +0 -13
- package/src/selectors/selector.is-active-style.ts +0 -13
- package/src/selectors/selector.is-at-the-end-of-block.ts +0 -30
- package/src/selectors/selector.is-at-the-start-of-block.ts +0 -30
- package/src/selectors/selector.is-overlapping-selection.test.ts +0 -304
- package/src/selectors/selector.is-overlapping-selection.ts +0 -181
- package/src/selectors/selector.is-point-after-selection.ts +0 -97
- package/src/selectors/selector.is-point-before-selection.ts +0 -97
- package/src/selectors/selector.is-selecting-entire-blocks.ts +0 -43
- package/src/selectors/selector.is-selection-collapsed.ts +0 -17
- package/src/selectors/selector.is-selection-expanded.test.ts +0 -63
- package/src/selectors/selector.is-selection-expanded.ts +0 -9
- package/src/test/_exports/index.ts +0 -1
- package/src/test/gherkin-parameter-types.ts +0 -112
- package/src/test/index.ts +0 -1
- package/src/test/vitest/_exports/index.ts +0 -1
- package/src/test/vitest/index.ts +0 -3
- package/src/test/vitest/step-context.ts +0 -13
- package/src/test/vitest/step-definitions.tsx +0 -960
- package/src/test/vitest/test-editor.tsx +0 -198
- package/src/type-utils.ts +0 -29
- package/src/types/block-offset.ts +0 -9
- package/src/types/block-with-optional-key.ts +0 -25
- package/src/types/editor.ts +0 -509
- package/src/types/options.ts +0 -13
- package/src/types/paths.ts +0 -35
- package/src/types/slate-editor.ts +0 -50
- package/src/types/slate.ts +0 -27
- package/src/utils/_exports/index.ts +0 -1
- package/src/utils/asserters.ts +0 -9
- package/src/utils/index.ts +0 -24
- package/src/utils/key-generator.ts +0 -33
- package/src/utils/parse-blocks.test.ts +0 -836
- package/src/utils/parse-blocks.ts +0 -504
- package/src/utils/util.at-the-beginning-of-block.ts +0 -32
- package/src/utils/util.block-offset-to-block-selection-point.ts +0 -28
- package/src/utils/util.block-offset-to-selection-point.ts +0 -33
- package/src/utils/util.block-offset.test.ts +0 -375
- package/src/utils/util.block-offset.ts +0 -136
- package/src/utils/util.block-offsets-to-selection.ts +0 -38
- package/src/utils/util.child-selection-point-to-block-offset.ts +0 -51
- package/src/utils/util.get-block-end-point.ts +0 -35
- package/src/utils/util.get-block-start-point.ts +0 -31
- package/src/utils/util.get-selection-end-point.ts +0 -20
- package/src/utils/util.get-selection-start-point.ts +0 -20
- package/src/utils/util.get-text-block-text.ts +0 -8
- package/src/utils/util.is-empty-text-block.ts +0 -21
- package/src/utils/util.is-equal-selection-points.ts +0 -13
- package/src/utils/util.is-equal-selections.ts +0 -20
- package/src/utils/util.is-keyed-segment.ts +0 -8
- package/src/utils/util.is-selection-collapsed.ts +0 -16
- package/src/utils/util.is-selection-expanded.ts +0 -13
- package/src/utils/util.merge-text-blocks.ts +0 -40
- package/src/utils/util.reverse-selection.ts +0 -26
- package/src/utils/util.selection-point-to-block-offset.ts +0 -30
- package/src/utils/util.selection-point.ts +0 -22
- package/src/utils/util.slice-blocks.ts +0 -221
- package/src/utils/util.slice-text-block.test.ts +0 -190
- package/src/utils/util.slice-text-block.ts +0 -89
- package/src/utils/util.split-text-block.ts +0 -54
|
@@ -1,525 +0,0 @@
|
|
|
1
|
-
import {isSelectionExpanded} from '../selectors'
|
|
2
|
-
import {getFocusTextBlock} from '../selectors/selector.get-focus-text-block'
|
|
3
|
-
import {getLastBlock} from '../selectors/selector.get-last-block'
|
|
4
|
-
import {getBlockEndPoint} from '../utils/util.get-block-end-point'
|
|
5
|
-
import {getBlockStartPoint} from '../utils/util.get-block-start-point'
|
|
6
|
-
import {isEmptyTextBlock} from '../utils/util.is-empty-text-block'
|
|
7
|
-
import {isEqualSelectionPoints} from '../utils/util.is-equal-selection-points'
|
|
8
|
-
import {sliceTextBlock} from '../utils/util.slice-text-block'
|
|
9
|
-
import {raise} from './behavior.types.action'
|
|
10
|
-
import {defineBehavior} from './behavior.types.behavior'
|
|
11
|
-
|
|
12
|
-
export const abstractInsertBehaviors = [
|
|
13
|
-
defineBehavior({
|
|
14
|
-
on: 'insert.blocks',
|
|
15
|
-
guard: ({event}) => {
|
|
16
|
-
const onlyBlock =
|
|
17
|
-
event.blocks.length === 1 ? event.blocks.at(0) : undefined
|
|
18
|
-
|
|
19
|
-
if (!onlyBlock) {
|
|
20
|
-
return false
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return {onlyBlock}
|
|
24
|
-
},
|
|
25
|
-
actions: [
|
|
26
|
-
({event}, {onlyBlock}) => [
|
|
27
|
-
raise({
|
|
28
|
-
type: 'insert.block',
|
|
29
|
-
block: onlyBlock,
|
|
30
|
-
placement: event.placement,
|
|
31
|
-
select: event.select ?? 'end',
|
|
32
|
-
}),
|
|
33
|
-
],
|
|
34
|
-
],
|
|
35
|
-
}),
|
|
36
|
-
defineBehavior({
|
|
37
|
-
on: 'insert.blocks',
|
|
38
|
-
guard: ({snapshot, event}) => {
|
|
39
|
-
if (event.placement !== 'before') {
|
|
40
|
-
return false
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const firstBlockKey =
|
|
44
|
-
event.blocks.at(0)?._key ?? snapshot.context.keyGenerator()
|
|
45
|
-
const lastBlockKey =
|
|
46
|
-
event.blocks.at(-1)?._key ?? snapshot.context.keyGenerator()
|
|
47
|
-
|
|
48
|
-
return {firstBlockKey, lastBlockKey}
|
|
49
|
-
},
|
|
50
|
-
actions: [
|
|
51
|
-
({snapshot, event}, {firstBlockKey, lastBlockKey}) => [
|
|
52
|
-
...event.blocks.map((block, index) =>
|
|
53
|
-
raise({
|
|
54
|
-
type: 'insert.block',
|
|
55
|
-
block,
|
|
56
|
-
placement: index === 0 ? 'before' : 'after',
|
|
57
|
-
select: index !== event.blocks.length - 1 ? 'end' : 'none',
|
|
58
|
-
}),
|
|
59
|
-
),
|
|
60
|
-
...(event.select === 'none'
|
|
61
|
-
? [
|
|
62
|
-
raise({
|
|
63
|
-
type: 'select',
|
|
64
|
-
at: snapshot.context.selection,
|
|
65
|
-
}),
|
|
66
|
-
]
|
|
67
|
-
: event.select === 'start'
|
|
68
|
-
? [
|
|
69
|
-
raise({
|
|
70
|
-
type: 'select.block',
|
|
71
|
-
at: [{_key: firstBlockKey}],
|
|
72
|
-
select: 'start',
|
|
73
|
-
}),
|
|
74
|
-
]
|
|
75
|
-
: [
|
|
76
|
-
raise({
|
|
77
|
-
type: 'select.block',
|
|
78
|
-
at: [{_key: lastBlockKey}],
|
|
79
|
-
select: 'end',
|
|
80
|
-
}),
|
|
81
|
-
]),
|
|
82
|
-
],
|
|
83
|
-
],
|
|
84
|
-
}),
|
|
85
|
-
defineBehavior({
|
|
86
|
-
on: 'insert.blocks',
|
|
87
|
-
guard: ({snapshot, event}) => {
|
|
88
|
-
if (event.placement !== 'after') {
|
|
89
|
-
return false
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const firstBlockKey =
|
|
93
|
-
event.blocks.at(0)?._key ?? snapshot.context.keyGenerator()
|
|
94
|
-
const lastBlockKey =
|
|
95
|
-
event.blocks.at(-1)?._key ?? snapshot.context.keyGenerator()
|
|
96
|
-
|
|
97
|
-
return {firstBlockKey, lastBlockKey}
|
|
98
|
-
},
|
|
99
|
-
actions: [
|
|
100
|
-
({snapshot, event}, {firstBlockKey, lastBlockKey}) => [
|
|
101
|
-
...event.blocks.map((block, index) =>
|
|
102
|
-
raise({
|
|
103
|
-
type: 'insert.block',
|
|
104
|
-
block,
|
|
105
|
-
placement: 'after',
|
|
106
|
-
select: index !== event.blocks.length - 1 ? 'end' : 'none',
|
|
107
|
-
}),
|
|
108
|
-
),
|
|
109
|
-
...(event.select === 'none'
|
|
110
|
-
? [
|
|
111
|
-
raise({
|
|
112
|
-
type: 'select',
|
|
113
|
-
at: snapshot.context.selection,
|
|
114
|
-
}),
|
|
115
|
-
]
|
|
116
|
-
: event.select === 'start'
|
|
117
|
-
? [
|
|
118
|
-
raise({
|
|
119
|
-
type: 'select.block',
|
|
120
|
-
at: [{_key: firstBlockKey}],
|
|
121
|
-
select: 'start',
|
|
122
|
-
}),
|
|
123
|
-
]
|
|
124
|
-
: [
|
|
125
|
-
raise({
|
|
126
|
-
type: 'select.block',
|
|
127
|
-
at: [{_key: lastBlockKey}],
|
|
128
|
-
select: 'end',
|
|
129
|
-
}),
|
|
130
|
-
]),
|
|
131
|
-
],
|
|
132
|
-
],
|
|
133
|
-
}),
|
|
134
|
-
defineBehavior({
|
|
135
|
-
on: 'insert.blocks',
|
|
136
|
-
guard: ({snapshot, event}) => {
|
|
137
|
-
if (event.placement !== 'auto') {
|
|
138
|
-
return false
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const focusTextBlock = getFocusTextBlock(snapshot)
|
|
142
|
-
|
|
143
|
-
if (!focusTextBlock) {
|
|
144
|
-
return false
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (!isEmptyTextBlock(snapshot.context, focusTextBlock.node)) {
|
|
148
|
-
return false
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const firstBlockKey =
|
|
152
|
-
event.blocks.at(0)?._key ?? snapshot.context.keyGenerator()
|
|
153
|
-
const lastBlockKey =
|
|
154
|
-
event.blocks.at(-1)?._key ?? snapshot.context.keyGenerator()
|
|
155
|
-
|
|
156
|
-
return {focusTextBlock, firstBlockKey, lastBlockKey}
|
|
157
|
-
},
|
|
158
|
-
actions: [
|
|
159
|
-
({event}, {firstBlockKey, lastBlockKey}) => [
|
|
160
|
-
...event.blocks.map((block, index) =>
|
|
161
|
-
raise({
|
|
162
|
-
type: 'insert.block',
|
|
163
|
-
block,
|
|
164
|
-
placement: index === 0 ? 'auto' : 'after',
|
|
165
|
-
select: index !== event.blocks.length - 1 ? 'end' : 'none',
|
|
166
|
-
}),
|
|
167
|
-
),
|
|
168
|
-
...(event.select === 'none' || event.select === 'start'
|
|
169
|
-
? [
|
|
170
|
-
raise({
|
|
171
|
-
type: 'select.block',
|
|
172
|
-
at: [{_key: firstBlockKey}],
|
|
173
|
-
select: 'start',
|
|
174
|
-
}),
|
|
175
|
-
]
|
|
176
|
-
: [
|
|
177
|
-
raise({
|
|
178
|
-
type: 'select.block',
|
|
179
|
-
at: [{_key: lastBlockKey}],
|
|
180
|
-
select: 'end',
|
|
181
|
-
}),
|
|
182
|
-
]),
|
|
183
|
-
],
|
|
184
|
-
],
|
|
185
|
-
}),
|
|
186
|
-
defineBehavior({
|
|
187
|
-
on: 'insert.blocks',
|
|
188
|
-
guard: ({snapshot, event}) => {
|
|
189
|
-
if (event.placement !== 'auto') {
|
|
190
|
-
return false
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const focusTextBlock = getFocusTextBlock(snapshot)
|
|
194
|
-
|
|
195
|
-
if (!focusTextBlock || !snapshot.context.selection) {
|
|
196
|
-
return false
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const focusBlockStartPoint = getBlockStartPoint({
|
|
200
|
-
context: snapshot.context,
|
|
201
|
-
block: focusTextBlock,
|
|
202
|
-
})
|
|
203
|
-
const focusBlockEndPoint = getBlockEndPoint({
|
|
204
|
-
context: snapshot.context,
|
|
205
|
-
block: focusTextBlock,
|
|
206
|
-
})
|
|
207
|
-
const focusTextBlockAfter = sliceTextBlock({
|
|
208
|
-
context: {
|
|
209
|
-
schema: snapshot.context.schema,
|
|
210
|
-
selection: {
|
|
211
|
-
anchor: snapshot.context.selection.focus,
|
|
212
|
-
focus: focusBlockEndPoint,
|
|
213
|
-
},
|
|
214
|
-
},
|
|
215
|
-
block: focusTextBlock.node,
|
|
216
|
-
})
|
|
217
|
-
const firstBlockKey =
|
|
218
|
-
event.blocks.at(0)?._key ?? snapshot.context.keyGenerator()
|
|
219
|
-
|
|
220
|
-
return {
|
|
221
|
-
firstBlockKey,
|
|
222
|
-
focusBlockStartPoint,
|
|
223
|
-
focusBlockEndPoint,
|
|
224
|
-
focusTextBlockAfter,
|
|
225
|
-
selection: snapshot.context.selection,
|
|
226
|
-
}
|
|
227
|
-
},
|
|
228
|
-
actions: [
|
|
229
|
-
(
|
|
230
|
-
{event},
|
|
231
|
-
{
|
|
232
|
-
focusBlockEndPoint,
|
|
233
|
-
focusTextBlockAfter,
|
|
234
|
-
selection,
|
|
235
|
-
firstBlockKey,
|
|
236
|
-
focusBlockStartPoint,
|
|
237
|
-
},
|
|
238
|
-
) => [
|
|
239
|
-
...event.blocks.flatMap((block, index) =>
|
|
240
|
-
index === 0
|
|
241
|
-
? [
|
|
242
|
-
...(isEqualSelectionPoints(selection.focus, focusBlockEndPoint)
|
|
243
|
-
? []
|
|
244
|
-
: [
|
|
245
|
-
raise({
|
|
246
|
-
type: 'delete',
|
|
247
|
-
at: {
|
|
248
|
-
anchor: selection.focus,
|
|
249
|
-
focus: focusBlockEndPoint,
|
|
250
|
-
},
|
|
251
|
-
}),
|
|
252
|
-
]),
|
|
253
|
-
raise({
|
|
254
|
-
type: 'insert.block',
|
|
255
|
-
block,
|
|
256
|
-
placement: 'auto',
|
|
257
|
-
select: 'end',
|
|
258
|
-
}),
|
|
259
|
-
]
|
|
260
|
-
: index === event.blocks.length - 1
|
|
261
|
-
? [
|
|
262
|
-
raise({
|
|
263
|
-
type: 'insert.block',
|
|
264
|
-
block,
|
|
265
|
-
placement: 'after',
|
|
266
|
-
select: 'end',
|
|
267
|
-
}),
|
|
268
|
-
raise({
|
|
269
|
-
type: 'insert.block',
|
|
270
|
-
block: focusTextBlockAfter,
|
|
271
|
-
placement: 'auto',
|
|
272
|
-
select: event.select === 'end' ? 'none' : 'end',
|
|
273
|
-
}),
|
|
274
|
-
]
|
|
275
|
-
: [
|
|
276
|
-
raise({
|
|
277
|
-
type: 'insert.block',
|
|
278
|
-
block,
|
|
279
|
-
placement: 'after',
|
|
280
|
-
select: 'end',
|
|
281
|
-
}),
|
|
282
|
-
],
|
|
283
|
-
),
|
|
284
|
-
...(event.select === 'none'
|
|
285
|
-
? [
|
|
286
|
-
raise({
|
|
287
|
-
type: 'select',
|
|
288
|
-
at: selection,
|
|
289
|
-
}),
|
|
290
|
-
]
|
|
291
|
-
: event.select === 'start'
|
|
292
|
-
? [
|
|
293
|
-
isEqualSelectionPoints(selection.focus, focusBlockStartPoint)
|
|
294
|
-
? raise({
|
|
295
|
-
type: 'select.block',
|
|
296
|
-
at: [{_key: firstBlockKey}],
|
|
297
|
-
select: 'start',
|
|
298
|
-
})
|
|
299
|
-
: raise({
|
|
300
|
-
type: 'select',
|
|
301
|
-
at: {
|
|
302
|
-
anchor: selection.focus,
|
|
303
|
-
focus: selection.focus,
|
|
304
|
-
},
|
|
305
|
-
}),
|
|
306
|
-
]
|
|
307
|
-
: []),
|
|
308
|
-
],
|
|
309
|
-
],
|
|
310
|
-
}),
|
|
311
|
-
defineBehavior({
|
|
312
|
-
on: 'insert.blocks',
|
|
313
|
-
guard: ({event}) => event.placement === 'auto',
|
|
314
|
-
actions: [
|
|
315
|
-
({event}) =>
|
|
316
|
-
event.blocks.map((block, index) =>
|
|
317
|
-
raise({
|
|
318
|
-
type: 'insert.block',
|
|
319
|
-
block,
|
|
320
|
-
placement: index === 0 ? 'auto' : 'after',
|
|
321
|
-
select: event.select ?? 'end',
|
|
322
|
-
}),
|
|
323
|
-
),
|
|
324
|
-
],
|
|
325
|
-
}),
|
|
326
|
-
defineBehavior({
|
|
327
|
-
on: 'insert.break',
|
|
328
|
-
actions: [() => [raise({type: 'split'})]],
|
|
329
|
-
}),
|
|
330
|
-
defineBehavior({
|
|
331
|
-
on: 'insert.child',
|
|
332
|
-
guard: ({snapshot}) => {
|
|
333
|
-
const lastBlock = getLastBlock(snapshot)
|
|
334
|
-
|
|
335
|
-
if (!lastBlock) {
|
|
336
|
-
return false
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
if (snapshot.context.selection) {
|
|
340
|
-
return false
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
const lastBlockEndPoint = getBlockEndPoint({
|
|
344
|
-
context: snapshot.context,
|
|
345
|
-
block: lastBlock,
|
|
346
|
-
})
|
|
347
|
-
|
|
348
|
-
return {lastBlockEndPoint}
|
|
349
|
-
},
|
|
350
|
-
actions: [
|
|
351
|
-
({event}, {lastBlockEndPoint}) => [
|
|
352
|
-
raise({
|
|
353
|
-
type: 'select',
|
|
354
|
-
at: {
|
|
355
|
-
anchor: lastBlockEndPoint,
|
|
356
|
-
focus: lastBlockEndPoint,
|
|
357
|
-
},
|
|
358
|
-
}),
|
|
359
|
-
raise(event),
|
|
360
|
-
],
|
|
361
|
-
],
|
|
362
|
-
}),
|
|
363
|
-
defineBehavior({
|
|
364
|
-
on: 'insert.child',
|
|
365
|
-
guard: ({snapshot}) => {
|
|
366
|
-
const focusTextBlock = getFocusTextBlock(snapshot)
|
|
367
|
-
|
|
368
|
-
return snapshot.context.selection && !focusTextBlock
|
|
369
|
-
},
|
|
370
|
-
actions: [
|
|
371
|
-
({snapshot, event}) => [
|
|
372
|
-
raise({
|
|
373
|
-
type: 'insert.block',
|
|
374
|
-
block: {
|
|
375
|
-
_type: snapshot.context.schema.block.name,
|
|
376
|
-
children: [
|
|
377
|
-
{
|
|
378
|
-
_type: snapshot.context.schema.span.name,
|
|
379
|
-
text: '',
|
|
380
|
-
marks: [],
|
|
381
|
-
},
|
|
382
|
-
],
|
|
383
|
-
},
|
|
384
|
-
placement: 'auto',
|
|
385
|
-
select: 'end',
|
|
386
|
-
}),
|
|
387
|
-
raise(event),
|
|
388
|
-
],
|
|
389
|
-
],
|
|
390
|
-
}),
|
|
391
|
-
defineBehavior({
|
|
392
|
-
on: 'insert.inline object',
|
|
393
|
-
actions: [
|
|
394
|
-
({event}) => [
|
|
395
|
-
raise({
|
|
396
|
-
type: 'insert.child',
|
|
397
|
-
child: {
|
|
398
|
-
_type: event.inlineObject.name,
|
|
399
|
-
...event.inlineObject.value,
|
|
400
|
-
},
|
|
401
|
-
}),
|
|
402
|
-
],
|
|
403
|
-
],
|
|
404
|
-
}),
|
|
405
|
-
defineBehavior({
|
|
406
|
-
on: 'insert.soft break',
|
|
407
|
-
actions: [() => [raise({type: 'insert.text', text: '\n'})]],
|
|
408
|
-
}),
|
|
409
|
-
defineBehavior({
|
|
410
|
-
on: 'insert.span',
|
|
411
|
-
guard: ({snapshot}) => !getFocusTextBlock(snapshot),
|
|
412
|
-
actions: [
|
|
413
|
-
({snapshot, event}) => [
|
|
414
|
-
raise({
|
|
415
|
-
type: 'insert.block',
|
|
416
|
-
block: {
|
|
417
|
-
_type: snapshot.context.schema.block.name,
|
|
418
|
-
children: [
|
|
419
|
-
{
|
|
420
|
-
_type: snapshot.context.schema.span.name,
|
|
421
|
-
text: '',
|
|
422
|
-
marks: [],
|
|
423
|
-
},
|
|
424
|
-
],
|
|
425
|
-
},
|
|
426
|
-
placement: 'auto',
|
|
427
|
-
select: 'end',
|
|
428
|
-
}),
|
|
429
|
-
raise(event),
|
|
430
|
-
],
|
|
431
|
-
],
|
|
432
|
-
}),
|
|
433
|
-
defineBehavior({
|
|
434
|
-
on: 'insert.span',
|
|
435
|
-
guard: ({snapshot, event}) => {
|
|
436
|
-
const focusTextBlock = getFocusTextBlock(snapshot)
|
|
437
|
-
const markDefs =
|
|
438
|
-
event.annotations?.map((annotation) => ({
|
|
439
|
-
_type: annotation.name,
|
|
440
|
-
_key: snapshot.context.keyGenerator(),
|
|
441
|
-
...annotation.value,
|
|
442
|
-
})) ?? []
|
|
443
|
-
|
|
444
|
-
return {markDefs, focusTextBlock}
|
|
445
|
-
},
|
|
446
|
-
actions: [
|
|
447
|
-
({snapshot, event}, {markDefs, focusTextBlock}) => [
|
|
448
|
-
...(focusTextBlock
|
|
449
|
-
? [
|
|
450
|
-
raise({
|
|
451
|
-
type: 'block.set',
|
|
452
|
-
at: focusTextBlock.path,
|
|
453
|
-
props: {
|
|
454
|
-
markDefs: [
|
|
455
|
-
...(focusTextBlock.node.markDefs ?? []),
|
|
456
|
-
...markDefs,
|
|
457
|
-
],
|
|
458
|
-
},
|
|
459
|
-
}),
|
|
460
|
-
]
|
|
461
|
-
: []),
|
|
462
|
-
raise({
|
|
463
|
-
type: 'insert.child',
|
|
464
|
-
child: {
|
|
465
|
-
_type: snapshot.context.schema.span.name,
|
|
466
|
-
text: event.text,
|
|
467
|
-
marks: [
|
|
468
|
-
...(event.decorators ?? []),
|
|
469
|
-
...markDefs.map((markDef) => markDef._key),
|
|
470
|
-
],
|
|
471
|
-
},
|
|
472
|
-
}),
|
|
473
|
-
],
|
|
474
|
-
],
|
|
475
|
-
}),
|
|
476
|
-
|
|
477
|
-
/**
|
|
478
|
-
* If there's an expanded selection, then we delete the selection before we
|
|
479
|
-
* insert the text.
|
|
480
|
-
*/
|
|
481
|
-
defineBehavior({
|
|
482
|
-
on: 'insert.text',
|
|
483
|
-
guard: ({snapshot}) => {
|
|
484
|
-
return isSelectionExpanded(snapshot)
|
|
485
|
-
},
|
|
486
|
-
actions: [({event}) => [raise({type: 'delete'}), raise(event)]],
|
|
487
|
-
}),
|
|
488
|
-
|
|
489
|
-
/**
|
|
490
|
-
* If there's no selection, then we select the end of the editor before we
|
|
491
|
-
* we insert the text.
|
|
492
|
-
*/
|
|
493
|
-
defineBehavior({
|
|
494
|
-
on: 'insert.text',
|
|
495
|
-
guard: ({snapshot}) => {
|
|
496
|
-
if (snapshot.context.selection) {
|
|
497
|
-
return false
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
const lastBlok = getLastBlock(snapshot)
|
|
501
|
-
|
|
502
|
-
if (!lastBlok) {
|
|
503
|
-
return false
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
const endPoint = getBlockEndPoint({
|
|
507
|
-
context: snapshot.context,
|
|
508
|
-
block: lastBlok,
|
|
509
|
-
})
|
|
510
|
-
return {endPoint}
|
|
511
|
-
},
|
|
512
|
-
actions: [
|
|
513
|
-
({event}, {endPoint}) => [
|
|
514
|
-
raise({
|
|
515
|
-
type: 'select',
|
|
516
|
-
at: {
|
|
517
|
-
anchor: endPoint,
|
|
518
|
-
focus: endPoint,
|
|
519
|
-
},
|
|
520
|
-
}),
|
|
521
|
-
raise(event),
|
|
522
|
-
],
|
|
523
|
-
],
|
|
524
|
-
}),
|
|
525
|
-
]
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import {createKeyboardShortcut} from '@portabletext/keyboard-shortcuts'
|
|
2
|
-
import {isTextBlock} from '@portabletext/schema'
|
|
3
|
-
import {defaultKeyboardShortcuts} from '../keyboard-shortcuts/default-keyboard-shortcuts'
|
|
4
|
-
import {getFocusBlock} from '../selectors/selector.get-focus-block'
|
|
5
|
-
import {getFocusInlineObject} from '../selectors/selector.get-focus-inline-object'
|
|
6
|
-
import {getPreviousBlock} from '../selectors/selector.get-previous-block'
|
|
7
|
-
import {isSelectionCollapsed} from '../selectors/selector.is-selection-collapsed'
|
|
8
|
-
import {isSelectionExpanded} from '../selectors/selector.is-selection-expanded'
|
|
9
|
-
import {getBlockEndPoint} from '../utils/util.get-block-end-point'
|
|
10
|
-
import {isEmptyTextBlock} from '../utils/util.is-empty-text-block'
|
|
11
|
-
import {raise} from './behavior.types.action'
|
|
12
|
-
import {defineBehavior} from './behavior.types.behavior'
|
|
13
|
-
|
|
14
|
-
const shiftLeft = createKeyboardShortcut({
|
|
15
|
-
default: [
|
|
16
|
-
{
|
|
17
|
-
key: 'ArrowLeft',
|
|
18
|
-
shift: true,
|
|
19
|
-
meta: false,
|
|
20
|
-
ctrl: false,
|
|
21
|
-
alt: false,
|
|
22
|
-
},
|
|
23
|
-
],
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
export const abstractKeyboardBehaviors = [
|
|
27
|
-
/**
|
|
28
|
-
* When Backspace is pressed on an inline object, Slate will raise a
|
|
29
|
-
* `delete.backward` event with `unit: 'block'`. This is wrong and this
|
|
30
|
-
* Behavior adjusts that.
|
|
31
|
-
*/
|
|
32
|
-
defineBehavior({
|
|
33
|
-
on: 'keyboard.keydown',
|
|
34
|
-
guard: ({snapshot, event}) =>
|
|
35
|
-
defaultKeyboardShortcuts.backspace.guard(event.originEvent) &&
|
|
36
|
-
isSelectionCollapsed(snapshot) &&
|
|
37
|
-
getFocusInlineObject(snapshot),
|
|
38
|
-
actions: [() => [raise({type: 'delete.backward', unit: 'character'})]],
|
|
39
|
-
}),
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* When Delete is pressed on an inline object, Slate will raise a
|
|
43
|
-
* `delete.forward` event with `unit: 'block'`. This is wrong and this
|
|
44
|
-
* Behavior adjusts that.
|
|
45
|
-
*/
|
|
46
|
-
defineBehavior({
|
|
47
|
-
on: 'keyboard.keydown',
|
|
48
|
-
guard: ({snapshot, event}) =>
|
|
49
|
-
defaultKeyboardShortcuts.delete.guard(event.originEvent) &&
|
|
50
|
-
isSelectionCollapsed(snapshot) &&
|
|
51
|
-
getFocusInlineObject(snapshot),
|
|
52
|
-
actions: [() => [raise({type: 'delete.forward', unit: 'character'})]],
|
|
53
|
-
}),
|
|
54
|
-
|
|
55
|
-
defineBehavior({
|
|
56
|
-
on: 'keyboard.keydown',
|
|
57
|
-
guard: ({event}) =>
|
|
58
|
-
defaultKeyboardShortcuts.deleteWord.backward.guard(event.originEvent),
|
|
59
|
-
actions: [() => [raise({type: 'delete.backward', unit: 'word'})]],
|
|
60
|
-
}),
|
|
61
|
-
|
|
62
|
-
defineBehavior({
|
|
63
|
-
on: 'keyboard.keydown',
|
|
64
|
-
guard: ({event}) =>
|
|
65
|
-
defaultKeyboardShortcuts.deleteWord.forward.guard(event.originEvent),
|
|
66
|
-
actions: [() => [raise({type: 'delete.forward', unit: 'word'})]],
|
|
67
|
-
}),
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Allow raising an `insert.break` event when pressing Enter on an inline
|
|
71
|
-
* object.
|
|
72
|
-
*/
|
|
73
|
-
defineBehavior({
|
|
74
|
-
on: 'keyboard.keydown',
|
|
75
|
-
guard: ({snapshot, event}) =>
|
|
76
|
-
defaultKeyboardShortcuts.break.guard(event.originEvent) &&
|
|
77
|
-
isSelectionCollapsed(snapshot) &&
|
|
78
|
-
getFocusInlineObject(snapshot),
|
|
79
|
-
actions: [() => [raise({type: 'insert.break'})]],
|
|
80
|
-
}),
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* On Firefox, Enter might collapse the selection. To mitigate this, we
|
|
84
|
-
* `raise` an `insert.break` event manually.
|
|
85
|
-
*/
|
|
86
|
-
defineBehavior({
|
|
87
|
-
on: 'keyboard.keydown',
|
|
88
|
-
guard: ({snapshot, event}) =>
|
|
89
|
-
defaultKeyboardShortcuts.break.guard(event.originEvent) &&
|
|
90
|
-
isSelectionExpanded(snapshot),
|
|
91
|
-
actions: [() => [raise({type: 'insert.break'})]],
|
|
92
|
-
}),
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* On WebKit, Shift+Enter results in an `insertParagraph` input event rather
|
|
96
|
-
* than an `insertLineBreak` input event. This Behavior makes sure we catch
|
|
97
|
-
* that `keyboard.keydown` event beforehand and raise an `insert.soft break` manually.
|
|
98
|
-
*/
|
|
99
|
-
defineBehavior({
|
|
100
|
-
on: 'keyboard.keydown',
|
|
101
|
-
guard: ({event}) =>
|
|
102
|
-
defaultKeyboardShortcuts.lineBreak.guard(event.originEvent),
|
|
103
|
-
actions: [() => [raise({type: 'insert.soft break'})]],
|
|
104
|
-
}),
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Manual handling of undo shortcuts.
|
|
108
|
-
*/
|
|
109
|
-
defineBehavior({
|
|
110
|
-
on: 'keyboard.keydown',
|
|
111
|
-
guard: ({event}) =>
|
|
112
|
-
defaultKeyboardShortcuts.history.undo.guard(event.originEvent),
|
|
113
|
-
actions: [() => [raise({type: 'history.undo'})]],
|
|
114
|
-
}),
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Manual handling of redo shortcuts.
|
|
118
|
-
*/
|
|
119
|
-
defineBehavior({
|
|
120
|
-
on: 'keyboard.keydown',
|
|
121
|
-
guard: ({event}) =>
|
|
122
|
-
defaultKeyboardShortcuts.history.redo.guard(event.originEvent),
|
|
123
|
-
actions: [() => [raise({type: 'history.redo'})]],
|
|
124
|
-
}),
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Fix edge case where Shift+ArrowLeft didn't reduce a selection hanging
|
|
128
|
-
* onto an empty text block.
|
|
129
|
-
*/
|
|
130
|
-
defineBehavior({
|
|
131
|
-
on: 'keyboard.keydown',
|
|
132
|
-
guard: ({snapshot, event}) => {
|
|
133
|
-
if (!snapshot.context.selection || !shiftLeft.guard(event.originEvent)) {
|
|
134
|
-
return false
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const focusBlock = getFocusBlock(snapshot)
|
|
138
|
-
|
|
139
|
-
if (!focusBlock) {
|
|
140
|
-
return false
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const previousBlock = getPreviousBlock({
|
|
144
|
-
...snapshot,
|
|
145
|
-
context: {
|
|
146
|
-
...snapshot.context,
|
|
147
|
-
selection: {
|
|
148
|
-
anchor: {
|
|
149
|
-
path: focusBlock.path,
|
|
150
|
-
offset: 0,
|
|
151
|
-
},
|
|
152
|
-
focus: {
|
|
153
|
-
path: focusBlock.path,
|
|
154
|
-
offset: 0,
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
if (!previousBlock) {
|
|
161
|
-
return false
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const hanging =
|
|
165
|
-
isTextBlock(snapshot.context, focusBlock.node) &&
|
|
166
|
-
snapshot.context.selection.focus.offset === 0
|
|
167
|
-
|
|
168
|
-
if (hanging && isEmptyTextBlock(snapshot.context, focusBlock.node)) {
|
|
169
|
-
return {previousBlock, selection: snapshot.context.selection}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return false
|
|
173
|
-
},
|
|
174
|
-
actions: [
|
|
175
|
-
({snapshot}, {previousBlock, selection}) => [
|
|
176
|
-
raise({
|
|
177
|
-
type: 'select',
|
|
178
|
-
at: {
|
|
179
|
-
anchor: selection.anchor,
|
|
180
|
-
focus: getBlockEndPoint({
|
|
181
|
-
context: snapshot.context,
|
|
182
|
-
block: previousBlock,
|
|
183
|
-
}),
|
|
184
|
-
},
|
|
185
|
-
}),
|
|
186
|
-
],
|
|
187
|
-
],
|
|
188
|
-
}),
|
|
189
|
-
]
|