@portabletext/editor 1.35.0 → 1.35.2
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/{plugin.event-listener.cjs → editor-provider.cjs} +50 -20
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -0
- package/lib/_chunks-es/{plugin.event-listener.js → editor-provider.js} +51 -21
- package/lib/_chunks-es/editor-provider.js.map +1 -0
- package/lib/behaviors/index.d.cts +19377 -210
- package/lib/behaviors/index.d.ts +19377 -210
- package/lib/index.cjs +81 -51
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +318 -47
- package/lib/index.d.ts +318 -47
- package/lib/index.js +35 -4
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +22 -7
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +313 -2
- package/lib/plugins/index.d.ts +313 -2
- package/lib/plugins/index.js +18 -3
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.cts +19504 -1
- package/lib/selectors/index.d.ts +19504 -1
- package/lib/utils/index.d.cts +19506 -2
- package/lib/utils/index.d.ts +19506 -2
- package/package.json +3 -3
- package/src/behavior-actions/behavior.action.decorator.add.ts +1 -0
- package/src/behavior-actions/behavior.action.delete.text.ts +1 -0
- package/src/behaviors/behavior.decorator-pair.ts +1 -0
- package/src/converters/converter.portable-text.deserialize.test.ts +3 -7
- package/src/converters/converter.portable-text.ts +7 -1
- package/src/converters/converter.text-html.deserialize.test.ts +3 -7
- package/src/converters/converter.text-html.serialize.test.ts +5 -10
- package/src/converters/converter.text-plain.test.ts +4 -6
- package/src/editor/Editable.tsx +26 -0
- package/src/editor/editor-machine.ts +170 -147
- package/src/editor/editor-selector.ts +3 -0
- package/src/editor/editor-snapshot.ts +13 -0
- package/src/editor/mutation-machine.ts +2 -0
- package/src/editor-event-listener.tsx +30 -0
- package/src/index.ts +1 -1
- package/src/internal-utils/create-test-snapshot.ts +23 -0
- package/src/plugins/plugin.one-line.tsx +1 -1
- package/src/selectors/selector.get-active-annotations.test.ts +4 -13
- package/src/selectors/selector.get-caret-word-selection.test.ts +3 -7
- package/src/selectors/selector.get-selected-spans.test.ts +5 -9
- package/src/selectors/selector.get-selection-text.test.ts +5 -7
- package/src/selectors/selector.get-trimmed-selection.test.ts +3 -5
- package/src/selectors/selector.is-active-decorator.test.ts +5 -9
- package/lib/_chunks-cjs/plugin.event-listener.cjs.map +0 -1
- package/lib/_chunks-es/plugin.event-listener.js.map +0 -1
package/lib/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var
|
|
3
|
+
var editorProvider = require("./_chunks-cjs/editor-provider.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), React = require("react"), slate = require("slate"), slateReact = require("slate-react"), reactCompilerRuntime = require("react-compiler-runtime"), uniq = require("lodash/uniq.js"), behavior_core = require("./_chunks-cjs/behavior.core.cjs"), useEffectEvent = require("use-effect-event");
|
|
4
4
|
function _interopDefaultCompat(e) {
|
|
5
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
6
|
}
|
|
@@ -81,7 +81,7 @@ function DefaultInlineObject(props) {
|
|
|
81
81
|
"]"
|
|
82
82
|
] }), $[1] = props.value._key, $[2] = props.value._type, $[3] = t1) : t1 = $[3], t1;
|
|
83
83
|
}
|
|
84
|
-
const debug$3 =
|
|
84
|
+
const debug$3 = editorProvider.debugWithName("components:DraggableBlock"), DraggableBlock = (t0) => {
|
|
85
85
|
const $ = reactCompilerRuntime.c(51), {
|
|
86
86
|
children,
|
|
87
87
|
element,
|
|
@@ -98,12 +98,12 @@ const debug$3 = plugin_eventListener.debugWithName("components:DraggableBlock"),
|
|
|
98
98
|
$[6] !== blockRef || $[7] !== editor || $[8] !== element ? (t5 = () => setBlockElement(blockRef ? blockRef.current : slateReact.ReactEditor.toDOMNode(editor, element)), t6 = [editor, element, blockRef], $[6] = blockRef, $[7] = editor, $[8] = element, $[9] = t5, $[10] = t6) : (t5 = $[9], t6 = $[10]), React.useEffect(t5, t6);
|
|
99
99
|
let t7;
|
|
100
100
|
$[11] !== blockElement || $[12] !== editor || $[13] !== element ? (t7 = (event) => {
|
|
101
|
-
const isMyDragOver =
|
|
101
|
+
const isMyDragOver = editorProvider.IS_DRAGGING_BLOCK_ELEMENT.get(editor);
|
|
102
102
|
if (!isMyDragOver || !blockElement)
|
|
103
103
|
return;
|
|
104
|
-
event.preventDefault(), event.dataTransfer.dropEffect = "move",
|
|
104
|
+
event.preventDefault(), event.dataTransfer.dropEffect = "move", editorProvider.IS_DRAGGING_ELEMENT_TARGET.set(editor, element);
|
|
105
105
|
const elementRect = blockElement.getBoundingClientRect(), offset = elementRect.top, height = elementRect.height, Y = event.pageY, loc = Math.abs(offset - Y);
|
|
106
|
-
if (element === editor.children[0] || (loc < height / 2 ?
|
|
106
|
+
if (element === editor.children[0] || (loc < height / 2 ? editorProvider.IS_DRAGGING_BLOCK_TARGET_POSITION.set(editor, "top") : editorProvider.IS_DRAGGING_BLOCK_TARGET_POSITION.set(editor, "bottom")), isMyDragOver === element) {
|
|
107
107
|
event.dataTransfer.dropEffect = "none";
|
|
108
108
|
return;
|
|
109
109
|
}
|
|
@@ -117,11 +117,11 @@ const debug$3 = plugin_eventListener.debugWithName("components:DraggableBlock"),
|
|
|
117
117
|
const handleDragLeave = t8;
|
|
118
118
|
let t9;
|
|
119
119
|
$[16] !== editor || $[17] !== element ? (t9 = (event_0) => {
|
|
120
|
-
const targetBlock =
|
|
120
|
+
const targetBlock = editorProvider.IS_DRAGGING_ELEMENT_TARGET.get(editor);
|
|
121
121
|
if (targetBlock) {
|
|
122
|
-
|
|
123
|
-
const dragPosition =
|
|
124
|
-
|
|
122
|
+
editorProvider.IS_DRAGGING.set(editor, !1), event_0.preventDefault(), event_0.stopPropagation(), editorProvider.IS_DRAGGING_ELEMENT_TARGET.delete(editor), dragGhostRef.current && (debug$3("Removing drag ghost"), document.body.removeChild(dragGhostRef.current));
|
|
123
|
+
const dragPosition = editorProvider.IS_DRAGGING_BLOCK_TARGET_POSITION.get(editor);
|
|
124
|
+
editorProvider.IS_DRAGGING_BLOCK_TARGET_POSITION.delete(editor);
|
|
125
125
|
let targetPath = slateReact.ReactEditor.findPath(editor, targetBlock);
|
|
126
126
|
const myPath = slateReact.ReactEditor.findPath(editor, element), isBefore = slate.Path.isBefore(myPath, targetPath);
|
|
127
127
|
if (dragPosition === "bottom" && !isBefore) {
|
|
@@ -151,16 +151,16 @@ const debug$3 = plugin_eventListener.debugWithName("components:DraggableBlock"),
|
|
|
151
151
|
const handleDragEnd = t9;
|
|
152
152
|
let t10;
|
|
153
153
|
$[19] !== editor || $[20] !== element ? (t10 = (event_1) => {
|
|
154
|
-
|
|
154
|
+
editorProvider.IS_DRAGGING_BLOCK_ELEMENT.get(editor) && (debug$3("On drop (prevented)", element), event_1.preventDefault(), event_1.stopPropagation(), setIsDragOver(!1));
|
|
155
155
|
}, $[19] = editor, $[20] = element, $[21] = t10) : t10 = $[21];
|
|
156
156
|
const handleDrop = t10;
|
|
157
157
|
let t11;
|
|
158
158
|
$[22] !== editor || $[23] !== element || $[24] !== isVoid ? (t11 = (event_2) => {
|
|
159
159
|
if (!isVoid) {
|
|
160
|
-
|
|
160
|
+
editorProvider.IS_DRAGGING_BLOCK_ELEMENT.delete(editor);
|
|
161
161
|
return;
|
|
162
162
|
}
|
|
163
|
-
|
|
163
|
+
editorProvider.IS_DRAGGING.set(editor, !0), editorProvider.IS_DRAGGING_BLOCK_ELEMENT.set(editor, element), event_2.stopPropagation();
|
|
164
164
|
const target = event_2.target;
|
|
165
165
|
target instanceof HTMLElement && (target.style.opacity = "1");
|
|
166
166
|
}, $[22] = editor, $[23] = element, $[24] = isVoid, $[25] = t11) : t11 = $[25];
|
|
@@ -168,10 +168,10 @@ const debug$3 = plugin_eventListener.debugWithName("components:DraggableBlock"),
|
|
|
168
168
|
let t12;
|
|
169
169
|
$[26] !== blockElement || $[27] !== editor || $[28] !== handleDrag || $[29] !== isInline || $[30] !== isVoid ? (t12 = (event_3) => {
|
|
170
170
|
if (!isVoid || isInline) {
|
|
171
|
-
debug$3("Not dragging block"),
|
|
171
|
+
debug$3("Not dragging block"), editorProvider.IS_DRAGGING_BLOCK_ELEMENT.delete(editor), editorProvider.IS_DRAGGING.set(editor, !1);
|
|
172
172
|
return;
|
|
173
173
|
}
|
|
174
|
-
if (debug$3("Drag start"),
|
|
174
|
+
if (debug$3("Drag start"), editorProvider.IS_DRAGGING.set(editor, !0), event_3.dataTransfer && (event_3.dataTransfer.setData("application/portable-text", "something"), event_3.dataTransfer.effectAllowed = "move"), blockElement && blockElement instanceof HTMLElement) {
|
|
175
175
|
let dragGhost = blockElement.cloneNode(!0);
|
|
176
176
|
const customGhost = dragGhost.querySelector("[data-pt-drag-ghost-element]");
|
|
177
177
|
if (customGhost && (dragGhost = customGhost), dragGhost.setAttribute("data-dragged", ""), document.body) {
|
|
@@ -184,11 +184,11 @@ const debug$3 = plugin_eventListener.debugWithName("components:DraggableBlock"),
|
|
|
184
184
|
}, $[26] = blockElement, $[27] = editor, $[28] = handleDrag, $[29] = isInline, $[30] = isVoid, $[31] = t12) : t12 = $[31];
|
|
185
185
|
const handleDragStart = t12;
|
|
186
186
|
let t13;
|
|
187
|
-
$[32] !== editor || $[33] !== isDragOver ? (t13 = isDragOver && editor.children[0] ===
|
|
187
|
+
$[32] !== editor || $[33] !== isDragOver ? (t13 = isDragOver && editor.children[0] === editorProvider.IS_DRAGGING_ELEMENT_TARGET.get(editor), $[32] = editor, $[33] = isDragOver, $[34] = t13) : t13 = $[34];
|
|
188
188
|
const isDraggingOverFirstBlock = t13;
|
|
189
189
|
let t14;
|
|
190
|
-
$[35] !== editor || $[36] !== isDragOver ? (t14 = isDragOver && editor.children[editor.children.length - 1] ===
|
|
191
|
-
const isDraggingOverLastBlock = t14, dragPosition_0 =
|
|
190
|
+
$[35] !== editor || $[36] !== isDragOver ? (t14 = isDragOver && editor.children[editor.children.length - 1] === editorProvider.IS_DRAGGING_ELEMENT_TARGET.get(editor), $[35] = editor, $[36] = isDragOver, $[37] = t14) : t14 = $[37];
|
|
191
|
+
const isDraggingOverLastBlock = t14, dragPosition_0 = editorProvider.IS_DRAGGING_BLOCK_TARGET_POSITION.get(editor), isDraggingOverTop = isDraggingOverFirstBlock || isDragOver && !isDraggingOverFirstBlock && !isDraggingOverLastBlock && dragPosition_0 === "top", isDraggingOverBottom = isDraggingOverLastBlock || isDragOver && !isDraggingOverFirstBlock && !isDraggingOverLastBlock && dragPosition_0 === "bottom";
|
|
192
192
|
let t15, t16;
|
|
193
193
|
$[38] === Symbol.for("react.memo_cache_sentinel") ? (t16 = /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pt-drop-indicator", style: {
|
|
194
194
|
position: "absolute",
|
|
@@ -211,7 +211,7 @@ const debug$3 = plugin_eventListener.debugWithName("components:DraggableBlock"),
|
|
|
211
211
|
] }), $[41] = children, $[42] = handleDrag, $[43] = handleDragEnd, $[44] = handleDragOver, $[45] = handleDragStart, $[46] = handleDrop, $[47] = isVoid, $[48] = t17, $[49] = t18, $[50] = t19) : t19 = $[50], t19;
|
|
212
212
|
};
|
|
213
213
|
DraggableBlock.displayName = "DraggableBlock";
|
|
214
|
-
|
|
214
|
+
editorProvider.debugWithName("components:Element");
|
|
215
215
|
const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
216
216
|
display: "inline-block"
|
|
217
217
|
}, Element = ({
|
|
@@ -226,7 +226,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
226
226
|
renderStyle,
|
|
227
227
|
spellCheck
|
|
228
228
|
}) => {
|
|
229
|
-
const editor = slateReact.useSlateStatic(), selected = slateReact.useSelected(), blockRef = React.useRef(null), inlineBlockObjectRef = React.useRef(null), focused = selected && editor.selection && slate.Range.isCollapsed(editor.selection) || !1, value = React.useMemo(() =>
|
|
229
|
+
const editor = slateReact.useSlateStatic(), selected = slateReact.useSelected(), blockRef = React.useRef(null), inlineBlockObjectRef = React.useRef(null), focused = selected && editor.selection && slate.Range.isCollapsed(editor.selection) || !1, value = React.useMemo(() => editorProvider.fromSlateValue([element], schemaTypes.block.name, editorProvider.KEY_TO_VALUE_ELEMENT.get(editor))[0], [editor, element, schemaTypes.block.name]);
|
|
230
230
|
let renderedBlock = children, className;
|
|
231
231
|
const blockPath = React.useMemo(() => [{
|
|
232
232
|
_key: element._key
|
|
@@ -321,7 +321,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
321
321
|
if (!schemaType_0)
|
|
322
322
|
throw new Error(`Could not find schema type for block element of _type ${element._type}`);
|
|
323
323
|
className = "pt-block pt-object-block";
|
|
324
|
-
const block_0 =
|
|
324
|
+
const block_0 = editorProvider.fromSlateValue([element], schemaTypes.block.name, editorProvider.KEY_TO_VALUE_ELEMENT.get(editor))[0];
|
|
325
325
|
let renderedBlockFromProps;
|
|
326
326
|
if (renderBlock) {
|
|
327
327
|
const _props = Object.defineProperty({
|
|
@@ -346,7 +346,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
346
346
|
] }, element._key);
|
|
347
347
|
};
|
|
348
348
|
Element.displayName = "Element";
|
|
349
|
-
const debug$2 =
|
|
349
|
+
const debug$2 = editorProvider.debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (props) => {
|
|
350
350
|
const {
|
|
351
351
|
editorActor,
|
|
352
352
|
attributes,
|
|
@@ -356,7 +356,7 @@ const debug$2 = plugin_eventListener.debugWithName("components:Leaf"), EMPTY_MAR
|
|
|
356
356
|
renderChild,
|
|
357
357
|
renderDecorator,
|
|
358
358
|
renderAnnotation
|
|
359
|
-
} = props, spanRef = React.useRef(null), portableTextEditor =
|
|
359
|
+
} = props, spanRef = React.useRef(null), portableTextEditor = editorProvider.usePortableTextEditor(), blockSelected = slateReact.useSelected(), [focused, setFocused] = React.useState(!1), [selected, setSelected] = React.useState(!1), block = children.props.parent, path = React.useMemo(() => block ? [{
|
|
360
360
|
_key: block?._key
|
|
361
361
|
}, "children", {
|
|
362
362
|
_key: leaf._key
|
|
@@ -366,8 +366,8 @@ const debug$2 = plugin_eventListener.debugWithName("components:Leaf"), EMPTY_MAR
|
|
|
366
366
|
setFocused(!1);
|
|
367
367
|
return;
|
|
368
368
|
}
|
|
369
|
-
const sel =
|
|
370
|
-
sel && isEqual__default.default(sel.focus.path, path) &&
|
|
369
|
+
const sel = editorProvider.PortableTextEditor.getSelection(portableTextEditor);
|
|
370
|
+
sel && isEqual__default.default(sel.focus.path, path) && editorProvider.PortableTextEditor.isCollapsedSelection(portableTextEditor) && React.startTransition(() => {
|
|
371
371
|
setFocused(!0);
|
|
372
372
|
});
|
|
373
373
|
}, [shouldTrackSelectionAndFocus, path, portableTextEditor]);
|
|
@@ -392,10 +392,10 @@ const debug$2 = plugin_eventListener.debugWithName("components:Leaf"), EMPTY_MAR
|
|
|
392
392
|
const onBlur = editorActor.on("blur", () => {
|
|
393
393
|
setFocused(!1), setSelected(!1);
|
|
394
394
|
}), onFocus = editorActor.on("focus", () => {
|
|
395
|
-
const sel_0 =
|
|
396
|
-
sel_0 && isEqual__default.default(sel_0.focus.path, path) &&
|
|
395
|
+
const sel_0 = editorProvider.PortableTextEditor.getSelection(portableTextEditor);
|
|
396
|
+
sel_0 && isEqual__default.default(sel_0.focus.path, path) && editorProvider.PortableTextEditor.isCollapsedSelection(portableTextEditor) && setFocused(!0), setSelectedFromRange();
|
|
397
397
|
}), onSelection = editorActor.on("selection", (event) => {
|
|
398
|
-
event.selection && isEqual__default.default(event.selection.focus.path, path) &&
|
|
398
|
+
event.selection && isEqual__default.default(event.selection.focus.path, path) && editorProvider.PortableTextEditor.isCollapsedSelection(portableTextEditor) ? setFocused(!0) : setFocused(!1), setSelectedFromRange();
|
|
399
399
|
});
|
|
400
400
|
return () => {
|
|
401
401
|
onBlur.unsubscribe(), onFocus.unsubscribe(), onSelection.unsubscribe();
|
|
@@ -470,7 +470,7 @@ const debug$2 = plugin_eventListener.debugWithName("components:Leaf"), EMPTY_MAR
|
|
|
470
470
|
return React.useMemo(() => /* @__PURE__ */ jsxRuntime.jsx("span", { ...attributes, ref: spanRef, children: content }, leaf._key), [leaf, attributes, content]);
|
|
471
471
|
};
|
|
472
472
|
Leaf.displayName = "Leaf";
|
|
473
|
-
const debug$1 =
|
|
473
|
+
const debug$1 = editorProvider.debugWithName("plugin:withHotKeys");
|
|
474
474
|
function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions) {
|
|
475
475
|
const reservedHotkeys = ["enter", "tab", "shift", "delete", "end"], activeHotkeys = hotkeysFromOptions ?? {};
|
|
476
476
|
return function(editor) {
|
|
@@ -526,7 +526,7 @@ function withSyncRangeDecorations({
|
|
|
526
526
|
slateEditor.apply = originalApply;
|
|
527
527
|
};
|
|
528
528
|
}
|
|
529
|
-
const debug =
|
|
529
|
+
const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
530
530
|
position: "absolute",
|
|
531
531
|
userSelect: "none",
|
|
532
532
|
pointerEvents: "none",
|
|
@@ -553,9 +553,9 @@ const debug = plugin_eventListener.debugWithName("component:Editable"), PLACEHOL
|
|
|
553
553
|
scrollSelectionIntoView,
|
|
554
554
|
spellCheck,
|
|
555
555
|
...restProps
|
|
556
|
-
} = props, portableTextEditor =
|
|
556
|
+
} = props, portableTextEditor = editorProvider.usePortableTextEditor(), ref = React.useRef(null), [editableElement, setEditableElement] = React.useState(null), [hasInvalidValue, setHasInvalidValue] = React.useState(!1), [rangeDecorationState, setRangeDecorationsState] = React.useState([]);
|
|
557
557
|
React.useImperativeHandle(forwardedRef, () => ref.current);
|
|
558
|
-
const rangeDecorationsRef = React.useRef(rangeDecorations), editorActor = React.useContext(
|
|
558
|
+
const rangeDecorationsRef = React.useRef(rangeDecorations), editorActor = React.useContext(editorProvider.EditorActorContext), readOnly = react.useSelector(editorActor, (s) => s.matches({
|
|
559
559
|
"edit mode": "read only"
|
|
560
560
|
})), schemaTypes = react.useSelector(editorActor, (s_0) => s_0.context.schema), slateEditor = slateReact.useSlate(), blockTypeName = schemaTypes.block.name;
|
|
561
561
|
React.useMemo(() => {
|
|
@@ -581,10 +581,10 @@ const debug = plugin_eventListener.debugWithName("component:Editable"), PLACEHOL
|
|
|
581
581
|
}, [editorActor, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder, schemaTypes]), restoreSelectionFromProps = React.useCallback(() => {
|
|
582
582
|
if (propsSelection) {
|
|
583
583
|
debug(`Selection from props ${JSON.stringify(propsSelection)}`);
|
|
584
|
-
const normalizedSelection = normalizeSelection(propsSelection,
|
|
584
|
+
const normalizedSelection = normalizeSelection(propsSelection, editorProvider.fromSlateValue(slateEditor.children, blockTypeName));
|
|
585
585
|
if (normalizedSelection !== null) {
|
|
586
586
|
debug(`Normalized selection from props ${JSON.stringify(normalizedSelection)}`);
|
|
587
|
-
const slateRange =
|
|
587
|
+
const slateRange = editorProvider.toSlateRange(normalizedSelection, slateEditor);
|
|
588
588
|
slateRange && (slate.Transforms.select(slateEditor, slateRange), slateEditor.operations.some((o) => o.type === "set_selection") || editorActor.send({
|
|
589
589
|
type: "notify.selection",
|
|
590
590
|
selection: normalizedSelection
|
|
@@ -595,7 +595,7 @@ const debug = plugin_eventListener.debugWithName("component:Editable"), PLACEHOL
|
|
|
595
595
|
if (rangeDecorations && rangeDecorations.length > 0) {
|
|
596
596
|
const newSlateRanges = [];
|
|
597
597
|
if (rangeDecorations.forEach((rangeDecorationItem) => {
|
|
598
|
-
const slateRange_0 =
|
|
598
|
+
const slateRange_0 = editorProvider.toSlateRange(rangeDecorationItem.selection, slateEditor);
|
|
599
599
|
if (!slate.Range.isRange(slateRange_0)) {
|
|
600
600
|
rangeDecorationItem.onMoved && rangeDecorationItem.onMoved({
|
|
601
601
|
newSelection: null,
|
|
@@ -605,8 +605,8 @@ const debug = plugin_eventListener.debugWithName("component:Editable"), PLACEHOL
|
|
|
605
605
|
return;
|
|
606
606
|
}
|
|
607
607
|
let newRange;
|
|
608
|
-
if (operation && (newRange =
|
|
609
|
-
const value =
|
|
608
|
+
if (operation && (newRange = editorProvider.moveRangeByOperation(slateRange_0, operation), newRange && newRange !== slateRange_0 || newRange === null && slateRange_0)) {
|
|
609
|
+
const value = editorProvider.PortableTextEditor.getValue(portableTextEditor), newRangeSelection = editorProvider.toPortableTextRange(value, newRange, schemaTypes);
|
|
610
610
|
rangeDecorationItem.onMoved && rangeDecorationItem.onMoved({
|
|
611
611
|
newSelection: newRangeSelection,
|
|
612
612
|
rangeDecoration: rangeDecorationItem,
|
|
@@ -662,7 +662,7 @@ const debug = plugin_eventListener.debugWithName("component:Editable"), PLACEHOL
|
|
|
662
662
|
nativeEvent: event
|
|
663
663
|
});
|
|
664
664
|
}, [onCopy, editorActor, slateEditor]), handlePaste = React.useCallback((event_0) => {
|
|
665
|
-
const value_0 =
|
|
665
|
+
const value_0 = editorProvider.PortableTextEditor.getValue(portableTextEditor), path = editorProvider.toPortableTextRange(value_0, slateEditor.selection, schemaTypes)?.focus.path || [], onPasteResult = onPaste?.({
|
|
666
666
|
event: event_0,
|
|
667
667
|
value: value_0,
|
|
668
668
|
path,
|
|
@@ -671,7 +671,7 @@ const debug = plugin_eventListener.debugWithName("component:Editable"), PLACEHOL
|
|
|
671
671
|
onPasteResult || !slateEditor.selection ? (event_0.preventDefault(), editorActor.send({
|
|
672
672
|
type: "notify.loading"
|
|
673
673
|
}), Promise.resolve(onPasteResult).then((result_0) => {
|
|
674
|
-
debug("Custom paste function from client resolved", result_0), !result_0 || !result_0.insert ? (debug("No result from custom paste handler, pasting normally"), slateEditor.insertData(event_0.clipboardData)) : result_0.insert ? slateEditor.insertFragment(
|
|
674
|
+
debug("Custom paste function from client resolved", result_0), !result_0 || !result_0.insert ? (debug("No result from custom paste handler, pasting normally"), slateEditor.insertData(event_0.clipboardData)) : result_0.insert ? slateEditor.insertFragment(editorProvider.toSlateValue(result_0.insert, {
|
|
675
675
|
schemaTypes
|
|
676
676
|
})) : console.warn("Your onPaste function returned something unexpected:", result_0);
|
|
677
677
|
}).catch((error) => (console.error(error), error)).finally(() => {
|
|
@@ -689,12 +689,12 @@ const debug = plugin_eventListener.debugWithName("component:Editable"), PLACEHOL
|
|
|
689
689
|
}), debug("No result from custom paste handler, pasting normally");
|
|
690
690
|
}, [editorActor, onPaste, portableTextEditor, schemaTypes, slateEditor]), handleOnFocus = React.useCallback((event_1) => {
|
|
691
691
|
if (onFocus && onFocus(event_1), !event_1.isDefaultPrevented()) {
|
|
692
|
-
const selection =
|
|
692
|
+
const selection = editorProvider.PortableTextEditor.getSelection(portableTextEditor);
|
|
693
693
|
selection === null && (slate.Transforms.select(slateEditor, slate.Editor.start(slateEditor, [])), slateEditor.onChange()), editorActor.send({
|
|
694
694
|
type: "notify.focused",
|
|
695
695
|
event: event_1
|
|
696
696
|
});
|
|
697
|
-
const newSelection =
|
|
697
|
+
const newSelection = editorProvider.PortableTextEditor.getSelection(portableTextEditor);
|
|
698
698
|
selection === newSelection && editorActor.send({
|
|
699
699
|
type: "notify.selection",
|
|
700
700
|
selection
|
|
@@ -786,7 +786,7 @@ const debug = plugin_eventListener.debugWithName("component:Editable"), PLACEHOL
|
|
|
786
786
|
scrollSelectionIntoView(portableTextEditor, domRange);
|
|
787
787
|
};
|
|
788
788
|
}, [portableTextEditor, scrollSelectionIntoView]), decorate = React.useCallback(([, path_0]) => {
|
|
789
|
-
if (
|
|
789
|
+
if (editorProvider.isEqualToEmptyEditor(slateEditor.children, schemaTypes))
|
|
790
790
|
return [{
|
|
791
791
|
anchor: {
|
|
792
792
|
path: [0, 0],
|
|
@@ -814,7 +814,20 @@ const debug = plugin_eventListener.debugWithName("component:Editable"), PLACEHOL
|
|
|
814
814
|
}, [slateEditor, schemaTypes, rangeDecorationState]);
|
|
815
815
|
return React.useEffect(() => {
|
|
816
816
|
ref.current = slateReact.ReactEditor.toDOMNode(slateEditor, slateEditor), setEditableElement(ref.current);
|
|
817
|
-
}, [slateEditor, ref]),
|
|
817
|
+
}, [slateEditor, ref]), React.useEffect(() => {
|
|
818
|
+
const window_0 = slateReact.ReactEditor.getWindow(slateEditor), onDragEnd = () => {
|
|
819
|
+
editorActor.send({
|
|
820
|
+
type: "dragend"
|
|
821
|
+
});
|
|
822
|
+
}, onDrop = () => {
|
|
823
|
+
editorActor.send({
|
|
824
|
+
type: "drop"
|
|
825
|
+
});
|
|
826
|
+
};
|
|
827
|
+
return window_0.document.addEventListener("dragend", onDragEnd), window_0.document.addEventListener("drop", onDrop), () => {
|
|
828
|
+
window_0.document.removeEventListener("dragend", onDragEnd), window_0.document.removeEventListener("drop", onDrop);
|
|
829
|
+
};
|
|
830
|
+
}, [slateEditor, editorActor]), portableTextEditor ? hasInvalidValue ? null : /* @__PURE__ */ jsxRuntime.jsx(
|
|
818
831
|
slateReact.Editable,
|
|
819
832
|
{
|
|
820
833
|
...restProps,
|
|
@@ -825,6 +838,11 @@ const debug = plugin_eventListener.debugWithName("component:Editable"), PLACEHOL
|
|
|
825
838
|
onCopy: handleCopy,
|
|
826
839
|
onClick: handleClick,
|
|
827
840
|
onDOMBeforeInput: handleOnBeforeInput,
|
|
841
|
+
onDragStart: (event_7) => {
|
|
842
|
+
props.onDragStart?.(event_7), !event_7.isDefaultPrevented() && !event_7.isPropagationStopped() && editorActor.send({
|
|
843
|
+
type: "dragstart"
|
|
844
|
+
});
|
|
845
|
+
},
|
|
828
846
|
onFocus: handleOnFocus,
|
|
829
847
|
onKeyDown: handleKeyDown,
|
|
830
848
|
onKeyUp: handleKeyUp,
|
|
@@ -838,14 +856,26 @@ const debug = plugin_eventListener.debugWithName("component:Editable"), PLACEHOL
|
|
|
838
856
|
) : null;
|
|
839
857
|
});
|
|
840
858
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
859
|
+
function EditorEventListener(props) {
|
|
860
|
+
const $ = reactCompilerRuntime.c(5), editor = editorProvider.useEditor(), on = useEffectEvent.useEffectEvent(props.on);
|
|
861
|
+
let t0;
|
|
862
|
+
$[0] !== editor || $[1] !== on ? (t0 = () => {
|
|
863
|
+
const subscription = editor.on("*", on);
|
|
864
|
+
return () => {
|
|
865
|
+
subscription.unsubscribe();
|
|
866
|
+
};
|
|
867
|
+
}, $[0] = editor, $[1] = on, $[2] = t0) : t0 = $[2];
|
|
868
|
+
let t1;
|
|
869
|
+
return $[3] !== editor ? (t1 = [editor], $[3] = editor, $[4] = t1) : t1 = $[4], React.useEffect(t0, t1), null;
|
|
870
|
+
}
|
|
871
|
+
exports.EditorProvider = editorProvider.EditorProvider;
|
|
872
|
+
exports.PortableTextEditor = editorProvider.PortableTextEditor;
|
|
873
|
+
exports.defineSchema = editorProvider.defineSchema;
|
|
874
|
+
exports.keyGenerator = editorProvider.defaultKeyGenerator;
|
|
875
|
+
exports.useEditor = editorProvider.useEditor;
|
|
876
|
+
exports.useEditorSelector = editorProvider.useEditorSelector;
|
|
877
|
+
exports.usePortableTextEditor = editorProvider.usePortableTextEditor;
|
|
878
|
+
exports.usePortableTextEditorSelection = editorProvider.usePortableTextEditorSelection;
|
|
879
|
+
exports.EditorEventListener = EditorEventListener;
|
|
850
880
|
exports.PortableTextEditable = PortableTextEditable;
|
|
851
881
|
//# sourceMappingURL=index.cjs.map
|