| 1 | "use client"; |
| 2 | |
| 3 | import { BlockSelectionPlugin } from "@platejs/selection/react"; |
| 4 | import { useEditorRef, usePluginOption } from "platejs/react"; |
| 5 | import * as React from "react"; |
| 6 | |
| 7 | export function BlockSelectionFocusBridge() { |
| 8 | const editor = useEditorRef(); |
| 9 | const selectedIds = usePluginOption(BlockSelectionPlugin, "selectedIds"); |
| 10 | const isSelectionAreaVisible = usePluginOption( |
| 11 | BlockSelectionPlugin, |
| 12 | "isSelectionAreaVisible", |
| 13 | ); |
| 14 | |
| 15 | React.useEffect(() => { |
| 16 | if (!selectedIds || selectedIds.size === 0 || isSelectionAreaVisible) { |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | const frame = window.requestAnimationFrame(() => { |
| 21 | editor.getApi(BlockSelectionPlugin).blockSelection.focus(); |
| 22 | }); |
| 23 | |
| 24 | return () => window.cancelAnimationFrame(frame); |
| 25 | }, [editor, isSelectionAreaVisible, selectedIds]); |
| 26 | |
| 27 | return null; |
| 28 | } |
| 29 |