@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.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 {
|
|
@@ -2284,8 +2291,12 @@ PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
|
2284
2291
|
function validateSelection(slateEditor, activeElement) {
|
|
2285
2292
|
if (!slateEditor.selection)
|
|
2286
2293
|
return;
|
|
2287
|
-
|
|
2288
|
-
|
|
2294
|
+
let root;
|
|
2295
|
+
try {
|
|
2296
|
+
root = ReactEditor.findDocumentOrShadowRoot(slateEditor);
|
|
2297
|
+
} catch {
|
|
2298
|
+
}
|
|
2299
|
+
if (!root || activeElement !== root.activeElement)
|
|
2289
2300
|
return;
|
|
2290
2301
|
const domSelection = ReactEditor.getWindow(slateEditor).getSelection();
|
|
2291
2302
|
if (!domSelection || domSelection.rangeCount === 0)
|
|
@@ -2626,46 +2637,6 @@ function createPlaceholderBlock(context) {
|
|
|
2626
2637
|
}]
|
|
2627
2638
|
};
|
|
2628
2639
|
}
|
|
2629
|
-
const insertTextOperationImplementation = ({
|
|
2630
|
-
context,
|
|
2631
|
-
operation
|
|
2632
|
-
}) => {
|
|
2633
|
-
const snapshot = {
|
|
2634
|
-
blockIndexMap: operation.editor.blockIndexMap,
|
|
2635
|
-
context: {
|
|
2636
|
-
value: operation.editor.value,
|
|
2637
|
-
selection: operation.editor.selection ? slateRangeToSelection({
|
|
2638
|
-
schema: context.schema,
|
|
2639
|
-
editor: operation.editor,
|
|
2640
|
-
range: operation.editor.selection
|
|
2641
|
-
}) : null,
|
|
2642
|
-
schema: context.schema,
|
|
2643
|
-
keyGenerator: context.keyGenerator,
|
|
2644
|
-
converters: [],
|
|
2645
|
-
readOnly: !1
|
|
2646
|
-
},
|
|
2647
|
-
decoratorState: operation.editor.decoratorState
|
|
2648
|
-
}, markState = getMarkState(snapshot), activeDecorators = getActiveDecorators(snapshot), activeAnnotations = getActiveAnnotationsMarks(snapshot), [focusSpan] = getFocusSpan({
|
|
2649
|
-
editor: operation.editor
|
|
2650
|
-
});
|
|
2651
|
-
if (!focusSpan) {
|
|
2652
|
-
Transforms.insertText(operation.editor, operation.text);
|
|
2653
|
-
return;
|
|
2654
|
-
}
|
|
2655
|
-
if (markState && markState.state === "unchanged") {
|
|
2656
|
-
const markStateDecorators = (markState.marks ?? []).filter((mark) => context.schema.decorators.map((decorator) => decorator.name).includes(mark));
|
|
2657
|
-
if (markStateDecorators.length === activeDecorators.length && markStateDecorators.every((mark) => activeDecorators.includes(mark))) {
|
|
2658
|
-
Transforms.insertText(operation.editor, operation.text);
|
|
2659
|
-
return;
|
|
2660
|
-
}
|
|
2661
|
-
}
|
|
2662
|
-
Transforms.insertNodes(operation.editor, {
|
|
2663
|
-
_type: focusSpan._type,
|
|
2664
|
-
_key: context.keyGenerator(),
|
|
2665
|
-
text: operation.text,
|
|
2666
|
-
marks: [...activeDecorators, ...activeAnnotations]
|
|
2667
|
-
}), EDITOR_TO_PENDING_SELECTION.set(operation.editor, operation.editor.selection), operation.editor.decoratorState = {};
|
|
2668
|
-
};
|
|
2669
2640
|
function getPreviousSpan({
|
|
2670
2641
|
editor,
|
|
2671
2642
|
blockPath,
|
|
@@ -4092,55 +4063,35 @@ const addAnnotationOperationImplementation = ({
|
|
|
4092
4063
|
context,
|
|
4093
4064
|
operation
|
|
4094
4065
|
}) => {
|
|
4095
|
-
const
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
selection: {
|
|
4100
|
-
anchor: {
|
|
4101
|
-
path: operation.at,
|
|
4102
|
-
offset: 0
|
|
4103
|
-
},
|
|
4104
|
-
focus: {
|
|
4105
|
-
path: operation.at,
|
|
4106
|
-
offset: 0
|
|
4107
|
-
}
|
|
4108
|
-
}
|
|
4109
|
-
},
|
|
4110
|
-
blockIndexMap: operation.editor.blockIndexMap
|
|
4111
|
-
});
|
|
4112
|
-
if (!location)
|
|
4113
|
-
throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
|
|
4114
|
-
const block = Editor.node(operation.editor, location, {
|
|
4115
|
-
depth: 1
|
|
4116
|
-
})?.[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);
|
|
4117
4070
|
if (!block)
|
|
4118
4071
|
throw new Error(`Unable to find block at ${JSON.stringify(operation.at)}`);
|
|
4119
|
-
const parsedBlock = fromSlateValue([block], context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(operation.editor)).at(0);
|
|
4120
|
-
if (!parsedBlock)
|
|
4121
|
-
throw new Error(`Unable to parse block at ${JSON.stringify(operation.at)}`);
|
|
4122
4072
|
const {
|
|
4123
4073
|
_type,
|
|
4124
4074
|
...filteredProps
|
|
4125
|
-
} = operation.props, updatedBlock =
|
|
4075
|
+
} = operation.props, updatedBlock = {
|
|
4076
|
+
...block,
|
|
4077
|
+
...filteredProps
|
|
4078
|
+
}, parsedBlock = parseBlock({
|
|
4126
4079
|
context,
|
|
4127
|
-
block:
|
|
4128
|
-
...parsedBlock,
|
|
4129
|
-
...filteredProps
|
|
4130
|
-
},
|
|
4080
|
+
block: updatedBlock,
|
|
4131
4081
|
options: {
|
|
4132
4082
|
validateFields: !0
|
|
4133
4083
|
}
|
|
4134
4084
|
});
|
|
4135
|
-
if (!
|
|
4085
|
+
if (!parsedBlock)
|
|
4136
4086
|
throw new Error(`Unable to update block at ${JSON.stringify(operation.at)}`);
|
|
4137
|
-
|
|
4087
|
+
parsedBlock.markDefs = updatedBlock.markDefs;
|
|
4088
|
+
const slateBlock = toSlateValue([parsedBlock], {
|
|
4138
4089
|
schemaTypes: context.schema
|
|
4139
4090
|
})?.at(0);
|
|
4140
4091
|
if (!slateBlock)
|
|
4141
4092
|
throw new Error("Unable to convert block to Slate value");
|
|
4142
4093
|
Transforms.setNodes(operation.editor, slateBlock, {
|
|
4143
|
-
at:
|
|
4094
|
+
at: [blockIndex]
|
|
4144
4095
|
});
|
|
4145
4096
|
}, blockUnsetOperationImplementation = ({
|
|
4146
4097
|
context,
|
|
@@ -4793,7 +4744,46 @@ function insertBlock({
|
|
|
4793
4744
|
}
|
|
4794
4745
|
}
|
|
4795
4746
|
}
|
|
4796
|
-
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 = ({
|
|
4797
4787
|
operation
|
|
4798
4788
|
}) => {
|
|
4799
4789
|
Transforms.move(operation.editor, {
|
|
@@ -4868,141 +4858,141 @@ function performOperation({
|
|
|
4868
4858
|
context,
|
|
4869
4859
|
operation
|
|
4870
4860
|
}) {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
+
}
|
|
4991
4983
|
}
|
|
4984
|
+
} catch (error) {
|
|
4985
|
+
console.error(new Error(`Executing "${operation.type}" failed due to: ${error.message}`));
|
|
4992
4986
|
}
|
|
4993
|
-
}
|
|
4994
|
-
console.error(new Error(`Executing "${operation.type}" failed due to: ${error.message}`));
|
|
4995
|
-
}
|
|
4996
|
-
}
|
|
4997
|
-
const CURRENT_OPERATION_ID = /* @__PURE__ */ new WeakMap();
|
|
4998
|
-
function withApplyingBehaviorOperations(editor, fn) {
|
|
4999
|
-
CURRENT_OPERATION_ID.set(editor, defaultKeyGenerator()), Editor.withoutNormalizing(editor, fn), CURRENT_OPERATION_ID.set(editor, void 0);
|
|
4987
|
+
});
|
|
5000
4988
|
}
|
|
5001
|
-
|
|
5002
|
-
|
|
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);
|
|
5003
4993
|
}
|
|
5004
|
-
function
|
|
5005
|
-
return
|
|
4994
|
+
function isPerformingBehaviorOperation(editor) {
|
|
4995
|
+
return IS_PERFORMING_OPERATION.get(editor) ?? !1;
|
|
5006
4996
|
}
|
|
5007
4997
|
function createWithEventListeners(editorActor) {
|
|
5008
4998
|
return function(editor) {
|
|
@@ -5013,7 +5003,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5013
5003
|
select
|
|
5014
5004
|
} = editor;
|
|
5015
5005
|
return editor.delete = (options) => {
|
|
5016
|
-
if (
|
|
5006
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5017
5007
|
editorDelete(options);
|
|
5018
5008
|
return;
|
|
5019
5009
|
}
|
|
@@ -5042,7 +5032,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5042
5032
|
editor
|
|
5043
5033
|
});
|
|
5044
5034
|
}, editor.deleteBackward = (unit) => {
|
|
5045
|
-
if (
|
|
5035
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5046
5036
|
console.error("Unexpected call to .deleteBackward(...)");
|
|
5047
5037
|
return;
|
|
5048
5038
|
}
|
|
@@ -5055,7 +5045,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5055
5045
|
editor
|
|
5056
5046
|
});
|
|
5057
5047
|
}, editor.deleteForward = (unit) => {
|
|
5058
|
-
if (
|
|
5048
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5059
5049
|
console.error("Unexpected call to .deleteForward(...)");
|
|
5060
5050
|
return;
|
|
5061
5051
|
}
|
|
@@ -5068,7 +5058,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5068
5058
|
editor
|
|
5069
5059
|
});
|
|
5070
5060
|
}, editor.insertBreak = () => {
|
|
5071
|
-
if (
|
|
5061
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5072
5062
|
console.error("Unexpected call to .insertBreak(...)");
|
|
5073
5063
|
return;
|
|
5074
5064
|
}
|
|
@@ -5080,7 +5070,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5080
5070
|
editor
|
|
5081
5071
|
});
|
|
5082
5072
|
}, editor.insertData = (dataTransfer) => {
|
|
5083
|
-
if (
|
|
5073
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5084
5074
|
console.error("Unexpected call to .insertData(...)");
|
|
5085
5075
|
return;
|
|
5086
5076
|
}
|
|
@@ -5095,13 +5085,14 @@ function createWithEventListeners(editorActor) {
|
|
|
5095
5085
|
editor
|
|
5096
5086
|
});
|
|
5097
5087
|
}, editor.insertSoftBreak = () => {
|
|
5098
|
-
if (
|
|
5099
|
-
|
|
5088
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5089
|
+
performOperation({
|
|
5100
5090
|
context: {
|
|
5101
5091
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
5102
5092
|
schema: editorActor.getSnapshot().context.schema
|
|
5103
5093
|
},
|
|
5104
5094
|
operation: {
|
|
5095
|
+
type: "insert.text",
|
|
5105
5096
|
text: `
|
|
5106
5097
|
`,
|
|
5107
5098
|
editor
|
|
@@ -5117,13 +5108,14 @@ function createWithEventListeners(editorActor) {
|
|
|
5117
5108
|
editor
|
|
5118
5109
|
});
|
|
5119
5110
|
}, editor.insertText = (text) => {
|
|
5120
|
-
if (
|
|
5121
|
-
|
|
5111
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5112
|
+
performOperation({
|
|
5122
5113
|
context: {
|
|
5123
5114
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
5124
5115
|
schema: editorActor.getSnapshot().context.schema
|
|
5125
5116
|
},
|
|
5126
5117
|
operation: {
|
|
5118
|
+
type: "insert.text",
|
|
5127
5119
|
text,
|
|
5128
5120
|
editor
|
|
5129
5121
|
}
|
|
@@ -5139,7 +5131,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5139
5131
|
editor
|
|
5140
5132
|
});
|
|
5141
5133
|
}, editor.redo = () => {
|
|
5142
|
-
if (
|
|
5134
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5143
5135
|
performOperation({
|
|
5144
5136
|
context: {
|
|
5145
5137
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
@@ -5160,7 +5152,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5160
5152
|
editor
|
|
5161
5153
|
});
|
|
5162
5154
|
}, editor.select = (location) => {
|
|
5163
|
-
if (
|
|
5155
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5164
5156
|
select(location);
|
|
5165
5157
|
return;
|
|
5166
5158
|
}
|
|
@@ -5180,7 +5172,7 @@ function createWithEventListeners(editorActor) {
|
|
|
5180
5172
|
}, editor.setFragmentData = () => {
|
|
5181
5173
|
console.error("Unexpected call to .setFragmentData(...)");
|
|
5182
5174
|
}, editor.undo = () => {
|
|
5183
|
-
if (
|
|
5175
|
+
if (isPerformingBehaviorOperation(editor)) {
|
|
5184
5176
|
performOperation({
|
|
5185
5177
|
context: {
|
|
5186
5178
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
@@ -9249,7 +9241,7 @@ function performEvent({
|
|
|
9249
9241
|
return listenedNamespace !== void 0 && eventNamespace !== void 0 && listenedNamespace === eventNamespace || listenedNamespace !== void 0 && eventNamespace === void 0 && listenedNamespace === event.type ? !0 : behavior.on === event.type;
|
|
9250
9242
|
});
|
|
9251
9243
|
if (eventBehaviors.length === 0 && isSyntheticBehaviorEvent(event)) {
|
|
9252
|
-
nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor),
|
|
9244
|
+
nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor), withPerformingBehaviorOperation(editor, () => {
|
|
9253
9245
|
debug$6(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
9254
9246
|
context: {
|
|
9255
9247
|
keyGenerator,
|
|
@@ -9291,117 +9283,72 @@ function performEvent({
|
|
|
9291
9283
|
} catch (error) {
|
|
9292
9284
|
console.error(new Error(`Evaluating actions for "${event.type}" failed due to: ${error.message}`));
|
|
9293
9285
|
}
|
|
9294
|
-
if (actions.length
|
|
9295
|
-
|
|
9296
|
-
|
|
9297
|
-
|
|
9298
|
-
|
|
9299
|
-
|
|
9300
|
-
|
|
9301
|
-
|
|
9302
|
-
|
|
9303
|
-
|
|
9304
|
-
console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
|
|
9305
|
-
}
|
|
9306
|
-
continue;
|
|
9307
|
-
}
|
|
9308
|
-
if (action.type === "forward") {
|
|
9309
|
-
const remainingEventBehaviors2 = eventBehaviors.slice(eventBehaviorIndex + 1);
|
|
9310
|
-
performEvent({
|
|
9311
|
-
mode: "forward",
|
|
9312
|
-
behaviors,
|
|
9313
|
-
remainingEventBehaviors: remainingEventBehaviors2,
|
|
9314
|
-
event: action.event,
|
|
9315
|
-
editor,
|
|
9316
|
-
keyGenerator,
|
|
9317
|
-
schema,
|
|
9318
|
-
getSnapshot,
|
|
9319
|
-
nativeEvent,
|
|
9320
|
-
sendBack
|
|
9321
|
-
});
|
|
9322
|
-
continue;
|
|
9323
|
-
}
|
|
9324
|
-
if (action.type === "raise") {
|
|
9325
|
-
performEvent({
|
|
9326
|
-
mode: "raise",
|
|
9327
|
-
behaviors,
|
|
9328
|
-
remainingEventBehaviors: behaviors,
|
|
9329
|
-
event: action.event,
|
|
9330
|
-
editor,
|
|
9331
|
-
keyGenerator,
|
|
9332
|
-
schema,
|
|
9333
|
-
getSnapshot,
|
|
9334
|
-
nativeEvent,
|
|
9335
|
-
sendBack
|
|
9336
|
-
});
|
|
9337
|
-
continue;
|
|
9338
|
-
}
|
|
9339
|
-
performEvent({
|
|
9340
|
-
mode: "execute",
|
|
9341
|
-
behaviors,
|
|
9342
|
-
remainingEventBehaviors: [],
|
|
9343
|
-
event: action.event,
|
|
9344
|
-
editor,
|
|
9345
|
-
keyGenerator,
|
|
9346
|
-
schema,
|
|
9347
|
-
getSnapshot,
|
|
9348
|
-
nativeEvent: void 0,
|
|
9349
|
-
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
|
|
9350
9296
|
});
|
|
9297
|
+
} catch (error) {
|
|
9298
|
+
console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
|
|
9351
9299
|
}
|
|
9352
|
-
clearUndoStep(editor);
|
|
9353
9300
|
continue;
|
|
9354
9301
|
}
|
|
9355
|
-
|
|
9356
|
-
|
|
9357
|
-
|
|
9358
|
-
|
|
9359
|
-
|
|
9360
|
-
|
|
9361
|
-
|
|
9362
|
-
|
|
9363
|
-
|
|
9364
|
-
|
|
9365
|
-
|
|
9366
|
-
|
|
9367
|
-
|
|
9368
|
-
|
|
9369
|
-
|
|
9370
|
-
behaviors,
|
|
9371
|
-
remainingEventBehaviors: remainingEventBehaviors2,
|
|
9372
|
-
event: action.event,
|
|
9373
|
-
editor,
|
|
9374
|
-
keyGenerator,
|
|
9375
|
-
schema,
|
|
9376
|
-
getSnapshot,
|
|
9377
|
-
nativeEvent,
|
|
9378
|
-
sendBack
|
|
9379
|
-
});
|
|
9380
|
-
continue;
|
|
9381
|
-
}
|
|
9382
|
-
if (action.type === "raise") {
|
|
9383
|
-
performEvent({
|
|
9384
|
-
mode: "raise",
|
|
9385
|
-
behaviors,
|
|
9386
|
-
remainingEventBehaviors: mode === "execute" ? remainingEventBehaviors : behaviors,
|
|
9387
|
-
event: action.event,
|
|
9388
|
-
editor,
|
|
9389
|
-
keyGenerator,
|
|
9390
|
-
schema,
|
|
9391
|
-
getSnapshot,
|
|
9392
|
-
nativeEvent,
|
|
9393
|
-
sendBack
|
|
9394
|
-
});
|
|
9395
|
-
continue;
|
|
9396
|
-
}
|
|
9397
|
-
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;
|
|
9398
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
|
+
});
|
|
9399
9345
|
}
|
|
9346
|
+
undoStepCreated && clearUndoStep(editor);
|
|
9400
9347
|
}
|
|
9401
9348
|
break;
|
|
9402
9349
|
}
|
|
9403
9350
|
}
|
|
9404
|
-
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor),
|
|
9351
|
+
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor), withPerformingBehaviorOperation(editor, () => {
|
|
9405
9352
|
debug$6(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|
|
9406
9353
|
context: {
|
|
9407
9354
|
keyGenerator,
|
|
@@ -11341,7 +11288,8 @@ async function updateValue({
|
|
|
11341
11288
|
slateEditor,
|
|
11342
11289
|
value
|
|
11343
11290
|
});
|
|
11344
|
-
isChanged = blockChanged || isChanged, isValid = isValid && blockValid
|
|
11291
|
+
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !isValid)
|
|
11292
|
+
break;
|
|
11345
11293
|
}
|
|
11346
11294
|
resolve();
|
|
11347
11295
|
})();
|
|
@@ -11370,7 +11318,9 @@ async function updateValue({
|
|
|
11370
11318
|
slateEditor,
|
|
11371
11319
|
value
|
|
11372
11320
|
});
|
|
11373
|
-
isChanged = blockChanged || isChanged, isValid = isValid && blockValid,
|
|
11321
|
+
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !blockValid)
|
|
11322
|
+
break;
|
|
11323
|
+
index++;
|
|
11374
11324
|
}
|
|
11375
11325
|
});
|
|
11376
11326
|
});
|