@portabletext/editor 2.13.6 → 2.13.7
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 +2 -2
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -1
- package/lib/_chunks-dts/behavior.types.action.d.ts +53 -53
- package/lib/_chunks-es/selector.is-active-style.js +2 -2
- package/lib/_chunks-es/selector.is-active-style.js.map +1 -1
- package/lib/index.cjs +0 -65
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +1 -66
- package/lib/index.js.map +1 -1
- package/package.json +3 -3
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +1 -118
- package/src/selectors/selector.get-mark-state.test.ts +63 -0
- package/src/selectors/selector.get-mark-state.ts +2 -2
|
@@ -470,8 +470,8 @@ const getNextSpan = (snapshot) => {
|
|
|
470
470
|
}
|
|
471
471
|
return atTheBeginningOfSpan && !spanIsEmpty && previousSpan ? previousSpanHasAnnotations ? {
|
|
472
472
|
state: "changed",
|
|
473
|
-
|
|
474
|
-
|
|
473
|
+
marks,
|
|
474
|
+
previousMarks: previousSpan?.node.marks ?? []
|
|
475
475
|
} : {
|
|
476
476
|
state: "changed",
|
|
477
477
|
previousMarks: marks,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selector.is-active-style.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-next-inline-object.ts","../../src/selectors/selector.get-caret-word-selection.ts","../../src/selectors/selector.get-active-annotation-marks.ts","../../src/selectors/selector.is-active-annotation.ts","../../src/selectors/selector.get-focus-block-object.ts","../../src/selectors/selector.get-next-block.ts","../../src/selectors/selector.get-previous-block.ts","../../src/selectors/selector.get-first-block.ts","../../src/selectors/selector.get-last-block.ts","../../src/selectors/selector.is-at-the-end-of-block.ts","../../src/selectors/selector.is-at-the-start-of-block.ts","../../src/selectors/selector.get-focus-list-block.ts","../../src/selectors/selector.is-active-decorator.ts","../../src/selectors/selector.get-active-annotations.ts","../../src/selectors/selector.get-selected-text-blocks.ts","../../src/selectors/selector.get-active-list-item.ts","../../src/selectors/selector.is-active-list-item.ts","../../src/selectors/selector.get-active-style.ts","../../src/selectors/selector.is-active-style.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 previousMarks: previousSpan.node.marks ?? [],\n 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 {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 {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 {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 {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 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 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 {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","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 {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 {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 {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 {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 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 {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 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"],"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","getNextInlineObject","isKeySegment","inlineObject","getCaretWordSelection","selectionStartOffset","spanSelectionPointToBlockOffset","selectionPoint","previousInlineObject","getPreviousInlineObject","blockStartPoint","textDirectlyBefore","getSelectionText","split","nextInlineObject","blockEndPoint","textDirectlyAfter","caretWordStartOffset","caretWordEndOffset","caretWordStartSelectionPoint","caretWordEndSelectionPoint","caretWordSelection","getActiveAnnotationsMarks","isActiveAnnotation","annotation","options","mode","getSelectedValue","flatMap","markDefs","markDef","_type","selectionMarkDefs","activeAnnotations","getFocusBlockObject","focusBlock","getNextBlock","nextBlock","getPreviousBlock","previousBlock","getFirstBlock","getLastBlock","isAtTheEndOfBlock","isAtTheStartOfBlock","getFocusListBlock","isListBlock","isActiveDecorator","getActiveAnnotations","getSelectedTextBlocks","selectedTextBlocks","getActiveListItem","firstTextBlock","firstListItem","listItem","isActiveListItem","getActiveStyle","firstStyle","style","isActiveStyle"],"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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BADiBnM,kBAAkBP,QAAQ,EAAEwH,IAAK/F,CAAAA,UAAUA,MAAMrB,IAAI,EAClC6G,OAAQxF,WAChDoB,OAAAA,YAAY7C,SAASQ,SAASiB,KAAK,CACrC,GAEMmL,iBAAiBF,mBAAmB9J,GAAG,CAAC;AAE9C,MAAI,CAACgK;AACH;AAGF,QAAMC,gBAAgBD,eAAeE;AAErC,MAAKD,iBAIDH,mBAAmBrE,MAAO5G,CAAAA,UAAUA,MAAMqL,aAAaD,aAAa;AACtE,WAAOA;AAIX;AC/BO,SAASE,iBAAiBD,UAA2C;AAC1E,SAAQ9M,CAAAA,aACiB2M,kBAAkB3M,QAAQ,MAEvB8M;AAE9B;ACJO,MAAME,iBACXhN,CAAAA,aACG;AACH,MAAI,CAACA,SAASQ,QAAQC;AACpB;AAIF,QAAMiM,qBADiBnM,kBAAkBP,QAAQ,EAAEwH,IAAK/F,CAAAA,UAAUA,MAAMrB,IAAI,EAClC6G,OAAQxF,WAChDoB,OAAAA,YAAY7C,SAASQ,SAASiB,KAAK,CACrC,GAEMmL,iBAAiBF,mBAAmB9J,GAAG,CAAC;AAE9C,MAAI,CAACgK;AACH;AAGF,QAAMK,aAAaL,eAAeM;AAElC,MAAKD,cAIDP,mBAAmBrE,MAAO5G,CAAAA,UAAUA,MAAMyL,UAAUD,UAAU;AAChE,WAAOA;AAIX;AC/BO,SAASE,cAAcD,OAAwC;AACpE,SAAQlN,CAAAA,aACcgN,eAAehN,QAAQ,MAEpBkN;AAE3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"selector.is-active-style.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-next-inline-object.ts","../../src/selectors/selector.get-caret-word-selection.ts","../../src/selectors/selector.get-active-annotation-marks.ts","../../src/selectors/selector.is-active-annotation.ts","../../src/selectors/selector.get-focus-block-object.ts","../../src/selectors/selector.get-next-block.ts","../../src/selectors/selector.get-previous-block.ts","../../src/selectors/selector.get-first-block.ts","../../src/selectors/selector.get-last-block.ts","../../src/selectors/selector.is-at-the-end-of-block.ts","../../src/selectors/selector.is-at-the-start-of-block.ts","../../src/selectors/selector.get-focus-list-block.ts","../../src/selectors/selector.is-active-decorator.ts","../../src/selectors/selector.get-active-annotations.ts","../../src/selectors/selector.get-selected-text-blocks.ts","../../src/selectors/selector.get-active-list-item.ts","../../src/selectors/selector.is-active-list-item.ts","../../src/selectors/selector.get-active-style.ts","../../src/selectors/selector.is-active-style.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 {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 {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 {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 {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 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 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 {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","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 {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 {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 {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 {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 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 {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 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"],"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","getNextInlineObject","isKeySegment","inlineObject","getCaretWordSelection","selectionStartOffset","spanSelectionPointToBlockOffset","selectionPoint","previousInlineObject","getPreviousInlineObject","blockStartPoint","textDirectlyBefore","getSelectionText","split","nextInlineObject","blockEndPoint","textDirectlyAfter","caretWordStartOffset","caretWordEndOffset","caretWordStartSelectionPoint","caretWordEndSelectionPoint","caretWordSelection","getActiveAnnotationsMarks","isActiveAnnotation","annotation","options","mode","getSelectedValue","flatMap","markDefs","markDef","_type","selectionMarkDefs","activeAnnotations","getFocusBlockObject","focusBlock","getNextBlock","nextBlock","getPreviousBlock","previousBlock","getFirstBlock","getLastBlock","isAtTheEndOfBlock","isAtTheStartOfBlock","getFocusListBlock","isListBlock","isActiveDecorator","getActiveAnnotations","getSelectedTextBlocks","selectedTextBlocks","getActiveListItem","firstTextBlock","firstListItem","listItem","isActiveListItem","getActiveStyle","firstStyle","style","isActiveStyle"],"mappings":";;AAQO,MAAMA,uBAERC,CAAAA,aAAa;AAChB,QAAMC,aAAaC,0BAAAA,cAAcF,QAAQ;AAEzC,SAAOC,cAAc,CAACE,MAAAA,mBAAmBF,WAAWG,IAAI,IACpD;AAAA,IA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