@portabletext/editor 7.5.1 → 7.5.2

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.
@@ -1,12 +1,11 @@
1
1
  import { rangeEdges, comparePoints$1 as comparePoints, isInline, isSpanNode, isObject, getEnclosingBlock, resolveContainerAt, hasNode, getBlock, getNodes, getSibling, getPathSubSchema, isTextBlockNode, isEditableContainer } from "./get-path-sub-schema.js";
2
- import { isSelectionCollapsed as isSelectionCollapsed$1, getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint as getSelectionEndPoint$1, sliceBlocks, getBlockStartPoint, getBlockEndPoint, isEqualSelectionPoints, blockOffsetToSpanSelectionPoint, spanSelectionPointToBlockOffset, isListBlock } from "./util.slice-blocks.js";
2
+ import { getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint as getSelectionEndPoint$1, sliceBlocks, isSelectionCollapsed as isSelectionCollapsed$1, getBlockStartPoint, getBlockEndPoint, isEqualSelectionPoints, blockOffsetToSpanSelectionPoint, spanSelectionPointToBlockOffset, isListBlock } from "./util.slice-blocks.js";
3
3
  import { getNode, getNodeChildren, isKeyedSegment, getParent, getChildren, parentPath } from "./get-parent.js";
4
4
  import { isSpan, isTextBlock } from "@portabletext/schema";
5
5
  function rangesOverlap(rangeA, rangeB, root) {
6
6
  const [startA, endA] = rangeEdges(rangeA, root), [startB, endB] = rangeEdges(rangeB, root);
7
7
  return comparePoints(startA, endB, root) <= 0 && comparePoints(startB, endA, root) <= 0;
8
8
  }
