@portabletext/editor 1.53.0 → 1.53.1

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.
Files changed (47) hide show
  1. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  2. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +144 -6
  3. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
  4. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs +6 -140
  5. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -1
  6. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  7. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +148 -10
  8. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
  9. package/lib/_chunks-es/selector.is-selection-expanded.js +6 -140
  10. package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -1
  11. package/lib/index.cjs +24 -24
  12. package/lib/index.cjs.map +1 -1
  13. package/lib/index.js +2 -2
  14. package/lib/selectors/index.cjs +10 -10
  15. package/lib/selectors/index.cjs.map +1 -1
  16. package/lib/selectors/index.d.cts +11 -11
  17. package/lib/selectors/index.d.ts +11 -11
  18. package/lib/selectors/index.js +4 -4
  19. package/lib/selectors/index.js.map +1 -1
  20. package/package.json +13 -13
  21. package/src/selectors/index.ts +13 -1
  22. package/src/selectors/selector.get-active-annotations.ts +2 -1
  23. package/src/selectors/selector.get-active-list-item.ts +1 -1
  24. package/src/selectors/selector.get-active-style.ts +1 -1
  25. package/src/selectors/selector.get-caret-word-selection.ts +1 -1
  26. package/src/selectors/selector.get-first-block.ts +14 -0
  27. package/src/selectors/selector.get-focus-block-object.ts +18 -0
  28. package/src/selectors/selector.get-focus-block.ts +23 -0
  29. package/src/selectors/selector.get-focus-child.ts +39 -0
  30. package/src/selectors/selector.get-focus-inline-object.ts +1 -1
  31. package/src/selectors/selector.get-focus-list-block.ts +18 -0
  32. package/src/selectors/selector.get-focus-span.ts +18 -0
  33. package/src/selectors/selector.get-focus-text-block.ts +18 -0
  34. package/src/selectors/selector.get-last-block.ts +16 -0
  35. package/src/selectors/selector.get-list-state.ts +2 -1
  36. package/src/selectors/selector.get-next-block.ts +38 -0
  37. package/src/selectors/selector.get-next-inline-object.ts +1 -1
  38. package/src/selectors/selector.get-previous-block.ts +35 -0
  39. package/src/selectors/selector.get-previous-inline-object.ts +1 -1
  40. package/src/selectors/selector.get-selected-blocks.ts +50 -0
  41. package/src/selectors/selector.get-selection-end-block.ts +4 -1
  42. package/src/selectors/selector.get-selection-start-block.ts +4 -1
  43. package/src/selectors/selector.get-text-before.ts +1 -1
  44. package/src/selectors/selector.get-trimmed-selection.ts +1 -1
  45. package/src/selectors/selector.is-active-annotation.ts +1 -1
  46. package/src/selectors/selector.is-selecting-entire-blocks.ts +2 -1
  47. package/src/selectors/selectors.ts +0 -299
package/lib/index.js CHANGED
@@ -14,8 +14,8 @@ import { getBlockEndPoint, isEmptyTextBlock, isEqualSelectionPoints } from "./_c
14
14
  import { isSelectionCollapsed, selectionPointToBlockOffset } from "./_chunks-es/util.selection-point-to-block-offset.js";
15
15
  import isEqual from "lodash/isEqual.js";
16
16
  import { isKeySegment, defineType, defineField } from "@sanity/types";
17
- import { isSelectionCollapsed as isSelectionCollapsed$1, getFocusTextBlock, getFocusSpan as getFocusSpan$1, getSelectedBlocks, isSelectionExpanded, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, getFocusBlock as getFocusBlock$1, getFocusBlockObject, getPreviousBlock, getNextBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock } from "./_chunks-es/selector.is-selection-expanded.js";
18
- import { getFocusInlineObject, isOverlappingSelection, isSelectingEntireBlocks, getTrimmedSelection, getSelectedSpans, getCaretWordSelection, isAtTheEndOfBlock, isAtTheStartOfBlock, isActiveAnnotation, isActiveDecorator, getSelectedTextBlocks, isActiveListItem, isActiveStyle, getActiveAnnotations as getActiveAnnotations$1 } from "./_chunks-es/selector.is-selecting-entire-blocks.js";
17
+ import { isSelectionCollapsed as isSelectionCollapsed$1, getFocusTextBlock, getFocusSpan as getFocusSpan$1, isSelectionExpanded, getFocusBlock as getFocusBlock$1 } from "./_chunks-es/selector.is-selection-expanded.js";
18
+ import { getFocusInlineObject, getSelectedBlocks, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, isOverlappingSelection, isSelectingEntireBlocks, getTrimmedSelection, getSelectedSpans, getCaretWordSelection, getFocusBlockObject, getPreviousBlock, getNextBlock, isAtTheEndOfBlock, isAtTheStartOfBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock, isActiveAnnotation, isActiveDecorator, getSelectedTextBlocks, isActiveListItem, isActiveStyle, getActiveAnnotations as getActiveAnnotations$1 } from "./_chunks-es/selector.is-selecting-entire-blocks.js";
19
19
  import getRandomValues from "get-random-values-esm";
20
20
  import { defineBehavior, forward, raise, effect } from "./behaviors/index.js";
21
21
  import uniq from "lodash/uniq.js";
