@portabletext/editor 2.12.3 → 2.13.1

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 (36) hide show
  1. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +64 -5
  2. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
  3. package/lib/_chunks-cjs/util.slice-blocks.cjs +1 -0
  4. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
  5. package/lib/_chunks-dts/behavior.types.action.d.cts +9 -17
  6. package/lib/_chunks-dts/behavior.types.action.d.ts +9 -17
  7. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +65 -6
  8. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
  9. package/lib/_chunks-es/util.slice-blocks.js +1 -0
  10. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  11. package/lib/index.cjs +262 -29
  12. package/lib/index.cjs.map +1 -1
  13. package/lib/index.js +262 -29
  14. package/lib/index.js.map +1 -1
  15. package/lib/plugins/index.cjs +1 -1
  16. package/lib/plugins/index.d.ts +3 -3
  17. package/lib/plugins/index.js +1 -1
  18. package/lib/selectors/index.cjs +1 -0
  19. package/lib/selectors/index.cjs.map +1 -1
  20. package/lib/selectors/index.d.cts +15 -1
  21. package/lib/selectors/index.d.ts +15 -1
  22. package/lib/selectors/index.js +2 -1
  23. package/lib/utils/index.d.cts +2 -2
  24. package/package.json +13 -13
  25. package/src/behaviors/behavior.abstract.delete.ts +1 -0
  26. package/src/behaviors/behavior.abstract.keyboard.ts +27 -0
  27. package/src/editor/components/render-block-object.tsx +29 -2
  28. package/src/editor/components/render-inline-object.tsx +31 -2
  29. package/src/editor/components/render-span.tsx +91 -6
  30. package/src/editor/components/render-text-block.tsx +95 -6
  31. package/src/internal-utils/asserters.ts +1 -1
  32. package/src/keyboard-shortcuts/default-keyboard-shortcuts.ts +22 -0
  33. package/src/operations/behavior.operation.delete.ts +6 -24
  34. package/src/selectors/index.ts +1 -0
  35. package/src/selectors/selector.get-mark-state.ts +75 -6
  36. package/src/types/paths.ts +18 -0
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEditor = require("../_chunks-cjs/use-editor.cjs"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), xstate = require("xstate"), selector_isSelectionExpanded = require("../_chunks-cjs/selector.is-selection-expanded.cjs"), util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs"), util_childSelectionPointToBlockOffset = require("../_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs"), behaviors_index = require("../behaviors/index.cjs"), jsxRuntime = require("react/jsx-runtime"), schema = require("@portabletext/schema"), util_mergeTextBlocks = require("../_chunks-cjs/util.merge-text-blocks.cjs");
3
+ var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEditor = require("../_chunks-cjs/use-editor.cjs"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), xstate = require("xstate"), util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs"), util_childSelectionPointToBlockOffset = require("../_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), selector_isSelectionExpanded = require("../_chunks-cjs/selector.is-selection-expanded.cjs"), selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs"), behaviors_index = require("../behaviors/index.cjs"), jsxRuntime = require("react/jsx-runtime"), schema = require("@portabletext/schema"), util_mergeTextBlocks = require("../_chunks-cjs/util.merge-text-blocks.cjs");
4
4
  function _interopDefaultCompat(e) {
5
5
  return e && typeof e == "object" && "default" in e ? e : { default: e };
6
6
  }
@@ -1,5 +1,5 @@
1
1
  import { Behavior, Editor, EditorEmittedEvent, EditorSchema } from "../_chunks-dts/behavior.types.action.js";
2
- import * as react22 from "react";
2
+ import * as react12 from "react";
3
3
  import React from "react";
4
4
  /**
5
5
  * @beta
@@ -181,7 +181,7 @@ type MarkdownPluginConfig = MarkdownBehaviorsConfig & {
181
181
  */
182
182
  declare function MarkdownPlugin(props: {
183
183
  config: MarkdownPluginConfig;
184
- }): react22.JSX.Element;
184
+ }): react12.JSX.Element;
185
185
  /**
186
186
  * @beta
187
187
  * Restrict the editor to one line. The plugin takes care of blocking
@@ -192,5 +192,5 @@ declare function MarkdownPlugin(props: {
192
192
  *
193
193
  * @deprecated Install the plugin from `@portabletext/plugin-one-line`
194
194
  */
195
- declare function OneLinePlugin(): react22.JSX.Element;
195
+ declare function OneLinePlugin(): react12.JSX.Element;
196
196
  export { BehaviorPlugin, DecoratorShortcutPlugin, EditorRefPlugin, EventListenerPlugin, MarkdownPlugin, type MarkdownPluginConfig, OneLinePlugin };
@@ -4,9 +4,9 @@ import { useEditor } from "../_chunks-es/use-editor.js";
4
4
  import { useActorRef } from "@xstate/react";
5
5
  import isEqual from "lodash/isEqual.js";
6
6
  import { setup, fromCallback, assign } from "xstate";
7
- import { getFocusTextBlock, getSelectionStartPoint, getPreviousInlineObject, isSelectionCollapsed, getFocusSpan, getFocusBlock, isSelectionExpanded } from "../_chunks-es/selector.is-selection-expanded.js";
8
7
  import { spanSelectionPointToBlockOffset, getTextBlockText } from "../_chunks-es/util.slice-blocks.js";
9
8
  import { blockOffsetsToSelection, childSelectionPointToBlockOffset } from "../_chunks-es/util.child-selection-point-to-block-offset.js";
