@portabletext/editor 1.0.18 → 1.0.19
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 +47 -56
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +47 -56
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +47 -56
- package/lib/index.mjs.map +1 -1
- package/package.json +7 -3
- package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +0 -533
- package/src/editor/plugins/createWithEditableAPI.ts +10 -1
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +97 -118
- package/src/utils/values.ts +0 -1
- package/src/editor/plugins/__tests__/withHotkeys.test.tsx +0 -212
- package/src/editor/plugins/__tests__/withInsertBreak.test.tsx +0 -220
- package/src/editor/plugins/__tests__/withPlaceholderBlock.test.tsx +0 -133
package/lib/index.js
CHANGED
|
@@ -106,7 +106,7 @@ function normalizeSelection(selection, value) {
|
|
|
106
106
|
const { anchor, focus } = selection;
|
|
107
107
|
return anchor && value.find((blk) => isEqual__default.default({ _key: blk._key }, anchor.path[0])) && (newAnchor = normalizePoint(anchor, value)), focus && value.find((blk) => isEqual__default.default({ _key: blk._key }, focus.path[0])) && (newFocus = normalizePoint(focus, value)), newAnchor && newFocus ? { anchor: newAnchor, focus: newFocus, backward: selection.backward } : null;
|
|
108
108
|
}
|
|
109
|
-
const EMPTY_MARKDEFS = [],
|
|
109
|
+
const EMPTY_MARKDEFS = [], VOID_CHILD_KEY = "void-child";
|
|
110
110
|
function keepObjectEquality(object, keyMap) {
|
|
111
111
|
const value = keyMap[object._key];
|
|
112
112
|
return value && isEqual__default.default(object, value) ? value : (keyMap[object._key] = object, object);
|
|
@@ -1152,9 +1152,10 @@ function createWithEditableAPI(portableTextEditor, types$1, keyGenerator) {
|
|
|
1152
1152
|
const [block] = slate.Editor.node(editor, originalSelection.focus, { depth: 1 });
|
|
1153
1153
|
if (!editor.isTextBlock(block))
|
|
1154
1154
|
return;
|
|
1155
|
-
slate.Range.isCollapsed(originalSelection) && (editor.pteExpandToWord(), editor.onChange());
|
|
1156
1155
|
const [textNode] = slate.Editor.node(editor, originalSelection.focus, { depth: 2 });
|
|
1157
|
-
|
|
1156
|
+
if (!types.isPortableTextSpan(textNode) || textNode.text === "")
|
|
1157
|
+
return;
|
|
1158
|
+
slate.Range.isCollapsed(originalSelection) && (editor.pteExpandToWord(), editor.onChange()), editor.selection && (slate.Editor.withoutNormalizing(editor, () => {
|
|
1158
1159
|
const annotationKey = keyGenerator();
|
|
1159
1160
|
slate.Transforms.setNodes(
|
|
1160
1161
|
editor,
|
|
@@ -2770,7 +2771,7 @@ function createWithPortableTextMarkModel(types2, change$, keyGenerator) {
|
|
|
2770
2771
|
change$.next({ type: "selection", selection: ptRange });
|
|
2771
2772
|
};
|
|
2772
2773
|
return editor.normalizeNode = (nodeEntry) => {
|
|
2773
|
-
const [node, path] = nodeEntry
|
|
2774
|
+
const [node, path] = nodeEntry;
|
|
2774
2775
|
if (editor.isTextBlock(node)) {
|
|
2775
2776
|
const children = slate.Node.children(editor, path);
|
|
2776
2777
|
for (const [child, childPath] of children) {
|
|
@@ -2785,65 +2786,47 @@ function createWithPortableTextMarkModel(types2, change$, keyGenerator) {
|
|
|
2785
2786
|
}
|
|
2786
2787
|
}
|
|
2787
2788
|
}
|
|
2788
|
-
if (
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2789
|
+
if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
|
|
2790
|
+
debug$c("Adding .marks to span node"), slate.Transforms.setNodes(editor, { marks: [] }, { at: path });
|
|
2791
|
+
return;
|
|
2792
|
+
}
|
|
2793
|
+
if (editor.isTextSpan(node)) {
|
|
2794
|
+
const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath), decorators2 = types2.decorators.map((decorator) => decorator.value), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
|
|
2795
|
+
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
2796
|
+
debug$c("Removing annotations from empty span node"), slate.Transforms.setNodes(
|
|
2797
|
+
editor,
|
|
2798
|
+
{ marks: node.marks?.filter((mark) => decorators2.includes(mark)) },
|
|
2799
|
+
{ at: path }
|
|
2796
2800
|
);
|
|
2797
|
-
|
|
2798
|
-
const [block] = slate.Editor.node(editor, slate.Path.parent(path)), orphanedMarks = editor.isTextBlock(block) && annotationMarks.filter(
|
|
2799
|
-
(mark) => !block.markDefs?.find((def) => def._key === mark)
|
|
2800
|
-
) || [];
|
|
2801
|
-
if (orphanedMarks.length > 0) {
|
|
2802
|
-
debug$c("Removing orphaned .marks from span node"), slate.Transforms.setNodes(
|
|
2803
|
-
editor,
|
|
2804
|
-
{ marks: spanMarks.filter((mark) => !orphanedMarks.includes(mark)) },
|
|
2805
|
-
{ at: path }
|
|
2806
|
-
);
|
|
2807
|
-
return;
|
|
2808
|
-
}
|
|
2809
|
-
}
|
|
2801
|
+
return;
|
|
2810
2802
|
}
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
}
|
|
2820
|
-
}
|
|
2821
|
-
}
|
|
2822
|
-
if (op.type === "split_node" && op.path.length === 1 && slate.Element.isElementProps(op.properties) && op.properties._type === types2.block.name && "markDefs" in op.properties && Array.isArray(op.properties.markDefs) && op.properties.markDefs.length > 0 && op.path[0] + 1 < editor.children.length) {
|
|
2823
|
-
const [targetBlock, targetPath] = slate.Editor.node(editor, [op.path[0] + 1]);
|
|
2824
|
-
if (debug$c("Copying markDefs over to split block", op), editor.isTextBlock(targetBlock)) {
|
|
2825
|
-
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [];
|
|
2826
|
-
slate.Transforms.setNodes(
|
|
2803
|
+
}
|
|
2804
|
+
if (editor.isTextBlock(node)) {
|
|
2805
|
+
const decorators2 = types2.decorators.map((decorator) => decorator.value);
|
|
2806
|
+
for (const [child, childPath] of slate.Node.children(editor, path))
|
|
2807
|
+
if (editor.isTextSpan(child)) {
|
|
2808
|
+
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
2809
|
+
if (orphanedAnnotations.length > 0) {
|
|
2810
|
+
debug$c("Removing orphaned annotations from span node"), slate.Transforms.setNodes(
|
|
2827
2811
|
editor,
|
|
2828
|
-
{
|
|
2829
|
-
{ at:
|
|
2812
|
+
{ marks: marks.filter((mark) => !orphanedAnnotations.includes(mark)) },
|
|
2813
|
+
{ at: childPath }
|
|
2830
2814
|
);
|
|
2831
2815
|
return;
|
|
2832
2816
|
}
|
|
2833
2817
|
}
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
}
|
|
2818
|
+
}
|
|
2819
|
+
if (editor.isTextSpan(node)) {
|
|
2820
|
+
const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath);
|
|
2821
|
+
if (editor.isTextBlock(block)) {
|
|
2822
|
+
const decorators2 = types2.decorators.map((decorator) => decorator.value), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
2823
|
+
if (orphanedAnnotations.length > 0) {
|
|
2824
|
+
debug$c("Removing orphaned annotations from span node"), slate.Transforms.setNodes(
|
|
2825
|
+
editor,
|
|
2826
|
+
{ marks: marks.filter((mark) => !orphanedAnnotations.includes(mark)) },
|
|
2827
|
+
{ at: path }
|
|
2828
|
+
);
|
|
2829
|
+
return;
|
|
2847
2830
|
}
|
|
2848
2831
|
}
|
|
2849
2832
|
}
|
|
@@ -2937,6 +2920,14 @@ function createWithPortableTextMarkModel(types2, change$, keyGenerator) {
|
|
|
2937
2920
|
}
|
|
2938
2921
|
}
|
|
2939
2922
|
}
|
|
2923
|
+
if (op.type === "merge_node" && op.path.length === 1 && "markDefs" in op.properties && op.properties._type === types2.block.name && Array.isArray(op.properties.markDefs) && op.properties.markDefs.length > 0 && op.path[0] - 1 >= 0) {
|
|
2924
|
+
const [targetBlock, targetPath] = slate.Editor.node(editor, [op.path[0] - 1]);
|
|
2925
|
+
if (editor.isTextBlock(targetBlock)) {
|
|
2926
|
+
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq__default.default([...oldDefs, ...op.properties.markDefs]);
|
|
2927
|
+
debug$c("Copying markDefs over to merged block", op), slate.Transforms.setNodes(editor, { markDefs: newMarkDefs }, { at: targetPath, voids: !1 }), apply2(op);
|
|
2928
|
+
return;
|
|
2929
|
+
}
|
|
2930
|
+
}
|
|
2940
2931
|
apply2(op);
|
|
2941
2932
|
}, editor.addMark = (mark) => {
|
|
2942
2933
|
if (editor.selection) {
|