@portabletext/editor 1.47.2 → 1.47.4
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 +125 -100
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +126 -101
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/behaviors/index.d.cts +404 -543
- package/lib/behaviors/index.d.ts +404 -543
- package/lib/index.cjs +9 -6
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +411 -34
- package/lib/index.d.ts +411 -34
- package/lib/index.js +9 -6
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +411 -34
- package/lib/plugins/index.d.ts +411 -34
- package/lib/selectors/index.d.cts +404 -33
- package/lib/selectors/index.d.ts +404 -33
- package/lib/utils/index.d.cts +404 -33
- package/lib/utils/index.d.ts +404 -33
- package/package.json +3 -3
- package/src/behavior-actions/behavior.action.insert.text.ts +10 -1
- package/src/behavior-actions/behavior.actions.ts +0 -18
- package/src/behaviors/behavior.perform-event.ts +55 -65
- package/src/behaviors/behavior.types.event.ts +7 -9
- package/src/editor/Editable.tsx +18 -13
- package/src/editor/create-editor.ts +14 -0
- package/src/editor/editor-machine.ts +76 -5
- package/src/editor/plugins/create-with-event-listeners.ts +0 -6
- package/src/editor/plugins/createWithEditableAPI.ts +2 -8
- package/src/editor/with-applying-behavior-actions.ts +2 -2
- package/src/behavior-actions/behavior.action.blur.ts +0 -8
- package/src/behavior-actions/behavior.action.focus.ts +0 -8
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { c } from "react-compiler-runtime";
|
|
3
3
|
import React, { useEffect, useMemo, createContext, useContext, useState, startTransition, Component } from "react";
|
|
4
|
-
import {
|
|
4
|
+
import { withReact, ReactEditor, Slate } from "slate-react";
|
|
5
5
|
import { useSelector, useActorRef } from "@xstate/react";
|
|
6
6
|
import debug$g from "debug";
|
|
7
7
|
import isEqual from "lodash/isEqual.js";
|
|
@@ -1339,12 +1339,12 @@ const CURRENT_BEHAVIOR_ACTION_SET = /* @__PURE__ */ new WeakMap();
|
|
|
1339
1339
|
function withApplyingBehaviorActionSet(editor, fn) {
|
|
1340
1340
|
const current = CURRENT_BEHAVIOR_ACTION_SET.get(editor);
|
|
1341
1341
|
if (current) {
|
|
1342
|
-
|
|
1342
|
+
fn();
|
|
1343
1343
|
return;
|
|
1344
1344
|
}
|
|
1345
1345
|
CURRENT_BEHAVIOR_ACTION_SET.set(editor, current ?? {
|
|
1346
1346
|
actionSetId: defaultKeyGenerator()
|
|
1347
|
-
}),
|
|
1347
|
+
}), fn(), CURRENT_BEHAVIOR_ACTION_SET.set(editor, void 0);
|
|
1348
1348
|
}
|
|
1349
1349
|
function getCurrentBehaviorActionSetId(editor) {
|
|
1350
1350
|
return CURRENT_BEHAVIOR_ACTION_SET.get(editor)?.actionSetId;
|
|
@@ -2655,7 +2655,10 @@ function createOperationToPatches(editorActor) {
|
|
|
2655
2655
|
const insertTextActionImplementation = ({
|
|
2656
2656
|
action
|
|
2657
2657
|
}) => {
|
|
2658
|
-
Transforms.
|
|
2658
|
+
action.editor.marks ? Transforms.insertNodes(action.editor, {
|
|
2659
|
+
text: action.text,
|
|
2660
|
+
...action.editor.marks
|
|
2661
|
+
}) : Transforms.insertText(action.editor, action.text), action.editor.marks = null;
|
|
2659
2662
|
};
|
|
2660
2663
|
function isPortableTextSpan(node) {
|
|
2661
2664
|
return node._type === "span" && "text" in node && typeof node.text == "string" && (typeof node.marks > "u" || Array.isArray(node.marks) && node.marks.every((mark) => typeof mark == "string"));
|
|
@@ -3414,10 +3417,6 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
3414
3417
|
}, {
|
|
3415
3418
|
at: location
|
|
3416
3419
|
});
|
|
3417
|
-
}, blurActionImplementation = ({
|
|
3418
|
-
action
|
|
3419
|
-
}) => {
|
|
3420
|
-
ReactEditor.blur(action.editor);
|
|
3421
3420
|
};
|
|
3422
3421
|
function getFocusBlock({
|
|
3423
3422
|
editor
|
|
@@ -3748,10 +3747,6 @@ const decoratorAddActionImplementation = ({
|
|
|
3748
3747
|
action
|
|
3749
3748
|
}) => {
|
|
3750
3749
|
action.effect();
|
|
3751
|
-
}, focusActionImplementation = ({
|
|
3752
|
-
action
|
|
3753
|
-
}) => {
|
|
3754
|
-
ReactEditor.focus(action.editor);
|
|
3755
3750
|
}, insertInlineObjectActionImplementation = ({
|
|
3756
3751
|
context,
|
|
3757
3752
|
action
|
|
@@ -4064,10 +4059,8 @@ const moveBackwardActionImplementation = ({
|
|
|
4064
4059
|
"annotation.remove": removeAnnotationActionImplementation,
|
|
4065
4060
|
"block.set": blockSetBehaviorActionImplementation,
|
|
4066
4061
|
"block.unset": blockUnsetBehaviorActionImplementation,
|
|
4067
|
-
blur: blurActionImplementation,
|
|
4068
4062
|
"decorator.add": decoratorAddActionImplementation,
|
|
4069
4063
|
"decorator.remove": removeDecoratorActionImplementation,
|
|
4070
|
-
focus: focusActionImplementation,
|
|
4071
4064
|
delete: deleteActionImplementation,
|
|
4072
4065
|
"delete.backward": deleteBackwardActionImplementation,
|
|
4073
4066
|
"delete.forward": deleteForwardActionImplementation,
|
|
@@ -4119,13 +4112,6 @@ function performAction({
|
|
|
4119
4112
|
});
|
|
4120
4113
|
break;
|
|
4121
4114
|
}
|
|
4122
|
-
case "blur": {
|
|
4123
|
-
behaviorActionImplementations.blur({
|
|
4124
|
-
context,
|
|
4125
|
-
action
|
|
4126
|
-
});
|
|
4127
|
-
break;
|
|
4128
|
-
}
|
|
4129
4115
|
case "decorator.add": {
|
|
4130
4116
|
behaviorActionImplementations["decorator.add"]({
|
|
4131
4117
|
context,
|
|
@@ -4175,13 +4161,6 @@ function performAction({
|
|
|
4175
4161
|
});
|
|
4176
4162
|
break;
|
|
4177
4163
|
}
|
|
4178
|
-
case "focus": {
|
|
4179
|
-
behaviorActionImplementations.focus({
|
|
4180
|
-
context,
|
|
4181
|
-
action
|
|
4182
|
-
});
|
|
4183
|
-
break;
|
|
4184
|
-
}
|
|
4185
4164
|
case "history.redo": {
|
|
4186
4165
|
behaviorActionImplementations["history.redo"]({
|
|
4187
4166
|
context,
|
|
@@ -4358,10 +4337,7 @@ function createWithEventListeners(editorActor) {
|
|
|
4358
4337
|
type: "insert.text",
|
|
4359
4338
|
text
|
|
4360
4339
|
},
|
|
4361
|
-
editor
|
|
4362
|
-
defaultActionCallback: () => {
|
|
4363
|
-
insertText(text, options);
|
|
4364
|
-
}
|
|
4340
|
+
editor
|
|
4365
4341
|
});
|
|
4366
4342
|
}, editor.redo = () => {
|
|
4367
4343
|
if (isApplyingBehaviorActions(editor)) {
|
|
@@ -4400,10 +4376,7 @@ function createWithEventListeners(editorActor) {
|
|
|
4400
4376
|
range
|
|
4401
4377
|
})
|
|
4402
4378
|
},
|
|
4403
|
-
editor
|
|
4404
|
-
defaultActionCallback: () => {
|
|
4405
|
-
select(location);
|
|
4406
|
-
}
|
|
4379
|
+
editor
|
|
4407
4380
|
});
|
|
4408
4381
|
}, editor.setFragmentData = () => {
|
|
4409
4382
|
console.warn("Unexpected call to .setFragmentData(...)");
|
|
@@ -5886,8 +5859,7 @@ function performEvent({
|
|
|
5886
5859
|
keyGenerator,
|
|
5887
5860
|
schema,
|
|
5888
5861
|
getSnapshot,
|
|
5889
|
-
nativeEvent
|
|
5890
|
-
defaultActionCallback
|
|
5862
|
+
nativeEvent
|
|
5891
5863
|
}) {
|
|
5892
5864
|
debug$3(`(${eventCategory(event)})`, JSON.stringify(event, null, 2));
|
|
5893
5865
|
const defaultAction = isCustomBehaviorEvent(event) || isNativeBehaviorEvent(event) || isAbstractBehaviorEvent(event) ? void 0 : {
|
|
@@ -5900,16 +5872,6 @@ function performEvent({
|
|
|
5900
5872
|
return listenedNamespace !== void 0 && eventNamespace !== void 0 && listenedNamespace === eventNamespace || listenedNamespace !== void 0 && eventNamespace === void 0 && listenedNamespace === event.type ? !0 : behavior.on === event.type;
|
|
5901
5873
|
});
|
|
5902
5874
|
if (eventBehaviors.length === 0) {
|
|
5903
|
-
if (defaultActionCallback) {
|
|
5904
|
-
withApplyingBehaviorActions(editor, () => {
|
|
5905
|
-
try {
|
|
5906
|
-
defaultActionCallback();
|
|
5907
|
-
} catch (error) {
|
|
5908
|
-
console.error(new Error(`Performing action "${event.type}" failed due to: ${error.message}`));
|
|
5909
|
-
}
|
|
5910
|
-
});
|
|
5911
|
-
return;
|
|
5912
|
-
}
|
|
5913
5875
|
if (!defaultAction)
|
|
5914
5876
|
return;
|
|
5915
5877
|
withApplyingBehaviorActions(editor, () => {
|
|
@@ -5920,11 +5882,11 @@ function performEvent({
|
|
|
5920
5882
|
schema
|
|
5921
5883
|
},
|
|
5922
5884
|
action: defaultAction
|
|
5923
|
-
})
|
|
5885
|
+
});
|
|
5924
5886
|
} catch (error) {
|
|
5925
5887
|
console.error(new Error(`Performing action "${defaultAction.type}" as a result of "${event.type}" failed due to: ${error.message}`));
|
|
5926
5888
|
}
|
|
5927
|
-
});
|
|
5889
|
+
}), editor.onChange();
|
|
5928
5890
|
return;
|
|
5929
5891
|
}
|
|
5930
5892
|
const guardSnapshot = getSnapshot();
|
|
@@ -5951,7 +5913,6 @@ function performEvent({
|
|
|
5951
5913
|
keyGenerator,
|
|
5952
5914
|
schema,
|
|
5953
5915
|
getSnapshot,
|
|
5954
|
-
defaultActionCallback: void 0,
|
|
5955
5916
|
nativeEvent: void 0
|
|
5956
5917
|
});
|
|
5957
5918
|
continue;
|
|
@@ -5966,45 +5927,53 @@ function performEvent({
|
|
|
5966
5927
|
keyGenerator,
|
|
5967
5928
|
schema,
|
|
5968
5929
|
getSnapshot,
|
|
5969
|
-
defaultActionCallback: void 0,
|
|
5970
5930
|
nativeEvent: void 0
|
|
5971
5931
|
});
|
|
5972
|
-
else
|
|
5973
|
-
|
|
5974
|
-
|
|
5975
|
-
|
|
5976
|
-
|
|
5977
|
-
|
|
5978
|
-
|
|
5979
|
-
|
|
5980
|
-
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
|
|
5932
|
+
else {
|
|
5933
|
+
const internalAction2 = {
|
|
5934
|
+
...action.event,
|
|
5935
|
+
editor
|
|
5936
|
+
};
|
|
5937
|
+
let actionFailed2 = !1;
|
|
5938
|
+
if (withApplyingBehaviorActions(editor, () => {
|
|
5939
|
+
try {
|
|
5940
|
+
performAction({
|
|
5941
|
+
context: {
|
|
5942
|
+
keyGenerator,
|
|
5943
|
+
schema
|
|
5944
|
+
},
|
|
5945
|
+
action: internalAction2
|
|
5946
|
+
});
|
|
5947
|
+
} catch (error) {
|
|
5948
|
+
console.error(new Error(`Performing action "${action.event.type}" as a result of "${event.type}" failed due to: ${error.message}`)), actionFailed2 = !0;
|
|
5949
|
+
}
|
|
5950
|
+
}), actionFailed2)
|
|
5986
5951
|
break;
|
|
5987
|
-
|
|
5952
|
+
editor.onChange();
|
|
5953
|
+
}
|
|
5988
5954
|
continue;
|
|
5989
5955
|
}
|
|
5990
5956
|
const internalAction = {
|
|
5991
5957
|
...action,
|
|
5992
5958
|
editor
|
|
5993
5959
|
};
|
|
5994
|
-
|
|
5995
|
-
|
|
5996
|
-
|
|
5997
|
-
|
|
5998
|
-
|
|
5999
|
-
|
|
6000
|
-
|
|
6001
|
-
|
|
6002
|
-
|
|
6003
|
-
|
|
5960
|
+
let actionFailed = !1;
|
|
5961
|
+
if (withApplyingBehaviorActions(editor, () => {
|
|
5962
|
+
try {
|
|
5963
|
+
performAction({
|
|
5964
|
+
context: {
|
|
5965
|
+
keyGenerator,
|
|
5966
|
+
schema
|
|
5967
|
+
},
|
|
5968
|
+
action: internalAction
|
|
5969
|
+
});
|
|
5970
|
+
} catch (error) {
|
|
5971
|
+
console.error(new Error(`Performing action "${internalAction.type}" as a result of "${event.type}" failed due to: ${error.message}`)), actionFailed = !0;
|
|
5972
|
+
}
|
|
5973
|
+
}), actionFailed)
|
|
6004
5974
|
break;
|
|
6005
|
-
|
|
5975
|
+
editor.onChange();
|
|
6006
5976
|
}
|
|
6007
|
-
editor.onChange();
|
|
6008
5977
|
}));
|
|
6009
5978
|
}
|
|
6010
5979
|
if (behaviorOverwritten) {
|
|
@@ -6014,16 +5983,6 @@ function performEvent({
|
|
|
6014
5983
|
}
|
|
6015
5984
|
}
|
|
6016
5985
|
if (!behaviorOverwritten) {
|
|
6017
|
-
if (defaultActionCallback) {
|
|
6018
|
-
withApplyingBehaviorActions(editor, () => {
|
|
6019
|
-
try {
|
|
6020
|
-
defaultActionCallback();
|
|
6021
|
-
} catch (error) {
|
|
6022
|
-
console.error(new Error(`Performing "${event.type}" failed due to: ${error.message}`));
|
|
6023
|
-
}
|
|
6024
|
-
});
|
|
6025
|
-
return;
|
|
6026
|
-
}
|
|
6027
5986
|
if (!defaultAction)
|
|
6028
5987
|
return;
|
|
6029
5988
|
withApplyingBehaviorActions(editor, () => {
|
|
@@ -6034,11 +5993,11 @@ function performEvent({
|
|
|
6034
5993
|
schema
|
|
6035
5994
|
},
|
|
6036
5995
|
action: defaultAction
|
|
6037
|
-
})
|
|
5996
|
+
});
|
|
6038
5997
|
} catch (error) {
|
|
6039
5998
|
console.error(new Error(`Performing action "${defaultAction.type}" as a result of "${event.type}" failed due to: ${error.message}`));
|
|
6040
5999
|
}
|
|
6041
|
-
});
|
|
6000
|
+
}), editor.onChange();
|
|
6042
6001
|
}
|
|
6043
6002
|
}
|
|
6044
6003
|
function slateChildrenToBlocks(schema, value) {
|
|
@@ -6182,6 +6141,30 @@ const editorMachine = setup({
|
|
|
6182
6141
|
"clear pending events": assign({
|
|
6183
6142
|
pendingEvents: []
|
|
6184
6143
|
}),
|
|
6144
|
+
"handle blur": ({
|
|
6145
|
+
event
|
|
6146
|
+
}) => {
|
|
6147
|
+
assertEvent(event, "blur");
|
|
6148
|
+
try {
|
|
6149
|
+
ReactEditor.blur(event.editor);
|
|
6150
|
+
} catch (error) {
|
|
6151
|
+
console.error(new Error(`Failed to blur editor: ${error.message}`));
|
|
6152
|
+
}
|
|
6153
|
+
},
|
|
6154
|
+
"handle focus": ({
|
|
6155
|
+
context
|
|
6156
|
+
}) => {
|
|
6157
|
+
if (!context.slateEditor) {
|
|
6158
|
+
console.error("No Slate editor found to focus");
|
|
6159
|
+
return;
|
|
6160
|
+
}
|
|
6161
|
+
try {
|
|
6162
|
+
const currentSelection = context.slateEditor.selection;
|
|
6163
|
+
ReactEditor.focus(context.slateEditor), currentSelection && Transforms.select(context.slateEditor, currentSelection);
|
|
6164
|
+
} catch (error) {
|
|
6165
|
+
console.error(new Error(`Failed to focus editor: ${error.message}`));
|
|
6166
|
+
}
|
|
6167
|
+
},
|
|
6185
6168
|
"handle behavior event": ({
|
|
6186
6169
|
context,
|
|
6187
6170
|
event,
|
|
@@ -6205,10 +6188,14 @@ const editorMachine = setup({
|
|
|
6205
6188
|
hasTag: (tag) => self.getSnapshot().hasTag(tag),
|
|
6206
6189
|
internalDrag: context.internalDrag
|
|
6207
6190
|
}),
|
|
6208
|
-
nativeEvent: event.nativeEvent
|
|
6209
|
-
defaultActionCallback: event.type === "behavior event" ? event.defaultActionCallback : void 0
|
|
6191
|
+
nativeEvent: event.nativeEvent
|
|
6210
6192
|
});
|
|
6211
6193
|
}
|
|
6194
|
+
},
|
|
6195
|
+
guards: {
|
|
6196
|
+
"slate is busy": ({
|
|
6197
|
+
context
|
|
6198
|
+
}) => context.slateEditor ? context.slateEditor.operations.length > 0 : !1
|
|
6212
6199
|
}
|
|
6213
6200
|
}).createMachine({
|
|
6214
6201
|
id: "editor",
|
|
@@ -6387,6 +6374,17 @@ const editorMachine = setup({
|
|
|
6387
6374
|
},
|
|
6388
6375
|
"behavior event": {
|
|
6389
6376
|
actions: "handle behavior event"
|
|
6377
|
+
},
|
|
6378
|
+
blur: {
|
|
6379
|
+
actions: "handle blur"
|
|
6380
|
+
},
|
|
6381
|
+
focus: {
|
|
6382
|
+
target: ".focusing",
|
|
6383
|
+
actions: [assign({
|
|
6384
|
+
slateEditor: ({
|
|
6385
|
+
event
|
|
6386
|
+
}) => event.editor
|
|
6387
|
+
})]
|
|
6390
6388
|
}
|
|
6391
6389
|
},
|
|
6392
6390
|
initial: "idle",
|
|
@@ -6406,6 +6404,27 @@ const editorMachine = setup({
|
|
|
6406
6404
|
}
|
|
6407
6405
|
}
|
|
6408
6406
|
},
|
|
6407
|
+
focusing: {
|
|
6408
|
+
initial: "checking if busy",
|
|
6409
|
+
states: {
|
|
6410
|
+
"checking if busy": {
|
|
6411
|
+
always: [{
|
|
6412
|
+
guard: "slate is busy",
|
|
6413
|
+
target: "busy"
|
|
6414
|
+
}, {
|
|
6415
|
+
target: "#editor.edit mode.editable.idle",
|
|
6416
|
+
actions: ["handle focus"]
|
|
6417
|
+
}]
|
|
6418
|
+
},
|
|
6419
|
+
busy: {
|
|
6420
|
+
after: {
|
|
6421
|
+
10: {
|
|
6422
|
+
target: "checking if busy"
|
|
6423
|
+
}
|
|
6424
|
+
}
|
|
6425
|
+
}
|
|
6426
|
+
}
|
|
6427
|
+
},
|
|
6409
6428
|
"dragging internally": {
|
|
6410
6429
|
exit: [({
|
|
6411
6430
|
context
|
|
@@ -6738,19 +6757,13 @@ function createEditableAPI(editor, editorActor) {
|
|
|
6738
6757
|
return {
|
|
6739
6758
|
focus: () => {
|
|
6740
6759
|
editorActor.send({
|
|
6741
|
-
type: "
|
|
6742
|
-
behaviorEvent: {
|
|
6743
|
-
type: "focus"
|
|
6744
|
-
},
|
|
6760
|
+
type: "focus",
|
|
6745
6761
|
editor
|
|
6746
6762
|
});
|
|
6747
6763
|
},
|
|
6748
6764
|
blur: () => {
|
|
6749
6765
|
editorActor.send({
|
|
6750
|
-
type: "
|
|
6751
|
-
behaviorEvent: {
|
|
6752
|
-
type: "blur"
|
|
6753
|
-
},
|
|
6766
|
+
type: "blur",
|
|
6754
6767
|
editor
|
|
6755
6768
|
});
|
|
6756
6769
|
},
|
|
@@ -7162,6 +7175,18 @@ function createInternalEditorFromActor(editorActor, legacySchema) {
|
|
|
7162
7175
|
case "update maxBlocks":
|
|
7163
7176
|
editorActor.send(event);
|
|
7164
7177
|
break;
|
|
7178
|
+
case "blur":
|
|
7179
|
+
editorActor.send({
|
|
7180
|
+
type: "blur",
|
|
7181
|
+
editor: slateEditor.instance
|
|
7182
|
+
});
|
|
7183
|
+
break;
|
|
7184
|
+
case "focus":
|
|
7185
|
+
editorActor.send({
|
|
7186
|
+
type: "focus",
|
|
7187
|
+
editor: slateEditor.instance
|
|
7188
|
+
});
|
|
7189
|
+
break;
|
|
7165
7190
|
case "insert.block object":
|
|
7166
7191
|
editorActor.send({
|
|
7167
7192
|
type: "behavior event",
|