@portabletext/editor 1.50.8 → 1.52.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/{util.slice-blocks.cjs → selection-point.cjs} +26 -18
- package/lib/_chunks-cjs/selection-point.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.get-text-before.cjs +13 -10
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +46 -46
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs +21 -17
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -1
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs +10 -10
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-cjs/util.is-equal-selection-points.cjs +5 -5
- package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +1 -1
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs +3 -3
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +7 -14
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-es/{util.slice-blocks.js → selection-point.js} +26 -18
- package/lib/_chunks-es/selection-point.js.map +1 -0
- package/lib/_chunks-es/selector.get-text-before.js +13 -10
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +21 -21
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/selector.is-selection-expanded.js +14 -10
- package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -1
- package/lib/_chunks-es/util.child-selection-point-to-block-offset.js +2 -2
- package/lib/_chunks-es/util.child-selection-point-to-block-offset.js.map +1 -1
- package/lib/_chunks-es/util.is-equal-selection-points.js +1 -1
- package/lib/_chunks-es/util.merge-text-blocks.js +1 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js +4 -11
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +25 -2010
- package/lib/behaviors/index.d.ts +25 -2010
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +515 -393
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +361 -34
- package/lib/index.d.ts +361 -34
- package/lib/index.js +471 -349
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +11 -11
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +32 -1986
- package/lib/plugins/index.d.ts +32 -1986
- package/lib/plugins/index.js +1 -1
- package/lib/selectors/index.cjs +11 -7
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +2 -2648
- package/lib/selectors/index.d.ts +2 -2648
- package/lib/selectors/index.js +7 -3
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +25 -14
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +0 -2647
- package/lib/utils/index.d.ts +0 -2647
- package/lib/utils/index.js +14 -3
- package/lib/utils/index.js.map +1 -1
- package/package.json +14 -14
- package/src/behaviors/behavior.abstract.delete.ts +0 -2
- package/src/behaviors/behavior.abstract.insert.ts +8 -8
- package/src/behaviors/behavior.abstract.ts +0 -113
- package/src/behaviors/behavior.core.block-element.ts +9 -3
- package/src/behaviors/behavior.core.dnd.ts +328 -1
- package/src/behaviors/behavior.perform-event.ts +10 -0
- package/src/behaviors/behavior.types.action.ts +2 -0
- package/src/behaviors/behavior.types.event.ts +5 -0
- package/src/behaviors/behavior.types.guard.ts +2 -0
- package/src/converters/converter.portable-text.ts +2 -7
- package/src/converters/converter.text-html.ts +1 -3
- package/src/converters/converter.text-plain.ts +3 -5
- package/src/editor/Editable.tsx +6 -133
- package/src/editor/editor-machine.ts +15 -10
- package/src/editor/editor-selector.ts +0 -2
- package/src/editor/editor-snapshot.ts +0 -18
- package/src/internal-utils/create-test-snapshot.ts +0 -2
- package/src/internal-utils/event-position.ts +42 -30
- package/src/internal-utils/selection-block-keys.ts +7 -7
- package/src/internal-utils/selection-elements.ts +108 -0
- package/src/internal-utils/selection-focus-text.ts +13 -9
- package/src/internal-utils/selection-text.ts +9 -78
- package/src/internal-utils/terse-pt.test.ts +108 -26
- package/src/internal-utils/terse-pt.ts +132 -14
- package/src/operations/behavior.operation.decorator.add.ts +0 -2
- package/src/operations/behavior.operation.delete.ts +18 -13
- package/src/operations/behavior.operation.insert.block.ts +5 -1
- package/src/selection/selection-point.ts +22 -0
- package/src/selectors/selector.get-anchor-block.ts +6 -6
- package/src/selectors/selector.get-anchor-child.ts +6 -6
- package/src/selectors/selector.get-selected-spans.ts +16 -19
- package/src/selectors/selector.get-selected-text-blocks.ts +11 -19
- package/src/selectors/selector.get-selection-end-block.ts +30 -0
- package/src/selectors/selector.get-selection-start-block.ts +30 -0
- package/src/selectors/selector.get-text-before.ts +15 -16
- package/src/selectors/selector.get-trimmed-selection.ts +15 -21
- package/src/selectors/selector.is-point-after-selection.ts +11 -19
- package/src/selectors/selector.is-point-before-selection.ts +11 -19
- package/src/selectors/selectors.ts +23 -39
- package/src/utils/util.block-offset.ts +6 -7
- package/src/utils/util.child-selection-point-to-block-offset.ts +6 -7
- package/src/utils/util.selection-point-to-block-offset.ts +5 -6
- package/src/utils/util.slice-blocks.ts +11 -20
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +0 -1
- package/lib/_chunks-es/util.slice-blocks.js.map +0 -1
- package/src/internal-utils/inline-object-selection.ts +0 -115
|
@@ -1,7 +1,176 @@
|
|
|
1
|
+
import {getCompoundClientRect} from '../internal-utils/compound-client-rect'
|
|
2
|
+
import {getDragSelection} from '../internal-utils/drag-selection'
|
|
1
3
|
import * as selectors from '../selectors'
|
|
4
|
+
import {effect, forward, raise} from './behavior.types.action'
|
|
2
5
|
import {defineBehavior} from './behavior.types.behavior'
|
|
3
6
|
|
|
4
7
|
export const coreDndBehaviors = [
|
|
8
|
+
/**
|
|
9
|
+
* Core Behavior that:
|
|
10
|
+
* 1. Calculates and selects a "drag selection"
|
|
11
|
+
* 2. Constructs and sets a drag ghost element
|
|
12
|
+
* 3. Forwards the dragstart event
|
|
13
|
+
*/
|
|
14
|
+
defineBehavior({
|
|
15
|
+
on: 'drag.dragstart',
|
|
16
|
+
guard: ({snapshot, dom, event}) => {
|
|
17
|
+
const dragSelection = getDragSelection({
|
|
18
|
+
snapshot,
|
|
19
|
+
eventSelection: event.position.selection,
|
|
20
|
+
})
|
|
21
|
+
const selectingEntireBlocks = selectors.isSelectingEntireBlocks({
|
|
22
|
+
...snapshot,
|
|
23
|
+
context: {
|
|
24
|
+
...snapshot.context,
|
|
25
|
+
selection: dragSelection,
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
const draggedDomNodes = {
|
|
29
|
+
blockNodes: dom.getBlockNodes({
|
|
30
|
+
...snapshot,
|
|
31
|
+
context: {
|
|
32
|
+
...snapshot.context,
|
|
33
|
+
selection: dragSelection,
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
childNodes: dom.getChildNodes({
|
|
37
|
+
...snapshot,
|
|
38
|
+
context: {
|
|
39
|
+
...snapshot.context,
|
|
40
|
+
selection: dragSelection,
|
|
41
|
+
},
|
|
42
|
+
}),
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
dragSelection,
|
|
47
|
+
draggedDomNodes,
|
|
48
|
+
selectingEntireBlocks,
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
actions: [
|
|
52
|
+
(
|
|
53
|
+
{dom, event},
|
|
54
|
+
{dragSelection, draggedDomNodes, selectingEntireBlocks},
|
|
55
|
+
) => {
|
|
56
|
+
const dragGhost = document.createElement('div')
|
|
57
|
+
|
|
58
|
+
if (selectingEntireBlocks) {
|
|
59
|
+
// Clone the DOM Nodes so they won't be visually clipped by scroll-containers etc.
|
|
60
|
+
const clonedBlockNodes = draggedDomNodes.blockNodes.map((node) =>
|
|
61
|
+
node.cloneNode(true),
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
for (const block of clonedBlockNodes) {
|
|
65
|
+
if (block instanceof HTMLElement) {
|
|
66
|
+
block.style.position = 'relative'
|
|
67
|
+
}
|
|
68
|
+
dragGhost.appendChild(block)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// A custom drag ghost element can be configured using this data attribute
|
|
72
|
+
const customGhost = dragGhost.querySelector(
|
|
73
|
+
'[data-pt-drag-ghost-element]',
|
|
74
|
+
)
|
|
75
|
+
if (customGhost) {
|
|
76
|
+
dragGhost.replaceChildren(customGhost)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Setting the `data-dragged` attribute so the consumer can style the element while it’s dragged
|
|
80
|
+
dragGhost.setAttribute('data-dragged', '')
|
|
81
|
+
|
|
82
|
+
dragGhost.style.position = 'absolute'
|
|
83
|
+
dragGhost.style.left = '-99999px'
|
|
84
|
+
dragGhost.style.boxSizing = 'border-box'
|
|
85
|
+
document.body.appendChild(dragGhost)
|
|
86
|
+
|
|
87
|
+
if (customGhost) {
|
|
88
|
+
const customGhostRect = customGhost.getBoundingClientRect()
|
|
89
|
+
const x = event.originEvent.clientX - customGhostRect.left
|
|
90
|
+
const y = event.originEvent.clientY - customGhostRect.top
|
|
91
|
+
dragGhost.style.width = `${customGhostRect.width}px`
|
|
92
|
+
dragGhost.style.height = `${customGhostRect.height}px`
|
|
93
|
+
|
|
94
|
+
return [
|
|
95
|
+
raise({
|
|
96
|
+
type: 'select',
|
|
97
|
+
at: dragSelection,
|
|
98
|
+
}),
|
|
99
|
+
effect(() => {
|
|
100
|
+
dom.setDragGhost({
|
|
101
|
+
event,
|
|
102
|
+
ghost: {
|
|
103
|
+
element: dragGhost,
|
|
104
|
+
x,
|
|
105
|
+
y,
|
|
106
|
+
},
|
|
107
|
+
})
|
|
108
|
+
}),
|
|
109
|
+
forward(event),
|
|
110
|
+
]
|
|
111
|
+
} else {
|
|
112
|
+
const blocksDomRect = getCompoundClientRect(
|
|
113
|
+
draggedDomNodes.blockNodes,
|
|
114
|
+
)
|
|
115
|
+
const x = event.originEvent.clientX - blocksDomRect.left
|
|
116
|
+
const y = event.originEvent.clientY - blocksDomRect.top
|
|
117
|
+
dragGhost.style.width = `${blocksDomRect.width}px`
|
|
118
|
+
dragGhost.style.height = `${blocksDomRect.height}px`
|
|
119
|
+
|
|
120
|
+
return [
|
|
121
|
+
raise({
|
|
122
|
+
type: 'select',
|
|
123
|
+
at: dragSelection,
|
|
124
|
+
}),
|
|
125
|
+
effect(() => {
|
|
126
|
+
dom.setDragGhost({
|
|
127
|
+
event,
|
|
128
|
+
ghost: {element: dragGhost, x, y},
|
|
129
|
+
})
|
|
130
|
+
}),
|
|
131
|
+
forward(event),
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
const clonedChildNodes = draggedDomNodes.childNodes.map((node) =>
|
|
136
|
+
node.cloneNode(true),
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
for (const child of clonedChildNodes) {
|
|
140
|
+
dragGhost.appendChild(child)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
dragGhost.style.position = 'absolute'
|
|
144
|
+
dragGhost.style.left = '-99999px'
|
|
145
|
+
dragGhost.style.boxSizing = 'border-box'
|
|
146
|
+
document.body.appendChild(dragGhost)
|
|
147
|
+
|
|
148
|
+
const childrenDomRect = getCompoundClientRect(
|
|
149
|
+
draggedDomNodes.childNodes,
|
|
150
|
+
)
|
|
151
|
+
const x = event.originEvent.clientX - childrenDomRect.left
|
|
152
|
+
const y = event.originEvent.clientY - childrenDomRect.top
|
|
153
|
+
dragGhost.style.width = `${childrenDomRect.width}px`
|
|
154
|
+
dragGhost.style.height = `${childrenDomRect.height}px`
|
|
155
|
+
|
|
156
|
+
return [
|
|
157
|
+
raise({
|
|
158
|
+
type: 'select',
|
|
159
|
+
at: dragSelection,
|
|
160
|
+
}),
|
|
161
|
+
effect(() => {
|
|
162
|
+
dom.setDragGhost({
|
|
163
|
+
event,
|
|
164
|
+
ghost: {element: dragGhost, x, y},
|
|
165
|
+
})
|
|
166
|
+
}),
|
|
167
|
+
forward(event),
|
|
168
|
+
]
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
}),
|
|
173
|
+
|
|
5
174
|
/**
|
|
6
175
|
* When dragging over the drag origin, we don't want to show the caret in the
|
|
7
176
|
* text.
|
|
@@ -9,7 +178,7 @@ export const coreDndBehaviors = [
|
|
|
9
178
|
defineBehavior({
|
|
10
179
|
on: 'drag.dragover',
|
|
11
180
|
guard: ({snapshot, event}) => {
|
|
12
|
-
const dragOrigin =
|
|
181
|
+
const dragOrigin = event.dragOrigin
|
|
13
182
|
const draggingOverDragOrigin = dragOrigin
|
|
14
183
|
? selectors.isOverlappingSelection(event.position.selection)({
|
|
15
184
|
...snapshot,
|
|
@@ -24,4 +193,162 @@ export const coreDndBehaviors = [
|
|
|
24
193
|
},
|
|
25
194
|
actions: [],
|
|
26
195
|
}),
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* If the drop position overlaps the drag origin, then the event should be
|
|
199
|
+
* cancelled.
|
|
200
|
+
*/
|
|
201
|
+
defineBehavior({
|
|
202
|
+
on: 'drag.drop',
|
|
203
|
+
guard: ({snapshot, event}) => {
|
|
204
|
+
const dragOrigin = event.dragOrigin
|
|
205
|
+
const dropPosition = event.position.selection
|
|
206
|
+
const droppingOnDragOrigin = dragOrigin
|
|
207
|
+
? selectors.isOverlappingSelection(dropPosition)({
|
|
208
|
+
...snapshot,
|
|
209
|
+
context: {
|
|
210
|
+
...snapshot.context,
|
|
211
|
+
selection: dragOrigin.selection,
|
|
212
|
+
},
|
|
213
|
+
})
|
|
214
|
+
: false
|
|
215
|
+
return droppingOnDragOrigin
|
|
216
|
+
},
|
|
217
|
+
actions: [],
|
|
218
|
+
}),
|
|
219
|
+
/**
|
|
220
|
+
* If we drop and have access to a drag origin, then we can deserialize
|
|
221
|
+
* without creating a new selection.
|
|
222
|
+
*/
|
|
223
|
+
defineBehavior({
|
|
224
|
+
on: 'drag.drop',
|
|
225
|
+
guard: ({event}) => event.dragOrigin !== undefined,
|
|
226
|
+
actions: [
|
|
227
|
+
({event}) => [
|
|
228
|
+
raise({
|
|
229
|
+
type: 'deserialize',
|
|
230
|
+
originEvent: event,
|
|
231
|
+
}),
|
|
232
|
+
],
|
|
233
|
+
],
|
|
234
|
+
}),
|
|
235
|
+
/**
|
|
236
|
+
* Otherwise, we should to create a new selection.
|
|
237
|
+
*/
|
|
238
|
+
defineBehavior({
|
|
239
|
+
on: 'drag.drop',
|
|
240
|
+
actions: [
|
|
241
|
+
({event}) => [
|
|
242
|
+
raise({
|
|
243
|
+
type: 'select',
|
|
244
|
+
at: event.position.selection,
|
|
245
|
+
}),
|
|
246
|
+
raise({
|
|
247
|
+
type: 'deserialize',
|
|
248
|
+
originEvent: event,
|
|
249
|
+
}),
|
|
250
|
+
],
|
|
251
|
+
],
|
|
252
|
+
}),
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Core Behavior that uses the drag origin to mimic a move operation during
|
|
256
|
+
* internal dragging.
|
|
257
|
+
*/
|
|
258
|
+
defineBehavior({
|
|
259
|
+
on: 'deserialization.success',
|
|
260
|
+
guard: ({snapshot, event}) => {
|
|
261
|
+
if (
|
|
262
|
+
event.originEvent.type !== 'drag.drop' ||
|
|
263
|
+
event.originEvent.dragOrigin === undefined
|
|
264
|
+
) {
|
|
265
|
+
return false
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const dragOrigin = event.originEvent.dragOrigin
|
|
269
|
+
const dragSelection = getDragSelection({
|
|
270
|
+
eventSelection: dragOrigin.selection,
|
|
271
|
+
snapshot,
|
|
272
|
+
})
|
|
273
|
+
const dropPosition = event.originEvent.position.selection
|
|
274
|
+
const droppingOnDragOrigin = dragOrigin
|
|
275
|
+
? selectors.isOverlappingSelection(dropPosition)({
|
|
276
|
+
...snapshot,
|
|
277
|
+
context: {
|
|
278
|
+
...snapshot.context,
|
|
279
|
+
selection: dragSelection,
|
|
280
|
+
},
|
|
281
|
+
})
|
|
282
|
+
: false
|
|
283
|
+
|
|
284
|
+
const draggingEntireBlocks = selectors.isSelectingEntireBlocks({
|
|
285
|
+
...snapshot,
|
|
286
|
+
context: {
|
|
287
|
+
...snapshot.context,
|
|
288
|
+
selection: dragSelection,
|
|
289
|
+
},
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
const draggedBlocks = selectors.getSelectedBlocks({
|
|
293
|
+
...snapshot,
|
|
294
|
+
context: {
|
|
295
|
+
...snapshot.context,
|
|
296
|
+
selection: dragSelection,
|
|
297
|
+
},
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
if (!droppingOnDragOrigin) {
|
|
301
|
+
return {
|
|
302
|
+
dropPosition,
|
|
303
|
+
draggingEntireBlocks,
|
|
304
|
+
draggedBlocks,
|
|
305
|
+
dragOrigin,
|
|
306
|
+
originEvent: event.originEvent,
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return false
|
|
311
|
+
},
|
|
312
|
+
actions: [
|
|
313
|
+
(
|
|
314
|
+
{event},
|
|
315
|
+
{
|
|
316
|
+
draggingEntireBlocks,
|
|
317
|
+
draggedBlocks,
|
|
318
|
+
dragOrigin,
|
|
319
|
+
dropPosition,
|
|
320
|
+
originEvent,
|
|
321
|
+
},
|
|
322
|
+
) => [
|
|
323
|
+
...(draggingEntireBlocks
|
|
324
|
+
? draggedBlocks.map((block) =>
|
|
325
|
+
raise({
|
|
326
|
+
type: 'delete.block',
|
|
327
|
+
at: block.path,
|
|
328
|
+
}),
|
|
329
|
+
)
|
|
330
|
+
: [
|
|
331
|
+
raise({
|
|
332
|
+
type: 'delete',
|
|
333
|
+
at: dragOrigin.selection,
|
|
334
|
+
}),
|
|
335
|
+
]),
|
|
336
|
+
raise({
|
|
337
|
+
type: 'select',
|
|
338
|
+
at: dropPosition,
|
|
339
|
+
}),
|
|
340
|
+
raise({
|
|
341
|
+
type: 'insert.blocks',
|
|
342
|
+
blocks: event.data,
|
|
343
|
+
placement: draggingEntireBlocks
|
|
344
|
+
? originEvent.position.block === 'start'
|
|
345
|
+
? 'before'
|
|
346
|
+
: originEvent.position.block === 'end'
|
|
347
|
+
? 'after'
|
|
348
|
+
: 'auto'
|
|
349
|
+
: 'auto',
|
|
350
|
+
}),
|
|
351
|
+
],
|
|
352
|
+
],
|
|
353
|
+
}),
|
|
27
354
|
]
|
|
@@ -3,6 +3,7 @@ import type {EditorSnapshot} from '../editor/editor-snapshot'
|
|
|
3
3
|
import {withApplyingBehaviorOperations} from '../editor/with-applying-behavior-operations'
|
|
4
4
|
import {withUndoStep} from '../editor/with-undo-step'
|
|
5
5
|
import {debugWithName} from '../internal-utils/debug'
|
|
6
|
+
import {createEditorDom} from '../internal-utils/selection-elements'
|
|
6
7
|
import {performOperation} from '../operations/behavior.operations'
|
|
7
8
|
import type {PortableTextSlateEditor} from '../types/editor'
|
|
8
9
|
import {abstractBehaviors} from './behavior.abstract'
|
|
@@ -38,6 +39,7 @@ export function performEvent({
|
|
|
38
39
|
schema,
|
|
39
40
|
getSnapshot,
|
|
40
41
|
nativeEvent,
|
|
42
|
+
sendBack,
|
|
41
43
|
}: {
|
|
42
44
|
mode: 'raise' | 'execute' | 'forward'
|
|
43
45
|
behaviors: Array<Behavior>
|
|
@@ -52,6 +54,7 @@ export function performEvent({
|
|
|
52
54
|
preventDefault: () => void
|
|
53
55
|
}
|
|
54
56
|
| undefined
|
|
57
|
+
sendBack: (event: {type: 'set drag ghost'; ghost: HTMLElement}) => void
|
|
55
58
|
}) {
|
|
56
59
|
debug(`(${mode}:${eventCategory(event)})`, JSON.stringify(event, null, 2))
|
|
57
60
|
|
|
@@ -135,6 +138,7 @@ export function performEvent({
|
|
|
135
138
|
eventBehavior.guard({
|
|
136
139
|
snapshot: guardSnapshot,
|
|
137
140
|
event,
|
|
141
|
+
dom: createEditorDom(sendBack, editor),
|
|
138
142
|
})
|
|
139
143
|
} catch (error) {
|
|
140
144
|
console.error(
|
|
@@ -162,6 +166,7 @@ export function performEvent({
|
|
|
162
166
|
{
|
|
163
167
|
snapshot: actionsSnapshot,
|
|
164
168
|
event,
|
|
169
|
+
dom: createEditorDom(sendBack, editor),
|
|
165
170
|
},
|
|
166
171
|
shouldRun,
|
|
167
172
|
)
|
|
@@ -215,6 +220,7 @@ export function performEvent({
|
|
|
215
220
|
schema,
|
|
216
221
|
getSnapshot,
|
|
217
222
|
nativeEvent,
|
|
223
|
+
sendBack,
|
|
218
224
|
})
|
|
219
225
|
|
|
220
226
|
continue
|
|
@@ -233,6 +239,7 @@ export function performEvent({
|
|
|
233
239
|
schema,
|
|
234
240
|
getSnapshot,
|
|
235
241
|
nativeEvent,
|
|
242
|
+
sendBack,
|
|
236
243
|
})
|
|
237
244
|
|
|
238
245
|
continue
|
|
@@ -252,6 +259,7 @@ export function performEvent({
|
|
|
252
259
|
schema,
|
|
253
260
|
getSnapshot,
|
|
254
261
|
nativeEvent: undefined,
|
|
262
|
+
sendBack,
|
|
255
263
|
})
|
|
256
264
|
}
|
|
257
265
|
})
|
|
@@ -291,6 +299,7 @@ export function performEvent({
|
|
|
291
299
|
schema,
|
|
292
300
|
getSnapshot,
|
|
293
301
|
nativeEvent,
|
|
302
|
+
sendBack,
|
|
294
303
|
})
|
|
295
304
|
|
|
296
305
|
continue
|
|
@@ -309,6 +318,7 @@ export function performEvent({
|
|
|
309
318
|
schema,
|
|
310
319
|
getSnapshot,
|
|
311
320
|
nativeEvent,
|
|
321
|
+
sendBack,
|
|
312
322
|
})
|
|
313
323
|
|
|
314
324
|
continue
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type {EditorSnapshot} from '../editor/editor-snapshot'
|
|
2
|
+
import type {EditorDom} from '../internal-utils/selection-elements'
|
|
2
3
|
import type {PickFromUnion} from '../type-utils'
|
|
3
4
|
import type {
|
|
4
5
|
CustomBehaviorEvent,
|
|
@@ -70,6 +71,7 @@ export type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (
|
|
|
70
71
|
payload: {
|
|
71
72
|
snapshot: EditorSnapshot
|
|
72
73
|
event: TBehaviorEvent
|
|
74
|
+
dom: EditorDom
|
|
73
75
|
},
|
|
74
76
|
guardResponse: TGuardResponse,
|
|
75
77
|
) => Array<BehaviorAction>
|
|
@@ -337,6 +337,7 @@ type AbstractBehaviorEvent =
|
|
|
337
337
|
type: StrictExtract<SyntheticBehaviorEventType, 'insert.blocks'>
|
|
338
338
|
blocks: Array<BlockWithOptionalKey>
|
|
339
339
|
placement: InsertPlacement
|
|
340
|
+
select?: 'start' | 'end' | 'none'
|
|
340
341
|
}
|
|
341
342
|
| {
|
|
342
343
|
type: StrictExtract<SyntheticBehaviorEventType, 'insert.break'>
|
|
@@ -462,6 +463,8 @@ type DragBehaviorEvent =
|
|
|
462
463
|
| {
|
|
463
464
|
type: StrictExtract<NativeBehaviorEventType, 'drag.dragstart'>
|
|
464
465
|
originEvent: {
|
|
466
|
+
clientX: number
|
|
467
|
+
clientY: number
|
|
465
468
|
dataTransfer: DataTransfer
|
|
466
469
|
}
|
|
467
470
|
position: Pick<EventPosition, 'selection'>
|
|
@@ -490,6 +493,7 @@ type DragBehaviorEvent =
|
|
|
490
493
|
originEvent: {
|
|
491
494
|
dataTransfer: DataTransfer
|
|
492
495
|
}
|
|
496
|
+
dragOrigin?: Pick<EventPosition, 'selection'>
|
|
493
497
|
position: EventPosition
|
|
494
498
|
}
|
|
495
499
|
| {
|
|
@@ -497,6 +501,7 @@ type DragBehaviorEvent =
|
|
|
497
501
|
originEvent: {
|
|
498
502
|
dataTransfer: DataTransfer
|
|
499
503
|
}
|
|
504
|
+
dragOrigin?: Pick<EventPosition, 'selection'>
|
|
500
505
|
position: EventPosition
|
|
501
506
|
}
|
|
502
507
|
| {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type {EditorSnapshot} from '../editor/editor-snapshot'
|
|
2
|
+
import type {EditorDom} from '../internal-utils/selection-elements'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @beta
|
|
@@ -6,4 +7,5 @@ import type {EditorSnapshot} from '../editor/editor-snapshot'
|
|
|
6
7
|
export type BehaviorGuard<TBehaviorEvent, TGuardResponse> = (payload: {
|
|
7
8
|
snapshot: EditorSnapshot
|
|
8
9
|
event: TBehaviorEvent
|
|
10
|
+
dom: EditorDom
|
|
9
11
|
}) => TGuardResponse | false
|
|
@@ -5,8 +5,7 @@ import {defineConverter} from './converter.types'
|
|
|
5
5
|
export const converterPortableText = defineConverter({
|
|
6
6
|
mimeType: 'application/x-portable-text',
|
|
7
7
|
serialize: ({snapshot, event}) => {
|
|
8
|
-
const selection =
|
|
9
|
-
snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection
|
|
8
|
+
const selection = snapshot.context.selection
|
|
10
9
|
|
|
11
10
|
if (!selection) {
|
|
12
11
|
return {
|
|
@@ -57,11 +56,7 @@ export const converterPortableText = defineConverter({
|
|
|
57
56
|
context: snapshot.context,
|
|
58
57
|
block,
|
|
59
58
|
options: {
|
|
60
|
-
|
|
61
|
-
* If we are dragging internally then we would like to keep the
|
|
62
|
-
* dropped portable text as is.
|
|
63
|
-
*/
|
|
64
|
-
refreshKeys: !snapshot.beta.hasTag?.('dragging internally'),
|
|
59
|
+
refreshKeys: true,
|
|
65
60
|
validateFields: false,
|
|
66
61
|
},
|
|
67
62
|
})
|
|
@@ -12,9 +12,7 @@ export function createConverterTextHtml(
|
|
|
12
12
|
return defineConverter({
|
|
13
13
|
mimeType: 'text/html',
|
|
14
14
|
serialize: ({snapshot, event}) => {
|
|
15
|
-
const selection =
|
|
16
|
-
snapshot.beta.internalDrag?.origin.selection ??
|
|
17
|
-
snapshot.context.selection
|
|
15
|
+
const selection = snapshot.context.selection
|
|
18
16
|
|
|
19
17
|
if (!selection) {
|
|
20
18
|
return {
|
|
@@ -11,9 +11,7 @@ export function createConverterTextPlain(
|
|
|
11
11
|
return defineConverter({
|
|
12
12
|
mimeType: 'text/plain',
|
|
13
13
|
serialize: ({snapshot, event}) => {
|
|
14
|
-
const selection =
|
|
15
|
-
snapshot.beta.internalDrag?.origin.selection ??
|
|
16
|
-
snapshot.context.selection
|
|
14
|
+
const selection = snapshot.context.selection
|
|
17
15
|
|
|
18
16
|
if (!selection) {
|
|
19
17
|
return {
|
|
@@ -41,7 +39,7 @@ export function createConverterTextPlain(
|
|
|
41
39
|
return child.text
|
|
42
40
|
}
|
|
43
41
|
|
|
44
|
-
return
|
|
42
|
+
return event.originEvent === 'drag.dragstart'
|
|
45
43
|
? `[${
|
|
46
44
|
snapshot.context.schema.inlineObjects.find(
|
|
47
45
|
(inlineObjectType) =>
|
|
@@ -53,7 +51,7 @@ export function createConverterTextPlain(
|
|
|
53
51
|
.join('')
|
|
54
52
|
}
|
|
55
53
|
|
|
56
|
-
return
|
|
54
|
+
return event.originEvent === 'drag.dragstart'
|
|
57
55
|
? `[${
|
|
58
56
|
snapshot.context.schema.blockObjects.find(
|
|
59
57
|
(blockObjectType) => blockObjectType.name === block._type,
|