@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.31.0",
3
+ "version": "1.31.2",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -73,7 +73,7 @@
73
73
  "get-random-values-esm": "^1.0.2",
74
74
  "lodash": "^4.17.21",
75
75
  "lodash.startcase": "^4.4.0",
76
- "react-compiler-runtime": "19.0.0-beta-714736e-20250131",
76
+ "react-compiler-runtime": "19.0.0-beta-30d8a17-20250209",
77
77
  "slate": "0.112.0",
78
78
  "slate-dom": "^0.112.2",
79
79
  "slate-react": "0.112.1",
@@ -100,9 +100,9 @@
100
100
  "@vitejs/plugin-react": "^4.3.4",
101
101
  "@vitest/browser": "^3.0.5",
102
102
  "@vitest/coverage-istanbul": "^3.0.5",
103
- "babel-plugin-react-compiler": "19.0.0-beta-714736e-20250131",
103
+ "babel-plugin-react-compiler": "19.0.0-beta-30d8a17-20250209",
104
104
  "eslint": "8.57.1",
105
- "eslint-plugin-react-compiler": "19.0.0-beta-714736e-20250131",
105
+ "eslint-plugin-react-compiler": "19.0.0-beta-30d8a17-20250209",
106
106
  "eslint-plugin-react-hooks": "^5.1.0",
107
107
  "jsdom": "^26.0.0",
108
108
  "react": "^19.0.0",
@@ -112,7 +112,7 @@
112
112
  "vite": "^6.0.11",
113
113
  "vitest": "^3.0.5",
114
114
  "vitest-browser-react": "^0.0.4",
115
- "racejar": "1.1.3"
115
+ "racejar": "1.2.0"
116
116
  },
