@portabletext/editor 2.9.1 → 2.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +9 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-dts/behavior.types.action.d.cts +9 -9
- package/lib/_chunks-dts/behavior.types.action.d.ts +3 -3
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +9 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/index.cjs +268 -322
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +269 -323
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +3 -3
- package/lib/plugins/index.d.ts +3 -3
- package/package.json +3 -3
- package/src/behaviors/behavior.perform-event.ts +24 -80
- package/src/editor/plugins/create-with-event-listeners.ts +13 -14
- package/src/editor/sync-machine.ts +9 -0
- package/src/editor/with-performing-behavior-operation.ts +21 -0
- package/src/internal-utils/slate-utils.test.tsx +119 -0
- package/src/internal-utils/slate-utils.ts +14 -1
- package/src/internal-utils/text-marks.ts +1 -1
- package/src/internal-utils/values.ts +1 -55
- package/src/operations/behavior.operation.block.set.ts +17 -36
- package/src/operations/behavior.operations.ts +131 -128
- package/src/selectors/selector.get-mark-state.ts +19 -5
- package/src/editor/with-applying-behavior-operations.ts +0 -18
package/lib/index.js
CHANGED
|
@@ -14,7 +14,7 @@ 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
|
-
import { getFocusInlineObject, getSelectedBlocks, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, isOverlappingSelection, isSelectingEntireBlocks, getMarkState, getActiveDecorators,
|
|
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
18
|
import { defineBehavior, forward, raise, effect, execute } 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";
|
|
@@ -185,7 +185,14 @@ function getFocusSpan({
|
|
|
185
185
|
if (!editor.selection)
|
|
186
186
|
return [void 0, void 0];
|
|
187
187
|
try {
|
|
188
|
-
const [
|
|
188
|
+
const [focusBlock] = getFocusBlock({
|
|
189
|
+
editor
|
|
190
|
+
});
|
|
191
|
+
if (!focusBlock)
|
|
192
|
+
return [void 0, void 0];
|
|
193
|
+
if (!editor.isTextBlock(focusBlock))
|
|
194
|
+
return [void 0, void 0];
|
|
195
|
+
const [node, path] = Editor.node(editor, editor.selection.focus.path.slice(0, 2));
|
|
189
196
|
if (editor.isTextSpan(node))
|
|
190
197
|
return [node, path];
|
|
191
198
|
} catch {
|
|
@@ -2630,46 +2637,6 @@ function createPlaceholderBlock(context) {
|
|
|
2630
2637
|
}]
|
|
2631
2638
|
};
|
|
2632
2639
|
}
|
|
2633
|
-
const insertTextOperationImplementation = ({
|
|
2634
|
-
context,
|
|
2635
|
-
operation
|
|
2636
|
-
}) => {
|
|
2637
|
-
const snapshot = {
|
|
2638
|
-
blockIndexMap: operation.editor.blockIndexMap,
|
|
2639
|
-
context: {
|
|
2640
|
-
value: operation.editor.value,
|
|
2641
|
-
selection: operation.editor.selection ? slateRangeToSelection({
|
|
2642
|
-
schema: context.schema,
|
|
2643
|
-
editor: operation.editor,
|
|
2644
|
-
range: operation.editor.selection
|
|
2645
|
-
}) : null,
|
|
2646
|
-
schema: context.schema,
|
|
2647
|
-
keyGenerator: context.keyGenerator,
|
|
2648
|
-
converters: [],
|
|
2649
|
-
readOnly: !1
|
|
2650
|
-
},
|
|
2651
|
-
decoratorState: operation.editor.decoratorState
|
|
2652
|
-
}, markState = getMarkState(snapshot), activeDecorators = getActiveDecorators(snapshot), activeAnnotations = getActiveAnnotationsMarks(snapshot), [focusSpan] = getFocusSpan({
|
|
2653
|
-
editor: operation.editor
|
|
2654
|
-
});
|
|
2655
|
-
if (!focusSpan) {
|
|
2656
|
-
Transforms.insertText(operation.editor, operation.text);
|
|
2657
|
-
return;
|
|
2658
|
-
}
|
|
2659
|
-
if (markState && markState.state === "unchanged") {
|
|
2660
|
-
const markStateDecorators = (markState.marks ?? []).filter((mark) => context.schema.decorators.map((decorator) => decorator.name).includes(mark));
|
|
2661
|
-
if (markStateDecorators.length === activeDecorators.length && markStateDecorators.every((mark) => activeDecorators.includes(mark))) {
|
|
2662
|
-
Transforms.insertText(operation.editor, operation.text);
|
|
2663
|
-
return;
|
|
2664
|
-
}
|
|
2665
|
-
}
|
|
2666
|
-
Transforms.insertNodes(operation.editor, {
|
|
2667
|
-
_type: focusSpan._type,
|
|
2668
|
-
_key: context.keyGenerator(),
|
|
2669
|
-
text: operation.text,
|
|
2670
|
-
marks: [...activeDecorators, ...activeAnnotations]
|
|
2671
|
-
}), EDITOR_TO_PENDING_SELECTION.set(operation.editor, operation.editor.selection), operation.editor.decoratorState = {};
|
|
2672
|
-
};
|
|
2673
2640
|
function getPreviousSpan({
|
|
2674
2641
|
editor,
|
|
2675
2642
|
blockPath,
|
|
@@ -4096,55 +4063,35 @@ const addAnnotationOperationImplementation = ({
|
|
|
4096
4063
|
context,
|
|
4097
4064
|
operation
|
|
4098
4065
|
}) => {
|
|
4099
|
-
const
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
selection: {
|
|
4104
|
-
anchor: {
|
|
4105
|
-
path: operation.at,
|
|
4106
|
-
offset: 0
|
|
4107
|
-
},
|
|
4108
|
-
focus: {
|
|
4109
|
-
path: operation.at,
|
|
4110
|
-
offset: 0
|
|
4111
|
-
}
|
|
4112
|
-
}
|
|
4113
|
-
},
|
|
4114
|
-
blockIndexMap: operation.editor.blockIndexMap
|
|
4115
|
-
});
|
|
4116
|
-
if (!location)
|
|
4117
|
-
throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
|
|
4118
|
-
const block = Editor.node(operation.editor, location, {
|
|
4119
|
-
depth: 1
|
|
4120
|
-
})?.[0];
|
|
4066
|
+
const blockIndex = operation.editor.blockIndexMap.get(operation.at[0]._key);
|
|
4067
|
+
if (blockIndex === void 0)
|
|
4068
|
+
throw new Error(`Unable to find block index for block at ${JSON.stringify(operation.at)}`);
|
|
4069
|
+
const block = operation.editor.value.at(blockIndex);
|
|
4121
4070
|
if (!block)
|
|
4122
4071
|
throw new Error(`Unable to find block at ${JSON.stringify(operation.at)}`);
|
|
4123
|
-
const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(operation.editor)).at(0);
|
|
4124
|
-
if (!parsedBlock)
|
|
4125
|
-
throw new Error(`Unable to parse block at ${JSON.stringify(operation.at)}`);
|
|
4126
4072
|
const {
|
|
4127
4073
|
_type,
|
|
4128
4074
|
...filteredProps
|
|
4129
|
-
} = operation.props, updatedBlock =
|
|
4075
|
+
} = operation.props, updatedBlock = {
|
|
4076
|
+
...block,
|
|
4077
|
+
...filteredProps
|
|
4078
|
+
}, parsedBlock = parseBlock({
|
|
4130
4079
|
context,
|
|
4131
|
-
block:
|
|
4132
|
-
...parsedBlock,
|
|
4133
|
-
...filteredProps
|
|
4134
|
-
},
|
|
4080
|
+
block: updatedBlock,
|
|
4135
4081
|
options: {
|
|
4136
4082
|
validateFields: !0
|
|
4137
4083
|
}
|
|
4138
4084
|
});
|
|
4139
|
-
if (!
|
|
4085
|
+
if (!parsedBlock)
|
|
4140
4086
|
throw new Error(`Unable to update block at ${JSON.stringify(operation.at)}`);
|
|
4141
|
-
|
|
4087
|
+
parsedBlock.markDefs = updatedBlock.markDefs;
|
|
4088
|
+
const slateBlock = toSlateValue([parsedBlock], {
|
|
4142
4089
|
schemaTypes: context.schema
|
|
4143
4090
|
})?.at(0);
|
|
4144
4091
|
if (!slateBlock)
|
|
4145
4092
|
throw new Error("Unable to convert block to Slate value");
|
|
4146
4093
|
Transforms.setNodes(operation.editor, slateBlock, {
|
|
4147
|
-
at:
|
|
4094
|
+
at: [blockIndex]
|
|
4148
4095
|
});
|
|
4149
4096
|
}, blockUnsetOperationImplementation = ({
|
|
4150
4097
|
context,
|
|
@@ -4797,7 +4744,46 @@ function insertBlock({
|
|
|
4797
4744
|
}
|
|
4798
4745
|
}
|
|
4799
4746
|
}
|
|
4800
|
-
const
|
|
4747
|
+
const insertTextOperationImplementation = ({
|
|
4748
|
+
context,
|
|
4749
|
+
operation
|
|
4750
|
+
}) => {
|
|
4751
|
+
const snapshot = {
|
|
4752
|
+
blockIndexMap: operation.editor.blockIndexMap,
|
|
4753
|
+
context: {
|
|
4754
|
+
value: operation.editor.value,
|
|
4755
|
+
selection: operation.editor.selection ? slateRangeToSelection({
|
|
4756
|
+
schema: context.schema,
|
|
4757
|
+
editor: operation.editor,
|
|
4758
|
+
range: operation.editor.selection
|
|
4759
|
+
}) : null,
|
|
4760
|
+
schema: context.schema,
|
|
4761
|
+
keyGenerator: context.keyGenerator,
|
|
4762
|
+
converters: [],
|
|
4763
|
+
readOnly: !1
|
|
4764
|
+
},
|
|
4765
|
+
decoratorState: operation.editor.decoratorState
|
|
4766
|
+
}, markState = getMarkState(snapshot), activeDecorators = getActiveDecorators(snapshot), activeAnnotations = getActiveAnnotationsMarks(snapshot), [focusSpan] = getFocusSpan({
|
|
4767
|
+
editor: operation.editor
|
|
4768
|
+
});
|
|
4769
|
+
if (!focusSpan) {
|
|
4770
|
+
Transforms.insertText(operation.editor, operation.text);
|
|
4771
|
+
return;
|
|
4772
|
+
}
|
|
4773
|
+
if (markState && markState.state === "unchanged") {
|
|
4774
|
+
const markStateDecorators = (markState.marks ?? []).filter((mark) => context.schema.decorators.map((decorator) => decorator.name).includes(mark));
|
|
4775
|
+
if (markStateDecorators.length === activeDecorators.length && markStateDecorators.every((mark) => activeDecorators.includes(mark))) {
|
|
4776
|
+
Transforms.insertText(operation.editor, operation.text);
|
|
4777
|
+
return;
|
|
4778
|
+
}
|
|
4779
|
+
}
|
|
4780
|
+
Transforms.insertNodes(operation.editor, {
|
|
4781
|
+
_type: focusSpan._type,
|
|
4782
|
+
_key: context.keyGenerator(),
|
|
4783
|
+
text: operation.text,
|
|
4784
|
+
marks: [...activeDecorators, ...activeAnnotations]
|
|
4785
|
+
}), EDITOR_TO_PENDING_SELECTION.set(operation.editor, operation.editor.selection), operation.editor.decoratorState = {};
|
|
4786
|
+
}, moveBackwardOperationImplementation = ({
|
|
4801
4787
|
operation
|
|
4802
4788
|
}) => {
|
|
4803
4789
|
Transforms.move(operation.editor, {
|
|
@@ -4872,141 +4858,141 @@ function performOperation({
|
|
|
4872
4858
|
context,
|
|
4873
4859
|
operation
|
|
4874
4860
|
}) {
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
|
|
4861
|
+
Editor.withoutNormalizing(operation.editor, () => {
|
|
4862
|
+
try {
|
|
4863
|
+
switch (operation.type) {
|
|
4864
|
+
case "annotation.add": {
|
|
4865
|
+
behaviorOperationImplementations["annotation.add"]({
|
|
4866
|
+
context,
|
|
4867
|
+
operation
|
|
4868
|
+
});
|
|
4869
|
+
break;
|
|
4870
|
+
}
|
|
4871
|
+
case "annotation.remove": {
|
|
4872
|
+
behaviorOperationImplementations["annotation.remove"]({
|
|
4873
|
+
context,
|
|
4874
|
+
operation
|
|
4875
|
+
});
|
|
4876
|
+
break;
|
|
4877
|
+
}
|
|
4878
|
+
case "block.set": {
|
|
4879
|
+
behaviorOperationImplementations["block.set"]({
|
|
4880
|
+
context,
|
|
4881
|
+
operation
|
|
4882
|
+
});
|
|
4883
|
+
break;
|
|
4884
|
+
}
|
|
4885
|
+
case "block.unset": {
|
|
4886
|
+
behaviorOperationImplementations["block.unset"]({
|
|
4887
|
+
context,
|
|
4888
|
+
operation
|
|
4889
|
+
});
|
|
4890
|
+
break;
|
|
4891
|
+
}
|
|
4892
|
+
case "child.set": {
|
|
4893
|
+
behaviorOperationImplementations["child.set"]({
|
|
4894
|
+
context,
|
|
4895
|
+
operation
|
|
4896
|
+
});
|
|
4897
|
+
break;
|
|
4898
|
+
}
|
|
4899
|
+
case "child.unset": {
|
|
4900
|
+
behaviorOperationImplementations["child.unset"]({
|
|
4901
|
+
context,
|
|
4902
|
+
operation
|
|
4903
|
+
});
|
|
4904
|
+
break;
|
|
4905
|
+
}
|
|
4906
|
+
case "decorator.add": {
|
|
4907
|
+
behaviorOperationImplementations["decorator.add"]({
|
|
4908
|
+
context,
|
|
4909
|
+
operation
|
|
4910
|
+
});
|
|
4911
|
+
break;
|
|
4912
|
+
}
|
|
4913
|
+
case "decorator.remove": {
|
|
4914
|
+
behaviorOperationImplementations["decorator.remove"]({
|
|
4915
|
+
context,
|
|
4916
|
+
operation
|
|
4917
|
+
});
|
|
4918
|
+
break;
|
|
4919
|
+
}
|
|
4920
|
+
case "delete": {
|
|
4921
|
+
behaviorOperationImplementations.delete({
|
|
4922
|
+
context,
|
|
4923
|
+
operation
|
|
4924
|
+
});
|
|
4925
|
+
break;
|
|
4926
|
+
}
|
|
4927
|
+
case "history.redo": {
|
|
4928
|
+
behaviorOperationImplementations["history.redo"]({
|
|
4929
|
+
context,
|
|
4930
|
+
operation
|
|
4931
|
+
});
|
|
4932
|
+
break;
|
|
4933
|
+
}
|
|
4934
|
+
case "history.undo": {
|
|
4935
|
+
behaviorOperationImplementations["history.undo"]({
|
|
4936
|
+
context,
|
|
4937
|
+
operation
|
|
4938
|
+
});
|
|
4939
|
+
break;
|
|
4940
|
+
}
|
|
4941
|
+
case "insert.block": {
|
|
4942
|
+
behaviorOperationImplementations["insert.block"]({
|
|
4943
|
+
context,
|
|
4944
|
+
operation
|
|
4945
|
+
});
|
|
4946
|
+
break;
|
|
4947
|
+
}
|
|
4948
|
+
case "insert.text": {
|
|
4949
|
+
behaviorOperationImplementations["insert.text"]({
|
|
4950
|
+
context,
|
|
4951
|
+
operation
|
|
4952
|
+
});
|
|
4953
|
+
break;
|
|
4954
|
+
}
|
|
4955
|
+
case "move.backward": {
|
|
4956
|
+
behaviorOperationImplementations["move.backward"]({
|
|
4957
|
+
context,
|
|
4958
|
+
operation
|
|
4959
|
+
});
|
|
4960
|
+
break;
|
|
4961
|
+
}
|
|
4962
|
+
case "move.block": {
|
|
4963
|
+
behaviorOperationImplementations["move.block"]({
|
|
4964
|
+
context,
|
|
4965
|
+
operation
|
|
4966
|
+
});
|
|
4967
|
+
break;
|
|
4968
|
+
}
|
|
4969
|
+
case "move.forward": {
|
|
4970
|
+
behaviorOperationImplementations["move.forward"]({
|
|
4971
|
+
context,
|
|
4972
|
+
operation
|
|
4973
|
+
});
|
|
4974
|
+
break;
|
|
4975
|
+
}
|
|
4976
|
+
default: {
|
|
4977
|
+
behaviorOperationImplementations.select({
|
|
4978
|
+
context,
|
|
4979
|
+
operation
|
|
4980
|
+
});
|
|
4981
|
+
break;
|
|
4982
|
+
}
|
|
4995
4983
|
}
|
|
4984
|
+
} catch (error) {
|
|
4985
|
+
console.error(new Error(`Executing "${operation.type}" failed due to: ${error.message}`));
|
|
4996
4986
|
}
|
|
4997
|
-
}
|
|
4998
|
-
console.error(new Error(`Executing "${operation.type}" failed due to: ${error.message}`));
|
|
4999
|
-
}
|
|
5000
|
-
}
|
|
5001
|
-
const CURRENT_OPERATION_ID = /* @__PURE__ */ new WeakMap();
|
|
5002
|
-
function withApplyingBehaviorOperations(editor, fn) {
|
|
5003
|
-
CURRENT_OPERATION_ID.set(editor, defaultKeyGenerator()), Editor.withoutNormalizing(editor, fn), CURRENT_OPERATION_ID.set(editor, void 0);
|
|
4987
|
+
});
|
|
5004
4988
|
}
|
|
5005
|
-
|
|
5006
|
-
|
|
4989
|
+
const IS_PERFORMING_OPERATION = /* @__PURE__ */ new WeakMap();
|
|
4990
|
+
function withPerformingBehaviorOperation(editor, fn) {
|
|
4991
|
+
const prev = IS_PERFORMING_OPERATION.get(editor);
|
|
4992
|
+
IS_PERFORMING_OPERATION.set(editor, !0), fn(), IS_PERFORMING_OPERATION.set(editor, prev);
|
|
5007
4993
|
}
|
|
5008
|
-
function
|
|
5009
|
-
return
|
|
4994
|
+
function isPerformingBehaviorOperation(editor) {
|
|
4995
|
+
return IS_PERFORMING_OPERATION.get(editor) ?? !1;
|
|
5010
4996
|
}
|
|
5011
4997
|
function createWithEventListeners(editorActor) {
|
|
5012
4998
|
return function(editor) {
|
|
@@ -5017,7 +5003,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5017
5003
|
select
|
|
5018
5004
|
} = editor;
|
|
5019
5005
|
return editor.delete = (options) => {
|
|
5020
|
-
if (
|
|
5006
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5021
5007
|
editorDelete(options);
|
|
5022
5008
|
return;
|
|
5023
5009
|
}
|
|
@@ -5046,7 +5032,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5046
5032
|
editor
|
|
5047
5033
|
});
|
|
5048
5034
|
}, editor.deleteBackward = (unit) => {
|
|
5049
|
-
if (
|
|
5035
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5050
5036
|
console.error("Unexpected call to .deleteBackward(...)");
|
|
5051
5037
|
return;
|
|
5052
5038
|
}
|
|
@@ -5059,7 +5045,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5059
5045
|
editor
|
|
5060
5046
|
});
|
|
5061
5047
|
}, editor.deleteForward = (unit) => {
|
|
5062
|
-
if (
|
|
5048
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5063
5049
|
console.error("Unexpected call to .deleteForward(...)");
|
|
5064
5050
|
return;
|
|
5065
5051
|
}
|
|
@@ -5072,7 +5058,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5072
5058
|
editor
|
|
5073
5059
|
});
|
|
5074
5060
|
}, editor.insertBreak = () => {
|
|
5075
|
-
if (
|
|
5061
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5076
5062
|
console.error("Unexpected call to .insertBreak(...)");
|
|
5077
5063
|
return;
|
|
5078
5064
|
}
|
|
@@ -5084,7 +5070,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5084
5070
|
editor
|
|
5085
5071
|
});
|
|
5086
5072
|
}, editor.insertData = (dataTransfer) => {
|
|
5087
|
-
if (
|
|
5073
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5088
5074
|
console.error("Unexpected call to .insertData(...)");
|
|
5089
5075
|
return;
|
|
5090
5076
|
}
|
|
@@ -5099,13 +5085,14 @@ function createWithEventListeners(editorActor) {
|
|
|
5099
5085
|
editor
|
|
5100
5086
|
});
|
|
5101
5087
|
}, editor.insertSoftBreak = () => {
|
|
5102
|
-
if (
|
|
5103
|
-
|
|
5088
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5089
|
+
performOperation({
|
|
5104
5090
|
context: {
|
|
5105
5091
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
5106
5092
|
schema: editorActor.getSnapshot().context.schema
|
|
5107
5093
|
},
|
|
5108
5094
|
operation: {
|
|
5095
|
+
type: "insert.text",
|
|
5109
5096
|
text: `
|
|
5110
5097
|
`,
|
|
5111
5098
|
editor
|
|
@@ -5121,13 +5108,14 @@ function createWithEventListeners(editorActor) {
|
|
|
5121
5108
|
editor
|
|
5122
5109
|
});
|
|
5123
5110
|
}, editor.insertText = (text) => {
|
|
5124
|
-
if (
|
|
5125
|
-
|
|
5111
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5112
|
+
performOperation({
|
|
5126
5113
|
context: {
|
|
5127
5114
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
5128
5115
|
schema: editorActor.getSnapshot().context.schema
|
|
5129
5116
|
},
|
|
5130
5117
|
operation: {
|
|
5118
|
+
type: "insert.text",
|
|
5131
5119
|
text,
|
|
5132
5120
|
editor
|
|
5133
5121
|
}
|
|
@@ -5143,7 +5131,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5143
5131
|
editor
|
|
5144
5132
|
});
|
|
5145
5133
|
}, editor.redo = () => {
|
|
5146
|
-
if (
|
|
5134
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5147
5135
|
performOperation({
|
|
5148
5136
|
context: {
|
|
5149
5137
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
@@ -5164,7 +5152,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5164
5152
|
editor
|
|
5165
5153
|
});
|
|
5166
5154
|
}, editor.select = (location) => {
|
|
5167
|
-
if (
|
|
5155
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5168
5156
|
select(location);
|
|
5169
5157
|
return;
|
|
5170
5158
|
}
|
|
@@ -5184,7 +5172,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5184
5172
|
}, editor.setFragmentData = () => {
|
|
5185
5173
|
console.error("Unexpected call to .setFragmentData(...)");
|
|
5186
5174
|
}, editor.undo = () => {
|
|
5187
|
-
if (
|
|
5175
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5188
5176
|
performOperation({
|
|
5189
5177
|
context: {
|
|
5190
5178
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
@@ -9253,7 +9241,7 @@ function performEvent({
|
|
|
9253
9241
|
return listenedNamespace !== void 0 && eventNamespace !== void 0 && listenedNamespace === eventNamespace || listenedNamespace !== void 0 && eventNamespace === void 0 && listenedNamespace === event.type ? !0 : behavior.on === event.type;
|
|
9254
9242
|
});
|
|
9255
9243
|
if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
|
|
9256
|
-
nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor),
|
|
9244
|
+
nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor), withPerformingBehaviorOperation(editor, () => {
|
|
9257
9245
|
debug$6(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
9258
9246
|
context: {
|
|
9259
9247
|
keyGenerator,
|
|
@@ -9295,117 +9283,72 @@ function performEvent({
|
|
|
9295
9283
|
} catch (error) {
|
|
9296
9284
|
console.error(new Error(`Evaluating actions for "${event.type}" failed due to: ${error.message}`));
|
|
9297
9285
|
}
|
|
9298
|
-
if (actions.length
|
|
9299
|
-
|
|
9300
|
-
|
|
9301
|
-
|
|
9302
|
-
|
|
9303
|
-
|
|
9304
|
-
|
|
9305
|
-
|
|
9306
|
-
|
|
9307
|
-
|
|
9308
|
-
console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
|
|
9309
|
-
}
|
|
9310
|
-
continue;
|
|
9311
|
-
}
|
|
9312
|
-
if (action.type === "forward") {
|
|
9313
|
-
const remainingEventBehaviors2 = eventBehaviors.slice(eventBehaviorIndex + 1);
|
|
9314
|
-
performEvent({
|
|
9315
|
-
mode: "forward",
|
|
9316
|
-
behaviors,
|
|
9317
|
-
remainingEventBehaviors: remainingEventBehaviors2,
|
|
9318
|
-
event: action.event,
|
|
9319
|
-
editor,
|
|
9320
|
-
keyGenerator,
|
|
9321
|
-
schema,
|
|
9322
|
-
getSnapshot,
|
|
9323
|
-
nativeEvent,
|
|
9324
|
-
sendBack
|
|
9325
|
-
});
|
|
9326
|
-
continue;
|
|
9327
|
-
}
|
|
9328
|
-
if (action.type === "raise") {
|
|
9329
|
-
performEvent({
|
|
9330
|
-
mode: "raise",
|
|
9331
|
-
behaviors,
|
|
9332
|
-
remainingEventBehaviors: behaviors,
|
|
9333
|
-
event: action.event,
|
|
9334
|
-
editor,
|
|
9335
|
-
keyGenerator,
|
|
9336
|
-
schema,
|
|
9337
|
-
getSnapshot,
|
|
9338
|
-
nativeEvent,
|
|
9339
|
-
sendBack
|
|
9340
|
-
});
|
|
9341
|
-
continue;
|
|
9342
|
-
}
|
|
9343
|
-
performEvent({
|
|
9344
|
-
mode: "execute",
|
|
9345
|
-
behaviors,
|
|
9346
|
-
remainingEventBehaviors: [],
|
|
9347
|
-
event: action.event,
|
|
9348
|
-
editor,
|
|
9349
|
-
keyGenerator,
|
|
9350
|
-
schema,
|
|
9351
|
-
getSnapshot,
|
|
9352
|
-
nativeEvent: void 0,
|
|
9353
|
-
sendBack
|
|
9286
|
+
if (actions.length === 0)
|
|
9287
|
+
continue;
|
|
9288
|
+
nativeEventPrevented = actions.some((action) => action.type === "raise" || action.type === "execute") || !actions.some((action) => action.type === "forward");
|
|
9289
|
+
let undoStepCreated = !1;
|
|
9290
|
+
actions.some((action) => action.type === "execute") && (createUndoStep(editor), undoStepCreated = !0);
|
|
9291
|
+
for (const action of actions) {
|
|
9292
|
+
if (action.type === "effect") {
|
|
9293
|
+
try {
|
|
9294
|
+
action.effect({
|
|
9295
|
+
send: sendBack
|
|
9354
9296
|
});
|
|
9297
|
+
} catch (error) {
|
|
9298
|
+
console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
|
|
9355
9299
|
}
|
|
9356
|
-
clearUndoStep(editor);
|
|
9357
9300
|
continue;
|
|
9358
9301
|
}
|
|
9359
|
-
|
|
9360
|
-
|
|
9361
|
-
|
|
9362
|
-
|
|
9363
|
-
|
|
9364
|
-
|
|
9365
|
-
|
|
9366
|
-
|
|
9367
|
-
|
|
9368
|
-
|
|
9369
|
-
|
|
9370
|
-
|
|
9371
|
-
|
|
9372
|
-
|
|
9373
|
-
|
|
9374
|
-
behaviors,
|
|
9375
|
-
remainingEventBehaviors: remainingEventBehaviors2,
|
|
9376
|
-
event: action.event,
|
|
9377
|
-
editor,
|
|
9378
|
-
keyGenerator,
|
|
9379
|
-
schema,
|
|
9380
|
-
getSnapshot,
|
|
9381
|
-
nativeEvent,
|
|
9382
|
-
sendBack
|
|
9383
|
-
});
|
|
9384
|
-
continue;
|
|
9385
|
-
}
|
|
9386
|
-
if (action.type === "raise") {
|
|
9387
|
-
performEvent({
|
|
9388
|
-
mode: "raise",
|
|
9389
|
-
behaviors,
|
|
9390
|
-
remainingEventBehaviors: mode === "execute" ? remainingEventBehaviors : behaviors,
|
|
9391
|
-
event: action.event,
|
|
9392
|
-
editor,
|
|
9393
|
-
keyGenerator,
|
|
9394
|
-
schema,
|
|
9395
|
-
getSnapshot,
|
|
9396
|
-
nativeEvent,
|
|
9397
|
-
sendBack
|
|
9398
|
-
});
|
|
9399
|
-
continue;
|
|
9400
|
-
}
|
|
9401
|
-
action.type === "execute" && console.error("Unexpected action type: `execute`");
|
|
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;
|
|
9402
9317
|
}
|
|
9318
|
+
if (action.type === "raise") {
|
|
9319
|
+
performEvent({
|
|
9320
|
+
mode: mode === "execute" ? "execute" : "raise",
|
|
9321
|
+
behaviors,
|
|
9322
|
+
remainingEventBehaviors: mode === "execute" ? remainingEventBehaviors : behaviors,
|
|
9323
|
+
event: action.event,
|
|
9324
|
+
editor,
|
|
9325
|
+
keyGenerator,
|
|
9326
|
+
schema,
|
|
9327
|
+
getSnapshot,
|
|
9328
|
+
nativeEvent,
|
|
9329
|
+
sendBack
|
|
9330
|
+
});
|
|
9331
|
+
continue;
|
|
9332
|
+
}
|
|
9333
|
+
performEvent({
|
|
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
|
+
});
|
|
9403
9345
|
}
|
|
9346
|
+
undoStepCreated && clearUndoStep(editor);
|
|
9404
9347
|
}
|
|
9405
9348
|
break;
|
|
9406
9349
|
}
|
|
9407
9350
|
}
|
|
9408
|
-
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor),
|
|
9351
|
+
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor), withPerformingBehaviorOperation(editor, () => {
|
|
9409
9352
|
debug$6(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
9410
9353
|
context: {
|
|
9411
9354
|
keyGenerator,
|
|
@@ -11345,7 +11288,8 @@ async function updateValue({
|
|
|
11345
11288
|
slateEditor,
|
|
11346
11289
|
value
|
|
11347
11290
|
});
|
|
11348
|
-
isChanged = blockChanged || isChanged, isValid = isValid && blockValid
|
|
11291
|
+
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !isValid)
|
|
11292
|
+
break;
|
|
11349
11293
|
}
|
|
11350
11294
|
resolve();
|
|
11351
11295
|
})();
|
|
@@ -11374,7 +11318,9 @@ async function updateValue({
|
|
|
11374
11318
|
slateEditor,
|
|
11375
11319
|
value
|
|
11376
11320
|
});
|
|
11377
|
-
isChanged = blockChanged || isChanged, isValid = isValid && blockValid,
|
|
11321
|
+
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !blockValid)
|
|
11322
|
+
break;
|
|
11323
|
+
index++;
|
|
11378
11324
|
}
|
|
11379
11325
|
});
|
|
11380
11326
|
});
|