2024-02-03 22:26:12 +01:00
|
|
|
import { z } from "zod";
|
|
|
|
|
|
|
|
|
|
import { integrationKinds, widgetKinds } from "@homarr/definitions";
|
|
|
|
|
|
|
|
|
|
import { zodEnumFromArray } from "./enums";
|
|
|
|
|
|
|
|
|
|
export const integrationSchema = z.object({
|
|
|
|
|
id: z.string(),
|
|
|
|
|
kind: zodEnumFromArray(integrationKinds),
|
|
|
|
|
name: z.string(),
|
|
|
|
|
url: z.string(),
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-06 21:12:55 +02:00
|
|
|
export type BoardItemIntegration = z.infer<typeof integrationSchema>;
|
|
|
|
|
|
2024-05-19 23:01:26 +02:00
|
|
|
export const itemAdvancedOptionsSchema = z.object({
|
|
|
|
|
customCssClasses: z.array(z.string()).default([]),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type BoardItemAdvancedOptions = z.infer<typeof itemAdvancedOptionsSchema>;
|
|
|
|
|
|
2024-02-03 22:26:12 +01:00
|
|
|
export const sharedItemSchema = z.object({
|
|
|
|
|
id: z.string(),
|
|
|
|
|
xOffset: z.number(),
|
|
|
|
|
yOffset: z.number(),
|
|
|
|
|
height: z.number(),
|
|
|
|
|
width: z.number(),
|
2024-05-26 17:13:34 +02:00
|
|
|
integrationIds: z.array(z.string()),
|
2024-05-19 23:01:26 +02:00
|
|
|
advancedOptions: itemAdvancedOptionsSchema,
|
2024-02-03 22:26:12 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const commonItemSchema = z
|
|
|
|
|
.object({
|
|
|
|
|
kind: zodEnumFromArray(widgetKinds),
|
|
|
|
|
options: z.record(z.unknown()),
|
|
|
|
|
})
|
|
|
|
|
.and(sharedItemSchema);
|
|
|
|
|
|
2024-05-19 22:38:39 +02:00
|
|
|
const createCategorySchema = <TItemSchema extends z.ZodTypeAny>(itemSchema: TItemSchema) =>
|
2024-02-03 22:26:12 +01:00
|
|
|
z.object({
|
|
|
|
|
id: z.string(),
|
|
|
|
|
name: z.string(),
|
|
|
|
|
kind: z.literal("category"),
|
|
|
|
|
position: z.number(),
|
|
|
|
|
items: z.array(itemSchema),
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-19 22:38:39 +02:00
|
|
|
const createEmptySchema = <TItemSchema extends z.ZodTypeAny>(itemSchema: TItemSchema) =>
|
2024-02-03 22:26:12 +01:00
|
|
|
z.object({
|
|
|
|
|
id: z.string(),
|
|
|
|
|
kind: z.literal("empty"),
|
|
|
|
|
position: z.number(),
|
|
|
|
|
items: z.array(itemSchema),
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-19 22:38:39 +02:00
|
|
|
export const createSectionSchema = <TItemSchema extends z.ZodTypeAny>(itemSchema: TItemSchema) =>
|
|
|
|
|
z.union([createCategorySchema(itemSchema), createEmptySchema(itemSchema)]);
|