@portabletext/editor 1.55.13 → 1.55.15
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.is-selection-expanded.cjs → selector.get-focus-span.cjs} +27 -27
- package/lib/_chunks-cjs/selector.get-focus-span.cjs.map +1 -0
- 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 +291 -168
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs +1 -1
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-cjs/{util.is-equal-selection-points.cjs → util.is-selection-collapsed.cjs} +7 -3
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +1 -0
- package/lib/_chunks-cjs/util.slice-blocks.cjs +2 -2
- package/lib/_chunks-cjs/util.slice-text-block.cjs +2 -6
- package/lib/_chunks-cjs/util.slice-text-block.cjs.map +1 -1
- package/lib/_chunks-es/{selector.is-selection-expanded.js → selector.get-focus-span.js} +27 -27
- package/lib/_chunks-es/selector.get-focus-span.js.map +1 -0
- package/lib/_chunks-es/selector.get-text-before.js +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +266 -143
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/util.child-selection-point-to-block-offset.js +1 -1
- package/lib/_chunks-es/{util.is-equal-selection-points.js → util.is-selection-collapsed.js} +7 -3
- package/lib/_chunks-es/util.is-selection-collapsed.js.map +1 -0
- package/lib/_chunks-es/util.slice-blocks.js +2 -2
- package/lib/_chunks-es/util.slice-text-block.js +1 -5
- package/lib/_chunks-es/util.slice-text-block.js.map +1 -1
- package/lib/behaviors/index.d.cts +3 -6
- package/lib/behaviors/index.d.ts +3 -6
- package/lib/index.cjs +357 -322
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +11 -20
- package/lib/index.d.ts +11 -20
- package/lib/index.js +296 -261
- 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.d.cts +3 -6
- package/lib/plugins/index.d.ts +3 -6
- 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.d.cts +3 -6
- package/lib/selectors/index.d.ts +3 -6
- package/lib/selectors/index.js +2 -2
- package/lib/utils/index.cjs +9 -9
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +3 -6
- package/lib/utils/index.d.ts +3 -6
- package/lib/utils/index.js +5 -5
- package/package.json +3 -3
- package/src/behaviors/behavior.abstract.ts +2 -1
- package/src/behaviors/behavior.core.dnd.ts +4 -4
- package/src/editor/Editable.tsx +8 -1
- package/src/editor/create-slate-editor.tsx +0 -1
- package/src/editor/editor-dom.ts +3 -3
- package/src/editor/editor-selector.ts +1 -13
- package/src/editor/editor-snapshot.ts +4 -19
- package/src/editor/plugins/createWithEditableAPI.ts +52 -13
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +13 -4
- package/src/editor/plugins/with-plugins.ts +4 -8
- package/src/editor/range-decorations-machine.ts +24 -12
- package/src/internal-utils/create-test-snapshot.ts +2 -5
- package/src/internal-utils/paths.ts +65 -17
- package/src/internal-utils/ranges.test.ts +179 -0
- package/src/internal-utils/ranges.ts +39 -22
- package/src/internal-utils/test-editor.tsx +16 -1
- package/src/operations/behavior.operation.block.set.ts +10 -6
- package/src/operations/behavior.operation.block.unset.ts +10 -6
- package/src/operations/behavior.operation.child.set.ts +10 -6
- package/src/operations/behavior.operation.child.unset.ts +10 -6
- package/src/operations/behavior.operation.decorator.add.ts +17 -6
- package/src/operations/behavior.operation.delete.ts +8 -1
- package/src/operations/behavior.operation.insert.text.ts +34 -20
- package/src/operations/behavior.operation.move.block.ts +25 -3
- package/src/operations/behavior.operation.select.ts +9 -2
- package/src/selectors/selector.get-active-annotation-marks.ts +12 -0
- package/src/selectors/selector.get-active-annotations.ts +8 -20
- package/src/{editor/get-active-decorators.ts → selectors/selector.get-active-decorators.ts} +6 -11
- package/src/{internal-utils/mark-state.ts → selectors/selector.get-mark-state.ts} +41 -67
- package/src/selectors/selector.get-next-span.ts +56 -0
- package/src/selectors/selector.get-previous-span.ts +53 -0
- package/src/selectors/selector.is-active-annotation.ts +3 -1
- package/src/selectors/selector.is-active-decorator.ts +4 -1
- package/src/types/editor.ts +0 -2
- package/src/utils/util.is-selection-expanded.ts +13 -0
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +0 -1
- package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +0 -1
- package/lib/_chunks-es/selector.is-selection-expanded.js.map +0 -1
- package/lib/_chunks-es/util.is-equal-selection-points.js.map +0 -1
- package/src/editor/get-active-annotations.ts +0 -15
- package/src/editor/plugins/slate-plugin.update-mark-state.ts +0 -21
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"),
|
|
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_isSelectingEntireBlocks = require("./_chunks-cjs/selector.is-selecting-entire-blocks.cjs"), selector_getFocusSpan = require("./_chunks-cjs/selector.get-focus-span.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"), 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
|
}
|
|
@@ -402,7 +402,7 @@ function getEventPosition({
|
|
|
402
402
|
}]
|
|
403
403
|
}
|
|
404
404
|
}),
|
|
405
|
-
focus:
|
|
405
|
+
focus: util_isSelectionCollapsed.getBlockEndPoint({
|
|
406
406
|
context: editorActor.getSnapshot().context,
|
|
407
407
|
block: {
|
|
408
408
|
node: eventBlock,
|
|
@@ -417,7 +417,7 @@ function getEventPosition({
|
|
|
417
417
|
return;
|
|
418
418
|
const eventSelectionFocusBlockKey = util_sliceBlocks.getBlockKeyFromSelectionPoint(eventSelection.focus);
|
|
419
419
|
if (eventSelectionFocusBlockKey !== void 0)
|
|
420
|
-
return
|
|
420
|
+
return util_isSelectionCollapsed.isSelectionCollapsed(eventSelection) && eventBlock && eventSelectionFocusBlockKey !== eventBlock._key ? {
|
|
421
421
|
block: eventPositionBlock,
|
|
422
422
|
isEditor: !1,
|
|
423
423
|
selection: {
|
|
@@ -430,7 +430,7 @@ function getEventPosition({
|
|
|
430
430
|
}]
|
|
431
431
|
}
|
|
432
432
|
}),
|
|
433
|
-
focus:
|
|
433
|
+
focus: util_isSelectionCollapsed.getBlockEndPoint({
|
|
434
434
|
context: editorActor.getSnapshot().context,
|
|
435
435
|
block: {
|
|
436
436
|
node: eventBlock,
|
|
@@ -519,47 +519,78 @@ function getSlateRangeFromEvent(editor, event) {
|
|
|
519
519
|
}
|
|
520
520
|
return range;
|
|
521
521
|
}
|
|
522
|
-
function toSlatePath(
|
|
522
|
+
function toSlatePath(snapshot, path) {
|
|
523
523
|
const blockKey = util_sliceBlocks.getBlockKeyFromSelectionPoint({
|
|
524
524
|
path
|
|
525
525
|
});
|
|
526
526
|
if (!blockKey)
|
|
527
|
-
return
|
|
528
|
-
|
|
527
|
+
return {
|
|
528
|
+
block: void 0,
|
|
529
|
+
child: void 0,
|
|
530
|
+
path: []
|
|
531
|
+
};
|
|
532
|
+
const blockIndex = snapshot.blockIndexMap.get(blockKey);
|
|
529
533
|
if (blockIndex === void 0)
|
|
530
|
-
return
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
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
|
+
};
|
|
536
552
|
const childKey = util_sliceBlocks.getChildKeyFromSelectionPoint({
|
|
537
553
|
path
|
|
538
554
|
});
|
|
539
555
|
if (!childKey)
|
|
540
|
-
return
|
|
541
|
-
|
|
556
|
+
return {
|
|
557
|
+
block,
|
|
558
|
+
child: void 0,
|
|
559
|
+
path: [blockIndex, 0]
|
|
560
|
+
};
|
|
561
|
+
let childPath = [], childIndex = -1, pathChild;
|
|
542
562
|
for (const child of block.children)
|
|
543
563
|
if (childIndex++, child._key === childKey) {
|
|
544
|
-
|
|
564
|
+
pathChild = child, util_sliceBlocks.isSpan(snapshot.context, child) ? childPath = [childIndex] : childPath = [childIndex, 0];
|
|
545
565
|
break;
|
|
546
566
|
}
|
|
547
|
-
return
|
|
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
|
+
};
|
|
548
576
|
}
|
|
549
|
-
function toSlateRange(
|
|
550
|
-
if (!selection
|
|
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)
|
|
551
582
|
return null;
|
|
552
|
-
const anchor =
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
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
|
+
}
|
|
558
593
|
};
|
|
559
|
-
return focus.path.length === 0 || anchor.path.length === 0 ? null : anchor && focus ? {
|
|
560
|
-
anchor,
|
|
561
|
-
focus
|
|
562
|
-
} : null;
|
|
563
594
|
}
|
|
564
595
|
function moveRangeByOperation(range, operation) {
|
|
565
596
|
const anchor = slate.Point.transform(range.anchor, operation), focus = slate.Point.transform(range.focus, operation);
|
|
@@ -669,18 +700,18 @@ function getDragSelection({
|
|
|
669
700
|
}
|
|
670
701
|
}))
|
|
671
702
|
return dragSelection;
|
|
672
|
-
const draggingCollapsedSelection =
|
|
703
|
+
const draggingCollapsedSelection = selector_getFocusSpan.isSelectionCollapsed({
|
|
673
704
|
context: {
|
|
674
705
|
...snapshot.context,
|
|
675
706
|
selection: eventSelection
|
|
676
707
|
}
|
|
677
|
-
}), draggedTextBlock =
|
|
708
|
+
}), draggedTextBlock = selector_getFocusSpan.getFocusTextBlock({
|
|
678
709
|
...snapshot,
|
|
679
710
|
context: {
|
|
680
711
|
...snapshot.context,
|
|
681
712
|
selection: eventSelection
|
|
682
713
|
}
|
|
683
|
-
}), draggedSpan =
|
|
714
|
+
}), draggedSpan = selector_getFocusSpan.getFocusSpan({
|
|
684
715
|
...snapshot,
|
|
685
716
|
context: {
|
|
686
717
|
...snapshot.context,
|
|
@@ -692,20 +723,20 @@ function getDragSelection({
|
|
|
692
723
|
context: snapshot.context,
|
|
693
724
|
block: draggedTextBlock
|
|
694
725
|
}),
|
|
695
|
-
focus:
|
|
726
|
+
focus: util_isSelectionCollapsed.getBlockEndPoint({
|
|
696
727
|
context: snapshot.context,
|
|
697
728
|
block: draggedTextBlock
|
|
698
729
|
})
|
|
699
730
|
});
|
|
700
731
|
const selectedBlocks = selector_isSelectingEntireBlocks.getSelectedBlocks(snapshot);
|
|
701
|
-
if (snapshot.context.selection &&
|
|
732
|
+
if (snapshot.context.selection && selector_getFocusSpan.isSelectionExpanded(snapshot) && selectedBlocks.length > 1) {
|
|
702
733
|
const selectionStartBlock = selector_isSelectingEntireBlocks.getSelectionStartBlock(snapshot), selectionEndBlock = selector_isSelectingEntireBlocks.getSelectionEndBlock(snapshot);
|
|
703
734
|
if (!selectionStartBlock || !selectionEndBlock)
|
|
704
735
|
return dragSelection;
|
|
705
736
|
const selectionStartPoint = util_sliceBlocks.getBlockStartPoint({
|
|
706
737
|
context: snapshot.context,
|
|
707
738
|
block: selectionStartBlock
|
|
708
|
-
}), selectionEndPoint =
|
|
739
|
+
}), selectionEndPoint = util_isSelectionCollapsed.getBlockEndPoint({
|
|
709
740
|
context: snapshot.context,
|
|
710
741
|
block: selectionEndBlock
|
|
711
742
|
});
|
|
@@ -765,7 +796,7 @@ function createCoreBlockElementBehaviorsConfig({
|
|
|
765
796
|
snapshot,
|
|
766
797
|
event
|
|
767
798
|
}) => {
|
|
768
|
-
const dropFocusBlock =
|
|
799
|
+
const dropFocusBlock = selector_getFocusSpan.getFocusBlock({
|
|
769
800
|
...snapshot,
|
|
770
801
|
context: {
|
|
771
802
|
...snapshot.context,
|
|
@@ -1092,7 +1123,7 @@ const converterJson = {
|
|
|
1092
1123
|
originEvent: event.originEvent,
|
|
1093
1124
|
reason: "No selection"
|
|
1094
1125
|
};
|
|
1095
|
-
const blocks =
|
|
1126
|
+
const blocks = selector_getFocusSpan.getSelectedValue(snapshot);
|
|
1096
1127
|
return blocks.length === 0 ? {
|
|
1097
1128
|
type: "serialization.failure",
|
|
1098
1129
|
mimeType: "application/x-portable-text",
|
|
@@ -1152,7 +1183,7 @@ function createConverterTextHtml(legacySchema) {
|
|
|
1152
1183
|
originEvent: event.originEvent,
|
|
1153
1184
|
reason: "No selection"
|
|
1154
1185
|
};
|
|
1155
|
-
const blocks =
|
|
1186
|
+
const blocks = selector_getFocusSpan.getSelectedValue(snapshot), html = toHtml.toHTML(blocks, {
|
|
1156
1187
|
onMissingComponent: !1,
|
|
1157
1188
|
components: {
|
|
1158
1189
|
unknownType: ({
|
|
@@ -1210,7 +1241,7 @@ function createConverterTextPlain(legacySchema) {
|
|
|
1210
1241
|
event
|
|
1211
1242
|
}) => snapshot.context.selection ? {
|
|
1212
1243
|
type: "serialization.success",
|
|
1213
|
-
data:
|
|
1244
|
+
data: selector_getFocusSpan.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(`
|
|
1214
1245
|
|
|
1215
1246
|
`),
|
|
1216
1247
|
mimeType: "text/plain",
|
|
@@ -1343,43 +1374,34 @@ function createPlaceholderBlock(context) {
|
|
|
1343
1374
|
}]
|
|
1344
1375
|
};
|
|
1345
1376
|
}
|
|
1346
|
-
function getActiveAnnotations({
|
|
1347
|
-
markState,
|
|
1348
|
-
schema: schema2
|
|
1349
|
-
}) {
|
|
1350
|
-
return (markState?.marks ?? []).filter((mark) => !schema2.decorators.map((decorator) => decorator.name).includes(mark));
|
|
1351
|
-
}
|
|
1352
|
-
function getActiveDecorators({
|
|
1353
|
-
decoratorState,
|
|
1354
|
-
markState,
|
|
1355
|
-
schema: schema2
|
|
1356
|
-
}) {
|
|
1357
|
-
const decorators = schema2.decorators.map((decorator) => decorator.name);
|
|
1358
|
-
let activeDecorators = (markState?.marks ?? []).filter((mark) => decorators.includes(mark));
|
|
1359
|
-
for (const decorator in decoratorState)
|
|
1360
|
-
decoratorState[decorator] === !1 ? activeDecorators = activeDecorators.filter((activeDecorator) => activeDecorator !== decorator) : decoratorState[decorator] === !0 && (activeDecorators.includes(decorator) || activeDecorators.push(decorator));
|
|
1361
|
-
return activeDecorators;
|
|
1362
|
-
}
|
|
1363
1377
|
const insertTextOperationImplementation = ({
|
|
1364
1378
|
context,
|
|
1365
1379
|
operation
|
|
1366
1380
|
}) => {
|
|
1367
|
-
const
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1381
|
+
const snapshot = {
|
|
1382
|
+
blockIndexMap: operation.editor.blockIndexMap,
|
|
1383
|
+
context: {
|
|
1384
|
+
value: operation.editor.value,
|
|
1385
|
+
selection: operation.editor.selection ? slateRangeToSelection({
|
|
1386
|
+
schema: context.schema,
|
|
1387
|
+
editor: operation.editor,
|
|
1388
|
+
range: operation.editor.selection
|
|
1389
|
+
}) : null,
|
|
1390
|
+
schema: context.schema,
|
|
1391
|
+
keyGenerator: context.keyGenerator,
|
|
1392
|
+
converters: [],
|
|
1393
|
+
readOnly: !1
|
|
1394
|
+
},
|
|
1395
|
+
decoratorState: operation.editor.decoratorState
|
|
1396
|
+
}, markState = selector_isSelectingEntireBlocks.getMarkState(snapshot), activeDecorators = selector_isSelectingEntireBlocks.getActiveDecorators(snapshot), activeAnnotations = selector_isSelectingEntireBlocks.getActiveAnnotationsMarks(snapshot), [focusSpan] = getFocusSpan({
|
|
1375
1397
|
editor: operation.editor
|
|
1376
1398
|
});
|
|
1377
1399
|
if (!focusSpan) {
|
|
1378
1400
|
slate.Transforms.insertText(operation.editor, operation.text);
|
|
1379
1401
|
return;
|
|
1380
1402
|
}
|
|
1381
|
-
if (
|
|
1382
|
-
const markStateDecorators = (
|
|
1403
|
+
if (markState && markState.state === "unchanged") {
|
|
1404
|
+
const markStateDecorators = (markState.marks ?? []).filter((mark) => context.schema.decorators.map((decorator) => decorator.name).includes(mark));
|
|
1383
1405
|
if (markStateDecorators.length === activeDecorators.length && markStateDecorators.every((mark) => activeDecorators.includes(mark))) {
|
|
1384
1406
|
slate.Transforms.insertText(operation.editor, operation.text);
|
|
1385
1407
|
return;
|
|
@@ -1493,17 +1515,7 @@ function getEditorSnapshot({
|
|
|
1493
1515
|
selection: editorActorSnapshot.context.selection,
|
|
1494
1516
|
value: slateEditorInstance.value
|
|
1495
1517
|
},
|
|
1496
|
-
|
|
1497
|
-
activeAnnotations: getActiveAnnotations({
|
|
1498
|
-
markState: slateEditorInstance.markState,
|
|
1499
|
-
schema: editorActorSnapshot.context.schema
|
|
1500
|
-
}),
|
|
1501
|
-
activeDecorators: getActiveDecorators({
|
|
1502
|
-
decoratorState: slateEditorInstance.decoratorState,
|
|
1503
|
-
markState: slateEditorInstance.markState,
|
|
1504
|
-
schema: editorActorSnapshot.context.schema
|
|
1505
|
-
})
|
|
1506
|
-
}
|
|
1518
|
+
decoratorState: slateEditorInstance.decoratorState
|
|
1507
1519
|
};
|
|
1508
1520
|
}
|
|
1509
1521
|
const debug$e = debugWithName("plugin:withPortableTextMarkModel");
|
|
@@ -1718,11 +1730,15 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1718
1730
|
}
|
|
1719
1731
|
}
|
|
1720
1732
|
if (op.type === "insert_text") {
|
|
1721
|
-
|
|
1733
|
+
const snapshot = getEditorSnapshot({
|
|
1734
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
1735
|
+
slateEditorInstance: editor
|
|
1736
|
+
}), markState = selector_isSelectingEntireBlocks.getMarkState(snapshot);
|
|
1737
|
+
if (!markState) {
|
|
1722
1738
|
apply2(op);
|
|
1723
1739
|
return;
|
|
1724
1740
|
}
|
|
1725
|
-
if (
|
|
1741
|
+
if (markState.state === "unchanged") {
|
|
1726
1742
|
apply2(op);
|
|
1727
1743
|
return;
|
|
1728
1744
|
}
|
|
@@ -1730,7 +1746,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1730
1746
|
_type: "span",
|
|
1731
1747
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
1732
1748
|
text: op.text,
|
|
1733
|
-
marks:
|
|
1749
|
+
marks: markState.marks
|
|
1734
1750
|
});
|
|
1735
1751
|
return;
|
|
1736
1752
|
}
|
|
@@ -1767,7 +1783,7 @@ function createWithPortableTextMarkModel(editorActor) {
|
|
|
1767
1783
|
});
|
|
1768
1784
|
slate.Editor.withoutNormalizing(editor, () => {
|
|
1769
1785
|
apply2(op), slate.Transforms.setNodes(editor, {
|
|
1770
|
-
marks: snapshot
|
|
1786
|
+
marks: selector_isSelectingEntireBlocks.getActiveDecorators(snapshot)
|
|
1771
1787
|
}, {
|
|
1772
1788
|
at: op.path
|
|
1773
1789
|
});
|
|
@@ -2890,15 +2906,22 @@ const addAnnotationOperationImplementation = ({
|
|
|
2890
2906
|
operation
|
|
2891
2907
|
}) => {
|
|
2892
2908
|
const location = toSlateRange({
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2909
|
+
context: {
|
|
2910
|
+
schema: context.schema,
|
|
2911
|
+
value: operation.editor.value,
|
|
2912
|
+
selection: {
|
|
2913
|
+
anchor: {
|
|
2914
|
+
path: operation.at,
|
|
2915
|
+
offset: 0
|
|
2916
|
+
},
|
|
2917
|
+
focus: {
|
|
2918
|
+
path: operation.at,
|
|
2919
|
+
offset: 0
|
|
2920
|
+
}
|
|
2921
|
+
}
|
|
2896
2922
|
},
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
offset: 0
|
|
2900
|
-
}
|
|
2901
|
-
}, operation.editor);
|
|
2923
|
+
blockIndexMap: operation.editor.blockIndexMap
|
|
2924
|
+
});
|
|
2902
2925
|
if (!location)
|
|
2903
2926
|
throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
|
|
2904
2927
|
const block = slate.Editor.node(operation.editor, location, {
|
|
@@ -2938,15 +2961,22 @@ const addAnnotationOperationImplementation = ({
|
|
|
2938
2961
|
operation
|
|
2939
2962
|
}) => {
|
|
2940
2963
|
const location = toSlateRange({
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2964
|
+
context: {
|
|
2965
|
+
schema: context.schema,
|
|
2966
|
+
value: operation.editor.value,
|
|
2967
|
+
selection: {
|
|
2968
|
+
anchor: {
|
|
2969
|
+
path: operation.at,
|
|
2970
|
+
offset: 0
|
|
2971
|
+
},
|
|
2972
|
+
focus: {
|
|
2973
|
+
path: operation.at,
|
|
2974
|
+
offset: 0
|
|
2975
|
+
}
|
|
2976
|
+
}
|
|
2944
2977
|
},
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
offset: 0
|
|
2948
|
-
}
|
|
2949
|
-
}, operation.editor);
|
|
2978
|
+
blockIndexMap: operation.editor.blockIndexMap
|
|
2979
|
+
});
|
|
2950
2980
|
if (!location)
|
|
2951
2981
|
throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
|
|
2952
2982
|
const block = slate.Editor.node(operation.editor, location, {
|
|
@@ -3003,15 +3033,22 @@ const addAnnotationOperationImplementation = ({
|
|
|
3003
3033
|
operation
|
|
3004
3034
|
}) => {
|
|
3005
3035
|
const location = toSlateRange({
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3036
|
+
context: {
|
|
3037
|
+
schema: context.schema,
|
|
3038
|
+
value: operation.editor.value,
|
|
3039
|
+
selection: {
|
|
3040
|
+
anchor: {
|
|
3041
|
+
path: operation.at,
|
|
3042
|
+
offset: 0
|
|
3043
|
+
},
|
|
3044
|
+
focus: {
|
|
3045
|
+
path: operation.at,
|
|
3046
|
+
offset: 0
|
|
3047
|
+
}
|
|
3048
|
+
}
|
|
3009
3049
|
},
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
offset: 0
|
|
3013
|
-
}
|
|
3014
|
-
}, operation.editor);
|
|
3050
|
+
blockIndexMap: operation.editor.blockIndexMap
|
|
3051
|
+
});
|
|
3015
3052
|
if (!location)
|
|
3016
3053
|
throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
|
|
3017
3054
|
const childEntry = slate.Editor.node(operation.editor, location, {
|
|
@@ -3072,15 +3109,22 @@ const addAnnotationOperationImplementation = ({
|
|
|
3072
3109
|
operation
|
|
3073
3110
|
}) => {
|
|
3074
3111
|
const location = toSlateRange({
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3112
|
+
context: {
|
|
3113
|
+
schema: context.schema,
|
|
3114
|
+
value: operation.editor.value,
|
|
3115
|
+
selection: {
|
|
3116
|
+
anchor: {
|
|
3117
|
+
path: operation.at,
|
|
3118
|
+
offset: 0
|
|
3119
|
+
},
|
|
3120
|
+
focus: {
|
|
3121
|
+
path: operation.at,
|
|
3122
|
+
offset: 0
|
|
3123
|
+
}
|
|
3124
|
+
}
|
|
3078
3125
|
},
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
offset: 0
|
|
3082
|
-
}
|
|
3083
|
-
}, operation.editor);
|
|
3126
|
+
blockIndexMap: operation.editor.blockIndexMap
|
|
3127
|
+
});
|
|
3084
3128
|
if (!location)
|
|
3085
3129
|
throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
|
|
3086
3130
|
const childEntry = slate.Editor.node(operation.editor, location, {
|
|
@@ -3145,7 +3189,14 @@ const addAnnotationOperationImplementation = ({
|
|
|
3145
3189
|
}) : void 0, manualSelection = manualAnchor && manualFocus ? {
|
|
3146
3190
|
anchor: manualAnchor,
|
|
3147
3191
|
focus: manualFocus
|
|
3148
|
-
} : void 0, selection = manualSelection ? toSlateRange(
|
|
3192
|
+
} : void 0, selection = manualSelection ? toSlateRange({
|
|
3193
|
+
context: {
|
|
3194
|
+
schema: context.schema,
|
|
3195
|
+
value: operation.editor.value,
|
|
3196
|
+
selection: manualSelection
|
|
3197
|
+
},
|
|
3198
|
+
blockIndexMap: operation.editor.blockIndexMap
|
|
3199
|
+
}) ?? editor.selection : editor.selection;
|
|
3149
3200
|
if (!selection)
|
|
3150
3201
|
return;
|
|
3151
3202
|
const editorSelection = slateRangeToSelection({
|
|
@@ -3186,10 +3237,6 @@ const addAnnotationOperationImplementation = ({
|
|
|
3186
3237
|
backward: editorSelection?.backward
|
|
3187
3238
|
}), trimmedSelection = selector_isSelectingEntireBlocks.getTrimmedSelection({
|
|
3188
3239
|
blockIndexMap: editor.blockIndexMap,
|
|
3189
|
-
beta: {
|
|
3190
|
-
activeAnnotations: [],
|
|
3191
|
-
activeDecorators: []
|
|
3192
|
-
},
|
|
3193
3240
|
context: {
|
|
3194
3241
|
converters: [],
|
|
3195
3242
|
keyGenerator: context.keyGenerator,
|
|
@@ -3197,11 +3244,19 @@ const addAnnotationOperationImplementation = ({
|
|
|
3197
3244
|
schema: context.schema,
|
|
3198
3245
|
selection: newSelection,
|
|
3199
3246
|
value: newValue
|
|
3200
|
-
}
|
|
3247
|
+
},
|
|
3248
|
+
decoratorState: editor.decoratorState
|
|
3201
3249
|
});
|
|
3202
3250
|
if (!trimmedSelection)
|
|
3203
3251
|
throw new Error("Unable to find trimmed selection");
|
|
3204
|
-
const newRange = toSlateRange(
|
|
3252
|
+
const newRange = toSlateRange({
|
|
3253
|
+
context: {
|
|
3254
|
+
schema: context.schema,
|
|
3255
|
+
value: operation.editor.value,
|
|
3256
|
+
selection: trimmedSelection
|
|
3257
|
+
},
|
|
3258
|
+
blockIndexMap: operation.editor.blockIndexMap
|
|
3259
|
+
});
|
|
3205
3260
|
if (!newRange)
|
|
3206
3261
|
throw new Error("Unable to find new selection");
|
|
3207
3262
|
const splitTextNodes = slate.Range.isRange(newRange) ? [...slate.Editor.nodes(editor, {
|
|
@@ -3262,7 +3317,14 @@ const addAnnotationOperationImplementation = ({
|
|
|
3262
3317
|
}), operation.editor.children.length === 0 && slate.Transforms.insertNodes(operation.editor, createPlaceholderBlock(context));
|
|
3263
3318
|
return;
|
|
3264
3319
|
}
|
|
3265
|
-
const range = toSlateRange(
|
|
3320
|
+
const range = toSlateRange({
|
|
3321
|
+
context: {
|
|
3322
|
+
schema: context.schema,
|
|
3323
|
+
value: operation.editor.value,
|
|
3324
|
+
selection: operation.at
|
|
3325
|
+
},
|
|
3326
|
+
blockIndexMap: operation.editor.blockIndexMap
|
|
3327
|
+
});
|
|
3266
3328
|
if (!range)
|
|
3267
3329
|
throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(operation.at)}`);
|
|
3268
3330
|
operation.editor.delete({
|
|
@@ -3535,9 +3597,22 @@ const moveBackwardOperationImplementation = ({
|
|
|
3535
3597
|
reverse: !0
|
|
3536
3598
|
});
|
|
3537
3599
|
}, moveBlockOperationImplementation = ({
|
|
3600
|
+
context,
|
|
3538
3601
|
operation
|
|
3539
3602
|
}) => {
|
|
3540
|
-
const at = [toSlatePath(
|
|
3603
|
+
const at = [toSlatePath({
|
|
3604
|
+
context: {
|
|
3605
|
+
schema: context.schema,
|
|
3606
|
+
value: operation.editor.value
|
|
3607
|
+
},
|
|
3608
|
+
blockIndexMap: operation.editor.blockIndexMap
|
|
3609
|
+
}, operation.at).path[0]], to = [toSlatePath({
|
|
3610
|
+
context: {
|
|
3611
|
+
schema: context.schema,
|
|
3612
|
+
value: operation.editor.value
|
|
3613
|
+
},
|
|
3614
|
+
blockIndexMap: operation.editor.blockIndexMap
|
|
3615
|
+
}, operation.to).path[0]];
|
|
3541
3616
|
slate.Transforms.moveNodes(operation.editor, {
|
|
3542
3617
|
at,
|
|
3543
3618
|
to,
|
|
@@ -3551,9 +3626,17 @@ const moveBackwardOperationImplementation = ({
|
|
|
3551
3626
|
distance: operation.distance
|
|
3552
3627
|
});
|
|
3553
3628
|
}, selectOperationImplementation = ({
|
|
3629
|
+
context,
|
|
3554
3630
|
operation
|
|
3555
3631
|
}) => {
|
|
3556
|
-
const newSelection = toSlateRange(
|
|
3632
|
+
const newSelection = toSlateRange({
|
|
3633
|
+
context: {
|
|
3634
|
+
schema: context.schema,
|
|
3635
|
+
value: operation.editor.value,
|
|
3636
|
+
selection: operation.at
|
|
3637
|
+
},
|
|
3638
|
+
blockIndexMap: operation.editor.blockIndexMap
|
|
3639
|
+
});
|
|
3557
3640
|
newSelection ? slate.Transforms.select(operation.editor, newSelection) : slate.Transforms.deselect(operation.editor);
|
|
3558
3641
|
}, behaviorOperationImplementations = {
|
|
3559
3642
|
"annotation.add": addAnnotationOperationImplementation,
|
|
@@ -4348,7 +4431,7 @@ function insertTextPatch(schema2, children, operation, beforeValue) {
|
|
|
4348
4431
|
throw new Error("Could not find block");
|
|
4349
4432
|
const textChild = util_sliceBlocks.isTextBlock({
|
|
4350
4433
|
schema: schema2
|
|
4351
|
-
}, block) && util_sliceBlocks.isSpan
|
|
4434
|
+
}, block) && util_sliceBlocks.isSpan({
|
|
4352
4435
|
schema: schema2
|
|
4353
4436
|
}, block.children[operation.path[1]]) && block.children[operation.path[1]];
|
|
4354
4437
|
if (!textChild)
|
|
@@ -4359,7 +4442,7 @@ function insertTextPatch(schema2, children, operation, beforeValue) {
|
|
|
4359
4442
|
_key: textChild._key
|
|
4360
4443
|
}, "text"], prevBlock = beforeValue[operation.path[0]], prevChild = util_sliceBlocks.isTextBlock({
|
|
4361
4444
|
schema: schema2
|
|
4362
|
-
}, prevBlock) && prevBlock.children[operation.path[1]], prevText = util_sliceBlocks.isSpan
|
|
4445
|
+
}, prevBlock) && prevBlock.children[operation.path[1]], prevText = util_sliceBlocks.isSpan({
|
|
4363
4446
|
schema: schema2
|
|
4364
4447
|
}, prevChild) ? prevChild.text : "", patch = patches.diffMatchPatch(prevText, textChild.text, path);
|
|
4365
4448
|
return patch.value.length ? [patch] : [];
|
|
@@ -4370,7 +4453,7 @@ function removeTextPatch(schema2, children, operation, beforeValue) {
|
|
|
4370
4453
|
throw new Error("Could not find block");
|
|
4371
4454
|
const child = util_sliceBlocks.isTextBlock({
|
|
4372
4455
|
schema: schema2
|
|
4373
|
-
}, block) && block.children[operation.path[1]] || void 0, textChild = util_sliceBlocks.isSpan
|
|
4456
|
+
}, block) && block.children[operation.path[1]] || void 0, textChild = util_sliceBlocks.isSpan({
|
|
4374
4457
|
schema: schema2
|
|
4375
4458
|
}, child) ? child : void 0;
|
|
4376
4459
|
if (child && !textChild)
|
|
@@ -4383,7 +4466,7 @@ function removeTextPatch(schema2, children, operation, beforeValue) {
|
|
|
4383
4466
|
_key: textChild._key
|
|
4384
4467
|
}, "text"], beforeBlock = beforeValue[operation.path[0]], prevTextChild = util_sliceBlocks.isTextBlock({
|
|
4385
4468
|
schema: schema2
|
|
4386
|
-
}, beforeBlock) && beforeBlock.children[operation.path[1]], prevText = util_sliceBlocks.isSpan
|
|
4469
|
+
}, beforeBlock) && beforeBlock.children[operation.path[1]], prevText = util_sliceBlocks.isSpan({
|
|
4387
4470
|
schema: schema2
|
|
4388
4471
|
}, prevTextChild) && prevTextChild.text, patch = patches.diffMatchPatch(prevText || "", textChild.text, path);
|
|
4389
4472
|
return patch.value ? [patch] : [];
|
|
@@ -4484,7 +4567,7 @@ function splitNodePatch(schema2, children, operation, beforeValue) {
|
|
|
4484
4567
|
}
|
|
4485
4568
|
if (operation.path.length === 2) {
|
|
4486
4569
|
const splitSpan = splitBlock.children[operation.path[1]];
|
|
4487
|
-
if (util_sliceBlocks.isSpan
|
|
4570
|
+
if (util_sliceBlocks.isSpan({
|
|
4488
4571
|
schema: schema2
|
|
4489
4572
|
}, splitSpan)) {
|
|
4490
4573
|
const targetSpans = fromSlateValue([{
|
|
@@ -4542,9 +4625,9 @@ function mergeNodePatch(schema2, children, operation, beforeValue) {
|
|
|
4542
4625
|
}, block) && util_sliceBlocks.isTextBlock({
|
|
4543
4626
|
schema: schema2
|
|
4544
4627
|
}, updatedBlock) && operation.path.length === 2) {
|
|
4545
|
-
const updatedSpan = updatedBlock.children[operation.path[1] - 1] && util_sliceBlocks.isSpan
|
|
4628
|
+
const updatedSpan = updatedBlock.children[operation.path[1] - 1] && util_sliceBlocks.isSpan({
|
|
4546
4629
|
schema: schema2
|
|
4547
|
-
}, updatedBlock.children[operation.path[1] - 1]) ? updatedBlock.children[operation.path[1] - 1] : void 0, removedSpan = block.children[operation.path[1]] && util_sliceBlocks.isSpan
|
|
4630
|
+
}, updatedBlock.children[operation.path[1] - 1]) ? updatedBlock.children[operation.path[1] - 1] : void 0, removedSpan = block.children[operation.path[1]] && util_sliceBlocks.isSpan({
|
|
4548
4631
|
schema: schema2
|
|
4549
4632
|
}, block.children[operation.path[1]]) ? block.children[operation.path[1]] : void 0;
|
|
4550
4633
|
updatedSpan && (block.children.filter((span) => span._key === updatedSpan._key).length === 1 ? patches$1.push(patches.set(updatedSpan.text, [{
|
|
@@ -4732,7 +4815,7 @@ function createWithSchemaTypes({
|
|
|
4732
4815
|
editorActor
|
|
4733
4816
|
}) {
|
|
4734
4817
|
return function(editor) {
|
|
4735
|
-
editor.isTextBlock = (value) => slate.Editor.isEditor(value) ? !1 : util_sliceBlocks.isTextBlock(editorActor.getSnapshot().context, value), editor.isTextSpan = (value) => slate.Editor.isEditor(value) ? !1 : util_sliceBlocks.isSpan
|
|
4818
|
+
editor.isTextBlock = (value) => slate.Editor.isEditor(value) ? !1 : util_sliceBlocks.isTextBlock(editorActor.getSnapshot().context, value), editor.isTextSpan = (value) => slate.Editor.isEditor(value) ? !1 : util_sliceBlocks.isSpan(editorActor.getSnapshot().context, value), editor.isListBlock = (value) => slate.Editor.isEditor(value) ? !1 : util_sliceBlocks.isListBlock(editorActor.getSnapshot().context, value), editor.isVoid = (element) => slate.Editor.isEditor(element) ? !1 : editorActor.getSnapshot().context.schema.block.name !== element._type && (editorActor.getSnapshot().context.schema.blockObjects.map((obj) => obj.name).includes(element._type) || editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type)), editor.isInline = (element) => slate.Editor.isEditor(element) ? !1 : editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type) && "__inline" in element && element.__inline === !0;
|
|
4736
4819
|
const {
|
|
4737
4820
|
normalizeNode
|
|
4738
4821
|
} = editor;
|
|
@@ -4800,110 +4883,6 @@ function createWithUtils({
|
|
|
4800
4883
|
})[0], editor;
|
|
4801
4884
|
};
|
|
4802
4885
|
}
|
|
4803
|
-
function getMarkState({
|
|
4804
|
-
schema: schema2,
|
|
4805
|
-
editor
|
|
4806
|
-
}) {
|
|
4807
|
-
if (!editor.selection)
|
|
4808
|
-
return;
|
|
4809
|
-
const [block, blockPath] = getFocusBlock({
|
|
4810
|
-
editor
|
|
4811
|
-
}), [span, spanPath] = getFocusSpan({
|
|
4812
|
-
editor
|
|
4813
|
-
});
|
|
4814
|
-
if (!block || !editor.isTextBlock(block) || !span)
|
|
4815
|
-
return;
|
|
4816
|
-
if (slate.Range.isExpanded(editor.selection)) {
|
|
4817
|
-
const selection = editor.selection ? slateRangeToSelection({
|
|
4818
|
-
schema: schema2,
|
|
4819
|
-
editor,
|
|
4820
|
-
range: editor.selection
|
|
4821
|
-
}) : null, selectedSpans = selector_isSelectingEntireBlocks.getSelectedSpans({
|
|
4822
|
-
blockIndexMap: editor.blockIndexMap,
|
|
4823
|
-
context: {
|
|
4824
|
-
value: editor.value,
|
|
4825
|
-
selection,
|
|
4826
|
-
schema: schema2,
|
|
4827
|
-
converters: [],
|
|
4828
|
-
keyGenerator: () => "",
|
|
4829
|
-
readOnly: !1
|
|
4830
|
-
}
|
|
4831
|
-
});
|
|
4832
|
-
let index = 0, marks2 = [];
|
|
4833
|
-
for (const span2 of selectedSpans)
|
|
4834
|
-
index === 0 ? marks2 = span2.node.marks ?? [] : (span2.node.marks?.length === 0 || (span2.node.marks ?? [])?.some((mark) => !marks2.includes(mark))) && (marks2 = []), index++;
|
|
4835
|
-
return {
|
|
4836
|
-
state: "unchanged",
|
|
4837
|
-
marks: marks2
|
|
4838
|
-
};
|
|
4839
|
-
}
|
|
4840
|
-
const decorators = schema2.decorators.map((decorator) => decorator.name), marks = span.marks ?? [], marksWithoutAnnotations = marks.filter((mark) => decorators.includes(mark)), spanHasAnnotations = marks.length > marksWithoutAnnotations.length, spanIsEmpty = span.text.length === 0, atTheBeginningOfSpan = editor.selection.anchor.offset === 0, atTheEndOfSpan = editor.selection.anchor.offset === span.text.length, previousSpan = getPreviousSpan({
|
|
4841
|
-
editor,
|
|
4842
|
-
blockPath,
|
|
4843
|
-
spanPath
|
|
4844
|
-
}), nextSpan = getNextSpan({
|
|
4845
|
-
editor,
|
|
4846
|
-
blockPath,
|
|
4847
|
-
spanPath
|
|
4848
|
-
}), nextSpanAnnotations = nextSpan?.marks?.filter((mark) => !decorators.includes(mark)) ?? [], spanAnnotations = marks.filter((mark) => !decorators.includes(mark)), previousSpanHasAnnotations = previousSpan ? previousSpan.marks?.some((mark) => !decorators.includes(mark)) : !1, previousSpanHasSameAnnotations = previousSpan ? previousSpan.marks?.filter((mark) => !decorators.includes(mark)).every((mark) => marks.includes(mark)) : !1, previousSpanHasSameAnnotation = previousSpan ? previousSpan.marks?.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1, previousSpanHasSameMarks = previousSpan ? previousSpan.marks?.every((mark) => marks.includes(mark)) : !1, nextSpanSharesSomeAnnotations = spanAnnotations.some((mark) => nextSpanAnnotations?.includes(mark));
|
|
4849
|
-
if (spanHasAnnotations && !spanIsEmpty) {
|
|
4850
|
-
if (atTheBeginningOfSpan) {
|
|
4851
|
-
if (previousSpanHasSameMarks)
|
|
4852
|
-
return {
|
|
4853
|
-
state: "changed",
|
|
4854
|
-
marks: previousSpan?.marks ?? []
|
|
4855
|
-
};
|
|
4856
|
-
if (previousSpanHasSameAnnotations)
|
|
4857
|
-
return {
|
|
4858
|
-
state: "changed",
|
|
4859
|
-
marks: previousSpan?.marks ?? []
|
|
4860
|
-
};
|
|
4861
|
-
if (previousSpanHasSameAnnotation)
|
|
4862
|
-
return {
|
|
4863
|
-
state: "unchanged",
|
|
4864
|
-
marks: span.marks ?? []
|
|
4865
|
-
};
|
|
4866
|
-
if (!previousSpan)
|
|
4867
|
-
return {
|
|
4868
|
-
state: "changed",
|
|
4869
|
-
marks: []
|
|
4870
|
-
};
|
|
4871
|
-
}
|
|
4872
|
-
if (atTheEndOfSpan) {
|
|
4873
|
-
if (nextSpan && nextSpanSharesSomeAnnotations && nextSpanAnnotations.length < spanAnnotations.length || !nextSpanSharesSomeAnnotations)
|
|
4874
|
-
return {
|
|
4875
|
-
state: "changed",
|
|
4876
|
-
marks: nextSpan?.marks ?? []
|
|
4877
|
-
};
|
|
4878
|
-
if (!nextSpan)
|
|
4879
|
-
return {
|
|
4880
|
-
state: "changed",
|
|
4881
|
-
marks: []
|
|
4882
|
-
};
|
|
4883
|
-
}
|
|
4884
|
-
}
|
|
4885
|
-
return atTheBeginningOfSpan && !spanIsEmpty && previousSpan ? previousSpanHasAnnotations ? {
|
|
4886
|
-
state: "changed",
|
|
4887
|
-
marks: []
|
|
4888
|
-
} : {
|
|
4889
|
-
state: "changed",
|
|
4890
|
-
marks: (previousSpan?.marks ?? []).filter((mark) => decorators.includes(mark))
|
|
4891
|
-
} : {
|
|
4892
|
-
state: "unchanged",
|
|
4893
|
-
marks: span.marks ?? []
|
|
4894
|
-
};
|
|
4895
|
-
}
|
|
4896
|
-
function pluginUpdateMarkState(context, editor) {
|
|
4897
|
-
const {
|
|
4898
|
-
apply: apply2
|
|
4899
|
-
} = editor;
|
|
4900
|
-
return editor.apply = (operation) => {
|
|
4901
|
-
apply2(operation), editor.markState = getMarkState({
|
|
4902
|
-
editor,
|
|
4903
|
-
schema: context.schema
|
|
4904
|
-
});
|
|
4905
|
-
}, editor;
|
|
4906
|
-
}
|
|
4907
4886
|
function pluginUpdateSelection({
|
|
4908
4887
|
editor,
|
|
4909
4888
|
editorActor
|
|
@@ -5247,10 +5226,10 @@ const withPlugins = (editor, options) => {
|
|
|
5247
5226
|
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor), withPlaceholderBlock = createWithPlaceholderBlock(editorActor), withUtils = createWithUtils({
|
|
5248
5227
|
editorActor
|
|
5249
5228
|
});
|
|
5250
|
-
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(pluginUpdateValue(editorActor.getSnapshot().context,
|
|
5229
|
+
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(pluginUpdateValue(editorActor.getSnapshot().context, pluginUpdateSelection({
|
|
5251
5230
|
editorActor,
|
|
5252
5231
|
editor: e
|
|
5253
|
-
})))))))))))
|
|
5232
|
+
})))))))))));
|
|
5254
5233
|
}, debug$9 = debugWithName("setup");
|
|
5255
5234
|
function createSlateEditor(config) {
|
|
5256
5235
|
debug$9("Creating new Slate editor instance");
|
|
@@ -5259,7 +5238,7 @@ function createSlateEditor(config) {
|
|
|
5259
5238
|
relayActor: config.relayActor,
|
|
5260
5239
|
subscriptions: config.subscriptions
|
|
5261
5240
|
});
|
|
5262
|
-
KEY_TO_VALUE_ELEMENT.set(instance, {}), KEY_TO_SLATE_ELEMENT.set(instance, {}), instance.decoratedRanges = [], instance.decoratorState = {}
|
|
5241
|
+
KEY_TO_VALUE_ELEMENT.set(instance, {}), KEY_TO_SLATE_ELEMENT.set(instance, {}), instance.decoratedRanges = [], instance.decoratorState = {};
|
|
5263
5242
|
const placeholderBlock = createPlaceholderBlock(config.editorActor.getSnapshot().context);
|
|
5264
5243
|
instance.value = [placeholderBlock], instance.blockIndexMap = /* @__PURE__ */ new Map(), instance.listIndexMap = /* @__PURE__ */ new Map(), buildIndexMaps({
|
|
5265
5244
|
schema: config.editorActor.getSnapshot().context.schema,
|
|
@@ -5293,7 +5272,7 @@ function createEditorDom(sendBack, slateEditor) {
|
|
|
5293
5272
|
function getBlockNodes(slateEditor, snapshot) {
|
|
5294
5273
|
if (!snapshot.context.selection)
|
|
5295
5274
|
return [];
|
|
5296
|
-
const range = toSlateRange(snapshot
|
|
5275
|
+
const range = toSlateRange(snapshot);
|
|
5297
5276
|
if (!range)
|
|
5298
5277
|
return [];
|
|
5299
5278
|
try {
|
|
@@ -5309,7 +5288,7 @@ function getBlockNodes(slateEditor, snapshot) {
|
|
|
5309
5288
|
function getChildNodes(slateEditor, snapshot) {
|
|
5310
5289
|
if (!snapshot.context.selection)
|
|
5311
5290
|
return [];
|
|
5312
|
-
const range = toSlateRange(snapshot
|
|
5291
|
+
const range = toSlateRange(snapshot);
|
|
5313
5292
|
if (!range)
|
|
5314
5293
|
return [];
|
|
5315
5294
|
try {
|
|
@@ -5337,10 +5316,10 @@ const addAnnotationOnCollapsedSelection = behaviors_index.defineBehavior({
|
|
|
5337
5316
|
guard: ({
|
|
5338
5317
|
snapshot
|
|
5339
5318
|
}) => {
|
|
5340
|
-
if (!
|
|
5319
|
+
if (!selector_getFocusSpan.isSelectionCollapsed(snapshot))
|
|
5341
5320
|
return !1;
|
|
5342
5321
|
const caretWordSelection = selector_isSelectingEntireBlocks.getCaretWordSelection(snapshot);
|
|
5343
|
-
return !caretWordSelection || !
|
|
5322
|
+
return !caretWordSelection || !selector_getFocusSpan.isSelectionExpanded({
|
|
5344
5323
|
context: {
|
|
5345
5324
|
...snapshot.context,
|
|
5346
5325
|
selection: caretWordSelection
|
|
@@ -5566,7 +5545,7 @@ const defaultKeyboardShortcuts = {
|
|
|
5566
5545
|
snapshot,
|
|
5567
5546
|
event
|
|
5568
5547
|
}) => {
|
|
5569
|
-
if (!defaultKeyboardShortcuts.arrowDown.guard(event.originEvent) || !
|
|
5548
|
+
if (!defaultKeyboardShortcuts.arrowDown.guard(event.originEvent) || !selector_getFocusSpan.isSelectionCollapsed(snapshot))
|
|
5570
5549
|
return !1;
|
|
5571
5550
|
const focusBlockObject = selector_isSelectingEntireBlocks.getFocusBlockObject(snapshot), nextBlock = selector_isSelectingEntireBlocks.getNextBlock(snapshot);
|
|
5572
5551
|
return focusBlockObject && !nextBlock;
|
|
@@ -5586,7 +5565,7 @@ const defaultKeyboardShortcuts = {
|
|
|
5586
5565
|
snapshot,
|
|
5587
5566
|
event
|
|
5588
5567
|
}) => {
|
|
5589
|
-
if (!defaultKeyboardShortcuts.arrowUp.guard(event.originEvent) || !
|
|
5568
|
+
if (!defaultKeyboardShortcuts.arrowUp.guard(event.originEvent) || !selector_getFocusSpan.isSelectionCollapsed(snapshot))
|
|
5590
5569
|
return !1;
|
|
5591
5570
|
const focusBlockObject = selector_isSelectingEntireBlocks.getFocusBlockObject(snapshot), previousBlock = selector_isSelectingEntireBlocks.getPreviousBlock(snapshot);
|
|
5592
5571
|
return focusBlockObject && !previousBlock;
|
|
@@ -5606,7 +5585,7 @@ const defaultKeyboardShortcuts = {
|
|
|
5606
5585
|
snapshot
|
|
5607
5586
|
}) => {
|
|
5608
5587
|
const focusBlockObject = selector_isSelectingEntireBlocks.getFocusBlockObject(snapshot);
|
|
5609
|
-
return
|
|
5588
|
+
return selector_getFocusSpan.isSelectionCollapsed(snapshot) && focusBlockObject !== void 0;
|
|
5610
5589
|
},
|
|
5611
5590
|
actions: [({
|
|
5612
5591
|
snapshot
|
|
@@ -5623,7 +5602,7 @@ const defaultKeyboardShortcuts = {
|
|
|
5623
5602
|
snapshot,
|
|
5624
5603
|
event
|
|
5625
5604
|
}) => {
|
|
5626
|
-
if (snapshot.context.readOnly || snapshot.context.selection && !
|
|
5605
|
+
if (snapshot.context.readOnly || snapshot.context.selection && !selector_getFocusSpan.isSelectionCollapsed(snapshot))
|
|
5627
5606
|
return !1;
|
|
5628
5607
|
const focusBlockObject = selector_isSelectingEntireBlocks.getFocusBlockObject({
|
|
5629
5608
|
...snapshot,
|
|
@@ -5660,7 +5639,7 @@ const defaultKeyboardShortcuts = {
|
|
|
5660
5639
|
snapshot,
|
|
5661
5640
|
event
|
|
5662
5641
|
}) => {
|
|
5663
|
-
if (snapshot.context.readOnly || snapshot.context.selection && !
|
|
5642
|
+
if (snapshot.context.readOnly || snapshot.context.selection && !selector_getFocusSpan.isSelectionCollapsed(snapshot))
|
|
5664
5643
|
return !1;
|
|
5665
5644
|
const focusBlockObject = selector_isSelectingEntireBlocks.getFocusBlockObject({
|
|
5666
5645
|
...snapshot,
|
|
@@ -5696,8 +5675,8 @@ const defaultKeyboardShortcuts = {
|
|
|
5696
5675
|
guard: ({
|
|
5697
5676
|
snapshot
|
|
5698
5677
|
}) => {
|
|
5699
|
-
const focusTextBlock =
|
|
5700
|
-
return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 :
|
|
5678
|
+
const focusTextBlock = selector_getFocusSpan.getFocusTextBlock(snapshot), selectionCollapsed = selector_getFocusSpan.isSelectionCollapsed(snapshot), previousBlock = selector_isSelectingEntireBlocks.getPreviousBlock(snapshot);
|
|
5679
|
+
return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : util_isSelectionCollapsed.isEmptyTextBlock(snapshot.context, focusTextBlock.node) && !util_sliceBlocks.isTextBlock(snapshot.context, previousBlock.node) ? {
|
|
5701
5680
|
focusTextBlock,
|
|
5702
5681
|
previousBlock
|
|
5703
5682
|
} : !1;
|
|
@@ -5726,8 +5705,8 @@ const defaultKeyboardShortcuts = {
|
|
|
5726
5705
|
guard: ({
|
|
5727
5706
|
snapshot
|
|
5728
5707
|
}) => {
|
|
5729
|
-
const focusTextBlock =
|
|
5730
|
-
return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 :
|
|
5708
|
+
const focusTextBlock = selector_getFocusSpan.getFocusTextBlock(snapshot), selectionCollapsed = selector_getFocusSpan.isSelectionCollapsed(snapshot), nextBlock = selector_isSelectingEntireBlocks.getNextBlock(snapshot);
|
|
5709
|
+
return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : util_isSelectionCollapsed.isEmptyTextBlock(snapshot.context, focusTextBlock.node) && !util_sliceBlocks.isTextBlock(snapshot.context, nextBlock.node) ? {
|
|
5731
5710
|
focusTextBlock,
|
|
5732
5711
|
nextBlock
|
|
5733
5712
|
} : !1;
|
|
@@ -6053,16 +6032,16 @@ const coreDndBehaviors = [
|
|
|
6053
6032
|
dragOrigin,
|
|
6054
6033
|
dropPosition,
|
|
6055
6034
|
originEvent
|
|
6056
|
-
}) => [
|
|
6035
|
+
}) => [behaviors_index.raise({
|
|
6036
|
+
type: "select",
|
|
6037
|
+
at: dropPosition
|
|
6038
|
+
}), ...draggingEntireBlocks ? draggedBlocks.map((block) => behaviors_index.raise({
|
|
6057
6039
|
type: "delete.block",
|
|
6058
6040
|
at: block.path
|
|
6059
6041
|
})) : [behaviors_index.raise({
|
|
6060
6042
|
type: "delete",
|
|
6061
6043
|
at: dragOrigin.selection
|
|
6062
6044
|
})], behaviors_index.raise({
|
|
6063
|
-
type: "select",
|
|
6064
|
-
at: dropPosition
|
|
6065
|
-
}), behaviors_index.raise({
|
|
6066
6045
|
type: "insert.blocks",
|
|
6067
6046
|
blocks: event.data,
|
|
6068
6047
|
placement: draggingEntireBlocks ? originEvent.position.block === "start" ? "before" : originEvent.position.block === "end" ? "after" : "auto" : "auto"
|
|
@@ -6073,7 +6052,7 @@ const coreDndBehaviors = [
|
|
|
6073
6052
|
guard: ({
|
|
6074
6053
|
snapshot
|
|
6075
6054
|
}) => {
|
|
6076
|
-
const focusTextBlock =
|
|
6055
|
+
const focusTextBlock = selector_getFocusSpan.getFocusTextBlock(snapshot), selectionCollapsed = selector_getFocusSpan.isSelectionCollapsed(snapshot);
|
|
6077
6056
|
if (!snapshot.context.selection || !focusTextBlock || !selectionCollapsed)
|
|
6078
6057
|
return !1;
|
|
6079
6058
|
const atTheEndOfBlock = selector_isSelectingEntireBlocks.isAtTheEndOfBlock(focusTextBlock)(snapshot), focusListItem = focusTextBlock.node.listItem, focusLevel = focusTextBlock.node.level;
|
|
@@ -6108,10 +6087,10 @@ const coreDndBehaviors = [
|
|
|
6108
6087
|
guard: ({
|
|
6109
6088
|
snapshot
|
|
6110
6089
|
}) => {
|
|
6111
|
-
const focusTextBlock =
|
|
6090
|
+
const focusTextBlock = selector_getFocusSpan.getFocusTextBlock(snapshot), selectionCollapsed = selector_getFocusSpan.isSelectionCollapsed(snapshot);
|
|
6112
6091
|
if (!snapshot.context.selection || !focusTextBlock || !selectionCollapsed)
|
|
6113
6092
|
return !1;
|
|
6114
|
-
const focusSpan =
|
|
6093
|
+
const focusSpan = selector_getFocusSpan.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;
|
|
6115
6094
|
return selector_isSelectingEntireBlocks.isAtTheStartOfBlock(focusTextBlock)(snapshot) ? {
|
|
6116
6095
|
focusAnnotations,
|
|
6117
6096
|
focusDecorators,
|
|
@@ -6147,7 +6126,7 @@ const coreDndBehaviors = [
|
|
|
6147
6126
|
guard: ({
|
|
6148
6127
|
snapshot
|
|
6149
6128
|
}) => {
|
|
6150
|
-
if (!snapshot.context.selection || !
|
|
6129
|
+
if (!snapshot.context.selection || !selector_getFocusSpan.isSelectionExpanded(snapshot))
|
|
6151
6130
|
return !1;
|
|
6152
6131
|
const firstBlock = selector_isSelectingEntireBlocks.getFirstBlock(snapshot), lastBlock = selector_isSelectingEntireBlocks.getLastBlock(snapshot);
|
|
6153
6132
|
if (!firstBlock || !lastBlock)
|
|
@@ -6155,11 +6134,11 @@ const coreDndBehaviors = [
|
|
|
6155
6134
|
const firstBlockStartPoint = util_sliceBlocks.getBlockStartPoint({
|
|
6156
6135
|
context: snapshot.context,
|
|
6157
6136
|
block: firstBlock
|
|
6158
|
-
}), selectionStartPoint = util_sliceBlocks.getSelectionStartPoint(snapshot.context.selection), lastBlockEndPoint =
|
|
6137
|
+
}), selectionStartPoint = util_sliceBlocks.getSelectionStartPoint(snapshot.context.selection), lastBlockEndPoint = util_isSelectionCollapsed.getBlockEndPoint({
|
|
6159
6138
|
context: snapshot.context,
|
|
6160
6139
|
block: lastBlock
|
|
6161
6140
|
}), selectionEndPoint = util_sliceBlocks.getSelectionEndPoint(snapshot.context.selection);
|
|
6162
|
-
return
|
|
6141
|
+
return util_isSelectionCollapsed.isEqualSelectionPoints(firstBlockStartPoint, selectionStartPoint) && util_isSelectionCollapsed.isEqualSelectionPoints(lastBlockEndPoint, selectionEndPoint) ? {
|
|
6163
6142
|
selection: snapshot.context.selection
|
|
6164
6143
|
} : !1;
|
|
6165
6144
|
},
|
|
@@ -6174,7 +6153,7 @@ const coreDndBehaviors = [
|
|
|
6174
6153
|
guard: ({
|
|
6175
6154
|
snapshot
|
|
6176
6155
|
}) => {
|
|
6177
|
-
if (!snapshot.context.selection || !
|
|
6156
|
+
if (!snapshot.context.selection || !selector_getFocusSpan.isSelectionExpanded(snapshot))
|
|
6178
6157
|
return !1;
|
|
6179
6158
|
const selectedBlocks = selector_isSelectingEntireBlocks.getSelectedBlocks(snapshot), selectionStartBlock = selector_isSelectingEntireBlocks.getSelectionStartBlock(snapshot), selectionEndBlock = selector_isSelectingEntireBlocks.getSelectionEndBlock(snapshot);
|
|
6180
6159
|
if (!selectionStartBlock || !selectionEndBlock)
|
|
@@ -6182,11 +6161,11 @@ const coreDndBehaviors = [
|
|
|
6182
6161
|
const startBlockStartPoint = util_sliceBlocks.getBlockStartPoint({
|
|
6183
6162
|
context: snapshot.context,
|
|
6184
6163
|
block: selectionStartBlock
|
|
6185
|
-
}), selectionStartPoint = util_sliceBlocks.getSelectionStartPoint(snapshot.context.selection), endBlockEndPoint =
|
|
6164
|
+
}), selectionStartPoint = util_sliceBlocks.getSelectionStartPoint(snapshot.context.selection), endBlockEndPoint = util_isSelectionCollapsed.getBlockEndPoint({
|
|
6186
6165
|
context: snapshot.context,
|
|
6187
6166
|
block: selectionEndBlock
|
|
6188
6167
|
}), selectionEndPoint = util_sliceBlocks.getSelectionEndPoint(snapshot.context.selection);
|
|
6189
|
-
return
|
|
6168
|
+
return util_isSelectionCollapsed.isEqualSelectionPoints(selectionStartPoint, startBlockStartPoint) && util_isSelectionCollapsed.isEqualSelectionPoints(selectionEndPoint, endBlockEndPoint) ? {
|
|
6190
6169
|
selectedBlocks
|
|
6191
6170
|
} : !1;
|
|
6192
6171
|
},
|
|
@@ -6215,7 +6194,7 @@ const coreDndBehaviors = [
|
|
|
6215
6194
|
guard: ({
|
|
6216
6195
|
snapshot
|
|
6217
6196
|
}) => {
|
|
6218
|
-
const selectionCollapsed =
|
|
6197
|
+
const selectionCollapsed = selector_getFocusSpan.isSelectionCollapsed(snapshot), focusInlineObject = selector_isSelectingEntireBlocks.getFocusInlineObject(snapshot);
|
|
6219
6198
|
return selectionCollapsed && focusInlineObject;
|
|
6220
6199
|
},
|
|
6221
6200
|
actions: [() => [behaviors_index.raise({
|
|
@@ -6235,7 +6214,7 @@ const coreDndBehaviors = [
|
|
|
6235
6214
|
guard: ({
|
|
6236
6215
|
snapshot
|
|
6237
6216
|
}) => {
|
|
6238
|
-
const selectionCollapsed =
|
|
6217
|
+
const selectionCollapsed = selector_getFocusSpan.isSelectionCollapsed(snapshot), focusTextBlock = selector_getFocusSpan.getFocusTextBlock(snapshot), focusSpan = selector_getFocusSpan.getFocusSpan(snapshot);
|
|
6239
6218
|
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && snapshot.context.selection?.focus.offset === 0 && focusTextBlock.node.level === 1 ? {
|
|
6240
6219
|
focusTextBlock
|
|
6241
6220
|
} : !1;
|
|
@@ -6252,7 +6231,7 @@ const coreDndBehaviors = [
|
|
|
6252
6231
|
guard: ({
|
|
6253
6232
|
snapshot
|
|
6254
6233
|
}) => {
|
|
6255
|
-
const selectionCollapsed =
|
|
6234
|
+
const selectionCollapsed = selector_getFocusSpan.isSelectionCollapsed(snapshot), focusTextBlock = selector_getFocusSpan.getFocusTextBlock(snapshot), focusSpan = selector_getFocusSpan.getFocusSpan(snapshot);
|
|
6256
6235
|
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 ? {
|
|
6257
6236
|
focusTextBlock,
|
|
6258
6237
|
level: focusTextBlock.node.level - 1
|
|
@@ -6273,8 +6252,8 @@ const coreDndBehaviors = [
|
|
|
6273
6252
|
guard: ({
|
|
6274
6253
|
snapshot
|
|
6275
6254
|
}) => {
|
|
6276
|
-
const selectionCollapsed =
|
|
6277
|
-
return !selectionCollapsed || !focusListBlock || !
|
|
6255
|
+
const selectionCollapsed = selector_getFocusSpan.isSelectionCollapsed(snapshot), focusListBlock = selector_isSelectingEntireBlocks.getFocusListBlock(snapshot);
|
|
6256
|
+
return !selectionCollapsed || !focusListBlock || !util_isSelectionCollapsed.isEmptyTextBlock(snapshot.context, focusListBlock.node) ? !1 : {
|
|
6278
6257
|
focusListBlock
|
|
6279
6258
|
};
|
|
6280
6259
|
},
|
|
@@ -6350,7 +6329,7 @@ const coreDndBehaviors = [
|
|
|
6350
6329
|
snapshot,
|
|
6351
6330
|
event
|
|
6352
6331
|
}) => {
|
|
6353
|
-
const blockKey = event.at[0]._key, markDefKey = event.at[2]._key, block =
|
|
6332
|
+
const blockKey = event.at[0]._key, markDefKey = event.at[2]._key, block = selector_getFocusSpan.getFocusTextBlock({
|
|
6354
6333
|
...snapshot,
|
|
6355
6334
|
context: {
|
|
6356
6335
|
...snapshot.context,
|
|
@@ -6510,7 +6489,7 @@ const coreDndBehaviors = [
|
|
|
6510
6489
|
snapshot,
|
|
6511
6490
|
event
|
|
6512
6491
|
}) => {
|
|
6513
|
-
const focusChild =
|
|
6492
|
+
const focusChild = selector_getFocusSpan.getFocusChild({
|
|
6514
6493
|
...snapshot,
|
|
6515
6494
|
context: {
|
|
6516
6495
|
...snapshot.context,
|
|
@@ -6526,7 +6505,7 @@ const coreDndBehaviors = [
|
|
|
6526
6505
|
}
|
|
6527
6506
|
}
|
|
6528
6507
|
});
|
|
6529
|
-
return focusChild ? util_sliceBlocks.isSpan
|
|
6508
|
+
return focusChild ? util_sliceBlocks.isSpan(snapshot.context, focusChild.node) ? {
|
|
6530
6509
|
selection: {
|
|
6531
6510
|
anchor: {
|
|
6532
6511
|
path: event.at,
|
|
@@ -6620,7 +6599,7 @@ const coreDndBehaviors = [
|
|
|
6620
6599
|
}) => {
|
|
6621
6600
|
if (event.placement !== "auto")
|
|
6622
6601
|
return !1;
|
|
6623
|
-
const focusTextBlock =
|
|
6602
|
+
const focusTextBlock = selector_getFocusSpan.getFocusTextBlock(snapshot);
|
|
6624
6603
|
return focusTextBlock ? {
|
|
6625
6604
|
focusTextBlock
|
|
6626
6605
|
} : !1;
|
|
@@ -6635,7 +6614,7 @@ const coreDndBehaviors = [
|
|
|
6635
6614
|
block: event.blocks[0],
|
|
6636
6615
|
placement: "auto",
|
|
6637
6616
|
select: event.select ?? "end"
|
|
6638
|
-
})] :
|
|
6617
|
+
})] : util_isSelectionCollapsed.isEmptyTextBlock(snapshot.context, focusTextBlock.node) ? event.blocks.map((block, index) => behaviors_index.raise({
|
|
6639
6618
|
type: "insert.block",
|
|
6640
6619
|
block,
|
|
6641
6620
|
placement: index === 0 ? "auto" : "after",
|
|
@@ -6699,7 +6678,7 @@ const coreDndBehaviors = [
|
|
|
6699
6678
|
guard: ({
|
|
6700
6679
|
snapshot,
|
|
6701
6680
|
event
|
|
6702
|
-
}) => defaultKeyboardShortcuts.break.guard(event.originEvent) &&
|
|
6681
|
+
}) => defaultKeyboardShortcuts.break.guard(event.originEvent) && selector_getFocusSpan.isSelectionCollapsed(snapshot) && selector_isSelectingEntireBlocks.getFocusInlineObject(snapshot),
|
|
6703
6682
|
actions: [() => [behaviors_index.raise({
|
|
6704
6683
|
type: "insert.break"
|
|
6705
6684
|
})]]
|
|
@@ -6878,7 +6857,7 @@ const coreDndBehaviors = [
|
|
|
6878
6857
|
const previousBlock = selector_isSelectingEntireBlocks.getPreviousBlock(snapshot);
|
|
6879
6858
|
if (!previousBlock)
|
|
6880
6859
|
return !1;
|
|
6881
|
-
const point = event.select === "end" ?
|
|
6860
|
+
const point = event.select === "end" ? util_isSelectionCollapsed.getBlockEndPoint({
|
|
6882
6861
|
context: snapshot.context,
|
|
6883
6862
|
block: previousBlock
|
|
6884
6863
|
}) : util_sliceBlocks.getBlockStartPoint({
|
|
@@ -6907,7 +6886,7 @@ const coreDndBehaviors = [
|
|
|
6907
6886
|
const nextBlock = selector_isSelectingEntireBlocks.getNextBlock(snapshot);
|
|
6908
6887
|
if (!nextBlock)
|
|
6909
6888
|
return !1;
|
|
6910
|
-
const point = event.select === "end" ?
|
|
6889
|
+
const point = event.select === "end" ? util_isSelectionCollapsed.getBlockEndPoint({
|
|
6911
6890
|
context: snapshot.context,
|
|
6912
6891
|
block: nextBlock
|
|
6913
6892
|
}) : util_sliceBlocks.getBlockStartPoint({
|
|
@@ -6935,7 +6914,7 @@ const coreDndBehaviors = [
|
|
|
6935
6914
|
on: "split",
|
|
6936
6915
|
guard: ({
|
|
6937
6916
|
snapshot
|
|
6938
|
-
}) =>
|
|
6917
|
+
}) => selector_getFocusSpan.isSelectionCollapsed(snapshot) && selector_isSelectingEntireBlocks.getFocusInlineObject(snapshot),
|
|
6939
6918
|
actions: []
|
|
6940
6919
|
}),
|
|
6941
6920
|
/**
|
|
@@ -6945,7 +6924,7 @@ const coreDndBehaviors = [
|
|
|
6945
6924
|
on: "split",
|
|
6946
6925
|
guard: ({
|
|
6947
6926
|
snapshot
|
|
6948
|
-
}) =>
|
|
6927
|
+
}) => selector_getFocusSpan.isSelectionCollapsed(snapshot) && selector_isSelectingEntireBlocks.getFocusBlockObject(snapshot),
|
|
6949
6928
|
actions: []
|
|
6950
6929
|
}),
|
|
6951
6930
|
behaviors_index.defineBehavior({
|
|
@@ -6954,7 +6933,7 @@ const coreDndBehaviors = [
|
|
|
6954
6933
|
snapshot
|
|
6955
6934
|
}) => {
|
|
6956
6935
|
const selection = snapshot.context.selection;
|
|
6957
|
-
if (!selection ||
|
|
6936
|
+
if (!selection || util_isSelectionCollapsed.isSelectionCollapsed(selection))
|
|
6958
6937
|
return !1;
|
|
6959
6938
|
const selectionStartBlock = selector_isSelectingEntireBlocks.getSelectionStartBlock(snapshot), selectionEndBlock = selector_isSelectingEntireBlocks.getSelectionEndBlock(snapshot);
|
|
6960
6939
|
return !selectionStartBlock || !selectionEndBlock ? !1 : !util_sliceBlocks.isTextBlock(snapshot.context, selectionStartBlock.node) && util_sliceBlocks.isTextBlock(snapshot.context, selectionEndBlock.node) ? {
|
|
@@ -6974,7 +6953,7 @@ const coreDndBehaviors = [
|
|
|
6974
6953
|
snapshot
|
|
6975
6954
|
}) => {
|
|
6976
6955
|
const selection = snapshot.context.selection;
|
|
6977
|
-
return !selection ||
|
|
6956
|
+
return !selection || util_isSelectionCollapsed.isSelectionCollapsed(selection) ? !1 : {
|
|
6978
6957
|
selection
|
|
6979
6958
|
};
|
|
6980
6959
|
},
|
|
@@ -6993,12 +6972,12 @@ const coreDndBehaviors = [
|
|
|
6993
6972
|
snapshot
|
|
6994
6973
|
}) => {
|
|
6995
6974
|
const selection = snapshot.context.selection;
|
|
6996
|
-
if (!selection || !
|
|
6975
|
+
if (!selection || !util_isSelectionCollapsed.isSelectionCollapsed(selection))
|
|
6997
6976
|
return !1;
|
|
6998
|
-
const selectionStartPoint = util_sliceBlocks.getSelectionStartPoint(selection), focusTextBlock =
|
|
6977
|
+
const selectionStartPoint = util_sliceBlocks.getSelectionStartPoint(selection), focusTextBlock = selector_getFocusSpan.getFocusTextBlock(snapshot);
|
|
6999
6978
|
if (!focusTextBlock)
|
|
7000
6979
|
return !1;
|
|
7001
|
-
const blockEndPoint =
|
|
6980
|
+
const blockEndPoint = util_isSelectionCollapsed.getBlockEndPoint({
|
|
7002
6981
|
context: snapshot.context,
|
|
7003
6982
|
block: focusTextBlock
|
|
7004
6983
|
}), newTextBlockSelection = {
|
|
@@ -7026,7 +7005,7 @@ const coreDndBehaviors = [
|
|
|
7026
7005
|
actions: [(_, {
|
|
7027
7006
|
newTextBlock,
|
|
7028
7007
|
newTextBlockSelection
|
|
7029
|
-
}) =>
|
|
7008
|
+
}) => util_isSelectionCollapsed.isSelectionCollapsed(newTextBlockSelection) ? [behaviors_index.raise({
|
|
7030
7009
|
type: "insert.block",
|
|
7031
7010
|
block: newTextBlock,
|
|
7032
7011
|
placement: "after",
|
|
@@ -7163,7 +7142,7 @@ const coreDndBehaviors = [
|
|
|
7163
7142
|
guard: ({
|
|
7164
7143
|
snapshot
|
|
7165
7144
|
}) => {
|
|
7166
|
-
const focusSpan =
|
|
7145
|
+
const focusSpan = selector_getFocusSpan.getFocusSpan(snapshot), selectionCollapsed = selector_getFocusSpan.isSelectionCollapsed(snapshot);
|
|
7167
7146
|
return focusSpan && selectionCollapsed;
|
|
7168
7147
|
},
|
|
7169
7148
|
actions: []
|
|
@@ -7182,7 +7161,7 @@ const coreDndBehaviors = [
|
|
|
7182
7161
|
guard: ({
|
|
7183
7162
|
snapshot
|
|
7184
7163
|
}) => {
|
|
7185
|
-
const focusSpan =
|
|
7164
|
+
const focusSpan = selector_getFocusSpan.getFocusSpan(snapshot), selectionCollapsed = selector_getFocusSpan.isSelectionCollapsed(snapshot);
|
|
7186
7165
|
return focusSpan && selectionCollapsed;
|
|
7187
7166
|
},
|
|
7188
7167
|
actions: []
|
|
@@ -7248,8 +7227,8 @@ const coreDndBehaviors = [
|
|
|
7248
7227
|
snapshot,
|
|
7249
7228
|
event
|
|
7250
7229
|
}) => {
|
|
7251
|
-
if (
|
|
7252
|
-
const activeDecorators = snapshot
|
|
7230
|
+
if (selector_getFocusSpan.getFocusTextBlock(snapshot) && event.mimeType === "text/plain" && event.originEvent.type === "clipboard.paste") {
|
|
7231
|
+
const activeDecorators = selector_isSelectingEntireBlocks.getActiveDecorators(snapshot);
|
|
7253
7232
|
return {
|
|
7254
7233
|
activeAnnotations: selector_isSelectingEntireBlocks.getActiveAnnotations(snapshot),
|
|
7255
7234
|
activeDecorators,
|
|
@@ -7315,7 +7294,7 @@ const coreDndBehaviors = [
|
|
|
7315
7294
|
on: "clipboard.paste",
|
|
7316
7295
|
guard: ({
|
|
7317
7296
|
snapshot
|
|
7318
|
-
}) => snapshot.context.selection &&
|
|
7297
|
+
}) => snapshot.context.selection && selector_getFocusSpan.isSelectionExpanded(snapshot) ? {
|
|
7319
7298
|
selection: snapshot.context.selection
|
|
7320
7299
|
} : !1,
|
|
7321
7300
|
actions: [({
|
|
@@ -7625,17 +7604,7 @@ function createEditorSnapshot({
|
|
|
7625
7604
|
return {
|
|
7626
7605
|
blockIndexMap: editor.blockIndexMap,
|
|
7627
7606
|
context,
|
|
7628
|
-
|
|
7629
|
-
activeAnnotations: getActiveAnnotations({
|
|
7630
|
-
markState: editor.markState,
|
|
7631
|
-
schema: schema2
|
|
7632
|
-
}),
|
|
7633
|
-
activeDecorators: getActiveDecorators({
|
|
7634
|
-
decoratorState: editor.decoratorState,
|
|
7635
|
-
markState: editor.markState,
|
|
7636
|
-
schema: schema2
|
|
7637
|
-
})
|
|
7638
|
-
}
|
|
7607
|
+
decoratorState: editor.decoratorState
|
|
7639
7608
|
};
|
|
7640
7609
|
}
|
|
7641
7610
|
const debug$7 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
@@ -8601,16 +8570,19 @@ function createEditableAPI(editor, editorActor) {
|
|
|
8601
8570
|
editor
|
|
8602
8571
|
});
|
|
8603
8572
|
},
|
|
8604
|
-
isMarkActive: (mark) =>
|
|
8605
|
-
editorActorSnapshot: editorActor.getSnapshot(),
|
|
8606
|
-
slateEditorInstance: editor
|
|
8607
|
-
}).beta.activeDecorators.includes(mark),
|
|
8608
|
-
marks: () => {
|
|
8573
|
+
isMarkActive: (mark) => {
|
|
8609
8574
|
const snapshot = getEditorSnapshot({
|
|
8610
8575
|
editorActorSnapshot: editorActor.getSnapshot(),
|
|
8611
8576
|
slateEditorInstance: editor
|
|
8612
8577
|
});
|
|
8613
|
-
return
|
|
8578
|
+
return selector_isSelectingEntireBlocks.getActiveDecorators(snapshot).includes(mark);
|
|
8579
|
+
},
|
|
8580
|
+
marks: () => {
|
|
8581
|
+
const snapshot = getEditorSnapshot({
|
|
8582
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
8583
|
+
slateEditorInstance: editor
|
|
8584
|
+
}), activeAnnotations = selector_isSelectingEntireBlocks.getActiveAnnotationsMarks(snapshot), activeDecorators = selector_isSelectingEntireBlocks.getActiveDecorators(snapshot);
|
|
8585
|
+
return [...activeAnnotations, ...activeDecorators];
|
|
8614
8586
|
},
|
|
8615
8587
|
undo: () => {
|
|
8616
8588
|
editorActor.send({
|
|
@@ -8631,7 +8603,14 @@ function createEditableAPI(editor, editorActor) {
|
|
|
8631
8603
|
});
|
|
8632
8604
|
},
|
|
8633
8605
|
select: (selection) => {
|
|
8634
|
-
const slateSelection = toSlateRange(
|
|
8606
|
+
const slateSelection = toSlateRange({
|
|
8607
|
+
context: {
|
|
8608
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
8609
|
+
value: editor.value,
|
|
8610
|
+
selection
|
|
8611
|
+
},
|
|
8612
|
+
blockIndexMap: editor.blockIndexMap
|
|
8613
|
+
});
|
|
8635
8614
|
slateSelection ? slate.Transforms.select(editor, slateSelection) : slate.Transforms.deselect(editor), editor.onChange();
|
|
8636
8615
|
},
|
|
8637
8616
|
focusBlock: () => {
|
|
@@ -8737,15 +8716,22 @@ function createEditableAPI(editor, editorActor) {
|
|
|
8737
8716
|
isVoid: (element) => ![types2.block.name, types2.span.name].includes(element._type),
|
|
8738
8717
|
findByPath: (path) => {
|
|
8739
8718
|
const slatePath = toSlateRange({
|
|
8740
|
-
|
|
8741
|
-
|
|
8742
|
-
|
|
8719
|
+
context: {
|
|
8720
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
8721
|
+
value: editor.value,
|
|
8722
|
+
selection: {
|
|
8723
|
+
focus: {
|
|
8724
|
+
path,
|
|
8725
|
+
offset: 0
|
|
8726
|
+
},
|
|
8727
|
+
anchor: {
|
|
8728
|
+
path,
|
|
8729
|
+
offset: 0
|
|
8730
|
+
}
|
|
8731
|
+
}
|
|
8743
8732
|
},
|
|
8744
|
-
|
|
8745
|
-
|
|
8746
|
-
offset: 0
|
|
8747
|
-
}
|
|
8748
|
-
}, editor);
|
|
8733
|
+
blockIndexMap: editor.blockIndexMap
|
|
8734
|
+
});
|
|
8749
8735
|
if (slatePath) {
|
|
8750
8736
|
const [block, blockPath] = slate.Editor.node(editor, slatePath.focus.path.slice(0, 1));
|
|
8751
8737
|
if (block && blockPath && typeof block._key == "string") {
|
|
@@ -8827,7 +8813,14 @@ function createEditableAPI(editor, editorActor) {
|
|
|
8827
8813
|
},
|
|
8828
8814
|
delete: (selection, options) => {
|
|
8829
8815
|
if (selection) {
|
|
8830
|
-
const range = toSlateRange(
|
|
8816
|
+
const range = toSlateRange({
|
|
8817
|
+
context: {
|
|
8818
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
8819
|
+
value: editor.value,
|
|
8820
|
+
selection
|
|
8821
|
+
},
|
|
8822
|
+
blockIndexMap: editor.blockIndexMap
|
|
8823
|
+
});
|
|
8831
8824
|
if (!(range && range.anchor.path.length > 0 && range.focus.path.length > 0))
|
|
8832
8825
|
throw new Error("Invalid range");
|
|
8833
8826
|
if (range) {
|
|
@@ -8888,7 +8881,21 @@ function createEditableAPI(editor, editorActor) {
|
|
|
8888
8881
|
},
|
|
8889
8882
|
getFragment: () => fromSlateValue(editor.getFragment(), types2.block.name),
|
|
8890
8883
|
isSelectionsOverlapping: (selectionA, selectionB) => {
|
|
8891
|
-
const rangeA = toSlateRange(
|
|
8884
|
+
const rangeA = toSlateRange({
|
|
8885
|
+
context: {
|
|
8886
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
8887
|
+
value: editor.value,
|
|
8888
|
+
selection: selectionA
|
|
8889
|
+
},
|
|
8890
|
+
blockIndexMap: editor.blockIndexMap
|
|
8891
|
+
}), rangeB = toSlateRange({
|
|
8892
|
+
context: {
|
|
8893
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
8894
|
+
value: editor.value,
|
|
8895
|
+
selection: selectionB
|
|
8896
|
+
},
|
|
8897
|
+
blockIndexMap: editor.blockIndexMap
|
|
8898
|
+
});
|
|
8892
8899
|
return slate.Range.isRange(rangeA) && slate.Range.isRange(rangeB) && slate.Range.includes(rangeA, rangeB);
|
|
8893
8900
|
}
|
|
8894
8901
|
};
|
|
@@ -10856,7 +10863,14 @@ const slateOperationCallback = ({
|
|
|
10856
10863
|
}) => {
|
|
10857
10864
|
const rangeDecorationState = [];
|
|
10858
10865
|
for (const rangeDecoration of context.pendingRangeDecorations) {
|
|
10859
|
-
const slateRange = toSlateRange(
|
|
10866
|
+
const slateRange = toSlateRange({
|
|
10867
|
+
context: {
|
|
10868
|
+
schema: context.schema,
|
|
10869
|
+
value: context.slateEditor.value,
|
|
10870
|
+
selection: rangeDecoration.selection
|
|
10871
|
+
},
|
|
10872
|
+
blockIndexMap: context.slateEditor.blockIndexMap
|
|
10873
|
+
});
|
|
10860
10874
|
if (!slate.Range.isRange(slateRange)) {
|
|
10861
10875
|
rangeDecoration.onMoved?.({
|
|
10862
10876
|
newSelection: null,
|
|
@@ -10880,7 +10894,14 @@ const slateOperationCallback = ({
|
|
|
10880
10894
|
return;
|
|
10881
10895
|
const rangeDecorationState = [];
|
|
10882
10896
|
for (const rangeDecoration of event.rangeDecorations) {
|
|
10883
|
-
const slateRange = toSlateRange(
|
|
10897
|
+
const slateRange = toSlateRange({
|
|
10898
|
+
context: {
|
|
10899
|
+
schema: context.schema,
|
|
10900
|
+
value: context.slateEditor.value,
|
|
10901
|
+
selection: rangeDecoration.selection
|
|
10902
|
+
},
|
|
10903
|
+
blockIndexMap: context.slateEditor.blockIndexMap
|
|
10904
|
+
});
|
|
10884
10905
|
if (!slate.Range.isRange(slateRange)) {
|
|
10885
10906
|
rangeDecoration.onMoved?.({
|
|
10886
10907
|
newSelection: null,
|
|
@@ -10904,7 +10925,14 @@ const slateOperationCallback = ({
|
|
|
10904
10925
|
return;
|
|
10905
10926
|
const rangeDecorationState = [];
|
|
10906
10927
|
for (const decoratedRange of context.slateEditor.decoratedRanges) {
|
|
10907
|
-
const slateRange = toSlateRange(
|
|
10928
|
+
const slateRange = toSlateRange({
|
|
10929
|
+
context: {
|
|
10930
|
+
schema: context.schema,
|
|
10931
|
+
value: context.slateEditor.value,
|
|
10932
|
+
selection: decoratedRange.rangeDecoration.selection
|
|
10933
|
+
},
|
|
10934
|
+
blockIndexMap: context.slateEditor.blockIndexMap
|
|
10935
|
+
});
|
|
10908
10936
|
if (!slate.Range.isRange(slateRange)) {
|
|
10909
10937
|
decoratedRange.rangeDecoration.onMoved?.({
|
|
10910
10938
|
newSelection: null,
|
|
@@ -11158,7 +11186,14 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
11158
11186
|
const normalizedSelection = normalizeSelection(propsSelection, fromSlateValue(slateEditor.children, editorActor.getSnapshot().context.schema.block.name));
|
|
11159
11187
|
if (normalizedSelection !== null) {
|
|
11160
11188
|
debug(`Normalized selection from props ${JSON.stringify(normalizedSelection)}`);
|
|
11161
|
-
const slateRange = toSlateRange(
|
|
11189
|
+
const slateRange = toSlateRange({
|
|
11190
|
+
context: {
|
|
11191
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
11192
|
+
value: slateEditor.value,
|
|
11193
|
+
selection: normalizedSelection
|
|
11194
|
+
},
|
|
11195
|
+
blockIndexMap: slateEditor.blockIndexMap
|
|
11196
|
+
});
|
|
11162
11197
|
slateRange && (slate.Transforms.select(slateEditor, slateRange), slateEditor.operations.some((o) => o.type === "set_selection") || editorActor.send({
|
|
11163
11198
|
type: "update selection",
|
|
11164
11199
|
selection: normalizedSelection
|