9
+ import { getFocusTextBlock, getSelectionStartPoint, getPreviousInlineObject, isSelectionCollapsed, getFocusSpan, getFocusBlock, isSelectionExpanded } from "../_chunks-es/selector.is-selection-expanded.js";
10
10
  import { getBlockTextBefore } from "../_chunks-es/selector.get-text-before.js";
11
11
  import { defineBehavior, execute, effect, forward, raise } from "../behaviors/index.js";
12
12
  import { jsxs, Fragment, jsx } from "react/jsx-runtime";
@@ -125,6 +125,7 @@ exports.getFocusBlockObject = selector_isSelectingEntireBlocks.getFocusBlockObje
125
125
  exports.getFocusInlineObject = selector_isSelectingEntireBlocks.getFocusInlineObject;
126
126
  exports.getFocusListBlock = selector_isSelectingEntireBlocks.getFocusListBlock;
127
127
  exports.getLastBlock = selector_isSelectingEntireBlocks.getLastBlock;
128
+ exports.getMarkState = selector_isSelectingEntireBlocks.getMarkState;
128
129
  exports.getNextBlock = selector_isSelectingEntireBlocks.getNextBlock;
129
130
  exports.getNextInlineObject = selector_isSelectingEntireBlocks.getNextInlineObject;
