@portabletext/editor 1.40.4 → 1.41.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/editor-provider.cjs +11 -6
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs +4 -0
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +11 -6
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/util.is-selection-collapsed.js +4 -0
- package/lib/_chunks-es/util.is-selection-collapsed.js.map +1 -1
- package/lib/index.cjs +260 -131
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +262 -133
- package/lib/index.js.map +1 -1
- package/lib/utils/index.cjs +5 -0
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +22 -0
- package/lib/utils/index.d.ts +22 -0
- package/lib/utils/index.js +6 -1
- package/lib/utils/index.js.map +1 -1
- package/package.json +2 -2
- package/src/converters/converter.text-plain.ts +24 -11
- package/src/editor/Editable.tsx +336 -223
- package/src/editor/components/drop-indicator.tsx +4 -1
- package/src/internal-utils/dragging-on-drag-origin.ts +22 -0
- package/src/internal-utils/event-position.ts +32 -4
- package/src/internal-utils/slate-utils.ts +18 -9
- package/src/utils/index.ts +2 -0
- package/src/utils/util.get-selection-end-point.ts +20 -0
- package/src/utils/util.get-selection-start-point.ts +20 -0
package/src/editor/Editable.tsx
CHANGED
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
import {getCompoundClientRect} from '../internal-utils/compound-client-rect'
|
|
37
37
|
import {debugWithName} from '../internal-utils/debug'
|
|
38
38
|
import {getDragSelection} from '../internal-utils/drag-selection'
|
|
39
|
+
import {draggingOnDragOrigin} from '../internal-utils/dragging-on-drag-origin'
|
|
39
40
|
import {getEventPosition} from '../internal-utils/event-position'
|
|
40
41
|
import {parseBlocks} from '../internal-utils/parse-blocks'
|
|
41
42
|
import {
|
|
@@ -62,6 +63,8 @@ import type {
|
|
|
62
63
|
ScrollSelectionIntoViewFunction,
|
|
63
64
|
} from '../types/editor'
|
|
64
65
|
import type {HotkeyOptions} from '../types/options'
|
|
66
|
+
import {isSelectionCollapsed} from '../utils'
|
|
67
|
+
import {getSelectionEndPoint} from '../utils/util.get-selection-end-point'
|
|
65
68
|
import {Element} from './components/Element'
|
|
66
69
|
import {Leaf} from './components/Leaf'
|
|
67
70
|
import {EditorActorContext} from './editor-actor-context'
|
|
@@ -936,144 +939,164 @@ export const PortableTextEditable = forwardRef<
|
|
|
936
939
|
(event: React.DragEvent<HTMLDivElement>) => {
|
|
937
940
|
onDragStart?.(event)
|
|
938
941
|
|
|
939
|
-
if (
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
slateEditor,
|
|
943
|
-
event: event.nativeEvent,
|
|
944
|
-
})
|
|
942
|
+
if (event.isDefaultPrevented() || event.isPropagationStopped()) {
|
|
943
|
+
return
|
|
944
|
+
}
|
|
945
945
|
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
return
|
|
949
|
-
}
|
|
946
|
+
// Prevent Slate from handling the event
|
|
947
|
+
event.stopPropagation()
|
|
950
948
|
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
949
|
+
const position = getEventPosition({
|
|
950
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
951
|
+
slateEditor,
|
|
952
|
+
event: event.nativeEvent,
|
|
953
|
+
})
|
|
954
|
+
|
|
955
|
+
if (!position) {
|
|
956
|
+
console.warn('Could not find position for dragstart event')
|
|
957
|
+
return
|
|
958
|
+
}
|
|
959
959
|
|
|
960
|
-
|
|
960
|
+
const snapshot = getEditorSnapshot({
|
|
961
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
962
|
+
slateEditorInstance: slateEditor,
|
|
963
|
+
})
|
|
964
|
+
const dragSelection = getDragSelection({
|
|
965
|
+
eventSelection: position.selection,
|
|
966
|
+
snapshot,
|
|
967
|
+
})
|
|
968
|
+
|
|
969
|
+
const selectingEntireBlocks = selectors.isSelectingEntireBlocks({
|
|
970
|
+
...snapshot,
|
|
971
|
+
context: {
|
|
972
|
+
...snapshot.context,
|
|
973
|
+
selection: dragSelection,
|
|
974
|
+
},
|
|
975
|
+
})
|
|
976
|
+
|
|
977
|
+
const dragGhost = document.createElement('div')
|
|
978
|
+
|
|
979
|
+
const draggedDomNodes = getSelectionDomNodes({
|
|
980
|
+
snapshot: {
|
|
961
981
|
...snapshot,
|
|
962
982
|
context: {
|
|
963
983
|
...snapshot.context,
|
|
964
984
|
selection: dragSelection,
|
|
965
985
|
},
|
|
966
|
-
}
|
|
986
|
+
},
|
|
987
|
+
slateEditor,
|
|
988
|
+
})
|
|
967
989
|
|
|
968
|
-
|
|
990
|
+
if (selectingEntireBlocks) {
|
|
991
|
+
// Clone the DOM Nodes so they won't be visually clipped by scroll-containers etc.
|
|
992
|
+
const clonedBlockNodes = draggedDomNodes.blockNodes.map((node) =>
|
|
993
|
+
node.cloneNode(true),
|
|
994
|
+
)
|
|
969
995
|
|
|
970
|
-
const
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
},
|
|
977
|
-
},
|
|
978
|
-
slateEditor,
|
|
979
|
-
})
|
|
996
|
+
for (const block of clonedBlockNodes) {
|
|
997
|
+
if (block instanceof HTMLElement) {
|
|
998
|
+
block.style.position = 'relative'
|
|
999
|
+
}
|
|
1000
|
+
dragGhost.appendChild(block)
|
|
1001
|
+
}
|
|
980
1002
|
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
1003
|
+
// A custom drag ghost element can be configured using this data attribute
|
|
1004
|
+
const customGhost = dragGhost.querySelector(
|
|
1005
|
+
'[data-pt-drag-ghost-element]',
|
|
1006
|
+
)
|
|
1007
|
+
if (customGhost) {
|
|
1008
|
+
dragGhost.replaceChildren(customGhost)
|
|
1009
|
+
}
|
|
986
1010
|
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
block.style.position = 'relative'
|
|
990
|
-
}
|
|
991
|
-
dragGhost.appendChild(block)
|
|
992
|
-
}
|
|
1011
|
+
// Setting the `data-dragged` attribute so the consumer can style the element while it’s dragged
|
|
1012
|
+
dragGhost.setAttribute('data-dragged', '')
|
|
993
1013
|
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
if (customGhost) {
|
|
999
|
-
dragGhost.replaceChildren(customGhost)
|
|
1000
|
-
}
|
|
1014
|
+
dragGhost.style.position = 'absolute'
|
|
1015
|
+
dragGhost.style.left = '-99999px'
|
|
1016
|
+
dragGhost.style.boxSizing = 'border-box'
|
|
1017
|
+
document.body.appendChild(dragGhost)
|
|
1001
1018
|
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
dragGhost.style.
|
|
1007
|
-
dragGhost.style.
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
if (customGhost) {
|
|
1011
|
-
const customGhostRect = customGhost.getBoundingClientRect()
|
|
1012
|
-
const x = event.clientX - customGhostRect.left
|
|
1013
|
-
const y = event.clientY - customGhostRect.top
|
|
1014
|
-
dragGhost.style.width = `${customGhostRect.width}px`
|
|
1015
|
-
dragGhost.style.height = `${customGhostRect.height}px`
|
|
1016
|
-
event.dataTransfer.setDragImage(dragGhost, x, y)
|
|
1017
|
-
} else {
|
|
1018
|
-
const blocksDomRect = getCompoundClientRect(
|
|
1019
|
-
draggedDomNodes.blockNodes,
|
|
1020
|
-
)
|
|
1021
|
-
const x = event.clientX - blocksDomRect.left
|
|
1022
|
-
const y = event.clientY - blocksDomRect.top
|
|
1023
|
-
dragGhost.style.width = `${blocksDomRect.width}px`
|
|
1024
|
-
dragGhost.style.height = `${blocksDomRect.height}px`
|
|
1025
|
-
event.dataTransfer.setDragImage(dragGhost, x, y)
|
|
1026
|
-
}
|
|
1019
|
+
if (customGhost) {
|
|
1020
|
+
const customGhostRect = customGhost.getBoundingClientRect()
|
|
1021
|
+
const x = event.clientX - customGhostRect.left
|
|
1022
|
+
const y = event.clientY - customGhostRect.top
|
|
1023
|
+
dragGhost.style.width = `${customGhostRect.width}px`
|
|
1024
|
+
dragGhost.style.height = `${customGhostRect.height}px`
|
|
1025
|
+
event.dataTransfer.setDragImage(dragGhost, x, y)
|
|
1027
1026
|
} else {
|
|
1028
|
-
const
|
|
1029
|
-
|
|
1027
|
+
const blocksDomRect = getCompoundClientRect(
|
|
1028
|
+
draggedDomNodes.blockNodes,
|
|
1030
1029
|
)
|
|
1030
|
+
const x = event.clientX - blocksDomRect.left
|
|
1031
|
+
const y = event.clientY - blocksDomRect.top
|
|
1032
|
+
dragGhost.style.width = `${blocksDomRect.width}px`
|
|
1033
|
+
dragGhost.style.height = `${blocksDomRect.height}px`
|
|
1034
|
+
event.dataTransfer.setDragImage(dragGhost, x, y)
|
|
1035
|
+
}
|
|
1036
|
+
} else {
|
|
1037
|
+
const clonedChildNodes = draggedDomNodes.childNodes.map((node) =>
|
|
1038
|
+
node.cloneNode(true),
|
|
1039
|
+
)
|
|
1031
1040
|
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1041
|
+
for (const child of clonedChildNodes) {
|
|
1042
|
+
dragGhost.appendChild(child)
|
|
1043
|
+
}
|
|
1035
1044
|
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1045
|
+
dragGhost.style.position = 'absolute'
|
|
1046
|
+
dragGhost.style.left = '-99999px'
|
|
1047
|
+
dragGhost.style.boxSizing = 'border-box'
|
|
1048
|
+
document.body.appendChild(dragGhost)
|
|
1040
1049
|
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1050
|
+
const childrenDomRect = getCompoundClientRect(
|
|
1051
|
+
draggedDomNodes.childNodes,
|
|
1052
|
+
)
|
|
1053
|
+
const x = event.clientX - childrenDomRect.left
|
|
1054
|
+
const y = event.clientY - childrenDomRect.top
|
|
1055
|
+
dragGhost.style.width = `${childrenDomRect.width}px`
|
|
1056
|
+
dragGhost.style.height = `${childrenDomRect.height}px`
|
|
1048
1057
|
|
|
1049
|
-
|
|
1050
|
-
|
|
1058
|
+
event.dataTransfer.setDragImage(dragGhost, x, y)
|
|
1059
|
+
}
|
|
1051
1060
|
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1061
|
+
// Select drag selection
|
|
1062
|
+
// If the selection is expanded then we just select the end of the
|
|
1063
|
+
// selection
|
|
1064
|
+
editorActor.send({
|
|
1065
|
+
type: 'behavior event',
|
|
1066
|
+
behaviorEvent: {
|
|
1067
|
+
type: 'select',
|
|
1068
|
+
selection: isSelectionCollapsed(dragSelection)
|
|
1069
|
+
? dragSelection
|
|
1070
|
+
: {
|
|
1071
|
+
anchor: getSelectionEndPoint(dragSelection),
|
|
1072
|
+
focus: getSelectionEndPoint(dragSelection),
|
|
1073
|
+
backward: false,
|
|
1074
|
+
},
|
|
1075
|
+
},
|
|
1076
|
+
editor: slateEditor,
|
|
1077
|
+
})
|
|
1059
1078
|
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
position: {
|
|
1068
|
-
selection: dragSelection,
|
|
1069
|
-
},
|
|
1070
|
-
},
|
|
1071
|
-
editor: slateEditor,
|
|
1072
|
-
})
|
|
1079
|
+
editorActor.send({
|
|
1080
|
+
type: 'dragstart',
|
|
1081
|
+
origin: {
|
|
1082
|
+
selection: dragSelection,
|
|
1083
|
+
},
|
|
1084
|
+
ghost: dragGhost,
|
|
1085
|
+
})
|
|
1073
1086
|
|
|
1074
|
-
|
|
1075
|
-
event
|
|
1076
|
-
|
|
1087
|
+
editorActor.send({
|
|
1088
|
+
type: 'behavior event',
|
|
1089
|
+
behaviorEvent: {
|
|
1090
|
+
type: 'drag.dragstart',
|
|
1091
|
+
originEvent: {
|
|
1092
|
+
dataTransfer: event.dataTransfer,
|
|
1093
|
+
},
|
|
1094
|
+
position: {
|
|
1095
|
+
selection: dragSelection,
|
|
1096
|
+
},
|
|
1097
|
+
},
|
|
1098
|
+
editor: slateEditor,
|
|
1099
|
+
})
|
|
1077
1100
|
},
|
|
1078
1101
|
[onDragStart, editorActor, slateEditor],
|
|
1079
1102
|
)
|
|
@@ -1082,21 +1105,43 @@ export const PortableTextEditable = forwardRef<
|
|
|
1082
1105
|
(event: React.DragEvent<HTMLDivElement>) => {
|
|
1083
1106
|
onDrag?.(event)
|
|
1084
1107
|
|
|
1085
|
-
if (
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
behaviorEvent: {
|
|
1089
|
-
type: 'drag.drag',
|
|
1090
|
-
originEvent: {
|
|
1091
|
-
dataTransfer: event.dataTransfer,
|
|
1092
|
-
},
|
|
1093
|
-
},
|
|
1094
|
-
editor: slateEditor,
|
|
1095
|
-
})
|
|
1108
|
+
if (event.isDefaultPrevented() || event.isPropagationStopped()) {
|
|
1109
|
+
return
|
|
1110
|
+
}
|
|
1096
1111
|
|
|
1097
|
-
|
|
1098
|
-
|
|
1112
|
+
// Prevent Slate from handling the event
|
|
1113
|
+
event.stopPropagation()
|
|
1114
|
+
|
|
1115
|
+
const position = getEventPosition({
|
|
1116
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1117
|
+
slateEditor,
|
|
1118
|
+
event: event.nativeEvent,
|
|
1119
|
+
})
|
|
1120
|
+
|
|
1121
|
+
if (!position) {
|
|
1122
|
+
return
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
const snapshot = getEditorSnapshot({
|
|
1126
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1127
|
+
slateEditorInstance: slateEditor,
|
|
1128
|
+
})
|
|
1129
|
+
|
|
1130
|
+
if (draggingOnDragOrigin({snapshot, position})) {
|
|
1131
|
+
event.preventDefault()
|
|
1132
|
+
return
|
|
1099
1133
|
}
|
|
1134
|
+
|
|
1135
|
+
editorActor.send({
|
|
1136
|
+
type: 'behavior event',
|
|
1137
|
+
behaviorEvent: {
|
|
1138
|
+
type: 'drag.drag',
|
|
1139
|
+
originEvent: {
|
|
1140
|
+
dataTransfer: event.dataTransfer,
|
|
1141
|
+
},
|
|
1142
|
+
},
|
|
1143
|
+
editor: slateEditor,
|
|
1144
|
+
})
|
|
1100
1145
|
},
|
|
1101
1146
|
[onDrag, editorActor, slateEditor],
|
|
1102
1147
|
)
|
|
@@ -1105,21 +1150,23 @@ export const PortableTextEditable = forwardRef<
|
|
|
1105
1150
|
(event: React.DragEvent<HTMLDivElement>) => {
|
|
1106
1151
|
onDragEnd?.(event)
|
|
1107
1152
|
|
|
1108
|
-
if (
|
|
1109
|
-
|
|
1110
|
-
type: 'behavior event',
|
|
1111
|
-
behaviorEvent: {
|
|
1112
|
-
type: 'drag.dragend',
|
|
1113
|
-
originEvent: {
|
|
1114
|
-
dataTransfer: event.dataTransfer,
|
|
1115
|
-
},
|
|
1116
|
-
},
|
|
1117
|
-
editor: slateEditor,
|
|
1118
|
-
})
|
|
1119
|
-
|
|
1120
|
-
// Prevent Slate from handling the event
|
|
1121
|
-
event.stopPropagation()
|
|
1153
|
+
if (event.isDefaultPrevented() || event.isPropagationStopped()) {
|
|
1154
|
+
return
|
|
1122
1155
|
}
|
|
1156
|
+
|
|
1157
|
+
// Prevent Slate from handling the event
|
|
1158
|
+
event.stopPropagation()
|
|
1159
|
+
|
|
1160
|
+
editorActor.send({
|
|
1161
|
+
type: 'behavior event',
|
|
1162
|
+
behaviorEvent: {
|
|
1163
|
+
type: 'drag.dragend',
|
|
1164
|
+
originEvent: {
|
|
1165
|
+
dataTransfer: event.dataTransfer,
|
|
1166
|
+
},
|
|
1167
|
+
},
|
|
1168
|
+
editor: slateEditor,
|
|
1169
|
+
})
|
|
1123
1170
|
},
|
|
1124
1171
|
[onDragEnd, editorActor, slateEditor],
|
|
1125
1172
|
)
|
|
@@ -1128,32 +1175,44 @@ export const PortableTextEditable = forwardRef<
|
|
|
1128
1175
|
(event: React.DragEvent<HTMLDivElement>) => {
|
|
1129
1176
|
onDragEnter?.(event)
|
|
1130
1177
|
|
|
1131
|
-
if (
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
slateEditor,
|
|
1135
|
-
event: event.nativeEvent,
|
|
1136
|
-
})
|
|
1178
|
+
if (event.isDefaultPrevented() || event.isPropagationStopped()) {
|
|
1179
|
+
return
|
|
1180
|
+
}
|
|
1137
1181
|
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
}
|
|
1182
|
+
// Prevent Slate from handling the event
|
|
1183
|
+
event.stopPropagation()
|
|
1141
1184
|
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
dataTransfer: event.dataTransfer,
|
|
1148
|
-
},
|
|
1149
|
-
position,
|
|
1150
|
-
},
|
|
1151
|
-
editor: slateEditor,
|
|
1152
|
-
})
|
|
1185
|
+
const position = getEventPosition({
|
|
1186
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1187
|
+
slateEditor,
|
|
1188
|
+
event: event.nativeEvent,
|
|
1189
|
+
})
|
|
1153
1190
|
|
|
1154
|
-
|
|
1155
|
-
|
|
1191
|
+
if (!position) {
|
|
1192
|
+
return
|
|
1156
1193
|
}
|
|
1194
|
+
|
|
1195
|
+
const snapshot = getEditorSnapshot({
|
|
1196
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1197
|
+
slateEditorInstance: slateEditor,
|
|
1198
|
+
})
|
|
1199
|
+
|
|
1200
|
+
if (draggingOnDragOrigin({snapshot, position})) {
|
|
1201
|
+
event.preventDefault()
|
|
1202
|
+
return
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
editorActor.send({
|
|
1206
|
+
type: 'behavior event',
|
|
1207
|
+
behaviorEvent: {
|
|
1208
|
+
type: 'drag.dragenter',
|
|
1209
|
+
originEvent: {
|
|
1210
|
+
dataTransfer: event.dataTransfer,
|
|
1211
|
+
},
|
|
1212
|
+
position,
|
|
1213
|
+
},
|
|
1214
|
+
editor: slateEditor,
|
|
1215
|
+
})
|
|
1157
1216
|
},
|
|
1158
1217
|
[onDragEnter, editorActor, slateEditor],
|
|
1159
1218
|
)
|
|
@@ -1162,33 +1221,45 @@ export const PortableTextEditable = forwardRef<
|
|
|
1162
1221
|
(event: React.DragEvent<HTMLDivElement>) => {
|
|
1163
1222
|
onDragOver?.(event)
|
|
1164
1223
|
|
|
1165
|
-
if (
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
slateEditor,
|
|
1169
|
-
event: event.nativeEvent,
|
|
1170
|
-
})
|
|
1224
|
+
if (event.isDefaultPrevented() || event.isPropagationStopped()) {
|
|
1225
|
+
return
|
|
1226
|
+
}
|
|
1171
1227
|
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
}
|
|
1228
|
+
// Prevent Slate from handling the event
|
|
1229
|
+
event.stopPropagation()
|
|
1175
1230
|
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
dataTransfer: event.dataTransfer,
|
|
1182
|
-
},
|
|
1183
|
-
position,
|
|
1184
|
-
},
|
|
1185
|
-
editor: slateEditor,
|
|
1186
|
-
nativeEvent: event,
|
|
1187
|
-
})
|
|
1231
|
+
const position = getEventPosition({
|
|
1232
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1233
|
+
slateEditor,
|
|
1234
|
+
event: event.nativeEvent,
|
|
1235
|
+
})
|
|
1188
1236
|
|
|
1189
|
-
|
|
1190
|
-
|
|
1237
|
+
if (!position) {
|
|
1238
|
+
return
|
|
1191
1239
|
}
|
|
1240
|
+
|
|
1241
|
+
const snapshot = getEditorSnapshot({
|
|
1242
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1243
|
+
slateEditorInstance: slateEditor,
|
|
1244
|
+
})
|
|
1245
|
+
|
|
1246
|
+
if (draggingOnDragOrigin({snapshot, position})) {
|
|
1247
|
+
event.preventDefault()
|
|
1248
|
+
return
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
editorActor.send({
|
|
1252
|
+
type: 'behavior event',
|
|
1253
|
+
behaviorEvent: {
|
|
1254
|
+
type: 'drag.dragover',
|
|
1255
|
+
originEvent: {
|
|
1256
|
+
dataTransfer: event.dataTransfer,
|
|
1257
|
+
},
|
|
1258
|
+
position,
|
|
1259
|
+
},
|
|
1260
|
+
editor: slateEditor,
|
|
1261
|
+
nativeEvent: event,
|
|
1262
|
+
})
|
|
1192
1263
|
},
|
|
1193
1264
|
[onDragOver, editorActor, slateEditor],
|
|
1194
1265
|
)
|
|
@@ -1197,37 +1268,54 @@ export const PortableTextEditable = forwardRef<
|
|
|
1197
1268
|
(event: React.DragEvent<HTMLDivElement>) => {
|
|
1198
1269
|
onDrop?.(event)
|
|
1199
1270
|
|
|
1200
|
-
if (
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
slateEditor,
|
|
1204
|
-
event: event.nativeEvent,
|
|
1205
|
-
})
|
|
1271
|
+
if (event.isDefaultPrevented() || event.isPropagationStopped()) {
|
|
1272
|
+
return
|
|
1273
|
+
}
|
|
1206
1274
|
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
return
|
|
1210
|
-
}
|
|
1275
|
+
// Prevent Slate from handling the event
|
|
1276
|
+
event.preventDefault()
|
|
1211
1277
|
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
slateEditor
|
|
1278
|
+
const position = getEventPosition({
|
|
1279
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1280
|
+
slateEditor,
|
|
1281
|
+
event: event.nativeEvent,
|
|
1282
|
+
})
|
|
1215
1283
|
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
originEvent: {
|
|
1221
|
-
dataTransfer: event.dataTransfer,
|
|
1222
|
-
},
|
|
1223
|
-
position,
|
|
1224
|
-
},
|
|
1225
|
-
editor: slateEditor,
|
|
1226
|
-
})
|
|
1284
|
+
if (!position) {
|
|
1285
|
+
console.warn('Could not find position for drop event')
|
|
1286
|
+
return
|
|
1287
|
+
}
|
|
1227
1288
|
|
|
1228
|
-
|
|
1289
|
+
const snapshot = getEditorSnapshot({
|
|
1290
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1291
|
+
slateEditorInstance: slateEditor,
|
|
1292
|
+
})
|
|
1293
|
+
|
|
1294
|
+
if (draggingOnDragOrigin({snapshot, position})) {
|
|
1229
1295
|
event.preventDefault()
|
|
1296
|
+
return
|
|
1230
1297
|
}
|
|
1298
|
+
|
|
1299
|
+
editorActor.send({
|
|
1300
|
+
type: 'behavior event',
|
|
1301
|
+
behaviorEvent: {
|
|
1302
|
+
type: 'select',
|
|
1303
|
+
selection: position.selection,
|
|
1304
|
+
},
|
|
1305
|
+
editor: slateEditor,
|
|
1306
|
+
})
|
|
1307
|
+
|
|
1308
|
+
editorActor.send({
|
|
1309
|
+
type: 'behavior event',
|
|
1310
|
+
behaviorEvent: {
|
|
1311
|
+
type: 'drag.drop',
|
|
1312
|
+
originEvent: {
|
|
1313
|
+
dataTransfer: event.dataTransfer,
|
|
1314
|
+
},
|
|
1315
|
+
position,
|
|
1316
|
+
},
|
|
1317
|
+
editor: slateEditor,
|
|
1318
|
+
})
|
|
1231
1319
|
},
|
|
1232
1320
|
[onDrop, editorActor, slateEditor],
|
|
1233
1321
|
)
|
|
@@ -1236,18 +1324,43 @@ export const PortableTextEditable = forwardRef<
|
|
|
1236
1324
|
(event: React.DragEvent<HTMLDivElement>) => {
|
|
1237
1325
|
onDragLeave?.(event)
|
|
1238
1326
|
|
|
1239
|
-
if (
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1327
|
+
if (event.isDefaultPrevented() || event.isPropagationStopped()) {
|
|
1328
|
+
return
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
// Prevent Slate from handling the event
|
|
1332
|
+
event.stopPropagation()
|
|
1333
|
+
|
|
1334
|
+
const position = getEventPosition({
|
|
1335
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1336
|
+
slateEditor,
|
|
1337
|
+
event: event.nativeEvent,
|
|
1338
|
+
})
|
|
1339
|
+
|
|
1340
|
+
if (!position) {
|
|
1341
|
+
return
|
|
1250
1342
|
}
|
|
1343
|
+
|
|
1344
|
+
const snapshot = getEditorSnapshot({
|
|
1345
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1346
|
+
slateEditorInstance: slateEditor,
|
|
1347
|
+
})
|
|
1348
|
+
|
|
1349
|
+
if (draggingOnDragOrigin({snapshot, position})) {
|
|
1350
|
+
event.preventDefault()
|
|
1351
|
+
return
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
editorActor.send({
|
|
1355
|
+
type: 'behavior event',
|
|
1356
|
+
behaviorEvent: {
|
|
1357
|
+
type: 'drag.dragleave',
|
|
1358
|
+
originEvent: {
|
|
1359
|
+
dataTransfer: event.dataTransfer,
|
|
1360
|
+
},
|
|
1361
|
+
},
|
|
1362
|
+
editor: slateEditor,
|
|
1363
|
+
})
|
|
1251
1364
|
},
|
|
1252
1365
|
[onDragLeave, editorActor, slateEditor],
|
|
1253
1366
|
)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export function DropIndicator() {
|
|
2
2
|
return (
|
|
3
3
|
<div
|
|
4
|
+
contentEditable={false}
|
|
4
5
|
className="pt-drop-indicator"
|
|
5
6
|
style={{
|
|
6
7
|
position: 'absolute',
|
|
@@ -9,6 +10,8 @@ export function DropIndicator() {
|
|
|
9
10
|
borderBottom: '1px solid currentColor',
|
|
10
11
|
zIndex: 5,
|
|
11
12
|
}}
|
|
12
|
-
|
|
13
|
+
>
|
|
14
|
+
<span />
|
|
15
|
+
</div>
|
|
13
16
|
)
|
|
14
17
|
}
|