UNPKG

@portabletext/editor

Version:

Portable Text Editor made in React

1 lines 2.2 kB
{"version":3,"file":"util.selection-point-to-block-offset.cjs","sources":["../../src/utils/util.is-selection-collapsed.ts","../../src/utils/util.selection-point-to-block-offset.ts"],"sourcesContent":["import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function isSelectionCollapsed(selection: EditorSelection) {\n if (!selection) {\n return false\n }\n\n return (\n JSON.stringify(selection.anchor.path) ===\n JSON.stringify(selection.focus.path) &&\n selection.anchor.offset === selection.focus.offset\n )\n}\n","import type {EditorContext} from '../editor/editor-snapshot'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {childSelectionPointToBlockOffset} from './util.child-selection-point-to-block-offset'\n\n/**\n * @public\n */\nexport function selectionPointToBlockOffset({\n context,\n selectionPoint,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n const blockKey = getBlockKeyFromSelectionPoint(selectionPoint)\n\n if (selectionPoint.path.length === 1 && blockKey !== undefined) {\n return {\n path: [{_key: blockKey}],\n offset: selectionPoint.offset,\n }\n }\n\n return childSelectionPointToBlockOffset({\n context,\n selectionPoint,\n })\n}\n"],"names":["isSelectionCollapsed","selection","JSON","stringify","anchor","path","focus","offset","selectionPointToBlockOffset","context","selectionPoint","blockKey","getBlockKeyFromSelectionPoint","length","undefined","_key","childSelectionPointToBlockOffset"],"mappings":";;AAKO,SAASA,qBAAqBC,WAA4B;AAC/D,SAAKA,YAKHC,KAAKC,UAAUF,UAAUG,OAAOC,IAAI,MAClCH,KAAKC,UAAUF,UAAUK,MAAMD,IAAI,KACrCJ,UAAUG,OAAOG,WAAWN,UAAUK,MAAMC,SANrC;AAQX;ACNO,SAASC,4BAA4B;AAAA,EAC1CC;AAAAA,EACAC,gBAAAA;AAIF,GAA4B;AACpBC,QAAAA,WAAWC,6CAA8BF,gBAAc;AAE7D,SAAIA,iBAAeL,KAAKQ,WAAW,KAAKF,aAAaG,SAC5C;AAAA,IACLT,MAAM,CAAC;AAAA,MAACU,MAAMJ;AAAAA,IAAAA,CAAS;AAAA,IACvBJ,QAAQG,iBAAeH;AAAAA,MAIpBS,uEAAiC;AAAA,IACtCP;AAAAA,IACAC,gBAAAA;AAAAA,EAAAA,CACD;AACH;;;"}