130
131
  exports.getPreviousBlock = selector_isSelectingEntireBlocks.getPreviousBlock;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-list-state.ts","../../src/selectors/selector.get-selected-slice.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-selection-end-child.ts","../../src/selectors/selector.get-selection-start-child.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.anchor)\n const index = key ? snapshot.blockIndexMap.get(key) : undefined\n const node =\n index !== undefined ? snapshot.context.value.at(index) : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\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 {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {ChildPath} from '../types/paths'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.anchor)\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\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 && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\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 = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * @beta\n * @deprecated Use the precomputed `data-list-index` on text blocks instead.\n * Given the `path` of a block, this selector will return the \"list index\" of\n * the block.\n */\nexport function getListIndex({\n path,\n}: {\n path: BlockPath\n}): EditorSelector<number | undefined> {\n return (snapshot) => {\n const selection = {\n anchor: {\n path,\n offset: 0,\n },\n focus: {\n path,\n offset: 0,\n },\n }\n\n const focusTextBlock = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!focusTextBlock) {\n return undefined\n }\n\n if (\n focusTextBlock.node.listItem === undefined ||\n focusTextBlock.node.level === undefined\n ) {\n return undefined\n }\n\n const targetListItem = focusTextBlock.node.listItem\n const targetLevel = focusTextBlock.node.level\n const targetKey = focusTextBlock.node._key\n\n // Find the target block's index\n const targetIndex = snapshot.blockIndexMap.get(targetKey)\n\n if (targetIndex === undefined) {\n return undefined\n }\n\n // Walk backwards from the target block and count consecutive list items\n // of the same type and level\n let listIndex = 1 // Start at 1 for the target block itself\n\n for (let i = targetIndex - 1; i >= 0; i--) {\n const block = snapshot.context.value[i]\n\n if (!isTextBlock(snapshot.context, block)) {\n // Non-text block breaks the sequence\n break\n }\n\n if (block.listItem === undefined || block.level === undefined) {\n // Non-list item breaks the sequence\n break\n }\n\n if (block.listItem !== targetListItem) {\n // Different list type breaks the sequence\n break\n }\n\n if (block.level < targetLevel) {\n // Lower level breaks the sequence\n break\n }\n\n if (block.level === targetLevel) {\n // Same level - continue counting\n listIndex++\n }\n\n // Higher level items don't affect the count for the target level\n }\n\n return listIndex\n }\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * @public\n * @deprecated Renamed to `getSelectedValue`.\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return getSelectedValue(snapshot)\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getSelectionEndChild: EditorSelector<\n | {\n node: PortableTextSpan | PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n\n if (!endPoint) {\n return undefined\n }\n\n return getFocusChild({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: endPoint,\n focus: endPoint,\n },\n },\n })\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getSelectionStartChild: EditorSelector<\n | {\n node: PortableTextSpan | PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n\n if (!startPoint) {\n return undefined\n }\n\n return getFocusChild({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startPoint,\n focus: startPoint,\n },\n },\n })\n}\n","import type {PortableTextBlock} from '@sanity/types'\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"],"names":["getAnchorBlock","snapshot","context","selection","key","getBlockKeyFromSelectionPoint","anchor","index","blockIndexMap","get","undefined","node","value","at","path","_key","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","getChildKeyFromSelectionPoint","children","find","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getListIndex","offset","focus","focusTextBlock","getFocusTextBlock","listItem","level","targetListItem","targetLevel","targetKey","targetIndex","listIndex","i","block","getSelectedSlice","getSelectedValue","getSelection","getSelectionEndChild","endPoint","getFocusChild","getSelectionStartChild","startPoint","getValue"],"mappings":";;;AAQO,MAAMA,iBAERC,CAAAA,aAAa;AAChB,MAAI,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,iBAAAA,8BAA8BJ,SAASC,QAAQC,UAAUG,MAAM,GACrEC,QAAQH,MAAMH,SAASO,cAAcC,IAAIL,GAAG,IAAIM,QAChDC,OACJJ,UAAUG,SAAYT,SAASC,QAAQU,MAAMC,GAAGN,KAAK,IAAIG;AAE3D,SAAOC,QAAQP,MAAM;AAAA,IAACO;AAAAA,IAAMG,MAAM,CAAC;AAAA,MAACC,MAAMX;AAAAA,IAAAA,CAAI;AAAA,EAAA,IAAKM;AACrD,GCZaM,qBAERf,CAAAA,aAAa;AAChB,QAAMgB,cAAcjB,eAAeC,QAAQ;AAE3C,SAAOgB,eAAeC,OAAAA,YAAYjB,SAASC,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E,MAAKmD;AAIL,WAAOC,2CAAc;AAAA,MACnB,GAAGtD;AAAAA,MACHC,SAAS;AAAA,QACP,GAAGD,SAASC;AAAAA,QACZC,WAAW;AAAA,UACTG,QAAQgD;AAAAA,UACRhB,OAAOgB;AAAAA,QAAAA;AAAAA,MACT;AAAA,IACF,CACD;AACH,GCvBaE,yBAMRvD,CAAAA,aAAa;AAChB,QAAMwD,aAAa5B,iBAAAA,uBAAuB5B,SAASC,QAAQC,SAAS;AAEpE,MAAKsD;AAIL,WAAOF,2CAAc;AAAA,MACnB,GAAGtD;AAAAA,MACHC,SAAS;AAAA,QACP,GAAGD,SAASC;AAAAA,QACZC,WAAW;AAAA,UACTG,QAAQmD;AAAAA,UACRnB,OAAOmB;AAAAA,QAAAA;AAAAA,MACT;AAAA,IACF,CACD;AACH,GC1BaC,WACXzD,CAAAA,aAEOA,SAASC,QAAQU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/selectors/selector.get-anchor-block.ts","../../src/selectors/selector.get-anchor-text-block.ts","../../src/selectors/selector.get-anchor-child.ts","../../src/selectors/selector.get-anchor-span.ts","../../src/selectors/selector.get-block-offsets.ts","../../src/selectors/selector.get-list-state.ts","../../src/selectors/selector.get-selected-slice.ts","../../src/selectors/selector.get-selection.ts","../../src/selectors/selector.get-selection-end-child.ts","../../src/selectors/selector.get-selection-start-child.ts","../../src/selectors/selector.get-value.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getBlockKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {BlockPath} from '../types/paths'\n\n/**\n * @public\n */\nexport const getAnchorBlock: EditorSelector<\n {node: PortableTextBlock; path: BlockPath} | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const key = getBlockKeyFromSelectionPoint(snapshot.context.selection.anchor)\n const index = key ? snapshot.blockIndexMap.get(key) : undefined\n const node =\n index !== undefined ? snapshot.context.value.at(index) : undefined\n\n return node && key ? {node, path: [{_key: key}]} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getAnchorBlock} from './selector.get-anchor-block'\n\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 {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getChildKeyFromSelectionPoint} from '../selection/selection-point'\nimport type {ChildPath} from '../types/paths'\nimport {getAnchorTextBlock} from './selector.get-anchor-text-block'\n\n/**\n * @public\n */\nexport const getAnchorChild: EditorSelector<\n | {\n node: PortableTextObject | PortableTextSpan\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const anchorBlock = getAnchorTextBlock(snapshot)\n\n if (!anchorBlock) {\n return undefined\n }\n\n const key = getChildKeyFromSelectionPoint(snapshot.context.selection.anchor)\n\n const node = key\n ? anchorBlock.node.children.find((span) => span._key === key)\n : undefined\n\n return node && key\n ? {node, path: [...anchorBlock.path, 'children', {_key: key}]}\n : undefined\n}\n","import {isPortableTextSpan, type PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getAnchorChild} from './selector.get-anchor-child'\n\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 && isPortableTextSpan(anchorChild.node)\n ? {node: anchorChild.node, path: anchorChild.path}\n : undefined\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockOffset} from '../types/block-offset'\nimport * as utils from '../utils'\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 = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionStartPoint,\n })\n const end = utils.spanSelectionPointToBlockOffset({\n context: snapshot.context,\n selectionPoint: selectionEndPoint,\n })\n\n return start && end ? {start, end} : undefined\n}\n","import {isTextBlock} from '@portabletext/schema'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {BlockPath} from '../types/paths'\nimport {getFocusTextBlock} from './selector.get-focus-text-block'\n\n/**\n * @beta\n * @deprecated Use the precomputed `data-list-index` on text blocks instead.\n * Given the `path` of a block, this selector will return the \"list index\" of\n * the block.\n */\nexport function getListIndex({\n path,\n}: {\n path: BlockPath\n}): EditorSelector<number | undefined> {\n return (snapshot) => {\n const selection = {\n anchor: {\n path,\n offset: 0,\n },\n focus: {\n path,\n offset: 0,\n },\n }\n\n const focusTextBlock = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection,\n },\n })\n\n if (!focusTextBlock) {\n return undefined\n }\n\n if (\n focusTextBlock.node.listItem === undefined ||\n focusTextBlock.node.level === undefined\n ) {\n return undefined\n }\n\n const targetListItem = focusTextBlock.node.listItem\n const targetLevel = focusTextBlock.node.level\n const targetKey = focusTextBlock.node._key\n\n // Find the target block's index\n const targetIndex = snapshot.blockIndexMap.get(targetKey)\n\n if (targetIndex === undefined) {\n return undefined\n }\n\n // Walk backwards from the target block and count consecutive list items\n // of the same type and level\n let listIndex = 1 // Start at 1 for the target block itself\n\n for (let i = targetIndex - 1; i >= 0; i--) {\n const block = snapshot.context.value[i]\n\n if (!isTextBlock(snapshot.context, block)) {\n // Non-text block breaks the sequence\n break\n }\n\n if (block.listItem === undefined || block.level === undefined) {\n // Non-list item breaks the sequence\n break\n }\n\n if (block.listItem !== targetListItem) {\n // Different list type breaks the sequence\n break\n }\n\n if (block.level < targetLevel) {\n // Lower level breaks the sequence\n break\n }\n\n if (block.level === targetLevel) {\n // Same level - continue counting\n listIndex++\n }\n\n // Higher level items don't affect the count for the target level\n }\n\n return listIndex\n }\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedValue} from './selector.get-selected-value'\n\n/**\n * @public\n * @deprecated Renamed to `getSelectedValue`.\n */\nexport const getSelectedSlice: EditorSelector<Array<PortableTextBlock>> = (\n snapshot,\n) => {\n return getSelectedValue(snapshot)\n}\n","import type {EditorSelection} from '..'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelection: EditorSelector<EditorSelection> = (snapshot) => {\n return snapshot.context.selection\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getSelectionEndPoint} from '../utils/util.get-selection-end-point'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getSelectionEndChild: EditorSelector<\n | {\n node: PortableTextSpan | PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const endPoint = getSelectionEndPoint(snapshot.context.selection)\n\n if (!endPoint) {\n return undefined\n }\n\n return getFocusChild({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: endPoint,\n focus: endPoint,\n },\n },\n })\n}\n","import type {PortableTextObject, PortableTextSpan} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {ChildPath} from '../types/paths'\nimport {getSelectionStartPoint} from '../utils/util.get-selection-start-point'\nimport {getFocusChild} from './selector.get-focus-child'\n\n/**\n * @public\n */\nexport const getSelectionStartChild: EditorSelector<\n | {\n node: PortableTextSpan | PortableTextObject\n path: ChildPath\n }\n | undefined\n> = (snapshot) => {\n const startPoint = getSelectionStartPoint(snapshot.context.selection)\n\n if (!startPoint) {\n return undefined\n }\n\n return getFocusChild({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: {\n anchor: startPoint,\n focus: startPoint,\n },\n },\n })\n}\n","import type {PortableTextBlock} from '@sanity/types'\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"],"names":["getAnchorBlock","snapshot","context","selection","key","getBlockKeyFromSelectionPoint","anchor","index","blockIndexMap","get","undefined","node","value","at","path","_key","getAnchorTextBlock","anchorBlock","isTextBlock","getAnchorChild","getChildKeyFromSelectionPoint","children","find","span","getAnchorSpan","anchorChild","isPortableTextSpan","getBlockOffsets","selectionStartPoint","getSelectionStartPoint","selectionEndPoint","getSelectionEndPoint","start","utils","selectionPoint","end","getListIndex","offset","focus","focusTextBlock","getFocusTextBlock","listItem","level","targetListItem","targetLevel","targetKey","targetIndex","listIndex","i","block","getSelectedSlice","getSelectedValue","getSelection","getSelectionEndChild","endPoint","getFocusChild","getSelectionStartChild","startPoint","getValue"],"mappings":";;;AAQO,MAAMA,iBAERC,CAAAA,aAAa;AAChB,MAAI,CAACA,SAASC,QAAQC;AACpB;AAGF,QAAMC,MAAMC,iBAAAA,8BAA8BJ,SAASC,QAAQC,UAAUG,MAAM,GACrEC,QAAQH,MAAMH,SAASO,cAAcC,IAAIL,GAAG,IAAIM,QAChDC,OACJJ,UAAUG,SAAYT,SAASC,QAAQU,MAAMC,GAAGN,KA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AAA,IAIJ;AAEA,WAAOA;AAAAA,EACT;AACF;ACvFO,MAAMG,mBACXjD,CAAAA,aAEOkD,6BAAAA,iBAAiBlD,QAAQ,GCLrBmD,eAAiDnD,CAAAA,aACrDA,SAASC,QAAQC,WCEbkD,uBAMRpD,CAAAA,aAAa;AAChB,QAAMqD,WAAWvB,iBAAAA,qBAAqB9B,SAASC,QAAQC,SAAS;AAEhE,MAAKmD;AAIL,WAAOC,2CAAc;AAAA,MACnB,GAAGtD;AAAAA,MACHC,SAAS;AAAA,QACP,GAAGD,SAASC;AAAAA,QACZC,WAAW;AAAA,UACTG,QAAQgD;AAAAA,UACRhB,OAAOgB;AAAAA,QAAAA;AAAAA,MACT;AAAA,IACF,CACD;AACH,GCvBaE,yBAMRvD,CAAAA,aAAa;AAChB,QAAMwD,aAAa5B,iBAAAA,uBAAuB5B,SAASC,QAAQC,SAAS;AAEpE,MAAKsD;AAIL,WAAOF,2CAAc;AAAA,MACnB,GAAGtD;AAAAA,MACHC,SAAS;AAAA,QACP,GAAGD,SAASC;AAAAA,QACZC,WAAW;AAAA,UACTG,QAAQmD;AAAAA,UACRnB,OAAOmB;AAAAA,QAAAA;AAAAA,MACT;AAAA,IACF,CACD;AACH,GC1BaC,WACXzD,CAAAA,aAEOA,SAASC,QAAQU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -127,6 +127,20 @@ declare function getListIndex({
