import { useTranslation } from "@termix/plugin-sdk/frontend"; import { useRef } from "react"; import { List, ExternalLink } from "lucide-react"; import { registerWidget } from "./WidgetRegistry"; import type { LinkTreeConfig, LinkTreeLink, WidgetComponentProps, } from "../types.js"; import { GRID_SIZE } from "../types.js"; import { WidgetTitle } from "@termix/plugin-sdk/ui"; function TreeLink({ link, compact, isReadOnly, }: { link: LinkTreeLink; compact: boolean; isReadOnly?: boolean; }) { const mouseDownRef = useRef<{ x: number; y: number } | null>(null); const content = (
{link.label} {!compact && link.description && ( {link.description} )}
); if (isReadOnly || !link.url) return content; return ( { mouseDownRef.current = { x: e.clientX, y: e.clientY }; }} onClick={(e) => { const s = mouseDownRef.current; if ( s && (Math.abs(e.clientX - s.x) > 4 || Math.abs(e.clientY - s.y) > 4) ) e.preventDefault(); mouseDownRef.current = null; }} > {content} ); } function LinkTreeWidget({ widget, config, isReadOnly, }: WidgetComponentProps) { const { t } = useTranslation(); const { sections, compact } = config; if (sections.length === 0) { return (
{t("homepage.noSections")}
); } return (
} />
{sections.map((section, si) => (
{section.heading && (
{section.heading}
)} {section.links.map((link, li) => ( ))}
))}
); } registerWidget({ id: "link_tree", name: "Link Tree", description: "Grouped links organized into labeled sections", category: "links", icon: , defaultConfig: { sections: [], compact: false }, defaultSize: { w: GRID_SIZE * 10, h: GRID_SIZE * 12 }, minSize: { w: GRID_SIZE * 4, h: GRID_SIZE * 4 }, component: LinkTreeWidget, }); export { LinkTreeWidget };