refactor: Significantly refactor how conditions work internally (#1886)

- Much improved API cleanliness and testability to allow further
extensibility in future
 - Simplified code in `live` view

This technically contains a small change in how overrides work in the
`live` view. Since that change is _closer_ to the documentation, and
since this is likely to be rarely used, this is not considered a
breaking change. Previously, overrides for a given live camera would
always render _as if_ that camera was selected, vs was actually
selected. Now, overrides will only apply in the live view when the
camera is _actually_ selected. If this is an issue for you in practice,
lets discuss.
This commit is contained in:
Dermot Duffy
2025-02-11 20:07:55 -08:00
committed by GitHub
parent a92074bc8d
commit 8d3cf07b43
51 changed files with 2443 additions and 2118 deletions
+3 -13
View File
@@ -685,7 +685,7 @@ export type StatusBarItem = z.infer<typeof statusBarItemSchema>;
const viewConditionSchema = z.object({
condition: z.literal('view'),
views: z.string().array(),
views: z.string().array().optional(),
});
const fullscreenConditionSchema = z.object({
condition: z.literal('fullscreen'),
@@ -697,7 +697,7 @@ const expandConditionSchema = z.object({
});
const cameraConditionSchema = z.object({
condition: z.literal('camera'),
cameras: z.string().array(),
cameras: z.string().array().optional(),
});
const mediaLoadedConditionSchema = z.object({
condition: z.literal('media_loaded'),
@@ -773,7 +773,7 @@ export type AdvancedCameraCardCondition = z.infer<
typeof advancedCameraCardConditionSchema
>;
export const advancedCameraCardConditionalSchema = z.object({
const advancedCameraCardConditionalSchema = z.object({
type: z.literal('custom:advanced-camera-card-conditional'),
conditions: advancedCameraCardConditionSchema.array(),
elements: z.lazy(() => pictureElementsSchema),
@@ -1328,16 +1328,6 @@ const liveConfigSchema = z
.default(liveConfigDefault);
export type LiveConfig = z.infer<typeof liveConfigSchema>;
// This schema is used when the live config needs to be overridden (see
// `live.ts`). Overrides will always be "relative" to the config root, so this
// schema maintains that 'depth' from the root but without the other
// requirements that advancedCameraCardConfigSchema has. Without this, overrides
// calculated in `live.ts` would fail since cameras/type are not provided (as
// these are mandatory parameters in the full config).
export const liveConfigAbsoluteRootSchema = z.object({
live: liveConfigSchema,
});
// *************************************************************************
// Cast Configuration
// *************************************************************************