@@ -98,7 +98,7 @@ function getPreviousListItem({
98
98
  level
99
99
  }) {
100
100
  return (snapshot) => {
101
- const previousBlock = selector_isSelectionExpanded.getPreviousBlock({
101
+ const previousBlock = selector_isSelectingEntireBlocks.getPreviousBlock({
102
102
  context: {
103
103
  ...snapshot.context
104
104
  }
@@ -137,11 +137,20 @@ exports.getActiveAnnotations = selector_isSelectingEntireBlocks.getActiveAnnotat
137
137
  exports.getActiveListItem = selector_isSelectingEntireBlocks.getActiveListItem;
138
138
  exports.getActiveStyle = selector_isSelectingEntireBlocks.getActiveStyle;
139
139
  exports.getCaretWordSelection = selector_isSelectingEntireBlocks.getCaretWordSelection;
140
+ exports.getFirstBlock = selector_isSelectingEntireBlocks.getFirstBlock;
141
+ exports.getFocusBlockObject = selector_isSelectingEntireBlocks.getFocusBlockObject;
140
142
  exports.getFocusInlineObject = selector_isSelectingEntireBlocks.getFocusInlineObject;
143
+ exports.getFocusListBlock = selector_isSelectingEntireBlocks.getFocusListBlock;
144
+ exports.getLastBlock = selector_isSelectingEntireBlocks.getLastBlock;
145
+ exports.getNextBlock = selector_isSelectingEntireBlocks.getNextBlock;
141
146
  exports.getNextInlineObject = selector_isSelectingEntireBlocks.getNextInlineObject;
147
+ exports.getPreviousBlock = selector_isSelectingEntireBlocks.getPreviousBlock;
148
+ exports.getSelectedBlocks = selector_isSelectingEntireBlocks.getSelectedBlocks;
142
149
  exports.getSelectedSpans = selector_isSelectingEntireBlocks.getSelectedSpans;
143
150
  exports.getSelectedTextBlocks = selector_isSelectingEntireBlocks.getSelectedTextBlocks;
151
+ exports.getSelectionEndBlock = selector_isSelectingEntireBlocks.getSelectionEndBlock;
144
152
  exports.getSelectionEndPoint = selector_isSelectingEntireBlocks.getSelectionEndPoint;
153
+ exports.getSelectionStartBlock = selector_isSelectingEntireBlocks.getSelectionStartBlock;
145
154
  exports.getTrimmedSelection = selector_isSelectingEntireBlocks.getTrimmedSelection;
146
155
  exports.isActiveAnnotation = selector_isSelectingEntireBlocks.isActiveAnnotation;
147
156
  exports.isActiveDecorator = selector_isSelectingEntireBlocks.isActiveDecorator;
@@ -153,21 +162,12 @@ exports.isOverlappingSelection = selector_isSelectingEntireBlocks.isOverlappingS
153
162
  exports.isPointAfterSelection = selector_isSelectingEntireBlocks.isPointAfterSelection;
154
163
  exports.isPointBeforeSelection = selector_isSelectingEntireBlocks.isPointBeforeSelection;
155
164
  exports.isSelectingEntireBlocks = selector_isSelectingEntireBlocks.isSelectingEntireBlocks;
156
- exports.getFirstBlock = selector_isSelectionExpanded.getFirstBlock;
157
165
  exports.getFocusBlock = selector_isSelectionExpanded.getFocusBlock;
158
- exports.getFocusBlockObject = selector_isSelectionExpanded.getFocusBlockObject;
159
166
  exports.getFocusChild = selector_isSelectionExpanded.getFocusChild;
160
- exports.getFocusListBlock = selector_isSelectionExpanded.getFocusListBlock;
161
167
  exports.getFocusSpan = selector_isSelectionExpanded.getFocusSpan;
162
168
  exports.getFocusTextBlock = selector_isSelectionExpanded.getFocusTextBlock;
163
- exports.getLastBlock = selector_isSelectionExpanded.getLastBlock;
164
- exports.getNextBlock = selector_isSelectionExpanded.getNextBlock;
165
- exports.getPreviousBlock = selector_isSelectionExpanded.getPreviousBlock;
166
169
  exports.getPreviousInlineObject = selector_isSelectionExpanded.getPreviousInlineObject;
167
- exports.getSelectedBlocks = selector_isSelectionExpanded.getSelectedBlocks;
168
170
  exports.getSelectedSlice = selector_isSelectionExpanded.getSelectedSlice;
169
- exports.getSelectionEndBlock = selector_isSelectionExpanded.getSelectionEndBlock;
170
- exports.getSelectionStartBlock = selector_isSelectionExpanded.getSelectionStartBlock;
171
171
  exports.getSelectionStartPoint = selector_isSelectionExpanded.getSelectionStartPoint;
172
172
  exports.getSelectionText = selector_isSelectionExpanded.getSelectionText;
173
173
  exports.isSelectionCollapsed = selector_isSelectionExpanded.isSelectionCollapsed;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-list-state.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.anchor)\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import type {KeyedSegment, PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildKeyFromSelectionPoint} from '../selection/selection-point'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.anchor)\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusTextBlock, getPreviousBlock} from './selectors'\n\n/**\n * @beta\n * Given the `path` of a block, this selector will return the \"list index\" of\n * the block.\n */\nexport function getListIndex({\n path,\n}: {\n path: BlockPath\n}): EditorSelector<number | undefined> {\n return (snapshot) => {\n const selection = {\n anchor: {\n path,\n offset: 0,\n },\n focus: {\n path,\n offset: 0,\n },\n }\n\n const focusTextBlock = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!focusTextBlock) {\n return undefined\n }\n\n if (\n focusTextBlock.node.listItem === undefined ||\n focusTextBlock.node.level === undefined\n ) {\n return undefined\n }\n\n const previousListItem = getPreviousListItem({\n listItem: focusTextBlock.node.listItem,\n level: focusTextBlock.node.level,\n })({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!previousListItem) {\n return 1\n }\n\n if (previousListItem.node.listItem !== focusTextBlock.node.listItem) {\n return 1\n }\n\n if (\n previousListItem.node.level !== undefined &&\n previousListItem.node.level < focusTextBlock.node.level\n ) {\n return 1\n }\n\n const previousListItemListState = getListIndex({\n path: previousListItem.path,\n })(snapshot)\n\n if (previousListItemListState === undefined) {\n return 1\n }\n\n return previousListItemListState + 1\n }\n}\n\nfunction getPreviousListItem({\n listItem,\n level,\n}: {\n listItem: string\n level: number\n}): EditorSelector<\n | {\n node: PortableTextTextBlock\n path: [{_key: string}]\n }\n | undefined\n> {\n return (snapshot) => {\n const previousBlock = getPreviousBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n },\n })\n\n if (!previousBlock) {\n return undefined\n }\n\n if (!isTextBlock(snapshot.context, previousBlock.node)) {\n return undefined\n }\n\n if (\n previousBlock.node.listItem === undefined ||\n previousBlock.node.level === undefined\n ) {\n return undefined\n }\n\n if (previousBlock.node.listItem !== listItem) {\n return undefined\n }\n\n if (previousBlock.node.level === level) {\n return {\n node: previousBlock.node,\n path: previousBlock.path,\n }\n }\n\n if (previousBlock.node.level < level) {\n return undefined\n }\n\n return getPreviousListItem({\n listItem,\n level,\n })({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: {\n path: previousBlock.path,\n offset: 0,\n },\n focus: {\n path: previousBlock.path,\n offset: 0,\n },\n },\n },\n })\n }\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n"],"names":["getAnchorBlock","snapshot","context","selection","key","getBlockKeyFromSelectionPoint","anchor","node","value","find","block","_key","undefined","path","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","getChildKeyFromSelectionPoint","children","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getListIndex","offset","focus","focusTextBlock","getFocusTextBlock","listItem","level","previousListItem","getPreviousListItem","previousListItemListState","previousBlock","getPreviousBlock","getSelection","getValue"],"mappings":";;;AAOO,MAAMA,iBAERC,CAAa,aAAA;AACZ,MAAA,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,eAA8BJ,8BAAAA,SAASC,QAAQC,UAAUG,MAAM,GAErEC,OAAOH,MACTH,SAASC,QAAQM,MAAMC,KAAMC,WAAUA,MAAMC,SAASP,GAAG,IACzDQ;AAEJ,SAAOL,QAAQH,MAAM;AAAA,IAACG;AAAAA,IAAMM,MAAM,CAAC;AAAA,MAACF,MAAMP;AAAAA,IAAI,CAAA;AAAA,EAAA,IAAKQ;AACrD,GCbaE,qBAERb,CAAa,aAAA;AACVc,QAAAA,cAAcf,eAAeC,QAAQ;AAE3C,SAAOc,eAAeC,eAAAA,YAAYf,SAASC,SAASa,YAAYR,IAAI,IAChE;AAAA,IAACA,MAAMQ,YAAYR;AAAAA,IAAMM,MAAME,YAAYF;AAAAA,EAAAA,IAC3CD;AACN,GCPaK,iBAMRhB,CAAa,aAAA;AACZ,MAAA,CAACA,SAASC,QAAQC;AACpB;AAGIY,QAAAA,cAAcD,mBAAmBb,QAAQ;AAE/C,MAAI,CAACc;AACH;AAGF,QAAMX,MAAMc,eAA8BjB,8BAAAA,SAASC,QAAQC,UAAUG,MAAM,GAErEC,OAAOH,MACTW,YAAYR,KAAKY,SAASV,KAAMW,UAASA,KAAKT,SAASP,GAAG,IAC1DQ;AAEJ,SAAOL,QAAQH,MACX;AAAA,IAACG;AAAAA,IAAMM,MAAM,CAAC,GAAGE,YAAYF,MAAM,YAAY;AAAA,MAACF,MAAMP;AAAAA,IAAI,CAAA;AAAA,EAAA,IAC1DQ;AACN,GC3BaS,gBAGRpB,C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AA,gBACpBqB,QAAQ;AAAA,cACV;AAAA,cACAC,OAAO;AAAA,gBACLtB,MAAM8B,cAAc9B;AAAAA,gBACpBqB,QAAQ;AAAA,cAAA;AAAA,YACV;AAAA,UACF;AAAA,QACF,CACD;AAAA,IAAA;AAAA,EACH;AACF;ACtJaW,MAAAA,eAAiD5C,CACrDA,aAAAA,SAASC,QAAQC,WCDb2C,WACX7C,CAEOA,aAAAA,SAASC,QAAQM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-list-state.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.anchor)\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import type {KeyedSegment, PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildKeyFromSelectionPoint} from '../selection/selection-point'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.anchor)\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getPreviousBlock} from './selector.get-previous-block'\n\n/**\n * @beta\n * Given the `path` of a block, this selector will return the \"list index\" of\n * the block.\n */\nexport function getListIndex({\n path,\n}: {\n path: BlockPath\n}): EditorSelector<number | undefined> {\n return (snapshot) => {\n const selection = {\n anchor: {\n path,\n offset: 0,\n },\n focus: {\n path,\n offset: 0,\n },\n }\n\n const focusTextBlock = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!focusTextBlock) {\n return undefined\n }\n\n if (\n focusTextBlock.node.listItem === undefined ||\n focusTextBlock.node.level === undefined\n ) {\n return undefined\n }\n\n const previousListItem = getPreviousListItem({\n listItem: focusTextBlock.node.listItem,\n level: focusTextBlock.node.level,\n })({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!previousListItem) {\n return 1\n }\n\n if (previousListItem.node.listItem !== focusTextBlock.node.listItem) {\n return 1\n }\n\n if (\n previousListItem.node.level !== undefined &&\n previousListItem.node.level < focusTextBlock.node.level\n ) {\n return 1\n }\n\n const previousListItemListState = getListIndex({\n path: previousListItem.path,\n })(snapshot)\n\n if (previousListItemListState === undefined) {\n return 1\n }\n\n return previousListItemListState + 1\n }\n}\n\nfunction getPreviousListItem({\n listItem,\n level,\n}: {\n listItem: string\n level: number\n}): EditorSelector<\n | {\n node: PortableTextTextBlock\n path: [{_key: string}]\n }\n | undefined\n> {\n return (snapshot) => {\n const previousBlock = getPreviousBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n },\n })\n\n if (!previousBlock) {\n return undefined\n }\n\n if (!isTextBlock(snapshot.context, previousBlock.node)) {\n return undefined\n }\n\n if (\n previousBlock.node.listItem === undefined ||\n previousBlock.node.level === undefined\n ) {\n return undefined\n }\n\n if (previousBlock.node.listItem !== listItem) {\n return undefined\n }\n\n if (previousBlock.node.level === level) {\n return {\n node: previousBlock.node,\n path: previousBlock.path,\n }\n }\n\n if (previousBlock.node.level < level) {\n return undefined\n }\n\n return getPreviousListItem({\n listItem,\n level,\n })({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: {\n path: previousBlock.path,\n offset: 0,\n },\n focus: {\n path: previousBlock.path,\n offset: 0,\n },\n },\n },\n })\n }\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n"],"names":["getAnchorBlock","snapshot","context","selection","key","getBlockKeyFromSelectionPoint","anchor","node","value","find","block","_key","undefined","path","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","getChildKeyFromSelectionPoint","children","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getListIndex","offset","focus","focusTextBlock","getFocusTextBlock","listItem","level","previousListItem","getPreviousListItem","previousListItemListState","previousBlock","getPreviousBlock","getSelection","getValue"],"mappings":";;;AAOO,MAAMA,iBAERC,CAAa,aAAA;AACZ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A,aAAAA,SAASC,QAAQM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -281,7 +281,7 @@ export declare const getCaretWordSelection: EditorSelector<EditorSelection>
