@portabletext/editor 1.48.6 → 1.48.8
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/behavior.core.cjs +20 -8
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +5 -5
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +137 -90
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs +2 -2
- package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +7 -4
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +63 -47
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +29 -23
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.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 +15 -15
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs +258 -38
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +21 -10
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +5 -6
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +91 -46
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/selector.get-focus-inline-object.js +1 -2
- package/lib/_chunks-es/selector.get-focus-inline-object.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +7 -4
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-overlapping-selection.js +61 -46
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +30 -26
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/util.merge-text-blocks.js +1 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js +15 -16
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js +258 -38
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/behaviors/index.d.cts +2552 -251
- package/lib/behaviors/index.d.ts +2552 -251
- package/lib/index.cjs +45 -21
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +2350 -51
- package/lib/index.d.ts +2350 -51
- package/lib/index.js +44 -21
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +16 -7
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +2328 -23
- package/lib/plugins/index.d.ts +2328 -23
- package/lib/plugins/index.js +16 -7
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs +5 -5
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +2321 -28
- package/lib/selectors/index.d.ts +2321 -28
- package/lib/selectors/index.js +5 -6
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +30 -24
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +2350 -44
- package/lib/utils/index.d.ts +2350 -44
- package/lib/utils/index.js +30 -24
- package/lib/utils/index.js.map +1 -1
- package/package.json +1 -2
- package/src/behavior-actions/behavior.action.block.unset.ts +1 -1
- package/src/behavior-actions/behavior.action.decorator.add.ts +20 -5
- package/src/behavior-actions/behavior.action.delete.ts +21 -1
- package/src/behaviors/behavior.abstract.decorator.ts +1 -1
- package/src/behaviors/behavior.abstract.delete.ts +1 -1
- package/src/behaviors/behavior.abstract.insert.ts +2 -2
- package/src/behaviors/behavior.abstract.select.ts +16 -4
- package/src/behaviors/behavior.abstract.split.ts +9 -6
- package/src/behaviors/behavior.core.block-objects.ts +5 -5
- package/src/behaviors/behavior.core.insert-break.ts +16 -4
- package/src/behaviors/behavior.core.lists.ts +4 -6
- package/src/behaviors/behavior.decorator-pair.ts +13 -4
- package/src/behaviors/behavior.default.ts +1 -1
- package/src/behaviors/behavior.markdown.ts +5 -5
- package/src/converters/converter.portable-text.ts +1 -1
- package/src/converters/converter.text-html.ts +1 -1
- package/src/converters/converter.text-plain.ts +4 -4
- package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +10 -2
- package/src/editor/plugins/createWithSchemaTypes.ts +12 -19
- package/src/internal-utils/__tests__/dmpToOperations.test.ts +13 -12
- package/src/internal-utils/drag-selection.ts +16 -4
- package/src/internal-utils/event-position.ts +20 -8
- package/src/internal-utils/parse-blocks.ts +17 -5
- package/src/internal-utils/validateValue.ts +6 -6
- package/src/plugins/plugin.decorator-shortcut.ts +3 -2
- package/src/plugins/plugin.markdown.tsx +2 -0
- package/src/plugins/plugin.one-line.tsx +2 -0
- package/src/selectors/selector.get-active-annotations.ts +5 -2
- package/src/selectors/selector.get-active-list-item.ts +4 -3
- package/src/selectors/selector.get-active-style.ts +4 -3
- package/src/selectors/selector.get-anchor-text-block.ts +3 -6
- package/src/selectors/selector.get-block-offsets.ts +2 -2
- package/src/selectors/selector.get-caret-word-selection.ts +11 -5
- package/src/selectors/selector.get-selected-slice.ts +1 -1
- package/src/selectors/selector.get-selected-spans.ts +11 -15
- package/src/selectors/selector.get-selected-text-blocks.ts +3 -3
- package/src/selectors/selector.get-selection-text.ts +3 -3
- package/src/selectors/selector.get-text-before.ts +5 -2
- package/src/selectors/selector.get-trimmed-selection.ts +20 -14
- package/src/selectors/selector.is-active-annotation.ts +4 -2
- package/src/selectors/selector.is-active-decorator.test.ts +3 -3
- package/src/selectors/selector.is-at-the-end-of-block.ts +4 -1
- package/src/selectors/selector.is-at-the-start-of-block.ts +4 -1
- package/src/selectors/selector.is-point-after-selection.ts +7 -6
- package/src/selectors/selector.is-point-before-selection.ts +7 -6
- package/src/selectors/selector.is-selecting-entire-blocks.ts +8 -2
- package/src/selectors/selectors.ts +25 -28
- package/src/utils/util.block-offset-to-block-selection-point.ts +4 -4
- package/src/utils/util.block-offset-to-selection-point.ts +5 -5
- package/src/utils/util.block-offset.test.ts +219 -156
- package/src/utils/util.block-offset.ts +14 -17
- package/src/utils/util.block-offsets-to-selection.ts +5 -5
- package/src/utils/util.child-selection-point-to-block-offset.ts +7 -10
- package/src/utils/util.get-block-end-point.ts +15 -15
- package/src/utils/util.get-block-start-point.ts +13 -12
- package/src/utils/util.is-empty-text-block.ts +9 -8
- package/src/utils/util.selection-point-to-block-offset.ts +4 -4
- package/src/utils/util.slice-blocks.test.ts +178 -121
- package/src/utils/util.slice-blocks.ts +25 -24
- package/src/utils/util.split-text-block.ts +18 -12
- package/lib/_chunks-cjs/parse-blocks.cjs +0 -205
- package/lib/_chunks-cjs/parse-blocks.cjs.map +0 -1
- package/lib/_chunks-es/parse-blocks.js +0 -206
- package/lib/_chunks-es/parse-blocks.js.map +0 -1
- package/src/behavior-actions/behavior.guards.ts +0 -24
|
@@ -8,26 +8,24 @@ import isEqual from "lodash/isEqual.js";
|
|
|
8
8
|
import { Element, Text, Editor, Operation, Transforms, Path, Node, Range, Point, createEditor } from "slate";
|
|
9
9
|
import { setup, stateIn, fromCallback, assign, enqueueActions, emit, assertEvent, and, not, createActor } from "xstate";
|
|
10
10
|
import { unset, set, setIfMissing, insert, diffMatchPatch as diffMatchPatch$1, applyAll } from "@portabletext/patches";
|
|
11
|
-
import { isPortableTextTextBlock, isKeySegment, isPortableTextSpan as isPortableTextSpan$1, isPortableTextListBlock, defineType, defineField } from "@sanity/types";
|
|
12
11
|
import flatten from "lodash/flatten.js";
|
|
13
12
|
import isPlainObject from "lodash/isPlainObject.js";
|
|
14
13
|
import uniq from "lodash/uniq.js";
|
|
14
|
+
import { isTextBlock, parseBlock, sliceBlocks, parseAnnotation, blockOffsetToSpanSelectionPoint, parseInlineObject, isSpan, isListBlock, isEmptyTextBlock, getBlockEndPoint, getBlockStartPoint, getTextBlockText } from "./util.slice-blocks.js";
|
|
15
15
|
import getRandomValues from "get-random-values-esm";
|
|
16
|
-
import { parseBlock, parseAnnotation, isTextBlock, parseInlineObject } from "./parse-blocks.js";
|
|
17
|
-
import { sliceBlocks, blockOffsetToSpanSelectionPoint, isEmptyTextBlock, getBlockEndPoint, getBlockStartPoint, getTextBlockText } from "./util.slice-blocks.js";
|
|
18
16
|
import { htmlToBlocks } from "@portabletext/block-tools";
|
|
19
17
|
import { toHTML } from "@portabletext/to-html";
|
|
20
18
|
import { Schema } from "@sanity/schema";
|
|
21
19
|
import get from "lodash/get.js";
|
|
22
20
|
import isUndefined from "lodash/isUndefined.js";
|
|
23
21
|
import omitBy from "lodash/omitBy.js";
|
|
22
|
+
import { isKeySegment, defineType, defineField, isPortableTextSpan as isPortableTextSpan$1, getFocusTextBlock, getPreviousBlock, getNextBlock, getFocusBlockObject, getFocusSpan, isSelectionCollapsed, isOverlappingSelection, getSelectedBlocks, isSelectionExpanded } from "./selector.is-overlapping-selection.js";
|
|
24
23
|
import omit from "lodash/omit.js";
|
|
25
24
|
import { selectionPointToBlockOffset, blockOffsetsToSelection } from "./util.selection-point-to-block-offset.js";
|
|
26
25
|
import { getTrimmedSelection, isActiveAnnotation, isActiveDecorator, getSelectedTextBlocks, isActiveListItem, isActiveStyle, isSelectingEntireBlocks, getActiveAnnotations } from "./selector.is-selecting-entire-blocks.js";
|
|
27
26
|
import { DOMEditor } from "slate-dom";
|
|
28
27
|
import startCase from "lodash.startcase";
|
|
29
28
|
import { defineBehavior, raise, coreBehaviors } from "./behavior.core.js";
|
|
30
|
-
import { getFocusTextBlock, getPreviousBlock, getNextBlock, getFocusBlockObject, getFocusSpan, isSelectionCollapsed, isOverlappingSelection, getSelectedBlocks, isSelectionExpanded } from "./selector.is-overlapping-selection.js";
|
|
31
29
|
import { getSelectionStartPoint, getSelectionEndPoint } from "./util.get-selection-start-point.js";
|
|
32
30
|
import { Subject } from "rxjs";
|
|
33
31
|
import { useEffectEvent } from "use-effect-event";
|
|
@@ -381,7 +379,9 @@ function validateValue(value, types, keyGenerator) {
|
|
|
381
379
|
}
|
|
382
380
|
}, !0;
|
|
383
381
|
}
|
|
384
|
-
return !blk._type &&
|
|
382
|
+
return !blk._type && isTextBlock({
|
|
383
|
+
schema: types
|
|
384
|
+
}, {
|
|
385
385
|
...blk,
|
|
386
386
|
_type: types.block.name
|
|
387
387
|
}) ? (resolution = {
|
|
@@ -2229,8 +2229,7 @@ const converterJson = {
|
|
|
2229
2229
|
snapshot,
|
|
2230
2230
|
event
|
|
2231
2231
|
}) => {
|
|
2232
|
-
|
|
2233
|
-
if (!selection)
|
|
2232
|
+
if (!(snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection))
|
|
2234
2233
|
return {
|
|
2235
2234
|
type: "serialization.failure",
|
|
2236
2235
|
mimeType: "application/x-portable-text",
|
|
@@ -2238,8 +2237,8 @@ const converterJson = {
|
|
|
2238
2237
|
reason: "No selection"
|
|
2239
2238
|
};
|
|
2240
2239
|
const blocks = sliceBlocks({
|
|
2241
|
-
|
|
2242
|
-
|
|
2240
|
+
context: snapshot.context,
|
|
2241
|
+
blocks: snapshot.context.value
|
|
2243
2242
|
});
|
|
2244
2243
|
return blocks.length === 0 ? {
|
|
2245
2244
|
type: "serialization.failure",
|
|
@@ -2296,8 +2295,7 @@ function createConverterTextHtml(legacySchema) {
|
|
|
2296
2295
|
snapshot,
|
|
2297
2296
|
event
|
|
2298
2297
|
}) => {
|
|
2299
|
-
|
|
2300
|
-
if (!selection)
|
|
2298
|
+
if (!(snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection))
|
|
2301
2299
|
return {
|
|
2302
2300
|
type: "serialization.failure",
|
|
2303
2301
|
mimeType: "text/html",
|
|
@@ -2305,8 +2303,8 @@ function createConverterTextHtml(legacySchema) {
|
|
|
2305
2303
|
reason: "No selection"
|
|
2306
2304
|
};
|
|
2307
2305
|
const blocks = sliceBlocks({
|
|
2308
|
-
|
|
2309
|
-
|
|
2306
|
+
context: snapshot.context,
|
|
2307
|
+
blocks: snapshot.context.value
|
|
2310
2308
|
}), html = toHTML(blocks, {
|
|
2311
2309
|
onMissingComponent: !1,
|
|
2312
2310
|
components: {
|
|
@@ -2362,24 +2360,21 @@ function createConverterTextPlain(legacySchema) {
|
|
|
2362
2360
|
serialize: ({
|
|
2363
2361
|
snapshot,
|
|
2364
2362
|
event
|
|
2365
|
-
}) => {
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
selection
|
|
2372
|
-
}).map((block) => isPortableTextTextBlock(block) ? block.children.map((child) => child._type === snapshot.context.schema.span.name ? child.text : snapshot.beta.hasTag("dragging internally") ? `[${snapshot.context.schema.inlineObjects.find((inlineObjectType) => inlineObjectType.name === child._type)?.title ?? "Object"}]` : "").join("") : snapshot.beta.hasTag("dragging internally") ? `[${snapshot.context.schema.blockObjects.find((blockObjectType) => blockObjectType.name === block._type)?.title ?? "Object"}]` : "").filter((block) => block !== "").join(`
|
|
2363
|
+
}) => snapshot.beta.internalDrag?.origin.selection ?? snapshot.context.selection ? {
|
|
2364
|
+
type: "serialization.success",
|
|
2365
|
+
data: sliceBlocks({
|
|
2366
|
+
context: snapshot.context,
|
|
2367
|
+
blocks: snapshot.context.value
|
|
2368
|
+
}).map((block) => isTextBlock(snapshot.context, block) ? block.children.map((child) => child._type === snapshot.context.schema.span.name ? child.text : snapshot.beta.hasTag("dragging internally") ? `[${snapshot.context.schema.inlineObjects.find((inlineObjectType) => inlineObjectType.name === child._type)?.title ?? "Object"}]` : "").join("") : snapshot.beta.hasTag("dragging internally") ? `[${snapshot.context.schema.blockObjects.find((blockObjectType) => blockObjectType.name === block._type)?.title ?? "Object"}]` : "").filter((block) => block !== "").join(`
|
|
2373
2369
|
|
|
2374
2370
|
`),
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
};
|
|
2371
|
+
mimeType: "text/plain",
|
|
2372
|
+
originEvent: event.originEvent
|
|
2373
|
+
} : {
|
|
2374
|
+
type: "serialization.failure",
|
|
2375
|
+
mimeType: "text/plain",
|
|
2376
|
+
originEvent: event.originEvent,
|
|
2377
|
+
reason: "No selection"
|
|
2383
2378
|
},
|
|
2384
2379
|
deserialize: ({
|
|
2385
2380
|
snapshot,
|
|
@@ -3379,7 +3374,7 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
3379
3374
|
const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(action.editor)).at(0);
|
|
3380
3375
|
if (!parsedBlock)
|
|
3381
3376
|
throw new Error(`Unable to parse block at ${JSON.stringify(action.at)}`);
|
|
3382
|
-
if (isTextBlock(context
|
|
3377
|
+
if (isTextBlock(context, parsedBlock)) {
|
|
3383
3378
|
const propsToRemove = action.props.filter((prop) => prop !== "_type"), updatedTextBlock = parseBlock({
|
|
3384
3379
|
context,
|
|
3385
3380
|
block: omit(parsedBlock, propsToRemove),
|
|
@@ -3625,11 +3620,17 @@ const decoratorAddActionImplementation = ({
|
|
|
3625
3620
|
action
|
|
3626
3621
|
}) => {
|
|
3627
3622
|
const editor = action.editor, mark = action.decorator, value = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), manualAnchor = action.at?.anchor ? blockOffsetToSpanSelectionPoint({
|
|
3628
|
-
|
|
3623
|
+
context: {
|
|
3624
|
+
...context,
|
|
3625
|
+
value
|
|
3626
|
+
},
|
|
3629
3627
|
blockOffset: action.at.anchor,
|
|
3630
3628
|
direction: "backward"
|
|
3631
3629
|
}) : void 0, manualFocus = action.at?.focus ? blockOffsetToSpanSelectionPoint({
|
|
3632
|
-
|
|
3630
|
+
context: {
|
|
3631
|
+
...context,
|
|
3632
|
+
value
|
|
3633
|
+
},
|
|
3633
3634
|
blockOffset: action.at.focus,
|
|
3634
3635
|
direction: "forward"
|
|
3635
3636
|
}) : void 0, manualSelection = manualAnchor && manualFocus ? {
|
|
@@ -3643,10 +3644,16 @@ const decoratorAddActionImplementation = ({
|
|
|
3643
3644
|
editor,
|
|
3644
3645
|
range: selection
|
|
3645
3646
|
}), anchorOffset = editorSelection ? selectionPointToBlockOffset({
|
|
3646
|
-
|
|
3647
|
+
context: {
|
|
3648
|
+
...context,
|
|
3649
|
+
value
|
|
3650
|
+
},
|
|
3647
3651
|
selectionPoint: editorSelection.anchor
|
|
3648
3652
|
}) : void 0, focusOffset = editorSelection ? selectionPointToBlockOffset({
|
|
3649
|
-
|
|
3653
|
+
context: {
|
|
3654
|
+
...context,
|
|
3655
|
+
value
|
|
3656
|
+
},
|
|
3650
3657
|
selectionPoint: editorSelection.focus
|
|
3651
3658
|
}) : void 0;
|
|
3652
3659
|
if (!anchorOffset || !focusOffset)
|
|
@@ -3659,7 +3666,10 @@ const decoratorAddActionImplementation = ({
|
|
|
3659
3666
|
hanging: !0
|
|
3660
3667
|
});
|
|
3661
3668
|
const newValue = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), newSelection = blockOffsetsToSelection({
|
|
3662
|
-
|
|
3669
|
+
context: {
|
|
3670
|
+
...context,
|
|
3671
|
+
value: newValue
|
|
3672
|
+
},
|
|
3663
3673
|
offsets: {
|
|
3664
3674
|
anchor: anchorOffset,
|
|
3665
3675
|
focus: focusOffset
|
|
@@ -3730,11 +3740,27 @@ const decoratorAddActionImplementation = ({
|
|
|
3730
3740
|
};
|
|
3731
3741
|
}
|
|
3732
3742
|
}, deleteActionImplementation = ({
|
|
3743
|
+
context,
|
|
3733
3744
|
action
|
|
3734
3745
|
}) => {
|
|
3735
3746
|
const range = toSlateRange(action.at, action.editor);
|
|
3736
3747
|
if (!range)
|
|
3737
3748
|
throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(action.at)}`);
|
|
3749
|
+
if (Range.isCollapsed(range)) {
|
|
3750
|
+
const [focusBlock] = getFocusBlock({
|
|
3751
|
+
editor: {
|
|
3752
|
+
...action.editor,
|
|
3753
|
+
selection: range
|
|
3754
|
+
}
|
|
3755
|
+
}), [focusChild] = getFocusChild({
|
|
3756
|
+
editor: {
|
|
3757
|
+
...action.editor,
|
|
3758
|
+
selection: range
|
|
3759
|
+
}
|
|
3760
|
+
});
|
|
3761
|
+
if (focusBlock && focusBlock._type === context.schema.block.name && focusChild && focusChild._type === context.schema.span.name)
|
|
3762
|
+
return;
|
|
3763
|
+
}
|
|
3738
3764
|
action.editor.delete({
|
|
3739
3765
|
at: range
|
|
3740
3766
|
});
|
|
@@ -4942,7 +4968,7 @@ function createWithSchemaTypes({
|
|
|
4942
4968
|
editorActor
|
|
4943
4969
|
}) {
|
|
4944
4970
|
return function(editor) {
|
|
4945
|
-
editor.isTextBlock = (value) =>
|
|
4971
|
+
editor.isTextBlock = (value) => isTextBlock(editorActor.getSnapshot().context, value), editor.isTextSpan = (value) => isSpan(editorActor.getSnapshot().context, value), editor.isListBlock = (value) => 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;
|
|
4946
4972
|
const {
|
|
4947
4973
|
normalizeNode
|
|
4948
4974
|
} = editor;
|
|
@@ -5850,7 +5876,7 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
5850
5876
|
event
|
|
5851
5877
|
}) => {
|
|
5852
5878
|
const manualSelection = event.at ? blockOffsetsToSelection({
|
|
5853
|
-
|
|
5879
|
+
context: snapshot.context,
|
|
5854
5880
|
offsets: event.at
|
|
5855
5881
|
}) : null;
|
|
5856
5882
|
return manualSelection ? !isActiveDecorator(event.decorator)({
|
|
@@ -5874,7 +5900,7 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
5874
5900
|
event
|
|
5875
5901
|
}) => {
|
|
5876
5902
|
const selection = blockOffsetsToSelection({
|
|
5877
|
-
|
|
5903
|
+
context: snapshot.context,
|
|
5878
5904
|
offsets: event.at
|
|
5879
5905
|
});
|
|
5880
5906
|
if (!selection)
|
|
@@ -5940,6 +5966,7 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
5940
5966
|
} : !1;
|
|
5941
5967
|
},
|
|
5942
5968
|
actions: [({
|
|
5969
|
+
snapshot,
|
|
5943
5970
|
event
|
|
5944
5971
|
}, {
|
|
5945
5972
|
focusTextBlock
|
|
@@ -5948,7 +5975,7 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
5948
5975
|
block: event.blocks[0],
|
|
5949
5976
|
placement: "auto",
|
|
5950
5977
|
select: "end"
|
|
5951
|
-
})] : isEmptyTextBlock(focusTextBlock.node) ? event.blocks.map((block, index) => raise({
|
|
5978
|
+
})] : isEmptyTextBlock(snapshot.context, focusTextBlock.node) ? event.blocks.map((block, index) => raise({
|
|
5952
5979
|
type: "insert.block",
|
|
5953
5980
|
block,
|
|
5954
5981
|
placement: index === 0 ? "auto" : "after",
|
|
@@ -6136,7 +6163,13 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6136
6163
|
const previousBlock = getPreviousBlock(snapshot);
|
|
6137
6164
|
if (!previousBlock)
|
|
6138
6165
|
return !1;
|
|
6139
|
-
const point = event.select === "end" ? getBlockEndPoint(
|
|
6166
|
+
const point = event.select === "end" ? getBlockEndPoint({
|
|
6167
|
+
context: snapshot.context,
|
|
6168
|
+
block: previousBlock
|
|
6169
|
+
}) : getBlockStartPoint({
|
|
6170
|
+
context: snapshot.context,
|
|
6171
|
+
block: previousBlock
|
|
6172
|
+
});
|
|
6140
6173
|
return {
|
|
6141
6174
|
selection: {
|
|
6142
6175
|
anchor: point,
|
|
@@ -6159,7 +6192,13 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6159
6192
|
const nextBlock = getNextBlock(snapshot);
|
|
6160
6193
|
if (!nextBlock)
|
|
6161
6194
|
return !1;
|
|
6162
|
-
const point = event.select === "end" ? getBlockEndPoint(
|
|
6195
|
+
const point = event.select === "end" ? getBlockEndPoint({
|
|
6196
|
+
context: snapshot.context,
|
|
6197
|
+
block: nextBlock
|
|
6198
|
+
}) : getBlockStartPoint({
|
|
6199
|
+
context: snapshot.context,
|
|
6200
|
+
block: nextBlock
|
|
6201
|
+
});
|
|
6163
6202
|
return {
|
|
6164
6203
|
selection: {
|
|
6165
6204
|
anchor: point,
|
|
@@ -6190,20 +6229,26 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6190
6229
|
}
|
|
6191
6230
|
});
|
|
6192
6231
|
if (focusTextBlock) {
|
|
6193
|
-
const blockEndPoint = getBlockEndPoint(
|
|
6232
|
+
const blockEndPoint = getBlockEndPoint({
|
|
6233
|
+
context: snapshot.context,
|
|
6234
|
+
block: focusTextBlock
|
|
6235
|
+
}), newTextBlockSelection = {
|
|
6194
6236
|
anchor: selectionEndPoint,
|
|
6195
6237
|
focus: blockEndPoint
|
|
6196
6238
|
}, newTextBlock = parseBlock({
|
|
6197
6239
|
block: sliceBlocks({
|
|
6198
|
-
|
|
6199
|
-
|
|
6240
|
+
context: {
|
|
6241
|
+
...snapshot.context,
|
|
6242
|
+
selection: newTextBlockSelection
|
|
6243
|
+
},
|
|
6244
|
+
blocks: [focusTextBlock.node]
|
|
6200
6245
|
}).at(0),
|
|
6201
6246
|
context: snapshot.context,
|
|
6202
6247
|
options: {
|
|
6203
6248
|
refreshKeys: !0
|
|
6204
6249
|
}
|
|
6205
6250
|
});
|
|
6206
|
-
return !newTextBlock || !isTextBlock(snapshot.context
|
|
6251
|
+
return !newTextBlock || !isTextBlock(snapshot.context, newTextBlock) ? !1 : {
|
|
6207
6252
|
newTextBlock,
|
|
6208
6253
|
newTextBlockSelection,
|
|
6209
6254
|
selection: {
|
|
@@ -6556,7 +6601,7 @@ const EditorContext = createGloballyScopedContext("@portabletext/editor/context/
|
|
|
6556
6601
|
return {
|
|
6557
6602
|
activeAnnotations: getActiveAnnotations(snapshot),
|
|
6558
6603
|
activeDecorators,
|
|
6559
|
-
textRuns: event.data.flatMap((block) => isTextBlock(snapshot.context
|
|
6604
|
+
textRuns: event.data.flatMap((block) => isTextBlock(snapshot.context, block) ? [getTextBlockText(block)] : [])
|
|
6560
6605
|
};
|
|
6561
6606
|
}
|
|
6562
6607
|
return !1;
|