@portabletext/editor 7.10.1 → 7.10.3

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,9 +1,9 @@
1
- import { getInline, getSelectionStartPoint, getSelectionEndPoint, getFocusTextBlock, getSelectionText } from "../_chunks-es/selector.is-at-the-start-of-block.js";
2
- import { compareApplicableSchema, getActiveAnnotations, getActiveListItem, getActiveStyle, getApplicableSchema, getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusInlineObject, getFocusListBlock, getFocusSpan, getFragment, getLastBlock, getMarkState, getNextBlock, getNextInlineObject, getNextSpan, getPreviousBlock, getPreviousInlineObject, getPreviousSpan, getSelectedBlocks, getSelectedSpans, getSelectedTextBlocks, getSelectedValue, getSelectionEndBlock, getSelectionEndChild, getSelectionStartBlock, getSelectionStartChild, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isSelectingEntireBlocks, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-at-the-start-of-block.js";
3
- import { getEnclosingBlock, isObject, comparePoints } from "../_chunks-es/get-path-sub-schema.js";
1
+ import { getInline, getSelectionStartPoint, getSelectionEndPoint, getFocusBlock, getFocusTextBlock, getSelectionText } from "../_chunks-es/selector.is-at-the-start-of-block.js";
2
+ import { compareApplicableSchema, getActiveAnnotations, getActiveListItem, getActiveStyle, getApplicableSchema, getCaretWordSelection, getFocusBlockObject, getFocusChild, getFocusInlineObject, getFocusListBlock, getFocusSpan, getFragment, getLastBlock, getMarkState, getNextBlock, getNextInlineObject, getNextSpan, getPreviousBlock, getPreviousInlineObject, getPreviousSpan, getSelectedBlocks, getSelectedSpans, getSelectedTextBlocks, getSelectedValue, getSelectionEndBlock, getSelectionEndChild, getSelectionStartBlock, getSelectionStartChild, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isSelectingEntireBlocks, isSelectionCollapsed, isSelectionExpanded } from "../_chunks-es/selector.is-at-the-start-of-block.js";
3
+ import { getEnclosingBlock, getBlock, isObject, comparePoints } from "../_chunks-es/get-path-sub-schema.js";
4
4
  import { isSpan, isTextBlock } from "@portabletext/schema";
5
5
  import { spanSelectionPointToBlockOffset, getSelectionEndPoint as getSelectionEndPoint$1, getBlockEndPoint, getSelectionStartPoint as getSelectionStartPoint$1, getBlockStartPoint } from "../_chunks-es/util.slice-blocks.js";
6
- import { isKeyedSegment, getChildren, parentPath } from "../_chunks-es/get-parent.js";
6
+ import { getChildren, parentPath, isKeyedSegment } from "../_chunks-es/get-parent.js";
7
7
  const getAnchorBlock = (snapshot) => {
8
8
  const selection = snapshot.context.selection;
9
9
  if (selection)
@@ -41,6 +41,20 @@ const getAnchorBlock = (snapshot) => {
41
41
  start,
42
42
  end
43
43
  } : void 0;
44
+ }, getFirstBlock = (snapshot) => {
45
+ const focusBlock = getFocusBlock(snapshot);
46
+ if (focusBlock) {
47
+ const first = getChildren(snapshot, parentPath(focusBlock.path)).at(0);
48
+ if (first)
49
+ return getBlock(snapshot, first.path);
50
+ }
51
+ const node = snapshot.context.value[0];
52
+ return node ? {
53
+ node,
54
+ path: [{
55
+ _key: node._key
56
+ }]
57
+ } : void 0;
44
58
  }, getNextInlineObjects = (snapshot) => {
45
59
  const point = getSelectionEndPoint(snapshot);
46
60
  if (!point)
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../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-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 {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 {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"],"names":["getAnchorBlock","snapshot","selection","context","getEnclosingBlock","anchor","path","getAnchorChild","getInline","getAnchorSpan","anchorChild","isSpan","node","undefined","getAnchorTextBlock","anchorBlock","isTextBlock","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","spanSelectionPointToBlockOffset","selectionPoint","end","getNextInlineObjects","point","endSegment","at","endKey","isKeyedSegment","_key","children","getChildren","parentPath","inlineObjects","endFound","child","segment","isObject","push","getPreviousInlineObjects","startSegment","startKey","getSelection","getBlockTextAfter","endPoint","block","getFocusTextBlock","focus","endOfBlock","getBlockEndPoint","getSelectionText","getBlockTextBefore","startPoint","startOfBlock","getBlockStartPoint","getValue","value","isPointAfterSelection","comparePoints","isPointBeforeSelection"],"mappings":";;;;;;AAUO,MAAMA,iBAERC,CAAAA,aAAa;AAChB,QAAMC,YAAYD,SAASE,QAAQD;AAEnC,MAAKA;AAIL,WAAOE,kBAAkBH,UAAUC,UAAUG,OAAOC,IAAI;A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QAAQwD;ACDnB,SAASC,sBACdjC,OACyB;AACzB,SAAQ1B,CAAAA,aAAa;AACnB,QAAI,CAACA,SAASE,QAAQD;AACpB,aAAO;AAGT,UAAM6C,WAAW1B,uBAAqBpB,SAASE,QAAQD,SAAS;AAEhE,WAAO2D,cAAc5D,UAAU0B,OAAOoB,QAAQ,MAAM;AAAA,EACtD;AACF;ACZO,SAASe,uBACdnC,OACyB;AACzB,SAAQ1B,CAAAA,aAAa;AACnB,QAAI,CAACA,SAASE,QAAQD;AACpB,aAAO;AAGT,UAAMqD,aAAapC,yBAAuBlB,SAASE,QAAQD,SAAS;AAEpE,WAAO2D,cAAc5D,UAAU0B,OAAO4B,UAAU,MAAM;AAAA,EACxD;AACF;"}
1
+ {"version":3,"file":"index.js","sources":["../../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 {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"],"names":["getAnchorBlock","snapshot","selection","context","getEnclosingBlock","anchor","path","getAnchorChild","getInline","getAnchorSpan","anchorChild","isSpan","node","undefined","getAnchorTextBlock","anchorBlock","isTextBlock","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","spanSelectionPointToBlockOffset","selectionPoint","end","getFirstBlock","focusBlock","getFocusBlock","first","getChildren","parentPath","at","getBlock","value","_key","getNextInlineObjects","point","endSegment","endKey","isKeyedSegment","children","inlineObjects","endFound","child","segment","isObject","push","getPreviousInlineObjects","startSegment","startKey","getSelection","getBlockTextAfter","endPoint","block","getFocusTextBlock","focus","endOfBlock","getBlockEndPoint","getSelectionText","getBlockTextBefore","startPoint","startOfBlock","getBlockStartPoint","getValue","is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QD;AACpB,WAAO;AAGT,QAAM2D,aAAa1C,yBAAuBlB,SAASE,QAAQD,SAAS,GAC9DoD,QAAQC,kBAAkB;AAAA,IAC9B,GAAGtD;AAAAA,IACHE,SAAS;AAAA,MACP,GAAGF,SAASE;AAAAA,MACZD,WAAW;AAAA,QACTG,QAAQwD;AAAAA,QACRL,OAAOK;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AAED,MAAI,CAACP;AACH,WAAO;AAGT,QAAMQ,eAAeC,mBAAmB;AAAA,IACtC5D,SAASF,SAASE;AAAAA,IAClBmD;AAAAA,EAAAA,CACD;AAED,SAAOK,iBAAiB;AAAA,IACtB,GAAG1D;AAAAA,IACHE,SAAS;AAAA,MACP,GAAGF,SAASE;AAAAA,MACZD,WAAW;AAAA,QACTG,QAAQyD;AAAAA,QACRN,OAAOK;AAAAA,MAAAA;AAAAA,IACT;AAAA,EACF,CACD;AACH,GCvCaG,WACX/D,CAAAA,aAEOA,SAASE,QAAQ+B;ACDnB,SAAS+B,sBACd5B,OACyB;AACzB,SAAQpC,CAAAA,aAAa;AACnB,QAAI,CAACA,SAASE,QAAQD;AACpB,aAAO;AAGT,UAAMmD,WAAWhC,uBAAqBpB,SAASE,QAAQD,SAAS;AAEhE,WAAOgE,cAAcjE,UAAUoC,OAAOgB,QAAQ,MAAM;AAAA,EACtD;AACF;ACZO,SAASc,uBACd9B,OACyB;AACzB,SAAQpC,CAAAA,aAAa;AACnB,QAAI,CAACA,SAASE,QAAQD;AACpB,aAAO;AAGT,UAAM2D,aAAa1C,yBAAuBlB,SAASE,QAAQD,SAAS;AAEpE,WAAOgE,cAAcjE,UAAUoC,OAAOwB,UAAU,MAAM;AAAA,EACxD;AACF;"}
@@ -1,8 +1,8 @@
1
1
  import { getTextBlock } from "../_chunks-es/get-container.js";
2
- import { getAncestor, getContainer, getFirstChild, getLeaf, getSpan, getText, getUnionSchema, isLeafObject, pathContains, rangeIntersects } from "../_chunks-es/get-container.js";
2
+ import { getAncestor, getContainer, getFirstChild, getLastChild, getLeaf, getSpan, getText, getUnionSchema, isLeafObject, pathContains, rangeIntersects } from "../_chunks-es/get-container.js";
3
3
  import { comparePoints, getAncestors, getBlock, getEnclosingBlock, getPathSubSchema, getSibling, hasNode, isBlock, isInline, isObject } from "../_chunks-es/get-path-sub-schema.js";
4
- import { isKeyedSegment, getChildren } from "../_chunks-es/get-parent.js";
5
- import { getContainerChildren, getNode, getParent } from "../_chunks-es/get-parent.js";
4
+ import { isKeyedSegment } from "../_chunks-es/get-parent.js";
5
+ import { getChildren, getContainerChildren, getNode, getParent } from "../_chunks-es/get-parent.js";
6
6
  function getAnnotation(snapshot, path) {
7
7
  for (let i = 0; i < path.length - 1; i++) {
8
8
  if (path[i] !== "markDefs")
@@ -22,9 +22,6 @@ function getAnnotation(snapshot, path) {
22
22
  } : void 0;
23
23
  }
24
24
  }
25
- function getLastChild(snapshot, path) {
26
- return getChildren(snapshot, path).at(-1);
27
- }
28
25
  export {
29
26
  comparePoints,
30
27
  getAncestor,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/traversal/get-annotation.ts","../../src/traversal/get-last-child.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","import type {Node} from '../engine/interfaces/node'\nimport type {Path} from '../engine/interfaces/path'\nimport {getChildren} from './get-children'\nimport type {TraversalSnapshot} from './traversal-snapshot'\n\n/**\n * Get the last child of a node at a given path.\n *\n * @beta\n */\nexport function getLastChild(\n snapshot: TraversalSnapshot,\n path: Path,\n): {node: Node; path: Path} | undefined {\n const children = getChildren(snapshot, path)\n\n return children.at(-1)\n}\n"],"names":["getAnnotation","snapshot","path","i","length","annotationSegment","isKeyedSegment","block","getTextBlock","slice","annotation","node","markDefs","find","markDef","_key","getLastChild","getChildren","at"],"mappings":";;;;;AAiBO,SAASA,cACdC,UACAC,MACoD;AAKpD,WAASC,IAAI,GAAGA,IAAID,KAAKE,SAAS,GAAGD,KAAK;AACxC,QAAID,KAAKC,CAAC,MAAM;AACd;AAGF,UAAME,oBAAoBH,KAAKC,IAAI,CAAC;AAEpC,QAAI,CAACG,eAAeD,iBAAiB;AACnC;AAGF,UAAME,QAAQC,aAAaP,UAAUC,KAAKO,MAAM,GAAGN,CAAC,CAAC;AAErD,QAAI,CAACI;AACH;AAGF,UAAMG,aAAaH,MAAMI,KAAKC,UAAUC,KACrCC,CAAAA,YAAYA,QAAQC,SAASV,kBAAkBU,IAClD;AAEA,WAAKL,aAIE;AAAA,MACLC,MAAMD;AAAAA,MACNR,MAAM,CAAC,GAAGK,MAAML,MAAM,YAAY;AAAA,QAACa,MAAML,WAAWK;AAAAA,MAAAA,CAAK;AAAA,IAAA,IALzD;AAAA,EAOJ;AAGF;AC/CO,SAASC,aACdf,UACAC,MACsC;AAGtC,SAFiBe,YAAYhB,UAAUC,IAAI,EAE3BgB,GAAG,EAAE;AACvB;"}
1
+ {"version":3,"file":"index.js","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"],"names":["getAnnotation","snapshot","path","i","length","annotationSegment","isKeyedSegment","block","getTextBlock","slice","annotation","node","markDefs","find","markDef","_key"],"mappings":";;;;;AAiBO,SAASA,cACdC,UACAC,MACoD;AAKpD,WAASC,IAAI,GAAGA,IAAID,KAAKE,SAAS,GAAGD,KAAK;AACxC,QAAID,KAAKC,CAAC,MAAM;AACd;AAGF,UAAME,oBAAoBH,KAAKC,IAAI,CAAC;AAEpC,QAAI,CAACG,eAAeD,iBAAiB;AACnC;AAGF,UAAME,QAAQC,aAAaP,UAAUC,KAAKO,MAAM,GAAGN,CAAC,CAAC;AAErD,QAAI,CAACI;AACH;AAGF,UAAMG,aAAaH,MAAMI,KAAKC,UAAUC,KACrCC,CAAAA,YAAYA,QAAQC,SAASV,kBAAkBU,IAClD;AAEA,WAAKL,aAIE;AAAA,MACLC,MAAMD;AAAAA,MACNR,MAAM,CAAC,GAAGK,MAAML,MAAM,YAAY;AAAA,QAACa,MAAML,WAAWK;AAAAA,MAAAA,CAAK;AAAA,IAAA,IALzD;AAAA,EAOJ;AAGF;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "7.10.1",
3
+ "version": "7.10.3",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "collaborative",
@@ -47,7 +47,7 @@
47
47
  "@xstate/react": "^6.1.0",
48
48
  "debug": "^4.4.3",
49
49
  "scroll-into-view-if-needed": "^3.1.0",
50
- "xstate": "^5.32.2",
50
+ "xstate": "^5.32.4",
51
51
  "@portabletext/html": "^1.1.0",
52
52
  "@portabletext/keyboard-shortcuts": "^2.1.3",
53
53
  "@portabletext/markdown": "^1.4.3",