@portabletext/editor 1.57.3 → 1.57.4
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/selector.get-text-before.cjs +3 -3
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +114 -114
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/{selector.get-focus-span.cjs → selector.is-selection-expanded.cjs} +25 -25
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -0
- package/lib/_chunks-es/selector.get-text-before.js +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +93 -93
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/{selector.get-focus-span.js → selector.is-selection-expanded.js} +26 -26
- package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -0
- package/lib/index.cjs +130 -135
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +95 -100
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +16 -16
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.js +1 -1
- package/lib/selectors/index.cjs +14 -14
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.js +2 -2
- package/package.json +8 -8
- package/src/editor/Editable.tsx +1 -1
- package/src/editor/editor-dom.ts +1 -1
- package/src/editor/plugins/createWithEditableAPI.ts +1 -1
- package/src/editor/range-decorations-machine.ts +2 -1
- package/src/internal-utils/__tests__/ranges.test.ts +1 -1
- package/src/internal-utils/move-range-by-operation.ts +19 -0
- package/src/internal-utils/{ranges.test.ts → to-slate-range.test.ts} +101 -1
- package/src/internal-utils/to-slate-range.ts +171 -0
- package/src/operations/behavior.operation.block.set.ts +1 -1
- package/src/operations/behavior.operation.block.unset.ts +1 -1
- package/src/operations/behavior.operation.child.set.ts +1 -1
- package/src/operations/behavior.operation.child.unset.ts +1 -1
- package/src/operations/behavior.operation.decorator.add.ts +1 -1
- package/src/operations/behavior.operation.delete.ts +1 -1
- package/src/operations/behavior.operation.move.block.ts +34 -28
- package/src/operations/behavior.operation.select.ts +1 -1
- package/src/selectors/selector.get-mark-state.ts +3 -1
- package/lib/_chunks-cjs/selector.get-focus-span.cjs.map +0 -1
- package/lib/_chunks-es/selector.get-focus-span.js.map +0 -1
- package/src/internal-utils/paths.ts +0 -110
- package/src/internal-utils/ranges.ts +0 -70
package/lib/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$f = require("debug"), slateDom = require("slate-dom"), util_sliceBlocks = require("./_chunks-cjs/util.slice-blocks.cjs"), util_isSelectionCollapsed = require("./_chunks-cjs/util.is-selection-collapsed.cjs"), isEqual = require("lodash/isEqual.js"),
|
|
3
|
+
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEffectEvent = require("use-effect-event"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$f = require("debug"), slateDom = require("slate-dom"), util_sliceBlocks = require("./_chunks-cjs/util.slice-blocks.cjs"), util_isSelectionCollapsed = require("./_chunks-cjs/util.is-selection-collapsed.cjs"), isEqual = require("lodash/isEqual.js"), selector_isSelectionExpanded = require("./_chunks-cjs/selector.is-selection-expanded.cjs"), selector_isSelectingEntireBlocks = require("./_chunks-cjs/selector.is-selecting-entire-blocks.cjs"), getRandomValues = require("get-random-values-esm"), behaviors_index = require("./behaviors/index.cjs"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), xstate = require("xstate"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), flatten = require("lodash/flatten.js"), omit = require("lodash/omit.js"), patches = require("@portabletext/patches"), util_childSelectionPointToBlockOffset = require("./_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), util_sliceTextBlock = require("./_chunks-cjs/util.slice-text-block.cjs"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), immer = require("immer"), keyboardShortcuts = require("@portabletext/keyboard-shortcuts"), types = require("@sanity/types"), startCase = require("lodash.startcase"), isPlainObject = require("lodash/isPlainObject.js");
|
|
4
4
|
function _interopDefaultCompat(e) {
|
|
5
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
6
|
}
|
|
@@ -519,86 +519,6 @@ function getSlateRangeFromEvent(editor, event) {
|
|
|
519
519
|
}
|
|
520
520
|
return range;
|
|
521
521
|
}
|
|
522
|
-
function toSlatePath(snapshot, path) {
|
|
523
|
-
const blockKey = util_sliceBlocks.getBlockKeyFromSelectionPoint({
|
|
524
|
-
path
|
|
525
|
-
});
|
|
526
|
-
if (!blockKey)
|
|
527
|
-
return {
|
|
528
|
-
block: void 0,
|
|
529
|
-
child: void 0,
|
|
530
|
-
path: []
|
|
531
|
-
};
|
|
532
|
-
const blockIndex = snapshot.blockIndexMap.get(blockKey);
|
|
533
|
-
if (blockIndex === void 0)
|
|
534
|
-
return {
|
|
535
|
-
block: void 0,
|
|
536
|
-
child: void 0,
|
|
537
|
-
path: []
|
|
538
|
-
};
|
|
539
|
-
const block = snapshot.context.value.at(blockIndex);
|
|
540
|
-
if (!block)
|
|
541
|
-
return {
|
|
542
|
-
block: void 0,
|
|
543
|
-
child: void 0,
|
|
544
|
-
path: []
|
|
545
|
-
};
|
|
546
|
-
if (!util_sliceBlocks.isTextBlock(snapshot.context, block))
|
|
547
|
-
return {
|
|
548
|
-
block,
|
|
549
|
-
child: void 0,
|
|
550
|
-
path: [blockIndex, 0]
|
|
551
|
-
};
|
|
552
|
-
const childKey = util_sliceBlocks.getChildKeyFromSelectionPoint({
|
|
553
|
-
path
|
|
554
|
-
});
|
|
555
|
-
if (!childKey)
|
|
556
|
-
return {
|
|
557
|
-
block,
|
|
558
|
-
child: void 0,
|
|
559
|
-
path: [blockIndex, 0]
|
|
560
|
-
};
|
|
561
|
-
let childPath = [], childIndex = -1, pathChild;
|
|
562
|
-
for (const child of block.children)
|
|
563
|
-
if (childIndex++, child._key === childKey) {
|
|
564
|
-
pathChild = child, util_sliceBlocks.isSpan(snapshot.context, child) ? childPath = [childIndex] : childPath = [childIndex, 0];
|
|
565
|
-
break;
|
|
566
|
-
}
|
|
567
|
-
return childPath.length === 0 ? {
|
|
568
|
-
block,
|
|
569
|
-
child: void 0,
|
|
570
|
-
path: [blockIndex, 0]
|
|
571
|
-
} : {
|
|
572
|
-
block,
|
|
573
|
-
child: pathChild,
|
|
574
|
-
path: [blockIndex].concat(childPath)
|
|
575
|
-
};
|
|
576
|
-
}
|
|
577
|
-
function toSlateRange(snapshot) {
|
|
578
|
-
if (!snapshot.context.selection)
|
|
579
|
-
return null;
|
|
580
|
-
const anchorPath = toSlatePath(snapshot, snapshot.context.selection.anchor.path), focusPath = toSlatePath(snapshot, snapshot.context.selection.focus.path);
|
|
581
|
-
if (anchorPath.path.length === 0 || focusPath.path.length === 0)
|
|
582
|
-
return null;
|
|
583
|
-
const anchorOffset = anchorPath.child && util_sliceBlocks.isSpan(snapshot.context, anchorPath.child) ? Math.min(anchorPath.child.text.length, snapshot.context.selection.anchor.offset) : 0, focusOffset = focusPath.child && util_sliceBlocks.isSpan(snapshot.context, focusPath.child) ? Math.min(focusPath.child.text.length, snapshot.context.selection.focus.offset) : 0;
|
|
584
|
-
return {
|
|
585
|
-
anchor: {
|
|
586
|
-
path: anchorPath.path,
|
|
587
|
-
offset: anchorOffset
|
|
588
|
-
},
|
|
589
|
-
focus: {
|
|
590
|
-
path: focusPath.path,
|
|
591
|
-
offset: focusOffset
|
|
592
|
-
}
|
|
593
|
-
};
|
|
594
|
-
}
|
|
595
|
-
function moveRangeByOperation(range, operation) {
|
|
596
|
-
const anchor = slate.Point.transform(range.anchor, operation), focus = slate.Point.transform(range.focus, operation);
|
|
597
|
-
return anchor === null || focus === null ? null : slate.Point.equals(anchor, range.anchor) && slate.Point.equals(focus, range.focus) ? range : {
|
|
598
|
-
anchor,
|
|
599
|
-
focus
|
|
600
|
-
};
|
|
601
|
-
}
|
|
602
522
|
function normalizePoint(point, value) {
|
|
603
523
|
if (!point || !value)
|
|
604
524
|
return null;
|
|
@@ -645,6 +565,72 @@ function normalizeSelection(selection, value) {
|
|
|
645
565
|
backward: selection.backward
|
|
646
566
|
} : null;
|
|
647
567
|
}
|
|
568
|
+
function toSlateRange(snapshot) {
|
|
569
|
+
if (!snapshot.context.selection)
|
|
570
|
+
return null;
|
|
571
|
+
if (util_isSelectionCollapsed.isEqualSelectionPoints(snapshot.context.selection.anchor, snapshot.context.selection.focus)) {
|
|
572
|
+
const anchorPoint2 = toSlateSelectionPoint(snapshot, snapshot.context.selection.anchor, snapshot.context.selection.backward ? "forward" : "backward");
|
|
573
|
+
return anchorPoint2 ? {
|
|
574
|
+
anchor: anchorPoint2,
|
|
575
|
+
focus: anchorPoint2
|
|
576
|
+
} : null;
|
|
577
|
+
}
|
|
578
|
+
const anchorPoint = toSlateSelectionPoint(snapshot, snapshot.context.selection.anchor, snapshot.context.selection.backward ? "forward" : "backward"), focusPoint = toSlateSelectionPoint(snapshot, snapshot.context.selection.focus, snapshot.context.selection.backward ? "backward" : "forward");
|
|
579
|
+
return !anchorPoint || !focusPoint ? null : {
|
|
580
|
+
anchor: anchorPoint,
|
|
581
|
+
focus: focusPoint
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
function toSlateSelectionPoint(snapshot, selectionPoint, direction) {
|
|
585
|
+
const blockKey = util_sliceBlocks.getBlockKeyFromSelectionPoint(selectionPoint);
|
|
586
|
+
if (!blockKey)
|
|
587
|
+
return;
|
|
588
|
+
const blockIndex = snapshot.blockIndexMap.get(blockKey);
|
|
589
|
+
if (blockIndex === void 0)
|
|
590
|
+
return;
|
|
591
|
+
const block = snapshot.context.value.at(blockIndex);
|
|
592
|
+
if (!block)
|
|
593
|
+
return;
|
|
594
|
+
if (!util_sliceBlocks.isTextBlock(snapshot.context, block))
|
|
595
|
+
return {
|
|
596
|
+
path: [blockIndex, 0],
|
|
597
|
+
offset: 0
|
|
598
|
+
};
|
|
599
|
+
let childKey = util_sliceBlocks.getChildKeyFromSelectionPoint({
|
|
600
|
+
path: selectionPoint.path
|
|
601
|
+
});
|
|
602
|
+
const spanSelectionPoint = childKey ? void 0 : util_sliceBlocks.blockOffsetToSpanSelectionPoint({
|
|
603
|
+
context: {
|
|
604
|
+
schema: snapshot.context.schema,
|
|
605
|
+
value: [block]
|
|
606
|
+
},
|
|
607
|
+
blockOffset: {
|
|
608
|
+
path: [{
|
|
609
|
+
_key: blockKey
|
|
610
|
+
}],
|
|
611
|
+
offset: selectionPoint.offset
|
|
612
|
+
},
|
|
613
|
+
direction
|
|
614
|
+
});
|
|
615
|
+
if (childKey = spanSelectionPoint ? util_sliceBlocks.getChildKeyFromSelectionPoint(spanSelectionPoint) : childKey, !childKey)
|
|
616
|
+
return {
|
|
617
|
+
path: [blockIndex, 0],
|
|
618
|
+
offset: 0
|
|
619
|
+
};
|
|
620
|
+
let offset = spanSelectionPoint?.offset ?? selectionPoint.offset, childPath = [], childIndex = -1, pathChild;
|
|
621
|
+
for (const child of block.children)
|
|
622
|
+
if (childIndex++, child._key === childKey) {
|
|
623
|
+
pathChild = child, util_sliceBlocks.isSpan(snapshot.context, child) ? childPath = [childIndex] : (childPath = [childIndex, 0], offset = 0);
|
|
624
|
+
break;
|
|
625
|
+
}
|
|
626
|
+
return childPath.length === 0 ? {
|
|
627
|
+
path: [blockIndex, 0],
|
|
628
|
+
offset: 0
|
|
629
|
+
} : {
|
|
630
|
+
path: [blockIndex].concat(childPath),
|
|
631
|
+
offset: util_sliceBlocks.isSpan(snapshot.context, pathChild) ? Math.min(pathChild.text.length, offset) : offset
|
|
632
|
+
};
|
|
633
|
+
}
|
|
648
634
|
const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE_ELEMENT = /* @__PURE__ */ new WeakMap(), KEY_TO_VALUE_ELEMENT = /* @__PURE__ */ new WeakMap(), SLATE_TO_PORTABLE_TEXT_RANGE = /* @__PURE__ */ new WeakMap(), EditorActorContext = React.createContext({});
|
|
649
635
|
function DropIndicator() {
|
|
650
636
|
const $ = reactCompilerRuntime.c(1);
|
|
@@ -700,18 +686,18 @@ function getDragSelection({
|
|
|
700
686
|
}
|
|
701
687
|
}))
|
|
702
688
|
return dragSelection;
|
|
703
|
-
const draggingCollapsedSelection =
|
|
689
|
+
const draggingCollapsedSelection = selector_isSelectionExpanded.isSelectionCollapsed({
|
|
704
690
|
context: {
|
|
705
691
|
...snapshot.context,
|
|
706
692
|
selection: eventSelection
|
|
707
693
|
}
|
|
708
|
-
}), draggedTextBlock =
|
|
694
|
+
}), draggedTextBlock = selector_isSelectionExpanded.getFocusTextBlock({
|
|
709
695
|
...snapshot,
|
|
710
696
|
context: {
|
|
711
697
|
...snapshot.context,
|
|
712
698
|
selection: eventSelection
|
|
713
699
|
}
|
|
714
|
-
}), draggedSpan =
|
|
700
|
+
}), draggedSpan = selector_isSelectionExpanded.getFocusSpan({
|
|
715
701
|
...snapshot,
|
|
716
702
|
context: {
|
|
717
703
|
...snapshot.context,
|
|
@@ -729,7 +715,7 @@ function getDragSelection({
|
|
|
729
715
|
})
|
|
730
716
|
});
|
|
731
717
|
const selectedBlocks = selector_isSelectingEntireBlocks.getSelectedBlocks(snapshot);
|
|
732
|
-
if (snapshot.context.selection &&
|
|
718
|
+
if (snapshot.context.selection && selector_isSelectionExpanded.isSelectionExpanded(snapshot) && selectedBlocks.length > 1) {
|
|
733
719
|
const selectionStartBlock = selector_isSelectingEntireBlocks.getSelectionStartBlock(snapshot), selectionEndBlock = selector_isSelectingEntireBlocks.getSelectionEndBlock(snapshot);
|
|
734
720
|
if (!selectionStartBlock || !selectionEndBlock)
|
|
735
721
|
return dragSelection;
|
|
@@ -796,7 +782,7 @@ function createCoreBlockElementBehaviorsConfig({
|
|
|
796
782
|
snapshot,
|
|
797
783
|
event
|
|
798
784
|
}) => {
|
|
799
|
-
const dropFocusBlock =
|
|
785
|
+
const dropFocusBlock = selector_isSelectionExpanded.getFocusBlock({
|
|
800
786
|
...snapshot,
|
|
801
787
|
context: {
|
|
802
788
|
...snapshot.context,
|
|
@@ -1123,7 +1109,7 @@ const converterJson = {
|
|
|
1123
1109
|
originEvent: event.originEvent,
|
|
1124
1110
|
reason: "No selection"
|
|
1125
1111
|
};
|
|
1126
|
-
const blocks =
|
|
1112
|
+
const blocks = selector_isSelectionExpanded.getSelectedValue(snapshot);
|
|
1127
1113
|
return blocks.length === 0 ? {
|
|
1128
1114
|
type: "serialization.failure",
|
|
1129
1115
|
mimeType: "application/x-portable-text",
|
|
@@ -1183,7 +1169,7 @@ function createConverterTextHtml(legacySchema) {
|
|
|
1183
1169
|
originEvent: event.originEvent,
|
|
1184
1170
|
reason: "No selection"
|
|
1185
1171
|
};
|
|
1186
|
-
const blocks =
|
|
1172
|
+
const blocks = selector_isSelectionExpanded.getSelectedValue(snapshot), html = toHtml.toHTML(blocks, {
|
|
1187
1173
|
onMissingComponent: !1,
|
|
1188
1174
|
components: {
|
|
1189
1175
|
unknownType: ({
|
|
@@ -1241,7 +1227,7 @@ function createConverterTextPlain(legacySchema) {
|
|
|
1241
1227
|
event
|
|
1242
1228
|
}) => snapshot.context.selection ? {
|
|
1243
1229
|
type: "serialization.success",
|
|
1244
|
-
data:
|
|
1230
|
+
data: selector_isSelectionExpanded.getSelectedValue(snapshot).map((block) => util_sliceBlocks.isTextBlock(snapshot.context, block) ? block.children.map((child) => child._type === snapshot.context.schema.span.name ? child.text : event.originEvent === "drag.dragstart" ? `[${snapshot.context.schema.inlineObjects.find((inlineObjectType) => inlineObjectType.name === child._type)?.title ?? "Object"}]` : "").join("") : event.originEvent === "drag.dragstart" ? `[${snapshot.context.schema.blockObjects.find((blockObjectType) => blockObjectType.name === block._type)?.title ?? "Object"}]` : "").filter((block) => block !== "").join(`
|
|
1245
1231
|
|
|
1246
1232
|
`),
|
|
1247
1233
|
mimeType: "text/plain",
|
|
@@ -3603,25 +3589,27 @@ const moveBackwardOperationImplementation = ({
|
|
|
3603
3589
|
reverse: !0
|
|
3604
3590
|
});
|
|
3605
3591
|
}, moveBlockOperationImplementation = ({
|
|
3606
|
-
context,
|
|
3607
3592
|
operation
|
|
3608
3593
|
}) => {
|
|
3609
|
-
const
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3594
|
+
const originKey = util_sliceBlocks.getBlockKeyFromSelectionPoint({
|
|
3595
|
+
path: operation.at
|
|
3596
|
+
});
|
|
3597
|
+
if (!originKey)
|
|
3598
|
+
throw new Error("Failed to get block key from selection point");
|
|
3599
|
+
const originBlockIndex = operation.editor.blockIndexMap.get(originKey);
|
|
3600
|
+
if (originBlockIndex === void 0)
|
|
3601
|
+
throw new Error("Failed to get block index from block key");
|
|
3602
|
+
const destinationKey = util_sliceBlocks.getBlockKeyFromSelectionPoint({
|
|
3603
|
+
path: operation.to
|
|
3604
|
+
});
|
|
3605
|
+
if (!destinationKey)
|
|
3606
|
+
throw new Error("Failed to get block key from selection point");
|
|
3607
|
+
const destinationBlockIndex = operation.editor.blockIndexMap.get(destinationKey);
|
|
3608
|
+
if (destinationBlockIndex === void 0)
|
|
3609
|
+
throw new Error("Failed to get block index from block key");
|
|
3622
3610
|
slate.Transforms.moveNodes(operation.editor, {
|
|
3623
|
-
at,
|
|
3624
|
-
to,
|
|
3611
|
+
at: [originBlockIndex],
|
|
3612
|
+
to: [destinationBlockIndex],
|
|
3625
3613
|
mode: "highest"
|
|
3626
3614
|
});
|
|
3627
3615
|
}, moveForwardOperationImplementation = ({
|
|
@@ -5322,10 +5310,10 @@ const addAnnotationOnCollapsedSelection = behaviors_index.defineBehavior({
|
|
|
5322
5310
|
guard: ({
|
|
5323
5311
|
snapshot
|
|
5324
5312
|
}) => {
|
|
5325
|
-
if (!
|
|
5313
|
+
if (!selector_isSelectionExpanded.isSelectionCollapsed(snapshot))
|
|
5326
5314
|
return !1;
|
|
5327
5315
|
const caretWordSelection = selector_isSelectingEntireBlocks.getCaretWordSelection(snapshot);
|
|
5328
|
-
return !caretWordSelection || !
|
|
5316
|
+
return !caretWordSelection || !selector_isSelectionExpanded.isSelectionExpanded({
|
|
5329
5317
|
context: {
|
|
5330
5318
|
...snapshot.context,
|
|
5331
5319
|
selection: caretWordSelection
|
|
@@ -5412,7 +5400,7 @@ const addAnnotationOnCollapsedSelection = behaviors_index.defineBehavior({
|
|
|
5412
5400
|
snapshot,
|
|
5413
5401
|
event
|
|
5414
5402
|
}) => {
|
|
5415
|
-
if (!defaultKeyboardShortcuts.arrowDown.guard(event.originEvent) || !
|
|
5403
|
+
if (!defaultKeyboardShortcuts.arrowDown.guard(event.originEvent) || !selector_isSelectionExpanded.isSelectionCollapsed(snapshot))
|
|
5416
5404
|
return !1;
|
|
5417
5405
|
const focusBlockObject = selector_isSelectingEntireBlocks.getFocusBlockObject(snapshot), nextBlock = selector_isSelectingEntireBlocks.getNextBlock(snapshot);
|
|
5418
5406
|
return focusBlockObject && !nextBlock;
|
|
@@ -5432,7 +5420,7 @@ const addAnnotationOnCollapsedSelection = behaviors_index.defineBehavior({
|
|
|
5432
5420
|
snapshot,
|
|
5433
5421
|
event
|
|
5434
5422
|
}) => {
|
|
5435
|
-
if (!defaultKeyboardShortcuts.arrowUp.guard(event.originEvent) || !
|
|
5423
|
+
if (!defaultKeyboardShortcuts.arrowUp.guard(event.originEvent) || !selector_isSelectionExpanded.isSelectionCollapsed(snapshot))
|
|
5436
5424
|
return !1;
|
|
5437
5425
|
const focusBlockObject = selector_isSelectingEntireBlocks.getFocusBlockObject(snapshot), previousBlock = selector_isSelectingEntireBlocks.getPreviousBlock(snapshot);
|
|
5438
5426
|
return focusBlockObject && !previousBlock;
|
|
@@ -5452,7 +5440,7 @@ const addAnnotationOnCollapsedSelection = behaviors_index.defineBehavior({
|
|
|
5452
5440
|
snapshot
|
|
5453
5441
|
}) => {
|
|
5454
5442
|
const focusBlockObject = selector_isSelectingEntireBlocks.getFocusBlockObject(snapshot);
|
|
5455
|
-
return
|
|
5443
|
+
return selector_isSelectionExpanded.isSelectionCollapsed(snapshot) && focusBlockObject !== void 0;
|
|
5456
5444
|
},
|
|
5457
5445
|
actions: [({
|
|
5458
5446
|
snapshot
|
|
@@ -5469,7 +5457,7 @@ const addAnnotationOnCollapsedSelection = behaviors_index.defineBehavior({
|
|
|
5469
5457
|
snapshot,
|
|
5470
5458
|
event
|
|
5471
5459
|
}) => {
|
|
5472
|
-
if (snapshot.context.readOnly || snapshot.context.selection && !
|
|
5460
|
+
if (snapshot.context.readOnly || snapshot.context.selection && !selector_isSelectionExpanded.isSelectionCollapsed(snapshot))
|
|
5473
5461
|
return !1;
|
|
5474
5462
|
const focusBlockObject = selector_isSelectingEntireBlocks.getFocusBlockObject({
|
|
5475
5463
|
...snapshot,
|
|
@@ -5506,7 +5494,7 @@ const addAnnotationOnCollapsedSelection = behaviors_index.defineBehavior({
|
|
|
5506
5494
|
snapshot,
|
|
5507
5495
|
event
|
|
5508
5496
|
}) => {
|
|
5509
|
-
if (snapshot.context.readOnly || snapshot.context.selection && !
|
|
5497
|
+
if (snapshot.context.readOnly || snapshot.context.selection && !selector_isSelectionExpanded.isSelectionCollapsed(snapshot))
|
|
5510
5498
|
return !1;
|
|
5511
5499
|
const focusBlockObject = selector_isSelectingEntireBlocks.getFocusBlockObject({
|
|
5512
5500
|
...snapshot,
|
|
@@ -5542,7 +5530,7 @@ const addAnnotationOnCollapsedSelection = behaviors_index.defineBehavior({
|
|
|
5542
5530
|
guard: ({
|
|
5543
5531
|
snapshot
|
|
5544
5532
|
}) => {
|
|
5545
|
-
const focusTextBlock =
|
|
5533
|
+
const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot), selectionCollapsed = selector_isSelectionExpanded.isSelectionCollapsed(snapshot), previousBlock = selector_isSelectingEntireBlocks.getPreviousBlock(snapshot);
|
|
5546
5534
|
return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : util_isSelectionCollapsed.isEmptyTextBlock(snapshot.context, focusTextBlock.node) && !util_sliceBlocks.isTextBlock(snapshot.context, previousBlock.node) ? {
|
|
5547
5535
|
focusTextBlock,
|
|
5548
5536
|
previousBlock
|
|
@@ -5572,7 +5560,7 @@ const addAnnotationOnCollapsedSelection = behaviors_index.defineBehavior({
|
|
|
5572
5560
|
guard: ({
|
|
5573
5561
|
snapshot
|
|
5574
5562
|
}) => {
|
|
5575
|
-
const focusTextBlock =
|
|
5563
|
+
const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot), selectionCollapsed = selector_isSelectionExpanded.isSelectionCollapsed(snapshot), nextBlock = selector_isSelectingEntireBlocks.getNextBlock(snapshot);
|
|
5576
5564
|
return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : util_isSelectionCollapsed.isEmptyTextBlock(snapshot.context, focusTextBlock.node) && !util_sliceBlocks.isTextBlock(snapshot.context, nextBlock.node) ? {
|
|
5577
5565
|
focusTextBlock,
|
|
5578
5566
|
nextBlock
|
|
@@ -5919,7 +5907,7 @@ const coreDndBehaviors = [
|
|
|
5919
5907
|
guard: ({
|
|
5920
5908
|
snapshot
|
|
5921
5909
|
}) => {
|
|
5922
|
-
const focusTextBlock =
|
|
5910
|
+
const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot), selectionCollapsed = selector_isSelectionExpanded.isSelectionCollapsed(snapshot);
|
|
5923
5911
|
if (!snapshot.context.selection || !focusTextBlock || !selectionCollapsed)
|
|
5924
5912
|
return !1;
|
|
5925
5913
|
const atTheEndOfBlock = selector_isSelectingEntireBlocks.isAtTheEndOfBlock(focusTextBlock)(snapshot), focusListItem = focusTextBlock.node.listItem, focusLevel = focusTextBlock.node.level;
|
|
@@ -5954,10 +5942,10 @@ const coreDndBehaviors = [
|
|
|
5954
5942
|
guard: ({
|
|
5955
5943
|
snapshot
|
|
5956
5944
|
}) => {
|
|
5957
|
-
const focusTextBlock =
|
|
5945
|
+
const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot), selectionCollapsed = selector_isSelectionExpanded.isSelectionCollapsed(snapshot);
|
|
5958
5946
|
if (!snapshot.context.selection || !focusTextBlock || !selectionCollapsed)
|
|
5959
5947
|
return !1;
|
|
5960
|
-
const focusSpan =
|
|
5948
|
+
const focusSpan = selector_isSelectionExpanded.getFocusSpan(snapshot), focusDecorators = focusSpan?.node.marks?.filter((mark) => snapshot.context.schema.decorators.some((decorator) => decorator.name === mark) ?? []), focusAnnotations = focusSpan?.node.marks?.filter((mark) => !snapshot.context.schema.decorators.some((decorator) => decorator.name === mark)) ?? [], focusListItem = focusTextBlock.node.listItem, focusLevel = focusTextBlock.node.level;
|
|
5961
5949
|
return selector_isSelectingEntireBlocks.isAtTheStartOfBlock(focusTextBlock)(snapshot) ? {
|
|
5962
5950
|
focusAnnotations,
|
|
5963
5951
|
focusDecorators,
|
|
@@ -5993,7 +5981,7 @@ const coreDndBehaviors = [
|
|
|
5993
5981
|
guard: ({
|
|
5994
5982
|
snapshot
|
|
5995
5983
|
}) => {
|
|
5996
|
-
if (!snapshot.context.selection || !
|
|
5984
|
+
if (!snapshot.context.selection || !selector_isSelectionExpanded.isSelectionExpanded(snapshot))
|
|
5997
5985
|
return !1;
|
|
5998
5986
|
const firstBlock = selector_isSelectingEntireBlocks.getFirstBlock(snapshot), lastBlock = selector_isSelectingEntireBlocks.getLastBlock(snapshot);
|
|
5999
5987
|
if (!firstBlock || !lastBlock)
|
|
@@ -6020,7 +6008,7 @@ const coreDndBehaviors = [
|
|
|
6020
6008
|
guard: ({
|
|
6021
6009
|
snapshot
|
|
6022
6010
|
}) => {
|
|
6023
|
-
if (!snapshot.context.selection || !
|
|
6011
|
+
if (!snapshot.context.selection || !selector_isSelectionExpanded.isSelectionExpanded(snapshot))
|
|
6024
6012
|
return !1;
|
|
6025
6013
|
const selectedBlocks = selector_isSelectingEntireBlocks.getSelectedBlocks(snapshot), selectionStartBlock = selector_isSelectingEntireBlocks.getSelectionStartBlock(snapshot), selectionEndBlock = selector_isSelectingEntireBlocks.getSelectionEndBlock(snapshot);
|
|
6026
6014
|
if (!selectionStartBlock || !selectionEndBlock)
|
|
@@ -6061,7 +6049,7 @@ const coreDndBehaviors = [
|
|
|
6061
6049
|
guard: ({
|
|
6062
6050
|
snapshot
|
|
6063
6051
|
}) => {
|
|
6064
|
-
const selectionCollapsed =
|
|
6052
|
+
const selectionCollapsed = selector_isSelectionExpanded.isSelectionCollapsed(snapshot), focusInlineObject = selector_isSelectingEntireBlocks.getFocusInlineObject(snapshot);
|
|
6065
6053
|
return selectionCollapsed && focusInlineObject;
|
|
6066
6054
|
},
|
|
6067
6055
|
actions: [() => [behaviors_index.raise({
|
|
@@ -6081,7 +6069,7 @@ const coreDndBehaviors = [
|
|
|
6081
6069
|
guard: ({
|
|
6082
6070
|
snapshot
|
|
6083
6071
|
}) => {
|
|
6084
|
-
const selectionCollapsed =
|
|
6072
|
+
const selectionCollapsed = selector_isSelectionExpanded.isSelectionCollapsed(snapshot), focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot), focusSpan = selector_isSelectionExpanded.getFocusSpan(snapshot);
|
|
6085
6073
|
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && snapshot.context.selection?.focus.offset === 0 && focusTextBlock.node.level === 1 ? {
|
|
6086
6074
|
focusTextBlock
|
|
6087
6075
|
} : !1;
|
|
@@ -6098,7 +6086,7 @@ const coreDndBehaviors = [
|
|
|
6098
6086
|
guard: ({
|
|
6099
6087
|
snapshot
|
|
6100
6088
|
}) => {
|
|
6101
|
-
const selectionCollapsed =
|
|
6089
|
+
const selectionCollapsed = selector_isSelectionExpanded.isSelectionCollapsed(snapshot), focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot), focusSpan = selector_isSelectionExpanded.getFocusSpan(snapshot);
|
|
6102
6090
|
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && snapshot.context.selection?.focus.offset === 0 && focusTextBlock.node.level !== void 0 && focusTextBlock.node.level > 1 ? {
|
|
6103
6091
|
focusTextBlock,
|
|
6104
6092
|
level: focusTextBlock.node.level - 1
|
|
@@ -6141,7 +6129,7 @@ const coreDndBehaviors = [
|
|
|
6141
6129
|
guard: ({
|
|
6142
6130
|
snapshot
|
|
6143
6131
|
}) => {
|
|
6144
|
-
const focusTextBlock =
|
|
6132
|
+
const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot), previousBlock = selector_isSelectingEntireBlocks.getPreviousBlock(snapshot);
|
|
6145
6133
|
if (!focusTextBlock || !previousBlock || !util_sliceBlocks.isListBlock(snapshot.context, previousBlock.node) || !util_isSelectionCollapsed.isEmptyTextBlock(snapshot.context, previousBlock.node))
|
|
6146
6134
|
return !1;
|
|
6147
6135
|
const previousBlockEndPoint = util_isSelectionCollapsed.getBlockEndPoint({
|
|
@@ -6176,7 +6164,7 @@ const coreDndBehaviors = [
|
|
|
6176
6164
|
guard: ({
|
|
6177
6165
|
snapshot
|
|
6178
6166
|
}) => {
|
|
6179
|
-
const selectionCollapsed =
|
|
6167
|
+
const selectionCollapsed = selector_isSelectionExpanded.isSelectionCollapsed(snapshot), focusListBlock = selector_isSelectingEntireBlocks.getFocusListBlock(snapshot);
|
|
6180
6168
|
return !selectionCollapsed || !focusListBlock || !util_isSelectionCollapsed.isEmptyTextBlock(snapshot.context, focusListBlock.node) ? !1 : {
|
|
6181
6169
|
focusListBlock
|
|
6182
6170
|
};
|
|
@@ -6350,7 +6338,7 @@ const coreDndBehaviors = [
|
|
|
6350
6338
|
snapshot,
|
|
6351
6339
|
event
|
|
6352
6340
|
}) => {
|
|
6353
|
-
const blockKey = event.at[0]._key, markDefKey = event.at[2]._key, block =
|
|
6341
|
+
const blockKey = event.at[0]._key, markDefKey = event.at[2]._key, block = selector_isSelectionExpanded.getFocusTextBlock({
|
|
6354
6342
|
...snapshot,
|
|
6355
6343
|
context: {
|
|
6356
6344
|
...snapshot.context,
|
|
@@ -6510,7 +6498,7 @@ const coreDndBehaviors = [
|
|
|
6510
6498
|
snapshot,
|
|
6511
6499
|
event
|
|
6512
6500
|
}) => {
|
|
6513
|
-
const focusChild =
|
|
6501
|
+
const focusChild = selector_isSelectionExpanded.getFocusChild({
|
|
6514
6502
|
...snapshot,
|
|
6515
6503
|
context: {
|
|
6516
6504
|
...snapshot.context,
|
|
@@ -6620,7 +6608,7 @@ const coreDndBehaviors = [
|
|
|
6620
6608
|
}) => {
|
|
6621
6609
|
if (event.placement !== "auto")
|
|
6622
6610
|
return !1;
|
|
6623
|
-
const focusTextBlock =
|
|
6611
|
+
const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot);
|
|
6624
6612
|
return focusTextBlock ? {
|
|
6625
6613
|
focusTextBlock
|
|
6626
6614
|
} : !1;
|
|
@@ -6699,7 +6687,7 @@ const coreDndBehaviors = [
|
|
|
6699
6687
|
guard: ({
|
|
6700
6688
|
snapshot,
|
|
6701
6689
|
event
|
|
6702
|
-
}) => defaultKeyboardShortcuts.break.guard(event.originEvent) &&
|
|
6690
|
+
}) => defaultKeyboardShortcuts.break.guard(event.originEvent) && selector_isSelectionExpanded.isSelectionCollapsed(snapshot) && selector_isSelectingEntireBlocks.getFocusInlineObject(snapshot),
|
|
6703
6691
|
actions: [() => [behaviors_index.raise({
|
|
6704
6692
|
type: "insert.break"
|
|
6705
6693
|
})]]
|
|
@@ -6935,7 +6923,7 @@ const coreDndBehaviors = [
|
|
|
6935
6923
|
on: "split",
|
|
6936
6924
|
guard: ({
|
|
6937
6925
|
snapshot
|
|
6938
|
-
}) =>
|
|
6926
|
+
}) => selector_isSelectionExpanded.isSelectionCollapsed(snapshot) && selector_isSelectingEntireBlocks.getFocusInlineObject(snapshot),
|
|
6939
6927
|
actions: []
|
|
6940
6928
|
}),
|
|
6941
6929
|
/**
|
|
@@ -6945,7 +6933,7 @@ const coreDndBehaviors = [
|
|
|
6945
6933
|
on: "split",
|
|
6946
6934
|
guard: ({
|
|
6947
6935
|
snapshot
|
|
6948
|
-
}) =>
|
|
6936
|
+
}) => selector_isSelectionExpanded.isSelectionCollapsed(snapshot) && selector_isSelectingEntireBlocks.getFocusBlockObject(snapshot),
|
|
6949
6937
|
actions: []
|
|
6950
6938
|
}),
|
|
6951
6939
|
behaviors_index.defineBehavior({
|
|
@@ -6995,7 +6983,7 @@ const coreDndBehaviors = [
|
|
|
6995
6983
|
const selection = snapshot.context.selection;
|
|
6996
6984
|
if (!selection || !util_isSelectionCollapsed.isSelectionCollapsed(selection))
|
|
6997
6985
|
return !1;
|
|
6998
|
-
const selectionStartPoint = util_sliceBlocks.getSelectionStartPoint(selection), focusTextBlock =
|
|
6986
|
+
const selectionStartPoint = util_sliceBlocks.getSelectionStartPoint(selection), focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot);
|
|
6999
6987
|
if (!focusTextBlock)
|
|
7000
6988
|
return !1;
|
|
7001
6989
|
const blockEndPoint = util_isSelectionCollapsed.getBlockEndPoint({
|
|
@@ -7163,7 +7151,7 @@ const coreDndBehaviors = [
|
|
|
7163
7151
|
guard: ({
|
|
7164
7152
|
snapshot
|
|
7165
7153
|
}) => {
|
|
7166
|
-
const focusSpan =
|
|
7154
|
+
const focusSpan = selector_isSelectionExpanded.getFocusSpan(snapshot), selectionCollapsed = selector_isSelectionExpanded.isSelectionCollapsed(snapshot);
|
|
7167
7155
|
return focusSpan && selectionCollapsed;
|
|
7168
7156
|
},
|
|
7169
7157
|
actions: []
|
|
@@ -7182,7 +7170,7 @@ const coreDndBehaviors = [
|
|
|
7182
7170
|
guard: ({
|
|
7183
7171
|
snapshot
|
|
7184
7172
|
}) => {
|
|
7185
|
-
const focusSpan =
|
|
7173
|
+
const focusSpan = selector_isSelectionExpanded.getFocusSpan(snapshot), selectionCollapsed = selector_isSelectionExpanded.isSelectionCollapsed(snapshot);
|
|
7186
7174
|
return focusSpan && selectionCollapsed;
|
|
7187
7175
|
},
|
|
7188
7176
|
actions: []
|
|
@@ -7248,7 +7236,7 @@ const coreDndBehaviors = [
|
|
|
7248
7236
|
snapshot,
|
|
7249
7237
|
event
|
|
7250
7238
|
}) => {
|
|
7251
|
-
if (
|
|
7239
|
+
if (selector_isSelectionExpanded.getFocusTextBlock(snapshot) && event.mimeType === "text/plain" && event.originEvent.type === "clipboard.paste") {
|
|
7252
7240
|
const activeDecorators = selector_isSelectingEntireBlocks.getActiveDecorators(snapshot);
|
|
7253
7241
|
return {
|
|
7254
7242
|
activeAnnotations: selector_isSelectingEntireBlocks.getActiveAnnotations(snapshot),
|
|
@@ -7315,7 +7303,7 @@ const coreDndBehaviors = [
|
|
|
7315
7303
|
on: "clipboard.paste",
|
|
7316
7304
|
guard: ({
|
|
7317
7305
|
snapshot
|
|
7318
|
-
}) => snapshot.context.selection &&
|
|
7306
|
+
}) => snapshot.context.selection && selector_isSelectionExpanded.isSelectionExpanded(snapshot) ? {
|
|
7319
7307
|
selection: snapshot.context.selection
|
|
7320
7308
|
} : !1,
|
|
7321
7309
|
actions: [({
|
|
@@ -10867,6 +10855,13 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
|
|
|
10867
10855
|
}, editor;
|
|
10868
10856
|
};
|
|
10869
10857
|
}
|
|
10858
|
+
function moveRangeByOperation(range, operation) {
|
|
10859
|
+
const anchor = slate.Point.transform(range.anchor, operation), focus = slate.Point.transform(range.focus, operation);
|
|
10860
|
+
return anchor === null || focus === null ? null : slate.Point.equals(anchor, range.anchor) && slate.Point.equals(focus, range.focus) ? range : {
|
|
10861
|
+
anchor,
|
|
10862
|
+
focus
|
|
10863
|
+
};
|
|
10864
|
+
}
|
|
10870
10865
|
const slateOperationCallback = ({
|
|
10871
10866
|
input,
|
|
10872
10867
|
sendBack
|