@portabletext/editor 1.36.1 → 1.36.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/lib/_chunks-cjs/editor-provider.cjs +24 -13
  2. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  3. package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
  4. package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs.map +1 -1
  5. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
  6. package/lib/_chunks-es/editor-provider.js +24 -13
  7. package/lib/_chunks-es/editor-provider.js.map +1 -1
  8. package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
  9. package/lib/_chunks-es/util.block-offsets-to-selection.js.map +1 -1
  10. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  11. package/lib/behaviors/index.d.cts +7 -10
  12. package/lib/behaviors/index.d.ts +7 -10
  13. package/lib/index.cjs +140 -104
  14. package/lib/index.cjs.map +1 -1
  15. package/lib/index.d.cts +13 -26
  16. package/lib/index.d.ts +13 -26
  17. package/lib/index.js +142 -106
  18. package/lib/index.js.map +1 -1
  19. package/lib/plugins/index.cjs.map +1 -1
  20. package/lib/plugins/index.d.cts +2 -7
  21. package/lib/plugins/index.d.ts +2 -7
  22. package/lib/plugins/index.js.map +1 -1
  23. package/lib/selectors/index.cjs.map +1 -1
  24. package/lib/selectors/index.d.cts +8 -13
  25. package/lib/selectors/index.d.ts +8 -13
  26. package/lib/selectors/index.js.map +1 -1
  27. package/lib/utils/index.cjs.map +1 -1
  28. package/lib/utils/index.d.cts +3 -6
  29. package/lib/utils/index.d.ts +3 -6
  30. package/lib/utils/index.js.map +1 -1
  31. package/package.json +9 -8
  32. package/src/behavior-actions/behavior.actions.ts +2 -2
  33. package/src/behaviors/behavior.decorator-pair.ts +2 -1
  34. package/src/behaviors/index.ts +0 -8
  35. package/src/converters/converter.text-html.deserialize.test.ts +1 -1
  36. package/src/converters/converter.text-html.serialize.test.ts +1 -1
  37. package/src/converters/converter.text-html.ts +8 -0
  38. package/src/converters/converter.text-plain.test.ts +1 -1
  39. package/src/converters/converter.text-plain.ts +8 -0
  40. package/src/editor/Editable.tsx +1 -1
  41. package/src/editor/__tests__/PortableTextEditor.test.tsx +16 -20
  42. package/src/editor/components/Element.tsx +26 -18
  43. package/src/editor/components/drop-indicator.tsx +14 -0
  44. package/src/editor/components/{DraggableBlock.tsx → use-draggable.ts} +42 -163
  45. package/src/editor/components/use-droppable.ts +135 -0
  46. package/src/editor/create-slate-editor.tsx +0 -3
  47. package/src/index.ts +48 -12
  48. package/src/internal-utils/create-test-snapshot.ts +1 -1
  49. package/src/plugins/plugin.decorator-shortcut.ts +1 -1
  50. package/src/plugins/plugin.markdown.tsx +1 -0
  51. package/src/selectors/index.ts +0 -8
  52. package/src/selectors/selector.get-active-annotations.test.ts +1 -1
  53. package/src/selectors/selector.get-caret-word-selection.test.ts +1 -1
  54. package/src/selectors/selector.get-selected-spans.test.ts +2 -1
  55. package/src/selectors/selector.get-selection-end-point.ts +1 -1
  56. package/src/selectors/selector.get-selection-start-point.ts +1 -1
  57. package/src/selectors/selector.get-selection-text.test.ts +1 -1
  58. package/src/selectors/selector.get-selection.ts +2 -1
  59. package/src/selectors/selector.get-value.ts +1 -1
  60. package/src/selectors/selector.is-active-decorator.test.ts +1 -1
  61. package/src/types/editor.ts +6 -16
  62. package/src/types/slate.ts +1 -1
  63. package/src/utils/index.ts +0 -1
  64. package/src/utils/util.block-offsets-to-selection.ts +1 -1
  65. package/src/utils/util.is-span.ts +1 -1
  66. package/src/utils/util.is-text-block.ts +1 -1
  67. package/src/utils/util.merge-text-blocks.ts +1 -1
  68. package/src/utils/util.slice-blocks.ts +1 -1
  69. package/src/utils/util.split-text-block.ts +4 -2
