@portabletext/editor 1.0.3 → 1.0.5
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.d.mts +3 -3
- package/lib/index.d.ts +3 -3
- package/lib/index.esm.js +1 -3
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +150 -158
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +1 -3
- package/lib/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/editor/components/Synchronizer.tsx +1 -1
- package/src/editor/plugins/createWithPatches.ts +1 -2
- package/src/editor/plugins/createWithUndoRedo.ts +1 -1
- package/src/index.ts +1 -1
- package/src/types/editor.ts +1 -1
- package/src/utils/__tests__/dmpToOperations.test.ts +1 -1
- package/src/utils/__tests__/patchToOperations.test.ts +2 -1
- package/src/utils/applyPatch.ts +2 -2
- package/src/utils/operationToPatches.ts +9 -2
- package/src/utils/validateValue.ts +1 -1
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var jsxRuntime = require("react/jsx-runtime"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), react = require("react"), slate = require("slate"), slateReact = require("slate-react"), debug$l = require("debug"), types
|
|
3
|
+
var jsxRuntime = require("react/jsx-runtime"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), react = require("react"), slate = require("slate"), slateReact = require("slate-react"), debug$l = require("debug"), types = require("@sanity/types"), styledComponents = require("styled-components"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), schema = require("@sanity/schema"), patches = require("@portabletext/patches"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), flatten = require("lodash/flatten.js"), isHotkeyEsm = require("is-hotkey-esm"), blockTools = require("@sanity/block-tools"), isPlainObject = require("lodash/isPlainObject.js"), throttle = require("lodash/throttle.js"), content = require("@sanity/util/content"), debounce = require("lodash/debounce.js");
|
|
4
4
|
function _interopDefaultCompat(e) {
|
|
5
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
6
|
}
|
|
@@ -31,7 +31,7 @@ function createArrayedPath(point, editor) {
|
|
|
31
31
|
const [block, blockPath] = Array.from(
|
|
32
32
|
slate.Editor.nodes(editor, {
|
|
33
33
|
at: [],
|
|
34
|
-
match: (n) => types
|
|
34
|
+
match: (n) => types.isKeySegment(point.path[0]) && n._key === point.path[0]._key
|
|
35
35
|
})
|
|
36
36
|
)[0] || [void 0, void 0];
|
|
37
37
|
if (!block || !slate.Element.isElement(block))
|
|
@@ -713,7 +713,7 @@ function createOperationToPatches(types2) {
|
|
|
713
713
|
const textChild = editor.isTextBlock(block) && editor.isTextSpan(block.children[operation.path[1]]) && block.children[operation.path[1]];
|
|
714
714
|
if (!textChild)
|
|
715
715
|
throw new Error("Could not find child");
|
|
716
|
-
const path = [{ _key: block._key }, "children", { _key: textChild._key }, "text"], prevBlock = beforeValue[operation.path[0]], prevChild = editor.isTextBlock(prevBlock) && prevBlock.children[operation.path[1]], prevText = editor.isTextSpan(prevChild) ? prevChild.text : "", patch =
|
|
716
|
+
const path = [{ _key: block._key }, "children", { _key: textChild._key }, "text"], prevBlock = beforeValue[operation.path[0]], prevChild = editor.isTextBlock(prevBlock) && prevBlock.children[operation.path[1]], prevText = editor.isTextSpan(prevChild) ? prevChild.text : "", patch = patches.diffMatchPatch(prevText, textChild.text, path);
|
|
717
717
|
return patch.value.length ? [patch] : [];
|
|
718
718
|
}
|
|
719
719
|
function removeTextPatch(editor, operation, beforeValue) {
|
|
@@ -725,7 +725,7 @@ function createOperationToPatches(types2) {
|
|
|
725
725
|
throw new Error("Expected span");
|
|
726
726
|
if (!textChild)
|
|
727
727
|
throw new Error("Could not find child");
|
|
728
|
-
const path = [{ _key: block._key }, "children", { _key: textChild._key }, "text"], beforeBlock = beforeValue[operation.path[0]], prevTextChild = editor.isTextBlock(beforeBlock) && beforeBlock.children[operation.path[1]], prevText = editor.isTextSpan(prevTextChild) && prevTextChild.text, patch =
|
|
728
|
+
const path = [{ _key: block._key }, "children", { _key: textChild._key }, "text"], beforeBlock = beforeValue[operation.path[0]], prevTextChild = editor.isTextBlock(beforeBlock) && beforeBlock.children[operation.path[1]], prevText = editor.isTextSpan(prevTextChild) && prevTextChild.text, patch = patches.diffMatchPatch(prevText || "", textChild.text, path);
|
|
729
729
|
return patch.value ? [patch] : [];
|
|
730
730
|
}
|
|
731
731
|
function setNodePatch(editor, operation) {
|
|
@@ -737,24 +737,24 @@ function createOperationToPatches(types2) {
|
|
|
737
737
|
{ ...editor.children[operation.path[0]], ...operation.newProperties },
|
|
738
738
|
isUndefined__default.default
|
|
739
739
|
);
|
|
740
|
-
return [
|
|
740
|
+
return [patches.set(fromSlateValue([setNode], textBlockName)[0], [{ _key: block._key }])];
|
|
741
741
|
} else if (operation.path.length === 2) {
|
|
742
742
|
const block = editor.children[operation.path[0]];
|
|
743
743
|
if (editor.isTextBlock(block)) {
|
|
744
744
|
const child = block.children[operation.path[1]];
|
|
745
745
|
if (child) {
|
|
746
|
-
const blockKey = block._key, childKey = child._key, patches = [], keys = Object.keys(operation.newProperties);
|
|
746
|
+
const blockKey = block._key, childKey = child._key, patches$1 = [], keys = Object.keys(operation.newProperties);
|
|
747
747
|
return keys.forEach((keyName) => {
|
|
748
748
|
if (keys.length === 1 && keyName === "_key") {
|
|
749
749
|
const val = get__default.default(operation.newProperties, keyName);
|
|
750
|
-
patches.push(
|
|
751
|
-
|
|
750
|
+
patches$1.push(
|
|
751
|
+
patches.set(val, [{ _key: blockKey }, "children", block.children.indexOf(child), keyName])
|
|
752
752
|
);
|
|
753
753
|
} else {
|
|
754
754
|
const val = get__default.default(operation.newProperties, keyName);
|
|
755
|
-
patches.push(
|
|
755
|
+
patches$1.push(patches.set(val, [{ _key: blockKey }, "children", { _key: childKey }, keyName]));
|
|
756
756
|
}
|
|
757
|
-
}), patches;
|
|
757
|
+
}), patches$1;
|
|
758
758
|
}
|
|
759
759
|
throw new Error("Could not find a valid child");
|
|
760
760
|
}
|
|
@@ -767,12 +767,12 @@ function createOperationToPatches(types2) {
|
|
|
767
767
|
if (operation.path.length === 1) {
|
|
768
768
|
const position = operation.path[0] === 0 ? "before" : "after", beforeBlock = beforeValue[operation.path[0] - 1], targetKey = operation.path[0] === 0 ? block == null ? void 0 : block._key : beforeBlock == null ? void 0 : beforeBlock._key;
|
|
769
769
|
return targetKey ? [
|
|
770
|
-
|
|
770
|
+
patches.insert([fromSlateValue([operation.node], textBlockName)[0]], position, [
|
|
771
771
|
{ _key: targetKey }
|
|
772
772
|
])
|
|
773
773
|
] : [
|
|
774
|
-
|
|
775
|
-
|
|
774
|
+
patches.setIfMissing(beforeValue, []),
|
|
775
|
+
patches.insert([fromSlateValue([operation.node], textBlockName)[0]], "before", [
|
|
776
776
|
operation.path[0]
|
|
777
777
|
])
|
|
778
778
|
];
|
|
@@ -790,7 +790,7 @@ function createOperationToPatches(types2) {
|
|
|
790
790
|
textBlockName
|
|
791
791
|
)[0].children[0];
|
|
792
792
|
return [
|
|
793
|
-
|
|
793
|
+
patches.insert([child], position, [
|
|
794
794
|
{ _key: block._key },
|
|
795
795
|
"children",
|
|
796
796
|
block.children.length <= 1 || !block.children[operation.path[1] - 1] ? 0 : { _key: block.children[operation.path[1] - 1]._key }
|
|
@@ -800,7 +800,7 @@ function createOperationToPatches(types2) {
|
|
|
800
800
|
return debug$j("Something was inserted into a void block. Not producing editor patches."), [];
|
|
801
801
|
}
|
|
802
802
|
function splitNodePatch(editor, operation, beforeValue) {
|
|
803
|
-
const patches = [], splitBlock = editor.children[operation.path[0]];
|
|
803
|
+
const patches$1 = [], splitBlock = editor.children[operation.path[0]];
|
|
804
804
|
if (!editor.isTextBlock(splitBlock))
|
|
805
805
|
throw new Error(
|
|
806
806
|
`Block with path ${JSON.stringify(
|
|
@@ -814,12 +814,12 @@ function createOperationToPatches(types2) {
|
|
|
814
814
|
[editor.children[operation.path[0] + 1]],
|
|
815
815
|
textBlockName
|
|
816
816
|
)[0];
|
|
817
|
-
targetValue && (patches.push(
|
|
817
|
+
targetValue && (patches$1.push(patches.insert([targetValue], "after", [{ _key: splitBlock._key }])), oldBlock.children.slice(operation.position).forEach((span) => {
|
|
818
818
|
const path = [{ _key: oldBlock._key }, "children", { _key: span._key }];
|
|
819
|
-
patches.push(
|
|
819
|
+
patches$1.push(patches.unset(path));
|
|
820
820
|
}));
|
|
821
821
|
}
|
|
822
|
-
return patches;
|
|
822
|
+
return patches$1;
|
|
823
823
|
}
|
|
824
824
|
if (operation.path.length === 2) {
|
|
825
825
|
const splitSpan = splitBlock.children[operation.path[1]];
|
|
@@ -833,14 +833,14 @@ function createOperationToPatches(types2) {
|
|
|
833
833
|
],
|
|
834
834
|
textBlockName
|
|
835
835
|
)[0].children;
|
|
836
|
-
patches.push(
|
|
837
|
-
|
|
836
|
+
patches$1.push(
|
|
837
|
+
patches.insert(targetSpans, "after", [
|
|
838
838
|
{ _key: splitBlock._key },
|
|
839
839
|
"children",
|
|
840
840
|
{ _key: splitSpan._key }
|
|
841
841
|
])
|
|
842
|
-
), patches.push(
|
|
843
|
-
|
|
842
|
+
), patches$1.push(
|
|
843
|
+
patches.set(splitSpan.text, [
|
|
844
844
|
{ _key: splitBlock._key },
|
|
845
845
|
"children",
|
|
846
846
|
{ _key: splitSpan._key },
|
|
@@ -848,57 +848,57 @@ function createOperationToPatches(types2) {
|
|
|
848
848
|
])
|
|
849
849
|
);
|
|
850
850
|
}
|
|
851
|
-
return patches;
|
|
851
|
+
return patches$1;
|
|
852
852
|
}
|
|
853
|
-
return patches;
|
|
853
|
+
return patches$1;
|
|
854
854
|
}
|
|
855
855
|
function removeNodePatch(editor, operation, beforeValue) {
|
|
856
856
|
const block = beforeValue[operation.path[0]];
|
|
857
857
|
if (operation.path.length === 1) {
|
|
858
858
|
if (block && block._key)
|
|
859
|
-
return [
|
|
859
|
+
return [patches.unset([{ _key: block._key }])];
|
|
860
860
|
throw new Error("Block not found");
|
|
861
861
|
} else if (editor.isTextBlock(block) && operation.path.length === 2) {
|
|
862
862
|
const spanToRemove = editor.isTextBlock(block) && block.children && block.children[operation.path[1]];
|
|
863
|
-
return spanToRemove ? [
|
|
863
|
+
return spanToRemove ? [patches.unset([{ _key: block._key }, "children", { _key: spanToRemove._key }])] : (debug$j("Span not found in editor trying to remove node"), []);
|
|
864
864
|
} else
|
|
865
865
|
return debug$j("Not creating patch inside object block"), [];
|
|
866
866
|
}
|
|
867
867
|
function mergeNodePatch(editor, operation, beforeValue) {
|
|
868
|
-
const patches = [], block = beforeValue[operation.path[0]], targetBlock = editor.children[operation.path[0]];
|
|
868
|
+
const patches$1 = [], block = beforeValue[operation.path[0]], targetBlock = editor.children[operation.path[0]];
|
|
869
869
|
if (operation.path.length === 1)
|
|
870
870
|
if (block != null && block._key) {
|
|
871
871
|
const newBlock = fromSlateValue([editor.children[operation.path[0] - 1]], textBlockName)[0];
|
|
872
|
-
patches.push(
|
|
872
|
+
patches$1.push(patches.set(newBlock, [{ _key: newBlock._key }])), patches$1.push(patches.unset([{ _key: block._key }]));
|
|
873
873
|
} else
|
|
874
874
|
throw new Error("Target key not found!");
|
|
875
875
|
else if (operation.path.length === 2 && editor.isTextBlock(targetBlock)) {
|
|
876
876
|
const mergedSpan = editor.isTextBlock(block) && block.children[operation.path[1]] || void 0, targetSpan = targetBlock.children[operation.path[1] - 1];
|
|
877
|
-
editor.isTextSpan(targetSpan) && (patches.push(
|
|
878
|
-
|
|
879
|
-
), mergedSpan && patches.push(
|
|
877
|
+
editor.isTextSpan(targetSpan) && (patches$1.push(
|
|
878
|
+
patches.set(targetSpan.text, [{ _key: block._key }, "children", { _key: targetSpan._key }, "text"])
|
|
879
|
+
), mergedSpan && patches$1.push(patches.unset([{ _key: block._key }, "children", { _key: mergedSpan._key }])));
|
|
880
880
|
} else
|
|
881
881
|
debug$j("Void nodes can't be merged, not creating any patches");
|
|
882
|
-
return patches;
|
|
882
|
+
return patches$1;
|
|
883
883
|
}
|
|
884
884
|
function moveNodePatch(editor, operation, beforeValue) {
|
|
885
|
-
const patches = [], block = beforeValue[operation.path[0]], targetBlock = beforeValue[operation.newPath[0]];
|
|
885
|
+
const patches$1 = [], block = beforeValue[operation.path[0]], targetBlock = beforeValue[operation.newPath[0]];
|
|
886
886
|
if (operation.path.length === 1) {
|
|
887
887
|
const position = operation.path[0] > operation.newPath[0] ? "before" : "after";
|
|
888
|
-
patches.push(
|
|
889
|
-
|
|
888
|
+
patches$1.push(patches.unset([{ _key: block._key }])), patches$1.push(
|
|
889
|
+
patches.insert([fromSlateValue([block], textBlockName)[0]], position, [{ _key: targetBlock._key }])
|
|
890
890
|
);
|
|
891
891
|
} else if (operation.path.length === 2 && editor.isTextBlock(block) && editor.isTextBlock(targetBlock)) {
|
|
892
892
|
const child = block.children[operation.path[1]], targetChild = targetBlock.children[operation.newPath[1]], position = operation.newPath[1] === targetBlock.children.length ? "after" : "before", childToInsert = fromSlateValue([block], textBlockName)[0].children[operation.path[1]];
|
|
893
|
-
patches.push(
|
|
894
|
-
|
|
893
|
+
patches$1.push(patches.unset([{ _key: block._key }, "children", { _key: child._key }])), patches$1.push(
|
|
894
|
+
patches.insert([childToInsert], position, [
|
|
895
895
|
{ _key: targetBlock._key },
|
|
896
896
|
"children",
|
|
897
897
|
{ _key: targetChild._key }
|
|
898
898
|
])
|
|
899
899
|
);
|
|
900
900
|
}
|
|
901
|
-
return patches;
|
|
901
|
+
return patches$1;
|
|
902
902
|
}
|
|
903
903
|
return {
|
|
904
904
|
insertNodePatch,
|
|
@@ -912,7 +912,7 @@ function createOperationToPatches(types2) {
|
|
|
912
912
|
};
|
|
913
913
|
}
|
|
914
914
|
const debug$i = debugWithName("API:editable");
|
|
915
|
-
function createWithEditableAPI(portableTextEditor,
|
|
915
|
+
function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
916
916
|
return function(editor) {
|
|
917
917
|
return portableTextEditor.setEditable({
|
|
918
918
|
focus: () => {
|
|
@@ -950,7 +950,7 @@ function createWithEditableAPI(portableTextEditor, types2, keyGenerator) {
|
|
|
950
950
|
if (editor.selection) {
|
|
951
951
|
const block = slate.Node.descendant(editor, editor.selection.focus.path.slice(0, 1));
|
|
952
952
|
if (block)
|
|
953
|
-
return fromSlateValue([block],
|
|
953
|
+
return fromSlateValue([block], types$1.block.name, KEY_TO_VALUE_ELEMENT.get(editor))[0];
|
|
954
954
|
}
|
|
955
955
|
},
|
|
956
956
|
focusChild: () => {
|
|
@@ -959,7 +959,7 @@ function createWithEditableAPI(portableTextEditor, types2, keyGenerator) {
|
|
|
959
959
|
if (block && editor.isTextBlock(block))
|
|
960
960
|
return fromSlateValue(
|
|
961
961
|
[block],
|
|
962
|
-
|
|
962
|
+
types$1.block.name,
|
|
963
963
|
KEY_TO_VALUE_ELEMENT.get(editor)
|
|
964
964
|
)[0].children[editor.selection.focus.path[1]];
|
|
965
965
|
}
|
|
@@ -971,18 +971,18 @@ function createWithEditableAPI(portableTextEditor, types2, keyGenerator) {
|
|
|
971
971
|
const [focusBlock] = Array.from(
|
|
972
972
|
slate.Editor.nodes(editor, {
|
|
973
973
|
at: editor.selection.focus.path.slice(0, 1),
|
|
974
|
-
match: (n) => n._type ===
|
|
974
|
+
match: (n) => n._type === types$1.block.name
|
|
975
975
|
})
|
|
976
976
|
)[0] || [void 0];
|
|
977
977
|
if (!focusBlock)
|
|
978
978
|
throw new Error("No focused text block");
|
|
979
|
-
if (type.name !==
|
|
979
|
+
if (type.name !== types$1.span.name && !types$1.inlineObjects.some((t) => t.name === type.name))
|
|
980
980
|
throw new Error("This type cannot be inserted as a child to a text block");
|
|
981
981
|
const child = toSlateValue(
|
|
982
982
|
[
|
|
983
983
|
{
|
|
984
984
|
_key: keyGenerator(),
|
|
985
|
-
_type:
|
|
985
|
+
_type: types$1.block.name,
|
|
986
986
|
children: [
|
|
987
987
|
{
|
|
988
988
|
_key: keyGenerator(),
|
|
@@ -993,14 +993,14 @@ function createWithEditableAPI(portableTextEditor, types2, keyGenerator) {
|
|
|
993
993
|
}
|
|
994
994
|
],
|
|
995
995
|
portableTextEditor
|
|
996
|
-
)[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type ===
|
|
997
|
-
return isSpanNode && focusNode._type !==
|
|
996
|
+
)[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type === types$1.span.name, focusNode = slate.Node.get(editor, focusChildPath);
|
|
997
|
+
return isSpanNode && focusNode._type !== types$1.span.name && (debug$i("Inserting span child next to inline object child, moving selection + 1"), editor.move({ distance: 1, unit: "character" })), slate.Transforms.insertNodes(editor, child, {
|
|
998
998
|
select: !0,
|
|
999
999
|
at: editor.selection
|
|
1000
1000
|
}), editor.onChange(), ((_a = toPortableTextRange(
|
|
1001
|
-
fromSlateValue(editor.children,
|
|
1001
|
+
fromSlateValue(editor.children, types$1.block.name, KEY_TO_VALUE_ELEMENT.get(editor)),
|
|
1002
1002
|
editor.selection,
|
|
1003
|
-
|
|
1003
|
+
types$1
|
|
1004
1004
|
)) == null ? void 0 : _a.focus.path) || [];
|
|
1005
1005
|
},
|
|
1006
1006
|
insertBlock: (type, value) => {
|
|
@@ -1019,13 +1019,13 @@ function createWithEditableAPI(portableTextEditor, types2, keyGenerator) {
|
|
|
1019
1019
|
)[0], [focusBlock] = Array.from(
|
|
1020
1020
|
slate.Editor.nodes(editor, {
|
|
1021
1021
|
at: editor.selection.focus.path.slice(0, 1),
|
|
1022
|
-
match: (n) => n._type ===
|
|
1022
|
+
match: (n) => n._type === types$1.block.name
|
|
1023
1023
|
})
|
|
1024
1024
|
)[0] || [void 0];
|
|
1025
|
-
return focusBlock && isEqualToEmptyEditor([focusBlock],
|
|
1026
|
-
fromSlateValue(editor.children,
|
|
1025
|
+
return focusBlock && isEqualToEmptyEditor([focusBlock], types$1) && slate.Transforms.removeNodes(editor, { at: editor.selection }), slate.Editor.insertNode(editor, block), editor.onChange(), ((_a = toPortableTextRange(
|
|
1026
|
+
fromSlateValue(editor.children, types$1.block.name, KEY_TO_VALUE_ELEMENT.get(editor)),
|
|
1027
1027
|
editor.selection,
|
|
1028
|
-
|
|
1028
|
+
types$1
|
|
1029
1029
|
)) == null ? void 0 : _a.focus.path) || [];
|
|
1030
1030
|
},
|
|
1031
1031
|
hasBlockStyle: (style) => {
|
|
@@ -1042,7 +1042,7 @@ function createWithEditableAPI(portableTextEditor, types2, keyGenerator) {
|
|
|
1042
1042
|
return !1;
|
|
1043
1043
|
}
|
|
1044
1044
|
},
|
|
1045
|
-
isVoid: (element) => ![
|
|
1045
|
+
isVoid: (element) => ![types$1.block.name, types$1.span.name].includes(element._type),
|
|
1046
1046
|
findByPath: (path) => {
|
|
1047
1047
|
const slatePath = toSlateRange(
|
|
1048
1048
|
{ focus: { path, offset: 0 }, anchor: { path, offset: 0 } },
|
|
@@ -1052,10 +1052,10 @@ function createWithEditableAPI(portableTextEditor, types2, keyGenerator) {
|
|
|
1052
1052
|
const [block, blockPath] = slate.Editor.node(editor, slatePath.focus.path.slice(0, 1));
|
|
1053
1053
|
if (block && blockPath && typeof block._key == "string") {
|
|
1054
1054
|
if (path.length === 1 && slatePath.focus.path.length === 1)
|
|
1055
|
-
return [fromSlateValue([block],
|
|
1055
|
+
return [fromSlateValue([block], types$1.block.name)[0], [{ _key: block._key }]];
|
|
1056
1056
|
const ptBlock = fromSlateValue(
|
|
1057
1057
|
[block],
|
|
1058
|
-
|
|
1058
|
+
types$1.block.name,
|
|
1059
1059
|
KEY_TO_VALUE_ELEMENT.get(editor)
|
|
1060
1060
|
)[0];
|
|
1061
1061
|
if (editor.isTextBlock(ptBlock)) {
|
|
@@ -1114,7 +1114,7 @@ function createWithEditableAPI(portableTextEditor, types2, keyGenerator) {
|
|
|
1114
1114
|
if (spans.some(
|
|
1115
1115
|
([span]) => {
|
|
1116
1116
|
var _a;
|
|
1117
|
-
return !types
|
|
1117
|
+
return !types.isPortableTextSpan(span) || !span.marks || ((_a = span.marks) == null ? void 0 : _a.length) === 0;
|
|
1118
1118
|
}
|
|
1119
1119
|
))
|
|
1120
1120
|
return !1;
|
|
@@ -1124,7 +1124,7 @@ function createWithEditableAPI(portableTextEditor, types2, keyGenerator) {
|
|
|
1124
1124
|
}, []);
|
|
1125
1125
|
return spans.every(([span]) => {
|
|
1126
1126
|
var _a;
|
|
1127
|
-
if (!types
|
|
1127
|
+
if (!types.isPortableTextSpan(span)) return !1;
|
|
1128
1128
|
const spanMarkDefs = (_a = span.marks) == null ? void 0 : _a.map(
|
|
1129
1129
|
(markKey) => {
|
|
1130
1130
|
var _a2;
|
|
@@ -1164,7 +1164,7 @@ function createWithEditableAPI(portableTextEditor, types2, keyGenerator) {
|
|
|
1164
1164
|
},
|
|
1165
1165
|
{
|
|
1166
1166
|
at: editor.selection,
|
|
1167
|
-
match: (n) => n._type ===
|
|
1167
|
+
match: (n) => n._type === types$1.span.name
|
|
1168
1168
|
}
|
|
1169
1169
|
), editor.onChange(), editor.selection && slate.Transforms.insertNodes(
|
|
1170
1170
|
editor,
|
|
@@ -1174,9 +1174,9 @@ function createWithEditableAPI(portableTextEditor, types2, keyGenerator) {
|
|
|
1174
1174
|
}
|
|
1175
1175
|
);
|
|
1176
1176
|
const newPortableTextEditorSelection = toPortableTextRange(
|
|
1177
|
-
fromSlateValue(editor.children,
|
|
1177
|
+
fromSlateValue(editor.children, types$1.block.name, KEY_TO_VALUE_ELEMENT.get(editor)),
|
|
1178
1178
|
editor.selection,
|
|
1179
|
-
|
|
1179
|
+
types$1
|
|
1180
1180
|
);
|
|
1181
1181
|
newPortableTextEditorSelection && (returnValue = {
|
|
1182
1182
|
spanPath: newPortableTextEditorSelection.focus.path,
|
|
@@ -1207,7 +1207,7 @@ function createWithEditableAPI(portableTextEditor, types2, keyGenerator) {
|
|
|
1207
1207
|
})), (options == null ? void 0 : options.mode) === "children" && (debug$i("Deleting children touched by selection"), slate.Transforms.removeNodes(editor, {
|
|
1208
1208
|
at: range,
|
|
1209
1209
|
voids: !0,
|
|
1210
|
-
match: (node) => node._type ===
|
|
1210
|
+
match: (node) => node._type === types$1.span.name || // Text children
|
|
1211
1211
|
!editor.isTextBlock(node) && slate.Element.isElement(node)
|
|
1212
1212
|
})), editor.children.length === 0 && (editor.children = [editor.pteCreateEmptyBlock()]), editor.onChange();
|
|
1213
1213
|
}
|
|
@@ -1245,20 +1245,20 @@ function createWithEditableAPI(portableTextEditor, types2, keyGenerator) {
|
|
|
1245
1245
|
if (existing)
|
|
1246
1246
|
return existing;
|
|
1247
1247
|
ptRange = toPortableTextRange(
|
|
1248
|
-
fromSlateValue(editor.children,
|
|
1248
|
+
fromSlateValue(editor.children, types$1.block.name, KEY_TO_VALUE_ELEMENT.get(editor)),
|
|
1249
1249
|
editor.selection,
|
|
1250
|
-
|
|
1250
|
+
types$1
|
|
1251
1251
|
), SLATE_TO_PORTABLE_TEXT_RANGE.set(editor.selection, ptRange);
|
|
1252
1252
|
}
|
|
1253
1253
|
return ptRange;
|
|
1254
1254
|
},
|
|
1255
|
-
getValue: () => fromSlateValue(editor.children,
|
|
1255
|
+
getValue: () => fromSlateValue(editor.children, types$1.block.name, KEY_TO_VALUE_ELEMENT.get(editor)),
|
|
1256
1256
|
isCollapsedSelection: () => !!editor.selection && slate.Range.isCollapsed(editor.selection),
|
|
1257
1257
|
isExpandedSelection: () => !!editor.selection && slate.Range.isExpanded(editor.selection),
|
|
1258
1258
|
insertBreak: () => {
|
|
1259
1259
|
editor.insertBreak(), editor.onChange();
|
|
1260
1260
|
},
|
|
1261
|
-
getFragment: () => fromSlateValue(editor.getFragment(),
|
|
1261
|
+
getFragment: () => fromSlateValue(editor.getFragment(), types$1.block.name),
|
|
1262
1262
|
isSelectionsOverlapping: (selectionA, selectionB) => {
|
|
1263
1263
|
const rangeA = toSlateRange(selectionA, editor), rangeB = toSlateRange(selectionB, editor);
|
|
1264
1264
|
return slate.Range.isRange(rangeA) && slate.Range.isRange(rangeB) && slate.Range.includes(rangeA, rangeB);
|
|
@@ -1839,7 +1839,7 @@ function countUtf8Bytes(str) {
|
|
|
1839
1839
|
}
|
|
1840
1840
|
return bytes;
|
|
1841
1841
|
}
|
|
1842
|
-
function adjustIndiciesToUcs2(
|
|
1842
|
+
function adjustIndiciesToUcs2(patches2, base) {
|
|
1843
1843
|
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, byteOffset = 0, idx = 0;
|
|
1844
1844
|
function advanceTo(target) {
|
|
1845
1845
|
for (; byteOffset < target; ) {
|
|
@@ -1853,7 +1853,7 @@ function adjustIndiciesToUcs2(patches, base) {
|
|
|
1853
1853
|
return idx;
|
|
1854
1854
|
}
|
|
1855
1855
|
const adjusted = [];
|
|
1856
|
-
for (const patch of
|
|
1856
|
+
for (const patch of patches2)
|
|
1857
1857
|
adjusted.push({
|
|
1858
1858
|
diffs: patch.diffs.map((diff2) => cloneDiff(diff2)),
|
|
1859
1859
|
start1: advanceTo(patch.start1),
|
|
@@ -1897,21 +1897,21 @@ function xIndex(diffs, loc) {
|
|
|
1897
1897
|
lastChars1 = chars1, lastChars2 = chars2;
|
|
1898
1898
|
return diffs.length !== x && diffs[x][0] === DIFF_DELETE ? lastChars2 : lastChars2 + (loc - lastChars1);
|
|
1899
1899
|
}
|
|
1900
|
-
function addPadding(
|
|
1900
|
+
function addPadding(patches2) {
|
|
1901
1901
|
const paddingLength = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : DEFAULT_MARGIN;
|
|
1902
1902
|
let nullPadding = "";
|
|
1903
1903
|
for (let x = 1; x <= paddingLength; x++)
|
|
1904
1904
|
nullPadding += String.fromCharCode(x);
|
|
1905
|
-
for (const p of
|
|
1905
|
+
for (const p of patches2)
|
|
1906
1906
|
p.start1 += paddingLength, p.start2 += paddingLength, p.utf8Start1 += paddingLength, p.utf8Start2 += paddingLength;
|
|
1907
|
-
let patch =
|
|
1907
|
+
let patch = patches2[0], diffs = patch.diffs;
|
|
1908
1908
|
if (diffs.length === 0 || diffs[0][0] !== DIFF_EQUAL)
|
|
1909
1909
|
diffs.unshift([DIFF_EQUAL, nullPadding]), patch.start1 -= paddingLength, patch.start2 -= paddingLength, patch.utf8Start1 -= paddingLength, patch.utf8Start2 -= paddingLength, patch.length1 += paddingLength, patch.length2 += paddingLength, patch.utf8Length1 += paddingLength, patch.utf8Length2 += paddingLength;
|
|
1910
1910
|
else if (paddingLength > diffs[0][1].length) {
|
|
1911
1911
|
const firstDiffLength = diffs[0][1].length, extraLength = paddingLength - firstDiffLength;
|
|
1912
1912
|
diffs[0][1] = nullPadding.substring(firstDiffLength) + diffs[0][1], patch.start1 -= extraLength, patch.start2 -= extraLength, patch.utf8Start1 -= extraLength, patch.utf8Start2 -= extraLength, patch.length1 += extraLength, patch.length2 += extraLength, patch.utf8Length1 += extraLength, patch.utf8Length2 += extraLength;
|
|
1913
1913
|
}
|
|
1914
|
-
if (patch =
|
|
1914
|
+
if (patch = patches2[patches2.length - 1], diffs = patch.diffs, diffs.length === 0 || diffs[diffs.length - 1][0] !== DIFF_EQUAL)
|
|
1915
1915
|
diffs.push([DIFF_EQUAL, nullPadding]), patch.length1 += paddingLength, patch.length2 += paddingLength, patch.utf8Length1 += paddingLength, patch.utf8Length2 += paddingLength;
|
|
1916
1916
|
else if (paddingLength > diffs[diffs.length - 1][1].length) {
|
|
1917
1917
|
const extraLength = paddingLength - diffs[diffs.length - 1][1].length;
|
|
@@ -1919,14 +1919,14 @@ function addPadding(patches) {
|
|
|
1919
1919
|
}
|
|
1920
1920
|
return nullPadding;
|
|
1921
1921
|
}
|
|
1922
|
-
function splitMax(
|
|
1922
|
+
function splitMax(patches2) {
|
|
1923
1923
|
let margin = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : DEFAULT_MARGIN;
|
|
1924
1924
|
const patchSize = MAX_BITS;
|
|
1925
|
-
for (let x = 0; x <
|
|
1926
|
-
if (
|
|
1925
|
+
for (let x = 0; x < patches2.length; x++) {
|
|
1926
|
+
if (patches2[x].length1 <= patchSize)
|
|
1927
1927
|
continue;
|
|
1928
|
-
const bigpatch =
|
|
1929
|
-
|
|
1928
|
+
const bigpatch = patches2[x];
|
|
1929
|
+
patches2.splice(x--, 1);
|
|
1930
1930
|
let start1 = bigpatch.start1, start2 = bigpatch.start2, preContext = "";
|
|
1931
1931
|
for (; bigpatch.diffs.length !== 0; ) {
|
|
1932
1932
|
const patch = createPatchObject(start1 - preContext.length, start2 - preContext.length);
|
|
@@ -1946,18 +1946,18 @@ function splitMax(patches) {
|
|
|
1946
1946
|
}
|
|
1947
1947
|
preContext = diffText2(patch.diffs), preContext = preContext.substring(preContext.length - margin);
|
|
1948
1948
|
const postContext = diffText1(bigpatch.diffs).substring(0, margin), postContextByteCount = countUtf8Bytes(postContext);
|
|
1949
|
-
postContext !== "" && (patch.length1 += postContext.length, patch.length2 += postContext.length, patch.utf8Length1 += postContextByteCount, patch.utf8Length2 += postContextByteCount, patch.diffs.length !== 0 && patch.diffs[patch.diffs.length - 1][0] === DIFF_EQUAL ? patch.diffs[patch.diffs.length - 1][1] += postContext : patch.diffs.push([DIFF_EQUAL, postContext])), empty ||
|
|
1949
|
+
postContext !== "" && (patch.length1 += postContext.length, patch.length2 += postContext.length, patch.utf8Length1 += postContextByteCount, patch.utf8Length2 += postContextByteCount, patch.diffs.length !== 0 && patch.diffs[patch.diffs.length - 1][0] === DIFF_EQUAL ? patch.diffs[patch.diffs.length - 1][1] += postContext : patch.diffs.push([DIFF_EQUAL, postContext])), empty || patches2.splice(++x, 0, patch);
|
|
1950
1950
|
}
|
|
1951
1951
|
}
|
|
1952
1952
|
}
|
|
1953
|
-
function apply(
|
|
1953
|
+
function apply(patches2, originalText) {
|
|
1954
1954
|
let opts = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1955
|
-
if (typeof
|
|
1955
|
+
if (typeof patches2 == "string")
|
|
1956
1956
|
throw new Error("Patches must be an array - pass the patch to `parsePatch()` first");
|
|
1957
1957
|
let text = originalText;
|
|
1958
|
-
if (
|
|
1958
|
+
if (patches2.length === 0)
|
|
1959
1959
|
return [text, []];
|
|
1960
|
-
const parsed = adjustIndiciesToUcs2(
|
|
1960
|
+
const parsed = adjustIndiciesToUcs2(patches2, text, {
|
|
1961
1961
|
allowExceedingIndices: opts.allowExceedingIndices
|
|
1962
1962
|
}), margin = opts.margin || DEFAULT_MARGIN, deleteThreshold = opts.deleteThreshold || 0.4, nullPadding = addPadding(parsed, margin);
|
|
1963
1963
|
text = nullPadding + text + nullPadding, splitMax(parsed, margin);
|
|
@@ -1996,7 +1996,7 @@ const patchHeader = /^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;
|
|
|
1996
1996
|
function parse(textline) {
|
|
1997
1997
|
if (!textline)
|
|
1998
1998
|
return [];
|
|
1999
|
-
const
|
|
1999
|
+
const patches2 = [], lines = textline.split(`
|
|
2000
2000
|
`);
|
|
2001
2001
|
let textPointer = 0;
|
|
2002
2002
|
for (; textPointer < lines.length; ) {
|
|
@@ -2004,7 +2004,7 @@ function parse(textline) {
|
|
|
2004
2004
|
if (!m)
|
|
2005
2005
|
throw new Error("Invalid patch string: ".concat(lines[textPointer]));
|
|
2006
2006
|
const patch = createPatchObject(toInt(m[1]), toInt(m[3]));
|
|
2007
|
-
for (
|
|
2007
|
+
for (patches2.push(patch), m[2] === "" ? (patch.start1--, patch.utf8Start1--, patch.length1 = 1, patch.utf8Length1 = 1) : m[2] === "0" ? (patch.length1 = 0, patch.utf8Length1 = 0) : (patch.start1--, patch.utf8Start1--, patch.utf8Length1 = toInt(m[2]), patch.length1 = patch.utf8Length1), m[4] === "" ? (patch.start2--, patch.utf8Start2--, patch.length2 = 1, patch.utf8Length2 = 1) : m[4] === "0" ? (patch.length2 = 0, patch.utf8Length2 = 0) : (patch.start2--, patch.utf8Start2--, patch.utf8Length2 = toInt(m[4]), patch.length2 = patch.utf8Length2), textPointer++; textPointer < lines.length; ) {
|
|
2008
2008
|
const currentLine = lines[textPointer], sign = currentLine.charAt(0);
|
|
2009
2009
|
if (sign === "@")
|
|
2010
2010
|
break;
|
|
@@ -2030,7 +2030,7 @@ function parse(textline) {
|
|
|
2030
2030
|
textPointer++;
|
|
2031
2031
|
}
|
|
2032
2032
|
}
|
|
2033
|
-
return
|
|
2033
|
+
return patches2;
|
|
2034
2034
|
}
|
|
2035
2035
|
function toInt(num) {
|
|
2036
2036
|
return parseInt(num, 10);
|
|
@@ -2074,7 +2074,7 @@ function diffMatchPatch(editor, patch) {
|
|
|
2074
2074
|
return debug$h("Child not found"), !1;
|
|
2075
2075
|
if (!(block && editor.isTextBlock(block) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !slate.Text.isText(child))
|
|
2076
2076
|
return !1;
|
|
2077
|
-
const
|
|
2077
|
+
const patches2 = parse(patch.value), [newValue] = apply(patches2, child.text, { allowExceedingIndices: !0 }), diff$1 = cleanupEfficiency(diff(child.text, newValue), 5);
|
|
2078
2078
|
debugState(editor, "before");
|
|
2079
2079
|
let offset = 0;
|
|
2080
2080
|
for (const [op, text] of diff$1)
|
|
@@ -2163,7 +2163,7 @@ function setPatch(editor, patch) {
|
|
|
2163
2163
|
});
|
|
2164
2164
|
});
|
|
2165
2165
|
} else if (block && "value" in block) {
|
|
2166
|
-
const newVal =
|
|
2166
|
+
const newVal = patches.applyAll([block.value], [patch])[0];
|
|
2167
2167
|
return slate.Transforms.setNodes(editor, { ...block, value: newVal }, { at: blockPath }), !0;
|
|
2168
2168
|
}
|
|
2169
2169
|
return debugState(editor, "after"), !0;
|
|
@@ -2245,9 +2245,9 @@ function createWithUndoRedo(options) {
|
|
|
2245
2245
|
const remotePatches = getRemotePatches(editor);
|
|
2246
2246
|
patches$ && editor.subscriptions.push(() => {
|
|
2247
2247
|
debug$g("Subscribing to patches");
|
|
2248
|
-
const sub = patches$.subscribe(({ patches, snapshot }) => {
|
|
2248
|
+
const sub = patches$.subscribe(({ patches: patches2, snapshot }) => {
|
|
2249
2249
|
let reset = !1;
|
|
2250
|
-
|
|
2250
|
+
patches2.forEach((patch) => {
|
|
2251
2251
|
if (!reset && patch.origin !== "local" && remotePatches) {
|
|
2252
2252
|
if (patch.type === "unset" && patch.path.length === 0) {
|
|
2253
2253
|
debug$g("Someone else cleared the content, resetting undo/redo history"), editor.history = { undos: [], redos: [] }, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
|
|
@@ -2453,7 +2453,7 @@ function createWithPatches({
|
|
|
2453
2453
|
const handleBufferedRemotePatches = () => {
|
|
2454
2454
|
if (bufferedPatches.length === 0)
|
|
2455
2455
|
return;
|
|
2456
|
-
const
|
|
2456
|
+
const patches2 = bufferedPatches;
|
|
2457
2457
|
bufferedPatches = [];
|
|
2458
2458
|
let changed = !1;
|
|
2459
2459
|
withRemoteChanges(editor, () => {
|
|
@@ -2461,7 +2461,7 @@ function createWithPatches({
|
|
|
2461
2461
|
withoutPatching(editor, () => {
|
|
2462
2462
|
withoutSaving(editor, () => {
|
|
2463
2463
|
withPreserveKeys(editor, () => {
|
|
2464
|
-
|
|
2464
|
+
patches2.forEach((patch) => {
|
|
2465
2465
|
debug$f.enabled && debug$f(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
|
|
2466
2466
|
});
|
|
2467
2467
|
});
|
|
@@ -2469,8 +2469,8 @@ function createWithPatches({
|
|
|
2469
2469
|
});
|
|
2470
2470
|
}), changed && (editor.normalize(), editor.onChange());
|
|
2471
2471
|
});
|
|
2472
|
-
}, handlePatches = ({ patches }) => {
|
|
2473
|
-
const remotePatches =
|
|
2472
|
+
}, handlePatches = ({ patches: patches2 }) => {
|
|
2473
|
+
const remotePatches = patches2.filter((p) => p.origin !== "local");
|
|
2474
2474
|
remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
|
|
2475
2475
|
};
|
|
2476
2476
|
return patches$ && editor.subscriptions.push(() => {
|
|
@@ -2482,71 +2482,71 @@ function createWithPatches({
|
|
|
2482
2482
|
}), editor.apply = (operation) => {
|
|
2483
2483
|
if (readOnly)
|
|
2484
2484
|
return apply2(operation), editor;
|
|
2485
|
-
let patches = [];
|
|
2485
|
+
let patches$1 = [];
|
|
2486
2486
|
previousChildren = editor.children;
|
|
2487
2487
|
const editorWasEmpty = isEqualToEmptyEditor(previousChildren, schemaTypes);
|
|
2488
2488
|
apply2(operation);
|
|
2489
2489
|
const editorIsEmpty = isEqualToEmptyEditor(editor.children, schemaTypes);
|
|
2490
2490
|
if (!isPatching(editor))
|
|
2491
2491
|
return editor;
|
|
2492
|
-
switch (editorWasEmpty && !editorIsEmpty && operation.type !== "set_selection" && patches.push(
|
|
2492
|
+
switch (editorWasEmpty && !editorIsEmpty && operation.type !== "set_selection" && patches$1.push(patches.insert(previousChildren, "before", [0])), operation.type) {
|
|
2493
2493
|
case "insert_text":
|
|
2494
|
-
patches = [
|
|
2495
|
-
...patches,
|
|
2494
|
+
patches$1 = [
|
|
2495
|
+
...patches$1,
|
|
2496
2496
|
...patchFunctions.insertTextPatch(editor, operation, previousChildren)
|
|
2497
2497
|
];
|
|
2498
2498
|
break;
|
|
2499
2499
|
case "remove_text":
|
|
2500
|
-
patches = [
|
|
2501
|
-
...patches,
|
|
2500
|
+
patches$1 = [
|
|
2501
|
+
...patches$1,
|
|
2502
2502
|
...patchFunctions.removeTextPatch(editor, operation, previousChildren)
|
|
2503
2503
|
];
|
|
2504
2504
|
break;
|
|
2505
2505
|
case "remove_node":
|
|
2506
|
-
patches = [
|
|
2507
|
-
...patches,
|
|
2506
|
+
patches$1 = [
|
|
2507
|
+
...patches$1,
|
|
2508
2508
|
...patchFunctions.removeNodePatch(editor, operation, previousChildren)
|
|
2509
2509
|
];
|
|
2510
2510
|
break;
|
|
2511
2511
|
case "split_node":
|
|
2512
|
-
patches = [
|
|
2513
|
-
...patches,
|
|
2512
|
+
patches$1 = [
|
|
2513
|
+
...patches$1,
|
|
2514
2514
|
...patchFunctions.splitNodePatch(editor, operation, previousChildren)
|
|
2515
2515
|
];
|
|
2516
2516
|
break;
|
|
2517
2517
|
case "insert_node":
|
|
2518
|
-
patches = [
|
|
2519
|
-
...patches,
|
|
2518
|
+
patches$1 = [
|
|
2519
|
+
...patches$1,
|
|
2520
2520
|
...patchFunctions.insertNodePatch(editor, operation, previousChildren)
|
|
2521
2521
|
];
|
|
2522
2522
|
break;
|
|
2523
2523
|
case "set_node":
|
|
2524
|
-
patches = [
|
|
2525
|
-
...patches,
|
|
2524
|
+
patches$1 = [
|
|
2525
|
+
...patches$1,
|
|
2526
2526
|
...patchFunctions.setNodePatch(editor, operation, previousChildren)
|
|
2527
2527
|
];
|
|
2528
2528
|
break;
|
|
2529
2529
|
case "merge_node":
|
|
2530
|
-
patches = [
|
|
2531
|
-
...patches,
|
|
2530
|
+
patches$1 = [
|
|
2531
|
+
...patches$1,
|
|
2532
2532
|
...patchFunctions.mergeNodePatch(editor, operation, previousChildren)
|
|
2533
2533
|
];
|
|
2534
2534
|
break;
|
|
2535
2535
|
case "move_node":
|
|
2536
|
-
patches = [
|
|
2537
|
-
...patches,
|
|
2536
|
+
patches$1 = [
|
|
2537
|
+
...patches$1,
|
|
2538
2538
|
...patchFunctions.moveNodePatch(editor, operation, previousChildren)
|
|
2539
2539
|
];
|
|
2540
2540
|
break;
|
|
2541
2541
|
}
|
|
2542
|
-
return !editorWasEmpty && editorIsEmpty && ["merge_node", "set_node", "remove_text", "remove_node"].includes(operation.type) && (patches = [...patches,
|
|
2542
|
+
return !editorWasEmpty && editorIsEmpty && ["merge_node", "set_node", "remove_text", "remove_node"].includes(operation.type) && (patches$1 = [...patches$1, patches.unset([])], change$.next({
|
|
2543
2543
|
type: "unset",
|
|
2544
2544
|
previousValue: fromSlateValue(
|
|
2545
2545
|
previousChildren,
|
|
2546
2546
|
schemaTypes.block.name,
|
|
2547
2547
|
KEY_TO_VALUE_ELEMENT.get(editor)
|
|
2548
2548
|
)
|
|
2549
|
-
})), editorWasEmpty && patches.length > 0 && (patches = [
|
|
2549
|
+
})), editorWasEmpty && patches$1.length > 0 && (patches$1 = [patches.setIfMissing([], []), ...patches$1]), patches$1.length > 0 && patches$1.forEach((patch) => {
|
|
2550
2550
|
change$.next({
|
|
2551
2551
|
type: "patch",
|
|
2552
2552
|
patch: { ...patch, origin: "local" }
|
|
@@ -2958,7 +2958,7 @@ function createWithSchemaTypes({
|
|
|
2958
2958
|
keyGenerator
|
|
2959
2959
|
}) {
|
|
2960
2960
|
return function(editor) {
|
|
2961
|
-
editor.isTextBlock = (value) => types
|
|
2961
|
+
editor.isTextBlock = (value) => types.isPortableTextTextBlock(value) && value._type === schemaTypes.block.name, editor.isTextSpan = (value) => types.isPortableTextSpan(value) && value._type == schemaTypes.span.name, editor.isListBlock = (value) => types.isPortableTextListBlock(value) && value._type === schemaTypes.block.name, editor.isVoid = (element) => schemaTypes.block.name !== element._type && (schemaTypes.blockObjects.map((obj) => obj.name).includes(element._type) || schemaTypes.inlineObjects.map((obj) => obj.name).includes(element._type)), editor.isInline = (element) => schemaTypes.inlineObjects.map((obj) => obj.name).includes(element._type) && "__inline" in element && element.__inline === !0;
|
|
2962
2962
|
const { normalizeNode } = editor;
|
|
2963
2963
|
return editor.normalizeNode = (entry) => {
|
|
2964
2964
|
const [node, path] = entry;
|
|
@@ -3027,7 +3027,7 @@ const debug$7 = debugWithName("plugin:withHotKeys"), DEFAULT_HOTKEYS = {
|
|
|
3027
3027
|
},
|
|
3028
3028
|
custom: {}
|
|
3029
3029
|
};
|
|
3030
|
-
function createWithHotkeys(
|
|
3030
|
+
function createWithHotkeys(types$1, portableTextEditor, hotkeysFromOptions) {
|
|
3031
3031
|
const reservedHotkeys = ["enter", "tab", "shift", "delete", "end"], activeHotkeys = hotkeysFromOptions || DEFAULT_HOTKEYS;
|
|
3032
3032
|
return function(editor) {
|
|
3033
3033
|
return editor.pteWithHotKeys = (event) => {
|
|
@@ -3078,7 +3078,7 @@ function createWithHotkeys(types2, portableTextEditor, hotkeysFromOptions) {
|
|
|
3078
3078
|
}
|
|
3079
3079
|
}
|
|
3080
3080
|
if (isBackspace && editor.selection && editor.selection.focus.path[0] === 0 && slate.Range.isCollapsed(editor.selection)) {
|
|
3081
|
-
const focusBlock = slate.Node.descendant(editor, editor.selection.focus.path.slice(0, 1)), nextPath = slate.Path.next(editor.selection.focus.path.slice(0, 1)), nextBlock = slate.Node.has(editor, nextPath), isTextBlock = types
|
|
3081
|
+
const focusBlock = slate.Node.descendant(editor, editor.selection.focus.path.slice(0, 1)), nextPath = slate.Path.next(editor.selection.focus.path.slice(0, 1)), nextBlock = slate.Node.has(editor, nextPath), isTextBlock = types.isPortableTextTextBlock(focusBlock), isEmptyFocusBlock = isTextBlock && focusBlock.children.length === 1 && ((_b = (_a = focusBlock.children) == null ? void 0 : _a[0]) == null ? void 0 : _b.text) === "";
|
|
3082
3082
|
if (nextBlock && isTextBlock && isEmptyFocusBlock) {
|
|
3083
3083
|
event.preventDefault(), event.stopPropagation(), slate.Transforms.removeNodes(editor, { match: (n) => n === focusBlock }), editor.onChange();
|
|
3084
3084
|
return;
|
|
@@ -3088,7 +3088,7 @@ function createWithHotkeys(types2, portableTextEditor, hotkeysFromOptions) {
|
|
|
3088
3088
|
const prevPath = slate.Path.previous(editor.selection.focus.path.slice(0, 1)), prevBlock = slate.Node.descendant(editor, prevPath), focusBlock = slate.Node.descendant(editor, editor.selection.focus.path.slice(0, 1));
|
|
3089
3089
|
if (prevBlock && focusBlock && slate.Editor.isVoid(editor, prevBlock) && editor.selection.focus.offset === 0) {
|
|
3090
3090
|
debug$7("Preventing deleting void block above"), event.preventDefault(), event.stopPropagation();
|
|
3091
|
-
const isTextBlock = types
|
|
3091
|
+
const isTextBlock = types.isPortableTextTextBlock(focusBlock), isEmptyFocusBlock = isTextBlock && focusBlock.children.length === 1 && ((_d = (_c = focusBlock.children) == null ? void 0 : _c[0]) == null ? void 0 : _d.text) === "";
|
|
3092
3092
|
if (!isTextBlock || isEmptyFocusBlock) {
|
|
3093
3093
|
slate.Transforms.removeNodes(editor, { match: (n) => n === focusBlock }), slate.Transforms.select(editor, prevPath), editor.onChange();
|
|
3094
3094
|
return;
|
|
@@ -3111,10 +3111,10 @@ function createWithHotkeys(types2, portableTextEditor, hotkeysFromOptions) {
|
|
|
3111
3111
|
}
|
|
3112
3112
|
}
|
|
3113
3113
|
if ((isTab || isShiftTab) && editor.selection) {
|
|
3114
|
-
const [focusChild] = slate.Editor.node(editor, editor.selection.focus, { depth: 2 }), [focusBlock] = types
|
|
3114
|
+
const [focusChild] = slate.Editor.node(editor, editor.selection.focus, { depth: 2 }), [focusBlock] = types.isPortableTextSpan(focusChild) ? slate.Editor.node(editor, editor.selection.focus, { depth: 1 }) : [], hasAnnotationFocus = focusChild && types.isPortableTextTextBlock(focusBlock) && types.isPortableTextSpan(focusChild) && (focusChild.marks || []).filter(
|
|
3115
3115
|
(m) => (focusBlock.markDefs || []).map((def) => def._key).includes(m)
|
|
3116
3116
|
).length > 0, [start] = slate.Range.edges(editor.selection), atStartOfNode = slate.Editor.isStart(editor, start, start.path);
|
|
3117
|
-
focusChild && types
|
|
3117
|
+
focusChild && types.isPortableTextSpan(focusChild) && (!hasAnnotationFocus || atStartOfNode) && editor.pteIncrementBlockLevels(isShiftTab) && event.preventDefault();
|
|
3118
3118
|
}
|
|
3119
3119
|
if (isEnter && !isShiftEnter && editor.selection) {
|
|
3120
3120
|
const focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = slate.Node.descendant(editor, focusBlockPath);
|
|
@@ -3122,7 +3122,7 @@ function createWithHotkeys(types2, portableTextEditor, hotkeysFromOptions) {
|
|
|
3122
3122
|
editor.pteEndList() && event.preventDefault();
|
|
3123
3123
|
return;
|
|
3124
3124
|
}
|
|
3125
|
-
if (editor.isTextBlock(focusBlock) && focusBlock.style && focusBlock.style !==
|
|
3125
|
+
if (editor.isTextBlock(focusBlock) && focusBlock.style && focusBlock.style !== types$1.styles[0].value) {
|
|
3126
3126
|
const [, end] = slate.Range.edges(editor.selection);
|
|
3127
3127
|
if (slate.Editor.isEnd(editor, end, end.path)) {
|
|
3128
3128
|
slate.Editor.insertNode(editor, editor.pteCreateEmptyBlock()), event.preventDefault(), editor.onChange();
|
|
@@ -3148,13 +3148,13 @@ function createWithHotkeys(types2, portableTextEditor, hotkeysFromOptions) {
|
|
|
3148
3148
|
}, editor;
|
|
3149
3149
|
};
|
|
3150
3150
|
}
|
|
3151
|
-
function validateValue(value,
|
|
3151
|
+
function validateValue(value, types$1, keyGenerator) {
|
|
3152
3152
|
let resolution = null, valid = !0;
|
|
3153
|
-
const validChildTypes = [
|
|
3153
|
+
const validChildTypes = [types$1.span.name, ...types$1.inlineObjects.map((t) => t.name)], validBlockTypes = [types$1.block.name, ...types$1.blockObjects.map((t) => t.name)];
|
|
3154
3154
|
return value === void 0 ? { valid: !0, resolution: null, value } : !Array.isArray(value) || value.length === 0 ? {
|
|
3155
3155
|
valid: !1,
|
|
3156
3156
|
resolution: {
|
|
3157
|
-
patches: [
|
|
3157
|
+
patches: [patches.unset([])],
|
|
3158
3158
|
description: "Editor value must be an array of Portable Text blocks, or undefined.",
|
|
3159
3159
|
action: "Unset the value",
|
|
3160
3160
|
item: value,
|
|
@@ -3167,7 +3167,7 @@ function validateValue(value, types2, keyGenerator) {
|
|
|
3167
3167
|
} : (value.some((blk, index) => {
|
|
3168
3168
|
if (!isPlainObject__default.default(blk))
|
|
3169
3169
|
return resolution = {
|
|
3170
|
-
patches: [
|
|
3170
|
+
patches: [patches.unset([index])],
|
|
3171
3171
|
description: `Block must be an object, got ${String(blk)}`,
|
|
3172
3172
|
action: "Unset invalid item",
|
|
3173
3173
|
item: blk,
|
|
@@ -3179,7 +3179,7 @@ function validateValue(value, types2, keyGenerator) {
|
|
|
3179
3179
|
}, !0;
|
|
3180
3180
|
if (!blk._key || typeof blk._key != "string")
|
|
3181
3181
|
return resolution = {
|
|
3182
|
-
patches: [
|
|
3182
|
+
patches: [patches.set({ ...blk, _key: keyGenerator() }, [index])],
|
|
3183
3183
|
description: `Block at index ${index} is missing required _key.`,
|
|
3184
3184
|
action: "Set the block with a random _key value",
|
|
3185
3185
|
item: blk,
|
|
@@ -3191,9 +3191,9 @@ function validateValue(value, types2, keyGenerator) {
|
|
|
3191
3191
|
}, !0;
|
|
3192
3192
|
if (!blk._type || !validBlockTypes.includes(blk._type)) {
|
|
3193
3193
|
if (blk._type === "block") {
|
|
3194
|
-
const currentBlockTypeName =
|
|
3194
|
+
const currentBlockTypeName = types$1.block.name;
|
|
3195
3195
|
return resolution = {
|
|
3196
|
-
patches: [
|
|
3196
|
+
patches: [patches.set({ ...blk, _type: currentBlockTypeName }, [{ _key: blk._key }])],
|
|
3197
3197
|
description: `Block with _key '${blk._key}' has invalid type name '${blk._type}'. According to the schema, the block type name is '${currentBlockTypeName}'`,
|
|
3198
3198
|
action: `Use type '${currentBlockTypeName}'`,
|
|
3199
3199
|
item: blk,
|
|
@@ -3204,18 +3204,18 @@ function validateValue(value, types2, keyGenerator) {
|
|
|
3204
3204
|
}
|
|
3205
3205
|
}, !0;
|
|
3206
3206
|
}
|
|
3207
|
-
return !blk._type && types
|
|
3208
|
-
patches: [
|
|
3209
|
-
description: `Block with _key '${blk._key}' is missing a type name. According to the schema, the block type name is '${
|
|
3210
|
-
action: `Use type '${
|
|
3207
|
+
return !blk._type && types.isPortableTextTextBlock({ ...blk, _type: types$1.block.name }) ? (resolution = {
|
|
3208
|
+
patches: [patches.set({ ...blk, _type: types$1.block.name }, [{ _key: blk._key }])],
|
|
3209
|
+
description: `Block with _key '${blk._key}' is missing a type name. According to the schema, the block type name is '${types$1.block.name}'`,
|
|
3210
|
+
action: `Use type '${types$1.block.name}'`,
|
|
3211
3211
|
item: blk,
|
|
3212
3212
|
i18n: {
|
|
3213
3213
|
description: "inputs.portable-text.invalid-value.missing-block-type.description",
|
|
3214
3214
|
action: "inputs.portable-text.invalid-value.missing-block-type.action",
|
|
3215
|
-
values: { key: blk._key, expectedTypeName:
|
|
3215
|
+
values: { key: blk._key, expectedTypeName: types$1.block.name }
|
|
3216
3216
|
}
|
|
3217
3217
|
}, !0) : blk._type ? (resolution = {
|
|
3218
|
-
patches: [
|
|
3218
|
+
patches: [patches.unset([{ _key: blk._key }])],
|
|
3219
3219
|
description: `Block with _key '${blk._key}' has invalid _type '${blk._type}'`,
|
|
3220
3220
|
action: "Remove the block",
|
|
3221
3221
|
item: blk,
|
|
@@ -3225,7 +3225,7 @@ function validateValue(value, types2, keyGenerator) {
|
|
|
3225
3225
|
values: { key: blk._key, typeName: blk._type }
|
|
3226
3226
|
}
|
|
3227
3227
|
}, !0) : (resolution = {
|
|
3228
|
-
patches: [
|
|
3228
|
+
patches: [patches.unset([{ _key: blk._key }])],
|
|
3229
3229
|
description: `Block with _key '${blk._key}' is missing an _type property`,
|
|
3230
3230
|
action: "Remove the block",
|
|
3231
3231
|
item: blk,
|
|
@@ -3236,11 +3236,11 @@ function validateValue(value, types2, keyGenerator) {
|
|
|
3236
3236
|
}
|
|
3237
3237
|
}, !0);
|
|
3238
3238
|
}
|
|
3239
|
-
if (blk._type ===
|
|
3239
|
+
if (blk._type === types$1.block.name) {
|
|
3240
3240
|
const textBlock = blk;
|
|
3241
3241
|
if (textBlock.children && !Array.isArray(textBlock.children))
|
|
3242
3242
|
return resolution = {
|
|
3243
|
-
patches: [
|
|
3243
|
+
patches: [patches.set({ children: [] }, [{ _key: textBlock._key }])],
|
|
3244
3244
|
description: `Text block with _key '${textBlock._key}' has a invalid required property 'children'.`,
|
|
3245
3245
|
action: "Reset the children property",
|
|
3246
3246
|
item: textBlock,
|
|
@@ -3252,7 +3252,7 @@ function validateValue(value, types2, keyGenerator) {
|
|
|
3252
3252
|
}, !0;
|
|
3253
3253
|
if (textBlock.children === void 0 || Array.isArray(textBlock.children) && textBlock.children.length === 0) {
|
|
3254
3254
|
const newSpan = {
|
|
3255
|
-
_type:
|
|
3255
|
+
_type: types$1.span.name,
|
|
3256
3256
|
_key: keyGenerator(),
|
|
3257
3257
|
text: "",
|
|
3258
3258
|
marks: []
|
|
@@ -3260,8 +3260,8 @@ function validateValue(value, types2, keyGenerator) {
|
|
|
3260
3260
|
return resolution = {
|
|
3261
3261
|
autoResolve: !0,
|
|
3262
3262
|
patches: [
|
|
3263
|
-
|
|
3264
|
-
|
|
3263
|
+
patches.setIfMissing([], [{ _key: blk._key }, "children"]),
|
|
3264
|
+
patches.insert([newSpan], "after", [{ _key: blk._key }, "children", 0])
|
|
3265
3265
|
],
|
|
3266
3266
|
description: `Children for text block with _key '${blk._key}' is empty.`,
|
|
3267
3267
|
action: "Insert an empty text",
|
|
@@ -3275,7 +3275,7 @@ function validateValue(value, types2, keyGenerator) {
|
|
|
3275
3275
|
}
|
|
3276
3276
|
if (blk.markDefs && !Array.isArray(blk.markDefs))
|
|
3277
3277
|
return resolution = {
|
|
3278
|
-
patches: [
|
|
3278
|
+
patches: [patches.set({ ...textBlock, markDefs: EMPTY_MARKDEFS }, [{ _key: textBlock._key }])],
|
|
3279
3279
|
description: "Block has invalid required property 'markDefs'.",
|
|
3280
3280
|
action: "Add empty markDefs array",
|
|
3281
3281
|
item: textBlock,
|
|
@@ -3287,7 +3287,7 @@ function validateValue(value, types2, keyGenerator) {
|
|
|
3287
3287
|
}, !0;
|
|
3288
3288
|
const allUsedMarks = uniq__default.default(
|
|
3289
3289
|
flatten__default.default(
|
|
3290
|
-
textBlock.children.filter((cld) => cld._type ===
|
|
3290
|
+
textBlock.children.filter((cld) => cld._type === types$1.span.name).map((cld) => cld.marks || [])
|
|
3291
3291
|
)
|
|
3292
3292
|
);
|
|
3293
3293
|
if (Array.isArray(blk.markDefs) && blk.markDefs.length > 0) {
|
|
@@ -3298,7 +3298,7 @@ function validateValue(value, types2, keyGenerator) {
|
|
|
3298
3298
|
return resolution = {
|
|
3299
3299
|
autoResolve: !0,
|
|
3300
3300
|
patches: unusedMarkDefs.map(
|
|
3301
|
-
(markDefKey) =>
|
|
3301
|
+
(markDefKey) => patches.unset([{ _key: blk._key }, "markDefs", { _key: markDefKey }])
|
|
3302
3302
|
),
|
|
3303
3303
|
description: `Block contains orphaned data (unused mark definitions): ${unusedMarkDefs.join(
|
|
3304
3304
|
", "
|
|
@@ -3313,19 +3313,19 @@ function validateValue(value, types2, keyGenerator) {
|
|
|
3313
3313
|
}, !0;
|
|
3314
3314
|
}
|
|
3315
3315
|
const orphanedMarks = allUsedMarks.filter(
|
|
3316
|
-
(mark) => !
|
|
3316
|
+
(mark) => !types$1.decorators.map((dec) => dec.value).includes(mark)
|
|
3317
3317
|
).filter(
|
|
3318
3318
|
(mark) => textBlock.markDefs === void 0 || !textBlock.markDefs.find((def) => def._key === mark)
|
|
3319
3319
|
);
|
|
3320
3320
|
if (orphanedMarks.length > 0) {
|
|
3321
3321
|
const spanChildren = textBlock.children.filter(
|
|
3322
|
-
(cld) => cld._type ===
|
|
3322
|
+
(cld) => cld._type === types$1.span.name && Array.isArray(cld.marks) && cld.marks.some((mark) => orphanedMarks.includes(mark))
|
|
3323
3323
|
);
|
|
3324
3324
|
if (spanChildren) {
|
|
3325
3325
|
const orphaned = orphanedMarks.join(", ");
|
|
3326
3326
|
return resolution = {
|
|
3327
3327
|
autoResolve: !0,
|
|
3328
|
-
patches: spanChildren.map((child) =>
|
|
3328
|
+
patches: spanChildren.map((child) => patches.set(
|
|
3329
3329
|
(child.marks || []).filter((cMrk) => !orphanedMarks.includes(cMrk)),
|
|
3330
3330
|
[{ _key: blk._key }, "children", { _key: child._key }, "marks"]
|
|
3331
3331
|
)),
|
|
@@ -3343,7 +3343,7 @@ function validateValue(value, types2, keyGenerator) {
|
|
|
3343
3343
|
textBlock.children.some((child, cIndex) => {
|
|
3344
3344
|
if (!isPlainObject__default.default(child))
|
|
3345
3345
|
return resolution = {
|
|
3346
|
-
patches: [
|
|
3346
|
+
patches: [patches.unset([{ _key: blk._key }, "children", cIndex])],
|
|
3347
3347
|
description: `Child at index '${cIndex}' in block with key '${blk._key}' is not an object.`,
|
|
3348
3348
|
action: "Remove the item",
|
|
3349
3349
|
item: blk,
|
|
@@ -3357,7 +3357,7 @@ function validateValue(value, types2, keyGenerator) {
|
|
|
3357
3357
|
const newChild = { ...child, _key: keyGenerator() };
|
|
3358
3358
|
return resolution = {
|
|
3359
3359
|
autoResolve: !0,
|
|
3360
|
-
patches: [
|
|
3360
|
+
patches: [patches.set(newChild, [{ _key: blk._key }, "children", cIndex])],
|
|
3361
3361
|
description: `Child at index ${cIndex} is missing required _key in block with _key ${blk._key}.`,
|
|
3362
3362
|
action: "Set a new random _key on the object",
|
|
3363
3363
|
item: blk,
|
|
@@ -3368,9 +3368,9 @@ function validateValue(value, types2, keyGenerator) {
|
|
|
3368
3368
|
}
|
|
3369
3369
|
}, !0;
|
|
3370
3370
|
}
|
|
3371
|
-
return child._type ? validChildTypes.includes(child._type) ? child._type ===
|
|
3371
|
+
return child._type ? validChildTypes.includes(child._type) ? child._type === types$1.span.name && typeof child.text != "string" ? (resolution = {
|
|
3372
3372
|
patches: [
|
|
3373
|
-
|
|
3373
|
+
patches.set({ ...child, text: "" }, [{ _key: blk._key }, "children", { _key: child._key }])
|
|
3374
3374
|
],
|
|
3375
3375
|
description: `Child with _key '${child._key}' in block with key '${blk._key}' has missing or invalid text property!`,
|
|
3376
3376
|
action: "Write an empty text property to the object",
|
|
@@ -3381,7 +3381,7 @@ function validateValue(value, types2, keyGenerator) {
|
|
|
3381
3381
|
values: { key: blk._key, childKey: child._key }
|
|
3382
3382
|
}
|
|
3383
3383
|
}, !0) : !1 : (resolution = {
|
|
3384
|
-
patches: [
|
|
3384
|
+
patches: [patches.unset([{ _key: blk._key }, "children", { _key: child._key }])],
|
|
3385
3385
|
description: `Child with _key '${child._key}' in block with key '${blk._key}' has invalid '_type' property (${child._type}).`,
|
|
3386
3386
|
action: "Remove the object",
|
|
3387
3387
|
item: blk,
|
|
@@ -3391,7 +3391,7 @@ function validateValue(value, types2, keyGenerator) {
|
|
|
3391
3391
|
values: { key: blk._key, childKey: child._key, childType: child._type }
|
|
3392
3392
|
}
|
|
3393
3393
|
}, !0) : (resolution = {
|
|
3394
|
-
patches: [
|
|
3394
|
+
patches: [patches.unset([{ _key: blk._key }, "children", { _key: child._key }])],
|
|
3395
3395
|
description: `Child with _key '${child._key}' in block with key '${blk._key}' is missing '_type' property.`,
|
|
3396
3396
|
action: "Remove the object",
|
|
3397
3397
|
item: blk,
|
|
@@ -4561,12 +4561,4 @@ exports.PortableTextEditor = PortableTextEditor;
|
|
|
4561
4561
|
exports.keyGenerator = defaultKeyGenerator;
|
|
4562
4562
|
exports.usePortableTextEditor = usePortableTextEditor;
|
|
4563
4563
|
exports.usePortableTextEditorSelection = usePortableTextEditorSelection;
|
|
4564
|
-
Object.keys(types).forEach(function(k) {
|
|
4565
|
-
k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k) && Object.defineProperty(exports, k, {
|
|
4566
|
-
enumerable: !0,
|
|
4567
|
-
get: function() {
|
|
4568
|
-
return types[k];
|
|
4569
|
-
}
|
|
4570
|
-
});
|
|
4571
|
-
});
|
|
4572
4564
|
//# sourceMappingURL=index.js.map
|