@portabletext/editor 8.1.2 → 8.1.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.
- package/lib/{behavior.types.action-C0XDEQnB.d.ts → behavior.types.action-BDNqhLEt.d.ts} +53 -25
- package/lib/behavior.types.action-BDNqhLEt.d.ts.map +1 -0
- package/lib/behaviors/index.d.ts +1 -1
- package/lib/{get-container-D2pN5Npr.js → get-container-CXdmRdiX.js} +3 -3
- package/lib/{get-container-D2pN5Npr.js.map → get-container-CXdmRdiX.js.map} +1 -1
- package/lib/{get-parent-DgaKcy8-.js → get-parent-BLzi7eLr.js} +39 -14
- package/lib/get-parent-BLzi7eLr.js.map +1 -0
- package/lib/{get-path-sub-schema-Dd0QYZ0m.js → get-path-sub-schema-DsN1qF_l.js} +9 -5
- package/lib/get-path-sub-schema-DsN1qF_l.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +233 -217
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.ts +1 -1
- package/lib/{selector.is-selecting-entire-blocks-BFhnnkHf.js → selector.is-selecting-entire-blocks-BHVYIXbI.js} +8 -5
- package/lib/selector.is-selecting-entire-blocks-BHVYIXbI.js.map +1 -0
- package/lib/selectors/index.d.ts +1 -1
- package/lib/selectors/index.js +4 -4
- package/lib/traversal/index.d.ts +9 -6
- package/lib/traversal/index.d.ts.map +1 -1
- package/lib/traversal/index.js +3 -3
- package/lib/{util.is-equal-selections-BdK98okY.js → util.is-equal-selections-sCQib0IC.js} +2 -2
- package/lib/{util.is-equal-selections-BdK98okY.js.map → util.is-equal-selections-sCQib0IC.js.map} +1 -1
- package/lib/{util.slice-blocks-_ElaB53f.js → util.slice-blocks-B-iKFEG7.js} +43 -56
- package/lib/util.slice-blocks-B-iKFEG7.js.map +1 -0
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +4 -8
- package/lib/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/lib/behavior.types.action-C0XDEQnB.d.ts.map +0 -1
- package/lib/get-parent-DgaKcy8-.js.map +0 -1
- package/lib/get-path-sub-schema-Dd0QYZ0m.js.map +0 -1
- package/lib/selector.is-selecting-entire-blocks-BFhnnkHf.js.map +0 -1
- package/lib/util.slice-blocks-_ElaB53f.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selector.is-selecting-entire-blocks-BFhnnkHf.js","names":[],"sources":["../src/engine/range/ranges-overlap.ts","../src/traversal/get-inline.ts","../src/selectors/selector.get-focus-child.ts","../src/selectors/selector.get-focus-inline-object.ts","../src/selectors/selector.get-focus-span.ts","../src/selectors/selector.get-focus-block.ts","../src/selectors/selector.get-focus-text-block.ts","../src/schema/get-root-accepted-types.ts","../src/selectors/selector.get-selected-value.ts","../src/selectors/selector.get-fragment.ts","../src/selectors/selector.get-selection-end-block.ts","../src/selectors/selector.get-selection-start-block.ts","../src/selectors/selector.is-overlapping-selection.ts","../src/selectors/selector.is-selection-collapsed.ts","../src/selectors/selector.is-selection-expanded.ts","../src/utils/util.is-selection-expanded.ts","../src/selectors/selector.get-selection-end-point.ts","../src/selectors/selector.get-next-span.ts","../src/selectors/selector.get-selection-start-point.ts","../src/selectors/selector.get-previous-span.ts","../src/selectors/selector.get-selected-children.ts","../src/selectors/selector.get-selected-spans.ts","../src/selectors/selector.get-mark-state.ts","../src/selectors/selector.get-active-annotation-marks.ts","../src/selectors/selector.get-selected-text-blocks.ts","../src/selectors/selector.get-active-decorators.ts","../src/selectors/selector.is-active-annotation.ts","../src/selectors/selector.get-active-annotations.ts","../src/selectors/selector.get-active-list-item.ts","../src/selectors/selector.get-active-style.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.get-caret-word-selection.ts","../src/selectors/selector.get-focus-block-object.ts","../src/selectors/selector.get-focus-list-block.ts","../src/selectors/selector.get-last-block.ts","../src/selectors/selector.get-next-block.ts","../src/selectors/selector.get-previous-block.ts","../src/selectors/selector.get-selection-end-child.ts","../src/selectors/selector.get-selection-start-child.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","../src/selectors/selector.is-selecting-entire-blocks.ts"],"sourcesContent":["import type {Node} from '../interfaces/node'\nimport type {Range} from '../interfaces/range'\nimport {comparePoints} from '../point/compare-points'\nimport {rangeEdges} from './range-edges'\n\n/**\n * Returns true if the two ranges share at least one point.\n *\n * Two ranges overlap iff each one's start is at or before the other's end.\n * Adjacent ranges that touch at a single point are considered overlapping.\n */\nexport function rangesOverlap(\n rangeA: Range,\n rangeB: Range,\n root: {value: Array<Node>},\n): boolean {\n const [startA, endA] = rangeEdges(rangeA, root)\n const [startB, endB] = rangeEdges(rangeB, root)\n return (\n comparePoints(startA, endB, root) <= 0 &&\n comparePoints(startB, endA, root) <= 0\n )\n}\n","import type {PortableTextObject, PortableTextSpan} from '@portabletext/schema'\nimport type {Path} from '../engine/interfaces/path'\nimport {isSpanNode} from '../engine/node/is-span-node'\nimport {getNode} from './get-node'\nimport {isInline} from './is-inline'\nimport {isObject} from './is-object'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Get the node at the given path if it is inline (a span or inline object).\n *\n * A node is inline if its parent is a text block. Returns the node narrowed\n * to `PortableTextSpan | PortableTextObject`, or `undefined` if the node\n * doesn't exist or is not inline.\n */\nexport function getInline(\n snapshot: TraversalSnapshot,\n path: Path,\n): {node: PortableTextSpan | PortableTextObject; path: Path} | undefined {\n const entry = getNode(snapshot, path)\n\n if (!entry || !isInline(snapshot, entry.path)) {\n return undefined\n }\n\n if (\n !isSpanNode({schema: snapshot.context.schema}, entry.node) &&\n !isObject(snapshot, entry.node)\n ) {\n return undefined\n }\n\n return {node: entry.node, path: entry.path}\n}\n","import type {PortableTextObject, PortableTextSpan} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getInline} from '../traversal/get-inline'\nimport type {ChildPath} from '../types/paths'\n\n/**\n * Returns the child (span or inline object) containing the focus selection,\n * resolved at any depth.\n *\n * @public\n */\nexport const getFocusChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const selection = snapshot.context.selection\n\n if (!selection) {\n return undefined\n }\n\n return getInline(snapshot, selection.focus.path)\n}\n","import type {PortableTextObject} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isSpanNode} from '../engine/node/is-span-node'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * Returns the inline object containing the focus selection, resolved at any\n * depth.\n *\n * @public\n */\nexport const getFocusInlineObject: EditorSelector<\n {node: PortableTextObject; path: ChildPath} | undefined\n> = (snapshot) => {\n const focusChild = getFocusChild(snapshot)\n\n return focusChild && !isSpanNode(snapshot.context, focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n","import {isSpan, type PortableTextSpan} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * Returns the span containing the focus selection, resolved at any depth.\n *\n * @public\n */\nexport const getFocusSpan: EditorSelector<\n {node: PortableTextSpan; path: ChildPath} | undefined\n> = (snapshot) => {\n const focusChild = getFocusChild(snapshot)\n\n return focusChild && isSpan(snapshot.context, focusChild.node)\n ? {node: focusChild.node, path: focusChild.path}\n : undefined\n}\n","import type {PortableTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getEnclosingBlock} from '../traversal/get-enclosing-block'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * Returns the block containing the focus selection, resolved at any depth.\n *\n * When the focus is inside an editable container (e.g. a code block's line),\n * this returns the innermost block ancestor (the line), not the outer\n * container. When the focus is at root, behavior is unchanged.\n *\n * @public\n */\nexport const getFocusBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const selection = snapshot.context.selection\n\n if (!selection) {\n return undefined\n }\n\n return getEnclosingBlock(snapshot, selection.focus.path)\n}\n","import {isTextBlock, type PortableTextTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * Returns the text block containing the focus selection, resolved at any depth.\n *\n * When the focus is inside an editable container (e.g. a code block's line),\n * this returns the innermost text block ancestor (the line), not the outer\n * container. When the focus is at root, behavior is unchanged.\n *\n * @public\n */\nexport const getFocusTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const focusBlock = getFocusBlock(snapshot)\n\n return focusBlock && isTextBlock(snapshot.context, focusBlock.node)\n ? {node: focusBlock.node, path: focusBlock.path}\n : undefined\n}\n","import type {EditorSchema} from '../editor/editor-schema'\n\n/**\n * Set of types that are valid at the root of the editor's value: the\n * configured text-block type plus every registered block-object type.\n *\n * The editor accepts these at the top level of `value` and uses them\n * to validate input and as the implicit accept-list for any payload\n * that escapes registered containers.\n */\nexport function getRootAcceptedTypes(schema: EditorSchema): Set<string> {\n return new Set<string>([\n schema.block.name,\n ...schema.blockObjects.map((blockObject) => blockObject.name),\n ])\n}\n","import {\n isSpan,\n isTextBlock,\n type PortableTextBlock,\n type PortableTextChild,\n} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport type {Path} from '../engine/interfaces/path'\nimport type {RegisteredContainer} from '../schema/resolve-containers'\nimport {getNodeChildren} from '../traversal/get-children'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {sliceBlocks} from '../utils/util.slice-blocks'\n\ntype Edge = EditorSelectionPoint | 'array-start' | 'array-end'\n\ntype SliceContext = Pick<\n EditorContext,\n 'schema' | 'selection' | 'value' | 'containers'\n> & {keyGenerator?: () => string}\n\n/**\n * Returns the portion of the document's value covered by the selection,\n * resolved at any depth.\n *\n * Containers fully inside the selection are preserved verbatim. Containers\n * on the selection boundary are recursed into so only the selected portion\n * of their content is kept. Text blocks on the boundary are span-sliced.\n *\n * The result preserves the full ancestor envelope around the selection. For\n * the clipboard-shaped view that unwraps the envelope toward the selection's\n * lowest common ancestor, see {@link getFragment}.\n *\n * @public\n */\nexport const getSelectedValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n const selection = snapshot.context.selection\n\n if (!selection) {\n return []\n }\n\n const startPoint = getSelectionStartPoint(selection)\n const endPoint = getSelectionEndPoint(selection)\n\n if (!startPoint || !endPoint) {\n return []\n }\n\n return sliceArray({\n context: snapshot.context,\n blocks: snapshot.context.value,\n pathPrefix: [],\n fieldNameInPrefix: undefined,\n startEdge: startPoint,\n endEdge: endPoint,\n })\n}\n\nfunction sliceArray({\n context,\n blocks,\n pathPrefix,\n fieldNameInPrefix,\n startEdge,\n endEdge,\n parent,\n}: {\n context: SliceContext\n blocks: ReadonlyArray<PortableTextBlock>\n pathPrefix: Path\n fieldNameInPrefix: string | undefined\n startEdge: Edge\n endEdge: Edge\n parent?: RegisteredContainer\n}): Array<PortableTextBlock> {\n if (blocks.length === 0) {\n return []\n }\n\n const startIdx = resolveIndex(blocks, pathPrefix, startEdge)\n const endIdx = resolveIndex(blocks, pathPrefix, endEdge)\n\n if (startIdx === -1 || endIdx === -1) {\n return []\n }\n\n const [lo, hi, loEdge, hiEdge] =\n startIdx <= endIdx\n ? [startIdx, endIdx, startEdge, endEdge]\n : [endIdx, startIdx, endEdge, startEdge]\n\n const result: Array<PortableTextBlock> = []\n\n for (let i = lo; i <= hi; i++) {\n const block = blocks[i]!\n const blockPath: Path = [\n ...pathPrefix,\n ...(fieldNameInPrefix ? [fieldNameInPrefix] : []),\n {_key: block._key},\n ]\n\n const startPointForBlock: Edge = i === lo ? loEdge : 'array-start'\n const endPointForBlock: Edge = i === hi ? hiEdge : 'array-end'\n\n const startInside = edgeIsInside(startPointForBlock, blockPath)\n const endInside = edgeIsInside(endPointForBlock, blockPath)\n\n if (!startInside && !endInside) {\n result.push(block)\n continue\n }\n\n if (isTextBlock({schema: context.schema}, block)) {\n const sliced = sliceBoundaryTextBlock({\n context,\n block,\n blockPath,\n startEdge: startPointForBlock,\n endEdge: endPointForBlock,\n })\n if (sliced) {\n result.push(sliced)\n }\n continue\n }\n\n const childInfo = getNodeChildren(context, block, parent)\n\n if (!childInfo) {\n result.push(block)\n continue\n }\n\n const innerSliced = sliceArray({\n context,\n blocks: childInfo.children as Array<PortableTextBlock>,\n pathPrefix: blockPath,\n fieldNameInPrefix: childInfo.fieldName,\n startEdge: startPointForBlock,\n endEdge: endPointForBlock,\n parent: childInfo.parent,\n })\n\n const updatedBlock: PortableTextBlock = {...block}\n ;(updatedBlock as Record<string, unknown>)[childInfo.fieldName] =\n innerSliced\n\n result.push(updatedBlock)\n }\n\n return result\n}\n\nfunction resolveIndex(\n blocks: ReadonlyArray<PortableTextBlock>,\n pathPrefix: Path,\n edge: Edge,\n): number {\n if (edge === 'array-start') {\n return 0\n }\n if (edge === 'array-end') {\n return blocks.length - 1\n }\n return findBlockIndexForPoint(blocks, pathPrefix, edge)\n}\n\nfunction findBlockIndexForPoint(\n blocks: ReadonlyArray<PortableTextBlock>,\n pathPrefix: Path,\n point: EditorSelectionPoint,\n): number {\n let nodeSegmentIndex = pathPrefix.length\n\n if (\n nodeSegmentIndex < point.path.length &&\n typeof point.path[nodeSegmentIndex] === 'string'\n ) {\n nodeSegmentIndex++\n }\n\n const segment = point.path[nodeSegmentIndex]\n\n if (segment === undefined) {\n return -1\n }\n\n if (isKeyedSegment(segment)) {\n return blocks.findIndex((block) => block._key === segment._key)\n }\n\n if (typeof segment === 'number') {\n return segment >= 0 && segment < blocks.length ? segment : -1\n }\n\n return -1\n}\n\nfunction edgeIsInside(edge: Edge, blockPath: Path): boolean {\n if (edge === 'array-start' || edge === 'array-end') {\n return false\n }\n return edge.path.length > blockPath.length\n}\n\nfunction sliceBoundaryTextBlock({\n context,\n block,\n blockPath,\n startEdge,\n endEdge,\n}: {\n context: SliceContext\n block: PortableTextBlock\n blockPath: Path\n startEdge: Edge\n endEdge: Edge\n}): PortableTextBlock | undefined {\n if (!isTextBlock({schema: context.schema}, block)) {\n return block\n }\n\n const firstChild = block.children[0]\n const lastChild = block.children[block.children.length - 1]\n\n // Build block-relative selection points. `sliceBlocks` assumes paths start\n // at the block level (e.g. `[{block}, 'children', {child}]`), so we strip\n // any ancestor container prefix from the path.\n const blockRelativeStart = stripPrefix(startEdge, blockPath, block, {\n fallback: 'block-start',\n firstChild,\n })\n const blockRelativeEnd = stripPrefix(endEdge, blockPath, block, {\n fallback: 'block-end',\n lastChild,\n context,\n })\n\n const sliced = sliceBlocks({\n context: {\n ...context,\n selection: {anchor: blockRelativeStart, focus: blockRelativeEnd},\n },\n blocks: [block],\n })\n\n return sliced[0]\n}\n\nfunction stripPrefix(\n edge: Edge,\n blockPath: Path,\n block: PortableTextBlock,\n opts: {\n fallback: 'block-start' | 'block-end'\n firstChild?: PortableTextChild\n lastChild?: PortableTextChild\n context?: SliceContext\n },\n): EditorSelectionPoint {\n if (edge !== 'array-start' && edge !== 'array-end') {\n // Is the point inside this block? If yes, strip the prefix.\n if (edge.path.length > blockPath.length) {\n return {\n path: edge.path.slice(blockPath.length - 1),\n offset: edge.offset,\n }\n }\n }\n // Fall back to block start or end.\n if (opts.fallback === 'block-start') {\n return {\n path: [\n {_key: block._key},\n 'children',\n {_key: opts.firstChild?._key ?? ''},\n ],\n offset: 0,\n }\n }\n return {\n path: [{_key: block._key}, 'children', {_key: opts.lastChild?._key ?? ''}],\n offset:\n opts.lastChild &&\n opts.context &&\n isSpan({schema: opts.context.schema}, opts.lastChild)\n ? opts.lastChild.text.length\n : 0,\n }\n}\n","import type {PortableTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {Path} from '../engine/interfaces/path'\nimport {getRootAcceptedTypes} from '../schema/get-root-accepted-types'\nimport {resolveContainerAt} from '../schema/resolve-container-at'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * Returns the smallest top-level-valid fragment of the editor's value\n * that covers the current selection.\n *\n * Starts from {@link getSelectedValue}'s envelope and unwraps it toward\n * the selection's lowest common ancestor, stopping at the deepest level\n * whose siblings are all root-accepted types. Intermediate single-child\n * containers (a single row inside a table, a single cell inside a row)\n * are walked through to look for a deeper unwrap target; an intermediate\n * level with multiple siblings (the lowest common ancestor across two\n * cells in one row) ends the walk and the last root-valid wrapping is\n * returned.\n *\n * A selection whose endpoints terminate at the root level (collapsed at\n * a root-level node, or expanded across root siblings without descending\n * into them) is treated as the user pointing AT the named node(s) rather\n * than INTO them; the envelope is returned as-is and the unwrap walk is\n * skipped. This is how a chrome drag carries the container itself rather\n * than its unwrapped content.\n *\n * Backs every registered clipboard converter, `editor.getFragment()`\n * (which projects to blocks only), and the drag preview pipeline (which\n * uses the paths to find DOM nodes). Exposed for custom converters and\n * any consumer that needs the clipboard-shaped view of the current\n * selection without redundant ancestor envelopes.\n *\n * @public\n */\nexport const getFragment: EditorSelector<\n Array<{node: PortableTextBlock; path: BlockPath}>\n> = (snapshot) => {\n const envelope = getSelectedValue(snapshot)\n\n if (envelope.length === 0) {\n return []\n }\n\n const selection = snapshot.context.selection\n if (\n selection &&\n selection.anchor.path.length <= 1 &&\n selection.focus.path.length <= 1\n ) {\n return envelope.map((block) => ({\n node: block,\n path: [{_key: block._key}],\n }))\n }\n\n const {schema, containers, value} = snapshot.context\n const rootAcceptedTypes = getRootAcceptedTypes(schema)\n const textBlockName = schema.block.name\n\n // The outer envelope is rooted in `editor.value` so its top-level types\n // are root-accepted by construction.\n let lastRootValid: Array<PortableTextBlock> = envelope\n let lastRootValidPrefix: Path = []\n let current: Array<PortableTextBlock> = envelope\n const pathPrefix: Path = []\n\n while (current.length === 1) {\n const single = current[0]!\n const singlePath: Path = [...pathPrefix, {_key: single._key}]\n const container = resolveContainerAt(containers, value, singlePath)\n\n if (!container || !('field' in container)) {\n break\n }\n\n const children = (single as Record<string, unknown>)[container.field.name]\n if (!Array.isArray(children) || children.length === 0) {\n break\n }\n\n const childBlocks = children as Array<PortableTextBlock>\n pathPrefix.push({_key: single._key}, container.field.name)\n current = childBlocks\n\n const allRootAccepted = childBlocks.every(\n (block) =>\n block._type === textBlockName || rootAcceptedTypes.has(block._type),\n )\n\n if (allRootAccepted) {\n lastRootValid = childBlocks\n lastRootValidPrefix = [...pathPrefix]\n // Keep walking - a deeper level might also be root-valid (a single\n // block inside the cell that is itself a container, etc.).\n continue\n }\n\n // Children are intermediate types (e.g. `row`, `cell`). If there is\n // a single intermediate child, walk through it; otherwise the lowest\n // common ancestor is here and we stop with the last root-valid level.\n if (childBlocks.length !== 1) {\n break\n }\n }\n\n return lastRootValid.map((block) => ({\n node: block,\n path: [...lastRootValidPrefix, {_key: block._key}],\n }))\n}\n","import type {PortableTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * Returns the block containing the selection's end point, resolved at any\n * depth.\n *\n * @public\n */\nexport const getSelectionEndBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: BlockPath\n }\n | undefined\n> = (snapshot) => {\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n\n if (!endPoint) {\n return undefined\n }\n\n return getFocusBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: endPoint,\n focus: endPoint,\n },\n },\n })\n}\n","import type {PortableTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * Returns the block containing the selection's start point, resolved at any\n * depth.\n *\n * @public\n */\nexport const getSelectionStartBlock: EditorSelector<\n | {\n node: PortableTextBlock\n path: BlockPath\n }\n | undefined\n> = (snapshot) => {\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n\n if (!startPoint) {\n return undefined\n }\n\n return getFocusBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startPoint,\n focus: startPoint,\n },\n },\n })\n}\n","import {rangesOverlap} from '../engine/range/ranges-overlap'\nimport {hasNode} from '../traversal/has-node'\nimport type {EditorSelection} from '../types/editor'\nimport type {EditorSelector} from './../editor/editor-selector'\n\n/**\n * Returns true if the supplied selection shares at least one point with the\n * editor's current selection. Resolves at any container depth.\n *\n * Two selections that touch at a single endpoint share that point and are\n * considered overlapping.\n *\n * @public\n */\nexport function isOverlappingSelection(\n selection: EditorSelection,\n): EditorSelector<boolean> {\n return (snapshot) => {\n const editorSelection = snapshot.context.selection\n\n if (!selection || !editorSelection) {\n return false\n }\n\n if (\n !hasNode(snapshot, selection.anchor.path) ||\n !hasNode(snapshot, selection.focus.path) ||\n !hasNode(snapshot, editorSelection.anchor.path) ||\n !hasNode(snapshot, editorSelection.focus.path)\n ) {\n return false\n }\n\n return rangesOverlap(selection, editorSelection, {\n value: snapshot.context.value,\n })\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {isSelectionCollapsed as isSelectionCollapsedUtil} from '../utils/util.is-selection-collapsed'\n\n/**\n * @public\n */\nexport const isSelectionCollapsed: EditorSelector<boolean> = (snapshot) =>\n isSelectionCollapsedUtil(snapshot.context.selection)\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> = (snapshot) => {\n return snapshot.context.selection !== null && !isSelectionCollapsed(snapshot)\n}\n","import type {EditorSelection} from '../types/editor'\nimport {isSelectionCollapsed} from './util.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isSelectionExpanded(selection: EditorSelection) {\n if (!selection) {\n return false\n }\n\n return !isSelectionCollapsed(selection)\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport const getSelectionEndPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n return snapshot.context.selection.backward\n ? snapshot.context.selection.anchor\n : snapshot.context.selection.focus\n}\n","import {isSpan, type PortableTextSpan} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {Path} from '../engine/interfaces/path'\nimport {getSibling} from '../traversal/get-sibling'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\n\n/**\n * Returns the span after the selection end within the same text block,\n * resolved at any depth.\n *\n * @public\n */\nexport const getNextSpan: EditorSelector<\n {node: PortableTextSpan; path: Path} | undefined\n> = (snapshot) => {\n const point = getSelectionEndPoint(snapshot)\n\n if (!point) {\n return undefined\n }\n\n return getSibling(snapshot, point.path, {\n direction: 'next',\n match: (node): node is PortableTextSpan => isSpan(snapshot.context, node),\n })\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport const getSelectionStartPoint: EditorSelector<\n EditorSelectionPoint | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n return snapshot.context.selection.backward\n ? snapshot.context.selection.focus\n : snapshot.context.selection.anchor\n}\n","import {isSpan, type PortableTextSpan} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {Path} from '../engine/interfaces/path'\nimport {getSibling} from '../traversal/get-sibling'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * Returns the span before the selection start within the same text block,\n * resolved at any depth.\n *\n * @public\n */\nexport const getPreviousSpan: EditorSelector<\n {node: PortableTextSpan; path: Path} | undefined\n> = (snapshot) => {\n const point = getSelectionStartPoint(snapshot)\n\n if (!point) {\n return undefined\n }\n\n return getSibling(snapshot, point.path, {\n direction: 'previous',\n match: (node): node is PortableTextSpan => isSpan(snapshot.context, node),\n })\n}\n","import {isSpan, type PortableTextChild} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {Path} from '../engine/interfaces/path'\nimport {getNode} from '../traversal/get-node'\nimport {getNodes} from '../traversal/get-nodes'\nimport {isInline} from '../traversal/is-inline'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\n\ntype SelectedChild<TChild extends PortableTextChild = PortableTextChild> = {\n node: TChild\n path: Path\n}\n\ntype GetSelectedChildrenOptions<\n TChild extends PortableTextChild = PortableTextChild,\n> = {\n filter?: (child: PortableTextChild) => child is TChild\n}\n\n/**\n * Returns the inline children (spans and inline objects) touched by the\n * selection, resolved at any depth.\n *\n * @public\n */\nexport function getSelectedChildren<\n TChild extends PortableTextChild = PortableTextChild,\n>(\n options?: GetSelectedChildrenOptions<TChild>,\n): EditorSelector<Array<SelectedChild<TChild>>> {\n const filter = options?.filter\n\n return (snapshot) => {\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n\n if (!startPoint || !endPoint) {\n return []\n }\n\n const startChildKey = startPoint.path.findLast(isKeyedSegment)?._key\n const endChildKey = endPoint.path.findLast(isKeyedSegment)?._key\n\n const result: Array<SelectedChild<TChild>> = []\n\n // Fast path: when both endpoints reference the same inline child -\n // the common case for collapsed selections and intra-span selections\n // - resolve that child directly instead of walking the range.\n if (\n startChildKey &&\n startChildKey === endChildKey &&\n isInline(snapshot, startPoint.path)\n ) {\n const node = getNode(snapshot, startPoint.path)\n if (node) {\n const child = node.node as PortableTextChild\n let skip = false\n if (child._key === startChildKey && isSpan(snapshot.context, child)) {\n if (startPoint.offset >= child.text.length) {\n skip = true\n }\n if (endPoint.offset <= 0) {\n skip = true\n }\n }\n if (!skip && (!filter || filter(child))) {\n result.push({node: child as TChild, path: node.path})\n }\n }\n return result\n }\n\n for (const entry of getNodes(snapshot, {\n from: startPoint.path,\n to: endPoint.path,\n match: (_, path) => isInline(snapshot, path),\n })) {\n const child = entry.node as PortableTextChild\n\n // Skip the start child when the selection begins exactly at its end\n // and skip the end child when the selection ends exactly at its start.\n if (child._key === startChildKey && isSpan(snapshot.context, child)) {\n if (startPoint.offset >= child.text.length) {\n continue\n }\n }\n\n if (child._key === endChildKey && isSpan(snapshot.context, child)) {\n if (endPoint.offset <= 0) {\n continue\n }\n }\n\n if (filter && !filter(child)) {\n continue\n }\n\n result.push({node: child as TChild, path: entry.path})\n }\n\n return result\n }\n}\n","import {isSpan, type PortableTextSpan} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getSelectedChildren} from './selector.get-selected-children'\n\n/**\n * Returns the spans touched by the selection, resolved at any depth.\n *\n * @public\n */\nexport const getSelectedSpans: EditorSelector<\n Array<{\n node: PortableTextSpan\n path: ChildPath\n }>\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n return getSelectedChildren({\n filter: (child) => isSpan(snapshot.context, child),\n })(snapshot)\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getParent} from '../traversal/get-parent'\nimport {getPathSubSchema} from '../traversal/get-path-sub-schema'\nimport {getBlock} from '../traversal/is-block'\nimport {blockOffsetToSpanSelectionPoint} from '../utils/util.block-offset'\nimport {isSelectionExpanded} from '../utils/util.is-selection-expanded'\nimport {getFocusSpan} from './selector.get-focus-span'\nimport {getNextSpan} from './selector.get-next-span'\nimport {getPreviousSpan} from './selector.get-previous-span'\nimport {getSelectedSpans} from './selector.get-selected-spans'\n\n/**\n * @public\n */\nexport type MarkState =\n | {\n state: 'unchanged'\n marks: Array<string>\n }\n | {\n state: 'changed'\n marks: Array<string>\n previousMarks: Array<string>\n }\n\n/**\n * Given that text is inserted at the current position, what marks should\n * be applied?\n * @public\n */\nexport const getMarkState: EditorSelector<MarkState | undefined> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n let selection = snapshot.context.selection\n\n if (getBlock(snapshot, selection.anchor.path)) {\n const spanSelectionPoint = blockOffsetToSpanSelectionPoint({\n snapshot,\n blockOffset: {\n path: selection.anchor.path,\n offset: selection.anchor.offset,\n },\n direction: selection.backward ? 'backward' : 'forward',\n })\n\n selection = spanSelectionPoint\n ? {\n ...selection,\n anchor: spanSelectionPoint,\n }\n : selection\n }\n\n if (getBlock(snapshot, selection.focus.path)) {\n const spanSelectionPoint = blockOffsetToSpanSelectionPoint({\n snapshot,\n blockOffset: {\n path: selection.focus.path,\n offset: selection.focus.offset,\n },\n direction: selection.backward ? 'backward' : 'forward',\n })\n\n selection = spanSelectionPoint\n ? {\n ...selection,\n focus: spanSelectionPoint,\n }\n : selection\n }\n\n const focusSpan = getFocusSpan({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!focusSpan) {\n return undefined\n }\n\n if (isSelectionExpanded(selection)) {\n const selectedSpans = getSelectedSpans({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n // Per-span info: marks present, the decorator names declared by the\n // span's block sub-schema, and the annotation markDef keys declared on\n // the span's enclosing block. Used so that out-of-scope spans (where\n // the mark cannot apply) don't disqualify the mark across the\n // selection.\n const spanInfo = selectedSpans.map((span) => {\n const block = getParent(snapshot, span.path, {\n match: (node) => isTextBlock({schema: snapshot.context.schema}, node),\n })\n return {\n marks: span.node.marks ?? [],\n decoratorNames: getPathSubSchema(snapshot, span.path).decorators.map(\n (decorator) => decorator.name,\n ),\n markDefKeys: (block?.node.markDefs ?? []).map(\n (markDef) => markDef._key,\n ),\n }\n })\n\n // Candidate marks: union of all marks present on any selected span.\n const candidateMarks = new Set<string>()\n for (const {marks: spanMarks} of spanInfo) {\n for (const mark of spanMarks) {\n candidateMarks.add(mark)\n }\n }\n\n const marks: Array<string> = []\n for (const candidate of candidateMarks) {\n const isDecoratorSomewhere = spanInfo.some(({decoratorNames}) =>\n decoratorNames.includes(candidate),\n )\n let active = true\n for (const {marks: spanMarks, decoratorNames, markDefKeys} of spanInfo) {\n const inScope = isDecoratorSomewhere\n ? decoratorNames.includes(candidate)\n : markDefKeys.includes(candidate)\n if (!inScope) {\n continue\n }\n if (!spanMarks.includes(candidate)) {\n active = false\n break\n }\n }\n if (active) {\n marks.push(candidate)\n }\n }\n\n return {\n state: 'unchanged',\n marks,\n }\n }\n\n const focusSubSchema = getPathSubSchema(snapshot, focusSpan.path)\n const decorators = focusSubSchema.decorators.map(\n (decorator) => decorator.name,\n )\n const marks = focusSpan.node.marks ?? []\n const marksWithoutAnnotations = marks.filter((mark) =>\n decorators.includes(mark),\n )\n\n const spanHasAnnotations = marks.length > marksWithoutAnnotations.length\n\n const spanIsEmpty = focusSpan.node.text.length === 0\n\n const atTheBeginningOfSpan = snapshot.context.selection.anchor.offset === 0\n const atTheEndOfSpan =\n snapshot.context.selection.anchor.offset === focusSpan.node.text.length\n\n const previousSpan = getPreviousSpan({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n const nextSpan = getNextSpan({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n const nextSpanAnnotations =\n nextSpan?.node?.marks?.filter((mark) => !decorators.includes(mark)) ?? []\n const spanAnnotations = marks.filter((mark) => !decorators.includes(mark))\n\n const previousSpanHasAnnotations = previousSpan\n ? previousSpan.node.marks?.some((mark) => !decorators.includes(mark))\n : false\n const previousSpanHasSameAnnotations = previousSpan\n ? previousSpan.node.marks\n ?.filter((mark) => !decorators.includes(mark))\n .every((mark) => marks.includes(mark))\n : false\n const previousSpanHasSameAnnotation = previousSpan\n ? previousSpan.node.marks?.some(\n (mark) => !decorators.includes(mark) && marks.includes(mark),\n )\n : false\n\n const previousSpanHasSameMarks = previousSpan\n ? previousSpan.node.marks?.every((mark) => marks.includes(mark))\n : false\n const nextSpanSharesSomeAnnotations = spanAnnotations.some((mark) =>\n nextSpanAnnotations?.includes(mark),\n )\n\n if (spanHasAnnotations && !spanIsEmpty) {\n if (atTheBeginningOfSpan) {\n if (previousSpanHasSameMarks) {\n return {\n state: 'changed',\n previousMarks: marks,\n marks: previousSpan?.node.marks ?? [],\n }\n } else if (previousSpanHasSameAnnotations) {\n return {\n state: 'changed',\n previousMarks: marks,\n marks: previousSpan?.node.marks ?? [],\n }\n } else if (previousSpanHasSameAnnotation) {\n return {\n state: 'unchanged',\n marks: focusSpan.node.marks ?? [],\n }\n } else if (!previousSpan) {\n return {\n state: 'changed',\n previousMarks: marks,\n marks: [],\n }\n }\n }\n\n if (atTheEndOfSpan) {\n if (!nextSpan) {\n return {\n state: 'changed',\n previousMarks: marks,\n marks: [],\n }\n }\n\n if (nextSpanAnnotations.length > 0 && !nextSpanSharesSomeAnnotations) {\n return {\n state: 'changed',\n previousMarks: marks,\n marks: [],\n }\n }\n\n if (\n (nextSpanSharesSomeAnnotations &&\n nextSpanAnnotations.length < spanAnnotations.length) ||\n !nextSpanSharesSomeAnnotations\n ) {\n return {\n state: 'changed',\n previousMarks: marks,\n marks: nextSpan?.node.marks ?? [],\n }\n }\n }\n }\n\n if (atTheBeginningOfSpan && !spanIsEmpty && previousSpan) {\n if (previousSpanHasAnnotations) {\n return {\n state: 'changed',\n marks,\n previousMarks: previousSpan?.node.marks ?? [],\n }\n } else {\n return {\n state: 'changed',\n previousMarks: marks,\n marks: (previousSpan?.node.marks ?? []).filter((mark) =>\n decorators.includes(mark),\n ),\n }\n }\n }\n\n return {\n state: 'unchanged',\n marks,\n }\n}\n","import type {EditorSnapshot} from '../editor/editor-snapshot'\nimport {getMarkState} from './selector.get-mark-state'\n\nexport function getActiveAnnotationsMarks(snapshot: EditorSnapshot) {\n const schema = snapshot.context.schema\n const markState = getMarkState(snapshot)\n\n return (markState?.marks ?? []).filter(\n (mark) =>\n !schema.decorators.map((decorator) => decorator.name).includes(mark),\n )\n}\n","import {isTextBlock, type PortableTextTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {Path} from '../engine/interfaces/path'\nimport {getEnclosingBlock} from '../traversal/get-enclosing-block'\nimport {getNodes} from '../traversal/get-nodes'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\n\n/**\n * Returns the text blocks touched by the selection, resolved at any depth.\n *\n * Walks the tree between the selection endpoints and returns every text\n * block found, regardless of container nesting. For toolbar state and\n * anywhere that needs \"text blocks with text in the selection\".\n *\n * @public\n */\nexport const getSelectedTextBlocks: EditorSelector<\n Array<{node: PortableTextTextBlock; path: Path}>\n> = (snapshot) => {\n const selection = snapshot.context.selection\n\n if (!selection) {\n return []\n }\n\n const startPoint = getSelectionStartPoint(selection)\n const endPoint = getSelectionEndPoint(selection)\n\n if (!startPoint || !endPoint) {\n return []\n }\n\n // Fast path: when both endpoints sit inside the same text block - the\n // common case for toolbar state on a collapsed or single-block\n // selection - skip the range walk entirely. The range walk visits\n // every descendant in document order between the endpoints; that's\n // O(tree) work and gets very expensive in deeply nested containers.\n const startBlock = getEnclosingBlock(snapshot, startPoint.path)\n const endBlock = getEnclosingBlock(snapshot, endPoint.path)\n if (\n startBlock &&\n endBlock &&\n startBlock.node._key === endBlock.node._key &&\n isTextBlock(snapshot.context, startBlock.node)\n ) {\n return [{node: startBlock.node, path: startBlock.path}]\n }\n\n const result: Array<{node: PortableTextTextBlock; path: Path}> = []\n\n for (const entry of getNodes(snapshot, {\n from: startPoint.path,\n to: endPoint.path,\n match: (node) => isTextBlock(snapshot.context, node),\n })) {\n if (isTextBlock(snapshot.context, entry.node)) {\n result.push({node: entry.node, path: entry.path})\n }\n }\n\n return result\n}\n","import type {EditorSnapshot} from '../editor/editor-snapshot'\nimport {getPathSubSchema} from '../traversal/get-path-sub-schema'\nimport {getMarkState} from './selector.get-mark-state'\nimport {getSelectedTextBlocks} from './selector.get-selected-text-blocks'\n\nexport function getActiveDecorators(snapshot: EditorSnapshot) {\n const decoratorState = snapshot.decoratorState\n const markState = getMarkState(snapshot)\n\n // Union of decorator names across all selected blocks' sub-schemas. At\n // root this is the full schema; inside containers it's the union of\n // each block's sub-schema decorators (so cross-container selections\n // include decorators that any in-scope span allows).\n const selectedBlocks = getSelectedTextBlocks(snapshot)\n const decorators = new Set<string>()\n for (const block of selectedBlocks) {\n for (const decorator of getPathSubSchema(snapshot, block.path).decorators) {\n decorators.add(decorator.name)\n }\n }\n if (decorators.size === 0) {\n for (const decorator of snapshot.context.schema.decorators) {\n decorators.add(decorator.name)\n }\n }\n\n const markStateDecorators = (markState?.marks ?? []).filter((mark) =>\n decorators.has(mark),\n )\n\n let activeDecorators: Array<string> = markStateDecorators\n\n for (const decorator in decoratorState) {\n if (decoratorState[decorator] === false) {\n activeDecorators = activeDecorators.filter(\n (activeDecorator) => activeDecorator !== decorator,\n )\n } else if (decoratorState[decorator] === true) {\n if (!activeDecorators.includes(decorator)) {\n activeDecorators.push(decorator)\n }\n }\n }\n\n return activeDecorators\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveAnnotationsMarks} from './selector.get-active-annotation-marks'\nimport {getSelectedTextBlocks} from './selector.get-selected-text-blocks'\nimport {getSelectedValue} from './selector.get-selected-value'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\n\n/**\n * Check whether an annotation is active in the given `snapshot`.\n *\n * @public\n */\nexport function isActiveAnnotation(\n annotation: string,\n options?: {\n /**\n * Choose whether the annotation has to cover the entire selection\n * (`'full'`) or whether the selection covering at least one character\n * of the annotation suffices (`'partial'`). With a collapsed\n * selection the modes agree: the annotation is active when the caret\n * sits inside it, not at its edges.\n *\n * Defaults to `'full'`\n */\n mode?: 'partial' | 'full'\n },\n): EditorSelector<boolean> {\n return (snapshot) => {\n const mode = options?.mode ?? 'full'\n\n if (mode === 'partial' && isSelectionExpanded(snapshot)) {\n // An expanded selection \"partially selects\" the annotation when it\n // covers at least one character of annotated text.\n const selectedValue = getSelectedValue(snapshot)\n\n return selectedValue.some((block) => {\n if (!isTextBlock(snapshot.context, block)) {\n return false\n }\n\n const annotationKeys = new Set(\n (block.markDefs ?? [])\n .filter((markDef) => markDef._type === annotation)\n .map((markDef) => markDef._key),\n )\n\n if (annotationKeys.size === 0) {\n return false\n }\n\n return block.children.some(\n (child) =>\n isSpan(snapshot.context, child) &&\n // Spans the selection only touches at a zero-width boundary\n // survive the slice with empty text and intact `marks`,\n // keeping their definitions alive through the slice's\n // unused-definition pruning. A boundary touch selects nothing\n // of the annotation, so those spans don't count.\n child.text.length > 0 &&\n child.marks?.some((mark) => annotationKeys.has(mark)),\n )\n })\n }\n\n // `'partial'` with a collapsed selection falls through to here: a\n // caret covers no characters, so the `'partial'`/`'full'` distinction\n // is meaningless and both modes share the canonical caret answer this\n // computes (active inside an annotated span, not at its edges, where\n // typing doesn't extend the annotation either).\n const selectedBlocks = getSelectedTextBlocks(snapshot)\n const selectionMarkDefs = selectedBlocks.flatMap(\n (block) => block.node.markDefs ?? [],\n )\n const activeAnnotations = getActiveAnnotationsMarks(snapshot)\n const activeMarkDefs = selectionMarkDefs.filter(\n (markDef) =>\n markDef._type === annotation &&\n activeAnnotations.includes(markDef._key),\n )\n\n return activeMarkDefs.length > 0\n }\n}\n","import type {PortableTextObject} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getPathSubSchema} from '../traversal/get-path-sub-schema'\nimport {getMarkState} from './selector.get-mark-state'\nimport {getSelectedTextBlocks} from './selector.get-selected-text-blocks'\n\n/**\n * @public\n */\nexport const getActiveAnnotations: EditorSelector<Array<PortableTextObject>> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedBlocks = getSelectedTextBlocks(snapshot)\n const markState = getMarkState(snapshot)\n\n // Union of decorator names across selected blocks' sub-schemas. Marks\n // that aren't decorators in any in-scope sub-schema are annotations.\n const decoratorNames = new Set<string>()\n for (const block of selectedBlocks) {\n for (const decorator of getPathSubSchema(snapshot, block.path).decorators) {\n decoratorNames.add(decorator.name)\n }\n }\n if (decoratorNames.size === 0) {\n for (const decorator of snapshot.context.schema.decorators) {\n decoratorNames.add(decorator.name)\n }\n }\n\n const activeAnnotations = (markState?.marks ?? []).filter(\n (mark) => !decoratorNames.has(mark),\n )\n\n const selectionMarkDefs = selectedBlocks.flatMap(\n (block) => block.node.markDefs ?? [],\n )\n\n return selectionMarkDefs.filter((markDef) =>\n activeAnnotations.includes(markDef._key),\n )\n}\n","import type {PortableTextListBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getPathSubSchema} from '../traversal/get-path-sub-schema'\nimport {getSelectedTextBlocks} from './selector.get-selected-text-blocks'\n\n/**\n * @public\n */\nexport const getActiveListItem: EditorSelector<\n PortableTextListBlock['listItem'] | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectedTextBlocks = getSelectedTextBlocks(snapshot)\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstListItem = firstTextBlock.node.listItem\n\n if (!firstListItem) {\n return undefined\n }\n\n // Skip blocks whose sub-schema does not declare the list. A list item\n // is active when every in-scope block carries it.\n const inScopeBlocks = selectedTextBlocks.filter((block) =>\n getPathSubSchema(snapshot, block.path).lists.some(\n (l) => l.name === firstListItem,\n ),\n )\n\n if (inScopeBlocks.every((block) => block.node.listItem === firstListItem)) {\n return firstListItem\n }\n\n return undefined\n}\n","import type {PortableTextTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getPathSubSchema} from '../traversal/get-path-sub-schema'\nimport {getSelectedTextBlocks} from './selector.get-selected-text-blocks'\n\n/**\n * @public\n */\nexport const getActiveStyle: EditorSelector<PortableTextTextBlock['style']> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectedTextBlocks = getSelectedTextBlocks(snapshot)\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n // A block without a `style` reads as its sub-schema's default (the\n // first declared style), the same value normalization fills in when a\n // local edit touches the block.\n const firstStyle =\n firstTextBlock.node.style ??\n getPathSubSchema(snapshot, firstTextBlock.path).styles.at(0)?.name\n\n if (!firstStyle) {\n return undefined\n }\n\n // Skip blocks whose sub-schema does not declare the style. A style is\n // active when every in-scope block carries it.\n const inScopeBlocks = selectedTextBlocks.filter((block) =>\n getPathSubSchema(snapshot, block.path).styles.some(\n (s) => s.name === firstStyle,\n ),\n )\n\n if (\n inScopeBlocks.every(\n (block) =>\n (block.node.style ??\n getPathSubSchema(snapshot, block.path).styles.at(0)?.name) ===\n firstStyle,\n )\n ) {\n return firstStyle\n }\n\n return undefined\n}\n","import type {PortableTextObject} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSibling} from '../traversal/get-sibling'\nimport {isObject} from '../traversal/is-object'\nimport type {ChildPath} from '../types/paths'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\n\n/**\n * Returns the inline object after the selection end within the same text\n * block, resolved at any depth.\n *\n * @public\n */\nexport const getNextInlineObject: EditorSelector<\n {node: PortableTextObject; path: ChildPath} | undefined\n> = (snapshot) => {\n const point = getSelectionEndPoint(snapshot)\n\n if (!point) {\n return undefined\n }\n\n const sibling = getSibling(snapshot, point.path, {\n direction: 'next',\n match: (node): node is PortableTextObject => isObject(snapshot, node),\n })\n\n return sibling\n}\n","import type {PortableTextObject} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSibling} from '../traversal/get-sibling'\nimport {isObject} from '../traversal/is-object'\nimport type {ChildPath} from '../types/paths'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * Returns the inline object before the selection start within the same text\n * block, resolved at any depth.\n *\n * @public\n */\nexport const getPreviousInlineObject: EditorSelector<\n {node: PortableTextObject; path: ChildPath} | undefined\n> = (snapshot) => {\n const point = getSelectionStartPoint(snapshot)\n\n if (!point) {\n return undefined\n }\n\n const sibling = getSibling(snapshot, point.path, {\n direction: 'previous',\n match: (node): node is PortableTextObject => isObject(snapshot, node),\n })\n\n return sibling\n}\n","import {isSpan, isTextBlock, type PortableTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport type {Node} from '../engine/interfaces/node'\nimport type {RegisteredContainer} from '../schema/resolve-containers'\nimport {getNodeChildren} from '../traversal/get-children'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * @public\n */\nexport const getSelectionText: EditorSelector<string> = (snapshot) => {\n const selectedValue = getSelectedValue(snapshot)\n\n return collectText(snapshot.context, selectedValue)\n}\n\nfunction collectText(\n context: Pick<EditorContext, 'schema' | 'containers'>,\n blocks: ReadonlyArray<Node | PortableTextBlock>,\n parent?: RegisteredContainer,\n): string {\n let text = ''\n\n for (const block of blocks) {\n if (isTextBlock(context, block)) {\n for (const child of block.children) {\n if (isSpan(context, child)) {\n text += child.text\n }\n }\n continue\n }\n\n const childInfo = getNodeChildren(context, block, parent)\n\n if (!childInfo) {\n continue\n }\n\n text += collectText(context, childInfo.children, childInfo.parent)\n }\n\n return text\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelection} from '../types/editor'\nimport {\n blockOffsetToSpanSelectionPoint,\n spanSelectionPointToBlockOffset,\n} from '../utils/util.block-offset'\nimport {getBlockEndPoint} from '../utils/util.get-block-end-point'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\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'\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 snapshot,\n) => {\n if (!snapshot.context.selection) {\n return null\n }\n\n if (!isSelectionCollapsed(snapshot)) {\n return null\n }\n\n const focusTextBlock = getFocusTextBlock(snapshot)\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionStartOffset = selectionStartPoint\n ? spanSelectionPointToBlockOffset({\n snapshot,\n selectionPoint: selectionStartPoint,\n })\n : undefined\n\n if (!focusTextBlock || !selectionStartPoint || !selectionStartOffset) {\n return null\n }\n\n const previousInlineObject = getPreviousInlineObject(snapshot)\n const blockStartPoint = getBlockStartPoint({\n context: snapshot.context,\n block: focusTextBlock,\n })\n const textBefore = getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.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(snapshot)\n const blockEndPoint = getBlockEndPoint({\n context: snapshot.context,\n block: focusTextBlock,\n })\n const textAfter = getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.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 snapshot,\n blockOffset: caretWordStartOffset,\n direction: 'backward',\n })\n const caretWordEndSelectionPoint = blockOffsetToSpanSelectionPoint({\n snapshot,\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 ...snapshot,\n context: {\n ...snapshot.context,\n selection: caretWordSelection,\n },\n })\n ? caretWordSelection\n : null\n}\n","import type {PortableTextObject} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {isTextBlockNode} from '../engine/node/is-text-block-node'\nimport {isEditableContainer} from '../schema/is-editable-container'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * Returns the void block object containing the focus selection, resolved at\n * any depth.\n *\n * Excludes text blocks and editable containers (which have their own children\n * and are not \"void\"). When the focus is at root, behavior is unchanged.\n *\n * @public\n */\nexport const getFocusBlockObject: EditorSelector<\n {node: PortableTextObject; path: BlockPath} | undefined\n> = (snapshot) => {\n const focusBlock = getFocusBlock(snapshot)\n\n if (!focusBlock) {\n return undefined\n }\n\n if (isTextBlockNode(snapshot.context, focusBlock.node)) {\n return undefined\n }\n\n if (isEditableContainer(snapshot, focusBlock.node, focusBlock.path)) {\n return undefined\n }\n\n return {node: focusBlock.node, path: focusBlock.path}\n}\n","import type {PortableTextListBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {isListBlock} from '../utils/parse-blocks'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * Returns the list block containing the focus selection, resolved at any\n * depth.\n *\n * @public\n */\nexport const getFocusListBlock: EditorSelector<\n {node: PortableTextListBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const focusTextBlock = getFocusTextBlock(snapshot)\n\n return focusTextBlock && isListBlock(snapshot.context, focusTextBlock.node)\n ? {node: focusTextBlock.node, path: focusTextBlock.path}\n : undefined\n}\n","import type {PortableTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {parentPath} from '../engine/path/parent-path'\nimport {getChildren} from '../traversal/get-children'\nimport {getBlock} from '../traversal/is-block'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusBlock} from './selector.get-focus-block'\n\n/**\n * Returns the last block at the current container scope.\n *\n * When the focus is inside an editable container (e.g. a code block's line),\n * this returns the last block within that container (the last line). When\n * the focus is at root, or there is no selection, this returns the last\n * block in the document.\n *\n * @public\n */\nexport const getLastBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const focusBlock = getFocusBlock(snapshot)\n\n if (focusBlock) {\n const siblings = getChildren(snapshot, parentPath(focusBlock.path))\n const last = siblings.at(-1)\n\n if (last) {\n return getBlock(snapshot, last.path)\n }\n }\n\n const node = snapshot.context.value.at(-1)\n\n return node ? {node, path: [{_key: node._key}]} : undefined\n}\n","import type {PortableTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSibling} from '../traversal/get-sibling'\nimport {getBlock} from '../traversal/is-block'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionEndBlock} from './selector.get-selection-end-block'\n\n/**\n * Returns the block after the selection's end block within the same\n * container scope, if any.\n *\n * Siblings are resolved within the enclosing container (or the document root\n * if the selection is at root level). Never crosses container boundaries.\n *\n * @public\n */\nexport const getNextBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const selectionEndBlock = getSelectionEndBlock(snapshot)\n\n if (!selectionEndBlock) {\n return undefined\n }\n\n const next = getSibling(snapshot, selectionEndBlock.path, {direction: 'next'})\n\n if (!next) {\n return undefined\n }\n\n return getBlock(snapshot, next.path)\n}\n","import type {PortableTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSibling} from '../traversal/get-sibling'\nimport {getBlock} from '../traversal/is-block'\nimport type {BlockPath} from '../types/paths'\nimport {getSelectionStartBlock} from './selector.get-selection-start-block'\n\n/**\n * Returns the block before the selection's start block within the same\n * container scope, if any.\n *\n * Siblings are resolved within the enclosing container (or the document root\n * if the selection is at root level). Never crosses container boundaries.\n *\n * @public\n */\nexport const getPreviousBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const selectionStartBlock = getSelectionStartBlock(snapshot)\n\n if (!selectionStartBlock) {\n return undefined\n }\n\n const previous = getSibling(snapshot, selectionStartBlock.path, {\n direction: 'previous',\n })\n\n if (!previous) {\n return undefined\n }\n\n return getBlock(snapshot, previous.path)\n}\n","import type {PortableTextObject, PortableTextSpan} from '@portabletext/schema'\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 * Returns the child containing the selection's end point, resolved at any\n * depth.\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 '@portabletext/schema'\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 * Returns the child containing the selection's start point, resolved at any\n * depth.\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 {getPathSubSchema} from '../traversal/get-path-sub-schema'\nimport {getActiveDecorators} from './selector.get-active-decorators'\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 // Skip spans whose enclosing block sub-schema does not declare the\n // decorator. A mark is active when every in-scope span carries it.\n const inScopeSpans = selectedSpans.filter((span) =>\n getPathSubSchema(snapshot, span.path).decorators.some(\n (d) => d.name === decorator,\n ),\n )\n\n return (\n inScopeSpans.length > 0 &&\n inScopeSpans.every((span) => span.node.marks?.includes(decorator))\n )\n }\n\n const activeDecorators = getActiveDecorators(snapshot)\n\n return 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 {PortableTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getBlockEndPoint} from '../utils/util.get-block-end-point'\nimport {isEqualSelectionPoints} from '../utils/util.is-equal-selection-points'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isAtTheEndOfBlock(block: {\n node: PortableTextBlock\n path: BlockPath\n}): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection || !isSelectionCollapsed(snapshot)) {\n return false\n }\n\n const blockEndPoint = getBlockEndPoint({\n context: snapshot.context,\n block,\n })\n\n return isEqualSelectionPoints(\n snapshot.context.selection.focus,\n blockEndPoint,\n )\n }\n}\n","import type {PortableTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {isEqualSelectionPoints} from '../utils/util.is-equal-selection-points'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\n\n/**\n * @public\n */\nexport function isAtTheStartOfBlock(block: {\n node: PortableTextBlock\n path: BlockPath\n}): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection || !isSelectionCollapsed(snapshot)) {\n return false\n }\n\n const blockStartPoint = getBlockStartPoint({\n context: snapshot.context,\n block,\n })\n\n return isEqualSelectionPoints(\n snapshot.context.selection.focus,\n blockStartPoint,\n )\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockEndPoint} from '../utils/util.get-block-end-point'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {isEqualSelectionPoints} from '../utils/util.is-equal-selection-points'\nimport {getSelectionEndBlock} from './selector.get-selection-end-block'\nimport {getSelectionStartBlock} from './selector.get-selection-start-block'\n\n/**\n * @public\n */\nexport const isSelectingEntireBlocks: EditorSelector<boolean> = (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const startPoint = snapshot.context.selection.backward\n ? snapshot.context.selection.focus\n : snapshot.context.selection.anchor\n const endPoint = snapshot.context.selection.backward\n ? snapshot.context.selection.anchor\n : snapshot.context.selection.focus\n\n const startBlock = getSelectionStartBlock(snapshot)\n const endBlock = getSelectionEndBlock(snapshot)\n\n if (!startBlock || !endBlock) {\n return false\n }\n\n const startBlockStartPoint = getBlockStartPoint({\n context: snapshot.context,\n block: startBlock,\n })\n const endBlockEndPoint = getBlockEndPoint({\n context: snapshot.context,\n block: endBlock,\n })\n\n return (\n isEqualSelectionPoints(startBlockStartPoint, startPoint) &&\n isEqualSelectionPoints(endBlockEndPoint, endPoint)\n )\n}\n"],"mappings":";;;;;;;;;;AAWA,SAAgB,cACd,QACA,QACA,MACS;CACT,IAAM,CAAC,QAAQ,QAAQ,WAAW,QAAQ,IAAI,GACxC,CAAC,QAAQ,QAAQ,WAAW,QAAQ,IAAI;CAC9C,OACE,cAAc,QAAQ,MAAM,IAAI,KAAK,KACrC,cAAc,QAAQ,MAAM,IAAI,KAAK;AAEzC;;;;;;;;ACPA,SAAgB,UACd,UACA,MACuE;CACvE,IAAM,QAAQ,QAAQ,UAAU,IAAI;CAEhC,OAAC,SAAS,CAAC,SAAS,UAAU,MAAM,IAAI,MAK1C,GAAC,WAAW,EAAC,QAAQ,SAAS,QAAQ,OAAM,GAAG,MAAM,IAAI,KACzD,CAAC,SAAS,UAAU,MAAM,IAAI,IAKhC,OAAO;EAAC,MAAM,MAAM;EAAM,MAAM,MAAM;CAAI;AAC5C;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AC9C,SAAS,SAAS;EAClB,OAAO;CACT,CAAC,GACK,mBAAmB,iBAAiB;EACxC,SAAS,SAAS;EAClB,OAAO;CACT,CAAC;CAED,OACE,uBAAuB,sBAAsB,UAAU,KACvD,uBAAuB,kBAAkB,QAAQ;AAErD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.slice-blocks-_ElaB53f.js","names":[],"sources":["../src/utils/util.child-text-offset.ts","../src/utils/util.block-offset.ts","../src/utils/util.is-equal-path-segments.ts","../src/utils/util.is-equal-paths.ts","../src/utils/util.is-equal-selection-points.ts","../src/utils/util.selection-point.ts","../src/utils/util.get-block-end-point.ts","../src/utils/util.get-block-start-point.ts","../src/utils/util.is-selection-collapsed.ts","../src/utils/util.get-selection-end-point.ts","../src/utils/util.get-selection-start-point.ts","../src/utils/key-generator.ts","../src/utils/parse-blocks.ts","../src/utils/util.slice-blocks.ts"],"sourcesContent":["/**\n * Pure text-offset arithmetic over a node's children array, shared by\n * the snapshot-aware block-offset utils (`util.block-offset.ts`) and\n * the schema-free point transform (`engine/point/transform-point.ts`).\n * Span-ness is the caller's concern, expressed as an accessor that\n * returns the child's text when the child occupies text offsets and\n * `undefined` when it does not (inline objects, blocks).\n */\n\n/**\n * The text offset of `(childKey, offsetInChild)` within `children`:\n * the total text of the children before that child, plus the offset\n * into it. `undefined` when the child is missing or carries no text.\n */\nexport function textOffsetOfChild(\n children: ReadonlyArray<unknown>,\n getSpanText: (child: unknown) => string | undefined,\n childKey: string,\n offsetInChild: number,\n): number | undefined {\n let precedingTextLength = 0\n\n for (const child of children) {\n const text = getSpanText(child)\n if (keyOf(child) === childKey) {\n return text === undefined\n ? undefined\n : precedingTextLength + offsetInChild\n }\n if (text !== undefined) {\n precedingTextLength += text.length\n }\n }\n\n return undefined\n}\n\n/**\n * The child and child-local offset at `textOffset` within `children`.\n * Forward-boundary convention: an offset landing exactly on a span\n * boundary stays at the end of the earlier span. `undefined` when the\n * offset lies beyond the children's total text.\n */\nexport function childAtTextOffset(\n children: ReadonlyArray<unknown>,\n getSpanText: (child: unknown) => string | undefined,\n textOffset: number,\n): {key: string; offset: number} | undefined {\n let remainingOffset = textOffset\n\n for (const child of children) {\n const text = getSpanText(child)\n if (text === undefined) {\n continue\n }\n if (remainingOffset <= text.length) {\n const key = keyOf(child)\n return key === undefined ? undefined : {key, offset: remainingOffset}\n }\n remainingOffset -= text.length\n }\n\n return undefined\n}\n\nfunction keyOf(child: unknown): string | undefined {\n if (child !== null && typeof child === 'object' && '_key' in child) {\n const key = (child as {_key: unknown})._key\n return typeof key === 'string' ? key : undefined\n }\n return undefined\n}\n","import {isSpan, isTextBlock} from '@portabletext/schema'\nimport {getNode} from '../traversal/get-node'\nimport {getParent} from '../traversal/get-parent'\nimport type {TraversalSnapshot} from '../traversal/traversal-snapshot'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport type {ChildPath} from '../types/paths'\nimport {childAtTextOffset, textOffsetOfChild} from './util.child-text-offset'\nimport {isKeyedSegment} from './util.is-keyed-segment'\n\n/**\n * @public\n */\nexport function blockOffsetToSpanSelectionPoint({\n snapshot,\n blockOffset,\n direction,\n}: {\n snapshot: TraversalSnapshot\n blockOffset: BlockOffset\n direction: 'forward' | 'backward'\n}) {\n const blockEntry = getNode(snapshot, blockOffset.path)\n\n if (!blockEntry || !isTextBlock(snapshot.context, blockEntry.node)) {\n return undefined\n }\n\n const block = blockEntry.node\n const blockPath = blockEntry.path\n\n if (direction === 'forward') {\n const placed = childAtTextOffset(\n block.children,\n (child) =>\n isSpan(snapshot.context, child as (typeof block.children)[number])\n ? (child as {text: string}).text\n : undefined,\n blockOffset.offset,\n )\n return placed\n ? {\n path: [\n ...blockPath,\n 'children',\n {_key: placed.key},\n ] satisfies ChildPath,\n offset: placed.offset,\n }\n : undefined\n }\n\n let offsetLeft = blockOffset.offset\n let selectionPoint: {path: ChildPath; offset: number} | undefined\n let skippedInlineObject = false\n\n for (const child of block.children) {\n if (!isSpan(snapshot.context, child)) {\n skippedInlineObject = true\n continue\n }\n\n if (offsetLeft === 0 && selectionPoint && !skippedInlineObject) {\n // A boundary offset stays at the end of the previous span unless an\n // inline object was skipped, in which case falling through to the\n // `offsetLeft <= child.text.length` branch lands the point at the\n // start of this span instead.\n break\n }\n\n if (offsetLeft > child.text.length) {\n offsetLeft -= child.text.length\n continue\n }\n\n if (offsetLeft <= child.text.length) {\n selectionPoint = {\n path: [...blockPath, 'children', {_key: child._key}],\n offset: offsetLeft,\n }\n\n offsetLeft -= child.text.length\n\n if (offsetLeft !== 0) {\n break\n }\n }\n }\n\n return selectionPoint\n}\n\n/**\n * @public\n */\nexport function spanSelectionPointToBlockOffset({\n snapshot,\n selectionPoint,\n}: {\n snapshot: TraversalSnapshot\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n const spanSegment = selectionPoint.path.at(-1)\n\n if (!isKeyedSegment(spanSegment)) {\n return undefined\n }\n\n const textBlock = getParent(snapshot, selectionPoint.path, {\n match: (node) => isTextBlock({schema: snapshot.context.schema}, node),\n })\n\n if (!textBlock) {\n return undefined\n }\n\n const offset = textOffsetOfChild(\n textBlock.node.children,\n (child) =>\n isSpan(\n snapshot.context,\n child as (typeof textBlock.node.children)[number],\n )\n ? (child as {text: string}).text\n : undefined,\n spanSegment._key,\n selectionPoint.offset,\n )\n\n return offset === undefined ? undefined : {path: textBlock.path, offset}\n}\n","import type {PathSegment} from '../types/paths'\nimport {isKeyedSegment} from './util.is-keyed-segment'\n\nexport function isEqualPathSegments(\n segA: PathSegment | undefined,\n segB: PathSegment | undefined,\n): boolean {\n if (segA === segB) {\n return true\n }\n\n if (segA === undefined || segB === undefined) {\n return false\n }\n\n if (\n (typeof segA === 'string' || typeof segA === 'number') &&\n (typeof segB === 'string' || typeof segB === 'number')\n ) {\n return segA === segB\n }\n\n if (isKeyedSegment(segA) && isKeyedSegment(segB)) {\n return segA._key === segB._key\n }\n\n if (Array.isArray(segA) && Array.isArray(segB)) {\n return segA[0] === segB[0] && segA[1] === segB[1]\n }\n\n return false\n}\n","import type {Path} from '../types/paths'\nimport {isEqualPathSegments} from './util.is-equal-path-segments'\n\n/**\n * @public\n */\nexport function isEqualPaths(a: Path, b: Path): boolean {\n if (a.length !== b.length) {\n return false\n }\n\n for (let i = 0; i < a.length; i++) {\n if (!isEqualPathSegments(a[i], b[i])) {\n return false\n }\n }\n\n return true\n}\n","import type {EditorSelectionPoint} from '../types/editor'\nimport {isEqualPaths} from './util.is-equal-paths'\n\n/**\n * @public\n */\nexport function isEqualSelectionPoints(\n a: EditorSelectionPoint,\n b: EditorSelectionPoint,\n) {\n return a.offset === b.offset && isEqualPaths(a.path, b.path)\n}\n","import type {EditorSelectionPoint} from '../types/editor'\nimport {isKeyedSegment} from './util.is-keyed-segment'\n\nexport function getBlockKeyFromSelectionPoint(point: EditorSelectionPoint) {\n const blockPathSegment = point.path.at(0)\n\n if (isKeyedSegment(blockPathSegment)) {\n return blockPathSegment._key\n }\n\n return undefined\n}\n\nexport function getChildKeyFromSelectionPoint(point: EditorSelectionPoint) {\n const childPathSegment = point.path.at(2)\n\n if (isKeyedSegment(childPathSegment)) {\n return childPathSegment._key\n }\n\n return undefined\n}\n","import {isSpan, isTextBlock, type PortableTextBlock} from '@portabletext/schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport function getBlockEndPoint({\n context,\n block,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: {\n node: PortableTextBlock\n path: BlockPath\n }\n}): EditorSelectionPoint {\n if (isTextBlock(context, block.node)) {\n const lastChild = block.node.children[block.node.children.length - 1]\n\n if (lastChild) {\n return {\n path: [...block.path, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n }\n }\n }\n\n return {\n path: block.path,\n offset: 0,\n }\n}\n","import {isTextBlock, type PortableTextBlock} from '@portabletext/schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport function getBlockStartPoint({\n context,\n block,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: {\n node: PortableTextBlock\n path: BlockPath\n }\n}): EditorSelectionPoint {\n if (isTextBlock(context, block.node)) {\n const firstChild = block.node.children[0]\n return {\n path: [...block.path, 'children', {_key: firstChild?._key ?? ''}],\n offset: 0,\n }\n }\n\n return {\n path: block.path,\n offset: 0,\n }\n}\n","import type {EditorSelection} from '../types/editor'\nimport {isEqualPaths} from './util.is-equal-paths'\n\n/**\n * @public\n */\nexport function isSelectionCollapsed(selection: EditorSelection) {\n if (!selection) {\n return false\n }\n\n return (\n isEqualPaths(selection.anchor.path, selection.focus.path) &&\n selection.anchor.offset === selection.focus.offset\n )\n}\n","import type {EditorSelection, EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getSelectionEndPoint<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n TEditorSelectionPoint extends EditorSelectionPoint | null =\n TEditorSelection extends NonNullable<EditorSelection>\n ? EditorSelectionPoint\n : null,\n>(selection: TEditorSelection): TEditorSelectionPoint {\n if (!selection) {\n return null as TEditorSelectionPoint\n }\n\n return (\n selection.backward ? selection.anchor : selection.focus\n ) as TEditorSelectionPoint\n}\n","import type {EditorSelection, EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function getSelectionStartPoint<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n TEditorSelectionPoint extends EditorSelectionPoint | null =\n TEditorSelection extends NonNullable<EditorSelection>\n ? EditorSelectionPoint\n : null,\n>(selection: TEditorSelection): TEditorSelectionPoint {\n if (!selection) {\n return null as TEditorSelectionPoint\n }\n\n return (\n selection.backward ? selection.focus : selection.anchor\n ) as TEditorSelectionPoint\n}\n","/**\n * @public\n */\nexport const defaultKeyGenerator = (): string => randomKey(12)\n\nconst getByteHexTable = (() => {\n let table: any[]\n return () => {\n if (table) {\n return table\n }\n\n table = []\n for (let i = 0; i < 256; ++i) {\n table[i] = (i + 0x100).toString(16).slice(1)\n }\n return table\n }\n})()\n\n// WHATWG crypto RNG - https://w3c.github.io/webcrypto/Overview.html\nfunction whatwgRNG(length = 16) {\n const rnds8 = new Uint8Array(length)\n crypto.getRandomValues(rnds8)\n return rnds8\n}\n\nfunction randomKey(length?: number): string {\n const table = getByteHexTable()\n return whatwgRNG(length)\n .reduce((str, n) => str + table[n], '')\n .slice(0, length)\n}\n","import {\n getSubSchema,\n isSpan,\n isTextBlock,\n type FieldDefinition,\n type OfDefinition,\n type PortableTextBlock,\n type PortableTextListBlock,\n type PortableTextObject,\n type PortableTextSpan,\n type PortableTextTextBlock,\n type Schema,\n type TypedObject,\n} from '@portabletext/schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isRecord, isTypedObject} from './asserters'\n\nexport function parseBlocks({\n schema,\n keyGenerator,\n blocks,\n options,\n}: {\n schema: Schema\n keyGenerator: () => string\n blocks: unknown\n options: {\n normalize: boolean\n removeUnusedMarkDefs: boolean\n validateFields: boolean\n }\n}): Array<PortableTextBlock> {\n if (!Array.isArray(blocks)) {\n return []\n }\n\n return blocks.flatMap((block) => {\n const parsedBlock = parseBlockInternal({\n schema,\n keyGenerator,\n block,\n options,\n })\n\n return parsedBlock ? [parsedBlock] : []\n })\n}\n\nexport function parseBlock({\n schema,\n keyGenerator,\n block,\n options,\n}: {\n schema: Schema\n keyGenerator: () => string\n block: unknown\n options: {\n normalize: boolean\n removeUnusedMarkDefs: boolean\n validateFields: boolean\n }\n}): PortableTextBlock | undefined {\n return parseBlockInternal({schema, keyGenerator, block, options})\n}\n\nexport function parseSpan({\n span,\n schema,\n keyGenerator,\n markDefKeyMap,\n options,\n}: {\n span: unknown\n schema: Schema\n keyGenerator: () => string\n markDefKeyMap: Map<string, string>\n options: {validateFields: boolean}\n}): PortableTextSpan | undefined {\n return parseSpanInternal({span, schema, keyGenerator, markDefKeyMap, options})\n}\n\nexport function parseInlineObject({\n inlineObject,\n schema,\n keyGenerator,\n options,\n}: {\n inlineObject: unknown\n schema: Schema\n keyGenerator: () => string\n options: {validateFields: boolean}\n}): PortableTextObject | undefined {\n return parseInlineObjectInternal({\n inlineObject,\n schema,\n keyGenerator,\n options,\n })\n}\n\nexport function parseChild({\n child,\n schema,\n keyGenerator,\n markDefKeyMap,\n options,\n}: {\n child: unknown\n schema: Schema\n keyGenerator: () => string\n markDefKeyMap: Map<string, string>\n options: {validateFields: boolean}\n}): PortableTextSpan | PortableTextObject | undefined {\n return parseChildInternal({\n child,\n schema,\n keyGenerator,\n markDefKeyMap,\n options,\n })\n}\n\nexport function parseMarkDefs({\n schema,\n keyGenerator,\n markDefs,\n options,\n}: {\n schema: Schema\n keyGenerator: () => string\n markDefs: unknown\n options: {validateFields: boolean}\n}): {\n markDefs: Array<PortableTextObject>\n markDefKeyMap: Map<string, string>\n} {\n return parseMarkDefsInternal({schema, keyGenerator, markDefs, options})\n}\n\nfunction parseBlockInternal({\n schema,\n keyGenerator,\n block,\n options,\n}: {\n schema: Schema\n keyGenerator: () => string\n block: unknown\n options: {\n normalize: boolean\n removeUnusedMarkDefs: boolean\n validateFields: boolean\n }\n}): PortableTextBlock | undefined {\n return (\n parseTextBlock({block, schema, keyGenerator, options}) ??\n parseBlockObject({blockObject: block, schema, keyGenerator, options})\n )\n}\n\nfunction parseBlockObject({\n blockObject,\n schema,\n keyGenerator,\n options,\n}: {\n blockObject: unknown\n schema: Schema\n keyGenerator: () => string\n options: {validateFields: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(blockObject)) {\n return undefined\n }\n\n const schemaType = schema.blockObjects.find(\n ({name}) => name === blockObject._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: blockObject,\n schema,\n keyGenerator,\n schemaType,\n options,\n })\n}\n\nexport function isListBlock(\n context: Pick<EditorContext, 'schema'>,\n block: unknown,\n): block is PortableTextListBlock {\n return (\n isTextBlock(context, block) &&\n block.level !== undefined &&\n block.listItem !== undefined\n )\n}\n\nfunction parseTextBlock({\n block,\n schema,\n keyGenerator,\n options,\n}: {\n block: unknown\n schema: Schema\n keyGenerator: () => string\n options: {\n normalize: boolean\n removeUnusedMarkDefs: boolean\n validateFields: boolean\n }\n}): PortableTextTextBlock | undefined {\n if (!isTypedObject(block)) {\n return undefined\n }\n\n if (block._type !== schema.block.name) {\n return undefined\n }\n\n const customFields: Record<string, unknown> = {}\n\n for (const key of Object.keys(block)) {\n if (\n key === '_type' ||\n key === '_key' ||\n key === 'children' ||\n key === 'markDefs' ||\n key === 'style' ||\n key === 'listItem' ||\n key === 'level'\n ) {\n continue\n }\n\n if (options.validateFields) {\n if ((schema.block.fields ?? []).some((f) => f.name === key)) {\n customFields[key] = block[key]\n }\n } else {\n customFields[key] = block[key]\n }\n }\n\n const _key =\n typeof block['_key'] === 'string' ? block['_key'] : keyGenerator()\n\n const {markDefs, markDefKeyMap} = parseMarkDefsInternal({\n schema,\n keyGenerator,\n markDefs: block['markDefs'],\n options,\n })\n\n const unparsedChildren: Array<unknown> = Array.isArray(block['children'])\n ? block['children']\n : []\n\n const parsedChildren = unparsedChildren\n .map((child) =>\n parseChildInternal({child, schema, keyGenerator, markDefKeyMap, options}),\n )\n .filter((child) => child !== undefined)\n const marks = parsedChildren.flatMap((child) => child.marks ?? [])\n\n const children =\n parsedChildren.length > 0\n ? parsedChildren\n : [\n {\n _key: keyGenerator(),\n _type: schema.span.name,\n text: '',\n marks: [],\n },\n ]\n\n const normalizedChildren = options.normalize\n ? // Ensure that inline objects re surrounded by spans\n children.reduce<Array<PortableTextObject | PortableTextSpan>>(\n (normalizedChildren, child, index) => {\n if (isSpan({schema}, child)) {\n return [...normalizedChildren, child]\n }\n\n const previousChild = normalizedChildren.at(-1)\n\n if (!previousChild || !isSpan({schema}, previousChild)) {\n return [\n ...normalizedChildren,\n {\n _key: keyGenerator(),\n _type: schema.span.name,\n text: '',\n marks: [],\n },\n child,\n ...(index === children.length - 1\n ? [\n {\n _key: keyGenerator(),\n _type: schema.span.name,\n text: '',\n marks: [],\n },\n ]\n : []),\n ]\n }\n\n return [...normalizedChildren, child]\n },\n [],\n )\n : children\n\n const parsedBlock: PortableTextTextBlock = {\n _type: schema.block.name,\n _key,\n children: normalizedChildren,\n ...customFields,\n }\n\n if (typeof block['markDefs'] === 'object' && block['markDefs'] !== null) {\n parsedBlock.markDefs = options.removeUnusedMarkDefs\n ? markDefs.filter((markDef) => marks.includes(markDef._key))\n : markDefs\n }\n\n if (\n typeof block['style'] === 'string' &&\n schema.styles.find((style) => style.name === block['style'])\n ) {\n parsedBlock.style = block['style']\n }\n\n if (\n typeof block['listItem'] === 'string' &&\n schema.lists.find((list) => list.name === block['listItem'])\n ) {\n parsedBlock.listItem = block['listItem']\n }\n\n if (typeof block['level'] === 'number') {\n parsedBlock.level = block['level']\n }\n\n return parsedBlock\n}\n\nfunction parseMarkDefsInternal({\n schema,\n keyGenerator,\n markDefs,\n options,\n}: {\n schema: Schema\n keyGenerator: () => string\n markDefs: unknown\n options: {validateFields: boolean}\n}): {\n markDefs: Array<PortableTextObject>\n markDefKeyMap: Map<string, string>\n} {\n const unparsedMarkDefs: Array<unknown> = Array.isArray(markDefs)\n ? markDefs\n : []\n const markDefKeyMap = new Map<string, string>()\n\n const parsedMarkDefs = unparsedMarkDefs.flatMap((markDef) => {\n if (!isTypedObject(markDef)) {\n return []\n }\n\n const schemaType = schema.annotations.find(\n ({name}) => name === markDef._type,\n )\n\n if (!schemaType) {\n return []\n }\n\n if (typeof markDef['_key'] !== 'string') {\n // If the `markDef` doesn't have a `_key` then we don't know what spans\n // it belongs to and therefore we have to discard it.\n return []\n }\n\n const parsedAnnotation = parseObject({\n object: markDef,\n schema,\n keyGenerator,\n schemaType,\n options,\n })\n\n if (!parsedAnnotation) {\n return []\n }\n\n markDefKeyMap.set(markDef['_key'], parsedAnnotation._key)\n\n return [parsedAnnotation]\n })\n\n return {\n markDefs: parsedMarkDefs,\n markDefKeyMap,\n }\n}\n\nfunction parseChildInternal({\n child,\n schema,\n keyGenerator,\n markDefKeyMap,\n options,\n}: {\n child: unknown\n schema: Schema\n keyGenerator: () => string\n markDefKeyMap: Map<string, string>\n options: {validateFields: boolean}\n}): PortableTextSpan | PortableTextObject | undefined {\n return (\n parseSpanInternal({\n span: child,\n schema,\n keyGenerator,\n markDefKeyMap,\n options,\n }) ??\n parseInlineObjectInternal({\n inlineObject: child,\n schema,\n keyGenerator,\n options,\n })\n )\n}\n\nfunction parseSpanInternal({\n span,\n schema,\n keyGenerator,\n markDefKeyMap,\n options,\n}: {\n span: unknown\n schema: Schema\n keyGenerator: () => string\n markDefKeyMap: Map<string, string>\n options: {validateFields: boolean}\n}): PortableTextSpan | undefined {\n if (!isRecord(span)) {\n return undefined\n }\n\n const customFields: Record<string, unknown> = {}\n\n for (const key of Object.keys(span)) {\n if (\n key !== '_type' &&\n key !== '_key' &&\n key !== 'text' &&\n key !== 'marks'\n ) {\n customFields[key] = span[key]\n }\n }\n\n const unparsedMarks: Array<unknown> = Array.isArray(span['marks'])\n ? span['marks']\n : []\n const marks = unparsedMarks.flatMap((mark) => {\n if (typeof mark !== 'string') {\n return []\n }\n\n const markDefKey = markDefKeyMap.get(mark)\n\n if (markDefKey !== undefined) {\n return [markDefKey]\n }\n\n if (schema.decorators.some((decorator) => decorator.name === mark)) {\n return [mark]\n }\n\n return []\n })\n\n if (typeof span['_type'] === 'string' && span['_type'] !== schema.span.name) {\n return undefined\n }\n\n if (typeof span['_type'] !== 'string') {\n if (typeof span['text'] === 'string') {\n return {\n _type: schema.span.name as 'span',\n _key: typeof span['_key'] === 'string' ? span['_key'] : keyGenerator(),\n text: span['text'],\n marks,\n ...(options.validateFields ? {} : customFields),\n }\n }\n\n return undefined\n }\n\n return {\n _type: schema.span.name as 'span',\n _key: typeof span['_key'] === 'string' ? span['_key'] : keyGenerator(),\n text: typeof span['text'] === 'string' ? span['text'] : '',\n marks,\n ...(options.validateFields ? {} : customFields),\n }\n}\n\nfunction parseInlineObjectInternal({\n inlineObject,\n schema,\n keyGenerator,\n options,\n}: {\n inlineObject: unknown\n schema: Schema\n keyGenerator: () => string\n options: {validateFields: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(inlineObject)) {\n return undefined\n }\n\n const schemaType = schema.inlineObjects.find(\n ({name}) => name === inlineObject._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: inlineObject,\n schema,\n keyGenerator,\n schemaType,\n options,\n })\n}\n\nexport function parseAnnotation({\n annotation,\n schema,\n keyGenerator,\n options,\n}: {\n annotation: TypedObject\n schema: Schema\n keyGenerator: () => string\n options: {validateFields: boolean}\n}): PortableTextObject | undefined {\n if (!isTypedObject(annotation)) {\n return undefined\n }\n\n const schemaType = schema.annotations.find(\n ({name}) => name === annotation._type,\n )\n\n if (!schemaType) {\n return undefined\n }\n\n return parseObject({\n object: annotation,\n schema,\n keyGenerator,\n schemaType,\n options,\n })\n}\n\n/**\n * Resolve an `of` member against a runtime `_type`. Returns the schema-type\n * to use for parsing the item, or `undefined` if no member matches.\n *\n * Three forms (one branch each):\n * - Inline declaration `{type: 'object', name: 'X', fields: [...]}` -- name\n * matches `_type`, fields are inline.\n * - Reference `{type: 'X'}` -- looks up in the ancestor chain first\n * (inline-declared types are visible to descendants), then in the schema's\n * root `blockObjects`. Mirrors `resolve-containers.ts`'s reference\n * resolution.\n * - `{type: 'block'}` -- not a non-PTE object member, returns `undefined`.\n */\nfunction resolveOfMember(\n of: ReadonlyArray<OfDefinition>,\n typeName: string,\n schema: Schema,\n ancestorFields: ReadonlyMap<string, ReadonlyArray<FieldDefinition>>,\n): {name: string; fields: ReadonlyArray<FieldDefinition>} | undefined {\n for (const member of of) {\n if (member.type === 'block') {\n continue\n }\n if (member.type === 'object' && 'name' in member && member.name) {\n if (member.name === typeName && 'fields' in member && member.fields) {\n return {name: member.name, fields: member.fields}\n }\n continue\n }\n if (member.type === typeName) {\n const ancestorMatch = ancestorFields.get(typeName)\n if (ancestorMatch) {\n return {name: typeName, fields: ancestorMatch}\n }\n const rootMatch = schema.blockObjects.find(\n (blockObject) => blockObject.name === typeName,\n )\n if (rootMatch && 'fields' in rootMatch && rootMatch.fields) {\n return {name: rootMatch.name, fields: rootMatch.fields}\n }\n return undefined\n }\n }\n return undefined\n}\n\n/**\n * Parse an object against a `{name, fields}` schema type. Validates top-level\n * fields and recurses into any array field whose `of` contains a block-like\n * member -- parsing the nested blocks against a child `Schema` built from\n * that `of`.\n */\nfunction parseObject({\n object,\n schema,\n keyGenerator,\n schemaType,\n ancestorFields,\n options,\n}: {\n object: TypedObject\n schema: Schema\n keyGenerator: () => string\n schemaType: {\n name: string\n fields: ReadonlyArray<FieldDefinition>\n }\n ancestorFields?: ReadonlyMap<string, ReadonlyArray<FieldDefinition>>\n options: {validateFields: boolean}\n}): PortableTextObject {\n const {_key, ...customFields} = object\n\n const fieldsByName = new Map(\n schemaType.fields.map((field) => [field.name, field]),\n )\n\n const nextAncestors = new Map(ancestorFields ?? [])\n nextAncestors.set(schemaType.name, schemaType.fields)\n\n const values: Record<string, unknown> = {}\n\n for (const [key, value] of Object.entries(customFields)) {\n if (key === '_type') {\n continue\n }\n\n if (value === undefined) {\n continue\n }\n\n const field = fieldsByName.get(key)\n\n if (options.validateFields && !field) {\n continue\n }\n\n if (field && field.type === 'array' && field.of && Array.isArray(value)) {\n values[key] = parseContainerFieldValue({\n schema,\n keyGenerator,\n of: field.of,\n value,\n ancestorFields: nextAncestors,\n options,\n })\n continue\n }\n\n values[key] = value\n }\n\n return {\n _type: schemaType.name,\n _key: typeof _key === 'string' ? _key : keyGenerator(),\n ...values,\n }\n}\n\n/**\n * Parse the value of an array field whose `of` declares what's allowed at\n * that position. Each item is dispatched per its own type:\n *\n * - Text blocks (`_type === schema.block.name`) are parsed against a child\n * sub-schema derived from the `{type: 'block'}` member of `of` (which\n * carries the styles, decorators, annotations, lists, and inline objects\n * allowed at this position).\n *\n * - Block objects (and structural objects sitting between containers and\n * text blocks) are parsed via `resolveOfMember` against the `of` array,\n * with `ancestorFields` carrying inline type declarations down to bare\n * references like `{type: 'list'}`. This lets nested containers resolve\n * to their inline shapes at any depth.\n *\n * Items that don't resolve are passed through unchanged.\n */\nfunction parseContainerFieldValue({\n schema,\n keyGenerator,\n of,\n value,\n ancestorFields,\n options,\n}: {\n schema: Schema\n keyGenerator: () => string\n of: ReadonlyArray<OfDefinition>\n value: ReadonlyArray<unknown>\n ancestorFields: ReadonlyMap<string, ReadonlyArray<FieldDefinition>>\n options: {validateFields: boolean; normalize?: boolean}\n}): Array<unknown> {\n const hasBlockMember = of.some((member) => member.type === 'block')\n const childBlockSubSchema = hasBlockMember\n ? getSubSchema(schema, of)\n : undefined\n\n return value.flatMap((item) => {\n if (!isTypedObject(item)) {\n return [item]\n }\n\n if (childBlockSubSchema && item._type === childBlockSubSchema.block.name) {\n const parsed = parseTextBlock({\n block: item,\n schema: childBlockSubSchema,\n keyGenerator,\n options: {\n normalize: false,\n removeUnusedMarkDefs: false,\n validateFields: options.validateFields,\n },\n })\n return parsed ? [parsed] : []\n }\n\n const schemaType = resolveOfMember(of, item._type, schema, ancestorFields)\n if (!schemaType) {\n return [item]\n }\n return [\n parseObject({\n object: item,\n schema,\n keyGenerator,\n schemaType: {\n name: schemaType.name,\n fields: schemaType.fields,\n },\n ancestorFields,\n options,\n }),\n ]\n })\n}\n","import {isSpan, isTextBlock, type PortableTextBlock} from '@portabletext/schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {defaultKeyGenerator} from './key-generator'\nimport {parseBlock} from './parse-blocks'\nimport {getSelectionEndPoint} from './util.get-selection-end-point'\nimport {getSelectionStartPoint} from './util.get-selection-start-point'\nimport {\n getBlockKeyFromSelectionPoint,\n getChildKeyFromSelectionPoint,\n} from './util.selection-point'\n\n/**\n * @public\n */\nexport function sliceBlocks({\n context,\n blocks,\n}: {\n context: Pick<EditorContext, 'schema' | 'selection'> & {\n keyGenerator?: () => string\n }\n blocks: Array<PortableTextBlock>\n}): Array<PortableTextBlock> {\n const slice: Array<PortableTextBlock> = []\n\n if (!context.selection) {\n return slice\n }\n\n let startBlock: PortableTextBlock | undefined\n const middleBlocks: PortableTextBlock[] = []\n let endBlock: PortableTextBlock | undefined\n\n const startPoint = getSelectionStartPoint(context.selection)\n const endPoint = getSelectionEndPoint(context.selection)\n const startBlockKey = getBlockKeyFromSelectionPoint(startPoint)\n const startChildKey = getChildKeyFromSelectionPoint(startPoint)\n const endBlockKey = getBlockKeyFromSelectionPoint(endPoint)\n const endChildKey = getChildKeyFromSelectionPoint(endPoint)\n\n if (!startBlockKey || !endBlockKey) {\n return slice\n }\n\n for (const block of blocks) {\n if (!isTextBlock(context, block)) {\n if (block._key === startBlockKey && block._key === endBlockKey) {\n startBlock = block\n break\n }\n }\n\n if (block._key === startBlockKey) {\n if (!isTextBlock(context, block)) {\n startBlock = block\n continue\n }\n\n if (startChildKey) {\n for (const child of block.children) {\n if (child._key === startChildKey) {\n if (isSpan(context, child)) {\n const text =\n child._key === endChildKey\n ? child.text.slice(startPoint.offset, endPoint.offset)\n : child.text.slice(startPoint.offset)\n\n startBlock = {\n ...block,\n children: [\n {\n ...child,\n text,\n },\n ],\n }\n } else {\n startBlock = {\n ...block,\n children: [child],\n }\n }\n\n if (block._key === endBlockKey && startChildKey === endChildKey) {\n break\n }\n continue\n }\n\n if (startBlock && isTextBlock(context, startBlock)) {\n if (\n endChildKey &&\n child._key === endChildKey &&\n isSpan(context, child)\n ) {\n startBlock.children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n } else {\n startBlock.children.push(child)\n }\n\n if (\n block._key === endBlockKey &&\n endChildKey &&\n child._key === endChildKey\n ) {\n break\n }\n }\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n\n continue\n }\n\n startBlock = block\n\n if (startBlockKey === endBlockKey) {\n break\n }\n }\n\n if (block._key === endBlockKey) {\n if (!isTextBlock(context, block)) {\n endBlock = block\n break\n }\n\n if (endChildKey) {\n endBlock = {\n ...block,\n children: [],\n }\n\n for (const child of block.children) {\n if (endBlock && isTextBlock(context, endBlock)) {\n if (child._key === endChildKey && isSpan(context, child)) {\n endBlock.children.push({\n ...child,\n text: child.text.slice(0, endPoint.offset),\n })\n\n break\n }\n\n endBlock.children.push(child)\n\n if (endChildKey && child._key === endChildKey) {\n break\n }\n }\n }\n\n break\n }\n\n endBlock = block\n\n break\n }\n\n if (startBlock) {\n middleBlocks.push(\n parseBlock({\n keyGenerator: context.keyGenerator ?? defaultKeyGenerator,\n block,\n options: {\n normalize: false,\n removeUnusedMarkDefs: true,\n validateFields: false,\n },\n schema: context.schema,\n }) ?? block,\n )\n }\n }\n\n const parsedStartBlock = startBlock\n ? parseBlock({\n keyGenerator: context.keyGenerator ?? defaultKeyGenerator,\n block: startBlock,\n options: {\n normalize: false,\n removeUnusedMarkDefs: true,\n validateFields: false,\n },\n schema: context.schema,\n })\n : undefined\n\n const parsedEndBlock = endBlock\n ? parseBlock({\n keyGenerator: context.keyGenerator ?? defaultKeyGenerator,\n block: endBlock,\n options: {\n normalize: false,\n removeUnusedMarkDefs: true,\n validateFields: false,\n },\n schema: context.schema,\n })\n : undefined\n\n return [\n ...(parsedStartBlock ? [parsedStartBlock] : []),\n ...middleBlocks,\n ...(parsedEndBlock ? [parsedEndBlock] : []),\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;;AAcA,SAAgB,kBACd,UACA,aACA,UACA,eACoB;CACpB,IAAI,sBAAsB;CAE1B,KAAK,IAAM,SAAS,UAAU;EAC5B,IAAM,OAAO,YAAY,KAAK;EAC9B,IAAI,MAAM,KAAK,MAAM,UACnB,OAAO,SAAS,KAAA,IACZ,KAAA,IACA,sBAAsB;EAE5B,AAAI,SAAS,KAAA,MACX,uBAAuB,KAAK;CAEhC;AAGF;;;;;;;AAQA,SAAgB,kBACd,UACA,aACA,YAC2C;CAC3C,IAAI,kBA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