@portabletext/editor 2.13.6 → 2.14.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.
@@ -89,7 +89,45 @@ function getListIndex({
89
89
  return listIndex;
90
90
  };
91
91
  }
92
- const getSelectedSlice = (snapshot) => selector_getSelectionText.getSelectedValue(snapshot), getSelection = (snapshot) => snapshot.context.selection, getSelectionEndChild = (snapshot) => {
92
+ const getNextInlineObjects = (snapshot) => {
93
+ const focusTextBlock = selector_getSelectionText.getFocusTextBlock(snapshot), selectionEndPoint = selector_isActiveStyle.getSelectionEndPoint(snapshot), selectionEndPointChildKey = selectionEndPoint && types.isKeySegment(selectionEndPoint.path[2]) ? selectionEndPoint.path[2]._key : void 0;
94
+ if (!focusTextBlock || !selectionEndPointChildKey)
95
+ return [];
96
+ let endPointChildFound = !1;
97
+ const inlineObjects = [];
98
+ for (const child of focusTextBlock.node.children) {
99
+ if (child._key === selectionEndPointChildKey) {
100
+ endPointChildFound = !0;
101
+ continue;
102
+ }
103
+ if (!schema.isSpan(snapshot.context, child) && endPointChildFound) {
104
+ inlineObjects.push({
105
+ node: child,
106
+ path: [...focusTextBlock.path, "children", {
107
+ _key: child._key
108
+ }]
109
+ });
110
+ break;
111
+ }
112
+ }
113
+ return inlineObjects;
114
+ }, getPreviousInlineObjects = (snapshot) => {
115
+ const focusTextBlock = selector_getSelectionText.getFocusTextBlock(snapshot), selectionStartPoint = selector_getSelectionText.getSelectionStartPoint(snapshot), selectionStartPointChildKey = selectionStartPoint && types.isKeySegment(selectionStartPoint.path[2]) ? selectionStartPoint.path[2]._key : void 0;
116
+ if (!focusTextBlock || !selectionStartPointChildKey)
117
+ return [];
118
+ const inlineObjects = [];
119
+ for (const child of focusTextBlock.node.children) {
120
+ if (child._key === selectionStartPointChildKey)
121
+ break;
122
+ schema.isSpan(snapshot.context, child) || inlineObjects.push({
123
+ node: child,
124
+ path: [...focusTextBlock.path, "children", {
125
+ _key: child._key
126
+ }]
127
+ });
128
+ }
129
+ return inlineObjects;
130
+ }, getSelectedSlice = (snapshot) => selector_getSelectionText.getSelectedValue(snapshot), getSelection = (snapshot) => snapshot.context.selection, getSelectionEndChild = (snapshot) => {
93
131
  const endPoint = util_getTextBlockText.getSelectionEndPoint(snapshot.context.selection);
94
132
  if (endPoint)
95
133
  return selector_getSelectionText.getFocusChild({
@@ -163,6 +201,8 @@ exports.getAnchorSpan = getAnchorSpan;
163
201
  exports.getAnchorTextBlock = getAnchorTextBlock;
164
202
  exports.getBlockOffsets = getBlockOffsets;
165
203
  exports.getListIndex = getListIndex;
204
+ exports.getNextInlineObjects = getNextInlineObjects;
205
+ exports.getPreviousInlineObjects = getPreviousInlineObjects;
166
206
  exports.getSelectedSlice = getSelectedSlice;
167
207
  exports.getSelection = getSelection;
168
208
  exports.getSelectionEndChild = getSelectionEndChild;
@@ -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-selected-slice.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-selection-end-child.ts","../../src/selectors/selector.get-selection-start-child.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.anchor)\n const index = key ? snapshot.blockIndexMap.get(key) : undefined\n const node =\n index !== undefined ? snapshot.context.value.at(index) : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: BlockPath} | 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 {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getChildKeyFromSelectionPoint} from '../utils/util.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: ChildPath\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 {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n {node: PortableTextSpan; path: ChildPath} | 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 {spanSelectionPointToBlockOffset} from '../utils/util.block-offset'\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 = spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * @beta\n * @deprecated Use the precomputed `data-list-index` on text blocks instead.\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 targetListItem = focusTextBlock.node.listItem\n const targetLevel = focusTextBlock.node.level\n const targetKey = focusTextBlock.node._key\n\n // Find the target block's index\n const targetIndex = snapshot.blockIndexMap.get(targetKey)\n\n if (targetIndex === undefined) {\n return undefined\n }\n\n // Walk backwards from the target block and count consecutive list items\n // of the same type and level\n let listIndex = 1 // Start at 1 for the target block itself\n\n for (let i = targetIndex - 1; i >= 0; i--) {\n const block = snapshot.context.value[i]\n\n if (!isTextBlock(snapshot.context, block)) {\n // Non-text block breaks the sequence\n break\n }\n\n if (block.listItem === undefined || block.level === undefined) {\n // Non-list item breaks the sequence\n break\n }\n\n if (block.listItem !== targetListItem) {\n // Different list type breaks the sequence\n break\n }\n\n if (block.level < targetLevel) {\n // Lower level breaks the sequence\n break\n }\n\n if (block.level === targetLevel) {\n // Same level - continue counting\n listIndex++\n }\n\n // Higher level items don't affect the count for the target level\n }\n\n return listIndex\n }\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * @public\n * @deprecated Renamed to `getSelectedValue`.\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return getSelectedValue(snapshot)\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getSelectionEndChild: EditorSelector<\n | {\n node: PortableTextSpan | PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n\n if (!endPoint) {\n return undefined\n }\n\n return getFocusChild({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: endPoint,\n focus: endPoint,\n },\n },\n })\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getSelectionStartChild: EditorSelector<\n | {\n node: PortableTextSpan | PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n\n if (!startPoint) {\n return undefined\n }\n\n return getFocusChild({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startPoint,\n focus: startPoint,\n },\n },\n })\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","index","blockIndexMap","get","undefined","node","value","at","path","_key","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","getChildKeyFromSelectionPoint","children","find","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","spanSelectionPointToBlockOffset","selectionPoint","end","getListIndex","offset","focus","focusTextBlock","getFocusTextBlock","listItem","level","targetListItem","targetLevel","targetKey","targetIndex","listIndex","i","block","getSelectedSlice","getSelectedValue","getSelection","getSelectionEndChild","endPoint","getFocusChild","getSelectionStartChild","startPoint","getValue"],"mappings":";;;AAQO,MAAMA,iBAERC,CAAAA,aAAa;AAChB,MAAI,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,sBAAAA,8BAA8BJ,SAASC,QAAQC,UAAUG,MAAM,GACrEC,QAAQH,MAAMH,SAASO,cAAcC,IAAIL,GAAG,IAAIM,QAChDC,OACJJ,UAAUG,SAAYT,SAASC,QAAQU,MAAMC,GAAGN,KAAK,IAAIG;AAE3D,SAA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AAOA;AAAAA,EACT;AACF;ACvFO,MAAMG,mBACXjD,CAAAA,aAEOkD,0BAAAA,iBAAiBlD,QAAQ,GCLrBmD,eAAiDnD,CAAAA,aACrDA,SAASC,QAAQC,WCEbkD,uBAMRpD,CAAAA,aAAa;AAChB,QAAMqD,WAAWvB,sBAAAA,qBAAqB9B,SAASC,QAAQC,SAAS;AAEhE,MAAKmD;AAIL,WAAOC,wCAAc;AAAA,MACnB,GAAGtD;AAAAA,MACHC,SAAS;AAAA,QACP,GAAGD,SAASC;AAAAA,QACZC,WAAW;AAAA,UACTG,QAAQgD;AAAAA,UACRhB,OAAOgB;AAAAA,QAAAA;AAAAA,MACT;AAAA,IACF,CACD;AACH,GCvBaE,yBAMRvD,CAAAA,aAAa;AAChB,QAAMwD,aAAa5B,sBAAAA,uBAAuB5B,SAASC,QAAQC,SAAS;AAEpE,MAAKsD;AAIL,WAAOF,wCAAc;AAAA,MACnB,GAAGtD;AAAAA,MACHC,SAAS;AAAA,QACP,GAAGD,SAASC;AAAAA,QACZC,WAAW;AAAA,UACTG,QAAQmD;AAAAA,UACRnB,OAAOmB;AAAAA,QAAAA;AAAAA,MACT;AAAA,IACF,CACD;AACH,GC1BaC,WACXzD,CAAAA,aAEOA,SAASC,QAAQU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
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-next-inline-objects.ts","../../src/selectors/selector.get-previous-inline-objects.ts","../../src/selectors/selector.get-selected-slice.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-selection-end-child.ts","../../src/selectors/selector.get-selection-start-child.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.anchor)\n const index = key ? snapshot.blockIndexMap.get(key) : undefined\n const node =\n index !== undefined ? snapshot.context.value.at(index) : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: BlockPath} | 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 {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getChildKeyFromSelectionPoint} from '../utils/util.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: ChildPath\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 {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n {node: PortableTextSpan; path: ChildPath} | 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 {spanSelectionPointToBlockOffset} from '../utils/util.block-offset'\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 = spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * @beta\n * @deprecated Use the precomputed `data-list-index` on text blocks instead.\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 targetListItem = focusTextBlock.node.listItem\n const targetLevel = focusTextBlock.node.level\n const targetKey = focusTextBlock.node._key\n\n // Find the target block's index\n const targetIndex = snapshot.blockIndexMap.get(targetKey)\n\n if (targetIndex === undefined) {\n return undefined\n }\n\n // Walk backwards from the target block and count consecutive list items\n // of the same type and level\n let listIndex = 1 // Start at 1 for the target block itself\n\n for (let i = targetIndex - 1; i >= 0; i--) {\n const block = snapshot.context.value[i]\n\n if (!isTextBlock(snapshot.context, block)) {\n // Non-text block breaks the sequence\n break\n }\n\n if (block.listItem === undefined || block.level === undefined) {\n // Non-list item breaks the sequence\n break\n }\n\n if (block.listItem !== targetListItem) {\n // Different list type breaks the sequence\n break\n }\n\n if (block.level < targetLevel) {\n // Lower level breaks the sequence\n break\n }\n\n if (block.level === targetLevel) {\n // Same level - continue counting\n listIndex++\n }\n\n // Higher level items don't affect the count for the target level\n }\n\n return listIndex\n }\n}\n","import {isSpan} from '@portabletext/schema'\nimport {isKeySegment, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\n\n/**\n * @public\n */\nexport const getNextInlineObjects: EditorSelector<\n Array<{\n node: PortableTextObject\n path: ChildPath\n }>\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 []\n }\n\n let endPointChildFound = false\n const inlineObjects: Array<{\n node: PortableTextObject\n path: ChildPath\n }> = []\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 inlineObjects.push({\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n })\n break\n }\n }\n\n return inlineObjects\n}\n","import {isSpan} from '@portabletext/schema'\nimport {isKeySegment, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getPreviousInlineObjects: EditorSelector<\n Array<{\n node: PortableTextObject\n path: ChildPath\n }>\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartPointChildKey =\n selectionStartPoint && isKeySegment(selectionStartPoint.path[2])\n ? selectionStartPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionStartPointChildKey) {\n return []\n }\n\n const inlineObjects: Array<{\n node: PortableTextObject\n path: ChildPath\n }> = []\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionStartPointChildKey) {\n break\n }\n\n if (!isSpan(snapshot.context, child)) {\n inlineObjects.push({\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n })\n }\n }\n\n return inlineObjects\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * @public\n * @deprecated Renamed to `getSelectedValue`.\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return getSelectedValue(snapshot)\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getSelectionEndChild: EditorSelector<\n | {\n node: PortableTextSpan | PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n\n if (!endPoint) {\n return undefined\n }\n\n return getFocusChild({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: endPoint,\n focus: endPoint,\n },\n },\n })\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getSelectionStartChild: EditorSelector<\n | {\n node: PortableTextSpan | PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n\n if (!startPoint) {\n return undefined\n }\n\n return getFocusChild({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startPoint,\n focus: startPoint,\n },\n },\n })\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","index","blockIndexMap","get","undefined","node","value","at","path","_key","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","getChildKeyFromSelectionPoint","children","find","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","spanSelectionPointToBlockOffset","selectionPoint","end","getListIndex","offset","focus","focusTextBlock","getFocusTextBlock","listItem","level","targetListItem","targetLevel","targetKey","targetIndex","listIndex","i","block","getNextInlineObjects","selectionEndPointChildKey","isKeySegment","endPointChildFound","inlineObjects","child","isSpan","push","getPreviousInlineObjects","selectionStartPointChildKey","getSelectedSlice","getSelectedValue","getSelection","getSelectionEndChild","endPoint","getFocusChild","getSelectionStartChild","startPoint","getValue"],"mappings":";;;AAQO,MAAMA,iBAERC,CAAAA,aAAa;AAChB,MAAI,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,sBAAAA,8BAA8BJ,SAASC,QAAQC,UAAUG,MAAM,GACrEC,QAAQH,MAAMH,SAASO,cAAcC,IAAIL,GAAG,IAAIM,QAChDC,OACJJ,UAAUG,SAAYT,SAASC,QAAQU,MAAMC,GAAGN,KAAK,IAAIG;AAE3D,SAAOC,QAAQP,MAAM;AAAA,IAACO;AAAAA,IAAMG,MAAM,CAAC;AAAA,MAACC,MAAMX;AAAAA,IAAAA,CAAI;AAAA,EAAA,IAAKM;AACrD,GCZaM,qBAERf,CAAAA,aAAa;AAChB,QAAMgB,cAAcjB,eAAeC,QAAQ;AAE3C,SAAOgB,eAAeC,OAAAA,YAAYjB,SAASC,SAASe,YAAYN,IAAI,IAChE;AAAA,IAACA,MAAMM,YAAYN;AAAAA,IAAMG,MAAMG,YAAYH;AAAAA,EAAAA,IAC3CJ;AACN,GCRaS,iBAMRlB,CAAAA,aAAa;AAChB,MAAI,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMc,cAAcD,mBAAmBf,QAAQ;AAE/C,MAAI,CAACgB;AACH;AAGF,QAAMb,MAAMgB,sBAAAA,8BAA8BnB,SAASC,QAAQC,UAAUG,MAAM,GAErEK,OAAOP,MACTa,YAAYN,KAAKU,SAASC,KAAM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aE,yBAMRjE,CAAAA,aAAa;AAChB,QAAMkE,aAAatC,sBAAAA,uBAAuB5B,SAASC,QAAQC,SAAS;AAEpE,MAAKgE;AAIL,WAAOF,wCAAc;AAAA,MACnB,GAAGhE;AAAAA,MACHC,SAAS;AAAA,QACP,GAAGD,SAASC;AAAAA,QACZC,WAAW;AAAA,UACTG,QAAQ6D;AAAAA,UACR7B,OAAO6B;AAAAA,QAAAA;AAAAA,MACT;AAAA,IACF,CACD;AACH,GC1BaC,WACXnE,CAAAA,aAEOA,SAASC,QAAQU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -158,6 +158,13 @@ declare const getNextInlineObject: EditorSelector<{
158
158
  node: PortableTextObject;
