@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.cjs
CHANGED
|
@@ -156,7 +156,14 @@ function getFocusSpan({
|
|
|
156
156
|
if (!editor.selection)
|
|
157
157
|
return [void 0, void 0];
|
|
158
158
|
try {
|
|
159
|
-
const [
|
|
159
|
+
const [focusBlock] = getFocusBlock({
|
|
160
|
+
editor
|
|
161
|
+
});
|
|
162
|
+
if (!focusBlock)
|
|
163
|
+
return [void 0, void 0];
|
|
164
|
+
if (!editor.isTextBlock(focusBlock))
|
|
165
|
+
return [void 0, void 0];
|
|
166
|
+
const [node, path] = slate.Editor.node(editor, editor.selection.focus.path.slice(0, 2));
|
|
160
167
|
if (editor.isTextSpan(node))
|
|
161
168
|
return [node, path];
|
|
162
169
|
} catch {
|
|
@@ -2601,46 +2608,6 @@ function createPlaceholderBlock(context) {
|
|
|
2601
2608
|
}]
|
|
2602
2609
|
};
|
|
2603
2610
|
}
|
|
2604
|
-
const insertTextOperationImplementation = ({
|
|
2605
|
-
context,
|
|
2606
|
-
operation
|
|
2607
|
-
}) => {
|
|
2608
|
-
const snapshot = {
|
|
2609
|
-
blockIndexMap: operation.editor.blockIndexMap,
|
|
2610
|
-
context: {
|
|
2611
|
-
value: operation.editor.value,
|
|
2612
|
-
selection: operation.editor.selection ? slateRangeToSelection({
|
|
2613
|
-
schema: context.schema,
|
|
2614
|
-
editor: operation.editor,
|
|
2615
|
-
range: operation.editor.selection
|
|
2616
|
-
}) : null,
|
|
2617
|
-
schema: context.schema,
|
|
2618
|
-
keyGenerator: context.keyGenerator,
|
|
2619
|
-
converters: [],
|
|
2620
|
-
readOnly: !1
|
|
2621
|
-
},
|
|
2622
|
-
decoratorState: operation.editor.decoratorState
|
|
2623
|
-
}, markState = selector_isSelectingEntireBlocks.getMarkState(snapshot), activeDecorators = selector_isSelectingEntireBlocks.getActiveDecorators(snapshot), activeAnnotations = selector_isSelectingEntireBlocks.getActiveAnnotationsMarks(snapshot), [focusSpan] = getFocusSpan({
|
|
2624
|
-
editor: operation.editor
|
|
2625
|
-
});
|
|
2626
|
-
if (!focusSpan) {
|
|
2627
|
-
slate.Transforms.insertText(operation.editor, operation.text);
|
|
2628
|
-
return;
|
|
2629
|
-
}
|
|
2630
|
-
if (markState && markState.state === "unchanged") {
|
|
2631
|
-
const markStateDecorators = (markState.marks ?? []).filter((mark) => context.schema.decorators.map((decorator) => decorator.name).includes(mark));
|
|
2632
|
-
if (markStateDecorators.length === activeDecorators.length && markStateDecorators.every((mark) => activeDecorators.includes(mark))) {
|
|
2633
|
-
slate.Transforms.insertText(operation.editor, operation.text);
|
|
2634
|
-
return;
|
|
2635
|
-
}
|
|
2636
|
-
}
|
|
2637
|
-
slate.Transforms.insertNodes(operation.editor, {
|
|
2638
|
-
_type: focusSpan._type,
|
|
2639
|
-
_key: context.keyGenerator(),
|
|
2640
|
-
text: operation.text,
|
|
2641
|
-
marks: [...activeDecorators, ...activeAnnotations]
|
|
2642
|
-
}), slateDom.EDITOR_TO_PENDING_SELECTION.set(operation.editor, operation.editor.selection), operation.editor.decoratorState = {};
|
|
2643
|
-
};
|
|
2644
2611
|
function getPreviousSpan({
|
|
2645
2612
|
editor,
|
|
2646
2613
|
blockPath,
|
|
@@ -4067,55 +4034,35 @@ const addAnnotationOperationImplementation = ({
|
|
|
4067
4034
|
context,
|
|
4068
4035
|
operation
|
|
4069
4036
|
}) => {
|
|
4070
|
-
const
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
selection: {
|
|
4075
|
-
anchor: {
|
|
4076
|
-
path: operation.at,
|
|
4077
|
-
offset: 0
|
|
4078
|
-
},
|
|
4079
|
-
focus: {
|
|
4080
|
-
path: operation.at,
|
|
4081
|
-
offset: 0
|
|
4082
|
-
}
|
|
4083
|
-
}
|
|
4084
|
-
},
|
|
4085
|
-
blockIndexMap: operation.editor.blockIndexMap
|
|
4086
|
-
});
|
|
4087
|
-
if (!location)
|
|
4088
|
-
throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
|
|
4089
|
-
const block = slate.Editor.node(operation.editor, location, {
|
|
4090
|
-
depth: 1
|
|
4091
|
-
})?.[0];
|
|
4037
|
+
const blockIndex = operation.editor.blockIndexMap.get(operation.at[0]._key);
|
|
4038
|
+
if (blockIndex === void 0)
|
|
4039
|
+
throw new Error(`Unable to find block index for block at ${JSON.stringify(operation.at)}`);
|
|
4040
|
+
const block = operation.editor.value.at(blockIndex);
|
|
4092
4041
|
if (!block)
|
|
4093
4042
|
throw new Error(`Unable to find block at ${JSON.stringify(operation.at)}`);
|
|
4094
|
-
const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(operation.editor)).at(0);
|
|
4095
|
-
if (!parsedBlock)
|
|
4096
|
-
throw new Error(`Unable to parse block at ${JSON.stringify(operation.at)}`);
|
|
4097
4043
|
const {
|
|
4098
4044
|
_type,
|
|
4099
4045
|
...filteredProps
|
|
4100
|
-
} = operation.props, updatedBlock =
|
|
4046
|
+
} = operation.props, updatedBlock = {
|
|
4047
|
+
...block,
|
|
4048
|
+
...filteredProps
|
|
4049
|
+
}, parsedBlock = util_sliceBlocks.parseBlock({
|
|
4101
4050
|
context,
|
|
4102
|
-
block:
|
|
4103
|
-
...parsedBlock,
|
|
4104
|
-
...filteredProps
|
|
4105
|
-
},
|
|
4051
|
+
block: updatedBlock,
|
|
4106
4052
|
options: {
|
|
4107
4053
|
validateFields: !0
|
|
4108
4054
|
}
|
|
4109
4055
|
});
|
|
4110
|
-
if (!
|
|
4056
|
+
if (!parsedBlock)
|
|
4111
4057
|
throw new Error(`Unable to update block at ${JSON.stringify(operation.at)}`);
|
|
4112
|
-
|
|
4058
|
+
parsedBlock.markDefs = updatedBlock.markDefs;
|
|
4059
|
+
const slateBlock = toSlateValue([parsedBlock], {
|
|
4113
4060
|
schemaTypes: context.schema
|
|
4114
4061
|
})?.at(0);
|
|
4115
4062
|
if (!slateBlock)
|
|
4116
4063
|
throw new Error("Unable to convert block to Slate value");
|
|
4117
4064
|
slate.Transforms.setNodes(operation.editor, slateBlock, {
|
|
4118
|
-
at:
|
|
4065
|
+
at: [blockIndex]
|
|
4119
4066
|
});
|
|
4120
4067
|
}, blockUnsetOperationImplementation = ({
|
|
4121
4068
|
context,
|
|
@@ -4768,7 +4715,46 @@ function insertBlock({
|
|
|
4768
4715
|
}
|
|
4769
4716
|
}
|
|
4770
4717
|
}
|
|
4771
|
-
const
|
|
4718
|
+
const insertTextOperationImplementation = ({
|
|
4719
|
+
context,
|
|
4720
|
+
operation
|
|
4721
|
+
}) => {
|
|
4722
|
+
const snapshot = {
|
|
4723
|
+
blockIndexMap: operation.editor.blockIndexMap,
|
|
4724
|
+
context: {
|
|
4725
|
+
value: operation.editor.value,
|
|
4726
|
+
selection: operation.editor.selection ? slateRangeToSelection({
|
|
4727
|
+
schema: context.schema,
|
|
4728
|
+
editor: operation.editor,
|
|
4729
|
+
range: operation.editor.selection
|
|
4730
|
+
}) : null,
|
|
4731
|
+
schema: context.schema,
|
|
4732
|
+
keyGenerator: context.keyGenerator,
|
|
4733
|
+
converters: [],
|
|
4734
|
+
readOnly: !1
|
|
4735
|
+
},
|
|
4736
|
+
decoratorState: operation.editor.decoratorState
|
|
4737
|
+
}, markState = selector_isSelectingEntireBlocks.getMarkState(snapshot), activeDecorators = selector_isSelectingEntireBlocks.getActiveDecorators(snapshot), activeAnnotations = selector_isSelectingEntireBlocks.getActiveAnnotationsMarks(snapshot), [focusSpan] = getFocusSpan({
|
|
4738
|
+
editor: operation.editor
|
|
4739
|
+
});
|
|
4740
|
+
if (!focusSpan) {
|
|
4741
|
+
slate.Transforms.insertText(operation.editor, operation.text);
|
|
4742
|
+
return;
|
|
4743
|
+
}
|
|
4744
|
+
if (markState && markState.state === "unchanged") {
|
|
4745
|
+
const markStateDecorators = (markState.marks ?? []).filter((mark) => context.schema.decorators.map((decorator) => decorator.name).includes(mark));
|
|
4746
|
+
if (markStateDecorators.length === activeDecorators.length && markStateDecorators.every((mark) => activeDecorators.includes(mark))) {
|
|
4747
|
+
slate.Transforms.insertText(operation.editor, operation.text);
|
|
4748
|
+
return;
|
|
4749
|
+
}
|
|
4750
|
+
}
|
|
4751
|
+
slate.Transforms.insertNodes(operation.editor, {
|
|
4752
|
+
_type: focusSpan._type,
|
|
4753
|
+
_key: context.keyGenerator(),
|
|
4754
|
+
text: operation.text,
|
|
4755
|
+
marks: [...activeDecorators, ...activeAnnotations]
|
|
4756
|
+
}), slateDom.EDITOR_TO_PENDING_SELECTION.set(operation.editor, operation.editor.selection), operation.editor.decoratorState = {};
|
|
4757
|
+
}, moveBackwardOperationImplementation = ({
|
|
4772
4758
|
operation
|
|
4773
4759
|
}) => {
|
|
4774
4760
|
slate.Transforms.move(operation.editor, {
|
|
@@ -4843,141 +4829,141 @@ function performOperation({
|
|
|
4843
4829
|
context,
|
|
4844
4830
|
operation
|
|
4845
4831
|
}) {
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
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
|
-
|
|
4832
|
+
slate.Editor.withoutNormalizing(operation.editor, () => {
|
|
4833
|
+
try {
|
|
4834
|
+
switch (operation.type) {
|
|
4835
|
+
case "annotation.add": {
|
|
4836
|
+
behaviorOperationImplementations["annotation.add"]({
|
|
4837
|
+
context,
|
|
4838
|
+
operation
|
|
4839
|
+
});
|
|
4840
|
+
break;
|
|
4841
|
+
}
|
|
4842
|
+
case "annotation.remove": {
|
|
4843
|
+
behaviorOperationImplementations["annotation.remove"]({
|
|
4844
|
+
context,
|
|
4845
|
+
operation
|
|
4846
|
+
});
|
|
4847
|
+
break;
|
|
4848
|
+
}
|
|
4849
|
+
case "block.set": {
|
|
4850
|
+
behaviorOperationImplementations["block.set"]({
|
|
4851
|
+
context,
|
|
4852
|
+
operation
|
|
4853
|
+
});
|
|
4854
|
+
break;
|
|
4855
|
+
}
|
|
4856
|
+
case "block.unset": {
|
|
4857
|
+
behaviorOperationImplementations["block.unset"]({
|
|
4858
|
+
context,
|
|
4859
|
+
operation
|
|
4860
|
+
});
|
|
4861
|
+
break;
|
|
4862
|
+
}
|
|
4863
|
+
case "child.set": {
|
|
4864
|
+
behaviorOperationImplementations["child.set"]({
|
|
4865
|
+
context,
|
|
4866
|
+
operation
|
|
4867
|
+
});
|
|
4868
|
+
break;
|
|
4869
|
+
}
|
|
4870
|
+
case "child.unset": {
|
|
4871
|
+
behaviorOperationImplementations["child.unset"]({
|
|
4872
|
+
context,
|
|
4873
|
+
operation
|
|
4874
|
+
});
|
|
4875
|
+
break;
|
|
4876
|
+
}
|
|
4877
|
+
case "decorator.add": {
|
|
4878
|
+
behaviorOperationImplementations["decorator.add"]({
|
|
4879
|
+
context,
|
|
4880
|
+
operation
|
|
4881
|
+
});
|
|
4882
|
+
break;
|
|
4883
|
+
}
|
|
4884
|
+
case "decorator.remove": {
|
|
4885
|
+
behaviorOperationImplementations["decorator.remove"]({
|
|
4886
|
+
context,
|
|
4887
|
+
operation
|
|
4888
|
+
});
|
|
4889
|
+
break;
|
|
4890
|
+
}
|
|
4891
|
+
case "delete": {
|
|
4892
|
+
behaviorOperationImplementations.delete({
|
|
4893
|
+
context,
|
|
4894
|
+
operation
|
|
4895
|
+
});
|
|
4896
|
+
break;
|
|
4897
|
+
}
|
|
4898
|
+
case "history.redo": {
|
|
4899
|
+
behaviorOperationImplementations["history.redo"]({
|
|
4900
|
+
context,
|
|
4901
|
+
operation
|
|
4902
|
+
});
|
|
4903
|
+
break;
|
|
4904
|
+
}
|
|
4905
|
+
case "history.undo": {
|
|
4906
|
+
behaviorOperationImplementations["history.undo"]({
|
|
4907
|
+
context,
|
|
4908
|
+
operation
|
|
4909
|
+
});
|
|
4910
|
+
break;
|
|
4911
|
+
}
|
|
4912
|
+
case "insert.block": {
|
|
4913
|
+
behaviorOperationImplementations["insert.block"]({
|
|
4914
|
+
context,
|
|
4915
|
+
operation
|
|
4916
|
+
});
|
|
4917
|
+
break;
|
|
4918
|
+
}
|
|
4919
|
+
case "insert.text": {
|
|
4920
|
+
behaviorOperationImplementations["insert.text"]({
|
|
4921
|
+
context,
|
|
4922
|
+
operation
|
|
4923
|
+
});
|
|
4924
|
+
break;
|
|
4925
|
+
}
|
|
4926
|
+
case "move.backward": {
|
|
4927
|
+
behaviorOperationImplementations["move.backward"]({
|
|
4928
|
+
context,
|
|
4929
|
+
operation
|
|
4930
|
+
});
|
|
4931
|
+
break;
|
|
4932
|
+
}
|
|
4933
|
+
case "move.block": {
|
|
4934
|
+
behaviorOperationImplementations["move.block"]({
|
|
4935
|
+
context,
|
|
4936
|
+
operation
|
|
4937
|
+
});
|
|
4938
|
+
break;
|
|
4939
|
+
}
|
|
4940
|
+
case "move.forward": {
|
|
4941
|
+
behaviorOperationImplementations["move.forward"]({
|
|
4942
|
+
context,
|
|
4943
|
+
operation
|
|
4944
|
+
});
|
|
4945
|
+
break;
|
|
4946
|
+
}
|
|
4947
|
+
default: {
|
|
4948
|
+
behaviorOperationImplementations.select({
|
|
4949
|
+
context,
|
|
4950
|
+
operation
|
|
4951
|
+
});
|
|
4952
|
+
break;
|
|
4953
|
+
}
|
|
4966
4954
|
}
|
|
4955
|
+
} catch (error) {
|
|
4956
|
+
console.error(new Error(`Executing "${operation.type}" failed due to: ${error.message}`));
|
|
4967
4957
|
}
|
|
4968
|
-
}
|
|
4969
|
-
console.error(new Error(`Executing "${operation.type}" failed due to: ${error.message}`));
|
|
4970
|
-
}
|
|
4971
|
-
}
|
|
4972
|
-
const CURRENT_OPERATION_ID = /* @__PURE__ */ new WeakMap();
|
|
4973
|
-
function withApplyingBehaviorOperations(editor, fn) {
|
|
4974
|
-
CURRENT_OPERATION_ID.set(editor, util_sliceBlocks.defaultKeyGenerator()), slate.Editor.withoutNormalizing(editor, fn), CURRENT_OPERATION_ID.set(editor, void 0);
|
|
4958
|
+
});
|
|
4975
4959
|
}
|
|
4976
|
-
|
|
4977
|
-
|
|
4960
|
+
const IS_PERFORMING_OPERATION = /* @__PURE__ */ new WeakMap();
|
|
4961
|
+
function withPerformingBehaviorOperation(editor, fn) {
|
|
4962
|
+
const prev = IS_PERFORMING_OPERATION.get(editor);
|
|
4963
|
+
IS_PERFORMING_OPERATION.set(editor, !0), fn(), IS_PERFORMING_OPERATION.set(editor, prev);
|
|
4978
4964
|
}
|
|
4979
|
-
function
|
|
4980
|
-
return
|
|
4965
|
+
function isPerformingBehaviorOperation(editor) {
|
|
4966
|
+
return IS_PERFORMING_OPERATION.get(editor) ?? !1;
|
|
4981
4967
|
}
|
|
4982
4968
|
function createWithEventListeners(editorActor) {
|
|
4983
4969
|
return function(editor) {
|
|
@@ -4988,7 +4974,7 @@ function createWithEventListeners(editorActor) {
|
|
|
4988
4974
|
select
|
|
4989
4975
|
} = editor;
|
|
4990
4976
|
return editor.delete = (options) => {
|
|
4991
|
-
if (
|
|
4977
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
4992
4978
|
editorDelete(options);
|
|
4993
4979
|
return;
|
|
4994
4980
|
}
|
|
@@ -5017,7 +5003,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5017
5003
|
editor
|
|
5018
5004
|
});
|
|
5019
5005
|
}, editor.deleteBackward = (unit) => {
|
|
5020
|
-
if (
|
|
5006
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5021
5007
|
console.error("Unexpected call to .deleteBackward(...)");
|
|
5022
5008
|
return;
|
|
5023
5009
|
}
|
|
@@ -5030,7 +5016,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5030
5016
|
editor
|
|
5031
5017
|
});
|
|
5032
5018
|
}, editor.deleteForward = (unit) => {
|
|
5033
|
-
if (
|
|
5019
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5034
5020
|
console.error("Unexpected call to .deleteForward(...)");
|
|
5035
5021
|
return;
|
|
5036
5022
|
}
|
|
@@ -5043,7 +5029,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5043
5029
|
editor
|
|
5044
5030
|
});
|
|
5045
5031
|
}, editor.insertBreak = () => {
|
|
5046
|
-
if (
|
|
5032
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5047
5033
|
console.error("Unexpected call to .insertBreak(...)");
|
|
5048
5034
|
return;
|
|
5049
5035
|
}
|
|
@@ -5055,7 +5041,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5055
5041
|
editor
|
|
5056
5042
|
});
|
|
5057
5043
|
}, editor.insertData = (dataTransfer) => {
|
|
5058
|
-
if (
|
|
5044
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5059
5045
|
console.error("Unexpected call to .insertData(...)");
|
|
5060
5046
|
return;
|
|
5061
5047
|
}
|
|
@@ -5070,13 +5056,14 @@ function createWithEventListeners(editorActor) {
|
|
|
5070
5056
|
editor
|
|
5071
5057
|
});
|
|
5072
5058
|
}, editor.insertSoftBreak = () => {
|
|
5073
|
-
if (
|
|
5074
|
-
|
|
5059
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5060
|
+
performOperation({
|
|
5075
5061
|
context: {
|
|
5076
5062
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
5077
5063
|
schema: editorActor.getSnapshot().context.schema
|
|
5078
5064
|
},
|
|
5079
5065
|
operation: {
|
|
5066
|
+
type: "insert.text",
|
|
5080
5067
|
text: `
|
|
5081
5068
|
`,
|
|
5082
5069
|
editor
|
|
@@ -5092,13 +5079,14 @@ function createWithEventListeners(editorActor) {
|
|
|
5092
5079
|
editor
|
|
5093
5080
|
});
|
|
5094
5081
|
}, editor.insertText = (text) => {
|
|
5095
|
-
if (
|
|
5096
|
-
|
|
5082
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5083
|
+
performOperation({
|
|
5097
5084
|
context: {
|
|
5098
5085
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
5099
5086
|
schema: editorActor.getSnapshot().context.schema
|
|
5100
5087
|
},
|
|
5101
5088
|
operation: {
|
|
5089
|
+
type: "insert.text",
|
|
5102
5090
|
text,
|
|
5103
5091
|
editor
|
|
5104
5092
|
}
|
|
@@ -5114,7 +5102,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5114
5102
|
editor
|
|
5115
5103
|
});
|
|
5116
5104
|
}, editor.redo = () => {
|
|
5117
|
-
if (
|
|
5105
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5118
5106
|
performOperation({
|
|
5119
5107
|
context: {
|
|
5120
5108
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
@@ -5135,7 +5123,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5135
5123
|
editor
|
|
5136
5124
|
});
|
|
5137
5125
|
}, editor.select = (location) => {
|
|
5138
|
-
if (
|
|
5126
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5139
5127
|
select(location);
|
|
5140
5128
|
return;
|
|
5141
5129
|
}
|
|
@@ -5155,7 +5143,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5155
5143
|
}, editor.setFragmentData = () => {
|
|
5156
5144
|
console.error("Unexpected call to .setFragmentData(...)");
|
|
5157
5145
|
}, editor.undo = () => {
|
|
5158
|
-
if (
|
|
5146
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5159
5147
|
performOperation({
|
|
5160
5148
|
context: {
|
|
5161
5149
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
@@ -9224,7 +9212,7 @@ function performEvent({
|
|
|
9224
9212
|
return listenedNamespace !== void 0 && eventNamespace !== void 0 && listenedNamespace === eventNamespace || listenedNamespace !== void 0 && eventNamespace === void 0 && listenedNamespace === event.type ? !0 : behavior.on === event.type;
|
|
9225
9213
|
});
|
|
9226
9214
|
if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
|
|
9227
|
-
nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor),
|
|
9215
|
+
nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor), withPerformingBehaviorOperation(editor, () => {
|
|
9228
9216
|
debug$6(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
9229
9217
|
context: {
|
|
9230
9218
|
keyGenerator,
|
|
@@ -9266,117 +9254,72 @@ function performEvent({
|
|
|
9266
9254
|
} catch (error) {
|
|
9267
9255
|
console.error(new Error(`Evaluating actions for "${event.type}" failed due to: ${error.message}`));
|
|
9268
9256
|
}
|
|
9269
|
-
if (actions.length
|
|
9270
|
-
|
|
9271
|
-
|
|
9272
|
-
|
|
9273
|
-
|
|
9274
|
-
|
|
9275
|
-
|
|
9276
|
-
|
|
9277
|
-
|
|
9278
|
-
|
|
9279
|
-
console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
|
|
9280
|
-
}
|
|
9281
|
-
continue;
|
|
9282
|
-
}
|
|
9283
|
-
if (action.type === "forward") {
|
|
9284
|
-
const remainingEventBehaviors2 = eventBehaviors.slice(eventBehaviorIndex + 1);
|
|
9285
|
-
performEvent({
|
|
9286
|
-
mode: "forward",
|
|
9287
|
-
behaviors,
|
|
9288
|
-
remainingEventBehaviors: remainingEventBehaviors2,
|
|
9289
|
-
event: action.event,
|
|
9290
|
-
editor,
|
|
9291
|
-
keyGenerator,
|
|
9292
|
-
schema: schema2,
|
|
9293
|
-
getSnapshot,
|
|
9294
|
-
nativeEvent,
|
|
9295
|
-
sendBack
|
|
9296
|
-
});
|
|
9297
|
-
continue;
|
|
9298
|
-
}
|
|
9299
|
-
if (action.type === "raise") {
|
|
9300
|
-
performEvent({
|
|
9301
|
-
mode: "raise",
|
|
9302
|
-
behaviors,
|
|
9303
|
-
remainingEventBehaviors: behaviors,
|
|
9304
|
-
event: action.event,
|
|
9305
|
-
editor,
|
|
9306
|
-
keyGenerator,
|
|
9307
|
-
schema: schema2,
|
|
9308
|
-
getSnapshot,
|
|
9309
|
-
nativeEvent,
|
|
9310
|
-
sendBack
|
|
9311
|
-
});
|
|
9312
|
-
continue;
|
|
9313
|
-
}
|
|
9314
|
-
performEvent({
|
|
9315
|
-
mode: "execute",
|
|
9316
|
-
behaviors,
|
|
9317
|
-
remainingEventBehaviors: [],
|
|
9318
|
-
event: action.event,
|
|
9319
|
-
editor,
|
|
9320
|
-
keyGenerator,
|
|
9321
|
-
schema: schema2,
|
|
9322
|
-
getSnapshot,
|
|
9323
|
-
nativeEvent: void 0,
|
|
9324
|
-
sendBack
|
|
9257
|
+
if (actions.length === 0)
|
|
9258
|
+
continue;
|
|
9259
|
+
nativeEventPrevented = actions.some((action) => action.type === "raise" || action.type === "execute") || !actions.some((action) => action.type === "forward");
|
|
9260
|
+
let undoStepCreated = !1;
|
|
9261
|
+
actions.some((action) => action.type === "execute") && (createUndoStep(editor), undoStepCreated = !0);
|
|
9262
|
+
for (const action of actions) {
|
|
9263
|
+
if (action.type === "effect") {
|
|
9264
|
+
try {
|
|
9265
|
+
action.effect({
|
|
9266
|
+
send: sendBack
|
|
9325
9267
|
});
|
|
9268
|
+
} catch (error) {
|
|
9269
|
+
console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
|
|
9326
9270
|
}
|
|
9327
|
-
clearUndoStep(editor);
|
|
9328
9271
|
continue;
|
|
9329
9272
|
}
|
|
9330
|
-
|
|
9331
|
-
|
|
9332
|
-
|
|
9333
|
-
|
|
9334
|
-
|
|
9335
|
-
|
|
9336
|
-
|
|
9337
|
-
|
|
9338
|
-
|
|
9339
|
-
|
|
9340
|
-
|
|
9341
|
-
|
|
9342
|
-
|
|
9343
|
-
|
|
9344
|
-
|
|
9345
|
-
behaviors,
|
|
9346
|
-
remainingEventBehaviors: remainingEventBehaviors2,
|
|
9347
|
-
event: action.event,
|
|
9348
|
-
editor,
|
|
9349
|
-
keyGenerator,
|
|
9350
|
-
schema: schema2,
|
|
9351
|
-
getSnapshot,
|
|
9352
|
-
nativeEvent,
|
|
9353
|
-
sendBack
|
|
9354
|
-
});
|
|
9355
|
-
continue;
|
|
9356
|
-
}
|
|
9357
|
-
if (action.type === "raise") {
|
|
9358
|
-
performEvent({
|
|
9359
|
-
mode: "raise",
|
|
9360
|
-
behaviors,
|
|
9361
|
-
remainingEventBehaviors: mode === "execute" ? remainingEventBehaviors : behaviors,
|
|
9362
|
-
event: action.event,
|
|
9363
|
-
editor,
|
|
9364
|
-
keyGenerator,
|
|
9365
|
-
schema: schema2,
|
|
9366
|
-
getSnapshot,
|
|
9367
|
-
nativeEvent,
|
|
9368
|
-
sendBack
|
|
9369
|
-
});
|
|
9370
|
-
continue;
|
|
9371
|
-
}
|
|
9372
|
-
action.type === "execute" && console.error("Unexpected action type: `execute`");
|
|
9273
|
+
if (action.type === "forward") {
|
|
9274
|
+
const remainingEventBehaviors2 = eventBehaviors.slice(eventBehaviorIndex + 1);
|
|
9275
|
+
performEvent({
|
|
9276
|
+
mode: mode === "execute" ? "execute" : "forward",
|
|
9277
|
+
behaviors,
|
|
9278
|
+
remainingEventBehaviors: remainingEventBehaviors2,
|
|
9279
|
+
event: action.event,
|
|
9280
|
+
editor,
|
|
9281
|
+
keyGenerator,
|
|
9282
|
+
schema: schema2,
|
|
9283
|
+
getSnapshot,
|
|
9284
|
+
nativeEvent,
|
|
9285
|
+
sendBack
|
|
9286
|
+
});
|
|
9287
|
+
continue;
|
|
9373
9288
|
}
|
|
9289
|
+
if (action.type === "raise") {
|
|
9290
|
+
performEvent({
|
|
9291
|
+
mode: mode === "execute" ? "execute" : "raise",
|
|
9292
|
+
behaviors,
|
|
9293
|
+
remainingEventBehaviors: mode === "execute" ? remainingEventBehaviors : behaviors,
|
|
9294
|
+
event: action.event,
|
|
9295
|
+
editor,
|
|
9296
|
+
keyGenerator,
|
|
9297
|
+
schema: schema2,
|
|
9298
|
+
getSnapshot,
|
|
9299
|
+
nativeEvent,
|
|
9300
|
+
sendBack
|
|
9301
|
+
});
|
|
9302
|
+
continue;
|
|
9303
|
+
}
|
|
9304
|
+
performEvent({
|
|
9305
|
+
mode: "execute",
|
|
9306
|
+
behaviors,
|
|
9307
|
+
remainingEventBehaviors: [],
|
|
9308
|
+
event: action.event,
|
|
9309
|
+
editor,
|
|
9310
|
+
keyGenerator,
|
|
9311
|
+
schema: schema2,
|
|
9312
|
+
getSnapshot,
|
|
9313
|
+
nativeEvent: void 0,
|
|
9314
|
+
sendBack
|
|
9315
|
+
});
|
|
9374
9316
|
}
|
|
9317
|
+
undoStepCreated && clearUndoStep(editor);
|
|
9375
9318
|
}
|
|
9376
9319
|
break;
|
|
9377
9320
|
}
|
|
9378
9321
|
}
|
|
9379
|
-
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor),
|
|
9322
|
+
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor), withPerformingBehaviorOperation(editor, () => {
|
|
9380
9323
|
debug$6(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
9381
9324
|
context: {
|
|
9382
9325
|
keyGenerator,
|
|
@@ -11316,7 +11259,8 @@ async function updateValue({
|
|
|
11316
11259
|
slateEditor,
|
|
11317
11260
|
value
|
|
11318
11261
|
});
|
|
11319
|
-
isChanged = blockChanged || isChanged, isValid = isValid && blockValid
|
|
11262
|
+
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !isValid)
|
|
11263
|
+
break;
|
|
11320
11264
|
}
|
|
11321
11265
|
resolve();
|
|
11322
11266
|
})();
|
|
@@ -11345,7 +11289,9 @@ async function updateValue({
|
|
|
11345
11289
|
slateEditor,
|
|
11346
11290
|
value
|
|
11347
11291
|
});
|
|
11348
|
-
isChanged = blockChanged || isChanged, isValid = isValid && blockValid,
|
|
11292
|
+
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !blockValid)
|
|
11293
|
+
break;
|
|
11294
|
+
index++;
|
|
11349
11295
|
}
|
|
11350
11296
|
});
|
|
11351
11297
|
});
|