281
281
  export declare const getFirstBlock: EditorSelector<
282
282
  | {
283
283
  node: PortableTextBlock
284
- path: [KeyedSegment]
284
+ path: BlockPath
285
285
  }
286
286
  | undefined
287
287
  >
@@ -292,7 +292,7 @@ export declare const getFirstBlock: EditorSelector<
292
292
  export declare const getFocusBlock: EditorSelector<
293
293
  | {
294
294
  node: PortableTextBlock
295
- path: [KeyedSegment]
295
+ path: BlockPath
296
296
  }
297
297
  | undefined
298
298
  >
@@ -303,7 +303,7 @@ export declare const getFocusBlock: EditorSelector<
303
303
  export declare const getFocusBlockObject: EditorSelector<
304
304
  | {
305
305
  node: PortableTextObject
306
- path: [KeyedSegment]
306
+ path: BlockPath
307
307
  }
308
308
  | undefined
309
309
  >
@@ -336,7 +336,7 @@ export declare const getFocusInlineObject: EditorSelector<
336
336
  export declare const getFocusListBlock: EditorSelector<
337
337
  | {
338
338
  node: PortableTextListBlock
339
- path: [KeyedSegment]
339
+ path: BlockPath
340
340
  }
341
341
  | undefined
342
342
  >