package/lib/index.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/internal-utils/selection.ts","../src/editor/components/DefaultObject.tsx","../src/editor/components/DraggableBlock.tsx","../src/editor/components/Element.tsx","../src/editor/components/Leaf.tsx","../src/editor/plugins/createWithHotKeys.ts","../src/editor/withSyncRangeDecorations.ts","../src/editor/Editable.tsx","../src/editor-event-listener.tsx"],"sourcesContent":["import type {Path, PortableTextBlock} from '@sanity/types'\nimport {isEqual} from 'lodash'\nimport type {EditorSelection, EditorSelectionPoint} from '../types/editor'\n\nexport function normalizePoint(\n point: EditorSelectionPoint,\n value: PortableTextBlock[],\n): EditorSelectionPoint | null {\n if (!point || !value) {\n return null\n }\n const newPath: Path = []\n let newOffset: number = point.offset || 0\n const blockKey =\n typeof point.path[0] === 'object' &&\n '_key' in point.path[0] &&\n point.path[0]._key\n const childKey =\n typeof point.path[2] === 'object' &&\n '_key' in point.path[2] &&\n point.path[2]._key\n const block: PortableTextBlock | undefined = value.find(\n (blk) => blk._key === blockKey,\n )\n if (block) {\n newPath.push({_key: block._key})\n } else {\n return null\n }\n if (block && point.path[1] === 'children') {\n if (\n !block.children ||\n (Array.isArray(block.children) && block.children.length === 0)\n ) {\n return null\n }\n const child =\n Array.isArray(block.children) &&\n block.children.find((cld) => cld._key === childKey)\n if (child) {\n newPath.push('children')\n newPath.push({_key: child._key})\n newOffset =\n child.text && child.text.length >= point.offset\n ? point.offset\n : (child.text && child.text.length) || 0\n } else {\n return null\n }\n }\n return {path: newPath, offset: newOffset}\n}\n\nexport function normalizeSelection(\n selection: EditorSelection,\n value: PortableTextBlock[] | undefined,\n): EditorSelection | null {\n if (!selection || !value || value.length === 0) {\n return null\n }\n let newAnchor: EditorSelectionPoint | null = null\n let newFocus: EditorSelectionPoint | null = null\n const {anchor, focus} = selection\n if (\n anchor &&\n value.find((blk) => isEqual({_key: blk._key}, anchor.path[0]))\n ) {\n newAnchor = normalizePoint(anchor, value)\n }\n if (focus && value.find((blk) => isEqual({_key: blk._key}, focus.path[0]))) {\n newFocus = normalizePoint(focus, value)\n }\n if (newAnchor && newFocus) {\n return {anchor: newAnchor, focus: newFocus, backward: selection.backward}\n }\n return null\n}\n","import type {PortableTextBlock, PortableTextChild} from '@sanity/types'\n\nexport function DefaultBlockObject(props: {\n value: PortableTextBlock | PortableTextChild\n}) {\n return (\n <div style={{userSelect: 'none'}}>\n [{props.value._type}: {props.value._key}]\n </div>\n )\n}\n\nexport function DefaultInlineObject(props: {\n value: PortableTextBlock | PortableTextChild\n}) {\n return (\n <span style={{userSelect: 'none'}}>\n [{props.value._type}: {props.value._key}]\n </span>\n )\n}\n","import {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type DragEvent,\n type MutableRefObject,\n type ReactNode,\n} from 'react'\nimport {Editor, Path, Transforms, type Element as SlateElement} from 'slate'\nimport {ReactEditor, useSlateStatic} from 'slate-react'\nimport {debugWithName} from '../../internal-utils/debug'\nimport {\n IS_DRAGGING,\n IS_DRAGGING_BLOCK_ELEMENT,\n IS_DRAGGING_BLOCK_TARGET_POSITION,\n IS_DRAGGING_ELEMENT_TARGET,\n} from '../../internal-utils/weakMaps'\n\nconst debug = debugWithName('components:DraggableBlock')\nconst debugRenders = false\n\n/**\n * @internal\n */\nexport interface DraggableBlockProps {\n children: ReactNode\n element: SlateElement\n readOnly: boolean\n blockRef: MutableRefObject<HTMLDivElement | null>\n}\n\n/**\n * Implements drag and drop functionality on editor block nodes\n * @internal\n */\nexport const DraggableBlock = ({\n children,\n element,\n readOnly,\n blockRef,\n}: DraggableBlockProps) => {\n const editor = useSlateStatic()\n const dragGhostRef = useRef<HTMLElement>(undefined)\n const [isDragOver, setIsDragOver] = useState(false)\n const isVoid = useMemo(\n () => Editor.isVoid(editor, element),\n [editor, element],\n )\n const isInline = useMemo(\n () => Editor.isInline(editor, element),\n [editor, element],\n )\n\n const [blockElement, setBlockElement] = useState<HTMLElement | null>(null)\n\n useEffect(\n () =>\n setBlockElement(\n blockRef ? blockRef.current : ReactEditor.toDOMNode(editor, element),\n ),\n [editor, element, blockRef],\n )\n\n // Note: this is called not for the dragging block, but for the targets when the block is dragged over them\n const handleDragOver = useCallback(\n (event: DragEvent) => {\n const isMyDragOver = IS_DRAGGING_BLOCK_ELEMENT.get(editor)\n // debug('Drag over', blockElement)\n if (!isMyDragOver || !blockElement) {\n return\n }\n event.preventDefault()\n event.dataTransfer.dropEffect = 'move'\n IS_DRAGGING_ELEMENT_TARGET.set(editor, element)\n const elementRect = blockElement.getBoundingClientRect()\n const offset = elementRect.top\n const height = elementRect.height\n const Y = event.pageY\n const loc = Math.abs(offset - Y)\n let position: 'top' | 'bottom' = 'bottom'\n if (element === editor.children[0]) {\n position = 'top'\n } else if (loc < height / 2) {\n position = 'top'\n IS_DRAGGING_BLOCK_TARGET_POSITION.set(editor, position)\n } else {\n position = 'bottom'\n IS_DRAGGING_BLOCK_TARGET_POSITION.set(editor, position)\n }\n if (isMyDragOver === element) {\n event.dataTransfer.dropEffect = 'none'\n return\n }\n setIsDragOver(true)\n },\n [blockElement, editor, element],\n )\n\n // Note: this is called not for the dragging block, but for the targets when the block is dragged over them\n const handleDragLeave = useCallback(() => {\n setIsDragOver(false)\n }, [])\n\n // Note: this is called for the dragging block\n const handleDragEnd = useCallback(\n (event: DragEvent) => {\n const targetBlock = IS_DRAGGING_ELEMENT_TARGET.get(editor)\n if (targetBlock) {\n IS_DRAGGING.set(editor, false)\n event.preventDefault()\n event.stopPropagation()\n IS_DRAGGING_ELEMENT_TARGET.delete(editor)\n if (dragGhostRef.current) {\n debug('Removing drag ghost')\n document.body.removeChild(dragGhostRef.current)\n }\n const dragPosition = IS_DRAGGING_BLOCK_TARGET_POSITION.get(editor)\n IS_DRAGGING_BLOCK_TARGET_POSITION.delete(editor)\n let targetPath = ReactEditor.findPath(editor, targetBlock)\n const myPath = ReactEditor.findPath(editor, element)\n const isBefore = Path.isBefore(myPath, targetPath)\n if (dragPosition === 'bottom' && !isBefore) {\n // If it is already at the bottom, don't do anything.\n if (targetPath[0] >= editor.children.length - 1) {\n debug('target is already at the bottom, not moving')\n return\n }\n const originalPath = targetPath\n targetPath = Path.next(targetPath)\n debug(\n `Adjusting targetPath from ${JSON.stringify(originalPath)} to ${JSON.stringify(\n targetPath,\n )}`,\n )\n }\n if (\n dragPosition === 'top' &&\n isBefore &&\n targetPath[0] !== editor.children.length - 1\n ) {\n const originalPath = targetPath\n targetPath = Path.previous(targetPath)\n debug(\n `Adjusting targetPath from ${JSON.stringify(originalPath)} to ${JSON.stringify(\n targetPath,\n )}`,\n )\n }\n if (Path.equals(targetPath, myPath)) {\n event.preventDefault()\n debug('targetPath and myPath is the same, not moving')\n return\n }\n debug(\n `Moving element ${element._key} from path ${JSON.stringify(myPath)} to ${JSON.stringify(\n targetPath,\n )} (${dragPosition})`,\n )\n Transforms.moveNodes(editor, {at: myPath, to: targetPath})\n editor.onChange()\n return\n }\n debug('No target element, not doing anything')\n },\n [editor, element],\n )\n // Note: this is called not for the dragging block, but for the drop target\n const handleDrop = useCallback(\n (event: DragEvent) => {\n if (IS_DRAGGING_BLOCK_ELEMENT.get(editor)) {\n debug('On drop (prevented)', element)\n event.preventDefault()\n event.stopPropagation()\n setIsDragOver(false)\n }\n },\n [editor, element],\n )\n // Note: this is called for the dragging block\n const handleDrag = useCallback(\n (event: DragEvent) => {\n if (!isVoid) {\n IS_DRAGGING_BLOCK_ELEMENT.delete(editor)\n return\n }\n IS_DRAGGING.set(editor, true)\n IS_DRAGGING_BLOCK_ELEMENT.set(editor, element)\n event.stopPropagation() // Stop propagation so that leafs don't get this and take focus/selection!\n\n const target = event.target\n\n if (target instanceof HTMLElement) {\n target.style.opacity = '1'\n }\n },\n [editor, element, isVoid],\n )\n\n // Note: this is called for the dragging block\n const handleDragStart = useCallback(\n (event: DragEvent) => {\n if (!isVoid || isInline) {\n debug('Not dragging block')\n IS_DRAGGING_BLOCK_ELEMENT.delete(editor)\n IS_DRAGGING.set(editor, false)\n return\n }\n debug('Drag start')\n IS_DRAGGING.set(editor, true)\n if (event.dataTransfer) {\n event.dataTransfer.setData('application/portable-text', 'something')\n event.dataTransfer.effectAllowed = 'move'\n }\n // Clone blockElement so that it will not be visually clipped by scroll-containers etc.\n // The application that uses the portable-text-editor may indicate the element used as\n // drag ghost by adding a truthy data attribute 'data-pt-drag-ghost-element' to a HTML element.\n if (blockElement && blockElement instanceof HTMLElement) {\n let dragGhost = blockElement.cloneNode(true) as HTMLElement\n const customGhost = dragGhost.querySelector(\n '[data-pt-drag-ghost-element]',\n )\n if (customGhost) {\n dragGhost = customGhost as HTMLElement\n }\n\n // Set the `data-dragged` attribute so the consumer can style the element while it’s dragged\n dragGhost.setAttribute('data-dragged', '')\n\n if (document.body) {\n dragGhostRef.current = dragGhost\n dragGhost.style.position = 'absolute'\n dragGhost.style.left = '-99999px'\n dragGhost.style.boxSizing = 'border-box'\n document.body.appendChild(dragGhost)\n const rect = blockElement.getBoundingClientRect()\n const x = event.clientX - rect.left\n const y = event.clientY - rect.top\n dragGhost.style.width = `${rect.width}px`\n dragGhost.style.height = `${rect.height}px`\n event.dataTransfer.setDragImage(dragGhost, x, y)\n }\n }\n handleDrag(event)\n },\n [blockElement, editor, handleDrag, isInline, isVoid],\n )\n\n const isDraggingOverFirstBlock =\n isDragOver && editor.children[0] === IS_DRAGGING_ELEMENT_TARGET.get(editor)\n const isDraggingOverLastBlock =\n isDragOver &&\n editor.children[editor.children.length - 1] ===\n IS_DRAGGING_ELEMENT_TARGET.get(editor)\n const dragPosition = IS_DRAGGING_BLOCK_TARGET_POSITION.get(editor)\n\n const isDraggingOverTop =\n isDraggingOverFirstBlock ||\n (isDragOver &&\n !isDraggingOverFirstBlock &&\n !isDraggingOverLastBlock &&\n dragPosition === 'top')\n const isDraggingOverBottom =\n isDraggingOverLastBlock ||\n (isDragOver &&\n !isDraggingOverFirstBlock &&\n !isDraggingOverLastBlock &&\n dragPosition === 'bottom')\n\n const dropIndicator = useMemo(\n () => (\n <div\n className=\"pt-drop-indicator\"\n style={{\n position: 'absolute',\n width: '100%',\n height: 1,\n borderBottom: '1px solid currentColor',\n zIndex: 5,\n }}\n />\n ),\n [],\n )\n\n if (readOnly) {\n return <>{children}</>\n }\n\n if (debugRenders) {\n debug('render')\n }\n\n return (\n <div\n draggable={isVoid}\n onDragStart={handleDragStart}\n onDrag={handleDrag}\n onDragOver={handleDragOver}\n onDragLeave={handleDragLeave}\n onDragEnd={handleDragEnd}\n onDrop={handleDrop}\n >\n {isDraggingOverTop && dropIndicator}\n {children}\n {isDraggingOverBottom && dropIndicator}\n </div>\n )\n}\n\nDraggableBlock.displayName = 'DraggableBlock'\n","import type {\n Path,\n PortableTextChild,\n PortableTextObject,\n PortableTextTextBlock,\n} from '@sanity/types'\nimport {\n useMemo,\n useRef,\n type FunctionComponent,\n type JSX,\n type ReactElement,\n} from 'react'\nimport {Editor, Range, Element as SlateElement} from 'slate'\nimport {\n ReactEditor,\n useSelected,\n useSlateStatic,\n type RenderElementProps,\n} from 'slate-react'\nimport {debugWithName} from '../../internal-utils/debug'\nimport {fromSlateValue} from '../../internal-utils/values'\nimport {KEY_TO_VALUE_ELEMENT} from '../../internal-utils/weakMaps'\nimport type {\n BlockRenderProps,\n PortableTextMemberSchemaTypes,\n RenderBlockFunction,\n RenderChildFunction,\n RenderListItemFunction,\n RenderStyleFunction,\n} from '../../types/editor'\nimport {DefaultBlockObject, DefaultInlineObject} from './DefaultObject'\nimport {DraggableBlock} from './DraggableBlock'\n\nconst debug = debugWithName('components:Element')\nconst debugRenders = false\nconst EMPTY_ANNOTATIONS: PortableTextObject[] = []\n\n/**\n * @internal\n */\nexport interface ElementProps {\n attributes: RenderElementProps['attributes']\n children: ReactElement<any>\n element: SlateElement\n schemaTypes: PortableTextMemberSchemaTypes\n readOnly: boolean\n renderBlock?: RenderBlockFunction\n renderChild?: RenderChildFunction\n renderListItem?: RenderListItemFunction\n renderStyle?: RenderStyleFunction\n spellCheck?: boolean\n}\n\nconst inlineBlockStyle = {display: 'inline-block'}\n\n/**\n * Renders Portable Text block and inline object nodes in Slate\n * @internal\n */\nexport const Element: FunctionComponent<ElementProps> = ({\n attributes,\n children,\n element,\n schemaTypes,\n readOnly,\n renderBlock,\n renderChild,\n renderListItem,\n renderStyle,\n spellCheck,\n}) => {\n const editor = useSlateStatic()\n const selected = useSelected()\n const blockRef = useRef<HTMLDivElement | null>(null)\n const inlineBlockObjectRef = useRef(null)\n const focused =\n (selected && editor.selection && Range.isCollapsed(editor.selection)) ||\n false\n\n const value = useMemo(\n () =>\n fromSlateValue(\n [element],\n schemaTypes.block.name,\n KEY_TO_VALUE_ELEMENT.get(editor),\n )[0],\n [editor, element, schemaTypes.block.name],\n )\n\n let renderedBlock = children\n\n let className: string | undefined\n\n const blockPath: Path = useMemo(() => [{_key: element._key}], [element])\n\n if (typeof element._type !== 'string') {\n throw new Error(`Expected element to have a _type property`)\n }\n\n if (typeof element._key !== 'string') {\n throw new Error(`Expected element to have a _key property`)\n }\n\n // Test for inline objects first\n if (editor.isInline(element)) {\n const path = ReactEditor.findPath(editor, element)\n const [block] = Editor.node(editor, path, {depth: 1})\n const schemaType = schemaTypes.inlineObjects.find(\n (_type) => _type.name === element._type,\n )\n if (!schemaType) {\n throw new Error('Could not find type for inline block element')\n }\n if (SlateElement.isElement(block)) {\n const elmPath: Path = [\n {_key: block._key},\n 'children',\n {_key: element._key},\n ]\n if (debugRenders) {\n debug(`Render ${element._key} (inline object)`)\n }\n return (\n <span {...attributes}>\n {/* Note that children must follow immediately or cut and selections will not work properly in Chrome. */}\n {children}\n <span\n draggable={!readOnly}\n className=\"pt-inline-object\"\n data-testid=\"pt-inline-object\"\n ref={inlineBlockObjectRef}\n key={element._key}\n style={inlineBlockStyle}\n contentEditable={false}\n >\n {renderChild &&\n renderChild({\n annotations: EMPTY_ANNOTATIONS, // These inline objects currently doesn't support annotations. This is a limitation of the current PT spec/model.\n children: <DefaultInlineObject value={value} />,\n editorElementRef: inlineBlockObjectRef,\n focused,\n path: elmPath,\n schemaType,\n selected,\n type: schemaType,\n value: value as PortableTextChild,\n })}\n {!renderChild && <DefaultInlineObject value={value} />}\n </span>\n </span>\n )\n }\n throw new Error('Block not found!')\n }\n\n // If not inline, it's either a block (text) or a block object (non-text)\n // NOTE: text blocks aren't draggable with DraggableBlock (yet?)\n if (element._type === schemaTypes.block.name) {\n className = `pt-block pt-text-block`\n const isListItem = 'listItem' in element\n if (debugRenders) {\n debug(`Render ${element._key} (text block)`)\n }\n const style = ('style' in element && element.style) || 'normal'\n className = `pt-block pt-text-block pt-text-block-style-${style}`\n const blockStyleType = schemaTypes.styles.find(\n (item) => item.value === style,\n )\n if (renderStyle && blockStyleType) {\n renderedBlock = renderStyle({\n block: element as PortableTextTextBlock,\n children,\n focused,\n selected,\n value: style,\n path: blockPath,\n schemaType: blockStyleType,\n editorElementRef: blockRef,\n })\n }\n let level: number | undefined\n\n if (isListItem) {\n if (typeof element.level === 'number') {\n level = element.level\n }\n className += ` pt-list-item pt-list-item-${element.listItem} pt-list-item-level-${level || 1}`\n }\n\n if (editor.isListBlock(value) && isListItem && element.listItem) {\n const listType = schemaTypes.lists.find(\n (item) => item.value === element.listItem,\n )\n if (renderListItem && listType) {\n renderedBlock = renderListItem({\n block: value,\n children: renderedBlock,\n focused,\n selected,\n value: element.listItem,\n path: blockPath,\n schemaType: listType,\n level: value.level || 1,\n editorElementRef: blockRef,\n })\n }\n }\n\n const renderProps: Omit<BlockRenderProps, 'type'> = Object.defineProperty(\n {\n children: renderedBlock,\n editorElementRef: blockRef,\n focused,\n level,\n listItem: isListItem ? element.listItem : undefined,\n path: blockPath,\n selected,\n style,\n schemaType: schemaTypes.block,\n value,\n },\n 'type',\n {\n enumerable: false,\n get() {\n console.warn(\n \"Property 'type' is deprecated, use 'schemaType' instead.\",\n )\n return schemaTypes.block\n },\n },\n )\n\n const propsOrDefaultRendered = renderBlock\n ? renderBlock(renderProps as BlockRenderProps)\n : children\n return (\n <div\n key={element._key}\n {...attributes}\n className={className}\n spellCheck={spellCheck}\n >\n <DraggableBlock\n element={element}\n readOnly={readOnly}\n blockRef={blockRef}\n >\n <div ref={blockRef}>{propsOrDefaultRendered}</div>\n </DraggableBlock>\n </div>\n )\n }\n\n const schemaType = schemaTypes.blockObjects.find(\n (_type) => _type.name === element._type,\n )\n\n if (!schemaType) {\n throw new Error(\n `Could not find schema type for block element of _type ${element._type}`,\n )\n }\n\n if (debugRenders) {\n debug(`Render ${element._key} (object block)`)\n }\n\n className = 'pt-block pt-object-block'\n\n const block = fromSlateValue(\n [element],\n schemaTypes.block.name,\n KEY_TO_VALUE_ELEMENT.get(editor),\n )[0]\n\n let renderedBlockFromProps: JSX.Element | undefined\n\n if (renderBlock) {\n const _props: Omit<BlockRenderProps, 'type'> = Object.defineProperty(\n {\n children: <DefaultBlockObject value={value} />,\n editorElementRef: blockRef,\n focused,\n path: blockPath,\n schemaType,\n selected,\n value: block,\n },\n 'type',\n {\n enumerable: false,\n get() {\n console.warn(\n \"Property 'type' is deprecated, use 'schemaType' instead.\",\n )\n return schemaType\n },\n },\n )\n renderedBlockFromProps = renderBlock(_props as BlockRenderProps)\n }\n\n return (\n <div key={element._key} {...attributes} className={className}>\n {children}\n <DraggableBlock element={element} readOnly={readOnly} blockRef={blockRef}>\n <div ref={blockRef} contentEditable={false}>\n {renderedBlockFromProps ? (\n renderedBlockFromProps\n ) : (\n <DefaultBlockObject value={value} />\n )}\n </div>\n </DraggableBlock>\n </div>\n )\n}\n\nElement.displayName = 'Element'\n","import type {\n Path,\n PortableTextObject,\n PortableTextTextBlock,\n} from '@sanity/types'\nimport {isEqual, uniq} from 'lodash'\nimport {\n startTransition,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ReactElement,\n} from 'react'\nimport {Text} from 'slate'\nimport {useSelected, type RenderLeafProps} from 'slate-react'\nimport {debugWithName} from '../../internal-utils/debug'\nimport type {\n BlockAnnotationRenderProps,\n BlockChildRenderProps,\n BlockDecoratorRenderProps,\n PortableTextMemberSchemaTypes,\n RenderAnnotationFunction,\n RenderChildFunction,\n RenderDecoratorFunction,\n} from '../../types/editor'\nimport type {EditorActor} from '../editor-machine'\nimport {usePortableTextEditor} from '../hooks/usePortableTextEditor'\nimport {PortableTextEditor} from '../PortableTextEditor'\n\nconst debug = debugWithName('components:Leaf')\n\nconst EMPTY_MARKS: string[] = []\n\n/**\n * @internal\n */\nexport interface LeafProps extends RenderLeafProps {\n editorActor: EditorActor\n children: ReactElement<any>\n schemaTypes: PortableTextMemberSchemaTypes\n renderAnnotation?: RenderAnnotationFunction\n renderChild?: RenderChildFunction\n renderDecorator?: RenderDecoratorFunction\n readOnly: boolean\n}\n\n/**\n * Renders Portable Text span nodes in Slate\n * @internal\n */\nexport const Leaf = (props: LeafProps) => {\n const {\n editorActor,\n attributes,\n children,\n leaf,\n schemaTypes,\n renderChild,\n renderDecorator,\n renderAnnotation,\n } = props\n const spanRef = useRef<HTMLElement>(null)\n const portableTextEditor = usePortableTextEditor()\n const blockSelected = useSelected()\n const [focused, setFocused] = useState(false)\n const [selected, setSelected] = useState(false)\n const block = children.props.parent as PortableTextTextBlock | undefined\n const path: Path = useMemo(\n () => (block ? [{_key: block?._key}, 'children', {_key: leaf._key}] : []),\n [block, leaf._key],\n )\n const decoratorValues = useMemo(\n () => schemaTypes.decorators.map((dec) => dec.value),\n [schemaTypes.decorators],\n )\n const marks: string[] = useMemo(\n () =>\n uniq(\n (leaf.marks || EMPTY_MARKS).filter((mark) =>\n decoratorValues.includes(mark),\n ),\n ),\n [decoratorValues, leaf.marks],\n )\n const annotationMarks = Array.isArray(leaf.marks) ? leaf.marks : EMPTY_MARKS\n const annotations = useMemo(\n () =>\n annotationMarks\n .map(\n (mark) =>\n !decoratorValues.includes(mark) &&\n block?.markDefs?.find((def) => def._key === mark),\n )\n .filter(Boolean) as PortableTextObject[],\n [annotationMarks, block, decoratorValues],\n )\n\n const shouldTrackSelectionAndFocus = annotations.length > 0 && blockSelected\n\n useEffect(() => {\n if (!shouldTrackSelectionAndFocus) {\n setFocused(false)\n return\n }\n const sel = PortableTextEditor.getSelection(portableTextEditor)\n if (\n sel &&\n isEqual(sel.focus.path, path) &&\n PortableTextEditor.isCollapsedSelection(portableTextEditor)\n ) {\n startTransition(() => {\n setFocused(true)\n })\n }\n }, [shouldTrackSelectionAndFocus, path, portableTextEditor])\n\n // Function to check if this leaf is currently inside the user's text selection\n const setSelectedFromRange = useCallback(() => {\n if (!shouldTrackSelectionAndFocus) {\n return\n }\n debug('Setting selection and focus from range')\n const winSelection = window.getSelection()\n if (!winSelection) {\n setSelected(false)\n return\n }\n if (winSelection && winSelection.rangeCount > 0) {\n const range = winSelection.getRangeAt(0)\n if (spanRef.current && range.intersectsNode(spanRef.current)) {\n setSelected(true)\n } else {\n setSelected(false)\n }\n } else {\n setSelected(false)\n }\n }, [shouldTrackSelectionAndFocus])\n\n useEffect(() => {\n if (!shouldTrackSelectionAndFocus) {\n return undefined\n }\n\n const onBlur = editorActor.on('blur', () => {\n setFocused(false)\n setSelected(false)\n })\n\n const onFocus = editorActor.on('focus', () => {\n const sel = PortableTextEditor.getSelection(portableTextEditor)\n if (\n sel &&\n isEqual(sel.focus.path, path) &&\n PortableTextEditor.isCollapsedSelection(portableTextEditor)\n ) {\n setFocused(true)\n }\n setSelectedFromRange()\n })\n\n const onSelection = editorActor.on('selection', (event) => {\n if (\n event.selection &&\n isEqual(event.selection.focus.path, path) &&\n PortableTextEditor.isCollapsedSelection(portableTextEditor)\n ) {\n setFocused(true)\n } else {\n setFocused(false)\n }\n setSelectedFromRange()\n })\n\n return () => {\n onBlur.unsubscribe()\n onFocus.unsubscribe()\n onSelection.unsubscribe()\n }\n }, [\n editorActor,\n path,\n portableTextEditor,\n setSelectedFromRange,\n shouldTrackSelectionAndFocus,\n ])\n\n useEffect(() => setSelectedFromRange(), [setSelectedFromRange])\n\n const content = useMemo(() => {\n let returnedChildren = children\n // Render text nodes\n if (Text.isText(leaf) && leaf._type === schemaTypes.span.name) {\n marks.forEach((mark) => {\n const schemaType = schemaTypes.decorators.find(\n (dec) => dec.value === mark,\n )\n if (schemaType && renderDecorator) {\n const _props: Omit<BlockDecoratorRenderProps, 'type'> =\n Object.defineProperty(\n {\n children: returnedChildren,\n editorElementRef: spanRef,\n focused,\n path,\n selected,\n schemaType,\n value: mark,\n },\n 'type',\n {\n enumerable: false,\n get() {\n console.warn(\n \"Property 'type' is deprecated, use 'schemaType' instead.\",\n )\n return schemaType\n },\n },\n )\n returnedChildren = renderDecorator(\n _props as BlockDecoratorRenderProps,\n )\n }\n })\n\n if (block && annotations.length > 0) {\n annotations.forEach((annotation) => {\n const schemaType = schemaTypes.annotations.find(\n (t) => t.name === annotation._type,\n )\n if (schemaType) {\n if (renderAnnotation) {\n const _props: Omit<BlockAnnotationRenderProps, 'type'> =\n Object.defineProperty(\n {\n block,\n children: returnedChildren,\n editorElementRef: spanRef,\n focused,\n path,\n selected,\n schemaType,\n value: annotation,\n },\n 'type',\n {\n enumerable: false,\n get() {\n console.warn(\n \"Property 'type' is deprecated, use 'schemaType' instead.\",\n )\n return schemaType\n },\n },\n )\n\n returnedChildren = (\n <span ref={spanRef}>\n {renderAnnotation(_props as BlockAnnotationRenderProps)}\n </span>\n )\n } else {\n returnedChildren = <span ref={spanRef}>{returnedChildren}</span>\n }\n }\n })\n }\n if (block && renderChild) {\n const child = block.children.find((_child) => _child._key === leaf._key) // Ensure object equality\n if (child) {\n const defaultRendered = <>{returnedChildren}</>\n const _props: Omit<BlockChildRenderProps, 'type'> =\n Object.defineProperty(\n {\n annotations,\n children: defaultRendered,\n editorElementRef: spanRef,\n focused,\n path,\n schemaType: schemaTypes.span,\n selected,\n value: child,\n },\n 'type',\n {\n enumerable: false,\n get() {\n console.warn(\n \"Property 'type' is deprecated, use 'schemaType' instead.\",\n )\n return schemaTypes.span\n },\n },\n )\n returnedChildren = renderChild(_props as BlockChildRenderProps)\n }\n }\n }\n return returnedChildren\n }, [\n annotations,\n block,\n children,\n focused,\n leaf,\n marks,\n path,\n renderAnnotation,\n renderChild,\n renderDecorator,\n schemaTypes.annotations,\n schemaTypes.decorators,\n schemaTypes.span,\n selected,\n ])\n return useMemo(\n () => (\n <span key={leaf._key} {...attributes} ref={spanRef}>\n {content}\n </span>\n ),\n [leaf, attributes, content],\n )\n}\n\nLeaf.displayName = 'Leaf'\n","import type {KeyboardEvent} from 'react'\nimport type {ReactEditor} from 'slate-react'\nimport {debugWithName} from '../../internal-utils/debug'\nimport {isHotkey} from '../../internal-utils/is-hotkey'\nimport type {PortableTextSlateEditor} from '../../types/editor'\nimport type {HotkeyOptions} from '../../types/options'\nimport type {EditorActor} from '../editor-machine'\nimport type {PortableTextEditor} from '../PortableTextEditor'\n\nconst debug = debugWithName('plugin:withHotKeys')\n\n/**\n * This plugin takes care of all hotkeys in the editor\n *\n */\nexport function createWithHotkeys(\n editorActor: EditorActor,\n portableTextEditor: PortableTextEditor,\n hotkeysFromOptions?: HotkeyOptions,\n): (editor: PortableTextSlateEditor & ReactEditor) => any {\n const reservedHotkeys = ['enter', 'tab', 'shift', 'delete', 'end']\n const activeHotkeys = hotkeysFromOptions ?? {}\n return function withHotKeys(editor: PortableTextSlateEditor & ReactEditor) {\n editor.pteWithHotKeys = (event: KeyboardEvent<HTMLDivElement>): void => {\n // Wire up custom marks hotkeys\n Object.keys(activeHotkeys).forEach((cat) => {\n if (cat === 'marks') {\n for (const hotkey in activeHotkeys[cat]) {\n if (reservedHotkeys.includes(hotkey)) {\n throw new Error(`The hotkey ${hotkey} is reserved!`)\n }\n if (isHotkey(hotkey, event.nativeEvent)) {\n event.preventDefault()\n const possibleMark = activeHotkeys[cat]\n if (possibleMark) {\n const mark = possibleMark[hotkey]\n debug(`HotKey ${hotkey} to toggle ${mark}`)\n editorActor.send({\n type: 'behavior event',\n behaviorEvent: {\n type: 'decorator.toggle',\n decorator: mark,\n },\n editor,\n })\n }\n }\n }\n }\n if (cat === 'custom') {\n for (const hotkey in activeHotkeys[cat]) {\n if (reservedHotkeys.includes(hotkey)) {\n throw new Error(`The hotkey ${hotkey} is reserved!`)\n }\n if (isHotkey(hotkey, event.nativeEvent)) {\n const possibleCommand = activeHotkeys[cat]\n if (possibleCommand) {\n const command = possibleCommand[hotkey]\n command(event, portableTextEditor)\n }\n }\n }\n }\n })\n }\n return editor\n }\n}\n","import type {BaseEditor, Operation} from 'slate'\nimport type {ReactEditor} from 'slate-react'\nimport type {PortableTextSlateEditor} from '../types/editor'\nimport type {EditorActor} from './editor-machine'\n\n// React Compiler considers `slateEditor` as immutable, and opts-out if we do this inline in a useEffect, doing it in a function moves it out of the scope, and opts-in again for the rest of the component.\nexport function withSyncRangeDecorations({\n editorActor,\n slateEditor,\n syncRangeDecorations,\n}: {\n editorActor: EditorActor\n slateEditor: BaseEditor & ReactEditor & PortableTextSlateEditor\n syncRangeDecorations: (operation?: Operation) => void\n}) {\n const originalApply = slateEditor.apply\n\n slateEditor.apply = (op: Operation) => {\n originalApply(op)\n\n if (\n !editorActor.getSnapshot().matches({'edit mode': 'read only'}) &&\n op.type !== 'set_selection'\n ) {\n syncRangeDecorations(op)\n }\n }\n\n return () => {\n slateEditor.apply = originalApply\n }\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport {useSelector} from '@xstate/react'\nimport {isEqual, noop} from 'lodash'\nimport {\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n type ClipboardEvent,\n type CSSProperties,\n type FocusEventHandler,\n type KeyboardEvent,\n type MutableRefObject,\n type TextareaHTMLAttributes,\n} from 'react'\nimport {\n Editor,\n Node,\n Path,\n Range as SlateRange,\n Transforms,\n type BaseRange,\n type NodeEntry,\n type Operation,\n type Text,\n} from 'slate'\nimport {\n ReactEditor,\n Editable as SlateEditable,\n useSlate,\n type RenderElementProps,\n type RenderLeafProps,\n} from 'slate-react'\nimport {debugWithName} from '../internal-utils/debug'\nimport {\n moveRangeByOperation,\n toPortableTextRange,\n toSlateRange,\n} from '../internal-utils/ranges'\nimport {normalizeSelection} from '../internal-utils/selection'\nimport {\n fromSlateValue,\n isEqualToEmptyEditor,\n toSlateValue,\n} from '../internal-utils/values'\nimport type {\n EditorSelection,\n OnCopyFn,\n OnPasteFn,\n RangeDecoration,\n RenderAnnotationFunction,\n RenderBlockFunction,\n RenderChildFunction,\n RenderDecoratorFunction,\n RenderListItemFunction,\n RenderPlaceholderFunction,\n RenderStyleFunction,\n ScrollSelectionIntoViewFunction,\n} from '../types/editor'\nimport type {HotkeyOptions} from '../types/options'\nimport type {SlateTextBlock, VoidElement} from '../types/slate'\nimport {Element} from './components/Element'\nimport {Leaf} from './components/Leaf'\nimport {EditorActorContext} from './editor-actor-context'\nimport {usePortableTextEditor} from './hooks/usePortableTextEditor'\nimport {createWithHotkeys} from './plugins/createWithHotKeys'\nimport {PortableTextEditor} from './PortableTextEditor'\nimport {withSyncRangeDecorations} from './withSyncRangeDecorations'\n\nconst debug = debugWithName('component:Editable')\n\nconst PLACEHOLDER_STYLE: CSSProperties = {\n position: 'absolute',\n userSelect: 'none',\n pointerEvents: 'none',\n left: 0,\n right: 0,\n}\n\ninterface BaseRangeWithDecoration extends BaseRange {\n rangeDecoration: RangeDecoration\n}\n\n/**\n * @public\n */\nexport type PortableTextEditableProps = Omit<\n TextareaHTMLAttributes<HTMLDivElement>,\n 'onPaste' | 'onCopy' | 'onBeforeInput'\n> & {\n hotkeys?: HotkeyOptions\n onBeforeInput?: (event: InputEvent) => void\n onPaste?: OnPasteFn\n onCopy?: OnCopyFn\n ref: MutableRefObject<HTMLDivElement | null>\n rangeDecorations?: RangeDecoration[]\n renderAnnotation?: RenderAnnotationFunction\n renderBlock?: RenderBlockFunction\n renderChild?: RenderChildFunction\n renderDecorator?: RenderDecoratorFunction\n renderListItem?: RenderListItemFunction\n renderPlaceholder?: RenderPlaceholderFunction\n renderStyle?: RenderStyleFunction\n scrollSelectionIntoView?: ScrollSelectionIntoViewFunction\n selection?: EditorSelection\n spellCheck?: boolean\n}\n\n/**\n * @public\n *\n *\n * The core component that renders the editor. Must be placed within the {@link EventProvider} component.\n *\n * @example\n * ```tsx\n * import { PortableTextEditable, EditorProvider } from '@portabletext/editor'\n *\n * function MyComponent() {\n * return (\n * <EditorProvider>\n * <PortableTextEditable />\n * </EditorProvider>\n * )\n * }\n * ```\n * @group Components\n */\nexport const PortableTextEditable = forwardRef<\n Omit<HTMLDivElement, 'as' | 'onPaste' | 'onBeforeInput'>,\n PortableTextEditableProps\n>(function PortableTextEditable(props, forwardedRef) {\n const {\n hotkeys,\n onBlur,\n onFocus,\n onBeforeInput,\n onPaste,\n onCopy,\n onClick,\n rangeDecorations,\n renderAnnotation,\n renderBlock,\n renderChild,\n renderDecorator,\n renderListItem,\n renderPlaceholder,\n renderStyle,\n selection: propsSelection,\n scrollSelectionIntoView,\n spellCheck,\n ...restProps\n } = props\n\n const portableTextEditor = usePortableTextEditor()\n const ref = useRef<HTMLDivElement | null>(null)\n const [editableElement, setEditableElement] = useState<HTMLDivElement | null>(\n null,\n )\n const [hasInvalidValue, setHasInvalidValue] = useState(false)\n const [rangeDecorationState, setRangeDecorationsState] = useState<\n BaseRangeWithDecoration[]\n >([])\n\n // Forward ref to parent component\n useImperativeHandle<HTMLDivElement | null, HTMLDivElement | null>(\n forwardedRef,\n () => ref.current,\n )\n\n const rangeDecorationsRef = useRef(rangeDecorations)\n\n const editorActor = useContext(EditorActorContext)\n const readOnly = useSelector(editorActor, (s) =>\n s.matches({'edit mode': 'read only'}),\n )\n const schemaTypes = useSelector(editorActor, (s) => s.context.schema)\n const slateEditor = useSlate()\n\n const blockTypeName = schemaTypes.block.name\n\n // Output a minimal React editor inside Editable when in readOnly mode.\n // NOTE: make sure all the plugins used here can be safely run over again at any point.\n // There will be a problem if they redefine editor methods and then calling the original method within themselves.\n useMemo(() => {\n // React/UI-specific plugins\n if (readOnly) {\n debug('Editable is in read only mode')\n return slateEditor\n }\n const withHotKeys = createWithHotkeys(\n editorActor,\n portableTextEditor,\n hotkeys,\n )\n\n debug('Editable is in edit mode')\n return withHotKeys(slateEditor)\n }, [editorActor, hotkeys, portableTextEditor, readOnly, slateEditor])\n\n const renderElement = useCallback(\n (eProps: RenderElementProps) => (\n <Element\n {...eProps}\n readOnly={readOnly}\n renderBlock={renderBlock}\n renderChild={renderChild}\n renderListItem={renderListItem}\n renderStyle={renderStyle}\n schemaTypes={schemaTypes}\n spellCheck={spellCheck}\n />\n ),\n [\n schemaTypes,\n spellCheck,\n readOnly,\n renderBlock,\n renderChild,\n renderListItem,\n renderStyle,\n ],\n )\n\n const renderLeaf = useCallback(\n (\n lProps: RenderLeafProps & {\n leaf: Text & {placeholder?: boolean; rangeDecoration?: RangeDecoration}\n },\n ) => {\n if (lProps.leaf._type === 'span') {\n let rendered = (\n <Leaf\n {...lProps}\n editorActor={editorActor}\n schemaTypes={schemaTypes}\n renderAnnotation={renderAnnotation}\n renderChild={renderChild}\n renderDecorator={renderDecorator}\n readOnly={readOnly}\n />\n )\n if (\n renderPlaceholder &&\n lProps.leaf.placeholder &&\n lProps.text.text === ''\n ) {\n return (\n <>\n <span style={PLACEHOLDER_STYLE} contentEditable={false}>\n {renderPlaceholder()}\n </span>\n {rendered}\n </>\n )\n }\n const decoration = lProps.leaf.rangeDecoration\n if (decoration) {\n rendered = decoration.component({children: rendered})\n }\n return rendered\n }\n return lProps.children\n },\n [\n editorActor,\n readOnly,\n renderAnnotation,\n renderChild,\n renderDecorator,\n renderPlaceholder,\n schemaTypes,\n ],\n )\n\n const restoreSelectionFromProps = useCallback(() => {\n if (propsSelection) {\n debug(`Selection from props ${JSON.stringify(propsSelection)}`)\n const normalizedSelection = normalizeSelection(\n propsSelection,\n fromSlateValue(slateEditor.children, blockTypeName),\n )\n if (normalizedSelection !== null) {\n debug(\n `Normalized selection from props ${JSON.stringify(normalizedSelection)}`,\n )\n const slateRange = toSlateRange(normalizedSelection, slateEditor)\n if (slateRange) {\n Transforms.select(slateEditor, slateRange)\n // Output selection here in those cases where the editor selection was the same, and there are no set_selection operations made.\n // The selection is usually automatically emitted to change$ by the withPortableTextSelections plugin whenever there is a set_selection operation applied.\n if (!slateEditor.operations.some((o) => o.type === 'set_selection')) {\n editorActor.send({\n type: 'notify.selection',\n selection: normalizedSelection,\n })\n }\n slateEditor.onChange()\n }\n }\n }\n }, [blockTypeName, editorActor, propsSelection, slateEditor])\n\n const syncRangeDecorations = useCallback(\n (operation?: Operation) => {\n if (rangeDecorations && rangeDecorations.length > 0) {\n const newSlateRanges: BaseRangeWithDecoration[] = []\n rangeDecorations.forEach((rangeDecorationItem) => {\n const slateRange = toSlateRange(\n rangeDecorationItem.selection,\n slateEditor,\n )\n if (!SlateRange.isRange(slateRange)) {\n if (rangeDecorationItem.onMoved) {\n rangeDecorationItem.onMoved({\n newSelection: null,\n rangeDecoration: rangeDecorationItem,\n origin: 'local',\n })\n }\n return\n }\n let newRange: BaseRange | null | undefined\n if (operation) {\n newRange = moveRangeByOperation(slateRange, operation)\n if (\n (newRange && newRange !== slateRange) ||\n (newRange === null && slateRange)\n ) {\n const value = PortableTextEditor.getValue(portableTextEditor)\n const newRangeSelection = toPortableTextRange(\n value,\n newRange,\n schemaTypes,\n )\n if (rangeDecorationItem.onMoved) {\n rangeDecorationItem.onMoved({\n newSelection: newRangeSelection,\n rangeDecoration: rangeDecorationItem,\n origin: 'local',\n })\n }\n }\n }\n // If the newRange is null, it means that the range is not valid anymore and should be removed\n // If it's undefined, it means that the slateRange is still valid and should be kept\n if (newRange !== null) {\n newSlateRanges.push({\n ...(newRange || slateRange),\n rangeDecoration: rangeDecorationItem,\n })\n }\n })\n if (newSlateRanges.length > 0) {\n setRangeDecorationsState(newSlateRanges)\n return\n }\n }\n setRangeDecorationsState((rangeDecorationState) => {\n // If there's state then we want to reset\n if (rangeDecorationState.length > 0) {\n return []\n }\n // Otherwise we no-op, React will skip a state update if what we return has reference equality to the previous state\n return rangeDecorationState\n })\n },\n [portableTextEditor, rangeDecorations, schemaTypes, slateEditor],\n )\n\n // Restore selection from props when the editor has been initialized properly with it's value\n useEffect(() => {\n const onReady = editorActor.on('ready', () => {\n syncRangeDecorations()\n restoreSelectionFromProps()\n })\n const onInvalidValue = editorActor.on('invalid value', () => {\n setHasInvalidValue(true)\n })\n const onValueChanged = editorActor.on('value changed', () => {\n setHasInvalidValue(false)\n })\n\n return () => {\n onReady.unsubscribe()\n onInvalidValue.unsubscribe()\n onValueChanged.unsubscribe()\n }\n }, [editorActor, restoreSelectionFromProps, syncRangeDecorations])\n\n // Restore selection from props when it changes\n useEffect(() => {\n if (propsSelection && !hasInvalidValue) {\n restoreSelectionFromProps()\n }\n }, [hasInvalidValue, propsSelection, restoreSelectionFromProps])\n\n const [syncedRangeDecorations, setSyncedRangeDecorations] = useState(false)\n useEffect(() => {\n if (!syncedRangeDecorations) {\n // We only want this to run once, on mount\n setSyncedRangeDecorations(true)\n syncRangeDecorations()\n }\n }, [syncRangeDecorations, syncedRangeDecorations])\n\n useEffect(() => {\n if (!isEqual(rangeDecorations, rangeDecorationsRef.current)) {\n syncRangeDecorations()\n }\n rangeDecorationsRef.current = rangeDecorations\n }, [rangeDecorations, syncRangeDecorations])\n\n // Sync range decorations after an operation is applied\n useEffect(() => {\n const teardown = withSyncRangeDecorations({\n editorActor,\n slateEditor,\n syncRangeDecorations,\n })\n return () => teardown()\n }, [editorActor, slateEditor, syncRangeDecorations])\n\n // Handle from props onCopy function\n const handleCopy = useCallback(\n (event: ClipboardEvent<HTMLDivElement>): void | ReactEditor => {\n if (onCopy) {\n const result = onCopy(event)\n // CopyFn may return something to avoid doing default stuff\n if (result !== undefined) {\n event.preventDefault()\n }\n } else if (event.nativeEvent.clipboardData) {\n editorActor.send({\n type: 'behavior event',\n behaviorEvent: {\n type: 'copy',\n data: event.nativeEvent.clipboardData,\n },\n editor: slateEditor,\n nativeEvent: event,\n })\n }\n },\n [onCopy, editorActor, slateEditor],\n )\n\n // Handle incoming pasting events in the editor\n const handlePaste = useCallback(\n (event: ClipboardEvent<HTMLDivElement>): Promise<void> | void => {\n const value = PortableTextEditor.getValue(portableTextEditor)\n const ptRange = toPortableTextRange(\n value,\n slateEditor.selection,\n schemaTypes,\n )\n const path = ptRange?.focus.path || []\n const onPasteResult = onPaste?.({event, value, path, schemaTypes})\n\n if (onPasteResult || !slateEditor.selection) {\n event.preventDefault()\n\n // Resolve it as promise (can be either async promise or sync return value)\n editorActor.send({type: 'notify.loading'})\n\n Promise.resolve(onPasteResult)\n .then((result) => {\n debug('Custom paste function from client resolved', result)\n\n if (!result || !result.insert) {\n debug('No result from custom paste handler, pasting normally')\n\n slateEditor.insertData(event.clipboardData)\n } else if (result.insert) {\n slateEditor.insertFragment(\n toSlateValue(result.insert as PortableTextBlock[], {\n schemaTypes,\n }),\n )\n } else {\n console.warn(\n 'Your onPaste function returned something unexpected:',\n result,\n )\n }\n })\n .catch((error) => {\n console.error(error)\n\n return error\n })\n .finally(() => {\n editorActor.send({type: 'notify.done loading'})\n })\n } else if (event.nativeEvent.clipboardData) {\n editorActor.send({\n type: 'behavior event',\n behaviorEvent: {\n type: 'paste',\n data: event.nativeEvent.clipboardData,\n },\n editor: slateEditor,\n nativeEvent: event,\n })\n }\n\n debug('No result from custom paste handler, pasting normally')\n },\n [editorActor, onPaste, portableTextEditor, schemaTypes, slateEditor],\n )\n\n const handleOnFocus: FocusEventHandler<HTMLDivElement> = useCallback(\n (event) => {\n if (onFocus) {\n onFocus(event)\n }\n if (!event.isDefaultPrevented()) {\n const selection = PortableTextEditor.getSelection(portableTextEditor)\n // Create an editor selection if it does'nt exist\n if (selection === null) {\n Transforms.select(slateEditor, Editor.start(slateEditor, []))\n slateEditor.onChange()\n }\n editorActor.send({type: 'notify.focused', event})\n const newSelection = PortableTextEditor.getSelection(portableTextEditor)\n // If the selection is the same, emit it explicitly here as there is no actual onChange event triggered.\n if (selection === newSelection) {\n editorActor.send({\n type: 'notify.selection',\n selection,\n })\n }\n }\n },\n [editorActor, onFocus, portableTextEditor, slateEditor],\n )\n\n const handleClick = useCallback(\n (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {\n if (onClick) {\n onClick(event)\n }\n\n const focusBlockPath = slateEditor.selection\n ? slateEditor.selection.focus.path.slice(0, 1)\n : undefined\n const focusBlock = focusBlockPath\n ? (Node.descendant(slateEditor, focusBlockPath) as\n | SlateTextBlock\n | VoidElement)\n : undefined\n const [_, lastNodePath] = Node.last(slateEditor, [])\n const lastBlockPath = lastNodePath.slice(0, 1)\n const lastNodeFocused = focusBlockPath\n ? Path.equals(lastBlockPath, focusBlockPath)\n : false\n const lastBlockIsVoid = focusBlock\n ? !slateEditor.isTextBlock(focusBlock)\n : false\n const collapsedSelection =\n slateEditor.selection && SlateRange.isCollapsed(slateEditor.selection)\n\n if (collapsedSelection && lastNodeFocused && lastBlockIsVoid) {\n Transforms.insertNodes(\n slateEditor,\n slateEditor.pteCreateTextBlock({decorators: []}),\n )\n slateEditor.onChange()\n }\n },\n [onClick, slateEditor],\n )\n\n const handleOnBlur: FocusEventHandler<HTMLDivElement> = useCallback(\n (event) => {\n if (onBlur) {\n onBlur(event)\n }\n if (!event.isPropagationStopped()) {\n editorActor.send({type: 'notify.blurred', event})\n }\n },\n [editorActor, onBlur],\n )\n\n const handleOnBeforeInput = useCallback(\n (event: InputEvent) => {\n if (onBeforeInput) {\n onBeforeInput(event)\n }\n },\n [onBeforeInput],\n )\n\n // This function will handle unexpected DOM changes inside the Editable rendering,\n // and make sure that we can maintain a stable slateEditor.selection when that happens.\n //\n // For example, if this Editable is rendered inside something that might re-render\n // this component (hidden contexts) while the user is still actively changing the\n // contentEditable, this could interfere with the intermediate DOM selection,\n // which again could be picked up by ReactEditor's event listeners.\n // If that range is invalid at that point, the slate.editorSelection could be\n // set either wrong, or invalid, to which slateEditor will throw exceptions\n // that are impossible to recover properly from or result in a wrong selection.\n //\n // Also the other way around, when the ReactEditor will try to create a DOM Range\n // from the current slateEditor.selection, it may throw unrecoverable errors\n // if the current editor.selection is invalid according to the DOM.\n // If this is the case, default to selecting the top of the document, if the\n // user already had a selection.\n const validateSelection = useCallback(() => {\n if (!slateEditor.selection) {\n return\n }\n const root = ReactEditor.findDocumentOrShadowRoot(slateEditor)\n const {activeElement} = root\n // Return if the editor isn't the active element\n if (ref.current !== activeElement) {\n return\n }\n const window = ReactEditor.getWindow(slateEditor)\n const domSelection = window.getSelection()\n if (!domSelection || domSelection.rangeCount === 0) {\n return\n }\n const existingDOMRange = domSelection.getRangeAt(0)\n try {\n const newDOMRange = ReactEditor.toDOMRange(\n slateEditor,\n slateEditor.selection,\n )\n if (\n newDOMRange.startOffset !== existingDOMRange.startOffset ||\n newDOMRange.endOffset !== existingDOMRange.endOffset\n ) {\n debug('DOM range out of sync, validating selection')\n // Remove all ranges temporary\n domSelection?.removeAllRanges()\n // Set the correct range\n domSelection.addRange(newDOMRange)\n }\n } catch {\n debug(`Could not resolve selection, selecting top document`)\n // Deselect the editor\n Transforms.deselect(slateEditor)\n // Select top document if there is a top block to select\n if (slateEditor.children.length > 0) {\n Transforms.select(slateEditor, [0, 0])\n }\n slateEditor.onChange()\n }\n }, [ref, slateEditor])\n\n // Observe mutations (child list and subtree) to this component's DOM,\n // and make sure the editor selection is valid when that happens.\n useEffect(() => {\n if (editableElement) {\n const mutationObserver = new MutationObserver(validateSelection)\n mutationObserver.observe(editableElement, {\n attributeOldValue: false,\n attributes: false,\n characterData: false,\n childList: true,\n subtree: true,\n })\n return () => {\n mutationObserver.disconnect()\n }\n }\n return undefined\n }, [validateSelection, editableElement])\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent<HTMLDivElement>) => {\n if (props.onKeyDown) {\n props.onKeyDown(event)\n }\n if (!event.isDefaultPrevented()) {\n slateEditor.pteWithHotKeys(event)\n }\n if (!event.isDefaultPrevented()) {\n editorActor.send({\n type: 'behavior event',\n behaviorEvent: {\n type: 'key.down',\n keyboardEvent: {\n key: event.key,\n code: event.code,\n altKey: event.altKey,\n ctrlKey: event.ctrlKey,\n metaKey: event.metaKey,\n shiftKey: event.shiftKey,\n },\n },\n editor: slateEditor,\n nativeEvent: event,\n })\n }\n },\n [props, editorActor, slateEditor],\n )\n\n const handleKeyUp = useCallback(\n (event: KeyboardEvent<HTMLDivElement>) => {\n if (props.onKeyUp) {\n props.onKeyUp(event)\n }\n if (!event.isDefaultPrevented()) {\n editorActor.send({\n type: 'behavior event',\n behaviorEvent: {\n type: 'key.up',\n keyboardEvent: {\n key: event.key,\n code: event.code,\n altKey: event.altKey,\n ctrlKey: event.ctrlKey,\n metaKey: event.metaKey,\n shiftKey: event.shiftKey,\n },\n },\n editor: slateEditor,\n nativeEvent: event,\n })\n }\n },\n [props, editorActor, slateEditor],\n )\n\n const scrollSelectionIntoViewToSlate = useMemo(() => {\n // Use slate-react default scroll into view\n if (scrollSelectionIntoView === undefined) {\n return undefined\n }\n // Disable scroll into view totally\n if (scrollSelectionIntoView === null) {\n return noop\n }\n // Translate PortableTextEditor prop fn to Slate plugin fn\n return (_editor: ReactEditor, domRange: Range) => {\n scrollSelectionIntoView(portableTextEditor, domRange)\n }\n }, [portableTextEditor, scrollSelectionIntoView])\n\n const decorate: (entry: NodeEntry) => BaseRange[] = useCallback(\n ([, path]) => {\n if (isEqualToEmptyEditor(slateEditor.children, schemaTypes)) {\n return [\n {\n anchor: {\n path: [0, 0],\n offset: 0,\n },\n focus: {\n path: [0, 0],\n offset: 0,\n },\n placeholder: true,\n },\n ]\n }\n // Editor node has a path length of 0 (should never be decorated)\n if (path.length === 0) {\n return []\n }\n const result = rangeDecorationState.filter((item) => {\n // Special case in order to only return one decoration for collapsed ranges\n if (SlateRange.isCollapsed(item)) {\n // Collapsed ranges should only be decorated if they are on a block child level (length 2)\n if (path.length !== 2) {\n return false\n }\n return (\n Path.equals(item.focus.path, path) &&\n Path.equals(item.anchor.path, path)\n )\n }\n // Include decorations that either include or intersects with this path\n return (\n SlateRange.intersection(item, {\n anchor: {path, offset: 0},\n focus: {path, offset: 0},\n }) || SlateRange.includes(item, path)\n )\n })\n if (result.length > 0) {\n return result\n }\n return []\n },\n [slateEditor, schemaTypes, rangeDecorationState],\n )\n\n // Set the forwarded ref to be the Slate editable DOM element\n // Also set the editable element in a state so that the MutationObserver\n // is setup when this element is ready.\n useEffect(() => {\n ref.current = ReactEditor.toDOMNode(\n slateEditor,\n slateEditor,\n ) as HTMLDivElement | null\n setEditableElement(ref.current)\n }, [slateEditor, ref])\n\n useEffect(() => {\n const window = ReactEditor.getWindow(slateEditor)\n\n const onDragEnd = () => {\n editorActor.send({type: 'dragend'})\n }\n const onDrop = () => {\n editorActor.send({type: 'drop'})\n }\n\n window.document.addEventListener('dragend', onDragEnd)\n window.document.addEventListener('drop', onDrop)\n\n return () => {\n window.document.removeEventListener('dragend', onDragEnd)\n window.document.removeEventListener('drop', onDrop)\n }\n }, [slateEditor, editorActor])\n\n if (!portableTextEditor) {\n return null\n }\n return hasInvalidValue ? null : (\n <SlateEditable\n {...restProps}\n autoFocus={false}\n className={restProps.className || 'pt-editable'}\n decorate={decorate}\n onBlur={handleOnBlur}\n onCopy={handleCopy}\n onClick={handleClick}\n onDOMBeforeInput={handleOnBeforeInput}\n onDragStart={(event) => {\n props.onDragStart?.(event)\n\n if (!event.isDefaultPrevented() && !event.isPropagationStopped()) {\n editorActor.send({type: 'dragstart'})\n }\n }}\n onFocus={handleOnFocus}\n onKeyDown={handleKeyDown}\n onKeyUp={handleKeyUp}\n onPaste={handlePaste}\n readOnly={readOnly}\n // We have implemented our own placeholder logic with decorations.\n // This 'renderPlaceholder' should not be used.\n renderPlaceholder={undefined}\n renderElement={renderElement}\n renderLeaf={renderLeaf}\n scrollSelectionIntoView={scrollSelectionIntoViewToSlate}\n />\n )\n})\n\nPortableTextEditable.displayName = 'ForwardRef(PortableTextEditable)'\n","import {useEffect} from 'react'\nimport {useEffectEvent} from 'use-effect-event'\nimport type {EditorEmittedEvent} from './editor/editor-machine'\nimport {useEditor} from './editor/editor-provider'\n\n/**\n * @public\n * @deprecated\n * This component has been renamed. Use `EventListenerPlugin` instead.\n *\n * ```\n * import {EventListenerPlugin} from '@portabletext/editor/plugins'\n * ```\n */\nexport function EditorEventListener(props: {\n on: (event: EditorEmittedEvent) => void\n}) {\n const editor = useEditor()\n const on = useEffectEvent(props.on)\n\n useEffect(() => {\n const subscription = editor.on('*', on)\n\n return () => {\n subscription.unsubscribe()\n }\n }, [editor])\n\n return null\n}\n"],"names":["normalizePoint","point","value","newPath","newOffset","offset","blockKey","path","_key","childKey","block","find","blk","push","children","Array","isArray","length","child","cld","text","normalizeSelection","selection","newAnchor","newFocus","anchor","focus","isEqual","backward","DefaultBlockObject","props","$","_c","t0","Symbol","for","userSelect","t1","_type","jsxs","DefaultInlineObject","debug","debugWithName","DraggableBlock","element","readOnly","blockRef","editor","useSlateStatic","dragGhostRef","useRef","undefined","isDragOver","setIsDragOver","useState","t2","Editor","isVoid","t3","t4","isInline","blockElement","setBlockElement","t5","t6","current","ReactEditor","toDOMNode","useEffect","t7","event","isMyDragOver","IS_DRAGGING_BLOCK_ELEMENT","get","preventDefault","dataTransfer","dropEffect","IS_DRAGGING_ELEMENT_TARGET","set","elementRect","getBoundingClientRect","top","height","Y","pageY","loc","Math","abs","IS_DRAGGING_BLOCK_TARGET_POSITION","handleDragOver","t8","handleDragLeave","t9","event_0","targetBlock","stopPropagation","delete","document","body","removeChild","dragPosition","targetPath","findPath","myPath","isBefore","Path","originalPath","JSON","stringify","originalPath_0","equals","Transforms","moveNodes","at","to","onChange","handleDragEnd","t10","event_1","handleDrop","t11","event_2","target","HTMLElement","style","opacity","handleDrag","t12","event_3","IS_DRAGGING","setData","effectAllowed","dragGhost","cloneNode","customGhost","querySelector","setAttribute","position","left","boxSizing","appendChild","rect","x","clientX","y","clientY","width","setDragImage","handleDragStart","t13","isDraggingOverFirstBlock","t14","isDraggingOverLastBlock","dragPosition_0","isDraggingOverTop","isDraggingOverBottom","t15","t16","borderBottom","zIndex","dropIndicator","t17","jsx","Fragment","t18","t19","displayName","EMPTY_ANNOTATIONS","inlineBlockStyle","display","Element","attributes","schemaTypes","renderBlock","renderChild","renderListItem","renderStyle","spellCheck","selected","useSelected","inlineBlockObjectRef","focused","Range","isCollapsed","useMemo","fromSlateValue","name","KEY_TO_VALUE_ELEMENT","renderedBlock","className","blockPath","Error","node","depth","schemaType","inlineObjects","SlateElement","isElement","elmPath","debugRenders","annotations","editorElementRef","type","isListItem","blockStyleType","styles","item","level","listItem","isListBlock","listType","lists","renderProps","Object","defineProperty","enumerable","warn","propsOrDefaultRendered","blockObjects","renderedBlockFromProps","_props","EMPTY_MARKS","Leaf","editorActor","leaf","renderDecorator","renderAnnotation","spanRef","portableTextEditor","usePortableTextEditor","blockSelected","setFocused","setSelected","parent","decoratorValues","decorators","map","dec","marks","uniq","filter","mark","includes","annotationMarks","markDefs","def","Boolean","shouldTrackSelectionAndFocus","sel","PortableTextEditor","getSelection","isCollapsedSelection","startTransition","setSelectedFromRange","useCallback","winSelection","window","rangeCount","range","getRangeAt","intersectsNode","onBlur","on","onFocus","onSelection","unsubscribe","content","returnedChildren","Text","isText","span","forEach","annotation","t","_child","createWithHotkeys","hotkeysFromOptions","reservedHotkeys","activeHotkeys","pteWithHotKeys","keys","cat","hotkey","isHotkey","nativeEvent","possibleMark","send","behaviorEvent","decorator","possibleCommand","command","withSyncRangeDecorations","slateEditor","syncRangeDecorations","originalApply","apply","op","getSnapshot","matches","PLACEHOLDER_STYLE","pointerEvents","right","PortableTextEditable","forwardRef","forwardedRef","hotkeys","onBeforeInput","onPaste","onCopy","onClick","rangeDecorations","renderPlaceholder","propsSelection","scrollSelectionIntoView","restProps","ref","editableElement","setEditableElement","hasInvalidValue","setHasInvalidValue","rangeDecorationState","setRangeDecorationsState","rangeDecorationsRef","useContext","EditorActorContext","useSelector","s","context","schema","useSlate","blockTypeName","withHotKeys","renderElement","eProps","renderLeaf","lProps","rendered","placeholder","decoration","rangeDecoration","component","restoreSelectionFromProps","normalizedSelection","slateRange","toSlateRange","select","operations","some","o","operation","newSlateRanges","rangeDecorationItem","SlateRange","isRange","onMoved","newSelection","origin","newRange","moveRangeByOperation","getValue","newRangeSelection","toPortableTextRange","onReady","onInvalidValue","onValueChanged","syncedRangeDecorations","setSyncedRangeDecorations","teardown","handleCopy","clipboardData","data","handlePaste","onPasteResult","Promise","resolve","then","result","insert","insertData","insertFragment","toSlateValue","console","catch","error","finally","handleOnFocus","isDefaultPrevented","start","handleClick","focusBlockPath","slice","focusBlock","Node","descendant","_","lastNodePath","last","lastBlockPath","lastNodeFocused","lastBlockIsVoid","isTextBlock","insertNodes","pteCreateTextBlock","handleOnBlur","isPropagationStopped","handleOnBeforeInput","validateSelection","root","findDocumentOrShadowRoot","activeElement","domSelection","getWindow","existingDOMRange","newDOMRange","toDOMRange","startOffset","endOffset","removeAllRanges","addRange","deselect","mutationObserver","MutationObserver","observe","attributeOldValue","characterData","childList","subtree","disconnect","handleKeyDown","onKeyDown","keyboardEvent","key","code","altKey","ctrlKey","metaKey","shiftKey","handleKeyUp","onKeyUp","scrollSelectionIntoViewToSlate","noop","_editor","domRange","decorate","isEqualToEmptyEditor","intersection","onDragEnd","onDrop","addEventListener","removeEventListener","SlateEditable","onDragStart","EditorEventListener","useEditor","useEffectEvent","subscription"],"mappings":";;;;;;;AAIgBA,SAAAA,eACdC,OACAC,OAC6B;AACzB,MAAA,CAACD,SAAS,CAACC;AACN,WAAA;AAET,QAAMC,UAAgB,CAAE;AACpBC,MAAAA,YAAoBH,MAAMI,UAAU;AACxC,QAAMC,WACJ,OAAOL,MAAMM,KAAK,CAAC,KAAM,YACzB,UAAUN,MAAMM,KAAK,CAAC,KACtBN,MAAMM,KAAK,CAAC,EAAEC,MACVC,WACJ,OAAOR,MAAMM,KAAK,CAAC,KAAM,YACzB,UAAUN,MAAMM,KAAK,CAAC,KACtBN,MAAMM,KAAK,CAAC,EAAEC,MACVE,QAAuCR,MAAMS,KAChDC,CAAQA,QAAAA,IAAIJ,SAASF,QACxB;AACII,MAAAA;AACFP,YAAQU,KAAK;AAAA,MAACL,MAAME,MAAMF;AAAAA,IAAAA,CAAK;AAAA;AAExB,WAAA;AAET,MAAIE,SAAST,MAAMM,KAAK,CAAC,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xI,cAAc;ACh1B5B,SAAA8R,oBAAAta,OAAA;AAAAC,QAAAA,IAAAC,qBAAAA,EAAA,CAAA,GAGLe,SAAesZ,yBACf/L,GAAAA,KAAWgM,eAAAA,eAAexa,MAAKwO,EAAG;AAACrO,MAAAA;AAAAF,IAAAgB,CAAAA,MAAAA,UAAAhB,SAAAuO,MAEzBrO,KAAAA,MAAA;AACR,UAAAsa,eAAqBxZ,OAAMuN,GAAI,KAAKA,EAAE;AAAC,WAAA,MAAA;AAGrCiM,mBAAY9L,YAAa;AAAA,IAAC;AAAA,EAE7B1O,GAAAA,OAAAgB,QAAAhB,OAAAuO,IAAAvO,OAAAE,MAAAA,KAAAF,EAAA,CAAA;AAAAM,MAAAA;AAAAN,SAAAA,SAAAgB,UAAEV,MAACU,MAAM,GAAChB,OAAAgB,QAAAhB,OAAAM,MAAAA,KAAAN,EAAA,CAAA,GANXqC,gBAAUnC,IAMPI,EAAQ,GAAC;AAAA;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/internal-utils/selection.ts","../src/editor/components/DefaultObject.tsx","../src/editor/components/drop-indicator.tsx","../src/editor/components/use-draggable.ts","../src/editor/components/use-droppable.ts","../src/editor/components/Element.tsx","../src/editor/components/Leaf.tsx","../src/editor/plugins/createWithHotKeys.ts","../src/editor/withSyncRangeDecorations.ts","../src/editor/Editable.tsx","../src/editor-event-listener.tsx"],"sourcesContent":["import type {Path, PortableTextBlock} from '@sanity/types'\nimport {isEqual} from 'lodash'\nimport type {EditorSelection, EditorSelectionPoint} from '../types/editor'\n\nexport function normalizePoint(\n point: EditorSelectionPoint,\n value: PortableTextBlock[],\n): EditorSelectionPoint | null {\n if (!point || !value) {\n return null\n }\n const newPath: Path = []\n let newOffset: number = point.offset || 0\n const blockKey =\n typeof point.path[0] === 'object' &&\n '_key' in point.path[0] &&\n point.path[0]._key\n const childKey =\n typeof point.path[2] === 'object' &&\n '_key' in point.path[2] &&\n point.path[2]._key\n const block: PortableTextBlock | undefined = value.find(\n (blk) => blk._key === blockKey,\n )\n if (block) {\n newPath.push({_key: block._key})\n } else {\n return null\n }\n if (block && point.path[1] === 'children') {\n if (\n !block.children ||\n (Array.isArray(block.children) && block.children.length === 0)\n ) {\n return null\n }\n const child =\n Array.isArray(block.children) &&\n block.children.find((cld) => cld._key === childKey)\n if (child) {\n newPath.push('children')\n newPath.push({_key: child._key})\n newOffset =\n child.text && child.text.length >= point.offset\n ? point.offset\n : (child.text && child.text.length) || 0\n } else {\n return null\n }\n }\n return {path: newPath, offset: newOffset}\n}\n\nexport function normalizeSelection(\n selection: EditorSelection,\n value: PortableTextBlock[] | undefined,\n): EditorSelection | null {\n if (!selection || !value || value.length === 0) {\n return null\n }\n let newAnchor: EditorSelectionPoint | null = null\n let newFocus: EditorSelectionPoint | null = null\n const {anchor, focus} = selection\n if (\n anchor &&\n value.find((blk) => isEqual({_key: blk._key}, anchor.path[0]))\n ) {\n newAnchor = normalizePoint(anchor, value)\n }\n if (focus && value.find((blk) => isEqual({_key: blk._key}, focus.path[0]))) {\n newFocus = normalizePoint(focus, value)\n }\n if (newAnchor && newFocus) {\n return {anchor: newAnchor, focus: newFocus, backward: selection.backward}\n }\n return null\n}\n","import type {PortableTextBlock, PortableTextChild} from '@sanity/types'\n\nexport function DefaultBlockObject(props: {\n value: PortableTextBlock | PortableTextChild\n}) {\n return (\n <div style={{userSelect: 'none'}}>\n [{props.value._type}: {props.value._key}]\n </div>\n )\n}\n\nexport function DefaultInlineObject(props: {\n value: PortableTextBlock | PortableTextChild\n}) {\n return (\n <span style={{userSelect: 'none'}}>\n [{props.value._type}: {props.value._key}]\n </span>\n )\n}\n","export function DropIndicator() {\n return (\n <div\n className=\"pt-drop-indicator\"\n style={{\n position: 'absolute',\n width: '100%',\n height: 1,\n borderBottom: '1px solid currentColor',\n zIndex: 5,\n }}\n />\n )\n}\n","import {\n useCallback,\n useEffect,\n useRef,\n useState,\n type DragEvent,\n type RefObject,\n} from 'react'\nimport {Path, Transforms, type Element as SlateElement} from 'slate'\nimport {ReactEditor, useSlateStatic} from 'slate-react'\nimport {debugWithName} from '../../internal-utils/debug'\nimport {\n IS_DRAGGING,\n IS_DRAGGING_BLOCK_ELEMENT,\n IS_DRAGGING_BLOCK_TARGET_POSITION,\n IS_DRAGGING_ELEMENT_TARGET,\n} from '../../internal-utils/weakMaps'\n\nconst debug = debugWithName('useDraggable')\n\ntype Draggable = {\n draggableProps: {\n draggable: boolean\n onDragStart?: (event: DragEvent) => void\n onDrag?: (event: DragEvent) => void\n onDragEnd?: (event: DragEvent) => void\n }\n}\n\nexport function useDraggable(props: {\n element: SlateElement\n readOnly: boolean\n blockRef: RefObject<HTMLDivElement | null>\n}): Draggable {\n const editor = useSlateStatic()\n const dragGhostRef = useRef<HTMLElement>(undefined)\n const [blockElement, setBlockElement] = useState<HTMLElement | null>(null)\n\n useEffect(\n () =>\n setBlockElement(\n props.blockRef\n ? props.blockRef.current\n : ReactEditor.toDOMNode(editor, props.element),\n ),\n [editor, props.element, props.blockRef],\n )\n\n // Note: this is called for the dragging block\n const handleDragEnd = useCallback(\n (event: DragEvent) => {\n const targetBlock = IS_DRAGGING_ELEMENT_TARGET.get(editor)\n if (targetBlock) {\n IS_DRAGGING.set(editor, false)\n event.preventDefault()\n event.stopPropagation()\n IS_DRAGGING_ELEMENT_TARGET.delete(editor)\n if (dragGhostRef.current) {\n debug('Removing drag ghost')\n document.body.removeChild(dragGhostRef.current)\n }\n const dragPosition = IS_DRAGGING_BLOCK_TARGET_POSITION.get(editor)\n IS_DRAGGING_BLOCK_TARGET_POSITION.delete(editor)\n let targetPath = ReactEditor.findPath(editor, targetBlock)\n const myPath = ReactEditor.findPath(editor, props.element)\n const isBefore = Path.isBefore(myPath, targetPath)\n if (dragPosition === 'bottom' && !isBefore) {\n // If it is already at the bottom, don't do anything.\n if (targetPath[0] >= editor.children.length - 1) {\n debug('target is already at the bottom, not moving')\n return\n }\n const originalPath = targetPath\n targetPath = Path.next(targetPath)\n debug(\n `Adjusting targetPath from ${JSON.stringify(originalPath)} to ${JSON.stringify(\n targetPath,\n )}`,\n )\n }\n if (\n dragPosition === 'top' &&\n isBefore &&\n targetPath[0] !== editor.children.length - 1\n ) {\n const originalPath = targetPath\n targetPath = Path.previous(targetPath)\n debug(\n `Adjusting targetPath from ${JSON.stringify(originalPath)} to ${JSON.stringify(\n targetPath,\n )}`,\n )\n }\n if (Path.equals(targetPath, myPath)) {\n event.preventDefault()\n debug('targetPath and myPath is the same, not moving')\n return\n }\n debug(\n `Moving element ${props.element._key} from path ${JSON.stringify(myPath)} to ${JSON.stringify(\n targetPath,\n )} (${dragPosition})`,\n )\n Transforms.moveNodes(editor, {at: myPath, to: targetPath})\n editor.onChange()\n return\n }\n debug('No target element, not doing anything')\n },\n [editor, props.element],\n )\n\n // Note: this is called for the dragging block\n const handleDrag = useCallback(\n (event: DragEvent) => {\n IS_DRAGGING.set(editor, true)\n IS_DRAGGING_BLOCK_ELEMENT.set(editor, props.element)\n event.stopPropagation() // Stop propagation so that leafs don't get this and take focus/selection!\n\n const target = event.target\n\n if (target instanceof HTMLElement) {\n target.style.opacity = '1'\n }\n },\n [editor, props.element],\n )\n\n // Note: this is called for the dragging block\n const handleDragStart = useCallback(\n (event: DragEvent) => {\n debug('Drag start')\n IS_DRAGGING.set(editor, true)\n if (event.dataTransfer) {\n event.dataTransfer.setData('application/portable-text', 'something')\n event.dataTransfer.effectAllowed = 'move'\n }\n // Clone blockElement so that it will not be visually clipped by scroll-containers etc.\n // The application that uses the portable-text-editor may indicate the element used as\n // drag ghost by adding a truthy data attribute 'data-pt-drag-ghost-element' to a HTML element.\n if (blockElement && blockElement instanceof HTMLElement) {\n let dragGhost = blockElement.cloneNode(true) as HTMLElement\n const customGhost = dragGhost.querySelector(\n '[data-pt-drag-ghost-element]',\n )\n if (customGhost) {\n dragGhost = customGhost as HTMLElement\n }\n\n // Set the `data-dragged` attribute so the consumer can style the element while it’s dragged\n dragGhost.setAttribute('data-dragged', '')\n\n if (document.body) {\n dragGhostRef.current = dragGhost\n dragGhost.style.position = 'absolute'\n dragGhost.style.left = '-99999px'\n dragGhost.style.boxSizing = 'border-box'\n document.body.appendChild(dragGhost)\n const rect = blockElement.getBoundingClientRect()\n const x = event.clientX - rect.left\n const y = event.clientY - rect.top\n dragGhost.style.width = `${rect.width}px`\n dragGhost.style.height = `${rect.height}px`\n event.dataTransfer.setDragImage(dragGhost, x, y)\n }\n }\n handleDrag(event)\n },\n [blockElement, editor, handleDrag],\n )\n\n if (props.readOnly) {\n return {\n draggableProps: {\n draggable: false,\n onDragStart: undefined,\n onDrag: undefined,\n onDragEnd: undefined,\n },\n }\n }\n\n return {\n draggableProps: {\n draggable: true,\n onDragStart: handleDragStart,\n onDrag: handleDrag,\n onDragEnd: handleDragEnd,\n },\n }\n}\n","import type React from 'react'\nimport {useCallback, useEffect, useState, type DragEvent} from 'react'\nimport type {Element as SlateElement} from 'slate'\nimport {ReactEditor, useSlateStatic} from 'slate-react'\nimport {debugWithName} from '../../internal-utils/debug'\nimport {\n IS_DRAGGING_BLOCK_ELEMENT,\n IS_DRAGGING_BLOCK_TARGET_POSITION,\n IS_DRAGGING_ELEMENT_TARGET,\n} from '../../internal-utils/weakMaps'\n\nconst debug = debugWithName('useDroppable')\n\ntype Droppable = {\n droppableProps: {\n onDragOver?: (event: DragEvent) => void\n onDragLeave?: () => void\n onDrop?: (event: DragEvent) => void\n }\n isDraggingOverTop: boolean\n isDraggingOverBottom: boolean\n}\n\nexport function useDroppable(props: {\n element: SlateElement\n blockRef: React.RefObject<HTMLDivElement | null>\n readOnly: boolean\n}): Droppable {\n const editor = useSlateStatic()\n const [isDragOver, setIsDragOver] = useState(false)\n const [blockElement, setBlockElement] = useState<HTMLElement | null>(null)\n\n useEffect(\n () =>\n setBlockElement(\n props.blockRef\n ? props.blockRef.current\n : ReactEditor.toDOMNode(editor, props.element),\n ),\n [editor, props.element, props.blockRef],\n )\n\n const handleDragOver = useCallback(\n (event: DragEvent) => {\n const isMyDragOver = IS_DRAGGING_BLOCK_ELEMENT.get(editor)\n // debug('Drag over', blockElement)\n if (!isMyDragOver || !blockElement) {\n return\n }\n event.preventDefault()\n event.dataTransfer.dropEffect = 'move'\n IS_DRAGGING_ELEMENT_TARGET.set(editor, props.element)\n const elementRect = blockElement.getBoundingClientRect()\n const offset = elementRect.top\n const height = elementRect.height\n const Y = event.pageY\n const loc = Math.abs(offset - Y)\n let position: 'top' | 'bottom' = 'bottom'\n if (props.element === editor.children[0]) {\n position = 'top'\n } else if (loc < height / 2) {\n position = 'top'\n IS_DRAGGING_BLOCK_TARGET_POSITION.set(editor, position)\n } else {\n position = 'bottom'\n IS_DRAGGING_BLOCK_TARGET_POSITION.set(editor, position)\n }\n if (isMyDragOver === props.element) {\n event.dataTransfer.dropEffect = 'none'\n return\n }\n setIsDragOver(true)\n },\n [blockElement, editor, props.element],\n )\n\n const handleDragLeave = useCallback(() => {\n setIsDragOver(false)\n }, [])\n\n const handleDrop = useCallback(\n (event: DragEvent) => {\n if (IS_DRAGGING_BLOCK_ELEMENT.get(editor)) {\n debug('On drop (prevented)', props.element)\n event.preventDefault()\n event.stopPropagation()\n setIsDragOver(false)\n }\n },\n [editor, props.element],\n )\n\n const isDraggingOverFirstBlock =\n isDragOver && editor.children[0] === IS_DRAGGING_ELEMENT_TARGET.get(editor)\n const isDraggingOverLastBlock =\n isDragOver &&\n editor.children[editor.children.length - 1] ===\n IS_DRAGGING_ELEMENT_TARGET.get(editor)\n const dragPosition = IS_DRAGGING_BLOCK_TARGET_POSITION.get(editor)\n\n const isDraggingOverTop =\n isDraggingOverFirstBlock ||\n (isDragOver &&\n !isDraggingOverFirstBlock &&\n !isDraggingOverLastBlock &&\n dragPosition === 'top')\n const isDraggingOverBottom =\n isDraggingOverLastBlock ||\n (isDragOver &&\n !isDraggingOverFirstBlock &&\n !isDraggingOverLastBlock &&\n dragPosition === 'bottom')\n\n if (props.readOnly) {\n return {\n droppableProps: {\n onDragOver: undefined,\n onDragLeave: undefined,\n onDrop: undefined,\n },\n isDraggingOverTop: false,\n isDraggingOverBottom: false,\n }\n }\n\n return {\n droppableProps: {\n onDragOver: handleDragOver,\n onDragLeave: handleDragLeave,\n onDrop: handleDrop,\n },\n isDraggingOverTop,\n isDraggingOverBottom,\n }\n}\n","import type {\n Path,\n PortableTextChild,\n PortableTextObject,\n PortableTextTextBlock,\n} from '@sanity/types'\nimport {\n useMemo,\n useRef,\n type FunctionComponent,\n type JSX,\n type ReactElement,\n} from 'react'\nimport {Editor, Range, Element as SlateElement} from 'slate'\nimport {\n ReactEditor,\n useSelected,\n useSlateStatic,\n type RenderElementProps,\n} from 'slate-react'\nimport {debugWithName} from '../../internal-utils/debug'\nimport {fromSlateValue} from '../../internal-utils/values'\nimport {KEY_TO_VALUE_ELEMENT} from '../../internal-utils/weakMaps'\nimport type {\n BlockRenderProps,\n PortableTextMemberSchemaTypes,\n RenderBlockFunction,\n RenderChildFunction,\n RenderListItemFunction,\n RenderStyleFunction,\n} from '../../types/editor'\nimport {DefaultBlockObject, DefaultInlineObject} from './DefaultObject'\nimport {DropIndicator} from './drop-indicator'\nimport {useDraggable} from './use-draggable'\nimport {useDroppable} from './use-droppable'\n\nconst debug = debugWithName('components:Element')\nconst debugRenders = false\nconst EMPTY_ANNOTATIONS: PortableTextObject[] = []\n\n/**\n * @internal\n */\nexport interface ElementProps {\n attributes: RenderElementProps['attributes']\n children: ReactElement<any>\n element: SlateElement\n schemaTypes: PortableTextMemberSchemaTypes\n readOnly: boolean\n renderBlock?: RenderBlockFunction\n renderChild?: RenderChildFunction\n renderListItem?: RenderListItemFunction\n renderStyle?: RenderStyleFunction\n spellCheck?: boolean\n}\n\nconst inlineBlockStyle = {display: 'inline-block'}\n\n/**\n * Renders Portable Text block and inline object nodes in Slate\n * @internal\n */\nexport const Element: FunctionComponent<ElementProps> = ({\n attributes,\n children,\n element,\n schemaTypes,\n readOnly,\n renderBlock,\n renderChild,\n renderListItem,\n renderStyle,\n spellCheck,\n}) => {\n const editor = useSlateStatic()\n const selected = useSelected()\n const blockRef = useRef<HTMLDivElement | null>(null)\n const inlineBlockObjectRef = useRef(null)\n const focused =\n (selected && editor.selection && Range.isCollapsed(editor.selection)) ||\n false\n const droppable = useDroppable({element, blockRef, readOnly})\n const draggable = useDraggable({element, blockRef, readOnly})\n\n const value = useMemo(\n () =>\n fromSlateValue(\n [element],\n schemaTypes.block.name,\n KEY_TO_VALUE_ELEMENT.get(editor),\n )[0],\n [editor, element, schemaTypes.block.name],\n )\n\n let renderedBlock = children\n\n let className: string | undefined\n\n const blockPath: Path = useMemo(() => [{_key: element._key}], [element])\n\n if (typeof element._type !== 'string') {\n throw new Error(`Expected element to have a _type property`)\n }\n\n if (typeof element._key !== 'string') {\n throw new Error(`Expected element to have a _key property`)\n }\n\n // Test for inline objects first\n if (editor.isInline(element)) {\n const path = ReactEditor.findPath(editor, element)\n const [block] = Editor.node(editor, path, {depth: 1})\n const schemaType = schemaTypes.inlineObjects.find(\n (_type) => _type.name === element._type,\n )\n if (!schemaType) {\n throw new Error('Could not find type for inline block element')\n }\n if (SlateElement.isElement(block)) {\n const elmPath: Path = [\n {_key: block._key},\n 'children',\n {_key: element._key},\n ]\n if (debugRenders) {\n debug(`Render ${element._key} (inline object)`)\n }\n return (\n <span {...attributes}>\n {/* Note that children must follow immediately or cut and selections will not work properly in Chrome. */}\n {children}\n <span\n draggable={!readOnly}\n className=\"pt-inline-object\"\n data-testid=\"pt-inline-object\"\n ref={inlineBlockObjectRef}\n key={element._key}\n style={inlineBlockStyle}\n contentEditable={false}\n >\n {renderChild &&\n renderChild({\n annotations: EMPTY_ANNOTATIONS, // These inline objects currently doesn't support annotations. This is a limitation of the current PT spec/model.\n children: <DefaultInlineObject value={value} />,\n editorElementRef: inlineBlockObjectRef,\n focused,\n path: elmPath,\n schemaType,\n selected,\n type: schemaType,\n value: value as PortableTextChild,\n })}\n {!renderChild && <DefaultInlineObject value={value} />}\n </span>\n </span>\n )\n }\n throw new Error('Block not found!')\n }\n\n // If not inline, it's either a block (text) or a block object (non-text)\n // NOTE: text blocks aren't draggable with DraggableBlock (yet?)\n if (element._type === schemaTypes.block.name) {\n className = `pt-block pt-text-block`\n const isListItem = 'listItem' in element\n if (debugRenders) {\n debug(`Render ${element._key} (text block)`)\n }\n const style = ('style' in element && element.style) || 'normal'\n className = `pt-block pt-text-block pt-text-block-style-${style}`\n const blockStyleType = schemaTypes.styles.find(\n (item) => item.value === style,\n )\n if (renderStyle && blockStyleType) {\n renderedBlock = renderStyle({\n block: element as PortableTextTextBlock,\n children,\n focused,\n selected,\n value: style,\n path: blockPath,\n schemaType: blockStyleType,\n editorElementRef: blockRef,\n })\n }\n let level: number | undefined\n\n if (isListItem) {\n if (typeof element.level === 'number') {\n level = element.level\n }\n className += ` pt-list-item pt-list-item-${element.listItem} pt-list-item-level-${level || 1}`\n }\n\n if (editor.isListBlock(value) && isListItem && element.listItem) {\n const listType = schemaTypes.lists.find(\n (item) => item.value === element.listItem,\n )\n if (renderListItem && listType) {\n renderedBlock = renderListItem({\n block: value,\n children: renderedBlock,\n focused,\n selected,\n value: element.listItem,\n path: blockPath,\n schemaType: listType,\n level: value.level || 1,\n editorElementRef: blockRef,\n })\n }\n }\n\n const renderProps: Omit<BlockRenderProps, 'type'> = Object.defineProperty(\n {\n children: renderedBlock,\n editorElementRef: blockRef,\n focused,\n level,\n listItem: isListItem ? element.listItem : undefined,\n path: blockPath,\n selected,\n style,\n schemaType: schemaTypes.block,\n value,\n },\n 'type',\n {\n enumerable: false,\n get() {\n console.warn(\n \"Property 'type' is deprecated, use 'schemaType' instead.\",\n )\n return schemaTypes.block\n },\n },\n )\n\n const propsOrDefaultRendered = renderBlock\n ? renderBlock(renderProps as BlockRenderProps)\n : children\n\n return (\n <div\n key={element._key}\n {...attributes}\n className={className}\n spellCheck={spellCheck}\n {...droppable.droppableProps}\n >\n {droppable.isDraggingOverTop ? <DropIndicator /> : null}\n <div ref={blockRef}>{propsOrDefaultRendered}</div>\n {droppable.isDraggingOverBottom ? <DropIndicator /> : null}\n </div>\n )\n }\n\n const schemaType = schemaTypes.blockObjects.find(\n (_type) => _type.name === element._type,\n )\n\n if (!schemaType) {\n throw new Error(\n `Could not find schema type for block element of _type ${element._type}`,\n )\n }\n\n if (debugRenders) {\n debug(`Render ${element._key} (object block)`)\n }\n\n className = 'pt-block pt-object-block'\n\n const block = fromSlateValue(\n [element],\n schemaTypes.block.name,\n KEY_TO_VALUE_ELEMENT.get(editor),\n )[0]\n\n let renderedBlockFromProps: JSX.Element | undefined\n\n if (renderBlock) {\n const _props: Omit<BlockRenderProps, 'type'> = Object.defineProperty(\n {\n children: <DefaultBlockObject value={value} />,\n editorElementRef: blockRef,\n focused,\n path: blockPath,\n schemaType,\n selected,\n value: block,\n },\n 'type',\n {\n enumerable: false,\n get() {\n console.warn(\n \"Property 'type' is deprecated, use 'schemaType' instead.\",\n )\n return schemaType\n },\n },\n )\n renderedBlockFromProps = renderBlock(_props as BlockRenderProps)\n }\n\n return (\n <div\n key={element._key}\n {...attributes}\n className={className}\n {...droppable.droppableProps}\n {...draggable.draggableProps}\n >\n {droppable.isDraggingOverTop ? <DropIndicator /> : null}\n {children}\n <div ref={blockRef} contentEditable={false}>\n {renderedBlockFromProps ? (\n renderedBlockFromProps\n ) : (\n <DefaultBlockObject value={value} />\n )}\n </div>\n {droppable.isDraggingOverBottom ? <DropIndicator /> : null}\n </div>\n )\n}\n\nElement.displayName = 'Element'\n","import type {\n Path,\n PortableTextObject,\n PortableTextTextBlock,\n} from '@sanity/types'\nimport {isEqual, uniq} from 'lodash'\nimport {\n startTransition,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ReactElement,\n} from 'react'\nimport {Text} from 'slate'\nimport {useSelected, type RenderLeafProps} from 'slate-react'\nimport {debugWithName} from '../../internal-utils/debug'\nimport type {\n BlockAnnotationRenderProps,\n BlockChildRenderProps,\n BlockDecoratorRenderProps,\n PortableTextMemberSchemaTypes,\n RenderAnnotationFunction,\n RenderChildFunction,\n RenderDecoratorFunction,\n} from '../../types/editor'\nimport type {EditorActor} from '../editor-machine'\nimport {usePortableTextEditor} from '../hooks/usePortableTextEditor'\nimport {PortableTextEditor} from '../PortableTextEditor'\n\nconst debug = debugWithName('components:Leaf')\n\nconst EMPTY_MARKS: string[] = []\n\n/**\n * @internal\n */\nexport interface LeafProps extends RenderLeafProps {\n editorActor: EditorActor\n children: ReactElement<any>\n schemaTypes: PortableTextMemberSchemaTypes\n renderAnnotation?: RenderAnnotationFunction\n renderChild?: RenderChildFunction\n renderDecorator?: RenderDecoratorFunction\n readOnly: boolean\n}\n\n/**\n * Renders Portable Text span nodes in Slate\n * @internal\n */\nexport const Leaf = (props: LeafProps) => {\n const {\n editorActor,\n attributes,\n children,\n leaf,\n schemaTypes,\n renderChild,\n renderDecorator,\n renderAnnotation,\n } = props\n const spanRef = useRef<HTMLElement>(null)\n const portableTextEditor = usePortableTextEditor()\n const blockSelected = useSelected()\n const [focused, setFocused] = useState(false)\n const [selected, setSelected] = useState(false)\n const block = children.props.parent as PortableTextTextBlock | undefined\n const path: Path = useMemo(\n () => (block ? [{_key: block?._key}, 'children', {_key: leaf._key}] : []),\n [block, leaf._key],\n )\n const decoratorValues = useMemo(\n () => schemaTypes.decorators.map((dec) => dec.value),\n [schemaTypes.decorators],\n )\n const marks: string[] = useMemo(\n () =>\n uniq(\n (leaf.marks || EMPTY_MARKS).filter((mark) =>\n decoratorValues.includes(mark),\n ),\n ),\n [decoratorValues, leaf.marks],\n )\n const annotationMarks = Array.isArray(leaf.marks) ? leaf.marks : EMPTY_MARKS\n const annotations = useMemo(\n () =>\n annotationMarks\n .map(\n (mark) =>\n !decoratorValues.includes(mark) &&\n block?.markDefs?.find((def) => def._key === mark),\n )\n .filter(Boolean) as PortableTextObject[],\n [annotationMarks, block, decoratorValues],\n )\n\n const shouldTrackSelectionAndFocus = annotations.length > 0 && blockSelected\n\n useEffect(() => {\n if (!shouldTrackSelectionAndFocus) {\n setFocused(false)\n return\n }\n const sel = PortableTextEditor.getSelection(portableTextEditor)\n if (\n sel &&\n isEqual(sel.focus.path, path) &&\n PortableTextEditor.isCollapsedSelection(portableTextEditor)\n ) {\n startTransition(() => {\n setFocused(true)\n })\n }\n }, [shouldTrackSelectionAndFocus, path, portableTextEditor])\n\n // Function to check if this leaf is currently inside the user's text selection\n const setSelectedFromRange = useCallback(() => {\n if (!shouldTrackSelectionAndFocus) {\n return\n }\n debug('Setting selection and focus from range')\n const winSelection = window.getSelection()\n if (!winSelection) {\n setSelected(false)\n return\n }\n if (winSelection && winSelection.rangeCount > 0) {\n const range = winSelection.getRangeAt(0)\n if (spanRef.current && range.intersectsNode(spanRef.current)) {\n setSelected(true)\n } else {\n setSelected(false)\n }\n } else {\n setSelected(false)\n }\n }, [shouldTrackSelectionAndFocus])\n\n useEffect(() => {\n if (!shouldTrackSelectionAndFocus) {\n return undefined\n }\n\n const onBlur = editorActor.on('blur', () => {\n setFocused(false)\n setSelected(false)\n })\n\n const onFocus = editorActor.on('focus', () => {\n const sel = PortableTextEditor.getSelection(portableTextEditor)\n if (\n sel &&\n isEqual(sel.focus.path, path) &&\n PortableTextEditor.isCollapsedSelection(portableTextEditor)\n ) {\n setFocused(true)\n }\n setSelectedFromRange()\n })\n\n const onSelection = editorActor.on('selection', (event) => {\n if (\n event.selection &&\n isEqual(event.selection.focus.path, path) &&\n PortableTextEditor.isCollapsedSelection(portableTextEditor)\n ) {\n setFocused(true)\n } else {\n setFocused(false)\n }\n setSelectedFromRange()\n })\n\n return () => {\n onBlur.unsubscribe()\n onFocus.unsubscribe()\n onSelection.unsubscribe()\n }\n }, [\n editorActor,\n path,\n portableTextEditor,\n setSelectedFromRange,\n shouldTrackSelectionAndFocus,\n ])\n\n useEffect(() => setSelectedFromRange(), [setSelectedFromRange])\n\n const content = useMemo(() => {\n let returnedChildren = children\n // Render text nodes\n if (Text.isText(leaf) && leaf._type === schemaTypes.span.name) {\n marks.forEach((mark) => {\n const schemaType = schemaTypes.decorators.find(\n (dec) => dec.value === mark,\n )\n if (schemaType && renderDecorator) {\n const _props: Omit<BlockDecoratorRenderProps, 'type'> =\n Object.defineProperty(\n {\n children: returnedChildren,\n editorElementRef: spanRef,\n focused,\n path,\n selected,\n schemaType,\n value: mark,\n },\n 'type',\n {\n enumerable: false,\n get() {\n console.warn(\n \"Property 'type' is deprecated, use 'schemaType' instead.\",\n )\n return schemaType\n },\n },\n )\n returnedChildren = renderDecorator(\n _props as BlockDecoratorRenderProps,\n )\n }\n })\n\n if (block && annotations.length > 0) {\n annotations.forEach((annotation) => {\n const schemaType = schemaTypes.annotations.find(\n (t) => t.name === annotation._type,\n )\n if (schemaType) {\n if (renderAnnotation) {\n const _props: Omit<BlockAnnotationRenderProps, 'type'> =\n Object.defineProperty(\n {\n block,\n children: returnedChildren,\n editorElementRef: spanRef,\n focused,\n path,\n selected,\n schemaType,\n value: annotation,\n },\n 'type',\n {\n enumerable: false,\n get() {\n console.warn(\n \"Property 'type' is deprecated, use 'schemaType' instead.\",\n )\n return schemaType\n },\n },\n )\n\n returnedChildren = (\n <span ref={spanRef}>\n {renderAnnotation(_props as BlockAnnotationRenderProps)}\n </span>\n )\n } else {\n returnedChildren = <span ref={spanRef}>{returnedChildren}</span>\n }\n }\n })\n }\n if (block && renderChild) {\n const child = block.children.find((_child) => _child._key === leaf._key) // Ensure object equality\n if (child) {\n const defaultRendered = <>{returnedChildren}</>\n const _props: Omit<BlockChildRenderProps, 'type'> =\n Object.defineProperty(\n {\n annotations,\n children: defaultRendered,\n editorElementRef: spanRef,\n focused,\n path,\n schemaType: schemaTypes.span,\n selected,\n value: child,\n },\n 'type',\n {\n enumerable: false,\n get() {\n console.warn(\n \"Property 'type' is deprecated, use 'schemaType' instead.\",\n )\n return schemaTypes.span\n },\n },\n )\n returnedChildren = renderChild(_props as BlockChildRenderProps)\n }\n }\n }\n return returnedChildren\n }, [\n annotations,\n block,\n children,\n focused,\n leaf,\n marks,\n path,\n renderAnnotation,\n renderChild,\n renderDecorator,\n schemaTypes.annotations,\n schemaTypes.decorators,\n schemaTypes.span,\n selected,\n ])\n return useMemo(\n () => (\n <span key={leaf._key} {...attributes} ref={spanRef}>\n {content}\n </span>\n ),\n [leaf, attributes, content],\n )\n}\n\nLeaf.displayName = 'Leaf'\n","import type {KeyboardEvent} from 'react'\nimport type {ReactEditor} from 'slate-react'\nimport {debugWithName} from '../../internal-utils/debug'\nimport {isHotkey} from '../../internal-utils/is-hotkey'\nimport type {PortableTextSlateEditor} from '../../types/editor'\nimport type {HotkeyOptions} from '../../types/options'\nimport type {EditorActor} from '../editor-machine'\nimport type {PortableTextEditor} from '../PortableTextEditor'\n\nconst debug = debugWithName('plugin:withHotKeys')\n\n/**\n * This plugin takes care of all hotkeys in the editor\n *\n */\nexport function createWithHotkeys(\n editorActor: EditorActor,\n portableTextEditor: PortableTextEditor,\n hotkeysFromOptions?: HotkeyOptions,\n): (editor: PortableTextSlateEditor & ReactEditor) => any {\n const reservedHotkeys = ['enter', 'tab', 'shift', 'delete', 'end']\n const activeHotkeys = hotkeysFromOptions ?? {}\n return function withHotKeys(editor: PortableTextSlateEditor & ReactEditor) {\n editor.pteWithHotKeys = (event: KeyboardEvent<HTMLDivElement>): void => {\n // Wire up custom marks hotkeys\n Object.keys(activeHotkeys).forEach((cat) => {\n if (cat === 'marks') {\n for (const hotkey in activeHotkeys[cat]) {\n if (reservedHotkeys.includes(hotkey)) {\n throw new Error(`The hotkey ${hotkey} is reserved!`)\n }\n if (isHotkey(hotkey, event.nativeEvent)) {\n event.preventDefault()\n const possibleMark = activeHotkeys[cat]\n if (possibleMark) {\n const mark = possibleMark[hotkey]\n debug(`HotKey ${hotkey} to toggle ${mark}`)\n editorActor.send({\n type: 'behavior event',\n behaviorEvent: {\n type: 'decorator.toggle',\n decorator: mark,\n },\n editor,\n })\n }\n }\n }\n }\n if (cat === 'custom') {\n for (const hotkey in activeHotkeys[cat]) {\n if (reservedHotkeys.includes(hotkey)) {\n throw new Error(`The hotkey ${hotkey} is reserved!`)\n }\n if (isHotkey(hotkey, event.nativeEvent)) {\n const possibleCommand = activeHotkeys[cat]\n if (possibleCommand) {\n const command = possibleCommand[hotkey]\n command(event, portableTextEditor)\n }\n }\n }\n }\n })\n }\n return editor\n }\n}\n","import type {BaseEditor, Operation} from 'slate'\nimport type {ReactEditor} from 'slate-react'\nimport type {PortableTextSlateEditor} from '../types/editor'\nimport type {EditorActor} from './editor-machine'\n\n// React Compiler considers `slateEditor` as immutable, and opts-out if we do this inline in a useEffect, doing it in a function moves it out of the scope, and opts-in again for the rest of the component.\nexport function withSyncRangeDecorations({\n editorActor,\n slateEditor,\n syncRangeDecorations,\n}: {\n editorActor: EditorActor\n slateEditor: BaseEditor & ReactEditor & PortableTextSlateEditor\n syncRangeDecorations: (operation?: Operation) => void\n}) {\n const originalApply = slateEditor.apply\n\n slateEditor.apply = (op: Operation) => {\n originalApply(op)\n\n if (\n !editorActor.getSnapshot().matches({'edit mode': 'read only'}) &&\n op.type !== 'set_selection'\n ) {\n syncRangeDecorations(op)\n }\n }\n\n return () => {\n slateEditor.apply = originalApply\n }\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport {useSelector} from '@xstate/react'\nimport {isEqual, noop} from 'lodash'\nimport {\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n type ClipboardEvent,\n type CSSProperties,\n type FocusEventHandler,\n type KeyboardEvent,\n type MutableRefObject,\n type TextareaHTMLAttributes,\n} from 'react'\nimport {\n Editor,\n Node,\n Path,\n Range as SlateRange,\n Transforms,\n type BaseRange,\n type NodeEntry,\n type Operation,\n type Text,\n} from 'slate'\nimport {\n ReactEditor,\n Editable as SlateEditable,\n useSlate,\n type RenderElementProps,\n type RenderLeafProps,\n} from 'slate-react'\nimport {debugWithName} from '../internal-utils/debug'\nimport {\n moveRangeByOperation,\n toPortableTextRange,\n toSlateRange,\n} from '../internal-utils/ranges'\nimport {normalizeSelection} from '../internal-utils/selection'\nimport {\n fromSlateValue,\n isEqualToEmptyEditor,\n toSlateValue,\n} from '../internal-utils/values'\nimport type {\n EditorSelection,\n OnCopyFn,\n OnPasteFn,\n RangeDecoration,\n RenderAnnotationFunction,\n RenderBlockFunction,\n RenderChildFunction,\n RenderDecoratorFunction,\n RenderListItemFunction,\n RenderPlaceholderFunction,\n RenderStyleFunction,\n ScrollSelectionIntoViewFunction,\n} from '../types/editor'\nimport type {HotkeyOptions} from '../types/options'\nimport type {SlateTextBlock, VoidElement} from '../types/slate'\nimport {Element} from './components/Element'\nimport {Leaf} from './components/Leaf'\nimport {EditorActorContext} from './editor-actor-context'\nimport {usePortableTextEditor} from './hooks/usePortableTextEditor'\nimport {createWithHotkeys} from './plugins/createWithHotKeys'\nimport {PortableTextEditor} from './PortableTextEditor'\nimport {withSyncRangeDecorations} from './withSyncRangeDecorations'\n\nconst debug = debugWithName('component:Editable')\n\nconst PLACEHOLDER_STYLE: CSSProperties = {\n position: 'absolute',\n userSelect: 'none',\n pointerEvents: 'none',\n left: 0,\n right: 0,\n}\n\ninterface BaseRangeWithDecoration extends BaseRange {\n rangeDecoration: RangeDecoration\n}\n\n/**\n * @public\n */\nexport type PortableTextEditableProps = Omit<\n TextareaHTMLAttributes<HTMLDivElement>,\n 'onPaste' | 'onCopy' | 'onBeforeInput'\n> & {\n hotkeys?: HotkeyOptions\n onBeforeInput?: (event: InputEvent) => void\n onPaste?: OnPasteFn\n onCopy?: OnCopyFn\n ref: MutableRefObject<HTMLDivElement | null>\n rangeDecorations?: RangeDecoration[]\n renderAnnotation?: RenderAnnotationFunction\n renderBlock?: RenderBlockFunction\n renderChild?: RenderChildFunction\n renderDecorator?: RenderDecoratorFunction\n renderListItem?: RenderListItemFunction\n renderPlaceholder?: RenderPlaceholderFunction\n renderStyle?: RenderStyleFunction\n scrollSelectionIntoView?: ScrollSelectionIntoViewFunction\n selection?: EditorSelection\n spellCheck?: boolean\n}\n\n/**\n * @public\n *\n *\n * The core component that renders the editor. Must be placed within the {@link EditorProvider} component.\n *\n * @example\n * ```tsx\n * import { PortableTextEditable, EditorProvider } from '@portabletext/editor'\n *\n * function MyComponent() {\n * return (\n * <EditorProvider>\n * <PortableTextEditable />\n * </EditorProvider>\n * )\n * }\n * ```\n * @group Components\n */\nexport const PortableTextEditable = forwardRef<\n Omit<HTMLDivElement, 'as' | 'onPaste' | 'onBeforeInput'>,\n PortableTextEditableProps\n>(function PortableTextEditable(props, forwardedRef) {\n const {\n hotkeys,\n onBlur,\n onFocus,\n onBeforeInput,\n onPaste,\n onCopy,\n onClick,\n rangeDecorations,\n renderAnnotation,\n renderBlock,\n renderChild,\n renderDecorator,\n renderListItem,\n renderPlaceholder,\n renderStyle,\n selection: propsSelection,\n scrollSelectionIntoView,\n spellCheck,\n ...restProps\n } = props\n\n const portableTextEditor = usePortableTextEditor()\n const ref = useRef<HTMLDivElement | null>(null)\n const [editableElement, setEditableElement] = useState<HTMLDivElement | null>(\n null,\n )\n const [hasInvalidValue, setHasInvalidValue] = useState(false)\n const [rangeDecorationState, setRangeDecorationsState] = useState<\n BaseRangeWithDecoration[]\n >([])\n\n // Forward ref to parent component\n useImperativeHandle<HTMLDivElement | null, HTMLDivElement | null>(\n forwardedRef,\n () => ref.current,\n )\n\n const rangeDecorationsRef = useRef(rangeDecorations)\n\n const editorActor = useContext(EditorActorContext)\n const readOnly = useSelector(editorActor, (s) =>\n s.matches({'edit mode': 'read only'}),\n )\n const schemaTypes = useSelector(editorActor, (s) => s.context.schema)\n const slateEditor = useSlate()\n\n const blockTypeName = schemaTypes.block.name\n\n // Output a minimal React editor inside Editable when in readOnly mode.\n // NOTE: make sure all the plugins used here can be safely run over again at any point.\n // There will be a problem if they redefine editor methods and then calling the original method within themselves.\n useMemo(() => {\n // React/UI-specific plugins\n if (readOnly) {\n debug('Editable is in read only mode')\n return slateEditor\n }\n const withHotKeys = createWithHotkeys(\n editorActor,\n portableTextEditor,\n hotkeys,\n )\n\n debug('Editable is in edit mode')\n return withHotKeys(slateEditor)\n }, [editorActor, hotkeys, portableTextEditor, readOnly, slateEditor])\n\n const renderElement = useCallback(\n (eProps: RenderElementProps) => (\n <Element\n {...eProps}\n readOnly={readOnly}\n renderBlock={renderBlock}\n renderChild={renderChild}\n renderListItem={renderListItem}\n renderStyle={renderStyle}\n schemaTypes={schemaTypes}\n spellCheck={spellCheck}\n />\n ),\n [\n schemaTypes,\n spellCheck,\n readOnly,\n renderBlock,\n renderChild,\n renderListItem,\n renderStyle,\n ],\n )\n\n const renderLeaf = useCallback(\n (\n lProps: RenderLeafProps & {\n leaf: Text & {placeholder?: boolean; rangeDecoration?: RangeDecoration}\n },\n ) => {\n if (lProps.leaf._type === 'span') {\n let rendered = (\n <Leaf\n {...lProps}\n editorActor={editorActor}\n schemaTypes={schemaTypes}\n renderAnnotation={renderAnnotation}\n renderChild={renderChild}\n renderDecorator={renderDecorator}\n readOnly={readOnly}\n />\n )\n if (\n renderPlaceholder &&\n lProps.leaf.placeholder &&\n lProps.text.text === ''\n ) {\n return (\n <>\n <span style={PLACEHOLDER_STYLE} contentEditable={false}>\n {renderPlaceholder()}\n </span>\n {rendered}\n </>\n )\n }\n const decoration = lProps.leaf.rangeDecoration\n if (decoration) {\n rendered = decoration.component({children: rendered})\n }\n return rendered\n }\n return lProps.children\n },\n [\n editorActor,\n readOnly,\n renderAnnotation,\n renderChild,\n renderDecorator,\n renderPlaceholder,\n schemaTypes,\n ],\n )\n\n const restoreSelectionFromProps = useCallback(() => {\n if (propsSelection) {\n debug(`Selection from props ${JSON.stringify(propsSelection)}`)\n const normalizedSelection = normalizeSelection(\n propsSelection,\n fromSlateValue(slateEditor.children, blockTypeName),\n )\n if (normalizedSelection !== null) {\n debug(\n `Normalized selection from props ${JSON.stringify(normalizedSelection)}`,\n )\n const slateRange = toSlateRange(normalizedSelection, slateEditor)\n if (slateRange) {\n Transforms.select(slateEditor, slateRange)\n // Output selection here in those cases where the editor selection was the same, and there are no set_selection operations made.\n // The selection is usually automatically emitted to change$ by the withPortableTextSelections plugin whenever there is a set_selection operation applied.\n if (!slateEditor.operations.some((o) => o.type === 'set_selection')) {\n editorActor.send({\n type: 'notify.selection',\n selection: normalizedSelection,\n })\n }\n slateEditor.onChange()\n }\n }\n }\n }, [blockTypeName, editorActor, propsSelection, slateEditor])\n\n const syncRangeDecorations = useCallback(\n (operation?: Operation) => {\n if (rangeDecorations && rangeDecorations.length > 0) {\n const newSlateRanges: BaseRangeWithDecoration[] = []\n rangeDecorations.forEach((rangeDecorationItem) => {\n const slateRange = toSlateRange(\n rangeDecorationItem.selection,\n slateEditor,\n )\n if (!SlateRange.isRange(slateRange)) {\n if (rangeDecorationItem.onMoved) {\n rangeDecorationItem.onMoved({\n newSelection: null,\n rangeDecoration: rangeDecorationItem,\n origin: 'local',\n })\n }\n return\n }\n let newRange: BaseRange | null | undefined\n if (operation) {\n newRange = moveRangeByOperation(slateRange, operation)\n if (\n (newRange && newRange !== slateRange) ||\n (newRange === null && slateRange)\n ) {\n const value = PortableTextEditor.getValue(portableTextEditor)\n const newRangeSelection = toPortableTextRange(\n value,\n newRange,\n schemaTypes,\n )\n if (rangeDecorationItem.onMoved) {\n rangeDecorationItem.onMoved({\n newSelection: newRangeSelection,\n rangeDecoration: rangeDecorationItem,\n origin: 'local',\n })\n }\n }\n }\n // If the newRange is null, it means that the range is not valid anymore and should be removed\n // If it's undefined, it means that the slateRange is still valid and should be kept\n if (newRange !== null) {\n newSlateRanges.push({\n ...(newRange || slateRange),\n rangeDecoration: rangeDecorationItem,\n })\n }\n })\n if (newSlateRanges.length > 0) {\n setRangeDecorationsState(newSlateRanges)\n return\n }\n }\n setRangeDecorationsState((rangeDecorationState) => {\n // If there's state then we want to reset\n if (rangeDecorationState.length > 0) {\n return []\n }\n // Otherwise we no-op, React will skip a state update if what we return has reference equality to the previous state\n return rangeDecorationState\n })\n },\n [portableTextEditor, rangeDecorations, schemaTypes, slateEditor],\n )\n\n // Restore selection from props when the editor has been initialized properly with it's value\n useEffect(() => {\n const onReady = editorActor.on('ready', () => {\n syncRangeDecorations()\n restoreSelectionFromProps()\n })\n const onInvalidValue = editorActor.on('invalid value', () => {\n setHasInvalidValue(true)\n })\n const onValueChanged = editorActor.on('value changed', () => {\n setHasInvalidValue(false)\n })\n\n return () => {\n onReady.unsubscribe()\n onInvalidValue.unsubscribe()\n onValueChanged.unsubscribe()\n }\n }, [editorActor, restoreSelectionFromProps, syncRangeDecorations])\n\n // Restore selection from props when it changes\n useEffect(() => {\n if (propsSelection && !hasInvalidValue) {\n restoreSelectionFromProps()\n }\n }, [hasInvalidValue, propsSelection, restoreSelectionFromProps])\n\n const [syncedRangeDecorations, setSyncedRangeDecorations] = useState(false)\n useEffect(() => {\n if (!syncedRangeDecorations) {\n // We only want this to run once, on mount\n setSyncedRangeDecorations(true)\n syncRangeDecorations()\n }\n }, [syncRangeDecorations, syncedRangeDecorations])\n\n useEffect(() => {\n if (!isEqual(rangeDecorations, rangeDecorationsRef.current)) {\n syncRangeDecorations()\n }\n rangeDecorationsRef.current = rangeDecorations\n }, [rangeDecorations, syncRangeDecorations])\n\n // Sync range decorations after an operation is applied\n useEffect(() => {\n const teardown = withSyncRangeDecorations({\n editorActor,\n slateEditor,\n syncRangeDecorations,\n })\n return () => teardown()\n }, [editorActor, slateEditor, syncRangeDecorations])\n\n // Handle from props onCopy function\n const handleCopy = useCallback(\n (event: ClipboardEvent<HTMLDivElement>): void | ReactEditor => {\n if (onCopy) {\n const result = onCopy(event)\n // CopyFn may return something to avoid doing default stuff\n if (result !== undefined) {\n event.preventDefault()\n }\n } else if (event.nativeEvent.clipboardData) {\n editorActor.send({\n type: 'behavior event',\n behaviorEvent: {\n type: 'copy',\n data: event.nativeEvent.clipboardData,\n },\n editor: slateEditor,\n nativeEvent: event,\n })\n }\n },\n [onCopy, editorActor, slateEditor],\n )\n\n // Handle incoming pasting events in the editor\n const handlePaste = useCallback(\n (event: ClipboardEvent<HTMLDivElement>): Promise<void> | void => {\n const value = PortableTextEditor.getValue(portableTextEditor)\n const ptRange = toPortableTextRange(\n value,\n slateEditor.selection,\n schemaTypes,\n )\n const path = ptRange?.focus.path || []\n const onPasteResult = onPaste?.({event, value, path, schemaTypes})\n\n if (onPasteResult || !slateEditor.selection) {\n event.preventDefault()\n\n // Resolve it as promise (can be either async promise or sync return value)\n editorActor.send({type: 'notify.loading'})\n\n Promise.resolve(onPasteResult)\n .then((result) => {\n debug('Custom paste function from client resolved', result)\n\n if (!result || !result.insert) {\n debug('No result from custom paste handler, pasting normally')\n\n slateEditor.insertData(event.clipboardData)\n } else if (result.insert) {\n slateEditor.insertFragment(\n toSlateValue(result.insert as PortableTextBlock[], {\n schemaTypes,\n }),\n )\n } else {\n console.warn(\n 'Your onPaste function returned something unexpected:',\n result,\n )\n }\n })\n .catch((error) => {\n console.error(error)\n\n return error\n })\n .finally(() => {\n editorActor.send({type: 'notify.done loading'})\n })\n } else if (event.nativeEvent.clipboardData) {\n editorActor.send({\n type: 'behavior event',\n behaviorEvent: {\n type: 'paste',\n data: event.nativeEvent.clipboardData,\n },\n editor: slateEditor,\n nativeEvent: event,\n })\n }\n\n debug('No result from custom paste handler, pasting normally')\n },\n [editorActor, onPaste, portableTextEditor, schemaTypes, slateEditor],\n )\n\n const handleOnFocus: FocusEventHandler<HTMLDivElement> = useCallback(\n (event) => {\n if (onFocus) {\n onFocus(event)\n }\n if (!event.isDefaultPrevented()) {\n const selection = PortableTextEditor.getSelection(portableTextEditor)\n // Create an editor selection if it does'nt exist\n if (selection === null) {\n Transforms.select(slateEditor, Editor.start(slateEditor, []))\n slateEditor.onChange()\n }\n editorActor.send({type: 'notify.focused', event})\n const newSelection = PortableTextEditor.getSelection(portableTextEditor)\n // If the selection is the same, emit it explicitly here as there is no actual onChange event triggered.\n if (selection === newSelection) {\n editorActor.send({\n type: 'notify.selection',\n selection,\n })\n }\n }\n },\n [editorActor, onFocus, portableTextEditor, slateEditor],\n )\n\n const handleClick = useCallback(\n (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {\n if (onClick) {\n onClick(event)\n }\n\n const focusBlockPath = slateEditor.selection\n ? slateEditor.selection.focus.path.slice(0, 1)\n : undefined\n const focusBlock = focusBlockPath\n ? (Node.descendant(slateEditor, focusBlockPath) as\n | SlateTextBlock\n | VoidElement)\n : undefined\n const [_, lastNodePath] = Node.last(slateEditor, [])\n const lastBlockPath = lastNodePath.slice(0, 1)\n const lastNodeFocused = focusBlockPath\n ? Path.equals(lastBlockPath, focusBlockPath)\n : false\n const lastBlockIsVoid = focusBlock\n ? !slateEditor.isTextBlock(focusBlock)\n : false\n const collapsedSelection =\n slateEditor.selection && SlateRange.isCollapsed(slateEditor.selection)\n\n if (collapsedSelection && lastNodeFocused && lastBlockIsVoid) {\n Transforms.insertNodes(\n slateEditor,\n slateEditor.pteCreateTextBlock({decorators: []}),\n )\n slateEditor.onChange()\n }\n },\n [onClick, slateEditor],\n )\n\n const handleOnBlur: FocusEventHandler<HTMLDivElement> = useCallback(\n (event) => {\n if (onBlur) {\n onBlur(event)\n }\n if (!event.isPropagationStopped()) {\n editorActor.send({type: 'notify.blurred', event})\n }\n },\n [editorActor, onBlur],\n )\n\n const handleOnBeforeInput = useCallback(\n (event: InputEvent) => {\n if (onBeforeInput) {\n onBeforeInput(event)\n }\n },\n [onBeforeInput],\n )\n\n // This function will handle unexpected DOM changes inside the Editable rendering,\n // and make sure that we can maintain a stable slateEditor.selection when that happens.\n //\n // For example, if this Editable is rendered inside something that might re-render\n // this component (hidden contexts) while the user is still actively changing the\n // contentEditable, this could interfere with the intermediate DOM selection,\n // which again could be picked up by ReactEditor's event listeners.\n // If that range is invalid at that point, the slate.editorSelection could be\n // set either wrong, or invalid, to which slateEditor will throw exceptions\n // that are impossible to recover properly from or result in a wrong selection.\n //\n // Also the other way around, when the ReactEditor will try to create a DOM Range\n // from the current slateEditor.selection, it may throw unrecoverable errors\n // if the current editor.selection is invalid according to the DOM.\n // If this is the case, default to selecting the top of the document, if the\n // user already had a selection.\n const validateSelection = useCallback(() => {\n if (!slateEditor.selection) {\n return\n }\n const root = ReactEditor.findDocumentOrShadowRoot(slateEditor)\n const {activeElement} = root\n // Return if the editor isn't the active element\n if (ref.current !== activeElement) {\n return\n }\n const window = ReactEditor.getWindow(slateEditor)\n const domSelection = window.getSelection()\n if (!domSelection || domSelection.rangeCount === 0) {\n return\n }\n const existingDOMRange = domSelection.getRangeAt(0)\n try {\n const newDOMRange = ReactEditor.toDOMRange(\n slateEditor,\n slateEditor.selection,\n )\n if (\n newDOMRange.startOffset !== existingDOMRange.startOffset ||\n newDOMRange.endOffset !== existingDOMRange.endOffset\n ) {\n debug('DOM range out of sync, validating selection')\n // Remove all ranges temporary\n domSelection?.removeAllRanges()\n // Set the correct range\n domSelection.addRange(newDOMRange)\n }\n } catch {\n debug(`Could not resolve selection, selecting top document`)\n // Deselect the editor\n Transforms.deselect(slateEditor)\n // Select top document if there is a top block to select\n if (slateEditor.children.length > 0) {\n Transforms.select(slateEditor, [0, 0])\n }\n slateEditor.onChange()\n }\n }, [ref, slateEditor])\n\n // Observe mutations (child list and subtree) to this component's DOM,\n // and make sure the editor selection is valid when that happens.\n useEffect(() => {\n if (editableElement) {\n const mutationObserver = new MutationObserver(validateSelection)\n mutationObserver.observe(editableElement, {\n attributeOldValue: false,\n attributes: false,\n characterData: false,\n childList: true,\n subtree: true,\n })\n return () => {\n mutationObserver.disconnect()\n }\n }\n return undefined\n }, [validateSelection, editableElement])\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent<HTMLDivElement>) => {\n if (props.onKeyDown) {\n props.onKeyDown(event)\n }\n if (!event.isDefaultPrevented()) {\n slateEditor.pteWithHotKeys(event)\n }\n if (!event.isDefaultPrevented()) {\n editorActor.send({\n type: 'behavior event',\n behaviorEvent: {\n type: 'key.down',\n keyboardEvent: {\n key: event.key,\n code: event.code,\n altKey: event.altKey,\n ctrlKey: event.ctrlKey,\n metaKey: event.metaKey,\n shiftKey: event.shiftKey,\n },\n },\n editor: slateEditor,\n nativeEvent: event,\n })\n }\n },\n [props, editorActor, slateEditor],\n )\n\n const handleKeyUp = useCallback(\n (event: KeyboardEvent<HTMLDivElement>) => {\n if (props.onKeyUp) {\n props.onKeyUp(event)\n }\n if (!event.isDefaultPrevented()) {\n editorActor.send({\n type: 'behavior event',\n behaviorEvent: {\n type: 'key.up',\n keyboardEvent: {\n key: event.key,\n code: event.code,\n altKey: event.altKey,\n ctrlKey: event.ctrlKey,\n metaKey: event.metaKey,\n shiftKey: event.shiftKey,\n },\n },\n editor: slateEditor,\n nativeEvent: event,\n })\n }\n },\n [props, editorActor, slateEditor],\n )\n\n const scrollSelectionIntoViewToSlate = useMemo(() => {\n // Use slate-react default scroll into view\n if (scrollSelectionIntoView === undefined) {\n return undefined\n }\n // Disable scroll into view totally\n if (scrollSelectionIntoView === null) {\n return noop\n }\n // Translate PortableTextEditor prop fn to Slate plugin fn\n return (_editor: ReactEditor, domRange: Range) => {\n scrollSelectionIntoView(portableTextEditor, domRange)\n }\n }, [portableTextEditor, scrollSelectionIntoView])\n\n const decorate: (entry: NodeEntry) => BaseRange[] = useCallback(\n ([, path]) => {\n if (isEqualToEmptyEditor(slateEditor.children, schemaTypes)) {\n return [\n {\n anchor: {\n path: [0, 0],\n offset: 0,\n },\n focus: {\n path: [0, 0],\n offset: 0,\n },\n placeholder: true,\n },\n ]\n }\n // Editor node has a path length of 0 (should never be decorated)\n if (path.length === 0) {\n return []\n }\n const result = rangeDecorationState.filter((item) => {\n // Special case in order to only return one decoration for collapsed ranges\n if (SlateRange.isCollapsed(item)) {\n // Collapsed ranges should only be decorated if they are on a block child level (length 2)\n if (path.length !== 2) {\n return false\n }\n return (\n Path.equals(item.focus.path, path) &&\n Path.equals(item.anchor.path, path)\n )\n }\n // Include decorations that either include or intersects with this path\n return (\n SlateRange.intersection(item, {\n anchor: {path, offset: 0},\n focus: {path, offset: 0},\n }) || SlateRange.includes(item, path)\n )\n })\n if (result.length > 0) {\n return result\n }\n return []\n },\n [slateEditor, schemaTypes, rangeDecorationState],\n )\n\n // Set the forwarded ref to be the Slate editable DOM element\n // Also set the editable element in a state so that the MutationObserver\n // is setup when this element is ready.\n useEffect(() => {\n ref.current = ReactEditor.toDOMNode(\n slateEditor,\n slateEditor,\n ) as HTMLDivElement | null\n setEditableElement(ref.current)\n }, [slateEditor, ref])\n\n useEffect(() => {\n const window = ReactEditor.getWindow(slateEditor)\n\n const onDragEnd = () => {\n editorActor.send({type: 'dragend'})\n }\n const onDrop = () => {\n editorActor.send({type: 'drop'})\n }\n\n window.document.addEventListener('dragend', onDragEnd)\n window.document.addEventListener('drop', onDrop)\n\n return () => {\n window.document.removeEventListener('dragend', onDragEnd)\n window.document.removeEventListener('drop', onDrop)\n }\n }, [slateEditor, editorActor])\n\n if (!portableTextEditor) {\n return null\n }\n return hasInvalidValue ? null : (\n <SlateEditable\n {...restProps}\n autoFocus={false}\n className={restProps.className || 'pt-editable'}\n decorate={decorate}\n onBlur={handleOnBlur}\n onCopy={handleCopy}\n onClick={handleClick}\n onDOMBeforeInput={handleOnBeforeInput}\n onDragStart={(event) => {\n props.onDragStart?.(event)\n\n if (!event.isDefaultPrevented() && !event.isPropagationStopped()) {\n editorActor.send({type: 'dragstart'})\n }\n }}\n onFocus={handleOnFocus}\n onKeyDown={handleKeyDown}\n onKeyUp={handleKeyUp}\n onPaste={handlePaste}\n readOnly={readOnly}\n // We have implemented our own placeholder logic with decorations.\n // This 'renderPlaceholder' should not be used.\n renderPlaceholder={undefined}\n renderElement={renderElement}\n renderLeaf={renderLeaf}\n scrollSelectionIntoView={scrollSelectionIntoViewToSlate}\n />\n )\n})\n\nPortableTextEditable.displayName = 'ForwardRef(PortableTextEditable)'\n","import {useEffect} from 'react'\nimport {useEffectEvent} from 'use-effect-event'\nimport type {EditorEmittedEvent} from './editor/editor-machine'\nimport {useEditor} from './editor/editor-provider'\n\n/**\n * @public\n * @deprecated\n * This component has been renamed. Use `EventListenerPlugin` instead.\n *\n * ```\n * import {EventListenerPlugin} from '@portabletext/editor/plugins'\n * ```\n */\nexport function EditorEventListener(props: {\n on: (event: EditorEmittedEvent) => void\n}) {\n const editor = useEditor()\n const on = useEffectEvent(props.on)\n\n useEffect(() => {\n const subscription = editor.on('*', on)\n\n return () => {\n subscription.unsubscribe()\n }\n }, [editor])\n\n return null\n}\n"],"names":["normalizePoint","point","value","newPath","newOffset","offset","blockKey","path","_key","childKey","block","find","blk","push","children","Array","isArray","length","child","cld","text","normalizeSelection","selection","newAnchor","newFocus","anchor","focus","isEqual","backward","DefaultBlockObject","props","$","_c","t0","Symbol","for","userSelect","t1","_type","jsxs","DefaultInlineObject","DropIndicator","position","width","height","borderBottom","zIndex","debug","debugWithName","useDraggable","editor","useSlateStatic","dragGhostRef","useRef","undefined","blockElement","setBlockElement","useState","blockRef","element","current","ReactEditor","toDOMNode","useEffect","t2","event","targetBlock","IS_DRAGGING_ELEMENT_TARGET","get","set","preventDefault","stopPropagation","delete","document","body","removeChild","dragPosition","IS_DRAGGING_BLOCK_TARGET_POSITION","targetPath","findPath","myPath","isBefore","Path","originalPath","JSON","stringify","originalPath_0","equals","Transforms","moveNodes","at","to","onChange","handleDragEnd","t3","event_0","IS_DRAGGING_BLOCK_ELEMENT","target","HTMLElement","style","opacity","handleDrag","t4","event_1","IS_DRAGGING","dataTransfer","setData","effectAllowed","dragGhost","cloneNode","customGhost","querySelector","setAttribute","left","boxSizing","appendChild","rect","getBoundingClientRect","x","clientX","y","clientY","top","setDragImage","handleDragStart","readOnly","t5","draggableProps","draggable","onDragStart","onDrag","onDragEnd","useDroppable","isDragOver","setIsDragOver","isMyDragOver","dropEffect","elementRect","Y","pageY","loc","Math","abs","handleDragOver","handleDragLeave","handleDrop","isDraggingOverFirstBlock","t6","isDraggingOverLastBlock","isDraggingOverTop","isDraggingOverBottom","t7","droppableProps","onDragOver","onDragLeave","onDrop","t8","EMPTY_ANNOTATIONS","inlineBlockStyle","display","Element","attributes","schemaTypes","renderBlock","renderChild","renderListItem","renderStyle","spellCheck","selected","useSelected","inlineBlockObjectRef","focused","Range","isCollapsed","droppable","useMemo","fromSlateValue","name","KEY_TO_VALUE_ELEMENT","renderedBlock","className","blockPath","Error","isInline","Editor","node","depth","schemaType","inlineObjects","SlateElement","isElement","elmPath","debugRenders","annotations","jsx","editorElementRef","type","isListItem","blockStyleType","styles","item","level","listItem","isListBlock","listType","lists","renderProps","Object","defineProperty","enumerable","warn","propsOrDefaultRendered","blockObjects","renderedBlockFromProps","_props","displayName","EMPTY_MARKS","Leaf","editorActor","leaf","renderDecorator","renderAnnotation","spanRef","portableTextEditor","usePortableTextEditor","blockSelected","setFocused","setSelected","parent","decoratorValues","decorators","map","dec","marks","uniq","filter","mark","includes","annotationMarks","markDefs","def","Boolean","shouldTrackSelectionAndFocus","sel","PortableTextEditor","getSelection","isCollapsedSelection","startTransition","setSelectedFromRange","useCallback","winSelection","window","rangeCount","range","getRangeAt","intersectsNode","onBlur","on","onFocus","onSelection","unsubscribe","content","returnedChildren","Text","isText","span","forEach","annotation","t","_child","createWithHotkeys","hotkeysFromOptions","reservedHotkeys","activeHotkeys","pteWithHotKeys","keys","cat","hotkey","isHotkey","nativeEvent","possibleMark","send","behaviorEvent","decorator","possibleCommand","command","withSyncRangeDecorations","slateEditor","syncRangeDecorations","originalApply","apply","op","getSnapshot","matches","PLACEHOLDER_STYLE","pointerEvents","right","PortableTextEditable","forwardRef","forwardedRef","hotkeys","onBeforeInput","onPaste","onCopy","onClick","rangeDecorations","renderPlaceholder","propsSelection","scrollSelectionIntoView","restProps","ref","editableElement","setEditableElement","hasInvalidValue","setHasInvalidValue","rangeDecorationState","setRangeDecorationsState","rangeDecorationsRef","useContext","EditorActorContext","useSelector","s","context","schema","useSlate","blockTypeName","withHotKeys","renderElement","eProps","renderLeaf","lProps","rendered","placeholder","Fragment","decoration","rangeDecoration","component","restoreSelectionFromProps","normalizedSelection","slateRange","toSlateRange","select","operations","some","o","operation","newSlateRanges","rangeDecorationItem","SlateRange","isRange","onMoved","newSelection","origin","newRange","moveRangeByOperation","getValue","newRangeSelection","toPortableTextRange","onReady","onInvalidValue","onValueChanged","syncedRangeDecorations","setSyncedRangeDecorations","teardown","handleCopy","clipboardData","data","handlePaste","onPasteResult","Promise","resolve","then","result","insert","insertData","insertFragment","toSlateValue","console","catch","error","finally","handleOnFocus","isDefaultPrevented","start","handleClick","focusBlockPath","slice","focusBlock","Node","descendant","_","lastNodePath","last","lastBlockPath","lastNodeFocused","lastBlockIsVoid","isTextBlock","insertNodes","pteCreateTextBlock","handleOnBlur","isPropagationStopped","handleOnBeforeInput","validateSelection","root","findDocumentOrShadowRoot","activeElement","domSelection","getWindow","existingDOMRange","newDOMRange","toDOMRange","startOffset","endOffset","removeAllRanges","addRange","deselect","mutationObserver","MutationObserver","observe","attributeOldValue","characterData","childList","subtree","disconnect","handleKeyDown","onKeyDown","keyboardEvent","key","code","altKey","ctrlKey","metaKey","shiftKey","handleKeyUp","onKeyUp","scrollSelectionIntoViewToSlate","noop","_editor","domRange","decorate","isEqualToEmptyEditor","intersection","addEventListener","removeEventListener","SlateEditable","EditorEventListener","useEditor","useEffectEvent","subscription"],"mappings":";;;;;;;AAIgBA,SAAAA,eACdC,OACAC,OAC6B;AACzB,MAAA,CAACD,SAAS,CAACC;AACN,WAAA;AAET,QAAMC,UAAgB,CAAE;AACpBC,MAAAA,YAAoBH,MAAMI,UAAU;AACxC,QAAMC,WACJ,OAAOL,MAAMM,KAAK,CAAC,KAAM,YACzB,UAAUN,MAAMM,KAAK,CAAC,KACtBN,MAAMM,KAAK,CAAC,EAAEC,MACVC,WACJ,OAAOR,MAAMM,KAAK,CAAC,KAAM,YACzB,UAAUN,MAAMM,KAAK,CAAC,KACtBN,MAAMM,KAAK,CAAC,EAAEC,MACVE,QAAuCR,MAAMS,KAChDC,CAAQA,QAAAA,IAAIJ,SAASF,QACxB;AACII,MAAAA;AACFP,YAAQU,KAAK;AAAA,MAACL,MAAME,MAAMF;AAAAA,IAAAA,CAAK;AAAA;AAExB,WAAA;A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