AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
import { NoteColorVariant } from '@activepieces/shared';
import { Editor } from '@tiptap/core';
import { t } from 'i18next';
import { TrashIcon } from 'lucide-react';
import { forwardRef, useRef, useState } from 'react';
import { useBuilderStateContext } from '@/app/builder/builder-hooks';
import {
MarkdownTools,
ToolWrapper,
} from '@/components/custom/markdown-input/tools';
import { Button } from '@/components/ui/button';
import {
Popover,
PopoverContent,
PopoverTrigger,
} from '@/components/ui/popover';
import { Separator } from '@/components/ui/separator';
import { cn } from '@/lib/utils';
export const NoteTools = ({ editor, currentColor, id }: NoteToolsProps) => {
const containerRef = useRef<HTMLDivElement>(null);
const [updateNoteColor, deleteNote] = useBuilderStateContext((state) => [
state.updateNoteColor,
state.deleteNote,
]);
return (
<div
ref={containerRef}
className="absolute cursor-default -top-[45px] w-full left-0"
>
<div className="flex items-center justify-center">
<div className="p-1 bg-gray-1 flex items-center gap-0.5 shadow-md rounded-xl scale-65 border border-solid border-gray-6">
<NoteColorPicker
currentColor={currentColor}
setCurrentColor={(color: NoteColorVariant) => {
updateNoteColor(id, color);
}}
container={containerRef.current}
/>
<MarkdownTools editor={editor} />
<Separator orientation="vertical" className="h-[30px]"></Separator>
<ToolWrapper tooltip={t('Delete')}>
<Button
variant="ghost"
size="icon"
onClick={() => {
deleteNote(id);
}}
>
<TrashIcon className="size-4 text-danger-11" />
</Button>
</ToolWrapper>
</div>
</div>
</div>
);
};
const NoteColorPickerClassName = {
[NoteColorVariant.YELLOW]: 'bg-swatch-6-mark',
[NoteColorVariant.ORANGE]: 'bg-swatch-5-mark',
[NoteColorVariant.RED]: 'bg-swatch-4-mark',
[NoteColorVariant.GREEN]: 'bg-swatch-8-mark',
[NoteColorVariant.BLUE]: 'bg-swatch-11-mark',
[NoteColorVariant.PURPLE]: 'bg-swatch-1-mark',
};
const NoteColorPicker = ({
currentColor,
setCurrentColor,
container,
}: NoteColorPickerProps) => {
const [open, setOpen] = useState(false);
const popoverTriggerRef = useRef<HTMLButtonElement>(null);
return (
<Popover onOpenChange={setOpen} open={open}>
<ToolWrapper tooltip={t('Color')}>
<PopoverTrigger asChild>
<div>
<ColorButton
color={currentColor}
big={true}
ref={popoverTriggerRef}
/>
</div>
</PopoverTrigger>
</ToolWrapper>
<PopoverContent
container={container}
side="top"
className="w-[80px] p-1 mb-2"
>
<div className="flex items-center cursor-default gap-1 justify-between flex-wrap w-full ">
{Object.values(NoteColorVariant).map((color) => (
<ColorButton
key={color}
color={color}
onClick={() => {
setCurrentColor(color);
setOpen(false);
requestAnimationFrame(() => {
popoverTriggerRef.current?.focus();
});
}}
/>
))}
</div>
</PopoverContent>
</Popover>
);
};
NoteTools.displayName = 'NoteTools';
type NoteToolsProps = {
editor: Editor;
currentColor: NoteColorVariant;
id: string;
};
type NoteColorPickerProps = {
currentColor: NoteColorVariant;
setCurrentColor: (color: NoteColorVariant) => void;
container: HTMLDivElement | null;
};
const ColorButton = forwardRef<HTMLButtonElement, ColorButtonProps>(
({ color, onClick, big }, ref) => {
return (
<Button
key={color}
ref={ref}
variant="ghost"
size="icon"
role="button"
className={cn('size-5 shrink-0 grow flex items-center justify-center', {
'size-6': big,
})}
onClick={onClick}
onFocus={() => {
console.log('focus');
}}
>
<div
className={cn(
NoteColorPickerClassName[color] ??
NoteColorPickerClassName[NoteColorVariant.YELLOW],
'size-4 shrink-0 rounded-full',
{
'size-5': big,
},
)}
></div>
</Button>
);
},
);
ColorButton.displayName = 'ColorButton';
type ColorButtonProps = {
color: NoteColorVariant;
onClick?: () => void;
big?: boolean;
};