Files
advanced-camera-card/src/card-controller/expand-manager.ts
T
Dermot Duffy 8d3cf07b43 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.
2025-02-11 20:07:55 -08:00

40 lines
911 B
TypeScript

import { CardExpandAPI } from './types';
export class ExpandManager {
protected _expanded = false;
protected _api: CardExpandAPI;
constructor(api: CardExpandAPI) {
this._api = api;
}
public initialize(): void {
this._setConditionState();
}
public isExpanded(): boolean {
return this._expanded;
}
public toggleExpanded(): void {
this.setExpanded(!this._expanded);
}
public setExpanded(expanded: boolean): void {
if (expanded && this._api.getFullscreenManager().isInFullscreen()) {
// Fullscreen and expanded mode are mutually exclusive.
this._api.getFullscreenManager().setFullscreen(false);
}
this._expanded = expanded;
this._setConditionState();
this._api.getCardElementManager().update();
}
protected _setConditionState(): void {
this._api.getConditionStateManager()?.setState({
expand: this._expanded,
});
}
}