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