159
159
  path: ChildPath;
160
160
  } | undefined>;
161
+ /**
162
+ * @public
163
+ */
164
+ declare const getNextInlineObjects: EditorSelector<Array<{
165
+ node: PortableTextObject;
166
+ path: ChildPath;
167
+ }>>;
161
168
  /**
162
169
  * @public
163
170
  */
@@ -172,6 +179,13 @@ declare const getPreviousInlineObject: EditorSelector<{
172
179
  node: PortableTextObject;
173
180
  path: ChildPath;
174
181
  } | undefined>;
182
+ /**
183
+ * @public
184
+ */
185
+ declare const getPreviousInlineObjects: EditorSelector<Array<{
186
+ node: PortableTextObject;
187
+ path: ChildPath;
188
+ }>>;
175
189
  /**
176
190
  * @public
177
191
  */
@@ -322,4 +336,4 @@ declare const isSelectionCollapsed: EditorSelector<boolean>;
322
336
  * @public
323
337
  */
324
338
  declare const isSelectionExpanded: EditorSelector<boolean>;
325
- export { MarkState, getActiveAnnotations, getActiveListItem, getActiveStyle, getAnchorBlock, getAnchorChild, getAnchorSpan, getAnchorTextBlock, getBlockOffsets, getBlockTextBefore, getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusInlineObject, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getListIndex, getMarkState, getNextBlock, getNextInlineObject, getPreviousBlock, getPreviousInlineObject, getSelectedBlocks, getSelectedSlice, getSelectedSpans, getSelectedTextBlocks, getSelectedValue, getSelection, getSelectionEndBlock, getSelectionEndChild, getSelectionEndPoint, getSelectionStartBlock, getSelectionStartChild, getSelectionStartPoint, getSelectionText, getTrimmedSelection, getValue, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks, isSelectionCollapsed, isSelectionExpanded };
339
+ export { MarkState, getActiveAnnotations, getActiveListItem, getActiveStyle, getAnchorBlock, getAnchorChild, getAnchorSpan, getAnchorTextBlock, getBlockOffsets, getBlockTextBefore, getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusInlineObject, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getListIndex, getMarkState, getNextBlock, getNextInlineObject, getNextInlineObjects, getPreviousBlock, getPreviousInlineObject, getPreviousInlineObjects, getSelectedBlocks, getSelectedSlice, getSelectedSpans, getSelectedTextBlocks, getSelectedValue, getSelection, getSelectionEndBlock, getSelectionEndChild, getSelectionEndPoint, getSelectionStartBlock, getSelectionStartChild, getSelectionStartPoint, getSelectionText, getTrimmedSelection, getValue, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks, isSelectionCollapsed, isSelectionExpanded };
@@ -158,6 +158,13 @@ declare const getNextInlineObject: EditorSelector<{
158
158
  node: PortableTextObject;
159
159
  path: ChildPath;
160
160
  } | undefined>;
