@portabletext/editor 1.50.7 → 1.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/{util.slice-blocks.cjs → selection-point.cjs} +26 -18
- package/lib/_chunks-cjs/selection-point.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.get-text-before.cjs +13 -10
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +46 -46
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs +21 -17
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -1
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs +10 -10
- 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 +5 -5
- package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +1 -1
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs +3 -3
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +7 -14
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-es/{util.slice-blocks.js → selection-point.js} +26 -18
- package/lib/_chunks-es/selection-point.js.map +1 -0
- package/lib/_chunks-es/selector.get-text-before.js +13 -10
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +21 -21
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/selector.is-selection-expanded.js +14 -10
- package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -1
- package/lib/_chunks-es/util.child-selection-point-to-block-offset.js +2 -2
- package/lib/_chunks-es/util.child-selection-point-to-block-offset.js.map +1 -1
- package/lib/_chunks-es/util.is-equal-selection-points.js +1 -1
- package/lib/_chunks-es/util.merge-text-blocks.js +1 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js +4 -11
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
- package/lib/behaviors/index.d.cts +1 -2007
- package/lib/behaviors/index.d.ts +1 -2007
- package/lib/index.cjs +130 -146
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +1 -3
- package/lib/index.d.ts +1 -3
- package/lib/index.js +63 -79
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +11 -11
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +6 -1981
- package/lib/plugins/index.d.ts +6 -1981
- package/lib/plugins/index.js +1 -1
- package/lib/selectors/index.cjs +17 -27
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +5 -2645
- package/lib/selectors/index.d.ts +5 -2645
- package/lib/selectors/index.js +13 -23
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +25 -14
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +0 -2633
- package/lib/utils/index.d.ts +0 -2633
- package/lib/utils/index.js +14 -3
- package/lib/utils/index.js.map +1 -1
- package/package.json +18 -18
- package/src/behaviors/behavior.abstract.delete.ts +0 -1
- package/src/behaviors/behavior.abstract.insert.ts +8 -8
- package/src/behaviors/behavior.types.event.ts +1 -0
- package/src/converters/converter.portable-text.ts +1 -1
- package/src/converters/converter.text-plain.ts +2 -2
- package/src/editor/editor-machine.ts +0 -2
- package/src/editor/editor-selector.ts +0 -1
- package/src/editor/editor-snapshot.ts +0 -5
- package/src/editor/mutation-machine.ts +52 -63
- package/src/internal-utils/applyPatch.ts +2 -1
- package/src/internal-utils/create-test-snapshot.ts +0 -1
- package/src/internal-utils/event-position.ts +3 -5
- package/src/internal-utils/selection-block-keys.ts +7 -7
- package/src/internal-utils/selection-focus-text.ts +13 -9
- package/src/internal-utils/selection-text.ts +9 -78
- package/src/internal-utils/terse-pt.test.ts +108 -26
- package/src/internal-utils/terse-pt.ts +132 -14
- package/src/operations/behavior.operation.decorator.add.ts +0 -1
- package/src/operations/behavior.operation.delete.ts +18 -13
- package/src/operations/behavior.operation.insert.block.ts +5 -1
- package/src/selection/selection-point.ts +22 -0
- package/src/selectors/index.ts +1 -1
- package/src/selectors/selector.get-anchor-block.ts +6 -6
- package/src/selectors/selector.get-anchor-child.ts +6 -6
- package/src/selectors/selector.get-list-state.test.ts +14 -27
- package/src/selectors/selector.get-list-state.ts +9 -27
- package/src/selectors/selector.get-selected-spans.ts +16 -19
- package/src/selectors/selector.get-selected-text-blocks.ts +11 -19
- package/src/selectors/selector.get-selection-end-block.ts +30 -0
- package/src/selectors/selector.get-selection-start-block.ts +30 -0
- package/src/selectors/selector.get-text-before.ts +15 -16
- package/src/selectors/selector.get-trimmed-selection.ts +15 -21
- package/src/selectors/selector.is-point-after-selection.ts +11 -19
- package/src/selectors/selector.is-point-before-selection.ts +11 -19
- package/src/selectors/selectors.ts +23 -39
- package/src/utils/util.block-offset.ts +6 -7
- package/src/utils/util.child-selection-point-to-block-offset.ts +6 -7
- package/src/utils/util.selection-point-to-block-offset.ts +5 -6
- package/src/utils/util.slice-blocks.ts +11 -20
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +0 -1
- package/lib/_chunks-es/util.slice-blocks.js.map +0 -1
- package/src/internal-utils/inline-object-selection.ts +0 -115
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$h = require("debug"), util_isEqualSelectionPoints = require("./_chunks-cjs/util.is-equal-selection-points.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$h = require("debug"), util_isEqualSelectionPoints = require("./_chunks-cjs/util.is-equal-selection-points.cjs"), selectionPoint = require("./_chunks-cjs/selection-point.cjs"), selector_isSelectionExpanded = require("./_chunks-cjs/selector.is-selection-expanded.cjs"), selector_isSelectingEntireBlocks = require("./_chunks-cjs/selector.is-selecting-entire-blocks.cjs"), slateDom = require("slate-dom"), util_selectionPointToBlockOffset = require("./_chunks-cjs/util.selection-point-to-block-offset.cjs"), isEqual = require("lodash/isEqual.js"), types = require("@sanity/types"), 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"), util_childSelectionPointToBlockOffset = require("./_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), patches = require("@portabletext/patches"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), immer = require("immer"), 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
|
}
|
|
@@ -65,7 +65,7 @@ function getDragSelection({
|
|
|
65
65
|
}
|
|
66
66
|
});
|
|
67
67
|
draggingCollapsedSelection && draggedTextBlock && draggedSpan && (dragSelection = {
|
|
68
|
-
anchor:
|
|
68
|
+
anchor: selectionPoint.getBlockStartPoint({
|
|
69
69
|
context: snapshot.context,
|
|
70
70
|
block: draggedTextBlock
|
|
71
71
|
}),
|
|
@@ -79,7 +79,7 @@ function getDragSelection({
|
|
|
79
79
|
const selectionStartBlock = selector_isSelectionExpanded.getSelectionStartBlock(snapshot), selectionEndBlock = selector_isSelectionExpanded.getSelectionEndBlock(snapshot);
|
|
80
80
|
if (!selectionStartBlock || !selectionEndBlock)
|
|
81
81
|
return dragSelection;
|
|
82
|
-
const selectionStartPoint =
|
|
82
|
+
const selectionStartPoint = selectionPoint.getBlockStartPoint({
|
|
83
83
|
context: snapshot.context,
|
|
84
84
|
block: selectionStartBlock
|
|
85
85
|
}), selectionEndPoint = util_isEqualSelectionPoints.getBlockEndPoint({
|
|
@@ -486,7 +486,7 @@ function getEventPosition({
|
|
|
486
486
|
block: positionBlock,
|
|
487
487
|
isEditor: !1,
|
|
488
488
|
selection: {
|
|
489
|
-
anchor:
|
|
489
|
+
anchor: selectionPoint.getBlockStartPoint({
|
|
490
490
|
context: editorActor.getSnapshot().context,
|
|
491
491
|
block: {
|
|
492
492
|
node: block,
|
|
@@ -508,13 +508,13 @@ function getEventPosition({
|
|
|
508
508
|
};
|
|
509
509
|
if (!positionBlock || !selection)
|
|
510
510
|
return;
|
|
511
|
-
const
|
|
512
|
-
if (focusBlockKey)
|
|
511
|
+
const focusBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(selection.focus);
|
|
512
|
+
if (focusBlockKey !== void 0)
|
|
513
513
|
return util_selectionPointToBlockOffset.isSelectionCollapsed(selection) && block && focusBlockKey !== block._key ? {
|
|
514
514
|
block: positionBlock,
|
|
515
515
|
isEditor: !1,
|
|
516
516
|
selection: {
|
|
517
|
-
anchor:
|
|
517
|
+
anchor: selectionPoint.getBlockStartPoint({
|
|
518
518
|
context: editorActor.getSnapshot().context,
|
|
519
519
|
block: {
|
|
520
520
|
node: block,
|
|
@@ -1025,7 +1025,7 @@ function RenderElement(props) {
|
|
|
1025
1025
|
let t02;
|
|
1026
1026
|
if ($[0] !== props.element || $[1] !== schema2) {
|
|
1027
1027
|
let t13;
|
|
1028
|
-
$[3] !== props.element ? (t13 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[3] = props.element, $[4] = t13) : t13 = $[4], t02 =
|
|
1028
|
+
$[3] !== props.element ? (t13 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[3] = props.element, $[4] = t13) : t13 = $[4], t02 = selectionPoint.parseInlineObject({
|
|
1029
1029
|
context: {
|
|
1030
1030
|
keyGenerator: _temp2,
|
|
1031
1031
|
schema: schema2
|
|
@@ -1053,7 +1053,7 @@ function RenderElement(props) {
|
|
|
1053
1053
|
return $[9] !== props.attributes || $[10] !== props.children || $[11] !== props.element || $[12] !== props.readOnly || $[13] !== props.renderChild || $[14] !== t12 ? (t22 = /* @__PURE__ */ jsxRuntime.jsx(RenderInlineObject, { attributes: props.attributes, element: props.element, inlineObject: t12, readOnly: props.readOnly, renderChild: props.renderChild, children: props.children }), $[9] = props.attributes, $[10] = props.children, $[11] = props.element, $[12] = props.readOnly, $[13] = props.renderChild, $[14] = t12, $[15] = t22) : t22 = $[15], t22;
|
|
1054
1054
|
}
|
|
1055
1055
|
let t0;
|
|
1056
|
-
$[16] !== props.element || $[17] !== schema2 ? (t0 =
|
|
1056
|
+
$[16] !== props.element || $[17] !== schema2 ? (t0 = selectionPoint.parseTextBlock({
|
|
1057
1057
|
context: {
|
|
1058
1058
|
keyGenerator: _temp3,
|
|
1059
1059
|
schema: schema2
|
|
@@ -1072,7 +1072,7 @@ function RenderElement(props) {
|
|
|
1072
1072
|
let t1;
|
|
1073
1073
|
if ($[29] !== props.element || $[30] !== schema2) {
|
|
1074
1074
|
let t22;
|
|
1075
|
-
$[32] !== props.element ? (t22 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[32] = props.element, $[33] = t22) : t22 = $[33], t1 =
|
|
1075
|
+
$[32] !== props.element ? (t22 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[32] = props.element, $[33] = t22) : t22 = $[33], t1 = selectionPoint.parseBlockObject({
|
|
1076
1076
|
context: {
|
|
1077
1077
|
keyGenerator: _temp4,
|
|
1078
1078
|
schema: schema2
|
|
@@ -1185,7 +1185,7 @@ const converterJson = {
|
|
|
1185
1185
|
originEvent: event.originEvent,
|
|
1186
1186
|
reason: "No selection"
|
|
1187
1187
|
};
|
|
1188
|
-
const blocks =
|
|
1188
|
+
const blocks = selectionPoint.sliceBlocks({
|
|
1189
1189
|
context: {
|
|
1190
1190
|
selection,
|
|
1191
1191
|
schema: snapshot.context.schema
|
|
@@ -1216,7 +1216,7 @@ const converterJson = {
|
|
|
1216
1216
|
reason: "Data is not an array"
|
|
1217
1217
|
};
|
|
1218
1218
|
const parsedBlocks = blocks.flatMap((block) => {
|
|
1219
|
-
const parsedBlock =
|
|
1219
|
+
const parsedBlock = selectionPoint.parseBlock({
|
|
1220
1220
|
context: snapshot.context,
|
|
1221
1221
|
block,
|
|
1222
1222
|
options: {
|
|
@@ -1224,7 +1224,7 @@ const converterJson = {
|
|
|
1224
1224
|
* If we are dragging internally then we would like to keep the
|
|
1225
1225
|
* dropped portable text as is.
|
|
1226
1226
|
*/
|
|
1227
|
-
refreshKeys: !snapshot.beta.
|
|
1227
|
+
refreshKeys: !snapshot.beta.internalDrag,
|
|
1228
1228
|
validateFields: !1
|
|
1229
1229
|
}
|
|
1230
1230
|
});
|
|
@@ -1256,7 +1256,7 @@ function createConverterTextHtml(legacySchema) {
|
|
|
1256
1256
|
originEvent: event.originEvent,
|
|
1257
1257
|
reason: "No selection"
|
|
1258
1258
|
};
|
|
1259
|
-
const blocks =
|
|
1259
|
+
const blocks = selectionPoint.sliceBlocks({
|
|
1260
1260
|
context: {
|
|
1261
1261
|
selection,
|
|
1262
1262
|
schema: snapshot.context.schema
|
|
@@ -1290,7 +1290,7 @@ function createConverterTextHtml(legacySchema) {
|
|
|
1290
1290
|
keyGenerator: snapshot.context.keyGenerator,
|
|
1291
1291
|
unstable_whitespaceOnPasteMode: legacySchema.block.options.unstable_whitespaceOnPasteMode
|
|
1292
1292
|
}).flatMap((block) => {
|
|
1293
|
-
const parsedBlock =
|
|
1293
|
+
const parsedBlock = selectionPoint.parseBlock({
|
|
1294
1294
|
context: snapshot.context,
|
|
1295
1295
|
block,
|
|
1296
1296
|
options: {
|
|
@@ -1322,13 +1322,13 @@ function createConverterTextPlain(legacySchema) {
|
|
|
1322
1322
|
const selection = snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection;
|
|
1323
1323
|
return selection ? {
|
|
1324
1324
|
type: "serialization.success",
|
|
1325
|
-
data:
|
|
1325
|
+
data: selectionPoint.sliceBlocks({
|
|
1326
1326
|
context: {
|
|
1327
1327
|
selection,
|
|
1328
1328
|
schema: snapshot.context.schema
|
|
1329
1329
|
},
|
|
1330
1330
|
blocks: snapshot.context.value
|
|
1331
|
-
}).map((block) =>
|
|
1331
|
+
}).map((block) => selectionPoint.isTextBlock(snapshot.context, block) ? block.children.map((child) => child._type === snapshot.context.schema.span.name ? child.text : snapshot.beta.internalDrag ? `[${snapshot.context.schema.inlineObjects.find((inlineObjectType) => inlineObjectType.name === child._type)?.title ?? "Object"}]` : "").join("") : snapshot.beta.internalDrag ? `[${snapshot.context.schema.blockObjects.find((blockObjectType) => blockObjectType.name === block._type)?.title ?? "Object"}]` : "").filter((block) => block !== "").join(`
|
|
1332
1332
|
|
|
1333
1333
|
`),
|
|
1334
1334
|
mimeType: "text/plain",
|
|
@@ -1347,7 +1347,7 @@ function createConverterTextPlain(legacySchema) {
|
|
|
1347
1347
|
const textToHtml = `<html><body>${escapeHtml(event.data).split(/\n{2,}/).map((line) => line ? `<p>${line.replace(/(?:\r\n|\r|\n)/g, "<br/>")}</p>` : "<p></p>").join("")}</body></html>`, parsedBlocks = blockTools.htmlToBlocks(textToHtml, legacySchema.portableText, {
|
|
1348
1348
|
keyGenerator: snapshot.context.keyGenerator
|
|
1349
1349
|
}).flatMap((block) => {
|
|
1350
|
-
const parsedBlock =
|
|
1350
|
+
const parsedBlock = selectionPoint.parseBlock({
|
|
1351
1351
|
context: snapshot.context,
|
|
1352
1352
|
block,
|
|
1353
1353
|
options: {
|
|
@@ -1564,7 +1564,6 @@ function getEditorSnapshot({
|
|
|
1564
1564
|
markState: slateEditorInstance.markState,
|
|
1565
1565
|
schema: editorActorSnapshot.context.schema
|
|
1566
1566
|
}),
|
|
1567
|
-
hasTag: (tag) => editorActorSnapshot.hasTag(tag),
|
|
1568
1567
|
internalDrag: editorActorSnapshot.context.internalDrag
|
|
1569
1568
|
}
|
|
1570
1569
|
};
|
|
@@ -2819,7 +2818,7 @@ const addAnnotationOperationImplementation = ({
|
|
|
2819
2818
|
context,
|
|
2820
2819
|
operation
|
|
2821
2820
|
}) => {
|
|
2822
|
-
const parsedAnnotation =
|
|
2821
|
+
const parsedAnnotation = selectionPoint.parseAnnotation({
|
|
2823
2822
|
annotation: {
|
|
2824
2823
|
_type: operation.annotation.name,
|
|
2825
2824
|
...operation.annotation.value
|
|
@@ -2975,7 +2974,7 @@ const addAnnotationOperationImplementation = ({
|
|
|
2975
2974
|
const {
|
|
2976
2975
|
_type,
|
|
2977
2976
|
...filteredProps
|
|
2978
|
-
} = operation.props, updatedBlock =
|
|
2977
|
+
} = operation.props, updatedBlock = selectionPoint.parseBlock({
|
|
2979
2978
|
context,
|
|
2980
2979
|
block: {
|
|
2981
2980
|
...parsedBlock,
|
|
@@ -3020,8 +3019,8 @@ const addAnnotationOperationImplementation = ({
|
|
|
3020
3019
|
const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(operation.editor)).at(0);
|
|
3021
3020
|
if (!parsedBlock)
|
|
3022
3021
|
throw new Error(`Unable to parse block at ${JSON.stringify(operation.at)}`);
|
|
3023
|
-
if (
|
|
3024
|
-
const propsToRemove = operation.props.filter((prop) => prop !== "_type"), updatedTextBlock =
|
|
3022
|
+
if (selectionPoint.isTextBlock(context, parsedBlock)) {
|
|
3023
|
+
const propsToRemove = operation.props.filter((prop) => prop !== "_type"), updatedTextBlock = selectionPoint.parseBlock({
|
|
3025
3024
|
context,
|
|
3026
3025
|
block: omit__default.default(parsedBlock, propsToRemove),
|
|
3027
3026
|
options: {
|
|
@@ -3039,7 +3038,7 @@ const addAnnotationOperationImplementation = ({
|
|
|
3039
3038
|
});
|
|
3040
3039
|
return;
|
|
3041
3040
|
}
|
|
3042
|
-
const updatedBlockObject =
|
|
3041
|
+
const updatedBlockObject = selectionPoint.parseBlock({
|
|
3043
3042
|
context,
|
|
3044
3043
|
block: omit__default.default(parsedBlock, operation.props.filter((prop) => prop !== "_type")),
|
|
3045
3044
|
options: {
|
|
@@ -3065,14 +3064,14 @@ const addAnnotationOperationImplementation = ({
|
|
|
3065
3064
|
context,
|
|
3066
3065
|
operation
|
|
3067
3066
|
}) => {
|
|
3068
|
-
const editor = operation.editor, mark = operation.decorator, value = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), manualAnchor = operation.at?.anchor ?
|
|
3067
|
+
const editor = operation.editor, mark = operation.decorator, value = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), manualAnchor = operation.at?.anchor ? selectionPoint.blockOffsetToSpanSelectionPoint({
|
|
3069
3068
|
context: {
|
|
3070
3069
|
...context,
|
|
3071
3070
|
value
|
|
3072
3071
|
},
|
|
3073
3072
|
blockOffset: operation.at.anchor,
|
|
3074
3073
|
direction: "backward"
|
|
3075
|
-
}) : void 0, manualFocus = operation.at?.focus ?
|
|
3074
|
+
}) : void 0, manualFocus = operation.at?.focus ? selectionPoint.blockOffsetToSpanSelectionPoint({
|
|
3076
3075
|
context: {
|
|
3077
3076
|
...context,
|
|
3078
3077
|
value
|
|
@@ -3180,12 +3179,12 @@ const addAnnotationOperationImplementation = ({
|
|
|
3180
3179
|
}, deleteOperationImplementation = ({
|
|
3181
3180
|
operation
|
|
3182
3181
|
}) => {
|
|
3183
|
-
const
|
|
3182
|
+
const anchorBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(operation.at.anchor), focusBlockKey = selectionPoint.getBlockKeyFromSelectionPoint(operation.at.focus), anchorBlockPath = anchorBlockKey !== void 0 ? getBlockPath({
|
|
3184
3183
|
editor: operation.editor,
|
|
3185
|
-
_key:
|
|
3186
|
-
}) : void 0, focusBlockPath =
|
|
3184
|
+
_key: anchorBlockKey
|
|
3185
|
+
}) : void 0, focusBlockPath = focusBlockKey !== void 0 ? getBlockPath({
|
|
3187
3186
|
editor: operation.editor,
|
|
3188
|
-
_key:
|
|
3187
|
+
_key: focusBlockKey
|
|
3189
3188
|
}) : void 0;
|
|
3190
3189
|
if (operation.at.anchor.path.length === 1 && operation.at.focus.path.length === 1 && anchorBlockPath && focusBlockPath && anchorBlockPath[0] === focusBlockPath[0]) {
|
|
3191
3190
|
slate.Transforms.removeNodes(operation.editor, {
|
|
@@ -3205,7 +3204,7 @@ const addAnnotationOperationImplementation = ({
|
|
|
3205
3204
|
context,
|
|
3206
3205
|
operation
|
|
3207
3206
|
}) => {
|
|
3208
|
-
const parsedInlineObject =
|
|
3207
|
+
const parsedInlineObject = selectionPoint.parseInlineObject({
|
|
3209
3208
|
context,
|
|
3210
3209
|
inlineObject: {
|
|
3211
3210
|
_type: operation.inlineObject.name,
|
|
@@ -3275,7 +3274,7 @@ const addAnnotationOperationImplementation = ({
|
|
|
3275
3274
|
context,
|
|
3276
3275
|
operation
|
|
3277
3276
|
}) => {
|
|
3278
|
-
const parsedBlock =
|
|
3277
|
+
const parsedBlock = selectionPoint.parseBlock({
|
|
3279
3278
|
block: operation.block,
|
|
3280
3279
|
context,
|
|
3281
3280
|
options: {
|
|
@@ -3322,8 +3321,7 @@ function insertBlock({
|
|
|
3322
3321
|
else if (placement === "after") {
|
|
3323
3322
|
const nextPath = lastBlockPath ? [lastBlockPath[0] + 1] : [0];
|
|
3324
3323
|
slate.Transforms.insertNodes(editor, [block], {
|
|
3325
|
-
at: nextPath
|
|
3326
|
-
select: !1
|
|
3324
|
+
at: nextPath
|
|
3327
3325
|
}), select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, nextPath)) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, nextPath));
|
|
3328
3326
|
} else {
|
|
3329
3327
|
if (lastBlock && isEqualToEmptyEditor([lastBlock], schema2)) {
|
|
@@ -3436,7 +3434,9 @@ function insertBlock({
|
|
|
3436
3434
|
editor
|
|
3437
3435
|
});
|
|
3438
3436
|
if (focusChild && editor.isTextSpan(focusChild))
|
|
3439
|
-
slate.Transforms.
|
|
3437
|
+
slate.Transforms.splitNodes(editor, {
|
|
3438
|
+
at: currentSelection2
|
|
3439
|
+
}), slate.Transforms.insertFragment(editor, [block], {
|
|
3440
3440
|
at: currentSelection2
|
|
3441
3441
|
}), select === "start" || select === "end" ? slate.Transforms.select(editor, [endBlockPath[0] + 1]) : slate.Transforms.select(editor, currentSelection2);
|
|
3442
3442
|
else {
|
|
@@ -4187,7 +4187,7 @@ function unsetPatch(editor, patch) {
|
|
|
4187
4187
|
const newNode = patches.applyAll(child.node, [{
|
|
4188
4188
|
...patch,
|
|
4189
4189
|
path: propPath
|
|
4190
|
-
}]), removedProperties = Object.keys(child.node).filter((property) =>
|
|
4190
|
+
}]), newKeys = Object.keys(newNode), removedProperties = Object.keys(child.node).filter((property) => !newKeys.includes(property));
|
|
4191
4191
|
return slate.Transforms.unsetNodes(editor, removedProperties, {
|
|
4192
4192
|
at: [block.index, child.index]
|
|
4193
4193
|
}), !0;
|
|
@@ -4212,7 +4212,7 @@ function unsetPatch(editor, patch) {
|
|
|
4212
4212
|
function findBlock(children, path) {
|
|
4213
4213
|
let blockIndex = -1;
|
|
4214
4214
|
const block = children.find((node, index) => {
|
|
4215
|
-
const isMatch =
|
|
4215
|
+
const isMatch = selectionPoint.isKeyedSegment(path[0]) ? node._key === path[0]._key : index === path[0];
|
|
4216
4216
|
return isMatch && (blockIndex = index), isMatch;
|
|
4217
4217
|
});
|
|
4218
4218
|
if (block)
|
|
@@ -4227,7 +4227,7 @@ function findBlockChild(block, path) {
|
|
|
4227
4227
|
return;
|
|
4228
4228
|
let childIndex = -1;
|
|
4229
4229
|
const child = blockNode.children.find((node, index) => {
|
|
4230
|
-
const isMatch =
|
|
4230
|
+
const isMatch = selectionPoint.isKeyedSegment(path[2]) ? node._key === path[2]._key : index === path[2];
|
|
4231
4231
|
return isMatch && (childIndex = index), isMatch;
|
|
4232
4232
|
});
|
|
4233
4233
|
if (child)
|
|
@@ -4237,14 +4237,14 @@ function findBlockChild(block, path) {
|
|
|
4237
4237
|
};
|
|
4238
4238
|
}
|
|
4239
4239
|
function insertTextPatch(schema2, children, operation, beforeValue) {
|
|
4240
|
-
const block =
|
|
4240
|
+
const block = selectionPoint.isTextBlock({
|
|
4241
4241
|
schema: schema2
|
|
4242
4242
|
}, children[operation.path[0]]) && children[operation.path[0]];
|
|
4243
4243
|
if (!block)
|
|
4244
4244
|
throw new Error("Could not find block");
|
|
4245
|
-
const textChild =
|
|
4245
|
+
const textChild = selectionPoint.isTextBlock({
|
|
4246
4246
|
schema: schema2
|
|
4247
|
-
}, block) &&
|
|
4247
|
+
}, block) && selectionPoint.isSpan$1({
|
|
4248
4248
|
schema: schema2
|
|
4249
4249
|
}, block.children[operation.path[1]]) && block.children[operation.path[1]];
|
|
4250
4250
|
if (!textChild)
|
|
@@ -4253,9 +4253,9 @@ function insertTextPatch(schema2, children, operation, beforeValue) {
|
|
|
4253
4253
|
_key: block._key
|
|
4254
4254
|
}, "children", {
|
|
4255
4255
|
_key: textChild._key
|
|
4256
|
-
}, "text"], prevBlock = beforeValue[operation.path[0]], prevChild =
|
|
4256
|
+
}, "text"], prevBlock = beforeValue[operation.path[0]], prevChild = selectionPoint.isTextBlock({
|
|
4257
4257
|
schema: schema2
|
|
4258
|
-
}, prevBlock) && prevBlock.children[operation.path[1]], prevText =
|
|
4258
|
+
}, prevBlock) && prevBlock.children[operation.path[1]], prevText = selectionPoint.isSpan$1({
|
|
4259
4259
|
schema: schema2
|
|
4260
4260
|
}, prevChild) ? prevChild.text : "", patch = patches.diffMatchPatch(prevText, textChild.text, path);
|
|
4261
4261
|
return patch.value.length ? [patch] : [];
|
|
@@ -4264,9 +4264,9 @@ function removeTextPatch(schema2, children, operation, beforeValue) {
|
|
|
4264
4264
|
const block = children[operation.path[0]];
|
|
4265
4265
|
if (!block)
|
|
4266
4266
|
throw new Error("Could not find block");
|
|
4267
|
-
const child =
|
|
4267
|
+
const child = selectionPoint.isTextBlock({
|
|
4268
4268
|
schema: schema2
|
|
4269
|
-
}, block) && block.children[operation.path[1]] || void 0, textChild =
|
|
4269
|
+
}, block) && block.children[operation.path[1]] || void 0, textChild = selectionPoint.isSpan$1({
|
|
4270
4270
|
schema: schema2
|
|
4271
4271
|
}, child) ? child : void 0;
|
|
4272
4272
|
if (child && !textChild)
|
|
@@ -4277,9 +4277,9 @@ function removeTextPatch(schema2, children, operation, beforeValue) {
|
|
|
4277
4277
|
_key: block._key
|
|
4278
4278
|
}, "children", {
|
|
4279
4279
|
_key: textChild._key
|
|
4280
|
-
}, "text"], beforeBlock = beforeValue[operation.path[0]], prevTextChild =
|
|
4280
|
+
}, "text"], beforeBlock = beforeValue[operation.path[0]], prevTextChild = selectionPoint.isTextBlock({
|
|
4281
4281
|
schema: schema2
|
|
4282
|
-
}, beforeBlock) && beforeBlock.children[operation.path[1]], prevText =
|
|
4282
|
+
}, beforeBlock) && beforeBlock.children[operation.path[1]], prevText = selectionPoint.isSpan$1({
|
|
4283
4283
|
schema: schema2
|
|
4284
4284
|
}, prevTextChild) && prevTextChild.text, patch = patches.diffMatchPatch(prevText || "", textChild.text, path);
|
|
4285
4285
|
return patch.value ? [patch] : [];
|
|
@@ -4298,7 +4298,7 @@ function setNodePatch(schema2, children, operation) {
|
|
|
4298
4298
|
}])];
|
|
4299
4299
|
} else if (operation.path.length === 2) {
|
|
4300
4300
|
const block = children[operation.path[0]];
|
|
4301
|
-
if (
|
|
4301
|
+
if (selectionPoint.isTextBlock({
|
|
4302
4302
|
schema: schema2
|
|
4303
4303
|
}, block)) {
|
|
4304
4304
|
const child = block.children[operation.path[1]];
|
|
@@ -4333,7 +4333,7 @@ function insertNodePatch(schema2, children, operation, beforeValue) {
|
|
|
4333
4333
|
return targetKey ? [patches.insert([fromSlateValue([operation.node], schema2.block.name)[0]], position, [{
|
|
4334
4334
|
_key: targetKey
|
|
4335
4335
|
}])] : [patches.setIfMissing(beforeValue, []), patches.insert([fromSlateValue([operation.node], schema2.block.name)[0]], "before", [operation.path[0]])];
|
|
4336
|
-
} else if (
|
|
4336
|
+
} else if (selectionPoint.isTextBlock({
|
|
4337
4337
|
schema: schema2
|
|
4338
4338
|
}, block) && operation.path.length === 2 && children[operation.path[0]]) {
|
|
4339
4339
|
const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node = {
|
|
@@ -4355,13 +4355,13 @@ function insertNodePatch(schema2, children, operation, beforeValue) {
|
|
|
4355
4355
|
}
|
|
4356
4356
|
function splitNodePatch(schema2, children, operation, beforeValue) {
|
|
4357
4357
|
const patches$1 = [], splitBlock = children[operation.path[0]];
|
|
4358
|
-
if (!
|
|
4358
|
+
if (!selectionPoint.isTextBlock({
|
|
4359
4359
|
schema: schema2
|
|
4360
4360
|
}, splitBlock))
|
|
4361
4361
|
throw new Error(`Block with path ${JSON.stringify(operation.path[0])} is not a text block and can't be split`);
|
|
4362
4362
|
if (operation.path.length === 1) {
|
|
4363
4363
|
const oldBlock = beforeValue[operation.path[0]];
|
|
4364
|
-
if (
|
|
4364
|
+
if (selectionPoint.isTextBlock({
|
|
4365
4365
|
schema: schema2
|
|
4366
4366
|
}, oldBlock)) {
|
|
4367
4367
|
const targetValue = fromSlateValue([children[operation.path[0] + 1]], schema2.block.name)[0];
|
|
@@ -4380,7 +4380,7 @@ function splitNodePatch(schema2, children, operation, beforeValue) {
|
|
|
4380
4380
|
}
|
|
4381
4381
|
if (operation.path.length === 2) {
|
|
4382
4382
|
const splitSpan = splitBlock.children[operation.path[1]];
|
|
4383
|
-
if (
|
|
4383
|
+
if (selectionPoint.isSpan$1({
|
|
4384
4384
|
schema: schema2
|
|
4385
4385
|
}, splitSpan)) {
|
|
4386
4386
|
const targetSpans = fromSlateValue([{
|
|
@@ -4409,7 +4409,7 @@ function removeNodePatch(schema2, beforeValue, operation) {
|
|
|
4409
4409
|
_key: block._key
|
|
4410
4410
|
}])];
|
|
4411
4411
|
throw new Error("Block not found");
|
|
4412
|
-
} else if (
|
|
4412
|
+
} else if (selectionPoint.isTextBlock({
|
|
4413
4413
|
schema: schema2
|
|
4414
4414
|
}, block) && operation.path.length === 2) {
|
|
4415
4415
|
const spanToRemove = block.children[operation.path[1]];
|
|
@@ -4433,14 +4433,14 @@ function mergeNodePatch(schema2, children, operation, beforeValue) {
|
|
|
4433
4433
|
}]));
|
|
4434
4434
|
} else
|
|
4435
4435
|
throw new Error("Target key not found!");
|
|
4436
|
-
else if (
|
|
4436
|
+
else if (selectionPoint.isTextBlock({
|
|
4437
4437
|
schema: schema2
|
|
4438
|
-
}, block) &&
|
|
4438
|
+
}, block) && selectionPoint.isTextBlock({
|
|
4439
4439
|
schema: schema2
|
|
4440
4440
|
}, updatedBlock) && operation.path.length === 2) {
|
|
4441
|
-
const updatedSpan = updatedBlock.children[operation.path[1] - 1] &&
|
|
4441
|
+
const updatedSpan = updatedBlock.children[operation.path[1] - 1] && selectionPoint.isSpan$1({
|
|
4442
4442
|
schema: schema2
|
|
4443
|
-
}, updatedBlock.children[operation.path[1] - 1]) ? updatedBlock.children[operation.path[1] - 1] : void 0, removedSpan = block.children[operation.path[1]] &&
|
|
4443
|
+
}, updatedBlock.children[operation.path[1] - 1]) ? updatedBlock.children[operation.path[1] - 1] : void 0, removedSpan = block.children[operation.path[1]] && selectionPoint.isSpan$1({
|
|
4444
4444
|
schema: schema2
|
|
4445
4445
|
}, block.children[operation.path[1]]) ? block.children[operation.path[1]] : void 0;
|
|
4446
4446
|
updatedSpan && (block.children.filter((span) => span._key === updatedSpan._key).length === 1 ? patches$1.push(patches.set(updatedSpan.text, [{
|
|
@@ -4466,9 +4466,9 @@ function moveNodePatch(schema2, beforeValue, operation) {
|
|
|
4466
4466
|
}])), patches$1.push(patches.insert([fromSlateValue([block], schema2.block.name)[0]], position, [{
|
|
4467
4467
|
_key: targetBlock._key
|
|
4468
4468
|
}]));
|
|
4469
|
-
} else if (operation.path.length === 2 &&
|
|
4469
|
+
} else if (operation.path.length === 2 && selectionPoint.isTextBlock({
|
|
4470
4470
|
schema: schema2
|
|
4471
|
-
}, block) &&
|
|
4471
|
+
}, block) && selectionPoint.isTextBlock({
|
|
4472
4472
|
schema: schema2
|
|
4473
4473
|
}, targetBlock)) {
|
|
4474
4474
|
const child = block.children[operation.path[1]], targetChild = targetBlock.children[operation.newPath[1]], position = operation.newPath[1] === targetBlock.children.length ? "after" : "before", childToInsert = fromSlateValue([block], schema2.block.name)[0].children[operation.path[1]];
|
|
@@ -4695,7 +4695,7 @@ function createWithSchemaTypes({
|
|
|
4695
4695
|
editorActor
|
|
4696
4696
|
}) {
|
|
4697
4697
|
return function(editor) {
|
|
4698
|
-
editor.isTextBlock = (value) =>
|
|
4698
|
+
editor.isTextBlock = (value) => selectionPoint.isTextBlock(editorActor.getSnapshot().context, value), editor.isTextSpan = (value) => selectionPoint.isSpan$1(editorActor.getSnapshot().context, value), editor.isListBlock = (value) => selectionPoint.isListBlock(editorActor.getSnapshot().context, value), editor.isVoid = (element) => 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) => editorActor.getSnapshot().context.schema.inlineObjects.map((obj) => obj.name).includes(element._type) && "__inline" in element && element.__inline === !0;
|
|
4699
4699
|
const {
|
|
4700
4700
|
normalizeNode
|
|
4701
4701
|
} = editor;
|
|
@@ -4859,7 +4859,7 @@ function isEditorNode(node) {
|
|
|
4859
4859
|
return typeof node == "object" && node !== null ? !("_type" in node) && "children" in node && Array.isArray(node.children) : !1;
|
|
4860
4860
|
}
|
|
4861
4861
|
function isTextBlockNode(context, node) {
|
|
4862
|
-
return
|
|
4862
|
+
return selectionPoint.isTypedObject(node) && node._type === context.schema.block.name;
|
|
4863
4863
|
}
|
|
4864
4864
|
function isSpanNode(context, node) {
|
|
4865
4865
|
return typeof node != "object" || node === null || "children" in node ? !1 : "_type" in node ? node._type === context.schema.span.name : "text" in node;
|
|
@@ -5444,7 +5444,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
5444
5444
|
snapshot
|
|
5445
5445
|
}) => {
|
|
5446
5446
|
const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot), selectionCollapsed = selector_isSelectionExpanded.isSelectionCollapsed(snapshot), previousBlock = selector_isSelectionExpanded.getPreviousBlock(snapshot);
|
|
5447
|
-
return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : util_isEqualSelectionPoints.isEmptyTextBlock(snapshot.context, focusTextBlock.node) && !
|
|
5447
|
+
return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : util_isEqualSelectionPoints.isEmptyTextBlock(snapshot.context, focusTextBlock.node) && !selectionPoint.isTextBlock(snapshot.context, previousBlock.node) ? {
|
|
5448
5448
|
focusTextBlock,
|
|
5449
5449
|
previousBlock
|
|
5450
5450
|
} : !1;
|
|
@@ -5474,7 +5474,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
5474
5474
|
snapshot
|
|
5475
5475
|
}) => {
|
|
5476
5476
|
const focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot), selectionCollapsed = selector_isSelectionExpanded.isSelectionCollapsed(snapshot), nextBlock = selector_isSelectionExpanded.getNextBlock(snapshot);
|
|
5477
|
-
return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : util_isEqualSelectionPoints.isEmptyTextBlock(snapshot.context, focusTextBlock.node) && !
|
|
5477
|
+
return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : util_isEqualSelectionPoints.isEmptyTextBlock(snapshot.context, focusTextBlock.node) && !selectionPoint.isTextBlock(snapshot.context, nextBlock.node) ? {
|
|
5478
5478
|
focusTextBlock,
|
|
5479
5479
|
nextBlock
|
|
5480
5480
|
} : !1;
|
|
@@ -5657,13 +5657,13 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
5657
5657
|
const firstBlock = selector_isSelectionExpanded.getFirstBlock(snapshot), lastBlock = selector_isSelectionExpanded.getLastBlock(snapshot);
|
|
5658
5658
|
if (!firstBlock || !lastBlock)
|
|
5659
5659
|
return !1;
|
|
5660
|
-
const firstBlockStartPoint =
|
|
5660
|
+
const firstBlockStartPoint = selectionPoint.getBlockStartPoint({
|
|
5661
5661
|
context: snapshot.context,
|
|
5662
5662
|
block: firstBlock
|
|
5663
|
-
}), selectionStartPoint =
|
|
5663
|
+
}), selectionStartPoint = selectionPoint.getSelectionStartPoint(snapshot.context.selection), lastBlockEndPoint = util_isEqualSelectionPoints.getBlockEndPoint({
|
|
5664
5664
|
context: snapshot.context,
|
|
5665
5665
|
block: lastBlock
|
|
5666
|
-
}), selectionEndPoint =
|
|
5666
|
+
}), selectionEndPoint = selectionPoint.getSelectionEndPoint(snapshot.context.selection);
|
|
5667
5667
|
return util_isEqualSelectionPoints.isEqualSelectionPoints(firstBlockStartPoint, selectionStartPoint) && util_isEqualSelectionPoints.isEqualSelectionPoints(lastBlockEndPoint, selectionEndPoint) ? {
|
|
5668
5668
|
selection: snapshot.context.selection
|
|
5669
5669
|
} : !1;
|
|
@@ -5684,13 +5684,13 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
5684
5684
|
const selectedBlocks = selector_isSelectionExpanded.getSelectedBlocks(snapshot), selectionStartBlock = selector_isSelectionExpanded.getSelectionStartBlock(snapshot), selectionEndBlock = selector_isSelectionExpanded.getSelectionEndBlock(snapshot);
|
|
5685
5685
|
if (!selectionStartBlock || !selectionEndBlock)
|
|
5686
5686
|
return !1;
|
|
5687
|
-
const startBlockStartPoint =
|
|
5687
|
+
const startBlockStartPoint = selectionPoint.getBlockStartPoint({
|
|
5688
5688
|
context: snapshot.context,
|
|
5689
5689
|
block: selectionStartBlock
|
|
5690
|
-
}), selectionStartPoint =
|
|
5690
|
+
}), selectionStartPoint = selectionPoint.getSelectionStartPoint(snapshot.context.selection), endBlockEndPoint = util_isEqualSelectionPoints.getBlockEndPoint({
|
|
5691
5691
|
context: snapshot.context,
|
|
5692
5692
|
block: selectionEndBlock
|
|
5693
|
-
}), selectionEndPoint =
|
|
5693
|
+
}), selectionEndPoint = selectionPoint.getSelectionEndPoint(snapshot.context.selection);
|
|
5694
5694
|
return util_isEqualSelectionPoints.isEqualSelectionPoints(selectionStartPoint, startBlockStartPoint) && util_isEqualSelectionPoints.isEqualSelectionPoints(selectionEndPoint, endBlockEndPoint) ? {
|
|
5695
5695
|
selectedBlocks
|
|
5696
5696
|
} : !1;
|
|
@@ -5783,7 +5783,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
5783
5783
|
}) => {
|
|
5784
5784
|
if (!isHotkey("Tab", event.originEvent))
|
|
5785
5785
|
return !1;
|
|
5786
|
-
const selectedBlocks = selector_isSelectionExpanded.getSelectedBlocks(snapshot), selectedListBlocks = selectedBlocks.flatMap((block) =>
|
|
5786
|
+
const selectedBlocks = selector_isSelectionExpanded.getSelectedBlocks(snapshot), selectedListBlocks = selectedBlocks.flatMap((block) => selectionPoint.isListBlock(snapshot.context, block.node) ? [{
|
|
5787
5787
|
node: block.node,
|
|
5788
5788
|
path: block.path
|
|
5789
5789
|
}] : []);
|
|
@@ -5808,7 +5808,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
5808
5808
|
}) => {
|
|
5809
5809
|
if (!isHotkey("Shift+Tab", event.originEvent))
|
|
5810
5810
|
return !1;
|
|
5811
|
-
const selectedBlocks = selector_isSelectionExpanded.getSelectedBlocks(snapshot), selectedListBlocks = selectedBlocks.flatMap((block) =>
|
|
5811
|
+
const selectedBlocks = selector_isSelectionExpanded.getSelectedBlocks(snapshot), selectedListBlocks = selectedBlocks.flatMap((block) => selectionPoint.isListBlock(snapshot.context, block.node) ? [{
|
|
5812
5812
|
node: block.node,
|
|
5813
5813
|
path: block.path
|
|
5814
5814
|
}] : []);
|
|
@@ -5988,7 +5988,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
5988
5988
|
type: "insert.block",
|
|
5989
5989
|
block,
|
|
5990
5990
|
placement: index === 0 ? "before" : "after",
|
|
5991
|
-
select: "end"
|
|
5991
|
+
select: event.select ?? "end"
|
|
5992
5992
|
}))]
|
|
5993
5993
|
}), behaviors_index.defineBehavior({
|
|
5994
5994
|
on: "insert.blocks",
|
|
@@ -6001,7 +6001,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
6001
6001
|
type: "insert.block",
|
|
6002
6002
|
block,
|
|
6003
6003
|
placement: "after",
|
|
6004
|
-
select: "end"
|
|
6004
|
+
select: event.select ?? "end"
|
|
6005
6005
|
}))]
|
|
6006
6006
|
}), behaviors_index.defineBehavior({
|
|
6007
6007
|
on: "insert.blocks",
|
|
@@ -6025,12 +6025,12 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
6025
6025
|
type: "insert.block",
|
|
6026
6026
|
block: event.blocks[0],
|
|
6027
6027
|
placement: "auto",
|
|
6028
|
-
select: "end"
|
|
6028
|
+
select: event.select ?? "end"
|
|
6029
6029
|
})] : util_isEqualSelectionPoints.isEmptyTextBlock(snapshot.context, focusTextBlock.node) ? event.blocks.map((block, index) => behaviors_index.raise({
|
|
6030
6030
|
type: "insert.block",
|
|
6031
6031
|
block,
|
|
6032
6032
|
placement: index === 0 ? "auto" : "after",
|
|
6033
|
-
select: "end"
|
|
6033
|
+
select: event.select ?? "end"
|
|
6034
6034
|
})) : event.blocks.flatMap((block, index) => index === 0 ? [behaviors_index.raise({
|
|
6035
6035
|
type: "split"
|
|
6036
6036
|
}), behaviors_index.raise({
|
|
@@ -6040,7 +6040,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
6040
6040
|
type: "insert.block",
|
|
6041
6041
|
block,
|
|
6042
6042
|
placement: "auto",
|
|
6043
|
-
select: "end"
|
|
6043
|
+
select: event.select ?? "end"
|
|
6044
6044
|
})] : index === event.blocks.length - 1 ? [behaviors_index.raise({
|
|
6045
6045
|
type: "select.next block",
|
|
6046
6046
|
select: "start"
|
|
@@ -6048,12 +6048,12 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
6048
6048
|
type: "insert.block",
|
|
6049
6049
|
block,
|
|
6050
6050
|
placement: "auto",
|
|
6051
|
-
select: "end"
|
|
6051
|
+
select: event.select ?? "end"
|
|
6052
6052
|
})] : [behaviors_index.raise({
|
|
6053
6053
|
type: "insert.block",
|
|
6054
6054
|
block,
|
|
6055
6055
|
placement: "after",
|
|
6056
|
-
select: "end"
|
|
6056
|
+
select: event.select ?? "end"
|
|
6057
6057
|
})])]
|
|
6058
6058
|
}), behaviors_index.defineBehavior({
|
|
6059
6059
|
on: "insert.blocks",
|
|
@@ -6066,7 +6066,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
6066
6066
|
type: "insert.block",
|
|
6067
6067
|
block,
|
|
6068
6068
|
placement: index === 0 ? "auto" : "after",
|
|
6069
|
-
select: "end"
|
|
6069
|
+
select: event.select ?? "end"
|
|
6070
6070
|
}))]
|
|
6071
6071
|
}), behaviors_index.defineBehavior({
|
|
6072
6072
|
on: "insert.break",
|
|
@@ -6234,7 +6234,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
6234
6234
|
const point = event.select === "end" ? util_isEqualSelectionPoints.getBlockEndPoint({
|
|
6235
6235
|
context: snapshot.context,
|
|
6236
6236
|
block: previousBlock
|
|
6237
|
-
}) :
|
|
6237
|
+
}) : selectionPoint.getBlockStartPoint({
|
|
6238
6238
|
context: snapshot.context,
|
|
6239
6239
|
block: previousBlock
|
|
6240
6240
|
});
|
|
@@ -6263,7 +6263,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
6263
6263
|
const point = event.select === "end" ? util_isEqualSelectionPoints.getBlockEndPoint({
|
|
6264
6264
|
context: snapshot.context,
|
|
6265
6265
|
block: nextBlock
|
|
6266
|
-
}) :
|
|
6266
|
+
}) : selectionPoint.getBlockStartPoint({
|
|
6267
6267
|
context: snapshot.context,
|
|
6268
6268
|
block: nextBlock
|
|
6269
6269
|
});
|
|
@@ -6287,7 +6287,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
6287
6287
|
}) => {
|
|
6288
6288
|
if (!snapshot.context.selection)
|
|
6289
6289
|
return !1;
|
|
6290
|
-
const selectionStartPoint =
|
|
6290
|
+
const selectionStartPoint = selectionPoint.getSelectionStartPoint(snapshot.context.selection), selectionEndPoint = selectionPoint.getSelectionEndPoint(snapshot.context.selection), focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock({
|
|
6291
6291
|
context: {
|
|
6292
6292
|
...snapshot.context,
|
|
6293
6293
|
selection: {
|
|
@@ -6303,8 +6303,8 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
6303
6303
|
}), newTextBlockSelection = {
|
|
6304
6304
|
anchor: selectionEndPoint,
|
|
6305
6305
|
focus: blockEndPoint
|
|
6306
|
-
}, newTextBlock =
|
|
6307
|
-
block:
|
|
6306
|
+
}, newTextBlock = selectionPoint.parseBlock({
|
|
6307
|
+
block: selectionPoint.sliceBlocks({
|
|
6308
6308
|
context: {
|
|
6309
6309
|
...snapshot.context,
|
|
6310
6310
|
selection: newTextBlockSelection
|
|
@@ -6317,7 +6317,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
6317
6317
|
validateFields: !0
|
|
6318
6318
|
}
|
|
6319
6319
|
});
|
|
6320
|
-
return !newTextBlock || !
|
|
6320
|
+
return !newTextBlock || !selectionPoint.isTextBlock(snapshot.context, newTextBlock) ? !1 : {
|
|
6321
6321
|
newTextBlock,
|
|
6322
6322
|
newTextBlockSelection,
|
|
6323
6323
|
selection: {
|
|
@@ -6335,7 +6335,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
6335
6335
|
}
|
|
6336
6336
|
}
|
|
6337
6337
|
})) {
|
|
6338
|
-
const newTextBlock =
|
|
6338
|
+
const newTextBlock = selectionPoint.parseBlock({
|
|
6339
6339
|
block: {
|
|
6340
6340
|
_type: snapshot.context.schema.block.name,
|
|
6341
6341
|
children: []
|
|
@@ -6666,7 +6666,7 @@ const arrowDownOnLonelyBlockObject = behaviors_index.defineBehavior({
|
|
|
6666
6666
|
return {
|
|
6667
6667
|
activeAnnotations: selector_isSelectingEntireBlocks.getActiveAnnotations(snapshot),
|
|
6668
6668
|
activeDecorators,
|
|
6669
|
-
textRuns: event.data.flatMap((block) =>
|
|
6669
|
+
textRuns: event.data.flatMap((block) => selectionPoint.isTextBlock(snapshot.context, block) ? [selectionPoint.getTextBlockText(block)] : [])
|
|
6670
6670
|
};
|
|
6671
6671
|
}
|
|
6672
6672
|
return !1;
|
|
@@ -7016,7 +7016,6 @@ function createEditorSnapshot({
|
|
|
7016
7016
|
keyGenerator,
|
|
7017
7017
|
readOnly,
|
|
7018
7018
|
schema: schema2,
|
|
7019
|
-
hasTag,
|
|
7020
7019
|
internalDrag
|
|
7021
7020
|
}) {
|
|
7022
7021
|
const selection = editor.selection ? slateRangeToSelection({
|
|
@@ -7043,7 +7042,6 @@ function createEditorSnapshot({
|
|
|
7043
7042
|
markState: editor.markState,
|
|
7044
7043
|
schema: schema2
|
|
7045
7044
|
}),
|
|
7046
|
-
hasTag,
|
|
7047
7045
|
internalDrag
|
|
7048
7046
|
}
|
|
7049
7047
|
};
|
|
@@ -7167,7 +7165,6 @@ const debug$8 = debugWithName("editor machine"), editorMachine = xstate.setup({
|
|
|
7167
7165
|
"edit mode": "read only"
|
|
7168
7166
|
}),
|
|
7169
7167
|
schema: context.schema,
|
|
7170
|
-
hasTag: (tag) => self.getSnapshot().hasTag(tag),
|
|
7171
7168
|
internalDrag: context.internalDrag
|
|
7172
7169
|
}),
|
|
7173
7170
|
nativeEvent: event.nativeEvent
|
|
@@ -7820,6 +7817,18 @@ const debug$7 = debugWithName("mutation-machine"), mutationMachine = xstate.setu
|
|
|
7820
7817
|
}, () => {
|
|
7821
7818
|
input.slateEditor.apply = originalApply;
|
|
7822
7819
|
};
|
|
7820
|
+
}),
|
|
7821
|
+
"mutation debouncer": xstate.fromCallback(({
|
|
7822
|
+
sendBack
|
|
7823
|
+
}) => {
|
|
7824
|
+
const interval = setInterval(() => {
|
|
7825
|
+
sendBack({
|
|
7826
|
+
type: "mutation delay passed"
|
|
7827
|
+
});
|
|
7828
|
+
}, process.env.NODE_ENV === "test" ? 250 : 0);
|
|
7829
|
+
return () => {
|
|
7830
|
+
clearInterval(interval);
|
|
7831
|
+
};
|
|
7823
7832
|
})
|
|
7824
7833
|
},
|
|
7825
7834
|
guards: {
|
|
@@ -7829,15 +7838,11 @@ const debug$7 = debugWithName("mutation-machine"), mutationMachine = xstate.setu
|
|
|
7829
7838
|
"is typing": xstate.stateIn({
|
|
7830
7839
|
typing: "typing"
|
|
7831
7840
|
}),
|
|
7832
|
-
"no pending mutations": ({
|
|
7833
|
-
context
|
|
7834
|
-
}) => context.pendingMutations.length === 0,
|
|
7835
7841
|
"slate is normalizing": ({
|
|
7836
7842
|
context
|
|
7837
7843
|
}) => slate.Editor.isNormalizing(context.slateEditor)
|
|
7838
7844
|
},
|
|
7839
7845
|
delays: {
|
|
7840
|
-
"mutation debounce": process.env.NODE_ENV === "test" ? 250 : 0,
|
|
7841
7846
|
"type debounce": process.env.NODE_ENV === "test" ? 0 : 250
|
|
7842
7847
|
}
|
|
7843
7848
|
}).createMachine({
|
|
@@ -7874,7 +7879,7 @@ const debug$7 = debugWithName("mutation-machine"), mutationMachine = xstate.setu
|
|
|
7874
7879
|
debug$7("entry: typing->idle");
|
|
7875
7880
|
}],
|
|
7876
7881
|
exit: [() => {
|
|
7877
|
-
debug$7("exit: typing->idle");
|
|
7882
|
+
debug$7("exit: typing->idle"), debug$7("entry: typing->typing");
|
|
7878
7883
|
}],
|
|
7879
7884
|
on: {
|
|
7880
7885
|
typing: {
|
|
@@ -7883,15 +7888,12 @@ const debug$7 = debugWithName("mutation-machine"), mutationMachine = xstate.setu
|
|
|
7883
7888
|
}
|
|
7884
7889
|
},
|
|
7885
7890
|
typing: {
|
|
7886
|
-
entry: [() => {
|
|
7887
|
-
debug$7("entry: typing->typing");
|
|
7888
|
-
}],
|
|
7889
|
-
exit: [() => {
|
|
7890
|
-
debug$7("exit: typing->typing");
|
|
7891
|
-
}],
|
|
7892
7891
|
after: {
|
|
7893
7892
|
"type debounce": {
|
|
7894
|
-
target: "idle"
|
|
7893
|
+
target: "idle",
|
|
7894
|
+
actions: [() => {
|
|
7895
|
+
debug$7("exit: typing->typing");
|
|
7896
|
+
}]
|
|
7895
7897
|
}
|
|
7896
7898
|
},
|
|
7897
7899
|
on: {
|
|
@@ -7917,56 +7919,38 @@ const debug$7 = debugWithName("mutation-machine"), mutationMachine = xstate.setu
|
|
|
7917
7919
|
debug$7("exit: mutations->idle");
|
|
7918
7920
|
}],
|
|
7919
7921
|
on: {
|
|
7920
|
-
patch: {
|
|
7921
|
-
actions: ["emit patch", "defer mutation", "emit has pending mutations"],
|
|
7922
|
-
target: "emitting mutations"
|
|
7923
|
-
}
|
|
7924
|
-
}
|
|
7925
|
-
},
|
|
7926
|
-
"emitting mutations": {
|
|
7927
|
-
entry: [() => {
|
|
7928
|
-
debug$7("entry: mutations->emitting mutations");
|
|
7929
|
-
}],
|
|
7930
|
-
exit: [() => {
|
|
7931
|
-
debug$7("exit: mutations->emitting mutations");
|
|
7932
|
-
}],
|
|
7933
|
-
after: {
|
|
7934
|
-
"mutation debounce": [{
|
|
7922
|
+
patch: [{
|
|
7935
7923
|
guard: "is read-only",
|
|
7936
|
-
|
|
7924
|
+
actions: ["defer patch", "defer mutation"],
|
|
7925
|
+
target: "has pending mutations"
|
|
7937
7926
|
}, {
|
|
7938
|
-
guard: xstate.and([xstate.not("is typing"), "slate is normalizing"]),
|
|
7939
|
-
target: "idle",
|
|
7940
|
-
actions: ["emit mutations", "clear pending mutations"]
|
|
7941
|
-
}, {
|
|
7942
|
-
target: "emitting mutations",
|
|
7943
|
-
reenter: !0
|
|
7944
|
-
}]
|
|
7945
|
-
},
|
|
7946
|
-
on: {
|
|
7947
|
-
patch: {
|
|
7948
|
-
target: "emitting mutations",
|
|
7949
7927
|
actions: ["emit patch", "defer mutation"],
|
|
7950
|
-
|
|
7951
|
-
}
|
|
7928
|
+
target: "has pending mutations"
|
|
7929
|
+
}]
|
|
7952
7930
|
}
|
|
7953
7931
|
},
|
|
7954
|
-
"
|
|
7932
|
+
"has pending mutations": {
|
|
7955
7933
|
entry: [() => {
|
|
7956
|
-
debug$7("entry: mutations->
|
|
7957
|
-
}],
|
|
7934
|
+
debug$7("entry: mutations->has pending mutations");
|
|
7935
|
+
}, "emit has pending mutations"],
|
|
7958
7936
|
exit: [() => {
|
|
7959
|
-
debug$7("exit: mutations->
|
|
7960
|
-
}],
|
|
7961
|
-
always: [{
|
|
7962
|
-
guard: xstate.not("is read-only"),
|
|
7963
|
-
target: "emitting mutations",
|
|
7964
|
-
actions: ["emit pending patch events", "clear pending patch events"]
|
|
7937
|
+
debug$7("exit: mutations->has pending mutations");
|
|
7965
7938
|
}],
|
|
7939
|
+
invoke: {
|
|
7940
|
+
src: "mutation debouncer"
|
|
7941
|
+
},
|
|
7966
7942
|
on: {
|
|
7967
|
-
|
|
7943
|
+
"mutation delay passed": {
|
|
7944
|
+
guard: xstate.and([xstate.not("is read-only"), xstate.not("is typing"), "slate is normalizing"]),
|
|
7945
|
+
target: "idle",
|
|
7946
|
+
actions: ["emit pending patch events", "clear pending patch events", "emit mutations", "clear pending mutations"]
|
|
7947
|
+
},
|
|
7948
|
+
patch: [{
|
|
7949
|
+
guard: "is read-only",
|
|
7968
7950
|
actions: ["defer patch", "defer mutation"]
|
|
7969
|
-
}
|
|
7951
|
+
}, {
|
|
7952
|
+
actions: ["emit patch", "defer mutation"]
|
|
7953
|
+
}]
|
|
7970
7954
|
}
|
|
7971
7955
|
}
|
|
7972
7956
|
}
|
|
@@ -8422,7 +8406,7 @@ function validateValue(value, types2, keyGenerator) {
|
|
|
8422
8406
|
}
|
|
8423
8407
|
}, !0;
|
|
8424
8408
|
}
|
|
8425
|
-
return !blk._type &&
|
|
8409
|
+
return !blk._type && selectionPoint.isTextBlock({
|
|
8426
8410
|
schema: types2
|
|
8427
8411
|
}, {
|
|
8428
8412
|
...blk,
|
|
@@ -10587,7 +10571,7 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
10587
10571
|
type: "behavior event",
|
|
10588
10572
|
behaviorEvent: {
|
|
10589
10573
|
type: "insert.blocks",
|
|
10590
|
-
blocks:
|
|
10574
|
+
blocks: selectionPoint.parseBlocks({
|
|
10591
10575
|
context: {
|
|
10592
10576
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
10593
10577
|
schema: editorActor.getSnapshot().context.schema
|
|
@@ -10813,8 +10797,8 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
10813
10797
|
behaviorEvent: {
|
|
10814
10798
|
type: "select",
|
|
10815
10799
|
at: util_selectionPointToBlockOffset.isSelectionCollapsed(dragSelection) ? dragSelection : {
|
|
10816
|
-
anchor:
|
|
10817
|
-
focus:
|
|
10800
|
+
anchor: selectionPoint.getSelectionEndPoint(dragSelection),
|
|
10801
|
+
focus: selectionPoint.getSelectionEndPoint(dragSelection),
|
|
10818
10802
|
backward: !1
|
|
10819
10803
|
}
|
|
10820
10804
|
},
|