@portabletext/editor 1.44.15 → 1.45.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 +5 -5
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +28 -22
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +154 -129
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/parse-blocks.cjs +74 -22
- package/lib/_chunks-cjs/parse-blocks.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +5 -5
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +28 -22
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +161 -136
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/parse-blocks.js +75 -23
- package/lib/_chunks-es/parse-blocks.js.map +1 -1
- package/lib/behaviors/index.cjs +18 -14
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +862 -636
- package/lib/behaviors/index.d.ts +862 -636
- package/lib/behaviors/index.js +18 -14
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +1 -1
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +40 -17
- package/lib/index.d.ts +40 -17
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +16 -7
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +20 -14
- package/lib/plugins/index.d.ts +20 -14
- package/lib/plugins/index.js +16 -7
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.cts +20 -14
- package/lib/selectors/index.d.ts +20 -14
- package/lib/utils/index.d.cts +20 -14
- package/lib/utils/index.d.ts +20 -14
- package/package.json +2 -2
- package/src/behavior-actions/behavior.action.annotation.add.ts +26 -5
- package/src/behavior-actions/behavior.action.decorator.add.ts +4 -4
- package/src/behavior-actions/behavior.action.delete.text.ts +1 -4
- package/src/behavior-actions/behavior.action.delete.ts +2 -2
- package/src/behavior-actions/behavior.action.insert-inline-object.ts +14 -13
- package/src/behavior-actions/behavior.action.select.ts +1 -1
- package/src/behavior-actions/{behavior.action.insert-break.ts → behavior.action.split.block.ts} +3 -9
- package/src/behavior-actions/behavior.actions.ts +9 -20
- package/src/behaviors/behavior.abstract.decorator.ts +2 -2
- package/src/behaviors/behavior.abstract.insert.ts +9 -1
- package/src/behaviors/behavior.abstract.select.ts +2 -2
- package/src/behaviors/behavior.core.annotations.ts +1 -1
- package/src/behaviors/behavior.core.block-objects.ts +4 -4
- package/src/behaviors/behavior.decorator-pair.ts +3 -3
- package/src/behaviors/behavior.default.ts +4 -4
- package/src/behaviors/behavior.emoji-picker.ts +18 -14
- package/src/behaviors/behavior.markdown.ts +28 -22
- package/src/behaviors/behavior.types.event.ts +23 -14
- package/src/converters/converter.portable-text.deserialize.test.ts +12 -3
- package/src/converters/converter.text-html.deserialize.test.ts +3 -1
- package/src/editor/Editable.tsx +1 -1
- package/src/editor/define-schema.ts +29 -5
- package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +2 -2
- package/src/editor/plugins/create-with-event-listeners.ts +4 -4
- package/src/internal-utils/parse-blocks.ts +109 -39
- package/src/plugins/plugin.decorator-shortcut.ts +3 -3
- package/src/plugins/plugin.one-line.tsx +8 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {Path} from '@sanity/types'
|
|
2
2
|
import {Editor, Node, Range, Text, Transforms} from 'slate'
|
|
3
|
+
import {parseAnnotation} from '../internal-utils/parse-blocks'
|
|
3
4
|
import type {BehaviorActionImplementation} from './behavior.actions'
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -24,6 +25,21 @@ export const addAnnotationActionImplementation: BehaviorActionImplementation<
|
|
|
24
25
|
'annotation.add',
|
|
25
26
|
AddedAnnotationPaths | undefined
|
|
26
27
|
> = ({context, action}) => {
|
|
28
|
+
const parsedAnnotation = parseAnnotation({
|
|
29
|
+
annotation: {
|
|
30
|
+
_type: action.annotation.name,
|
|
31
|
+
...action.annotation.value,
|
|
32
|
+
},
|
|
33
|
+
context,
|
|
34
|
+
options: {refreshKeys: false},
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
if (!parsedAnnotation) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
`Failed to parse annotation ${JSON.stringify(action.annotation)}`,
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
27
43
|
const editor = action.editor
|
|
28
44
|
|
|
29
45
|
if (!editor.selection || Range.isCollapsed(editor.selection)) {
|
|
@@ -41,6 +57,8 @@ export const addAnnotationActionImplementation: BehaviorActionImplementation<
|
|
|
41
57
|
reverse: Range.isBackward(editor.selection),
|
|
42
58
|
})
|
|
43
59
|
|
|
60
|
+
let blockIndex = 0
|
|
61
|
+
|
|
44
62
|
for (const [block, blockPath] of selectedBlocks) {
|
|
45
63
|
if (block.children.length === 0) {
|
|
46
64
|
continue
|
|
@@ -50,11 +68,13 @@ export const addAnnotationActionImplementation: BehaviorActionImplementation<
|
|
|
50
68
|
continue
|
|
51
69
|
}
|
|
52
70
|
|
|
53
|
-
|
|
71
|
+
// Make sure we don't generate more keys than needed
|
|
72
|
+
const annotationKey =
|
|
73
|
+
blockIndex === 0 ? parsedAnnotation._key : context.keyGenerator()
|
|
54
74
|
const markDefs = block.markDefs ?? []
|
|
55
75
|
const existingMarkDef = markDefs.find(
|
|
56
76
|
(markDef) =>
|
|
57
|
-
markDef._type ===
|
|
77
|
+
markDef._type === parsedAnnotation._type &&
|
|
58
78
|
markDef._key === annotationKey,
|
|
59
79
|
)
|
|
60
80
|
|
|
@@ -65,9 +85,8 @@ export const addAnnotationActionImplementation: BehaviorActionImplementation<
|
|
|
65
85
|
markDefs: [
|
|
66
86
|
...markDefs,
|
|
67
87
|
{
|
|
68
|
-
|
|
88
|
+
...parsedAnnotation,
|
|
69
89
|
_key: annotationKey,
|
|
70
|
-
...action.annotation.value,
|
|
71
90
|
},
|
|
72
91
|
],
|
|
73
92
|
},
|
|
@@ -100,7 +119,7 @@ export const addAnnotationActionImplementation: BehaviorActionImplementation<
|
|
|
100
119
|
const existingSameTypeAnnotations = marks.filter((mark) =>
|
|
101
120
|
markDefs.some(
|
|
102
121
|
(markDef) =>
|
|
103
|
-
markDef._key === mark && markDef._type ===
|
|
122
|
+
markDef._key === mark && markDef._type === parsedAnnotation._type,
|
|
104
123
|
),
|
|
105
124
|
)
|
|
106
125
|
|
|
@@ -119,6 +138,8 @@ export const addAnnotationActionImplementation: BehaviorActionImplementation<
|
|
|
119
138
|
|
|
120
139
|
spanPath = [{_key: block._key}, 'children', {_key: span._key}]
|
|
121
140
|
}
|
|
141
|
+
|
|
142
|
+
blockIndex++
|
|
122
143
|
}
|
|
123
144
|
|
|
124
145
|
if (markDefPath && spanPath) {
|
|
@@ -18,17 +18,17 @@ export const decoratorAddActionImplementation: BehaviorActionImplementation<
|
|
|
18
18
|
KEY_TO_VALUE_ELEMENT.get(editor),
|
|
19
19
|
)
|
|
20
20
|
|
|
21
|
-
const manualAnchor = action.
|
|
21
|
+
const manualAnchor = action.at?.anchor
|
|
22
22
|
? utils.blockOffsetToSpanSelectionPoint({
|
|
23
23
|
value,
|
|
24
|
-
blockOffset: action.
|
|
24
|
+
blockOffset: action.at.anchor,
|
|
25
25
|
direction: 'backward',
|
|
26
26
|
})
|
|
27
27
|
: undefined
|
|
28
|
-
const manualFocus = action.
|
|
28
|
+
const manualFocus = action.at?.focus
|
|
29
29
|
? utils.blockOffsetToSpanSelectionPoint({
|
|
30
30
|
value,
|
|
31
|
-
blockOffset: action.
|
|
31
|
+
blockOffset: action.at.focus,
|
|
32
32
|
direction: 'forward',
|
|
33
33
|
})
|
|
34
34
|
: undefined
|
|
@@ -17,10 +17,7 @@ export const deleteTextActionImplementation: BehaviorActionImplementation<
|
|
|
17
17
|
|
|
18
18
|
const selection = utils.blockOffsetsToSelection({
|
|
19
19
|
value,
|
|
20
|
-
offsets:
|
|
21
|
-
anchor: action.anchor,
|
|
22
|
-
focus: action.focus,
|
|
23
|
-
},
|
|
20
|
+
offsets: action.at,
|
|
24
21
|
})
|
|
25
22
|
|
|
26
23
|
if (!selection) {
|
|
@@ -4,11 +4,11 @@ import type {BehaviorActionImplementation} from './behavior.actions'
|
|
|
4
4
|
export const deleteActionImplementation: BehaviorActionImplementation<
|
|
5
5
|
'delete'
|
|
6
6
|
> = ({action}) => {
|
|
7
|
-
const range = toSlateRange(action.
|
|
7
|
+
const range = toSlateRange(action.at, action.editor)
|
|
8
8
|
|
|
9
9
|
if (!range) {
|
|
10
10
|
throw new Error(
|
|
11
|
-
`Failed to get Slate Range for selection ${JSON.stringify(action.
|
|
11
|
+
`Failed to get Slate Range for selection ${JSON.stringify(action.at)}`,
|
|
12
12
|
)
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import {Editor, Transforms, type Element} from 'slate'
|
|
2
|
+
import {parseInlineObject} from '../internal-utils/parse-blocks'
|
|
2
3
|
import {toSlateValue} from '../internal-utils/values'
|
|
3
4
|
import type {BehaviorActionImplementation} from './behavior.actions'
|
|
4
5
|
|
|
5
6
|
export const insertInlineObjectActionImplementation: BehaviorActionImplementation<
|
|
6
7
|
'insert.inline object'
|
|
7
8
|
> = ({context, action}) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const parsedInlineObject = parseInlineObject({
|
|
10
|
+
context,
|
|
11
|
+
inlineObject: {
|
|
12
|
+
_type: action.inlineObject.name,
|
|
13
|
+
...(action.inlineObject.value ?? {}),
|
|
14
|
+
},
|
|
15
|
+
options: {refreshKeys: false},
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
if (!parsedInlineObject) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
`Failed to parse inline object ${JSON.stringify(action.inlineObject)}`,
|
|
11
21
|
)
|
|
12
|
-
) {
|
|
13
|
-
console.error('Unable to insert unknown inline object')
|
|
14
|
-
return
|
|
15
22
|
}
|
|
16
23
|
|
|
17
24
|
if (!action.editor.selection) {
|
|
@@ -36,13 +43,7 @@ export const insertInlineObjectActionImplementation: BehaviorActionImplementatio
|
|
|
36
43
|
{
|
|
37
44
|
_type: context.schema.block.name,
|
|
38
45
|
_key: context.keyGenerator(),
|
|
39
|
-
children: [
|
|
40
|
-
{
|
|
41
|
-
_type: action.inlineObject.name,
|
|
42
|
-
_key: context.keyGenerator(),
|
|
43
|
-
...(action.inlineObject.value ?? {}),
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
+
children: [parsedInlineObject],
|
|
46
47
|
},
|
|
47
48
|
],
|
|
48
49
|
{schemaTypes: context.schema},
|
|
@@ -5,7 +5,7 @@ import type {BehaviorActionImplementation} from './behavior.actions'
|
|
|
5
5
|
export const selectActionImplementation: BehaviorActionImplementation<
|
|
6
6
|
'select'
|
|
7
7
|
> = ({action}) => {
|
|
8
|
-
const newSelection = toSlateRange(action.
|
|
8
|
+
const newSelection = toSlateRange(action.at, action.editor)
|
|
9
9
|
|
|
10
10
|
if (newSelection) {
|
|
11
11
|
Transforms.select(action.editor, newSelection)
|
package/src/behavior-actions/{behavior.action.insert-break.ts → behavior.action.split.block.ts}
RENAMED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {isEqual} from 'lodash'
|
|
2
|
-
import {Editor,
|
|
2
|
+
import {Editor, Node, Path, Transforms} from 'slate'
|
|
3
3
|
import type {SlateTextBlock, VoidElement} from '../types/slate'
|
|
4
4
|
import type {BehaviorActionImplementation} from './behavior.actions'
|
|
5
5
|
|
|
6
|
-
export const
|
|
7
|
-
'
|
|
6
|
+
export const splitBlockActionImplementation: BehaviorActionImplementation<
|
|
7
|
+
'split.block'
|
|
8
8
|
> = ({context, action}) => {
|
|
9
9
|
const keyGenerator = context.keyGenerator
|
|
10
10
|
const schema = context.schema
|
|
@@ -144,9 +144,3 @@ export const insertBreakActionImplementation: BehaviorActionImplementation<
|
|
|
144
144
|
|
|
145
145
|
Transforms.splitNodes(editor, {always: true})
|
|
146
146
|
}
|
|
147
|
-
|
|
148
|
-
export const insertSoftBreakActionImplementation: BehaviorActionImplementation<
|
|
149
|
-
'insert.soft break'
|
|
150
|
-
> = ({action}) => {
|
|
151
|
-
insertText(action.editor, '\n')
|
|
152
|
-
}
|
|
@@ -21,10 +21,6 @@ import {deleteForwardActionImplementation} from './behavior.action.delete.forwar
|
|
|
21
21
|
import {deleteTextActionImplementation} from './behavior.action.delete.text'
|
|
22
22
|
import {effectActionImplementation} from './behavior.action.effect'
|
|
23
23
|
import {focusActionImplementation} from './behavior.action.focus'
|
|
24
|
-
import {
|
|
25
|
-
insertBreakActionImplementation,
|
|
26
|
-
insertSoftBreakActionImplementation,
|
|
27
|
-
} from './behavior.action.insert-break'
|
|
28
24
|
import {insertInlineObjectActionImplementation} from './behavior.action.insert-inline-object'
|
|
29
25
|
import {insertSpanActionImplementation} from './behavior.action.insert-span'
|
|
30
26
|
import {insertBlockActionImplementation} from './behavior.action.insert.block'
|
|
@@ -32,6 +28,7 @@ import {insertTextActionImplementation} from './behavior.action.insert.text'
|
|
|
32
28
|
import {moveBlockActionImplementation} from './behavior.action.move.block'
|
|
33
29
|
import {noopActionImplementation} from './behavior.action.noop'
|
|
34
30
|
import {selectActionImplementation} from './behavior.action.select'
|
|
31
|
+
import {splitBlockActionImplementation} from './behavior.action.split.block'
|
|
35
32
|
|
|
36
33
|
const debug = debugWithName('behaviors:action')
|
|
37
34
|
|
|
@@ -72,15 +69,14 @@ const behaviorActionImplementations: BehaviorActionImplementations = {
|
|
|
72
69
|
'history.redo': historyRedoActionImplementation,
|
|
73
70
|
'history.undo': historyUndoActionImplementation,
|
|
74
71
|
'insert.block': insertBlockActionImplementation,
|
|
75
|
-
'insert.break': insertBreakActionImplementation,
|
|
76
72
|
'insert.inline object': insertInlineObjectActionImplementation,
|
|
77
|
-
'insert.soft break': insertSoftBreakActionImplementation,
|
|
78
73
|
'insert.span': insertSpanActionImplementation,
|
|
79
74
|
'insert.text': insertTextActionImplementation,
|
|
80
75
|
'effect': effectActionImplementation,
|
|
81
76
|
'move.block': moveBlockActionImplementation,
|
|
82
77
|
'noop': noopActionImplementation,
|
|
83
78
|
'select': selectActionImplementation,
|
|
79
|
+
'split.block': splitBlockActionImplementation,
|
|
84
80
|
}
|
|
85
81
|
|
|
86
82
|
export function performAction({
|
|
@@ -219,20 +215,6 @@ export function performAction({
|
|
|
219
215
|
})
|
|
220
216
|
break
|
|
221
217
|
}
|
|
222
|
-
case 'insert.break': {
|
|
223
|
-
behaviorActionImplementations['insert.break']({
|
|
224
|
-
context,
|
|
225
|
-
action,
|
|
226
|
-
})
|
|
227
|
-
break
|
|
228
|
-
}
|
|
229
|
-
case 'insert.soft break': {
|
|
230
|
-
behaviorActionImplementations['insert.soft break']({
|
|
231
|
-
context,
|
|
232
|
-
action,
|
|
233
|
-
})
|
|
234
|
-
break
|
|
235
|
-
}
|
|
236
218
|
case 'insert.span': {
|
|
237
219
|
behaviorActionImplementations['insert.span']({
|
|
238
220
|
context,
|
|
@@ -261,6 +243,13 @@ export function performAction({
|
|
|
261
243
|
})
|
|
262
244
|
break
|
|
263
245
|
}
|
|
246
|
+
case 'split.block': {
|
|
247
|
+
behaviorActionImplementations['split.block']({
|
|
248
|
+
context,
|
|
249
|
+
action,
|
|
250
|
+
})
|
|
251
|
+
break
|
|
252
|
+
}
|
|
264
253
|
default: {
|
|
265
254
|
behaviorActionImplementations.select({
|
|
266
255
|
context,
|
|
@@ -16,10 +16,10 @@ export const abstractDecoratorBehaviors = [
|
|
|
16
16
|
defineBehavior({
|
|
17
17
|
on: 'decorator.toggle',
|
|
18
18
|
guard: ({snapshot, event}) => {
|
|
19
|
-
const manualSelection = event.
|
|
19
|
+
const manualSelection = event.at
|
|
20
20
|
? blockOffsetsToSelection({
|
|
21
21
|
value: snapshot.context.value,
|
|
22
|
-
offsets: event.
|
|
22
|
+
offsets: event.at,
|
|
23
23
|
})
|
|
24
24
|
: null
|
|
25
25
|
|
|
@@ -63,7 +63,7 @@ export const abstractInsertBehaviors = [
|
|
|
63
63
|
index === 0
|
|
64
64
|
? [
|
|
65
65
|
raise({
|
|
66
|
-
type: '
|
|
66
|
+
type: 'split.block',
|
|
67
67
|
}),
|
|
68
68
|
raise({
|
|
69
69
|
type: 'select.previous block',
|
|
@@ -115,4 +115,12 @@ export const abstractInsertBehaviors = [
|
|
|
115
115
|
),
|
|
116
116
|
],
|
|
117
117
|
}),
|
|
118
|
+
defineBehavior({
|
|
119
|
+
on: 'insert.break',
|
|
120
|
+
actions: [() => [raise({type: 'split.block'})]],
|
|
121
|
+
}),
|
|
122
|
+
defineBehavior({
|
|
123
|
+
on: 'insert.soft break',
|
|
124
|
+
actions: [() => [raise({type: 'insert.text', text: '\n'})]],
|
|
125
|
+
}),
|
|
118
126
|
]
|
|
@@ -29,7 +29,7 @@ export const abstractSelectBehaviors = [
|
|
|
29
29
|
(_, {selection}) => [
|
|
30
30
|
raise({
|
|
31
31
|
type: 'select',
|
|
32
|
-
selection,
|
|
32
|
+
at: selection,
|
|
33
33
|
}),
|
|
34
34
|
],
|
|
35
35
|
],
|
|
@@ -54,7 +54,7 @@ export const abstractSelectBehaviors = [
|
|
|
54
54
|
(_, {selection}) => [
|
|
55
55
|
raise({
|
|
56
56
|
type: 'select',
|
|
57
|
-
selection,
|
|
57
|
+
at: selection,
|
|
58
58
|
}),
|
|
59
59
|
],
|
|
60
60
|
],
|
|
@@ -28,7 +28,7 @@ const addAnnotationOnCollapsedSelection = defineBehavior({
|
|
|
28
28
|
},
|
|
29
29
|
actions: [
|
|
30
30
|
({event}, {caretWordSelection}) => [
|
|
31
|
-
raise({type: 'select',
|
|
31
|
+
raise({type: 'select', at: caretWordSelection}),
|
|
32
32
|
raise({type: 'annotation.add', annotation: event.annotation}),
|
|
33
33
|
],
|
|
34
34
|
],
|
|
@@ -132,7 +132,7 @@ const clickingAboveLonelyBlockObject = defineBehavior({
|
|
|
132
132
|
({snapshot, event}) => [
|
|
133
133
|
raise({
|
|
134
134
|
type: 'select',
|
|
135
|
-
|
|
135
|
+
at: event.position.selection,
|
|
136
136
|
}),
|
|
137
137
|
raise({
|
|
138
138
|
type: 'insert.block',
|
|
@@ -186,7 +186,7 @@ const clickingBelowLonelyBlockObject = defineBehavior({
|
|
|
186
186
|
({snapshot, event}) => [
|
|
187
187
|
raise({
|
|
188
188
|
type: 'select',
|
|
189
|
-
|
|
189
|
+
at: event.position.selection,
|
|
190
190
|
}),
|
|
191
191
|
raise({
|
|
192
192
|
type: 'insert.block',
|
|
@@ -228,7 +228,7 @@ const deletingEmptyTextBlockAfterBlockObject = defineBehavior({
|
|
|
228
228
|
}),
|
|
229
229
|
raise({
|
|
230
230
|
type: 'select',
|
|
231
|
-
|
|
231
|
+
at: {
|
|
232
232
|
anchor: {path: previousBlock.path, offset: 0},
|
|
233
233
|
focus: {path: previousBlock.path, offset: 0},
|
|
234
234
|
},
|
|
@@ -265,7 +265,7 @@ const deletingEmptyTextBlockBeforeBlockObject = defineBehavior({
|
|
|
265
265
|
}),
|
|
266
266
|
raise({
|
|
267
267
|
type: 'select',
|
|
268
|
-
|
|
268
|
+
at: {
|
|
269
269
|
anchor: {path: nextBlock.path, offset: 0},
|
|
270
270
|
focus: {path: nextBlock.path, offset: 0},
|
|
271
271
|
},
|
|
@@ -165,7 +165,7 @@ export function createDecoratorPairBehavior(config: {
|
|
|
165
165
|
{
|
|
166
166
|
type: 'decorator.add',
|
|
167
167
|
decorator,
|
|
168
|
-
|
|
168
|
+
at: {
|
|
169
169
|
anchor: prefixOffsets.focus,
|
|
170
170
|
focus: suffixOffsets.anchor,
|
|
171
171
|
},
|
|
@@ -173,12 +173,12 @@ export function createDecoratorPairBehavior(config: {
|
|
|
173
173
|
// Delete the suffix
|
|
174
174
|
{
|
|
175
175
|
type: 'delete.text',
|
|
176
|
-
|
|
176
|
+
at: suffixOffsets,
|
|
177
177
|
},
|
|
178
178
|
// Delete the prefix
|
|
179
179
|
{
|
|
180
180
|
type: 'delete.text',
|
|
181
|
-
|
|
181
|
+
at: prefixOffsets,
|
|
182
182
|
},
|
|
183
183
|
// Toggle the decorator off so the next inserted text isn't emphasized
|
|
184
184
|
{
|
|
@@ -149,7 +149,7 @@ export const defaultBehaviors = [
|
|
|
149
149
|
}),
|
|
150
150
|
raise({
|
|
151
151
|
type: 'delete',
|
|
152
|
-
selection,
|
|
152
|
+
at: selection,
|
|
153
153
|
}),
|
|
154
154
|
],
|
|
155
155
|
],
|
|
@@ -220,7 +220,7 @@ export const defaultBehaviors = [
|
|
|
220
220
|
({event}) => [
|
|
221
221
|
raise({
|
|
222
222
|
type: 'select',
|
|
223
|
-
|
|
223
|
+
at: event.position.selection,
|
|
224
224
|
}),
|
|
225
225
|
raise({
|
|
226
226
|
type: 'deserialize',
|
|
@@ -293,7 +293,7 @@ export const defaultBehaviors = [
|
|
|
293
293
|
: [
|
|
294
294
|
raise({
|
|
295
295
|
type: 'delete',
|
|
296
|
-
|
|
296
|
+
at: dragOrigin.selection,
|
|
297
297
|
}),
|
|
298
298
|
]),
|
|
299
299
|
raise({
|
|
@@ -414,7 +414,7 @@ export const defaultBehaviors = [
|
|
|
414
414
|
({event}, {selection}) => [
|
|
415
415
|
raise({
|
|
416
416
|
type: 'delete',
|
|
417
|
-
selection,
|
|
417
|
+
at: selection,
|
|
418
418
|
}),
|
|
419
419
|
raise({
|
|
420
420
|
type: 'deserialize',
|
|
@@ -131,13 +131,15 @@ export function createEmojiPickerBehaviors<TEmojiMatch>(
|
|
|
131
131
|
},
|
|
132
132
|
{
|
|
133
133
|
type: 'delete.text',
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
134
|
+
at: {
|
|
135
|
+
anchor: {
|
|
136
|
+
path: params.focusBlock.path,
|
|
137
|
+
offset: params.textBeforeLength - params.emojiStringLength,
|
|
138
|
+
},
|
|
139
|
+
focus: {
|
|
140
|
+
path: params.focusBlock.path,
|
|
141
|
+
offset: params.textBeforeLength,
|
|
142
|
+
},
|
|
141
143
|
},
|
|
142
144
|
},
|
|
143
145
|
{
|
|
@@ -225,13 +227,15 @@ export function createEmojiPickerBehaviors<TEmojiMatch>(
|
|
|
225
227
|
},
|
|
226
228
|
{
|
|
227
229
|
type: 'delete.text',
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
230
|
+
at: {
|
|
231
|
+
anchor: {
|
|
232
|
+
path: params.focusBlock.path,
|
|
233
|
+
offset: params.textBeforeLength - params.emojiStringLength,
|
|
234
|
+
},
|
|
235
|
+
focus: {
|
|
236
|
+
path: params.focusBlock.path,
|
|
237
|
+
offset: params.textBeforeLength,
|
|
238
|
+
},
|
|
235
239
|
},
|
|
236
240
|
},
|
|
237
241
|
{
|
|
@@ -137,13 +137,15 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
137
137
|
},
|
|
138
138
|
{
|
|
139
139
|
type: 'delete.text',
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
140
|
+
at: {
|
|
141
|
+
anchor: {
|
|
142
|
+
path: focusTextBlock.path,
|
|
143
|
+
offset: 0,
|
|
144
|
+
},
|
|
145
|
+
focus: {
|
|
146
|
+
path: focusTextBlock.path,
|
|
147
|
+
offset: 2,
|
|
148
|
+
},
|
|
147
149
|
},
|
|
148
150
|
},
|
|
149
151
|
],
|
|
@@ -213,7 +215,7 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
213
215
|
},
|
|
214
216
|
{
|
|
215
217
|
type: 'delete.text',
|
|
216
|
-
|
|
218
|
+
at: hrBlockOffsets,
|
|
217
219
|
},
|
|
218
220
|
],
|
|
219
221
|
],
|
|
@@ -348,13 +350,15 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
348
350
|
},
|
|
349
351
|
{
|
|
350
352
|
type: 'delete.text',
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
353
|
+
at: {
|
|
354
|
+
anchor: {
|
|
355
|
+
path: focusTextBlock.path,
|
|
356
|
+
offset: 0,
|
|
357
|
+
},
|
|
358
|
+
focus: {
|
|
359
|
+
path: focusTextBlock.path,
|
|
360
|
+
offset: level + 1,
|
|
361
|
+
},
|
|
358
362
|
},
|
|
359
363
|
},
|
|
360
364
|
],
|
|
@@ -485,13 +489,15 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
485
489
|
},
|
|
486
490
|
{
|
|
487
491
|
type: 'delete.text',
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
492
|
+
at: {
|
|
493
|
+
anchor: {
|
|
494
|
+
path: focusTextBlock.path,
|
|
495
|
+
offset: 0,
|
|
496
|
+
},
|
|
497
|
+
focus: {
|
|
498
|
+
path: focusTextBlock.path,
|
|
499
|
+
offset: listItemLength + 1,
|
|
500
|
+
},
|
|
495
501
|
},
|
|
496
502
|
},
|
|
497
503
|
],
|
|
@@ -73,13 +73,12 @@ const syntheticBehaviorEventTypes = [
|
|
|
73
73
|
'history.redo',
|
|
74
74
|
'history.undo',
|
|
75
75
|
'insert.inline object',
|
|
76
|
-
'insert.break',
|
|
77
|
-
'insert.soft break',
|
|
78
76
|
'insert.block',
|
|
79
77
|
'insert.span',
|
|
80
78
|
'insert.text',
|
|
81
79
|
'move.block',
|
|
82
80
|
'select',
|
|
81
|
+
'split.block',
|
|
83
82
|
] as const
|
|
84
83
|
|
|
85
84
|
type SyntheticBehaviorEventType = (typeof syntheticBehaviorEventTypes)[number]
|
|
@@ -120,7 +119,10 @@ export type SyntheticBehaviorEvent =
|
|
|
120
119
|
| {
|
|
121
120
|
type: StrictExtract<SyntheticBehaviorEventType, 'decorator.add'>
|
|
122
121
|
decorator: string
|
|
123
|
-
|
|
122
|
+
at?: {
|
|
123
|
+
anchor: BlockOffset
|
|
124
|
+
focus: BlockOffset
|
|
125
|
+
}
|
|
124
126
|
}
|
|
125
127
|
| {
|
|
126
128
|
type: StrictExtract<SyntheticBehaviorEventType, 'decorator.remove'>
|
|
@@ -128,7 +130,7 @@ export type SyntheticBehaviorEvent =
|
|
|
128
130
|
}
|
|
129
131
|
| {
|
|
130
132
|
type: StrictExtract<SyntheticBehaviorEventType, 'delete'>
|
|
131
|
-
|
|
133
|
+
at: NonNullable<EditorSelection>
|
|
132
134
|
}
|
|
133
135
|
| {
|
|
134
136
|
type: StrictExtract<SyntheticBehaviorEventType, 'delete.backward'>
|
|
@@ -144,8 +146,10 @@ export type SyntheticBehaviorEvent =
|
|
|
144
146
|
}
|
|
145
147
|
| {
|
|
146
148
|
type: StrictExtract<SyntheticBehaviorEventType, 'delete.text'>
|
|
147
|
-
|
|
148
|
-
|
|
149
|
+
at: {
|
|
150
|
+
anchor: BlockOffset
|
|
151
|
+
focus: BlockOffset
|
|
152
|
+
}
|
|
149
153
|
}
|
|
150
154
|
| {
|
|
151
155
|
type: StrictExtract<SyntheticBehaviorEventType, 'focus'>
|
|
@@ -163,12 +167,6 @@ export type SyntheticBehaviorEvent =
|
|
|
163
167
|
value?: {[prop: string]: unknown}
|
|
164
168
|
}
|
|
165
169
|
}
|
|
166
|
-
| {
|
|
167
|
-
type: StrictExtract<SyntheticBehaviorEventType, 'insert.break'>
|
|
168
|
-
}
|
|
169
|
-
| {
|
|
170
|
-
type: StrictExtract<SyntheticBehaviorEventType, 'insert.soft break'>
|
|
171
|
-
}
|
|
172
170
|
| {
|
|
173
171
|
type: StrictExtract<SyntheticBehaviorEventType, 'insert.block'>
|
|
174
172
|
block: BlockWithOptionalKey
|
|
@@ -195,7 +193,10 @@ export type SyntheticBehaviorEvent =
|
|
|
195
193
|
}
|
|
196
194
|
| {
|
|
197
195
|
type: StrictExtract<SyntheticBehaviorEventType, 'select'>
|
|
198
|
-
|
|
196
|
+
at: EditorSelection
|
|
197
|
+
}
|
|
198
|
+
| {
|
|
199
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'split.block'>
|
|
199
200
|
}
|
|
200
201
|
|
|
201
202
|
export type InsertPlacement = 'auto' | 'after' | 'before'
|
|
@@ -217,6 +218,8 @@ const abstractBehaviorEventTypes = [
|
|
|
217
218
|
'deserialization.success',
|
|
218
219
|
'deserialization.failure',
|
|
219
220
|
'insert.blocks',
|
|
221
|
+
'insert.break',
|
|
222
|
+
'insert.soft break',
|
|
220
223
|
'list item.add',
|
|
221
224
|
'list item.remove',
|
|
222
225
|
'list item.toggle',
|
|
@@ -248,7 +251,7 @@ export type AbstractBehaviorEvent =
|
|
|
248
251
|
| {
|
|
249
252
|
type: StrictExtract<AbstractBehaviorEventType, 'decorator.toggle'>
|
|
250
253
|
decorator: string
|
|
251
|
-
|
|
254
|
+
at?: {anchor: BlockOffset; focus: BlockOffset}
|
|
252
255
|
}
|
|
253
256
|
| {
|
|
254
257
|
type: StrictExtract<AbstractBehaviorEventType, 'deserialize'>
|
|
@@ -317,6 +320,12 @@ export type AbstractBehaviorEvent =
|
|
|
317
320
|
blocks: Array<PortableTextBlock>
|
|
318
321
|
placement: InsertPlacement
|
|
319
322
|
}
|
|
323
|
+
| {
|
|
324
|
+
type: StrictExtract<AbstractBehaviorEventType, 'insert.break'>
|
|
325
|
+
}
|
|
326
|
+
| {
|
|
327
|
+
type: StrictExtract<AbstractBehaviorEventType, 'insert.soft break'>
|
|
328
|
+
}
|
|
320
329
|
| {
|
|
321
330
|
type: StrictExtract<AbstractBehaviorEventType, 'list item.add'>
|
|
322
331
|
listItem: string
|