@@ -358,7 +358,7 @@ export declare const getFocusSpan: EditorSelector<
358
358
  export declare const getFocusTextBlock: EditorSelector<
359
359
  | {
360
360
  node: PortableTextTextBlock
361
- path: [KeyedSegment]
361
+ path: BlockPath
362
362
  }
363
363
  | undefined
364
364
  >
@@ -369,7 +369,7 @@ export declare const getFocusTextBlock: EditorSelector<
369
369
  export declare const getLastBlock: EditorSelector<
370
370
  | {
371
371
  node: PortableTextBlock
372
- path: [KeyedSegment]
372
+ path: BlockPath
373
373
  }
374
374
  | undefined
375
375
  >
@@ -391,7 +391,7 @@ export declare function getListIndex({
391
391
  export declare const getNextBlock: EditorSelector<
392
392
  | {
393
393
  node: PortableTextBlock
394
- path: [KeyedSegment]
394
+ path: BlockPath
395
395
  }
396
396
  | undefined
397
397
  >
@@ -413,7 +413,7 @@ export declare const getNextInlineObject: EditorSelector<
413
413
  export declare const getPreviousBlock: EditorSelector<
414
414
  | {
415
415
  node: PortableTextBlock
416
- path: [KeyedSegment]
416
+ path: BlockPath
417
417
  }
418
418
  | undefined
419
419
  >
@@ -435,7 +435,7 @@ export declare const getPreviousInlineObject: EditorSelector<
435
435
  export declare const getSelectedBlocks: EditorSelector<
436
436
  Array<{
437
437
  node: PortableTextBlock
438
- path: [KeyedSegment]
438
+ path: BlockPath
439
439
  }>
440
440
  >
441
441
 
@@ -476,7 +476,7 @@ export {getSelection_2 as getSelection}
476
476
  export declare const getSelectionEndBlock: EditorSelector<
477
477
  | {
478
478
  node: PortableTextBlock
479
- path: [KeyedSegment]
479
+ path: BlockPath
480
480
  }
481
481
  | undefined
482
482
  >
@@ -494,7 +494,7 @@ export declare const getSelectionEndPoint: EditorSelector<
494
494
  export declare const getSelectionStartBlock: EditorSelector<
495
495
  | {
496
496
  node: PortableTextBlock
497
- path: [KeyedSegment]
497
+ path: BlockPath
498
498
  }
499
499
  | undefined
500
500
  >
@@ -281,7 +281,7 @@ export declare const getCaretWordSelection: EditorSelector<EditorSelection>
281
281
  export declare const getFirstBlock: EditorSelector<
282
282
  | {
283
283
  node: PortableTextBlock
284
- path: [KeyedSegment]
284
+ path: BlockPath
285
285
  }
286
286
  | undefined
287
287
  >
@@ -292,7 +292,7 @@ export declare const getFirstBlock: EditorSelector<
292
292
  export declare const getFocusBlock: EditorSelector<
293
293
  | {
294
294
  node: PortableTextBlock
295
- path: [KeyedSegment]
295
+ path: BlockPath
296
296
  }
297
297
  | undefined
298
298
  >
@@ -303,7 +303,7 @@ export declare const getFocusBlock: EditorSelector<
303
303
  export declare const getFocusBlockObject: EditorSelector<
304
304
  | {
305
305
  node: PortableTextObject
306
- path: [KeyedSegment]
306
+ path: BlockPath
307
307
  }
308
308
  | undefined
309
309
  >
@@ -336,7 +336,7 @@ export declare const getFocusInlineObject: EditorSelector<
336
336
  export declare const getFocusListBlock: EditorSelector<
337
337
  | {
338
338
  node: PortableTextListBlock
339
- path: [KeyedSegment]
339
+ path: BlockPath
340
340
  }
341
341
  | undefined
342
342
  >
@@ -358,7 +358,7 @@ export declare const getFocusSpan: EditorSelector<
358
358
  export declare const getFocusTextBlock: EditorSelector<
359
359
  | {
360
360
  node: PortableTextTextBlock
361
- path: [KeyedSegment]
361
+ path: BlockPath
362
362
  }
363
363
  | undefined
364
364
  >
@@ -369,7 +369,7 @@ export declare const getFocusTextBlock: EditorSelector<
369
369
  export declare const getLastBlock: EditorSelector<
370
370
  | {
371
371
  node: PortableTextBlock
372
- path: [KeyedSegment]
372
+ path: BlockPath
373
373
  }
374
374
  | undefined
375
375
  >
@@ -391,7 +391,7 @@ export declare function getListIndex({
391
391
  export declare const getNextBlock: EditorSelector<
392
392
  | {
393
393
  node: PortableTextBlock
394
- path: [KeyedSegment]
394
+ path: BlockPath
395
395
  }
396
396
  | undefined
397
397
  >
@@ -413,7 +413,7 @@ export declare const getNextInlineObject: EditorSelector<
413
413
  export declare const getPreviousBlock: EditorSelector<
414
414
  | {
415
415
  node: PortableTextBlock
416
- path: [KeyedSegment]
416
+ path: BlockPath
417
417
  }
418
418
  | undefined
419
419
  >
@@ -435,7 +435,7 @@ export declare const getPreviousInlineObject: EditorSelector<
435
435
  export declare const getSelectedBlocks: EditorSelector<
436
436
  Array<{
437
437
  node: PortableTextBlock
438
- path: [KeyedSegment]
438
+ path: BlockPath
439
439
  }>
440
440
  >
441
441
 
@@ -476,7 +476,7 @@ export {getSelection_2 as getSelection}
476
476
  export declare const getSelectionEndBlock: EditorSelector<
477
477
  | {
478
478
  node: PortableTextBlock
479
- path: [KeyedSegment]
479
+ path: BlockPath
480
480
  }
481
481
  | undefined
482
482
  >
@@ -494,7 +494,7 @@ export declare const getSelectionEndPoint: EditorSelector<
494
494
  export declare const getSelectionStartBlock: EditorSelector<
495
495
  | {
496
496
  node: PortableTextBlock
497
- path: [KeyedSegment]
497
+ path: BlockPath
498
498
  }
499
499
  | undefined
500
500
  >
@@ -1,9 +1,9 @@
1
- import { getSelectionEndPoint } from "../_chunks-es/selector.is-selecting-entire-blocks.js";
2
- import { getActiveAnnotations, getActiveListItem, getActiveStyle, getCaretWordSelection, getFocusInlineObject, getNextInlineObject, getSelectedSpans, getSelectedTextBlocks, getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks } from "../_chunks-es/selector.is-selecting-entire-blocks.js";
1
+ import { getSelectionEndPoint, getPreviousBlock } from "../_chunks-es/selector.is-selecting-entire-blocks.js";
2
+ import { getActiveAnnotations, getActiveListItem, getActiveStyle, getCaretWordSelection, getFirstBlock, getFocusBlockObject, getFocusInlineObject, getFocusListBlock, getLastBlock, getNextBlock, getNextInlineObject, getSelectedBlocks, getSelectedSpans, getSelectedTextBlocks, getSelectionEndBlock, getSelectionStartBlock, getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks } from "../_chunks-es/selector.is-selecting-entire-blocks.js";
3
3
  import { getBlockKeyFromSelectionPoint, isTextBlock, getChildKeyFromSelectionPoint, spanSelectionPointToBlockOffset } from "../_chunks-es/selection-point.js";
4
4
  import { isPortableTextSpan } from "@sanity/types";
5
- import { getSelectionStartPoint, getFocusTextBlock, getPreviousBlock } from "../_chunks-es/selector.is-selection-expanded.js";
6
- import { getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusListBlock, getFocusSpan, getLastBlock, getNextBlock, getPreviousInlineObject, getSelectedBlocks, getSelectedSlice, getSelectionEndBlock, getSelectionStartBlock, getSelectionText, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-selection-expanded.js";
5
+ import { getSelectionStartPoint, getFocusTextBlock } from "../_chunks-es/selector.is-selection-expanded.js";
6
+ import { getFocusBlock, getFocusChild, getFocusSpan, getPreviousInlineObject, getSelectedSlice, getSelectionText, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-selection-expanded.js";
7
7
  import { getBlockTextBefore } from "../_chunks-es/selector.get-text-before.js";
8
8
  const getAnchorBlock = (snapshot) => {
9
9
  if (!snapshot.context.selection)
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-list-state.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.anchor)\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import type {KeyedSegment, PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildKeyFromSelectionPoint} from '../selection/selection-point'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.anchor)\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusTextBlock, getPreviousBlock} from './selectors'\n\n/**\n * @beta\n * Given the `path` of a block, this selector will return the \"list index\" of\n * the block.\n */\nexport function getListIndex({\n path,\n}: {\n path: BlockPath\n}): EditorSelector<number | undefined> {\n return (snapshot) => {\n const selection = {\n anchor: {\n path,\n offset: 0,\n },\n focus: {\n path,\n offset: 0,\n },\n }\n\n const focusTextBlock = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!focusTextBlock) {\n return undefined\n }\n\n if (\n focusTextBlock.node.listItem === undefined ||\n focusTextBlock.node.level === undefined\n ) {\n return undefined\n }\n\n const previousListItem = getPreviousListItem({\n listItem: focusTextBlock.node.listItem,\n level: focusTextBlock.node.level,\n })({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!previousListItem) {\n return 1\n }\n\n if (previousListItem.node.listItem !== focusTextBlock.node.listItem) {\n return 1\n }\n\n if (\n previousListItem.node.level !== undefined &&\n previousListItem.node.level < focusTextBlock.node.level\n ) {\n return 1\n }\n\n const previousListItemListState = getListIndex({\n path: previousListItem.path,\n })(snapshot)\n\n if (previousListItemListState === undefined) {\n return 1\n }\n\n return previousListItemListState + 1\n }\n}\n\nfunction getPreviousListItem({\n listItem,\n level,\n}: {\n listItem: string\n level: number\n}): EditorSelector<\n | {\n node: PortableTextTextBlock\n path: [{_key: string}]\n }\n | undefined\n> {\n return (snapshot) => {\n const previousBlock = getPreviousBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n },\n })\n\n if (!previousBlock) {\n return undefined\n }\n\n if (!isTextBlock(snapshot.context, previousBlock.node)) {\n return undefined\n }\n\n if (\n previousBlock.node.listItem === undefined ||\n previousBlock.node.level === undefined\n ) {\n return undefined\n }\n\n if (previousBlock.node.listItem !== listItem) {\n return undefined\n }\n\n if (previousBlock.node.level === level) {\n return {\n node: previousBlock.node,\n path: previousBlock.path,\n }\n }\n\n if (previousBlock.node.level < level) {\n return undefined\n }\n\n return getPreviousListItem({\n listItem,\n level,\n })({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: {\n path: previousBlock.path,\n offset: 0,\n },\n focus: {\n path: previousBlock.path,\n offset: 0,\n },\n },\n },\n })\n }\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n"],"names":["getAnchorBlock","snapshot","context","selection","key","getBlockKeyFromSelectionPoint","anchor","node","value","find","block","_key","undefined","path","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","getChildKeyFromSelectionPoint","children","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getListIndex","offset","focus","focusTextBlock","getFocusTextBlock","listItem","level","previousListItem","getPreviousListItem","previousListItemListState","previousBlock","getPreviousBlock","getSelection","getValue"],"mappings":";;;;;;;AAOO,MAAMA,iBAERC,CAAa,aAAA;AACZ,MAAA,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,8BAA8BJ,SAASC,QAAQC,UAAUG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,QAAQ;AAEPyC,WAAAA,8BAA8B9B,SACzB,IAGF8B,4BAA4B;AAAA,EACrC;AACF;AAEA,SAASD,oBAAoB;AAAA,EAC3BH;AAAAA,EACAC;AAIF,GAME;AACA,SAAQtC,CAAa,aAAA;AACnB,UAAM0C,gBAAgBC,iBAAiB;AAAA,MAErC1C,SAAS;AAAA,QACP,GAAGD,SAASC;AAAAA,MAAAA;AAAAA,IACd,CACD;AAED,QAAKyC,iBAIA3B,YAAYf,SAASC,SAASyC,cAAcpC,IAAI,KAKnDoC,EAAcpC,cAAAA,KAAK+B,aAAa1B,UAChC+B,cAAcpC,KAAKgC,UAAU3B,WAK3B+B,cAAcpC,KAAK+B,aAAaA,UAIpC;AAAIK,UAAAA,cAAcpC,KAAKgC,UAAUA;AACxB,eAAA;AAAA,UACLhC,MAAMoC,cAAcpC;AAAAA,UACpBM,MAAM8B,cAAc9B;AAAAA,QACtB;AAGE8B,UAAAA,EAAAA,cAAcpC,KAAKgC,QAAQA;AAI/B,eAAOE,oBAAoB;AAAA,UACzBH;AAAAA,UACAC;AAAAA,QAAAA,CACD,EAAE;AAAA,UACD,GAAGtC;AAAAA,UACHC,SAAS;AAAA,YACP,GAAGD,SAASC;AAAAA,YACZC,WAAW;AAAA,cACTG,QAAQ;AAAA,gBACNO,MAAM8B,cAAc9B;AAAAA,gBACpBqB,QAAQ;AAAA,cACV;AAAA,cACAC,OAAO;AAAA,gBACLtB,MAAM8B,cAAc9B;AAAAA,gBACpBqB,QAAQ;AAAA,cAAA;AAAA,YACV;AAAA,UACF;AAAA,QACF,CACD;AAAA,IAAA;AAAA,EACH;AACF;ACtJaW,MAAAA,eAAiD5C,CACrDA,aAAAA,SAASC,QAAQC,WCDb2C,WACX7C,CAEOA,aAAAA,SAASC,QAAQM;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-list-state.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.anchor)\n\n const node = key\n ? snapshot.context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import type {KeyedSegment, PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildKeyFromSelectionPoint} from '../selection/selection-point'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.anchor)\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import type {KeyedSegment} from '@portabletext/patches'\nimport {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlock} from '../internal-utils/parse-blocks'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getPreviousBlock} from './selector.get-previous-block'\n\n/**\n * @beta\n * Given the `path` of a block, this selector will return the \"list index\" of\n * the block.\n */\nexport function getListIndex({\n path,\n}: {\n path: BlockPath\n}): EditorSelector<number | undefined> {\n return (snapshot) => {\n const selection = {\n anchor: {\n path,\n offset: 0,\n },\n focus: {\n path,\n offset: 0,\n },\n }\n\n const focusTextBlock = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!focusTextBlock) {\n return undefined\n }\n\n if (\n focusTextBlock.node.listItem === undefined ||\n focusTextBlock.node.level === undefined\n ) {\n return undefined\n }\n\n const previousListItem = getPreviousListItem({\n listItem: focusTextBlock.node.listItem,\n level: focusTextBlock.node.level,\n })({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!previousListItem) {\n return 1\n }\n\n if (previousListItem.node.listItem !== focusTextBlock.node.listItem) {\n return 1\n }\n\n if (\n previousListItem.node.level !== undefined &&\n previousListItem.node.level < focusTextBlock.node.level\n ) {\n return 1\n }\n\n const previousListItemListState = getListIndex({\n path: previousListItem.path,\n })(snapshot)\n\n if (previousListItemListState === undefined) {\n return 1\n }\n\n return previousListItemListState + 1\n }\n}\n\nfunction getPreviousListItem({\n listItem,\n level,\n}: {\n listItem: string\n level: number\n}): EditorSelector<\n | {\n node: PortableTextTextBlock\n path: [{_key: string}]\n }\n | undefined\n> {\n return (snapshot) => {\n const previousBlock = getPreviousBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n },\n })\n\n if (!previousBlock) {\n return undefined\n }\n\n if (!isTextBlock(snapshot.context, previousBlock.node)) {\n return undefined\n }\n\n if (\n previousBlock.node.listItem === undefined ||\n previousBlock.node.level === undefined\n ) {\n return undefined\n }\n\n if (previousBlock.node.listItem !== listItem) {\n return undefined\n }\n\n if (previousBlock.node.level === level) {\n return {\n node: previousBlock.node,\n path: previousBlock.path,\n }\n }\n\n if (previousBlock.node.level < level) {\n return undefined\n }\n\n return getPreviousListItem({\n listItem,\n level,\n })({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: {\n path: previousBlock.path,\n offset: 0,\n },\n focus: {\n path: previousBlock.path,\n offset: 0,\n },\n },\n },\n })\n }\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n"],"names":["getAnchorBlock","snapshot","context","selection","key","getBlockKeyFromSelectionPoint","anchor","node","value","find","block","_key","undefined","path","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","getChildKeyFromSelectionPoint","children","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getListIndex","offset","focus","focusTextBlock","getFocusTextBlock","listItem","level","previousListItem","getPreviousListItem","previousListItemListState","previousBlock","getPreviousBlock","getSelection","getValue"],"mappings":";;;;;;;AAOO,MAAMA,iBAERC,CAAa,aAAA;AACZ,MAAA,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,8BAA8BJ,SAASC,QAAQC,UAAUG,MAAM,GAErEC,OAAOH,MACTH,SAASC,QAAQM,MAAMC,KAAMC,WAAUA,MAAMC,SAASP,GAAG,IACzDQ;AAEJ,SAAOL,QAAQH,MAAM;AAAA,IAACG;AAAAA,IAAMM,MAAM,CAAC;AAAA,MAACF,MAAMP;AAAAA,IAAI,CAAA;AAAA,EAAA,IAAKQ;AACrD,GCbaE,qBAERb,CAAa,aAAA;AACVc,QAAAA,cAAcf,eAAeC,QAAQ;AAE3C,SAAOc,eAAeC,YAAYf,SAASC,SAASa,YAAYR,IAAI,IAChE;AAAA,IAACA,MAAMQ,YAAYR;AAAAA,I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AcpC,KAAKgC,UAAU3B,WAK3B+B,cAAcpC,KAAK+B,aAAaA,UAIpC;AAAIK,UAAAA,cAAcpC,KAAKgC,UAAUA;AACxB,eAAA;AAAA,UACLhC,MAAMoC,cAAcpC;AAAAA,UACpBM,MAAM8B,cAAc9B;AAAAA,QACtB;AAGE8B,UAAAA,EAAAA,cAAcpC,KAAKgC,QAAQA;AAI/B,eAAOE,oBAAoB;AAAA,UACzBH;AAAAA,UACAC;AAAAA,QAAAA,CACD,EAAE;AAAA,UACD,GAAGtC;AAAAA,UACHC,SAAS;AAAA,YACP,GAAGD,SAASC;AAAAA,YACZC,WAAW;AAAA,cACTG,QAAQ;AAAA,gBACNO,MAAM8B,cAAc9B;AAAAA,gBACpBqB,QAAQ;AAAA,cACV;AAAA,cACAC,OAAO;AAAA,gBACLtB,MAAM8B,cAAc9B;AAAAA,gBACpBqB,QAAQ;AAAA,cAAA;AAAA,YACV;AAAA,UACF;AAAA,QACF,CACD;AAAA,IAAA;AAAA,EACH;AACF;ACvJaW,MAAAA,eAAiD5C,CACrDA,aAAAA,SAASC,QAAQC,WCDb2C,WACX7C,CAEOA,aAAAA,SAASC,QAAQM;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.53.0",
3
+ "version": "1.53.1",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -74,35 +74,35 @@
74
74
  "immer": "^10.1.1",
