@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
|
@@ -4572,67 +4572,56 @@ const addAnnotationActionImplementation = ({
|
|
|
4572
4572
|
context,
|
|
4573
4573
|
action
|
|
4574
4574
|
}) => {
|
|
4575
|
-
const editor = action.editor
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
let paths;
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
marks: [...marks.filter((mark) => !existingSameTypeAnnotations.includes(mark)), annotationKey]
|
|
4619
|
-
}, {
|
|
4620
|
-
at: path
|
|
4621
|
-
}), spanPath = [{
|
|
4622
|
-
_key: block._key
|
|
4623
|
-
}, "children", {
|
|
4624
|
-
_key: span._key
|
|
4625
|
-
}];
|
|
4626
|
-
}
|
|
4627
|
-
}
|
|
4628
|
-
markDefPath && spanPath && (paths = {
|
|
4629
|
-
markDefPath,
|
|
4630
|
-
markDefPaths,
|
|
4631
|
-
spanPath
|
|
4632
|
-
});
|
|
4575
|
+
const editor = action.editor;
|
|
4576
|
+
if (!editor.selection || slate.Range.isCollapsed(editor.selection))
|
|
4577
|
+
return;
|
|
4578
|
+
let paths, spanPath, markDefPath;
|
|
4579
|
+
const markDefPaths = [], selectedBlocks = slate.Editor.nodes(editor, {
|
|
4580
|
+
at: editor.selection,
|
|
4581
|
+
match: (node) => editor.isTextBlock(node),
|
|
4582
|
+
reverse: slate.Range.isBackward(editor.selection)
|
|
4583
|
+
});
|
|
4584
|
+
for (const [block, blockPath] of selectedBlocks) {
|
|
4585
|
+
if (block.children.length === 0 || block.children.length === 1 && block.children[0].text === "")
|
|
4586
|
+
continue;
|
|
4587
|
+
const annotationKey = context.keyGenerator(), markDefs = block.markDefs ?? [];
|
|
4588
|
+
markDefs.find((markDef) => markDef._type === action.annotation.name && markDef._key === annotationKey) === void 0 && (slate.Transforms.setNodes(editor, {
|
|
4589
|
+
markDefs: [...markDefs, {
|
|
4590
|
+
_type: action.annotation.name,
|
|
4591
|
+
_key: annotationKey,
|
|
4592
|
+
...action.annotation.value
|
|
4593
|
+
}]
|
|
4594
|
+
}, {
|
|
4595
|
+
at: blockPath
|
|
4596
|
+
}), markDefPath = [{
|
|
4597
|
+
_key: block._key
|
|
4598
|
+
}, "markDefs", {
|
|
4599
|
+
_key: annotationKey
|
|
4600
|
+
}], slate.Range.isBackward(editor.selection) ? markDefPaths.unshift(markDefPath) : markDefPaths.push(markDefPath)), slate.Transforms.setNodes(editor, {}, {
|
|
4601
|
+
match: slate.Text.isText,
|
|
4602
|
+
split: !0
|
|
4603
|
+
});
|
|
4604
|
+
const children = slate.Node.children(editor, blockPath);
|
|
4605
|
+
for (const [span, path] of children) {
|
|
4606
|
+
if (!editor.isTextSpan(span) || !slate.Range.includes(editor.selection, path))
|
|
4607
|
+
continue;
|
|
4608
|
+
const marks = span.marks ?? [], existingSameTypeAnnotations = marks.filter((mark) => markDefs.some((markDef) => markDef._key === mark && markDef._type === action.annotation.name));
|
|
4609
|
+
slate.Transforms.setNodes(editor, {
|
|
4610
|
+
marks: [...marks.filter((mark) => !existingSameTypeAnnotations.includes(mark)), annotationKey]
|
|
4611
|
+
}, {
|
|
4612
|
+
at: path
|
|
4613
|
+
}), spanPath = [{
|
|
4614
|
+
_key: block._key
|
|
4615
|
+
}, "children", {
|
|
4616
|
+
_key: span._key
|
|
4617
|
+
}];
|
|
4633
4618
|
}
|
|
4634
4619
|
}
|
|
4635
|
-
return paths
|
|
4620
|
+
return markDefPath && spanPath && (paths = {
|
|
4621
|
+
markDefPath,
|
|
4622
|
+
markDefPaths,
|
|
4623
|
+
spanPath
|
|
4624
|
+
}), paths;
|
|
4636
4625
|
}, removeAnnotationActionImplementation = ({
|
|
4637
4626
|
action
|
|
4638
4627
|
}) => {
|