161
+ /**
162
+ * @public
163
+ */
164
+ declare const getNextInlineObjects: EditorSelector<Array<{
165
+ node: PortableTextObject;
166
+ path: ChildPath;
167
+ }>>;
161
168
  /**
162
169
  * @public
163
170
  */
@@ -172,6 +179,13 @@ declare const getPreviousInlineObject: EditorSelector<{
172
179
  node: PortableTextObject;
173
180
  path: ChildPath;
174
181
  } | undefined>;
182
+ /**
183
+ * @public
184
+ */
185
+ declare const getPreviousInlineObjects: EditorSelector<Array<{
186
+ node: PortableTextObject;
187
+ path: ChildPath;
188
+ }>>;
175
189
  /**
176
190
  * @public
177
191
  */
@@ -322,4 +336,4 @@ declare const isSelectionCollapsed: EditorSelector<boolean>;
322
336
  * @public
323
337
  */
324
338
  declare const isSelectionExpanded: EditorSelector<boolean>;
325
- export { MarkState, getActiveAnnotations, getActiveListItem, getActiveStyle, getAnchorBlock, getAnchorChild, getAnchorSpan, getAnchorTextBlock, getBlockOffsets, getBlockTextBefore, getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusInlineObject, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getListIndex, getMarkState, getNextBlock, getNextInlineObject, getPreviousBlock, getPreviousInlineObject, getSelectedBlocks, getSelectedSlice, getSelectedSpans, getSelectedTextBlocks, getSelectedValue, getSelection, getSelectionEndBlock, getSelectionEndChild, getSelectionEndPoint, getSelectionStartBlock, getSelectionStartChild, getSelectionStartPoint, getSelectionText, getTrimmedSelection, getValue, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks, isSelectionCollapsed, isSelectionExpanded };
339
+ export { MarkState, getActiveAnnotations, getActiveListItem, getActiveStyle, getAnchorBlock, getAnchorChild, getAnchorSpan, getAnchorTextBlock, getBlockOffsets, getBlockTextBefore, getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusInlineObject, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getListIndex, getMarkState, getNextBlock, getNextInlineObject, getNextInlineObjects, getPreviousBlock, getPreviousInlineObject, getPreviousInlineObjects, getSelectedBlocks, getSelectedSlice, getSelectedSpans, getSelectedTextBlocks, getSelectedValue, getSelection, getSelectionEndBlock, getSelectionEndChild, getSelectionEndPoint, getSelectionStartBlock, getSelectionStartChild, getSelectionStartPoint, getSelectionText, getTrimmedSelection, getValue, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks, isSelectionCollapsed, isSelectionExpanded };
@@ -1,8 +1,8 @@
1
1
  import { getSelectionEndPoint } from "../_chunks-es/selector.is-active-style.js";
