@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.esm.js
CHANGED
|
@@ -122,7 +122,7 @@ function normalizeSelection(selection, value) {
|
|
|
122
122
|
const { anchor, focus } = selection;
|
|
123
123
|
return anchor && value.find((blk) => isEqual({ _key: blk._key }, anchor.path[0])) && (newAnchor = normalizePoint(anchor, value)), focus && value.find((blk) => isEqual({ _key: blk._key }, focus.path[0])) && (newFocus = normalizePoint(focus, value)), newAnchor && newFocus ? { anchor: newAnchor, focus: newFocus, backward: selection.backward } : null;
|
|
124
124
|
}
|
|
125
|
-
const EMPTY_MARKDEFS = [],
|
|
125
|
+
const EMPTY_MARKDEFS = [], VOID_CHILD_KEY = "void-child";
|
|
126
126
|
function keepObjectEquality(object, keyMap) {
|
|
127
127
|
const value = keyMap[object._key];
|
|
128
128
|
return value && isEqual(object, value) ? value : (keyMap[object._key] = object, object);
|
|
@@ -1168,9 +1168,10 @@ function createWithEditableAPI(portableTextEditor, types, keyGenerator) {
|
|
|
1168
1168
|
const [block] = Editor.node(editor, originalSelection.focus, { depth: 1 });
|
|
1169
1169
|
if (!editor.isTextBlock(block))
|
|
1170
1170
|
return;
|
|
1171
|
-
Range.isCollapsed(originalSelection) && (editor.pteExpandToWord(), editor.onChange());
|
|
1172
1171
|
const [textNode] = Editor.node(editor, originalSelection.focus, { depth: 2 });
|
|
1173
|
-
|
|
1172
|
+
if (!isPortableTextSpan$1(textNode) || textNode.text === "")
|
|
1173
|
+
return;
|
|
1174
|
+
Range.isCollapsed(originalSelection) && (editor.pteExpandToWord(), editor.onChange()), editor.selection && (Editor.withoutNormalizing(editor, () => {
|
|
1174
1175
|
const annotationKey = keyGenerator();
|
|
1175
1176
|
Transforms.setNodes(
|
|
1176
1177
|
editor,
|
|
@@ -2786,7 +2787,7 @@ function createWithPortableTextMarkModel(types, change$, keyGenerator) {
|
|
|
2786
2787
|
change$.next({ type: "selection", selection: ptRange });
|
|
2787
2788
|
};
|
|
2788
2789
|
return editor.normalizeNode = (nodeEntry) => {
|
|
2789
|
-
const [node, path] = nodeEntry
|
|
2790
|
+
const [node, path] = nodeEntry;
|
|
2790
2791
|
if (editor.isTextBlock(node)) {
|
|
2791
2792
|
const children = Node.children(editor, path);
|
|
2792
2793
|
for (const [child, childPath] of children) {
|
|
@@ -2801,65 +2802,47 @@ function createWithPortableTextMarkModel(types, change$, keyGenerator) {
|
|
|
2801
2802
|
}
|
|
2802
2803
|
}
|
|
2803
2804
|
}
|
|
2804
|
-
if (
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2805
|
+
if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
|
|
2806
|
+
debug$c("Adding .marks to span node"), Transforms.setNodes(editor, { marks: [] }, { at: path });
|
|
2807
|
+
return;
|
|
2808
|
+
}
|
|
2809
|
+
if (editor.isTextSpan(node)) {
|
|
2810
|
+
const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath), decorators2 = types.decorators.map((decorator) => decorator.value), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
|
|
2811
|
+
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
2812
|
+
debug$c("Removing annotations from empty span node"), Transforms.setNodes(
|
|
2813
|
+
editor,
|
|
2814
|
+
{ marks: node.marks?.filter((mark) => decorators2.includes(mark)) },
|
|
2815
|
+
{ at: path }
|
|
2812
2816
|
);
|
|
2813
|
-
|
|
2814
|
-
const [block] = Editor.node(editor, Path.parent(path)), orphanedMarks = editor.isTextBlock(block) && annotationMarks.filter(
|
|
2815
|
-
(mark) => !block.markDefs?.find((def) => def._key === mark)
|
|
2816
|
-
) || [];
|
|
2817
|
-
if (orphanedMarks.length > 0) {
|
|
2818
|
-
debug$c("Removing orphaned .marks from span node"), Transforms.setNodes(
|
|
2819
|
-
editor,
|
|
2820
|
-
{ marks: spanMarks.filter((mark) => !orphanedMarks.includes(mark)) },
|
|
2821
|
-
{ at: path }
|
|
2822
|
-
);
|
|
2823
|
-
return;
|
|
2824
|
-
}
|
|
2825
|
-
}
|
|
2817
|
+
return;
|
|
2826
2818
|
}
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
}
|
|
2836
|
-
}
|
|
2837
|
-
}
|
|
2838
|
-
if (op.type === "split_node" && op.path.length === 1 && Element$1.isElementProps(op.properties) && op.properties._type === types.block.name && "markDefs" in op.properties && Array.isArray(op.properties.markDefs) && op.properties.markDefs.length > 0 && op.path[0] + 1 < editor.children.length) {
|
|
2839
|
-
const [targetBlock, targetPath] = Editor.node(editor, [op.path[0] + 1]);
|
|
2840
|
-
if (debug$c("Copying markDefs over to split block", op), editor.isTextBlock(targetBlock)) {
|
|
2841
|
-
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [];
|
|
2842
|
-
Transforms.setNodes(
|
|
2819
|
+
}
|
|
2820
|
+
if (editor.isTextBlock(node)) {
|
|
2821
|
+
const decorators2 = types.decorators.map((decorator) => decorator.value);
|
|
2822
|
+
for (const [child, childPath] of Node.children(editor, path))
|
|
2823
|
+
if (editor.isTextSpan(child)) {
|
|
2824
|
+
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
2825
|
+
if (orphanedAnnotations.length > 0) {
|
|
2826
|
+
debug$c("Removing orphaned annotations from span node"), Transforms.setNodes(
|
|
2843
2827
|
editor,
|
|
2844
|
-
{
|
|
2845
|
-
{ at:
|
|
2828
|
+
{ marks: marks.filter((mark) => !orphanedAnnotations.includes(mark)) },
|
|
2829
|
+
{ at: childPath }
|
|
2846
2830
|
);
|
|
2847
2831
|
return;
|
|
2848
2832
|
}
|
|
2849
2833
|
}
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
}
|
|
2834
|
+
}
|
|
2835
|
+
if (editor.isTextSpan(node)) {
|
|
2836
|
+
const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath);
|
|
2837
|
+
if (editor.isTextBlock(block)) {
|
|
2838
|
+
const decorators2 = types.decorators.map((decorator) => decorator.value), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
2839
|
+
if (orphanedAnnotations.length > 0) {
|
|
2840
|
+
debug$c("Removing orphaned annotations from span node"), Transforms.setNodes(
|
|
2841
|
+
editor,
|
|
2842
|
+
{ marks: marks.filter((mark) => !orphanedAnnotations.includes(mark)) },
|
|
2843
|
+
{ at: path }
|
|
2844
|
+
);
|
|
2845
|
+
return;
|
|
2863
2846
|
}
|
|
2864
2847
|
}
|
|
2865
2848
|
}
|
|
@@ -2953,6 +2936,14 @@ function createWithPortableTextMarkModel(types, change$, keyGenerator) {
|
|
|
2953
2936
|
}
|
|
2954
2937
|
}
|
|
2955
2938
|
}
|
|
2939
|
+
if (op.type === "merge_node" && op.path.length === 1 && "markDefs" in op.properties && op.properties._type === types.block.name && Array.isArray(op.properties.markDefs) && op.properties.markDefs.length > 0 && op.path[0] - 1 >= 0) {
|
|
2940
|
+
const [targetBlock, targetPath] = Editor.node(editor, [op.path[0] - 1]);
|
|
2941
|
+
if (editor.isTextBlock(targetBlock)) {
|
|
2942
|
+
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq([...oldDefs, ...op.properties.markDefs]);
|
|
2943
|
+
debug$c("Copying markDefs over to merged block", op), Transforms.setNodes(editor, { markDefs: newMarkDefs }, { at: targetPath, voids: !1 }), apply2(op);
|
|
2944
|
+
return;
|
|
2945
|
+
}
|
|
2946
|
+
}
|
|
2956
2947
|
apply2(op);
|
|
2957
2948
|
}, editor.addMark = (mark) => {
|
|
2958
2949
|
if (editor.selection) {
|