@portabletext/editor 7.10.19 → 7.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +57 -64
  2. package/lib/{behavior.types.action-CYtiRDck.d.ts → behavior.types.action-DH6ujvaH.d.ts} +409 -109
  3. package/lib/behavior.types.action-DH6ujvaH.d.ts.map +1 -0
  4. package/lib/{behavior.types.behavior-B_77VtQR.js → behavior.types.behavior-BxSLb73I.js} +5 -5
  5. package/lib/behavior.types.behavior-BxSLb73I.js.map +1 -0
  6. package/lib/behaviors/index.d.ts +1 -1
  7. package/lib/behaviors/index.js +1 -1
  8. package/lib/{get-container-BeXYKpoi.js → get-container-D1nM_ww9.js} +14 -14
  9. package/lib/get-container-D1nM_ww9.js.map +1 -0
  10. package/lib/{get-parent-51Kzgaf9.js → get-parent-Ci5241qs.js} +3 -3
  11. package/lib/get-parent-Ci5241qs.js.map +1 -0
  12. package/lib/{get-path-sub-schema--2I4NJbG.js → get-path-sub-schema-CZd9VcVM.js} +10 -10
  13. package/lib/get-path-sub-schema-CZd9VcVM.js.map +1 -0
  14. package/lib/index.d.ts +2 -2
  15. package/lib/index.js +294 -101
  16. package/lib/index.js.map +1 -1
  17. package/lib/plugins/index.d.ts +6 -6
  18. package/lib/plugins/index.js +5 -5
  19. package/lib/plugins/index.js.map +1 -1
  20. package/lib/{selector.is-at-the-start-of-block-gJIMWRpU.js → selector.is-at-the-start-of-block-D0boZbDu.js} +4 -4
  21. package/lib/selector.is-at-the-start-of-block-D0boZbDu.js.map +1 -0
  22. package/lib/selectors/index.d.ts +6 -6
  23. package/lib/selectors/index.js +6 -6
  24. package/lib/selectors/index.js.map +1 -1
  25. package/lib/traversal/index.d.ts +31 -31
  26. package/lib/traversal/index.js +4 -4
  27. package/lib/traversal/index.js.map +1 -1
  28. package/lib/{util.is-equal-selections-BF4WJtz5.js → util.is-equal-selections-N1hxVUbE.js} +2 -2
  29. package/lib/{util.is-equal-selections-BF4WJtz5.js.map → util.is-equal-selections-N1hxVUbE.js.map} +1 -1
  30. package/lib/{util.slice-blocks-DQnr9X2s.js → util.slice-blocks-B2fZcNok.js} +2 -2
  31. package/lib/{util.slice-blocks-DQnr9X2s.js.map → util.slice-blocks-B2fZcNok.js.map} +1 -1
  32. package/lib/utils/index.d.ts +1 -1
  33. package/lib/utils/index.js +3 -3
  34. package/package.json +3 -3
  35. package/lib/behavior.types.action-CYtiRDck.d.ts.map +0 -1
  36. package/lib/behavior.types.behavior-B_77VtQR.js.map +0 -1
  37. package/lib/get-container-BeXYKpoi.js.map +0 -1
  38. package/lib/get-parent-51Kzgaf9.js.map +0 -1
  39. package/lib/get-path-sub-schema--2I4NJbG.js.map +0 -1
  40. package/lib/selector.is-at-the-start-of-block-gJIMWRpU.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["EditorSelector","getPathSubSchema","getFocusBlock","getSelectedTextBlocks","ApplicableSchema","decorators","ReadonlySet","annotations","lists","styles","blockObjects","inlineObjects","getApplicableSchema","snapshot","context","selection","EMPTY","focusBlock","focusSub","path","undefined","insertion","namesOfArray","EMPTY_SET","textBlocks","length","textApplicable","textCategoryNames","i","unionTextCategories","compareApplicableSchema","a","b","sameSet","Object","freeze","Set","TextCategoryNames","Pick","schema","ReadonlyArray","name","unionSet","entries","map","entry","result","item","add","size","has","PortableTextBlock","EditorSelector","getEnclosingBlock","BlockPath","getAnchorBlock","node","path","snapshot","selection","context","undefined","anchor","PortableTextObject","PortableTextSpan","EditorSelector","getInline","ChildPath","getAnchorChild","node","path","snapshot","selection","context","undefined","anchor","isSpan","PortableTextSpan","EditorSelector","ChildPath","getAnchorChild","getAnchorSpan","node","path","snapshot","anchorChild","context","undefined","isTextBlock","PortableTextTextBlock","EditorSelector","BlockPath","getAnchorBlock","getAnchorTextBlock","node","path","snapshot","anchorBlock","context","undefined","EditorSelector","BlockOffset","spanSelectionPointToBlockOffset","getSelectionEndPoint","getSelectionStartPoint","getBlockOffsets","start","end","snapshot","context","selection","undefined","selectionStartPoint","selectionEndPoint","selectionPoint","PortableTextBlock","EditorSelector","parentPath","getChildren","getBlock","BlockPath","getFocusBlock","getFirstBlock","node","path","snapshot","focusBlock","siblings","first","at","context","value","_key","undefined","PortableTextObject","EditorSelector","parentPath","getChildren","isObject","ChildPath","isKeyedSegment","getSelectionEndPoint","getNextInlineObjects","Array","node","path","snapshot","point","endSegment","at","endKey","_key","undefined","children","inlineObjects","endFound","child","segment","childKey","push","PortableTextObject","EditorSelector","parentPath","getChildren","isObject","ChildPath","isKeyedSegment","getSelectionStartPoint","getPreviousInlineObjects","Array","node","path","snapshot","point","startSegment","at","startKey","_key","undefined","children","inlineObjects","child","segment","childKey","push","EditorSelector","EditorSelection","getSelection","snapshot","context","selection","EditorSelector","getBlockEndPoint","getSelectionEndPoint","getFocusTextBlock","getSelectionText","getBlockTextAfter","snapshot","context","selection","endPoint","block","anchor","focus","endOfBlock","EditorSelector","getBlockStartPoint","getSelectionStartPoint","getFocusTextBlock","getSelectionText","getBlockTextBefore","snapshot","context","selection","startPoint","block","anchor","focus","startOfBlock","PortableTextBlock","EditorSelector","getValue","Array","snapshot","context","value","EditorSelector","comparePoints","EditorSelectionPoint","getSelectionEndPoint","isPointAfterSelection","point","snapshot","context","selection","endPoint","EditorSelector","comparePoints","EditorSelectionPoint","getSelectionStartPoint","isPointBeforeSelection","point","snapshot","context","selection","startPoint"],"sources":["../../src/selectors/selector.get-applicable-schema.ts","../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-first-block.ts","../../src/selectors/selector.get-next-inline-objects.ts","../../src/selectors/selector.get-previous-inline-objects.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-text-after.ts","../../src/selectors/selector.get-text-before.ts","../../src/selectors/selector.get-value.ts","../../src/selectors/selector.is-point-after-selection.ts","../../src/selectors/selector.is-point-before-selection.ts"],"sourcesContent":["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 {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 anchor selection, resolved at any depth.\n *\n * @public\n */\nexport const getAnchorBlock: 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.anchor.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 anchor selection,\n * resolved at any depth.\n *\n * @public\n */\nexport const getAnchorChild: 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.anchor.path)\n}\n","import {isSpan, type PortableTextSpan} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * Returns the span containing the anchor selection, resolved at any depth.\n *\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n {node: PortableTextSpan; path: ChildPath} | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isSpan(snapshot.context, anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import {isTextBlock, type PortableTextTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * Returns the text block containing the anchor selection, resolved at any\n * depth.\n *\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport {spanSelectionPointToBlockOffset} from '../utils/util.block-offset'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = spanSelectionPointToBlockOffset({\n snapshot,\n selectionPoint: selectionStartPoint,\n })\n const end = spanSelectionPointToBlockOffset({\n snapshot,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : 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 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 {parentPath} from '../engine/path/parent-path'\nimport {getChildren} from '../traversal/get-children'\nimport {isObject} from '../traversal/is-object'\nimport type {ChildPath} from '../types/paths'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\n\n/**\n * Returns all inline objects after the selection end within the same text\n * block, resolved at any depth.\n *\n * @public\n */\nexport const getNextInlineObjects: EditorSelector<\n Array<{node: PortableTextObject; path: ChildPath}>\n> = (snapshot) => {\n const point = getSelectionEndPoint(snapshot)\n\n if (!point) {\n return []\n }\n\n const endSegment = point.path.at(-1)\n const endKey = isKeyedSegment(endSegment) ? endSegment._key : undefined\n\n if (!endKey) {\n return []\n }\n\n const children = getChildren(snapshot, parentPath(point.path))\n const inlineObjects: Array<{node: PortableTextObject; path: ChildPath}> = []\n let endFound = false\n\n for (const child of children) {\n const segment = child.path.at(-1)\n const childKey = isKeyedSegment(segment) ? segment._key : undefined\n\n if (childKey === endKey) {\n endFound = true\n continue\n }\n\n if (endFound && isObject(snapshot, child.node)) {\n inlineObjects.push({\n node: child.node,\n path: child.path,\n })\n }\n }\n\n return inlineObjects\n}\n","import type {PortableTextObject} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {parentPath} from '../engine/path/parent-path'\nimport {getChildren} from '../traversal/get-children'\nimport {isObject} from '../traversal/is-object'\nimport type {ChildPath} from '../types/paths'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * Returns all inline objects before the selection start within the same text\n * block, resolved at any depth.\n *\n * @public\n */\nexport const getPreviousInlineObjects: EditorSelector<\n Array<{node: PortableTextObject; path: ChildPath}>\n> = (snapshot) => {\n const point = getSelectionStartPoint(snapshot)\n\n if (!point) {\n return []\n }\n\n const startSegment = point.path.at(-1)\n const startKey = isKeyedSegment(startSegment) ? startSegment._key : undefined\n\n if (!startKey) {\n return []\n }\n\n const children = getChildren(snapshot, parentPath(point.path))\n const inlineObjects: Array<{node: PortableTextObject; path: ChildPath}> = []\n\n for (const child of children) {\n const segment = child.path.at(-1)\n const childKey = isKeyedSegment(segment) ? segment._key : undefined\n\n if (childKey === startKey) {\n break\n }\n\n if (isObject(snapshot, child.node)) {\n inlineObjects.push({\n node: child.node,\n path: child.path,\n })\n }\n }\n\n return inlineObjects\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockEndPoint} from '../utils/util.get-block-end-point'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @public\n */\nexport const getBlockTextAfter: EditorSelector<string> = (snapshot) => {\n if (!snapshot.context.selection) {\n return ''\n }\n\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n const block = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: endPoint,\n focus: endPoint,\n },\n },\n })\n\n if (!block) {\n return ''\n }\n\n const endOfBlock = getBlockEndPoint({\n context: snapshot.context,\n block,\n })\n\n return getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: endPoint,\n focus: endOfBlock,\n },\n },\n })\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @public\n */\nexport const getBlockTextBefore: EditorSelector<string> = (snapshot) => {\n if (!snapshot.context.selection) {\n return ''\n }\n\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n const block = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startPoint,\n focus: startPoint,\n },\n },\n })\n\n if (!block) {\n return ''\n }\n\n const startOfBlock = getBlockStartPoint({\n context: snapshot.context,\n block,\n })\n\n return getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startOfBlock,\n focus: startPoint,\n },\n },\n })\n}\n","import type {PortableTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {comparePoints} from '../traversal/compare-points'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\n\n/**\n * @public\n */\nexport function isPointAfterSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n\n return comparePoints(snapshot, point, endPoint) === 1\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {comparePoints} from '../traversal/compare-points'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\n\n/**\n * @public\n */\nexport function isPointBeforeSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n\n return comparePoints(snapshot, point, startPoint) === -1\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,MAAaY,uBACXC,aACG;CACH,IAAI,CAACA,SAASC,QAAQC,WACpB,OAAOC;CAGT,IAAMC,aAAaf,cAAcW,QAAQ,GACnCK,WAAWD,aACbhB,iBAAiBY,UAAUI,WAAWE,IAAI,IAC1CC,KAAAA,GAEEC,YAAYH,WACd;EACER,cAAcY,aAAaJ,SAASR,YAAY;EAChDC,eAAeW,aAAaJ,SAASP,aAAa;CACpD,IACA;EAACD,cAAca;EAAWZ,eAAeY;CAAS,GAEhDC,aAAarB,sBAAsBU,QAAQ;CAEjD,IAAIW,WAAWC,WAAW,GACxB,OAAO;EACLpB,YAAYkB;EACZhB,aAAagB;EACbf,OAAOe;EACPd,QAAQc;EACR,GAAGF;CACL;CAGF,IAAIK,iBAAiBC,kBACnB1B,iBAAiBY,UAAUW,WAAW,EAAE,CAAEL,IAAI,CAChD;CACA,KAAK,IAAIS,IAAI,GAAGA,IA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TG,QAAQF;IACRG,OAAOH;GACT;EACF;CACF,CAAC;CAED,IAAI,CAACC,OACH,OAAO;CAGT,IAAMG,eAAeZ,mBAAmB;EACtCM,SAASD,SAASC;EAClBG;CACF,CAAC;CAED,OAAON,iBAAiB;EACtB,GAAGE;EACHC,SAAS;GACP,GAAGD,SAASC;GACZC,WAAW;IACTG,QAAQE;IACRD,OAAOH;GACT;EACF;CACF,CAAC;AACH,GCvCaO,YACXE,aAEOA,SAASC,QAAQC;;;;ACD1B,SAAgBK,sBACdC,OACyB;CACzB,QAAQC,aAAa;EACnB,IAAI,CAACA,SAASC,QAAQC,WACpB,OAAO;EAGT,IAAMC,WAAWN,uBAAqBG,SAASC,QAAQC,SAAS;EAEhE,OAAOP,cAAcK,UAAUD,OAAOI,QAAQ,MAAM;CACtD;AACF;;;;ACZA,SAAgBK,uBACdC,OACyB;CACzB,QAAQC,aAAa;EACnB,IAAI,CAACA,SAASC,QAAQC,WACpB,OAAO;EAGT,IAAMC,aAAaN,yBAAuBG,SAASC,QAAQC,SAAS;EAEpE,OAAOP,cAAcK,UAAUD,OAAOI,UAAU,MAAM;CACxD;AACF"}
