chore: update prettier configuration for print width (#519)
* feat: update prettier configuration for print width * chore: apply code formatting to entire repository * fix: remove build files * fix: format issue --------- Co-authored-by: Meier Lukas <meierschlumpf@gmail.com>
This commit is contained in:
@@ -4,10 +4,7 @@ import type { IntegrationKind, WidgetKind } from "@homarr/definitions";
|
||||
import type { TablerIcon } from "@homarr/ui";
|
||||
|
||||
import type { WidgetImports } from ".";
|
||||
import type {
|
||||
inferOptionsFromDefinition,
|
||||
WidgetOptionsRecord,
|
||||
} from "./options";
|
||||
import type { inferOptionsFromDefinition, WidgetOptionsRecord } from "./options";
|
||||
import type { IntegrationSelectOption } from "./widget-integration-select";
|
||||
|
||||
type ServerDataLoader<TKind extends WidgetKind> = () => Promise<{
|
||||
@@ -29,9 +26,7 @@ const createWithDynamicImport =
|
||||
WidgetComponentProps<TKind> &
|
||||
(TServerDataLoader extends ServerDataLoader<TKind>
|
||||
? {
|
||||
serverData: Awaited<
|
||||
ReturnType<Awaited<ReturnType<TServerDataLoader>>["default"]>
|
||||
>;
|
||||
serverData: Awaited<ReturnType<Awaited<ReturnType<TServerDataLoader>>["default"]>>;
|
||||
}
|
||||
: never)
|
||||
>,
|
||||
@@ -46,30 +41,18 @@ const createWithDynamicImport =
|
||||
});
|
||||
|
||||
const createWithServerData =
|
||||
<TKind extends WidgetKind, TDefinition extends WidgetDefinition>(
|
||||
kind: TKind,
|
||||
definition: TDefinition,
|
||||
) =>
|
||||
<TServerDataLoader extends ServerDataLoader<TKind>>(
|
||||
serverDataLoader: TServerDataLoader,
|
||||
) => ({
|
||||
<TKind extends WidgetKind, TDefinition extends WidgetDefinition>(kind: TKind, definition: TDefinition) =>
|
||||
<TServerDataLoader extends ServerDataLoader<TKind>>(serverDataLoader: TServerDataLoader) => ({
|
||||
definition: {
|
||||
...definition,
|
||||
kind,
|
||||
},
|
||||
kind,
|
||||
serverDataLoader,
|
||||
withDynamicImport: createWithDynamicImport(
|
||||
kind,
|
||||
definition,
|
||||
serverDataLoader,
|
||||
),
|
||||
withDynamicImport: createWithDynamicImport(kind, definition, serverDataLoader),
|
||||
});
|
||||
|
||||
export const createWidgetDefinition = <
|
||||
TKind extends WidgetKind,
|
||||
TDefinition extends WidgetDefinition,
|
||||
>(
|
||||
export const createWidgetDefinition = <TKind extends WidgetKind, TDefinition extends WidgetDefinition>(
|
||||
kind: TKind,
|
||||
definition: TDefinition,
|
||||
) => ({
|
||||
@@ -85,41 +68,32 @@ export interface WidgetDefinition {
|
||||
|
||||
export interface WidgetProps<TKind extends WidgetKind> {
|
||||
options: inferOptionsFromDefinition<WidgetOptionsRecordOf<TKind>>;
|
||||
integrations: inferIntegrationsFromDefinition<
|
||||
WidgetImports[TKind]["definition"]
|
||||
>;
|
||||
integrations: inferIntegrationsFromDefinition<WidgetImports[TKind]["definition"]>;
|
||||
}
|
||||
|
||||
type inferServerDataForKind<TKind extends WidgetKind> =
|
||||
WidgetImports[TKind] extends { serverDataLoader: ServerDataLoader<TKind> }
|
||||
? Awaited<
|
||||
ReturnType<
|
||||
Awaited<
|
||||
ReturnType<WidgetImports[TKind]["serverDataLoader"]>
|
||||
>["default"]
|
||||
>
|
||||
>
|
||||
: undefined;
|
||||
type inferServerDataForKind<TKind extends WidgetKind> = WidgetImports[TKind] extends {
|
||||
serverDataLoader: ServerDataLoader<TKind>;
|
||||
}
|
||||
? Awaited<ReturnType<Awaited<ReturnType<WidgetImports[TKind]["serverDataLoader"]>>["default"]>>
|
||||
: undefined;
|
||||
|
||||
export type WidgetComponentProps<TKind extends WidgetKind> =
|
||||
WidgetProps<TKind> & {
|
||||
serverData?: inferServerDataForKind<TKind>;
|
||||
} & {
|
||||
itemId: string | undefined; // undefined when in preview mode
|
||||
boardId: string | undefined; // undefined when in preview mode
|
||||
isEditMode: boolean;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
export type WidgetComponentProps<TKind extends WidgetKind> = WidgetProps<TKind> & {
|
||||
serverData?: inferServerDataForKind<TKind>;
|
||||
} & {
|
||||
itemId: string | undefined; // undefined when in preview mode
|
||||
boardId: string | undefined; // undefined when in preview mode
|
||||
isEditMode: boolean;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
|
||||
type inferIntegrationsFromDefinition<TDefinition extends WidgetDefinition> =
|
||||
TDefinition extends {
|
||||
supportedIntegrations: infer TSupportedIntegrations;
|
||||
} // check if definition has supportedIntegrations
|
||||
? TSupportedIntegrations extends IntegrationKind[] // check if supportedIntegrations is an array of IntegrationKind
|
||||
? IntegrationSelectOptionFor<TSupportedIntegrations[number]>[] // if so, return an array of IntegrationSelectOptionFor
|
||||
: IntegrationSelectOption[] // otherwise, return an array of IntegrationSelectOption without specifying the kind
|
||||
: IntegrationSelectOption[];
|
||||
type inferIntegrationsFromDefinition<TDefinition extends WidgetDefinition> = TDefinition extends {
|
||||
supportedIntegrations: infer TSupportedIntegrations;
|
||||
} // check if definition has supportedIntegrations
|
||||
? TSupportedIntegrations extends IntegrationKind[] // check if supportedIntegrations is an array of IntegrationKind
|
||||
? IntegrationSelectOptionFor<TSupportedIntegrations[number]>[] // if so, return an array of IntegrationSelectOptionFor
|
||||
: IntegrationSelectOption[] // otherwise, return an array of IntegrationSelectOption without specifying the kind
|
||||
: IntegrationSelectOption[];
|
||||
|
||||
interface IntegrationSelectOptionFor<TIntegration extends IntegrationKind> {
|
||||
id: string;
|
||||
@@ -128,5 +102,4 @@ interface IntegrationSelectOptionFor<TIntegration extends IntegrationKind> {
|
||||
kind: TIntegration[number];
|
||||
}
|
||||
|
||||
export type WidgetOptionsRecordOf<TKind extends WidgetKind> =
|
||||
WidgetImports[TKind]["definition"]["options"];
|
||||
export type WidgetOptionsRecordOf<TKind extends WidgetKind> = WidgetImports[TKind]["definition"]["options"];
|
||||
|
||||
Reference in New Issue
Block a user