127
127
  }: {
128
128
  path: BlockPath;
129
129
  }): EditorSelector<number | undefined>;
130
+ type MarkState = {
131
+ state: 'unchanged';
132
+ marks: Array<string>;
133
+ } | {
134
+ state: 'changed';
135
+ marks: Array<string>;
136
+ previousMarks: Array<string>;
137
+ };
138
+ /**
139
+ * Given that text is inserted at the current position, what marks should
140
+ * be applied?
141
+ * @beta
142
+ */
143
+ declare const getMarkState: EditorSelector<MarkState | undefined>;
130
144
  /**
131
145
  * @public
132
146
  */
@@ -305,4 +319,4 @@ declare const isSelectionCollapsed: EditorSelector<boolean>;
305
319
  * @public
306
320
  */
307
321
  declare const isSelectionExpanded: EditorSelector<boolean>;
308
- export { getActiveAnnotations, getActiveListItem, getActiveStyle, getAnchorBlock, getAnchorChild, getAnchorSpan, getAnchorTextBlock, getBlockOffsets, getBlockTextBefore, getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusInlineObject, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getListIndex, getNextBlock, getNextInlineObject, getPreviousBlock, getPreviousInlineObject, getSelectedBlocks, getSelectedSlice, getSelectedSpans, getSelectedTextBlocks, getSelectedValue, getSelection, getSelectionEndBlock, getSelectionEndChild, getSelectionEndPoint, getSelectionStartBlock, getSelectionStartChild, getSelectionStartPoint, getSelectionText, getTrimmedSelection, getValue, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks, isSelectionCollapsed, isSelectionExpanded };
322
+ export { getActiveAnnotations, getActiveListItem, getActiveStyle, getAnchorBlock, getAnchorChild, getAnchorSpan, getAnchorTextBlock, getBlockOffsets, getBlockTextBefore, getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusInlineObject, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getListIndex, getMarkState, getNextBlock, getNextInlineObject, getPreviousBlock, getPreviousInlineObject, getSelectedBlocks, getSelectedSlice, getSelectedSpans, getSelectedTextBlocks, getSelectedValue, getSelection, getSelectionEndBlock, getSelectionEndChild, getSelectionEndPoint, getSelectionStartBlock, getSelectionStartChild, getSelectionStartPoint, getSelectionText, getTrimmedSelection, getValue, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks, isSelectionCollapsed, isSelectionExpanded };
@@ -127,6 +127,20 @@ declare function getListIndex({
127
127
  }: {
128
128
  path: BlockPath;
129
129
  }): EditorSelector<number | undefined>;
