@portabletext/editor 1.31.0 → 1.31.2
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/_chunks-cjs/plugin.event-listener.cjs +48 -59
- package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -1
- package/lib/_chunks-es/plugin.event-listener.js +48 -59
- package/lib/_chunks-es/plugin.event-listener.js.map +1 -1
- package/package.json +5 -5
- package/src/editor/plugins/createWithEditableAPI.ts +85 -93
|
@@ -4595,67 +4595,56 @@ const addAnnotationActionImplementation = ({
|
|
|
4595
4595
|
context,
|
|
4596
4596
|
action
|
|
4597
4597
|
}) => {
|
|
4598
|
-
const editor = action.editor
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
let paths;
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
marks: [...marks.filter((mark) => !existingSameTypeAnnotations.includes(mark)), annotationKey]
|
|
4642
|
-
}, {
|
|
4643
|
-
at: path
|
|
4644
|
-
}), spanPath = [{
|
|
4645
|
-
_key: block._key
|
|
4646
|
-
}, "children", {
|
|
4647
|
-
_key: span._key
|
|
4648
|
-
}];
|
|
4649
|
-
}
|
|
4650
|
-
}
|
|
4651
|
-
markDefPath && spanPath && (paths = {
|
|
4652
|
-
markDefPath,
|
|
4653
|
-
markDefPaths,
|
|
4654
|
-
spanPath
|
|
4655
|
-
});
|
|
4598
|
+
const editor = action.editor;
|
|
4599
|
+
if (!editor.selection || Range.isCollapsed(editor.selection))
|
|
4600
|
+
return;
|
|
4601
|
+
let paths, spanPath, markDefPath;
|
|
4602
|
+
const markDefPaths = [], selectedBlocks = Editor.nodes(editor, {
|
|
4603
|
+
at: editor.selection,
|
|
4604
|
+
match: (node) => editor.isTextBlock(node),
|
|
4605
|
+
reverse: Range.isBackward(editor.selection)
|
|
4606
|
+
});
|
|
4607
|
+
for (const [block, blockPath] of selectedBlocks) {
|
|
4608
|
+
if (block.children.length === 0 || block.children.length === 1 && block.children[0].text === "")
|
|
4609
|
+
continue;
|
|
4610
|
+
const annotationKey = context.keyGenerator(), markDefs = block.markDefs ?? [];
|
|
4611
|
+
markDefs.find((markDef) => markDef._type === action.annotation.name && markDef._key === annotationKey) === void 0 && (Transforms.setNodes(editor, {
|
|
4612
|
+
markDefs: [...markDefs, {
|
|
4613
|
+
_type: action.annotation.name,
|
|
4614
|
+
_key: annotationKey,
|
|
4615
|
+
...action.annotation.value
|
|
4616
|
+
}]
|
|
4617
|
+
}, {
|
|
4618
|
+
at: blockPath
|
|
4619
|
+
}), markDefPath = [{
|
|
4620
|
+
_key: block._key
|
|
4621
|
+
}, "markDefs", {
|
|
4622
|
+
_key: annotationKey
|
|
4623
|
+
}], Range.isBackward(editor.selection) ? markDefPaths.unshift(markDefPath) : markDefPaths.push(markDefPath)), Transforms.setNodes(editor, {}, {
|
|
4624
|
+
match: Text.isText,
|
|
4625
|
+
split: !0
|
|
4626
|
+
});
|
|
4627
|
+
const children = Node.children(editor, blockPath);
|
|
4628
|
+
for (const [span, path] of children) {
|
|
4629
|
+
if (!editor.isTextSpan(span) || !Range.includes(editor.selection, path))
|
|
4630
|
+
continue;
|
|
4631
|
+
const marks = span.marks ?? [], existingSameTypeAnnotations = marks.filter((mark) => markDefs.some((markDef) => markDef._key === mark && markDef._type === action.annotation.name));
|
|
4632
|
+
Transforms.setNodes(editor, {
|
|
4633
|
+
marks: [...marks.filter((mark) => !existingSameTypeAnnotations.includes(mark)), annotationKey]
|
|
4634
|
+
}, {
|
|
4635
|
+
at: path
|
|
4636
|
+
}), spanPath = [{
|
|
4637
|
+
_key: block._key
|
|
4638
|
+
}, "children", {
|
|
4639
|
+
_key: span._key
|
|
4640
|
+
}];
|
|
4656
4641
|
}
|
|
4657
4642
|
}
|
|
4658
|
-
return paths
|
|
4643
|
+
return markDefPath && spanPath && (paths = {
|
|
4644
|
+
markDefPath,
|
|
4645
|
+
markDefPaths,
|
|
4646
|
+
spanPath
|
|
4647
|
+
}), paths;
|
|
4659
4648
|
}, removeAnnotationActionImplementation = ({
|
|
4660
4649
|
action
|
|
4661
4650
|
}) => {
|