@portabletext/editor 2.9.0 → 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 +9 -9
- 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 +274 -324
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +275 -325
- 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 +4 -4
- package/src/behaviors/behavior.perform-event.ts +24 -80
- package/src/editor/Editable.tsx +12 -1
- 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 {
|
|
@@ -2255,8 +2262,12 @@ PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
|
2255
2262
|
function validateSelection(slateEditor, activeElement) {
|
|
2256
2263
|
if (!slateEditor.selection)
|
|
2257
2264
|
return;
|
|
2258
|
-
|
|
2259
|
-
|
|
2265
|
+
let root;
|
|
2266
|
+
try {
|
|
2267
|
+
root = slateReact.ReactEditor.findDocumentOrShadowRoot(slateEditor);
|
|
2268
|
+
} catch {
|
|
2269
|
+
}
|
|
2270
|
+
if (!root || activeElement !== root.activeElement)
|
|
2260
2271
|
return;
|
|
2261
2272
|
const domSelection = slateReact.ReactEditor.getWindow(slateEditor).getSelection();
|
|
2262
2273
|
if (!domSelection || domSelection.rangeCount === 0)
|
|
@@ -2597,46 +2608,6 @@ function createPlaceholderBlock(context) {
|
|
|
2597
2608
|
}]
|
|
2598
2609
|
};
|
|
2599
2610
|
}
|
|
2600
|
-
const insertTextOperationImplementation = ({
|
|
2601
|
-
context,
|
|
2602
|
-
operation
|
|
2603
|
-
}) => {
|
|
2604
|
-
const snapshot = {
|
|
2605
|
-
blockIndexMap: operation.editor.blockIndexMap,
|
|
2606
|
-
context: {
|
|
2607
|
-
value: operation.editor.value,
|
|
2608
|
-
selection: operation.editor.selection ? slateRangeToSelection({
|
|
2609
|
-
schema: context.schema,
|
|
2610
|
-
editor: operation.editor,
|
|
2611
|
-
range: operation.editor.selection
|
|
2612
|
-
}) : null,
|
|
2613
|
-
schema: context.schema,
|
|
2614
|
-
keyGenerator: context.keyGenerator,
|
|
2615
|
-
converters: [],
|
|
2616
|
-
readOnly: !1
|
|
2617
|
-
},
|
|
2618
|
-
decoratorState: operation.editor.decoratorState
|
|
2619
|
-
}, markState = selector_isSelectingEntireBlocks.getMarkState(snapshot), activeDecorators = selector_isSelectingEntireBlocks.getActiveDecorators(snapshot), activeAnnotations = selector_isSelectingEntireBlocks.getActiveAnnotationsMarks(snapshot), [focusSpan] = getFocusSpan({
|
|
2620
|
-
editor: operation.editor
|
|
2621
|
-
});
|
|
2622
|
-
if (!focusSpan) {
|
|
2623
|
-
slate.Transforms.insertText(operation.editor, operation.text);
|
|
2624
|
-
return;
|
|
2625
|
-
}
|
|
2626
|
-
if (markState && markState.state === "unchanged") {
|
|
2627
|
-
const markStateDecorators = (markState.marks ?? []).filter((mark) => context.schema.decorators.map((decorator) => decorator.name).includes(mark));
|
|
2628
|
-
if (markStateDecorators.length === activeDecorators.length && markStateDecorators.every((mark) => activeDecorators.includes(mark))) {
|
|
2629
|
-
slate.Transforms.insertText(operation.editor, operation.text);
|
|
2630
|
-
return;
|
|
2631
|
-
}
|
|
2632
|
-
}
|
|
2633
|
-
slate.Transforms.insertNodes(operation.editor, {
|
|
2634
|
-
_type: focusSpan._type,
|
|
2635
|
-
_key: context.keyGenerator(),
|
|
2636
|
-
text: operation.text,
|
|
2637
|
-
marks: [...activeDecorators, ...activeAnnotations]
|
|
2638
|
-
}), slateDom.EDITOR_TO_PENDING_SELECTION.set(operation.editor, operation.editor.selection), operation.editor.decoratorState = {};
|
|
2639
|
-
};
|
|
2640
2611
|
function getPreviousSpan({
|
|
2641
2612
|
editor,
|
|
2642
2613
|
blockPath,
|
|
@@ -4063,55 +4034,35 @@ const addAnnotationOperationImplementation = ({
|
|
|
4063
4034
|
context,
|
|
4064
4035
|
operation
|
|
4065
4036
|
}) => {
|
|
4066
|
-
const
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
selection: {
|
|
4071
|
-
anchor: {
|
|
4072
|
-
path: operation.at,
|
|
4073
|
-
offset: 0
|
|
4074
|
-
},
|
|
4075
|
-
focus: {
|
|
4076
|
-
path: operation.at,
|
|
4077
|
-
offset: 0
|
|
4078
|
-
}
|
|
4079
|
-
}
|
|
4080
|
-
},
|
|
4081
|
-
blockIndexMap: operation.editor.blockIndexMap
|
|
4082
|
-
});
|
|
4083
|
-
if (!location)
|
|
4084
|
-
throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
|
|
4085
|
-
const block = slate.Editor.node(operation.editor, location, {
|
|
4086
|
-
depth: 1
|
|
4087
|
-
})?.[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);
|
|
4088
4041
|
if (!block)
|
|
4089
4042
|
throw new Error(`Unable to find block at ${JSON.stringify(operation.at)}`);
|
|
4090
|
-
const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(operation.editor)).at(0);
|
|
4091
|
-
if (!parsedBlock)
|
|
4092
|
-
throw new Error(`Unable to parse block at ${JSON.stringify(operation.at)}`);
|
|
4093
4043
|
const {
|
|
4094
4044
|
_type,
|
|
4095
4045
|
...filteredProps
|
|
4096
|
-
} = operation.props, updatedBlock =
|
|
4046
|
+
} = operation.props, updatedBlock = {
|
|
4047
|
+
...block,
|
|
4048
|
+
...filteredProps
|
|
4049
|
+
}, parsedBlock = util_sliceBlocks.parseBlock({
|
|
4097
4050
|
context,
|
|
4098
|
-
block:
|
|
4099
|
-
...parsedBlock,
|
|
4100
|
-
...filteredProps
|
|
4101
|
-
},
|
|
4051
|
+
block: updatedBlock,
|
|
4102
4052
|
options: {
|
|
4103
4053
|
validateFields: !0
|
|
4104
4054
|
}
|
|
4105
4055
|
});
|
|
4106
|
-
if (!
|
|
4056
|
+
if (!parsedBlock)
|
|
4107
4057
|
throw new Error(`Unable to update block at ${JSON.stringify(operation.at)}`);
|
|
4108
|
-
|
|
4058
|
+
parsedBlock.markDefs = updatedBlock.markDefs;
|
|
4059
|
+
const slateBlock = toSlateValue([parsedBlock], {
|
|
4109
4060
|
schemaTypes: context.schema
|
|
4110
4061
|
})?.at(0);
|
|
4111
4062
|
if (!slateBlock)
|
|
4112
4063
|
throw new Error("Unable to convert block to Slate value");
|
|
4113
4064
|
slate.Transforms.setNodes(operation.editor, slateBlock, {
|
|
4114
|
-
at:
|
|
4065
|
+
at: [blockIndex]
|
|
4115
4066
|
});
|
|
4116
4067
|
}, blockUnsetOperationImplementation = ({
|
|
4117
4068
|
context,
|
|
@@ -4764,7 +4715,46 @@ function insertBlock({
|
|
|
4764
4715
|
}
|
|
4765
4716
|
}
|
|
4766
4717
|
}
|
|
4767
|
-
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 = ({
|
|
4768
4758
|
operation
|
|
4769
4759
|
}) => {
|
|
4770
4760
|
slate.Transforms.move(operation.editor, {
|
|
@@ -4839,141 +4829,141 @@ function performOperation({
|
|
|
4839
4829
|
context,
|
|
4840
4830
|
operation
|
|
4841
4831
|
}) {
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
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
|
-
|
|
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
|
+
}
|
|
4962
4954
|
}
|
|
4955
|
+
} catch (error) {
|
|
4956
|
+
console.error(new Error(`Executing "${operation.type}" failed due to: ${error.message}`));
|
|
4963
4957
|
}
|
|
4964
|
-
}
|
|
4965
|
-
console.error(new Error(`Executing "${operation.type}" failed due to: ${error.message}`));
|
|
4966
|
-
}
|
|
4967
|
-
}
|
|
4968
|
-
const CURRENT_OPERATION_ID = /* @__PURE__ */ new WeakMap();
|
|
4969
|
-
function withApplyingBehaviorOperations(editor, fn) {
|
|
4970
|
-
CURRENT_OPERATION_ID.set(editor, util_sliceBlocks.defaultKeyGenerator()), slate.Editor.withoutNormalizing(editor, fn), CURRENT_OPERATION_ID.set(editor, void 0);
|
|
4958
|
+
});
|
|
4971
4959
|
}
|
|
4972
|
-
|
|
4973
|
-
|
|
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);
|
|
4974
4964
|
}
|
|
4975
|
-
function
|
|
4976
|
-
return
|
|
4965
|
+
function isPerformingBehaviorOperation(editor) {
|
|
4966
|
+
return IS_PERFORMING_OPERATION.get(editor) ?? !1;
|
|
4977
4967
|
}
|
|
4978
4968
|
function createWithEventListeners(editorActor) {
|
|
4979
4969
|
return function(editor) {
|
|
@@ -4984,7 +4974,7 @@ function createWithEventListeners(editorActor) {
|
|
|
4984
4974
|
select
|
|
4985
4975
|
} = editor;
|
|
4986
4976
|
return editor.delete = (options) => {
|
|
4987
|
-
if (
|
|
4977
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
4988
4978
|
editorDelete(options);
|
|
4989
4979
|
return;
|
|
4990
4980
|
}
|
|
@@ -5013,7 +5003,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5013
5003
|
editor
|
|
5014
5004
|
});
|
|
5015
5005
|
}, editor.deleteBackward = (unit) => {
|
|
5016
|
-
if (
|
|
5006
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5017
5007
|
console.error("Unexpected call to .deleteBackward(...)");
|
|
5018
5008
|
return;
|
|
5019
5009
|
}
|
|
@@ -5026,7 +5016,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5026
5016
|
editor
|
|
5027
5017
|
});
|
|
5028
5018
|
}, editor.deleteForward = (unit) => {
|
|
5029
|
-
if (
|
|
5019
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5030
5020
|
console.error("Unexpected call to .deleteForward(...)");
|
|
5031
5021
|
return;
|
|
5032
5022
|
}
|
|
@@ -5039,7 +5029,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5039
5029
|
editor
|
|
5040
5030
|
});
|
|
5041
5031
|
}, editor.insertBreak = () => {
|
|
5042
|
-
if (
|
|
5032
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5043
5033
|
console.error("Unexpected call to .insertBreak(...)");
|
|
5044
5034
|
return;
|
|
5045
5035
|
}
|
|
@@ -5051,7 +5041,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5051
5041
|
editor
|
|
5052
5042
|
});
|
|
5053
5043
|
}, editor.insertData = (dataTransfer) => {
|
|
5054
|
-
if (
|
|
5044
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5055
5045
|
console.error("Unexpected call to .insertData(...)");
|
|
5056
5046
|
return;
|
|
5057
5047
|
}
|
|
@@ -5066,13 +5056,14 @@ function createWithEventListeners(editorActor) {
|
|
|
5066
5056
|
editor
|
|
5067
5057
|
});
|
|
5068
5058
|
}, editor.insertSoftBreak = () => {
|
|
5069
|
-
if (
|
|
5070
|
-
|
|
5059
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5060
|
+
performOperation({
|
|
5071
5061
|
context: {
|
|
5072
5062
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
5073
5063
|
schema: editorActor.getSnapshot().context.schema
|
|
5074
5064
|
},
|
|
5075
5065
|
operation: {
|
|
5066
|
+
type: "insert.text",
|
|
5076
5067
|
text: `
|
|
5077
5068
|
`,
|
|
5078
5069
|
editor
|
|
@@ -5088,13 +5079,14 @@ function createWithEventListeners(editorActor) {
|
|
|
5088
5079
|
editor
|
|
5089
5080
|
});
|
|
5090
5081
|
}, editor.insertText = (text) => {
|
|
5091
|
-
if (
|
|
5092
|
-
|
|
5082
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5083
|
+
performOperation({
|
|
5093
5084
|
context: {
|
|
5094
5085
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
5095
5086
|
schema: editorActor.getSnapshot().context.schema
|
|
5096
5087
|
},
|
|
5097
5088
|
operation: {
|
|
5089
|
+
type: "insert.text",
|
|
5098
5090
|
text,
|
|
5099
5091
|
editor
|
|
5100
5092
|
}
|
|
@@ -5110,7 +5102,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5110
5102
|
editor
|
|
5111
5103
|
});
|
|
5112
5104
|
}, editor.redo = () => {
|
|
5113
|
-
if (
|
|
5105
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5114
5106
|
performOperation({
|
|
5115
5107
|
context: {
|
|
5116
5108
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
@@ -5131,7 +5123,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5131
5123
|
editor
|
|
5132
5124
|
});
|
|
5133
5125
|
}, editor.select = (location) => {
|
|
5134
|
-
if (
|
|
5126
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5135
5127
|
select(location);
|
|
5136
5128
|
return;
|
|
5137
5129
|
}
|
|
@@ -5151,7 +5143,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5151
5143
|
}, editor.setFragmentData = () => {
|
|
5152
5144
|
console.error("Unexpected call to .setFragmentData(...)");
|
|
5153
5145
|
}, editor.undo = () => {
|
|
5154
|
-
if (
|
|
5146
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5155
5147
|
performOperation({
|
|
5156
5148
|
context: {
|
|
5157
5149
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
@@ -9220,7 +9212,7 @@ function performEvent({
|
|
|
9220
9212
|
return listenedNamespace !== void 0 && eventNamespace !== void 0 && listenedNamespace === eventNamespace || listenedNamespace !== void 0 && eventNamespace === void 0 && listenedNamespace === event.type ? !0 : behavior.on === event.type;
|
|
9221
9213
|
});
|
|
9222
9214
|
if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
|
|
9223
|
-
nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor),
|
|
9215
|
+
nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor), withPerformingBehaviorOperation(editor, () => {
|
|
9224
9216
|
debug$6(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
9225
9217
|
context: {
|
|
9226
9218
|
keyGenerator,
|
|
@@ -9262,117 +9254,72 @@ function performEvent({
|
|
|
9262
9254
|
} catch (error) {
|
|
9263
9255
|
console.error(new Error(`Evaluating actions for "${event.type}" failed due to: ${error.message}`));
|
|
9264
9256
|
}
|
|
9265
|
-
if (actions.length
|
|
9266
|
-
|
|
9267
|
-
|
|
9268
|
-
|
|
9269
|
-
|
|
9270
|
-
|
|
9271
|
-
|
|
9272
|
-
|
|
9273
|
-
|
|
9274
|
-
|
|
9275
|
-
console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
|
|
9276
|
-
}
|
|
9277
|
-
continue;
|
|
9278
|
-
}
|
|
9279
|
-
if (action.type === "forward") {
|
|
9280
|
-
const remainingEventBehaviors2 = eventBehaviors.slice(eventBehaviorIndex + 1);
|
|
9281
|
-
performEvent({
|
|
9282
|
-
mode: "forward",
|
|
9283
|
-
behaviors,
|
|
9284
|
-
remainingEventBehaviors: remainingEventBehaviors2,
|
|
9285
|
-
event: action.event,
|
|
9286
|
-
editor,
|
|
9287
|
-
keyGenerator,
|
|
9288
|
-
schema: schema2,
|
|
9289
|
-
getSnapshot,
|
|
9290
|
-
nativeEvent,
|
|
9291
|
-
sendBack
|
|
9292
|
-
});
|
|
9293
|
-
continue;
|
|
9294
|
-
}
|
|
9295
|
-
if (action.type === "raise") {
|
|
9296
|
-
performEvent({
|
|
9297
|
-
mode: "raise",
|
|
9298
|
-
behaviors,
|
|
9299
|
-
remainingEventBehaviors: behaviors,
|
|
9300
|
-
event: action.event,
|
|
9301
|
-
editor,
|
|
9302
|
-
keyGenerator,
|
|
9303
|
-
schema: schema2,
|
|
9304
|
-
getSnapshot,
|
|
9305
|
-
nativeEvent,
|
|
9306
|
-
sendBack
|
|
9307
|
-
});
|
|
9308
|
-
continue;
|
|
9309
|
-
}
|
|
9310
|
-
performEvent({
|
|
9311
|
-
mode: "execute",
|
|
9312
|
-
behaviors,
|
|
9313
|
-
remainingEventBehaviors: [],
|
|
9314
|
-
event: action.event,
|
|
9315
|
-
editor,
|
|
9316
|
-
keyGenerator,
|
|
9317
|
-
schema: schema2,
|
|
9318
|
-
getSnapshot,
|
|
9319
|
-
nativeEvent: void 0,
|
|
9320
|
-
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
|
|
9321
9267
|
});
|
|
9268
|
+
} catch (error) {
|
|
9269
|
+
console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
|
|
9322
9270
|
}
|
|
9323
|
-
clearUndoStep(editor);
|
|
9324
9271
|
continue;
|
|
9325
9272
|
}
|
|
9326
|
-
|
|
9327
|
-
|
|
9328
|
-
|
|
9329
|
-
|
|
9330
|
-
|
|
9331
|
-
|
|
9332
|
-
|
|
9333
|
-
|
|
9334
|
-
|
|
9335
|
-
|
|
9336
|
-
|
|
9337
|
-
|
|
9338
|
-
|
|
9339
|
-
|
|
9340
|
-
|
|
9341
|
-
behaviors,
|
|
9342
|
-
remainingEventBehaviors: remainingEventBehaviors2,
|
|
9343
|
-
event: action.event,
|
|
9344
|
-
editor,
|
|
9345
|
-
keyGenerator,
|
|
9346
|
-
schema: schema2,
|
|
9347
|
-
getSnapshot,
|
|
9348
|
-
nativeEvent,
|
|
9349
|
-
sendBack
|
|
9350
|
-
});
|
|
9351
|
-
continue;
|
|
9352
|
-
}
|
|
9353
|
-
if (action.type === "raise") {
|
|
9354
|
-
performEvent({
|
|
9355
|
-
mode: "raise",
|
|
9356
|
-
behaviors,
|
|
9357
|
-
remainingEventBehaviors: mode === "execute" ? remainingEventBehaviors : behaviors,
|
|
9358
|
-
event: action.event,
|
|
9359
|
-
editor,
|
|
9360
|
-
keyGenerator,
|
|
9361
|
-
schema: schema2,
|
|
9362
|
-
getSnapshot,
|
|
9363
|
-
nativeEvent,
|
|
9364
|
-
sendBack
|
|
9365
|
-
});
|
|
9366
|
-
continue;
|
|
9367
|
-
}
|
|
9368
|
-
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;
|
|
9369
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
|
+
});
|
|
9370
9316
|
}
|
|
9317
|
+
undoStepCreated && clearUndoStep(editor);
|
|
9371
9318
|
}
|
|
9372
9319
|
break;
|
|
9373
9320
|
}
|
|
9374
9321
|
}
|
|
9375
|
-
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor),
|
|
9322
|
+
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor), withPerformingBehaviorOperation(editor, () => {
|
|
9376
9323
|
debug$6(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
9377
9324
|
context: {
|
|
9378
9325
|
keyGenerator,
|
|
@@ -11312,7 +11259,8 @@ async function updateValue({
|
|
|
11312
11259
|
slateEditor,
|
|
11313
11260
|
value
|
|
11314
11261
|
});
|
|
11315
|
-
isChanged = blockChanged || isChanged, isValid = isValid && blockValid
|
|
11262
|
+
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !isValid)
|
|
11263
|
+
break;
|
|
11316
11264
|
}
|
|
11317
11265
|
resolve();
|
|
11318
11266
|
})();
|
|
@@ -11341,7 +11289,9 @@ async function updateValue({
|
|
|
11341
11289
|
slateEditor,
|
|
11342
11290
|
value
|
|
11343
11291
|
});
|
|
11344
|
-
isChanged = blockChanged || isChanged, isValid = isValid && blockValid,
|
|
11292
|
+
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !blockValid)
|
|
11293
|
+
break;
|
|
11294
|
+
index++;
|
|
11345
11295
|
}
|
|
11346
11296
|
});
|
|
11347
11297
|
});
|