@portabletext/editor
Version:
Portable Text Editor made in React
107 lines (106 loc) • 4.32 kB
JavaScript
import { getActiveAnnotations, getActiveListItem, getActiveStyle, getSelectedSpans, getSelectedTextBlocks, getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isSelectingEntireBlocks } from "../_chunks-es/selector.is-selecting-entire-blocks.js";
import { isKeyedSegment, spanSelectionPointToBlockOffset } from "../_chunks-es/util.slice-blocks.js";
import { isPortableTextTextBlock, isPortableTextSpan } from "@sanity/types";
import { getSelectionStartPoint, getSelectionEndPoint } from "../_chunks-es/selector.is-overlapping-selection.js";
import { getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getNextBlock, getNextInlineObject, getPreviousBlock, getPreviousInlineObject, getSelectedBlocks, getSelectedSlice, getSelectionEndBlock, getSelectionStartBlock, getSelectionText, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-overlapping-selection.js";
import { getFocusInlineObject } from "../_chunks-es/selector.get-focus-inline-object.js";
import { getBlockTextBefore } from "../_chunks-es/selector.get-text-before.js";
const getAnchorBlock = (snapshot) => {
const key = snapshot.context.selection && isKeyedSegment(snapshot.context.selection.anchor.path[0]) ? snapshot.context.selection.anchor.path[0]._key : void 0, node = key ? snapshot.context.value.find((block) => block._key === key) : void 0;
return node && key ? {
node,
path: [{
_key: key
}]
} : void 0;
}, getAnchorTextBlock = (snapshot) => {
const anchorBlock = getAnchorBlock(snapshot);
return anchorBlock && isPortableTextTextBlock(anchorBlock.node) ? {
node: anchorBlock.node,
path: anchorBlock.path
} : void 0;
}, getAnchorChild = (snapshot) => {
const anchorBlock = getAnchorTextBlock(snapshot);
if (!anchorBlock)
return;
const key = snapshot.context.selection && isKeyedSegment(snapshot.context.selection.anchor.path[2]) ? snapshot.context.selection.anchor.path[2]._key : void 0, node = key ? anchorBlock.node.children.find((span) => span._key === key) : void 0;
return node && key ? {
node,
path: [...anchorBlock.path, "children", {
_key: key
}]
} : void 0;
}, getAnchorSpan = (snapshot) => {
const anchorChild = getAnchorChild(snapshot);
return anchorChild && isPortableTextSpan(anchorChild.node) ? {
node: anchorChild.node,
path: anchorChild.path
} : void 0;
}, getBlockOffsets = (snapshot) => {
if (!snapshot.context.selection)
return;
const selectionStartPoint = getSelectionStartPoint(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot);
if (!selectionStartPoint || !selectionEndPoint)
return;
const start = spanSelectionPointToBlockOffset({
value: snapshot.context.value,
selectionPoint: selectionStartPoint
}), end = spanSelectionPointToBlockOffset({
value: snapshot.context.value,
selectionPoint: selectionEndPoint
});
return start && end ? {
start,
end
} : void 0;
}, getSelection = (snapshot) => snapshot.context.selection, getValue = (snapshot) => snapshot.context.value;
export {
getActiveAnnotations,
getActiveListItem,
getActiveStyle,
getAnchorBlock,
getAnchorChild,
getAnchorSpan,
getAnchorTextBlock,
getBlockOffsets,
getBlockTextBefore,
getCaretWordSelection,
getFirstBlock,
getFocusBlock,
getFocusBlockObject,
getFocusChild,
getFocusInlineObject,
getFocusListBlock,
getFocusSpan,
getFocusTextBlock,
getLastBlock,
getNextBlock,
getNextInlineObject,
getPreviousBlock,
getPreviousInlineObject,
getSelectedBlocks,
getSelectedSlice,
getSelectedSpans,
getSelectedTextBlocks,
getSelection,
getSelectionEndBlock,
getSelectionEndPoint,
getSelectionStartBlock,
getSelectionStartPoint,
getSelectionText,
getTrimmedSelection,
getValue,
isActiveAnnotation,
isActiveDecorator,
isActiveListItem,
isActiveStyle,
isAtTheEndOfBlock,
isAtTheStartOfBlock,
isOverlappingSelection,
isPointAfterSelection,
isPointBeforeSelection,
isSelectingEntireBlocks,
isSelectionCollapsed,
isSelectionExpanded
};
//# sourceMappingURL=index.js.map