130
+ type MarkState = {
131
+ state: 'unchanged';
132
+ marks: Array<string>;
133
+ } | {
134
+ state: 'changed';
135
+ marks: Array<string>;
136
+ previousMarks: Array<string>;
137
+ };
138
+ /**
139
+ * Given that text is inserted at the current position, what marks should
140
+ * be applied?
141
+ * @beta
142
+ */
143
+ declare const getMarkState: EditorSelector<MarkState | undefined>;
130
144
  /**
131
145
  * @public
132
146
  */
@@ -305,4 +319,4 @@ declare const isSelectionCollapsed: EditorSelector<boolean>;
305
319
  * @public
306
320
  */
307
321
  declare const isSelectionExpanded: EditorSelector<boolean>;
308
- export { getActiveAnnotations, getActiveListItem, getActiveStyle, getAnchorBlock, getAnchorChild, getAnchorSpan, getAnchorTextBlock, getBlockOffsets, getBlockTextBefore, getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusInlineObject, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getListIndex, getNextBlock, getNextInlineObject, getPreviousBlock, getPreviousInlineObject, getSelectedBlocks, getSelectedSlice, getSelectedSpans, getSelectedTextBlocks, getSelectedValue, getSelection, getSelectionEndBlock, getSelectionEndChild, getSelectionEndPoint, getSelectionStartBlock, getSelectionStartChild, getSelectionStartPoint, getSelectionText, getTrimmedSelection, getValue, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks, isSelectionCollapsed, isSelectionExpanded };
322
+ export { getActiveAnnotations, getActiveListItem, getActiveStyle, getAnchorBlock, getAnchorChild, getAnchorSpan, getAnchorTextBlock, getBlockOffsets, getBlockTextBefore, getCaretWordSelection, getFirstBlock, getFocusBlock, getFocusBlockObject, getFocusChild, getFocusInlineObject, getFocusListBlock, getFocusSpan, getFocusTextBlock, getLastBlock, getListIndex, getMarkState, getNextBlock, getNextInlineObject, getPreviousBlock, getPreviousInlineObject, getSelectedBlocks, getSelectedSlice, getSelectedSpans, getSelectedTextBlocks, getSelectedValue, getSelection, getSelectionEndBlock, getSelectionEndChild, getSelectionEndPoint, getSelectionStartBlock, getSelectionStartChild, getSelectionStartPoint, getSelectionText, getTrimmedSelection, getValue, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks, isSelectionCollapsed, isSelectionExpanded };
@@ -1,5 +1,5 @@
1
1
  import { getSelectionEndPoint } from "../_chunks-es/selector.is-selecting-entire-blocks.js";