75
75
  "lodash": "^4.17.21",
76
76
  "lodash.startcase": "^4.4.0",
77
- "react-compiler-runtime": "19.1.0-rc.1",
77
+ "react-compiler-runtime": "19.1.0-rc.2",
78
78
  "slate": "0.115.1",
79
79
  "slate-dom": "^0.114.0",
80
80
  "slate-react": "0.114.2",
81
81
  "use-effect-event": "^1.0.2",
82
82
  "xstate": "^5.19.4",
83
- "@portabletext/block-tools": "1.1.30",
83
+ "@portabletext/block-tools": "1.1.31",
84
84
  "@portabletext/patches": "1.1.4"
85
85
  },
86
86
  "devDependencies": {
87
87
  "@portabletext/toolkit": "^2.0.17",
88
88
  "@sanity/diff-match-patch": "^3.2.0",
89
- "@sanity/pkg-utils": "^7.2.4",
90
- "@sanity/schema": "^3.92.0",
91
- "@sanity/types": "^3.92.0",
89
+ "@sanity/pkg-utils": "^7.2.6",
90
+ "@sanity/schema": "^3.93.0",
91
+ "@sanity/types": "^3.93.0",
92
92
  "@testing-library/react": "^16.3.0",
93
93
  "@types/debug": "^4.1.12",
94
94
  "@types/lodash": "^4.17.16",
95
95
  "@types/lodash.startcase": "^4.4.9",
96
96
  "@types/react": "^19.1.8",
97
97
  "@types/react-dom": "^19.1.6",
98
- "@typescript-eslint/eslint-plugin": "^8.33.0",
99
- "@typescript-eslint/parser": "^8.33.0",
98
+ "@typescript-eslint/eslint-plugin": "^8.34.0",
99
+ "@typescript-eslint/parser": "^8.34.0",
100
100
  "@vitejs/plugin-react": "^4.5.2",
101
101
  "@vitest/browser": "^3.2.3",
102
102
  "@vitest/coverage-istanbul": "^3.2.3",
103
- "babel-plugin-react-compiler": "19.1.0-rc.1",
103
+ "babel-plugin-react-compiler": "19.1.0-rc.2",
104
104
  "eslint": "8.57.1",
105
- "eslint-plugin-react-hooks": "0.0.0-experimental-f9ae0a4c-20250527",
105
+ "eslint-plugin-react-hooks": "0.0.0-experimental-12bc60f5-20250613",
106
106
  "jsdom": "^26.0.0",
107
107
  "react": "^19.1.0",
108
108
  "react-dom": "^19.1.0",
@@ -110,12 +110,12 @@
110
110
  "typescript": "5.8.3",
111
111
  "vite": "^6.2.5",
112
112
  "vitest": "^3.2.3",
113
- "vitest-browser-react": "^0.2.0",
113
+ "vitest-browser-react": "^0.3.0",
114
114
  "racejar": "1.2.6"
115
115
  },
