@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
package/lib/index.js
CHANGED
|
@@ -1,16 +1,127 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { toPortableTextRange, EditorActorContext, getEditorSnapshot, debugWithName, fromSlateValue, KEY_TO_VALUE_ELEMENT, usePortableTextEditor, PortableTextEditor, toSlateRange, moveRangeByOperation, isEqualToEmptyEditor, useEditor } from "./_chunks-es/editor-provider.js";
|
|
2
2
|
import { EditorProvider, defineSchema, defaultKeyGenerator, useEditorSelector, usePortableTextEditorSelection } from "./_chunks-es/editor-provider.js";
|
|
3
3
|
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
4
4
|
import { useSelector } from "@xstate/react";
|
|
5
5
|
import isEqual from "lodash/isEqual.js";
|
|
6
6
|
import noop from "lodash/noop.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
7
|
+
import { useContext, useState, useEffect, useRef, useMemo, startTransition, useCallback, forwardRef, useImperativeHandle } from "react";
|
|
8
|
+
import { Editor, Range, Element as Element$1, Text, Transforms, Path } from "slate";
|
|
9
|
+
import { ReactEditor, useSlateStatic, useSelected, useSlate, Editable } from "slate-react";
|
|
10
|
+
import { DOMEditor, isDOMNode } from "slate-dom";
|
|
11
|
+
import { getBlockStartPoint, getBlockEndPoint } from "./_chunks-es/util.slice-blocks.js";
|
|
12
|
+
import { isSelectionCollapsed, getFocusTextBlock, getFocusSpan, getFocusBlock, getSelectedBlocks } from "./_chunks-es/selector.is-at-the-start-of-block.js";
|
|
13
|
+
import { parseBlocks } from "./_chunks-es/parse-blocks.js";
|
|
14
|
+
import { isSelectingEntireBlocks } from "./_chunks-es/selector.is-overlapping-selection.js";
|
|
15
|
+
import { defineBehavior, isHotkey } from "./_chunks-es/behavior.core.js";
|
|
10
16
|
import { c } from "react-compiler-runtime";
|
|
11
17
|
import uniq from "lodash/uniq.js";
|
|
12
|
-
import { isHotkey } from "./_chunks-es/behavior.core.js";
|
|
13
18
|
import { useEffectEvent } from "use-effect-event";
|
|
19
|
+
function getEventPosition({
|
|
20
|
+
snapshot,
|
|
21
|
+
slateEditor,
|
|
22
|
+
event
|
|
23
|
+
}) {
|
|
24
|
+
if (!DOMEditor.hasTarget(slateEditor, event.target))
|
|
25
|
+
return;
|
|
26
|
+
const node = DOMEditor.toSlateNode(slateEditor, event.target);
|
|
27
|
+
if (isClipboardEvent(event)) {
|
|
28
|
+
const selection2 = snapshot.context.selection;
|
|
29
|
+
return selection2 ? {
|
|
30
|
+
block: "end",
|
|
31
|
+
isEditor: Editor.isEditor(node),
|
|
32
|
+
selection: selection2
|
|
33
|
+
} : void 0;
|
|
34
|
+
}
|
|
35
|
+
const block = getEventPositionBlock({
|
|
36
|
+
slateEditor,
|
|
37
|
+
event
|
|
38
|
+
}), selection = getEventPositionSelection({
|
|
39
|
+
snapshot,
|
|
40
|
+
slateEditor,
|
|
41
|
+
event
|
|
42
|
+
});
|
|
43
|
+
if (!(!block || !selection))
|
|
44
|
+
return {
|
|
45
|
+
block,
|
|
46
|
+
isEditor: Editor.isEditor(node),
|
|
47
|
+
selection
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function getEventPositionBlock({
|
|
51
|
+
slateEditor,
|
|
52
|
+
event
|
|
53
|
+
}) {
|
|
54
|
+
if (!ReactEditor.hasTarget(slateEditor, event.target))
|
|
55
|
+
return;
|
|
56
|
+
const node = ReactEditor.toSlateNode(slateEditor, event.target), elementRect = ReactEditor.toDOMNode(slateEditor, node).getBoundingClientRect(), top = elementRect.top, height = elementRect.height;
|
|
57
|
+
return Math.abs(top - event.pageY) < height / 2 ? "start" : "end";
|
|
58
|
+
}
|
|
59
|
+
function getEventPositionSelection({
|
|
60
|
+
snapshot,
|
|
61
|
+
slateEditor,
|
|
62
|
+
event
|
|
63
|
+
}) {
|
|
64
|
+
const range = getSlateRangeFromEvent(slateEditor, event), selection = range ? toPortableTextRange(snapshot.context.value, range, snapshot.context.schema) : null;
|
|
65
|
+
if (!selection)
|
|
66
|
+
return selection;
|
|
67
|
+
const collapsedSelection = isSelectionCollapsed({
|
|
68
|
+
...snapshot,
|
|
69
|
+
context: {
|
|
70
|
+
...snapshot.context,
|
|
71
|
+
selection
|
|
72
|
+
}
|
|
73
|
+
}), focusTextBlock = getFocusTextBlock({
|
|
74
|
+
...snapshot,
|
|
75
|
+
context: {
|
|
76
|
+
...snapshot.context,
|
|
77
|
+
selection
|
|
78
|
+
}
|
|
79
|
+
}), focusSpan = getFocusSpan({
|
|
80
|
+
...snapshot,
|
|
81
|
+
context: {
|
|
82
|
+
...snapshot.context,
|
|
83
|
+
selection
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
if (event.type === "dragstart" && collapsedSelection && focusTextBlock && focusSpan) {
|
|
87
|
+
const blockStartPoint = getBlockStartPoint(focusTextBlock), blockEndPoint = getBlockEndPoint(focusTextBlock);
|
|
88
|
+
return {
|
|
89
|
+
anchor: blockStartPoint,
|
|
90
|
+
focus: blockEndPoint
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
return selection;
|
|
94
|
+
}
|
|
95
|
+
function getSlateRangeFromEvent(editor, event) {
|
|
96
|
+
if (!event.target || !isDOMNode(event.target))
|
|
97
|
+
return;
|
|
98
|
+
const window2 = DOMEditor.getWindow(editor);
|
|
99
|
+
let domRange;
|
|
100
|
+
if (window2.document.caretPositionFromPoint !== void 0) {
|
|
101
|
+
const position = window2.document.caretPositionFromPoint(event.clientX, event.clientY);
|
|
102
|
+
position && (domRange = window2.document.createRange(), domRange.setStart(position.offsetNode, position.offset), domRange.setEnd(position.offsetNode, position.offset));
|
|
103
|
+
} else if (window2.document.caretRangeFromPoint !== void 0)
|
|
104
|
+
domRange = window2.document.caretRangeFromPoint(event.clientX, event.clientY) ?? void 0;
|
|
105
|
+
else {
|
|
106
|
+
console.warn("Neither caretPositionFromPoint nor caretRangeFromPoint is supported");
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (!domRange)
|
|
110
|
+
return;
|
|
111
|
+
let range;
|
|
112
|
+
try {
|
|
113
|
+
range = DOMEditor.toSlateRange(editor, domRange, {
|
|
114
|
+
exactMatch: !1,
|
|
115
|
+
// It can still throw even with this option set to true
|
|
116
|
+
suppressThrow: !1
|
|
117
|
+
});
|
|
118
|
+
} catch {
|
|
119
|
+
}
|
|
120
|
+
return range;
|
|
121
|
+
}
|
|
122
|
+
function isClipboardEvent(event) {
|
|
123
|
+
return event.type === "copy" || event.type === "cut" || event.type === "paste";
|
|
124
|
+
}
|
|
14
125
|
function normalizePoint(point, value) {
|
|
15
126
|
if (!point || !value)
|
|
16
127
|
return null;
|
|
@@ -98,146 +209,69 @@ function DropIndicator() {
|
|
|
98
209
|
zIndex: 5
|
|
99
210
|
} }), $[0] = t0) : t0 = $[0], t0;
|
|
100
211
|
}
|
|
101
|
-
const debug$4 = debugWithName("useDraggable");
|
|
102
212
|
function useDraggable(props) {
|
|
103
|
-
const $ = c(
|
|
213
|
+
const $ = c(15), editorActor = useContext(EditorActorContext), editor = useSlateStatic(), [blockElement, setBlockElement] = useState(null);
|
|
104
214
|
let t0, t1;
|
|
105
215
|
$[0] !== editor || $[1] !== props.blockRef || $[2] !== props.element ? (t0 = () => setBlockElement(props.blockRef ? props.blockRef.current : ReactEditor.toDOMNode(editor, props.element)), t1 = [editor, props.element, props.blockRef], $[0] = editor, $[1] = props.blockRef, $[2] = props.element, $[3] = t0, $[4] = t1) : (t0 = $[3], t1 = $[4]), useEffect(t0, t1);
|
|
106
216
|
let t2;
|
|
107
|
-
$[5] !==
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
IS_DRAGGING_BLOCK_TARGET_POSITION.delete(editor);
|
|
113
|
-
let targetPath = ReactEditor.findPath(editor, targetBlock);
|
|
114
|
-
const myPath = ReactEditor.findPath(editor, props.element), isBefore = Path.isBefore(myPath, targetPath);
|
|
115
|
-
if (dragPosition === "bottom" && !isBefore) {
|
|
116
|
-
if (targetPath[0] >= editor.children.length - 1) {
|
|
117
|
-
debug$4("target is already at the bottom, not moving");
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
const originalPath = targetPath;
|
|
121
|
-
targetPath = Path.next(targetPath), debug$4(`Adjusting targetPath from ${JSON.stringify(originalPath)} to ${JSON.stringify(targetPath)}`);
|
|
122
|
-
}
|
|
123
|
-
if (dragPosition === "top" && isBefore && targetPath[0] !== editor.children.length - 1) {
|
|
124
|
-
const originalPath_0 = targetPath;
|
|
125
|
-
targetPath = Path.previous(targetPath), debug$4(`Adjusting targetPath from ${JSON.stringify(originalPath_0)} to ${JSON.stringify(targetPath)}`);
|
|
126
|
-
}
|
|
127
|
-
if (Path.equals(targetPath, myPath)) {
|
|
128
|
-
event.preventDefault(), debug$4("targetPath and myPath is the same, not moving");
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
debug$4(`Moving element ${props.element._key} from path ${JSON.stringify(myPath)} to ${JSON.stringify(targetPath)} (${dragPosition})`), Transforms.moveNodes(editor, {
|
|
132
|
-
at: myPath,
|
|
133
|
-
to: targetPath
|
|
134
|
-
}), editor.onChange();
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
debug$4("No target element, not doing anything");
|
|
138
|
-
}, $[5] = editor, $[6] = props.element, $[7] = t2) : t2 = $[7];
|
|
217
|
+
$[5] !== editorActor ? (t2 = () => {
|
|
218
|
+
editorActor.send({
|
|
219
|
+
type: "dragend"
|
|
220
|
+
});
|
|
221
|
+
}, $[5] = editorActor, $[6] = t2) : t2 = $[6];
|
|
139
222
|
const handleDragEnd = t2;
|
|
140
223
|
let t3;
|
|
141
|
-
$[8] !== editor || $[9] !==
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
224
|
+
$[7] !== blockElement || $[8] !== editor || $[9] !== editorActor ? (t3 = (event) => {
|
|
225
|
+
const position = getEventPosition({
|
|
226
|
+
snapshot: getEditorSnapshot({
|
|
227
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
228
|
+
slateEditorInstance: editor
|
|
229
|
+
}),
|
|
230
|
+
slateEditor: editor,
|
|
231
|
+
event: event.nativeEvent
|
|
232
|
+
});
|
|
233
|
+
if (!position) {
|
|
234
|
+
console.error("Could not find position for dragstart event");
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (blockElement && blockElement instanceof HTMLElement) {
|
|
150
238
|
let dragGhost = blockElement.cloneNode(!0);
|
|
151
239
|
const customGhost = dragGhost.querySelector("[data-pt-drag-ghost-element]");
|
|
152
240
|
if (customGhost && (dragGhost = customGhost), dragGhost.setAttribute("data-dragged", ""), document.body) {
|
|
153
|
-
|
|
154
|
-
const rect = blockElement.getBoundingClientRect(), x =
|
|
155
|
-
dragGhost.style.width = `${rect.width}px`, dragGhost.style.height = `${rect.height}px`,
|
|
241
|
+
dragGhost.style.position = "absolute", dragGhost.style.left = "-99999px", dragGhost.style.boxSizing = "border-box", document.body.appendChild(dragGhost);
|
|
242
|
+
const rect = blockElement.getBoundingClientRect(), x = event.clientX - rect.left, y = event.clientY - rect.top;
|
|
243
|
+
dragGhost.style.width = `${rect.width}px`, dragGhost.style.height = `${rect.height}px`, event.dataTransfer.setDragImage(dragGhost, x, y), editorActor.send({
|
|
244
|
+
type: "dragstart",
|
|
245
|
+
origin: position,
|
|
246
|
+
ghost: dragGhost
|
|
247
|
+
});
|
|
248
|
+
return;
|
|
156
249
|
}
|
|
250
|
+
editorActor.send({
|
|
251
|
+
type: "dragstart",
|
|
252
|
+
origin: position
|
|
253
|
+
});
|
|
157
254
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const handleDragStart = t4;
|
|
255
|
+
}, $[7] = blockElement, $[8] = editor, $[9] = editorActor, $[10] = t3) : t3 = $[10];
|
|
256
|
+
const handleDragStart = t3;
|
|
161
257
|
if (props.readOnly) {
|
|
162
|
-
let
|
|
163
|
-
return $[
|
|
258
|
+
let t42;
|
|
259
|
+
return $[11] === Symbol.for("react.memo_cache_sentinel") ? (t42 = {
|
|
164
260
|
draggableProps: {
|
|
165
261
|
draggable: !1,
|
|
166
262
|
onDragStart: void 0,
|
|
167
|
-
onDrag: void 0,
|
|
168
263
|
onDragEnd: void 0
|
|
169
264
|
}
|
|
170
|
-
}, $[
|
|
265
|
+
}, $[11] = t42) : t42 = $[11], t42;
|
|
171
266
|
}
|
|
172
|
-
let
|
|
173
|
-
return $[
|
|
267
|
+
let t4;
|
|
268
|
+
return $[12] !== handleDragEnd || $[13] !== handleDragStart ? (t4 = {
|
|
174
269
|
draggableProps: {
|
|
175
270
|
draggable: !0,
|
|
176
271
|
onDragStart: handleDragStart,
|
|
177
|
-
onDrag: handleDrag,
|
|
178
272
|
onDragEnd: handleDragEnd
|
|
179
273
|
}
|
|
180
|
-
}, $[
|
|
181
|
-
}
|
|
182
|
-
const debug$3 = debugWithName("useDroppable");
|
|
183
|
-
function useDroppable(props) {
|
|
184
|
-
const $ = c(27), editor = useSlateStatic(), [isDragOver, setIsDragOver] = useState(!1), [blockElement, setBlockElement] = useState(null);
|
|
185
|
-
let t0, t1;
|
|
186
|
-
$[0] !== editor || $[1] !== props.blockRef || $[2] !== props.element ? (t0 = () => setBlockElement(props.blockRef ? props.blockRef.current : ReactEditor.toDOMNode(editor, props.element)), t1 = [editor, props.element, props.blockRef], $[0] = editor, $[1] = props.blockRef, $[2] = props.element, $[3] = t0, $[4] = t1) : (t0 = $[3], t1 = $[4]), useEffect(t0, t1);
|
|
187
|
-
let t2;
|
|
188
|
-
$[5] !== blockElement || $[6] !== editor || $[7] !== props.element ? (t2 = (event) => {
|
|
189
|
-
const isMyDragOver = IS_DRAGGING_BLOCK_ELEMENT.get(editor);
|
|
190
|
-
if (!isMyDragOver || !blockElement)
|
|
191
|
-
return;
|
|
192
|
-
event.preventDefault(), event.dataTransfer.dropEffect = "move", IS_DRAGGING_ELEMENT_TARGET.set(editor, props.element);
|
|
193
|
-
const elementRect = blockElement.getBoundingClientRect(), offset = elementRect.top, height = elementRect.height, Y = event.pageY, loc = Math.abs(offset - Y);
|
|
194
|
-
if (props.element === editor.children[0] || (loc < height / 2 ? IS_DRAGGING_BLOCK_TARGET_POSITION.set(editor, "top") : IS_DRAGGING_BLOCK_TARGET_POSITION.set(editor, "bottom")), isMyDragOver === props.element) {
|
|
195
|
-
event.dataTransfer.dropEffect = "none";
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
setIsDragOver(!0);
|
|
199
|
-
}, $[5] = blockElement, $[6] = editor, $[7] = props.element, $[8] = t2) : t2 = $[8];
|
|
200
|
-
const handleDragOver = t2;
|
|
201
|
-
let t3;
|
|
202
|
-
$[9] === Symbol.for("react.memo_cache_sentinel") ? (t3 = () => {
|
|
203
|
-
setIsDragOver(!1);
|
|
204
|
-
}, $[9] = t3) : t3 = $[9];
|
|
205
|
-
const handleDragLeave = t3;
|
|
206
|
-
let t4;
|
|
207
|
-
$[10] !== editor || $[11] !== props.element ? (t4 = (event_0) => {
|
|
208
|
-
IS_DRAGGING_BLOCK_ELEMENT.get(editor) && (debug$3("On drop (prevented)", props.element), event_0.preventDefault(), event_0.stopPropagation(), setIsDragOver(!1));
|
|
209
|
-
}, $[10] = editor, $[11] = props.element, $[12] = t4) : t4 = $[12];
|
|
210
|
-
const handleDrop = t4;
|
|
211
|
-
let t5;
|
|
212
|
-
$[13] !== editor || $[14] !== isDragOver ? (t5 = isDragOver && editor.children[0] === IS_DRAGGING_ELEMENT_TARGET.get(editor), $[13] = editor, $[14] = isDragOver, $[15] = t5) : t5 = $[15];
|
|
213
|
-
const isDraggingOverFirstBlock = t5;
|
|
214
|
-
let t6;
|
|
215
|
-
$[16] !== editor || $[17] !== isDragOver ? (t6 = isDragOver && editor.children[editor.children.length - 1] === IS_DRAGGING_ELEMENT_TARGET.get(editor), $[16] = editor, $[17] = isDragOver, $[18] = t6) : t6 = $[18];
|
|
216
|
-
const isDraggingOverLastBlock = t6, dragPosition = IS_DRAGGING_BLOCK_TARGET_POSITION.get(editor), isDraggingOverTop = isDraggingOverFirstBlock || isDragOver && !isDraggingOverFirstBlock && !isDraggingOverLastBlock && dragPosition === "top", isDraggingOverBottom = isDraggingOverLastBlock || isDragOver && !isDraggingOverFirstBlock && !isDraggingOverLastBlock && dragPosition === "bottom";
|
|
217
|
-
if (props.readOnly) {
|
|
218
|
-
let t72;
|
|
219
|
-
return $[19] === Symbol.for("react.memo_cache_sentinel") ? (t72 = {
|
|
220
|
-
droppableProps: {
|
|
221
|
-
onDragOver: void 0,
|
|
222
|
-
onDragLeave: void 0,
|
|
223
|
-
onDrop: void 0
|
|
224
|
-
},
|
|
225
|
-
isDraggingOverTop: !1,
|
|
226
|
-
isDraggingOverBottom: !1
|
|
227
|
-
}, $[19] = t72) : t72 = $[19], t72;
|
|
228
|
-
}
|
|
229
|
-
let t7;
|
|
230
|
-
$[20] !== handleDragOver || $[21] !== handleDrop ? (t7 = {
|
|
231
|
-
onDragOver: handleDragOver,
|
|
232
|
-
onDragLeave: handleDragLeave,
|
|
233
|
-
onDrop: handleDrop
|
|
234
|
-
}, $[20] = handleDragOver, $[21] = handleDrop, $[22] = t7) : t7 = $[22];
|
|
235
|
-
let t8;
|
|
236
|
-
return $[23] !== isDraggingOverBottom || $[24] !== isDraggingOverTop || $[25] !== t7 ? (t8 = {
|
|
237
|
-
droppableProps: t7,
|
|
238
|
-
isDraggingOverTop,
|
|
239
|
-
isDraggingOverBottom
|
|
240
|
-
}, $[23] = isDraggingOverBottom, $[24] = isDraggingOverTop, $[25] = t7, $[26] = t8) : t8 = $[26], t8;
|
|
274
|
+
}, $[12] = handleDragEnd, $[13] = handleDragStart, $[14] = t4) : t4 = $[14], t4;
|
|
241
275
|
}
|
|
242
276
|
debugWithName("components:Element");
|
|
243
277
|
const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
@@ -254,15 +288,86 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
254
288
|
renderStyle,
|
|
255
289
|
spellCheck
|
|
256
290
|
}) => {
|
|
257
|
-
const
|
|
291
|
+
const editorActor = useContext(EditorActorContext), slateEditor = useSlateStatic(), selected = useSelected(), blockRef = useRef(null), inlineBlockObjectRef = useRef(null), focused = selected && slateEditor.selection && Range.isCollapsed(slateEditor.selection) || !1, [dragPositionBlock, setDragPositionBlock] = useState(), draggable = useDraggable({
|
|
258
292
|
element,
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
})
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
293
|
+
readOnly,
|
|
294
|
+
blockRef
|
|
295
|
+
});
|
|
296
|
+
useEffect(() => {
|
|
297
|
+
const behavior = defineBehavior({
|
|
298
|
+
on: "drag.dragover",
|
|
299
|
+
guard: ({
|
|
300
|
+
snapshot,
|
|
301
|
+
event
|
|
302
|
+
}) => {
|
|
303
|
+
const dropFocusBlock = getFocusBlock({
|
|
304
|
+
...snapshot,
|
|
305
|
+
context: {
|
|
306
|
+
...snapshot.context,
|
|
307
|
+
selection: event.position.selection
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
if (!dropFocusBlock || dropFocusBlock.node._key !== element._key)
|
|
311
|
+
return !1;
|
|
312
|
+
const dragOrigin = snapshot.beta.internalDrag?.origin;
|
|
313
|
+
return !dragOrigin || getSelectedBlocks({
|
|
314
|
+
...snapshot,
|
|
315
|
+
context: {
|
|
316
|
+
...snapshot.context,
|
|
317
|
+
selection: dragOrigin.selection
|
|
318
|
+
}
|
|
319
|
+
}).some((draggedBlock) => draggedBlock.node._key === element._key) ? !1 : isSelectingEntireBlocks({
|
|
320
|
+
...snapshot,
|
|
321
|
+
context: {
|
|
322
|
+
...snapshot.context,
|
|
323
|
+
selection: dragOrigin.selection
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
},
|
|
327
|
+
actions: [({
|
|
328
|
+
event: event_0
|
|
329
|
+
}) => [{
|
|
330
|
+
type: "effect",
|
|
331
|
+
effect: () => {
|
|
332
|
+
setDragPositionBlock(event_0.position.block);
|
|
333
|
+
}
|
|
334
|
+
}, {
|
|
335
|
+
type: "noop"
|
|
336
|
+
}]]
|
|
337
|
+
});
|
|
338
|
+
return editorActor.send({
|
|
339
|
+
type: "add behavior",
|
|
340
|
+
behavior
|
|
341
|
+
}), () => {
|
|
342
|
+
editorActor.send({
|
|
343
|
+
type: "remove behavior",
|
|
344
|
+
behavior
|
|
345
|
+
});
|
|
346
|
+
};
|
|
347
|
+
}, [editorActor, element._key]), useEffect(() => {
|
|
348
|
+
const behavior_0 = defineBehavior({
|
|
349
|
+
on: "drag.*",
|
|
350
|
+
guard: ({
|
|
351
|
+
event: event_1
|
|
352
|
+
}) => event_1.type !== "drag.dragover",
|
|
353
|
+
actions: [() => [{
|
|
354
|
+
type: "effect",
|
|
355
|
+
effect: () => {
|
|
356
|
+
setDragPositionBlock(void 0);
|
|
357
|
+
}
|
|
358
|
+
}]]
|
|
359
|
+
});
|
|
360
|
+
return editorActor.send({
|
|
361
|
+
type: "add behavior",
|
|
362
|
+
behavior: behavior_0
|
|
363
|
+
}), () => {
|
|
364
|
+
editorActor.send({
|
|
365
|
+
type: "remove behavior",
|
|
366
|
+
behavior: behavior_0
|
|
367
|
+
});
|
|
368
|
+
};
|
|
369
|
+
}, [editorActor]);
|
|
370
|
+
const value = useMemo(() => fromSlateValue([element], schemaTypes.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditor))[0], [slateEditor, element, schemaTypes.block.name]);
|
|
266
371
|
let renderedBlock = children, className;
|
|
267
372
|
const blockPath = useMemo(() => [{
|
|
268
373
|
_key: element._key
|
|
@@ -271,8 +376,8 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
271
376
|
throw new Error("Expected element to have a _type property");
|
|
272
377
|
if (typeof element._key != "string")
|
|
273
378
|
throw new Error("Expected element to have a _key property");
|
|
274
|
-
if (
|
|
275
|
-
const path = ReactEditor.findPath(
|
|
379
|
+
if (slateEditor.isInline(element)) {
|
|
380
|
+
const path = ReactEditor.findPath(slateEditor, element), [block] = Editor.node(slateEditor, path, {
|
|
276
381
|
depth: 1
|
|
277
382
|
}), schemaType = schemaTypes.inlineObjects.find((_type) => _type.name === element._type);
|
|
278
383
|
if (!schemaType)
|
|
@@ -320,7 +425,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
320
425
|
editorElementRef: blockRef
|
|
321
426
|
}));
|
|
322
427
|
let level;
|
|
323
|
-
if (isListItem && (typeof element.level == "number" && (level = element.level), className += ` pt-list-item pt-list-item-${element.listItem} pt-list-item-level-${level || 1}`),
|
|
428
|
+
if (isListItem && (typeof element.level == "number" && (level = element.level), className += ` pt-list-item pt-list-item-${element.listItem} pt-list-item-level-${level || 1}`), slateEditor.isListBlock(value) && isListItem && element.listItem) {
|
|
324
429
|
const listType = schemaTypes.lists.find((item_0) => item_0.value === element.listItem);
|
|
325
430
|
renderListItem && listType && (renderedBlock = renderListItem({
|
|
326
431
|
block: value,
|
|
@@ -351,17 +456,17 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
351
456
|
return console.warn("Property 'type' is deprecated, use 'schemaType' instead."), schemaTypes.block;
|
|
352
457
|
}
|
|
353
458
|
}), propsOrDefaultRendered = renderBlock ? renderBlock(renderProps) : children;
|
|
354
|
-
return /* @__PURE__ */ jsxs("div", { ...attributes, className, spellCheck,
|
|
355
|
-
|
|
459
|
+
return /* @__PURE__ */ jsxs("div", { ...attributes, className, spellCheck, children: [
|
|
460
|
+
dragPositionBlock === "start" ? /* @__PURE__ */ jsx(DropIndicator, {}) : null,
|
|
356
461
|
/* @__PURE__ */ jsx("div", { ref: blockRef, children: propsOrDefaultRendered }),
|
|
357
|
-
|
|
462
|
+
dragPositionBlock === "end" ? /* @__PURE__ */ jsx(DropIndicator, {}) : null
|
|
358
463
|
] }, element._key);
|
|
359
464
|
}
|
|
360
465
|
const schemaType_0 = schemaTypes.blockObjects.find((_type_0) => _type_0.name === element._type);
|
|
361
466
|
if (!schemaType_0)
|
|
362
467
|
throw new Error(`Could not find schema type for block element of _type ${element._type}`);
|
|
363
468
|
className = "pt-block pt-object-block";
|
|
364
|
-
const block_0 = fromSlateValue([element], schemaTypes.block.name, KEY_TO_VALUE_ELEMENT.get(
|
|
469
|
+
const block_0 = fromSlateValue([element], schemaTypes.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditor))[0];
|
|
365
470
|
let renderedBlockFromProps;
|
|
366
471
|
if (renderBlock) {
|
|
367
472
|
const _props = Object.defineProperty({
|
|
@@ -380,11 +485,11 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
380
485
|
});
|
|
381
486
|
renderedBlockFromProps = renderBlock(_props);
|
|
382
487
|
}
|
|
383
|
-
return /* @__PURE__ */ jsxs("div", { ...attributes, className, ...
|
|
384
|
-
|
|
488
|
+
return /* @__PURE__ */ jsxs("div", { ...attributes, className, ...draggable.draggableProps, children: [
|
|
489
|
+
dragPositionBlock === "start" ? /* @__PURE__ */ jsx(DropIndicator, {}) : null,
|
|
385
490
|
children,
|
|
386
491
|
/* @__PURE__ */ jsx("div", { ref: blockRef, contentEditable: !1, children: renderedBlockFromProps || /* @__PURE__ */ jsx(DefaultBlockObject, { value }) }),
|
|
387
|
-
|
|
492
|
+
dragPositionBlock === "end" ? /* @__PURE__ */ jsx(DropIndicator, {}) : null
|
|
388
493
|
] }, element._key);
|
|
389
494
|
};
|
|
390
495
|
Element.displayName = "Element";
|
|
@@ -582,7 +687,15 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
582
687
|
onBeforeInput,
|
|
583
688
|
onPaste,
|
|
584
689
|
onCopy,
|
|
690
|
+
onCut,
|
|
585
691
|
onClick,
|
|
692
|
+
onDragStart,
|
|
693
|
+
onDrag,
|
|
694
|
+
onDragEnd,
|
|
695
|
+
onDragEnter,
|
|
696
|
+
onDragOver,
|
|
697
|
+
onDrop,
|
|
698
|
+
onDragLeave,
|
|
586
699
|
rangeDecorations,
|
|
587
700
|
renderAnnotation,
|
|
588
701
|
renderBlock,
|
|
@@ -694,47 +807,151 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
694
807
|
return () => teardown();
|
|
695
808
|
}, [editorActor, slateEditor, syncRangeDecorations]);
|
|
696
809
|
const handleCopy = useCallback((event) => {
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
810
|
+
if (onCopy)
|
|
811
|
+
onCopy(event) !== void 0 && event.preventDefault();
|
|
812
|
+
else if (event.nativeEvent.clipboardData) {
|
|
813
|
+
event.stopPropagation(), event.preventDefault();
|
|
814
|
+
const position = getEventPosition({
|
|
815
|
+
snapshot: getEditorSnapshot({
|
|
816
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
817
|
+
slateEditorInstance: slateEditor
|
|
818
|
+
}),
|
|
819
|
+
slateEditor,
|
|
820
|
+
event: event.nativeEvent
|
|
821
|
+
});
|
|
822
|
+
if (!position) {
|
|
823
|
+
console.warn("Could not find position for copy event");
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
editorActor.send({
|
|
827
|
+
type: "behavior event",
|
|
828
|
+
behaviorEvent: {
|
|
829
|
+
type: "copy",
|
|
830
|
+
data: event.nativeEvent.clipboardData,
|
|
831
|
+
position
|
|
832
|
+
},
|
|
833
|
+
editor: slateEditor,
|
|
834
|
+
nativeEvent: event
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
}, [onCopy, editorActor, slateEditor]), handleCut = useCallback((event_0) => {
|
|
838
|
+
if (onCut)
|
|
839
|
+
onCut(event_0) !== void 0 && event_0.preventDefault();
|
|
840
|
+
else if (event_0.nativeEvent.clipboardData) {
|
|
841
|
+
event_0.stopPropagation(), event_0.preventDefault();
|
|
842
|
+
const position_0 = getEventPosition({
|
|
843
|
+
snapshot: getEditorSnapshot({
|
|
844
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
845
|
+
slateEditorInstance: slateEditor
|
|
846
|
+
}),
|
|
847
|
+
slateEditor,
|
|
848
|
+
event: event_0.nativeEvent
|
|
849
|
+
});
|
|
850
|
+
if (!position_0) {
|
|
851
|
+
console.warn("Could not find position for cut event");
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
editorActor.send({
|
|
855
|
+
type: "behavior event",
|
|
856
|
+
behaviorEvent: {
|
|
857
|
+
type: "cut",
|
|
858
|
+
dataTransfer: event_0.nativeEvent.clipboardData,
|
|
859
|
+
position: position_0
|
|
860
|
+
},
|
|
861
|
+
editor: slateEditor,
|
|
862
|
+
nativeEvent: event_0
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
}, [onCut, editorActor, slateEditor]), handlePaste = useCallback((event_1) => {
|
|
707
866
|
const value_0 = PortableTextEditor.getValue(portableTextEditor), path = toPortableTextRange(value_0, slateEditor.selection, schemaTypes)?.focus.path || [], onPasteResult = onPaste?.({
|
|
708
|
-
event:
|
|
867
|
+
event: event_1,
|
|
709
868
|
value: value_0,
|
|
710
869
|
path,
|
|
711
870
|
schemaTypes
|
|
712
871
|
});
|
|
713
|
-
onPasteResult || !slateEditor.selection
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
872
|
+
if (onPasteResult || !slateEditor.selection)
|
|
873
|
+
event_1.preventDefault(), editorActor.send({
|
|
874
|
+
type: "notify.loading"
|
|
875
|
+
}), Promise.resolve(onPasteResult).then((result_1) => {
|
|
876
|
+
if (debug("Custom paste function from client resolved", result_1), !result_1 || !result_1.insert) {
|
|
877
|
+
debug("No result from custom paste handler, pasting normally");
|
|
878
|
+
const position_1 = getEventPosition({
|
|
879
|
+
snapshot: getEditorSnapshot({
|
|
880
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
881
|
+
slateEditorInstance: slateEditor
|
|
882
|
+
}),
|
|
883
|
+
slateEditor,
|
|
884
|
+
event: event_1.nativeEvent
|
|
885
|
+
});
|
|
886
|
+
if (!position_1) {
|
|
887
|
+
console.warn("Could not find position for paste event");
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
editorActor.send({
|
|
891
|
+
type: "behavior event",
|
|
892
|
+
behaviorEvent: {
|
|
893
|
+
type: "paste",
|
|
894
|
+
data: event_1.clipboardData,
|
|
895
|
+
position: position_1
|
|
896
|
+
},
|
|
897
|
+
editor: slateEditor,
|
|
898
|
+
nativeEvent: event_1
|
|
899
|
+
});
|
|
900
|
+
} else result_1.insert ? editorActor.send({
|
|
901
|
+
type: "behavior event",
|
|
902
|
+
behaviorEvent: {
|
|
903
|
+
type: "insert.blocks",
|
|
904
|
+
blocks: parseBlocks({
|
|
905
|
+
context: {
|
|
906
|
+
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
907
|
+
schema: editorActor.getSnapshot().context.schema
|
|
908
|
+
},
|
|
909
|
+
blocks: result_1.insert,
|
|
910
|
+
options: {
|
|
911
|
+
refreshKeys: !0
|
|
912
|
+
}
|
|
913
|
+
}),
|
|
914
|
+
placement: "auto"
|
|
915
|
+
},
|
|
916
|
+
editor: slateEditor
|
|
917
|
+
}) : console.warn("Your onPaste function returned something unexpected:", result_1);
|
|
918
|
+
}).catch((error) => (console.warn(error), error)).finally(() => {
|
|
919
|
+
editorActor.send({
|
|
920
|
+
type: "notify.done loading"
|
|
921
|
+
});
|
|
922
|
+
});
|
|
923
|
+
else if (event_1.nativeEvent.clipboardData) {
|
|
924
|
+
event_1.preventDefault(), event_1.stopPropagation();
|
|
925
|
+
const position_2 = getEventPosition({
|
|
926
|
+
snapshot: getEditorSnapshot({
|
|
927
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
928
|
+
slateEditorInstance: slateEditor
|
|
929
|
+
}),
|
|
930
|
+
slateEditor,
|
|
931
|
+
event: event_1.nativeEvent
|
|
932
|
+
});
|
|
933
|
+
if (!position_2) {
|
|
934
|
+
console.warn("Could not find position for paste event");
|
|
935
|
+
return;
|
|
936
|
+
}
|
|
720
937
|
editorActor.send({
|
|
721
|
-
type: "
|
|
938
|
+
type: "behavior event",
|
|
939
|
+
behaviorEvent: {
|
|
940
|
+
type: "paste",
|
|
941
|
+
data: event_1.nativeEvent.clipboardData,
|
|
942
|
+
position: position_2
|
|
943
|
+
},
|
|
944
|
+
editor: slateEditor,
|
|
945
|
+
nativeEvent: event_1
|
|
722
946
|
});
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
data: event_0.nativeEvent.clipboardData
|
|
728
|
-
},
|
|
729
|
-
editor: slateEditor,
|
|
730
|
-
nativeEvent: event_0
|
|
731
|
-
}), debug("No result from custom paste handler, pasting normally");
|
|
732
|
-
}, [editorActor, onPaste, portableTextEditor, schemaTypes, slateEditor]), handleOnFocus = useCallback((event_1) => {
|
|
733
|
-
if (onFocus && onFocus(event_1), !event_1.isDefaultPrevented()) {
|
|
947
|
+
}
|
|
948
|
+
debug("No result from custom paste handler, pasting normally");
|
|
949
|
+
}, [editorActor, onPaste, portableTextEditor, schemaTypes, slateEditor]), handleOnFocus = useCallback((event_2) => {
|
|
950
|
+
if (onFocus && onFocus(event_2), !event_2.isDefaultPrevented()) {
|
|
734
951
|
const selection = PortableTextEditor.getSelection(portableTextEditor);
|
|
735
952
|
selection === null && (Transforms.select(slateEditor, Editor.start(slateEditor, [])), slateEditor.onChange()), editorActor.send({
|
|
736
953
|
type: "notify.focused",
|
|
737
|
-
event:
|
|
954
|
+
event: event_2
|
|
738
955
|
});
|
|
739
956
|
const newSelection = PortableTextEditor.getSelection(portableTextEditor);
|
|
740
957
|
selection === newSelection && editorActor.send({
|
|
@@ -742,19 +959,37 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
742
959
|
selection
|
|
743
960
|
});
|
|
744
961
|
}
|
|
745
|
-
}, [editorActor, onFocus, portableTextEditor, slateEditor]), handleClick = useCallback((
|
|
746
|
-
onClick && onClick(
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
962
|
+
}, [editorActor, onFocus, portableTextEditor, slateEditor]), handleClick = useCallback((event_3) => {
|
|
963
|
+
if (onClick && onClick(event_3), event_3.isDefaultPrevented() || event_3.isPropagationStopped())
|
|
964
|
+
return;
|
|
965
|
+
const position_3 = getEventPosition({
|
|
966
|
+
snapshot: getEditorSnapshot({
|
|
967
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
968
|
+
slateEditorInstance: slateEditor
|
|
969
|
+
}),
|
|
970
|
+
slateEditor,
|
|
971
|
+
event: event_3.nativeEvent
|
|
972
|
+
});
|
|
973
|
+
if (!position_3) {
|
|
974
|
+
console.warn("Could not find EventPosition for MouseEvent");
|
|
975
|
+
return;
|
|
976
|
+
}
|
|
977
|
+
editorActor.send({
|
|
978
|
+
type: "behavior event",
|
|
979
|
+
behaviorEvent: {
|
|
980
|
+
type: "mouse.click",
|
|
981
|
+
position: position_3
|
|
982
|
+
},
|
|
983
|
+
editor: slateEditor,
|
|
984
|
+
nativeEvent: event_3
|
|
985
|
+
});
|
|
986
|
+
}, [onClick, editorActor, slateEditor]), handleOnBlur = useCallback((event_4) => {
|
|
987
|
+
onBlur && onBlur(event_4), event_4.isPropagationStopped() || editorActor.send({
|
|
753
988
|
type: "notify.blurred",
|
|
754
|
-
event:
|
|
989
|
+
event: event_4
|
|
755
990
|
});
|
|
756
|
-
}, [editorActor, onBlur]), handleOnBeforeInput = useCallback((
|
|
757
|
-
onBeforeInput && onBeforeInput(
|
|
991
|
+
}, [editorActor, onBlur]), handleOnBeforeInput = useCallback((event_5) => {
|
|
992
|
+
onBeforeInput && onBeforeInput(event_5);
|
|
758
993
|
}, [onBeforeInput]), validateSelection = useCallback(() => {
|
|
759
994
|
if (!slateEditor.selection)
|
|
760
995
|
return;
|
|
@@ -788,39 +1023,39 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
788
1023
|
};
|
|
789
1024
|
}
|
|
790
1025
|
}, [validateSelection, editableElement]);
|
|
791
|
-
const handleKeyDown = useCallback((
|
|
792
|
-
props.onKeyDown && props.onKeyDown(
|
|
1026
|
+
const handleKeyDown = useCallback((event_6) => {
|
|
1027
|
+
props.onKeyDown && props.onKeyDown(event_6), event_6.isDefaultPrevented() || slateEditor.pteWithHotKeys(event_6), event_6.isDefaultPrevented() || editorActor.send({
|
|
793
1028
|
type: "behavior event",
|
|
794
1029
|
behaviorEvent: {
|
|
795
1030
|
type: "key.down",
|
|
796
1031
|
keyboardEvent: {
|
|
797
|
-
key:
|
|
798
|
-
code:
|
|
799
|
-
altKey:
|
|
800
|
-
ctrlKey:
|
|
801
|
-
metaKey:
|
|
802
|
-
shiftKey:
|
|
1032
|
+
key: event_6.key,
|
|
1033
|
+
code: event_6.code,
|
|
1034
|
+
altKey: event_6.altKey,
|
|
1035
|
+
ctrlKey: event_6.ctrlKey,
|
|
1036
|
+
metaKey: event_6.metaKey,
|
|
1037
|
+
shiftKey: event_6.shiftKey
|
|
803
1038
|
}
|
|
804
1039
|
},
|
|
805
1040
|
editor: slateEditor,
|
|
806
|
-
nativeEvent:
|
|
1041
|
+
nativeEvent: event_6
|
|
807
1042
|
});
|
|
808
|
-
}, [props, editorActor, slateEditor]), handleKeyUp = useCallback((
|
|
809
|
-
props.onKeyUp && props.onKeyUp(
|
|
1043
|
+
}, [props, editorActor, slateEditor]), handleKeyUp = useCallback((event_7) => {
|
|
1044
|
+
props.onKeyUp && props.onKeyUp(event_7), event_7.isDefaultPrevented() || editorActor.send({
|
|
810
1045
|
type: "behavior event",
|
|
811
1046
|
behaviorEvent: {
|
|
812
1047
|
type: "key.up",
|
|
813
1048
|
keyboardEvent: {
|
|
814
|
-
key:
|
|
815
|
-
code:
|
|
816
|
-
altKey:
|
|
817
|
-
ctrlKey:
|
|
818
|
-
metaKey:
|
|
819
|
-
shiftKey:
|
|
1049
|
+
key: event_7.key,
|
|
1050
|
+
code: event_7.code,
|
|
1051
|
+
altKey: event_7.altKey,
|
|
1052
|
+
ctrlKey: event_7.ctrlKey,
|
|
1053
|
+
metaKey: event_7.metaKey,
|
|
1054
|
+
shiftKey: event_7.shiftKey
|
|
820
1055
|
}
|
|
821
1056
|
},
|
|
822
1057
|
editor: slateEditor,
|
|
823
|
-
nativeEvent:
|
|
1058
|
+
nativeEvent: event_7
|
|
824
1059
|
});
|
|
825
1060
|
}, [props, editorActor, slateEditor]), scrollSelectionIntoViewToSlate = useMemo(() => {
|
|
826
1061
|
if (scrollSelectionIntoView !== void 0)
|
|
@@ -842,7 +1077,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
842
1077
|
}];
|
|
843
1078
|
if (path_0.length === 0)
|
|
844
1079
|
return [];
|
|
845
|
-
const
|
|
1080
|
+
const result_2 = rangeDecorationState.filter((item) => Range.isCollapsed(item) ? path_0.length !== 2 ? !1 : Path.equals(item.focus.path, path_0) && Path.equals(item.anchor.path, path_0) : Range.intersection(item, {
|
|
846
1081
|
anchor: {
|
|
847
1082
|
path: path_0,
|
|
848
1083
|
offset: 0
|
|
@@ -852,24 +1087,164 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
852
1087
|
offset: 0
|
|
853
1088
|
}
|
|
854
1089
|
}) || Range.includes(item, path_0));
|
|
855
|
-
return
|
|
1090
|
+
return result_2.length > 0 ? result_2 : [];
|
|
856
1091
|
}, [slateEditor, schemaTypes, rangeDecorationState]);
|
|
857
|
-
|
|
1092
|
+
useEffect(() => {
|
|
858
1093
|
ref.current = ReactEditor.toDOMNode(slateEditor, slateEditor), setEditableElement(ref.current);
|
|
859
1094
|
}, [slateEditor, ref]), useEffect(() => {
|
|
860
|
-
const window_0 = ReactEditor.getWindow(slateEditor),
|
|
1095
|
+
const window_0 = ReactEditor.getWindow(slateEditor), onDragEnd_0 = () => {
|
|
861
1096
|
editorActor.send({
|
|
862
1097
|
type: "dragend"
|
|
863
1098
|
});
|
|
864
|
-
},
|
|
1099
|
+
}, onDrop_0 = () => {
|
|
865
1100
|
editorActor.send({
|
|
866
1101
|
type: "drop"
|
|
867
1102
|
});
|
|
868
1103
|
};
|
|
869
|
-
return window_0.document.addEventListener("dragend",
|
|
870
|
-
window_0.document.removeEventListener("dragend",
|
|
1104
|
+
return window_0.document.addEventListener("dragend", onDragEnd_0), window_0.document.addEventListener("drop", onDrop_0), () => {
|
|
1105
|
+
window_0.document.removeEventListener("dragend", onDragEnd_0), window_0.document.removeEventListener("drop", onDrop_0);
|
|
871
1106
|
};
|
|
872
|
-
}, [slateEditor, editorActor])
|
|
1107
|
+
}, [slateEditor, editorActor]);
|
|
1108
|
+
const handleDragStart = useCallback((event_8) => {
|
|
1109
|
+
if (onDragStart?.(event_8), !event_8.isDefaultPrevented() && !event_8.isPropagationStopped()) {
|
|
1110
|
+
const position_4 = getEventPosition({
|
|
1111
|
+
snapshot: getEditorSnapshot({
|
|
1112
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1113
|
+
slateEditorInstance: slateEditor
|
|
1114
|
+
}),
|
|
1115
|
+
slateEditor,
|
|
1116
|
+
event: event_8.nativeEvent
|
|
1117
|
+
});
|
|
1118
|
+
if (!position_4) {
|
|
1119
|
+
console.warn("Could not find position for dragstart event");
|
|
1120
|
+
return;
|
|
1121
|
+
}
|
|
1122
|
+
if (ReactEditor.hasTarget(slateEditor, event_8.target)) {
|
|
1123
|
+
const node = ReactEditor.toSlateNode(slateEditor, event_8.target), path_1 = ReactEditor.findPath(slateEditor, node);
|
|
1124
|
+
if (Element$1.isElement(node) && Editor.isVoid(slateEditor, node) || Editor.void(slateEditor, {
|
|
1125
|
+
at: path_1,
|
|
1126
|
+
voids: !0
|
|
1127
|
+
})) {
|
|
1128
|
+
const range = Editor.range(slateEditor, path_1);
|
|
1129
|
+
Transforms.select(slateEditor, range);
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
editorActor.send({
|
|
1133
|
+
type: "dragstart",
|
|
1134
|
+
origin: position_4
|
|
1135
|
+
}), editorActor.send({
|
|
1136
|
+
type: "behavior event",
|
|
1137
|
+
behaviorEvent: {
|
|
1138
|
+
type: "drag.dragstart",
|
|
1139
|
+
dataTransfer: event_8.dataTransfer,
|
|
1140
|
+
position: position_4
|
|
1141
|
+
},
|
|
1142
|
+
editor: slateEditor
|
|
1143
|
+
}), event_8.stopPropagation();
|
|
1144
|
+
}
|
|
1145
|
+
}, [onDragStart, editorActor, slateEditor]), handleDrag = useCallback((event_9) => {
|
|
1146
|
+
onDrag?.(event_9), !event_9.isDefaultPrevented() && !event_9.isPropagationStopped() && (editorActor.send({
|
|
1147
|
+
type: "behavior event",
|
|
1148
|
+
behaviorEvent: {
|
|
1149
|
+
type: "drag.drag",
|
|
1150
|
+
dataTransfer: event_9.dataTransfer
|
|
1151
|
+
},
|
|
1152
|
+
editor: slateEditor
|
|
1153
|
+
}), event_9.stopPropagation());
|
|
1154
|
+
}, [onDrag, editorActor, slateEditor]), handleDragEnd = useCallback((event_10) => {
|
|
1155
|
+
onDragEnd?.(event_10), !event_10.isDefaultPrevented() && !event_10.isPropagationStopped() && (editorActor.send({
|
|
1156
|
+
type: "behavior event",
|
|
1157
|
+
behaviorEvent: {
|
|
1158
|
+
type: "drag.dragend",
|
|
1159
|
+
dataTransfer: event_10.dataTransfer
|
|
1160
|
+
},
|
|
1161
|
+
editor: slateEditor
|
|
1162
|
+
}), event_10.stopPropagation());
|
|
1163
|
+
}, [onDragEnd, editorActor, slateEditor]), handleDragEnter = useCallback((event_11) => {
|
|
1164
|
+
if (onDragEnter?.(event_11), !event_11.isDefaultPrevented() && !event_11.isPropagationStopped()) {
|
|
1165
|
+
const position_5 = getEventPosition({
|
|
1166
|
+
snapshot: getEditorSnapshot({
|
|
1167
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1168
|
+
slateEditorInstance: slateEditor
|
|
1169
|
+
}),
|
|
1170
|
+
slateEditor,
|
|
1171
|
+
event: event_11.nativeEvent
|
|
1172
|
+
});
|
|
1173
|
+
if (!position_5) {
|
|
1174
|
+
console.warn("Could not find position for dragenter event");
|
|
1175
|
+
return;
|
|
1176
|
+
}
|
|
1177
|
+
editorActor.send({
|
|
1178
|
+
type: "behavior event",
|
|
1179
|
+
behaviorEvent: {
|
|
1180
|
+
type: "drag.dragenter",
|
|
1181
|
+
dataTransfer: event_11.dataTransfer,
|
|
1182
|
+
position: position_5
|
|
1183
|
+
},
|
|
1184
|
+
editor: slateEditor
|
|
1185
|
+
}), event_11.stopPropagation();
|
|
1186
|
+
}
|
|
1187
|
+
}, [onDragEnter, editorActor, slateEditor]), handleDragOver = useCallback((event_12) => {
|
|
1188
|
+
if (onDragOver?.(event_12), !event_12.isDefaultPrevented() && !event_12.isPropagationStopped()) {
|
|
1189
|
+
const position_6 = getEventPosition({
|
|
1190
|
+
snapshot: getEditorSnapshot({
|
|
1191
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1192
|
+
slateEditorInstance: slateEditor
|
|
1193
|
+
}),
|
|
1194
|
+
slateEditor,
|
|
1195
|
+
event: event_12.nativeEvent
|
|
1196
|
+
});
|
|
1197
|
+
if (!position_6) {
|
|
1198
|
+
console.warn("Could not find position for dragover event");
|
|
1199
|
+
return;
|
|
1200
|
+
}
|
|
1201
|
+
editorActor.send({
|
|
1202
|
+
type: "behavior event",
|
|
1203
|
+
behaviorEvent: {
|
|
1204
|
+
type: "drag.dragover",
|
|
1205
|
+
dataTransfer: event_12.dataTransfer,
|
|
1206
|
+
position: position_6
|
|
1207
|
+
},
|
|
1208
|
+
editor: slateEditor,
|
|
1209
|
+
nativeEvent: event_12
|
|
1210
|
+
}), event_12.stopPropagation();
|
|
1211
|
+
}
|
|
1212
|
+
}, [onDragOver, editorActor, slateEditor]), handleDrop = useCallback((event_13) => {
|
|
1213
|
+
if (onDrop?.(event_13), !event_13.isDefaultPrevented() && !event_13.isPropagationStopped()) {
|
|
1214
|
+
const position_7 = getEventPosition({
|
|
1215
|
+
snapshot: getEditorSnapshot({
|
|
1216
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1217
|
+
slateEditorInstance: slateEditor
|
|
1218
|
+
}),
|
|
1219
|
+
slateEditor,
|
|
1220
|
+
event: event_13.nativeEvent
|
|
1221
|
+
});
|
|
1222
|
+
if (!position_7) {
|
|
1223
|
+
console.warn("Could not find position for drop event");
|
|
1224
|
+
return;
|
|
1225
|
+
}
|
|
1226
|
+
const range_0 = ReactEditor.findEventRange(slateEditor, event_13);
|
|
1227
|
+
slateEditor.select(range_0), editorActor.send({
|
|
1228
|
+
type: "behavior event",
|
|
1229
|
+
behaviorEvent: {
|
|
1230
|
+
type: "drag.drop",
|
|
1231
|
+
dataTransfer: event_13.dataTransfer,
|
|
1232
|
+
position: position_7
|
|
1233
|
+
},
|
|
1234
|
+
editor: slateEditor
|
|
1235
|
+
}), event_13.preventDefault();
|
|
1236
|
+
}
|
|
1237
|
+
}, [onDrop, editorActor, slateEditor]), handleDragLeave = useCallback((event_14) => {
|
|
1238
|
+
onDragLeave?.(event_14), !event_14.isDefaultPrevented() && !event_14.isPropagationStopped() && editorActor.send({
|
|
1239
|
+
type: "behavior event",
|
|
1240
|
+
behaviorEvent: {
|
|
1241
|
+
type: "drag.dragleave",
|
|
1242
|
+
dataTransfer: event_14.dataTransfer
|
|
1243
|
+
},
|
|
1244
|
+
editor: slateEditor
|
|
1245
|
+
});
|
|
1246
|
+
}, [onDragLeave, editorActor, slateEditor]);
|
|
1247
|
+
return portableTextEditor ? hasInvalidValue ? null : /* @__PURE__ */ jsx(
|
|
873
1248
|
Editable,
|
|
874
1249
|
{
|
|
875
1250
|
...restProps,
|
|
@@ -878,13 +1253,16 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
878
1253
|
decorate,
|
|
879
1254
|
onBlur: handleOnBlur,
|
|
880
1255
|
onCopy: handleCopy,
|
|
1256
|
+
onCut: handleCut,
|
|
881
1257
|
onClick: handleClick,
|
|
882
1258
|
onDOMBeforeInput: handleOnBeforeInput,
|
|
883
|
-
onDragStart:
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
1259
|
+
onDragStart: handleDragStart,
|
|
1260
|
+
onDrag: handleDrag,
|
|
1261
|
+
onDragEnd: handleDragEnd,
|
|
1262
|
+
onDragEnter: handleDragEnter,
|
|
1263
|
+
onDragOver: handleDragOver,
|
|
1264
|
+
onDrop: handleDrop,
|
|
1265
|
+
onDragLeave: handleDragLeave,
|
|
888
1266
|
onFocus: handleOnFocus,
|
|
889
1267
|
onKeyDown: handleKeyDown,
|
|
890
1268
|
onKeyUp: handleKeyUp,
|