@portabletext/editor 1.21.0 → 1.21.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/index.cjs +83 -15
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +26 -0
- package/lib/index.d.ts +26 -0
- package/lib/index.js +83 -15
- package/lib/index.js.map +1 -1
- package/package.json +4 -4
- package/src/editor/editor-machine.ts +73 -9
- package/src/editor/plugins/create-with-event-listeners.ts +39 -1
package/lib/index.cjs
CHANGED
|
@@ -2861,9 +2861,18 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
2861
2861
|
};
|
|
2862
2862
|
});
|
|
2863
2863
|
const {
|
|
2864
|
+
deleteBackward,
|
|
2865
|
+
deleteForward,
|
|
2866
|
+
insertBreak,
|
|
2867
|
+
insertSoftBreak,
|
|
2868
|
+
insertText,
|
|
2864
2869
|
select
|
|
2865
2870
|
} = editor;
|
|
2866
2871
|
return editor.deleteBackward = (unit) => {
|
|
2872
|
+
if (isApplyingBehaviorActions(editor)) {
|
|
2873
|
+
deleteBackward(unit);
|
|
2874
|
+
return;
|
|
2875
|
+
}
|
|
2867
2876
|
editorActor.send({
|
|
2868
2877
|
type: "behavior event",
|
|
2869
2878
|
behaviorEvent: {
|
|
@@ -2873,6 +2882,10 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
2873
2882
|
editor
|
|
2874
2883
|
});
|
|
2875
2884
|
}, editor.deleteForward = (unit) => {
|
|
2885
|
+
if (isApplyingBehaviorActions(editor)) {
|
|
2886
|
+
deleteForward(unit);
|
|
2887
|
+
return;
|
|
2888
|
+
}
|
|
2876
2889
|
editorActor.send({
|
|
2877
2890
|
type: "behavior event",
|
|
2878
2891
|
behaviorEvent: {
|
|
@@ -2882,6 +2895,10 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
2882
2895
|
editor
|
|
2883
2896
|
});
|
|
2884
2897
|
}, editor.insertBreak = () => {
|
|
2898
|
+
if (isApplyingBehaviorActions(editor)) {
|
|
2899
|
+
insertBreak();
|
|
2900
|
+
return;
|
|
2901
|
+
}
|
|
2885
2902
|
editorActor.send({
|
|
2886
2903
|
type: "behavior event",
|
|
2887
2904
|
behaviorEvent: {
|
|
@@ -2890,6 +2907,10 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
2890
2907
|
editor
|
|
2891
2908
|
});
|
|
2892
2909
|
}, editor.insertSoftBreak = () => {
|
|
2910
|
+
if (isApplyingBehaviorActions(editor)) {
|
|
2911
|
+
insertSoftBreak();
|
|
2912
|
+
return;
|
|
2913
|
+
}
|
|
2893
2914
|
editorActor.send({
|
|
2894
2915
|
type: "behavior event",
|
|
2895
2916
|
behaviorEvent: {
|
|
@@ -2898,6 +2919,10 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
2898
2919
|
editor
|
|
2899
2920
|
});
|
|
2900
2921
|
}, editor.insertText = (text, options) => {
|
|
2922
|
+
if (isApplyingBehaviorActions(editor)) {
|
|
2923
|
+
insertText(text, options);
|
|
2924
|
+
return;
|
|
2925
|
+
}
|
|
2901
2926
|
editorActor.send({
|
|
2902
2927
|
type: "behavior event",
|
|
2903
2928
|
behaviorEvent: {
|
|
@@ -2905,7 +2930,10 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
2905
2930
|
text,
|
|
2906
2931
|
options
|
|
2907
2932
|
},
|
|
2908
|
-
editor
|
|
2933
|
+
editor,
|
|
2934
|
+
defaultActionCallback: () => {
|
|
2935
|
+
insertText(text, options);
|
|
2936
|
+
}
|
|
2909
2937
|
});
|
|
2910
2938
|
}, editor.select = (location) => {
|
|
2911
2939
|
if (isApplyingBehaviorActions(editor)) {
|
|
@@ -2919,7 +2947,10 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
2919
2947
|
type: "select",
|
|
2920
2948
|
selection: toPortableTextRange(fromSlateValue(editor.children, editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), range, editorActor.getSnapshot().context.schema)
|
|
2921
2949
|
},
|
|
2922
|
-
editor
|
|
2950
|
+
editor,
|
|
2951
|
+
defaultActionCallback: () => {
|
|
2952
|
+
select(location);
|
|
2953
|
+
}
|
|
2923
2954
|
});
|
|
2924
2955
|
}, editor;
|
|
2925
2956
|
};
|
|
@@ -5599,16 +5630,32 @@ const editorMachine = xstate.setup({
|
|
|
5599
5630
|
const defaultAction = event.type === "custom behavior event" || event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" ? void 0 : {
|
|
5600
5631
|
...event.behaviorEvent,
|
|
5601
5632
|
editor: event.editor
|
|
5602
|
-
}, eventBehaviors = [...context.behaviors.values()].filter((behavior) => behavior.on === event.behaviorEvent.type);
|
|
5633
|
+
}, defaultActionCallback = event.type === "behavior event" ? event.defaultActionCallback : void 0, eventBehaviors = [...context.behaviors.values()].filter((behavior) => behavior.on === event.behaviorEvent.type);
|
|
5603
5634
|
if (eventBehaviors.length === 0) {
|
|
5635
|
+
if (defaultActionCallback) {
|
|
5636
|
+
withApplyingBehaviorActions(event.editor, () => {
|
|
5637
|
+
slate.Editor.withoutNormalizing(event.editor, () => {
|
|
5638
|
+
try {
|
|
5639
|
+
defaultActionCallback();
|
|
5640
|
+
} catch (error) {
|
|
5641
|
+
console.error(new Error(`Performing action "${event.behaviorEvent.type}" failed due to: ${error.message}`));
|
|
5642
|
+
}
|
|
5643
|
+
});
|
|
5644
|
+
});
|
|
5645
|
+
return;
|
|
5646
|
+
}
|
|
5604
5647
|
if (!defaultAction)
|
|
5605
5648
|
return;
|
|
5606
5649
|
withApplyingBehaviorActions(event.editor, () => {
|
|
5607
5650
|
slate.Editor.withoutNormalizing(event.editor, () => {
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5651
|
+
try {
|
|
5652
|
+
performAction({
|
|
5653
|
+
context,
|
|
5654
|
+
action: defaultAction
|
|
5655
|
+
});
|
|
5656
|
+
} catch (error) {
|
|
5657
|
+
console.error(new Error(`Performing action "${defaultAction.type}" as a result of "${event.behaviorEvent.type}" failed due to: ${error.message}`));
|
|
5658
|
+
}
|
|
5612
5659
|
});
|
|
5613
5660
|
}), event.editor.onChange();
|
|
5614
5661
|
return;
|
|
@@ -5655,10 +5702,15 @@ const editorMachine = xstate.setup({
|
|
|
5655
5702
|
...actionIntend,
|
|
5656
5703
|
editor: event.editor
|
|
5657
5704
|
};
|
|
5658
|
-
|
|
5659
|
-
|
|
5660
|
-
|
|
5661
|
-
|
|
5705
|
+
try {
|
|
5706
|
+
performAction({
|
|
5707
|
+
context,
|
|
5708
|
+
action
|
|
5709
|
+
});
|
|
5710
|
+
} catch (error) {
|
|
5711
|
+
console.error(new Error(`Performing action "${action.type}" as a result of "${event.behaviorEvent.type}" failed due to: ${error.message}`));
|
|
5712
|
+
break;
|
|
5713
|
+
}
|
|
5662
5714
|
}
|
|
5663
5715
|
});
|
|
5664
5716
|
}), event.editor.onChange();
|
|
@@ -5668,14 +5720,30 @@ const editorMachine = xstate.setup({
|
|
|
5668
5720
|
}
|
|
5669
5721
|
}
|
|
5670
5722
|
if (!behaviorOverwritten) {
|
|
5723
|
+
if (defaultActionCallback) {
|
|
5724
|
+
withApplyingBehaviorActions(event.editor, () => {
|
|
5725
|
+
slate.Editor.withoutNormalizing(event.editor, () => {
|
|
5726
|
+
try {
|
|
5727
|
+
defaultActionCallback();
|
|
5728
|
+
} catch (error) {
|
|
5729
|
+
console.error(new Error(`Performing "${event.behaviorEvent.type}" failed due to: ${error.message}`));
|
|
5730
|
+
}
|
|
5731
|
+
});
|
|
5732
|
+
});
|
|
5733
|
+
return;
|
|
5734
|
+
}
|
|
5671
5735
|
if (!defaultAction)
|
|
5672
5736
|
return;
|
|
5673
5737
|
withApplyingBehaviorActions(event.editor, () => {
|
|
5674
5738
|
slate.Editor.withoutNormalizing(event.editor, () => {
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5739
|
+
try {
|
|
5740
|
+
performAction({
|
|
5741
|
+
context,
|
|
5742
|
+
action: defaultAction
|
|
5743
|
+
});
|
|
5744
|
+
} catch (error) {
|
|
5745
|
+
console.error(new Error(`Performing action "${defaultAction.type}" as a result of "${event.behaviorEvent.type}" failed due to: ${error.message}`));
|
|
5746
|
+
}
|
|
5679
5747
|
});
|
|
5680
5748
|
}), event.editor.onChange();
|
|
5681
5749
|
}
|