@portabletext/editor 1.33.2 → 1.33.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +11 -204
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
  3. package/lib/_chunks-cjs/behavior.markdown.cjs +7 -7
  4. package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
  5. package/lib/_chunks-cjs/plugin.event-listener.cjs +208 -33
  6. package/lib/_chunks-cjs/plugin.event-listener.cjs.map +1 -1
  7. package/lib/_chunks-cjs/selector.get-text-before.cjs +3 -3
  8. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  9. package/lib/_chunks-cjs/selector.is-active-style.cjs +246 -0
  10. package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -0
  11. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +31 -200
  12. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
  13. package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs +7 -5
  14. package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs.map +1 -1
  15. package/lib/_chunks-cjs/util.reverse-selection.cjs +0 -116
  16. package/lib/_chunks-cjs/util.reverse-selection.cjs.map +1 -1
  17. package/lib/_chunks-cjs/util.slice-blocks.cjs +138 -1
  18. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
  19. package/lib/_chunks-es/behavior.core.js +9 -202
  20. package/lib/_chunks-es/behavior.core.js.map +1 -1
  21. package/lib/_chunks-es/behavior.markdown.js +1 -1
  22. package/lib/_chunks-es/plugin.event-listener.js +205 -31
  23. package/lib/_chunks-es/plugin.event-listener.js.map +1 -1
  24. package/lib/_chunks-es/selector.get-text-before.js +2 -1
  25. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  26. package/lib/_chunks-es/selector.is-active-style.js +249 -0
  27. package/lib/_chunks-es/selector.is-active-style.js.map +1 -0
  28. package/lib/_chunks-es/selector.is-at-the-start-of-block.js +20 -189
  29. package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
  30. package/lib/_chunks-es/util.block-offsets-to-selection.js +5 -3
  31. package/lib/_chunks-es/util.block-offsets-to-selection.js.map +1 -1
  32. package/lib/_chunks-es/util.reverse-selection.js +1 -117
  33. package/lib/_chunks-es/util.reverse-selection.js.map +1 -1
  34. package/lib/_chunks-es/util.slice-blocks.js +140 -3
  35. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  36. package/lib/index.d.cts +1 -115
  37. package/lib/index.d.ts +1 -115
  38. package/lib/plugins/index.cjs +19 -15
  39. package/lib/plugins/index.cjs.map +1 -1
  40. package/lib/plugins/index.d.cts +1 -115
  41. package/lib/plugins/index.d.ts +1 -115
  42. package/lib/plugins/index.js +9 -5
  43. package/lib/plugins/index.js.map +1 -1
  44. package/lib/selectors/index.cjs +16 -21
  45. package/lib/selectors/index.cjs.map +1 -1
  46. package/lib/selectors/index.d.cts +2 -0
  47. package/lib/selectors/index.d.ts +2 -0
  48. package/lib/selectors/index.js +7 -11
  49. package/lib/selectors/index.js.map +1 -1
  50. package/lib/utils/index.cjs +13 -13
  51. package/lib/utils/index.cjs.map +1 -1
  52. package/lib/utils/index.d.cts +2 -0
  53. package/lib/utils/index.d.ts +2 -0
  54. package/lib/utils/index.js +3 -3
  55. package/package.json +2 -2
  56. package/src/behaviors/behavior.core.annotations.ts +0 -24
  57. package/src/behaviors/behavior.core.decorators.ts +0 -19
  58. package/src/behaviors/behavior.core.insert-break.ts +4 -4
  59. package/src/behaviors/behavior.core.lists.ts +0 -30
  60. package/src/behaviors/behavior.core.ts +2 -17
  61. package/src/behaviors/behavior.default.ts +198 -0
  62. package/src/behaviors/behavior.foundational.ts +12 -12
  63. package/src/behaviors/behavior.markdown-emphasis.ts +4 -0
  64. package/src/converters/converter.text-html.serialize.test.ts +1 -1
  65. package/src/editor/PortableTextEditor.tsx +1 -1
  66. package/src/editor/editor-machine.ts +8 -8
  67. package/src/plugins/plugin.event-listener.tsx +1 -1
  68. package/src/selectors/selector.get-caret-word-selection.ts +9 -0
  69. package/src/selectors/selector.get-selection-text.test.ts +383 -36
  70. package/src/selectors/selector.get-selection-text.ts +13 -73
  71. package/src/utils/util.block-offset.test.ts +312 -0
  72. package/src/utils/util.block-offset.ts +39 -7
  73. package/src/utils/util.block-offsets-to-selection.ts +2 -0
  74. package/src/utils/util.slice-blocks.ts +12 -1
  75. package/lib/_chunks-cjs/selector.get-trimmed-selection.cjs +0 -97
  76. package/lib/_chunks-cjs/selector.get-trimmed-selection.cjs.map +0 -1
  77. package/lib/_chunks-es/selector.get-trimmed-selection.js +0 -100
  78. package/lib/_chunks-es/selector.get-trimmed-selection.js.map +0 -1
  79. package/src/behaviors/behavior.core.deserialize.ts +0 -60
  80. package/src/behaviors/behavior.core.serialize.ts +0 -44
  81. package/src/behaviors/behavior.core.style.ts +0 -19
