@portabletext/editor 2.14.4 → 2.15.0
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/{selector.is-active-style.cjs → selector.is-at-the-start-of-block.cjs} +90 -94
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -0
- package/lib/_chunks-dts/behavior.types.action.d.cts +4 -0
- package/lib/_chunks-dts/behavior.types.action.d.ts +4 -0
- package/lib/_chunks-es/{selector.is-active-style.js → selector.is-at-the-start-of-block.js} +90 -94
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -0
- package/lib/index.cjs +163 -81
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +84 -2
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.cjs +33 -33
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.js +2 -2
- package/lib/utils/index.d.cts +2 -2
- package/package.json +3 -3
- package/src/editor/editor-dom.ts +99 -0
- package/src/internal-utils/operation-to-patches.ts +39 -0
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +0 -1
- package/lib/_chunks-es/selector.is-active-style.js.map +0 -1
package/lib/_chunks-cjs/{selector.is-active-style.cjs → selector.is-at-the-start-of-block.cjs}
RENAMED
|
@@ -576,6 +576,29 @@ const getTrimmedSelection = (snapshot) => {
|
|
|
576
576
|
return null;
|
|
577
577
|
}
|
|
578
578
|
return trimmedSelection;
|
|
579
|
+
}, getActiveAnnotations = (snapshot) => {
|
|
580
|
+
if (!snapshot.context.selection)
|
|
581
|
+
return [];
|
|
582
|
+
const selectedBlocks = getSelectedBlocks(snapshot), activeAnnotations = (getMarkState(snapshot)?.marks ?? []).filter((mark) => !snapshot.context.schema.decorators.map((decorator) => decorator.name).includes(mark));
|
|
583
|
+
return selectedBlocks.flatMap((block) => schema.isTextBlock(snapshot.context, block.node) ? block.node.markDefs ?? [] : []).filter((markDef) => activeAnnotations.includes(markDef._key));
|
|
584
|
+
}, getActiveListItem = (snapshot) => {
|
|
585
|
+
if (!snapshot.context.selection)
|
|
586
|
+
return;
|
|
587
|
+
const selectedTextBlocks = getSelectedBlocks(snapshot).map((block) => block.node).filter((block) => schema.isTextBlock(snapshot.context, block)), firstTextBlock = selectedTextBlocks.at(0);
|
|
588
|
+
if (!firstTextBlock)
|
|
589
|
+
return;
|
|
590
|
+
const firstListItem = firstTextBlock.listItem;
|
|
591
|
+
if (firstListItem && selectedTextBlocks.every((block) => block.listItem === firstListItem))
|
|
592
|
+
return firstListItem;
|
|
593
|
+
}, getActiveStyle = (snapshot) => {
|
|
594
|
+
if (!snapshot.context.selection)
|
|
595
|
+
return;
|
|
596
|
+
const selectedTextBlocks = getSelectedBlocks(snapshot).map((block) => block.node).filter((block) => schema.isTextBlock(snapshot.context, block)), firstTextBlock = selectedTextBlocks.at(0);
|
|
597
|
+
if (!firstTextBlock)
|
|
598
|
+
return;
|
|
599
|
+
const firstStyle = firstTextBlock.style;
|
|
600
|
+
if (firstStyle && selectedTextBlocks.every((block) => block.style === firstStyle))
|
|
601
|
+
return firstStyle;
|
|
579
602
|
}, getNextInlineObject = (snapshot) => {
|
|
580
603
|
const focusTextBlock = selector_getSelectionText.getFocusTextBlock(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot), selectionEndPointChildKey = selectionEndPoint && types.isKeySegment(selectionEndPoint.path[2]) ? selectionEndPoint.path[2]._key : void 0;
|
|
581
604
|
if (!focusTextBlock || !selectionEndPointChildKey)
|
|
@@ -666,25 +689,34 @@ const getTrimmedSelection = (snapshot) => {
|
|
|
666
689
|
selection: caretWordSelection
|
|
667
690
|
}
|
|
668
691
|
}) ? caretWordSelection : null;
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
const selectionMarkDefs = getSelectedBlocks(snapshot).flatMap((block) => schema.isTextBlock(snapshot.context, block.node) ? block.node.markDefs ?? [] : []), activeAnnotations = getActiveAnnotationsMarks(snapshot);
|
|
679
|
-
return selectionMarkDefs.filter((markDef) => markDef._type === annotation && activeAnnotations.includes(markDef._key)).length > 0;
|
|
680
|
-
};
|
|
681
|
-
}
|
|
682
|
-
const getFocusBlockObject = (snapshot) => {
|
|
692
|
+
}, getFirstBlock = (snapshot) => {
|
|
693
|
+
const node = snapshot.context.value[0];
|
|
694
|
+
return node ? {
|
|
695
|
+
node,
|
|
696
|
+
path: [{
|
|
697
|
+
_key: node._key
|
|
698
|
+
}]
|
|
699
|
+
} : void 0;
|
|
700
|
+
}, getFocusBlockObject = (snapshot) => {
|
|
683
701
|
const focusBlock = selector_getSelectionText.getFocusBlock(snapshot);
|
|
684
702
|
return focusBlock && !schema.isTextBlock(snapshot.context, focusBlock.node) ? {
|
|
685
703
|
node: focusBlock.node,
|
|
686
704
|
path: focusBlock.path
|
|
687
705
|
} : void 0;
|
|
706
|
+
}, getFocusListBlock = (snapshot) => {
|
|
707
|
+
const focusTextBlock = selector_getSelectionText.getFocusTextBlock(snapshot);
|
|
708
|
+
return focusTextBlock && util_getTextBlockText.isListBlock(snapshot.context, focusTextBlock.node) ? {
|
|
709
|
+
node: focusTextBlock.node,
|
|
710
|
+
path: focusTextBlock.path
|
|
711
|
+
} : void 0;
|
|
712
|
+
}, getLastBlock = (snapshot) => {
|
|
713
|
+
const node = snapshot.context.value[snapshot.context.value.length - 1] ? snapshot.context.value[snapshot.context.value.length - 1] : void 0;
|
|
714
|
+
return node ? {
|
|
715
|
+
node,
|
|
716
|
+
path: [{
|
|
717
|
+
_key: node._key
|
|
718
|
+
}]
|
|
719
|
+
} : void 0;
|
|
688
720
|
}, getNextBlock = (snapshot) => {
|
|
689
721
|
const selectionEndBlock = getSelectionEndBlock(snapshot);
|
|
690
722
|
if (!selectionEndBlock)
|
|
@@ -713,66 +745,6 @@ const getFocusBlockObject = (snapshot) => {
|
|
|
713
745
|
_key: previousBlock._key
|
|
714
746
|
}]
|
|
715
747
|
} : void 0;
|
|
716
|
-
}, getFirstBlock = (snapshot) => {
|
|
717
|
-
const node = snapshot.context.value[0];
|
|
718
|
-
return node ? {
|
|
719
|
-
node,
|
|
720
|
-
path: [{
|
|
721
|
-
_key: node._key
|
|
722
|
-
}]
|
|
723
|
-
} : void 0;
|
|
724
|
-
}, getLastBlock = (snapshot) => {
|
|
725
|
-
const node = snapshot.context.value[snapshot.context.value.length - 1] ? snapshot.context.value[snapshot.context.value.length - 1] : void 0;
|
|
726
|
-
return node ? {
|
|
727
|
-
node,
|
|
728
|
-
path: [{
|
|
729
|
-
_key: node._key
|
|
730
|
-
}]
|
|
731
|
-
} : void 0;
|
|
732
|
-
};
|
|
733
|
-
function isAtTheEndOfBlock(block) {
|
|
734
|
-
return (snapshot) => {
|
|
735
|
-
if (!snapshot.context.selection || !selector_getSelectionText.isSelectionCollapsed(snapshot))
|
|
736
|
-
return !1;
|
|
737
|
-
const blockEndPoint = util_isEmptyTextBlock.getBlockEndPoint({
|
|
738
|
-
context: snapshot.context,
|
|
739
|
-
block
|
|
740
|
-
});
|
|
741
|
-
return util_isEmptyTextBlock.isEqualSelectionPoints(snapshot.context.selection.focus, blockEndPoint);
|
|
742
|
-
};
|
|
743
|
-
}
|
|
744
|
-
function isAtTheStartOfBlock(block) {
|
|
745
|
-
return (snapshot) => {
|
|
746
|
-
if (!snapshot.context.selection || !selector_getSelectionText.isSelectionCollapsed(snapshot))
|
|
747
|
-
return !1;
|
|
748
|
-
const blockStartPoint = util_getTextBlockText.getBlockStartPoint({
|
|
749
|
-
context: snapshot.context,
|
|
750
|
-
block
|
|
751
|
-
});
|
|
752
|
-
return util_isEmptyTextBlock.isEqualSelectionPoints(snapshot.context.selection.focus, blockStartPoint);
|
|
753
|
-
};
|
|
754
|
-
}
|
|
755
|
-
const getFocusListBlock = (snapshot) => {
|
|
756
|
-
const focusTextBlock = selector_getSelectionText.getFocusTextBlock(snapshot);
|
|
757
|
-
return focusTextBlock && util_getTextBlockText.isListBlock(snapshot.context, focusTextBlock.node) ? {
|
|
758
|
-
node: focusTextBlock.node,
|
|
759
|
-
path: focusTextBlock.path
|
|
760
|
-
} : void 0;
|
|
761
|
-
};
|
|
762
|
-
function isActiveDecorator(decorator) {
|
|
763
|
-
return (snapshot) => {
|
|
764
|
-
if (selector_getSelectionText.isSelectionExpanded(snapshot)) {
|
|
765
|
-
const selectedSpans = getSelectedSpans(snapshot);
|
|
766
|
-
return selectedSpans.length > 0 && selectedSpans.every((span) => span.node.marks?.includes(decorator));
|
|
767
|
-
}
|
|
768
|
-
return getActiveDecorators(snapshot).includes(decorator);
|
|
769
|
-
};
|
|
770
|
-
}
|
|
771
|
-
const getActiveAnnotations = (snapshot) => {
|
|
772
|
-
if (!snapshot.context.selection)
|
|
773
|
-
return [];
|
|
774
|
-
const selectedBlocks = getSelectedBlocks(snapshot), activeAnnotations = (getMarkState(snapshot)?.marks ?? []).filter((mark) => !snapshot.context.schema.decorators.map((decorator) => decorator.name).includes(mark));
|
|
775
|
-
return selectedBlocks.flatMap((block) => schema.isTextBlock(snapshot.context, block.node) ? block.node.markDefs ?? [] : []).filter((markDef) => activeAnnotations.includes(markDef._key));
|
|
776
748
|
}, getSelectedTextBlocks = (snapshot) => {
|
|
777
749
|
if (!snapshot.context.selection)
|
|
778
750
|
return [];
|
|
@@ -811,32 +783,56 @@ const getActiveAnnotations = (snapshot) => {
|
|
|
811
783
|
});
|
|
812
784
|
}
|
|
813
785
|
return selectedTextBlocks;
|
|
814
|
-
}, getActiveListItem = (snapshot) => {
|
|
815
|
-
if (!snapshot.context.selection)
|
|
816
|
-
return;
|
|
817
|
-
const selectedTextBlocks = getSelectedBlocks(snapshot).map((block) => block.node).filter((block) => schema.isTextBlock(snapshot.context, block)), firstTextBlock = selectedTextBlocks.at(0);
|
|
818
|
-
if (!firstTextBlock)
|
|
819
|
-
return;
|
|
820
|
-
const firstListItem = firstTextBlock.listItem;
|
|
821
|
-
if (firstListItem && selectedTextBlocks.every((block) => block.listItem === firstListItem))
|
|
822
|
-
return firstListItem;
|
|
823
786
|
};
|
|
787
|
+
function getActiveAnnotationsMarks(snapshot) {
|
|
788
|
+
const schema2 = snapshot.context.schema;
|
|
789
|
+
return (getMarkState(snapshot)?.marks ?? []).filter((mark) => !schema2.decorators.map((decorator) => decorator.name).includes(mark));
|
|
790
|
+
}
|
|
791
|
+
function isActiveAnnotation(annotation, options) {
|
|
792
|
+
return (snapshot) => {
|
|
793
|
+
if ((options?.mode ?? "full") === "partial")
|
|
794
|
+
return selector_getSelectionText.getSelectedValue(snapshot).flatMap((block) => schema.isTextBlock(snapshot.context, block) ? block.markDefs ?? [] : []).some((markDef) => markDef._type === annotation);
|
|
795
|
+
const selectionMarkDefs = getSelectedBlocks(snapshot).flatMap((block) => schema.isTextBlock(snapshot.context, block.node) ? block.node.markDefs ?? [] : []), activeAnnotations = getActiveAnnotationsMarks(snapshot);
|
|
796
|
+
return selectionMarkDefs.filter((markDef) => markDef._type === annotation && activeAnnotations.includes(markDef._key)).length > 0;
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
function isActiveDecorator(decorator) {
|
|
800
|
+
return (snapshot) => {
|
|
801
|
+
if (selector_getSelectionText.isSelectionExpanded(snapshot)) {
|
|
802
|
+
const selectedSpans = getSelectedSpans(snapshot);
|
|
803
|
+
return selectedSpans.length > 0 && selectedSpans.every((span) => span.node.marks?.includes(decorator));
|
|
804
|
+
}
|
|
805
|
+
return getActiveDecorators(snapshot).includes(decorator);
|
|
806
|
+
};
|
|
807
|
+
}
|
|
824
808
|
function isActiveListItem(listItem) {
|
|
825
809
|
return (snapshot) => getActiveListItem(snapshot) === listItem;
|
|
826
810
|
}
|
|
827
|
-
const getActiveStyle = (snapshot) => {
|
|
828
|
-
if (!snapshot.context.selection)
|
|
829
|
-
return;
|
|
830
|
-
const selectedTextBlocks = getSelectedBlocks(snapshot).map((block) => block.node).filter((block) => schema.isTextBlock(snapshot.context, block)), firstTextBlock = selectedTextBlocks.at(0);
|
|
831
|
-
if (!firstTextBlock)
|
|
832
|
-
return;
|
|
833
|
-
const firstStyle = firstTextBlock.style;
|
|
834
|
-
if (firstStyle && selectedTextBlocks.every((block) => block.style === firstStyle))
|
|
835
|
-
return firstStyle;
|
|
836
|
-
};
|
|
837
811
|
function isActiveStyle(style) {
|
|
838
812
|
return (snapshot) => getActiveStyle(snapshot) === style;
|
|
839
813
|
}
|
|
814
|
+
function isAtTheEndOfBlock(block) {
|
|
815
|
+
return (snapshot) => {
|
|
816
|
+
if (!snapshot.context.selection || !selector_getSelectionText.isSelectionCollapsed(snapshot))
|
|
817
|
+
return !1;
|
|
818
|
+
const blockEndPoint = util_isEmptyTextBlock.getBlockEndPoint({
|
|
819
|
+
context: snapshot.context,
|
|
820
|
+
block
|
|
821
|
+
});
|
|
822
|
+
return util_isEmptyTextBlock.isEqualSelectionPoints(snapshot.context.selection.focus, blockEndPoint);
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
function isAtTheStartOfBlock(block) {
|
|
826
|
+
return (snapshot) => {
|
|
827
|
+
if (!snapshot.context.selection || !selector_getSelectionText.isSelectionCollapsed(snapshot))
|
|
828
|
+
return !1;
|
|
829
|
+
const blockStartPoint = util_getTextBlockText.getBlockStartPoint({
|
|
830
|
+
context: snapshot.context,
|
|
831
|
+
block
|
|
832
|
+
});
|
|
833
|
+
return util_isEmptyTextBlock.isEqualSelectionPoints(snapshot.context.selection.focus, blockStartPoint);
|
|
834
|
+
};
|
|
835
|
+
}
|
|
840
836
|
exports.getActiveAnnotations = getActiveAnnotations;
|
|
841
837
|
exports.getActiveAnnotationsMarks = getActiveAnnotationsMarks;
|
|
842
838
|
exports.getActiveDecorators = getActiveDecorators;
|
|
@@ -869,4 +865,4 @@ exports.isOverlappingSelection = isOverlappingSelection;
|
|
|
869
865
|
exports.isPointAfterSelection = isPointAfterSelection;
|
|
870
866
|
exports.isPointBeforeSelection = isPointBeforeSelection;
|
|
871
867
|
exports.isSelectingEntireBlocks = isSelectingEntireBlocks;
|
|
872
|
-
//# sourceMappingURL=selector.is-
|
|
868
|
+
//# sourceMappingURL=selector.is-at-the-start-of-block.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selector.is-at-the-start-of-block.cjs","sources":["../../src/selectors/selector.get-focus-inline-object.ts","../../src/selectors/selector.get-selected-blocks.ts","../../src/selectors/selector.get-selection-end-block.ts","../../src/selectors/selector.get-selection-start-block.ts","../../src/selectors/selector.get-selection-end-point.ts","../../src/selectors/selector.is-point-after-selection.ts","../../src/selectors/selector.is-point-before-selection.ts","../../src/selectors/selector.is-overlapping-selection.ts","../../src/selectors/selector.is-selecting-entire-blocks.ts","../../src/types/paths.ts","../../src/utils/util.is-selection-expanded.ts","../../src/selectors/selector.get-next-span.ts","../../src/selectors/selector.get-previous-span.ts","../../src/selectors/selector.get-selected-spans.ts","../../src/selectors/selector.get-mark-state.ts","../../src/selectors/selector.get-active-decorators.ts","../../src/selectors/selector.get-trimmed-selection.ts","../../src/selectors/selector.get-active-annotations.ts","../../src/selectors/selector.get-active-list-item.ts","../../src/selectors/selector.get-active-style.ts","../../src/selectors/selector.get-next-inline-object.ts","../../src/selectors/selector.get-caret-word-selection.ts","../../src/selectors/selector.get-first-block.ts","../../src/selectors/selector.get-focus-block-object.ts","../../src/selectors/selector.get-focus-list-block.ts","../../src/selectors/selector.get-last-block.ts","../../src/selectors/selector.get-next-block.ts","../../src/selectors/selector.get-previous-block.ts","../../src/selectors/selector.get-selected-text-blocks.ts","../../src/selectors/selector.get-active-annotation-marks.ts","../../src/selectors/selector.is-active-annotation.ts","../../src/selectors/selector.is-active-decorator.ts","../../src/selectors/selector.is-active-list-item.ts","../../src/selectors/selector.is-active-style.ts","../../src/selectors/selector.is-at-the-end-of-block.ts","../../src/selectors/selector.is-at-the-start-of-block.ts"],"sourcesContent":["import {isPortableTextSpan, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getFocusInlineObject: EditorSelector<\n {node: PortableTextObject; path: ChildPath} | undefined\n> = (snapshot) => {\n const focusChild = getFocusChild(snapshot)\n\n return focusChild && !isPortableTextSpan(focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'\n\n/**\n * @public\n */\nexport const getSelectedBlocks: EditorSelector<\n Array<{node: PortableTextBlock; path: BlockPath}>\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedBlocks: Array<{node: PortableTextBlock; path: BlockPath}> = []\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n const startKey = getBlockKeyFromSelectionPoint(startPoint)\n const endKey = getBlockKeyFromSelectionPoint(endPoint)\n\n if (!startKey || !endKey) {\n return selectedBlocks\n }\n\n const startBlockIndex = snapshot.blockIndexMap.get(startKey)\n const endBlockIndex = snapshot.blockIndexMap.get(endKey)\n\n if (startBlockIndex === undefined || endBlockIndex === undefined) {\n return selectedBlocks\n }\n\n const slicedValue = snapshot.context.value.slice(\n startBlockIndex,\n endBlockIndex + 1,\n )\n\n for (const block of slicedValue) {\n if (block._key === startKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n\n if (startKey === endKey) {\n break\n }\n continue\n }\n\n if (block._key === endKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n break\n }\n\n if (selectedBlocks.length > 0) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n }\n }\n\n return selectedBlocks\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * @public\n */\nexport const getSelectionEndBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: BlockPath\n }\n | undefined\n> = (snapshot) => {\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n\n if (!endPoint) {\n return undefined\n }\n\n return getFocusBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: endPoint,\n focus: endPoint,\n },\n },\n })\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * @public\n */\nexport const getSelectionStartBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: BlockPath\n }\n | undefined\n> = (snapshot) => {\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n\n if (!startPoint) {\n return undefined\n }\n\n return getFocusBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startPoint,\n focus: startPoint,\n },\n },\n })\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport const getSelectionEndPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n return snapshot.context.selection.backward\n ? snapshot.context.selection.anchor\n : snapshot.context.selection.focus\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../utils/util.selection-point'\n\n/**\n * @public\n */\nexport function isPointAfterSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n const endChildKey = getChildKeyFromSelectionPoint(endPoint)\n\n const pointBlockKey = getBlockKeyFromSelectionPoint(point)\n const pointChildKey = getChildKeyFromSelectionPoint(point)\n\n if (!pointBlockKey || !endBlockKey) {\n return false\n }\n\n const pointBlockIndex = snapshot.blockIndexMap.get(pointBlockKey)\n const endBlockIndex = snapshot.blockIndexMap.get(endBlockKey)\n\n if (pointBlockIndex === undefined || endBlockIndex === undefined) {\n return false\n }\n\n if (pointBlockIndex > endBlockIndex) {\n // The point block is after the end block.\n return true\n }\n\n if (pointBlockIndex < endBlockIndex) {\n // The point block is before the end block.\n return false\n }\n\n // The point block is the same as the end block.\n const pointBlock = snapshot.context.value.at(pointBlockIndex)\n\n if (!pointBlock) {\n // The point block is not in the value.\n return false\n }\n\n if (!isTextBlock(snapshot.context, pointBlock)) {\n // The point block is not a text block.\n // Since the point block is the same as the end block, the point is not\n // after the selection.\n return false\n }\n\n let pointChildIndex: number | undefined\n let endChildIndex: number | undefined\n\n let childIndex = -1\n\n // The point block is the same as the end block, so we need to find the\n // child indices and compare them.\n for (const child of pointBlock.children) {\n childIndex++\n\n if (child._key === pointChildKey && child._key === endChildKey) {\n return point.offset > endPoint.offset\n }\n\n if (child._key === pointChildKey) {\n pointChildIndex = childIndex\n }\n\n if (child._key === endChildKey) {\n endChildIndex = childIndex\n }\n\n if (pointChildIndex !== undefined && endChildIndex !== undefined) {\n break\n }\n }\n\n if (pointChildIndex === undefined || endChildIndex === undefined) {\n return false\n }\n\n return pointChildIndex > endChildIndex\n }\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../utils/util.selection-point'\n\n/**\n * @public\n */\nexport function isPointBeforeSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const startChildKey = getChildKeyFromSelectionPoint(startPoint)\n\n const pointBlockKey = getBlockKeyFromSelectionPoint(point)\n const pointChildKey = getChildKeyFromSelectionPoint(point)\n\n if (!pointBlockKey || !startBlockKey) {\n return false\n }\n\n const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey)\n const pointBlockIndex = snapshot.blockIndexMap.get(pointBlockKey)\n\n if (startBlockIndex === undefined || pointBlockIndex === undefined) {\n return false\n }\n\n if (pointBlockIndex < startBlockIndex) {\n // The point block is before the start block.\n return true\n }\n\n if (pointBlockIndex > startBlockIndex) {\n // The point block is after the start block.\n return false\n }\n\n // The point block is the same as the start block.\n const pointBlock = snapshot.context.value.at(pointBlockIndex)\n\n if (!pointBlock) {\n // The point block is not in the value.\n return false\n }\n\n if (!isTextBlock(snapshot.context, pointBlock)) {\n // The point block is not a text block.\n // Since the point block is the same as the start block, the point is not\n // before the selection.\n return false\n }\n\n let pointChildIndex: number | undefined\n let startChildIndex: number | undefined\n\n let childIndex = -1\n\n // The point block is the same as the start block, so we need to find the\n // child indices and compare them.\n for (const child of pointBlock.children) {\n childIndex++\n\n if (child._key === pointChildKey && child._key === startChildKey) {\n return point.offset < startPoint.offset\n }\n\n if (child._key === pointChildKey) {\n pointChildIndex = childIndex\n }\n\n if (child._key === startChildKey) {\n startChildIndex = childIndex\n }\n\n if (pointChildIndex !== undefined && startChildIndex !== undefined) {\n break\n }\n }\n\n if (pointChildIndex === undefined || startChildIndex === undefined) {\n return false\n }\n\n return pointChildIndex < startChildIndex\n }\n}\n","import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from '../utils/util.is-equal-selection-points'\nimport type {EditorSelector} from './../editor/editor-selector'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\nimport {isPointAfterSelection} from './selector.is-point-after-selection'\nimport {isPointBeforeSelection} from './selector.is-point-before-selection'\n\n/**\n * @public\n */\nexport function isOverlappingSelection(\n selection: EditorSelection,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!selection || !snapshot.context.selection) {\n return false\n }\n\n const selectionStartPoint = getSelectionStartPoint({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n const selectionEndPoint = getSelectionEndPoint({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n const originalSelectionStartPoint = getSelectionStartPoint(snapshot)\n const originalSelectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (\n !selectionStartPoint ||\n !selectionEndPoint ||\n !originalSelectionStartPoint ||\n !originalSelectionEndPoint\n ) {\n return false\n }\n\n const startPointEqualToOriginalStartPoint = isEqualSelectionPoints(\n selectionStartPoint,\n originalSelectionStartPoint,\n )\n const endPointEqualToOriginalEndPoint = isEqualSelectionPoints(\n selectionEndPoint,\n originalSelectionEndPoint,\n )\n\n if (\n startPointEqualToOriginalStartPoint &&\n endPointEqualToOriginalEndPoint\n ) {\n return true\n }\n\n const startPointBeforeSelection =\n isPointBeforeSelection(selectionStartPoint)(snapshot)\n const startPointAfterSelection =\n isPointAfterSelection(selectionStartPoint)(snapshot)\n const endPointBeforeSelection =\n isPointBeforeSelection(selectionEndPoint)(snapshot)\n const endPointAfterSelection =\n isPointAfterSelection(selectionEndPoint)(snapshot)\n\n const originalStartPointBeforeStartPoint = isPointBeforeSelection(\n originalSelectionStartPoint,\n )({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: selectionStartPoint,\n focus: selectionStartPoint,\n },\n },\n })\n const originalStartPointAfterStartPoint = isPointAfterSelection(\n originalSelectionStartPoint,\n )({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: selectionStartPoint,\n focus: selectionStartPoint,\n },\n },\n })\n\n const originalEndPointBeforeEndPoint = isPointBeforeSelection(\n originalSelectionEndPoint,\n )({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: selectionEndPoint,\n focus: selectionEndPoint,\n },\n },\n })\n const originalEndPointAfterEndPoint = isPointAfterSelection(\n originalSelectionEndPoint,\n )({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: selectionEndPoint,\n focus: selectionEndPoint,\n },\n },\n })\n\n const startPointEqualToOriginalEndPoint = isEqualSelectionPoints(\n selectionStartPoint,\n originalSelectionEndPoint,\n )\n const endPointEqualToOriginalStartPoint = isEqualSelectionPoints(\n selectionEndPoint,\n originalSelectionStartPoint,\n )\n\n // If all checks fail then we can deduce that the selection does not exist\n // and there doesn't overlap with the snapshot selection\n if (\n !endPointEqualToOriginalStartPoint &&\n !startPointEqualToOriginalEndPoint &&\n !originalStartPointBeforeStartPoint &&\n !originalStartPointAfterStartPoint &&\n !originalEndPointBeforeEndPoint &&\n !originalEndPointAfterEndPoint\n ) {\n return false\n }\n\n if (endPointBeforeSelection && !endPointEqualToOriginalStartPoint) {\n return false\n }\n\n if (startPointAfterSelection && !startPointEqualToOriginalEndPoint) {\n return false\n }\n\n if (\n !originalStartPointBeforeStartPoint &&\n originalStartPointAfterStartPoint &&\n !originalEndPointBeforeEndPoint &&\n originalEndPointAfterEndPoint\n ) {\n return !endPointEqualToOriginalStartPoint\n }\n\n if (\n originalStartPointBeforeStartPoint &&\n !originalStartPointAfterStartPoint &&\n originalEndPointBeforeEndPoint &&\n !originalEndPointAfterEndPoint\n ) {\n return !startPointEqualToOriginalEndPoint\n }\n\n if (\n !startPointAfterSelection ||\n !startPointBeforeSelection ||\n !endPointAfterSelection ||\n !endPointBeforeSelection\n ) {\n return true\n }\n\n return false\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockEndPoint} from '../utils/util.get-block-end-point'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {isEqualSelectionPoints} from '../utils/util.is-equal-selection-points'\nimport {getSelectionEndBlock} from './selector.get-selection-end-block'\nimport {getSelectionStartBlock} from './selector.get-selection-start-block'\n\n/**\n * @public\n */\nexport const isSelectingEntireBlocks: EditorSelector<boolean> = (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const startPoint = snapshot.context.selection.backward\n ? snapshot.context.selection.focus\n : snapshot.context.selection.anchor\n const endPoint = snapshot.context.selection.backward\n ? snapshot.context.selection.anchor\n : snapshot.context.selection.focus\n\n const startBlock = getSelectionStartBlock(snapshot)\n const endBlock = getSelectionEndBlock(snapshot)\n\n if (!startBlock || !endBlock) {\n return false\n }\n\n const startBlockStartPoint = getBlockStartPoint({\n context: snapshot.context,\n block: startBlock,\n })\n const endBlockEndPoint = getBlockEndPoint({\n context: snapshot.context,\n block: endBlock,\n })\n\n return (\n isEqualSelectionPoints(startBlockStartPoint, startPoint) &&\n isEqualSelectionPoints(endBlockEndPoint, endPoint)\n )\n}\n","import type {Path} from '@sanity/types'\n\n/**\n * @public\n */\nexport type BlockPath = [{_key: string}]\n\n/**\n * @public\n */\nexport function isBlockPath(path: Path): path is BlockPath {\n const firstSegment = path.at(0)\n\n return (\n path.length === 1 &&\n firstSegment !== undefined &&\n isRecord(firstSegment) &&\n '_key' in firstSegment &&\n typeof firstSegment._key === 'string'\n )\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && (typeof value === 'object' || typeof value === 'function')\n}\n\n/**\n * @public\n */\nexport type AnnotationPath = [{_key: string}, 'markDefs', {_key: string}]\n\n/**\n * @public\n */\nexport type ChildPath = [{_key: string}, 'children', {_key: string}]\n","import type {EditorSelection} from '../types/editor'\nimport {isSelectionCollapsed} from './util.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isSelectionExpanded(selection: EditorSelection) {\n if (!selection) {\n return false\n }\n\n return !isSelectionCollapsed(selection)\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {KeyedSegment, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildKeyFromSelectionPoint} from '../utils/util.selection-point'\nimport {getSelectionEndBlock} from './selector.get-selection-end-block'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\n\n/**\n * @public\n */\nexport const getNextSpan: EditorSelector<\n | {\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const selectionEndBlock = getSelectionEndBlock(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionEndBlock || !selectionEndPoint) {\n return undefined\n }\n\n if (!isTextBlock(snapshot.context, selectionEndBlock.node)) {\n return undefined\n }\n\n const selectionEndPointChildKey =\n getChildKeyFromSelectionPoint(selectionEndPoint)\n\n let endPointChildFound = false\n let nextSpan:\n | {\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n\n for (const child of selectionEndBlock.node.children) {\n if (child._key === selectionEndPointChildKey) {\n endPointChildFound = true\n continue\n }\n\n if (isSpan(snapshot.context, child) && endPointChildFound) {\n nextSpan = {\n node: child,\n path: [...selectionEndBlock.path, 'children', {_key: child._key}],\n }\n break\n }\n }\n\n return nextSpan\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {KeyedSegment, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildKeyFromSelectionPoint} from '../utils/util.selection-point'\nimport {getSelectionStartBlock} from './selector.get-selection-start-block'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getPreviousSpan: EditorSelector<\n | {\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n const selectionStartBlock = getSelectionStartBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n\n if (!selectionStartBlock || !selectionStartPoint) {\n return undefined\n }\n\n if (!isTextBlock(snapshot.context, selectionStartBlock.node)) {\n return undefined\n }\n\n const selectionStartPointChildKey =\n getChildKeyFromSelectionPoint(selectionStartPoint)\n\n let previousSpan:\n | {\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n\n for (const child of selectionStartBlock.node.children) {\n if (child._key === selectionStartPointChildKey) {\n break\n }\n\n if (isSpan(snapshot.context, child)) {\n previousSpan = {\n node: child,\n path: [...selectionStartBlock.path, 'children', {_key: child._key}],\n }\n }\n }\n\n return previousSpan\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../utils/util.selection-point'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getSelectedSpans: EditorSelector<\n Array<{\n node: PortableTextSpan\n path: ChildPath\n }>\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedSpans: Array<{\n node: PortableTextSpan\n path: ChildPath\n }> = []\n\n const startPoint = getSelectionStartPoint(snapshot)\n const endPoint = getSelectionEndPoint(snapshot)\n\n if (!startPoint || !endPoint) {\n return selectedSpans\n }\n\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n const startSpanKey = getChildKeyFromSelectionPoint(startPoint)\n const endSpanKey = getChildKeyFromSelectionPoint(endPoint)\n\n if (!startBlockKey || !endBlockKey) {\n return selectedSpans\n }\n\n const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey)\n const endBlockIndex = snapshot.blockIndexMap.get(endBlockKey)\n\n if (startBlockIndex === undefined || endBlockIndex === undefined) {\n return selectedSpans\n }\n\n const slicedValue = snapshot.context.value.slice(\n startBlockIndex,\n endBlockIndex + 1,\n )\n\n let startBlockFound = false\n\n for (const block of slicedValue) {\n if (block._key === startBlockKey) {\n startBlockFound = true\n }\n\n if (!isTextBlock(snapshot.context, block)) {\n continue\n }\n\n if (block._key === startBlockKey) {\n for (const child of block.children) {\n if (!isSpan(snapshot.context, child)) {\n continue\n }\n\n if (startSpanKey && child._key === startSpanKey) {\n if (startPoint.offset < child.text.length) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n\n if (startSpanKey === endSpanKey) {\n break\n }\n\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n if (endPoint.offset > 0) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n break\n }\n\n if (selectedSpans.length > 0) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n\n continue\n }\n\n if (block._key === endBlockKey) {\n for (const child of block.children) {\n if (!isSpan(snapshot.context, child)) {\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n if (endPoint.offset > 0) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n break\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n\n break\n }\n\n if (startBlockFound) {\n for (const child of block.children) {\n if (!isSpan(snapshot.context, child)) {\n continue\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n }\n\n return selectedSpans\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isBlockPath} from '../types/paths'\nimport {blockOffsetToSpanSelectionPoint} from '../utils/util.block-offset'\nimport {isSelectionExpanded} from '../utils/util.is-selection-expanded'\nimport {getFocusSpan} from './selector.get-focus-span'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getNextSpan} from './selector.get-next-span'\nimport {getPreviousSpan} from './selector.get-previous-span'\nimport {getSelectedSpans} from './selector.get-selected-spans'\n\n/**\n * @beta\n */\nexport type MarkState =\n | {\n state: 'unchanged'\n marks: Array<string>\n }\n | {\n state: 'changed'\n marks: Array<string>\n previousMarks: Array<string>\n }\n\n/**\n * Given that text is inserted at the current position, what marks should\n * be applied?\n * @beta\n */\nexport const getMarkState: EditorSelector<MarkState | undefined> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n let selection = snapshot.context.selection\n const focusTextBlock = getFocusTextBlock(snapshot)\n\n if (!focusTextBlock) {\n return undefined\n }\n\n if (isBlockPath(selection.anchor.path)) {\n const spanSelectionPoint = blockOffsetToSpanSelectionPoint({\n context: snapshot.context,\n blockOffset: {\n path: selection.anchor.path,\n offset: selection.anchor.offset,\n },\n direction: selection.backward ? 'backward' : 'forward',\n })\n\n selection = spanSelectionPoint\n ? {\n ...selection,\n anchor: spanSelectionPoint,\n }\n : selection\n }\n\n if (isBlockPath(selection.focus.path)) {\n const spanSelectionPoint = blockOffsetToSpanSelectionPoint({\n context: snapshot.context,\n blockOffset: {\n path: selection.focus.path,\n offset: selection.focus.offset,\n },\n direction: selection.backward ? 'backward' : 'forward',\n })\n\n selection = spanSelectionPoint\n ? {\n ...selection,\n focus: spanSelectionPoint,\n }\n : selection\n }\n\n const focusSpan = getFocusSpan({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!focusSpan) {\n return undefined\n }\n\n if (isSelectionExpanded(selection)) {\n const selectedSpans = getSelectedSpans({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n let index = 0\n let marks: Array<string> = []\n\n for (const span of selectedSpans) {\n if (index === 0) {\n marks = span.node.marks ?? []\n } else {\n if (span.node.marks?.length === 0) {\n marks = []\n continue\n }\n\n marks = marks.filter((mark) =>\n (span.node.marks ?? []).some((spanMark) => spanMark === mark),\n )\n }\n\n index++\n }\n\n return {\n state: 'unchanged',\n marks,\n }\n }\n\n const decorators = snapshot.context.schema.decorators.map(\n (decorator) => decorator.name,\n )\n const marks = focusSpan.node.marks ?? []\n const marksWithoutAnnotations = marks.filter((mark) =>\n decorators.includes(mark),\n )\n\n const spanHasAnnotations = marks.length > marksWithoutAnnotations.length\n\n const spanIsEmpty = focusSpan.node.text.length === 0\n\n const atTheBeginningOfSpan = snapshot.context.selection.anchor.offset === 0\n const atTheEndOfSpan =\n snapshot.context.selection.anchor.offset === focusSpan.node.text.length\n\n const previousSpan = getPreviousSpan({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n const nextSpan = getNextSpan({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n const nextSpanAnnotations =\n nextSpan?.node?.marks?.filter((mark) => !decorators.includes(mark)) ?? []\n const spanAnnotations = marks.filter((mark) => !decorators.includes(mark))\n\n const previousSpanHasAnnotations = previousSpan\n ? previousSpan.node.marks?.some((mark) => !decorators.includes(mark))\n : false\n const previousSpanHasSameAnnotations = previousSpan\n ? previousSpan.node.marks\n ?.filter((mark) => !decorators.includes(mark))\n .every((mark) => marks.includes(mark))\n : false\n const previousSpanHasSameAnnotation = previousSpan\n ? previousSpan.node.marks?.some(\n (mark) => !decorators.includes(mark) && marks.includes(mark),\n )\n : false\n\n const previousSpanHasSameMarks = previousSpan\n ? previousSpan.node.marks?.every((mark) => marks.includes(mark))\n : false\n const nextSpanSharesSomeAnnotations = spanAnnotations.some((mark) =>\n nextSpanAnnotations?.includes(mark),\n )\n\n if (spanHasAnnotations && !spanIsEmpty) {\n if (atTheBeginningOfSpan) {\n if (previousSpanHasSameMarks) {\n return {\n state: 'changed',\n previousMarks: marks,\n marks: previousSpan?.node.marks ?? [],\n }\n } else if (previousSpanHasSameAnnotations) {\n return {\n state: 'changed',\n previousMarks: marks,\n marks: previousSpan?.node.marks ?? [],\n }\n } else if (previousSpanHasSameAnnotation) {\n return {\n state: 'unchanged',\n previousMarks: marks,\n marks: focusSpan.node.marks ?? [],\n }\n } else if (!previousSpan) {\n return {\n state: 'changed',\n previousMarks: marks,\n marks: [],\n }\n }\n }\n\n if (atTheEndOfSpan) {\n if (\n (nextSpan &&\n nextSpanSharesSomeAnnotations &&\n nextSpanAnnotations.length < spanAnnotations.length) ||\n !nextSpanSharesSomeAnnotations\n ) {\n return {\n state: 'changed',\n previousMarks: marks,\n marks: nextSpan?.node.marks ?? [],\n }\n }\n\n if (!nextSpan) {\n return {\n state: 'changed',\n previousMarks: marks,\n marks: [],\n }\n }\n }\n }\n\n if (atTheBeginningOfSpan && !spanIsEmpty && !!previousSpan) {\n if (previousSpanHasAnnotations) {\n return {\n state: 'changed',\n marks,\n previousMarks: previousSpan?.node.marks ?? [],\n }\n } else {\n return {\n state: 'changed',\n previousMarks: marks,\n marks: (previousSpan?.node.marks ?? []).filter((mark) =>\n decorators.includes(mark),\n ),\n }\n }\n }\n\n return {\n state: 'unchanged',\n marks,\n }\n}\n","import type {EditorSnapshot} from '../editor/editor-snapshot'\nimport {getMarkState} from './selector.get-mark-state'\n\nexport function getActiveDecorators(snapshot: EditorSnapshot) {\n const schema = snapshot.context.schema\n const decoratorState = snapshot.decoratorState\n const markState = getMarkState(snapshot)\n const decorators = schema.decorators.map((decorator) => decorator.name)\n\n const markStateDecorators = (markState?.marks ?? []).filter((mark) =>\n decorators.includes(mark),\n )\n\n let activeDecorators: Array<string> = markStateDecorators\n\n for (const decorator in decoratorState) {\n if (decoratorState[decorator] === false) {\n activeDecorators = activeDecorators.filter(\n (activeDecorator) => activeDecorator !== decorator,\n )\n } else if (decoratorState[decorator] === true) {\n if (!activeDecorators.includes(decorator)) {\n activeDecorators.push(decorator)\n }\n }\n }\n\n return activeDecorators\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelection, EditorSelectionPoint} from '../types/editor'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {isEmptyTextBlock} from '../utils/util.is-empty-text-block'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../utils/util.selection-point'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport const getTrimmedSelection: EditorSelector<EditorSelection> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return snapshot.context.selection\n }\n\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const startChildKey = getChildKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n const endChildKey = getChildKeyFromSelectionPoint(endPoint)\n\n if (!startBlockKey || !endBlockKey) {\n return snapshot.context.selection\n }\n\n const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey)\n const endBlockIndex = snapshot.blockIndexMap.get(endBlockKey)\n\n if (startBlockIndex === undefined || endBlockIndex === undefined) {\n return snapshot.context.selection\n }\n\n const slicedValue = snapshot.context.value.slice(\n startBlockIndex,\n endBlockIndex + 1,\n )\n\n let startBlockFound = false\n let adjustedStartPoint: EditorSelectionPoint | undefined\n let trimStartPoint = false\n let adjustedEndPoint: EditorSelectionPoint | undefined\n let trimEndPoint = false\n let previousPotentialEndpoint:\n | {blockKey: string; span: PortableTextSpan}\n | undefined\n\n for (const block of slicedValue) {\n if (block._key === startBlockKey) {\n startBlockFound = true\n\n if (\n isTextBlock(snapshot.context, block) &&\n isEmptyTextBlock(snapshot.context, block)\n ) {\n continue\n }\n }\n\n if (!startBlockFound) {\n continue\n }\n\n if (!isTextBlock(snapshot.context, block)) {\n continue\n }\n\n if (\n block._key === endBlockKey &&\n isEmptyTextBlock(snapshot.context, block)\n ) {\n break\n }\n\n for (const child of block.children) {\n if (child._key === endChildKey) {\n if (!isSpan(snapshot.context, child) || endPoint.offset === 0) {\n adjustedEndPoint = previousPotentialEndpoint\n ? {\n path: [\n {_key: previousPotentialEndpoint.blockKey},\n 'children',\n {_key: previousPotentialEndpoint.span._key},\n ],\n offset: previousPotentialEndpoint.span.text.length,\n }\n : undefined\n\n trimEndPoint = true\n break\n }\n }\n\n if (trimStartPoint) {\n const lonelySpan =\n isSpan(snapshot.context, child) && block.children.length === 1\n\n if (\n (isSpan(snapshot.context, child) && child.text.length > 0) ||\n lonelySpan\n ) {\n adjustedStartPoint = {\n path: [{_key: block._key}, 'children', {_key: child._key}],\n offset: 0,\n }\n previousPotentialEndpoint = {blockKey: block._key, span: child}\n trimStartPoint = false\n }\n\n continue\n }\n\n if (child._key === startChildKey) {\n if (!isSpan(snapshot.context, child)) {\n trimStartPoint = true\n continue\n }\n\n if (startPoint.offset === child.text.length) {\n trimStartPoint = true\n previousPotentialEndpoint =\n child.text.length > 0\n ? {blockKey: block._key, span: child}\n : previousPotentialEndpoint\n continue\n }\n }\n\n previousPotentialEndpoint =\n isSpan(snapshot.context, child) && child.text.length > 0\n ? {blockKey: block._key, span: child}\n : previousPotentialEndpoint\n }\n\n if (block._key === endBlockKey) {\n break\n }\n }\n\n const trimmedSelection = snapshot.context.selection.backward\n ? {\n anchor: trimEndPoint && adjustedEndPoint ? adjustedEndPoint : endPoint,\n focus: adjustedStartPoint ?? startPoint,\n backward: true,\n }\n : {\n anchor: adjustedStartPoint ?? startPoint,\n focus: trimEndPoint && adjustedEndPoint ? adjustedEndPoint : endPoint,\n }\n\n if (\n isSelectionCollapsed({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: trimmedSelection,\n },\n })\n ) {\n const focusTextBlock = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: trimmedSelection,\n },\n })\n\n if (\n focusTextBlock &&\n !isEmptyTextBlock(snapshot.context, focusTextBlock.node)\n ) {\n return null\n }\n }\n\n return trimmedSelection\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getMarkState} from './selector.get-mark-state'\nimport {getSelectedBlocks} from './selector.get-selected-blocks'\n\n/**\n * @public\n */\nexport const getActiveAnnotations: EditorSelector<Array<PortableTextObject>> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const markState = getMarkState(snapshot)\n\n const activeAnnotations = (markState?.marks ?? []).filter(\n (mark) =>\n !snapshot.context.schema.decorators\n .map((decorator) => decorator.name)\n .includes(mark),\n )\n\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isTextBlock(snapshot.context, block.node)\n ? (block.node.markDefs ?? [])\n : [],\n )\n\n return selectionMarkDefs.filter((markDef) =>\n activeAnnotations.includes(markDef._key),\n )\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextListBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selector.get-selected-blocks'\n\n/**\n * @public\n */\nexport const getActiveListItem: EditorSelector<\n PortableTextListBlock['listItem'] | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter((block) =>\n isTextBlock(snapshot.context, block),\n )\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstListItem = firstTextBlock.listItem\n\n if (!firstListItem) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.listItem === firstListItem)) {\n return firstListItem\n }\n\n return undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selector.get-selected-blocks'\n\n/**\n * @public\n */\nexport const getActiveStyle: EditorSelector<PortableTextTextBlock['style']> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter((block) =>\n isTextBlock(snapshot.context, block),\n )\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstStyle = firstTextBlock.style\n\n if (!firstStyle) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.style === firstStyle)) {\n return firstStyle\n }\n\n return undefined\n}\n","import {isSpan} from '@portabletext/schema'\nimport {isKeySegment, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\n\n/**\n * @public\n */\nexport const getNextInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n const selectionEndPointChildKey =\n selectionEndPoint && isKeySegment(selectionEndPoint.path[2])\n ? selectionEndPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionEndPointChildKey) {\n return undefined\n }\n\n let endPointChildFound = false\n let inlineObject:\n | {\n node: PortableTextObject\n path: ChildPath\n }\n | undefined\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionEndPointChildKey) {\n endPointChildFound = true\n continue\n }\n\n if (!isSpan(snapshot.context, child) && endPointChildFound) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n break\n }\n }\n\n return inlineObject\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelection} from '../types/editor'\nimport {\n blockOffsetToSpanSelectionPoint,\n spanSelectionPointToBlockOffset,\n} from '../utils/util.block-offset'\nimport {getBlockEndPoint} from '../utils/util.get-block-end-point'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getNextInlineObject} from './selector.get-next-inline-object'\nimport {getPreviousInlineObject} from './selector.get-previous-inline-object'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\nimport {getSelectionText} from './selector.get-selection-text'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\n\n/**\n * @public\n * Returns the selection of the of the word the caret is placed in.\n * Note: Only returns a word selection if the current selection is collapsed\n */\nexport const getCaretWordSelection: EditorSelector<EditorSelection> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return null\n }\n\n if (!isSelectionCollapsed(snapshot)) {\n return null\n }\n\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartOffset = selectionStartPoint\n ? spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n : undefined\n\n if (!focusTextBlock || !selectionStartPoint || !selectionStartOffset) {\n return null\n }\n\n const previousInlineObject = getPreviousInlineObject(snapshot)\n const blockStartPoint = getBlockStartPoint({\n context: snapshot.context,\n block: focusTextBlock,\n })\n const textBefore = getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: previousInlineObject\n ? {path: previousInlineObject.path, offset: 0}\n : blockStartPoint,\n focus: selectionStartPoint,\n },\n },\n })\n const textDirectlyBefore = textBefore.split(/\\s+/).at(-1)\n\n const nextInlineObject = getNextInlineObject(snapshot)\n const blockEndPoint = getBlockEndPoint({\n context: snapshot.context,\n block: focusTextBlock,\n })\n const textAfter = getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: selectionStartPoint,\n focus: nextInlineObject\n ? {path: nextInlineObject.path, offset: 0}\n : blockEndPoint,\n },\n },\n })\n const textDirectlyAfter = textAfter.split(/\\s+/).at(0)\n\n if (\n (textDirectlyBefore === undefined || textDirectlyBefore === '') &&\n (textDirectlyAfter === undefined || textDirectlyAfter === '')\n ) {\n return null\n }\n\n const caretWordStartOffset: BlockOffset = textDirectlyBefore\n ? {\n ...selectionStartOffset,\n offset: selectionStartOffset.offset - textDirectlyBefore.length,\n }\n : selectionStartOffset\n const caretWordEndOffset: BlockOffset = textDirectlyAfter\n ? {\n ...selectionStartOffset,\n offset: selectionStartOffset.offset + textDirectlyAfter.length,\n }\n : selectionStartOffset\n\n const caretWordStartSelectionPoint = blockOffsetToSpanSelectionPoint({\n context: snapshot.context,\n blockOffset: caretWordStartOffset,\n direction: 'backward',\n })\n const caretWordEndSelectionPoint = blockOffsetToSpanSelectionPoint({\n context: snapshot.context,\n blockOffset: caretWordEndOffset,\n direction: 'forward',\n })\n\n if (!caretWordStartSelectionPoint || !caretWordEndSelectionPoint) {\n return null\n }\n\n const caretWordSelection = {\n anchor: caretWordStartSelectionPoint,\n focus: caretWordEndSelectionPoint,\n }\n\n return isSelectionExpanded({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: caretWordSelection,\n },\n })\n ? caretWordSelection\n : null\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport const getFirstBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const node = snapshot.context.value[0]\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * @public\n */\nexport const getFocusBlockObject: EditorSelector<\n {node: PortableTextObject; path: BlockPath} | undefined\n> = (snapshot) => {\n const focusBlock = getFocusBlock(snapshot)\n\n return focusBlock && !isTextBlock(snapshot.context, focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n","import type {PortableTextListBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {isListBlock} from '../utils/parse-blocks'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * @public\n */\nexport const getFocusListBlock: EditorSelector<\n {node: PortableTextListBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n\n return focusTextBlock && isListBlock(snapshot.context, focusTextBlock.node)\n ? {node: focusTextBlock.node, path: focusTextBlock.path}\n : undefined\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport const getLastBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const node = snapshot.context.value[snapshot.context.value.length - 1]\n ? snapshot.context.value[snapshot.context.value.length - 1]\n : undefined\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionEndBlock} from './selector.get-selection-end-block'\n\n/**\n * @public\n */\nexport const getNextBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const selectionEndBlock = getSelectionEndBlock(snapshot)\n\n if (!selectionEndBlock) {\n return undefined\n }\n\n const index = snapshot.blockIndexMap.get(selectionEndBlock.node._key)\n\n if (index === undefined || index === snapshot.context.value.length - 1) {\n return undefined\n }\n\n const nextBlock = snapshot.context.value.at(index + 1)\n\n return nextBlock\n ? {node: nextBlock, path: [{_key: nextBlock._key}]}\n : undefined\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionStartBlock} from './selector.get-selection-start-block'\n\n/**\n * @public\n */\nexport const getPreviousBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const selectionStartBlock = getSelectionStartBlock(snapshot)\n\n if (!selectionStartBlock) {\n return undefined\n }\n\n const index = snapshot.blockIndexMap.get(selectionStartBlock.node._key)\n\n if (index === undefined || index === 0) {\n return undefined\n }\n\n const previousBlock = snapshot.context.value.at(index - 1)\n\n return previousBlock\n ? {node: previousBlock, path: [{_key: previousBlock._key}]}\n : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'\n\n/**\n * @public\n */\nexport const getSelectedTextBlocks: EditorSelector<\n Array<{node: PortableTextTextBlock; path: BlockPath}>\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedTextBlocks: Array<{\n node: PortableTextTextBlock\n path: BlockPath\n }> = []\n\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n\n if (!startBlockKey || !endBlockKey) {\n return selectedTextBlocks\n }\n\n const startBlockIndex = snapshot.blockIndexMap.get(startBlockKey)\n const endBlockIndex = snapshot.blockIndexMap.get(endBlockKey)\n\n if (startBlockIndex === undefined || endBlockIndex === undefined) {\n return selectedTextBlocks\n }\n\n const slicedValue = snapshot.context.value.slice(\n startBlockIndex,\n endBlockIndex + 1,\n )\n\n for (const block of slicedValue) {\n if (block._key === startBlockKey) {\n if (isTextBlock(snapshot.context, block)) {\n selectedTextBlocks.push({node: block, path: [{_key: block._key}]})\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n continue\n }\n\n if (block._key === endBlockKey) {\n if (isTextBlock(snapshot.context, block)) {\n selectedTextBlocks.push({node: block, path: [{_key: block._key}]})\n }\n\n break\n }\n\n if (selectedTextBlocks.length > 0) {\n if (isTextBlock(snapshot.context, block)) {\n selectedTextBlocks.push({node: block, path: [{_key: block._key}]})\n }\n }\n }\n\n return selectedTextBlocks\n}\n","import type {EditorSnapshot} from '../editor/editor-snapshot'\nimport {getMarkState} from './selector.get-mark-state'\n\nexport function getActiveAnnotationsMarks(snapshot: EditorSnapshot) {\n const schema = snapshot.context.schema\n const markState = getMarkState(snapshot)\n\n return (markState?.marks ?? []).filter(\n (mark) =>\n !schema.decorators.map((decorator) => decorator.name).includes(mark),\n )\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveAnnotationsMarks} from './selector.get-active-annotation-marks'\nimport {getSelectedBlocks} from './selector.get-selected-blocks'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * Check whether an annotation is active in the given `snapshot`.\n *\n * @public\n */\nexport function isActiveAnnotation(\n annotation: string,\n options?: {\n /**\n * Choose whether the annotation has to take up the entire selection in the\n * `snapshot` or if the annotation can be partially selected.\n *\n * Defaults to 'full'\n */\n mode?: 'partial' | 'full'\n },\n): EditorSelector<boolean> {\n return (snapshot) => {\n const mode = options?.mode ?? 'full'\n\n if (mode === 'partial') {\n const selectedValue = getSelectedValue(snapshot)\n\n const selectionMarkDefs = selectedValue.flatMap((block) =>\n isTextBlock(snapshot.context, block) ? (block.markDefs ?? []) : [],\n )\n\n return selectionMarkDefs.some((markDef) => markDef._type === annotation)\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isTextBlock(snapshot.context, block.node)\n ? (block.node.markDefs ?? [])\n : [],\n )\n const activeAnnotations = getActiveAnnotationsMarks(snapshot)\n const activeMarkDefs = selectionMarkDefs.filter(\n (markDef) =>\n markDef._type === annotation &&\n activeAnnotations.includes(markDef._key),\n )\n\n return activeMarkDefs.length > 0\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveDecorators} from './selector.get-active-decorators'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\n\n/**\n * @public\n */\nexport function isActiveDecorator(decorator: string): EditorSelector<boolean> {\n return (snapshot) => {\n if (isSelectionExpanded(snapshot)) {\n const selectedSpans = getSelectedSpans(snapshot)\n\n return (\n selectedSpans.length > 0 &&\n selectedSpans.every((span) => span.node.marks?.includes(decorator))\n )\n }\n\n const activeDecorators = getActiveDecorators(snapshot)\n\n return activeDecorators.includes(decorator)\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveListItem} from './selector.get-active-list-item'\n\n/**\n * @public\n */\nexport function isActiveListItem(listItem: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeListItem = getActiveListItem(snapshot)\n\n return activeListItem === listItem\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveStyle} from './selector.get-active-style'\n\n/**\n * @public\n */\nexport function isActiveStyle(style: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeStyle = getActiveStyle(snapshot)\n\n return activeStyle === style\n }\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getBlockEndPoint} from '../utils/util.get-block-end-point'\nimport {isEqualSelectionPoints} from '../utils/util.is-equal-selection-points'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isAtTheEndOfBlock(block: {\n node: PortableTextBlock\n path: BlockPath\n}): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection || !isSelectionCollapsed(snapshot)) {\n return false\n }\n\n const blockEndPoint = getBlockEndPoint({\n context: snapshot.context,\n block,\n })\n\n return isEqualSelectionPoints(\n snapshot.context.selection.focus,\n blockEndPoint,\n )\n }\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {isEqualSelectionPoints} from '../utils/util.is-equal-selection-points'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isAtTheStartOfBlock(block: {\n node: PortableTextBlock\n path: BlockPath\n}): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection || !isSelectionCollapsed(snapshot)) {\n return false\n }\n\n const blockStartPoint = getBlockStartPoint({\n context: snapshot.context,\n block,\n })\n\n return isEqualSelectionPoints(\n snapshot.context.selection.focus,\n blockStartPoint,\n )\n }\n}\n"],"names":["getFocusInlineObject","snapshot","focusChild","getFocusChild","isPortableTextSpan","node","path","undefined","getSelectedBlocks","context","selection","selectedBlocks","startPoint","getSelectionStartPoint","endPoint","getSelectionEndPoint","startKey","getBlockKeyFromSelectionPoint","endKey","startBlockIndex","blockIndexMap","get","endBlockIndex","slicedValue","value","slice","block","_key","push","length","getSelectionEndBlock","getFocusBlock","anchor","focus","getSelectionStartBlock","backward","isPointAfterSelection","point","endBlockKey","endChildKey","getChildKeyFromSelectionPoint","pointBlockKey","pointChildKey","pointBlockIndex","pointBlock","at","isTextBlock","pointChildIndex","endChildIndex","childIndex","child","children","offset","isPointBeforeSelection","startBlockKey","startChildKey","startChildIndex","isOverlappingSelection","selectionStartPoint","selectionEndPoint","originalSelectionStartPoint","originalSelectionEndPoint","startPointEqualToOriginalStartPoint","isEqualSelectionPoints","endPointEqualToOriginalEndPoint","startPointBeforeSelection","startPointAfterSelection","endPointBeforeSelection","endPointAfterSelection","originalStartPointBeforeStartPoint","originalStartPointAfterStartPoint","originalEndPointBeforeEndPoint","originalEndPointAfterEndPoint","startPointEqualToOriginalEndPoint","endPointEqualToOriginalStartPoint","isSelectingEntireBlocks","startBlock","endBlock","startBlockStartPoint","getBlockStartPoint","endBlockEndPoint","getBlockEndPoint","isBlockPath","firstSegment","isRecord","isSelectionExpanded","isSelectionCollapsed","getNextSpan","selectionEndBlock","selectionEndPointChildKey","endPointChildFound","nextSpan","isSpan","getPreviousSpan","selectionStartBlock","selectionStartPointChildKey","previousSpan","getSelectedSpans","selectedSpans","startSpanKey","endSpanKey","startBlockFound","text","getMarkState","getFocusTextBlock","spanSelectionPoint","blockOffsetToSpanSelectionPoint","blockOffset","direction","focusSpan","getFocusSpan","index","marks","span","filter","mark","some","spanMark","state","decorators","schema","map","decorator","name","marksWithoutAnnotations","includes","spanHasAnnotations","spanIsEmpty","atTheBeginningOfSpan","atTheEndOfSpan","nextSpanAnnotations","spanAnnotations","previousSpanHasAnnotations","previousSpanHasSameAnnotations","every","previousSpanHasSameAnnotation","previousSpanHasSameMarks","nextSpanSharesSomeAnnotations","previousMarks","getActiveDecorators","decoratorState","markState","activeDecorators","activeDecorator","getTrimmedSelection","adjustedStartPoint","trimStartPoint","adjustedEndPoint","trimEndPoint","previousPotentialEndpoint","isEmptyTextBlock","blockKey","lonelySpan","trimmedSelection","focusTextBlock","getActiveAnnotations","activeAnnotations","flatMap","markDefs","markDef","getActiveListItem","selectedTextBlocks","firstTextBlock","firstListItem","listItem","getActiveStyle","firstStyle","style","getNextInlineObject","isKeySegment","inlineObject","getCaretWordSelection","selectionStartOffset","spanSelectionPointToBlockOffset","selectionPoint","previousInlineObject","getPreviousInlineObject","blockStartPoint","textDirectlyBefore","getSelectionText","split","nextInlineObject","blockEndPoint","textDirectlyAfter","caretWordStartOffset","caretWordEndOffset","caretWordStartSelectionPoint","caretWordEndSelectionPoint","caretWordSelection","getFirstBlock","getFocusBlockObject","focusBlock","getFocusListBlock","isListBlock","getLastBlock","getNextBlock","nextBlock","getPreviousBlock","previousBlock","getSelectedTextBlocks","getActiveAnnotationsMarks","isActiveAnnotation","annotation","options","mode","getSelectedValue","_type","selectionMarkDefs","isActiveDecorator","isActiveListItem","isActiveStyle","isAtTheEndOfBlock","isAtTheStartOfBlock"],"mappings":";;AAQO,MAAMA,uBAERC,CAAAA,aAAa;AAChB,QAAMC,aAAaC,0BAAAA,cAAcF,QAAQ;AAEzC,SAAOC,cAAc,CAACE,MAAAA,mBAAmBF,WAAWG,IAAI,IACpD;AAAA,IAACA,MAAMH,WAAWG;AAAAA,IAAMC,MAAMJ,WAAWI;AAAAA,EAAAA,IACzCC;AACN,GCNaC,oBAERP,CAAAA,aAAa;AAChB,MAAI,CAACA,SAASQ,QAAQC;AACpB,WAAO,CAAA;AAGT,QAAMC,iBAAoE,CAAA,GACpEC,aAAaC,sBAAAA,uBAAuBZ,SAASQ,QAAQC,SAAS,GAC9DI,WAAWC,sBAAAA,qBAAqBd,SAASQ,QAAQC,SAAS,GAC1DM,WAAWC,sBAAAA,8BAA8BL,UAAU,GACnDM,SAASD,sBAAAA,8BAA8BH,QAAQ;AAErD,MAAI,CAACE,YAAY,CAACE;AAChB,WAAOP;AAGT,QAAMQ,kBAAkBlB,SAASmB,cAAcC,IAAIL,QAAQ,GACrDM,gBAAgBrB,SAASmB,cAAcC,IAAIH,MAAM;AAEvD,MAAIC,oBAAoBZ,UAAae,kBAAkBf;AACrD,WAAOI;AAGT,QAAMY,cAActB,SAASQ,QAAQe,MAAMC,MACzCN,iBACAG,gBAAgB,CAClB;AAEA,aAAWI,SAASH,aAAa;AAC/B,QAAIG,MAAMC,SAASX,UAAU;AAG3B,UAFAL,eAAeiB,KAAK;AAAA,QAACvB,MAAMqB;AAAAA,QAAOpB,MAAM,CAAC;AAAA,UAACqB,MAAMD,MAAMC;AAAAA,QAAAA,CAAK;AAAA,MAA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,aAAa,CAAC4E,0BAAAA,qBAAqBrF,QAAQ;AAC/D,aAAO;AAGT,UAAMgL,kBAAkBlG,sBAAAA,mBAAmB;AAAA,MACzCtE,SAASR,SAASQ;AAAAA,MAClBiB;AAAAA,IAAAA,CACD;AAED,WAAOqC,sBAAAA,uBACL9D,SAASQ,QAAQC,UAAUuB,OAC3BgJ,eACF;AAAA,EACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -3563,6 +3563,10 @@ type ExtractNamespace<TType extends string> = TType extends `${infer Namespace}.
|
|
|
3563
3563
|
type EditorDom = {
|
|
3564
3564
|
getBlockNodes: (snapshot: EditorSnapshot) => Array<Node>;
|
|
3565
3565
|
getChildNodes: (snapshot: EditorSnapshot) => Array<Node>;
|
|
3566
|
+
getEditorElement: () => Element | undefined;
|
|
3567
|
+
getSelectionRect: (snapshot: EditorSnapshot) => DOMRect | null;
|
|
3568
|
+
getStartBlockElement: (snapshot: EditorSnapshot) => Element | null;
|
|
3569
|
+
getEndBlockElement: (snapshot: EditorSnapshot) => Element | null;
|
|
3566
3570
|
/**
|
|
3567
3571
|
* Let the Editor set the drag ghost. This is to be sure that it will get
|
|
3568
3572
|
* properly removed again when the drag ends.
|
|
@@ -3563,6 +3563,10 @@ type ExtractNamespace<TType extends string> = TType extends `${infer Namespace}.
|
|
|
3563
3563
|
type EditorDom = {
|
|
3564
3564
|
getBlockNodes: (snapshot: EditorSnapshot) => Array<Node>;
|
|
3565
3565
|
getChildNodes: (snapshot: EditorSnapshot) => Array<Node>;
|
|
3566
|
+
getEditorElement: () => Element | undefined;
|
|
3567
|
+
getSelectionRect: (snapshot: EditorSnapshot) => DOMRect | null;
|
|
3568
|
+
getStartBlockElement: (snapshot: EditorSnapshot) => Element | null;
|
|
3569
|
+
getEndBlockElement: (snapshot: EditorSnapshot) => Element | null;
|
|
3566
3570
|
/**
|
|
3567
3571
|
* Let the Editor set the drag ghost. This is to be sure that it will get
|
|
3568
3572
|
* properly removed again when the drag ends.
|