import type { MutableRefObject } from "react"; import { Suspense, use, useRef } from "react"; import { Badge, Card, Center, Loader } from "@mantine/core"; import { useElementSize } from "@mantine/hooks"; import { QueryErrorResetBoundary, useQueryClient } from "@tanstack/react-query"; import combineClasses from "clsx"; import { NoIntegrationSelectedError } from "@homarr/widgets/errors/classes"; import { ErrorBoundary } from "react-error-boundary"; import { useRequiredBoard } from "@homarr/boards/context"; import { useEditMode } from "@homarr/boards/edit-mode"; import { useSettings } from "@homarr/settings"; import { getWidgetComponent } from "@homarr/widgets/client"; import { WidgetError } from "@homarr/widgets/errors"; import { loadWidgetDefinition, reduceWidgetOptionsWithDefinition } from "@homarr/widgets/manifest"; import type { WidgetDefinition } from "@homarr/widgets/definition"; import type { SectionItem } from "~/app/[locale]/boards/_types"; import classes from "../sections/item.module.css"; import { useItemActions } from "./item-actions"; import itemContentClasses from "./item-content.module.css"; import { BoardItemMenu } from "./item-menu"; import { WidgetContextMenu } from "./widget-context-menu"; import { removePersistedWidgetQueries } from "./widget-query-recovery"; interface BoardItemContentProps { item: SectionItem; } const getOverflowFromKind = (kind: SectionItem["kind"]) => { if (kind === "iframe") return "hidden"; if (kind === "systemResources") return "visible"; return undefined; }; export const BoardItemContent = ({ item }: BoardItemContentProps) => { const { ref, width, height } = useElementSize(); const board = useRequiredBoard(); const widgetStateRef = useRef | null>(null); return ( <> } > {item.advancedOptions.title?.trim() && ( {item.advancedOptions.title} )} ); }; interface LoadedBoardItemContentProps extends Omit { innerRef: (element: HTMLDivElement | null) => void; } const LoadedBoardItemContent = ({ item, innerRef, ...innerContentProps }: LoadedBoardItemContentProps) => { const board = useRequiredBoard(); const definition = use(loadWidgetDefinition(item.kind)); return ( ( <> )} > ); }; interface InnerContentProps { item: SectionItem; width: number; height: number; widgetStateRef: MutableRefObject | null>; definition: WidgetDefinition; } const InnerContent = ({ item, definition, ...dimensions }: InnerContentProps) => { const settings = useSettings(); const board = useRequiredBoard(); const [isEditMode] = useEditMode(); const Comp = getWidgetComponent(item.kind); const options = reduceWidgetOptionsWithDefinition(definition, settings, item.options); const newItem = { ...item, options }; const { updateItemOptions } = useItemActions(); const updateOptions = ({ newOptions }: { newOptions: Record }) => updateItemOptions({ itemId: item.id, newOptions }); const widgetSupportsIntegrations = "supportedIntegrations" in definition && (definition.supportedIntegrations?.length ?? 0) >= 1; const queryClient = useQueryClient(); return ( {({ reset }) => ( { removePersistedWidgetQueries(queryClient); reset(); }} fallbackRender={({ resetErrorBoundary, error }) => ( <> )} > updateOptions({ newOptions: { ...options, ...partialNewOptions.newOptions, }, }) } {...dimensions} /> )} ); }; const Throw = ({ when, error }: { when: boolean; error: Error }) => { if (when) throw error; return null; };