2024-12-10 13:12:58 -08:00
|
|
|
import { PlusIcon } from "@radix-ui/react-icons";
|
|
|
|
|
import { cn } from "@/util/utils";
|
|
|
|
|
import { AutoResizingTextarea } from "./AutoResizingTextarea/AutoResizingTextarea";
|
2024-12-12 08:30:04 -08:00
|
|
|
import { Popover, PopoverContent, PopoverTrigger } from "./ui/popover";
|
|
|
|
|
import { WorkflowBlockParameterSelect } from "@/routes/workflows/editor/nodes/WorkflowBlockParameterSelect";
|
2025-01-22 22:25:37 +08:00
|
|
|
import {
|
|
|
|
|
Tooltip,
|
|
|
|
|
TooltipContent,
|
|
|
|
|
TooltipProvider,
|
|
|
|
|
TooltipTrigger,
|
|
|
|
|
} from "./ui/tooltip";
|
|
|
|
|
import { useEdges, useNodes } from "@xyflow/react";
|
2024-12-10 13:12:58 -08:00
|
|
|
|
2024-12-12 08:30:04 -08:00
|
|
|
type Props = Omit<
|
|
|
|
|
React.ComponentProps<typeof AutoResizingTextarea>,
|
|
|
|
|
"onChange"
|
|
|
|
|
> & {
|
|
|
|
|
onChange: (value: string) => void;
|
|
|
|
|
nodeId: string;
|
2025-01-22 22:25:37 +08:00
|
|
|
isFirstInputInNode?: boolean;
|
2024-12-10 13:12:58 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function WorkflowBlockInputTextarea(props: Props) {
|
2024-12-12 08:30:04 -08:00
|
|
|
const { nodeId, onChange, ...textAreaProps } = props;
|
2025-01-22 22:25:37 +08:00
|
|
|
const edges = useEdges();
|
|
|
|
|
const nodes = useNodes();
|
|
|
|
|
|
|
|
|
|
function isInsideFirstNode() {
|
|
|
|
|
const node = nodes.find((node) => node.id === nodeId);
|
|
|
|
|
if (!node) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const incomingEdge = edges.find((edge) => edge.target === node.id);
|
|
|
|
|
if (!incomingEdge) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const source = incomingEdge.source;
|
|
|
|
|
const sourceNode = nodes.find((node) => node.id === source);
|
|
|
|
|
if (!sourceNode) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return !node.parentId && sourceNode.type === "start";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const showInputTooltip = isInsideFirstNode() && props.isFirstInputInNode;
|
2024-12-12 08:30:04 -08:00
|
|
|
|
2024-12-10 13:12:58 -08:00
|
|
|
return (
|
|
|
|
|
<div className="relative">
|
|
|
|
|
<AutoResizingTextarea
|
2024-12-12 08:30:04 -08:00
|
|
|
{...textAreaProps}
|
|
|
|
|
onChange={(event) => {
|
|
|
|
|
onChange(event.target.value);
|
|
|
|
|
}}
|
2024-12-10 13:12:58 -08:00
|
|
|
className={cn("pr-9", props.className)}
|
|
|
|
|
/>
|
|
|
|
|
<div className="absolute right-0 top-0 flex size-9 cursor-pointer items-center justify-center">
|
2024-12-12 08:30:04 -08:00
|
|
|
<Popover>
|
2025-01-22 22:25:37 +08:00
|
|
|
<TooltipProvider>
|
|
|
|
|
<Tooltip open={showInputTooltip}>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<PopoverTrigger asChild>
|
|
|
|
|
<div className="rounded p-1 hover:bg-muted">
|
|
|
|
|
<PlusIcon className="size-4" />
|
|
|
|
|
</div>
|
|
|
|
|
</PopoverTrigger>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent>Add parameters using the + button</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</TooltipProvider>
|
2024-12-12 08:30:04 -08:00
|
|
|
<PopoverContent>
|
|
|
|
|
<WorkflowBlockParameterSelect
|
|
|
|
|
nodeId={nodeId}
|
|
|
|
|
onAdd={(parameterKey) => {
|
|
|
|
|
onChange(`${props.value ?? ""}{{${parameterKey}}}`);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</PopoverContent>
|
|
|
|
|
</Popover>
|
2024-12-10 13:12:58 -08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export { WorkflowBlockInputTextarea };
|