@portabletext/editor 1.48.11 → 1.48.13
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/editor-provider.cjs +54 -58
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +55 -59
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.js.map +1 -1
- package/package.json +6 -6
- package/src/behavior-actions/behavior.actions.ts +0 -9
- package/src/behaviors/behavior.perform-event.ts +54 -34
- package/src/behaviors/behavior.types.action.ts +5 -4
- package/src/editor/editor-machine.ts +28 -20
- package/src/behavior-actions/behavior.action.effect.ts +0 -7
|
@@ -5,7 +5,7 @@ import { withReact, ReactEditor, Slate } from "slate-react";
|
|
|
5
5
|
import { c } from "react-compiler-runtime";
|
|
6
6
|
import debug$f from "debug";
|
|
7
7
|
import isEqual from "lodash/isEqual.js";
|
|
8
|
-
import { Element, Text, Editor, Operation, Transforms,
|
|
8
|
+
import { Element, Text, Editor, Path, Operation, Transforms, Node, Range, Point, createEditor } from "slate";
|
|
9
9
|
import { setup, stateIn, fromCallback, assign, enqueueActions, emit, assertEvent, and, not, createActor } from "xstate";
|
|
10
10
|
import { unset, set, setIfMissing, insert, diffMatchPatch as diffMatchPatch$1, applyAll } from "@portabletext/patches";
|
|
11
11
|
import flatten from "lodash/flatten.js";
|
|
@@ -3794,10 +3794,6 @@ const decoratorAddActionImplementation = ({
|
|
|
3794
3794
|
action
|
|
3795
3795
|
}) => {
|
|
3796
3796
|
action.editor.deleteForward(action.unit);
|
|
3797
|
-
}, effectActionImplementation = ({
|
|
3798
|
-
action
|
|
3799
|
-
}) => {
|
|
3800
|
-
action.effect();
|
|
3801
3797
|
}, insertInlineObjectActionImplementation = ({
|
|
3802
3798
|
context,
|
|
3803
3799
|
action
|
|
@@ -4087,7 +4083,6 @@ const moveBackwardActionImplementation = ({
|
|
|
4087
4083
|
"insert.inline object": insertInlineObjectActionImplementation,
|
|
4088
4084
|
"insert.span": insertSpanActionImplementation,
|
|
4089
4085
|
"insert.text": insertTextActionImplementation,
|
|
4090
|
-
effect: effectActionImplementation,
|
|
4091
4086
|
"move.backward": moveBackwardActionImplementation,
|
|
4092
4087
|
"move.block": moveBlockActionImplementation,
|
|
4093
4088
|
"move.forward": moveForwardActionImplementation,
|
|
@@ -4168,13 +4163,6 @@ function performAction({
|
|
|
4168
4163
|
});
|
|
4169
4164
|
break;
|
|
4170
4165
|
}
|
|
4171
|
-
case "effect": {
|
|
4172
|
-
behaviorActionImplementations.effect({
|
|
4173
|
-
context,
|
|
4174
|
-
action
|
|
4175
|
-
});
|
|
4176
|
-
break;
|
|
4177
|
-
}
|
|
4178
4166
|
case "history.redo": {
|
|
4179
4167
|
behaviorActionImplementations["history.redo"]({
|
|
4180
4168
|
context,
|
|
@@ -7430,32 +7418,39 @@ function performEvent({
|
|
|
7430
7418
|
let nativeEventPrevented = !1, defaultBehaviorOverwritten = !1, eventBehaviorIndex = -1;
|
|
7431
7419
|
for (const eventBehavior of eventBehaviors) {
|
|
7432
7420
|
eventBehaviorIndex++;
|
|
7433
|
-
|
|
7434
|
-
|
|
7435
|
-
|
|
7436
|
-
|
|
7421
|
+
let shouldRun = !1;
|
|
7422
|
+
try {
|
|
7423
|
+
shouldRun = eventBehavior.guard === void 0 || eventBehavior.guard({
|
|
7424
|
+
snapshot: guardSnapshot,
|
|
7425
|
+
event
|
|
7426
|
+
});
|
|
7427
|
+
} catch (error) {
|
|
7428
|
+
console.error(new Error(`Evaluating guard for "${event.type}" failed due to: ${error.message}`));
|
|
7429
|
+
}
|
|
7437
7430
|
if (shouldRun) {
|
|
7438
7431
|
defaultBehaviorOverwritten = !0;
|
|
7439
7432
|
for (const actionSet of eventBehavior.actions) {
|
|
7440
|
-
const actionsSnapshot = getSnapshot()
|
|
7441
|
-
|
|
7442
|
-
|
|
7443
|
-
|
|
7433
|
+
const actionsSnapshot = getSnapshot();
|
|
7434
|
+
let actions = [];
|
|
7435
|
+
try {
|
|
7436
|
+
actions = actionSet({
|
|
7437
|
+
snapshot: actionsSnapshot,
|
|
7438
|
+
event
|
|
7439
|
+
}, shouldRun);
|
|
7440
|
+
} catch (error) {
|
|
7441
|
+
console.error(new Error(`Evaluating actions for "${event.type}" failed due to: ${error.message}`));
|
|
7442
|
+
}
|
|
7444
7443
|
if (actions.length !== 0) {
|
|
7445
7444
|
if (actions.some((action) => action.type === "execute")) {
|
|
7446
7445
|
withUndoStep(editor, () => {
|
|
7447
7446
|
for (const action of actions) {
|
|
7448
7447
|
if (action.type === "effect") {
|
|
7449
|
-
nativeEventPrevented = !0
|
|
7450
|
-
|
|
7451
|
-
|
|
7452
|
-
|
|
7453
|
-
}
|
|
7454
|
-
|
|
7455
|
-
...action,
|
|
7456
|
-
editor
|
|
7457
|
-
}
|
|
7458
|
-
});
|
|
7448
|
+
nativeEventPrevented = !0;
|
|
7449
|
+
try {
|
|
7450
|
+
action.effect();
|
|
7451
|
+
} catch (error) {
|
|
7452
|
+
console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
|
|
7453
|
+
}
|
|
7459
7454
|
continue;
|
|
7460
7455
|
}
|
|
7461
7456
|
if (action.type === "forward") {
|
|
@@ -7504,16 +7499,12 @@ function performEvent({
|
|
|
7504
7499
|
}
|
|
7505
7500
|
for (const action of actions) {
|
|
7506
7501
|
if (action.type === "effect") {
|
|
7507
|
-
nativeEventPrevented = !0
|
|
7508
|
-
|
|
7509
|
-
|
|
7510
|
-
|
|
7511
|
-
}
|
|
7512
|
-
|
|
7513
|
-
...action,
|
|
7514
|
-
editor
|
|
7515
|
-
}
|
|
7516
|
-
});
|
|
7502
|
+
nativeEventPrevented = !0;
|
|
7503
|
+
try {
|
|
7504
|
+
action.effect();
|
|
7505
|
+
} catch (error) {
|
|
7506
|
+
console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
|
|
7507
|
+
}
|
|
7517
7508
|
continue;
|
|
7518
7509
|
}
|
|
7519
7510
|
if (action.type === "forward") {
|
|
@@ -7713,27 +7704,32 @@ const editorMachine = setup({
|
|
|
7713
7704
|
event,
|
|
7714
7705
|
self: self2
|
|
7715
7706
|
}) => {
|
|
7716
|
-
assertEvent(event, ["behavior event"])
|
|
7717
|
-
|
|
7718
|
-
|
|
7719
|
-
|
|
7720
|
-
|
|
7721
|
-
|
|
7722
|
-
|
|
7723
|
-
schema: context.schema,
|
|
7724
|
-
getSnapshot: () => createEditorSnapshot({
|
|
7725
|
-
converters: [...context.converters],
|
|
7707
|
+
assertEvent(event, ["behavior event"]);
|
|
7708
|
+
try {
|
|
7709
|
+
performEvent({
|
|
7710
|
+
mode: "raise",
|
|
7711
|
+
behaviors: [...context.behaviors.values()],
|
|
7712
|
+
remainingEventBehaviors: [...context.behaviors.values()],
|
|
7713
|
+
event: event.behaviorEvent,
|
|
7726
7714
|
editor: event.editor,
|
|
7727
7715
|
keyGenerator: context.keyGenerator,
|
|
7728
|
-
readOnly: self2.getSnapshot().matches({
|
|
7729
|
-
"edit mode": "read only"
|
|
7730
|
-
}),
|
|
7731
7716
|
schema: context.schema,
|
|
7732
|
-
|
|
7733
|
-
|
|
7734
|
-
|
|
7735
|
-
|
|
7736
|
-
|
|
7717
|
+
getSnapshot: () => createEditorSnapshot({
|
|
7718
|
+
converters: [...context.converters],
|
|
7719
|
+
editor: event.editor,
|
|
7720
|
+
keyGenerator: context.keyGenerator,
|
|
7721
|
+
readOnly: self2.getSnapshot().matches({
|
|
7722
|
+
"edit mode": "read only"
|
|
7723
|
+
}),
|
|
7724
|
+
schema: context.schema,
|
|
7725
|
+
hasTag: (tag) => self2.getSnapshot().hasTag(tag),
|
|
7726
|
+
internalDrag: context.internalDrag
|
|
7727
|
+
}),
|
|
7728
|
+
nativeEvent: event.nativeEvent
|
|
7729
|
+
});
|
|
7730
|
+
} catch (error) {
|
|
7731
|
+
console.error(new Error(`Raising "${event.behaviorEvent.type}" failed due to: ${error.message}`));
|
|
7732
|
+
}
|
|
7737
7733
|
}
|
|
7738
7734
|
},
|
|
7739
7735
|
guards: {
|