116
116
  "peerDependencies": {
117
- "@sanity/schema": "^3.92.0",
118
- "@sanity/types": "^3.92.0",
117
+ "@sanity/schema": "^3.93.0",
118
+ "@sanity/types": "^3.93.0",
119
119
  "react": "^16.9 || ^17 || ^18 || ^19",
120
120
  "rxjs": "^7.8.2"
121
121
  },
@@ -7,15 +7,28 @@ export {getAnchorSpan} from './selector.get-anchor-span'
7
7
  export {getAnchorTextBlock} from './selector.get-anchor-text-block'
8
8
  export {getBlockOffsets} from './selector.get-block-offsets'
9
9
  export {getCaretWordSelection} from './selector.get-caret-word-selection'
10
+ export {getFirstBlock} from './selector.get-first-block'
11
+ export {getFocusBlock} from './selector.get-focus-block'
12
+ export {getFocusBlockObject} from './selector.get-focus-block-object'
13
+ export {getFocusChild} from './selector.get-focus-child'
10
14
  export {getFocusInlineObject} from './selector.get-focus-inline-object'
15
+ export {getFocusListBlock} from './selector.get-focus-list-block'
16
+ export {getFocusSpan} from './selector.get-focus-span'
17
+ export {getFocusTextBlock} from './selector.get-focus-text-block'
18
+ export {getLastBlock} from './selector.get-last-block'
11
19
  export {getListIndex} from './selector.get-list-state'