2
- import { getActiveAnnotations, getActiveListItem, getActiveStyle, getCaretWordSelection, getFirstBlock, getFocusBlockObject, getFocusInlineObject, getFocusListBlock, getLastBlock, getNextBlock, getNextInlineObject, getPreviousBlock, getSelectedBlocks, getSelectedSpans, getSelectedTextBlocks, getSelectionEndBlock, getSelectionStartBlock, getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks } from "../_chunks-es/selector.is-selecting-entire-blocks.js";
2
+ import { getActiveAnnotations, getActiveListItem, getActiveStyle, getCaretWordSelection, getFirstBlock, getFocusBlockObject, getFocusInlineObject, getFocusListBlock, getLastBlock, getMarkState, getNextBlock, getNextInlineObject, getPreviousBlock, getSelectedBlocks, getSelectedSpans, getSelectedTextBlocks, getSelectionEndBlock, getSelectionStartBlock, getTrimmedSelection, isActiveAnnotation, isActiveDecorator, isActiveListItem, isActiveStyle, isAtTheEndOfBlock, isAtTheStartOfBlock, isOverlappingSelection, isPointAfterSelection, isPointBeforeSelection, isSelectingEntireBlocks } from "../_chunks-es/selector.is-selecting-entire-blocks.js";
3
3
  import { getBlockKeyFromSelectionPoint, getChildKeyFromSelectionPoint, spanSelectionPointToBlockOffset, getSelectionEndPoint as getSelectionEndPoint$1, getSelectionStartPoint as getSelectionStartPoint$1 } from "../_chunks-es/util.slice-blocks.js";
4
4
  import { isTextBlock } from "@portabletext/schema";
5
5
  import { isPortableTextSpan } from "@sanity/types";
