@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.js
CHANGED
|
@@ -812,6 +812,17 @@ function getFocusBlockObject(context) {
|
|
|
812
812
|
const focusBlock = getFocusBlock(context);
|
|
813
813
|
return focusBlock && !types.isPortableTextTextBlock(focusBlock.node) ? { node: focusBlock.node, path: focusBlock.path } : void 0;
|
|
814
814
|
}
|
|
815
|
+
function getFocusChild(context) {
|
|
816
|
+
const focusBlock = getFocusTextBlock(context);
|
|
817
|
+
if (!focusBlock)
|
|
818
|
+
return;
|
|
819
|
+
const key = context.selection && types.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;
|
|
820
|
+
return node && key ? { node, path: [...focusBlock.path, "children", { _key: key }] } : void 0;
|
|
821
|
+
}
|
|
822
|
+
function getFocusSpan(context) {
|
|
823
|
+
const focusChild = getFocusChild(context);
|
|
824
|
+
return focusChild && types.isPortableTextSpan(focusChild.node) ? { node: focusChild.node, path: focusChild.path } : void 0;
|
|
825
|
+
}
|
|
815
826
|
function getSelectionStartBlock(context) {
|
|
816
827
|
const key = context.selection.backward ? types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0 : types.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;
|
|
817
828
|
return node && key ? { node, path: [{ _key: key }] } : void 0;
|
|
@@ -858,11 +869,7 @@ function getNextBlock(context) {
|
|
|
858
869
|
function isEmptyTextBlock(block) {
|
|
859
870
|
return block.children.length === 1 && block.children[0].text === "";
|
|
860
871
|
}
|
|
861
|
-
const
|
|
862
|
-
on: "insert soft break",
|
|
863
|
-
actions: [() => [{ type: "insert text", text: `
|
|
864
|
-
` }]]
|
|
865
|
-
}, breakingVoidBlock = {
|
|
872
|
+
const breakingVoidBlock = {
|
|
866
873
|
on: "insert break",
|
|
867
874
|
guard: ({ context }) => !!getFocusBlockObject(context),
|
|
868
875
|
actions: [() => [{ type: "insert text block", decorators: [] }]]
|
|
@@ -914,11 +921,48 @@ const softReturn = {
|
|
|
914
921
|
}
|
|
915
922
|
]
|
|
916
923
|
]
|
|
917
|
-
},
|
|
918
|
-
softReturn,
|
|
924
|
+
}, coreBlockObjectBehaviors = [
|
|
919
925
|
breakingVoidBlock,
|
|
920
926
|
deletingEmptyTextBlockAfterBlockObject,
|
|
921
927
|
deletingEmptyTextBlockBeforeBlockObject
|
|
928
|
+
], clearListOnBackspace = {
|
|
929
|
+
on: "delete backward",
|
|
930
|
+
guard: ({ context }) => {
|
|
931
|
+
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
932
|
+
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level === 1 ? { focusTextBlock } : !1;
|
|
933
|
+
},
|
|
934
|
+
actions: [
|
|
935
|
+
(_, { focusTextBlock }) => [
|
|
936
|
+
{
|
|
937
|
+
type: "unset block",
|
|
938
|
+
props: ["listItem", "level"],
|
|
939
|
+
paths: [focusTextBlock.path]
|
|
940
|
+
}
|
|
941
|
+
]
|
|
942
|
+
]
|
|
943
|
+
}, unindentListOnBackspace = {
|
|
944
|
+
on: "delete backward",
|
|
945
|
+
guard: ({ context }) => {
|
|
946
|
+
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
947
|
+
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;
|
|
948
|
+
},
|
|
949
|
+
actions: [
|
|
950
|
+
(_, { focusTextBlock, level }) => [
|
|
951
|
+
{
|
|
952
|
+
type: "set block",
|
|
953
|
+
level,
|
|
954
|
+
paths: [focusTextBlock.path]
|
|
955
|
+
}
|
|
956
|
+
]
|
|
957
|
+
]
|
|
958
|
+
}, coreListBehaviors = [clearListOnBackspace, unindentListOnBackspace], softReturn = {
|
|
959
|
+
on: "insert soft break",
|
|
960
|
+
actions: [() => [{ type: "insert text", text: `
|
|
961
|
+
` }]]
|
|
962
|
+
}, coreBehaviors = [
|
|
963
|
+
softReturn,
|
|
964
|
+
...coreBlockObjectBehaviors,
|
|
965
|
+
...coreListBehaviors
|
|
922
966
|
], debug$k = debugWithName("operationToPatches");
|
|
923
967
|
function createOperationToPatches(types2) {
|
|
924
968
|
const textBlockName = types2.block.name;
|