@@ -1 +1 @@
1
- {"version":3,"file":"selector.is-at-the-start-of-block.cjs","sources":["../../src/behavior-actions/behavior.guards.ts","../../src/selectors/selector.get-selected-spans.ts","../../src/selectors/selectors.ts","../../src/selectors/selector.get-active-list-item.ts","../../src/selectors/selector.get-active-style.ts","../../src/selectors/selector.get-selection-end-point.ts","../../src/selectors/selector.get-selection-start-point.ts","../../src/selectors/selector.get-next-inline-object.ts","../../src/selectors/selector.get-previous-inline-object.ts","../../src/selectors/selector.get-selection-text.ts","../../src/selectors/selector.is-selection-collapsed.ts","../../src/selectors/selector.is-selection-expanded.ts","../../src/selectors/selector.get-caret-word-selection.ts","../../src/selectors/selector.is-active-annotation.ts","../../src/selectors/selector.is-active-decorator.ts","../../src/selectors/selector.is-active-list-item.ts","../../src/selectors/selector.is-active-style.ts","../../src/selectors/selector.is-at-the-end-of-block.ts","../../src/selectors/selector.is-at-the-start-of-block.ts"],"sourcesContent":["import {\n isPortableTextListBlock,\n isPortableTextTextBlock,\n type PortableTextListBlock,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {EditorSchema} from '../editor/define-schema'\n\n/**\n * @alpha\n */\nexport type BehaviorGuards = ReturnType<typeof createGuards>\n\nexport function createGuards({schema}: {schema: EditorSchema}) {\n function isListBlock(block: unknown): block is PortableTextListBlock {\n return isPortableTextListBlock(block) && block._type === schema.block.name\n }\n\n function isTextBlock(block: unknown): block is PortableTextTextBlock {\n return isPortableTextTextBlock(block) && block._type === schema.block.name\n }\n\n return {isListBlock, isTextBlock}\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextSpan,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelectedSpans: EditorSelector<\n Array<{\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }>\n> = ({context}) => {\n if (!context.selection) {\n return []\n }\n\n const selectedSpans: Array<{\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }> = []\n\n const startPoint = context.selection.backward\n ? context.selection.focus\n : context.selection.anchor\n const endPoint = context.selection.backward\n ? context.selection.anchor\n : context.selection.focus\n\n const startBlockKey = isKeySegment(startPoint.path[0])\n ? startPoint.path[0]._key\n : undefined\n const endBlockKey = isKeySegment(endPoint.path[0])\n ? endPoint.path[0]._key\n : undefined\n\n if (!startBlockKey || !endBlockKey) {\n return selectedSpans\n }\n\n const startSpanKey = isKeySegment(startPoint.path[2])\n ? startPoint.path[2]._key\n : undefined\n const endSpanKey = isKeySegment(endPoint.path[2])\n ? endPoint.path[2]._key\n : undefined\n\n for (const block of context.value) {\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n if (block._key === startBlockKey) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (startSpanKey && child._key === startSpanKey) {\n if (startPoint.offset < child.text.length) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n\n if (startSpanKey === endSpanKey) {\n break\n }\n\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n if (endPoint.offset > 0) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n break\n }\n\n if (selectedSpans.length > 0) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n\n continue\n }\n\n if (block._key === endBlockKey) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n if (endPoint.offset > 0) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n break\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n\n break\n }\n\n if (selectedSpans.length > 0) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n }\n\n return selectedSpans\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n type PortableTextListBlock,\n type PortableTextObject,\n type PortableTextSpan,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusListBlock: EditorSelector<\n {node: PortableTextListBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const guards = createGuards(context)\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && guards.isListBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusBlockObject: EditorSelector<\n {node: PortableTextObject; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && !isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n const focusBlock = getFocusTextBlock({context})\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[2])\n ? context.selection.focus.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? focusBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...focusBlock.path, 'children', {_key: key}]}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = ({context}) => {\n const focusChild = getFocusChild({context})\n\n return focusChild && isPortableTextSpan(focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFirstBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const node = context.value[0]\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getLastBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const node = context.value[context.value.length - 1]\n ? context.value[context.value.length - 1]\n : undefined\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getSelectedBlocks: EditorSelector<\n Array<{node: PortableTextBlock; path: [KeyedSegment]}>\n> = ({context}) => {\n if (!context.selection) {\n return []\n }\n\n const selectedBlocks: Array<{node: PortableTextBlock; path: [KeyedSegment]}> =\n []\n const startKey = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n const endKey = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n if (!startKey || !endKey) {\n return selectedBlocks\n }\n\n for (const block of context.value) {\n if (block._key === startKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n\n if (startKey === endKey) {\n break\n }\n continue\n }\n\n if (block._key === endKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n break\n }\n\n if (selectedBlocks.length > 0) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n }\n }\n\n return selectedBlocks\n}\n\n/**\n * @public\n */\nexport const getSelectionStartBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getSelectionEndBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getPreviousBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n let previousBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionStartBlock = getSelectionStartBlock({context})\n\n if (!selectionStartBlock) {\n return undefined\n }\n\n let foundSelectionStartBlock = false\n\n for (const block of context.value) {\n if (block._key === selectionStartBlock.node._key) {\n foundSelectionStartBlock = true\n break\n }\n\n previousBlock = {node: block, path: [{_key: block._key}]}\n }\n\n if (foundSelectionStartBlock && previousBlock) {\n return previousBlock\n }\n\n return undefined\n}\n\n/**\n * @public\n */\nexport const getNextBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n let nextBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionEndBlock = getSelectionEndBlock({context})\n\n if (!selectionEndBlock) {\n return undefined\n }\n\n let foundSelectionEndBlock = false\n\n for (const block of context.value) {\n if (block._key === selectionEndBlock.node._key) {\n foundSelectionEndBlock = true\n continue\n }\n\n if (foundSelectionEndBlock) {\n nextBlock = {node: block, path: [{_key: block._key}]}\n break\n }\n }\n\n if (foundSelectionEndBlock && nextBlock) {\n return nextBlock\n }\n\n return undefined\n}\n","import type {PortableTextListBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveListItem: EditorSelector<\n PortableTextListBlock['listItem'] | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const guards = createGuards(context)\n const selectedBlocks = getSelectedBlocks({context}).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstListItem = firstTextBlock.listItem\n\n if (!firstListItem) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.listItem === firstListItem)) {\n return firstListItem\n }\n\n return undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveStyle: EditorSelector<PortableTextTextBlock['style']> = ({\n context,\n}) => {\n if (!context.selection) {\n return undefined\n }\n\n const guards = createGuards(context)\n const selectedBlocks = getSelectedBlocks({context}).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstStyle = firstTextBlock.style\n\n if (!firstStyle) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.style === firstStyle)) {\n return firstStyle\n }\n\n return undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectionEndPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n return context.selection.backward\n ? context.selection.anchor\n : context.selection.focus\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectionStartPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n return context.selection.backward\n ? context.selection.focus\n : context.selection.anchor\n}\n","import {\n isKeySegment,\n type KeyedSegment,\n type PortableTextObject,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isSpan} from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getFocusTextBlock} from './selectors'\n\n/**\n * @public\n */\nexport const getNextInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n const focusTextBlock = getFocusTextBlock({context})\n const selectionEndPoint = getSelectionEndPoint({context})\n const selectionEndPointChildKey =\n selectionEndPoint && isKeySegment(selectionEndPoint.path[2])\n ? selectionEndPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionEndPointChildKey) {\n return undefined\n }\n\n let endPointChildFound = false\n let inlineObject:\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionEndPointChildKey) {\n endPointChildFound = true\n continue\n }\n\n if (!isSpan(context, child) && endPointChildFound) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n break\n }\n }\n\n return inlineObject\n}\n","import {\n isKeySegment,\n type KeyedSegment,\n type PortableTextObject,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isSpan} from '../utils'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\nimport {getFocusTextBlock} from './selectors'\n\n/**\n * @public\n */\nexport const getPreviousInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n const focusTextBlock = getFocusTextBlock({context})\n const selectionStartPoint = getSelectionStartPoint({context})\n const selectionStartPointChildKey =\n selectionStartPoint && isKeySegment(selectionStartPoint.path[2])\n ? selectionStartPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionStartPointChildKey) {\n return undefined\n }\n\n let inlineObject:\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionStartPointChildKey) {\n break\n }\n\n if (!isSpan(context, child)) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n }\n }\n\n return inlineObject\n}\n","import {isPortableTextSpan, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {reverseSelection} from '../utils/util.reverse-selection'\n\n/**\n * @public\n */\nexport const getSelectionText: EditorSelector<string> = ({context}) => {\n let text = ''\n\n const {value, selection} = context\n\n if (!value || !selection) {\n return text\n }\n\n const forwardSelection = selection.backward\n ? reverseSelection(selection)\n : selection\n\n if (!forwardSelection) {\n return text\n }\n\n for (const block of value) {\n if (\n isKeyedSegment(forwardSelection.anchor.path[0]) &&\n block._key !== forwardSelection.anchor.path[0]._key\n ) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n for (const child of block.children) {\n if (isPortableTextSpan(child)) {\n if (\n isKeyedSegment(forwardSelection.anchor.path[2]) &&\n child._key === forwardSelection.anchor.path[2]._key &&\n isKeyedSegment(forwardSelection.focus.path[2]) &&\n child._key === forwardSelection.focus.path[2]._key\n ) {\n text =\n text +\n child.text.slice(\n forwardSelection.anchor.offset,\n forwardSelection.focus.offset,\n )\n\n break\n }\n\n if (\n isKeyedSegment(forwardSelection.anchor.path[2]) &&\n child._key === forwardSelection.anchor.path[2]._key\n ) {\n text = text + child.text.slice(forwardSelection.anchor.offset)\n continue\n }\n\n if (\n isKeyedSegment(forwardSelection.focus.path[2]) &&\n child._key === forwardSelection.focus.path[2]._key\n ) {\n text = text + child.text.slice(0, forwardSelection.focus.offset)\n break\n }\n\n if (text.length > 0) {\n text = text + child.text\n }\n }\n }\n\n if (\n isKeyedSegment(forwardSelection.focus.path[0]) &&\n block._key === forwardSelection.focus.path[0]._key\n ) {\n break\n }\n }\n\n return text\n}\n","import type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const isSelectionCollapsed: EditorSelector<boolean> = ({context}) => {\n if (!context.selection) {\n return false\n }\n\n return (\n JSON.stringify(context.selection.anchor.path) ===\n JSON.stringify(context.selection.focus.path) &&\n context.selection?.anchor.offset === context.selection?.focus.offset\n )\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport const isSelectionExpanded: EditorSelector<boolean> = ({context}) => {\n return !isSelectionCollapsed({context})\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelection} from '../types/editor'\nimport {\n blockOffsetToSpanSelectionPoint,\n getBlockEndPoint,\n getBlockStartPoint,\n spanSelectionPointToBlockOffset,\n type BlockOffset,\n} from '../utils'\nimport {getNextInlineObject} from './selector.get-next-inline-object'\nimport {getPreviousInlineObject} from './selector.get-previous-inline-object'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\nimport {getSelectionText} from './selector.get-selection-text'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\nimport {getFocusTextBlock} from './selectors'\n\n/**\n * @public\n * Returns the selection of the of the word the caret is placed in.\n * Note: Only returns a word selection if the current selection is collapsed\n */\nexport const getCaretWordSelection: EditorSelector<EditorSelection> = ({\n context,\n}) => {\n if (!context.selection) {\n return null\n }\n\n if (!isSelectionCollapsed({context})) {\n return null\n }\n\n const focusTextBlock = getFocusTextBlock({context})\n const selectionStartPoint = getSelectionStartPoint({context})\n const selectionStartOffset = selectionStartPoint\n ? spanSelectionPointToBlockOffset({\n value: context.value,\n selectionPoint: selectionStartPoint,\n })\n : undefined\n\n if (!focusTextBlock || !selectionStartPoint || !selectionStartOffset) {\n return null\n }\n\n const previousInlineObject = getPreviousInlineObject({context})\n const blockStartPoint = getBlockStartPoint(focusTextBlock)\n const textBefore = getSelectionText({\n context: {\n ...context,\n selection: {\n anchor: previousInlineObject\n ? {path: previousInlineObject.path, offset: 0}\n : blockStartPoint,\n focus: selectionStartPoint,\n },\n },\n })\n const textDirectlyBefore = textBefore.split(/\\s+/).at(-1)\n\n const nextInlineObject = getNextInlineObject({context})\n const blockEndPoint = getBlockEndPoint(focusTextBlock)\n const textAfter = getSelectionText({\n context: {\n ...context,\n selection: {\n anchor: selectionStartPoint,\n focus: nextInlineObject\n ? {path: nextInlineObject.path, offset: 0}\n : blockEndPoint,\n },\n },\n })\n const textDirectlyAfter = textAfter.split(/\\s+/).at(0)\n\n const caretWordStartOffset: BlockOffset = textDirectlyBefore\n ? {\n ...selectionStartOffset,\n offset: selectionStartOffset.offset - textDirectlyBefore.length,\n }\n : selectionStartOffset\n const caretWordEndOffset: BlockOffset = textDirectlyAfter\n ? {\n ...selectionStartOffset,\n offset: selectionStartOffset.offset + textDirectlyAfter.length,\n }\n : selectionStartOffset\n\n const caretWordStartSelectionPoint = blockOffsetToSpanSelectionPoint({\n value: context.value,\n blockOffset: caretWordStartOffset,\n })\n const caretWordEndSelectionPoint = blockOffsetToSpanSelectionPoint({\n value: context.value,\n blockOffset: caretWordEndOffset,\n })\n\n if (!caretWordStartSelectionPoint || !caretWordEndSelectionPoint) {\n return null\n }\n\n const caretWordSelection = {\n anchor: caretWordStartSelectionPoint,\n focus: caretWordEndSelectionPoint,\n }\n\n return isSelectionExpanded({\n context: {\n ...context,\n selection: caretWordSelection,\n },\n })\n ? caretWordSelection\n : null\n}\n","import {isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\nimport {getFocusSpan, getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport function isActiveAnnotation(\n annotation: string,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const focusSpan = getFocusSpan(snapshot)\n\n const selectedSpans = isSelectionExpanded(snapshot)\n ? getSelectedSpans(snapshot)\n : focusSpan\n ? [focusSpan]\n : []\n\n if (selectedSpans.length === 0) {\n return false\n }\n\n if (\n selectedSpans.some(\n (span) => !span.node.marks || span.node.marks?.length === 0,\n )\n ) {\n return false\n }\n\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isPortableTextTextBlock(block.node) ? (block.node.markDefs ?? []) : [],\n )\n\n return selectedSpans.every((span) => {\n const spanMarkDefs =\n span.node.marks?.flatMap((mark) => {\n const markDef = selectionMarkDefs.find(\n (markDef) => markDef._key === mark,\n )\n\n return markDef ? [markDef._type] : []\n }) ?? []\n\n return spanMarkDefs.includes(annotation)\n })\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\n\n/**\n * @public\n */\nexport function isActiveDecorator(decorator: string): EditorSelector<boolean> {\n return (snapshot) => {\n if (isSelectionExpanded(snapshot)) {\n const selectedSpans = getSelectedSpans(snapshot)\n\n return (\n selectedSpans.length > 0 &&\n selectedSpans.every((span) => span.node.marks?.includes(decorator))\n )\n }\n\n return snapshot.context.activeDecorators.includes(decorator)\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveListItem} from './selector.get-active-list-item'\n\n/**\n * @public\n */\nexport function isActiveListItem(listItem: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeListItem = getActiveListItem(snapshot)\n\n return activeListItem === listItem\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveStyle} from './selector.get-active-style'\n\n/**\n * @public\n */\nexport function isActiveStyle(style: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeStyle = getActiveStyle(snapshot)\n\n return activeStyle === style\n }\n}\n","import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isAtTheEndOfBlock(block: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelector<boolean> {\n return ({context}) => {\n if (!context.selection || !isSelectionCollapsed({context})) {\n return false\n }\n\n const blockEndPoint = utils.getBlockEndPoint(block)\n\n return utils.isEqualSelectionPoints(context.selection.focus, blockEndPoint)\n }\n}\n","import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isAtTheStartOfBlock(block: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelector<boolean> {\n return ({context}) => {\n if (!context.selection || !isSelectionCollapsed({context})) {\n return false\n }\n\n const blockStartPoint = utils.getBlockStartPoint(block)\n\n return utils.isEqualSelectionPoints(\n context.selection.focus,\n blockStartPoint,\n )\n }\n}\n"],"names":["createGuards","schema","isListBlock","block","isPortableTextListBlock","_type","name","isTextBlock","isPortableTextTextBlock","getSelectedSpans","context","selection","selectedSpans","startPoint","backward","focus","anchor","endPoint","startBlockKey","isKeySegment","path","_key","undefined","endBlockKey","startSpanKey","endSpanKey","value","child","children","isPortableTextSpan","offset","text","length","push","node","getFocusBlock","key","find","getFocusListBlock","guards","focusBlock","getFocusTextBlock","getFocusBlockObject","getFocusChild","span","getFocusSpan","focusChild","getFirstBlock","getLastBlock","getSelectedBlocks","selectedBlocks","startKey","endKey","getSelectionStartBlock","getSelectionEndBlock","getPreviousBlock","previousBlock","selectionStartBlock","foundSelectionStartBlock","getNextBlock","nextBlock","selectionEndBlock","foundSelectionEndBlock","getActiveListItem","selectedTextBlocks","map","filter","firstTextBlock","at","firstListItem","listItem","every","getActiveStyle","firstStyle","style","getSelectionEndPoint","getSelectionStartPoint","getNextInlineObject","focusTextBlock","selectionEndPoint","selectionEndPointChildKey","endPointChildFound","inlineObject","isSpan","getPreviousInlineObject","selectionStartPoint","selectionStartPointChildKey","getSelectionText","forwardSelection","reverseSelection","isKeyedSegment","slice","isSelectionCollapsed","JSON","stringify","isSelectionExpanded","getCaretWordSelection","selectionStartOffset","spanSelectionPointToBlockOffset","selectionPoint","previousInlineObject","blockStartPoint","getBlockStartPoint","textDirectlyBefore","split","nextInlineObject","blockEndPoint","getBlockEndPoint","textDirectlyAfter","caretWordStartOffset","caretWordEndOffset","caretWordStartSelectionPoint","blockOffsetToSpanSelectionPoint","blockOffset","caretWordEndSelectionPoint","caretWordSelection","isActiveAnnotation","annotation","snapshot","focusSpan","some","marks","selectionMarkDefs","flatMap","markDefs","mark","markDef","includes","isActiveDecorator","decorator","activeDecorators","isActiveListItem","isActiveStyle","isAtTheEndOfBlock","utils","isEqualSelectionPoints","isAtTheStartOfBlock"],"mappings":";;AAaO,SAASA,aAAa;AAAA,EAACC;AAA8B,GAAG;AAC7D,WAASC,YAAYC,OAAgD;AACnE,WAAOC,MAAAA,wBAAwBD,KAAK,KAAKA,MAAME,UAAUJ,OAAOE,MAAMG;AAAAA,EAAAA;AAGxE,WAASC,YAAYJ,OAAgD;AACnE,WAAOK,MAAAA,wBAAwBL,KAAK,KAAKA,MAAME,UAAUJ,OAAOE,MAAMG;AAAAA,EAAAA;AAGjE,SAAA;AAAA,IAACJ;AAAAA,IAAaK;AAAAA,EAAW;AAClC;ACXO,MAAME,mBAKTA,CAAC;AAAA,EAACC;AAAO,MAAM;AACjB,MAAI,CAACA,QAAQC;AACX,WAAO,CAAE;AAGLC,QAAAA,gBAGD,IAECC,aAAaH,QAAQC,UAAUG,WACjCJ,QAAQC,UAAUI,QAClBL,QAAQC,UAAUK,QAChBC,WAAWP,QAAQC,UAAUG,WAC/BJ,QAAQC,UAAUK,SAClBN,QAAQC,UAAUI,OA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AEvBhD;AAE9B;ACNO,SAAS8D,cAAc1D,OAAwC;AAC5D4C,SAAAA,CAAAA,aACc9C,eAAe8C,QAAQ,MAEpB5C;AAE3B;ACJO,SAAS2D,kBAAkBlI,OAGN;AAC1B,SAAO,CAAC;AAAA,IAACO;AAAAA,EAAAA,MAAa;AACpB,QAAI,CAACA,QAAQC,aAAa,CAACiF,qBAAqB;AAAA,MAAClF;AAAAA,IAAAA,CAAQ;AAChD,aAAA;AAGHgG,UAAAA,gBAAgB4B,sBAAM3B,iBAAiBxG,KAAK;AAElD,WAAOmI,sBAAMC,uBAAuB7H,QAAQC,UAAUI,OAAO2F,aAAa;AAAA,EAC5E;AACF;ACbO,SAAS8B,oBAAoBrI,OAGR;AAC1B,SAAO,CAAC;AAAA,IAACO;AAAAA,EAAAA,MAAa;AACpB,QAAI,CAACA,QAAQC,aAAa,CAACiF,qBAAqB;AAAA,MAAClF;AAAAA,IAAAA,CAAQ;AAChD,aAAA;AAGH2F,UAAAA,kBAAkBiC,sBAAMhC,mBAAmBnG,KAAK;AAEtD,WAAOmI,sBAAMC,uBACX7H,QAAQC,UAAUI,OAClBsF,eACF;AAAA,EACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"selector.is-at-the-start-of-block.cjs","sources":["../../src/behavior-actions/behavior.guards.ts","../../src/selectors/selectors.ts","../../src/selectors/selector.get-selection-end-point.ts","../../src/selectors/selector.get-selection-start-point.ts","../../src/selectors/selector.get-next-inline-object.ts","../../src/selectors/selector.get-previous-inline-object.ts","../../src/selectors/selector.get-selected-slice.ts","../../src/selectors/selector.get-selection-text.ts","../../src/selectors/selector.is-selection-collapsed.ts","../../src/selectors/selector.is-selection-expanded.ts","../../src/selectors/selector.get-caret-word-selection.ts","../../src/selectors/selector.is-at-the-end-of-block.ts","../../src/selectors/selector.is-at-the-start-of-block.ts"],"sourcesContent":["import {\n isPortableTextListBlock,\n isPortableTextTextBlock,\n type PortableTextListBlock,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport type {EditorSchema} from '../editor/define-schema'\n\n/**\n * @alpha\n */\nexport type BehaviorGuards = ReturnType<typeof createGuards>\n\nexport function createGuards({schema}: {schema: EditorSchema}) {\n function isListBlock(block: unknown): block is PortableTextListBlock {\n return isPortableTextListBlock(block) && block._type === schema.block.name\n }\n\n function isTextBlock(block: unknown): block is PortableTextTextBlock {\n return isPortableTextTextBlock(block) && block._type === schema.block.name\n }\n\n return {isListBlock, isTextBlock}\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n type PortableTextListBlock,\n type PortableTextObject,\n type PortableTextSpan,\n type PortableTextTextBlock,\n} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusListBlock: EditorSelector<\n {node: PortableTextListBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const guards = createGuards(context)\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && guards.isListBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusBlockObject: EditorSelector<\n {node: PortableTextObject; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const focusBlock = getFocusBlock({context})\n\n return focusBlock && !isPortableTextTextBlock(focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n const focusBlock = getFocusTextBlock({context})\n\n if (!focusBlock) {\n return undefined\n }\n\n const key = context.selection\n ? isKeySegment(context.selection.focus.path[2])\n ? context.selection.focus.path[2]._key\n : undefined\n : undefined\n\n const node = key\n ? focusBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...focusBlock.path, 'children', {_key: key}]}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFocusSpan: EditorSelector<\n | {node: PortableTextSpan; path: [KeyedSegment, 'children', KeyedSegment]}\n | undefined\n> = ({context}) => {\n const focusChild = getFocusChild({context})\n\n return focusChild && isPortableTextSpan(focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n\n/**\n * @public\n */\nexport const getFirstBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const node = context.value[0]\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getLastBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n const node = context.value[context.value.length - 1]\n ? context.value[context.value.length - 1]\n : undefined\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getSelectedBlocks: EditorSelector<\n Array<{node: PortableTextBlock; path: [KeyedSegment]}>\n> = ({context}) => {\n if (!context.selection) {\n return []\n }\n\n const selectedBlocks: Array<{node: PortableTextBlock; path: [KeyedSegment]}> =\n []\n const startKey = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n const endKey = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n if (!startKey || !endKey) {\n return selectedBlocks\n }\n\n for (const block of context.value) {\n if (block._key === startKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n\n if (startKey === endKey) {\n break\n }\n continue\n }\n\n if (block._key === endKey) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n break\n }\n\n if (selectedBlocks.length > 0) {\n selectedBlocks.push({node: block, path: [{_key: block._key}]})\n }\n }\n\n return selectedBlocks\n}\n\n/**\n * @public\n */\nexport const getSelectionStartBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n : isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getSelectionEndBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: [KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n const key = context.selection.backward\n ? isKeySegment(context.selection.anchor.path[0])\n ? context.selection.anchor.path[0]._key\n : undefined\n : isKeySegment(context.selection.focus.path[0])\n ? context.selection.focus.path[0]._key\n : undefined\n\n const node = key\n ? context.value.find((block) => block._key === key)\n : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n\n/**\n * @public\n */\nexport const getPreviousBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n let previousBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionStartBlock = getSelectionStartBlock({context})\n\n if (!selectionStartBlock) {\n return undefined\n }\n\n let foundSelectionStartBlock = false\n\n for (const block of context.value) {\n if (block._key === selectionStartBlock.node._key) {\n foundSelectionStartBlock = true\n break\n }\n\n previousBlock = {node: block, path: [{_key: block._key}]}\n }\n\n if (foundSelectionStartBlock && previousBlock) {\n return previousBlock\n }\n\n return undefined\n}\n\n/**\n * @public\n */\nexport const getNextBlock: EditorSelector<\n {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n> = ({context}) => {\n let nextBlock: {node: PortableTextBlock; path: [KeyedSegment]} | undefined\n const selectionEndBlock = getSelectionEndBlock({context})\n\n if (!selectionEndBlock) {\n return undefined\n }\n\n let foundSelectionEndBlock = false\n\n for (const block of context.value) {\n if (block._key === selectionEndBlock.node._key) {\n foundSelectionEndBlock = true\n continue\n }\n\n if (foundSelectionEndBlock) {\n nextBlock = {node: block, path: [{_key: block._key}]}\n break\n }\n }\n\n if (foundSelectionEndBlock && nextBlock) {\n return nextBlock\n }\n\n return undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectionEndPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n return context.selection.backward\n ? context.selection.anchor\n : context.selection.focus\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectionStartPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = ({context}) => {\n if (!context.selection) {\n return undefined\n }\n\n return context.selection.backward\n ? context.selection.focus\n : context.selection.anchor\n}\n","import {\n isKeySegment,\n type KeyedSegment,\n type PortableTextObject,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isSpan} from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getFocusTextBlock} from './selectors'\n\n/**\n * @public\n */\nexport const getNextInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n const focusTextBlock = getFocusTextBlock({context})\n const selectionEndPoint = getSelectionEndPoint({context})\n const selectionEndPointChildKey =\n selectionEndPoint && isKeySegment(selectionEndPoint.path[2])\n ? selectionEndPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionEndPointChildKey) {\n return undefined\n }\n\n let endPointChildFound = false\n let inlineObject:\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionEndPointChildKey) {\n endPointChildFound = true\n continue\n }\n\n if (!isSpan(context, child) && endPointChildFound) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n break\n }\n }\n\n return inlineObject\n}\n","import {\n isKeySegment,\n type KeyedSegment,\n type PortableTextObject,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isSpan} from '../utils'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\nimport {getFocusTextBlock} from './selectors'\n\n/**\n * @public\n */\nexport const getPreviousInlineObject: EditorSelector<\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n> = ({context}) => {\n const focusTextBlock = getFocusTextBlock({context})\n const selectionStartPoint = getSelectionStartPoint({context})\n const selectionStartPointChildKey =\n selectionStartPoint && isKeySegment(selectionStartPoint.path[2])\n ? selectionStartPoint.path[2]._key\n : undefined\n\n if (!focusTextBlock || !selectionStartPointChildKey) {\n return undefined\n }\n\n let inlineObject:\n | {\n node: PortableTextObject\n path: [KeyedSegment, 'children', KeyedSegment]\n }\n | undefined\n\n for (const child of focusTextBlock.node.children) {\n if (child._key === selectionStartPointChildKey) {\n break\n }\n\n if (!isSpan(context, child)) {\n inlineObject = {\n node: child,\n path: [...focusTextBlock.path, 'children', {_key: child._key}],\n }\n }\n }\n\n return inlineObject\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {sliceBlocks} from '../utils'\n\n/**\n * @public\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = ({\n context,\n}) => {\n return sliceBlocks({blocks: context.value, selection: context.selection})\n}\n","import {isPortableTextSpan, isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSlice} from './selector.get-selected-slice'\n\n/**\n * @public\n */\nexport const getSelectionText: EditorSelector<string> = ({context}) => {\n const selectedSlice = getSelectedSlice({context})\n\n return selectedSlice.reduce((text, block) => {\n if (!isPortableTextTextBlock(block)) {\n return text\n }\n\n return (\n text +\n block.children.reduce((text, child) => {\n if (isPortableTextSpan(child)) {\n return text + child.text\n }\n\n return text\n }, '')\n )\n }, '')\n}\n","import type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const isSelectionCollapsed: EditorSelector<boolean> = ({context}) => {\n if (!context.selection) {\n return false\n }\n\n return (\n JSON.stringify(context.selection.anchor.path) ===\n JSON.stringify(context.selection.focus.path) &&\n context.selection?.anchor.offset === context.selection?.focus.offset\n )\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport const isSelectionExpanded: EditorSelector<boolean> = ({context}) => {\n return !isSelectionCollapsed({context})\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelection} from '../types/editor'\nimport {\n blockOffsetToSpanSelectionPoint,\n getBlockEndPoint,\n getBlockStartPoint,\n spanSelectionPointToBlockOffset,\n type BlockOffset,\n} from '../utils'\nimport {getNextInlineObject} from './selector.get-next-inline-object'\nimport {getPreviousInlineObject} from './selector.get-previous-inline-object'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\nimport {getSelectionText} from './selector.get-selection-text'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\nimport {getFocusTextBlock} from './selectors'\n\n/**\n * @public\n * Returns the selection of the of the word the caret is placed in.\n * Note: Only returns a word selection if the current selection is collapsed\n */\nexport const getCaretWordSelection: EditorSelector<EditorSelection> = ({\n context,\n}) => {\n if (!context.selection) {\n return null\n }\n\n if (!isSelectionCollapsed({context})) {\n return null\n }\n\n const focusTextBlock = getFocusTextBlock({context})\n const selectionStartPoint = getSelectionStartPoint({context})\n const selectionStartOffset = selectionStartPoint\n ? spanSelectionPointToBlockOffset({\n value: context.value,\n selectionPoint: selectionStartPoint,\n })\n : undefined\n\n if (!focusTextBlock || !selectionStartPoint || !selectionStartOffset) {\n return null\n }\n\n const previousInlineObject = getPreviousInlineObject({context})\n const blockStartPoint = getBlockStartPoint(focusTextBlock)\n const textBefore = getSelectionText({\n context: {\n ...context,\n selection: {\n anchor: previousInlineObject\n ? {path: previousInlineObject.path, offset: 0}\n : blockStartPoint,\n focus: selectionStartPoint,\n },\n },\n })\n const textDirectlyBefore = textBefore.split(/\\s+/).at(-1)\n\n const nextInlineObject = getNextInlineObject({context})\n const blockEndPoint = getBlockEndPoint(focusTextBlock)\n const textAfter = getSelectionText({\n context: {\n ...context,\n selection: {\n anchor: selectionStartPoint,\n focus: nextInlineObject\n ? {path: nextInlineObject.path, offset: 0}\n : blockEndPoint,\n },\n },\n })\n const textDirectlyAfter = textAfter.split(/\\s+/).at(0)\n\n if (\n (textDirectlyBefore === undefined || textDirectlyBefore === '') &&\n (textDirectlyAfter === undefined || textDirectlyAfter === '')\n ) {\n return null\n }\n\n const caretWordStartOffset: BlockOffset = textDirectlyBefore\n ? {\n ...selectionStartOffset,\n offset: selectionStartOffset.offset - textDirectlyBefore.length,\n }\n : selectionStartOffset\n const caretWordEndOffset: BlockOffset = textDirectlyAfter\n ? {\n ...selectionStartOffset,\n offset: selectionStartOffset.offset + textDirectlyAfter.length,\n }\n : selectionStartOffset\n\n const caretWordStartSelectionPoint = blockOffsetToSpanSelectionPoint({\n value: context.value,\n blockOffset: caretWordStartOffset,\n direction: 'backward',\n })\n const caretWordEndSelectionPoint = blockOffsetToSpanSelectionPoint({\n value: context.value,\n blockOffset: caretWordEndOffset,\n direction: 'forward',\n })\n\n if (!caretWordStartSelectionPoint || !caretWordEndSelectionPoint) {\n return null\n }\n\n const caretWordSelection = {\n anchor: caretWordStartSelectionPoint,\n focus: caretWordEndSelectionPoint,\n }\n\n return isSelectionExpanded({\n context: {\n ...context,\n selection: caretWordSelection,\n },\n })\n ? caretWordSelection\n : null\n}\n","import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isAtTheEndOfBlock(block: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelector<boolean> {\n return ({context}) => {\n if (!context.selection || !isSelectionCollapsed({context})) {\n return false\n }\n\n const blockEndPoint = utils.getBlockEndPoint(block)\n\n return utils.isEqualSelectionPoints(context.selection.focus, blockEndPoint)\n }\n}\n","import type {KeyedSegment, PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isAtTheStartOfBlock(block: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelector<boolean> {\n return ({context}) => {\n if (!context.selection || !isSelectionCollapsed({context})) {\n return false\n }\n\n const blockStartPoint = utils.getBlockStartPoint(block)\n\n return utils.isEqualSelectionPoints(\n context.selection.focus,\n blockStartPoint,\n )\n }\n}\n"],"names":["createGuards","schema","isListBlock","block","isPortableTextListBlock","_type","name","isTextBlock","isPortableTextTextBlock","getFocusBlock","context","key","selection","isKeySegment","focus","path","_key","undefined","node","value","find","getFocusListBlock","guards","focusBlock","getFocusTextBlock","getFocusBlockObject","getFocusChild","children","span","getFocusSpan","focusChild","isPortableTextSpan","getFirstBlock","getLastBlock","length","getSelectedBlocks","selectedBlocks","startKey","backward","anchor","endKey","push","getSelectionStartBlock","getSelectionEndBlock","getPreviousBlock","previousBlock","selectionStartBlock","foundSelectionStartBlock","getNextBlock","nextBlock","selectionEndBlock","foundSelectionEndBlock","getSelectionEndPoint","getSelectionStartPoint","getNextInlineObject","focusTextBlock","selectionEndPoint","selectionEndPointChildKey","endPointChildFound","inlineObject","child","isSpan","getPreviousInlineObject","selectionStartPoint","selectionStartPointChildKey","getSelectedSlice","sliceBlocks","blocks","getSelectionText","reduce","text","isSelectionCollapsed","JSON","stringify","offset","isSelectionExpanded","getCaretWordSelection","selectionStartOffset","spanSelectionPointToBlockOffset","selectionPoint","previousInlineObject","blockStartPoint","getBlockStartPoint","textDirectlyBefore","split","at","nextInlineObject","blockEndPoint","getBlockEndPoint","textDirectlyAfter","caretWordStartOffset","caretWordEndOffset","caretWordStartSelectionPoint","blockOffsetToSpanSelectionPoint","blockOffset","direction","caretWordEndSelectionPoint","caretWordSelection","isAtTheEndOfBlock","utils","isEqualSelectionPoints","isAtTheStartOfBlock"],"mappings":";;AAaO,SAASA,aAAa;AAAA,EAACC;AAA8B,GAAG;AAC7D,WAASC,YAAYC,OAAgD;AACnE,WAAOC,MAAAA,wBAAwBD,KAAK,KAAKA,MAAME,UAAUJ,OAAOE,MAAMG;AAAAA,EAAAA;AAGxE,WAASC,YAAYJ,OAAgD;AACnE,WAAOK,MAAAA,wBAAwBL,KAAK,KAAKA,MAAME,UAAUJ,OAAOE,MAAMG;AAAAA,EAAAA;AAGjE,SAAA;AAAA,IAACJ;AAAAA,IAAaK;AAAAA,EAAW;AAClC;ACNO,MAAME,gBAETA,CAAC;AAAA,EAACC;AAAO,MAAM;AACjB,QAAMC,MAAMD,QAAQE,a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AQS;AAAAA,IACf2E,aAAaJ;AAAAA,IACbK,WAAW;AAAA,EAAA,CACZ,GACKC,6BAA6BH,iDAAgC;AAAA,IACjE1E,OAAOT,QAAQS;AAAAA,IACf2E,aAAaH;AAAAA,IACbI,WAAW;AAAA,EAAA,CACZ;AAEG,MAAA,CAACH,gCAAgC,CAACI;AAC7B,WAAA;AAGT,QAAMC,qBAAqB;AAAA,IACzB1D,QAAQqD;AAAAA,IACR9E,OAAOkF;AAAAA,EACT;AAEA,SAAOrB,oBAAoB;AAAA,IACzBjE,SAAS;AAAA,MACP,GAAGA;AAAAA,MACHE,WAAWqF;AAAAA,IAAAA;AAAAA,EACb,CACD,IACGA,qBACA;AACN;ACpHO,SAASC,kBAAkB/F,OAGN;AAC1B,SAAO,CAAC;AAAA,IAACO;AAAAA,EAAAA,MAAa;AACpB,QAAI,CAACA,QAAQE,aAAa,CAAC2D,qBAAqB;AAAA,MAAC7D;AAAAA,IAAAA,CAAQ;AAChD,aAAA;AAGH6E,UAAAA,gBAAgBY,iBAAMX,iBAAiBrF,KAAK;AAElD,WAAOgG,iBAAMC,uBAAuB1F,QAAQE,UAAUE,OAAOyE,aAAa;AAAA,EAC5E;AACF;ACbO,SAASc,oBAAoBlG,OAGR;AAC1B,SAAO,CAAC;AAAA,IAACO;AAAAA,EAAAA,MAAa;AACpB,QAAI,CAACA,QAAQE,aAAa,CAAC2D,qBAAqB;AAAA,MAAC7D;AAAAA,IAAAA,CAAQ;AAChD,aAAA;AAGHuE,UAAAA,kBAAkBkB,iBAAMjB,mBAAmB/E,KAAK;AAEtD,WAAOgG,iBAAMC,uBACX1F,QAAQE,UAAUE,OAClBmE,eACF;AAAA,EACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- var types = require("@sanity/types"), util_reverseSelection = require("./util.reverse-selection.cjs");
2
+ var types = require("@sanity/types"), util_sliceBlocks = require("./util.slice-blocks.cjs");
3
3
  function isTypedObject(object) {
4
4
  return isRecord(object) && typeof object._type == "string";
5
5
  }
@@ -80,12 +80,14 @@ function blockOffsetsToSelection({
80
80
  offsets,
81
81
  backward
82
82
  }) {
83
- const anchor = util_reverseSelection.blockOffsetToSpanSelectionPoint({
83
+ const anchor = util_sliceBlocks.blockOffsetToSpanSelectionPoint({
84
84
  value,
85
- blockOffset: offsets.anchor
86
- }), focus = util_reverseSelection.blockOffsetToSpanSelectionPoint({
85
+ blockOffset: offsets.anchor,
86
+ direction: backward ? "backward" : "forward"
87
+ }), focus = util_sliceBlocks.blockOffsetToSpanSelectionPoint({
87
88
  value,
88
- blockOffset: offsets.focus
89
+ blockOffset: offsets.focus,
90
+ direction: backward ? "forward" : "backward"
89
91
  });
90
92
  return !anchor || !focus ? null : {
91
93
  anchor,
@@ -1 +1 @@
1
- {"version":3,"file":"util.block-offsets-to-selection.cjs","sources":["../../src/internal-utils/asserters.ts","../../src/internal-utils/parse-blocks.ts","../../src/utils/util.block-offsets-to-selection.ts"],"sourcesContent":["import type {TypedObject} from '@sanity/types'\n\nexport function isTypedObject(object: unknown): object is TypedObject {\n return isRecord(object) && typeof object._type === 'string'\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && (typeof value === 'object' || typeof value === 'function')\n}\n","import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isTypedObject} from './asserters'\n\nexport function parseBlock({\n context,\n block,\n options,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n block: unknown\n options: {\n refreshKeys: boolean\n }\n}): PortableTextBlock | undefined {\n if (!isTypedObject(block)) {\n return undefined\n }\n\n if (\n block._type !== context.schema.block.name &&\n !context.schema.blockObjects.some(\n (blockObject) => blockObject.name === block._type,\n )\n ) {\n return undefined\n }\n\n if (block._type !== context.schema.block.name) {\n const _key = options.refreshKeys\n ? context.keyGenerator()\n : typeof block._key === 'string'\n ? block._key\n : context.keyGenerator()\n return {\n ...block,\n _key,\n }\n }\n\n if (!isPortableTextTextBlock(block)) {\n return {\n _type: context.schema.block.name,\n _key: options.refreshKeys\n ? context.keyGenerator()\n : typeof block._key === 'string'\n ? block._key\n : context.keyGenerator(),\n children: [\n {\n _key: context.keyGenerator(),\n _type: context.schema.span.name,\n text: '',\n marks: [],\n },\n ],\n markDefs: [],\n style: context.schema.styles[0].value,\n }\n }\n\n const markDefKeyMap = new Map<string, string>()\n const markDefs = (block.markDefs ?? []).flatMap((markDef) => {\n if (\n context.schema.annotations.some(\n (annotation) => annotation.name === markDef._type,\n )\n ) {\n const _key = options.refreshKeys ? context.keyGenerator() : markDef._key\n markDefKeyMap.set(markDef._key, _key)\n\n return [\n {\n ...markDef,\n _key,\n },\n ]\n }\n\n return []\n })\n\n const children = block.children.flatMap((child) => {\n if (!isTypedObject(child)) {\n return []\n }\n\n if (\n child._type !== context.schema.span.name &&\n !context.schema.inlineObjects.some(\n (inlineObject) => inlineObject.name === child._type,\n )\n ) {\n return []\n }\n\n if (!isPortableTextSpan(child)) {\n return [\n {\n ...child,\n _key: options.refreshKeys ? context.keyGenerator() : child._key,\n },\n ]\n }\n\n const marks = (child.marks ?? []).flatMap((mark) => {\n if (markDefKeyMap.has(mark)) {\n return [markDefKeyMap.get(mark)]\n }\n\n if (\n context.schema.decorators.some((decorator) => decorator.value === mark)\n ) {\n return [mark]\n }\n\n return []\n })\n\n return [\n {\n ...child,\n _key: options.refreshKeys ? context.keyGenerator() : child._key,\n marks,\n },\n ]\n })\n\n const parsedBlock = {\n ...block,\n _key: options.refreshKeys ? context.keyGenerator() : block._key,\n children:\n children.length > 0\n ? children\n : [\n {\n _key: context.keyGenerator(),\n _type: context.schema.span.name,\n text: '',\n marks: [],\n },\n ],\n markDefs,\n }\n\n if (!context.schema.styles.find((style) => style.value === block.style)) {\n const defaultStyle = context.schema.styles[0].value\n\n if (defaultStyle !== undefined) {\n parsedBlock.style = defaultStyle\n } else {\n delete parsedBlock.style\n }\n }\n\n if (!context.schema.lists.find((list) => list.value === block.listItem)) {\n delete parsedBlock.listItem\n delete parsedBlock.level\n }\n\n return parsedBlock\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {BlockOffset} from '../behaviors'\nimport type {EditorSelection} from '../selectors'\nimport {blockOffsetToSpanSelectionPoint} from './util.block-offset'\n\n/**\n * @public\n */\nexport function blockOffsetsToSelection({\n value,\n offsets,\n backward,\n}: {\n value: Array<PortableTextBlock>\n offsets: {anchor: BlockOffset; focus: BlockOffset}\n backward?: boolean\n}): EditorSelection {\n const anchor = blockOffsetToSpanSelectionPoint({\n value,\n blockOffset: offsets.anchor,\n })\n const focus = blockOffsetToSpanSelectionPoint({\n value,\n blockOffset: offsets.focus,\n })\n\n if (!anchor || !focus) {\n return null\n }\n\n return {\n anchor,\n focus,\n backward,\n }\n}\n"],"names":["isTypedObject","object","isRecord","_type","value","parseBlock","context","block","options","schema","name","blockObjects","some","blockObject","_key","refreshKeys","keyGenerator","isPortableTextTextBlock","children","span","text","marks","markDefs","style","styles","markDefKeyMap","Map","flatMap","markDef","annotations","annotation","set","child","inlineObjects","inlineObject","isPortableTextSpan","mark","has","get","decorators","decorator","parsedBlock","length","find","defaultStyle","undefined","lists","list","listItem","level","blockOffsetsToSelection","offsets","backward","anchor","blockOffsetToSpanSelectionPoint","blockOffset","focus"],"mappings":";;AAEO,SAASA,cAAcC,QAAwC;AACpE,SAAOC,SAASD,MAAM,KAAK,OAAOA,OAAOE,SAAU;AACrD;AAEA,SAASD,SAASE,OAAkD;AAClE,SAAO,CAAC,CAACA,UAAU,OAAOA,SAAU,YAAY,OAAOA,SAAU;AACnE;ACAO,SAASC,WAAW;AAAA,EACzBC;AAAAA,EACAC;AAAAA,EACAC;AAOF,GAAkC;AAKhC,MAJI,CAACR,cAAcO,KAAK,KAKtBA,MAAMJ,UAAUG,QAAQG,OAAOF,MAAMG,QACrC,CAACJ,QAAQG,OAAOE,aAAaC,KAC1BC,iBA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lB,QAAQqB,eAEpB,OAAOH,YAAYlB;AAAAA,EAAAA;AAIvB,SAAKjB,QAAQG,OAAOqC,MAAMH,KAAMI,UAASA,KAAK3C,UAAUG,MAAMyC,QAAQ,MACpE,OAAOP,YAAYO,UACnB,OAAOP,YAAYQ,QAGdR;AACT;AC7JO,SAASS,wBAAwB;AAAA,EACtC9C;AAAAA,EACA+C;AAAAA,EACAC;AAKF,GAAoB;AAClB,QAAMC,SAASC,sBAAAA,gCAAgC;AAAA,IAC7ClD;AAAAA,IACAmD,aAAaJ,QAAQE;AAAAA,EAAAA,CACtB,GACKG,QAAQF,sDAAgC;AAAA,IAC5ClD;AAAAA,IACAmD,aAAaJ,QAAQK;AAAAA,EAAAA,CACtB;AAED,SAAI,CAACH,UAAU,CAACG,QACP,OAGF;AAAA,IACLH;AAAAA,IACAG;AAAAA,IACAJ;AAAAA,EACF;AACF;;;"}
1
+ {"version":3,"file":"util.block-offsets-to-selection.cjs","sources":["../../src/internal-utils/asserters.ts","../../src/internal-utils/parse-blocks.ts","../../src/utils/util.block-offsets-to-selection.ts"],"sourcesContent":["import type {TypedObject} from '@sanity/types'\n\nexport function isTypedObject(object: unknown): object is TypedObject {\n return isRecord(object) && typeof object._type === 'string'\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && (typeof value === 'object' || typeof value === 'function')\n}\n","import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isTypedObject} from './asserters'\n\nexport function parseBlock({\n context,\n block,\n options,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n block: unknown\n options: {\n refreshKeys: boolean\n }\n}): PortableTextBlock | undefined {\n if (!isTypedObject(block)) {\n return undefined\n }\n\n if (\n block._type !== context.schema.block.name &&\n !context.schema.blockObjects.some(\n (blockObject) => blockObject.name === block._type,\n )\n ) {\n return undefined\n }\n\n if (block._type !== context.schema.block.name) {\n const _key = options.refreshKeys\n ? context.keyGenerator()\n : typeof block._key === 'string'\n ? block._key\n : context.keyGenerator()\n return {\n ...block,\n _key,\n }\n }\n\n if (!isPortableTextTextBlock(block)) {\n return {\n _type: context.schema.block.name,\n _key: options.refreshKeys\n ? context.keyGenerator()\n : typeof block._key === 'string'\n ? block._key\n : context.keyGenerator(),\n children: [\n {\n _key: context.keyGenerator(),\n _type: context.schema.span.name,\n text: '',\n marks: [],\n },\n ],\n markDefs: [],\n style: context.schema.styles[0].value,\n }\n }\n\n const markDefKeyMap = new Map<string, string>()\n const markDefs = (block.markDefs ?? []).flatMap((markDef) => {\n if (\n context.schema.annotations.some(\n (annotation) => annotation.name === markDef._type,\n )\n ) {\n const _key = options.refreshKeys ? context.keyGenerator() : markDef._key\n markDefKeyMap.set(markDef._key, _key)\n\n return [\n {\n ...markDef,\n _key,\n },\n ]\n }\n\n return []\n })\n\n const children = block.children.flatMap((child) => {\n if (!isTypedObject(child)) {\n return []\n }\n\n if (\n child._type !== context.schema.span.name &&\n !context.schema.inlineObjects.some(\n (inlineObject) => inlineObject.name === child._type,\n )\n ) {\n return []\n }\n\n if (!isPortableTextSpan(child)) {\n return [\n {\n ...child,\n _key: options.refreshKeys ? context.keyGenerator() : child._key,\n },\n ]\n }\n\n const marks = (child.marks ?? []).flatMap((mark) => {\n if (markDefKeyMap.has(mark)) {\n return [markDefKeyMap.get(mark)]\n }\n\n if (\n context.schema.decorators.some((decorator) => decorator.value === mark)\n ) {\n return [mark]\n }\n\n return []\n })\n\n return [\n {\n ...child,\n _key: options.refreshKeys ? context.keyGenerator() : child._key,\n marks,\n },\n ]\n })\n\n const parsedBlock = {\n ...block,\n _key: options.refreshKeys ? context.keyGenerator() : block._key,\n children:\n children.length > 0\n ? children\n : [\n {\n _key: context.keyGenerator(),\n _type: context.schema.span.name,\n text: '',\n marks: [],\n },\n ],\n markDefs,\n }\n\n if (!context.schema.styles.find((style) => style.value === block.style)) {\n const defaultStyle = context.schema.styles[0].value\n\n if (defaultStyle !== undefined) {\n parsedBlock.style = defaultStyle\n } else {\n delete parsedBlock.style\n }\n }\n\n if (!context.schema.lists.find((list) => list.value === block.listItem)) {\n delete parsedBlock.listItem\n delete parsedBlock.level\n }\n\n return parsedBlock\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {BlockOffset} from '../behaviors'\nimport type {EditorSelection} from '../selectors'\nimport {blockOffsetToSpanSelectionPoint} from './util.block-offset'\n\n/**\n * @public\n */\nexport function blockOffsetsToSelection({\n value,\n offsets,\n backward,\n}: {\n value: Array<PortableTextBlock>\n offsets: {anchor: BlockOffset; focus: BlockOffset}\n backward?: boolean\n}): EditorSelection {\n const anchor = blockOffsetToSpanSelectionPoint({\n value,\n blockOffset: offsets.anchor,\n direction: backward ? 'backward' : 'forward',\n })\n const focus = blockOffsetToSpanSelectionPoint({\n value,\n blockOffset: offsets.focus,\n direction: backward ? 'forward' : 'backward',\n })\n\n if (!anchor || !focus) {\n return null\n }\n\n return {\n anchor,\n focus,\n backward,\n }\n}\n"],"names":["isTypedObject","object","isRecord","_type","value","parseBlock","context","block","options","schema","name","blockObjects","some","blockObject","_key","refreshKeys","keyGenerator","isPortableTextTextBlock","children","span","text","marks","markDefs","style","styles","markDefKeyMap","Map","flatMap","markDef","annotations","annotation","set","child","inlineObjects","inlineObject","isPortableTextSpan","mark","has","get","decorators","decorator","parsedBlock","length","find","defaultStyle","undefined","lists","list","listItem","level","blockOffsetsToSelection","offsets","backward","anchor","blockOffsetToSpanSelectionPoint","blockOffset","direction","focus"],"mappings":";;AAEO,SAASA,cAAcC,QAAwC;AACpE,SAAOC,SAASD,MAAM,KAAK,OAAOA,OAAOE,SAAU;AACrD;AAEA,SAASD,SAASE,OAAkD;AAClE,SAAO,CAAC,CAACA,UAAU,OAAOA,SAAU,YAAY,OAAOA,SAAU;AACnE;ACAO,SAASC,WAAW;AAAA,EACzBC;AAAAA,EACAC;AAAAA,EACAC;AAOF,GAAkC;AAKhC,MAJI,CAACR,c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gB,KAAK,GAAG;AACvE,UAAMqB,eAAetC,QAAQG,OAAOe,OAAO,CAAC,EAAEpB;AAE1CwC,qBAAiBC,SACnBJ,YAAYlB,QAAQqB,eAEpB,OAAOH,YAAYlB;AAAAA,EAAAA;AAIvB,SAAKjB,QAAQG,OAAOqC,MAAMH,KAAMI,UAASA,KAAK3C,UAAUG,MAAMyC,QAAQ,MACpE,OAAOP,YAAYO,UACnB,OAAOP,YAAYQ,QAGdR;AACT;AC7JO,SAASS,wBAAwB;AAAA,EACtC9C;AAAAA,EACA+C;AAAAA,EACAC;AAKF,GAAoB;AAClB,QAAMC,SAASC,iBAAAA,gCAAgC;AAAA,IAC7ClD;AAAAA,IACAmD,aAAaJ,QAAQE;AAAAA,IACrBG,WAAWJ,WAAW,aAAa;AAAA,EAAA,CACpC,GACKK,QAAQH,iDAAgC;AAAA,IAC5ClD;AAAAA,IACAmD,aAAaJ,QAAQM;AAAAA,IACrBD,WAAWJ,WAAW,YAAY;AAAA,EAAA,CACnC;AAED,SAAI,CAACC,UAAU,CAACI,QACP,OAGF;AAAA,IACLJ;AAAAA,IACAI;AAAAA,IACAL;AAAAA,EACF;AACF;;;"}
@@ -1,111 +1,4 @@
1
1
  "use strict";
2
- var types = require("@sanity/types");
3
- function isKeyedSegment(segment) {
4
- return typeof segment == "object" && segment !== null && "_key" in segment;
5
- }
6
- function blockOffsetToSpanSelectionPoint({
7
- value,
8
- blockOffset
9
- }) {
10
- let offsetLeft = blockOffset.offset, selectionPoint;
11
- for (const block of value)
12
- if (block._key === blockOffset.path[0]._key && types.isPortableTextTextBlock(block)) {
13
- for (const child of block.children)
14
- if (types.isPortableTextSpan(child)) {
15
- if (offsetLeft === 0) {
16
- selectionPoint = {
17
- path: [...blockOffset.path, "children", {
18
- _key: child._key
19
- }],
20
- offset: 0
21
- };
22
- break;
23
- }
24
- if (offsetLeft <= child.text.length) {
25
- selectionPoint = {
26
- path: [...blockOffset.path, "children", {
27
- _key: child._key
28
- }],
29
- offset: offsetLeft
30
- };
31
- break;
32
- }
33
- offsetLeft -= child.text.length;
34
- }
35
- }
36
- return selectionPoint;
37
- }
38
- function spanSelectionPointToBlockOffset({
39
- value,
40
- selectionPoint
41
- }) {
42
- let offset = 0;
43
- const blockKey = isKeyedSegment(selectionPoint.path[0]) ? selectionPoint.path[0]._key : void 0, spanKey = isKeyedSegment(selectionPoint.path[2]) ? selectionPoint.path[2]._key : void 0;
44
- if (!(!blockKey || !spanKey)) {
45
- for (const block of value)
46
- if (block._key === blockKey && types.isPortableTextTextBlock(block)) {
47
- for (const child of block.children)
48
- if (types.isPortableTextSpan(child)) {
49
- if (child._key === spanKey)
50
- return {
51
- path: [{
52
- _key: block._key
53
- }],
54
- offset: offset + selectionPoint.offset
55
- };
56
- offset += child.text.length;
57
- }
58
- }
59
- }
60
- }
61
- function getBlockEndPoint({
62
- node,
63
- path
64
- }) {
65
- if (types.isPortableTextTextBlock(node)) {
66
- const lastChild = node.children[node.children.length - 1];
67
- if (lastChild)
68
- return {
69
- path: [...path, "children", {
70
- _key: lastChild._key
71
- }],
72
- offset: types.isPortableTextSpan(lastChild) ? lastChild.text.length : 0
73
- };
74
- }
75
- return {
76
- path,
77
- offset: 0
78
- };
79
- }
80
- function getBlockStartPoint({
81
- node,
82
- path
83
- }) {
84
- return types.isPortableTextTextBlock(node) ? {
85
- path: [...path, "children", {
86
- _key: node.children[0]._key
87
- }],
88
- offset: 0
89
- } : {
90
- path,
91
- offset: 0
92
- };
93
- }
94
- function getTextBlockText(block) {
95
- return block.children.map((child) => child.text ?? "").join("");
96
- }
97
- function isEmptyTextBlock(block) {
98
- if (!types.isPortableTextTextBlock(block))
99
- return !1;
100
- const onlyText = block.children.every(types.isPortableTextSpan), blockText = getTextBlockText(block);
101
- return onlyText && blockText === "";
102
- }
103
- function isEqualSelectionPoints(a, b) {
104
- return a.offset === b.offset && JSON.stringify(a.path) === JSON.stringify(b.path);
105
- }
106
- function isSpan(context, child) {
107
- return child._type === context.schema.span.name;
108
- }
109
2
  function reverseSelection(selection) {
110
3
  return selection.backward ? {
111
4
  anchor: selection.focus,
@@ -117,14 +10,5 @@ function reverseSelection(selection) {
117
10
  backward: !0
118
11
  };
119
12
  }
120
- exports.blockOffsetToSpanSelectionPoint = blockOffsetToSpanSelectionPoint;
121
- exports.getBlockEndPoint = getBlockEndPoint;
122
- exports.getBlockStartPoint = getBlockStartPoint;
123
- exports.getTextBlockText = getTextBlockText;
124
- exports.isEmptyTextBlock = isEmptyTextBlock;
125
- exports.isEqualSelectionPoints = isEqualSelectionPoints;
126
- exports.isKeyedSegment = isKeyedSegment;
127
- exports.isSpan = isSpan;
128
13
  exports.reverseSelection = reverseSelection;
129
- exports.spanSelectionPointToBlockOffset = spanSelectionPointToBlockOffset;
130
14
  //# sourceMappingURL=util.reverse-selection.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.reverse-selection.cjs","sources":["../../src/utils/util.is-keyed-segment.ts","../../src/utils/util.block-offset.ts","../../src/utils/util.get-block-end-point.ts","../../src/utils/util.get-block-start-point.ts","../../src/utils/util.get-text-block-text.ts","../../src/utils/util.is-empty-text-block.ts","../../src/utils/util.is-equal-selection-points.ts","../../src/utils/util.is-span.ts","../../src/utils/util.reverse-selection.ts"],"sourcesContent":["import type {KeyedSegment, PathSegment} from '@sanity/types'\n\n/**\n * @public\n */\nexport function isKeyedSegment(segment: PathSegment): segment is KeyedSegment {\n return typeof segment === 'object' && segment !== null && '_key' in segment\n}\n","import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {BlockOffset} from '../behaviors/behavior.types'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {isKeyedSegment} from './util.is-keyed-segment'\n\n/**\n * @public\n */\nexport function blockOffsetToSpanSelectionPoint({\n value,\n blockOffset,\n}: {\n value: Array<PortableTextBlock>\n blockOffset: BlockOffset\n}) {\n let offsetLeft = blockOffset.offset\n let selectionPoint:\n | {path: [KeyedSegment, 'children', KeyedSegment]; offset: number}\n | undefined\n\n for (const block of value) {\n if (block._key !== blockOffset.path[0]._key) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (offsetLeft === 0) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: 0,\n }\n break\n }\n\n if (offsetLeft <= child.text.length) {\n selectionPoint = {\n path: [...blockOffset.path, 'children', {_key: child._key}],\n offset: offsetLeft,\n }\n break\n }\n\n offsetLeft -= child.text.length\n }\n }\n\n return selectionPoint\n}\n\n/**\n * @public\n */\nexport function spanSelectionPointToBlockOffset({\n value,\n selectionPoint,\n}: {\n value: Array<PortableTextBlock>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n let offset = 0\n\n const blockKey = isKeyedSegment(selectionPoint.path[0])\n ? selectionPoint.path[0]._key\n : undefined\n const spanKey = isKeyedSegment(selectionPoint.path[2])\n ? selectionPoint.path[2]._key\n : undefined\n\n if (!blockKey || !spanKey) {\n return undefined\n }\n\n for (const block of value) {\n if (block._key !== blockKey) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (child._key === spanKey) {\n return {\n path: [{_key: block._key}],\n offset: offset + selectionPoint.offset,\n }\n }\n\n offset += child.text.length\n }\n }\n}\n","import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getBlockEndPoint({\n node,\n path,\n}: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelectionPoint {\n if (isPortableTextTextBlock(node)) {\n const lastChild = node.children[node.children.length - 1]\n\n if (lastChild) {\n return {\n path: [...path, 'children', {_key: lastChild._key}],\n offset: isPortableTextSpan(lastChild) ? lastChild.text.length : 0,\n }\n }\n }\n\n return {\n path,\n offset: 0,\n }\n}\n","import {\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getBlockStartPoint({\n node,\n path,\n}: {\n node: PortableTextBlock\n path: [KeyedSegment]\n}): EditorSelectionPoint {\n if (isPortableTextTextBlock(node)) {\n return {\n path: [...path, 'children', {_key: node.children[0]._key}],\n offset: 0,\n }\n }\n\n return {\n path,\n offset: 0,\n }\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\n\n/**\n * @public\n */\nexport function getTextBlockText(block: PortableTextTextBlock) {\n return block.children.map((child) => child.text ?? '').join('')\n}\n","import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type PortableTextBlock,\n} from '@sanity/types'\nimport {getTextBlockText} from './util.get-text-block-text'\n\n/**\n * @public\n */\nexport function isEmptyTextBlock(block: PortableTextBlock) {\n if (!isPortableTextTextBlock(block)) {\n return false\n }\n\n const onlyText = block.children.every(isPortableTextSpan)\n const blockText = getTextBlockText(block)\n\n return onlyText && blockText === ''\n}\n","import type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function isEqualSelectionPoints(\n a: EditorSelectionPoint,\n b: EditorSelectionPoint,\n) {\n return (\n a.offset === b.offset && JSON.stringify(a.path) === JSON.stringify(b.path)\n )\n}\n","import type {PortableTextChild, PortableTextSpan} from '@sanity/types'\nimport type {EditorContext} from '../selectors'\n\n/**\n * @public\n */\nexport function isSpan(\n context: Pick<EditorContext, 'schema'>,\n child: PortableTextChild,\n): child is PortableTextSpan {\n return child._type === context.schema.span.name\n}\n","import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function reverseSelection(\n selection: NonNullable<EditorSelection>,\n): NonNullable<EditorSelection> {\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n }\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n }\n}\n"],"names":["isKeyedSegment","segment","blockOffsetToSpanSelectionPoint","value","blockOffset","offsetLeft","offset","selectionPoint","block","_key","path","isPortableTextTextBlock","child","children","isPortableTextSpan","text","length","spanSelectionPointToBlockOffset","blockKey","undefined","spanKey","getBlockEndPoint","node","lastChild","getBlockStartPoint","getTextBlockText","map","join","isEmptyTextBlock","onlyText","every","blockText","isEqualSelectionPoints","a","b","JSON","stringify","isSpan","context","_type","schema","span","name","reverseSelection","selection","backward","anchor","focus"],"mappings":";;AAKO,SAASA,eAAeC,SAA+C;AAC5E,SAAO,OAAOA,WAAY,YAAYA,YAAY,QAAQ,UAAUA;AACtE;ACMO,SAASC,gCAAgC;AAAA,EAC9CC;AAAAA,EACAC;AAIF,GAAG;AACGC,MAAAA,aAAaD,YAAYE,QACzBC;AAIJ,aAAWC,SAASL;AACdK,QAAAA,MAAMC,SAASL,YAAYM,KAAK,CAAC,EAAED,QAIlCE,8BAAwBH,KAAK;AAIlC,iBAAWI,SAASJ,MAAMK;AACnBC,YAAAA,MAAAA,mBAAmBF,KAAK,GAI7B;AAAA,cAAIP,eAAe,GAAG;AACH,6BAAA;AAAA,cACfK,MAAM,CAAC,GAAGN,YAAYM,MAAM,YAAY;AAAA,gBAACD,MAAMG,MAAMH;AAAAA,cAAAA,CAAK;AAAA,cAC1DH,QAAQ;AAAA,YACV;AACA;AAAA,UAAA;AAGED,cAAAA,cAAcO,MAAMG,KAAKC,QAAQ;AAClB,6BAAA;AAAA,cACfN,MAAM,CAAC,GAAGN,YAAYM,MAAM,YAAY;AAAA,gBAACD,MAAMG,MAAMH;AAAAA,cAAAA,CAAK;AAAA,cAC1DH,QAAQD;AAAAA,YACV;AACA;AAAA,UAAA;AAGFA,wBAAcO,MAAMG,KAAKC;AAAAA,QAAAA;AAAAA;AAItBT,SAAAA;AACT;AAKO,SAASU,gCAAgC;AAAA,EAC9Cd;AAAAA,EACAI;AAIF,GAA4B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AKT,SAAS,CAAC,EAAEJ;AAAAA,IAAAA,CAAK;AAAA,IACzDH,QAAQ;AAAA,EAAA,IAIL;AAAA,IACLI;AAAAA,IACAJ,QAAQ;AAAA,EACV;AACF;ACvBO,SAASmB,iBAAiBjB,OAA8B;AACtDA,SAAAA,MAAMK,SAASa,IAAKd,CAAAA,UAAUA,MAAMG,QAAQ,EAAE,EAAEY,KAAK,EAAE;AAChE;ACGO,SAASC,iBAAiBpB,OAA0B;AACrD,MAAA,CAACG,8BAAwBH,KAAK;AACzB,WAAA;AAGHqB,QAAAA,WAAWrB,MAAMK,SAASiB,MAAMhB,MAAAA,kBAAkB,GAClDiB,YAAYN,iBAAiBjB,KAAK;AAExC,SAAOqB,YAAYE,cAAc;AACnC;ACdgBC,SAAAA,uBACdC,GACAC,GACA;AACA,SACED,EAAE3B,WAAW4B,EAAE5B,UAAU6B,KAAKC,UAAUH,EAAEvB,IAAI,MAAMyB,KAAKC,UAAUF,EAAExB,IAAI;AAE7E;ACNgB2B,SAAAA,OACdC,SACA1B,OAC2B;AAC3B,SAAOA,MAAM2B,UAAUD,QAAQE,OAAOC,KAAKC;AAC7C;ACNO,SAASC,iBACdC,WAC8B;AAC9B,SAAIA,UAAUC,WACL;AAAA,IACLC,QAAQF,UAAUG;AAAAA,IAClBA,OAAOH,UAAUE;AAAAA,IACjBD,UAAU;AAAA,EAAA,IAIP;AAAA,IACLC,QAAQF,UAAUG;AAAAA,IAClBA,OAAOH,UAAUE;AAAAA,IACjBD,UAAU;AAAA,EACZ;AACF;;;;;;;;;;;"}
1
+ {"version":3,"file":"util.reverse-selection.cjs","sources":["../../src/utils/util.reverse-selection.ts"],"sourcesContent":["import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function reverseSelection(\n selection: NonNullable<EditorSelection>,\n): NonNullable<EditorSelection> {\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n }\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n }\n}\n"],"names":["reverseSelection","selection","backward","anchor","focus"],"mappings":";AAKO,SAASA,iBACdC,WAC8B;AAC9B,SAAIA,UAAUC,WACL;AAAA,IACLC,QAAQF,UAAUG;AAAAA,IAClBA,OAAOH,UAAUE;AAAAA,IACjBD,UAAU;AAAA,EAAA,IAIP;AAAA,IACLC,QAAQF,UAAUG;AAAAA,IAClBA,OAAOH,UAAUE;AAAAA,IACjBD,UAAU;AAAA,EACZ;AACF;;"}
@@ -1,5 +1,130 @@
1
1
  "use strict";
2
2
  var types = require("@sanity/types");
3
+ function isKeyedSegment(segment) {
4
+ return typeof segment == "object" && segment !== null && "_key" in segment;
5
+ }
6
+ function blockOffsetToSpanSelectionPoint({
7
+ value,
8
+ blockOffset,
9
+ direction
10
+ }) {
11
+ let offsetLeft = blockOffset.offset, selectionPoint, skippedInlineObject = !1;
12
+ for (const block of value)
13
+ if (block._key === blockOffset.path[0]._key && types.isPortableTextTextBlock(block))
14
+ for (const child of block.children) {
15
+ if (direction === "forward") {
16
+ if (!types.isPortableTextSpan(child))
17
+ continue;
18
+ if (offsetLeft <= child.text.length) {
19
+ selectionPoint = {
20
+ path: [...blockOffset.path, "children", {
21
+ _key: child._key
22
+ }],
23
+ offset: offsetLeft
24
+ };
25
+ break;
26
+ }
27
+ offsetLeft -= child.text.length;
28
+ continue;
29
+ }
30
+ if (!types.isPortableTextSpan(child)) {
31
+ skippedInlineObject = !0;
32
+ continue;
33
+ }
34
+ if (offsetLeft === 0 && selectionPoint && !skippedInlineObject) {
35
+ skippedInlineObject && (selectionPoint = {
36
+ path: [...blockOffset.path, "children", {
37
+ _key: child._key
38
+ }],
39
+ offset: 0
40
+ });
41
+ break;
42
+ }
43
+ if (offsetLeft > child.text.length) {
44
+ offsetLeft -= child.text.length;
45
+ continue;
46
+ }
47
+ if (offsetLeft <= child.text.length && (selectionPoint = {
48
+ path: [...blockOffset.path, "children", {
49
+ _key: child._key
50
+ }],
51
+ offset: offsetLeft
52
+ }, offsetLeft -= child.text.length, offsetLeft !== 0))
53
+ break;
54
+ }
55
+ return selectionPoint;
56
+ }
57
+ function spanSelectionPointToBlockOffset({
58
+ value,
59
+ selectionPoint
60
+ }) {
61
+ let offset = 0;
62
+ const blockKey = isKeyedSegment(selectionPoint.path[0]) ? selectionPoint.path[0]._key : void 0, spanKey = isKeyedSegment(selectionPoint.path[2]) ? selectionPoint.path[2]._key : void 0;
63
+ if (!(!blockKey || !spanKey)) {
64
+ for (const block of value)
65
+ if (block._key === blockKey && types.isPortableTextTextBlock(block)) {
66
+ for (const child of block.children)
67
+ if (types.isPortableTextSpan(child)) {
68
+ if (child._key === spanKey)
69
+ return {
70
+ path: [{
71
+ _key: block._key
72
+ }],
73
+ offset: offset + selectionPoint.offset
74
+ };
75
+ offset += child.text.length;
76
+ }
77
+ }
78
+ }
79
+ }
80
+ function getBlockEndPoint({
81
+ node,
82
+ path
83
+ }) {
84
+ if (types.isPortableTextTextBlock(node)) {
85
+ const lastChild = node.children[node.children.length - 1];
86
+ if (lastChild)
87
+ return {
88
+ path: [...path, "children", {
89
+ _key: lastChild._key
90
+ }],
91
+ offset: types.isPortableTextSpan(lastChild) ? lastChild.text.length : 0
92
+ };
93
+ }
94
+ return {
95
+ path,
96
+ offset: 0
97
+ };
98
+ }
99
+ function getBlockStartPoint({
100
+ node,
101
+ path
102
+ }) {
103
+ return types.isPortableTextTextBlock(node) ? {
104
+ path: [...path, "children", {
105
+ _key: node.children[0]._key
106
+ }],
107
+ offset: 0
108
+ } : {
109
+ path,
110
+ offset: 0
111
+ };
112
+ }
113
+ function getTextBlockText(block) {
114
+ return block.children.map((child) => child.text ?? "").join("");
115
+ }
116
+ function isEmptyTextBlock(block) {
117
+ if (!types.isPortableTextTextBlock(block))
118
+ return !1;
119
+ const onlyText = block.children.every(types.isPortableTextSpan), blockText = getTextBlockText(block);
120
+ return onlyText && blockText === "";
121
+ }
122
+ function isEqualSelectionPoints(a, b) {
123
+ return a.offset === b.offset && JSON.stringify(a.path) === JSON.stringify(b.path);
124
+ }
125
+ function isSpan(context, child) {
126
+ return child._type === context.schema.span.name;
127
+ }
3
128
  function sliceBlocks({
4
129
  blocks,
5
130
  selection
@@ -44,7 +169,10 @@ function sliceBlocks({
44
169
  break;
45
170
  continue;
46
171
  }
47
- if (startBlock && types.isPortableTextTextBlock(startBlock) && (startBlock.children.push(child), block._key === endBlockKey && endChildKey && child._key === endChildKey))
172
+ if (startBlock && types.isPortableTextTextBlock(startBlock) && (endChildKey && child._key === endChildKey && types.isPortableTextSpan(child) ? startBlock.children.push({
173
+ ...child,
174
+ text: child.text.slice(0, endPoint.offset)
175
+ }) : startBlock.children.push(child), block._key === endBlockKey && endChildKey && child._key === endChildKey))
48
176
  break;
49
177
  }
50
178
  if (startBlockKey === endBlockKey)
@@ -85,5 +213,14 @@ function sliceBlocks({
85
213
  }
86
214
  return [...startBlock ? [startBlock] : [], ...middleBlocks, ...endBlock ? [endBlock] : []];
87
215
  }
216
+ exports.blockOffsetToSpanSelectionPoint = blockOffsetToSpanSelectionPoint;
217
+ exports.getBlockEndPoint = getBlockEndPoint;
218
+ exports.getBlockStartPoint = getBlockStartPoint;
219
+ exports.getTextBlockText = getTextBlockText;
220
+ exports.isEmptyTextBlock = isEmptyTextBlock;
221
+ exports.isEqualSelectionPoints = isEqualSelectionPoints;
222
+ exports.isKeyedSegment = isKeyedSegment;
223
+ exports.isSpan = isSpan;
88
224
  exports.sliceBlocks = sliceBlocks;
225
+ exports.spanSelectionPointToBlockOffset = spanSelectionPointToBlockOffset;
89
226
  //# sourceMappingURL=util.slice-blocks.cjs.map