@portabletext/editor 1.36.6 → 1.38.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 +84 -49
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +919 -526
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/{util.block-offsets-to-selection.cjs → parse-blocks.cjs} +36 -21
- package/lib/_chunks-cjs/parse-blocks.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.get-text-before.cjs +2 -2
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/{selector.is-active-style.cjs → selector.is-overlapping-selection.cjs} +144 -3
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -0
- package/lib/_chunks-cjs/util.slice-blocks.cjs +12 -0
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +84 -49
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +1 -1
- package/lib/_chunks-es/editor-provider.js +911 -517
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/{util.block-offsets-to-selection.js → parse-blocks.js} +37 -22
- package/lib/_chunks-es/parse-blocks.js.map +1 -0
- package/lib/_chunks-es/selector.get-text-before.js +1 -2
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/{selector.is-active-style.js → selector.is-overlapping-selection.js} +146 -5
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -0
- package/lib/_chunks-es/util.slice-blocks.js +12 -0
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/behaviors/index.d.cts +10535 -4689
- package/lib/behaviors/index.d.ts +10535 -4689
- package/lib/index.cjs +582 -209
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +5297 -1178
- package/lib/index.d.ts +5297 -1178
- package/lib/index.js +591 -213
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +2 -2
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +5297 -1178
- package/lib/plugins/index.d.ts +5297 -1178
- package/lib/plugins/index.js +2 -2
- package/lib/selectors/index.cjs +21 -103
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +5313 -1178
- package/lib/selectors/index.d.ts +5313 -1178
- package/lib/selectors/index.js +13 -96
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +4 -4
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +5297 -1178
- package/lib/utils/index.d.ts +5297 -1178
- package/lib/utils/index.js +3 -4
- package/lib/utils/index.js.map +1 -1
- package/package.json +15 -14
- package/src/behavior-actions/behavior.action.blur.ts +8 -0
- package/src/behavior-actions/behavior.action.decorator.add.ts +2 -1
- package/src/behavior-actions/behavior.action.delete.backward.ts +7 -0
- package/src/behavior-actions/behavior.action.delete.block.ts +24 -0
- package/src/behavior-actions/behavior.action.delete.forward.ts +7 -0
- package/src/behavior-actions/behavior.action.delete.text.ts +2 -1
- package/src/behavior-actions/behavior.action.delete.ts +1 -3
- package/src/behavior-actions/behavior.action.deserialization.failure.ts +9 -0
- package/src/behavior-actions/behavior.action.deserialization.success.ts +16 -0
- package/src/behavior-actions/behavior.action.effect.ts +7 -0
- package/src/behavior-actions/behavior.action.focus.ts +8 -0
- package/src/behavior-actions/behavior.action.insert-blocks.ts +118 -74
- package/src/behavior-actions/behavior.action.insert-break.ts +1 -0
- package/src/behavior-actions/{behavior.action.insert-block-object.ts → behavior.action.insert.block-object.ts} +9 -14
- package/src/behavior-actions/behavior.action.insert.block.ts +247 -2
- package/src/behavior-actions/behavior.action.insert.text-block.ts +33 -0
- package/src/behavior-actions/behavior.action.insert.text.ts +7 -0
- package/src/behavior-actions/behavior.action.move.block-down.ts +48 -0
- package/src/behavior-actions/behavior.action.move.block-up.ts +53 -0
- package/src/behavior-actions/behavior.action.move.block.ts +16 -0
- package/src/behavior-actions/behavior.action.noop.ts +5 -0
- package/src/behavior-actions/behavior.action.select.next-block.ts +44 -0
- package/src/behavior-actions/behavior.action.select.previous-block.ts +48 -0
- package/src/behavior-actions/behavior.action.select.ts +15 -0
- package/src/behavior-actions/behavior.action.serialization.failure.ts +9 -0
- package/src/behavior-actions/behavior.action.serialization.success.ts +14 -0
- package/src/behavior-actions/behavior.actions.ts +54 -212
- package/src/behaviors/behavior.core.block-objects.ts +35 -6
- package/src/behaviors/behavior.core.insert-break.ts +1 -0
- package/src/behaviors/behavior.core.ts +2 -0
- package/src/behaviors/behavior.default.ts +241 -33
- package/src/behaviors/behavior.types.ts +138 -20
- package/src/converters/converter.portable-text.ts +5 -2
- package/src/converters/converter.text-html.serialize.test.ts +4 -4
- package/src/converters/converter.text-html.ts +5 -2
- package/src/converters/converter.text-plain.test.ts +6 -6
- package/src/converters/converter.text-plain.ts +5 -2
- package/src/converters/converter.types.ts +3 -3
- package/src/editor/Editable.tsx +403 -48
- package/src/editor/components/Element.tsx +133 -18
- package/src/editor/components/use-draggable.ts +34 -102
- package/src/editor/editor-machine.ts +66 -10
- package/src/editor/editor-selector.ts +2 -0
- package/src/editor/editor-snapshot.ts +17 -0
- package/src/editor/plugins/create-with-event-listeners.ts +6 -40
- package/src/internal-utils/create-test-snapshot.ts +2 -0
- package/src/internal-utils/event-position.ts +210 -0
- package/src/internal-utils/slate-utils.ts +56 -0
- package/src/internal-utils/weakMaps.ts +1 -15
- package/src/selectors/index.ts +2 -0
- package/src/selectors/selector.get-focus-inline-object.ts +21 -0
- package/src/selectors/selector.is-overlapping-selection.test.ts +171 -0
- package/src/selectors/selector.is-overlapping-selection.ts +108 -4
- package/src/selectors/selector.is-point-after-selection.ts +3 -1
- package/src/selectors/selector.is-point-before-selection.ts +3 -1
- package/src/selectors/selector.is-selecting-entire-blocks.ts +34 -0
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +0 -1
- package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs.map +0 -1
- package/lib/_chunks-cjs/util.reverse-selection.cjs +0 -14
- package/lib/_chunks-cjs/util.reverse-selection.cjs.map +0 -1
- package/lib/_chunks-es/selector.is-active-style.js.map +0 -1
- package/lib/_chunks-es/util.block-offsets-to-selection.js.map +0 -1
- package/lib/_chunks-es/util.reverse-selection.js +0 -15
- package/lib/_chunks-es/util.reverse-selection.js.map +0 -1
- package/src/behavior-actions/behavior.action-utils.insert-block.ts +0 -61
- package/src/editor/__tests__/handleClick.test.tsx +0 -277
- package/src/editor/components/use-droppable.ts +0 -135
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {ReactEditor} from 'slate-react'
|
|
3
|
-
import type {
|
|
4
|
-
InternalBehaviorAction,
|
|
5
|
-
SyntheticBehaviorEvent,
|
|
6
|
-
} from '../behaviors/behavior.types'
|
|
1
|
+
import type {InternalBehaviorAction} from '../behaviors/behavior.types'
|
|
7
2
|
import type {EditorContext} from '../editor/editor-snapshot'
|
|
8
3
|
import {
|
|
9
4
|
addAnnotationActionImplementation,
|
|
@@ -18,18 +13,21 @@ import {
|
|
|
18
13
|
historyRedoActionImplementation,
|
|
19
14
|
historyUndoActionImplementation,
|
|
20
15
|
} from '../editor/plugins/createWithUndoRedo'
|
|
21
|
-
import {toSlatePath} from '../internal-utils/paths'
|
|
22
|
-
import {toSlateRange} from '../internal-utils/ranges'
|
|
23
|
-
import {toSlateValue} from '../internal-utils/values'
|
|
24
16
|
import type {PickFromUnion} from '../type-utils'
|
|
25
|
-
import {insertBlock} from './behavior.action-utils.insert-block'
|
|
26
17
|
import {blockSetBehaviorActionImplementation} from './behavior.action.block.set'
|
|
27
18
|
import {blockUnsetBehaviorActionImplementation} from './behavior.action.block.unset'
|
|
19
|
+
import {blurActionImplementation} from './behavior.action.blur'
|
|
28
20
|
import {dataTransferSetActionImplementation} from './behavior.action.data-transfer-set'
|
|
29
21
|
import {decoratorAddActionImplementation} from './behavior.action.decorator.add'
|
|
30
22
|
import {deleteActionImplementation} from './behavior.action.delete'
|
|
23
|
+
import {deleteBackwardActionImplementation} from './behavior.action.delete.backward'
|
|
24
|
+
import {deleteBlockActionImplementation} from './behavior.action.delete.block'
|
|
25
|
+
import {deleteForwardActionImplementation} from './behavior.action.delete.forward'
|
|
31
26
|
import {deleteTextActionImplementation} from './behavior.action.delete.text'
|
|
32
|
-
import {
|
|
27
|
+
import {deserializationFailureActionImplementation} from './behavior.action.deserialization.failure'
|
|
28
|
+
import {deserializationSuccessActionImplementation} from './behavior.action.deserialization.success'
|
|
29
|
+
import {effectActionImplementation} from './behavior.action.effect'
|
|
30
|
+
import {focusActionImplementation} from './behavior.action.focus'
|
|
33
31
|
import {insertBlocksActionImplementation} from './behavior.action.insert-blocks'
|
|
34
32
|
import {
|
|
35
33
|
insertBreakActionImplementation,
|
|
@@ -38,11 +36,23 @@ import {
|
|
|
38
36
|
import {insertInlineObjectActionImplementation} from './behavior.action.insert-inline-object'
|
|
39
37
|
import {insertSpanActionImplementation} from './behavior.action.insert-span'
|
|
40
38
|
import {insertBlockActionImplementation} from './behavior.action.insert.block'
|
|
39
|
+
import {insertBlockObjectActionImplementation} from './behavior.action.insert.block-object'
|
|
40
|
+
import {insertTextActionImplementation} from './behavior.action.insert.text'
|
|
41
|
+
import {insertTextBlockActionImplementation} from './behavior.action.insert.text-block'
|
|
41
42
|
import {
|
|
42
43
|
addListItemActionImplementation,
|
|
43
44
|
removeListItemActionImplementation,
|
|
44
45
|
toggleListItemActionImplementation,
|
|
45
46
|
} from './behavior.action.list-item'
|
|
47
|
+
import {moveBlockActionImplementation} from './behavior.action.move.block'
|
|
48
|
+
import {moveBlockDownActionImplementation} from './behavior.action.move.block-down'
|
|
49
|
+
import {moveBlockUpActionImplementation} from './behavior.action.move.block-up'
|
|
50
|
+
import {noopActionImplementation} from './behavior.action.noop'
|
|
51
|
+
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'
|
|
46
56
|
import {
|
|
47
57
|
addStyleActionImplementation,
|
|
48
58
|
removeStyleActionImplementation,
|
|
@@ -75,58 +85,19 @@ const behaviorActionImplementations: BehaviorActionImplementations = {
|
|
|
75
85
|
'annotation.toggle': toggleAnnotationActionImplementation,
|
|
76
86
|
'block.set': blockSetBehaviorActionImplementation,
|
|
77
87
|
'block.unset': blockUnsetBehaviorActionImplementation,
|
|
78
|
-
'blur':
|
|
79
|
-
ReactEditor.blur(action.editor)
|
|
80
|
-
},
|
|
88
|
+
'blur': blurActionImplementation,
|
|
81
89
|
'data transfer.set': dataTransferSetActionImplementation,
|
|
82
90
|
'decorator.add': decoratorAddActionImplementation,
|
|
83
91
|
'decorator.remove': removeDecoratorActionImplementation,
|
|
84
92
|
'decorator.toggle': toggleDecoratorActionImplementation,
|
|
85
|
-
'focus':
|
|
86
|
-
ReactEditor.focus(action.editor)
|
|
87
|
-
},
|
|
93
|
+
'focus': focusActionImplementation,
|
|
88
94
|
'delete': deleteActionImplementation,
|
|
89
|
-
'delete.backward':
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
'delete.forward': ({action}) => {
|
|
93
|
-
deleteForward(action.editor, action.unit)
|
|
94
|
-
},
|
|
95
|
-
'delete.block': ({action}) => {
|
|
96
|
-
const range = toSlateRange(
|
|
97
|
-
{
|
|
98
|
-
anchor: {path: action.blockPath, offset: 0},
|
|
99
|
-
focus: {path: action.blockPath, offset: 0},
|
|
100
|
-
},
|
|
101
|
-
action.editor,
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
if (!range) {
|
|
105
|
-
console.error('Unable to find Slate range from selection points')
|
|
106
|
-
return
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
Transforms.removeNodes(action.editor, {
|
|
110
|
-
at: range,
|
|
111
|
-
})
|
|
112
|
-
},
|
|
95
|
+
'delete.backward': deleteBackwardActionImplementation,
|
|
96
|
+
'delete.forward': deleteForwardActionImplementation,
|
|
97
|
+
'delete.block': deleteBlockActionImplementation,
|
|
113
98
|
'delete.text': deleteTextActionImplementation,
|
|
114
|
-
'deserialization.failure':
|
|
115
|
-
|
|
116
|
-
`Deserialization of ${action.mimeType} failed with reason "${action.reason}"`,
|
|
117
|
-
)
|
|
118
|
-
},
|
|
119
|
-
'deserialization.success': ({context, action}) => {
|
|
120
|
-
insertBlocksActionImplementation({
|
|
121
|
-
context,
|
|
122
|
-
action: {
|
|
123
|
-
type: 'insert.blocks',
|
|
124
|
-
blocks: action.data,
|
|
125
|
-
editor: action.editor,
|
|
126
|
-
placement: 'auto',
|
|
127
|
-
},
|
|
128
|
-
})
|
|
129
|
-
},
|
|
99
|
+
'deserialization.failure': deserializationFailureActionImplementation,
|
|
100
|
+
'deserialization.success': deserializationSuccessActionImplementation,
|
|
130
101
|
'history.redo': historyRedoActionImplementation,
|
|
131
102
|
'history.undo': historyUndoActionImplementation,
|
|
132
103
|
'insert.block': insertBlockActionImplementation,
|
|
@@ -136,132 +107,21 @@ const behaviorActionImplementations: BehaviorActionImplementations = {
|
|
|
136
107
|
'insert.inline object': insertInlineObjectActionImplementation,
|
|
137
108
|
'insert.soft break': insertSoftBreakActionImplementation,
|
|
138
109
|
'insert.span': insertSpanActionImplementation,
|
|
139
|
-
'insert.text':
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
'insert.text block': ({context, action}) => {
|
|
143
|
-
const block = toSlateValue(
|
|
144
|
-
[
|
|
145
|
-
{
|
|
146
|
-
_key: context.keyGenerator(),
|
|
147
|
-
_type: context.schema.block.name,
|
|
148
|
-
style: context.schema.styles[0].value ?? 'normal',
|
|
149
|
-
markDefs: [],
|
|
150
|
-
children: action.textBlock?.children?.map((child) => ({
|
|
151
|
-
...child,
|
|
152
|
-
_key: context.keyGenerator(),
|
|
153
|
-
})) ?? [
|
|
154
|
-
{
|
|
155
|
-
_type: context.schema.span.name,
|
|
156
|
-
_key: context.keyGenerator(),
|
|
157
|
-
text: '',
|
|
158
|
-
},
|
|
159
|
-
],
|
|
160
|
-
},
|
|
161
|
-
],
|
|
162
|
-
{schemaTypes: context.schema},
|
|
163
|
-
)[0]
|
|
164
|
-
|
|
165
|
-
insertBlock({
|
|
166
|
-
block,
|
|
167
|
-
editor: action.editor,
|
|
168
|
-
schema: context.schema,
|
|
169
|
-
placement: action.placement,
|
|
170
|
-
})
|
|
171
|
-
},
|
|
172
|
-
'effect': ({action}) => {
|
|
173
|
-
action.effect()
|
|
174
|
-
},
|
|
110
|
+
'insert.text': insertTextActionImplementation,
|
|
111
|
+
'insert.text block': insertTextBlockActionImplementation,
|
|
112
|
+
'effect': effectActionImplementation,
|
|
175
113
|
'list item.add': addListItemActionImplementation,
|
|
176
114
|
'list item.remove': removeListItemActionImplementation,
|
|
177
115
|
'list item.toggle': toggleListItemActionImplementation,
|
|
178
|
-
'move.block':
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
},
|
|
188
|
-
'move.block down': ({action}) => {
|
|
189
|
-
const at = [toSlatePath(action.at, action.editor)[0]]
|
|
190
|
-
const to = [Path.next(at)[0]]
|
|
191
|
-
|
|
192
|
-
Transforms.moveNodes(action.editor, {
|
|
193
|
-
at,
|
|
194
|
-
to,
|
|
195
|
-
mode: 'highest',
|
|
196
|
-
})
|
|
197
|
-
},
|
|
198
|
-
'move.block up': ({action}) => {
|
|
199
|
-
const at = [toSlatePath(action.at, action.editor)[0]]
|
|
200
|
-
|
|
201
|
-
if (!Path.hasPrevious(at)) {
|
|
202
|
-
return
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const to = [Path.previous(at)[0]]
|
|
206
|
-
|
|
207
|
-
Transforms.moveNodes(action.editor, {
|
|
208
|
-
at,
|
|
209
|
-
to,
|
|
210
|
-
mode: 'highest',
|
|
211
|
-
})
|
|
212
|
-
},
|
|
213
|
-
'noop': () => {},
|
|
214
|
-
'select': ({action}) => {
|
|
215
|
-
const newSelection = toSlateRange(action.selection, action.editor)
|
|
216
|
-
|
|
217
|
-
if (newSelection) {
|
|
218
|
-
Transforms.select(action.editor, newSelection)
|
|
219
|
-
} else {
|
|
220
|
-
Transforms.deselect(action.editor)
|
|
221
|
-
}
|
|
222
|
-
},
|
|
223
|
-
'select.previous block': ({action}) => {
|
|
224
|
-
if (!action.editor.selection) {
|
|
225
|
-
console.error('Unable to select previous block without a selection')
|
|
226
|
-
return
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const blockPath = action.editor.selection.focus.path.slice(0, 1)
|
|
230
|
-
|
|
231
|
-
if (!Path.hasPrevious(blockPath)) {
|
|
232
|
-
console.error("There's no previous block to select")
|
|
233
|
-
return
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
const previousBlockPath = Path.previous(blockPath)
|
|
237
|
-
|
|
238
|
-
Transforms.select(action.editor, previousBlockPath)
|
|
239
|
-
},
|
|
240
|
-
'select.next block': ({action}) => {
|
|
241
|
-
if (!action.editor.selection) {
|
|
242
|
-
console.error('Unable to select next block without a selection')
|
|
243
|
-
return
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
const blockPath = action.editor.selection.focus.path.slice(0, 1)
|
|
247
|
-
const nextBlockPath = [blockPath[0] + 1]
|
|
248
|
-
|
|
249
|
-
Transforms.select(action.editor, nextBlockPath)
|
|
250
|
-
},
|
|
251
|
-
'serialization.failure': ({action}) => {
|
|
252
|
-
console.warn(
|
|
253
|
-
`Serialization of ${action.mimeType} failed with reason "${action.reason}"`,
|
|
254
|
-
)
|
|
255
|
-
},
|
|
256
|
-
'serialization.success': ({context, action}) => {
|
|
257
|
-
dataTransferSetActionImplementation({
|
|
258
|
-
context,
|
|
259
|
-
action: {
|
|
260
|
-
...action,
|
|
261
|
-
type: 'data transfer.set',
|
|
262
|
-
},
|
|
263
|
-
})
|
|
264
|
-
},
|
|
116
|
+
'move.block': moveBlockActionImplementation,
|
|
117
|
+
'move.block down': moveBlockDownActionImplementation,
|
|
118
|
+
'move.block up': moveBlockUpActionImplementation,
|
|
119
|
+
'noop': noopActionImplementation,
|
|
120
|
+
'select': selectActionImplementation,
|
|
121
|
+
'select.previous block': selectPreviousBlockActionImplementation,
|
|
122
|
+
'select.next block': selectNextBlockActionImplementation,
|
|
123
|
+
'serialization.failure': serializationFailureActionImplementation,
|
|
124
|
+
'serialization.success': serializationSuccessActionImplementation,
|
|
265
125
|
'style.toggle': toggleStyleActionImplementation,
|
|
266
126
|
'style.add': addStyleActionImplementation,
|
|
267
127
|
'style.remove': removeStyleActionImplementation,
|
|
@@ -273,38 +133,6 @@ export function performAction({
|
|
|
273
133
|
}: {
|
|
274
134
|
context: BehaviorActionImplementationContext
|
|
275
135
|
action: InternalBehaviorAction
|
|
276
|
-
}) {
|
|
277
|
-
switch (action.type) {
|
|
278
|
-
case 'noop': {
|
|
279
|
-
behaviorActionImplementations.noop({
|
|
280
|
-
context,
|
|
281
|
-
action,
|
|
282
|
-
})
|
|
283
|
-
break
|
|
284
|
-
}
|
|
285
|
-
case 'effect': {
|
|
286
|
-
behaviorActionImplementations.effect({
|
|
287
|
-
context,
|
|
288
|
-
action,
|
|
289
|
-
})
|
|
290
|
-
break
|
|
291
|
-
}
|
|
292
|
-
default: {
|
|
293
|
-
performDefaultAction({context, action})
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
function performDefaultAction({
|
|
299
|
-
context,
|
|
300
|
-
action,
|
|
301
|
-
}: {
|
|
302
|
-
context: BehaviorActionImplementationContext
|
|
303
|
-
action: PickFromUnion<
|
|
304
|
-
InternalBehaviorAction,
|
|
305
|
-
'type',
|
|
306
|
-
SyntheticBehaviorEvent['type']
|
|
307
|
-
>
|
|
308
136
|
}) {
|
|
309
137
|
switch (action.type) {
|
|
310
138
|
case 'annotation.add': {
|
|
@@ -426,6 +254,13 @@ function performDefaultAction({
|
|
|
426
254
|
})
|
|
427
255
|
break
|
|
428
256
|
}
|
|
257
|
+
case 'effect': {
|
|
258
|
+
behaviorActionImplementations.effect({
|
|
259
|
+
context,
|
|
260
|
+
action,
|
|
261
|
+
})
|
|
262
|
+
break
|
|
263
|
+
}
|
|
429
264
|
case 'focus': {
|
|
430
265
|
behaviorActionImplementations.focus({
|
|
431
266
|
context,
|
|
@@ -552,6 +387,13 @@ function performDefaultAction({
|
|
|
552
387
|
})
|
|
553
388
|
break
|
|
554
389
|
}
|
|
390
|
+
case 'noop': {
|
|
391
|
+
behaviorActionImplementations.noop({
|
|
392
|
+
context,
|
|
393
|
+
action,
|
|
394
|
+
})
|
|
395
|
+
break
|
|
396
|
+
}
|
|
555
397
|
case 'select': {
|
|
556
398
|
behaviorActionImplementations.select({
|
|
557
399
|
context,
|
|
@@ -25,12 +25,7 @@ const arrowUpOnLonelyBlockObject = defineBehavior({
|
|
|
25
25
|
|
|
26
26
|
return isArrowUp && focusBlockObject && !previousBlock
|
|
27
27
|
},
|
|
28
|
-
actions: [
|
|
29
|
-
() => [
|
|
30
|
-
raise({type: 'insert.text block', placement: 'before'}),
|
|
31
|
-
raise({type: 'select.previous block'}),
|
|
32
|
-
],
|
|
33
|
-
],
|
|
28
|
+
actions: [() => [raise({type: 'insert.text block', placement: 'before'})]],
|
|
34
29
|
})
|
|
35
30
|
|
|
36
31
|
const breakingBlockObject = defineBehavior({
|
|
@@ -44,6 +39,38 @@ const breakingBlockObject = defineBehavior({
|
|
|
44
39
|
actions: [() => [raise({type: 'insert.text block', placement: 'after'})]],
|
|
45
40
|
})
|
|
46
41
|
|
|
42
|
+
const clickingAboveLonelyBlockObject = defineBehavior({
|
|
43
|
+
on: 'mouse.click',
|
|
44
|
+
guard: ({snapshot, event}) => {
|
|
45
|
+
const focusBlockObject = selectors.getFocusBlockObject(snapshot)
|
|
46
|
+
const previousBlock = selectors.getPreviousBlock(snapshot)
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
event.position.isEditor &&
|
|
50
|
+
event.position.block === 'start' &&
|
|
51
|
+
focusBlockObject &&
|
|
52
|
+
!previousBlock
|
|
53
|
+
)
|
|
54
|
+
},
|
|
55
|
+
actions: [() => [raise({type: 'insert.text block', placement: 'before'})]],
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const clickingBelowLonelyBlockObject = defineBehavior({
|
|
59
|
+
on: 'mouse.click',
|
|
60
|
+
guard: ({snapshot, event}) => {
|
|
61
|
+
const focusBlockObject = selectors.getFocusBlockObject(snapshot)
|
|
62
|
+
const nextBlock = selectors.getNextBlock(snapshot)
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
event.position.isEditor &&
|
|
66
|
+
event.position.block === 'end' &&
|
|
67
|
+
focusBlockObject &&
|
|
68
|
+
!nextBlock
|
|
69
|
+
)
|
|
70
|
+
},
|
|
71
|
+
actions: [() => [raise({type: 'insert.text block', placement: 'after'})]],
|
|
72
|
+
})
|
|
73
|
+
|
|
47
74
|
const deletingEmptyTextBlockAfterBlockObject = defineBehavior({
|
|
48
75
|
on: 'delete.backward',
|
|
49
76
|
guard: ({snapshot}) => {
|
|
@@ -122,6 +149,8 @@ export const coreBlockObjectBehaviors = {
|
|
|
122
149
|
arrowDownOnLonelyBlockObject,
|
|
123
150
|
arrowUpOnLonelyBlockObject,
|
|
124
151
|
breakingBlockObject,
|
|
152
|
+
clickingAboveLonelyBlockObject,
|
|
153
|
+
clickingBelowLonelyBlockObject,
|
|
125
154
|
deletingEmptyTextBlockAfterBlockObject,
|
|
126
155
|
deletingEmptyTextBlockBeforeBlockObject,
|
|
127
156
|
}
|
|
@@ -13,6 +13,8 @@ export const coreBehaviors = [
|
|
|
13
13
|
coreDecoratorBehaviors.emShortcut,
|
|
14
14
|
coreDecoratorBehaviors.underlineShortcut,
|
|
15
15
|
coreDecoratorBehaviors.codeShortcut,
|
|
16
|
+
coreBlockObjectBehaviors.clickingAboveLonelyBlockObject,
|
|
17
|
+
coreBlockObjectBehaviors.clickingBelowLonelyBlockObject,
|
|
16
18
|
coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject,
|
|
17
19
|
coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject,
|
|
18
20
|
coreBlockObjectBehaviors.breakingBlockObject,
|