@portabletext/editor 2.9.1 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +9 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs +1 -0
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs +6 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-dts/behavior.types.action.d.cts +141 -131
- package/lib/_chunks-dts/behavior.types.action.d.ts +71 -61
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +9 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/util.merge-text-blocks.js +1 -0
- package/lib/_chunks-es/util.merge-text-blocks.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js +6 -1
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/index.cjs +419 -309
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +422 -312
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +3 -3
- package/lib/plugins/index.d.ts +3 -3
- package/lib/utils/index.d.ts +2 -2
- package/package.json +8 -8
- package/src/behaviors/behavior.abstract.insert.ts +109 -24
- package/src/behaviors/behavior.abstract.split.ts +1 -0
- package/src/behaviors/behavior.perform-event.ts +84 -118
- package/src/behaviors/behavior.types.event.ts +9 -1
- package/src/converters/converter.portable-text.ts +1 -0
- package/src/converters/converter.text-html.ts +1 -0
- package/src/converters/converter.text-plain.ts +1 -0
- package/src/editor/Editable.tsx +1 -0
- package/src/editor/editor-selector.ts +10 -1
- package/src/editor/plugins/create-with-event-listeners.ts +13 -14
- package/src/editor/sync-machine.ts +9 -0
- package/src/editor/with-performing-behavior-operation.ts +21 -0
- package/src/editor/without-normalizing-conditional.ts +13 -0
- package/src/internal-utils/parse-blocks.test.ts +14 -14
- package/src/internal-utils/parse-blocks.ts +9 -2
- package/src/internal-utils/slate-utils.test.tsx +119 -0
- package/src/internal-utils/slate-utils.ts +14 -1
- package/src/internal-utils/text-marks.ts +1 -1
- package/src/internal-utils/values.ts +1 -55
- package/src/operations/behavior.operation.block.set.ts +18 -36
- package/src/operations/behavior.operation.block.unset.ts +8 -2
- package/src/operations/behavior.operation.insert.block.ts +4 -1
- package/src/operations/behavior.operation.insert.child.ts +95 -0
- package/src/operations/behavior.operations.ts +140 -128
- package/src/selectors/selector.get-mark-state.ts +19 -5
- package/src/selectors/selector.get-trimmed-selection.test.ts +1 -0
- package/src/types/block-with-optional-key.ts +13 -1
- package/src/utils/util.merge-text-blocks.ts +1 -1
- package/src/utils/util.slice-blocks.ts +3 -3
- package/src/utils/util.slice-text-block.test.ts +54 -28
- package/src/editor/with-applying-behavior-operations.ts +0 -18
|
@@ -198,21 +198,25 @@ const getSelectionEndBlock = (snapshot) => {
|
|
|
198
198
|
if (previousSpanHasSameMarks)
|
|
199
199
|
return {
|
|
200
200
|
state: "changed",
|
|
201
|
+
previousMarks: marks,
|
|
201
202
|
marks: previousSpan?.node.marks ?? []
|
|
202
203
|
};
|
|
203
204
|
if (previousSpanHasSameAnnotations)
|
|
204
205
|
return {
|
|
205
206
|
state: "changed",
|
|
207
|
+
previousMarks: marks,
|
|
206
208
|
marks: previousSpan?.node.marks ?? []
|
|
207
209
|
};
|
|
208
210
|
if (previousSpanHasSameAnnotation)
|
|
209
211
|
return {
|
|
210
212
|
state: "unchanged",
|
|
213
|
+
previousMarks: marks,
|
|
211
214
|
marks: focusSpan.node.marks ?? []
|
|
212
215
|
};
|
|
213
216
|
if (!previousSpan)
|
|
214
217
|
return {
|
|
215
218
|
state: "changed",
|
|
219
|
+
previousMarks: marks,
|
|
216
220
|
marks: []
|
|
217
221
|
};
|
|
218
222
|
}
|
|
@@ -220,24 +224,28 @@ const getSelectionEndBlock = (snapshot) => {
|
|
|
220
224
|
if (nextSpan && nextSpanSharesSomeAnnotations && nextSpanAnnotations.length < spanAnnotations.length || !nextSpanSharesSomeAnnotations)
|
|
221
225
|
return {
|
|
222
226
|
state: "changed",
|
|
227
|
+
previousMarks: marks,
|
|
223
228
|
marks: nextSpan?.node.marks ?? []
|
|
224
229
|
};
|
|
225
230
|
if (!nextSpan)
|
|
226
231
|
return {
|
|
227
232
|
state: "changed",
|
|
233
|
+
previousMarks: marks,
|
|
228
234
|
marks: []
|
|
229
235
|
};
|
|
230
236
|
}
|
|
231
237
|
}
|
|
232
238
|
return atTheBeginningOfSpan && !spanIsEmpty && previousSpan ? previousSpanHasAnnotations ? {
|
|
233
239
|
state: "changed",
|
|
240
|
+
previousMarks: marks,
|
|
234
241
|
marks: []
|
|
235
242
|
} : {
|
|
236
243
|
state: "changed",
|
|
244
|
+
previousMarks: marks,
|
|
237
245
|
marks: (previousSpan?.node.marks ?? []).filter((mark) => decorators.includes(mark))
|
|
238
246
|
} : {
|
|
239
247
|
state: "unchanged",
|
|
240
|
-
marks
|
|
248
|
+
marks
|
|
241
249
|
};
|
|
242
250
|
}, getSelectedBlocks = (snapshot) => {
|
|
243
251
|
if (!snapshot.context.selection)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selector.is-selecting-entire-blocks.js","sources":["../../src/utils/util.is-selection-expanded.ts","../../src/selectors/selector.get-selection-end-block.ts","../../src/selectors/selector.get-selection-end-point.ts","../../src/selectors/selector.get-next-span.ts","../../src/selectors/selector.get-selection-start-block.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-selected-blocks.ts","../../src/selectors/selector.get-active-annotations.ts","../../src/selectors/selector.get-active-list-item.ts","../../src/selectors/selector.get-active-style.ts","../../src/selectors/selector.get-next-inline-object.ts","../../src/selectors/selector.get-caret-word-selection.ts","../../src/selectors/selector.get-first-block.ts","../../src/selectors/selector.get-focus-block-object.ts","../../src/selectors/selector.get-focus-inline-object.ts","../../src/selectors/selector.get-focus-list-block.ts","../../src/selectors/selector.get-last-block.ts","../../src/selectors/selector.get-next-block.ts","../../src/selectors/selector.get-previous-block.ts","../../src/selectors/selector.get-selected-text-blocks.ts","../../src/selectors/selector.get-trimmed-selection.ts","../../src/selectors/selector.get-active-annotation-marks.ts","../../src/selectors/selector.is-active-annotation.ts","../../src/selectors/selector.get-active-decorators.ts","../../src/selectors/selector.is-active-decorator.ts","../../src/selectors/selector.is-active-list-item.ts","../../src/selectors/selector.is-active-style.ts","../../src/selectors/selector.is-at-the-end-of-block.ts","../../src/selectors/selector.is-at-the-start-of-block.ts","../../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"],"sourcesContent":["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 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 {EditorSelectionPoint} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\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 {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {KeyedSegment, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildKeyFromSelectionPoint} from '../selection/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 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 {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {KeyedSegment, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildKeyFromSelectionPoint} from '../selection/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 {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../selection/selection-point'\nimport type {ChildPath} from '../types/paths'\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 {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\nexport type MarkState = {\n state: 'changed' | 'unchanged'\n marks: Array<string>\n}\n\n/**\n * Given that text is inserted at the current position, what marks should\n * be applied?\n */\nexport const getMarkState: EditorSelector<MarkState | undefined> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const focusTextBlock = getFocusTextBlock(snapshot)\n const focusSpan = getFocusSpan(snapshot)\n\n if (!focusTextBlock || !focusSpan) {\n return undefined\n }\n\n if (isSelectionExpanded(snapshot.context.selection)) {\n const selectedSpans = getSelectedSpans(snapshot)\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(snapshot)\n const nextSpan = getNextSpan(snapshot)\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 marks: previousSpan?.node.marks ?? [],\n }\n } else if (previousSpanHasSameAnnotations) {\n return {\n state: 'changed',\n marks: previousSpan?.node.marks ?? [],\n }\n } else if (previousSpanHasSameAnnotation) {\n return {\n state: 'unchanged',\n marks: focusSpan.node.marks ?? [],\n }\n } else if (!previousSpan) {\n return {\n state: 'changed',\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 marks: nextSpan?.node.marks ?? [],\n }\n }\n\n if (!nextSpan) {\n return {\n state: 'changed',\n marks: [],\n }\n }\n }\n }\n\n if (atTheBeginningOfSpan && !spanIsEmpty && !!previousSpan) {\n if (previousSpanHasAnnotations) {\n return {\n state: 'changed',\n marks: [],\n }\n } else {\n return {\n state: 'changed',\n marks: (previousSpan?.node.marks ?? []).filter((mark) =>\n decorators.includes(mark),\n ),\n }\n }\n }\n\n return {\n state: 'unchanged',\n marks: focusSpan.node.marks ?? [],\n }\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-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 {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getMarkState} from './selector.get-mark-state'\nimport {getSelectedBlocks} from './selector.get-selected-blocks'\n\n/**\n * @public\n */\nexport const getActiveAnnotations: EditorSelector<Array<PortableTextObject>> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const markState = getMarkState(snapshot)\n\n const activeAnnotations = (markState?.marks ?? []).filter(\n (mark) =>\n !snapshot.context.schema.decorators\n .map((decorator) => decorator.name)\n .includes(mark),\n )\n\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isTextBlock(snapshot.context, block.node)\n ? (block.node.markDefs ?? [])\n : [],\n )\n\n return selectionMarkDefs.filter((markDef) =>\n activeAnnotations.includes(markDef._key),\n )\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextListBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selector.get-selected-blocks'\n\n/**\n * @public\n */\nexport const getActiveListItem: EditorSelector<\n PortableTextListBlock['listItem'] | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter((block) =>\n isTextBlock(snapshot.context, block),\n )\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstListItem = firstTextBlock.listItem\n\n if (!firstListItem) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.listItem === firstListItem)) {\n return firstListItem\n }\n\n return undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selector.get-selected-blocks'\n\n/**\n * @public\n */\nexport const getActiveStyle: EditorSelector<PortableTextTextBlock['style']> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter((block) =>\n isTextBlock(snapshot.context, block),\n )\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstStyle = firstTextBlock.style\n\n if (!firstStyle) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.style === firstStyle)) {\n return firstStyle\n }\n\n return undefined\n}\n","import {isKeySegment, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {isSpan} from '../utils'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\n\n/**\n * @public\n */\nexport const getNextInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n const selectionEndPointChildKey =\n selectionEndPoint && isKeySegment(selectionEndPoint.path[2])\n ? selectionEndPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionEndPointChildKey) {\n return undefined\n }\n\n let endPointChildFound = false\n let inlineObject:\n | {\n node: PortableTextObject\n path: ChildPath\n }\n | undefined\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionEndPointChildKey) {\n endPointChildFound = true\n continue\n }\n\n if (!isSpan(snapshot.context, child) && endPointChildFound) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n break\n }\n }\n\n return inlineObject\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelection} from '../types/editor'\nimport {\n blockOffsetToSpanSelectionPoint,\n spanSelectionPointToBlockOffset,\n} from '../utils/util.block-offset'\nimport {getBlockEndPoint} from '../utils/util.get-block-end-point'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getNextInlineObject} from './selector.get-next-inline-object'\nimport {getPreviousInlineObject} from './selector.get-previous-inline-object'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\nimport {getSelectionText} from './selector.get-selection-text'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\n\n/**\n * @public\n * Returns the selection of the of the word the caret is placed in.\n * Note: Only returns a word selection if the current selection is collapsed\n */\nexport const getCaretWordSelection: EditorSelector<EditorSelection> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return null\n }\n\n if (!isSelectionCollapsed(snapshot)) {\n return null\n }\n\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartOffset = selectionStartPoint\n ? spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n : undefined\n\n if (!focusTextBlock || !selectionStartPoint || !selectionStartOffset) {\n return null\n }\n\n const previousInlineObject = getPreviousInlineObject(snapshot)\n const blockStartPoint = getBlockStartPoint({\n context: snapshot.context,\n block: focusTextBlock,\n })\n const textBefore = getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: previousInlineObject\n ? {path: previousInlineObject.path, offset: 0}\n : blockStartPoint,\n focus: selectionStartPoint,\n },\n },\n })\n const textDirectlyBefore = textBefore.split(/\\s+/).at(-1)\n\n const nextInlineObject = getNextInlineObject(snapshot)\n const blockEndPoint = getBlockEndPoint({\n context: snapshot.context,\n block: focusTextBlock,\n })\n const textAfter = getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: selectionStartPoint,\n focus: nextInlineObject\n ? {path: nextInlineObject.path, offset: 0}\n : blockEndPoint,\n },\n },\n })\n const textDirectlyAfter = textAfter.split(/\\s+/).at(0)\n\n if (\n (textDirectlyBefore === undefined || textDirectlyBefore === '') &&\n (textDirectlyAfter === undefined || textDirectlyAfter === '')\n ) {\n return null\n }\n\n const caretWordStartOffset: BlockOffset = textDirectlyBefore\n ? {\n ...selectionStartOffset,\n offset: selectionStartOffset.offset - textDirectlyBefore.length,\n }\n : selectionStartOffset\n const caretWordEndOffset: BlockOffset = textDirectlyAfter\n ? {\n ...selectionStartOffset,\n offset: selectionStartOffset.offset + textDirectlyAfter.length,\n }\n : selectionStartOffset\n\n const caretWordStartSelectionPoint = blockOffsetToSpanSelectionPoint({\n context: snapshot.context,\n blockOffset: caretWordStartOffset,\n direction: 'backward',\n })\n const caretWordEndSelectionPoint = blockOffsetToSpanSelectionPoint({\n context: snapshot.context,\n blockOffset: caretWordEndOffset,\n direction: 'forward',\n })\n\n if (!caretWordStartSelectionPoint || !caretWordEndSelectionPoint) {\n return null\n }\n\n const caretWordSelection = {\n anchor: caretWordStartSelectionPoint,\n focus: caretWordEndSelectionPoint,\n }\n\n return isSelectionExpanded({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: caretWordSelection,\n },\n })\n ? caretWordSelection\n : null\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport const getFirstBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const node = snapshot.context.value[0]\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * @public\n */\nexport const getFocusBlockObject: EditorSelector<\n {node: PortableTextObject; path: BlockPath} | undefined\n> = (snapshot) => {\n const focusBlock = getFocusBlock(snapshot)\n\n return focusBlock && !isTextBlock(snapshot.context, focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n","import {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 {PortableTextListBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isListBlock} from '../internal-utils/parse-blocks'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * @public\n */\nexport const getFocusListBlock: EditorSelector<\n {node: PortableTextListBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n\n return focusTextBlock && isListBlock(snapshot.context, focusTextBlock.node)\n ? {node: focusTextBlock.node, path: focusTextBlock.path}\n : undefined\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport const getLastBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const node = snapshot.context.value[snapshot.context.value.length - 1]\n ? snapshot.context.value[snapshot.context.value.length - 1]\n : undefined\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionEndBlock} from './selector.get-selection-end-block'\n\n/**\n * @public\n */\nexport const getNextBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const selectionEndBlock = getSelectionEndBlock(snapshot)\n\n if (!selectionEndBlock) {\n return undefined\n }\n\n const index = snapshot.blockIndexMap.get(selectionEndBlock.node._key)\n\n if (index === undefined || index === snapshot.context.value.length - 1) {\n return undefined\n }\n\n const nextBlock = snapshot.context.value.at(index + 1)\n\n return nextBlock\n ? {node: nextBlock, path: [{_key: nextBlock._key}]}\n : undefined\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionStartBlock} from './selector.get-selection-start-block'\n\n/**\n * @public\n */\nexport const getPreviousBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const selectionStartBlock = getSelectionStartBlock(snapshot)\n\n if (!selectionStartBlock) {\n return undefined\n }\n\n const index = snapshot.blockIndexMap.get(selectionStartBlock.node._key)\n\n if (index === undefined || index === 0) {\n return undefined\n }\n\n const previousBlock = snapshot.context.value.at(index - 1)\n\n return previousBlock\n ? {node: previousBlock, path: [{_key: previousBlock._key}]}\n : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionEndPoint, getSelectionStartPoint} from '../utils'\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 {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../selection/selection-point'\nimport type {EditorSelection, EditorSelectionPoint} from '../types/editor'\nimport {\n getSelectionEndPoint,\n getSelectionStartPoint,\n isEmptyTextBlock,\n} from '../utils'\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 type {EditorSnapshot} from '../editor/editor-snapshot'\nimport {getMarkState} from './selector.get-mark-state'\n\nexport function getActiveAnnotationsMarks(snapshot: EditorSnapshot) {\n const schema = snapshot.context.schema\n const markState = getMarkState(snapshot)\n\n return (markState?.marks ?? []).filter(\n (mark) =>\n !schema.decorators.map((decorator) => decorator.name).includes(mark),\n )\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveAnnotationsMarks} from './selector.get-active-annotation-marks'\nimport {getSelectedBlocks} from './selector.get-selected-blocks'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * Check whether an annotation is active in the given `snapshot`.\n *\n * @public\n */\nexport function isActiveAnnotation(\n annotation: string,\n options?: {\n /**\n * Choose whether the annotation has to take up the entire selection in the\n * `snapshot` or if the annotation can be partially selected.\n *\n * Defaults to 'full'\n */\n mode?: 'partial' | 'full'\n },\n): EditorSelector<boolean> {\n return (snapshot) => {\n const mode = options?.mode ?? 'full'\n\n if (mode === 'partial') {\n const selectedValue = getSelectedValue(snapshot)\n\n const selectionMarkDefs = selectedValue.flatMap((block) =>\n isTextBlock(snapshot.context, block) ? (block.markDefs ?? []) : [],\n )\n\n return selectionMarkDefs.some((markDef) => markDef._type === annotation)\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isTextBlock(snapshot.context, block.node)\n ? (block.node.markDefs ?? [])\n : [],\n )\n const activeAnnotations = getActiveAnnotationsMarks(snapshot)\n const activeMarkDefs = selectionMarkDefs.filter(\n (markDef) =>\n markDef._type === annotation &&\n activeAnnotations.includes(markDef._key),\n )\n\n return activeMarkDefs.length > 0\n }\n}\n","import type {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 type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveDecorators} from './selector.get-active-decorators'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\n\n/**\n * @public\n */\nexport function isActiveDecorator(decorator: string): EditorSelector<boolean> {\n return (snapshot) => {\n if (isSelectionExpanded(snapshot)) {\n const selectedSpans = getSelectedSpans(snapshot)\n\n return (\n selectedSpans.length > 0 &&\n selectedSpans.every((span) => span.node.marks?.includes(decorator))\n )\n }\n\n const activeDecorators = getActiveDecorators(snapshot)\n\n return activeDecorators.includes(decorator)\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveListItem} from './selector.get-active-list-item'\n\n/**\n * @public\n */\nexport function isActiveListItem(listItem: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeListItem = getActiveListItem(snapshot)\n\n return activeListItem === listItem\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveStyle} from './selector.get-active-style'\n\n/**\n * @public\n */\nexport function isActiveStyle(style: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeStyle = getActiveStyle(snapshot)\n\n return activeStyle === style\n }\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport * as utils from '../utils'\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 = utils.getBlockEndPoint({\n context: snapshot.context,\n block,\n })\n\n return utils.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 * as utils from '../utils'\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 = utils.getBlockStartPoint({\n context: snapshot.context,\n block,\n })\n\n return utils.isEqualSelectionPoints(\n snapshot.context.selection.focus,\n blockStartPoint,\n )\n }\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../selection/selection-point'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {getSelectionEndPoint} from '../utils'\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 {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../selection/selection-point'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {getSelectionStartPoint} from '../utils'\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'\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 * as utils from '../utils'\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 = utils.getBlockStartPoint({\n context: snapshot.context,\n block: startBlock,\n })\n const endBlockEndPoint = utils.getBlockEndPoint({\n context: snapshot.context,\n block: endBlock,\n })\n\n return (\n utils.isEqualSelectionPoints(startBlockStartPoint, startPoint) &&\n utils.isEqualSelectionPoints(endBlockEndPoint, endPoint)\n )\n}\n"],"names":["isSelectionExpanded","selection","isSelectionCollapsed","getSelectionEndBlock","snapshot","endPoint","getSelectionEndPoint","context","getFocusBlock","anchor","focus","backward","getNextSpan","selectionEndBlock","selectionEndPoint","isTextBlock","node","selectionEndPointChildKey","getChildKeyFromSelectionPoint","endPointChildFound","nextSpan","child","children","_key","isSpan","path","getSelectionStartBlock","startPoint","getSelectionStartPoint","getPreviousSpan","selectionStartBlock","selectionStartPoint","selectionStartPointChildKey","previousSpan","getSelectedSpans","selectedSpans","startBlockKey","getBlockKeyFromSelectionPoint","endBlockKey","startSpanKey","endSpanKey","startBlockIndex","blockIndexMap","get","endBlockIndex","undefined","slicedValue","value","slice","startBlockFound","block","offset","text","length","push","getMarkState","focusTextBlock","getFocusTextBlock","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","getSelectedBlocks","selectedBlocks","startKey","endKey","getActiveAnnotations","activeAnnotations","flatMap","markDefs","markDef","getActiveListItem","selectedTextBlocks","firstTextBlock","at","firstListItem","listItem","getActiveStyle","firstStyle","style","getNextInlineObject","isKeySegment","inlineObject","getCaretWordSelection","selectionStartOffset","spanSelectionPointToBlockOffset","selectionPoint","previousInlineObject","getPreviousInlineObject","blockStartPoint","getBlockStartPoint","textDirectlyBefore","getSelectionText","split","nextInlineObject","blockEndPoint","getBlockEndPoint","textDirectlyAfter","caretWordStartOffset","caretWordEndOffset","caretWordStartSelectionPoint","blockOffsetToSpanSelectionPoint","blockOffset","direction","caretWordEndSelectionPoint","caretWordSelection","getFirstBlock","getFocusBlockObject","focusBlock","getFocusInlineObject","focusChild","getFocusChild","isPortableTextSpan","getFocusListBlock","isListBlock","getLastBlock","getNextBlock","nextBlock","getPreviousBlock","previousBlock","getSelectedTextBlocks","getTrimmedSelection","startChildKey","endChildKey","adjustedStartPoint","trimStartPoint","adjustedEndPoint","trimEndPoint","previousPotentialEndpoint","isEmptyTextBlock","blockKey","lonelySpan","trimmedSelection","getActiveAnnotationsMarks","isActiveAnnotation","annotation","options","mode","getSelectedValue","_type","selectionMarkDefs","getActiveDecorators","decoratorState","markState","activeDecorators","activeDecorator","isActiveDecorator","isActiveListItem","isActiveStyle","isAtTheEndOfBlock","utils","isAtTheStartOfBlock","isPointAfterSelection","point","pointBlockKey","pointChildKey","pointBlockIndex","pointBlock","pointChildIndex","endChildIndex","childIndex","isPointBeforeSelection","startChildIndex","isOverlappingSelection","originalSelectionStartPoint","originalSelectionEndPoint","startPointEqualToOriginalStartPoint","isEqualSelectionPoints","endPointEqualToOriginalEndPoint","startPointBeforeSelection","startPointAfterSelection","endPointBeforeSelection","endPointAfterSelection","originalStartPointBeforeStartPoint","originalStartPointAfterStartPoint","originalEndPointBeforeEndPoint","originalEndPointAfterEndPoint","startPointEqualToOriginalEndPoint","endPointEqualToOriginalStartPoint","isSelectingEntireBlocks","startBlock","endBlock","startBlockStartPoint","endBlockEndPoint"],"mappings":";;;;;AAMO,SAASA,oBAAoBC,WAA4B;AAC9D,SAAKA,YAIE,CAACC,qBAAqBD,SAAS,IAH7B;AAIX;ACHO,MAAME,uBAMRC,CAAAA,aAAa;AAChB,QAAMC,WAAWC,uBAAqBF,SAASG,QAAQN,SAAS;AAEhE,MAAKI;AAIL,WAAOG,cAAc;AAAA,MACnB,GAAGJ;AAAAA,MACHG,SAAS;AAAA,QACP,GAAGH,SAASG;AAAAA,QACZN,WAAW;AAAA,UACTQ,QAAQJ;AAAAA,UACRK,OAAOL;AAAAA,QAAAA;AAAAA,MACT;AAAA,IACF,CACD;AACH,GC1BaC,uBAERF,CAAAA,aAAa;AAChB,MAAKA,SAASG,QAAQN;AAItB,WAAOG,SAASG,QAAQN,UAAUU,WAC9BP,SAASG,QAAQN,UAAUQ,SAC3BL,SAASG,QAAQN,UAAUS;AACjC,GCNaE,cAMRR,CAAAA,aAAa;AAChB,QAAMS,oBAAoBV,qBAAqBC,QAAQ,GACjDU,oBAAoBR,qBAAqBF,QAAQ;AAMvD,MAJI,CAACS,qBAAqB,CAACC,qBAIvB,CAACC,YAAYX,SAASG,SAASM,kBAAkBG,IAAI;AACvD;AAGF,QAAMC,4BACJC,8BAA8BJ,iBA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AAAAA,EAAAA,CACR,GACKG,mBAAmBjC,iBAAuB;AAAA,IAC9CxK,SAASH,SAASG;AAAAA,IAClB2C,OAAO4J;AAAAA,EAAAA,CACR;AAED,SACE/B,uBAA6BgC,sBAAsBpL,UAAU,KAC7DoJ,uBAA6BiC,kBAAkB3M,QAAQ;AAE3D;"}
|
|
1
|
+
{"version":3,"file":"selector.is-selecting-entire-blocks.js","sources":["../../src/utils/util.is-selection-expanded.ts","../../src/selectors/selector.get-selection-end-block.ts","../../src/selectors/selector.get-selection-end-point.ts","../../src/selectors/selector.get-next-span.ts","../../src/selectors/selector.get-selection-start-block.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-selected-blocks.ts","../../src/selectors/selector.get-active-annotations.ts","../../src/selectors/selector.get-active-list-item.ts","../../src/selectors/selector.get-active-style.ts","../../src/selectors/selector.get-next-inline-object.ts","../../src/selectors/selector.get-caret-word-selection.ts","../../src/selectors/selector.get-first-block.ts","../../src/selectors/selector.get-focus-block-object.ts","../../src/selectors/selector.get-focus-inline-object.ts","../../src/selectors/selector.get-focus-list-block.ts","../../src/selectors/selector.get-last-block.ts","../../src/selectors/selector.get-next-block.ts","../../src/selectors/selector.get-previous-block.ts","../../src/selectors/selector.get-selected-text-blocks.ts","../../src/selectors/selector.get-trimmed-selection.ts","../../src/selectors/selector.get-active-annotation-marks.ts","../../src/selectors/selector.is-active-annotation.ts","../../src/selectors/selector.get-active-decorators.ts","../../src/selectors/selector.is-active-decorator.ts","../../src/selectors/selector.is-active-list-item.ts","../../src/selectors/selector.is-active-style.ts","../../src/selectors/selector.is-at-the-end-of-block.ts","../../src/selectors/selector.is-at-the-start-of-block.ts","../../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"],"sourcesContent":["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 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 {EditorSelectionPoint} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\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 {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {KeyedSegment, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildKeyFromSelectionPoint} from '../selection/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 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 {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {KeyedSegment, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildKeyFromSelectionPoint} from '../selection/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 {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../selection/selection-point'\nimport type {ChildPath} from '../types/paths'\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 {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\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 */\nexport const getMarkState: EditorSelector<MarkState | undefined> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const focusTextBlock = getFocusTextBlock(snapshot)\n const focusSpan = getFocusSpan(snapshot)\n\n if (!focusTextBlock || !focusSpan) {\n return undefined\n }\n\n if (isSelectionExpanded(snapshot.context.selection)) {\n const selectedSpans = getSelectedSpans(snapshot)\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(snapshot)\n const nextSpan = getNextSpan(snapshot)\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: 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 {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-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 {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getMarkState} from './selector.get-mark-state'\nimport {getSelectedBlocks} from './selector.get-selected-blocks'\n\n/**\n * @public\n */\nexport const getActiveAnnotations: EditorSelector<Array<PortableTextObject>> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const markState = getMarkState(snapshot)\n\n const activeAnnotations = (markState?.marks ?? []).filter(\n (mark) =>\n !snapshot.context.schema.decorators\n .map((decorator) => decorator.name)\n .includes(mark),\n )\n\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isTextBlock(snapshot.context, block.node)\n ? (block.node.markDefs ?? [])\n : [],\n )\n\n return selectionMarkDefs.filter((markDef) =>\n activeAnnotations.includes(markDef._key),\n )\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextListBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selector.get-selected-blocks'\n\n/**\n * @public\n */\nexport const getActiveListItem: EditorSelector<\n PortableTextListBlock['listItem'] | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter((block) =>\n isTextBlock(snapshot.context, block),\n )\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstListItem = firstTextBlock.listItem\n\n if (!firstListItem) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.listItem === firstListItem)) {\n return firstListItem\n }\n\n return undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selector.get-selected-blocks'\n\n/**\n * @public\n */\nexport const getActiveStyle: EditorSelector<PortableTextTextBlock['style']> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter((block) =>\n isTextBlock(snapshot.context, block),\n )\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstStyle = firstTextBlock.style\n\n if (!firstStyle) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.style === firstStyle)) {\n return firstStyle\n }\n\n return undefined\n}\n","import {isKeySegment, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {isSpan} from '../utils'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\n\n/**\n * @public\n */\nexport const getNextInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n const selectionEndPointChildKey =\n selectionEndPoint && isKeySegment(selectionEndPoint.path[2])\n ? selectionEndPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionEndPointChildKey) {\n return undefined\n }\n\n let endPointChildFound = false\n let inlineObject:\n | {\n node: PortableTextObject\n path: ChildPath\n }\n | undefined\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionEndPointChildKey) {\n endPointChildFound = true\n continue\n }\n\n if (!isSpan(snapshot.context, child) && endPointChildFound) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n break\n }\n }\n\n return inlineObject\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelection} from '../types/editor'\nimport {\n blockOffsetToSpanSelectionPoint,\n spanSelectionPointToBlockOffset,\n} from '../utils/util.block-offset'\nimport {getBlockEndPoint} from '../utils/util.get-block-end-point'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getNextInlineObject} from './selector.get-next-inline-object'\nimport {getPreviousInlineObject} from './selector.get-previous-inline-object'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\nimport {getSelectionText} from './selector.get-selection-text'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\n\n/**\n * @public\n * Returns the selection of the of the word the caret is placed in.\n * Note: Only returns a word selection if the current selection is collapsed\n */\nexport const getCaretWordSelection: EditorSelector<EditorSelection> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return null\n }\n\n if (!isSelectionCollapsed(snapshot)) {\n return null\n }\n\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartOffset = selectionStartPoint\n ? spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n : undefined\n\n if (!focusTextBlock || !selectionStartPoint || !selectionStartOffset) {\n return null\n }\n\n const previousInlineObject = getPreviousInlineObject(snapshot)\n const blockStartPoint = getBlockStartPoint({\n context: snapshot.context,\n block: focusTextBlock,\n })\n const textBefore = getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: previousInlineObject\n ? {path: previousInlineObject.path, offset: 0}\n : blockStartPoint,\n focus: selectionStartPoint,\n },\n },\n })\n const textDirectlyBefore = textBefore.split(/\\s+/).at(-1)\n\n const nextInlineObject = getNextInlineObject(snapshot)\n const blockEndPoint = getBlockEndPoint({\n context: snapshot.context,\n block: focusTextBlock,\n })\n const textAfter = getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: selectionStartPoint,\n focus: nextInlineObject\n ? {path: nextInlineObject.path, offset: 0}\n : blockEndPoint,\n },\n },\n })\n const textDirectlyAfter = textAfter.split(/\\s+/).at(0)\n\n if (\n (textDirectlyBefore === undefined || textDirectlyBefore === '') &&\n (textDirectlyAfter === undefined || textDirectlyAfter === '')\n ) {\n return null\n }\n\n const caretWordStartOffset: BlockOffset = textDirectlyBefore\n ? {\n ...selectionStartOffset,\n offset: selectionStartOffset.offset - textDirectlyBefore.length,\n }\n : selectionStartOffset\n const caretWordEndOffset: BlockOffset = textDirectlyAfter\n ? {\n ...selectionStartOffset,\n offset: selectionStartOffset.offset + textDirectlyAfter.length,\n }\n : selectionStartOffset\n\n const caretWordStartSelectionPoint = blockOffsetToSpanSelectionPoint({\n context: snapshot.context,\n blockOffset: caretWordStartOffset,\n direction: 'backward',\n })\n const caretWordEndSelectionPoint = blockOffsetToSpanSelectionPoint({\n context: snapshot.context,\n blockOffset: caretWordEndOffset,\n direction: 'forward',\n })\n\n if (!caretWordStartSelectionPoint || !caretWordEndSelectionPoint) {\n return null\n }\n\n const caretWordSelection = {\n anchor: caretWordStartSelectionPoint,\n focus: caretWordEndSelectionPoint,\n }\n\n return isSelectionExpanded({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: caretWordSelection,\n },\n })\n ? caretWordSelection\n : null\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport const getFirstBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const node = snapshot.context.value[0]\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * @public\n */\nexport const getFocusBlockObject: EditorSelector<\n {node: PortableTextObject; path: BlockPath} | undefined\n> = (snapshot) => {\n const focusBlock = getFocusBlock(snapshot)\n\n return focusBlock && !isTextBlock(snapshot.context, focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n","import {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 {PortableTextListBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isListBlock} from '../internal-utils/parse-blocks'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * @public\n */\nexport const getFocusListBlock: EditorSelector<\n {node: PortableTextListBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n\n return focusTextBlock && isListBlock(snapshot.context, focusTextBlock.node)\n ? {node: focusTextBlock.node, path: focusTextBlock.path}\n : undefined\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport const getLastBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const node = snapshot.context.value[snapshot.context.value.length - 1]\n ? snapshot.context.value[snapshot.context.value.length - 1]\n : undefined\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionEndBlock} from './selector.get-selection-end-block'\n\n/**\n * @public\n */\nexport const getNextBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const selectionEndBlock = getSelectionEndBlock(snapshot)\n\n if (!selectionEndBlock) {\n return undefined\n }\n\n const index = snapshot.blockIndexMap.get(selectionEndBlock.node._key)\n\n if (index === undefined || index === snapshot.context.value.length - 1) {\n return undefined\n }\n\n const nextBlock = snapshot.context.value.at(index + 1)\n\n return nextBlock\n ? {node: nextBlock, path: [{_key: nextBlock._key}]}\n : undefined\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionStartBlock} from './selector.get-selection-start-block'\n\n/**\n * @public\n */\nexport const getPreviousBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const selectionStartBlock = getSelectionStartBlock(snapshot)\n\n if (!selectionStartBlock) {\n return undefined\n }\n\n const index = snapshot.blockIndexMap.get(selectionStartBlock.node._key)\n\n if (index === undefined || index === 0) {\n return undefined\n }\n\n const previousBlock = snapshot.context.value.at(index - 1)\n\n return previousBlock\n ? {node: previousBlock, path: [{_key: previousBlock._key}]}\n : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionEndPoint, getSelectionStartPoint} from '../utils'\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 {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../selection/selection-point'\nimport type {EditorSelection, EditorSelectionPoint} from '../types/editor'\nimport {\n getSelectionEndPoint,\n getSelectionStartPoint,\n isEmptyTextBlock,\n} from '../utils'\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 type {EditorSnapshot} from '../editor/editor-snapshot'\nimport {getMarkState} from './selector.get-mark-state'\n\nexport function getActiveAnnotationsMarks(snapshot: EditorSnapshot) {\n const schema = snapshot.context.schema\n const markState = getMarkState(snapshot)\n\n return (markState?.marks ?? []).filter(\n (mark) =>\n !schema.decorators.map((decorator) => decorator.name).includes(mark),\n )\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveAnnotationsMarks} from './selector.get-active-annotation-marks'\nimport {getSelectedBlocks} from './selector.get-selected-blocks'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * Check whether an annotation is active in the given `snapshot`.\n *\n * @public\n */\nexport function isActiveAnnotation(\n annotation: string,\n options?: {\n /**\n * Choose whether the annotation has to take up the entire selection in the\n * `snapshot` or if the annotation can be partially selected.\n *\n * Defaults to 'full'\n */\n mode?: 'partial' | 'full'\n },\n): EditorSelector<boolean> {\n return (snapshot) => {\n const mode = options?.mode ?? 'full'\n\n if (mode === 'partial') {\n const selectedValue = getSelectedValue(snapshot)\n\n const selectionMarkDefs = selectedValue.flatMap((block) =>\n isTextBlock(snapshot.context, block) ? (block.markDefs ?? []) : [],\n )\n\n return selectionMarkDefs.some((markDef) => markDef._type === annotation)\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isTextBlock(snapshot.context, block.node)\n ? (block.node.markDefs ?? [])\n : [],\n )\n const activeAnnotations = getActiveAnnotationsMarks(snapshot)\n const activeMarkDefs = selectionMarkDefs.filter(\n (markDef) =>\n markDef._type === annotation &&\n activeAnnotations.includes(markDef._key),\n )\n\n return activeMarkDefs.length > 0\n }\n}\n","import type {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 type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveDecorators} from './selector.get-active-decorators'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\n\n/**\n * @public\n */\nexport function isActiveDecorator(decorator: string): EditorSelector<boolean> {\n return (snapshot) => {\n if (isSelectionExpanded(snapshot)) {\n const selectedSpans = getSelectedSpans(snapshot)\n\n return (\n selectedSpans.length > 0 &&\n selectedSpans.every((span) => span.node.marks?.includes(decorator))\n )\n }\n\n const activeDecorators = getActiveDecorators(snapshot)\n\n return activeDecorators.includes(decorator)\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveListItem} from './selector.get-active-list-item'\n\n/**\n * @public\n */\nexport function isActiveListItem(listItem: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeListItem = getActiveListItem(snapshot)\n\n return activeListItem === listItem\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveStyle} from './selector.get-active-style'\n\n/**\n * @public\n */\nexport function isActiveStyle(style: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeStyle = getActiveStyle(snapshot)\n\n return activeStyle === style\n }\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport * as utils from '../utils'\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 = utils.getBlockEndPoint({\n context: snapshot.context,\n block,\n })\n\n return utils.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 * as utils from '../utils'\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 = utils.getBlockStartPoint({\n context: snapshot.context,\n block,\n })\n\n return utils.isEqualSelectionPoints(\n snapshot.context.selection.focus,\n blockStartPoint,\n )\n }\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../selection/selection-point'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {getSelectionEndPoint} from '../utils'\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 {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from '../selection/selection-point'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {getSelectionStartPoint} from '../utils'\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'\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 * as utils from '../utils'\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 = utils.getBlockStartPoint({\n context: snapshot.context,\n block: startBlock,\n })\n const endBlockEndPoint = utils.getBlockEndPoint({\n context: snapshot.context,\n block: endBlock,\n })\n\n return (\n utils.isEqualSelectionPoints(startBlockStartPoint, startPoint) &&\n utils.isEqualSelectionPoints(endBlockEndPoint, endPoint)\n )\n}\n"],"names":["isSelectionExpanded","selection","isSelectionCollapsed","getSelectionEndBlock","snapshot","endPoint","getSelectionEndPoint","context","getFocusBlock","anchor","focus","backward","getNextSpan","selectionEndBlock","selectionEndPoint","isTextBlock","node","selectionEndPointChildKey","getChildKeyFromSelectionPoint","endPointChildFound","nextSpan","child","children","_key","isSpan","path","getSelectionStartBlock","startPoint","getSelectionStartPoint","getPreviousSpan","selectionStartBlock","selectionStartPoint","selectionStartPointChildKey","previousSpan","getSelectedSpans","selectedSpans","startBlockKey","getBlockKeyFromSelectionPoint","endBlockKey","startSpanKey","endSpanKey","startBlockIndex","blockIndexMap","get","endBlockIndex","undefined","slicedValue","value","slice","startBlockFound","block","offset","text","length","push","getMarkState","focusTextBlock","getFocusTextBlock","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","getSelectedBlocks","selectedBlocks","startKey","endKey","getActiveAnnotations","activeAnnotations","flatMap","markDefs","markDef","getActiveListItem","selectedTextBlocks","firstTextBlock","at","firstListItem","listItem","getActiveStyle","firstStyle","style","getNextInlineObject","isKeySegment","inlineObject","getCaretWordSelection","selectionStartOffset","spanSelectionPointToBlockOffset","selectionPoint","previousInlineObject","getPreviousInlineObject","blockStartPoint","getBlockStartPoint","textDirectlyBefore","getSelectionText","split","nextInlineObject","blockEndPoint","getBlockEndPoint","textDirectlyAfter","caretWordStartOffset","caretWordEndOffset","caretWordStartSelectionPoint","blockOffsetToSpanSelectionPoint","blockOffset","direction","caretWordEndSelectionPoint","caretWordSelection","getFirstBlock","getFocusBlockObject","focusBlock","getFocusInlineObject","focusChild","getFocusChild","isPortableTextSpan","getFocusListBlock","isListBlock","getLastBlock","getNextBlock","nextBlock","getPreviousBlock","previousBlock","getSelectedTextBlocks","getTrimmedSelection","startChildKey","endChildKey","adjustedStartPoint","trimStartPoint","adjustedEndPoint","trimEndPoint","previousPotentialEndpoint","isEmptyTextBlock","blockKey","lonelySpan","trimmedSelection","getActiveAnnotationsMarks","isActiveAnnotation","annotation","options","mode","getSelectedValue","_type","selectionMarkDefs","getActiveDecorators","decoratorState","markState","activeDecorators","activeDecorator","isActiveDecorator","isActiveListItem","isActiveStyle","isAtTheEndOfBlock","utils","isAtTheStartOfBlock","isPointAfterSelection","point","pointBlockKey","pointChildKey","pointBlockIndex","pointBlock","pointChildIndex","endChildIndex","childIndex","isPointBeforeSelection","startChildIndex","isOverlappingSelection","originalSelectionStartPoint","originalSelectionEndPoint","startPointEqualToOriginalStartPoint","isEqualSelectionPoints","endPointEqualToOriginalEndPoint","startPointBeforeSelection","startPointAfterSelection","endPointBeforeSelection","endPointAfterSelection","originalStartPointBeforeStartPoint","originalStartPointAfterStartPoint","originalEndPointBeforeEndPoint","originalEndPointAfterEndPoint","startPointEqualToOriginalEndPoint","endPointEqualToOriginalStartPoint","isSelectingEntireBlocks","startBlock","endBlock","startBlockStartPoint","endBlockEnd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AA,UACRJ,OAAOI;AAAAA,QAAAA;AAAAA,MACT;AAAA,IACF,CACD,GAEK6L,oCAAoCV,uBACxClK,qBACAgK,yBACF,GACMa,oCAAoCX,uBACxCnL,mBACAgL,2BACF;AAmBA,WAdE,CAACc,qCACD,CAACD,qCACD,CAACJ,sCACD,CAACC,qCACD,CAACC,kCACD,CAACC,iCAKCL,2BAA2B,CAACO,qCAI5BR,4BAA4B,CAACO,oCACxB,KAIP,CAACJ,sCACDC,qCACA,CAACC,kCACDC,gCAEO,CAACE,oCAIRL,sCACA,CAACC,qCACDC,kCACA,CAACC,gCAEM,CAACC,oCAIR,CAACP,4BACD,CAACD,6BACD,CAACG,0BACD,CAACD;AAAAA,EAML;AACF;AC5KO,MAAMQ,0BAAoDzM,CAAAA,aAAa;AAC5E,MAAI,CAACA,SAASG,QAAQN;AACpB,WAAO;AAGT,QAAM0B,aAAavB,SAASG,QAAQN,UAAUU,WAC1CP,SAASG,QAAQN,UAAUS,QAC3BN,SAASG,QAAQN,UAAUQ,QACzBJ,WAAWD,SAASG,QAAQN,UAAUU,WACxCP,SAASG,QAAQN,UAAUQ,SAC3BL,SAASG,QAAQN,UAAUS,OAEzBoM,aAAapL,uBAAuBtB,QAAQ,GAC5C2M,WAAW5M,qBAAqBC,QAAQ;AAE9C,MAAI,CAAC0M,cAAc,CAACC;AAClB,WAAO;AAGT,QAAMC,uBAAuBhC,mBAAyB;AAAA,IACpDzK,SAASH,SAASG;AAAAA,IAClB2C,OAAO4J;AAAAA,EAAAA,CACR,GACKG,mBAAmBjC,iBAAuB;AAAA,IAC9CzK,SAASH,SAASG;AAAAA,IAClB2C,OAAO6J;AAAAA,EAAAA,CACR;AAED,SACE/B,uBAA6BgC,sBAAsBrL,UAAU,KAC7DqJ,uBAA6BiC,kBAAkB5M,QAAQ;AAE3D;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.merge-text-blocks.js","sources":["../../src/utils/util.merge-text-blocks.ts"],"sourcesContent":["import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\nimport {parseBlock} from '../internal-utils/parse-blocks'\n\n/**\n * @beta\n */\nexport function mergeTextBlocks({\n context,\n targetBlock,\n incomingBlock,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n targetBlock: PortableTextTextBlock\n incomingBlock: PortableTextTextBlock\n}) {\n const parsedIncomingBlock = parseBlock({\n context,\n block: incomingBlock,\n options: {validateFields: false},\n })\n\n if (!parsedIncomingBlock || !isTextBlock(context, parsedIncomingBlock)) {\n return targetBlock\n }\n\n return {\n ...targetBlock,\n children: [...targetBlock.children, ...parsedIncomingBlock.children],\n markDefs: [\n ...(targetBlock.markDefs ?? []),\n ...(parsedIncomingBlock.markDefs ?? []),\n ],\n }\n}\n"],"names":["mergeTextBlocks","context","targetBlock","incomingBlock","parsedIncomingBlock","parseBlock","block","options","validateFields","isTextBlock","children","markDefs"],"mappings":";;AAQO,SAASA,gBAAgB;AAAA,EAC9BC;AAAAA,EACAC;AAAAA,EACAC;AAKF,GAAG;AACD,QAAMC,sBAAsBC,WAAW;AAAA,IACrCJ;AAAAA,IACAK,OAAOH;AAAAA,IACPI,SAAS;AAAA,MAACC,gBAAgB;AAAA,IAAA;AAAA,EAAK,
|
|
1
|
+
{"version":3,"file":"util.merge-text-blocks.js","sources":["../../src/utils/util.merge-text-blocks.ts"],"sourcesContent":["import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\nimport {parseBlock} from '../internal-utils/parse-blocks'\n\n/**\n * @beta\n */\nexport function mergeTextBlocks({\n context,\n targetBlock,\n incomingBlock,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n targetBlock: PortableTextTextBlock\n incomingBlock: PortableTextTextBlock\n}) {\n const parsedIncomingBlock = parseBlock({\n context,\n block: incomingBlock,\n options: {removeUnusedMarkDefs: true, validateFields: false},\n })\n\n if (!parsedIncomingBlock || !isTextBlock(context, parsedIncomingBlock)) {\n return targetBlock\n }\n\n return {\n ...targetBlock,\n children: [...targetBlock.children, ...parsedIncomingBlock.children],\n markDefs: [\n ...(targetBlock.markDefs ?? []),\n ...(parsedIncomingBlock.markDefs ?? []),\n ],\n }\n}\n"],"names":["mergeTextBlocks","context","targetBlock","incomingBlock","parsedIncomingBlock","parseBlock","block","options","removeUnusedMarkDefs","validateFields","isTextBlock","children","markDefs"],"mappings":";;AAQO,SAASA,gBAAgB;AAAA,EAC9BC;AAAAA,EACAC;AAAAA,EACAC;AAKF,GAAG;AACD,QAAMC,sBAAsBC,WAAW;AAAA,IACrCJ;AAAAA,IACAK,OAAOH;AAAAA,IACPI,SAAS;AAAA,MAACC,sBAAsB;AAAA,MAAMC,gBAAgB;AAAA,IAAA;AAAA,EAAK,CAC5D;AAED,SAAI,CAACL,uBAAuB,CAACM,YAAYT,SAASG,mBAAmB,IAC5DF,cAGF;AAAA,IACL,GAAGA;AAAAA,IACHS,UAAU,CAAC,GAAGT,YAAYS,UAAU,GAAGP,oBAAoBO,QAAQ;AAAA,IACnEC,UAAU,CACR,GAAIV,YAAYU,YAAY,CAAA,GAC5B,GAAIR,oBAAoBQ,YAAY,CAAA,CAAG;AAAA,EAAA;AAG7C;"}
|
|
@@ -217,7 +217,7 @@ function parseTextBlock({
|
|
|
217
217
|
text: "",
|
|
218
218
|
marks: []
|
|
219
219
|
}],
|
|
220
|
-
markDefs: markDefs.filter((markDef) => marks.includes(markDef._key)),
|
|
220
|
+
markDefs: options.removeUnusedMarkDefs ? markDefs.filter((markDef) => marks.includes(markDef._key)) : markDefs,
|
|
221
221
|
...customFields
|
|
222
222
|
};
|
|
223
223
|
if (typeof block.style == "string" && context.schema.styles.find((style) => style.name === block.style))
|
|
@@ -424,6 +424,7 @@ function sliceBlocks({
|
|
|
424
424
|
},
|
|
425
425
|
block,
|
|
426
426
|
options: {
|
|
427
|
+
removeUnusedMarkDefs: !0,
|
|
427
428
|
validateFields: !1
|
|
428
429
|
}
|
|
429
430
|
}) ?? block);
|
|
@@ -435,6 +436,7 @@ function sliceBlocks({
|
|
|
435
436
|
},
|
|
436
437
|
block: startBlock,
|
|
437
438
|
options: {
|
|
439
|
+
removeUnusedMarkDefs: !0,
|
|
438
440
|
validateFields: !1
|
|
439
441
|
}
|
|
440
442
|
}) : void 0, parsedEndBlock = endBlock ? parseBlock({
|
|
@@ -444,6 +446,7 @@ function sliceBlocks({
|
|
|
444
446
|
},
|
|
445
447
|
block: endBlock,
|
|
446
448
|
options: {
|
|
449
|
+
removeUnusedMarkDefs: !0,
|
|
447
450
|
validateFields: !1
|
|
448
451
|
}
|
|
449
452
|
}) : void 0;
|
|
@@ -464,6 +467,8 @@ export {
|
|
|
464
467
|
parseAnnotation,
|
|
465
468
|
parseBlock,
|
|
466
469
|
parseBlocks,
|
|
470
|
+
parseInlineObject,
|
|
471
|
+
parseSpan,
|
|
467
472
|
sliceBlocks,
|
|
468
473
|
spanSelectionPointToBlockOffset
|
|
469
474
|
};
|