2025-09-08 15:56:57 -07:00
|
|
|
import { z } from "zod";
|
|
|
|
|
|
2025-09-23 13:08:51 -07:00
|
|
|
import { type Datum } from "./datum.svelte.ts";
|
2025-09-08 15:56:57 -07:00
|
|
|
|
|
|
|
|
type Assert<_T extends true> = void;
|
|
|
|
|
|
|
|
|
|
export const all_presentation_tags = [
|
2025-10-07 06:23:50 +00:00
|
|
|
"Dropdown",
|
2025-09-08 15:56:57 -07:00
|
|
|
"Text",
|
|
|
|
|
"Timestamp",
|
|
|
|
|
"Uuid",
|
|
|
|
|
] as const;
|
|
|
|
|
|
|
|
|
|
// Type checking to ensure that all valid enum tags are included.
|
2025-10-07 06:23:50 +00:00
|
|
|
type _PresentationTagsAssertionA = Assert<
|
2025-09-08 15:56:57 -07:00
|
|
|
Presentation["t"] extends (typeof all_presentation_tags)[number] ? true
|
|
|
|
|
: false
|
|
|
|
|
>;
|
2025-10-07 06:23:50 +00:00
|
|
|
type _PresentationTagsAssertionB = Assert<
|
|
|
|
|
(typeof all_presentation_tags)[number] extends Presentation["t"] ? true
|
|
|
|
|
: false
|
|
|
|
|
>;
|
2025-09-08 15:56:57 -07:00
|
|
|
|
|
|
|
|
export const all_text_input_modes = [
|
|
|
|
|
"SingleLine",
|
|
|
|
|
"MultiLine",
|
|
|
|
|
] as const;
|
|
|
|
|
|
|
|
|
|
// Type checking to ensure that all valid enum tags are included.
|
2025-10-07 06:23:50 +00:00
|
|
|
type _TextInputModesAssertionA = Assert<
|
2025-09-08 15:56:57 -07:00
|
|
|
TextInputMode["t"] extends (typeof all_text_input_modes)[number] ? true
|
|
|
|
|
: false
|
|
|
|
|
>;
|
2025-10-07 06:23:50 +00:00
|
|
|
type _TextInputModesAssertionB = Assert<
|
|
|
|
|
(typeof all_text_input_modes)[number] extends TextInputMode["t"] ? true
|
|
|
|
|
: false
|
|
|
|
|
>;
|
2025-09-08 15:56:57 -07:00
|
|
|
|
|
|
|
|
const text_input_mode_schema = z.union([
|
|
|
|
|
z.object({
|
|
|
|
|
t: z.literal("SingleLine"),
|
|
|
|
|
c: z.object({}),
|
|
|
|
|
}),
|
|
|
|
|
z.object({
|
|
|
|
|
t: z.literal("MultiLine"),
|
|
|
|
|
c: z.object({}),
|
|
|
|
|
}),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
export type TextInputMode = z.infer<typeof text_input_mode_schema>;
|
|
|
|
|
|
2025-10-21 18:58:09 +00:00
|
|
|
const dropdown_option_schema = z.object({
|
|
|
|
|
color: z.string(),
|
|
|
|
|
value: z.string(),
|
|
|
|
|
});
|
|
|
|
|
|
2025-10-07 06:23:50 +00:00
|
|
|
const presentation_dropdown_schema = z.object({
|
|
|
|
|
t: z.literal("Dropdown"),
|
|
|
|
|
c: z.object({
|
|
|
|
|
allow_custom: z.boolean(),
|
2025-10-21 18:58:09 +00:00
|
|
|
options: z.array(dropdown_option_schema),
|
2025-10-07 06:23:50 +00:00
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type PresentationDropdown = z.infer<typeof presentation_dropdown_schema>;
|
|
|
|
|
|
2025-09-08 15:56:57 -07:00
|
|
|
const presentation_text_schema = z.object({
|
|
|
|
|
t: z.literal("Text"),
|
|
|
|
|
c: z.object({
|
|
|
|
|
input_mode: text_input_mode_schema,
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type PresentationText = z.infer<typeof presentation_text_schema>;
|
|
|
|
|
|
|
|
|
|
const presentation_timestamp_schema = z.object({
|
|
|
|
|
t: z.literal("Timestamp"),
|
|
|
|
|
c: z.unknown(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type PresentationTimestamp = z.infer<
|
|
|
|
|
typeof presentation_timestamp_schema
|
|
|
|
|
>;
|
|
|
|
|
|
|
|
|
|
const presentation_uuid_schema = z.object({
|
|
|
|
|
t: z.literal("Uuid"),
|
|
|
|
|
c: z.unknown(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type PresentationUuid = z.infer<typeof presentation_uuid_schema>;
|
|
|
|
|
|
|
|
|
|
export const presentation_schema = z.union([
|
2025-10-07 06:23:50 +00:00
|
|
|
presentation_dropdown_schema,
|
2025-09-08 15:56:57 -07:00
|
|
|
presentation_text_schema,
|
|
|
|
|
presentation_timestamp_schema,
|
|
|
|
|
presentation_uuid_schema,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
export type Presentation = z.infer<typeof presentation_schema>;
|
|
|
|
|
|
2025-09-23 13:08:51 -07:00
|
|
|
export function get_empty_datum_for(presentation: Presentation): Datum {
|
2025-10-07 06:23:50 +00:00
|
|
|
if (presentation.t === "Dropdown") {
|
|
|
|
|
return { t: "Text", c: undefined };
|
2025-09-08 15:56:57 -07:00
|
|
|
}
|
|
|
|
|
if (presentation.t === "Text") {
|
|
|
|
|
return { t: "Text", c: undefined };
|
|
|
|
|
}
|
2025-10-07 06:23:50 +00:00
|
|
|
if (presentation.t === "Timestamp") {
|
|
|
|
|
return { t: "Timestamp", c: undefined };
|
|
|
|
|
}
|
2025-09-08 15:56:57 -07:00
|
|
|
if (presentation.t === "Uuid") {
|
|
|
|
|
return { t: "Uuid", c: undefined };
|
|
|
|
|
}
|
|
|
|
|
type _ = Assert<typeof presentation extends never ? true : false>;
|
|
|
|
|
throw new Error("this should be unreachable");
|
|
|
|
|
}
|