20
+ export {getNextBlock} from './selector.get-next-block'
12
21
  export {getNextInlineObject} from './selector.get-next-inline-object'
22
+ export {getPreviousBlock} from './selector.get-previous-block'
13
23
  export {getPreviousInlineObject} from './selector.get-previous-inline-object'
24
+ export {getSelectedBlocks} from './selector.get-selected-blocks'
14
25
  export {getSelectedSlice} from './selector.get-selected-slice'
15
26
  export {getSelectedSpans} from './selector.get-selected-spans'
16
27
  export {getSelectedTextBlocks} from './selector.get-selected-text-blocks'
17
28
  export {getSelection} from './selector.get-selection'
29
+ export {getSelectionEndBlock} from './selector.get-selection-end-block'
18
30
  export {getSelectionEndPoint} from './selector.get-selection-end-point'
31
+ export {getSelectionStartBlock} from './selector.get-selection-start-block'
19
32
  export {getSelectionStartPoint} from './selector.get-selection-start-point'
20
33
  export {getSelectionText} from './selector.get-selection-text'
21
34
  export {getBlockTextBefore} from './selector.get-text-before'
@@ -33,4 +46,3 @@ export {isPointBeforeSelection} from './selector.is-point-before-selection'
33
46
  export {isSelectingEntireBlocks} from './selector.is-selecting-entire-blocks'
