import type { LoaderComponent } from "next/dynamic"; import type { DefaultErrorData } from "@trpc/server/unstable-core-do-not-import"; import type { IntegrationKind, WidgetKind } from "@homarr/definitions"; import type { stringOrTranslation } from "@homarr/translation"; import type { TablerIcon } from "@homarr/ui"; import type { WidgetImports } from "."; import type { inferOptionsFromDefinition, WidgetOptionsRecord } from "./options"; const createWithDynamicImport = (kind: TKind, definition: TDefinition) => (componentLoader: () => LoaderComponent>) => ({ definition: { ...definition, kind, }, kind, componentLoader, }); export const createWidgetDefinition = ( kind: TKind, definition: TDefinition, ) => ({ withDynamicImport: createWithDynamicImport(kind, definition), }); export interface WidgetDefinition { icon: TablerIcon; supportedIntegrations?: IntegrationKind[]; options: WidgetOptionsRecord; errors?: Partial< Record< DefaultErrorData["code"], { icon: TablerIcon; message: stringOrTranslation; hideLogsLink?: boolean; } > >; } export interface WidgetProps { options: inferOptionsFromDefinition>; integrationIds: string[]; itemId: string | undefined; // undefined when in preview mode } export type WidgetComponentProps = WidgetProps & { boardId: string | undefined; // undefined when in preview mode isEditMode: boolean; setOptions: ({ newOptions, }: { newOptions: Partial>>; }) => void; width: number; height: number; }; export type WidgetOptionsRecordOf = WidgetImports[TKind]["definition"]["options"];