@portabletext/editor 2.19.3 → 2.20.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-dts/index.d.ts +6 -24
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +2 -91
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/_chunks-es/util.merge-text-blocks.js +78 -2
- package/lib/_chunks-es/util.merge-text-blocks.js.map +1 -1
- package/lib/_chunks-es/util.slice-text-block.js +1 -18
- package/lib/_chunks-es/util.slice-text-block.js.map +1 -1
- package/lib/index.js +44 -128
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.js +1 -2
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.ts +2 -0
- package/lib/selectors/index.js +92 -4
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.js +18 -3
- package/lib/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/src/behaviors/behavior.abstract.decorator.ts +2 -10
- package/src/behaviors/behavior.abstract.delete.ts +1 -30
- package/src/behaviors/behavior.types.event.ts +3 -10
- package/src/operations/behavior.operation.decorator.add.ts +38 -131
- package/src/selectors/selector.get-trimmed-selection.ts +2 -0
- package/lib/_chunks-es/util.child-selection-point-to-block-offset.js +0 -81
- package/lib/_chunks-es/util.child-selection-point-to-block-offset.js.map +0 -1
package/lib/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import { getBlockStartPoint, getBlockKeyFromSelectionPoint, getChildKeyFromSelec
|
|
|
13
13
|
import isEqual from "lodash/isEqual.js";
|
|
14
14
|
import { isTextBlock, isSpan, compileSchema } from "@portabletext/schema";
|
|
15
15
|
import { defineSchema } from "@portabletext/schema";
|
|
16
|
-
import { getFocusInlineObject, getSelectedBlocks, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, isOverlappingSelection, isSelectingEntireBlocks, getActiveDecorators,
|
|
16
|
+
import { getFocusInlineObject, getSelectedBlocks, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, isOverlappingSelection, isSelectingEntireBlocks, getActiveDecorators, isActiveAnnotation, getCaretWordSelection, getFocusBlockObject, getPreviousBlock, getNextBlock, getMarkState, getActiveAnnotationsMarks, isAtTheEndOfBlock, isAtTheStartOfBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock, getSelectionEndPoint as getSelectionEndPoint$1, isActiveDecorator, getActiveAnnotations, getSelectedTextBlocks, isActiveListItem, isActiveStyle } from "./_chunks-es/selector.is-at-the-start-of-block.js";
|
|
17
17
|
import { isSelectionCollapsed as isSelectionCollapsed$1, getFocusTextBlock, getFocusSpan as getFocusSpan$1, isSelectionExpanded, getFocusBlock as getFocusBlock$1, getSelectedValue, getSelectionStartPoint as getSelectionStartPoint$1, getFocusChild as getFocusChild$1 } from "./_chunks-es/selector.get-selection-text.js";
|
|
18
18
|
import { defineBehavior, forward, raise, effect } from "./behaviors/index.js";
|
|
19
19
|
import uniq from "lodash/uniq.js";
|
|
@@ -25,10 +25,9 @@ import { Schema } from "@sanity/schema";
|
|
|
25
25
|
import flatten from "lodash/flatten.js";
|
|
26
26
|
import omit from "lodash/omit.js";
|
|
27
27
|
import { applyAll, unset, insert, set, setIfMissing, diffMatchPatch as diffMatchPatch$1 } from "@portabletext/patches";
|
|
28
|
-
import { blockOffsetsToSelection } from "./_chunks-es/util.child-selection-point-to-block-offset.js";
|
|
29
|
-
import { selectionPointToBlockOffset, sliceTextBlock } from "./_chunks-es/util.slice-text-block.js";
|
|
30
28
|
import { createDraft, finishDraft } from "immer";
|
|
31
29
|
import { createKeyboardShortcut, code, underline, italic, bold, undo, redo } from "@portabletext/keyboard-shortcuts";
|
|
30
|
+
import { sliceTextBlock } from "./_chunks-es/util.slice-text-block.js";
|
|
32
31
|
import isPlainObject from "lodash/isPlainObject.js";
|
|
33
32
|
import { Subject } from "rxjs";
|
|
34
33
|
function EditorEventListener(props) {
|
|
@@ -4494,97 +4493,42 @@ const addAnnotationOperationImplementation = ({
|
|
|
4494
4493
|
context,
|
|
4495
4494
|
operation
|
|
4496
4495
|
}) => {
|
|
4497
|
-
const editor = operation.editor, mark = operation.decorator
|
|
4498
|
-
|
|
4499
|
-
...context,
|
|
4500
|
-
value
|
|
4501
|
-
},
|
|
4502
|
-
blockOffset: operation.at.anchor,
|
|
4503
|
-
direction: "backward"
|
|
4504
|
-
}) : void 0, manualFocus = operation.at?.focus ? blockOffsetToSpanSelectionPoint({
|
|
4505
|
-
context: {
|
|
4506
|
-
...context,
|
|
4507
|
-
value
|
|
4508
|
-
},
|
|
4509
|
-
blockOffset: operation.at.focus,
|
|
4510
|
-
direction: "forward"
|
|
4511
|
-
}) : void 0, manualSelection = manualAnchor && manualFocus ? {
|
|
4512
|
-
anchor: manualAnchor,
|
|
4513
|
-
focus: manualFocus
|
|
4514
|
-
} : void 0, selection = manualSelection ? toSlateRange({
|
|
4496
|
+
const editor = operation.editor, mark = operation.decorator;
|
|
4497
|
+
let at = operation.at ? toSlateRange({
|
|
4515
4498
|
context: {
|
|
4516
4499
|
schema: context.schema,
|
|
4517
4500
|
value: operation.editor.value,
|
|
4518
|
-
selection:
|
|
4501
|
+
selection: operation.at
|
|
4519
4502
|
},
|
|
4520
4503
|
blockIndexMap: operation.editor.blockIndexMap
|
|
4521
|
-
})
|
|
4522
|
-
if (!
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
...context,
|
|
4531
|
-
value
|
|
4532
|
-
},
|
|
4533
|
-
selectionPoint: editorSelection.anchor
|
|
4534
|
-
}) : void 0, focusOffset = editorSelection ? selectionPointToBlockOffset({
|
|
4535
|
-
context: {
|
|
4536
|
-
...context,
|
|
4537
|
-
value
|
|
4538
|
-
},
|
|
4539
|
-
selectionPoint: editorSelection.focus
|
|
4540
|
-
}) : void 0;
|
|
4541
|
-
if (!anchorOffset || !focusOffset)
|
|
4542
|
-
throw new Error("Unable to find anchor or focus offset");
|
|
4543
|
-
if (Range.isExpanded(selection)) {
|
|
4544
|
-
Transforms.setNodes(editor, {}, {
|
|
4545
|
-
at: selection,
|
|
4504
|
+
}) : operation.editor.selection;
|
|
4505
|
+
if (!at)
|
|
4506
|
+
throw new Error("Unable to add decorator without a selection");
|
|
4507
|
+
if (Range.isExpanded(at)) {
|
|
4508
|
+
const rangeRef = Editor.rangeRef(editor, at, {
|
|
4509
|
+
affinity: "inward"
|
|
4510
|
+
}), [start, end] = Range.edges(at), endAtEndOfNode = Editor.isEnd(editor, end, end.path);
|
|
4511
|
+
Transforms.splitNodes(editor, {
|
|
4512
|
+
at: end,
|
|
4546
4513
|
match: Text.isText,
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
const newValue = fromSlateValue(editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), newSelection = blockOffsetsToSelection({
|
|
4551
|
-
context: {
|
|
4552
|
-
...context,
|
|
4553
|
-
value: newValue
|
|
4554
|
-
},
|
|
4555
|
-
offsets: {
|
|
4556
|
-
anchor: anchorOffset,
|
|
4557
|
-
focus: focusOffset
|
|
4558
|
-
},
|
|
4559
|
-
backward: editorSelection?.backward
|
|
4560
|
-
}), trimmedSelection = getTrimmedSelection({
|
|
4561
|
-
blockIndexMap: editor.blockIndexMap,
|
|
4562
|
-
context: {
|
|
4563
|
-
converters: [],
|
|
4564
|
-
keyGenerator: context.keyGenerator,
|
|
4565
|
-
readOnly: !1,
|
|
4566
|
-
schema: context.schema,
|
|
4567
|
-
selection: newSelection,
|
|
4568
|
-
value: newValue
|
|
4569
|
-
},
|
|
4570
|
-
decoratorState: editor.decoratorState
|
|
4514
|
+
mode: "lowest",
|
|
4515
|
+
voids: !1,
|
|
4516
|
+
always: !endAtEndOfNode
|
|
4571
4517
|
});
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4518
|
+
const startAtStartOfNode = Editor.isStart(editor, start, start.path);
|
|
4519
|
+
if (Transforms.splitNodes(editor, {
|
|
4520
|
+
at: start,
|
|
4521
|
+
match: Text.isText,
|
|
4522
|
+
mode: "lowest",
|
|
4523
|
+
voids: !1,
|
|
4524
|
+
always: !startAtStartOfNode
|
|
4525
|
+
}), at = rangeRef.unref(), !at)
|
|
4526
|
+
throw new Error("Unable to add decorator without a selection");
|
|
4527
|
+
operation.at || Transforms.select(editor, at);
|
|
4528
|
+
const splitTextNodes = Editor.nodes(editor, {
|
|
4529
|
+
at,
|
|
4530
|
+
match: Text.isText
|
|
4581
4531
|
});
|
|
4582
|
-
if (!newRange)
|
|
4583
|
-
throw new Error("Unable to find new selection");
|
|
4584
|
-
const splitTextNodes = Range.isRange(newRange) ? [...Editor.nodes(editor, {
|
|
4585
|
-
at: newRange,
|
|
4586
|
-
match: (node) => Text.isText(node)
|
|
4587
|
-
})] : [];
|
|
4588
4532
|
for (const [node, path] of splitTextNodes) {
|
|
4589
4533
|
const marks = [...(Array.isArray(node.marks) ? node.marks : []).filter((eMark) => eMark !== mark), mark];
|
|
4590
4534
|
Transforms.setNodes(editor, {
|
|
@@ -4598,11 +4542,11 @@ const addAnnotationOperationImplementation = ({
|
|
|
4598
4542
|
}
|
|
4599
4543
|
} else {
|
|
4600
4544
|
if (!Array.from(Editor.nodes(editor, {
|
|
4601
|
-
at
|
|
4545
|
+
at,
|
|
4602
4546
|
match: (node) => editor.isTextSpan(node)
|
|
4603
4547
|
}))?.at(0))
|
|
4604
4548
|
return;
|
|
4605
|
-
const [block, blockPath] = Editor.node(editor,
|
|
4549
|
+
const [block, blockPath] = Editor.node(editor, at, {
|
|
4606
4550
|
depth: 1
|
|
4607
4551
|
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
4608
4552
|
if (lonelyEmptySpan) {
|
|
@@ -4617,9 +4561,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
4617
4561
|
editor.decoratorState[mark] = !0;
|
|
4618
4562
|
}
|
|
4619
4563
|
if (editor.selection) {
|
|
4620
|
-
const
|
|
4564
|
+
const selection = editor.selection;
|
|
4621
4565
|
editor.selection = {
|
|
4622
|
-
...
|
|
4566
|
+
...selection
|
|
4623
4567
|
};
|
|
4624
4568
|
}
|
|
4625
4569
|
}, deleteOperationImplementation = ({
|
|
@@ -8317,19 +8261,13 @@ const abstractAnnotationBehaviors = [defineBehavior({
|
|
|
8317
8261
|
guard: ({
|
|
8318
8262
|
snapshot,
|
|
8319
8263
|
event
|
|
8320
|
-
}) => {
|
|
8321
|
-
|
|
8322
|
-
|
|
8323
|
-
|
|
8324
|
-
|
|
8325
|
-
|
|
8326
|
-
|
|
8327
|
-
context: {
|
|
8328
|
-
...snapshot.context,
|
|
8329
|
-
selection: manualSelection
|
|
8330
|
-
}
|
|
8331
|
-
}) : !isActiveDecorator(event.decorator)(snapshot);
|
|
8332
|
-
},
|
|
8264
|
+
}) => event.at ? !isActiveDecorator(event.decorator)({
|
|
8265
|
+
...snapshot,
|
|
8266
|
+
context: {
|
|
8267
|
+
...snapshot.context,
|
|
8268
|
+
selection: event.at
|
|
8269
|
+
}
|
|
8270
|
+
}) : !isActiveDecorator(event.decorator)(snapshot),
|
|
8333
8271
|
actions: [({
|
|
8334
8272
|
event
|
|
8335
8273
|
}) => [raise({
|
|
@@ -8542,33 +8480,11 @@ const abstractAnnotationBehaviors = [defineBehavior({
|
|
|
8542
8480
|
})]]
|
|
8543
8481
|
}), defineBehavior({
|
|
8544
8482
|
on: "delete.text",
|
|
8545
|
-
|
|
8546
|
-
snapshot,
|
|
8483
|
+
actions: [({
|
|
8547
8484
|
event
|
|
8548
|
-
}) => {
|
|
8549
|
-
const selection = blockOffsetsToSelection({
|
|
8550
|
-
context: snapshot.context,
|
|
8551
|
-
offsets: event.at
|
|
8552
|
-
});
|
|
8553
|
-
if (!selection)
|
|
8554
|
-
return !1;
|
|
8555
|
-
const trimmedSelection = getTrimmedSelection({
|
|
8556
|
-
...snapshot,
|
|
8557
|
-
context: {
|
|
8558
|
-
...snapshot.context,
|
|
8559
|
-
value: snapshot.context.value,
|
|
8560
|
-
selection
|
|
8561
|
-
}
|
|
8562
|
-
});
|
|
8563
|
-
return trimmedSelection ? {
|
|
8564
|
-
selection: trimmedSelection
|
|
8565
|
-
} : !1;
|
|
8566
|
-
},
|
|
8567
|
-
actions: [(_, {
|
|
8568
|
-
selection
|
|
8569
8485
|
}) => [raise({
|
|
8570
|
-
|
|
8571
|
-
|
|
8486
|
+
...event,
|
|
8487
|
+
type: "delete"
|
|
8572
8488
|
})]]
|
|
8573
8489
|
})], abstractDeserializeBehaviors = [
|
|
8574
8490
|
defineBehavior({
|