2
2
  import { getActiveAnnotations, getActiveListItem, getActiveStyle, getCaretWordSelection, getFirstBlock, getFocusBlockObject, getFocusInlineObject, getFocusListBlock, getLastBlock, getMarkState, getNextBlock, getNextInlineObject, getPreviousBlock, getSelectedBlocks, getSelectedSpans, getSelectedTextBlocks, getSelectionEndBlock, getSelectionStartBlock, getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks } from "../_chunks-es/selector.is-active-style.js";
3
3
  import { getBlockKeyFromSelectionPoint, getChildKeyFromSelectionPoint, spanSelectionPointToBlockOffset, getSelectionEndPoint as getSelectionEndPoint$1, getSelectionStartPoint as getSelectionStartPoint$1 } from "../_chunks-es/util.get-text-block-text.js";
4
- import { isTextBlock } from "@portabletext/schema";
5
- import { isPortableTextSpan } from "@sanity/types";
4
+ import { isTextBlock, isSpan } from "@portabletext/schema";
5
+ import { isPortableTextSpan, isKeySegment } from "@sanity/types";
6
6
  import { getSelectionStartPoint, getFocusTextBlock, getSelectedValue, getFocusChild } from "../_chunks-es/selector.get-selection-text.js";
7
7
  import { getFocusBlock, getFocusSpan, getPreviousInlineObject, getSelectionText, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.get-selection-text.js";
8
8
  import { getBlockTextBefore } from "../_chunks-es/selector.get-text-before.js";
@@ -94,7 +94,45 @@ function getListIndex({
94
94
  return listIndex;
95
95
  };
96
96
  }
97
- const getSelectedSlice = (snapshot) => getSelectedValue(snapshot), getSelection = (snapshot) => snapshot.context.selection, getSelectionEndChild = (snapshot) => {
97
+ const getNextInlineObjects = (snapshot) => {
98
+ const focusTextBlock = getFocusTextBlock(snapshot), selectionEndPoint = getSelectionEndPoint(snapshot), selectionEndPointChildKey = selectionEndPoint && isKeySegment(selectionEndPoint.path[2]) ? selectionEndPoint.path[2]._key : void 0;
99
+ if (!focusTextBlock || !selectionEndPointChildKey)
100
+ return [];
101
+ let endPointChildFound = !1;
102
+ const inlineObjects = [];
103
+ for (const child of focusTextBlock.node.children) {
104
+ if (child._key === selectionEndPointChildKey) {
105
+ endPointChildFound = !0;
106
+ continue;
107
+ }
108
+ if (!isSpan(snapshot.context, child) && endPointChildFound) {
109
+ inlineObjects.push({
110
+ node: child,
111
+ path: [...focusTextBlock.path, "children", {
112
+ _key: child._key
113
+ }]
114
+ });
115
+ break;
116
+ }
117
+ }
118
+ return inlineObjects;
119
+ }, getPreviousInlineObjects = (snapshot) => {
120
+ const focusTextBlock = getFocusTextBlock(snapshot), selectionStartPoint = getSelectionStartPoint(snapshot), selectionStartPointChildKey = selectionStartPoint && isKeySegment(selectionStartPoint.path[2]) ? selectionStartPoint.path[2]._key : void 0;
121
+ if (!focusTextBlock || !selectionStartPointChildKey)
122
+ return [];
123
+ const inlineObjects = [];
124
+ for (const child of focusTextBlock.node.children) {
125
+ if (child._key === selectionStartPointChildKey)
126
+ break;
127
+ isSpan(snapshot.context, child) || inlineObjects.push({
128
+ node: child,
129
+ path: [...focusTextBlock.path, "children", {
130
+ _key: child._key
131
+ }]
132
+ });
133
+ }
134
+ return inlineObjects;
135
+ }, getSelectedSlice = (snapshot) => getSelectedValue(snapshot), getSelection = (snapshot) => snapshot.context.selection, getSelectionEndChild = (snapshot) => {
98
136
  const endPoint = getSelectionEndPoint$1(snapshot.context.selection);
99
137
  if (endPoint)
100
138
  return getFocusChild({
@@ -145,8 +183,10 @@ export {
145
183
  getMarkState,
146
184
  getNextBlock,
147
185
  getNextInlineObject,
186
+ getNextInlineObjects,
148
187
  getPreviousBlock,
149
188
  getPreviousInlineObject,
189
+ getPreviousInlineObjects,
150
190
  getSelectedBlocks,
151
191
  getSelectedSlice,
152
192
  getSelectedSpans,
@@ -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-selected-slice.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-selection-end-child.ts","../../src/selectors/selector.get-selection-start-child.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.anchor)\n const index = key ? snapshot.blockIndexMap.get(key) : undefined\n const node =\n index !== undefined ? snapshot.context.value.at(index) : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: BlockPath} | 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 {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getChildKeyFromSelectionPoint} from '../utils/util.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: ChildPath\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 {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n {node: PortableTextSpan; path: ChildPath} | 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 {spanSelectionPointToBlockOffset} from '../utils/util.block-offset'\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 = spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * @beta\n * @deprecated Use the precomputed `data-list-index` on text blocks instead.\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 targetListItem = focusTextBlock.node.listItem\n const targetLevel = focusTextBlock.node.level\n const targetKey = focusTextBlock.node._key\n\n // Find the target block's index\n const targetIndex = snapshot.blockIndexMap.get(targetKey)\n\n if (targetIndex === undefined) {\n return undefined\n }\n\n // Walk backwards from the target block and count consecutive list items\n // of the same type and level\n let listIndex = 1 // Start at 1 for the target block itself\n\n for (let i = targetIndex - 1; i >= 0; i--) {\n const block = snapshot.context.value[i]\n\n if (!isTextBlock(snapshot.context, block)) {\n // Non-text block breaks the sequence\n break\n }\n\n if (block.listItem === undefined || block.level === undefined) {\n // Non-list item breaks the sequence\n break\n }\n\n if (block.listItem !== targetListItem) {\n // Different list type breaks the sequence\n break\n }\n\n if (block.level < targetLevel) {\n // Lower level breaks the sequence\n break\n }\n\n if (block.level === targetLevel) {\n // Same level - continue counting\n listIndex++\n }\n\n // Higher level items don't affect the count for the target level\n }\n\n return listIndex\n }\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * @public\n * @deprecated Renamed to `getSelectedValue`.\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return getSelectedValue(snapshot)\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getSelectionEndChild: EditorSelector<\n | {\n node: PortableTextSpan | PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n\n if (!endPoint) {\n return undefined\n }\n\n return getFocusChild({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: endPoint,\n focus: endPoint,\n },\n },\n })\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getSelectionStartChild: EditorSelector<\n | {\n node: PortableTextSpan | PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n\n if (!startPoint) {\n return undefined\n }\n\n return getFocusChild({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startPoint,\n focus: startPoint,\n },\n },\n })\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","index","blockIndexMap","get","undefined","node","value","at","path","_key","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","getChildKeyFromSelectionPoint","children","find","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","spanSelectionPointToBlockOffset","selectionPoint","end","getListIndex","offset","focus","focusTextBlock","getFocusTextBlock","listItem","level","targetListItem","targetLevel","targetKey","targetIndex","listIndex","i","block","getSelectedSlice","getSelectedValue","getSelection","getSelectionEndChild","endPoint","getFocusChild","getSelectionStartChild","startPoint","getValue"],"mappings":";;;;;;;;AAQO,MAAMA,iBAERC,CAAAA,aAAa;AAChB,MAAI,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,8BAA8BJ,SAASC,QAAQC,UAAUG,MAAM,GACrEC,QAAQH,MAAMH,SAASO,cAAcC,IAAIL,GAAG,IAAIM,QAChDC,OACJJ,UAAUG,SAAYT,SAASC,QAAQU,MAAMC,GAAGN,KAAK,IAAIG;AAE3D,SAAOC,QAAQP,MAAM;AAAA,IAACO;AAAAA,IAAMG,MAAM,CAAC;AAAA,MAACC,MAAMX;AAAAA,IAAAA,CAAI;AAAA,EAAA,IAAKM;AACrD,GCZaM,qBAERf,CAAAA,aAAa;AAChB,QAAMgB,cAAcjB,eAAeC,QAAQ;AAE3C,SAAOgB,eAAeC,YAAYjB,SAASC,SAASe,YAAYN,IAAI,IAChE;AAAA,IAACA,MAAMM,YAAYN;AAAAA,IAAMG,MAAMG,YAAYH;AAAAA,EAAAA,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AAA;AAAAA,MACT;AAAA,IACF,CACD;AACH,GCvBaE,yBAMRvD,CAAAA,aAAa;AAChB,QAAMwD,aAAa5B,yBAAuB5B,SAASC,QAAQC,SAAS;AAEpE,MAAKsD;AAIL,WAAOF,cAAc;AAAA,MACnB,GAAGtD;AAAAA,MACHC,SAAS;AAAA,QACP,GAAGD,SAASC;AAAAA,QACZC,WAAW;AAAA,UACTG,QAAQmD;AAAAA,UACRnB,OAAOmB;AAAAA,QAAAA;AAAAA,MACT;AAAA,IACF,CACD;AACH,GC1BaC,WACXzD,CAAAA,aAEOA,SAASC,QAAQU;"}
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-next-inline-objects.ts","../../src/selectors/selector.get-previous-inline-objects.ts","../../src/selectors/selector.get-selected-slice.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-selection-end-child.ts","../../src/selectors/selector.get-selection-start-child.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.anchor)\n const index = key ? snapshot.blockIndexMap.get(key) : undefined\n const node =\n index !== undefined ? snapshot.context.value.at(index) : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: BlockPath} | 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 {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getChildKeyFromSelectionPoint} from '../utils/util.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: ChildPath\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 {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n {node: PortableTextSpan; path: ChildPath} | 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 {spanSelectionPointToBlockOffset} from '../utils/util.block-offset'\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 = spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * @beta\n * @deprecated Use the precomputed `data-list-index` on text blocks instead.\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 targetListItem = focusTextBlock.node.listItem\n const targetLevel = focusTextBlock.node.level\n const targetKey = focusTextBlock.node._key\n\n // Find the target block's index\n const targetIndex = snapshot.blockIndexMap.get(targetKey)\n\n if (targetIndex === undefined) {\n return undefined\n }\n\n // Walk backwards from the target block and count consecutive list items\n // of the same type and level\n let listIndex = 1 // Start at 1 for the target block itself\n\n for (let i = targetIndex - 1; i >= 0; i--) {\n const block = snapshot.context.value[i]\n\n if (!isTextBlock(snapshot.context, block)) {\n // Non-text block breaks the sequence\n break\n }\n\n if (block.listItem === undefined || block.level === undefined) {\n // Non-list item breaks the sequence\n break\n }\n\n if (block.listItem !== targetListItem) {\n // Different list type breaks the sequence\n break\n }\n\n if (block.level < targetLevel) {\n // Lower level breaks the sequence\n break\n }\n\n if (block.level === targetLevel) {\n // Same level - continue counting\n listIndex++\n }\n\n // Higher level items don't affect the count for the target level\n }\n\n return listIndex\n }\n}\n","import {isSpan} from '@portabletext/schema'\nimport {isKeySegment, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\n\n/**\n * @public\n */\nexport const getNextInlineObjects: EditorSelector<\n Array<{\n node: PortableTextObject\n path: ChildPath\n }>\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 []\n }\n\n let endPointChildFound = false\n const inlineObjects: Array<{\n node: PortableTextObject\n path: ChildPath\n }> = []\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 inlineObjects.push({\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n })\n break\n }\n }\n\n return inlineObjects\n}\n","import {isSpan} from '@portabletext/schema'\nimport {isKeySegment, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getPreviousInlineObjects: EditorSelector<\n Array<{\n node: PortableTextObject\n path: ChildPath\n }>\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartPointChildKey =\n selectionStartPoint && isKeySegment(selectionStartPoint.path[2])\n ? selectionStartPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionStartPointChildKey) {\n return []\n }\n\n const inlineObjects: Array<{\n node: PortableTextObject\n path: ChildPath\n }> = []\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionStartPointChildKey) {\n break\n }\n\n if (!isSpan(snapshot.context, child)) {\n inlineObjects.push({\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n })\n }\n }\n\n return inlineObjects\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * @public\n * @deprecated Renamed to `getSelectedValue`.\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return getSelectedValue(snapshot)\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getSelectionEndChild: EditorSelector<\n | {\n node: PortableTextSpan | PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n\n if (!endPoint) {\n return undefined\n }\n\n return getFocusChild({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: endPoint,\n focus: endPoint,\n },\n },\n })\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getSelectionStartChild: EditorSelector<\n | {\n node: PortableTextSpan | PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n\n if (!startPoint) {\n return undefined\n }\n\n return getFocusChild({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startPoint,\n focus: startPoint,\n },\n },\n })\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","index","blockIndexMap","get","undefined","node","value","at","path","_key","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","getChildKeyFromSelectionPoint","children","find","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","spanSelectionPointToBlockOffset","selectionPoint","end","getListIndex","offset","focus","focusTextBlock","getFocusTextBlock","listItem","level","targetListItem","targetLevel","targetKey","targetIndex","listIndex","i","block","getNextInlineObjects","selectionEndPointChildKey","isKeySegment","endPointChildFound","inlineObjects","child","isSpan","push","getPreviousInlineObjects","selectionStartPointChildKey","getSelectedSlice","getSelectedValue","getSelection","getSelectionEndChild","endPoint","getFocusChild","getSelectionStartChild","startPoint","getValue"],"mappings":";;;;;;;;AAQO,MAAMA,iBAERC,CAAAA,aAAa;AAChB,MAAI,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,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AAGGH,WAAOvD,SAASC,SAASqD,KAAK,KACjCD,cAAcG,KAAK;AAAA,MACjB9C,MAAM4C;AAAAA,MACNzC,MAAM,CAAC,GAAGyB,eAAezB,MAAM,YAAY;AAAA,QAACC,MAAMwC,MAAMxC;AAAAA,MAAAA,CAAK;AAAA,IAAA,CAC9D;AAAA,EAEL;AAEA,SAAOuC;AACT,GCtCaM,mBACX3D,CAAAA,aAEO4D,iBAAiB5D,QAAQ,GCLrB6D,eAAiD7D,CAAAA,aACrDA,SAASC,QAAQC,WCEb4D,uBAMR9D,CAAAA,aAAa;AAChB,QAAM+D,WAAWjC,uBAAqB9B,SAASC,QAAQC,SAAS;AAEhE,MAAK6D;AAIL,WAAOC,cAAc;AAAA,MACnB,GAAGhE;AAAAA,MACHC,SAAS;AAAA,QACP,GAAGD,SAASC;AAAAA,QACZC,WAAW;AAAA,UACTG,QAAQ0D;AAAAA,UACR1B,OAAO0B;AAAAA,QAAAA;AAAAA,MACT;AAAA,IACF,CACD;AACH,GCvBaE,yBAMRjE,CAAAA,aAAa;AAChB,QAAMkE,aAAatC,yBAAuB5B,SAASC,QAAQC,SAAS;AAEpE,MAAKgE;AAIL,WAAOF,cAAc;AAAA,MACnB,GAAGhE;AAAAA,MACHC,SAAS;AAAA,QACP,GAAGD,SAASC;AAAAA,QACZC,WAAW;AAAA,UACTG,QAAQ6D;AAAAA,UACR7B,OAAO6B;AAAAA,QAAAA;AAAAA,MACT;AAAA,IACF,CACD;AACH,GC1BaC,WACXnE,CAAAA,aAEOA,SAASC,QAAQU;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "2.13.6",
3
+ "version": "2.14.0",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -84,11 +84,11 @@
84
84
  "slate": "0.118.1",
85
85
  "slate-dom": "^0.118.1",
86
86
  "slate-react": "0.117.4",
87
- "xstate": "^5.22.1",
87
+ "xstate": "^5.23.0",
88
88
  "@portabletext/block-tools": "^3.5.10",
89
+ "@portabletext/keyboard-shortcuts": "^1.1.1",
89
90
  "@portabletext/patches": "^1.1.8",
90
- "@portabletext/schema": "^1.2.0",
91
- "@portabletext/keyboard-shortcuts": "^1.1.1"
91
+ "@portabletext/schema": "^1.2.0"
92
92
  },
93
93
  "devDependencies": {
94
94
  "@sanity/diff-match-patch": "^3.2.0",
@@ -4,7 +4,7 @@
4
4
  *
5
5
  */
6
6
 
7
- import {isSpan, isTextBlock} from '@portabletext/schema'
7
+ import {isTextBlock} from '@portabletext/schema'
8
8
  import type {PortableTextObject, PortableTextSpan} from '@sanity/types'
9
9
  import {isEqual, uniq} from 'lodash'
10
10
  import {Editor, Element, Node, Path, Range, Text, Transforms} from 'slate'
@@ -12,7 +12,6 @@ import {debugWithName} from '../../internal-utils/debug'
12
12
  import {getNextSpan, getPreviousSpan} from '../../internal-utils/sibling-utils'
13
13
  import type {BehaviorOperationImplementation} from '../../operations/behavior.operations'
14
14
  import {getActiveDecorators} from '../../selectors/selector.get-active-decorators'
15
- import {getMarkState} from '../../selectors/selector.get-mark-state'
16
15
  import type {PortableTextSlateEditor} from '../../types/editor'
17
16
  import type {EditorActor} from '../editor-machine'
18
17
  import {getEditorSnapshot} from '../editor-selector'
@@ -325,122 +324,6 @@ export function createWithPortableTextMarkModel(
325
324
  }
326
325
  }
327
326
 
328
- if (op.type === 'insert_node') {
329
- const {selection} = editor
330
-
331
- if (selection) {
332
- const [_block, blockPath] = Editor.node(editor, selection, {depth: 1})
333
- const previousSpan = getPreviousSpan({
334
- editor,
335
- blockPath,
336
- spanPath: op.path,
337
- })
338
- const previousSpanAnnotations = previousSpan
339
- ? previousSpan.marks?.filter((mark) => !decorators.includes(mark))
340
- : []
341
-
342
- const nextSpan = getNextSpan({
343
- editor,
344
- blockPath,
345
- spanPath: [op.path[0], op.path[1] - 1],
346
- })
347
- const nextSpanAnnotations = nextSpan
348
- ? nextSpan.marks?.filter((mark) => !decorators.includes(mark))
349
- : []
350
-
351
- const annotationsEnding =
352
- previousSpanAnnotations?.filter(
353
- (annotation) => !nextSpanAnnotations?.includes(annotation),
354
- ) ?? []
355
- const atTheEndOfAnnotation = annotationsEnding.length > 0
356
-
357
- if (
358
- atTheEndOfAnnotation &&
359
- isSpan(editorActor.getSnapshot().context, op.node) &&
360
- op.node.marks?.some((mark) => annotationsEnding.includes(mark))
361
- ) {
362
- Transforms.insertNodes(editor, {
363
- ...op.node,
364
- _key: editorActor.getSnapshot().context.keyGenerator(),
365
- marks:
366
- op.node.marks?.filter(
367
- (mark) => !annotationsEnding.includes(mark),
368
- ) ?? [],
369
- })
370
- return
371
- }
372
-
373
- const annotationsStarting =
374
- nextSpanAnnotations?.filter(
375
- (annotation) => !previousSpanAnnotations?.includes(annotation),
376
- ) ?? []
377
- const atTheStartOfAnnotation = annotationsStarting.length > 0
378
-
379
- if (
380
- atTheStartOfAnnotation &&
381
- isSpan(editorActor.getSnapshot().context, op.node) &&
382
- op.node.marks?.some((mark) => annotationsStarting.includes(mark))
383
- ) {
384
- Transforms.insertNodes(editor, {
385
- ...op.node,
386
- _key: editorActor.getSnapshot().context.keyGenerator(),
387
- marks:
388
- op.node.marks?.filter(
389
- (mark) => !annotationsStarting.includes(mark),
390
- ) ?? [],
391
- })
392
- return
393
- }
394
-
395
- const nextSpanDecorators =
396
- nextSpan?.marks?.filter((mark) => decorators.includes(mark)) ?? []
397
- const decoratorStarting = nextSpanDecorators.length > 0
398
-
399
- if (
400
- decoratorStarting &&
401
- atTheEndOfAnnotation &&
402
- !atTheStartOfAnnotation &&
403
- isSpan(editorActor.getSnapshot().context, op.node) &&
404
- op.node.marks?.length === 0
405
- ) {
406
- Transforms.insertNodes(editor, {
407
- ...op.node,
408
- _key: editorActor.getSnapshot().context.keyGenerator(),
409
- marks: nextSpanDecorators,
410
- })
411
- return
412
- }
413
- }
414
- }
415
-
416
- if (op.type === 'insert_text') {
417
- const snapshot = getEditorSnapshot({
418
- editorActorSnapshot: editorActor.getSnapshot(),
419
- slateEditorInstance: editor,
420
- })
421
-
422
- const markState = getMarkState(snapshot)
423
-
424
- if (!markState) {
425
- apply(op)
426
- return
427
- }
428
-
429
- if (markState.state === 'unchanged') {
430
- apply(op)
431
- return
432
- }
433
-
434
- Transforms.insertNodes(editor, {
435
- _type: 'span',
436
- _key: editorActor.getSnapshot().context.keyGenerator(),
437
- text: op.text,
438
- marks: markState.marks,
439
- })
440
-
441
- return
442
- }
443
-
444
327
  if (op.type === 'remove_text') {
445
328
  const {selection} = editor
446
329
 
@@ -59,8 +59,8 @@ describe(toSlateRange.name, () => {
59
59
  })
60
60
 
61
61
  expect(range).toEqual({
62
- anchor: {path: [0, 2], offset: 0},
63
- focus: {path: [0, 2], offset: 0},
62
+ anchor: {path: [0, 0], offset: 3},
63
+ focus: {path: [0, 0], offset: 3},
64
64
  })
65
65
  })
