@portabletext/editor 2.16.0 → 2.17.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.
- package/lib/_chunks-cjs/selector.get-selection-text.cjs +1 -1
- package/lib/_chunks-cjs/selector.get-selection-text.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +1 -0
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
- package/lib/_chunks-dts/behavior.types.action.d.cts +2 -2
- package/lib/_chunks-dts/behavior.types.action.d.ts +5 -5
- package/lib/_chunks-es/selector.get-selection-text.js +1 -1
- package/lib/_chunks-es/selector.get-selection-text.js.map +1 -1
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +1 -0
- package/lib/index.cjs +485 -511
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +488 -514
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.cjs +1 -0
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +8 -1
- package/lib/selectors/index.d.ts +8 -1
- package/lib/selectors/index.js +2 -1
- package/lib/utils/index.d.ts +2 -2
- package/package.json +2 -2
- package/src/behaviors/behavior.abstract.delete.ts +12 -16
- package/src/behaviors/behavior.abstract.insert.ts +37 -6
- package/src/behaviors/behavior.abstract.split.ts +24 -89
- package/src/behaviors/behavior.core.lists.ts +9 -3
- package/src/behaviors/behavior.types.event.ts +1 -1
- package/src/editor/plugins/create-with-event-listeners.ts +30 -31
- package/src/operations/behavior.operation.delete.ts +76 -80
- package/src/selectors/index.ts +1 -0
- package/src/selectors/selector.is-selection-expanded.test.ts +63 -0
- package/src/selectors/selector.is-selection-expanded.ts +1 -1
package/lib/selectors/index.cjs
CHANGED
|
@@ -197,6 +197,7 @@ exports.getNextBlock = selector_isAtTheStartOfBlock.getNextBlock;
|
|
|
197
197
|
exports.getNextInlineObject = selector_isAtTheStartOfBlock.getNextInlineObject;
|
|
198
198
|
exports.getNextSpan = selector_isAtTheStartOfBlock.getNextSpan;
|
|
199
199
|
exports.getPreviousBlock = selector_isAtTheStartOfBlock.getPreviousBlock;
|
|
200
|
+
exports.getPreviousSpan = selector_isAtTheStartOfBlock.getPreviousSpan;
|
|
200
201
|
exports.getSelectedBlocks = selector_isAtTheStartOfBlock.getSelectedBlocks;
|
|
201
202
|
exports.getSelectedSpans = selector_isAtTheStartOfBlock.getSelectedSpans;
|
|
202
203
|
exports.getSelectedTextBlocks = selector_isAtTheStartOfBlock.getSelectedTextBlocks;
|
|
@@ -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-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-text-after.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 {EditorSelector} from '../editor/editor-selector'\nimport {getBlockEndPoint} from '../utils/util.get-block-end-point'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getFocusBlock} from './selector.get-focus-block'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @public\n */\nexport const getBlockTextAfter: EditorSelector<string> = (snapshot) => {\n if (!snapshot.context.selection) {\n return ''\n }\n\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n const block = getFocusBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: endPoint,\n focus: endPoint,\n },\n },\n })\n\n if (!block) {\n return ''\n }\n\n const endOfBlock = getBlockEndPoint({\n context: snapshot.context,\n block,\n })\n\n return getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: endPoint,\n focus: endOfBlock,\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","getBlockTextAfter","getFocusBlock","endOfBlock","getBlockEndPoint","getSelectionText","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,MA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["../../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-text-after.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 {EditorSelector} from '../editor/editor-selector'\nimport {getBlockEndPoint} from '../utils/util.get-block-end-point'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getFocusBlock} from './selector.get-focus-block'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @public\n */\nexport const getBlockTextAfter: EditorSelector<string> = (snapshot) => {\n if (!snapshot.context.selection) {\n return ''\n }\n\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n const block = getFocusBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: endPoint,\n focus: endPoint,\n },\n },\n })\n\n if (!block) {\n return ''\n }\n\n const endOfBlock = getBlockEndPoint({\n context: snapshot.context,\n block,\n })\n\n return getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: endPoint,\n focus: endOfBlock,\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","getBlockTextAfter","getFocusBlock","endOfBlock","getBlockEndPoint","getSelectionText","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,KAAMC,UAASA,KAAKR,SAASX,GAAG,IAC1DM;AAEJ,SAAOC,QAAQP,MACX;AAAA,IAACO;AAAAA,IAAMG,MAAM,CAAC,GAAGG,YAAYH,MAAM,YAAY;AAAA,MAACC,MAAMX;AAAAA,IAAAA,CAAI;AAAA,EAAA,IAC1DM;AACN,GC3Bac,gBAERvB,CAAAA,aAAa;AAChB,QAAMwB,cAAcN,eAAelB,QAAQ;A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AAA;AAAAA,MACT;AAAA,IACF,CACD;AACH,GCvBaC,oBAA6CnE,CAAAA,aAAa;AACrE,MAAI,CAACA,SAASC,QAAQC;AACpB,WAAO;AAGT,QAAM6D,WAAWjC,sBAAAA,qBAAqB9B,SAASC,QAAQC,SAAS,GAC1D8C,QAAQoB,wCAAc;AAAA,IAC1B,GAAGpE;AAAAA,IACHC,SAAS;AAAA,MACP,GAAGD,SAASC;AAAAA,MACZC,WAAW;AAAA,QACTG,QAAQ0D;AAAAA,QACR1B,OAAO0B;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AAED,MAAI,CAACf;AACH,WAAO;AAGT,QAAMqB,aAAaC,sBAAAA,iBAAiB;AAAA,IAClCrE,SAASD,SAASC;AAAAA,IAClB+C;AAAAA,EAAAA,CACD;AAED,SAAOuB,2CAAiB;AAAA,IACtB,GAAGvE;AAAAA,IACHC,SAAS;AAAA,MACP,GAAGD,SAASC;AAAAA,MACZC,WAAW;AAAA,QACTG,QAAQ0D;AAAAA,QACR1B,OAAOgC;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AACH,GCvCaG,WACXxE,CAAAA,aAEOA,SAASC,QAAQU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -193,6 +193,13 @@ declare const getPreviousInlineObjects: EditorSelector<Array<{
|
|
|
193
193
|
node: PortableTextObject;
|
|
194
194
|
path: ChildPath;
|
|
195
195
|
}>>;
|
|
196
|
+
/**
|
|
197
|
+
* @public
|
|
198
|
+
*/
|
|
199
|
+
declare const getPreviousSpan: EditorSelector<{
|
|
200
|
+
node: PortableTextSpan;
|
|
201
|
+
path: [KeyedSegment, 'children', KeyedSegment];
|
|
202
|
+
} | undefined>;
|
|
196
203
|
/**
|
|
197
204
|
* @public
|
|
198
205
|
*/
|
|
@@ -347,4 +354,4 @@ declare const isSelectionCollapsed: EditorSelector<boolean>;
|
|
|
347
354
|
* @public
|
|
348
355
|
*/
|
|
349
356
|
declare const isSelectionExpanded: EditorSelector<boolean>;
|
|
350
|
-
export { MarkState, getActiveAnnotations, getActiveListItem, getActiveStyle, getAnchorBlock, getAnchorChild, getAnchorSpan, getAnchorTextBlock, getBlockOffsets, getBlockTextAfter, getBlockTextBefore, getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusInlineObject, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getListIndex, getMarkState, getNextBlock, getNextInlineObject, getNextInlineObjects, getNextSpan, 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 };
|
|
357
|
+
export { MarkState, getActiveAnnotations, getActiveListItem, getActiveStyle, getAnchorBlock, getAnchorChild, getAnchorSpan, getAnchorTextBlock, getBlockOffsets, getBlockTextAfter, getBlockTextBefore, getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusInlineObject, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getListIndex, getMarkState, getNextBlock, getNextInlineObject, getNextInlineObjects, getNextSpan, getPreviousBlock, getPreviousInlineObject, getPreviousInlineObjects, getPreviousSpan, 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 };
|
package/lib/selectors/index.d.ts
CHANGED
|
@@ -193,6 +193,13 @@ declare const getPreviousInlineObjects: EditorSelector<Array<{
|
|
|
193
193
|
node: PortableTextObject;
|
|
194
194
|
path: ChildPath;
|
|
195
195
|
}>>;
|
|
196
|
+
/**
|
|
197
|
+
* @public
|
|
198
|
+
*/
|
|
199
|
+
declare const getPreviousSpan: EditorSelector<{
|
|
200
|
+
node: PortableTextSpan;
|
|
201
|
+
path: [KeyedSegment, 'children', KeyedSegment];
|
|
202
|
+
} | undefined>;
|
|
196
203
|
/**
|
|
197
204
|
* @public
|
|
198
205
|
*/
|
|
@@ -347,4 +354,4 @@ declare const isSelectionCollapsed: EditorSelector<boolean>;
|
|
|
347
354
|
* @public
|
|
348
355
|
*/
|
|
349
356
|
declare const isSelectionExpanded: EditorSelector<boolean>;
|
|
350
|
-
export { MarkState, getActiveAnnotations, getActiveListItem, getActiveStyle, getAnchorBlock, getAnchorChild, getAnchorSpan, getAnchorTextBlock, getBlockOffsets, getBlockTextAfter, getBlockTextBefore, getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusInlineObject, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getListIndex, getMarkState, getNextBlock, getNextInlineObject, getNextInlineObjects, getNextSpan, 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 };
|
|
357
|
+
export { MarkState, getActiveAnnotations, getActiveListItem, getActiveStyle, getAnchorBlock, getAnchorChild, getAnchorSpan, getAnchorTextBlock, getBlockOffsets, getBlockTextAfter, getBlockTextBefore, getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusInlineObject, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getListIndex, getMarkState, getNextBlock, getNextInlineObject, getNextInlineObjects, getNextSpan, getPreviousBlock, getPreviousInlineObject, getPreviousInlineObjects, getPreviousSpan, 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 };
|
package/lib/selectors/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getSelectionEndPoint } from "../_chunks-es/selector.is-at-the-start-of-block.js";
|
|
2
|
-
import { getActiveAnnotations, getActiveListItem, getActiveStyle, getCaretWordSelection, getFirstBlock, getFocusBlockObject, getFocusInlineObject, getFocusListBlock, getLastBlock, getMarkState, getNextBlock, getNextInlineObject, getNextSpan, getPreviousBlock, getSelectedBlocks, getSelectedSpans, getSelectedTextBlocks, getSelectionEndBlock, getSelectionStartBlock, getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks } from "../_chunks-es/selector.is-at-the-start-of-block.js";
|
|
2
|
+
import { getActiveAnnotations, getActiveListItem, getActiveStyle, getCaretWordSelection, getFirstBlock, getFocusBlockObject, getFocusInlineObject, getFocusListBlock, getLastBlock, getMarkState, getNextBlock, getNextInlineObject, getNextSpan, getPreviousBlock, getPreviousSpan, getSelectedBlocks, getSelectedSpans, getSelectedTextBlocks, getSelectionEndBlock, getSelectionStartBlock, getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks } from "../_chunks-es/selector.is-at-the-start-of-block.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
4
|
import { isTextBlock, isSpan } from "@portabletext/schema";
|
|
5
5
|
import { isPortableTextSpan, isKeySegment } from "@sanity/types";
|
|
@@ -219,6 +219,7 @@ export {
|
|
|
219
219
|
getPreviousBlock,
|
|
220
220
|
getPreviousInlineObject,
|
|
221
221
|
getPreviousInlineObjects,
|
|
222
|
+
getPreviousSpan,
|
|
222
223
|
getSelectedBlocks,
|
|
223
224
|
getSelectedSlice,
|
|
224
225
|
getSelectedSpans,
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BlockOffset, BlockPath, ChildPath, EditorContext, EditorSelection, EditorSelectionPoint } from "../_chunks-dts/behavior.types.action.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _sanity_types9 from "@sanity/types";
|
|
3
3
|
import { KeyedSegment, PortableTextBlock, PortableTextTextBlock } from "@sanity/types";
|
|
4
4
|
import { isSpan, isTextBlock } from "@portabletext/schema";
|
|
5
5
|
/**
|
|
@@ -143,7 +143,7 @@ declare function mergeTextBlocks({
|
|
|
143
143
|
context: Pick<EditorContext, 'keyGenerator' | 'schema'>;
|
|
144
144
|
targetBlock: PortableTextTextBlock;
|
|
145
145
|
incomingBlock: PortableTextTextBlock;
|
|
146
|
-
}): PortableTextTextBlock<
|
|
146
|
+
}): PortableTextTextBlock<_sanity_types9.PortableTextObject | _sanity_types9.PortableTextSpan>;
|
|
147
147
|
/**
|
|
148
148
|
* @public
|
|
149
149
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.17.1",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -118,8 +118,8 @@
|
|
|
118
118
|
"vite": "^7.1.10",
|
|
119
119
|
"vitest": "^4.0.4",
|
|
120
120
|
"vitest-browser-react": "^2.0.2",
|
|
121
|
-
"@portabletext/test": "^0.0.0",
|
|
122
121
|
"@portabletext/sanity-bridge": "1.1.16",
|
|
122
|
+
"@portabletext/test": "^0.0.0",
|
|
123
123
|
"racejar": "1.3.2"
|
|
124
124
|
},
|
|
125
125
|
"peerDependencies": {
|
|
@@ -17,19 +17,14 @@ export const abstractDeleteBehaviors = [
|
|
|
17
17
|
defineBehavior({
|
|
18
18
|
on: 'delete.backward',
|
|
19
19
|
guard: ({snapshot}) => {
|
|
20
|
-
|
|
21
|
-
return false
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return {selection: snapshot.context.selection}
|
|
20
|
+
return snapshot.context.selection
|
|
25
21
|
},
|
|
26
22
|
actions: [
|
|
27
|
-
({event}
|
|
23
|
+
({event}) => [
|
|
28
24
|
raise({
|
|
29
25
|
type: 'delete',
|
|
30
26
|
direction: 'backward',
|
|
31
27
|
unit: event.unit,
|
|
32
|
-
at: selection,
|
|
33
28
|
}),
|
|
34
29
|
],
|
|
35
30
|
],
|
|
@@ -88,19 +83,14 @@ export const abstractDeleteBehaviors = [
|
|
|
88
83
|
defineBehavior({
|
|
89
84
|
on: 'delete.forward',
|
|
90
85
|
guard: ({snapshot}) => {
|
|
91
|
-
|
|
92
|
-
return false
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return {selection: snapshot.context.selection}
|
|
86
|
+
return snapshot.context.selection
|
|
96
87
|
},
|
|
97
88
|
actions: [
|
|
98
|
-
({event}
|
|
89
|
+
({event}) => [
|
|
99
90
|
raise({
|
|
100
91
|
type: 'delete',
|
|
101
92
|
direction: 'forward',
|
|
102
93
|
unit: event.unit,
|
|
103
|
-
at: selection,
|
|
104
94
|
}),
|
|
105
95
|
],
|
|
106
96
|
],
|
|
@@ -112,18 +102,24 @@ export const abstractDeleteBehaviors = [
|
|
|
112
102
|
return false
|
|
113
103
|
}
|
|
114
104
|
|
|
105
|
+
const at = event.at ?? snapshot.context.selection
|
|
106
|
+
|
|
107
|
+
if (!at) {
|
|
108
|
+
return false
|
|
109
|
+
}
|
|
110
|
+
|
|
115
111
|
const nextBlock = getNextBlock({
|
|
116
112
|
...snapshot,
|
|
117
113
|
context: {
|
|
118
114
|
...snapshot.context,
|
|
119
|
-
selection:
|
|
115
|
+
selection: at,
|
|
120
116
|
},
|
|
121
117
|
})
|
|
122
118
|
const focusTextBlock = getFocusTextBlock({
|
|
123
119
|
...snapshot,
|
|
124
120
|
context: {
|
|
125
121
|
...snapshot.context,
|
|
126
|
-
selection:
|
|
122
|
+
selection: at,
|
|
127
123
|
},
|
|
128
124
|
})
|
|
129
125
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import {isSelectionExpanded} from '../selectors'
|
|
1
2
|
import {getFocusTextBlock} from '../selectors/selector.get-focus-text-block'
|
|
2
3
|
import {getLastBlock} from '../selectors/selector.get-last-block'
|
|
3
|
-
import {isSelectionCollapsed} from '../utils'
|
|
4
4
|
import {getBlockEndPoint} from '../utils/util.get-block-end-point'
|
|
5
5
|
import {getBlockStartPoint} from '../utils/util.get-block-start-point'
|
|
6
6
|
import {isEmptyTextBlock} from '../utils/util.is-empty-text-block'
|
|
@@ -473,20 +473,51 @@ export const abstractInsertBehaviors = [
|
|
|
473
473
|
],
|
|
474
474
|
],
|
|
475
475
|
}),
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* If there's an expanded selection, then we delete the selection before we
|
|
479
|
+
* insert the text.
|
|
480
|
+
*/
|
|
476
481
|
defineBehavior({
|
|
477
482
|
on: 'insert.text',
|
|
478
483
|
guard: ({snapshot}) => {
|
|
479
|
-
|
|
484
|
+
return isSelectionExpanded(snapshot)
|
|
485
|
+
},
|
|
486
|
+
actions: [({event}) => [raise({type: 'delete'}), raise(event)]],
|
|
487
|
+
}),
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* If there's no selection, then we select the end of the editor before we
|
|
491
|
+
* we insert the text.
|
|
492
|
+
*/
|
|
493
|
+
defineBehavior({
|
|
494
|
+
on: 'insert.text',
|
|
495
|
+
guard: ({snapshot}) => {
|
|
496
|
+
if (snapshot.context.selection) {
|
|
497
|
+
return false
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
const lastBlok = getLastBlock(snapshot)
|
|
480
501
|
|
|
481
|
-
if (!
|
|
502
|
+
if (!lastBlok) {
|
|
482
503
|
return false
|
|
483
504
|
}
|
|
484
505
|
|
|
485
|
-
|
|
506
|
+
const endPoint = getBlockEndPoint({
|
|
507
|
+
context: snapshot.context,
|
|
508
|
+
block: lastBlok,
|
|
509
|
+
})
|
|
510
|
+
return {endPoint}
|
|
486
511
|
},
|
|
487
512
|
actions: [
|
|
488
|
-
({event}, {
|
|
489
|
-
raise({
|
|
513
|
+
({event}, {endPoint}) => [
|
|
514
|
+
raise({
|
|
515
|
+
type: 'select',
|
|
516
|
+
at: {
|
|
517
|
+
anchor: endPoint,
|
|
518
|
+
focus: endPoint,
|
|
519
|
+
},
|
|
520
|
+
}),
|
|
490
521
|
raise(event),
|
|
491
522
|
],
|
|
492
523
|
],
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {isTextBlock} from '@portabletext/schema'
|
|
2
|
+
import {isSelectionExpanded} from '../selectors'
|
|
2
3
|
import {getFocusBlockObject} from '../selectors/selector.get-focus-block-object'
|
|
3
4
|
import {getFocusInlineObject} from '../selectors/selector.get-focus-inline-object'
|
|
4
5
|
import {getFocusTextBlock} from '../selectors/selector.get-focus-text-block'
|
|
5
|
-
import {getSelectedValue} from '../selectors/selector.get-selected-value'
|
|
6
6
|
import {getSelectionEndBlock} from '../selectors/selector.get-selection-end-block'
|
|
7
7
|
import {getSelectionStartBlock} from '../selectors/selector.get-selection-start-block'
|
|
8
|
+
import {isEqualSelectionPoints} from '../utils'
|
|
8
9
|
import {parseBlock} from '../utils/parse-blocks'
|
|
9
10
|
import {getBlockEndPoint} from '../utils/util.get-block-end-point'
|
|
10
11
|
import {getBlockStartPoint} from '../utils/util.get-block-start-point'
|
|
@@ -47,115 +48,49 @@ export const abstractSplitBehaviors = [
|
|
|
47
48
|
return false
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
if (!selectionStartBlock || !selectionEndBlock) {
|
|
54
|
-
return false
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (
|
|
58
|
-
!isTextBlock(snapshot.context, selectionStartBlock.node) &&
|
|
59
|
-
isTextBlock(snapshot.context, selectionEndBlock.node)
|
|
60
|
-
) {
|
|
61
|
-
return {selection}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return false
|
|
65
|
-
},
|
|
66
|
-
actions: [(_, {selection}) => [raise({type: 'delete', at: selection})]],
|
|
67
|
-
}),
|
|
68
|
-
|
|
69
|
-
defineBehavior({
|
|
70
|
-
on: 'split',
|
|
71
|
-
guard: ({snapshot}) => {
|
|
72
|
-
const selection = snapshot.context.selection
|
|
51
|
+
const startPoint = getSelectionStartPoint(selection)
|
|
52
|
+
const endPoint = getSelectionEndPoint(selection)
|
|
73
53
|
|
|
74
|
-
if (!
|
|
54
|
+
if (!startPoint || !endPoint) {
|
|
75
55
|
return false
|
|
76
56
|
}
|
|
77
57
|
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
if (!selectionStartBlock || !selectionEndBlock) {
|
|
82
|
-
return false
|
|
83
|
-
}
|
|
58
|
+
const startBlock = getSelectionStartBlock(snapshot)
|
|
59
|
+
const endBlock = getSelectionEndBlock(snapshot)
|
|
84
60
|
|
|
85
|
-
if (
|
|
61
|
+
if (!startBlock || !endBlock) {
|
|
86
62
|
return false
|
|
87
63
|
}
|
|
88
64
|
|
|
89
|
-
const
|
|
90
|
-
const startBlockEndPoint = getBlockEndPoint({
|
|
65
|
+
const startBlockStartPoint = getBlockStartPoint({
|
|
91
66
|
context: snapshot.context,
|
|
92
|
-
block:
|
|
67
|
+
block: startBlock,
|
|
93
68
|
})
|
|
94
|
-
const
|
|
95
|
-
const endBlockStartPoint = getBlockStartPoint({
|
|
69
|
+
const endBlockEndPoint = getBlockEndPoint({
|
|
96
70
|
context: snapshot.context,
|
|
97
|
-
block:
|
|
71
|
+
block: endBlock,
|
|
98
72
|
})
|
|
99
73
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return {
|
|
109
|
-
startPoint,
|
|
110
|
-
startBlockEndPoint,
|
|
111
|
-
endPoint,
|
|
112
|
-
endBlockStartPoint,
|
|
113
|
-
blocksInBetween,
|
|
74
|
+
if (
|
|
75
|
+
isTextBlock(snapshot.context, startBlock.node) &&
|
|
76
|
+
isTextBlock(snapshot.context, endBlock.node) &&
|
|
77
|
+
!isEqualSelectionPoints(startPoint, startBlockStartPoint) &&
|
|
78
|
+
!isEqualSelectionPoints(endPoint, endBlockEndPoint)
|
|
79
|
+
) {
|
|
80
|
+
return true
|
|
114
81
|
}
|
|
82
|
+
|
|
83
|
+
return false
|
|
115
84
|
},
|
|
116
|
-
actions: [
|
|
117
|
-
(
|
|
118
|
-
_,
|
|
119
|
-
{
|
|
120
|
-
startPoint,
|
|
121
|
-
startBlockEndPoint,
|
|
122
|
-
endPoint,
|
|
123
|
-
endBlockStartPoint,
|
|
124
|
-
blocksInBetween,
|
|
125
|
-
},
|
|
126
|
-
) => [
|
|
127
|
-
raise({
|
|
128
|
-
type: 'delete',
|
|
129
|
-
at: {anchor: startPoint, focus: startBlockEndPoint},
|
|
130
|
-
}),
|
|
131
|
-
...blocksInBetween.map((block) =>
|
|
132
|
-
raise({type: 'delete.block', at: [{_key: block._key}]}),
|
|
133
|
-
),
|
|
134
|
-
raise({
|
|
135
|
-
type: 'delete',
|
|
136
|
-
at: {anchor: endBlockStartPoint, focus: endPoint},
|
|
137
|
-
}),
|
|
138
|
-
],
|
|
139
|
-
],
|
|
85
|
+
actions: [() => [raise({type: 'delete'}), raise({type: 'split'})]],
|
|
140
86
|
}),
|
|
141
87
|
|
|
142
88
|
defineBehavior({
|
|
143
89
|
on: 'split',
|
|
144
90
|
guard: ({snapshot}) => {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (!selection || isSelectionCollapsed(selection)) {
|
|
148
|
-
return false
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return {selection}
|
|
91
|
+
return isSelectionExpanded(snapshot)
|
|
152
92
|
},
|
|
153
|
-
actions: [
|
|
154
|
-
(_, {selection}) => [
|
|
155
|
-
raise({type: 'delete', at: selection}),
|
|
156
|
-
raise({type: 'split'}),
|
|
157
|
-
],
|
|
158
|
-
],
|
|
93
|
+
actions: [() => [raise({type: 'delete'})]],
|
|
159
94
|
}),
|
|
160
95
|
|
|
161
96
|
defineBehavior({
|
|
@@ -204,11 +204,17 @@ const mergeTextIntoListOnBackspace = defineBehavior({
|
|
|
204
204
|
const deletingListFromStart = defineBehavior({
|
|
205
205
|
on: 'delete',
|
|
206
206
|
guard: ({snapshot, event}) => {
|
|
207
|
+
const at = event.at ?? snapshot.context.selection
|
|
208
|
+
|
|
209
|
+
if (!at) {
|
|
210
|
+
return false
|
|
211
|
+
}
|
|
212
|
+
|
|
207
213
|
const blocksToDelete = getSelectedBlocks({
|
|
208
214
|
...snapshot,
|
|
209
215
|
context: {
|
|
210
216
|
...snapshot.context,
|
|
211
|
-
selection:
|
|
217
|
+
selection: at,
|
|
212
218
|
},
|
|
213
219
|
})
|
|
214
220
|
|
|
@@ -233,14 +239,14 @@ const deletingListFromStart = defineBehavior({
|
|
|
233
239
|
...snapshot,
|
|
234
240
|
context: {
|
|
235
241
|
...snapshot.context,
|
|
236
|
-
selection:
|
|
242
|
+
selection: at,
|
|
237
243
|
},
|
|
238
244
|
})
|
|
239
245
|
const deleteEndPoint = getSelectionEndPoint({
|
|
240
246
|
...snapshot,
|
|
241
247
|
context: {
|
|
242
248
|
...snapshot.context,
|
|
243
|
-
selection:
|
|
249
|
+
selection: at,
|
|
244
250
|
},
|
|
245
251
|
})
|
|
246
252
|
|
|
@@ -18,38 +18,37 @@ export function createWithEventListeners(editorActor: EditorActor) {
|
|
|
18
18
|
return
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
21
|
+
const range = options?.at ? Editor.range(editor, options.at) : undefined
|
|
22
|
+
const selection = range
|
|
23
|
+
? slateRangeToSelection({
|
|
24
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
25
|
+
editor,
|
|
26
|
+
range,
|
|
27
|
+
})
|
|
28
|
+
: undefined
|
|
29
|
+
|
|
30
|
+
if (selection) {
|
|
31
|
+
editorActor.send({
|
|
32
|
+
type: 'behavior event',
|
|
33
|
+
behaviorEvent: {
|
|
34
|
+
type: 'delete',
|
|
35
|
+
at: selection,
|
|
36
|
+
direction: options?.reverse ? 'backward' : 'forward',
|
|
37
|
+
unit: options?.unit,
|
|
38
|
+
},
|
|
39
|
+
editor,
|
|
40
|
+
})
|
|
41
|
+
} else {
|
|
42
|
+
editorActor.send({
|
|
43
|
+
type: 'behavior event',
|
|
44
|
+
behaviorEvent: {
|
|
45
|
+
type: 'delete',
|
|
46
|
+
direction: options?.reverse ? 'backward' : 'forward',
|
|
47
|
+
unit: options?.unit,
|
|
48
|
+
},
|
|
49
|
+
editor,
|
|
50
|
+
})
|
|
41
51
|
}
|
|
42
|
-
|
|
43
|
-
editorActor.send({
|
|
44
|
-
type: 'behavior event',
|
|
45
|
-
behaviorEvent: {
|
|
46
|
-
type: 'delete',
|
|
47
|
-
at: selection,
|
|
48
|
-
direction: options?.reverse ? 'backward' : 'forward',
|
|
49
|
-
unit: options?.unit,
|
|
50
|
-
},
|
|
51
|
-
editor,
|
|
52
|
-
})
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
editor.deleteBackward = (unit) => {
|