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