返回 presentation-ai
block-selection.tsx
根目录 / src / components / plate / ui / block-selection.tsx
1 "use client";
2
3 import { DndPlugin } from "@platejs/dnd";
4 import { useBlockSelected } from "@platejs/selection/react";
5 import { cva } from "class-variance-authority";
6 import { usePluginOption, type PlateElementProps } from "platejs/react";
7
8 export const blockSelectionVariants = cva(
9 "pointer-events-none absolute inset-0 z-1 bg-brand/13 transition-opacity",
10 {
11 defaultVariants: {
12 active: true,
13 },
14 variants: {
15 active: {
16 false: "opacity-0",
17 true: "opacity-100",
18 },
19 },
20 },
21 );
22
23 export function BlockSelection(props: PlateElementProps) {
24 const isBlockSelected = useBlockSelected();
25 const isDragging = usePluginOption(DndPlugin, "isDragging");
26
27 if (!isBlockSelected || props.plugin.key === "tr") return null;
28
29 return (
30 <div
31 className={blockSelectionVariants({
32 active: isBlockSelected && !isDragging,
33 })}
34 data-slot="block-selection"
35 />
36 );
37 }
38
38 lines Plain Text