66
66
 
@@ -28,7 +28,7 @@ export function toSlateRange(
28
28
  const anchorPoint = toSlateSelectionPoint(
29
29
  snapshot,
30
30
  snapshot.context.selection.anchor,
31
- snapshot.context.selection.backward ? 'forward' : 'backward',
31
+ snapshot.context.selection.backward ? 'backward' : 'forward',
32
32
  )
33
33
 
34
34
  if (!anchorPoint) {
@@ -20,8 +20,10 @@ export {getListIndex} from './selector.get-list-state'
20
20
  export {getMarkState, type MarkState} from './selector.get-mark-state'
21
21
  export {getNextBlock} from './selector.get-next-block'
22
22
  export {getNextInlineObject} from './selector.get-next-inline-object'
23
+ export {getNextInlineObjects} from './selector.get-next-inline-objects'
23
24
  export {getPreviousBlock} from './selector.get-previous-block'
24
25
  export {getPreviousInlineObject} from './selector.get-previous-inline-object'
26
+ export {getPreviousInlineObjects} from './selector.get-previous-inline-objects'
25
27
  export {getSelectedBlocks} from './selector.get-selected-blocks'
26
28
  export {getSelectedSlice} from './selector.get-selected-slice'
27
29
  export {getSelectedSpans} from './selector.get-selected-spans'
@@ -73,4 +73,67 @@ describe(getMarkState.name, () => {
73
73
  previousMarks: [linkKey, 'strong'],
74
74
  })
75
75
  })
