@portabletext/editor 1.1.12 → 1.2.0
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 +51 -7
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +51 -7
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +51 -7
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/editor/behavior/behavior.core.block-objects.ts +106 -0
- package/src/editor/behavior/behavior.core.lists.ts +76 -0
- package/src/editor/behavior/behavior.core.ts +4 -102
package/lib/index.esm.js
CHANGED
|
@@ -830,6 +830,17 @@ function getFocusBlockObject(context) {
|
|
|
830
830
|
const focusBlock = getFocusBlock(context);
|
|
831
831
|
return focusBlock && !isPortableTextTextBlock(focusBlock.node) ? { node: focusBlock.node, path: focusBlock.path } : void 0;
|
|
832
832
|
}
|
|
833
|
+
function getFocusChild(context) {
|
|
834
|
+
const focusBlock = getFocusTextBlock(context);
|
|
835
|
+
if (!focusBlock)
|
|
836
|
+
return;
|
|
837
|
+
const key = context.selection && isKeySegment(context.selection.focus.path[2]) ? context.selection.focus.path[2]._key : void 0, node = key ? focusBlock.node.children.find((span) => span._key === key) : void 0;
|
|
838
|
+
return node && key ? { node, path: [...focusBlock.path, "children", { _key: key }] } : void 0;
|
|
839
|
+
}
|
|
840
|
+
function getFocusSpan(context) {
|
|
841
|
+
const focusChild = getFocusChild(context);
|
|
842
|
+
return focusChild && isPortableTextSpan(focusChild.node) ? { node: focusChild.node, path: focusChild.path } : void 0;
|
|
843
|
+
}
|
|
833
844
|
function getSelectionStartBlock(context) {
|
|
834
845
|
const key = context.selection.backward ? isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0 : isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
|
|
835
846
|
return node && key ? { node, path: [{ _key: key }] } : void 0;
|
|
@@ -876,11 +887,7 @@ function getNextBlock(context) {
|
|
|
876
887
|
function isEmptyTextBlock(block) {
|
|
877
888
|
return block.children.length === 1 && block.children[0].text === "";
|
|
878
889
|
}
|
|
879
|
-
const
|
|
880
|
-
on: "insert soft break",
|
|
881
|
-
actions: [() => [{ type: "insert text", text: `
|
|
882
|
-
` }]]
|
|
883
|
-
}, breakingVoidBlock = {
|
|
890
|
+
const breakingVoidBlock = {
|
|
884
891
|
on: "insert break",
|
|
885
892
|
guard: ({ context }) => !!getFocusBlockObject(context),
|
|
886
893
|
actions: [() => [{ type: "insert text block", decorators: [] }]]
|
|
@@ -932,11 +939,48 @@ const softReturn = {
|
|
|
932
939
|
}
|
|
933
940
|
]
|
|
934
941
|
]
|
|
935
|
-
},
|
|
936
|
-
softReturn,
|
|
942
|
+
}, coreBlockObjectBehaviors = [
|
|
937
943
|
breakingVoidBlock,
|
|
938
944
|
deletingEmptyTextBlockAfterBlockObject,
|
|
939
945
|
deletingEmptyTextBlockBeforeBlockObject
|
|
946
|
+
], clearListOnBackspace = {
|
|
947
|
+
on: "delete backward",
|
|
948
|
+
guard: ({ context }) => {
|
|
949
|
+
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
950
|
+
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level === 1 ? { focusTextBlock } : !1;
|
|
951
|
+
},
|
|
952
|
+
actions: [
|
|
953
|
+
(_, { focusTextBlock }) => [
|
|
954
|
+
{
|
|
955
|
+
type: "unset block",
|
|
956
|
+
props: ["listItem", "level"],
|
|
957
|
+
paths: [focusTextBlock.path]
|
|
958
|
+
}
|
|
959
|
+
]
|
|
960
|
+
]
|
|
961
|
+
}, unindentListOnBackspace = {
|
|
962
|
+
on: "delete backward",
|
|
963
|
+
guard: ({ context }) => {
|
|
964
|
+
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
965
|
+
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level !== void 0 && focusTextBlock.node.level > 1 ? { focusTextBlock, level: focusTextBlock.node.level - 1 } : !1;
|
|
966
|
+
},
|
|
967
|
+
actions: [
|
|
968
|
+
(_, { focusTextBlock, level }) => [
|
|
969
|
+
{
|
|
970
|
+
type: "set block",
|
|
971
|
+
level,
|
|
972
|
+
paths: [focusTextBlock.path]
|
|
973
|
+
}
|
|
974
|
+
]
|
|
975
|
+
]
|
|
976
|
+
}, coreListBehaviors = [clearListOnBackspace, unindentListOnBackspace], softReturn = {
|
|
977
|
+
on: "insert soft break",
|
|
978
|
+
actions: [() => [{ type: "insert text", text: `
|
|
979
|
+
` }]]
|
|
980
|
+
}, coreBehaviors = [
|
|
981
|
+
softReturn,
|
|
982
|
+
...coreBlockObjectBehaviors,
|
|
983
|
+
...coreListBehaviors
|
|
940
984
|
], debug$k = debugWithName("operationToPatches");
|
|
941
985
|
function createOperationToPatches(types) {
|
|
942
986
|
const textBlockName = types.block.name;
|