Cursor Overlay
plate/cursor-overlayFreeComponent
A visual overlay for cursors and selections.
Live preview
live · rendered by the registry
Rendered by plate on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://platejs.org/r/cursor-overlay.jsonSource
1'use client';23import * as React from 'react';45import { AIChatPlugin } from '@platejs/ai/react';6import {7 type CursorData,8 type CursorOverlayState,9 useCursorOverlay,10} from '@platejs/selection/react';11import { getTableGridAbove } from '@platejs/table';12import { RangeApi } from 'platejs';13import { useEditorRef, usePluginOption } from 'platejs/react';1415import { cn } from '@/lib/utils';1617export function CursorOverlay() {18 const { cursors } = useCursorOverlay();1920 return (21 <>22 {cursors.map((cursor) => (23 <Cursor key={cursor.id} {...cursor} />24 ))}25 </>26 );27}2829function Cursor({30 id,31 caretPosition,32 data,33 selection,34 selectionRects,35}: CursorOverlayState<CursorData>) {36 const editor = useEditorRef();37 const streaming = usePluginOption(AIChatPlugin, 'streaming');38 const { style, selectionStyle = style } = data ?? ({} as CursorData);39 const isCursor = RangeApi.isCollapsed(selection);4041 if (streaming) return null;4243 // Skip overlay for multi-cell table selection (table has its own selection UI)44 if (id === 'selection' && selection) {45 const cellEntries = getTableGridAbove(editor, {46 at: selection,47 format: 'cell',48 });4950 if (cellEntries.length > 1) {51 return null;52 }53 }5455 return (56 <>57 {selectionRects.map((position, i) => (58 <div59 key={i}60 className={cn(61 'pointer-events-none absolute z-10',62 id === 'selection' && 'bg-brand/25',63 id === 'selection' && isCursor && 'bg-primary'64 )}65 style={{66 ...selectionStyle,67 ...position,68 }}69 />70 ))}71 {caretPosition && (72 <div73 className={cn(74 'pointer-events-none absolute z-10 w-0.5',75 id === 'drag' && 'w-px bg-brand'76 )}77 style={{ ...caretPosition, ...style }}78 />79 )}80 </>81 );82}
What it pulls in
npm packages
Files it writes
More from plate
All 324 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ai-kitai-kit | plate | Components | Free | 1 dep | |
| AI Menuai-menu | plate | Components | Free | 5 deps · 2 files | |
| AI Leafai-node | plate | Components | Free | no deps | |
| AI Toolbar Buttonai-toolbar-button | plate | Components | Free | 1 dep | |
| align-base-kitalign-base-kit | plate | Components | Free | 1 dep | |
| align-kitalign-kit | plate | Components | Free | 1 dep | |
| Align Toolbar Buttonalign-toolbar-button | plate | Components | Free | 1 dep | |
| autoformat-classic-kitautoformat-classic-kit | plate | Components | Free | 2 deps |
