@portabletext/editor 1.0.10 → 1.0.11
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.esm.js +21 -8
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +21 -8
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +21 -8
- package/lib/index.mjs.map +1 -1
- package/package.json +7 -7
- package/src/editor/__tests__/insert-block.test.tsx +229 -0
- package/src/editor/plugins/createWithEditableAPI.ts +41 -10
package/lib/index.esm.js
CHANGED
|
@@ -1020,9 +1020,7 @@ function createWithEditableAPI(portableTextEditor, types, keyGenerator) {
|
|
|
1020
1020
|
)) == null ? void 0 : _a.focus.path) || [];
|
|
1021
1021
|
},
|
|
1022
1022
|
insertBlock: (type, value) => {
|
|
1023
|
-
var _a;
|
|
1024
|
-
if (!editor.selection)
|
|
1025
|
-
throw new Error("The editor has no selection");
|
|
1023
|
+
var _a, _b, _c;
|
|
1026
1024
|
const block = toSlateValue(
|
|
1027
1025
|
[
|
|
1028
1026
|
{
|
|
@@ -1032,17 +1030,32 @@ function createWithEditableAPI(portableTextEditor, types, keyGenerator) {
|
|
|
1032
1030
|
}
|
|
1033
1031
|
],
|
|
1034
1032
|
portableTextEditor
|
|
1035
|
-
)[0]
|
|
1033
|
+
)[0];
|
|
1034
|
+
if (!editor.selection) {
|
|
1035
|
+
const lastBlock = Array.from(
|
|
1036
|
+
Editor.nodes(editor, {
|
|
1037
|
+
match: (n) => !Editor.isEditor(n),
|
|
1038
|
+
at: [],
|
|
1039
|
+
reverse: !0
|
|
1040
|
+
})
|
|
1041
|
+
)[0];
|
|
1042
|
+
return Editor.insertNode(editor, block), lastBlock && isEqualToEmptyEditor([lastBlock[0]], types) && Transforms.removeNodes(editor, { at: lastBlock[1] }), editor.onChange(), (_b = (_a = toPortableTextRange(
|
|
1043
|
+
fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)),
|
|
1044
|
+
editor.selection,
|
|
1045
|
+
types
|
|
1046
|
+
)) == null ? void 0 : _a.focus.path) != null ? _b : [];
|
|
1047
|
+
}
|
|
1048
|
+
const focusBlock = Array.from(
|
|
1036
1049
|
Editor.nodes(editor, {
|
|
1037
1050
|
at: editor.selection.focus.path.slice(0, 1),
|
|
1038
1051
|
match: (n) => n._type === types.block.name
|
|
1039
1052
|
})
|
|
1040
|
-
)[0]
|
|
1041
|
-
return focusBlock && isEqualToEmptyEditor([focusBlock], types) && Transforms.removeNodes(editor, { at:
|
|
1053
|
+
)[0];
|
|
1054
|
+
return Editor.insertNode(editor, block), focusBlock && isEqualToEmptyEditor([focusBlock[0]], types) && Transforms.removeNodes(editor, { at: focusBlock[1] }), editor.onChange(), ((_c = toPortableTextRange(
|
|
1042
1055
|
fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)),
|
|
1043
1056
|
editor.selection,
|
|
1044
1057
|
types
|
|
1045
|
-
)) == null ? void 0 :
|
|
1058
|
+
)) == null ? void 0 : _c.focus.path) || [];
|
|
1046
1059
|
},
|
|
1047
1060
|
hasBlockStyle: (style) => {
|
|
1048
1061
|
try {
|
|
@@ -1127,7 +1140,7 @@ function createWithEditableAPI(portableTextEditor, types, keyGenerator) {
|
|
|
1127
1140
|
match: (node) => Text.isText(node)
|
|
1128
1141
|
})
|
|
1129
1142
|
];
|
|
1130
|
-
if (spans.some(
|
|
1143
|
+
if (spans.length === 0 || spans.some(
|
|
1131
1144
|
([span]) => {
|
|
1132
1145
|
var _a;
|
|
1133
1146
|
return !isPortableTextSpan(span) || !span.marks || ((_a = span.marks) == null ? void 0 : _a.length) === 0;
|