@portabletext/editor 2.9.2 → 2.11.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.merge-text-blocks.cjs +1 -0
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs +6 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-dts/behavior.types.action.d.cts +79 -69
- package/lib/_chunks-dts/behavior.types.action.d.ts +79 -69
- package/lib/_chunks-es/util.merge-text-blocks.js +1 -0
- package/lib/_chunks-es/util.merge-text-blocks.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js +6 -1
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/index.cjs +232 -68
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +234 -70
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +3 -3
- package/lib/plugins/index.d.ts +3 -3
- package/lib/utils/index.d.cts +2 -2
- package/package.json +10 -10
- package/src/behaviors/behavior.abstract.insert.ts +109 -24
- package/src/behaviors/behavior.abstract.split.ts +1 -0
- package/src/behaviors/behavior.perform-event.ts +89 -67
- package/src/behaviors/behavior.types.event.ts +10 -3
- package/src/converters/converter.portable-text.ts +1 -0
- package/src/converters/converter.text-html.ts +1 -0
- package/src/converters/converter.text-plain.ts +1 -0
- package/src/editor/Editable.tsx +1 -0
- package/src/editor/editor-selector.ts +10 -1
- package/src/editor/without-normalizing-conditional.ts +13 -0
- package/src/internal-utils/parse-blocks.test.ts +14 -14
- package/src/internal-utils/parse-blocks.ts +9 -2
- package/src/internal-utils/test-editor.tsx +1 -25
- package/src/operations/behavior.operation.block.set.ts +4 -3
- package/src/operations/behavior.operation.block.unset.ts +8 -2
- package/src/operations/behavior.operation.insert.block.ts +4 -1
- package/src/operations/behavior.operation.insert.child.ts +95 -0
- package/src/operations/behavior.operations.ts +9 -0
- package/src/selectors/selector.get-trimmed-selection.test.ts +1 -0
- package/src/types/block-with-optional-key.ts +13 -1
- package/src/utils/util.merge-text-blocks.ts +1 -1
- package/src/utils/util.slice-blocks.ts +3 -3
- package/src/utils/util.slice-text-block.test.ts +54 -28
- package/src/plugins/plugin.internal.editor-actor-ref.tsx +0 -15
package/lib/index.js
CHANGED
|
@@ -8,14 +8,14 @@ import { Element as Element$1, Text, Range, Editor, Node, Point, Path, Transform
|
|
|
8
8
|
import { useSelected, useSlateSelector, useSlateStatic, useSlate, Editable, ReactEditor, withReact, Slate } from "slate-react";
|
|
9
9
|
import debug$f from "debug";
|
|
10
10
|
import { DOMEditor, isDOMNode, EDITOR_TO_PENDING_SELECTION, IS_FOCUSED, IS_READ_ONLY } from "slate-dom";
|
|
11
|
-
import { getBlockStartPoint, getBlockKeyFromSelectionPoint, getChildKeyFromSelectionPoint, blockOffsetToSpanSelectionPoint, defaultKeyGenerator, parseBlocks, parseBlock, parseAnnotation, isKeyedSegment, isListBlock, isTypedObject, getSelectionStartPoint, getSelectionEndPoint, getTextBlockText } from "./_chunks-es/util.slice-blocks.js";
|
|
11
|
+
import { getBlockStartPoint, getBlockKeyFromSelectionPoint, getChildKeyFromSelectionPoint, blockOffsetToSpanSelectionPoint, defaultKeyGenerator, parseBlocks, parseBlock, parseAnnotation, parseSpan, parseInlineObject, isKeyedSegment, isListBlock, isTypedObject, getSelectionStartPoint, getSelectionEndPoint, getTextBlockText } from "./_chunks-es/util.slice-blocks.js";
|
|
12
12
|
import { getBlockEndPoint, isSelectionCollapsed, isEqualSelectionPoints, isEmptyTextBlock } from "./_chunks-es/util.is-selection-collapsed.js";
|
|
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
16
|
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.is-selection-expanded.js";
|
|
17
17
|
import { getFocusInlineObject, getSelectedBlocks, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, isOverlappingSelection, isSelectingEntireBlocks, getMarkState, getActiveDecorators, getTrimmedSelection, getActiveAnnotationsMarks, isActiveAnnotation, getCaretWordSelection, getFocusBlockObject, getPreviousBlock, getNextBlock, 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-selecting-entire-blocks.js";
|
|
18
|
-
import { defineBehavior, forward, raise, effect
|
|
18
|
+
import { defineBehavior, forward, raise, effect } from "./behaviors/index.js";
|
|
19
19
|
import uniq from "lodash/uniq.js";
|
|
20
20
|
import { setup, fromCallback, assign, and, enqueueActions, emit, assertEvent, raise as raise$1, not, createActor } from "xstate";
|
|
21
21
|
import { compileSchemaDefinitionToPortableTextMemberSchemaTypes, createPortableTextMemberSchemaTypes, portableTextMemberSchemaTypesToSchema } from "@portabletext/sanity-bridge";
|
|
@@ -1118,6 +1118,11 @@ function getEditorSnapshot({
|
|
|
1118
1118
|
editorActorSnapshot,
|
|
1119
1119
|
slateEditorInstance
|
|
1120
1120
|
}) {
|
|
1121
|
+
const selection = slateEditorInstance.selection ? slateRangeToSelection({
|
|
1122
|
+
schema: editorActorSnapshot.context.schema,
|
|
1123
|
+
editor: slateEditorInstance,
|
|
1124
|
+
range: slateEditorInstance.selection
|
|
1125
|
+
}) : null;
|
|
1121
1126
|
return {
|
|
1122
1127
|
blockIndexMap: slateEditorInstance.blockIndexMap,
|
|
1123
1128
|
context: {
|
|
@@ -1127,7 +1132,7 @@ function getEditorSnapshot({
|
|
|
1127
1132
|
"edit mode": "read only"
|
|
1128
1133
|
}),
|
|
1129
1134
|
schema: editorActorSnapshot.context.schema,
|
|
1130
|
-
selection
|
|
1135
|
+
selection,
|
|
1131
1136
|
value: slateEditorInstance.value
|
|
1132
1137
|
},
|
|
1133
1138
|
decoratorState: slateEditorInstance.decoratorState
|
|
@@ -1955,6 +1960,7 @@ const RelayActorContext = createContext({}), debug$d = debugWithName("component:
|
|
|
1955
1960
|
},
|
|
1956
1961
|
blocks: result_1.insert,
|
|
1957
1962
|
options: {
|
|
1963
|
+
removeUnusedMarkDefs: !0,
|
|
1958
1964
|
validateFields: !1
|
|
1959
1965
|
}
|
|
1960
1966
|
}),
|
|
@@ -2423,6 +2429,7 @@ const converterJson = {
|
|
|
2423
2429
|
context: snapshot.context,
|
|
2424
2430
|
block,
|
|
2425
2431
|
options: {
|
|
2432
|
+
removeUnusedMarkDefs: !0,
|
|
2426
2433
|
validateFields: !1
|
|
2427
2434
|
}
|
|
2428
2435
|
});
|
|
@@ -2485,6 +2492,7 @@ function createConverterTextHtml(legacySchema) {
|
|
|
2485
2492
|
context: snapshot.context,
|
|
2486
2493
|
block,
|
|
2487
2494
|
options: {
|
|
2495
|
+
removeUnusedMarkDefs: !0,
|
|
2488
2496
|
validateFields: !1
|
|
2489
2497
|
}
|
|
2490
2498
|
});
|
|
@@ -2532,6 +2540,7 @@ function createConverterTextPlain(legacySchema) {
|
|
|
2532
2540
|
context: snapshot.context,
|
|
2533
2541
|
block,
|
|
2534
2542
|
options: {
|
|
2543
|
+
removeUnusedMarkDefs: !0,
|
|
2535
2544
|
validateFields: !1
|
|
2536
2545
|
}
|
|
2537
2546
|
});
|
|
@@ -4079,12 +4088,12 @@ const addAnnotationOperationImplementation = ({
|
|
|
4079
4088
|
context,
|
|
4080
4089
|
block: updatedBlock,
|
|
4081
4090
|
options: {
|
|
4091
|
+
removeUnusedMarkDefs: !1,
|
|
4082
4092
|
validateFields: !0
|
|
4083
4093
|
}
|
|
4084
4094
|
});
|
|
4085
4095
|
if (!parsedBlock)
|
|
4086
4096
|
throw new Error(`Unable to update block at ${JSON.stringify(operation.at)}`);
|
|
4087
|
-
parsedBlock.markDefs = updatedBlock.markDefs;
|
|
4088
4097
|
const slateBlock = toSlateValue([parsedBlock], {
|
|
4089
4098
|
schemaTypes: context.schema
|
|
4090
4099
|
})?.at(0);
|
|
@@ -4129,6 +4138,7 @@ const addAnnotationOperationImplementation = ({
|
|
|
4129
4138
|
context,
|
|
4130
4139
|
block: omit(parsedBlock, propsToRemove),
|
|
4131
4140
|
options: {
|
|
4141
|
+
removeUnusedMarkDefs: !0,
|
|
4132
4142
|
validateFields: !0
|
|
4133
4143
|
}
|
|
4134
4144
|
});
|
|
@@ -4146,6 +4156,7 @@ const addAnnotationOperationImplementation = ({
|
|
|
4146
4156
|
context,
|
|
4147
4157
|
block: omit(parsedBlock, operation.props.filter((prop) => prop !== "_type")),
|
|
4148
4158
|
options: {
|
|
4159
|
+
removeUnusedMarkDefs: !0,
|
|
4149
4160
|
validateFields: !0
|
|
4150
4161
|
}
|
|
4151
4162
|
});
|
|
@@ -4534,6 +4545,7 @@ const insertBlockOperationImplementation = ({
|
|
|
4534
4545
|
block: operation.block,
|
|
4535
4546
|
context,
|
|
4536
4547
|
options: {
|
|
4548
|
+
removeUnusedMarkDefs: !0,
|
|
4537
4549
|
validateFields: !0
|
|
4538
4550
|
}
|
|
4539
4551
|
});
|
|
@@ -4744,7 +4756,76 @@ function insertBlock({
|
|
|
4744
4756
|
}
|
|
4745
4757
|
}
|
|
4746
4758
|
}
|
|
4747
|
-
const
|
|
4759
|
+
const insertChildOperationImplementation = ({
|
|
4760
|
+
context,
|
|
4761
|
+
operation
|
|
4762
|
+
}) => {
|
|
4763
|
+
const focus = operation.editor.selection?.focus, focusBlockIndex = focus?.path.at(0), focusChildIndex = focus?.path.at(1);
|
|
4764
|
+
if (focusBlockIndex === void 0 || focusChildIndex === void 0)
|
|
4765
|
+
throw new Error("Unable to insert child without a focus");
|
|
4766
|
+
const [focusBlock, focusBlockPath] = getFocusBlock({
|
|
4767
|
+
editor: operation.editor
|
|
4768
|
+
});
|
|
4769
|
+
if (!focus || !focusBlock || !focusBlockPath)
|
|
4770
|
+
throw new Error("Unable to insert child without a focus block");
|
|
4771
|
+
if (!isTextBlock(context, focusBlock))
|
|
4772
|
+
throw new Error("Unable to insert child into a non-text block");
|
|
4773
|
+
const markDefs = focusBlock.markDefs ?? [], markDefKeyMap = /* @__PURE__ */ new Map();
|
|
4774
|
+
for (const markDef of markDefs)
|
|
4775
|
+
markDefKeyMap.set(markDef._key, markDef._key);
|
|
4776
|
+
const span = parseSpan({
|
|
4777
|
+
span: operation.child,
|
|
4778
|
+
context,
|
|
4779
|
+
markDefKeyMap,
|
|
4780
|
+
options: {
|
|
4781
|
+
validateFields: !0
|
|
4782
|
+
}
|
|
4783
|
+
});
|
|
4784
|
+
if (span) {
|
|
4785
|
+
const [focusSpan] = getFocusSpan({
|
|
4786
|
+
editor: operation.editor
|
|
4787
|
+
});
|
|
4788
|
+
focusSpan ? Transforms.insertNodes(operation.editor, span, {
|
|
4789
|
+
at: focus,
|
|
4790
|
+
select: !0
|
|
4791
|
+
}) : Transforms.insertNodes(operation.editor, span, {
|
|
4792
|
+
at: [focusBlockIndex, focusChildIndex + 1],
|
|
4793
|
+
select: !0
|
|
4794
|
+
});
|
|
4795
|
+
return;
|
|
4796
|
+
}
|
|
4797
|
+
const inlineObject = parseInlineObject({
|
|
4798
|
+
inlineObject: operation.child,
|
|
4799
|
+
context,
|
|
4800
|
+
options: {
|
|
4801
|
+
validateFields: !0
|
|
4802
|
+
}
|
|
4803
|
+
});
|
|
4804
|
+
if (inlineObject) {
|
|
4805
|
+
const {
|
|
4806
|
+
_key,
|
|
4807
|
+
_type,
|
|
4808
|
+
...rest
|
|
4809
|
+
} = inlineObject;
|
|
4810
|
+
Transforms.insertNodes(operation.editor, {
|
|
4811
|
+
_key,
|
|
4812
|
+
_type,
|
|
4813
|
+
children: [{
|
|
4814
|
+
_key: VOID_CHILD_KEY,
|
|
4815
|
+
_type: "span",
|
|
4816
|
+
text: "",
|
|
4817
|
+
marks: []
|
|
4818
|
+
}],
|
|
4819
|
+
value: rest,
|
|
4820
|
+
__inline: !0
|
|
4821
|
+
}, {
|
|
4822
|
+
at: [focusBlockIndex, focusChildIndex + 1],
|
|
4823
|
+
select: !0
|
|
4824
|
+
});
|
|
4825
|
+
return;
|
|
4826
|
+
}
|
|
4827
|
+
throw new Error("Unable to parse child");
|
|
4828
|
+
}, insertTextOperationImplementation = ({
|
|
4748
4829
|
context,
|
|
4749
4830
|
operation
|
|
4750
4831
|
}) => {
|
|
@@ -4848,6 +4929,7 @@ const insertTextOperationImplementation = ({
|
|
|
4848
4929
|
"history.redo": historyRedoOperationImplementation,
|
|
4849
4930
|
"history.undo": historyUndoOperationImplementation,
|
|
4850
4931
|
"insert.block": insertBlockOperationImplementation,
|
|
4932
|
+
"insert.child": insertChildOperationImplementation,
|
|
4851
4933
|
"insert.text": insertTextOperationImplementation,
|
|
4852
4934
|
"move.backward": moveBackwardOperationImplementation,
|
|
4853
4935
|
"move.block": moveBlockOperationImplementation,
|
|
@@ -4945,6 +5027,13 @@ function performOperation({
|
|
|
4945
5027
|
});
|
|
4946
5028
|
break;
|
|
4947
5029
|
}
|
|
5030
|
+
case "insert.child": {
|
|
5031
|
+
behaviorOperationImplementations["insert.child"]({
|
|
5032
|
+
context,
|
|
5033
|
+
operation
|
|
5034
|
+
});
|
|
5035
|
+
break;
|
|
5036
|
+
}
|
|
4948
5037
|
case "insert.text": {
|
|
4949
5038
|
behaviorOperationImplementations["insert.text"]({
|
|
4950
5039
|
context,
|
|
@@ -7722,7 +7811,11 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
|
|
|
7722
7811
|
}, coreBehaviorsConfig = [...coreAnnotationBehaviors, coreDecoratorBehaviors.strongShortcut, coreDecoratorBehaviors.emShortcut, coreDecoratorBehaviors.underlineShortcut, coreDecoratorBehaviors.codeShortcut, ...coreDndBehaviors, coreBlockObjectBehaviors.clickingAboveLonelyBlockObject, coreBlockObjectBehaviors.clickingBelowLonelyBlockObject, coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject, coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace, coreListBehaviors.mergeTextIntoListOnDelete, coreListBehaviors.mergeTextIntoListOnBackspace, coreListBehaviors.deletingListFromStart, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab, coreListBehaviors.inheritListLevel, coreListBehaviors.inheritListItem, coreListBehaviors.inheritListProperties, coreInsertBreakBehaviors.breakingAtTheEndOfTextBlock, coreInsertBreakBehaviors.breakingAtTheStartOfTextBlock, coreInsertBreakBehaviors.breakingEntireDocument, coreInsertBreakBehaviors.breakingEntireBlocks, coreInsertBreakBehaviors.breakingInlineObject].map((behavior) => ({
|
|
7723
7812
|
behavior,
|
|
7724
7813
|
priority: corePriority
|
|
7725
|
-
}))
|
|
7814
|
+
}));
|
|
7815
|
+
function withoutNormalizingConditional(editor, predicate, fn) {
|
|
7816
|
+
predicate() ? Editor.withoutNormalizing(editor, fn) : fn();
|
|
7817
|
+
}
|
|
7818
|
+
const abstractAnnotationBehaviors = [defineBehavior({
|
|
7726
7819
|
on: "annotation.set",
|
|
7727
7820
|
guard: ({
|
|
7728
7821
|
snapshot,
|
|
@@ -8504,21 +8597,63 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
|
|
|
8504
8597
|
type: "split"
|
|
8505
8598
|
})]]
|
|
8506
8599
|
}), defineBehavior({
|
|
8507
|
-
on: "insert.
|
|
8600
|
+
on: "insert.child",
|
|
8601
|
+
guard: ({
|
|
8602
|
+
snapshot
|
|
8603
|
+
}) => {
|
|
8604
|
+
const lastBlock = getLastBlock$1(snapshot);
|
|
8605
|
+
return !lastBlock || snapshot.context.selection ? !1 : {
|
|
8606
|
+
lastBlockEndPoint: getBlockEndPoint({
|
|
8607
|
+
context: snapshot.context,
|
|
8608
|
+
block: lastBlock
|
|
8609
|
+
})
|
|
8610
|
+
};
|
|
8611
|
+
},
|
|
8612
|
+
actions: [({
|
|
8613
|
+
event
|
|
8614
|
+
}, {
|
|
8615
|
+
lastBlockEndPoint
|
|
8616
|
+
}) => [raise({
|
|
8617
|
+
type: "select",
|
|
8618
|
+
at: {
|
|
8619
|
+
anchor: lastBlockEndPoint,
|
|
8620
|
+
focus: lastBlockEndPoint
|
|
8621
|
+
}
|
|
8622
|
+
}), raise(event)]]
|
|
8623
|
+
}), defineBehavior({
|
|
8624
|
+
on: "insert.child",
|
|
8625
|
+
guard: ({
|
|
8626
|
+
snapshot
|
|
8627
|
+
}) => {
|
|
8628
|
+
const focusTextBlock = getFocusTextBlock(snapshot);
|
|
8629
|
+
return snapshot.context.selection && !focusTextBlock;
|
|
8630
|
+
},
|
|
8508
8631
|
actions: [({
|
|
8509
8632
|
snapshot,
|
|
8510
8633
|
event
|
|
8511
|
-
}) => [
|
|
8634
|
+
}) => [raise({
|
|
8512
8635
|
type: "insert.block",
|
|
8513
8636
|
block: {
|
|
8514
8637
|
_type: snapshot.context.schema.block.name,
|
|
8515
8638
|
children: [{
|
|
8516
|
-
_type:
|
|
8517
|
-
|
|
8639
|
+
_type: snapshot.context.schema.span.name,
|
|
8640
|
+
text: "",
|
|
8641
|
+
marks: []
|
|
8518
8642
|
}]
|
|
8519
8643
|
},
|
|
8520
8644
|
placement: "auto",
|
|
8521
8645
|
select: "end"
|
|
8646
|
+
}), raise(event)]]
|
|
8647
|
+
}), defineBehavior({
|
|
8648
|
+
on: "insert.inline object",
|
|
8649
|
+
actions: [({
|
|
8650
|
+
event
|
|
8651
|
+
}) => [raise({
|
|
8652
|
+
type: "insert.child",
|
|
8653
|
+
child: {
|
|
8654
|
+
_type: event.inlineObject.name,
|
|
8655
|
+
...event.inlineObject.value
|
|
8656
|
+
}
|
|
8522
8657
|
})]]
|
|
8523
8658
|
}), defineBehavior({
|
|
8524
8659
|
on: "insert.soft break",
|
|
@@ -8530,33 +8665,59 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
|
|
|
8530
8665
|
}), defineBehavior({
|
|
8531
8666
|
on: "insert.span",
|
|
8532
8667
|
guard: ({
|
|
8533
|
-
snapshot
|
|
8534
|
-
|
|
8535
|
-
}) => ({
|
|
8536
|
-
markDefs: event.annotations?.map((annotation) => ({
|
|
8537
|
-
_type: annotation.name,
|
|
8538
|
-
_key: snapshot.context.keyGenerator(),
|
|
8539
|
-
...annotation.value
|
|
8540
|
-
})) ?? []
|
|
8541
|
-
}),
|
|
8668
|
+
snapshot
|
|
8669
|
+
}) => !getFocusTextBlock(snapshot),
|
|
8542
8670
|
actions: [({
|
|
8543
8671
|
snapshot,
|
|
8544
8672
|
event
|
|
8545
|
-
}
|
|
8546
|
-
markDefs
|
|
8547
|
-
}) => [execute({
|
|
8673
|
+
}) => [raise({
|
|
8548
8674
|
type: "insert.block",
|
|
8549
8675
|
block: {
|
|
8550
8676
|
_type: snapshot.context.schema.block.name,
|
|
8551
8677
|
children: [{
|
|
8552
8678
|
_type: snapshot.context.schema.span.name,
|
|
8553
|
-
text:
|
|
8554
|
-
marks: [
|
|
8555
|
-
}]
|
|
8556
|
-
markDefs
|
|
8679
|
+
text: "",
|
|
8680
|
+
marks: []
|
|
8681
|
+
}]
|
|
8557
8682
|
},
|
|
8558
8683
|
placement: "auto",
|
|
8559
8684
|
select: "end"
|
|
8685
|
+
}), raise(event)]]
|
|
8686
|
+
}), defineBehavior({
|
|
8687
|
+
on: "insert.span",
|
|
8688
|
+
guard: ({
|
|
8689
|
+
snapshot,
|
|
8690
|
+
event
|
|
8691
|
+
}) => {
|
|
8692
|
+
const focusTextBlock = getFocusTextBlock(snapshot);
|
|
8693
|
+
return {
|
|
8694
|
+
markDefs: event.annotations?.map((annotation) => ({
|
|
8695
|
+
_type: annotation.name,
|
|
8696
|
+
_key: snapshot.context.keyGenerator(),
|
|
8697
|
+
...annotation.value
|
|
8698
|
+
})) ?? [],
|
|
8699
|
+
focusTextBlock
|
|
8700
|
+
};
|
|
8701
|
+
},
|
|
8702
|
+
actions: [({
|
|
8703
|
+
snapshot,
|
|
8704
|
+
event
|
|
8705
|
+
}, {
|
|
8706
|
+
markDefs,
|
|
8707
|
+
focusTextBlock
|
|
8708
|
+
}) => [...focusTextBlock ? [raise({
|
|
8709
|
+
type: "block.set",
|
|
8710
|
+
at: focusTextBlock.path,
|
|
8711
|
+
props: {
|
|
8712
|
+
markDefs: [...focusTextBlock.node.markDefs ?? [], ...markDefs]
|
|
8713
|
+
}
|
|
8714
|
+
})] : [], raise({
|
|
8715
|
+
type: "insert.child",
|
|
8716
|
+
child: {
|
|
8717
|
+
_type: snapshot.context.schema.span.name,
|
|
8718
|
+
text: event.text,
|
|
8719
|
+
marks: [...event.decorators ?? [], ...markDefs.map((markDef) => markDef._key)]
|
|
8720
|
+
}
|
|
8560
8721
|
})]]
|
|
8561
8722
|
})], abstractKeyboardBehaviors = [
|
|
8562
8723
|
/**
|
|
@@ -9034,6 +9195,7 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
|
|
|
9034
9195
|
}),
|
|
9035
9196
|
context: snapshot.context,
|
|
9036
9197
|
options: {
|
|
9198
|
+
removeUnusedMarkDefs: !0,
|
|
9037
9199
|
validateFields: !1
|
|
9038
9200
|
}
|
|
9039
9201
|
});
|
|
@@ -9288,62 +9450,64 @@ function performEvent({
|
|
|
9288
9450
|
nativeEventPrevented = actions.some((action) => action.type === "raise" || action.type === "execute") || !actions.some((action) => action.type === "forward");
|
|
9289
9451
|
let undoStepCreated = !1;
|
|
9290
9452
|
actions.some((action) => action.type === "execute") && (createUndoStep(editor), undoStepCreated = !0);
|
|
9291
|
-
|
|
9292
|
-
|
|
9293
|
-
|
|
9294
|
-
|
|
9295
|
-
|
|
9453
|
+
const actionTypes = actions.map((action) => action.type), uniqueActionTypes = new Set(actionTypes), raiseGroup = actionTypes.length > 1 && uniqueActionTypes.size === 1 && uniqueActionTypes.has("raise"), executeGroup = actionTypes.length > 1 && uniqueActionTypes.size === 1 && uniqueActionTypes.has("execute");
|
|
9454
|
+
withoutNormalizingConditional(editor, () => raiseGroup || executeGroup, () => {
|
|
9455
|
+
for (const action of actions) {
|
|
9456
|
+
if (action.type === "effect") {
|
|
9457
|
+
try {
|
|
9458
|
+
action.effect({
|
|
9459
|
+
send: sendBack
|
|
9460
|
+
});
|
|
9461
|
+
} catch (error) {
|
|
9462
|
+
console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
|
|
9463
|
+
}
|
|
9464
|
+
continue;
|
|
9465
|
+
}
|
|
9466
|
+
if (action.type === "forward") {
|
|
9467
|
+
const remainingEventBehaviors2 = eventBehaviors.slice(eventBehaviorIndex + 1);
|
|
9468
|
+
performEvent({
|
|
9469
|
+
mode: mode === "execute" ? "execute" : "forward",
|
|
9470
|
+
behaviors,
|
|
9471
|
+
remainingEventBehaviors: remainingEventBehaviors2,
|
|
9472
|
+
event: action.event,
|
|
9473
|
+
editor,
|
|
9474
|
+
keyGenerator,
|
|
9475
|
+
schema,
|
|
9476
|
+
getSnapshot,
|
|
9477
|
+
nativeEvent,
|
|
9478
|
+
sendBack
|
|
9296
9479
|
});
|
|
9297
|
-
|
|
9298
|
-
|
|
9480
|
+
continue;
|
|
9481
|
+
}
|
|
9482
|
+
if (action.type === "raise") {
|
|
9483
|
+
performEvent({
|
|
9484
|
+
mode: mode === "execute" ? "execute" : "raise",
|
|
9485
|
+
behaviors,
|
|
9486
|
+
remainingEventBehaviors: mode === "execute" ? remainingEventBehaviors : behaviors,
|
|
9487
|
+
event: action.event,
|
|
9488
|
+
editor,
|
|
9489
|
+
keyGenerator,
|
|
9490
|
+
schema,
|
|
9491
|
+
getSnapshot,
|
|
9492
|
+
nativeEvent,
|
|
9493
|
+
sendBack
|
|
9494
|
+
});
|
|
9495
|
+
continue;
|
|
9299
9496
|
}
|
|
9300
|
-
continue;
|
|
9301
|
-
}
|
|
9302
|
-
if (action.type === "forward") {
|
|
9303
|
-
const remainingEventBehaviors2 = eventBehaviors.slice(eventBehaviorIndex + 1);
|
|
9304
|
-
performEvent({
|
|
9305
|
-
mode: mode === "execute" ? "execute" : "forward",
|
|
9306
|
-
behaviors,
|
|
9307
|
-
remainingEventBehaviors: remainingEventBehaviors2,
|
|
9308
|
-
event: action.event,
|
|
9309
|
-
editor,
|
|
9310
|
-
keyGenerator,
|
|
9311
|
-
schema,
|
|
9312
|
-
getSnapshot,
|
|
9313
|
-
nativeEvent,
|
|
9314
|
-
sendBack
|
|
9315
|
-
});
|
|
9316
|
-
continue;
|
|
9317
|
-
}
|
|
9318
|
-
if (action.type === "raise") {
|
|
9319
9497
|
performEvent({
|
|
9320
|
-
mode:
|
|
9498
|
+
mode: "execute",
|
|
9321
9499
|
behaviors,
|
|
9322
|
-
remainingEventBehaviors:
|
|
9500
|
+
remainingEventBehaviors: [],
|
|
9323
9501
|
event: action.event,
|
|
9324
9502
|
editor,
|
|
9325
9503
|
keyGenerator,
|
|
9326
9504
|
schema,
|
|
9327
9505
|
getSnapshot,
|
|
9328
|
-
nativeEvent,
|
|
9506
|
+
nativeEvent: void 0,
|
|
9329
9507
|
sendBack
|
|
9330
9508
|
});
|
|
9331
|
-
continue;
|
|
9332
9509
|
}
|
|
9333
|
-
|
|
9334
|
-
mode: "execute",
|
|
9335
|
-
behaviors,
|
|
9336
|
-
remainingEventBehaviors: [],
|
|
9337
|
-
event: action.event,
|
|
9338
|
-
editor,
|
|
9339
|
-
keyGenerator,
|
|
9340
|
-
schema,
|
|
9341
|
-
getSnapshot,
|
|
9342
|
-
nativeEvent: void 0,
|
|
9343
|
-
sendBack
|
|
9344
|
-
});
|
|
9345
|
-
}
|
|
9346
|
-
undoStepCreated && clearUndoStep(editor);
|
|
9510
|
+
}), undoStepCreated && clearUndoStep(editor);
|
|
9347
9511
|
}
|
|
9348
9512
|
break;
|
|
9349
9513
|
}
|