9
- const isSelectionCollapsed = (snapshot) => isSelectionCollapsed$1(snapshot.context.selection);
10
9
  function getInline(snapshot, path) {
11
10
  const entry = getNode(snapshot, path);
12
11
  if (!(!entry || !isInline(snapshot, entry.path)) && !(!isSpanNode({
@@ -252,7 +251,7 @@ function isOverlappingSelection(selection) {
252
251
  });
253
252
  };
254
253
  }
255
- const isSelectionExpanded$1 = (snapshot) => snapshot.context.selection !== null && !isSelectionCollapsed(snapshot), getSelectedBlocks = (snapshot) => {
254
+ const isSelectionCollapsed = (snapshot) => isSelectionCollapsed$1(snapshot.context.selection), isSelectionExpanded$1 = (snapshot) => snapshot.context.selection !== null && !isSelectionCollapsed(snapshot), getSelectedBlocks = (snapshot) => {
256
255
  const selection = snapshot.context.selection;
257
256
  if (!selection)
258
257
  return [];
@@ -1 +1 @@
1
- {"version":3,"file":"selector.is-at-the-start-of-block.js","sources":["../../src/engine/range/ranges-overlap.ts","../../src/selectors/selector.is-selection-collapsed.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-expanded.ts","../../src/selectors/selector.get-selected-blocks.ts","../../src/selectors/selector.is-selecting-entire-blocks.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-applicable-schema.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-first-block.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"],"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 {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 {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 * 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 {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} 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 {PortableTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getNodes} from '../traversal/get-nodes'\nimport {getBlock} from '../traversal/is-block'\nimport type {BlockPath} from '../types/paths'\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\n/**\n * Returns the root-level blocks the selection covers.\n *\n * Only looks at direct children of the editor. If the selection is inside\n * an editable container, the container itself is returned - not its inner\n * blocks. Containers are preserved whole.\n *\n * Use for block-level operations like `move.block up/down` and\n * drag-and-drop. For \"selection as portable text\" use `getSelectedValue`;\n * for \"text blocks at any depth\" use `getSelectedTextBlocks`.\n *\n * @public\n */\nexport const getSelectedBlocks: EditorSelector<\n Array<{node: PortableTextBlock; path: BlockPath}>\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 share the same root-level block, that\n // single block is the answer. The range walk only needs to run when\n // the selection crosses block boundaries.\n const startRootKey = startPoint.path.find(isKeyedSegment)?._key\n const endRootKey = endPoint.path.find(isKeyedSegment)?._key\n if (startRootKey && startRootKey === endRootKey) {\n const block = getBlock(snapshot, [{_key: startRootKey}])\n if (block) {\n return [{node: block.node, path: block.path}]\n }\n }\n\n const result: Array<{node: PortableTextBlock; path: BlockPath}> = []\n\n for (const entry of getNodes(snapshot, {\n from: startPoint.path,\n to: endPoint.path,\n match: (_, path) => path.length === 1,\n })) {\n const block = getBlock(snapshot, entry.path)\n if (block) {\n result.push({node: block.node, path: block.path})\n }\n }\n\n return result\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","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 * @beta\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 * @beta\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 {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'\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 take up the entire selection in the\n * `snapshot` or if the annotation can be partially selected.\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') {\n const selectedValue = getSelectedValue(snapshot)\n\n const selectionMarkDefs = selectedValue.flatMap((block) =>\n isTextBlock(snapshot.context, block) ? (block.markDefs ?? []) : [],\n )\n\n return selectionMarkDefs.some((markDef) => markDef._type === annotation)\n }\n\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 {EditorSelector} from '../editor/editor-selector'\nimport {getPathSubSchema} from '../traversal/get-path-sub-schema'\nimport {getFocusBlock} from './selector.get-focus-block'\nimport {getSelectedTextBlocks} from './selector.get-selected-text-blocks'\n\n/**\n * The set of schema member names applicable at the current selection,\n * grouped by category.\n *\n * @beta\n */\nexport type ApplicableSchema = {\n decorators: ReadonlySet<string>\n annotations: ReadonlySet<string>\n lists: ReadonlySet<string>\n styles: ReadonlySet<string>\n blockObjects: ReadonlySet<string>\n inlineObjects: ReadonlySet<string>\n}\n\n/**\n * Resolve which schema members are applicable at the current selection. For\n * each named category (decorators, annotations, lists, styles, block objects,\n * inline objects) returns the set of names that the editor allows at the\n * current selection.\n *\n * Categories split by what they apply to:\n *\n * Text-only (decorators, annotations, lists, styles): require text-block\n * content in the selection. A name is applicable when at least one text\n * block the range covers declares it (union). The underlying operations\n * apply per-block, validating each block's sub-schema and skipping blocks\n * that don't declare the type, so the result reflects \"will this produce\n * any effect?\" semantics. Selection on a void block, or no selection,\n * returns empty sets.\n *\n * Insertion (blockObjects, inlineObjects): the things consumers might\n * insert AT the current selection. The focus block's sub-schema applies\n * even when the selection is on a void block (the question \"what can I\n * insert here?\" still has an answer). No selection returns empty sets.\n *\n * Useful for gating toolbar buttons, slash-command items, command palettes,\n * keyboard-shortcut hints and other selection-aware UIs.\n *\n * Pair with `getUnionSchema` (from `@portabletext/editor/traversal`) to render a static toolbar whose\n * buttons stay stable across selection moves while gating their enabled\n * state on whether the corresponding name is in the relevant set.\n *\n * Note for React consumers: the returned object is a fresh value on every\n * call, so subscribing via `useEditorSelector` requires a structural\n * compare to avoid re-rendering on every editor tick. Use\n * {@link compareApplicableSchema} as the third argument.\n *\n * @beta\n */\nexport const getApplicableSchema: EditorSelector<ApplicableSchema> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return EMPTY\n }\n\n const focusBlock = getFocusBlock(snapshot)\n const focusSub = focusBlock\n ? getPathSubSchema(snapshot, focusBlock.path)\n : undefined\n\n const insertion = focusSub\n ? {\n blockObjects: namesOfArray(focusSub.blockObjects),\n inlineObjects: namesOfArray(focusSub.inlineObjects),\n }\n : {blockObjects: EMPTY_SET, inlineObjects: EMPTY_SET}\n\n const textBlocks = getSelectedTextBlocks(snapshot)\n\n if (textBlocks.length === 0) {\n return {\n decorators: EMPTY_SET,\n annotations: EMPTY_SET,\n lists: EMPTY_SET,\n styles: EMPTY_SET,\n ...insertion,\n }\n }\n\n let textApplicable = textCategoryNames(\n getPathSubSchema(snapshot, textBlocks[0]!.path),\n )\n for (let i = 1; i < textBlocks.length; i++) {\n textApplicable = unionTextCategories(\n textApplicable,\n textCategoryNames(getPathSubSchema(snapshot, textBlocks[i]!.path)),\n )\n }\n\n return {\n ...textApplicable,\n ...insertion,\n }\n}\n\n/**\n * Structural comparator for {@link ApplicableSchema} values. Two results\n * compare equal when every category contains the same names (set equality).\n * Pass as the `compare` argument to `useEditorSelector` to keep React\n * subscriptions stable.\n *\n * @beta\n */\nexport function compareApplicableSchema(\n a: ApplicableSchema,\n b: ApplicableSchema,\n): boolean {\n if (a === b) {\n return true\n }\n return (\n sameSet(a.decorators, b.decorators) &&\n sameSet(a.annotations, b.annotations) &&\n sameSet(a.lists, b.lists) &&\n sameSet(a.styles, b.styles) &&\n sameSet(a.blockObjects, b.blockObjects) &&\n sameSet(a.inlineObjects, b.inlineObjects)\n )\n}\n\nconst EMPTY_SET: ReadonlySet<string> = Object.freeze(new Set<string>())\n\nconst EMPTY: ApplicableSchema = Object.freeze({\n decorators: EMPTY_SET,\n annotations: EMPTY_SET,\n lists: EMPTY_SET,\n styles: EMPTY_SET,\n blockObjects: EMPTY_SET,\n inlineObjects: EMPTY_SET,\n})\n\ntype TextCategoryNames = Pick<\n ApplicableSchema,\n 'decorators' | 'annotations' | 'lists' | 'styles'\n>\n\nfunction textCategoryNames(schema: {\n decorators: ReadonlyArray<{name: string}>\n annotations: ReadonlyArray<{name: string}>\n lists: ReadonlyArray<{name: string}>\n styles: ReadonlyArray<{name: string}>\n}): TextCategoryNames {\n return {\n decorators: namesOfArray(schema.decorators),\n annotations: namesOfArray(schema.annotations),\n lists: namesOfArray(schema.lists),\n styles: namesOfArray(schema.styles),\n }\n}\n\nfunction unionTextCategories(\n a: TextCategoryNames,\n b: TextCategoryNames,\n): TextCategoryNames {\n return {\n decorators: unionSet(a.decorators, b.decorators),\n annotations: unionSet(a.annotations, b.annotations),\n lists: unionSet(a.lists, b.lists),\n styles: unionSet(a.styles, b.styles),\n }\n}\n\nfunction namesOfArray(\n entries: ReadonlyArray<{name: string}>,\n): ReadonlySet<string> {\n return new Set(entries.map((entry) => entry.name))\n}\n\nfunction unionSet(a: ReadonlySet<string>, b: ReadonlySet<string>): Set<string> {\n const result = new Set<string>(a)\n for (const item of b) {\n result.add(item)\n }\n return result\n}\n\nfunction sameSet(a: ReadonlySet<string>, b: ReadonlySet<string>) {\n if (a === b) {\n return true\n }\n if (a.size !== b.size) {\n return false\n }\n for (const item of a) {\n if (!b.has(item)) {\n return false\n }\n }\n return true\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 const firstStyle = firstTextBlock.node.style\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 (inScopeBlocks.every((block) => block.node.style === firstStyle)) {\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 {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 first 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 first block within that container (the first line). When\n * the focus is at root, or there is no selection, this returns the first\n * block in the document.\n *\n * @public\n */\nexport const getFirstBlock: 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 first = siblings.at(0)\n\n if (first) {\n return getBlock(snapshot, first.path)\n }\n }\n\n const node = snapshot.context.value[0]\n\n return node ? {node, path: [{_key: node._key}]} : undefined\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"],"names":["rangesOverlap","rangeA","rangeB","root","startA","endA","rangeEdges","startB","endB","comparePoints","isSelectionCollapsed","snapshot","isSelectionCollapsedUtil","context","selection","getInline","path","entry","getNode","isInline","isSpanNode","schema","node","isObject","getFocusChild","focus","getFocusInlineObject","focusChild","undefined","getFocusSpan","isSpan","getFocusBlock","getEnclosingBlock","getFocusTextBlock","focusBlock","isTextBlock","getRootAcceptedTypes","Set","block","name","blockObjects","map","blockObject","getSelectedValue","startPoint","getSelectionStartPoint","endPoint","getSelectionEndPoint","sliceArray","blocks","value","pathPrefix","fieldNameInPrefix","startEdge","endEdge","parent","length","startIdx","resolveIndex","endIdx","lo","hi","loEdge","hiEdge","result","i","blockPath","_key","startPointForBlock","endPointForBlock","startInside","edgeIsInside","endInside","push","sliced","sliceBoundaryTextBlock","childInfo","getNodeChildren","innerSliced","children","fieldName","updatedBlock","edge","findBlockIndexForPoint","point","nodeSegmentIndex","segment","isKeyedSegment","findIndex","firstChild","lastChild","blockRelativeStart","stripPrefix","fallback","blockRelativeEnd","sliceBlocks","anchor","opts","slice","offset","text","getFragment","envelope","containers","rootAcceptedTypes","textBlockName","lastRootValid","lastRootValidPrefix","current","single","singlePath","container","resolveContainerAt","field","Array","isArray","childBlocks","every","_type","has","getSelectionEndBlock","getSelectionStartBlock","isOverlappingSelection","editorSelection","hasNode","isSelectionExpanded","getSelectedBlocks","startRootKey","find","endRootKey","getBlock","getNodes","from","to","match","_","isSelectingEntireBlocks","backward","startBlock","endBlock","startBlockStartPoint","getBlockStartPoint","endBlockEndPoint","getBlockEndPoint","isEqualSelectionPoints","getNextSpan","getSibling","direction","getPreviousSpan","getSelectedChildren","options","filter","startChildKey","findLast","endChildKey","child","skip","getSelectedSpans","getMarkState","spanSelectionPoint","blockOffsetToSpanSelectionPoint","blockOffset","focusSpan","spanInfo","span","getParent","marks","decoratorNames","getPathSubSchema","decorators","decorator","markDefKeys","markDefs","markDef","candidateMarks","spanMarks","mark","add","candidate","isDecoratorSomewhere","some","includes","active","state","marksWithoutAnnotations","spanHasAnnotations","spanIsEmpty","atTheBeginningOfSpan","atTheEndOfSpan","previousSpan","nextSpan","nextSpanAnnotations","spanAnnotations","previousSpanHasAnnotations","previousSpanHasSameAnnotations","previousSpanHasSameAnnotation","previousSpanHasSameMarks","nextSpanSharesSomeAnnotations","previousMarks","getActiveAnnotationsMarks","getSelectedTextBlocks","getActiveDecorators","decoratorState","markState","selectedBlocks","size","activeDecorators","activeDecorator","isActiveAnnotation","annotation","mode","flatMap","selectionMarkDefs","activeAnnotations","getApplicableSchema","EMPTY","focusSub","insertion","namesOfArray","inlineObjects","EMPTY_SET","textBlocks","annotations","lists","styles","textApplicable","textCategoryNames","unionTextCategories","compareApplicableSchema","a","b","sameSet","Object","freeze","unionSet","entries","item","getActiveAnnotations","getActiveListItem","selectedTextBlocks","firstTextBlock","at","firstListItem","listItem","l","getActiveStyle","firstStyle","style","s","getNextInlineObject","getPreviousInlineObject","getSelectionText","selectedValue","collectText","getCaretWordSelection","focusTextBlock","selectionStartPoint","selectionStartOffset","spanSelectionPointToBlockOffset","selectionPoint","previousInlineObject","blockStartPoint","textDirectlyBefore","split","nextInlineObject","blockEndPoint","textDirectlyAfter","caretWordStartOffset","caretWordEndOffset","caretWordStartSelectionPoint","caretWordEndSelectionPoint","caretWordSelection","getFirstBlock","first","getChildren","parentPath","getFocusBlockObject","isTextBlockNode","isEditableContainer","getFocusListBlock","isListBlock","getLastBlock","last","getNextBlock","selectionEndBlock","next","getPreviousBlock","selectionStartBlock","previous","getSelectionEndChild","getSelectionStartChild","isActiveDecorator","inScopeSpans","d","isActiveListItem","isActiveStyle","isAtTheEndOfBlock","isAtTheStartOfBlock"],"mappings":";;;;AAWO,SAASA,cACdC,QACAC,QACAC,MACS;AACT,QAAM,CAACC,QAAQC,IAAI,IAAIC,WAAWL,QAAQE,IAAI,GACxC,CAACI,QAAQC,IAAI,IAAIF,WAAWJ,QAAQC,IAAI;AAC9C,SACEM,cAAcL,QAAQI,MAAML,IAAI,KAAK,KACrCM,cAAcF,QAAQF,MAAMF,IAAI,KAAK;AAEzC;AChBO,MAAMO,uBAAiDC,CAAAA,aAC5DC,uBAAyBD,SAASE,QAAQC,SAAS;ACQ9C,SAASC,UACdJ,UACAK,MACuE;AACvE,QAAMC,QAAQC,QAAQP,UAAUK,IAAI;AAEpC,MAAI,EAAA,CAACC,SAAS,CAACE,SAASR,UAAUM,MAAMD,IAAI,MAK1C,EAAA,CAACI,WAAW;AAAA,IAACC,QAAQV,SAASE,QAAQQ;AAAAA,EAAAA,GAAS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IZ4I,OAAQa,UACzCI,iBAAiB7J,UAAUyJ,KAAKpJ,IAAI,EAAEyJ,WAAWW,KAC9CiH,OAAMA,EAAE9P,SAASmI,SACpB,CACF;AAEA,aACE0H,aAAa5O,SAAS,KACtB4O,aAAa/K,MAAO+C,CAAAA,SAASA,KAAK9I,KAAKgJ,OAAOe,SAASX,SAAS,CAAC;AAAA,IAErE;AAIA,WAFyB+B,oBAAoB9L,QAAQ,EAE7B0K,SAASX,SAAS;AAAA,EAC5C;AACF;AC1BO,SAAS4H,iBAAiBnD,UAA2C;AAC1E,SAAQxO,CAAAA,aACiBmO,kBAAkBnO,QAAQ,MAEvBwO;AAE9B;ACNO,SAASoD,cAAchD,OAAwC;AACpE,SAAQ5O,CAAAA,aACc0O,eAAe1O,QAAQ,MAEpB4O;AAE3B;ACFO,SAASiD,kBAAkBlQ,OAGN;AAC1B,SAAQ3B,CAAAA,aAAa;AACnB,QAAI,CAACA,SAASE,QAAQC,aAAa,CAACJ,qBAAqBC,QAAQ;AAC/D,aAAO;AAGT,UAAM8P,gBAAgB1H,iBAAiB;AAAA,MACrClI,SAASF,SAASE;AAAAA,MAClByB;AAAAA,IAAAA,CACD;AAED,WAAO0G,uBACLrI,SAASE,QAAQC,UAAUW,OAC3BgP,aACF;AAAA,EACF;AACF;ACnBO,SAASgC,oBAAoBnQ,OAGR;AAC1B,SAAQ3B,CAAAA,aAAa;AACnB,QAAI,CAACA,SAASE,QAAQC,aAAa,CAACJ,qBAAqBC,QAAQ;AAC/D,aAAO;AAGT,UAAM0P,kBAAkBxH,mBAAmB;AAAA,MACzChI,SAASF,SAASE;AAAAA,MAClByB;AAAAA,IAAAA,CACD;AAED,WAAO0G,uBACLrI,SAASE,QAAQC,UAAUW,OAC3B4O,eACF;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"selector.is-at-the-start-of-block.js","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/selectors/selector.get-selected-blocks.ts","../../src/selectors/selector.is-selecting-entire-blocks.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-applicable-schema.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-first-block.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"],"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 * 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 {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 {PortableTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getNodes} from '../traversal/get-nodes'\nimport {getBlock} from '../traversal/is-block'\nimport type {BlockPath} from '../types/paths'\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\n/**\n * Returns the root-level blocks the selection covers.\n *\n * Only looks at direct children of the editor. If the selection is inside\n * an editable container, the container itself is returned - not its inner\n * blocks. Containers are preserved whole.\n *\n * Use for block-level operations like `move.block up/down` and\n * drag-and-drop. For \"selection as portable text\" use `getSelectedValue`;\n * for \"text blocks at any depth\" use `getSelectedTextBlocks`.\n *\n * @public\n */\nexport const getSelectedBlocks: EditorSelector<\n Array<{node: PortableTextBlock; path: BlockPath}>\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 share the same root-level block, that\n // single block is the answer. The range walk only needs to run when\n // the selection crosses block boundaries.\n const startRootKey = startPoint.path.find(isKeyedSegment)?._key\n const endRootKey = endPoint.path.find(isKeyedSegment)?._key\n if (startRootKey && startRootKey === endRootKey) {\n const block = getBlock(snapshot, [{_key: startRootKey}])\n if (block) {\n return [{node: block.node, path: block.path}]\n }\n }\n\n const result: Array<{node: PortableTextBlock; path: BlockPath}> = []\n\n for (const entry of getNodes(snapshot, {\n from: startPoint.path,\n to: endPoint.path,\n match: (_, path) => path.length === 1,\n })) {\n const block = getBlock(snapshot, entry.path)\n if (block) {\n result.push({node: block.node, path: block.path})\n }\n }\n\n return result\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","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 * @beta\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 * @beta\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 {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'\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 take up the entire selection in the\n * `snapshot` or if the annotation can be partially selected.\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') {\n const selectedValue = getSelectedValue(snapshot)\n\n const selectionMarkDefs = selectedValue.flatMap((block) =>\n isTextBlock(snapshot.context, block) ? (block.markDefs ?? []) : [],\n )\n\n return selectionMarkDefs.some((markDef) => markDef._type === annotation)\n }\n\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 {EditorSelector} from '../editor/editor-selector'\nimport {getPathSubSchema} from '../traversal/get-path-sub-schema'\nimport {getFocusBlock} from './selector.get-focus-block'\nimport {getSelectedTextBlocks} from './selector.get-selected-text-blocks'\n\n/**\n * The set of schema member names applicable at the current selection,\n * grouped by category.\n *\n * @beta\n */\nexport type ApplicableSchema = {\n decorators: ReadonlySet<string>\n annotations: ReadonlySet<string>\n lists: ReadonlySet<string>\n styles: ReadonlySet<string>\n blockObjects: ReadonlySet<string>\n inlineObjects: ReadonlySet<string>\n}\n\n/**\n * Resolve which schema members are applicable at the current selection. For\n * each named category (decorators, annotations, lists, styles, block objects,\n * inline objects) returns the set of names that the editor allows at the\n * current selection.\n *\n * Categories split by what they apply to:\n *\n * Text-only (decorators, annotations, lists, styles): require text-block\n * content in the selection. A name is applicable when at least one text\n * block the range covers declares it (union). The underlying operations\n * apply per-block, validating each block's sub-schema and skipping blocks\n * that don't declare the type, so the result reflects \"will this produce\n * any effect?\" semantics. Selection on a void block, or no selection,\n * returns empty sets.\n *\n * Insertion (blockObjects, inlineObjects): the things consumers might\n * insert AT the current selection. The focus block's sub-schema applies\n * even when the selection is on a void block (the question \"what can I\n * insert here?\" still has an answer). No selection returns empty sets.\n *\n * Useful for gating toolbar buttons, slash-command items, command palettes,\n * keyboard-shortcut hints and other selection-aware UIs.\n *\n * Pair with `getUnionSchema` (from `@portabletext/editor/traversal`) to render a static toolbar whose\n * buttons stay stable across selection moves while gating their enabled\n * state on whether the corresponding name is in the relevant set.\n *\n * Note for React consumers: the returned object is a fresh value on every\n * call, so subscribing via `useEditorSelector` requires a structural\n * compare to avoid re-rendering on every editor tick. Use\n * {@link compareApplicableSchema} as the third argument.\n *\n * @beta\n */\nexport const getApplicableSchema: EditorSelector<ApplicableSchema> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return EMPTY\n }\n\n const focusBlock = getFocusBlock(snapshot)\n const focusSub = focusBlock\n ? getPathSubSchema(snapshot, focusBlock.path)\n : undefined\n\n const insertion = focusSub\n ? {\n blockObjects: namesOfArray(focusSub.blockObjects),\n inlineObjects: namesOfArray(focusSub.inlineObjects),\n }\n : {blockObjects: EMPTY_SET, inlineObjects: EMPTY_SET}\n\n const textBlocks = getSelectedTextBlocks(snapshot)\n\n if (textBlocks.length === 0) {\n return {\n decorators: EMPTY_SET,\n annotations: EMPTY_SET,\n lists: EMPTY_SET,\n styles: EMPTY_SET,\n ...insertion,\n }\n }\n\n let textApplicable = textCategoryNames(\n getPathSubSchema(snapshot, textBlocks[0]!.path),\n )\n for (let i = 1; i < textBlocks.length; i++) {\n textApplicable = unionTextCategories(\n textApplicable,\n textCategoryNames(getPathSubSchema(snapshot, textBlocks[i]!.path)),\n )\n }\n\n return {\n ...textApplicable,\n ...insertion,\n }\n}\n\n/**\n * Structural comparator for {@link ApplicableSchema} values. Two results\n * compare equal when every category contains the same names (set equality).\n * Pass as the `compare` argument to `useEditorSelector` to keep React\n * subscriptions stable.\n *\n * @beta\n */\nexport function compareApplicableSchema(\n a: ApplicableSchema,\n b: ApplicableSchema,\n): boolean {\n if (a === b) {\n return true\n }\n return (\n sameSet(a.decorators, b.decorators) &&\n sameSet(a.annotations, b.annotations) &&\n sameSet(a.lists, b.lists) &&\n sameSet(a.styles, b.styles) &&\n sameSet(a.blockObjects, b.blockObjects) &&\n sameSet(a.inlineObjects, b.inlineObjects)\n )\n}\n\nconst EMPTY_SET: ReadonlySet<string> = Object.freeze(new Set<string>())\n\nconst EMPTY: ApplicableSchema = Object.freeze({\n decorators: EMPTY_SET,\n annotations: EMPTY_SET,\n lists: EMPTY_SET,\n styles: EMPTY_SET,\n blockObjects: EMPTY_SET,\n inlineObjects: EMPTY_SET,\n})\n\ntype TextCategoryNames = Pick<\n ApplicableSchema,\n 'decorators' | 'annotations' | 'lists' | 'styles'\n>\n\nfunction textCategoryNames(schema: {\n decorators: ReadonlyArray<{name: string}>\n annotations: ReadonlyArray<{name: string}>\n lists: ReadonlyArray<{name: string}>\n styles: ReadonlyArray<{name: string}>\n}): TextCategoryNames {\n return {\n decorators: namesOfArray(schema.decorators),\n annotations: namesOfArray(schema.annotations),\n lists: namesOfArray(schema.lists),\n styles: namesOfArray(schema.styles),\n }\n}\n\nfunction unionTextCategories(\n a: TextCategoryNames,\n b: TextCategoryNames,\n): TextCategoryNames {\n return {\n decorators: unionSet(a.decorators, b.decorators),\n annotations: unionSet(a.annotations, b.annotations),\n lists: unionSet(a.lists, b.lists),\n styles: unionSet(a.styles, b.styles),\n }\n}\n\nfunction namesOfArray(\n entries: ReadonlyArray<{name: string}>,\n): ReadonlySet<string> {\n return new Set(entries.map((entry) => entry.name))\n}\n\nfunction unionSet(a: ReadonlySet<string>, b: ReadonlySet<string>): Set<string> {\n const result = new Set<string>(a)\n for (const item of b) {\n result.add(item)\n }\n return result\n}\n\nfunction sameSet(a: ReadonlySet<string>, b: ReadonlySet<string>) {\n if (a === b) {\n return true\n }\n if (a.size !== b.size) {\n return false\n }\n for (const item of a) {\n if (!b.has(item)) {\n return false\n }\n }\n return true\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 const firstStyle = firstTextBlock.node.style\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 (inScopeBlocks.every((block) => block.node.style === firstStyle)) {\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 {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 first 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 first block within that container (the first line). When\n * the focus is at root, or there is no selection, this returns the first\n * block in the document.\n *\n * @public\n */\nexport const getFirstBlock: 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 first = siblings.at(0)\n\n if (first) {\n return getBlock(snapshot, first.path)\n }\n }\n\n const node = snapshot.context.value[0]\n\n return node ? {node, path: [{_key: node._key}]} : undefined\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"],"names":["rangesOverlap","rangeA","rangeB","root","startA","endA","rangeEdges","startB","endB","comparePoints","getInline","snapshot","path","entry","getNode","isInline","isSpanNode","schema","context","node","isObject","getFocusChild","selection","focus","getFocusInlineObject","focusChild","undefined","getFocusSpan","isSpan","getFocusBlock","getEnclosingBlock","getFocusTextBlock","focusBlock","isTextBlock","getRootAcceptedTypes","Set","block","name","blockObjects","map","blockObject","getSelectedValue","startPoint","getSelectionStartPoint","endPoint","getSelectionEndPoint","sliceArray","blocks","value","pathPrefix","fieldNameInPrefix","startEdge","endEdge","parent","length","startIdx","resolveIndex","endIdx","lo","hi","loEdge","hiEdge","result","i","blockPath","_key","startPointForBlock","endPointForBlock","startInside","edgeIsInside","endInside","push","sliced","sliceBoundaryTextBlock","childInfo","getNodeChildren","innerSliced","children","fieldName","updatedBlock","edge","findBlockIndexForPoint","point","nodeSegmentIndex","segment","isKeyedSegment","findIndex","firstChild","lastChild","blockRelativeStart","stripPrefix","fallback","blockRelativeEnd","sliceBlocks","anchor","opts","slice","offset","text","getFragment","envelope","containers","rootAcceptedTypes","textBlockName","lastRootValid","lastRootValidPrefix","current","single","singlePath","container","resolveContainerAt","field","Array","isArray","childBlocks","every","_type","has","getSelectionEndBlock","getSelectionStartBlock","isOverlappingSelection","editorSelection","hasNode","isSelectionCollapsed","isSelectionCollapsedUtil","isSelectionExpanded","getSelectedBlocks","startRootKey","find","endRootKey","getBlock","getNodes","from","to","match","_","isSelectingEntireBlocks","backward","startBlock","endBlock","startBlockStartPoint","getBlockStartPoint","endBlockEndPoint","getBlockEndPoint","isEqualSelectionPoints","getNextSpan","getSibling","direction","getPreviousSpan","getSelectedChildren","options","filter","startChildKey","findLast","endChildKey","child","skip","getSelectedSpans","getMarkState","spanSelectionPoint","blockOffsetToSpanSelectionPoint","blockOffset","focusSpan","spanInfo","span","getParent","marks","decoratorNames","getPathSubSchema","decorators","decorator","markDefKeys","markDefs","markDef","candidateMarks","spanMarks","mark","add","candidate","isDecoratorSomewhere","some","includes","active","state","marksWithoutAnnotations","spanHasAnnotations","spanIsEmpty","atTheBeginningOfSpan","atTheEndOfSpan","previousSpan","nextSpan","nextSpanAnnotations","spanAnnotations","previousSpanHasAnnotations","previousSpanHasSameAnnotations","previousSpanHasSameAnnotation","previousSpanHasSameMarks","nextSpanSharesSomeAnnotations","previousMarks","getActiveAnnotationsMarks","getSelectedTextBlocks","getActiveDecorators","decoratorState","markState","selectedBlocks","size","activeDecorators","activeDecorator","isActiveAnnotation","annotation","mode","flatMap","selectionMarkDefs","activeAnnotations","getApplicableSchema","EMPTY","focusSub","insertion","namesOfArray","inlineObjects","EMPTY_SET","textBlocks","annotations","lists","styles","textApplicable","textCategoryNames","unionTextCategories","compareApplicableSchema","a","b","sameSet","Object","freeze","unionSet","entries","item","getActiveAnnotations","getActiveListItem","selectedTextBlocks","firstTextBlock","at","firstListItem","listItem","l","getActiveStyle","firstStyle","style","s","getNextInlineObject","getPreviousInlineObject","getSelectionText","selectedValue","collectText","getCaretWordSelection","focusTextBlock","selectionStartPoint","selectionStartOffset","spanSelectionPointToBlockOffset","selectionPoint","previousInlineObject","blockStartPoint","textDirectlyBefore","split","nextInlineObject","blockEndPoint","textDirectlyAfter","caretWordStartOffset","caretWordEndOffset","caretWordStartSelectionPoint","caretWordEndSelectionPoint","caretWordSelection","getFirstBlock","first","getChildren","parentPath","getFocusBlockObject","isTextBlockNode","isEditableContainer","getFocusListBlock","isListBlock","getLastBlock","last","getNextBlock","selectionEndBlock","next","getPreviousBlock","selectionStartBlock","previous","getSelectionEndChild","getSelectionStartChild","isActiveDecorator","inScopeSpans","d","isActiveListItem","isActiveStyle","isAtTheEndOfBlock","isAtTheStartOfBlock"],"mappings":";;;;AAWO,SAASA,cACdC,QACAC,QACAC,MACS;AACT,QAAM,CAACC,QAAQC,IAAI,IAAIC,WAAWL,QAAQE,IAAI,GACxC,CAACI,QAAQC,IAAI,IAAIF,WAAWJ,QAAQC,IAAI;AAC9C,SACEM,cAAcL,QAAQI,MAAML,IAAI,KAAK,KACrCM,cAAcF,QAAQF,MAAMF,IAAI,KAAK;AAEzC;ACPO,SAASO,UACdC,UACAC,MACuE;AACvE,QAAMC,QAAQC,QAAQH,UAAUC,IAAI;AAEpC,MAAI,EAAA,CAACC,SAAS,CAACE,SAASJ,UAAUE,MAAMD,IAAI,MAK1C,EAAA,CAACI,WAAW;AAAA,IAACC,QAAQN,SAASO,QAAQD;AAAAA,EAAAA,GAASJ,MAAMM,IAAI,KACzD,CAACC,SAAST,UAAUE,MAAMM,IAAI;AAKhC,WAAO;AAAA,MAACA,MAAMN,MAAMM;AAAAA,MAAMP,MAAMC,MAAMD;AAAAA,IAAAA;AACxC;ACtBO,MAAMS,gBAMRV,CAAAA,aAAa;AAChB,QAAMW,YAAYX,SAASO,QAAQI;AAEnC,MAAKA;AAIL,WAAOZ,UAAUC,UAAUW,UAAUC,MAAMX,IAAI;AACjD,GCbaY,uBAERb,CAAAA,aAAa;AAChB,QAAMc,aAAaJ,cAAcV,QAAQ;AAEzC,SAAOc,cAAc,CAACT,WAAWL,SAASO,SAASO,WAAWN,IAAI,IAC9D;AAAA,IA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