@portabletext/editor 3.3.5 → 3.3.6
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/index.js +86 -8
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.js +1 -1
- package/lib/plugins/index.js.map +1 -1
- package/package.json +5 -5
package/lib/index.js
CHANGED
|
@@ -353,6 +353,35 @@ function slateRangeToSelection({
|
|
|
353
353
|
_key: focusChild._key
|
|
354
354
|
})), selection;
|
|
355
355
|
}
|
|
356
|
+
function slatePointToSelectionPoint({
|
|
357
|
+
schema,
|
|
358
|
+
editor,
|
|
359
|
+
point
|
|
360
|
+
}) {
|
|
361
|
+
const [block] = getPointBlock({
|
|
362
|
+
editor,
|
|
363
|
+
point
|
|
364
|
+
});
|
|
365
|
+
if (!block)
|
|
366
|
+
return;
|
|
367
|
+
const [child] = block._type === schema.block.name ? getPointChild({
|
|
368
|
+
editor,
|
|
369
|
+
point
|
|
370
|
+
}) : [void 0, void 0];
|
|
371
|
+
return child ? {
|
|
372
|
+
path: [{
|
|
373
|
+
_key: block._key
|
|
374
|
+
}, "children", {
|
|
375
|
+
_key: child._key
|
|
376
|
+
}],
|
|
377
|
+
offset: point.offset
|
|
378
|
+
} : {
|
|
379
|
+
path: [{
|
|
380
|
+
_key: block._key
|
|
381
|
+
}],
|
|
382
|
+
offset: point.offset
|
|
383
|
+
};
|
|
384
|
+
}
|
|
356
385
|
function getEventPosition({
|
|
357
386
|
editorActor,
|
|
358
387
|
slateEditor,
|
|
@@ -660,7 +689,7 @@ const EditorActorContext = createContext({});
|
|
|
660
689
|
function DropIndicator() {
|
|
661
690
|
const $ = c(1);
|
|
662
691
|
let t0;
|
|
663
|
-
return $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = /* @__PURE__ */ jsx("div", { contentEditable: !1, className: "pt-drop-indicator", style: {
|
|
692
|
+
return $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = /* @__PURE__ */ jsx("div", { contentEditable: !1, className: "pt-drop-indicator", style: {
|
|
664
693
|
position: "absolute",
|
|
665
694
|
width: "100%",
|
|
666
695
|
height: 1,
|
|
@@ -671,7 +700,7 @@ function DropIndicator() {
|
|
|
671
700
|
function RenderDefaultBlockObject(props) {
|
|
672
701
|
const $ = c(4);
|
|
673
702
|
let t0;
|
|
674
|
-
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = {
|
|
703
|
+
$[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = {
|
|
675
704
|
userSelect: "none"
|
|
676
705
|
}, $[0] = t0) : t0 = $[0];
|
|
677
706
|
let t1;
|
|
@@ -686,7 +715,7 @@ function RenderDefaultBlockObject(props) {
|
|
|
686
715
|
function RenderDefaultInlineObject(props) {
|
|
687
716
|
const $ = c(4);
|
|
688
717
|
let t0;
|
|
689
|
-
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = {
|
|
718
|
+
$[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = {
|
|
690
719
|
userSelect: "none"
|
|
691
720
|
}, $[0] = t0) : t0 = $[0];
|
|
692
721
|
let t1;
|
|
@@ -983,7 +1012,7 @@ function RenderInlineObject(props) {
|
|
|
983
1012
|
}, $[12] = props.element._key, $[13] = props.element._type, $[14] = t3, $[15] = t4) : t4 = $[15];
|
|
984
1013
|
const inlineObject_0 = t4, t5 = !props.readOnly;
|
|
985
1014
|
let t6;
|
|
986
|
-
$[16] === Symbol.for("react.memo_cache_sentinel") ? (t6 = {
|
|
1015
|
+
$[16] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t6 = {
|
|
987
1016
|
display: "inline-block"
|
|
988
1017
|
}, $[16] = t6) : t6 = $[16];
|
|
989
1018
|
let t7;
|
|
@@ -5364,7 +5393,8 @@ function createWithEventListeners(editorActor) {
|
|
|
5364
5393
|
const {
|
|
5365
5394
|
delete: editorDelete,
|
|
5366
5395
|
insertNodes,
|
|
5367
|
-
select
|
|
5396
|
+
select,
|
|
5397
|
+
setSelection
|
|
5368
5398
|
} = editor;
|
|
5369
5399
|
return editor.delete = (options) => {
|
|
5370
5400
|
if (isPerformingBehaviorOperation(editor)) {
|
|
@@ -5529,6 +5559,10 @@ function createWithEventListeners(editorActor) {
|
|
|
5529
5559
|
select(location);
|
|
5530
5560
|
return;
|
|
5531
5561
|
}
|
|
5562
|
+
if (editor.selection) {
|
|
5563
|
+
select(location);
|
|
5564
|
+
return;
|
|
5565
|
+
}
|
|
5532
5566
|
const range = Editor.range(editor, location);
|
|
5533
5567
|
editorActor.send({
|
|
5534
5568
|
type: "behavior event",
|
|
@@ -5542,6 +5576,49 @@ function createWithEventListeners(editorActor) {
|
|
|
5542
5576
|
},
|
|
5543
5577
|
editor
|
|
5544
5578
|
});
|
|
5579
|
+
}, editor.setSelection = (partialRange) => {
|
|
5580
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5581
|
+
setSelection(partialRange);
|
|
5582
|
+
return;
|
|
5583
|
+
}
|
|
5584
|
+
const anchor = partialRange.anchor ? slatePointToSelectionPoint({
|
|
5585
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
5586
|
+
editor,
|
|
5587
|
+
point: partialRange.anchor
|
|
5588
|
+
}) : void 0, focus = partialRange.focus ? slatePointToSelectionPoint({
|
|
5589
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
5590
|
+
editor,
|
|
5591
|
+
point: partialRange.focus
|
|
5592
|
+
}) : void 0, backward = editor.selection ? Range.isBackward({
|
|
5593
|
+
anchor: partialRange.anchor ?? editor.selection.anchor,
|
|
5594
|
+
focus: partialRange.focus ?? editor.selection.focus
|
|
5595
|
+
}) : partialRange.anchor && partialRange.focus ? Range.isBackward({
|
|
5596
|
+
anchor: partialRange.anchor,
|
|
5597
|
+
focus: partialRange.focus
|
|
5598
|
+
}) : void 0;
|
|
5599
|
+
if (editor.selection) {
|
|
5600
|
+
const newAnchor = partialRange.anchor ?? editor.selection.anchor, newFocus = partialRange.focus ?? editor.selection.focus;
|
|
5601
|
+
if (Point.equals(newAnchor, editor.selection.anchor) && Point.equals(newFocus, editor.selection.focus)) {
|
|
5602
|
+
setSelection(partialRange);
|
|
5603
|
+
return;
|
|
5604
|
+
}
|
|
5605
|
+
}
|
|
5606
|
+
if (!anchor || !focus) {
|
|
5607
|
+
setSelection(partialRange);
|
|
5608
|
+
return;
|
|
5609
|
+
}
|
|
5610
|
+
editorActor.send({
|
|
5611
|
+
type: "behavior event",
|
|
5612
|
+
behaviorEvent: {
|
|
5613
|
+
type: "select",
|
|
5614
|
+
at: {
|
|
5615
|
+
anchor,
|
|
5616
|
+
focus,
|
|
5617
|
+
backward
|
|
5618
|
+
}
|
|
5619
|
+
},
|
|
5620
|
+
editor
|
|
5621
|
+
});
|
|
5545
5622
|
}, editor.setFragmentData = () => {
|
|
5546
5623
|
console.error("Unexpected call to .setFragmentData(...)");
|
|
5547
5624
|
}, editor.undo = () => {
|
|
@@ -10366,13 +10443,14 @@ const editorMachine = setup({
|
|
|
10366
10443
|
"handle focus": ({
|
|
10367
10444
|
context
|
|
10368
10445
|
}) => {
|
|
10369
|
-
|
|
10446
|
+
const slateEditor = context.slateEditor;
|
|
10447
|
+
if (!slateEditor) {
|
|
10370
10448
|
console.error("No Slate editor found to focus");
|
|
10371
10449
|
return;
|
|
10372
10450
|
}
|
|
10373
10451
|
try {
|
|
10374
|
-
const currentSelection =
|
|
10375
|
-
ReactEditor.focus(
|
|
10452
|
+
const currentSelection = slateEditor.selection;
|
|
10453
|
+
ReactEditor.focus(slateEditor), currentSelection && (Transforms.select(slateEditor, currentSelection), EDITOR_TO_PENDING_SELECTION.set(slateEditor, slateEditor.selection), slateEditor.onChange());
|
|
10376
10454
|
} catch (error) {
|
|
10377
10455
|
console.error(new Error(`Failed to focus editor: ${error.message}`));
|
|
10378
10456
|
}
|