76
+
77
+ test('Scenario: Caret after annotation inside decorator', () => {
78
+ const keyGenerator = createTestKeyGenerator()
79
+ const blockKey = keyGenerator()
80
+ const fooSpanKey = keyGenerator()
81
+ const barSpanKey = keyGenerator()
82
+ const bazSpanKey = keyGenerator()
83
+ const linkKey = keyGenerator()
84
+ const snapshot = createTestSnapshot({
85
+ context: {
86
+ keyGenerator,
87
+ value: [
88
+ {
89
+ _type: 'block',
90
+ _key: blockKey,
91
+ children: [
92
+ {
93
+ _type: 'span',
94
+ _key: fooSpanKey,
95
+ text: 'foo ',
96
+ marks: ['strong'],
97
+ },
98
+ {
99
+ _type: 'span',
100
+ _key: barSpanKey,
101
+ text: 'bar',
102
+ marks: [linkKey, 'strong'],
103
+ },
104
+ {
105
+ _type: 'span',
106
+ _key: bazSpanKey,
107
+ text: ' baz',
108
+ marks: ['strong'],
109
+ },
110
+ ],
111
+ },
112
+ ],
113
+ selection: {
114
+ anchor: {
115
+ path: [{_key: blockKey}, 'children', {_key: bazSpanKey}],
116
+ offset: 0,
117
+ },
118
+ focus: {
119
+ path: [{_key: blockKey}, 'children', {_key: bazSpanKey}],
120
+ offset: 0,
121
+ },
122
+ backward: false,
123
+ },
124
+ schema: compileSchema(
125
+ defineSchema({
126
+ annotations: [{name: 'link'}],
127
+ decorators: [{name: 'strong'}],
128
+ }),
129
+ ),
130
+ },
131
+ })
132
+
133
+ expect(getMarkState(snapshot)).toEqual({
134
+ state: 'changed',
135
+ marks: ['strong'],
136
+ previousMarks: [linkKey, 'strong'],
137
+ })
138
+ })
76
139
  })
@@ -236,8 +236,8 @@ export const getMarkState: EditorSelector<MarkState | undefined> = (
236
236
  if (previousSpanHasAnnotations) {
237
237
  return {
238
238
  state: 'changed',
239
- previousMarks: previousSpan.node.marks ?? [],
240
- marks: [],
239
+ marks,
240
+ previousMarks: previousSpan?.node.marks ?? [],
241
241
  }
242
242
  } else {
243
243
  return {