1
+ {"version":3,"file":"index.js","names":["EditorSelector","getPathSubSchema","getFocusBlock","getSelectedTextBlocks","ApplicableSchema","decorators","ReadonlySet","annotations","lists","styles","blockObjects","inlineObjects","getApplicableSchema","snapshot","context","selection","EMPTY","focusBlock","focusSub","path","undefined","insertion","namesOfArray","EMPTY_SET","textBlocks","length","textApplicable","textCategoryNames","i","unionTextCategories","compareApplicableSchema","a","b","sameSet","Object","freeze","Set","TextCategoryNames","Pick","schema","ReadonlyArray","name","unionSet","entries","map","entry","result","item","add","size","has","PortableTextBlock","EditorSelector","getEnclosingBlock","BlockPath","getAnchorBlock","node","path","snapshot","selection","context","undefined","anchor","PortableTextObject","PortableTextSpan","EditorSelector","getInline","ChildPath","getAnchorChild","node","path","snapshot","selection","context","undefined","anchor","isSpan","PortableTextSpan","EditorSelector","ChildPath","getAnchorChild","getAnchorSpan","node","path","snapshot","anchorChild","context","undefined","isTextBlock","PortableTextTextBlock","EditorSelector","BlockPath","getAnchorBlock","getAnchorTextBlock","node","path","snapshot","anchorBlock","context","undefined","EditorSelector","BlockOffset","spanSelectionPointToBlockOffset","getSelectionEndPoint","getSelectionStartPoint","getBlockOffsets","start","end","snapshot","context","selection","undefined","selectionStartPoint","selectionEndPoint","selectionPoint","PortableTextBlock","EditorSelector","parentPath","getChildren","getBlock","BlockPath","getFocusBlock","getFirstBlock","node","path","snapshot","focusBlock","siblings","first","at","context","value","_key","undefined","PortableTextObject","EditorSelector","parentPath","getChildren","isObject","ChildPath","isKeyedSegment","getSelectionEndPoint","getNextInlineObjects","Array","node","path","snapshot","point","endSegment","at","endKey","_key","undefined","children","inlineObjects","endFound","child","segment","childKey","push","PortableTextObject","EditorSelector","parentPath","getChildren","isObject","ChildPath","isKeyedSegment","getSelectionStartPoint","getPreviousInlineObjects","Array","node","path","snapshot","point","startSegment","at","startKey","_key","undefined","children","inlineObjects","child","segment","childKey","push","EditorSelector","EditorSelection","getSelection","snapshot","context","selection","EditorSelector","getBlockEndPoint","getSelectionEndPoint","getFocusTextBlock","getSelectionText","getBlockTextAfter","snapshot","context","selection","endPoint","block","anchor","focus","endOfBlock","EditorSelector","getBlockStartPoint","getSelectionStartPoint","getFocusTextBlock","getSelectionText","getBlockTextBefore","snapshot","context","selection","startPoint","block","anchor","focus","startOfBlock","PortableTextBlock","EditorSelector","getValue","Array","snapshot","context","value","EditorSelector","comparePoints","EditorSelectionPoint","getSelectionEndPoint","isPointAfterSelection","point","snapshot","context","selection","endPoint","EditorSelector","comparePoints","EditorSelectionPoint","getSelectionStartPoint","isPointBeforeSelection","point","snapshot","context","selection","startPoint"],"sources":["../../src/selectors/selector.get-applicable-schema.ts","../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-first-block.ts","../../src/selectors/selector.get-next-inline-objects.ts","../../src/selectors/selector.get-previous-inline-objects.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-text-after.ts","../../src/selectors/selector.get-text-before.ts","../../src/selectors/selector.get-value.ts","../../src/selectors/selector.is-point-after-selection.ts","../../src/selectors/selector.is-point-before-selection.ts"],"sourcesContent":["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 * @public\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 * @public\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 * @public\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 {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 anchor selection, resolved at any depth.\n *\n * @public\n */\nexport const getAnchorBlock: 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.anchor.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 anchor selection,\n * resolved at any depth.\n *\n * @public\n */\nexport const getAnchorChild: 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.anchor.path)\n}\n","import {isSpan, type PortableTextSpan} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\n/**\n * Returns the span containing the anchor selection, resolved at any depth.\n *\n * @public\n */\nexport const getAnchorSpan: EditorSelector<\n {node: PortableTextSpan; path: ChildPath} | undefined\n> = (snapshot) => {\n const anchorChild = getAnchorChild(snapshot)\n\n return anchorChild && isSpan(snapshot.context, anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import {isTextBlock, type PortableTextTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\n/**\n * Returns the text block containing the anchor selection, resolved at any\n * depth.\n *\n * @public\n */\nexport const getAnchorTextBlock: EditorSelector<\n {node: PortableTextTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n const anchorBlock = getAnchorBlock(snapshot)\n\n return anchorBlock && isTextBlock(snapshot.context, anchorBlock.node)\n ? {node: anchorBlock.node, path: anchorBlock.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport {spanSelectionPointToBlockOffset} from '../utils/util.block-offset'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * @public\n */\nexport const getBlockOffsets: EditorSelector<\n {start: BlockOffset; end: BlockOffset} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const selectionStartPoint = getSelectionStartPoint(snapshot)\n const selectionEndPoint = getSelectionEndPoint(snapshot)\n\n if (!selectionStartPoint || !selectionEndPoint) {\n return undefined\n }\n\n const start = spanSelectionPointToBlockOffset({\n snapshot,\n selectionPoint: selectionStartPoint,\n })\n const end = spanSelectionPointToBlockOffset({\n snapshot,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : 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 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 {parentPath} from '../engine/path/parent-path'\nimport {getChildren} from '../traversal/get-children'\nimport {isObject} from '../traversal/is-object'\nimport type {ChildPath} from '../types/paths'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\n\n/**\n * Returns all inline objects after the selection end within the same text\n * block, resolved at any depth.\n *\n * @public\n */\nexport const getNextInlineObjects: EditorSelector<\n Array<{node: PortableTextObject; path: ChildPath}>\n> = (snapshot) => {\n const point = getSelectionEndPoint(snapshot)\n\n if (!point) {\n return []\n }\n\n const endSegment = point.path.at(-1)\n const endKey = isKeyedSegment(endSegment) ? endSegment._key : undefined\n\n if (!endKey) {\n return []\n }\n\n const children = getChildren(snapshot, parentPath(point.path))\n const inlineObjects: Array<{node: PortableTextObject; path: ChildPath}> = []\n let endFound = false\n\n for (const child of children) {\n const segment = child.path.at(-1)\n const childKey = isKeyedSegment(segment) ? segment._key : undefined\n\n if (childKey === endKey) {\n endFound = true\n continue\n }\n\n if (endFound && isObject(snapshot, child.node)) {\n inlineObjects.push({\n node: child.node,\n path: child.path,\n })\n }\n }\n\n return inlineObjects\n}\n","import type {PortableTextObject} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {parentPath} from '../engine/path/parent-path'\nimport {getChildren} from '../traversal/get-children'\nimport {isObject} from '../traversal/is-object'\nimport type {ChildPath} from '../types/paths'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\n\n/**\n * Returns all inline objects before the selection start within the same text\n * block, resolved at any depth.\n *\n * @public\n */\nexport const getPreviousInlineObjects: EditorSelector<\n Array<{node: PortableTextObject; path: ChildPath}>\n> = (snapshot) => {\n const point = getSelectionStartPoint(snapshot)\n\n if (!point) {\n return []\n }\n\n const startSegment = point.path.at(-1)\n const startKey = isKeyedSegment(startSegment) ? startSegment._key : undefined\n\n if (!startKey) {\n return []\n }\n\n const children = getChildren(snapshot, parentPath(point.path))\n const inlineObjects: Array<{node: PortableTextObject; path: ChildPath}> = []\n\n for (const child of children) {\n const segment = child.path.at(-1)\n const childKey = isKeyedSegment(segment) ? segment._key : undefined\n\n if (childKey === startKey) {\n break\n }\n\n if (isObject(snapshot, child.node)) {\n inlineObjects.push({\n node: child.node,\n path: child.path,\n })\n }\n }\n\n return inlineObjects\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockEndPoint} from '../utils/util.get-block-end-point'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @public\n */\nexport const getBlockTextAfter: EditorSelector<string> = (snapshot) => {\n if (!snapshot.context.selection) {\n return ''\n }\n\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n const block = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: endPoint,\n focus: endPoint,\n },\n },\n })\n\n if (!block) {\n return ''\n }\n\n const endOfBlock = getBlockEndPoint({\n context: snapshot.context,\n block,\n })\n\n return getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: endPoint,\n focus: endOfBlock,\n },\n },\n })\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockStartPoint} from '../utils/util.get-block-start-point'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\nimport {getSelectionText} from './selector.get-selection-text'\n\n/**\n * @public\n */\nexport const getBlockTextBefore: EditorSelector<string> = (snapshot) => {\n if (!snapshot.context.selection) {\n return ''\n }\n\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n const block = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startPoint,\n focus: startPoint,\n },\n },\n })\n\n if (!block) {\n return ''\n }\n\n const startOfBlock = getBlockStartPoint({\n context: snapshot.context,\n block,\n })\n\n return getSelectionText({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startOfBlock,\n focus: startPoint,\n },\n },\n })\n}\n","import type {PortableTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getValue: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return snapshot.context.value\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {comparePoints} from '../traversal/compare-points'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\n\n/**\n * @public\n */\nexport function isPointAfterSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n\n return comparePoints(snapshot, point, endPoint) === 1\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {comparePoints} from '../traversal/compare-points'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\n\n/**\n * @public\n */\nexport function isPointBeforeSelection(\n point: EditorSelectionPoint,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n\n return comparePoints(snapshot, point, startPoint) === -1\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,MAAaY,uBACXC,aACG;CACH,IAAI,CAACA,SAASC,QAAQC,WACpB,OAAOC;CAGT,IAAMC,aAAaf,cAAcW,QAAQ,GACnCK,WAAWD,aACbhB,iBAAiBY,UAAUI,WAAWE,IAAI,IAC1CC,KAAAA,GAEEC,YAAYH,WACd;EACER,cAAcY,aAAaJ,SAASR,YAAY;EAChDC,eAAeW,aAAaJ,SAASP,aAAa;CACpD,IACA;EAACD,cAAca;EAAWZ,eAAeY;CAAS,GAEhDC,aAAarB,sBAAsBU,QAAQ;CAEjD,IAAIW,WAAWC,WAAW,GACxB,OAAO;EACLpB,YAA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;CACtE,IAAI,CAACA,SAASC,QAAQC,WACpB,OAAO;CAGT,IAAMC,aAAaP,yBAAuBI,SAASC,QAAQC,SAAS,GAC9DE,QAAQP,kBAAkB;EAC9B,GAAGG;EACHC,SAAS;GACP,GAAGD,SAASC;GACZC,WAAW;IACTG,QAAQF;IACRG,OAAOH;GACT;EACF;CACF,CAAC;CAED,IAAI,CAACC,OACH,OAAO;CAGT,IAAMG,eAAeZ,mBAAmB;EACtCM,SAASD,SAASC;EAClBG;CACF,CAAC;CAED,OAAON,iBAAiB;EACtB,GAAGE;EACHC,SAAS;GACP,GAAGD,SAASC;GACZC,WAAW;IACTG,QAAQE;IACRD,OAAOH;GACT;EACF;CACF,CAAC;AACH,GCvCaO,YACXE,aAEOA,SAASC,QAAQC;;;;ACD1B,SAAgBK,sBACdC,OACyB;CACzB,QAAQC,aAAa;EACnB,IAAI,CAACA,SAASC,QAAQC,WACpB,OAAO;EAGT,IAAMC,WAAWN,uBAAqBG,SAASC,QAAQC,SAAS;EAEhE,OAAOP,cAAcK,UAAUD,OAAOI,QAAQ,MAAM;CACtD;AACF;;;;ACZA,SAAgBK,uBACdC,OACyB;CACzB,QAAQC,aAAa;EACnB,IAAI,CAACA,SAASC,QAAQC,WACpB,OAAO;EAGT,IAAMC,aAAaN,yBAAuBG,SAASC,QAAQC,SAAS;EAEpE,OAAOP,cAAcK,UAAUD,OAAOI,UAAU,MAAM;CACxD;AACF"}
@@ -1,4 +1,4 @@
1
- import { It as Containers, Nt as TraversalSnapshot, Pt as Node, Rt as RegisteredContainer, lt as EditorSelection, pn as Path, ut as EditorSelectionPoint } from "../behavior.types.action-CYtiRDck.js";
1
+ import { Ft as Node, Lt as Containers, Pt as TraversalSnapshot, Sn as Path, dt as EditorSelectionPoint, ut as EditorSelection, zt as RegisteredContainer } from "../behavior.types.action-DH6ujvaH.js";
2
2
  import { PortableTextBlock, PortableTextObject, PortableTextSpan, PortableTextTextBlock, Schema } from "@portabletext/schema";
3
3
  /**
4
4
  * Find an ancestor of the node at a given path that matches a predicate.
@@ -9,7 +9,7 @@ import { PortableTextBlock, PortableTextObject, PortableTextSpan, PortableTextTe
9
9
  *
10
10
  * When `match` is a type predicate, the returned `node` narrows to that type.
11
11
  *
12
- * @beta
12
+ * @public
13
13
  */
14
14
  declare function getAncestor<TMatch extends PortableTextBlock>(snapshot: TraversalSnapshot, path: Path, options: {
15
15
  match: (node: PortableTextBlock, path: Path) => node is TMatch;
@@ -19,7 +19,7 @@ declare function getAncestor<TMatch extends PortableTextBlock>(snapshot: Travers
19
19
  path: Path;
20
20
  } | undefined;
21
21
  /**
22
- * @beta
22
+ * @public
23
23
  */
24
24
  declare function getAncestor(snapshot: TraversalSnapshot, path: Path, options: {
25
25
  match: (node: PortableTextBlock, path: Path) => boolean;
@@ -42,7 +42,7 @@ declare function getAncestor(snapshot: TraversalSnapshot, path: Path, options: {
42
42
  * Every ancestor is a `PortableTextBlock`: only text blocks and object
43
43
  * nodes can contain children.
44
44
  *
45
- * @beta
45
+ * @public
46
46
  */
47
47
  declare function getAncestors(snapshot: TraversalSnapshot, path: Path): Array<{
48
48
  node: PortableTextBlock;
@@ -57,7 +57,7 @@ declare function getAncestors(snapshot: TraversalSnapshot, path: Path): Array<{
57
57
  * `[..., {_key: block}, 'markDefs', {_key: annotation}, ...]` to the
58
58
  * annotation node on the enclosing text block.
59
59
  *
60
- * @beta
60
+ * @public
61
61
  */
62
62
  declare function getAnnotation(snapshot: TraversalSnapshot, path: Path): {
63
63
  node: PortableTextObject;
@@ -71,7 +71,7 @@ declare function getAnnotation(snapshot: TraversalSnapshot, path: Path): {
71
71
  * (spans and inline objects) are not blocks. Children of containers are
72
72
  * blocks within that container.
73
73
  *
74
- * @beta
74
+ * @public
75
75
  */
76
76
  declare function isBlock(snapshot: TraversalSnapshot, path: Path): boolean;
77
77
  /**
@@ -80,7 +80,7 @@ declare function isBlock(snapshot: TraversalSnapshot, path: Path): boolean;
80
80
  * Returns the node narrowed to PortableTextBlock, or undefined if the node
81
81
  * doesn't exist or is not a block.
82
82
  *
83
- * @beta
83
+ * @public
84
84
  */
85
85
  declare function getBlock(snapshot: TraversalSnapshot, path: Path): {
86
86
  node: PortableTextBlock;
@@ -89,7 +89,7 @@ declare function getBlock(snapshot: TraversalSnapshot, path: Path): {
89
89
  /**
90
90
  * Get the children of a node at a given path.
91
91
  *
92
- * @beta
92
+ * @public
93
93
  */
94
94
  declare function getChildren(snapshot: TraversalSnapshot, path: Path): Array<{
95
95
  node: Node;
@@ -98,7 +98,7 @@ declare function getChildren(snapshot: TraversalSnapshot, path: Path): Array<{
98
98
  /**
99
99
  * Get the registered editable container at a given path.
100
100
  *
101
- * @beta
101
+ * @public
102
102
  */
103
103
  declare function getContainer(snapshot: TraversalSnapshot, path: Path): {
104
104
  node: Node;
@@ -141,7 +141,7 @@ declare function getContainerChildren(containers: Containers, node: Node, parent
141
141
  * ancestor that matches, falling back to the node at the path only if no
142
142
  * ancestor does.
143
143
  *
144
- * @beta
144
+ * @public
145
145
  */
146
146
  declare function getEnclosingBlock<TMatch extends PortableTextBlock>(snapshot: TraversalSnapshot, path: Path, options: {
147
147
  match: (node: PortableTextBlock, path: Path) => node is TMatch;
@@ -151,7 +151,7 @@ declare function getEnclosingBlock<TMatch extends PortableTextBlock>(snapshot: T
151
151
  path: Path;
152
152
  } | undefined;
153
153
  /**
154
- * @beta
154
+ * @public
155
155
  */
156
156
  declare function getEnclosingBlock(snapshot: TraversalSnapshot, path: Path, options?: {
157
157
  match?: (node: PortableTextBlock, path: Path) => boolean;
@@ -163,7 +163,7 @@ declare function getEnclosingBlock(snapshot: TraversalSnapshot, path: Path, opti
163
163
  /**
164
164
  * Get the first child of a node at a given path.
165
165
  *
166
- * @beta
166
+ * @public
167
167
  */
168
168
  declare function getFirstChild(snapshot: TraversalSnapshot, path: Path): {
169
169
  node: Node;
@@ -172,7 +172,7 @@ declare function getFirstChild(snapshot: TraversalSnapshot, path: Path): {
172
172
  /**
173
173
  * Get the last child of a node at a given path.
174
174
  *
175
- * @beta
175
+ * @public
176
176
  */
177
177
  declare function getLastChild(snapshot: TraversalSnapshot, path: Path): {
178
178
  node: Node;
@@ -183,7 +183,7 @@ declare function getLastChild(snapshot: TraversalSnapshot, path: Path): {
183
183
  * start or end edge. A leaf is any node that has no children according to the
184
184
  * traversal context.
185
185
  *
186
- * @beta
186
+ * @public
187
187
  */
188
188
  declare function getLeaf(snapshot: TraversalSnapshot, path: Path, options: {
189
189
  edge: 'start' | 'end';
@@ -212,7 +212,7 @@ declare function getLeaf(snapshot: TraversalSnapshot, path: Path, options: {
212
212
  * it, so `getNode` resolves an annotation path to the enclosing text
213
213
  * block. Use `getAnnotation` to resolve the annotation itself.
214
214
  *
215
- * @beta
215
+ * @public
216
216
  */
217
217
  declare function getNode(snapshot: TraversalSnapshot, path: Path): {
218
218
  node: Node;
@@ -227,7 +227,7 @@ declare function getNode(snapshot: TraversalSnapshot, path: Path): {
227
227
  * When `match` is provided and the parent does not satisfy it, returns
228
228
  * `undefined`.
229
229
  *
230
- * @beta
230
+ * @public
231
231
  */
232
232
  declare function getParent<TMatch extends PortableTextBlock>(snapshot: TraversalSnapshot, path: Path, options: {
233
233
  match: (node: PortableTextBlock, path: Path) => node is TMatch;
@@ -236,7 +236,7 @@ declare function getParent<TMatch extends PortableTextBlock>(snapshot: Traversal
236
236
  path: Path;
237
237
  } | undefined;
238
238
  /**
239
- * @beta
239
+ * @public
240
240
  */
241
241
  declare function getParent(snapshot: TraversalSnapshot, path: Path, options?: {
242
242
  match?: (node: PortableTextBlock, path: Path) => boolean;
@@ -252,7 +252,7 @@ declare function getParent(snapshot: TraversalSnapshot, path: Path, options?: {
252
252
  * container, walks ancestors to find the nearest container and returns the
253
253
  * sub-schema derived from its `of` declaration.
254
254
  *
255
- * @beta
255
+ * @public
256
256
  */
257
257
  declare function getPathSubSchema(snapshot: TraversalSnapshot, path: Path): Schema;
258
258
  /**
@@ -264,7 +264,7 @@ declare function getPathSubSchema(snapshot: TraversalSnapshot, path: Path): Sche
264
264
  *
265
265
  * When `match` is a type predicate, the returned `node` narrows to that type.
266
266
  *
267
- * @beta
267
+ * @public
268
268
  */
269
269
  declare function getSibling<TMatch extends Node>(snapshot: TraversalSnapshot, path: Path, options: {
270
270
  direction: 'next' | 'previous';
@@ -274,7 +274,7 @@ declare function getSibling<TMatch extends Node>(snapshot: TraversalSnapshot, pa
274
274
  path: Path;
275
275
  } | undefined;
276
276
  /**
277
- * @beta
277
+ * @public
278
278
  */
279
279
  declare function getSibling(snapshot: TraversalSnapshot, path: Path, options: {
280
280
  direction: 'next' | 'previous';
@@ -293,14 +293,14 @@ declare function getSibling(snapshot: TraversalSnapshot, path: Path, options: {
293
293
  * Compares the two points by document order, resolved at any depth. When
294
294
  * the paths are equal, compares offsets.
295
295
  *
296
- * @beta
296
+ * @public
297
297
  */
298
298
  declare function comparePoints(snapshot: TraversalSnapshot, pointA: EditorSelectionPoint, pointB: EditorSelectionPoint): -1 | 0 | 1;
299
299
  /**
300
300
  * Returns true if `ancestor` is equal to `descendant`, or if `descendant`
301
301
  * lives anywhere inside `ancestor`'s subtree.
302
302
  *
303
- * @beta
303
+ * @public
304
304
  */
305
305
  declare function pathContains(ancestor: Path, descendant: Path): boolean;
306
306
  /**
@@ -319,13 +319,13 @@ declare function pathContains(ancestor: Path, descendant: Path): boolean;
319
319
  *
320
320
  * Returns `false` when either `range` or `target` is `null`.
321
321
  *
322
- * @beta
322
+ * @public
323
323
  */
324
324
  declare function rangeIntersects(snapshot: TraversalSnapshot, range: EditorSelection, target: Path | EditorSelectionPoint | EditorSelection): boolean;
325
325
  /**
326
326
  * Get the span node at a given path.
327
327
  *
328
- * @beta
328
+ * @public
329
329
  */
330
330
  declare function getSpan(snapshot: TraversalSnapshot, path: Path): {
331
331
  node: PortableTextSpan;
@@ -334,13 +334,13 @@ declare function getSpan(snapshot: TraversalSnapshot, path: Path): {
334
334
  /**
335
335
  * Get the concatenated text content of the node at a given path.
336
336
  *
337
- * @beta
337
+ * @public
338
338
  */
339
339
  declare function getText(snapshot: TraversalSnapshot, path: Path): string | undefined;
340
340
  /**
341
341
  * Get the text block node at a given path.
342
342
  *
343
- * @beta
343
+ * @public
344
344
  */
345
345
  declare function getTextBlock(snapshot: TraversalSnapshot, path: Path): {
346
346
  node: PortableTextTextBlock;
@@ -368,13 +368,13 @@ declare function getTextBlock(snapshot: TraversalSnapshot, path: Path): {
368
368
  * range) to determine which of the union's members are applicable at the
369
369
  * current selection.
370
370
  *
371
- * @beta
371
+ * @public
372
372
  */
373
373
  declare function getUnionSchema(schema: Schema, containers: Containers): Schema;
374
374
  /**
375
375
  * Check if a node exists at a given path.
376
376
  *
377
- * @beta
377
+ * @public
378
378
  */
379
379
  declare function hasNode(snapshot: TraversalSnapshot, path: Path): boolean;
380
380
  /**
@@ -383,7 +383,7 @@ declare function hasNode(snapshot: TraversalSnapshot, path: Path): boolean;
383
383
  * A node is inline if its parent is a text block. This is the inverse of
384
384
  * `isBlock`. Top-level nodes are never inline.
385
385
  *
386
- * @beta
386
+ * @public
387
387
  */
388
388
  declare function isInline(snapshot: TraversalSnapshot, path: Path): boolean;
389
389
  /**
@@ -392,13 +392,13 @@ declare function isInline(snapshot: TraversalSnapshot, path: Path): boolean;
392
392
  * Returns true for block objects and inline objects that don't have
393
393
  * registered editable content (containers).
394
394
  *
395
- * @beta
395
+ * @public
396
396
  */
397
397
  declare function isLeafObject(snapshot: TraversalSnapshot, node: unknown, path: Path): node is PortableTextObject;
398
398
  /**
399
399
  * Check if a node is an object node (not a text block or span).
400
400
  *
401
- * @beta
401
+ * @public
402
402
  */
403
403
  declare function isObject(snapshot: TraversalSnapshot, node: unknown): node is PortableTextObject;
404
404
  export { comparePoints, getAncestor, getAncestors, getAnnotation, getBlock, getChildren, getContainer, getContainerChildren, getEnclosingBlock, getFirstChild, getLastChild, getLeaf, getNode, getParent, getPathSubSchema, getSibling, getSpan, getText, getTextBlock, getUnionSchema, hasNode, isBlock, isInline, isLeafObject, isObject, pathContains, rangeIntersects };
@@ -1,6 +1,6 @@
1
- import { i as getChildren, o as getContainerChildren, r as getNode, t as getParent, u as isKeyedSegment } from "../get-parent-51Kzgaf9.js";
2
- import { C as getAncestors, S as hasNode, a as isInline, i as getEnclosingBlock, l as getSibling, o as getBlock, r as comparePoints, s as isBlock, t as getPathSubSchema, y as isObject } from "../get-path-sub-schema--2I4NJbG.js";
3
- import { _ as getAncestor, a as getTextBlock, c as pathContains, g as isLeafObject, h as getLeaf, i as getFirstChild, l as getSpan, n as getUnionSchema, o as rangeIntersects, r as getLastChild, t as getContainer, u as getText } from "../get-container-BeXYKpoi.js";
1
+ import { i as getChildren, o as getContainerChildren, r as getNode, t as getParent, u as isKeyedSegment } from "../get-parent-Ci5241qs.js";
2
+ import { C as getAncestors, S as hasNode, a as isInline, i as getEnclosingBlock, l as getSibling, o as getBlock, r as comparePoints, s as isBlock, t as getPathSubSchema, y as isObject } from "../get-path-sub-schema-CZd9VcVM.js";
3
+ import { _ as getAncestor, a as getTextBlock, c as pathContains, g as isLeafObject, h as getLeaf, i as getFirstChild, l as getSpan, n as getUnionSchema, o as rangeIntersects, r as getLastChild, t as getContainer, u as getText } from "../get-container-D1nM_ww9.js";
4
4
  /**
5
5
  * Get the annotation at a given path.
6
6
  *
@@ -10,7 +10,7 @@ import { _ as getAncestor, a as getTextBlock, c as pathContains, g as isLeafObje
10
10
  * `[..., {_key: block}, 'markDefs', {_key: annotation}, ...]` to the
11
11
  * annotation node on the enclosing text block.
12
12
  *
13
- * @beta
13
+ * @public
14
14
  */
15
15
  function getAnnotation(snapshot, path) {
16
16
  for (let i = 0; i < path.length - 1; i++) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["PortableTextObject","Path","isKeyedSegment","getTextBlock","TraversalSnapshot","getAnnotation","snapshot","path","node","i","length","annotationSegment","block","slice","annotation","markDefs","find","markDef","_key","undefined"],"sources":["../../src/traversal/get-annotation.ts"],"sourcesContent":["import type {PortableTextObject} from '@portabletext/schema'\nimport type {Path} from '../engine/interfaces/path'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {getTextBlock} from './get-text-block'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Get the annotation at a given path.\n *\n * Annotations live in `markDefs` on a text block, alongside `children`\n * rather than inside it, so they aren't reachable through `getNode`.\n * `getAnnotation` resolves a path of the shape\n * `[..., {_key: block}, 'markDefs', {_key: annotation}, ...]` to the\n * annotation node on the enclosing text block.\n *\n * @beta\n */\nexport function getAnnotation(\n snapshot: TraversalSnapshot,\n path: Path,\n): {node: PortableTextObject; path: Path} | undefined {\n // A path may cross multiple `'markDefs'` segments if a consumer\n // registers a container whose array field is named `markDefs`. Try\n // each position and pick the one whose prefix resolves to a text\n // block.\n for (let i = 0; i < path.length - 1; i++) {\n if (path[i] !== 'markDefs') {\n continue\n }\n\n const annotationSegment = path[i + 1]\n\n if (!isKeyedSegment(annotationSegment)) {\n continue\n }\n\n const block = getTextBlock(snapshot, path.slice(0, i))\n\n if (!block) {\n continue\n }\n\n const annotation = block.node.markDefs?.find(\n (markDef) => markDef._key === annotationSegment._key,\n )\n\n if (!annotation) {\n return undefined\n }\n\n return {\n node: annotation,\n path: [...block.path, 'markDefs', {_key: annotation._key}],\n }\n }\n\n return undefined\n}\n"],"mappings":";;;;;;;;;;;;;;AAiBA,SAAgBK,cACdC,UACAC,MACoD;CAKpD,KAAK,IAAIE,IAAI,GAAGA,IAAIF,KAAKG,SAAS,GAAGD,KAAK;EACxC,IAAIF,KAAKE,OAAO,YACd;EAGF,IAAME,oBAAoBJ,KAAKE,IAAI;EAEnC,IAAI,CAACP,eAAeS,iBAAiB,GACnC;EAGF,IAAMC,QAAQT,aAAaG,UAAUC,KAAKM,MAAM,GAAGJ,CAAC,CAAC;EAErD,IAAI,CAACG,OACH;EAGF,IAAME,aAAaF,MAAMJ,KAAKO,UAAUC,MACrCC,YAAYA,QAAQC,SAASP,kBAAkBO,IAClD;EAMA,OAJKJ,aAIE;GACLN,MAAMM;GACNP,MAAM;IAAC,GAAGK,MAAML;IAAM;IAAY,EAACW,MAAMJ,WAAWI,KAAI;GAAC;EAC3D,IANE;CAOJ;AAGF"}
1
+ {"version":3,"file":"index.js","names":["PortableTextObject","Path","isKeyedSegment","getTextBlock","TraversalSnapshot","getAnnotation","snapshot","path","node","i","length","annotationSegment","block","slice","annotation","markDefs","find","markDef","_key","undefined"],"sources":["../../src/traversal/get-annotation.ts"],"sourcesContent":["import type {PortableTextObject} from '@portabletext/schema'\nimport type {Path} from '../engine/interfaces/path'\nimport {isKeyedSegment} from '../utils/util.is-keyed-segment'\nimport {getTextBlock} from './get-text-block'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Get the annotation at a given path.\n *\n * Annotations live in `markDefs` on a text block, alongside `children`\n * rather than inside it, so they aren't reachable through `getNode`.\n * `getAnnotation` resolves a path of the shape\n * `[..., {_key: block}, 'markDefs', {_key: annotation}, ...]` to the\n * annotation node on the enclosing text block.\n *\n * @public\n */\nexport function getAnnotation(\n snapshot: TraversalSnapshot,\n path: Path,\n): {node: PortableTextObject; path: Path} | undefined {\n // A path may cross multiple `'markDefs'` segments if a consumer\n // registers a container whose array field is named `markDefs`. Try\n // each position and pick the one whose prefix resolves to a text\n // block.\n for (let i = 0; i < path.length - 1; i++) {\n if (path[i] !== 'markDefs') {\n continue\n }\n\n const annotationSegment = path[i + 1]\n\n if (!isKeyedSegment(annotationSegment)) {\n continue\n }\n\n const block = getTextBlock(snapshot, path.slice(0, i))\n\n if (!block) {\n continue\n }\n\n const annotation = block.node.markDefs?.find(\n (markDef) => markDef._key === annotationSegment._key,\n )\n\n if (!annotation) {\n return undefined\n }\n\n return {\n node: annotation,\n path: [...block.path, 'markDefs', {_key: annotation._key}],\n }\n }\n\n return undefined\n}\n"],"mappings":";;;;;;;;;;;;;;AAiBA,SAAgBK,cACdC,UACAC,MACoD;CAKpD,KAAK,IAAIE,IAAI,GAAGA,IAAIF,KAAKG,SAAS,GAAGD,KAAK;EACxC,IAAIF,KAAKE,OAAO,YACd;EAGF,IAAME,oBAAoBJ,KAAKE,IAAI;EAEnC,IAAI,CAACP,eAAeS,iBAAiB,GACnC;EAGF,IAAMC,QAAQT,aAAaG,UAAUC,KAAKM,MAAM,GAAGJ,CAAC,CAAC;EAErD,IAAI,CAACG,OACH;EAGF,IAAME,aAAaF,MAAMJ,KAAKO,UAAUC,MACrCC,YAAYA,QAAQC,SAASP,kBAAkBO,IAClD;EAMA,OAJKJ,aAIE;GACLN,MAAMM;GACNP,MAAM;IAAC,GAAGK,MAAML;IAAM;IAAY,EAACW,MAAMJ,WAAWI,KAAI;GAAC;EAC3D,IANE;CAOJ;AAGF"}
@@ -1,4 +1,4 @@
1
- import { g as isEqualSelectionPoints } from "./util.slice-blocks-DQnr9X2s.js";
1
+ import { g as isEqualSelectionPoints } from "./util.slice-blocks-B2fZcNok.js";
2
2
  import { isSpan, isTextBlock } from "@portabletext/schema";
3
3
  /**
4
4
  * @public
@@ -22,4 +22,4 @@ function isEqualSelections(a, b) {
22
22
  }
23
23
  export { isEmptyTextBlock as n, getTextBlockText as r, isEqualSelections as t };
24
24
 
25
- //# sourceMappingURL=util.is-equal-selections-BF4WJtz5.js.map
25
+ //# sourceMappingURL=util.is-equal-selections-N1hxVUbE.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.is-equal-selections-BF4WJtz5.js","names":["PortableTextTextBlock","getTextBlockText","block","children","map","child","text","join","isSpan","isTextBlock","PortableTextBlock","EditorContext","getTextBlockText","isEmptyTextBlock","context","Pick","block","onlyText","children","every","child","blockText","EditorSelection","isEqualSelectionPoints","isEqualSelections","a","b","anchor","focus"],"sources":["../src/utils/util.get-text-block-text.ts","../src/utils/util.is-empty-text-block.ts","../src/utils/util.is-equal-selections.ts"],"sourcesContent":["import type {PortableTextTextBlock} from '@portabletext/schema'\n\n/**\n * @public\n */\nexport function getTextBlockText(block: PortableTextTextBlock) {\n return block.children.map((child) => child.text ?? '').join('')\n}\n","import {isSpan, isTextBlock, type PortableTextBlock} from '@portabletext/schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {getTextBlockText} from './util.get-text-block-text'\n\n/**\n * @public\n */\nexport function isEmptyTextBlock(\n context: Pick<EditorContext, 'schema'>,\n block: PortableTextBlock | unknown,\n) {\n if (!isTextBlock(context, block)) {\n return false\n }\n\n const onlyText = block.children.every((child) => isSpan(context, child))\n const blockText = getTextBlockText(block)\n\n return onlyText && blockText === ''\n}\n","import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n"],"mappings":";;;;;AAKA,SAAgBC,iBAAiBC,OAA8B;CAC7D,OAAOA,MAAMC,SAASC,KAAKC,UAAUA,MAAMC,QAAQ,EAAE,CAAC,CAACC,KAAK,EAAE;AAChE;;;;ACAA,SAAgBM,iBACdC,SACAE,OACA;CACA,IAAI,CAACP,YAAYK,SAASE,KAAK,GAC7B,OAAO;CAGT,IAAMC,WAAWD,MAAME,SAASC,OAAOC,UAAUZ,OAAOM,SAASM,KAAK,CAAC,GACjEC,YAAYT,iBAAiBI,KAAK;CAExC,OAAOC,YAAYI,cAAc;AACnC;;;;ACbA,SAAgBG,kBAAkBC,GAAoBC,GAAoB;CASxE,OARI,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPH,uBAAuBE,EAAEE,QAAQD,EAAEC,MAAM,KACzCJ,uBAAuBE,EAAEG,OAAOF,EAAEE,KAAK;AAE3C"}
1
+ {"version":3,"file":"util.is-equal-selections-N1hxVUbE.js","names":["PortableTextTextBlock","getTextBlockText","block","children","map","child","text","join","isSpan","isTextBlock","PortableTextBlock","EditorContext","getTextBlockText","isEmptyTextBlock","context","Pick","block","onlyText","children","every","child","blockText","EditorSelection","isEqualSelectionPoints","isEqualSelections","a","b","anchor","focus"],"sources":["../src/utils/util.get-text-block-text.ts","../src/utils/util.is-empty-text-block.ts","../src/utils/util.is-equal-selections.ts"],"sourcesContent":["import type {PortableTextTextBlock} from '@portabletext/schema'\n\n/**\n * @public\n */\nexport function getTextBlockText(block: PortableTextTextBlock) {\n return block.children.map((child) => child.text ?? '').join('')\n}\n","import {isSpan, isTextBlock, type PortableTextBlock} from '@portabletext/schema'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {getTextBlockText} from './util.get-text-block-text'\n\n/**\n * @public\n */\nexport function isEmptyTextBlock(\n context: Pick<EditorContext, 'schema'>,\n block: PortableTextBlock | unknown,\n) {\n if (!isTextBlock(context, block)) {\n return false\n }\n\n const onlyText = block.children.every((child) => isSpan(context, child))\n const blockText = getTextBlockText(block)\n\n return onlyText && blockText === ''\n}\n","import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n"],"mappings":";;;;;AAKA,SAAgBC,iBAAiBC,OAA8B;CAC7D,OAAOA,MAAMC,SAASC,KAAKC,UAAUA,MAAMC,QAAQ,EAAE,CAAC,CAACC,KAAK,EAAE;AAChE;;;;ACAA,SAAgBM,iBACdC,SACAE,OACA;CACA,IAAI,CAACP,YAAYK,SAASE,KAAK,GAC7B,OAAO;CAGT,IAAMC,WAAWD,MAAME,SAASC,OAAOC,UAAUZ,OAAOM,SAASM,KAAK,CAAC,GACjEC,YAAYT,iBAAiBI,KAAK;CAExC,OAAOC,YAAYI,cAAc;AACnC;;;;ACbA,SAAgBG,kBAAkBC,GAAoBC,GAAoB;CASxE,OARI,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPH,uBAAuBE,EAAEE,QAAQD,EAAEC,MAAM,KACzCJ,uBAAuBE,EAAEG,OAAOF,EAAEE,KAAK;AAE3C"}
@@ -1,4 +1,4 @@
1
- import { c as isTypedObject, r as getNode, s as isRecord, t as getParent, u as isKeyedSegment } from "./get-parent-51Kzgaf9.js";
1
+ import { c as isTypedObject, r as getNode, s as isRecord, t as getParent, u as isKeyedSegment } from "./get-parent-Ci5241qs.js";
2
2
  import { getSubSchema, isSpan, isTextBlock } from "@portabletext/schema";
3
3
  /**
4
4
  * Pure text-offset arithmetic over a node's children array, shared by
@@ -630,4 +630,4 @@ function sliceBlocks({ context, blocks }) {
630
630
  }
631
631
  export { isEqualPaths as _, parseBlocks as a, childAtTextOffset as b, parseSpan as c, getSelectionEndPoint as d, isSelectionCollapsed as f, isEqualSelectionPoints as g, getBlockKeyFromSelectionPoint as h, parseBlock as i, defaultKeyGenerator as l, getBlockEndPoint as m, isListBlock as n, parseInlineObject as o, getBlockStartPoint as p, parseAnnotation as r, parseMarkDefs as s, sliceBlocks as t, getSelectionStartPoint as u, blockOffsetToSpanSelectionPoint as v, textOffsetOfChild as x, spanSelectionPointToBlockOffset as y };
632
632
 
633
- //# sourceMappingURL=util.slice-blocks-DQnr9X2s.js.map
633
+ //# sourceMappingURL=util.slice-blocks-B2fZcNok.js.map