34
47
  export {isSelectionCollapsed} from './selector.is-selection-collapsed'
35
48
  export {isSelectionExpanded} from './selector.is-selection-expanded'
36
- export * from './selectors'
@@ -1,9 +1,10 @@
1
1
  import type {PortableTextObject} from '@sanity/types'
2
2
  import type {EditorSelector} from '../editor/editor-selector'
3
3
  import {isTextBlock} from '../internal-utils/parse-blocks'
4
+ import {getFocusSpan} from './selector.get-focus-span'
5
+ import {getSelectedBlocks} from './selector.get-selected-blocks'
4
6
  import {getSelectedSpans} from './selector.get-selected-spans'
5
7
  import {isSelectionCollapsed} from './selector.is-selection-collapsed'
6
- import {getFocusSpan, getSelectedBlocks} from './selectors'
7
8
 
8
9
  /**
9
10
  * @public
@@ -1,7 +1,7 @@
1
1
  import type {PortableTextListBlock} from '@sanity/types'
2
2
  import type {EditorSelector} from '../editor/editor-selector'
3
3
  import {isTextBlock} from '../internal-utils/parse-blocks'
4
- import {getSelectedBlocks} from './selectors'
4
+ import {getSelectedBlocks} from './selector.get-selected-blocks'
5
5
 
6
6
  /**
7
7
  * @public
@@ -1,7 +1,7 @@
1
1
  import type {PortableTextTextBlock} from '@sanity/types'
2
2
  import type {EditorSelector} from '../editor/editor-selector'
3
3
  import {isTextBlock} from '../internal-utils/parse-blocks'
4
- import {getSelectedBlocks} from './selectors'
4
+ import {getSelectedBlocks} from './selector.get-selected-blocks'
5
5
 
6
6
  /**
7
7
  * @public
@@ -7,13 +7,13 @@ import {
7
7
  getBlockStartPoint,
8
8
  spanSelectionPointToBlockOffset,
9
9
  } from '../utils'
10
+ import {getFocusTextBlock} from './selector.get-focus-text-block'
10
11
  import {getNextInlineObject} from './selector.get-next-inline-object'
11
12
  import {getPreviousInlineObject} from './selector.get-previous-inline-object'
12
13
  import {getSelectionStartPoint} from './selector.get-selection-start-point'
13
14
  import {getSelectionText} from './selector.get-selection-text'
14
15
  import {isSelectionCollapsed} from './selector.is-selection-collapsed'
15
16
  import {isSelectionExpanded} from './selector.is-selection-expanded'
16
- import {getFocusTextBlock} from './selectors'
17
17
 
18
18
  /**
19
19
  * @public
@@ -0,0 +1,14 @@
1
+ import type {PortableTextBlock} from '@sanity/types'
2
+ import type {EditorSelector} from '../editor/editor-selector'
3
+ import type {BlockPath} from '../types/paths'
4
+
5
+ /**
6
+ * @public
7
+ */
8
+ export const getFirstBlock: EditorSelector<
9
+ {node: PortableTextBlock; path: BlockPath} | undefined
10
+ > = (snapshot) => {
11
+ const node = snapshot.context.value[0]
12
+
13
+ return node ? {node, path: [{_key: node._key}]} : undefined
14
+ }
@@ -0,0 +1,18 @@
1
+ import type {PortableTextObject} from '@sanity/types'
2
+ import type {EditorSelector} from '../editor/editor-selector'
3
+ import {isTextBlock} from '../internal-utils/parse-blocks'
4
+ import type {BlockPath} from '../types/paths'
5
+ import {getFocusBlock} from './selector.get-focus-block'
6
+
7
+ /**
8
+ * @public
9
+ */
10
+ export const getFocusBlockObject: EditorSelector<
11
+ {node: PortableTextObject; path: BlockPath} | undefined
12
+ > = (snapshot) => {
13
+ const focusBlock = getFocusBlock(snapshot)
14
+
15
+ return focusBlock && !isTextBlock(snapshot.context, focusBlock.node)
16
+ ? {node: focusBlock.node, path: focusBlock.path}
17
+ : undefined
18
+ }
@@ -0,0 +1,23 @@
1
+ import type {PortableTextBlock} from '@sanity/types'
2
+ import type {EditorSelector} from '../editor/editor-selector'
3
+ import {getBlockKeyFromSelectionPoint} from '../selection/selection-point'
4
+ import type {BlockPath} from '../types/paths'
5
+
6
+ /**
7
+ * @public
8
+ */
9
+ export const getFocusBlock: EditorSelector<
10
+ {node: PortableTextBlock; path: BlockPath} | undefined
11
+ > = (snapshot) => {
12
+ if (!snapshot.context.selection) {
13
+ return undefined
14
+ }
15
+
16
+ const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.focus)
17
+
18
+ const node = key
19
+ ? snapshot.context.value.find((block) => block._key === key)
20
+ : undefined
21
+
22
+ return node && key ? {node, path: [{_key: key}]} : undefined
23
+ }