117
117
  "peerDependencies": {
118
118
  "@sanity/schema": "^3.74.1",
@@ -629,118 +629,110 @@ export const addAnnotationActionImplementation: BehaviorActionImplementation<
629
629
  AddedAnnotationPaths | undefined
630
630
  > = ({context, action}) => {
631
631
  const editor = action.editor
632
- const {selection: originalSelection} = editor
633
- let paths: AddedAnnotationPaths | undefined = undefined
634
-
635
- if (originalSelection) {
636
- if (Range.isCollapsed(originalSelection)) {
637
- return
638
- }
639
-
640
- // If we still have a selection, add the annotation to the selected text
641
- if (editor.selection) {
642
- let spanPath: Path | undefined
643
- let markDefPath: Path | undefined
644
- const markDefPaths: Path[] = []
645
632
 
646
- if (!editor.selection) {
647
- return
648
- }
633
+ if (!editor.selection || Range.isCollapsed(editor.selection)) {
634
+ return
635
+ }
649
636
 
650
- const selectedBlocks = Editor.nodes(editor, {
651
- at: editor.selection,
652
- match: (node) => editor.isTextBlock(node),
653
- reverse: Range.isBackward(editor.selection),
654
- })
637
+ let paths: AddedAnnotationPaths | undefined = undefined
638
+ let spanPath: Path | undefined
639
+ let markDefPath: Path | undefined
640
+ const markDefPaths: Path[] = []
641
+
642
+ const selectedBlocks = Editor.nodes(editor, {
643
+ at: editor.selection,
644
+ match: (node) => editor.isTextBlock(node),
645
+ reverse: Range.isBackward(editor.selection),
646
+ })
655
647
 
656
- for (const [block, blockPath] of selectedBlocks) {
657
- if (block.children.length === 0) {
658
- continue
659
- }
648
+ for (const [block, blockPath] of selectedBlocks) {
649
+ if (block.children.length === 0) {
650
+ continue
651
+ }
660
652
 
661
- if (block.children.length === 1 && block.children[0].text === '') {
662
- continue
663
- }
653
+ if (block.children.length === 1 && block.children[0].text === '') {
654
+ continue
655
+ }
664
656
 
665
- const annotationKey = context.keyGenerator()
666
- const markDefs = block.markDefs ?? []
667
- const existingMarkDef = markDefs.find(
668
- (markDef) =>
669
- markDef._type === action.annotation.name &&
670
- markDef._key === annotationKey,
671
- )
657
+ const annotationKey = context.keyGenerator()
658
+ const markDefs = block.markDefs ?? []
659
+ const existingMarkDef = markDefs.find(
660
+ (markDef) =>
661
+ markDef._type === action.annotation.name &&
662
+ markDef._key === annotationKey,
663
+ )
672
664
 
673
- if (existingMarkDef === undefined) {
674
- Transforms.setNodes(
675
- editor,
665
+ if (existingMarkDef === undefined) {
666
+ Transforms.setNodes(
667
+ editor,
668
+ {
669
+ markDefs: [
670
+ ...markDefs,
676
671
  {
677
- markDefs: [
678
- ...markDefs,
679
- {
680
- _type: action.annotation.name,
681
- _key: annotationKey,
682
- ...action.annotation.value,
683
- },
684
- ],
672
+ _type: action.annotation.name,
673
+ _key: annotationKey,
674
+ ...action.annotation.value,
685
675
  },
686
- {at: blockPath},
687
- )
676
+ ],
677
+ },
678
+ {at: blockPath},
679
+ )
688
680
 
689
- markDefPath = [{_key: block._key}, 'markDefs', {_key: annotationKey}]
690
- if (Range.isBackward(editor.selection)) {
691
- markDefPaths.unshift(markDefPath)
692
- } else {
693
- markDefPaths.push(markDefPath)
694
- }
695
- }
681
+ markDefPath = [{_key: block._key}, 'markDefs', {_key: annotationKey}]
696
682
 
697
- Transforms.setNodes(editor, {}, {match: Text.isText, split: true})
683
+ if (Range.isBackward(editor.selection)) {
684
+ markDefPaths.unshift(markDefPath)
685
+ } else {
686
+ markDefPaths.push(markDefPath)
687
+ }
688
+ }
698
689
 
699
- const children = Node.children(editor, blockPath)
690
+ Transforms.setNodes(editor, {}, {match: Text.isText, split: true})
700
691
 
701
- for (const [span, path] of children) {
702
- if (!editor.isTextSpan(span)) {
703
- continue
704
- }
692
+ const children = Node.children(editor, blockPath)
705
693
 
706
- if (!Range.includes(editor.selection, path)) {
707
- continue
708
- }
694
+ for (const [span, path] of children) {
695
+ if (!editor.isTextSpan(span)) {
696
+ continue
697
+ }
709
698
 
710
- const marks = span.marks ?? []
711
- const existingSameTypeAnnotations = marks.filter((mark) =>
712
- markDefs.some(
713
- (markDef) =>
714
- markDef._key === mark &&
715
- markDef._type === action.annotation.name,
699
+ if (!Range.includes(editor.selection, path)) {
700
+ continue
701
+ }
702
+
703
+ const marks = span.marks ?? []
704
+ const existingSameTypeAnnotations = marks.filter((mark) =>
705
+ markDefs.some(
706
+ (markDef) =>
707
+ markDef._key === mark && markDef._type === action.annotation.name,
708
+ ),
709
+ )
710
+
711
+ Transforms.setNodes(
712
+ editor,
713
+ {
714
+ marks: [
715
+ ...marks.filter(
716
+ (mark) => !existingSameTypeAnnotations.includes(mark),
716
717
  ),
717
- )
718
+ annotationKey,
719
+ ],
720
+ },
721
+ {at: path},
722
+ )
718
723
 
719
- Transforms.setNodes(
720
- editor,
721
- {
722
- marks: [
723
- ...marks.filter(
724
- (mark) => !existingSameTypeAnnotations.includes(mark),
725
- ),
726
- annotationKey,
727
- ],
728
- },
729
- {at: path},
730
- )
731
- spanPath = [{_key: block._key}, 'children', {_key: span._key}]
732
- }
733
- }
724
+ spanPath = [{_key: block._key}, 'children', {_key: span._key}]
725
+ }
726
+ }
734
727
 
735
- if (markDefPath && spanPath) {
736
- paths = {
737
- markDefPath,
738
- markDefPaths,
739
- spanPath,
740
- }
741
- }
728
+ if (markDefPath && spanPath) {
729
+ paths = {
730
+ markDefPath,
731
+ markDefPaths,
732
+ spanPath,
742
733
  }
743
734
  }
735
+
744
736
  return paths
745
737
  }
746
738