@@ -142,6 +142,7 @@ export {
142
142
  getFocusTextBlock,
143
143
  getLastBlock,
144
144
  getListIndex,
145
+ getMarkState,
145
146
  getNextBlock,
146
147
  getNextInlineObject,
147
148
  getPreviousBlock,
@@ -1,5 +1,5 @@
1
1
  import { BlockOffset, BlockPath, ChildPath, EditorContext, EditorSelection, EditorSelectionPoint } from "../_chunks-dts/behavior.types.action.cjs";
2
- import * as _sanity_types9 from "@sanity/types";
2
+ import * as _sanity_types8 from "@sanity/types";
3
3
  import { KeyedSegment, PortableTextBlock, PortableTextTextBlock } from "@sanity/types";
4
4
  import { isSpan, isTextBlock } from "@portabletext/schema";
5
5
  /**
@@ -143,7 +143,7 @@ declare function mergeTextBlocks({
143
143
  context: Pick<EditorContext, 'keyGenerator' | 'schema'>;
144
144
  targetBlock: PortableTextTextBlock;
145
145
  incomingBlock: PortableTextTextBlock;
146
- }): PortableTextTextBlock<_sanity_types9.PortableTextObject | _sanity_types9.PortableTextSpan>;
146
+ }): PortableTextTextBlock<_sanity_types8.PortableTextObject | _sanity_types8.PortableTextSpan>;
147
147
  /**
148
148
  * @public
149
149
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "2.12.3",
3
+ "version": "2.13.1",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -75,7 +75,7 @@
75
75
  "dependencies": {
76
76
  "@portabletext/to-html": "^3.0.0",
77
77
  "@xstate/react": "^6.0.0",
78
- "debug": "^4.4.1",
78
+ "debug": "^4.4.3",
79
79
  "get-random-values-esm": "^1.0.2",
80
80
  "immer": "^10.1.3",
81
81
  "lodash": "^4.17.21",
@@ -85,40 +85,40 @@
85
85
  "slate-dom": "^0.118.1",
86
86
  "slate-react": "0.117.4",
87
87
  "xstate": "^5.22.0",
88
- "@portabletext/schema": "^1.2.0",
89
88
  "@portabletext/block-tools": "^3.5.7",
90
89
  "@portabletext/keyboard-shortcuts": "^1.1.1",
91
- "@portabletext/patches": "^1.1.8"
90
+ "@portabletext/patches": "^1.1.8",
91
+ "@portabletext/schema": "^1.2.0"
92
92
  },
93
93
  "devDependencies": {
94
94
  "@sanity/diff-match-patch": "^3.2.0",
95
- "@sanity/pkg-utils": "^8.1.4",
95
+ "@sanity/pkg-utils": "^8.1.14",
96
96
  "@sanity/schema": "^4.9.0",
97
97
  "@sanity/types": "^4.9.0",
98
98
  "@types/debug": "^4.1.12",
99
99
  "@types/lodash": "^4.17.20",
100
100
  "@types/lodash.startcase": "^4.4.9",
101
- "@types/react": "^19.1.11",
102
- "@types/react-dom": "^19.1.7",
101
+ "@types/react": "^19.1.13",
102
+ "@types/react-dom": "^19.1.9",
103
103
  "@vitejs/plugin-react": "^4.7.0",
104
104
  "@vitest/browser": "^3.2.4",
105
105
  "@vitest/coverage-istanbul": "^3.2.4",
106
106
  "babel-plugin-react-compiler": "19.1.0-rc.3",
107
- "eslint": "^9.34.0",
107
+ "eslint": "^9.36.0",
108
108
  "eslint-formatter-gha": "^1.6.0",
109
109
  "eslint-plugin-react-hooks": "6.0.0-rc.2",
110
- "jsdom": "^26.0.0",
110
+ "jsdom": "^27.0.0",
111
111
  "react": "^19.1.1",
112
112
  "react-dom": "^19.1.1",
113
113
  "rxjs": "^7.8.2",
114
114
  "typescript": "5.9.2",
115
- "typescript-eslint": "^8.41.0",
116
- "vite": "^7.1.3",
115
+ "typescript-eslint": "^8.44.1",
116
+ "vite": "^7.1.7",
117
117
  "vitest": "^3.2.4",
118
118
  "vitest-browser-react": "^1.0.1",
119
119
  "@portabletext/sanity-bridge": "1.1.11",
120
- "@portabletext/test": "^0.0.0",
121
- "racejar": "1.3.0"
120
+ "racejar": "1.3.0",
121
+ "@portabletext/test": "^0.0.0"
122
122
  },
123
123
  "peerDependencies": {
124
124
  "@portabletext/sanity-bridge": "^1.1.11",
@@ -204,6 +204,7 @@ export const abstractDeleteBehaviors = [
204
204
  offset: 0,
205
205
  },
206
206
  },
207
+ unit: 'block',
207
208
  }),
208
209
  ],
209
210
  ],
@@ -25,6 +25,33 @@ const shiftLeft = createKeyboardShortcut({
25
25
  })
26
26
 
27
27
  export const abstractKeyboardBehaviors = [
28
+ /**
29
+ * When Backspace is pressed on an inline object, Slate will raise a
30
+ * `delete.backward` event with `unit: 'block'`. This is wrong and this
31
+ * Behavior adjusts that.
32
+ */
33
+ defineBehavior({
34
+ on: 'keyboard.keydown',
35
+ guard: ({snapshot, event}) =>
36
+ defaultKeyboardShortcuts.backspace.guard(event.originEvent) &&
37
+ isSelectionCollapsed(snapshot) &&
38
+ getFocusInlineObject(snapshot),
39
+ actions: [() => [raise({type: 'delete.backward', unit: 'character'})]],
40
+ }),
41
+ /**
42
+ * When Delete is pressed on an inline object, Slate will raise a
43
+ * `delete.forward` event with `unit: 'block'`. This is wrong and this
44
+ * Behavior adjusts that.
45
+ */
46
+ defineBehavior({
47
+ on: 'keyboard.keydown',
48
+ guard: ({snapshot, event}) =>
49
+ defaultKeyboardShortcuts.delete.guard(event.originEvent) &&
50
+ isSelectionCollapsed(snapshot) &&
51
+ getFocusInlineObject(snapshot),
52
+ actions: [() => [raise({type: 'delete.forward', unit: 'character'})]],
53
+ }),
54
+
28
55
  /**
29
56
  * Allow raising an `insert.break` event when pressing Enter on an inline
30
57
  * object.
@@ -8,6 +8,7 @@ import {
8
8
  } from 'slate-react'
9
9
  import type {EventPositionBlock} from '../../internal-utils/event-position'
10
10
  import type {
11
+ BlockRenderProps,
11
12
  PortableTextMemberSchemaTypes,
12
13
  RenderBlockFunction,
13
14
  } from '../../types/editor'
@@ -73,7 +74,8 @@ export function RenderBlockObject(props: {
73
74
  draggable={!props.readOnly}
74
75
  >
75
76
  {props.renderBlock && legacySchemaType ? (
76
- <props.renderBlock
77
+ <RenderBlock
78
+ renderBlock={props.renderBlock}
77
79
  editorElementRef={blockObjectRef}
78
80
  focused={focused}
79
81
  path={[{_key: props.element._key}]}
@@ -83,7 +85,7 @@ export function RenderBlockObject(props: {
83
85
  value={blockObject}
84
86
  >
85
87
  <RenderDefaultBlockObject blockObject={blockObject} />
86
- </props.renderBlock>
88
+ </RenderBlock>
87
89
  ) : (
88
90
  <RenderDefaultBlockObject blockObject={blockObject} />
89
91
  )}
@@ -92,3 +94,28 @@ export function RenderBlockObject(props: {
92
94
  </div>
93
95
  )
94
96
  }
97
+
98
+ function RenderBlock({
99
+ renderBlock,
100
+ children,
101
+ editorElementRef,
102
+ focused,
103
+ path,
104
+ schemaType,
105
+ selected,
106
+ type,
107
+ value,
108
+ }: {
109
+ renderBlock: RenderBlockFunction
110
+ } & BlockRenderProps) {
111
+ return renderBlock({
112
+ children,
113
+ editorElementRef,
114
+ focused,
115
+ path,
116
+ schemaType,
117
+ selected,
118
+ type,
119
+ value,
120
+ })
121
+ }
@@ -9,6 +9,7 @@ import {
9
9
  } from 'slate-react'
10
10
  import {getPointBlock} from '../../internal-utils/slate-utils'
11
11
  import type {
12
+ BlockChildRenderProps,
12
13
  PortableTextMemberSchemaTypes,
13
14
  RenderChildFunction,
14
15
  } from '../../types/editor'
@@ -79,7 +80,8 @@ export function RenderInlineObject(props: {
79
80
  {props.children}
80
81
  <span ref={inlineObjectRef} style={{display: 'inline-block'}}>
81
82
  {props.renderChild && block && legacySchemaType ? (
82
- <props.renderChild
83
+ <RenderChild
84
+ renderChild={props.renderChild}
83
85
  annotations={[]}
84
86
  editorElementRef={inlineObjectRef}
85
87
  selected={selected}
@@ -90,7 +92,7 @@ export function RenderInlineObject(props: {
90
92
  type={legacySchemaType}
91
93
  >
92
94
  <RenderDefaultInlineObject inlineObject={inlineObject} />
93
- </props.renderChild>
95
+ </RenderChild>
94
96
  ) : (
95
97
  <RenderDefaultInlineObject inlineObject={inlineObject} />
96
98
  )}
@@ -98,3 +100,30 @@ export function RenderInlineObject(props: {
98
100
  </span>
99
101
  )
100
102
  }
103
+
104
+ function RenderChild({
105
+ renderChild,
106
+ annotations,
107
+ children,
108
+ editorElementRef,
109
+ focused,
110
+ path,
111
+ schemaType,
112
+ selected,
113
+ value,
114
+ type,
115
+ }: {
116
+ renderChild: RenderChildFunction
117
+ } & BlockChildRenderProps) {
118
+ return renderChild({
119
+ annotations,
120
+ children,
121
+ editorElementRef,
122
+ focused,
123
+ path,
124
+ schemaType,
125
+ selected,
126
+ value,
127
+ type,
128
+ })
129
+ }
@@ -9,6 +9,9 @@ import {
9
9
  isSelectionCollapsed,
10
10
  } from '../../selectors'
11
11
  import type {
12
+ BlockAnnotationRenderProps,
13
+ BlockChildRenderProps,
14
+ BlockDecoratorRenderProps,
12
15
  EditorSelection,
13
16
  RenderAnnotationFunction,
14
17
  RenderChildFunction,
@@ -140,7 +143,8 @@ export function RenderSpan(props: RenderSpanProps) {
140
143
 
141
144
  if (path && legacyDecoratorSchemaType && props.renderDecorator) {
142
145
  children = (
143
- <props.renderDecorator
146
+ <RenderDecorator
147
+ renderDecorator={props.renderDecorator}
144
148
  editorElementRef={spanRef}
145
149
  focused={focused}
146
150
  path={path}
@@ -150,7 +154,7 @@ export function RenderSpan(props: RenderSpanProps) {
150
154
  type={legacyDecoratorSchemaType}
151
155
  >
152
156
  {children}
153
- </props.renderDecorator>
157
+ </RenderDecorator>
154
158
  )
155
159
  }
156
160
  }
@@ -166,7 +170,8 @@ export function RenderSpan(props: RenderSpanProps) {
166
170
  if (block && path && props.renderAnnotation) {
167
171
  children = (
168
172
  <span ref={spanRef}>
169
- <props.renderAnnotation
173
+ <RenderAnnotation
174
+ renderAnnotation={props.renderAnnotation}
170
175
  block={block}
171
176
  editorElementRef={spanRef}
172
177
  focused={focused}
@@ -177,7 +182,7 @@ export function RenderSpan(props: RenderSpanProps) {
177
182
  type={legacyAnnotationSchemaType}
178
183
  >
179
184
  {children}
180
- </props.renderAnnotation>
185
+ </RenderAnnotation>
181
186
  </span>
182
187
  )
183
188
  } else {
@@ -196,7 +201,8 @@ export function RenderSpan(props: RenderSpanProps) {
196
201
 
197
202
  if (child) {
198
203
  children = (
199
- <props.renderChild
204
+ <RenderChild
205
+ renderChild={props.renderChild}
200
206
  annotations={annotationMarkDefs}
201
207
  editorElementRef={spanRef}
202
208
  focused={focused}
@@ -207,7 +213,7 @@ export function RenderSpan(props: RenderSpanProps) {
207
213
  type={legacySchema.span}
208
214
  >
209
215
  {children}
210
- </props.renderChild>
216
+ </RenderChild>
211
217
  )
212
218
  }
213
219
  }
@@ -218,3 +224,82 @@ export function RenderSpan(props: RenderSpanProps) {
218
224
  </span>
219
225
  )
220
226
  }
227
+
228
+ function RenderAnnotation({
229
+ renderAnnotation,
230
+ block,
231
+ children,
232
+ editorElementRef,
233
+ focused,
234
+ path,
235
+ schemaType,
236
+ selected,
237
+ value,
238
+ type,
239
+ }: {
240
+ renderAnnotation: RenderAnnotationFunction
241
+ } & BlockAnnotationRenderProps) {
242
+ return renderAnnotation({
243
+ block,
244
+ children,
245
+ editorElementRef,
246
+ focused,
247
+ path,
248
+ schemaType,
249
+ selected,
250
+ value,
251
+ type,
252
+ })
253
+ }
254
+
255
+ function RenderDecorator({
256
+ renderDecorator,
257
+ children,
258
+ editorElementRef,
259
+ focused,
260
+ path,
261
+ schemaType,
262
+ selected,
263
+ value,
264
+ type,
265
+ }: {
266
+ renderDecorator: RenderDecoratorFunction
267
+ } & BlockDecoratorRenderProps) {
268
+ return renderDecorator({
269
+ children,
270
+ editorElementRef,
271
+ focused,
272
+ path,
273
+ schemaType,
274
+ selected,
275
+ value,
276
+ type,
277
+ })
278
+ }
279
+
280
+ function RenderChild({
281
+ renderChild,
282
+ annotations,
283
+ children,
284
+ editorElementRef,
285
+ focused,
286
+ path,
287
+ schemaType,
288
+ selected,
289
+ value,
290
+ type,
291
+ }: {
292
+ renderChild: RenderChildFunction
293
+ } & BlockChildRenderProps) {
294
+ return renderChild({
295
+ annotations,
296
+ children,
297
+ editorElementRef,
298
+ focused,
299
+ path,
300
+ schemaType,
301
+ selected,
302
+ value,
303
+ type,
304
+ })
305
+ }